diff --git a/admin/extending.php b/admin/extending.php index d0fc5dcb..e3e6b147 100644 --- a/admin/extending.php +++ b/admin/extending.php @@ -3,7 +3,7 @@ include 'common.php'; $panel = $request->get('panel'); -$panelTable = unserialize($options->panelTable); +$panelTable = $options->panelTable; if (!isset($panelTable['file']) || !in_array(urlencode($panel), $panelTable['file'])) { throw new \Typecho\Plugin\Exception(_t('页面不存在'), 404); diff --git a/install.php b/install.php index 857785bd..184f6c5d 100644 --- a/install.php +++ b/install.php @@ -241,7 +241,16 @@ function install_get_default_options(): array if (empty($options)) { $options = [ 'theme' => 'default', - 'theme:default' => 'a:2:{s:7:"logoUrl";N;s:12:"sidebarBlock";a:5:{i:0;s:15:"ShowRecentPosts";i:1;s:18:"ShowRecentComments";i:2;s:12:"ShowCategory";i:3;s:11:"ShowArchive";i:4;s:9:"ShowOther";}}', + 'theme:default' => json_encode([ + 'logoUrl' => '', + 'sidebarBlock' => [ + 'ShowRecentPosts', + 'ShowRecentComments', + 'ShowCategory', + 'ShowArchive', + 'ShowOther' + ] + ]), 'timezone' => '28800', 'lang' => install_get_lang(), 'charset' => 'UTF-8', @@ -294,9 +303,9 @@ function install_get_default_options(): array 'commentsAvatar' => 1, 'commentsAvatarRating' => 'G', 'commentsAntiSpam' => 1, - 'routingTable' => serialize(install_get_default_routers()), - 'actionTable' => 'a:0:{}', - 'panelTable' => 'a:0:{}', + 'routingTable' => json_encode(install_get_default_routers()), + 'actionTable' => json_encode([]), + 'panelTable' => json_encode([]), 'attachmentTypes' => '@image@', 'secret' => \Typecho\Common::randString(32, true), 'installed' => 0, diff --git a/var/Typecho/Config.php b/var/Typecho/Config.php index 957aaad1..53d2439c 100644 --- a/var/Typecho/Config.php +++ b/var/Typecho/Config.php @@ -200,7 +200,7 @@ class Config extends \stdClass implements \Iterator, \ArrayAccess */ public function __toString(): string { - return serialize($this->currentConfig); + return json_encode($this->currentConfig); } /** diff --git a/var/Typecho/Validate.php b/var/Typecho/Validate.php index f0d9d9b1..9c77e160 100644 --- a/var/Typecho/Validate.php +++ b/var/Typecho/Validate.php @@ -134,7 +134,7 @@ class Validate * * @access public * - * @param string + * @param string $str * * @return boolean */ @@ -148,7 +148,7 @@ class Validate * * @access public * - * @param string + * @param string $str * * @return boolean */ diff --git a/var/Utils/Helper.php b/var/Utils/Helper.php index 494a0082..f4be04c2 100644 --- a/var/Utils/Helper.php +++ b/var/Utils/Helper.php @@ -118,9 +118,7 @@ class Helper try { Plugin::deactivate($pluginName); - $db->query($db->update('table.options') - ->rows(['value' => serialize(Plugin::export())]) - ->where('name = ?', 'plugins')); + self::setOption('plugins', Plugin::export()); } catch (Plugin\Exception $e) { //nothing to do } @@ -145,6 +143,32 @@ class Helper } } + /** + * 获取Options对象 + * + * @return Options + */ + public static function options(): Options + { + return Options::alloc(); + } + + /** + * @param string $name + * @param $value + * @return int + */ + public static function setOption(string $name, $value): int + { + $options = self::options(); + $options->{$name} = $value; + + return BaseOptions::alloc()->update( + ['value' => is_array($value) ? json_encode($value) : $value], + Db::get()->sql()->where('name = ?', $name) + ); + } + /** * 增加路由 * @@ -186,22 +210,8 @@ class Helper 'action' => $action ] ], $next); - self::options()->routingTable = $routingTable; - return BaseOptions::alloc()->update( - ['value' => serialize($routingTable)], - Db::get()->sql()->where('name = ?', 'routingTable') - ); - } - - /** - * 获取Options对象 - * - * @return Options - */ - public static function options(): Options - { - return Options::alloc(); + return self::setOption('routingTable', $routingTable); } /** @@ -218,13 +228,7 @@ class Helper } unset($routingTable[$name]); - self::options()->routingTable = $routingTable; - - $db = Db::get(); - return BaseOptions::alloc()->update( - ['value' => serialize($routingTable)], - $db->sql()->where('name = ?', 'routingTable') - ); + return self::setOption('routingTable', $routingTable); } /** @@ -236,14 +240,11 @@ class Helper */ public static function addAction(string $actionName, string $widgetName): int { - $actionTable = unserialize(self::options()->actionTable); + $actionTable = self::options()->actionTable; $actionTable = empty($actionTable) ? [] : $actionTable; $actionTable[$actionName] = $widgetName; - return BaseOptions::alloc()->update( - ['value' => (self::options()->actionTable = serialize($actionTable))], - Db::get()->sql()->where('name = ?', 'actionTable') - ); + return self::setOption('actionTable', $actionTable); } /** @@ -254,7 +255,7 @@ class Helper */ public static function removeAction(string $actionName): int { - $actionTable = unserialize(self::options()->actionTable); + $actionTable = self::options()->actionTable; $actionTable = empty($actionTable) ? [] : $actionTable; if (isset($actionTable[$actionName])) { @@ -262,10 +263,7 @@ class Helper reset($actionTable); } - return BaseOptions::alloc()->update( - ['value' => (self::options()->actionTable = serialize($actionTable))], - Db::get()->sql()->where('name = ?', 'actionTable') - ); + return self::setOption('actionTable', $actionTable); } /** @@ -276,14 +274,11 @@ class Helper */ public static function addMenu(string $menuName): int { - $panelTable = unserialize(self::options()->panelTable); + $panelTable = self::options()->panelTable; $panelTable['parent'] = empty($panelTable['parent']) ? [] : $panelTable['parent']; $panelTable['parent'][] = $menuName; - BaseOptions::alloc()->update( - ['value' => (self::options()->panelTable = serialize($panelTable))], - Db::get()->sql()->where('name = ?', 'panelTable') - ); + self::setOption('panelTable', $panelTable); end($panelTable['parent']); return key($panelTable['parent']) + 10; @@ -297,17 +292,14 @@ class Helper */ public static function removeMenu(string $menuName): int { - $panelTable = unserialize(self::options()->panelTable); + $panelTable = self::options()->panelTable; $panelTable['parent'] = empty($panelTable['parent']) ? [] : $panelTable['parent']; if (false !== ($index = array_search($menuName, $panelTable['parent']))) { unset($panelTable['parent'][$index]); } - BaseOptions::alloc()->update( - ['value' => (self::options()->panelTable = serialize($panelTable))], - Db::get()->sql()->where('name = ?', 'panelTable') - ); + self::setOption('panelTable', $panelTable); return $index + 10; } @@ -333,7 +325,7 @@ class Helper bool $hidden = false, string $addLink = '' ): int { - $panelTable = unserialize(self::options()->panelTable); + $panelTable = self::options()->panelTable; $panelTable['child'] = empty($panelTable['child']) ? [] : $panelTable['child']; $panelTable['child'][$index] = empty($panelTable['child'][$index]) ? [] : $panelTable['child'][$index]; $fileName = urlencode(trim($fileName, '/')); @@ -344,10 +336,7 @@ class Helper $panelTable['file'][] = $fileName; $panelTable['file'] = array_unique($panelTable['file']); - BaseOptions::alloc()->update( - ['value' => (self::options()->panelTable = serialize($panelTable))], - Db::get()->sql()->where('name = ?', 'panelTable') - ); + self::setOption('panelTable', $panelTable); end($panelTable['child'][$index]); return key($panelTable['child'][$index]); @@ -362,7 +351,7 @@ class Helper */ public static function removePanel(int $index, string $fileName): int { - $panelTable = unserialize(self::options()->panelTable); + $panelTable = self::options()->panelTable; $panelTable['child'] = empty($panelTable['child']) ? [] : $panelTable['child']; $panelTable['child'][$index] = empty($panelTable['child'][$index]) ? [] : $panelTable['child'][$index]; $panelTable['file'] = empty($panelTable['file']) ? [] : $panelTable['file']; @@ -380,10 +369,7 @@ class Helper } } - BaseOptions::alloc()->update( - ['value' => (self::options()->panelTable = serialize($panelTable))], - Db::get()->sql()->where('name = ?', 'panelTable') - ); + self::setOption('panelTable', $panelTable); return $return; } diff --git a/var/Utils/Upgrade.php b/var/Utils/Upgrade.php index 3d424a9a..75d73506 100644 --- a/var/Utils/Upgrade.php +++ b/var/Utils/Upgrade.php @@ -38,7 +38,7 @@ class Upgrade unset($routingTable[0]); $db->query($db->update('table.options') - ->rows(['value' => serialize($routingTable)]) + ->rows(['value' => json_encode($routingTable)]) ->where('name = ?', 'routingTable')); // fix options->commentsRequireURL @@ -46,8 +46,53 @@ class Upgrade ->rows(['name' => 'commentsRequireUrl']) ->where('name = ?', 'commentsRequireURL')); + // fix draft $db->query($db->update('table.contents') ->rows(['type' => 'revision']) ->where('parent <> 0 AND (type = ? OR type = ?)', 'post_draft', 'page_draft')); + + // fix attachment serialize + $lastId = 0; + do { + $rows = $db->fetchAll( + $db->select('cid', 'text')->from('table.contents') + ->where('cid > ?', $lastId) + ->where('type = ?', 'attachment') + ->order('cid', Db::SORT_ASC) + ->limit(100) + ); + + foreach ($rows as $row) { + if (strpos($row['text'], 'a:') !== 0) { + continue; + } + + $value = @unserialize($row['text']); + if ($value !== false) { + $db->query($db->update('table.contents') + ->rows(['text' => json_encode($value)]) + ->where('cid = ?', $row['cid'])); + } + + $lastId = $row['cid']; + } + } while (count($rows) === 100); + + $rows = $db->fetchAll($db->select()->from('table.options')); + + foreach ($rows as $row) { + if ( + in_array($row['name'], ['plugins', 'actionTable', 'panelTable']) + || strpos($row['name'], 'plugin:') === 0 + || strpos($row['name'], 'theme:') === 0 + ) { + $value = @unserialize($row['value']); + if ($value !== false) { + $db->query($db->update('table.options') + ->rows(['value' => json_encode($value)]) + ->where('name = ?', $row['name'])); + } + } + } } } diff --git a/var/Widget/Action.php b/var/Widget/Action.php index b15c54df..31600a40 100644 --- a/var/Widget/Action.php +++ b/var/Widget/Action.php @@ -58,7 +58,7 @@ class Action extends Widget $action = $this->request->get('action'); /** 判断是否为plugin */ - $actionTable = array_merge($this->map, unserialize(Options::alloc()->actionTable)); + $actionTable = array_merge($this->map, Options::alloc()->actionTable); if (isset($actionTable[$action])) { $widgetName = $actionTable[$action]; diff --git a/var/Widget/Base/Contents.php b/var/Widget/Base/Contents.php index a7c5a22a..00bf9790 100644 --- a/var/Widget/Base/Contents.php +++ b/var/Widget/Base/Contents.php @@ -723,7 +723,7 @@ class Contents extends Base implements QueryInterface, RowFilterInterface, Prima protected function ___attachment(): ?Config { if ('attachment' == $this->type) { - $content = @unserialize($this->row['text']); + $content = json_decode($this->row['text'], true); //增加数据信息 $attachment = new Config($content); diff --git a/var/Widget/Contents/Attachment/Edit.php b/var/Widget/Contents/Attachment/Edit.php index e6297a53..43bd7209 100644 --- a/var/Widget/Contents/Attachment/Edit.php +++ b/var/Widget/Contents/Attachment/Edit.php @@ -103,7 +103,7 @@ class Edit extends Contents implements ActionInterface $content = $this->attachment->toArray(); $content['description'] = $input['description']; - $attachment['text'] = serialize($content); + $attachment['text'] = json_encode($content); $cid = $this->request->filter('int')->get('cid'); /** 更新数据 */ diff --git a/var/Widget/Menu.php b/var/Widget/Menu.php index 2833a874..ff6d6c44 100644 --- a/var/Widget/Menu.php +++ b/var/Widget/Menu.php @@ -127,7 +127,7 @@ class Menu extends Base ]; /** 获取扩展菜单 */ - $panelTable = unserialize($this->options->panelTable); + $panelTable = $this->options->panelTable; $extendingParentMenu = empty($panelTable['parent']) ? [] : $panelTable['parent']; $extendingChildMenu = empty($panelTable['child']) ? [] : $panelTable['child']; $currentUrl = $this->request->getRequestUrl(); diff --git a/var/Widget/Options.php b/var/Widget/Options.php index 8060e46c..70f9c3f5 100644 --- a/var/Widget/Options.php +++ b/var/Widget/Options.php @@ -63,8 +63,8 @@ if (!defined('__TYPECHO_ROOT_DIR__')) { * @property string $frontPage * @property int $commentsListSize * @property bool $commentsShowCommentOnly - * @property string $actionTable - * @property string $panelTable + * @property array $actionTable + * @property array $panelTable * @property bool $commentsThreaded * @property bool $defaultAllowComment * @property bool $defaultAllowPing @@ -148,72 +148,29 @@ class Options extends Base */ public function execute() { + $options = []; + if (isset($this->db)) { $values = $this->db->fetchAll($this->db->select()->from('table.options') - ->where('user = 0'), [$this, 'push']); + ->where('user = 0')); // finish install if (empty($values)) { $this->response->redirect(defined('__TYPECHO_ADMIN__') ? '../install.php?step=3' : 'install.php?step=3'); } - } - /** 支持皮肤变量重载 */ - if (!empty($this->row['theme:' . $this->row['theme']])) { - $themeOptions = null; + $options = array_column($values, 'value', 'name'); - /** 解析变量 */ - if ($themeOptions = unserialize($this->row['theme:' . $this->row['theme']])) { - /** 覆盖变量 */ - $this->row = array_merge($this->row, $themeOptions); + /** 支持皮肤变量重载 */ + $themeOptionsKey = 'theme:' . $options['theme']; + if (!empty($options[$themeOptionsKey])) { + $themeOptions = $this->tryDeserialize($options[$themeOptionsKey]); + $options = array_merge($options, $themeOptions); } } - $this->stack[] = &$this->row; - - /** 动态获取根目录 */ - $this->rootUrl = defined('__TYPECHO_ROOT_URL__') ? __TYPECHO_ROOT_URL__ : $this->request->getRequestRoot(); - if (defined('__TYPECHO_ADMIN__')) { - /** 识别在admin目录中的情况 */ - $adminDir = '/' . trim(defined('__TYPECHO_ADMIN_DIR__') ? __TYPECHO_ADMIN_DIR__ : '/admin/', '/'); - $this->rootUrl = substr($this->rootUrl, 0, - strlen($adminDir)); - } - - /** 初始化站点信息 */ - if (defined('__TYPECHO_SITE_URL__')) { - $this->siteUrl = __TYPECHO_SITE_URL__; - } elseif (defined('__TYPECHO_DYNAMIC_SITE_URL__') && __TYPECHO_DYNAMIC_SITE_URL__) { - $this->siteUrl = $this->rootUrl; - } - - $this->originalSiteUrl = $this->siteUrl; - $this->siteUrl = Common::url(null, $this->siteUrl); - $this->plugins = unserialize($this->plugins); - - /** 动态判断皮肤目录 */ - $this->missingTheme = null; - - if (!is_dir($this->themeFile($this->theme))) { - $this->missingTheme = $this->theme; - $this->theme = 'default'; - } - - /** 增加对SSL连接的支持 */ - if ($this->request->isSecure() && 0 === strpos($this->siteUrl, 'http://')) { - $this->siteUrl = substr_replace($this->siteUrl, 'https', 0, 4); - } - - /** 自动初始化路由表 */ - $this->routingTable = unserialize($this->routingTable); - if (isset($this->db) && !isset($this->routingTable[0])) { - /** 解析路由并缓存 */ - $parser = new Parser($this->routingTable); - $parsedRoutingTable = $parser->parse(); - $this->routingTable = array_merge([$parsedRoutingTable], $this->routingTable); - $this->db->query($this->db->update('table.options')->rows(['value' => serialize($this->routingTable)]) - ->where('name = ?', 'routingTable')); - } + $this->push($options); } /** @@ -228,19 +185,6 @@ class Options extends Base return __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . trim($theme, './') . '/' . trim($file, './'); } - /** - * 重载父类push函数,将所有变量值压入堆栈 - * - * @param array $value 每行的值 - * @return array - */ - public function push(array $value): array - { - //将行数据按顺序置位 - $this->row[$value['name']] = $value['value']; - return $value; - } - /** * 输出网站路径 * @@ -364,7 +308,7 @@ class Options extends Base if (!isset($this->pluginConfig[$pluginName])) { if ( !empty($this->row['plugin:' . $pluginName]) - && false !== ($options = unserialize($this->row['plugin:' . $pluginName])) + && false !== ($options = $this->tryDeserialize($this->row['plugin:' . $pluginName])) ) { $this->pluginConfig[$pluginName] = new Config($options); } else { @@ -388,7 +332,7 @@ class Options extends Base if (!isset($this->personalPluginConfig[$pluginName])) { if ( !empty($this->row['_plugin:' . $pluginName]) - && false !== ($options = unserialize($this->row['_plugin:' . $pluginName])) + && false !== ($options = $this->tryDeserialize($this->row['_plugin:' . $pluginName])) ) { $this->personalPluginConfig[$pluginName] = new Config($options); } else { @@ -399,6 +343,116 @@ class Options extends Base return $this->personalPluginConfig[$pluginName]; } + /** + * @return array + */ + protected function ___routingTable(): array + { + $routingTable = $this->tryDeserialize($this->row['routingTable']); + + if (isset($this->db) && !isset($routingTable[0])) { + /** 解析路由并缓存 */ + $parser = new Parser($routingTable); + $parsedRoutingTable = $parser->parse(); + $routingTable = array_merge([$parsedRoutingTable], $routingTable); + $this->db->query($this->db->update('table.options')->rows(['value' => json_encode($routingTable)]) + ->where('name = ?', 'routingTable')); + } + + return $routingTable; + } + + /** + * @return array + */ + protected function ___actionTable(): array + { + return $this->tryDeserialize($this->row['actionTable']); + } + + /** + * @return array + */ + protected function ___panelTable(): array + { + return $this->tryDeserialize($this->row['panelTable']); + } + + /** + * @return array + */ + protected function ___plugins(): array + { + return $this->tryDeserialize($this->row['plugins']); + } + + /** + * 动态判断皮肤目录 + * + * @return string|null + */ + protected function ___missingTheme(): ?string + { + return !is_dir($this->themeFile($this->row['theme'])) ? $this->row['theme'] : null; + } + + /** + * @return string + */ + protected function ___theme(): string + { + return $this->missingTheme ? 'default' : $this->row['theme']; + } + + /** + * 动态获取根目录 + * + * @return string + */ + protected function ___rootUrl(): string + { + $rootUrl = defined('__TYPECHO_ROOT_URL__') ? __TYPECHO_ROOT_URL__ : $this->request->getRequestRoot(); + + if (defined('__TYPECHO_ADMIN__')) { + /** 识别在admin目录中的情况 */ + $adminDir = '/' . trim(defined('__TYPECHO_ADMIN_DIR__') ? __TYPECHO_ADMIN_DIR__ : '/admin/', '/'); + $rootUrl = substr($rootUrl, 0, - strlen($adminDir)); + } + + return $rootUrl; + } + + /** + * @return string + */ + protected function ___originalSiteUrl(): string + { + $siteUrl = $this->row['siteUrl']; + + if (defined('__TYPECHO_SITE_URL__')) { + $siteUrl = __TYPECHO_SITE_URL__; + } elseif (defined('__TYPECHO_DYNAMIC_SITE_URL__') && __TYPECHO_DYNAMIC_SITE_URL__) { + $siteUrl = $this->rootUrl; + } + + return $siteUrl; + } + + /** + * @return string + */ + protected function ___siteUrl(): string + { + $siteUrl = Common::url(null, $this->originalSiteUrl); + + /** 增加对SSL连接的支持 */ + if ($this->request->isSecure() && 0 === strpos($siteUrl, 'http://')) { + $siteUrl = substr_replace($siteUrl, 'https', 0, 4); + } + + return $siteUrl; + } + /** * RSS2.0 * @@ -686,4 +740,16 @@ class Options extends Base return $attachmentTypesResult; } + + /** + * Try to deserialize a value + * + * @param string $value + * @return mixed + */ + private function tryDeserialize(string $value) + { + $isSerialized = strpos($value, 'a:') === 0 || $value === 'b:0;'; + return $isSerialized ? @unserialize($value) : json_decode($value, true); + } } diff --git a/var/Widget/Options/Permalink.php b/var/Widget/Options/Permalink.php index f34a3c05..aad27f1a 100644 --- a/var/Widget/Options/Permalink.php +++ b/var/Widget/Options/Permalink.php @@ -176,7 +176,7 @@ RewriteRule . {$basePath}index.php [L] unset($routingTable[0]); } - $settings['routingTable'] = serialize($routingTable); + $settings['routingTable'] = json_encode($routingTable); } foreach ($settings as $name => $value) { diff --git a/var/Widget/Options/Reading.php b/var/Widget/Options/Reading.php index 575ea2e9..9b6df31c 100644 --- a/var/Widget/Options/Reading.php +++ b/var/Widget/Options/Reading.php @@ -73,7 +73,7 @@ class Reading extends Permalink unset($routingTable[0]); } - $settings['routingTable'] = serialize($routingTable); + $settings['routingTable'] = json_encode($routingTable); } } else { $settings['frontArchive'] = 0; diff --git a/var/Widget/Plugins/Edit.php b/var/Widget/Plugins/Edit.php index 215c0bdd..8d3c9feb 100644 --- a/var/Widget/Plugins/Edit.php +++ b/var/Widget/Plugins/Edit.php @@ -65,7 +65,7 @@ class Edit extends Options implements ActionInterface $result = call_user_func([$className, 'activate']); Plugin::activate($pluginName); $this->update( - ['value' => serialize(Plugin::export())], + ['value' => json_encode(Plugin::export())], $this->db->sql()->where('name = ?', 'plugins') ); } catch (Plugin\Exception $e) { @@ -164,16 +164,16 @@ class Edit extends Options implements ActionInterface $db->query($db->insert('table.options') ->rows([ 'name' => $pluginName, - 'value' => serialize($settings), + 'value' => json_encode($settings), 'user' => 0 ])); } else { foreach ($options as $option) { - $value = unserialize($option['value']); + $value = json_decode($option['value'], true); $value = array_merge($value, $settings); $db->query($db->update('table.options') - ->rows(['value' => serialize($value)]) + ->rows(['value' => json_encode($value)]) ->where('name = ?', $pluginName) ->where('user = ?', $option['user'])); } @@ -255,7 +255,7 @@ class Edit extends Options implements ActionInterface } Plugin::deactivate($pluginName); - $this->update(['value' => serialize(Plugin::export())], $this->db->sql()->where('name = ?', 'plugins')); + $this->update(['value' => json_encode(Plugin::export())], $this->db->sql()->where('name = ?', 'plugins')); $this->delete($this->db->sql()->where('name = ?', 'plugin:' . $pluginName)); $this->delete($this->db->sql()->where('name = ?', '_plugin:' . $pluginName)); diff --git a/var/Widget/Themes/Edit.php b/var/Widget/Themes/Edit.php index 72bab0c7..d214ceba 100644 --- a/var/Widget/Themes/Edit.php +++ b/var/Widget/Themes/Edit.php @@ -61,7 +61,7 @@ class Edit extends Options implements ActionInterface if ($options && !$this->configHandle($options, true)) { $this->insert([ 'name' => 'theme:' . $theme, - 'value' => serialize($options), + 'value' => json_encode($options), 'user' => 0 ]); } @@ -142,13 +142,13 @@ class Edit extends Options implements ActionInterface if (!$this->configHandle($settings, false)) { if ($this->options->__get('theme:' . $theme)) { $this->update( - ['value' => serialize($settings)], + ['value' => json_encode($settings)], $this->db->sql()->where('name = ?', 'theme:' . $theme) ); } else { $this->insert([ 'name' => 'theme:' . $theme, - 'value' => serialize($settings), + 'value' => json_encode($settings), 'user' => 0 ]); } diff --git a/var/Widget/Upload.php b/var/Widget/Upload.php index 41a2be3c..4d379281 100644 --- a/var/Widget/Upload.php +++ b/var/Widget/Upload.php @@ -138,7 +138,7 @@ class Upload extends Contents implements ActionInterface self::pluginHandle()->call('beforeModify', $result); $this->update([ - 'text' => serialize($result) + 'text' => json_encode($result) ], $this->db->sql()->where('cid = ?', $this->cid)); $this->db->fetchRow($this->select()->where('table.contents.cid = ?', $this->cid) @@ -309,7 +309,7 @@ class Upload extends Contents implements ActionInterface 'slug' => $result['name'], 'type' => 'attachment', 'status' => 'publish', - 'text' => serialize($result), + 'text' => json_encode($result), 'allowComment' => 1, 'allowPing' => 0, 'allowFeed' => 1 diff --git a/var/Widget/Users/Profile.php b/var/Widget/Users/Profile.php index 73f0e942..02b1b7b1 100644 --- a/var/Widget/Users/Profile.php +++ b/var/Widget/Users/Profile.php @@ -405,13 +405,13 @@ class Profile extends Users implements ActionInterface ) { Options::alloc() ->update( - ['value' => serialize($settings)], + ['value' => json_encode($settings)], $this->db->sql()->where('name = ? AND user = ?', $name, $this->user->uid) ); } else { Options::alloc()->insert([ 'name' => $name, - 'value' => serialize($settings), + 'value' => json_encode($settings), 'user' => $this->user->uid ]); } diff --git a/var/Widget/XmlRpc.php b/var/Widget/XmlRpc.php index b663f2ab..bc48267b 100644 --- a/var/Widget/XmlRpc.php +++ b/var/Widget/XmlRpc.php @@ -547,10 +547,10 @@ class XmlRpc extends Contents implements ActionInterface, Hook $attachment['title'] = $content['post_title']; $attachment['slug'] = $content['post_excerpt']; - $text = unserialize($post->text); + $text = json_decode($post->text, true); $text['description'] = $content['description']; - $attachment['text'] = serialize($text); + $attachment['text'] = json_encode($text); /** 更新数据 */ $updateRows = $this->update($attachment, $this->db->sql()->where('cid = ?', $postId)); @@ -1376,7 +1376,7 @@ class XmlRpc extends Contents implements ActionInterface, Hook 'slug' => $result['name'], 'type' => 'attachment', 'status' => 'publish', - 'text' => serialize($result), + 'text' => json_encode($result), 'allowComment' => 1, 'allowPing' => 0, 'allowFeed' => 1