PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/wap/include/global.func.php

https://github.com/gcao/bbs
PHP | 216 lines | 163 code | 39 blank | 14 comment | 47 complexity | f39ff3644c90ddd1e20e19c4510de3ee MD5 | raw file
  1. <?php
  2. /*
  3. [Discuz!] (C)2001-2009 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: global.func.php 18537 2009-06-11 01:36:49Z monkey $
  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>Powered by Discuz!</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, $dot = ' ..') {
  93. global $charset;
  94. if(strlen($string) <= $length) {
  95. return $string;
  96. }
  97. $string = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $string);
  98. $strcut = '';
  99. if(strtolower($charset) == 'utf-8') {
  100. $n = $tn = $noc = 0;
  101. while($n < strlen($string)) {
  102. $t = ord($string[$n]);
  103. if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
  104. $tn = 1; $n++; $noc++;
  105. } elseif(194 <= $t && $t <= 223) {
  106. $tn = 2; $n += 2; $noc += 2;
  107. } elseif(224 <= $t && $t <= 239) {
  108. $tn = 3; $n += 3; $noc += 2;
  109. } elseif(240 <= $t && $t <= 247) {
  110. $tn = 4; $n += 4; $noc += 2;
  111. } elseif(248 <= $t && $t <= 251) {
  112. $tn = 5; $n += 5; $noc += 2;
  113. } elseif($t == 252 || $t == 253) {
  114. $tn = 6; $n += 6; $noc += 2;
  115. } else {
  116. $n++;
  117. }
  118. if($noc >= $length) {
  119. break;
  120. }
  121. }
  122. if($noc > $length) {
  123. $n -= $tn;
  124. }
  125. $strcut = substr($string, 0, $n);
  126. } else {
  127. for($i = 0; $i < $length; $i++) {
  128. $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
  129. }
  130. }
  131. $strcut = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $strcut);
  132. return $strcut.$dot;
  133. }
  134. function wapcode($string) {
  135. global $lang;
  136. $string = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $string);
  137. $string = preg_replace("/\[hide\](.+?)\[\/hide\]/is", $lang['post_hide_reply_hidden'], $string);
  138. $string = preg_replace("/\[hide=(\d+)\]\s*(.+?)\s*\[\/hide\]/ies", $lang['post_hide_reply_hidden'], $string);
  139. for($i = 0; $i < 5; $i++) {
  140. $string = preg_replace("/\[(\w+)[^\]]*?\](.*?)\[\/\\1\]/is", "\\2", $string);
  141. }
  142. return $string;
  143. }
  144. function wmloutput() {
  145. global $sid, $charset, $wapcharset;
  146. static $chs;
  147. $content = preg_replace("/\<a(\s*[^\>]+\s*)href\=([\"|\']?)([^\"\'\s]+)/ies", "transsid('\\3','<a\\1href=\\2',1)", ob_get_contents());
  148. ob_end_clean();
  149. if($charset != 'utf-8') {
  150. $target = $wapcharset == 1 ? 'UTF-8' : 'UNICODE';
  151. if(empty($chs)) {
  152. $chs = new Chinese($charset, $target);
  153. } else {
  154. $chs->config['SourceLang'] = $chs->_lang($charset);
  155. $chs->config['TargetLang'] = $target;
  156. }
  157. echo ($wapcharset == 1 ? $chs->Convert($content) : str_replace(array('&#x;', '&#x0;'), array('??', ''), $chs->Convert($content)));
  158. } else {
  159. echo $content;
  160. }
  161. }
  162. function wapconvert($str) {
  163. static $chs;
  164. if($str != '' && !is_numeric($str) && $GLOBALS['charset'] != 'utf-8') {
  165. $chs = empty($chs) ? new Chinese('UTF-8', $GLOBALS['charset']) : $chs;
  166. if(is_array($str)) {
  167. foreach($str as $key => $val) {
  168. $str[$key] = wapconvert($val);
  169. }
  170. } else {
  171. $str = addslashes($chs->Convert(stripslashes($str)));
  172. }
  173. }
  174. return $str;
  175. }
  176. ?>