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

218 lines
7.8KB

  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. if ($action == 'edit' || $action == 'newfile') {
  29. if ($filename == '' && $action == 'edit') {
  30. ShowMsg('未指定要修改的模板', '-1');
  31. exit();
  32. }
  33. if (!file_exists($templetdird.'/'.$filename) && $action == 'edit') {
  34. $action = 'newfile';
  35. }
  36. //读取文件文档
  37. //$content = dede_htmlspecialchars(trim(file_get_contents($truePath.$filename)));
  38. if ($action == 'edit') {
  39. $fp = fopen($templetdird.'/'.$filename, 'r');
  40. $content = fread($fp, filesize($templetdird.'/'.$filename));
  41. fclose($fp);
  42. $content = preg_replace("#<textarea#i", "##textarea", $content);
  43. $content = preg_replace("#</textarea#i", "##/textarea", $content);
  44. $content = preg_replace("#<form#i", "##form", $content);
  45. $content = preg_replace("#</form#i", "##/form", $content);
  46. } else {
  47. if (empty($filename)) $filename = 'newtpl.htm';
  48. $content = '';
  49. }
  50. //获取标签帮助信息
  51. $helps = $dtags = array();
  52. $tagHelpDir = DEDEINC.'/taglib/help/';
  53. $dir = dir($tagHelpDir);
  54. while (false !== ($entry = $dir->read())) {
  55. if ($entry != '.' && $entry != '..' && !is_dir($tagHelpDir.$entry)) {
  56. $dtags[] = str_replace('.txt', '', $entry);
  57. }
  58. }
  59. $dir->close();
  60. foreach ($dtags as $tag) {
  61. //$helpContent = file_get_contents($tagHelpDir.$tag.'.txt');
  62. $fp = fopen($tagHelpDir.$tag.'.txt', 'r');
  63. $helpContent = fread($fp, filesize($tagHelpDir.$tag.'.txt'));
  64. fclose($fp);
  65. $helps[$tag] = explode('>>dede>>', $helpContent);
  66. }
  67. make_hash();
  68. include DEDEADMIN.'/templets/tpl_edit.htm';
  69. exit();
  70. }
  71. //保存修改模板
  72. else if ($action == 'saveedit') {
  73. CheckCSRF();
  74. if ($filename == '') {
  75. ShowMsg('未指定要修改的文件或文件名不合法', '-1');
  76. exit();
  77. }
  78. if (!preg_match("#\.htm$#", $filename)) {
  79. ShowMsg('模板只能用.htm扩展名', '-1');
  80. exit();
  81. }
  82. $content = stripslashes($content);
  83. $content = preg_replace("/##textarea/i", "<textarea", $content);
  84. $content = preg_replace("/##\/textarea/i", "</textarea", $content);
  85. $content = preg_replace("/##form/i", "<form", $content);
  86. $content = preg_replace("/##\/form/i", "</form", $content);
  87. $truefile = $templetdird.'/'.$filename;
  88. $fp = fopen($truefile, 'w');
  89. fwrite($fp, $content);
  90. fclose($fp);
  91. ShowMsg('修改或新建模板成功', 'templets_main.php?acdir='.$acdir);
  92. exit();
  93. }
  94. //删除模板
  95. else if ($action == 'del') {
  96. $truefile = $templetdird.'/'.$filename;
  97. if (unlink($truefile)) {
  98. ShowMsg('删除模板成功', 'templets_main.php?acdir='.$acdir);
  99. exit();
  100. } else {
  101. ShowMsg('删除模板失败', '-1');
  102. exit();
  103. }
  104. }
  105. //上传新模板
  106. else if ($action == 'upload') {
  107. require_once(DEDEINC.'/libraries/oxwindow.class.php');
  108. $acdir = str_replace('.', '', $acdir);
  109. $win = new OxWindow();
  110. make_hash();
  111. $win->Init("tpl.php", "js/blank.js", "POST' enctype='multipart/form-data' ");
  112. $win->mainTitle = "模块管理";
  113. $wecome_info = "<a href='templets_main.php'>模板管理</a> - 上传模板";
  114. $win->AddTitle('请选择要上传的模块文件');
  115. $win->AddHidden("action", 'uploadok');
  116. $msg = "<table>
  117. <tr>
  118. <td width='90'>选择文件:</td>
  119. <td>
  120. <input name='acdir' type='hidden' value='$acdir'>
  121. <input name='token' type='hidden' value='{$_SESSION['token']}'>
  122. <input name='upfile' type='file' id='upfile' class='admin-input-lg'>
  123. </td>
  124. </tr>
  125. </table>";
  126. $win->AddMsgItem("$msg");
  127. $winform = $win->GetWindow('ok', '');
  128. $win->Display();
  129. exit();
  130. }
  131. //上传新模板
  132. else if ($action == 'uploadok') {
  133. CheckCSRF();
  134. if (!is_uploaded_file($upfile)) {
  135. ShowMsg("请选择上传的模板文件", "javascript:;");
  136. exit();
  137. } else {
  138. if (!preg_match("#\.(htm|html)$#", $upfile_name)) {
  139. ShowMsg("模板只能用.htm或.html扩展名", "-1");
  140. exit();
  141. }
  142. if (preg_match("#[\\\\\/]#", $upfile_name)) {
  143. ShowMsg("模板文件名有非法字符,禁止上传", "-1");
  144. exit();
  145. }
  146. move_uploaded_file($upfile, $templetdird.'/'.$upfile_name);
  147. @unlink($upfile);
  148. ShowMsg("成功上传一个模板", "templets_main.php?acdir=$acdir");
  149. exit();
  150. }
  151. exit();
  152. }
  153. //修改标签碎片
  154. else if ($action == 'edittag' || $action == 'addnewtag') {
  155. if ($action == 'addnewtag') {
  156. $democode = '<'."?php
  157. if (!defined('DEDEINC')) {
  158. exit(\"Request Error!\");
  159. }
  160. function lib_demotag(\$ctag, \$refObj)
  161. {
  162. global \$dsql, \$envs;
  163. //属性处理
  164. \$attlist = \"row|12,titlelen|30\";
  165. FillAttsDefault(\$ctag->CAttribute->Items,\$attlist);
  166. extract(\$ctag->CAttribute->Items, EXTR_SKIP);
  167. \$revalue = '';
  168. //您需编写的代码,不能用echo之类语法,把最终返回值传给\$revalue
  169. \$revalue = 'Hello Word!';
  170. return \$revalue;
  171. }
  172. ?".'>';
  173. $filename = "demotag.lib.php";
  174. $title = "新建标签";
  175. } else {
  176. if (!preg_match("#^[a-z0-9_-]{1,}\.lib\.php$#i", $filename)) {
  177. ShowMsg('文件不是标准的标签碎片文件,不允许在此修改', '-1');
  178. exit();
  179. }
  180. $fp = fopen(DEDEINC.'/taglib/'.$filename, 'r');
  181. $democode = fread($fp, filesize(DEDEINC.'/taglib/'.$filename));
  182. fclose($fp);
  183. $title = "修改标签";
  184. }
  185. make_hash();
  186. include DEDEADMIN.'/templets/tpl_edit_tag.htm';
  187. exit();
  188. }
  189. //保存标签碎片修改
  190. else if ($action == 'savetagfile') {
  191. CheckCSRF();
  192. if (!preg_match("#^[a-z0-9_-]{1,}\.lib\.php$#i", $filename)) {
  193. ShowMsg('文件名不合法,不允许进行操作', '-1');
  194. exit();
  195. }
  196. require_once(DEDEINC.'/libraries/oxwindow.class.php');
  197. $tagname = preg_replace("#\.lib\.php$#i", "", $filename);
  198. $content = stripslashes($content);
  199. $truefile = DEDEINC.'/taglib/'.$filename;
  200. $fp = fopen($truefile, 'w');
  201. fwrite($fp, $content);
  202. fclose($fp);
  203. $msg = "<form name='form1' action='tag_test_action.php' target='blank' method='post'>
  204. <div class='mb-3'><label><input type='hidden' name='dopost' value='make'> 标签测试(环境变量标签不支持测试)</label></div>
  205. <div class='mb-3'><textarea name='partcode' cols='150' rows='6' class='admin-textarea-xl'>{dede:{$tagname}}{/dede:{$tagname}}</textarea></div>
  206. <div class='text-center'><button type='submit' name='B1' class='btn btn-success btn-sm'>确定</button></div>
  207. </form>";
  208. $wintitle = "成功操作文件";
  209. $wecome_info = "<a href='templets_tagsource.php'>标签源码管理</a> - 新建修改标签";
  210. $win = new OxWindow();
  211. $win->AddTitle("新建修改标签");
  212. $win->AddMsgItem($msg);
  213. $winform = $win->GetWindow("hand", false);
  214. $win->Display();
  215. exit();
  216. }
  217. ?>