= $title ?>
- next()): ?>
- current): ?> class="current"> file(); ?>
- file == 'guest.html'): ?>
to($options); /** 初始化上下文 */ $request = $options->request; $response = $options->response; $current = $request->get('act', 'index'); $theme = $request->get('file', 'owner.html'); $title = '编辑邮件模板 ' . $theme; if ($current == 'index') { $title = '邮件发信模板'; } if ($request->is('do=editTheme')) { editTheme($request->edit); } function editTheme($file) { $template = Plugin::configStr('template', 'default'); $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $template . DIRECTORY_SEPARATOR . $file; if (file_exists($path) && is_writeable($path)) { $handle = fopen($path, 'wb'); if ($handle && fwrite($handle, Options::alloc()->request->content)) { fclose($handle); Notice::alloc()->set(_t("文件 %s 的更改已经保存", $file), 'success'); } else { Notice::alloc()->set(_t("文件 %s 无法被写入", $file), 'error'); } Options::alloc()->response->goBack(); } else { throw new Typecho_Widget_Exception(_t('您编辑的模板文件不存在')); } } class CommentNotifier_Console extends Typecho_Widget { /** @var 模板文件目录 */ private $_dir; /** * 当前文件 * * @access private * @var string */ private $_currentFile; /** * 执行函数 * * @access public * @return void * @throws Typecho_Widget_Exception */ public function execute() { $this->_dir = dirname(__FILE__); $template = Plugin::configStr('template', 'default'); $path = '/template/' . $template; $files = glob($this->_dir . $path . '/*.{html,HTML}', GLOB_BRACE); $this->_currentFile = $this->request->get('file', 'owner.html'); if (preg_match("/^([_0-9a-z-\.\ ])+$/i", $this->_currentFile) && file_exists($this->_dir . $path . '/' . $this->_currentFile)) { foreach ($files as $file) { if (file_exists($file)) { $file = basename($file); $this->push(array( 'file' => $file, 'current' => ($file == $this->_currentFile) )); } } return; } throw new Typecho_Widget_Exception('模板文件不存在', 404); } /** * 获取菜单标题 * * @access public * @return string */ public function getMenuTitle(): string { return _t('编辑文件 %s', $this->_currentFile); } /** * 获取文件内容 * * @access public * @return string */ public function currentContent(): string { $template = Plugin::configStr('template', 'default'); $path = '/template/' . $template; return htmlspecialchars(file_get_contents($this->_dir . $path . '/' . $this->_currentFile)); } /** * 获取文件是否可读 * * @access public * @return bool */ public function currentIsWriteable(): bool { $template = Plugin::configStr('template', 'default'); $path = '/template/' . $template; return is_writeable($this->_dir . $path . '/' . $this->_currentFile); } /** * 获取当前文件 * * @access public * @return string */ public function currentFile(): string { return $this->_currentFile; } } ?>