widget('Widget_User')->pass('administrator'); $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 = $this->widget('Widget_Options')->themeFile($this->_currentTheme)) && (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__)) { $files = array_filter(glob($dir . '/*'), function ($path) { return preg_match("/\.(php|js|css|vbs)$/i", $path); }); $this->_currentFile = $this->request->get('file', 'index.php'); if (preg_match("/^([_0-9a-z-\.\ ])+$/i", $this->_currentFile) && file_exists($dir . '/' . $this->_currentFile)) { foreach ($files as $file) { if (file_exists($file)) { $file = basename($file); $this->push(array( 'file' => $file, 'theme' => $this->_currentTheme, 'current' => ($file == $this->_currentFile) )); } } return; } } throw new Typecho_Widget_Exception('风格文件不存在', 404); } /** * 获取菜单标题 * * @access public * @return string */ public function getMenuTitle() { return _t('编辑文件 %s', $this->_currentFile); } /** * 获取文件内容 * * @access public * @return string */ public function currentContent() { return htmlspecialchars(file_get_contents($this->widget('Widget_Options') ->themeFile($this->_currentTheme, $this->_currentFile))); } /** * 获取文件是否可读 * * @access public * @return string */ public function currentIsWriteable() { return is_writeable($this->widget('Widget_Options') ->themeFile($this->_currentTheme, $this->_currentFile)) && !Typecho_Common::isAppEngine() && (!defined('__TYPECHO_THEME_WRITEABLE__') || __TYPECHO_THEME_WRITEABLE__); } /** * 获取当前文件 * * @access public * @return string */ public function currentFile() { return $this->_currentFile; } /** * 获取当前风格 * * @access public * @return string */ public function currentTheme() { return $this->_currentTheme; } }