SuperbWallpapersBridge.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * SuperbWallpapersBridge
  4. * Returns the latests wallpapers from http://www.superbwallpapers.com
  5. *
  6. * @name Superb Wallpapers Bridge
  7. * @homepage http://www.superbwallpapers.com/
  8. * @description Returns the latests wallpapers from SuperbWallpapers
  9. * @maintainer nel50n
  10. * @update 2015-04-08
  11. * @use1(c="category",m="max number of wallpapers",r="resolution (1920x1200, 1680x1050, ...)")
  12. */
  13. class SuperbWallpapersBridge extends BridgeAbstract {
  14. private $category;
  15. private $resolution;
  16. public function collectData(array $param){
  17. $html = '';
  18. $baseUri = 'http://www.superbwallpapers.com';
  19. $this->category = $param['c'] ?: ''; // All default
  20. $this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default
  21. $num = 0;
  22. $max = $param['m'] ?: 36;
  23. $lastpage = 1;
  24. // Get last page number
  25. $link = $baseUri.'/'.$this->category.'/9999.html';
  26. $html = file_get_html($link);
  27. $lastpage = min($html->find('.paging .cpage', 0)->innertext(), ceil($max/36));
  28. for ($page = 1; $page <= $lastpage; $page++) {
  29. $link = $baseUri.'/'.$this->category.'/'.$page.'.html';
  30. $html = file_get_html($link) or $this->returnError('No results for this query.', 404);
  31. foreach($html->find('.wpl .i a') as $element) {
  32. $thumbnail = $element->find('img', 0);
  33. $item = new \Item();
  34. $item->uri = str_replace('200x125', $this->resolution, $thumbnail->src);
  35. $item->timestamp = time();
  36. $item->title = $element->title;
  37. $item->thumbnailUri = $thumbnail->src;
  38. $item->content = $item->title.'<br><a href="'.$item->uri.'">'.$thumbnail.'</a>';
  39. $this->items[] = $item;
  40. $num++;
  41. if ($num >= $max)
  42. break 2;
  43. }
  44. }
  45. }
  46. public function getName(){
  47. return 'HDWallpapers - '.$this->category.' ['.$this->resolution.']';
  48. }
  49. public function getURI(){
  50. return 'http://www.superbwallpapers.com';
  51. }
  52. public function getCacheDuration(){
  53. return 43200; // 12 hours
  54. }
  55. }