From 08a349890d1b0c481622de1a364ba37f8cbc4f0f Mon Sep 17 00:00:00 2001 From: nel50n Date: Mon, 2 Mar 2015 22:42:54 +0100 Subject: [PATCH] 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 + } +}