-
Notifications
You must be signed in to change notification settings - Fork 1k
/
TheFarSideBridge.php
52 lines (40 loc) · 1.45 KB
/
TheFarSideBridge.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
class TheFarSideBridge extends BridgeAbstract
{
const NAME = 'The Far Side Bridge';
const URI = 'https://www.thefarside.com';
const DESCRIPTION = 'Returns the daily dose';
const MAINTAINER = 'VerifiedJoseph';
const PARAMETERS = [];
const CACHE_TIMEOUT = 3600; // 1 hour
public function collectData()
{
$html = getSimpleHTMLDOM(self::URI);
$div = $html->find('div.tfs-page-container__cows', 0);
$item = [];
$item['uri'] = $html->find('meta[property="og:url"]', 0)->content;
$item['title'] = $div->find('h3', 0)->innertext;
$item['timestamp'] = $div->find('h3', 0)->innertext;
$item['content'] = '';
foreach ($div->find('div.card-body') as $index => $card) {
$image = $card->find('img', 0);
$imageUrl = $image->attr['data-src'];
// Images are downloaded to bypass the hotlink protection.
$image = getContents($imageUrl, ['Referer: ' . self::URI]);
// Encode image as base64
$imageBase64 = base64_encode($image);
$caption = '';
if ($card->find('figcaption', 0)) {
$caption = $card->find('figcaption', 0)->innertext;
}
$item['content'] .= <<<EOD
<figure>
<img title="{$caption}" src="data:image/jpeg;base64,{$imageBase64}"/>
<figcaption>{$caption}</figcaption>
</figure>
<br/>
EOD;
}
$this->items[] = $item;
}
}