Skip to content

Commit 8c3d36d

Browse files
committed
fix some bugs
1 parent 6a73282 commit 8c3d36d

File tree

13 files changed

+119
-51
lines changed

13 files changed

+119
-51
lines changed

Diff for: admin/common.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
define('__TYPECHO_ADMIN__', true);
77

88
/** 载入配置文件 */
9-
if (!@include_once __DIR__ . '/../config.inc.php') {
9+
if (!defined('__TYPECHO_ROOT_DIR__') && !@include_once __DIR__ . '/../config.inc.php') {
1010
file_exists(__DIR__ . '/../install.php') ? header('Location: ../install.php') : print('Missing Config File');
1111
exit;
1212
}

Diff for: index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
/** 载入配置支持 */
11-
if (!@include_once 'config.inc.php') {
11+
if (!defined('__TYPECHO_ROOT_DIR__') && !@include_once 'config.inc.php') {
1212
file_exists('./install.php') ? header('Location: install.php') : print('Missing Config File');
1313
exit;
1414
}

Diff for: var/Typecho/Request.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ class Typecho_Request
122122
'integer' => 'intval',
123123
'search' => array('Typecho_Common', 'filterSearchQuery'),
124124
'xss' => array('Typecho_Common', 'removeXSS'),
125-
'url' => array('Typecho_Common', 'safeUrl')
125+
'url' => array('Typecho_Common', 'safeUrl'),
126+
'slug' => array('Typecho_Common', 'slugName')
126127
);
127128

128129
/**

Diff for: var/Typecho/Widget.php

-3
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ public static function widget($alias, $params = NULL, $request = NULL, $enableRe
196196
}
197197

198198
if (!isset(self::$_widgetPool[$alias])) {
199-
$fileName = str_replace('_', '/', $className) . '.php';
200-
require_once $fileName;
201-
202199
/** 如果类不存在 */
203200
if (!class_exists($className)) {
204201
throw new Typecho_Widget_Exception($className);

Diff for: var/Widget/Archive.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public function __construct($request, $response, $params = NULL)
234234
}
235235

236236
/** 初始化皮肤路径 */
237-
$this->_themeDir = __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_THEME_DIR__ . '/' . $this->options->theme . '/';
237+
$this->_themeDir = rtrim($this->options->themeFile($this->options->theme), '/') . '/';
238238

239239
/** 处理feed模式 **/
240240
if ('feed' == $this->parameter->type) {
@@ -1864,7 +1864,7 @@ public function is($archiveType, $archiveSlug = NULL)
18641864
*/
18651865
public function need($fileName)
18661866
{
1867-
require __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_THEME_DIR__ . '/' . $this->options->theme . '/' . $fileName;
1867+
require $this->_themeDir . $fileName;
18681868
}
18691869

18701870
/**

Diff for: var/Widget/Options.php

+23
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,29 @@ public function pluginUrl($path = NULL)
452452
echo Typecho_Common::url($path, $this->pluginUrl);
453453
}
454454

455+
/**
456+
* 获取皮肤文件
457+
*
458+
* @param string $theme
459+
* @param string $file
460+
* @return string
461+
*/
462+
public function themeFile($theme, $file = '')
463+
{
464+
return __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . trim($theme, './') . '/' . trim($file, './');
465+
}
466+
467+
/**
468+
* 获取插件目录
469+
*
470+
* @param $plugin
471+
* @return string
472+
*/
473+
public function pluginDir($plugin)
474+
{
475+
return __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__;
476+
}
477+
455478
/**
456479
* 输出后台路径
457480
*

Diff for: var/Widget/Plugins/Config.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ class Widget_Plugins_Config extends Widget_Abstract_Options
5151
public function execute()
5252
{
5353
$this->user->pass('administrator');
54-
if (!isset($this->request->config)) {
54+
$config = $this->request->filter('slug')->config;
55+
if (empty($config)) {
5556
throw new Typecho_Widget_Exception(_t('插件不存在'), 404);
5657
}
5758

5859
/** 获取插件入口 */
59-
list($this->_pluginFileName, $this->_className) = Typecho_Plugin::portal($this->request->config,
60-
__TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
60+
list($this->_pluginFileName, $this->_className) = Typecho_Plugin::portal($config,
61+
$this->options->pluginDir($config));
6162
$this->info = Typecho_Plugin::parseInfo($this->_pluginFileName);
6263
}
6364

@@ -82,7 +83,7 @@ public function getMenuTitle()
8283
public function config()
8384
{
8485
/** 获取插件名称 */
85-
$pluginName = $this->request->config;
86+
$pluginName = $this->request->filter('slug')->config;
8687

8788
/** 获取已启用插件 */
8889
$plugins = Typecho_Plugin::export();

Diff for: var/Widget/Plugins/Edit.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function configPlugin($pluginName, array $settings, $isPersonal =
7373
public function activate($pluginName)
7474
{
7575
/** 获取插件入口 */
76-
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
76+
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, $this->options->pluginDir($pluginName));
7777
$info = Typecho_Plugin::parseInfo($pluginFileName);
7878

7979
/** 检测依赖信息 */
@@ -155,7 +155,7 @@ public function deactivate($pluginName)
155155

156156
try {
157157
/** 获取插件入口 */
158-
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
158+
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, $this->options->pluginDir($pluginName));
159159
} catch (Typecho_Plugin_Exception $e) {
160160
$pluginFileExist = false;
161161

@@ -251,7 +251,7 @@ public function config($pluginName)
251251
public function configHandle($pluginName, array $settings, $isInit)
252252
{
253253
/** 获取插件入口 */
254-
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
254+
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, $this->options->pluginDir($pluginName));
255255

256256
if (method_exists($className, 'configHandle')) {
257257
call_user_func(array($className, 'configHandle'), $settings, $isInit);
@@ -289,9 +289,9 @@ public function action()
289289
{
290290
$this->user->pass('administrator');
291291
$this->security->protect();
292-
$this->on($this->request->is('activate'))->activate($this->request->activate);
293-
$this->on($this->request->is('deactivate'))->deactivate($this->request->deactivate);
294-
$this->on($this->request->is('config'))->config($this->request->config);
292+
$this->on($this->request->is('activate'))->activate($this->request->filter('slug')->activate);
293+
$this->on($this->request->is('deactivate'))->deactivate($this->request->filter('slug')->deactivate);
294+
$this->on($this->request->is('config'))->config($this->request->filter('slug')->config);
295295
$this->response->redirect($this->options->adminUrl);
296296
}
297297
}

Diff for: var/Widget/Plugins/List.php

+42-17
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,42 @@ class Widget_Plugins_List extends Typecho_Widget
2727
*/
2828
public $activatedPlugins = array();
2929

30+
/**
31+
* @return array
32+
*/
33+
protected function getPlugins()
34+
{
35+
return glob(__TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__ . '/*');
36+
}
37+
38+
/**
39+
* @param string $plugin
40+
* @param string $index
41+
* @return array|null
42+
*/
43+
protected function getPlugin($plugin, $index)
44+
{
45+
if (is_dir($plugin)) {
46+
/** 获取插件名称 */
47+
$pluginName = basename($plugin);
48+
49+
/** 获取插件主文件 */
50+
$pluginFileName = $plugin . '/Plugin.php';
51+
} else if (file_exists($plugin) && 'index.php' != basename($plugin)) {
52+
$pluginFileName = $plugin;
53+
$part = explode('.', basename($plugin));
54+
if (2 == count($part) && 'php' == $part[1]) {
55+
$pluginName = $part[0];
56+
} else {
57+
return NULL;
58+
}
59+
} else {
60+
return NULL;
61+
}
62+
63+
return array($pluginName, $pluginFileName);
64+
}
65+
3066
/**
3167
* 执行函数
3268
*
@@ -36,33 +72,22 @@ class Widget_Plugins_List extends Typecho_Widget
3672
public function execute()
3773
{
3874
/** 列出插件目录 */
39-
$pluginDirs = glob(__TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__ . '/*');
75+
$pluginDirs = $this->getPlugins();
4076
$this->parameter->setDefault(array('activated' => NULL));
4177

4278
/** 获取已启用插件 */
4379
$plugins = Typecho_Plugin::export();
4480
$this->activatedPlugins = $plugins['activated'];
4581

4682
if (!empty($pluginDirs)) {
47-
foreach ($pluginDirs as $pluginDir) {
48-
if (is_dir($pluginDir)) {
49-
/** 获取插件名称 */
50-
$pluginName = basename($pluginDir);
51-
52-
/** 获取插件主文件 */
53-
$pluginFileName = $pluginDir . '/Plugin.php';
54-
} else if (file_exists($pluginDir) && 'index.php' != basename($pluginDir)) {
55-
$pluginFileName = $pluginDir;
56-
$part = explode('.', basename($pluginDir));
57-
if (2 == count($part) && 'php' == $part[1]) {
58-
$pluginName = $part[0];
59-
} else {
60-
continue;
61-
}
62-
} else {
83+
foreach ($pluginDirs as $key => $pluginDir) {
84+
$parts = $this->getPlugin($pluginDir, $key);
85+
if (empty($parts)) {
6386
continue;
6487
}
6588

89+
list ($pluginName, $pluginFileName) = $parts;
90+
6691
if (file_exists($pluginFileName)) {
6792
$info = Typecho_Plugin::parseInfo($pluginFileName);
6893
$info['name'] = $pluginName;

Diff for: var/Widget/Themes/Config.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public function getMenuTitle()
5454
*/
5555
public static function isExists()
5656
{
57-
$configFile = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__
58-
. '/' . Typecho_Widget::widget('Widget_Options')->theme . '/functions.php';
59-
57+
$options = Typecho_Widget::widget('Widget_Options');
58+
$configFile = $options->themeFile($options->theme, 'functions.php');
59+
6060
if (file_exists($configFile)) {
6161
require_once $configFile;
6262

Diff for: var/Widget/Themes/Edit.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Widget_Themes_Edit extends Widget_Abstract_Options implements Widget_Inter
3232
public function changeTheme($theme)
3333
{
3434
$theme = trim($theme, './');
35-
if (is_dir(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . $theme)) {
35+
if (is_dir($this->options->themeFile($theme))) {
3636
/** 删除原外观设置信息 */
3737
$this->delete($this->db->sql()->where('name = ?', 'theme:' . $this->options->theme));
3838

@@ -43,7 +43,7 @@ public function changeTheme($theme)
4343
$this->update(array('value' => 'recent'), $this->db->sql()->where('name = ?', 'frontPage'));
4444
}
4545

46-
$configFile = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . $theme . '/functions.php';
46+
$configFile = $this->options->themeFile($theme, 'functions.php');
4747

4848
if (file_exists($configFile)) {
4949
require_once $configFile;
@@ -82,7 +82,7 @@ public function changeTheme($theme)
8282
*/
8383
public function editThemeFile($theme, $file)
8484
{
85-
$path = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . trim($theme, './') . '/' . trim($file, './');
85+
$path = $this->options->themeFile($theme, $file);
8686

8787
if (file_exists($path) && is_writeable($path) && !Typecho_Common::isAppEngine()
8888
&& (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__)) {
@@ -170,8 +170,9 @@ public function action()
170170
/** 需要管理员权限 */
171171
$this->user->pass('administrator');
172172
$this->security->protect();
173-
$this->on($this->request->is('change'))->changeTheme($this->request->change);
174-
$this->on($this->request->is('edit&theme'))->editThemeFile($this->request->theme, $this->request->edit);
173+
$this->on($this->request->is('change'))->changeTheme($this->request->filter('slug')->change);
174+
$this->on($this->request->is('edit&theme'))
175+
->editThemeFile($this->request->filter('slug')->theme, $this->request->edit);
175176
$this->on($this->request->is('config'))->config($this->options->theme);
176177
$this->response->redirect($this->options->adminUrl);
177178
}

Diff for: var/Widget/Themes/Files.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public function execute()
4848
{
4949
/** 管理员权限 */
5050
$this->widget('Widget_User')->pass('administrator');
51-
$this->_currentTheme = $this->request->get('theme', $this->widget('Widget_Options')->theme);
51+
$this->_currentTheme = $this->request->filter('slug')->get('theme', $this->widget('Widget_Options')->theme);
5252

5353
if (preg_match("/^([_0-9a-z-\.\ ])+$/i", $this->_currentTheme)
54-
&& is_dir($dir = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . $this->_currentTheme)
54+
&& is_dir($dir = $this->widget('Widget_Options')->themeFile($this->_currentTheme))
5555
&& (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__)) {
5656
$files = glob($dir . '/*.{php,PHP,js,JS,css,CSS,vbs,VBS}', GLOB_BRACE);
5757
$this->_currentFile = $this->request->get('file', 'index.php');
@@ -95,8 +95,8 @@ public function getMenuTitle()
9595
*/
9696
public function currentContent()
9797
{
98-
return htmlspecialchars(file_get_contents(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' .
99-
$this->_currentTheme . '/' . $this->_currentFile));
98+
return htmlspecialchars(file_get_contents($this->widget('Widget_Options')
99+
->themeFile($this->_currentTheme, $this->_currentFile)));
100100
}
101101

102102
/**
@@ -107,8 +107,8 @@ public function currentContent()
107107
*/
108108
public function currentIsWriteable()
109109
{
110-
return is_writeable(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' .
111-
$this->_currentTheme . '/' . $this->_currentFile) && !Typecho_Common::isAppEngine()
110+
return is_writeable($this->widget('Widget_Options')
111+
->themeFile($this->_currentTheme, $this->_currentFile)) && !Typecho_Common::isAppEngine()
112112
&& (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__);
113113
}
114114

Diff for: var/Widget/Themes/List.php

+22-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@
2121
*/
2222
class Widget_Themes_List extends Typecho_Widget
2323
{
24+
/**
25+
* @return array
26+
*/
27+
protected function getThemes()
28+
{
29+
return glob(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/*');
30+
}
31+
32+
/**
33+
* get theme
34+
*
35+
* @param string $theme
36+
* @param mixed $index
37+
* @return string
38+
*/
39+
protected function getTheme($theme, $index)
40+
{
41+
return basename($theme);
42+
}
43+
2444
/**
2545
* 执行函数
2646
*
@@ -29,7 +49,7 @@ class Widget_Themes_List extends Typecho_Widget
2949
*/
3050
public function execute()
3151
{
32-
$themes = glob(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/*');
52+
$themes = $this->getThemes();
3353

3454
if ($themes) {
3555
$options = $this->widget('Widget_Options');
@@ -42,7 +62,7 @@ public function execute()
4262
$themeFile = $theme . '/index.php';
4363
if (file_exists($themeFile)) {
4464
$info = Typecho_Plugin::parseInfo($themeFile);
45-
$info['name'] = basename($theme);
65+
$info['name'] = $this->getTheme($theme, $key);
4666

4767
if ($info['activated'] = ($options->theme == $info['name'])) {
4868
$activated = $key;

0 commit comments

Comments
 (0)