rss-bridge/bridges/TheFarSideBridge.php

53 lines
1.4 KiB
PHP
Raw Normal View History

2021-04-03 21:31:49 +03:00
<?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 = [];
2021-04-03 21:31:49 +03:00
const CACHE_TIMEOUT = 3600; // 1 hour
2021-04-03 21:31:49 +03:00
public function collectData()
{
$html = getSimpleHTMLDOM(self::URI);
2021-04-03 21:31:49 +03:00
$div = $html->find('div.tfs-page-container__cows', 0);
2021-04-03 21:31:49 +03:00
$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'] = '';
2021-04-03 21:31:49 +03:00
foreach ($div->find('div.card-body') as $index => $card) {
$image = $card->find('img', 0);
$imageUrl = $image->attr['data-src'];
2021-04-03 21:31:49 +03:00
// Images are downloaded to bypass the hotlink protection.
$image = getContents($imageUrl, ['Referer: ' . self::URI]);
2021-04-03 21:31:49 +03:00
// Encode image as base64
$imageBase64 = base64_encode($image);
2021-04-03 21:31:49 +03:00
$caption = '';
2021-04-03 21:31:49 +03:00
if ($card->find('figcaption', 0)) {
$caption = $card->find('figcaption', 0)->innertext;
}
$item['content'] .= <<<EOD
2021-04-03 21:31:49 +03:00
<figure>
<img title="{$caption}" src="data:image/jpeg;base64,{$imageBase64}"/>
<figcaption>{$caption}</figcaption>
</figure>
<br/>
EOD;
}
2021-04-03 21:31:49 +03:00
$this->items[] = $item;
}
2021-04-03 21:31:49 +03:00
}