HDWallpapersBridge.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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(
  14. 'name' => 'max number of wallpapers'
  15. ),
  16. 'r' => array(
  17. 'name' => 'resolution',
  18. 'defaultValue' => '1920x1200',
  19. 'exampleValue' => '1920x1200, 1680x1050,…'
  20. )
  21. ));
  22. public function collectData(){
  23. $category = $this->category;
  24. if(strrpos($category, 'wallpapers') !== strlen($category) - strlen('wallpapers')) {
  25. $category .= '-desktop-wallpapers';
  26. }
  27. $num = 0;
  28. $max = $this->getInput('m') ?: 14;
  29. $lastpage = 1;
  30. for($page = 1; $page <= $lastpage; $page++) {
  31. $link = self::URI . '/' . $category . '/page/' . $page;
  32. $html = getSimpleHTMLDOM($link)
  33. or 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'] = self::URI
  43. . '/download'
  44. . str_replace('wallpapers.html', $this->getInput('r') . '.jpg', $element->href);
  45. $item['timestamp'] = time();
  46. $item['title'] = $element->find('p', 0)->text();
  47. $item['content'] = $item['title']
  48. . '<br><a href="'
  49. . $item['uri']
  50. . '"><img src="'
  51. . self::URI
  52. . $thumbnail->src
  53. . '" /></a>';
  54. $this->items[] = $item;
  55. $num++;
  56. if ($num >= $max)
  57. break 2;
  58. }
  59. }
  60. }
  61. public function getName(){
  62. if(!is_null($this->getInput('c')) && !is_null($this->getInput('r'))) {
  63. return 'HDWallpapers - '
  64. . str_replace(['__', '_'], [' & ', ' '], $this->getInput('c'))
  65. . ' ['
  66. . $this->getInput('r')
  67. . ']';
  68. }
  69. return parent::getName();
  70. }
  71. }