Rev 3 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/*QBPWCF, Quick Build PHP website Component base on Fedora Linux.Copyright (C) 2014~2025 MIN ZHI, CHENThis file is part of QBPWCF.QBPWCF is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.QBPWCF is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with QBPWCF. If not, see <http://www.gnu.org/licenses/>.*/namespace qbpwcf;/*類別說明:提供googleMap相關應用的類別.備註:無.*/class googleMap{/*#函式說明:#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$method,物件,為物件實體或類別名稱,會自動置入該參數.#$arguments,陣列,為呼叫方法時所用的參數.#參考資料:#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic*/public function __call($method,$arguments){#取得當前執行的函式$result["function"]=__FUNCTION__;#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";#設置所丟入的參數$result["error"][]=$arguments;#回傳結果return $result;}#function __call end/*#函式說明:#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$method,物件,為物件實體或類別名稱,會自動置入該參數.#$arguments,陣列,為呼叫方法時所用的參數.#參考資料:#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic*/public static function __callStatic($method,$arguments){#取得當前執行的函式$result["function"]=__FUNCTION__;#設置執行不正常$result["status"]="false";#設置執行錯誤$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";#設置所丟入的參數$result["error"][]=$arguments;#回傳結果return $result;}#function __callStatic end/*#函數說明:#用 google map 的 api 1.0 版提供靜態的地圖.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息 .#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["content"],語法.#必填參數:#無#可省略參數:#$conf["center"],字串陣列,地圖的中心位置,預設為array("City Hall","taipei","tw)",亦即"臺灣省(州)-臺北-市政府",也可以用緯經度array("40.714728,-73.998672").#$conf["center"]=array();#$conf["zoom"],字串,地圖的縮放等級,預設為16,可用範圍為10~19.#$conf["zoom"]="";#$conf["size"],字串陣列,地圖的大小,預設為array("400","400"),亦即400x400,最大為640x640.#$conf["size"]=array();#$conf["scale"],字串,地圖是否要放大,"false"為否,"true"為要放大.#$conf["scale"]="false";#$conf["lang"],字串,要使用的輔助語言,預設為"en_US"為美語."zh_TW"為中文,#$conf["lang"]="en_US";#$conf["format"],字串,地圖圖片的檔案類型,預設為"png",若要快速載入可用"jpg".#$conf["format"]="png";#$conf["demo"],字串,是否為示範模式,"true"為是,"false"為不是,預設為"false",若為"true"則$conf["center"]參數無效.#$conf["demo"]="";#參考資料:#static-maps=>https://developers.google.com/maps/documentation/static-maps/?hl=zh-tw*/function staticMap(&$conf){#初始化要回傳的結果$result=array();#取得當前執行的函數名稱$result["function"]=__FUNCTION__;#取得參數$result["argu"]=$conf;#如果 $conf 不為陣列if(gettype($conf)!="array"){#設置執行失敗$result["status"]="false";#設置執行錯誤訊息$result["error"][]="\$conf變數須為陣列形態";#如果傳入的參數為 nullif($conf==null){#設置執行錯誤訊息$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";}#if end#回傳結果return $result;}#if end#檢查參數#函式說明:#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["function"],當前執行的函式名稱.#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。#必填參數:#$conf["checkedVar"],陣列,要檢查的變數陣列名稱為?$conf["variableCheck::checkSkipableVarType"]["checkedVar"]=$conf;#$conf["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.$conf["variableCheck::checkSkipableVarType"]["sikpableVarNameArray"]=array("center","zoom","size","scale","lang","format","demo");#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).$argu=&$conf;#可省略參數:#$conf["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何,null代表不指定變數形態.$conf["variableCheck::checkSkipableVarType"]["skipableVarTypeArray"]=array("array","string","array","string","string","string","string");#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的變數要初始化為什麼,null代表不指定.$conf["variableCheck::checkSkipableVarType"]["skipableVarDefaultValue"]=array(array("City Hall","taipei","tw"),"16",array("400","400"),"false","en_US","png","false");$checkSkipableVarType=variableCheck::checkSkipableVarType($conf["variableCheck::checkSkipableVarType"],$argu);unset($conf["variableCheck::checkSkipableVarType"]);$conf=$argu;#如果檢查參數失敗if($checkSkipableVarType["status"]==="false"){#設置執行不正常$result["status"]="false";#設置錯誤訊息$result["error"]=$checkSkipableVarType;#回傳結果return $result;}#if end#如果參數檢查不通過if($checkSkipableVarType["passed"]==="false"){#設置執行不正常$result["status"]="false";#設置錯誤訊息$result["error"]=$checkSkipableVarType;#回傳結果return $result;}#if end#如果要demoif($conf["demo"]==="true"){#設定示範用的地點$demoAddr[]=array("City Hall","taipei","tw");$demoAddr[]=array("City Hall","new+york","NY");$demoAddr[]=array("City Hall","Los+angeles","CA");$demoAddr[]=array("Paris","France");$demoAddr[]=array("London","United Kingdom");$demoAddr[]=array("Wellington","New Zealand");$demoAddr[]=array("Thanon Na Phra Lan Bangkok Thailand");$demoAddr[]=array("Seoul","Korea");$demoAddr[]=array("Tokyo","Japan");$demoAddr[]=array("Melbourne","Victoria","Australia");/*"臺灣-臺北","美國-紐約","美國-洛杉磯","法國-巴黎","英國-倫敦","紐西蘭-威靈頓","泰國-曼谷","韓國-首爾","日本-東京","澳洲-墨爾本"*//*"City+Hall,taipei,tw","City+Hall,new+york,NY","City+Hall,Los+angeles,CA","Paris,France","London,United+Kingdom","Wellington,New+Zealand","Thanon+Na+Phra+Lan+Bangkok+Thailand","Seoul","Tokyo,Japan","Melbourne+Victoria+Australia"*/#隨機取用一個展示地點#函式說明:#亂數產生特定陣列裡面的內容#回傳的結果:#$result["status"],執行正常與否,"true"為正常,"false"為不正常.#$result["function"],當前執行的函數名稱.#$result["error"],錯誤訊息陣列.#$result["content"]["name"],產生的元素在$conf["randomArray"]裡面的key是?#$result["content"]["value"],產生的元素內容.#必填參數:#$conf["randomArray"],字串陣列,要隨機產生的元素.$conf["math::randomFromArray"]["randomArray"]=$demoAddr;#可省略參數:#無$randomFromArray=math::randomFromArray($conf["math::randomFromArray"]);unset($conf["math::randomFromArray"]);#如果隨機取用一個展示地點失敗if($randomFromArray["status"]==="false"){#設置執行不正常$result["status"]="false";#設置錯誤訊息$result["error"]=$randomFromArray;#回傳結果return $result;}#if end#設置 $conf["center"]$conf["center"]=$randomFromArray["content"]["value"];}#if end#初始化儲存地點$center="";#處理 $conf["center"]foreach($conf["center"] as $addClip){#涵式說明:#處理字串避免網頁出錯#回傳的結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["function"],當前執行的函數.#$result["content"],爲處理好的字串.#$result["error"],錯誤訊息陣列.#必填的參數:$conf["stringProcess::correctCharacter"]["stringIn"]=$addClip;#爲要處理的字串#可省略的參數:$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array(" ");#爲被選擇要處理的字串/字元,須爲陣列值。#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔$conf["stringProcess::correctCharacter"]["changeTo"]=array("+");#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);unset($conf["stringProcess::correctCharacter"]);#如果修正字串失敗if($correctCharacter["status"]==="false"){#設置執行不正常$result["status"]="false";#設置錯誤訊息$result["error"]=$correctCharacter;#回傳結果return $result;}#if end#取得處理好的位置片段$center=$center.$correctCharacter["content"];}#foreach end#如果要放大地圖if($conf["scale"]==="true"){#設置scale參數$conf["scale"]="2";}#if end#反之不放大地圖else{#設置scale參數$conf["scale"]="1";}#else end#初始化 google static map 網址$googleStaticMap="http://maps.google.com/maps/api/staticmap?";#設置參數$googleStaticMap=$googleStaticMap."center=".$center;$googleStaticMap=$googleStaticMap."&zoom=".$conf["zoom"];$googleStaticMap=$googleStaticMap."&size=".$conf["size"][0]."x".$conf["size"][1];$googleStaticMap=$googleStaticMap."&sensor=false";$googleStaticMap=$googleStaticMap."&scale=".$conf["scale"];$googleStaticMap=$googleStaticMap."&language=".$conf["lang"];$googleStaticMap=$googleStaticMap."&format=".$conf["format"];#放置 google static map 圖片的語法$result["content"]="<img src = \"".$googleStaticMap."\">";#設置執行正常$result["status"]="true";#回傳結果return $result;}#function demo end}#class googleMap end?>