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

@ -2,25 +2,27 @@
require __DIR__ . '/assets.php';
require __DIR__ . '/settings.php';
require __DIR__ . '/following.php';
require __DIR__ . '/rss.php';
/**@var Bramus\Router\Router $router */
use Steampixel\Route;
use Helpers\Misc;
use Helpers\Error;
use Helpers\ErrorHandler;
use Views\Models\BaseTemplate;
use Views\Models\FeedTemplate;
use Views\Models\ItemTemplate;
Route::add('/', function () {
$router->get('/', function () {
$latte = Misc::latte();
$latte->render(Misc::getView('home'), new BaseTemplate('Home'));
});
Route::add('/about', function () {
$router->get('/about', function () {
$latte = Misc::latte();
$latte->render(Misc::getView('about'), new BaseTemplate('About'));
});
Route::add("/trending", function () {
$router->get("/trending", function () {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
@ -31,11 +33,11 @@ Route::add("/trending", function () {
$latte = Misc::latte();
$latte->render(Misc::getView('trending'), new FeedTemplate('Trending', $feed));
} else {
Error::show($feed->meta);
ErrorHandler::show($feed->meta);
}
});
Route::add("/@([^/]+)", function (string $username) {
$router->get("/@([^/]+)", function (string $username) {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
@ -50,22 +52,22 @@ Route::add("/@([^/]+)", function (string $username) {
$latte = Misc::latte();
$latte->render(Misc::getView('user'), new FeedTemplate($feed->info->detail->user->nickname, $feed));
} else {
Error::show($feed->meta);
ErrorHandler::show($feed->meta);
}
});
Route::add('/video/([^/]+)', function (string $video_id) {
$router->get('/video/([^/]+)', function (string $video_id) {
$api = Misc::api();
$item = $api->getVideoByID($video_id);
if ($item->meta->success) {
$latte = Misc::latte();
$latte->render(Misc::getView('video'), new ItemTemplate($item->info->detail->user->nickname, $item));
} else {
Error::show($item->meta);
ErrorHandler::show($item->meta);
}
});
Route::add('/music/([^/]+)', function (string $music_id) {
$router->get('/music/([^/]+)', function (string $music_id) {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
@ -77,11 +79,11 @@ Route::add('/music/([^/]+)', function (string $music_id) {
$latte = Misc::latte();
$latte->render(Misc::getView('music'), new FeedTemplate('Music', $feed));
} else {
Error::show($feed->meta);
ErrorHandler::show($feed->meta);
}
});
Route::add('/tag/(\w+)', function (string $name) {
$router->get('/tag/(\w+)', function (string $name) {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
@ -92,6 +94,6 @@ Route::add('/tag/(\w+)', function (string $name) {
$latte = Misc::latte();
$latte->render(Misc::getView('tag'), new FeedTemplate('Tag', $feed));
} else {
Error::show($feed->meta);
ErrorHandler::show($feed->meta);
}
});