[EliteDangerousGalnetBridge] Add support for others website languages (#992)

* [EliteDangerousGalnetBridge] Add support for others website languages

* [EliteDangerousGalnetBridge] Fix post title
This commit is contained in:
Corentin Garcia 2019-01-03 18:29:29 +01:00 committed by Teromene
parent 3e45643418
commit f3f33cabed

View file

@ -6,25 +6,36 @@ class EliteDangerousGalnetBridge extends BridgeAbstract {
const URI = 'https://community.elitedangerous.com/galnet/'; const URI = 'https://community.elitedangerous.com/galnet/';
const CACHE_TIMEOUT = 7200; // 2h const CACHE_TIMEOUT = 7200; // 2h
const DESCRIPTION = 'Returns the latest page of news from Galnet'; const DESCRIPTION = 'Returns the latest page of news from Galnet';
const PARAMETERS = array(
public function getIcon() { array(
return 'https://community.elitedangerous.com/sites/ 'language' => array(
EDSITE_COMM/themes/bootstrap/bootstrap_community/favicon.ico'; 'name' => 'Language',
} 'type' => 'list',
'values' => array(
'English' => 'en',
'French' => 'fr',
'German' => 'de'
),
'defaultValue' => 'en'
)
)
);
public function collectData(){ public function collectData(){
$html = getSimpleHTMLDOM(self::URI) $language = $this->getInput('language');
$url = 'https://community.elitedangerous.com/';
$url = $url . $language . '/galnet';
$html = getSimpleHTMLDOM($url)
or returnServerError('Error while downloading the website content'); or returnServerError('Error while downloading the website content');
foreach($html->find('div.article') as $element) { foreach($html->find('div.article') as $element) {
$item = array(); $item = array();
$uri = $element->find('h3 a', 0)->href; $uri = $element->find('h3 a', 0)->href;
$uri = self::URI . substr($uri, strlen('/galnet/')); $uri = 'https://community.elitedangerous.com/' . $language . $uri;
$item['uri'] = $uri; $item['uri'] = $uri;
$title = $element->find('h3 a', 0)->plaintext; $item['title'] = $element->find('h3 a', 0)->plaintext;
$item['title'] = substr($title, 1); //remove the space between icon and title
$content = $element->find('p', -1)->innertext; $content = $element->find('p', -1)->innertext;
$item['content'] = $content; $item['content'] = $content;