uoj-html-lib.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  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></tr>', queryUserExtgroups($user), function($grp) {
  384. $link = getUserLink(queryUser($grp)['username']);
  385. echo <<<HTML
  386. <tr>
  387. <td>$link</td>
  388. <td><a href="/problems/group/{$grp}">题目</a></td>
  389. </tr>
  390. HTML;
  391. });
  392. }
  393. function echoGroupMemberList($grp) {
  394. echoShortList('<tr><th>用户名</th><th>管理</th></tr>', queryGroupMembers($grp),
  395. function($usern) use ($grp) {
  396. $username = $usern['username'];
  397. $user = queryUser($username);
  398. $link = getUserLink($username);
  399. if (hasGroupCtrlPermission($user, $grp)) $adminp = '<b>是</b>';
  400. else $adminp = '否';
  401. echo <<<HTML
  402. <tr>
  403. <td>$link</td>
  404. <td>$adminp</td>
  405. </tr>
  406. HTML;
  407. });
  408. }
  409. function echoGroupProblemList($grp) {
  410. echoShortList('<tr><th>题号</th><th>题名</th><th>控制</th><th>压缩包大小</th></tr>', queryGroupProblems($grp),
  411. function($pid) use ($grp) {
  412. $problem = queryProblemBrief($pid);
  413. $pid = $pid;
  414. $title = $problem['title'];
  415. if ($problem['ctrl'] && $problem['ctrl'] == $grp['username']) $adminp = '<b>是</b>';
  416. else $adminp = '否';
  417. $size = printSize(queryProblemSize($pid));
  418. echo <<<HTML
  419. <tr><td>$pid</td>
  420. <td><a href="/problem/{$pid}">$title</a></td>
  421. <td>$adminp</td>
  422. <td>$size</td></tr>
  423. HTML;
  424. });
  425. }
  426. function echoGroupProblemSizeList($grp) {
  427. echoShortList('<tr><th>题号</th><th>题名</th><th>压缩包大小</th></tr>', queryGroupCtrlProblems($grp),
  428. function($pid) {
  429. $problem = queryProblemBrief($pid);
  430. $pid = $pid;
  431. $title = $problem['title'];
  432. $size = printSize(queryProblemSize($pid));
  433. echo <<<HTML
  434. <tr><td>$pid</td>
  435. <td><a href="/problem/{$pid}">$title</a></td>
  436. <td>$size</td></tr>
  437. HTML;
  438. });
  439. }
  440. function echoControlGroupList($user) {
  441. echoShortList('<tr><th>组名</th><th>管理</th></tr>', queryUserCtrlgroups($user), function($grp) {
  442. $link = getUserLink(queryUser($grp)['username']);
  443. echo <<<HTML
  444. <tr>
  445. <td>$link</td>
  446. <td><a href="/group-manage/{$grp}">管理</a></td>
  447. </tr>
  448. HTML;
  449. });
  450. }
  451. function echoGroupsList() {
  452. $header_row = '<tr>';
  453. $col_names = ['username', 'privs'];
  454. $header_row .= '<th>组名</th>';
  455. $header_row .= '<th>组权限</th>';
  456. $header_row .= '</tr>';
  457. $table_name = 'user_info';
  458. echoLongTable($col_names, $table_name, "username like 'group_%'", '', $header_row,
  459. function ($group) {
  460. $link = getUserLink($group['username']);
  461. $privs = $group['privs'];
  462. echo <<<HTML
  463. <tr>
  464. <td>
  465. {$link}
  466. </td>
  467. <td>
  468. {$privs_pretty}
  469. </td>
  470. </tr>
  471. HTML;
  472. }, []);
  473. }
  474. function echoCertsList($user) {
  475. echoShortList('<tr><th>勋章</th><th>展示</th></tr>', explode(',', $user['certslist']), function($certs) {
  476. $col = explode('#', $certs)[0];
  477. $text = explode('#', $certs)[1];
  478. $cert = '<span class="uoj-certs uoj-certs-' . $col . '">' . $text . '</span>';
  479. echo <<<HTML
  480. <tr>
  481. <td>$cert</td>
  482. <td>
  483. <form action="/certs-manage" method="post">
  484. <input type="hidden" name="certs" value="$certs">
  485. <button type="submit" class="btn btn-primary">展示这个</button>
  486. </form>
  487. </td>
  488. </tr>
  489. HTML;
  490. });
  491. }
  492. function echoPastesList() {
  493. $header_row = '<tr>';
  494. $col_names = ['`index`','creator','created_at'];
  495. $header_row .= '<th>ID</th>';
  496. $header_row .= '<th>'.UOJLocale::get("problems::submitter").'</th>';
  497. $header_row .= '<th>'.UOJLocale::get('problems::submit time').'</th>';
  498. $header_row .= '<th> 操作 </th>';
  499. $header_row .= '</tr>';
  500. $table_name = 'pastes';
  501. echoLongTable($col_names, $table_name, "1", 'order by created_at desc', $header_row,
  502. function($paste) {
  503. $user = getUserLink($paste['creator']);
  504. $token = HTML::hiddenToken();
  505. echo <<<HTML
  506. <tr>
  507. <td>
  508. <a href="/pastes/{$paste['index']}">{$paste['index']}</a>
  509. </td>
  510. <td>
  511. {$user}
  512. </td>
  513. <td>
  514. {$paste['created_at']}
  515. </td>
  516. <td>
  517. <form action="/super-manage/paste" method="post" class="form-horizontal">
  518. {$token}
  519. <input type="text" class="form-control" name="paste_deleter_name" id="input-paste_deleter_name" value="{$paste['index']}" style="display: none;">
  520. <button type="submit" name="submit-paste_deleter" value="paste_deleter" class="btn btn-sm btn-danger" style="margin: 0">删除</button>
  521. </form>
  522. </td>
  523. </tr>
  524. HTML;
  525. }, []);
  526. }
  527. function echoPasteContent($paste) {
  528. $zip_file = new ZipArchive();
  529. $submission_content = json_decode($paste['content'], true);
  530. $zip_file->open(UOJContext::storagePath().$submission_content['file_name']);
  531. $config = array();
  532. foreach ($submission_content['config'] as $config_key => $config_val) {
  533. $config[$config_val[0]] = $config_val[1];
  534. }
  535. $file_content = $zip_file->getFromName("paste.code");
  536. $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
  537. $file_language = htmlspecialchars($config["paste_language"]);
  538. $footer_text = UOJLocale::get('problems::source code').', '.UOJLocale::get('problems::language').': '.$file_language;
  539. $footer_text .= ", ".UOJLocale::get("problems::submitter") . <<<HTML
  540. : <a href="/user/profile/${paste['creator']}">${paste['creator']}</a>
  541. HTML;
  542. $footer_text .= ", ".UOJLocale::get("problems::submit time").": ".$paste['created_at'];
  543. switch ($file_language) {
  544. case 'C++14':
  545. case 'C++17':
  546. case 'C++17ubsan':
  547. $sh_class = 'sh_cpp';
  548. break;
  549. case 'Python2':
  550. case 'Python3':
  551. $sh_class = 'sh_python';
  552. break;
  553. case 'Java8':
  554. case 'Java11':
  555. $sh_class = 'sh_java';
  556. break;
  557. case 'C':
  558. $sh_class = 'sh_c';
  559. break;
  560. case 'Pascal':
  561. $sh_class = 'sh_pascal';
  562. break;
  563. default:
  564. $sh_class = '';
  565. break;
  566. }
  567. echo '<div class="card border-info mb-3">';
  568. echo '<div class="card-header bg-info">';
  569. echo '<h4 class="card-title">Paste!</h4>';
  570. echo '</div>';
  571. echo '<div class="card-body">';
  572. echo '<pre><code class="'.$sh_class.'">'.$file_content."\n".'</code></pre>';
  573. echo '</div>';
  574. echo '<div class="card-footer">'.$footer_text.'</div>';
  575. echo '</div>';
  576. $zip_file->close();
  577. }
  578. function echoSubmissionContent($submission, $requirement) {
  579. $zip_file = new ZipArchive();
  580. $submission_content = json_decode($submission['content'], true);
  581. $zip_file->open(UOJContext::storagePath().$submission_content['file_name']);
  582. $config = array();
  583. foreach ($submission_content['config'] as $config_key => $config_val) {
  584. $config[$config_val[0]] = $config_val[1];
  585. }
  586. foreach ($requirement as $req) {
  587. if ($req['type'] == "source code") {
  588. $file_content = $zip_file->getFromName("{$req['name']}.code");
  589. $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
  590. $file_language = htmlspecialchars($config["{$req['name']}_language"]);
  591. $footer_text = UOJLocale::get('problems::source code').', '.UOJLocale::get('problems::language').': '.$file_language;
  592. switch ($file_language) {
  593. case 'C++14':
  594. case 'C++17':
  595. case 'C++17ubsan':
  596. $sh_class = 'sh_cpp';
  597. break;
  598. case 'Python2':
  599. case 'Python3':
  600. $sh_class = 'sh_python';
  601. break;
  602. case 'Java8':
  603. case 'Java11':
  604. $sh_class = 'sh_java';
  605. break;
  606. case 'C':
  607. $sh_class = 'sh_c';
  608. break;
  609. case 'Pascal':
  610. $sh_class = 'sh_pascal';
  611. break;
  612. default:
  613. $sh_class = '';
  614. break;
  615. }
  616. echo '<div class="card border-info mb-3">';
  617. echo '<div class="card-header bg-info">';
  618. echo '<h4 class="card-title">'.$req['name'].'</h4>';
  619. echo '</div>';
  620. echo '<div class="card-body">';
  621. echo '<pre><code class="'.$sh_class.'">'.$file_content."\n".'</code></pre>';
  622. echo '</div>';
  623. echo '<div class="card-footer">'.$footer_text.'</div>';
  624. echo '</div>';
  625. } elseif ($req['type'] == "text") {
  626. $file_content = $zip_file->getFromName("{$req['file_name']}", 504);
  627. $file_content = strOmit($file_content, 500);
  628. $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
  629. $footer_text = UOJLocale::get('problems::text file');
  630. echo '<div class="card border-info mb-3">';
  631. echo '<div class="card-header bg-info">';
  632. echo '<h4 class="card-title">'.$req['file_name'].'</h4>';
  633. echo '</div>';
  634. echo '<div class="card-body">';
  635. echo '<pre>'."\n".$file_content."\n".'</pre>';
  636. echo '</div>';
  637. echo '<div class="card-footer">'.$footer_text.'</div>';
  638. echo '</div>';
  639. }
  640. }
  641. $zip_file->close();
  642. }
  643. class JudgementDetailsPrinter {
  644. private $name;
  645. private $styler;
  646. private $dom;
  647. private $subtask_num;
  648. private function _print_c($node) {
  649. foreach ($node->childNodes as $child) {
  650. if ($child->nodeName == '#text') {
  651. echo htmlspecialchars($child->nodeValue);
  652. } else {
  653. $this->_print($child);
  654. }
  655. }
  656. }
  657. private function _print($node) {
  658. if ($node->nodeName == 'error') {
  659. echo "<pre>\n";
  660. $this->_print_c($node);
  661. echo "\n</pre>";
  662. } elseif ($node->nodeName == 'tests') {
  663. echo '<div id="', $this->name, '_details_accordion">';
  664. if ($this->styler->show_small_tip) {
  665. echo '<div class="text-right text-muted">', '小提示:点击横条可展开更详细的信息', '</div>';
  666. } elseif ($this->styler->ioi_contest_is_running) {
  667. echo '<div class="text-right text-muted">', 'IOI 赛制比赛中不支持显示详细信息', '</div>';
  668. }
  669. $this->_print_c($node);
  670. echo '</div>';
  671. } elseif ($node->nodeName == 'subtask') {
  672. $subtask_num = $node->getAttribute('num');
  673. $subtask_score = $node->getAttribute('score');
  674. $subtask_info = $node->getAttribute('info');
  675. echo '<div class="card ', $this->styler->getTestInfoClass($subtask_info), ' mb-3">';
  676. $accordion_parent = "{$this->name}_details_accordion";
  677. $accordion_collapse = "{$accordion_parent}_collapse_subtask_{$subtask_num}";
  678. $accordion_collapse_accordion = "{$accordion_collapse}_accordion";
  679. echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
  680. echo '<div class="row">';
  681. echo '<div class="col-sm-4">';
  682. echo '<h3 class="card-title">', 'Subtask #', $subtask_num, ': ', '</h3>';
  683. echo '</div>';
  684. if ($this->styler->show_score) {
  685. echo '<div class="col-sm-4">';
  686. echo '得分:', $subtask_score;
  687. echo '</div>';
  688. echo '<div class="col-sm-4">';
  689. echo htmlspecialchars($subtask_info);
  690. echo '</div>';
  691. } else {
  692. echo '<div class="col-sm-8">';
  693. echo htmlspecialchars($subtask_info);
  694. echo '</div>';
  695. }
  696. echo '</div>';
  697. echo '</div>';
  698. echo '<div id="', $accordion_collapse, '" class="card-collapse collapse">';
  699. echo '<div class="card-body">';
  700. echo '<div id="', $accordion_collapse_accordion, '">';
  701. $this->subtask_num = $subtask_num;
  702. $this->_print_c($node);
  703. $this->subtask_num = null;
  704. echo '</div>';
  705. echo '</div>';
  706. echo '</div>';
  707. echo '</div>';
  708. } elseif ($node->nodeName == 'test') {
  709. $test_info = $node->getAttribute('info');
  710. $test_num = $node->getAttribute('num');
  711. $test_score = $node->getAttribute('score');
  712. $test_time = $node->getAttribute('time');
  713. $test_memory = $node->getAttribute('memory');
  714. echo '<div class="card ', $this->styler->getTestInfoClass($test_info), ' mb-3">';
  715. $accordion_parent = "{$this->name}_details_accordion";
  716. if ($this->subtask_num != null) {
  717. $accordion_parent .= "_collapse_subtask_{$this->subtask_num}_accordion";
  718. }
  719. $accordion_collapse = "{$accordion_parent}_collapse_test_{$test_num}";
  720. if (!$this->styler->shouldFadeDetails($test_info)) {
  721. echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
  722. } else {
  723. echo '<div class="card-header">';
  724. }
  725. echo '<div class="row">';
  726. echo '<div class="col-sm-4">';
  727. if ($test_num > 0) {
  728. echo '<h4 class="card-title">', 'Test #', $test_num, ': ', '</h4>';
  729. } else {
  730. echo '<h4 class="card-title">', 'Extra Test:', '</h4>';
  731. }
  732. echo '</div>';
  733. if ($this->styler->show_score) {
  734. echo '<div class="col-sm-4">';
  735. echo '得分:', $test_score;
  736. echo '</div>';
  737. echo '<div class="col-sm-4">';
  738. echo htmlspecialchars($test_info);
  739. echo '</div>';
  740. } else {
  741. echo '<div class="col-sm-8">';
  742. echo htmlspecialchars($test_info);
  743. echo '</div>';
  744. }
  745. echo '<div class="col-sm-4">';
  746. if ($test_time >= 0) {
  747. echo '时间:', $test_time, 'ms';
  748. }
  749. echo '</div>';
  750. echo '<div class="col-sm-4">';
  751. if ($test_memory >= 0) {
  752. echo '内存:', $test_memory, 'kb';
  753. }
  754. echo '</div>';
  755. echo '</div>';
  756. echo '</div>';
  757. if (!$this->styler->shouldFadeDetails($test_info)) {
  758. $accordion_collapse_class = 'card-collapse collapse';
  759. if ($this->styler->collapse_in) {
  760. $accordion_collapse_class .= ' in';
  761. }
  762. echo '<div id="', $accordion_collapse, '" class="', $accordion_collapse_class, '">';
  763. echo '<div class="card-body">';
  764. $this->_print_c($node);
  765. echo '</div>';
  766. echo '</div>';
  767. }
  768. echo '</div>';
  769. } elseif ($node->nodeName == 'custom-test') {
  770. $test_info = $node->getAttribute('info');
  771. $test_time = $node->getAttribute('time');
  772. $test_memory = $node->getAttribute('memory');
  773. echo '<div class="card ', $this->styler->getTestInfoClass($test_info), ' mb-3">';
  774. $accordion_parent = "{$this->name}_details_accordion";
  775. $accordion_collapse = "{$accordion_parent}_collapse_custom_test";
  776. if (!$this->styler->shouldFadeDetails($test_info)) {
  777. echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
  778. } else {
  779. echo '<div class="card-header">';
  780. }
  781. echo '<div class="row">';
  782. echo '<div class="col-sm-2">';
  783. echo '<h4 class="card-title">', '自定义测试:', '</h4>';
  784. echo '</div>';
  785. echo '<div class="col-sm-4">';
  786. echo htmlspecialchars($test_info);
  787. echo '</div>';
  788. echo '<div class="col-sm-3">';
  789. if ($test_time >= 0) {
  790. echo '时间:', $test_time, 'ms';
  791. }
  792. echo '</div>';
  793. echo '<div class="col-sm-3">';
  794. if ($test_memory >= 0) {
  795. echo '空间:', $test_memory, 'kb';
  796. }
  797. echo '</div>';
  798. echo '</div>';
  799. echo '</div>';
  800. if (!$this->styler->shouldFadeDetails($test_info)) {
  801. $accordion_collapse_class = 'card-collapse collapse';
  802. if ($this->styler->collapse_in) {
  803. $accordion_collapse_class .= ' in';
  804. }
  805. echo '<div id="', $accordion_collapse, '" class="', $accordion_collapse_class, '">';
  806. echo '<div class="card-body">';
  807. $this->_print_c($node);
  808. echo '</div>';
  809. echo '</div>';
  810. echo '</div>';
  811. }
  812. } elseif ($node->nodeName == 'in') {
  813. echo "<h4>标准输入:</h4><pre>\n";
  814. $this->_print_c($node);
  815. echo "\n</pre>";
  816. } elseif ($node->nodeName == 'out') {
  817. echo "<h4>标准输出:</h4><pre>\n";
  818. $this->_print_c($node);
  819. echo "\n</pre>";
  820. } elseif ($node->nodeName == 'res') {
  821. echo "<h4>检验结果:</h4><pre>\n";
  822. $this->_print_c($node);
  823. echo "\n</pre>";
  824. } else {
  825. echo '<', $node->nodeName;
  826. foreach ($node->attributes as $attr) {
  827. echo ' ', $attr->name, '="', htmlspecialchars($attr->value), '"';
  828. }
  829. echo '>';
  830. $this->_print_c($node);
  831. echo '</', $node->nodeName, '>';
  832. }
  833. }
  834. public function __construct($details, $styler, $name) {
  835. $this->name = $name;
  836. $this->styler = $styler;
  837. $this->details = $details;
  838. $this->dom = new DOMDocument();
  839. if (!$this->dom->loadXML($this->details)) {
  840. throw new Exception("XML syntax error");
  841. }
  842. $this->details = '';
  843. }
  844. public function printHTML() {
  845. $this->subtask_num = null;
  846. $this->_print($this->dom->documentElement);
  847. }
  848. }
  849. function echoJudgementDetails($raw_details, $styler, $name) {
  850. try {
  851. $printer = new JudgementDetailsPrinter($raw_details, $styler, $name);
  852. $printer->printHTML();
  853. } catch (Exception $e) {
  854. echo 'Failed to show details';
  855. }
  856. }
  857. class SubmissionDetailsStyler {
  858. public $show_score = true;
  859. public $show_small_tip = true;
  860. public $collapse_in = false;
  861. public $fade_all_details = false;
  862. public function getTestInfoClass($info) {
  863. if ($info == 'Accepted' || $info == 'Extra Test Passed') {
  864. return 'card-uoj-accepted';
  865. } elseif ($info == 'Time Limit Exceeded') {
  866. return 'card-uoj-tle';
  867. } elseif ($info == 'Acceptable Answer') {
  868. return 'card-uoj-acceptable-answer';
  869. } else {
  870. return 'card-uoj-wrong';
  871. }
  872. }
  873. public function shouldFadeDetails($info) {
  874. return $this->fade_all_details || $info == 'Extra Test Passed';
  875. }
  876. }
  877. class CustomTestSubmissionDetailsStyler {
  878. public $show_score = true;
  879. public $show_small_tip = false;
  880. public $collapse_in = true;
  881. public $fade_all_details = false;
  882. public $ioi_contest_is_running = false;
  883. public function getTestInfoClass($info) {
  884. if ($info == 'Success') {
  885. return 'card-uoj-accepted';
  886. } elseif ($info == 'Time Limit Exceeded') {
  887. return 'card-uoj-tle';
  888. } elseif ($info == 'Acceptable Answer') {
  889. return 'card-uoj-acceptable-answer';
  890. } else {
  891. return 'card-uoj-wrong';
  892. }
  893. }
  894. public function shouldFadeDetails($info) {
  895. return $this->fade_all_details;
  896. }
  897. }
  898. class HackDetailsStyler {
  899. public $show_score = false;
  900. public $show_small_tip = false;
  901. public $collapse_in = true;
  902. public $fade_all_details = false;
  903. public function getTestInfoClass($info) {
  904. if ($info == 'Accepted' || $info == 'Extra Test Passed') {
  905. return 'card-uoj-accepted';
  906. } elseif ($info == 'Time Limit Exceeded') {
  907. return 'card-uoj-tle';
  908. } elseif ($info == 'Acceptable Answer') {
  909. return 'card-uoj-acceptable-answer';
  910. } else {
  911. return 'card-uoj-wrong';
  912. }
  913. }
  914. public function shouldFadeDetails($info) {
  915. return $this->fade_all_details;
  916. }
  917. }
  918. function echoSubmissionDetails($submission_details, $name) {
  919. echoJudgementDetails($submission_details, new SubmissionDetailsStyler(), $name);
  920. }
  921. function echoCustomTestSubmissionDetails($submission_details, $name) {
  922. echoJudgementDetails($submission_details, new CustomTestSubmissionDetailsStyler(), $name);
  923. }
  924. function echoHackDetails($hack_details, $name) {
  925. echoJudgementDetails($hack_details, new HackDetailsStyler(), $name);
  926. }
  927. function echoHack($hack, $config, $user) {
  928. $problem = queryProblemBrief($hack['problem_id']);
  929. echo '<tr>';
  930. if (!isset($config['id_hidden'])) {
  931. echo '<td><a href="/hack/', $hack['id'], '">#', $hack['id'], '</a></td>';
  932. }
  933. if (!isset($config['submission_hidden'])) {
  934. echo '<td><a href="/submission/', $hack['submission_id'], '">#', $hack['submission_id'], '</a></td>';
  935. }
  936. if (!isset($config['problem_hidden'])) {
  937. if ($hack['contest_id']) {
  938. echo '<td>', getContestProblemLink($problem, $hack['contest_id'], '!id_and_title'), '</td>';
  939. } else {
  940. echo '<td>', getProblemLink($problem, '!id_and_title'), '</td>';
  941. }
  942. }
  943. if (!isset($config['hacker_hidden'])) {
  944. echo '<td>', getUserLink($hack['hacker']), '</td>';
  945. }
  946. if (!isset($config['owner_hidden'])) {
  947. echo '<td>', getUserLink($hack['owner']), '</td>';
  948. }
  949. if (!isset($config['result_hidden'])) {
  950. if ($hack['judge_time'] == null) {
  951. echo '<td><a href="/hack/', $hack['id'], '">Waiting</a></td>';
  952. } elseif ($hack['success'] == null) {
  953. echo '<td><a href="/hack/', $hack['id'], '">Judging</a></td>';
  954. } elseif ($hack['success']) {
  955. echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status" data-success="1"><strong>Success!</strong></a></td>';
  956. } else {
  957. echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status" data-success="0"><strong>Failed.</strong></a></td>';
  958. }
  959. } else {
  960. echo '<td>Hidden</td>';
  961. }
  962. if (!isset($config['submit_time_hidden'])) {
  963. echo '<td>', $hack['submit_time'], '</td>';
  964. }
  965. if (!isset($config['judge_time_hidden'])) {
  966. echo '<td>', $hack['judge_time'], '</td>';
  967. }
  968. echo '</tr>';
  969. }
  970. function echoHackListOnlyOne($hack, $config, $user) {
  971. echo '<div class="table-responsive shadow my-4">';
  972. echo '<table class="table table-bordered table-text-center">';
  973. echo '<thead>';
  974. echo '<tr>';
  975. if (!isset($config['id_hidden'])) {
  976. echo '<th>ID</th>';
  977. }
  978. if (!isset($config['submission_id_hidden'])) {
  979. echo '<th>'.UOJLocale::get('problems::submission id').'</th>';
  980. }
  981. if (!isset($config['problem_hidden'])) {
  982. echo '<th>'.UOJLocale::get('problems::problem').'</th>';
  983. }
  984. if (!isset($config['hacker_hidden'])) {
  985. echo '<th>'.UOJLocale::get('problems::hacker').'</th>';
  986. }
  987. if (!isset($config['owner_hidden'])) {
  988. echo '<th>'.UOJLocale::get('problems::owner').'</th>';
  989. }
  990. if (!isset($config['result_hidden'])) {
  991. echo '<th>'.UOJLocale::get('problems::result').'</th>';
  992. }
  993. if (!isset($config['submit_time_hidden'])) {
  994. echo '<th>'.UOJLocale::get('problems::submit time').'</th>';
  995. }
  996. if (!isset($config['judge_time_hidden'])) {
  997. echo '<th>'.UOJLocale::get('problems::judge time').'</th>';
  998. }
  999. echo '</tr>';
  1000. echo '</thead>';
  1001. echo '<tbody>';
  1002. echoHack($hack, $config, $user);
  1003. echo '</tbody>';
  1004. echo '</table>';
  1005. echo '</div>';
  1006. }
  1007. function echoHacksList($cond, $tail, $config, $user) {
  1008. $header_row = '<tr>';
  1009. $col_names = array();
  1010. $col_names[] = 'id';
  1011. $col_names[] = 'success';
  1012. $col_names[] = 'judge_time';
  1013. if (!isset($config['id_hidden'])) {
  1014. $header_row .= '<th>ID</th>';
  1015. }
  1016. if (!isset($config['submission_id_hidden'])) {
  1017. $header_row .= '<th>'.UOJLocale::get('problems::submission id').'</th>';
  1018. $col_names[] = 'submission_id';
  1019. }
  1020. if (!isset($config['problem_hidden'])) {
  1021. $header_row .= '<th>'.UOJLocale::get('problems::problem').'</th>';
  1022. $col_names[] = 'problem_id';
  1023. }
  1024. if (!isset($config['hacker_hidden'])) {
  1025. $header_row .= '<th>'.UOJLocale::get('problems::hacker').'</th>';
  1026. $col_names[] = 'hacker';
  1027. }
  1028. if (!isset($config['owner_hidden'])) {
  1029. $header_row .= '<th>'.UOJLocale::get('problems::owner').'</th>';
  1030. $col_names[] = 'owner';
  1031. }
  1032. if (!isset($config['result_hidden'])) {
  1033. $header_row .= '<th>'.UOJLocale::get('problems::result').'</th>';
  1034. }
  1035. if (!isset($config['submit_time_hidden'])) {
  1036. $header_row .= '<th>'.UOJLocale::get('problems::submit time').'</th>';
  1037. $col_names[] = 'submit_time';
  1038. }
  1039. if (!isset($config['judge_time_hidden'])) {
  1040. $header_row .= '<th>'.UOJLocale::get('problems::judge time').'</th>';
  1041. }
  1042. $header_row .= '</tr>';
  1043. if (!isSuperUser($user)) {
  1044. if ($user != null) {
  1045. $permission_cond = "is_hidden = false or (is_hidden = true and problem_id in (select problem_id from problems_permissions where username = '{$user['username']}'))";
  1046. } else {
  1047. $permission_cond = "is_hidden = false";
  1048. }
  1049. if ($cond !== '1') {
  1050. $cond = "($cond) and ($permission_cond)";
  1051. } else {
  1052. $cond = $permission_cond;
  1053. }
  1054. }
  1055. echoLongTable($col_names, 'hacks', $cond, $tail, $header_row,
  1056. function($hacks) use ($config, $user) {
  1057. echoHack($hacks, $config, $user);
  1058. }, null);
  1059. }
  1060. function echoDatum($datum) {
  1061. $pid = $datum['pid'];
  1062. $title = queryProblemBrief($pid)['title'];
  1063. echo '<tr>';
  1064. echo '<td>' . $datum['id'] . '</td>';
  1065. echo '<td>', getProblemLink(queryProblemBrief($pid), '!id_and_title'), '</td>';
  1066. if ($datum['status'] == 'Done')
  1067. echo '<td><a href="/datum/' . $datum['id'] . '" class="uoj-status" data-success="1"><strong>Done</strong></a></td>';
  1068. else if ($datum['status'] == 'Failed')
  1069. echo '<td><a href="/datum/' . $datum['id'] . '" class="uoj-status" data-success="0"><strong>Failed</strong></a></td>';
  1070. else echo '<td><a href="/datum/' . $datum['id'] . '">' . $datum['status'] . '</a></td>';
  1071. echo '<td>' . $datum['request_time'] . '</td>';
  1072. echo '<td>' . $datum['finish_time'] . '</td>';
  1073. echo '<td>' . $datum['timelimit'] . ' s</td>';
  1074. echo '<td>' . $datum['memlimit'] . ' MB</td>';
  1075. echo '</tr>';
  1076. }
  1077. function echoDatumlistOnlyOne($datum) {
  1078. $header_row = '<tr><th>ID</th><th>题目</th><th>状态</th><th>请求时间</th><th>完成时间</th><th>时间限制</th><th>空间限制</th></tr>';
  1079. echo '<div class="table-responsive shadow my-4">';
  1080. echo '<table class="table table-bordered table-text-center">';
  1081. echo '<thead>';
  1082. echo $header_row;
  1083. echo '</thead>';
  1084. echo '<tbody>';
  1085. echoDatum($datum);
  1086. echo '</tbody>';
  1087. echo '</table></div>';
  1088. }
  1089. function echoDatumList() {
  1090. $col_names = array('id', 'pid', 'request_time', 'status', 'finish_time', 'timelimit', 'memlimit');
  1091. $header_row = '<tr><th>ID</th><th>题目</th><th>状态</th><th>请求时间</th><th>完成时间</th><th>时间限制</th><th>空间限制</th></tr>';
  1092. echoLongTable($col_names, 'datum_requests', '1', '', $header_row,
  1093. function($datum) { echoDatum($datum); }, null);
  1094. }
  1095. function getBlogPreview($str) {
  1096. return '';
  1097. }
  1098. function echoBlogCard($blog) {
  1099. if ($blog == null)
  1100. return;
  1101. $bloghref = "/blogs/" . $blog['id'];
  1102. $blogtitle = $blog['title'];
  1103. $poster = queryUser($blog['poster']);
  1104. $blogpreview = getBlogPreview($blog['content']);
  1105. $userlink = getUserLink($blog['poster']);
  1106. $posttime = $blog['post_time'];
  1107. $usermotto = $poster['motto'];
  1108. $zanblock = getClickZanBlock('B', $blog['id'], $blog['zan']);
  1109. return <<<EOF
  1110. <div class="col-12 mb-4">
  1111. <div class="card d-flex p-3 shadow mx-4">
  1112. <div class="align-items-start">
  1113. <a href="$bloghref"><h5>$blogtitle</h5></a>
  1114. <p>$blogpreview</p>
  1115. </div>
  1116. <div class="d-flex align-items-end justify-content-between">
  1117. <div>
  1118. <span class="mb-2">$userlink</span>
  1119. <span class="text-muted">$posttime</span>
  1120. <span class="ml-4">$usermotto</span>
  1121. </div>
  1122. $zanblock
  1123. </div>
  1124. </div>
  1125. </div>
  1126. EOF;
  1127. }
  1128. function echoRecommendProblem($pid, $link, $name, $descr) {
  1129. return <<<EOF
  1130. <div class="col-md-3 mb-4">
  1131. <div class="card h-100 p-3 text-center">
  1132. <a class="mb-2" href="$link"><h4>$pid</h4></a>
  1133. <h4 class="mb-2">$name</h4>
  1134. <span class="text-bottom">$descr</span>
  1135. </div>
  1136. </div>
  1137. EOF;
  1138. }
  1139. function echoBlog($blog, $config = array()) {
  1140. $default_config = array(
  1141. 'blog' => $blog,
  1142. 'show_title_only' => false,
  1143. 'show_content_only' => false,
  1144. 'is_preview' => false,
  1145. 'outside_blog_domain' => false,
  1146. );
  1147. foreach ($default_config as $key => $val) {
  1148. if (!isset($config[$key])) {
  1149. $config[$key] = $val;
  1150. }
  1151. }
  1152. uojIncludeView('blog-preview', $config);
  1153. }
  1154. function echoBlogTag($tag) {
  1155. echo '<a class="uoj-blog-tag"><span class="badge badge-pill badge-secondary">', HTML::escape($tag), '</span></a>';
  1156. }
  1157. function echoUOJPageHeader($page_title, $extra_config = array()) {
  1158. global $REQUIRE_LIB;
  1159. $config = UOJContext::pageConfig();
  1160. $config['REQUIRE_LIB'] = $REQUIRE_LIB;
  1161. $config['PageTitle'] = $page_title;
  1162. $config = array_merge($config, $extra_config);
  1163. uojIncludeView('page-header', $config);
  1164. }
  1165. function echoUOJPageFooter($config = array()) {
  1166. uojIncludeView('page-footer', $config);
  1167. }
  1168. function getAvatar($user) {
  1169. return '<img class="media-object img-rounded" height="50" width="50" src="' . HTML::avatar_addr($user, 50) . '">';
  1170. }
  1171. function echoRanklist($config = array()) {
  1172. $header_row = '';
  1173. $header_row .= '<tr>';
  1174. $header_row .= '<th style="width: 5em;">#</th>';
  1175. $header_row .= '<th style="width: 14em";>'.'头像'.'</th>';
  1176. $header_row .= '<th style="width: 14em;">'.UOJLocale::get('username').'</th>';
  1177. $header_row .= '<th style="width: 50em;">'.UOJLocale::get('motto').'</th>';
  1178. $header_row .= '<th style="width: 5em;">'.UOJLocale::get('rating').'</th>';
  1179. $header_row .= '</tr>';
  1180. $users = array();
  1181. $print_row = function($user, $now_cnt) use (&$users) {
  1182. if (!$users) {
  1183. $rank = DB::selectCount("select count(*) from user_info where rating > {$user['rating']}") + 1;
  1184. } elseif ($user['rating'] == $users[count($users) - 1]['rating']) {
  1185. $rank = $users[count($users) - 1]['rank'];
  1186. } else {
  1187. $rank = $now_cnt;
  1188. }
  1189. $user['rank'] = $rank;
  1190. echo '<tr>';
  1191. echo '<td>' . $user['rank'] . '</td>';
  1192. echo '<td>' . getAvatar($user) . '</td>';
  1193. echo '<td>' . getUserLink($user['username']) . '</td>';
  1194. echo '<td>' . HTML::escape($user['motto']) . '</td>';
  1195. echo '<td>' . $user['rating'] . '</td>';
  1196. echo '</tr>';
  1197. $users[] = $user;
  1198. };
  1199. $col_names = array('username', 'email', 'qq', 'rating', 'motto');
  1200. $tail = 'order by rating desc, username asc';
  1201. if (isset($config['top10'])) {
  1202. $tail .= ' limit 10';
  1203. }
  1204. $config['get_row_index'] = '';
  1205. echoLongTable($col_names, 'user_info', '1', $tail, $header_row, $print_row, $config);
  1206. }