[EpicgamesBridge] Add pinned posts to list (#1736)

This commit is contained in:
Alexander 2020-09-14 11:14:35 +03:00 committed by GitHub
parent cf606a3a6b
commit d299adb827
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,13 +48,22 @@ class EpicgamesBridge extends BridgeAbstract {
)); ));
public function collectData() { public function collectData() {
// Example: https://store-content.ak.epicgames.com/api/ru/content/blog?limit=25
$api = 'https://store-content.ak.epicgames.com/api/'; $api = 'https://store-content.ak.epicgames.com/api/';
$url = $api . $this->getInput('language') . '/content/blog?limit=' . $this->getInput('postcount');
$data = getContents($url) // Get sticky posts first
or returnServerError('Unable to get the news pages from epicgames.com!'); // Example: https://store-content.ak.epicgames.com/api/ru/content/blog/sticky?locale=ru
$decodedData = json_decode($data); $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) { foreach($decodedData as $key => $value) {
$item = array(); $item = array();
@ -76,5 +85,16 @@ class EpicgamesBridge extends BridgeAbstract {
$this->items[] = $item; $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'));
} }
} }