proxitok/app/Controllers/UserController.php

55 lines
1.7 KiB
PHP
Raw Normal View History

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;
use App\Helpers\Wrappers;
2022-05-24 08:10:41 -04:00
use App\Models\FullTemplate;
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();
$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();
if ($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-26 17:51:45 -05:00
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) {
$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) {
$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
}
}
}