mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-22 13:28:41 +00:00
feat(web/user): qq avatar
This commit is contained in:
parent
6ee3ed2490
commit
3985b97f2e
@ -819,6 +819,7 @@ CREATE TABLE `user_info` (
|
||||
`codeforces_handle` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`github` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`website` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`avatar_source` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'gravatar',
|
||||
PRIMARY KEY (`username`),
|
||||
KEY `ac_num` (`ac_num`,`username`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
|
@ -44,16 +44,21 @@
|
||||
$update_profile_form = new UOJForm('update_profile');
|
||||
$username = UOJLocale::get('username');
|
||||
$avatar = UOJLocale::get('avatar');
|
||||
$change_avatar_help = UOJLocale::get('change avatar help');
|
||||
$update_profile_form->appendHTML(<<<EOD
|
||||
<div class="mb-3">
|
||||
<label for="input-username" class="form-label">$username</label>
|
||||
<input type="text" class="form-control" id="input-username" aria-describedby="help-username" value="{$user['username']}" disabled>
|
||||
<div id="help-username" class="form-text">用户名不能被修改。</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<div>$avatar</div>
|
||||
<div class="mt-1 small text-muted">$change_avatar_help</div>
|
||||
EOD);
|
||||
$update_profile_form->addVCheckboxes('avatar_source', [
|
||||
'gravatar' => 'Gravatar',
|
||||
'qq' => 'QQ',
|
||||
], UOJLocale::get('user::avatar source'), $user['avatar_source']);
|
||||
$change_avatar_help = UOJLocale::get('change avatar help');
|
||||
$update_profile_form->appendHTML(<<<EOD
|
||||
<div style="margin-top: -1.25rem;" class="mb-3 small text-muted">
|
||||
$change_avatar_help
|
||||
</div>
|
||||
EOD);
|
||||
$update_profile_form->addVInput('email', 'email', UOJLocale::get('email'), $user['email'],
|
||||
@ -103,7 +108,7 @@ EOD);
|
||||
</div>
|
||||
EOD);
|
||||
}
|
||||
$update_profile_form->addVSelect('sex', [
|
||||
$update_profile_form->addVCheckboxes('sex', [
|
||||
'U' => UOJLocale::get('refuse to answer'),
|
||||
'M' => UOJLocale::get('male'),
|
||||
'F' => UOJLocale::get('female'),
|
||||
@ -146,6 +151,7 @@ EOD);
|
||||
$esc_motto = DB::escape($vdata['motto']);
|
||||
$esc_codeforces_handle = DB::escape($vdata['codeforces_handle']);
|
||||
$esc_website = DB::escape($vdata['website']);
|
||||
$esc_avatar_source = DB::escape($_POST['avatar_source']);
|
||||
|
||||
if (isSuperUser($myUser)) {
|
||||
$esc_school = DB::escape($vdata['school']);
|
||||
@ -153,7 +159,7 @@ EOD);
|
||||
DB::update("UPDATE user_info SET school = '$esc_school' WHERE username = '{$user['username']}'");
|
||||
}
|
||||
|
||||
DB::update("UPDATE user_info SET email = '$esc_email', qq = '$esc_qq', sex = '$esc_sex', motto = '$esc_motto', codeforces_handle = '$esc_codeforces_handle', github = '$esc_github', website = '$esc_website' WHERE username = '{$user['username']}'");
|
||||
DB::update("UPDATE user_info SET email = '$esc_email', qq = '$esc_qq', sex = '$esc_sex', motto = '$esc_motto', codeforces_handle = '$esc_codeforces_handle', github = '$esc_github', website = '$esc_website', avatar_source = '$esc_avatar_source' WHERE username = '{$user['username']}'");
|
||||
};
|
||||
$update_profile_form->submit_button_config['margin_class'] = 'mt-3';
|
||||
$update_profile_form->submit_button_config['text'] = '更新';
|
||||
|
@ -225,6 +225,40 @@ EOD;
|
||||
EOD;
|
||||
$this->addNoVal($name, $html);
|
||||
}
|
||||
public function addVCheckboxes($name, $options, $label_text, $default_value) {
|
||||
$default_value = htmlspecialchars($default_value);
|
||||
$html = <<<EOD
|
||||
<div id="div-$name" class="input-group mb-3">
|
||||
<label class="form-label me-3">$label_text</label>
|
||||
EOD;
|
||||
foreach ($options as $opt_name => $opt_label) {
|
||||
$html .= <<<EOD
|
||||
<div class="form-check ms-2">
|
||||
EOD;
|
||||
if ($opt_name != $default_value) {
|
||||
$html .= <<<EOD
|
||||
<input class="form-check-input" type="radio" id="input-$name-$opt_name" name="$name" value="$opt_name">
|
||||
EOD;
|
||||
} else {
|
||||
$html .= <<<EOD
|
||||
<input class="form-check-input" type="radio" id="input-$name-$opt_name" name="$name" value="$opt_name" checked="checked">
|
||||
EOD;
|
||||
}
|
||||
$html .= <<<EOD
|
||||
<label class="form-check-label" for="input-$name-$opt_name">$opt_label</label>
|
||||
</div>
|
||||
EOD;
|
||||
}
|
||||
$html .= <<<EOD
|
||||
</div>
|
||||
EOD;
|
||||
$this->add($name, $html,
|
||||
function($opt) use ($options) {
|
||||
return isset($options[$opt]) ? '' : "无效选项";
|
||||
},
|
||||
null
|
||||
);
|
||||
}
|
||||
public function addCKEditor($name, $label_text, $default_value, $validator_php, $validator_js) {
|
||||
$default_value = htmlspecialchars($default_value);
|
||||
global $REQUIRE_LIB;
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
'avatar source' => 'Avatar source',
|
||||
'website' => 'Website',
|
||||
'user type' => 'User type',
|
||||
'admin' => 'Admin',
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
'avatar source' => '头像来源',
|
||||
'website' => '网址',
|
||||
'user type' => '用户类型',
|
||||
'admin' => '管理员',
|
||||
|
@ -8,6 +8,20 @@ class HTML {
|
||||
return strip_tags($str);
|
||||
}
|
||||
public static function avatar_addr($user, $size) {
|
||||
if ($user['avatar_source'] == 'qq' && $user['qq']) {
|
||||
$s = '5';
|
||||
|
||||
if ($size <= 40) {
|
||||
$s = '2';
|
||||
} elseif ($size <= 100) {
|
||||
$s = '3';
|
||||
} elseif ($size <= 140) {
|
||||
$s = '4';
|
||||
}
|
||||
|
||||
return "https://q1.qlogo.cn/g?b=qq&nk={$user['qq']}&s=$s";
|
||||
}
|
||||
|
||||
return '//gravatar.loli.net/avatar/' . md5(strtolower(trim($user['email']))) . "?d=mm&s=$size";
|
||||
}
|
||||
|
||||
|
@ -1,2 +1,4 @@
|
||||
ALTER TABLE `user_info` DROP COLUMN IF EXISTS `codeforces_handle`;
|
||||
ALTER TABLE `user_info` DROP COLUMN IF EXISTS `github`;
|
||||
ALTER TABLE `user_info` DROP COLUMN IF EXISTS `website`;
|
||||
ALTER TABLE `user_info` DROP COLUMN IF EXISTS `avatar_source`;
|
||||
|
@ -1,3 +1,4 @@
|
||||
ALTER TABLE `user_info` ADD COLUMN `codeforces_handle` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '';
|
||||
ALTER TABLE `user_info` ADD COLUMN `github` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '';
|
||||
ALTER TABLE `user_info` ADD COLUMN `website` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '';
|
||||
ALTER TABLE `user_info` ADD COLUMN `avatar_source` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'gravatar';
|
||||
|
Loading…
Reference in New Issue
Block a user