2023-01-30 10:47:44 +00:00
|
|
|
<?php
|
|
|
|
Auth::check() || redirectToLogin();
|
|
|
|
UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404();
|
|
|
|
|
|
|
|
$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) {
|
2023-02-06 10:29:52 +00:00
|
|
|
$filepath = realpath(UOJProblem::cur()->getResourcesPath(rawurldecode($sub_path)));
|
2023-01-30 10:47:44 +00:00
|
|
|
$realbasepath = realpath(UOJProblem::cur()->getResourcesPath());
|
2023-11-12 07:46:42 +00:00
|
|
|
$filename = basename($filepath);
|
2023-01-30 10:47:44 +00:00
|
|
|
|
2023-02-06 10:29:52 +00:00
|
|
|
if (!strStartWith($filepath, $realbasepath)) {
|
2023-01-30 10:47:44 +00:00
|
|
|
UOJResponse::page406();
|
|
|
|
}
|
|
|
|
|
2023-11-12 07:46:42 +00:00
|
|
|
UOJResponse::xsendfile($filepath, [
|
|
|
|
'attachment' => $filename,
|
|
|
|
]);
|
2023-01-30 10:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$global_readonly = !UOJProblem::cur()->userCanManage(Auth::user());
|
|
|
|
|
|
|
|
include(__DIR__ . '/tinyfilemanager/tinyfilemanager.php');
|