SuperbWallpapersBridge.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. class SuperbWallpapersBridge extends BridgeAbstract {
  3. const MAINTAINER = "nel50n";
  4. const NAME = "Superb Wallpapers Bridge";
  5. const URI = "http://www.superbwallpapers.com/";
  6. const DESCRIPTION = "Returns the latests wallpapers from SuperbWallpapers";
  7. const PARAMETERS = array( array(
  8. 'c'=>array(
  9. 'name'=>'category',
  10. 'required'=>true
  11. ),
  12. 'm'=>array(
  13. 'name'=>'Max number of wallpapers',
  14. 'type'=>'number'
  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. $resolution = $this->getInput('r'); // Wide wallpaper default
  25. $num = 0;
  26. $max = $this->getInput('m') ?: 36;
  27. $lastpage = 1;
  28. // Get last page number
  29. $link = self::URI.'/'.$category.'/9999.html';
  30. $html = getSimpleHTMLDOM($link)
  31. or returnServerError('Could not load '.$link);
  32. $lastpage = min($html->find('.paging .cpage', 0)->innertext(), ceil($max/36));
  33. for ($page = 1; $page <= $lastpage; $page++) {
  34. $link = self::URI.'/'.$category.'/'.$page.'.html';
  35. $html = getSimpleHTMLDOM($link)
  36. or returnServerError('No results for this query.');
  37. foreach($html->find('.wpl .i a') as $element) {
  38. $thumbnail = $element->find('img', 0);
  39. $item = array();
  40. $item['uri'] = str_replace('200x125', $this->resolution, $thumbnail->src);
  41. $item['timestamp'] = time();
  42. $item['title'] = $element->title;
  43. $item['content'] = $item['title'].'<br><a href="'.$item['uri'].'">'.$thumbnail.'</a>';
  44. $this->items[] = $item;
  45. $num++;
  46. if ($num >= $max)
  47. break 2;
  48. }
  49. }
  50. }
  51. public function getName(){
  52. return self::NAME .'- '.$this->getInput('c').' ['.$this->getInput('r').']';
  53. }
  54. public function getCacheDuration(){
  55. return 43200; // 12 hours
  56. }
  57. }