mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-29 14:48:52 +03:00
[EpicgamesBridge] Add pinned posts to list (#1736)
This commit is contained in:
parent
cf606a3a6b
commit
d299adb827
1 changed files with 25 additions and 5 deletions
|
@ -48,13 +48,22 @@ class EpicgamesBridge extends BridgeAbstract {
|
|||
));
|
||||
|
||||
public function collectData() {
|
||||
// Example: https://store-content.ak.epicgames.com/api/ru/content/blog?limit=25
|
||||
$api = 'https://store-content.ak.epicgames.com/api/';
|
||||
$url = $api . $this->getInput('language') . '/content/blog?limit=' . $this->getInput('postcount');
|
||||
|
||||
$data = getContents($url)
|
||||
or returnServerError('Unable to get the news pages from epicgames.com!');
|
||||
$decodedData = json_decode($data);
|
||||
// Get sticky posts first
|
||||
// Example: https://store-content.ak.epicgames.com/api/ru/content/blog/sticky?locale=ru
|
||||
$urlSticky = $api . $this->getInput('language') . '/content/blog/sticky';
|
||||
// Then get posts
|
||||
// Example: https://store-content.ak.epicgames.com/api/ru/content/blog?limit=25
|
||||
$urlBlog = $api . $this->getInput('language') . '/content/blog?limit=' . $this->getInput('postcount');
|
||||
|
||||
$dataSticky = getContents($urlSticky)
|
||||
or returnServerError('Unable to get the sticky posts from epicgames.com!');
|
||||
$dataBlog = getContents($urlBlog)
|
||||
or returnServerError('Unable to get the news posts from epicgames.com!');
|
||||
|
||||
// Merge data
|
||||
$decodedData = array_merge(json_decode($dataSticky), json_decode($dataBlog));
|
||||
|
||||
foreach($decodedData as $key => $value) {
|
||||
$item = array();
|
||||
|
@ -76,5 +85,16 @@ class EpicgamesBridge extends BridgeAbstract {
|
|||
|
||||
$this->items[] = $item;
|
||||
}
|
||||
|
||||
// Sort data
|
||||
usort($this->items, function ($item1, $item2) {
|
||||
if ($item2['timestamp'] == $item1['timestamp']) {
|
||||
return 0;
|
||||
}
|
||||
return ($item2['timestamp'] < $item1['timestamp']) ? -1 : 1;
|
||||
});
|
||||
|
||||
// Limit data
|
||||
$this->items = array_slice($this->items, 0, $this->getInput('postcount'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue