iT邦幫忙

1

PHP 基本Basic 函式庫

  • 分享至 

  • twitterImage
  •  
<?php
/**
 * 個人函式庫
 *
 * //安全性使用, 過濾 $_POST, $_GET 等
 * EscapeData ($DataArray, $SPECIAL_ESCAPE = true)
 * 		參數1 : 資料, 須為 Array 型態
 * 		參數2 : 若不想限制使用一些 Script 或是 Object 等語法嵌入, 則使用 false, 就可以停止使用語法過濾
 * 
 * //圖片確認, 若不存在則用預設圖取代
 * Img ($IMG_URL, $Return = false)
 * 		參數1 : 圖片網址 (相對於整個網站的網址)
 * 		參數2 : 若為 false 則直接印出來, 若為 true 則回傳結果, 不印
 * 
 * //用來確認是否此選項有被勾選 or 選擇, 若 $option = $value 則會回傳 checked = 'checked'
 * CheckChoice ($type,$option,$value,$return=0)
 * 		參數1 : 類型, 僅支援 select, radio 或是 checkbox
 * 		參數2 : 選項的數值
 * 		參數3 : 已選擇的數值
 * 		參數4 : 若為 0 或 false 則直接印出回傳字串, 若為 1 或 true 則只是回傳, 不印出
 * 
 * //PHPExcel 用的, 以數字來取得欄位開頭英文, 起始為數字 0 , 會被轉成 A
 * ColumnAssign ($val)
 * 		參數1 : 從左由 0 開始, 往右邊數, 傳入數字, 會被轉換成 Excel 的英文欄位開頭
 * 
 * //驗證權限用, 確認是否擁有某個權限
 * AuthorityIdentifier($CurrentAuthority, $PermitAuthorityList, $ReturnType = "HTML")
 * 		參數1 : 目前的權限
 * 		參數2 : 目前可允許的權限
 * 		參數3 : 有 AJAX, FUNCTION, HTML 可選, 
 * 			AJAX 可用來處理 AJAX 的回傳, FUNCTION 則直接回傳狀態, HTML 則直接轉頁面
 * 		參數4 : 若為 0 或 false 則直接印出回傳字串, 若為 1 或 true 則只是回傳, 不印出	
 * 
 * //功能同上, 不同的是用來確認狀態
 * inStatus($CurrentStatus, $PermitStatusList, $ReturnType = "FUNCTION")
 * 
 * //取得使用者目前的 IP
 * getClientIP ()
 * 
 * //驗證 Email 是否符合規定
 * isEmail ($email)
 * 		參數1 : 輸入的EMAIL
 * 
 * //手機收件人列表驗證, 若不是 '09' 開頭, 長度不是 10 則會被認為非手機, 注意: 使用此函式需要兩個參數都加上 & [EX: GetContactArray (&$ContactList, &$ErrorContact)]
 * GetContactArray ($ContactList, $ErrorContact)
 * 		參數1 : 輸入的手機聯絡人列表
 * 		參數2 : 錯誤的聯絡人列表
 * 		
 * //判斷是否為Windows系統
 * isWindows ()
 * 
 * //測試取得的路徑是否正確
 * getAllPath ()
 * 
 * //印出錯誤訊息並且轉頁
 * MessageRedirect ($Message,$TargetPage)
 * 		參數1 : 要印出的訊息
 * 		參數2 : 目標位置, 為網址, 可用 back, return 回到上一頁, 或用 reflash, reload 重新整理頁面
 * 
 * //字數限制
 * WordLimit ($String , $Num = 100 , $HTML_LIMIT = true , $Code = "UTF-8")
 * 		參數1 : 需要判斷是否過長的字串
 * 		參數2 : 字數限制
 * 		參數3 : 是否取代空白, /n, /t 等, false 表示不消去
 * 		參數4 : 文字編碼, 預設為 UTF-8
 * 
 * //時間比較, 忘了怎麼用了
 * dateDiff ($startDate, $endDate)
 * 		參數1 : 需要判斷是否過長的字串
 * 		參數2 : 字數限制
 * 
 * //確認是否為手機開網頁
 * isMobile ()
 * 
 * //分析 Youtube 網址, 取得 Youtube ID
 * getYoutubeID ($STR)
 * 		參數1 : Youtube 網址
 * 
 * //印出字串, 換行正確並且空白也會按照原有格式來印出
 * pre ($Var)
 * 		參數1 : 變數
 * 
 * //是否存取過某頁面
 * ised ($PageName = "", $ID = 1)
 * 		參數1 : 頁面取名
 * 		參數2 : 頁面ID
 * 
 * //後端引用正確檔案使用
 * FunctionName () 
 *
 * //帳號格式確認 
 * AccountCheck ()
 * 
 * //Facebook META 設定使用
 * 要注意要設定幾個變數, 請直接看函式
 * FacebookMeta ()
 * 
 * Basic_File.php 檔案相關
 *
 */
 	function _autoload ($LoadClassName) {
		if (is_file(BASE_PATH . 'require/class/' . $LoadClassName . '.php')) {
			require (BASE_PATH . 'require/class/' . $LoadClassName . '.php') ;
			
		} else if (is_file(BASE_PATH . 'require/tools/' . $LoadClassName . '/' . $LoadClassName . '.php')) {
			require (BASE_PATH . 'require/tools/' . $LoadClassName . '/' . $LoadClassName . '.php') ;

		} else if (is_file(BASE_PATH . 'require/tools/' . $LoadClassName . '/class.' . $LoadClassName . '.php')) {
			require (BASE_PATH . 'require/tools/' . $LoadClassName . '/class.' . $LoadClassName . '.php') ;
			
		} else {
			if ($DebugMode) echo 'Can Not Load Class: ' . $LoadClassName ;
		}
	}

	if(!function_exists('json_encode')) {
		@include(BASE_PATH . 'require/tools/JSON/JSON.php');
		function json_encode($val)
		{
			$json = new Services_JSON();
			return $json->encode($val);
		}
	
		function json_decode($val)
		{
			$json = new Services_JSON();
			return $json->decode($val);
		}
	}
	
	function EscapeData_Admin ($DataArray, $SPECIAL_ESCAPE = true, $HTML_STRIP = false) {
		$FindTarget = array(
										"<html",
										"</html",
										"<body",
										"</body",
										) ;
		$ReplaceTarget = array(
										"<html",
										"</html",
										"<body",
										"</body",
										) ;
		
		//若僅有一字串, 則直接處理
		if (!is_array($DataArray)) {
			$v = trim($DataArray) ;
			$v = get_magic_quotes_gpc() ? stripslashes($v) : $v;
			
			if ($HTML_STRIP) {
				$v = strip_tags($v) ;
			}
			
			$v = mysql_escape($v);
			
			return $v ;
		}
		
		//若為一 Array 則針對每個數值處理
		foreach ($DataArray as $k => $v) {
			if (is_array($v)) {
				$DataArray[$k] = EscapeData_Admin ($v, $SPECIAL_ESCAPE, $HTML_STRIP) ;
				
			} else {
				$v = trim($v) ;

				if ($HTML_STRIP) {
					$v = strip_tags($v) ;
				}
			
				$v = get_magic_quotes_gpc() ? stripslashes($v) : $v;
				$v = mysql_escape($v);
				
				if (is_bool($SPECIAL_ESCAPE) && $SPECIAL_ESCAPE == false) {
				} else {
					if (is_array($SPECIAL_ESCAPE) && in_array($k,$SPECIAL_ESCAPE)) {
					} else {
						$v = str_ireplace($FindTarget,$ReplaceTarget,$v) ;
					}
				}
				
				$DataArray[$k] = $v ;
				
			}
		}
		
		return $DataArray ;
	}
	
	function EscapeData_User ($DataArray, $SPECIAL_ESCAPE = true, $HTML_STRIP = false) {
		$FindTarget = array(
										"onclick",
										"ondblclick",
										"onmousedown",
										"onmouseup",
										"onmouseover",
										"onmousemove",
										"onmouseout",
										"onkeypress",
										"onkeydown",
										"onkeyup",
										"onabort",
										"onbeforeunload",
										"onerror",
										"onload",
										"onmove",
										"onresize",
										"onscroll",
										"onstop",
										"onunload",
										"onblur",
										"onchange",
										"onfocus",
										"onreset",
										"onsubmit",
										"onbounce",
										"onfinish",
										"onstart",
										"onbeforecopy",
										"onbeforecut",
										"onbeforeeditfocus",
										"onbeforepaste",
										"onbeforeupdate",
										"oncontextmenu",
										"oncopy",
										"oncut",
										"ondrag",
										"ondragdrop",
										"ondragend",
										"ondragenter",
										"ondragleave",
										"ondragover",
										"ondragstart",
										"ondrop",
										"onlosecapture",
										"onpaste",
										"onselect",
										"onselectstart",
										"onafterupdate",
										"oncellchange",
										"ondataavailable",
										"ondatasetchanged",
										"ondatasetcomplete",
										"onerrorupdate",
										"onrowenter",
										"onrowexit",
										"onrowsdelete",
										"onrowsinserted",
										"onafterprint",
										"onbeforeprint",
										"onfilterchange",
										"onhelp",
										"onpropertychange",
										"onreadystatechange",
										"<link",
										"</link",
										"<iframe",
										"</iframe",
										"<object",
										"</object",
										"<script",
										"</script",
										"<embed",
										"</embed",
										"<html",
										"</html",
										"<body",
										"</body",
										) ;
		$ReplaceTarget = array(
										"0nclick",
										"0ndblclick",
										"0nmousedown",
										"0nmouseup",
										"0nmouseover",
										"0nmousemove",
										"0nmouseout",
										"0nkeypress",
										"0nkeydown",
										"0nkeyup",
										"0nabort",
										"0nbeforeunload",
										"0nerror",
										"0nload",
										"0nmove",
										"0nresize",
										"0nscroll",
										"0nstop",
										"0nunload",
										"0nblur",
										"0nchange",
										"0nfocus",
										"0nreset",
										"0nsubmit",
										"0nbounce",
										"0nfinish",
										"0nstart",
										"0nbeforecopy",
										"0nbeforecut",
										"0nbeforeeditfocus",
										"0nbeforepaste",
										"0nbeforeupdate",
										"0ncontextmenu",
										"0ncopy",
										"0ncut",
										"0ndrag",
										"0ndragdrop",
										"0ndragend",
										"0ndragenter",
										"0ndragleave",
										"0ndragover",
										"0ndragstart",
										"0ndrop",
										"0nlosecapture",
										"0npaste",
										"0nselect",
										"0nselectstart",
										"0nafterupdate",
										"0ncellchange",
										"0ndataavailable",
										"0ndatasetchanged",
										"0ndatasetcomplete",
										"0nerrorupdate",
										"0nrowenter",
										"0nrowexit",
										"0nrowsdelete",
										"0nrowsinserted",
										"0nafterprint",
										"0nbeforeprint",
										"0nfilterchange",
										"0nhelp",
										"0npropertychange",
										"0nreadystatechange",
										"<link",
										"</link",
										"<iframe",
										"</iframe",
										"<object",
										"</object",
										"<script",
										"</script",
										"<embed",
										"</embed",
										"<html",
										"</html",
										"<body",
										"</body",
										) ;
		
		//若僅有一字串, 則直接處理
		if (!is_array($DataArray)) {
			$v = trim($DataArray) ;
			$v = get_magic_quotes_gpc() ? stripslashes($v) : $v;
			
			if ($HTML_STRIP) {
				$v = strip_tags($v) ;
			}
			
			$v = mysql_escape($v);
			
			return $v ;
		}
		
		//若為一 Array 則針對每個數值處理
		foreach ($DataArray as $k => $v) {
			if (is_array($v)) {
				$DataArray[$k] = EscapeData_User($v, $SPECIAL_ESCAPE, $HTML_STRIP);
				
			} else {
				$v = trim($v) ;

				if ($HTML_STRIP) {
					$v = strip_tags($v) ;
				}
			
				$v = get_magic_quotes_gpc() ? stripslashes($v) : $v;
				$v = mysql_escape($v);
				
				if (is_bool($SPECIAL_ESCAPE) && $SPECIAL_ESCAPE == false) {
				} else {
					if (is_array($SPECIAL_ESCAPE) && in_array($k,$SPECIAL_ESCAPE)) {
					} else {
						$v = str_ireplace($FindTarget,$ReplaceTarget,$v) ;
					}
				}
				
				$DataArray[$k] = $v ;
				
			}
		}
		
		return $DataArray ;
	}
	
	function Img ($IMG_URL, $Return = false) {
		global $_CONFIG ;
		$DefaultImage = $_CONFIG['DEFAULT_PATH_NOIMAGE'] ;

		$IMG_URL = mb_convert_encoding($IMG_URL, "BIG5", "UTF-8") ;
		
		if (strstr($IMG_URL,"http://")) {
			if ($Return == true) return true ;
			echo $IMG_URL ;
		} else if (is_file(BASE_PATH . $IMG_URL)) {
			$IMG_URL = mb_convert_encoding($IMG_URL, "UTF-8", "BIG5") ;

			if ($Return == true) return BASE_URL . $IMG_URL ;
			echo BASE_URL . $IMG_URL ;
			
		} else {
			if ($Return == true) return false ;
			echo BASE_URL . $DefaultImage ;
		}
	}
	
	function CheckChoice($type,$option,$value,$return=0) {
		$bool = false ;
		$return_val = "" ;
		$type = strtolower($type) ;
		
		if ($option == $value) $bool = true ;
		
		if ($bool)
		switch ($type) {
			case "select" :
				$return_val = "selected='seleced'" ;
				break ;
			case "radio" :
			case "checkbox" :
				$return_val = "checked='checked'" ;
				break ;
		}
		
		if ($return) 
			return $return_val ;
		else
			echo $return_val ;
	}

	//PHPExcel 資料匯出用
	function ColumnAssign($val) {
		$ColumnName = "" ;
		$ColumnTitle = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
		$val = $val + 0 ;
		
		if ($val <= 0) return 'A' ;
		$mul = $val ;
		
		while ($mul > 0) {
			$mod = ($mul-1) % 26 ;
			
			if ($mul > 26)
				$mul = floor(($mul-1) / 26) ;
			else
				$mul = 0 ;
			
			$ColumnName .= $ColumnTitle[$mod] ;
		}
		
		return strrev($ColumnName) ;
	}
	
	function AuthorityIdentifier($CurrentAuthority, $PermitAuthorityList, $ReturnType = "HTML") {
		
		$Permission = false ;
		
		if (is_array($PermitAuthorityList)) {
			
			if (in_array($CurrentAuthority, $PermitAuthorityList)) {
				
				$Permission = true ;
				
			} else if (isset($PermitAuthorityList) && $PermitAuthorityList != "") {
				
				if ($PermitAuthorityList == $CurrentAuthority) {
					
					$Permission = true ;
					
				}
				
			}
			
		}
		
		$ReturnType = strtoupper($ReturnType) ;
		
		switch ($ReturnType) {
			
			case "AJAX" :
			
				if (!$Permission) {
					
					$ReturnData = array() ;
					
					$ReturnData['status'] = "stay" ;
					
					$ReturnData['msg'] = "抱歉, 您沒有使用的權限 !!\n\n請確認您是否已登入, 或是您沒有使用此功能的權限 !" ;
					
					exit(json_encode($ReturnData)) ;
		
				}
				
				break ;
				
			case "FUNCTION" ;
			
				return $Permission ;
				
				exit() ;
				
			case "HTML" :
			
				if (!$Permission) {
					
					header("Location: ./") ;
					
					exit() ;
					
				}
				
				break ;
				
			default :
			
				exit() ;
				
		}
		
	}
	
	function inStatus($CurrentStatus, $PermitStatusList, $ReturnType = "FUNCTION") {
		
		$Permission = false ;
		
		if (is_array($PermitStatusList)) {
			
			if (in_array($CurrentStatus, $PermitStatusList)) {
				
				$Permission = true ;
				
			} else if (isset($PermitStatusList) && $PermitStatusList != "") {
				
				if ($PermitStatusList == $CurrentStatus) {
					
					$Permission = true ;
					
				}
				
			}
			
		}
		
		$ReturnType = strtoupper($ReturnType) ;
		
		switch ($ReturnType) {
			
			case "AJAX" :
			
				if (!$Permission) {
					
					$ReturnData = array() ;
					
					$ReturnData['status'] = "stay" ;
					
					$ReturnData['msg'] = "抱歉, 您沒有存取此資料的權限 !" ;
					
					exit(json_encode($ReturnData)) ;
					
				}
				
				break ;
				
			case "FUNCTION" ;
			
				return $Permission ;
				
				exit() ;
				
			case "HTML" :
				
				if (!$Permission) {
					
					header("Location: ./") ;
					
					exit() ;
					
				}
			
				break ;
				
			default :
			
				exit() ;
				
		}
		
	}
	
	function getClientIP () {
		if (empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
		$myip = $_SERVER['REMOTE_ADDR'];
		} else {
		$myip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
		$myip = $myip[0];
		}
		return $myip;
	}
	
	function isEmail($email) {
		$email = strtolower($email) ;
		if (preg_match('/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/', $email))
			return true;
		else
			return false;
	}	
	
	function GetContactArray($ContactList, $ErrorContact) {
		//需要字串型態的收件人列表
		$ContactList = explode(",",$ContactList) ;
		$TmpContact = array() ;
		$ErrorContact = array() ;
		foreach ($ContactList as $i => $v) {
			$v = str_replace(array("-","#","ext","."),"",trim($v)) ;
			
			if ($v != "") {
				if (preg_match("/09[0-9]{8}$/",$v)) {
					array_push($TmpContact,$v) ;
				} else {
					array_push($ErrorContact,$v) ;
				}
			}
		}
		
		$ContactList = $TmpContact ;
		$ErrorContact = $ErrorContact ;
	}
	
	function isWindows () {
		if (strtoupper(substr(PHP_OS,0,3)) == "WIN") return true ;
		else false ;
	}
	
	function getAllPath () {
		echo "
		<style>
			.PathInfoTable {
				width: 600px;
				text-align: left;
			}
			.PathInfoTable th {
				width: 150px;
				border: 1px solid #CCC;
				padding: 2px 5px;
				background: #F5F5F5;
			}
			.PathInfoTable td {
				border-bottom: 1px solid #CCC;
				padding: 2px 5px;
			}
		</style>
		<table Class='PathInfoTable'>
			<tr><th>DOCUMENT_ROOT</th><td>" . $_SERVER['DOCUMENT_ROOT'] . "</td></tr>
			<tr><th>BASE_PATH</th><td>" . BASE_PATH . "</td></tr>
			<tr><th>CURRENT_PATH</th><td>" . CURRENT_PATH . "</td></tr>
			<tr><th>BASE_URL</th><td>" . BASE_URL . "</td></tr>
			<tr><th>URL</th><td>" . URL . "</td></tr>
			<tr><th>DOMAIN_URL</th><td>" . DOMAIN_URL . "</td></tr>
		</table>" ;
	}
	
	function MessageRedirect($Message,$TargetPage) {
		$Message = mysql_escape($Message) ;
		$Page = 'window.location = \'' . $TargetPage . '\' ;' ;
		if ($TargetPage == "back" || $TargetPage == "return") $Page = 'if (history.length > 1) history.back(-1) ; else window.location = "' . URL . '" ;' ;
		if ($TargetPage == "close") $Page = 'window.close() ;' ;
		if ($TargetPage == "reflash" || $TargetPage == "reload") $Page = 'window.location.reload() ;' ;
		
		//方式 1
		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml">
				<head>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
				<title>訊息</title>
				<script type="text/javascript">
					' . $Page . '
					alert(\'' . $Message . '\') ;
				</script>
				</head>
				<body style="background: white;">&nbsp;</body>
				</html>' ;
		
		//方式 2
		/*
		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml">
				<head>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
				<script src="' . BASE_URL . 'require/tools/jquery.js"></script>
				<script src="' . BASE_URL . 'require/tools/jquery.blockUI.js"></script>
				<title>訊息</title>
				<script type="text/javascript">
					$(function () {
						$.blockUI({ 
							css: { 
								border: "none", 
								padding: "15px", 
								backgroundColor: "#FFF", 
								"-webkit-border-radius": "3px", 
								"-moz-border-radius": "3px", 
								opacity: 1, 
								color: "#333" 
							},
							message: "' . $Message . '"
						}) ;
						
						setTimeout("Action()",' . ($WaitTime * 1000) . ') ;
					}) ;
					
					function Action() {
						' . $Page . '
					}
				</script>
				</head>
				<body style="background: #CCC;"></body>
				</html>' ;
		*/
		exit() ;
	}

	function WordLimit ($String , $Num = 100 , $HTML_LIMIT = true , $EndAppend = " ..." , $Code = "UTF-8") {
		
		if (is_string($HTML_LIMIT)) {
			$String = str_replace(array("  ","\t","\r"),"",strip_tags($String,$HTML_LIMIT)) ;
		} else if ($HTML_LIMIT == false) {
			//不動
		} else if ($HTML_LIMIT == true) {
			//替換特殊字或多空格者
			$String = str_replace(array("  ","\t","\r"),"",strip_tags($String,"")) ;
		}
		
		$ASCII= array(1		=> 0.0, 2		=> 0.0, 3		=> 0.0, 4		=> 0.0, 5		=> 0.0, 6		=> 0.0, 7		=> 0.0, 8		=> 0.0,	 9	=> 0.0, 10	=> 0.0, 
								11	=> 0.0, 12	=> 0.0, 13	=> 0.0, 14	=> 0.0, 15	=> 0.0, 16	=> 0.0, 17	=> 0.0, 18	=> 0.0, 19	=> 0.0, 20	=> 0.0, 
								21	=> 0.0, 22	=> 0.0, 23	=> 0.0, 24	=> 0.0, 25	=> 0.0, 26	=> 0.0, 27	=> 0.0, 28	=> 0.0, 29	=> 0.0, 30	=> 0.0, 
								31	=> 0.0, 32	=> 0.0, 33	=> 0.3, 34	=> 0.3, 35	=> 0.6, 36	=> 0.5, 37	=> 0.9, 38	=> 0.7, 39	=> 0.2, 40	=> 0.3, 
								41	=> 0.3, 42	=> 0.3, 43	=> 0.3, 44	=> 0.3, 45	=> 0.3, 46	=> 0.3, 47	=> 0.3, 48	=> 0.55, 49	=> 0.55, 50	=> 0.55, 
								51	=> 0.55, 52	=> 0.55, 53	=> 0.55, 54	=> 0.55, 55	=> 0.55, 56	=> 0.55, 57	=> 0.55, 58	=> 0.6, 59	=> 0.6, 60	=> 0.6, 
								61	=> 0.6, 62	=> 0.6, 63	=> 0.6, 64	=> 0.6, 65	=> 0.65, 66	=> 0.65, 67	=> 0.65, 68	=> 0.65, 69	=> 0.65, 70	=> 0.65, 
								71	=> 0.65, 72	=> 0.65, 73	=> 0.3, 74	=> 0.3, 75	=> 0.65, 76	=> 0.65, 77	=> 0.65, 78	=> 0.65, 79	=> 0.65, 80	=> 0.65, 
								81	=> 0.65, 82	=> 0.65, 83	=> 0.65, 84	=> 0.65, 85	=> 0.65, 86	=> 0.65, 87	=> 0.65, 88	=> 0.65, 89	=> 0.65, 90	=> 0.65, 
								91	=> 0.6, 92	=> 0.6, 93	=> 0.6, 94	=> 0.6, 95	=> 0.6, 96	=> 0.6, 97	=> 0.6, 98	=> 0.6, 99	=> 0.6, 100	=> 0.6, 
								101	=> 0.6, 102	=> 0.6, 103	=> 0.6, 104	=> 0.6, 105	=> 0.6, 106	=> 0.6, 107	=> 0.6, 108	=> 0.6, 109	=> 0.6, 110	=> 0.6, 
								111	=> 0.6, 112	=> 0.6, 113	=> 0.6, 114	=> 0.6, 115	=> 0.6, 116	=> 0.6, 117	=> 0.6, 118	=> 0.6, 119	=> 0.6, 120	=> 0.6, 
								121	=> 0.6, 122	=> 0.6, 123	=> 0.6, 124	=> 0.6, 125	=> 0.6, 126	=> 0.6, 127	=> 0.6) ;
		
		$WordCounter = 0 ;
		$ReturnStr = "" ;
		$STR_LENGTH = mb_strlen($String,$Code) ;
		for ($CurrentPosition = 0 ; $CurrentPosition < $STR_LENGTH ; $CurrentPosition++) {
			$Word = mb_substr($String,$CurrentPosition,1,$Code) ;
			
			$WordOrd = ord($Word) ;
			
			if ($WordOrd < 32) continue ;
			$ReturnStr .= $Word ;
			
			if ($WordOrd < 128) {
				$WordCounter += $ASCII[$WordOrd] ;
			} else {
				$WordCounter++ ;
			}
			
			if ($WordCounter >= $Num) break ;
		}
		
		return $CurrentPosition < $STR_LENGTH ? $ReturnStr . $EndAppend : $String ;
	}

	function WordLimit2($string, $length, $dot = ' ...') {
		if(strlen($string) <= $length) {
			return $string;
		}
	
		$pre = chr(1);
		$end = chr(1);
		$string = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array($pre.'&'.$end, $pre.'"'.$end, $pre.'<'.$end, $pre.'>'.$end), $string);
	
		$strcut = '';
		$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);
	
		$strcut = str_replace(array($pre.'&'.$end, $pre.'"'.$end, $pre.'<'.$end, $pre.'>'.$end), array('&amp;', '&quot;', '&lt;', '&gt;'), $strcut);
	
		$pos = strrpos($strcut, chr(1));
		if($pos !== false) {
			$strcut = substr($strcut,0,$pos);
		}
		return $strcut.$dot;
	}
	
	function dateDiff ($startDate, $endDate) { 
		$startDate = strtotime($startDate); 
		$endDate = strtotime($endDate); 
		if ($startDate === false || $startDate < 0 || $endDate === false || $endDate < 0 || $startDate > $endDate) 
			return false; 
		
		$years = date('Y', $endDate) - date('Y', $startDate); 
		
		$endMonth = date('m', $endDate); 
		$startMonth = date('m', $startDate); 
		
		// Calculate months 
		$months = $endMonth - $startMonth; 
		if ($months <= 0)  { 
			$months += 12; 
			$years--; 
		} 
		if ($years < 0) 
			return false; 
		
		// Calculate the days 
		$offsets = array(); 
		if ($years > 0) 
			$offsets[] = $years . (($years == 1) ? ' year' : ' years'); 
		if ($months > 0) 
			$offsets[] = $months . (($months == 1) ? ' month' : ' months'); 
		$offsets = count($offsets) > 0 ? '+' . implode(' ', $offsets) : 'now'; 

		$days = $endDate - strtotime($offsets, $startDate); 
		$days = date('z', $days);    
					
		return array(
					0 => $years,
					1 => $months,
					2 => $days,
					"year" => $years,
					"month" => $months,
					"day" => $days,
				); 
	}

	
	function isMobile(){
		$useragent=isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:"";
		$useragent_commentsblock=preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:"";
		
		function CheckSubstrs($substrs,$text) {
			foreach($substrs as $substr)
				if(false!==strpos($text,$substr)) return true;
			
			return false;
		}
		
		$mobile_os_list=array('Google Wireless Transcoder','Windows CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera Mobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');
		
		$mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');
		
		$found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock) ||
		CheckSubstrs($mobile_token_list,$useragent);
		
		if ($found_mobile) return true;
		else return false;
	}
	
	function getYoutubeID ($STR) {
		preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#",$STR,$matches);
		//echo $STR . "<BR />" ;
		//print_r($matches) ;
		$VideoID = $matches[0] ;
		
		if ($VideoID == "" || strlen($VideoID) < 11) {
			preg_match('/embed\/([0-9a-z_-]+)(&|$|=|"|\?)/si',$STR,$matches);
			//echo $STR . "<BR />" ;
			//print_r($matches) ;
			$VideoID = $matches[1] ;
		}
		
		return $VideoID ;
	}
	
	function pre ($Var, $EXIT = false) {
		echo "<pre>" ;
		print_r($Var) ;
		echo "</pre><BR /><BR />" ;
		
		if ($EXIT) exit () ;
	}
	
	function ised($PageName = "", $ID = 1) {
		if (!$PageName) return true ;
		
		if (empty($_SESSION['ED'][$PageName][$ID]) || $_SESSION['ED'][$PageName][$ID] == false || $_SESSION['ED'][$PageName][$ID] == "") {
			$_SESSION['ED'][$PageName][$ID] = true ;
			return false ;
		} else {
			return true ;
		}
	}

	function FunctionName() {
		$SCRIPT_FILENAME = str_replace("\\", "/", $_SERVER['SCRIPT_FILENAME']) ;
		$SCRIPT_FILENAME = substr($SCRIPT_FILENAME, 0, strrpos($SCRIPT_FILENAME,"/")) ;
		$SCRIPT_FILENAME = substr($SCRIPT_FILENAME, strrpos($SCRIPT_FILENAME,"/")+1) ;
		
		return $SCRIPT_FILENAME ;
	}
	
	function AccountCheck($ACCOUNT_ID) {
		
		$Result = preg_match('/^[a-z_A-Z0-9\-]{6,12}+$/', $ACCOUNT_ID) ;
		
		if ($Result == 1) {
			//英文數字個要有一個以上
			
			//第一個字必須是英文
			//if (preg_match('/^[a-zA-Z]{1}[^a-zA-Z]*[a-zA-Z]{1,}+/', $ACCOUNT_ID) == 1 && preg_match('/[0-9]{1,}+/', $ACCOUNT_ID) == 1)
			if (preg_match('/[a-zA-Z]{1,}+/', $ACCOUNT_ID) == 1 && preg_match('/[0-9]{1,}+/', $ACCOUNT_ID) == 1)
				return true ;
			
		}
		
		return false ;
	}
	
	function FacebookMeta2($Title = "", $Description = "", $Img = "", $URL = "", $Type = "article") {
		$MetaInfo = "" ;
		
		if ($Type) 
			$MetaInfo .= '<meta property="og:type" content="' . $Type . '" />' . "\n" ;
		
		if ($Title) 
			$MetaInfo .= '<meta property="og:title" content="' . $Title . '" />' . "\n" ;
		
		if ($Img) {
			$MetaInfo .= '<meta property="og:image" content="' . DOMAIN_URL . Img($Img, true) . '" />' . "\n" ;
			$MetaInfo .= '<link rel="image_src" href="' . DOMAIN_URL . Img($Img, true) . '" />' . "\n" ;
		}
		
		if ($Description)
			$MetaInfo .= '<meta property="og:description" content="' . WordLimit($Description,200) . '" />' . "\n" ;
		
		if ($URL)
			$MetaInfo .= '<meta property="og:url" content="' . URL . $URL . '" />' . "\n" ;
		else
			$MetaInfo .= '<meta property="og:url" content="' . URL . '" />' . "\n" ;
		
		return $MetaInfo ;
	}
	
	/*
		$FacebookMeta['TYPE'] = "" ;
		$FacebookMeta['TITLE'] = $Info['n_title'] . " - " . $WebConfig["conf_site_title"] ;
		$FacebookMeta['DESC'] = WordLimit($Info['n_content'],150) ;
		$FacebookMeta['URL'] = "exhibition/{$ID}/" ;
		$FacebookMeta['IMG'] = $Info['n_img'] ;
		$FacebookMeta['KEYWORD'] = $Info['n_keyword'] ;
	*/
	function FacebookMeta() {
		global $FacebookMeta, $WebConfig ;
		
		$ExtMeta = '' ;
		if ($FacebookMeta) {
			$ExtMeta .= '' ;
			
			foreach ($FacebookMeta as $k => $v) $FacebookMeta[$k] = str_replace("\n", ' ', $v) ;
			
			if ($FacebookMeta['TYPE']) {
				$ExtMeta .= '<meta property="og:type" content="' . $FacebookMeta['TYPE'] . '"/>' . "\r\n" ;
			} else {
				$ExtMeta .= '<meta property="og:type" content="article" />' . "\r\n" ;
			}
			
			if ($FacebookMeta['URL']) {
				$ExtMeta .= '<meta property="og:url" content="' . URL . $FacebookMeta['URL'] . '"/>' . "\r\n" ;
			} else {
				$ExtMeta .= '<meta property="og:url" content="' . URL . '"/>' . "\r\n" ;
			}
			
			if ($FacebookMeta['TITLE']) {
				$ExtMeta .= '<meta property="og:title" content="' . $FacebookMeta['TITLE'] . '"/>' . "\r\n" ;
			}
			
			if ($FacebookMeta['DESC']) {
				$ExtMeta .= '<meta property="og:description" content="' . $FacebookMeta['DESC'] . '"/>' . "\r\n" ;
			}
			
			if ($FacebookMeta['IMG']) {
				$ExtMeta .= '<meta property="og:image" content="' . DOMAIN_URL . Img($FacebookMeta['IMG'], true) . '"/>' . "\r\n" ;
				$ExtMeta .= '<link rel="image_src" href="' . DOMAIN_URL . Img($FacebookMeta['IMG'], true) . '" />' . "\r\n" ;
			}
		}

		return $ExtMeta ;
	}
	
	function TextField($String) {
		return str_replace('"','&quot;',$String) ;
	}
		
	function SetSortTitle($ColTitle, $ColName) {
		$SortTitle = '<a class="SortableTitle" href="' . $_SERVER['PHP_SELF'] . '?' . getQuery(array('SORTT','SORTD')) . '&SORTT=' . $ColName . '&SORTD=' . ($_GET['SORTD'] == 1 ? "2" : "1") . '">' . $ColTitle ;
		
		if ($_GET['SORTT'] == $ColName)
			$SortTitle .= '<img src="../../images/global/' . ($_GET['SORTD'] == 1 ? "up" : "down") . '.png" align="absmiddle">' ;
		
		$SortTitle .= '</a>' ;
		
		return $SortTitle ;
	}
	
	function GetSortString($HasSortSQL) {
		global $_GET ;
		
		$SORT_STR = "" ;
		
		$_GET['SORTT'] = mysql_escape(trim($_GET['SORTT'])) ;
		$_GET['SORTD'] = mysql_escape(trim($_GET['SORTD'])) ;
		
		if ($_GET['SORTT'] != "") {
			$SORT_STR = " " . $_GET['SORTT'] . " " . ($_GET['SORTD'] == 1 ? "ASC" : "DESC") . ($HasSortSQL ? ", " : " ") ;
		}
		
		return $SORT_STR ;
	}
	
	
	function getNum($MainType = "", $SubType = "", $TargetID = 0, $Range = "") {
		global $DB ;
		
		$MainType = strtoupper($MainType) ;
		$SubType = strtoupper($SubType) ;
		$Range = strtoupper($Range) ;
		
		$TargetID += 0 ;
		
		//每次取得瀏覽數都要檢查今日瀏覽人數
		if ($_SESSION['']['TODAY'] != date("Y-m-d")) {
			$SQL = "SELECT * FROM or WHERE vt_main_target = 'DAILY' and vt_date = '" . date("Y-m-d") . "' and vt_type = '' LIMIT 1 " ;
			$Num = $DB->query($SQL,1) ;
			
			if ($Num) {
				$SQL = "UPDATE or SET mvt_num = mvt_num + 1 WHERE vt_main_target = 'DAILY' and mvt_date = '" . date("Y-m-d") . "' and mvt_type = 'TODAY' " ;
				$DB->query($SQL,0) ;
			} else {
				$SQL = "INSERT INTO or (vt_main_target,mvt_date,mvt_type,mvt_num,mvt_id) VALUES ('DAILY','" . date("Y-m-d") . "','TODAY',1,'') " ;
				$DB->query($SQL,0) ;
			}
			$_SESSION['']['TODAY'] = date("Y-m-d") ;
			
			//if ($QueryType == "TODAY" && $Range == "") return ($Num['mvt_num']+1) ;
		}
		
		if (!$MainType) return false ;
		
		//其他種類瀏覽人數統計檢查
		if ($QueryType != "TODAY" && $_SESSION[''][$QueryType]["Query".$TargetID] != date("Y-m-d")) {
			$SQL = "SELECT * FROM or WHERE vt_main_target = '{$MainTarget}' and mvt_date = '" . date("Y-m-d") . "' and mvt_type = '{$QueryType}' and mvt_id = '{$TargetID}' LIMIT 1 " ;
			$Num = $DB->query($SQL,1) ;
			
			if ($Num) {
				$SQL = "UPDATE or SET mvt_num = mvt_num + 1 WHERE vt_main_target = '{$MainTarget}' and mvt_date = '" . date("Y-m-d") . "' and mvt_type = '{$QueryType}' and mvt_id = '{$TargetID}' " ;
				$DB->query($SQL,0) ;
			} else {
				$SQL = "INSERT INTO or (vt_main_target,mvt_date,mvt_type,mvt_num,mvt_id) VALUES ('{$MainTarget}','" . date("Y-m-d") . "','{$QueryType}',1,'{$TargetID}') " ;
				$DB->query($SQL,0) ;
			}
			$_SESSION[''][$QueryType]["Query".$TargetID] = date("Y-m-d") ;
			
			if ($Range == "") return ($Num['mvt_num']+1) ;
		}
		
		//最後確認是要取總數還是要取今日的人數
		if ($Range == "ALL") {
			$SQL = "SELECT SUM(mvt_num) as mvt_num FROM or WHERE vt_main_target = '{$MainTarget}' and mvt_type = '{$QueryType}' and mvt_id = '{$TargetID}' " ;
		} else {
			$SQL = "SELECT * FROM or WHERE vt_main_target = '{$MainTarget}' and mvt_date = '" . date("Y-m-d") . "' and mvt_type = '{$QueryType}' and mvt_id = '{$TargetID}' LIMIT 1 " ;
		}
					
		$Num = $DB->query($SQL,1) ;
		
		return ($Num['mvt_num']+0) ;
	}

	function isUFT8($Str) {
		if (mb_convert_encoding($Str,"UTF8","UTF8") == $Str)
			return true ;
		else
			return false ;
	}
	
	function Loc($WebSite) {
		header("Location: " . $WebSite) ;
		exit() ;
	}
	
	function isVisited($TableName, $DataID) {
		if ($_SESSION['Dataisited' . $TableName][$DataID]) {
			return true;
		} else {
			$_SESSION['Dataisited' . $TableName][$DataID] = true;
			return false;
		}
	}
	
	function getOnlineNum($Type = "USER") {
		global $DB ;
		
		$Type = mysql_escape($Type) ;
		
		$SQL = "SELECT count(*) as num FROM sys_log WHERE log_type = 'ONLINE_USER' and log_id = '{$Type}' " ;
		$OnlineNum = $DB->query($SQL, 1) ;
		$OnlineNum = $OnlineNum['num'] + 0 ;

		return $OnlineNum ;
	}
	
	function BR_Convert ($Text) {
		if (strstr($Text, "\\r\\n")) {
			$Text = str_replace(array("\\r\\n", "\\n"), array("<BR />", "<BR />"), $Text) ;
		} else {
			$Text = nl2br($Text) ;
		}
		
		return $Text ;
	}
	
	function SizeCount($size) {
		if($size >= 1073741824) {
			$size = round($size / 1073741824 * 100) / 100 . ' GB';
		} elseif($size >= 1048576) {
			$size = round($size / 1048576 * 100) / 100 . ' MB';
		} elseif($size >= 1024) {
			$size = round($size / 1024 * 100) / 100 . ' KB';
		} else {
			$size = $size . ' Bytes';
		}
		return $size;
	}
	
	function getQuery($exclude = array(), $NeedDelimiter = true, $QuestionMark = false) {
		global $_GET ;

		if (!is_array($exclude)) {
			if ($exclude == "") $exclude = array() ;
			else {
				$temp = array() ;
				array_push($temp, $exclude) ;
				$exclude = $temp ;
			}
		}
		
		$QU_ReCheckList = array() ;
		$QU_ExcludeList = array() ;
		foreach ($exclude as $k) {
			if (strstr($k, '%')) array_push($QU_ReCheckList, str_replace('%', '.*', $k)) ;
			else array_push($QU_ExcludeList, $k) ;
		}
		
		$QueryString = "" ;
		foreach ($_GET as $k => $v) {
			$v = trim($v) ;
			if ($v === "") continue;
			
			$bool = true;
			
			if (in_array($k, $QU_ExcludeList)) $bool = false;
			foreach ($QU_ReCheckList as $CheckKey) {
				if (preg_match("/" . $CheckKey . ".*/i", $k)) {
					$bool = false;
					break;
				}
			}
			
			if ($bool) $QueryString .= "&" . @urlencode($k) . "=" . @urlencode($v) ;
		}
		
		return ($QuestionMark && $QueryString != "" ? "?" : "") . substr($QueryString, $NeedDelimiter ? 0 : 1) ;
	}
	
	function getPageLimit ($PageCookieName = "", $PageDefaultSize = 10) {
		global $_GET ;
		
		$Page_Display_Limit = $PageDefaultSize ;
		
		if (
			(isset($_GET['PLIMIT']) && $_GET['PLIMIT'] !== "" && $_GET['PLIMIT'] != 0) ||
			(isset($_GET['PLIMIT']) && ($_GET['PLIMIT'] === 0 || $_GET['PLIMIT'] === "0"))
			) {
			setcookie($PageCookieName, ($_GET['PLIMIT'] + 0), 0, '/') ;
			header("Location: " . basename($_SERVER['SCRIPT_NAME']) . getQuery(array('PLIMIT'), false, true) ) ;
			exit() ;
			
		} else if ($_COOKIE[$PageCookieName] != 0) {
			$Page_Display_Limit = ($_COOKIE[$PageCookieName] + 0) ;
			
		} else {
			if (isset($_COOKIE[$PageCookieName]) && $_COOKIE[$PageCookieName] == 0) {
				setcookie($PageCookieName, "", time() - 3600, '/') ;
				header("Location: " . basename($_SERVER['SCRIPT_NAME']) . getQuery(array('PLIMIT'), false, true)) ;
				exit() ;
				
			}
			
		}
		
		return $Page_Display_Limit ;
	}

    function Price($Info, $IsAddProduct = false) {
        global $ActProducts ;
        $Price = $Info['p_price'] > 0 ? $Info['p_price'] : $Info['p_basic_price'];
        if (Member('ISVIP') && $Info['p_vip_price'] > 0) $Price = $Info['p_vip_price'];
        if (count($ActProducts[$Info['p_idn']]) > 0 && $Info['p_act_price'] > 0) $Price = $Info['p_act_price'];
        if ($IsAddProduct && $Info['p_add_price'] > 0) $Price = $Info['p_add_price'];
        
        return $Price;
    }

    function IsActPrice($Info) {
        global $ActProducts ;
        return (count($ActProducts[$Info['p_idn']]) > 0 && $Info['p_act_price'] > 0) ? true : false;
    }
	
	require("Basic_File.php") ;
	require("Basic_Check.php") ;
	require("Basic_System.php") ;
?>

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言