| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
|
|
6 |
Copyright (C) 2015~2024 Min-Jhin,Chen
|
|
|
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
namespace qbpwcf;
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
提供googleMap相關應用的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class googleMap{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#參考資料:
|
|
|
45 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
46 |
*/
|
|
|
47 |
public function __call($method,$arguments){
|
|
|
48 |
|
|
|
49 |
#取得當前執行的函式
|
|
|
50 |
$result["function"]=__FUNCTION__;
|
|
|
51 |
|
|
|
52 |
#設置執行不正常
|
|
|
53 |
$result["status"]="false";
|
|
|
54 |
|
|
|
55 |
#設置執行錯誤
|
|
|
56 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
57 |
|
|
|
58 |
#設置所丟入的參數
|
|
|
59 |
$result["error"][]=$arguments;
|
|
|
60 |
|
|
|
61 |
#回傳結果
|
|
|
62 |
return $result;
|
|
|
63 |
|
|
|
64 |
}#function __call end
|
|
|
65 |
|
|
|
66 |
/*
|
|
|
67 |
#函式說明:
|
|
|
68 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
69 |
#回傳結果:
|
|
|
70 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
71 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
72 |
#$result["function"],當前執行的函式名稱.
|
|
|
73 |
#必填參數:
|
|
|
74 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
75 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
76 |
#參考資料:
|
|
|
77 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
78 |
*/
|
|
|
79 |
public static function __callStatic($method,$arguments){
|
|
|
80 |
|
|
|
81 |
#取得當前執行的函式
|
|
|
82 |
$result["function"]=__FUNCTION__;
|
|
|
83 |
|
|
|
84 |
#設置執行不正常
|
|
|
85 |
$result["status"]="false";
|
|
|
86 |
|
|
|
87 |
#設置執行錯誤
|
|
|
88 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
89 |
|
|
|
90 |
#設置所丟入的參數
|
|
|
91 |
$result["error"][]=$arguments;
|
|
|
92 |
|
|
|
93 |
#回傳結果
|
|
|
94 |
return $result;
|
|
|
95 |
|
|
|
96 |
}#function __callStatic end
|
|
|
97 |
|
|
|
98 |
/*
|
|
|
99 |
#函數說明:
|
|
|
100 |
#用 google map 的 api 1.0 版提供靜態的地圖.
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
103 |
#$result["error"],錯誤訊息 .
|
|
|
104 |
#$result["function"],當前執行的函數名稱.
|
|
|
105 |
#$result["argu"],使用的參數.
|
|
|
106 |
#$result["content"],語法.
|
|
|
107 |
#必填參數:
|
|
|
108 |
#無
|
|
|
109 |
#可省略參數:
|
|
|
110 |
#$conf["center"],字串陣列,地圖的中心位置,預設為array("City Hall","taipei","tw)",亦即"臺灣省(州)-臺北-市政府",也可以用緯經度array("40.714728,-73.998672").
|
|
|
111 |
#$conf["center"]=array();
|
|
|
112 |
#$conf["zoom"],字串,地圖的縮放等級,預設為16,可用範圍為10~19.
|
|
|
113 |
#$conf["zoom"]="";
|
|
|
114 |
#$conf["size"],字串陣列,地圖的大小,預設為array("400","400"),亦即400x400,最大為640x640.
|
|
|
115 |
#$conf["size"]=array();
|
|
|
116 |
#$conf["scale"],字串,地圖是否要放大,"false"為否,"true"為要放大.
|
|
|
117 |
#$conf["scale"]="false";
|
|
|
118 |
#$conf["lang"],字串,要使用的輔助語言,預設為"en_US"為美語."zh_TW"為中文,
|
|
|
119 |
#$conf["lang"]="en_US";
|
|
|
120 |
#$conf["format"],字串,地圖圖片的檔案類型,預設為"png",若要快速載入可用"jpg".
|
|
|
121 |
#$conf["format"]="png";
|
|
|
122 |
#$conf["demo"],字串,是否為示範模式,"true"為是,"false"為不是,預設為"false",若為"true"則$conf["center"]參數無效.
|
|
|
123 |
#$conf["demo"]="";
|
|
|
124 |
#參考資料:
|
|
|
125 |
#static-maps=>https://developers.google.com/maps/documentation/static-maps/?hl=zh-tw
|
|
|
126 |
*/
|
|
|
127 |
function staticMap(&$conf){
|
|
|
128 |
|
|
|
129 |
#初始化要回傳的結果
|
|
|
130 |
$result=array();
|
|
|
131 |
|
|
|
132 |
#取得當前執行的函數名稱
|
|
|
133 |
$result["function"]=__FUNCTION__;
|
|
|
134 |
|
|
|
135 |
#取得參數
|
|
|
136 |
$result["argu"]=$conf;
|
|
|
137 |
|
|
|
138 |
#如果 $conf 不為陣列
|
|
|
139 |
if(gettype($conf)!="array"){
|
|
|
140 |
|
|
|
141 |
#設置執行失敗
|
|
|
142 |
$result["status"]="false";
|
|
|
143 |
|
|
|
144 |
#設置執行錯誤訊息
|
|
|
145 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
146 |
|
|
|
147 |
#如果傳入的參數為 null
|
|
|
148 |
if($conf==null){
|
|
|
149 |
|
|
|
150 |
#設置執行錯誤訊息
|
|
|
151 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
152 |
|
|
|
153 |
}#if end
|
|
|
154 |
|
|
|
155 |
#回傳結果
|
|
|
156 |
return $result;
|
|
|
157 |
|
|
|
158 |
}#if end
|
|
|
159 |
|
|
|
160 |
#檢查參數
|
|
|
161 |
#函式說明:
|
|
|
162 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
163 |
#回傳結果:
|
|
|
164 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
165 |
#$result["error"],錯誤訊息陣列.
|
|
|
166 |
#$result["function"],當前執行的函式名稱.
|
|
|
167 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
168 |
#必填參數:
|
|
|
169 |
#$conf["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
170 |
$conf["variableCheck::checkSkipableVarType"]["checkedVar"]=$conf;
|
|
|
171 |
#$conf["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
172 |
$conf["variableCheck::checkSkipableVarType"]["sikpableVarNameArray"]=array("center","zoom","size","scale","lang","format","demo");
|
|
|
173 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
174 |
$argu=&$conf;
|
|
|
175 |
#可省略參數:
|
|
|
176 |
#$conf["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何,null代表不指定變數形態.
|
|
|
177 |
$conf["variableCheck::checkSkipableVarType"]["skipableVarTypeArray"]=array("array","string","array","string","string","string","string");
|
|
|
178 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的變數要初始化為什麼,null代表不指定.
|
|
|
179 |
$conf["variableCheck::checkSkipableVarType"]["skipableVarDefaultValue"]=array(array("City Hall","taipei","tw"),"16",array("400","400"),"false","en_US","png","false");
|
|
|
180 |
$checkSkipableVarType=variableCheck::checkSkipableVarType($conf["variableCheck::checkSkipableVarType"],$argu);
|
|
|
181 |
unset($conf["variableCheck::checkSkipableVarType"]);
|
|
|
182 |
$conf=$argu;
|
|
|
183 |
|
|
|
184 |
#如果檢查參數失敗
|
|
|
185 |
if($checkSkipableVarType["status"]==="false"){
|
|
|
186 |
|
|
|
187 |
#設置執行不正常
|
|
|
188 |
$result["status"]="false";
|
|
|
189 |
|
|
|
190 |
#設置錯誤訊息
|
|
|
191 |
$result["error"]=$checkSkipableVarType;
|
|
|
192 |
|
|
|
193 |
#回傳結果
|
|
|
194 |
return $result;
|
|
|
195 |
|
|
|
196 |
}#if end
|
|
|
197 |
|
|
|
198 |
#如果參數檢查不通過
|
|
|
199 |
if($checkSkipableVarType["passed"]==="false"){
|
|
|
200 |
|
|
|
201 |
#設置執行不正常
|
|
|
202 |
$result["status"]="false";
|
|
|
203 |
|
|
|
204 |
#設置錯誤訊息
|
|
|
205 |
$result["error"]=$checkSkipableVarType;
|
|
|
206 |
|
|
|
207 |
#回傳結果
|
|
|
208 |
return $result;
|
|
|
209 |
|
|
|
210 |
}#if end
|
|
|
211 |
|
|
|
212 |
#如果要demo
|
|
|
213 |
if($conf["demo"]==="true"){
|
|
|
214 |
|
|
|
215 |
#設定示範用的地點
|
|
|
216 |
$demoAddr[]=array("City Hall","taipei","tw");
|
|
|
217 |
$demoAddr[]=array("City Hall","new+york","NY");
|
|
|
218 |
$demoAddr[]=array("City Hall","Los+angeles","CA");
|
|
|
219 |
$demoAddr[]=array("Paris","France");
|
|
|
220 |
$demoAddr[]=array("London","United Kingdom");
|
|
|
221 |
$demoAddr[]=array("Wellington","New Zealand");
|
|
|
222 |
$demoAddr[]=array("Thanon Na Phra Lan Bangkok Thailand");
|
|
|
223 |
$demoAddr[]=array("Seoul","Korea");
|
|
|
224 |
$demoAddr[]=array("Tokyo","Japan");
|
|
|
225 |
$demoAddr[]=array("Melbourne","Victoria","Australia");
|
|
|
226 |
|
|
|
227 |
/*
|
|
|
228 |
"臺灣-臺北",
|
|
|
229 |
"美國-紐約",
|
|
|
230 |
"美國-洛杉磯",
|
|
|
231 |
"法國-巴黎",
|
|
|
232 |
"英國-倫敦",
|
|
|
233 |
"紐西蘭-威靈頓",
|
|
|
234 |
"泰國-曼谷",
|
|
|
235 |
"韓國-首爾",
|
|
|
236 |
"日本-東京",
|
|
|
237 |
"澳洲-墨爾本"
|
|
|
238 |
*/
|
|
|
239 |
|
|
|
240 |
/*
|
|
|
241 |
"City+Hall,taipei,tw",
|
|
|
242 |
"City+Hall,new+york,NY",
|
|
|
243 |
"City+Hall,Los+angeles,CA",
|
|
|
244 |
"Paris,France",
|
|
|
245 |
"London,United+Kingdom",
|
|
|
246 |
"Wellington,New+Zealand",
|
|
|
247 |
"Thanon+Na+Phra+Lan+Bangkok+Thailand",
|
|
|
248 |
"Seoul",
|
|
|
249 |
"Tokyo,Japan",
|
|
|
250 |
"Melbourne+Victoria+Australia"
|
|
|
251 |
*/
|
|
|
252 |
|
|
|
253 |
#隨機取用一個展示地點
|
|
|
254 |
#函式說明:
|
|
|
255 |
#亂數產生特定陣列裡面的內容
|
|
|
256 |
#回傳的結果:
|
|
|
257 |
#$result["status"],執行正常與否,"true"為正常,"false"為不正常.
|
|
|
258 |
#$result["function"],當前執行的函數名稱.
|
|
|
259 |
#$result["error"],錯誤訊息陣列.
|
|
|
260 |
#$result["content"]["name"],產生的元素在$conf["randomArray"]裡面的key是?
|
|
|
261 |
#$result["content"]["value"],產生的元素內容.
|
|
|
262 |
#必填參數:
|
|
|
263 |
#$conf["randomArray"],字串陣列,要隨機產生的元素.
|
|
|
264 |
$conf["math::randomFromArray"]["randomArray"]=$demoAddr;
|
|
|
265 |
#可省略參數:
|
|
|
266 |
#無
|
|
|
267 |
$randomFromArray=math::randomFromArray($conf["math::randomFromArray"]);
|
|
|
268 |
unset($conf["math::randomFromArray"]);
|
|
|
269 |
|
|
|
270 |
#如果隨機取用一個展示地點失敗
|
|
|
271 |
if($randomFromArray["status"]==="false"){
|
|
|
272 |
|
|
|
273 |
#設置執行不正常
|
|
|
274 |
$result["status"]="false";
|
|
|
275 |
|
|
|
276 |
#設置錯誤訊息
|
|
|
277 |
$result["error"]=$randomFromArray;
|
|
|
278 |
|
|
|
279 |
#回傳結果
|
|
|
280 |
return $result;
|
|
|
281 |
|
|
|
282 |
}#if end
|
|
|
283 |
|
|
|
284 |
#設置 $conf["center"]
|
|
|
285 |
$conf["center"]=$randomFromArray["content"]["value"];
|
|
|
286 |
|
|
|
287 |
}#if end
|
|
|
288 |
|
|
|
289 |
#初始化儲存地點
|
|
|
290 |
$center="";
|
|
|
291 |
|
|
|
292 |
#處理 $conf["center"]
|
|
|
293 |
foreach($conf["center"] as $addClip){
|
|
|
294 |
|
|
|
295 |
#涵式說明:
|
|
|
296 |
#處理字串避免網頁出錯
|
|
|
297 |
#回傳的結果:
|
|
|
298 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
299 |
#$result["function"],當前執行的函數.
|
|
|
300 |
#$result["content"],爲處理好的字串.
|
|
|
301 |
#$result["error"],錯誤訊息陣列.
|
|
|
302 |
#必填的參數:
|
|
|
303 |
$conf["stringProcess::correctCharacter"]["stringIn"]=$addClip;#爲要處理的字串
|
|
|
304 |
#可省略的參數:
|
|
|
305 |
$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array(" ");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
306 |
#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
|
|
|
307 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
308 |
$conf["stringProcess::correctCharacter"]["changeTo"]=array("+");#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
309 |
$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
|
|
|
310 |
unset($conf["stringProcess::correctCharacter"]);
|
|
|
311 |
|
|
|
312 |
#如果修正字串失敗
|
|
|
313 |
if($correctCharacter["status"]==="false"){
|
|
|
314 |
|
|
|
315 |
#設置執行不正常
|
|
|
316 |
$result["status"]="false";
|
|
|
317 |
|
|
|
318 |
#設置錯誤訊息
|
|
|
319 |
$result["error"]=$correctCharacter;
|
|
|
320 |
|
|
|
321 |
#回傳結果
|
|
|
322 |
return $result;
|
|
|
323 |
|
|
|
324 |
}#if end
|
|
|
325 |
|
|
|
326 |
#取得處理好的位置片段
|
|
|
327 |
$center=$center.$correctCharacter["content"];
|
|
|
328 |
|
|
|
329 |
}#foreach end
|
|
|
330 |
|
|
|
331 |
#如果要放大地圖
|
|
|
332 |
if($conf["scale"]==="true"){
|
|
|
333 |
|
|
|
334 |
#設置scale參數
|
|
|
335 |
$conf["scale"]="2";
|
|
|
336 |
|
|
|
337 |
}#if end
|
|
|
338 |
|
|
|
339 |
#反之不放大地圖
|
|
|
340 |
else{
|
|
|
341 |
|
|
|
342 |
#設置scale參數
|
|
|
343 |
$conf["scale"]="1";
|
|
|
344 |
|
|
|
345 |
}#else end
|
|
|
346 |
|
|
|
347 |
#初始化 google static map 網址
|
|
|
348 |
$googleStaticMap="http://maps.google.com/maps/api/staticmap?";
|
|
|
349 |
|
|
|
350 |
#設置參數
|
|
|
351 |
$googleStaticMap=$googleStaticMap."center=".$center;
|
|
|
352 |
$googleStaticMap=$googleStaticMap."&zoom=".$conf["zoom"];
|
|
|
353 |
$googleStaticMap=$googleStaticMap."&size=".$conf["size"][0]."x".$conf["size"][1];
|
|
|
354 |
$googleStaticMap=$googleStaticMap."&sensor=false";
|
|
|
355 |
$googleStaticMap=$googleStaticMap."&scale=".$conf["scale"];
|
|
|
356 |
$googleStaticMap=$googleStaticMap."&language=".$conf["lang"];
|
|
|
357 |
$googleStaticMap=$googleStaticMap."&format=".$conf["format"];
|
|
|
358 |
|
|
|
359 |
#放置 google static map 圖片的語法
|
|
|
360 |
$result["content"]="<img src = \"".$googleStaticMap."\">";
|
|
|
361 |
|
|
|
362 |
#設置執行正常
|
|
|
363 |
$result["status"]="true";
|
|
|
364 |
|
|
|
365 |
#回傳結果
|
|
|
366 |
return $result;
|
|
|
367 |
|
|
|
368 |
}#function demo end
|
|
|
369 |
|
|
|
370 |
}#class googleMap end
|
|
|
371 |
|
|
|
372 |
?>
|