您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 公司方案 > Discuz!常用函数解析
Discuz!常用函数解析php,函数,Discuz,param,Discuz二次开发?php/*[Discuz!](C)2001-2007ComsenzInc.ThisisNOTafreeware,useissubjecttolicenseterms$Id:global.func.php134262008-04-1503:37:02Zheyond$*/if(!defined('IN_DISCUZ')){exit('AccessDenied');}/***加密或者解密用户信息*@param$string-加密或解密的串*@param$operation-加密还是解密*@param密钥*@return返回字符串*$ckey_length随机密钥长度取值0-32;*加入随机密钥,可以令密文无任何规律,即便是原文和密钥完全相同,加密结果也会每次不同,增大破解难度。*取值越大,密文变动规律越大,密文变化=16的$ckey_length次方*当此值为0时,则不产生随机密钥*/functionauthcode($string,$operation='DECODE',$key='',$expiry=0){$ckey_length=4;$key=md5($key?$key:$GLOBALS['discuz_auth_key']);$keya=md5(substr($key,0,16));$keyb=md5(substr($key,16,16));$keyc=$ckey_length?($operation=='DECODE'?substr($string,0,$ckey_length):substr(md5(microtime()),-$ckey_length)):'';$cryptkey=$keya.md5($keya.$keyc);$key_length=strlen($cryptkey);$string=$operation=='DECODE'?base64_decode(substr($string,$ckey_length)):sprintf('%010d',$expiry?$expiry+time():0).substr(md5($string.$keyb),0,16).$string;$string_length=strlen($string);$result='';$box=range(0,255);$rndkey=array();for($i=0;$i=255;$i++){$rndkey[$i]=ord($cryptkey[$i%$key_length]);}for($j=$i=0;$i256;$i++){$j=($j+$box[$i]+$rndkey[$i])%256;$tmp=$box[$i];$box[$i]=$box[$j];$box[$j]=$tmp;}for($a=$j=$i=0;$i$string_length;$i++){$a=($a+1)%256;$j=($j+$box[$a])%256;$tmp=$box[$a];$box[$a]=$box[$j];$box[$j]=$tmp;$result.=chr(ord($string[$i])^($box[($box[$a]+$box[$j])%256]));}if($operation=='DECODE'){if((substr($result,0,10)==0||substr($result,0,10)-time()0)&&substr($result,10,16)==substr(md5(substr($result,26).$keyb),0,16)){returnsubstr($result,26);}else{return'';}}else{return$keyc.str_replace('=','',base64_encode($result));}}/***清理cookie*/functionclearcookies(){global$discuz_uid,$discuz_user,$discuz_pw,$discuz_secques,$adminid,$credits;dsetcookie('sid','',-86400*365);dsetcookie('auth','',-86400*365);dsetcookie('visitedfid','',-86400*365);dsetcookie('onlinedetail','',-86400*365,0);dsetcookie('loginuser','',-86400*365);dsetcookie('activationauth','',-86400*365);$discuz_uid=$adminid=$credits=0;$discuz_user=$discuz_pw=$discuz_secques='';}/***检查积分下限*@param$creditsarray-积分数组*@param$coef-积分*/functionchecklowerlimit($creditsarray,$coef=1){if(is_array($creditsarray)){global$extcredits,$id;foreach($creditsarrayas$id=$addcredits){$addcredits=$addcredits*$coef;if($addcredits0&&($GLOBALS['extcredits'.$id]$extcredits[$id]['lowerlimit']||(($GLOBALS['extcredits'.$id]+$addcredits)$extcredits[$id]['lowerlimit']))){if($coef==1){showmessage('credits_policy_lowerlimit');}else{showmessage('credits_policy_num_lowerlimit');}}}}}/***密码检测**@paramstring$md5*@paramstring$verified*@paramstring$salt*@return*0=Failed*1=MD5withsalt,2=DualMD5,3=NormalMd54=MD5-16*/functioncheckmd5($md5,$verified,$salt=''){if(md5($md5.$salt)==$verified){$result=!empty($salt)?1:2;}elseif(empty($salt)){$result=$md5==$verified?3:((strlen($verified)==16&&substr($md5,8,16)==$verified)?4:0);}else{$result=0;}return$result;}/***检查模板源文件是否更新*当编译文件不存时强制重新编译*当tplrefresh=1时检查文件*当tplrefresh1时,则根据tplrefresh取余,无余时则检查更新**/functionchecktplrefresh($maintpl,$subtpl,$timecompare,$templateid,$tpldir){global$tplrefresh;if(empty($timecompare)||$tplrefresh==1||($tplrefresh1&&!($GLOBALS['timestamp']%$tplrefresh))){if(empty($timecompare)||@filemtime($subtpl)$timecompare){require_onceDISCUZ_ROOT.'./include/template.func.php';parse_template($maintpl,$templateid,$tpldir);returnTRUE;}}returnFALSE;}/***根据中文裁减字符串*@param$string-字符串*@param$length-长度*@param$doc-缩略后缀*@return返回带省略号被裁减好的字符串*/functioncutstr($string,$length,$dot='...'){global$charset;if(strlen($string)=$length){return$string;}$string=str_replace(array('&','','',''),array('&','','',''),$string);$strcut='';if(strtolower($charset)=='utf-8'){$n=$tn=$noc=0;while($nstrlen($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&&$t239){$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;$i++){$strcut.=ord($string[$i])127?$string[$i].$string[++$i]:$string[$i];}}$strcut=str_replace(array('&','','',''),array('&','','',''),$strcut);return$strcut.$dot;}/***处理转义字符*@param$string-字符串*@param$force-是否强制*@return返回整理好的字符串*/functiondaddslashes($string,$force=0){!defined('MAGIC_QUOTES_GPC')&&define('MAGIC_QUOTES_GPC',get_magic_quotes_gpc());if(!MAGIC_QUOTES_GPC||$force){if(is_array($string)){foreach($stringas$key=$val){$string[$key]=daddslashes($val,$force);}}else{$string=addslashes($string);}}return$string;}/***检测日期的有效性*/functiondatecheck($ymd,$sep='-'){if(!empty($ymd)){list($year,$month,$day)=explode($sep,$ymd);returncheckdate($month,$day,$year);}else{returnFALSE;}}/***调试信息*/functiondebuginfo(){if($GLOBALS['debug']){global$db,$discuz_starttime,$debuginfo;$mtime=explode('',microtime());$debuginfo=array('time'=number_format(($
本文标题:Discuz!常用函数解析
链接地址:https://www.777doc.com/doc-5912893 .html