api_setting.inc.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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: api_setting.inc.php 34754 2014-07-29 03:16:20Z 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('orderssubmit')) {
  18. $apihook = WeChatHook::getAPIHook();
  19. foreach($apihook as $page => $hooks) {
  20. foreach($hooks as $hook => $rows) {
  21. foreach($rows as $plugin => $row) {
  22. if(isset($_GET['order'][$page][$hook][$plugin])) {
  23. $apihook[$page][$hook][$plugin]['order'] = $_GET['order'][$page][$hook][$plugin];
  24. }
  25. $apihook[$page][$hook][$plugin]['allow'] = !empty($_GET['allow'][$page][$hook][$plugin]) ? 1 : 0;
  26. }
  27. uasort($apihook[$page][$hook], 'pluginapicmp');
  28. }
  29. }
  30. $settings = array('mobileapihook' => serialize($apihook));
  31. C::t('common_setting')->update_batch($settings);
  32. updatecache('setting');
  33. }
  34. showtips(lang('plugin/wechat', 'wechatapi_tips'));
  35. $apihook = WeChatHook::getAPIHook();
  36. $plugins = DB::fetch_all('SELECT identifier, name FROM %t', array('common_plugin'), 'identifier');
  37. showformheader('plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=api_setting');
  38. showtableheader(lang('plugin/wechat', 'api_wsq'));
  39. echo '<tr class="header"><th>'.lang('plugin/wechat', 'api_hook').'</th><th>'.cplang('plugins_name').'</th><th>'.cplang('enable').'/'.cplang('display_order').'</th><th>'.lang('plugin/wechat', 'api_method').'</th></tr>';
  40. foreach($apihook as $page => $hooks) {
  41. foreach($hooks as $hook => $rows) {
  42. $i = 0;
  43. foreach($rows as $plugin => $row) {
  44. if(!$plugins[$plugin]) {
  45. $deleteplugins[] = $plugin;
  46. }
  47. $row['plugin'] = $plugin;
  48. echo '<tr class="hover"><td>'.(!$i ? $page.'_'.$hook : '').'</td>'.
  49. '<td>'.$plugins[$plugin]['name'].'</td>'.
  50. '<td><input class="checkbox" type="checkbox" name="allow['.$page.']['.$hook.']['.$plugin.']" value="1"'.($row['allow'] ? ' checked' : '').'>'.
  51. ($hook != 'variables' ?
  52. '<input class="txt num" type="text" name="order['.$page.']['.$hook.']['.$plugin.']" value="'.$row['order'].'"></td>' :
  53. '</td>').
  54. '<td>'.formathook($row).'</td></tr>';
  55. $i++;
  56. }
  57. }
  58. }
  59. if($deleteplugins) {
  60. WeChatHook::delAPIHook($deleteplugins);
  61. }
  62. showsubmit('orderssubmit');
  63. showtablefooter();
  64. showformfooter();
  65. $redirect = WeChatHook::getRedirect();
  66. $response = WeChatHook::getResponse();
  67. $plugins = DB::fetch_all('SELECT identifier, name FROM %t', array('common_plugin'), 'identifier');
  68. showtableheader(lang('plugin/wechat', 'api_wechat'));
  69. echo '<tr class="header"><th>'.lang('plugin/wechat', 'api_hook').'</th><th>'.cplang('plugins_name').'</th><th>'.lang('plugin/wechat', 'api_method').'</th></tr>';
  70. if($redirect) {
  71. if(!$plugins[$redirect['plugin']]) {
  72. WeChatHook::updateRedirect(array());
  73. }
  74. echo '<tr class="hover"><td>'.lang('plugin/wechat', 'wechatapi_redirect').'</td><td>'.$plugins[$redirect['plugin']]['name'].'</td><td>'.formathook($redirect).'</td></tr>';
  75. }
  76. foreach($response as $k => $row) {
  77. if(!$plugins[$row['plugin']]) {
  78. $deleteresponses[$k] = array();
  79. }
  80. echo '<tr class="hover"><td>'.lang('plugin/wechat', 'api_'.$k).'('.$k.')</td><td>'.$plugins[$row['plugin']]['name'].'</td><td>'.formathook($row).'</td></tr>';
  81. }
  82. showtablefooter();
  83. $wechatresponseExts = unserialize($_G['setting']['wechatresponseExts']);
  84. if($wechatresponseExts) {
  85. showtableheader();
  86. foreach($wechatresponseExts as $extk => $response) {
  87. echo '<tr class="header"><th>'.lang('plugin/wechat', 'wechat_responseexts').' '.$extk.'</th><th>'.cplang('plugins_name').'</th><th>'.lang('plugin/wechat', 'api_method').'</th></tr>';
  88. foreach($response as $k => $row) {
  89. if(!$plugins[$row['plugin']]) {
  90. $deleteresponseExts[$extk][$k] = array();
  91. }
  92. echo '<tr class="hover"><td>'.lang('plugin/wechat', 'api_'.$k).'('.$k.')</td><td>'.$plugins[$row['plugin']]['name'].'</td><td>'.formathook($row).'</td></tr>';
  93. }
  94. }
  95. showtablefooter();
  96. }
  97. if($deleteresponses) {
  98. WeChatHook::updateResponse($deleteresponses);
  99. }
  100. if($deleteresponseExts) {
  101. foreach($deleteresponseExts as $extk => $deleteresponses) {
  102. WeChatHook::updateResponse($deleteresponses, $extk);
  103. }
  104. }
  105. $wechatappInfos = unserialize($_G['setting']['wechatappInfos']);
  106. if($wechatappInfos) {
  107. showtableheader();
  108. echo '<tr class="header"><th width="200">'.lang('plugin/wechat', 'wechat_devids').'</th><th>'.lang('plugin/wechat', 'wechat_appId').'</th><th>'.lang('plugin/wechat', 'wechat_appsecret').'</th></tr>';
  109. foreach(unserialize($_G['setting']['wechatappInfos']) as $k => $info) {
  110. echo '<tr class="hover"><td>'.$k.'</td><td>'.$info['appId'].'</td><td>'.$info['appSecret'].'</td></tr>';
  111. }
  112. showtablefooter();
  113. }
  114. function formathook($hook) {
  115. return '<b>File:</b> '.$hook['plugin'].'/'.$hook['include'].' <b>Method:</b> '.$hook['class'].'->'.$hook['method'];
  116. }
  117. function pluginapicmp($a, $b) {
  118. return $a['order'] > $b['order'] ? 1 : -1;
  119. }
  120. ?>