xists('debugmessage') && debugmessage(); } } function output_replace($content) { global $_G; if(defined('IN_MODCP') || defined('IN_ADMINCP')) return $content; if(!empty($_G['setting']['output']['str']['search'])) { if(empty($_G['setting']['domain']['app']['default'])) { $_G['setting']['output']['str']['replace'] = str_replace('{CURHOST}', $_G['siteurl'], $_G['setting']['output']['str']['replace']); } $content = str_replace($_G['setting']['output']['str']['search'], $_G['setting']['output']['str']['replace'], $content); } if(!empty($_G['setting']['output']['preg']['search'])) { if(empty($_G['setting']['domain']['app']['default'])) { $_G['setting']['output']['preg']['search'] = str_replace('\{CURHOST\}', preg_quote($_G['siteurl'], '/'), $_G['setting']['output']['preg']['search']); $_G['setting']['output']['preg']['replace'] = str_replace('{CURHOST}', $_G['siteurl'], $_G['setting']['output']['preg']['replace']); } $content = preg_replace($_G['setting']['output']['preg']['search'], $_G['setting']['output']['preg']['replace'], $content); } return $content; } function output_ajax() { global $_G; $s = ob_get_contents(); ob_end_clean(); $s = preg_replace("/([\\x01-\\x08\\x0b-\\x0c\\x0e-\\x1f])+/", ' ', $s); $s = str_replace(array(chr(0), ']]>'), array(' ', ']]>'), $s); if(defined('DISCUZ_DEBUG') && DISCUZ_DEBUG && @include(libfile('function/debug'))) { function_exists('debugmessage') && $s .= debugmessage(1); } $havedomain = implode('', $_G['setting']['domain']['app']); if($_G['setting']['rewritestatus'] || !empty($havedomain)) { $s = output_replace($s); } return $s; } function runhooks() { if(!defined('HOOKTYPE')) { define('HOOKTYPE', !defined('IN_MOBILE') ? 'hookscript' : 'hookscriptmobile'); } if(defined('CURMODULE')) { global $_G; if($_G['setting']['plugins'][HOOKTYPE.'_common']) { hookscript('common', 'global', 'funcs', array(), 'common'); } hookscript(CURMODULE, $_G['basescript']); } } function hookscript($script, $hscript, $type = 'funcs', $param = array(), $func = '') { global $_G; static $pluginclasses; if($hscript == 'home') { if($script != 'spacecp') { $script = 'space_'.(!empty($_G['gp_do']) ? $_G['gp_do'] : (!empty($_GET['do']) ? $_GET['do'] : '')); } else { $script .= !empty($_G['gp_ac']) ? '_'.$_G['gp_ac'] : (!empty($_GET['ac']) ? '_'.$_GET['ac'] : ''); } } if(!isset($_G['setting'][HOOKTYPE][$hscript][$script][$type])) { return; } if(!isset($_G['cache']['plugin'])) { loadcache('plugin'); } foreach((array)$_G['setting'][HOOKTYPE][$hscript][$script]['module'] as $identifier => $include) { $hooksadminid[$identifier] = !$_G['setting'][HOOKTYPE][$hscript][$script]['adminid'][$identifier] || ($_G['setting'][HOOKTYPE][$hscript][$script]['adminid'][$identifier] && $_G['adminid'] > 0 && $_G['setting']['hookscript'][$hscript][$script]['adminid'][$identifier] >= $_G['adminid']); if($hooksadminid[$identifier]) { @include_once DISCUZ_ROOT.'./source/plugin/'.$include.'.class.php'; } } if(@is_array($_G['setting'][HOOKTYPE][$hscript][$script][$type])) { $_G['inhookscript'] = true; $funcs = !$func ? $_G['setting'][HOOKTYPE][$hscript][$script][$type] : array($func => $_G['setting'][HOOKTYPE][$hscript][$script][$type][$func]); foreach($funcs as $hookkey => $hookfuncs) { foreach($hookfuncs as $hookfunc) { if($hooksadminid[$hookfunc[0]]) { $classkey = (HOOKTYPE != 'hookscriptmobile' ? '' : 'mobile').'plugin_'.($hookfunc[0].($hscript != 'global' ? '_'.$hscript : '')); if(!class_exists($classkey)) { continue; } if(!isset($pluginclasses[$classkey])) { $pluginclasses[$classkey] = new $classkey; } if(!method_exists($pluginclasses[$classkey], $hookfunc[1])) { continue; } $return = $pluginclasses[$classkey]->$hookfunc[1]($param); if(is_array($return)) { if(!isset($_G['setting']['pluginhooks'][$hookkey]) || is_array($_G['setting']['pluginhooks'][$hookkey])) { foreach($return as $k => $v) { $_G['setting']['pluginhooks'][$hookkey][$k] .= $v; } } } else { if(!is_array($_G['setting']['pluginhooks'][$hookkey])) { $_G['setting']['pluginhooks'][$hookkey] .= $return; } else { foreach($_G['setting']['pluginhooks'][$hookkey] as $k => $v) { $_G['setting']['pluginhooks'][$hookkey][$k] .= $return; } } } } } } } $_G['inhookscript'] = false; } function hookscriptoutput($tplfile) { global $_G; if(!empty($_G['hookscriptoutput'])) { return; } if(!empty($_G['gp_mobiledata'])) { require_once libfile('class/mobiledata'); $mobiledata = new mobiledata(); if($mobiledata->validator()) { $mobiledata->outputvariables(); } } hookscript('global', 'global'); if(defined('CURMODULE')) { $param = array('template' => $tplfile, 'message' => $_G['hookscriptmessage'], 'values' => $_G['hookscriptvalues']); hookscript(CURMODULE, $_G['basescript'], 'outputfuncs', $param); } $_G['hookscriptoutput'] = true; } function pluginmodule($pluginid, $type) { global $_G; if(!isset($_G['cache']['plugin'])) { loadcache('plugin'); } list($identifier, $module) = explode(':', $pluginid); if(!is_array($_G['setting']['plugins'][$type]) || !array_key_exists($pluginid, $_G['setting']['plugins'][$type])) { showmessage('plugin_nonexistence'); } if(!empty($_G['setting']['plugins'][$type][$pluginid]['url'])) { dheader('location: '.$_G['setting']['plugins'][$type][$pluginid]['url']); } $directory = $_G['setting']['plugins'][$type][$pluginid]['directory']; if(empty($identifier) || !preg_match("/^[a-z]+[a-z0-9_]*\/$/i", $directory) || !preg_match("/^[a-z0-9_\-]+$/i", $module)) { showmessage('undefined_action'); } if(@!file_exists(DISCUZ_ROOT.($modfile = './source/plugin/'.$directory.$module.'.inc.php'))) { showmessage('plugin_module_nonexistence', '', array('mod' => $modfile)); } return DISCUZ_ROOT.$modfile; } function updatecreditbyaction($action, $uid = 0, $extrasql = array(), $needle = '', $coef = 1, $update = 1, $fid = 0) { include_once libfile('class/credit'); $credit = & credit::instance(); if($extrasql) { $credit->extrasql = $extrasql; } return $credit->execrule($action, $uid, $needle, $coef, $update, $fid); } function checklowerlimit($action, $uid = 0, $coef = 1, $fid = 0, $returnonly = 0) { require_once libfile('function/credit'); return _checklowerlimit($action, $uid, $coef, $fid, $returnonly); } function batchupdatecredit($action, $uids = 0, $extrasql = array(), $coef = 1, $fid = 0) { include_once libfile('class/credit'); $credit = & credit::instance(); if($extrasql) { $credit->extrasql = $extrasql; } return $credit->updatecreditbyrule($action, $uids, $coef, $fid); } function updatemembercount($uids, $dataarr = array(), $checkgroup = true, $operation = '', $relatedid = 0, $ruletxt = '') { if(!empty($uids) && (is_array($dataarr) && $dataarr)) { require_once libfile('function/credit'); return _updatemembercount($uids, $dataarr, $checkgroup, $operation, $relatedid, $ruletxt); } return true; } function checkusergroup($uid = 0) { require_once libfile('class/credit'); $credit = & credit::instance(); $credit->checkusergroup($uid); } function checkformulasyntax($formula, $operators, $tokens) { $var = implode('|', $tokens); $operator = implode('', $operators); $operator = str_replace( array('+', '-', '*', '/', '(', ')', '{', '}', '\''), array('\+', '\-', '\*', '\/', '\(', '\)', '\{', '\}', '\\\''), $operator ); if(!empty($formula)) { if(!preg_match("/^([$operator\.\d\(\)]|(($var)([$operator\(\)]|$)+))+$/", $formula) || !is_null(eval(preg_replace("/($var)/", "\$\\1", $formula).';'))){ return false; } } return true; } function checkformulacredits($formula) { return checkformulasyntax( $formula, array('+', '-', '*', '/', ' '), array('extcredits[1-8]', 'digestposts', 'posts', 'threads', 'oltime', 'friends', 'doings', 'polls', 'blogs', 'albums', 'sharings') ); } function debug($var = null, $vardump = false) { echo '
';
	if($var === null) {
		print_r($GLOBALS);
	} else {
		if($vardump) {
			var_dump($var);
		} else {
			print_r($var);
		}
	}
	exit();
}

