Rumah > php教程 > PHP源码 > teks badan

Destoon 核心

PHP中文网
Lepaskan: 2016-05-25 17:09:05
asal
1528 orang telah melayarinya

1. [代码]Destoon 核心    

<?php
/*
	[Destoon B2B System] Copyright (c) 2008-2011 Destoon.COM
	This is NOT a freeware, use is subject to license.txt
*/
defined(&#39;IN_DESTOON&#39;) or exit(&#39;Access Denied&#39;);
function dhtmlspecialchars($string) {
    return is_array($string) ? array_map(&#39;dhtmlspecialchars&#39;, $string) : str_replace(&#39;&amp;&#39;, &#39;&&#39;, htmlspecialchars($string, ENT_QUOTES));
}

function daddslashes($string) {
	if(!is_array($string)) return addslashes($string);
	foreach($string as $key => $val) $string[$key] = daddslashes($val);
	return $string;
}

function dstripslashes($string) {
	if(!is_array($string)) return stripslashes($string);
	foreach($string as $key => $val) $string[$key] = dstripslashes($val);
	return $string;
}

function dsafe($string) {
	if(is_array($string)) {
		return array_map(&#39;dsafe&#39;, $string);
	} else {
		if(strlen($string) < 20) return $string;
		$match = array("/&#([a-z0-9]+)([;]*)/i", "/(j[\s\r\n\t]*a[\s\r\n\t]*v[\s\r\n\t]*a[\s\r\n\t]*s[\s\r\n\t]*c[\s\r\n\t]*r[\s\r\n\t]*i[\s\r\n\t]*p[\s\r\n\t]*t|jscript|js|vbscript|vbs|about|expression|script|frame|link|import)/i", "/on(mouse|exit|error|click|dblclick|key|load|unload|change|move|submit|reset|cut|copy|select|start|stop)/i");
		$replace = array("", "<d>\\1</d>", "on\n\\1");
		return preg_replace($match, $replace, $string);
	}
}

function dtrim($string, $js = false) {
	$string = str_replace(array(chr(10), chr(13)), array(&#39;&#39;, &#39;&#39;), $string);
	return $js ? str_replace("&#39;", "\&#39;", $string) : $string;
}

function dheader($url) {
	global $DT;	
	if(!defined(&#39;DT_ADMIN&#39;) && $DT[&#39;defend_reload&#39;]) sleep($DT[&#39;defend_reload&#39;]);
	exit(header(&#39;location:&#39;.$url));
}

function dmsg($dmsg = &#39;&#39;, $dforward = &#39;&#39;) {
	if(!$dmsg && !$dforward) {
		$dmsg = get_cookie(&#39;dmsg&#39;);
		if($dmsg) {
			echo &#39;<script type="text/javascript">showmsg(\&#39;&#39;.$dmsg.&#39;\&#39;);</script>&#39;;
			set_cookie(&#39;dmsg&#39;, &#39;&#39;);
		}
	} else {
		set_cookie(&#39;dmsg&#39;, $dmsg);
		$dforward = preg_replace("/(.*)([&?]rand=[0-9]*)(.*)/i", "\\1\\3", $dforward);
		$dforward = str_replace(&#39;.php&&#39;, &#39;.php?&#39;, $dforward);
		$dforward = strpos($dforward, &#39;?&#39;) === false ? $dforward.&#39;?rand=&#39;.mt_rand(10, 99) : str_replace(&#39;?&#39;, &#39;?rand=&#39;.mt_rand(10, 99).&#39;&&#39;, $dforward);
		dheader($dforward);
	}
}

function dalert($dmessage = errmsg, $dforward = &#39;&#39;, $extend = &#39;&#39;) {
	global $CFG, $DT;
	exit(include template(&#39;alert&#39;, &#39;message&#39;));
}

function dsubstr($string, $length, $suffix = &#39;&#39;, $start = 0) {
	if($start) {
		$tmp = dsubstr($string, $start);
		$string = substr($string, strlen($tmp));
	}
	$strlen = strlen($string);
	if($strlen <= $length) return $string;
	$string = str_replace(array(&#39;&quot;&#39;, &#39;&lt;&#39;, &#39;&gt;&#39;), array(&#39;"&#39;, &#39;<&#39;, &#39;>&#39;), $string);
	$length = $length - strlen($suffix);
	$str = &#39;&#39;;
	if(strtolower(DT_CHARSET) == &#39;utf-8&#39;) {
		$n = $tn = $noc = 0;
		while($n < $strlen)	{
			$t = ord($string{$n});
			if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
				$tn = 1; $n++; $noc++;
			} elseif(194 <= $t && $t <= 223) {
				$tn = 2; $n += 2; $noc += 2;
			} elseif(224 <= $t && $t <= 239) {
				$tn = 3; $n += 3; $noc += 2;
			} elseif(240 <= $t && $t <= 247) {
				$tn = 4; $n += 4; $noc += 2;
			} elseif(248 <= $t && $t <= 251) {
				$tn = 5; $n += 5; $noc += 2;
			} elseif($t == 252 || $t == 253) {
				$tn = 6; $n += 6; $noc += 2;
			} else {
				$n++;
			}
			if($noc >= $length) break;
		}
		if($noc > $length) $n -= $tn;
		$str = substr($string, 0, $n);
	} else {
		for($i = 0; $i < $length; $i++) {
			$str .= ord($string{$i}) > 127 ? $string{$i}.$string{++$i} : $string{$i};
		}
	}
	$str = str_replace(array(&#39;"&#39;, &#39;<&#39;, &#39;>&#39;), array(&#39;&quot;&#39;, &#39;&lt;&#39;, &#39;&gt;&#39;), $str);
	return $str == $string ? $str : $str.$suffix;
}

function encrypt($txt, $key = &#39;&#39;) {
	$rnd = md5(microtime());
	$len = strlen($txt);
	$ren = strlen($rnd);
	$ctr = 0;
	$str = &#39;&#39;;
	for($i = 0; $i < $len; $i++) {
		$ctr = $ctr == $ren ? 0 : $ctr;
		$str .= $rnd[$ctr].($txt[$i] ^ $rnd[$ctr++]);
	}
	return str_replace(&#39;=&#39;, &#39;&#39;, base64_encode(kecrypt($str, $key)));
}

function decrypt($txt, $key = &#39;&#39;) {
	$txt = kecrypt(base64_decode($txt), $key);
	$len = strlen($txt);
	$str = &#39;&#39;;
	for($i = 0; $i < $len; $i++) {
		$tmp = $txt[$i];
		$str .= $txt[++$i] ^ $tmp;
	}
	return $str;
}

function kecrypt($txt, $key) {
	$key = md5($key);
	$len = strlen($txt);
	$ken = strlen($key);
	$ctr = 0;
	$str = &#39;&#39;;
	for($i = 0; $i < $len; $i++) {
		$ctr = $ctr == $ken ? 0 : $ctr;
		$str .= $txt[$i] ^ $key[$ctr++];
	}
	return $str;
}

function strtohex($str) {
	$hex = &#39;&#39;;
	for($i = 0; $i < strlen($str); $i++) {
		$hex .= dechex(ord($str[$i]));
	}
	return $hex;
}

function hextostr($hex) {
	$str = &#39;&#39;;
	for($i = 0; $i < strlen($hex) - 1; $i += 2) {
		$str .= chr(hexdec($hex[$i].$hex[$i+1]));
	}
	return $str;
}

function dround($var, $precision = 2, $sprinft = false) {
	$var = round(floatval($var), $precision);
	if($sprinft) $var = sprintf(&#39;%.&#39;.$precision.&#39;f&#39;, $var);
	return $var;
}

function dalloc($i, $n = 5000) {
	return ceil($i/$n);
}

function strip_sql($string) {
	$search = array("/union[\s|\t]/i","/select[\s|\t]/i","/update[\s|\t]/i","/outfile[\s|\t]/i","/ascii/i","/[\s|\t]or[\s|\t]/i","/\/\*/i");
	$replace = array(&#39;union &#39;,&#39;select &#39;,&#39;update &#39;,&#39;outfile &#39;,&#39;ascii &#39;,&#39; or &#39;, &#39;&#39;);
	return is_array($string) ? array_map(&#39;strip_sql&#39;, $string) : preg_replace($search, $replace, $string);
}

function strip_nr($string, $js = false) {
	$string =  str_replace(array(chr(13), chr(10), "\n", "\r", "\t", &#39;  &#39;),array(&#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;), $string);
	if($js) $string = str_replace("&#39;", "\&#39;", $string);
	return $string;
}

function template($template = &#39;index&#39;, $dir = &#39;&#39;) {
	global $CFG;
	$to = $dir ? DT_CACHE.&#39;/tpl/&#39;.$dir.&#39;-&#39;.$template.&#39;.php&#39; : DT_CACHE.&#39;/tpl/&#39;.$template.&#39;.php&#39;;
	$isfileto = is_file($to);
	if($CFG[&#39;template_refresh&#39;] || !$isfileto) {
		if($dir) $dir = $dir.&#39;/&#39;;
        $from = DT_ROOT.&#39;/template/&#39;.$CFG[&#39;template&#39;].&#39;/&#39;.$dir.$template.&#39;.htm&#39;;
		if($CFG[&#39;template&#39;] != &#39;default&#39; && !is_file($from)) {
			$from = DT_ROOT.&#39;/template/default/&#39;.$dir.$template.&#39;.htm&#39;;
		}
        if(!$isfileto || filemtime($from) > filemtime($to) || (filesize($to) == 0 && filesize($from) > 0)) {
			require_once DT_ROOT.&#39;/include/template.func.php&#39;;
			template_compile($from, $to);
		}
	}
	return $to;
}

function ob_template($template, $dir = &#39;&#39;) {
	extract($GLOBALS, EXTR_SKIP);
	ob_start();
	include template($template, $dir);
	$contents = ob_get_contents();
	ob_clean();
	return $contents;
}

function message($dmessage = errmsg, $dforward = &#39;goback&#39;, $dtime = 1) {
	global $CFG, $DT;
	if(!$dmessage && $dforward && $dforward != &#39;goback&#39;) dheader($dforward);
	exit(include template(&#39;message&#39;, &#39;message&#39;));
}

function login() {
	global $_userid, $MODULE, $DT_URL, $DT;
	$_userid or dheader($MODULE[2][&#39;linkurl&#39;].$DT[&#39;file_login&#39;].&#39;?forward=&#39;.rawurlencode($DT_URL));
}

function random($length, $chars = &#39;ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz&#39;) {
	$hash = &#39;&#39;;
	$max = strlen($chars) - 1;
	for($i = 0; $i < $length; $i++)	{
		$hash .= $chars[mt_rand(0, $max)];
	}
	return $hash;
}

function set_cookie($var, $value = &#39;&#39;, $time = 0) {
	global $CFG, $DT_TIME;
	$time = $time > 0 ? $time : (empty($value) ? $DT_TIME - 3600 : 0);
	$port = $_SERVER[&#39;SERVER_PORT&#39;] == &#39;443&#39; ? 1 : 0;
	$var = $CFG[&#39;cookie_pre&#39;].$var;
	return setcookie($var, $value, $time, $CFG[&#39;cookie_path&#39;], $CFG[&#39;cookie_domain&#39;], $port);
}

function get_cookie($var) {
	global $CFG;
	$var = $CFG[&#39;cookie_pre&#39;].$var;
	return isset($_COOKIE[$var]) ? $_COOKIE[$var] : &#39;&#39;;
}

function get_table($moduleid, $data = 0) {
	global $DT_PRE, $MODULE;
	$module = $MODULE[$moduleid][&#39;module&#39;];
	if($data) {
		return in_array($module, array(&#39;article&#39;, &#39;info&#39;)) ? $DT_PRE.$module.&#39;_data_&#39;.$moduleid : $DT_PRE.$module.&#39;_data&#39;;
	} else {
		return in_array($module, array(&#39;article&#39;, &#39;info&#39;)) ? $DT_PRE.$module.&#39;_&#39;.$moduleid : $DT_PRE.$module;
	}
}

function get_process($fromtime, $totime) {
	global $DT_TIME;
	if($fromtime && $DT_TIME < $fromtime) return 1;
	if($totime && $DT_TIME > $totime) return 3;
	return 2;
}

function send_message($touser, $title, $content, $typeid = 4, $fromuser = &#39;&#39;) {
	global $db, $DT_TIME, $DT_IP;
	if($touser == $fromuser) return false;
	if(check_name($touser) && $title && $content) {
		$title = addslashes($title);
		$content = addslashes($content);
		$r = $db->get_one("SELECT black FROM {$db->pre}member WHERE username=&#39;$touser&#39;");
		if($r) {
			if($r[&#39;black&#39;] && $typeid != 4) {
				$blacks = explode(&#39; &#39;, $r[&#39;black&#39;]);
				$_from = $fromuser ? $fromuser : &#39;Guest&#39;;
				if(in_array($_from, $blacks)) return false;
			}
			$db->query("INSERT INTO {$db->pre}message (title,typeid,touser,fromuser,content,addtime,ip,status) VALUES (&#39;$title&#39;, $typeid, &#39;$touser&#39;,&#39;$fromuser&#39;,&#39;$content&#39;,&#39;$DT_TIME&#39;,&#39;$DT_IP&#39;,3)");			
			$db->query("UPDATE {$db->pre}member SET message=message+1 WHERE username=&#39;$touser&#39;");
			if($fromuser) {
				$db->query("INSERT INTO {$db->pre}message (title,typeid,content,fromuser,touser,addtime,ip,status) VALUES (&#39;$title&#39;,&#39;$typeid&#39;,&#39;$content&#39;,&#39;$fromuser&#39;,&#39;$touser&#39;,&#39;$DT_TIME&#39;,&#39;$DT_IP&#39;,&#39;2&#39;)");
			}
			return true;
		}
	}
	return false;
}

function send_mail($mail_to, $mail_subject, $mail_body, $mail_from = &#39;&#39;, $mail_sign = true) {
	global $DT;
	require_once DT_ROOT.&#39;/include/mail.func.php&#39;;
	$result = dmail(trim($mail_to), $mail_subject, $mail_body, $mail_from, $mail_sign);
	$success = $result == &#39;SUCCESS&#39; ? 1 : 0;
	if($DT[&#39;mail_log&#39;]) {
		global $DT_TIME, $db;
		$status = $success ? 3 : 2;
		$note = $success ? &#39;&#39; : addslashes($result);
		$mail_subject = stripslashes($mail_subject);
		$mail_body = stripslashes($mail_body);
		$mail_subject = addslashes($mail_subject);
		$mail_body = addslashes($mail_body);
		$db->query("INSERT INTO {$db->pre}mail_log (email,title,content,addtime,status,note) VALUES (&#39;$mail_to&#39;,&#39;$mail_subject&#39;,&#39;$mail_body&#39;,&#39;$DT_TIME&#39;,&#39;$status&#39;,&#39;$note&#39;)");
	}
	return $success;
}

function strip_sms($message) {
	global $DT;
	$message = strip_tags($message);
	$message = preg_replace("/&([a-z]{1,});/", &#39;&#39;, $message);
	$message = str_replace(&#39; &#39;, &#39;&#39;, $message);
	if($DT[&#39;sms_sign&#39;]) $message .= $DT[&#39;sms_sign&#39;];
	return $message;
}

function send_sms($mobile, $message, $word = 0, $time = 0) {
	global $db, $DT, $DT_TIME, $DT_IP, $_username;
	if(!$DT[&#39;sms&#39;] || !$DT[&#39;sms_uid&#39;] || !$DT[&#39;sms_key&#39;]) return false;
	$word or $word = word_count($message);
	$sms_message = rawurlencode(convert($message, DT_CHARSET, &#39;UTF-8&#39;));
	$data = &#39;sms_uid=&#39;.$DT[&#39;sms_uid&#39;].&#39;&sms_key=&#39;.$DT[&#39;sms_key&#39;].&#39;&sms_charset=&#39;.DT_CHARSET.&#39;&sms_mobile=&#39;.$mobile.&#39;&sms_message=&#39;.$sms_message.&#39;&sms_time=&#39;.$time;
	$header = "POST /send.php HTTP/1.0\r\n";
	$header .= "Accept: */*\r\n";
	$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
	$header .= "Content-Length: ".strlen($data)."\r\n\r\n";
	$DT[&#39;sms_host&#39;] or $DT[&#39;sms_host&#39;] = &#39;sms&#39;;
	$fp = fsockopen($DT[&#39;sms_host&#39;].&#39;.destoon.com&#39;, 8820);
	$code = &#39;&#39;;
	if($fp) {
		fputs($fp, $header.$data);
		while(!feof($fp)) {
			$code .= fgets($fp, 1024);
		}
		fclose($fp);
		if($code && strpos($code, &#39;destoon_sms_code=&#39;) !== false) {
			$code = explode(&#39;destoon_sms_code=&#39;, $code);
			$code = $code[1];
		} else {
			$code = &#39;Can Not Connect SMS Server&#39;;
		}
	} else {
		$code = &#39;Can Not Connect SMS Server&#39;;
	}
	$db->query("INSERT INTO {$db->pre}sms (mobile,message,word,editor,sendtime,code) VALUES (&#39;$mobile&#39;,&#39;$message&#39;,&#39;$word&#39;,&#39;$_username&#39;,&#39;$DT_TIME&#39;,&#39;$code&#39;)");
	return $code;
}

function word_count($string) {
	$string = convert($string, DT_CHARSET, &#39;gbk&#39;);
	$length = strlen($string);
	$count = 0;
	for($i = 0; $i < $length; $i++) {
		$t = ord($string[$i]);
		if($t > 127) $i++;
		$count++;
	}
	return $count;
}

function cache_read($file, $dir = &#39;&#39;, $mode = &#39;&#39;) {
	$file = $dir ? DT_CACHE.&#39;/&#39;.$dir.&#39;/&#39;.$file : DT_CACHE.&#39;/&#39;.$file;
	if(!is_file($file)) return array();
	return $mode ? file_get($file) : include $file;
}

function cache_write($file, $string, $dir = &#39;&#39;) {
	if(is_array($string)) $string = "<?php defined(&#39;IN_DESTOON&#39;) or exit(&#39;Access Denied&#39;); return ".strip_nr(var_export($string, true))."; ?>";
	$file = $dir ? DT_CACHE.&#39;/&#39;.$dir.&#39;/&#39;.$file : DT_CACHE.&#39;/&#39;.$file;
	$strlen = file_put($file, $string);
	return $strlen;
}

function cache_delete($file, $dir = &#39;&#39;) {
	$file = $dir ? DT_CACHE.&#39;/&#39;.$dir.&#39;/&#39;.$file : DT_CACHE.&#39;/&#39;.$file;
	return file_del($file);
}

function cache_clear($str, $type = &#39;&#39;, $dir = &#39;&#39;) {
	$dir = $dir ? DT_CACHE.&#39;/&#39;.$dir.&#39;/&#39; : DT_CACHE.&#39;/&#39;;
	$files = glob($dir.&#39;*&#39;);
	if(is_array($files)) {
		if($type == &#39;dir&#39;) {
			foreach($files as $file) {
				if(is_dir($file)) {dir_delete($file);} else {if(file_ext($file) == $str) file_del($file);}
			}
		} else {
			foreach($files as $file) {
				if(!is_dir($file) && strpos(basename($file), $str) !== false) file_del($file);
			}
		}
	}
}

function content_table($moduleid, $itemid, $split, $table_data = &#39;&#39;) {
	if($split) {
		return split_table($moduleid, $itemid);
	} else {
		$table_data or $table_data = get_table($moduleid, 1);
		return $table_data;
	}
}

function split_table($moduleid, $itemid) {
	global $DT_PRE;
	$part = split_id($itemid);
	return $DT_PRE.$moduleid.&#39;_&#39;.$part;
}

function split_id($id) {
	return $id > 0 ? ceil($id/500000) : 1;
}

function ip2area($ip) {
	$area = &#39;&#39;;
	if(is_ip($ip)) {
		$tmp = explode(&#39;.&#39;, $ip);
		if($tmp[0] == 10 || $tmp[0] == 127 || ($tmp[0] == 192 && $tmp[1] == 168) || ($tmp[0] == 172 && ($tmp[1] >= 16 && $tmp[1] <= 31))) {
			$area = &#39;LAN&#39;;
		} elseif($tmp[0] > 255 || $tmp[1] > 255 || $tmp[2] > 255 || $tmp[3] > 255) {
			$area = &#39;Unkonw&#39;;
		} else {
			require_once DT_ROOT.&#39;/include/ip.func.php&#39;;
			$area = convertip($ip);
		}
	}
	$area = convert($area, &#39;gbk&#39;, DT_CHARSET);
	return $area;
}

function banip($IP) {
	global $DT_IP, $DT_TIME;
	$ban = false;
	foreach($IP as $v) {
		if($v[&#39;totime&#39;] && $v[&#39;totime&#39;] < $DT_TIME) continue;
		if($v[&#39;ip&#39;] == $DT_IP) { $ban = true; break; }
		if(preg_match("/^".str_replace(&#39;*&#39;, &#39;[0-9]{1,3}&#39;, $v[&#39;ip&#39;])."$/", $DT_IP)) { $ban = true; break; }
	}
	if($ban) message(lang(&#39;include->msg_ip_ban&#39;, array($DT_IP)));
}

function banword($WORD, $string, $extend = true) {
	$string = stripslashes($string);
	foreach($WORD as $v) {
		$v[0] = preg_quote($v[0]);
		$v[0] = str_replace(&#39;/&#39;, &#39;\/&#39;, $v[0]);
		$v[0] = str_replace("\*", ".*", $v[0]);
		if($v[2] && $extend) {
			if(preg_match("/".$v[0]."/i", $string)) dalert(lang(&#39;include->msg_word_ban&#39;));
		} else {
			if($string == &#39;&#39;) break;
			if(preg_match("/".$v[0]."/i", $string)) $string = preg_replace("/".$v[0]."/i", $v[1], $string);
		}
	}
	return addslashes($string);
}

function get_env($type) {
	switch($type) {
		case &#39;ip&#39;:
			isset($_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;]) or $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;] = &#39;&#39;;
			isset($_SERVER[&#39;REMOTE_ADDR&#39;]) or $_SERVER[&#39;REMOTE_ADDR&#39;] = &#39;&#39;;
			isset($_SERVER[&#39;HTTP_CLIENT_IP&#39;]) or $_SERVER[&#39;HTTP_CLIENT_IP&#39;] = &#39;&#39;;
			if($_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;] && $_SERVER[&#39;REMOTE_ADDR&#39;]) {
				$ip = $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;];
				if(strpos($ip, &#39;,&#39;) !== false) {
					$tmp = explode(&#39;,&#39;, $ip);
					$ip = trim(end($tmp));
				}
				if(is_ip($ip)) return $ip;
			}
			if(is_ip($_SERVER[&#39;HTTP_CLIENT_IP&#39;])) return $_SERVER[&#39;HTTP_CLIENT_IP&#39;];
			if(is_ip($_SERVER[&#39;REMOTE_ADDR&#39;])) return $_SERVER[&#39;REMOTE_ADDR&#39;];
			return &#39;unknown&#39;;
		break;
		case &#39;self&#39;:
			return isset($_SERVER[&#39;PHP_SELF&#39;]) ? $_SERVER[&#39;PHP_SELF&#39;] : (isset($_SERVER[&#39;SCRIPT_NAME&#39;]) ? $_SERVER[&#39;SCRIPT_NAME&#39;] : $_SERVER[&#39;ORIG_PATH_INFO&#39;]);
		break;
		case &#39;referer&#39;:
			return isset($_SERVER[&#39;HTTP_REFERER&#39;]) ? $_SERVER[&#39;HTTP_REFERER&#39;] : &#39;&#39;;
		break;
		case &#39;domain&#39;:
			return $_SERVER[&#39;SERVER_NAME&#39;];
		break;
		case &#39;scheme&#39;:
			return $_SERVER[&#39;SERVER_PORT&#39;] == &#39;443&#39; ? &#39;https://&#39; : &#39;http://&#39;;
		break;
		case &#39;port&#39;:
			return $_SERVER[&#39;SERVER_PORT&#39;] == &#39;80&#39; ? &#39;&#39; : &#39;:&#39;.$_SERVER[&#39;SERVER_PORT&#39;];
		break;
		case &#39;url&#39;:
			if(isset($_SERVER[&#39;REQUEST_URI&#39;])) {
				$uri = $_SERVER[&#39;REQUEST_URI&#39;];
			} else {
				$uri = $_SERVER[&#39;PHP_SELF&#39;];
				if(isset($_SERVER[&#39;argv&#39;])) {
					if(isset($_SERVER[&#39;argv&#39;][0])) $uri .= &#39;?&#39;.$_SERVER[&#39;argv&#39;][0];
				} else {
					$uri .= &#39;?&#39;.$_SERVER[&#39;QUERY_STRING&#39;];
				}
			}
			$uri = dhtmlspecialchars($uri);
			return get_env(&#39;scheme&#39;).$_SERVER[&#39;HTTP_HOST&#39;].(strpos($_SERVER[&#39;HTTP_HOST&#39;], &#39;:&#39;) === false ? get_env(&#39;port&#39;) : &#39;&#39;).$uri;
		break;
	}
}

function convert($str, $from = &#39;utf-8&#39;, $to = &#39;gb2312&#39;) {
	if(!$str) return &#39;&#39;;
	$from = strtolower($from);
	$to = strtolower($to);
	if($from == $to) return $str;
	$from = str_replace(&#39;gbk&#39;, &#39;gb2312&#39;, $from);
	$to = str_replace(&#39;gbk&#39;, &#39;gb2312&#39;, $to);
	$from = str_replace(&#39;utf8&#39;, &#39;utf-8&#39;, $from);
	$to = str_replace(&#39;utf8&#39;, &#39;utf-8&#39;, $to);
	if($from == $to) return $str;
	$tmp = array();
	if(function_exists(&#39;iconv&#39;)) {
		if(is_array($str)) {
			foreach($str as $key => $val) {
				$tmp[$key] = iconv($from, $to."//IGNORE", $val);
			}
			return $tmp;
		} else {
			return iconv($from, $to."//IGNORE", $str);
		}
	} else if(function_exists(&#39;mb_convert_encoding&#39;)) {
		if(is_array($str)) {
			foreach($str as $key => $val) {
				$tmp[$key] = mb_convert_encoding($val, $to, $from);
			}
			return $tmp;
		} else {
			return mb_convert_encoding($str, $to, $from);
		}	
	} else {
		require_once DT_ROOT.&#39;/include/convert.func.php&#39;;
		return dconvert($str, $to, $from);
	}
}

function get_type($item, $cache = 0) {
	$types = array();
	if($cache) {
		$types = cache_read(&#39;type-&#39;.$item.&#39;.php&#39;);
	} else {
		global $db;
		$result = $db->query("SELECT * FROM {$db->pre}type WHERE item=&#39;$item&#39; ORDER BY listorder ASC,typeid DESC ");
		while($r = $db->fetch_array($result)) {
			$types[$r[&#39;typeid&#39;]] = $r;
		}
	}
	return $types;
}

function get_cat($catid) {
	global $db;
	$catid = intval($catid);
	return $catid ? $db->get_one("SELECT * FROM {$db->pre}category WHERE catid=$catid") : array();
}

function cat_pos($CAT, $str = &#39; &raquo; &#39;, $target = &#39;&#39;) {
	global $MODULE, $db;
	if(!$CAT) return &#39;&#39;;
	$arrparentids = $CAT[&#39;arrparentid&#39;].&#39;,&#39;.$CAT[&#39;catid&#39;];
	$arrparentid = explode(&#39;,&#39;, $arrparentids);
	$pos = &#39;&#39;;
	$target = $target ? &#39; target="_blank"&#39; : &#39;&#39;;	
	$CATEGORY = array();
	$result = $db->query("SELECT catid,moduleid,catname,linkurl FROM {$db->pre}category WHERE catid IN ($arrparentids)");
	while($r = $db->fetch_array($result)) {
		$CATEGORY[$r[&#39;catid&#39;]] = $r;
	}
	foreach($arrparentid as $catid) {
		if(!$catid || !isset($CATEGORY[$catid])) continue;
		$pos .= &#39;<a href="&#39;.$MODULE[$CATEGORY[$catid][&#39;moduleid&#39;]][&#39;linkurl&#39;].$CATEGORY[$catid][&#39;linkurl&#39;].&#39;"&#39;.$target.&#39;>&#39;.$CATEGORY[$catid][&#39;catname&#39;].&#39;</a>&#39;.$str;
	}
	$_len = strlen($str);
	if($str && substr($pos, -$_len, $_len) === $str) $pos = substr($pos, 0, strlen($pos)-$_len);
	return $pos;
}

function cat_url($catid) {
	global $MODULE, $db;
	$r = $db->get_one("SELECT moduleid,linkurl FROM {$db->pre}category WHERE catid=$catid");
	return $r ? $MODULE[$r[&#39;moduleid&#39;]][&#39;linkurl&#39;].$r[&#39;linkurl&#39;] : &#39;&#39;;
}

function get_area($areaid) {
	global $db;
	$areaid = intval($areaid);
	return $db->get_one("SELECT * FROM {$db->pre}area WHERE areaid=$areaid");
}

function area_pos($areaid, $str = &#39; &raquo; &#39;, $deep = 0) {
	if($areaid) {
		global $AREA;
	} else {
		global $L;
		return $L[&#39;allcity&#39;];
	}
	$AREA or $AREA = cache_read(&#39;area.php&#39;);
	$arrparentid = $AREA[$areaid][&#39;arrparentid&#39;] ? explode(&#39;,&#39;, $AREA[$areaid][&#39;arrparentid&#39;]) : array();
	$arrparentid[] = $areaid;
	$pos = &#39;&#39;;
	if($deep) $i = 1;
	foreach($arrparentid as $areaid) {
		if(!$areaid || !isset($AREA[$areaid])) continue;
		if($deep) {
			if($i > $deep) continue;
			$i++;
		}
		$pos .= $AREA[$areaid][&#39;areaname&#39;].$str;
	}
	$_len = strlen($str);
	if($str && substr($pos, -$_len, $_len) === $str) $pos = substr($pos, 0, strlen($pos)-$_len);
	return $pos;
}

function get_maincat($catid, $moduleid, $level = -1) {
	global $db;
	$condition = $catid ? "parentid=$catid" : "moduleid=$moduleid AND parentid=0";
	if($level >= 0) $condition .= " AND level=$level";
	$cat = array();
	$result = $db->query("SELECT catid,catname,child,style,linkurl,item FROM {$db->pre}category WHERE $condition ORDER BY listorder,catid ASC", &#39;CACHE&#39;);
	while($r = $db->fetch_array($result)) {
		$cat[] = $r;
	}
	return $cat;
}

function get_mainarea($areaid) {
	global $db;
	$areaid = intval($areaid);
	$are = array();
	$result = $db->query("SELECT areaid,areaname FROM {$db->pre}area WHERE parentid=$areaid ORDER BY listorder,areaid ASC", &#39;CACHE&#39;);
	while($r = $db->fetch_array($result)) {
		$are[] = $r;
	}
	return $are;
}

function get_user($value, $key = &#39;username&#39;, $from = &#39;userid&#39;) {
	global $db;
	$r = $db->get_one("SELECT `$from` FROM {$db->pre}member WHERE `$key`=&#39;$value&#39;");
	return $r[$from];
}

function check_group($groupid, $groupids) {
	if(!$groupids || $groupid == 1) return true;
	if($groupid == 4) $groupid = 3;
	return in_array($groupid, explode(&#39;,&#39;, $groupids));
}

function tohtml($htmlfile, $module = &#39;&#39;, $parameter = &#39;&#39;) {
	defined(&#39;TOHTML&#39;) or define(&#39;TOHTML&#39;, true);
    extract($GLOBALS, EXTR_SKIP);
	if($parameter) parse_str($parameter);
    include $module ? DT_ROOT.&#39;/module/&#39;.$module.&#39;/&#39;.$htmlfile.&#39;.htm.php&#39; : DT_ROOT.&#39;/include/&#39;.$htmlfile.&#39;.htm.php&#39;;
}

function set_style($string, $style = &#39;&#39;, $tag = &#39;span&#39;) {
	if(preg_match("/^#[0-9a-zA-Z]{6}$/", $style)) $style = &#39;color:&#39;.$style;
	return $style ? &#39;<&#39;.$tag.&#39; style="&#39;.$style.&#39;">&#39;.$string.&#39;</&#39;.$tag.&#39;>&#39; : $string;
}

function crypt_action($action) {
	global $DT_IP;
	return md5(md5($action.DT_KEY.$DT_IP));
}

function captcha($captcha, $enable = 1, $return = false) {
	global $DT_IP, $DT, $session;
	if($enable) {
		if($DT[&#39;captcha_cn&#39;]) {
			if(strlen($captcha) < 4) {
				$msg = lang(&#39;include->captcha_missed&#39;);
				return $return ? $msg : message($msg);
			}
		} else {
			if(!preg_match("/^[0-9a-z]{4,}$/i", $captcha)) {
				$msg = lang(&#39;include->captcha_missed&#39;);
				return $return ? $msg : message($msg);
			}
		}
		if(!is_object($session)) $session = new dsession();
		if(!isset($_SESSION[&#39;captchastr&#39;])) {
			$msg = lang(&#39;include->captcha_expired&#39;);
			return $return ? $msg : message($msg);
		}
		if($_SESSION[&#39;captchastr&#39;] != md5(md5(strtoupper($captcha).DT_KEY.$DT_IP))) {
			$msg = lang(&#39;include->captcha_error&#39;);
			return $return ? $msg : message($msg);
		}
		unset($_SESSION[&#39;captchastr&#39;]);
	} else {
		return &#39;&#39;;
	}
}

function question($answer, $enable = 1, $return = false) {
	global $DT_IP, $session;
	if($enable) {
		if(!$answer) {
			$msg = lang(&#39;include->answer_missed&#39;);
			return $return ? $msg : message($msg);
		}
		$answer = stripslashes($answer);
		if(!is_object($session)) $session = new dsession();
		if(!isset($_SESSION[&#39;answerstr&#39;])) {
			$msg = lang(&#39;include->question_expired&#39;);
			return $return ? $msg : message($msg);
		}
		if($_SESSION[&#39;answerstr&#39;] != md5(md5($answer.DT_KEY.$DT_IP))) {
			$msg = lang(&#39;include->answer_error&#39;);
			return $return ? $msg : message($msg);
		}
		unset($_SESSION[&#39;answerstr&#39;]);
	} else {
		return &#39;&#39;;
	}
}

function pages($total, $page = 1, $perpage = 20, $demo = &#39;&#39;, $step = 2) {
	global $DT_URL, $DT, $L;
	if($total <= $perpage) return &#39;&#39;;
	$items = $total;
	$total = ceil($total/$perpage);
	if($page < 1 || $page > $total) $page = 1;
	if($demo) {
		$demo_url = $demo;
		$home_url = str_replace(&#39;{destoon_page}&#39;, &#39;1&#39;, $demo_url);
	} else {
		if(defined(&#39;DT_REWRITE&#39;) && $DT[&#39;rewrite&#39;] && $_SERVER["SCRIPT_NAME"]) {
			$demo_url = $_SERVER["SCRIPT_NAME"];
			$demo_url = str_replace(&#39;//&#39;, &#39;/&#39;, $demo_url);//Fix Nginx
			$mark = false;
			if(substr($demo_url, -4) == &#39;.php&#39;) {
				if(strpos($_SERVER[&#39;QUERY_STRING&#39;], &#39;.html&#39;) === false) {
					$qstr = &#39;&#39;;
					if($_SERVER[&#39;QUERY_STRING&#39;]) {					
						if(substr($_SERVER[&#39;QUERY_STRING&#39;], -5) == &#39;.html&#39;) {
							$qstr = &#39;-&#39;.substr($_SERVER[&#39;QUERY_STRING&#39;], 0, -5);
						} else {
							parse_str($_SERVER[&#39;QUERY_STRING&#39;], $qs);
							foreach($qs as $k=>$v) {
								$qstr .= &#39;-&#39;.$k.&#39;-&#39;.rawurlencode($v);
							}
						}
					}
					$demo_url = substr($demo_url, 0, -4).&#39;-htm-page-{destoon_page}&#39;.$qstr.&#39;.html&#39;;
				} else {
					$demo_url = substr($demo_url, 0, -4).&#39;-htm-&#39;.$_SERVER[&#39;QUERY_STRING&#39;];
					$mark = true;
				}
			} else {
				$mark = true;
			}
			if($mark) {
				if(strpos($demo_url, &#39;%&#39;) === false) $demo_url =  rawurlencode($demo_url);
				$demo_url = str_replace(array(&#39;%2F&#39;, &#39;%3A&#39;), array(&#39;/&#39;, &#39;:&#39;), $demo_url);
				if(strpos($demo_url, &#39;-page-&#39;) !== false) {
					$demo_url = preg_replace("/page-([0-9]+)/", &#39;page-{destoon_page}&#39;, $demo_url);
				} else {
					$demo_url = str_replace(&#39;.html&#39;, &#39;-page-{destoon_page}.html&#39;, $demo_url);
				}
			}
			$home_url = str_replace(&#39;-page-{destoon_page}&#39;, &#39;-page-1&#39;, $demo_url);
		} else {
			$DT_URL = str_replace(&#39;&amp;&#39;, &#39;&&#39;, $DT_URL);
			$demo_url = $home_url = preg_replace("/(.*)([&?]page=[0-9]*)(.*)/i", "\\1\\3", $DT_URL);
			$s = strpos($demo_url, &#39;?&#39;) === false ? &#39;?&#39; : &#39;&&#39;;
			$demo_url = $demo_url.$s.&#39;page={des&#39;.&#39;toon_page}&#39;;
		}
	}
	$pages = &#39;&#39;;
	include DT_ROOT.&#39;/api/pages.&#39;.($DT[&#39;pages_mode&#39;] ? &#39;sample&#39; : &#39;default&#39;).&#39;.php&#39;;
	return $pages;
}

function listpages($CAT, $total, $page = 1, $perpage = 20, $step = 2) {
	global $DT, $MOD, $L;
	if($total <= $perpage) return &#39;&#39;;
	$items = $total;
	$total = ceil($total/$perpage);
	if($page < 1 || $page > $total) $page = 1;
	$home_url = $MOD[&#39;linkurl&#39;].$CAT[&#39;linkurl&#39;];
	$demo_url = $MOD[&#39;linkurl&#39;].listurl($CAT, &#39;{destoon_page}&#39;);
	$pages = &#39;&#39;;
	include DT_ROOT.&#39;/api/pages.&#39;.($DT[&#39;pages_mode&#39;] ? &#39;sample&#39; : &#39;default&#39;).&#39;.php&#39;;
	return $pages;
}

function showpages($item, $total, $page = 1) {
	global $MOD, $L;
	$pages = &#39;&#39;;
	$home_url = $MOD[&#39;linkurl&#39;].itemurl($item);
	$demo_url = $MOD[&#39;linkurl&#39;].itemurl($item, &#39;{destoon_page}&#39;);
	$_page = $page <= 1 ? $total : ($page - 1);
	$url = $_page == 1 ? $home_url : str_replace(&#39;{destoon_page}&#39;, $_page, $demo_url);
	$pages .= &#39;<input type="hidden" id="des&#39;.&#39;toon_previous" value="&#39;.$url.&#39;"/><a href="&#39;.$url.&#39;" title="&#39;.$L[&#39;prev_page&#39;].&#39;"> &#171; </a> &#39;;
	for($_page = 1; $_page <= $total; $_page++) {
		$url = $_page == 1 ? $home_url : str_replace(&#39;{destoon_page}&#39;, $_page, $demo_url);
		$pages .= $page == $_page ? &#39;<strong> &#39;.$_page.&#39; </strong> &#39; : &#39; <a href="&#39;.$url.&#39;"> &#39;.$_page.&#39; </a>  &#39;;
	}
	$_page = $page >= $total ? 1 : $page + 1;
	$url = $_page == 1 ? $home_url : str_replace(&#39;{destoon_page}&#39;, $_page, $demo_url);
	$pages .= &#39;<a href="&#39;.$url.&#39;" title="&#39;.$L[&#39;next_page&#39;].&#39;"> &#187; </a> <input type="hidden" id="des&#39;.&#39;toon_next" value="&#39;.$url.&#39;"/>&#39;;
	return $pages;
}

function linkurl($linkurl, $absurl = 1) {
	global $CFG;
	if($absurl) {
		if(strpos($linkurl, &#39;://&#39;) !== false) return $linkurl;
		return strpos($linkurl, $CFG[&#39;path&#39;]) === 0 ? $CFG[&#39;url&#39;].substr($linkurl, strlen($CFG[&#39;path&#39;])) : $CFG[&#39;url&#39;].$linkurl;
	} else {
		if(strpos($linkurl, &#39;://&#39;) !== false) return strpos($linkurl, $CFG[&#39;url&#39;]) === 0 ? $CFG[&#39;path&#39;].substr($linkurl, strlen($CFG[&#39;url&#39;])) : $linkurl;
		return strpos($linkurl, $CFG[&#39;path&#39;]) === 0 ? $linkurl : $CFG[&#39;path&#39;].$linkurl;
	}
}

function imgurl($imgurl = &#39;&#39;, $absurl = 1) {
	return $imgurl ? $imgurl : DT_SKIN.&#39;image/nopic.gif&#39;;
}

function userurl($username, $qstring = &#39;&#39;, $domain = &#39;&#39;) {
	global $CFG, $DT, $MODULE;
	$URL = &#39;&#39;;
	$subdomain = 0;
	if($CFG[&#39;com_domain&#39;]) $subdomain = substr($CFG[&#39;com_domain&#39;], 0, 1) == &#39;.&#39; ? 1 : 2;
	if($username) {
		if($subdomain || $domain) {
			$URL = $domain ? &#39;http://&#39;.$domain.&#39;/&#39; : ($subdomain == 1 ? &#39;http://&#39;.($DT[&#39;com_www&#39;] ? &#39;www.&#39; : &#39;&#39;).$username.$CFG[&#39;com_domain&#39;].&#39;/&#39; : &#39;http://&#39;.$CFG[&#39;com_domain&#39;].&#39;/&#39;.$username.&#39;/&#39;);
			if($qstring) {
				parse_str($qstring, $q);
				if(isset($q[&#39;file&#39;])) {
					$URL .= $CFG[&#39;com_dir&#39;] ? $q[&#39;file&#39;].&#39;/&#39; : &#39;company/&#39;.$q[&#39;file&#39;].&#39;/&#39;;
					unset($q[&#39;file&#39;]);
				}
				if($q) {
					if($DT[&#39;rewrite&#39;]) {
						foreach($q as $k=>$v) {
							$v = rawurlencode($v);
							$URL .= $k.&#39;-&#39;.$v.&#39;-&#39;;
						}
						$URL = substr($URL, 0, -1).&#39;.shtml&#39;;
					} else {
						$URL .= &#39;index.php?&#39;;
						$i = 0;
						foreach($q as $k=>$v) {
							$v = rawurlencode($v);
							$URL .= ($i++ == 0 ? &#39;&#39; : &#39;&&#39;).$k.&#39;=&#39;.$v;
						}
					}
				}
			}
		} else if($DT[&#39;rewrite&#39;]) {
			$URL = DT_PATH.&#39;com/&#39;.$username.&#39;/&#39;;
			if($qstring) {
				parse_str($qstring, $q);
				if(isset($q[&#39;file&#39;])) {
					$URL .= $CFG[&#39;com_dir&#39;] ? $q[&#39;file&#39;].&#39;/&#39; : &#39;company/&#39;.$q[&#39;file&#39;].&#39;/&#39;;
					unset($q[&#39;file&#39;]);
				}
				if($q) {
					foreach($q as $k=>$v) {
						$v = rawurlencode($v);
						$URL .= $k.&#39;-&#39;.$v.&#39;-&#39;;
					}
					$URL = substr($URL, 0, -1).&#39;.html&#39;;
				}
			}
		} else {
			$URL = DT_PATH.&#39;index.php?homepage=&#39;.$username;
			if($qstring) $URL = $URL.&#39;&&#39;.$qstring;
		}
	} else {
		$URL = linkurl($MODULE[4][&#39;linkurl&#39;], 1).&#39;guest.php&#39;;
	}
	return $URL;
}

function userinfo($username, $cache = &#39;&#39;, $fields = &#39;*&#39;) {
	global $db;
	return $db->get_one("SELECT $fields FROM {$db->pre}member m, {$db->pre}company c WHERE m.userid=c.userid AND m.username=&#39;$username&#39;", $cache);
}

function memberinfo($username, $cache = &#39;&#39;, $fields = &#39;*&#39;) {
	global $db;
	return $db->get_one("SELECT $fields FROM {$db->pre}member WHERE username=&#39;$username&#39;", $cache);
}

function listurl($CAT, $page = 0) {
	global $DT, $MOD, $L;
	include DT_ROOT.&#39;/api/url.inc.php&#39;;
	$catid = $CAT[&#39;catid&#39;];
	$file_ext = $DT[&#39;file_ext&#39;];
	$index = $DT[&#39;index&#39;];
	$catdir = $CAT[&#39;catdir&#39;];
	$catname = file_vname($CAT[&#39;catname&#39;]);
	$prefix = $MOD[&#39;htm_list_prefix&#39;];
	$urlid = $MOD[&#39;list_html&#39;] ? $MOD[&#39;htm_list_urlid&#39;] : $MOD[&#39;php_list_urlid&#39;];
	$ext = $MOD[&#39;list_html&#39;] ? &#39;htm&#39; : &#39;php&#39;;
	isset($urls[$ext][&#39;list&#39;][$urlid]) or $urlid = 0;
	$url = $urls[$ext][&#39;list&#39;][$urlid];
	$url = $page ? $url[&#39;page&#39;] : $url[&#39;index&#39;];
    eval("\$listurl = \"$url\";");
	if(substr($listurl, 0, 1) == &#39;/&#39;) $listurl = substr($listurl, 1);
	return $listurl;
}

function itemurl($item, $page = 0) {
	global $DT, $MOD, $L;
	if($MOD[&#39;show_html&#39;] && $item[&#39;filepath&#39;]) {
		if($page === 0) return $item[&#39;filepath&#39;];
		$ext = file_ext($item[&#39;filepath&#39;]);
		return str_replace(&#39;.&#39;.$ext, &#39;_&#39;.$page.&#39;.&#39;.$ext, $item[&#39;filepath&#39;]);
	}
	include DT_ROOT.&#39;/api/url.inc.php&#39;;
	$file_ext = $DT[&#39;file_ext&#39;];
	$index = $DT[&#39;index&#39;];
	$itemid = $item[&#39;itemid&#39;];
	$title = file_vname($item[&#39;title&#39;]);
	$addtime = $item[&#39;addtime&#39;];
	$catid = $item[&#39;catid&#39;];
	$year = date(&#39;Y&#39;, $addtime);
	$month = date(&#39;m&#39;, $addtime);
	$day = date(&#39;d&#39;, $addtime);
	$prefix = $MOD[&#39;htm_item_prefix&#39;];
	$urlid = $MOD[&#39;show_html&#39;] ? $MOD[&#39;htm_item_urlid&#39;] : $MOD[&#39;php_item_urlid&#39;];
	$ext = $MOD[&#39;show_html&#39;] ? &#39;htm&#39; : &#39;php&#39;;
	$alloc = dalloc($itemid);
	$url = $urls[$ext][&#39;item&#39;][$urlid];
	$url = $page ? $url[&#39;page&#39;] : $url[&#39;index&#39;];
	if(strpos($url, &#39;cat&#39;) !== false && $catid) {
		$cate = get_cat($catid);
		$catdir = $cate[&#39;catdir&#39;];
		$catname = $cate[&#39;catname&#39;];
	}
    eval("\$itemurl = \"$url\";");
	if(substr($itemurl, 0, 1) == &#39;/&#39;) $itemurl = substr($itemurl, 1);
	return $itemurl;
}

function rewrite($url, $encode = 0) {
	global $DT, $CFG;
	if(!$DT[&#39;rewrite&#39;]) return $url;
	if(strpos($url, &#39;.php?&#39;) === false || strpos($url, &#39;=&#39;) === false) return $url;
	$url = str_replace(array(&#39;+&#39;, &#39;-&#39;), array(&#39;%20&#39;, &#39;%20&#39;), $url);
	$url = str_replace(array(&#39;.php?&#39;, &#39;&&#39;, &#39;=&#39;), array(&#39;-htm-&#39;, &#39;-&#39;, &#39;-&#39;), $url).&#39;.html&#39;;
	return $url;
}

function timetodate($time = 0, $type = 6) {
	if(!$time) {global $DT_TIME; $time = $DT_TIME;}
	$types = array(&#39;Y-m-d&#39;, &#39;Y&#39;, &#39;m-d&#39;, &#39;Y-m-d&#39;, &#39;m-d H:i&#39;, &#39;Y-m-d H:i&#39;, &#39;Y-m-d H:i:s&#39;);
	if(isset($types[$type])) $type = $types[$type];
	return date($type, $time);
}

function log_write($message, $type = &#39;php&#39;) {
	global $DT_IP, $DT_TIME, $_username;
	if(!DT_DEBUG) return;
	$DT_IP or $DT_IP = get_env(&#39;ip&#39;);
	$DT_TIME or $DT_TIME = time();
	$user = $_username ? $_username : &#39;guest&#39;;
	$log = "<$type>\n";
	$log .= "\t<time>".date(&#39;Y-m-d H:i:s&#39;, $DT_TIME)."</time>\n";
	$log .= "\t<ip>".$DT_IP."</ip>\n";
	$log .= "\t<user>".$user."</user>\n";
	$log .= "\t<file>".$_SERVER[&#39;SCRIPT_NAME&#39;]."</file>\n";
	$log .= "\t<querystring>".str_replace(&#39;&&#39;, &#39;&amp;&#39;, $_SERVER[&#39;QUERY_STRING&#39;])."</querystring>\n";
	$log .= "\t<message>".$message."\t</message>\n";
	$log .= "</$type>";
	file_put(DT_ROOT.&#39;/file/log/&#39;.date(&#39;Ym&#39;, $DT_TIME).&#39;/&#39;.$type.&#39;-&#39;.date(&#39;Y.m.d H.i.s&#39;, $DT_TIME).&#39;-&#39;.strtolower(random(10)).&#39;.xml&#39;, $log);
}

function load($file) {
	$ext = file_ext($file);
	if($ext == &#39;css&#39;) {
		echo &#39;<link rel="stylesheet" type="text/css" href="&#39;.DT_SKIN.$file.&#39;" />&#39;;
	} else if($ext == &#39;js&#39;) {
		echo &#39;<script type="text/javascript" src="&#39;.DT_PATH.&#39;file/script/&#39;.$file.&#39;"></script>&#39;;
	} else if($ext == &#39;htm&#39;) {
		$file = str_replace(&#39;ad_m&#39;, &#39;ad_t6_m&#39;, $file);
		if(is_file(DT_CACHE.&#39;/htm/&#39;.$file)) {
			$content = file_get(DT_CACHE.&#39;/htm/&#39;.$file);
			if(substr($content, 0, 4) == &#39;<!--&#39;) $content = substr($content, 17);
			echo $content;
		} else {
			echo &#39;&#39;;
		}
	} else if($ext == &#39;lang&#39;) {
		$file = str_replace(&#39;.lang&#39;, &#39;.inc.php&#39;, $file);
		return DT_ROOT.&#39;/lang/&#39;.DT_LANG.&#39;/&#39;.$file;
	}
}

function ad($id, $cid = 0, $kw = &#39;&#39;, $tid = 0) {
	global $cityid;
	if($tid) {
		if($kw) {
			$file = &#39;ad_t&#39;.$tid.&#39;_m&#39;.$id.&#39;_k&#39;.urlencode($kw);
		} else if($cid) {
			$file = &#39;ad_t&#39;.$tid.&#39;_m&#39;.$id.&#39;_c&#39;.$cid;
		} else {
			$file = &#39;ad_t&#39;.$tid.&#39;_m&#39;.$id;
		}
		$a3 = &#39;ad_&#39;.$id.&#39;_d&#39;.$tid.&#39;.htm&#39;;
	} else {
		$file = &#39;ad_&#39;.$id;
		$a3 = &#39;ad_&#39;.$id.&#39;_d0.htm&#39;;
	}
	$a1 = $file.&#39;_&#39;.$cityid.&#39;.htm&#39;;
	if(is_file(DT_CACHE.&#39;/htm/&#39;.$a1)) return load($a1);
	$a2 = $file.&#39;_0.htm&#39;;
	if(is_file(DT_CACHE.&#39;/htm/&#39;.$a2)) return load($a2);
	if(is_file(DT_CACHE.&#39;/htm/&#39;.$a3)) return load($a3);
}

function lang($str, $arr = array()) {
	if(strpos($str, &#39;->&#39;) !== false) {
		$t = explode(&#39;->&#39;, $str);
		include load($t[0].&#39;.lang&#39;);
		$str = $L[$t[1]];
	}
	if($arr) {
		foreach($arr as $k=>$v) {
			$str = str_replace(&#39;{V&#39;.$k.&#39;}&#39;, $v, $str);
		}
	}
	return $str;
}

function check_name($username) {
	if(strpos($username, &#39;__&#39;) !== false || strpos($username, &#39;--&#39;) !== false) return false; 
	return preg_match("/^[a-z0-9]{1}[a-z0-9_\-]{0,}[a-z0-9]{1}$/", $username);
}

function check_post() {
	if(strtoupper($_SERVER[&#39;REQUEST_METHOD&#39;]) != &#39;POST&#39;) return false;
	return check_referer();
}

function check_referer() {
	global $DT_REF, $CFG, $DT;
	if($DT[&#39;check_referer&#39;]) {
		if(!$DT_REF) return false;
		$R = parse_url($DT_REF);
		if($CFG[&#39;cookie_domain&#39;] && strpos($R[&#39;host&#39;], $CFG[&#39;cookie_domain&#39;]) !== false) return true;
		if($CFG[&#39;com_domain&#39;] && strpos($R[&#39;host&#39;], $CFG[&#39;com_domain&#39;]) !== false) return true;
		if($DT[&#39;safe_domain&#39;]) {
			$tmp = explode(&#39;|&#39;, $DT[&#39;safe_domain&#39;]);
			foreach($tmp as $v) {
				if(strpos($R[&#39;host&#39;], $v) !== false) return true;
			}
		}		
		$U = parse_url(DT_PATH);
		if(strpos($R[&#39;host&#39;], str_replace(&#39;www.&#39;, &#39;.&#39;, $U[&#39;host&#39;])) !== false) return true;
		return false;
	} else {
		return true;
	}
}

function is_robot() {
	if(strpos($_SERVER[&#39;HTTP_USER_AGENT&#39;], &#39;://&#39;) === false && preg_match("/(MSIE|Netscape|Opera|Konqueror|Mozilla)/i", $_SERVER[&#39;HTTP_USER_AGENT&#39;])) {
		return false;
	} else if(preg_match("/(Spider|Bot|Crawl|Slurp|lycos|robozilla)/i", $_SERVER[&#39;HTTP_USER_AGENT&#39;])) {
		return true;
	} else {
		return false;
	}
}

function is_ip($ip) {
	return preg_match("/^([0-9]{1,3}\.){3}[0-9]{1,3}$/", $ip);
}

function is_md5($password) {
	return preg_match("/^[a-z0-9]{32}$/", $password);
}

function debug() {
	global $db, $debug_starttime;
	$mtime = explode(&#39; &#39;, microtime());
	$s = number_format(($mtime[1] + $mtime[0] - $debug_starttime), 3);
	echo &#39;Processed in &#39;.$s.&#39; second(s), &#39;.$db->querynum.&#39; queries&#39;;
    if(function_exists(&#39;memory_get_usage&#39;)) echo &#39;, Memory &#39;.round(memory_get_usage()/1024/1024, 2).&#39; M&#39;;
}

//For 3.x
function extendurl($func) {
	global $MODULE, $EXT;
	$key = $func.&#39;_url&#39;;
	return $EXT[$key] ? $EXT[$key] : $MODULE[1][&#39;linkurl&#39;].$func.&#39;/&#39;;
}

function extend_setting($key = &#39;&#39;) {
	global $EXT;
	return $key ? $EXT[$key] : $EXT;
}
?>
Salin selepas log masuk

                   

                   

Label berkaitan:
php
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan