From 7db5f3c87353cf21ddc95308046507ff0a9de35d Mon Sep 17 00:00:00 2001 From: joyqi Date: Wed, 1 Sep 2021 18:27:03 +0800 Subject: [PATCH] change all --- install.php | 4 +- var/Typecho/Widget.php | 5 +- var/{ => Utils}/AutoP.php | 37 ++-- var/{ => Utils}/Helper.php | 237 +++++++++++--------- var/{ => Utils}/HyperDown.php | 2 + var/{ => Utils}/Markdown.php | 5 +- var/{ => Utils}/PasswordHash.php | 174 +++++++++------ var/{ => Utils}/Upgrade.php | 348 +++++++++++++++--------------- var/Widget/Backup.php | 4 +- var/Widget/Base/Comments.php | 21 +- var/Widget/Base/Contents.php | 22 +- var/Widget/Base/Metas.php | 2 +- var/Widget/Base/Users.php | 2 +- var/Widget/Contents/Post/Edit.php | 4 +- var/Widget/Feedback.php | 3 +- var/Widget/Init.php | 6 + var/Widget/Options.php | 83 +++---- var/Widget/Register.php | 5 +- var/Widget/Service.php | 2 +- var/Widget/Upload.php | 4 +- var/Widget/User.php | 5 +- var/Widget/Users/Edit.php | 9 +- var/Widget/Users/Profile.php | 5 +- 23 files changed, 541 insertions(+), 448 deletions(-) rename var/{ => Utils}/AutoP.php (86%) rename var/{ => Utils}/Helper.php (65%) rename var/{ => Utils}/HyperDown.php (99%) rename var/{ => Utils}/Markdown.php (89%) rename var/{ => Utils}/PasswordHash.php (64%) rename var/{ => Utils}/Upgrade.php (81%) diff --git a/install.php b/install.php index af19e9b9..9e36312d 100644 --- a/install.php +++ b/install.php @@ -1257,11 +1257,11 @@ function install_step_3_perform() } // write user - $hasher = new PasswordHash(8, true); + $hasher = new \Utils\PasswordHash(8, true); $installDb->query( $installDb->insert('table.users')->rows([ 'name' => $config['userName'], - 'password' => $hasher->HashPassword($config['userPassword']), + 'password' => $hasher->hashPassword($config['userPassword']), 'mail' => $config['userMail'], 'url' => $options->siteUrl, 'screenName' => $config['userName'], diff --git a/var/Typecho/Widget.php b/var/Typecho/Widget.php index 11d48172..80cbafc9 100644 --- a/var/Typecho/Widget.php +++ b/var/Typecho/Widget.php @@ -344,12 +344,11 @@ abstract class Widget /** * 获取对象插件句柄 * - * @param string|null $handle 句柄 * @return Plugin */ - public function pluginHandle(?string $handle = null): Plugin + public static function pluginHandle(): Plugin { - return Plugin::factory(empty($handle) ? static::class : $handle); + return Plugin::factory(static::class); } /** diff --git a/var/AutoP.php b/var/Utils/AutoP.php similarity index 86% rename from var/AutoP.php rename to var/Utils/AutoP.php index 35cf27e7..d52a9242 100644 --- a/var/AutoP.php +++ b/var/Utils/AutoP.php @@ -1,5 +1,7 @@ cutByBlock($text); if (false !== strpos($text, '

