From df80500c513cc09f3169b30a6d2df6686c08abd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Mon, 29 Aug 2016 11:52:13 +0200 Subject: [PATCH] [JapanExpoBridge] code simplification + use checkbox instead of list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/JapanExpoBridge.php | 43 ++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/bridges/JapanExpoBridge.php b/bridges/JapanExpoBridge.php index 0a722bbc..b02304a9 100644 --- a/bridges/JapanExpoBridge.php +++ b/bridges/JapanExpoBridge.php @@ -7,12 +7,8 @@ class JapanExpoBridge extends HttpCachingBridgeAbstract { public $description = 'Returns most recent entries from Japan Expo actualités.'; public $parameters = array( array( 'mode'=>array( - 'name'=>'Mode', - 'type'=>'list', - 'values'=>array( - 'Titles only'=>'light', - 'Full Contents'=>'full' - ) + 'name'=>'Show full contents', + 'type'=>'checkbox', ) )); @@ -46,9 +42,9 @@ class JapanExpoBridge extends HttpCachingBridgeAbstract { } }; - $link = 'http://www.japan-expo-paris.com/fr/actualites'; - $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request JapanExpo: '.$link); - $fullcontent = (!empty($this->getInput('mode')) && $this->getInput('mode') == 'full'); + $html = $this->getSimpleHTMLDOM($this->uri) + or $this->returnServerError('Could not request JapanExpo: '.$this->uri); + $fullcontent = $this->getInput('mode'); $count = 0; foreach ($html->find('a._tile2') as $element) { @@ -60,22 +56,21 @@ class JapanExpoBridge extends HttpCachingBridgeAbstract { $thumbnail = trim($img_search_result[1], "'"); if ($fullcontent) { - if ($count < 5) { - if($this->get_cached_time($url) <= strtotime('-24 hours')) - $this->remove_from_cache($url); - - $article_html = $this->get_cached($url) or $this->returnServerError('Could not request JapanExpo: '.$url); - $header = $article_html->find('header.pageHeadBox', 0); - $timestamp = strtotime($header->find('time', 0)->datetime); - $title_html = $header->find('div.section', 0)->next_sibling(); - $title = $title_html->plaintext; - $headings = $title_html->next_sibling()->outertext; - $article = $article_html->find('div.content', 0)->innertext; - $article = preg_replace_callback('/]+ style="[^\(]+\(\'([^\']+)\'[^>]+>/i', $convert_article_images, $article); - $content = $headings.$article; - } else { - break; + if ($count >= 5) { + break; } + if($this->get_cached_time($url) <= strtotime('-24 hours')) + $this->remove_from_cache($url); + + $article_html = $this->get_cached($url) or $this->returnServerError('Could not request JapanExpo: '.$url); + $header = $article_html->find('header.pageHeadBox', 0); + $timestamp = strtotime($header->find('time', 0)->datetime); + $title_html = $header->find('div.section', 0)->next_sibling(); + $title = $title_html->plaintext; + $headings = $title_html->next_sibling()->outertext; + $article = $article_html->find('div.content', 0)->innertext; + $article = preg_replace_callback('/]+ style="[^\(]+\(\'([^\']+)\'[^>]+>/i', $convert_article_images, $article); + $content = $headings.$article; } else { $date_text = $element->find('span.date', 0)->plaintext; $timestamp = french_pubdate_to_timestamp($date_text);