国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

215 行
7.7KB

  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. $wecome_info = "<a href='templets_main.php'>模板管理</a> - 上传模板";
  113. $win->AddTitle('请选择要上传的模块文件');
  114. $win->AddHidden("action", 'uploadok');
  115. $msg = "<tr>
  116. <td width='260'>选择文件:</td>
  117. <td>
  118. <input name='acdir' type='hidden' value='$acdir'>
  119. <input name='token' type='hidden' value='{$_SESSION['token']}'>
  120. <input name='upfile' type='file' id='upfile' class='admin-input-lg'>
  121. </td>
  122. </tr>";
  123. $win->AddMsgItem("$msg");
  124. $winform = $win->GetWindow('ok', '');
  125. $win->Display();
  126. exit();
  127. }
  128. //上传新模板
  129. else if ($action == 'uploadok') {
  130. CheckCSRF();
  131. if (!is_uploaded_file($upfile)) {
  132. ShowMsg("请选择上传的模板文件", "javascript:;");
  133. exit();
  134. } else {
  135. if (!preg_match("#\.(htm|html)$#", $upfile_name)) {
  136. ShowMsg("模板只能用.htm或.html扩展名", "-1");
  137. exit();
  138. }
  139. if (preg_match("#[\\\\\/]#", $upfile_name)) {
  140. ShowMsg("模板文件名有非法字符,禁止上传", "-1");
  141. exit();
  142. }
  143. move_uploaded_file($upfile, $templetdird.'/'.$upfile_name);
  144. @unlink($upfile);
  145. ShowMsg("成功上传一个模板", "templets_main.php?acdir=$acdir");
  146. exit();
  147. }
  148. exit();
  149. }
  150. //修改标签碎片
  151. else if ($action == 'edittag' || $action == 'addnewtag') {
  152. if ($action == 'addnewtag') {
  153. $democode = '<'."?php
  154. if (!defined('DEDEINC')) {
  155. exit(\"Request Error!\");
  156. }
  157. function lib_demotag(\$ctag, \$refObj)
  158. {
  159. global \$dsql, \$envs;
  160. //属性处理
  161. \$attlist = \"row|12,titlelen|30\";
  162. FillAttsDefault(\$ctag->CAttribute->Items,\$attlist);
  163. extract(\$ctag->CAttribute->Items, EXTR_SKIP);
  164. \$revalue = '';
  165. //您需编写的代码,不能用echo之类语法,把最终返回值传给\$revalue
  166. \$revalue = 'Hello Word!';
  167. return \$revalue;
  168. }
  169. ?".'>';
  170. $filename = "demotag.lib.php";
  171. $title = "新建标签";
  172. } else {
  173. if (!preg_match("#^[a-z0-9_-]{1,}\.lib\.php$#i", $filename)) {
  174. ShowMsg('文件不是标准的标签碎片文件,不允许在此修改', '-1');
  175. exit();
  176. }
  177. $fp = fopen(DEDEINC.'/taglib/'.$filename, 'r');
  178. $democode = fread($fp, filesize(DEDEINC.'/taglib/'.$filename));
  179. fclose($fp);
  180. $title = "修改标签";
  181. }
  182. make_hash();
  183. include DEDEADMIN.'/templets/tpl_edit_tag.htm';
  184. exit();
  185. }
  186. //保存标签碎片修改
  187. else if ($action == 'savetagfile') {
  188. CheckCSRF();
  189. if (!preg_match("#^[a-z0-9_-]{1,}\.lib\.php$#i", $filename)) {
  190. ShowMsg('文件名不合法,不允许进行操作', '-1');
  191. exit();
  192. }
  193. require_once(DEDEINC.'/libraries/oxwindow.class.php');
  194. $tagname = preg_replace("#\.lib\.php$#i", "", $filename);
  195. $content = stripslashes($content);
  196. $truefile = DEDEINC.'/taglib/'.$filename;
  197. $fp = fopen($truefile, 'w');
  198. fwrite($fp, $content);
  199. fclose($fp);
  200. $msg = "<form name='form1' action='tag_test_action.php' target='blank' method='post'>
  201. <div class='mb-3'><label><input type='hidden' name='dopost' value='make'> 标签测试(环境变量标签不支持测试)</label></div>
  202. <div class='mb-3'><textarea name='partcode' cols='150' rows='6' class='admin-textarea-xl'>{dede:{$tagname}}{/dede:{$tagname}}</textarea></div>
  203. <div class='text-center'><button type='submit' name='B1' class='btn btn-success btn-sm'>确定</button></div>
  204. </form>";
  205. $wintitle = "成功操作文件";
  206. $wecome_info = "<a href='templets_tagsource.php'>标签源码管理</a> - 新建修改标签";
  207. $win = new OxWindow();
  208. $win->AddTitle("新建修改标签");
  209. $win->AddMsgItem($msg);
  210. $winform = $win->GetWindow("hand", false);
  211. $win->Display();
  212. exit();
  213. }
  214. ?>