📄 global.func.php
字号:
(
//"/\<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();
echo $content;
}
}
function rewrite_thread($tid, $page = 0, $prevpage = 0, $extra = '') {
return '<a href="thread-'.$tid.'-'.($page ? $page : 1).'-'.($prevpage ? $prevpage : 1).'.html"'.stripslashes($extra).'>';
}
function rewrite_forum($fid, $page = 0, $extra = '') {
return '<a href="forum-'.$fid.'-'.($page ? $page : 1).'.html"'.stripslashes($extra).'>';
}
function rewrite_profile($uid, $username, $extra = '') {
return '<a href="profile-'.($uid ? 'uid-'.$uid : 'username-'.$username).'.html"'.stripslashes($extra).'>';
}
function payment($amount, $orderid) {
global $bbname, $boardurl, $extcredits, $creditstrans, $timestamp, $authkey, $ec_ratio, $ec_account, $ec_securitycode, $discuz_userss, $onlineip;
$ec_securitycode = authcode($ec_securitycode, 'DECODE', $authkey);
$params = array
(
'subject' => $bbname.' - '.$discuz_userss.' - 积分充值('.$boardurl.')',
'body' => '论坛积分充值 '.$extcredits[$creditstrans]['title'].' '.intval($amount * $ec_ratio).' '.$extcredits[$creditstrans]['unit'].' ('.$onlineip.')',
'order_no' => $orderid,
'date' => gmdate("Ymd", $timestamp + 8 * 3600),
'price' => $amount,
'type' => 2,
'number' => 1,
'transport' => 3,
'seller' => $ec_account,
'partner' => '20880020258585430156'
);
$ac = '';
$url = 'https://www.alipay.com/trade/direct_pay.htm?';
foreach($params as $key => $val) {
$ac .= $key.$val;
$url .= $key.'='.rawurlencode($val).'&';
}
$ac .= $ec_securitycode;
$url .= 'ac='.md5($ac);
return $url;
}
function payto($seller, $detail) {
$detailarray = array();
foreach(array_merge($detail, array('partner' => '20880020258585430156', 'readonly' => 'true')) as $key => $val) {
if($val = trim($val)) {
$detailarray[] = $key.'='.rawurlencode($val);
}
}
return '<a href="https://www.alipay.com/payto:'.$seller.'?'.implode('&', $detailarray).'" target="_blank"><img src="'.IMGDIR.'/alipaybutton.gif" border="0"></a>';
}
function periodscheck($periods, $showmessage = 1) {
global $timestamp, $disableperiodctrl, $_DCACHE, $banperiods;
if(!$disableperiodctrl && $_DCACHE['settings'][$periods]) {
$now = gmdate('G.i', $timestamp + $_DCACHE['settings']['timeoffset'] * 3600);
foreach(explode("\r\n", str_replace(':', '.', $_DCACHE['settings'][$periods])) as $period) {
list($periodbegin, $periodend) = explode('-', $period);
if(($periodbegin > $periodend && ($now >= $periodbegin || $now < $periodend)) || ($oeriodbegin < $periodend && $now >= $periodbegin && $now < $periodend)) {
$banperiods = str_replace("\r\n", ', ', $_DCACHE['settings'][$periods]);
if($showmessage) {
showmessage('period_nopermission', NULL, 'NOPERM');
} else {
return TRUE;
}
}
}
}
return FALSE;
}
function quescrypt($questionid, $answer) {
return $questionid > 0 && $answer != '' ? substr(md5($answer.md5($questionid)), 16, 8) : '';
}
function random($length, $numeric = 0) {
PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
if($numeric) {
$hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
} else {
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
}
return $hash;
}
function sendmail($email_to, $email_subject, $email_message, $email_from = '') {
extract($GLOBALS, EXTR_SKIP);
require DISCUZ_ROOT.'./include/sendmail.inc.php';
}
function sendpm($toid, $subject, $message, $fromid = '', $from = '') {
extract($GLOBALS, EXTR_SKIP);
include language('pms');
if(isset($language[$subject])) {
eval("\$subject = addslashes(\"".$language[$subject]."\");");
}
if(isset($language[$message])) {
eval("\$message = addslashes(\"".$language[$message]."\");");
}
if(!$fromid && !$from) {
$fromid = $discuz_uid;
$from = $discuz_user;
}
foreach(explode(',', $toid) as $uid) {
$db->query("INSERT INTO {$tablepre}pms (msgfrom, msgfromid, msgtoid, folder, new, subject, dateline, message)
VALUES ('$from', '$fromid', '$uid', 'inbox', '1', '$subject', '$timestamp', '$message')");
}
$db->query("UPDATE {$tablepre}members SET newpm='1' WHERE uid IN ($toid)");
}
function showmessage($show_message, $url_forward = '', $extra = '') {
extract($GLOBALS, EXTR_SKIP);
global $extrahead, $discuz_action, $debuginfo, $seccode, $fid, $tid;
if(in_array($extra, array('HALTED', 'NOPERM'))) {
$fid = $tid = 0;
$discuz_action = 254;
} else {
$discuz_action = 255;
}
include language('messages');
if(isset($language[$show_message])) {
eval("\$show_message = \"".$language[$show_message]."\";");
}
$extrahead .= $url_forward ? '<meta http-equiv="refresh" content="3;url='.
(empty($_DCOOKIE['sid']) && $transsidstatus ? transsid($url_forward) : $url_forward).
'">' : '';
if($extra == 'NOPERM' && !$passport_status) {
//get secure code checking status (pos. -2)
if($seccodecheck = substr(sprintf('%05b', $seccodestatus), -2, 1)) {
$seccode = random(4, 1);
}
include template('nopermission');
} else {
include template('showmessage');
}
dexit();
}
function showstars($num) {
global $starthreshold;
$alt = 'alt="Rank: '.$num.'"';
if(empty($starthreshold)) {
for($i = 0; $i < $num; $i++) {
echo '<img src="'.IMGDIR.'/star_level1.gif" '.$alt.'>';
}
} else {
for($i = 3; $i > 0; $i--) {
$numlevel = intval($num / pow($starthreshold, ($i - 1)));
$num = ($num % pow($starthreshold, ($i - 1)));
for($j = 0; $j < $numlevel; $j++) {
echo '<img src="'.IMGDIR.'/star_level'.$i.'.gif" '.$alt.'>';
}
}
}
}
function site() {
return $_SERVER['HTTP_HOST'];
}
function strexists($haystack, $needle) {
return !(strpos($haystack, $needle) === FALSE);
}
function submitcheck($var, $allowget = 0, $seccodecheck = 0) {
if(empty($GLOBALS[$var])) {
return FALSE;
} else {
global $_SERVER, $adminid, $submitrefcheck, $seccode, $seccodeverify;
if($allowget || ($_SERVER['REQUEST_METHOD'] == 'POST' && $GLOBALS['formhash'] == formhash() && (empty($_SERVER['HTTP_REFERER']) ||
preg_replace("/https?:\/\/([^\:\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) == preg_replace("/([^\:]+).*/", "\\1", $_SERVER['HTTP_HOST'])))) {
if($seccodecheck) {
if(intval($seccodeverify) == intval($seccode)) {
$seccode = random(4, 1);
return TRUE;
} else {
showmessage('submit_seccode_invalid');
}
} else {
return TRUE;
}
} else {
showmessage('submit_invalid');
}
}
}
function template($file, $templateid = 0, $tpldir = '') {
global $tplrefresh;
$tpldir = $tpldir ? $tpldir : TPLDIR;
$templateid = $templateid ? $templateid : TEMPLATEID;
$tplfile = DISCUZ_ROOT.'./'.$tpldir.'/'.$file.'.htm';
$objfile = DISCUZ_ROOT.'./forumdata/templates/'.$templateid.'_'.$file.'.tpl.php';
if(TEMPLATEID != 1 && $templateid != 1 && !file_exists($tplfile)) {
return template($file, 1, './templates/default/');
}
if($tplrefresh == 1 || ($tplrefresh > 1 && substr($GLOBALS['timestamp'], -1) > $tplrefresh)) {
if(@filemtime($tplfile) > @filemtime($objfile)) {
require_once DISCUZ_ROOT.'./include/template.func.php';
parse_template($file, $templateid, $tpldir);
}
}
return $objfile;
}
function transsid($url, $tag = '', $wml = 0) {
global $sid;
$tag = stripslashes($tag);
if(!$tag || (!preg_match("/^(http:\/\/|mailto:|#|javascript)/i", $url) && !strpos($url, 'sid='))) {
if($pos = strpos($url, '#')) {
$urlret = substr($url, $pos);
$url = substr($url, 0, $pos);
} else {
$urlret = '';
}
$url .= (strpos($url, '?') ? ($wml ? '&' : '&') : '?').'sid='.$sid.$urlret;
}
return $tag.$url;
}
function typeselect($curtypeid = 0) {
if($threadtypes = $GLOBALS['forum']['threadtypes']) {
$html = '<select name="typeid"><option value="0"> </option>';
foreach($threadtypes['types'] as $typeid => $name) {
$html .= '<option value="'.$typeid.'" '.($curtypeid == $typeid ? 'selected' : '').'>'.strip_tags($name).'</option>';
}
$html .= '</select>';
return $html;
} else {
return '';
}
}
function updatecredits($uids, $creditsarray, $coef = 1, $extrasql = '') {
if($uids && ((!empty($creditsarray) && is_array($creditsarray)) || $extrasql)) {
global $db, $tablepre;
$creditsadd = $comma = '';
foreach($creditsarray as $id => $addcredits) {
$creditsadd .= $comma.'extcredits'.$id.'=extcredits'.$id.'+('.intval($addcredits).')*('.$coef.')';
$comma = ', ';
}
if($creditsadd || $extrasql) {
$db->query("UPDATE {$tablepre}members SET $creditsadd ".($creditsadd && $extrasql ? ', ' : '')." $extrasql WHERE uid IN ('$uids')", 'UNBUFFERED');
}
}
}
function updatesession() {
if(!empty($GLOBALS['sessionupdated'])) {
return TRUE;
}
global $db, $tablepre, $sessionexists, $sessionupdated, $sid, $onlineip, $discuz_uid, $discuz_user, $timestamp, $lastactivity, $seccode,
$pvfrequence, $spageviews, $lastolupdate, $oltimespan, $onlinehold, $groupid, $styleid, $invisible, $discuz_action, $fid, $tid, $bloguid, $onlinehold;
$fid = intval($fid);
$tid = intval($tid);
if($oltimespan && $discuz_uid && $lastactivity && $timestamp - ($lastolupdate ? $lastolupdate : $lastactivity) > $oltimespan * 60) {
$lastolupdate = $timestamp;
$db->query("UPDATE {$tablepre}onlinetime SET total=total+'$oltimespan', thismonth=thismonth+'$oltimespan', lastupdate='$timestamp' WHERE uid='$discuz_uid' AND lastupdate<='".($timestamp - $oltimespan * 60)."'");
if(!$db->affected_rows()) {
$db->query("INSERT INTO {$tablepre}onlinetime (uid, thismonth, total, lastupdate)
VALUES ('$discuz_uid', '$oltimespan', '$oltimespan', '$timestamp')", 'SILENT');
}
} else {
$lastolupdate = intval($lastolupdate);
}
if($sessionexists == 1) {
if($pvfrequence && $discuz_uid) {
if($spageviews >= $pvfrequence) {
$pageviewsadd = ', pageviews=\'0\'';
$db->query("UPDATE {$tablepre}members SET pageviews=pageviews+'$spageviews' WHERE uid='$discuz_uid'", 'UNBUFFERED');
} else {
$pageviewsadd = ', pageviews=pageviews+1';
}
} else {
$pageviewsadd = '';
}
$db->query("UPDATE {$tablepre}sessions SET uid='$discuz_uid', username='$discuz_user', groupid='$groupid', styleid='$styleid', invisible='$invisible', action='$discuz_action', lastactivity='$timestamp', lastolupdate='$lastolupdate', seccode='$seccode', fid='$fid', tid='$tid', bloguid='$bloguid' $pageviewsadd WHERE sid='$sid'");
} else {
$ips = explode('.', $onlineip);
$db->query("DELETE FROM {$tablepre}sessions WHERE sid='$sid' OR lastactivity<($timestamp-$onlinehold) OR ('$discuz_uid'<>'0' AND uid='$discuz_uid') OR (uid='0' AND ip1='$ips[0]' AND ip2='$ips[1]' AND ip3='$ips[2]' AND ip4='$ips[3]' AND lastactivity>$timestamp-60)");
$db->query("INSERT INTO {$tablepre}sessions (sid, ip1, ip2, ip3, ip4, uid, username, groupid, styleid, invisible, action, lastactivity, lastolupdate, seccode, fid, tid, bloguid)
VALUES ('$sid', '$ips[0]', '$ips[1]', '$ips[2]', '$ips[3]', '$discuz_uid', '$discuz_user', '$groupid', '$styleid', '$invisible', '$discuz_action', '$timestamp', '$lastolupdate', '$seccode', '$fid', '$tid', '$bloguid')", 'SILENT');
if($discuz_uid && $timestamp - $lastactivity > 21600) {
if($oltimespan && $timestamp - $lastactivity > 86400) {
$query = $db->query("SELECT total FROM {$tablepre}onlinetime WHERE uid='$discuz_uid'");
$oltimeadd = ', oltime='.round(intval($db->result($query, 0)) / 60);
} else {
$oltimeadd = '';
}
$db->query("UPDATE {$tablepre}members SET lastip='$onlineip', lastvisit=lastactivity, lastactivity='$timestamp' $oltimeadd WHERE uid='$discuz_uid'", 'UNBUFFERED');
}
}
$sessionupdated = 1;
}
function updatemodworks($modaction, $posts = 1) {
global $modworkstatus, $db, $tablepre, $discuz_uid, $timestamp, $_DCACHE;
$today = gmdate('Y-m-d', $timestamp + $_DCACHE['settings']['timeoffset'] * 3600);
if($modworkstatus && $modaction && $posts) {
$db->query("UPDATE {$tablepre}modworks SET count=count+1, posts=posts+'$posts' WHERE uid='$discuz_uid' AND modaction='$modaction' AND dateline='$today'");
if(!$db->affected_rows()) {
$db->query("INSERT INTO {$tablepre}modworks (uid, modaction, dateline, count, posts) VALUES ('$discuz_uid', '$modaction', '$today', 1, '$posts')");
}
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -