PickyWallpapersBridge.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. class PickyWallpapersBridge extends BridgeAbstract {
  3. private $category;
  4. private $subcategory;
  5. private $resolution;
  6. public function loadMetadatas() {
  7. $this->maintainer = "nel50n";
  8. $this->name = "PickyWallpapers Bridge";
  9. $this->uri = "http://www.pickywallpapers.com/";
  10. $this->description = "Returns the latests wallpapers from PickyWallpapers";
  11. $this->parameters[] = array(
  12. 'c'=>array('name'=>'category'),
  13. 's'=>array('name'=>'subcategory'),
  14. 'm'=>array(
  15. 'name'=>'Max number of wallpapers',
  16. 'type'=>'number'
  17. ),
  18. 'r'=>array(
  19. 'name'=>'resolution',
  20. 'exampleValue'=>'1920x1200, 1680x1050,…',
  21. 'pattern'=>'[0-9]{3,4}x[0-9]{3,4}'
  22. )
  23. );
  24. }
  25. public function collectData(array $param){
  26. $html = '';
  27. if (!isset($param['c'])) {
  28. $this->returnClientError('You must specify at least a category (?c=...).');
  29. } else {
  30. $baseUri = 'http://www.pickywallpapers.com';
  31. $this->category = $param['c'];
  32. $this->subcategory = $param['s'] ?: '';
  33. $this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default
  34. $num = 0;
  35. $max = $param['m'] ?: 12;
  36. $lastpage = 1;
  37. for ($page = 1; $page <= $lastpage; $page++) {
  38. $link = $baseUri.'/'.$this->resolution.'/'.$this->category.'/'.(!empty($this->subcategory)?$this->subcategory.'/':'').'page-'.$page.'/';
  39. $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('No results for this query.');
  40. if ($page === 1) {
  41. preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches);
  42. $lastpage = min($matches[1], ceil($max/12));
  43. }
  44. foreach($html->find('.items li img') as $element) {
  45. $item = array();
  46. $item['uri'] = str_replace('www', 'wallpaper', $baseUri).'/'.$this->resolution.'/'.basename($element->src);
  47. $item['timestamp'] = time();
  48. $item['title'] = $element->alt;
  49. $item['content'] = $item['title'].'<br><a href="'.$item['uri'].'">'.$element.'</a>';
  50. $this->items[] = $item;
  51. $num++;
  52. if ($num >= $max)
  53. break 2;
  54. }
  55. }
  56. }
  57. }
  58. public function getName(){
  59. return 'PickyWallpapers - '.$this->category.(!empty($this->subcategory) ? ' > '.$this->subcategory : '').' ['.$this->resolution.']';
  60. }
  61. public function getCacheDuration(){
  62. return 43200; // 12 hours
  63. }
  64. }