1
0
Fork 0
forked from blallo/rss-bridge

[bridges] extract nested functions

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-08-21 11:46:23 +02:00
parent fd5c8ea658
commit dd1474f154
2 changed files with 65 additions and 66 deletions

View file

@ -12,7 +12,6 @@ class ArstechnicaBridge extends BridgeAbstract {
}
public function collectData(array $param) {
function StripWithDelimiters($string, $start, $end) {
while (strpos($string, $start) !== false) {
$section_to_remove = substr($string, strpos($string, $start));
@ -20,6 +19,7 @@ class ArstechnicaBridge extends BridgeAbstract {
$string = str_replace($section_to_remove, '', $string);
} return $string;
}
function StripCDATA($string) {
$string = str_replace('<![CDATA[', '', $string);
$string = str_replace(']]>', '', $string);
@ -28,38 +28,40 @@ class ArstechnicaBridge extends BridgeAbstract {
function ExtractContent($url) {
#echo $url;
$html2 = getSimpleHTMLDOM($url);
$html2 = $this->getSimpleHTMLDOM($url);
$text = $html2->find("section[id='article-guts']", 0);
/*foreach ($text->find('<aside id="social-left">') as $node)
{ $node = NULL; }*/
$text = StripWithDelimiters($text->innertext,'<aside id="social-left">','</aside>');
$text = StripWithDelimiters($text,'<figcaption class="caption">','</figcaption>');
$text = StripWithDelimiters($text,'<div class="gallery shortcode-gallery">','</div>');
$text = $this->StripWithDelimiters($text->innertext,'<aside id="social-left">','</aside>');
$text = $this->StripWithDelimiters($text,'<figcaption class="caption">','</figcaption>');
$text = $this->StripWithDelimiters($text,'<div class="gallery shortcode-gallery">','</div>');
//error_log("ICI", 0);
//error_log($text, 0);
return $text;
}
public function collectData(array $param) {
$html = $this->getSimpleHTMLDOM('http://feeds.arstechnica.com/arstechnica/index') or $this->returnServerError('Could not request NextInpact.');
$limit = 0;
foreach($html->find('item') as $element) {
if($limit < 5) {
$item = new \Item();
$item->title = StripCDATA($element->find('title', 0)->innertext);
$item->uri = StripCDATA($element->find('guid', 0)->plaintext);
$item->author = StripCDATA($element->find('author', 0)->innertext);
$item->title = $this->StripCDATA($element->find('title', 0)->innertext);
$item->uri = $this->StripCDATA($element->find('guid', 0)->plaintext);
$item->author = $this->StripCDATA($element->find('author', 0)->innertext);
$item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
$item->content = ExtractContent($item->uri);
$item->content = $this->ExtractContent($item->uri);
//$item->content = $item->uri;
$this->items[] = $item;
$limit++;
}
}
}
}
public function getCacheDuration() {
return 7200; // 2h

View file

@ -41,9 +41,6 @@ class DailymotionBridge extends BridgeAbstract{
]';
}
public function collectData(array $param){
function getMetadata($id) {
$metadata=array();
$html2 = $this->getSimpleHTMLDOM('http://www.dailymotion.com/video/'.$id) or $this->returnServerError('Could not request Dailymotion.');
@ -55,7 +52,7 @@ class DailymotionBridge extends BridgeAbstract{
return $metadata;
}
public function collectData(array $param){
$html = '';
$limit = 5;
$count = 0;
@ -80,7 +77,7 @@ class DailymotionBridge extends BridgeAbstract{
if($count < $limit) {
$item = new \Item();
$item->id = str_replace('/video/', '', strtok($element->href, '_'));
$metadata = getMetadata($item->id);
$metadata = $this->getMetadata($item->id);
$item->uri = $metadata['uri'];
$item->title = $metadata['title'];
$item->timestamp = $metadata['timestamp'];