WallpaperStopBridge.php 2.6 KB

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