HDWallpapersBridge.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 CACHE_TIMEOUT = 43200; //12h
  7. const DESCRIPTION = "Returns the latests wallpapers from HDWallpapers";
  8. const PARAMETERS = array( array(
  9. 'c'=>array(
  10. 'name'=>'category',
  11. 'defaultValue'=>'latest_wallpapers'
  12. ),
  13. 'm'=>array('name'=>'max number of wallpapers'),
  14. 'r'=>array(
  15. 'name'=>'resolution',
  16. 'defaultValue'=>'1920x1200',
  17. 'exampleValue'=>'1920x1200, 1680x1050,…'
  18. )
  19. ));
  20. public function collectData(){
  21. $category = $this->category;
  22. if (strrpos($category, 'wallpapers') !== strlen($category)-strlen('wallpapers')) {
  23. $category .= '-desktop-wallpapers';
  24. }
  25. $num = 0;
  26. $max = $this->getInput('m') ?: 14;
  27. $lastpage = 1;
  28. for ($page = 1; $page <= $lastpage; $page++) {
  29. $link = self::URI.'/'.$category.'/page/'.$page;
  30. $html = getSimpleHTMLDOM($link) or returnServerError('No results for this query.');
  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 = array();
  38. // http://www.hdwallpapers.in/download/yosemite_reflections-1680x1050.jpg
  39. $item['uri'] = self::URI.'/download'.str_replace('wallpapers.html', $this->getInput('r').'.jpg', $element->href);
  40. $item['timestamp'] = time();
  41. $item['title'] = $element->find('p', 0)->text();
  42. $item['content'] = $item['title'].'<br><a href="'.$item['uri'].'"><img src="'.self::URI.$thumbnail->src.'" /></a>';
  43. $this->items[] = $item;
  44. $num++;
  45. if ($num >= $max)
  46. break 2;
  47. }
  48. }
  49. }
  50. public function getName(){
  51. return 'HDWallpapers - '.str_replace(['__', '_'], [' & ', ' '], $this->getInput('c')).' ['.$this->getInput('r').']';
  52. }
  53. }