$val) { $string[$key] = dhtmlspecialchars($val, $flags); } } else { if($flags === null) { $string = str_replace(['&', '"', '<', '>'], ['&', '"', '<', '>'], $string); } else { if(PHP_VERSION < '5.4.0') { $string = htmlspecialchars($string, $flags); } else { if(strtolower(CHARSET) == 'utf-8') { $charset = 'UTF-8'; } else { $charset = 'ISO-8859-1'; } $string = htmlspecialchars($string, $flags, $charset); } } } return $string; } 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 checkrobot($useragent = '') { static $kw_spiders = ['bot', 'crawl', 'spider', 'slurp', 'sohu-search', 'lycos', 'robozilla']; static $kw_browsers = ['msie', 'netscape', 'opera', 'konqueror', 'mozilla']; $useragent = strtolower(empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent); if(dstrpos($useragent, $kw_spiders)) return true; if(!str_contains($useragent, 'http://') && dstrpos($useragent, $kw_browsers)) return false; return false; } function dstrpos($string, $arr, $returnvalue = false) { if(empty($string)) return false; foreach((array)$arr as $v) { if(str_contains($string, $v)) { $return = $returnvalue ? $v : true; return $return; } } return false; } function checktplrefresh($maintpl, $subtpl, $timecompare, $templateid, $cachefile, $tpldir, $file) { static $tplrefresh, $timestamp, $targettplname; if($tplrefresh === null) { $tplrefresh = getglobal('config/output/tplrefresh'); $timestamp = getglobal('timestamp'); } if(empty($timecompare) || $tplrefresh == 1 || ($tplrefresh > 1 && !($timestamp % $tplrefresh))) { if(empty($timecompare) || tplfile::filemtime($subtpl) > $timecompare) { require_once DISCUZ_ROOT.'/source/class/class_template.php'; $template = new template(); $template->parse_template($maintpl, $templateid, $tpldir, $file, $cachefile); return TRUE; } } return FALSE; } function fileext($filename) { return addslashes(strtolower(substr(strrchr($filename, '.'), 1, 10))); } function strexists($string, $find) { return !(!str_contains($string, $find)); } function template($file, $templateid = 0, $tpldir = '', $gettplfile = 0, $primaltpl = '') { global $_G; if(str_starts_with($tpldir, 'source/app/')) { $tplfile = DISCUZ_ROOT.$tpldir.'/'.$file.'.php'; } else { if(!$tpldir) { $tpldir = './template/default'; } $tplfile = DISCUZ_TEMPLATE($tpldir).'/'.$file.'.htm'; if(!tplfile::file_exists($tplfile)) { $tplfile = DISCUZ_TEMPLATE($tpldir).'/'.$file.'.php'; } } $file == 'common/header' && defined('CURMODULE') && CURMODULE && $file = 'common/header_'.$_G['basescript'].'_'.CURMODULE; $cachefile = './template/'.$templateid.'_'.str_replace('/', '_', $file).'.tpl.php'; if($gettplfile) { return $tplfile; } checktplrefresh($tplfile, $tplfile, tplfile::filemtime(DISCUZ_DATA.$cachefile), $templateid, $cachefile, $tpldir, $file); return DISCUZ_DATA.$cachefile; }