rss-bridge/bridges/CADBridge.php

67 lines
1.8 KiB
PHP
Raw Normal View History

2015-04-28 20:28:49 +03:00
<?php
class CADBridge extends BridgeAbstract{
const MAINTAINER = "nyutag";
const NAME = "CAD Bridge";
const URI = "http://www.cad-comic.com/";
const DESCRIPTION = "Returns the newest articles.";
private function CADExtractContent($url) {
$html3 = $this->getSimpleHTMLDOM($url);
// The request might fail due to missing https support or wrong URL
if($html3 == false)
return 'Daily comic not released yet';
2015-05-06 10:53:21 +03:00
$htmlpart = explode("/", $url);
switch ($htmlpart[3]){
case 'cad':
preg_match_all("/http:\/\/cdn2\.cad-comic\.com\/comics\/cad-\S*png/", $html3, $url2);
break;
case 'sillies':
preg_match_all("/http:\/\/cdn2\.cad-comic\.com\/comics\/sillies-\S*gif/", $html3, $url2);
break;
default:
return 'Daily comic not released yet';
}
2015-04-28 20:28:49 +03:00
$img = implode ($url2[0]);
2015-05-06 10:53:21 +03:00
$html3->clear();
unset ($html3);
if ($img == '')
return 'Daily comic not released yet';
2015-05-06 10:53:21 +03:00
return '<img src="'.$img.'"/>';
}
public function collectData(){
function CADUrl($string) {
$html2 = explode("\"", $string);
$string = $html2[1];
if (substr($string,0,4) != 'http')
return 'notanurl';
return $string;
}
$html = $this->getSimpleHTMLDOM('http://cdn2.cad-comic.com/rss.xml') or $this->returnServerError('Could not request CAD.');
2015-04-28 20:28:49 +03:00
$limit = 0;
2015-04-28 20:28:49 +03:00
foreach($html->find('item') as $element) {
if($limit < 5) {
$item = array();
$item['title'] = $element->find('title', 0)->innertext;
$item['uri'] = CADUrl($element->find('description', 0)->innertext);
if ($item['uri'] != 'notanurl') {
$item['timestamp'] = strtotime($element->find('pubDate', 0)->plaintext);
$item['content'] = $this->CADExtractContent($item['uri']);
$this->items[] = $item;
$limit++;
}
}
2015-04-28 20:28:49 +03:00
}
}
2015-04-28 20:28:49 +03:00
public function getCacheDuration(){
return 3600*2; // 2 hours
}
2015-04-28 20:28:49 +03:00
}
?>