-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathconsole.php
221 lines (203 loc) · 7.92 KB
/
console.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
include 'header.php';
include 'menu.php';
use Typecho\Widget;
use Widget\Notice;
use Widget\Options;
\Widget\Options::alloc()->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)
{ $muban=\Widget\Options::alloc()->plugin('CommentNotifier')->muban;
$path = dirname(__FILE__) . '/' . $file;
if(!empty($muban)){
$path = dirname(__FILE__) .'/template/'. $muban .'/' . $file;
}
if (file_exists($path) && is_writeable($path)) {
$handle = fopen($path, 'wb');
if ($handle && fwrite($handle, \Widget\Options::alloc()->request->content)) {
fclose($handle);
\Widget\Notice::alloc()->set(_t("文件 %s 的更改已经保存", $file), 'success');
} else {
\Widget\Notice::alloc()->set(_t("文件 %s 无法被写入", $file), 'error');
}
\Widget\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()
{ $muban=\Widget\Options::alloc()->plugin('CommentNotifier')->muban;
$p='';
if(!empty($muban)){
$p = '/template/'. $muban ;
}
$this->_dir = dirname(__FILE__);
$files = glob($this->_dir .$p. '/*.{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 .$p. '/' . $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()
{
return _t('编辑文件 %s', $this->_currentFile);
}
/**
* 获取文件内容
*
* @access public
* @return string
*/
public function currentContent()
{ $muban=\Widget\Options::alloc()->plugin('CommentNotifier')->muban;
$p='';
if(!empty($muban)){
$p = '/template/'. $muban ;
}
return htmlspecialchars(file_get_contents($this->_dir .$p. '/' . $this->_currentFile));
}
/**
* 获取文件是否可读
*
* @access public
* @return string
*/
public function currentIsWriteable()
{ $muban=\Widget\Options::alloc()->plugin('CommentNotifier')->muban;
$p='';
if(!empty($muban)){
$p = '/template/'. $muban ;
}
return is_writeable($this->_dir .$p. '/' . $this->_currentFile);
}
/**
* 获取当前文件
*
* @access public
* @return string
*/
public function currentFile()
{
return $this->_currentFile;
}
}
?>
<div class="main">
<div class="body container">
<div class="typecho-page-title">
<h2><?=$title?></h2>
</div>
<div class="row typecho-page-main" role="main">
<div class="col-mb-12">
<ul class="typecho-option-tabs fix-tabs clearfix">
<li<?=($current == 'index' ? ' class="current"' : '')?>><a href="<?php $options->adminUrl('extending.php?panel=' . CommentNotifier_Plugin::$panel . '&act=index'); ?>">
<?php _e('模板列表'); ?>
</a></li>
<li<?=($current == 'theme' ? ' class="current"' : '')?>><a href="<?php $options->adminUrl('extending.php?panel=' . CommentNotifier_Plugin::$panel . '&act=theme'); ?>">
<?php _e('编辑邮件模板'); ?>
</a></li>
<li><a href="<?php $options->adminUrl('options-plugin.php?config=CommentNotifier') ?>"><?php _e('插件设置'); ?></a></li>
</ul>
</div>
<?php if ($current == 'index'): ?>
<?php include(dirname(__FILE__).'/themes.php'); ?>
<?php else: ?>
<?php
Widget::widget('CommentNotifier_Console')->to($files);
?>
<div class="typecho-edit-theme">
<div class="col-mb-12 col-tb-8 col-9 content">
<form method="post" name="theme" id="theme" action="<?php $options->adminUrl('extending.php?panel=' . CommentNotifier_Plugin::$panel . '&act=theme' . '&file=' . $files->file); ?>">
<label for="content" class="sr-only"><?php _e('编辑源码'); ?></label>
<textarea name="content" id="content" class="w-100 mono" <?php if(!$files->currentIsWriteable()): ?>readonly<?php endif; ?>><?php echo $files->currentContent(); ?></textarea>
<p class="submit">
<?php if($files->currentIsWriteable()): ?>
<input type="hidden" name="do" value="editTheme" />
<input type="hidden" name="edit" value="<?php echo $files->currentFile(); ?>" />
<button type="submit" class="btn primary"><?php _e('保存文件'); ?></button>
<?php else: ?>
<em><?php _e('此文件无法写入'); ?></em>
<?php endif; ?>
</p>
</form>
</div>
<ul class="col-mb-12 col-tb-4 col-3">
<li><strong>模板文件</strong></li>
<?php while($files->next()): ?>
<li<?php if($files->current): ?> class="current"<?php endif; ?>>
<a href="<?php $options->adminUrl('extending.php?panel=' . CommentNotifier_Plugin::$panel . '&act=theme' . '&file=' . $files->file); ?>"><?php $files->file(); ?></a></li>
<?php endwhile; ?>
<li><strong>参数说明</strong></li>
<li>文章标题:{title}</li>
<li>评论发出时间:{time}</li>
<li>评论内容:{commentText}</li>
<li>评论人昵称:{author}</li>
<li>评论者邮箱:{mail}</li>
<li>评论楼层链接:{permalink}</li><?php if($request->file=='guest.html'): ?>
<li>父评论昵称:{Pname}</li>
<li>父评论内容:{Ptext}</li>
<li>父评论邮箱:{Pmail}</li><?php endif; ?>
<li>网站地址:{siteUrl}</li>
<li>网站标题:{siteTitle}</li>
<li>当前模板文件夹路径:{url}</li>
<li><strong>文件说明</strong></li>
<li>notice.html:待审核评论通知模板</li>
<li>owner.html:文章作者邮件提醒模板</li>
<li>guest:游客评论回复提醒模板</li>
</ul>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php
include 'copyright.php';
include 'common-js.php';
include 'footer.php';
?>