-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TheFarSideBridge] Add bridge (#1484)
- Loading branch information
1 parent
579bfa6
commit 5966cc0
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?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 = array(); | ||
|
||
const CACHE_TIMEOUT = 3600; // 1 hour | ||
|
||
public function collectData() { | ||
$html = getSimpleHTMLDOM(self::URI) | ||
or returnServerError('Could not request: ' . self::URI); | ||
|
||
$div = $html->find('div.tfs-page-container__cows', 0); | ||
|
||
$item = array(); | ||
$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, array('Referer: ' . self::URI)) | ||
or returnServerError('Could not request: ' . $imageUrl); | ||
|
||
// 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; | ||
} | ||
} |