Add Silicon News bridge
This commit is contained in:
parent
e7966dd102
commit
f036bff6b4
1 changed files with 75 additions and 0 deletions
75
bridges/SiliconBridge.php
Normal file
75
bridges/SiliconBridge.php
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Silicon Bridge
|
||||||
|
* Returns the newest articles
|
||||||
|
* 2015-09-08
|
||||||
|
*
|
||||||
|
* @name Silicon.fr
|
||||||
|
* @homepage http://www.silicon.fr/
|
||||||
|
* @description Returns the newest articles.
|
||||||
|
* @maintainer ORelio
|
||||||
|
* @update 2015-09-08
|
||||||
|
*/
|
||||||
|
class SiliconBridge extends BridgeAbstract {
|
||||||
|
|
||||||
|
public function collectData(array $param) {
|
||||||
|
|
||||||
|
function StripCDATA($string) {
|
||||||
|
$string = str_replace('<![CDATA[', '', $string);
|
||||||
|
$string = str_replace(']]>', '', $string);
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
|
$feedUrl = 'http://www.silicon.fr/feed';
|
||||||
|
$html = file_get_html($feedUrl) or $this->returnError('Could not request Silicon: '.$feedUrl, 404);
|
||||||
|
$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>'));
|
||||||
|
$article_html = file_get_html($article_uri) or $this->returnError('Could not request Silicon: '.$article_uri, 404);
|
||||||
|
|
||||||
|
//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
|
||||||
|
$item = new \Item();
|
||||||
|
$item->uri = $article_uri;
|
||||||
|
$item->thumbnailUri = $thumbnailUri;
|
||||||
|
$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;
|
||||||
|
$this->items[] = $item;
|
||||||
|
$limit++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName() {
|
||||||
|
return 'Silicon Bridge';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getURI() {
|
||||||
|
return 'http://www.silicon.fr/';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCacheDuration() {
|
||||||
|
return 1800; // 30 minutes
|
||||||
|
// return 0;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue