📄 func.php
字号:
<?phpfunction template($file) { global $tpldir, $templateid; $tplfile = MYROOT.'./'.$tpldir.'/'.$file.'.htm'; $objfile = MYROOT.'./cache/temp/'.$templateid.'_'.$file.'.tpl.php'; if($templateid != 1 && !file_exists($tplfile)) { $tpldir='./temp/01/'; $templateid=1; return template($file); } if(@filemtime($tplfile) > @filemtime($objfile)) { require_once MYROOT.'./inc/temp.php'; parse_template($file, $templateid, $tpldir); } return $objfile;}function cut_str($string, $length, $dot = ' ...') { global $charset; $length*=2; if(strlen($string) <= $length) { return $string; } $strcut = ''; if(strtolower($charset) == 'utf-8') { $n = $tn = $noc = 0; while ($n < strlen($string)) { $t = ord($string[$n]); if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) { $tn = 1; $n++; $noc++; } elseif(194 <= $t && $t <= 223) { $tn = 2; $n += 2; $noc += 2; } elseif(224 <= $t && $t < 239) { $tn = 3; $n += 3; $noc += 2; } elseif(240 <= $t && $t <= 247) { $tn = 4; $n += 4; $noc += 2; } elseif(248 <= $t && $t <= 251) { $tn = 5; $n += 5; $noc += 2; } elseif($t == 252 || $t == 253) { $tn = 6; $n += 6; $noc += 2; } else { $n++; } if ($noc >= $length) { break; } } if ($noc > $length) { $n -= $tn; } $strcut = substr($string, 0, $n); } else { for($i = 0; $i < $length - strlen($dot) - 1; $i++) { $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i]; } } return $strcut.$dot;} function daddslashes($string, $force = 0) { if(!$GLOBALS['magic_quotes_gpc'] || $force) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = daddslashes($val, $force); } } else { $string = addslashes($string); } } return $string;}function dhtmlspecialchars($string) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = dhtmlspecialchars($val); } } else { $string = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/', '&\\1', str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string)); } return $string;}function show($message, $to, $tostr=''){ if ($to=='back'){ $to='javascript:history.back()'; $tostr='请点击这里返回'; } if ($to=='close'){ $to='javascript:close()'; $tostr='请点击这里关闭窗口'; } if ($to=='') $to='index.php'; if ($to!='javascript:history.back()'&&$to!='javascript:close()'){ $url_forward=$to; } include template('message'); exit();}function clearcookie(){ global $uid, $password, $username; setcookie('bosauth', '', $timestamp-86400 * 365); $uid=0; $password=''; $username='';}function random($length, $numeric = 0) { mt_srand((double)microtime() * 1000000); if($numeric) { $hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1)); } else { $hash = ''; $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; $max = strlen($chars) - 1; for($i = 0; $i < $length; $i++) { $hash .= $chars[mt_rand(0, $max)]; } } return $hash;}function setting_cache(){ global $db; $cache_url=MYROOT."./cache/setting.php"; if (!file_exists($cache_url)){ $qstr="select * from setting where variable<>'logadmin' and variable<>'logpassword'"; $result=$db->query($qstr); $setting=array(); while($temp=$db->fetch_array($result)){ $setting[$temp['variable']]=$temp['val']; } $cache_str="<?php \n \$setting=array(\n"; $temparray=array(); foreach ($setting as $key=>$val){ $temparray[]="'$key'=>'".addslashes($val)."'"; } $cache_str.=implode(", \n", $temparray); $cache_str.='); ?>'; //echo $cache_str; $fp=fopen("$cache_url",'w'); fwrite($fp,$cache_str); fclose($fp); }else{ require_once "$cache_url"; } return $setting;}function clearcache(){ $cache_url=MYROOT."./cache/setting.php"; if (file_exists($cache_url)){ unlink($cache_url); }}function makeurl($uid, $script){ global $isrewrite; $uri='http://'.$_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"]; $baseurl=str_replace($script, '', $uri); if(!$isrewrite){ $adurl=$baseurl."?$uid-1.html"; }else{ $adurl=$baseurl."$uid-1.html"; } return $adurl;}function makepage($now, $total, $url){ $laststr=''; $nextstr=''; $last=$now-1; $next=$now+1; if ($last>0){ $laststr="<a href='{$url}&page=$last'>上一页</a>"; }else{ $laststr="上一页"; } if ($next<=$total){ $nextstr="<a href='{$url}&page=$next'>下一页</a>"; }else{ $nextstr="下一页"; } return $laststr." ".$nextstr." $now/$total"; }?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -