国内流行的内容管理系统(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.

283 lines
8.6KB

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