2015-04-28 19:28:49 +02:00
|
|
|
<?php
|
|
|
|
class CADBridge extends BridgeAbstract{
|
2016-08-02 13:37:18 +02:00
|
|
|
public function loadMetadatas() {
|
|
|
|
$this->maintainer = "nyutag";
|
|
|
|
$this->name = "CAD Bridge";
|
|
|
|
$this->uri = "http://www.cad-comic.com/";
|
|
|
|
$this->description = "Returns the newest articles.";
|
|
|
|
$this->update = "2016-08-02";
|
|
|
|
}
|
2015-11-03 23:28:44 +01:00
|
|
|
|
2016-08-02 13:37:18 +02:00
|
|
|
function CADExtractContent($url) {
|
2016-06-25 23:17:42 +02:00
|
|
|
$html3 = $this->file_get_html($url);
|
2016-08-02 14:07:40 +02:00
|
|
|
|
|
|
|
// The request might fail due to missing https support or wrong URL
|
|
|
|
if($html3 == false)
|
|
|
|
return 'Daily comic not released yet';
|
|
|
|
|
2015-05-06 09:53:21 +02:00
|
|
|
$htmlpart = explode("/", $url);
|
|
|
|
if ($htmlpart[3] == 'cad')
|
2016-08-02 13:37:18 +02:00
|
|
|
preg_match_all("/http:\/\/cdn2\.cad-comic\.com\/comics\/cad-\S*png/", $html3, $url2);
|
2015-05-06 09:53:21 +02:00
|
|
|
if ($htmlpart[3] == 'sillies')
|
2016-08-02 13:37:18 +02:00
|
|
|
preg_match_all("/http:\/\/cdn2\.cad-comic\.com\/comics\/sillies-\S*gif/", $html3, $url2);
|
2015-04-28 19:28:49 +02:00
|
|
|
$img = implode ($url2[0]);
|
2015-05-06 09:53:21 +02:00
|
|
|
$html3->clear();
|
|
|
|
unset ($html3);
|
|
|
|
if ($img == '')
|
2016-08-02 14:07:40 +02:00
|
|
|
return 'Daily comic not released yet';
|
2015-05-06 09:53:21 +02:00
|
|
|
return '<img src="'.$img.'"/>';
|
2016-08-02 13:37:18 +02:00
|
|
|
}
|
2016-08-02 13:25:49 +02:00
|
|
|
|
2016-08-02 13:37:18 +02:00
|
|
|
public function collectData(array $param){
|
2016-08-02 13:25:49 +02:00
|
|
|
function CADUrl($string) {
|
2016-08-02 13:37:18 +02:00
|
|
|
$html2 = explode("\"", $string);
|
|
|
|
$string = $html2[1];
|
|
|
|
if (substr($string,0,4) != 'http')
|
|
|
|
return 'notanurl';
|
|
|
|
return $string;
|
2016-08-02 13:25:49 +02:00
|
|
|
}
|
|
|
|
|
2016-06-25 23:17:42 +02:00
|
|
|
$html = $this->file_get_html('http://cdn2.cad-comic.com/rss.xml') or $this->returnError('Could not request CAD.', 404);
|
2015-04-28 19:28:49 +02:00
|
|
|
$limit = 0;
|
2016-08-02 13:37:18 +02:00
|
|
|
|
2015-04-28 19:28:49 +02:00
|
|
|
foreach($html->find('item') as $element) {
|
2016-08-02 13:37:18 +02:00
|
|
|
if($limit < 5) {
|
|
|
|
$item = new \Item();
|
|
|
|
$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 19:28:49 +02:00
|
|
|
}
|
2016-08-02 13:37:18 +02:00
|
|
|
}
|
2015-04-28 19:28:49 +02:00
|
|
|
|
2016-08-02 13:37:18 +02:00
|
|
|
public function getName(){
|
|
|
|
return 'CAD Bridge';
|
|
|
|
}
|
2015-04-28 19:28:49 +02:00
|
|
|
|
2016-08-02 13:37:18 +02:00
|
|
|
public function getURI(){
|
|
|
|
return 'http://www.cad-comic.com/';
|
|
|
|
}
|
2015-04-28 19:28:49 +02:00
|
|
|
|
2016-08-02 13:37:18 +02:00
|
|
|
public function getCacheDuration(){
|
|
|
|
return 3600*2; // 2 hours
|
|
|
|
}
|
2015-04-28 19:28:49 +02:00
|
|
|
}
|
2016-08-02 13:37:18 +02:00
|
|
|
?>
|