From 9f82adc87bca74def1071567bf2b20e3e774a879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Mon, 29 Aug 2016 22:04:26 +0200 Subject: [PATCH] [RTBFBridge] add getURI() + code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/RTBFBridge.php | 45 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/bridges/RTBFBridge.php b/bridges/RTBFBridge.php index 6097dcf..cee0f0e 100644 --- a/bridges/RTBFBridge.php +++ b/bridges/RTBFBridge.php @@ -1,7 +1,7 @@ getInput('c')) { - $html = $this->getSimpleHTMLDOM('http://www.rtbf.be/auvio/emissions/detail?id='.$this->getInput('c')) or $this->returnServerError('Could not request RTBF.'); + $html = $this->getSimpleHTMLDOM($this->getURI()) + or $this->returnServerError('Could not request RTBF.'); - foreach($html->find('section[id!=widget-ml-avoiraussi-] .rtbf-media-grid article') as $element) { - if($count < $limit) { - $item = array(); - $item['id'] = $element->getAttribute('data-id'); - $item['uri'] = 'http://www.rtbf.be/auvio/detail?id='.$item['id']; - $thumbnailUriSrcSet = explode(',', $element->find('figure .www-img-16by9 img', 0)->getAttribute('data-srcset')); - $thumbnailUriLastSrc = end($thumbnailUriSrcSet); - $thumbnailUri = explode(' ', $thumbnailUriLastSrc)[0]; - $item['title'] = trim($element->find('h3',0)->plaintext) . ' - ' . trim($element->find('h4',0)->plaintext); - $item['timestamp'] = strtotime($element->find('time', 0)->getAttribute('datetime')); - $item['content'] = ''; - $this->items[] = $item; - $count++; - } - } - } - else { - $this->returnClientError('You must specify a series id.'); + foreach($html->find('section[id!=widget-ml-avoiraussi-] .rtbf-media-grid article') as $element) { + if($count >= $limit) { + break; + } + $item = array(); + $item['id'] = $element->getAttribute('data-id'); + $item['uri'] = $this->uri.'detail?id='.$item['id']; + $thumbnailUriSrcSet = explode(',', $element->find('figure .www-img-16by9 img', 0)->getAttribute('data-srcset')); + $thumbnailUriLastSrc = end($thumbnailUriSrcSet); + $thumbnailUri = explode(' ', $thumbnailUriLastSrc)[0]; + $item['title'] = trim($element->find('h3',0)->plaintext) . ' - ' . trim($element->find('h4',0)->plaintext); + $item['timestamp'] = strtotime($element->find('time', 0)->getAttribute('datetime')); + $item['content'] = ''; + $this->items[] = $item; + $count++; } } + public function getURI(){ + return $this->uri.'detail?id='.$this->getInput('c'); + } + public function getName(){ - return (!empty($this->request) ? $this->request .' - ' : '') .'RTBF Bridge'; + return $this->getInput('c') .' - RTBF Bridge'; } public function getCacheDuration(){