From 5144c83c95f901a5ce6d06c53999facfeea3aae7 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Sat, 7 Feb 2015 14:25:38 -0500 Subject: [PATCH] Add support for Zataz website. It gets the last 5 articles available. The feed is missing images since hot-linking is impossible from host. We might need a way to grab and store that content as well. --- bridges/ZatazBridge.php | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 bridges/ZatazBridge.php diff --git a/bridges/ZatazBridge.php b/bridges/ZatazBridge.php new file mode 100644 index 0000000..b5affbc --- /dev/null +++ b/bridges/ZatazBridge.php @@ -0,0 +1,55 @@ +getURI()) or $this->returnError('Could not request ' . $this->getURI(), 404); + + $recent_posts = $html->find('#recent-posts-3', 0)->find('ul', 0)->find('li'); + foreach ($recent_posts as $article) { + if (count($this->items) < 5) { + $uri = $article->find('a', 0)->href; + $this->items[] = $this->getDetails($uri); + } + } + } + + private function getDetails($uri) { + $html = file_get_html($uri) or exit; + + $item = new \Item(); + + $article = $html->find('.gdl-blog-full', 0); + $item->uri = $uri; + $item->title = $article->find('.blog-title', 0)->find('a', 0)->innertext; + $item->content = $article->find('.blog-content', 0)->innertext; + $item->timestamp = $this->getTimestampFromDate($article->find('.blog-date', 0)->find('a', 0)->href); + return $item; + } + + private function getTimestampFromDate($uri) { + preg_match('/\d{4}\/\d{2}\/\d{2}/', $uri, $matches); + $date = new \DateTime($matches[0]); + return $date->format('U'); + } + + public function getName() { + return 'Zataz Magazine'; + } + + public function getCacheDuration() { + return 7200; // 2h + } + + public function getURI() { + return 'http://www.zataz.com'; + } + +}