首页 > 编程语言 >PHPcms分页实现多种效果

PHPcms分页实现多种效果

时间:2022-11-10 10:36:36浏览次数:48  
标签:function return 分页 效果 param PHPcms str array string

   2022-11-10   phpcms修改分页实现多种效果"首页、上一页、页码数、下一页、末页、共X页、共X条"等,根据自己实际需要来进行更改。
  实现代码在776行左右
1 <?php 2 /** 3 * global.func.php 公共函数库 4 * 5 * @copyright (C) 2005-2010 PHPCMS 6 * @license http://www.phpcms.cn/license/ 7 * @lastmodify 2010-6-1 8 */ 9 10 /** 11 * 返回经addslashes处理过的字符串或数组 12 * @param $string 需要处理的字符串或数组 13 * @return mixed 14 */ 15 function new_addslashes($string){ 16 if(!is_array($string)) return addslashes($string); 17 foreach($string as $key => $val) $string[$key] = new_addslashes($val); 18 return $string; 19 } 20 21 /** 22 * 返回经stripslashes处理过的字符串或数组 23 * @param $string 需要处理的字符串或数组 24 * @return mixed 25 */ 26 function new_stripslashes($string) { 27 if(!is_array($string)) return stripslashes($string); 28 foreach($string as $key => $val) $string[$key] = new_stripslashes($val); 29 return $string; 30 } 31 32 /** 33 * 返回经htmlspecialchars处理过的字符串或数组 34 * @param $obj 需要处理的字符串或数组 35 * @return mixed 36 */ 37 function new_html_special_chars($string) { 38 $encoding = 'utf-8'; 39 if(strtolower(CHARSET)=='gbk') $encoding = 'ISO-8859-15'; 40 if(!is_array($string)) return htmlspecialchars($string,ENT_QUOTES,$encoding); 41 foreach($string as $key => $val) $string[$key] = new_html_special_chars($val); 42 return $string; 43 } 44 45 function new_html_entity_decode($string) { 46 $encoding = 'utf-8'; 47 if(strtolower(CHARSET)=='gbk') $encoding = 'ISO-8859-15'; 48 return html_entity_decode($string,ENT_QUOTES,$encoding); 49 } 50 51 function new_htmlentities($string) { 52 $encoding = 'utf-8'; 53 if(strtolower(CHARSET)=='gbk') $encoding = 'ISO-8859-15'; 54 return htmlentities($string,ENT_QUOTES,$encoding); 55 } 56 57 /** 58 * 安全过滤函数 59 * 60 * @param $string 61 * @return string 62 */ 63 function safe_replace($string) { 64 $string = str_replace('%20','',$string); 65 $string = str_replace('%27','',$string); 66 $string = str_replace('%2527','',$string); 67 $string = str_replace('*','',$string); 68 $string = str_replace('"','&quot;',$string); 69 $string = str_replace("'",'',$string); 70 $string = str_replace('"','',$string); 71 $string = str_replace(';','',$string); 72 $string = str_replace('<','&lt;',$string); 73 $string = str_replace('>','&gt;',$string); 74 $string = str_replace("{",'',$string); 75 $string = str_replace('}','',$string); 76 $string = str_replace('\\','',$string); 77 return $string; 78 } 79 80 /** 81 * xss过滤函数 82 * 83 * @param $string 84 * @return string 85 */ 86 function remove_xss($string) { 87 $string = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S', '', $string); 88 89 $parm1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base'); 90 91 $parm2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload'); 92 93 $parm = array_merge($parm1, $parm2); 94 95 for ($i = 0; $i < sizeof($parm); $i++) { 96 $pattern = '/'; 97 for ($j = 0; $j < strlen($parm[$i]); $j++) { 98 if ($j > 0) { 99 $pattern .= '('; 100 $pattern .= '(&#[x|X]0([9][a][b]);?)?'; 101 $pattern .= '|(&#0([9][10][13]);?)?'; 102 $pattern .= ')?'; 103 } 104 $pattern .= $parm[$i][$j]; 105 } 106 $pattern .= '/i'; 107 $string = preg_replace($pattern, ' ', $string); 108 } 109 return $string; 110 } 111 112 /** 113 * 过滤ASCII码从0-28的控制字符 114 * @return String 115 */ 116 function trim_unsafe_control_chars($str) { 117 $rule = '/[' . chr ( 1 ) . '-' . chr ( 8 ) . chr ( 11 ) . '-' . chr ( 12 ) . chr ( 14 ) . '-' . chr ( 31 ) . ']*/'; 118 return str_replace ( chr ( 0 ), '', preg_replace ( $rule, '', $str ) ); 119 } 120 121 /** 122 * 格式化文本域内容 123 * 124 * @param $string 文本域内容 125 * @return string 126 */ 127 function trim_textarea($string) { 128 $string = nl2br ( str_replace ( ' ', '&nbsp;', $string ) ); 129 return $string; 130 } 131 132 /** 133 * 将文本格式成适合js输出的字符串 134 * @param string $string 需要处理的字符串 135 * @param intval $isjs 是否执行字符串格式化,默认为执行 136 * @return string 处理后的字符串 137 */ 138 function format_js($string, $isjs = 1) { 139 $string = addslashes(str_replace(array("\r", "\n", "\t"), array('', '', ''), $string)); 140 return $isjs ? 'document.write("'.$string.'");' : $string; 141 } 142 143 /** 144 * 转义 javascript 代码标记 145 * 146 * @param $str 147 * @return mixed 148 */ 149 function trim_script($str) { 150 if(is_array($str)){ 151 foreach ($str as $key => $val){ 152 $str[$key] = trim_script($val); 153 } 154 }else{ 155 $str = preg_replace ( '/\<([\/]?)script([^\>]*?)\>/si', '&lt;\\1script\\2&gt;', $str ); 156 $str = preg_replace ( '/\<([\/]?)iframe([^\>]*?)\>/si', '&lt;\\1iframe\\2&gt;', $str ); 157 $str = preg_replace ( '/\<([\/]?)frame([^\>]*?)\>/si', '&lt;\\1frame\\2&gt;', $str ); 158 $str = str_replace ( 'javascript:', 'javascript:', $str ); 159 } 160 return $str; 161 } 162 /** 163 * 获取当前页面完整URL地址 164 */ 165 function get_url() { 166 $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://'; 167 $php_self = $_SERVER['PHP_SELF'] ? safe_replace($_SERVER['PHP_SELF']) : safe_replace($_SERVER['SCRIPT_NAME']); 168 $path_info = isset($_SERVER['PATH_INFO']) ? safe_replace($_SERVER['PATH_INFO']) : ''; 169 $relate_url = isset($_SERVER['REQUEST_URI']) ? safe_replace($_SERVER['REQUEST_URI']) : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.safe_replace($_SERVER['QUERY_STRING']) : $path_info); 170 return $sys_protocal.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '').$relate_url; 171 } 172 /** 173 * 字符截取 支持UTF8/GBK 174 * @param $string 175 * @param $length 176 * @param $dot 177 */ 178 function str_cut($string, $length, $dot = '...') { 179 $strlen = strlen($string); 180 if($strlen <= $length) return $string; 181 $string = str_replace(array(' ','&nbsp;', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), array('∵',' ', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), $string); 182 $strcut = ''; 183 if(strtolower(CHARSET) == 'utf-8') { 184 $length = intval($length-strlen($dot)-$length/3); 185 $n = $tn = $noc = 0; 186 while($n < strlen($string)) { 187 $t = ord($string[$n]); 188 if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) { 189 $tn = 1; $n++; $noc++; 190 } elseif(194 <= $t && $t <= 223) { 191 $tn = 2; $n += 2; $noc += 2; 192 } elseif(224 <= $t && $t <= 239) { 193 $tn = 3; $n += 3; $noc += 2; 194 } elseif(240 <= $t && $t <= 247) { 195 $tn = 4; $n += 4; $noc += 2; 196 } elseif(248 <= $t && $t <= 251) { 197 $tn = 5; $n += 5; $noc += 2; 198 } elseif($t == 252 || $t == 253) { 199 $tn = 6; $n += 6; $noc += 2; 200 } else { 201 $n++; 202 } 203 if($noc >= $length) { 204 break; 205 } 206 } 207 if($noc > $length) { 208 $n -= $tn; 209 } 210 $strcut = substr($string, 0, $n); 211 $strcut = str_replace(array('∵', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), array(' ', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), $strcut); 212 } else { 213 $dotlen = strlen($dot); 214 $maxi = $length - $dotlen - 1; 215 $current_str = ''; 216 $search_arr = array('&',' ', '"', "'", '“', '”', '—', '<', '>', '·', '…','∵'); 217 $replace_arr = array('&amp;','&nbsp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;',' '); 218 $search_flip = array_flip($search_arr); 219 for ($i = 0; $i < $maxi; $i++) { 220 $current_str = ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i]; 221 if (in_array($current_str, $search_arr)) { 222 $key = $search_flip[$current_str]; 223 $current_str = str_replace($search_arr[$key], $replace_arr[$key], $current_str); 224 } 225 $strcut .= $current_str; 226 } 227 } 228 return $strcut.$dot; 229 } 230 231 232 233 /** 234 * 获取请求ip 235 * 236 * @return ip地址 237 */ 238 function ip() { 239 if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) { 240 $ip = getenv('HTTP_CLIENT_IP'); 241 } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) { 242 $ip = getenv('HTTP_X_FORWARDED_FOR'); 243 } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) { 244 $ip = getenv('REMOTE_ADDR'); 245 } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) { 246 $ip = $_SERVER['REMOTE_ADDR']; 247 } 248 return preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : ''; 249 } 250 251 function get_cost_time() { 252 $microtime = microtime ( TRUE ); 253 return $microtime - SYS_START_TIME; 254 } 255 /** 256 * 程序执行时间 257 * 258 * @return int 单位ms 259 */ 260 function execute_time() { 261 $stime = explode ( ' ', SYS_START_TIME ); 262 $etime = explode ( ' ', microtime () ); 263 return number_format ( ($etime [1] + $etime [0] - $stime [1] - $stime [0]), 6 ); 264 } 265 266 /** 267 * 产生随机字符串 268 * 269 * @param int $length 输出长度 270 * @param string $chars 可选的 ,默认为 0123456789 271 * @return string 字符串 272 */ 273 function random($length, $chars = '0123456789') { 274 $hash = ''; 275 $max = strlen($chars) - 1; 276 mt_srand(); 277 for($i = 0; $i < $length; $i++) { 278 $hash .= $chars[mt_rand(0, $max)]; 279 } 280 return $hash; 281 } 282 283 /** 284 * 将字符串转换为数组 285 * 286 * @param string $data 字符串 287 * @return array 返回数组格式,如果,data为空,则返回空数组 288 */ 289 function string2array($data) { 290 $data = trim($data); 291 if($data == '') return array(); 292 if(strpos($data, 'array')===0){ 293 @eval("\$array = $data;"); 294 }else{ 295 if(strpos($data, '{\\')===0) $data = stripslashes($data); 296 $array=json_decode($data,true); 297 if(strtolower(CHARSET)=='gbk'){ 298 $array = mult_iconv("UTF-8", "GBK//IGNORE", $array); 299 } 300 } 301 return $array; 302 } 303 /** 304 * 将数组转换为字符串 305 * 306 * @param array $data 数组 307 * @param bool $isformdata 如果为0,则不使用new_stripslashes处理,可选参数,默认为1 308 * @return string 返回字符串,如果,data为空,则返回空 309 */ 310 function array2string($data, $isformdata = 1) { 311 if($data == '' || empty($data)) return ''; 312 313 if($isformdata) $data = new_stripslashes($data); 314 if(strtolower(CHARSET)=='gbk'){ 315 $data = mult_iconv("GBK", "UTF-8", $data); 316 } 317 if (version_compare(PHP_VERSION,'5.3.0','<')){ 318 return addslashes(json_encode($data)); 319 }else{ 320 return addslashes(json_encode($data,JSON_FORCE_OBJECT)); 321 } 322 } 323 /** 324 * 数组转码 325 * 326 */ 327 function mult_iconv($in_charset,$out_charset,$data){ 328 if(substr($out_charset,-8)=='//IGNORE'){ 329 $out_charset=substr($out_charset,0,-8); 330 } 331 if(is_array($data)){ 332 foreach($data as $key => $value){ 333 if(is_array($value)){ 334 $key=iconv($in_charset,$out_charset.'//IGNORE',$key); 335 $rtn[$key]=mult_iconv($in_charset,$out_charset,$value); 336 }elseif(is_string($key) || is_string($value)){ 337 if(is_string($key)){ 338 $key=iconv($in_charset,$out_charset.'//IGNORE',$key); 339 } 340 if(is_string($value)){ 341 $value=iconv($in_charset,$out_charset.'//IGNORE',$value); 342 } 343 $rtn[$key]=$value; 344 }else{ 345 $rtn[$key]=$value; 346 } 347 } 348 }elseif(is_string($data)){ 349 $rtn=iconv($in_charset,$out_charset.'//IGNORE',$data); 350 }else{ 351 $rtn=$data; 352 } 353 return $rtn; 354 } 355 356 /** 357 * 转换字节数为其他单位 358 * 359 * 360 * @param string $filesize 字节大小 361 * @return string 返回大小 362 */ 363 function sizecount($filesize) { 364 if ($filesize >= 1073741824) { 365 $filesize = round($filesize / 1073741824 * 100) / 100 .' GB'; 366 } elseif ($filesize >= 1048576) { 367 $filesize = round($filesize / 1048576 * 100) / 100 .' MB'; 368 } elseif($filesize >= 1024) { 369 $filesize = round($filesize / 1024 * 100) / 100 . ' KB'; 370 } else { 371 $filesize = $filesize.' Bytes'; 372 } 373 return $filesize; 374 } 375 /** 376 * 字符串加密、解密函数 377 * 378 * 379 * @param string $txt 字符串 380 * @param string $operation ENCODE为加密,DECODE为解密,可选参数,默认为ENCODE, 381 * @param string $key 密钥:数字、字母、下划线 382 * @param string $expiry 过期时间 383 * @return string 384 */ 385 function sys_auth($string, $operation = 'ENCODE', $key = '', $expiry = 0) { 386 $ckey_length = 4; 387 $key = md5($key != '' ? $key : pc_base::load_config('system', 'auth_key')); 388 $keya = md5(substr($key, 0, 16)); 389 $keyb = md5(substr($key, 16, 16)); 390 $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : ''; 391 392 $cryptkey = $keya.md5($keya.$keyc); 393 $key_length = strlen($cryptkey); 394 395 $string = $operation == 'DECODE' ? base64_decode(strtr(substr($string, $ckey_length), '-_', '+/')) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string; 396 $string_length = strlen($string); 397 398 $result = ''; 399 $box = range(0, 255); 400 401 $rndkey = array(); 402 for($i = 0; $i <= 255; $i++) { 403 $rndkey[$i] = ord($cryptkey[$i % $key_length]); 404 } 405 406 for($j = $i = 0; $i < 256; $i++) { 407 $j = ($j + $box[$i] + $rndkey[$i]) % 256; 408 $tmp = $box[$i]; 409 $box[$i] = $box[$j]; 410 $box[$j] = $tmp; 411 } 412 413 for($a = $j = $i = 0; $i < $string_length; $i++) { 414 $a = ($a + 1) % 256; 415 $j = ($j + $box[$a]) % 256; 416 $tmp = $box[$a]; 417 $box[$a] = $box[$j]; 418 $box[$j] = $tmp; 419 $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); 420 } 421 422 if($operation == 'DECODE') { 423 if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) { 424 return substr($result, 26); 425 } else { 426 return ''; 427 } 428 } else { 429 return $keyc.rtrim(strtr(base64_encode($result), '+/', '-_'), '='); 430 } 431 } 432 /** 433 * 语言文件处理 434 * 435 * @param string $language 标示符 436 * @param array $pars 转义的数组,二维数组 ,'key1'=>'value1','key2'=>'value2', 437 * @param string $modules 多个模块之间用半角逗号隔开,如:member,guestbook 438 * @return string 语言字符 439 */ 440 function L($language = 'no_language',$pars = array(), $modules = '') { 441 static $LANG = array(); 442 static $LANG_MODULES = array(); 443 static $lang = ''; 444 if(defined('IN_ADMIN')) { 445 $lang = SYS_STYLE ? SYS_STYLE : 'zh-cn'; 446 } else { 447 $lang = pc_base::load_config('system','lang'); 448 } 449 if(!$LANG) { 450 require_once PC_PATH.'languages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.'system.lang.php'; 451 if(defined('IN_ADMIN')) require_once PC_PATH.'languages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.'system_menu.lang.php'; 452 if(file_exists(PC_PATH.'languages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.ROUTE_M.'.lang.php')) require_once PC_PATH.'languages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.ROUTE_M.'.lang.php'; 453 } 454 if(!empty($modules)) { 455 $modules = explode(',',$modules); 456 foreach($modules AS $m) { 457 if(!isset($LANG_MODULES[$m])) require_once PC_PATH.'languages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.$m.'.lang.php'; 458 } 459 } 460 if(!array_key_exists($language,$LANG)) { 461 return $language; 462 } else { 463 $language = $LANG[$language]; 464 if($pars) { 465 foreach($pars AS $_k=>$_v) { 466 $language = str_replace('{'.$_k.'}',$_v,$language); 467 } 468 } 469 return $language; 470 } 471 } 472 473 /** 474 * 模板调用 475 * 476 * @param $module 477 * @param $template 478 * @param $istag 479 * @return unknown_type 480 */ 481 function template($module = 'content', $template = 'index', $style = '') { 482 483 if(strpos($module, 'plugin/')!== false) { 484 $plugin = str_replace('plugin/', '', $module); 485 return p_template($plugin, $template,$style); 486 } 487 $module = str_replace('/', DIRECTORY_SEPARATOR, $module); 488 if(!empty($style) && preg_match('/([a-z0-9\-_]+)/is',$style)) { 489 } elseif (empty($style) && !defined('STYLE')) { 490 if(defined('SITEID')) { 491 $siteid = SITEID; 492 } else { 493 $siteid = param::get_cookie('siteid'); 494 } 495 if (!$siteid) $siteid = 1; 496 $sitelist = getcache('sitelist','commons'); 497 if(!empty($siteid)) { 498 $style = $sitelist[$siteid]['default_style']; 499 } 500 } elseif (empty($style) && defined('STYLE')) { 501 $style = STYLE; 502 } else { 503 $style = 'default'; 504 } 505 if(!$style) $style = 'default'; 506 $template_cache = pc_base::load_sys_class('template_cache'); 507 $compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.php'; 508 if(file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html')) { 509 if(!file_exists($compiledtplfile) || (@filemtime(PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') > @filemtime($compiledtplfile))) { 510 $template_cache->template_compile($module, $template, $style); 511 } 512 } else { 513 $compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.php'; 514 if(!file_exists($compiledtplfile) || (file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') && filemtime(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') > filemtime($compiledtplfile))) { 515 $template_cache->template_compile($module, $template, 'default'); 516 } elseif (!file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html')) { 517 showmessage('Template does not exist.'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html'); 518 } 519 } 520 return $compiledtplfile; 521 } 522 523 /** 524 * 输出自定义错误 525 * 526 * @param $errno 错误号 527 * @param $errstr 错误描述 528 * @param $errfile 报错文件地址 529 * @param $errline 错误行号 530 * @return string 错误提示 531 */ 532 533 function my_error_handler($errno, $errstr, $errfile, $errline) { 534 if($errno==8) return ''; 535 $errfile = str_replace(PHPCMS_PATH,'',$errfile); 536 if(pc_base::load_config('system','errorlog')) { 537 error_log('<?php exit;?>'.date('m-d H:i:s',SYS_TIME).' | '.$errno.' | '.str_pad($errstr,30).' | '.$errfile.' | '.$errline."\r\n", 3, CACHE_PATH.'error_log.php'); 538 } else { 539 $str = '<div style="font-size:12px;text-align:left; border-bottom:1px solid #9cc9e0; border-right:1px solid #9cc9e0;padding:1px 4px;color:#000000;font-family:Arial, Helvetica,sans-serif;"><span>errorno:' . $errno . ',str:' . $errstr . ',file:<font color="blue">' . $errfile . '</font>,line' . $errline .'<br /><a href="http://faq.phpcms.cn/?type=file&errno='.$errno.'&errstr='.urlencode($errstr).'&errfile='.urlencode($errfile).'&errline='.$errline.'" target="_blank" style="color:red">Need Help?</a></span></div>'; 540 echo $str; 541 } 542 } 543 544 /** 545 * 提示信息页面跳转,跳转地址如果传入数组,页面会提示多个地址供用户选择,默认跳转地址为数组的第一个值,时间为5秒。 546 * showmessage('登录成功', array('默认跳转地址'=>'http://www.phpcms.cn')); 547 * @param string $msg 提示信息 548 * @param mixed(string/array) $url_forward 跳转地址 549 * @param int $ms 跳转等待时间 550 */ 551 function showmessage($msg, $url_forward = 'goback', $ms = 1250, $dialog = '', $returnjs = '') { 552 if(defined('IN_ADMIN')) { 553 include(admin::admin_tpl('showmessage', 'admin')); 554 } else { 555 include(template('content', 'message')); 556 } 557 exit; 558 } 559 /** 560 * 查询字符是否存在于某字符串 561 * 562 * @param $haystack 字符串 563 * @param $needle 要查找的字符 564 * @return bool 565 */ 566 function str_exists($haystack, $needle) 567 { 568 return !(strpos($haystack, $needle) === FALSE); 569 } 570 571 /** 572 * 取得文件扩展 573 * 574 * @param $filename 文件名 575 * @return 扩展名 576 */ 577 function fileext($filename) { 578 return strtolower(trim(substr(strrchr($filename, '.'), 1, 10))); 579 } 580 581 /** 582 * 加载模板标签缓存 583 * @param string $name 缓存名 584 * @param integer $times 缓存时间 585 */ 586 function tpl_cache($name,$times = 0) { 587 $filepath = 'tpl_data'; 588 $info = getcacheinfo($name, $filepath); 589 if (SYS_TIME - $info['filemtime'] >= $times) { 590 return false; 591 } else { 592 return getcache($name,$filepath); 593 } 594 } 595 596 /** 597 * 写入缓存,默认为文件缓存,不加载缓存配置。 598 * @param $name 缓存名称 599 * @param $data 缓存数据 600 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/ 601 * @param $type 缓存类型[file,memcache,apc] 602 * @param $config 配置名称 603 * @param $timeout 过期时间 604 */ 605 function setcache($name, $data, $filepath='', $type='file', $config='', $timeout=0) { 606 if(!preg_match("/^[a-zA-Z0-9_-]+$/", $name)) return false; 607 if($filepath!="" && !preg_match("/^[a-zA-Z0-9_-]+$/", $filepath)) return false; 608 pc_base::load_sys_class('cache_factory','',0); 609 if($config) { 610 $cacheconfig = pc_base::load_config('cache'); 611 $cache = cache_factory::get_instance($cacheconfig)->get_cache($config); 612 } else { 613 $cache = cache_factory::get_instance()->get_cache($type); 614 } 615 616 return $cache->set($name, $data, $timeout, '', $filepath); 617 } 618 619 /** 620 * 读取缓存,默认为文件缓存,不加载缓存配置。 621 * @param string $name 缓存名称 622 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/ 623 * @param string $config 配置名称 624 */ 625 function getcache($name, $filepath='', $type='file', $config='') { 626 if(!preg_match("/^[a-zA-Z0-9_-]+$/", $name)) return false; 627 if($filepath!="" && !preg_match("/^[a-zA-Z0-9_-]+$/", $filepath)) return false; 628 pc_base::load_sys_class('cache_factory','',0); 629 if($config) { 630 $cacheconfig = pc_base::load_config('cache'); 631 $cache = cache_factory::get_instance($cacheconfig)->get_cache($config); 632 } else { 633 $cache = cache_factory::get_instance()->get_cache($type); 634 } 635 return $cache->get($name, '', '', $filepath); 636 } 637 638 /** 639 * 删除缓存,默认为文件缓存,不加载缓存配置。 640 * @param $name 缓存名称 641 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/ 642 * @param $type 缓存类型[file,memcache,apc] 643 * @param $config 配置名称 644 */ 645 function delcache($name, $filepath='', $type='file', $config='') { 646 if(!preg_match("/^[a-zA-Z0-9_-]+$/", $name)) return false; 647 if($filepath!="" && !preg_match("/^[a-zA-Z0-9_-]+$/", $filepath)) return false; 648 pc_base::load_sys_class('cache_factory','',0); 649 if($config) { 650 $cacheconfig = pc_base::load_config('cache'); 651 $cache = cache_factory::get_instance($cacheconfig)->get_cache($config); 652 } else { 653 $cache = cache_factory::get_instance()->get_cache($type); 654 } 655 return $cache->delete($name, '', '', $filepath); 656 } 657 658 /** 659 * 读取缓存,默认为文件缓存,不加载缓存配置。 660 * @param string $name 缓存名称 661 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/ 662 * @param string $config 配置名称 663 */ 664 function getcacheinfo($name, $filepath='', $type='file', $config='') { 665 if(!preg_match("/^[a-zA-Z0-9_-]+$/", $name)) return false; 666 if($filepath!="" && !preg_match("/^[a-zA-Z0-9_-]+$/", $filepath)) return false; 667 pc_base::load_sys_class('cache_factory'); 668 if($config) { 669 $cacheconfig = pc_base::load_config('cache'); 670 $cache = cache_factory::get_instance($cacheconfig)->get_cache($config); 671 } else { 672 $cache = cache_factory::get_instance()->get_cache($type); 673 } 674 return $cache->cacheinfo($name, '', '', $filepath); 675 } 676 677 /** 678 * 生成sql语句,如果传入$in_cloumn 生成格式为 IN('a', 'b', 'c') 679 * @param $data 条件数组或者字符串 680 * @param $front 连接符 681 * @param $in_column 字段名称 682 * @return string 683 */ 684 function to_sqls($data, $front = ' AND ', $in_column = false) { 685 if($in_column && is_array($data)) { 686 $ids = '\''.implode('\',\'', $data).'\''; 687 $sql = "$in_column IN ($ids)"; 688 return $sql; 689 } else { 690 if ($front == '') { 691 $front = ' AND '; 692 } 693 if(is_array($data) && count($data) > 0) { 694 $sql = ''; 695 foreach ($data as $key => $val) { 696 $sql .= $sql ? " $front `$key` = '$val' " : " `$key` = '$val' "; 697 } 698 return $sql; 699 } else { 700 return $data; 701 } 702 } 703 } 704 705 /** 706 * 分页函数 707 * 708 * @param $num 信息总数 709 * @param $curr_page 当前分页 710 * @param $perpage 每页显示数 711 * @param $urlrule URL规则 712 * @param $array 需要传递的数组,用于增加额外的方法 713 * @return 分页 714 */ 715 function pages($num, $curr_page, $perpage = 20, $urlrule = '', $array = array(),$setpages = 3) { 716 if(defined('URLRULE') && $urlrule == '') { 717 $urlrule = URLRULE; 718 $array = $GLOBALS['URL_ARRAY']; 719 } elseif($urlrule == '') { 720 $urlrule = url_par('page={$page}'); 721 } 722 $multipage = ''; 723 if($num > $perpage) { 724 $page = $setpages+1; 725 $offset = ceil($setpages/2-1); 726 $pages = ceil($num / $perpage); 727 if (defined('IN_ADMIN') && !defined('PAGES')) define('PAGES', $pages); 728 $from = $curr_page - $offset; 729 $to = $curr_page + $offset; 730 $more = 0; 731 if($page >= $pages) { 732 $from = 2; 733 $to = $pages-1; 734 } else { 735 if($from <= 1) { 736 $to = $page-1; 737 $from = 2; 738 } elseif($to >= $pages) { 739 $from = $pages-($page-2); 740 $to = $pages-1; 741 } 742 $more = 1; 743 } 744 745 $multipage .= ' <a href="'.pageurl($urlrule, 1, $array).'">首页</a>'; 746 747 if($curr_page>0) { 748 $multipage .= ' <a href="'.pageurl($urlrule, $curr_page-1, $array).'" class="a1">'.L('previous').'</a>'; 749 if($curr_page==1) { 750 $multipage .= '<span style="color:red;font-size:18px;font-weight:600">1</span>'; 751 } elseif($curr_page>6 && $more) { 752 $multipage .= ' <a href="'.pageurl($urlrule, 1, $array).'">1</a>..'; 753 } else { 754 $multipage .= ' <a href="'.pageurl($urlrule, 1, $array).'">1</a>'; 755 } 756 } 757 for($i = $from; $i <= $to; $i++) { 758 if($i != $curr_page) { 759 $multipage .= ' <a href="'.pageurl($urlrule, $i, $array).'">'.$i.'</a>'; 760 } else { 761 $multipage .= ' <span style="color:red;font-size:18px;font-weight:600">'.$i.'</span>'; 762 } 763 } 764 if($curr_page<$pages) { 765 if($curr_page<$pages-5 && $more) { 766 $multipage .= ' ..<a href="'.pageurl($urlrule, $pages, $array).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $array).'" class="a1">'.L('next').'</a>'; 767 } else { 768 $multipage .= ' <a href="'.pageurl($urlrule, $pages, $array).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $array).'" class="a1">'.L('next').'</a>'; 769 } 770 } elseif($curr_page==$pages) { 771 $multipage .= ' <span style="color:red;font-size:18px;font-weight:600">'.$pages.'</span> <a href="'.pageurl($urlrule, $curr_page, $array).'" class="a1">'.L('next').'</a>'; 772 } else { 773 $multipage .= ' <a href="'.pageurl($urlrule, $pages, $array).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $array).'" class="a1">'.L('next').'</a>'; 774 } 775 776 $moye=ceil($num/$perpage); 777 $multipage .= ' <a style="margin-left:10px;" href="'.pageurl($urlrule, $moye, $array).'">末页</a>'; 778 //$multipage .= '<a class="a1">当前页数'.$curr_page.'</a>'; 779 $multipage .= '<a class="a1" style="font-weight:600;margin-left: 10px;">共'.$moye.'页</a>'; 780 //$multipage .= ' <br/>'; 781 //$multipage .= '<a class="a1">每页'.$perpage.'数据</a>'; 782 $multipage .= '<a class="a1" style="font-weight:600;float:right;">共'.$num.L('page_item').'</a>'; 783 } 784 return $multipage; 785 } 786 /** 787 * 返回分页路径 788 * 789 * @param $urlrule 分页规则 790 * @param $page 当前页 791 * @param $array 需要传递的数组,用于增加额外的方法 792 * @return 完整的URL路径 793 */ 794 function pageurl($urlrule, $page, $array = array()) { 795 if(strpos($urlrule, '~')) { 796 $urlrules = explode('~', $urlrule); 797 $urlrule = $page < 2 ? $urlrules[0] : $urlrules[1]; 798 } 799 $findme = array('{$page}'); 800 $replaceme = array($page); 801 if (is_array($array)) foreach ($array as $k=>$v) { 802 $findme[] = '{$'.$k.'}'; 803 $replaceme[] = $v; 804 } 805 $url = str_replace($findme, $replaceme, $urlrule); 806 $url = str_replace(array('http://','//','~'), array('~','/','http://'), $url); 807 return $url; 808 } 809 810 /** 811 * URL路径解析,pages 函数的辅助函数 812 * 813 * @param $par 传入需要解析的变量 默认为,page={$page} 814 * @param $url URL地址 815 * @return URL 816 */ 817 function url_par($par, $url = '') { 818 if($url == '') $url = get_url(); 819 $pos = strpos($url, '?'); 820 if($pos === false) { 821 $url .= '?'.$par; 822 } else { 823 $querystring = substr(strstr($url, '?'), 1); 824 parse_str($querystring, $pars); 825 $query_array = array(); 826 foreach($pars as $k=>$v) { 827 if($k != 'page') $query_array[$k] = $v; 828 } 829 $querystring = http_build_query($query_array).'&'.$par; 830 $url = substr($url, 0, $pos).'?'.$querystring; 831 } 832 return $url; 833 } 834 835 /** 836 * 判断email格式是否正确 837 * @param $email 838 */ 839 function is_email($email) { 840 return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email); 841 } 842 843 /** 844 * iconv 编辑转换 845 */ 846 if (!function_exists('iconv')) { 847 function iconv($in_charset, $out_charset, $str) { 848 $in_charset = strtoupper($in_charset); 849 $out_charset = strtoupper($out_charset); 850 if (function_exists('mb_convert_encoding')) { 851 return mb_convert_encoding($str, $out_charset, $in_charset); 852 } else { 853 pc_base::load_sys_func('iconv'); 854 $in_charset = strtoupper($in_charset); 855 $out_charset = strtoupper($out_charset); 856 if ($in_charset == 'UTF-8' && ($out_charset == 'GBK' || $out_charset == 'GB2312')) { 857 return utf8_to_gbk($str); 858 } 859 if (($in_charset == 'GBK' || $in_charset == 'GB2312') && $out_charset == 'UTF-8') { 860 return gbk_to_utf8($str); 861 } 862 return $str; 863 } 864 } 865 } 866 867 /** 868 * 代码广告展示函数 869 * @param intval $siteid 所属站点 870 * @param intval $id 广告ID 871 * @return 返回广告代码 872 */ 873 function show_ad($siteid, $id) { 874 $siteid = intval($siteid); 875 $id = intval($id); 876 if(!$id || !$siteid) return false; 877 $p = pc_base::load_model('poster_model'); 878 $r = $p->get_one(array('spaceid'=>$id, 'siteid'=>$siteid), 'disabled, setting', '`id` ASC'); 879 if ($r['disabled']) return ''; 880 if ($r['setting']) { 881 $c = string2array($r['setting']); 882 } else { 883 $r['code'] = ''; 884 } 885 return $c['code']; 886 } 887 888 /** 889 * 获取当前的站点ID 890 */ 891 function get_siteid() { 892 static $siteid; 893 if (!empty($siteid)) return $siteid; 894 if (defined('IN_ADMIN')) { 895 if ($d = param::get_cookie('siteid')) { 896 $siteid = $d; 897 } else { 898 return ''; 899 } 900 } else { 901 $data = getcache('sitelist', 'commons'); 902 if(!is_array($data)) return '1'; 903 $site_url = SITE_PROTOCOL.SITE_URL; 904 foreach ($data as $v) { 905 if ($v['url'] == $site_url.'/') $siteid = $v['siteid']; 906 } 907 } 908 if (empty($siteid)) $siteid = 1; 909 return $siteid; 910 } 911 912 /** 913 * 获取用户昵称 914 * 不传入userid取当前用户nickname,如果nickname为空取username 915 * 传入field,取用户$field字段信息 916 */ 917 function get_nickname($userid='', $field='') { 918 $return = ''; 919 if(is_numeric($userid)) { 920 $member_db = pc_base::load_model('member_model'); 921 $memberinfo = $member_db->get_one(array('userid'=>$userid)); 922 if(!empty($field) && $field != 'nickname' && isset($memberinfo[$field]) &&!empty($memberinfo[$field])) { 923 $return = $memberinfo[$field]; 924 } else { 925 $return = isset($memberinfo['nickname']) && !empty($memberinfo['nickname']) ? $memberinfo['nickname'].'('.$memberinfo['username'].')' : $memberinfo['username']; 926 } 927 } else { 928 if (param::get_cookie('_nickname')) { 929 $return .= '('.param::get_cookie('_nickname').')'; 930 } else { 931 $return .= '('.param::get_cookie('_username').')'; 932 } 933 } 934 return $return; 935 } 936 937 /** 938 * 获取用户信息 939 * 不传入$field返回用户所有信息, 940 * 传入field,取用户$field字段信息 941 */ 942 function get_memberinfo($userid, $field='') { 943 if(!is_numeric($userid)) { 944 return false; 945 } else { 946 static $memberinfo; 947 if (!isset($memberinfo[$userid])) { 948 $member_db = pc_base::load_model('member_model'); 949 $memberinfo[$userid] = $member_db->get_one(array('userid'=>$userid)); 950 } 951 if(!empty($field) && !empty($memberinfo[$userid][$field])) { 952 return $memberinfo[$userid][$field]; 953 } else { 954 return $memberinfo[$userid]; 955 } 956 } 957 } 958 959 /** 960 * 通过 username 值,获取用户所有信息 961 * 获取用户信息 962 * 不传入$field返回用户所有信息, 963 * 传入field,取用户$field字段信息 964 */ 965 function get_memberinfo_buyusername($username, $field='') { 966 if(empty($username)){return false;} 967 static $memberinfo; 968 if (!isset($memberinfo[$username])) { 969 $member_db = pc_base::load_model('member_model'); 970 $memberinfo[$username] = $member_db->get_one(array('username'=>$username)); 971 } 972 if(!empty($field) && !empty($memberinfo[$username][$field])) { 973 return $memberinfo[$username][$field]; 974 } else { 975 return $memberinfo[$username]; 976 } 977 } 978 979 /** 980 * 获取用户头像,建议传入phpssouid 981 * @param $uid 默认为phpssouid 982 * @param $is_userid $uid是否为v9 userid,如果为真,执行sql查询此用户的phpssouid 983 * @param $size 头像大小 有四种[30x30 45x45 90x90 180x180] 默认30 984 */ 985 function get_memberavatar($uid, $is_userid='', $size='30') { 986 if($is_userid) { 987 $db = pc_base::load_model('member_model'); 988 $memberinfo = $db->get_one(array('userid'=>$uid)); 989 if(isset($memberinfo['phpssouid'])) { 990 $uid = $memberinfo['phpssouid']; 991 } else { 992 return false; 993 } 994 } 995 996 pc_base::load_app_class('client', 'member', 0); 997 define('APPID', pc_base::load_config('system', 'phpsso_appid')); 998 $phpsso_api_url = pc_base::load_config('system', 'phpsso_api_url'); 999 $phpsso_auth_key = pc_base::load_config('system', 'phpsso_auth_key'); 1000 $client = new client($phpsso_api_url, $phpsso_auth_key); 1001 $avatar = $client->ps_getavatar($uid); 1002 if(isset($avatar[$size])) { 1003 return $avatar[$size]; 1004 } else { 1005 return false; 1006 } 1007 } 1008 1009 /** 1010 * 调用关联菜单 1011 * @param $linkageid 联动菜单id 1012 * @param $id 生成联动菜单的样式id 1013 * @param $defaultvalue 默认值 1014 */ 1015 function menu_linkage($linkageid = 0, $id = 'linkid', $defaultvalue = 0) { 1016 $linkageid = intval($linkageid); 1017 $datas = array(); 1018 $datas = getcache($linkageid,'linkage'); 1019 $infos = $datas['data']; 1020 1021 if($datas['style']=='1') { 1022 $title = $datas['title']; 1023 $container = 'content'.random(3).date('is'); 1024 if(!defined('DIALOG_INIT_1')) { 1025 define('DIALOG_INIT_1', 1); 1026 $string .= '<script type="text/javascript" src="'.JS_PATH.'dialog.js"></script>'; 1027 //TODO $string .= '<link href="'.CSS_PATH.'dialog.css" rel="stylesheet" type="text/css">'; 1028 } 1029 if(!defined('LINKAGE_INIT_1')) { 1030 define('LINKAGE_INIT_1', 1); 1031 $string .= '<script type="text/javascript" src="'.JS_PATH.'linkage/js/pop.js"></script>'; 1032 } 1033 $var_div = $defaultvalue && (ROUTE_A=='edit' || ROUTE_A=='account_manage_info' || ROUTE_A=='info_publish' || ROUTE_A=='orderinfo') ? menu_linkage_level($defaultvalue,$linkageid,$infos) : $datas['title']; 1034 $var_input = $defaultvalue && (ROUTE_A=='edit' || ROUTE_A=='account_manage_info' || ROUTE_A=='info_publish') ? '<input type="hidden" name="info['.$id.']" value="'.$defaultvalue.'">' : '<input type="hidden" name="info['.$id.']" value="">'; 1035 $string .= '<div name="'.$id.'" value="" id="'.$id.'" class="ib">'.$var_div.'</div>'.$var_input.' <input type="button" name="btn_'.$id.'" class="button" value="'.L('linkage_select').'" onclick="open_linkage(\''.$id.'\',\''.$title.'\','.$container.',\''.$linkageid.'\')">'; 1036 $string .= '<script type="text/javascript">'; 1037 $string .= 'var returnid_'.$id.'= \''.$id.'\';'; 1038 $string .= 'var returnkeyid_'.$id.' = \''.$linkageid.'\';'; 1039 $string .= 'var '.$container.' = new Array('; 1040 foreach($infos AS $k=>$v) { 1041 if($v['parentid'] == 0) { 1042 $s[]='new Array(\''.$v['linkageid'].'\',\''.$v['name'].'\',\''.$v['parentid'].'\')'; 1043 } else { 1044 continue; 1045 } 1046 } 1047 $s = implode(',',$s); 1048 $string .=$s; 1049 $string .= ')'; 1050 $string .= '</script>'; 1051 1052 } elseif($datas['style']=='2') { 1053 if(!defined('LINKAGE_INIT_1')) { 1054 define('LINKAGE_INIT_1', 1); 1055 $string .= '<script type="text/javascript" src="'.JS_PATH.'linkage/js/jquery.ld.js"></script>'; 1056 } 1057 $default_txt = ''; 1058 if($defaultvalue) { 1059 $default_txt = menu_linkage_level($defaultvalue,$linkageid,$infos); 1060 $default_txt = '["'.str_replace(' > ','","',$default_txt).'"]'; 1061 } 1062 $string .= $defaultvalue && (ROUTE_A=='edit' || ROUTE_A=='account_manage_info' || ROUTE_A=='info_publish') ? '<input type="hidden" name="info['.$id.']" id="'.$id.'" value="'.$defaultvalue.'">' : '<input type="hidden" name="info['.$id.']" id="'.$id.'" value="">'; 1063 1064 for($i=1;$i<=$datas['setting']['level'];$i++) { 1065 $string .='<select class="pc-select-'.$id.'" name="'.$id.'-'.$i.'" id="'.$id.'-'.$i.'" width="100"><option value="">请选择菜单</option></select> '; 1066 } 1067 1068 $string .= '<script type="text/javascript"> 1069 $(function(){ 1070 var $ld5 = $(".pc-select-'.$id.'"); 1071 $ld5.ld({ajaxOptions : {"url" : "'.APP_PATH.'api.php?op=get_linkage&act=ajax_select&keyid='.$linkageid.'"},defaultParentId : 0,style : {"width" : 120}}) 1072 var ld5_api = $ld5.ld("api"); 1073 ld5_api.selected('.$default_txt.'); 1074 $ld5.bind("change",onchange); 1075 function onchange(e){ 1076 var $target = $(e.target); 1077 var index = $ld5.index($target); 1078 $("#'.$id.'-'.$i.'").remove(); 1079 $("#'.$id.'").val($ld5.eq(index).show().val()); 1080 index ++; 1081 $ld5.eq(index).show(); } 1082 }) 1083 </script>'; 1084 1085 } else { 1086 $title = $defaultvalue ? $infos[$defaultvalue]['name'] : $datas['title']; 1087 $colObj = random(3).date('is'); 1088 $string = ''; 1089 if(!defined('LINKAGE_INIT')) { 1090 define('LINKAGE_INIT', 1); 1091 $string .= '<script type="text/javascript" src="'.JS_PATH.'linkage/js/mln.colselect.js"></script>'; 1092 if(defined('IN_ADMIN')) { 1093 $string .= '<link href="'.JS_PATH.'linkage/style/admin.css" rel="stylesheet" type="text/css">'; 1094 } else { 1095 $string .= '<link href="'.JS_PATH.'linkage/style/css.css" rel="stylesheet" type="text/css">'; 1096 } 1097 } 1098 $string .= '<input type="hidden" name="info['.$id.']" value="1"><div id="'.$id.'"></div>'; 1099 $string .= '<script type="text/javascript">'; 1100 $string .= 'var colObj'.$colObj.' = {"Items":['; 1101 1102 foreach($infos AS $k=>$v) { 1103 $s .= '{"name":"'.$v['name'].'","topid":"'.$v['parentid'].'","colid":"'.$k.'","value":"'.$k.'","fun":function(){}},'; 1104 } 1105 1106 $string .= substr($s, 0, -1); 1107 $string .= ']};'; 1108 $string .= '$("#'.$id.'").mlnColsel(colObj'.$colObj.',{'; 1109 $string .= 'title:"'.$title.'",'; 1110 $string .= 'value:"'.$defaultvalue.'",'; 1111 $string .= 'width:100'; 1112 $string .= '});'; 1113 $string .= '</script>'; 1114 } 1115 return $string; 1116 } 1117 1118 /** 1119 * 联动菜单层级 1120 */ 1121 1122 function menu_linkage_level($linkageid,$keyid,$infos,$result=array()) { 1123 if(array_key_exists($linkageid,$infos)) { 1124 $result[]=$infos[$linkageid]['name']; 1125 return menu_linkage_level($infos[$linkageid]['parentid'],$keyid,$infos,$result); 1126 } 1127 krsort($result); 1128 return implode(' > ',$result); 1129 } 1130 /** 1131 * 通过catid获取显示菜单完整结构 1132 * @param $menuid 菜单ID 1133 * @param $cache_file 菜单缓存文件名称 1134 * @param $cache_path 缓存文件目录 1135 * @param $key 取得缓存值的键值名称 1136 * @param $parentkey 父级的ID 1137 * @param $linkstring 链接字符 1138 */ 1139 function menu_level($menuid, $cache_file, $cache_path = 'commons', $key = 'catname', $parentkey = 'parentid', $linkstring = ' > ', $result=array()) { 1140 $menu_arr = getcache($cache_file, $cache_path); 1141 if (array_key_exists($menuid, $menu_arr)) { 1142 $result[] = $menu_arr[$menuid][$key]; 1143 return menu_level($menu_arr[$menuid][$parentkey], $cache_file, $cache_path, $key, $parentkey, $linkstring, $result); 1144 } 1145 krsort($result); 1146 return implode($linkstring, $result); 1147 } 1148 /** 1149 * 通过id获取显示联动菜单 1150 * @param $linkageid 联动菜单ID 1151 * @param $keyid 菜单keyid 1152 * @param $space 菜单间隔符 1153 * @param $tyoe 1 返回间隔符链接,完整路径名称 3 返回完整路径数组,2返回当前联动菜单名称,4 直接返回ID 1154 * @param $result 递归使用字段1 1155 * @param $infos 递归使用字段2 1156 */ 1157 function get_linkage($linkageid, $keyid, $space = '>', $type = 1, $result = array(), $infos = array()) { 1158 if($space=='' || !isset($space))$space = '>'; 1159 if(!$infos) { 1160 $datas = getcache($keyid,'linkage'); 1161 $infos = $datas['data']; 1162 } 1163 if($type == 1 || $type == 3 || $type == 4) { 1164 if(array_key_exists($linkageid,$infos)) { 1165 $result[]= ($type == 1) ? $infos[$linkageid]['name'] : (($type == 4) ? $linkageid :$infos[$linkageid]); 1166 return get_linkage($infos[$linkageid]['parentid'], $keyid, $space, $type, $result, $infos); 1167 } else { 1168 if(count($result)>0) { 1169 krsort($result); 1170 if($type == 1 || $type == 4) $result = implode($space,$result); 1171 return $result; 1172 } else { 1173 return $result; 1174 } 1175 } 1176 } else { 1177 return $infos[$linkageid]['name']; 1178 } 1179 } 1180 /** 1181 * IE浏览器判断 1182 */ 1183 1184 function is_ie() { 1185 $useragent = strtolower($_SERVER['HTTP_USER_AGENT']); 1186 if((strpos($useragent, 'opera') !== false) || (strpos($useragent, 'konqueror') !== false)) return false; 1187 if(strpos($useragent, 'msie ') !== false) return true; 1188 return false; 1189 } 1190 1191 1192 /** 1193 * 文件下载 1194 * @param $filepath 文件路径 1195 * @param $filename 文件名称 1196 */ 1197 1198 function file_down($filepath, $filename = '') { 1199 if(!$filename) $filename = basename($filepath); 1200 if(is_ie()) $filename = rawurlencode($filename); 1201 $filetype = fileext($filename); 1202 $filesize = sprintf("%u", filesize($filepath)); 1203 if(ob_get_length() !== false) @ob_end_clean(); 1204 header('Pragma: public'); 1205 header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT'); 1206 header('Cache-Control: no-store, no-cache, must-revalidate'); 1207 header('Cache-Control: pre-check=0, post-check=0, max-age=0'); 1208 header('Content-Transfer-Encoding: binary'); 1209 header('Content-Encoding: none'); 1210 header('Content-type: '.$filetype); 1211 header('Content-Disposition: attachment; filename="'.$filename.'"'); 1212 header('Content-length: '.$filesize); 1213 readfile($filepath); 1214 exit; 1215 } 1216 1217 /** 1218 * 判断字符串是否为utf8编码,英文和半角字符返回ture 1219 * @param $string 1220 * @return bool 1221 */ 1222 function is_utf8($string) { 1223 return preg_match('%^(?: 1224 [\x09\x0A\x0D\x20-\x7E] # ASCII 1225 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte 1226 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs 1227 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte 1228 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates 1229 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 1230 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 1231 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 1232 )*$%xs', $string); 1233 } 1234 1235 /** 1236 * 组装生成ID号 1237 * @param $modules 模块名 1238 * @param $contentid 内容ID 1239 * @param $siteid 站点ID 1240 */ 1241 function id_encode($modules,$contentid, $siteid) { 1242 return urlencode($modules.'-'.$contentid.'-'.$siteid); 1243 } 1244 1245 /** 1246 * 解析ID 1247 * @param $id 评论ID 1248 */ 1249 function id_decode($id) { 1250 return explode('-', $id); 1251 } 1252 1253 /** 1254 * 对用户的密码进行加密 1255 * @param $password 1256 * @param $encrypt //传入加密串,在修改密码时做认证 1257 * @return array/password 1258 */ 1259 function password($password, $encrypt='') { 1260 $pwd = array(); 1261 $pwd['encrypt'] = $encrypt ? $encrypt : create_randomstr(); 1262 $pwd['password'] = md5(md5(trim($password)).$pwd['encrypt']); 1263 return $encrypt ? $pwd['password'] : $pwd; 1264 } 1265 /** 1266 * 生成随机字符串 1267 * @param string $lenth 长度 1268 * @return string 字符串 1269 */ 1270 function create_randomstr($lenth = 6) { 1271 return random($lenth, '123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ'); 1272 } 1273 1274 /** 1275 * 检查密码长度是否符合规定 1276 * 1277 * @param STRING $password 1278 * @return TRUE or FALSE 1279 */ 1280 function is_password($password) { 1281 $strlen = strlen($password); 1282 if($strlen >= 6 && $strlen <= 20) return true; 1283 return false; 1284 } 1285 1286 /** 1287 * 检测输入中是否含有错误字符 1288 * 1289 * @param char $string 要检查的字符串名称 1290 * @return TRUE or FALSE 1291 */ 1292 function is_badword($string) { 1293 $badwords = array("\\",'&',' ',"'",'"','/','*',',','<','>',"\r","\t","\n","#"); 1294 foreach($badwords as $value){ 1295 if(strpos($string, $value) !== FALSE) { 1296 return TRUE; 1297 } 1298 } 1299 return FALSE; 1300 } 1301 1302 /** 1303 * 检查用户名是否符合规定 1304 * 1305 * @param STRING $username 要检查的用户名 1306 * @return TRUE or FALSE 1307 */ 1308 function is_username($username) { 1309 $strlen = strlen($username); 1310 if(is_badword($username) || !preg_match("/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/", $username)){ 1311 return false; 1312 } elseif ( 20 < $strlen || $strlen < 2 ) { 1313 return false; 1314 } 1315 return true; 1316 } 1317 1318 /** 1319 * 检查id是否存在于数组中 1320 * 1321 * @param $id 1322 * @param $ids 1323 * @param $s 1324 */ 1325 function check_in($id, $ids = '', $s = ',') { 1326 if(!$ids) return false; 1327 $ids = explode($s, $ids); 1328 return is_array($id) ? array_intersect($id, $ids) : in_array($id, $ids); 1329 } 1330 1331 /** 1332 * 对数据进行编码转换 1333 * @param array/string $data 数组 1334 * @param string $input 需要转换的编码 1335 * @param string $output 转换后的编码 1336 */ 1337 function array_iconv($data, $input = 'gbk', $output = 'utf-8') { 1338 if (!is_array($data)) { 1339 return iconv($input, $output, $data); 1340 } else { 1341 foreach ($data as $key=>$val) { 1342 if(is_array($val)) { 1343 $data[$key] = array_iconv($val, $input, $output); 1344 } else { 1345 $data[$key] = iconv($input, $output, $val); 1346 } 1347 } 1348 return $data; 1349 } 1350 } 1351 1352 /** 1353 * 生成缩略图函数 1354 * @param $imgurl 图片路径 1355 * @param $width 缩略图宽度 1356 * @param $height 缩略图高度 1357 * @param $autocut 是否自动裁剪 默认裁剪,当高度或宽度有一个数值为0是,自动关闭 1358 * @param $smallpic 无图片是默认图片路径 1359 */ 1360 function thumb($imgurl, $width = 100, $height = 100 ,$autocut = 1, $smallpic = 'nopic.gif') { 1361 global $image; 1362 $upload_url = pc_base::load_config('system','upload_url'); 1363 $upload_path = pc_base::load_config('system','upload_path'); 1364 if(empty($imgurl)) return IMG_PATH.$smallpic; 1365 $imgurl_replace= str_replace($upload_url, '', $imgurl); 1366 if(!extension_loaded('gd') || strpos($imgurl_replace, '://')) return $imgurl; 1367 if(!file_exists($upload_path.$imgurl_replace)) return IMG_PATH.$smallpic; 1368 1369 list($width_t, $height_t, $type, $attr) = getimagesize($upload_path.$imgurl_replace); 1370 if($width>=$width_t || $height>=$height_t) return $imgurl; 1371 1372 $newimgurl = dirname($imgurl_replace).'/thumb_'.$width.'_'.$height.'_'.basename($imgurl_replace); 1373 1374 if(file_exists($upload_path.$newimgurl)) return $upload_url.$newimgurl; 1375 1376 if(!is_object($image)) { 1377 pc_base::load_sys_class('image','','0'); 1378 $image = new image(1,0); 1379 } 1380 return $image->thumb($upload_path.$imgurl_replace, $upload_path.$newimgurl, $width, $height, '', $autocut) ? $upload_url.$newimgurl : $imgurl; 1381 } 1382 1383 /** 1384 * 水印添加 1385 * @param $source 原图片路径 1386 * @param $target 生成水印图片途径,默认为空,覆盖原图 1387 * @param $siteid 站点id,系统需根据站点id获取水印信息 1388 */ 1389 function watermark($source, $target = '',$siteid) { 1390 global $image_w; 1391 if(empty($source)) return $source; 1392 if(!extension_loaded('gd') || strpos($source, '://')) return $source; 1393 if(!$target) $target = $source; 1394 if(!is_object($image_w)){ 1395 pc_base::load_sys_class('image','','0'); 1396 $image_w = new image(0,$siteid); 1397 } 1398 $image_w->watermark($source, $target); 1399 return $target; 1400 } 1401 1402 /** 1403 * 当前路径 1404 * 返回指定栏目路径层级 1405 * @param $catid 栏目id 1406 * @param $symbol 栏目间隔符 1407 */ 1408 function catpos($catid, $symbol=' > '){ 1409 $category_arr = array(); 1410 $siteids = getcache('category_content','commons'); 1411 $siteid = $siteids[$catid]; 1412 $category_arr = getcache('category_content_'.$siteid,'commons'); 1413 if(!isset($category_arr[$catid])) return ''; 1414 $pos = ''; 1415 $siteurl = siteurl($category_arr[$catid]['siteid']); 1416 $arrparentid = array_filter(explode(',', $category_arr[$catid]['arrparentid'].','.$catid)); 1417 foreach($arrparentid as $catid) { 1418 $url = $category_arr[$catid]['url']; 1419 if(strpos($url, '://') === false) $url = $siteurl.$url; 1420 $pos .= '<a href="'.$url.'">'.$category_arr[$catid]['catname'].'</a>'.$symbol; 1421 } 1422 return $pos; 1423 } 1424 1425 /** 1426 * 根据catid获取子栏目数据的sql语句 1427 * @param string $module 缓存文件名 1428 * @param intval $catid 栏目ID 1429 */ 1430 1431 function get_sql_catid($file = 'category_content_1', $catid = 0, $module = 'commons') { 1432 $category = getcache($file,$module); 1433 $catid = intval($catid); 1434 if(!isset($category[$catid])) return false; 1435 return $category[$catid]['child'] ? " `catid` IN(".$category[$catid]['arrchildid'].") " : " `catid`=$catid "; 1436 } 1437 1438 /** 1439 * 获取子栏目 1440 * @param $parentid 父级id 1441 * @param $type 栏目类型 1442 * @param $self 是否包含本身 0为不包含 1443 * @param $siteid 站点id 1444 */ 1445 function subcat($parentid = NULL, $type = NULL,$self = '0', $siteid = '') { 1446 if (empty($siteid)) $siteid = get_siteid(); 1447 $category = getcache('category_content_'.$siteid,'commons'); 1448 foreach($category as $id=>$cat) { 1449 if($cat['siteid'] == $siteid && ($parentid === NULL || $cat['parentid'] == $parentid) && ($type === NULL || $cat['type'] == $type)) $subcat[$id] = $cat; 1450 if($self == 1 && $cat['catid'] == $parentid && !$cat['child']) $subcat[$id] = $cat; 1451 } 1452 return $subcat; 1453 } 1454 1455 /** 1456 * 获取内容地址 1457 * @param $catid 栏目ID 1458 * @param $id 文章ID 1459 * @param $allurl 是否以绝对路径返回 1460 */ 1461 function go($catid,$id, $allurl = 0) { 1462 static $category; 1463 if(empty($category)) { 1464 $siteids = getcache('category_content','commons'); 1465 $siteid = $siteids[$catid]; 1466 $category = getcache('category_content_'.$siteid,'commons'); 1467 } 1468 $id = intval($id); 1469 if(!$id || !isset($category[$catid])) return ''; 1470 $modelid = $category[$catid]['modelid']; 1471 if(!$modelid) return ''; 1472 $db = pc_base::load_model('content_model'); 1473 $db->set_model($modelid); 1474 $r = $db->get_one(array('id'=>$id), '`url`'); 1475 if (!empty($allurl)) { 1476 if (strpos($r['url'], '://')===false) { 1477 $site = siteinfo($category[$catid]['siteid']); 1478 $r['url'] = substr($site['domain'], 0, -1).$r['url']; 1479 } 1480 } 1481 1482 return $r['url']; 1483 } 1484 1485 /** 1486 * 将附件地址转换为绝对地址 1487 * @param $path 附件地址 1488 */ 1489 function atturl($path) { 1490 if(strpos($path, ':/')) { 1491 return $path; 1492 } else { 1493 $sitelist = getcache('sitelist','commons'); 1494 $siteid = get_siteid(); 1495 $siteurl = $sitelist[$siteid]['domain']; 1496 $domainlen = strlen($sitelist[$siteid]['domain'])-1; 1497 $path = $siteurl.$path; 1498 $path = substr_replace($path, '/', strpos($path, '//',$domainlen),2); 1499 return $path; 1500 } 1501 } 1502 1503 /** 1504 * 判断模块是否安装 1505 * @param $m 模块名称 1506 */ 1507 function module_exists($m = '') { 1508 if ($m=='admin') return true; 1509 $modules = getcache('modules', 'commons'); 1510 $modules = array_keys($modules); 1511 return in_array($m, $modules); 1512 } 1513 1514 /** 1515 * 生成SEO 1516 * @param $siteid 站点ID 1517 * @param $catid 栏目ID 1518 * @param $title 标题 1519 * @param $description 描述 1520 * @param $keyword 关键词 1521 */ 1522 function seo($siteid, $catid = '', $title = '', $description = '', $keyword = '') { 1523 if (!empty($title))$title = strip_tags($title); 1524 if (!empty($description)) $description = strip_tags($description); 1525 if (!empty($keyword)) $keyword = str_replace(' ', ',', strip_tags($keyword)); 1526 $sites = getcache('sitelist', 'commons'); 1527 $site = $sites[$siteid]; 1528 $cat = array(); 1529 if (!empty($catid)) { 1530 $siteids = getcache('category_content','commons'); 1531 $siteid = $siteids[$catid]; 1532 $categorys = getcache('category_content_'.$siteid,'commons'); 1533 $cat = $categorys[$catid]; 1534 $cat['setting'] = string2array($cat['setting']); 1535 } 1536 $seo['site_title'] =isset($site['site_title']) && !empty($site['site_title']) ? $site['site_title'] : $site['name']; 1537 $seo['keyword'] = !empty($keyword) ? $keyword : $site['keywords']; 1538 $seo['description'] = isset($description) && !empty($description) ? $description : (isset($cat['setting']['meta_description']) && !empty($cat['setting']['meta_description']) ? $cat['setting']['meta_description'] : (isset($site['description']) && !empty($site['description']) ? $site['description'] : '')); 1539 $seo['title'] = (isset($title) && !empty($title) ? $title.' - ' : '').(isset($cat['setting']['meta_title']) && !empty($cat['setting']['meta_title']) ? $cat['setting']['meta_title'].' - ' : (isset($cat['catname']) && !empty($cat['catname']) ? $cat['catname'].' - ' : '')); 1540 foreach ($seo as $k=>$v) { 1541 $seo[$k] = str_replace(array("\n","\r"), '', $v); 1542 } 1543 return $seo; 1544 } 1545 1546 /** 1547 * 获取站点的信息 1548 * @param $siteid 站点ID 1549 */ 1550 function siteinfo($siteid) { 1551 static $sitelist; 1552 if (empty($sitelist)) $sitelist = getcache('sitelist','commons'); 1553 return isset($sitelist[$siteid]) ? $sitelist[$siteid] : ''; 1554 } 1555 1556 /** 1557 * 生成CNZZ统计代码 1558 */ 1559 1560 function tjcode() { 1561 if(!module_exists('cnzz')) return false; 1562 $config = getcache('cnzz', 'commons'); 1563 if (empty($config)) { 1564 return false; 1565 } else { 1566 return '<script src=\'http://pw.cnzz.com/c.php?id='.$config['siteid'].'&l=2\' language=\'JavaScript\' charset=\'gb2312\'></script>'; 1567 } 1568 } 1569 1570 /** 1571 * 生成标题样式 1572 * @param $style 样式 1573 * @param $html 是否显示完整的STYLE 1574 */ 1575 function title_style($style, $html = 1) { 1576 if(!$style) return ""; 1577 $str = ''; 1578 if ($html) $str = ' style="'; 1579 $style_arr = explode(';',$style); 1580 if (!empty($style_arr[0])) $str .= 'color:'.$style_arr[0].';'; 1581 if (!empty($style_arr[1])) $str .= 'font-weight:'.$style_arr[1].';'; 1582 if ($html) $str .= '" '; 1583 return $str; 1584 } 1585 1586 /** 1587 * 获取站点域名 1588 * @param $siteid 站点id 1589 */ 1590 function siteurl($siteid) { 1591 static $sitelist; 1592 if(!$siteid) return WEB_PATH; 1593 if(empty($sitelist)) $sitelist = getcache('sitelist','commons'); 1594 return substr($sitelist[$siteid]['domain'],0,-1); 1595 } 1596 /** 1597 * 生成上传附件验证 1598 * @param $args 参数 1599 * @param $operation 操作类型(加密解密) 1600 */ 1601 1602 function upload_key($args) { 1603 $pc_auth_key = md5(PC_PATH.'upload'.pc_base::load_config('system','auth_key').$_SERVER['HTTP_USER_AGENT']); 1604 $authkey = md5($args.$pc_auth_key); 1605 return $authkey; 1606 } 1607 /** 1608 * 生成验证key 1609 * @param $prefix 参数 1610 * @param $suffix 参数 1611 */ 1612 function get_auth_key($prefix,$suffix="") { 1613 if($prefix=='login'){ 1614 $pc_auth_key = md5(PC_PATH.'login'.pc_base::load_config('system','auth_key').ip()); 1615 }else if($prefix=='email'){ 1616 $pc_auth_key = md5(PC_PATH.'email'.pc_base::load_config('system','auth_key')); 1617 }else{ 1618 $pc_auth_key = md5(PC_PATH.'other'.pc_base::load_config('system','auth_key').$suffix); 1619 } 1620 $authkey = md5($prefix.$pc_auth_key); 1621 return $authkey; 1622 } 1623 /** 1624 * 文本转换为图片 1625 * @param string $txt 图形化文本内容 1626 * @param int $fonttype 无外部字体时生成文字大小,取值范围1-5 1627 * @param int $fontsize 引入外部字体时,字体大小 1628 * @param string $font 字体名称 字体请放于phpcms\libs\data\font下 1629 * @param string $fontcolor 字体颜色 十六进制形式 如FFFFFF,FF0000 1630 */ 1631 function string2img($txt, $fonttype = 5, $fontsize = 16, $font = '', $fontcolor = 'FF0000',$transparent = '1') { 1632 if(empty($txt)) return false; 1633 if(function_exists("imagepng")) { 1634 $txt = urlencode(sys_auth($txt)); 1635 $txt = '<img src="'.APP_PATH.'api.php?op=creatimg&txt='.$txt.'&fonttype='.$fonttype.'&fontsize='.$fontsize.'&font='.$font.'&fontcolor='.$fontcolor.'&transparent='.$transparent.'" align="absmiddle">'; 1636 } 1637 return $txt; 1638 } 1639 1640 /** 1641 * 获取phpcms版本号 1642 */ 1643 function get_pc_version($type='') { 1644 $version = pc_base::load_config('version'); 1645 if($type==1) { 1646 return $version['pc_version']; 1647 } elseif($type==2) { 1648 return $version['pc_release']; 1649 } else { 1650 return $version['pc_version'].' '.$version['pc_release']; 1651 } 1652 } 1653 /** 1654 * 运行钩子(插件使用) 1655 */ 1656 function runhook($method) { 1657 $time_start = getmicrotime(); 1658 $data = ''; 1659 $getpclass = FALSE; 1660 $hook_appid = getcache('hook','plugins'); 1661 if(!empty($hook_appid)) { 1662 foreach($hook_appid as $appid => $p) { 1663 $pluginfilepath = PC_PATH.'plugin'.DIRECTORY_SEPARATOR.$p.DIRECTORY_SEPARATOR.'hook.class.php'; 1664 $getpclass = TRUE; 1665 include_once $pluginfilepath; 1666 } 1667 $hook_appid = array_flip($hook_appid); 1668 if($getpclass) { 1669 $pclass = new ReflectionClass('hook'); 1670 foreach($pclass->getMethods() as $r) { 1671 $legalmethods[] = $r->getName(); 1672 } 1673 } 1674 if(in_array($method,$legalmethods)) { 1675 foreach (get_declared_classes() as $class){ 1676 $refclass = new ReflectionClass($class); 1677 if($refclass->isSubclassOf('hook')){ 1678 if ($_method = $refclass->getMethod($method)) { 1679 $classname = $refclass->getName(); 1680 if ($_method->isPublic() && $_method->isFinal()) { 1681 plugin_stat($hook_appid[$classname]); 1682 $data .= $_method->invoke(null); 1683 } 1684 } 1685 } 1686 } 1687 } 1688 return $data; 1689 } 1690 } 1691 1692 function getmicrotime() { 1693 list($usec, $sec) = explode(" ",microtime()); 1694 return ((float)$usec + (float)$sec); 1695 } 1696 1697 /** 1698 * 插件前台模板加载 1699 * Enter description here ... 1700 * @param unknown_type $module 1701 * @param unknown_type $template 1702 * @param unknown_type $style 1703 */ 1704 function p_template($plugin = 'content', $template = 'index',$style='default') { 1705 if(!$style) $style = 'default'; 1706 $template_cache = pc_base::load_sys_class('template_cache'); 1707 $compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.$template.'.php'; 1708 1709 if(!file_exists($compiledtplfile) || (file_exists(PC_PATH.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.html') && filemtime(PC_PATH.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.html') > filemtime($compiledtplfile))) { 1710 $template_cache->template_compile('plugin/'.$plugin, $template, 'default'); 1711 } elseif (!file_exists(PC_PATH.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.html')) { 1712 showmessage('Template does not exist.'.DIRECTORY_SEPARATOR.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.$template.'.html'); 1713 } 1714 1715 return $compiledtplfile; 1716 } 1717 /** 1718 * 读取缓存动态页面 1719 */ 1720 function cache_page_start() { 1721 $relate_url = isset($_SERVER['REQUEST_URI']) ? safe_replace($_SERVER['REQUEST_URI']) : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.safe_replace($_SERVER['QUERY_STRING']) : $path_info); 1722 define('CACHE_PAGE_ID', md5($relate_url)); 1723 $contents = getcache(CACHE_PAGE_ID, 'page_tmp/'.substr(CACHE_PAGE_ID, 0, 2)); 1724 if($contents && intval(substr($contents, 15, 10)) > SYS_TIME) { 1725 echo substr($contents, 29); 1726 exit; 1727 } 1728 if (!defined('HTML')) define('HTML',true); 1729 return true; 1730 } 1731 /** 1732 * 写入缓存动态页面 1733 */ 1734 function cache_page($ttl = 360, $isjs = 0) { 1735 if($ttl == 0 || !defined('CACHE_PAGE_ID')) return false; 1736 $contents = ob_get_contents(); 1737 1738 if($isjs) $contents = format_js($contents); 1739 $contents = "<!--expiretime:".(SYS_TIME + $ttl)."-->\n".$contents; 1740 setcache(CACHE_PAGE_ID, $contents, 'page_tmp/'.substr(CACHE_PAGE_ID, 0, 2)); 1741 } 1742 1743 /** 1744 * 1745 * 获取远程内容 1746 * @param $url 接口url地址 1747 * @param $timeout 超时时间 1748 */ 1749 function pc_file_get_contents($url, $timeout=30) { 1750 $stream = stream_context_create(array('http' => array('timeout' => $timeout))); 1751 return @file_get_contents($url, 0, $stream); 1752 } 1753 1754 /** 1755 * Function get_vid 1756 * 获取视频信息 1757 * @param int $contentid 内容ID 必须 1758 * @param int $catid 栏目id 取内容里面视频信息时必须 1759 * @param int $isspecial 是否取专题的视频信息 1760 */ 1761 function get_vid($contentid = 0, $catid = 0, $isspecial = 0) { 1762 static $categorys; 1763 if (!$contentid) return false; 1764 if (!$isspecial) { 1765 if (!$catid) return false; 1766 $contentid = intval($contentid); 1767 $catid = intval($catid); 1768 $siteid = get_siteid(); 1769 if (!$categorys) { 1770 $categorys = getcache('category_content_'.$siteid, 'commons'); 1771 } 1772 $modelid = $categorys[$catid]['modelid']; 1773 $video_content = pc_base::load_model('video_content_model'); 1774 $r = $video_content->get_one(array('contentid'=>$contentid, 'modelid'=>$modelid), 'videoid', '`listorder` ASC'); 1775 $video_store =pc_base::load_model('video_store_model'); 1776 return $video_store->get_one(array('videoid'=>$r['videoid'])); 1777 } else { 1778 $special_content = pc_base::load_model('special_content_model'); 1779 $contentid = intval($contentid); 1780 $video_store =pc_base::load_model('video_store_model'); 1781 $r = $special_content->get_one(array('id'=>$contentid), 'videoid'); 1782 return $video_store->get_one(array('videoid'=>$r['videoid'])); 1783 } 1784 } 1785 1786 /** 1787 * Function dataformat 1788 * 时间转换 1789 * @param $n INT时间 1790 */ 1791 function dataformat($n) { 1792 $hours = floor($n/3600); 1793 $minite = floor($n%3600/60); 1794 $secend = floor($n%3600%60); 1795 $minite = $minite < 10 ? "0".$minite : $minite; 1796 $secend = $secend < 10 ? "0".$secend : $secend; 1797 if($n >= 3600){ 1798 return $hours.":".$minite.":".$secend; 1799 }else{ 1800 return $minite.":".$secend; 1801 } 1802 1803 } 1804 ?>

 

标签:function,return,分页,效果,param,PHPcms,str,array,string
From: https://www.cnblogs.com/zsyyyds/p/16876236.html

相关文章