2016-04-06 16:13:09 +02:00
|
|
|
<?php
|
2017-02-11 16:16:56 +01:00
|
|
|
class EliteDangerousGalnetBridge extends BridgeAbstract {
|
|
|
|
|
|
|
|
const MAINTAINER = 'corenting';
|
|
|
|
const NAME = 'Elite: Dangerous Galnet';
|
|
|
|
const URI = 'https://community.elitedangerous.com/galnet/';
|
|
|
|
const CACHE_TIMEOUT = 7200; // 2h
|
|
|
|
const DESCRIPTION = 'Returns the latest page of news from Galnet';
|
2019-01-03 18:29:29 +01:00
|
|
|
const PARAMETERS = array(
|
|
|
|
array(
|
|
|
|
'language' => array(
|
|
|
|
'name' => 'Language',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => array(
|
|
|
|
'English' => 'en',
|
|
|
|
'French' => 'fr',
|
|
|
|
'German' => 'de'
|
|
|
|
),
|
|
|
|
'defaultValue' => 'en'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2018-10-26 18:07:34 +02:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
public function collectData(){
|
2019-01-03 18:29:29 +01:00
|
|
|
$language = $this->getInput('language');
|
|
|
|
$url = 'https://community.elitedangerous.com/';
|
|
|
|
$url = $url . $language . '/galnet';
|
|
|
|
$html = getSimpleHTMLDOM($url)
|
2017-02-11 16:16:56 +01:00
|
|
|
or returnServerError('Error while downloading the website content');
|
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
foreach($html->find('div.article') as $element) {
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
2016-04-06 16:13:09 +02:00
|
|
|
|
|
|
|
$uri = $element->find('h3 a', 0)->href;
|
2019-01-03 18:29:29 +01:00
|
|
|
$uri = 'https://community.elitedangerous.com/' . $language . $uri;
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['uri'] = $uri;
|
2016-04-06 16:13:09 +02:00
|
|
|
|
2019-01-03 18:29:29 +01:00
|
|
|
$item['title'] = $element->find('h3 a', 0)->plaintext;
|
2016-04-06 16:13:09 +02:00
|
|
|
|
|
|
|
$content = $element->find('p', -1)->innertext;
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content'] = $content;
|
2016-04-06 16:13:09 +02:00
|
|
|
|
|
|
|
$date = $element->find('p.small', 0)->innertext;
|
|
|
|
$article_year = substr($date, -4) - 1286; //Convert E:D date to actual date
|
|
|
|
$date = substr($date, 0, -4) . $article_year;
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['timestamp'] = strtotime($date);
|
2016-04-06 16:13:09 +02:00
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2019-06-16 20:35:24 +02:00
|
|
|
|
|
|
|
//Remove duplicates that sometimes show up on the website
|
|
|
|
$this->items = array_unique($this->items, SORT_REGULAR);
|
2016-04-06 16:13:09 +02:00
|
|
|
}
|
2016-07-08 19:06:35 +02:00
|
|
|
}
|