Merge pull request #304 from LogMANOriginal/DauphineLibereBridge

Dauphine libere bridge
This commit is contained in:
Mitsu 2016-08-02 17:34:02 +02:00 committed by GitHub
commit 0bb11db536

View file

@ -1,5 +1,5 @@
<?php <?php
class DauphineLibereBridge extends BridgeAbstract{ class DauphineLibereBridge extends BridgeAbstract {
public function loadMetadatas() { public function loadMetadatas() {
@ -7,8 +7,7 @@ class DauphineLibereBridge extends BridgeAbstract{
$this->name = "DauphineLibereBridge Bridge"; $this->name = "DauphineLibereBridge Bridge";
$this->uri = "http://www.ledauphine.com/"; $this->uri = "http://www.ledauphine.com/";
$this->description = "Returns the newest articles."; $this->description = "Returns the newest articles.";
$this->update = "05/11/2015"; $this->update = "2016-08-02";
$this->parameters[] = $this->parameters[] =
'[ '[
@ -82,22 +81,31 @@ class DauphineLibereBridge extends BridgeAbstract{
]'; ]';
} }
function ExtractContent($url, $context) {
public function collectData(array $param){ $html2 = $this->file_get_html($url, false, $context);
function ExtractContent($url) {
$html2 = $this->file_get_html($url);
$text = $html2->find('div.column', 0)->innertext; $text = $html2->find('div.column', 0)->innertext;
$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text); $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
return $text; return $text;
} }
public function collectData(array $param){
// Simulate Mozilla user-agent to fix error 403 (Forbidden)
$opts = array('http' =>
array(
'method' => 'GET',
'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'
)
);
$context = stream_context_create($opts);
if (isset($param['u'])) { /* user timeline mode */ if (isset($param['u'])) { /* user timeline mode */
$this->request = $param['u']; $this->request = $param['u'];
$html = $this->file_get_html('http://www.ledauphine.com/'.$this->request.'/rss') or $this->returnError('Could not request DauphineLibere.', 404); $html = $this->file_get_html('http://www.ledauphine.com/'.$this->request.'/rss', false, $context) or $this->returnError('Could not request DauphineLibere.', 404);
} }
else { else {
$html = $this->file_get_html('http://www.ledauphine.com/rss') or $this->returnError('Could not request DauphineLibere.', 404); $html = $this->file_get_html('http://www.ledauphine.com/rss', false, $context) or $this->returnError('Could not request DauphineLibere.', 404);
} }
$limit = 0; $limit = 0;
@ -107,12 +115,11 @@ class DauphineLibereBridge extends BridgeAbstract{
$item->title = $element->find('title', 0)->innertext; $item->title = $element->find('title', 0)->innertext;
$item->uri = $element->find('guid', 0)->plaintext; $item->uri = $element->find('guid', 0)->plaintext;
$item->timestamp = strtotime($element->find('pubDate', 0)->plaintext); $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
$item->content = ExtractContent($item->uri); $item->content = $this->ExtractContent($item->uri, $context);
$this->items[] = $item; $this->items[] = $item;
$limit++; $limit++;
} }
} }
} }
public function getName(){ public function getName(){
@ -125,6 +132,6 @@ class DauphineLibereBridge extends BridgeAbstract{
public function getCacheDuration(){ public function getCacheDuration(){
return 3600*2; // 2 hours return 3600*2; // 2 hours
// return 0; // 2 hours
} }
} }
?>