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

112 lines
3.8KB

  1. <?php
  2. /**
  3. * 文档随机模板
  4. *
  5. * @version $id:article_template_rand.php 14:31 2010年7月12日 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. require_once(DEDEINC.'/libraries/oxwindow.class.php');
  13. CheckPurview('sys_StringMix');
  14. if (empty($dopost)) $dopost = '';
  15. $templates = empty($templates) ? '' : stripslashes($templates);
  16. $m_file = DEDEDATA.'/template.rand.php';
  17. $okmsg = '';
  18. //保存配置
  19. if ($dopost == 'save') {
  20. CheckCSRF();
  21. $fp = fopen($m_file, 'w');
  22. flock($fp, 3);
  23. fwrite($fp, $templates);
  24. fclose($fp);
  25. $okmsg = '成功保存配置信息 AT:('.MyDate('H:i:s', time()).')';
  26. }
  27. //对旧文档进行随机模板处理
  28. else if ($dopost == 'makeold') {
  29. CheckCSRF();
  30. set_time_limit(3600);
  31. if (!file_exists($m_file)) {
  32. AjaxHead();
  33. echo "配置文件不存在";
  34. exit();
  35. }
  36. require_once($m_file);
  37. if ($cfg_tamplate_rand == 0) {
  38. AjaxHead();
  39. echo "系统没开启允许随机模板的选项";
  40. exit();
  41. }
  42. $totalTmp = count($cfg_tamplate_arr) - 1;
  43. if ($totalTmp < 1) {
  44. AjaxHead();
  45. echo "随机模板的数量必须为2个或以上";
  46. exit();
  47. }
  48. for ($i = 0; $i < 10; $i++) {
  49. $temp = $cfg_tamplate_arr[mt_rand(0, $totalTmp)];
  50. $dsql->ExecuteNoneQuery("UPDATE `#@__addonarticle` SET templet='$temp' where RIGHT(aid, 1)='$i' ");
  51. }
  52. AjaxHead();
  53. echo "全部随机操作成功";
  54. exit();
  55. }
  56. //清除全部的指定模板
  57. else if ($dopost == 'clearold') {
  58. CheckCSRF();
  59. $dsql->ExecuteNoneQuery("UPDATE `#@__addonarticle` SET templet='' ");
  60. $dsql->ExecuteNoneQuery(" OPTIMIZE TABLE `#@__addonarticle` ");
  61. AjaxHead();
  62. echo "全部清除操作成功";
  63. exit();
  64. }
  65. //读出
  66. if (empty($templates) && filesize($m_file) > 0) {
  67. $fp = fopen($m_file, 'r');
  68. $templates = fread($fp, filesize($m_file));
  69. fclose($fp);
  70. }
  71. $wintitle = "随机模板设置";
  72. $wecome_info = "随机模板设置";
  73. make_hash();
  74. $msg = "
  75. <link rel='stylesheet' href='../static/web/css/admin.css'>
  76. <script src='../static/web/js/webajax.js'></script>
  77. <script src='js/main.js'></script>
  78. <script>
  79. function DoRand(jobname)
  80. {
  81. ChangeFullDiv('show');
  82. \$DE('loading').style.display = 'block';
  83. fetch('article_template_rand.php?dopost='+jobname+'&token={$_SESSION['token']}').then(resp=>resp.text()).then((d)=>{
  84. \$DE('tmpct').innerHTML = d;
  85. \$DE('loading').style.display = 'none';
  86. ChangeFullDiv('hide');
  87. });
  88. }
  89. </script>
  90. <div id='loaddiv' class='text-center py-2' style='display:none'><img src='../static/web/img/loadinglit.gif'></div>
  91. <table width='100%' align='center'>
  92. <tr>
  93. <td>
  94. 如果您想对旧的文档应用随机模板设置,请点击此对旧文档进行处理(必须设置好模板项)
  95. <a href='javascript:;' onclick='DoRand(\"makeold\")' class='btn btn-success btn-sm'>设置全部</a>
  96. <a href='javascript:;' onclick='DoRand(\"clearold\")' class='btn btn-success btn-sm'>取消全部</a>
  97. <span id='tmpct'>$okmsg</span>
  98. </td>
  99. </tr>
  100. <tr>
  101. <td><textarea name='templates' id='templates' class='admin-textarea-xl'>$templates</textarea></td>
  102. </tr>
  103. </table>";
  104. $win = new OxWindow();
  105. $win->Init('article_template_rand.php', 'js/blank.js', 'POST');
  106. $win->AddHidden('dopost', 'save');
  107. $win->AddHidden('token', $_SESSION['token']);
  108. $win->AddTitle("<div class='alert alert-info mb-0'>本设置仅适用于系统默认的文档模型,设置后发布文档时会自动按指定的模板随机获取一个,如果不想使用此功能,把它设置为空即可</div");
  109. $win->AddMsgItem($msg);
  110. $winform = $win->GetWindow('ok');
  111. $win->Display();
  112. ?>