diff --git a/bridges/HDWallpapersBridge.php b/bridges/HDWallpapersBridge.php new file mode 100644 index 0000000..befdacc --- /dev/null +++ b/bridges/HDWallpapersBridge.php @@ -0,0 +1,73 @@ +category = $param['c'] ?: 'latest_wallpapers'; // Latest default + $this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default + + $category = $this->category; + if (strrpos($category, 'wallpapers') !== strlen($category)-strlen('wallpapers')) { + $category .= '-desktop-wallpapers'; + } + + $num = 0; + $max = $param['m'] ?: 14; + $lastpage = 1; + + for ($page = 1; $page <= $lastpage; $page++) { + $link = $baseUri.'/'.$category.'/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('.pagination a', -2)->href, $matches); + $lastpage = min($matches[1], ceil($max/14)); + } + + foreach($html->find('.wallpapers .wall a') as $element) { + $thumbnail = $element->find('img', 0); + + $item = new \Item(); + // http://www.hdwallpapers.in/download/yosemite_reflections-1680x1050.jpg + $item->uri = $baseUri.'/download'.str_replace('wallpapers.html', $this->resolution.'.jpg', $element->href); + $item->timestamp = time(); + $item->title = $element->find('p', 0)->text(); + $item->thumbnailUri = $baseUri.$thumbnail->src; + $item->content = $item->title.'
'; + $this->items[] = $item; + + $num++; + if ($num >= $max) + break 2; + } + } + } + + public function getName(){ + return 'HDWallpapers - '.str_replace(['__', '_'], [' & ', ' '], $this->category).' ['.$this->resolution.']'; + } + + public function getURI(){ + return 'http://www.hdwallpapers.in'; + } + + public function getCacheDuration(){ + return 43200; // 12 hours + } +} diff --git a/bridges/PickyWallpapersBridge.php b/bridges/PickyWallpapersBridge.php new file mode 100644 index 0000000..1f47a5c --- /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 + } +} diff --git a/bridges/SuperbWallpapersBridge.php b/bridges/SuperbWallpapersBridge.php new file mode 100644 index 0000000..c437d92 --- /dev/null +++ b/bridges/SuperbWallpapersBridge.php @@ -0,0 +1,67 @@ +category = $param['c'] ?: ''; // All default + $this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default + + $num = 0; + $max = $param['m'] ?: 36; + $lastpage = 1; + + // Get last page number + $link = $baseUri.'/'.$this->category.'/9999.html'; + $html = file_get_html($link); + $lastpage = min($html->find('.paging .cpage', 0)->innertext(), ceil($max/36)); + + for ($page = 1; $page <= $lastpage; $page++) { + $link = $baseUri.'/'.$this->category.'/'.$page.'.html'; + $html = file_get_html($link) or $this->returnError('No results for this query.', 404); + + foreach($html->find('.wpl .i a') as $element) { + $thumbnail = $element->find('img', 0); + + $item = new \Item(); + $item->uri = str_replace('200x125', $this->resolution, $thumbnail->src); + $item->timestamp = time(); + $item->title = $element->title; + $item->thumbnailUri = $thumbnail->src; + $item->content = $item->title.'
'.$thumbnail.''; + $this->items[] = $item; + + $num++; + if ($num >= $max) + break 2; + } + } + } + + public function getName(){ + return 'HDWallpapers - '.$this->category.' ['.$this->resolution.']'; + } + + public function getURI(){ + return 'http://www.superbwallpapers.com'; + } + + public function getCacheDuration(){ + return 43200; // 12 hours + } +} diff --git a/bridges/UnsplashBridge.php b/bridges/UnsplashBridge.php new file mode 100644 index 0000000..791ab4c --- /dev/null +++ b/bridges/UnsplashBridge.php @@ -0,0 +1,67 @@ +returnError('No results for this query.', 404); + + if ($page === 1) { + preg_match('/=(\d+)$/', $html->find('.pagination > a[!class]', -1)->href, $matches); + $lastpage = min($matches[1], ceil($max/40)); + } + + foreach($html->find('.photo') as $element) { + $thumbnail = $element->find('img', 0); + $thumbnail->src = str_replace('https://', 'http://', $thumbnail->src); + + $item = new \Item(); + $item->uri = str_replace(array('q=75', 'w=400'), + array("q=$quality", "w=$width"), + $thumbnail->src).'.jpg'; // '.jpg' only for format hint + $item->timestamp = time(); + $item->title = $thumbnail->alt; + $item->thumbnailUri = $thumbnail->src; + $item->content = $item->title.'
'; + $this->items[] = $item; + + $num++; + if ($num >= $max) + break 2; + } + } + } + + public function getName(){ + return 'Unsplash'; + } + + public function getURI(){ + return 'http://unsplash.com'; + } + + public function getCacheDuration(){ + return 43200; // 12 hours + } +} 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 + } +} diff --git a/formats/MrssFormat.php b/formats/MrssFormat.php new file mode 100644 index 0000000..0753059 --- /dev/null +++ b/formats/MrssFormat.php @@ -0,0 +1,86 @@ +getExtraInfos(); + $title = htmlspecialchars($extraInfos['name']); + $uri = htmlspecialchars($extraInfos['uri']); + $icon = 'http://g.etfv.co/'. $uri .'?icon.jpg'; + + $items = ''; + foreach($this->getDatas() as $data){ + $itemTitle = strip_tags(is_null($data->title) ? '' : $data->title); + $itemUri = is_null($data->uri) ? '' : $data->uri; + $itemThumbnailUri = is_null($data->thumbnailUri) ? '' : $data->thumbnailUri; + $itemTimestamp = is_null($data->timestamp) ? '' : date(DATE_RFC2822, $data->timestamp); + // We prevent content from closing the CDATA too early. + $itemContent = is_null($data->content) ? '' : htmlspecialchars($this->sanitizeHtml(str_replace(']]>','',$data->content))); + + $items .= << + {$itemTitle} + {$itemUri} + {$itemUri} + {$itemTimestamp} + {$itemContent} + {$itemTitle} + + + +EOD; + } + + /* + TODO : + - Security: Disable Javascript ? + - : Define new extra info ? + - : RFC look with xhtml, keep this in spite of ? + */ + + /* Data are prepared, now let's begin the "MAGIE !!!" */ + $toReturn = ''; + $toReturn .= << + + {$title} + {$uri}/ + {$title} + + {$items} + + +EOD; + + // Remove invalid non-UTF8 characters + + // We cannot use iconv because of a bug in some versions of iconv. + // See http://www.php.net/manual/fr/function.iconv.php#108643 + //$toReturn = iconv("UTF-8", "UTF-8//IGNORE", $toReturn); + // So we use mb_convert_encoding instead: + ini_set('mbstring.substitute_character', 'none'); + $toReturn= mb_convert_encoding($toReturn, 'UTF-8', 'UTF-8'); + return $toReturn; + } + + public function display(){ + $this + ->setContentType('application/rss+xml; charset=UTF-8') // We force UTF-8 in RSS output. + ->callContentType(); + + return parent::display(); + } +}