2015-10-22 15:52:34 +03:00
|
|
|
<?php
|
|
|
|
class SiliconBridge extends BridgeAbstract {
|
|
|
|
|
2015-11-05 14:20:11 +03:00
|
|
|
public function loadMetadatas() {
|
|
|
|
|
|
|
|
$this->maintainer = "ORelio";
|
2016-08-09 21:01:21 +03:00
|
|
|
$this->name = 'Silicon Bridge';
|
|
|
|
$this->uri = 'http://www.silicon.fr/';
|
2015-11-05 14:20:11 +03:00
|
|
|
$this->description = "Returns the newest articles.";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
public function collectData(){
|
2015-10-22 15:52:34 +03:00
|
|
|
|
|
|
|
function StripCDATA($string) {
|
|
|
|
$string = str_replace('<![CDATA[', '', $string);
|
|
|
|
$string = str_replace(']]>', '', $string);
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
$feedUrl = 'http://www.silicon.fr/feed';
|
2016-07-08 20:06:35 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM($feedUrl) or $this->returnServerError('Could not request Silicon: '.$feedUrl);
|
2015-10-22 15:52:34 +03:00
|
|
|
$limit = 0;
|
|
|
|
|
|
|
|
foreach($html->find('item') as $element) {
|
|
|
|
if($limit < 5) {
|
|
|
|
|
|
|
|
//Retrieve article Uri and get that page
|
|
|
|
$article_uri = $element->innertext;
|
|
|
|
$article_uri = substr($article_uri, strpos($article_uri, '<link>') + 6);
|
|
|
|
$article_uri = substr($article_uri, 0, strpos($article_uri, '</link>'));
|
2016-07-08 20:06:35 +03:00
|
|
|
$article_html = $this->getSimpleHTMLDOM($article_uri) or $this->returnServerError('Could not request Silicon: '.$article_uri);
|
2015-10-22 15:52:34 +03:00
|
|
|
|
|
|
|
//Build article contents from corresponding elements
|
|
|
|
$thumbnailUri = $element->find('enclosure', 0)->url;
|
|
|
|
$article_content = '<p><img src="'.$thumbnailUri.'" /></p>'
|
|
|
|
.'<p><b>'.$article_html->find('div.entry-excerpt', 0)->plaintext.'</b></p>'
|
|
|
|
.$article_html->find('div.entry-content', 0)->innertext;
|
|
|
|
|
|
|
|
//Remove useless scripts left in the page
|
|
|
|
while (strpos($article_content, '<script') !== false) {
|
|
|
|
$script_section = substr($article_content, strpos($article_content, '<script'));
|
|
|
|
$script_section = substr($script_section, 0, strpos($script_section, '</script>') + 9);
|
|
|
|
$article_content = str_replace($script_section, '', $article_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Build and add final item
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
|
|
|
$item['uri'] = $article_uri;
|
|
|
|
$item['title'] = StripCDATA($element->find('title', 0)->innertext);
|
|
|
|
$item['author'] = StripCDATA($element->find('dc:creator', 0)->innertext);
|
|
|
|
$item['timestamp'] = strtotime($element->find('pubDate', 0)->plaintext);
|
|
|
|
$item['content'] = $article_content;
|
2015-10-22 15:52:34 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
$limit++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration() {
|
|
|
|
return 1800; // 30 minutes
|
|
|
|
}
|
|
|
|
}
|