uoj-html-lib.php 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  1. <?php
  2. function uojHandleAtSign($str, $uri) {
  3. $referrers = array();
  4. $res = preg_replace_callback('/@(@|[a-zA-Z0-9_]{1,20})/', function($matches) use (&$referrers) {
  5. if ($matches[1] === '@') {
  6. return '@';
  7. } else {
  8. $user = queryUser($matches[1]);
  9. if ($user == null) {
  10. return $matches[0];
  11. } else {
  12. $referrers[$user['username']] = '';
  13. return '<span class="uoj-username" data-rating="'.$user['rating'].'">@'.$user['username'].'</span>';
  14. }
  15. }
  16. }, $str);
  17. $referrers_list = array();
  18. foreach ($referrers as $referrer => $val) {
  19. $referrers_list[] = $referrer;
  20. }
  21. return array($res, $referrers_list);
  22. }
  23. function uojFilePreview($file_name, $output_limit, $file_type = 'text') {
  24. switch ($file_type) {
  25. case 'text':
  26. return strOmit(file_get_contents($file_name, false, null, 0, $output_limit + 4), $output_limit);
  27. default:
  28. return strOmit(shell_exec('xxd -g 4 -l 5000 ' . escapeshellarg($file_name) . ' | head -c ' . ($output_limit + 4)), $output_limit);
  29. }
  30. }
  31. function uojIncludeView($name, $view_params = array()) {
  32. extract($view_params);
  33. include $_SERVER['DOCUMENT_ROOT'].'/app/views/'.$name.'.php';
  34. }
  35. function redirectTo($url) {
  36. header('Location: '.$url);
  37. die();
  38. }
  39. function permanentlyRedirectTo($url) {
  40. header("HTTP/1.1 301 Moved Permanently");
  41. header('Location: '.$url);
  42. die();
  43. }
  44. function redirectToLogin() {
  45. if (UOJContext::isAjax()) {
  46. die('please <a href="'.HTML::url('/login').'">login</a>');
  47. } else {
  48. header('Location: '.HTML::url('/login'));
  49. die();
  50. }
  51. }
  52. function becomeMsgPage($msg, $title = '消息') {
  53. if (UOJContext::isAjax()) {
  54. die($msg);
  55. } else {
  56. echoUOJPageHeader($title);
  57. echo $msg;
  58. echoUOJPageFooter();
  59. die();
  60. }
  61. }
  62. function become404Page() {
  63. header($_SERVER['SERVER_PROTOCOL'] . " 404 Not Found", true, 404);
  64. becomeMsgPage('<div class="text-center"><div style="font-size:233px">404</div><p>唔……未找到该页面……你是从哪里点进来的……&gt;_&lt;……</p></div>', '404');
  65. }
  66. function become403Page() {
  67. header($_SERVER['SERVER_PROTOCOL'] . " 403 Forbidden", true, 403);
  68. becomeMsgPage('<div class="text-center"><div style="font-size:233px">403</div><p>禁止入内! T_T</p></div>', '403');
  69. }
  70. function getUserLink($username, $rating = null, $certs = null) {
  71. if (validateUsername($username) && ($user = queryUser($username))) {
  72. if ($rating == null) {
  73. $rating = $user['rating'];
  74. }
  75. if ($cert == null) {
  76. $certs = $user['certs'];
  77. }
  78. return '<span class="uoj-username" data-rating="'.$rating.'" data-certs="'.$certs.'">'.$username.'</span>';
  79. } else {
  80. $esc_username = HTML::escape($username);
  81. return '<span>'.$esc_username.'</span>';
  82. }
  83. }
  84. function getRemoteProblemLink($rpid) {
  85. $rp = queryRemoteProblemBrief($rpid);
  86. return '<a href="/rp/' . $rpid . '">' . $rp['title'] . '</a>';
  87. }
  88. function getProblemLink($problem, $problem_title = '!title_only') {
  89. if ($problem_title == '!title_only') {
  90. $problem_title = $problem['title'];
  91. } elseif ($problem_title == '!id_and_title') {
  92. $problem_title = "#${problem['id']}. ${problem['title']}";
  93. }
  94. return '<a href="/problem/'.$problem['id'].'">'.$problem_title.'</a>';
  95. }
  96. function getContestProblemLink($problem, $contest_id, $problem_title = '!title_only') {
  97. if ($problem_title == '!title_only') {
  98. $problem_title = $problem['title'];
  99. } elseif ($problem_title == '!id_and_title') {
  100. $problem_title = "#{$problem['id']}. {$problem['title']}";
  101. }
  102. return '<a href="/contest/'.$contest_id.'/problem/'.$problem['id'].'">'.$problem_title.'</a>';
  103. }
  104. function getBlogLink($id) {
  105. if (validateUInt($id) && $blog = queryBlog($id)) {
  106. return '<a href="/blogs/'.$id.'">'.$blog['title'].'</a>';
  107. }
  108. }
  109. function getClickZanBlock($type, $id, $cnt, $val = null) {
  110. if ($val == null) {
  111. $val = queryZanVal($id, $type, Auth::user());
  112. }
  113. return '<div class="uoj-click-zan-block" data-id="'.$id.'" data-type="'.$type.'" data-val="'.$val.'" data-cnt="'.$cnt.'"></div>';
  114. }
  115. function getLongTablePageRawUri($page) {
  116. $path = strtok(UOJContext::requestURI(), '?');
  117. $query_string = strtok('?');
  118. parse_str($query_string, $param);
  119. $param['page'] = $page;
  120. if ($page == 1) {
  121. unset($param['page']);
  122. }
  123. if ($param) {
  124. return $path . '?' . http_build_query($param);
  125. } else {
  126. return $path;
  127. }
  128. }
  129. function getLongTablePageUri($page) {
  130. return HTML::escape(getLongTablePageRawUri($page));
  131. }
  132. function echoLongTable($col_names, $table_name, $cond, $tail, $header_row, $print_row, $config) {
  133. $pag_config = $config;
  134. $pag_config['col_names'] = $col_names;
  135. $pag_config['table_name'] = $table_name;
  136. $pag_config['cond'] = $cond;
  137. $pag_config['tail'] = $tail;
  138. $pag = new Paginator($pag_config);
  139. $div_classes = isset($config['div_classes']) ? $config['div_classes'] : array('table-responsive', 'shadow', 'my-4');
  140. $table_classes = isset($config['table_classes']) ? $config['table_classes'] : array('table', 'table-bordered', 'table-hover', 'table-striped', 'table-text-center');
  141. echo '<div class="', join($div_classes, ' '), '">';
  142. echo '<table class="', join($table_classes, ' '), '">';
  143. echo '<thead>';
  144. echo $header_row;
  145. echo '</thead>';
  146. echo '<tbody>';
  147. foreach ($pag->get() as $idx => $row) {
  148. if (isset($config['get_row_index'])) {
  149. $print_row($row, $idx);
  150. } else {
  151. $print_row($row);
  152. }
  153. }
  154. if ($pag->isEmpty()) {
  155. echo '<tr><td colspan="233">'.UOJLocale::get('none').'</td></tr>';
  156. }
  157. echo '</tbody>';
  158. echo '</table>';
  159. echo '</div>';
  160. if (isset($config['print_after_table'])) {
  161. $fun = $config['print_after_table'];
  162. $fun();
  163. }
  164. echo $pag->pagination();
  165. }
  166. function getSubmissionStatusDetails($submission) {
  167. $html = '<td colspan="233" style="vertical-align: middle">';
  168. $out_status = explode(', ', $submission['status'])[0];
  169. $fly = '<img src="/images/utility/qpx_n/b37.gif" alt="小熊像超人一样飞" class="img-rounded" />';
  170. $think = '<img src="/images/utility/qpx_n/b29.gif" alt="小熊像在思考" class="img-rounded" />';
  171. if ($out_status == 'Judged') {
  172. $status_text = '<strong>Judged!</strong>';
  173. $status_img = $fly;
  174. } else {
  175. if ($submission['status_details'] !== '') {
  176. $status_img = $fly;
  177. $status_text = HTML::escape($submission['status_details']);
  178. } else {
  179. $status_img = $think;
  180. $status_text = $out_status;
  181. }
  182. }
  183. $html .= '<div class="uoj-status-details-img-div">' . $status_img . '</div>';
  184. $html .= '<div class="uoj-status-details-text-div">' . $status_text . '</div>';
  185. $html .= '</td>';
  186. return $html;
  187. }
  188. function echoSubmission($submission, $config, $user) {
  189. $problem = queryProblemBrief($submission['problem_id']);
  190. $submitterLink = getUserLink($submission['submitter']);
  191. if ($submission['score'] == null) {
  192. $used_time_str = "/";
  193. $used_memory_str = "/";
  194. } else {
  195. $used_time_str = $submission['used_time'] . 'ms';
  196. $used_memory_str = $submission['used_memory'] . 'kb';
  197. }
  198. $status = explode(', ', $submission['status'])[0];
  199. $show_status_details = Auth::check() && ($submission['submitter'] === Auth::id() || isSuperUser(queryUser(Auth::id()))) && $status !== 'Judged';
  200. if (!$show_status_details) {
  201. echo '<tr>';
  202. } else {
  203. echo '<tr class="warning">';
  204. }
  205. if (!isset($config['id_hidden'])) {
  206. echo '<td><a href="/submission/', $submission['id'], '">#', $submission['id'], '</a></td>';
  207. }
  208. if (!isset($config['problem_hidden'])) {
  209. if ($submission['contest_id']) {
  210. echo '<td>', getContestProblemLink($problem, $submission['contest_id'], '!id_and_title'), '</td>';
  211. } else if ($submission['problem_id'] != 260328) {
  212. echo '<td>', getProblemLink($problem, '!id_and_title'), '</td>';
  213. } else {
  214. foreach (json_decode($submission['content'], true)['config'] as $row)
  215. if ($row[0] == 'rpid') {
  216. $rpid = $row[1];
  217. break;
  218. }
  219. echo '<td>' . getRemoteProblemLink($rpid) . '</td>';
  220. }
  221. }
  222. if (!isset($config['submitter_hidden'])) {
  223. echo '<td>', $submitterLink, '</td>';
  224. }
  225. if (!isset($config['result_hidden'])) {
  226. echo '<td>';
  227. if ($status == 'Judged') {
  228. if ($submission['score'] == null) {
  229. echo '<a href="/submission/', $submission['id'], '" class="small">', $submission['result_error'], '</a>';
  230. } else {
  231. echo '<a href="/submission/', $submission['id'], '" class="uoj-score">', $submission['score'], '</a>';
  232. }
  233. } else {
  234. echo '<a href="/submission/', $submission['id'], '" class="small">', $status, '</a>';
  235. }
  236. echo '</td>';
  237. }
  238. if (!isset($config['used_time_hidden'])) {
  239. echo '<td>', $used_time_str, '</td>';
  240. }
  241. if (!isset($config['used_memory_hidden'])) {
  242. echo '<td>', $used_memory_str, '</td>';
  243. }
  244. echo '<td>', '<a href="/submission/', $submission['id'], '">', $submission['language'], '</a>', '</td>';
  245. if ($submission['tot_size'] < 1024) {
  246. $size_str = $submission['tot_size'] . 'b';
  247. } else {
  248. $size_str = sprintf("%.1f", $submission['tot_size'] / 1024) . 'kb';
  249. }
  250. echo '<td>', $size_str, '</td>';
  251. if (!isset($config['submit_time_hidden'])) {
  252. echo '<td><small>', $submission['submit_time'], '</small></td>';
  253. }
  254. if (!isset($config['judge_time_hidden'])) {
  255. echo '<td><small>', $submission['judge_time'], '</small></td>';
  256. }
  257. echo '</tr>';
  258. if ($show_status_details) {
  259. echo '<tr id="', "status_details_{$submission['id']}", '" class="info">';
  260. echo getSubmissionStatusDetails($submission);
  261. echo '</tr>';
  262. echo '<script type="text/javascript">update_judgement_status_details('.$submission['id'].')</script>';
  263. }
  264. }
  265. function echoSubmissionsListOnlyOne($submission, $config, $user) {
  266. echo '<div class="table-responsive shadow my-4">';
  267. echo '<table class="table table-bordered table-text-center">';
  268. echo '<thead>';
  269. echo '<tr>';
  270. if (!isset($config['id_hidden'])) {
  271. echo '<th>ID</th>';
  272. }
  273. if (!isset($config['problem_hidden'])) {
  274. echo '<th>'.UOJLocale::get('problems::problem').'</th>';
  275. }
  276. if (!isset($config['submitter_hidden'])) {
  277. echo '<th>'.UOJLocale::get('problems::submitter').'</th>';
  278. }
  279. if (!isset($config['result_hidden'])) {
  280. echo '<th>'.UOJLocale::get('problems::result').'</th>';
  281. }
  282. if (!isset($config['used_time_hidden'])) {
  283. echo '<th>'.UOJLocale::get('problems::used time').'</th>';
  284. }
  285. if (!isset($config['used_memory_hidden'])) {
  286. echo '<th>'.UOJLocale::get('problems::used memory').'</th>';
  287. }
  288. echo '<th>'.UOJLocale::get('problems::language').'</th>';
  289. echo '<th>'.UOJLocale::get('problems::file size').'</th>';
  290. if (!isset($config['submit_time_hidden'])) {
  291. echo '<th>'.UOJLocale::get('problems::submit time').'</th>';
  292. }
  293. if (!isset($config['judge_time_hidden'])) {
  294. echo '<th>'.UOJLocale::get('problems::judge time').'</th>';
  295. }
  296. echo '</tr>';
  297. echo '</thead>';
  298. echo '<tbody>';
  299. echoSubmission($submission, $config, $user);
  300. echo '</tbody>';
  301. echo '</table>';
  302. echo '</div>';
  303. }
  304. function echoSubmissionsList($cond, $tail, $config, $user) {
  305. $header_row = '<tr>';
  306. $col_names = array();
  307. $col_names[] = 'submissions.status_details';
  308. $col_names[] = 'submissions.status';
  309. $col_names[] = 'submissions.result_error';
  310. $col_names[] = 'submissions.score';
  311. $col_names[] = 'submissions.content';
  312. if (!isset($config['id_hidden'])) {
  313. $header_row .= '<th>ID</th>';
  314. $col_names[] = 'submissions.id';
  315. }
  316. if (!isset($config['problem_hidden'])) {
  317. $header_row .= '<th>'.UOJLocale::get('problems::problem').'</th>';
  318. $col_names[] = 'submissions.problem_id';
  319. $col_names[] = 'submissions.contest_id';
  320. }
  321. if (!isset($config['submitter_hidden'])) {
  322. $header_row .= '<th>'.UOJLocale::get('problems::submitter').'</th>';
  323. $col_names[] = 'submissions.submitter';
  324. }
  325. if (!isset($config['result_hidden'])) {
  326. $header_row .= '<th>'.UOJLocale::get('problems::result').'</th>';
  327. }
  328. if (!isset($config['used_time_hidden'])) {
  329. $header_row .= '<th>'.UOJLocale::get('problems::used time').'</th>';
  330. $col_names[] = 'submissions.used_time';
  331. }
  332. if (!isset($config['used_memory_hidden'])) {
  333. $header_row .= '<th>'.UOJLocale::get('problems::used memory').'</th>';
  334. $col_names[] = 'submissions.used_memory';
  335. }
  336. $header_row .= '<th>'.UOJLocale::get('problems::language').'</th>';
  337. $col_names[] = 'submissions.language';
  338. $header_row .= '<th>'.UOJLocale::get('problems::file size').'</th>';
  339. $col_names[] = 'submissions.tot_size';
  340. if (!isset($config['submit_time_hidden'])) {
  341. $header_row .= '<th>'.UOJLocale::get('problems::submit time').'</th>';
  342. $col_names[] = 'submissions.submit_time';
  343. }
  344. if (!isset($config['judge_time_hidden'])) {
  345. $header_row .= '<th>'.UOJLocale::get('problems::judge time').'</th>';
  346. $col_names[] = 'submissions.judge_time';
  347. }
  348. $header_row .= '</tr>';
  349. $table_name = isset($config['table_name']) ? $config['table_name'] : 'submissions';
  350. if (!isSuperUser($user)) {
  351. if ($user != null) {
  352. $permission_cond = "submissions.is_hidden = false or (submissions.is_hidden = true and submissions.problem_id in (select problem_id from problems_permissions where username = '{$user['username']}')) or (submissions.is_hidden = 1 and (select max(find_in_set(submissions.problem_id, privs)) as nr from user_info where username like 'group_%' and find_in_set(username, '{$user['extgroups']}')))";
  353. } else {
  354. $permission_cond = "submissions.is_hidden = false";
  355. }
  356. if ($cond !== '1') {
  357. $cond = "($cond) and ($permission_cond)";
  358. } else {
  359. $cond = $permission_cond;
  360. }
  361. }
  362. $table_config = isset($config['table_config']) ? $config['table_config'] : null;
  363. echoLongTable($col_names, $table_name, $cond, $tail, $header_row,
  364. function($submission) use ($config, $user) {
  365. echoSubmission($submission, $config, $user);
  366. }, $table_config);
  367. }
  368. function echoShortList($header, $rows, $print_row) {
  369. echo '<div class="table-responsive"><table class="table table-bordered table-hover table-striped table-text-center">';
  370. echo '<thead>';
  371. echo $header;
  372. echo '</thead>';
  373. echo '<tbody>';
  374. foreach ($rows as $idx => $row)
  375. $print_row($row);
  376. if (empty($rows))
  377. echo '<tr><td colspan="233">'.UOJLocale::get('none').'</td></tr>';
  378. echo '</tbody>';
  379. echo '</table>';
  380. echo '</div>';
  381. }
  382. function echoBelongGroupList($user) {
  383. echoShortList('<tr><th>组名</th><th>显示名</th><th>题目</th></tr>', queryUserExtgroups($user), function($grp) {
  384. $qp = queryUser($grp);
  385. $link = getUserLink($qp['username']);
  386. $name = $qp['email'];
  387. echo <<<HTML
  388. <tr>
  389. <td>$link</td>
  390. <td>$name</td>
  391. <td><a href="/problems/group/{$grp}">题目</a></td>
  392. </tr>
  393. HTML;
  394. });
  395. }
  396. function echoGroupMemberList($grp) {
  397. echoShortList('<tr><th>用户名</th><th>管理</th></tr>', queryGroupMembers($grp),
  398. function($usern) use ($grp) {
  399. $username = $usern['username'];
  400. $user = queryUser($username);
  401. $link = getUserLink($username);
  402. if (hasGroupCtrlPermission($user, $grp)) $adminp = '<b>是</b>';
  403. else $adminp = '否';
  404. echo <<<HTML
  405. <tr>
  406. <td>$link</td>
  407. <td>$adminp</td>
  408. </tr>
  409. HTML;
  410. });
  411. }
  412. function echoGroupProblemList($grp) {
  413. echoShortList('<tr><th>题号</th><th>题名</th><th>控制</th><th>压缩包大小</th></tr>', queryGroupProblems($grp),
  414. function($pid) use ($grp) {
  415. $problem = queryProblemBrief($pid);
  416. $pid = $pid;
  417. $title = $problem['title'];
  418. if ($problem['ctrl'] && $problem['ctrl'] == $grp['username']) $adminp = '<b>是</b>';
  419. else $adminp = '否';
  420. $size = printSize(queryProblemSize($pid));
  421. echo <<<HTML
  422. <tr><td>$pid</td>
  423. <td><a href="/problem/{$pid}">$title</a></td>
  424. <td>$adminp</td>
  425. <td>$size</td></tr>
  426. HTML;
  427. });
  428. }
  429. function echoGroupProblemSizeList($grp) {
  430. echoShortList('<tr><th>题号</th><th>题名</th><th>压缩包大小</th></tr>', queryGroupCtrlProblems($grp),
  431. function($pid) {
  432. $problem = queryProblemBrief($pid);
  433. $pid = $pid;
  434. $title = $problem['title'];
  435. $size = printSize(queryProblemSize($pid));
  436. echo <<<HTML
  437. <tr><td>$pid</td>
  438. <td><a href="/problem/{$pid}">$title</a></td>
  439. <td>$size</td></tr>
  440. HTML;
  441. });
  442. }
  443. function echoControlGroupList($user) {
  444. echoShortList('<tr><th>组名</th><th>显示名</th><th>管理</th></tr>', queryUserCtrlgroups($user), function($grp) {
  445. $qp = queryUser($grp);
  446. $link = getUserLink($qp['username']);
  447. $name = $qp['email'];
  448. echo <<<HTML
  449. <tr>
  450. <td>$link</td>
  451. <td>$name</td>
  452. <td><a href="/group-manage/{$grp}">管理</a></td>
  453. </tr>
  454. HTML;
  455. });
  456. }
  457. function echoGroupsList() {
  458. $header_row = '<tr>';
  459. $col_names = ['username', 'privs'];
  460. $header_row .= '<th>组名</th>';
  461. $header_row .= '<th>组权限</th>';
  462. $header_row .= '</tr>';
  463. $table_name = 'user_info';
  464. echoLongTable($col_names, $table_name, "username like 'group_%'", '', $header_row,
  465. function ($group) {
  466. $link = getUserLink($group['username']);
  467. $privs = $group['privs'];
  468. echo <<<HTML
  469. <tr>
  470. <td>
  471. {$link}
  472. </td>
  473. <td>
  474. {$privs_pretty}
  475. </td>
  476. </tr>
  477. HTML;
  478. }, []);
  479. }
  480. function echoCertsList($user) {
  481. echoShortList('<tr><th>勋章</th><th>展示</th></tr>', explode(',', $user['certslist']), function($certs) {
  482. $col = explode('#', $certs)[0];
  483. $text = explode('#', $certs)[1];
  484. $cert = '<span class="uoj-certs uoj-certs-' . $col . '">' . $text . '</span>';
  485. echo <<<HTML
  486. <tr>
  487. <td>$cert</td>
  488. <td>
  489. <form action="/certs-manage" method="post">
  490. <input type="hidden" name="certs" value="$certs">
  491. <button type="submit" class="btn btn-primary">展示这个</button>
  492. </form>
  493. </td>
  494. </tr>
  495. HTML;
  496. });
  497. }
  498. function echoPastesList() {
  499. $header_row = '<tr>';
  500. $col_names = ['`index`','creator','created_at'];
  501. $header_row .= '<th>ID</th>';
  502. $header_row .= '<th>'.UOJLocale::get("problems::submitter").'</th>';
  503. $header_row .= '<th>'.UOJLocale::get('problems::submit time').'</th>';
  504. $header_row .= '<th> 操作 </th>';
  505. $header_row .= '</tr>';
  506. $table_name = 'pastes';
  507. echoLongTable($col_names, $table_name, "1", 'order by created_at desc', $header_row,
  508. function($paste) {
  509. $user = getUserLink($paste['creator']);
  510. $token = HTML::hiddenToken();
  511. echo <<<HTML
  512. <tr>
  513. <td>
  514. <a href="/pastes/{$paste['index']}">{$paste['index']}</a>
  515. </td>
  516. <td>
  517. {$user}
  518. </td>
  519. <td>
  520. {$paste['created_at']}
  521. </td>
  522. <td>
  523. <form action="/super-manage/paste" method="post" class="form-horizontal">
  524. {$token}
  525. <input type="text" class="form-control" name="paste_deleter_name" id="input-paste_deleter_name" value="{$paste['index']}" style="display: none;">
  526. <button type="submit" name="submit-paste_deleter" value="paste_deleter" class="btn btn-sm btn-danger" style="margin: 0">删除</button>
  527. </form>
  528. </td>
  529. </tr>
  530. HTML;
  531. }, []);
  532. }
  533. function echoPasteContent($paste) {
  534. $zip_file = new ZipArchive();
  535. $submission_content = json_decode($paste['content'], true);
  536. $zip_file->open(UOJContext::storagePath().$submission_content['file_name']);
  537. $config = array();
  538. foreach ($submission_content['config'] as $config_key => $config_val) {
  539. $config[$config_val[0]] = $config_val[1];
  540. }
  541. $file_content = $zip_file->getFromName("paste.code");
  542. $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
  543. $file_language = htmlspecialchars($config["paste_language"]);
  544. $footer_text = UOJLocale::get('problems::source code').', '.UOJLocale::get('problems::language').': '.$file_language;
  545. $footer_text .= ", ".UOJLocale::get("problems::submitter") . <<<HTML
  546. : <a href="/user/profile/${paste['creator']}">${paste['creator']}</a>
  547. HTML;
  548. $footer_text .= ", ".UOJLocale::get("problems::submit time").": ".$paste['created_at'];
  549. switch ($file_language) {
  550. case 'C++14':
  551. case 'C++17':
  552. case 'C++17ubsan':
  553. $sh_class = 'sh_cpp';
  554. break;
  555. case 'Python2':
  556. case 'Python3':
  557. $sh_class = 'sh_python';
  558. break;
  559. case 'Java8':
  560. case 'Java11':
  561. $sh_class = 'sh_java';
  562. break;
  563. case 'C':
  564. $sh_class = 'sh_c';
  565. break;
  566. case 'Pascal':
  567. $sh_class = 'sh_pascal';
  568. break;
  569. default:
  570. $sh_class = '';
  571. break;
  572. }
  573. echo '<div class="card border-info mb-3">';
  574. echo '<div class="card-header bg-info">';
  575. echo '<h4 class="card-title">Paste!</h4>';
  576. echo '</div>';
  577. echo '<div class="card-body">';
  578. echo '<pre><code class="'.$sh_class.'">'.$file_content."\n".'</code></pre>';
  579. echo '</div>';
  580. echo '<div class="card-footer">'.$footer_text.'</div>';
  581. echo '</div>';
  582. $zip_file->close();
  583. }
  584. function echoSubmissionContent($submission, $requirement) {
  585. $zip_file = new ZipArchive();
  586. $submission_content = json_decode($submission['content'], true);
  587. $zip_file->open(UOJContext::storagePath().$submission_content['file_name']);
  588. $config = array();
  589. foreach ($submission_content['config'] as $config_key => $config_val) {
  590. $config[$config_val[0]] = $config_val[1];
  591. }
  592. foreach ($requirement as $req) {
  593. if ($req['type'] == "source code") {
  594. $file_content = $zip_file->getFromName("{$req['name']}.code");
  595. $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
  596. $file_language = htmlspecialchars($config["{$req['name']}_language"]);
  597. $footer_text = UOJLocale::get('problems::source code').', '.UOJLocale::get('problems::language').': '.$file_language;
  598. switch ($file_language) {
  599. case 'C++14':
  600. case 'C++17':
  601. case 'C++17ubsan':
  602. $sh_class = 'sh_cpp';
  603. break;
  604. case 'Python2':
  605. case 'Python3':
  606. $sh_class = 'sh_python';
  607. break;
  608. case 'Java8':
  609. case 'Java11':
  610. $sh_class = 'sh_java';
  611. break;
  612. case 'C':
  613. $sh_class = 'sh_c';
  614. break;
  615. case 'Pascal':
  616. $sh_class = 'sh_pascal';
  617. break;
  618. default:
  619. $sh_class = '';
  620. break;
  621. }
  622. echo '<div class="card border-info mb-3">';
  623. echo '<div class="card-header bg-info">';
  624. echo '<h4 class="card-title">'.$req['name'].'</h4>';
  625. echo '</div>';
  626. echo '<div class="card-body">';
  627. echo '<pre><code class="'.$sh_class.'">'.$file_content."\n".'</code></pre>';
  628. echo '</div>';
  629. echo '<div class="card-footer">'.$footer_text.'</div>';
  630. echo '</div>';
  631. } elseif ($req['type'] == "text") {
  632. $file_content = $zip_file->getFromName("{$req['file_name']}", 504);
  633. $file_content = strOmit($file_content, 500);
  634. $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
  635. $footer_text = UOJLocale::get('problems::text file');
  636. echo '<div class="card border-info mb-3">';
  637. echo '<div class="card-header bg-info">';
  638. echo '<h4 class="card-title">'.$req['file_name'].'</h4>';
  639. echo '</div>';
  640. echo '<div class="card-body">';
  641. echo '<pre>'."\n".$file_content."\n".'</pre>';
  642. echo '</div>';
  643. echo '<div class="card-footer">'.$footer_text.'</div>';
  644. echo '</div>';
  645. }
  646. }
  647. $zip_file->close();
  648. }
  649. class JudgementDetailsPrinter {
  650. private $name;
  651. private $styler;
  652. private $dom;
  653. private $subtask_num;
  654. private function _print_c($node) {
  655. foreach ($node->childNodes as $child) {
  656. if ($child->nodeName == '#text') {
  657. echo htmlspecialchars($child->nodeValue);
  658. } else {
  659. $this->_print($child);
  660. }
  661. }
  662. }
  663. private function _print($node) {
  664. if ($node->nodeName == 'error') {
  665. echo "<pre>\n";
  666. $this->_print_c($node);
  667. echo "\n</pre>";
  668. } elseif ($node->nodeName == 'tests') {
  669. echo '<div id="', $this->name, '_details_accordion">';
  670. if ($this->styler->show_small_tip) {
  671. echo '<div class="text-right text-muted">', '小提示:点击横条可展开更详细的信息', '</div>';
  672. } elseif ($this->styler->ioi_contest_is_running) {
  673. echo '<div class="text-right text-muted">', 'IOI 赛制比赛中不支持显示详细信息', '</div>';
  674. }
  675. $this->_print_c($node);
  676. echo '</div>';
  677. } elseif ($node->nodeName == 'subtask') {
  678. $subtask_num = $node->getAttribute('num');
  679. $subtask_score = $node->getAttribute('score');
  680. $subtask_info = $node->getAttribute('info');
  681. echo '<div class="card ', $this->styler->getTestInfoClass($subtask_info), ' mb-3">';
  682. $accordion_parent = "{$this->name}_details_accordion";
  683. $accordion_collapse = "{$accordion_parent}_collapse_subtask_{$subtask_num}";
  684. $accordion_collapse_accordion = "{$accordion_collapse}_accordion";
  685. echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
  686. echo '<div class="row">';
  687. echo '<div class="col-sm-4">';
  688. echo '<h3 class="card-title">', 'Subtask #', $subtask_num, ': ', '</h3>';
  689. echo '</div>';
  690. if ($this->styler->show_score) {
  691. echo '<div class="col-sm-4">';
  692. echo '得分:', $subtask_score;
  693. echo '</div>';
  694. echo '<div class="col-sm-4">';
  695. echo htmlspecialchars($subtask_info);
  696. echo '</div>';
  697. } else {
  698. echo '<div class="col-sm-8">';
  699. echo htmlspecialchars($subtask_info);
  700. echo '</div>';
  701. }
  702. echo '</div>';
  703. echo '</div>';
  704. echo '<div id="', $accordion_collapse, '" class="card-collapse collapse">';
  705. echo '<div class="card-body">';
  706. echo '<div id="', $accordion_collapse_accordion, '">';
  707. $this->subtask_num = $subtask_num;
  708. $this->_print_c($node);
  709. $this->subtask_num = null;
  710. echo '</div>';
  711. echo '</div>';
  712. echo '</div>';
  713. echo '</div>';
  714. } elseif ($node->nodeName == 'test') {
  715. $test_info = $node->getAttribute('info');
  716. $test_num = $node->getAttribute('num');
  717. $test_score = $node->getAttribute('score');
  718. $test_time = $node->getAttribute('time');
  719. $test_memory = $node->getAttribute('memory');
  720. echo '<div class="card ', $this->styler->getTestInfoClass($test_info), ' mb-3">';
  721. $accordion_parent = "{$this->name}_details_accordion";
  722. if ($this->subtask_num != null) {
  723. $accordion_parent .= "_collapse_subtask_{$this->subtask_num}_accordion";
  724. }
  725. $accordion_collapse = "{$accordion_parent}_collapse_test_{$test_num}";
  726. if (!$this->styler->shouldFadeDetails($test_info)) {
  727. echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
  728. } else {
  729. echo '<div class="card-header">';
  730. }
  731. echo '<div class="row">';
  732. echo '<div class="col-sm-4">';
  733. if ($test_num > 0) {
  734. echo '<h4 class="card-title">', 'Test #', $test_num, ': ', '</h4>';
  735. } else {
  736. echo '<h4 class="card-title">', 'Extra Test:', '</h4>';
  737. }
  738. echo '</div>';
  739. if ($this->styler->show_score) {
  740. echo '<div class="col-sm-4">';
  741. echo '得分:', $test_score;
  742. echo '</div>';
  743. echo '<div class="col-sm-4">';
  744. echo htmlspecialchars($test_info);
  745. echo '</div>';
  746. } else {
  747. echo '<div class="col-sm-8">';
  748. echo htmlspecialchars($test_info);
  749. echo '</div>';
  750. }
  751. echo '<div class="col-sm-4">';
  752. if ($test_time >= 0) {
  753. echo '时间:', $test_time, 'ms';
  754. }
  755. echo '</div>';
  756. echo '<div class="col-sm-4">';
  757. if ($test_memory >= 0) {
  758. echo '内存:', $test_memory, 'kb';
  759. }
  760. echo '</div>';
  761. echo '</div>';
  762. echo '</div>';
  763. if (!$this->styler->shouldFadeDetails($test_info)) {
  764. $accordion_collapse_class = 'card-collapse collapse';
  765. if ($this->styler->collapse_in) {
  766. $accordion_collapse_class .= ' in';
  767. }
  768. echo '<div id="', $accordion_collapse, '" class="', $accordion_collapse_class, '">';
  769. echo '<div class="card-body">';
  770. $this->_print_c($node);
  771. echo '</div>';
  772. echo '</div>';
  773. }
  774. echo '</div>';
  775. } elseif ($node->nodeName == 'custom-test') {
  776. $test_info = $node->getAttribute('info');
  777. $test_time = $node->getAttribute('time');
  778. $test_memory = $node->getAttribute('memory');
  779. echo '<div class="card ', $this->styler->getTestInfoClass($test_info), ' mb-3">';
  780. $accordion_parent = "{$this->name}_details_accordion";
  781. $accordion_collapse = "{$accordion_parent}_collapse_custom_test";
  782. if (!$this->styler->shouldFadeDetails($test_info)) {
  783. echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
  784. } else {
  785. echo '<div class="card-header">';
  786. }
  787. echo '<div class="row">';
  788. echo '<div class="col-sm-2">';
  789. echo '<h4 class="card-title">', '自定义测试:', '</h4>';
  790. echo '</div>';
  791. echo '<div class="col-sm-4">';
  792. echo htmlspecialchars($test_info);
  793. echo '</div>';
  794. echo '<div class="col-sm-3">';
  795. if ($test_time >= 0) {
  796. echo '时间:', $test_time, 'ms';
  797. }
  798. echo '</div>';
  799. echo '<div class="col-sm-3">';
  800. if ($test_memory >= 0) {
  801. echo '空间:', $test_memory, 'kb';
  802. }
  803. echo '</div>';
  804. echo '</div>';
  805. echo '</div>';
  806. if (!$this->styler->shouldFadeDetails($test_info)) {
  807. $accordion_collapse_class = 'card-collapse collapse';
  808. if ($this->styler->collapse_in) {
  809. $accordion_collapse_class .= ' in';
  810. }
  811. echo '<div id="', $accordion_collapse, '" class="', $accordion_collapse_class, '">';
  812. echo '<div class="card-body">';
  813. $this->_print_c($node);
  814. echo '</div>';
  815. echo '</div>';
  816. echo '</div>';
  817. }
  818. } elseif ($node->nodeName == 'in') {
  819. echo "<h4>标准输入:</h4><pre>\n";
  820. $this->_print_c($node);
  821. echo "\n</pre>";
  822. } elseif ($node->nodeName == 'out') {
  823. echo "<h4>标准输出:</h4><pre>\n";
  824. $this->_print_c($node);
  825. echo "\n</pre>";
  826. } elseif ($node->nodeName == 'res') {
  827. echo "<h4>检验结果:</h4><pre>\n";
  828. $this->_print_c($node);
  829. echo "\n</pre>";
  830. } else {
  831. echo '<', $node->nodeName;
  832. foreach ($node->attributes as $attr) {
  833. echo ' ', $attr->name, '="', htmlspecialchars($attr->value), '"';
  834. }
  835. echo '>';
  836. $this->_print_c($node);
  837. echo '</', $node->nodeName, '>';
  838. }
  839. }
  840. public function __construct($details, $styler, $name) {
  841. $this->name = $name;
  842. $this->styler = $styler;
  843. $this->details = $details;
  844. $this->dom = new DOMDocument();
  845. if (!$this->dom->loadXML($this->details)) {
  846. throw new Exception("XML syntax error");
  847. }
  848. $this->details = '';
  849. }
  850. public function printHTML() {
  851. $this->subtask_num = null;
  852. $this->_print($this->dom->documentElement);
  853. }
  854. }
  855. function echoJudgementDetails($raw_details, $styler, $name) {
  856. try {
  857. $printer = new JudgementDetailsPrinter($raw_details, $styler, $name);
  858. $printer->printHTML();
  859. } catch (Exception $e) {
  860. echo 'Failed to show details';
  861. }
  862. }
  863. class SubmissionDetailsStyler {
  864. public $show_score = true;
  865. public $show_small_tip = true;
  866. public $collapse_in = false;
  867. public $fade_all_details = false;
  868. public function getTestInfoClass($info) {
  869. if ($info == 'Accepted' || $info == 'Extra Test Passed') {
  870. return 'card-uoj-accepted';
  871. } elseif ($info == 'Time Limit Exceeded') {
  872. return 'card-uoj-tle';
  873. } elseif ($info == 'Acceptable Answer') {
  874. return 'card-uoj-acceptable-answer';
  875. } else {
  876. return 'card-uoj-wrong';
  877. }
  878. }
  879. public function shouldFadeDetails($info) {
  880. return $this->fade_all_details || $info == 'Extra Test Passed';
  881. }
  882. }
  883. class CustomTestSubmissionDetailsStyler {
  884. public $show_score = true;
  885. public $show_small_tip = false;
  886. public $collapse_in = true;
  887. public $fade_all_details = false;
  888. public $ioi_contest_is_running = false;
  889. public function getTestInfoClass($info) {
  890. if ($info == 'Success') {
  891. return 'card-uoj-accepted';
  892. } elseif ($info == 'Time Limit Exceeded') {
  893. return 'card-uoj-tle';
  894. } elseif ($info == 'Acceptable Answer') {
  895. return 'card-uoj-acceptable-answer';
  896. } else {
  897. return 'card-uoj-wrong';
  898. }
  899. }
  900. public function shouldFadeDetails($info) {
  901. return $this->fade_all_details;
  902. }
  903. }
  904. class HackDetailsStyler {
  905. public $show_score = false;
  906. public $show_small_tip = false;
  907. public $collapse_in = true;
  908. public $fade_all_details = false;
  909. public function getTestInfoClass($info) {
  910. if ($info == 'Accepted' || $info == 'Extra Test Passed') {
  911. return 'card-uoj-accepted';
  912. } elseif ($info == 'Time Limit Exceeded') {
  913. return 'card-uoj-tle';
  914. } elseif ($info == 'Acceptable Answer') {
  915. return 'card-uoj-acceptable-answer';
  916. } else {
  917. return 'card-uoj-wrong';
  918. }
  919. }
  920. public function shouldFadeDetails($info) {
  921. return $this->fade_all_details;
  922. }
  923. }
  924. function echoSubmissionDetails($submission_details, $name) {
  925. echoJudgementDetails($submission_details, new SubmissionDetailsStyler(), $name);
  926. }
  927. function echoCustomTestSubmissionDetails($submission_details, $name) {
  928. echoJudgementDetails($submission_details, new CustomTestSubmissionDetailsStyler(), $name);
  929. }
  930. function echoHackDetails($hack_details, $name) {
  931. echoJudgementDetails($hack_details, new HackDetailsStyler(), $name);
  932. }
  933. function echoHack($hack, $config, $user) {
  934. $problem = queryProblemBrief($hack['problem_id']);
  935. echo '<tr>';
  936. if (!isset($config['id_hidden'])) {
  937. echo '<td><a href="/hack/', $hack['id'], '">#', $hack['id'], '</a></td>';
  938. }
  939. if (!isset($config['submission_hidden'])) {
  940. echo '<td><a href="/submission/', $hack['submission_id'], '">#', $hack['submission_id'], '</a></td>';
  941. }
  942. if (!isset($config['problem_hidden'])) {
  943. if ($hack['contest_id']) {
  944. echo '<td>', getContestProblemLink($problem, $hack['contest_id'], '!id_and_title'), '</td>';
  945. } else {
  946. echo '<td>', getProblemLink($problem, '!id_and_title'), '</td>';
  947. }
  948. }
  949. if (!isset($config['hacker_hidden'])) {
  950. echo '<td>', getUserLink($hack['hacker']), '</td>';
  951. }
  952. if (!isset($config['owner_hidden'])) {
  953. echo '<td>', getUserLink($hack['owner']), '</td>';
  954. }
  955. if (!isset($config['result_hidden'])) {
  956. if ($hack['judge_time'] == null) {
  957. echo '<td><a href="/hack/', $hack['id'], '">Waiting</a></td>';
  958. } elseif ($hack['success'] == null) {
  959. echo '<td><a href="/hack/', $hack['id'], '">Judging</a></td>';
  960. } elseif ($hack['success']) {
  961. echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status" data-success="1"><strong>Success!</strong></a></td>';
  962. } else {
  963. echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status" data-success="0"><strong>Failed.</strong></a></td>';
  964. }
  965. } else {
  966. echo '<td>Hidden</td>';
  967. }
  968. if (!isset($config['submit_time_hidden'])) {
  969. echo '<td>', $hack['submit_time'], '</td>';
  970. }
  971. if (!isset($config['judge_time_hidden'])) {
  972. echo '<td>', $hack['judge_time'], '</td>';
  973. }
  974. echo '</tr>';
  975. }
  976. function echoHackListOnlyOne($hack, $config, $user) {
  977. echo '<div class="table-responsive shadow my-4">';
  978. echo '<table class="table table-bordered table-text-center">';
  979. echo '<thead>';
  980. echo '<tr>';
  981. if (!isset($config['id_hidden'])) {
  982. echo '<th>ID</th>';
  983. }
  984. if (!isset($config['submission_id_hidden'])) {
  985. echo '<th>'.UOJLocale::get('problems::submission id').'</th>';
  986. }
  987. if (!isset($config['problem_hidden'])) {
  988. echo '<th>'.UOJLocale::get('problems::problem').'</th>';
  989. }
  990. if (!isset($config['hacker_hidden'])) {
  991. echo '<th>'.UOJLocale::get('problems::hacker').'</th>';
  992. }
  993. if (!isset($config['owner_hidden'])) {
  994. echo '<th>'.UOJLocale::get('problems::owner').'</th>';
  995. }
  996. if (!isset($config['result_hidden'])) {
  997. echo '<th>'.UOJLocale::get('problems::result').'</th>';
  998. }
  999. if (!isset($config['submit_time_hidden'])) {
  1000. echo '<th>'.UOJLocale::get('problems::submit time').'</th>';
  1001. }
  1002. if (!isset($config['judge_time_hidden'])) {
  1003. echo '<th>'.UOJLocale::get('problems::judge time').'</th>';
  1004. }
  1005. echo '</tr>';
  1006. echo '</thead>';
  1007. echo '<tbody>';
  1008. echoHack($hack, $config, $user);
  1009. echo '</tbody>';
  1010. echo '</table>';
  1011. echo '</div>';
  1012. }
  1013. function echoHacksList($cond, $tail, $config, $user) {
  1014. $header_row = '<tr>';
  1015. $col_names = array();
  1016. $col_names[] = 'id';
  1017. $col_names[] = 'success';
  1018. $col_names[] = 'judge_time';
  1019. if (!isset($config['id_hidden'])) {
  1020. $header_row .= '<th>ID</th>';
  1021. }
  1022. if (!isset($config['submission_id_hidden'])) {
  1023. $header_row .= '<th>'.UOJLocale::get('problems::submission id').'</th>';
  1024. $col_names[] = 'submission_id';
  1025. }
  1026. if (!isset($config['problem_hidden'])) {
  1027. $header_row .= '<th>'.UOJLocale::get('problems::problem').'</th>';
  1028. $col_names[] = 'problem_id';
  1029. }
  1030. if (!isset($config['hacker_hidden'])) {
  1031. $header_row .= '<th>'.UOJLocale::get('problems::hacker').'</th>';
  1032. $col_names[] = 'hacker';
  1033. }
  1034. if (!isset($config['owner_hidden'])) {
  1035. $header_row .= '<th>'.UOJLocale::get('problems::owner').'</th>';
  1036. $col_names[] = 'owner';
  1037. }
  1038. if (!isset($config['result_hidden'])) {
  1039. $header_row .= '<th>'.UOJLocale::get('problems::result').'</th>';
  1040. }
  1041. if (!isset($config['submit_time_hidden'])) {
  1042. $header_row .= '<th>'.UOJLocale::get('problems::submit time').'</th>';
  1043. $col_names[] = 'submit_time';
  1044. }
  1045. if (!isset($config['judge_time_hidden'])) {
  1046. $header_row .= '<th>'.UOJLocale::get('problems::judge time').'</th>';
  1047. }
  1048. $header_row .= '</tr>';
  1049. if (!isSuperUser($user)) {
  1050. if ($user != null) {
  1051. $permission_cond = "is_hidden = false or (is_hidden = true and problem_id in (select problem_id from problems_permissions where username = '{$user['username']}'))";
  1052. } else {
  1053. $permission_cond = "is_hidden = false";
  1054. }
  1055. if ($cond !== '1') {
  1056. $cond = "($cond) and ($permission_cond)";
  1057. } else {
  1058. $cond = $permission_cond;
  1059. }
  1060. }
  1061. echoLongTable($col_names, 'hacks', $cond, $tail, $header_row,
  1062. function($hacks) use ($config, $user) {
  1063. echoHack($hacks, $config, $user);
  1064. }, null);
  1065. }
  1066. function echoDatum($datum) {
  1067. $pid = $datum['pid'];
  1068. $title = queryProblemBrief($pid)['title'];
  1069. echo '<tr>';
  1070. echo '<td>' . $datum['id'] . '</td>';
  1071. echo '<td>', getProblemLink(queryProblemBrief($pid), '!id_and_title'), '</td>';
  1072. if ($datum['status'] == 'Done')
  1073. echo '<td><a href="/datum/' . $datum['id'] . '" class="uoj-status" data-success="1"><strong>Done</strong></a></td>';
  1074. else if ($datum['status'] == 'Failed')
  1075. echo '<td><a href="/datum/' . $datum['id'] . '" class="uoj-status" data-success="0"><strong>Failed</strong></a></td>';
  1076. else echo '<td><a href="/datum/' . $datum['id'] . '">' . $datum['status'] . '</a></td>';
  1077. echo '<td>' . $datum['request_time'] . '</td>';
  1078. echo '<td>' . $datum['finish_time'] . '</td>';
  1079. echo '<td>' . $datum['timelimit'] . ' s</td>';
  1080. echo '<td>' . $datum['memlimit'] . ' MB</td>';
  1081. echo '</tr>';
  1082. }
  1083. function echoDatumlistOnlyOne($datum) {
  1084. $header_row = '<tr><th>ID</th><th>题目</th><th>状态</th><th>请求时间</th><th>完成时间</th><th>时间限制</th><th>空间限制</th></tr>';
  1085. echo '<div class="table-responsive shadow my-4">';
  1086. echo '<table class="table table-bordered table-text-center">';
  1087. echo '<thead>';
  1088. echo $header_row;
  1089. echo '</thead>';
  1090. echo '<tbody>';
  1091. echoDatum($datum);
  1092. echo '</tbody>';
  1093. echo '</table></div>';
  1094. }
  1095. function echoDatumList() {
  1096. $col_names = array('id', 'pid', 'request_time', 'status', 'finish_time', 'timelimit', 'memlimit');
  1097. $header_row = '<tr><th>ID</th><th>题目</th><th>状态</th><th>请求时间</th><th>完成时间</th><th>时间限制</th><th>空间限制</th></tr>';
  1098. echoLongTable($col_names, 'datum_requests', '1', '', $header_row,
  1099. function($datum) { echoDatum($datum); }, null);
  1100. }
  1101. function getBlogPreview($str) {
  1102. return '';
  1103. }
  1104. function echoBlogCard($blog) {
  1105. if ($blog == null)
  1106. return;
  1107. $bloghref = "/blogs/" . $blog['id'];
  1108. $blogtitle = $blog['title'];
  1109. $poster = queryUser($blog['poster']);
  1110. $userlink = getUserLink($blog['poster']);
  1111. $posttime = $blog['post_time'];
  1112. $usermotto = $poster['motto'];
  1113. $zanblock = getClickZanBlock('B', $blog['id'], $blog['zan']);
  1114. $avatar = "https://q.qlogo.cn/g?b=qq&nk=" . $poster['qq'] . "&s=100";
  1115. error_log($blog);
  1116. error_log($poster);
  1117. error_log($poster['qq']);
  1118. error_log("FACK");
  1119. return <<<EOF
  1120. <div class="col-12 mb-3">
  1121. <div class="card wyoj-blog-card border-0 shadow-sm">
  1122. <div class="card-body p-3">
  1123. <a href="$bloghref" class="text-decoration-none text-dark">
  1124. <h5 class="mb-3 wyoj-blog-title">$blogtitle</h5>
  1125. </a>
  1126. <div class="d-flex align-items-center justify-content-between">
  1127. <div class="d-flex align-items-center" style="min-width:0;">
  1128. <img class="uoj-avatar rounded-circle flex-shrink-0 mr-2"
  1129. style="width:28px;height:28px;object-fit:cover;"
  1130. src="$avatar" alt="...">
  1131. <span class="text-truncate">$userlink</span>
  1132. <span class="text-muted ml-2 text-nowrap" style="font-size:0.85rem;">$posttime</span>
  1133. <span class="ml-3 text-truncate" style="font-size:1rem;font-family:'SimSun','宋体','Songti SC','STSong',serif;">$usermotto</span>
  1134. </div>
  1135. <div class="flex-shrink-0 ml-2">$zanblock</div>
  1136. </div>
  1137. </div>
  1138. </div>
  1139. </div>
  1140. EOF;
  1141. }
  1142. function echoRecommendProblem($pid, $link, $name, $descr) {
  1143. return <<<EOF
  1144. <div class="col-md-3 mb-4">
  1145. <div class="card h-100 p-3 text-center">
  1146. <a class="mb-2" href="$link"><h4>$pid</h4></a>
  1147. <h4 class="mb-2">$name</h4>
  1148. <span class="text-bottom">$descr</span>
  1149. </div>
  1150. </div>
  1151. EOF;
  1152. }
  1153. function echoBlog($blog, $config = array()) {
  1154. $default_config = array(
  1155. 'blog' => $blog,
  1156. 'show_title_only' => false,
  1157. 'show_content_only' => false,
  1158. 'is_preview' => false,
  1159. 'outside_blog_domain' => false,
  1160. );
  1161. foreach ($default_config as $key => $val) {
  1162. if (!isset($config[$key])) {
  1163. $config[$key] = $val;
  1164. }
  1165. }
  1166. uojIncludeView('blog-preview', $config);
  1167. }
  1168. function echoBlogTag($tag) {
  1169. echo '<a class="uoj-blog-tag"><span class="badge badge-pill badge-secondary">', HTML::escape($tag), '</span></a>';
  1170. }
  1171. function echoUOJPageHeader($page_title, $extra_config = array()) {
  1172. global $REQUIRE_LIB;
  1173. $config = UOJContext::pageConfig();
  1174. $config['REQUIRE_LIB'] = $REQUIRE_LIB;
  1175. $config['PageTitle'] = $page_title;
  1176. $config = array_merge($config, $extra_config);
  1177. uojIncludeView('page-header', $config);
  1178. }
  1179. function echoUOJPageFooter($config = array()) {
  1180. uojIncludeView('page-footer', $config);
  1181. }
  1182. function getAvatar($user) {
  1183. return '<img class="media-object img-rounded" height="50" width="50" src="' . HTML::avatar_addr($user, 50) . '">';
  1184. }
  1185. function echoRanklist($config = array()) {
  1186. $header_row = '';
  1187. $header_row .= '<tr>';
  1188. $header_row .= '<th style="width: 5em;">#</th>';
  1189. $header_row .= '<th style="width: 14em";>'.'头像'.'</th>';
  1190. $header_row .= '<th style="width: 14em;">'.UOJLocale::get('username').'</th>';
  1191. $header_row .= '<th style="width: 50em;">'.UOJLocale::get('motto').'</th>';
  1192. $header_row .= '<th style="width: 5em;">'.UOJLocale::get('rating').'</th>';
  1193. $header_row .= '</tr>';
  1194. $users = array();
  1195. $relcnt = 0;
  1196. $print_row = function($user, $now_cnt) use (&$users, &$relcnt) {
  1197. #if (!$users) {
  1198. $rank = DB::selectCount("select count(*) from user_info where rating > {$user['rating']}") + 1;
  1199. # } elseif ($user['rating'] == $users[count($users) - 1]['rating']) {
  1200. # $rank = $users[count($users) - 1]['rank'];
  1201. # } else {
  1202. # $rank = $now_cnt;
  1203. # }
  1204. $user['rank'] = $rank;
  1205. $relcnt++;
  1206. echo '<tr>';
  1207. echo '<td>' . $user['rank'] . ' (' . $relcnt . ')</td>';
  1208. echo '<td>' . getAvatar($user) . '</td>';
  1209. echo '<td>' . getUserLink($user['username']) . '</td>';
  1210. echo '<td>' . HTML::escape($user['motto']) . '</td>';
  1211. echo '<td>' . $user['rating'] . '</td>';
  1212. echo '</tr>';
  1213. $users[] = $user;
  1214. };
  1215. $col_names = array('username', 'email', 'qq', 'rating', 'motto');
  1216. $tail = 'inner join contests_registrants c on user_info.username = c.username inner join contests s on s.id = c.contest_id where datediff(now(), s.start_time) <= 180 group by c.username having cnt >= 3 order by rating desc, username asc';
  1217. # $tail = 'order by rating desc, username asc';
  1218. #
  1219. $config['raw_sql'] = 'select u.username, u.email, u.rating, u.rating_rd, u.rating_vol, u.motto, u.qq, count(*) cnt from user_info u inner join contests_registrants c on u.username = c.username inner join contests s on s.id = c.contest_id where datediff(now(), s.start_time) <= 180 group by c.username having cnt >= 3 order by rating desc, username asc';
  1220. if (isset($config['top10'])) {
  1221. $tail .= ' limit 10';
  1222. }
  1223. $config['get_row_index'] = '';
  1224. echoLongTable($col_names, 'user_info', '1', $tail, $header_row, $print_row, $config);
  1225. }