feat: friend links
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2022-09-21 11:33:42 +08:00
parent f57fa8a895
commit b7a0ee7fda
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
4 changed files with 124 additions and 8 deletions

View File

@ -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`
--

View File

@ -1,6 +1,7 @@
<?php
$blogs = DB::selectAll("select blogs.id, title, poster, post_time from important_blogs, blogs where is_hidden = 0 and important_blogs.blog_id = blogs.id order by level desc, important_blogs.blog_id desc limit 5");
$countdowns = DB::selectAll("select * from countdowns order by endtime asc")
$countdowns = DB::selectAll("select * from countdowns order by endtime asc");
$friend_links = DB::selectAll("select * from friend_links order by level desc, id asc");
?>
<?php echoUOJPageHeader(UOJConfig::$data['profile']['oj-name-short']) ?>
<div class="row">
@ -77,19 +78,18 @@
<?php endif ?>
</li>
<?php endforeach ?>
</div>
</ul>
</div>
</div>
<div class="card card-default mt-4">
<div class="card-body">
<h3 class="card-title" style="font-size: 1.25rem">友情链接</h3>
<ul class="pl-4 mb-0">
<?php foreach ($friend_links as $friend_link): ?>
<li>
<a href="http://www.sjzez.com">石家庄二中</a>
</li>
<li>
<a href="http://www.sjzezsyxx.com">石家庄二中实验学校</a>
<a href="<?= $friend_link['url'] ?>" target="_blank"><?= $friend_link['title'] ?></a>
</li>
<?php endforeach ?>
</ul>
</div>
</div>

View File

@ -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 = <<<EOD
<tr>
<th>ID</th>
<th>名称</th>
<th>链接</th>
<th>置顶等级</th>
</tr>
EOD;
$friend_links_print_row = function($row) {
echo <<<EOD
<tr>
<td>{$row['id']}</td>
<td>{$row['title']}</td>
<td>{$row['url']}</td>
<td>{$row['level']}</td>
</tr>
EOD;
};
$contest_submissions_deleter = new UOJForm('contest_submissions');
$contest_submissions_deleter->addInput('contest_id', 'text', '比赛ID', '',
function ($x) {
@ -631,6 +712,13 @@ EOD;
<?php $countdown_adder->printHTML(); ?>
<h5>删除倒计时</h5>
<?php $countdown_deleter->printHTML(); ?>
<h4>友情链接</h4>
<?php echoLongTable(array('id', 'title', 'url', 'level'), 'friend_links', '1', 'order by level desc, id asc', $friend_links_header_row, $friend_links_print_row, $userlist_config) ?>
<h5>添加友情链接</h5>
<?php $friend_link_adder->printHTML(); ?>
<h5>删除友情链接</h5>
<?php $friend_link_deleter->printHTML(); ?>
</div>
<?php elseif ($cur_tab === 'submissions'): ?>
<div>

View File

@ -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;
}