From 4c8c64c79ef9faf5a8423d653faef3126d274c81 Mon Sep 17 00:00:00 2001 From: joyqi Date: Sun, 24 Sep 2023 16:21:32 +0800 Subject: [PATCH] Feat/code refactor (#1626) * remove all magic methods, add type for class properties * refactor codes * fix all * refactor code * fix type * fix all * fix request is method * fix all * fix router * fix get page --- admin/common.php | 2 +- admin/editor-js.php | 2 +- admin/footer.php | 4 +- admin/header.php | 2 +- admin/login.php | 4 +- admin/menu.php | 2 +- admin/profile.php | 2 +- admin/theme-editor.php | 2 +- admin/write-js.php | 2 +- admin/write-page.php | 8 +- admin/write-post.php | 10 +- install.php | 2 +- usr/themes/classic-22/comments.php | 2 +- usr/themes/default/comments.php | 4 +- var/IXR/Base64.php | 2 +- var/IXR/Client.php | 10 +- var/IXR/Date.php | 24 +-- var/IXR/Error.php | 4 +- var/IXR/Message.php | 28 +-- var/IXR/Pingback.php | 6 +- var/IXR/Request.php | 2 +- var/IXR/Server.php | 10 +- var/IXR/Value.php | 6 +- var/Typecho/Common.php | 12 +- var/Typecho/Config.php | 2 +- var/Typecho/Cookie.php | 21 ++- var/Typecho/Date.php | 14 +- var/Typecho/Db.php | 12 +- var/Typecho/Db/Adapter/Mysqli.php | 2 +- var/Typecho/Db/Adapter/Pdo.php | 4 +- var/Typecho/Db/Adapter/PgsqlTrait.php | 6 +- var/Typecho/Db/Adapter/SQLiteTrait.php | 2 +- var/Typecho/Db/Query.php | 11 +- var/Typecho/Feed.php | 20 +- var/Typecho/Http/Client.php | 24 +-- var/Typecho/I18n.php | 8 +- var/Typecho/I18n/GetTextMulti.php | 10 +- var/Typecho/Plugin.php | 29 ++- var/Typecho/Request.php | 64 ++++--- var/Typecho/Response.php | 24 +-- var/Typecho/Router.php | 107 +++++------ var/Typecho/Router/Parser.php | 6 +- var/Typecho/Validate.php | 10 +- var/Typecho/Widget.php | 22 +-- var/Typecho/Widget/Helper/EmptyClass.php | 2 +- var/Typecho/Widget/Helper/Form.php | 2 +- var/Typecho/Widget/Helper/Form/Element.php | 26 +-- .../Widget/Helper/Form/Element/Checkbox.php | 2 +- .../Widget/Helper/Form/Element/Radio.php | 2 +- .../Widget/Helper/Form/Element/Select.php | 2 +- var/Typecho/Widget/Helper/Layout.php | 14 +- var/Typecho/Widget/Helper/PageNavigator.php | 12 +- var/Typecho/Widget/Request.php | 33 ++-- var/Typecho/Widget/Response.php | 4 +- var/Utils/AutoP.php | 4 +- var/Utils/Helper.php | 4 +- var/Utils/PasswordHash.php | 8 +- var/Utils/Upgrade.php | 2 + var/Widget/Action.php | 4 +- var/Widget/Ajax.php | 10 +- var/Widget/Archive.php | 173 ++++++++---------- var/Widget/Backup.php | 12 +- var/Widget/Base.php | 8 +- var/Widget/Base/Comments.php | 14 +- var/Widget/Base/Contents.php | 26 ++- var/Widget/Base/Metas.php | 6 +- var/Widget/Base/Users.php | 15 +- var/Widget/CommentPage.php | 2 +- var/Widget/Comments/Admin.php | 30 +-- var/Widget/Comments/Archive.php | 32 ++-- var/Widget/Comments/Edit.php | 40 ++-- var/Widget/Comments/Ping.php | 7 +- var/Widget/Contents/Attachment/Admin.php | 12 +- var/Widget/Contents/Attachment/Edit.php | 22 +-- var/Widget/Contents/Attachment/Related.php | 2 +- var/Widget/Contents/Attachment/Unattached.php | 2 +- var/Widget/Contents/Page/Admin.php | 4 +- var/Widget/Contents/Page/Edit.php | 22 +-- var/Widget/Contents/Page/Rows.php | 2 +- var/Widget/Contents/Post/Admin.php | 30 +-- var/Widget/Contents/Post/Edit.php | 124 ++++++------- var/Widget/Feed.php | 12 +- var/Widget/Feedback.php | 32 ++-- var/Widget/Login.php | 32 ++-- var/Widget/Logout.php | 2 +- var/Widget/Menu.php | 14 +- var/Widget/Metas/Category/Admin.php | 16 +- var/Widget/Metas/Category/Edit.php | 28 +-- var/Widget/Metas/Category/Rows.php | 20 +- var/Widget/Metas/Tag/Admin.php | 4 +- var/Widget/Metas/Tag/Edit.php | 26 +-- var/Widget/Notice.php | 2 +- var/Widget/Options.php | 11 +- var/Widget/Options/Discussion.php | 10 +- var/Widget/Options/General.php | 4 +- var/Widget/Options/Permalink.php | 31 ++-- var/Widget/Options/Reading.php | 10 +- var/Widget/Plugins/Config.php | 12 +- var/Widget/Plugins/Edit.php | 12 +- var/Widget/Plugins/Rows.php | 6 +- var/Widget/Register.php | 16 +- var/Widget/Security.php | 4 +- var/Widget/Service.php | 6 +- var/Widget/Stat.php | 14 +- var/Widget/Themes/Edit.php | 8 +- var/Widget/Themes/Files.php | 8 +- var/Widget/Themes/Rows.php | 3 +- var/Widget/Upload.php | 30 +-- var/Widget/User.php | 24 +-- var/Widget/Users/Admin.php | 10 +- var/Widget/Users/Edit.php | 14 +- var/Widget/Users/Profile.php | 16 +- var/Widget/XmlRpc.php | 28 +-- 113 files changed, 871 insertions(+), 860 deletions(-) diff --git a/admin/common.php b/admin/common.php index df44d313..e210a1fd 100644 --- a/admin/common.php +++ b/admin/common.php @@ -15,7 +15,7 @@ if (!defined('__TYPECHO_ROOT_DIR__') && !@include_once __DIR__ . '/../config.inc \Widget\Init::alloc(); /** 注册一个初始化插件 */ -\Typecho\Plugin::factory('admin/common.php')->begin(); +\Typecho\Plugin::factory('admin/common.php')->call('begin'); \Widget\Options::alloc()->to($options); \Widget\User::alloc()->to($user); diff --git a/admin/editor-js.php b/admin/editor-js.php index db2586ff..0fd25de3 100644 --- a/admin/editor-js.php +++ b/admin/editor-js.php @@ -109,7 +109,7 @@ $(document).ready(function () { } }); - markdownEditor($content); ?> + call('markdownEditor', $content); ?> var th = textarea.height(), ph = preview.height(), uploadBtn = $(' diff --git a/admin/menu.php b/admin/menu.php index 177dc19e..92212e73 100644 --- a/admin/menu.php +++ b/admin/menu.php @@ -5,7 +5,7 @@ output(); ?>
- navBar(); ?>logged > 0) { $logged = new \Typecho\Date($user->logged); _e('最后登录: %s', $logged->word()); diff --git a/admin/profile.php b/admin/profile.php index 5c49ed69..4428cece 100644 --- a/admin/profile.php +++ b/admin/profile.php @@ -57,6 +57,6 @@ $stat = \Widget\Stat::alloc(); include 'copyright.php'; include 'common-js.php'; include 'form-js.php'; -\Typecho\Plugin::factory('admin/profile.php')->bottom(); +\Typecho\Plugin::factory('admin/profile.php')->call('bottom'); include 'footer.php'; ?> diff --git a/admin/theme-editor.php b/admin/theme-editor.php index 7f1fad88..e214e17a 100644 --- a/admin/theme-editor.php +++ b/admin/theme-editor.php @@ -60,6 +60,6 @@ include 'menu.php'; bottom($files); +\Typecho\Plugin::factory('admin/theme-editor.php')->call('bottom', $files); include 'footer.php'; ?> diff --git a/admin/write-js.php b/admin/write-js.php index de6e7071..8c69f0e4 100644 --- a/admin/write-js.php +++ b/admin/write-js.php @@ -1,5 +1,5 @@ -write(); ?> +call('write'); ?> to($tags); ?> diff --git a/admin/write-page.php b/admin/write-page.php index 4ab81db7..89ad10ed 100644 --- a/admin/write-page.php +++ b/admin/write-page.php @@ -66,7 +66,7 @@ include 'menu.php';

- content($page); ?> + call('content', $page); ?>
have()): ?> modified); ?> @@ -167,7 +167,7 @@ include 'common-js.php'; include 'form-js.php'; include 'write-js.php'; -\Typecho\Plugin::factory('admin/write-page.php')->trigger($plugged)->richEditor($page); +\Typecho\Plugin::factory('admin/write-page.php')->trigger($plugged)->call('richEditor', $page); if (!$plugged) { include 'editor-js.php'; } diff --git a/admin/write-post.php b/admin/write-post.php index 1f9a40a8..41e972b3 100644 --- a/admin/write-post.php +++ b/admin/write-post.php @@ -71,7 +71,7 @@ include 'menu.php';

- content($post); ?> + call('content', $post); ?> have()): ?> @@ -204,13 +204,13 @@ include 'common-js.php'; include 'form-js.php'; include 'write-js.php'; -\Typecho\Plugin::factory('admin/write-post.php')->trigger($plugged)->richEditor($post); +\Typecho\Plugin::factory('admin/write-post.php')->trigger($plugged)->call('richEditor', $post); if (!$plugged) { include 'editor-js.php'; } include 'file-upload-js.php'; include 'custom-fields-js.php'; -\Typecho\Plugin::factory('admin/write-post.php')->bottom($post); +\Typecho\Plugin::factory('admin/write-post.php')->call('bottom', $post); include 'footer.php'; ?> diff --git a/install.php b/install.php index fdc7a05c..857785bd 100644 --- a/install.php +++ b/install.php @@ -256,7 +256,7 @@ function install_get_default_options(): array 'frontArchive' => 0, 'commentsRequireMail' => 1, 'commentsWhitelist' => 0, - 'commentsRequireURL' => 0, + 'commentsRequireUrl' => 0, 'commentsRequireModeration' => 0, 'plugins' => 'a:0:{}', 'commentDateFormat' => 'F jS, Y \a\t h:i a', diff --git a/usr/themes/classic-22/comments.php b/usr/themes/classic-22/comments.php index 6e134221..a80893f8 100644 --- a/usr/themes/classic-22/comments.php +++ b/usr/themes/classic-22/comments.php @@ -32,7 +32,7 @@
options->commentsRequireMail): ?> required /> - options->commentsRequireURL): ?> required /> + options->commentsRequireUrl): ?> required />
diff --git a/usr/themes/default/comments.php b/usr/themes/default/comments.php index efaa6113..8800e3d2 100644 --- a/usr/themes/default/comments.php +++ b/usr/themes/default/comments.php @@ -37,9 +37,9 @@

+ for="url"options->commentsRequireUrl): ?> class="required"> options->commentsRequireURL): ?> required /> + value="remember('url'); ?>"options->commentsRequireUrl): ?> required />

