S2OJ/web/app/controllers/problem_resources.php
Baoshuo 692c512adc
All checks were successful
continuous-integration/drone/push Build is passing
refactor: goodbye, bootstrap 4
2023-02-05 20:55:14 +08:00

53 lines
1.5 KiB
PHP

<?php
requireLib('hljs');
Auth::check() || redirectToLogin();
UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404();
$problem = UOJProblem::cur()->info;
$problem_content = UOJProblem::cur()->queryContent();
$user_can_view = UOJProblem::cur()->userCanView(Auth::user());
if (!$user_can_view) {
foreach (UOJProblem::cur()->findInContests() as $cp) {
if ($cp->contest->progress() >= CONTEST_IN_PROGRESS && $cp->contest->userHasRegistered(Auth::user())) {
$user_can_view = true;
break;
}
}
}
if (!$user_can_view) {
UOJResponse::page403();
}
// Create directory if not exists
if (!is_dir(UOJProblem::cur()->getResourcesPath())) {
mkdir(UOJProblem::cur()->getResourcesPath(), 0755, true);
}
define('APP_TITLE', '题目资源 - ' . UOJProblem::cur()->getTitle(['with' => false]));
define('FM_EMBED', true);
define('FM_DISABLE_COLS', true);
define('FM_DATETIME_FORMAT', UOJTime::FORMAT);
define('FM_ROOT_PATH', UOJProblem::cur()->getResourcesFolderPath());
define('FM_ROOT_URL', UOJProblem::cur()->getResourcesBaseUri());
$sub_path = UOJRequest::get('sub_path', 'is_string', '');
if ($sub_path) {
$filepath = realpath(UOJProblem::cur()->getResourcesPath($sub_path));
$realbasepath = realpath(UOJProblem::cur()->getResourcesPath());
if (!str_starts_with($filepath, $realbasepath)) {
UOJResponse::page406();
}
UOJResponse::xsendfile($filepath);
}
$global_readonly = !UOJProblem::cur()->userCanManage(Auth::user());
include(__DIR__ . '/tinyfilemanager/tinyfilemanager.php');