From b7a0ee7fdac9ceb0fac4bf8b95c3eb17ce6517c4 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 21 Sep 2022 11:33:42 +0800 Subject: [PATCH] feat: friend links --- db/app_uoj233.sql | 24 ++++++++ web/app/controllers/index.php | 16 ++--- web/app/controllers/super_manage.php | 88 ++++++++++++++++++++++++++++ web/app/libs/uoj-validate-lib.php | 4 ++ 4 files changed, 124 insertions(+), 8 deletions(-) diff --git a/db/app_uoj233.sql b/db/app_uoj233.sql index cf13048..2f2d888 100644 --- a/db/app_uoj233.sql +++ b/db/app_uoj233.sql @@ -409,6 +409,30 @@ LOCK TABLES `custom_test_submissions` WRITE; /*!40000 ALTER TABLE `custom_test_submissions` ENABLE KEYS */; UNLOCK TABLES; +-- +-- Table structure for table `friend_links` +-- + +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `friend_links` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `title` varchar(40) NOT NULL, + `url` varchar(100) NOT NULL, + `level` int(10) NOT NULL DEFAULT 10, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `friend_links` +-- + +LOCK TABLES `friend_links` WRITE; +/*!40000 ALTER TABLE `friend_links` DISABLE KEYS */; +/*!40000 ALTER TABLE `friend_links` ENABLE KEYS */; +UNLOCK TABLES; + -- -- Table structure for table `groups` -- diff --git a/web/app/controllers/index.php b/web/app/controllers/index.php index 970b2d0..3e3cf52 100644 --- a/web/app/controllers/index.php +++ b/web/app/controllers/index.php @@ -1,6 +1,7 @@
@@ -77,19 +78,18 @@ -
+

友情链接

diff --git a/web/app/controllers/super_manage.php b/web/app/controllers/super_manage.php index 65d0fab..db16273 100644 --- a/web/app/controllers/super_manage.php +++ b/web/app/controllers/super_manage.php @@ -385,6 +385,87 @@ EOD; EOD; }; + $friend_link_adder = new UOJForm('new_friend_link'); + $friend_link_adder->submit_button_config['align'] = 'compressed'; + $friend_link_adder->addInput('new_friend_link_title', 'text', '名称', '', + function ($str) { + return ''; + }, + null + ); + $friend_link_adder->addInput('new_friend_link_url', 'text', '链接', '', + function($str) { + if (!validateURL($str)) { + return '链接不合法'; + } + + return ''; + }, + null + ); + $friend_link_adder->addInput('new_friend_link_level', 'text', '权重', '10', + function($str) { + if (!validateUInt($str)) { + return '权重必须是数字'; + } + + return ''; + }, + null + ); + $friend_link_adder->handle = function() { + $new_friend_link_title = $_POST['new_friend_link_title']; + $new_friend_link_url = $_POST['new_friend_link_url']; + $new_friend_link_level = $_POST['new_friend_link_level']; + $esc_new_friend_link_title = DB::escape($new_friend_link_title); + $esc_new_friend_link_url = DB::escape($new_friend_link_url); + + DB::query("insert into friend_links (title, url, level) values ('$esc_new_friend_link_title', '$esc_new_friend_link_url', $new_friend_link_level)"); + }; + $friend_link_adder->runAtServer(); + + $friend_link_deleter = new UOJForm('delete_friend_link'); + $friend_link_deleter->submit_button_config['align'] = 'compressed'; + $friend_link_deleter->addInput('delete_friend_link_id', 'text', 'ID', '', + function ($id) { + if (!validateUInt($id)) { + return 'ID不合法'; + } + + if (!DB::selectFirst("select * from friend_links where id = $id")) { + return 'ID不存在'; + } + + return ''; + }, + null + ); + $friend_link_deleter->handle = function() { + $delete_friend_link_id = $_POST['delete_friend_link_id']; + + DB::query("delete from friend_links where id = $delete_friend_link_id"); + }; + $friend_link_deleter->runAtServer(); + + $friend_links_header_row = << + ID + 名称 + 链接 + 置顶等级 + +EOD; + $friend_links_print_row = function($row) { + echo << + {$row['id']} + {$row['title']} + {$row['url']} + {$row['level']} + +EOD; + }; + $contest_submissions_deleter = new UOJForm('contest_submissions'); $contest_submissions_deleter->addInput('contest_id', 'text', '比赛ID', '', function ($x) { @@ -631,6 +712,13 @@ EOD; printHTML(); ?>
删除倒计时
printHTML(); ?> + +

友情链接

+ +
添加友情链接
+ printHTML(); ?> +
删除友情链接
+ printHTML(); ?>
diff --git a/web/app/libs/uoj-validate-lib.php b/web/app/libs/uoj-validate-lib.php index be54351..eb991a5 100644 --- a/web/app/libs/uoj-validate-lib.php +++ b/web/app/libs/uoj-validate-lib.php @@ -47,3 +47,7 @@ function validateUploadedFile($name) { function validateIP($ip) { return filter_var($ip, FILTER_VALIDATE_IP) !== false; } + +function validateURL($url) { + return filter_var($url, FILTER_VALIDATE_URL) !== false; +}