1
0

HDWallpapersBridge.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * HDWallpapersBridge
  4. * Returns the latests wallpapers from http://www.hdwallpapers.in
  5. *
  6. * @name HD Wallpapers Bridge
  7. * @homepage http://www.hdwallpapers.in/
  8. * @description Returns the latests wallpapers from HDWallpapers
  9. * @maintainer nel50n
  10. * @update 2015-04-08
  11. * @use1(c="category",m="max number of wallpapers",r="resolution (1920x1200, 1680x1050, ...)")
  12. */
  13. class HDWallpapersBridge extends BridgeAbstract {
  14. private $category;
  15. private $resolution;
  16. public function collectData(array $param){
  17. $html = '';
  18. $baseUri = 'http://www.hdwallpapers.in';
  19. $this->category = $param['c'] ?: 'latest_wallpapers'; // Latest default
  20. $this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default
  21. $category = $this->category;
  22. if (strrpos($category, 'wallpapers') !== strlen($category)-strlen('wallpapers')) {
  23. $category .= '-desktop-wallpapers';
  24. }
  25. $num = 0;
  26. $max = $param['m'] ?: 14;
  27. $lastpage = 1;
  28. for ($page = 1; $page <= $lastpage; $page++) {
  29. $link = $baseUri.'/'.$category.'/page/'.$page;
  30. $html = file_get_html($link) or $this->returnError('No results for this query.', 404);
  31. if ($page === 1) {
  32. preg_match('/page\/(\d+)$/', $html->find('.pagination a', -2)->href, $matches);
  33. $lastpage = min($matches[1], ceil($max/14));
  34. }
  35. foreach($html->find('.wallpapers .wall a') as $element) {
  36. $thumbnail = $element->find('img', 0);
  37. $item = new \Item();
  38. // http://www.hdwallpapers.in/download/yosemite_reflections-1680x1050.jpg
  39. $item->uri = $baseUri.'/download'.str_replace('wallpapers.html', $this->resolution.'.jpg', $element->href);
  40. $item->timestamp = time();
  41. $item->title = $element->find('p', 0)->text();
  42. $item->thumbnailUri = $baseUri.$thumbnail->src;
  43. $item->content = $item->title.'<br><a href="'.$item->uri.'"><img src="'.$item->thumbnailUri.'" /></a>';
  44. $this->items[] = $item;
  45. $num++;
  46. if ($num >= $max)
  47. break 2;
  48. }
  49. }
  50. }
  51. public function getName(){
  52. return 'HDWallpapers - '.str_replace(['__', '_'], [' & ', ' '], $this->category).' ['.$this->resolution.']';
  53. }
  54. public function getURI(){
  55. return 'http://www.hdwallpapers.in';
  56. }
  57. public function getCacheDuration(){
  58. return 43200; // 12 hours
  59. }
  60. }