国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
8.5KB

  1. <?php
  2. /**
  3. * 文件管理器
  4. *
  5. * @version $Id: tpl.php 1 23:44 2010年7月20日Z tianya $
  6. * @package DedeCMS.Administrator
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(dirname(__FILE__)."/config.php");
  12. CheckPurview('plus_文件管理器');
  13. $action = isset($action) ? trim($action) : '';
  14. if(empty($acdir)) $acdir = $cfg_df_style;
  15. $templetdir = $cfg_basedir.$cfg_templets_dir;
  16. $templetdird = $templetdir.'/'.$acdir;
  17. $templeturld = $cfg_templeturl.'/'.$acdir;
  18. if(empty($filename)) $filename = '';
  19. $filename = preg_replace("#[\/\\\\]#", '', $filename);
  20. if(preg_match("#\.#", $acdir))
  21. {
  22. ShowMsg('Not Allow dir '.$acdir.'!','-1');
  23. exit();
  24. }
  25. /*
  26. function edit_new_tpl() { }
  27. 编辑模板
  28. */
  29. if($action == 'edit' || $action == 'newfile')
  30. {
  31. if($filename == '' && $action == 'edit')
  32. {
  33. ShowMsg('未指定要编辑的文件', '-1');
  34. exit();
  35. }
  36. if(!file_exists($templetdird.'/'.$filename) && $action == 'edit')
  37. {
  38. $action = 'newfile';
  39. }
  40. //读取文件内容
  41. //$content = dede_htmlspecialchars(trim(file_get_contents($truePath.$filename)));
  42. if($action == 'edit')
  43. {
  44. $fp = fopen($templetdird.'/'.$filename, 'r');
  45. $content = fread($fp, filesize($templetdird.'/'.$filename));
  46. fclose($fp);
  47. $content = preg_replace("#<textarea#i", "##textarea", $content);
  48. $content = preg_replace("#</textarea#i", "##/textarea", $content);
  49. $content = preg_replace("#<form#i", "##form", $content);
  50. $content = preg_replace("#</form#i", "##/form", $content);
  51. }
  52. else
  53. {
  54. if(empty($filename)) $filename = 'newtpl.htm';
  55. $content = '';
  56. }
  57. //获取标签帮助信息
  58. $helps = $dtags = array();
  59. $tagHelpDir = DEDEINC.'/taglib/help/';
  60. $dir = dir($tagHelpDir);
  61. while(false !== ($entry = $dir->read()))
  62. {
  63. if($entry != '.' && $entry != '..' && !is_dir($tagHelpDir.$entry))
  64. {
  65. $dtags[] = str_replace('.txt', '', $entry);
  66. }
  67. }
  68. $dir->close();
  69. foreach($dtags as $tag)
  70. {
  71. //$helpContent = file_get_contents($tagHelpDir.$tag.'.txt');
  72. $fp = fopen($tagHelpDir.$tag.'.txt','r');
  73. $helpContent = fread($fp,filesize($tagHelpDir.$tag.'.txt'));
  74. fclose($fp);
  75. $helps[$tag] = explode('>>dede>>', $helpContent);
  76. }
  77. make_hash();
  78. include DEDEADMIN.'/templets/tpl_edit.htm';
  79. exit();
  80. }
  81. /*---------------------------
  82. function save_tpl() { }
  83. 保存编辑模板
  84. --------------------------*/
  85. else if($action == 'saveedit')
  86. {
  87. CheckCSRF();
  88. if($filename == '')
  89. {
  90. ShowMsg('未指定要编辑的文件或文件名不合法', '-1');
  91. exit();
  92. }
  93. if(!preg_match("#\.htm$#", $filename))
  94. {
  95. ShowMsg('DEDE模板文件,文件名必须用.htm结尾!', '-1');
  96. exit();
  97. }
  98. $content = stripslashes($content);
  99. $content = preg_replace("/##textarea/i", "<textarea", $content);
  100. $content = preg_replace("/##\/textarea/i", "</textarea", $content);
  101. $content = preg_replace("/##form/i", "<form", $content);
  102. $content = preg_replace("/##\/form/i", "</form", $content);
  103. $truefile = $templetdird.'/'.$filename;
  104. $fp = fopen($truefile, 'w');
  105. fwrite($fp, $content);
  106. fclose($fp);
  107. ShowMsg('成功修改或新建文件', 'templets_main.php?acdir='.$acdir);
  108. exit();
  109. }
  110. /*---------------------------
  111. function del_tpl() { }
  112. 删除模板
  113. --------------------------*/
  114. else if ($action == 'del')
  115. {
  116. $truefile = $templetdird.'/'.$filename;
  117. if(unlink($truefile))
  118. {
  119. ShowMsg('删除文件成功','templets_main.php?acdir='.$acdir);
  120. exit();
  121. }
  122. else
  123. {
  124. ShowMsg('删除文件失败','-1');
  125. exit();
  126. }
  127. }
  128. /*----------------------
  129. function _upload() {}
  130. 上传新模板
  131. -----------------------*/
  132. else if ($action == 'upload')
  133. {
  134. require_once(dirname(__FILE__).'/../include/oxwindow.class.php');
  135. $acdir = str_replace('.', '', $acdir);
  136. $win = new OxWindow();
  137. make_hash();
  138. $win->Init("tpl.php","js/blank.js","POST' enctype='multipart/form-data' ");
  139. $win->mainTitle = "模块管理";
  140. $wecome_info = "<a href='templets_main.php'>模板管理</a> &gt;&gt; 上传模板";
  141. $win->AddTitle('请选择要上传的文件:');
  142. $win->AddHidden("action",'uploadok');
  143. $msg = "
  144. <table width='600' border='0' cellspacing='0' cellpadding='0'>
  145. <tr>
  146. <td width='96' height='60'>请选择文件:</td>
  147. <td width='504'>
  148. <input name='acdir' type='hidden' value='$acdir' />
  149. <input name='token' type='hidden' value='{$_SESSION['token']}' />
  150. <input name='upfile' type='file' id='upfile' style='width:380px' />
  151. </td>
  152. </tr>
  153. </table>
  154. ";
  155. $win->AddMsgItem("<div style='padding-left:20px;line-height:150%'>$msg</div>");
  156. $winform = $win->GetWindow('ok','');
  157. $win->Display();
  158. exit();
  159. }
  160. /*----------------------
  161. function _upload() {}
  162. 上传新模板
  163. -----------------------*/
  164. else if ($action == 'uploadok')
  165. {
  166. CheckCSRF();
  167. if( !is_uploaded_file($upfile) )
  168. {
  169. ShowMsg("貌似你什么都没有上传哦!","javascript:;");
  170. exit();
  171. }
  172. else
  173. {
  174. if( !preg_match("#\.(htm|html)$#", $upfile_name) )
  175. {
  176. ShowMsg("DedeCMS模板只能用 .htm 或 .html扩展名!", "-1");
  177. exit();
  178. }
  179. if( preg_match("#[\\\\\/]#", $upfile_name) )
  180. {
  181. ShowMsg("模板文件名有非法字符,禁止上传!", "-1");
  182. exit();
  183. }
  184. move_uploaded_file($upfile, $templetdird.'/'.$upfile_name);
  185. @unlink($upfile);
  186. ShowMsg("成功上传一个模板!","templets_main.php?acdir=$acdir");
  187. exit();
  188. }
  189. exit();
  190. }
  191. /*---------------------------
  192. function edittag() { }
  193. 修改标签碎片
  194. --------------------------*/
  195. else if($action=='edittag' || $action=='addnewtag')
  196. {
  197. if($action=='addnewtag')
  198. {
  199. $democode = '<'."?php
  200. if(!defined('DEDEINC'))
  201. {
  202. exit(\"Request Error!\");
  203. }
  204. function lib_demotag(&\$ctag,&\$refObj)
  205. {
  206. global \$dsql,\$envs;
  207. //属性处理
  208. \$attlist=\"row|12,titlelen|24\";
  209. FillAttsDefault(\$ctag->CAttribute->Items,\$attlist);
  210. extract(\$ctag->CAttribute->Items, EXTR_SKIP);
  211. \$revalue = '';
  212. //你需编写的代码,不能用echo之类语法,把最终返回值传给\$revalue
  213. //------------------------------------------------------
  214. \$revalue = 'Hello Word!';
  215. //------------------------------------------------------
  216. return \$revalue;
  217. }
  218. ?".'>';
  219. $filename = "demotag.lib.php";
  220. $title = "新建标签";
  221. }
  222. else
  223. {
  224. if(!preg_match("#^[a-z0-9_-]{1,}\.lib\.php$#i", $filename))
  225. {
  226. ShowMsg('文件不是标准的标签碎片文件,不允许在此编辑!','-1');
  227. exit();
  228. }
  229. $fp = fopen(DEDEINC.'/taglib/'.$filename,'r');
  230. $democode = fread($fp, filesize(DEDEINC.'/taglib/'.$filename));
  231. fclose($fp);
  232. $title = "修改标签";
  233. }
  234. make_hash();
  235. include DEDEADMIN.'/templets/tpl_edit_tag.htm';
  236. exit();
  237. }
  238. /*---------------------------
  239. function savetagfile() { }
  240. 保存标签碎片修改
  241. --------------------------*/
  242. else if($action=='savetagfile')
  243. {
  244. CheckCSRF();
  245. if(!preg_match("#^[a-z0-9_-]{1,}\.lib\.php$#i", $filename))
  246. {
  247. ShowMsg('文件名不合法,不允许进行操作!', '-1');
  248. exit();
  249. }
  250. require_once(DEDEINC.'/oxwindow.class.php');
  251. $tagname = preg_replace("#\.lib\.php$#i", "", $filename);
  252. $content = stripslashes($content);
  253. $truefile = DEDEINC.'/taglib/'.$filename;
  254. $fp = fopen($truefile, 'w');
  255. fwrite($fp, $content);
  256. fclose($fp);
  257. $msg = "
  258. <form name='form1' action='tag_test_action.php' target='blank' method='post'>
  259. <input type='hidden' name='dopost' value='make' />
  260. <b>测试标签:</b>(需要使用环境变量的不能在此测试)<br/>
  261. <textarea name='partcode' cols='150' rows='6' style='width:90%;'>{dede:{$tagname} }{/dede:{$tagname}}</textarea><br />
  262. <input name='imageField1' type='image' class='np' src='images/button_ok.gif' width='60' height='22' border='0' />
  263. </form>
  264. ";
  265. $wintitle = "成功修改/创建文件!";
  266. $wecome_info = "<a href='templets_tagsource.php'>标签源码碎片管理</a> &gt;&gt; 修改/新建标签";
  267. $win = new OxWindow();
  268. $win->AddTitle("修改/新建标签:");
  269. $win->AddMsgItem($msg);
  270. $winform = $win->GetWindow("hand","&nbsp;",false);
  271. $win->Display();
  272. exit();
  273. }