[Dilbert] Update field retrieval

This commit is contained in:
ORelio 2016-05-14 12:40:27 +02:00
parent a04d7ba8eb
commit 8a00c9d407

View file

@ -3,44 +3,43 @@ class DilbertBridge extends BridgeAbstract {
public function loadMetadatas() { public function loadMetadatas() {
$this->maintainer = "kranack"; $this->maintainer = 'kranack';
$this->name = "Dilbert Daily Strip"; $this->name = $this->getName();
$this->uri = "http://dilbert.com/"; $this->uri = $this->getURI();
$this->description = "The Unofficial Dilbert Daily Comic Strip"; $this->description = $this->getDescription();
$this->update = "14/02/2016"; $this->update = "14/05/2016";
} }
public function collectData(array $param) { 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) { foreach ($html->find('section.comic-item') as $element) {
$img = $element->find('img', 0); $img = $element->find('img', 0);
$link = $element->find('a', 0);
$comic = $img->src; $comic = $img->src;
$title = $img->alt; $title = $link->alt;
$url = $element->find('a', 0)->href; $url = $link->href;
$author = trim(substr($title, strpos($title, ' - Dilbert by ') + 14));
$title = trim(substr($title, 0, strpos($title, ' - ')));
$date = substr($url, 25); $date = substr($url, 25);
if (empty($title)) if (empty($title))
$title = "Dilbert Comic Strip on ".$date; $title = 'Dilbert Comic Strip on '.$date;
$date = strtotime($date); $date = strtotime($date);
$item = new \Item(); $item = new \Item();
$item->uri = $url; $item->uri = $url;
$item->thumbnailUri = $comic; $item->thumbnailUri = $comic;
$item->title = $title; $item->title = $title;
$item->author = $author; $item->author = 'Scott Adams';
$item->timestamp = $date; $item->timestamp = $date;
$item->content = '<img src="'.$comic.'" alt="'.$title.'" />'; $item->content = '<img src="'.$comic.'" alt="'.$img->alt.'" />';
$this->items[] = $item; $this->items[] = $item;
} }
} }
public function getName() { public function getName() {
return 'Dilbert Bridge'; return 'Dilbert Daily Strip';
} }
public function getURI() { public function getURI() {
@ -48,7 +47,7 @@ class DilbertBridge extends BridgeAbstract {
} }
public function getDescription() { public function getDescription() {
return 'Dilbert Daily Strip Bridge'; return 'The Unofficial Dilbert Daily Comic Strip';
} }
public function getCacheDuration() { public function getCacheDuration() {