Skip to content

Commit

Permalink
[CyanideAndHappiness] Add bridge (#2807)
Browse files Browse the repository at this point in the history
  • Loading branch information
sal0max authored Jun 10, 2022
1 parent 347f9a3 commit de279de
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions bridges/CyanideAndHappinessBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
class CyanideAndHappinessBridge extends BridgeAbstract {
const NAME = 'Cyanide & Happiness';
const URI = 'https://explosm.net/';
const DESCRIPTION = 'The Webcomic from Explosm.';
const MAINTAINER = 'sal0max';
const CACHE_TIMEOUT = 60 * 60 * 2; // 2 hours

public function getIcon() {
return self::URI . 'favicon-32x32.png';
}

public function getURI(){
return self::URI . 'comics/latest#comic';
}

public function collectData() {
$html = getSimpleHTMLDOM($this->getUri());

foreach ($html->find('[class*=ComicImage]') as $element) {
$date = $element->find('[class^=Author__Right] p', 0)->plaintext;
$author = str_replace('by ', '', $element->find('[class^=Author__Right] p', 1)->plaintext);
$image = $element->find('img', 0)->src;
$link = $html->find('[rel=canonical]', 0)->href;

$item = array(
'uid' => $link,
'author' => $author,
'title' => $date,
'uri' => $link . '#comic',
'timestamp' => str_replace('.', '-', $date) . 'T00:00:00Z',
'content' => "<img src=\"$image\" />"
);
$this->items[] = $item;
}
}
}

0 comments on commit de279de

Please sign in to comment.