forked from RSS-Bridge/rss-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DilbertBridge.php
35 lines (29 loc) · 926 Bytes
/
DilbertBridge.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
class DilbertBridge extends BridgeAbstract {
const MAINTAINER = 'kranack';
const NAME = 'Dilbert Daily Strip';
const URI = 'https://dilbert.com';
const CACHE_TIMEOUT = 21600; // 6h
const DESCRIPTION = 'The Unofficial Dilbert Daily Comic Strip';
public function collectData(){
$html = getSimpleHTMLDOM(self::URI);
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 = $link->href;
$date = substr(strrchr($url, '/'), 1);
if (empty($title))
$title = 'Dilbert Comic Strip on ' . $date;
$date = strtotime($date);
$item = array();
$item['uri'] = $url;
$item['title'] = $title;
$item['author'] = 'Scott Adams';
$item['timestamp'] = $date;
$item['content'] = '<img src="' . $comic . '" alt="' . $img->alt . '" />';
$this->items[] = $item;
}
}
}