rss-bridge/bridges/BundesbankBridge.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
2.6 KiB
PHP
Raw Normal View History

2018-10-01 19:52:16 +03:00
<?php
class BundesbankBridge extends BridgeAbstract
{
2018-10-01 19:52:16 +03:00
const PARAM_LANG = 'lang';
2018-10-01 19:52:16 +03:00
const LANG_EN = 'en';
const LANG_DE = 'de';
2018-10-01 19:52:16 +03:00
const NAME = 'Bundesbank Bridge';
const URI = 'https://www.bundesbank.de/';
const DESCRIPTION = 'Returns the latest studies of the Bundesbank (Germany)';
const MAINTAINER = 'logmanoriginal';
const CACHE_TIMEOUT = 86400; // 24 hours
2018-10-01 19:52:16 +03:00
const PARAMETERS = [
[
2018-10-01 19:52:16 +03:00
self::PARAM_LANG => [
'name' => 'Language',
'type' => 'list',
'defaultValue' => self::LANG_DE,
'values' => [
'English' => self::LANG_EN,
'Deutsch' => self::LANG_DE
]
]
]
2018-10-01 19:52:16 +03:00
];
public function getIcon()
{
return self::URI . 'resource/crblob/1890/a7f48ee0ae35348748121770ba3ca009/mL/favicon-ico-data.ico';
}
2018-10-01 19:52:16 +03:00
public function getURI()
{
switch ($this->getInput(self::PARAM_LANG)) {
case self::LANG_EN:
return self::URI . 'en/publications/reports/studies';
case self::LANG_DE:
return self::URI . 'de/publikationen/berichte/studien';
}
2018-10-01 19:52:16 +03:00
return parent::getURI();
}
2018-10-01 19:52:16 +03:00
public function collectData()
{
$html = getSimpleHTMLDOM($this->getURI());
2018-10-01 19:52:16 +03:00
$html = defaultLinkTo($html, $this->getURI());
2018-10-01 19:52:16 +03:00
foreach ($html->find('ul.resultlist li') as $study) {
$item = [];
2018-10-01 19:52:16 +03:00
$item['uri'] = $study->find('.teasable__link', 0)->href;
2018-10-01 19:52:16 +03:00
// Get title without child elements (i.e. subtitle)
$title = $study->find('.teasable__title div.h2', 0);
2018-10-01 19:52:16 +03:00
foreach ($title->children as &$child) {
$child->outertext = '';
2018-10-01 19:52:16 +03:00
}
2018-10-01 19:52:16 +03:00
$item['title'] = $title->innertext;
2018-10-01 19:52:16 +03:00
// Add subtitle to the content if it exists
$item['content'] = '';
2018-10-01 19:52:16 +03:00
if ($subtitle = $study->find('.teasable__subtitle', 0)) {
$item['content'] .= '<strong>' . $study->find('.teasable__subtitle', 0)->plaintext . '</strong>';
}
2018-10-01 19:52:16 +03:00
$item['content'] .= '<p>' . $study->find('.teasable__text', 0)->plaintext . '</p>';
2018-10-01 19:52:16 +03:00
$item['timestamp'] = strtotime($study->find('.teasable__date', 0)->plaintext);
2018-10-01 19:52:16 +03:00
// Downloads and older studies don't have images
if ($study->find('.teasable__image', 0)) {
$item['enclosures'] = [
$study->find('.teasable__image img', 0)->src
];
}
2018-10-01 19:52:16 +03:00
$this->items[] = $item;
}
}
}