From f036bff6b4836393d5e6b49a5668a5171683fa4c Mon Sep 17 00:00:00 2001 From: ORelio Date: Thu, 22 Oct 2015 14:52:34 +0200 Subject: [PATCH] Add Silicon News bridge --- bridges/SiliconBridge.php | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 bridges/SiliconBridge.php diff --git a/bridges/SiliconBridge.php b/bridges/SiliconBridge.php new file mode 100644 index 00000000..523f33ed --- /dev/null +++ b/bridges/SiliconBridge.php @@ -0,0 +1,75 @@ +', '', $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, '') + 6); + $article_uri = substr($article_uri, 0, strpos($article_uri, '')); + $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 = '

' + .'

'.$article_html->find('div.entry-excerpt', 0)->plaintext.'

' + .$article_html->find('div.entry-content', 0)->innertext; + + //Remove useless scripts left in the page + while (strpos($article_content, '') + 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; + } +}