📄 functions.php
字号:
if ($escape==1) {
$template=addslashes($template);
$template=str_replace("\\'","'",$template);
}
if ($gethtmlcomments and $addtemplatename) {
return "<!-- BEGIN TEMPLATE: $templatename -->\n$template\n<!-- END TEMPLATE: $templatename -->";
}
return $template;
}
// ###################### Start verifyid #######################
function verifyid($idname, &$id, $alert=1, $selall=0) {
// verifies an id number and returns a correct one if it can be found
// returns 0 if none found
global $DB_site,$webmasteremail,$session,$threadcache,$forumcache;
$id=intval($id);
if (!isset($id) or $id==0 or $id=="") {
if ($alert) { // show alert?
eval("standarderror(\"".gettemplate('error_noid')."\");");
exit;
}
} else {
if ($selall==1) {
$selid = '*';
} else {
$selid = $idname.'id';
}
if (!$check=$DB_site->query_first("SELECT $selid FROM $idname WHERE $idname"."id=$id")) {
if ($alert) { // show alert?
eval("standarderror(\"".gettemplate('error_invalidid')."\");");
exit;
}
} else {
if ($selall!=1) {
return $check["$selid"];
} else {
return $check;
} //if ($selall!=1) {
} //if ($idname=="thread" and isset($threadcache["$id"])) {
} //if (!isset($id) or $id==0 or $id=="") {
}
// ###################### Start getpermissions #######################
function getpermissions($forumid=0,$userid=-1,$usergroupid=-1,$parentlist="") {
// gets permissions, depending on given userid and forumid
global $DB_site, $usercache, $bbuserinfo, $enableaccess, $table;
static $permscache, $usergroupcache;
$userid=intval($userid);
if ($userid==-1) {
$userid=$bbuserinfo['userid'];
$usergroupid=$bbuserinfo['usergroupid'];
}
if ($usergroupid==-1 or $usergroupid==0) {
if ($userid==0) {
$usergroupid=1;
} else {
if (isset($usercache["$userid"])) {
$usergroupid=$usercache["$userid"]['usergroupid'];
} else {
$getuser=$DB_site->query_first("SELECT usergroupid FROM ".$table["user"]." WHERE userid=$userid");
$usergroupid=$getuser['usergroupid'];
}
}
}
if (!isset($usergroupcache["$usergroupid"])) {
$usergroupcache["$usergroupid"] = $DB_site->query_first("SELECT * FROM ".$table["usergroup"]." WHERE usergroupid=$usergroupid");
return $usergroupcache["$usergroupid"];
} else {
return $usergroupcache["$usergroupid"];
}
}
// ###################### Start countchar #######################
function countchar($string,$char) {
//counts number of times $char occus in $string
$charpos=strstr($string,$char);
if ($charpos!="") {
return countchar(substr($charpos,strlen($char)),$char)+1;
} else {
return 0;
}
}
// ###################### Start gzipoutput #######################
function gzipoutput($text,$level=1){
global $HTTP_ACCEPT_ENCODING,$nozip;
$returntext=$text;
if (function_exists("crc32") and function_exists("gzcompress") and !$nozip){
if (strpos(" ".$HTTP_ACCEPT_ENCODING,"x-gzip")) {
$encoding = "x-gzip";
}
if (strpos(" ".$HTTP_ACCEPT_ENCODING,"gzip")) {
$encoding = "gzip";
}
if ($encoding) {
header("Content-Encoding: $encoding");
$size = strlen($text);
$crc = crc32($text);
$returntext = "\x1f\x8b\x08\x00\x00\x00\x00\x00";
$returntext .= substr(gzcompress($text,$level),0,-4);
$returntext .= pack("V",$crc);
$returntext .= pack("V",$size);
}
}
return $returntext;
}
// ###################### Start vbsetcookie #######################
function vbsetcookie($name,$value="",$permanent=1) {
global $cookiepath,$cookiedomain, $SERVER_PORT;
if ($permanent) {
$expire=time() + 60*60*24*365;
} else {
$expire = 0;
}
if ($SERVER_PORT == "443") {
// we're using SSL
$secure = 1;
} else {
$secure = 0;
}
if (defined('USE_COOKIE_WORKAROUND')) {
// It's been reported that there's a bug in PHP 4.2.0/4.2.1 with Apache 2 causing setcookie() to not work correctly.
// This is the workaround. If you need to use this code, please add:
// define('USE_COOKIE_WORKAROUND', 1);
// to your config.php.
if (!$value) {
// need to do this so IE deletes the cookie correctly
$expire = time() - 31536001;
$value = 'deleted';
}
$cookieheader = "Set-Cookie: $name=".urlencode($value);
if ($expire) {
$cookieheader .= '; expires='.gmdate('D, d-M-Y H:i:s', $expire).' GMT';
}
if ($cookiepath) {
$cookieheader .= "; path=$cookiepath";
}
if ($cookiedomain) {
$cookieheader .= "; domain=$cookiedomain";
}
if ($secure) {
$cookieheader .= '; secure';
}
header($cookieheader, false); // force multiple headers of same type
} else {
setcookie($name, $value, $expire, $cookiepath, $cookiedomain, $secure);
}
}
// ###################### Start show_nopermission #######################
function show_nopermission($noheadfoot=0) {
global $webtitle,$logincode,$url,$scriptpath,$bbuserinfo,$session,$headinclude;
// generate 'logged in as:' box or username and pwd box
if (!$logincode) {
$logincode=makelogincode();
}
if ($bbuserinfo[userid]==0) {
if ($noheadfoot==0) {
eval("standarderror(\"".gettemplate("error_nopermission_loggedout")."\");");
} else {
eval("dooutput(\"".gettemplate("error_nopermission_loggedout_nohead")."\");");
}
} else {
if ($noheadfoot==0) {
eval("standarderror(\"".gettemplate("error_nopermission_loggedin")."\");");
} else {
eval("dooutput(\"".gettemplate("error_nopermission_loggedin_nohead")."\");");
}
}
exit;
}
// ###################### Start vbdate #######################
function vbdate($format,$timestamp) {
global $bbuserinfo,$timeoffset;
return date($format,$timestamp+($bbuserinfo['timezoneoffset']-$timeoffset)*3600);
}
// ###################### Start getextension #######################
function getextension($filename) {
return substr(strrchr($filename,"."),1);
}
// ###################### Start make login code #######################
function makelogincode() {
global $DB_site,$bbuserinfo,$session;
if ($bbuserinfo['userid']==0) {
eval("\$logincode = \"".gettemplate("username_loggedout")."\";");
} else {
eval("\$logincode = \"".gettemplate("username_loggedin")."\";");
}
return $logincode;
}
// ###################### Start un htmlspecialchars #######################
function unhtmlspecialchars($chars) {
if (floor(phpversion())<4) {
//php3
$temp=addslashes($chars);
$temp=preg_replace("/(&#)([0-9]*)(;)/siU","\".chr(intval('\\2')).\"",$temp);
eval ("\$temp=\"$temp\";");
$chars=stripslashes($temp);
} else {
//php4
$chars=preg_replace("/(&#)([0-9]*)(;)/esiU","chr(intval('\\2'))",$chars);
}
$chars=str_replace(">",">",$chars);
$chars=str_replace("<","<",$chars);
$chars=str_replace(""","\"",$chars);
$chars=str_replace("&","&",$chars);
return $chars;
}
// ###################### Start replacesession ###############
function replacesession($url) {
// replace the sessionhash in $url with the current one
global $session;
$url = addslashes($url);
$url=ereg_replace("s=[a-z0-9]{32}&","",$url);
$url=ereg_replace("\\?s=[a-z0-9]{32}","",$url);
$url=str_replace("s=", "", $url);
if (strpos($url,"?")>0) {
$url .= "&s=$session[dbsessionhash]";
} else {
$url .= "?s=$session[dbsessionhash]";
}
return $url;
}
// ########### add the mysql_escape_string() function if it doesn't exist ######
if (!function_exists("mysql_escape_string")) {
function mysql_escape_string($string) {
$string = str_replace("\\", "\\\\", $string);
$string = str_replace("\0", '\0', $string);
$string = str_replace("\n", '\n', $string);
$string = str_replace("\r", '\r', $string);
$string = str_replace("'", '\\\'', $string);
$string = str_replace("\"", '\"', $string);
$string = str_replace("\032", "\\Z", $string);
return $string;
}
}
// ###################### Start get_bbthreadcookie #######################
$bbcookiecache = array();
function get_bbarraycookie($cookiename, $id) {
// gets the value for a array stored in a cookie
global $HTTP_COOKIE_VARS;
global $bbcookiecache;
if (!isset($bbcookiecache[$cookiename])) {
$bbcookiecache[$cookiename] = @unserialize($HTTP_COOKIE_VARS["bb$cookiename"]);
}
return intval($bbcookiecache[$cookiename][$id]);
}
// ###################### Start set_bbthreadcookie #######################
function set_bbarraycookie($cookiename, $id, $value, $permanent = 0) {
// sets the value for a array and sets the cookie
global $HTTP_COOKIE_VARS;
global $bbcookiecache;
if (!isset($bbcookiecache[$cookiename])) {
$bbcookiecache[$cookiename] = @unserialize($HTTP_COOKIE_VARS["bb$cookiename"]);
}
$bbcookiecache[$cookiename][$id] = $value;
vbsetcookie("bb$cookiename", serialize($bbcookiecache[$cookiename]), $permanent);
}
// ###################### Start doshutdown #######################
$shutdownqueries=array();
function doshutdown() {
global $shutdownqueries,$DB_site,$table;
if (is_array($shutdownqueries)) {
while (list($devnul,$query)=each($shutdownqueries)) {
$DB_site->query($query);
}
}
global $cookietimeout,$bypass,$bbuserinfo,$session;
if ($bypass and $bbuserinfo['userid']) {
// if the user has sent bypass=1 through the url (to prevent updating of last activity/visit time), reset the session
// so the below function doesn't do update their info anyway
$userinfo=$DB_site->query_first("SELECT lastactivity FROM ".$table["user"]." WHERE userid='$bbuserinfo[userid]'");
$DB_site->query("UPDATE ".$table["session"]." SET lastactivity='$userinfo[lastactivity]' WHERE sessionhash='".addslashes($session['dbsessionhash'])."'");
}
// update user table from session table in bulk
mt_srand ((double) microtime() * 1000000);
if (mt_rand(1,100)=='50') {
$oldsessions=$DB_site->query("SELECT userid,lastactivity FROM ".$table["session"]." WHERE lastactivity<'".(time()-$cookietimeout)."'");
while ($oldsession=$DB_site->fetch_array($oldsessions)) {
$DB_site->query("UPDATE ".$table["user"]." SET lastactivity=$oldsession[lastactivity] WHERE userid=$oldsession[userid] AND lastactivity<$oldsession[lastactivity]");
}
$DB_site->query("DELETE FROM ".$table["session"]." WHERE lastactivity<".(time()-$cookietimeout));
}
// bye bye!
}
if (!$noshutdownfunc) {
register_shutdown_function("doshutdown");
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -