diff --git a/bridges/WallpaperStopBridge.php b/bridges/WallpaperStopBridge.php new file mode 100644 index 0000000..9d3e20b --- /dev/null +++ b/bridges/WallpaperStopBridge.php @@ -0,0 +1,78 @@ +returnError('You must specify at least a category (?c=...).', 400); + } else { + $baseUri = 'http://www.wallpaperstop.com'; + + $this->category = $param['c']; + $this->subcategory = $param['s'] ?: ''; + $this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default + + $num = 0; + $max = $param['m'] ?: 20; + $lastpage = 1; + + for ($page = 1; $page <= $lastpage; $page++) { + $link = $baseUri.'/'.$this->category.'-wallpaper/'.(!empty($this->subcategory)?$this->subcategory.'-wallpaper/':'').'desktop-wallpaper-'.$page.'.html'; + $html = file_get_html($link) or $this->returnError('No results for this query.', 404); + + if ($page === 1) { + preg_match('/-(\d+)\.html$/', $html->find('.pagination > .last', 0)->href, $matches); + $lastpage = min($matches[1], ceil($max/20)); + } + + foreach($html->find('article.item') as $element) { + $wplink = $element->getAttribute('data-permalink'); + if (preg_match('%^http://www\.wallpaperstop\.com/(.+)/([^/]+)-(\d+)\.html$%', $wplink, $matches)) { + $thumbnail = $element->find('img', 0); + + $item = new \Item(); + $item->uri = $baseUri.'/wallpapers/'.str_replace('wallpaper', 'wallpapers', $matches[1]).'/'.$matches[2].'-'.$this->resolution.'-'.$matches[3].'.jpg'; + $item->id = $matches[3]; + $item->timestamp = time(); + $item->title = $thumbnail->title; + $item->thumbnailUri = $baseUri.$thumbnail->src; + $item->content = $item->title.'
'; + $this->items[] = $item; + + $num++; + if ($num >= $max) + break 2; + } + + } + } + } + } + + public function getName(){ + return 'WallpaperStop - '.$this->category.(!empty($this->subcategory) ? ' > '.$this->subcategory : '').' ['.$this->resolution.']'; + } + + public function getURI(){ + return 'http://www.wallpaperstop.com'; + } + + public function getCacheDuration(){ + return 43200; // 12 hours + } +}