function debuginfo() {
	global $_G;
	if(getglobal('setting/debug')) {
		$db = & DB::object();
		$_G['debuginfo'] = array(
		    'time' => number_format((dmicrotime() - $_G['starttime']), 6),
		    'queries' => $db->querynum,
		    'memory' => ucwords($_G['memory'])
		    );
		if($db->slaveid) {
			$_G['debuginfo']['queries'] = 'Total '.$db->querynum.', Slave '.$db->slavequery;
		}
		return TRUE;
	} else {
		return FALSE;
	}
}

function getfocus_rand($module) {
	global $_G;

	if(empty($_G['setting']['focus']) || !array_key_exists($module, $_G['setting']['focus'])) {
		return null;
	}
	do {
		$focusid = $_G['setting']['focus'][$module][array_rand($_G['setting']['focus'][$module])];
		if(!empty($_G['cookie']['nofocus_'.$focusid])) {
			unset($_G['setting']['focus'][$module][$focusid]);
			$continue = 1;
		} else {
			$continue = 0;
		}
	} while(!empty($_G['setting']['focus'][$module]) && $continue);
	if(!$_G['setting']['focus'][$module]) {
		return null;
	}
	loadcache('focus');
	if(empty($_G['cache']['focus']['data']) || !is_array($_G['cache']['focus']['data'])) {
		return null;
	}
	return $focusid;
}

