proxitok/routes/index.php

100 lines
2.9 KiB
PHP
Raw Normal View History

<?php
require __DIR__ . '/assets.php';
require __DIR__ . '/settings.php';
require __DIR__ . '/following.php';
2022-01-28 09:54:09 -05:00
require __DIR__ . '/rss.php';
/**@var Bramus\Router\Router $router */
use Helpers\Misc;
2022-01-28 09:54:09 -05:00
use Helpers\ErrorHandler;
use Views\Models\BaseTemplate;
use Views\Models\FeedTemplate;
use Views\Models\ItemTemplate;
2022-01-28 09:54:09 -05:00
$router->get('/', function () {
$latte = Misc::latte();
$latte->render(Misc::getView('home'), new BaseTemplate('Home'));
});
2022-01-28 09:54:09 -05:00
$router->get('/about', function () {
2022-01-08 10:03:57 -05:00
$latte = Misc::latte();
$latte->render(Misc::getView('about'), new BaseTemplate('About'));
2022-01-08 10:03:57 -05:00
});
2022-01-28 09:54:09 -05:00
$router->get("/trending", function () {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
}
$api = Misc::api();
$feed = $api->getTrendingFeed($cursor);
2022-01-13 10:51:45 -05:00
if ($feed->meta->success) {
$latte = Misc::latte();
$latte->render(Misc::getView('trending'), new FeedTemplate('Trending', $feed));
} else {
2022-01-28 09:54:09 -05:00
ErrorHandler::show($feed->meta);
}
});
2022-01-28 09:54:09 -05:00
$router->get("/@([^/]+)", function (string $username) {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
}
$api = Misc::api();
$feed = $api->getUserFeed($username, $cursor);
2022-01-13 10:51:45 -05:00
if ($feed->meta->success) {
if ($feed->info->detail->user->privateAccount) {
http_response_code(400);
return 'Private account detected! Not supported';
}
$latte = Misc::latte();
$latte->render(Misc::getView('user'), new FeedTemplate($feed->info->detail->user->nickname, $feed));
} else {
2022-01-28 09:54:09 -05:00
ErrorHandler::show($feed->meta);
}
});
2022-01-28 09:54:09 -05:00
$router->get('/video/([^/]+)', function (string $video_id) {
2022-01-08 10:03:57 -05:00
$api = Misc::api();
$item = $api->getVideoByID($video_id);
2022-01-13 10:51:45 -05:00
if ($item->meta->success) {
$latte = Misc::latte();
$latte->render(Misc::getView('video'), new ItemTemplate($item->info->detail->user->nickname, $item));
2022-01-08 10:03:57 -05:00
} else {
2022-01-28 09:54:09 -05:00
ErrorHandler::show($item->meta);
2022-01-08 10:03:57 -05:00
}
});
2022-01-28 09:54:09 -05:00
$router->get('/music/([^/]+)', function (string $music_id) {
2022-01-17 15:11:40 -05:00
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
}
$api = Misc::api();
$feed = $api->getMusicFeed($music_id, $cursor);
if ($feed->meta->success) {
$latte = Misc::latte();
$latte->render(Misc::getView('music'), new FeedTemplate('Music', $feed));
2022-01-17 15:11:40 -05:00
} else {
2022-01-28 09:54:09 -05:00
ErrorHandler::show($feed->meta);
2022-01-17 15:11:40 -05:00
}
});
2022-01-28 09:54:09 -05:00
$router->get('/tag/(\w+)', function (string $name) {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
}
$api = Misc::api();
$feed = $api->getChallengeFeed($name, $cursor);
2022-01-13 10:51:45 -05:00
if ($feed->meta->success) {
$latte = Misc::latte();
$latte->render(Misc::getView('tag'), new FeedTemplate('Tag', $feed));
} else {
2022-01-28 09:54:09 -05:00
ErrorHandler::show($feed->meta);
}
});