📄 global.func.php
字号:
<?php
/*
[Discuz!] (C)2001-2006 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$RCSfile: global.func.php,v $
$Revision: 1.83.2.6 $
$Date: 2006/09/28 02:34:15 $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
function authcode($string, $operation, $key = '') {
$key = $key ? $key : $GLOBALS['discuz_auth_key'];
$coded = '';
$keylength = strlen($key);
$string = $operation == 'DECODE' ? base64_decode($string) : $string;
for($i = 0; $i < strlen($string); $i += $keylength) {
$coded .= substr($string, $i, $keylength) ^ $key;
}
$coded = $operation == 'ENCODE' ? str_replace('=', '', base64_encode($coded)) : $coded;
return $coded;
}
function avatarshow($id, $gender = 0) {
global $discuz_uid, $avatarshowid, $avatarshow_license, $avatarshowlink, $avatarshowheight, $avatarshowwidth;
return '<iframe marginwidth="0" marginheight="0" frameborder="0" scrolling="no" height="'.$avatarshowheight.'" width="'.$avatarshowwidth.'" src="api/avatarshow.php?uid='.$discuz_uid.'&thisid='.$avatarshowid.'&id='.$id.'&license='.$avatarshow_license.'&width='.$avatarshowwidth.'&height='.$avatarshowheight.'gender='.$gender.'&link='.$avatarshowlink.'"></iframe>';
}
function clearcookies() {
global $timestamp, $cookiepath, $cookiedomain, $discuz_uid, $discuz_user, $discuz_pw, $discuz_secques, $adminid, $groupid, $credits;
dsetcookie('auth', '', -86400 * 365);
dsetcookie('visitedfid', '', -86400 * 365);
// clear cookies defined in older version (transitional operation)
dsetcookie('_discuz_uid', '', -86400 * 365, 0);
dsetcookie('_discuz_pw', '', -86400 * 365, 0);
dsetcookie('_discuz_secques', '', -86400 * 365, 0);
dsetcookie('onlinedetail', '', -86400 * 365, 0);
// end
$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] < $extcredits[$id]['lowerlimit']) {
showmessage('credits_policy_lowerlimit');
}
}
}
}
function cutstr($string, $length, $dot = ' ...') {
global $charset;
if(strlen($string) <= $length) {
return $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];
}
}
return $strcut.$dot;
}
function daddslashes($string, $force = 0) {
if(!$GLOBALS['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 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 $tablepre, $cookiedomain, $cookiepath, $timestamp, $_SERVER;
setcookie(($prefix ? $tablepre : '').$var, $value,
$life ? $timestamp + $life : 0, $cookiepath,
$cookiedomain, $_SERVER['SERVER_PORT'] == 443 ? 1 : 0);
}
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;
@$fp = fopen(DISCUZ_ROOT.'./forumdata/errorlog.php', 'a');
@fwrite($fp, "<?PHP exit('Access Denied'); ?>\t$timestamp\t$type\t$discuz_userss\t".str_replace(array("\r", "\n"), array(' ', ' '), trim(dhtmlspecialchars($message)))."\n");
@fclose($fp);
if($halt) {
dexit();
}
}
function fileext($filename) {
return trim(substr(strrchr($filename, '.'), 1));
}
function formhash() {
global $discuz_user, $discuz_uid, $discuz_pw, $timestamp;
return substr(md5(substr($timestamp, 0, -7).$discuz_user.$discuz_uid.$discuz_pw), 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]'";
}
}
if($updatearray) {
$db->query("UPDATE {$tablepre}members SET ".implode(', ', $updatearray)." WHERE uid='$uid'");
}
}
return $member['groupid'];
}
function groupexpiry($terms) {
$terms = is_array($terms) ? $terms : unserialize($terms);
$groupexpiry = isset($terms['main']['time']) ? intval($terms['main']['time']) : 0;
if(is_array($terms['ext'])) {
foreach($terms['ext'] as $expiry) {
if((!$groupexpiry && $expiry) || $expiry < $groupexpiry) {
$groupexpiry = $expiry;
}
}
}
return $groupexpiry;
}
function image($imageinfo, $basedir = '', $remark = '') {
if($basedir) {
$basedir .= '/';
}
if(strstr($imageinfo, ',')) {
$flash = explode(",", $imageinfo);
return "<embed src=\"$basedir".trim($flash[0])."\" width=\"".trim($flash[1])."\" height=\"".trim($flash[2])."\" type=\"application/x-shockwave-flash\" $remark></embed>";
} else {
return "<img src=\"$basedir$imageinfo\" $remark border=\"0\" />";
}
}
function ipaccess($ip, $accesslist) {
return preg_match("/^(".str_replace(array("\r\n", ' '), array('|', ''), preg_quote($accesslist, '/')).")/", $ip);
}
function ipbanned($onlineip) {
global $ipaccess, $timestamp, $cachelost;
if($ipaccess && !ipaccess($onlineip, $ipaccess)) {
return TRUE;
}
$cachelost .= (@include DISCUZ_ROOT.'./forumdata/cache/cache_ipbanned.php') ? '' : ' ipbanned';
if(empty($_DCACHE['ipbanned'])) {
return FALSE;
} else {
if($_DCACHE['ipbanned']['expiration'] < $timestamp) {
@unlink(DISCUZ_ROOT.'./forumdata/cache/cache_ipbanned.php');
}
return preg_match("/^(".$_DCACHE['ipbanned']['regexp'].")$/", $onlineip);
}
}
function isemail($email) {
return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-]+(\.\w+)+$/", $email);
}
function ispage($number) {
return !empty($number) && preg_match ("/^([0-9]+)$/", $number);
}
function language($file, $templateid = 0, $tpldir = '') {
$tpldir = $tpldir ? $tpldir : TPLDIR;
$templateid = $templateid ? $templateid : TEMPLATEID;
$languagepack = DISCUZ_ROOT.'./'.$tpldir.'/'.$file.'.lang.php';
if(file_exists($languagepack)) {
return $languagepack;
} elseif($templateid != 1 && $tpldir != './templates/default') {
return language($file, 1, './templates/default');
} else {
return FALSE;
}
}
function multi($num, $perpage, $curpage, $mpurl, $maxpages = 0) {
$multipage = '';
$mpurl .= strpos($mpurl, '?') ? '&' : '?';
if($num > $perpage) {
$page = 10;
$offset = 2;
$realpages = @ceil($num / $perpage);
$pages = $maxpages && $maxpages < $realpages ? $maxpages : $realpages;
if($page > $pages) {
$from = 1;
$to = $pages;
} else {
$from = $curpage - $offset;
$to = $from + $page - 1;
if($from < 1) {
$to = $curpage + 1 - $from;
$from = 1;
if($to - $from < $page) {
$to = $page;
}
} elseif($to > $pages) {
$from = $pages - $page + 1;
$to = $pages;
}
}
$multipage = ($curpage - $offset > 1 && $pages > $page ? '<a class="p_redirect" href="'.$mpurl.'page=1">|‹</a>' : '').
($curpage > 1 ? '<a class="p_redirect" href="'.$mpurl.'page='.($curpage - 1).'">‹‹</a>' : '');
for($i = $from; $i <= $to; $i++) {
$multipage .= $i == $curpage ? '<a class="p_curpage">'.$i.'</a>' :
'<a href="'.$mpurl.'page='.$i.'" class="p_num">'.$i.'</a>';
}
$multipage .= ($curpage < $pages ? '<a class="p_redirect" href="'.$mpurl.'page='.($curpage + 1).'">››</a>' : '').
($to < $pages ? '<a class="p_redirect" href="'.$mpurl.'page='.$pages.'">›|</a>' : '').
($curpage == $maxpages ? '<a class="p_redirect" href="misc.php?action=maxpages&pages='.$maxpages.'">›?</a>' : '').
($pages > $page ? '<a class="p_pages" style="padding: 0px"><input class="p_input" type="text" name="custompage" onKeyDown="if(event.keyCode==13) {window.location=\''.$mpurl.'page=\'+this.value; return false;}"></a>' : '');
$multipage = $multipage ? '<div class="p_bar"><a class="p_total"> '.$num.' </a><a class="p_pages"> '.$curpage.'/'.$realpages.' </a>'.$multipage.'</div>' : '';
}
return $multipage;
}
function output() {
global $sid, $transsidstatus, $rewritestatus;
if(($transsidstatus = empty($GLOBALS['_DCOOKIE']['sid']) && $transsidstatus) || in_array($rewritestatus, array(2, 3))) {
if($transsidstatus) {
$searcharray = array
(
"/\<a(\s*[^\>]+\s*)href\=([\"|\']?)([^\"\'\s]+)/ies",
"/(\<form.+?\>)/is"
);
$replacearray = array
(
"transsid('\\3','<a\\1href=\\2')",
"\\1\n<input type=\"hidden\" name=\"sid\" value=\"$sid\">"
);
} else {
$searcharray = array
(
//"/\<a href\=\"index\.php\"\>/",
"/\<a href\=\"forumdisplay\.php\?fid\=(\d+)(&page\=(\d+))?\"([^\>]*)\>/e",
"/\<a href\=\"viewthread\.php\?tid\=(\d+)(&extra\=page\%3D(\d+))?(&page\=(\d+))?\"([^\>]*)\>/e",
"/\<a href\=\"viewpro\.php\?(uid\=(\d+)|username\=([^&]+?))\"([^\>]*)\>/e"
);
$replacearray = array
(
//"<a href=\"index.html\">",
"rewrite_forum('\\1', '\\3', '\\4')",
"rewrite_thread('\\1', '\\5', '\\3', '\\6')",
"rewrite_profile('\\2', '\\3', '\\4')"
);
}
$content = preg_replace($searcharray, $replacearray, ob_get_contents());
ob_end_clean();
$GLOBALS['gzipcompress'] ? ob_start('ob_gzhandler') : ob_start();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -