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

245 lines
8.2KB

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