function check_seccode($value, $idhash) {
	global $_G;
	if(!$_G['setting']['seccodestatus']) {
		return true;
	}
	if(!isset($_G['cookie']['seccode'.$idhash])) {
		return false;
	}
	list($checkvalue, $checktime, $checkidhash, $checkformhash) = explode("\t", authcode($_G['cookie']['seccode'.$idhash], 'DECODE', $_G['config']['security']['authkey']));
	return $checkvalue == strtoupper($value) && TIMESTAMP - 180 > $checktime && $checkidhash == $idhash && FORMHASH == $checkformhash;
}

function check_secqaa($value, $idhash) {
	global $_G;
	if(!$_G['setting']['secqaa']) {
		return true;
	}
	if(!isset($_G['cookie']['secqaa'.$idhash])) {
		return false;
	}
	loadcache('secqaa');
	list($checkvalue, $checktime, $checkidhash, $checkformhash) = explode("\t", authcode($_G['cookie']['secqaa'.$idhash], 'DECODE', $_G['config']['security']['authkey']));
	return $checkvalue == md5($value) && TIMESTAMP - 180 > $checktime && $checkidhash == $idhash && FORMHASH == $checkformhash;
}

function adshow($parameter) {
	global $_G;
	if($_G['inajax']) {
		return;
	}
	$params = explode('/', $parameter);
	$customid = 0;
	$customc = explode('_', $params[0]);
	if($customc[0] == 'custom') {
		$params[0] = $customc[0];
		$customid = $customc[1];
	}
	$adcontent = null;
	if(empty($_G['setting']['advtype']) || !in_array($params[0], $_G['setting']['advtype'])) {
		$adcontent = '';
	}
	if($adcontent === null) {
		loadcache('advs');
		$adids = array();
		$evalcode = &$_G['cache']['advs']['evalcode'][$params[0]];
		$parameters = &$_G['cache']['advs']['parameters'][$params[0]];
		$codes = &$_G['cache']['advs']['code'][$_G['basescript']][$params[0]];
		if(!empty($codes)) {
			foreach($codes as $adid => $code) {
				$parameter = &$parameters[$adid];
				$checked = true;
				@eval($evalcode['check']);
				if($checked) {
					$adids[] = $adid;
				}
			}
			if(!empty($adids)) {
				$adcode = $extra = '';
				@eval($evalcode['create']);
				if(empty($notag)) {
					$adcontent = ''.$adcode.'';
				} else {
					$adcontent = $adcode;
				}
			}
		}
	}
	$adfunc = 'ad_'.$params[0];
	$_G['setting']['pluginhooks'][$adfunc] = null;
	hookscript('ad', 'global', 'funcs', array('params' => $params, 'content' => $adcontent), $adfunc);
	hookscript('ad', $_G['basescript'], 'funcs', array('params' => $params, 'content' => $adcontent), $adfunc);
	return $_G['setting']['pluginhooks'][$adfunc] === null ? $adcontent : $_G['setting']['pluginhooks'][$adfunc];
}

