forked from blallo/rss-bridge
[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);
|
#error_reporting(E_ALL);
|
||||||
class ArstechnicaBridge extends BridgeAbstract {
|
class ArstechnicaBridge extends BridgeAbstract {
|
||||||
|
|
||||||
public function loadMetadatas() {
|
public function loadMetadatas() {
|
||||||
|
|
||||||
$this->maintainer = "prysme";
|
$this->maintainer = "prysme";
|
||||||
$this->name = "ArstechnicaBridge";
|
$this->name = "ArstechnicaBridge";
|
||||||
$this->uri = "http://arstechnica.com";
|
$this->uri = "http://arstechnica.com";
|
||||||
$this->description = "The PC enthusiast's resource. Power users and the tools they love, without computing religion";
|
$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) {
|
||||||
function StripWithDelimiters($string, $start, $end) {
|
while (strpos($string, $start) !== false) {
|
||||||
while (strpos($string, $start) !== false) {
|
$section_to_remove = substr($string, strpos($string, $start));
|
||||||
$section_to_remove = substr($string, strpos($string, $start));
|
$section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
|
||||||
$section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
|
$string = str_replace($section_to_remove, '', $string);
|
||||||
$string = str_replace($section_to_remove, '', $string);
|
} return $string;
|
||||||
} return $string;
|
}
|
||||||
}
|
|
||||||
function StripCDATA($string) {
|
|
||||||
$string = str_replace('<![CDATA[', '', $string);
|
|
||||||
$string = str_replace(']]>', '', $string);
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function ExtractContent($url) {
|
function StripCDATA($string) {
|
||||||
#echo $url;
|
$string = str_replace('<![CDATA[', '', $string);
|
||||||
$html2 = getSimpleHTMLDOM($url);
|
$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)
|
/*foreach ($text->find('<aside id="social-left">') as $node)
|
||||||
{ $node = NULL; }*/
|
{ $node = NULL; }*/
|
||||||
$text = StripWithDelimiters($text->innertext,'<aside id="social-left">','</aside>');
|
$text = $this->StripWithDelimiters($text->innertext,'<aside id="social-left">','</aside>');
|
||||||
$text = StripWithDelimiters($text,'<figcaption class="caption">','</figcaption>');
|
$text = $this->StripWithDelimiters($text,'<figcaption class="caption">','</figcaption>');
|
||||||
$text = StripWithDelimiters($text,'<div class="gallery shortcode-gallery">','</div>');
|
$text = $this->StripWithDelimiters($text,'<div class="gallery shortcode-gallery">','</div>');
|
||||||
//error_log("ICI", 0);
|
//error_log("ICI", 0);
|
||||||
//error_log($text, 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.');
|
public function collectData(array $param) {
|
||||||
$limit = 0;
|
|
||||||
|
|
||||||
foreach($html->find('item') as $element) {
|
$html = $this->getSimpleHTMLDOM('http://feeds.arstechnica.com/arstechnica/index') or $this->returnServerError('Could not request NextInpact.');
|
||||||
if($limit < 5) {
|
$limit = 0;
|
||||||
$item = new \Item();
|
|
||||||
$item->title = StripCDATA($element->find('title', 0)->innertext);
|
foreach($html->find('item') as $element) {
|
||||||
$item->uri = StripCDATA($element->find('guid', 0)->plaintext);
|
if($limit < 5) {
|
||||||
$item->author = StripCDATA($element->find('author', 0)->innertext);
|
$item = new \Item();
|
||||||
$item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
|
$item->title = $this->StripCDATA($element->find('title', 0)->innertext);
|
||||||
$item->content = ExtractContent($item->uri);
|
$item->uri = $this->StripCDATA($element->find('guid', 0)->plaintext);
|
||||||
//$item->content = $item->uri;
|
$item->author = $this->StripCDATA($element->find('author', 0)->innertext);
|
||||||
$this->items[] = $item;
|
$item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
|
||||||
$limit++;
|
$item->content = $this->ExtractContent($item->uri);
|
||||||
}
|
//$item->content = $item->uri;
|
||||||
}
|
$this->items[] = $item;
|
||||||
|
$limit++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public function getCacheDuration() {
|
|
||||||
return 7200; // 2h
|
}
|
||||||
}
|
|
||||||
|
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){
|
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 = '';
|
$html = '';
|
||||||
$limit = 5;
|
$limit = 5;
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
@ -80,7 +77,7 @@ class DailymotionBridge extends BridgeAbstract{
|
||||||
if($count < $limit) {
|
if($count < $limit) {
|
||||||
$item = new \Item();
|
$item = new \Item();
|
||||||
$item->id = str_replace('/video/', '', strtok($element->href, '_'));
|
$item->id = str_replace('/video/', '', strtok($element->href, '_'));
|
||||||
$metadata = getMetadata($item->id);
|
$metadata = $this->getMetadata($item->id);
|
||||||
$item->uri = $metadata['uri'];
|
$item->uri = $metadata['uri'];
|
||||||
$item->title = $metadata['title'];
|
$item->title = $metadata['title'];
|
||||||
$item->timestamp = $metadata['timestamp'];
|
$item->timestamp = $metadata['timestamp'];
|
||||||
|
|
Loading…
Reference in a new issue