From e3b335b9ff8b3edd2a541e4a085418d8405b4fc9 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sun, 26 Mar 2017 17:56:06 +0200 Subject: [PATCH] [WikiLeaksBridge] Add new bridge This bridge will fetch contents from https://wikileaks.org Available options are: - Category: Defines a list of categories to select from - Show teaser: Defines whether to show the teaser or not Notice: Feeds provided by WikiLeaks do not work, see https://wikileaks.org/wiki/RSS Closes #489 --- bridges/WikiLeaksBridge.php | 129 ++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 bridges/WikiLeaksBridge.php diff --git a/bridges/WikiLeaksBridge.php b/bridges/WikiLeaksBridge.php new file mode 100644 index 00000000..5533d68c --- /dev/null +++ b/bridges/WikiLeaksBridge.php @@ -0,0 +1,129 @@ + array( + 'name' => 'Category', + 'type' => 'list', + 'required' => true, + 'title' => 'Select your category', + 'values' => array( + 'News' => '-News-', + 'Leaks' => array( + 'All' => '-Leaks-', + 'Intelligence' => '+-Intelligence-+', + 'Global Economy' => '+-Global-Economy-+', + 'International Politics' => '+-International-Politics-+', + 'Corporations' => '+-Corporations-+', + 'Government' => '+-Government-+', + 'War & Military' => '+-War-Military-+' + ) + ), + 'defaultValue' => 'news' + ), + 'teaser' => array( + 'name' => 'Show teaser', + 'type' => 'checkbox', + 'required' => false, + 'title' => 'If checked feeds will display the teaser', + 'defaultValue' => true + ) + ) + ); + + public function collectData(){ + $html = getSimpleHTMLDOM($this->getURI()); + + // News are presented differently + switch($this->getInput('category')){ + case '-News-': + $this->loadNewsItems($html); + break; + default: + $this->loadLeakItems($html); + } + } + + public function getURI(){ + if(!is_null($this->getInput('category'))){ + return static::URI . '/' . $this->getInput('category') . '.html'; + } + + return parent::getURI(); + } + + public function getName(){ + if(!is_null($this->getInput('category'))){ + $category = array_search( + $this->getInput('category'), + static::PARAMETERS[0]['category']['values'] + ); + + if($category === false){ + $category = array_search( + $this->getInput('category'), + static::PARAMETERS[0]['category']['values']['Leaks'] + ); + } + + return $category . ' - ' . static::NAME; + } + + return parent::getName(); + } + + private function loadNewsItems($html){ + $articles = $html->find('div.news-articles ul li'); + + if(is_null($articles) || count($articles) === 0){ + return; + } + + foreach($articles as $article){ + $item = array(); + + $item['title'] = $article->find('h3', 0)->plaintext; + $item['uri'] = static::URI . $article->find('h3 a', 0)->href; + $item['content'] = $article->find('div.introduction', 0)->plaintext; + $item['timestamp'] = strtotime($article->find('div.timestamp', 0)->plaintext); + + $this->items[] = $item; + } + } + + private function loadLeakItems($html){ + $articles = $html->find('li.tile'); + + if(is_null($articles) || count($articles) === 0){ + return; + } + + foreach($articles as $article){ + $item = array(); + + $item['title'] = $article->find('h2', 0)->plaintext; + $item['uri'] = static::URI . $article->find('a', 0)->href; + + $teaser = static::URI . '/' . $article->find('div.teaser img', 0)->src; + + if($this->getInput('teaser')){ + $item['content'] = '

' + . $article->find('div.intro', 0)->plaintext + . '

'; + } else { + $item['content'] = $article->find('div.intro', 0)->plaintext; + } + + $item['timestamp'] = strtotime($article->find('div.timestamp', 0)->plaintext); + $item['enclosures'] = array($teaser); + + $this->items[] = $item; + } + } +}