1. 允许注册 CJK 用户名
文件 /vendor/flarum/core/src/User/UserValidator.php
将 47 行的 'regex:/^[a-z0-9_-]+$/i'
替换为(三个方案选一个)
// 1. CJK基础上,不允许全数字用户名出现,防止个人主页报错。
'regex:/^[-_a-zA-Z0-9\x7f-\xff]*[-_a-zA-Z\x7f-\xff][-_a-zA-Z0-9\x7f-\xff]*$/i',
// 2. CJK基础上,允许全数字用户名
'regex:/^[-_a-zA-Z0-9\x7f-\xff]+$/i',
// 3. Unicode 用户名
'alpha_dash'
文件 /vendor/flarum/core/src/Forum/Auth/Registration.php
- 将 101 行
$username = preg_replace('/[^a-z0-9-_]/i', '', $username);
注释掉。
2. 允许@艾特 CJK 用户名。
文件 /vendor/flarum/mentions/src/ConfigureMentions.php
- 大概 53 行,将
configureUserMentions
函数中$config->Preg->match
的正则表达式改为:
/\B@(?<username>[\p{L}\p{N}_-]+)(?!#)/ui
原始表达式:/\B@(?<username>[a-z0-9_-]+)(?!#)/i
- 同文件大概 91 行,将
configurePostMentions
函数中$config->Preg->match
的正则表达式改为:
/\B@(?<username>[\p{L}\p{N}_-]+)#(?<id>\d+)/ui
原始表达式:/\B@(?<username>[a-z0-9_-]+)#(?<id>\d+)/ui
3. 增加 API URL CJK 编码转换支持。(很多时候点击 CJK/Unicode 用户链接提示“找不到此资源”就是这个问题)
文件 /vendor/flarum/core/src/Api/Controller/ShowUserController.php
将 52 行的 getIdForUsername($id)
替换为 getIdForUsername(urldecode($id))
。
4. 清除缓存,必须有这一步!
终端运行 php flarum cache:clear
或其他方式。
转载自Flaurm中文社区[ext]