mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-26 03:16:33 +03:00
[bridges] extract nested functions
Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
parent
fd5c8ea658
commit
dd1474f154
2 changed files with 65 additions and 66 deletions
|
@ -3,66 +3,68 @@
|
|||
#error_reporting(E_ALL);
|
||||
class ArstechnicaBridge extends BridgeAbstract {
|
||||
|
||||
public function loadMetadatas() {
|
||||
public function loadMetadatas() {
|
||||
|
||||
$this->maintainer = "prysme";
|
||||
$this->name = "ArstechnicaBridge";
|
||||
$this->uri = "http://arstechnica.com";
|
||||
$this->description = "The PC enthusiast's resource. Power users and the tools they love, without computing religion";
|
||||
$this->maintainer = "prysme";
|
||||
$this->name = "ArstechnicaBridge";
|
||||
$this->uri = "http://arstechnica.com";
|
||||
$this->description = "The PC enthusiast's resource. Power users and the tools they love, without computing religion";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function collectData(array $param) {
|
||||
function StripWithDelimiters($string, $start, $end) {
|
||||
while (strpos($string, $start) !== false) {
|
||||
$section_to_remove = substr($string, strpos($string, $start));
|
||||
$section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
|
||||
$string = str_replace($section_to_remove, '', $string);
|
||||
} return $string;
|
||||
}
|
||||
function StripCDATA($string) {
|
||||
$string = str_replace('<![CDATA[', '', $string);
|
||||
$string = str_replace(']]>', '', $string);
|
||||
return $string;
|
||||
}
|
||||
function StripWithDelimiters($string, $start, $end) {
|
||||
while (strpos($string, $start) !== false) {
|
||||
$section_to_remove = substr($string, strpos($string, $start));
|
||||
$section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
|
||||
$string = str_replace($section_to_remove, '', $string);
|
||||
} return $string;
|
||||
}
|
||||
|
||||
function ExtractContent($url) {
|
||||
#echo $url;
|
||||
$html2 = getSimpleHTMLDOM($url);
|
||||
function StripCDATA($string) {
|
||||
$string = str_replace('<![CDATA[', '', $string);
|
||||
$string = str_replace(']]>', '', $string);
|
||||
return $string;
|
||||
}
|
||||
|
||||
$text = $html2->find("section[id='article-guts']", 0);
|
||||
function ExtractContent($url) {
|
||||
#echo $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>');
|
||||
//error_log("ICI", 0);
|
||||
//error_log($text, 0);
|
||||
{ $node = NULL; }*/
|
||||
$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;
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
$html = $this->getSimpleHTMLDOM('http://feeds.arstechnica.com/arstechnica/index') or $this->returnServerError('Could not request NextInpact.');
|
||||
$limit = 0;
|
||||
public function collectData(array $param) {
|
||||
|
||||
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->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
|
||||
$item->content = ExtractContent($item->uri);
|
||||
//$item->content = $item->uri;
|
||||
$this->items[] = $item;
|
||||
$limit++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getCacheDuration() {
|
||||
return 7200; // 2h
|
||||
}
|
||||
$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 = $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 = $this->ExtractContent($item->uri);
|
||||
//$item->content = $item->uri;
|
||||
$this->items[] = $item;
|
||||
$limit++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getCacheDuration() {
|
||||
return 7200; // 2h
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,21 +41,18 @@ class DailymotionBridge extends BridgeAbstract{
|
|||
]';
|
||||
}
|
||||
|
||||
function getMetadata($id) {
|
||||
$metadata=array();
|
||||
$html2 = $this->getSimpleHTMLDOM('http://www.dailymotion.com/video/'.$id) or $this->returnServerError('Could not request Dailymotion.');
|
||||
$metadata['title'] = $html2->find('meta[property=og:title]', 0)->getAttribute('content');
|
||||
$metadata['timestamp'] = strtotime($html2->find('meta[property=video:release_date]', 0)->getAttribute('content') );
|
||||
$metadata['thumbnailUri'] = $html2->find('meta[property=og:image]', 0)->getAttribute('content');
|
||||
$metadata['uri'] = $html2->find('meta[property=og:url]', 0)->getAttribute('content');
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
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.');
|
||||
$metadata['title'] = $html2->find('meta[property=og:title]', 0)->getAttribute('content');
|
||||
$metadata['timestamp'] = strtotime($html2->find('meta[property=video:release_date]', 0)->getAttribute('content') );
|
||||
$metadata['thumbnailUri'] = $html2->find('meta[property=og:image]', 0)->getAttribute('content');
|
||||
$metadata['uri'] = $html2->find('meta[property=og:url]', 0)->getAttribute('content');
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
|
||||
$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'];
|
||||
|
|
Loading…
Reference in a new issue