".$text.""; //$r=""; return $r; } //取得唯一标识 function gsession(){ $r=date("YmdHis").substr(microtime(),2,6); return $r; } //daddslashes function daddslashes($string) { if(!get_magic_quotes_gpc()) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = daddslashes($val, $force); } } else { $string = addslashes($string); } } return $string; } //dstripslashes function dstripslashes($string) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = dstripslashes($val, $force); } } else { $string = stripslashes($string); } return $string; } //取得随机字母 function get_rand($num){ $choper="123456789abcdefghijklmnpqrstuvwxyz"; for($i=0;$i<$num;$i++){ $r_str.=substr($choper,rand(0,strlen($choper)-1),1); } return $r_str; } //取得随机数字 function get_rand_num($num){ $choper="0123456789"; for($i=0;$i<$num;$i++){ $r_str.=substr($choper,rand(0,strlen($choper)-1),1); } return $r_str; } //转换成html function dhtmlchars($str){ $str=str_replace("<","<",$str); $str=str_replace(">",">",$str); $str=str_replace("\n","
",$str); $str=str_replace("\r","",$str); $str=str_replace(" "," ",$str); return $str; } //dhtmlspecialchars function dhtmlspecialchars($string) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = dhtmlspecialchars($val); } } else { $string = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/', '&\\1', str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string)); } return $string; } //去除html标记 function no_html($content){ $search=array("']*?>.*?'si", "'<[\/\!]*?[^<>]*?>'si", "'([\r\n])[\s]+'", "'&(quot|#34);'i", "'&(amp|#38);'i", "'&(lt|#60);'i", "'&(gt|#62);'i", "'&(nbsp|#160);'i", "'&(iexcl|#161);'i", "'&(cent|#162);'i", "'&(pound|#163);'i", "'&(copy|#169);'i", "'&#(\d+);'e"); $replace=array("", "", "\\1", "\"", "&", "<", ">", " ", chr(161), chr(162), chr(163), chr(169), "chr(\\1)"); $content=preg_replace($search,$replace,$content); return $content; } /////显示短标题 //不带省略号 function substrgb($str,$len){ if(strlen($str)<$len+1){ return $str; }else{ $start=0; for($i=0;$i<$start+$len;$i++){ $tmpstr=(ord($str[$i])>=161 && ord($str[$i])<=247 && ord($str[$i+1])>=161 && ord($str[$i+1])<=254)?$str[$i].$str[++$i]:$tmpstr=$str[$i]; if ($i>=$start&&$i<($start+$len)) $tmp.=$tmpstr; } return $tmp; } } //带省略号 function substrgb1($str,$len){ if(strlen($str)<$len+1){ return $str; }else{ $start=0; for($i=0;$i<$start+$len;$i++){ $tmpstr=(ord($str[$i])>=161 && ord($str[$i])<=247 && ord($str[$i+1])>=161 && ord($str[$i+1])<=254)?$str[$i].$str[++$i]:$tmpstr=$str[$i]; if ($i>=$start&&$i<($start+$len)) $tmp.=$tmpstr; } return $tmp."..."; } } //截取字符 function sub_start_end($str,$start,$end){ $tmp=explode($start,$str); $tmp=explode($end,$tmp[1]); return $tmp[0]; } // function check_td($str){ return trim($str)?$str:" "; } ///////////////////////////////////////////////////////url相关 //重定向 function url_redirect($url=''){ $url=$url?$url:$_SERVER["HTTP_REFERER"]; //echo $url; echo ""; //echo ""; echo "Success!"; exit(); } //输出js代码并且重定向 function jscode_and_redirect($url='',$jscode=''){ $url=$url?$url:$_SERVER["HTTP_REFERER"]; echo "".$jscode.""; exit(); } //输出js错误提示 function alert($msg){ echo ""; exit(); } //输出js错误提示并返回 function alert_and_back($msg){ echo ""; exit(); } //输出js错误提示并关闭窗口 function alert_and_close($msg){ echo ""; exit(); } //输出js错误提示并重定向 function alert_and_redirect($msg,$url){ echo ""; exit(); } //输出js错误提示并关闭窗口 function alert_and_reload_opener($msg){ echo ""; exit(); } //重定向并post变量 function redirect_and_post($url,$var){ $html="
"; if(is_array($var)){ foreach($var as $key => $value){ $html.="\n"; } } $html.="
"; echo $html; } //处理url function url_add_getvar($url,$arr){ $tmp=str_replace("?","#",$url); if(ereg("#",$tmp)) $url.="&"; else $url.="?"; foreach($arr as $key => $value){ $url.=$key."=".$value."&"; } $url=substr($url,0,-1); return $url; } ///////////////////////////////////////////////////////文件操作 //上传文件 function upload_file($original_file,$path,$new_file_name){ make_dir($path); return copy($original_file,$path."/".$new_file_name); } //修改文件名 function modify_file_name($original_file,$new_file_name){ if(is_file($original_file)){ copy($original_file,$new_file_name); unlink($original_file); } } //创建目录 function make_dir($dir){ if(!is_dir($dir)) mkdir($dir,0777); } ///删除文件 function del_file($file){ if(is_file($file)) return unlink($file); } //写入文件 function write_file($dir,$file_name,$content){ make_dir($dir); $file=$dir."/".$file_name; $fp=fopen($file,"w"); if(fwrite($fp,$content)) return true; else return false; } //写入并覆盖文件 function write_file1($dir,$file_name,$content){ make_dir($dir); $file=$dir."/".$file_name; $fp=fopen($file,"w+"); if(fwrite($fp,$content)) return true; else return false; } //读取文件内容 function read_file($file){ if(is_file($file)){ $fp=fopen($file,"r"); while($buffer=fread($fp,1024)){ $content.=$buffer; } fclose($fp); } return $content; } //取得文件的后缀名 function get_file_name($file_name){ $arr_tmp=explode(".",$file_name); $num=count($arr_tmp)-1; $r=""; for($i=0;$i<$num;$i++){ $r.=$arr_tmp[$i]."."; } if($r) $r=substr($r,0,-1); return $r; } //取得文件的后缀名 function get_file_ext($file_name){ $arr_tmp=explode(".",$file_name); $num=count($arr_tmp)-1; return strtolower($arr_tmp[$num]); } //取得文件的图标 function get_file_ext_icon($file_ext,$property){ $ft=""; switch($file_ext){ case "rm": case "swf": $ft=$file_ext; break; default: $ft="avi"; break; } return ""; } //检查类型 function check_file_type($str,$type){ $r=false; $tmp=explode("|",$str); for($i=0;$i$srcH){ $dstW=$size; $dstH=intval($srcH*$size/$srcW); }else{ $dstH=$size; $dstW=intval($srcW*$size/$srcH); } $ni=imagecreatetruecolor($dstW,$dstH); imagecopyresampled($ni,$im,0,0,0,0,$dstW,$dstH,$srcW,$srcH); ImageJpeg($ni,$dstFile); } ///////////////////////////////////////////////////////数据库操作 function _mysql_connect($t=''){ global $dbhost,$dbuser,$dbpw,$dbname; switch($t){ case "1": // break; default: $db=new DB_Sql; $db->connect($dbhost,$dbuser,$dbpw,$dbname); break; } return $db; } //取得结果 function get_db_msg($query){ global $db; $res=$db->query($query); $msg=$db->fetch_array($res); return $msg; } ///////////////////////////////////////////////////////分页相关函数 // function get_order_reverse_url($tran_var,$order,$value,$url=''){ $url=$url?$url:$_SERVER[PHP_SELF]; foreach($tran_var as $key1=>$value1){ $other_var.="&".$key1."=".urlencode($value1); } if($value==str_replace("!","",$order) && !ereg("!",$order)) $other_var="?order=!".$value.$other_var; else $other_var="?order=".$value.$other_var; $r=$url.$other_var; return $r; } // function get_order_sql($order){ global $arr_order,$arr_order_d; $arr=ereg("!",$order)?$arr_order_d:$arr_order; $order=ereg("!",$order)?str_replace("!","",$order):$order; foreach($arr as $key => $value){ if($key==$order) $r=$value; } return $r; } // function get_pagesize_option($arr){ global $page_size; for($i=0;$i"; } return $r; } // function get_order_action($self,$order,$url,$tran_var){ $url=$url?$url:$_SERVER[PHP_SELF]; if(is_array($tran_var)){ foreach($tran_var as $key => $value){ $query.=$key."=".urlencode($value)."&"; } if(str_replace("!","",$order)==$self){ if(substr($order,strlen($order)-1,1)=="!"){ $query.="order=".$self; $img="order2h.gif"; }else{ $query.="order=".$self."!"; $img="order1h.gif"; } }else{ $query.="order=".$self; $img="order1.gif"; } return ""; }else{ return ; } } // ///////////////////////////////////////////////////////目录操作 // function path_cut0($path){ $tmp=explode("-",$path); for($i=0;$i0) $r.=$tmp[$i]."-"; } $r=substr($r,0,-1); return $r; } ///截去前$num层目录 function path_cut($path,$num){ $tmp=explode("-",$path); for($i=$num;$i0){ for($i=0;$i<$deep-1;$i++){ $r.="  "; } $r.="└ "; } return $r; } //取得父目录 function get_parent_id($path){ $tmp=explode("-",$path); $r=$tmp[count($tmp)-1]; $r=$r?$r:"0"; return $r; } //取得最后路径 function get_last_id($path){ $tmp=explode("-",$path); $r=$tmp[count($tmp)]; $r=$r?$r:"0"; return $r; } //检测是否存在下级目录 function check_subpath($path){ global $db,$table_pre,$_m; $check=false; $tmp=get_db_msg("select count(*) 'num' from ".$table_pre."path where module='".$_m."' and path='".$path."'"); if($tmp[num]>0) $check=true; return $check; } // function get_deep($path){ $arr=explode("-",$path); return count($arr); } // function op_path($path,$mod){ global $db,$table_pre; $op_path=""; $res=$db->query("select * from ".$table_pre."path where module='".$mod."' and deep='1' order by ord"); while($msg=$db->fetch_array($res)){ $op_path.=""; } } return $op_path; } // function op_path_two1($path,$mod){ global $db,$table_pre; $op_path=""; $res=$db->query("select * from ".$table_pre."path where module='".$mod."' and deep='1' order by ord"); while($msg=$db->fetch_array($res)){ $check=get_db_msg("select count(*) 'num' from ".$table_pre."path where module='".$mod."' and path='".$msg["path"]."-".$msg["id"]."'"); $op_path.=""; } $r1=$db->query("select * from ".$table_pre."path where module='".$mod."' and path='".$m["path"]."-".$m["id"]."' order by ord"); while($m1=$db->fetch_array($r1)){ $op_path.=""; } } } return $op_path; } // function op_client_dp($path=''){ global $db,$table_pre; $op_path=""; $res=$db->query("select * from ".$table_pre."client where face='4' order by path, ord"); while($msg=$db->fetch_array($res)){ $op_path.=""; } $r1=$db->query("select * from ".$table_pre."client where path='".$m["path"]."-".$m["id"]."' order by ord"); while($m1=$db->fetch_array($r1)){ $check=get_db_msg("select count(*) 'num' from ".$table_pre."client where path='".$m1["path"]."-".$m1["id"]."'"); if($check[num]==0){ $op_path.=""; } $r2=$db->query("select * from ".$table_pre."client where path='".$m1["path"]."-".$m1["id"]."' order by ord"); while($m2=$db->fetch_array($r2)){ $check=get_db_msg("select count(*) 'num' from ".$table_pre."client where path='".$m2["path"]."-".$m2["id"]."'"); if($check[num]==0){ $op_path.=""; } } } } } return $op_path; } // function get_client_path_title($path,$split='-'){ global $db,$table_pre; $table=$table_pre."client"; $tmp=explode("-",$path); $r=""; for($i=0;$i0){ $t=get_db_msg("select * from ".$table." where id='".$tmp[$i]."'"); $r.=$t["title"].$split; } } $r=substr($r,0,0-strlen($split)); return $r?$r:$path; } // function get_path_title($path,$split='-',$table=''){ global $db,$table_pre; $table=$table?$table:$table_pre."path"; $tmp=explode("-",$path); $r=""; for($i=0;$i0){ $t=get_db_msg("select * from ".$table." where id='".$tmp[$i]."'"); $r.=$t["title"].$split; } } $r=substr($r,0,0-strlen($split)); return $r; } // function get_column_name($table,$id,$column){ global $db; $msg=get_db_msg("select * from ".$table." where id='".$id."'"); return $msg[$column]; } // function parse_deep($deep){ $r=""; for($i=1;$i<$deep;$i++){ $r.="    "; } return $r; } ///////////////////////////////////////////////////////数学和日期 // function sizecount($filesize) { if($filesize >= 1073741824) { $filesize = round($filesize / 1073741824 * 100) / 100 . ' G'; } elseif($filesize >= 1048576) { $filesize = round($filesize / 1048576 * 100) / 100 . ' M'; } elseif($filesize >= 1024) { $filesize = round($filesize / 1024 * 100) / 100 . ' K'; } else { $filesize = $filesize . ' bytes'; } return $filesize; } //保留小数 function keep_float($f,$num,$thousands_sep=''){ $r=number_format($f,$num,".",$thousands_sep); return $r; } //计算百分比 function deel_bfb($n1,$n2){ if($n2>0 && $n1>0){ $r=round(($n1/$n2)*100); $r=$r."%"; }else{ $r="0%"; } return $r; } //计算百分比 function deel_bfb1($n1,$n2,$num=2){ if($n2>0 && $n1>0){ $r=keep_float(($n1/$n2)*100,$num); $r=$r."%"; //$r=$n1.",".$n2; }else{ $r="0%"; } return $r; } //计算百分比 function deel_bfb3($n1,$num=0){ if($n1>0){ $r=keep_float($n1*100,$num); $r=$r."%"; //$r=$n1.",".$n2; }else{ $r="0%"; } return $r; } // function deel_date1($format,$time){ if($time>0) return date($format,$time); else return ""; } //处理数字 function deel_num($num){ return $num+1-1; } // function deel_price($price){ if($price==0) return ""; else return $price; } // function deel_date_null($date){ $date=str_replace("0000-00-00","",$date); return $date; } // function format_my_date($date){ $date=str_replace("/","-",$date); $date=deel_full_date($date); return $date; } // function get_min_in_array($arr){ if(is_array($arr)){ sort($arr); return $arr[0]; }else{ return 0; } } // function check_datetime($datetime){ $datetime=str_replace("-","",$datetime); $datetime=str_replace(":","",$datetime); $datetime=str_replace(" ","",$datetime); $datetime=$datetime+1-1; return $datetime; } // function day_add($date,$adder){ $tmp=explode("-",$date); $t=mktime(0,0,0,$tmp[1],$tmp[2]+$adder,$tmp[0]); return date("Y-n-j",$t); } // function day_add1($date,$adder){ $tmp=explode("-",$date); $t=mktime(0,0,0,$tmp[1],$tmp[2]+$adder,$tmp[0]); return date("Y-m-d",$t); } // function day_to_ymd($date){ if(!$date) return; $tmp=explode("-",$date); $t=mktime(0,0,0,$tmp[1],$tmp[2]+$adder,$tmp[0]); return date("Y-m-d",$t); } //日期转化为time()格式 function day_to_time($date){ if(!$date) return; $tmp=explode(" ",$date); $date=explode("-",$tmp[0]); $time=explode(":",$tmp[1]); return mktime($time[0],$time[1],$time[2],$date[1],$date[2],$date[0]); } //日期转化为time()格式,时间为0:0:0 function day_to_time1($date){ if(!$date) return; $date=explode("-",$date); return mktime(0,0,0,$date[1],$date[2],$date[0]); } //日期转化为time()格式,时间为23:59:59 function day_to_time2($date){ $date=explode("-",$date); return mktime(23,59,59,$date[1],$date[2],$date[0]); } //计算天数 function count_day($date1,$date2){ if(!$date2) return 0; $Date_List_1=explode("-",$date1); $Date_List_2=explode("-",$date2); $d1=mktime(0,0,0,$Date_List_1[1],$Date_List_1[2],$Date_List_1[0]); $d2=mktime(0,0,0,$Date_List_2[1],$Date_List_2[2],$Date_List_2[0]); $days=round(($d2-$d1)/3600/24); return $days; } //日期转成yyyy-dd-mm格式 function deel_full_date($date){ $arr=explode("-",$date); $m=strlen($arr[1])>1?$arr[1]:"0".$arr[1]; $d=strlen($arr[2])>1?$arr[2]:"0".$arr[2]; return $arr[0]."-".$m."-".$d; } // function hb_date($date1,$date2){ $a1=explode("-",$date1); $a2=explode("-",$date2); if($date1==$date2){ $r=$a1[0]."年".$a1[1]."月".$a1[2]."日"; }else if($a1[0]==$a2[0]){ if($a1[1]==$a2[1]){ $r=$a1[0]."年".$a1[1]."月".$a1[2]."日-".$a2[2]."日"; }else{ $r=$a1[0]."年".$a1[1]."月".$a1[2]."日-".$a2[1]."月".$a2[2]."日"; } }else{ $r=$a1[0]."年".$a1[1]."月".$a1[2]."日-".$a2[0]."年".$a2[1]."月".$a2[2]."日"; } return $r; } // function deel_add_date($add_date){ $arr1=explode(" ",$add_date); $arr_d=explode("-",$arr1[0]); $arr_t=explode(":",$arr1[1]); return $arr_d[2]."日 ".$arr_t[0]."点".$arr_t[1]."分".$arr_t[2]."秒"; } //处理显示的金额方式 function deel_je_show($je){ if($je>=100000000){ $je=keep_float(($je/100000000),2)."亿"; }else if($je>=10000){ $je=keep_float(($je/10000),1)."万"; }else{ $je=$je; } return $je; } ///////////////////////////////////////////////////////权限相关 // function count_priv_channel($cid,$priv){ $p=explode(",",$priv); $count=0; for($i=0;$iquery($query); $i=0; while($msg=$db->fetch_array($res)){ $query1="select * from ".$table_pre."channel where path='0-".$msg["id"]."' order by ord"; $t=get_db_msg("select count(*) 'num' from ".$table_pre."channel where path='0-".$msg["id"]."'"); $t=$t["num"]; $r.="".$msg[title].""; $res1=$db->query($query1); $j=0; while($msg1=$db->fetch_array($res1)){ if(trim($msg1["priv"])!=""){ $r.="  ".$msg1["title"].":"; $a=explode(",",$msg1["priv"]); for($k=0;$k".get_main_value($arr_priv_tran,$a[$k]).""; } $r.="
"; }else{ $r.="  ".$msg1[title]."
"; } $j++; } $r.=""; $i++; } $r.=""; return $r; } // function print_form_priv1($priv=''){ global $arr_priv1; $check=explode(",",$priv); $r=""; $i=0; foreach($arr_priv1 as $k1 => $v1){ $r.="".$v1." "; $i++; } return $r; } //检查权限 function check_priv1($p,$priv){ $c=explode(",",$priv); if(in_array($p,$c)) return true; else return false; } // function deel_gang($str){ $str=str_replace("-","_",$str); return $str; } // function deel_0($str){ if($str==0 or $str=="0%") $str=""; return $str; } // function add_0($str){ if($str>0) $str=$str; else $str="0"; return $str; } // function deel_01($str){ $str=$str==""?"0":$str; return $str; } // function deel_td($str){ return $str?$str:" "; } // function split_priv_str($priv){ $tmp=explode(",",$priv); $r=array(); for($i=0;$iquery("insert into ".$table_pre."log (uid,ip,action,remark,sql_value,add_date) values ('".$uid."','".$ip."','".$action."','".$remark."','".mysql_escape_string($query)."','".time()."')"); } ///////////////////////////////////////////////////////可选类别 ////////////输出cate // function out_select_cate($form,$name,$width,$cate,$value=''){ global $db,$table_pre; $width1=$width+18; $width2=$width+2; $d_value=$value; $r="
"; return $r; } // function out_select_cate1($form,$name,$width,$cate,$value=''){ global $db,$table_pre; $width1=$width+18; $d_value=$value; $r=" "; return $r; } ////////////更新 function update_cate($cate,$value){ global $db,$table_pre; if(trim($value)){ $msg=get_db_msg("select count(*) 'num' from ".$table_pre."keyword where title='".$value."' and cate='".$cate."'"); if($msg[num]==0){ $tmp=get_db_msg("select max(ord) 'ord' from ".$table_pre."keyword where cate='".$cate."'"); $ord=$tmp[ord]+1; $db->query("insert into ".$table_pre."keyword (ord,cate,title) values ('".$ord."','".$cate."','".$value."')"); } } } // function update_keyword($cate,$value){ global $db,$table_pre; $value=trim($value); if(trim($value)){ $msg=get_db_msg("select count(*) 'num' from ".$table_pre."keyword where title='".$value."' and cate='".$cate."'"); if($msg["num"]==0){ $tmp=get_db_msg("select max(ord) 'ord' from ".$table_pre."keyword where cate='".$cate."'"); if($tmp["ord"]>10) $ord=$tmp[ord]+1; else $ord=11; $db->query("insert into ".$table_pre."keyword (ord,cate,no,title) values ('".$ord."','".$cate."','".$ord."','".$value."')"); } } } // function update_keyword_color($code,$title){ global $db,$table_pre; $title=trim($title); $code=trim($code); if($title && $code){ $msg=get_db_msg("select count(*) 'num' from ".$table_pre."keyword where title='".$title."' and no='".$code."' and cate='color'"); if($msg["num"]==0){ $tmp=get_db_msg("select max(ord) 'ord' from ".$table_pre."keyword where cate='color'"); if($tmp["ord"]>0) $ord=$tmp[ord]+1; else $ord=1; $db->query("insert into ".$table_pre."keyword (ord,cate,no,title) values ('".$ord."','color','".$code."','".$title."')"); } } } ////////////op // function op_select_cate($cate,$value=""){ global $db,$table_pre; $r=$db->query("select * from ".$table_pre."keyword where cate='".$cate."' order by no"); $op=""; while($m=$db->fetch_array($r)){ $op.="