From 58f6a4357499a46e22db581a916aef495e0a52d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sun, 28 Aug 2016 13:00:12 +0200 Subject: [PATCH] [CollegeDeFranceBridge] code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/CollegeDeFranceBridge.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/bridges/CollegeDeFranceBridge.php b/bridges/CollegeDeFranceBridge.php index fc69533..3d9a21c 100644 --- a/bridges/CollegeDeFranceBridge.php +++ b/bridges/CollegeDeFranceBridge.php @@ -30,7 +30,8 @@ class CollegeDeFranceBridge extends BridgeAbstract{ * * */ - $html = $this->getSimpleHTMLDOM('http://www.college-de-france.fr/components/search-audiovideo.jsp?fulltext=&siteid=1156951719600&lang=FR&type=all') or $this->returnServerError('Could not request CollegeDeFrance.'); + $html = $this->getSimpleHTMLDOM($this->uri.'components/search-audiovideo.jsp?fulltext=&siteid=1156951719600&lang=FR&type=all') + or $this->returnServerError('Could not request CollegeDeFrance.'); foreach($html->find('a[data-target]') as $element) { $item = array(); $item['title'] = $element->find('.title', 0)->plaintext; @@ -43,10 +44,25 @@ class CollegeDeFranceBridge extends BridgeAbstract{ // $timezone = new DateTimeZone('Europe/Paris'); // strpos($element->href, '201') will break in 2020 but it'll probably break prior to then due to site changes anyway - $d = DateTime::createFromFormat('!Y-m-d-H\hi', substr($element->href, strpos($element->href, '201'), 16), $timezone) ?: DateTime::createFromFormat('!d m Y', trim(str_replace(array_values($months), array_keys($months), $element->find('.date', 0)->plaintext)), $timezone); - $item['timestamp'] = $d->format('U'); + $d = DateTime::createFromFormat( + '!Y-m-d-H\hi', + substr($element->href, strpos($element->href, '201'), 16), + $timezone + ); + if(!$d){ + $d=DateTime::createFromFormat( + '!d m Y', + trim(str_replace( + array_values($months), + array_keys($months), + $element->find('.date', 0)->plaintext + )), + $timezone + ); + } + $item['timestamp'] = $d->format('U'); $item['content'] = $element->find('.lecturer', 0)->innertext . ' - ' . $element->find('.title', 0)->innertext; - $item['uri'] = 'http://www.college-de-france.fr' . $element->href; + $item['uri'] = $this->uri . $element->href; $this->items[] = $item; } }