';
} else {
return $host.$href;
}
}
function mobilereplace($file, $replace) {
return helper_mobile::mobilereplace($file, $replace);
}
function mobileoutput() {
helper_mobile::mobileoutput();
}
function output() {
global $_G;
if(defined('DISCUZ_OUTPUTED')) {
return;
} else {
define('DISCUZ_OUTPUTED', 1);
}
if(!empty($_G['blockupdate'])) {
block_updatecache($_G['blockupdate']['bid']);
}
if(defined('IN_MOBILE')) {
mobileoutput();
}
if(!defined('IN_MOBILE') && !defined('IN_ARCHIVER')) {
$tipsService = Cloud::loadClass('Service_DiscuzTips');
$tipsService->show();
}
$havedomain = implode('', $_G['setting']['domain']['app']);
if($_G['setting']['rewritestatus'] || !empty($havedomain)) {
$content = ob_get_contents();
$content = output_replace($content);
ob_end_clean();
$_G['gzipcompress'] ? ob_start('ob_gzhandler') : ob_start();
echo $content;
}
if(isset($_G['makehtml'])) {
helper_makehtml::make_html();
}
if($_G['setting']['ftp']['connid']) {
@ftp_close($_G['setting']['ftp']['connid']);
}
$_G['setting']['ftp'] = array();
if(defined('CACHE_FILE') && CACHE_FILE && !defined('CACHE_FORBIDDEN') && !defined('IN_MOBILE') && !checkmobile()) {
if(diskfreespace(DISCUZ_ROOT.'./'.$_G['setting']['cachethreaddir']) > 1000000) {
if($fp = @fopen(CACHE_FILE, 'w')) {
flock($fp, LOCK_EX);
fwrite($fp, empty($content) ? ob_get_contents() : $content);
}
@fclose($fp);
chmod(CACHE_FILE, 0777);
}
}
if(defined('DISCUZ_DEBUG') && DISCUZ_DEBUG && @include(libfile('function/debug'))) {
function_exists('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']) && (empty($_G['setting']['rewriteguest']) || empty($_G['uid']))) {
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']);
}
foreach($_G['setting']['output']['preg']['search'] as $key => $value) {
$content = preg_replace_callback($value, create_function('$matches', 'return '.$_G['setting']['output']['preg']['replace'][$key].';'), $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($scriptextra = '') {
if(!defined('HOOKTYPE')) {
define('HOOKTYPE', !defined('IN_MOBILE') ? 'hookscript' : 'hookscriptmobile');
}
if(defined('CURMODULE')) {
global $_G;
if($_G['setting']['plugins']['func'][HOOKTYPE]['common']) {
hookscript('common', 'global', 'funcs', array(), 'common');
}
hookscript(CURMODULE, $_G['basescript'], 'funcs', array(), '', $scriptextra);
}
}
function hookscript($script, $hscript, $type = 'funcs', $param = array(), $func = '', $scriptextra = '') {
global $_G;
static $pluginclasses;
if($hscript == 'home') {
if($script == 'space') {
$scriptextra = !$scriptextra ? $_GET['do'] : $scriptextra;
$script = 'space'.(!empty($scriptextra) ? '_'.$scriptextra : '');
} elseif($script == 'spacecp') {
$scriptextra = !$scriptextra ? $_GET['ac'] : $scriptextra;
$script .= !empty($scriptextra) ? '_'.$scriptextra : '';
}
}
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) {
if($_G['pluginrunlist'] && !in_array($identifier, $_G['pluginrunlist'])) {
continue;
}
$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, false)) {
continue;
}
if(!isset($pluginclasses[$classkey])) {
$pluginclasses[$classkey] = new $classkey;
}
if(!method_exists($pluginclasses[$classkey], $hookfunc[1])) {
continue;
}
$return = call_user_func(array($pluginclasses[$classkey], $hookfunc[1]), $param);
if(substr($hookkey, -7) == '_extend' && !empty($_G['setting']['pluginhooks'][$hookkey])) {
continue;
}
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 {
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;
}
hookscript('global', 'global');
$_G['hookscriptoutput'] = true;
if(defined('CURMODULE')) {
$param = array('template' => $tplfile, 'message' => $_G['hookscriptmessage'], 'values' => $_G['hookscriptvalues']);
hookscript(CURMODULE, $_G['basescript'], 'outputfuncs', $param);
}
}
function pluginmodule($pluginid, $type) {
global $_G;
$pluginid = $pluginid ? preg_replace("/[^A-Za-z0-9_:]/", '', $pluginid) : '';
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) {
$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) {
$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 = '', $customtitle = '', $custommemo = '') {
if(!empty($uids) && (is_array($dataarr) && $dataarr)) {
require_once libfile('function/credit');
return _updatemembercount($uids, $dataarr, $checkgroup, $operation, $relatedid, $ruletxt, $customtitle, $custommemo);
}
return true;
}
function checkusergroup($uid = 0) {
$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 '';
$vardump = empty($var) ? true : $vardump;
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((microtime(true) - $_G['starttime']), 6),
'queries' => $db->querynum,
'memory' => ucwords(C::memory()->type)
);
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']) || !empty($_G['cookie']['nofocus_'.$module]) || !$_G['setting']['focus'][$module]) {
return null;
}
loadcache('focus');
if(empty($_G['cache']['focus']['data']) || !is_array($_G['cache']['focus']['data'])) {
return null;
}
$focusid = $_G['setting']['focus'][$module][array_rand($_G['setting']['focus'][$module])];
return $focusid;
}
function check_seccode($value, $idhash, $fromjs = 0, $modid = '') {
return helper_seccheck::check_seccode($value, $idhash, $fromjs, $modid);
}
function check_secqaa($value, $idhash) {
return helper_seccheck::check_secqaa($value, $idhash);
}
function seccheck($rule, $param = array()) {
return helper_seccheck::seccheck($rule, $param);
}
function make_seccode($seccode = '') {
return helper_seccheck::make_seccode($seccode);
}
function make_secqaa() {
return helper_seccheck::make_secqaa();
}
function adshow($parameter) {
global $_G;
if($_G['inajax'] || $_G['group']['closead']) {
return;
}
if(isset($_G['config']['plugindeveloper']) && $_G['config']['plugindeveloper'] == 2) {
return '[ad '.$parameter.']';
}
$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);
if(!$_G['setting']['hookscript']['global']['ad']['funcs'][$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 {
return helper_form::submitcheck($var, $allowget, $seccodecheck, $secqaacheck);
}
}
function multi($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = FALSE, $simple = FALSE, $jsfunc = FALSE) {
return $num > $perpage ? helper_page::multi($num, $perpage, $curpage, $mpurl, $maxpages, $page, $autogoto, $simple, $jsfunc) : '';
}
function simplepage($num, $perpage, $curpage, $mpurl) {
return helper_page::simplepage($num, $perpage, $curpage, $mpurl);
}
function censor($message, $modword = NULL, $return = FALSE) {
return helper_form::censor($message, $modword, $return);
}
function censormod($message) {
return getglobal('group/ignorecensor') || !$message ? false :helper_form::censormod($message);
}
function space_merge(&$values, $tablename, $isarchive = false) {
global $_G;
$uid = empty($values['uid'])?$_G['uid']:$values['uid'];
$var = "member_{$uid}_{$tablename}";
if($uid) {
if(!isset($_G[$var])) {
$ext = $isarchive ? '_archive' : '';
if(($_G[$var] = C::t('common_member_'.$tablename.$ext)->fetch($uid)) !== false) {
if($tablename == 'field_home') {
$_G['setting']['privacy'] = empty($_G['setting']['privacy']) ? array() : (is_array($_G['setting']['privacy']) ? $_G['setting']['privacy'] : dunserialize($_G['setting']['privacy']));
$_G[$var]['privacy'] = empty($_G[$var]['privacy'])? array() : is_array($_G[$var]['privacy']) ? $_G[$var]['privacy'] : dunserialize($_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() : dunserialize($_G[$var]['acceptemail']);
if(empty($_G[$var]['acceptemail'])) {
$_G[$var]['acceptemail'] = empty($_G['setting']['acceptemail'])?array():dunserialize($_G['setting']['acceptemail']);
}
}
} else {
C::t('common_member_'.$tablename.$ext)->insert(array('uid'=>$uid));
$_G[$var] = array();
}
}
$values = array_merge($values, $_G[$var]);
}
}
function runlog($file, $message, $halt=0) {
helper_log::runlog($file, $message, $halt);
}
function stripsearchkey($string) {
$string = trim($string);
$string = str_replace('*', '%', addcslashes($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) && $_ENV['curapp'] ? $_ENV['curapp'].'.php' : '';
$_G['referer'] = !empty($_GET['referer']) ? $_GET['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;
}
$reurl = parse_url($_G['referer']);
if(!$reurl || (isset($reurl['scheme']) && !in_array(strtolower($reurl['scheme']), array('http', 'https')))) {
$_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'];
}
$_G['referer'] = durlencode($_G['referer']);
return $_G['referer'];
}
function ftpcmd($cmd, $arg1 = '') {
static $ftp;
$ftpon = getglobal('setting/ftp/on');
if(!$ftpon) {
return $cmd == 'error' ? -101 : 0;
} elseif($ftp == null) {
$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 == '') {
$chinese = new Chinese($in_charset, $out_charset, true);
$out = $chinese->Convert($str);
}
return $out;
}
function widthauto() {
global $_G;
if($_G['disabledwidthauto']) {
return 0;
}
if(!empty($_G['widthauto'])) {
return $_G['widthauto'] > 0 ? 1 : 0;
}
if($_G['setting']['switchwidthauto'] && !empty($_G['cookie']['widthauto'])) {
return $_G['cookie']['widthauto'] > 0 ? 1 : 0;
} else {
return $_G['setting']['allowwidthauto'] ? 0 : 1;
}
}
function renum($array) {
$newnums = $nums = array();
foreach ($array as $id => $num) {
$newnums[$num][] = $id;
$nums[$num] = $num;
}
return array($nums, $newnums);
}
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 = intval($size) . ' Bytes';
}
return $size;
}
function swapclass($class1, $class2 = '') {
static $swapc = null;
$swapc = isset($swapc) && $swapc != $class1 ? $class1 : $class2;
return $swapc;
}
function writelog($file, $log) {
helper_log::writelog($file, $log);
}
function getstatus($status, $position) {
$t = $status & pow(2, $position - 1) ? 1 : 0;
return $t;
}
function setstatus($position, $value, $baseon = null) {
$t = pow(2, $position - 1);
if($value) {
$t = $baseon | $t;
} elseif ($baseon !== null) {
$t = $baseon & ~$t;
} else {
$t = ~$t;
}
return $t & 0xFFFF;
}
function notification_add($touid, $type, $note, $notevars = array(), $system = 0) {
return helper_notification::notification_add($touid, $type, $note, $notevars, $system);
}
function manage_addnotify($type, $from_num = 0, $langvar = array()) {
helper_notification::manage_addnotify($type, $from_num, $langvar);
}
function sendpm($toid, $subject, $message, $fromid = '', $replypmid = 0, $isusername = 0, $type = 0) {
return helper_pm::sendpm($toid, $subject, $message, $fromid, $replypmid, $isusername, $type);
}
function g_icon($groupid, $return = 0) {
global $_G;
if(empty($_G['cache']['usergroups'][$groupid]['icon'])) {
$s = '';
} else {
if(substr($_G['cache']['usergroups'][$groupid]['icon'], 0, 5) == 'http:') {
$s = '';
} else {
$s = '';
}
}
if($return) {
return $s;
} else {
echo $s;
}
}
function updatediytemplate($targettplname = '', $tpldirectory = '') {
$r = false;
$alldata = !empty($targettplname) ? array( C::t('common_diy_data')->fetch($targettplname, $tpldirectory)) : C::t('common_diy_data')->range();
require_once libfile('function/portalcp');
foreach($alldata as $value) {
$r = save_diy_data($value['tpldirectory'], $value['primaltplname'], $value['targettplname'], dunserialize($value['diycontent']));
}
return $r;
}
function space_key($uid, $appid=0) {
global $_G;
return substr(md5($_G['setting']['siteuniqueid'].'|'.$uid.(empty($appid)?'':'|'.$appid)), 8, 16);
}
function getposttablebytid($tids, $primary = 0) {
return table_forum_post::getposttablebytid($tids, $primary);
}
function getposttable($tableid = 0, $prefix = false) {
return table_forum_post::getposttable($tableid, $prefix);
}
function memory($cmd, $key='', $value='', $ttl = 0, $prefix = '') {
if($cmd == 'check') {
return C::memory()->enable ? C::memory()->type : '';
} elseif(C::memory()->enable && in_array($cmd, array('set', 'get', 'rm', 'inc', 'dec'))) {
if(defined('DISCUZ_DEBUG') && DISCUZ_DEBUG) {
if(is_array($key)) {
foreach($key as $k) {
C::memory()->debug[$cmd][] = ($cmd == 'get' || $cmd == 'rm' ? $value : '').$prefix.$k;
}
} else {
C::memory()->debug[$cmd][] = ($cmd == 'get' || $cmd == 'rm' ? $value : '').$prefix.$key;
}
}
switch ($cmd) {
case 'set': return C::memory()->set($key, $value, $ttl, $prefix); break;
case 'get': return C::memory()->get($key, $value); break;
case 'rm': return C::memory()->rm($key, $value); break;
case 'inc': return C::memory()->inc($key, $value ? $value : 1); break;
case 'dec': return C::memory()->dec($key, $value ? $value : -1); break;
}
}
return null;
}
function ipaccess($ip, $accesslist) {
return preg_match("/^(".str_replace(array("\r\n", ' '), array('|', ''), preg_quote($accesslist, '/')).")/", $ip);
}
function ipbanned($onlineip) {
global $_G;
if($_G['setting']['ipaccess'] && !ipaccess($onlineip, $_G['setting']['ipaccess'])) {
return TRUE;
}
loadcache('ipbanned');
if(empty($_G['cache']['ipbanned'])) {
return FALSE;
} else {
if($_G['cache']['ipbanned']['expiration'] < TIMESTAMP) {
require_once libfile('function/cache');
updatecache('ipbanned');
}
return preg_match("/^(".$_G['cache']['ipbanned']['regexp'].")$/", $onlineip);
}
}
function getcount($tablename, $condition) {
if(empty($condition)) {
$where = '1';
} elseif(is_array($condition)) {
$where = DB::implode_field_value($condition, ' AND ');
} else {
$where = $condition;
}
$ret = intval(DB::result_first("SELECT COUNT(*) AS num FROM ".DB::table($tablename)." WHERE $where"));
return $ret;
}
function sysmessage($message) {
helper_sysmessage::show($message);
}
function forumperm($permstr, $groupid = 0) {
global $_G;
$groupidarray = array($_G['groupid']);
if($groupid) {
return preg_match("/(^|\t)(".$groupid.")(\t|$)/", $permstr);
}
foreach(explode("\t", $_G['member']['extgroupids']) as $extgroupid) {
if($extgroupid = intval(trim($extgroupid))) {
$groupidarray[] = $extgroupid;
}
}
if($_G['setting']['verify']['enabled']) {
getuserprofile('verify1');
foreach($_G['setting']['verify'] as $vid => $verify) {
if($verify['available'] && $_G['member']['verify'.$vid] == 1) {
$groupidarray[] = 'v'.$vid;
}
}
}
return preg_match("/(^|\t)(".implode('|', $groupidarray).")(\t|$)/", $permstr);
}
function checkperm($perm) {
global $_G;
return defined('IN_ADMINCP') ? true : (empty($_G['group'][$perm])?'':$_G['group'][$perm]);
}
function periodscheck($periods, $showmessage = 1) {
global $_G;
if(($periods == 'postmodperiods' || $periods == 'postbanperiods') && ($_G['setting']['postignorearea'] || $_G['setting']['postignoreip'])) {
if($_G['setting']['postignoreip']) {
foreach(explode("\n", $_G['setting']['postignoreip']) as $ctrlip) {
if(preg_match("/^(".preg_quote(($ctrlip = trim($ctrlip)), '/').")/", $_G['clientip'])) {
return false;
break;
}
}
}
if($_G['setting']['postignorearea']) {
$location = $whitearea = '';
require_once libfile('function/misc');
$location = trim(convertip($_G['clientip'], "./"));
if($location) {
$whitearea = preg_quote(trim($_G['setting']['postignorearea']), '/');
$whitearea = str_replace(array("\\*"), array('.*'), $whitearea);
$whitearea = '.*'.$whitearea.'.*';
$whitearea = '/^('.str_replace(array("\r\n", ' '), array('.*|.*', ''), $whitearea).')$/i';
if(@preg_match($whitearea, $location)) {
return false;
}
}
}
}
if(!$_G['group']['disableperiodctrl'] && $_G['setting'][$periods]) {
$now = dgmdate(TIMESTAMP, 'G.i', $_G['setting']['timeoffset']);
foreach(explode("\r\n", str_replace(':', '.', $_G['setting'][$periods])) as $period) {
list($periodbegin, $periodend) = explode('-', $period);
if(($periodbegin > $periodend && ($now >= $periodbegin || $now < $periodend)) || ($periodbegin < $periodend && $now >= $periodbegin && $now < $periodend)) {
$banperiods = str_replace("\r\n", ', ', $_G['setting'][$periods]);
if($showmessage) {
showmessage('period_nopermission', NULL, array('banperiods' => $banperiods), array('login' => 1));
} else {
return TRUE;
}
}
}
}
return FALSE;
}
function cknewuser($return=0) {
global $_G;
$result = true;
if(!$_G['uid']) return true;
if(checkperm('disablepostctrl')) {
return $result;
}
$ckuser = $_G['member'];
if($_G['setting']['newbiespan'] && $_G['timestamp']-$ckuser['regdate']<$_G['setting']['newbiespan']*60) {
if(empty($return)) showmessage('no_privilege_newbiespan', '', array('newbiespan' => $_G['setting']['newbiespan']), array());
$result = false;
}
if($_G['setting']['need_avatar'] && empty($ckuser['avatarstatus'])) {
if(empty($return)) showmessage('no_privilege_avatar', '', array(), array());
$result = false;
}
if($_G['setting']['need_email'] && empty($ckuser['emailstatus'])) {
if(empty($return)) showmessage('no_privilege_email', '', array(), array());
$result = false;
}
if($_G['setting']['need_friendnum']) {
space_merge($ckuser, 'count');
if($ckuser['friends'] < $_G['setting']['need_friendnum']) {
if(empty($return)) showmessage('no_privilege_friendnum', '', array('friendnum' => $_G['setting']['need_friendnum']), array());
$result = false;
}
}
return $result;
}
function manyoulog($logtype, $uids, $action, $fid = '') {
helper_manyou::manyoulog($logtype, $uids, $action, $fid);
}
function useractionlog($uid, $action) {
return helper_log::useractionlog($uid, $action);
}
function getuseraction($var) {
return helper_log::getuseraction($var);
}
function getuserapp($panel = 0) {
return helper_manyou::getuserapp($panel);
}
function getmyappiconpath($appid, $iconstatus=0) {
return helper_manyou::getmyappiconpath($appid, $iconstatus);
}
function getexpiration() {
global $_G;
$date = getdate($_G['timestamp']);
return mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year']) + 86400;
}
function return_bytes($val) {
$val = trim($val);
$last = strtolower($val{strlen($val)-1});
switch($last) {
case 'g': $val *= 1024;
case 'm': $val *= 1024;
case 'k': $val *= 1024;
}
return $val;
}
function iswhitelist($host) {
global $_G;
static $iswhitelist = array();
if(isset($iswhitelist[$host])) {
return $iswhitelist[$host];
}
$hostlen = strlen($host);
$iswhitelist[$host] = false;
if(!$_G['cache']['domainwhitelist']) {
loadcache('domainwhitelist');
}
if(is_array($_G['cache']['domainwhitelist'])) foreach($_G['cache']['domainwhitelist'] as $val) {
$domainlen = strlen($val);
if($domainlen > $hostlen) {
continue;
}
if(substr($host, -$domainlen) == $val) {
$iswhitelist[$host] = true;
break;
}
}
if($iswhitelist[$host] == false) {
$iswhitelist[$host] = $host == $_SERVER['HTTP_HOST'];
}
return $iswhitelist[$host];
}
function getattachtablebyaid($aid) {
$attach = C::t('forum_attachment')->fetch($aid);
$tableid = $attach['tableid'];
return 'forum_attachment_'.($tableid >= 0 && $tableid < 10 ? intval($tableid) : 'unused');
}
function getattachtableid($tid) {
$tid = (string)$tid;
return intval($tid{strlen($tid)-1});
}
function getattachtablebytid($tid) {
return 'forum_attachment_'.getattachtableid($tid);
}
function getattachtablebypid($pid) {
$tableid = DB::result_first("SELECT tableid FROM ".DB::table('forum_attachment')." WHERE pid='$pid' LIMIT 1");
return 'forum_attachment_'.($tableid >= 0 && $tableid < 10 ? intval($tableid) : 'unused');
}
function getattachnewaid($uid = 0) {
global $_G;
$uid = !$uid ? $_G['uid'] : $uid;
return C::t('forum_attachment')->insert(array('tid' => 0, 'pid' => 0, 'uid' => $uid, 'tableid' => 127), true);
}
function get_seosetting($page, $data = array(), $defset = array()) {
return helper_seo::get_seosetting($page, $data, $defset);
}
function getimgthumbname($fileStr, $extend='.thumb.jpg', $holdOldExt=true) {
if(empty($fileStr)) {
return '';
}
if(!$holdOldExt) {
$fileStr = substr($fileStr, 0, strrpos($fileStr, '.'));
}
$extend = strstr($extend, '.') ? $extend : '.'.$extend;
return $fileStr.$extend;
}
function updatemoderate($idtype, $ids, $status = 0) {
helper_form::updatemoderate($idtype, $ids, $status);
}
function userappprompt() {
global $_G;
if($_G['setting']['my_app_status'] && $_G['setting']['my_openappprompt'] && empty($_G['cookie']['userappprompt'])) {
$sid = $_G['setting']['my_siteid'];
$ts = $_G['timestamp'];
$key = md5($sid.$ts.$_G['setting']['my_sitekey']);
$uchId = $_G['uid'] ? $_G['uid'] : 0;
echo '';
}
}
function dintval($int, $allowarray = false) {
$ret = floatval($int);
if($int == $ret || !$allowarray && is_array($int)) return $ret;
if($allowarray && is_array($int)) {
foreach($int as &$v) {
$v = dintval($v, true);
}
return $int;
} elseif($int <= 0xffffffff) {
$l = strlen($int);
$m = substr($int, 0, 1) == '-' ? 1 : 0;
if(($l - $m) === strspn($int,'0987654321', $m)) {
return $int;
}
}
return $ret;
}
function makeSearchSignUrl() {
return getglobal('setting/my_search_data/status') ? helper_manyou::makeSearchSignUrl() : array();
}
function get_related_link($extent) {
return helper_seo::get_related_link($extent);
}
function parse_related_link($content, $extent) {
return helper_seo::parse_related_link($content, $extent);
}
function check_diy_perm($topic = array(), $flag = '') {
static $ret;
if(!isset($ret)) {
global $_G;
$common = !empty($_G['style']['tplfile']) || $_GET['inajax'];
$blockallow = getstatus($_G['member']['allowadmincp'], 4) || getstatus($_G['member']['allowadmincp'], 5) || getstatus($_G['member']['allowadmincp'], 6);
$ret['data'] = $common && $blockallow;
$ret['layout'] = $common && ($_G['group']['allowdiy'] || (
CURMODULE === 'topic' && ($_G['group']['allowmanagetopic'] || $_G['group']['allowaddtopic'] && $topic && $topic['uid'] == $_G['uid'])
));
}
return empty($flag) ? $ret['data'] || $ret['layout'] : $ret[$flag];
}
function strhash($string, $operation = 'DECODE', $key = '') {
$key = md5($key != '' ? $key : getglobal('authkey'));
if($operation == 'DECODE') {
$hashcode = gzuncompress(base64_decode(($string)));
$string = substr($hashcode, 0, -16);
$hash = substr($hashcode, -16);
unset($hashcode);
}
$vkey = substr(md5($string.substr($key, 0, 16)), 4, 8).substr(md5($string.substr($key, 16, 16)), 18, 8);
if($operation == 'DECODE') {
return $hash == $vkey ? $string : '';
}
return base64_encode(gzcompress($string.$vkey));
}
function dunserialize($data) {
if(($ret = unserialize($data)) === false) {
$ret = unserialize(stripslashes($data));
}
return $ret;
}
function browserversion($type) {
static $return = array();
static $types = array('ie' => 'msie', 'firefox' => '', 'chrome' => '', 'opera' => '', 'safari' => '', 'mozilla' => '', 'webkit' => '', 'maxthon' => '', 'qq' => 'qqbrowser');
if(!$return) {
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
$other = 1;
foreach($types as $i => $v) {
$v = $v ? $v : $i;
if(strpos($useragent, $v) !== false) {
preg_match('/'.$v.'(\/|\s)([\d\.]+)/i', $useragent, $matches);
$ver = $matches[2];
$other = $ver !== 0 && $v != 'mozilla' ? 0 : $other;
} else {
$ver = 0;
}
$return[$i] = $ver;
}
$return['other'] = $other;
}
return $return[$type];
}
function currentlang() {
$charset = strtoupper(CHARSET);
if($charset == 'GBK') {
return 'SC_GBK';
} elseif($charset == 'BIG5') {
return 'TC_BIG5';
} elseif($charset == 'UTF-8') {
global $_G;
if($_G['config']['output']['language'] == 'zh_cn') {
return 'SC_UTF8';
} elseif ($_G['config']['output']['language'] == 'zh_tw') {
return 'TC_UTF8';
}
} else {
return '';
}
}
if(PHP_VERSION < '7.0.0') {
function dpreg_replace($pattern, $replacement, $subject, $limit = -1, &$count) {
return preg_replace($pattern, $replacement, $subject, $limit, $count);
}
} else {
function dpreg_replace($pattern, $replacement, $subject, $limit = -1, &$count) {
require_once libfile('function/preg');
return _dpreg_replace($pattern, $replacement, $subject, $limit, $count);
}
}
?>