Merge pull request #128 from Nyutag/master

[new] ReporterreBridge
+ fixes [CADBridge] [CommonDreamsBridge]
This commit is contained in:
Mitsu 2015-07-30 11:59:53 +02:00
commit d39336525d
3 changed files with 72 additions and 7 deletions

View file

@ -23,21 +23,29 @@ class CADBridge extends BridgeAbstract{
function CADExtractContent($url) {
$html3 = 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]);
return $img;
$html3->clear();
unset ($html3);
if ($img == '')
return 'Daily comic not realease yet';
return '<img src="'.$img.'"/>';
}
$html = 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 < 3) {
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 = '<img src="'.CADExtractContent($item->uri).'"/>';
$item->content = CADExtractContent($item->uri);
$this->items[] = $item;
$limit++;
}

View file

@ -22,13 +22,15 @@ class CommonDreamsBridge extends BridgeAbstract{
function CommonDreamsExtractContent($url) {
$html3 = file_get_html($url);
$text = $html3->find('div[class=field--type-text-with-summary]', 0)->innertext;
$html3->clear();
unset ($html3);
return $text;
}
$html = file_get_html('http://www.commondreams.org/rss.xml') or $this->returnError('Could not request CommonDreams.', 404);
$limit = 0;
foreach($html->find('item') as $element) {
if($limit < 2) {
if($limit < 4) {
$item = new \Item();
$item->title = $element->find('title', 0)->innertext;
$item->uri = CommonDreamsUrl($element->find('guid', 0)->innertext);
@ -50,7 +52,7 @@ class CommonDreamsBridge extends BridgeAbstract{
}
public function getCacheDuration(){
// return 3600*2; // 2 hours
return 0;
return 3600; // 1 hours
// return 0;
}
}

View file

@ -0,0 +1,55 @@
<?php
/**
* RssBridgeReporterre
* Returns the newest article
* 2015-04-07
*
* @name Reporterre Bridge
* @homepage http://www.reporterre.net/
* @description Returns the newest articles.
* @maintainer nyutag
*/
class ReporterreBridge extends BridgeAbstract{
public function collectData(array $param){
function ExtractContentReporterre($url) {
$html2 = file_get_html($url);
foreach($html2->find('div[style=text-align:justify]') as $e) {
$text = $e->outertext;
}
$html2->clear();
unset ($html2);
return $text;
}
$html = file_get_html('http://www.reporterre.net/spip.php?page=backend') or $this->returnError('Could not request Reporterre.', 404);
$limit = 0;
foreach($html->find('item') as $element) {
if($limit < 5) {
$item = new \Item();
$item->title = html_entity_decode($element->find('title', 0)->plaintext);
$item->timestamp = strtotime($element->find('dc:date', 0)->plaintext);
$item->uri = $element->find('guid', 0)->innertext;
$item->content = html_entity_decode(ExtractContentReporterre($item->uri));
$this->items[] = $item;
$limit++;
}
}
}
public function getName(){
return 'Reporterre Bridge';
}
public function getURI(){
return 'http://www.reporterre.net/';
}
public function getCacheDuration(){
return 3600; // 1 hours
// return 0;
}
}