diff --git a/bridges/FM4Bridge.php b/bridges/FM4Bridge.php new file mode 100644 index 00000000..6f59e80f --- /dev/null +++ b/bridges/FM4Bridge.php @@ -0,0 +1,66 @@ + array( + 'name' => 'Tag (author, category, ...)', + 'title' => 'Tag to retrieve', + 'exampleValue' => 'musik' + ), + 'loadcontent' => array( + 'name' => 'Load Full Article Content', + 'title' => 'Retrieve full content of articles (may take longer)', + 'type' => 'checkbox' + ), + 'pages' => array( + 'name' => 'Pages', + 'title' => 'Amount of pages to load', + 'type' => 'number', + 'defaultValue' => 1 + ) + ) + ); + + public function getPageData($tag, $page) { + if($tag) + $uri = self::URI . "/tags/" . $tag; + else + $uri = self::URI; + + $uri = $uri . '?page=' . $page; + + $html = getSimpleHTMLDOM($uri) + or returnServerError('Error while downloading the website content'); + + $page_items = array(); + + foreach ($html->find('div[class*=listItem]') as $article) { + $item = array(); + + $item['uri'] = $article->find('a', 0)->href; + $item['title'] = $article->find('h2', 0)->plaintext; + $item['author'] = $article->find('p[class*=keyword]', 0)->plaintext; + $item["timestamp"] = strtotime($article->find('p[class*=time]', 0)->plaintext); + + if ($this->getInput('loadcontent')) { + $item['content'] = getSimpleHTMLDOM($item['uri'])->find('div[class=storyText]', 0)->innertext + or returnServerError('Error while downloading the full article'); + } + + $page_items[] = $item; + } + return $page_items; + } + public function collectData() { + for ($cur_page = 1; $cur_page <= $this->getInput('pages'); $cur_page++) { + $this->items = array_merge($this->items,$this->getPageData($this->getInput('tag'), $cur_page)); + } + } +}