mirror of
https://github.com/typecho/typecho.git
synced 2025-03-18 08:59:40 +01:00
Support IDN (#1629)
* Support IDN * use js * Optimize code * Optimize code * fix URL script * remove unnecessary use --------- Co-authored-by: joyqi <joyqi@segmentfault.com>
This commit is contained in:
parent
e89b1bbcf6
commit
a1f62e1bcc
File diff suppressed because one or more lines are too long
@ -2,7 +2,7 @@
|
||||
<script>
|
||||
(function () {
|
||||
$(document).ready(function () {
|
||||
var error = $('.typecho-option .error:first');
|
||||
const error = $('.typecho-option .error:first');
|
||||
|
||||
if (error.length > 0) {
|
||||
$('html,body').scrollTop(error.parents('.typecho-option').offset().top);
|
||||
@ -23,10 +23,29 @@
|
||||
});
|
||||
|
||||
$('label input[type=text]').click(function (e) {
|
||||
var check = $('#' + $(this).parents('label').attr('for'));
|
||||
const check = $('#' + $(this).parents('label').attr('for'));
|
||||
check.prop('checked', true);
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.main form input[type="url"]').each(function () {
|
||||
const self = $(this);
|
||||
const input = $('<input type="hidden" />').attr('name', self.attr('name'));
|
||||
|
||||
function setInput() {
|
||||
const url = self.val();
|
||||
|
||||
try {
|
||||
const urlObj = new URL(url);
|
||||
input.val(urlObj.toString());
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
self.removeAttr('name').after(input).on('input', setInput);
|
||||
setInput();
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
@ -11,7 +11,7 @@ $stat = \Widget\Stat::alloc();
|
||||
<?php include 'page-title.php'; ?>
|
||||
<div class="row typecho-page-main">
|
||||
<div class="col-mb-12 col-tb-3">
|
||||
<p><a href="https://gravatar.com/emails/"
|
||||
<p><a href="https://gravatar.com/"
|
||||
title="<?php _e('在 Gravatar 上修改头像'); ?>"><?php echo '<img class="profile-avatar" src="' . \Typecho\Common::gravatarUrl($user->mail, 220, 'X', 'mm', $request->isSecure()) . '" alt="' . $user->screenName . '" />'; ?></a>
|
||||
</p>
|
||||
<h2><?php $user->screenName(); ?></h2>
|
||||
|
@ -2,7 +2,7 @@
|
||||
* Forms
|
||||
*/
|
||||
|
||||
input[type=text], input[type=password], input[type=email],
|
||||
input[type=text], input[type=url], input[type=password], input[type=email],
|
||||
textarea {
|
||||
background: #FFF;
|
||||
border: 1px solid #D9D9D6;
|
||||
|
@ -1477,5 +1477,21 @@ EOF;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* IDN转UTF8
|
||||
*
|
||||
* @param string $url
|
||||
* @return string
|
||||
*/
|
||||
public static function idnToUtf8(string $url): string
|
||||
{
|
||||
if (function_exists('idn_to_utf8') && !empty($url)) {
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
$url = str_replace($host, idn_to_utf8($host), $url);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
54
var/Typecho/Widget/Helper/Form/Element/Url.php
Normal file
54
var/Typecho/Widget/Helper/Form/Element/Url.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Typecho\Widget\Helper\Form\Element;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Widget\Helper\Form\Element;
|
||||
use Typecho\Widget\Helper\Layout;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Url 表单项帮手类
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Url extends Element
|
||||
{
|
||||
/**
|
||||
* 初始化当前输入项
|
||||
*
|
||||
* @param string|null $name 表单元素名称
|
||||
* @param array|null $options 选择项
|
||||
* @return Layout|null
|
||||
*/
|
||||
public function input(?string $name = null, ?array $options = null): ?Layout
|
||||
{
|
||||
$input = new Layout('input', ['id' => $name . '-0-' . self::$uniqueId,
|
||||
'name' => $name, 'type' => 'url', 'class' => 'text']);
|
||||
$this->container($input);
|
||||
$this->label->setAttribute('for', $name . '-0-' . self::$uniqueId);
|
||||
$this->inputs[] = $input;
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置表单项默认值
|
||||
*
|
||||
* @param mixed $value 表单项默认值
|
||||
*/
|
||||
protected function inputValue($value)
|
||||
{
|
||||
if (isset($value)) {
|
||||
$this->input->setAttribute('value', htmlspecialchars(Common::idnToUtf8($value)));
|
||||
} else {
|
||||
$this->input->removeAttribute('value');
|
||||
}
|
||||
}
|
||||
}
|
@ -153,7 +153,7 @@ class General extends Options implements ActionInterface
|
||||
|
||||
/** 站点地址 */
|
||||
if (!defined('__TYPECHO_SITE_URL__')) {
|
||||
$siteUrl = new Form\Element\Text(
|
||||
$siteUrl = new Form\Element\Url(
|
||||
'siteUrl',
|
||||
null,
|
||||
$this->options->originalSiteUrl,
|
||||
|
@ -222,7 +222,7 @@ class Profile extends Users implements ActionInterface
|
||||
$form->addInput($screenName);
|
||||
|
||||
/** 个人主页地址 */
|
||||
$url = new Form\Element\Text('url', null, null, _t('个人主页地址'), _t('此用户的个人主页地址, 请用 <code>https://</code> 开头.'));
|
||||
$url = new Form\Element\Url('url', null, null, _t('个人主页地址'), _t('此用户的个人主页地址, 请用 <code>https://</code> 开头.'));
|
||||
$form->addInput($url);
|
||||
|
||||
/** 电子邮箱地址 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user