')) { - $text = $this->fixPragraph($text); + $text = $this->fixParagraph($text); } break; default: @@ -73,11 +74,10 @@ class AutoP /** * 用段落方法处理换行 * - * @access private * @param string $text * @return string */ - private function cutByBlock($text) + private function cutByBlock(string $text): string { $space = "( | )"; $text = str_replace("\r\n", "\n", trim($text)); @@ -95,11 +95,10 @@ class AutoP /** * 修复段落开头和结尾 * - * @access private * @param string $text * @return string */ - private function fixPragraph($text) + private function fixParagraph(string $text): string { $text = trim($text); if (!preg_match("/^<(" . self::BLOCK . ")(\s|>)/i", $text)) { @@ -117,11 +116,9 @@ class AutoP * 自动分段 * * @param string $text - * @static - * @access private * @return string */ - public function parse($text) + public function parse(string $text): string { /** 重置计数器 */ $this->uniqueId = 0; @@ -164,15 +161,24 @@ class AutoP $tagLength = strlen($tag); $text = substr_replace($text, $uniqueId, $pos + 1 + $tagLength, 0); - $text = substr_replace($text, $uniqueId, $match[1] + 7 + $foundTagCount * 10 + $tagLength, 0); // 7 = 5 + 2 - $foundTagCount ++; + $text = substr_replace( + $text, + $uniqueId, + $match[1] + 7 + $foundTagCount * 10 + $tagLength, + 0 + ); // 7 = 5 + 2 + $foundTagCount++; } } } foreach ($uniqueIdList as $uniqueId => $tag) { - $text = preg_replace_callback("/<({$tag})({$uniqueId})([^>]*)>(.*)<\/\\1\\2>/is", - [$this, 'replaceBlockCallback'], $text, 1); + $text = preg_replace_callback( + "/<({$tag})({$uniqueId})([^>]*)>(.*)<\/\\1\\2>/is", + [$this, 'replaceBlockCallback'], + $text, + 1 + ); } $text = $this->cutByBlock($text); @@ -182,16 +188,15 @@ class AutoP $text = str_replace($blockKey, $blockValue, $text); } - return $this->fixPragraph($text); + return $this->fixParagraph($text); } /** * 生成唯一的id, 为了速度考虑最多支持1万个tag的处理 * - * @access private * @return string */ - private function makeUniqueId() + private function makeUniqueId(): string { return ':' . str_pad($this->uniqueId ++, 4, '0', STR_PAD_LEFT); } diff --git a/var/Helper.php b/var/Utils/Helper.php similarity index 65% rename from var/Helper.php rename to var/Utils/Helper.php index f0367d35..6c25df5b 100644 --- a/var/Helper.php +++ b/var/Utils/Helper.php @@ -1,5 +1,18 @@ 'cid', 'Comments' => 'coid', - 'Metas' => 'mid', - 'Users' => 'uid' + 'Metas' => 'mid', + 'Users' => 'uid' ]; - $className = "Widget_Abstract_{$table}"; + $className = '\Widget\Base\\' . $table; + $key = $keys[$table]; - $db = Typecho_Db::get(); - $widget = new $className(Typecho_Request::getInstance(), Typecho_Widget_Helper_Empty::getInstance()); + $db = Db::get(); + $widget = Widget::widget($className); $db->fetchRow( $widget->select()->where("{$key} = ?", $pkId)->limit(1), - [$widget, 'push']); + [$widget, 'push'] + ); return $widget; } @@ -61,49 +77,51 @@ class Helper */ public static function requestService($method, $params) { - Typecho_Widget::widget('Widget_Service')->requestService($method, $params); + Service::alloc()->requestService($method, $params); } /** * 强行删除某个插件 * - * @access public * @param string $pluginName 插件名称 - * @return void */ - public static function removePlugin($pluginName) + public static function removePlugin(string $pluginName) { try { /** 获取插件入口 */ - [$pluginFileName, $className] = Typecho_Plugin::portal($pluginName, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__); + [$pluginFileName, $className] = Plugin::portal( + $pluginName, + __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__ + ); /** 获取已启用插件 */ - $plugins = Typecho_Plugin::export(); + $plugins = Plugin::export(); $activatedPlugins = $plugins['activated']; /** 载入插件 */ require_once $pluginFileName; /** 判断实例化是否成功 */ - if (!isset($activatedPlugins[$pluginName]) || !class_exists($className) - || !method_exists($className, 'deactivate')) { - throw new Typecho_Widget_Exception(_t('无法禁用插件'), 500); + if ( + !isset($activatedPlugins[$pluginName]) || !class_exists($className) + || !method_exists($className, 'deactivate') + ) { + throw new Widget\Exception(_t('无法禁用插件'), 500); } - $result = call_user_func([$className, 'deactivate']); - - } catch (Exception $e) { + call_user_func([$className, 'deactivate']); + } catch (\Exception $e) { //nothing to do } - $db = Typecho_Db::get(); + $db = Db::get(); try { - Typecho_Plugin::deactivate($pluginName); + Plugin::deactivate($pluginName); $db->query($db->update('table.options') - ->rows(['value' => serialize(Typecho_Plugin::export())]) + ->rows(['value' => serialize(Plugin::export())]) ->where('name = ?', 'plugins')); - } catch (Typecho_Plugin_Exception $e) { + } catch (Plugin\Exception $e) { //nothing to do } @@ -113,18 +131,16 @@ class Helper /** * 导入语言项 * - * @access public * @param string $domain - * @return void */ - public static function lang($domain) + public static function lang(string $domain) { - $currentLang = Typecho_I18n::getLang(); + $currentLang = I18n::getLang(); if ($currentLang) { $currentLang = basename($currentLang); $fileName = dirname(__FILE__) . '/' . $domain . '/lang/' . $currentLang; if (file_exists($fileName)) { - Typecho_I18n::addLang($fileName); + I18n::addLang($fileName); } } } @@ -132,16 +148,20 @@ class Helper /** * 增加路由 * - * @access public * @param string $name 路由名称 * @param string $url 路由路径 * @param string $widget 组件名称 - * @param string $action 组件动作 - * @param string $after 在某个路由后面 + * @param string|null $action 组件动作 + * @param string|null $after 在某个路由后面 * @return integer */ - public static function addRoute($name, $url, $widget, $action = null, $after = null) - { + public static function addRoute( + string $name, + string $url, + string $widget, + ?string $action = null, + ?string $after = null + ): int { $routingTable = self::options()->routingTable; if (isset($routingTable[0])) { unset($routingTable[0]); @@ -149,7 +169,7 @@ class Helper $pos = 0; foreach ($routingTable as $key => $val) { - $pos ++; + $pos++; if ($key == $after) { break; @@ -159,37 +179,38 @@ class Helper $pre = array_slice($routingTable, 0, $pos); $next = array_slice($routingTable, $pos); - $routingTable = array_merge($pre, [$name => [ - 'url' => $url, - 'widget' => $widget, - 'action' => $action - ]], $next); + $routingTable = array_merge($pre, [ + $name => [ + 'url' => $url, + 'widget' => $widget, + 'action' => $action + ] + ], $next); self::options()->routingTable = $routingTable; - $db = Typecho_Db::get(); - return Typecho_Widget::widget('Widget_Abstract_Options')->update(['value' => serialize($routingTable)] - , $db->sql()->where('name = ?', 'routingTable')); + return BaseOptions::alloc()->update( + ['value' => serialize($routingTable)], + Db::get()->sql()->where('name = ?', 'routingTable') + ); } /** * 获取Widget_Options对象 * - * @access public - * @return Widget_Options + * @return Options */ - public static function options() + public static function options(): Options { - return Typecho_Widget::widget('Widget_Options'); + return Options::alloc(); } /** * 移除路由 * - * @access public * @param string $name 路由名称 * @return integer */ - public static function removeRoute($name) + public static function removeRoute(string $name): int { $routingTable = self::options()->routingTable; if (isset($routingTable[0])) { @@ -199,38 +220,39 @@ class Helper unset($routingTable[$name]); self::options()->routingTable = $routingTable; - $db = Typecho_Db::get(); - return Typecho_Widget::widget('Widget_Abstract_Options')->update(['value' => serialize($routingTable)] - , $db->sql()->where('name = ?', 'routingTable')); + $db = Db::get(); + return BaseOptions::alloc()->update( + ['value' => serialize($routingTable)], + $db->sql()->where('name = ?', 'routingTable') + ); } /** * 增加action扩展 * - * @access public * @param string $actionName 需要扩展的action名称 * @param string $widgetName 需要扩展的widget名称 * @return integer */ - public static function addAction($actionName, $widgetName) + public static function addAction(string $actionName, string $widgetName): int { $actionTable = unserialize(self::options()->actionTable); $actionTable = empty($actionTable) ? [] : $actionTable; $actionTable[$actionName] = $widgetName; - $db = Typecho_Db::get(); - return Typecho_Widget::widget('Widget_Abstract_Options')->update(['value' => (self::options()->actionTable = serialize($actionTable))] - , $db->sql()->where('name = ?', 'actionTable')); + return BaseOptions::alloc()->update( + ['value' => (self::options()->actionTable = serialize($actionTable))], + Db::get()->sql()->where('name = ?', 'actionTable') + ); } /** * 删除action扩展 * - * @access public * @param string $actionName - * @return Typecho_Widget + * @return int */ - public static function removeAction($actionName) + public static function removeAction(string $actionName): int { $actionTable = unserialize(self::options()->actionTable); $actionTable = empty($actionTable) ? [] : $actionTable; @@ -240,27 +262,28 @@ class Helper reset($actionTable); } - $db = Typecho_Db::get(); - return Typecho_Widget::widget('Widget_Abstract_Options')->update(['value' => (self::options()->actionTable = serialize($actionTable))] - , $db->sql()->where('name = ?', 'actionTable')); + return BaseOptions::alloc()->update( + ['value' => (self::options()->actionTable = serialize($actionTable))], + Db::get()->sql()->where('name = ?', 'actionTable') + ); } /** * 增加一个菜单 * - * @access public * @param string $menuName 菜单名 * @return integer */ - public static function addMenu($menuName) + public static function addMenu(string $menuName): int { $panelTable = unserialize(self::options()->panelTable); $panelTable['parent'] = empty($panelTable['parent']) ? [] : $panelTable['parent']; $panelTable['parent'][] = $menuName; - $db = Typecho_Db::get(); - Typecho_Widget::widget('Widget_Abstract_Options')->update(['value' => (self::options()->panelTable = serialize($panelTable))] - , $db->sql()->where('name = ?', 'panelTable')); + BaseOptions::alloc()->update( + ['value' => (self::options()->panelTable = serialize($panelTable))], + Db::get()->sql()->where('name = ?', 'panelTable') + ); end($panelTable['parent']); return key($panelTable['parent']) + 10; @@ -269,11 +292,10 @@ class Helper /** * 移除一个菜单 * - * @access public * @param string $menuName 菜单名 * @return integer */ - public static function removeMenu($menuName) + public static function removeMenu(string $menuName): int { $panelTable = unserialize(self::options()->panelTable); $panelTable['parent'] = empty($panelTable['parent']) ? [] : $panelTable['parent']; @@ -282,9 +304,10 @@ class Helper unset($panelTable['parent'][$index]); } - $db = Typecho_Db::get(); - Typecho_Widget::widget('Widget_Abstract_Options')->update(['value' => (self::options()->panelTable = serialize($panelTable))] - , $db->sql()->where('name = ?', 'panelTable')); + BaseOptions::alloc()->update( + ['value' => (self::options()->panelTable = serialize($panelTable))], + Db::get()->sql()->where('name = ?', 'panelTable') + ); return $index + 10; } @@ -292,7 +315,6 @@ class Helper /** * 增加一个面板 * - * @access public * @param integer $index 菜单索引 * @param string $fileName 文件名称 * @param string $title 面板标题 @@ -302,21 +324,30 @@ class Helper * @param string $addLink 新增项目链接, 会显示在页面标题之后 * @return integer */ - public static function addPanel($index, $fileName, $title, $subTitle, $level, $hidden = false, $addLink = '') - { + public static function addPanel( + int $index, + string $fileName, + string $title, + string $subTitle, + string $level, + bool $hidden = false, + string $addLink = '' + ): int { $panelTable = unserialize(self::options()->panelTable); $panelTable['child'] = empty($panelTable['child']) ? [] : $panelTable['child']; $panelTable['child'][$index] = empty($panelTable['child'][$index]) ? [] : $panelTable['child'][$index]; $fileName = urlencode(trim($fileName, '/')); - $panelTable['child'][$index][] = [$title, $subTitle, 'extending.php?panel=' . $fileName, $level, $hidden, $addLink]; + $panelTable['child'][$index][] + = [$title, $subTitle, 'extending.php?panel=' . $fileName, $level, $hidden, $addLink]; $panelTable['file'] = empty($panelTable['file']) ? [] : $panelTable['file']; $panelTable['file'][] = $fileName; $panelTable['file'] = array_unique($panelTable['file']); - $db = Typecho_Db::get(); - Typecho_Widget::widget('Widget_Abstract_Options')->update(['value' => (self::options()->panelTable = serialize($panelTable))] - , $db->sql()->where('name = ?', 'panelTable')); + BaseOptions::alloc()->update( + ['value' => (self::options()->panelTable = serialize($panelTable))], + Db::get()->sql()->where('name = ?', 'panelTable') + ); end($panelTable['child'][$index]); return key($panelTable['child'][$index]); @@ -325,12 +356,11 @@ class Helper /** * 移除一个面板 * - * @access public * @param integer $index 菜单索引 * @param string $fileName 文件名称 * @return integer */ - public static function removePanel($index, $fileName) + public static function removePanel(int $index, string $fileName): int { $panelTable = unserialize(self::options()->panelTable); $panelTable['child'] = empty($panelTable['child']) ? [] : $panelTable['child']; @@ -350,41 +380,38 @@ class Helper } } - $db = Typecho_Db::get(); - Typecho_Widget::widget('Widget_Abstract_Options')->update(['value' => (self::options()->panelTable = serialize($panelTable))] - , $db->sql()->where('name = ?', 'panelTable')); + BaseOptions::alloc()->update( + ['value' => (self::options()->panelTable = serialize($panelTable))], + Db::get()->sql()->where('name = ?', 'panelTable') + ); return $return; } /** * 获取面板url * - * @access public * @param string $fileName * @return string */ - public static function url($fileName) + public static function url(string $fileName): string { - return Typecho_Common::url('extending.php?panel=' . (trim($fileName, '/')), self::options()->adminUrl); + return Common::url('extending.php?panel=' . (trim($fileName, '/')), self::options()->adminUrl); } /** * 手动配置插件变量 * - * @access public - * @static * @param mixed $pluginName 插件名称 * @param array $settings 变量键值对 * @param bool $isPersonal . (default: false) 是否为私人变量 - * @return void */ - public static function configPlugin($pluginName, array $settings, $isPersonal = false) + public static function configPlugin($pluginName, array $settings, bool $isPersonal = false) { if (empty($settings)) { return; } - Widget_Plugins_Edit::configPlugin($pluginName, $settings, $isPersonal); + Edit::configPlugin($pluginName, $settings, $isPersonal); } /** @@ -398,8 +425,13 @@ class Helper * @param integer $style 样式类型 * @return void */ - public static function replyLink($theId, $coid, $word = 'Reply', $formId = 'respond', $style = 2) - { + public static function replyLink( + string $theId, + int $coid, + string $word = 'Reply', + string $formId = 'respond', + int $style = 2 + ) { if (self::options()->commentsThreaded) { echo '' . $word . ''; @@ -409,12 +441,10 @@ class Helper /** * 评论取消按钮 * - * @access public * @param string $word 按钮文字 * @param string $formId 表单id - * @return void */ - public static function cancelCommentReplyLink($word = 'Cancel', $formId = 'respond') + public static function cancelCommentReplyLink(string $word = 'Cancel', string $formId = 'respond') { if (self::options()->commentsThreaded) { echo 'itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; - if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) + if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) { $iteration_count_log2 = 8; + } + $this->iteration_count_log2 = $iteration_count_log2; $this->portable_hashes = $portable_hashes; @@ -53,34 +39,45 @@ class PasswordHash $this->random_state = microtime() . uniqid(rand(), true); // removed getmypid() for compability reasons } - function HashPassword($password) + /** + * @param string $password + * @return string + */ + public function hashPassword(string $password): string { $random = ''; if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) { - $random = $this->get_random_bytes(16); + $random = $this->getRandomBytes(16); $hash = - crypt($password, $this->gensalt_blowfish($random)); - if (strlen($hash) == 60) + crypt($password, $this->gensaltBlowfish($random)); + + if (strlen($hash) == 60) { return $hash; + } } if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) { - if (strlen($random) < 3) - $random = $this->get_random_bytes(3); + if (strlen($random) < 3) { + $random = $this->getRandomBytes(3); + } + $hash = - crypt($password, $this->gensalt_extended($random)); - if (strlen($hash) == 20) + crypt($password, $this->gensaltExtended($random)); + + if (strlen($hash) == 20) { return $hash; + } } - if (strlen($random) < 6) - $random = $this->get_random_bytes(6); - $hash = - $this->crypt_private($password, - $this->gensalt_private($random)); - if (strlen($hash) == 34) + if (strlen($random) < 6) { + $random = $this->getRandomBytes(6); + } + + $hash = $this->cryptPrivate($password, $this->gensaltPrivate($random)); + if (strlen($hash) == 34) { return $hash; + } # Returning '*' on error is safe here, but would _not_ be safe # in a crypt(3)-like function used _both_ for generating new @@ -88,11 +85,14 @@ class PasswordHash return '*'; } - function get_random_bytes($count) + /** + * @param int $count + * @return string + */ + private function getRandomBytes(int $count): string { $output = ''; - if (@is_readable('/dev/urandom') && - ($fh = @fopen('/dev/urandom', 'rb'))) { + if (@is_readable('/dev/urandom') && ($fh = @fopen('/dev/urandom', 'rb'))) { $output = fread($fh, $count); fclose($fh); } @@ -111,7 +111,11 @@ class PasswordHash return $output; } - function gensalt_blowfish($input) + /** + * @param string $input + * @return string + */ + private function gensaltBlowfish(string $input): string { # This one needs to use a different order of characters and a # different encoding scheme from the one in encode64() above. @@ -130,7 +134,7 @@ class PasswordHash $i = 0; do { - $c1 = ord($input[$i ++]); + $c1 = ord($input[$i++]); $output .= $itoa64[$c1 >> 2]; $c1 = ($c1 & 0x03) << 4; if ($i >= 16) { @@ -138,12 +142,12 @@ class PasswordHash break; } - $c2 = ord($input[$i ++]); + $c2 = ord($input[$i++]); $c1 |= $c2 >> 4; $output .= $itoa64[$c1]; $c1 = ($c2 & 0x0f) << 2; - $c2 = ord($input[$i ++]); + $c2 = ord($input[$i++]); $c1 |= $c2 >> 6; $output .= $itoa64[$c1]; $output .= $itoa64[$c2 & 0x3f]; @@ -152,7 +156,11 @@ class PasswordHash return $output; } - function gensalt_extended($input) + /** + * @param string $input + * @return string + */ + private function gensaltExtended(string $input): string { $count_log2 = min($this->iteration_count_log2 + 8, 24); # This should be odd to not reveal weak DES keys, and the @@ -170,47 +178,65 @@ class PasswordHash return $output; } - function encode64($input, $count) + /** + * @param string $input + * @param int $count + * @return string + */ + private function encode64(string $input, int $count): string { $output = ''; $i = 0; do { - $value = ord($input[$i ++]); + $value = ord($input[$i++]); $output .= $this->itoa64[$value & 0x3f]; - if ($i < $count) + if ($i < $count) { $value |= ord($input[$i]) << 8; + } $output .= $this->itoa64[($value >> 6) & 0x3f]; - if ($i ++ >= $count) + if ($i++ >= $count) { break; - if ($i < $count) + } + if ($i < $count) { $value |= ord($input[$i]) << 16; + } $output .= $this->itoa64[($value >> 12) & 0x3f]; - if ($i ++ >= $count) + if ($i++ >= $count) { break; + } $output .= $this->itoa64[($value >> 18) & 0x3f]; } while ($i < $count); return $output; } - function crypt_private($password, $setting) + /** + * @param string $password + * @param string $setting + * @return string + */ + private function cryptPrivate(string $password, string $setting): string { $output = '*0'; - if (substr($setting, 0, 2) == $output) + if (substr($setting, 0, 2) == $output) { $output = '*1'; + } - if (substr($setting, 0, 3) != '$P$') + if (substr($setting, 0, 3) != '$P$') { return $output; + } $count_log2 = strpos($this->itoa64, $setting[3]); - if ($count_log2 < 7 || $count_log2 > 30) + if ($count_log2 < 7 || $count_log2 > 30) { return $output; + } $count = 1 << $count_log2; $salt = substr($setting, 4, 8); - if (strlen($salt) != 8) + if (strlen($salt) != 8) { return $output; + } # We're kind of forced to use MD5 here since it's the only # cryptographic primitive available in all versions of PHP @@ -222,12 +248,12 @@ class PasswordHash $hash = md5($salt . $password, true); do { $hash = md5($hash . $password, true); - } while (-- $count); + } while (--$count); } else { $hash = pack('H*', md5($salt . $password)); do { $hash = pack('H*', md5($hash . $password)); - } while (-- $count); + } while (--$count); } $output = substr($setting, 0, 12); @@ -236,7 +262,11 @@ class PasswordHash return $output; } - function gensalt_private($input) + /** + * @param string $input + * @return string + */ + private function gensaltPrivate(string $input): string { $output = '$P$'; $output .= $this->itoa64[min($this->iteration_count_log2 + @@ -246,11 +276,17 @@ class PasswordHash return $output; } - function CheckPassword($password, $stored_hash) + /** + * @param string $password + * @param string $stored_hash + * @return bool + */ + public function checkPassword(string $password, string $stored_hash): bool { - $hash = $this->crypt_private($password, $stored_hash); - if ($hash[0] == '*') + $hash = $this->cryptPrivate($password, $stored_hash); + if ($hash[0] == '*') { $hash = crypt($password, $stored_hash); + } return $hash == $stored_hash; } diff --git a/var/Upgrade.php b/var/Utils/Upgrade.php similarity index 81% rename from var/Upgrade.php rename to var/Utils/Upgrade.php index 10ea993e..4894059b 100644 --- a/var/Upgrade.php +++ b/var/Utils/Upgrade.php @@ -1,13 +1,13 @@ query($db->select('coid', 'text')->from('table.comments') - ->order('coid', Typecho_Db::SORT_ASC)->page($i, 100)); + ->order('coid', Db::SORT_ASC)->page($i, 100)); $j = 0; while ($row = $db->fetchRow($result)) { @@ -44,7 +44,7 @@ class Upgrade ->rows(['text' => $text]) ->where('coid = ?', $row['coid'])); - $j ++; + $j++; unset($text); unset($row); } @@ -53,7 +53,7 @@ class Upgrade break; } - $i ++; + $i++; unset($result); } @@ -62,21 +62,24 @@ class Upgrade while (true) { $result = $db->query($db->select('cid', 'text')->from('table.contents') - ->order('cid', Typecho_Db::SORT_ASC)->page($i, 100)); + ->order('cid', Db::SORT_ASC)->page($i, 100)); $j = 0; while ($row = $db->fetchRow($result)) { $text = preg_replace( - ["/\s*

