From 0b021e5e7d88cbb8332501a86fa60d6b35596dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Wed, 9 Feb 2022 11:41:35 +0800 Subject: [PATCH 01/47] Fix broken extends.typecho.org link (#1315) close #857 --- admin/copyright.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/copyright.php b/admin/copyright.php index a938086884..a952ed6d59 100644 --- a/admin/copyright.php +++ b/admin/copyright.php @@ -8,6 +8,6 @@ • - + From 13dc5e87dd1d00b52cb772d4a17cee97791e5336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Tue, 15 Feb 2022 11:10:15 +0800 Subject: [PATCH 02/47] Fix #1322 (#1323) Great work! --- var/Typecho/Config.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/var/Typecho/Config.php b/var/Typecho/Config.php index d0cd705a09..cc1e882948 100644 --- a/var/Typecho/Config.php +++ b/var/Typecho/Config.php @@ -102,6 +102,7 @@ public function rewind(): void * @access public * @return mixed */ + #[\ReturnTypeWillChange] public function current() { return current($this->currentConfig); @@ -124,6 +125,7 @@ public function next(): void * @access public * @return mixed */ + #[\ReturnTypeWillChange] public function key() { return key($this->currentConfig); @@ -222,6 +224,7 @@ public function offsetExists($offset): bool * @param mixed $offset * @return mixed */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->currentConfig[$offset] ?? null; From f34d14280db442e26ff97d52c2949d0872ffe105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Tue, 15 Feb 2022 11:10:47 +0800 Subject: [PATCH 03/47] Fix compatibility with PHP 8.1 (#1324) * Fix compatibility with PHP 8.1 PHP Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in typecho/var/Widget/Archive.php on line 1292 * Fix login * Fix write * Fix manage * Fix PHP Deprecated --- admin/login.php | 4 ++-- admin/manage-comments.php | 2 +- admin/manage-medias.php | 2 +- admin/manage-pages.php | 2 +- admin/manage-users.php | 2 +- admin/write-page.php | 4 ++-- admin/write-post.php | 8 ++++---- var/Typecho/Response.php | 2 +- var/Widget/Archive.php | 2 +- var/Widget/User.php | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/admin/login.php b/admin/login.php index 3c49bd3629..e51d5789d2 100644 --- a/admin/login.php +++ b/admin/login.php @@ -4,7 +4,7 @@ if ($user->hasLogin()) { $response->redirect($options->adminUrl); } -$rememberName = htmlspecialchars(\Typecho\Cookie::get('__typecho_remember_name')); +$rememberName = htmlspecialchars(\Typecho\Cookie::get('__typecho_remember_name', '')); \Typecho\Cookie::delete('__typecho_remember_name'); $bodyClass = 'body-100'; @@ -25,7 +25,7 @@

- +

@@ -43,7 +43,7 @@ class="edit-draft-notice"> + name="text" class="w-100 mono">text ?? ''); ?>

diff --git a/admin/write-post.php b/admin/write-post.php index 896b4b0057..1f9a40a877 100644 --- a/admin/write-post.php +++ b/admin/write-post.php @@ -38,7 +38,7 @@ class="edit-draft-notice">cid, $post->category, $post->year, $post->month, $post->day ], $permalink); } - $input = ''; + $input = ''; ?>

@@ -47,7 +47,7 @@ class="edit-draft-notice"> + name="text" class="w-100 mono">text ?? ''); ?>

@@ -134,7 +134,7 @@ class="i-caret-down"> + value="password"password ?? '') > 0): ?> selected> @@ -142,7 +142,7 @@ class="i-caret-down"> value="waiting"pass('editor', true) || $post->status == 'waiting'): ?> selected>

-

password) == 0): ?> class="hidden"> +

