返回列表 发帖
查看: 1227|回复: 3

[已解决] 为什么刚装的discuz报毒

1

主题

1

回帖

6

积分

初学乍练

贡献
0 点
金币
5 个
发表于 2022-7-4 02:17:27 | 显示全部楼层 |阅读模式
webshell查杀发现/www/wwwroot/bbs.xxxx.cn目录中存在木马如下:['/www/wwwroot/bbs.asmile.cn/source/function/function_core.php']

代码如下:
  1. <?php

  2. /**
  3. *      [Discuz!] (C)2001-2099 Comsenz Inc.
  4. *      This is NOT a freeware, use is subject to license terms
  5. *
  6. *      $Id: function_core.php 36342 2017-01-09 01:15:30Z nemohou $
  7. */

  8. if(!defined('IN_DISCUZ')) {
  9.         exit('Access Denied');
  10. }

  11. define('DISCUZ_CORE_FUNCTION', true);

  12. function durlencode($url) {
  13.         static $fix = array('%21', '%2A','%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%2F', '%3F', '%25', '%23', '%5B', '%5D');
  14.         static $replacements = array('!', '*', ';', ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]");
  15.         return str_replace($fix, $replacements, urlencode($url));
  16. }

  17. function system_error($message, $show = true, $save = true, $halt = true) {
  18.         discuz_error::system_error($message, $show, $save, $halt);
  19. }

  20. function updatesession() {
  21.         return C::app()->session->updatesession();
  22. }

  23. function setglobal($key , $value, $group = null) {
  24.         global $_G;
  25.         $key = explode('/', $group === null ? $key : $group.'/'.$key);
  26.         $p = &$_G;
  27.         foreach ($key as $k) {
  28.                 if(!isset($p[$k]) || !is_array($p[$k])) {
  29.                         $p[$k] = array();
  30.                 }
  31.                 $p = &$p[$k];
  32.         }
  33.         $p = $value;
  34.         return true;
  35. }

  36. function getglobal($key, $group = null) {
  37.         global $_G;
  38.         $key = explode('/', $group === null ? $key : $group.'/'.$key);
  39.         $v = &$_G;
  40.         foreach ($key as $k) {
  41.                 if (!isset($v[$k])) {
  42.                         return null;
  43.                 }
  44.                 $v = &$v[$k];
  45.         }
  46.         return $v;
  47. }

  48. function getgpc($k, $type='GP') {
  49.         $type = strtoupper($type);
  50.         switch($type) {
  51.                 case 'G': $var = &$_GET; break;
  52.                 case 'P': $var = &$_POST; break;
  53.                 case 'C': $var = &$_COOKIE; break;
  54.                 default:
  55.                         if(isset($_GET[$k])) {
  56.                                 $var = &$_GET;
  57.                         } else {
  58.                                 $var = &$_POST;
  59.                         }
  60.                         break;
  61.         }

  62.         return isset($var[$k]) ? $var[$k] : NULL;

  63. }

  64. function getuserbyuid($uid, $fetch_archive = 0) {
  65.         static $users = array();
  66.         if(empty($users[$uid])) {
  67.                 $users[$uid] = C::t('common_member'.($fetch_archive === 2 ? '_archive' : ''))->fetch($uid);
  68.                 if($fetch_archive === 1 && empty($users[$uid])) {
  69.                         $users[$uid] = C::t('common_member_archive')->fetch($uid);
  70.                 }
  71.         }
  72.         if(!isset($users[$uid]['self']) && $uid == getglobal('uid') && getglobal('uid')) {
  73.                 $users[$uid]['self'] = 1;
  74.         }
  75.         return $users[$uid];
  76. }

  77. function getuserprofile($field) {
  78.         global $_G;
  79.         if(isset($_G['member'][$field])) {
  80.                 return $_G['member'][$field];
  81.         }
  82.         static $tablefields = array(
  83.                 'count'                => array('extcredits1','extcredits2','extcredits3','extcredits4','extcredits5','extcredits6','extcredits7','extcredits8','friends','posts','threads','digestposts','doings','blogs','albums','sharings','attachsize','views','oltime','todayattachs','todayattachsize', 'follower', 'following', 'newfollower', 'blacklist'),
  84.                 'status'        => array('regip','lastip','lastvisit','lastactivity','lastpost','lastsendmail','invisible','buyercredit','sellercredit','favtimes','sharetimes','profileprogress'),
  85.                 'field_forum'        => array('publishfeed','customshow','customstatus','medals','sightml','groupterms','authstr','groups','attentiongroup'),
  86.                 'field_home'        => array('videophoto','spacename','spacedescription','domain','addsize','addfriend','menunum','theme','spacecss','blockposition','recentnote','spacenote','privacy','feedfriend','acceptemail','magicgift','stickblogs'),
  87.                 'profile'        => array('realname','gender','birthyear','birthmonth','birthday','constellation','zodiac','telephone','mobile','idcardtype','idcard','address','zipcode','nationality','birthprovince','birthcity','resideprovince','residecity','residedist','residecommunity','residesuite','graduateschool','company','education','occupation','position','revenue','affectivestatus','lookingfor','bloodtype','height','weight','alipay','icq','qq','yahoo','msn','taobao','site','bio','interest','field1','field2','field3','field4','field5','field6','field7','field8'),
  88.                 'verify'        => array('verify1', 'verify2', 'verify3', 'verify4', 'verify5', 'verify6', 'verify7'),
  89.         );
  90.         $profiletable = '';
  91.         foreach($tablefields as $table => $fields) {
  92.                 if(in_array($field, $fields)) {
  93.                         $profiletable = $table;
  94.                         break;
  95.                 }
  96.         }
  97.         if($profiletable) {

  98.                 if(is_array($_G['member']) && $_G['member']['uid']) {
  99.                         space_merge($_G['member'], $profiletable);
  100.                 } else {
  101.                         foreach($tablefields[$profiletable] as $k) {
  102.                                 $_G['member'][$k] = '';
  103.                         }
  104.                 }
  105.                 return $_G['member'][$field];
  106.         }
  107.         return null;
  108. }

  109. function daddslashes($string, $force = 1) {
  110.         if(is_array($string)) {
  111.                 $keys = array_keys($string);
  112.                 foreach($keys as $key) {
  113.                         $val = $string[$key];
  114.                         unset($string[$key]);
  115.                         $string[addslashes($key)] = daddslashes($val, $force);
  116.                 }
  117.         } else {
  118.                 $string = addslashes($string);
  119.         }
  120.         return $string;
  121. }

  122. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  123.         $ckey_length = 4;
  124.         $key = md5($key != '' ? $key : getglobal('authkey'));
  125.         $keya = md5(substr($key, 0, 16));
  126.         $keyb = md5(substr($key, 16, 16));
  127.         $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';

  128.         $cryptkey = $keya.md5($keya.$keyc);
  129.         $key_length = strlen($cryptkey);

  130.         $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
  131.         $string_length = strlen($string);

  132.         $result = '';
  133.         $box = range(0, 255);

  134.         $rndkey = array();
  135.         for($i = 0; $i <= 255; $i++) {
  136.                 $rndkey[$i] = ord($cryptkey[$i % $key_length]);
  137.         }

  138.         for($j = $i = 0; $i < 256; $i++) {
  139.                 $j = ($j + $box[$i] + $rndkey[$i]) % 256;
  140.                 $tmp = $box[$i];
  141.                 $box[$i] = $box[$j];
  142.                 $box[$j] = $tmp;
  143.         }

  144.         for($a = $j = $i = 0; $i < $string_length; $i++) {
  145.                 $a = ($a + 1) % 256;
  146.                 $j = ($j + $box[$a]) % 256;
  147.                 $tmp = $box[$a];
  148.                 $box[$a] = $box[$j];
  149.                 $box[$j] = $tmp;
  150.                 $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
  151.         }

  152.         if($operation == 'DECODE') {
  153.                 if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) === substr(md5(substr($result, 26).$keyb), 0, 16)) {
  154.                         return substr($result, 26);
  155.                 } else {
  156.                         return '';
  157.                 }
  158.         } else {
  159.                 return $keyc.str_replace('=', '', base64_encode($result));
  160.         }

  161. }

  162. function fsocketopen($hostname, $port = 80, &$errno, &$errstr, $timeout = 15) {
  163.         $fp = '';
  164.         if(function_exists('fsockopen')) {
  165.                 $fp = @fsockopen($hostname, $port, $errno, $errstr, $timeout);
  166.         } elseif(function_exists('pfsockopen')) {
  167.                 $fp = @pfsockopen($hostname, $port, $errno, $errstr, $timeout);
  168.         } elseif(function_exists('stream_socket_client')) {
  169.                 $fp = @stream_socket_client($hostname.':'.$port, $errno, $errstr, $timeout);
  170.         }
  171.         return $fp;
  172. }

  173. function dfsockopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype  = 'URLENCODE', $allowcurl = TRUE, $position = 0, $files = array()) {
  174.         require_once libfile('function/filesock');
  175.         return _dfsockopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype, $allowcurl, $position, $files);
  176. }

  177. function dhtmlspecialchars($string, $flags = null) {
  178.         if(is_array($string)) {
  179.                 foreach($string as $key => $val) {
  180.                         $string[$key] = dhtmlspecialchars($val, $flags);
  181.                 }
  182.         } else {
  183.                 if($flags === null) {
  184.                         $string = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string);
  185.                 } else {
  186.                         if(PHP_VERSION < '5.4.0') {
  187.                                 $string = htmlspecialchars($string, $flags);
  188.                         } else {
  189.                                 if(strtolower(CHARSET) == 'utf-8') {
  190.                                         $charset = 'UTF-8';
  191.                                 } else {
  192.                                         $charset = 'ISO-8859-1';
  193.                                 }
  194.                                 $string = htmlspecialchars($string, $flags, $charset);
  195.                         }
  196.                 }
  197.         }
  198.         return $string;
  199. }

  200. function dexit($message = '') {
  201.         echo $message;
  202.         output();
  203.         exit();
  204. }

  205. function dheader($string, $replace = true, $http_response_code = 0) {
  206.         $islocation = substr(strtolower(trim($string)), 0, 8) == 'location';
  207.         if(defined('IN_MOBILE') && strpos($string, 'mobile') === false && $islocation) {
  208.                 if (strpos($string, '?') === false) {
  209.                         $string = $string.'?mobile='.IN_MOBILE;
  210.                 } else {
  211.                         if(strpos($string, '#') === false) {
  212.                                 $string = $string.'&mobile='.IN_MOBILE;
  213.                         } else {
  214.                                 $str_arr = explode('#', $string);
  215.                                 $str_arr[0] = $str_arr[0].'&mobile='.IN_MOBILE;
  216.                                 $string = implode('#', $str_arr);
  217.                         }
  218.                 }
  219.         }
  220.         $string = str_replace(array("\r", "\n"), array('', ''), $string);
  221.         if(empty($http_response_code) || PHP_VERSION < '4.3' ) {
  222.                 @header($string, $replace);
  223.         } else {
  224.                 @header($string, $replace, $http_response_code);
  225.         }
  226.         if($islocation) {
  227.                 exit();
  228.         }
  229. }

  230. function dsetcookie($var, $value = '', $life = 0, $prefix = 1, $httponly = false) {

  231.         global $_G;

  232.         $config = $_G['config']['cookie'];

  233.         $_G['cookie'][$var] = $value;
  234.         $var = ($prefix ? $config['cookiepre'] : '').$var;
  235.         $_COOKIE[$var] = $value;

  236.         if($value === '' || $life < 0) {
  237.                 $value = '';
  238.                 $life = -1;
  239.         }

  240.         if(defined('IN_MOBILE')) {
  241.                 $httponly = false;
  242.         }

  243.         $life = $life > 0 ? getglobal('timestamp') + $life : ($life < 0 ? getglobal('timestamp') - 31536000 : 0);
  244.         $path = $httponly && PHP_VERSION < '5.2.0' ? $config['cookiepath'].'; HttpOnly' : $config['cookiepath'];

  245.         $secure = $_G['isHTTPS'];
  246.         if(PHP_VERSION < '5.2.0') {
  247.                 setcookie($var, $value, $life, $path, $config['cookiedomain'], $secure);
  248.         } else {
  249.                 setcookie($var, $value, $life, $path, $config['cookiedomain'], $secure, $httponly);
  250.         }
  251. }

  252. function getcookie($key) {
  253.         global $_G;
  254.         return isset($_G['cookie'][$key]) ? $_G['cookie'][$key] : '';
  255. }

  256. function fileext($filename) {
  257.         return addslashes(strtolower(substr(strrchr($filename, '.'), 1, 10)));
  258. }

  259. function formhash($specialadd = '') {
  260.         global $_G;
  261.         $hashadd = defined('IN_ADMINCP') ? 'Only For Discuz! Admin Control Panel' : '';
  262.         return substr(md5(substr($_G['timestamp'], 0, -7).$_G['username'].$_G['uid'].$_G['authkey'].$hashadd.$specialadd), 8, 8);
  263. }

  264. function checkrobot($useragent = '') {
  265.         static $kw_spiders = array('bot', 'crawl', 'spider' ,'slurp', 'sohu-search', 'lycos', 'robozilla');
  266.         static $kw_browsers = array('msie', 'netscape', 'opera', 'konqueror', 'mozilla');

  267.         $useragent = strtolower(empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent);
  268.         if(dstrpos($useragent, $kw_spiders)) return true;
  269.         if(strpos($useragent, 'http://') === false && dstrpos($useragent, $kw_browsers)) return false;
  270.         return false;
  271. }
  272. function checkmobile() {
  273.         global $_G;
  274.         $mobile = array();
  275.         static $touchbrowser_list =array('iphone', 'android', 'phone', 'mobile', 'wap', 'netfront', 'java', 'opera mobi', 'opera mini',
  276.                                 'ucweb', 'windows ce', 'symbian', 'series', 'webos', 'sony', 'blackberry', 'dopod', 'nokia', 'samsung',
  277.                                 'palmsource', 'xda', 'pieplus', 'meizu', 'midp', 'cldc', 'motorola', 'foma', 'docomo', 'up.browser',
  278.                                 'up.link', 'blazer', 'helio', 'hosin', 'huawei', 'novarra', 'coolpad', 'webos', 'techfaith', 'palmsource',
  279.                                 'alcatel', 'amoi', 'ktouch', 'nexian', 'ericsson', 'philips', 'sagem', 'wellcom', 'bunjalloo', 'maui', 'smartphone',
  280.                                 'iemobile', 'spice', 'bird', 'zte-', 'longcos', 'pantech', 'gionee', 'portalmmm', 'jig browser', 'hiptop',
  281.                                 'benq', 'haier', '^lct', '320x320', '240x320', '176x220', 'windows phone');
  282.         static $wmlbrowser_list = array('cect', 'compal', 'ctl', 'lg', 'nec', 'tcl', 'alcatel', 'ericsson', 'bird', 'daxian', 'dbtel', 'eastcom',
  283.                         'pantech', 'dopod', 'philips', 'haier', 'konka', 'kejian', 'lenovo', 'benq', 'mot', 'soutec', 'nokia', 'sagem', 'sgh',
  284.                         'sed', 'capitel', 'panasonic', 'sonyericsson', 'sharp', 'amoi', 'panda', 'zte');

  285.         static $pad_list = array('ipad');

  286.         $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);

  287.         if(dstrpos($useragent, $pad_list)) {
  288.                 return false;
  289.         }
  290.         if(($v = dstrpos($useragent, $touchbrowser_list, true))){
  291.                 $_G['mobile'] = $v;
  292.                 return '2';
  293.         }
  294.         if(($v = dstrpos($useragent, $wmlbrowser_list))) {
  295.                 $_G['mobile'] = $v;
  296.                 return '3'; //wml版
  297.         }
  298.         $brower = array('mozilla', 'chrome', 'safari', 'opera', 'm3gate', 'winwap', 'openwave', 'myop');
  299.         if(dstrpos($useragent, $brower)) return false;

  300.         $_G['mobile'] = 'unknown';
  301.         if(isset($_G['mobiletpl'][$_GET['mobile']])) {
  302.                 return true;
  303.         } else {
  304.                 return false;
  305.         }
  306. }

  307. function dstrpos($string, $arr, $returnvalue = false) {
  308.         if(empty($string)) return false;
  309.         foreach((array)$arr as $v) {
  310.                 if(strpos($string, $v) !== false) {
  311.                         $return = $returnvalue ? $v : true;
  312.                         return $return;
  313.                 }
  314.         }
  315.         return false;
  316. }

  317. function isemail($email) {
  318.         return strlen($email) > 6 && strlen($email) <= 32 && preg_match("/^([A-Za-z0-9\-_.+]+)@([A-Za-z0-9\-]+[.][A-Za-z0-9\-.]+)$/", $email);
  319. }

  320. function quescrypt($questionid, $answer) {
  321.         return $questionid > 0 && $answer != '' ? substr(md5($answer.md5($questionid)), 16, 8) : '';
  322. }

  323. function random($length, $numeric = 0) {
  324.         $seed = base_convert(md5(microtime().$_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  325.         $seed = $numeric ? (str_replace('0', '', $seed).'012340567890') : ($seed.'zZ'.strtoupper($seed));
  326.         if($numeric) {
  327.                 $hash = '';
  328.         } else {
  329.                 $hash = chr(rand(1, 26) + rand(0, 1) * 32 + 64);
  330.                 $length--;
  331.         }
  332.         $max = strlen($seed) - 1;
  333.         for($i = 0; $i < $length; $i++) {
  334.                 $hash .= $seed[mt_rand(0, $max)];
  335.         }
  336.         return $hash;
  337. }

  338. function strexists($string, $find) {
  339.         return !(strpos($string, $find) === FALSE);
  340. }

  341. function avatar($uid, $size = 'middle', $returnsrc = FALSE, $real = FALSE, $static = FALSE, $ucenterurl = '') {
  342.         global $_G;
  343.         if($_G['setting']['plugins']['func'][HOOKTYPE]['avatar']) {
  344.                 $_G['hookavatar'] = '';
  345.                 $param = func_get_args();
  346.                 hookscript('avatar', 'global', 'funcs', array('param' => $param), 'avatar');
  347.                 if($_G['hookavatar']) {
  348.                         return $_G['hookavatar'];
  349.                 }
  350.         }
  351.         static $staticavatar;
  352.         if($staticavatar === null) {
  353.                 $staticavatar = $_G['setting']['avatarmethod'];
  354.         }

  355.         $ucenterurl = empty($ucenterurl) ? $_G['setting']['ucenterurl'] : $ucenterurl;
  356.         $size = in_array($size, array('big', 'middle', 'small')) ? $size : 'middle';
  357.         $uid = abs(intval($uid));
  358.         if(!$staticavatar && !$static) {
  359.                 $timestamp = $uid == $_G['uid'] ? "&ts=1" : "";
  360.                 return $returnsrc ? $ucenterurl.'/avatar.php?uid='.$uid.'&size='.$size.($real ? '&type=real' : '').$timestamp : '<img src="'.$ucenterurl.'/avatar.php?uid='.$uid.'&size='.$size.($real ? '&type=real' : '').$timestamp.'" />';
  361.         } else {
  362.                 $uid = sprintf("%09d", $uid);
  363.                 $dir1 = substr($uid, 0, 3);
  364.                 $dir2 = substr($uid, 3, 2);
  365.                 $dir3 = substr($uid, 5, 2);
  366.                 $file = $ucenterurl.'/data/avatar/'.$dir1.'/'.$dir2.'/'.$dir3.'/'.substr($uid, -2).($real ? '_real' : '').'_avatar_'.$size.'.jpg';
  367.                 return $returnsrc ? $file : '<img src="'.$file.'" onerror="this.onerror=null;this.src=\''.$ucenterurl.'/images/noavatar_'.$size.'.gif\'" />';
  368.         }
  369. }

  370. function lang($file, $langvar = null, $vars = array(), $default = null) {
  371.         global $_G;
  372.         $fileinput = $file;
  373.         list($path, $file) = explode('/', $file);
  374.         if(!$file) {
  375.                 $file = $path;
  376.                 $path = '';
  377.         }
  378.         if(strpos($file, ':') !== false) {
  379.                 $path = 'plugin';
  380.                 list($file) = explode(':', $file);
  381.         }

  382.         if($path != 'plugin') {
  383.                 $key = $path == '' ? $file : $path.'_'.$file;
  384.                 if(!isset($_G['lang'][$key])) {
  385.                         include DISCUZ_ROOT.'./source/language/'.($path == '' ? '' : $path.'/').'lang_'.$file.'.php';
  386.                         $_G['lang'][$key] = $lang;
  387.                 }
  388.                 if(defined('IN_MOBILE') && !defined('TPL_DEFAULT')) {
  389.                         include DISCUZ_ROOT.'./source/language/mobile/lang_template.php';
  390.                         $_G['lang'][$key] = array_merge($_G['lang'][$key], $lang);
  391.                 }
  392.                 if($file != 'error' && !isset($_G['cache']['pluginlanguage_system'])) {
  393.                         loadcache('pluginlanguage_system');
  394.                 }
  395.                 if(!isset($_G['hooklang'][$fileinput])) {
  396.                         if(isset($_G['cache']['pluginlanguage_system'][$fileinput]) && is_array($_G['cache']['pluginlanguage_system'][$fileinput])) {
  397.                                 $_G['lang'][$key] = array_merge($_G['lang'][$key], $_G['cache']['pluginlanguage_system'][$fileinput]);
  398.                         }
  399.                         $_G['hooklang'][$fileinput] = true;
  400.                 }
  401.                 $returnvalue = &$_G['lang'];
  402.         } else {
  403.                 if(empty($_G['config']['plugindeveloper'])) {
  404.                         loadcache('pluginlanguage_script');
  405.                 } elseif(!isset($_G['cache']['pluginlanguage_script'][$file]) && preg_match("/^[a-z]+[a-z0-9_]*$/i", $file)) {
  406.                         if(@include(DISCUZ_ROOT.'./data/plugindata/'.$file.'.lang.php')) {
  407.                                 $_G['cache']['pluginlanguage_script'][$file] = $scriptlang[$file];
  408.                         } else {
  409.                                 loadcache('pluginlanguage_script');
  410.                         }
  411.                 }
  412.                 $returnvalue = & $_G['cache']['pluginlanguage_script'];
  413.                 !is_array($returnvalue) && $returnvalue = array();
  414.                 $key = &$file;
  415.         }
  416.         $return = $langvar !== null ? (isset($returnvalue[$key][$langvar]) ? $returnvalue[$key][$langvar] : null) : (is_array($returnvalue[$key]) ? $returnvalue[$key] : array());
  417.         $return = $return === null ? ($default !== null ? $default : ($path != 'plugin' ? '' : $file . ':') . $langvar) : $return;
  418.         $searchs = $replaces = array();
  419.         if($vars && is_array($vars)) {
  420.                 foreach($vars as $k => $v) {
  421.                         $searchs[] = '{'.$k.'}';
  422.                         $replaces[] = $v;
  423.                 }
  424.         }
  425.         if(is_string($return) && strpos($return, '{_G/') !== false) {
  426.                 preg_match_all('/\{_G\/(.+?)\}/', $return, $gvar);
  427.                 foreach($gvar[0] as $k => $v) {
  428.                         $searchs[] = $v;
  429.                         $replaces[] = getglobal($gvar[1][$k]);
  430.                 }
  431.         }
  432.         $return = str_replace($searchs, $replaces, $return);
  433.         return $return;
  434. }

  435. function checktplrefresh($maintpl, $subtpl, $timecompare, $templateid, $cachefile, $tpldir, $file) {
  436.         static $tplrefresh, $timestamp, $targettplname;
  437.         if($tplrefresh === null) {
  438.                 $tplrefresh = getglobal('config/output/tplrefresh');
  439.                 $timestamp = getglobal('timestamp');
  440.         }

  441.         if(empty($timecompare) || $tplrefresh == 1 || ($tplrefresh > 1 && !($timestamp % $tplrefresh))) {
  442.                 if(!file_exists(DISCUZ_ROOT.$subtpl)){
  443.                         $subtpl = substr($subtpl, 0, -4).'.php';
  444.                 }
  445.                 if(empty($timecompare) || @filemtime(DISCUZ_ROOT.$subtpl) > $timecompare) {
  446.                         require_once DISCUZ_ROOT.'/source/class/class_template.php';
  447.                         $template = new template();
  448.                         $template->parse_template($maintpl, $templateid, $tpldir, $file, $cachefile);
  449.                         if($targettplname === null) {
  450.                                 $targettplname = getglobal('style/tplfile');
  451.                                 if(!empty($targettplname)) {
  452.                                         include_once libfile('function/block');
  453.                                         $targettplname = strtr($targettplname, ':', '_');
  454.                                         update_template_block($targettplname, getglobal('style/tpldirectory'), $template->blocks);
  455.                                 }
  456.                                 $targettplname = true;
  457.                         }
  458.                         return TRUE;
  459.                 }
  460.         }
  461.         return FALSE;
  462. }

  463. function template($file, $templateid = 0, $tpldir = '', $gettplfile = 0, $primaltpl='') {
  464.         global $_G;

  465.         if($_G['setting']['plugins']['func'][HOOKTYPE]['template']) {
  466.                 $param = func_get_args();
  467.                 $hookreturn = hookscript('template', 'global', 'funcs', array('param' => $param, 'caller' => 'template'), 'template');
  468.                 if($hookreturn) {
  469.                         return $hookreturn;
  470.                 }
  471.         }

  472.         static $_init_style = false;
  473.         if($_init_style === false) {
  474.                 C::app()->_init_style();
  475.                 $_init_style = true;
  476.         }
  477.         $oldfile = $file;
  478.         if(strpos($file, ':') !== false) {
  479.                 $clonefile = '';
  480.                 list($templateid, $file, $clonefile) = explode(':', $file);
  481.                 $oldfile = $file;
  482.                 $file = empty($clonefile) ? $file : $file.'_'.$clonefile;
  483.                 if($templateid == 'diy') {
  484.                         $indiy = false;
  485.                         $_G['style']['tpldirectory'] = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : '');
  486.                         $_G['style']['prefile'] = '';
  487.                         $diypath = DISCUZ_ROOT.'./data/diy/'.$_G['style']['tpldirectory'].'/'; //DIY模板文件目录
  488.                         $preend = '_diy_preview';
  489.                         $_GET['preview'] = !empty($_GET['preview']) ? $_GET['preview'] : '';
  490.                         $curtplname = $oldfile;
  491.                         $basescript = $_G['mod'] == 'viewthread' && !empty($_G['thread']) ? 'forum' : $_G['basescript'];
  492.                         if(isset($_G['cache']['diytemplatename'.$basescript])) {
  493.                                 $diytemplatename = &$_G['cache']['diytemplatename'.$basescript];
  494.                         } else {
  495.                                 if(!isset($_G['cache']['diytemplatename'])) {
  496.                                         loadcache('diytemplatename');
  497.                                 }
  498.                                 $diytemplatename = &$_G['cache']['diytemplatename'];
  499.                         }
  500.                         $tplsavemod = 0;
  501.                         if(isset($diytemplatename[$file]) && file_exists($diypath.$file.'.htm') && ($tplsavemod = 1) || empty($_G['forum']['styleid']) && ($file = $primaltpl ? $primaltpl : $oldfile) && isset($diytemplatename[$file]) && file_exists($diypath.$file.'.htm')) {
  502.                                 $tpldir = 'data/diy/'.$_G['style']['tpldirectory'].'/';
  503.                                 !$gettplfile && $_G['style']['tplsavemod'] = $tplsavemod;
  504.                                 $curtplname = $file;
  505.                                 if(isset($_GET['diy']) && $_GET['diy'] == 'yes' || isset($_GET['diy']) && $_GET['preview'] == 'yes') { //DIY模式或预览模式下做以下判断
  506.                                         $flag = file_exists($diypath.$file.$preend.'.htm');
  507.                                         if($_GET['preview'] == 'yes') {
  508.                                                 $file .= $flag ? $preend : '';
  509.                                         } else {
  510.                                                 $_G['style']['prefile'] = $flag ? 1 : '';
  511.                                         }
  512.                                 }
  513.                                 $indiy = true;
  514.                         } else {
  515.                                 $file = $primaltpl ? $primaltpl : $oldfile;
  516.                         }
  517.                         $tplrefresh = $_G['config']['output']['tplrefresh'];
  518.                         if($indiy && ($tplrefresh ==1 || ($tplrefresh > 1 && !($_G['timestamp'] % $tplrefresh))) && filemtime($diypath.$file.'.htm') < filemtime(DISCUZ_ROOT.$_G['style']['tpldirectory'].'/'.($primaltpl ? $primaltpl : $oldfile).'.htm')) {
  519.                                 if (!updatediytemplate($file, $_G['style']['tpldirectory'])) {
  520.                                         unlink($diypath.$file.'.htm');
  521.                                         $tpldir = '';
  522.                                 }
  523.                         }

  524.                         if (!$gettplfile && empty($_G['style']['tplfile'])) {
  525.                                 $_G['style']['tplfile'] = empty($clonefile) ? $curtplname : $oldfile.':'.$clonefile;
  526.                         }

  527.                         $_G['style']['prefile'] = !empty($_GET['preview']) && $_GET['preview'] == 'yes' ? '' : $_G['style']['prefile'];

  528.                 } else {
  529.                         $tpldir = './source/plugin/'.$templateid.'/template';
  530.                 }
  531.         }

  532.         $file .= !empty($_G['inajax']) && ($file == 'common/header' || $file == 'common/footer') ? '_ajax' : '';
  533.         $tpldir = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : '');
  534.         $templateid = $templateid ? $templateid : (defined('TEMPLATEID') ? TEMPLATEID : '');
  535.         $filebak = $file;

  536.         if(defined('IN_MOBILE') && !defined('TPL_DEFAULT') && strpos($file, $_G['mobiletpl'][IN_MOBILE].'/') === false || (isset($_G['forcemobilemessage']) && $_G['forcemobilemessage'])) {
  537.                 if(IN_MOBILE == 2) {
  538.                         $oldfile .= !empty($_G['inajax']) && ($oldfile == 'common/header' || $oldfile == 'common/footer') ? '_ajax' : '';
  539.                 }
  540.                 $file = $_G['mobiletpl'][IN_MOBILE].'/'.$oldfile;
  541.         }

  542.         if(!$tpldir) {
  543.                 $tpldir = './template/default';
  544.         }
  545.         $tplfile = $tpldir.'/'.$file.'.htm';

  546.         $file == 'common/header' && defined('CURMODULE') && CURMODULE && $file = 'common/header_'.$_G['basescript'].'_'.CURMODULE;

  547.         if(defined('IN_MOBILE') && !defined('TPL_DEFAULT')) {
  548.                 if(strpos($tpldir, 'plugin')) {
  549.                         if(!file_exists(DISCUZ_ROOT.$tpldir.'/'.$file.'.htm') && !file_exists(DISCUZ_ROOT.$tpldir.'/'.$file.'.php')) {
  550.                                 $url = $_SERVER['REQUEST_URI'].(strexists($_SERVER['REQUEST_URI'], '?') ? '&' : '?').'mobile=no';
  551.                                 showmessage('mobile_template_no_found', '', array('url' => $url));
  552.                         } else {
  553.                                 $mobiletplfile = $tpldir.'/'.$file.'.htm';
  554.                         }
  555.                 }
  556.                 !$mobiletplfile && $mobiletplfile = $file.'.htm';
  557.                 if(strpos($tpldir, 'plugin') && (file_exists(DISCUZ_ROOT.$mobiletplfile) || file_exists(substr(DISCUZ_ROOT.$mobiletplfile, 0, -4).'.php'))) {
  558.                         $tplfile = $mobiletplfile;
  559.                 } elseif(!file_exists(DISCUZ_ROOT.TPLDIR.'/'.$mobiletplfile) && !file_exists(substr(DISCUZ_ROOT.TPLDIR.'/'.$mobiletplfile, 0, -4).'.php')) {
  560.                         $mobiletplfile = './template/default/'.$file.'.htm';
  561.                         if(!file_exists(DISCUZ_ROOT.$mobiletplfile) && !$_G['forcemobilemessage']) {
  562.                                 $tplfile = str_replace($_G['mobiletpl'][IN_MOBILE].'/', '', $tplfile);
  563.                                 $file = str_replace($_G['mobiletpl'][IN_MOBILE].'/', '', $file);
  564.                                 define('TPL_DEFAULT', true);
  565.                         } else {
  566.                                 $tplfile = $mobiletplfile;
  567.                         }
  568.                 } else {
  569.                         $tplfile = TPLDIR.'/'.$mobiletplfile;
  570.                 }
  571.         }

  572.         $cachefile = './data/template/'.(defined('STYLEID') ? STYLEID.'_' : '_').$templateid.'_'.str_replace('/', '_', $file).'.tpl.php';
  573.         if($templateid != 1 && !file_exists(DISCUZ_ROOT.$tplfile) && !file_exists(substr(DISCUZ_ROOT.$tplfile, 0, -4).'.php')
  574.                         && !file_exists(DISCUZ_ROOT.($tplfile = $tpldir.$filebak.'.htm'))) {
  575.                 $tplfile = './template/default/'.$filebak.'.htm';
  576.         }

  577.         if($gettplfile) {
  578.                 return $tplfile;
  579.         }
  580.         checktplrefresh($tplfile, $tplfile, @filemtime(DISCUZ_ROOT.$cachefile), $templateid, $cachefile, $tpldir, $file);
  581.         return DISCUZ_ROOT.$cachefile;
  582. }

  583. function dsign($str, $length = 16){
  584.         return substr(md5($str.getglobal('config/security/authkey')), 0, ($length ? max(8, $length) : 16));
  585. }

  586. function modauthkey($id) {
  587.         return md5(getglobal('username').getglobal('uid').getglobal('authkey').substr(TIMESTAMP, 0, -7).$id);
  588. }

  589. function getcurrentnav() {
  590.         global $_G;
  591.         if(!empty($_G['mnid'])) {
  592.                 return $_G['mnid'];
  593.         }
  594.         $mnid = '';
  595.         $_G['basefilename'] = $_G['basefilename'] == $_G['basescript'] ? $_G['basefilename'] : $_G['basescript'].'.php';
  596.         if(isset($_G['setting']['navmns'][$_G['basefilename']])) {
  597.                 if($_G['basefilename'] == 'home.php' && $_GET['mod'] == 'space' && (empty($_GET['do']) || in_array($_GET['do'], array('follow', 'view')))) {
  598.                         $_GET['mod'] = 'follow';
  599.                 }
  600.                 foreach($_G['setting']['navmns'][$_G['basefilename']] as $navmn) {
  601.                         if($navmn[0] == array_intersect_assoc($navmn[0], $_GET) || (isset($_GET['gid']) && $navmn[0]['mod'] == 'forumdisplay' && $navmn[0]['fid'] == $_GET['gid'])  || ($navmn[0]['mod'] == 'space' && $_GET['mod'] == 'spacecp' && ($navmn[0]['do'] == $_GET['ac'] || $navmn[0]['do'] == 'album' && $_GET['ac'] == 'upload'))) {
  602.                                 $mnid = $navmn[1];
  603.                         }
  604.                 }

  605.         }
  606.         if(!$mnid && isset($_G['setting']['navdms'])) {
  607.                 foreach($_G['setting']['navdms'] as $navdm => $navid) {
  608.                         if(strpos(strtolower($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']), $navdm) !== false && strpos(strtolower($_SERVER['HTTP_HOST']), $navdm) === false) {
  609.                                 $mnid = $navid;
  610.                                 break;
  611.                         }
  612.                 }
  613.         }
  614.         if(!$mnid && isset($_G['setting']['navmn'][$_G['basefilename']])) {
  615.                 $mnid = $_G['setting']['navmn'][$_G['basefilename']];
  616.         }
  617.         return $mnid;
  618. }

  619. function loaducenter() {
  620.         require_once DISCUZ_ROOT.'./config/config_ucenter.php';
  621.         require_once DISCUZ_ROOT.'./uc_client/client.php';
  622. }

  623. function loadcache($cachenames, $force = false) {
  624.         global $_G;
  625.         static $loadedcache = array();
  626.         $cachenames = is_array($cachenames) ? $cachenames : array($cachenames);
  627.         $caches = array();
  628.         foreach ($cachenames as $k) {
  629.                 if(!isset($loadedcache[$k]) || $force) {
  630.                         $caches[] = $k;
  631.                         $loadedcache[$k] = true;
  632.                 }
  633.         }

  634.         if(!empty($caches)) {
  635.                 $cachedata = C::t('common_syscache')->fetch_all($caches);
  636.                 foreach($cachedata as $cname => $data) {
  637.                         if($cname == 'setting') {
  638.                                 $_G['setting'] = $data;
  639.                         } elseif($cname == 'usergroup_'.$_G['groupid']) {
  640.                                 $_G['cache'][$cname] = $_G['group'] = $data;
  641.                         } elseif($cname == 'style_default') {
  642.                                 $_G['cache'][$cname] = $_G['style'] = $data;
  643.                         } elseif($cname == 'grouplevels') {
  644.                                 $_G['grouplevels'] = $data;
  645.                         } else {
  646.                                 $_G['cache'][$cname] = $data;
  647.                         }
  648.                 }
  649.         }
  650.         return true;
  651. }

  652. function dgmdate($timestamp, $format = 'dt', $timeoffset = '9999', $uformat = '') {
  653.         global $_G;
  654.         $format == 'u' && !$_G['setting']['dateconvert'] && $format = 'dt';
  655.         static $dformat, $tformat, $dtformat, $offset, $lang;
  656.         if($dformat === null) {
  657.                 $dformat = getglobal('setting/dateformat');
  658.                 $tformat = getglobal('setting/timeformat');
  659.                 $dtformat = $dformat.' '.$tformat;
  660.                 $offset = getglobal('member/timeoffset');
  661.                 $sysoffset = getglobal('setting/timeoffset');
  662.                 $offset = $offset == 9999 ? ($sysoffset ? $sysoffset : 0) : $offset;
  663.                 $lang = lang('core', 'date');
  664.         }
  665.         $timeoffset = $timeoffset == 9999 ? $offset : $timeoffset;
  666.         $timestamp += $timeoffset * 3600;
  667.         $format = empty($format) || $format == 'dt' ? $dtformat : ($format == 'd' ? $dformat : ($format == 't' ? $tformat : $format));
  668.         if($format == 'u') {
  669.                 $todaytimestamp = TIMESTAMP - (TIMESTAMP + $timeoffset * 3600) % 86400 + $timeoffset * 3600;
  670.                 $s = gmdate(!$uformat ? $dtformat : $uformat, $timestamp);
  671.                 $time = TIMESTAMP + $timeoffset * 3600 - $timestamp;
  672.                 if($timestamp >= $todaytimestamp) {
  673.                         if($time > 3600) {
  674.                                 $return = intval($time / 3600).' '.$lang['hour'].$lang['before'];
  675.                         } elseif($time > 1800) {
  676.                                 $return = $lang['half'].$lang['hour'].$lang['before'];
  677.                         } elseif($time > 60) {
  678.                                 $return = intval($time / 60).' '.$lang['min'].$lang['before'];
  679.                         } elseif($time > 0) {
  680.                                 $return = $time.' '.$lang['sec'].$lang['before'];
  681.                         } elseif($time == 0) {
  682.                                 $return = $lang['now'];
  683.                         } else {
  684.                                 $return = $s;
  685.                         }
  686.                         if($time >=0 && !defined('IN_MOBILE')) {
  687.                                 $return = '<span title="'.$s.'">'.$return.'</span>';
  688.                         }
  689.                 } elseif(($days = intval(($todaytimestamp - $timestamp) / 86400)) >= 0 && $days < 7) {
  690.                         if($days == 0) {
  691.                                 $return = $lang['yday'].' '.gmdate($tformat, $timestamp);
  692.                         } elseif($days == 1) {
  693.                                 $return = $lang['byday'].' '.gmdate($tformat, $timestamp);
  694.                         } else {
  695.                                 $return = ($days + 1).' '.$lang['day'].$lang['before'];
  696.                         }
  697.                         if(!defined('IN_MOBILE')) {
  698.                                 $return = '<span title="'.$s.'">'.$return.'</span>';
  699.                         }
  700.                 } else {
  701.                         $return = $s;
  702.                 }
  703.                 return $return;
  704.         } else {
  705.                 return gmdate($format, $timestamp);
  706.         }
  707. }

  708. function dmktime($date) {
  709.         if(strpos($date, '-')) {
  710.                 $time = explode('-', $date);
  711.                 return mktime(0, 0, 0, $time[1], $time[2], $time[0]);
  712.         }
  713.         return 0;
  714. }

  715. function dnumber($number) {
  716.         return abs($number) > 10000 ? '<span title="'.$number.'">'.intval($number / 10000).lang('core', '10k').'</span>' : $number;
  717. }

  718. function savecache($cachename, $data) {
  719.         C::t('common_syscache')->insert($cachename, $data);
  720. }

  721. function save_syscache($cachename, $data) {
  722.         savecache($cachename, $data);
  723. }

  724. function block_get($parameter) {
  725.         include_once libfile('function/block');
  726.         block_get_batch($parameter);
  727. }

  728. function block_display($bid) {
  729.         include_once libfile('function/block');
  730.         block_display_batch($bid);
  731. }

  732. function dimplode($array) {
  733.         if(!empty($array)) {
  734.                 $array = array_map('addslashes', $array);
  735.                 return "'".implode("','", is_array($array) ? $array : array($array))."'";
  736.         } else {
  737.                 return 0;
  738.         }
  739. }

  740. function libfile($libname, $folder = '') {
  741.         $libpath = '/source/'.$folder;
  742.         if(strstr($libname, '/')) {
  743.                 list($pre, $name) = explode('/', $libname);
  744.                 $path = "{$libpath}/{$pre}/{$pre}_{$name}";
  745.         } else {
  746.                 $path = "{$libpath}/{$libname}";
  747.         }
  748.         return preg_match('/^[\w\d\/_]+$/i', $path) ? realpath(DISCUZ_ROOT.$path.'.php') : false;
  749. }

  750. function dstrlen($str) {
  751.         if(strtolower(CHARSET) != 'utf-8') {
  752.                 return strlen($str);
  753.         }
  754.         $count = 0;
  755.         for($i = 0; $i < strlen($str); $i++){
  756.                 $value = ord($str[$i]);
  757.                 if($value > 127) {
  758.                         $count++;
  759.                         if($value >= 192 && $value <= 223) $i++;
  760.                         elseif($value >= 224 && $value <= 239) $i = $i + 2;
  761.                         elseif($value >= 240 && $value <= 247) $i = $i + 3;
  762.                     }
  763.                     $count++;
  764.         }
  765.         return $count;
  766. }

  767. function cutstr($string, $length, $dot = ' ...') {
  768.         if(strlen($string) <= $length) {
  769.                 return $string;
  770.         }

  771.         $pre = chr(1);
  772.         $end = chr(1);
  773.         $string = str_replace(array('&', '"', '<', '>'), array($pre.'&'.$end, $pre.'"'.$end, $pre.'<'.$end, $pre.'>'.$end), $string);

  774.         $strcut = '';
  775.         if(strtolower(CHARSET) == 'utf-8') {

  776.                 $n = $tn = $noc = 0;
  777.                 while($n < strlen($string)) {

  778.                         $t = ord($string[$n]);
  779.                         if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
  780.                                 $tn = 1; $n++; $noc++;
  781.                         } elseif(194 <= $t && $t <= 223) {
  782.                                 $tn = 2; $n += 2; $noc += 2;
  783.                         } elseif(224 <= $t && $t <= 239) {
  784.                                 $tn = 3; $n += 3; $noc += 2;
  785.                         } elseif(240 <= $t && $t <= 247) {
  786.                                 $tn = 4; $n += 4; $noc += 2;
  787.                         } elseif(248 <= $t && $t <= 251) {
  788.                                 $tn = 5; $n += 5; $noc += 2;
  789.                         } elseif($t == 252 || $t == 253) {
  790.                                 $tn = 6; $n += 6; $noc += 2;
  791.                         } else {
  792.                                 $n++;
  793.                         }

  794.                         if($noc >= $length) {
  795.                                 break;
  796.                         }

  797.                 }
  798.                 if($noc > $length) {
  799.                         $n -= $tn;
  800.                 }

  801.                 $strcut = substr($string, 0, $n);

  802.         } else {
  803.                 $_length = $length - 1;
  804.                 for($i = 0; $i < $length; $i++) {
  805.                         if(ord($string[$i]) <= 127) {
  806.                                 $strcut .= $string[$i];
  807.                         } else if($i < $_length) {
  808.                                 $strcut .= $string[$i].$string[++$i];
  809.                         }
  810.                 }
  811.         }

  812.         $strcut = str_replace(array($pre.'&'.$end, $pre.'"'.$end, $pre.'<'.$end, $pre.'>'.$end), array('&', '"', '<', '>'), $strcut);

  813.         $pos = strrpos($strcut, chr(1));
  814.         if($pos !== false) {
  815.                 $strcut = substr($strcut,0,$pos);
  816.         }
  817.         return $strcut.$dot;
  818. }

  819. function dstripslashes($string) {
  820.         if(empty($string)) return $string;
  821.         if(is_array($string)) {
  822.                 foreach($string as $key => $val) {
  823.                         $string[$key] = dstripslashes($val);
  824.                 }
  825.         } else {
  826.                 $string = stripslashes($string);
  827.         }
  828.         return $string;
  829. }

  830. function aidencode($aid, $type = 0, $tid = 0) {
  831.         global $_G;
  832.         $s = !$type ? $aid.'|'.substr(md5($aid.md5($_G['config']['security']['authkey']).TIMESTAMP.$_G['uid']), 0, 8).'|'.TIMESTAMP.'|'.$_G['uid'].'|'.$tid : $aid.'|'.md5($aid.md5($_G['config']['security']['authkey']).TIMESTAMP).'|'.TIMESTAMP;
  833.         return rawurlencode(base64_encode($s));
  834. }

  835. function getforumimg($aid, $nocache = 0, $w = 140, $h = 140, $type = '') {
  836.         global $_G;
  837.         $key = dsign($aid.'|'.$w.'|'.$h);
  838.         return 'forum.php?mod=image&aid='.$aid.'&size='.$w.'x'.$h.'&key='.rawurlencode($key).($nocache ? '&nocache=yes' : '').($type ? '&type='.$type : '');
  839. }

  840. function rewriteoutput($type, $returntype, $host) {
  841.         global $_G;
  842.         $fextra = '';
  843.         if($type == 'forum_forumdisplay') {
  844.                 list(,,, $fid, $page, $extra) = func_get_args();
  845.                 $r = array(
  846.                         '{fid}' => empty($_G['setting']['forumkeys'][$fid]) ? $fid : $_G['setting']['forumkeys'][$fid],
  847.                         '{page}' => $page ? $page : 1,
  848.                 );
  849.         } elseif($type == 'forum_viewthread') {
  850.                 list(,,, $tid, $page, $prevpage, $extra) = func_get_args();
  851.                 $r = array(
  852.                         '{tid}' => $tid,
  853.                         '{page}' => $page ? $page : 1,
  854.                         '{prevpage}' => $prevpage && !IS_ROBOT ? $prevpage : 1,
  855.                 );
  856.         } elseif($type == 'home_space') {
  857.                 list(,,, $uid, $username, $extra) = func_get_args();
  858.                 $_G['setting']['rewritecompatible'] && $username = rawurlencode($username);
  859.                 $r = array(
  860.                         '{user}' => $uid ? 'uid' : 'username',
  861.                         '{value}' => $uid ? $uid : $username,
  862.                 );
  863.         } elseif($type == 'home_blog') {
  864.                 list(,,, $uid, $blogid, $extra) = func_get_args();
  865.                 $r = array(
  866.                         '{uid}' => $uid,
  867.                         '{blogid}' => $blogid,
  868.                 );
  869.         } elseif($type == 'group_group') {
  870.                 list(,,, $fid, $page, $extra) = func_get_args();
  871.                 $r = array(
  872.                         '{fid}' => $fid,
  873.                         '{page}' => $page ? $page : 1,
  874.                 );
  875.         } elseif($type == 'portal_topic') {
  876.                 list(,,, $name, $extra) = func_get_args();
  877.                 $r = array(
  878.                         '{name}' => $name,
  879.                 );
  880.         } elseif($type == 'portal_article') {
  881.                 list(,,, $id, $page, $extra) = func_get_args();
  882.                 $r = array(
  883.                         '{id}' => $id,
  884.                         '{page}' => $page ? $page : 1,
  885.                 );
  886.         } elseif($type == 'forum_archiver') {
  887.                 list(,, $action, $value, $page, $extra) = func_get_args();
  888.                 $host = '';
  889.                 $r = array(
  890.                         '{action}' => $action,
  891.                         '{value}' => $value,
  892.                 );
  893.                 if($page) {
  894.                         $fextra = '?page='.$page;
  895.                 }
  896.         } elseif($type == 'plugin') {
  897.                 list(,, $pluginid, $module,, $param, $extra) = func_get_args();
  898.                 $host = '';
  899.                 $r = array(
  900.                         '{pluginid}' => $pluginid,
  901.                         '{module}' => $module,
  902.                 );
  903.                 if($param) {
  904.                         $fextra = '?'.$param;
  905.                 }
  906.         }
  907.         $href = str_replace(array_keys($r), $r, $_G['setting']['rewriterule'][$type]).$fextra;
  908.         if(!$returntype) {
  909.                 return '<a href="'.$host.$href.'"'.(!empty($extra) ? stripslashes($extra) : '').'>';
  910.         } else {
  911.                 return $host.$href;
  912.         }
  913. }

  914. function mobilereplace($file, $replace) {
  915.         return helper_mobile::mobilereplace($file, $replace);
  916. }

  917. function mobileoutput() {
  918.         helper_mobile::mobileoutput();
  919. }

  920. function output() {

  921.         global $_G;


  922.         if(defined('DISCUZ_OUTPUTED')) {
  923.                 return;
  924.         } else {
  925.                 define('DISCUZ_OUTPUTED', 1);
  926.         }

  927.         if(!empty($_G['blockupdate'])) {
  928.                 block_updatecache($_G['blockupdate']['bid']);
  929.         }

  930.         if(defined('IN_MOBILE')) {
  931.                 mobileoutput();
  932.         }
  933.         $havedomain = implode('', $_G['setting']['domain']['app']);
  934.         if($_G['setting']['rewritestatus'] || !empty($havedomain)) {
  935.                 $content = ob_get_contents();
  936.                 $content = output_replace($content);


  937.                 ob_end_clean();
  938.                 $_G['gzipcompress'] ? ob_start('ob_gzhandler') : ob_start();

  939.                 echo $content;
  940.         }

  941.         if(isset($_G['makehtml'])) {
  942.                 helper_makehtml::make_html();
  943.         }

  944.         if($_G['setting']['ftp']['connid']) {
  945.                 @ftp_close($_G['setting']['ftp']['connid']);
  946.         }
  947.         $_G['setting']['ftp'] = array();

  948.         if(defined('CACHE_FILE') && CACHE_FILE && !defined('CACHE_FORBIDDEN') && !defined('IN_MOBILE') && !IS_ROBOT && !checkmobile()) {
  949.                 if(diskfreespace(DISCUZ_ROOT.'./'.$_G['setting']['cachethreaddir']) > 1000000) {
  950.                         if($fp = @fopen(CACHE_FILE, 'w')) {
  951.                                 flock($fp, LOCK_EX);
  952.                                 $content = empty($content) ? ob_get_contents() : $content;
  953.                                 $temp_md5 = md5(substr($_G['timestamp'], 0, -3).substr($_G['config']['security']['authkey'], 3, -3));
  954.                                 $temp_formhash = substr($temp_md5, 8, 8);
  955.                                 $content = preg_replace('/(name=[\'|"]formhash[\'|"] value=[\'"]|formhash=)('.constant("FORMHASH").')/ismU', '${1}'.$temp_formhash, $content);
  956.                                 $temp_siteurl = 'siteurl_'.substr($temp_md5, 16, 8);
  957.                                 $content = preg_replace('/("|\')('.preg_quote($_G['siteurl'], '/').')/ismU', '${1}'.$temp_siteurl, $content);
  958.                                 fwrite($fp, empty($content) ? ob_get_contents() : $content);
  959.                         }
  960.                         @fclose($fp);
  961.                         chmod(CACHE_FILE, 0777);
  962.                 }
  963.         }

  964.         if(defined('DISCUZ_DEBUG') && DISCUZ_DEBUG && @include(libfile('function/debug'))) {
  965.                 function_exists('debugmessage') && debugmessage();
  966.         }
  967. }

  968. function output_replace($content) {
  969.         global $_G;
  970.         if(defined('IN_MODCP') || defined('IN_ADMINCP')) return $content;
  971.         if(!empty($_G['setting']['output']['str']['search'])) {
  972.                 if(empty($_G['setting']['domain']['app']['default'])) {
  973.                         $_G['setting']['output']['str']['replace'] = str_replace('{CURHOST}', $_G['siteurl'], $_G['setting']['output']['str']['replace']);
  974.                 }
  975.                 $content = str_replace($_G['setting']['output']['str']['search'], $_G['setting']['output']['str']['replace'], $content);
  976.         }
  977.         if(!empty($_G['setting']['output']['preg']['search']) && (empty($_G['setting']['rewriteguest']) || empty($_G['uid']))) {
  978.                 if(empty($_G['setting']['domain']['app']['default'])) {
  979.                         $_G['setting']['output']['preg']['search'] = str_replace('\{CURHOST\}', preg_quote($_G['siteurl'], '/'), $_G['setting']['output']['preg']['search']);
  980.                         $_G['setting']['output']['preg']['replace'] = str_replace('{CURHOST}', $_G['siteurl'], $_G['setting']['output']['preg']['replace']);
  981.                 }

  982.                 foreach($_G['setting']['output']['preg']['search'] as $key => $value) {
  983.                         $content = preg_replace_callback($value, create_function('$matches', 'return '.$_G['setting']['output']['preg']['replace'][$key].';'), $content);
  984.                 }
  985.         }

  986.         return $content;
  987. }

  988. function output_ajax() {
  989.         global $_G;
  990.         $s = ob_get_contents();
  991.         ob_end_clean();
  992.         $s = preg_replace("/([\\x01-\\x08\\x0b-\\x0c\\x0e-\\x1f])+/", ' ', $s);
  993.         $s = str_replace(array(chr(0), ']]>'), array(' ', ']]>'), $s);
  994.         if(defined('DISCUZ_DEBUG') && DISCUZ_DEBUG && @include(libfile('function/debug'))) {
  995.                 function_exists('debugmessage') && $s .= debugmessage(1);
  996.         }
  997.         $havedomain = implode('', $_G['setting']['domain']['app']);
  998.         if($_G['setting']['rewritestatus'] || !empty($havedomain)) {
  999.         $s = output_replace($s);
  1000.         }
  1001.         return $s;
  1002. }

  1003. function runhooks($scriptextra = '') {
  1004.         if(!defined('HOOKTYPE')) {
  1005.                 define('HOOKTYPE', !defined('IN_MOBILE') ? 'hookscript' : 'hookscriptmobile');
  1006.         }
  1007.         if(defined('CURMODULE')) {
  1008.                 global $_G;
  1009.                 if($_G['setting']['plugins']['func'][HOOKTYPE]['common']) {
  1010.                         hookscript('common', 'global', 'funcs', array(), 'common');
  1011.                 }
  1012.                 hookscript(CURMODULE, $_G['basescript'], 'funcs', array(), '', $scriptextra);
  1013.         }
  1014. }

  1015. function hookscript($script, $hscript, $type = 'funcs', $param = array(), $func = '', $scriptextra = '') {
  1016.         global $_G;
  1017.         static $pluginclasses;
  1018.         if($hscript == 'home') {
  1019.                 if($script == 'space') {
  1020.                         $scriptextra = !$scriptextra ? $_GET['do'] : $scriptextra;
  1021.                         $script = 'space'.(!empty($scriptextra) ? '_'.$scriptextra : '');
  1022.                 } elseif($script == 'spacecp') {
  1023.                         $scriptextra = !$scriptextra ? $_GET['ac'] : $scriptextra;
  1024.                         $script .= !empty($scriptextra) ? '_'.$scriptextra : '';
  1025.                 }
  1026.         }
  1027.         if(!isset($_G['setting'][HOOKTYPE][$hscript][$script][$type])) {
  1028.                 return;
  1029.         }
  1030.         if(!isset($_G['cache']['plugin'])) {
  1031.                 loadcache('plugin');
  1032.         }
  1033.         foreach((array)$_G['setting'][HOOKTYPE][$hscript][$script]['module'] as $identifier => $include) {
  1034.                 if($_G['pluginrunlist'] && !in_array($identifier, $_G['pluginrunlist'])) {
  1035.                         continue;
  1036.                 }
  1037.                 $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']);
  1038.                 if($hooksadminid[$identifier]) {
  1039.                         @include_once DISCUZ_ROOT.'./source/plugin/'.$include.'.class.php';
  1040.                 }
  1041.         }
  1042.         if(@is_array($_G['setting'][HOOKTYPE][$hscript][$script][$type])) {
  1043.                 $_G['inhookscript'] = true;
  1044.                 $funcs = !$func ? $_G['setting'][HOOKTYPE][$hscript][$script][$type] : array($func => $_G['setting'][HOOKTYPE][$hscript][$script][$type][$func]);
  1045.                 foreach($funcs as $hookkey => $hookfuncs) {
  1046.                         foreach($hookfuncs as $hookfunc) {
  1047.                                 if($hooksadminid[$hookfunc[0]]) {
  1048.                                         $classkey = (HOOKTYPE != 'hookscriptmobile' ? '' : 'mobile').'plugin_'.($hookfunc[0].($hscript != 'global' ? '_'.$hscript : ''));
  1049.                                         if(!class_exists($classkey, false)) {
  1050.                                                 continue;
  1051.                                         }
  1052.                                         if(!isset($pluginclasses[$classkey])) {
  1053.                                                 $pluginclasses[$classkey] = new $classkey;
  1054.                                         }
  1055.                                         if(!method_exists($pluginclasses[$classkey], $hookfunc[1])) {
  1056.                                                 continue;
  1057.                                         }
  1058.                                         $return = call_user_func(array($pluginclasses[$classkey], $hookfunc[1]), $param);

  1059.                                         if(substr($hookkey, -7) == '_extend' && !empty($_G['setting']['pluginhooks'][$hookkey])) {
  1060.                                                 continue;
  1061.                                         }

  1062.                                         if(is_array($return)) {
  1063.                                                 if(!isset($_G['setting']['pluginhooks'][$hookkey]) || is_array($_G['setting']['pluginhooks'][$hookkey])) {
  1064.                                                         foreach($return as $k => $v) {
  1065.                                                                 $_G['setting']['pluginhooks'][$hookkey][$k] .= $v;
  1066.                                                         }
  1067.                                                 } else {
  1068.                                                         foreach($return as $k => $v) {
  1069.                                                                 $_G['setting']['pluginhooks'][$hookkey][$k] = $v;
  1070.                                                         }
  1071.                                                 }
  1072.                                         } else {
  1073.                                                 if(!is_array($_G['setting']['pluginhooks'][$hookkey])) {
  1074.                                                         $_G['setting']['pluginhooks'][$hookkey] .= $return;
  1075.                                                 } else {
  1076.                                                         foreach($_G['setting']['pluginhooks'][$hookkey] as $k => $v) {
  1077.                                                                 $_G['setting']['pluginhooks'][$hookkey][$k] .= $return;
  1078.                                                         }
  1079.                                                 }
  1080.                                         }
  1081.                                 }
  1082.                         }
  1083.                 }
  1084.         }
  1085.         $_G['inhookscript'] = false;
  1086. }

  1087. function hookscriptoutput($tplfile) {
  1088.         global $_G;
  1089.         if(!empty($_G['hookscriptoutput'])) {
  1090.                 return;
  1091.         }
  1092.         hookscript('global', 'global');
  1093.         $_G['hookscriptoutput'] = true;
  1094.         if(defined('CURMODULE')) {
  1095.                 $param = array('template' => $tplfile, 'message' => $_G['hookscriptmessage'], 'values' => $_G['hookscriptvalues']);
  1096.                 hookscript(CURMODULE, $_G['basescript'], 'outputfuncs', $param);
  1097.         }
  1098. }

  1099. function pluginmodule($pluginid, $type) {
  1100.         global $_G;
  1101.         $pluginid = $pluginid ? preg_replace("/[^A-Za-z0-9_:]/", '', $pluginid) : '';
  1102.         if(!isset($_G['cache']['plugin'])) {
  1103.                 loadcache('plugin');
  1104.         }
  1105.         list($identifier, $module) = explode(':', $pluginid);
  1106.         if(!is_array($_G['setting']['plugins'][$type]) || !array_key_exists($pluginid, $_G['setting']['plugins'][$type])) {
  1107.                 showmessage('plugin_nonexistence');
  1108.         }
  1109.         if(!empty($_G['setting']['plugins'][$type][$pluginid]['url'])) {
  1110.                 dheader('location: '.$_G['setting']['plugins'][$type][$pluginid]['url']);
  1111.         }
  1112.         $directory = $_G['setting']['plugins'][$type][$pluginid]['directory'];
  1113.         if(empty($identifier) || !preg_match("/^[a-z]+[a-z0-9_]*\/$/i", $directory) || !preg_match("/^[a-z0-9_\-]+$/i", $module)) {
  1114.                 showmessage('undefined_action');
  1115.         }
  1116.         if(@!file_exists(DISCUZ_ROOT.($modfile = './source/plugin/'.$directory.$module.'.inc.php'))) {
  1117.                 showmessage('plugin_module_nonexistence', '', array('mod' => $modfile));
  1118.         }
  1119.         return DISCUZ_ROOT.$modfile;
  1120. }
  1121. function updatecreditbyaction($action, $uid = 0, $extrasql = array(), $needle = '', $coef = 1, $update = 1, $fid = 0) {

  1122.         $credit = credit::instance();
  1123.         if($extrasql) {
  1124.                 $credit->extrasql = $extrasql;
  1125.         }
  1126.         return $credit->execrule($action, $uid, $needle, $coef, $update, $fid);
  1127. }

  1128. function checklowerlimit($action, $uid = 0, $coef = 1, $fid = 0, $returnonly = 0) {
  1129.         require_once libfile('function/credit');
  1130.         return _checklowerlimit($action, $uid, $coef, $fid, $returnonly);
  1131. }

  1132. function batchupdatecredit($action, $uids = 0, $extrasql = array(), $coef = 1, $fid = 0) {

  1133.         $credit = & credit::instance();
  1134.         if($extrasql) {
  1135.                 $credit->extrasql = $extrasql;
  1136.         }
  1137.         return $credit->updatecreditbyrule($action, $uids, $coef, $fid);
  1138. }


  1139. function updatemembercount($uids, $dataarr = array(), $checkgroup = true, $operation = '', $relatedid = 0, $ruletxt = '', $customtitle = '', $custommemo = '') {
  1140.         if(!empty($uids) && (is_array($dataarr) && $dataarr)) {
  1141.                 require_once libfile('function/credit');
  1142.                 return _updatemembercount($uids, $dataarr, $checkgroup, $operation, $relatedid, $ruletxt, $customtitle, $custommemo);
  1143.         }
  1144.         return true;
  1145. }

  1146. function checkusergroup($uid = 0) {
  1147.         $credit = & credit::instance();
  1148.         $credit->checkusergroup($uid);
  1149. }

  1150. function checkformulasyntax($formula, $operators, $tokens) {
  1151.         $var = implode('|', $tokens);
  1152.         $operator = implode('', $operators);

  1153.         $operator = str_replace(
  1154.                 array('+', '-', '*', '/', '(', ')', '{', '}', '\''),
  1155.                 array('\+', '\-', '\*', '\/', '\(', '\)', '\{', '\}', '\\\''),
  1156.                 $operator
  1157.         );

  1158.         if(!empty($formula)) {
  1159.                 if(!preg_match("/^([$operator\.\d\(\)]|(($var)([$operator\(\)]|$)+))+$/", $formula) || !is_null(eval(preg_replace("/($var)/", "\$\\1", $formula).';'))){
  1160.                         return false;
  1161.                 }
  1162.         }
  1163.         return true;
  1164. }

  1165. function checkformulacredits($formula) {
  1166.         return checkformulasyntax(
  1167.                 $formula,
  1168.                 array('+', '-', '*', '/', ' '),
  1169.                 array('extcredits[1-8]', 'digestposts', 'posts', 'threads', 'oltime', 'friends', 'doings', 'polls', 'blogs', 'albums', 'sharings')
  1170.         );
  1171. }

  1172. function debug($var = null, $vardump = false) {
  1173.         echo '<pre>';
  1174.         $vardump = empty($var) ? true : $vardump;
  1175.         if($vardump) {
  1176.                 var_dump($var);
  1177.         } else {
  1178.                 print_r($var);
  1179.         }
  1180.         exit();
  1181. }

  1182. function debuginfo() {
  1183.         global $_G;
  1184.         if(getglobal('setting/debug')) {
  1185.                 $db = & DB::object();
  1186.                 $_G['debuginfo'] = array(
  1187.                     'time' => number_format((microtime(true) - $_G['starttime']), 6),
  1188.                     'queries' => $db->querynum,
  1189.                     'memory' => ucwords(C::memory()->type)
  1190.                     );
  1191.                 if($db->slaveid) {
  1192.                         $_G['debuginfo']['queries'] = 'Total '.$db->querynum.', Slave '.$db->slavequery;
  1193.                 }
  1194.                 return TRUE;
  1195.         } else {
  1196.                 return FALSE;
  1197.         }
  1198. }

  1199. function getfocus_rand($module) {
  1200.         global $_G;

  1201.         if(empty($_G['setting']['focus']) || !array_key_exists($module, $_G['setting']['focus']) || !empty($_G['cookie']['nofocus_'.$module]) || !$_G['setting']['focus'][$module]) {
  1202.                 return null;
  1203.         }
  1204.         loadcache('focus');
  1205.         if(empty($_G['cache']['focus']['data']) || !is_array($_G['cache']['focus']['data'])) {
  1206.                 return null;
  1207.         }
  1208.         $focusid = $_G['setting']['focus'][$module][array_rand($_G['setting']['focus'][$module])];
  1209.         return $focusid;
  1210. }

  1211. function check_seccode($value, $idhash, $fromjs = 0, $modid = '') {
  1212.         return helper_seccheck::check_seccode($value, $idhash, $fromjs, $modid);
  1213. }

  1214. function check_secqaa($value, $idhash) {
  1215.         return helper_seccheck::check_secqaa($value, $idhash);
  1216. }

  1217. function seccheck($rule, $param = array()) {
  1218.         return helper_seccheck::seccheck($rule, $param);
  1219. }

  1220. function make_seccode($seccode = '') {
  1221.         return helper_seccheck::make_seccode($seccode);
  1222. }

  1223. function make_secqaa() {
  1224.         return helper_seccheck::make_secqaa();
  1225. }

  1226. function adshow($parameter) {
  1227.         global $_G;
  1228.         if($_G['inajax'] || $_G['group']['closead']) {
  1229.                 return;
  1230.         }
  1231.         if(isset($_G['config']['plugindeveloper']) && $_G['config']['plugindeveloper'] == 2) {
  1232.                 return '<hook>[ad '.$parameter.']</hook>';
  1233.         }
  1234.         $params = explode('/', $parameter);
  1235.         $customid = 0;
  1236.         $customc = explode('_', $params[0]);
  1237.         if($customc[0] == 'custom') {
  1238.                 $params[0] = $customc[0];
  1239.                 $customid = $customc[1];
  1240.         }
  1241.         $adcontent = null;
  1242.         if(empty($_G['setting']['advtype']) || !in_array($params[0], $_G['setting']['advtype'])) {
  1243.                 $adcontent = '';
  1244.         }
  1245.         if($adcontent === null) {
  1246.                 loadcache('advs');
  1247.                 $adids = array();
  1248.                 $evalcode = &$_G['cache']['advs']['evalcode'][$params[0]];
  1249.                 $parameters = &$_G['cache']['advs']['parameters'][$params[0]];
  1250.                 $codes = &$_G['cache']['advs']['code'][$_G['basescript']][$params[0]];
  1251.                 if(!empty($codes)) {
  1252.                         foreach($codes as $adid => $code) {
  1253.                                 $parameter = &$parameters[$adid];
  1254.                                 $checked = true;
  1255.                                 @eval($evalcode['check']);
  1256.                                 if($checked) {
  1257.                                         $adids[] = $adid;
  1258.                                 }
  1259.                         }
复制代码



我知道答案 回答被采纳将会获得1 贡献 已有3人回答
回复

使用道具 举报

1

主题

1

回帖

6

积分

初学乍练

贡献
0 点
金币
5 个
 楼主| 发表于 2022-7-4 02:17:59 | 显示全部楼层
                        if(!empty($adids)) {                                 $adcode = $extra = '';                                 @eval($evalcode['create']);                                 if(empty($notag)) {                                         $adcontent = '<div'.($params[1] != '' ? ' class="'.$params[1].'"' : '').$extra.'>'.$adcode.'</div>';                                 } else {                                         $adcontent = $adcode;                                 }                         }                 }         }         $adfunc = 'ad_'.$params[0];         $_G['setting']['pluginhooks'][$adfunc] = null;         hookscript('ad', 'global', 'funcs', array('params' => $params, 'content' => $adcontent, 'customid' => $customid), $adfunc);         if(!$_G['setting']['hookscript']['global']['ad']['funcs'][$adfunc]) {                 hookscript('ad', $_G['basescript'], 'funcs', array('params' => $params, 'content' => $adcontent, 'customid' => $customid), $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, $modasban = TRUE) {         return helper_form::censor($message, $modword, $return, $modasban); }  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'] = '';         }          list($http_host,)=explode(':', $_SERVER['HTTP_HOST']);          if(!empty($reurl['host']) && !in_array($reurl['host'], array($http_host, 'www.'.$http_host)) && !in_array($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;         $ftpconfig = getglobal('setting/ftp');         if(empty($ftpconfig['on']) || empty($ftpconfig['host'])) {                 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(preg_match('/^https?:\/\//is', $_G['cache']['usergroups'][$groupid]['icon'])) {                         $s = '<img src="'.$_G['cache']['usergroups'][$groupid]['icon'].'" alt="" class="vm" />';                 } else {                         $s = '<img src="'.$_G['setting']['attachurl'].'common/'.$_G['cache']['usergroups'][$groupid]['icon'].'" alt="" class="vm" />';                 }         }         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', 'add', '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' || $cmd == 'add' ? $value : '').$prefix.$k;                                 }                         } else {                                 C::memory()->debug[$cmd][] = ($cmd == 'get' || $cmd == 'rm' || $cmd == 'add' ? $value : '').$prefix.$key;                         }                 }                 switch ($cmd) {                         case 'set': return C::memory()->set($key, $value, $ttl, $prefix); break;                         case 'add': return C::memory()->add($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);         }         $groupterms = dunserialize(getuserprofile('groupterms'));         foreach(explode("\t", $_G['member']['extgroupids']) as $extgroupid) {                 if($extgroupid = intval(trim($extgroupid))) {                         if($groupterms['ext'][$extgroupid] && $groupterms['ext'][$extgroupid] < TIMESTAMP){                                 continue;                         }                         $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 = '') { }  function useractionlog($uid, $action) {         return helper_log::useractionlog($uid, $action); }  function getuseraction($var) {         return helper_log::getuseraction($var); }  function getuserapp($panel = 0) {         return ''; }  function getmyappiconpath($appid, $iconstatus=0) {         return ''; }  function getexpiration() {         global $_G;         $date = getdate($_G['timestamp']);         return mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year']) + 86400; }  function return_bytes($val) {         $last = strtolower($val[strlen($val)-1]);         if (!is_numeric($val)) {                 $val = substr(trim($val), 0, -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() { }  function dintval($int, $allowarray = false) {         $ret = intval($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 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);         } }    ?>
回复 支持 反对

使用道具 举报

14

主题

1791

回帖

2058

积分

应用开发者

discuz 老兵

贡献
8 点
金币
188 个
QQ
发表于 2022-7-4 22:17:11 | 显示全部楼层
  和官方文件对比下
回复 支持 反对

使用道具 举报

56

主题

1457

回帖

3万

积分

管理员

贡献
2072 点
金币
1383 个
发表于 2022-7-5 00:34:17 | 显示全部楼层
没改过就是误报,webshell查杀误报很常见
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 关注公众号
  • 有偿服务微信
  • 有偿服务QQ

手机版|小黑屋|Discuz! 官方交流社区 ( 皖ICP备16010102号 |皖公网安备34010302002376号 )|网站地图|star

GMT+8, 2024-5-2 05:27 , Processed in 0.059596 second(s), 7 queries , Redis On.

Powered by Discuz! W1.0 Licensed

Cpoyright © 2001-2024 Discuz! Team.

关灯 在本版发帖
有偿服务QQ
有偿服务微信
返回顶部
快速回复 返回顶部 返回列表