PickyWallpapersBridge.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * PickyWallpapersBridge
  4. * Returns the latests wallpapers from http://www.pickywallpapers.com
  5. *
  6. * @name PickyWallpapers Bridge
  7. * @homepage http://www.pickywallpapers.com/
  8. * @description Returns the latests wallpapers from PickyWallpapers
  9. * @maintainer nel50n
  10. * @update 2014-03-31
  11. * @use1(c="category",s="subcategory",m="max number of wallpapers",r="resolution (1920x1200, 1680x1050, ...)")
  12. */
  13. class PickyWallpapersBridge extends BridgeAbstract {
  14. private $category;
  15. private $subcategory;
  16. private $resolution;
  17. public function collectData(array $param){
  18. $html = '';
  19. if (!isset($param['c'])) {
  20. $this->returnError('You must specify at least a category (?c=...).', 400);
  21. } else {
  22. $baseUri = 'http://www.pickywallpapers.com';
  23. $this->category = $param['c'];
  24. $this->subcategory = $param['s'] ?: '';
  25. $this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default
  26. $num = 0;
  27. $max = $param['m'] ?: 12;
  28. $lastpage = 1;
  29. for ($page = 1; $page <= $lastpage; $page++) {
  30. $link = $baseUri.'/'.$this->resolution.'/'.$this->category.'/'.(!empty($this->subcategory)?$this->subcategory.'/':'').'page-'.$page.'/';
  31. $html = file_get_html($link) or $this->returnError('No results for this query.', 404);
  32. if ($page === 1) {
  33. preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches);
  34. $lastpage = min($matches[1], ceil($max/12));
  35. }
  36. foreach($html->find('.items li img') as $element) {
  37. $item = new \Item();
  38. $item->uri = str_replace('www', 'wallpaper', $baseUri).'/'.$this->resolution.'/'.basename($element->src);
  39. $item->timestamp = time();
  40. $item->title = $element->alt;
  41. $item->thumbnailUri = $element->src;
  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. }
  51. public function getName(){
  52. return 'PickyWallpapers - '.$this->category.(!empty($this->subcategory) ? ' > '.$this->subcategory : '').' ['.$this->resolution.']';
  53. }
  54. public function getURI(){
  55. return 'http://www.pickywallpapers.com';
  56. }
  57. public function getCacheDuration(){
  58. return 43200; // 12 hours
  59. }
  60. }