WallpaperStopBridge.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. class WallpaperStopBridge extends BridgeAbstract {
  3. const MAINTAINER = 'nel50n';
  4. const NAME = 'WallpaperStop Bridge';
  5. const URI = 'http://www.wallpaperstop.com';
  6. const CACHE_TIMEOUT = 43200; // 12h
  7. const DESCRIPTION = 'Returns the latests wallpapers from WallpaperStop';
  8. const PARAMETERS = array( array(
  9. 'c' => array(
  10. 'name' => 'Category'
  11. ),
  12. 's' => array(
  13. 'name' => 'subcategory'
  14. ),
  15. 'm' => array(
  16. 'name' => 'Max number of wallpapers',
  17. 'type' => 'number',
  18. 'defaultValue' => 20
  19. ),
  20. 'r' => array(
  21. 'name' => 'resolution',
  22. 'exampleValue' => '1920x1200, 1680x1050,…',
  23. 'defaultValue' => '1920x1200'
  24. )
  25. ));
  26. public function collectData(){
  27. $category = $this->getInput('c');
  28. $subcategory = $this->getInput('s');
  29. $resolution = $this->getInput('r');
  30. $num = 0;
  31. $max = $this->getInput('m');
  32. $lastpage = 1;
  33. for($page = 1; $page <= $lastpage; $page++) {
  34. $link = self::URI
  35. . '/'
  36. . $category
  37. . '-wallpaper/'
  38. . (!empty($subcategory) ? $subcategory . '-wallpaper/' : '')
  39. . 'desktop-wallpaper-'
  40. . $page
  41. . '.html';
  42. $html = getSimpleHTMLDOM($link)
  43. or returnServerError('No results for this query.');
  44. if($page === 1) {
  45. preg_match('/-(\d+)\.html$/', $html->find('.pagination > .last', 0)->href, $matches);
  46. $lastpage = min($matches[1], ceil($max / 20));
  47. }
  48. foreach($html->find('article.item') as $element) {
  49. $wplink = $element->getAttribute('data-permalink');
  50. if(preg_match('%^' . self::URI . '/(.+)/([^/]+)-(\d+)\.html$%', $wplink, $matches)) {
  51. $thumbnail = $element->find('img', 0);
  52. $item = array();
  53. $item['uri'] = self::URI
  54. . '/wallpapers/'
  55. . str_replace('wallpaper', 'wallpapers', $matches[1])
  56. . '/'
  57. . $matches[2]
  58. . '-'
  59. . $resolution
  60. . '-'
  61. . $matches[3]
  62. . '.jpg';
  63. $item['id'] = $matches[3];
  64. $item['timestamp'] = time();
  65. $item['title'] = $thumbnail->title;
  66. $item['content'] = $item['title']
  67. . '<br><a href="'
  68. . $wplink
  69. . '"><img src="'
  70. . self::URI
  71. . $thumbnail->src
  72. . '" /></a>';
  73. $this->items[] = $item;
  74. $num++;
  75. if ($num >= $max)
  76. break 2;
  77. }
  78. }
  79. }
  80. }
  81. public function getName(){
  82. if(!is_null($this->getInput('s')) && !is_null($this->getInput('c')) && !is_null($this->getInput('r'))) {
  83. $subcategory = $this->getInput('s');
  84. return 'WallpaperStop - '
  85. . $this->getInput('c')
  86. . (!empty($subcategory) ? ' > ' . $subcategory : '')
  87. . ' ['
  88. . $this->getInput('r')
  89. . ']';
  90. }
  91. return parent::getName();
  92. }
  93. }