From 8cbb222d0bd897d3a201d99382d9b9aaf70ae191 Mon Sep 17 00:00:00 2001 From: Leo Lu Date: Fri, 14 Aug 2020 01:29:26 +0800 Subject: [PATCH] Added created_at field to pastes --- install/db/app_uoj233.sql | 4 ++++ web/app/controllers/paste_post.php | 2 +- web/app/controllers/paste_view.php | 4 +++- web/app/libs/uoj-html-lib.php | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/install/db/app_uoj233.sql b/install/db/app_uoj233.sql index 0ec3098..b20be87 100644 --- a/install/db/app_uoj233.sql +++ b/install/db/app_uoj233.sql @@ -702,12 +702,16 @@ create table pastes ( `index` varchar(20) null, creator varchar(20) null, + created_at datetime null, content text null ); create unique index pastes_index_uindex on pastes (`index`); +create index pastes_created_at_index + on pastes (created_at); + alter table pastes add constraint pastes_pk primary key (`index`); diff --git a/web/app/controllers/paste_post.php b/web/app/controllers/paste_post.php index 52c7cb3..565cd73 100644 --- a/web/app/controllers/paste_post.php +++ b/web/app/controllers/paste_post.php @@ -16,7 +16,7 @@ function handleUpload($zip_file_name, $content, $tot_size) { $index = uojRandString(20); $esc_index = DB::escape($index); } - DB::query("insert into pastes (`index`, `creator`, `content`) values ('$esc_index', '${myUser['username']}', '$esc_content')"); + DB::query("insert into pastes (`index`, `creator`, `content`, `created_at`) values ('$esc_index', '${myUser['username']}', '$esc_content', '".date('Y-m-d H:i:s')."')"); redirectTo("/pastes/".$index); } diff --git a/web/app/controllers/paste_view.php b/web/app/controllers/paste_view.php index 2072cf0..16b8f65 100644 --- a/web/app/controllers/paste_view.php +++ b/web/app/controllers/paste_view.php @@ -3,7 +3,9 @@ $paste_id = $_GET['rand_str_id']; $paste = DB::selectFirst("select * from pastes where `index` = '".DB::escape($paste_id)."'"); - +if (!$paste) { + become404Page(); +} $REQUIRE_LIB['shjs'] = ""; echoUOJPageHeader("Paste!"); echoPasteContent($paste); diff --git a/web/app/libs/uoj-html-lib.php b/web/app/libs/uoj-html-lib.php index d5db92b..89e746a 100644 --- a/web/app/libs/uoj-html-lib.php +++ b/web/app/libs/uoj-html-lib.php @@ -410,6 +410,7 @@ function echoPasteContent($paste) { $footer_text .= ", ".UOJLocale::get("problems::submitter") . <<${paste['creator']} HTML; + $footer_text .= ", ".UOJLocale::get("problems::submit time").": ".$paste['created_at']; switch ($file_language) { case 'C++':