diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php
index fd69eea9..f9de0794 100644
--- a/app/Http/Controllers/AdminController.php
+++ b/app/Http/Controllers/AdminController.php
@@ -204,6 +204,8 @@ class AdminController extends Controller
$form->checkbox('auto_del_invalid_texture')->label()->hint();
+ $form->text('texture_name_regexp')->hint()->placeholder();
+
$form->textarea('comment_script')->rows(6)->description();
$form->checkbox('allow_sending_statistics')->label()->hint();
diff --git a/app/Http/Controllers/SkinlibController.php b/app/Http/Controllers/SkinlibController.php
index 6502b1d5..9529d22a 100644
--- a/app/Http/Controllers/SkinlibController.php
+++ b/app/Http/Controllers/SkinlibController.php
@@ -310,7 +310,7 @@ class SkinlibController extends Controller
}
$this->validate($request, [
- 'name' => 'required|no_special_chars',
+ 'name' => 'required|'.(option('texture_name_regexp') ? 'texture_name_regexp' : 'no_special_chars'),
'file' => 'required|max:'.option('max_upload_file_size'),
'public' => 'required'
]);
diff --git a/app/Providers/ValidatorExtendServiceProvider.php b/app/Providers/ValidatorExtendServiceProvider.php
index a4be21ac..41d3bd06 100644
--- a/app/Providers/ValidatorExtendServiceProvider.php
+++ b/app/Providers/ValidatorExtendServiceProvider.php
@@ -46,6 +46,10 @@ class ValidatorExtendServiceProvider extends ServiceProvider
return preg_match($regexp, $value);
});
+ Validator::extend('texture_name_regexp', function ($a, $value, $p, $v) {
+ return preg_match(option('texture_name_regexp'), $value);
+ });
+
Validator::extend('preference', function ($a, $value, $p, $v) {
return preg_match('/^(default|slim)$/', $value);
});
diff --git a/config/options.php b/config/options.php
index 18b8826f..65793a0b 100644
--- a/config/options.php
+++ b/config/options.php
@@ -32,6 +32,7 @@ return [
'update_source' => 'https://work.prinzeugen.net/update.json',
'copyright_text' => 'Copyright © '.getdate()['year'].' {site_name}. All rights reserved.',
'auto_del_invalid_texture' => 'false',
+ 'texture_name_regexp' => '',
'return_200_when_notfound' => 'false',
'cache_expire_time' => '31536000',
'max_upload_file_size' => '1024',
diff --git a/resources/lang/en/options.yml b/resources/lang/en/options.yml
index 9cd1d8b0..fad5cc9a 100644
--- a/resources/lang/en/options.yml
+++ b/resources/lang/en/options.yml
@@ -103,6 +103,10 @@ general:
title: Invalid Textures
label: Delete invalid textures automatically.
hint: Delete textures records whose file no longer exists from skinlib.
+ texture_name_regexp:
+ title: Texture Name Rules
+ hint: The RegExp for validating name of uploaded textures. Leave empty to allow any character except single, double quote and backslash.
+ placeholder: Regular Expressions
comment_script:
title: Comment Script
description: Placeholders are available in comment scripts. {tid} will be replaced with texture id, {name} will be replaced with texture name, {url} will be replaced with current URL.
diff --git a/resources/lang/en/skinlib.yml b/resources/lang/en/skinlib.yml
index cd907acb..abe0e0f1 100644
--- a/resources/lang/en/skinlib.yml
+++ b/resources/lang/en/skinlib.yml
@@ -61,6 +61,7 @@ upload:
texture-name: Texture Name
name-rule: Less than 32 characters and must not contain any special one.
+ name-rule-regexp: Custom name rules are applied. :regexp
texture-type: Texture Type
select-file: Select File
private-score-notice: It will spend you more scores to set it as private. You will be charged :score scores for every KB storage.
diff --git a/resources/lang/en/validation.yml b/resources/lang/en/validation.yml
index 502bf6f8..7ee5d61a 100644
--- a/resources/lang/en/validation.yml
+++ b/resources/lang/en/validation.yml
@@ -1,9 +1,10 @@
# Blessing Skin
-username: ':attribute format is invalid.'
-player_name: 'The :attribute contains invalid character.'
-no_special_chars: 'The :attribute must not contain special characters.'
-preference: 'The :attribute must be default or slim.'
-model: 'The :attribute must be steve, alex or cape.'
+username: ':attribute format is invalid.'
+player_name: 'The :attribute contains invalid character.'
+texture_name_regexp: 'The :attribute contains invalid character.'
+no_special_chars: 'The :attribute must not contain special characters.'
+preference: 'The :attribute must be default or slim.'
+model: 'The :attribute must be steve, alex or cape.'
accepted: 'The :attribute must be accepted.'
active_url: 'The :attribute is not a valid URL.'
diff --git a/resources/lang/zh_CN/options.yml b/resources/lang/zh_CN/options.yml
index e236ad73..32e17df3 100644
--- a/resources/lang/zh_CN/options.yml
+++ b/resources/lang/zh_CN/options.yml
@@ -103,6 +103,10 @@ general:
title: 失效材质
label: 自动删除失效材质
hint: 自动从皮肤库中删除文件不存在的材质记录
+ texture_name_regexp:
+ title: 材质名称规则
+ hint: 皮肤库上传材质时名称的正则表达式。留空表示允许使用除半角单双引号、反斜杠以外的任意字符。
+ placeholder: 正则表达式,不懂别乱填
comment_script:
title: 评论代码
description: 评论代码内可使用占位符,{tid} 将会被自动替换为材质的 id,{name} 会被替换为材质名称,{url} 会被替换为当前页面地址。
diff --git a/resources/lang/zh_CN/skinlib.yml b/resources/lang/zh_CN/skinlib.yml
index 9d1ce783..f598a48e 100644
--- a/resources/lang/zh_CN/skinlib.yml
+++ b/resources/lang/zh_CN/skinlib.yml
@@ -60,6 +60,7 @@ upload:
texture-name: 材质名称
name-rule: 材质名称应该小于 32 个字节且不能包含奇怪的符号
+ name-rule-regexp: 本站已应用特殊的名称规则::regexp
texture-type: 材质类型
select-file: 选择文件
private-score-notice: 私密材质将会消耗更多的积分:每 KB 存储空间 :score 积分
diff --git a/resources/lang/zh_CN/validation.yml b/resources/lang/zh_CN/validation.yml
index ee1a4b86..f1c37dfb 100644
--- a/resources/lang/zh_CN/validation.yml
+++ b/resources/lang/zh_CN/validation.yml
@@ -1,9 +1,10 @@
# Blessing Skin
-username: ':attribute 格式错误。'
-player_name: ':attribute 不符合规则。'
-no_special_chars: ':attribute 不能包含特殊字母。'
-preference: ':attribute 的值必须为 default 或 slim。'
-model: ':attribute 的值必须为 steve、alex 或 cape。'
+username: ':attribute 格式错误。'
+player_name: ':attribute 不符合规则。'
+texture_name_regexp: ':attribute 不符合规则。'
+no_special_chars: ':attribute 不能包含特殊字母。'
+preference: ':attribute 的值必须为 default 或 slim。'
+model: ':attribute 的值必须为 steve、alex 或 cape。'
accepted: ':attribute 必须接受。'
active_url: ':attribute 不是一个有效的网址。'
diff --git a/resources/views/skinlib/upload.tpl b/resources/views/skinlib/upload.tpl
index f9fe110c..72a412f3 100644
--- a/resources/views/skinlib/upload.tpl
+++ b/resources/views/skinlib/upload.tpl
@@ -30,7 +30,10 @@