event_template.inc.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * [超级活动(xj_event.{modulename})] (C)2012-2099 Powered by 逍遥工作室.
  4. * Version: 1.0
  5. * Date: 2012-9-15 10:27
  6. */
  7. if (!defined('IN_DISCUZ')) {
  8. exit('Access Denied');
  9. }
  10. if ($_GET['act'] == 'manage') {
  11. $tmp = explode("\n", $_G['cache']['plugin']['xj_event']['event_template']);
  12. $event_template = array();
  13. foreach($tmp as $key => $value) {
  14. $ctmp = array();
  15. $ctmp = explode("|", $value);
  16. $ctmp[0] = str_replace("\r", '', $ctmp[0]);
  17. $ctmp[1] = str_replace("\r", '', $ctmp[1]);
  18. $event_template[] = $ctmp;
  19. }
  20. include template('xj_event:event_template');
  21. } else if ($_GET['act'] == 'delete') {
  22. if($_GET['formhash'] != $_G['formhash']){
  23. showmessage('submit_invalid');
  24. }
  25. $tmp = explode("\n", $_G['cache']['plugin']['xj_event']['event_template']);
  26. $ctmp = explode("|", $tmp[intval($_GET['tpid'])]);
  27. $ctmp[0] = $_GET['tpname'];
  28. unset($tmp[intval($_GET['tpid'])]);
  29. $filename = "./source/plugin/xj_event/etpl/" . str_replace("\r", '', $ctmp[1]);
  30. if (unlink($filename)) {
  31. $_G['cache']['plugin']['xj_event']['event_template'] = implode('\n', $tmp);
  32. $pluginid = DB :: result_first("SELECT pluginid FROM " . DB :: table('common_plugin') . " where identifier='xj_event'");
  33. DB :: query("UPDATE " . DB :: table('common_pluginvar') . " SET value = '" . $_G['cache']['plugin']['xj_event']['event_template'] . "' WHERE pluginid = $pluginid and variable = 'event_template'");
  34. require_once libfile('function/cache');
  35. updatecache(array('plugin')); //更新缓存
  36. showmessage(lang('plugin/xj_event', 'mbsccg'),'plugin.php?id=xj_event:event_template&act=manage');
  37. }
  38. } else if ($_GET['act'] == 'add' or $_GET['act'] == 'edit') {
  39. if ($_GET['act'] == 'edit') { // 编辑模板时调用
  40. $tmp = explode("\n", $_G['cache']['plugin']['xj_event']['event_template']);
  41. $ctmp = explode("|", $tmp[intval($_GET['tpid'])]);
  42. $tpname = $ctmp[0];
  43. $filename = "./source/plugin/xj_event/etpl/" . str_replace("\r", '', $ctmp[1]);
  44. $tpcontent = file_get_contents($filename);
  45. }
  46. $discuz = &discuz_core :: instance();
  47. $discuz -> cachelist = $cachelist;
  48. $discuz -> init();
  49. $editorid = 'e';
  50. $_G['setting']['editoroptions'] = str_pad(decbin($_G['setting']['editoroptions']), 2, 0, STR_PAD_LEFT);
  51. $editormode = $_G['setting']['editoroptions'] {
  52. 0} ;
  53. $allowswitcheditor = $_G['setting']['editoroptions'] {
  54. 1} ;
  55. $editor = array('editormode' => $editormode,
  56. 'allowswitcheditor' => $allowswitcheditor,
  57. 'allowhtml' => 1,
  58. 'allowhtml' => 1,
  59. 'allowsmilies' => 1,
  60. 'allowbbcode' => 1,
  61. 'allowimgcode' => 2,
  62. 'allowcustombbcode' => 0,
  63. 'allowresize' => 1,
  64. 'textarea' => 'message',
  65. 'simplemode' => !isset($_G['cookie']['editormode_' . $editorid]) ? 1 : $_G['cookie']['editormode_' . $editorid],
  66. );
  67. loadcache('bbcodes_display');
  68. include template('xj_event:event_template');
  69. } else if ($_GET['act'] == 'editfull') {
  70. if(!submitcheck('etsubmit')){
  71. showmessage('submit_invalid');
  72. }
  73. $tmp = explode("\n", $_G['cache']['plugin']['xj_event']['event_template']);
  74. $ctmp = explode("|", $tmp[intval($_GET['tpid'])]);
  75. $ctmp[0] = $_GET['tpname'];
  76. $filename = str_replace("\r", '', $ctmp[1]);
  77. $filename = "./source/plugin/xj_event/etpl/" . $filename;
  78. $fp = fopen("$filename", "w+"); //打开文件指针,创建文件
  79. if (!is_writable($filename)) {
  80. showmessage(lang('plugin/xj_event', 'mbwjxrsbqjc'));;
  81. } else {
  82. $tmp[intval($_GET['tpid'])] = implode("|", $ctmp);
  83. $_G['cache']['plugin']['xj_event']['event_template'] = implode('\n', $tmp);
  84. $pluginid = DB :: result_first("SELECT pluginid FROM " . DB :: table('common_plugin') . " where identifier='xj_event'");
  85. DB :: query("UPDATE " . DB :: table('common_pluginvar') . " SET value = '" . $_G['cache']['plugin']['xj_event']['event_template'] . "' WHERE pluginid = $pluginid and variable = 'event_template'");
  86. require_once libfile('function/cache');
  87. updatecache(array('plugin')); //更新缓存
  88. fwrite($fp, $_GET['message']);
  89. fclose($fp); //关闭指针
  90. showmessage(lang('plugin/xj_event', 'mbxgcg'),'plugin.php?id=xj_event:event_template&act=manage');
  91. }
  92. } else if ($_GET['act'] == 'addfull') {
  93. if(!submitcheck('etsubmit')){
  94. showmessage('submit_invalid');
  95. }
  96. $filename = randomfile(6) . '.htm';
  97. $tmp = explode("\n", $_G['cache']['plugin']['xj_event']['event_template']);
  98. $tmp[] = $_GET['tpname'] . '|' . $filename;
  99. $filename = "./source/plugin/xj_event/etpl/" . $filename;
  100. $fp = fopen("$filename", "w+"); //打开文件指针,创建文件
  101. if (!is_writable($filename)) {
  102. showmessage(lang('plugin/xj_event', 'mbwjxrsbqjc'));;
  103. } else {
  104. $_G['cache']['plugin']['xj_event']['event_template'] = implode('\n', $tmp);
  105. $pluginid = DB :: result_first("SELECT pluginid FROM " . DB :: table('common_plugin') . " where identifier='xj_event'");
  106. DB :: query("UPDATE " . DB :: table('common_pluginvar') . " SET value = '" . $_G['cache']['plugin']['xj_event']['event_template'] . "' WHERE pluginid = $pluginid and variable = 'event_template'");
  107. require_once libfile('function/cache');
  108. updatecache(array('plugin')); //更新缓存
  109. fwrite($fp, $_GET['message']);
  110. fclose($fp); //关闭指针
  111. showmessage(lang('plugin/xj_event', 'mbtjcg'),'plugin.php?id=xj_event:event_template&act=manage');
  112. }
  113. } else {
  114. function Post($url, $post = null) {
  115. $context = array();
  116. if (is_array($post)) {
  117. ksort($post);
  118. $context['http'] = array
  119. ('method' => 'POST',
  120. 'content' => http_build_query($post, '', '&'),
  121. );
  122. }
  123. return file_get_contents($url, false, stream_context_create($context));
  124. }
  125. $data = array();
  126. /**
  127. * $data = array
  128. * (
  129. * 'url' => $_POST["url"],
  130. * );
  131. */
  132. echo Post('source/plugin/xj_event/etpl/' . $_POST["file"], $data);
  133. }// 生成随机文件名
  134. function randomfile($length) {
  135. $hash = ''; // 文件头, 可以自定义
  136. $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
  137. $max = strlen($chars) - 1;
  138. mt_srand((double)microtime() * 1000000);
  139. for($i = 0; $i < $length; $i++) {
  140. $hash .= $chars[mt_rand(0, $max)];
  141. }
  142. return $hash;
  143. }
  144. ?>