HDWallpapersBridge.php 2.3 KB

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