2022-01-05 18:11:00 -05:00
|
|
|
<?php
|
|
|
|
use Helpers\Following;
|
|
|
|
use Helpers\Misc;
|
|
|
|
use Steampixel\Route;
|
2022-01-25 11:20:11 -05:00
|
|
|
use Views\Models\FollowingTemplate;
|
2022-01-05 18:11:00 -05:00
|
|
|
|
|
|
|
// 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
|
|
|
|
];
|
|
|
|
$latte = Misc::latte();
|
2022-01-25 11:20:11 -05:00
|
|
|
$latte->render(Misc::getView('following'), new FollowingTemplate($following, $feed));
|
2022-01-05 18:11:00 -05:00
|
|
|
});
|