| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572 | <?phpclass Load {	static function controller($name) {		return @include_once (ROOT_PATH . 'protected/controller/' . $name . '.php');	}	static function logic($name) {				return @include_once (ROOT_PATH . 'protected/logic/' . $name . 'Logic.php');	}	static function lib($name) {		return @include_once (ROOT_PATH . 'protected/plugin/' . $name . '.han.php');	}	static function dao($name) {		return @include_once (ROOT_PATH . 'protected/model/' . $name . '.Dao.php');	}}/** * 获取时间戳,day获取几天后的时间戳 */function get_date($day = 0) {	if ($day != 0)		return strtotime ( "+" . $day . " day" );	return strtotime ( "now" );}/** * 获取几个小时后的时间戳 * @param unknown_type $hours */function get_hours($hours = 0) {	if ($hours != 0)		return strtotime ( "+" . $hours . " hours" );	return strtotime ( "now" );}/** * 获取几个分钟后的时间戳 * @param unknown_type $hours */function get_seconds($seconds = 0) {	if ($seconds != 0)		return strtotime ( "+" . $seconds . " seconds" );	return strtotime ( "now" );}/** * 获取时间戳 */function get_time($time = 0) {	return strtotime ( $time );}/** * 格式化时间为年月日时分秒 * @param unknown_type $strtotime */function format_date($strtotime = 0, $format = "Y-m-d H:i:s") {	return date ( $format, $strtotime );}/** * 获取当天开始时间和结束时间 */function get_today() {		$t = time ();		$start = mktime ( 0, 0, 0, date ( "m", $t ), date ( "d", $t ), date ( "Y", $t ) );		$end = mktime ( 23, 59, 59, date ( "m", $t ), date ( "d", $t ), date ( "Y", $t ) );		return array ('start' => $start, 'end' => $end );}/** * 格式化问题状态 * @param unknown_type $status */function format_question_status($status = 1, $type = "index") {		if ($type == "index") {		if (1 == $status)			return "待解决";		elseif (2 == $status)			return "<span class='queState colGreen'>已解决</span>";		elseif (9 == $status)			return "<span class='queState colRed'>已关闭</span>";		elseif (6 == $status)			return "推荐问题";	} elseif ($type == "page") {		if (1 == $status)			return "<b class='extraIcon iconNotDone'></b>待解决";		elseif (2 == $status)			return "<b class='extraIcon iconDone'></b><span class='queState colGreen'>已解决</span>";		elseif (9 == $status)			return "<b class='extraIcon iconStop'></b><span class='queState colRed'>已关闭</span>";		elseif (6 == $status)			return "推荐问题";	} elseif ($type == "vip") {		if (1 == $status)			return "未提问";		elseif (2 == $status)			return "已提问";		elseif (3 == $status)			return "满意";		elseif (4 == $status)			return "不满意";	} else {		if (1 == $status)			return "<b class='extraIcon iconNotDone'></b>";		elseif (2 == $status)			return "<b class='extraIcon iconDone'></b>";		elseif (9 == $status)			return "<b class='extraIcon iconStop'></b>";		elseif (6 == $status)			return "推荐问题";	}}/** * 获取客户端IP地址 */function client_ip() {	if (getenv ( 'HTTP_CLIENT_IP' ) && strcasecmp ( getenv ( 'HTTP_CLIENT_IP' ), 'unknown' )) {		$onlineip = getenv ( 'HTTP_CLIENT_IP' );	} elseif (getenv ( 'HTTP_X_FORWARDED_FOR' ) && strcasecmp ( getenv ( 'HTTP_X_FORWARDED_FOR' ), 'unknown' )) {		$onlineip = getenv ( 'HTTP_X_FORWARDED_FOR' );	} elseif (getenv ( 'REMOTE_ADDR' ) && strcasecmp ( getenv ( 'REMOTE_ADDR' ), 'unknown' )) {		$onlineip = getenv ( 'REMOTE_ADDR' );	} elseif (isset ( $_SERVER ['REMOTE_ADDR'] ) && $_SERVER ['REMOTE_ADDR'] && strcasecmp ( $_SERVER ['REMOTE_ADDR'], 'unknown' )) {		$onlineip = $_SERVER ['REMOTE_ADDR'];	}		preg_match ( '/[\d\.]{7,15}/', $onlineip, $onlineipmatches );	$onlineip = ($onlineipmatches [0] ? $onlineipmatches [0] : 'unknown');		return $onlineip;}/** * random 获取字符串 * @param int $length * @return string $hash */function random($length = 6, $type = 0) {	$hash = '';	$chararr = array ('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz', '0123456789', '23456789ABCDEFGHJKLMNPQRSTUVWXYZ' );	$chars = $chararr [$type];	$max = strlen ( $chars ) - 1;	PHP_VERSION < '4.2.0' && mt_srand ( ( double ) microtime () * 1000000 );	for($i = 0; $i < $length; $i ++) {		$hash .= $chars [mt_rand ( 0, $max )];	}	return $hash;}/** * 获取用户等级 */function get_lv($credit = 0) {	$lv = array ();	if (0 <= $credit && $credit <= 80) {				array_push ( $lv, 1 );				array_push ( $lv, 80 );				return $lv;	} elseif (81 <= $credit && $credit <= 400) {				array_push ( $lv, 2 );				array_push ( $lv, 400 );				return $lv;	} elseif (401 <= $credit && $credit <= 800) {				array_push ( $lv, 3 );				array_push ( $lv, 800 );				return $lv;	} elseif (801 <= $credit && $credit <= 2000) {				array_push ( $lv, 4 );				array_push ( $lv, 2000 );				return $lv;	} elseif (2001 <= $credit && $credit <= 4000) {				array_push ( $lv, 5 );				array_push ( $lv, 4000 );				return $lv;	} elseif (4001 <= $credit && $credit <= 7000) {				array_push ( $lv, 6 );				array_push ( $lv, 7000 );				return $lv;	} elseif (7001 <= $credit && $credit <= 10000) {				array_push ( $lv, 7 );				array_push ( $lv, 10000 );				return $lv;	} elseif (10001 <= $credit && $credit <= 14000) {				array_push ( $lv, 8 );				array_push ( $lv, 14000 );				return $lv;	} elseif (14001 <= $credit && $credit <= 18000) {				array_push ( $lv, 9 );				array_push ( $lv, 18000 );				return $lv;	} elseif (18001 <= $credit && $credit <= 22000) {				array_push ( $lv, 10 );				array_push ( $lv, 22000 );				return $lv;	} elseif (22001 <= $credit && $credit <= 32000) {				array_push ( $lv, 11 );				array_push ( $lv, 32000 );				return $lv;	} elseif (32001 <= $credit && $credit <= 45000) {				array_push ( $lv, 12 );				array_push ( $lv, 45000 );				return $lv;	} elseif (45001 <= $credit && $credit <= 60000) {				array_push ( $lv, 13 );				array_push ( $lv, 60000 );				return $lv;	} elseif (60001 <= $credit && $credit <= 100000) {				array_push ( $lv, 14 );				array_push ( $lv, 100000 );				return $lv;	} elseif (100001 <= $credit && $credit <= 150000) {				array_push ( $lv, 15 );				array_push ( $lv, 150000 );				return $lv;	} elseif (150001 <= $credit && $credit <= 250000) {				array_push ( $lv, 16 );				array_push ( $lv, 250000 );				return $lv;	} elseif (250001 <= $credit && $credit <= 400000) {				array_push ( $lv, 17 );				array_push ( $lv, 400000 );				return $lv;	} elseif (400001 <= $credit && $credit <= 700000) {				array_push ( $lv, 18 );				array_push ( $lv, 8700000 );				return $lv;	} elseif (700001 <= $credit && $credit <= 1000000) {				array_push ( $lv, 19 );				array_push ( $lv, 1000000 );				return $lv;	} elseif (1000000 <= $credit && $credit <= 9999999) {				array_push ( $lv, 20 );				array_push ( $lv, 9999999 );				return $lv;	}}/** * 多少天以前 */function day_ago($day = 7) {	$now = strtotime ( "now" );}/** * 获取天数差 * @param unknown_type $nowtime	现在时间 * @param unknown_type $future	过去时间 */function count_days($nowtime, $futuretime) {	$a_dt = getdate ( $nowtime );	$b_dt = getdate ( $futuretime );		$a_new = mktime ( 12, 0, 0, $a_dt ['mon'], $a_dt ['mday'], $a_dt ['year'] );	$b_new = mktime ( 12, 0, 0, $b_dt ['mon'], $b_dt ['mday'], $b_dt ['year'] );		return round ( abs ( $a_new - $b_new ) / 86400 );}/** * 获取最后关闭时间 */function get_last_close_day($sortime = 0, $period = 7) {		$result = count_days ( strtotime ( "now" ), $sortime );		$day = ($period - $result) <= 0 ? 0 : ($period - $result);		return $day;}function my_date_format($timestamp, $format = "Y-m-d H:i:s") {	$SystemConfig = ConfigHandler::get ();		$timezone = $SystemConfig ['timezone'];		return gmdate ( $format, ($timestamp + $timezone * 3600) );}//格式化时间函数function my_date_format2($time = 0, $format = 'Y-m-d') {		$time = isset ( $time ) ? $time : 0;		$now = time ();		$t = $now - $time;		if ($t < 0) {		$time = format_date ( $time, $format );		return $time;	}		if ($t >= 3600) {		$time = format_date ( $time, $format );	} 	elseif ($t < 3600 && $t >= 60) {		$time = floor ( $t / 60 ) . "分钟前";	} else {		$time = "刚刚";	}		return $time;}/** * 计算剩下时间2天 * @param unknown_type $time 剩下值 */function do_vip_answer_time($time = 0) {	if ($time <= 0) {		return "超过回答时间";	}		if ($time <= 432000 && $time >= 86400) {		$day = floor ( $time / 86400 );				$time = $time - ($day * 86400);				if ($time <= 0)			return $day . "天";				$t = round ( $time / 3600 );				return $day . "天" . $t . "小时";	}		if ($time < 86400 && $time >= 3600) {				$t = floor ( $time / 3600 );				return $t . "小时";	}		if ($time < 3600 && $time > 0) {		$t = floor ( $time / 60 );				return $t . "分钟";	}}/** * 获取文件后缀名 * @param unknown_type $filename */function _GetFileEXT($filename) {		$pics = explode ( '.', $filename );		$num = count ( $pics );		return $pics [$num - 1];}/** * 获取上一页 * @param unknown_type $on_page */function get_previous($on_page = 1) {	return $on_page != 0 ? $on_page - 1 : $on_page;}/** * 加密或解密指定字符串 * @param string $string 要加密或解密的字符串 * @param string $operation 当取值为'DECODE'时表示解密,否则为加密 * @param string $key 加解密的key * @param $expiry 超时值 * */function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {	$ckey_length = 4;	if (! $key) {		$key = AUTH;	}	$key = md5 ( $key );	$keya = md5 ( substr ( $key, 0, 16 ) );	$keyb = md5 ( substr ( $key, 16, 16 ) );	$keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';		$cryptkey = $keya . md5 ( $keya . $keyc );	$key_length = strlen ( $cryptkey );		$string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;	$string_length = strlen ( $string );		$result = '';	$box = range ( 0, 255 );		$rndkey = array ();	for($i = 0; $i <= 255; $i ++) {		$rndkey [$i] = ord ( $cryptkey [$i % $key_length] );	}		for($j = $i = 0; $i < 256; $i ++) {		$j = ($j + $box [$i] + $rndkey [$i]) % 256;		$tmp = $box [$i];		$box [$i] = $box [$j];		$box [$j] = $tmp;	}		for($a = $j = $i = 0; $i < $string_length; $i ++) {		$a = ($a + 1) % 256;		$j = ($j + $box [$a]) % 256;		$tmp = $box [$a];		$box [$a] = $box [$j];		$box [$j] = $tmp;		$result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );	}		if ($operation == 'DECODE') {		if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {			return substr ( $result, 26 );		} else {			return '';		}	} else {		return $keyc . str_replace ( '=', '', base64_encode ( $result ) );	}}/** * 将一个字符串写入文件 * @param string $filename 文件名 * @param string $data     要写入文件的内容 * @param mixed  $flag     文件的写入标识,如果为FILE_APPEND或'FILE_APPEND'表示追加,否则为新建 * @return int 返回写入文件的字节数 * */function files_put_contents($filename, $data, $flag = false) {	$mode = ($flag == FILE_APPEND || strtoupper ( $flag ) == 'FILE_APPEND') ? 'ab' : 'wb';	$f = @fopen ( $filename, $mode );	if ($f === false) {		return 0;	} else {		if (is_array ( $data )) {			$data = implode ( '', $data );		}		$bytes_written = @fwrite ( $f, $data );		@fclose ( $f );		return $bytes_written;	}}function cut_str($string, $length, $dot = ' ...') {	if (strlen ( $string ) <= $length) {		return $string;	}		$strcut = '';	$sys_config = "utf-8";	if (strtolower ( $sys_config ) == 'utf-8') {		$n = $tn = $noc = 0;		while ( $n < strlen ( $string ) ) {			$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;		}				$strcut = substr ( $string, 0, $n );	} else {		for($i = 0; $i < $length; $i ++) {			$strcut .= ord ( $string [$i] ) > 127 ? $string [$i] . $string [++ $i] : $string [$i];		}	}		return $strcut . $dot;}function cutstr($string, $length, $dot = '') {	Return cut_str ( $string, $length, $dot );};?>
 |