proxitok/app/Controllers/UserController.php

51 lines
1.5 KiB
PHP
Raw Permalink 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 {
2023-04-27 14:23:23 -04:00
public static function get(string $username) {
2022-01-30 18:02:52 -05:00
$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();
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
}
}
2023-04-27 14:23:23 -04:00
public static 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
}
}
2023-04-27 14:23:23 -04:00
public static 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
}
}
}