1
0
Fork 0
forked from blallo/rss-bridge

Merge pull request #25 from gsurrel/master

Added bridges for Wikipedia FR, EN and EO
This commit is contained in:
Sébastien SAUVAGE 2014-02-01 05:05:44 -08:00
commit b51030d003
3 changed files with 121 additions and 0 deletions

41
bridges/WikipediaENBridge.php Executable file
View file

@ -0,0 +1,41 @@
<?php
/**
* RssBridgeWikipediaEN
* Retrieve latest highlighted articles from Wikipedia in English.
*
* @name Wikipedia EN "Today's Featured Article..."
* @description Returns the highlighted en.wikipedia.org article.
*/
class WikipediaENBridge extends BridgeAbstract{
public function collectData(array $param){
$html = '';
$host = 'http://en.wikipedia.org';
// If you want HTTPS access instead, uncomment the following line:
//$host = 'https://en.wikipedia.org';
$link = '/wiki/Main_Page';
$html = file_get_html($host.$link) or $this->returnError('Could not request Wikipedia EN.', 404);
$element = $html->find('div[id=mp-tfa]', 0);
// Clean the bottom of the featured article
$element->find('div', -1)->outertext = '';
$item = new \Item();
$item->uri = $host.$element->find('p', 0)->find('a', 0)->href;
$item->title = $element->find('p',0)->find('a',0)->title;
$item->content = str_replace('href="/', 'href="'.$host.'/', $element->innertext);
$this->items[] = $item;
}
public function getName(){
return 'Wikipedia EN "Today\'s Featued Article"';
}
public function getURI(){
return 'https://en.wikipedia.org/wiki/Main_Page';
}
public function getCacheDuration(){
return 3600*4; // 4 hours
}
}

View file

@ -0,0 +1,41 @@
<?php
/**
* RssBridgeWikipediaEO
* Retrieve latest highlighted articles from Wikipedia in Esperanto.
*
* @name Wikipedia EO "Artikolo de la semajno"
* @description Returns the highlighted eo.wikipedia.org article.
*/
class WikipediaEOBridge extends BridgeAbstract{
public function collectData(array $param){
$html = '';
$host = 'http://eo.wikipedia.org';
// If you want HTTPS access instead, uncomment the following line:
//$host = 'https://eo.wikipedia.org';
$link = '/wiki/Vikipedio:%C4%88efpa%C4%9Do';
$html = file_get_html($host.$link) or $this->returnError('Could not request Wikipedia EO.', 404);
$element = $html->find('div[id=mf-tfa]', 0);
// Link to article
$link = $element->find('p', -2)->find('a', 0);
$item = new \Item();
$item->uri = $host.$link->href;
$item->title = $link->title;
$item->content = str_replace('href="/', 'href="'.$host.'/', $element->innertext);
$this->items[] = $item;
}
public function getName(){
return 'Wikipedia EO "Artikolo de la semajno"';
}
public function getURI(){
return 'https://eo.wikipedia.org/wiki/Vikipedio:%C4%88efpa%C4%9Do';
}
public function getCacheDuration(){
return 3600*12; // 12 hours
}
}

39
bridges/WikipediaFRBridge.php Executable file
View file

@ -0,0 +1,39 @@
<?php
/**
* RssBridgeWikipediaFR
* Retrieve latest highlighted articles from Wikipedia in French.
*
* @name Wikipedia FR "Lumière sur..."
* @description Returns the highlighted fr.wikipedia.org article.
*/
class WikipediaFRBridge extends BridgeAbstract{
public function collectData(array $param){
$html = '';
$host = 'http://fr.wikipedia.org';
// If you want HTTPS access instead, uncomment the following line:
//$host = 'https://fr.wikipedia.org';
$link = '/wiki/Wikip%C3%A9dia:Accueil_principal';
$html = file_get_html($host.$link) or $this->returnError('Could not request Wikipedia FR.', 404);
$element = $html->find('div[id=accueil-lumieresur]', 0);
$item = new \Item();
$item->uri = $host.$element->find('p', 0)->find('a', 0)->href;
$item->title = $element->find('p',0)->find('a',0)->title;
$item->content = str_replace('href="/', 'href="'.$host.'/', $element->find('div[id=mf-lumieresur]', 0)->innertext);
$this->items[] = $item;
}
public function getName(){
return 'Wikipedia FR "Lumière sur..."';
}
public function getURI(){
return 'https://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Accueil_principal';
}
public function getCacheDuration(){
return 3600*4; // 4 hours
}
}