From dd4bf889de4e67578bb5d2317daee654220cfb25 Mon Sep 17 00:00:00 2001 From: joyqi Date: Thu, 4 Nov 2021 16:37:29 +0800 Subject: [PATCH] fix #1222 --- var/Typecho/Request.php | 14 +++++++++++--- var/Widget/Contents/Attachment/Edit.php | 7 ++----- var/Widget/Contents/Page/Edit.php | 2 +- var/Widget/Contents/Post/Edit.php | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/var/Typecho/Request.php b/var/Typecho/Request.php index 6846033a..e93eaeb1 100644 --- a/var/Typecho/Request.php +++ b/var/Typecho/Request.php @@ -165,7 +165,11 @@ class Request $this->params = null; } - return $value ?? $default; + if (isset($value)) { + return is_array($default) == is_array($value) ? $value : $default; + } else { + return $default; + } } /** @@ -199,9 +203,13 @@ class Request */ public function getArray($key): array { - $result = $this->get($key, []); + $result = $this->get($key, [], $exists); - return is_array($result) ? $result : [$result]; + if (!empty($result) || !$exists) { + return $result; + } + + return [$this->get($key)]; } /** diff --git a/var/Widget/Contents/Attachment/Edit.php b/var/Widget/Contents/Attachment/Edit.php index 668ccbfd..33a556b3 100644 --- a/var/Widget/Contents/Attachment/Edit.php +++ b/var/Widget/Contents/Attachment/Edit.php @@ -37,10 +37,7 @@ class Edit extends PostEdit implements ActionInterface $this->user->pass('contributor'); /** 获取文章内容 */ - if ( - (isset($this->request->cid) && 'delete' != $this->request->do - && 'clear' != $this->request->do) || 'update' == $this->request->do - ) { + if (!empty($this->request->cid)) { $this->db->fetchRow($this->select() ->where('table.contents.type = ?', 'attachment') ->where('table.contents.cid = ?', $this->request->filter('int')->cid) @@ -344,7 +341,7 @@ class Edit extends PostEdit implements ActionInterface { $this->security->protect(); $this->on($this->request->is('do=delete'))->deleteAttachment(); - $this->on($this->request->is('do=update'))->updateAttachment(); + $this->on($this->have() && $this->request->is('do=update'))->updateAttachment(); $this->on($this->request->is('do=clear'))->clearAttachment(); $this->response->redirect($this->options->adminUrl); } diff --git a/var/Widget/Contents/Page/Edit.php b/var/Widget/Contents/Page/Edit.php index 396c02c6..0373a83c 100644 --- a/var/Widget/Contents/Page/Edit.php +++ b/var/Widget/Contents/Page/Edit.php @@ -47,7 +47,7 @@ class Edit extends PostEdit implements ActionInterface $this->user->pass('editor'); /** 获取文章内容 */ - if (!empty($this->request->cid) && in_array($this->request->do, ['save', 'publish'])) { + if (!empty($this->request->cid)) { $this->db->fetchRow($this->select() ->where('table.contents.type = ? OR table.contents.type = ?', 'page', 'page_draft') ->where('table.contents.cid = ?', $this->request->filter('int')->cid) diff --git a/var/Widget/Contents/Post/Edit.php b/var/Widget/Contents/Post/Edit.php index 463745c0..08e8c731 100644 --- a/var/Widget/Contents/Post/Edit.php +++ b/var/Widget/Contents/Post/Edit.php @@ -45,7 +45,7 @@ class Edit extends Contents implements ActionInterface $this->user->pass('contributor'); /** 获取文章内容 */ - if (!empty($this->request->cid) && in_array($this->request->do, ['save', 'publish'])) { + if (!empty($this->request->cid)) { $this->db->fetchRow($this->select() ->where('table.contents.type = ? OR table.contents.type = ?', 'post', 'post_draft') ->where('table.contents.cid = ?', $this->request->filter('int')->cid)