response_setting.inc.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: response_setting.inc.php 34817 2014-08-11 02:59:38Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. loadcache('wechat_response');
  12. $response = & $_G['cache']['wechat_response'];
  13. require_once DISCUZ_ROOT.'./source/plugin/wechat/wechat.lib.class.php';
  14. require_once DISCUZ_ROOT.'./source/plugin/wechat/wsq.class.php';
  15. require_once DISCUZ_ROOT.'./source/plugin/wechat/setting.class.php';
  16. WeChatSetting::menu();
  17. if(!submitcheck('menusubmit')) {
  18. showtips(lang('plugin/wechat', 'response_tips', array('url' => $url)));
  19. $responsehook = WeChatHook::getResponse();
  20. if($_GET['subscribe'] == 'custom') {
  21. $response['subscribeback'] = $responsehook['receiveEvent::subscribe'];
  22. $updatedata = array('receiveEvent::subscribe' => array('plugin' => 'wechat', 'include' => 'response.class.php', 'class' => 'WSQResponse', 'method' => 'custom'));
  23. $responsehook = WeChatHook::updateResponse($updatedata);
  24. savecache('wechat_response', $response);
  25. cpmsg(lang('plugin/wechat', 'response_subscribe_custom'), 'action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=response_setting', 'succeed');
  26. } elseif($_GET['subscribe'] == 'restore') {
  27. $response['subscribeback'] = $response['subscribeback'] ? $response['subscribeback'] : array('plugin' => 'wechat', 'include' => 'response.class.php', 'class' => 'WSQResponse', 'method' => 'subscribe');
  28. $updatedata = array('receiveEvent::subscribe' => $response['subscribeback']);
  29. $responsehook = WeChatHook::updateResponse($updatedata);
  30. savecache('wechat_response', $response);
  31. cpmsg(lang('plugin/wechat', 'response_subscribe_plugin'), 'action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=response_setting', 'succeed');
  32. }
  33. if($_GET['text'] == 'custom') {
  34. $response['textback'] = $responsehook['receiveMsg::text'];
  35. $updatedata = array('receiveMsg::text' => array('plugin' => 'wechat', 'include' => 'response.class.php', 'class' => 'WSQResponse', 'method' => 'text'));
  36. $responsehook = WeChatHook::updateResponse($updatedata);
  37. savecache('wechat_response', $response);
  38. cpmsg(lang('plugin/wechat', 'response_message_custom'), 'action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=response_setting', 'succeed');
  39. } elseif($_GET['text'] == 'restore') {
  40. $response['textback'] = $response['textback'] ? $response['textback'] : array('plugin' => 'wechat', 'include' => 'response.class.php', 'class' => 'WSQResponse', 'method' => 'text');
  41. $updatedata = array('receiveMsg::text' => $response['textback']);
  42. $responsehook = WeChatHook::updateResponse($updatedata);
  43. savecache('wechat_response', $response);
  44. cpmsg(lang('plugin/wechat', 'response_message_plugin'), 'action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=response_setting', 'succeed');
  45. }
  46. WeChatSetting::showResource();
  47. showformheader('plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=response_setting');
  48. showtableheader();
  49. echo '<tr><th class="td25"></th><th style="width:350px"><strong>'.lang('plugin/wechat', 'response_keyword').'</strong></th><th><strong>'.lang('plugin/wechat', 'response_content').'</strong></th></tr>';
  50. if($responsehook['receiveEvent::subscribe']['plugin'] == 'wechat' &&
  51. $responsehook['receiveEvent::subscribe']['class'] == 'WSQResponse' &&
  52. $responsehook['receiveEvent::subscribe']['method'] == 'custom') {
  53. showtablerow('class="header"', array('', 'class="td23 td28"', '', 'class="td29"'), array(
  54. "",
  55. lang('plugin/wechat', 'response_subscribe'),
  56. "<p class=\"mbn\">".lang('plugin/wechat', 'response_custom')." ".($response['subscribeback'] ? "<a class=\"normal\" href=\"".ADMINSCRIPT."?action=plugins&operation=config&do=$pluginid&identifier=wechat&pmod=response_setting&subscribe=restore\">[".lang('plugin/wechat', 'response_switch_plugin_mode', array('plugin' => $response['subscribeback']['plugin']))."]</a></p>" : '')
  57. ));
  58. showtablerow('', array('', 'class="td23 td28"', '', 'class="td29"'), array(
  59. "",
  60. "<i>".lang('plugin/wechat', 'subscribe')."</i>",
  61. "<textarea class=\"tarea\" name=\"response[subscribe]\" id=\"res_subscribe\" rows=\"5\" cols=\"40\">".dhtmlspecialchars($response['subscribe'])."</textarea>"
  62. ."<br /><a href=\"javascript:;\" id=\"rsel\" onclick=\"showResource('res_subscribe')\">".lang('plugin/wechat', 'resource_select')."</a>"
  63. ));
  64. } else {
  65. showtablerow('class="header"', array('', 'class="td23 td28"', '', 'class="td29"'), array(
  66. "",
  67. lang('plugin/wechat', 'response_subscribe'),
  68. "<p>".lang('plugin/wechat', 'response_plugin_mode', array('plugin' => $responsehook['receiveEvent::subscribe']['plugin']))." <a class=\"normal\" href=\"".ADMINSCRIPT."?action=plugins&operation=config&do=$pluginid&identifier=wechat&pmod=response_setting&subscribe=custom\">[".lang('plugin/wechat', 'response_switch_custom_mode')."]</a></p>"
  69. ));
  70. }
  71. showtablerow('class="header"', array('', 'class="td23 td28"', '', 'class="td29"'), array(
  72. "",
  73. lang('plugin/wechat', 'response_access'),
  74. "<p class=\"mbn normal\">".lang('plugin/wechat', 'response_access_comment')
  75. ));
  76. showtablerow('', array('', 'class="td23 td28"', '', 'class="td29"'), array(
  77. "",
  78. "<i>".lang('plugin/wechat', 'access')."</i>",
  79. "<textarea class=\"tarea\" name=\"response[access]\" id=\"res_access\" rows=\"5\" cols=\"40\">".dhtmlspecialchars($response['access'])."</textarea>"
  80. ."<br /><a href=\"javascript:;\" id=\"rsel\" onclick=\"showResource('res_access')\">".lang('plugin/wechat', 'resource_select')."</a>"
  81. ));
  82. showtablerow('class="header"', array('', 'class="td23 td28"', '', 'class="td29"'), array(
  83. "",
  84. lang('plugin/wechat', 'response_scan'),
  85. "<p class=\"mbn normal\">".lang('plugin/wechat', 'response_scan_comment')
  86. ));
  87. showtablerow('', array('', 'class="td23 td28"', '', 'class="td29"'), array(
  88. "",
  89. "<i>".lang('plugin/wechat', 'scan')."</i>",
  90. "<textarea class=\"tarea\" name=\"response[scan]\" id=\"res_scan\" rows=\"5\" cols=\"40\">".dhtmlspecialchars($response['scan'])."</textarea>"
  91. ."<br /><a href=\"javascript:;\" id=\"rsel\" onclick=\"showResource('res_scan')\">".lang('plugin/wechat', 'resource_select')."</a>"
  92. ));
  93. if($responsehook['receiveMsg::text']['plugin'] == 'wechat' &&
  94. $responsehook['receiveMsg::text']['class'] == 'WSQResponse' &&
  95. $responsehook['receiveMsg::text']['method'] == 'text') {
  96. showtablerow('class="header"', array('', 'class="td23 td28"', '', 'class="td29"'), array(
  97. "",
  98. lang('plugin/wechat', 'response_message'),
  99. "<p class=\"mbn\">".lang('plugin/wechat', 'response_custom')." ".($response['textback'] ? "<a class=\"normal\" href=\"".ADMINSCRIPT."?action=plugins&operation=config&do=$pluginid&identifier=wechat&pmod=response_setting&text=restore\">[".lang('plugin/wechat', 'response_switch_plugin_mode', array('plugin' => $response['textback']['plugin']))."]</a></p>" : '')
  100. ));
  101. foreach($response['text'] as $k => $text) {
  102. showtablerow('', array('', 'class="td23 td28"', 'class="td29"'), array(
  103. "<input class=\"checkbox\" type=\"checkbox\" name=\"response[text][$k][delete]\" value=\"yes\">",
  104. "<div class=\"parentnode\"><input type=\"text\" class=\"txt\" size=\"30\" name=\"response[text][$k][keyword]\" value=\"".dhtmlspecialchars($text['keyword'])."\"></div>",
  105. "<textarea class=\"tarea\" name=\"response[text][$k][response]\" rows=\"5\" id=\"res_text_$k\" cols=\"40\">".dhtmlspecialchars($text['response'])."</textarea>"
  106. ."<br /><a href=\"javascript:;\" id=\"rsel\" onclick=\"showResource('res_text_$k')\">".lang('plugin/wechat', 'resource_select')."</a>"
  107. ));
  108. }
  109. echo '<tr><td></td><td class="td23 td28"></td><td colspan="2"><div><a href="###" onclick="addrow(this, 0, 0)" class="addtr">'.lang('plugin/wechat', 'response_add_message').'</a></div></td></tr>';
  110. echo <<<EOT
  111. <script type="text/JavaScript">
  112. var rowtypedata = [
  113. [[1,''], [1, '<input name="newresponse[keyword][]" value="" size="30" type="text" class="txt">'], [1, '<textarea class="tarea" name="newresponse[response][]" rows="5" cols="40"></textarea>', 'td29']],
  114. ];
  115. </script>
  116. EOT;
  117. } else {
  118. showtablerow('class="header"', array('', 'class="td23 td28"', '', 'class="td29"'), array(
  119. "",
  120. lang('plugin/wechat', 'response_message'),
  121. "<p>".lang('plugin/wechat', 'response_plugin_mode', array('plugin' => $responsehook['receiveMsg::text']['plugin']))." <a class=\"normal\" href=\"".ADMINSCRIPT."?action=plugins&operation=config&do=$pluginid&identifier=wechat&pmod=response_setting&text=custom\">[".lang('plugin/wechat', 'response_switch_custom_mode')."]</a></p>"
  122. ));
  123. }
  124. showsubmit('menusubmit', 'submit', 'del');
  125. showtablefooter();
  126. showformfooter();
  127. } else {
  128. if(!empty($_GET['newresponse'])) {
  129. foreach($_GET['newresponse']['keyword'] as $k => $keyword) {
  130. $item = array(
  131. 'keyword' => $keyword,
  132. 'response' => $_GET['newresponse']['response'][$k],
  133. );
  134. $response['text'][] = $item;
  135. }
  136. }
  137. foreach($_GET['response']['text'] as $k => $value) {
  138. if($value['delete']) {
  139. unset($response['text'][$k]);
  140. continue;
  141. }
  142. $response['text'][$k] = $value;
  143. }
  144. $response['subscribe'] = $_GET['response']['subscribe'];
  145. $response['access'] = $_GET['response']['access'];
  146. $response['scan'] = $_GET['response']['scan'];
  147. $query = array(
  148. 'subscribe' => $response['subscribe'],
  149. 'text' => array(),
  150. );
  151. foreach($response['text'] as $value) {
  152. $query['text'][$value['keyword']] = $value['response'];
  153. }
  154. $response['query'] = $query;
  155. savecache('wechat_response', $response);
  156. cpmsg('setting_update_succeed', 'action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=response_setting', 'succeed');
  157. }
  158. ?>