global.php

来自「极限OA开源系统」· PHP 代码 · 共 181 行

PHP
181
字号
<?php

function union_htmlspecialchars($string) {
	if(is_array($string)) {
		foreach($string as $key => $val) {
			$string[$key] = union_htmlspecialchars($val);
		}
	} else {
		$string = str_replace("\"", "&quot;", $string);
		$string = str_replace("<", "&lt;", $string);
		$string = str_replace(">", "&gt;", $string);
	}
	return $string;
}
function union_setcookie($name,$value="",$permanent=31536000) {
  global $set_cookiepath,$set_cookiedomain;
  $set_cookiepath = ''; 
  $set_cookiedomain = '';

  $expire=time() + $permanent;
  $secure = 0;
  
  setcookie($name, $value, $expire, $set_cookiepath, $set_cookiedomain, $secure);

}
function clearcookies() {
	global $union_user, $union_pass, $status;
	union_setcookie('union_user_', '');
	union_setcookie('union_pass_', '');
	$union_user = $union_pass = '';
}
function url_rewriter($url, $tag = '') {
	global $sid;
	$tag = stripslashes($tag);
	return $tag.$url;
}
function union_end() {
	global $db;
	session_update();
	//$db->close();
}
function union_addslashes($string) {
	if(!$GLOBALS[$magic_quotes_gpc]) {
		if(is_array($string)) {
			foreach($string as $key => $val) {
				$string[$key] = union_addslashes($val);
			}
		} else {
			$string = addslashes($string);
		}
	}
	return $string;
}

function session_update() {
	global $db, $sess_arr, $etext, $UNION_CACHE, $creatsession, $sessionupdated, $cachetime, $set_cachetime, $sid, $ssid, $yip, $ipbanned, $hidden, $md5vali, $union_uid, $credit, $union_user, $timestamp, $gid, $bbsid, $themeid, $user_action, $set_onlinehold, $logincredits, $table_sessions, $table_members;
	
	$etext = array('username'=>$union_user,'themeid'=>$themeid,'action'=>$user_action,'ip'=>$yip,'hidden'=>$hidden,'ltime'=>$timestamp);
	session_register('sess_arr');
	

	if(($timestamp-$cachetime>$set_cachetime) || empty($cachetime)) {
		$db->query("UPDATE $table_sessions SET ltime='$timestamp'");
	}
}

function showmessage($message_, $url_forward = '',$url_to = '') {
	extract($GLOBALS, EXTR_OVERWRITE);

	$show_message = "".$message_;
	if(strpos($message_, "返回")) {
		$show_message .= "<br><br><a href=\"javascript:history.go(-1);\" class=\"mediumtxt\">[ 点这里返回上一页 ]</a>";
	}
	if($url_forward) {
		$show_message .= "<br><br><a href=\"$url_forward\">如果您的浏览器没有自动跳转,请点击这里</a>";
		$show_message .= "<meta http-equiv=\"refresh\" content=\"2;url=$url_forward\">";
	}
	if($url_to) {
		$show_message .= "<br><br><a href=\"$url_to\" style=\"color:black\">[ 点击这里确认 ]</a>\n";
	}
	include getData('showmessage');
	new gzip_encode($GLOBALS['set_gziplevel']);exit;

}
function checkright($k1,$k2='',$k3='') {
	global $union_rights;
	if($k1 && !$k2 && !$k3) {
		if(!$union_rights[$k1][value]) {
			showmessage("对不起 您没有操作".$union_rights[$k1][name]."的权限");
		}
	}elseif($k1 && $k2 && !$k3) {
		if(!$union_rights[$k1]['vk'][$k2][value]) {
			showmessage("对不起 您没有操作".$union_rights[$k1]['vk'][$k2][name]."的权限");
		}
	}elseif($k1 && $k2 && $k3) {
		if(!$union_rights[$k1]['vk'][$k2][vs][$k3]) {
			$tmp = array(0=>'浏览',1=>'查询',2=>'添加',3=>'修改',4=>'删除',);
			showmessage("对不起 您没有".$union_rights[$k1]['vk'][$k2][name].'的'.$tmp[$k3]."以上的权限");
		}
	}
}

function getData($file) {
	$cachefile = "./data/temp/_$file.php";

	return $cachefile;
}

function sizecount($s) {
    if($s>1073741824) {
        $rs = sprintf("%01.2f",$s/1073741824)." GB";
    }elseif($s>1048576) {
        $rs = sprintf("%01.2f",$s/1048576)." MB";
    }elseif($s>=1024) {
        $rs = sprintf("%01.2f",$s/1024)." Kb";
    }else {
        $rs = $size." bytes";
    }
    return $rs;
}
function random($l) {
	$letter = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
	mt_srand((double)microtime() * 1000000);
	for($i=0;$i<$l;$i++) {
		$s .= $letter[mt_rand(0,61)];
	}
	return $s;
}

function wordscut($s,$l,$b='...') {
	if (strlen($s)>$l) {
		$temp = 0;
		for($i=0; $i<$l; $i++) {
			ord($s[$i])>128?$t++:'';
		}
		($t%2 == 0)?($s=substr($s,0,$l).$b):($s=substr($s,0,$l+1).$b);
	} 
	return $s; 
} 
function usestat() {
	extract($GLOBALS, EXTR_OVERWRITE);
	include $union_root.'./includes/count.php';
}


function pages($num, $perpage, $nowpage, $scripturl) {
	global $pages2;
	$pages2 = pages2($nowpage);
	$pages = ceil($num / $perpage);

	$p_hm = "分页";
	$p_hm .= "&nbsp; ";
	$p_hm .= $nowpage == 1?"首页":"<a href=\"$scripturl&page=1\">首页</a>";
	$p_hm .= "&nbsp; ";
	$p_hm .= ($nowpage > 1)?"<a href=\"$scripturl&page=".($nowpage-1)."\">前页</a>":"前页";
	$p_hm .= "&nbsp; ";
	$p_hm .= ($pages > 1 && $nowpage < $pages)?"<a href=\"$scripturl&page=".($nowpage+1)."\">后页</a>":"后页";
	$p_hm .= "&nbsp; ";
	$p_hm .= $nowpage == $pages?"尾页":"<a href=\"$scripturl&page=$pages\">尾页</a>";
	$p_hm .= "&nbsp; ";
	$p_hm .= "页次:$nowpage/$pages 页 <font color=#ff3300>$perpage</font> 条/页 共 <font color=#ff3300>$num</font> 条纪录";
	
	return $p_hm;
}
function pages2($page) {
	$p = "<DIV align=right><P>转到: ";
	$p .= "<INPUT class=input maxLength=10 name=page size=4 value=$page> ";
	$p .= "<INPUT class=button id=button1 type=button value='OK'style='height:21px' onClick='onSubmit()' onMouseOver='onButton(this);' onMouseOut='offButton(this);'>&nbsp;";
	$p .= '</DIV>';
	return $p;
}
function iif ($expression,$returntrue,$returnfalse) {

  if ($expression==0) {
    return $returnfalse;
  } else {
    return $returntrue;
  }

}
?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?