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()) {
|
2022-11-26 17:51:45 -05:00
|
|
|
$info = $user->getInfo();
|
|
|
|
$feed = $user->getFeed();
|
|
|
|
Wrappers::latte('user', new FullTemplate($info->detail->nickname, $info, $feed));
|
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()) {
|
2022-11-26 17:51:45 -05:00
|
|
|
$item = $video->getFeed()->items[0];
|
|
|
|
$info = $video->getInfo();
|
|
|
|
Wrappers::latte('video', new VideoTemplate($item, $info));
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|