<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: class_core.php 21271 2011-03-22 02:44:58Z congyushuai $
*/
define('IN_DISCUZ', true);
error_reporting(0);
class discuz_core {
var $db = null;
var $mem = null;
var $session = null;
var $config = array();
var $var = array();
var $cachelist = array();
var $init_setting = true;
var $init_user = true;
var $init_session = true;
var $init_cron = true;
var $init_misc = true;
var $init_memory = true;
var $init_mobile = true;
var $initated = false; //初始化工作未完成標(biāo)志
var $superglobal = array(
'GLOBALS' => 1,
'_GET' => 1,
'_POST' => 1,
'_REQUEST' => 1,
'_COOKIE' => 1,
'_SERVER' => 1,
'_ENV' => 1,
'_FILES' => 1,
);
function &instance() {
static $object;
if(empty($object)) {
$object = new discuz_core();
}
return $object;
}
function discuz_core() {
$this->_init_env(); //初始化環(huán)境變量
$this->_init_config(); //初始化配置變量
$this->_init_input(); //初始化輸入
$this->_init_output(); //初始化輸出
}
function init() {
if(!$this->initated) {
$this->_init_db(); //初始化數(shù)據(jù)庫(kù)
$this->_init_memory(); //初始化memcache
$this->_init_user(); //用戶信息初始化
$this->_init_session(); //session操作初始化
$this->_init_setting(); //系統(tǒng)設(shè)置初始化
$this->_init_mobile(); //手機(jī)功能初始化
$this->_init_cron(); //計(jì)劃任務(wù)初始化
$this->_init_misc(); //其他功能初始化
}
$this->initated = true; //設(shè)置完成標(biāo)志
}
function _init_env() { //環(huán)境變量初始化方法
error_reporting(E_ERROR); //定義錯(cuò)誤報(bào)告等級(jí)
if(phpversion() < '5.3.0') {
set_magic_quotes_runtime(0); //設(shè)置set_magic_quotes_runtime
}
define('DISCUZ_ROOT', substr(dirname(__FILE__), 0, -12)); //定義根目錄常量
define('MAGIC_QUOTES_GPC', function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()); //定義MAGIC_QUOTES_GPC
define('ICONV_ENABLE', function_exists('iconv')); //定義轉(zhuǎn)碼函數(shù)常量,如果 iconv函數(shù)支持,則為T(mén)RUE
define('MB_ENABLE', function_exists('mb_convert_encoding')); //轉(zhuǎn)碼函數(shù)是否支持
define('EXT_OBGZIP', function_exists('ob_gzhandler')); //緩存輸出句柄函數(shù)
define('TIMESTAMP', time()); //定義當(dāng)前時(shí)間戳常量
$this->timezone_set();
if(!defined('DISCUZ_CORE_FUNCTION') && !@include(DISCUZ_ROOT.'./source/function/function_core.php')) {
exit('function_core.php is missing'); //如果系統(tǒng)核心函數(shù)庫(kù)文件未include,則include,如果核心函數(shù)庫(kù)文件缺失,則退出,因?yàn)閒unction_core.php是系統(tǒng)本身的函數(shù)庫(kù),必須加載
}
if(function_exists('ini_get')) {
$memorylimit = @ini_get('memory_limit');
if($memorylimit && return_bytes($memorylimit) < 33554432 && function_exists('ini_set')) {
ini_set('memory_limit', '128m');
}
}
//以上6行代碼的作用是設(shè)置內(nèi)存使用限制,如果小于32M,則增加為128M,因?yàn)閙emory_limit小于32M,可能會(huì)不夠用,畢竟X系統(tǒng)比較大,可能內(nèi)存會(huì)使用的多點(diǎn),如果不支持ini_set函數(shù),就得去php.ini中修改了。
define('IS_ROBOT', checkrobot()); //檢測(cè)機(jī)器人
foreach ($GLOBALS as $key => $value) {
if (!isset($this->superglobal[$key])) {
$GLOBALS[$key] = null; unset($GLOBALS[$key]);
}
}
//以上幾行的意思是,注銷所有的超級(jí)變量。
global $_G; //$_G大數(shù)組是Discuz中自定義的超級(jí)變量
$_G = array(
'uid' => 0, //uid
'username' => '', //用戶名
'adminid' => 0, //adminid標(biāo)識(shí)
'groupid' => 1, //用戶組ID
'sid' => '', // sessionID
'formhash' => '', //表單驗(yàn)證認(rèn)證
'timestamp' => TIMESTAMP, //時(shí)間戳
'starttime' => dmicrotime(), //開(kāi)始時(shí)間
'clientip' => $this->_get_client_ip(), //客戶端IP
'referer' => '', //referer地址
'charset' => '', //字符串編碼
'gzipcompress' => '', //gzip
'authkey' => '', //authkey 認(rèn)證碼
'timenow' => array(), //當(dāng)前時(shí)間
'PHP_SELF' => '', //PHP_SELF
'siteurl' => '', //網(wǎng)站地址
'siteroot' => '', //網(wǎng)站根目錄
'config' => array(), //配置變量數(shù)組
'setting' => array(), //設(shè)置變量數(shù)組
'member' => array(), //用戶信息數(shù)組
'group' => array(), //用戶組數(shù)組
'cookie' => array(), //cookie數(shù)組
'style' => array(), //風(fēng)格數(shù)組
'cache' => array(), //緩存列表數(shù)組
'session' => array(), //session變量數(shù)組
'lang' => array(), //語(yǔ)言包數(shù)組
'my_app' => array(), //我的應(yīng)用數(shù)組
'my_userapp' => array(), //用戶應(yīng)用數(shù)組
'fid' => 0,
'tid' => 0,
'forum' => array(), //論壇板塊數(shù)組
'thread' => array(), //論壇相關(guān)帖子數(shù)組
'rssauth' => '', //RSS訂閱認(rèn)證
'home' => array(), //home功能相關(guān)數(shù)組
'space' => array(), //space功能相關(guān)數(shù)組
'block' => array(), //塊信息數(shù)組
'article' => array(),
'action' => array(
'action' => APPTYPEID,
'fid' => 0,
'tid' => 0,
),
'mobile' => '', //手機(jī)信息
);
//以上定義了$_G超級(jí)變量的部分內(nèi)容。都是系統(tǒng)以后要用到的。寫(xiě)在一個(gè)大數(shù)組中,方便使用
$_G['PHP_SELF'] = htmlspecialchars($_SERVER['SCRIPT_NAME'] ? $_SERVER['SCRIPT_NAME'] : $_SERVER['PHP_SELF']);
//當(dāng)前腳本地址寫(xiě)入$_G超級(jí)變量中
$_G['basescript'] = CURSCRIPT; //當(dāng)前腳本
$_G['basefilename'] = basename($_G['PHP_SELF']); //當(dāng)前腳本名稱
$_G['siteurl'] =htmlspecialchars('http://'.$_SERVER['HTTP_HOST'].preg_replace("/\/+(api)?\/*$/i",'', substr($_G['PHP_SELF'], 0, strrpos($_G['PHP_SELF'],'/'))).'/');//網(wǎng)站地址
$_G['siteroot'] = substr($_G['PHP_SELF'], 0, -strlen($_G['basefilename']));//網(wǎng)站根地址
if(defined('SUB_DIR')) { //二級(jí)目錄設(shè)置
$_G['siteurl'] = str_replace(SUB_DIR, '/', $_G['siteurl']);
$_G['siteroot'] = str_replace(SUB_DIR, '/', $_G['siteroot']);
}
$this->var = & $_G;
}
function _init_input() { //輸入初始化方法
if (isset($_GET['GLOBALS']) ||isset($_POST['GLOBALS']) || isset($_COOKIE['GLOBALS']) || isset($_FILES['GLOBALS'])) {
system_error('request_tainting');
}
if(!MAGIC_QUOTES_GPC) {
$_GET = daddslashes($_GET);
$_POST = daddslashes($_POST);
$_COOKIE = daddslashes($_COOKIE);
$_FILES = daddslashes($_FILES);
}
//以上代碼未GPC安全機(jī)制,進(jìn)行轉(zhuǎn)義
$prelength = strlen($this->config['cookie']['cookiepre']);
foreach($_COOKIE as $key => $val) {
if(substr($key, 0, $prelength) == $this->config['cookie']['cookiepre']) {
$this->var['cookie'][substr($key, $prelength)] = $val;
}
}
//以上代碼意思是,如果cookie的鍵值等于定義的鍵值,那么截取cookiepre
$_GET['diy'] = empty($_GET['diy']) ? '' : $_GET['diy'];
if($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST)) {
$_GET = array_merge($_GET, $_POST);
}
//合并$_POST,$_GET
foreach($_GET as $k => $v) {
$this->var['gp_'.$k] = $v;
}
//然后把$_POST和$_GET的值都賦予gp變量中,方便使用
$this->var['mod'] = empty($this->var['gp_mod']) ? '' : htmlspecialchars($this->var['gp_mod']);
//獲得$mod變量 ?mod=xxx,則$this->var['mod']為xxx
$this->var['inajax'] = empty($this->var['gp_inajax']) ? 0 :(empty($this->var['config']['output']['ajaxvalidate']) ? 1 :($_SERVER['REQUEST_METHOD'] == 'GET' &&$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ||$_SERVER['REQUEST_METHOD'] == 'POST' ? 1 : 0));
//是否需要ajax方式
$this->var['page'] = empty($this->var['gp_page']) ? 1 : max(1, intval($this->var['gp_page']));
//頁(yè)面獲取,最小為1
$this->var['sid'] = $this->var['cookie']['sid'] =isset($this->var['cookie']['sid']) ?htmlspecialchars($this->var['cookie']['sid']) : '';
//sid獲取
}
function _init_config() { //獲得配置文件
$_config = array();
@include DISCUZ_ROOT.'./config/config_global.php';//加載全局配置文件
if(empty($_config)) {
if(!file_exists(DISCUZ_ROOT.'./data/install.lock')) {
header('location: install');
exit;
} else {
system_error('config_notfound');
}
}
//以上代碼為:如果config不存在,要么沒(méi)安裝,要么文件不存在,系統(tǒng)報(bào)錯(cuò)
if(empty($_config['security']['authkey'])) {
$_config['security']['authkey'] = md5($_config['cookie']['cookiepre'].$_config['db'][1]['dbname']);
}
//設(shè)置安全驗(yàn)證的authkey
if(empty($_config['debug']) || !file_exists(libfile('function/debug'))) {
define('DISCUZ_DEBUG', false);
} elseif($_config['debug'] === 1 || $_config['debug'] === 2 ||!empty($_REQUEST['debug']) && $_REQUEST['debug'] ===$_config['debug']) {
define('DISCUZ_DEBUG', true);
if($_config['debug'] == 2) {
error_reporting(E_ALL);
}
} else {
define('DISCUZ_DEBUG', false);
}
//以上代碼為是否調(diào)試模式,
define('STATICURL', !empty($_config['output']['staticurl']) ? $_config['output']['staticurl'] : 'static/');
//定義靜態(tài)文件常量,如:css,img等,如果$_config['output']['staticurl']為空,則是默認(rèn)的static目錄,就是默認(rèn)目錄
$this->var['staticurl'] = STATICURL;
$this->config = & $_config;
$this->var['config'] = & $_config;
//引用$_config變量,改變$this->config,則$_config改變,保持統(tǒng)一
if(substr($_config['cookie']['cookiepath'], 0, 1) != '/') {
$this->var['config']['cookie']['cookiepath'] = '/'.$this->var['config']['cookie']['cookiepath'];
}
//設(shè)置cookie域,一般是設(shè)置目錄域。/不存在則加上/,安全性更高
$this->var['config']['cookie']['cookiepre'] =$this->var['config']['cookie']['cookiepre'].substr(md5($this->var['config']['cookie']['cookiepath'].'|'.$this->var['config']['cookie']['cookiedomain']),0, 4).'_';
//定義cookie前綴,如定義為xxx_;則為$cookie['xxx_uid]
$this->var['authkey'] = md5($_config['security']['authkey'].$_SERVER['HTTP_USER_AGENT']);
//得到authkey
}
function _init_output() { //輸出初始化方法
if($this->config['security']['urlxssdefend'] &&$_SERVER['REQUEST_METHOD'] == 'GET' &&!empty($_SERVER['REQUEST_URI'])) {
$this->_xss_check();
}
if($this->config['security']['attackevasive'] &&(!defined('CURSCRIPT') || !in_array($this->var['mod'],array('seccode', 'secqaa', 'swfupload')))) {
require_once libfile('misc/security', 'include');
}
//驗(yàn)證碼設(shè)置,加載include/misc/misc_security.php文件,驗(yàn)證功能;
if(!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === false) {
$this->config['output']['gzip'] = false;
}
//是否開(kāi)啟gzip,如果不支持gzip,則定義為false
$allowgzip = $this->config['output']['gzip'] &&empty($this->var['inajax']) && $this->var['mod'] !='attachment' && EXT_OBGZIP;
setglobal('gzipcompress', $allowgzip);
//把$allowgzip寫(xiě)入全局變量中
ob_start($allowgzip ? 'ob_gzhandler' : null);
//定義輸出緩存
setglobal('charset', $this->config['output']['charset']);
//把配置文件中的字符集賦予全局變量中
define('CHARSET', $this->config['output']['charset']);
if($this->config['output']['forceheader']) {
@header('Content-Type: text/html; charset='.CHARSET);//設(shè)置網(wǎng)頁(yè)編碼,強(qiáng)制輸出
}
}
function reject_robot() { //拒絕機(jī)器人訪問(wèn),設(shè)置為403錯(cuò)誤
if(IS_ROBOT) {
exit(header("HTTP/1.1 403 Forbidden"));
}
}
function _xss_check() { //檢測(cè)xss漏洞,UBB
$temp = strtoupper(urldecode(urldecode($_SERVER['REQUEST_URI'])));
if(strpos($temp, '<') !== false || strpos($temp, '"') !== false || strpos($tmp,'CONTENT-TRANSFER-ENCODING')!==false) {
system_error('request_tainting');
}
return true;
}
function _get_client_ip() { //得到客戶端IP
$ip = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) ANDpreg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s',$_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
foreach ($matches[0] AS $xip) {
if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
$ip = $xip;
break;
}
}
}
return $ip;
}
function _init_db() { //初始化數(shù)據(jù)庫(kù)
$class = 'db_mysql';
if(count(getglobal('config/db/slave'))) { //是否存在從數(shù)據(jù)連接,存在則初始化
require_once libfile('class/mysql_slave');
$class = 'db_mysql_slave';
}
$this->db = & DB::object($class);
$this->db->set_config($this->config['db']);
$this->db->connect(); //建立數(shù)據(jù)庫(kù)連接
}
function _init_session() { //session初始化方法
$this->session = new discuz_session(); //new discuz_session類
if($this->init_session)
{
$this->session->init($this->var['cookie']['sid'], $this->var['clientip'], $this->var['uid']);
$this->var['sid'] = $this->session->sid; //設(shè)置sid
$this->var['session'] = $this->session->var; //設(shè)置session
if($this->var['sid'] != $this->var['cookie']['sid']) {
dsetcookie('sid', $this->var['sid'], 86400); //如果sid不為cookie中的sid,則重寫(xiě)sid到cookie
}
if($this->session->isnew) {
if(ipbanned($this->var['clientip'])) {
$this->session->set('groupid', 6); //如果發(fā)現(xiàn)IP在禁止范圍里,則設(shè)置該客戶端用戶組為6,則:禁止IP用戶組
}
}
if($this->session->get('groupid') == 6) {
$this->var['member']['groupid'] = 6;
sysmessage('user_banned'); //提示IP禁止
}
if($this->var['uid'] && ($this->session->isnew ||($this->session->get('lastactivity') + 600) < TIMESTAMP)) {
$this->session->set('lastactivity', TIMESTAMP);
//最近活動(dòng)檢測(cè),600秒
if($this->session->isnew) {
DB::update('common_member_status', array('lastip' =>$this->var['clientip'], 'lastvisit' => TIMESTAMP),"uid='".$this->var['uid']."'");
} //如果用戶在600秒里不活動(dòng),則設(shè)置最后訪問(wèn)時(shí)間點(diǎn)
}
}
}
function _init_user() { //用戶初始化方法
if($this->init_user) {
if($auth = getglobal('auth', 'cookie')) { //得到auth,username\tuid的加密信息
$auth = daddslashes(explode("\t", authcode($auth, 'DECODE'))); //進(jìn)行解密
}
list($discuz_pw, $discuz_uid) = empty($auth) || count($auth) < 2 ? array('', '') : $auth;
//得到用戶名和用戶密碼,如果auth為空,或者缺失uid和username中的一個(gè),則為空
if($discuz_uid) {
$user = getuserbyuid($discuz_uid); //如果uid存在,則得到該用戶信息
}
if(!empty($user) && $user['password'] == $discuz_pw) {
$this->var['member'] = $user; //如果用戶存在,且密碼正確,則用戶信息寫(xiě)進(jìn)全局變量中
} else {
$user = array(); //user定義為空數(shù)組
$this->_init_guest(); //否則為游客,游客初始化方法
}
if($user && $user['groupexpiry'] > 0 &&$user['groupexpiry'] < TIMESTAMP && getgpc('mod') !='spacecp' && getgpc('do') != 'expiry' && CURSCRIPT !='home') {
dheader('location: home.php?mod=spacecp&ac=usergroup&do=expiry');
}
//用戶組過(guò)期檢測(cè)
$this->cachelist[] = 'usergroup_'.$this->var['member']['groupid'];
//用戶組數(shù)據(jù)緩存
if($user && $user['adminid'] > 0 && $user['groupid'] != $user['adminid']) {
$this->cachelist[] = 'admingroup_'.$this->var['member']['adminid']; //管理員用戶組緩存
}
} else {
$this->_init_guest(); //游客
}
if(empty($this->var['cookie']['lastvisit'])) {
$this->var['member']['lastvisit'] = TIMESTAMP - 3600;
dsetcookie('lastvisit', TIMESTAMP - 3600, 86400 * 30); //cookie中如果為記錄最后訪問(wèn)時(shí)間,則寫(xiě)入
} else {
$this->var['member']['lastvisit'] = $this->var['cookie']['lastvisit'];//否則,寫(xiě)入全局變量
}
setglobal('uid', getglobal('uid', 'member'));
setglobal('username', addslashes(getglobal('username', 'member')));
setglobal('adminid', getglobal('adminid', 'member'));
setglobal('groupid', getglobal('groupid', 'member'));
//以上四行是把用戶的uid,用戶名,管理組id,用戶組寫(xiě)入全局變量中
}
function _init_guest() { //游客初始化方法
setglobal('member', array( 'uid' => 0, 'username' => '','adminid' => 0, 'groupid' => 7, 'credits' => 0, 'timeoffset'=> 9999));
}
function _init_cron() { //計(jì)劃任務(wù)初始化
if($this->init_cron && $this->init_setting) {
if($this->var['cache']['cronnextrun'] <= TIMESTAMP) {
require_once libfile('class/cron'); //加載source/class/class_cron.php文件
discuz_cron::run(); //運(yùn)行
}
}
}
function _init_misc() {
if(!$this->init_misc) {
return false;
}
lang('core'); //加載core語(yǔ)言包
if($this->init_setting && $this->init_user) {
if(!isset($this->var['member']['timeoffset']) ||$this->var['member']['timeoffset'] == 9999 ||$this->var['member']['timeoffset'] === '') {
$this->var['member']['timeoffset'] = $this->var['setting']['timeoffset'];
}
}
//設(shè)置用戶時(shí)區(qū)
$timeoffset = $this->init_setting ? $this->var['member']['timeoffset'] : $this->var['setting']['timeoffset'];
$this->var['timenow'] = array(
'time' => dgmdate(TIMESTAMP),
'offset' => $timeoffset >= 0 ? ($timeoffset == 0 ? '' : '+'.$timeoffset) : $timeoffset
);
$this->timezone_set($timeoffset);
$this->var['formhash'] = formhash(); //得到FORMHASH
define('FORMHASH', $this->var['formhash']); //定義為常量
if($this->init_user) {
if($this->var['group'] &&isset($this->var['group']['allowvisit']) &&!$this->var['group']['allowvisit']) {
if($this->var['uid']) {
sysmessage('user_banned', null); //檢測(cè)是否為禁止訪問(wèn)
} elseif((!defined('ALLOWGUEST') || !ALLOWGUEST) &&!in_array(CURSCRIPT, array('member', 'api')) &&!$this->var['inajax']) {
dheader('location: member.php?mod=logging&action=login&referer='.rawurlencode($_SERVER['REQUEST_URI']));
}
}
if($this->var['member']['status'] == -1) {
sysmessage('user_banned', null); //如果用戶狀態(tài)為-1,則提示禁止訪問(wèn)
}
}
if($this->var['setting']['ipaccess'] &&!ipaccess($this->var['clientip'],$this->var['setting']['ipaccess'])) {
sysmessage('user_banned', null); //ip權(quán)限檢測(cè)
}
if($this->var['setting']['bbclosed']) {
if($this->var['uid'] && ($this->var['group']['allowvisit'] == 2 || $this->var['groupid'] == 1)) {
} elseif(in_array(CURSCRIPT, array('admin', 'member', 'api')) || defined('ALLOWGUEST') && ALLOWGUEST) {
} else {
$closedreason = DB::result_first("SELECT svalue FROM ".DB::table('common_setting')." WHERE skey='closedreason'");
$closedreason = str_replace(':', ':', $closedreason);
showmessage($closedreason ? $closedreason : 'board_closed', NULL, array(), array('login' => 1));
}
}
//以上是論壇如果為關(guān)閉,只有管理員可以訪問(wèn),其他則提示關(guān)閉原因
if(CURSCRIPT != 'admin' && !(in_array($this->var['mod'], array('logging', 'seccode')))) {
periodscheck('visitbanperiods'); //私密板塊訪問(wèn)設(shè)置
}
if(defined('IN_MOBILE')) {
$this->var['tpp'] =$this->var['setting']['mobile']['mobiletopicperpage'] ?intval($this->var['setting']['mobile']['mobiletopicperpage']) : 20;
$this->var['ppp'] =$this->var['setting']['mobile']['mobilepostperpage'] ?intval($this->var['setting']['mobile']['mobilepostperpage']) : 5;
} else {
$this->var['tpp'] = $this->var['setting']['topicperpage'] ? intval($this->var['setting']['topicperpage']) : 20;
$this->var['ppp'] = $this->var['setting']['postperpage'] ? intval($this->var['setting']['postperpage']) : 10;
}
//wap訪問(wèn)設(shè)置
if($this->var['setting']['nocacheheaders']) {
@header("Expires: -1");
@header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
@header("Pragma: no-cache");
}
//以上五行作用是header cache狀態(tài)設(shè)置
if($this->session->isnew && $this->var['uid']) {
updatecreditbyaction('daylogin', $this->var['uid']); //每日登陸增加積分設(shè)置
include_once libfile('function/stat');
updatestat('login', 1);
if(defined('IN_MOBILE')) {
updatestat('mobilelogin', 1); //MOBILE
}
if($this->var['setting']['connect']['allow'] && $this->var['member']['conisbind']) {
updatestat('connectlogin', 1);
}
}
if($this->var['member']['conisbind'] && $this->var['setting']['connect']['newbiespan'] !== '') {
$this->var['setting']['newbiespan'] = $this->var['setting']['connect']['newbiespan'];
}
$lastact = TIMESTAMP."\t".htmlspecialchars(basename($this->var['PHP_SELF']))."\t".htmlspecialchars($this->var['mod']);
dsetcookie('lastact', $lastact, 86400);
setglobal('currenturl_encode', base64_encode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']));
//設(shè)置最后動(dòng)作
if($this->var['setting']['magicstatus'] && !$this->var['group']['allowmagics']) {
$this->var['setting']['magicstatus'] = false;
$this->var['setting']['magics'] = array();
unset($this->var['setting']['spacenavs']['magic']);
}
if((!empty($this->var['gp_fromuid']) ||!empty($this->var['gp_fromuser'])) &&($this->var['setting']['creditspolicy']['promotion_visit'] ||$this->var['setting']['creditspolicy']['promotion_register'])) {
require_once libfile('misc/promotion', 'include');
}
$this->var['seokeywords'] =!empty($this->var['setting']['seokeywords'][CURSCRIPT]) ?$this->var['setting']['seokeywords'][CURSCRIPT] : ''; //SEO keywords
$this->var['seodescription'] =!empty($this->var['setting']['seodescription'][CURSCRIPT]) ?$this->var['setting']['seodescription'][CURSCRIPT] : ''; //SEO 網(wǎng)站描述
}
function _init_setting() {
if($this->init_setting) {
if(empty($this->var['setting'])) {
$this->cachelist[] = 'setting'; //緩存設(shè)置文件
}
if(empty($this->var['style'])) {
$this->cachelist[] = 'style_default'; //風(fēng)格緩存設(shè)置
}
if(!isset($this->var['cache']['cronnextrun'])) {
$this->cachelist[] = 'cronnextrun'; //緩存計(jì)劃任務(wù)
}
}
!empty($this->cachelist) && loadcache($this->cachelist);
if(!is_array($this->var['setting'])) {
$this->var['setting'] = array();
}
if($this->var['member'] &&$this->var['group']['radminid'] == 0 &&$this->var['member']['adminid'] > 0 &&$this->var['member']['groupid'] != $this->var['member']['adminid']&&!empty($this->var['cache']['admingroup_'.$this->var['member']['adminid']])){
$this->var['group'] = array_merge($this->var['group'],$this->var['cache']['admingroup_'.$this->var['member']['adminid']]);
}
}
function _init_style() { //模板初始化方法
$styleid = !empty($this->var['cookie']['styleid']) ? $this->var['cookie']['styleid'] : 0;
if(intval(!empty($this->var['forum']['styleid']))) {
$this->var['cache']['style_default']['styleid'] = $styleid = $this->var['forum']['styleid'];
}
if(intval(!empty($this->var['category']['styleid']))) {
$this->var['cache']['style_default']['styleid'] = $styleid = $this->var['category']['styleid'];
}
if($styleid && $styleid != $this->var['setting']['styleid']) {
loadcache('style_'.$styleid);
if($this->var['cache']['style_'.$styleid]) {
$this->var['style'] = $this->var['cache']['style_'.$styleid];
}
}
if(is_array($this->var['style'])) {
foreach ($this->var['style'] as $key => $val) {
$key = strtoupper($key);
if(!defined($key) && !is_array($val)) {
define($key, $val);
}
}
}
}
function _init_memory() { //緩存設(shè)置
$this->mem = new discuz_memory();
if($this->init_memory) {
$this->mem->init($this->config['memory']);
}
$this->var['memory'] = $this->mem->type;
}
function _init_mobile() { //手機(jī)訪問(wèn)設(shè)置
if(!$this->var['setting'] || !$this->init_mobile ||!$this->var['setting']['mobile']['allowmobile'] ||!is_array($this->var['setting']['mobile']) || IS_ROBOT) {
$nomobile = true; //允許手機(jī)訪問(wèn)
}
if($_GET['mobile'] === 'no') {
dsetcookie('mobile', 'no', 3600);
$nomobile = true;
} elseif($this->var['cookie']['mobile'] == 'no' && $_GET['mobile'] === 'yes') {
dsetcookie('mobile', '');
} elseif($this->var['cookie']['mobile'] == 'no') {
$nomobile = true;
}
if(!checkmobile()) { //檢測(cè)是否為手機(jī)訪問(wèn)
$nomobile = true;
}
if((!$this->var['setting']['mobile']['mobileforward'] && $_GET['mobile'] !== 'yes') || $nomobile) {
if($_SERVER['HTTP_HOST'] ==$this->var['setting']['domain']['app']['mobile'] &&$this->var['setting']['domain']['app']['default']) {
dheader("Location:http://".$this->var['setting']['domain']['app']['default'].$_SERVER['REQUEST_URI']);
} else {
return;
}
}
if(strpos($this->var['setting']['domain']['defaultindex'],CURSCRIPT) === false && CURSCRIPT != 'forum' &&!$_GET['mod']) {
if($this->var['setting']['domain']['app']['mobile']) {
$mobileurl = 'http://'.$this->var['setting']['domain']['app']['mobile'];
} else {
if($this->var['setting']['domain']['app']['forum']) {
$mobileurl = 'http://'.$this->var['setting']['domain']['app']['forum'].'?mobile=yes';
} else {
$mobileurl = $this->var['siteurl'].'forum.php?mobile=yes';
}
}
dheader("location:$mobileurl");
}
define('IN_MOBILE', true);
setglobal('gzipcompress', 0);
$query_sting_tmp = preg_replace(array('/&simpletype=\w+/','/simpletype=\w+/', '/&mobile=yes/', '/mobile=yes/'), array(),$_SERVER['QUERY_STRING']);
$this->var['setting']['mobile']['nomobileurl'] =($this->var['setting']['domain']['app']['forum'] ?'http://'.$this->var['setting']['domain']['app']['forum'].'/' :$this->var['siteurl']).$this->var['basefilename'].($query_sting_tmp? '?'.$query_sting_tmp.'&' : '?').'mobile=no';
$this->var['setting']['lazyload'] = 0;
if('utf-8' != CHARSET) {
if(strtolower($_SERVER['REQUEST_METHOD']) === 'post') {
foreach($_POST AS $pk => $pv) {
if(!is_numeric($pv)) {
$this->var['gp_'.$pk] = $_GET[$pk] = $_POST[$pk] = $this->mobile_iconv_recurrence($pv);
}
}
}
}
if($_GET['simpletype']) {
if($_GET['simpletype'] == 'yes') {
$this->var['setting']['mobile']['mobilesimpletype'] = 1;
dsetcookie('simpletype', 1, 86400);
} else {
$this->var['setting']['mobile']['mobilesimpletype'] = 0;
dsetcookie('simpletype', 0, 86400);
}
} elseif($this->var['cookie']['simpletype']) {
$this->var['setting']['mobile']['mobilesimpletype'] = $this->var['cookie']['simpletype'] == 1 ? 1 : 0 ;
}
if(!$this->var['setting']['mobile']['mobilesimpletype']) {
$this->var['setting']['imagemaxwidth'] = 224;
}
$this->var['setting']['regstatus'] =$this->var['setting']['mobile']['mobileregister'] ?$this->var['setting']['regstatus'] : 0 ;
if(!$this->var['setting']['mobile']['mobileseccode']) {
$this->var['setting']['seccodestatus'] = 0;
}
$this->var['setting']['seccodedata']['type'] = 99;
$this->var['setting']['thumbquality'] = 50;
$this->var['setting']['mobile']['simpletypeurl'] = array();
$this->var['setting']['mobile']['simpletypeurl'][0] =$this->var['siteurl'].$this->var['basefilename'].($query_sting_tmp? '?'.$query_sting_tmp.'&' : '?').'simpletype=no&mobile=yes' ;
$this->var['setting']['mobile']['simpletypeurl'][1] = $this->var['siteurl'].$this->var['basefilename'].($query_sting_tmp? '?'.$query_sting_tmp.'&' : '?').'simpletype=yes&mobile=yes';
unset($query_sting_tmp);
ob_start();
}
function timezone_set($timeoffset = 0) { //時(shí)區(qū)設(shè)置
if(function_exists('date_default_timezone_set')) {
@date_default_timezone_set('Etc/GMT'.($timeoffset > 0 ? '-' : '+').(abs($timeoffset)));
}
}
function mobile_iconv_recurrence($value) { //手機(jī)訪問(wèn)再次轉(zhuǎn)碼
if(is_array($value)) {
foreach($value AS $key => $val) {
$value[$key] = $this->mobile_iconv_recurrence($val);
}
} else {
$value = daddslashes(diconv(stripslashes($value), 'utf-8', CHARSET));
}
return $value;
}
}
class db_mysql //數(shù)據(jù)庫(kù)類
{
var $tablepre;
var $version = '';
var $querynum = 0;
var $slaveid = 0;
var $curlink;
var $link = array();
var $config = array();
var $sqldebug = array();
var $map = array();
function db_mysql($config = array()) {
if(!empty($config)) {
$this->set_config($config);
}
}
function set_config($config) {
$this->config = &$config;
$this->tablepre = $config['1']['tablepre'];
if(!empty($this->config['map'])) {
$this->map = $this->config['map'];
}
}
function connect($serverid = 1) {
if(empty($this->config) || empty($this->config[$serverid])) {
$this->halt('config_db_not_found');
}
$this->link[$serverid] = $this->_dbconnect(
$this->config[$serverid]['dbhost'],
$this->config[$serverid]['dbuser'],
$this->config[$serverid]['dbpw'],
$this->config[$serverid]['dbcharset'],
$this->config[$serverid]['dbname'],
$this->config[$serverid]['pconnect']
);
$this->curlink = $this->link[$serverid];
}
function _dbconnect($dbhost, $dbuser, $dbpw, $dbcharset, $dbname, $pconnect) {
$link = null;
$func = empty($pconnect) ? 'mysql_connect' : 'mysql_pconnect';
if(!$link = @$func($dbhost, $dbuser, $dbpw, 1)) {
$this->halt('notconnect');
} else {
$this->curlink = $link;
if($this->version() > '4.1') {
$dbcharset = $dbcharset ? $dbcharset : $this->config[1]['dbcharset'];
$serverset = $dbcharset ? 'character_set_connection='.$dbcharset.',character_set_results='.$dbcharset.', character_set_client=binary' : '';
$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',').'sql_mode=\'\'') : '';
$serverset && mysql_query("SET $serverset", $link);
}
$dbname && @mysql_select_db($dbname, $link);
}
return $link;
}
function table_name($tablename) {
if(!empty($this->map) && !empty($this->map[$tablename])) {
$id = $this->map[$tablename];
if(!$this->link[$id]) {
$this->connect($id);
}
$this->curlink = $this->link[$id];
} else {
$this->curlink = $this->link[1];
}
return $this->tablepre.$tablename;
}
function select_db($dbname) {
return mysql_select_db($dbname, $this->curlink);
}
function fetch_array($query, $result_type = MYSQL_ASSOC) {
return mysql_fetch_array($query, $result_type);
}
function fetch_first($sql) {
return $this->fetch_array($this->query($sql));
}
function result_first($sql) {
return $this->result($this->query($sql), 0);
}
function query($sql, $type = '') {
if(defined('DISCUZ_DEBUG') && DISCUZ_DEBUG) {
$starttime = dmicrotime();
}
$func = $type == 'UNBUFFERED' && @function_exists('mysql_unbuffered_query') ?
'mysql_unbuffered_query' : 'mysql_query';
if(!($query = $func($sql, $this->curlink))) {
if(in_array($this->errno(), array(2006, 2013)) && substr($type, 0, 5) != 'RETRY') {
$this->connect();
return $this->query($sql, 'RETRY'.$type);
}
if($type != 'SILENT' && substr($type, 5) != 'SILENT') {
$this->halt('query_error', $sql);
}
}
if(defined('DISCUZ_DEBUG') && DISCUZ_DEBUG) {
$this->sqldebug[] = array($sql, number_format((dmicrotime() - $starttime), 6), debug_backtrace());
}
$this->querynum++;
return $query;
}
function affected_rows() {
return mysql_affected_rows($this->curlink);
}
function error() {
return (($this->curlink) ? mysql_error($this->curlink) : mysql_error());
}
function errno() {
return intval(($this->curlink) ? mysql_errno($this->curlink) : mysql_errno());
}
function result($query, $row = 0) {
$query = @mysql_result($query, $row);
return $query;
}
function num_rows($query) {
$query = mysql_num_rows($query);
return $query;
}
function num_fields($query) {
return mysql_num_fields($query);
}
function free_result($query) {
return mysql_free_result($query);
}
function insert_id() {
return ($id = mysql_insert_id($this->curlink)) >= 0 ? $id :$this->result($this->query("SELECT last_insert_id()"), 0);
}
function fetch_row($query) {
$query = mysql_fetch_row($query);
return $query;
}
function fetch_fields($query) {
return mysql_fetch_field($query);
}
function version() {
if(empty($this->version)) {
$this->version = mysql_get_server_info($this->curlink);
}
return $this->version;
}
function close() {
return mysql_close($this->curlink);
}
function halt($message = '', $sql = '') {
require_once libfile('class/error');
discuz_error::db_error($message, $sql);
}
}
class DB //數(shù)據(jù)庫(kù)操作
class discuz_session //session類
class discuz_memory //緩存初始化 支持eaccelerator/xcach/memcache
?>
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。