2022-01-30 18:02:52 -05:00
|
|
|
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
use App\Helpers\ErrorHandler;
|
|
|
|
use App\Helpers\Misc;
|
2022-11-04 15:08:19 -04:00
|
|
|
use App\Helpers\UrlBuilder;
|
2022-03-29 13:30:31 -04:00
|
|
|
use App\Helpers\Wrappers;
|
2022-05-24 08:10:41 -04:00
|
|
|
use App\Models\FullTemplate;
|
2022-03-29 13:30:31 -04:00
|
|
|
use App\Models\RSSTemplate;
|
2022-04-10 06:10:48 -04:00
|
|
|
use App\Models\VideoTemplate;
|
2022-01-30 18:02:52 -05:00
|
|
|
|
|
|
|
class UserController {
|
|
|
|
static public function get(string $username) {
|
|
|
|
$cursor = Misc::getCursor();
|
2022-03-29 13:30:31 -04:00
|
|
|
$api = Wrappers::api();
|
2022-05-24 08:10:41 -04:00
|
|
|
$user = $api->user($username);
|
|
|
|
$user->feed($cursor);
|
|
|
|
if ($user->ok()) {
|
|
|
|
$data = $user->getFull();
|
|
|
|
if ($data->info->detail->privateAccount) {
|
2022-09-03 08:01:03 -04:00
|
|
|
ErrorHandler::showText(401, "Private account detected! Not supported");
|
|
|
|
return;
|
2022-01-30 18:02:52 -05:00
|
|
|
}
|
2022-11-04 15:08:19 -04:00
|
|
|
Wrappers::latte('user', new FullTemplate($data->info->detail->nickname, $data));
|
2022-01-30 18:02:52 -05:00
|
|
|
} else {
|
2022-09-03 08:01:03 -04:00
|
|
|
ErrorHandler::showMeta($user->error());
|
2022-01-30 18:02:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 06:50:47 -04:00
|
|
|
static public function video(string $username, string $video_id) {
|
2022-03-29 13:30:31 -04:00
|
|
|
$api = Wrappers::api();
|
2022-05-24 08:10:41 -04:00
|
|
|
$video = $api->video($video_id);
|
|
|
|
$video->feed();
|
|
|
|
if ($video->ok()) {
|
|
|
|
$data = $video->getFull();
|
2022-11-04 15:08:19 -04:00
|
|
|
Wrappers::latte('video', new VideoTemplate($data->feed->items[0], $data->info->detail));
|
2022-03-14 06:50:47 -04:00
|
|
|
} else {
|
2022-09-03 08:01:03 -04:00
|
|
|
ErrorHandler::showMeta($video->error());
|
2022-03-14 06:50:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-30 18:02:52 -05:00
|
|
|
static public function rss(string $username) {
|
2022-03-29 13:30:31 -04:00
|
|
|
$api = Wrappers::api();
|
2022-05-24 08:10:41 -04:00
|
|
|
$user = $api->user($username);
|
|
|
|
$user->feed();
|
|
|
|
if ($user->ok()) {
|
|
|
|
$data = $user->getFull();
|
2022-11-04 15:08:19 -04:00
|
|
|
Misc::rss($username);
|
|
|
|
Wrappers::latte('rss', new RSSTemplate($username, $data->info->detail->signature, UrlBuilder::user($username), $data->feed->items));
|
2022-01-30 18:02:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|