PageRenderTime 25ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/jiaju001/bbs/wap/include/global.func.php

https://gitlab.com/BGCX262/zyyhong-svn-to-git
PHP | 175 lines | 133 code | 28 blank | 14 comment | 29 complexity | a2054d4ca4b757dcf39c975cd53f98fc MD5 | raw file
  1. <?php
  2. /*
  3. [Discuz!] (C)2001-2007 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: global.func.php 16713 2008-11-17 03:25:20Z cnteacher $
  6. */
  7. if(!defined('IN_DISCUZ')) {
  8. exit('Access Denied');
  9. }
  10. function wapheader($title) {
  11. global $action, $_SERVER;
  12. header("Content-type: text/vnd.wap.wml; charset=utf-8");
  13. /*
  14. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  15. header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
  16. header("Cache-Control: no-cache, must-revalidate");
  17. header("Pragma: no-cache");
  18. */
  19. echo "<?xml version=\"1.0\"?>\n".
  20. "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n".
  21. "<wml>\n".
  22. "<head>\n".
  23. "<meta http-equiv=\"cache-control\" content=\"max-age=180,private\" />\n".
  24. "</head>\n".
  25. "<card id=\"discuz_wml\" title=\"$title\">\n";
  26. // newcontext=\"true\"
  27. }
  28. function wapfooter() {
  29. global $discuz_uid, $discuz_user, $lang, $action, $settings, $timestamp, $timeoffset, $wapdateformat, $timeformat;
  30. echo "<p>".gmdate("$wapdateformat $timeformat", $timestamp + ($timeoffset * 3600))."<br />".
  31. ($action != 'home' ? "<anchor title=\"confirm\"><prev/>$lang[return]</anchor> <a href=\"index.php\">$lang[home_page]</a><br />" : '').
  32. ($discuz_uid ? "<a href=\"index.php?action=login&amp;logout=yes&amp;formhash=".FORMHASH."\">$discuz_user:$lang[logout]</a>" : "<a href=\"index.php?action=login\">$lang[login]</a> <a href=\"index.php?action=register\">$lang[register]</a>")."<br /><br />\n".
  33. "<small><a href=\"http://wap.jiaju001.com\">wap.jiaju001.com</a></small></p>\n".
  34. //"<do type=\"prev\" label=\"$lang[return]\"><exit /></do>\n".
  35. "</card>\n".
  36. "</wml>";
  37. updatesession();
  38. wmloutput();
  39. }
  40. function wapmsg($message, $forward = array()) {
  41. extract($GLOBALS, EXTR_SKIP);
  42. if(isset($lang[$message])) {
  43. eval("\$message = \"".$lang[$message]."\";");
  44. }
  45. echo "<p>$message".
  46. ($forward ? "<br /><a href=\"$forward[link]\">".(isset($lang[$forward['title']]) ? $lang[$forward['title']] : $forward['title'])."</a>" : '').
  47. "</p>\n";
  48. wapfooter();
  49. exit();
  50. }
  51. function wapmulti($num, $perpage, $curpage, $mpurl) {
  52. global $lang;
  53. $multipage = '';
  54. $mpurl .= strpos($mpurl, '?') ? '&amp;' : '?';
  55. if($num > $perpage) {
  56. $page = 3;
  57. $offset = 2;
  58. $realpages = @ceil($num / $perpage);
  59. $pages = $realpages;
  60. if($page > $pages) {
  61. $from = 1;
  62. $to = $pages;
  63. } else {
  64. $from = $curpage - $offset;
  65. $to = $from + $page - 1;
  66. if($from < 1) {
  67. $to = $curpage + 1 - $from;
  68. $from = 1;
  69. if($to - $from < $page) {
  70. $to = $page;
  71. }
  72. } elseif($to > $pages) {
  73. $from = $pages - $page + 1;
  74. $to = $pages;
  75. }
  76. }
  77. $multipage = ($curpage - $offset > 1 && $pages > $page ? '<a href="'.$mpurl.'page=1">'.$lang['home_page'].'</a>' : '').
  78. ($curpage > 1 ? ' <a href="'.$mpurl.'page='.($curpage - 1).'">'.$lang['last_page'].'</a>' : '');
  79. for($i = $from; $i <= $to; $i++) {
  80. $multipage .= $i == $curpage ? ' '.$i : ' <a href="'.$mpurl.'page='.$i.'">'.$i.'</a>';
  81. }
  82. $multipage .= ($curpage < $pages ? ' <a href="'.$mpurl.'page='.($curpage + 1).'">'.$lang['next_page'].'</a>' : '').
  83. ($to < $pages ? ' <a href="'.$mpurl.'page='.$pages.'">'.$lang['end_page'].'</a>' : '');
  84. $multipage .= $realpages > $page ?
  85. '<br />'.$curpage.'/'.$realpages.$lang['page'].'<input type="text" name="page" size="2" emptyok="true" /> '.
  86. '<anchor title="submit">'.$lang['turn_page'].'<go method="post" href="'.$mpurl.'">'.
  87. '<postfield name="page" value="$(page)" />'.
  88. '</go></anchor>' : '';
  89. }
  90. return $multipage;
  91. }
  92. function wapcutstr($string, &$length) {
  93. $strcut = '';
  94. if(strlen($string) > $length) {
  95. for($i = 0; $i < $length - 3; $i++) {
  96. $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
  97. }
  98. $length = $i;
  99. return $strcut.' ..';
  100. } else {
  101. return $string;
  102. }
  103. }
  104. function wapcode($string) {
  105. global $lang;
  106. $string = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $string);
  107. $string = preg_replace("/\[hide\](.+?)\[\/hide\]/is", $lang['post_hide_reply_hidden'], $string);
  108. $string = preg_replace("/\[hide=(\d+)\]\s*(.+?)\s*\[\/hide\]/ies", $lang['post_hide_reply_hidden'], $string);
  109. for($i = 0; $i < 5; $i++) {
  110. $string = preg_replace("/\[(\w+)[^\]]*?\](.*?)\[\/\\1\]/is", "\\2", $string);
  111. }
  112. return $string;
  113. }
  114. function wmloutput() {
  115. global $sid, $charset, $wapcharset;
  116. static $chs;
  117. $content = preg_replace("/\<a(\s*[^\>]+\s*)href\=([\"|\']?)([^\"\'\s]+)/ies", "transsid('\\3','<a\\1href=\\2',1)", ob_get_contents());
  118. ob_end_clean();
  119. if($charset != 'utf-8') {
  120. $target = $wapcharset == 1 ? 'UTF-8' : 'UNICODE';
  121. if(empty($chs)) {
  122. $chs = new Chinese($charset, $target);
  123. } else {
  124. $chs->config['SourceLang'] = $chs->_lang($charset);
  125. $chs->config['TargetLang'] = $target;
  126. }
  127. echo ($wapcharset == 1 ? $chs->Convert($content) : str_replace(array('&#x;', '&#x0;'), array('??', ''), $chs->Convert($content)));
  128. } else {
  129. echo $content;
  130. }
  131. }
  132. function wapconvert($str) {
  133. static $chs;
  134. if($str != '' && !is_numeric($str) && $GLOBALS['charset'] != 'utf-8') {
  135. $chs = empty($chs) ? new Chinese('UTF-8', $GLOBALS['charset']) : $chs;
  136. if(is_array($str)) {
  137. foreach($str as $key => $val) {
  138. $str[$key] = wapconvert($val);
  139. }
  140. } else {
  141. $str = addslashes($chs->Convert(stripslashes($str)));
  142. }
  143. }
  144. return $str;
  145. }
  146. ?>