global.func.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. /**
  3. * 输出xml头部信息
  4. */
  5. function wmlHeader() {
  6. echo "<?xml version=\"1.0\" encoding=\"".CHARSET."\"?>\n";
  7. }
  8. /**
  9. * 解析分类url路径
  10. */
  11. function list_url($typeid) {
  12. return WAP_SITEURL."&amp;a=lists&amp;typeid=$typeid";
  13. }
  14. function bigimg_url($url,$w='') {
  15. return WAP_SITEURL.'&amp;a=big_image&amp;url='.base64_encode($url).'&amp;w='.$w;
  16. }
  17. /**
  18. * 解析内容url路径
  19. * $catid 栏目id
  20. * $typeid wap分类id
  21. * $id 文章id
  22. */
  23. function show_url($catid, $id, $typeid='') {
  24. global $WAP;
  25. if($typeid=='') {
  26. $types = getcache('wap_type','wap');
  27. foreach ($types as $type) {
  28. if($type['cat']==$catid) {
  29. $typeid = $type['typeid'];
  30. break;
  31. }
  32. }
  33. }
  34. return WAP_SITEURL."&amp;a=show&amp;catid=$catid&amp;typeid=$typeid&amp;id=$id";
  35. }
  36. /**
  37. * 当前路径
  38. * 返回指定分类路径层级
  39. * @param $typeid 分类id
  40. * @param $symbol 分类间隔符
  41. */
  42. function wap_pos($typeid, $symbol=' > '){
  43. $type_arr = array();
  44. $type_arr = getcache('wap_type','wap');
  45. if(!isset($type_arr[$typeid])) return '';
  46. $pos = '';
  47. if($type_arr[$typeid]['parentid']!=0) {
  48. $pos = '<a href="'.list_url($type_arr[$typeid]['parentid']).'">'.$type_arr[$type_arr[$typeid]['parentid']]['typename'].'</a>'.$symbol;
  49. }
  50. $pos .= '<a href="'.list_url($typeid).'">'.$type_arr[$typeid]['typename'].'</a>'.$symbol;
  51. return $pos;
  52. }
  53. /**
  54. * 获取子分类
  55. */
  56. function subtype($parentid = NULL, $siteid = '') {
  57. if (empty($siteid)) $siteid = $GLOBALS['siteid'];
  58. $types = getcache('wap_type','wap');
  59. foreach($types as $id=>$type) {
  60. if($type['siteid'] == $siteid && ($parentid === NULL || $type['parentid'] == $parentid)) {
  61. $subtype[$id] = $type;;
  62. }
  63. }
  64. return $subtype;
  65. }
  66. /**
  67. * 分页函数
  68. *
  69. * @param $num 信息总数
  70. * @param $curr_page 当前分页
  71. * @param $perpage 每页显示数
  72. * @param $urlrule URL规则
  73. * @param $array 需要传递的数组,用于增加额外的方法
  74. * @return 分页
  75. */
  76. function wpa_pages($num, $curr_page, $perpage = 20, $urlrule = '', $array = array(),$setpages = 10) {
  77. if(defined('URLRULE')) {
  78. $urlrule = URLRULE;
  79. $array = $GLOBALS['URL_ARRAY'];
  80. } elseif($urlrule == '') {
  81. $urlrule = url_par('page={$page}');
  82. }
  83. $multipage = '';
  84. if($num > $perpage) {
  85. $page = $setpages+1;
  86. $offset = ceil($setpages/2-1);
  87. $pages = ceil($num / $perpage);
  88. if (defined('IN_ADMIN') && !defined('PAGES')) define('PAGES', $pages);
  89. $from = $curr_page - $offset;
  90. $to = $curr_page + $offset;
  91. $more = 0;
  92. if($page >= $pages) {
  93. $from = 2;
  94. $to = $pages-1;
  95. } else {
  96. if($from <= 1) {
  97. $to = $page-1;
  98. $from = 2;
  99. } elseif($to >= $pages) {
  100. $from = $pages-($page-2);
  101. $to = $pages-1;
  102. }
  103. $more = 1;
  104. }
  105. $multipage .= $curr_page.'/'.$pages;
  106. if($curr_page>0) {
  107. $multipage .= ' <a href="'.pageurl($urlrule, $curr_page-1, $array).'">'.L('previous').'</a>';
  108. }
  109. if($curr_page==$pages) {
  110. $multipage .= ' <a href="'.pageurl($urlrule, $curr_page, $array).'">'.L('next').'</a>';
  111. } else {
  112. $multipage .= ' <a href="'.pageurl($urlrule, $curr_page+1, $array).'">'.L('next').'</a>';
  113. }
  114. }
  115. return $multipage;
  116. }
  117. /**
  118. * 过滤内容为wml格式
  119. */
  120. function wml_strip($string) {
  121. $string = str_replace(array('&nbsp;', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;', '&'), array(' ', '&', '"', "'", '“', '”', '—', '{<}', '{>}', '·', '…', '&amp;'), $string);
  122. return str_replace(array('{<}', '{>}'), array('&lt;', '&gt;'), $string);
  123. }
  124. /**
  125. * 内容中图片替换
  126. */
  127. function content_strip($content,$ishow=1) {
  128. if($ishow!=1) $ishow=0;
  129. $content = preg_replace_callback('/<img[^>]*src=[\'"]?([^>\'"\s]*)[\'"]?[^>]*>/i', "wap_img_$ishow", $content);
  130. //匹配替换过的图片
  131. $content = strip_tags($content,'<b><br><img><p><div><a>');
  132. return $content;
  133. }
  134. /**
  135. * 图片过滤替换
  136. */
  137. function wap_img_1($matches) {
  138. return wap_img($matches[1],1);
  139. }
  140. function wap_img_0($matches) {
  141. return wap_img($matches[1],0);
  142. }
  143. function wap_img($url,$ishow) {
  144. $wap_site = getcache('wap_site','wap');
  145. $wap_setting = string2array($wap_site[$GLOBALS['siteid']]['setting']);
  146. $show_big = bigimg_url($url);
  147. if($ishow==1) $show_tips = '<br><a href="'.$show_big.'">浏览大图</a>';
  148. return '<img src="'.thumb($url,$wap_setting['thumb_w'],$wap_setting['thumb_h']).'">'.$show_tips;
  149. }
  150. function strip_selected_tags($text) {
  151. $tags = array('em','font','h1','h2','h3','h4','h5','h6','hr','i','ins','li','ol','p','pre','small','span','strike','strong','sub','sup','table','tbody','td','tfoot','th','thead','tr','tt','u','div','span');
  152. $args = func_get_args();
  153. $text = array_shift($args);
  154. $tags = func_num_args() > 2 ? array_diff($args,array($text)) : (array)$tags;
  155. foreach ($tags as $tag){
  156. if( preg_match_all( '/<'.$tag.'[^>]*>([^<]*)<\/'.$tag.'>/iu', $text, $found) ){
  157. $text = str_replace($found[0],$found[1],$text);
  158. }
  159. }
  160. return $text;
  161. }
  162. /**
  163. * 生成文章分页方法
  164. */
  165. function content_pages($num, $curr_page,$pageurls,$showremain = 1) {
  166. $multipage = '';
  167. $page = 11;
  168. $offset = 4;
  169. $pages = $num;
  170. $from = $curr_page - $offset;
  171. $to = $curr_page + $offset;
  172. $more = 0;
  173. if($page >= $pages) {
  174. $from = 2;
  175. $to = $pages-1;
  176. } else {
  177. if($from <= 1) {
  178. $to = $page-1;
  179. $from = 2;
  180. } elseif($to >= $pages) {
  181. $from = $pages-($page-2);
  182. $to = $pages-1;
  183. }
  184. $more = 1;
  185. }
  186. $multipage .='('.$curr_page.'/'.$num.')';
  187. if($curr_page>0) {
  188. $perpage = $curr_page == 1 ? 1 : $curr_page-1;
  189. $multipage .= '<a class="a1" href="'.$pageurls[$perpage][1].'">'.L('previous').'</a>';
  190. }
  191. if($curr_page<$pages) {
  192. if($curr_page<$pages-5 && $more) {
  193. $multipage .= ' <a class="a1" href="'.$pageurls[$curr_page+1][1].'">'.L('next').'</a>';
  194. } else {
  195. $multipage .= ' <a class="a1" href="'.$pageurls[$curr_page+1][1].'">'.L('next').'</a>';
  196. }
  197. } elseif($curr_page==$pages) {
  198. $multipage .= ' <a class="a1" href="'.$pageurls[$curr_page][1].'">'.L('next').'</a>';
  199. }
  200. if($showremain) $multipage .="| <a href='".$pageurls[$curr_page][1]."&remains=true'>剩余全文</a>";
  201. return $multipage;
  202. }
  203. /**
  204. * 多图分页处理
  205. */
  206. function pic_pages($array) {
  207. if(!is_array($array) || empty($array)) return false;
  208. foreach ($array as $k=>$p) {
  209. $photo_arr[$k]='<img src="'.$p['url'].'"><br>'.$p['alt'];
  210. }
  211. $photo_page = @implode('[page]', $photo_arr);
  212. $photo_page =content_strip(wml_strip($photo_page),0);
  213. return $photo_page;
  214. }
  215. /**
  216. * 获取热词
  217. */
  218. function hotword() {
  219. $site = getcache('wap_site','wap');
  220. $setting = string2array($site[$GLOBALS['siteid']]['setting']);
  221. $hotword = $setting['hotwords'];
  222. $hotword_arr = explode("\n", $hotword);
  223. if(is_array($hotword_arr) && count($hotword_arr) > 0) {
  224. foreach($hotword_arr as $_k) {
  225. $v = explode("|",$_k);
  226. $hotword_string .= '<a href="'.$v[1].'">'.$v[0].'</a>&nbsp';
  227. }
  228. }
  229. return $hotword_string;
  230. }
  231. ?>