Merge pull request #302 from LogMANOriginal/CADBridge

Cad bridge
This commit is contained in:
Mitsu 2016-08-02 14:21:20 +02:00 committed by GitHub
commit dfa6dc33aa

View file

@ -1,18 +1,42 @@
<?php
class CADBridge extends BridgeAbstract{
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 = "2015-04-03";
$this->update = "2016-08-02";
}
function CADExtractContent($url) {
$html3 = $this->file_get_html($url);
// The request might fail due to missing https support or wrong URL
if($html3 == false)
return 'Daily comic not released yet';
$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';
}
$img = implode ($url2[0]);
$html3->clear();
unset ($html3);
if ($img == '')
return 'Daily comic not released yet';
return '<img src="'.$img.'"/>';
}
public function collectData(array $param){
function CADUrl($string) {
$html2 = explode("\"", $string);
$string = $html2[1];
@ -21,23 +45,9 @@ class CADBridge extends BridgeAbstract{
return $string;
}
function CADExtractContent($url) {
$html3 = $this->file_get_html($url);
$htmlpart = explode("/", $url);
if ($htmlpart[3] == 'cad')
preg_match_all("/http:\/\/cdn2\.cad-comic\.com\/comics\/cad-\S*png/", $html3, $url2);
if ($htmlpart[3] == 'sillies')
preg_match_all("/http:\/\/cdn2\.cad-comic\.com\/comics\/sillies-\S*gif/", $html3, $url2);
$img = implode ($url2[0]);
$html3->clear();
unset ($html3);
if ($img == '')
return 'Daily comic not realease yet';
return '<img src="'.$img.'"/>';
}
$html = $this->file_get_html('http://cdn2.cad-comic.com/rss.xml') or $this->returnError('Could not request CAD.', 404);
$limit = 0;
foreach($html->find('item') as $element) {
if($limit < 5) {
$item = new \Item();
@ -45,13 +55,12 @@ class CADBridge extends BridgeAbstract{
$item->uri = CADUrl($element->find('description', 0)->innertext);
if ($item->uri != 'notanurl') {
$item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
$item->content = CADExtractContent($item->uri);
$item->content = $this->CADExtractContent($item->uri);
$this->items[] = $item;
$limit++;
}
}
}
}
public function getName(){
@ -64,6 +73,6 @@ class CADBridge extends BridgeAbstract{
public function getCacheDuration(){
return 3600*2; // 2 hours
// return 0;
}
}
?>