/is", "/\s*<\/p>\s*/is", "/\s*\s*/is", - "/\s*<(div|blockquote|pre|table|ol|ul)>/is", "/<\/(div|blockquote|pre|table|ol|ul)>\s*/is"], + [ + "/\s*

/is", "/\s*<\/p>\s*/is", "/\s*\s*/is", + "/\s*<(div|blockquote|pre|table|ol|ul)>/is", "/<\/(div|blockquote|pre|table|ol|ul)>\s*/is" + ], ['', "\n\n", "\n", "\n\n<\\1>", "\n\n"], - $row['text']); + $row['text'] + ); $db->query($db->update('table.contents') ->rows(['text' => $text]) ->where('cid = ?', $row['cid'])); - $j ++; + $j++; unset($text); unset($row); } @@ -85,7 +88,7 @@ class Upgrade break; } - $i ++; + $i++; unset($result); } } @@ -94,8 +97,8 @@ class Upgrade * 升级至9.1.14 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_4r9_1_14($db, $options) @@ -108,7 +111,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); '); fclose($handle); } else { - throw new Typecho_Exception(_t('config.inc.php 文件无法写入, 请将它的权限设置为可写')); + throw new Exception(_t('config.inc.php 文件无法写入, 请将它的权限设置为可写')); } } @@ -116,8 +119,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至9.2.3 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_5r9_2_3($db, $options) @@ -127,7 +130,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); while (true) { $result = $db->query($db->select('coid', 'text')->from('table.comments') - ->order('coid', Typecho_Db::SORT_ASC)->page($i, 100)); + ->order('coid', Db::SORT_ASC)->page($i, 100)); $j = 0; while ($row = $db->fetchRow($result)) { @@ -137,7 +140,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); ->rows(['text' => $text]) ->where('coid = ?', $row['coid'])); - $j ++; + $j++; unset($text); unset($row); } @@ -146,7 +149,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); break; } - $i ++; + $i++; unset($result); } } @@ -155,8 +158,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至9.2.18 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_5r9_2_18($db, $options) @@ -171,8 +174,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至9.2.25 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_5r9_2_25($db, $options) @@ -186,8 +189,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至9.4.3 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_6r9_4_3($db, $options) @@ -200,11 +203,11 @@ Typecho_Date::setTimezoneOffset($options->timezone); try { switch (true) { case false !== strpos($adapterName, 'Mysql'): - $db->query('ALTER TABLE `' . $prefix . 'users` DROP `meta`', Typecho_Db::WRITE); + $db->query('ALTER TABLE `' . $prefix . 'users` DROP `meta`', Db::WRITE); break; case false !== strpos($adapterName, 'Pgsql'): - $db->query('ALTER TABLE "' . $prefix . 'users" DROP COLUMN "meta"', Typecho_Db::WRITE); + $db->query('ALTER TABLE "' . $prefix . 'users" DROP COLUMN "meta"', Db::WRITE); break; case false !== strpos($adapterName, 'SQLite'): @@ -219,11 +222,11 @@ Typecho_Date::setTimezoneOffset($options->timezone); "activated" int(10) default \'0\' , "logged" int(10) default \'0\' , "group" varchar(16) default \'visitor\' , - "authCode" varchar(64) default NULL)', Typecho_Db::WRITE); + "authCode" varchar(64) default NULL)', Db::WRITE); $db->query('INSERT INTO ' . $prefix . 'users_' . $uuid . ' ("uid", "name", "password", "mail", "url" , "screenName", "created", "activated", "logged", "group", "authCode") SELECT "uid", "name", "password", "mail", "url" - , "screenName", "created", "activated", "logged", "group", "authCode" FROM ' . $prefix . 'users', Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'users', Typecho_Db::WRITE); + , "screenName", "created", "activated", "logged", "group", "authCode" FROM ' . $prefix . 'users', Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'users', Db::WRITE); $db->query('CREATE TABLE ' . $prefix . 'users ( "uid" INTEGER NOT NULL PRIMARY KEY, "name" varchar(32) default NULL , "password" varchar(64) default NULL , @@ -234,11 +237,11 @@ Typecho_Date::setTimezoneOffset($options->timezone); "activated" int(10) default \'0\' , "logged" int(10) default \'0\' , "group" varchar(16) default \'visitor\' , - "authCode" varchar(64) default NULL)', Typecho_Db::WRITE); - $db->query('INSERT INTO ' . $prefix . 'users SELECT * FROM ' . $prefix . 'users_' . $uuid, Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'users_' . $uuid, Typecho_Db::WRITE); - $db->query('CREATE UNIQUE INDEX ' . $prefix . 'users_name ON ' . $prefix . 'users ("name")', Typecho_Db::WRITE); - $db->query('CREATE UNIQUE INDEX ' . $prefix . 'users_mail ON ' . $prefix . 'users ("mail")', Typecho_Db::WRITE); + "authCode" varchar(64) default NULL)', Db::WRITE); + $db->query('INSERT INTO ' . $prefix . 'users SELECT * FROM ' . $prefix . 'users_' . $uuid, Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'users_' . $uuid, Db::WRITE); + $db->query('CREATE UNIQUE INDEX ' . $prefix . 'users_name ON ' . $prefix . 'users ("name")', Db::WRITE); + $db->query('CREATE UNIQUE INDEX ' . $prefix . 'users_mail ON ' . $prefix . 'users ("mail")', Db::WRITE); $db->flushPool(); break; @@ -246,7 +249,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); default: break; } - } catch (Typecho_Db_Exception $e) { + } catch (Db_Exception $e) { //do nothing } @@ -254,13 +257,13 @@ Typecho_Date::setTimezoneOffset($options->timezone); try { switch (true) { case false !== strpos($adapterName, 'Mysql'): - $db->query("ALTER TABLE `" . $prefix . "contents` MODIFY COLUMN `slug` varchar(150)", Typecho_Db::WRITE); - $db->query("ALTER TABLE `" . $prefix . "metas` MODIFY COLUMN `slug` varchar(150)", Typecho_Db::WRITE); + $db->query("ALTER TABLE `" . $prefix . "contents` MODIFY COLUMN `slug` varchar(150)", Db::WRITE); + $db->query("ALTER TABLE `" . $prefix . "metas` MODIFY COLUMN `slug` varchar(150)", Db::WRITE); break; case false !== strpos($adapterName, 'Pgsql'): - $db->query('ALTER TABLE "' . $prefix . 'contents" ALTER COLUMN "slug" TYPE varchar(150)', Typecho_Db::WRITE); - $db->query('ALTER TABLE "' . $prefix . 'metas" ALTER COLUMN "slug" TYPE varchar(150)', Typecho_Db::WRITE); + $db->query('ALTER TABLE "' . $prefix . 'contents" ALTER COLUMN "slug" TYPE varchar(150)', Db::WRITE); + $db->query('ALTER TABLE "' . $prefix . 'metas" ALTER COLUMN "slug" TYPE varchar(150)', Db::WRITE); break; case false !== strpos($adapterName, 'SQLite'): @@ -280,9 +283,9 @@ Typecho_Date::setTimezoneOffset($options->timezone); "commentsNum" int(10) default \'0\' , "allowComment" char(1) default \'0\' , "allowPing" char(1) default \'0\' , - "allowFeed" char(1) default \'0\' )', Typecho_Db::WRITE); - $db->query('INSERT INTO ' . $prefix . 'contents' . $uuid . ' SELECT * FROM ' . $prefix . 'contents', Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'contents', Typecho_Db::WRITE); + "allowFeed" char(1) default \'0\' )', Db::WRITE); + $db->query('INSERT INTO ' . $prefix . 'contents' . $uuid . ' SELECT * FROM ' . $prefix . 'contents', Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'contents', Db::WRITE); $db->query('CREATE TABLE ' . $prefix . 'contents ( "cid" INTEGER NOT NULL PRIMARY KEY, "title" varchar(150) default NULL , "slug" varchar(150) default NULL , @@ -298,11 +301,11 @@ Typecho_Date::setTimezoneOffset($options->timezone); "commentsNum" int(10) default \'0\' , "allowComment" char(1) default \'0\' , "allowPing" char(1) default \'0\' , - "allowFeed" char(1) default \'0\' )', Typecho_Db::WRITE); - $db->query('INSERT INTO ' . $prefix . 'contents SELECT * FROM ' . $prefix . 'contents' . $uuid, Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'contents' . $uuid, Typecho_Db::WRITE); - $db->query('CREATE UNIQUE INDEX ' . $prefix . 'contents_slug ON ' . $prefix . 'contents ("slug")', Typecho_Db::WRITE); - $db->query('CREATE INDEX ' . $prefix . 'contents_created ON ' . $prefix . 'contents ("created")', Typecho_Db::WRITE); + "allowFeed" char(1) default \'0\' )', Db::WRITE); + $db->query('INSERT INTO ' . $prefix . 'contents SELECT * FROM ' . $prefix . 'contents' . $uuid, Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'contents' . $uuid, Db::WRITE); + $db->query('CREATE UNIQUE INDEX ' . $prefix . 'contents_slug ON ' . $prefix . 'contents ("slug")', Db::WRITE); + $db->query('CREATE INDEX ' . $prefix . 'contents_created ON ' . $prefix . 'contents ("created")', Db::WRITE); $db->query('CREATE TABLE ' . $prefix . 'metas' . $uuid . ' ( "mid" INTEGER NOT NULL PRIMARY KEY, "name" varchar(150) default NULL , @@ -310,19 +313,19 @@ Typecho_Date::setTimezoneOffset($options->timezone); "type" varchar(32) NOT NULL , "description" varchar(150) default NULL , "count" int(10) default \'0\' , - "order" int(10) default \'0\' )', Typecho_Db::WRITE); - $db->query('INSERT INTO ' . $prefix . 'metas' . $uuid . ' SELECT * FROM ' . $prefix . 'metas', Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'metas', Typecho_Db::WRITE); + "order" int(10) default \'0\' )', Db::WRITE); + $db->query('INSERT INTO ' . $prefix . 'metas' . $uuid . ' SELECT * FROM ' . $prefix . 'metas', Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'metas', Db::WRITE); $db->query('CREATE TABLE ' . $prefix . 'metas ( "mid" INTEGER NOT NULL PRIMARY KEY, "name" varchar(150) default NULL , "slug" varchar(150) default NULL , "type" varchar(32) NOT NULL , "description" varchar(150) default NULL , "count" int(10) default \'0\' , - "order" int(10) default \'0\' )', Typecho_Db::WRITE); - $db->query('INSERT INTO ' . $prefix . 'metas SELECT * FROM ' . $prefix . 'metas' . $uuid, Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'metas' . $uuid, Typecho_Db::WRITE); - $db->query('CREATE INDEX ' . $prefix . 'metas_slug ON ' . $prefix . 'metas ("slug")', Typecho_Db::WRITE); + "order" int(10) default \'0\' )', Db::WRITE); + $db->query('INSERT INTO ' . $prefix . 'metas SELECT * FROM ' . $prefix . 'metas' . $uuid, Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'metas' . $uuid, Db::WRITE); + $db->query('CREATE INDEX ' . $prefix . 'metas_slug ON ' . $prefix . 'metas ("slug")', Db::WRITE); $db->flushPool(); break; @@ -330,7 +333,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); default: break; } - } catch (Typecho_Db_Exception $e) { + } catch (Db_Exception $e) { //do nothing } } @@ -339,23 +342,23 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至9.4.21 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_6r9_4_21($db, $options) { //创建上传目录 - $uploadDir = Typecho_Common::url(Widget_Upload::UPLOAD_DIR, __TYPECHO_ROOT_DIR__); + $uploadDir = Common::url(Upload::UPLOAD_DIR, __TYPECHO_ROOT_DIR__); if (is_dir($uploadDir)) { if (!is_writeable($uploadDir)) { if (!@chmod($uploadDir, 0644)) { - throw new Typecho_Widget_Exception(_t('上传目录无法写入, 请手动将安装目录下的 %s 目录的权限设置为可写然后继续升级', Widget_Upload::UPLOAD_DIR)); + throw new \Typecho\Widget\Exception(_t('上传目录无法写入, 请手动将安装目录下的 %s 目录的权限设置为可写然后继续升级', Upload::UPLOAD_DIR)); } } } else { if (!@mkdir($uploadDir, 0644)) { - throw new Typecho_Widget_Exception(_t('上传目录无法创建, 请手动创建安装目录下的 %s 目录, 并将它的权限设置为可写然后继续升级', Widget_Upload::UPLOAD_DIR)); + throw new \Typecho\Widget\Exception(_t('上传目录无法创建, 请手动创建安装目录下的 %s 目录, 并将它的权限设置为可写然后继续升级', Upload::UPLOAD_DIR)); } } @@ -388,12 +391,14 @@ Typecho_Date::setTimezoneOffset($options->timezone); $pre = array_slice($routingTable, 0, 2); $next = array_slice($routingTable, 2); - $routingTable = array_merge($pre, ['attachment' => - [ - 'url' => '/attachment/[cid:digital]/', - 'widget' => 'Widget_Archive', - 'action' => 'render', - ]], $next); + $routingTable = array_merge($pre, [ + 'attachment' => + [ + 'url' => '/attachment/[cid:digital]/', + 'widget' => 'Widget_Archive', + 'action' => 'render', + ] + ], $next); $db->query($db->update('table.options') ->rows(['value' => serialize($routingTable)]) @@ -404,8 +409,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至9.6.1 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_6r9_6_1($db, $options) @@ -428,8 +433,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至9.6.16 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_7r9_6_16($db, $options) @@ -448,7 +453,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); while (true) { $result = $db->query($db->select('cid', 'text')->from('table.contents') ->where('type = ?', 'attachment') - ->order('cid', Typecho_Db::SORT_ASC)->page($i, 100)); + ->order('cid', Db::SORT_ASC)->page($i, 100)); $j = 0; while ($row = $db->fetchRow($result)) { @@ -460,7 +465,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); ->rows(['text' => serialize($attachment)]) ->where('cid = ?', $row['cid'])); - $j ++; + $j++; unset($text); unset($row); } @@ -469,7 +474,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); break; } - $i ++; + $i++; unset($result); } } @@ -478,8 +483,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至9.6.16.1 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_7r9_6_16_1($db, $options) @@ -491,7 +496,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); } $routingTable['do'] = [ - 'url' => '/action/[action:alpha]', + 'url' => '/action/[action:alpha]', 'widget' => 'Widget_Do', 'action' => 'action' ]; @@ -510,8 +515,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至9.7.2 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_7r9_7_2($db, $options) @@ -526,9 +531,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); if (is_writeable(__TYPECHO_ROOT_DIR__ . '/config.inc.php')) { - $contents = file_get_contents(__TYPECHO_ROOT_DIR__ . '/config.inc.php'); - $contents = preg_replace("/Typecho_Common::init([^;]+);/is", "Typecho_Common::init(array( + $contents = preg_replace("/Common::init([^;]+);/is", "Common::init(array( 'autoLoad' => true, 'exception' => 'Widget_ExceptionHandle', 'gpc' => true @@ -550,8 +554,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 修改contents表的text字段类型为longtext(仅限mysql, pgsql和sqlite都是不限制长度的) * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_7r9_9_2($db, $options) @@ -560,7 +564,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); $prefix = $db->getPrefix(); if (false !== strpos($adapterName, 'Mysql')) { - $db->query("ALTER TABLE `{$prefix}contents` CHANGE `text` `text` LONGTEXT NULL DEFAULT NULL COMMENT '内容文字'", Typecho_Db::WRITE); + $db->query("ALTER TABLE `{$prefix}contents` CHANGE `text` `text` LONGTEXT NULL DEFAULT NULL COMMENT '内容文字'", Db::WRITE); } } @@ -569,8 +573,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 优化路由表结构 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_7r9_9_15($db, $options) @@ -599,8 +603,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 此升级用于修复从0.6升级时损坏的路由表 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_7r9_9_22($db, $options) @@ -612,7 +616,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); } $routingTable['do'] = [ - 'url' => '/action/[action:alpha]', + 'url' => '/action/[action:alpha]', 'widget' => 'Widget_Do', 'action' => 'action' ]; @@ -635,8 +639,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 增加按作者归档 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_7r9_9_27($db, $options) @@ -653,13 +657,13 @@ Typecho_Date::setTimezoneOffset($options->timezone); $next_next = array_slice($next, 5); $author = [ - 'url' => '/author/[uid:digital]/', + 'url' => '/author/[uid:digital]/', 'widget' => 'Widget_Archive', 'action' => 'render', ]; $author_page = [ - 'url' => '/author/[uid:digital]/[page:digital]/', + 'url' => '/author/[uid:digital]/[page:digital]/', 'widget' => 'Widget_Archive', 'action' => 'render', ]; @@ -677,8 +681,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 增加评论分页 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_7r9_10_16($db, $options) @@ -693,7 +697,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); $next = array_slice($routingTable, 20); $commentPage = [ - 'url' => '[permalink:string]/[commentType:alpha]-page-[commentPage:digital]', + 'url' => '[permalink:string]/[commentType:alpha]-page-[commentPage:digital]', 'widget' => 'Widget_Archive', 'action' => 'render', ]; @@ -710,8 +714,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 增加评论分页 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_7r9_10_20($db, $options) @@ -722,11 +726,11 @@ Typecho_Date::setTimezoneOffset($options->timezone); switch (true) { case false !== strpos($adapterName, 'Mysql'): - $db->query('ALTER TABLE `' . $prefix . 'contents` ADD `parent` INT(10) UNSIGNED NULL DEFAULT \'0\'', Typecho_Db::WRITE); + $db->query('ALTER TABLE `' . $prefix . 'contents` ADD `parent` INT(10) UNSIGNED NULL DEFAULT \'0\'', Db::WRITE); break; case false !== strpos($adapterName, 'Pgsql'): - $db->query('ALTER TABLE "' . $prefix . 'contents" ADD COLUMN "parent" INT NULL DEFAULT \'0\'', Typecho_Db::WRITE); + $db->query('ALTER TABLE "' . $prefix . 'contents" ADD COLUMN "parent" INT NULL DEFAULT \'0\'', Db::WRITE); break; case false !== strpos($adapterName, 'SQLite'): @@ -747,13 +751,13 @@ Typecho_Date::setTimezoneOffset($options->timezone); "allowComment" char(1) default \'0\' , "allowPing" char(1) default \'0\' , "allowFeed" char(1) default \'0\' , -"parent" int(10) default \'0\' )', Typecho_Db::WRITE); +"parent" int(10) default \'0\' )', Db::WRITE); $db->query('INSERT INTO ' . $prefix . 'contents_tmp ("cid", "title", "slug", "created", "modified" , "text", "order", "authorId", "template", "type", "status", "password", "commentsNum", "allowComment", "allowPing", "allowFeed", "parent") SELECT "cid", "title", "slug", "created", "modified" , "text", "order", "authorId", "template", "type", "status", "password", "commentsNum", "allowComment", - "allowPing", "allowFeed", "parent" FROM ' . $prefix . 'contents', Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'contents', Typecho_Db::WRITE); + "allowPing", "allowFeed", "parent" FROM ' . $prefix . 'contents', Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'contents', Db::WRITE); $db->query('CREATE TABLE ' . $prefix . 'contents ( "cid" INTEGER NOT NULL PRIMARY KEY, "title" varchar(150) default NULL , "slug" varchar(150) default NULL , @@ -770,11 +774,11 @@ Typecho_Date::setTimezoneOffset($options->timezone); "allowComment" char(1) default \'0\' , "allowPing" char(1) default \'0\' , "allowFeed" char(1) default \'0\' , -"parent" int(10) default \'0\' )', Typecho_Db::WRITE); - $db->query('INSERT INTO ' . $prefix . 'contents SELECT * FROM ' . $prefix . 'contents_tmp', Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'contents_tmp', Typecho_Db::WRITE); - $db->query('CREATE UNIQUE INDEX ' . $prefix . 'contents_slug ON ' . $prefix . 'contents ("slug")', Typecho_Db::WRITE); - $db->query('CREATE INDEX ' . $prefix . 'contents_created ON ' . $prefix . 'contents ("created")', Typecho_Db::WRITE); +"parent" int(10) default \'0\' )', Db::WRITE); + $db->query('INSERT INTO ' . $prefix . 'contents SELECT * FROM ' . $prefix . 'contents_tmp', Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'contents_tmp', Db::WRITE); + $db->query('CREATE UNIQUE INDEX ' . $prefix . 'contents_slug ON ' . $prefix . 'contents ("slug")', Db::WRITE); + $db->query('CREATE INDEX ' . $prefix . 'contents_created ON ' . $prefix . 'contents ("created")', Db::WRITE); $db->flushPool(); break; @@ -795,8 +799,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 修正附件 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_7r9_10_31($db, $options) @@ -809,8 +813,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至9.11.25 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_8r9_11_25($db, $options) @@ -854,7 +858,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); if (isset($routingTable['comment_page'])) { $routingTable['comment_page'] = [ - 'url' => '[permalink:string]/comment-page-[commentPage:digital]', + 'url' => '[permalink:string]/comment-page-[commentPage:digital]', 'widget' => 'Widget_Archive', 'action' => 'render', ]; @@ -863,7 +867,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); $next = array_slice($routingTable, 20); $commentPage = [ - 'url' => '[permalink:string]/comment-page-[commentPage:digital]', + 'url' => '[permalink:string]/comment-page-[commentPage:digital]', 'widget' => 'Widget_Archive', 'action' => 'render', ]; @@ -880,8 +884,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至9.12.11 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_8r9_12_11($db, $options) @@ -900,8 +904,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至10.2.27 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_8r10_2_27($db, $options) @@ -937,8 +941,8 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至10.3.8 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_8r10_3_8($db, $options) @@ -952,13 +956,13 @@ Typecho_Date::setTimezoneOffset($options->timezone); * 升级至10.5.17 * * @access public - * @param Typecho_Db $db 数据库对象 - * @param Typecho_Widget $options 全局信息组件 + * @param Db $db 数据库对象 + * @param Options $options 全局信息组件 * @return void */ public static function v0_8r10_5_17($db, $options) { - Typecho_Widget::widget('Widget_Themes_Edit', null, 'change=' . $options->theme, false)->action(); + Edit::alloc(null, 'change=' . $options->theme, false)->action(); } @@ -980,14 +984,14 @@ Typecho_Date::setTimezoneOffset($options->timezone); // 更新原来被搞乱的草稿 $db->query($db->update('table.contents') ->rows([ - 'type' => 'post_draft', + 'type' => 'post_draft', 'status' => 'publish' ]) ->where('type = ? AND status = ?', 'post', 'draft')); $db->query($db->update('table.contents') ->rows([ - 'type' => 'page_draft', + 'type' => 'page_draft', 'status' => 'publish' ]) ->where('type = ? AND status = ?', 'page', 'draft')); @@ -1038,7 +1042,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); PRIMARY KEY (`cid`,`name`), KEY `int_value` (`int_value`), KEY `float_value` (`float_value`) -) ENGINE=MyISAM DEFAULT CHARSET=" . $config[0]->charset, Typecho_Db::WRITE); +) ENGINE=MyISAM DEFAULT CHARSET=" . $config[0]->charset, Db::WRITE); break; case false !== strpos($adapterName, 'Pgsql'): @@ -1049,9 +1053,9 @@ Typecho_Date::setTimezoneOffset($options->timezone); "int_value" INT NULL DEFAULT \'0\', "float_value" REAL NULL DEFAULT \'0\', PRIMARY KEY ("cid","name") -)', Typecho_Db::WRITE); - $db->query('CREATE INDEX "' . $prefix . 'fields_int_value" ON "' . $prefix . 'fields" ("int_value")', Typecho_Db::WRITE); - $db->query('CREATE INDEX "' . $prefix . 'fields_float_value" ON "' . $prefix . 'fields" ("float_value")', Typecho_Db::WRITE); +)', Db::WRITE); + $db->query('CREATE INDEX "' . $prefix . 'fields_int_value" ON "' . $prefix . 'fields" ("int_value")', Db::WRITE); + $db->query('CREATE INDEX "' . $prefix . 'fields_float_value" ON "' . $prefix . 'fields" ("float_value")', Db::WRITE); break; case false !== strpos($adapterName, 'SQLite'): @@ -1061,10 +1065,10 @@ Typecho_Date::setTimezoneOffset($options->timezone); "str_value" text, "int_value" int(10) default \'0\', "float_value" real default \'0\' -)', Typecho_Db::WRITE); - $db->query('CREATE UNIQUE INDEX ' . $prefix . 'fields_cid_name ON ' . $prefix . 'fields ("cid", "name")', Typecho_Db::WRITE); - $db->query('CREATE INDEX ' . $prefix . 'fields_int_value ON ' . $prefix . 'fields ("int_value")', Typecho_Db::WRITE); - $db->query('CREATE INDEX ' . $prefix . 'fields_float_value ON ' . $prefix . 'fields ("float_value")', Typecho_Db::WRITE); +)', Db::WRITE); + $db->query('CREATE UNIQUE INDEX ' . $prefix . 'fields_cid_name ON ' . $prefix . 'fields ("cid", "name")', Db::WRITE); + $db->query('CREATE INDEX ' . $prefix . 'fields_int_value ON ' . $prefix . 'fields ("int_value")', Db::WRITE); + $db->query('CREATE INDEX ' . $prefix . 'fields_float_value ON ' . $prefix . 'fields ("float_value")', Db::WRITE); break; @@ -1143,11 +1147,11 @@ Typecho_Date::setTimezoneOffset($options->timezone); switch (true) { case false !== strpos($adapterName, 'Mysql'): - $db->query("ALTER TABLE `" . $prefix . "comments` MODIFY COLUMN `agent` varchar(511)", Typecho_Db::WRITE); + $db->query("ALTER TABLE `" . $prefix . "comments` MODIFY COLUMN `agent` varchar(511)", Db::WRITE); break; case false !== strpos($adapterName, 'Pgsql'): - $db->query('ALTER TABLE "' . $prefix . 'comments" ALTER COLUMN "agent" TYPE varchar(511)', Typecho_Db::WRITE); + $db->query('ALTER TABLE "' . $prefix . 'comments" ALTER COLUMN "agent" TYPE varchar(511)', Db::WRITE); break; case false !== strpos($adapterName, 'SQLite'): @@ -1165,9 +1169,9 @@ Typecho_Date::setTimezoneOffset($options->timezone); "text" text , "type" varchar(16) default \'comment\' , "status" varchar(16) default \'approved\' , -"parent" int(10) default \'0\')', Typecho_Db::WRITE); - $db->query('INSERT INTO ' . $prefix . 'comments' . $uuid . ' SELECT * FROM ' . $prefix . 'comments', Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'metas', Typecho_Db::WRITE); +"parent" int(10) default \'0\')', Db::WRITE); + $db->query('INSERT INTO ' . $prefix . 'comments' . $uuid . ' SELECT * FROM ' . $prefix . 'comments', Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'metas', Db::WRITE); $db->query('CREATE TABLE ' . $prefix . 'comments ( "coid" INTEGER NOT NULL PRIMARY KEY, "cid" int(10) default \'0\' , "created" int(10) default \'0\' , @@ -1181,11 +1185,11 @@ Typecho_Date::setTimezoneOffset($options->timezone); "text" text , "type" varchar(16) default \'comment\' , "status" varchar(16) default \'approved\' , -"parent" int(10) default \'0\')', Typecho_Db::WRITE); - $db->query('INSERT INTO ' . $prefix . 'comments SELECT * FROM ' . $prefix . 'comments' . $uuid, Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'comments' . $uuid, Typecho_Db::WRITE); - $db->query('CREATE INDEX ' . $prefix . 'comments_cid ON ' . $prefix . 'comments ("cid")', Typecho_Db::WRITE); - $db->query('CREATE INDEX ' . $prefix . 'comments_created ON ' . $prefix . 'comments ("created")', Typecho_Db::WRITE); +"parent" int(10) default \'0\')', Db::WRITE); + $db->query('INSERT INTO ' . $prefix . 'comments SELECT * FROM ' . $prefix . 'comments' . $uuid, Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'comments' . $uuid, Db::WRITE); + $db->query('CREATE INDEX ' . $prefix . 'comments_cid ON ' . $prefix . 'comments ("cid")', Db::WRITE); + $db->query('CREATE INDEX ' . $prefix . 'comments_created ON ' . $prefix . 'comments ("created")', Db::WRITE); $db->flushPool(); break; @@ -1207,11 +1211,11 @@ Typecho_Date::setTimezoneOffset($options->timezone); switch (true) { case false !== strpos($adapterName, 'Mysql'): - $db->query("ALTER TABLE `" . $prefix . "comments` MODIFY COLUMN `url` varchar(255)", Typecho_Db::WRITE); + $db->query("ALTER TABLE `" . $prefix . "comments` MODIFY COLUMN `url` varchar(255)", Db::WRITE); break; case false !== strpos($adapterName, 'Pgsql'): - $db->query('ALTER TABLE "' . $prefix . 'comments" ALTER COLUMN "url" TYPE varchar(255)', Typecho_Db::WRITE); + $db->query('ALTER TABLE "' . $prefix . 'comments" ALTER COLUMN "url" TYPE varchar(255)', Db::WRITE); break; case false !== strpos($adapterName, 'SQLite'): @@ -1229,9 +1233,9 @@ Typecho_Date::setTimezoneOffset($options->timezone); "text" text , "type" varchar(16) default \'comment\' , "status" varchar(16) default \'approved\' , -"parent" int(10) default \'0\')', Typecho_Db::WRITE); - $db->query('INSERT INTO ' . $prefix . 'comments' . $uuid . ' SELECT * FROM ' . $prefix . 'comments', Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'metas', Typecho_Db::WRITE); +"parent" int(10) default \'0\')', Db::WRITE); + $db->query('INSERT INTO ' . $prefix . 'comments' . $uuid . ' SELECT * FROM ' . $prefix . 'comments', Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'metas', Db::WRITE); $db->query('CREATE TABLE ' . $prefix . 'comments ( "coid" INTEGER NOT NULL PRIMARY KEY, "cid" int(10) default \'0\' , "created" int(10) default \'0\' , @@ -1245,11 +1249,11 @@ Typecho_Date::setTimezoneOffset($options->timezone); "text" text , "type" varchar(16) default \'comment\' , "status" varchar(16) default \'approved\' , -"parent" int(10) default \'0\')', Typecho_Db::WRITE); - $db->query('INSERT INTO ' . $prefix . 'comments SELECT * FROM ' . $prefix . 'comments' . $uuid, Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'comments' . $uuid, Typecho_Db::WRITE); - $db->query('CREATE INDEX ' . $prefix . 'comments_cid ON ' . $prefix . 'comments ("cid")', Typecho_Db::WRITE); - $db->query('CREATE INDEX ' . $prefix . 'comments_created ON ' . $prefix . 'comments ("created")', Typecho_Db::WRITE); +"parent" int(10) default \'0\')', Db::WRITE); + $db->query('INSERT INTO ' . $prefix . 'comments SELECT * FROM ' . $prefix . 'comments' . $uuid, Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'comments' . $uuid, Db::WRITE); + $db->query('CREATE INDEX ' . $prefix . 'comments_cid ON ' . $prefix . 'comments ("cid")', Db::WRITE); + $db->query('CREATE INDEX ' . $prefix . 'comments_created ON ' . $prefix . 'comments ("created")', Db::WRITE); $db->flushPool(); break; @@ -1306,11 +1310,11 @@ Typecho_Date::setTimezoneOffset($options->timezone); switch (true) { case false !== strpos($adapterName, 'Mysql'): - $db->query('ALTER TABLE `' . $prefix . 'metas` ADD `parent` INT(10) UNSIGNED NULL DEFAULT \'0\'', Typecho_Db::WRITE); + $db->query('ALTER TABLE `' . $prefix . 'metas` ADD `parent` INT(10) UNSIGNED NULL DEFAULT \'0\'', Db::WRITE); break; case false !== strpos($adapterName, 'Pgsql'): - $db->query('ALTER TABLE "' . $prefix . 'metas" ADD COLUMN "parent" INT NULL DEFAULT \'0\'', Typecho_Db::WRITE); + $db->query('ALTER TABLE "' . $prefix . 'metas" ADD COLUMN "parent" INT NULL DEFAULT \'0\'', Db::WRITE); break; case false !== strpos($adapterName, 'SQLite'): @@ -1322,10 +1326,10 @@ Typecho_Date::setTimezoneOffset($options->timezone); "description" varchar(150) default NULL , "count" int(10) default \'0\' , "order" int(10) default \'0\' , - "parent" int(10) default \'0\')', Typecho_Db::WRITE); + "parent" int(10) default \'0\')', Db::WRITE); $db->query('INSERT INTO ' . $prefix . 'metas' . $uuid . ' ("mid", "name", "slug", "type", "description", "count", "order") - SELECT "mid", "name", "slug", "type", "description", "count", "order" FROM ' . $prefix . 'metas', Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'metas', Typecho_Db::WRITE); + SELECT "mid", "name", "slug", "type", "description", "count", "order" FROM ' . $prefix . 'metas', Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'metas', Db::WRITE); $db->query('CREATE TABLE ' . $prefix . 'metas ( "mid" INTEGER NOT NULL PRIMARY KEY, "name" varchar(150) default NULL , "slug" varchar(150) default NULL , @@ -1333,10 +1337,10 @@ Typecho_Date::setTimezoneOffset($options->timezone); "description" varchar(150) default NULL , "count" int(10) default \'0\' , "order" int(10) default \'0\' , - "parent" int(10) default \'0\')', Typecho_Db::WRITE); - $db->query('INSERT INTO ' . $prefix . 'metas SELECT * FROM ' . $prefix . 'metas' . $uuid, Typecho_Db::WRITE); - $db->query('DROP TABLE ' . $prefix . 'metas' . $uuid, Typecho_Db::WRITE); - $db->query('CREATE INDEX ' . $prefix . 'metas_slug ON ' . $prefix . 'metas ("slug")', Typecho_Db::WRITE); + "parent" int(10) default \'0\')', Db::WRITE); + $db->query('INSERT INTO ' . $prefix . 'metas SELECT * FROM ' . $prefix . 'metas' . $uuid, Db::WRITE); + $db->query('DROP TABLE ' . $prefix . 'metas' . $uuid, Db::WRITE); + $db->query('CREATE INDEX ' . $prefix . 'metas_slug ON ' . $prefix . 'metas ("slug")', Db::WRITE); $db->flushPool(); break; @@ -1357,7 +1361,7 @@ Typecho_Date::setTimezoneOffset($options->timezone); { if (!isset($options->secret)) { $db->query($db->insert('table.options') - ->rows(['name' => 'secret', 'user' => 0, 'value' => Typecho_Common::randString(32, true)])); + ->rows(['name' => 'secret', 'user' => 0, 'value' => Common::randString(32, true)])); } } diff --git a/var/Widget/Backup.php b/var/Widget/Backup.php index 5eac80c8..4dce95ca 100644 --- a/var/Widget/Backup.php +++ b/var/Widget/Backup.php @@ -126,7 +126,7 @@ class Backup extends BaseOptions implements ActionInterface } while (count($rows) == 20); } - Plugin::factory(__CLASS__)->export($fp); + $this->pluginHandle()->export($fp); fwrite($fp, $header); fclose($fp); @@ -322,7 +322,7 @@ class Backup extends BaseOptions implements ActionInterface $this->importData($table, $data); } else { - Plugin::factory(__CLASS__)->import($type, $header, $body); + $this->pluginHandle()->import($type, $header, $body); } } diff --git a/var/Widget/Base/Comments.php b/var/Widget/Base/Comments.php index b5c9fdbe..4e4b4415 100644 --- a/var/Widget/Base/Comments.php +++ b/var/Widget/Base/Comments.php @@ -4,9 +4,12 @@ namespace Widget\Base; use Typecho\Common; use Typecho\Date; +use Typecho\Db; use Typecho\Db\Exception; use Typecho\Db\Query; use Typecho\Router; +use Utils\AutoP; +use Utils\Markdown; use Widget\Base; if (!defined('__TYPECHO_ROOT_DIR__')) { @@ -232,7 +235,7 @@ class Comments extends Base implements QueryInterface public function filter(array $value): array { $value['date'] = new Date($value['created']); - return $this->pluginHandle(__CLASS__)->filter($value, $this); + return $this->pluginHandle()->filter($value, $this); } /** @@ -275,7 +278,7 @@ class Comments extends Base implements QueryInterface if ($this->options->commentsAvatar && 'comment' == $this->type) { $rating = $this->options->commentsAvatarRating; - $this->pluginHandle(__CLASS__)->trigger($plugged)->gravatar($size, $rating, $default, $this); + $this->pluginHandle()->trigger($plugged)->gravatar($size, $rating, $default, $this); if (!$plugged) { $url = Common::gravatarUrl($this->mail, $size, $rating, $default, $this->request->isSecure()); echo '