";} } //頭相存放路徑 function CreatePicPathhead($Path,$id,$mLogin){ $DIR0 = $Path. "/" . substr($id,-1); if(!is_dir($DIR0)){ mkdir($DIR0); chmod($DIR0,0777);} $DIR3 = $DIR0. "/" . strtolower(substr($mLogin,0,1)); if(!is_dir($DIR3)){ mkdir($DIR3); chmod($DIR3,0777);} $DIR4 = $DIR3 . "/".strtolower(substr($mLogin,1,1)); if(!is_dir($DIR4)){ mkdir($DIR4); chmod($DIR4,0777);} $DIR5 = $DIR4 . "/".$mLogin; if(!is_dir($DIR5)){ mkdir($DIR5); chmod($DIR5,0777);} $DIR6 = $DIR5 . "/head"; if(!is_dir($DIR6)){ mkdir($DIR6); chmod($DIR6,0777);} return $DIR6; } //相本存放路徑 function CreatePicPath($Path,$id,$mLogin){ $DIR0 = $Path. "/" . substr($id,-1); if(!is_dir($DIR0)){ mkdir($DIR0); chmod($DIR0,0777);} $DIR1 = $DIR0. "/" . strtolower(substr($mLogin,0,1)); if(!is_dir($DIR1)){ mkdir($DIR1); chmod($DIR1,0777);} $DIR2 = $DIR1 . "/".strtolower(substr($mLogin,1,1)); if(!is_dir($DIR2)){ mkdir($DIR2); chmod($DIR2,0777);} $f_folder = $DIR2 . "/".$mLogin; if(!is_dir($f_folder)){ mkdir($f_folder); chmod($f_folder,0777);} return $f_folder; } //cookie 加密 function encryptCookie($value){ if(!$value){return false;} $key = 'The Line Uniwanna Key'; $text = $value; $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv); return trim(base64_encode($crypttext)); //encode for cookie } //cookie解密 function decryptCookie($value){ if(!$value){return false;} $key = 'The Line Uniwanna Key'; $crypttext = base64_decode($value); //decode cookie $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_ECB, $iv); return trim($decrypttext); } //cookie解陣列 function excryptCookie($value){ if(!$value){return false;} $key = 'The Line Uniwanna Key'; $crypttext = base64_decode($value); //decode cookie $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $decrypttext = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_ECB, $iv)); return explode('@!',$decrypttext); } //cookie解陣列 function excryptCookie_n($value,$num){ if(!$value){return false;} $key = 'The Line Uniwanna Key'; $crypttext = base64_decode($value); //decode cookie $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $decrypttext = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_ECB, $iv)); $string = explode('@!',$decrypttext); return $string[$num]; } function filesize_r($path){ if(!file_exists($path)) return 0; if(is_file($path)) return filesize($path); $self = __FUNCTION__; $ret = 0; foreach(glob($path."/*") as $fn) $ret += $self($fn); $ret = $ret/1024/1024; return number_format($ret,3,'.',''); } function roundsize($size){ $i=0; $iec = array("B", "Kb", "Mb", "Gb", "Tb"); while (($size/1024)>1) { $size=$size/1024; $i++;} return(round($size,1)." ".$iec[$i]);} //修正單引號及&或是"等字元 function fix_str($str){ if(isset($_POST[$str])){ $new_str = $_POST[$str]; }elseif(isset($_GET[$str])){ $new_str = $_GET[$str]; }else{ return false; } $newstr = addslashes(trim($new_str)); return $newstr; } function nowDate(){ echo date("Y-m-d"); } //java alert function javaAlert($str){ echo ' '; } function urlPage($url){ /*if(strpos($url,"?")){ $r = "&r=".rand(100,999);; }else{ $r = "?r=".rand(100,999);; }*/ $r=""; echo ' '; } function en_code($num){ $new_num = base64_encode($num); return $new_num; } function de_code($num){ $new_num = base64_decode($num); return $new_num; } function en_url(){ $tmp_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; if(substr($tmp_url,-6,3)=='?r='){ $url = str_replace(substr($tmp_url,-6),"",$tmp_url); }elseif(substr($tmp_url,-6,3)=='&r='){ $url = str_replace(substr($tmp_url,-6),"",$tmp_url); }else{ $url = $tmp_url; } return base64_encode($url); } function getPost($var){ $strPost = ""; if(isset($_GET[$var])){ $strPost = $_GET[$var]; }elseif(isset($_POST[$var])){ $strPost = $_POST[$var]; } //sql injection $b_valid = true; if (stripos( $strPost , 'insert') !== false) $b_valid = false; if (stripos( $strPost , 'delete') !== false) $b_valid = false; if (stripos( $strPost , 'drop') !== false) $b_valid = false; if (stripos( $strPost , 'update') !== false) $b_valid = false; if ( $b_valid == false ) { javaAlert('輸入的資料含有不予許字元!!!'); end(); }else{ return $strPost; } } //解決substr在unicode中亂碼的問題 function cut_str($string, $sublen, $start = 0, $code = 'UTF-8') { if($code == 'UTF-8') { $pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf]"; $pa .= "[\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|"; $pa .= "\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|"; $pa .= "[\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++; } if(strlen($tmpstr)<$strlen ) $tmpstr.= ".."; return $tmpstr; } } //分頁頁數判斷及處理 function define_page( $ori_page , $page_cnt ){ $page = 0; if($ori_page == ''){ $page = 1; }else{ $page = $ori_page; } if($page < 1) $page = 1; if($page >= $page_cnt) $page = $page_cnt; return $page; } //debug out function debug_o( $msg , $b){ if($b){ echo $msg.'
'; } } //讀取counter值 function counter_tostr( $obj_r ){ $counter = $obj_r->RMQ("select value from variables where name='counter'"); $digits=preg_split('//',$counter['value'],-1, PREG_SPLIT_NO_EMPTY); $counter_str = ''; foreach($digits as $digit){ $counter_str .= ""; } return $counter_str; } //menu hirachi function menu_hirachi_tostr ( $obj_r, $doc_id) { $arr = array(); $str = ''; $qt = '>'; $arr = menu_hirachi_recur( $obj_r, $doc_id, $arr); for($i = count($arr)-1; $i>=0; $i--){ $redir_page = ''; $sqt = $qt; if( $i == 0 ) $sqt = ''; if( $arr[$i]['level'] == 1 ){ $redir_page = 'doc_list.php'; $str .= ''.$arr[$i]['subject'].''.$sqt; }elseif($arr[$i]['level'] == 2){ $redir_page = 'doc_list.php'; $str .= ''.$arr[$i]['subject'].''.$sqt; }else{ $redir_page = 'doc_content.php'; $str .= ''.$arr[$i]['subject'].''.$sqt; } } $str = '首頁'.$qt.$str; echo $str; } function menu_hirachi_recur ( $obj_r, $doc_id, $arr) { $doc = $obj_r->RMQ("select * from doc_content where doc_id=$doc_id"); $arr = menu_array_push ( $arr, $doc['doc_id'], $doc['source_doc_id'], $doc['level'], $doc['doc_type'], $doc['subject'], $doc['menu_id']); if($doc['source_doc_id'] != 0){ $arr = menu_hirachi_recur ( $obj_r, $doc['source_doc_id'], $arr); } return $arr; } function menu_array_push ( $arr, $doc_id, $source_doc_id, $level, $doc_type, $subject, $menu_id) { $arr2 = array( "doc_id" => $doc_id, "source_doc_id" => $source_doc_id, "level" => $level, "doc_type" => $doc_type, "subject" => $subject, "menu_id" => $menu_id ); array_push ( $arr , $arr2); return $arr; } //取得使用者IP by DotNet@20110519 function userip(){ if (empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $uip = $_SERVER['REMOTE_ADDR']; } else { $uip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $uip = $uip[0]; } return $uip; }