rss-bridge/bridges/DilbertBridge.php
logmanoriginal 5432cabef5 bridges: Put name/uri directly in bridge metadata
Some bridges used getName() and getURI() to put information into the
metadatas. Instead the metadatas should be initialized with data and
(not yet done) returned by default via getName() and getURI().
2016-08-06 18:07:42 +02:00

53 lines
1.5 KiB
PHP

<?php
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 = "2016-08-06";
}
public function collectData(array $param) {
$html = $this->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 = $link->alt;
$url = $link->href;
$date = substr($url, 25);
if (empty($title))
$title = 'Dilbert Comic Strip on '.$date;
$date = strtotime($date);
$item = new \Item();
$item->uri = $url;
$item->thumbnailUri = $comic;
$item->title = $title;
$item->author = 'Scott Adams';
$item->timestamp = $date;
$item->content = '<img src="'.$comic.'" alt="'.$img->alt.'" />';
$this->items[] = $item;
}
}
public function getName() {
return $this->name;
}
public function getURI() {
return $this->uri;
}
public function getCacheDuration() {
return 21600; // 6 hours
}
}
?>