rss-bridge/bridges/DilbertBridge.php

58 lines
1.6 KiB
PHP
Raw Normal View History

<?php
2016-02-14 13:43:58 +01:00
class DilbertBridge extends BridgeAbstract {
2016-02-14 13:43:58 +01:00
public function loadMetadatas() {
2016-05-14 12:40:27 +02:00
$this->maintainer = 'kranack';
$this->name = $this->getName();
$this->uri = $this->getURI();
$this->description = $this->getDescription();
$this->update = "14/05/2016";
2016-02-14 13:43:58 +01:00
}
2015-01-30 18:12:28 +01:00
2016-02-14 13:43:58 +01:00
public function collectData(array $param) {
$html = $this->file_get_html($this->getURI()) or $this->returnError('Could not request Dilbert: '.$this->getURI(), 500);
2016-02-14 13:43:58 +01:00
foreach ($html->find('section.comic-item') as $element) {
$img = $element->find('img', 0);
2016-05-14 12:40:27 +02:00
$link = $element->find('a', 0);
2016-02-14 13:43:58 +01:00
$comic = $img->src;
2016-05-14 12:40:27 +02:00
$title = $link->alt;
$url = $link->href;
2016-02-14 13:43:58 +01:00
$date = substr($url, 25);
if (empty($title))
2016-05-14 12:40:27 +02:00
$title = 'Dilbert Comic Strip on '.$date;
2016-02-14 13:43:58 +01:00
$date = strtotime($date);
$item = new \Item();
$item->uri = $url;
$item->thumbnailUri = $comic;
$item->title = $title;
2016-05-14 12:40:27 +02:00
$item->author = 'Scott Adams';
2016-02-14 13:43:58 +01:00
$item->timestamp = $date;
2016-05-14 12:40:27 +02:00
$item->content = '<img src="'.$comic.'" alt="'.$img->alt.'" />';
$this->items[] = $item;
}
}
2016-02-14 13:43:58 +01:00
public function getName() {
2016-05-14 12:40:27 +02:00
return 'Dilbert Daily Strip';
}
2016-02-14 13:43:58 +01:00
public function getURI() {
return 'http://dilbert.com';
}
2016-02-14 13:43:58 +01:00
public function getDescription() {
2016-05-14 12:40:27 +02:00
return 'The Unofficial Dilbert Daily Comic Strip';
}
2016-02-14 13:43:58 +01:00
public function getCacheDuration() {
return 21600; // 6 hours
}
}
?>