From c8dccf76a6a2820a1e21f3affec6ed48559a6d01 Mon Sep 17 00:00:00 2001 From: nel50n Date: Mon, 2 Mar 2015 22:22:02 +0100 Subject: [PATCH 1/6] New Format : Media RSS --- formats/MrssFormat.php | 86 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 formats/MrssFormat.php diff --git a/formats/MrssFormat.php b/formats/MrssFormat.php new file mode 100644 index 00000000..0753059f --- /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(); + } +} From 91737f3a9747bda9da75c393a85d81fb14fa6ff2 Mon Sep 17 00:00:00 2001 From: nel50n Date: Mon, 2 Mar 2015 22:42:16 +0100 Subject: [PATCH 2/6] New Bridge : WallPaperStop --- bridges/WallpaperStopBridge.php | 78 +++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 bridges/WallpaperStopBridge.php diff --git a/bridges/WallpaperStopBridge.php b/bridges/WallpaperStopBridge.php new file mode 100644 index 00000000..9d3e20b2 --- /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 + } +} From 08a349890d1b0c481622de1a364ba37f8cbc4f0f Mon Sep 17 00:00:00 2001 From: nel50n Date: Mon, 2 Mar 2015 22:42:54 +0100 Subject: [PATCH 3/6] New Bridge : Unsplash --- bridges/UnsplashBridge.php | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 bridges/UnsplashBridge.php diff --git a/bridges/UnsplashBridge.php b/bridges/UnsplashBridge.php new file mode 100644 index 00000000..791ab4cd --- /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 + } +} From a1ccad3d5f65c89923cc1ca5426ce9a5407e52d2 Mon Sep 17 00:00:00 2001 From: nel50n Date: Tue, 31 Mar 2015 10:47:17 +0200 Subject: [PATCH 4/6] 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 + } +} From 42c94566d11e41ccda6d9f936bd62ab726b52f0e Mon Sep 17 00:00:00 2001 From: nel50n Date: Wed, 8 Apr 2015 14:25:00 +0200 Subject: [PATCH 5/6] New Bridge : HDWallpapers --- bridges/HDWallpapersBridge.php | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 bridges/HDWallpapersBridge.php diff --git a/bridges/HDWallpapersBridge.php b/bridges/HDWallpapersBridge.php new file mode 100644 index 00000000..befdaccc --- /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 + } +} From 466a139ce3020513b2b7424d5da7f66babecc5e2 Mon Sep 17 00:00:00 2001 From: nel50n Date: Wed, 8 Apr 2015 14:25:14 +0200 Subject: [PATCH 6/6] New Bridge : SuperbWallpapers --- bridges/SuperbWallpapersBridge.php | 67 ++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 bridges/SuperbWallpapersBridge.php diff --git a/bridges/SuperbWallpapersBridge.php b/bridges/SuperbWallpapersBridge.php new file mode 100644 index 00000000..c437d924 --- /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 + } +}