HDWallpapersBridge.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. return 'HDWallpapers - '
  63. . str_replace(['__', '_'], [' & ', ' '], $this->getInput('c'))
  64. . ' ['
  65. . $this->getInput('r')
  66. . ']';
  67. }
  68. }