fix some bugs

This commit is contained in:
祁宁 2014-04-22 22:42:35 +08:00
parent 6a73282e80
commit 8c3d36d1b2
13 changed files with 119 additions and 51 deletions

View File

@ -6,7 +6,7 @@ if (!defined('__DIR__')) {
define('__TYPECHO_ADMIN__', true);
/** 载入配置文件 */
if (!@include_once __DIR__ . '/../config.inc.php') {
if (!defined('__TYPECHO_ROOT_DIR__') && !@include_once __DIR__ . '/../config.inc.php') {
file_exists(__DIR__ . '/../install.php') ? header('Location: ../install.php') : print('Missing Config File');
exit;
}

View File

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

View File

@ -122,7 +122,8 @@ class Typecho_Request
'integer' => 'intval',
'search' => array('Typecho_Common', 'filterSearchQuery'),
'xss' => array('Typecho_Common', 'removeXSS'),
'url' => array('Typecho_Common', 'safeUrl')
'url' => array('Typecho_Common', 'safeUrl'),
'slug' => array('Typecho_Common', 'slugName')
);
/**

View File

@ -196,9 +196,6 @@ abstract class Typecho_Widget
}
if (!isset(self::$_widgetPool[$alias])) {
$fileName = str_replace('_', '/', $className) . '.php';
require_once $fileName;
/** 如果类不存在 */
if (!class_exists($className)) {
throw new Typecho_Widget_Exception($className);

View File

@ -234,7 +234,7 @@ class Widget_Archive extends Widget_Abstract_Contents
}
/** 初始化皮肤路径 */
$this->_themeDir = __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_THEME_DIR__ . '/' . $this->options->theme . '/';
$this->_themeDir = rtrim($this->options->themeFile($this->options->theme), '/') . '/';
/** 处理feed模式 **/
if ('feed' == $this->parameter->type) {
@ -1864,7 +1864,7 @@ var TypechoComment = {
*/
public function need($fileName)
{
require __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_THEME_DIR__ . '/' . $this->options->theme . '/' . $fileName;
require $this->_themeDir . $fileName;
}
/**

View File

@ -452,6 +452,29 @@ class Widget_Options extends Typecho_Widget
echo Typecho_Common::url($path, $this->pluginUrl);
}
/**
* 获取皮肤文件
*
* @param string $theme
* @param string $file
* @return string
*/
public function themeFile($theme, $file = '')
{
return __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . trim($theme, './') . '/' . trim($file, './');
}
/**
* 获取插件目录
*
* @param $plugin
* @return string
*/
public function pluginDir($plugin)
{
return __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__;
}
/**
* 输出后台路径
*

View File

@ -51,13 +51,14 @@ class Widget_Plugins_Config extends Widget_Abstract_Options
public function execute()
{
$this->user->pass('administrator');
if (!isset($this->request->config)) {
$config = $this->request->filter('slug')->config;
if (empty($config)) {
throw new Typecho_Widget_Exception(_t('插件不存在'), 404);
}
/** 获取插件入口 */
list($this->_pluginFileName, $this->_className) = Typecho_Plugin::portal($this->request->config,
__TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
list($this->_pluginFileName, $this->_className) = Typecho_Plugin::portal($config,
$this->options->pluginDir($config));
$this->info = Typecho_Plugin::parseInfo($this->_pluginFileName);
}
@ -82,7 +83,7 @@ class Widget_Plugins_Config extends Widget_Abstract_Options
public function config()
{
/** 获取插件名称 */
$pluginName = $this->request->config;
$pluginName = $this->request->filter('slug')->config;
/** 获取已启用插件 */
$plugins = Typecho_Plugin::export();

View File

@ -73,7 +73,7 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
public function activate($pluginName)
{
/** 获取插件入口 */
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, $this->options->pluginDir($pluginName));
$info = Typecho_Plugin::parseInfo($pluginFileName);
/** 检测依赖信息 */
@ -155,7 +155,7 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
try {
/** 获取插件入口 */
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, $this->options->pluginDir($pluginName));
} catch (Typecho_Plugin_Exception $e) {
$pluginFileExist = false;
@ -251,7 +251,7 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
public function configHandle($pluginName, array $settings, $isInit)
{
/** 获取插件入口 */
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, $this->options->pluginDir($pluginName));
if (method_exists($className, 'configHandle')) {
call_user_func(array($className, 'configHandle'), $settings, $isInit);
@ -289,9 +289,9 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
{
$this->user->pass('administrator');
$this->security->protect();
$this->on($this->request->is('activate'))->activate($this->request->activate);
$this->on($this->request->is('deactivate'))->deactivate($this->request->deactivate);
$this->on($this->request->is('config'))->config($this->request->config);
$this->on($this->request->is('activate'))->activate($this->request->filter('slug')->activate);
$this->on($this->request->is('deactivate'))->deactivate($this->request->filter('slug')->deactivate);
$this->on($this->request->is('config'))->config($this->request->filter('slug')->config);
$this->response->redirect($this->options->adminUrl);
}
}

View File

@ -27,6 +27,42 @@ class Widget_Plugins_List extends Typecho_Widget
*/
public $activatedPlugins = array();
/**
* @return array
*/
protected function getPlugins()
{
return glob(__TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__ . '/*');
}
/**
* @param string $plugin
* @param string $index
* @return array|null
*/
protected function getPlugin($plugin, $index)
{
if (is_dir($plugin)) {
/** 获取插件名称 */
$pluginName = basename($plugin);
/** 获取插件主文件 */
$pluginFileName = $plugin . '/Plugin.php';
} else if (file_exists($plugin) && 'index.php' != basename($plugin)) {
$pluginFileName = $plugin;
$part = explode('.', basename($plugin));
if (2 == count($part) && 'php' == $part[1]) {
$pluginName = $part[0];
} else {
return NULL;
}
} else {
return NULL;
}
return array($pluginName, $pluginFileName);
}
/**
* 执行函数
*
@ -36,7 +72,7 @@ class Widget_Plugins_List extends Typecho_Widget
public function execute()
{
/** 列出插件目录 */
$pluginDirs = glob(__TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__ . '/*');
$pluginDirs = $this->getPlugins();
$this->parameter->setDefault(array('activated' => NULL));
/** 获取已启用插件 */
@ -44,25 +80,14 @@ class Widget_Plugins_List extends Typecho_Widget
$this->activatedPlugins = $plugins['activated'];
if (!empty($pluginDirs)) {
foreach ($pluginDirs as $pluginDir) {
if (is_dir($pluginDir)) {
/** 获取插件名称 */
$pluginName = basename($pluginDir);
/** 获取插件主文件 */
$pluginFileName = $pluginDir . '/Plugin.php';
} else if (file_exists($pluginDir) && 'index.php' != basename($pluginDir)) {
$pluginFileName = $pluginDir;
$part = explode('.', basename($pluginDir));
if (2 == count($part) && 'php' == $part[1]) {
$pluginName = $part[0];
} else {
continue;
}
} else {
foreach ($pluginDirs as $key => $pluginDir) {
$parts = $this->getPlugin($pluginDir, $key);
if (empty($parts)) {
continue;
}
list ($pluginName, $pluginFileName) = $parts;
if (file_exists($pluginFileName)) {
$info = Typecho_Plugin::parseInfo($pluginFileName);
$info['name'] = $pluginName;

View File

@ -54,9 +54,9 @@ class Widget_Themes_Config extends Widget_Abstract_Options
*/
public static function isExists()
{
$configFile = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__
. '/' . Typecho_Widget::widget('Widget_Options')->theme . '/functions.php';
$options = Typecho_Widget::widget('Widget_Options');
$configFile = $options->themeFile($options->theme, 'functions.php');
if (file_exists($configFile)) {
require_once $configFile;

View File

@ -32,7 +32,7 @@ class Widget_Themes_Edit extends Widget_Abstract_Options implements Widget_Inter
public function changeTheme($theme)
{
$theme = trim($theme, './');
if (is_dir(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . $theme)) {
if (is_dir($this->options->themeFile($theme))) {
/** 删除原外观设置信息 */
$this->delete($this->db->sql()->where('name = ?', 'theme:' . $this->options->theme));
@ -43,7 +43,7 @@ class Widget_Themes_Edit extends Widget_Abstract_Options implements Widget_Inter
$this->update(array('value' => 'recent'), $this->db->sql()->where('name = ?', 'frontPage'));
}
$configFile = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . $theme . '/functions.php';
$configFile = $this->options->themeFile($theme, 'functions.php');
if (file_exists($configFile)) {
require_once $configFile;
@ -82,7 +82,7 @@ class Widget_Themes_Edit extends Widget_Abstract_Options implements Widget_Inter
*/
public function editThemeFile($theme, $file)
{
$path = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . trim($theme, './') . '/' . trim($file, './');
$path = $this->options->themeFile($theme, $file);
if (file_exists($path) && is_writeable($path) && !Typecho_Common::isAppEngine()
&& (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__)) {
@ -170,8 +170,9 @@ class Widget_Themes_Edit extends Widget_Abstract_Options implements Widget_Inter
/** 需要管理员权限 */
$this->user->pass('administrator');
$this->security->protect();
$this->on($this->request->is('change'))->changeTheme($this->request->change);
$this->on($this->request->is('edit&theme'))->editThemeFile($this->request->theme, $this->request->edit);
$this->on($this->request->is('change'))->changeTheme($this->request->filter('slug')->change);
$this->on($this->request->is('edit&theme'))
->editThemeFile($this->request->filter('slug')->theme, $this->request->edit);
$this->on($this->request->is('config'))->config($this->options->theme);
$this->response->redirect($this->options->adminUrl);
}

View File

@ -48,10 +48,10 @@ class Widget_Themes_Files extends Typecho_Widget
{
/** 管理员权限 */
$this->widget('Widget_User')->pass('administrator');
$this->_currentTheme = $this->request->get('theme', $this->widget('Widget_Options')->theme);
$this->_currentTheme = $this->request->filter('slug')->get('theme', $this->widget('Widget_Options')->theme);
if (preg_match("/^([_0-9a-z-\.\ ])+$/i", $this->_currentTheme)
&& is_dir($dir = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' . $this->_currentTheme)
&& is_dir($dir = $this->widget('Widget_Options')->themeFile($this->_currentTheme))
&& (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__)) {
$files = glob($dir . '/*.{php,PHP,js,JS,css,CSS,vbs,VBS}', GLOB_BRACE);
$this->_currentFile = $this->request->get('file', 'index.php');
@ -95,8 +95,8 @@ class Widget_Themes_Files extends Typecho_Widget
*/
public function currentContent()
{
return htmlspecialchars(file_get_contents(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' .
$this->_currentTheme . '/' . $this->_currentFile));
return htmlspecialchars(file_get_contents($this->widget('Widget_Options')
->themeFile($this->_currentTheme, $this->_currentFile)));
}
/**
@ -107,8 +107,8 @@ class Widget_Themes_Files extends Typecho_Widget
*/
public function currentIsWriteable()
{
return is_writeable(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/' .
$this->_currentTheme . '/' . $this->_currentFile) && !Typecho_Common::isAppEngine()
return is_writeable($this->widget('Widget_Options')
->themeFile($this->_currentTheme, $this->_currentFile)) && !Typecho_Common::isAppEngine()
&& (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__);
}

View File

@ -21,6 +21,26 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
*/
class Widget_Themes_List extends Typecho_Widget
{
/**
* @return array
*/
protected function getThemes()
{
return glob(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/*');
}
/**
* get theme
*
* @param string $theme
* @param mixed $index
* @return string
*/
protected function getTheme($theme, $index)
{
return basename($theme);
}
/**
* 执行函数
*
@ -29,7 +49,7 @@ class Widget_Themes_List extends Typecho_Widget
*/
public function execute()
{
$themes = glob(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/*');
$themes = $this->getThemes();
if ($themes) {
$options = $this->widget('Widget_Options');
@ -42,7 +62,7 @@ class Widget_Themes_List extends Typecho_Widget
$themeFile = $theme . '/index.php';
if (file_exists($themeFile)) {
$info = Typecho_Plugin::parseInfo($themeFile);
$info['name'] = basename($theme);
$info['name'] = $this->getTheme($theme, $key);
if ($info['activated'] = ($options->theme == $info['name'])) {
$activated = $key;