From 8a00c9d407f2b4a369da816a1f44cb428d1d2731 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sat, 14 May 2016 12:40:27 +0200 Subject: [PATCH] [Dilbert] Update field retrieval --- bridges/DilbertBridge.php | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/bridges/DilbertBridge.php b/bridges/DilbertBridge.php index 1fa5a24c..e6d34244 100644 --- a/bridges/DilbertBridge.php +++ b/bridges/DilbertBridge.php @@ -3,44 +3,43 @@ class DilbertBridge extends BridgeAbstract { public function loadMetadatas() { - $this->maintainer = "kranack"; - $this->name = "Dilbert Daily Strip"; - $this->uri = "http://dilbert.com/"; - $this->description = "The Unofficial Dilbert Daily Comic Strip"; - $this->update = "14/02/2016"; + $this->maintainer = 'kranack'; + $this->name = $this->getName(); + $this->uri = $this->getURI(); + $this->description = $this->getDescription(); + $this->update = "14/05/2016"; } public function collectData(array $param) { - $html = file_get_html('http://dilbert.com/') or $this->returnError('Could not request Dilbert.', 500); + $html = file_get_html($this->getURI()) or $this->returnError('Could not request Dilbert: '.$this->getURI(), 500); foreach ($html->find('section.comic-item') as $element) { $img = $element->find('img', 0); + $link = $element->find('a', 0); $comic = $img->src; - $title = $img->alt; - $url = $element->find('a', 0)->href; - $author = trim(substr($title, strpos($title, ' - Dilbert by ') + 14)); - $title = trim(substr($title, 0, strpos($title, ' - '))); + $title = $link->alt; + $url = $link->href; $date = substr($url, 25); if (empty($title)) - $title = "Dilbert Comic Strip on ".$date; + $title = 'Dilbert Comic Strip on '.$date; $date = strtotime($date); $item = new \Item(); $item->uri = $url; $item->thumbnailUri = $comic; $item->title = $title; - $item->author = $author; + $item->author = 'Scott Adams'; $item->timestamp = $date; - $item->content = ''.$title.''; + $item->content = ''.$img->alt.''; $this->items[] = $item; } } public function getName() { - return 'Dilbert Bridge'; + return 'Dilbert Daily Strip'; } public function getURI() { @@ -48,7 +47,7 @@ class DilbertBridge extends BridgeAbstract { } public function getDescription() { - return 'Dilbert Daily Strip Bridge'; + return 'The Unofficial Dilbert Daily Comic Strip'; } public function getCacheDuration() {