RSS initial support

This commit is contained in:
Pablo Ferreiro 2022-01-28 15:54:09 +01:00
parent ecdc8241e7
commit bd1642957c
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
21 changed files with 329 additions and 161 deletions

View file

@ -1,33 +1,15 @@
<?php
/**@var Bramus\Router\Router $router */
use Helpers\Following;
use Helpers\Misc;
use Steampixel\Route;
use Views\Models\FollowingTemplate;
// Showing
Route::add('/following', function () {
$allowed_items_total = isset($_GET['max']) && is_numeric($_GET['max']) && $_GET['max'] <= 100 ? $_GET['max'] : 20;
$following = Following::get();
$items = [];
if (count($following) !== 0) {
$api = Misc::api();
$max_items_per_user = $allowed_items_total / count($following);
foreach ($following as $user) {
$user_feed = $api->getUserFeed($user);
if ($user_feed) {
$max = count($user_feed->items) > $max_items_per_user ? $max_items_per_user : count($user_feed->items);
for ($i = 0; $i < $max; $i++) {
$item = $user_feed->items[$i];
array_push($items, $item);
}
}
}
}
$feed = (object) [
'items' => $items,
'hasMore' => false
];
$router->get('/following', function () {
$users = Following::getUsers();
$feed = Following::getAll($users);
$latte = Misc::latte();
$latte->render(Misc::getView('following'), new FollowingTemplate($following, $feed));
$latte->render(Misc::getView('following'), new FollowingTemplate($users, $feed));
});