HDWallpapersBridge.php 2.5 KB

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