📄 global.func.php
字号:
<?php
/*
[Discuz!] (C)2001-2007 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$RCSfile: global.func.php,v $
$Revision: 1.156.2.17 $
$Date: 2007/03/21 15:52:38 $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
function authcode($string, $operation, $key = '') {
$key = md5($key ? $key : $GLOBALS['discuz_auth_key']);
$key_length = strlen($key);
$string = $operation == 'DECODE' ? base64_decode($string) : substr(md5($string.$key), 0, 8).$string;
$string_length = strlen($string);
$rndkey = $box = array();
$result = '';
for($i = 0; $i <= 255; $i++) {
$rndkey[$i] = ord($key[$i % $key_length]);
$box[$i] = $i;
}
for($j = $i = 0; $i < 256; $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, 8) == substr(md5(substr($result, 8).$key), 0, 8)) {
return substr($result, 8);
} else {
return '';
}
} else {
return str_replace('=', '', base64_encode($result));
}
}
function clearcookies() {
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);
$discuz_uid = $adminid = $credits = 0;
$discuz_user = $discuz_pw = $discuz_secques = '';
}
function checklowerlimit($creditsarray, $coef = 1) {
if(is_array($creditsarray)) {
global $extcredits, $id;
foreach($creditsarray as $id => $addcredits) {
if($addcredits * $coef < 0 && $GLOBALS['extcredits'.$id] - $addcredits < $extcredits[$id]['lowerlimit']) {
showmessage('credits_policy_lowerlimit');
}
}
}
}
function cutstr($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($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];
}
}
$strcut = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $strcut);
return $strcut.$dot;
}
function daddslashes($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($string as $key => $val) {
$string[$key] = daddslashes($val, $force);
}
} else {
$string = addslashes($string);
}
}
return $string;
}
function datecheck($ymd, $sep='-') {
if(!empty($ymd)) {
list($year, $month, $day) = explode($sep, $ymd);
return checkdate($month, $day, $year);
} else {
return FALSE;
}
}
function debuginfo() {
if($GLOBALS['debug']) {
global $db, $discuz_starttime, $debuginfo;
$mtime = explode(' ', microtime());
$debuginfo = array('time' => number_format(($mtime[1] + $mtime[0] - $discuz_starttime), 6), 'queries' => $db->querynum);
return TRUE;
} else {
return FALSE;
}
}
function dexit($message = '') {
echo $message;
output();
exit();
}
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 dheader($string, $replace = true, $http_response_code = 0) {
$string = str_replace(array("\r", "\n"), array('', ''), $string);
if(empty($http_response_code) || PHP_VERSION < '4.3' ) {
@header($string, $replace);
} else {
@header($string, $replace, $http_response_code);
}
if(preg_match('/^\s*location:/is', $string)) {
exit();
}
}
function disuploadedfile($file) {
return function_exists('is_uploaded_file') && (is_uploaded_file($file) || is_uploaded_file(str_replace('\\\\', '\\', $file)));
}
function dreferer($default = '') {
global $referer, $indexname;
$default = empty($default) ? $indexname : '';
if(empty($referer) && isset($GLOBALS['_SERVER']['HTTP_REFERER'])) {
$referer = preg_replace("/([\?&])((sid\=[a-z0-9]{6})(&|$))/i", '\\1', $GLOBALS['_SERVER']['HTTP_REFERER']);
$referer = substr($referer, -1) == '?' ? substr($referer, 0, -1) : $referer;
} else {
$referer = dhtmlspecialchars($referer);
}
if(!preg_match("/(\.php|[a-z]+(\-\d+)+\.html)/", $referer) || strpos($referer, 'logging.php')) {
$referer = $default;
}
return $referer;
}
function dsetcookie($var, $value, $life = 0, $prefix = 1) {
global $cookiepre, $cookiedomain, $cookiepath, $timestamp, $_SERVER;
setcookie(($prefix ? $cookiepre : '').$var, $value,
$life ? $timestamp + $life : 0, $cookiepath,
$cookiedomain, $_SERVER['SERVER_PORT'] == 443 ? 1 : 0);
}
function dunlink($filename, $havethumb = 0, $remote = 0) {
global $authkey, $ftp, $attachdir;
if($remote) {
require_once DISCUZ_ROOT.'./include/ftp.func.php';
if(!$ftp['connid']) {
if(!($ftp['connid'] = dftp_connect($ftp['host'], $ftp['username'], authcode($ftp['password'], 'DECODE', md5($authkey)), $ftp['attachdir'], $ftp['port'], $ftp['ssl']))) {
return;
}
}
dftp_delete($ftp['connid'], $filename);
$havethumb && dftp_delete($ftp['connid'], $filename.'.thumb.jpg');
} else {
@unlink($attachdir.'/'.$filename);
$havethumb && @unlink($attachdir.'/'.$filename.'.thumb.jpg');
}
}
function emailconv($email, $tolink = 1) {
$email = str_replace(array('@', '.'), array('@', '.'), $email);
return $tolink ? '<a href="mailto: '.$email.'">'.$email.'</a>': $email;
}
function errorlog($type, $message, $halt = 1) {
global $timestamp, $discuz_userss, $onlineip, $_SERVER;
$user = empty($discuz_userss) ? '' : $discuz_userss.'<br>';
$user .= $onlineip.'|'.$_SERVER['REMOTE_ADDR'];
writelog('errorlog', dhtmlspecialchars("$timestamp\t$type\t$user\t".str_replace(array("\r", "\n"), array(' ', ' '), trim($message))));
if($halt) {
dexit();
}
}
function getrobot() {
if(!defined('IS_ROBOT')) {
$kw_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
$kw_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';
if(preg_match("/($kw_browsers)/", $_SERVER['HTTP_USER_AGENT'])) {
define('IS_ROBOT', FALSE);
} elseif(preg_match("/($kw_spiders)/", $_SERVER['HTTP_USER_AGENT'])) {
define('IS_ROBOT', TRUE);
} else {
define('IS_ROBOT', FALSE);
}
}
return IS_ROBOT;
}
function fileext($filename) {
return trim(substr(strrchr($filename, '.'), 1, 10));
}
function formhash() {
global $discuz_user, $discuz_uid, $discuz_pw, $timestamp, $discuz_auth_key;
return substr(md5(substr($timestamp, 0, -7).$discuz_user.$discuz_uid.$discuz_pw.$discuz_auth_key), 8, 8);
}
function forumperm($permstr) {
global $groupid, $extgroupids;
$groupidarray = array($groupid);
foreach(explode("\t", $extgroupids) as $extgroupid) {
if($extgroupid = intval(trim($extgroupid))) {
$groupidarray[] = $extgroupid;
}
}
return preg_match("/(^|\t)(".implode('|', $groupidarray).")(\t|$)/", $permstr);
}
function getgroupid($uid, $group, &$member) {
global $creditsformula, $db, $tablepre;
if(!empty($creditsformula)) {
$updatearray = array();
eval("\$credits = round($creditsformula);");
if($credits != $member['credits']) {
$updatearray[] = "credits='$credits'";
}
if($group['type'] == 'member' && !($member['credits'] >= $group['creditshigher'] && $member['credits'] < $group['creditslower'])) {
$query = $db->query("SELECT groupid FROM {$tablepre}usergroups WHERE type='member' AND $member[credits]>=creditshigher AND $member[credits]<creditslower LIMIT 1");
if($db->num_rows($query)) {
$member['groupid'] = $db->result($query, 0);
$updatearray[] = "groupid='$member[groupid]'";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -