2017-03-20 21:32:31 +01:00
|
|
|
<?php
|
|
|
|
class RainbowSixSiegeBridge extends BridgeAbstract {
|
|
|
|
|
|
|
|
const MAINTAINER = 'corenting';
|
2020-01-31 14:51:59 +01:00
|
|
|
const NAME = 'Rainbow Six Siege News';
|
|
|
|
const URI = 'https://www.ubisoft.com/en-us/game/rainbow-six/siege/news-updates';
|
2017-03-20 21:32:31 +01:00
|
|
|
const CACHE_TIMEOUT = 7200; // 2h
|
2020-01-31 14:51:59 +01:00
|
|
|
const DESCRIPTION = 'Latest news about Rainbow Six Siege';
|
2017-03-20 21:32:31 +01:00
|
|
|
|
2018-10-26 18:07:34 +02:00
|
|
|
public function getIcon() {
|
2020-01-31 14:51:59 +01:00
|
|
|
return 'https://static-dm.akamaized.net/siege/prod/favicon-144x144.png';
|
2018-10-26 18:07:34 +02:00
|
|
|
}
|
|
|
|
|
2017-03-20 21:32:31 +01:00
|
|
|
public function collectData(){
|
2020-01-31 14:51:59 +01:00
|
|
|
$dlUrl = 'https://www.ubisoft.com/api/updates/items?categoriesFilter=all';
|
|
|
|
$dlUrl = $dlUrl . '&limit=6&mediaFilter=all&skip=0&startIndex=undefined&locale=en-us';
|
2017-07-14 22:05:51 +02:00
|
|
|
$jsonString = getContents($dlUrl) or returnServerError('Error while downloading the website content');
|
2017-03-20 21:32:31 +01:00
|
|
|
|
2017-07-14 22:05:51 +02:00
|
|
|
$json = json_decode($jsonString, true);
|
|
|
|
$json = $json['items'];
|
2017-03-20 21:32:31 +01:00
|
|
|
|
|
|
|
// Start at index 2 to remove highlighted articles
|
2017-07-29 19:28:00 +02:00
|
|
|
for($i = 0; $i < count($json); $i++) {
|
2020-01-31 14:51:59 +01:00
|
|
|
$jsonItem = $json[$i];
|
2017-03-20 21:32:31 +01:00
|
|
|
|
2020-01-31 14:51:59 +01:00
|
|
|
$uri = 'https://www.ubisoft.com/en-us/game/rainbow-six/siege';
|
|
|
|
$uri = $uri . $jsonItem['button']['buttonUrl'];
|
|
|
|
|
|
|
|
$thumbnail = '<img src="' . $jsonItem['thumbnail']['url'] . '" alt="Thumbnail">';
|
|
|
|
$content = $thumbnail . '<br />' . $jsonItem['content'];
|
|
|
|
|
|
|
|
// Markdown parsing from https://gist.github.com/jbroadway/2836900
|
|
|
|
|
|
|
|
// Line breaks
|
|
|
|
$content = preg_replace("/\r\n|\r|\n/", '<br/>', $content);
|
|
|
|
|
|
|
|
// Links
|
|
|
|
$regex = '/\[([^\[]+)\]\(([^\)]+)\)/';
|
|
|
|
$replacement = '<a href=\'\2\'>\1</a>';
|
|
|
|
$content = preg_replace($regex, $replacement, $content);
|
2017-03-20 21:32:31 +01:00
|
|
|
|
2020-01-31 14:51:59 +01:00
|
|
|
// Bold text
|
|
|
|
$regex = '/(\*\*|__)(.*?)\1/';
|
|
|
|
$replacement = '<strong>\2</strong>';
|
|
|
|
$content = preg_replace($regex, $replacement, $content);
|
|
|
|
|
|
|
|
// Lists
|
|
|
|
$regex = '/\n\s*[\*|\-](.*)/';
|
|
|
|
$content = preg_replace_callback($regex, function($regs) {
|
|
|
|
$item = $regs[1];
|
|
|
|
return sprintf ('<ul><li>%s</li></ul>', trim ($item));
|
|
|
|
}, $content);
|
|
|
|
|
|
|
|
// Italic text
|
|
|
|
$regex = '/(\*\*|\*)(.*?)\1/';
|
|
|
|
$replacement = '<i>\2</i>';
|
|
|
|
$content = preg_replace($regex, $replacement, $content);
|
|
|
|
|
|
|
|
$item = array();
|
2017-03-20 21:32:31 +01:00
|
|
|
$item['uri'] = $uri;
|
2020-01-31 14:51:59 +01:00
|
|
|
$item['id'] = $jsonItem['id'];
|
|
|
|
$item['title'] = $jsonItem['title'];
|
|
|
|
$item['content'] = $content;
|
|
|
|
$item['timestamp'] = strtotime($jsonItem['date']);
|
2017-03-20 21:32:31 +01:00
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|