PickyWallpapersBridge.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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('name'=>'subcategory'),
  14. 'm'=>array(
  15. 'name'=>'Max number of wallpapers',
  16. 'defaultValue'=>12,
  17. 'type'=>'number'
  18. ),
  19. 'r'=>array(
  20. 'name'=>'resolution',
  21. 'exampleValue'=>'1920x1200, 1680x1050,…',
  22. 'defaultValue'=>'1920x1200',
  23. 'pattern'=>'[0-9]{3,4}x[0-9]{3,4}'
  24. )
  25. ));
  26. public function collectData(){
  27. $lastpage = 1;
  28. $num = 0;
  29. $max = $this->getInput('m');
  30. $resolution = $this->getInput('r'); // Wide wallpaper default
  31. for ($page = 1; $page <= $lastpage; $page++) {
  32. $html = getSimpleHTMLDOM($this->getURI().'/page-'.$page.'/')
  33. or returnServerError('No results for this query.');
  34. if ($page === 1) {
  35. preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches);
  36. $lastpage = min($matches[1], ceil($max/12));
  37. }
  38. foreach($html->find('.items li img') as $element) {
  39. $item = array();
  40. $item['uri'] = str_replace('www', 'wallpaper', self::URI).'/'.$resolution.'/'.basename($element->src);
  41. $item['timestamp'] = time();
  42. $item['title'] = $element->alt;
  43. $item['content'] = $item['title'].'<br><a href="'.$item['uri'].'">'.$element.'</a>';
  44. $this->items[] = $item;
  45. $num++;
  46. if ($num >= $max)
  47. break 2;
  48. }
  49. }
  50. }
  51. public function getURI(){
  52. $subcategory = $this->getInput('s');
  53. $link = self::URI.$this->getInput('r').'/'.$this->getInput('c').'/'.$subcategory;
  54. return $link;
  55. }
  56. public function getName(){
  57. $subcategory = $this->getInput('s');
  58. return 'PickyWallpapers - '.$this->getInput('c')
  59. .($subcategory? ' > '.$subcategory : '')
  60. .' ['.$this->getInput('r').']';
  61. }
  62. }