function_message.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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: function_message.php 32580 2013-02-22 03:40:28Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function dshowmessage($message, $url_forward = '', $values = array(), $extraparam = array(), $custom = 0) {
  12. global $_G, $show_message;
  13. $_G['messageparam'] = func_get_args();
  14. if(empty($_G['inhookscript']) && defined('CURMODULE')) {
  15. hookscript(CURMODULE, $_G['basescript'], 'messagefuncs', array('param' => $_G['messageparam']));
  16. }
  17. if($extraparam['break']) {
  18. return;
  19. }
  20. $_G['inshowmessage'] = true;
  21. $param = array(
  22. 'header' => false,
  23. 'timeout' => null,
  24. 'refreshtime' => null,
  25. 'closetime' => null,
  26. 'locationtime' => null,
  27. 'alert' => null,
  28. 'return' => false,
  29. 'redirectmsg' => 0,
  30. 'msgtype' => 1,
  31. 'showmsg' => true,
  32. 'showdialog' => false,
  33. 'login' => false,
  34. 'handle' => false,
  35. 'extrajs' => '',
  36. 'striptags' => true,
  37. );
  38. $navtitle = lang('core', 'title_board_message');
  39. if($custom) {
  40. $alerttype = 'alert_info';
  41. $show_message = $message;
  42. include template('common/showmessage');
  43. dexit();
  44. }
  45. define('CACHE_FORBIDDEN', TRUE);
  46. $_G['setting']['msgforward'] = @dunserialize($_G['setting']['msgforward']);
  47. $handlekey = $leftmsg = '';
  48. if(defined('IN_MOBILE')) {
  49. unset($extraparam['showdialog']);
  50. unset($extraparam['closetime']);
  51. unset($extraparam['extrajs']);
  52. if(!$url_forward && dreferer() && IN_MOBILE == 1) {
  53. $url_forward = $referer = dreferer();
  54. }
  55. if(!empty($url_forward) && strpos($url_forward, 'mobile') === false) {
  56. $url_forward_arr = explode("#", $url_forward);
  57. if(strpos($url_forward_arr[0], '?') !== false) {
  58. $url_forward_arr[0] = $url_forward_arr[0].'&mobile='.IN_MOBILE;
  59. } else {
  60. $url_forward_arr[0] = $url_forward_arr[0].'?mobile='.IN_MOBILE;
  61. }
  62. $url_forward = implode("#", $url_forward_arr);
  63. }
  64. }
  65. if(empty($_G['inajax']) && (!empty($_GET['quickforward']) || $_G['setting']['msgforward']['quick'] && empty($extraparam['clean_msgforward']) && $_G['setting']['msgforward']['messages'] && @in_array($message, $_G['setting']['msgforward']['messages']))) {
  66. $param['header'] = true;
  67. }
  68. $_GET['handlekey'] = !empty($_GET['handlekey']) && preg_match('/^\w+$/', $_GET['handlekey']) ? $_GET['handlekey'] : '';
  69. if(!empty($_G['inajax'])) {
  70. $handlekey = $_GET['handlekey'] = !empty($_GET['handlekey']) ? dhtmlspecialchars($_GET['handlekey']) : '';
  71. $param['handle'] = true;
  72. }
  73. if(!empty($_G['inajax'])) {
  74. $param['msgtype'] = empty($_GET['ajaxmenu']) && (empty($_POST) || !empty($_GET['nopost'])) ? 2 : 3;
  75. }
  76. if($url_forward) {
  77. $param['timeout'] = true;
  78. if($param['handle'] && !empty($_G['inajax'])) {
  79. $param['showmsg'] = false;
  80. }
  81. }
  82. foreach($extraparam as $k => $v) {
  83. $param[$k] = $v;
  84. }
  85. if(array_key_exists('set', $extraparam)) {
  86. $setdata = array('1' => array('msgtype' => 3));
  87. if($setdata[$extraparam['set']]) {
  88. foreach($setdata[$extraparam['set']] as $k => $v) {
  89. $param[$k] = $v;
  90. }
  91. }
  92. }
  93. $timedefault = intval($param['refreshtime'] === null ? $_G['setting']['msgforward']['refreshtime'] : $param['refreshtime']);
  94. if($param['timeout'] !== null) {
  95. $refreshsecond = !empty($timedefault) ? $timedefault : 3;
  96. $refreshtime = $refreshsecond * 1000;
  97. } else {
  98. $refreshtime = $refreshsecond = 0;
  99. }
  100. if($param['login'] && $_G['uid'] || $url_forward) {
  101. $param['login'] = false;
  102. }
  103. $param['header'] = $url_forward && $param['header'] ? true : false;
  104. if($_GET['ajaxdata'] === 'json') {
  105. $param['header'] = '';
  106. }
  107. if($param['header']) {
  108. header("HTTP/1.1 301 Moved Permanently");
  109. dheader("location: ".str_replace('&amp;', '&', $url_forward));
  110. }
  111. $url_forward_js = addslashes(str_replace('\\', '%27', $url_forward));
  112. if($param['location'] && !empty($_G['inajax'])) {
  113. include template('common/header_ajax');
  114. echo '<script type="text/javascript" reload="1">window.location.href=\''.$url_forward_js.'\';</script>';
  115. include template('common/footer_ajax');
  116. dexit();
  117. }
  118. $_G['hookscriptmessage'] = $message;
  119. $_G['hookscriptvalues'] = $values;
  120. $vars = explode(':', $message);
  121. if(count($vars) == 2) {
  122. $show_message = lang('plugin/'.$vars[0], $vars[1], $values);
  123. } else {
  124. $show_message = lang('message', $message, $values);
  125. }
  126. if(isset($_GET['ajaxdata'])) {
  127. if($_GET['ajaxdata'] === 'json') {
  128. helper_output::json(array('message' => $show_message, 'data' => $values));
  129. } else if($_GET['ajaxdata'] === 'html') {
  130. helper_output::html($show_message);
  131. }
  132. }
  133. if($_G['connectguest']) {
  134. $param['login'] = false;
  135. $param['alert'] = 'info';
  136. if (defined('IN_MOBILE')) {
  137. if ($message == 'postperm_login_nopermission_mobile') {
  138. $show_message = lang('plugin/qqconnect', 'connect_register_mobile_bind_error');
  139. }
  140. $show_message = str_replace(lang('forum/misc', 'connectguest_message_mobile_search'), lang('forum/misc', 'connectguest_message_mobile_replace'), $show_message);
  141. } else {
  142. $show_message = str_replace(lang('forum/misc', 'connectguest_message_search'), lang('forum/misc', 'connectguest_message_replace'), $show_message);
  143. }
  144. if ($message == 'group_nopermission') {
  145. $show_message = lang('plugin/qqconnect', 'connectguest_message_complete_or_bind');
  146. }
  147. }
  148. if($param['msgtype'] == 2 && $param['login']) {
  149. dheader('location: member.php?mod=logging&action=login&handlekey='.$handlekey.'&infloat=yes&inajax=yes&guestmessage=yes');
  150. }
  151. $show_jsmessage = str_replace("'", "\\'", $param['striptags'] ? strip_tags($show_message) : $show_message);
  152. if((!$param['showmsg'] || $param['showid']) && !defined('IN_MOBILE') ) {
  153. $show_message = '';
  154. }
  155. $allowreturn = !$param['timeout'] && !$url_forward && !$param['login'] || $param['return'] ? true : false;
  156. if($param['alert'] === null) {
  157. $alerttype = $url_forward ? (preg_match('/\_(succeed|success)$/', $message) ? 'alert_right' : 'alert_info') : ($allowreturn ? 'alert_error' : 'alert_info');
  158. } else {
  159. $alerttype = 'alert_'.$param['alert'];
  160. }
  161. $extra = '';
  162. if($param['showid']) {
  163. $extra .= 'if($(\''.$param['showid'].'\')) {$(\''.$param['showid'].'\').innerHTML = \''.$show_jsmessage.'\';}';
  164. }
  165. if($param['handle']) {
  166. $valuesjs = $comma = $subjs = '';
  167. foreach($values as $k => $v) {
  168. $v = daddslashes($v);
  169. if(is_array($v)) {
  170. $subcomma = '';
  171. foreach ($v as $subk => $subv) {
  172. $subjs .= $subcomma.'\''.$subk.'\':\''.$subv.'\'';
  173. $subcomma = ',';
  174. }
  175. $valuesjs .= $comma.'\''.$k.'\':{'.$subjs.'}';
  176. } else {
  177. $valuesjs .= $comma.'\''.$k.'\':\''.$v.'\'';
  178. }
  179. $comma = ',';
  180. }
  181. $valuesjs = '{'.$valuesjs.'}';
  182. if($url_forward) {
  183. $extra .= 'if(typeof succeedhandle_'.$handlekey.'==\'function\') {succeedhandle_'.$handlekey.'(\''.$url_forward_js.'\', \''.$show_jsmessage.'\', '.$valuesjs.');}';
  184. } else {
  185. $extra .= 'if(typeof errorhandle_'.$handlekey.'==\'function\') {errorhandle_'.$handlekey.'(\''.$show_jsmessage.'\', '.$valuesjs.');}';
  186. }
  187. }
  188. if($param['closetime'] !== null) {
  189. $param['closetime'] = $param['closetime'] === true ? $timedefault : $param['closetime'];
  190. }
  191. if($param['locationtime'] !== null) {
  192. $param['locationtime'] = $param['locationtime'] === true ? $timedefault : $param['locationtime'];
  193. }
  194. if($handlekey) {
  195. if($param['showdialog']) {
  196. $modes = array('alert_error' => 'alert', 'alert_right' => 'right', 'alert_info' => 'notice');
  197. $extra .= 'hideWindow(\''.$handlekey.'\');showDialog(\''.$show_jsmessage.'\', \''.$modes[$alerttype].'\', null, '.($param['locationtime'] !== null ? 'function () { window.location.href =\''.$url_forward_js.'\'; }' : 'null').', 0, null, null, null, null, '.($param['closetime'] ? $param['closetime'] : 'null').', '.($param['locationtime'] ? $param['locationtime'] : 'null').');';
  198. $param['closetime'] = null;
  199. $st = '';
  200. if($param['showmsg']) {
  201. $show_message = '';
  202. }
  203. }
  204. if($param['closetime'] !== null) {
  205. $extra .= 'setTimeout("hideWindow(\''.$handlekey.'\')", '.($param['closetime'] * 1000).');';
  206. }
  207. } else {
  208. $st = $param['locationtime'] !== null ?'setTimeout("window.location.href =\''.$url_forward_js.'\';", '.($param['locationtime'] * 1000).');' : '';
  209. }
  210. if(!$extra && $param['timeout'] && !defined('IN_MOBILE')) {
  211. $extra .= 'setTimeout("window.location.href =\''.$url_forward_js.'\';", '.$refreshtime.');';
  212. }
  213. $show_message .= $extra ? '<script type="text/javascript" reload="1">'.$extra.$st.'</script>' : '';
  214. $show_message .= $param['extrajs'] ? $param['extrajs'] : '';
  215. include template('common/showmessage');
  216. dexit();
  217. }
  218. ?>