PickyWallpapersBridge.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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->update = "2014-03-31";
  12. $this->parameters[] =
  13. '[
  14. {
  15. "name" : "Category",
  16. "identifier" : "c"
  17. },
  18. {
  19. "name" : "subcategory",
  20. "identifier" : "s"
  21. },
  22. {
  23. "name" : "Max number of wallpapers",
  24. "identifier" : "m",
  25. "type" : "number"
  26. },
  27. {
  28. "name" : "resolution",
  29. "identifier" : "r",
  30. "exampleValue" : "1920x1200, 1680x1050, ...",
  31. "pattern" : "[0-9]{3,4}x[0-9]{3,4}"
  32. }
  33. ]';
  34. }
  35. public function collectData(array $param){
  36. $html = '';
  37. if (!isset($param['c'])) {
  38. $this->returnError('You must specify at least a category (?c=...).', 400);
  39. } else {
  40. $baseUri = 'http://www.pickywallpapers.com';
  41. $this->category = $param['c'];
  42. $this->subcategory = $param['s'] ?: '';
  43. $this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default
  44. $num = 0;
  45. $max = $param['m'] ?: 12;
  46. $lastpage = 1;
  47. for ($page = 1; $page <= $lastpage; $page++) {
  48. $link = $baseUri.'/'.$this->resolution.'/'.$this->category.'/'.(!empty($this->subcategory)?$this->subcategory.'/':'').'page-'.$page.'/';
  49. $html = $this->file_get_html($link) or $this->returnError('No results for this query.', 404);
  50. if ($page === 1) {
  51. preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches);
  52. $lastpage = min($matches[1], ceil($max/12));
  53. }
  54. foreach($html->find('.items li img') as $element) {
  55. $item = new \Item();
  56. $item->uri = str_replace('www', 'wallpaper', $baseUri).'/'.$this->resolution.'/'.basename($element->src);
  57. $item->timestamp = time();
  58. $item->title = $element->alt;
  59. $item->thumbnailUri = $element->src;
  60. $item->content = $item->title.'<br><a href="'.$item->uri.'">'.$element.'</a>';
  61. $this->items[] = $item;
  62. $num++;
  63. if ($num >= $max)
  64. break 2;
  65. }
  66. }
  67. }
  68. }
  69. public function getName(){
  70. return 'PickyWallpapers - '.$this->category.(!empty($this->subcategory) ? ' > '.$this->subcategory : '').' ['.$this->resolution.']';
  71. }
  72. public function getURI(){
  73. return 'http://www.pickywallpapers.com';
  74. }
  75. public function getCacheDuration(){
  76. return 43200; // 12 hours
  77. }
  78. }