function showmessage($message, $url_forward = '', $values = array(), $extraparam = array(), $custom = 0) {
	require_once libfile('function/message');
	return dshowmessage($message, $url_forward, $values, $extraparam, $custom);
}

function submitcheck($var, $allowget = 0, $seccodecheck = 0, $secqaacheck = 0) {
	if(!getgpc($var)) {
		return FALSE;
	} else {
		global $_G;
		if(!empty($_G['gp_mobiledata'])) {
			require_once libfile('class/mobiledata');
			$mobiledata = new mobiledata();
			if($mobiledata->validator()) {
				return TRUE;
			}
		}
		if($allowget || ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_G['gp_formhash']) && $_G['gp_formhash'] == formhash() && empty($_SERVER['HTTP_X_FLASH_VERSION']) && (empty($_SERVER['HTTP_REFERER']) ||
		preg_replace("/https?:\/\/([^\:\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) == preg_replace("/([^\:]+).*/", "\\1", $_SERVER['HTTP_HOST'])))) {
			if(checkperm('seccode')) {
				if($secqaacheck && !check_secqaa($_G['gp_secanswer'], $_G['gp_sechash'])) {
					showmessage('submit_secqaa_invalid');
				}
				if($seccodecheck && !check_seccode($_G['gp_seccodeverify'], $_G['gp_sechash'])) {
					showmessage('submit_seccode_invalid');
				}
			}
			return TRUE;
		} else {
			showmessage('submit_invalid');
		}
	}
}

function multi($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = FALSE, $simple = FALSE) {
	global $_G;
	$ajaxtarget = !empty($_G['gp_ajaxtarget']) ? " ajaxtarget=\"".htmlspecialchars($_G['gp_ajaxtarget'])."\" " : '';

	$a_name = '';
	if(strpos($mpurl, '#') !== FALSE) {
		$a_strs = explode('#', $mpurl);
		$mpurl = $a_strs[0];
		$a_name = '#'.$a_strs[1];
	}

	if(defined('IN_ADMINCP')) {
		$shownum = $showkbd = TRUE;
		$lang['prev'] = '‹‹';
		$lang['next'] = '››';
	} else {
		$shownum = $showkbd = FALSE;
		if(defined('IN_MOBILE') && !defined('TPL_DEFAULT')) {
			$lang['prev'] = lang('core', 'prevpage');
			$lang['next'] = lang('core', 'nextpage');
		} else {
			$lang['prev'] = '  ';
			$lang['next'] = lang('core', 'nextpage');
		}
	}
	if(defined('IN_MOBILE') && !defined('TPL_DEFAULT')) {
		$dot = '..';
		$page = intval($page) < 10 && intval($page) > 0 ? $page : 4 ;
	} else {
		$dot = '...';
	}
	$multipage = '';
	$mpurl .= strpos($mpurl, '?') !== FALSE ? '&' : '?';

	$realpages = 1;
	$_G['page_next'] = 0;
	$page -= strlen($curpage) - 1;
	if($page <= 0) {
		$page = 1;
	}
	if($num > $perpage) {

		$offset = floor($page * 0.5);

		$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;
			}
		}
		$_G['page_next'] = $to;
		$multipage = ($curpage - $offset > 1 && $pages > $page ? '1 '.$dot.'' : '').
		($curpage > 1 && !$simple ? '' : '');
		for($i = $from; $i <= $to; $i++) {
			$multipage .= $i == $curpage ? ''.$i.'' :
			''.$i.'';
		}
		$multipage .= ($to < $pages ? ''.$dot.' '.$realpages.'' : '').
		($curpage < $pages && !$simple ? ''.$lang['next'].'' : '').
		($showkbd && !$simple && $pages > $page && !$ajaxtarget ? '' : '');

		$multipage = $multipage ? '
'.($shownum && !$simple ? ' '.$num.' ' : '').$multipage.'
' : ''; } $maxpage = $realpages; return $multipage; } function simplepage($num, $perpage, $curpage, $mpurl) { $return = ''; $lang['next'] = lang('core', 'nextpage'); $lang['prev'] = lang('core', 'prevpage'); $next = $num == $perpage ? ''.$lang['next'].'' : ''; $prev = $curpage > 1 ? ''.$lang['prev'].'' : ''; if($next || $prev) { $return = '
'.$prev.$next.'
'; } return $return; } function censor($message, $modword = NULL, $return = FALSE) { global $_G; require_once libfile('class/censor'); $censor = discuz_censor::instance(); $censor->check($message, $modword); if($censor->modbanned() && $_G['group']['ignorecensor']) { $wordbanned = implode(', ', $censor->words_found); if($return) { return array('message' => lang('message', 'word_banned', array('wordbanned' => $wordbanned))); } if(!defined('IN_ADMINCP')) { showmessage('word_banned', '', array('wordbanned' => $wordbanned)); } else { cpmsg(lang('message', 'word_banned'), '', 'error', array('wordbanned' => $wordbanned)); } } if($_G['group']['allowposturl'] == 0 || $_G['group']['allowposturl'] == 2) { $urllist = get_url_list($message); if(is_array($urllist[1])) foreach($urllist[1] as $key => $val) { if(!$val = trim($val)) continue; if(!iswhitelist($val)) { if($_G['group']['allowposturl'] == 0) { showmessage('post_url_nopermission'); } elseif($_G['group']['allowposturl'] == 2) { $message = str_replace('[url]'.$urllist[0][$key].'[/url]', $urllist[0][$key], $message); $message = preg_replace( array( "@\[url=".preg_quote($urllist[0][$key],'@')."\](.*?)\[/url\]@is", "@href=('|\")".preg_quote($urllist[0][$key],'@')."\\1@is", "@\[url\](.*?".preg_quote($urllist[0][$key],'@').".*?)\[/url\]@is", ), array( '\\1', '', '\\1', ), $message); } } } } return $message; } function censormod($message) { global $_G; if($_G['group']['ignorecensor']) { return false; } $modposturl = false; if($_G['group']['allowposturl'] == 1) { $urllist = get_url_list($message); if(is_array($urllist[1])) foreach($urllist[1] as $key => $val) { if(!$val = trim($val)) continue; if(!iswhitelist($val)) { $modposturl = true; } } } if($modposturl) { return true; } require_once libfile('class/censor'); $censor = discuz_censor::instance(); $censor->check($message); return $censor->modmoderated(); } function space_merge(&$values, $tablename) { global $_G; $uid = empty($values['uid'])?$_G['uid']:$values['uid']; $var = "member_{$uid}_{$tablename}"; if($uid) { if(!isset($_G[$var])) { $query = DB::query("SELECT * FROM ".DB::table('common_member_'.$tablename)." WHERE uid='$uid'"); if($_G[$var] = DB::fetch($query)) { if($tablename == 'field_home') { $_G['setting']['privacy'] = empty($_G['setting']['privacy']) ? array() : (is_array($_G['setting']['privacy']) ? $_G['setting']['privacy'] : unserialize($_G['setting']['privacy'])); $_G[$var]['privacy'] = empty($_G[$var]['privacy'])? array() : is_array($_G[$var]['privacy']) ? $_G[$var]['privacy'] : unserialize($_G[$var]['privacy']); foreach (array('feed','view','profile') as $pkey) { if(empty($_G[$var]['privacy'][$pkey]) && !isset($_G[$var]['privacy'][$pkey])) { $_G[$var]['privacy'][$pkey] = isset($_G['setting']['privacy'][$pkey]) ? $_G['setting']['privacy'][$pkey] : array(); } } $_G[$var]['acceptemail'] = empty($_G[$var]['acceptemail'])? array() : unserialize($_G[$var]['acceptemail']); if(empty($_G[$var]['acceptemail'])) { $_G[$var]['acceptemail'] = empty($_G['setting']['acceptemail'])?array():unserialize($_G['setting']['acceptemail']); } } } else { DB::insert('common_member_'.$tablename, array('uid'=>$uid)); $_G[$var] = array(); } } $values = array_merge($values, $_G[$var]); } } function runlog($file, $message, $halt=0) { global $_G; $nowurl = $_SERVER['REQUEST_URI']?$_SERVER['REQUEST_URI']:($_SERVER['PHP_SELF']?$_SERVER['PHP_SELF']:$_SERVER['SCRIPT_NAME']); $log = dgmdate($_G['timestamp'], 'Y-m-d H:i:s')."\t".$_G['clientip']."\t$_G[uid]\t{$nowurl}\t".str_replace(array("\r", "\n"), array(' ', ' '), trim($message))."\n"; writelog($file, $log); if($halt) { exit(); } } function stripsearchkey($string) { $string = trim($string); $string = str_replace('*', '%', addcslashes($string, '%_')); $string = str_replace('_', '\_', $string); return $string; } function dmkdir($dir, $mode = 0777, $makeindex = TRUE){ if(!is_dir($dir)) { dmkdir(dirname($dir), $mode, $makeindex); @mkdir($dir, $mode); if(!empty($makeindex)) { @touch($dir.'/index.html'); @chmod($dir.'/index.html', 0777); } } return true; } function dreferer($default = '') { global $_G; $default = empty($default) ? $GLOBALS['_t_curapp'] : ''; $_G['referer'] = !empty($_G['gp_referer']) ? $_G['gp_referer'] : $_SERVER['HTTP_REFERER']; $_G['referer'] = substr($_G['referer'], -1) == '?' ? substr($_G['referer'], 0, -1) : $_G['referer']; if(strpos($_G['referer'], 'member.php?mod=logging')) { $_G['referer'] = $default; } $_G['referer'] = htmlspecialchars($_G['referer'], ENT_QUOTES); $_G['referer'] = str_replace('&', '&', $_G['referer']); $reurl = parse_url($_G['referer']); if(!empty($reurl['host']) && !in_array($reurl['host'], array($_SERVER['HTTP_HOST'], 'www.'.$_SERVER['HTTP_HOST'])) && !in_array($_SERVER['HTTP_HOST'], array($reurl['host'], 'www.'.$reurl['host']))) { if(!in_array($reurl['host'], $_G['setting']['domain']['app']) && !isset($_G['setting']['domain']['list'][$reurl['host']])) { $domainroot = substr($reurl['host'], strpos($reurl['host'], '.')+1); if(empty($_G['setting']['domain']['root']) || (is_array($_G['setting']['domain']['root']) && !in_array($domainroot, $_G['setting']['domain']['root']))) { $_G['referer'] = $_G['setting']['domain']['defaultindex'] ? $_G['setting']['domain']['defaultindex'] : 'index.php'; } } } elseif(empty($reurl['host'])) { $_G['referer'] = $_G['siteurl'].'./'.$_G['referer']; } return strip_tags($_G['referer']); } function ftpcmd($cmd, $arg1 = '') { static $ftp; $ftpon = getglobal('setting/ftp/on'); if(!$ftpon) { return $cmd == 'error' ? -101 : 0; } elseif($ftp == null) { require_once libfile('class/ftp'); $ftp = & discuz_ftp::instance(); } if(!$ftp->enabled) { return $ftp->error(); } elseif($ftp->enabled && !$ftp->connectid) { $ftp->connect(); } switch ($cmd) { case 'upload' : return $ftp->upload(getglobal('setting/attachdir').'/'.$arg1, $arg1); break; case 'delete' : return $ftp->ftp_delete($arg1); break; case 'close' : return $ftp->ftp_close(); break; case 'error' : return $ftp->error(); break; case 'object' : return $ftp; break; default : return false; } } function diconv($str, $in_charset, $out_charset = CHARSET, $ForceTable = FALSE) { global $_G; $in_charset = strtoupper($in_charset); $out_charset = strtoupper($out_charset); if(empty($str) || $in_charset == $out_charset) { return $str; } $out = ''; if(!$ForceTable) { if(function_exists('iconv')) { $out = iconv($in_charset, $out_charset.'//IGNORE', $str); } elseif(function_exists('mb_convert_encoding')) { $out = mb_convert_encoding($str, $out_charset, $in_charset); } } if($out == '') { require_once libfile('class/chinese'); $chinese = new Chinese($in_charset, $out_charset, true); $out = $chinese->Convert($str); } return $out; } function renum($array) { $newnums = $nums = array(); foreach ($array as $id => $num) { $newnums[$num][] = $id; $nums[$num] = $num; } return array($nums, $newnums); } function getonlinenum($fid = 0, $tid = 0) { if($fid) { $sql = " AND fid='$fid'"; } if($tid) { $sql = " AND tid='$tid'"; } return DB::result_first('SELECT count(*) FROM '.DB::table("common_session")." WHERE 1 $sql"); } function sizecount($size) { if($size >= 1073741824) { $size = round($size / 1073741824 * 100) / 100 . ' GB'; } elseif($size >= 1048576) { $size = round($size / 1048576 * 100) / 100 . ' MB'; } elseif($size >= 1024) { $size = round($size / 1024 * 100) / 100 . ' KB'; } else { $size = $size . ' Bytes'; } return $size; } function swapclass($class1, $class2 = '') { static $swapc = null; $swapc = isset($swapc) && $swapc != $class1 ? $class1 : $class2; return $swapc; } function writelog($file, $log) { global $_G; $yearmonth = dgmdate(TIMESTAMP, 'Ym', $_G['setting']['timeoffset']); $logdir = DISCUZ_ROOT.'./data/log/'; $logfile = $logdir.$yearmonth.'_'.$file.'.php'; if(@filesize($logfile) > 2048000) { $dir = opendir($logdir); $length = strlen($file); $maxid = $id = 0; while($entry = readdir($dir)) { if(strpos($entry, $yearmonth.'_'.$file) !== false) { $id = intval(substr($entry, $length + 8, -4)); $id > $maxid && $maxid = $id; } } closedir($dir); $logfilebak = $logdir.$yearmonth.'_'.$file.'_'.($maxid + 1).'.php'; @rename($logfile, $logfilebak); } if($fp = @fopen($logfile, 'a')) { @flock($fp, 2); $log = is_array($log) ? $log : array($log); foreach($log as $tmp) { fwrite($fp, "