<?php
//包含函数库
require_once( dirname(__FILE__).'/inc/mysql.php' );
//拼音的缓冲数组
$pinyins = Array();
//获得当前的脚本网址
function GetCurUrl()
{
if(!empty($_SERVER["REQUEST_URI"]))
{
$scriptName = $_SERVER["REQUEST_URI"];
$nowurl = $scriptName;
}
else
{
$scriptName = $_SERVER["PHP_SELF"];
if(empty($_SERVER["QUERY_STRING"]))
{
$nowurl = $scriptName;
}
else
{
$nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];
}
}
return $nowurl;
}
//返回格林威治标准时间
function MyDate($format='Y-m-d H:i:s',$timest=0)
{
global $cfg_cli_time;
$addtime = $cfg_cli_time * 3600;
if(empty($format))
{
$format = 'Y-m-d H:i:s';
}
return gmdate ($format,$timest+$addtime);
}
function GetDateMk($mktime)
{
return MyDate("Y-m-d",$mktime);
}
//中文截取2,单字节截取模式
//如果是request的内容,必须使用这个函数
function cn_substrR($str,$slen,$startdd=0)
{
$str = cn_substr(stripslashes($str),$slen,$startdd);
return addslashes($str);
}
//中文截取2,单字节截取模式
function cn_substr_utf8($str, $length, $start=0)
{
$lgocl_str=$str;
//echo strlen($lgocl_str)."||".$length;
if(strlen($str) < $start+1)
{
return '';
}
preg_match_all("/./su", $str, $ar);
$str = '';
$tstr = '';
//为了兼容mysql4.1以下版本,与数据库varchar一致,这里使用按字节截取
for($i=0; isset($ar[0][$i]); $i++)
{
if(strlen($tstr) < $start)
{
$tstr .= $ar[0][$i];
}
else
{
if(strlen($str) < $length )
{
$str .= $ar[0][$i];
}
else
{
break;
}
}
}
return $str;
}
function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true){
$re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
$re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
$re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
$re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
preg_match_all($re[$charset], $str, $match);
$length_new = $length;
for($i=$start; $i<$length; $i++){
if (ord($match[0][$i]) > 0xa0){
//中文
}else{
$length_new++;
$length_chi++;
}
}
if($length_chi<$length){
$length_new = $length+($length_chi/2);
}
$slice = join("",array_slice($match[0], $start, $length_new));
if($suffix && $slice != $str){
return $slice."…";
}
return $slice;
}
function cn_substr($str,$slen,$startdd=0)
{
global $cfg_soft_lang;
if($cfg_soft_lang=='utf-8')
{
return cn_substr_utf8($str,$slen,$startdd);
}
$restr = '';
$c = '';
$str_len = strlen($str);
if($str_len < $startdd+1)
{
return '';
}
if($str_len < $startdd + $slen || $slen==0)
{
$slen = $str_len - $startdd;
}
$enddd = $startdd + $slen - 1;
for($i=0;$i<$str_len;$i++)
{
if($startdd==0)
{
$restr .= $c;
}
else if($i > $startdd)
{
$restr .= $c;
}
if(ord($str[$i])>0x80)
{
if($str_len>$i+1)
{
$c = $str[$i].$str[$i+1];
}
$i++;
}
else
{
$c = $str[$i];
}
if($i >= $enddd)
{
if(strlen($restr)+strlen($c)>$slen)
{
break;
}
else
{
$restr .= $c;
break;
}
}
}
return $restr;
}
function GetCkVdValue()
{
@session_start();
return isset($_SESSION['sea_ckstr']) ? $_SESSION['sea_ckstr'] : '';
}
//php某些版本有Bug,不能在同一作用域中同时读session并改注销它,因此调用后需执行本函数
function ResetVdValue()
{
@session_start();
$_SESSION['sea_ckstr'] = '';
$_SESSION['sea_ckstr_last'] = '';
}
function ExecTime()
{
$time = explode(" ", microtime());
$usec = (double)$time[0];
$sec = (double)$time[1];
return $sec + $usec;
}
function getRunTime($t1)
{
$t2=ExecTime() - $t1;
return "页面执行时间: ".number_format($t2, 6)."秒";
}
function getPowerInfo()
{
return "<p>Powered by <strong><a href=\"http://www.seacms.net\" title=\"".$GLOBALS['cfg_softname']."\" target=\"_blank\">".$GLOBALS['cfg_soft_enname']."</a></strong> <em>".$GLOBALS['cfg_version']."</em></p>";
}
function dd2char($ddnum)
{
$ddnum = strval($ddnum);
$slen = strlen($ddnum);
$okdd = '';
$nn = '';
for($i=0;$i<$slen;$i++)
{
if(isset($ddnum[$i+1]))
{
$n = $ddnum[$i].$ddnum[$i+1];
if( ($n>96 && $n<123) || ($n>64 && $n<91) )
{
$okdd .= chr($n);
$i++;
}
else
{
$okdd .= $ddnum[$i];
}
}
else
{
$okdd .= $ddnum[$i];
}
}
return $okdd;
}
function PutCookie($key,$value,$kptime=0,$pa="/")
{
global $cfg_cookie_encode;
setcookie($key,$value,time()+$kptime,$pa);
setcookie($key.'__ckMd5',substr(md5($cfg_cookie_encode.$value),0,16),time()+$kptime,$pa);
}
function DropCookie($key)
{
setcookie($key,'',time()-360000,"/");
setcookie($key.'__ckMd5','',time()-360000,"/");
}
function GetCookie($key)
{
global $cfg_cookie_encode;
if( !isset($_COOKIE[$key]) || !isset($_COOKIE[$key.'__ckMd5']) )
{
return '';
}
else
{
if($_COOKIE[$key.'__ckMd5']!=substr(md5($cfg_cookie_encode.$_COOKIE[$key]),0,16))
{
return '';
}
else
{
return $_COOKIE[$key];
}
}
}
function GetIP()
{
if(!empty($_SERVER["HTTP_CLIENT_IP"]))
{
$cip = $_SERVER["HTTP_CLIENT_IP"];
}
else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
{
$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
else if(!empty($_SERVER["REMOTE_ADDR"]))
{
$cip = $_SERVER["REMOTE_ADDR"];
}
else
{
$cip = '';
}
preg_match("/[\d\.]{7,15}/", $cip, $cips);
$cip = isset($cips[0]) ? $cips[0] : 'unknown';
unset($cips);
return $cip;
}
function ShowMsg($msg,$gourl,$onlymsg=0,$limittime=0,$extraJs='')
{
global $cfg_basehost;
if(empty($GLOBALS['cfg_phpurl']))
{
$GLOBALS['cfg_phpurl'] = '..';
}
$htmlhead = "<html>\r\n<head>\r\n<title>提示信息</title>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><meta name=\"viewport\" content=\"width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no\">\r\n";
$htmlhead .= "<base target='_self'/>\r\n<style>body{background:#f9fafd;color:#818181}a {text-decoration: none}.mac_msg_jump{width:90%;max-width:420px;margin:5% auto 0;border: 1px solid #293846;border-radius: 4px;box-shadow: 0px 1px 2px rgba(0,0,0,0.1);border: 1px solid #0099CC;background-color: #F2F9FD;}.mac_msg_jump .title{margin-bottom:11px}.mac_msg_jump .text{margin-top: 20px;font-size:14px;color:#555;font-weight: normal;}.msg_jump_tit{height: 32px;padding: 0px;line-height: 32px;font-size: 14px;color: #DFE4ED;text-align: left;background: #0099CC;}</style></head>\r\n<body leftmargin='0' topmargin='0'>\r\n<center>\r\n<script>\r\n";
$htmlfoot = "</script>\r\n$extraJs</center>\r\n</body>\r\n</html>\r\n";
if($limittime==0)
{
$litime = 1000;
}
else
{
$litime = $limittime;
}
if($gourl=="-1")
{
if($limittime==0)
{
$litime = 1000;
}
$gourl = "javascript:history.go(-1);";
}
if($gourl==''||$onlymsg==1)
{
$msg = "<script>alert(\"".str_replace("\"","“",$msg)."\");</script>";
}
else
{
$func = " var pgo=0;
function JumpUrl(){
if(pgo==0){ location='$gourl'; pgo=1; }
}\r\n";
$rmsg = $func;
$rmsg .= "document.write(\"<br /><div class='mac_msg_jump'>";
$rmsg .= "<div class='text'>\");\r\n";
$rmsg .= "document.write(\"<img style='height: 28px;margin-bottom: 15px;'; src='{$cfg_basehost}/pic/i2.png'><br>".str_replace("\"","“",$msg)."\");\r\n";
$rmsg .= "document.write(\"";
if($onlymsg==0)
{
if($gourl!="javascript:;" && $gourl!="")
{
$rmsg .= "<div style='margin-top:20px;'><a href='{$gour