PickyWallpapersBridge.php 2.3 KB

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