change all

This commit is contained in:
joyqi 2021-09-01 18:27:03 +08:00
parent 4f13adcadd
commit 7db5f3c873
23 changed files with 541 additions and 448 deletions

View File

@ -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'],

View File

@ -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);
}
/**

View File

@ -1,5 +1,7 @@
<?php
namespace Utils;
/**
* AutoP
*
@ -31,7 +33,6 @@ class AutoP
/**
* 替换段落的回调函数
*
* @access public
* @param array $matches 匹配值
* @return string
*/
@ -52,7 +53,7 @@ class AutoP
case false !== strpos('|div|blockquote|form|', $tagMatch):
$text = $this->cutByBlock($text);
if (false !== strpos($text, '</p><p>')) {
$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);
}

View File

@ -1,5 +1,18 @@
<?php
namespace Utils;
use Typecho\Common;
use Typecho\Db;
use Typecho\I18n;
use Typecho\Plugin;
use Typecho\Widget;
use Widget\Base\Options as BaseOptions;
use Widget\Options;
use Widget\Plugins\Edit;
use Widget\Security;
use Widget\Service;
/**
* 插件帮手将默认出现在所有的typecho发行版中.
* 因此你可以放心使用它的功能, 以方便你的插件安装在用户的系统里.
@ -12,22 +25,23 @@
class Helper
{
/**
* 获取Widget_Security对象
* 获取Security对象
*
* @return Widget_Security
* @return Security
*/
public static function security()
public static function security(): Security
{
return \Widget\Security::alloc();
return Security::alloc();
}
/**
* 根据ID获取单个Widget对象
*
* @param string $table 表名, 支持 contents, comments, metas, users
* @return Widget_Abstract
* @param int $pkId
* @return Widget|null
*/
public static function widgetById($table, $pkId)
public static function widgetById(string $table, int $pkId): ?Widget
{
$table = ucfirst($table);
if (!in_array($table, ['Contents', 'Comments', 'Metas', 'Users'])) {
@ -37,18 +51,20 @@ class Helper
$keys = [
'Contents' => '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 '<a href="#' . $formId . '" rel="nofollow" onclick="return typechoAddCommentReply(\'' .
$theId . '\', ' . $coid . ', \'' . $formId . '\', ' . $style . ');">' . $word . '</a>';
@ -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 '<a href="#' . $formId . '" rel="nofollow" onclick="return typechoCancelCommentReply(\'' .
@ -424,9 +454,6 @@ class Helper
/**
* 评论回复js脚本
*
* @access public
* @return void
*/
public static function threadedCommentsScript()
{

View File

@ -1,5 +1,7 @@
<?php
namespace Utils;
/**
* Parser
*

View File

@ -1,5 +1,6 @@
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
namespace Utils;
/**
* Markdown解析
@ -16,7 +17,7 @@ class Markdown
* @param string $text
* @return string
*/
public static function convert($text)
public static function convert(string $text): string
{
static $parser;

View File

@ -1,29 +1,6 @@
<?php
/**
* Portable PHP password hashing framework.
* @package phpass
* @since 2.5
* @version 0.2 / genuine.
* @link http://www.openwall.com/phpass/
*/
#
# Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in
# the public domain.
#
# There's absolutely no warranty.
#
# Please be sure to update the Version line if you edit this file in any way.
# It is suggested that you leave the main version number intact, but indicate
# your project name (after the slash) and add your own revision information.
#
# Please do not change the "private" password hashing method implemented in
# here, thereby making your hashes incompatible. However, if you must, please
# change the hash type identifier (the "$P$") to something different.
#
# Obviously, since this code is in the public domain, the above are not
# requirements (there can be none), but merely suggestions.
#
namespace Utils;
/**
* Portable PHP password hashing framework.
@ -35,17 +12,26 @@
*/
class PasswordHash
{
var $itoa64;
var $iteration_count_log2;
var $portable_hashes;
var $random_state;
private $itoa64;
function __construct($iteration_count_log2, $portable_hashes)
private $iteration_count_log2;
private $portable_hashes;
private $random_state;
/**
* @param int $iteration_count_log2
* @param bool $portable_hashes
*/
public function __construct(int $iteration_count_log2, bool $portable_hashes)
{
$this->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;
}

View File

@ -1,13 +1,13 @@
<?php
/**
* 升级程序
*
* @category typecho
* @package Upgrade
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
* @license GNU General Public License 2.0
* @version $Id$
*/
namespace Utils;
use Typecho\Common;
use Typecho\Db;
use Typecho\Exception;
use Widget\Options;
use Widget\Themes\Edit;
use Widget\Upload;
/**
* 升级程序
@ -23,8 +23,8 @@ class Upgrade
* 升级至9.1.7
*
* @access public
* @param Typecho_Db $db 数据库对象
* @param Typecho_Widget $options 全局信息组件
* @param Db $db 数据库对象
* @param Options $options 全局信息组件
* @return void
*/
public static function v0_3r9_1_7($db, $options)
@ -34,7 +34,7 @@ class Upgrade
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)) {
@ -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*<p>/is", "/\s*<\/p>\s*/is", "/\s*<br\s*\/>\s*/is",
"/\s*<(div|blockquote|pre|table|ol|ul)>/is", "/<\/(div|blockquote|pre|table|ol|ul)>\s*/is"],
[
"/\s*<p>/is", "/\s*<\/p>\s*/is", "/\s*<br\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>", "</\\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)]));
}
}

View File

@ -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);
}
}