diff --git a/var/IXR/Base64.php b/var/IXR/Base64.php index d009ebef..debe0bff 100644 --- a/var/IXR/Base64.php +++ b/var/IXR/Base64.php @@ -14,7 +14,7 @@ class Base64 * * @var string */ - private $data; + private string $data; /** * 初始化数据 diff --git a/var/IXR/Client.php b/var/IXR/Client.php index 0c8d2e19..d73d43a5 100644 --- a/var/IXR/Client.php +++ b/var/IXR/Client.php @@ -20,33 +20,33 @@ class Client * * @var string */ - private $url; + private string $url; /** * 消息体 * * @var Message */ - private $message; + private Message $message; /** * 调试开关 * * @var boolean */ - private $debug = false; + private bool $debug = false; /** * 请求前缀 * * @var string|null */ - private $prefix; + private ?string $prefix; /** * @var Error */ - private $error; + private Error $error; /** * 客户端构造函数 diff --git a/var/IXR/Date.php b/var/IXR/Date.php index f057f3de..d4be8d2c 100644 --- a/var/IXR/Date.php +++ b/var/IXR/Date.php @@ -9,17 +9,17 @@ namespace IXR; */ class Date { - private $year; + private int $year; - private $month; + private int $month; - private $day; + private int $day; - private $hour; + private int $hour; - private $minute; + private int $minute; - private $second; + private int $second; /** * @param int|string $time @@ -39,12 +39,12 @@ class Date */ private function parseTimestamp(int $timestamp) { - $this->year = date('Y', $timestamp); - $this->month = date('m', $timestamp); - $this->day = date('d', $timestamp); - $this->hour = date('H', $timestamp); - $this->minute = date('i', $timestamp); - $this->second = date('s', $timestamp); + $this->year = intval(date('Y', $timestamp)); + $this->month = intval(date('m', $timestamp)); + $this->day = intval(date('d', $timestamp)); + $this->hour = intval(date('H', $timestamp)); + $this->minute = intval(date('i', $timestamp)); + $this->second = intval(date('s', $timestamp)); } /** diff --git a/var/IXR/Error.php b/var/IXR/Error.php index 2ad17d5a..564620aa 100644 --- a/var/IXR/Error.php +++ b/var/IXR/Error.php @@ -15,7 +15,7 @@ class Error * @access public * @var integer */ - public $code; + public int $code; /** * 错误消息 @@ -23,7 +23,7 @@ class Error * @access public * @var string|null */ - public $message; + public ?string $message; /** * 构造函数 diff --git a/var/IXR/Message.php b/var/IXR/Message.php index 29ace229..4bb8f6ec 100644 --- a/var/IXR/Message.php +++ b/var/IXR/Message.php @@ -12,35 +12,35 @@ class Message /** * @var string */ - public $message; + public string $message; /** * @var string */ - public $messageType; // methodCall / methodResponse / fault + public string $messageType; // methodCall / methodResponse / fault - public $faultCode; + public int $faultCode; - public $faultString; + public string $faultString; /** * @var string */ - public $methodName; + public string $methodName; /** * @var array */ - public $params = []; + public array $params = []; // Current variable stacks - private $arrayStructs = []; // The stack used to keep track of the current array/struct + private array $arrayStructs = []; // The stack used to keep track of the current array/struct - private $arrayStructsTypes = []; // Stack keeping track of if things are structs or array + private array $arrayStructsTypes = []; // Stack keeping track of if things are structs or array - private $currentStructName = []; // A stack as well + private array $currentStructName = []; // A stack as well - private $currentTagContents; + private string $currentTagContents; /** * @param string $message @@ -76,7 +76,7 @@ class Message xml_parser_free($parser); // Grab the error messages, if any if ($this->messageType == 'fault') { - $this->faultCode = $this->params[0]['faultCode']; + $this->faultCode = intval($this->params[0]['faultCode']); $this->faultString = $this->params[0]['faultString']; } return true; @@ -84,7 +84,7 @@ class Message /** * @param $parser - * @param $tag + * @param string $tag * @param $attr */ private function tagOpen($parser, string $tag, $attr) @@ -133,7 +133,7 @@ class Message $this->currentTagContents = ''; break; case 'string': - $value = (string)trim($this->currentTagContents); + $value = trim($this->currentTagContents); $this->currentTagContents = ''; break; case 'dateTime.iso8601': @@ -144,7 +144,7 @@ class Message case 'value': // "If no type is indicated, the type is string." if (trim($this->currentTagContents) != '') { - $value = (string) $this->currentTagContents; + $value = $this->currentTagContents; $this->currentTagContents = ''; } break; diff --git a/var/IXR/Pingback.php b/var/IXR/Pingback.php index 07d774d5..287373f5 100644 --- a/var/IXR/Pingback.php +++ b/var/IXR/Pingback.php @@ -14,12 +14,12 @@ class Pingback /** * @var string */ - private $html; + private string $html; /** * @var string */ - private $target; + private string $target; /** * @param string $url @@ -73,7 +73,7 @@ class Pingback */ public function getTitle(): string { - if (preg_match("/\([^<]*?)\<\/title\\>/is", $this->html, $matchTitle)) { + if (preg_match("/([^<]*?)<\/title>/is", $this->html, $matchTitle)) { return Common::subStr(Common::removeXSS(trim(strip_tags($matchTitle[1]))), 0, 150, '...'); } diff --git a/var/IXR/Request.php b/var/IXR/Request.php index 4ef77845..e0c42095 100644 --- a/var/IXR/Request.php +++ b/var/IXR/Request.php @@ -12,7 +12,7 @@ class Request /** * @var string */ - private $xml; + private string $xml; /** * @param string $method diff --git a/var/IXR/Server.php b/var/IXR/Server.php index d613a37c..c3f6969d 100644 --- a/var/IXR/Server.php +++ b/var/IXR/Server.php @@ -16,19 +16,19 @@ class Server * * @var array */ - private $callbacks; + private array $callbacks; /** * 默认参数 * * @var array */ - private $capabilities; + private array $capabilities; /** * @var Hook */ - private $hook; + private Hook $hook; /** * 构造函数 @@ -248,9 +248,9 @@ class Server * * @access private * @param string $method 方法名 - * @return mixed + * @return bool */ - private function hasMethod(string $method) + private function hasMethod(string $method): bool { return in_array($method, array_keys($this->callbacks)); } diff --git a/var/IXR/Value.php b/var/IXR/Value.php index bda6d294..bb59bbd2 100644 --- a/var/IXR/Value.php +++ b/var/IXR/Value.php @@ -11,13 +11,13 @@ class Value { private $data; - private $type; + private ?string $type; /** * @param mixed $data - * @param bool|string $type + * @param string|null $type */ - public function __construct($data, $type = false) + public function __construct($data, ?string $type) { $this->data = $data; if (!$type) { diff --git a/var/Typecho/Common.php b/var/Typecho/Common.php index 7bdb18cc..593791ea 100644 --- a/var/Typecho/Common.php +++ b/var/Typecho/Common.php @@ -378,8 +378,8 @@ EOF; } //非自闭合html标签列表 - preg_match_all("/<([_0-9a-zA-Z-\:]+)\s*([^>]*)>/is", $string, $startTags); - preg_match_all("/<\/([_0-9a-zA-Z-\:]+)>/is", $string, $closeTags); + preg_match_all("/<([_0-9a-zA-Z-:]+)\s*([^>]*)>/is", $string, $startTags); + preg_match_all("/<\/([_0-9a-zA-Z-:]+)>/is", $string, $closeTags); if (!empty($startTags[1]) && is_array($startTags[1])) { krsort($startTags[1]); @@ -410,7 +410,7 @@ EOF; } } - return preg_replace("/\<br\s*\/\>\s*\<\/p\>/is", '</p>', $string); + return preg_replace("/<br\s*\/>\s*<\/p>/is", '</p>', $string); } /** @@ -432,7 +432,7 @@ EOF; $normalizeTags = ''; $allowableAttributes = []; - if (!empty($allowableTags) && preg_match_all("/\<([_a-z0-9-]+)([^>]*)\>/is", $allowableTags, $tags)) { + if (!empty($allowableTags) && preg_match_all("/<([_a-z0-9-]+)([^>]*)>/is", $allowableTags, $tags)) { $normalizeTags = '<' . implode('><', array_map('strtolower', $tags[1])) . '>'; $attributes = array_map('trim', $tags[2]); foreach ($attributes as $key => $val) { @@ -546,8 +546,8 @@ EOF; $params = array_map(function ($string) { $string = str_replace(['%0d', '%0a'], '', strip_tags($string)); return preg_replace([ - "/\(\s*(\"|')/i", //函数开头 - "/(\"|')\s*\)/i", //函数结尾 + "/\(\s*([\"'])/i", //函数开头 + "/([\"'])\s*\)/i", //函数结尾 ], '', $string); }, $params); diff --git a/var/Typecho/Config.php b/var/Typecho/Config.php index cc1e8829..bc56446f 100644 --- a/var/Typecho/Config.php +++ b/var/Typecho/Config.php @@ -18,7 +18,7 @@ class Config implements \Iterator, \ArrayAccess * @access private * @var array */ - private $currentConfig = []; + private array $currentConfig = []; /** * 实例化一个当前配置 diff --git a/var/Typecho/Cookie.php b/var/Typecho/Cookie.php index 90664628..90b4b83a 100644 --- a/var/Typecho/Cookie.php +++ b/var/Typecho/Cookie.php @@ -17,7 +17,7 @@ class Cookie * @var string * @access private */ - private static $prefix = ''; + private static string $prefix = ''; /** * 路径 @@ -25,25 +25,25 @@ class Cookie * @var string * @access private */ - private static $path = '/'; + private static string $path = '/'; /** * @var string * @access private */ - private static $domain = ''; + private static string $domain = ''; /** * @var bool * @access private */ - private static $secure = false; + private static bool $secure = false; /** * @var bool * @access private */ - private static $httponly = false; + private static bool $httponly = false; /** * 获取前缀 @@ -141,7 +141,15 @@ class Cookie { $key = self::$prefix . $key; $_COOKIE[$key] = $value; - Response::getInstance()->setCookie($key, $value, $expire, self::$path, self::$domain, self::$secure, self::$httponly); + Response::getInstance()->setCookie( + $key, + $value, + $expire, + self::$path, + self::$domain, + self::$secure, + self::$httponly + ); } /** @@ -160,4 +168,3 @@ class Cookie unset($_COOKIE[$key]); } } - diff --git a/var/Typecho/Date.php b/var/Typecho/Date.php index e4255d37..fd675e90 100644 --- a/var/Typecho/Date.php +++ b/var/Typecho/Date.php @@ -17,7 +17,7 @@ class Date * @access public * @var integer */ - public static $timezoneOffset = 0; + public static int $timezoneOffset = 0; /** * 服务器时区偏移 @@ -25,7 +25,7 @@ class Date * @access public * @var integer */ - public static $serverTimezoneOffset = 0; + public static int $serverTimezoneOffset = 0; /** * 当前的服务器时间戳 @@ -33,7 +33,7 @@ class Date * @access public * @var integer */ - public static $serverTimeStamp; + public static int $serverTimeStamp = 0; /** * 可以被直接转换的时间戳 @@ -41,22 +41,22 @@ class Date * @access public * @var integer */ - public $timeStamp = 0; + public int $timeStamp = 0; /** * @var string */ - public $year; + public string $year; /** * @var string */ - public $month; + public string $month; /** * @var string */ - public $day; + public string $day; /** * 初始化参数 diff --git a/var/Typecho/Db.php b/var/Typecho/Db.php index 547d9ccb..5e4e5a0c 100644 --- a/var/Typecho/Db.php +++ b/var/Typecho/Db.php @@ -55,14 +55,14 @@ class Db * 数据库适配器 * @var Adapter */ - private $adapter; + private Adapter $adapter; /** * 默认配置 * * @var array */ - private $config; + private array $config; /** * 已经连接 @@ -70,7 +70,7 @@ class Db * @access private * @var array */ - private $connectedPool; + private array $connectedPool; /** * 前缀 @@ -78,7 +78,7 @@ class Db * @access private * @var string */ - private $prefix; + private string $prefix; /** * 适配器名称 @@ -86,13 +86,13 @@ class Db * @access private * @var string */ - private $adapterName; + private string $adapterName; /** * 实例化的数据库对象 * @var Db */ - private static $instance; + private static Db $instance; /** * 数据库类构造函数 diff --git a/var/Typecho/Db/Adapter/Mysqli.php b/var/Typecho/Db/Adapter/Mysqli.php index d40a232d..76467a79 100644 --- a/var/Typecho/Db/Adapter/Mysqli.php +++ b/var/Typecho/Db/Adapter/Mysqli.php @@ -25,7 +25,7 @@ class Mysqli implements Adapter * @access private * @var \mysqli */ - private $dbLink; + private \mysqli $dbLink; /** * 判断适配器是否可用 diff --git a/var/Typecho/Db/Adapter/Pdo.php b/var/Typecho/Db/Adapter/Pdo.php index 3041c55c..5a55aeef 100644 --- a/var/Typecho/Db/Adapter/Pdo.php +++ b/var/Typecho/Db/Adapter/Pdo.php @@ -23,7 +23,7 @@ abstract class Pdo implements Adapter * @access protected * @var \PDO */ - protected $object; + protected \PDO $object; /** * 最后一次操作的数据表 @@ -31,7 +31,7 @@ abstract class Pdo implements Adapter * @access protected * @var string */ - protected $lastTable; + protected string $lastTable; /** * 判断适配器是否可用 diff --git a/var/Typecho/Db/Adapter/PgsqlTrait.php b/var/Typecho/Db/Adapter/PgsqlTrait.php index 21048eba..ba9a88b9 100644 --- a/var/Typecho/Db/Adapter/PgsqlTrait.php +++ b/var/Typecho/Db/Adapter/PgsqlTrait.php @@ -11,17 +11,17 @@ trait PgsqlTrait /** * @var array */ - private $pk = []; + private array $pk = []; /** * @var bool */ - private $compatibleInsert = false; + private bool $compatibleInsert = false; /** * @var string|null */ - private $lastInsertTable = null; + private ?string $lastInsertTable = null; /** * 清空数据表 diff --git a/var/Typecho/Db/Adapter/SQLiteTrait.php b/var/Typecho/Db/Adapter/SQLiteTrait.php index a2e42f90..88f696ae 100644 --- a/var/Typecho/Db/Adapter/SQLiteTrait.php +++ b/var/Typecho/Db/Adapter/SQLiteTrait.php @@ -9,7 +9,7 @@ trait SQLiteTrait { use QueryTrait; - private $isSQLite2 = false; + private bool $isSQLite2 = false; /** * 清空数据表 diff --git a/var/Typecho/Db/Query.php b/var/Typecho/Db/Query.php index b09f7c8c..efd3541c 100644 --- a/var/Typecho/Db/Query.php +++ b/var/Typecho/Db/Query.php @@ -29,7 +29,7 @@ class Query * @var array * @access private */ - private static $default = [ + private static array $default = [ 'action' => null, 'table' => null, 'fields' => '*', @@ -48,14 +48,14 @@ class Query * * @var Adapter */ - private $adapter; + private Adapter $adapter; /** * 查询语句预结构,由数组构成,方便组合为SQL查询字符串 * * @var array */ - private $sqlPreBuild; + private array $sqlPreBuild; /** * 前缀 @@ -63,12 +63,12 @@ class Query * @access private * @var string */ - private $prefix; + private string $prefix; /** * @var array */ - private $params = []; + private array $params = []; /** * 构造函数,引用数据库适配器作为内部数据 @@ -211,7 +211,6 @@ class Query $split .= $cha; $lastIsAlnum = false; } - } return $result; diff --git a/var/Typecho/Feed.php b/var/Typecho/Feed.php index a16789a5..7bd2e2aa 100644 --- a/var/Typecho/Feed.php +++ b/var/Typecho/Feed.php @@ -33,7 +33,7 @@ class Feed * @access private * @var string */ - private $type; + private string $type; /** * 字符集编码 @@ -41,7 +41,7 @@ class Feed * @access private * @var string */ - private $charset; + private string $charset; /** * 语言状态 @@ -49,7 +49,7 @@ class Feed * @access private * @var string */ - private $lang; + private string $lang; /** * 聚合地址 @@ -57,7 +57,7 @@ class Feed * @access private * @var string */ - private $feedUrl; + private string $feedUrl; /** * 基本地址 @@ -65,7 +65,7 @@ class Feed * @access private * @var string */ - private $baseUrl; + private string $baseUrl; /** * 聚合标题 @@ -73,7 +73,7 @@ class Feed * @access private * @var string */ - private $title; + private string $title; /** * 聚合副标题 @@ -81,7 +81,7 @@ class Feed * @access private * @var string */ - private $subTitle; + private string $subTitle; /** * 版本信息 @@ -89,7 +89,7 @@ class Feed * @access private * @var string */ - private $version; + private string $version; /** * 所有的items @@ -97,7 +97,7 @@ class Feed * @access private * @var array */ - private $items = []; + private array $items = []; /** * 创建Feed对象 @@ -382,7 +382,7 @@ xml:base="' . $this->baseUrl . '" $result .= '<title type="text">' . htmlspecialchars($this->title) . ' ' . htmlspecialchars($this->subTitle ?? '') . ' ' . $this->dateFormat($lastUpdate) . ' -Typecho +Typecho ' . $this->feedUrl . ' diff --git a/var/Typecho/Http/Client.php b/var/Typecho/Http/Client.php index ba08298f..858db027 100644 --- a/var/Typecho/Http/Client.php +++ b/var/Typecho/Http/Client.php @@ -30,33 +30,33 @@ class Client * * @var string */ - private $method = self::METHOD_GET; + private string $method = self::METHOD_GET; /** * 传递参数 * * @var string */ - private $query; + private string $query; /** * User Agent * * @var string */ - private $agent; + private string $agent; /** * 设置超时 * - * @var string + * @var integer */ - private $timeout = 3; + private int $timeout = 3; /** * @var bool */ - private $multipart = true; + private bool $multipart = true; /** * 需要在body中传递的值 @@ -71,40 +71,40 @@ class Client * @access private * @var array */ - private $headers = []; + private array $headers = []; /** * cookies * * @var array */ - private $cookies = []; + private array $cookies = []; /** * @var array */ - private $options = []; + private array $options = []; /** * 回执头部信息 * * @var array */ - private $responseHeader = []; + private array $responseHeader = []; /** * 回执代码 * * @var integer */ - private $responseStatus; + private int $responseStatus; /** * 回执身体 * * @var string */ - private $responseBody; + private string $responseBody; /** * 设置指定的COOKIE值 diff --git a/var/Typecho/I18n.php b/var/Typecho/I18n.php index 158e84a1..399fb3ca 100644 --- a/var/Typecho/I18n.php +++ b/var/Typecho/I18n.php @@ -15,17 +15,17 @@ class I18n * 是否已经载入的标志位 * * @access private - * @var GetTextMulti + * @var GetTextMulti|null */ - private static $loaded; + private static ?GetTextMulti $loaded = null; /** * 语言文件 * * @access private - * @var string + * @var string|null */ - private static $lang = null; + private static ?string $lang = null; /** * 翻译文字 diff --git a/var/Typecho/I18n/GetTextMulti.php b/var/Typecho/I18n/GetTextMulti.php index 2a62515e..ef24268a 100644 --- a/var/Typecho/I18n/GetTextMulti.php +++ b/var/Typecho/I18n/GetTextMulti.php @@ -18,7 +18,7 @@ class GetTextMulti * @access private * @var GetText[] */ - private $handlers = []; + private array $handlers = []; /** * 构造函数 @@ -48,7 +48,7 @@ class GetTextMulti * Translates a string * * @access public - * @param string string to be translated + * @param string $string string to be translated * @return string translated string (or original, if not found) */ public function translate(string $string): string @@ -67,9 +67,9 @@ class GetTextMulti * Plural version of gettext * * @access public - * @param string single - * @param string plural - * @param string number + * @param string $single single + * @param string $plural plural + * @param string $number number * @return string translated plural form */ public function ngettext($single, $plural, $number): string diff --git a/var/Typecho/Plugin.php b/var/Typecho/Plugin.php index 0f44b71b..26cbd37f 100644 --- a/var/Typecho/Plugin.php +++ b/var/Typecho/Plugin.php @@ -19,28 +19,28 @@ class Plugin * * @var array */ - private static $plugin = []; + private static array $plugin = []; /** * 实例化的插件对象 * * @var array */ - private static $instances; + private static array $instances; /** * 临时存储变量 * * @var array */ - private static $tmp = []; + private static array $tmp = []; /** * 唯一句柄 * * @var string */ - private $handle; + private string $handle; /** * 组件 @@ -54,7 +54,7 @@ class Plugin * * @var boolean */ - private $signal; + private bool $signal; /** * 插件初始化 @@ -207,7 +207,7 @@ class Plugin /** 分行读取 */ $described = false; - $lines = preg_split("(\r|\n)", $token[1]); + $lines = preg_split("([\r\n])", $token[1]); foreach ($lines as $line) { $line = trim($line); if (!empty($line) && '*' == $line[0]) { @@ -352,9 +352,9 @@ class Plugin * 判断插件是否存在 * * @param string $pluginName 插件名称 - * @return mixed + * @return bool */ - public static function exists(string $pluginName) + public static function exists(string $pluginName): bool { return array_key_exists($pluginName, self::$plugin['activated']); } @@ -433,7 +433,7 @@ class Plugin * @param array $args 参数 * @return mixed */ - public function __call(string $component, array $args) + public function call(string $component, ...$args) { $component = $this->handle . ':' . $component; $last = count($args); @@ -449,4 +449,15 @@ class Plugin return $args[$last]; } + + /** + * @deprecated ^1.3.0 + * @param string $component + * @param array $args + * @return false|mixed|null + */ + public function __call(string $component, array $args) + { + return $this->call($component, ... $args); + } } diff --git a/var/Typecho/Request.php b/var/Typecho/Request.php index ac0c1496..31a1ef76 100644 --- a/var/Typecho/Request.php +++ b/var/Typecho/Request.php @@ -15,7 +15,7 @@ class Request * @access private * @var Request */ - private static $instance; + private static Request $instance; /** * 沙箱参数 @@ -23,7 +23,7 @@ class Request * @access private * @var Config|null */ - private $sandbox; + private ?Config $sandbox; /** * 用户参数 @@ -31,54 +31,54 @@ class Request * @access private * @var Config|null */ - private $params; + private ?Config $params; /** * 路径信息 * * @access private - * @var string + * @var string|null */ - private $pathInfo = null; + private ?string $pathInfo = null; /** * requestUri * - * @var string + * @var string|null * @access private */ - private $requestUri = null; + private ?string $requestUri = null; /** * requestRoot * - * @var mixed + * @var string|null * @access private */ - private $requestRoot = null; + private ?string $requestRoot = null; /** * 获取baseurl * - * @var string + * @var string|null * @access private */ - private $baseUrl = null; + private ?string $baseUrl = null; /** * 客户端ip地址 * * @access private - * @var string + * @var string|null */ - private $ip = null; + private ?string $ip = null; /** * 域名前缀 * - * @var string + * @var string|null */ - private $urlPrefix = null; + private ?string $urlPrefix = null; /** * 获取单例句柄 @@ -125,6 +125,18 @@ class Request return $this; } + /** + * @return $this + */ + public function endProxy(): Request + { + if (isset($this->params)) { + $this->params = null; + } + + return $this; + } + /** * 获取实际传递参数 * @@ -135,7 +147,6 @@ class Request */ public function get(string $key, $default = null, ?bool &$exists = true) { - $exists = true; $value = null; switch (true) { @@ -145,17 +156,13 @@ class Request case isset($this->sandbox): if (isset($this->sandbox[$key])) { $value = $this->sandbox[$key]; - } else { - $exists = false; } break; case $key === '@json': - $exists = false; if ($this->isJson()) { $body = file_get_contents('php://input'); if (false !== $body) { - $exists = true; $value = json_decode($body, true, 16); $default = $default ?? $value; } @@ -168,18 +175,19 @@ class Request $value = $_POST[$key]; break; default: - $exists = false; break; } - // reset params - if (isset($this->params)) { - $this->params = null; - } - if (isset($value)) { - return is_array($default) == is_array($value) ? $value : $default; + if (is_array($default) == is_array($value)) { + $exists = is_array($value) || (is_string($value) && strlen($value) > 0); + return $value; + } else { + $exists = false; + return $default; + } } else { + $exists = false; return $default; } } @@ -187,6 +195,7 @@ class Request /** * 获取实际传递参数(magic) * + * @deprecated ^1.3.0 * @param string $key 指定参数 * @return mixed */ @@ -198,6 +207,7 @@ class Request /** * 判断参数是否存在 * + * @deprecated ^1.3.0 * @param string $key 指定参数 * @return boolean */ diff --git a/var/Typecho/Response.php b/var/Typecho/Response.php index c9255153..9e3e001a 100644 --- a/var/Typecho/Response.php +++ b/var/Typecho/Response.php @@ -70,49 +70,49 @@ class Response * @access private * @var Response */ - private static $instance; + private static Response $instance; /** * 字符编码 * * @var string */ - private $charset = 'UTF-8'; + private string $charset = 'UTF-8'; /** * @var string */ - private $contentType = 'text/html'; + private string $contentType = 'text/html'; /** * @var callable[] */ - private $responders = []; + private array $responders = []; /** * @var array */ - private $cookies = []; + private array $cookies = []; /** * @var array */ - private $headers = []; + private array $headers = []; /** * @var int */ - private $status = 200; + private int $status = 200; /** * @var bool */ - private $enableAutoSendHeaders = true; + private bool $enableAutoSendHeaders = true; /** * @var bool */ - private $sandbox = false; + private bool $sandbox = false; /** * init responder @@ -194,7 +194,7 @@ class Response // set header foreach ($this->headers as $name => $value) { if (!in_array(strtolower($name), $sentHeaders)) { - header($name . ': ' . $value, true); + header($name . ': ' . $value); } } @@ -220,7 +220,7 @@ class Response public function respond() { if ($this->sandbox) { - throw new Terminal(); + throw new Terminal('sandbox mode'); } if ($this->enableAutoSendHeaders) { @@ -301,7 +301,7 @@ class Response * @param string $contentType 文档类型 * @return $this */ - public function setContentType(string $contentType = 'text/html'): Response + public function setContentType(string $contentType): Response { if (!$this->sandbox) { $this->contentType = $contentType; diff --git a/var/Typecho/Router.php b/var/Typecho/Router.php index 8b4d8f6d..0d21df89 100644 --- a/var/Typecho/Router.php +++ b/var/Typecho/Router.php @@ -17,32 +17,32 @@ class Router * * @var string */ - public static $current; + public static string $current; /** * 已经解析完毕的路由表配置 * * @var array */ - private static $routingTable = []; + private static array $routingTable = []; /** * 是否已经匹配过,防止递归匹配 * * @var bool */ - private static $matched = false; + private static bool $matched = false; /** * 解析路径 * - * @param string|null $pathInfo 全路径 + * @param string $pathInfo 全路径 * @param mixed $parameter 输入参数 * @param bool $once 是否只匹配一次 * @return false|Widget * @throws \Exception */ - public static function match(?string $pathInfo, $parameter = null, bool $once = true) + public static function match(string $pathInfo, $parameter = null, bool $once = true) { if ($once && self::$matched) { throw new RouterException("Path '{$pathInfo}' not found", 404); @@ -50,29 +50,17 @@ class Router self::$matched = true; - foreach (self::$routingTable as $key => $route) { - if (preg_match($route['regx'], $pathInfo, $matches)) { - self::$current = $key; - - try { - /** 载入参数 */ - $params = null; - - if (!empty($route['params'])) { - unset($matches[0]); - $params = array_combine($route['params'], $matches); - } - - return Widget::widget($route['widget'], $parameter, $params); - - } catch (\Exception $e) { - if (404 == $e->getCode()) { - Widget::destroy($route['widget']); - continue; - } - - throw $e; + foreach (self::route($pathInfo) as $result) { + [$route, $params] = $result; + try { + return Widget::widget($route['widget'], $parameter, $params); + } catch (\Exception $e) { + if (404 == $e->getCode()) { + Widget::destroy($route['widget']); + continue; } + + throw $e; } } @@ -89,35 +77,24 @@ class Router /** 获取PATHINFO */ $pathInfo = Request::getInstance()->getPathInfo(); - foreach (self::$routingTable as $key => $route) { - if (preg_match($route['regx'], $pathInfo, $matches)) { - self::$current = $key; + foreach (self::route($pathInfo) as $result) { + [$route, $params] = $result; - try { - /** 载入参数 */ - $params = null; + try { + $widget = Widget::widget($route['widget'], null, $params); - if (!empty($route['params'])) { - unset($matches[0]); - $params = array_combine($route['params'], $matches); - } - - $widget = Widget::widget($route['widget'], null, $params); - - if (isset($route['action'])) { - $widget->{$route['action']}(); - } - - return; - - } catch (\Exception $e) { - if (404 == $e->getCode()) { - Widget::destroy($route['widget']); - continue; - } - - throw $e; + if (isset($route['action'])) { + $widget->{$route['action']}(); } + + return; + } catch (\Exception $e) { + if (404 == $e->getCode()) { + Widget::destroy($route['widget']); + continue; + } + + throw $e; } } @@ -173,4 +150,28 @@ class Router { return self::$routingTable[$routeName] ?? null; } + + /** + * @param string $pathInfo + * @return \Generator + * @throws \Exception + */ + private static function route(string $pathInfo): \Generator + { + foreach (self::$routingTable as $key => $route) { + if (preg_match($route['regx'], $pathInfo, $matches)) { + self::$current = $key; + + /** 载入参数 */ + $params = null; + + if (!empty($route['params'])) { + unset($matches[0]); + $params = array_combine($route['params'], $matches); + } + + yield [$route, $params]; + } + } + } } diff --git a/var/Typecho/Router/Parser.php b/var/Typecho/Router/Parser.php index 361e4f96..c400d44f 100644 --- a/var/Typecho/Router/Parser.php +++ b/var/Typecho/Router/Parser.php @@ -18,7 +18,7 @@ class Parser * @access private * @var array */ - private $defaultRegex; + private array $defaultRegex; /** * 路由器映射表 @@ -26,7 +26,7 @@ class Parser * @access private * @var array */ - private $routingTable; + private array $routingTable; /** * 参数表 @@ -34,7 +34,7 @@ class Parser * @access private * @var array */ - private $params; + private array $params; /** * 设置路由表 diff --git a/var/Typecho/Validate.php b/var/Typecho/Validate.php index ae8a3a5d..f0d9d9b1 100644 --- a/var/Typecho/Validate.php +++ b/var/Typecho/Validate.php @@ -15,7 +15,7 @@ class Validate * @access private * @var array */ - private $data; + private array $data; /** * 当前验证指针 @@ -23,7 +23,7 @@ class Validate * @access private * @var string */ - private $key; + private string $key; /** * 验证规则数组 @@ -31,7 +31,7 @@ class Validate * @access private * @var array */ - private $rules = []; + private array $rules = []; /** * 中断模式,一旦出现验证错误即抛出而不再继续执行 @@ -39,7 +39,7 @@ class Validate * @access private * @var boolean */ - private $break = false; + private bool $break = false; /** * 最小长度 @@ -120,7 +120,7 @@ class Validate * * @access public * - * @param string + * @param string $str * * @return boolean */ diff --git a/var/Typecho/Widget.php b/var/Typecho/Widget.php index e2665ead..4de9e51d 100644 --- a/var/Typecho/Widget.php +++ b/var/Typecho/Widget.php @@ -23,63 +23,63 @@ abstract class Widget * * @var array */ - private static $widgetPool = []; + private static array $widgetPool = []; /** * widget别名 * * @var array */ - private static $widgetAlias = []; + private static array $widgetAlias = []; /** * request对象 * * @var WidgetRequest */ - protected $request; + protected WidgetRequest $request; /** * response对象 * * @var WidgetResponse */ - protected $response; + protected WidgetResponse $response; /** * 数据堆栈 * * @var array */ - protected $stack = []; + protected array $stack = []; /** * 当前队列指针顺序值,从1开始 * * @var integer */ - protected $sequence = 0; + protected int $sequence = 0; /** * 队列长度 * * @var integer */ - protected $length = 0; + protected int $length = 0; /** * config对象 * * @var Config */ - protected $parameter; + protected Config $parameter; /** * 数据堆栈每一行 * * @var array */ - protected $row = []; + protected array $row = []; /** * 构造函数,初始化组件 @@ -361,7 +361,7 @@ abstract class Widget public function __call(string $name, array $args) { $method = 'call' . ucfirst($name); - self::pluginHandle()->trigger($plugged)->{$method}($this, $args); + self::pluginHandle()->trigger($plugged)->call($method, $this, $args); if (!$plugged) { echo $this->{$name}; @@ -394,7 +394,7 @@ abstract class Widget if (method_exists($this, $method)) { return $this->$method(); } else { - $return = self::pluginHandle()->trigger($plugged)->{$method}($this); + $return = self::pluginHandle()->trigger($plugged)->call($method, $this); if ($plugged) { return $return; } diff --git a/var/Typecho/Widget/Helper/EmptyClass.php b/var/Typecho/Widget/Helper/EmptyClass.php index 22e8d94d..1981d96e 100644 --- a/var/Typecho/Widget/Helper/EmptyClass.php +++ b/var/Typecho/Widget/Helper/EmptyClass.php @@ -18,7 +18,7 @@ class EmptyClass * @access private * @var EmptyClass */ - private static $instance = null; + private static ?EmptyClass $instance = null; /** * 获取单例句柄 diff --git a/var/Typecho/Widget/Helper/Form.php b/var/Typecho/Widget/Helper/Form.php index 4c1b49b3..92f6b0f0 100644 --- a/var/Typecho/Widget/Helper/Form.php +++ b/var/Typecho/Widget/Helper/Form.php @@ -42,7 +42,7 @@ class Form extends Layout * @access private * @var array */ - private $inputs = []; + private array $inputs = []; /** * 构造函数,设置基本属性 diff --git a/var/Typecho/Widget/Helper/Form/Element.php b/var/Typecho/Widget/Helper/Form/Element.php index 984864c5..f95d1b82 100644 --- a/var/Typecho/Widget/Helper/Form/Element.php +++ b/var/Typecho/Widget/Helper/Form/Element.php @@ -24,7 +24,7 @@ abstract class Element extends Layout * @access protected * @var integer */ - protected static $uniqueId = 0; + protected static int $uniqueId = 0; /** * 表单元素容器 @@ -32,15 +32,15 @@ abstract class Element extends Layout * @access public * @var Layout */ - public $container; + public Layout $container; /** * 输入栏 * * @access public - * @var Layout + * @var Layout|null */ - public $input; + public ?Layout $input; /** * inputs @@ -48,7 +48,7 @@ abstract class Element extends Layout * @var array * @access public */ - public $inputs = []; + public array $inputs = []; /** * 表单标题 @@ -56,7 +56,7 @@ abstract class Element extends Layout * @access public * @var Layout */ - public $label; + public Layout $label; /** * 表单验证器 @@ -64,7 +64,7 @@ abstract class Element extends Layout * @access public * @var array */ - public $rules = []; + public array $rules = []; /** * 表单名称 @@ -72,7 +72,7 @@ abstract class Element extends Layout * @access public * @var string */ - public $name; + public ?string $name; /** * 表单值 @@ -86,17 +86,17 @@ abstract class Element extends Layout * 表单描述 * * @access private - * @var string + * @var Layout */ - protected $description; + protected Layout $description; /** * 表单消息 * * @access protected - * @var string + * @var Layout */ - protected $message; + protected Layout $message; /** * 多行输入 @@ -104,7 +104,7 @@ abstract class Element extends Layout * @access public * @var array() */ - protected $multiline = []; + protected array $multiline = []; /** * 构造函数 diff --git a/var/Typecho/Widget/Helper/Form/Element/Checkbox.php b/var/Typecho/Widget/Helper/Form/Element/Checkbox.php index b931d692..3f89586e 100644 --- a/var/Typecho/Widget/Helper/Form/Element/Checkbox.php +++ b/var/Typecho/Widget/Helper/Form/Element/Checkbox.php @@ -24,7 +24,7 @@ class Checkbox extends Element * * @var array */ - private $options = []; + private array $options = []; /** * 初始化当前输入项 diff --git a/var/Typecho/Widget/Helper/Form/Element/Radio.php b/var/Typecho/Widget/Helper/Form/Element/Radio.php index 6125d531..bcc8618c 100644 --- a/var/Typecho/Widget/Helper/Form/Element/Radio.php +++ b/var/Typecho/Widget/Helper/Form/Element/Radio.php @@ -24,7 +24,7 @@ class Radio extends Element * * @var array */ - private $options = []; + private array $options = []; /** * 初始化当前输入项 diff --git a/var/Typecho/Widget/Helper/Form/Element/Select.php b/var/Typecho/Widget/Helper/Form/Element/Select.php index c1f5046b..2a57b860 100644 --- a/var/Typecho/Widget/Helper/Form/Element/Select.php +++ b/var/Typecho/Widget/Helper/Form/Element/Select.php @@ -24,7 +24,7 @@ class Select extends Element * * @var array */ - private $options = []; + private array $options = []; /** * 初始化当前输入项 diff --git a/var/Typecho/Widget/Helper/Layout.php b/var/Typecho/Widget/Helper/Layout.php index 01e22617..bb92a5bd 100644 --- a/var/Typecho/Widget/Helper/Layout.php +++ b/var/Typecho/Widget/Helper/Layout.php @@ -18,7 +18,7 @@ class Layout * @access private * @var array */ - private $items = []; + private array $items = []; /** * 表单属性列表 @@ -26,7 +26,7 @@ class Layout * @access private * @var array */ - private $attributes = []; + private array $attributes = []; /** * 标签名称 @@ -34,7 +34,7 @@ class Layout * @access private * @var string */ - private $tagName = 'div'; + private string $tagName = 'div'; /** * 是否自闭合 @@ -42,15 +42,15 @@ class Layout * @access private * @var boolean */ - private $close = false; + private bool $close = false; /** * 是否强制自闭合 * * @access private - * @var boolean + * @var boolean|null */ - private $forceClose = null; + private ?bool $forceClose = null; /** * 内部数据 @@ -58,7 +58,7 @@ class Layout * @access private * @var string */ - private $html; + private string $html; /** * 父节点 diff --git a/var/Typecho/Widget/Helper/PageNavigator.php b/var/Typecho/Widget/Helper/PageNavigator.php index 2abfcf7b..15855105 100644 --- a/var/Typecho/Widget/Helper/PageNavigator.php +++ b/var/Typecho/Widget/Helper/PageNavigator.php @@ -16,42 +16,42 @@ abstract class PageNavigator * * @var integer */ - protected $total; + protected int $total; /** * 页面总数 * * @var integer */ - protected $totalPage; + protected int $totalPage; /** * 当前页面 * * @var integer */ - protected $currentPage; + protected int $currentPage; /** * 每页内容数 * * @var integer */ - protected $pageSize; + protected int $pageSize; /** * 页面链接模板 * * @var string */ - protected $pageTemplate; + protected string $pageTemplate; /** * 链接锚点 * * @var string */ - protected $anchor; + protected string $anchor = ''; /** * 页面占位符 diff --git a/var/Typecho/Widget/Request.php b/var/Typecho/Widget/Request.php index 84da3830..8dc3181e 100644 --- a/var/Typecho/Widget/Request.php +++ b/var/Typecho/Widget/Request.php @@ -33,17 +33,17 @@ class Request * @access private * @var array */ - private $filter = []; + private array $filter = []; /** * @var HttpRequest */ - private $request; + private HttpRequest $request; /** * @var Config */ - private $params; + private Config $params; /** * @param HttpRequest $request @@ -105,6 +105,7 @@ class Request /** * 获取实际传递参数(magic) * + * @deprecated ^1.3.0 * @param string $key 指定参数 * @return mixed */ @@ -116,6 +117,7 @@ class Request /** * 判断参数是否存在 * + * @deprecated ^1.3.0 * @param string $key 指定参数 * @return boolean */ @@ -154,6 +156,19 @@ class Request return $this->applyFilter(call_user_func_array([$this->request->proxy($this->params), 'from'], $params)); } + /** + * 判断输入是否满足要求 + * + * @param mixed $query 条件 + * @return boolean + */ + public function is($query): bool + { + $result = $this->request->proxy($this->params)->is($query); + $this->request->endProxy(); + return $result; + } + /** * @return string */ @@ -337,17 +352,6 @@ class Request return $this->request->isJson(); } - /** - * 判断输入是否满足要求 - * - * @param mixed $query 条件 - * @return boolean - */ - public function is($query): bool - { - return $this->request->is($query); - } - /** * 应用过滤器 * @@ -366,6 +370,7 @@ class Request $this->filter = []; } + $this->request->endProxy(); return $value; } diff --git a/var/Typecho/Widget/Response.php b/var/Typecho/Widget/Response.php index db9351a3..b6e7820d 100644 --- a/var/Typecho/Widget/Response.php +++ b/var/Typecho/Widget/Response.php @@ -14,12 +14,12 @@ class Response /** * @var HttpRequest */ - private $request; + private HttpRequest $request; /** * @var HttpResponse */ - private $response; + private HttpResponse $response; /** * @param HttpRequest $request diff --git a/var/Utils/AutoP.php b/var/Utils/AutoP.php index d52a9242..a8630949 100644 --- a/var/Utils/AutoP.php +++ b/var/Utils/AutoP.php @@ -20,7 +20,7 @@ class AutoP * @access private * @var integer */ - private $uniqueId = 0; + private int $uniqueId = 0; /** * 存储的段落 @@ -28,7 +28,7 @@ class AutoP * @access private * @var array */ - private $blocks = []; + private array $blocks = []; /** * 替换段落的回调函数 diff --git a/var/Utils/Helper.php b/var/Utils/Helper.php index ca66db3b..494a0082 100644 --- a/var/Utils/Helper.php +++ b/var/Utils/Helper.php @@ -75,9 +75,9 @@ class Helper * @param $method * @param $params */ - public static function requestService($method, $params) + public static function requestService($method, ... $params) { - Service::alloc()->requestService($method, $params); + Service::alloc()->requestService($method, ... $params); } /** diff --git a/var/Utils/PasswordHash.php b/var/Utils/PasswordHash.php index 0a2470bc..16299e7e 100644 --- a/var/Utils/PasswordHash.php +++ b/var/Utils/PasswordHash.php @@ -12,13 +12,13 @@ namespace Utils; */ class PasswordHash { - private $itoa64; + private string $itoa64; - private $iteration_count_log2; + private int $iteration_count_log2; - private $portable_hashes; + private bool $portable_hashes; - private $random_state; + private string $random_state; /** * @param int $iteration_count_log2 diff --git a/var/Utils/Upgrade.php b/var/Utils/Upgrade.php index 7fc1e70f..0e13edc0 100644 --- a/var/Utils/Upgrade.php +++ b/var/Utils/Upgrade.php @@ -40,5 +40,7 @@ class Upgrade $db->query($db->update('table.options') ->rows(['value' => serialize($routingTable)]) ->where('name = ?', 'routingTable')); + + // todo: fix options->commentsRequireURL } } diff --git a/var/Widget/Action.php b/var/Widget/Action.php index 353ea554..b15c54df 100644 --- a/var/Widget/Action.php +++ b/var/Widget/Action.php @@ -21,7 +21,7 @@ class Action extends Widget * @access private * @var array */ - private $map = [ + private array $map = [ 'ajax' => '\Widget\Ajax', 'login' => '\Widget\Login', 'logout' => '\Widget\Logout', @@ -55,7 +55,7 @@ class Action extends Widget public function execute() { /** 验证路由地址 **/ - $action = $this->request->action; + $action = $this->request->get('action'); /** 判断是否为plugin */ $actionTable = array_merge($this->map, unserialize(Options::alloc()->actionTable)); diff --git a/var/Widget/Ajax.php b/var/Widget/Ajax.php index 3c01c9fd..c464dca6 100644 --- a/var/Widget/Ajax.php +++ b/var/Widget/Ajax.php @@ -58,7 +58,7 @@ class Ajax extends BaseOptions implements ActionInterface if ( isset($json['release']) - && preg_match("/^[0-9\.]+$/", $json['release']) + && preg_match("/^[0-9.]+$/", $json['release']) && version_compare($json['release'], $version, '>') ) { $result = [ @@ -96,7 +96,7 @@ class Ajax extends BaseOptions implements ActionInterface /** 匹配内容体 */ $response = $client->getResponseBody(); preg_match_all( - "/\s*([^>]*)<\/title>\s*<link>([^>]*)<\/link>\s*<guid>[^>]*<\/guid>\s*<pubDate>([^>]*)<\/pubDate>/is", + "/<item>\s*<title>([^>]*)<\/title>\s*<link>([^>]*)<\/link>\s*<guid>[^>]*<\/guid>\s*<pubDate>([^>]*)<\/pubDate>/i", $response, $matches ); @@ -127,18 +127,20 @@ class Ajax extends BaseOptions implements ActionInterface public function editorResize() { $this->user->pass('contributor'); + $size = $this->request->filter('int')->get('size'); + if ( $this->db->fetchObject($this->db->select(['COUNT(*)' => 'num']) ->from('table.options')->where('name = ? AND user = ?', 'editorSize', $this->user->uid))->num > 0 ) { parent::update( - ['value' => $this->request->size], + ['value' => $size], $this->db->sql()->where('name = ? AND user = ?', 'editorSize', $this->user->uid) ); } else { parent::insert([ 'name' => 'editorSize', - 'value' => $this->request->size, + 'value' => $size, 'user' => $this->user->uid ]); } diff --git a/var/Widget/Archive.php b/var/Widget/Archive.php index dff096c1..ecc87ced 100644 --- a/var/Widget/Archive.php +++ b/var/Widget/Archive.php @@ -37,119 +37,119 @@ class Archive extends Contents * * @var string */ - private $themeFile; + private string $themeFile; /** * 风格目录 * * @var string */ - private $themeDir; + private string $themeDir; /** * 分页计算对象 * * @var Query */ - private $countSql; + private Query $countSql; /** * 所有文章个数 * - * @var integer + * @var int|null */ - private $total = false; + private ?int $total = null; /** * 标记是否为从外部调用 * * @var boolean */ - private $invokeFromOutside = false; + private bool $invokeFromOutside = false; /** * 是否由聚合调用 * * @var boolean */ - private $invokeByFeed = false; + private bool $invokeByFeed = false; /** * 当前页 * * @var integer */ - private $currentPage; + private int $currentPage; /** * 生成分页的内容 * * @var array */ - private $pageRow = []; + private array $pageRow = []; /** * RSS 2.0聚合地址 * * @var string */ - private $feedUrl; + private string $feedUrl; /** * RSS 1.0聚合地址 * * @var string */ - private $feedRssUrl; + private string $feedRssUrl; /** * ATOM 聚合地址 * * @var string */ - private $feedAtomUrl; + private string $feedAtomUrl; /** * 本页关键字 * * @var string */ - private $keywords; + private string $keywords; /** * 本页描述 * * @var string */ - private $description; + private string $description; /** * 归档标题 * - * @var string + * @var string|null */ - private $archiveTitle = null; + private ?string $archiveTitle = null; /** * 归档地址 * * @var string|null */ - private $archiveUrl = null; + private ?string $archiveUrl = null; /** * 归档类型 * * @var string */ - private $archiveType = 'index'; + private string $archiveType = 'index'; /** * 是否为单一归档 * - * @var string + * @var boolean */ - private $archiveSingle = false; + private bool $archiveSingle = false; /** * 是否为自定义首页, 主要为了标记自定义首页的情况 @@ -159,7 +159,7 @@ class Archive extends Contents * @var boolean * @access private */ - private $makeSinglePageAsFrontPage = false; + private bool $makeSinglePageAsFrontPage = false; /** * 归档缩略名 @@ -167,7 +167,7 @@ class Archive extends Contents * @access private * @var string */ - private $archiveSlug; + private string $archiveSlug; /** * 设置分页对象 @@ -175,7 +175,7 @@ class Archive extends Contents * @access private * @var PageNavigator */ - private $pageNav; + private PageNavigator $pageNav; /** * @param Config $parameter @@ -268,22 +268,6 @@ class Archive extends Contents $this->archiveSlug = $archiveSlug; } - /** - * @return string|null - */ - public function getArchiveSingle(): ?string - { - return $this->archiveSingle; - } - - /** - * @param string $archiveSingle the $archiveSingle to set - */ - public function setArchiveSingle(string $archiveSingle) - { - $this->archiveSingle = $archiveSingle; - } - /** * @return string|null */ @@ -469,7 +453,7 @@ class Archive extends Contents */ public function getTotal(): int { - if (false === $this->total) { + if (!isset($this->total)) { $this->total = $this->size($this->countSql); } @@ -553,7 +537,7 @@ class Archive extends Contents ]; /** 处理搜索结果跳转 */ - if (isset($this->request->s)) { + if ($this->request->is('s')) { $filterKeywords = $this->request->filter('search')->get('s'); /** 跳转到搜索页 */ @@ -587,11 +571,11 @@ class Archive extends Contents } /** 初始化分页变量 */ - $this->currentPage = $this->request->filter('int')->page ?? 1; + $this->currentPage = $this->request->filter('int')->get('page', 1); $hasPushed = false; /** select初始化 */ - $select = self::pluginHandle()->trigger($selectPlugged)->select($this); + $select = self::pluginHandle()->trigger($selectPlugged)->call('select', $this); /** 定时发布功能 */ if (!$selectPlugged) { @@ -632,7 +616,7 @@ class Archive extends Contents } /** handle初始化 */ - self::pluginHandle()->handleInit($this, $select); + self::pluginHandle()->call('handleInit', $this, $select); /** 初始化其它变量 */ $this->feedUrl = $this->options->feedUrl; @@ -646,7 +630,7 @@ class Archive extends Contents $handle = $handles[$this->parameter->type]; $this->{$handle}($select, $hasPushed); } else { - $hasPushed = self::pluginHandle()->handle($this->parameter->type, $this, $select); + $hasPushed = self::pluginHandle()->call('handle', $this->parameter->type, $this, $select); } /** 初始化皮肤函数 */ @@ -745,7 +729,8 @@ class Archive extends Contents $this->options->index ); - self::pluginHandle()->trigger($hasNav)->pageNav( + self::pluginHandle()->trigger($hasNav)->call( + 'pageNav', $this->currentPage, $total, $this->parameter->pageSize, @@ -988,7 +973,7 @@ class Archive extends Contents $allows = array_merge($allows, $rules); } - $allows = self::pluginHandle()->headerOptions($allows, $this); + $allows = self::pluginHandle()->call('headerOptions', $allows, $this); $title = (empty($this->archiveTitle) ? '' : $this->archiveTitle . ' » ') . $this->options->title; $header = ''; @@ -1172,7 +1157,7 @@ class Archive extends Contents echo $header; /** 插件支持 */ - self::pluginHandle()->header($header, $this); + self::pluginHandle()->call('header', $header, $this); } /** @@ -1180,7 +1165,7 @@ class Archive extends Contents */ public function footer() { - self::pluginHandle()->footer($this); + self::pluginHandle()->call('footer', $this); } /** @@ -1321,13 +1306,13 @@ class Archive extends Contents } /** 挂接插件 */ - self::pluginHandle()->beforeRender($this); + self::pluginHandle()->call('beforeRender', $this); /** 输出模板 */ require_once $this->themeDir . $this->themeFile; /** 挂接插件 */ - self::pluginHandle()->afterRender($this); + self::pluginHandle()->call('afterRender', $this); } /** @@ -1355,7 +1340,7 @@ class Archive extends Contents */ public function query($select) { - self::pluginHandle()->trigger($queryPlugged)->query($this, $select); + self::pluginHandle()->trigger($queryPlugged)->call('query', $this, $select); if (!$queryPlugged) { $this->db->fetchAll($select, [$this, 'push']); } @@ -1373,7 +1358,7 @@ class Archive extends Contents $commentUrl = parent::___commentUrl(); //不依赖js的父级评论 - $reply = $this->request->filter('int')->replyTo; + $reply = $this->request->filter('int')->get('replyTo'); if ($reply && $this->is('single')) { $commentUrl .= '?parent=' . $reply; } @@ -1432,7 +1417,7 @@ class Archive extends Contents $select->where('table.contents.type = ?', 'post'); /** 插件接口 */ - self::pluginHandle()->indexHandle($this, $select); + self::pluginHandle()->call('indexHandle', $this, $select); } /** @@ -1476,7 +1461,7 @@ class Archive extends Contents $hasPushed = true; /** 插件接口 */ - self::pluginHandle()->error404Handle($this, $select); + self::pluginHandle()->call('error404Handle', $this, $select); } /** @@ -1502,18 +1487,18 @@ class Archive extends Contents } /** 如果是单篇文章或独立页面 */ - if (isset($this->request->cid)) { - $select->where('table.contents.cid = ?', $this->request->filter('int')->cid); + if ($this->request->is('cid')) { + $select->where('table.contents.cid = ?', $this->request->filter('int')->get('cid')); } /** 匹配缩略名 */ - if (isset($this->request->slug) && !$this->parameter->preview) { - $select->where('table.contents.slug = ?', $this->request->slug); + if ($this->request->is('slug') && !$this->parameter->preview) { + $select->where('table.contents.slug = ?', $this->request->get('slug')); } /** 匹配时间 */ - if (isset($this->request->year) && !$this->parameter->preview) { - $year = $this->request->filter('int')->year; + if ($this->request->is('year') && !$this->parameter->preview) { + $year = $this->request->filter('int')->get('year'); $fromMonth = 1; $toMonth = 12; @@ -1521,15 +1506,15 @@ class Archive extends Contents $fromDay = 1; $toDay = 31; - if (isset($this->request->month)) { - $fromMonth = $this->request->filter('int')->month; + if ($this->request->is('month')) { + $fromMonth = $this->request->filter('int')->get('month'); $toMonth = $fromMonth; $fromDay = 1; $toDay = date('t', mktime(0, 0, 0, $toMonth, 1, $year)); - if (isset($this->request->day)) { - $fromDay = $this->request->filter('int')->day; + if ($this->request->is('day')) { + $fromDay = $this->request->filter('int')->get('day'); $toDay = $fromDay; } } @@ -1547,12 +1532,12 @@ class Archive extends Contents if ( $this->request->isPost() - && isset($this->request->protectPassword) + && $this->request->is('protectPassword') && !$this->parameter->preview ) { $this->security->protect(); Cookie::set( - 'protectPassword_' . $this->request->filter('int')->protectCID, + 'protectPassword_' . $this->request->filter('int')->get('protectCID'), $this->request->protectPassword ); @@ -1565,10 +1550,10 @@ class Archive extends Contents if ( !$this->have() - || (isset($this->request->category) - && $this->category != $this->request->category && !$this->parameter->preview) - || (isset($this->request->directory) - && $this->request->directory != implode('/', $this->directory) && !$this->parameter->preview) + || ($this->request->is('category') + && $this->category != $this->request->get('category') && !$this->parameter->preview) + || ($this->request->is('directory') + && $this->request->get('directory') != implode('/', $this->directory) && !$this->parameter->preview) ) { if (!$this->invokeFromOutside) { /** 对没有索引情况下的判断 */ @@ -1630,7 +1615,7 @@ class Archive extends Contents $hasPushed = true; /** 插件接口 */ - self::pluginHandle()->singleHandle($this, $select); + self::pluginHandle()->call('singleHandle', $this, $select); } /** @@ -1648,16 +1633,16 @@ class Archive extends Contents ->where('type = ?', 'category') ->limit(1); - if (isset($this->request->mid)) { - $categorySelect->where('mid = ?', $this->request->filter('int')->mid); + if ($this->request->is('mid')) { + $categorySelect->where('mid = ?', $this->request->filter('int')->get('mid')); } - if (isset($this->request->slug)) { - $categorySelect->where('slug = ?', $this->request->slug); + if ($this->request->is('slug')) { + $categorySelect->where('slug = ?', $this->request->get('slug')); } - if (isset($this->request->directory)) { - $directory = explode('/', $this->request->directory); + if ($this->request->is('directory')) { + $directory = explode('/', $this->request->get('directory')); $categorySelect->where('slug = ?', $directory[count($directory) - 1]); } @@ -1669,7 +1654,7 @@ class Archive extends Contents $categoryListWidget = Rows::alloc('current=' . $category['mid']); $category = $categoryListWidget->filter($category); - if (isset($directory) && ($this->request->directory != implode('/', $category['directory']))) { + if (isset($directory) && ($this->request->get('directory') != implode('/', $category['directory']))) { throw new WidgetException(_t('父级分类不存在'), 404); } @@ -1717,7 +1702,7 @@ class Archive extends Contents $this->archiveUrl = $category['permalink']; /** 插件接口 */ - self::pluginHandle()->categoryHandle($this, $select); + self::pluginHandle()->call('categoryHandle', $this, $select); } /** @@ -1732,12 +1717,12 @@ class Archive extends Contents $tagSelect = $this->db->select()->from('table.metas') ->where('type = ?', 'tag')->limit(1); - if (isset($this->request->mid)) { - $tagSelect->where('mid = ?', $this->request->filter('int')->mid); + if ($this->request->is('mid')) { + $tagSelect->where('mid = ?', $this->request->filter('int')->get('mid')); } - if (isset($this->request->slug)) { - $tagSelect->where('slug = ?', $this->request->slug); + if ($this->request->is('slug')) { + $tagSelect->where('slug = ?', $this->request->get('slug')); } /** 如果是标签 */ @@ -1789,7 +1774,7 @@ class Archive extends Contents $this->archiveUrl = $tag['permalink']; /** 插件接口 */ - self::pluginHandle()->tagHandle($this, $select); + self::pluginHandle()->call('tagHandle', $this, $select); } /** @@ -1801,7 +1786,7 @@ class Archive extends Contents */ private function authorHandle(Query $select, bool &$hasPushed) { - $uid = $this->request->filter('int')->uid; + $uid = $this->request->filter('int')->get('uid'); $author = $this->db->fetchRow( $this->db->select()->from('table.users') @@ -1848,7 +1833,7 @@ class Archive extends Contents $this->archiveUrl = $author['permalink']; /** 插件接口 */ - self::pluginHandle()->authorHandle($this, $select); + self::pluginHandle()->call('authorHandle', $this, $select); } /** @@ -1862,9 +1847,9 @@ class Archive extends Contents private function dateHandle(Query $select, &$hasPushed) { /** 如果是按日期归档 */ - $year = $this->request->filter('int')->year; - $month = $this->request->filter('int')->month; - $day = $this->request->filter('int')->day; + $year = $this->request->filter('int')->get('year'); + $month = $this->request->filter('int')->get('month'); + $day = $this->request->filter('int')->get('day'); if (!empty($year) && !empty($month) && !empty($day)) { @@ -1934,7 +1919,7 @@ class Archive extends Contents $this->archiveUrl = Router::url($currentRoute, $value, $this->options->index); /** 插件接口 */ - self::pluginHandle()->dateHandle($this, $select); + self::pluginHandle()->call('dateHandle', $this, $select); } /** @@ -1949,8 +1934,8 @@ class Archive extends Contents { /** 增加自定义搜索引擎接口 */ //~ fix issue 40 - $keywords = $this->request->filter('url', 'search')->keywords; - self::pluginHandle()->trigger($hasPushed)->search($keywords, $this); + $keywords = $this->request->filter('url', 'search')->get('keywords'); + self::pluginHandle()->trigger($hasPushed)->call('search', $keywords, $this); if (!$hasPushed) { $searchQuery = '%' . str_replace(' ', '%', $keywords) . '%'; @@ -1999,6 +1984,6 @@ class Archive extends Contents $this->archiveUrl = Router::url('search', ['keywords' => $keywords], $this->options->index); /** 插件接口 */ - self::pluginHandle()->searchHandle($this, $select); + self::pluginHandle()->call('searchHandle', $this, $select); } } diff --git a/var/Widget/Backup.php b/var/Widget/Backup.php index 33dc1c21..0c1644bd 100644 --- a/var/Widget/Backup.php +++ b/var/Widget/Backup.php @@ -25,7 +25,7 @@ class Backup extends BaseOptions implements ActionInterface /** * @var array */ - private $types = [ + private array $types = [ 'contents' => 1, 'comments' => 2, 'metas' => 3, @@ -37,7 +37,7 @@ class Backup extends BaseOptions implements ActionInterface /** * @var array */ - private $fields = [ + private array $fields = [ 'contents' => [ 'cid', 'title', 'slug', 'created', 'modified', 'text', 'order', 'authorId', 'template', 'type', 'status', 'password', 'commentsNum', 'allowComment', 'allowPing', 'allowFeed', 'parent' @@ -62,17 +62,17 @@ class Backup extends BaseOptions implements ActionInterface /** * @var array */ - private $lastIds = []; + private array $lastIds = []; /** * @var array */ - private $cleared = []; + private array $cleared = []; /** * @var bool */ - private $login = false; + private bool $login = false; /** * 列出已有备份文件 @@ -126,7 +126,7 @@ class Backup extends BaseOptions implements ActionInterface } while (count($rows) == 20); } - self::pluginHandle()->export($fp); + self::pluginHandle()->call('export', $fp); fwrite($fp, $header); fclose($fp); diff --git a/var/Widget/Base.php b/var/Widget/Base.php index e28be21f..65fafb27 100644 --- a/var/Widget/Base.php +++ b/var/Widget/Base.php @@ -55,28 +55,28 @@ abstract class Base extends Widget * * @var Options */ - protected $options; + protected Options $options; /** * 用户对象 * * @var User */ - protected $user; + protected User $user; /** * 安全模块 * * @var Security */ - protected $security; + protected Security $security; /** * 数据库对象 * * @var Db */ - protected $db; + protected Db $db; /** * init method diff --git a/var/Widget/Base/Comments.php b/var/Widget/Base/Comments.php index 2c468e08..07dc8655 100644 --- a/var/Widget/Base/Comments.php +++ b/var/Widget/Base/Comments.php @@ -243,7 +243,7 @@ class Comments extends Base implements QueryInterface $value['text'] = $value['text'] ?? ''; $value['date'] = new Date($value['created']); - return Comments::pluginHandle()->filter($value, $this); + return Comments::pluginHandle()->call('filter', $value, $this); } /** @@ -286,7 +286,7 @@ class Comments extends Base implements QueryInterface if ($this->options->commentsAvatar && 'comment' == $this->type) { $rating = $this->options->commentsAvatarRating; - Comments::pluginHandle()->trigger($plugged)->gravatar($size, $rating, $default, $this); + Comments::pluginHandle()->trigger($plugged)->call('gravatar', $size, $rating, $default, $this); if (!$plugged) { $url = Common::gravatarUrl($this->mail, $size, $rating, $default, $this->request->isSecure()); echo '<img class="avatar" loading="lazy" src="' . $url . '" alt="' . @@ -353,7 +353,7 @@ class Comments extends Base implements QueryInterface */ public function markdown(?string $text): ?string { - $html = Comments::pluginHandle()->trigger($parsed)->markdown($text); + $html = Comments::pluginHandle()->trigger($parsed)->call('markdown', $text); if (!$parsed) { $html = Markdown::convert($text); @@ -370,7 +370,7 @@ class Comments extends Base implements QueryInterface */ public function autoP(?string $text): ?string { - $html = Comments::pluginHandle()->trigger($parsed)->autoP($text); + $html = Comments::pluginHandle()->trigger($parsed)->call('autoP', $text); if (!$parsed) { static $parser; @@ -436,7 +436,7 @@ class Comments extends Base implements QueryInterface $select = $this->db->select('coid', 'parent') ->from('table.comments')->where('cid = ? AND status = ?', $this->parentContent['cid'], 'approved') ->where('coid ' . ('DESC' == $this->options->commentsOrder ? '>=' : '<=') . ' ?', $coid) - ->order('coid', Db::SORT_ASC); + ->order('coid'); if ($this->options->commentsShowCommentOnly) { $select->where('type = ?', 'comment'); @@ -477,13 +477,13 @@ class Comments extends Base implements QueryInterface { $text = $this->parentContent['hidden'] ? _t('内容被隐藏') : $this->text; - $text = Comments::pluginHandle()->trigger($plugged)->content($text, $this); + $text = Comments::pluginHandle()->trigger($plugged)->call('content', $text, $this); if (!$plugged) { $text = $this->options->commentsMarkdown ? $this->markdown($text) : $this->autoP($text); } - $text = Comments::pluginHandle()->contentEx($text, $this); + $text = Comments::pluginHandle()->call('contentEx', $text, $this); return Common::stripTags($text, '<p><br>' . $this->options->commentsHTMLTagAllowed); } diff --git a/var/Widget/Base/Contents.php b/var/Widget/Base/Contents.php index 6dca0b12..8e155f4d 100644 --- a/var/Widget/Base/Contents.php +++ b/var/Widget/Base/Contents.php @@ -240,8 +240,7 @@ class Contents extends Base implements QueryInterface /** 更新缩略名 */ if ($updateRows > 0 && isset($rows['slug'])) { - $this->applySlug(!isset($rows['slug']) || strlen($rows['slug']) === 0 - ? null : $rows['slug'], $updateCondition); + $this->applySlug(strlen($rows['slug']) === 0 ? null : $rows['slug'], $updateCondition); } return $updateRows; @@ -312,7 +311,7 @@ class Contents extends Base implements QueryInterface continue; } - $isFieldReadOnly = Contents::pluginHandle()->trigger($plugged)->isFieldReadOnly($name); + $isFieldReadOnly = Contents::pluginHandle()->trigger($plugged)->call('isFieldReadOnly', $name); if ($plugged && $isFieldReadOnly) { continue; } @@ -403,7 +402,6 @@ class Contents extends Base implements QueryInterface $exist = $this->db->fetchRow($this->db->select('type')->from('table.fields') ->where('cid = ? AND name = ?', $cid, $name)); - $value = intval($value); if (empty($exist)) { return $this->db->query($this->db->insert('table.fields') @@ -600,7 +598,7 @@ class Contents extends Base implements QueryInterface $value['hidden'] = true; } - $value = Contents::pluginHandle()->filter($value, $this); + $value = Contents::pluginHandle()->call('filter', $value, $this); /** 如果访问权限被禁止 */ if ($value['hidden']) { @@ -662,7 +660,7 @@ class Contents extends Base implements QueryInterface */ public function title(int $length = 0, string $trim = '...') { - $title = Contents::pluginHandle()->trigger($plugged)->title($this->title, $this); + $title = Contents::pluginHandle()->trigger($plugged)->call('title', $this->title, $this); if (!$plugged) { echo $length > 0 ? Common::subStr($this->title, 0, $length, $trim) : $this->title; } else { @@ -747,7 +745,7 @@ class Contents extends Base implements QueryInterface * @param string $split 多个分类之间分隔符 * @param boolean $link 是否输出链接 * @param string|null $default 如果没有则输出 - * @throws \Typecho\Widget\Exception + * @throws Widget\Exception */ public function directory(string $split = '/', bool $link = true, ?string $default = null) { @@ -891,7 +889,7 @@ class Contents extends Base implements QueryInterface return $this->text; } - $content = Contents::pluginHandle()->trigger($plugged)->excerpt($this->text, $this); + $content = Contents::pluginHandle()->trigger($plugged)->call('excerpt', $this->text, $this); if (!$plugged) { $content = $this->isMarkdown ? $this->markdown($content) : $this->autoP($content); @@ -900,7 +898,7 @@ class Contents extends Base implements QueryInterface $contents = explode('<!--more-->', $content); [$excerpt] = $contents; - return Common::fixHtml(Contents::pluginHandle()->excerptEx($excerpt, $this)); + return Common::fixHtml(Contents::pluginHandle()->call('excerptEx', $excerpt, $this)); } /** @@ -912,7 +910,7 @@ class Contents extends Base implements QueryInterface { $plainText = str_replace("\n", '', trim(strip_tags($this->excerpt))); $plainText = $plainText ?: $this->title; - return Common::subStr($plainText, 0, 100, '...'); + return Common::subStr($plainText, 0, 100); } /** @@ -923,7 +921,7 @@ class Contents extends Base implements QueryInterface */ public function markdown(?string $text): ?string { - $html = Contents::pluginHandle()->trigger($parsed)->markdown($text); + $html = Contents::pluginHandle()->trigger($parsed)->call('markdown', $text); if (!$parsed) { $html = Markdown::convert($text); @@ -940,7 +938,7 @@ class Contents extends Base implements QueryInterface */ public function autoP(?string $text): ?string { - $html = Contents::pluginHandle()->trigger($parsed)->autoP($text); + $html = Contents::pluginHandle()->trigger($parsed)->call('autoP', $text); if (!$parsed && $text) { static $parser; @@ -966,14 +964,14 @@ class Contents extends Base implements QueryInterface return $this->text; } - $content = Contents::pluginHandle()->trigger($plugged)->content($this->text, $this); + $content = Contents::pluginHandle()->trigger($plugged)->call('content', $this->text, $this); if (!$plugged) { $content = $this->isMarkdown ? $this->markdown($content) : $this->autoP($content); } - return Contents::pluginHandle()->contentEx($content, $this); + return Contents::pluginHandle()->call('contentEx', $content, $this); } /** diff --git a/var/Widget/Base/Metas.php b/var/Widget/Base/Metas.php index 22f2c427..e202922a 100644 --- a/var/Widget/Base/Metas.php +++ b/var/Widget/Base/Metas.php @@ -5,7 +5,6 @@ namespace Widget\Base; use Typecho\Common; use Typecho\Db\Exception; use Typecho\Db\Query; -use Typecho\Plugin; use Typecho\Router; use Widget\Base; @@ -84,8 +83,7 @@ class Metas extends Base implements QueryInterface $value['feedAtomUrl'] = $routeExists ? Router::url($type, $value, $this->options->feedAtomUrl) : '#'; $value['slug'] = $tmpSlug; - $value = Metas::pluginHandle()->filter($value, $this); - return $value; + return Metas::pluginHandle()->call('filter', $value, $this); } /** @@ -142,7 +140,7 @@ class Metas extends Base implements QueryInterface */ public function merge(int $mid, string $type, array $metas) { - $contents = array_column($this->db->fetchAll($this->select('cid') + $contents = array_column($this->db->fetchAll($this->db->select('cid') ->from('table.relationships') ->where('mid = ?', $mid)), 'cid'); diff --git a/var/Widget/Base/Users.php b/var/Widget/Base/Users.php index 6d55b7d3..ffa9ccec 100644 --- a/var/Widget/Base/Users.php +++ b/var/Widget/Base/Users.php @@ -50,8 +50,8 @@ class Users extends Base implements QueryInterface ->where('name = ?', $name) ->limit(1); - if ($this->request->uid) { - $select->where('uid <> ?', $this->request->uid); + if ($this->request->is('uid')) { + $select->where('uid <> ?', $this->request->get('uid')); } $user = $this->db->fetchRow($select); @@ -72,8 +72,8 @@ class Users extends Base implements QueryInterface ->where('mail = ?', $mail) ->limit(1); - if ($this->request->uid) { - $select->where('uid <> ?', $this->request->uid); + if ($this->request->is('uid')) { + $select->where('uid <> ?', $this->request->get('uid')); } $user = $this->db->fetchRow($select); @@ -94,8 +94,8 @@ class Users extends Base implements QueryInterface ->where('screenName = ?', $screenName) ->limit(1); - if ($this->request->uid) { - $select->where('uid <> ?', $this->request->uid); + if ($this->request->is('uid')) { + $select->where('uid <> ?', $this->request->get('uid')); } $user = $this->db->fetchRow($select); @@ -137,8 +137,7 @@ class Users extends Base implements QueryInterface /** ATOM 1.0 */ $value['feedAtomUrl'] = $routeExists ? Router::url('author', $value, $this->options->feedAtomUrl) : '#'; - $value = Users::pluginHandle()->filter($value, $this); - return $value; + return Users::pluginHandle()->call('filter', $value, $this); } /** diff --git a/var/Widget/CommentPage.php b/var/Widget/CommentPage.php index be6bd1b2..9f4c89e1 100644 --- a/var/Widget/CommentPage.php +++ b/var/Widget/CommentPage.php @@ -20,7 +20,7 @@ class CommentPage extends Base implements ActionInterface { $page = abs($this->request->filter('int')->get('commentPage')); - $archive = Router::match($this->request->permalink, [ + $archive = Router::match($this->request->get('permalink'), [ 'checkPermalink' => false, 'commentPage' => $page ]); diff --git a/var/Widget/Comments/Admin.php b/var/Widget/Comments/Admin.php index c83d46af..92d097a8 100644 --- a/var/Widget/Comments/Admin.php +++ b/var/Widget/Comments/Admin.php @@ -31,7 +31,7 @@ class Admin extends Comments * @access private * @var Query */ - private $countSql; + private Query $countSql; /** * 当前页 @@ -39,15 +39,15 @@ class Admin extends Comments * @access private * @var integer */ - private $currentPage; + private int $currentPage; /** * 所有文章个数 * * @access private - * @var integer + * @var integer|null */ - private $total = false; + private ?int $total; /** * 获取菜单标题 @@ -78,18 +78,18 @@ class Admin extends Comments $this->currentPage = $this->request->get('page', 1); /** 过滤标题 */ - if (null != ($keywords = $this->request->filter('search')->keywords)) { + if (null != ($keywords = $this->request->filter('search')->get('keywords'))) { $select->where('table.comments.text LIKE ?', '%' . $keywords . '%'); } /** 如果具有贡献者以上权限,可以查看所有评论,反之只能查看自己的评论 */ if (!$this->user->pass('editor', true)) { $select->where('table.comments.ownerId = ?', $this->user->uid); - } elseif (!isset($this->request->cid)) { - if ('on' == $this->request->__typecho_all_comments) { + } elseif (!$this->request->is('cid')) { + if ($this->request->is('__typecho_all_comments=on')) { Cookie::set('__typecho_all_comments', 'on'); } else { - if ('off' == $this->request->__typecho_all_comments) { + if ($this->request->is('__typecho_all_comments=off')) { Cookie::set('__typecho_all_comments', 'off'); } @@ -99,17 +99,17 @@ class Admin extends Comments } } - if (in_array($this->request->status, ['approved', 'waiting', 'spam'])) { - $select->where('table.comments.status = ?', $this->request->status); - } elseif ('hold' == $this->request->status) { + if (in_array($this->request->get('status'), ['approved', 'waiting', 'spam'])) { + $select->where('table.comments.status = ?', $this->request->get('status')); + } elseif ('hold' == $this->request->get('status')) { $select->where('table.comments.status <> ?', 'approved'); } else { $select->where('table.comments.status = ?', 'approved'); } //增加按文章归档功能 - if (isset($this->request->cid)) { - $select->where('table.comments.cid = ?', $this->request->filter('int')->cid); + if ($this->request->is('cid')) { + $select->where('table.comments.cid = ?', $this->request->filter('int')->get('cid')); } $this->countSql = clone $select; @@ -131,7 +131,7 @@ class Admin extends Comments /** 使用盒状分页 */ $nav = new Box( - false === $this->total ? $this->total = $this->size($this->countSql) : $this->total, + !isset($this->total) ? $this->total = $this->size($this->countSql) : $this->total, $this->currentPage, $this->parameter->pageSize, $query @@ -147,7 +147,7 @@ class Admin extends Comments */ protected function ___parentContent(): ?array { - $cid = isset($this->request->cid) ? $this->request->filter('int')->cid : $this->cid; + $cid = $this->request->is('cid') ? $this->request->filter('int')->get('cid') : $this->cid; return $this->db->fetchRow(Contents::alloc()->select() ->where('table.contents.cid = ?', $cid) ->limit(1), [Contents::alloc(), 'filter']); diff --git a/var/Widget/Comments/Archive.php b/var/Widget/Comments/Archive.php index 520f0792..7ef2b813 100644 --- a/var/Widget/Comments/Archive.php +++ b/var/Widget/Comments/Archive.php @@ -5,6 +5,7 @@ namespace Widget\Comments; use Typecho\Config; use Typecho\Cookie; use Typecho\Router; +use Typecho\Widget\Exception; use Typecho\Widget\Helper\PageNavigator\Box; use Widget\Base\Comments; @@ -28,7 +29,7 @@ class Archive extends Comments * @access private * @var integer */ - private $currentPage; + private int $currentPage; /** * 所有文章个数 @@ -36,7 +37,7 @@ class Archive extends Comments * @access private * @var integer */ - private $total = false; + private int $total = 0; /** * 子父级评论关系 @@ -44,15 +45,15 @@ class Archive extends Comments * @access private * @var array */ - private $threadedComments = []; + private array $threadedComments = []; /** * _singleCommentOptions * - * @var mixed + * @var Config|null * @access private */ - private $singleCommentOptions = null; + private ?Config $singleCommentOptions = null; /** * @param Config $parameter @@ -73,7 +74,7 @@ class Archive extends Comments $args[] = '%d'; } - $num = intval($this->total); + $num = $this->total; echo sprintf($args[$num] ?? array_pop($args), $num); } @@ -101,7 +102,6 @@ class Archive extends Comments $commentsMail, 'waiting' ); - $threadedSelect = null; if ($this->options->commentsShowCommentOnly) { $select->where('table.comments.type = ?', 'comment'); @@ -211,7 +211,7 @@ class Archive extends Comments * @param string $splitWord 分割字符 * @param string|array $template 展现配置信息 * @return void - * @throws \Typecho\Widget\Exception + * @throws Exception */ public function pageNav( string $prev = '«', @@ -238,7 +238,8 @@ class Archive extends Comments $pageRow['permalink'] = $pageRow['pathinfo']; $query = Router::url('comment_page', $pageRow, $this->options->index); - self::pluginHandle()->trigger($hasNav)->pageNav( + self::pluginHandle()->trigger($hasNav)->call( + 'pageNav', $this->currentPage, $this->total, $this->options->commentsPageSize, @@ -286,7 +287,7 @@ class Archive extends Comments 'avatarSize' => 32, 'defaultAvatar' => null ]); - self::pluginHandle()->trigger($plugged)->listComments($this->singleCommentOptions, $this); + self::pluginHandle()->trigger($plugged)->call('listComments', $this->singleCommentOptions, $this); if (!$plugged) { if ($this->have()) { @@ -304,11 +305,12 @@ class Archive extends Comments /** * 评论回调函数 */ - private function threadedCommentsCallback() + private function threadedCommentsCallback(): void { $singleCommentOptions = $this->singleCommentOptions; if (function_exists('threadedComments')) { - return threadedComments($this, $singleCommentOptions); + threadedComments($this, $singleCommentOptions); + return; } $commentClass = ''; @@ -403,7 +405,7 @@ class Archive extends Comments { if ($this->options->commentsThreaded && !$this->isTopLevel && $this->parameter->allowComment) { $word = empty($word) ? _t('回复') : $word; - self::pluginHandle()->trigger($plugged)->reply($word, $this); + self::pluginHandle()->trigger($plugged)->call('reply', $word, $this); if (!$plugged) { echo '<a href="' . substr($this->permalink, 0, - strlen($this->theId) - 1) . '?replyTo=' . $this->coid . @@ -449,10 +451,10 @@ class Archive extends Comments { if ($this->options->commentsThreaded) { $word = empty($word) ? _t('取消回复') : $word; - self::pluginHandle()->trigger($plugged)->cancelReply($word, $this); + self::pluginHandle()->trigger($plugged)->call('cancelReply', $word, $this); if (!$plugged) { - $replyId = $this->request->filter('int')->replyTo; + $replyId = $this->request->filter('int')->get('replyTo'); echo '<a id="cancel-comment-reply-link" href="' . $this->parameter->parentContent['permalink'] . '#' . $this->parameter->respondId . '" rel="nofollow"' . ($replyId ? '' : ' style="display:none"') . ' onclick="return TypechoComment.cancelReply();">' . $word . '</a>'; } diff --git a/var/Widget/Comments/Edit.php b/var/Widget/Comments/Edit.php index a21fb950..b8dbc8d1 100644 --- a/var/Widget/Comments/Edit.php +++ b/var/Widget/Comments/Edit.php @@ -55,14 +55,14 @@ class Edit extends Comments implements ActionInterface * @return boolean * @throws Exception */ - private function mark($coid, $status) + private function mark(int $coid, string $status): bool { $comment = $this->db->fetchRow($this->select() ->where('coid = ?', $coid)->limit(1), [$this, 'push']); if ($comment && $this->commentIsWriteable()) { /** 增加评论编辑插件接口 */ - self::pluginHandle()->mark($comment, $this, $status); + self::pluginHandle()->call('mark', $comment, $this, $status); /** 不必更新的情况 */ if ($status == $comment['status']) { @@ -158,7 +158,7 @@ class Edit extends Comments implements ActionInterface ->where('coid = ?', $coid)->limit(1), [$this, 'push']); if ($comment && $this->commentIsWriteable()) { - self::pluginHandle()->delete($comment, $this); + self::pluginHandle()->call('delete', $comment, $this); /** 删除评论 */ $this->db->query($this->db->delete('table.comments')->where('coid = ?', $coid)); @@ -169,7 +169,7 @@ class Edit extends Comments implements ActionInterface ->expression('commentsNum', 'commentsNum - 1')->where('cid = ?', $comment['cid'])); } - self::pluginHandle()->finishDelete($comment, $this); + self::pluginHandle()->call('finishDelete', $comment, $this); $deleteRows++; } @@ -208,12 +208,12 @@ class Edit extends Comments implements ActionInterface public function deleteSpamComment() { $deleteQuery = $this->db->delete('table.comments')->where('status = ?', 'spam'); - if (!$this->request->__typecho_all_comments || !$this->user->pass('editor', true)) { + if (!$this->request->is('__typecho_all_comments=on') || !$this->user->pass('editor', true)) { $deleteQuery->where('ownerId = ?', $this->user->uid); } - if (isset($this->request->cid)) { - $deleteQuery->where('cid = ?', $this->request->cid); + if ($this->request->is('cid')) { + $deleteQuery->where('cid = ?', $this->request->get('cid')); } $deleteRows = $this->db->query($deleteQuery); @@ -235,7 +235,7 @@ class Edit extends Comments implements ActionInterface */ public function getComment() { - $coid = $this->request->filter('int')->coid; + $coid = $this->request->filter('int')->get('coid'); $comment = $this->db->fetchRow($this->select() ->where('coid = ?', $coid)->limit(1), [$this, 'push']); @@ -260,22 +260,22 @@ class Edit extends Comments implements ActionInterface */ public function editComment(): bool { - $coid = $this->request->filter('int')->coid; + $coid = $this->request->filter('int')->get('coid'); $commentSelect = $this->db->fetchRow($this->select() ->where('coid = ?', $coid)->limit(1), [$this, 'push']); if ($commentSelect && $this->commentIsWriteable()) { - $comment['text'] = $this->request->text; - $comment['author'] = $this->request->filter('strip_tags', 'trim', 'xss')->author; - $comment['mail'] = $this->request->filter('strip_tags', 'trim', 'xss')->mail; - $comment['url'] = $this->request->filter('url')->url; + $comment['text'] = $this->request->get('text'); + $comment['author'] = $this->request->filter('strip_tags', 'trim', 'xss')->get('author'); + $comment['mail'] = $this->request->filter('strip_tags', 'trim', 'xss')->get('mail'); + $comment['url'] = $this->request->filter('url')->get('url'); if ($this->request->is('created')) { - $comment['created'] = $this->request->filter('int')->created; + $comment['created'] = $this->request->filter('int')->get('created'); } /** 评论插件接口 */ - $comment = self::pluginHandle()->edit($comment, $this); + $comment = self::pluginHandle()->call('edit', $comment, $this); /** 更新评论 */ $this->update($comment, $this->db->sql()->where('coid = ?', $coid)); @@ -285,7 +285,7 @@ class Edit extends Comments implements ActionInterface $updatedComment['content'] = $this->content; /** 评论插件接口 */ - self::pluginHandle()->finishEdit($this); + self::pluginHandle()->call('finishEdit', $this); $this->response->throwJson([ 'success' => 1, @@ -306,7 +306,7 @@ class Edit extends Comments implements ActionInterface */ public function replyComment() { - $coid = $this->request->filter('int')->coid; + $coid = $this->request->filter('int')->get('coid'); $commentSelect = $this->db->fetchRow($this->select() ->where('coid = ?', $coid)->limit(1), [$this, 'push']); @@ -323,12 +323,12 @@ class Edit extends Comments implements ActionInterface 'mail' => $this->user->mail, 'url' => $this->user->url, 'parent' => $coid, - 'text' => $this->request->text, + 'text' => $this->request->get('text'), 'status' => 'approved' ]; /** 评论插件接口 */ - self::pluginHandle()->comment($comment, $this); + self::pluginHandle()->call('comment', $comment, $this); /** 回复评论 */ $commentId = $this->insert($comment); @@ -338,7 +338,7 @@ class Edit extends Comments implements ActionInterface $insertComment['content'] = $this->content; /** 评论完成接口 */ - self::pluginHandle()->finishComment($this); + self::pluginHandle()->call('finishComment', $this); $this->response->throwJson([ 'success' => 1, diff --git a/var/Widget/Comments/Ping.php b/var/Widget/Comments/Ping.php index 4866bbf9..446a8feb 100644 --- a/var/Widget/Comments/Ping.php +++ b/var/Widget/Comments/Ping.php @@ -26,7 +26,7 @@ class Ping extends Comments * @var boolean * @access private */ - private $customSinglePingCallback = false; + private bool $customSinglePingCallback = false; /** * @param Config $parameter @@ -111,10 +111,11 @@ class Ping extends Comments * * @param string $singlePingOptions 单个回响自定义选项 */ - private function singlePingCallback(string $singlePingOptions) + private function singlePingCallback(string $singlePingOptions): void { if ($this->customSinglePingCallback) { - return singlePing($this, $singlePingOptions); + singlePing($this, $singlePingOptions); + return; } ?> diff --git a/var/Widget/Contents/Attachment/Admin.php b/var/Widget/Contents/Attachment/Admin.php index 6b7008ad..bc87634a 100644 --- a/var/Widget/Contents/Attachment/Admin.php +++ b/var/Widget/Contents/Attachment/Admin.php @@ -28,21 +28,21 @@ class Admin extends Contents * * @var Query */ - private $countSql; + private Query $countSql; /** * 所有文章个数 * - * @var integer + * @var integer|null */ - private $total = false; + private ?int $total; /** * 当前页 * * @var integer */ - private $currentPage; + private int $currentPage; /** * 执行函数 @@ -64,7 +64,7 @@ class Admin extends Contents } /** 过滤标题 */ - if (null != ($keywords = $this->request->filter('search')->keywords)) { + if (null != ($keywords = $this->request->filter('search')->get('keywords'))) { $args = []; $keywordsList = explode(' ', $keywords); $args[] = implode(' OR ', array_fill(0, count($keywordsList), 'table.contents.title LIKE ?')); @@ -98,7 +98,7 @@ class Admin extends Contents /** 使用盒状分页 */ $nav = new Box( - false === $this->total ? $this->total = $this->size($this->countSql) : $this->total, + !isset($this->total) ? $this->total = $this->size($this->countSql) : $this->total, $this->currentPage, $this->parameter->pageSize, $query diff --git a/var/Widget/Contents/Attachment/Edit.php b/var/Widget/Contents/Attachment/Edit.php index 33a556b3..197a7b68 100644 --- a/var/Widget/Contents/Attachment/Edit.php +++ b/var/Widget/Contents/Attachment/Edit.php @@ -40,7 +40,7 @@ class Edit extends PostEdit implements ActionInterface if (!empty($this->request->cid)) { $this->db->fetchRow($this->select() ->where('table.contents.type = ?', 'attachment') - ->where('table.contents.cid = ?', $this->request->filter('int')->cid) + ->where('table.contents.cid = ?', $this->request->filter('int')->get('cid')) ->limit(1), [$this, 'push']); if (!$this->have()) { @@ -84,8 +84,8 @@ class Edit extends PostEdit implements ActionInterface ->where('slug = ?', Common::slugName($slug)) ->limit(1); - if ($this->request->cid) { - $select->where('cid <> ?', $this->request->cid); + if ($this->request->is('cid')) { + $select->where('cid <> ?', $this->request->get('cid')); } $attachment = $this->db->fetchRow($select); @@ -100,7 +100,7 @@ class Edit extends PostEdit implements ActionInterface */ public function updateAttachment() { - if ($this->form('update')->validate()) { + if ($this->form()->validate()) { $this->response->goBack(); } @@ -115,7 +115,7 @@ class Edit extends PostEdit implements ActionInterface $content['description'] = $input['description']; $attachment['text'] = serialize($content); - $cid = $this->request->filter('int')->cid; + $cid = $this->request->filter('int')->get('cid'); /** 更新数据 */ $updateRows = $this->update($attachment, $this->db->sql()->where('cid = ?', $cid)); @@ -231,7 +231,7 @@ class Edit extends PostEdit implements ActionInterface foreach ($posts as $post) { // 删除插件接口 - self::pluginHandle()->delete($post, $this); + self::pluginHandle()->call('delete', $post, $this); $condition = $this->db->sql()->where('cid = ?', $post); $row = $this->db->fetchRow($this->select() @@ -248,7 +248,7 @@ class Edit extends PostEdit implements ActionInterface ->where('cid = ?', $post)); // 完成删除插件接口 - self::pluginHandle()->finishDelete($post, $this); + self::pluginHandle()->call('finishDelete', $post, $this); $deleteCount++; } @@ -285,7 +285,7 @@ class Edit extends PostEdit implements ActionInterface $deleteCount = 0; do { - $posts = array_column($this->db->fetchAll($this->select('cid') + $posts = array_column($this->db->fetchAll($this->db->select('cid') ->from('table.contents') ->where('type = ? AND parent = ?', 'attachment', 0) ->page($page, 100)), 'cid'); @@ -293,7 +293,7 @@ class Edit extends PostEdit implements ActionInterface foreach ($posts as $post) { // 删除插件接口 - self::pluginHandle()->delete($post, $this); + self::pluginHandle()->call('delete', $post, $this); $condition = $this->db->sql()->where('cid = ?', $post); $row = $this->db->fetchRow($this->select() @@ -309,10 +309,8 @@ class Edit extends PostEdit implements ActionInterface $this->db->query($this->db->delete('table.comments') ->where('cid = ?', $post)); - $status = $this->status; - // 完成删除插件接口 - self::pluginHandle()->finishDelete($post, $this); + self::pluginHandle()->call('finishDelete', $post, $this); $deleteCount++; } diff --git a/var/Widget/Contents/Attachment/Related.php b/var/Widget/Contents/Attachment/Related.php index 2c0dca71..2d269605 100644 --- a/var/Widget/Contents/Attachment/Related.php +++ b/var/Widget/Contents/Attachment/Related.php @@ -42,7 +42,7 @@ class Related extends Contents $select->where('table.contents.parent = ?', $this->parameter->parentId); /** 提交查询 */ - $select->order('table.contents.created', Db::SORT_ASC); + $select->order('table.contents.created'); if ($this->parameter->limit > 0) { $select->limit($this->parameter->limit); diff --git a/var/Widget/Contents/Attachment/Unattached.php b/var/Widget/Contents/Attachment/Unattached.php index 42ce5608..c90fbb57 100644 --- a/var/Widget/Contents/Attachment/Unattached.php +++ b/var/Widget/Contents/Attachment/Unattached.php @@ -42,7 +42,7 @@ class Unattached extends Contents (table.contents.parent = 0 OR table.contents.parent IS NULL)', 'attachment'); /** 加上对用户的判断 */ - $this->where('table.contents.authorId = ?', $this->user->uid); + $select->where('table.contents.authorId = ?', $this->user->uid); /** 提交查询 */ $select->order('table.contents.created', Db::SORT_DESC); diff --git a/var/Widget/Contents/Page/Admin.php b/var/Widget/Contents/Page/Admin.php index ed2fd82c..f55a334a 100644 --- a/var/Widget/Contents/Page/Admin.php +++ b/var/Widget/Contents/Page/Admin.php @@ -38,7 +38,7 @@ class Admin extends PostAdmin ); /** 过滤标题 */ - if (null != ($keywords = $this->request->keywords)) { + if (null != ($keywords = $this->request->get('keywords'))) { $args = []; $keywordsList = explode(' ', $keywords); $args[] = implode(' OR ', array_fill(0, count($keywordsList), 'table.contents.title LIKE ?')); @@ -51,7 +51,7 @@ class Admin extends PostAdmin } /** 提交查询 */ - $select->order('table.contents.order', Db::SORT_ASC); + $select->order('table.contents.order'); $this->db->fetchAll($select, [$this, 'push']); } diff --git a/var/Widget/Contents/Page/Edit.php b/var/Widget/Contents/Page/Edit.php index 0373a83c..4636d6ca 100644 --- a/var/Widget/Contents/Page/Edit.php +++ b/var/Widget/Contents/Page/Edit.php @@ -31,7 +31,7 @@ class Edit extends PostEdit implements ActionInterface * @var string * @access protected */ - protected $themeCustomFieldsHook = 'themePageFields'; + protected string $themeCustomFieldsHook = 'themePageFields'; /** * 执行函数 @@ -47,10 +47,10 @@ class Edit extends PostEdit implements ActionInterface $this->user->pass('editor'); /** 获取文章内容 */ - if (!empty($this->request->cid)) { + if ($this->request->is('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) + ->where('table.contents.cid = ?', $this->request->filter('int')->get('cid')) ->limit(1), [$this, 'push']); if ('page_draft' == $this->status && $this->parent) { @@ -85,11 +85,11 @@ class Edit extends PostEdit implements ActionInterface $contents['created'] = $this->getCreated(); $contents['visibility'] = ('hidden' == $contents['visibility'] ? 'hidden' : 'publish'); - if ($this->request->markdown && $this->options->markdown) { + if ($this->request->is('markdown=1') && $this->options->markdown) { $contents['text'] = '<!--markdown-->' . $contents['text']; } - $contents = self::pluginHandle()->write($contents, $this); + $contents = self::pluginHandle()->call('write', $contents, $this); if ($this->request->is('do=publish')) { /** 重新发布已经存在的文章 */ @@ -97,7 +97,7 @@ class Edit extends PostEdit implements ActionInterface $this->publish($contents); // 完成发布插件接口 - self::pluginHandle()->finishPublish($contents, $this); + self::pluginHandle()->call('finishPublish', $contents, $this); /** 发送ping */ Service::alloc()->sendPing($this); @@ -119,7 +119,7 @@ class Edit extends PostEdit implements ActionInterface $this->save($contents); // 完成发布插件接口 - self::pluginHandle()->finishSave($contents, $this); + self::pluginHandle()->call('finishSave', $contents, $this); /** 设置高亮 */ Notice::alloc()->highlight($this->cid); @@ -164,7 +164,7 @@ class Edit extends PostEdit implements ActionInterface foreach ($pages as $page) { // 标记插件接口 - self::pluginHandle()->mark($status, $page, $this); + self::pluginHandle()->call('mark', $status, $page, $this); $condition = $this->db->sql()->where('cid = ?', $page); if ($this->db->query($condition->update('table.contents')->rows(['status' => $status]))) { @@ -180,7 +180,7 @@ class Edit extends PostEdit implements ActionInterface } // 完成标记插件接口 - self::pluginHandle()->finishMark($status, $page, $this); + self::pluginHandle()->call('finishMark', $status, $page, $this); $markCount++; } @@ -211,7 +211,7 @@ class Edit extends PostEdit implements ActionInterface foreach ($pages as $page) { // 删除插件接口 - self::pluginHandle()->delete($page, $this); + self::pluginHandle()->call('delete', $page, $this); if ($this->delete($this->db->sql()->where('cid = ?', $page))) { /** 删除评论 */ @@ -243,7 +243,7 @@ class Edit extends PostEdit implements ActionInterface } // 完成删除插件接口 - self::pluginHandle()->finishDelete($page, $this); + self::pluginHandle()->call('finishDelete', $page, $this); $deleteCount++; } diff --git a/var/Widget/Contents/Page/Rows.php b/var/Widget/Contents/Page/Rows.php index e716ae8d..1f239317 100644 --- a/var/Widget/Contents/Page/Rows.php +++ b/var/Widget/Contents/Page/Rows.php @@ -32,7 +32,7 @@ class Rows extends Contents $select = $this->select()->where('table.contents.type = ?', 'page') ->where('table.contents.status = ?', 'publish') ->where('table.contents.created < ?', $this->options->time) - ->order('table.contents.order', Db::SORT_ASC); + ->order('table.contents.order'); //去掉自定义首页 $frontPage = explode(':', $this->options->frontPage); diff --git a/var/Widget/Contents/Post/Admin.php b/var/Widget/Contents/Post/Admin.php index 51ab899d..c97f74c3 100644 --- a/var/Widget/Contents/Post/Admin.php +++ b/var/Widget/Contents/Post/Admin.php @@ -29,21 +29,21 @@ class Admin extends Contents * * @var Query */ - private $countSql; + private Query $countSql; /** * 所有文章个数 * - * @var integer + * @var integer|null */ - private $total = false; + private ?int $total; /** * 当前页 * * @var integer */ - private $currentPage; + private int $currentPage; /** * 获取菜单标题 @@ -53,9 +53,9 @@ class Admin extends Contents */ public function getMenuTitle(): string { - if (isset($this->request->uid)) { + if ($this->request->is('uid')) { return _t('%s的文章', $this->db->fetchObject($this->db->select('screenName')->from('table.users') - ->where('uid = ?', $this->request->filter('int')->uid))->screenName); + ->where('uid = ?', $this->request->filter('int')->get('uid')))->screenName); } throw new Exception(_t('用户不存在'), 404); @@ -100,24 +100,24 @@ class Admin extends Contents if (!$this->user->pass('editor', true)) { $select->where('table.contents.authorId = ?', $this->user->uid); } else { - if ('on' == $this->request->__typecho_all_posts) { + if ($this->request->is('__typecho_all_posts=on')) { Cookie::set('__typecho_all_posts', 'on'); } else { - if ('off' == $this->request->__typecho_all_posts) { + if ($this->request->is('__typecho_all_posts=off')) { Cookie::set('__typecho_all_posts', 'off'); } if ('on' != Cookie::get('__typecho_all_posts')) { - $select->where('table.contents.authorId = ?', isset($this->request->uid) ? - $this->request->filter('int')->uid : $this->user->uid); + $select->where('table.contents.authorId = ?', + $this->request->filter('int')->get('uid', $this->user->uid)); } } } /** 按状态查询 */ - if ('draft' == $this->request->status) { + if ($this->request->is('status=draft')) { $select->where('table.contents.type = ?', 'post_draft'); - } elseif ('waiting' == $this->request->status) { + } elseif ($this->request->is('status=waiting')) { $select->where( '(table.contents.type = ? OR table.contents.type = ?) AND table.contents.status = ?', 'post', @@ -134,13 +134,13 @@ class Admin extends Contents } /** 过滤分类 */ - if (null != ($category = $this->request->category)) { + if (null != ($category = $this->request->get('category'))) { $select->join('table.relationships', 'table.contents.cid = table.relationships.cid') ->where('table.relationships.mid = ?', $category); } /** 过滤标题 */ - if (null != ($keywords = $this->request->filter('search')->keywords)) { + if (null != ($keywords = $this->request->filter('search')->get('keywords'))) { $args = []; $keywordsList = explode(' ', $keywords); $args[] = implode(' OR ', array_fill(0, count($keywordsList), 'table.contents.title LIKE ?')); @@ -174,7 +174,7 @@ class Admin extends Contents /** 使用盒状分页 */ $nav = new Box( - false === $this->total ? $this->total = $this->size($this->countSql) : $this->total, + !isset($this->total) ? $this->total = $this->size($this->countSql) : $this->total, $this->currentPage, $this->parameter->pageSize, $query diff --git a/var/Widget/Contents/Post/Edit.php b/var/Widget/Contents/Post/Edit.php index 1679d7c4..1920e53b 100644 --- a/var/Widget/Contents/Post/Edit.php +++ b/var/Widget/Contents/Post/Edit.php @@ -32,7 +32,7 @@ class Edit extends Contents implements ActionInterface * * @var string */ - protected $themeCustomFieldsHook = 'themePostFields'; + protected string $themeCustomFieldsHook = 'themePostFields'; /** * 执行函数 @@ -45,10 +45,10 @@ class Edit extends Contents implements ActionInterface $this->user->pass('contributor'); /** 获取文章内容 */ - if (!empty($this->request->cid)) { + if ($this->request->is('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) + ->where('table.contents.cid = ?', $this->request->filter('int')->get('cid')) ->limit(1), [$this, 'push']); if ('post_draft' == $this->type && $this->parent) { @@ -170,7 +170,7 @@ class Edit extends Contents implements ActionInterface foreach ($rows as $row) { $isFieldReadOnly = Contents::pluginHandle() - ->trigger($plugged)->isFieldReadOnly($row['name']); + ->trigger($plugged)->call('isFieldReadOnly', $row['name']); if ($plugged && $isFieldReadOnly) { continue; @@ -201,7 +201,7 @@ class Edit extends Contents implements ActionInterface $fields = $this->fields; } - self::pluginHandle()->getDefaultFieldItems($layout); + self::pluginHandle()->call('getDefaultFieldItems', $layout); if (file_exists($configFile)) { require_once $configFile; @@ -221,7 +221,7 @@ class Edit extends Contents implements ActionInterface $name = $item->input->getAttribute('name'); $isFieldReadOnly = Contents::pluginHandle() - ->trigger($plugged)->isFieldReadOnly($name); + ->trigger($plugged)->call('isFieldReadOnly', $name); if ($plugged && $isFieldReadOnly) { continue; } @@ -279,11 +279,11 @@ class Edit extends Contents implements ActionInterface $contents['title'] = $this->request->get('title', _t('未命名文档')); $contents['created'] = $this->getCreated(); - if ($this->request->markdown && $this->options->markdown) { + if ($this->request->is('markdown=1') && $this->options->markdown) { $contents['text'] = '<!--markdown-->' . $contents['text']; } - $contents = self::pluginHandle()->write($contents, $this); + $contents = self::pluginHandle()->call('write', $contents, $this); if ($this->request->is('do=publish')) { /** 重新发布已经存在的文章 */ @@ -291,10 +291,10 @@ class Edit extends Contents implements ActionInterface $this->publish($contents); // 完成发布插件接口 - self::pluginHandle()->finishPublish($contents, $this); + self::pluginHandle()->call('finishPublish', $contents, $this); /** 发送ping */ - $trackback = array_filter(array_unique(preg_split("/(\r|\n|\r\n)/", trim($this->request->trackback)))); + $trackback = array_filter(array_unique(preg_split("/(\r|\n|\r\n)/", trim($this->request->get('trackback'))))); Service::alloc()->sendPing($this, $trackback); /** 设置提示信息 */ @@ -316,7 +316,7 @@ class Edit extends Contents implements ActionInterface $this->save($contents); // 完成保存插件接口 - self::pluginHandle()->finishSave($contents, $this); + self::pluginHandle()->call('finishSave', $contents, $this); /** 设置高亮 */ Notice::alloc()->highlight($this->cid); @@ -347,24 +347,24 @@ class Edit extends Contents implements ActionInterface protected function getCreated(): int { $created = $this->options->time; - if (!empty($this->request->created)) { - $created = $this->request->created; - } elseif (!empty($this->request->date)) { - $dstOffset = !empty($this->request->dst) ? $this->request->dst : 0; + if ($this->request->is('created')) { + $created = $this->request->get('created'); + } elseif ($this->request->is('date')) { + $dstOffset = $this->request->get('dst', 0); $timezoneSymbol = $this->options->timezone >= 0 ? '+' : '-'; $timezoneOffset = abs($this->options->timezone); $timezone = $timezoneSymbol . str_pad($timezoneOffset / 3600, 2, '0', STR_PAD_LEFT) . ':00'; - [$date, $time] = explode(' ', $this->request->date); + [$date, $time] = explode(' ', $this->request->get('date')); $created = strtotime("{$date}T{$time}{$timezone}") - $dstOffset; - } elseif (!empty($this->request->year) && !empty($this->request->month) && !empty($this->request->day)) { - $second = intval($this->request->get('sec', date('s'))); - $min = intval($this->request->get('min', date('i'))); - $hour = intval($this->request->get('hour', date('H'))); + } elseif ($this->request->is('year&month&day')) { + $second = $this->request->filter('int')->get('sec', date('s')); + $min = $this->request->filter('int')->get('min', date('i')); + $hour = $this->request->filter('int')->get('hour', date('H')); - $year = intval($this->request->year); - $month = intval($this->request->month); - $day = intval($this->request->day); + $year = $this->request->filter('int')->get('year'); + $month = $this->request->filter('int')->get('month'); + $day = $this->request->filter('int')->get('day'); $created = mktime($hour, $min, $second, $month, $day, $year) - $this->options->timezone + $this->options->serverTimezone; @@ -388,24 +388,7 @@ class Edit extends Contents implements ActionInterface protected function publish(array $contents) { /** 发布内容, 检查是否具有直接发布的权限 */ - if ($this->user->pass('editor', true)) { - if (empty($contents['visibility'])) { - $contents['status'] = 'publish'; - } elseif ( - !in_array($contents['visibility'], ['private', 'waiting', 'publish', 'hidden']) - ) { - if (empty($contents['password']) || 'password' != $contents['visibility']) { - $contents['password'] = ''; - } - $contents['status'] = 'publish'; - } else { - $contents['status'] = $contents['visibility']; - $contents['password'] = ''; - } - } else { - $contents['status'] = 'waiting'; - $contents['password'] = ''; - } + $this->checkStatus($contents); /** 真实的内容id */ $realId = 0; @@ -468,7 +451,7 @@ class Edit extends Contents implements ActionInterface * @param integer $cid 草稿id * @throws DbException */ - protected function deleteDraft($cid) + protected function deleteDraft(int $cid) { $this->delete($this->db->sql()->where('cid = ?', $cid)); @@ -690,7 +673,7 @@ class Edit extends Contents implements ActionInterface $cid, 'post', $status, - 'on' == $this->request->__typecho_all_posts ? 0 : $this->user->uid + $this->request->is('__typecho_all_posts=on') ? 0 : $this->user->uid ); } @@ -703,24 +686,7 @@ class Edit extends Contents implements ActionInterface protected function save(array $contents) { /** 发布内容, 检查是否具有直接发布的权限 */ - if ($this->user->pass('editor', true)) { - if (empty($contents['visibility'])) { - $contents['status'] = 'publish'; - } elseif ( - !in_array($contents['visibility'], ['private', 'waiting', 'publish', 'hidden']) - ) { - if (empty($contents['password']) || 'password' != $contents['visibility']) { - $contents['password'] = ''; - } - $contents['status'] = 'publish'; - } else { - $contents['status'] = $contents['visibility']; - $contents['password'] = ''; - } - } else { - $contents['status'] = 'waiting'; - $contents['password'] = ''; - } + $this->checkStatus($contents); /** 真实的内容id */ $realId = 0; @@ -792,7 +758,7 @@ class Edit extends Contents implements ActionInterface foreach ($posts as $post) { // 标记插件接口 - self::pluginHandle()->mark($status, $post, $this); + self::pluginHandle()->call('mark', $status, $post, $this); $condition = $this->db->sql()->where('cid = ?', $post); $postObject = $this->db->fetchObject($this->db->select('status', 'type') @@ -837,7 +803,7 @@ class Edit extends Contents implements ActionInterface } // 完成标记插件接口 - self::pluginHandle()->finishMark($status, $post, $this); + self::pluginHandle()->call('finishMark', $status, $post, $this); $markCount++; } @@ -868,7 +834,7 @@ class Edit extends Contents implements ActionInterface foreach ($posts as $post) { // 删除插件接口 - self::pluginHandle()->delete($post, $this); + self::pluginHandle()->call('delete', $post, $this); $condition = $this->db->sql()->where('cid = ?', $post); $postObject = $this->db->fetchObject($this->db->select('status', 'type') @@ -906,7 +872,7 @@ class Edit extends Contents implements ActionInterface } // 完成删除插件接口 - self::pluginHandle()->finishDelete($post, $this); + self::pluginHandle()->call('finishDelete', $post, $this); $deleteCount++; } @@ -935,7 +901,7 @@ class Edit extends Contents implements ActionInterface * @param integer $cid 内容id * @throws DbException */ - protected function unAttach($cid) + protected function unAttach(int $cid) { $this->db->query($this->db->update('table.contents')->rows(['parent' => 0, 'status' => 'publish']) ->where('parent = ? AND type = ?', $cid, 'attachment')); @@ -1044,4 +1010,30 @@ class Edit extends Contents implements ActionInterface return null; } + + /** + * @param array $contents + * @return void + */ + private function checkStatus(array &$contents) + { + if ($this->user->pass('editor', true)) { + if (empty($contents['visibility'])) { + $contents['status'] = 'publish'; + } elseif ( + !in_array($contents['visibility'], ['private', 'waiting', 'publish', 'hidden']) + ) { + if (empty($contents['password']) || 'password' != $contents['visibility']) { + $contents['password'] = ''; + } + $contents['status'] = 'publish'; + } else { + $contents['status'] = $contents['visibility']; + $contents['password'] = ''; + } + } else { + $contents['status'] = 'waiting'; + $contents['password'] = ''; + } + } } diff --git a/var/Widget/Feed.php b/var/Widget/Feed.php index 4adb12c1..5e52c0da 100644 --- a/var/Widget/Feed.php +++ b/var/Widget/Feed.php @@ -23,7 +23,7 @@ class Feed extends Contents /** * @var FeedGenerator */ - private $feed; + private FeedGenerator $feed; /** * @param Config $parameter @@ -41,7 +41,7 @@ class Feed extends Contents */ public function execute() { - $feedPath = $this->request->feed; + $feedPath = $this->request->get('feed'); $feedType = FeedGenerator::RSS2; $feedContentType = 'application/rss+xml'; $currentFeedUrl = $this->options->feedUrl; @@ -136,7 +136,11 @@ class Feed extends Contents } while ($comments->next()) { - $suffix = self::pluginHandle()->trigger($plugged)->commentFeedItem($feed->getType(), $comments); + $suffix = self::pluginHandle()->trigger($plugged)->call( + 'commentFeedItem', + $feed->getType(), + $comments + ); if (!$plugged) { $suffix = null; @@ -161,7 +165,7 @@ class Feed extends Contents . ($archive->getArchiveTitle() ? ' - ' . $archive->getArchiveTitle() : '')); while ($archive->next()) { - $suffix = self::pluginHandle()->trigger($plugged)->feedItem($feed->getType(), $archive); + $suffix = self::pluginHandle()->trigger($plugged)->call('feedItem', $feed->getType(), $archive); if (!$plugged) { $suffix = null; diff --git a/var/Widget/Feedback.php b/var/Widget/Feedback.php index cca026df..d3f77e2b 100644 --- a/var/Widget/Feedback.php +++ b/var/Widget/Feedback.php @@ -37,7 +37,7 @@ class Feedback extends Comments implements ActionInterface * * @param string $userName 用户名 * @return bool - * @throws \Typecho\Db\Exception + * @throws Db\Exception */ public function requireUserLogin(string $userName): bool { @@ -63,8 +63,8 @@ class Feedback extends Comments implements ActionInterface public function action() { /** 回调方法 */ - $callback = $this->request->type; - $this->content = Router::match($this->request->permalink); + $callback = $this->request->get('type'); + $this->content = Router::match($this->request->get('permalink')); /** 判断内容是否存在 */ if ( @@ -199,20 +199,20 @@ class Feedback extends Comments implements ActionInterface $validator->addRule('text', 'required', _t('必须填写评论内容')); - $comment['text'] = $this->request->text; + $comment['text'] = $this->request->get('text'); /** 对一般匿名访问者,将用户数据保存一个月 */ if (!$this->user->hasLogin()) { /** Anti-XSS */ - $comment['author'] = $this->request->filter('trim')->author; - $comment['mail'] = $this->request->filter('trim')->mail; - $comment['url'] = $this->request->filter('trim', 'url')->url; + $comment['author'] = $this->request->filter('trim')->get('author'); + $comment['mail'] = $this->request->filter('trim')->get('mail'); + $comment['url'] = $this->request->filter('trim', 'url')->get('url'); /** 修正用户提交的url */ if (!empty($comment['url'])) { $urlParams = parse_url($comment['url']); if (!isset($urlParams['scheme'])) { - $comment['url'] = 'http://' . $comment['url']; + $comment['url'] = 'https://' . $comment['url']; } } @@ -255,7 +255,7 @@ class Feedback extends Comments implements ActionInterface /** 生成过滤器 */ try { - $comment = self::pluginHandle()->comment($comment, $this->content); + $comment = self::pluginHandle()->call('comment', $comment, $this->content); } catch (\Typecho\Exception $e) { Cookie::set('__typecho_remember_text', $comment['text']); throw $e; @@ -268,7 +268,7 @@ class Feedback extends Comments implements ActionInterface ->limit(1), [$this, 'push']); /** 评论完成接口 */ - self::pluginHandle()->finishComment($this); + self::pluginHandle()->call('finishComment', $this); $this->response->goBack('#' . $this->theId); } @@ -276,7 +276,7 @@ class Feedback extends Comments implements ActionInterface /** * 引用处理函数 * - * @throws Exception|\Typecho\Db\Exception + * @throws Exception|Db\Exception */ private function trackback() { @@ -304,9 +304,9 @@ class Feedback extends Comments implements ActionInterface 'status' => $this->options->commentsRequireModeration ? 'waiting' : 'approved' ]; - $trackback['author'] = $this->request->filter('trim')->blog_name; - $trackback['url'] = $this->request->filter('trim', 'url')->url; - $trackback['text'] = $this->request->excerpt; + $trackback['author'] = $this->request->filter('trim')->get('blog_name'); + $trackback['url'] = $this->request->filter('trim', 'url')->get('url'); + $trackback['text'] = $this->request->get('excerpt'); //检验格式 $validator = new Validate(); @@ -337,13 +337,13 @@ class Feedback extends Comments implements ActionInterface } /** 生成过滤器 */ - $trackback = self::pluginHandle()->trackback($trackback, $this->content); + $trackback = self::pluginHandle()->call('trackback', $trackback, $this->content); /** 添加引用 */ $this->insert($trackback); /** 评论完成接口 */ - self::pluginHandle()->finishTrackback($this); + self::pluginHandle()->call('finishTrackback', $this); /** 返回正确 */ $this->response->throwXml(['success' => 0, 'message' => 'Trackback has registered.']); diff --git a/var/Widget/Login.php b/var/Widget/Login.php index 860f121e..b7cfbabb 100644 --- a/var/Widget/Login.php +++ b/var/Widget/Login.php @@ -44,7 +44,7 @@ class Login extends Users implements ActionInterface $expire = 30 * 24 * 3600; /** 记住密码状态 */ - if ($this->request->remember) { + if ($this->request->is('remember=1')) { Cookie::set('__typecho_remember_remember', 1, $expire); } elseif (Cookie::get('__typecho_remember_remember')) { Cookie::delete('__typecho_remember_remember'); @@ -52,7 +52,7 @@ class Login extends Users implements ActionInterface /** 截获验证异常 */ if ($error = $validator->run($this->request->from('name', 'password'))) { - Cookie::set('__typecho_remember_name', $this->request->name); + Cookie::set('__typecho_remember_name', $this->request->get('name')); /** 设置提示信息 */ Notice::alloc()->set($error); @@ -61,10 +61,10 @@ class Login extends Users implements ActionInterface /** 开始验证用户 **/ $valid = $this->user->login( - $this->request->name, - $this->request->password, + $this->request->get('name'), + $this->request->get('password'), false, - 1 == $this->request->remember ? $expire : 0 + 1 == $this->request->get('name') ? $expire : 0 ); /** 比对密码 */ @@ -72,23 +72,25 @@ class Login extends Users implements ActionInterface /** 防止穷举,休眠3秒 */ sleep(3); - self::pluginHandle()->loginFail( + self::pluginHandle()->call( + 'loginFailure', $this->user, - $this->request->name, - $this->request->password, - 1 == $this->request->remember + $this->request->get('name'), + $this->request->get('password'), + $this->request->is('remember=1') ); - Cookie::set('__typecho_remember_name', $this->request->name); + Cookie::set('__typecho_remember_name', $this->request->get('name')); Notice::alloc()->set(_t('用户名或密码无效'), 'error'); - $this->response->goBack('?referer=' . urlencode($this->request->referer)); + $this->response->goBack('?referer=' . urlencode($this->request->get('referer'))); } - self::pluginHandle()->loginSucceed( + self::pluginHandle()->call( + 'loginSuccess', $this->user, - $this->request->name, - $this->request->password, - 1 == $this->request->remember + $this->request->get('name'), + $this->request->get('password'), + $this->request->is('remember=1') ); /** 跳转验证后地址 */ diff --git a/var/Widget/Logout.php b/var/Widget/Logout.php index 9017ea6f..f9e1c5c8 100644 --- a/var/Widget/Logout.php +++ b/var/Widget/Logout.php @@ -30,7 +30,7 @@ class Logout extends Users implements ActionInterface $this->security->protect(); $this->user->logout(); - self::pluginHandle()->logout(); + self::pluginHandle()->call('logout'); @session_destroy(); $this->response->goBack(null, $this->options->index); } diff --git a/var/Widget/Menu.php b/var/Widget/Menu.php index e12d6238..d602b2b8 100644 --- a/var/Widget/Menu.php +++ b/var/Widget/Menu.php @@ -30,41 +30,41 @@ class Menu extends Base * 当前菜单标题 * @var string */ - public $title; + public string $title; /** * 当前增加项目链接 - * @var string + * @var string|null */ - public $addLink; + public ?string $addLink; /** * 父菜单列表 * * @var array */ - private $menu = []; + private array $menu = []; /** * 当前父菜单 * * @var integer */ - private $currentParent = 1; + private int $currentParent = 1; /** * 当前子菜单 * * @var integer */ - private $currentChild = 0; + private int $currentChild = 0; /** * 当前页面 * * @var string */ - private $currentUrl; + private string $currentUrl; /** * 执行函数,初始化菜单 diff --git a/var/Widget/Metas/Category/Admin.php b/var/Widget/Metas/Category/Admin.php index ffcdcaa3..f71ee635 100644 --- a/var/Widget/Metas/Category/Admin.php +++ b/var/Widget/Metas/Category/Admin.php @@ -23,10 +23,10 @@ class Admin extends Rows public function execute() { $select = $this->db->select('mid')->from('table.metas')->where('type = ?', 'category'); - $select->where('parent = ?', $this->request->parent ? $this->request->parent : 0); + $select->where('parent = ?', $this->request->get('parent', 0)); $this->stack = $this->getCategories(array_column( - $this->db->fetchAll($select->order('table.metas.order', Db::SORT_ASC)), + $this->db->fetchAll($select->order('table.metas.order')), 'mid' )); } @@ -38,9 +38,9 @@ class Admin extends Rows */ public function backLink() { - if (isset($this->request->parent)) { + if ($this->request->is('parent')) { $category = $this->db->fetchRow($this->select() - ->where('type = ? AND mid = ?', 'category', $this->request->parent)); + ->where('type = ? AND mid = ?', 'category', $this->request->get('parent'))); if (!empty($category)) { $parent = $this->db->fetchRow($this->select() @@ -69,9 +69,9 @@ class Admin extends Rows */ public function getMenuTitle(): ?string { - if (isset($this->request->parent)) { + if ($this->request->is('parent')) { $category = $this->db->fetchRow($this->select() - ->where('type = ? AND mid = ?', 'category', $this->request->parent)); + ->where('type = ? AND mid = ?', 'category', $this->request->get('parent'))); if (!empty($category)) { return _t('管理 %s 的子分类', $category['name']); @@ -90,8 +90,8 @@ class Admin extends Rows */ public function getAddLink(): string { - if (isset($this->request->parent)) { - return 'category.php?parent=' . $this->request->filter('int')->parent; + if ($this->request->is('parent')) { + return 'category.php?parent=' . $this->request->filter('int')->get('parent'); } else { return 'category.php'; } diff --git a/var/Widget/Metas/Category/Edit.php b/var/Widget/Metas/Category/Edit.php index 63bb7cf5..c3a0d700 100644 --- a/var/Widget/Metas/Category/Edit.php +++ b/var/Widget/Metas/Category/Edit.php @@ -65,8 +65,8 @@ class Edit extends Metas implements ActionInterface ->where('name = ?', $name) ->limit(1); - if ($this->request->mid) { - $select->where('mid <> ?', $this->request->mid); + if ($this->request->is('mid')) { + $select->where('mid <> ?', $this->request->get('mid')); } $category = $this->db->fetchRow($select); @@ -106,8 +106,8 @@ class Edit extends Metas implements ActionInterface ->where('slug = ?', Common::slugName($slug)) ->limit(1); - if ($this->request->mid) { - $select->where('mid <> ?', $this->request->mid); + if ($this->request->is('mid')) { + $select->where('mid <> ?', $this->request->get('mid')); } $category = $this->db->fetchRow($select); @@ -180,7 +180,7 @@ class Edit extends Metas implements ActionInterface $options = [0 => _t('不选择')]; $parents = Rows::allocWithAlias( 'options', - (isset($this->request->mid) ? 'ignore=' . $this->request->mid : '') + ($this->request->is('mid') ? 'ignore=' . $this->request->get('mid') : '') ); while ($parents->next()) { @@ -190,7 +190,7 @@ class Edit extends Metas implements ActionInterface $parent = new Form\Element\Select( 'parent', $options, - $this->request->parent, + $this->request->get('parent'), _t('父级分类'), _t('此分类将归档在您选择的父级分类下.') ); @@ -278,7 +278,7 @@ class Edit extends Metas implements ActionInterface /** 取出数据 */ $category = $this->request->from('name', 'slug', 'description', 'parent'); - $category['mid'] = $this->request->mid; + $category['mid'] = $this->request->get('mid'); $category['slug'] = Common::slugName(empty($category['slug']) ? $category['name'] : $category['slug']); $category['type'] = 'category'; $current = $this->db->fetchRow($this->select()->where('mid = ?', $category['mid'])); @@ -298,7 +298,7 @@ class Edit extends Metas implements ActionInterface } /** 更新数据 */ - $this->update($category, $this->db->sql()->where('mid = ?', $this->request->filter('int')->mid)); + $this->update($category, $this->db->sql()->where('mid = ?', $this->request->filter('int')->get('mid'))); $this->push($category); /** 设置高亮 */ @@ -358,7 +358,7 @@ class Edit extends Metas implements ActionInterface $this->response->goBack(); } - $merge = $this->request->merge; + $merge = $this->request->get('merge'); $categories = $this->request->filter('int')->getArray('mid'); if ($categories) { @@ -367,7 +367,7 @@ class Edit extends Metas implements ActionInterface /** 提示信息 */ Notice::alloc()->set(_t('分类已经合并'), 'success'); } else { - Notice::alloc()->set(_t('没有选择任何分类'), 'notice'); + Notice::alloc()->set(_t('没有选择任何分类')); } /** 转向原页 */ @@ -402,12 +402,12 @@ class Edit extends Metas implements ActionInterface $categories = $this->request->filter('int')->getArray('mid'); if ($categories) { foreach ($categories as $category) { - $this->refreshCountByTypeAndStatus($category, 'post', 'publish'); + $this->refreshCountByTypeAndStatus($category, 'post'); } Notice::alloc()->set(_t('分类刷新已经完成'), 'success'); } else { - Notice::alloc()->set(_t('没有选择任何分类'), 'notice'); + Notice::alloc()->set(_t('没有选择任何分类')); } /** 转向原页 */ @@ -430,10 +430,10 @@ class Edit extends Metas implements ActionInterface Notice::alloc()->set($error, 'error'); } else { $this->db->query($this->db->update('table.options') - ->rows(['value' => $this->request->mid]) + ->rows(['value' => $this->request->get('mid')]) ->where('name = ?', 'defaultCategory')); - $this->db->fetchRow($this->select()->where('mid = ?', $this->request->mid) + $this->db->fetchRow($this->select()->where('mid = ?', $this->request->get('mid')) ->where('type = ?', 'category')->limit(1), [$this, 'push']); /** 设置高亮 */ diff --git a/var/Widget/Metas/Category/Rows.php b/var/Widget/Metas/Category/Rows.php index e4a366ab..25e0dfbd 100644 --- a/var/Widget/Metas/Category/Rows.php +++ b/var/Widget/Metas/Category/Rows.php @@ -17,6 +17,8 @@ if (!defined('__TYPECHO_ROOT_DIR__')) { * @package Widget * @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org) * @license GNU General Public License 2.0 + * @property-read int $levels + * @property-read array $children */ class Rows extends Metas { @@ -26,15 +28,15 @@ class Rows extends Metas * @var array * @access private */ - private $treeViewCategories = []; + private array $treeViewCategories = []; /** * _categoryOptions * - * @var mixed + * @var Config|null * @access private */ - private $categoryOptions = null; + private ?Config $categoryOptions = null; /** * 顶层分类 @@ -42,7 +44,7 @@ class Rows extends Metas * @var array * @access private */ - private $top = []; + private array $top = []; /** * 所有分类哈希表 @@ -50,7 +52,7 @@ class Rows extends Metas * @var array * @access private */ - private $map = []; + private array $map = []; /** * 顺序流 @@ -58,7 +60,7 @@ class Rows extends Metas * @var array * @access private */ - private $orders = []; + private array $orders = []; /** * 所有子节点列表 @@ -66,7 +68,7 @@ class Rows extends Metas * @var array * @access private */ - private $childNodes = []; + private array $childNodes = []; /** * 所有父节点列表 @@ -74,7 +76,7 @@ class Rows extends Metas * @var array * @access private */ - private $parents = []; + private array $parents = []; /** * @param Config $parameter @@ -173,7 +175,7 @@ class Rows extends Metas ]); // 插件插件接口 - self::pluginHandle()->trigger($plugged)->listCategories($this->categoryOptions, $this); + self::pluginHandle()->trigger($plugged)->call('listCategories', $this->categoryOptions, $this); if (!$plugged) { $this->stack = $this->getCategories($this->top); diff --git a/var/Widget/Metas/Tag/Admin.php b/var/Widget/Metas/Tag/Admin.php index 3d8f60ba..6e764b21 100644 --- a/var/Widget/Metas/Tag/Admin.php +++ b/var/Widget/Metas/Tag/Admin.php @@ -38,9 +38,9 @@ class Admin extends Cloud */ public function getMenuTitle(): ?string { - if (isset($this->request->mid)) { + if ($this->request->is('mid')) { $tag = $this->db->fetchRow($this->select() - ->where('type = ? AND mid = ?', 'tag', $this->request->mid)); + ->where('type = ? AND mid = ?', 'tag', $this->request->get('mid'))); if (!empty($tag)) { return _t('编辑标签 %s', $tag['name']); diff --git a/var/Widget/Metas/Tag/Edit.php b/var/Widget/Metas/Tag/Edit.php index 2425f5ae..0f5f5a93 100644 --- a/var/Widget/Metas/Tag/Edit.php +++ b/var/Widget/Metas/Tag/Edit.php @@ -65,8 +65,8 @@ class Edit extends Metas implements ActionInterface ->where('name = ?', $name) ->limit(1); - if ($this->request->mid) { - $select->where('mid <> ?', $this->request->filter('int')->mid); + if ($this->request->is('mid')) { + $select->where('mid <> ?', $this->request->filter('int')->get('mid')); } $tag = $this->db->fetchRow($select); @@ -106,8 +106,8 @@ class Edit extends Metas implements ActionInterface ->where('slug = ?', Common::slugName($slug)) ->limit(1); - if ($this->request->mid) { - $select->where('mid <> ?', $this->request->mid); + if ($this->request->is('mid')) { + $select->where('mid <> ?', $this->request->get('mid')); } $tag = $this->db->fetchRow($select); @@ -192,10 +192,10 @@ class Edit extends Metas implements ActionInterface $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); - if (isset($this->request->mid) && 'insert' != $action) { + if ($this->request->is('mid') && 'insert' != $action) { /** 更新模式 */ $meta = $this->db->fetchRow($this->select() - ->where('mid = ?', $this->request->mid) + ->where('mid = ?', $this->request->get('mid')) ->where('type = ?', 'tag')->limit(1)); if (!$meta) { @@ -253,7 +253,7 @@ class Edit extends Metas implements ActionInterface $tag['slug'] = Common::slugName(empty($tag['slug']) ? $tag['name'] : $tag['slug']); /** 更新数据 */ - $this->update($tag, $this->db->sql()->where('mid = ?', $this->request->filter('int')->mid)); + $this->update($tag, $this->db->sql()->where('mid = ?', $this->request->filter('int')->get('mid'))); $this->push($tag); /** 设置高亮 */ @@ -279,7 +279,7 @@ class Edit extends Metas implements ActionInterface $tags = $this->request->filter('int')->getArray('mid'); $deleteCount = 0; - if ($tags && is_array($tags)) { + if ($tags) { foreach ($tags as $tag) { if ($this->delete($this->db->sql()->where('mid = ?', $tag))) { $this->db->query($this->db->delete('table.relationships')->where('mid = ?', $tag)); @@ -306,11 +306,11 @@ class Edit extends Metas implements ActionInterface public function mergeTag() { if (empty($this->request->merge)) { - Notice::alloc()->set(_t('请填写需要合并到的标签'), 'notice'); + Notice::alloc()->set(_t('请填写需要合并到的标签')); $this->response->goBack(); } - $merge = $this->scanTags($this->request->merge); + $merge = $this->scanTags($this->request->get('merge')); if (empty($merge)) { Notice::alloc()->set(_t('合并到的标签名不合法'), 'error'); $this->response->goBack(); @@ -324,7 +324,7 @@ class Edit extends Metas implements ActionInterface /** 提示信息 */ Notice::alloc()->set(_t('标签已经合并'), 'success'); } else { - Notice::alloc()->set(_t('没有选择任何标签'), 'notice'); + Notice::alloc()->set(_t('没有选择任何标签')); } /** 转向原页 */ @@ -343,7 +343,7 @@ class Edit extends Metas implements ActionInterface $tags = $this->request->filter('int')->getArray('mid'); if ($tags) { foreach ($tags as $tag) { - $this->refreshCountByTypeAndStatus($tag, 'post', 'publish'); + $this->refreshCountByTypeAndStatus($tag, 'post'); } // 自动清理标签 @@ -351,7 +351,7 @@ class Edit extends Metas implements ActionInterface Notice::alloc()->set(_t('标签刷新已经完成'), 'success'); } else { - Notice::alloc()->set(_t('没有选择任何标签'), 'notice'); + Notice::alloc()->set(_t('没有选择任何标签')); } /** 转向原页 */ diff --git a/var/Widget/Notice.php b/var/Widget/Notice.php index 6ccb47e3..e6d355fa 100644 --- a/var/Widget/Notice.php +++ b/var/Widget/Notice.php @@ -21,7 +21,7 @@ class Notice extends Widget * * @var string */ - public $highlight; + public string $highlight; /** * 高亮相关元素 diff --git a/var/Widget/Options.php b/var/Widget/Options.php index 3dadc434..8060e46c 100644 --- a/var/Widget/Options.php +++ b/var/Widget/Options.php @@ -87,6 +87,9 @@ if (!defined('__TYPECHO_ROOT_DIR__')) { * @property bool $commentsAntiSpam * @property bool $commentsAutoClose * @property bool $commentsPostIntervalEnable + * @property int $commentsMaxNestingLevels + * @property int $commentsPostTimeout + * @property int $commentsPostInterval * @property string $commentsHTMLTagAllowed * @property bool $allowRegister * @property bool $allowXmlRpc @@ -97,6 +100,8 @@ if (!defined('__TYPECHO_ROOT_DIR__')) { * @property array $plugins * @property string $secret * @property bool $installed + * @property bool $rewrite + * @property string $postDateFormat */ class Options extends Base { @@ -106,7 +111,7 @@ class Options extends Base * @access private * @var array */ - private $pluginConfig = []; + private array $pluginConfig = []; /** * 缓存的个人插件配置 @@ -114,7 +119,7 @@ class Options extends Base * @access private * @var array */ - private $personalPluginConfig = []; + private array $personalPluginConfig = []; /** * @param int $components @@ -676,7 +681,7 @@ class Options extends Base $this->attachmentTypes ); - $attachmentTypesResult = array_unique(array_map('trim', preg_split("/(,|\.)/", $attachmentTypes))); + $attachmentTypesResult = array_unique(array_map('trim', preg_split("/([,.])/", $attachmentTypes))); } return $attachmentTypesResult; diff --git a/var/Widget/Options/Discussion.php b/var/Widget/Options/Discussion.php index d4928f52..34f4de9a 100644 --- a/var/Widget/Options/Discussion.php +++ b/var/Widget/Options/Discussion.php @@ -52,7 +52,7 @@ class Discussion extends Options implements ActionInterface 'commentsPostTimeout', 'commentsPostInterval', 'commentsRequireModeration', - 'commentsRequireURL', + 'commentsRequireUrl', 'commentsHTMLTagAllowed', 'commentsStopWords', 'commentsIpBlackList' @@ -84,7 +84,7 @@ class Discussion extends Options implements ActionInterface ); $settings['commentsWhitelist'] = $this->isEnableByCheckbox($settings['commentsPost'], 'commentsWhitelist'); $settings['commentsRequireMail'] = $this->isEnableByCheckbox($settings['commentsPost'], 'commentsRequireMail'); - $settings['commentsRequireURL'] = $this->isEnableByCheckbox($settings['commentsPost'], 'commentsRequireURL'); + $settings['commentsRequireUrl'] = $this->isEnableByCheckbox($settings['commentsPost'], 'commentsRequireUrl'); $settings['commentsCheckReferer'] = $this->isEnableByCheckbox( $settings['commentsPost'], 'commentsCheckReferer' @@ -212,7 +212,7 @@ class Discussion extends Options implements ActionInterface 'commentsRequireModeration' => _t('所有评论必须经过审核'), 'commentsWhitelist' => _t('评论者之前须有评论通过了审核'), 'commentsRequireMail' => _t('必须填写邮箱'), - 'commentsRequireURL' => _t('必须填写网址'), + 'commentsRequireUrl' => _t('必须填写网址'), 'commentsCheckReferer' => _t('检查评论来源页 URL 是否与文章链接一致'), 'commentsAntiSpam' => _t('开启反垃圾保护'), 'commentsAutoClose' => _t('在文章发布 %s 天以后自动关闭评论', @@ -236,8 +236,8 @@ class Discussion extends Options implements ActionInterface $commentsPostOptionsValue[] = 'commentsRequireMail'; } - if ($this->options->commentsRequireURL) { - $commentsPostOptionsValue[] = 'commentsRequireURL'; + if ($this->options->commentsRequireUrl) { + $commentsPostOptionsValue[] = 'commentsRequireUrl'; } if ($this->options->commentsCheckReferer) { diff --git a/var/Widget/Options/General.php b/var/Widget/Options/General.php index 52c7971a..c29d66e0 100644 --- a/var/Widget/Options/General.php +++ b/var/Widget/Options/General.php @@ -96,7 +96,7 @@ class General extends Options implements ActionInterface $settings['attachmentTypes'] = $this->request->getArray('attachmentTypes'); if (!defined('__TYPECHO_SITE_URL__')) { - $settings['siteUrl'] = rtrim($this->request->siteUrl, '/'); + $settings['siteUrl'] = rtrim($this->request->get('siteUrl'), '/'); } $attachmentTypes = []; @@ -112,7 +112,7 @@ class General extends Options implements ActionInterface $attachmentTypes[] = '@doc@'; } - $attachmentTypesOther = $this->request->filter('trim', 'strtolower')->attachmentTypesOther; + $attachmentTypesOther = $this->request->filter('trim', 'strtolower')->get('attachmentTypesOther'); if ($this->isEnableByCheckbox($settings['attachmentTypes'], '@other@') && !empty($attachmentTypesOther)) { $types = implode( ',', diff --git a/var/Widget/Options/Permalink.php b/var/Widget/Options/Permalink.php index a266fedb..e98e7155 100644 --- a/var/Widget/Options/Permalink.php +++ b/var/Widget/Options/Permalink.php @@ -57,7 +57,7 @@ class Permalink extends Options implements ActionInterface * @param string $value 是否打开rewrite * @return bool */ - public function checkRewrite(string $value) + public function checkRewrite(string $value): bool { if ($value) { $this->user->pass('administrator'); @@ -125,7 +125,7 @@ RewriteRule . {$basePath}index.php [L] unlink(__TYPECHO_ROOT_DIR__ . '/.htaccess'); } } catch (Client\Exception $e) { - if (false != $hasWrote) { + if ($hasWrote) { @unlink(__TYPECHO_ROOT_DIR__ . '/.htaccess'); } return false; @@ -146,25 +146,28 @@ RewriteRule . {$basePath}index.php [L] */ public function updatePermalinkSettings() { + $customPattern = $this->request->get('customPattern'); + $postPattern = $this->request->get('postPattern'); + /** 验证格式 */ if ($this->form()->validate()) { - Cookie::set('__typecho_form_item_postPattern', $this->request->customPattern); + Cookie::set('__typecho_form_item_postPattern', $customPattern); $this->response->goBack(); } - $patternValid = $this->checkRule($this->request->postPattern); + $patternValid = $this->checkRule($postPattern); /** 解析url pattern */ - if ('custom' == $this->request->postPattern) { - $this->request->postPattern = '/' . ltrim($this->encodeRule($this->request->customPattern), '/'); + if ('custom' == $postPattern) { + $postPattern = '/' . ltrim($this->encodeRule($customPattern), '/'); } $settings = defined('__TYPECHO_REWRITE__') ? [] : $this->request->from('rewrite'); - if (isset($this->request->postPattern) && isset($this->request->pagePattern)) { + if (isset($postPattern) && $this->request->is('pagePattern')) { $routingTable = $this->options->routingTable; - $routingTable['post']['url'] = $this->request->postPattern; - $routingTable['page']['url'] = '/' . ltrim($this->encodeRule($this->request->pagePattern), '/'); - $routingTable['category']['url'] = '/' . ltrim($this->encodeRule($this->request->categoryPattern), '/'); + $routingTable['post']['url'] = $postPattern; + $routingTable['page']['url'] = '/' . ltrim($this->encodeRule($this->request->get('pagePattern')), '/'); + $routingTable['category']['url'] = '/' . ltrim($this->encodeRule($this->request->get('categoryPattern')), '/'); $routingTable['category_page']['url'] = rtrim($routingTable['category']['url'], '/') . '/[page:digital]/'; if (isset($routingTable[0])) { @@ -181,7 +184,7 @@ RewriteRule . {$basePath}index.php [L] if ($patternValid) { Notice::alloc()->set(_t("设置已经保存"), 'success'); } else { - Notice::alloc()->set(_t("自定义链接与现有规则存在冲突! 它可能影响解析效率, 建议你重新分配一个规则."), 'notice'); + Notice::alloc()->set(_t("自定义链接与现有规则存在冲突! 它可能影响解析效率, 建议你重新分配一个规则.")); } $this->response->goBack(); } @@ -246,8 +249,8 @@ RewriteRule . {$basePath}index.php [L] /** 增加个性化路径 */ $customPatternValue = null; - if (isset($this->request->__typecho_form_item_postPattern)) { - $customPatternValue = $this->request->__typecho_form_item_postPattern; + if ($this->request->is('__typecho_form_item_postPattern')) { + $customPatternValue = $this->request->get('__typecho_form_item_postPattern'); Cookie::delete('__typecho_form_item_postPattern'); } elseif (!isset($patterns[$postPatternValue])) { $customPatternValue = $this->decodeRule($postPatternValue); @@ -325,7 +328,7 @@ RewriteRule . {$basePath}index.php [L] } $routingTable = $this->options->routingTable; - $currentTable = ['custom' => ['url' => $this->encodeRule($this->request->customPattern)]]; + $currentTable = ['custom' => ['url' => $this->encodeRule($this->request->get('customPattern'))]]; $parser = new Parser($currentTable); $currentTable = $parser->parse(); $regx = $currentTable['custom']['regx']; diff --git a/var/Widget/Options/Reading.php b/var/Widget/Options/Reading.php index 0bdd25ef..575ea2e9 100644 --- a/var/Widget/Options/Reading.php +++ b/var/Widget/Options/Reading.php @@ -44,17 +44,17 @@ class Reading extends Permalink ); if ( - 'page' == $settings['frontPage'] && isset($this->request->frontPagePage) && + 'page' == $settings['frontPage'] && $this->request->is('frontPagePage') && $this->db->fetchRow($this->db->select('cid') ->from('table.contents')->where('type = ?', 'page') ->where('status = ?', 'publish')->where('created < ?', $this->options->time) - ->where('cid = ?', $pageId = intval($this->request->frontPagePage))) + ->where('cid = ?', $pageId = intval($this->request->get('frontPagePage')))) ) { $settings['frontPage'] = 'page:' . $pageId; } elseif ( - 'file' == $settings['frontPage'] && isset($this->request->frontPageFile) && + 'file' == $settings['frontPage'] && $this->request->is('frontPageFile') && file_exists(__TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_THEME_DIR__ . '/' . $this->options->theme . '/' . - ($file = trim($this->request->frontPageFile, " ./\\"))) + ($file = trim($this->request->get('frontPageFile'), " ./\\"))) ) { $settings['frontPage'] = 'file:' . $file; } else { @@ -65,7 +65,7 @@ class Reading extends Permalink $settings['frontArchive'] = empty($settings['frontArchive']) ? 0 : 1; if ($settings['frontArchive']) { $routingTable = $this->options->routingTable; - $routingTable['archive']['url'] = '/' . ltrim($this->encodeRule($this->request->archivePattern), '/'); + $routingTable['archive']['url'] = '/' . ltrim($this->encodeRule($this->request->get('archivePattern')), '/'); $routingTable['archive_page']['url'] = rtrim($routingTable['archive']['url'], '/') . '/page/[page:digital]/'; diff --git a/var/Widget/Plugins/Config.php b/var/Widget/Plugins/Config.php index 09bdb718..73d6bd21 100644 --- a/var/Widget/Plugins/Config.php +++ b/var/Widget/Plugins/Config.php @@ -27,21 +27,21 @@ class Config extends Options * * @var array */ - public $info; + public array $info; /** * 插件文件路径 * * @var string */ - private $pluginFileName; + private string $pluginFileName; /** * 插件类 * * @var string */ - private $className; + private string $className; /** * 绑定动作 @@ -52,7 +52,7 @@ class Config extends Options public function execute() { $this->user->pass('administrator'); - $config = $this->request->filter('slug')->config; + $config = $this->request->filter('slug')->get('config'); if (empty($config)) { throw new Exception(_t('插件不存在'), 404); } @@ -78,10 +78,10 @@ class Config extends Options * @return Form * @throws Exception|Plugin\Exception */ - public function config() + public function config(): Form { /** 获取插件名称 */ - $pluginName = $this->request->filter('slug')->config; + $pluginName = $this->request->filter('slug')->get('config'); /** 获取已启用插件 */ $plugins = Plugin::export(); diff --git a/var/Widget/Plugins/Edit.php b/var/Widget/Plugins/Edit.php index c6073bba..215c0bdd 100644 --- a/var/Widget/Plugins/Edit.php +++ b/var/Widget/Plugins/Edit.php @@ -29,7 +29,7 @@ class Edit extends Options implements ActionInterface /** * @var bool */ - private $configNoticed = false; + private bool $configNoticed = false; /** * 启用插件 @@ -124,7 +124,7 @@ class Edit extends Options implements ActionInterface $result = call_user_func([$className, 'configCheck'], $settings); if (!empty($result) && is_string($result)) { - Notice::alloc()->set($result, 'notice'); + Notice::alloc()->set($result); $this->configNoticed = true; } } @@ -261,7 +261,7 @@ class Edit extends Options implements ActionInterface $this->delete($this->db->sql()->where('name = ?', '_plugin:' . $pluginName)); if (isset($result) && is_string($result)) { - Notice::alloc()->set($result, 'notice'); + Notice::alloc()->set($result); } else { Notice::alloc()->set(_t('插件已经被禁用'), 'success'); } @@ -310,9 +310,9 @@ class Edit extends Options implements ActionInterface { $this->user->pass('administrator'); $this->security->protect(); - $this->on($this->request->is('activate'))->activate($this->request->filter('slug')->activate); - $this->on($this->request->is('deactivate'))->deactivate($this->request->filter('slug')->deactivate); - $this->on($this->request->is('config'))->config($this->request->filter('slug')->config); + $this->on($this->request->is('activate'))->activate($this->request->filter('slug')->get('activate')); + $this->on($this->request->is('deactivate'))->deactivate($this->request->filter('slug')->get('deactivate')); + $this->on($this->request->is('config'))->config($this->request->filter('slug')->get('config')); $this->response->redirect($this->options->adminUrl); } } diff --git a/var/Widget/Plugins/Rows.php b/var/Widget/Plugins/Rows.php index 0f835082..586152dd 100644 --- a/var/Widget/Plugins/Rows.php +++ b/var/Widget/Plugins/Rows.php @@ -2,7 +2,6 @@ namespace Widget\Plugins; -use Typecho\Common; use Typecho\Plugin; use Typecho\Widget; @@ -27,7 +26,7 @@ class Rows extends Widget * @access public * @var array */ - public $activatedPlugins = []; + public array $activatedPlugins = []; /** * 执行函数 @@ -89,10 +88,9 @@ class Rows extends Widget /** * @param string $plugin - * @param string $index * @return array|null */ - protected function getPlugin(string $plugin, string $index): ?array + protected function getPlugin(string $plugin): ?array { if (is_dir($plugin)) { /** 获取插件名称 */ diff --git a/var/Widget/Register.php b/var/Widget/Register.php index 3f1b2514..1ca23606 100644 --- a/var/Widget/Register.php +++ b/var/Widget/Register.php @@ -60,8 +60,8 @@ class Register extends Users implements ActionInterface /** 截获验证异常 */ if ($error = $validator->run($this->request->from('name', 'password', 'mail', 'confirm'))) { - Cookie::set('__typecho_remember_name', $this->request->name); - Cookie::set('__typecho_remember_mail', $this->request->mail); + Cookie::set('__typecho_remember_name', $this->request->get('name')); + Cookie::set('__typecho_remember_mail', $this->request->get('mail')); /** 设置提示信息 */ Notice::alloc()->set($error); @@ -72,23 +72,23 @@ class Register extends Users implements ActionInterface $generatedPassword = Common::randString(7); $dataStruct = [ - 'name' => $this->request->name, - 'mail' => $this->request->mail, - 'screenName' => $this->request->name, + 'name' => $this->request->get('name'), + 'mail' => $this->request->get('mail'), + 'screenName' => $this->request->get('name'), 'password' => $hasher->hashPassword($generatedPassword), 'created' => $this->options->time, 'group' => 'subscriber' ]; - $dataStruct = self::pluginHandle()->register($dataStruct); + $dataStruct = self::pluginHandle()->call('register', $dataStruct); $insertId = $this->insert($dataStruct); $this->db->fetchRow($this->select()->where('uid = ?', $insertId) ->limit(1), [$this, 'push']); - self::pluginHandle()->finishRegister($this); + self::pluginHandle()->call('finishRegister', $this); - $this->user->login($this->request->name, $generatedPassword); + $this->user->login($this->request->get('name'), $generatedPassword); Cookie::delete('__typecho_first_run'); Cookie::delete('__typecho_remember_name'); diff --git a/var/Widget/Security.php b/var/Widget/Security.php index b972ed45..df94f8a3 100644 --- a/var/Widget/Security.php +++ b/var/Widget/Security.php @@ -23,12 +23,12 @@ class Security extends Base /** * @var string */ - private $token; + private string $token; /** * @var boolean */ - private $enabled = true; + private bool $enabled = true; /** * @param int $components diff --git a/var/Widget/Service.php b/var/Widget/Service.php index 2a30d6bd..ef95e27d 100644 --- a/var/Widget/Service.php +++ b/var/Widget/Service.php @@ -27,7 +27,7 @@ class Service extends BaseOptions implements ActionInterface * * @var array */ - public $asyncRequests = []; + public array $asyncRequests = []; /** * 发送pingback实现 @@ -224,7 +224,7 @@ class Service extends BaseOptions implements ActionInterface * @param $method * @param mixed $params */ - public function requestService($method, $params = null) + public function requestService($method, ... $params) { static $called; @@ -281,7 +281,7 @@ class Service extends BaseOptions implements ActionInterface if (!empty($requests)) { foreach ($requests as $request) { [$method, $params] = $request; - $plugin->{$method}($params); + $plugin->call($method, ... $params); } } } diff --git a/var/Widget/Stat.php b/var/Widget/Stat.php index 2fa16cad..e493cf62 100644 --- a/var/Widget/Stat.php +++ b/var/Widget/Stat.php @@ -133,7 +133,7 @@ class Stat extends Base ->from('table.contents') ->where('table.contents.type = ?', 'post') ->where('table.contents.status = ?', 'publish') - ->where('table.contents.authorId = ?', $this->request->filter('int')->uid))->num; + ->where('table.contents.authorId = ?', $this->request->filter('int')->get('uid')))->num; } /** @@ -147,7 +147,7 @@ class Stat extends Base ->from('table.contents') ->where('table.contents.type = ? OR table.contents.type = ?', 'post', 'post_draft') ->where('table.contents.status = ?', 'waiting') - ->where('table.contents.authorId = ?', $this->request->filter('int')->uid))->num; + ->where('table.contents.authorId = ?', $this->request->filter('int')->get('uid')))->num; } /** @@ -160,7 +160,7 @@ class Stat extends Base return $this->db->fetchObject($this->db->select(['COUNT(cid)' => 'num']) ->from('table.contents') ->where('table.contents.type = ?', 'post_draft') - ->where('table.contents.authorId = ?', $this->request->filter('int')->uid))->num; + ->where('table.contents.authorId = ?', $this->request->filter('int')->get('uid')))->num; } /** @@ -272,7 +272,7 @@ class Stat extends Base { return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num']) ->from('table.comments') - ->where('table.comments.cid = ?', $this->request->filter('int')->cid))->num; + ->where('table.comments.cid = ?', $this->request->filter('int')->get('cid')))->num; } /** @@ -285,7 +285,7 @@ class Stat extends Base return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num']) ->from('table.comments') ->where('table.comments.status = ?', 'approved') - ->where('table.comments.cid = ?', $this->request->filter('int')->cid))->num; + ->where('table.comments.cid = ?', $this->request->filter('int')->get('cid')))->num; } /** @@ -298,7 +298,7 @@ class Stat extends Base return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num']) ->from('table.comments') ->where('table.comments.status = ?', 'waiting') - ->where('table.comments.cid = ?', $this->request->filter('int')->cid))->num; + ->where('table.comments.cid = ?', $this->request->filter('int')->get('cid')))->num; } /** @@ -311,7 +311,7 @@ class Stat extends Base return $this->db->fetchObject($this->db->select(['COUNT(coid)' => 'num']) ->from('table.comments') ->where('table.comments.status = ?', 'spam') - ->where('table.comments.cid = ?', $this->request->filter('int')->cid))->num; + ->where('table.comments.cid = ?', $this->request->filter('int')->get('cid')))->num; } /** diff --git a/var/Widget/Themes/Edit.php b/var/Widget/Themes/Edit.php index b362d29c..72bab0c7 100644 --- a/var/Widget/Themes/Edit.php +++ b/var/Widget/Themes/Edit.php @@ -100,7 +100,7 @@ class Edit extends Options implements ActionInterface * @param string $file 文件名 * @throws Exception */ - public function editThemeFile($theme, $file) + public function editThemeFile(string $theme, string $file) { $path = $this->options->themeFile($theme, $file); @@ -109,7 +109,7 @@ class Edit extends Options implements ActionInterface && (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__) ) { $handle = fopen($path, 'wb'); - if ($handle && fwrite($handle, $this->request->content)) { + if ($handle && fwrite($handle, $this->request->get('content'))) { fclose($handle); Notice::alloc()->set(_t("文件 %s 的更改已经保存", $file), 'success'); } else { @@ -174,9 +174,9 @@ class Edit extends Options implements ActionInterface /** 需要管理员权限 */ $this->user->pass('administrator'); $this->security->protect(); - $this->on($this->request->is('change'))->changeTheme($this->request->filter('slug')->change); + $this->on($this->request->is('change'))->changeTheme($this->request->filter('slug')->get('change')); $this->on($this->request->is('edit&theme')) - ->editThemeFile($this->request->filter('slug')->theme, $this->request->edit); + ->editThemeFile($this->request->filter('slug')->get('theme'), $this->request->get('edit')); $this->on($this->request->is('config'))->config($this->options->theme); $this->response->redirect($this->options->adminUrl); } diff --git a/var/Widget/Themes/Files.php b/var/Widget/Themes/Files.php index 5eb2e7b5..08cf5ea1 100644 --- a/var/Widget/Themes/Files.php +++ b/var/Widget/Themes/Files.php @@ -27,7 +27,7 @@ class Files extends Base * @access private * @var string */ - private $currentTheme; + private string $currentTheme; /** * 当前文件 @@ -35,7 +35,7 @@ class Files extends Base * @access private * @var string */ - private $currentFile; + private string $currentFile; /** * 执行函数 @@ -49,7 +49,7 @@ class Files extends Base $this->currentTheme = $this->request->filter('slug')->get('theme', Options::alloc()->theme); if ( - preg_match("/^([_0-9a-z-\.\ ])+$/i", $this->currentTheme) + preg_match("/^([_0-9a-z-. ])+$/i", $this->currentTheme) && is_dir($dir = Options::alloc()->themeFile($this->currentTheme)) && (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__) ) { @@ -60,7 +60,7 @@ class Files extends Base $this->currentFile = $this->request->get('file', 'index.php'); if ( - preg_match("/^([_0-9a-z-\.\ ])+$/i", $this->currentFile) + preg_match("/^([_0-9a-z-. ])+$/i", $this->currentFile) && file_exists($dir . '/' . $this->currentFile) ) { foreach ($files as $file) { diff --git a/var/Widget/Themes/Rows.php b/var/Widget/Themes/Rows.php index 8662422f..04096bd2 100644 --- a/var/Widget/Themes/Rows.php +++ b/var/Widget/Themes/Rows.php @@ -77,10 +77,9 @@ class Rows extends Widget * get theme * * @param string $theme - * @param mixed $index * @return string */ - protected function getTheme(string $theme, $index): string + protected function getTheme(string $theme): string { return basename($theme); } diff --git a/var/Widget/Upload.php b/var/Widget/Upload.php index 629af92a..0ea90f18 100644 --- a/var/Widget/Upload.php +++ b/var/Widget/Upload.php @@ -6,7 +6,6 @@ use Typecho\Common; use Typecho\Date; use Typecho\Db\Exception; use Typecho\Plugin; -use Typecho\Widget; use Widget\Base\Contents; if (!defined('__TYPECHO_ROOT_DIR__')) { @@ -33,7 +32,7 @@ class Upload extends Contents implements ActionInterface */ public static function deleteHandle(array $content): bool { - $result = Plugin::factory(Upload::class)->trigger($hasDeleted)->deleteHandle($content); + $result = Plugin::factory(Upload::class)->trigger($hasDeleted)->call('deleteHandle', $content); if ($hasDeleted) { return $result; } @@ -49,7 +48,7 @@ class Upload extends Contents implements ActionInterface */ public static function attachmentHandle(array $content): string { - $result = Plugin::factory(Upload::class)->trigger($hasPlugged)->attachmentHandle($content); + $result = Plugin::factory(Upload::class)->trigger($hasPlugged)->call('attachmentHandle', $content); if ($hasPlugged) { return $result; } @@ -69,7 +68,7 @@ class Upload extends Contents implements ActionInterface */ public static function attachmentDataHandle(array $content): string { - $result = Plugin::factory(Upload::class)->trigger($hasPlugged)->attachmentDataHandle($content); + $result = Plugin::factory(Upload::class)->trigger($hasPlugged)->call('attachmentDataHandle', $content); if ($hasPlugged) { return $result; } @@ -109,8 +108,13 @@ class Upload extends Contents implements ActionInterface if (!empty($_FILES)) { $file = array_pop($_FILES); if (0 == $file['error'] && is_uploaded_file($file['tmp_name'])) { - $this->db->fetchRow($this->select()->where('table.contents.cid = ?', $this->request->filter('int')->cid) - ->where('table.contents.type = ?', 'attachment'), [$this, 'push']); + $this->db->fetchRow( + $this->select()->where( + 'table.contents.cid = ?', + $this->request->filter('int')->get('cid') + ) + ->where('table.contents.type = ?', 'attachment'), [$this, 'push'] + ); if (!$this->have()) { $this->response->setStatus(404); @@ -130,7 +134,7 @@ class Upload extends Contents implements ActionInterface $result = self::modifyHandle($this->row, $file); if (false !== $result) { - self::pluginHandle()->beforeModify($result); + self::pluginHandle()->call('beforeModify', $result); $this->update([ 'text' => serialize($result) @@ -140,7 +144,7 @@ class Upload extends Contents implements ActionInterface ->where('table.contents.type = ?', 'attachment'), [$this, 'push']); /** 增加插件接口 */ - self::pluginHandle()->modify($this); + self::pluginHandle()->call('modify', $this); $this->response->throwJson([$this->attachment->url, [ 'cid' => $this->cid, @@ -172,7 +176,7 @@ class Upload extends Contents implements ActionInterface return false; } - $result = self::pluginHandle()->trigger($hasModified)->modifyHandle($content, $file); + $result = self::pluginHandle()->trigger($hasModified)->call('modifyHandle', $content, $file); if ($hasModified) { return $result; } @@ -297,7 +301,7 @@ class Upload extends Contents implements ActionInterface $result = self::uploadHandle($file); if (false !== $result) { - self::pluginHandle()->beforeUpload($result); + self::pluginHandle()->call('beforeUpload', $result); $struct = [ 'title' => $result['name'], @@ -311,7 +315,7 @@ class Upload extends Contents implements ActionInterface ]; if (isset($this->request->cid)) { - $cid = $this->request->filter('int')->cid; + $cid = $this->request->filter('int')->get('cid'); if ($this->isWriteable($this->db->sql()->where('cid = ?', $cid))) { $struct['parent'] = $cid; @@ -324,7 +328,7 @@ class Upload extends Contents implements ActionInterface ->where('table.contents.type = ?', 'attachment'), [$this, 'push']); /** 增加插件接口 */ - self::pluginHandle()->upload($this); + self::pluginHandle()->call('upload', $this); $this->response->throwJson([$this->attachment->url, [ 'cid' => $insertId, @@ -356,7 +360,7 @@ class Upload extends Contents implements ActionInterface return false; } - $result = self::pluginHandle()->trigger($hasUploaded)->uploadHandle($file); + $result = self::pluginHandle()->trigger($hasUploaded)->call('uploadHandle', $file); if ($hasUploaded) { return $result; } diff --git a/var/Widget/User.php b/var/Widget/User.php index 700bf1ad..b59b7906 100644 --- a/var/Widget/User.php +++ b/var/Widget/User.php @@ -28,7 +28,7 @@ class User extends Users * * @var array */ - public $groups = [ + public array $groups = [ 'administrator' => 0, 'editor' => 1, 'contributor' => 2, @@ -41,14 +41,14 @@ class User extends Users * * @var array */ - private $currentUser; + private array $currentUser; /** * 是否已经登录 * * @var boolean|null */ - private $hasLogin = null; + private ?bool $hasLogin = null; /** * @param int $components @@ -122,7 +122,7 @@ class User extends Users */ public function logout() { - self::pluginHandle()->trigger($logoutPluggable)->logout(); + self::pluginHandle()->trigger($logoutPluggable)->call('logout'); if ($logoutPluggable) { return; } @@ -145,7 +145,7 @@ class User extends Users public function login(string $name, string $password, bool $temporarily = false, int $expire = 0): bool { //插件接口 - $result = self::pluginHandle()->trigger($loginPluggable)->login($name, $password, $temporarily, $expire); + $result = self::pluginHandle()->trigger($loginPluggable)->call('login', $name, $password, $temporarily, $expire); if ($loginPluggable) { return $result; } @@ -160,7 +160,7 @@ class User extends Users return false; } - $hashValidate = self::pluginHandle()->trigger($hashPluggable)->hashValidate($password, $user['password']); + $hashValidate = self::pluginHandle()->trigger($hashPluggable)->call('hashValidate', $password, $user['password']); if (!$hashPluggable) { if ('$P$' == substr($user['password'], 0, 3)) { $hasher = new PasswordHash(8, true); @@ -170,7 +170,7 @@ class User extends Users } } - if ($user && $hashValidate) { + if ($hashValidate) { if (!$temporarily) { $this->commitLogin($user, $expire); } @@ -179,12 +179,12 @@ class User extends Users $this->push($user); $this->currentUser = $user; $this->hasLogin = true; - self::pluginHandle()->loginSucceed($this, $name, $password, $temporarily, $expire); + self::pluginHandle()->call('loginSucceed', $this, $name, $password, $temporarily, $expire); return true; } - self::pluginHandle()->loginFail($this, $name, $password, $temporarily, $expire); + self::pluginHandle()->call('loginFail', $this, $name, $password, $temporarily, $expire); return false; } @@ -231,7 +231,7 @@ class User extends Users } if (empty($user)) { - self::pluginHandle()->simpleLoginFail($this); + self::pluginHandle()->call('simpleLoginFail', $this); return false; } @@ -243,7 +243,7 @@ class User extends Users $this->currentUser = $user; $this->hasLogin = true; - self::pluginHandle()->simpleLoginSucceed($this, $user); + self::pluginHandle()->call('simpleLoginSucceed', $this, $user); return true; } @@ -269,7 +269,7 @@ class User extends Users //防止循环重定向 $this->response->redirect(defined('__TYPECHO_ADMIN__') ? $this->options->loginUrl . (0 === strpos($this->request->getReferer() ?? '', $this->options->loginUrl) ? '' : - '?referer=' . urlencode($this->request->makeUriByRequest())) : $this->options->siteUrl, false); + '?referer=' . urlencode($this->request->makeUriByRequest())) : $this->options->siteUrl); } } diff --git a/var/Widget/Users/Admin.php b/var/Widget/Users/Admin.php index 4065d6fa..a45e82c9 100644 --- a/var/Widget/Users/Admin.php +++ b/var/Widget/Users/Admin.php @@ -29,21 +29,21 @@ class Admin extends Users * * @var Query */ - private $countSql; + private Query $countSql; /** * 所有文章个数 * * @var integer */ - private $total; + private int $total; /** * 当前页 * * @var integer */ - private $currentPage; + private int $currentPage; /** * 执行函数 @@ -57,7 +57,7 @@ class Admin extends Users $this->currentPage = $this->request->get('page', 1); /** 过滤标题 */ - if (null != ($keywords = $this->request->keywords)) { + if (null != ($keywords = $this->request->get('keywords'))) { $select->where( 'name LIKE ? OR screenName LIKE ?', '%' . Common::filterSearchQuery($keywords) . '%', @@ -67,7 +67,7 @@ class Admin extends Users $this->countSql = clone $select; - $select->order('table.users.uid', Db::SORT_ASC) + $select->order('table.users.uid') ->page($this->currentPage, $this->parameter->pageSize); $this->db->fetchAll($select, [$this, 'push']); diff --git a/var/Widget/Users/Edit.php b/var/Widget/Users/Edit.php index 108cf65b..35e9ea1e 100644 --- a/var/Widget/Users/Edit.php +++ b/var/Widget/Users/Edit.php @@ -36,9 +36,9 @@ class Edit extends Users implements ActionInterface $this->user->pass('administrator'); /** 更新模式 */ - if (($this->request->uid && 'delete' != $this->request->do) || 'update' == $this->request->do) { + if (($this->request->is('uid') && 'delete' != $this->request->get('do')) || $this->request->is('do=update')) { $this->db->fetchRow($this->select() - ->where('uid = ?', $this->request->uid)->limit(1), [$this, 'push']); + ->where('uid = ?', $this->request->get('uid'))->limit(1), [$this, 'push']); if (!$this->have()) { throw new Exception(_t('用户不存在'), 404); @@ -143,7 +143,7 @@ class Edit extends Users implements ActionInterface $form->addInput($confirm); /** 个人主页地址 */ - $url = new Form\Element\Text('url', null, null, _t('个人主页地址'), _t('此用户的个人主页地址, 请用 <code>http://</code> 开头.')); + $url = new Form\Element\Text('url', null, null, _t('个人主页地址'), _t('此用户的个人主页地址, 请用 <code>https://</code> 开头.')); $form->addInput($url); /** 用户组 */ @@ -172,7 +172,7 @@ class Edit extends Users implements ActionInterface $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); - if (null != $this->request->uid) { + if ($this->request->is('uid')) { $submit->value(_t('编辑用户')); $name->value($this->name); $screenName->value($this->screenName); @@ -244,17 +244,17 @@ class Edit extends Users implements ActionInterface } /** 更新数据 */ - $this->update($user, $this->db->sql()->where('uid = ?', $this->request->uid)); + $this->update($user, $this->db->sql()->where('uid = ?', $this->request->get('uid'))); /** 设置高亮 */ - Notice::alloc()->highlight('user-' . $this->request->uid); + Notice::alloc()->highlight('user-' . $this->request->get('uid')); /** 提示信息 */ Notice::alloc()->set(_t('用户 %s 已经被更新', $user['screenName']), 'success'); /** 转向原页 */ $this->response->redirect(Common::url('manage-users.php?' . - $this->getPageOffsetQuery($this->request->uid), $this->options->adminUrl)); + $this->getPageOffsetQuery($this->request->get('uid')), $this->options->adminUrl)); } /** diff --git a/var/Widget/Users/Profile.php b/var/Widget/Users/Profile.php index ae7da4e4..4b97e7f7 100644 --- a/var/Widget/Users/Profile.php +++ b/var/Widget/Users/Profile.php @@ -148,7 +148,7 @@ class Profile extends Edit implements ActionInterface * @param string|null $group 用户组 * @throws Plugin\Exception */ - public function personalForm(string $pluginName, string $className, string $pluginFileName, ?string &$group) + public function personalForm(string $pluginName, string $className, string $pluginFileName, ?string &$group): Form { /** 构建表格 */ $form = new Form($this->security->getIndex('/action/users-profile'), Form::POST_METHOD); @@ -208,7 +208,7 @@ class Profile extends Edit implements ActionInterface * * @return Form */ - public function profileForm() + public function profileForm(): Form { /** 构建表格 */ $form = new Form($this->security->getIndex('/action/users-profile'), Form::POST_METHOD); @@ -219,7 +219,7 @@ class Profile extends Edit implements ActionInterface $form->addInput($screenName); /** 个人主页地址 */ - $url = new Form\Element\Text('url', null, null, _t('个人主页地址'), _t('此用户的个人主页地址, 请用 <code>http://</code> 开头.')); + $url = new Form\Element\Text('url', null, null, _t('个人主页地址'), _t('此用户的个人主页地址, 请用 <code>https://</code> 开头.')); $form->addInput($url); /** 电子邮箱地址 */ @@ -258,9 +258,9 @@ class Profile extends Edit implements ActionInterface */ public function updateOptions() { - $settings['autoSave'] = $this->request->autoSave ? 1 : 0; - $settings['markdown'] = $this->request->markdown ? 1 : 0; - $settings['xmlrpcMarkdown'] = $this->request->xmlrpcMarkdown ? 1 : 0; + $settings['autoSave'] = $this->request->is('autoSave=1') ? 1 : 0; + $settings['markdown'] = $this->request->is('markdown=1') ? 1 : 0; + $settings['xmlrpcMarkdown'] = $this->request->is('xmlrpcMarkdown=1') ? 1 : 0; $defaultAllow = $this->request->getArray('defaultAllow'); $settings['defaultAllowComment'] = in_array('comment', $defaultAllow) ? 1 : 0; @@ -366,7 +366,7 @@ class Profile extends Edit implements ActionInterface public function updatePersonal() { /** 获取插件名称 */ - $pluginName = $this->request->plugin; + $pluginName = $this->request->get('plugin'); /** 获取已启用插件 */ $plugins = Plugin::export(); @@ -374,7 +374,7 @@ class Profile extends Edit implements ActionInterface /** 获取插件入口 */ [$pluginFileName, $className] = Plugin::portal( - $this->request->plugin, + $pluginName, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__ ); $info = Plugin::parseInfo($pluginFileName); diff --git a/var/Widget/XmlRpc.php b/var/Widget/XmlRpc.php index 4397ed2c..6f0b914b 100644 --- a/var/Widget/XmlRpc.php +++ b/var/Widget/XmlRpc.php @@ -3,7 +3,6 @@ namespace Widget; use IXR\Date; -use IXR\Error; use IXR\Exception; use IXR\Hook; use IXR\Pingback; @@ -43,28 +42,13 @@ if (!defined('__TYPECHO_ROOT_DIR__')) { */ class XmlRpc extends Contents implements ActionInterface, Hook { - /** - * 当前错误 - * - * @var Error - */ - private $error; - /** * wordpress风格的系统选项 * * @access private * @var array */ - private $wpOptions; - - /** - * 已经使用过的组件列表 - * - * @access private - * @var array - */ - private $usedWidgetNameList = []; + private array $wpOptions; /** * 如果这里没有重载, 每次都会被默认执行 @@ -354,7 +338,7 @@ class XmlRpc extends Contents implements ActionInterface, Hook $input['text'] = !empty($content['mt_text_more']) ? $content['description'] . "\n<!--more-->\n" . $content['mt_text_more'] : $content['description']; - $input['text'] = self::pluginHandle()->textFilter($input['text'], $this); + $input['text'] = self::pluginHandle()->call('textFilter', $input['text'], $this); $input['password'] = $content["wp_password"] ?? null; $input['order'] = $content["wp_page_order"] ?? null; @@ -1400,7 +1384,7 @@ class XmlRpc extends Contents implements ActionInterface, Hook ->where('table.contents.type = ?', 'attachment'), [$this, 'push']); /** 增加插件接口 */ - self::pluginHandle()->upload($this); + self::pluginHandle()->call('upload', $this); return [ 'file' => $this->attachment->name, @@ -1733,13 +1717,13 @@ class XmlRpc extends Contents implements ActionInterface, Hook ]; /** 加入plugin */ - $pingback = self::pluginHandle()->pingback($pingback, $post); + $pingback = self::pluginHandle()->call('pingback', $pingback, $post); /** 执行插入*/ $insertId = Comments::alloc()->insert($pingback); /** 评论完成接口 */ - self::pluginHandle()->finishPingback($this); + self::pluginHandle()->call('finishPingback', $this); return $insertId; } catch (WidgetException $e) { @@ -1774,7 +1758,7 @@ class XmlRpc extends Contents implements ActionInterface, Hook <rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd"> <service> <engineName>Typecho</engineName> - <engineLink>http://www.typecho.org/</engineLink> + <engineLink>https://typecho.org/</engineLink> <homePageLink>{$this->options->siteUrl}</homePageLink> <apis> <api name="WordPress" blogID="1" preferred="true" apiLink="{$this->options->xmlRpcUrl}" />