tpl.php
8.35 KB
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?php
/**
* 文件管理器
*
* @version $Id: tpl.php 1 23:44 2010年7月20日Z tianya $
* @package DedeCMS.Administrator
* @copyright Copyright (c) 2007 - 2010, DesDev, Inc.
* @license http://help.dedecms.com/usersguide/license.html
* @link http://www.dedecms.com
*/
require_once(dirname(__FILE__)."/config.php");
CheckPurview('plus_文件管理器');
$action = isset($action) ? trim($action) : '';
if(empty($acdir)) $acdir = $cfg_df_style;
$templetdir = $cfg_basedir.$cfg_templets_dir;
$templetdird = $templetdir.'/'.$acdir;
$templeturld = $cfg_templeturl.'/'.$acdir;
if(empty($filename)) $filename = '';
$filename = preg_replace("#[\/\\\\]#", '', $filename);
if(preg_match("#\.#", $acdir))
{
ShowMsg('Not Allow dir '.$acdir.'!','-1');
exit();
}
/*
function edit_new_tpl() { }
编辑模板
*/
if($action == 'edit' || $action == 'newfile')
{
if($filename == '' && $action == 'edit')
{
ShowMsg('未指定要编辑的文件', '-1');
exit();
}
if(!file_exists($templetdird.'/'.$filename) && $action == 'edit')
{
$action = 'newfile';
}
//读取文件内容
//$content = htmlspecialchars(trim(file_get_contents($truePath.$filename)));
if($action == 'edit')
{
$fp = fopen($templetdird.'/'.$filename, 'r');
$content = fread($fp, filesize($templetdird.'/'.$filename));
fclose($fp);
$content = preg_replace("#<textarea#i", "##textarea", $content);
$content = preg_replace("#</textarea#i", "##/textarea", $content);
$content = preg_replace("#<form#i", "##form", $content);
$content = preg_replace("#</form#i", "##/form", $content);
}
else
{
if(empty($filename)) $filename = 'newtpl.htm';
$content = '';
}
//获取标签帮助信息
$helps = $dtags = array();
$tagHelpDir = DEDEINC.'/taglib/help/';
$dir = dir($tagHelpDir);
while(false !== ($entry = $dir->read()))
{
if($entry != '.' && $entry != '..' && !is_dir($tagHelpDir.$entry))
{
$dtags[] = str_replace('.txt', '', $entry);
}
}
$dir->close();
foreach($dtags as $tag)
{
//$helpContent = file_get_contents($tagHelpDir.$tag.'.txt');
$fp = fopen($tagHelpDir.$tag.'.txt','r');
$helpContent = fread($fp,filesize($tagHelpDir.$tag.'.txt'));
fclose($fp);
$helps[$tag] = explode('>>dede>>', $helpContent);
}
include DEDEADMIN.'/templets/tpl_edit.htm';
exit();
}
/*---------------------------
function save_tpl() { }
保存编辑模板
--------------------------*/
else if($action == 'saveedit')
{
if($filename == '')
{
ShowMsg('未指定要编辑的文件或文件名不合法', '-1');
exit();
}
if(!preg_match("#\.htm$#", $filename))
{
ShowMsg('DEDE模板文件,文件名必须用.htm结尾!', '-1');
exit();
}
$content = stripslashes($content);
$content = preg_replace("/##textarea/i", "<textarea", $content);
$content = preg_replace("/##\/textarea/i", "</textarea", $content);
$content = preg_replace("/##form/i", "<form", $content);
$content = preg_replace("/##\/form/i", "</form", $content);
$truefile = $templetdird.'/'.$filename;
$fp = fopen($truefile, 'w');
fwrite($fp, $content);
fclose($fp);
ShowMsg('成功修改或新建文件', 'templets_main.php?acdir='.$acdir);
exit();
}
/*---------------------------
function del_tpl() { }
删除模板
--------------------------*/
else if ($action == 'del')
{
$truefile = $templetdird.'/'.$filename;
if(unlink($truefile))
{
ShowMsg('删除文件成功','templets_main.php?acdir='.$acdir);
exit();
}
else
{
ShowMsg('删除文件失败','-1');
exit();
}
}
/*----------------------
function _upload() {}
上传新模板
-----------------------*/
else if ($action == 'upload')
{
require_once(dirname(__FILE__).'/../include/oxwindow.class.php');
$acdir = str_replace('.', '', $acdir);
$win = new OxWindow();
$win->Init("tpl.php","js/blank.js","POST' enctype='multipart/form-data' ");
$win->mainTitle = "模块管理";
$wecome_info = "<a href='templets_main.php'>模板管理</a> >> 上传模板";
$win->AddTitle('请选择要上传的文件:');
$win->AddHidden("action",'uploadok');
$msg = "
<table width='600' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='96' height='60'>请选择文件:</td>
<td width='504'>
<input name='acdir' type='hidden' value='$acdir' />
<input name='upfile' type='file' id='upfile' style='width:380px' />
</td>
</tr>
</table>
";
$win->AddMsgItem("<div style='padding-left:20px;line-height:150%'>$msg</div>");
$winform = $win->GetWindow('ok','');
$win->Display();
exit();
}
/*----------------------
function _upload() {}
上传新模板
-----------------------*/
else if ($action == 'uploadok')
{
if( !is_uploaded_file($upfile) )
{
ShowMsg("貌似你什么都没有上传哦!","javascript:;");
exit();
}
else
{
if( !preg_match("#\.(htm|html)$#", $upfile_name) )
{
ShowMsg("DedeCMS模板只能用 .htm 或 .html扩展名!", "-1");
exit();
}
if( preg_match("#[\\\\\/]#", $upfile_name) )
{
ShowMsg("模板文件名有非法字符,禁止上传!", "-1");
exit();
}
move_uploaded_file($upfile, $templetdird.'/'.$upfile_name);
@unlink($upfile);
ShowMsg("成功上传一个模板!","templets_main.php?acdir=$acdir");
exit();
}
exit();
}
/*---------------------------
function edittag() { }
修改标签碎片
--------------------------*/
else if($action=='edittag' || $action=='addnewtag')
{
if($action=='addnewtag')
{
$democode = '<'."?php
if(!defined('DEDEINC'))
{
exit(\"Request Error!\");
}
function lib_demotag(&\$ctag,&\$refObj)
{
global \$dsql,\$envs;
//属性处理
\$attlist=\"row|12,titlelen|24\";
FillAttsDefault(\$ctag->CAttribute->Items,\$attlist);
extract(\$ctag->CAttribute->Items, EXTR_SKIP);
\$revalue = '';
//你需编写的代码,不能用echo之类语法,把最终返回值传给\$revalue
//------------------------------------------------------
\$revalue = 'Hello Word!';
//------------------------------------------------------
return \$revalue;
}
?".'>';
$filename = "demotag.lib.php";
$title = "新建标签";
}
else
{
if(!preg_match("#^[a-z0-9_-]{1,}\.lib\.php$#i", $filename))
{
ShowMsg('文件不是标准的标签碎片文件,不允许在此编辑!','-1');
exit();
}
$fp = fopen(DEDEINC.'/taglib/'.$filename,'r');
$democode = fread($fp, filesize(DEDEINC.'/taglib/'.$filename));
fclose($fp);
$title = "修改标签";
}
include DEDEADMIN.'/templets/tpl_edit_tag.htm';
exit();
}
/*---------------------------
function savetagfile() { }
保存标签碎片修改
--------------------------*/
else if($action=='savetagfile')
{
if(!preg_match("#^[a-z0-9_-]{1,}\.lib\.php$#i", $filename))
{
ShowMsg('文件名不合法,不允许进行操作!', '-1');
exit();
}
require_once(DEDEINC.'/oxwindow.class.php');
$tagname = preg_replace("#\.lib\.php$#i", "", $filename);
$content = stripslashes($content);
$truefile = DEDEINC.'/taglib/'.$filename;
$fp = fopen($truefile, 'w');
fwrite($fp, $content);
fclose($fp);
$msg = "
<form name='form1' action='tag_test_action.php' target='blank' method='post'>
<input type='hidden' name='dopost' value='make' />
<b>测试标签:</b>(需要使用环境变量的不能在此测试)<br/>
<textarea name='partcode' cols='150' rows='6' style='width:90%;'>{dede:{$tagname} }{/dede:{$tagname}}</textarea><br />
<input name='imageField1' type='image' class='np' src='images/button_ok.gif' width='60' height='22' border='0' />
</form>
";
$wintitle = "成功修改/创建文件!";
$wecome_info = "<a href='templets_tagsource.php'>标签源码碎片管理</a> >> 修改/新建标签";
$win = new OxWindow();
$win->AddTitle("修改/新建标签:");
$win->AddMsgItem($msg);
$winform = $win->GetWindow("hand"," ",false);
$win->Display();
exit();
}