Subversion Repositories php-qbpwcf

Rev

Rev 226 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3 liveuser 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){
226 liveuser 48
 
3 liveuser 49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
226 liveuser 51
 
3 liveuser 52
		#設置執行不正常
53
		$result["status"]="false";
226 liveuser 54
 
3 liveuser 55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 57
 
3 liveuser 58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
226 liveuser 60
 
3 liveuser 61
		#回傳結果
62
		return $result;
226 liveuser 63
 
3 liveuser 64
		}#function __call end
226 liveuser 65
 
3 liveuser 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){
226 liveuser 80
 
3 liveuser 81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
226 liveuser 83
 
3 liveuser 84
		#設置執行不正常
85
		$result["status"]="false";
226 liveuser 86
 
3 liveuser 87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 89
 
3 liveuser 90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
226 liveuser 92
 
3 liveuser 93
		#回傳結果
94
		return $result;
226 liveuser 95
 
3 liveuser 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"],使用的參數.
226 liveuser 106
	#$result["content"],語法.
3 liveuser 107
	#必填參數:
226 liveuser 108
	#無
3 liveuser 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"為要放大.
226 liveuser 117
	#$conf["scale"]="false";
3 liveuser 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){
226 liveuser 128
 
3 liveuser 129
		#初始化要回傳的結果
130
		$result=array();
131
 
132
		#取得當前執行的函數名稱
133
		$result["function"]=__FUNCTION__;
134
 
135
		#取得參數
136
		$result["argu"]=$conf;
137
 
138
		#如果 $conf 不為陣列
139
		if(gettype($conf)!="array"){
226 liveuser 140
 
3 liveuser 141
			#設置執行失敗
142
			$result["status"]="false";
226 liveuser 143
 
3 liveuser 144
			#設置執行錯誤訊息
145
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 146
 
3 liveuser 147
			#如果傳入的參數為 null
148
			if($conf==null){
226 liveuser 149
 
3 liveuser 150
				#設置執行錯誤訊息
151
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 152
 
3 liveuser 153
				}#if end
154
 
155
			#回傳結果
156
			return $result;
226 liveuser 157
 
3 liveuser 158
		}#if end
226 liveuser 159
 
3 liveuser 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"]);
226 liveuser 182
		$conf=$argu;
183
 
3 liveuser 184
		#如果檢查參數失敗
185
		if($checkSkipableVarType["status"]==="false"){
226 liveuser 186
 
3 liveuser 187
			#設置執行不正常
188
			$result["status"]="false";
226 liveuser 189
 
3 liveuser 190
			#設置錯誤訊息
191
			$result["error"]=$checkSkipableVarType;
226 liveuser 192
 
3 liveuser 193
			#回傳結果
194
			return $result;
226 liveuser 195
 
3 liveuser 196
			}#if end
226 liveuser 197
 
3 liveuser 198
		#如果參數檢查不通過
199
		if($checkSkipableVarType["passed"]==="false"){
226 liveuser 200
 
3 liveuser 201
			#設置執行不正常
202
			$result["status"]="false";
226 liveuser 203
 
3 liveuser 204
			#設置錯誤訊息
205
			$result["error"]=$checkSkipableVarType;
226 liveuser 206
 
3 liveuser 207
			#回傳結果
208
			return $result;
226 liveuser 209
 
3 liveuser 210
			}#if end
226 liveuser 211
 
3 liveuser 212
		#如果要demo
213
		if($conf["demo"]==="true"){
226 liveuser 214
 
3 liveuser 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 liveuser 226
 
3 liveuser 227
			/*
228
			"臺灣-臺北",
229
			"美國-紐約",
230
			"美國-洛杉磯",
231
			"法國-巴黎",
232
			"英國-倫敦",
233
			"紐西蘭-威靈頓",
234
			"泰國-曼谷",
235
			"韓國-首爾",
236
			"日本-東京",
237
			"澳洲-墨爾本"
238
			*/
226 liveuser 239
 
3 liveuser 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",
226 liveuser 250
			"Melbourne+Victoria+Australia"
3 liveuser 251
			*/
226 liveuser 252
 
3 liveuser 253
			#隨機取用一個展示地點
226 liveuser 254
			#函式說明:
3 liveuser 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"]);
226 liveuser 269
 
3 liveuser 270
			#如果隨機取用一個展示地點失敗
271
			if($randomFromArray["status"]==="false"){
226 liveuser 272
 
3 liveuser 273
				#設置執行不正常
274
				$result["status"]="false";
226 liveuser 275
 
3 liveuser 276
				#設置錯誤訊息
277
				$result["error"]=$randomFromArray;
226 liveuser 278
 
3 liveuser 279
				#回傳結果
280
				return $result;
226 liveuser 281
 
3 liveuser 282
				}#if end
226 liveuser 283
 
3 liveuser 284
			#設置 $conf["center"]
285
			$conf["center"]=$randomFromArray["content"]["value"];
226 liveuser 286
 
3 liveuser 287
			}#if end
226 liveuser 288
 
3 liveuser 289
		#初始化儲存地點
290
		$center="";
226 liveuser 291
 
3 liveuser 292
		#處理 $conf["center"]
293
		foreach($conf["center"] as $addClip){
226 liveuser 294
 
3 liveuser 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"]);
226 liveuser 311
 
3 liveuser 312
			#如果修正字串失敗
313
			if($correctCharacter["status"]==="false"){
226 liveuser 314
 
3 liveuser 315
				#設置執行不正常
316
				$result["status"]="false";
226 liveuser 317
 
3 liveuser 318
				#設置錯誤訊息
319
				$result["error"]=$correctCharacter;
226 liveuser 320
 
3 liveuser 321
				#回傳結果
322
				return $result;
226 liveuser 323
 
3 liveuser 324
				}#if end
226 liveuser 325
 
3 liveuser 326
			#取得處理好的位置片段
327
			$center=$center.$correctCharacter["content"];
226 liveuser 328
 
3 liveuser 329
			}#foreach end
226 liveuser 330
 
3 liveuser 331
		#如果要放大地圖
332
		if($conf["scale"]==="true"){
226 liveuser 333
 
3 liveuser 334
			#設置scale參數
335
			$conf["scale"]="2";
226 liveuser 336
 
3 liveuser 337
			}#if end
226 liveuser 338
 
339
		#反之不放大地圖
3 liveuser 340
		else{
226 liveuser 341
 
3 liveuser 342
			#設置scale參數
343
			$conf["scale"]="1";
226 liveuser 344
 
345
			}#else end
346
 
347
		#初始化 google static map 網址
3 liveuser 348
		$googleStaticMap="http://maps.google.com/maps/api/staticmap?";
226 liveuser 349
 
3 liveuser 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"];
226 liveuser 358
 
359
		#放置 google static map 圖片的語法
3 liveuser 360
		$result["content"]="<img src = \"".$googleStaticMap."\">";
226 liveuser 361
 
3 liveuser 362
		#設置執行正常
363
		$result["status"]="true";
226 liveuser 364
 
3 liveuser 365
		#回傳結果
366
		return $result;
367
 
226 liveuser 368
		}#function demo end
369
 
3 liveuser 370
	}#class googleMap end
226 liveuser 371
 
3 liveuser 372
?>