From 666619538a771a26e7d03cb7c46f244c7007beff Mon Sep 17 00:00:00 2001 From: Jealous <CooLanfei@163.com> Date: Thu, 21 Sep 2023 22:48:27 +0800 Subject: [PATCH 1/4] Fix typo (#1612) --- admin/file-upload-js.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/admin/file-upload-js.php b/admin/file-upload-js.php index 80ac6412..05c7bfe5 100644 --- a/admin/file-upload-js.php +++ b/admin/file-upload-js.php @@ -17,7 +17,7 @@ if (preg_match("/^([0-9]+)([a-z]{1,2})$/i", $phpMaxFilesize, $matches)) { <script src="<?php $options->adminStaticUrl('js', 'plupload.js'); ?>"></script> <script> $(document).ready(function() { - function updateAttacmentNumber () { + function updateAttachmentNumber () { var btn = $('#tab-files-btn'), balloon = $('.balloon', btn), count = $('#file-list li .insert').length; @@ -56,7 +56,7 @@ $(document).ready(function() { } }); - updateAttacmentNumber(); + updateAttachmentNumber(); function fileUploadStart (file) { $('<li id="' + file.id + '" class="loading">' @@ -113,7 +113,7 @@ $(document).ready(function() { attachInsertEvent(li); attachDeleteEvent(li); - updateAttacmentNumber(); + updateAttachmentNumber(); if (!completeFile) { completeFile = data; @@ -211,7 +211,7 @@ $(document).ready(function() { function () { $(el).fadeOut(function () { $(this).remove(); - updateAttacmentNumber(); + updateAttachmentNumber(); }); }); } From 9910a9cddcff6db47825d9a679dd6103ddcfef40 Mon Sep 17 00:00:00 2001 From: Lu Fei <52o@qq52o.cn> Date: Fri, 22 Sep 2023 10:49:51 +0800 Subject: [PATCH 2/4] Optimize checkVersion,feed code (#1605) --- var/Typecho/Http/Client.php | 2 +- var/Widget/Ajax.php | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/var/Typecho/Http/Client.php b/var/Typecho/Http/Client.php index 3c876b36..ba08298f 100644 --- a/var/Typecho/Http/Client.php +++ b/var/Typecho/Http/Client.php @@ -353,7 +353,7 @@ class Client * 获取回执的头部信息 * * @param string $key 头信息名称 - * @return string + * @return ?string */ public function getResponseHeader(string $key): ?string { diff --git a/var/Widget/Ajax.php b/var/Widget/Ajax.php index ab064398..3c01c9fd 100644 --- a/var/Widget/Ajax.php +++ b/var/Widget/Ajax.php @@ -41,10 +41,10 @@ class Ajax extends BaseOptions implements ActionInterface { $this->user->pass('editor'); $client = Client::get(); + $result = ['available' => 0]; if ($client) { $client->setHeader('User-Agent', $this->options->generator) ->setTimeout(10); - $result = ['available' => 0]; try { $client->send('https://typecho.org/version.json'); @@ -72,11 +72,9 @@ class Ajax extends BaseOptions implements ActionInterface } catch (\Exception $e) { // do nothing } - - $this->response->throwJson($result); } - throw new Exception(_t('禁止访问'), 403); + $this->response->throwJson($result); } /** @@ -89,6 +87,7 @@ class Ajax extends BaseOptions implements ActionInterface { $this->user->pass('subscriber'); $client = Client::get(); + $data = []; if ($client) { $client->setHeader('User-Agent', $this->options->generator) ->setTimeout(10) @@ -102,8 +101,6 @@ class Ajax extends BaseOptions implements ActionInterface $matches ); - $data = []; - if ($matches) { foreach ($matches[0] as $key => $val) { $data[] = [ @@ -117,11 +114,9 @@ class Ajax extends BaseOptions implements ActionInterface } } } - - $this->response->throwJson($data); } - throw new Exception(_t('禁止访问'), 403); + $this->response->throwJson($data); } /** From 91ae56484d355a6255352844e75b541f0df6d2b3 Mon Sep 17 00:00:00 2001 From: joyqi <joyqi@users.noreply.github.com> Date: Fri, 22 Sep 2023 10:50:39 +0800 Subject: [PATCH 3/4] fix the source to get content type (#1622) --- var/Typecho/Request.php | 18 +++++++++++++++++- var/Typecho/Widget/Request.php | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/var/Typecho/Request.php b/var/Typecho/Request.php index c42c10a5..ac0c1496 100644 --- a/var/Typecho/Request.php +++ b/var/Typecho/Request.php @@ -351,6 +351,19 @@ class Request return ($this->pathInfo = '/' . ltrim(urldecode($pathInfo), '/')); } + /** + * 获取请求的内容类型 + * + * @return string|null + */ + public function getContentType(): ?string + { + return $this->getServer( + 'CONTENT_TYPE', + $this->getServer('HTTP_CONTENT_TYPE') + ); + } + /** * 获取环境变量 * @@ -492,7 +505,10 @@ class Request */ public function isJson(): bool { - return !!preg_match("/^\s*application\/json(;|$)/i", $this->getHeader('Content-Type', '')); + return !!preg_match( + "/^\s*application\/json(;|$)/i", + $this->getContentType() ?? '' + ); } /** diff --git a/var/Typecho/Widget/Request.php b/var/Typecho/Widget/Request.php index 4c1999c6..84da3830 100644 --- a/var/Typecho/Widget/Request.php +++ b/var/Typecho/Widget/Request.php @@ -213,6 +213,16 @@ class Request return $this->request->makeUriByRequest($parameter); } + /** + * 获取请求的内容类型 + * + * @return string|null + */ + public function getContentType(): ?string + { + return $this->request->getContentType(); + } + /** * 获取环境变量 * @@ -317,6 +327,16 @@ class Request return $this->request->isAjax(); } + /** + * 判断是否为json + * + * @return boolean + */ + public function isJson(): bool + { + return $this->request->isJson(); + } + /** * 判断输入是否满足要求 * From e143be0036b91a6ec4bfc5e8d3ad7c19edbfa6e8 Mon Sep 17 00:00:00 2001 From: Losses Don <1384036+Losses@users.noreply.github.com> Date: Fri, 22 Sep 2023 10:54:38 +0800 Subject: [PATCH 4/4] fix: Fix #1597 (#1598) --- admin/custom-fields-js.php | 2 +- admin/custom-fields.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/admin/custom-fields-js.php b/admin/custom-fields-js.php index 3b7205f8..4f27fddc 100644 --- a/admin/custom-fields-js.php +++ b/admin/custom-fields-js.php @@ -30,7 +30,7 @@ $(document).ready(function () { }); $('#custom-field button.operate-add').click(function () { - var html = '<tr><td><input type="text" name="fieldNames[]" placeholder="<?php _e('字段名称'); ?>" class="text-s w-100"></td>' + var html = '<tr><td><input type="text" name="fieldNames[]" placeholder="<?php _e('字段名称'); ?>" pattern="^[_a-zA-Z][_a-zA-Z0-9]*$" oninput="this.reportValidity()" class="text-s w-100"></td>' + '<td><select name="fieldTypes[]" id="">' + '<option value="str"><?php _e('字符'); ?></option>' + '<option value="int"><?php _e('整数'); ?></option>' diff --git a/admin/custom-fields.php b/admin/custom-fields.php index 8e94b0bd..fbedd7b9 100644 --- a/admin/custom-fields.php +++ b/admin/custom-fields.php @@ -26,7 +26,7 @@ $defaultFields = isset($post) ? $post->getDefaultFieldItems() : $page->getDefaul <td> <label for="fieldname" class="sr-only"><?php _e('字段名称'); ?></label> <input type="text" name="fieldNames[]" value="<?php echo htmlspecialchars($field['name']); ?>" - id="fieldname" class="text-s w-100"> + id="fieldname" pattern="^[_a-zA-Z][_a-zA-Z0-9]*$" oninput="this.reportValidity()" class="text-s w-100"> </td> <td> <label for="fieldtype" class="sr-only"><?php _e('字段类型'); ?></label> @@ -56,7 +56,7 @@ $defaultFields = isset($post) ? $post->getDefaultFieldItems() : $page->getDefaul <td> <label for="fieldname" class="sr-only"><?php _e('字段名称'); ?></label> <input type="text" name="fieldNames[]" placeholder="<?php _e('字段名称'); ?>" id="fieldname" - class="text-s w-100"> + class="text-s w-100" pattern="^[_a-zA-Z][_a-zA-Z0-9]*$" oninput="this.reportValidity()"> </td> <td> <label for="fieldtype" class="sr-only"><?php _e('字段类型'); ?></label>