password ?? '') == 0): ?> class="hidden"> response->redirect(defined('__TYPECHO_ADMIN__') ? $this->options->loginUrl . - (0 === strpos($this->request->getReferer(), $this->options->loginUrl) ? '' : + (0 === strpos($this->request->getReferer() ?? '', $this->options->loginUrl) ? '' : '?referer=' . urlencode($this->request->makeUriByRequest())) : $this->options->siteUrl, false); } } From b0d78a81dc67368709911cc461589abcd608f7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Mon, 21 Feb 2022 21:51:13 +0800 Subject: [PATCH 04/47] Fix #1326 (#1327) --- var/Typecho/Validate.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/var/Typecho/Validate.php b/var/Typecho/Validate.php index fbf753439a..ec89f89a9e 100644 --- a/var/Typecho/Validate.php +++ b/var/Typecho/Validate.php @@ -271,12 +271,12 @@ public function run(array $data, array $rules = null): array foreach ($rules as $key => $rule) { $this->key = $key; $data[$key] = (is_array($data[$key]) ? 0 == count($data[$key]) - : 0 == strlen($data[$key])) ? null : $data[$key]; + : 0 == strlen($data[$key] ?? '')) ? null : $data[$key]; foreach ($rule as $params) { $method = $params[0]; - if ('required' != $method && 'confirm' != $method && 0 == strlen($data[$key])) { + if ('required' != $method && 'confirm' != $method && 0 == strlen($data[$key] ?? '')) { continue; } @@ -319,11 +319,9 @@ public function confirm(?string $str, string $key): bool * * @access public * - * @param string|null $str 待处理的字符串 - * * @return boolean */ - public function required(?string $str): bool + public function required(): bool { return !empty($this->data[$this->key]); } From b23277267a639523b017b65bd841e21dbf294c90 Mon Sep 17 00:00:00 2001 From: joyqi Date: Thu, 24 Feb 2022 23:21:35 +0800 Subject: [PATCH 05/47] fix #1328 --- var/Typecho/Widget.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/var/Typecho/Widget.php b/var/Typecho/Widget.php index 883dda86bb..e2665ead78 100644 --- a/var/Typecho/Widget.php +++ b/var/Typecho/Widget.php @@ -190,19 +190,24 @@ public static function alloc($params = null, $request = null, $disableSandboxOrC /** * alloc widget instance with alias * - * @param string $alias + * @param string|null $alias * @param mixed $params * @param mixed $request * @param bool|callable $disableSandboxOrCallback * @return $this */ public static function allocWithAlias( - string $alias, + ?string $alias, $params = null, $request = null, $disableSandboxOrCallback = true ): Widget { - return self::widget(static::class . '@' . $alias, $params, $request, $disableSandboxOrCallback); + return self::widget( + static::class . (isset($alias) ? '@' . $alias : ''), + $params, + $request, + $disableSandboxOrCallback + ); } /** From 5f943d48b5cad36cad6fc8d7554417291fced56c Mon Sep 17 00:00:00 2001 From: joyqi Date: Fri, 25 Feb 2022 21:16:12 +0800 Subject: [PATCH 06/47] fix #1329 --- var/Widget/Comments/Edit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/var/Widget/Comments/Edit.php b/var/Widget/Comments/Edit.php index d4a7f39e48..a21fb9506a 100644 --- a/var/Widget/Comments/Edit.php +++ b/var/Widget/Comments/Edit.php @@ -275,7 +275,7 @@ public function editComment(): bool } /** 评论插件接口 */ - self::pluginHandle()->edit($comment, $this); + $comment = self::pluginHandle()->edit($comment, $this); /** 更新评论 */ $this->update($comment, $this->db->sql()->where('coid = ?', $coid)); From 17fcb2f08b5dd1efe84877143c901c741ba2e938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Tue, 15 Mar 2022 16:09:32 +0800 Subject: [PATCH 07/47] Fix undefined Typecho\Db\Adapter_Exception (#1334) --- install.php | 2 +- var/Typecho/Request.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/install.php b/install.php index 0a257eb7a0..137836764b 100644 --- a/install.php +++ b/install.php @@ -1051,7 +1051,7 @@ function install_step_2_perform() $installDb = new \Typecho\Db($config['dbAdapter'], $config['dbPrefix']); $installDb->addServer($dbConfig, \Typecho\Db::READ | \Typecho\Db::WRITE); $installDb->query('SELECT 1=1'); - } catch (\Typecho\Db\Adapter_Exception $e) { + } catch (\Typecho\Db\Adapter\ConnectionException $e) { install_raise_error(_t('对不起, 无法连接数据库, 请先检查数据库配置再继续进行安装')); } catch (\Typecho\Db\Exception $e) { install_raise_error(_t('安装程序捕捉到以下错误: " %s ". 程序被终止, 请检查您的配置信息.', $e->getMessage())); diff --git a/var/Typecho/Request.php b/var/Typecho/Request.php index 5e28e2de38..2fddd265b9 100644 --- a/var/Typecho/Request.php +++ b/var/Typecho/Request.php @@ -305,7 +305,7 @@ public function getPathInfo(): ?string return $this->pathInfo; } - //参考Zend Framework对pahtinfo的处理, 更好的兼容性 + //参考Zend Framework对pathinfo的处理, 更好的兼容性 $pathInfo = null; //处理requestUri From 0edb48fae0cc5b9feb686c7367974190074be334 Mon Sep 17 00:00:00 2001 From: joyqi Date: Wed, 16 Mar 2022 21:05:22 +0800 Subject: [PATCH 08/47] fix #1335, close #1337 --- var/Widget/Archive.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/var/Widget/Archive.php b/var/Widget/Archive.php index 1bd3b5ea62..6f70b23e93 100644 --- a/var/Widget/Archive.php +++ b/var/Widget/Archive.php @@ -1498,7 +1498,7 @@ public function feed() 'date' => $this->created, 'link' => $this->permalink, 'author' => $this->author, - 'excerpt' => $this->description, + 'excerpt' => $this->___description(), 'comments' => $this->commentsNum, 'commentsFeedUrl' => $feedUrl, 'suffix' => $suffix From 1b673e06ff459e3894b77bc1b63d7c2dae678f90 Mon Sep 17 00:00:00 2001 From: joyqi Date: Tue, 22 Mar 2022 14:24:14 +0800 Subject: [PATCH 09/47] fix typecho/Dockerfile#9 --- install.php | 7 +++++++ var/Typecho/Validate.php | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/install.php b/install.php index 137836764b..7962af11cb 100644 --- a/install.php +++ b/install.php @@ -1021,6 +1021,9 @@ function install_step_2_perform() case 'SQLite': $error = (new \Typecho\Validate()) ->addRule('dbFile', 'required', _t('确认您的配置')) + ->addRule('dbFile', function (string $path) { + return !!preg_match("/^(\/[_a-z0-9-]+)*[a-z0-9]+\.[a-z0-9]{2,}$/i", $path); + }, _t('确认您的配置')) ->run($config); break; default: @@ -1041,6 +1044,10 @@ function install_step_2_perform() $dbConfig['port'] = intval($dbConfig['port']); } + if (isset($dbConfig['file']) && preg_match("/^[a-z0-9]+\.[a-z0-9]{2,}$/i", $dbConfig['file'])) { + $dbConfig['file'] = __DIR__ . '/usr/' . $dbConfig['file']; + } + // check config file if ($config['dbNext'] == 'config' && !install_check('config')) { $code = install_config_file($config['dbAdapter'], $config['dbPrefix'], $dbConfig, true); diff --git a/var/Typecho/Validate.php b/var/Typecho/Validate.php index ec89f89a9e..4e37117289 100644 --- a/var/Typecho/Validate.php +++ b/var/Typecho/Validate.php @@ -221,7 +221,7 @@ public static function isInteger($str): bool * @access public * * @param string $key 数值键值 - * @param string|array $rule 规则名称 + * @param string|callable $rule 规则名称 * @param string $message 错误字符串 * * @return $this @@ -284,7 +284,7 @@ public function run(array $data, array $rules = null): array $params[1] = $data[$key]; $params = array_slice($params, 1); - if (!call_user_func_array(is_array($method) ? $method : [$this, $method], $params)) { + if (!call_user_func_array(is_callable($method) ? $method : [$this, $method], $params)) { $result[$key] = $message; break; } From ce7af58367cc809ffaa38e23b37a79ccb69c0df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Thu, 24 Mar 2022 17:46:03 +0800 Subject: [PATCH 10/47] Optimize code (#1342) --- install.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/install.php b/install.php index 7962af11cb..3b193996f9 100644 --- a/install.php +++ b/install.php @@ -1061,7 +1061,7 @@ function install_step_2_perform() } catch (\Typecho\Db\Adapter\ConnectionException $e) { install_raise_error(_t('对不起, 无法连接数据库, 请先检查数据库配置再继续进行安装')); } catch (\Typecho\Db\Exception $e) { - install_raise_error(_t('安装程序捕捉到以下错误: " %s ". 程序被终止, 请检查您的配置信息.', $e->getMessage())); + install_raise_error(_t('安装程序捕捉到以下错误: "%s". 程序被终止, 请检查您的配置信息.', $e->getMessage())); } $code = install_config_file($config['dbAdapter'], $config['dbPrefix'], $dbConfig); @@ -1091,12 +1091,14 @@ function install_step_2_perform() try { foreach ($tables as $table) { - if ($type == 'Mysql') { - $installDb->query("DROP TABLE IF EXISTS `{$table}`"); - } elseif ($type == 'Pgsql') { - $installDb->query("DROP TABLE {$table}"); - } elseif ($type == 'SQLite') { - $installDb->query("DROP TABLE {$table}"); + switch ($type) { + case 'Mysql': + $installDb->query("DROP TABLE IF EXISTS `{$table}`"); + break; + case 'Pgsql': + case 'SQLite': + $installDb->query("DROP TABLE {$table}"); + break; } } } catch (\Typecho\Db\Exception $e) { From 0bdf8721e136d2068311aef3c503f2088d4fec5c Mon Sep 17 00:00:00 2001 From: fen Date: Fri, 25 Mar 2022 12:08:22 +0800 Subject: [PATCH 11/47] add ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6b68ac9e7f..470b0e2c7d 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ *.sublime* .sass-cache config.rb +prepros.config /config.inc.php /usr/uploads/ /usr/*.db From 6100695d87eb3c9336e1074d30fd900a88aafb7c Mon Sep 17 00:00:00 2001 From: joyqi Date: Fri, 25 Mar 2022 15:31:57 +0800 Subject: [PATCH 12/47] fix db exception --- var/Typecho/Common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/var/Typecho/Common.php b/var/Typecho/Common.php index 27cf3e6888..07557dca3b 100644 --- a/var/Typecho/Common.php +++ b/var/Typecho/Common.php @@ -230,10 +230,10 @@ public static function error(\Throwable $exception) //覆盖原始错误信息 $message = 'Database Server Error'; - if ($exception instanceof \Typecho\Db\Adapter\SQLException) { + if ($exception instanceof \Typecho\Db\Adapter\ConnectionException) { $code = 503; $message = 'Error establishing a database connection'; - } elseif ($exception instanceof \Typecho\Db\Query\Exception) { + } elseif ($exception instanceof \Typecho\Db\Adapter\SQLException) { $message = 'Database Query Error'; } } From 4be93f27415404caf7fd7bbaafd84a9293cd017c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Mon, 28 Mar 2022 12:11:24 +0800 Subject: [PATCH 13/47] Fix missing mysqli_connect_errno (#1346) --- var/Typecho/Db/Adapter/Mysqli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/var/Typecho/Db/Adapter/Mysqli.php b/var/Typecho/Db/Adapter/Mysqli.php index eee61fc30e..5f417a3cbb 100644 --- a/var/Typecho/Db/Adapter/Mysqli.php +++ b/var/Typecho/Db/Adapter/Mysqli.php @@ -64,7 +64,7 @@ public function connect(Config $config): \mysqli } /** 数据库异常 */ - throw new ConnectionException("Couldn't connect to database."); + throw new ConnectionException("Couldn't connect to database.", mysqli_connect_errno()); } /** From 2f3e15dfb84b4ca65cef82dd3148e859b3c16e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Fri, 1 Apr 2022 11:12:54 +0800 Subject: [PATCH 14/47] Fix checkVersion (#1356) --- var/Widget/Ajax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/var/Widget/Ajax.php b/var/Widget/Ajax.php index 01a774b73f..1b3b1d6ab4 100644 --- a/var/Widget/Ajax.php +++ b/var/Widget/Ajax.php @@ -59,7 +59,7 @@ public function checkVersion() if ( isset($json['release']) && preg_match("/^[0-9\.]+$/", $json['release']) - && version_compare($json['release'], $version, '>=') + && version_compare($json['release'], $version, '>') ) { $result = [ 'available' => 1, From 2db893e80223593535be5f6ef574c8a41d57d04d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AF=9B=E7=BA=BF?= <13816653+maoxian-1@users.noreply.github.com> Date: Fri, 1 Apr 2022 14:07:08 +0800 Subject: [PATCH 15/47] Update install.php (#1357) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复宝塔面板的网站目录带.导致db路径校验不通过的问题 --- install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.php b/install.php index 3b193996f9..7b3b5e4650 100644 --- a/install.php +++ b/install.php @@ -1022,7 +1022,7 @@ function install_step_2_perform() $error = (new \Typecho\Validate()) ->addRule('dbFile', 'required', _t('确认您的配置')) ->addRule('dbFile', function (string $path) { - return !!preg_match("/^(\/[_a-z0-9-]+)*[a-z0-9]+\.[a-z0-9]{2,}$/i", $path); + return !!preg_match("/^(\/[._a-z0-9-]+)*[a-z0-9]+\.[a-z0-9]{2,}$/i", $path); }, _t('确认您的配置')) ->run($config); break; From c30b67d18d70c16de91f4cff7be0a353b3a416cc Mon Sep 17 00:00:00 2001 From: joyqi Date: Fri, 1 Apr 2022 15:25:10 +0800 Subject: [PATCH 16/47] Update .gitignore update gitignore --- .gitignore | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 470b0e2c7d..94fcdb9509 100644 --- a/.gitignore +++ b/.gitignore @@ -25,12 +25,13 @@ .sass-cache config.rb prepros.config -/config.inc.php -/usr/uploads/ -/usr/*.db -/usr/plugins/ -!/usr/plugins/HelloWorld -/usr/themes/ -!/usr/themes/default +config.inc.* +usr/uploads/ +usr/*.db +usr/plugins/ +!usr/plugins/HelloWorld +usr/themes/* +!usr/themes/default +!usr/themes/classic-22 node_modules/ /tools/tmp/ From ded268ef592deae2539e58e024776c6eafadf7b2 Mon Sep 17 00:00:00 2001 From: joyqi Date: Fri, 1 Apr 2022 16:50:23 +0800 Subject: [PATCH 17/47] Pr/1344 (#1360) * Add missing theme action * Fix typo * Optimize code * Optimize code * Update themes.php * Simpler missing theme judgement Co-authored-by: sy-records <52o@qq52o.cn> --- admin/themes.php | 19 +++++++++++++++---- config.inc.sqlite.php | 27 +++++++++++++++++++++++++++ var/Widget/Options.php | 8 +++++++- var/Widget/Themes/Config.php | 2 +- var/Widget/Themes/Edit.php | 5 +++-- var/Widget/Themes/Files.php | 13 ++++++++++++- 6 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 config.inc.sqlite.php diff --git a/admin/themes.php b/admin/themes.php index 0358e67b2f..2a3a66011b 100644 --- a/admin/themes.php +++ b/admin/themes.php @@ -12,7 +12,7 @@