diff --git a/admin/themes.php b/admin/themes.php index 0358e67b..2a3a6601 100644 --- a/admin/themes.php +++ b/admin/themes.php @@ -12,7 +12,7 @@ include 'menu.php';
missingTheme); ?>
+description); ?>
- theme != $themes->name): ?> + theme != $themes->name || $options->missingTheme): ?>- + diff --git a/config.inc.sqlite.php b/config.inc.sqlite.php new file mode 100644 index 00000000..23e48892 --- /dev/null +++ b/config.inc.sqlite.php @@ -0,0 +1,27 @@ +addServer(array ( + 'file' => '/Users/joyqi/Work/typecho/usr/62396a762847a.db', +), \Typecho\Db::READ | \Typecho\Db::WRITE); +\Typecho\Db::set($db); + +define('__TYPECHO_DEBUG__', true); diff --git a/var/Widget/Options.php b/var/Widget/Options.php index 0519b0e2..f520d5f4 100644 --- a/var/Widget/Options.php +++ b/var/Widget/Options.php @@ -46,6 +46,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) { * @property string $keywords * @property string $lang * @property string $theme + * @property string|null $missingTheme * @property int $pageSize * @property int $serverTimezone * @property int $timezone @@ -186,7 +187,12 @@ class Options extends Base $this->plugins = unserialize($this->plugins); /** 动态判断皮肤目录 */ - $this->theme = is_dir($this->themeFile($this->theme)) ? $this->theme : 'default'; + $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://')) { diff --git a/var/Widget/Themes/Config.php b/var/Widget/Themes/Config.php index 678a6252..02bda8f8 100644 --- a/var/Widget/Themes/Config.php +++ b/var/Widget/Themes/Config.php @@ -47,7 +47,7 @@ class Config extends BaseOptions $options = Options::alloc(); $configFile = $options->themeFile($options->theme, 'functions.php'); - if (file_exists($configFile)) { + if (!$options->missingTheme && file_exists($configFile)) { require_once $configFile; if (function_exists('themeConfig')) { diff --git a/var/Widget/Themes/Edit.php b/var/Widget/Themes/Edit.php index 64177a9f..5b1cb1a4 100644 --- a/var/Widget/Themes/Edit.php +++ b/var/Widget/Themes/Edit.php @@ -36,7 +36,8 @@ class Edit extends Options implements ActionInterface $theme = trim($theme, './'); if (is_dir($this->options->themeFile($theme))) { /** 删除原外观设置信息 */ - $this->delete($this->db->sql()->where('name = ?', 'theme:' . $this->options->theme)); + $oldTheme = $this->options->missingTheme ?: $this->options->theme; + $this->delete($this->db->sql()->where('name = ?', 'theme:' . $oldTheme)); $this->update(['value' => $theme], $this->db->sql()->where('name = ?', 'theme')); @@ -130,7 +131,7 @@ class Edit extends Options implements ActionInterface $form = Config::alloc()->config(); /** 验证表单 */ - if ($form->validate()) { + if (!Config::isExists() || $form->validate()) { $this->response->goBack(); } diff --git a/var/Widget/Themes/Files.php b/var/Widget/Themes/Files.php index 80a073aa..a44ba928 100644 --- a/var/Widget/Themes/Files.php +++ b/var/Widget/Themes/Files.php @@ -81,6 +81,17 @@ class Files extends Base throw new Widget\Exception('风格文件不存在', 404); } + /** + * 判断是否拥有写入权限 + * + * @return bool + */ + public static function isWriteable(): bool + { + return (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__) + && !Options::alloc()->missingTheme; + } + /** * 获取菜单标题 * @@ -111,7 +122,7 @@ class Files extends Base { return is_writeable(Options::alloc() ->themeFile($this->currentTheme, $this->currentFile)) - && (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__); + && self::isWriteable(); } /**