From 16bd2aec7a69b98b4b55002a3ba6f54805906359 Mon Sep 17 00:00:00 2001 From: killruana Date: Wed, 15 May 2019 21:51:23 +0200 Subject: [PATCH] [MediapartBridge] Add new bridge (#1130) * If no cookie session is defined, use the default rss stream * Add a parameter for enabling/disabling the single page mode --- bridges/MediapartBridge.php | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 bridges/MediapartBridge.php diff --git a/bridges/MediapartBridge.php b/bridges/MediapartBridge.php new file mode 100644 index 00000000..15d1d3ea --- /dev/null +++ b/bridges/MediapartBridge.php @@ -0,0 +1,60 @@ + array( + 'name' => 'Single page article', + 'type' => 'checkbox', + 'title' => 'Display long articles on a single page', + 'defaultValue' => 'checked' + ), + 'mpsessid' => array( + 'name' => 'MPSESSID', + 'type' => 'text', + 'title' => 'Value of the session cookie MPSESSID' + ) + ) + ); + const CACHE_TIMEOUT = 7200; // 2h + const DESCRIPTION = 'Returns the newest articles.'; + + public function collectData() { + $url = self::URI . 'articles/feed'; + $this->collectExpandableDatas($url); + } + + protected function parseItem($newsItem) { + $item = parent::parseItem($newsItem); + + // Enable single page mode? + if ($this->getInput('single_page_mode') === true) { + $item['uri'] .= '?onglet=full'; + } + + // If a session cookie is defined, get the full article + $mpsessid = $this->getInput('mpsessid'); + if (!empty($mpsessid)) { + // Set the session cookie + $opt = array(); + $opt[CURLOPT_COOKIE] = 'MPSESSID=' . $mpsessid; + + // Get the page + $articlePage = getSimpleHTMLDOM( + $newsItem->link . '?onglet=full', + array(), + $opt); + + // Extract the article content + $content = $articlePage->find('div.content-article', 0)->innertext; + $content = sanitize($content); + $content = defaultLinkTo($content, static::URI); + $item['content'] .= $content; + } + + return $item; + } +}