From a1ccad3d5f65c89923cc1ca5426ce9a5407e52d2 Mon Sep 17 00:00:00 2001 From: nel50n Date: Tue, 31 Mar 2015 10:47:17 +0200 Subject: [PATCH] New Bridge : PickyWallpapers --- bridges/PickyWallpapersBridge.php | 72 +++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 bridges/PickyWallpapersBridge.php diff --git a/bridges/PickyWallpapersBridge.php b/bridges/PickyWallpapersBridge.php new file mode 100644 index 00000000..1f47a5c9 --- /dev/null +++ b/bridges/PickyWallpapersBridge.php @@ -0,0 +1,72 @@ +returnError('You must specify at least a category (?c=...).', 400); + } else { + $baseUri = 'http://www.pickywallpapers.com'; + + $this->category = $param['c']; + $this->subcategory = $param['s'] ?: ''; + $this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default + + $num = 0; + $max = $param['m'] ?: 12; + $lastpage = 1; + + for ($page = 1; $page <= $lastpage; $page++) { + $link = $baseUri.'/'.$this->resolution.'/'.$this->category.'/'.(!empty($this->subcategory)?$this->subcategory.'/':'').'page-'.$page.'/'; + $html = file_get_html($link) or $this->returnError('No results for this query.', 404); + + if ($page === 1) { + preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches); + $lastpage = min($matches[1], ceil($max/12)); + } + + foreach($html->find('.items li img') as $element) { + + $item = new \Item(); + $item->uri = str_replace('www', 'wallpaper', $baseUri).'/'.$this->resolution.'/'.basename($element->src); + $item->timestamp = time(); + $item->title = $element->alt; + $item->thumbnailUri = $element->src; + $item->content = $item->title.'
'.$element.''; + $this->items[] = $item; + + $num++; + if ($num >= $max) + break 2; + } + } + } + } + + public function getName(){ + return 'PickyWallpapers - '.$this->category.(!empty($this->subcategory) ? ' > '.$this->subcategory : '').' ['.$this->resolution.']'; + } + + public function getURI(){ + return 'http://www.pickywallpapers.com'; + } + + public function getCacheDuration(){ + return 43200; // 12 hours + } +}