<?php

if (!defined('IN_OELOVE')) {
exit('OElove[OEPHP] Access Denied');
}
class XHandle{
public static function error($error) {
echo "<meta http-equiv='Content-Type' content='text/html; charset=".OELOVE_CHARSET."' />
		<style>body{font-size:12px;line-height:25px;}</style>
		<body>
		".$error."
		</body>
		";
die();
}
public static function redirect($url,$time = 0) {
if (!headers_sent()) {
if ($time === 0) header("Location:{$url}");
header("refresh:".$time.";url=".$url."");
die();
}
else {
exit("<meta http-equiv='Refresh' content='{$time};URL={$url}'>");
die();
}
}
public static function getLength($str) {
$len=0;
if (!empty($str)) {
preg_match_all ('#(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+)#s',$str,$array,PREG_PATTERN_ORDER);
foreach($array[0] as $val){
$len+=ord($val)>=128 ?2:1;
}
}
return $len;
}
public static function getWordLength($value) {
$len = 0;
if (!empty($value)) {
preg_match_all ('#(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+)#s',$value,$array,PREG_PATTERN_ORDER);
foreach($array[0] as $val){
$len+=ord($val)>=128 ?1:1;
}
}
return $len;
}
public static function getTitleLen($str) {
$len=0;
if (!empty($str)) {
preg_match_all ('#(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+)#s',$str,$array,PREG_PATTERN_ORDER);
foreach($array[0] as $val){
$len +=ord($val)>=128 ?2 : 1;
}
}
return $len;
}
public static function getRndChar($length,$type=0){
switch($type) {
case 1:$pattern = "1234567890";break;
case 2:$pattern = "abcdefghijklmnopqrstuvwxyz";break;
case 3:$pattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";break;
case 4:$pattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890~!@#$%^&*()_-+=";break;
case 5:$pattern = "123456789";break;
default:$pattern = "1234567890abcdefghijklmnopqrstuvwxyz";
}
$size = strlen($pattern)-1;
$key = $pattern{rand(0,$size)};
for ($i = 1;$i <$length;$i++) {
$key.= $pattern{rand(0,$size)};
}
return $key;
}
public static function foundInChar($string,$tofound,$split=','){
$flag = false;
if (!empty($string) &&!empty($tofound)) {
$arr = explode($split,$string);
if (!empty($arr)) {
foreach ($arr as $k=>$v) {
if (strtolower($v) == strtolower($tofound)) {
$flag = true;
break;
}
}
}
}
return $flag;
}
public static function getStrpos($s_str,$s_needlechar){
if (empty($s_str)) {return;}
if (empty($s_needlechar)) {return;}
$s_temparray = explode($s_needlechar,$s_str);
if (count($s_temparray)>0) {
return true;
}
else {
return false;
}
}
public static function recBr($s_content){
$s_content = str_replace("\n","<br />",$s_content);
return $s_content;
}
public static function filterHtml($_obfuscate_R2_b,$_obfuscate_KT_ujQ = false){
return self::clearHtml($_obfuscate_R2_b);
}
public static function cutStrLen($string,$sublen,$start=0){
if (OELOVE_CHARSET == 'UTF-8'OR OELOVE_CHARSET == 'utf-8'){
$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
preg_match_all($pa,$string,$t_string);
if(count($t_string[0]) -$start >$sublen) return join('',array_slice($t_string[0],$start,$sublen))."";return join('',array_slice($t_string[0],$start,$sublen));
}
else{
$start = $start*2;
$sublen = $sublen*2;
$strlen = strlen($string);
$tmpstr = '';
for($i=0;$i<$strlen;$i++){
if($i>=$start &&$i<($start+$sublen)){
if(ord(substr($string,$i,1))>129){
$tmpstr.= substr($string,$i,2);
}else{
$tmpstr.= substr($string,$i,1);
}
}
if(ord(substr($string,$i,1))>129) $i++;
}
return $tmpstr;
}
}
public static function utfToGbk($value){
if (function_exists('iconv')) {
return iconv('UTF-8','GBK',$value);
}
else {
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($value,'UTF-8','GBK');
}
else {
return $value;
}
}
}
public static function gbkToUtf($value){
if (function_exists('iconv')) {
return iconv('GBK','UTF-8',$value);
}
else {
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($value,'GBK','UTF-8');
}
else {
return $value;
}
}
}
public static function formatNumber($price,$pricetype=1,$change_price = true){
if ($change_price){
switch ($pricetype){
case 0: 
$price = number_format($price,2,'.','');
break;
case 1: 
$price = preg_replace('/(.*)(\\.)([0-9]*?)0+$/','\1\2\3',number_format($price,2,'.',''));
if (substr($price,-1) == '.'){
$price = substr($price,0,-1);
}
break;
case 2: 
$price = substr(number_format($price,2,'.',''),0,-1);
break;
case 3: 
$price = intval($price);
break;
case 4: 
$price = number_format($price,1,'.','');
break;
case 5: 
$price = round($price);
break;
}
}else{
$price = number_format($price,2,'.','');
}
return $price;
}
public static function mb($_string,$_comurl,$_gotype){
echo("<meta http-equiv='Content-Type' content='text/html; charset=".OELOVE_CHARSET."' />");
echo"<script language=javascript>alert('{$_string}');";
if ($_gotype == 1) {
echo"window.history.go(-1);";
}
else {
echo"window.location.href='{$_comurl}';";
}
echo"</script>";
die();
}
public static function halt($message,$url,$type){
require_once BASE_ROOT."tpl/halt/halt.php";
die();
}
public static function wapHalt($text='',$url='',$type=1) {
require_once(BASE_ROOT."tpl/waphalt/halt.php");
die();
}
public static function tbDialog($msg='',$type=1) {
echo("<meta http-equiv='Content-Type' content='text/html; charset=".OELOVE_CHARSET."' />");
if (!empty($msg)) {
echo("<script language=javascript>alert('{$msg}');</script>");
if ($type == 1) {
echo("<script>parent.location.reload();</script>");
}else {
echo("<script>parent.tb_remove();</script>");
}
}
else {
if ($type == 1) {
echo("<script>parent.location.reload();</script>");
}else {
echo("<script>parent.tb_remove();</script>");
}
}
die();
}
public static function combinSql($asname,$field,$sqlitem){
$sql = '';
if (is_numeric($sqlitem)) {
if (!empty($asname)) {
$sql .= " AND {$asname}.{$field}='{$sqlitem}'";
}
else {
$sql .= " AND `{$field}`='{$sqlitem}'";
}
}
else {
$array = explode(',',$sqlitem);
if (!empty($array)) {
$or_sql = '';
foreach ($array as $k=>$v) {
if (is_numeric($v)) {
if (!empty($asname)) {
if (empty($or_sql)) {
$or_sql .= " {$asname}.{$field}='{$v}'";
}
else {
$or_sql .= " OR {$asname}.{$field}='{$v}'";
}
}
else {
if (empty($or_sql)) {
$or_sql .= " `{$field}`='{$v}'";
}
else {
$or_sql .= " OR `{$field}`='{$v}'";
}
}
}
}
if (!empty($or_sql)) {
$sql .= " AND ({$or_sql})";
}
}
}
return $sql;
}
public static function sysSortArray($ArrayData,$KeyName1,$SortOrder1 = "SORT_ASC",$SortType1 = "SORT_REGULAR"){
if(!is_array($ArrayData)){
return $ArrayData;
}
$ArgCount = func_num_args();
for($I = 1;$I <$ArgCount;$I ++){
$Arg = func_get_arg($I);
if (!preg_match("/SORT/i",$Arg)) {
$KeyNameList[] = $Arg;
$SortRule[]= '$'.$Arg;
}
else {
$SortRule[]= $Arg;
}
}
foreach($ArrayData AS $Key =>$Info){
foreach($KeyNameList AS $KeyName){
${$KeyName}[$Key] = $Info[$KeyName];
}
}
$EvalString = 'array_multisort('.join(",",$SortRule).',$ArrayData);';
eval ($EvalString);
return $ArrayData;
}
public static function fileExists($fliename){
if (file_exists($fliename)) {
return true;
}
else {
return false;
}
}
public static function forbidChar($string){
$forbidchar = array('select','update','union','insert','load_file','outfile','where','char','concat','#');
if(self::isChar($string)){
foreach($forbidchar as $key){
if(strpos(strtolower($string),$key)){
$string = "";
}
}
}
return $string;
}
public static function checkOdayChar($string){
$checkflag = false;
$forbidchar = array('select','update','union','insert','load_file','outfile','char','concat','#');
if(self::isChar($string)){
foreach($forbidchar as $key){
if(strpos(strtolower($string),$key)){
$checkflag = true;
}
}
}
return $checkflag;
}
public static function checkTable($tablename){
if(preg_match("/^[0-9a-zA-Z_]+$/u",$tablename)){
return true;
}else {
return false;
}
}
public static function formatSize($size) {
if ($size <1000) {
$size_BKM = (string) $size .' B';
}elseif ($size <(1000 * 1000)) {
$size_BKM = number_format((double) ($size / 1000),1) .' KB';
}else {
$size_BKM = number_format((double) ($size / (1000 * 1000)),1) .' MB';
}
return $size_BKM;
}
public static function getDiffTime($endtime) {
$res = '';
$validtime = ($endtime-time());
if ($validtime >0) {
if ($validtime >= 86400) {
$res = ceil($validtime/86400).'天';
}
if ($validtime>=3600 &&$validtime<86400) {
$res = ceil($validtime/3600).'小时';
}
if ($validtime>=60 &&$validtime<3600) {
$res = ceil($validtime/60).'分钟';
}
if ($validtime<60) {
$res = $validtime.'秒';
}
}
return $res;
}
public static function getUnixTime($type='time') {
if ($type == 'time') {
return time();
}
else {
return strtotime(date("Y-m-d",time()));
}
}
public static function diffDate($timeline,$days,$difftype=1,$returntype=1) {
$dateline = date('Y-m-d',$timeline);
if ($difftype == 1) {
$diff_timeline = strtotime($dateline) +(3600 * 24 * $days);
}
else {
$diff_timeline = strtotime($dateline) -(3600 * 24 * $days);
}
if ($returntype == 1) {
return strtotime(date('Y-m-d',$diff_timeline));
}
else {
return date('Y-m-d',$diff_timeline);
}
}
public static function lastDate($date) {
$lastdays = 0;
if (is_numeric($date)) {
$lastdays = ($date-strtotime(date("Y-m-d",time())))/3600/24;
}
else {
$lastdays = (strtotime($date)-(strtotime('Y-m-d',time())))/3600/24;
}
return $lastdays;
}
public static function diffBetweenTwoDays ($day1,$day2) {
$days = 0;
$second1 = strtotime(date("Y-m-d",$day1));
$second2 = strtotime(date("Y-m-d",$day2));
if ($second1 >$second2) {
$days = ($second1-$second2)/86400;
}
return $days;
}
public static function lengthBetweenTwoDays ($min_day1,$max_day2,$is_str = 1) {
$min_day1 = strtotime(date("Y-m-d H:i:s",$min_day1));
$max_day2 = strtotime(date("Y-m-d H:i:s",$max_day2));
if ($min_day1 >= $max_day2) {
return null;
}else {
$length = $max_day2 -$min_day1;
$day = floor($length/86400);
$hour = floor(($length -(86400*$day))/3600);
$minute = floor(($length -(86400*$day) -(3600*$hour))/60);
if ($is_str == 1) {
$str = "{$day}天{$hour}小时{$minute}分钟";
return $str;
}else {
return array(
"day"=>$day,
"hour"=>$hour,
"minute"=>$minute
);
}
}
}
public static function dounSerialize($string){
if (!empty($string)) {
if (strtolower(OELOVE_CHARSET) == 'utf-8') {
return self::utf_unserialize($string);
}else{
return self::gbk_unserialize($string);
}
}
else {
return '';
}
}
private static function utf_unserialize($serial_str){
if (GB_PHP_VERSION >5.4) {
$serial_str = preg_replace_callback('!s:(\d+):"(.*?)";!s',
"self::_serialize_callback",
$serial_str
);
}
else {
$serial_str = preg_replace('!s:(\d+):"(.*?)";!se',"'s:'.strlen('$2').':\"$2\";'",$serial_str );
}
$serial_str = str_replace("\r","",$serial_str);
return @unserialize($serial_str);
}
private static function gbk_unserialize($serial_str) {
if (GB_PHP_VERSION >5.4) {
$serial_str = preg_replace_callback('!s:(\d+):"(.*?)";!s',
"self::_serialize_callback",
$serial_str
);
}
else {
$serial_str = preg_replace('!s:(\d+):"(.*?)";!se','"s:".strlen("$2").":\"$2\";"',$serial_str );
}
$serial_str= str_replace("\r","",$serial_str);
return @unserialize($serial_str);
}
private static function _serialize_callback($matches) {
return 's:'.strlen($matches[2]) .':"'.$matches[2] .'";';
}
public static function getOsType() {
$os = explode(" ",php_uname());
$os_name = $os[0];
if ('/'==DIRECTORY_SEPARATOR){
$ver = $os[2];
}
else{
$ver = $os[1];
}
return $os_name.' '.$ver;
}
public static function getGuid() {
$charid = strtoupper(md5(uniqid(mt_rand(),true)));
$hyphen = chr(45);
$uuid = substr($charid,0,8).$hyphen
.substr($charid,8,4).$hyphen
.substr($charid,12,4).$hyphen
.substr($charid,16,4).$hyphen
.substr($charid,20,12);
return $uuid;
}
public static function getCouponCode() {
$guid = strtoupper(md5(uniqid(mt_rand(),true)));
$hyphen = chr(45);
$_code = substr($guid,8,4).$hyphen
.substr($guid,12,4).$hyphen
.substr($guid,16,4).$hyphen
.substr($guid,20,4);
return $_code;
}
public static function daysInMonth($year,$month) {
$year  = intval($year);
$month = intval($month);
return $month == 2 ?($year %4 ?28 : ($year %100 ?29 : ($year %400 ?28 : 29))) : (($month -1) %7 %2 ?30 : 31);
}
public static function buildTagArray($params=''){
$attributes = array();
$_value = '';
if (!empty($params)) {
if (strstr($params,'mod={')) {
$_attr = explode('mod={',$params);
$_attr_value = $_attr[1];
#get value
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['mod'] = $_value;
}
}
if (strstr($params,'type={')) {
$_attr = explode('type={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['type'] = $_value;
}
}
if (strstr($params,'where={')) {
$_attr = explode('where={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['where'] = $_value;
}
}
if (strstr($params,'orderby={')) {
$_attr = explode('orderby={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['orderby'] = $_value;
}
}
if (strstr($params,'num={')) {
$_attr = explode('num={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['num'] = $_value;
}
}
if (strstr($params,'childnum={')) {
$_attr = explode('childnum={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['childnum'] = $_value;
}
}
if (strstr($params,'catid={')) {
$_attr = explode('catid={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['catid'] = $_value;
}
}
if (strstr($params,'child={')) {
$_attr = explode('child={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['child'] = $_value;
}
}
if (strstr($params,'city={')) {
$_attr = explode('city={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['city'] = $_value;
}
}
if (strstr($params,'value={')) {
$_attr = explode('value={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['value'] = $_value;
}
}
if (strstr($params,'limit={')) {
$_attr = explode('limit={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['limit'] = $_value;
}
}
if (strstr($params,'contday={')) {
$_attr = explode('contday={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['contday'] = $_value;
}
}
if (strstr($params,'startmonth={')) {
$_attr = explode('startmonth={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['startmonth'] = $_value;
}
}
if (strstr($params,'endmonth={')) {
$_attr = explode('endmonth={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['endmonth'] = $_value;
}
}
if (strstr($params,'cache={')) {
$_attr = explode('cache={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['cache'] = $_value;
}
}
if (strstr($params,'cachetime={')) {
$_attr = explode('cachetime={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['cachetime'] = $_value;
}
}
if (strstr($params,'siteid={')) {
$_attr = explode('siteid={',$params);
$_attr_value = $_attr[1];
if (strstr($_attr_value,'}')) {
$_attr_right_array = explode('}',$_attr_value);
$_value = $_attr_right_array[0];
$attributes['siteid'] = $_value;
}
}
}
return $attributes;
}
public static function isFromWeixin() {
if (strpos($_SERVER['HTTP_USER_AGENT'],'MicroMessenger') !== false ) {
return "weixin";
}
else {
return "";
}
}
public static function repEmface($text) {
$new_text = NULL;
if (!empty($text)) {
$new_text = $text;
$em_path = PATH_URL."tpl/static/images/face/";
for ($i=0;$i<105;$i++) {
$new_text = str_replace("{emf_{$i}}","<img src='".$em_path.$i.".gif' />",$new_text);
}
}
return $new_text;
}
public static function cutComma($string) {
if (!empty($string)) {
$string = str_ireplace(",,",",",$string);
if (substr($string,-1) == ',') {
$string = substr($string,0,(strlen($string)-1));
}
}
return $string;
}
public static function tranTime($time) {
$rtime = date("m-d H:i",$time);
$htime = date("H:i",$time);
$time = time() -$time;
if ($time <60) {
$str = '刚刚';
}
elseif ($time <60 * 60) {
$min = floor($time/60);
$str = $min.'分钟前';
}
elseif ($time <60 * 60 * 24) {
$h = floor($time/(60*60));
$str = $h.'小时前';
}
elseif ($time <60 * 60 * 24 * 3) {
$d = floor($time/(60*60*24));
if ($d==1) {
$str = '昨天 '.$htime;
}
else {
$str = '前天 '.$htime;
}
}
else {
$str = $rtime;
}
return $str;
}
public static function getFirstLetter($str) {
$str= iconv("UTF-8","gb2312",$str);
if (preg_match("/^[\x7f-\xff]/",$str)) {
$fchar = ord($str{0});
if ($fchar>=ord("A") and $fchar<=ord("z") ) return strtoupper($str{0});
$a = $str;
$val= ord($a{0})*256+ord($a{1})-65536;
if ($val>=-20319 and $val<=-20284) return "A";
if ($val>=-20283 and $val<=-19776) return "B";
if ($val>=-19775 and $val<=-19219) return "C";
if ($val>=-19218 and $val<=-18711) return "D";
if ($val>=-18710 and $val<=-18527) return "E";
if ($val>=-18526 and $val<=-18240) return "F";
if ($val>=-18239 and $val<=-17923) return "G";
if ($val>=-17922 and $val<=-17418) return "H";
if ($val>=-17417 and $val<=-16475) return "J";
if ($val>=-16474 and $val<=-16213) return "K";
if ($val>=-16212 and $val<=-15641) return "L";
if ($val>=-15640 and $val<=-15166) return "M";
if ($val>=-15165 and $val<=-14923) return "N";
if ($val>=-14922 and $val<=-14915) return "O";
if ($val>=-14914 and $val<=-14631) return "P";
if ($val>=-14630 and $val<=-14150) return "Q";
if ($val>=-14149 and $val<=-14091) return "R";
if ($val>=-14090 and $val<=-13319) return "S";
if ($val>=-13318 and $val<=-12839) return "T";
if ($val>=-12838 and $val<=-12557) return "W";
if ($val>=-12556 and $val<=-11848) return "X";
if ($val>=-11847 and $val<=-11056) return "Y";
if ($val>=-11055 and $val<=-10247) return "Z";
}
else
{
return "";
}
}
public static function getToday($type=1) {
$start = date("Y-m-d")." 00:00:00";
$end = date("Y-m-d")." 23:59:59";
if ($type == 1) {
$start = strtotime($start);
$end = strtotime($end);
}
return array($start,$end);
}
public static function getYesterday($type=1) {
$yesterday = date("Y-m-d",strtotime("-1 day"));
$start = $yesterday." 00:00:00";
$end = $yesterday." 23:59:59";
if ($type == 1) {
$start = strtotime($start);
$end = strtotime($end);
}
return array($start,$end);
}
public static function getCurWeek($type=1) {
$start = date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-date("w")+1,date("Y")));
$end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")));
if ($type == 1) {
$start = strtotime($start);
$end = strtotime($end);
}
return array($start,$end);
}
public static function getLastWeek($type=1) {
$start = date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-date("w")+1-7,date("Y")));
$end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y")));
if ($type == 1) {
$start = strtotime($start);
$end = strtotime($end);
}
return array($start,$end);
}
public static function getCurMonth($type=1) {
$start = date("Y-m-d H:i:s",mktime(0,0,0,date("m"),1,date("Y")));
$end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
if ($type == 1) {
$start = strtotime($start);
$end = strtotime($end);
}
return array($start,$end);
}
public static function getLastMonth($type=1) {
$start = date("Y-m-d H:i:s",mktime(0,0,0,date("m")-1,1,date("Y")));
$end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),0,date("Y")));
if ($type == 1) {
$start = strtotime($start);
$end = strtotime($end);
}
return array($start,$end);
}
public static function getCurQuarter($type=1) {
$getMonthDays = date("t",mktime(0,0,0,date('n')+(date('n')-1)%3,1,date("Y")));
$start = date('Y-m-d H:i:s',mktime(0,0,0,date('n')-(date('n')-1)%3,1,date('Y')));
$end = date('Y-m-d H:i:s',mktime(23,59,59,date('n')+(date('n')-1)%3,$getMonthDays,date('Y')));
if ($type == 1) {
$start = strtotime($start);
$end = strtotime($end);
}
return array($start,$end);
}
public static function unifyPrompt($text='',$url='',$type=1){
if(true == APP::isAjaxRequest()){
if ($type == '1'){
APP::callBackJson(0,$text);
}else{
APP::callBackJson(1,$text);
}
}
else{
if (true == mobile_device_detect()) {
self::wapHalt($text,$url,$type);
}else{
self::halt($text,$url,$type);
}
}
}
public static function timeDownText($dtime) {
$time_str = "";
$cur_time = time();
if ($dtime <$cur_time) {
$time_str = "已超时";
}
else {
$diff_timer = ($dtime-$cur_time);
$value = array(
"days"=>0,"hours"=>0,"minutes"=>0,"seconds"=>0,
);
if ($diff_timer >= 86400){
$value["days"] = floor($diff_timer/86400);
$diff_timer = ($diff_timer%86400);
}
if ($diff_timer >= 3600){
$value["hours"] = floor($diff_timer/3600);
$diff_timer = ($diff_timer%3600);
}
if ($diff_timer >= 60){
$value["minutes"] = floor($diff_timer/60);
$diff_timer = ($diff_timer%60);
}
$value["seconds"] = floor($diff_timer);
if ($value['days'] >0) {
$time_str .= $value['days']."天";
}
else {
if ($value['hours'] >0) {
$time_str .= $value["hours"]."小时";
}
if ($value['minutes'] >0) {
$time_str .= $value["minutes"]."分";
}
if ($value['seconds'] >0) {
$time_str .= $value["seconds"]."秒";
}
}
}
return $time_str;
}
public static function buildCheckBox($str) {
$new_str = "";
$new_str = $str;
if (!empty($new_str)) {
$new_str = str_ireplace(",,",",",$new_str);
if (true === XValid::isIDs($new_str)) {
if (substr($new_str,-1) == ',') {
$new_str = substr($new_str,0,(strlen($new_str)-1));
}
}
else {
$new_str = "";
}
}
return $new_str;
}
public static function clearHtml($cont) {
$new_cont = "";
if (!empty($cont)) {
$new_cont = stripslashes($cont);
$new_cont = strip_tags($new_cont);
$new_cont = trim($new_cont);
$new_cont = str_replace("\t","",$new_cont);
$new_cont = str_replace("\r\n","",$new_cont);
$new_cont = str_replace("\r","",$new_cont);
$new_cont = str_replace("\n","",$new_cont);
$new_cont = str_replace(" ","",$new_cont);
}
return $new_cont;
}
public static function loginTranTime($time) {
$str = "";
$rtime = date("m-d H:i",$time);
$htime = date("H:i",$time);
$time = (time() -$time);
if ($time <60*60*0.5) {
$str = "半小时前来过";
}
elseif ($time <60*60*1) {
$min = floor($time/60);
$str = "1小时前来过";
}
elseif ($time <60*60*6) {
$h = floor($time/(60*60));
$str = "6小时前来过";
}
elseif ($time <60*60*24*1) {
$d = floor($time/(60*60*24));
$str = "1天前来过";
}
elseif ($time <60*60*24*3) {
$d = floor($time/(60*60*24));
$str = "3天前来过";
}
return $str;
}
public static function isPhp7() {
$php7 = @version_compare(PHP_VERSION,'5.5','>=');
return $php7;
}
public static function getMobileDevice() {
$user_agent = '';
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$user_agent= strtolower($_SERVER['HTTP_USER_AGENT']);
}
$type = 'other';
if (!empty($user_agent)) {
if (strpos($user_agent,'iphone') !== false ||strpos($user_agent,'ipad') !== false) {
$type = 'ios';
}
elseif (strpos($user_agent,'android') !== false) {
$type = 'android';
}
}
return $type;
}
}
?>
