WallpaperStopBridge.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. class WallpaperStopBridge extends BridgeAbstract {
  3. const MAINTAINER = "nel50n";
  4. const NAME = "WallpaperStop Bridge";
  5. const URI = "http://www.wallpaperstop.com";
  6. const CACHE_TIMEOUT = 43200; // 12h
  7. const DESCRIPTION = "Returns the latests wallpapers from WallpaperStop";
  8. const PARAMETERS = array( array(
  9. 'c'=>array('name'=>'Category'),
  10. 's'=>array('name'=>'subcategory'),
  11. 'm'=>array(
  12. 'name'=>'Max number of wallpapers',
  13. 'type'=>'number',
  14. 'defaultValue'=>20
  15. ),
  16. 'r'=>array(
  17. 'name'=>'resolution',
  18. 'exampleValue'=>'1920x1200, 1680x1050,…',
  19. 'defaultValue'=>'1920x1200'
  20. )
  21. ));
  22. public function collectData(){
  23. $category = $this->getInput('c');
  24. $subcategory = $this->getInput('s');
  25. $resolution = $this->getInput('r');
  26. $num = 0;
  27. $max = $this->getInput('m');
  28. $lastpage = 1;
  29. for ($page = 1; $page <= $lastpage; $page++) {
  30. $link = self::URI.'/'.$category.'-wallpaper/'.(!empty($subcategory)?$subcategory.'-wallpaper/':'').'desktop-wallpaper-'.$page.'.html';
  31. $html = getSimpleHTMLDOM($link)
  32. or returnServerError('No results for this query.');
  33. if ($page === 1) {
  34. preg_match('/-(\d+)\.html$/', $html->find('.pagination > .last', 0)->href, $matches);
  35. $lastpage = min($matches[1], ceil($max/20));
  36. }
  37. foreach($html->find('article.item') as $element) {
  38. $wplink = $element->getAttribute('data-permalink');
  39. if (preg_match('%^'.self::URI.'/(.+)/([^/]+)-(\d+)\.html$%', $wplink, $matches)) {
  40. $thumbnail = $element->find('img', 0);
  41. $item = array();
  42. $item['uri'] = self::URI.'/wallpapers/'.str_replace('wallpaper', 'wallpapers', $matches[1]).'/'.$matches[2].'-'.$resolution.'-'.$matches[3].'.jpg';
  43. $item['id'] = $matches[3];
  44. $item['timestamp'] = time();
  45. $item['title'] = $thumbnail->title;
  46. $item['content'] = $item['title'].'<br><a href="'.$wplink.'"><img src="'.self::URI.$thumbnail->src.'" /></a>';
  47. $this->items[] = $item;
  48. $num++;
  49. if ($num >= $max)
  50. break 2;
  51. }
  52. }
  53. }
  54. }
  55. public function getName(){
  56. $subcategory=$this->getInput('s');
  57. return 'WallpaperStop - '.$this->getInput('c').(!empty($subcategory) ? ' > '.$subcategory : '').' ['.$this->getInput('r').']';
  58. }
  59. }