PickyWallpapersBridge.php 2.4 KB

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