View File

@ -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 '<img class="avatar" src="' . $url . '" alt="' .
@ -330,10 +333,10 @@ class Comments extends Base implements QueryInterface
*/
public function markdown(?string $text): string
{
$html = $this->pluginHandle(__CLASS__)->trigger($parsed)->markdown($text);
$html = $this->pluginHandle()->trigger($parsed)->markdown($text);
if (!$parsed) {
$html = \Markdown::convert($text);
$html = Markdown::convert($text);
}
return $html;
@ -347,13 +350,13 @@ class Comments extends Base implements QueryInterface
*/
public function autoP(?string $text): string
{
$html = $this->pluginHandle(__CLASS__)->trigger($parsed)->autoP($text);
$html = $this->pluginHandle()->trigger($parsed)->autoP($text);
if (!$parsed) {
static $parser;
if (empty($parser)) {
$parser = new \AutoP();
$parser = new AutoP();
}
$html = $parser->parse($text);
@ -413,7 +416,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', Typecho_Db::SORT_ASC);
->order('coid', Db::SORT_ASC);
if ($this->options->commentsShowCommentOnly) {
$select->where('type = ?', 'comment');
@ -454,13 +457,13 @@ class Comments extends Base implements QueryInterface
{
$text = $this->parentContent['hidden'] ? _t('内容被隐藏') : $this->text;
$text = $this->pluginHandle(__CLASS__)->trigger($plugged)->content($text, $this);
$text = $this->pluginHandle()->trigger($plugged)->content($text, $this);
if (!$plugged) {
$text = $this->options->commentsMarkdown ? $this->markdown($text)
: $this->autoP($text);
}
$text = $this->pluginHandle(__CLASS__)->contentEx($text, $this);
$text = $this->pluginHandle()->contentEx($text, $this);
return Common::stripTags($text, '<p><br>' . $this->options->commentsHTMLTagAllowed);
}

View File

@ -11,6 +11,8 @@ use Typecho\Db\Query;
use Typecho\Plugin;
use Typecho\Router;
use Typecho\Widget;
use Utils\AutoP;
use Utils\Markdown;
use Widget\Base;
use Widget\Metas\Category\Rows;
use Widget\Upload;
@ -309,7 +311,7 @@ class Contents extends Base implements QueryInterface
continue;
}
$isFieldReadOnly = $this->pluginHandle(__CLASS__)->trigger($plugged)->isFieldReadOnly($name);
$isFieldReadOnly = $this->pluginHandle()->trigger($plugged)->isFieldReadOnly($name);
if ($plugged && $isFieldReadOnly) {
continue;
}
@ -591,7 +593,7 @@ class Contents extends Base implements QueryInterface
$value['hidden'] = true;
}
$value = $this->pluginHandle(__CLASS__)->filter($value, $this);
$value = $this->pluginHandle()->filter($value, $this);
/** 如果访问权限被禁止 */
if ($value['hidden']) {
@ -880,7 +882,7 @@ class Contents extends Base implements QueryInterface
return $this->text;
}
$content = $this->pluginHandle(__CLASS__)->trigger($plugged)->excerpt($this->text, $this);
$content = $this->pluginHandle()->trigger($plugged)->excerpt($this->text, $this);
if (!$plugged) {
$content = $this->isMarkdown ? $this->markdown($content)
: $this->autoP($content);
@ -889,7 +891,7 @@ class Contents extends Base implements QueryInterface
$contents = explode('<!--more-->', $content);
[$excerpt] = $contents;
return Common::fixHtml($this->pluginHandle(__CLASS__)->excerptEx($excerpt, $this));
return Common::fixHtml($this->pluginHandle()->excerptEx($excerpt, $this));
}
/**
@ -900,10 +902,10 @@ class Contents extends Base implements QueryInterface
*/
public function markdown(?string $text): string
{
$html = $this->pluginHandle(__CLASS__)->trigger($parsed)->markdown($text);
$html = $this->pluginHandle()->trigger($parsed)->markdown($text);
if (!$parsed) {
$html = \Markdown::convert($text);
$html = Markdown::convert($text);
}
return $html;
@ -917,13 +919,13 @@ class Contents extends Base implements QueryInterface
*/
public function autoP(?string $text): string
{
$html = $this->pluginHandle(__CLASS__)->trigger($parsed)->autoP($text);
$html = $this->pluginHandle()->trigger($parsed)->autoP($text);
if (!$parsed) {
static $parser;
if (empty($parser)) {
$parser = new \AutoP();
$parser = new AutoP();
}
$html = $parser->parse($text);
@ -943,14 +945,14 @@ class Contents extends Base implements QueryInterface
return $this->text;
}
$content = $this->pluginHandle(__CLASS__)->trigger($plugged)->content($this->text, $this);
$content = $this->pluginHandle()->trigger($plugged)->content($this->text, $this);
if (!$plugged) {
$content = $this->isMarkdown ? $this->markdown($content)
: $this->autoP($content);
}
return $this->pluginHandle(__CLASS__)->contentEx($content, $this);
return $this->pluginHandle()->contentEx($content, $this);
}
/**

View File

@ -83,7 +83,7 @@ class Metas extends Base implements QueryInterface
$value['feedAtomUrl'] = $routeExists ? Router::url($type, $value, $this->options->feedAtomUrl) : '#';
$value['slug'] = $tmpSlug;
$value = $this->pluginHandle(__CLASS__)->filter($value, $this);
$value = $this->pluginHandle()->filter($value, $this);
return $value;
}

View File

@ -136,7 +136,7 @@ class Users extends Base implements QueryInterface
/** ATOM 1.0 */
$value['feedAtomUrl'] = $routeExists ? Router::url('author', $value, $this->options->feedAtomUrl) : '#';
$value = $this->pluginHandle(__CLASS__)->filter($value, $this);
$value = $this->pluginHandle()->filter($value, $this);
return $value;
}

View File

@ -169,7 +169,7 @@ class Edit extends Contents implements ActionInterface
->where('cid = ?', $this->cid));
foreach ($rows as $row) {
$isFieldReadOnly = $this->pluginHandle('Widget_Abstract_Contents')
$isFieldReadOnly = Contents::pluginHandle()
->trigger($plugged)->isFieldReadOnly($row['name']);
if ($plugged && $isFieldReadOnly) {
@ -220,7 +220,7 @@ class Edit extends Contents implements ActionInterface
if ($item instanceof Element) {
$name = $item->input->getAttribute('name');
$isFieldReadOnly = $this->pluginHandle('Widget_Abstract_Contents')
$isFieldReadOnly = Contents::pluginHandle()
->trigger($plugged)->isFieldReadOnly($name);
if ($plugged && $isFieldReadOnly) {
continue;

View File

@ -4,6 +4,7 @@ namespace Widget;
use Typecho\Common;
use Typecho\Cookie;
use Typecho\Db;
use Typecho\Router;
use Typecho\Validate;
use Typecho\Widget\Exception;
@ -117,7 +118,7 @@ class Feedback extends Comments implements ActionInterface
) {
$latestComment = $this->db->fetchRow($this->db->select('created')->from('table.comments')
->where('cid = ? AND ip = ?', $this->content->cid, $this->request->getIp())
->order('created', Typecho_Db::SORT_DESC)
->order('created', Db::SORT_DESC)
->limit(1));
if (

View File

@ -48,6 +48,12 @@ class Init extends Widget
'Widget_Themes_List' => '\Widget\Themes\Rows',
'Widget_Interface_Do' => '\Widget\ActionInterface',
'Widget_Do' => '\Widget\Action',
'AutoP' => '\Utils\AutoP',
'PasswordHash' => '\Utils\PasswordHash',
'Markdown' => '\Utils\Markdown',
'HyperDown' => '\Utils\HyperDown',
'Helper' => '\Utils\Helper',
'Upgrade' => '\Utils\Upgrade'
]);
/** 对变量赋值 */

View File

@ -18,46 +18,49 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
/**
* 全局选项组件
*
* @property-read string $feedUrl
* @property-read string $feedRssUrl
* @property-read string $feedAtomUrl
* @property-read string $commentsFeedUrl
* @property-read string $commentsFeedRssUrl
* @property-read string $commentsFeedAtomUrl
* @property-read string $themeUrl
* @property-read string $xmlRpcUrl
* @property-read string $index
* @property-read string $siteUrl
* @property-read array $routingTable
* @property-read string $rootUrl
* @property-read string $pluginUrl
* @property-read string $adminUrl
* @property-read string $loginUrl
* @property-read string $loginAction
* @property-read string $registerUrl
* @property-read string $registerAction
* @property-read string $profileUrl
* @property-read string $logoutUrl
* @property-read string $title
* @property-read string $description
* @property-read string $keywords
* @property-read string $lang
* @property-read string $theme
* @property-read int $pageSize
* @property-read int $serverTimezone
* @property-read int $timezone
* @property-read string $charset
* @property-read string $contentType
* @property-read string $software
* @property-read string $version
* @property-read bool $markdown
* @property-read bool $xmlrpcMarkdown
* @property-read array $allowedAttachmentTypes
* @property-read string $attachmentTypes
* @property-read int $time
* @property-read string $frontPage
* @property-read int $commentsListSize
* @property-read bool $commentsShowCommentOnly
* @property string $feedUrl
* @property string $feedRssUrl
* @property string $feedAtomUrl
* @property string $commentsFeedUrl
* @property string $commentsFeedRssUrl
* @property string $commentsFeedAtomUrl
* @property string $themeUrl
* @property string $xmlRpcUrl
* @property string $index
* @property string $siteUrl
* @property array $routingTable
* @property string $rootUrl
* @property string $pluginUrl
* @property string $adminUrl
* @property string $loginUrl
* @property string $loginAction
* @property string $registerUrl
* @property string $registerAction
* @property string $profileUrl
* @property string $logoutUrl
* @property string $title
* @property string $description
* @property string $keywords
* @property string $lang
* @property string $theme
* @property int $pageSize
* @property int $serverTimezone
* @property int $timezone
* @property string $charset
* @property string $contentType
* @property string $software
* @property string $version
* @property bool $markdown
* @property bool $xmlrpcMarkdown
* @property array $allowedAttachmentTypes
* @property string $attachmentTypes
* @property int $time
* @property string $frontPage
* @property int $commentsListSize
* @property bool $commentsShowCommentOnly
* @property string $actionTable
* @property string $panelTable
* @property bool $commentsThreaded
*/
class Options extends Base
{

View File

@ -6,6 +6,7 @@ use Typecho\Common;
use Typecho\Cookie;
use Typecho\Db\Exception;
use Typecho\Validate;
use Utils\PasswordHash;
use Widget\Base\Users;
if (!defined('__TYPECHO_ROOT_DIR__')) {
@ -67,14 +68,14 @@ class Register extends Users implements ActionInterface
$this->response->goBack();
}
$hasher = new \PasswordHash(8, true);
$hasher = new PasswordHash(8, true);
$generatedPassword = Common::randString(7);
$dataStruct = [
'name' => $this->request->name,
'mail' => $this->request->mail,
'screenName' => $this->request->name,
'password' => $hasher->HashPassword($generatedPassword),
'password' => $hasher->hashPassword($generatedPassword),
'created' => $this->options->time,
'group' => 'subscriber'
];

View File

@ -260,7 +260,7 @@ class Service extends BaseOptions implements ActionInterface
}
$requests = json_decode($this->request->requests, true);
$plugin = Plugin::factory(__CLASS__);
$plugin = $this->pluginHandle();
if (!empty($requests)) {
foreach ($requests as $request) {

View File

@ -172,7 +172,7 @@ class Upload extends Contents implements ActionInterface
return false;
}
$result = Plugin::factory('Widget_Upload')->trigger($hasModified)->modifyHandle($content, $file);
$result = self::pluginHandle()->trigger($hasModified)->modifyHandle($content, $file);
if ($hasModified) {
return $result;
}
@ -360,7 +360,7 @@ class Upload extends Contents implements ActionInterface
return false;
}
$result = Plugin::factory('Widget_Upload')->trigger($hasUploaded)->uploadHandle($file);
$result = self::pluginHandle()->trigger($hasUploaded)->uploadHandle($file);
if ($hasUploaded) {
return $result;
}

View File

@ -6,6 +6,7 @@ use Typecho\Common;
use Typecho\Cookie;
use Typecho\Db\Exception as DbException;
use Typecho\Widget;
use Utils\PasswordHash;
use Widget\Base\Users;
if (!defined('__TYPECHO_ROOT_DIR__')) {
@ -155,8 +156,8 @@ class User extends Users
$hashValidate = $this->pluginHandle()->trigger($hashPluggable)->hashValidate($password, $user['password']);
if (!$hashPluggable) {
if ('$P$' == substr($user['password'], 0, 3)) {
$hasher = new \PasswordHash(8, true);
$hashValidate = $hasher->CheckPassword($password, $user['password']);
$hasher = new PasswordHash(8, true);
$hashValidate = $hasher->checkPassword($password, $user['password']);
} else {
$hashValidate = Common::hashValidate($password, $user['password']);
}

View File

@ -5,6 +5,7 @@ namespace Widget\Users;
use Typecho\Common;
use Typecho\Widget\Exception;
use Typecho\Widget\Helper\Form;
use Utils\PasswordHash;
use Widget\ActionInterface;
use Widget\Base\Users;
use Widget\Notice;
@ -82,12 +83,12 @@ class Edit extends Users implements ActionInterface
$this->response->goBack();
}
$hasher = new \PasswordHash(8, true);
$hasher = new PasswordHash(8, true);
/** 取出数据 */
$user = $this->request->from('name', 'mail', 'screenName', 'password', 'url', 'group');
$user['screenName'] = empty($user['screenName']) ? $user['name'] : $user['screenName'];
$user['password'] = $hasher->HashPassword($user['password']);
$user['password'] = $hasher->hashPassword($user['password']);
$user['created'] = $this->options->time;
/** 插入数据 */
@ -238,8 +239,8 @@ class Edit extends Users implements ActionInterface
if (empty($user['password'])) {
unset($user['password']);
} else {
$hasher = new \PasswordHash(8, true);
$user['password'] = $hasher->HashPassword($user['password']);
$hasher = new PasswordHash(8, true);
$user['password'] = $hasher->hashPassword($user['password']);
}
/** 更新数据 */

View File

@ -6,6 +6,7 @@ use Typecho\Common;
use Typecho\Db\Exception;
use Typecho\Plugin;
use Typecho\Widget\Helper\Form;
use Utils\PasswordHash;
use Widget\ActionInterface;
use Widget\Base\Options;
use Widget\Notice;
@ -304,8 +305,8 @@ class Profile extends Edit implements ActionInterface
$this->response->goBack();
}
$hasher = new \PasswordHash(8, true);
$password = $hasher->HashPassword($this->request->password);
$hasher = new PasswordHash(8, true);
$password = $hasher->hashPassword($this->request->password);
/** 更新数据 */
$this->update(