SuperbWallpapersBridge.php 2.4 KB

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