Subversion Repositories php-qbpwcf

Rev

Rev 374 | Rev 391 | Go to most recent revision | 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
檔案存取應用的類別.
29
備註:
30
無.
31
*/
32
class fileAccess{
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
	#將字串寫入到檔案
101
	#回傳結果:
102
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
103
	#$result["error"],錯誤訊息陣列.
104
	#$result["function"],當前執行的函數名稱.
105
	#$result["fileInfo"],實際上寫入的檔案資訊陣列.
106
	#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
107
	#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
108
	#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
109
	#$result["argu"],使用的參數.
110
	#必填參數:
111
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
112
	$conf["fileArgu"]=__FILE__;
113
	#可省略參數:
114
	#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
115
	#$conf["fileName"]="";
116
	#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
117
	#$conf["inputString"]="";
118
	#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
119
	#$conf["writeMethod"]="a";
120
	#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
121
	#$conf["checkRepeat"]="";
122
	#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
123
	#$conf["filenameExtensionStartPoint"]="";
124
	#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
125
	#$conf["repeatNameRule"]="";
126
	#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
127
	#$conf["web"]="true";
128
	#參考資料:
129
	#無.
130
	#備註:
131
	#無.
132
	*/
133
	public static function writeTextIntoFile(&$conf){
134
 
135
		#初始化要回傳的變數
136
		$result=array();
137
 
138
		#初始化當前執行的函數名稱
139
		$result["function"]=__FUNCTION__;
140
 
141
		#如果 $conf 不為陣列
142
		if(gettype($conf)!="array"){
226 liveuser 143
 
3 liveuser 144
			#設置執行失敗
145
			$result["status"]="false";
226 liveuser 146
 
3 liveuser 147
			#設置執行錯誤訊息
148
			$result["error"][]="\$conf變數須為陣列形態";
149
 
150
			#如果傳入的參數為 null
151
			if($conf==null){
226 liveuser 152
 
3 liveuser 153
				#設置執行錯誤訊息
154
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 155
 
3 liveuser 156
				}#if end
157
 
158
			#回傳結果
159
			return $result;
226 liveuser 160
 
3 liveuser 161
			}#if end
226 liveuser 162
 
3 liveuser 163
		#取得使用的參數
164
		$result["argu"]=$conf;
165
 
166
		#檢查參數
167
		#函式說明:
168
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
169
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
170
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
171
		#$result["function"],當前執行的函式名稱.
172
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
173
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
174
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
175
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
176
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
177
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
178
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
179
		#必填寫的參數:
180
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
181
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
182
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
183
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
226 liveuser 184
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 185
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
186
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
187
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
188
		#可以省略的參數:
189
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
190
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
191
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
192
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileName","inputString","writeMethod","checkRepeat","filenameExtensionStartPoint","repeatNameRule","web");
226 liveuser 193
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 194
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
195
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
196
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"","w","false",null,null,"true");
197
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
198
		#$conf["arrayCountEqualCheck"][]=array();
199
		#參考資料來源:
200
		#array_keys=>http://php.net/manual/en/function.array-keys.php
201
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
202
		unset($conf["variableCheck::checkArguments"]);
203
 
204
		#如果 $checkArguments["status"] 等於 "false"
205
		if($checkArguments["status"]=="false"){
226 liveuser 206
 
3 liveuser 207
			#設置錯誤識別
208
			$result["status"]="false";
226 liveuser 209
 
3 liveuser 210
			#設置錯誤訊息
211
			$result["error"]=$checkArguments;
226 liveuser 212
 
3 liveuser 213
			#回傳結果
220 liveuser 214
			return $result;
226 liveuser 215
 
3 liveuser 216
			}#if end
226 liveuser 217
 
3 liveuser 218
		#如果 $checkArguments["passed"] 等於 "false"
219
		if($checkArguments["passed"]=="false"){
226 liveuser 220
 
3 liveuser 221
			#設置錯誤識別
222
			$result["status"]="false";
226 liveuser 223
 
3 liveuser 224
			#設置錯誤訊息
225
			$result["error"]=$checkArguments;
226 liveuser 226
 
3 liveuser 227
			#回傳結果
220 liveuser 228
			return $result;
226 liveuser 229
 
3 liveuser 230
			}#if end
231
 
232
		#如果沒有設置 $conf["fileName"]
233
		if(!isset($conf["fileName"])){
226 liveuser 234
 
3 liveuser 235
			#設定要檢查是否有重複的檔案名稱
236
			$conf["checkRepeat"]="true";
226 liveuser 237
 
3 liveuser 238
			#亂數產生檔案名稱
239
			#函式說明:
240
			#建立以圖片(PNG格式)呈現的驗證碼.
241
			#回傳的解果:
242
			#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
243
			#$result["error"],錯誤訊息.
244
			#$result["function"],檔前執行的函數名稱.
245
			#$result["randNumberWord"],傳驗證碼的內容.
246
			#$result["imgAddress"],圖片的位置與名稱.
247
			#必填參數:
248
			#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
249
			$conf["authenticate::validationCode"]["imgAddressAndName"]="don't need!";
250
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
251
			$conf["authenticate::validationCode"]["fileArgu"]=$conf["fileArgu"];
252
			#可省略參數:
253
			#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
254
			$conf["authenticate::validationCode"]["num"]="10";
255
			#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
256
			$conf["authenticate::validationCode"]["disableImg"]="true";
257
			#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
258
			#$conf["imgToData"]="true";
259
			$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
260
			unset($conf["authenticate::validationCode"]);
226 liveuser 261
 
3 liveuser 262
			#如果亂數產生錯誤
263
			if($validationCode["status"]=="false"){
226 liveuser 264
 
3 liveuser 265
				#設置錯誤識別
266
				$result["status"]="false";
226 liveuser 267
 
3 liveuser 268
				#設置錯誤訊息
269
				$result["error"]=$validationCode;
226 liveuser 270
 
3 liveuser 271
				#回傳結果
226 liveuser 272
				return $result;
273
 
3 liveuser 274
				}#if end
226 liveuser 275
 
3 liveuser 276
			#取得產生的檔案名稱
277
			$conf["fileName"]=$validationCode["randNumberWord"];
226 liveuser 278
 
3 liveuser 279
			}#if end
280
 
281
		#剃除 $conf["fileName"] 開頭的 "./"
282
		#函式說明:
283
		#移除字串開頭的特定內容
284
		#回傳的接結果:
285
		#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
286
		#$result["error"],錯誤訊息陣列.
287
		#$result["function"],當前執行的函數.
288
		#$result["content"],處理好的字串.
289
		#必填參數:
290
		#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
291
		$conf["stringProcess::delKeyWordsInStrHead"]["inputStr"]=$conf["fileName"];
292
		#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
226 liveuser 293
		$conf["stringProcess::delKeyWordsInStrHead"]["keyWord"]="./";
3 liveuser 294
		#可省略參數:
295
		#無.
296
		$delKeyWordsInStrHead=stringProcess::delKeyWordsInStrHead($conf["stringProcess::delKeyWordsInStrHead"]);
297
		unset($conf["stringProcess::delKeyWordsInStrHead"]);
298
 
299
		#如果處理失敗
300
		if($delKeyWordsInStrHead["status"]=="false"){
226 liveuser 301
 
3 liveuser 302
			#設置錯誤識別
303
			$result["status"]="false";
226 liveuser 304
 
3 liveuser 305
			#設置錯誤訊息
306
			$result["error"]=$delKeyWordsInStrHead;
226 liveuser 307
 
3 liveuser 308
			#回傳結果
226 liveuser 309
			return $result;
310
 
3 liveuser 311
			}#if end
226 liveuser 312
 
3 liveuser 313
		#取得處理好的檔案名稱
314
		$conf["fileName"]=$delKeyWordsInStrHead["content"];
315
 
316
		#函式說明:
317
		#確保路徑存在.
318
		#回傳結果:
319
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
320
		#$result["error"],錯誤訊息陣列.
321
		#$resutl["function"],當前執行的涵式名稱.
322
		#必填參數:
323
		#$conf["path"],要檢查的路徑
220 liveuser 324
		$conf["fileAccess::validatePath"]["path"]=$conf["fileName"];
3 liveuser 325
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
326
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
327
		#可省略參數:
328
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
329
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
330
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
331
		#$conf["dirPermission"]="";
332
		$conf["fileAccess::validatePath"]["web"]=$conf["web"];
333
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
334
		unset($conf["fileAccess::validatePath"]);
226 liveuser 335
 
3 liveuser 336
		#debug
337
		#var_dump($validatePath);exit;
226 liveuser 338
 
3 liveuser 339
		#如果確保路徑失敗
340
		if($validatePath["status"]=="false"){
226 liveuser 341
 
3 liveuser 342
			#設置錯誤識別
343
			$result["status"]="false";
226 liveuser 344
 
3 liveuser 345
			#設置錯誤訊息
346
			$result["error"]=$validatePath;
226 liveuser 347
 
3 liveuser 348
			#回傳結果
226 liveuser 349
			return $result;
350
 
3 liveuser 351
			}#if end
226 liveuser 352
 
220 liveuser 353
		#如果要檢查是否有同名的檔案
3 liveuser 354
		if($conf["checkRepeat"]=="true"){
226 liveuser 355
 
3 liveuser 356
			#函式說明:
357
			#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
358
			#回傳的結果:
359
			#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
360
			#$result["error"],錯誤訊息陣列.
361
			#$result["function"],當前執行的函數名稱.
362
			#$result["createdFileName"],建立好的檔案名稱.
363
			#$result["createdFilePath"],檔案建立的路徑.
364
			#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
365
			#必填參數:
366
			#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
367
			$conf["fileAccess::createFileAfterCheck"]["checkedFileAndPath"]=$conf["fileName"];
368
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
369
			$conf["fileAccess::createFileAfterCheck"]["fileArgu"]=$conf["fileArgu"];
370
			#可省略參數:
226 liveuser 371
 
3 liveuser 372
			#如果有設定 $conf["filenameExtensionStartPoint"]
373
			if(isset($conf["filenameExtensionStartPoint"])){
226 liveuser 374
 
3 liveuser 375
				#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點.
376
				$conf["fileAccess::createFileAfterCheck"]["filenameExtensionStartPoint"]=$conf["filenameExtensionStartPoint"];
226 liveuser 377
 
3 liveuser 378
				}#if end
226 liveuser 379
 
3 liveuser 380
			#如果有設定 $conf["repeatNameRule"]
381
			if(isset($conf["repeatNameRule"])){
226 liveuser 382
 
3 liveuser 383
				#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)".
384
				$conf["fileAccess::createFileAfterCheck"]["repeatNameRule"]=$conf["repeatNameRule"];
226 liveuser 385
 
3 liveuser 386
				}#if end
226 liveuser 387
 
3 liveuser 388
			#如果有設定 $conf["web"] 參數
389
			if(isset($conf["web"])){
226 liveuser 390
 
3 liveuser 391
				$conf["fileAccess::createFileAfterCheck"]["web"]=$conf["web"];
226 liveuser 392
 
3 liveuser 393
				}#if end
226 liveuser 394
 
3 liveuser 395
			$createFileAfterCheck=fileAccess::createFileAfterCheck($conf["fileAccess::createFileAfterCheck"]);
396
			unset($conf["fileAccess::createFileAfterCheck"]);
226 liveuser 397
 
3 liveuser 398
			#debug
399
			#var_dump($createFileAfterCheck);
400
			#exit;
226 liveuser 401
 
3 liveuser 402
			#如果嘗試建立檔案失敗
403
			if($createFileAfterCheck["status"]=="false"){
226 liveuser 404
 
3 liveuser 405
				#設置執行不正常
406
				$result["status"]="false";
226 liveuser 407
 
3 liveuser 408
				#設置錯誤訊息
409
				$result["error"]=$createFileAfterCheck;
226 liveuser 410
 
3 liveuser 411
				#回傳結果
412
				return $result;
226 liveuser 413
 
3 liveuser 414
				}#if end
226 liveuser 415
 
3 liveuser 416
			#取得建立的檔案資訊
417
			$result["fileInfo"]["createdFilePathAndName"]=$createFileAfterCheck["createdFilePathAndName"];
418
			$result["fileInfo"]["createdFilePath"]=$createFileAfterCheck["createdFilePath"];
226 liveuser 419
			$result["fileInfo"]["createdFileName"]=$createFileAfterCheck["createdFileName"];
420
 
3 liveuser 421
			#取得建立好的檔案路徑與名稱
422
			$conf["fileName"]=$createFileAfterCheck["createdFilePathAndName"];
226 liveuser 423
 
220 liveuser 424
			}#if end
3 liveuser 425
 
426
		#反之沒有要檢查檔案是否存在
427
		else{
226 liveuser 428
 
3 liveuser 429
			#取得建立的檔案資訊
430
			$result["fileInfo"]["createdFilePathAndName"]=$conf["fileName"];
431
			$result["fileInfo"]["createdFilePath"]=$validatePath["path"];
220 liveuser 432
			$result["fileInfo"]["createdFileName"]=$validatePath["fileName"];
226 liveuser 433
 
3 liveuser 434
			}#else end
435
 
436
		#設定要寫入或複寫的檔案
437
		$fileopenResult=fopen($conf["fileName"],$conf["writeMethod"]);
226 liveuser 438
 
3 liveuser 439
		#如果 $fileopenResult 等於 FALSE
440
		if($fileopenResult==FALSE){
226 liveuser 441
 
3 liveuser 442
			#設置錯誤識別
443
			$result["status"]="false";
226 liveuser 444
 
3 liveuser 445
			#代表打開檔案失敗
446
			$result["error"][]="檔案".$conf["fileName"]."開啟失敗";
226 liveuser 447
 
3 liveuser 448
			#回傳結果
449
			return $result;
226 liveuser 450
 
3 liveuser 451
			}#if end
226 liveuser 452
 
3 liveuser 453
		#將資料寫入到檔案裡面
454
		$fwriteResult=fwrite($fileopenResult,$conf["inputString"]);
455
 
456
		#如果 $fwriteResult 等於 FALSE
457
		if($fwriteResult!=0 && $fwriteResult==FALSE){
226 liveuser 458
 
3 liveuser 459
			#設置錯誤識別
460
			$result["status"]="false";
226 liveuser 461
 
3 liveuser 462
			#代表檔案寫入失敗
463
			$result["error"][]="檔案".$conf["fileName"]."寫入失敗";
226 liveuser 464
 
3 liveuser 465
			#回傳結果
466
			return $result;
226 liveuser 467
 
3 liveuser 468
			}#if end
469
 
470
		#存檔並關閉檔案
471
		$fcloseResult=fclose($fileopenResult);
472
 
473
		#如果 $fcloseResult 等於 FALSE
474
		if($fcloseResult==FALSE){
226 liveuser 475
 
3 liveuser 476
			#設置錯誤識別
477
			$result["status"]="false";
226 liveuser 478
 
3 liveuser 479
			#代表檔案寫入失敗
480
			$result["error"][]="檔案".$conf["fileName"]."儲存失敗";
226 liveuser 481
 
3 liveuser 482
			#回傳結果
483
			return $result;
226 liveuser 484
 
3 liveuser 485
			}#if end
486
 
487
		#檢查用來寫入的檔案是否存在
488
		#函式說明:檢查多個檔案與資料夾是否存在
489
		#回傳的結果:
490
		#$result["varName"][$i],爲第$i個變數的名稱。
491
		#$result["varExist"][$i],爲第$i個變數是否存在,true代表存在,false代表不存在。
492
		#必填參數:
493
		$conf["fileAccess::checkMutiFileExist"]["fileArray"]=array($conf["fileName"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
494
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
495
		$conf["fileAccess::checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
496
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false".
497
		$conf["fileAccess::checkMutiFileExist"]["web"]=$conf["web"];
498
		#參考資料來源:
499
		#http:#php.net/manual/en/function.file-exists.php
500
		#http:#php.net/manual/en/control-structures.foreach.php
501
		$fileAccess["checkMutiFileExist"]=fileAccess::checkMultiFileExist($conf["fileAccess::checkMutiFileExist"]);
502
		unset($conf["fileAccess::checkMutiFileExist"]);
503
 
504
		#如果檢查檔案是否存在失敗
505
		if($fileAccess["checkMutiFileExist"]["status"]==="false"){
226 liveuser 506
 
3 liveuser 507
			#設置錯誤識別
508
			$result["status"]="false";
226 liveuser 509
 
3 liveuser 510
			#設置錯誤訊息陣列
511
			$result["error"]=$fileAccess["checkMutiFileExist"];
226 liveuser 512
 
3 liveuser 513
			#回傳結果
514
			return $result;
226 liveuser 515
 
3 liveuser 516
			}#if end
517
 
226 liveuser 518
		#如果$fileAccess["checkMutiFileExist"]["varExist"][0] 等於 "false"
3 liveuser 519
		if($fileAccess["checkMutiFileExist"]["varExist"][0]==="false"){
226 liveuser 520
 
3 liveuser 521
			#設置錯誤識別
522
			$result["status"]="false";
226 liveuser 523
 
3 liveuser 524
			#設置錯誤訊息
525
			$result["error"]=$fileAccess["checkMutiFileExist"];
226 liveuser 526
 
3 liveuser 527
			#設置錯誤訊息陣列
528
			$result["error"][]="愈建立的檔案不存在";
226 liveuser 529
 
3 liveuser 530
			#回傳結果
531
			return $result;
226 liveuser 532
 
3 liveuser 533
			}#if end
226 liveuser 534
 
3 liveuser 535
		#函式說明:
536
		#依據取得檔案的擁有着資訊
537
		#回傳結果:
538
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
539
		#$result["error"],錯誤訊息陣列.
226 liveuser 540
		#$result["function"],函數名稱.
3 liveuser 541
		#$result["content"],檔案擁有着資訊.
542
		#$result["content"],檔案資訊陣列.
226 liveuser 543
		#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 544
		#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
545
		#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
546
		#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
547
		#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
548
		#$result["content"]["ownerName"],檔案擁有着資訊.
549
		#$result["content"]["groupName"],檔案所屬擁有着資訊.
550
		#$result["content"]["size"],檔案大小.
551
		#$result["content"]["modifyDate"],檔案變更年月日.
552
		#$result["content"]["modifyTime"],檔案變更時分秒.
553
		#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
554
		#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
555
		#必填參數:
556
		#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
557
		$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];
558
		#$conf["file"],字串,要查看擁有者資訊的檔案.
559
		$conf["fileAccess::fileInfo"]["file"]=$conf["fileName"];
560
		#可省略參數:
561
		#$conf["fileToRead"],字串,要讀取的檔案名稱為何?預設為"help".
562
		#$conf["fileToRead"]="help";
563
		#$conf["output"],字串,輸出的網頁檔案位置與名稱,副檔名html會自動補上,預設為"help".
226 liveuser 564
		#$conf["output"]="help.html";
3 liveuser 565
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false".
566
		$conf["fileAccess::fileInfo"]["web"]=$conf["web"];
567
		#參考資料:
568
		#fileowner=>http://php.net/manual/en/function.fileowner.php
569
		#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
570
		$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
571
		unset($conf["fileAccess::fileInfo"]);
226 liveuser 572
 
3 liveuser 573
		#如果取得檔案資訊失敗
574
		if($fileInfo["status"]==="false"){
226 liveuser 575
 
3 liveuser 576
			#設置執行失敗
577
			$result["status"]="false";
226 liveuser 578
 
3 liveuser 579
			#設置錯誤訊息
580
			$result["error"]=$fileInfo;
226 liveuser 581
 
3 liveuser 582
			#回傳結果
583
			return $result;
226 liveuser 584
 
220 liveuser 585
			}#if end
226 liveuser 586
 
3 liveuser 587
		#取得檔案的擁有者名稱
588
		$fileOwner=$fileInfo["content"]["ownerName"];
226 liveuser 589
 
3 liveuser 590
		#執行php的帳戶
220 liveuser 591
		$runner=csInformation::runner();
226 liveuser 592
 
3 liveuser 593
		#如果執行php的使用者等於檔案的擁有者名稱或為root
594
		if($runner===$fileOwner || $runner==="root"){
226 liveuser 595
 
3 liveuser 596
			#改變檔案的權限為0770
597
			chmod($conf["fileName"],0770);
226 liveuser 598
 
3 liveuser 599
			}#if end
226 liveuser 600
 
3 liveuser 601
		#執行到這邊代表執行正常
602
		$result["status"]="true";
226 liveuser 603
 
3 liveuser 604
		#回傳結果
605
		return $result;
226 liveuser 606
 
3 liveuser 607
		}#function writeTextIntoFile end
608
 
609
	/*
610
	#函式說明:
611
	#一次建立多個檔案,並寫入內容.
612
	#回傳結果:
613
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
614
	#$result["error"],錯誤訊息陣列.
615
	#$result["function"],當前執行的函數名稱.
616
	#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
617
	#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
618
	#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
619
	#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
620
	#$result["argu"],使用的參數.
621
	#必填參數:
622
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
623
	$conf["fileArgu"]=__FILE__;
624
	#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
625
	$conf["fileName"]=array("");
626
	#可省略參數:
627
	#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
628
	#$conf["inputString"]=array("");
629
	#參考資料:
630
	#無.
631
	#備註:
632
	#無.
633
	*/
634
	public static function writeMultiFile(&$conf){
226 liveuser 635
 
3 liveuser 636
		#初始化要回傳的變數
637
		$result=array();
638
 
639
		#初始化當前執行的函數名稱
640
		$result["function"]=__FUNCTION__;
641
 
642
		#如果 $conf 不為陣列
643
		if(gettype($conf)!="array"){
226 liveuser 644
 
3 liveuser 645
			#設置執行失敗
646
			$result["status"]="false";
226 liveuser 647
 
3 liveuser 648
			#設置執行錯誤訊息
649
			$result["error"][]="\$conf變數須為陣列形態";
650
 
651
			#如果傳入的參數為 null
652
			if($conf==null){
226 liveuser 653
 
3 liveuser 654
				#設置執行錯誤訊息
655
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 656
 
3 liveuser 657
				}#if end
658
 
659
			#回傳結果
660
			return $result;
226 liveuser 661
 
3 liveuser 662
			}#if end
226 liveuser 663
 
3 liveuser 664
		#取得使用的參數
665
		$result["argu"]=$conf;
666
 
667
		#檢查參數
668
		#函式說明:
669
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
670
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
671
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
672
		#$result["function"],當前執行的函式名稱.
673
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
674
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
675
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
676
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
677
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
678
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
679
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
680
		#必填寫的參數:
681
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
682
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
683
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
684
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileName");
226 liveuser 685
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 686
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
687
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
688
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
689
		#可以省略的參數:
690
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
691
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
692
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
693
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("inputString");
226 liveuser 694
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 695
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
696
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
697
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
698
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
699
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("fileName","inputString");
700
		#參考資料來源:
701
		#array_keys=>http://php.net/manual/en/function.array-keys.php
702
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
703
		unset($conf["variableCheck::checkArguments"]);
704
 
705
		#如果 $checkArguments["status"] 等於 "false"
706
		if($checkArguments["status"]=="false"){
226 liveuser 707
 
3 liveuser 708
			#設置錯誤識別
709
			$result["status"]="false";
226 liveuser 710
 
3 liveuser 711
			#設置錯誤訊息
712
			$result["error"]=$checkArguments;
226 liveuser 713
 
3 liveuser 714
			#回傳結果
220 liveuser 715
			return $result;
226 liveuser 716
 
3 liveuser 717
			}#if end
226 liveuser 718
 
3 liveuser 719
		#如果 $checkArguments["passed"] 等於 "false"
720
		if($checkArguments["passed"]=="false"){
226 liveuser 721
 
3 liveuser 722
			#設置錯誤識別
723
			$result["status"]="false";
226 liveuser 724
 
3 liveuser 725
			#設置錯誤訊息
726
			$result["error"]=$checkArguments;
226 liveuser 727
 
3 liveuser 728
			#回傳結果
220 liveuser 729
			return $result;
226 liveuser 730
 
3 liveuser 731
			}#if end
226 liveuser 732
 
3 liveuser 733
		#如果沒有設定要個別寫入的內容
734
		if(!isset($conf["inputString"])){
226 liveuser 735
 
3 liveuser 736
			#針對每個檔案名稱
737
			for($i=0;$i<count($conf["fileName"]);$i++){
226 liveuser 738
 
3 liveuser 739
				#建立空的 $conf["inputString"]
740
				$conf["inputString"][$i]="";
226 liveuser 741
 
3 liveuser 742
				}#for end
226 liveuser 743
 
3 liveuser 744
			}#if end
226 liveuser 745
 
3 liveuser 746
		#針對每個要寫入的檔案
747
		foreach($conf["fileName"] as $index => $file2writre){
226 liveuser 748
 
3 liveuser 749
			#取得要寫入的內容
750
			$content2writre=$conf["inputString"][$index];
226 liveuser 751
 
3 liveuser 752
			#函式說明:
753
			#將字串寫入到檔案
754
			#回傳結果:
755
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
756
			#$result["error"],錯誤訊息陣列.
757
			#$result["function"],當前執行的函數名稱.
758
			#$result["fileInfo"],實際上寫入的檔案資訊陣列.
759
			#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
760
			#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
761
			#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
762
			#$result["argu"],使用的參數.
763
			#必填參數:
764
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
765
			$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
766
			#可省略參數:
767
			#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
768
			$conf["fileAccess::writeTextIntoFile"]["fileName"]=$file2writre;
769
			#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
770
			$conf["fileAccess::writeTextIntoFile"]["inputString"]=$content2writre;
771
			#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
772
			#$conf["writeMethod"]="a";
773
			#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
774
			#$conf["checkRepeat"]="";
775
			#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
776
			#$conf["filenameExtensionStartPoint"]="";
777
			#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
778
			#$conf["repeatNameRule"]="";
779
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
780
			$conf["fileAccess::writeTextIntoFile"]["web"]="false";
781
			#備註:
782
			#無.
783
			$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
784
			unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 785
 
3 liveuser 786
			#如果建立檔案失敗
787
			if($writeTextIntoFile["status"]==="false"){
226 liveuser 788
 
3 liveuser 789
				#設置錯誤識別
790
				$result["status"]="false";
226 liveuser 791
 
3 liveuser 792
				#設置錯誤訊息
793
				$result["error"]=$writeTextIntoFile;
226 liveuser 794
 
3 liveuser 795
				#回傳結果
220 liveuser 796
				return $result;
226 liveuser 797
 
3 liveuser 798
				}#if end
226 liveuser 799
 
3 liveuser 800
			#設置建立好的檔案資訊
220 liveuser 801
			$result["content"][]=$writeTextIntoFile["fileInfo"];
226 liveuser 802
 
3 liveuser 803
			}#foreach end
226 liveuser 804
 
3 liveuser 805
			#設置執行正常
806
			$result["status"]="true";
226 liveuser 807
 
3 liveuser 808
			#回傳結果
226 liveuser 809
			return $result;
810
 
3 liveuser 811
		}#function writeMultiFile end
812
 
813
	/*
814
	#函式說明:
815
	#將多行字串寫入到檔案
816
	#回傳結果:
817
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
818
	#$result["error"],錯誤訊息陣列.
819
	#$result["function"],當前執行函數的名稱.
820
	#必填參數:
821
	#$conf["fileName"],字串,爲要編輯的檔案名稱
822
	$conf["fileName"]="";
823
	#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
824
	$conf["inputString"]=array("");
825
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
826
	$conf["fileArgu"]=__FILE__;
827
	#可省略參數:
220 liveuser 828
	#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
829
	#$conf["writeMethod"]="a";
830
	#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
831
	#$conf["fastWrite"]="false";
3 liveuser 832
	#參考資料:
833
	#無.
834
	#備註:
835
	#無.
836
	*/
837
	public static function writeMultiLine(&$conf){
226 liveuser 838
 
3 liveuser 839
		#初始化要回傳的結果
840
		$result=array();
226 liveuser 841
 
3 liveuser 842
		#取得當前執行的函數
843
		$result["function"]=__FUNCTION__;
844
 
845
		#如果 $conf 不為陣列
846
		if(gettype($conf)!="array"){
226 liveuser 847
 
3 liveuser 848
			#設置執行失敗
849
			$result["status"]="false";
226 liveuser 850
 
3 liveuser 851
			#設置執行錯誤訊息
852
			$result["error"][]="\$conf變數須為陣列形態";
853
 
854
			#如果傳入的參數為 null
855
			if($conf==null){
226 liveuser 856
 
3 liveuser 857
				#設置執行錯誤訊息
858
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 859
 
3 liveuser 860
				}#if end
861
 
862
			#回傳結果
863
			return $result;
226 liveuser 864
 
3 liveuser 865
			}#if end
226 liveuser 866
 
3 liveuser 867
		#檢查必填參數
868
		#函式說明:
869
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
870
		#回傳的結果:
871
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
872
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
873
		#$result["function"],當前執行的函式名稱.
874
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
875
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
876
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
877
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
878
		#必填寫的參數:
879
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
880
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileName","inputString","fileArgu");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
881
		#可以省略的參數:
226 liveuser 882
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","array","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 883
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
884
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
885
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 886
 
3 liveuser 887
		#如果檢查失敗
888
		if($checkResult["status"]=="false"){
226 liveuser 889
 
3 liveuser 890
			#設置執行錯誤
891
			$result["status"]="false";
226 liveuser 892
 
3 liveuser 893
			#設置執行錯誤訊息
894
			$result["error"]=$checkResult;
226 liveuser 895
 
3 liveuser 896
			#回傳結果
897
			return $result;
226 liveuser 898
 
3 liveuser 899
			}#if end
226 liveuser 900
 
3 liveuser 901
		#如果檢查不通過
902
		if($checkResult["passed"]=="false"){
226 liveuser 903
 
3 liveuser 904
			#設置執行錯誤
905
			$result["status"]="false";
226 liveuser 906
 
3 liveuser 907
			#設置執行錯誤訊息
908
			$result["error"]=$checkResult;
226 liveuser 909
 
3 liveuser 910
			#回傳結果
911
			return $result;
226 liveuser 912
 
3 liveuser 913
			}#if end
226 liveuser 914
 
915
		#檢查可省略參數
3 liveuser 916
		#函式說明:
917
		#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
918
		#回傳結果:
919
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
920
		#$result["error"],錯誤訊息陣列.
921
		#$result["function"],當前執行的函式名稱.
922
		#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
923
		#必填參數:
924
		#$conf["variableCheck.checkSkipableVarType"]["checkedVar"],陣列,要檢查的變數陣列名稱為?
925
		$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf;
926
		#$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
220 liveuser 927
		$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array("writeMethod","fastWrite");
3 liveuser 928
		#$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
220 liveuser 929
		$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array("string","string");
3 liveuser 930
		#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
931
		$argu=&$conf;
932
		#可省略參數:
933
		#$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"],字串陣列,每個不存的變數要初始化為什麼,"null"代表不指定.
220 liveuser 934
		$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array("w","false");
3 liveuser 935
		#無
936
		$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
937
		unset($conf["variableCheck.checkSkipableVarType"]);
226 liveuser 938
 
3 liveuser 939
		#如果檢查不通過
940
		if($checkResult["status"]=="false"){
226 liveuser 941
 
3 liveuser 942
			#設置執行錯誤
943
			$result["status"]="false";
226 liveuser 944
 
3 liveuser 945
			#設置執行錯誤訊息
946
			$result["error"]=$checkResult;
226 liveuser 947
 
3 liveuser 948
			#回傳結果
949
			return $result;
226 liveuser 950
 
3 liveuser 951
			}#if end
226 liveuser 952
 
3 liveuser 953
		#如果檢查不通過
954
		if($checkResult["passed"]=="false"){
226 liveuser 955
 
3 liveuser 956
			#設置執行錯誤
957
			$result["status"]="false";
226 liveuser 958
 
3 liveuser 959
			#設置執行錯誤訊息
960
			$result["error"]=$checkResult;
226 liveuser 961
 
3 liveuser 962
			#回傳結果
963
			return $result;
226 liveuser 964
 
3 liveuser 965
			}#if end
966
 
220 liveuser 967
		#如果有設置快速寫入
968
		if($conf["fastWrite"]==="true"){
226 liveuser 969
 
220 liveuser 970
			#初始化要寫入的字串
971
			$inputStrAll="";
226 liveuser 972
 
220 liveuser 973
			#有幾行字要寫就執行幾次
974
			foreach($conf["inputString"] as $inputStr){
975
 
976
				#附加 "\r\n"
977
				$inputStrAll=$inputStrAll.$inputStr.PHP_EOL;
978
 
979
				}#foreach end
226 liveuser 980
 
220 liveuser 981
			#函式說明:
982
			#將字串寫入到檔案
983
			#回傳結果:
984
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
985
			#$result["error"],錯誤訊息陣列.
986
			#必填參數:
987
			$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
988
			$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStrAll;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
989
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
990
			$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
991
			#可省略參數:
992
			$conf["fileAccess.writeTextIntoFile"]["writeMethod"]=$conf["writeMethod"];#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
993
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
994
			$conf["fileAccess.writeTextIntoFile"]["web"]="false";
995
			$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
996
			unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 997
 
220 liveuser 998
			#如果寫入失敗
999
			if($writeStatus["status"]=="false"){
226 liveuser 1000
 
220 liveuser 1001
				#設置執行錯誤
1002
				$result["status"]="false";
226 liveuser 1003
 
220 liveuser 1004
				#設置執行錯誤訊息
1005
				$result["error"]=$writeStatus;
226 liveuser 1006
 
220 liveuser 1007
				#回傳結果
1008
				return $result;
226 liveuser 1009
 
220 liveuser 1010
				}#if end
226 liveuser 1011
 
220 liveuser 1012
			#設置執行正常
1013
			$result["status"]="true";
226 liveuser 1014
 
220 liveuser 1015
			#回傳結果
1016
			return $result;
226 liveuser 1017
 
220 liveuser 1018
			}#if end
1019
 
3 liveuser 1020
		#初始化第一次寫入識別變數
1021
		$firstTimeToWrite="true";
226 liveuser 1022
 
3 liveuser 1023
		#有幾行字要寫就執行幾次
1024
		foreach($conf["inputString"] as $inputStr){
1025
 
1026
			#附加 "\r\n"
1027
			$inputStr=$inputStr.PHP_EOL;
1028
 
1029
			#如果是第一次寫入
1030
			if($firstTimeToWrite=="true"){
226 liveuser 1031
 
3 liveuser 1032
				#如果是要重新寫入
220 liveuser 1033
				if($conf["writeMethod"]==="w"){
226 liveuser 1034
 
3 liveuser 1035
					#函式說明:
1036
					#將字串寫入到檔案
1037
					#回傳結果:
1038
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1039
					#$result["error"],錯誤訊息陣列.
1040
					#必填參數:
1041
					$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
1042
					$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStr;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1043
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1044
					$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1045
					#可省略參數:
1046
					$conf["fileAccess.writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1047
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1048
					$conf["fileAccess.writeTextIntoFile"]["web"]="false";
1049
					$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
1050
					unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 1051
 
3 liveuser 1052
					#如果寫入失敗
1053
					if($writeStatus["status"]=="false"){
226 liveuser 1054
 
3 liveuser 1055
						#設置執行錯誤
1056
						$result["status"]="false";
226 liveuser 1057
 
3 liveuser 1058
						#設置執行錯誤訊息
1059
						$result["error"]=$writeStatus;
226 liveuser 1060
 
3 liveuser 1061
						#回傳結果
1062
						return $result;
226 liveuser 1063
 
3 liveuser 1064
						}#if end
226 liveuser 1065
 
3 liveuser 1066
					}#if end
226 liveuser 1067
 
3 liveuser 1068
				#反之不是重新寫入,而是附加寫入。
1069
				else{
226 liveuser 1070
 
3 liveuser 1071
					#函式說明:
1072
					#將字串寫入到檔案
1073
					#回傳結果:
1074
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1075
					#$result["error"],錯誤訊息陣列.
1076
					#必填參數:
1077
					$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
1078
					$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStr;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1079
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1080
					$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1081
					#可省略參數:
1082
					$conf["fileAccess.writeTextIntoFile"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1083
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1084
					$conf["fileAccess.writeTextIntoFile"]["web"]="false";
1085
					$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
1086
					unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 1087
 
3 liveuser 1088
					#如果寫入失敗
1089
					if($writeStatus["status"]=="false"){
226 liveuser 1090
 
3 liveuser 1091
						#設置執行錯誤
1092
						$result["status"]="false";
226 liveuser 1093
 
3 liveuser 1094
						#設置執行錯誤訊息
1095
						$result["error"]=$writeStatus;
226 liveuser 1096
 
3 liveuser 1097
						#回傳結果
1098
						return $result;
226 liveuser 1099
 
3 liveuser 1100
						}#if end
226 liveuser 1101
 
3 liveuser 1102
					}#else end
226 liveuser 1103
 
3 liveuser 1104
				#將之設為不是第一次寫入
1105
				$firstTimeToWrite="false";
226 liveuser 1106
 
3 liveuser 1107
				}#if end
226 liveuser 1108
 
3 liveuser 1109
			#反之不是第一次寫入
1110
			else{
226 liveuser 1111
 
3 liveuser 1112
				#函式說明:
1113
				#將字串寫入到檔案
1114
				#回傳結果:
1115
				#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1116
				#$result["error"],錯誤訊息陣列.
1117
				#必填參數:
1118
				$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
1119
				$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStr;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1120
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1121
				$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1122
				#可省略參數:
1123
				$conf["fileAccess.writeTextIntoFile"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1124
				#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1125
				$conf["fileAccess.writeTextIntoFile"]["web"]="false";
1126
				$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
1127
				unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 1128
 
3 liveuser 1129
				#如果寫入失敗
1130
				if($writeStatus["status"]=="false"){
226 liveuser 1131
 
3 liveuser 1132
					#設置執行錯誤
1133
					$result["status"]="false";
226 liveuser 1134
 
3 liveuser 1135
					#設置執行錯誤訊息
1136
					$result["error"]=$writeStatus;
226 liveuser 1137
 
3 liveuser 1138
					#回傳結果
1139
					return $result;
226 liveuser 1140
 
3 liveuser 1141
					}#if end
226 liveuser 1142
 
3 liveuser 1143
				}#else end
226 liveuser 1144
 
3 liveuser 1145
			}#foreach end
226 liveuser 1146
 
3 liveuser 1147
		#執行到這邊代表一切正常
1148
		$result["status"]="true";
226 liveuser 1149
 
3 liveuser 1150
		#回傳結果
1151
		return $result;
226 liveuser 1152
 
3 liveuser 1153
		}#function writeMultiLine end
226 liveuser 1154
 
3 liveuser 1155
	/*
1156
	#函式說明:
1157
	#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1158
	#回傳的變數說明:
1159
	#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1160
	#$result["error"],錯誤訊息提示.
374 liveuser 1161
	#$result["fileNotExist"],字串,"true"代表目標檔案不存在;"false"代表目標檔案存在.
1162
	#$result["fileCreated"],字串,"true"代表目標檔案被本函式建立;"false"代表檔案不是透過本函式建立.
3 liveuser 1163
	#$result["function"],當前執行的函數名稱.
1164
	#$result["fileContent"],爲檔案的內容陣列.
1165
	#$result["lineCount"],爲檔案內容總共的行數.
1166
	#$result["fullContent"],為檔案的完整內容.
200 liveuser 1167
	#$result["base64dataOnly"],檔案的base64data.
1168
	#$result["base64data"],為在網頁上給予src參數的數值.
3 liveuser 1169
	#$result["mimeType"],為檔案的mime type.
1170
	#必填參數:
1171
	#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
1172
	$conf["filePositionAndName"]="";
1173
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1174
	$conf["fileArgu"]=__FILE__;
1175
	#可省略參數:
1176
	#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
1177
	#$conf["web"]="true";
1178
	#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
1179
	#$conf["createIfnotExist"]="false";
1180
	#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
1181
	#$conf["autoDeleteSpaceOnEachLineStart"]="false";
1182
	#參考資料:
1183
	#file(),取得檔案內容的行數.
1184
	#file=>http:#php.net/manual/en/function.file.php
1185
	#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1186
	#filesize=>http://php.net/manual/en/function.filesize.php
1187
	#參考資料:
1188
	#無.
1189
	#備註:
1190
	#無.
1191
	*/
249 liveuser 1192
	public static function getFileContent(&$conf){
3 liveuser 1193
 
1194
		#初始化要回傳的內容
1195
		$result=array();
226 liveuser 1196
 
3 liveuser 1197
		#取得當前執行函數名稱
1198
		$result["function"]=__FUNCTION__;
374 liveuser 1199
 
1200
		#設置預設檔案不存在的識別
376 liveuser 1201
		$result["fileNotExist"]="true";
374 liveuser 1202
 
1203
		#設置預設檔案不為本函式所建立
1204
		$result["fileCreated"]="false";
3 liveuser 1205
 
1206
		#如果 $conf 不為陣列
1207
		if(gettype($conf)!="array"){
226 liveuser 1208
 
3 liveuser 1209
			#設置執行失敗
1210
			$result["status"]="false";
226 liveuser 1211
 
3 liveuser 1212
			#設置執行錯誤訊息
1213
			$result["error"][]="\$conf變數須為陣列形態";
1214
 
1215
			#如果傳入的參數為 null
1216
			if($conf==null){
226 liveuser 1217
 
3 liveuser 1218
				#設置執行錯誤訊息
1219
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1220
 
3 liveuser 1221
				}#if end
1222
 
1223
			#回傳結果
1224
			return $result;
226 liveuser 1225
 
3 liveuser 1226
			}#if end
1227
 
1228
		#檢查參數
1229
		#函式說明:
1230
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
1231
		#回傳結果:
1232
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1233
		#$result["error"],執行不正常結束的錯訊息陣列.
1234
		#$result["simpleError"],簡單表示的錯誤訊息.
1235
		#$result["function"],當前執行的函式名稱.
1236
		#$result["argu"],設置給予的參數.
1237
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1238
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1239
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1240
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1241
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1242
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1243
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1244
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1245
		#必填參數:
1246
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1247
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1248
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1249
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1250
		#可省略參數:
1251
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1252
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePositionAndName","fileArgu");
1253
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
1254
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
1255
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1256
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1257
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
1258
		#$conf["canNotBeEmpty"]=array();
1259
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
1260
		#$conf["canBeEmpty"]=array();
1261
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
1262
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("createIfnotExist","web","autoDeleteSpaceOnEachLineStart");
1263
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1264
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("createIfnotExist","web","autoDeleteSpaceOnEachLineStart");
1265
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1266
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1267
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1268
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
1269
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
1270
		#$conf["disallowAllSkipableVarIsEmpty"]="";
1271
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
1272
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
1273
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
1274
		#$conf["disallowAllSkipableVarNotExist"]="";
1275
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1276
		#$conf["arrayCountEqualCheck"][]=array();
1277
		#參考資料:
1278
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1279
		#備註:
1280
		#無.
1281
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1282
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 1283
 
3 liveuser 1284
		#如果檢查出錯
1285
		if($checkArguments["status"]==="false"){
226 liveuser 1286
 
3 liveuser 1287
			#設置執行錯誤識別
1288
			$result["status"]="false";
226 liveuser 1289
 
3 liveuser 1290
			#設置執行錯誤訊息
1291
			$result["error"]=$checkArguments;
226 liveuser 1292
 
3 liveuser 1293
			#回傳結果
1294
			return $result;
226 liveuser 1295
 
3 liveuser 1296
			}#if end
226 liveuser 1297
 
3 liveuser 1298
		#如果檢查參數不通過
1299
		if($checkArguments["passed"]==="false"){
226 liveuser 1300
 
3 liveuser 1301
			#設置執行錯誤識別
1302
			$result["status"]="false";
226 liveuser 1303
 
3 liveuser 1304
			#設置執行錯誤訊息
1305
			$result["error"]=$checkArguments;
226 liveuser 1306
 
3 liveuser 1307
			#回傳結果
1308
			return $result;
226 liveuser 1309
 
3 liveuser 1310
			}#if end
226 liveuser 1311
 
3 liveuser 1312
		#檢查檔案是否存在
1313
		#函式說明:檢查多個檔案與資料夾是否存在
1314
		#回傳的結果:
1315
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1316
		#$result["error"],錯誤訊息陣列.
1317
		#$resutl["function"],當前執行的涵式名稱.
1318
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1319
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
1320
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1321
		#必填參數:
1322
		$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($conf["filePositionAndName"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
1323
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1324
		$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
1325
		#可省略參數:
1326
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1327
		$conf["fileAccess"]["checkMutiFileExist"]["disableWebSearch"]="true";
226 liveuser 1328
 
3 liveuser 1329
		#如果有設置 $conf["web"]
1330
		if(isset($conf["web"])){
226 liveuser 1331
 
3 liveuser 1332
			#設置 web 參數.
1333
			$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
226 liveuser 1334
 
3 liveuser 1335
			}#if end
226 liveuser 1336
 
3 liveuser 1337
		#參考資料來源:
1338
		#http:#php.net/manual/en/function.file-exists.php
1339
		#http:#php.net/manual/en/control-structures.foreach.php
1340
		$fileCheckResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
1341
		unset($conf["fileAccess"]["checkMutiFileExist"]);
1342
 
1343
		#如果檢查檔案是否存在出錯
1344
		if($fileCheckResult["status"]=="false"){
226 liveuser 1345
 
3 liveuser 1346
			#設置執行錯誤識別
1347
			$result["status"]="false";
226 liveuser 1348
 
3 liveuser 1349
			#設置執行錯誤訊息
1350
			$result["error"]=$fileCheckResult;
226 liveuser 1351
 
3 liveuser 1352
			#回傳結果
1353
			return $result;
226 liveuser 1354
 
3 liveuser 1355
			}#if end
1356
 
1357
		#如果該檔案不存在
1358
		if($fileCheckResult["varExist"][0]=="false"){
226 liveuser 1359
 
3 liveuser 1360
			#如果也不要自動建立檔案
1361
			if($conf["createIfnotExist"]==="false"){
226 liveuser 1362
 
3 liveuser 1363
				#設置執行錯誤識別
1364
				$result["status"]="false";
226 liveuser 1365
 
3 liveuser 1366
				#設置執行錯誤訊息
1367
				$result["error"]=$fileCheckResult;
226 liveuser 1368
 
3 liveuser 1369
				#設置易讀的錯誤訊息
1370
				$result["error"][]="名為".$fileCheckResult["varName"][0]."的檔案不存在";
226 liveuser 1371
 
3 liveuser 1372
				#回傳結果
1373
				return $result;
226 liveuser 1374
 
3 liveuser 1375
				}#if end
226 liveuser 1376
 
3 liveuser 1377
			#執行到這邊代表需要建立該檔案
1378
			#函式說明:
1379
			#將字串寫入到檔案
1380
			#回傳結果:
1381
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1382
			#$result["error"],錯誤訊息陣列.
1383
			#$result["function"],當前執行的函數名稱.
1384
			#$result["fileInfo"],實際上寫入的檔案資訊陣列.
1385
			#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
1386
			#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
1387
			#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
1388
			#$result["argu"],使用的參數.
1389
			#必填參數:
1390
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1391
			$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1392
			#可省略參數:
1393
			#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
1394
			$conf["fileAccess::writeTextIntoFile"]["fileName"]=$fileCheckResult["varNameFullPath"][0];
1395
			#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
200 liveuser 1396
			$conf["fileAccess::writeTextIntoFile"]["inputString"]="";
3 liveuser 1397
			#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
1398
			#$conf["checkRepeat"]="";
1399
			#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
1400
			#$conf["filenameExtensionStartPoint"]="";
1401
			#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
1402
			#$conf["repeatNameRule"]="";
226 liveuser 1403
 
3 liveuser 1404
			#如果有設置 $conf["web"]
1405
			if(isset($conf["web"])){
226 liveuser 1406
 
3 liveuser 1407
				#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1408
				$conf["fileAccess::writeTextIntoFile"]["web"]=$conf["web"];
226 liveuser 1409
 
200 liveuser 1410
				}#if end
226 liveuser 1411
 
3 liveuser 1412
			#參考資料:
1413
			#無.
1414
			#備註:
1415
			#無.
1416
			$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
1417
			unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 1418
 
3 liveuser 1419
			#如果建立檔案失敗
1420
			if($writeTextIntoFile["status"]=="false"){
226 liveuser 1421
 
3 liveuser 1422
				#設置執行錯誤識別
1423
				$result["status"]="false";
226 liveuser 1424
 
3 liveuser 1425
				#設置執行錯誤訊息
1426
				$result["error"]=$writeTextIntoFile;
226 liveuser 1427
 
3 liveuser 1428
				#回傳結果
1429
				return $result;
226 liveuser 1430
 
3 liveuser 1431
				}#if end
374 liveuser 1432
 
1433
			#設置檔案存在的識別
376 liveuser 1434
			$result["fileNotExist"]="false";
374 liveuser 1435
 
1436
			#設置檔案為本函式所建立
1437
			$result["fileCreated"]="true";
226 liveuser 1438
 
3 liveuser 1439
			}#if end
374 liveuser 1440
 
1441
		#反之
1442
		else{
1443
 
1444
			#設置檔案存在的識別
376 liveuser 1445
			$result["fileNotExist"]="false";
374 liveuser 1446
 
1447
			}#else end
3 liveuser 1448
 
1449
		#file absolute addr
1450
		$fileAbAddr=$fileCheckResult["varNameFullPath"][0];
226 liveuser 1451
 
3 liveuser 1452
		#將檔案的內容放進變數裡面(會得到陣列)
1453
		$fileContent=file($fileAbAddr);
1454
 
1455
		#如果 $fileContent 等於
376 liveuser 1456
		if($fileContent===FALSE){
3 liveuser 1457
 
376 liveuser 1458
			#設置錯誤識別
1459
			$result["status"]="false";
226 liveuser 1460
 
376 liveuser 1461
			#設置錯誤訊息
1462
			$result["error"][]="讀取檔案失敗";
3 liveuser 1463
 
376 liveuser 1464
			#取得詳細的錯誤訊息
1465
			$result["error"][]=$fileCheckResult;
226 liveuser 1466
 
376 liveuser 1467
			#回傳結果
1468
			return $result;
3 liveuser 1469
 
1470
			}#if end
1471
 
1472
		#針對每行內容
1473
		for($i=0;$i<count($fileContent);$i++){
226 liveuser 1474
 
3 liveuser 1475
			#剔除字串尾的換行符號
1476
			$fileContent[$i]=rtrim($fileContent[$i]);
226 liveuser 1477
 
3 liveuser 1478
			#如果要移除開頭的空白
1479
			if($conf["autoDeleteSpaceOnEachLineStart"]==="true"){
226 liveuser 1480
 
3 liveuser 1481
				#如果開頭是空格
1482
				while(strpos($fileContent[$i]," ")===0){
226 liveuser 1483
 
3 liveuser 1484
					#函式說明:
1485
					#將字串特定關鍵字與其前面的內容剔除
1486
					#回傳結果:
1487
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1488
					#$result["error"],錯誤訊息陣列.
1489
					#$result["warning"],警告訊息鎮列.
1490
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
1491
					#$result["function"],當前執行的函數名稱.
1492
					#$result["argu"],使用的參數.
1493
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 1494
					#$result["content"],處理好的的字串內容.
3 liveuser 1495
					#必填參數:
1496
					#$conf["stringIn"],字串,要處理的字串.
1497
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$fileContent[$i];
1498
					#$conf["keyWord"],字串,特定字串.
1499
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
1500
					#可省略參數:
1501
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
1502
					#$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
1503
					#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
1504
					#$conf["lastResult"]=$delStrBeforeKeyWord;
1505
					#參考資料:
1506
					#無.
1507
					#備註:
1508
					#無.
1509
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
1510
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 1511
 
3 liveuser 1512
					#如果建立檔案失敗
1513
					if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 1514
 
3 liveuser 1515
						#設置執行錯誤識別
1516
						$result["status"]="false";
226 liveuser 1517
 
3 liveuser 1518
						#設置執行錯誤訊息
1519
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 1520
 
3 liveuser 1521
						#回傳結果
1522
						return $result;
226 liveuser 1523
 
3 liveuser 1524
						}#if end
226 liveuser 1525
 
3 liveuser 1526
					#取得剔除開頭空格後的內容
1527
					$fileContent[$i]=$delStrBeforeKeyWord["content"];
226 liveuser 1528
 
3 liveuser 1529
					}#while end
226 liveuser 1530
 
3 liveuser 1531
				}#if end
226 liveuser 1532
 
3 liveuser 1533
			}#for end
1534
 
1535
		#取得總共有幾行
1536
		$lineCount=count($fileContent);
1537
 
1538
		#將檔案內容的陣列放進 $result 陣列變數裏面
1539
		$result["fileContent"]=$fileContent;
226 liveuser 1540
 
3 liveuser 1541
		#建立暫存檔案
1542
		$tmpFile=tempnam("/tmp", "qbpwcf");
226 liveuser 1543
 
3 liveuser 1544
		#讀取要取得的檔案內容
1545
		$content=file_get_contents($fileAbAddr);
226 liveuser 1546
 
3 liveuser 1547
		#開啟暫存檔案(寫入模式)
1548
		$file=fopen($tmpFile,'w');
226 liveuser 1549
 
3 liveuser 1550
		#寫入讀取到的內容
1551
		fwrite($file,$content);
226 liveuser 1552
 
3 liveuser 1553
		#關閉暫存檔案
1554
		fclose($file);
226 liveuser 1555
 
3 liveuser 1556
		#取得檔案的 mime 類型
1557
		$mimeType=mime_content_type($tmpFile);
226 liveuser 1558
 
3 liveuser 1559
		#設置檔案的mime類型
1560
		$result["mimeType"]=$mimeType;
226 liveuser 1561
 
3 liveuser 1562
		#取得檔案的內容為字串
1563
		$result["fullContent"]=file_get_contents($tmpFile);
226 liveuser 1564
 
3 liveuser 1565
		#取得檔案的base64data
200 liveuser 1566
		$result["base64dataOnly"]=base64_encode($result["fullContent"]);
226 liveuser 1567
 
200 liveuser 1568
		#取得檔案用 data:mimeType;base64,base64data 表示的字串
203 liveuser 1569
		$result["base64data"]="data:".$result["mimeType"].";base64,".$result["base64dataOnly"];
226 liveuser 1570
 
3 liveuser 1571
		#移除暫存檔案
1572
		unlink($tmpFile);
226 liveuser 1573
 
3 liveuser 1574
		#將檔案內容的行數放進 $result 陣列變數裏面
1575
		$result["lineCount"]=$lineCount;
1576
 
1577
		#執行到這邊代表執行成功
1578
		$result["status"]="true";
1579
 
1580
		#回傳結果
1581
		return $result;
1582
 
1583
		}#function getFileContent end
1584
 
1585
	/*
1586
	#函式說明:
1587
	#依據逗號分隔抓取檔案的內容,結果會回傳一個陣列
226 liveuser 1588
	#回傳結果:
3 liveuser 1589
	#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1590
	#$result["error"],錯誤訊息提示.
1591
	#$result["function"],函數名稱.
1592
	#$result["lineCount"]爲總共有幾行
1593
	#$result["lineContent"][i]["dataCounts"],爲第 i+1 行總共有幾個字串
1594
	#$result["lineContent"][0][i],爲第1行第 i+1 個分割好的字串
1595
	#$result["lineContent"][1][i],爲第2行第 i+1 個分割好的字串
1596
	#必填參數:
1597
	#$conf["filePositionAndName"],字串,要抓取的檔案位置與名稱
1598
	$conf["filePositionAndName"]="";
1599
	#可省略參數:
1600
	#$conf["spiltSign"],字串,爲要用來分割字串的符號,可省略,預設爲「,」
1601
	#$conf["spiltSign"]="";
1602
	#參考資料:
1603
	#無.
1604
	#備註:
1605
	#無.
1606
	*/
249 liveuser 1607
	public static function getFileContentSpiltBySomething(&$conf){
3 liveuser 1608
 
1609
		#初始化要回傳的內容
1610
		$result=array();
226 liveuser 1611
 
3 liveuser 1612
		#取得當前執行函數名稱
1613
		$result["function"]=__FUNCTION__;
1614
 
1615
		#如果 $conf 不為陣列
1616
		if(gettype($conf)!="array"){
226 liveuser 1617
 
3 liveuser 1618
			#設置執行失敗
1619
			$result["status"]="false";
226 liveuser 1620
 
3 liveuser 1621
			#設置執行錯誤訊息
1622
			$result["error"][]="\$conf變數須為陣列形態";
1623
 
1624
			#如果傳入的參數為 null
1625
			if($conf==null){
226 liveuser 1626
 
3 liveuser 1627
				#設置執行錯誤訊息
1628
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1629
 
3 liveuser 1630
				}#if end
1631
 
1632
			#回傳結果
1633
			return $result;
226 liveuser 1634
 
3 liveuser 1635
			}#if end
1636
 
1637
		#如果 $conf["spiltSign"] 爲空,則預設爲","。
1638
		if(!isset($conf["spiltSign"])){
1639
 
1640
			$conf["spiltSign"]=",";
1641
 
1642
			}#if end
1643
 
1644
		#依據行號抓取所有的內容
1645
		#函式說明:
1646
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1647
		#回傳的變數說明:
1648
		#$result["fileContent"],爲檔案的內容陣列
1649
		#$result["lineCount"],爲檔案內容總共的行數
1650
		#必填參數:
1651
		$conf["fileAccess"]["getFileContent"]["filePositionAndName"]=$conf["filePositionAndName"];#爲檔案的位置以及名稱
1652
		#參考資料:
1653
		#file():取得檔案內容的行數
1654
		#http:#php.net/manual/en/function.file.php
1655
		$fileContent=fileAccess::getFileContent($conf["fileAccess"]["getFileContent"]);
1656
		unset($conf["fileAccess"]["getFileContent"]);
1657
 
1658
		#如果取得檔案內容失敗
1659
		if($fileContent["status"]=="false"){
226 liveuser 1660
 
3 liveuser 1661
			#設置執行失敗
1662
			$result["status"]="false";
226 liveuser 1663
 
3 liveuser 1664
			#設置執行錯誤訊息
1665
			$result["error"]=$fileContent;
1666
 
1667
			#回傳結果
1668
			return $result;
226 liveuser 1669
 
3 liveuser 1670
			}#if end
1671
 
1672
		#迴圈,有幾行資料就執行幾次
1673
		for($i=0;$i<$fileContent["lineCount"];$i++){
1674
 
1675
			#將該行內容用逗號分隔
1676
			$conf["stringProcess"]["spiltString"]["stringIn"]=$fileContent["fileContent"][$i];#要處理的字串。
1677
			$conf["stringProcess"]["spiltString"]["spiltSymbol"]=$conf["spiltSign"];#爲以哪個符號作爲分割
1678
			$lineSpiltResult[$i]=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
226 liveuser 1679
			unset($conf["stringProcess"]["spiltString"]);
3 liveuser 1680
 
1681
			#如果分割字串失敗
1682
			if($lineSpiltResult[$i]["status"]=="false"){
226 liveuser 1683
 
3 liveuser 1684
				#設置執行失敗
1685
				$result["status"]="false";
226 liveuser 1686
 
3 liveuser 1687
				#設置執行錯誤訊息
1688
				$result["error"]=$lineSpiltResult[$i];
1689
 
1690
				#回傳結果
1691
				return $result;
226 liveuser 1692
 
3 liveuser 1693
				}#if end
1694
 
1695
			}#for end
1696
 
1697
		#取得
1698
		$result["lineContent"]=$lineSpiltResult;
1699
 
1700
		#取得資料的行數
1701
		$result["lineCount"]=$fileContent["lineCount"];
1702
 
1703
		#回傳結果
1704
		return $result;
226 liveuser 1705
 
3 liveuser 1706
		}#function getFileContentSpiltBySomething end
1707
 
1708
	/*
1709
	#函式說明:
1710
	#檢查多個檔案與資料夾是否存在.
1711
	#回傳的結果:
1712
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1713
	#$result["error"],錯誤訊息陣列.
1714
	#$resutl["function"],當前執行的涵式名稱.
1715
	#$result["argu"],使用的參數.
1716
	#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1717
	#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
1718
	#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
1719
	#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
1720
	#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1721
	#必填參數:
1722
	#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
1723
	$conf["fileArray"]=array();
1724
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1725
	$conf["fileArgu"]=__FILE__;
1726
	#可省略參數:
1727
	#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1728
	#$conf["disableWebSearch"]="false";
1729
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
1730
	#$conf["userDir"]="true";
1731
	#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
1732
	#$conf["web"]="true";
1733
	#參考資料:
1734
	#http://php.net/manual/en/function.file-exists.php
1735
	#http://php.net/manual/en/control-structures.foreach.php
1736
	#備註:
1737
	#函數file_exists檢查的路徑為檔案系統的路徑
1738
	#$result["varName"][$i]結果未實作
1739
	*/
1740
	public static function checkMultiFileExist(&$conf){
226 liveuser 1741
 
3 liveuser 1742
		#初始化要回傳的變數
1743
		$result=array();
226 liveuser 1744
 
3 liveuser 1745
		#設置當前執行的涵式
1746
		$result["function"]=__FUNCTION__;
226 liveuser 1747
 
3 liveuser 1748
		#如果 $conf 不為陣列
1749
		if(gettype($conf)!="array"){
226 liveuser 1750
 
3 liveuser 1751
			#設置執行失敗
1752
			$result["status"]="false";
226 liveuser 1753
 
3 liveuser 1754
			#設置執行錯誤訊息
1755
			$result["error"][]="\$conf變數須為陣列形態";
1756
 
1757
			#如果傳入的參數為 null
1758
			if($conf==null){
226 liveuser 1759
 
3 liveuser 1760
				#設置執行錯誤訊息
1761
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1762
 
3 liveuser 1763
				}#if end
1764
 
1765
			#回傳結果
1766
			return $result;
226 liveuser 1767
 
3 liveuser 1768
			}#if end
226 liveuser 1769
 
3 liveuser 1770
		#取得使用的參數
1771
		$result["argu"]=$conf;
226 liveuser 1772
 
3 liveuser 1773
		#檢查參數
1774
		#函式說明:
1775
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1776
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1777
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1778
		#$result["function"],當前執行的函式名稱.
1779
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1780
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1781
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1782
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
1783
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1784
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1785
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1786
		#必填寫的參數:
1787
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1788
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1789
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1790
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArray","fileArgu");
226 liveuser 1791
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 1792
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
1793
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1794
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1795
		#可以省略的參數:
1796
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1797
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1798
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1799
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("disableWebSearch","userDir","web");
226 liveuser 1800
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 1801
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1802
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1803
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true","true","true");
1804
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1805
		#$conf["arrayCountEqualCheck"][]=array();
1806
		#參考資料來源:
1807
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1808
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1809
		unset($conf["variableCheck::checkArguments"]);
1810
 
1811
		#如果 $checkArguments["status"] 等於 "false"
1812
		if($checkArguments["status"]=="false"){
226 liveuser 1813
 
3 liveuser 1814
			#設置錯誤識別
1815
			$result["status"]="false";
226 liveuser 1816
 
3 liveuser 1817
			#設置錯誤訊息
1818
			$result["error"]=$checkArguments;
226 liveuser 1819
 
3 liveuser 1820
			#回傳結果
42 liveuser 1821
			return $result;
226 liveuser 1822
 
3 liveuser 1823
			}#if end
226 liveuser 1824
 
3 liveuser 1825
		#如果 $checkArguments["passed"] 等於 "false"
1826
		if($checkArguments["passed"]=="false"){
226 liveuser 1827
 
3 liveuser 1828
			#設置錯誤識別
1829
			$result["status"]="false";
226 liveuser 1830
 
3 liveuser 1831
			#設置錯誤訊息
1832
			$result["error"]=$checkArguments;
226 liveuser 1833
 
3 liveuser 1834
			#回傳結果
42 liveuser 1835
			return $result;
226 liveuser 1836
 
3 liveuser 1837
			}#if end
226 liveuser 1838
 
3 liveuser 1839
		#初始化儲存每個檔案是否存在的陣列變數
1840
		$result["varName"]=array();
1841
		$result["varExist"]=array();
1842
 
1843
		#針對每個要檢查的檔案
1844
		foreach($conf["fileArray"] as $i=>$varName){
226 liveuser 1845
 
3 liveuser 1846
			#儲存要判斷是否存在的物件
1847
			$result["varName"][]=$varName;
226 liveuser 1848
 
3 liveuser 1849
			#函式說明:
1850
			#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
1851
			#回傳結果:
1852
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1853
			#$result["error"],錯誤訊息陣列.
226 liveuser 1854
			#$result["function"],函數名稱.
3 liveuser 1855
			#$result["argu"],使用的參數.
1856
			#$result["content"],網址,若是在命令列執行,則為"null".
1857
			#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
1858
			#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
1859
			#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
1860
			#必填參數:
1861
			#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
1862
			$conf["fileAccess::getInternetAddressV2"]["address"]=$varName;
1863
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1864
			$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
1865
			#可省略參數:
1866
			$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
1867
			#備註:
1868
			#建構中,fileSystemRelativePosition尚未實作.
1869
			$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
1870
			unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 1871
 
3 liveuser 1872
			#如果轉換成絕對路徑失敗
1873
			if($getInternetAddressV2["status"]=="false"){
226 liveuser 1874
 
3 liveuser 1875
				#設置錯誤識別
1876
				$result["status"]="false";
226 liveuser 1877
 
3 liveuser 1878
				#設置錯誤訊息
1879
				$result["error"]=$getInternetAddressV2;
226 liveuser 1880
 
3 liveuser 1881
				#回傳結果
1882
				return $result;
226 liveuser 1883
 
3 liveuser 1884
				}#if end
226 liveuser 1885
 
3 liveuser 1886
			#傳參考
1887
			$getInternetAddress=&$getInternetAddressV2;
226 liveuser 1888
 
3 liveuser 1889
			#如果沒有檔案的絕對路徑位置
1890
			if(!isset($getInternetAddress["fileSystemAbsoulutePosition"])){
226 liveuser 1891
 
3 liveuser 1892
				#置換成給予的參數網址
1893
				$conf["fileArray"][$i]=$getInternetAddress["content"];
226 liveuser 1894
 
3 liveuser 1895
				#設置無法從檔案系統找到
1896
				$exist=FALSE;
226 liveuser 1897
 
3 liveuser 1898
				}#if end
226 liveuser 1899
 
3 liveuser 1900
			#反之取得
1901
			else{
226 liveuser 1902
 
3 liveuser 1903
				#轉換好的絕對路徑
1904
				$conf["fileArray"][$i]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 1905
 
42 liveuser 1906
				#無窮迴圈
1907
				while(true){
226 liveuser 1908
 
42 liveuser 1909
					#判斷該檔案是否存在
1910
					$exist=file_exists($conf["fileArray"][$i]);
226 liveuser 1911
 
42 liveuser 1912
					#如果不存在
1913
					if($exist===false){
226 liveuser 1914
 
42 liveuser 1915
						#無窮迴圈
1916
						while(true){
226 liveuser 1917
 
42 liveuser 1918
							#當要檢查的目標是 link 時
1919
							if(is_link($conf["fileArray"][$i])){
226 liveuser 1920
 
42 liveuser 1921
								#取得link的路徑
1922
								$conf["fileArray"][$i]=readlink($conf["fileArray"][$i]);
226 liveuser 1923
 
42 liveuser 1924
								#結束連結的判斷,回到判斷目標是否存在的地方.
1925
								continue 2;
226 liveuser 1926
 
42 liveuser 1927
								}#if end
226 liveuser 1928
 
42 liveuser 1929
							#結束連結的判斷
1930
							break;
226 liveuser 1931
 
42 liveuser 1932
							}#while end
226 liveuser 1933
 
42 liveuser 1934
						}#if end
226 liveuser 1935
 
42 liveuser 1936
					#結束到判斷目標是否存在
1937
					break;
226 liveuser 1938
 
42 liveuser 1939
					}#while end
226 liveuser 1940
 
3 liveuser 1941
				}#else end
226 liveuser 1942
 
3 liveuser 1943
			#如果 $exist 等於 false (檔案不存在) 且 沒有停用網路搜尋功能
1944
			if($exist===FALSE && $conf["disableWebSearch"]==="false"){
1945
 
1946
				#將目標轉換成網址
1947
				#函式說明:
1948
				#將檔案的位置名稱變成網址
1949
				#回傳結果:
1950
				#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1951
				#$result["error"],錯誤訊息陣列.
226 liveuser 1952
				#$result["function"],函數名稱.
3 liveuser 1953
				#$result["content"],網址.
1954
				#必填參數:
1955
				#$conf["address"],字串,檔案的相對位置.
1956
				$conf["fileAccess::getInternetAddress"]["address"]=$conf["fileArray"][$i];
1957
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1958
				$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
1959
				$getInternetAddress=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddress"]);
1960
				unset($conf["fileAccess::getInternetAddress"]);
1961
 
1962
				#如果轉換失敗
1963
				if($getInternetAddress["status"]=="false"){
226 liveuser 1964
 
3 liveuser 1965
					#設置錯誤識別
1966
					$result["status"]="false";
226 liveuser 1967
 
3 liveuser 1968
					#設置錯誤訊息
1969
					$result["error"]=$getInternetAddress;
226 liveuser 1970
 
3 liveuser 1971
					#回傳結果
226 liveuser 1972
					return $result;
1973
 
3 liveuser 1974
					}#if end
226 liveuser 1975
 
3 liveuser 1976
				#函式說明:
1977
				#運行curl cmd
1978
				#回傳結果:
1979
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1980
				#$result["error"],錯誤訊息陣列.
1981
				#$result["function"],當前執行的函式名稱.
1982
				#$result["content"],取得的回應內容.
1983
				#$result["cookie"],cookie檔案的位置與名稱.
1984
				#$result["cmd"],執行的command.
1985
				#$result["argu],使用的參數.
1986
				#必填參數:
1987
				#$conf["url"],字串,目標url.
1988
				$conf["catchWebContent::curlCmd"]["url"]=$getInternetAddress["content"];
1989
				#$conf["fileArgu"],字串,變數__FILE__的內容.
1990
				$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
1991
				#可省略參數:
1992
				#$conf["header"],字串陣列,要傳送的header.
1993
				#$conf["header"]=array();
1994
				#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
1995
				#$conf["allowAnySSLcertificate"]="";
1996
				#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
1997
				#$conf["postVar"]=array();
1998
				#$conf["rawPost"]="字串",要傳送的raw post內容.
1999
				#$conf["rawPost"]="";
2000
				#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
2001
				#$conf["urlEncode"]="false";
2002
				#$conf["agent"],字串,user agent的名稱.
2003
				#$conf["agent"]="";
2004
				#$conf["cookie"],字串,cookie位置與檔案位置.
2005
				#$conf["cookie"]="";
2006
				#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
2007
				#$conf["forceNewCookie"]="";
2008
				$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
2009
				unset($conf["catchWebContent::curlCmd"]);
226 liveuser 2010
 
3 liveuser 2011
				#如果抓取資料失敗
2012
				if($curlCmd["status"]==="false"){
226 liveuser 2013
 
3 liveuser 2014
					#設置錯誤識別
2015
					$result["status"]="false";
226 liveuser 2016
 
3 liveuser 2017
					#設置錯誤訊息
2018
					$result["error"]=$curlCmd;
226 liveuser 2019
 
3 liveuser 2020
					#回傳結果
2021
					return $result;
226 liveuser 2022
 
3 liveuser 2023
					}#if end
226 liveuser 2024
 
3 liveuser 2025
				#反之檔案存在網路上
2026
				else{
226 liveuser 2027
 
3 liveuser 2028
					#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2029
					$result["varName"][$i]=$getInternetAddress["content"];
226 liveuser 2030
 
3 liveuser 2031
					#如果存在檔案路徑的絕對位置
2032
					if(isset($getInternetAddress["fileSystemAbsoulutePosition"])){
226 liveuser 2033
 
42 liveuser 2034
						#設置該檔案的絕對路徑位置
3 liveuser 2035
						$result["varNameFullPath"][$i]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 2036
 
3 liveuser 2037
						}#if end
226 liveuser 2038
 
2039
					#反之代表輸入參數是網址
3 liveuser 2040
					else{
226 liveuser 2041
 
3 liveuser 2042
						#設置該檔案的網址
2043
						$result["varNameWebPath"][$i]=$getInternetAddress["content"];
226 liveuser 2044
 
3 liveuser 2045
						}#else end
226 liveuser 2046
 
3 liveuser 2047
					#設置有無找到的識別
2048
					$result["varExist"][$i]=$curlCmd["founded"];
226 liveuser 2049
 
3 liveuser 2050
					}#else end
226 liveuser 2051
 
3 liveuser 2052
				}#if end
2053
 
2054
			#反之檔案不存在,且停用網路搜尋.
2055
			else if($exist===FALSE){
226 liveuser 2056
 
3 liveuser 2057
				#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2058
				$result["varName"][$i]=$conf["fileArray"][$i];
2059
				$result["varNameFullPath"][$i]=$conf["fileArray"][$i];
2060
				$result["varExist"][$i]="false";
2061
 
2062
				#設置全部檔案都存在的識別變數為 "false"
2063
				$result["allExist"]="false";
226 liveuser 2064
 
3 liveuser 2065
				}#if end
2066
 
2067
			#反之代表檔案存在
2068
			else{
226 liveuser 2069
 
3 liveuser 2070
				#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2071
				$result["varNameFullPath"][$i]=$conf["fileArray"][$i];
226 liveuser 2072
 
3 liveuser 2073
				#如果 web 參數為 "true"
2074
				if($conf["web"]==="true"){
226 liveuser 2075
 
3 liveuser 2076
					#設置網路上的位置
2077
					$result["varNameWebPath"][$i]=$getInternetAddress["content"];
226 liveuser 2078
 
3 liveuser 2079
					}#if end
226 liveuser 2080
 
3 liveuser 2081
				$result["varExist"][$i]="true";
2082
 
2083
				}#else end
226 liveuser 2084
 
3 liveuser 2085
			}#foreach end
226 liveuser 2086
 
3 liveuser 2087
		#如果所有檔案與資料夾都找到的識別變數不存在
2088
		if(!isset($result["allExist"])){
226 liveuser 2089
 
3 liveuser 2090
			#設置全部檔案與資料夾都有找到
2091
			$result["allExist"]="true";
226 liveuser 2092
 
3 liveuser 2093
			}#if end
2094
 
2095
		#執行到這邊代表執行正常
2096
		$result["status"]="true";
2097
 
2098
		#回傳結果
2099
		return $result;
2100
 
2101
		}#function checkMutiFileExist
2102
 
2103
	/*
2104
	#函式說明:
2105
	#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
2106
	#回傳結果:
2107
	#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
2108
	#$result["error"],錯誤訊息陣列.
2109
	#$result["function"],當前執行的函數名稱.
2110
	#$result["argu"],使用的參數.
2111
	#$result["createdFileName"],建立好的檔案名稱.
2112
	#$result["createdFilePath"],檔案建立的路徑.
2113
	#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
2114
	#必填參數:
2115
	#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
2116
	$conf["checkedFileAndPath"]="";
2117
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2118
	$conf["fileArgu"]=__FILE__;
2119
	#可省略參數:
2120
	#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點.
2121
	#$conf["filenameExtensionStartPoint"]="";
2122
	#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)".
2123
	#$conf["repeatNameRule"]="";
2124
	#$conf["web"],"true"代表為網頁系統,"false"代表檔案系統,預設為"false".
2125
	#$conf["web"]="false";
2126
	#參考資料:
2127
	#無.
2128
	#備註:
2129
	#如果要在/tmp底下建立檔案,若在apache環境下則會被作業系統特殊處理,即不等於實際上的路徑.
2130
	*/
2131
	public static function createFileAfterCheck(&$conf){
226 liveuser 2132
 
3 liveuser 2133
		#初始化要回傳的結果
2134
		$result=array();
226 liveuser 2135
 
3 liveuser 2136
		#設置當前執行的涵式
2137
		$result["function"]=__FUNCTION__;
226 liveuser 2138
 
3 liveuser 2139
		#如果 $conf 不為陣列
2140
		if(gettype($conf)!="array"){
226 liveuser 2141
 
3 liveuser 2142
			#設置執行失敗
2143
			$result["status"]="false";
226 liveuser 2144
 
3 liveuser 2145
			#設置執行錯誤訊息
2146
			$result["error"][]="\$conf變數須為陣列形態";
2147
 
2148
			#如果傳入的參數為 null
2149
			if($conf==null){
226 liveuser 2150
 
3 liveuser 2151
				#設置執行錯誤訊息
2152
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 2153
 
3 liveuser 2154
				}#if end
2155
 
2156
			#回傳結果
2157
			return $result;
226 liveuser 2158
 
3 liveuser 2159
			}#if end
226 liveuser 2160
 
3 liveuser 2161
		#取得參數
2162
		$result["argu"]=$conf;
226 liveuser 2163
 
3 liveuser 2164
		#檢查參數
2165
		#函式說明:
2166
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2167
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2168
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2169
		#$result["function"],當前執行的函式名稱.
2170
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2171
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2172
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2173
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2174
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2175
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2176
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2177
		#必填寫的參數:
2178
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2179
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2180
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2181
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","checkedFileAndPath");
226 liveuser 2182
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 2183
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
2184
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2185
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2186
		#可以省略的參數:
2187
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2188
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2189
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2190
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("filenameExtensionStartPoint","repeatNameRule","web");
226 liveuser 2191
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 2192
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
2193
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2194
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("1","(\$i)","false");
2195
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2196
		#$conf["arrayCountEqualCheck"][]=array();
2197
		#參考資料來源:
2198
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2199
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2200
		unset($conf["variableCheck::checkArguments"]);
2201
 
2202
		#如果 $checkArguments["status"] 等於 "false"
2203
		if($checkArguments["status"]=="false"){
226 liveuser 2204
 
3 liveuser 2205
			#設置錯誤識別
2206
			$result["status"]="false";
226 liveuser 2207
 
3 liveuser 2208
			#設置錯誤訊息
2209
			$result["error"]=$checkArguments;
226 liveuser 2210
 
3 liveuser 2211
			#回傳結果
226 liveuser 2212
			return $result;
2213
 
3 liveuser 2214
			}#if end
226 liveuser 2215
 
3 liveuser 2216
		#如果 $checkArguments["passed"] 等於 "false"
2217
		if($checkArguments["passed"]=="false"){
226 liveuser 2218
 
3 liveuser 2219
			#設置錯誤識別
2220
			$result["status"]="false";
226 liveuser 2221
 
3 liveuser 2222
			#設置錯誤訊息
2223
			$result["error"]=$checkArguments;
226 liveuser 2224
 
3 liveuser 2225
			#回傳結果
226 liveuser 2226
			return $result;
2227
 
2228
			}#if end
2229
 
3 liveuser 2230
		#確保要建立檔案的路徑
2231
		#函式說明:
2232
		#確保路徑存在.
2233
		#回傳結果:
2234
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
2235
		#$result["error"],錯誤訊息陣列.
2236
		#$resutl["function"],當前執行的涵式名稱.
2237
		#$result["path"],建立好的路徑字串.
2238
		#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
2239
		#必填參數:
2240
		#$conf["path"],要檢查的路徑
226 liveuser 2241
		$conf["fileAccess::validatePath"]["path"]=$conf["checkedFileAndPath"];
3 liveuser 2242
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2243
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
2244
		#可省略參數:
2245
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
2246
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
2247
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
2248
		#$conf["dirPermission"]="";
2249
		$conf["fileAccess::validatePath"]["web"]=$conf["web"];
2250
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
226 liveuser 2251
		unset($conf["fileAccess::validatePath"]);
2252
 
3 liveuser 2253
		#debug
2254
		#var_dump($validatePath);
226 liveuser 2255
		#exit;
2256
 
3 liveuser 2257
		#如果確保路徑失敗
2258
		if($validatePath["status"]==="false"){
226 liveuser 2259
 
3 liveuser 2260
			#設置錯誤識別
2261
			$result["status"]="false";
226 liveuser 2262
 
3 liveuser 2263
			#設置錯誤訊息
2264
			$result["error"]=$validatePath;
226 liveuser 2265
 
3 liveuser 2266
			#回傳結果
2267
			return $result;
226 liveuser 2268
 
3 liveuser 2269
			}#if end
226 liveuser 2270
 
3 liveuser 2271
		#取得要建立的檔案名稱
2272
		$createdFileName=$validatePath["fileName"];
226 liveuser 2273
 
2274
		#取得要建立的路徑
3 liveuser 2275
		$createdFilePath=$validatePath["path"];
226 liveuser 2276
 
3 liveuser 2277
		#透過無窮迴圈嘗試建立不同編號的檔案
2278
		for($i=0;$i>-1;$i++){
226 liveuser 2279
 
3 liveuser 2280
			#如果 $i 為 0
2281
			if($i==0){
226 liveuser 2282
 
3 liveuser 2283
				#檢查該檔案是否存在
2284
				#函式說明:
2285
				#檢查多個檔案與資料夾是否存在.
2286
				#回傳的結果:
2287
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
2288
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2289
				#必填參數:
2290
				$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($createdFilePath."/".$createdFileName);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
2291
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2292
				$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
2293
				#參考資料來源:
2294
				#http://php.net/manual/en/function.file-exists.php
2295
				#http://php.net/manual/en/control-structures.foreach.php
2296
				$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
2297
				$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
2298
				unset($conf["fileAccess"]["checkMutiFileExist"]);
226 liveuser 2299
 
3 liveuser 2300
				#debug
2301
				#var_dump($checkResult);
2302
				#exit;
226 liveuser 2303
 
3 liveuser 2304
				#如果檢查檔案是否存在失敗
2305
				if($checkResult["status"]=="false"){
226 liveuser 2306
 
3 liveuser 2307
					#設置執行失敗
2308
					$result["status"]="false";
226 liveuser 2309
 
3 liveuser 2310
					#設置錯誤訊息
2311
					$result["error"]=$checkResult;
226 liveuser 2312
 
3 liveuser 2313
					#回傳結果
2314
					return $result;
226 liveuser 2315
 
3 liveuser 2316
					}#if end
226 liveuser 2317
 
3 liveuser 2318
				#如果 $createFilePath.$createdFileName 檔案存在
2319
				if($checkResult["varExist"][0]=="true"){
226 liveuser 2320
 
3 liveuser 2321
					#跳過這次迴圈
2322
					continue;
226 liveuser 2323
 
3 liveuser 2324
					}#if end
226 liveuser 2325
 
3 liveuser 2326
				#反之代表 $createFilePath.$createdFileName 檔案不存在
2327
				else{
226 liveuser 2328
 
3 liveuser 2329
					#嘗試建立該檔案
2330
					#函式說明:
2331
					#將字串寫入到檔案
2332
					#回傳結果:
2333
					#$result["status"],true表示檔案寫入成功,false表示檔案寫入失敗.
2334
					#$result["error"],錯誤訊息陣列.
2335
					#必填參數:
2336
					$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$createdFilePath."/".$createdFileName;#爲要編輯的檔案名稱
2337
					$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
2338
					$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
2339
					#可省略參數:
2340
					$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
2341
					$conf["fileAccess"]["writeTextIntoFile"]["web"]=$conf["web"];
2342
					$fileCreateResult=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
2343
					unset($conf["fileAccess"]["writeTextIntoFile"]);
226 liveuser 2344
 
3 liveuser 2345
					#如果 $fileCreateResult["status"] 等於 "true"
2346
					if($fileCreateResult["status"]=="true"){
226 liveuser 2347
 
3 liveuser 2348
						#代表檔案建立成功
226 liveuser 2349
 
3 liveuser 2350
						#更新建立的檔案名稱
2351
						$result["createdFileName"]=$createdFileName;
226 liveuser 2352
 
3 liveuser 2353
						#設置新建立的檔案名稱與路徑
2354
						$result["createdFilePathAndName"]=$createdFilePath."/".$result["createdFileName"];
226 liveuser 2355
 
3 liveuser 2356
						#設置新建立的檔與路徑
2357
						$result["createdFilePath"]=$createdFilePath;
226 liveuser 2358
 
3 liveuser 2359
						#跳出迴圈
2360
						break;
226 liveuser 2361
 
3 liveuser 2362
						}#if end
226 liveuser 2363
 
3 liveuser 2364
					#反之代表檔案建立失敗
2365
					else{
226 liveuser 2366
 
3 liveuser 2367
						#設置錯誤識別
2368
						$result["status"]="false";
226 liveuser 2369
 
3 liveuser 2370
						#設置錯誤訊息
2371
						$result["error"]=$fileCreateResult;
226 liveuser 2372
 
3 liveuser 2373
						#回傳結果
2374
						return $result;
226 liveuser 2375
 
3 liveuser 2376
						}#else end
226 liveuser 2377
 
2378
					}#else end
2379
 
3 liveuser 2380
				}#if end
226 liveuser 2381
 
3 liveuser 2382
			#反之代表有相同檔名存在
226 liveuser 2383
			else{
2384
 
3 liveuser 2385
				#用「.」分割檔案名稱
2386
				#函式說明:
2387
				#將固定格式的字串分開,並回傳分開的結果。
2388
				#回傳結果:
2389
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2390
				#$result["error"],錯誤訊息陣列
2391
				#$result["function"],當前執行的函數名稱.
2392
				#$result["oriStr"],要分割的原始字串內容
2393
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2394
				#$result["dataCounts"],爲總共分成幾段
2395
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
2396
				#必填參數:
2397
				$conf["stringProcess::spiltString"]["stringIn"]=$createdFileName;#要處理的字串。
2398
				$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
2399
				#可省略參數:
2400
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2401
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2402
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2403
				unset($conf["stringProcess::spiltString"]);
2404
 
3 liveuser 2405
				#如果分割檔案名稱失敗
2406
				if($spiltString["status"]=="false"){
226 liveuser 2407
 
3 liveuser 2408
					#設置執行失敗
2409
					$result["status"]="false";
226 liveuser 2410
 
3 liveuser 2411
					#設置錯誤訊息
2412
					$result["error"]=$spiltString;
226 liveuser 2413
 
3 liveuser 2414
					#回傳結果
2415
					return $result;
226 liveuser 2416
 
3 liveuser 2417
					}#if end
226 liveuser 2418
 
3 liveuser 2419
				#初始化儲存建立的檔案名稱
2420
				$createdFileName="";
226 liveuser 2421
 
3 liveuser 2422
				#初始化儲存編號的變數
2423
				$no="";
226 liveuser 2424
 
3 liveuser 2425
				#如果沒有dot存在
2426
				if($spiltString["found"]=="false"){
226 liveuser 2427
 
3 liveuser 2428
					#解析 $conf["repeatNameRule"],用 \$i 分割.
2429
					#函式說明:
2430
					#將固定格式的字串分開,並回傳分開的結果。
2431
					#回傳結果:
2432
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2433
					#$result["error"],錯誤訊息陣列
2434
					#$result["function"],當前執行的函數名稱.
2435
					#$result["oriStr"],要分割的原始字串內容
2436
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2437
					#$result["dataCounts"],爲總共分成幾段
2438
					#必填參數:
2439
					$conf["stringProcess::spiltString"]["stringIn"]=$conf["repeatNameRule"];#要處理的字串。
2440
					$conf["stringProcess::spiltString"]["spiltSymbol"]="\$i";#爲以哪個符號作爲分割
2441
					#可省略參數:
2442
					#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2443
					$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2444
					$noString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2445
					unset($conf["stringProcess::spiltString"]);
2446
 
3 liveuser 2447
					#如果分割檔案名稱失敗
2448
					if($noString["status"]=="false"){
226 liveuser 2449
 
3 liveuser 2450
						#設置執行失敗
2451
						$result["status"]="false";
226 liveuser 2452
 
3 liveuser 2453
						#設置錯誤訊息
2454
						$result["error"]=$noString;
226 liveuser 2455
 
3 liveuser 2456
						#回傳結果
2457
						return $result;
226 liveuser 2458
 
3 liveuser 2459
						}#if end
226 liveuser 2460
 
3 liveuser 2461
					#如果 編號規則字串 分割出來的段數為2
2462
					if($noString["dataCounts"]==2){
226 liveuser 2463
 
3 liveuser 2464
						#組合編號
2465
						$no=$noString["dataArray"][0].$i.$noString["dataArray"][1];
226 liveuser 2466
 
3 liveuser 2467
						}#if end
226 liveuser 2468
 
3 liveuser 2469
					#反之 號規則字串 分割出來的段數為1
2470
					else if($noString["dataCounts"]==1){
226 liveuser 2471
 
3 liveuser 2472
						#判斷 "\$i" 在開頭或結尾
2473
						#函式說明:
2474
						#取得關鍵字在字串的哪個位置
2475
						#回傳結果:
2476
						#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
2477
						#$result["error"],錯誤訊息陣列.
2478
						#$result["function"],當前執行的函數名稱.
2479
						#$result["argu"],傳入的參數.
2480
						#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
2481
						#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
2482
						#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
2483
						#必填參數:
2484
						#$conf["inputStr"],字串,被搜尋的字串.
2485
						$conf["search::findKeyWordPosition"]["inputStr"]=$conf["repeatNameRule"];
2486
						#$conf["keyWord"],字串,關鍵字.
2487
						$conf["search::findKeyWordPosition"]["keyWord"]="\$i";
2488
						#參考資料:
2489
						#http://php.net/manual/en/function.strpos.php
2490
						$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
2491
						unset($conf["search::findKeyWordPosition"]);
226 liveuser 2492
 
3 liveuser 2493
						#如果取得關鍵字位置失敗
2494
						if($findKeyWordPosition["status"]=="false"){
226 liveuser 2495
 
3 liveuser 2496
							#設置執行失敗
2497
							$result["status"]="false";
226 liveuser 2498
 
3 liveuser 2499
							#設置錯誤訊息
2500
							$result["error"]=$findKeyWordPosition;
226 liveuser 2501
 
3 liveuser 2502
							#回傳結果
2503
							return $result;
226 liveuser 2504
 
3 liveuser 2505
							}#if end
226 liveuser 2506
 
3 liveuser 2507
						#如果關鍵字在開頭
2508
						if($findKeyWordPosition["head"]=="true"){
226 liveuser 2509
 
3 liveuser 2510
							#組合編號
2511
							$no=$i.$noString["dataArray"][0];
226 liveuser 2512
 
3 liveuser 2513
							}#if end
226 liveuser 2514
 
3 liveuser 2515
						#反之如果關鍵字在結尾
2516
						else if($findKeyWordPosition["tail"]=="true"){
226 liveuser 2517
 
3 liveuser 2518
							#組合編號
2519
							$no=$noString["dataArray"][0].$i;
226 liveuser 2520
 
3 liveuser 2521
							}#if end
226 liveuser 2522
 
3 liveuser 2523
						#其他情況
2524
						else{
226 liveuser 2525
 
3 liveuser 2526
							#設置執行失敗
2527
							$result["status"]="false";
226 liveuser 2528
 
3 liveuser 2529
							#設置錯誤訊息
2530
							$result["error"]=$findKeyWordPosition;
226 liveuser 2531
 
3 liveuser 2532
							#設置額外的錯誤訊息
2533
							$result["error"][]="非預期的結果";
226 liveuser 2534
 
3 liveuser 2535
							#回傳結果
2536
							return $result;
226 liveuser 2537
 
3 liveuser 2538
							}#else end
226 liveuser 2539
 
3 liveuser 2540
						}#if end
226 liveuser 2541
 
3 liveuser 2542
					#反之 編號規則字串 分割出來的段數為0
2543
					else if($noString["dataCounts"]==0){
226 liveuser 2544
 
3 liveuser 2545
						#組合編號
2546
						$no=$j;
226 liveuser 2547
 
3 liveuser 2548
						}#if end
226 liveuser 2549
 
3 liveuser 2550
					#其他結果
2551
					else{
226 liveuser 2552
 
3 liveuser 2553
						#設置執行失敗
2554
						$result["status"]="false";
226 liveuser 2555
 
3 liveuser 2556
						#設置錯誤訊息
2557
						$result["error"]=$noString;
226 liveuser 2558
 
3 liveuser 2559
						#設置額外的錯誤訊息
2560
						$result["error"][]="非預期的結果";
226 liveuser 2561
 
3 liveuser 2562
						#回傳結果
2563
						return $result;
226 liveuser 2564
 
2565
						}#else end
2566
 
3 liveuser 2567
					#串接編號到檔案名稱上
2568
					$createdFileName=$validatePath["fileName"].$no;
226 liveuser 2569
 
3 liveuser 2570
					}#if end
226 liveuser 2571
 
2572
				#反之有dot存在
3 liveuser 2573
				else{
226 liveuser 2574
 
3 liveuser 2575
					#依據 $spiltString["dataCounts"] 值來組裝新的檔案名稱
2576
					for($j=0;$j<$spiltString["dataCounts"];$j++){
226 liveuser 2577
 
3 liveuser 2578
						#如果是副檔名的前一段內容
2579
						if(($conf["filenameExtensionStartPoint"]+1)==($spiltString["dataCounts"]-$j)){
226 liveuser 2580
 
3 liveuser 2581
							#解析 $conf["repeatNameRule"],用 \$i 分割.
2582
							#函式說明:
2583
							#將固定格式的字串分開,並回傳分開的結果。
2584
							#回傳結果:
2585
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2586
							#$result["error"],錯誤訊息陣列
2587
							#$result["function"],當前執行的函數名稱.
2588
							#$result["oriStr"],要分割的原始字串內容
2589
							#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2590
							#$result["dataCounts"],爲總共分成幾段
2591
							#必填參數:
2592
							$conf["stringProcess::spiltString"]["stringIn"]=$conf["repeatNameRule"];#要處理的字串。
2593
							$conf["stringProcess::spiltString"]["spiltSymbol"]="\$i";#爲以哪個符號作爲分割
2594
							#可省略參數:
2595
							#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2596
							$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2597
							$noString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2598
							unset($conf["stringProcess::spiltString"]);
2599
 
3 liveuser 2600
							#如果分割檔案名稱失敗
2601
							if($noString["status"]=="false"){
226 liveuser 2602
 
3 liveuser 2603
								#設置執行失敗
2604
								$result["status"]="false";
226 liveuser 2605
 
3 liveuser 2606
								#設置錯誤訊息
2607
								$result["error"]=$noString;
226 liveuser 2608
 
3 liveuser 2609
								#回傳結果
2610
								return $result;
226 liveuser 2611
 
3 liveuser 2612
								}#if end
226 liveuser 2613
 
3 liveuser 2614
							#如果 編號規則字串 分割出來的段數為2
2615
							if($noString["dataCounts"]==2){
226 liveuser 2616
 
3 liveuser 2617
								#組合編號
2618
								$no=$noString["dataArray"][0].$i.$noString["dataArray"][1];
226 liveuser 2619
 
3 liveuser 2620
								}#if end
226 liveuser 2621
 
3 liveuser 2622
							#反之 號規則字串 分割出來的段數為1
2623
							else if($noString["dataCounts"]==1){
226 liveuser 2624
 
3 liveuser 2625
								#判斷 "\$i" 在開頭或結尾
2626
								#函式說明:
2627
								#取得關鍵字在字串的哪個位置
2628
								#回傳結果:
2629
								#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
2630
								#$result["error"],錯誤訊息陣列.
2631
								#$result["function"],當前執行的函數名稱.
2632
								#$result["argu"],傳入的參數.
2633
								#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
2634
								#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
2635
								#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
2636
								#必填參數:
2637
								#$conf["inputStr"],字串,被搜尋的字串.
2638
								$conf["search::findKeyWordPosition"]["inputStr"]=$conf["repeatNameRule"];
2639
								#$conf["keyWord"],字串,關鍵字.
2640
								$conf["search::findKeyWordPosition"]["keyWord"]="\$i";
2641
								#參考資料:
2642
								#http://php.net/manual/en/function.strpos.php
2643
								$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
2644
								unset($conf["search::findKeyWordPosition"]);
226 liveuser 2645
 
3 liveuser 2646
								#如果取得關鍵字位置失敗
2647
								if($findKeyWordPosition["status"]=="false"){
226 liveuser 2648
 
3 liveuser 2649
									#設置執行失敗
2650
									$result["status"]="false";
226 liveuser 2651
 
3 liveuser 2652
									#設置錯誤訊息
2653
									$result["error"]=$findKeyWordPosition;
226 liveuser 2654
 
3 liveuser 2655
									#回傳結果
2656
									return $result;
226 liveuser 2657
 
3 liveuser 2658
									}#if end
226 liveuser 2659
 
3 liveuser 2660
								#如果關鍵字在開頭
2661
								if($findKeyWordPosition["head"]=="true"){
226 liveuser 2662
 
3 liveuser 2663
									#組合編號
2664
									$no=$i.$noString["dataArray"][0];
226 liveuser 2665
 
3 liveuser 2666
									}#if end
226 liveuser 2667
 
3 liveuser 2668
								#反之如果關鍵字在結尾
2669
								else if($findKeyWordPosition["tail"]=="true"){
226 liveuser 2670
 
3 liveuser 2671
									#組合編號
2672
									$no=$noString["dataArray"][0].$i;
226 liveuser 2673
 
3 liveuser 2674
									}#if end
226 liveuser 2675
 
3 liveuser 2676
								#其他情況
2677
								else{
226 liveuser 2678
 
3 liveuser 2679
									#設置執行失敗
2680
									$result["status"]="false";
226 liveuser 2681
 
3 liveuser 2682
									#設置錯誤訊息
2683
									$result["error"]=$findKeyWordPosition;
226 liveuser 2684
 
3 liveuser 2685
									#設置額外的錯誤訊息
2686
									$result["error"][]="非預期的結果";
226 liveuser 2687
 
3 liveuser 2688
									#回傳結果
2689
									return $result;
226 liveuser 2690
 
3 liveuser 2691
									}#else end
226 liveuser 2692
 
3 liveuser 2693
								}#if end
226 liveuser 2694
 
3 liveuser 2695
							#反之 編號規則字串 分割出來的段數為0
2696
							else if($noString["dataCounts"]==0){
226 liveuser 2697
 
3 liveuser 2698
								#組合編號
2699
								$no=$j;
226 liveuser 2700
 
3 liveuser 2701
								}#if end
226 liveuser 2702
 
3 liveuser 2703
							#其他結果
2704
							else{
226 liveuser 2705
 
3 liveuser 2706
								#設置執行失敗
2707
								$result["status"]="false";
226 liveuser 2708
 
3 liveuser 2709
								#設置錯誤訊息
2710
								$result["error"]=$noString;
226 liveuser 2711
 
3 liveuser 2712
								#設置額外的錯誤訊息
2713
								$result["error"][]="非預期的結果";
226 liveuser 2714
 
3 liveuser 2715
								#回傳結果
2716
								return $result;
226 liveuser 2717
 
2718
								}#else end
2719
 
3 liveuser 2720
							#串接編號到檔案名稱上
2721
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j].$no;
226 liveuser 2722
 
3 liveuser 2723
							#如果不是最後一段
2724
							if($j!=$spiltString["dataCounts"]-1){
226 liveuser 2725
 
3 liveuser 2726
								#串接並加上 dot
2727
								$createdFileName=$createdFileName.".";
226 liveuser 2728
 
3 liveuser 2729
								}#if end
226 liveuser 2730
 
3 liveuser 2731
							}#if end
226 liveuser 2732
 
3 liveuser 2733
						#反之如果不是最後一段
2734
						else if($j!=$spiltString["dataCounts"]-1){
226 liveuser 2735
 
3 liveuser 2736
							#串接並加上 dot
2737
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j].".";
226 liveuser 2738
 
3 liveuser 2739
							}#if end
226 liveuser 2740
 
2741
						#反之是最後一段
3 liveuser 2742
						else{
226 liveuser 2743
 
3 liveuser 2744
							#串接並加上 dot
2745
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j];
226 liveuser 2746
 
3 liveuser 2747
							}#else end
226 liveuser 2748
 
3 liveuser 2749
						}#for end
226 liveuser 2750
 
3 liveuser 2751
					}#else end
226 liveuser 2752
 
3 liveuser 2753
				#檢查加上編號的檔案是否存在
2754
				#函式說明:
2755
				#檢查多個檔案與資料夾是否存在.
2756
				#回傳的結果:
2757
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
2758
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2759
				#必填參數:
2760
				$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($createdFilePath."/".$createdFileName);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
2761
				$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
2762
				#參考資料來源:
2763
				#http://php.net/manual/en/function.file-exists.php
2764
				#http://php.net/manual/en/control-structures.foreach.php
2765
				$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
2766
				$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
2767
				unset($conf["fileAccess"]["checkMutiFileExist"]);
226 liveuser 2768
 
3 liveuser 2769
				#如果檢查檔案是否存在失敗
2770
				if($checkResult["status"]=="false"){
226 liveuser 2771
 
3 liveuser 2772
					#設置執行失敗
2773
					$result["status"]="false";
226 liveuser 2774
 
3 liveuser 2775
					#設置錯誤訊息
2776
					$result["error"]=$checkResult;
226 liveuser 2777
 
3 liveuser 2778
					#回傳結果
2779
					return $result;
226 liveuser 2780
 
2781
					}#if end
2782
 
3 liveuser 2783
				#如果 $checkResult["varExist"][0] 等於 "true"
226 liveuser 2784
				if($checkResult["varExist"][0]=="true"){
2785
 
3 liveuser 2786
					#取得要建立的檔案名稱
2787
					$createdFileName=$validatePath["fileName"];
226 liveuser 2788
 
3 liveuser 2789
					#跳到下個迴圈
2790
					continue;
226 liveuser 2791
 
3 liveuser 2792
					}#if end
226 liveuser 2793
 
3 liveuser 2794
				#反之代表 $createFilePath.$createdFileName."(".$i.")" 檔檔案不存在
2795
				else{
226 liveuser 2796
 
3 liveuser 2797
					#嘗試建立該檔案
2798
					#函式說明:
2799
					#將字串寫入到檔案
2800
					#回傳結果:
2801
					#$result["status"],true表示檔案寫入成功,false表示檔案寫入失敗.
2802
					#$result["error"],錯誤訊息陣列.
2803
					#必填參數:
2804
					$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$createdFilePath."/".$createdFileName;#爲要編輯的檔案名稱
2805
					$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
2806
					$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
2807
					#可省略參數:
2808
					$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
2809
					$conf["fileAccess"]["writeTextIntoFile"]["web"]=$conf["web"];
2810
					$fileCreateResult=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
2811
					unset($conf["fileAccess"]["writeTextIntoFile"]);
226 liveuser 2812
 
3 liveuser 2813
					#如果 $fileCreateResult["status"] 等於 "true"
2814
					if($fileCreateResult["status"]=="true"){
226 liveuser 2815
 
3 liveuser 2816
						#代表檔案建立成功
226 liveuser 2817
 
3 liveuser 2818
						#更新建立的檔案名稱
2819
						$result["createdFileName"]=$createdFileName;
226 liveuser 2820
 
3 liveuser 2821
						#跳出迴圈
2822
						break;
226 liveuser 2823
 
3 liveuser 2824
						}#if end
226 liveuser 2825
 
3 liveuser 2826
					#反之代表檔案建立失敗
2827
					else{
226 liveuser 2828
 
3 liveuser 2829
						#設置錯誤識別
2830
						$result["status"]="false";
226 liveuser 2831
 
3 liveuser 2832
						#設置錯誤訊息
2833
						$result["error"]=$fileCreateResult;
226 liveuser 2834
 
3 liveuser 2835
						#回傳結果
2836
						return $result;
226 liveuser 2837
 
3 liveuser 2838
						}#else end
226 liveuser 2839
 
3 liveuser 2840
					}#else end
226 liveuser 2841
 
3 liveuser 2842
				}#else end
226 liveuser 2843
 
3 liveuser 2844
			}#for end
226 liveuser 2845
 
3 liveuser 2846
		#如果不存在建立的檔案名稱
2847
		if(!isset($result["createdFileName"])){
226 liveuser 2848
 
3 liveuser 2849
			#設置錯誤識別
2850
			$result["status"]="false";
226 liveuser 2851
 
3 liveuser 2852
			#設置錯誤訊息
2853
			$result["error"][]="建立的檔案名稱不存在";
226 liveuser 2854
 
3 liveuser 2855
			#回傳結果
2856
			return $result;
226 liveuser 2857
 
2858
			}#if end
2859
 
3 liveuser 2860
		#執行到這邊代表執行成功
2861
		$result["status"]="true";
226 liveuser 2862
 
3 liveuser 2863
		#設置新建立的檔案名稱與路徑
2864
		$result["createdFilePathAndName"]=$createdFilePath."/".$result["createdFileName"];
226 liveuser 2865
 
3 liveuser 2866
		#設置新建立的檔與路徑
2867
		$result["createdFilePath"]=$createdFilePath;
226 liveuser 2868
 
3 liveuser 2869
		#回傳結果
2870
		return $result;
226 liveuser 2871
 
3 liveuser 2872
		}#fucntion createFileAfterCheck end
2873
 
2874
	/*
2875
	#函式說明:
2876
	#將檔案內容清空
2877
	#回傳結果:
2878
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
2879
	#$result["error"],錯誤訊息陣列
2880
	#必填參數:
2881
	#$conf["fileAddr"],字串,要清空的檔案位置與名稱.
2882
	$conf["fileAddr"]="";
2883
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2884
	$conf["fileArgu"]=__FILE__;
2885
	#可省略參數:
2886
	#$conf["web"],"true"代表為網頁系統,"false"代表檔案系統,預設為"false".
2887
	#$conf["web"]="false";
2888
	#參考資料:
2889
	#無.
2890
	#備註:
2891
	#無.
2892
	*/
2893
	public static function emptyFile(&$conf){
226 liveuser 2894
 
3 liveuser 2895
		#初始化要回傳的結果
2896
		$result=array();
226 liveuser 2897
 
3 liveuser 2898
		#設置當前執行的涵式
2899
		$result["function"]=__FUNCTION__;
226 liveuser 2900
 
3 liveuser 2901
		#如果 $conf 不為陣列
2902
		if(gettype($conf)!="array"){
226 liveuser 2903
 
3 liveuser 2904
			#設置執行失敗
2905
			$result["status"]="false";
226 liveuser 2906
 
3 liveuser 2907
			#設置執行錯誤訊息
2908
			$result["error"][]="\$conf變數須為陣列形態";
2909
 
2910
			#如果傳入的參數為 null
2911
			if($conf==null){
226 liveuser 2912
 
3 liveuser 2913
				#設置執行錯誤訊息
2914
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 2915
 
3 liveuser 2916
				}#if end
2917
 
2918
			#回傳結果
2919
			return $result;
226 liveuser 2920
 
3 liveuser 2921
			}#if end
226 liveuser 2922
 
3 liveuser 2923
		#取得參數
2924
		$result["argu"]=$conf;
226 liveuser 2925
 
3 liveuser 2926
		#檢查參數
2927
		#函式說明:
2928
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2929
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2930
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2931
		#$result["function"],當前執行的函式名稱.
2932
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2933
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2934
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2935
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2936
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2937
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2938
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2939
		#必填寫的參數:
2940
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2941
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2942
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2943
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddr");
226 liveuser 2944
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 2945
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
2946
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2947
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2948
		#可以省略的參數:
2949
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2950
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2951
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2952
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 2953
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 2954
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
2955
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2956
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
2957
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2958
		#$conf["arrayCountEqualCheck"][]=array();
2959
		#參考資料來源:
2960
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2961
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2962
		unset($conf["variableCheck::checkArguments"]);
2963
 
2964
		#如果 $checkArguments["status"] 等於 "false"
2965
		if($checkArguments["status"]=="false"){
226 liveuser 2966
 
3 liveuser 2967
			#設置錯誤識別
2968
			$result["status"]="false";
226 liveuser 2969
 
3 liveuser 2970
			#設置錯誤訊息
2971
			$result["error"]=$checkArguments;
226 liveuser 2972
 
3 liveuser 2973
			#回傳結果
226 liveuser 2974
			return $result;
2975
 
3 liveuser 2976
			}#if end
226 liveuser 2977
 
3 liveuser 2978
		#如果 $checkArguments["passed"] 等於 "false"
2979
		if($checkArguments["passed"]=="false"){
226 liveuser 2980
 
3 liveuser 2981
			#設置錯誤識別
2982
			$result["status"]="false";
226 liveuser 2983
 
3 liveuser 2984
			#設置錯誤訊息
2985
			$result["error"]=$checkArguments;
226 liveuser 2986
 
3 liveuser 2987
			#回傳結果
226 liveuser 2988
			return $result;
2989
 
2990
			}#if end
2991
 
3 liveuser 2992
		#函式說明:
2993
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
2994
		#回傳結果:
2995
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
2996
		#$result["error"],錯誤訊息陣列.
226 liveuser 2997
		#$result["function"],函數名稱.
3 liveuser 2998
		#$result["argu"],使用的參數.
2999
		#$result["content"],網址,若是在命令列執行,則為"null".
3000
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
3001
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
3002
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
3003
		#必填參數:
3004
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
3005
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["fileAddr"];
3006
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3007
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
3008
		#可省略參數:
3009
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3010
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
3011
		#備註:
3012
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
3013
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
3014
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 3015
 
3 liveuser 3016
		#如果確保路徑失敗
3017
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 3018
 
3 liveuser 3019
			#設置錯誤識別
3020
			$result["status"]="false";
226 liveuser 3021
 
3 liveuser 3022
			#設置錯誤訊息
3023
			$result["error"]=$getInternetAddressV2;
226 liveuser 3024
 
3 liveuser 3025
			#回傳結果
3026
			return $result;
226 liveuser 3027
 
3 liveuser 3028
			}#if end
226 liveuser 3029
 
3 liveuser 3030
		#更新檔案路徑
3031
		$conf["fileAddr"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 3032
 
3 liveuser 3033
		#確保要建立檔案的路徑
3034
		#函式說明:
3035
		#確保路徑存在.
3036
		#回傳結果:
3037
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3038
		#$result["error"],錯誤訊息陣列.
3039
		#$resutl["function"],當前執行的涵式名稱.
3040
		#$result["path"],建立好的路徑字串.
3041
		#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
3042
		#必填參數:
3043
		#$conf["path"],要檢查的路徑
226 liveuser 3044
		$conf["fileAccess::validatePath"]["path"]=$conf["fileAddr"];
3 liveuser 3045
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3046
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
3047
		#可省略參數:
3048
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
3049
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
3050
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3051
		#$conf["dirPermission"]="";
3052
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3053
		$conf["fileAccess::validatePath"]["web"]="false";
3054
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
226 liveuser 3055
		unset($conf["fileAccess::validatePath"]);
3056
 
3 liveuser 3057
		#如果確保路徑失敗
3058
		if($validatePath["status"]==="false"){
226 liveuser 3059
 
3 liveuser 3060
			#設置錯誤識別
3061
			$result["status"]="false";
226 liveuser 3062
 
3 liveuser 3063
			#設置錯誤訊息
3064
			$result["error"]=$validatePath;
226 liveuser 3065
 
3 liveuser 3066
			#回傳結果
3067
			return $result;
226 liveuser 3068
 
3 liveuser 3069
			}#if end
226 liveuser 3070
 
3 liveuser 3071
		#清空檔案
3072
		#函式說明:
3073
		#將字串寫入到檔案
3074
		#回傳結果:
3075
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
3076
		#$result["error"],錯誤訊息陣列.
3077
		#$result["function"],當前執行的函數名稱.
3078
		#$result["fileInfo"],實際上寫入的檔案資訊陣列.
3079
		#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
3080
		#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
3081
		#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
3082
		#$result["argu"],使用的參數.
3083
		#必填參數:
3084
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3085
		$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
3086
		#可省略參數:
3087
		#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
3088
		#$conf["fileAccess::writeTextIntoFile"]["fileName"]=$validatePath["path"]."/".$validatePath["fileName"];
3089
		$conf["fileAccess::writeTextIntoFile"]["fileName"]=$validatePath["path"]."/".$validatePath["fileName"];;
3090
		#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
3091
		#$conf["inputString"]="";
3092
		#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
3093
		#$conf["writeMethod"]="a";
3094
		#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
3095
		#$conf["checkRepeat"]="";
3096
		#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
3097
		#$conf["filenameExtensionStartPoint"]="";
3098
		#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
3099
		#$conf["repeatNameRule"]="";
3100
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3101
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
3102
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
3103
		unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 3104
 
3 liveuser 3105
		#如果確保路徑失敗
3106
		if($writeTextIntoFile["status"]==="false"){
226 liveuser 3107
 
3 liveuser 3108
			#設置錯誤識別
3109
			$result["status"]="false";
226 liveuser 3110
 
3 liveuser 3111
			#設置錯誤訊息
3112
			$result["error"]=$writeTextIntoFile;
226 liveuser 3113
 
3 liveuser 3114
			#回傳結果
3115
			return $result;
226 liveuser 3116
 
3 liveuser 3117
			}#if end
226 liveuser 3118
 
3 liveuser 3119
		#設置執行正常
3120
		$result["status"]="true";
226 liveuser 3121
 
3 liveuser 3122
		#儲存建立的結果
3123
		$result["content"]=$writeTextIntoFile;
226 liveuser 3124
 
3 liveuser 3125
		#回傳結果
3126
		return $result;
226 liveuser 3127
 
3 liveuser 3128
		}#function emptyFile end
3129
 
3130
	/*
3131
	#函式說明:
3132
	#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
3133
	#回傳結果:
3134
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3135
	#$result["error"],錯誤訊息陣列
3136
	#$result["warning"],警告訊息陣列
3137
	#必填參數:
3138
	#$conf["dirPositionAndName"]="";#新建的位置與名稱
3139
	$conf["dirPositionAndName"]="";
3140
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3141
	$conf["fileArgu"]=__FILE__;
3142
	#可省略參數:
3143
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3144
	#$conf["dirPermission"]="";
3145
	#參考資料:
3146
	#mkdir=>http://php.net/manual/en/function.mkdir.php
3147
	#chmod=>http://php.net/manual/en/function.chmod.php
3148
	#參考資料:
3149
	#無.
3150
	#備註:
3151
	#同 function createFolderAfterCheck.
3152
	*/
3153
	public static function createNewFolder(&$conf){
3154
 
3155
		/*
3156
		#函式說明:
3157
		#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
3158
		#回傳的結果:
3159
		#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
3160
		#$result["error"],錯誤訊息陣列.
3161
		#$result["function"],當前執行的函數名稱.
3162
		#$result["createdFileName"],建立好的檔案名稱.
3163
		#$result["createdFilePath"],檔案建立的路徑.
3164
		#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
3165
		#必填參數:
3166
		#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
3167
		$conf["checkedFileAndPath"]="";
3168
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3169
		$conf["fileArgu"]=__FILE__;
3170
		*/
3171
		return fileAccess::createFolderAfterCheck($conf);
3172
		unset($conf);
3173
 
3174
		}#function createNewFolder end
226 liveuser 3175
 
3 liveuser 3176
	/*
3177
	#函式說明:
3178
	#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
3179
	#回傳結果:
3180
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3181
	#$result["error"],錯誤訊息陣列
3182
	#$result["warning"],警告訊息陣列
3183
	#$result["argu"],使用的參數.
3184
	#$result["content"],建立的目錄路徑.
3185
	#必填參數:
3186
	#$conf["dirPositionAndName"]="";#新建的位置與名稱
3187
	$conf["dirPositionAndName"]="";
3188
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3189
	$conf["fileArgu"]=__FILE__;
3190
	#可省略參數:
3191
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3192
	#$conf["dirPermission"]="";
3193
	#$conf["web"],"false"代表在檔案系統環境,"true"代表在網頁稀系統環境.
3194
	#$conf["web"]="false";
3195
	#參考資料:
3196
	#mkdir=>http://php.net/manual/en/function.mkdir.php
3197
	#chmod=>http://php.net/manual/en/function.chmod.php
3198
	#備註:
3199
	#無.
3200
	*/
3201
	public static function createFolderAfterCheck(&$conf){
226 liveuser 3202
 
3 liveuser 3203
		#初始化要回傳的結果
3204
		$result=array();
226 liveuser 3205
 
3 liveuser 3206
		#初始化警告訊息陣列
3207
		$result["warning"]=array();
226 liveuser 3208
 
3 liveuser 3209
		#記錄當前執行的函數名稱
3210
		$result["function"]=__FUNCTION__;
226 liveuser 3211
 
3 liveuser 3212
		#如果 $conf 不為陣列
3213
		if(gettype($conf)!="array"){
226 liveuser 3214
 
3 liveuser 3215
			#設置執行失敗
3216
			$result["status"]="false";
226 liveuser 3217
 
3 liveuser 3218
			#設置執行錯誤訊息
3219
			$result["error"][]="\$conf變數須為陣列形態";
3220
 
3221
			#如果傳入的參數為 null
3222
			if($conf==null){
226 liveuser 3223
 
3 liveuser 3224
				#設置執行錯誤訊息
3225
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3226
 
3 liveuser 3227
				}#if end
3228
 
3229
			#回傳結果
3230
			return $result;
226 liveuser 3231
 
3 liveuser 3232
			}#if end
226 liveuser 3233
 
3 liveuser 3234
		#取得參數
3235
		$result["argu"]=$conf;
226 liveuser 3236
 
3 liveuser 3237
		#檢查參數
3238
		#函式說明:
3239
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3240
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3241
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3242
		#$result["function"],當前執行的函式名稱.
3243
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3244
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3245
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3246
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3247
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3248
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3249
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3250
		#必填寫的參數:
3251
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3252
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3253
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3254
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","dirPositionAndName");
226 liveuser 3255
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3256
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
3257
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3258
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3259
		#可以省略的參數:
3260
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3261
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3262
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3263
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dirPermission","web");
226 liveuser 3264
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3265
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
3266
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3267
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("0770","false");
3268
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3269
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
3270
		#參考資料來源:
3271
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3272
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3273
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3274
 
3 liveuser 3275
		#如果 $checkArguments["status"] 等於 "false"
3276
		if($checkArguments["status"]==="false"){
226 liveuser 3277
 
3 liveuser 3278
			#設置 $result["status"] 為 "false"
3279
			$result["status"]="false";
226 liveuser 3280
 
3 liveuser 3281
			#設置 $result["error"]
3282
			$result["error"]=$checkArguments;
226 liveuser 3283
 
3 liveuser 3284
			#回傳結果
3285
			return $result;
226 liveuser 3286
 
3 liveuser 3287
			}#if end
226 liveuser 3288
 
3 liveuser 3289
		#如果 $checkArguments["passed"] 等於 "false"
3290
		if($checkArguments["passed"]==="false"){
226 liveuser 3291
 
3 liveuser 3292
			#設置 $result["status"] 為 "false"
3293
			$result["status"]="false";
226 liveuser 3294
 
3 liveuser 3295
			#設置 $result["error"]
3296
			$result["error"]=$checkArguments;
226 liveuser 3297
 
3 liveuser 3298
			#回傳結果
3299
			return $result;
226 liveuser 3300
 
3301
			}#if end
3302
 
3 liveuser 3303
		#函式說明:
3304
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
3305
		#回傳結果:
3306
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3307
		#$result["error"],錯誤訊息陣列.
226 liveuser 3308
		#$result["function"],函數名稱.
3 liveuser 3309
		#$result["argu"],使用的參數.
3310
		#$result["content"],網址,若是在命令列執行,則為"null".
3311
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
3312
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
3313
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
3314
		#必填參數:
3315
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
3316
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["dirPositionAndName"];
3317
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3318
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
3319
		#可省略參數:
3320
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3321
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
3322
		#備註:
3323
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
3324
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
3325
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 3326
 
3 liveuser 3327
		#如果 $getInternetAddressV2["status"] 等於 "false"
3328
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 3329
 
3 liveuser 3330
			#設置 $result["status"] 為 "false"
3331
			$result["status"]="false";
226 liveuser 3332
 
3 liveuser 3333
			#設置 $result["error"]
3334
			$result["error"]=$getInternetAddressV2;
226 liveuser 3335
 
3 liveuser 3336
			#回傳結果
3337
			return $result;
226 liveuser 3338
 
3 liveuser 3339
			}#if end
226 liveuser 3340
 
3 liveuser 3341
		#取得絕對位置
3342
		$conf["dirPositionAndName"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 3343
 
3 liveuser 3344
		#用「/」分割要建立的路徑
3345
		#函式說明:
3346
		#將固定格式的字串分開,並回傳分開的結果。
3347
		#回傳結果:
3348
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3349
		#$result["error"],錯誤訊息陣列
3350
		#$result["function"],當前執行的函數名稱.
3351
		#$result["oriStr"],要分割的原始字串內容
3352
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
3353
		#$result["dataCounts"],爲總共分成幾段
3354
		#必填參數:
3355
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["dirPositionAndName"];
3356
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
3357
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 3358
		unset($conf["stringProcess::spiltString"]);
3359
 
3 liveuser 3360
		#如果分割失敗
3361
		if($spiltString["status"]=="false"){
226 liveuser 3362
 
3 liveuser 3363
			#設置 $result["status"] 為 "false"
3364
			$result["status"]="false";
226 liveuser 3365
 
3 liveuser 3366
			#設置 $result["error"]
3367
			$result["error"]=$spiltString;
226 liveuser 3368
 
3 liveuser 3369
			#回傳結果
3370
			return $result;
226 liveuser 3371
 
3 liveuser 3372
			}#if end
226 liveuser 3373
 
3 liveuser 3374
		$checkedPath="";
226 liveuser 3375
 
3 liveuser 3376
		#依據切割成的路徑片段數目
3377
		for($i=0;$i<$spiltString["dataCounts"];$i++){
226 liveuser 3378
 
3 liveuser 3379
			$checkedPath=$checkedPath."/".$spiltString["dataArray"][$i];
226 liveuser 3380
 
3 liveuser 3381
			#檢查路徑是否存在
3382
			#函式說明:
3383
			#檢查多個檔案與資料夾是否存在.
3384
			#回傳的結果:
3385
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3386
			#$result["error"],錯誤訊息陣列.
3387
			#$resutl["function"],當前執行的涵式名稱.
3388
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
3389
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
3390
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
3391
			#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
3392
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
3393
			#必填參數:
3394
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
3395
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($checkedPath);
3396
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3397
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
3398
			#可省略參數
3399
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
3400
			#$conf["disableWebSearch"]="false";
3401
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
3402
			#$conf["userDir"]="true";
3403
			#參考資料來源:
3404
			#http://php.net/manual/en/function.file-exists.php
3405
			#http://php.net/manual/en/control-structures.foreach.php
3406
			#備註:
3407
			#函數file_exists檢查的路徑為檔案系統的路徑
3408
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 3409
 
3 liveuser 3410
			#如果檢查資料夾路徑失敗
3411
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 3412
 
3 liveuser 3413
				#設置 $result["status"] 為 "false"
3414
				$result["status"]="false";
226 liveuser 3415
 
3 liveuser 3416
				#設置 $result["error"]
3417
				$result["error"]=$spiltString;
226 liveuser 3418
 
3 liveuser 3419
				#回傳結果
3420
				return $result;
226 liveuser 3421
 
3 liveuser 3422
				}#if end
226 liveuser 3423
 
3 liveuser 3424
			#如果目錄不存在
3425
			if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 3426
 
3 liveuser 3427
				#如果有這個名稱的東西存在
3428
				if(file_exists($checkedPath)){
226 liveuser 3429
 
3 liveuser 3430
					#如果目錄存在
3431
					if(is_dir($checkedPath)){
226 liveuser 3432
 
3 liveuser 3433
						#目錄已經存在換下一層
3434
						continue;
226 liveuser 3435
 
3 liveuser 3436
						}#if end
226 liveuser 3437
 
3 liveuser 3438
					}#if end
226 liveuser 3439
 
3 liveuser 3440
				#建立目錄
3441
				$mkdir=@mkdir($checkedPath,0770);
226 liveuser 3442
 
3 liveuser 3443
				#如果建立目錄失敗
3444
				#參考資料:
3445
				#http://php.net/manual/en/function.mkdir.php
3446
				if($mkdir===false){
226 liveuser 3447
 
3 liveuser 3448
					#設置 $result["status"] 為 "false"
3449
					$result["status"]="false";
226 liveuser 3450
 
3 liveuser 3451
					#設置 $result["error"]
3452
					$result["error"][]="建立目錄「".$checkedPath."」失敗";
226 liveuser 3453
 
3 liveuser 3454
					#回傳結果
3455
					return $result;
226 liveuser 3456
 
3 liveuser 3457
					}#if end
226 liveuser 3458
 
3 liveuser 3459
				#更改目錄的權限為 0770
3460
				chmod($checkedPath,0770);
226 liveuser 3461
 
3 liveuser 3462
				}#if end
226 liveuser 3463
 
3 liveuser 3464
			}#for end
226 liveuser 3465
 
3 liveuser 3466
		#取得建立好的目錄
226 liveuser 3467
		$result["content"]=$checkedPath;
3468
 
3 liveuser 3469
		#執行到這邊代表執行成功
3470
		$result["status"]="true";
226 liveuser 3471
 
3 liveuser 3472
		#回傳結果
3473
		return $result;
226 liveuser 3474
 
3 liveuser 3475
		}#function createFolderAfterCheck end
3476
 
3477
	/*
3478
	#函式說明:
3479
	#移除檔案
3480
	#回傳結果:
3481
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
3482
	#$result["error"],錯誤訊息陣列.
3483
	#$result["warning"],警告訊息陣列.
3484
	#$result["function"],當前執行的函數名稱.
3485
	#$result["argu"],當前函式使用的參數.
3486
	#必填參數:
3487
	#$conf["fileAddress"],字串,要移除檔案的位置.
3488
	$conf["fileAddress"]="";
3489
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3490
	$conf["fileArgu"]=__FILE__;
3491
	#可省略參數:
3492
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
3493
	#$conf["commentsArray"]=array("");
3494
	#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
3495
	#$conf["allowDelSymlink"]="true";
3496
	#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
3497
	#$conf["allowDelFolder"]="true";
3498
	#參考資料:
3499
	#無.
3500
	#備註:
3501
	#無.
220 liveuser 3502
	*/
3 liveuser 3503
	public static function delFile(&$conf){
3504
 
3505
		#初始化要回傳的結果
3506
		$result=array();
226 liveuser 3507
 
3 liveuser 3508
		#設置當其函數名稱
3509
		$result["function"]=__FUNCTION__;
226 liveuser 3510
 
3 liveuser 3511
		#如果 $conf 不為陣列
3512
		if(gettype($conf)!="array"){
226 liveuser 3513
 
3 liveuser 3514
			#設置執行失敗
3515
			$result["status"]="false";
226 liveuser 3516
 
3 liveuser 3517
			#設置執行錯誤訊息
3518
			$result["error"][]="\$conf變數須為陣列形態";
3519
 
3520
			#如果傳入的參數為 null
3521
			if($conf==null){
226 liveuser 3522
 
3 liveuser 3523
				#設置執行錯誤訊息
3524
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3525
 
3 liveuser 3526
				}#if end
3527
 
3528
			#回傳結果
3529
			return $result;
226 liveuser 3530
 
3 liveuser 3531
			}#if end
226 liveuser 3532
 
3 liveuser 3533
		#取得參數
3534
		$result["argu"]=$conf;
226 liveuser 3535
 
3 liveuser 3536
		#檢查參數
3537
		#函式說明:
3538
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3539
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3540
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3541
		#$result["function"],當前執行的函式名稱.
3542
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3543
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3544
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3545
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3546
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3547
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3548
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3549
		#必填寫的參數:
3550
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3551
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3552
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3553
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddress");
226 liveuser 3554
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3555
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
3556
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3557
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3558
		#可以省略的參數:
3559
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3560
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3561
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3562
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","allowDelSymlink","allowDelFolder");
226 liveuser 3563
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3564
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");
3565
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3566
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false","false");
3567
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3568
		#$conf["arrayCountEqualCheck"][]=array();
3569
		#參考資料來源:
3570
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3571
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3572
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3573
 
3 liveuser 3574
		#如果檢查失敗
3575
		if($checkResult["status"]=="false"){
226 liveuser 3576
 
3 liveuser 3577
			#設置錯誤識別
3578
			$result["status"]="false";
226 liveuser 3579
 
3 liveuser 3580
			#設置錯誤訊息
3581
			$result["error"]=$checkResult;
226 liveuser 3582
 
3 liveuser 3583
			#回傳結果
3584
			return $result;
226 liveuser 3585
 
3 liveuser 3586
			}#if end
226 liveuser 3587
 
3 liveuser 3588
		#如果檢查不通過
3589
		if($checkResult["passed"]=="false"){
226 liveuser 3590
 
3 liveuser 3591
			#設置錯誤識別
3592
			$result["status"]="false";
226 liveuser 3593
 
3 liveuser 3594
			#設置錯誤訊息
3595
			$result["error"]=$checkResult;
226 liveuser 3596
 
3 liveuser 3597
			#回傳結果
3598
			return $result;
226 liveuser 3599
 
3 liveuser 3600
			}#if end
3601
 
3602
		#如果 $conf["commentsArray"] 有設定
3603
		if(isset($conf["commentsArray"])){
226 liveuser 3604
 
3 liveuser 3605
			#印出提示文字
3606
			#函式說明:
3607
			#印出多行文字,結尾自動換行.
3608
			#回傳的結果:
3609
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
3610
			#$result["function"],當前執行的函數名稱.
3611
			#$result["error"],錯誤訊息陣列.
3612
			#必填參數:
3613
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
3614
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
3615
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
3616
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 3617
 
3 liveuser 3618
			#如果印出提示文字失敗
3619
			if($echoMultiLine["status"]=="false"){
226 liveuser 3620
 
3 liveuser 3621
				#設置執行失敗
3622
				$result["status"]="false";
226 liveuser 3623
 
3 liveuser 3624
				#設置執行錯誤訊息
3625
				$result["error"]=$echoMultiLine;
226 liveuser 3626
 
3 liveuser 3627
				#回傳結果
3628
				return $result;
226 liveuser 3629
 
3 liveuser 3630
				}#if end
226 liveuser 3631
 
3 liveuser 3632
			}#if end
3633
 
3634
		#檢查要移除的檔案是否存在
3635
		#函式說明:
3636
		#檢查多個檔案與資料夾是否存在.
3637
		#回傳的結果:
3638
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3639
		#$result["error"],錯誤訊息陣列.
3640
		#$resutl["function"],當前執行的涵式名稱.
3641
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
3642
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
3643
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
3644
		#必填參數:
3645
		$conf["fileAccess.checkMultiFileExist"]["fileArray"]=array($conf["fileAddress"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
3646
		#$conf["fileAccess.checkMultiFileExist"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3647
		$conf["fileAccess.checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
3648
		#可省略參數:
3649
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
3650
		#$conf["disableWebSearch"]="false";
3651
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
3652
		#$conf["userDir"]="true";
3653
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
3654
		$conf["fileAccess.checkMultiFileExist"]["web"]="false";
3655
		#參考資料來源:
3656
		#http://php.net/manual/en/function.file-exists.php
3657
		#http://php.net/manual/en/control-structures.foreach.php
3658
		$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess.checkMultiFileExist"]);
3659
		unset($conf["fileAccess.checkMultiFileExist"]);
3660
 
3661
		#var_dump($checkResult);
3662
 
3663
		#如果檢查檔案是否存在失敗
3664
		if($checkResult["status"]==="false"){
226 liveuser 3665
 
3 liveuser 3666
			#設置執行失敗
3667
			$result["status"]="false";
3668
 
3669
			#回傳錯誤訊息
3670
			$result["error"]=$checkResult;
3671
 
3672
			#回傳結果
3673
			return $result;
226 liveuser 3674
 
3 liveuser 3675
			}#if end
3676
 
3677
		#如果目標檔案不存在
3678
		if($checkResult["varExist"][0]==="false"){
226 liveuser 3679
 
3 liveuser 3680
			#設置錯誤識別
3681
			$result["status"]="true";
3682
 
3683
			#回傳錯誤訊息
3684
			$result["warning"][]="要移除的檔案不存在";
3685
 
3686
			#回傳結果
3687
			return $result;
226 liveuser 3688
 
3 liveuser 3689
			}#if end
3690
 
3691
		#如果要移除的目標是檔案
3692
		if(is_file($conf["fileAddress"])){
226 liveuser 3693
 
3 liveuser 3694
			#移除檔案,並回傳移除的結果
3695
			$eraseResult=(@unlink($conf["fileAddress"]));
3696
 
3697
			#如果 $eraseResult 等於 false
3698
			if($eraseResult===false){
226 liveuser 3699
 
3 liveuser 3700
				#設置錯誤識別
3701
				$result["status"]="false";
3702
 
3703
				#回傳錯誤訊息
3704
				$result["error"][]="檔案移除失敗";
3705
 
3706
				#回傳結果
3707
				return $result;
226 liveuser 3708
 
3 liveuser 3709
				}#if end
226 liveuser 3710
 
3 liveuser 3711
			}#if end
3712
 
3713
		#反之要移除的目標是目錄
3714
		else if(is_dir($conf["fileAddress"])){
226 liveuser 3715
 
3 liveuser 3716
			#如果允許移除目錄
3717
			if($conf["allowDelFolder"]==="true"){
226 liveuser 3718
 
3 liveuser 3719
				#移除目錄跟底下的內容
3720
				w函式說明:
3721
				#呼叫shell執行系統命令,並取得回傳的內容.
3722
				#回傳結果:
3723
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3724
				#$result["error"],錯誤訊息陣列.
3725
				#$result["function"],當前執行的函數名稱.
3726
				#$result["argu"],使用的參數.
3727
				#$result["cmd"],執行的指令內容.
3728
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
3729
				#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
3730
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
3731
				#$result["running"],是否還在執行.
3732
				#$result["pid"],pid.
3733
				#$result["statusCode"],執行結束後的代碼.
3734
				#必填參數:
3735
				#$conf["command"],字串,要執行的指令.
3736
				$conf["external::callShell"]["command"]="rm";
3737
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3738
				$conf["external::callShell"]["fileArgu"]=__FILE__;
3739
				#可省略參數:
3740
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3741
				$conf["external::callShell"]["argu"]=array("-rf",$conf["fileAddress"]);
3742
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
3743
				#$conf["arguIsAddr"]=array();
3744
				#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
3745
				#$conf["plainArgu"]=array();
3746
				#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
3747
				#$conf["useApostrophe"]=array();
3748
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
3749
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
3750
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
3751
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
3752
				#$conf["enablePrintDescription"]="true";
3753
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
3754
				#$conf["printDescription"]="";
3755
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
3756
				$conf["external::callShell"]["escapeshellarg"]="true";
3757
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
3758
				#$conf["thereIsShellVar"]=array();
3759
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
3760
				#$conf["username"]="";
3761
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
3762
				#$conf["password"]="";
3763
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
3764
				#$conf["useScript"]="";
3765
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
3766
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
3767
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
3768
				#$conf["inBackGround"]="";
3769
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
3770
				#$conf["getErr"]="false";
3771
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
3772
				#$conf["doNotRun"]="false";
3773
				#參考資料:
3774
				#exec=>http://php.net/manual/en/function.exec.php
3775
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
3776
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
3777
				#備註:
3778
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
3779
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
3780
				$callShell=external::callShell($conf["external::callShell"]);
3781
				unset($conf["external::callShell"]);
226 liveuser 3782
 
3 liveuser 3783
				#如果執行失敗
3784
				if($callShell["status"]==="false"){
226 liveuser 3785
 
3 liveuser 3786
					#設置錯誤識別
3787
					$result["status"]="false";
3788
 
3789
					#回傳錯誤訊息
3790
					$result["error"]=$callShell;
3791
 
3792
					#回傳結果
3793
					return $result;
226 liveuser 3794
 
3 liveuser 3795
					}#if end
226 liveuser 3796
 
3797
				}#if end
3798
 
3 liveuser 3799
			#反之不允許
3800
			else{
226 liveuser 3801
 
3 liveuser 3802
				#設置錯誤識別
3803
				$result["status"]="false";
3804
 
3805
				#回傳錯誤訊息
3806
				$result["error"][]="不允許移除目錄";
226 liveuser 3807
 
3 liveuser 3808
				#回傳結果
3809
				return $result;
226 liveuser 3810
 
3 liveuser 3811
				}#else end
226 liveuser 3812
 
3 liveuser 3813
			}#if end
226 liveuser 3814
 
3 liveuser 3815
		#反之
3816
		else{
226 liveuser 3817
 
3 liveuser 3818
			#可能為 軟連結
226 liveuser 3819
 
3 liveuser 3820
			#如果允許移除
3821
			if($conf["allowDelSymlink"]==="true"){
226 liveuser 3822
 
3 liveuser 3823
				#移除檔案,並回傳移除的結果
3824
				$eraseResult=(@unlink($conf["fileAddress"]));
3825
 
3826
				#如果 $eraseResult 等於 false
3827
				if($eraseResult===false){
226 liveuser 3828
 
3 liveuser 3829
					#設置錯誤識別
3830
					$result["status"]="false";
3831
 
3832
					#回傳錯誤訊息
3833
					$result["error"][]="檔案移除失敗";
3834
 
3835
					#回傳結果
3836
					return $result;
226 liveuser 3837
 
3 liveuser 3838
					}#if end
226 liveuser 3839
 
3 liveuser 3840
				}#if end
226 liveuser 3841
 
3 liveuser 3842
			#反之
3843
			else{
226 liveuser 3844
 
3 liveuser 3845
				#設置錯誤識別
3846
				$result["status"]="false";
226 liveuser 3847
 
3 liveuser 3848
				#設置錯誤訊息
3849
				$result["error"][]="不允許移除 檔案、目錄 以外類型的目標";
3850
 
3851
				#回傳結果
3852
				return $result;
226 liveuser 3853
 
3 liveuser 3854
				}#else end
226 liveuser 3855
 
3 liveuser 3856
			}#else end
226 liveuser 3857
 
3 liveuser 3858
		#執行到這邊代表執行正常.
3859
		$result["status"]="true";
226 liveuser 3860
 
3 liveuser 3861
		#回傳結果
3862
		return $result;
3863
 
3864
		}#function delFile end
226 liveuser 3865
 
3 liveuser 3866
	/*
3867
	#函式說明:
3868
	#移除多個檔案
3869
	#回傳結果:
3870
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
3871
	#$result["error"],錯誤訊息陣列
3872
	#$result["function"],當前執行的函數名稱.
3873
	#$result["argu"],使用的參數.
3874
	#$result["content"],陣列,移除各個檔案的結果.
3875
	#必填參數:
3876
	#$conf["fileAddress"],字串陣列,要移除檔案的位置.
3877
	$conf["fileAddress"]=array("");
3878
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3879
	$conf["fileArgu"]=__FILE__;
3880
	#可省略參數:
3881
	#無.
3882
	#參考資料:
3883
	#無.
3884
	#備註:
3885
	#無.
220 liveuser 3886
	*/
3 liveuser 3887
	public static function delMultiFile(&$conf){
226 liveuser 3888
 
3 liveuser 3889
		#初始化要回傳的結果
3890
		$result=array();
226 liveuser 3891
 
3 liveuser 3892
		#設置當其函數名稱
3893
		$result["function"]=__FUNCTION__;
226 liveuser 3894
 
3 liveuser 3895
		#如果 $conf 不為陣列
3896
		if(gettype($conf)!="array"){
226 liveuser 3897
 
3 liveuser 3898
			#設置執行失敗
3899
			$result["status"]="false";
226 liveuser 3900
 
3 liveuser 3901
			#設置執行錯誤訊息
3902
			$result["error"][]="\$conf變數須為陣列形態";
3903
 
3904
			#如果傳入的參數為 null
3905
			if($conf==null){
226 liveuser 3906
 
3 liveuser 3907
				#設置執行錯誤訊息
3908
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3909
 
3 liveuser 3910
				}#if end
3911
 
3912
			#回傳結果
3913
			return $result;
226 liveuser 3914
 
3 liveuser 3915
			}#if end
226 liveuser 3916
 
3 liveuser 3917
		#取得使用的參數.
3918
		$result["argu"]=$conf;
226 liveuser 3919
 
3 liveuser 3920
		#檢查參數
3921
		#函式說明:
3922
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3923
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3924
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3925
		#$result["function"],當前執行的函式名稱.
3926
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3927
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3928
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3929
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3930
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3931
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3932
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3933
		#必填寫的參數:
3934
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3935
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3936
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3937
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddress");
226 liveuser 3938
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3939
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
3940
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3941
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3942
		#可以省略的參數:
3943
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3944
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3945
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3946
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray");
226 liveuser 3947
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3948
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
3949
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3950
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
3951
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3952
		#$conf["arrayCountEqualCheck"][]=array();
3953
		#參考資料來源:
3954
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3955
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3956
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3957
 
3 liveuser 3958
		#如果檢查失敗
3959
		if($checkResult["status"]=="false"){
226 liveuser 3960
 
3 liveuser 3961
			#設置錯誤識別
3962
			$result["status"]="false";
226 liveuser 3963
 
3 liveuser 3964
			#設置錯誤訊息
3965
			$result["error"]=$checkResult;
226 liveuser 3966
 
3 liveuser 3967
			#回傳結果
3968
			return $result;
226 liveuser 3969
 
3 liveuser 3970
			}#if end
226 liveuser 3971
 
3 liveuser 3972
		#如果檢查不通過
3973
		if($checkResult["passed"]=="false"){
226 liveuser 3974
 
3 liveuser 3975
			#設置錯誤識別
3976
			$result["status"]="false";
226 liveuser 3977
 
3 liveuser 3978
			#設置錯誤訊息
3979
			$result["error"]=$checkResult;
226 liveuser 3980
 
3 liveuser 3981
			#回傳結果
3982
			return $result;
226 liveuser 3983
 
3 liveuser 3984
			}#if end
226 liveuser 3985
 
3 liveuser 3986
		#針對每個要移除的檔案
3987
		foreach($conf["fileAddress"] as $fileAddr){
226 liveuser 3988
 
3 liveuser 3989
			#函式說明:
3990
			#移除檔案
3991
			#回傳結果:
3992
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
3993
			#$result["error"],錯誤訊息陣列
3994
			#$result["warning"],警告訊息陣列
3995
			#$result["function"],當前執行的函數名稱
3996
			#必填參數:
3997
			#$conf["fileAddress"],字串,要移除檔案的位置.
3998
			$conf["fileAccess::delFile"]["fileAddress"]=$fileAddr;
3999
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
4000
			$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
4001
			#可省略參數:
4002
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
4003
			#$conf["commentsArray"]=array("");
4004
			#備註:
4005
			#無.
4006
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
4007
			unset($conf["fileAccess::delFile"]);
226 liveuser 4008
 
3 liveuser 4009
			#如果檢查失敗
4010
			if($delFile["status"]==="false"){
226 liveuser 4011
 
3 liveuser 4012
				#設置錯誤識別
4013
				$result["status"]="false";
226 liveuser 4014
 
3 liveuser 4015
				#設置錯誤訊息
4016
				$result["error"]=$delFile;
226 liveuser 4017
 
3 liveuser 4018
				#回傳結果
4019
				return $result;
226 liveuser 4020
 
3 liveuser 4021
				}#if end
226 liveuser 4022
 
3 liveuser 4023
			#取得移除檔案的結果
4024
			$result["content"][]=$delFile;
226 liveuser 4025
 
3 liveuser 4026
			}#foreach end
226 liveuser 4027
 
3 liveuser 4028
		#設置執行正常
4029
		$result["status"]="true";
226 liveuser 4030
 
3 liveuser 4031
		#回傳結果
4032
		return $result;
226 liveuser 4033
 
3 liveuser 4034
		}#function delMultiFile end
226 liveuser 4035
 
3 liveuser 4036
	/*
4037
	#函式說明:
4038
	#確保路徑存在.
4039
	#回傳結果:
4040
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4041
	#$result["error"],錯誤訊息陣列.
4042
	#$resutl["function"],當前執行的涵式名稱.
4043
	#$result["path"],建立好的路徑字串.
4044
	#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
4045
	#$result["argu"],使用的參數.
4046
	#必填參數:
4047
	#$conf["path"],要檢查的路徑
226 liveuser 4048
	$conf["path"]="";
3 liveuser 4049
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4050
	$conf["fileArgu"]=__FILE__;
4051
	#可省略參數:
4052
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4053
	#$conf["haveFileName"]="false";
4054
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人無法使用.
4055
	#$conf["dirPermission"]="";
4056
	#$conf["web"],是否為檔案系統,"true"為網頁路徑,"false"為網頁系統,預設為"false".
4057
	#$conf["web"]="";
4058
	#參考資料:
4059
	#無.
4060
	#備註:
4061
	#無.
226 liveuser 4062
	*/
3 liveuser 4063
	public static function validatePath(&$conf){
226 liveuser 4064
 
3 liveuser 4065
		#初始化要回傳的結果
4066
		$result=array();
226 liveuser 4067
 
3 liveuser 4068
		#設置當其函數名稱
4069
		$result["function"]=__FUNCTION__;
226 liveuser 4070
 
3 liveuser 4071
		#如果 $conf 不為陣列
4072
		if(gettype($conf)!="array"){
226 liveuser 4073
 
3 liveuser 4074
			#設置執行失敗
4075
			$result["status"]="false";
226 liveuser 4076
 
3 liveuser 4077
			#設置執行錯誤訊息
4078
			$result["error"][]="\$conf變數須為陣列形態";
4079
 
4080
			#如果傳入的參數為 null
4081
			if($conf==null){
226 liveuser 4082
 
3 liveuser 4083
				#設置執行錯誤訊息
4084
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4085
 
3 liveuser 4086
				}#if end
226 liveuser 4087
 
3 liveuser 4088
			#回傳結果
4089
			return $result;
226 liveuser 4090
 
3 liveuser 4091
			}#if end
226 liveuser 4092
 
3 liveuser 4093
		#取得使用的參數
226 liveuser 4094
		$result["argu"]=$conf;
4095
 
3 liveuser 4096
		#檢查參數
4097
		#函式說明:
4098
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4099
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4100
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4101
		#$result["function"],當前執行的函式名稱.
4102
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4103
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4104
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4105
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
4106
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
4107
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4108
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4109
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4110
		#必填寫的參數:
4111
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4112
		$conf["variableCheck::checkArgument"]["varInput"]=&$conf;
4113
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4114
		$conf["variableCheck::checkArgument"]["mustBeFilledVariableName"]=array("path","fileArgu");
4115
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
4116
		$conf["variableCheck::checkArgument"]["mustBeFilledVariableType"]=array("string","string");
4117
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4118
		$conf["variableCheck::checkArgument"]["referenceVarKey"]="variableCheck::checkArgument";
4119
		#可以省略的參數:
4120
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4121
		$conf["variableCheck::checkArgument"]["canBeEmptyString"]="false";
4122
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
4123
		$conf["variableCheck::checkArgument"]["skipableVariableCanNotBeEmpty"]=array("haveFileName","dirPermission","web");
4124
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4125
		$conf["variableCheck::checkArgument"]["skipableVariableName"]=array("haveFileName","dirPermission","web");
226 liveuser 4126
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4127
		$conf["variableCheck::checkArgument"]["skipableVariableType"]=array("string","string","string");
4128
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4129
		$conf["variableCheck::checkArgument"]["skipableVarDefaultValue"]=array("false","0770","false");
4130
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4131
		#$conf["arrayCountEqualCheck"][]=array();
4132
		#參考資料來源:
4133
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4134
		$checkArgument=variableCheck::checkArguments($conf["variableCheck::checkArgument"]);
4135
		unset($conf["variableCheck::checkArgument"]);
226 liveuser 4136
 
3 liveuser 4137
		#如果檢查過程出錯
4138
		if($checkArgument["status"]==="false"){
226 liveuser 4139
 
3 liveuser 4140
			#設置執行失敗
4141
			$result["status"]="false";
226 liveuser 4142
 
3 liveuser 4143
			#設置執行錯誤訊息
4144
			$result["error"]=$checkArgument;
4145
 
4146
			#回傳結果
4147
			return $result;
226 liveuser 4148
 
3 liveuser 4149
			}#if end
226 liveuser 4150
 
3 liveuser 4151
		#如果檢查不通過
4152
		if($checkArgument["passed"]==="false"){
226 liveuser 4153
 
3 liveuser 4154
			#設置執行失敗
4155
			$result["status"]="false";
226 liveuser 4156
 
3 liveuser 4157
			#設置執行錯誤訊息
4158
			$result["error"]=$checkArgument;
4159
 
4160
			#回傳結果
4161
			return $result;
226 liveuser 4162
 
3 liveuser 4163
			}#if end
226 liveuser 4164
 
3 liveuser 4165
		#函式說明:
4166
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
4167
		#回傳結果:
4168
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
4169
		#$result["error"],錯誤訊息陣列.
226 liveuser 4170
		#$result["function"],函數名稱.
3 liveuser 4171
		#$result["argu"],使用的參數.
4172
		#$result["content"],網址,若是在命令列執行,則為"null".
4173
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
4174
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
4175
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
4176
		#必填參數:
4177
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
4178
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["path"];
4179
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
4180
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
4181
		#可省略參數:
4182
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
4183
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
4184
		#備註:
4185
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
4186
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 4187
		unset($conf["fileAccess::getInternetAddressV2"]);
4188
 
3 liveuser 4189
		#如果檢查過程出錯
4190
		if($getInternetAddressV2["status"]=="false"){
226 liveuser 4191
 
3 liveuser 4192
			#設置執行失敗
4193
			$result["status"]="false";
226 liveuser 4194
 
3 liveuser 4195
			#設置執行錯誤訊息
4196
			$result["error"]=$getInternetAddressV2;
4197
 
4198
			#回傳結果
4199
			return $result;
226 liveuser 4200
 
4201
			}#if end
4202
 
3 liveuser 4203
		#取得轉換好的絕對路徑
4204
		$result["path"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 4205
 
3 liveuser 4206
		#debug
4207
		#var_dump($getInternetAddressV2);exit;
226 liveuser 4208
 
3 liveuser 4209
		#如果 路徑 含有檔案名稱
4210
		if($conf["haveFileName"]==="true"){
226 liveuser 4211
 
3 liveuser 4212
			#預設要加回去的結束字串為空字串
4213
			$endStr="";
226 liveuser 4214
 
3 liveuser 4215
			#如果開頭跟結尾都是 "'"
4216
			if( strpos($result["path"],"'")===0 && strpos($result["path"],"'")===(strlen($result["path"])-1) ){
226 liveuser 4217
 
3 liveuser 4218
				#設置要加回去的結束字串
4219
				$endStr="'";
226 liveuser 4220
 
3 liveuser 4221
				}#if end
226 liveuser 4222
 
3 liveuser 4223
			#函式說明:
4224
			#將固定格式的字串分開,並回傳分開的結果。
4225
			#回傳結果:
4226
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4227
			#$result["error"],錯誤訊息陣列
4228
			#$result["function"],當前執行的函數名稱.
4229
			#$result["argu"],使用的參數.
4230
			#$result["oriStr"],要分割的原始字串內容
4231
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4232
			#$result["dataCounts"],爲總共分成幾段
4233
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
4234
			#必填參數:
4235
			#$conf["stringIn"],字串,要處理的字串.
4236
			$conf["stringProcess::spiltString"]["stringIn"]=$result["path"];
4237
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
4238
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
4239
			#可省略參數:
4240
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
4241
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
4242
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4243
			unset($conf["stringProcess::spiltString"]);
226 liveuser 4244
 
3 liveuser 4245
			#如果檢查過程出錯
4246
			if($spiltString["status"]==="false"){
226 liveuser 4247
 
3 liveuser 4248
				#設置執行失敗
4249
				$result["status"]="false";
226 liveuser 4250
 
3 liveuser 4251
				#設置執行錯誤訊息
4252
				$result["error"]=$spiltString;
4253
 
4254
				#回傳結果
4255
				return $result;
226 liveuser 4256
 
3 liveuser 4257
				}#if end
226 liveuser 4258
 
3 liveuser 4259
			#初始化儲存 path
4260
			$path="";
226 liveuser 4261
 
3 liveuser 4262
			#針對n-1段的內容
4263
			for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 4264
 
3 liveuser 4265
				#串接路徑
4266
				$path=$path."/".$spiltString["dataArray"][$i];
226 liveuser 4267
 
3 liveuser 4268
				}#for end
226 liveuser 4269
 
3 liveuser 4270
			#如果路徑為空
4271
			if($path===""){
226 liveuser 4272
 
3 liveuser 4273
				#則與設為根目錄
4274
				$path="/";
226 liveuser 4275
 
3 liveuser 4276
				}#if end
226 liveuser 4277
 
3 liveuser 4278
			#設置檔案名稱
4279
			$result["fileName"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 4280
 
3 liveuser 4281
			#取得不含檔案名稱的路徑
4282
			$conf["path"]=$path.$endStr;
226 liveuser 4283
 
3 liveuser 4284
			#取得不含檔案名稱的路徑
4285
			$result["path"]=$path.$endStr;
226 liveuser 4286
 
3 liveuser 4287
			}#if end
226 liveuser 4288
 
3 liveuser 4289
		#函式說明:
4290
		#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
4291
		#回傳結果:
4292
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
4293
		#$result["error"],錯誤訊息陣列
4294
		#必填參數:
4295
		$conf["fileAccess::createFolderAfterCheck"]["dirPositionAndName"]=$conf["path"];#新建的位置與名稱
4296
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4297
		$conf["fileAccess::createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
4298
		#可省略參數:
4299
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
4300
		$conf["fileAccess::createFolderAfterCheck"]["dirPermission"]=$conf["dirPermission"];
4301
		$conf["fileAccess::createFolderAfterCheck"]["web"]="false";
4302
		#參考資料:
4303
		#mkdir=>http://php.net/manual/en/function.mkdir.php
4304
		#chmod=>http://php.net/manual/en/function.chmod.php
4305
		$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf["fileAccess::createFolderAfterCheck"]);
4306
		unset($conf["fileAccess::createFolderAfterCheck"]);
226 liveuser 4307
 
3 liveuser 4308
		#如果建立路徑過程出錯
4309
		if($createFolderAfterCheck["status"]==="false"){
226 liveuser 4310
 
3 liveuser 4311
			#設置執行失敗
4312
			$result["status"]="false";
226 liveuser 4313
 
3 liveuser 4314
			#設置執行錯誤訊息
4315
			$result["error"]=$createFolderAfterCheck;
4316
 
4317
			#回傳結果
4318
			return $result;
226 liveuser 4319
 
3 liveuser 4320
			}#if end
226 liveuser 4321
 
3 liveuser 4322
		#如果有警告訊息
4323
		if(count($createFolderAfterCheck["warning"])>0){
226 liveuser 4324
 
3 liveuser 4325
			#取得警告訊息
4326
			$result["error"]=$createFolderAfterCheck["warning"];
226 liveuser 4327
 
3 liveuser 4328
			#設置執行失敗
4329
			$result["status"]="false";
226 liveuser 4330
 
3 liveuser 4331
			#回傳結果
4332
			return $result;
226 liveuser 4333
 
3 liveuser 4334
			}#if end
226 liveuser 4335
 
3 liveuser 4336
		#執行到這邊代表成功
4337
		$result["status"]="true";
226 liveuser 4338
 
3 liveuser 4339
		#回傳結果
4340
		return $result;
226 liveuser 4341
 
3 liveuser 4342
		}#function validatePath end
226 liveuser 4343
 
3 liveuser 4344
	/*
4345
	#函式說明:
4346
	#解析路徑的每個層級.
4347
	#回傳結果:
4348
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4349
	#$result["error"],錯誤訊息陣列.
4350
	#$resutl["function"],當前執行的涵式名稱.
4351
	#$result["argu"],使用的參數.
4352
	#$result["content"],解析出來的路徑階層.
4353
	#必填參數:
4354
	#$conf["path"],要檢查的路徑
4355
	$conf["path"]="";
4356
	#可省略參數:
4357
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4358
	#$conf["haveFileName"]="false";
4359
	#參考資料:
4360
	#無.
4361
	#備註:
4362
	#無.
4363
	*/
4364
	public static function parsePath(&$conf){
226 liveuser 4365
 
3 liveuser 4366
		#初始化要回傳的內容
4367
		$result=array();
4368
 
4369
		#取得當前執行的函數名稱
4370
		$result["function"]=__FUNCTION__;
4371
 
4372
		#如果 $conf 不為陣列
4373
		if(gettype($conf)!="array"){
226 liveuser 4374
 
3 liveuser 4375
			#設置執行失敗
4376
			$result["status"]="false";
226 liveuser 4377
 
3 liveuser 4378
			#設置執行錯誤訊息
4379
			$result["error"][]="\$conf變數須為陣列形態";
4380
 
4381
			#如果傳入的參數為 null
4382
			if($conf==null){
226 liveuser 4383
 
3 liveuser 4384
				#設置執行錯誤訊息
4385
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4386
 
3 liveuser 4387
				}#if end
4388
 
4389
			#回傳結果
4390
			return $result;
226 liveuser 4391
 
3 liveuser 4392
			}#if end
4393
 
4394
		#記錄使用的參數
4395
		$result["argu"]=$conf;
4396
 
4397
		#檢查參數
4398
		#函式說明:
4399
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4400
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4401
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4402
		#$result["function"],當前執行的函式名稱.
4403
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4404
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4405
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4406
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4407
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4408
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4409
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4410
		#必填寫的參數:
4411
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4412
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4413
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4414
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
226 liveuser 4415
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 4416
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
4417
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4418
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4419
		#可以省略的參數:
4420
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4421
		#$conf["canBeEmptyString"]="false";
4422
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4423
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("haveFileName");
226 liveuser 4424
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4425
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
4426
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4427
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
4428
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4429
		#$conf["arrayCountEqualCheck"][]=array();
4430
		#參考資料來源:
4431
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4432
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4433
		unset($conf["variableCheck::checkArguments"]);
4434
 
4435
		#如果檢查有誤
4436
		if($checkResult["status"]=="false"){
226 liveuser 4437
 
3 liveuser 4438
			#設置錯誤識別
4439
			$result["status"]="false";
226 liveuser 4440
 
3 liveuser 4441
			#設置錯誤訊息
4442
			$result["error"]=$checkResult;
226 liveuser 4443
 
3 liveuser 4444
			#回傳結果
4445
			return $result;
226 liveuser 4446
 
3 liveuser 4447
			}#if end
226 liveuser 4448
 
3 liveuser 4449
		#如果檢查不通過
4450
		if($checkResult["passed"]=="false"){
226 liveuser 4451
 
3 liveuser 4452
			#設置錯誤識別
4453
			$result["status"]="false";
226 liveuser 4454
 
3 liveuser 4455
			#設置錯誤訊息
4456
			$result["error"]=$checkResult;
226 liveuser 4457
 
3 liveuser 4458
			#回傳結果
4459
			return $result;
226 liveuser 4460
 
3 liveuser 4461
			}#if end
226 liveuser 4462
 
3 liveuser 4463
		#函式說明:
4464
		#將固定格式的字串分開,並回傳分開的結果.
4465
		#回傳結果:
4466
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4467
		#$result["error"],錯誤訊息陣列
4468
		#$result["function"],當前執行的函數名稱.
4469
		#$result["argu"],使用的參數.
4470
		#$result["oriStr"],要分割的原始字串內容
4471
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4472
		#$result["dataCounts"],爲總共分成幾段
4473
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
4474
		#必填參數:
4475
		#$conf["stringIn"],字串,要處理的字串.
4476
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["path"];
4477
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
4478
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
4479
		#可省略參數:
4480
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
4481
		#$conf["allowEmptyStr"]="false";
4482
		#參考資料:
4483
		#無.
4484
		#備註:
4485
		#無.
4486
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4487
		unset($conf["stringProcess::spiltString"]);
226 liveuser 4488
 
3 liveuser 4489
		#如果檢查有誤
4490
		if($spiltString["status"]==="false"){
226 liveuser 4491
 
3 liveuser 4492
			#設置錯誤識別
4493
			$result["status"]="false";
226 liveuser 4494
 
3 liveuser 4495
			#設置錯誤訊息
4496
			$result["error"]=$spiltString;
226 liveuser 4497
 
3 liveuser 4498
			#回傳結果
4499
			return $result;
226 liveuser 4500
 
3 liveuser 4501
			}#if end
226 liveuser 4502
 
3 liveuser 4503
		#確認是否為絕對路徑
4504
		#函式說明:
4505
		#取得符合特定字首與字尾的字串
4506
		#回傳結果:
4507
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
4508
		#$result["function"],當前執行的函數名稱.
4509
		#$result["error"],錯誤訊息陣列.
4510
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
4511
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
4512
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
4513
		#$result["argu"],使用的參數.
4514
		#必填參數:
4515
		#$conf["checkString"],字串,要檢查的字串.
4516
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["path"];
4517
		#可省略參數:
4518
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
4519
		$conf["search::getMeetConditionsString"]["frontWord"]="/";
4520
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
4521
		#$conf["search::getMeetConditionsString"]["tailWord"]="";
4522
		#參考資料:
4523
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
4524
		#備註:
4525
		#無.
4526
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
4527
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 4528
 
3 liveuser 4529
		#如果檢查有誤
4530
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 4531
 
3 liveuser 4532
			#設置錯誤識別
4533
			$result["status"]="false";
226 liveuser 4534
 
3 liveuser 4535
			#設置錯誤訊息
4536
			$result["error"]=$getMeetConditionsString;
226 liveuser 4537
 
3 liveuser 4538
			#回傳結果
4539
			return $result;
226 liveuser 4540
 
3 liveuser 4541
			}#if end
226 liveuser 4542
 
3 liveuser 4543
		#如果是絕對路徑
4544
		if($getMeetConditionsString["founded"]==="true"){
226 liveuser 4545
 
3 liveuser 4546
			#初始化路徑為 "/"
4547
			$result["content"][]="/";
226 liveuser 4548
 
3 liveuser 4549
			}#if end
226 liveuser 4550
 
3 liveuser 4551
		#針對每個切割出來的路徑階層
4552
		foreach($spiltString["dataArray"] as $index => $dir){
226 liveuser 4553
 
3 liveuser 4554
			#如果路徑結尾含有檔案名稱
4555
			if($conf["haveFileName"]==="true"){
226 liveuser 4556
 
3 liveuser 4557
				#如果是最後一段
4558
				if($index===$spiltString["dataCounts"]-1){
226 liveuser 4559
 
3 liveuser 4560
					#忽略
4561
					continue;
226 liveuser 4562
 
3 liveuser 4563
					}#if end
226 liveuser 4564
 
3 liveuser 4565
				}#if end
226 liveuser 4566
 
3 liveuser 4567
			#後面加上 資料夾名稱 跟 "/"
4568
			$newPath=$dir."/";
226 liveuser 4569
 
3 liveuser 4570
			#如果有 content
4571
			if(isset($result["content"])){
226 liveuser 4572
 
3 liveuser 4573
				#如果有上個資料夾
4574
				if(isset($result["content"][count($result["content"])-1])){
226 liveuser 4575
 
3 liveuser 4576
					#後面加上 上個資料夾名稱 加上資料夾名稱 跟 "/"
4577
					$newPath=$result["content"][count($result["content"])-1].$dir."/";
226 liveuser 4578
 
3 liveuser 4579
					}#if end
226 liveuser 4580
 
3 liveuser 4581
				}#if end
226 liveuser 4582
 
3 liveuser 4583
			#並新增置結果
4584
			$result["content"][]=$newPath;
226 liveuser 4585
 
3 liveuser 4586
			}#foreach end
226 liveuser 4587
 
3 liveuser 4588
		#var_dump($result["content"]);
226 liveuser 4589
 
3 liveuser 4590
		#設置執行正常
4591
		$result["status"]="true";
226 liveuser 4592
 
3 liveuser 4593
		#回傳結果
4594
		return $result;
226 liveuser 4595
 
3 liveuser 4596
		}#function parsePath end
226 liveuser 4597
 
3 liveuser 4598
	/*
4599
	#函式說明:
4600
	#檢查路徑是否存在.
4601
	#回傳結果:
4602
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4603
	#$result["error"],錯誤訊息陣列.
4604
	#$resutl["function"],當前執行的涵式名稱.
4605
	#$result["argu"],使用的參數.
4606
	#$result["found"],路徑是否存在,"true"代表存在,"false"代表不存在.
4607
	#$result["content"],每個階層路徑的檢查結果,每個元素有檢查的路徑"path"跟是否有存在或可存取的識別"found".
4608
	#必填參數:
4609
	#$conf["path"],要檢查的路徑
4610
	$conf["path"]="";
4611
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4612
	$conf["fileArgu"]=__FILE__;
4613
	#可省略參數:
4614
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4615
	#$conf["haveFileName"]="false";
4616
	#參考資料:
4617
	#無.
4618
	#備註:
4619
	#無.
4620
	*/
4621
	public static function checkPathExist(&$conf){
226 liveuser 4622
 
3 liveuser 4623
		#初始化要回傳的內容
4624
		$result=array();
4625
 
4626
		#取得當前執行的函數名稱
4627
		$result["function"]=__FUNCTION__;
4628
 
4629
		#如果 $conf 不為陣列
4630
		if(gettype($conf)!="array"){
226 liveuser 4631
 
3 liveuser 4632
			#設置執行失敗
4633
			$result["status"]="false";
226 liveuser 4634
 
3 liveuser 4635
			#設置執行錯誤訊息
4636
			$result["error"][]="\$conf變數須為陣列形態";
4637
 
4638
			#如果傳入的參數為 null
4639
			if($conf==null){
226 liveuser 4640
 
3 liveuser 4641
				#設置執行錯誤訊息
4642
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4643
 
3 liveuser 4644
				}#if end
4645
 
4646
			#回傳結果
4647
			return $result;
226 liveuser 4648
 
3 liveuser 4649
			}#if end
4650
 
4651
		#記錄使用的參數
4652
		$result["argu"]=$conf;
4653
 
4654
		#檢查參數
4655
		#函式說明:
4656
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4657
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4658
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4659
		#$result["function"],當前執行的函式名稱.
4660
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4661
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4662
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4663
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4664
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4665
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4666
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4667
		#必填寫的參數:
4668
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4669
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4670
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4671
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 4672
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 4673
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
4674
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4675
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4676
		#可以省略的參數:
4677
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4678
		#$conf["canBeEmptyString"]="false";
4679
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4680
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("haveFileName");
226 liveuser 4681
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4682
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
4683
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4684
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
4685
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4686
		#$conf["arrayCountEqualCheck"][]=array();
4687
		#參考資料來源:
4688
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4689
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4690
		unset($conf["variableCheck::checkArguments"]);
4691
 
4692
		#如果檢查有誤
4693
		if($checkResult["status"]=="false"){
226 liveuser 4694
 
3 liveuser 4695
			#設置錯誤識別
4696
			$result["status"]="false";
226 liveuser 4697
 
3 liveuser 4698
			#設置錯誤訊息
4699
			$result["error"]=$checkResult;
226 liveuser 4700
 
3 liveuser 4701
			#回傳結果
4702
			return $result;
226 liveuser 4703
 
3 liveuser 4704
			}#if end
226 liveuser 4705
 
3 liveuser 4706
		#如果檢查不通過
4707
		if($checkResult["passed"]=="false"){
226 liveuser 4708
 
3 liveuser 4709
			#設置錯誤識別
4710
			$result["status"]="false";
226 liveuser 4711
 
3 liveuser 4712
			#設置錯誤訊息
4713
			$result["error"]=$checkResult;
226 liveuser 4714
 
3 liveuser 4715
			#回傳結果
4716
			return $result;
226 liveuser 4717
 
3 liveuser 4718
			}#if end
226 liveuser 4719
 
3 liveuser 4720
		#函式說明:
4721
		#解析路徑的每個層級.
4722
		#回傳結果:
4723
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4724
		#$result["error"],錯誤訊息陣列.
4725
		#$resutl["function"],當前執行的涵式名稱.
4726
		#$result["argu"],使用的參數.
4727
		#$result["content"],解析出來的路徑階層.
4728
		#必填參數:
4729
		#$conf["path"],要檢查的路徑
4730
		$conf["fileAccess::parsePath"]["path"]=$conf["path"];
4731
		#可省略參數:
4732
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4733
		$conf["fileAccess::parsePath"]["haveFileName"]=$conf["haveFileName"];
4734
		#參考資料:
4735
		#無.
4736
		#備註:
4737
		#無.
4738
		$parsePath=fileAccess::parsePath($conf["fileAccess::parsePath"]);
4739
		unset($conf["fileAccess::parsePath"]);
226 liveuser 4740
 
3 liveuser 4741
		#如果檢查有誤
4742
		if($parsePath["status"]==="false"){
226 liveuser 4743
 
3 liveuser 4744
			#設置錯誤識別
4745
			$result["status"]="false";
226 liveuser 4746
 
3 liveuser 4747
			#設置錯誤訊息
4748
			$result["error"]=$parsePath;
226 liveuser 4749
 
3 liveuser 4750
			#回傳結果
4751
			return $result;
226 liveuser 4752
 
3 liveuser 4753
			}#if end
226 liveuser 4754
 
3 liveuser 4755
		#函式說明:
4756
		#檢查多個檔案與資料夾是否存在.
4757
		#回傳的結果:
4758
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4759
		#$result["error"],錯誤訊息陣列.
4760
		#$resutl["function"],當前執行的涵式名稱.
4761
		#$result["argu"],使用的參數.
4762
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
4763
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
4764
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
4765
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
4766
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
4767
		#必填參數:
4768
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
4769
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$parsePath["content"];
4770
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4771
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
4772
		#可省略參數:
4773
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
4774
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
4775
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
4776
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
4777
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
4778
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
4779
		#參考資料:
4780
		#http://php.net/manual/en/function.file-exists.php
4781
		#http://php.net/manual/en/control-structures.foreach.php
4782
		#備註:
4783
		#函數file_exists檢查的路徑為檔案系統的路徑
4784
		#$result["varName"][$i]結果未實作
4785
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
4786
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 4787
 
3 liveuser 4788
		#如果執行異常
4789
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 4790
 
3 liveuser 4791
			#設置錯誤識別
4792
			$result["status"]="false";
226 liveuser 4793
 
3 liveuser 4794
			#設置錯誤訊息
4795
			$result["error"]=$checkMultiFileExist;
226 liveuser 4796
 
3 liveuser 4797
			#回傳結果
4798
			return $result;
226 liveuser 4799
 
3 liveuser 4800
			}#if end
226 liveuser 4801
 
3 liveuser 4802
		#如果有路徑無法存取
4803
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 4804
 
3 liveuser 4805
			#設置執行正常識別
4806
			$result["status"]="true";
226 liveuser 4807
 
3 liveuser 4808
			#設置路徑找不到
4809
			$result["found"]="false";
226 liveuser 4810
 
3 liveuser 4811
			#針對每個路徑的搜尋結果
4812
			foreach($checkMultiFileExist["varExist"] as $index => $found){
226 liveuser 4813
 
3 liveuser 4814
				#設置路徑尋找結果
4815
				$result["content"][]=array("found"=>$found,"path"=>$checkMultiFileExist["varNameFullPath"][$index]);
226 liveuser 4816
 
3 liveuser 4817
				}#foreach end
226 liveuser 4818
 
3 liveuser 4819
			#回傳結果
4820
			return $result;
226 liveuser 4821
 
3 liveuser 4822
			}#if end
226 liveuser 4823
 
3 liveuser 4824
		#設置路徑有找到
4825
		$result["found"]="true";
226 liveuser 4826
 
3 liveuser 4827
		#設置執行正常識別
4828
		$result["status"]="true";
226 liveuser 4829
 
3 liveuser 4830
		#回傳結果
4831
		return $result;
226 liveuser 4832
 
3 liveuser 4833
		}#function checkPathExist end
226 liveuser 4834
 
4835
	/*
3 liveuser 4836
	#函式說明:
4837
	#demo建立pdf檔
4838
	#必填參數:
4839
	#無
4840
	#可省略參數:
4841
	#無
4842
	#參考資料:
4843
	#tcpdf=>http://www.tcpdf.org/examples.php
4844
	#備註:
4845
	#開發中,需要安裝 php-tcpdf 套件.
4846
	*/
4847
	public static function demoCreateTcPdfFile(){
226 liveuser 4848
 
3 liveuser 4849
		#避免 TCPDF ERROR: Some data has already been output, can't send PDF file 錯誤產生
4850
		ob_end_clean();
226 liveuser 4851
 
3 liveuser 4852
		#create new PDF document
4853
		$pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
226 liveuser 4854
 
3 liveuser 4855
		#set document information
4856
		$pdf->SetCreator(PDF_CREATOR);
4857
		$pdf->SetAuthor('qbpwc');
4858
		$pdf->SetTitle('pdf sample title');
4859
		$pdf->SetSubject('pdf sample subject');
4860
		$pdf->SetKeywords('pdf, sample, tcpdf, qbpwc');
226 liveuser 4861
 
3 liveuser 4862
		#set default header data
4863
		$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
4864
		$pdf->setFooterData(array(0,64,0), array(0,64,128));
226 liveuser 4865
 
3 liveuser 4866
		#set header and footer fonts
4867
		$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
4868
		$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
226 liveuser 4869
 
3 liveuser 4870
		#set default monospaced font
4871
		$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
226 liveuser 4872
 
3 liveuser 4873
		#set margins
4874
		$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
4875
		$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
4876
		$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
4877
 
4878
		#set auto page breaks
4879
		$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
4880
 
4881
		#set image scale factor
4882
		$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
4883
 
4884
		#set some language-dependent strings (optional)
4885
		if (@file_exists(dirname(__FILE__).'/lang/eng.php')){
226 liveuser 4886
 
3 liveuser 4887
			require_once(dirname(__FILE__).'/lang/eng.php');
226 liveuser 4888
 
3 liveuser 4889
			$pdf->setLanguageArray($l);
226 liveuser 4890
 
3 liveuser 4891
			}#if end
226 liveuser 4892
 
3 liveuser 4893
		#set default font subsetting mode
4894
		$pdf->setFontSubsetting(true);
226 liveuser 4895
 
3 liveuser 4896
		#Set font
4897
		#dejavusans is a UTF-8 Unicode font, if you only need to
4898
		#print standard ASCII chars, you can use core fonts like
4899
		#helvetica or times to reduce file size.
4900
		$pdf->SetFont('dejavusans', '', 14, '', true);
226 liveuser 4901
 
3 liveuser 4902
		#Add a page
4903
		#This method has several options, check the source code documentation for more information.
4904
		$pdf->AddPage();
226 liveuser 4905
 
3 liveuser 4906
		#set text shadow effect
4907
		$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
226 liveuser 4908
 
3 liveuser 4909
		#Set some content to print
4910
		$html="<h5>Hello World!</h5>";
226 liveuser 4911
 
3 liveuser 4912
		// Print text using writeHTMLCell()
4913
		$pdf->writeHTMLCell(0,0,'','',$html,0,1,0,true,'',true);
4914
 
4915
		// Close and output PDF document
4916
		// This method has several options, check the source code documentation for more information.
4917
		$pdf->Output('fileAccessT/example_001.pdf','I');
226 liveuser 4918
 
3 liveuser 4919
		}#function demoCreateTcPdfFile end
226 liveuser 4920
 
3 liveuser 4921
	/*
4922
	#函式說明:
4923
	#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
4924
	#回傳的結果:
4925
	#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
4926
	#$result["error"],錯誤訊息.
4927
	#$result["function"],當前執行的函式名稱.
4928
	#$result["filePath"],路徑字串.
4929
	#$result["fileName"],檔案名稱字串.
4930
	#$result["fileExtention"],檔案的副檔名.
4931
	#$result["fullFileName"],含副檔名的檔案名稱.
4932
	#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
4933
	#必填參數:
4934
	#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
4935
	$conf["fileAddressAndName"]="";
4936
	#可省略參數:
4937
	#無.
4938
	#參考資料:
4939
	#無.
4940
	#備註:
4941
	#無.
4942
	*/
4943
	public static function getFileAddressAndNameAndFileExtention(&$conf){
226 liveuser 4944
 
3 liveuser 4945
		#初始化要回傳的參數
4946
		$result=array();
226 liveuser 4947
 
3 liveuser 4948
		#取得當前執行函數名稱
4949
		$result["function"]=__FUNCTION__;
4950
 
4951
		#如果 $conf 不為陣列
4952
		if(gettype($conf)!="array"){
226 liveuser 4953
 
3 liveuser 4954
			#設置執行失敗
4955
			$result["status"]="false";
226 liveuser 4956
 
3 liveuser 4957
			#設置執行錯誤訊息
4958
			$result["error"][]="\$conf變數須為陣列形態";
4959
 
4960
			#如果傳入的參數為 null
4961
			if($conf==null){
226 liveuser 4962
 
3 liveuser 4963
				#設置執行錯誤訊息
4964
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4965
 
3 liveuser 4966
				}#if end
4967
 
4968
			#回傳結果
4969
			return $result;
226 liveuser 4970
 
3 liveuser 4971
			}#if end
4972
 
4973
		#檢查參數
4974
		#函式說明:
4975
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4976
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4977
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4978
		#$result["function"],當前執行的函式名稱.
4979
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4980
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4981
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4982
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4983
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4984
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4985
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4986
		#必填寫的參數:
4987
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4988
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4989
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4990
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileAddressAndName");
226 liveuser 4991
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 4992
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
4993
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4994
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4995
		#可以省略的參數:
4996
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
4997
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
4998
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4999
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("outputAddress","noDownload");
226 liveuser 5000
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5001
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
5002
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5003
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".bin/".$conf["cppAddress"].".bin","true");
5004
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5005
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
5006
		#參考資料來源:
5007
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5008
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5009
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5010
 
3 liveuser 5011
		#如果 $checkArguments["status"] 等於 "false"
5012
		if($checkArguments["status"]=="false"){
226 liveuser 5013
 
3 liveuser 5014
			#設置 $result["status"] 為 "false"
5015
			$result["status"]="false";
226 liveuser 5016
 
3 liveuser 5017
			#設置 $result["error"]
5018
			$result["error"]=$checkArguments;
226 liveuser 5019
 
3 liveuser 5020
			#回傳結果
5021
			return $result;
226 liveuser 5022
 
3 liveuser 5023
			}#if end
226 liveuser 5024
 
3 liveuser 5025
		#如果 $checkArguments["passed"] 等於 "false"
5026
		if($checkArguments["passed"]=="false"){
226 liveuser 5027
 
3 liveuser 5028
			#設置 $result["status"] 為 "false"
5029
			$result["status"]="false";
226 liveuser 5030
 
3 liveuser 5031
			#設置 $result["error"]
5032
			$result["error"]=$checkArguments;
226 liveuser 5033
 
3 liveuser 5034
			#回傳結果
5035
			return $result;
226 liveuser 5036
 
3 liveuser 5037
			}#if end
226 liveuser 5038
 
3 liveuser 5039
		#確認路徑是否為絕對路徑
5040
		#函式說明:
5041
		#取得符合特定字首與字尾的字串
5042
		#回傳結果:
5043
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
5044
		#$result["function"],當前執行的函數名稱.
5045
		#$result["error"],錯誤訊息陣列.
5046
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
5047
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
5048
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
5049
		#$result["argu"],使用的參數.
5050
		#必填參數:
5051
		#$conf["checkString"],字串,要檢查的字串.
5052
		$conf["fileAccess::getMeetConditionsString"]["checkString"]=$conf["fileAddressAndName"];
5053
		#可省略參數:
5054
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
5055
		$conf["fileAccess::getMeetConditionsString"]["frontWord"]="/";
5056
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
5057
		#$conf["tailWord"]="";
5058
		#參考資料:
5059
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
5060
		#備註:
5061
		#無.
5062
		$getMeetConditionsString=search::getMeetConditionsString($conf["fileAccess::getMeetConditionsString"]);
5063
		unset($conf["fileAccess::getMeetConditionsString"]);
226 liveuser 5064
 
3 liveuser 5065
		#如果執行出錯
5066
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 5067
 
3 liveuser 5068
			#設置錯誤識別
5069
			$result["status"]="false";
226 liveuser 5070
 
3 liveuser 5071
			#設置錯誤訊息
5072
			$result["error"]=$getMeetConditionsString;
226 liveuser 5073
 
3 liveuser 5074
			#回傳結果
5075
			return $result;
226 liveuser 5076
 
3 liveuser 5077
			}#if end
226 liveuser 5078
 
3 liveuser 5079
		#預設參數 $conf["fileAddressAndName"] 不為 "/" 開始
5080
		$fileAddressAndNameStarFromRoot="true";
226 liveuser 5081
 
3 liveuser 5082
		#如果是 "/" 開頭
5083
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 5084
 
3 liveuser 5085
			#設置參數 $conf["fileAddressAndName"] 為 "/" 開始
5086
			$fileAddressAndNameStarFromRoot="true";
226 liveuser 5087
 
3 liveuser 5088
			}#if end
226 liveuser 5089
 
5090
		#檢查是否有路徑資訊
3 liveuser 5091
		#函式說明:
5092
		#將固定格式的字串分開,並回傳分開的結果。
5093
		#回傳的參數:
5094
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5095
		#$result["error"],錯誤訊息陣列
5096
		#$result["oriStr"],要分割的原始字串內容
5097
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5098
		#$result["dataCounts"],爲總共分成幾段
5099
		#必填參數:
5100
		$conf["stringProcess"]["spiltString"]["stringIn"]=$conf["fileAddressAndName"];#要處理的字串。
5101
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
5102
		$spiledResult=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5103
		unset($conf["stringProcess"]["spiltString"]);
226 liveuser 5104
 
3 liveuser 5105
		#如果 $spiledResult["status"] 等於 "false"
5106
		if($spiledResult["status"]==="false"){
226 liveuser 5107
 
3 liveuser 5108
			#設置錯誤識別
5109
			$result["status"]="false";
226 liveuser 5110
 
3 liveuser 5111
			#設置錯誤訊息
5112
			$result["error"]=$spiledResult;
226 liveuser 5113
 
3 liveuser 5114
			#回傳結果
5115
			return $result;
226 liveuser 5116
 
3 liveuser 5117
			}#if end
226 liveuser 5118
 
3 liveuser 5119
		#如果 $spiledResult["dataCounts"] 大於 1
5120
		if($spiledResult["dataCounts"]>1){
226 liveuser 5121
 
3 liveuser 5122
			#代表有路徑字串
226 liveuser 5123
 
3 liveuser 5124
			#初始化路徑字串暫存變數
5125
			$tempPathStr="";
226 liveuser 5126
 
3 liveuser 5127
			#如果是絕對路徑
5128
			if($fileAddressAndNameStarFromRoot==="true"){
226 liveuser 5129
 
3 liveuser 5130
				#加上根目錄
5131
				$tempPathStr=$tempPathStr."/";
226 liveuser 5132
 
3 liveuser 5133
				}#if end
226 liveuser 5134
 
3 liveuser 5135
			#取得路徑字串
5136
			for($i=0;$i<$spiledResult["dataCounts"]-1;$i++){
226 liveuser 5137
 
3 liveuser 5138
				#串連片段路徑字串
5139
				$tempPathStr=$tempPathStr.$spiledResult["dataArray"][$i]."/";
226 liveuser 5140
 
3 liveuser 5141
				}#for end
226 liveuser 5142
 
3 liveuser 5143
			#取得檔案的路徑
5144
			$result["filePath"]=$tempPathStr;
226 liveuser 5145
 
3 liveuser 5146
			}#if end
226 liveuser 5147
 
3 liveuser 5148
		#反之 $spiledResult["dataCounts"] 等於 1
5149
		else{
226 liveuser 5150
 
3 liveuser 5151
			#檔案的路徑設為""
5152
			$result["filePath"]="";
226 liveuser 5153
 
3 liveuser 5154
			}#else end
226 liveuser 5155
 
3 liveuser 5156
		#取得檔案名稱(含副檔名)
5157
		$result["fullFileName"]=$spiledResult["dataArray"][$spiledResult["dataCounts"]-1];
226 liveuser 5158
 
3 liveuser 5159
		#取得副檔名
5160
		#函式說明:
5161
		#將固定格式的字串分開,並回傳分開的結果。
5162
		#回傳的參數:
5163
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5164
		#$result["error"],錯誤訊息陣列
5165
		#$result["oriStr"],要分割的原始字串內容
5166
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5167
		#$result["dataCounts"],爲總共分成幾段
5168
		#必填參數:
5169
		$conf["stringProcess"]["spiltString"]["stringIn"]=$result["fullFileName"];#要處理的字串。
5170
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
5171
		$spiledResult=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5172
		unset($conf["stringProcess"]["spiltString"]);
226 liveuser 5173
 
3 liveuser 5174
		#如果 $spiledResult["status"] 等於 "false"
5175
		if($spiledResult["status"]=="false"){
226 liveuser 5176
 
3 liveuser 5177
			#設置錯誤識別
5178
			$result["status"]="false";
226 liveuser 5179
 
3 liveuser 5180
			#設置錯誤訊息
5181
			$result["error"]=$spiledResult;
226 liveuser 5182
 
3 liveuser 5183
			#回傳結果
5184
			return $result;
226 liveuser 5185
 
3 liveuser 5186
			}#if end
226 liveuser 5187
 
3 liveuser 5188
		#如果 $spiledResult["dataCounts"] 大於 1
5189
		if($spiledResult["dataCounts"]>1){
226 liveuser 5190
 
3 liveuser 5191
			#代表有副檔名
226 liveuser 5192
 
3 liveuser 5193
			#初始化檔名字串暫存變數
5194
			$tempFileNameStr="";
226 liveuser 5195
 
3 liveuser 5196
			#取得路徑字串
5197
			for($i=0;$i<$spiledResult["dataCounts"]-1;$i++){
226 liveuser 5198
 
3 liveuser 5199
				#如果是最後一個小黑點前面的字串片段
5200
				if($i==$spiledResult["dataCounts"]-2){
226 liveuser 5201
 
3 liveuser 5202
					#串連片段路徑字串
5203
					$tempFileNameStr=$tempFileNameStr.$spiledResult["dataArray"][$i];
226 liveuser 5204
 
3 liveuser 5205
					}#if end
226 liveuser 5206
 
3 liveuser 5207
				#反之不是最後一個小黑點前面的字串片段
5208
				else{
226 liveuser 5209
 
3 liveuser 5210
					#串連片段路徑字串(含小黑點)
5211
					$tempFileNameStr=$tempFileNameStr.$spiledResult["dataArray"][$i].".";
226 liveuser 5212
 
3 liveuser 5213
					}#else end
226 liveuser 5214
 
3 liveuser 5215
				}#for end
226 liveuser 5216
 
3 liveuser 5217
			#取得檔名
5218
			$result["fileName"]=$tempFileNameStr;
226 liveuser 5219
 
3 liveuser 5220
			#取得副檔名
5221
			$result["fileExtention"]=$spiledResult["dataArray"][$spiledResult["dataCounts"]-1];
226 liveuser 5222
 
3 liveuser 5223
			}#if end
226 liveuser 5224
 
3 liveuser 5225
		#反之 $spiledResult["dataCounts"] 等於 1
5226
		else{
226 liveuser 5227
 
3 liveuser 5228
			#檔案的副檔名設為""
5229
			$result["fileExtention"]="";
226 liveuser 5230
 
3 liveuser 5231
			#取得檔案的名稱
5232
			$result["fileName"]=$spiledResult["dataArray"][0];
226 liveuser 5233
 
3 liveuser 5234
			}#else end
226 liveuser 5235
 
3 liveuser 5236
		#如果 $result["fileExtention"] 不等於 ""
5237
		if($result["fileExtention"]!=""){
226 liveuser 5238
 
3 liveuser 5239
			#將副檔名用小黑點跟檔案名稱連在一塊
5240
			$result["fullFileName"]=$result["fileName"].".".$result["fileExtention"];
226 liveuser 5241
 
3 liveuser 5242
			}#if end
226 liveuser 5243
 
3 liveuser 5244
		#反之代表沒有副檔名
5245
		else{
226 liveuser 5246
 
3 liveuser 5247
			#取得含副檔名的檔案名稱
5248
			$result["fullFileName"]=$result["fileName"].$result["fileExtention"];
226 liveuser 5249
 
3 liveuser 5250
			}#else end
226 liveuser 5251
 
3 liveuser 5252
		#完整的檔案路徑(含副檔名).
5253
		$result["fullFilePathAndName"]=$result["filePath"].$result["fullFileName"];
226 liveuser 5254
 
3 liveuser 5255
		#設置執行正常的識別
5256
		$result["status"]="true";
226 liveuser 5257
 
3 liveuser 5258
		#回傳結果
5259
		return $result;
226 liveuser 5260
 
3 liveuser 5261
		}#funciton getFileAddressAndNameAndFileExtention end
5262
 
5263
	/*
5264
	#函式說明:
5265
	#將資料夾或檔案打包成tar檔案
5266
	#回傳結果:
5267
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5268
	#$result["function"],當前執行的函數名稱
5269
	#$result["error"],錯誤訊息.
5270
	#$result["content"],檔案輸出後的位置與名稱.
5271
	#必填參數:
5272
	#$conf["packetTarget"],陣列,要打包的每個資料夾與檔案位置
5273
	$conf["packetTarget"]=array("");
5274
	#$conf["createdTarFile"],字串,打包好的檔案要放在哪裡,副檔名.tar會自動加上.
5275
	$conf["createdTarFile"]="";
5276
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5277
	$conf["fileArgu"]=__FILE__;
5278
	#可省略參數:
5279
	#無.
5280
	#參考資料:
5281
	#無.
5282
	#備註:
5283
	#無.
5284
	*/
5285
	public static function makeTarFile(&$conf){
226 liveuser 5286
 
3 liveuser 5287
		#初始化要回傳的內容
5288
		$result=array();
226 liveuser 5289
 
3 liveuser 5290
		#記錄當前執行的函數名稱
5291
		$result["function"]=__FUNCTION__;
226 liveuser 5292
 
3 liveuser 5293
		#如果 $conf 不為陣列
5294
		if(gettype($conf)!="array"){
226 liveuser 5295
 
3 liveuser 5296
			#設置執行失敗
5297
			$result["status"]="false";
226 liveuser 5298
 
3 liveuser 5299
			#設置執行錯誤訊息
5300
			$result["error"][]="\$conf變數須為陣列形態";
5301
 
5302
			#如果傳入的參數為 null
5303
			if($conf==null){
226 liveuser 5304
 
3 liveuser 5305
				#設置執行錯誤訊息
5306
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5307
 
3 liveuser 5308
				}#if end
5309
 
5310
			#回傳結果
5311
			return $result;
226 liveuser 5312
 
3 liveuser 5313
			}#if end
226 liveuser 5314
 
3 liveuser 5315
		#檢查參數
5316
		#函式說明:
5317
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5318
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5319
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5320
		#$result["function"],當前執行的函式名稱.
5321
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5322
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5323
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5324
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5325
		#必填寫的參數:
5326
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5327
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5328
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5329
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","packetTarget","createdTarFile");
226 liveuser 5330
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5331
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
5332
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5333
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5334
		#可以省略的參數:
5335
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5336
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5337
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5338
		#$conf["skipableVariableName"]=array();
226 liveuser 5339
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5340
		#$conf["skipableVariableType"]=array();
5341
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5342
		#$conf["skipableVarDefaultValue"]=array("");
5343
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5344
		#$conf["arrayCountEqualCheck"][]=array();
5345
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5346
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5347
 
3 liveuser 5348
		#若檢查失敗
5349
		if($checkResult["status"]=="false"){
226 liveuser 5350
 
3 liveuser 5351
			#設置執行失敗
5352
			$result["status"]="false";
226 liveuser 5353
 
3 liveuser 5354
			#設置執行錯誤訊息
5355
			$result["error"]=$checkResult;
226 liveuser 5356
 
3 liveuser 5357
			#回傳結果
5358
			return $result;
226 liveuser 5359
 
3 liveuser 5360
			}#if end
226 liveuser 5361
 
3 liveuser 5362
		#若檢查不通過
5363
		if($checkResult["passed"]=="false"){
226 liveuser 5364
 
3 liveuser 5365
			#設置執行失敗
5366
			$result["status"]="false";
226 liveuser 5367
 
3 liveuser 5368
			#設置執行錯誤訊息
5369
			$result["error"]=$checkResult;
226 liveuser 5370
 
3 liveuser 5371
			#回傳結果
5372
			return $result;
226 liveuser 5373
 
3 liveuser 5374
			}#if end
226 liveuser 5375
 
3 liveuser 5376
		#初始化打包要用的tar指令參數
5377
		$paramsArray=array("-cvf",$conf["createdTarFile"].".tar");
226 liveuser 5378
 
3 liveuser 5379
		#檢查要打包的檔案是否存在
5380
		#函式說明:
5381
		#檢查多個檔案與資料夾是否存在.
5382
		#回傳的結果:
5383
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5384
		#$result["error"],錯誤訊息陣列.
5385
		#$resutl["function"],當前執行的涵式名稱.
5386
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
5387
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
5388
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
5389
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
5390
		#必填參數:
5391
		#$conf["fileArray"],陣列字串,要檢查書否存在的檔案有哪些,須爲一維陣列數值。
5392
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$conf["packetTarget"];
5393
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5394
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
5395
		#可省略參數
5396
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
5397
		#$conf["disableWebSearch"]="false";
5398
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5399
		#$conf["userDir"]="true";
5400
		#參考資料來源:
5401
		#http://php.net/manual/en/function.file-exists.php
5402
		#http://php.net/manual/en/control-structures.foreach.php
5403
		#備註:
5404
		#函數file_exists檢查的路徑為檔案系統的路徑
5405
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
5406
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 5407
 
3 liveuser 5408
		#如果檢查要打包的檔案失敗
5409
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 5410
 
3 liveuser 5411
			#設置執行失敗
5412
			$result["status"]="false";
226 liveuser 5413
 
3 liveuser 5414
			#設置執行錯誤訊息
5415
			$result["error"]=$checkMultiFileExist;
226 liveuser 5416
 
3 liveuser 5417
			#回傳結果
5418
			return $result;
226 liveuser 5419
 
3 liveuser 5420
			}#if end
226 liveuser 5421
 
3 liveuser 5422
		#如果要打包的檔案有缺
5423
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 5424
 
3 liveuser 5425
			#設置執行失敗
5426
			$result["status"]="false";
226 liveuser 5427
 
3 liveuser 5428
			#設置執行錯誤訊息
5429
			$result["error"]=$checkMultiFileExist;
226 liveuser 5430
 
3 liveuser 5431
			#回傳結果
5432
			return $result;
226 liveuser 5433
 
3 liveuser 5434
			}#if end
226 liveuser 5435
 
3 liveuser 5436
		#有幾個要打包的目標就執行幾次
5437
		for($i=0;$i<count($conf["packetTarget"]);$i++){
226 liveuser 5438
 
3 liveuser 5439
			#串接上要打包的檔案或資料夾
5440
			$paramsArray[]=$conf["packetTarget"][$i];
226 liveuser 5441
 
3 liveuser 5442
			}#for end
226 liveuser 5443
 
3 liveuser 5444
		#函式說明:
5445
		#呼叫shell執行系統命令,並取得回傳的內容.
5446
		#回傳結果:
5447
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5448
		#$result["error"],錯誤訊息陣列.
5449
		#$result["function"],當前執行的函數名稱.
5450
		#$result["argu"],使用的參數.
5451
		#$result["cmd"],執行的指令內容.
5452
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
5453
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
5454
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
5455
		#$result["running"],是否還在執行.
5456
		#$result["pid"],pid.
5457
		#$result["statusCode"],執行結束後的代碼.
5458
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
5459
		#必填參數:
5460
		#$conf["command"],字串,要執行的指令.
5461
		$conf["external::callShell"]["command"]="tar";
5462
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5463
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5464
		#可省略參數:
5465
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5466
		$conf["external::callShell"]["argu"]=$paramsArray;
5467
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
5468
		#$conf["arguIsAddr"]=array();
5469
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
5470
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
5471
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
5472
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5473
		#$conf["enablePrintDescription"]="true";
5474
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
5475
		#$conf["printDescription"]="";
5476
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
5477
		$conf["external::callShell"]["escapeshellarg"]="true";
5478
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
5479
		#$conf["thereIsShellVar"]=array();
5480
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
5481
		#$conf["username"]="";
5482
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
5483
		#$conf["password"]="";
5484
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
5485
		#$conf["useScript"]="";
5486
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
5487
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
5488
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
5489
		#$conf["inBackGround"]="";
5490
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
5491
		#$conf["getErr"]="false";
5492
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
5493
		#$conf["doNotRun"]="false";
5494
		#參考資料:
5495
		#exec=>http://php.net/manual/en/function.exec.php
5496
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
5497
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
5498
		#備註:
5499
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
5500
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
5501
		$conf["external::callShell"]=external::callShell($conf["external::callShell"]);
5502
		unset($conf["external::callShell"]);
226 liveuser 5503
 
3 liveuser 5504
		#如果執行shell失敗
5505
		if($callShell["status"]=="false"){
226 liveuser 5506
 
3 liveuser 5507
			#設置執行失敗
5508
			$result["status"]="false";
226 liveuser 5509
 
3 liveuser 5510
			#設置執行錯誤訊息
5511
			$result["error"]=$callShell;
226 liveuser 5512
 
3 liveuser 5513
			#回傳結果
5514
			return $result;
226 liveuser 5515
 
3 liveuser 5516
			}#if end
226 liveuser 5517
 
3 liveuser 5518
		#打包好的檔案位置與名稱
5519
		$result["content"]=$conf["createdTarFile"].".tar";
226 liveuser 5520
 
3 liveuser 5521
		#執行到這邊代表執行正常
5522
		$result["status"]="true";
226 liveuser 5523
 
3 liveuser 5524
		#回傳結果
5525
		return $result;
226 liveuser 5526
 
3 liveuser 5527
		}#function makeTarFile end
226 liveuser 5528
 
3 liveuser 5529
	/*
5530
	#函式說明:
5531
	#將一個檔案壓縮成xz檔案
5532
	#回傳結果:
5533
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5534
	#$result["function"],當前執行的函數名稱
5535
	#$result["error"],錯誤訊息.
5536
	#$result["content"],檔案輸出後的位置與名稱.
5537
	#必填參數:
5538
	#$conf["compressTarget"],字串,要打包的每個資料夾與檔案位置
5539
	$conf["compressTarget"]="";
5540
	#$conf["createdXzFile"],字串,打包好的檔案要放在哪裡,副檔名.xz會自動加上.
5541
	$conf["createdXzFile"]="";
5542
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5543
	$conf["fileArgu"]=__FILE__;
5544
	#可省略參數:
5545
	#無.
5546
	#參考資料:
5547
	#無.
5548
	#備註:
5549
	#無.
5550
	*/
5551
	public static function makeXzFile(&$conf){
5552
 
5553
		#初始化要回傳的內容
5554
		$result=array();
226 liveuser 5555
 
3 liveuser 5556
		#記錄當前執行的函數名稱
5557
		$result["function"]=__FUNCTION__;
226 liveuser 5558
 
3 liveuser 5559
		#如果 $conf 不為陣列
5560
		if(gettype($conf)!="array"){
226 liveuser 5561
 
3 liveuser 5562
			#設置執行失敗
5563
			$result["status"]="false";
226 liveuser 5564
 
3 liveuser 5565
			#設置執行錯誤訊息
5566
			$result["error"][]="\$conf變數須為陣列形態";
5567
 
5568
			#如果傳入的參數為 null
5569
			if($conf==null){
226 liveuser 5570
 
3 liveuser 5571
				#設置執行錯誤訊息
5572
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5573
 
3 liveuser 5574
				}#if end
5575
 
5576
			#回傳結果
5577
			return $result;
226 liveuser 5578
 
3 liveuser 5579
			}#if end
226 liveuser 5580
 
3 liveuser 5581
		#檢查參數
5582
		#函式說明:
5583
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5584
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5585
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5586
		#$result["function"],當前執行的函式名稱.
5587
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5588
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5589
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5590
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5591
		#必填寫的參數:
5592
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5593
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5594
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5595
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","compressTarget","createdXzFile");
226 liveuser 5596
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5597
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
5598
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5599
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5600
		#可以省略的參數:
5601
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5602
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5603
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5604
		#$conf["skipableVariableName"]=array();
226 liveuser 5605
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5606
		#$conf["skipableVariableType"]=array();
5607
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5608
		#$conf["skipableVarDefaultValue"]=array("");
5609
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5610
		#$conf["arrayCountEqualCheck"][]=array();
5611
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5612
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5613
 
3 liveuser 5614
		#若檢查失敗
5615
		if($checkResult["status"]=="false"){
226 liveuser 5616
 
3 liveuser 5617
			#設置執行失敗
5618
			$result["status"]="false";
226 liveuser 5619
 
3 liveuser 5620
			#設置執行錯誤訊息
5621
			$result["error"]=$checkResult;
226 liveuser 5622
 
3 liveuser 5623
			#回傳結果
5624
			return $result;
226 liveuser 5625
 
3 liveuser 5626
			}#if end
226 liveuser 5627
 
3 liveuser 5628
		#若檢查不通過
5629
		if($checkResult["passed"]=="false"){
226 liveuser 5630
 
3 liveuser 5631
			#設置執行失敗
5632
			$result["status"]="false";
226 liveuser 5633
 
3 liveuser 5634
			#設置執行錯誤訊息
5635
			$result["error"]=$checkResult;
226 liveuser 5636
 
3 liveuser 5637
			#回傳結果
5638
			return $result;
226 liveuser 5639
 
3 liveuser 5640
			}#if end
226 liveuser 5641
 
3 liveuser 5642
		#檢查要用xz壓縮的檔案是否存在
5643
		#函式說明:
5644
		#檢查多個檔案與資料夾是否存在.
5645
		#回傳的結果:
5646
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5647
		#$result["error"],錯誤訊息陣列.
5648
		#$resutl["function"],當前執行的涵式名稱.
5649
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
5650
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
5651
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
5652
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
5653
		#必填參數:
5654
		#$conf["fileArray"],陣列字串,要檢查書否存在的檔案有哪些,須爲一維陣列數值。
5655
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["compressTarget"]);
5656
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5657
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
5658
		#可省略參數
5659
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
5660
		#$conf["disableWebSearch"]="false";
5661
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5662
		#$conf["userDir"]="true";
5663
		#參考資料來源:
5664
		#http://php.net/manual/en/function.file-exists.php
5665
		#http://php.net/manual/en/control-structures.foreach.php
5666
		#備註:
5667
		#函數file_exists檢查的路徑為檔案系統的路徑
5668
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
5669
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 5670
 
3 liveuser 5671
		#如果檢查要用xz壓縮的檔案失敗
5672
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 5673
 
3 liveuser 5674
			#設置執行失敗
5675
			$result["status"]="false";
226 liveuser 5676
 
3 liveuser 5677
			#設置執行錯誤訊息
5678
			$result["error"]=$checkMultiFileExist;
226 liveuser 5679
 
3 liveuser 5680
			#回傳結果
5681
			return $result;
226 liveuser 5682
 
3 liveuser 5683
			}#if end
226 liveuser 5684
 
3 liveuser 5685
		#如果要用xz壓縮的檔案有缺
5686
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 5687
 
3 liveuser 5688
			#設置執行失敗
5689
			$result["status"]="false";
226 liveuser 5690
 
3 liveuser 5691
			#設置執行錯誤訊息
5692
			$result["error"]=$checkMultiFileExist;
226 liveuser 5693
 
3 liveuser 5694
			#回傳結果
5695
			return $result;
226 liveuser 5696
 
3 liveuser 5697
			}#if end
226 liveuser 5698
 
3 liveuser 5699
		#壓縮要用的xz語法
5700
		#函式說明:
5701
		#呼叫shell執行系統命令,並取得回傳的內容.
5702
		#回傳的結果:
5703
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5704
		#$result["error"],錯誤訊息陣列
5705
		#$result["output"],爲執行完二元碼後的輸出陣列
5706
		#必填的參數
5707
		$conf["external::callShell"]["command"]="xz";#要執行的指令與參數
5708
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5709
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5710
		#可省略參數:
5711
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5712
		$conf["external::callShell"]["argu"]=array("-v","-v","-z","-c",$conf["compressTarget"],">",$conf["createdXzFile"].".xz ");
5713
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5714
		#$conf["enablePrintDescription"]="true";
5715
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
5716
		#$conf["printDescription"]="";
5717
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
5718
		$conf["external::callShell"]["escapeshellarg"]="true";
5719
		#參考資料:
5720
		#http://php.net/manual/en/function.exec.php
5721
		$callShell=external::callShell($conf["external::callShell"]);
5722
		unset($conf["external::callShell"]);
226 liveuser 5723
 
3 liveuser 5724
		#如果執行shell失敗
5725
		if($callShell["status"]=="false"){
226 liveuser 5726
 
3 liveuser 5727
			#設置執行失敗
5728
			$result["status"]="false";
226 liveuser 5729
 
3 liveuser 5730
			#設置執行錯誤訊息
5731
			$result["error"]=$callShell;
226 liveuser 5732
 
3 liveuser 5733
			#回傳結果
5734
			return $result;
226 liveuser 5735
 
3 liveuser 5736
			}#if end
226 liveuser 5737
 
3 liveuser 5738
		#壓縮好的檔案位置與名稱
5739
		$result["content"]=$conf["createdXzFile"].".xz";
226 liveuser 5740
 
3 liveuser 5741
		#執行到這邊代表執行正常
5742
		$result["status"]="status";
226 liveuser 5743
 
3 liveuser 5744
		#回傳結果
5745
		return $result;
5746
 
5747
		}#function makeXzFile end
226 liveuser 5748
 
3 liveuser 5749
	/*
5750
	#函式說明:
5751
	#將資料夾或檔案打包壓縮成tar.xz檔案
5752
	#回傳結果:
5753
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5754
	#$result["function"],當前執行的函數名稱
5755
	#$result["error"],錯誤訊息.
5756
	#$result["content"],檔案輸出後的位置與名稱.
5757
	#必填參數:
5758
	#$conf["compressTarget"],陣列,要打包壓縮的每個資料夾與檔案位置
5759
	$conf["compressTarget"]=array();
5760
	#$conf["createdTarXzFile"],字串,打包壓縮好的檔案要放在哪裡,副檔名.tar.xz會自動加上.
5761
	$conf["createdTarXzFile"]="";
5762
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5763
	$conf["fileArgu"]=__FILE__;
5764
	#可省略參數:
5765
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
5766
	#$conf["commentsArray"]=array("");
5767
	#$conf["includeDotStart"],字串,當參數$conf["commentsArray"]含有星號時是否要包含「.」開頭的檔案目錄,預設為"false",不包含,"true"為要包含.
5768
	#$conf["includeDotStart"]="false";
5769
	#$conf["includeWaveEnd"],字串,當參數$conf["commentsArray"]含有星號時是否要包含「~」結尾的檔案.預設為"false",不包含,"true"為要包含.
5770
	#$conf["includeWaveEnd"]="false";
5771
	#參考資料:
5772
	#無.
5773
	#備註:
226 liveuser 5774
	#建議加上 --exclude-backups, --exclude-caches-all
3 liveuser 5775
	*/
5776
	public static function makeTarXzFile(&$conf){
226 liveuser 5777
 
3 liveuser 5778
		#初始化要回傳的內容
5779
		$result=array();
226 liveuser 5780
 
3 liveuser 5781
		#記錄當前執行的函數名稱
5782
		$result["function"]=__FUNCTION__;
226 liveuser 5783
 
3 liveuser 5784
		#如果 $conf 不為陣列
5785
		if(gettype($conf)!="array"){
226 liveuser 5786
 
3 liveuser 5787
			#設置執行失敗
5788
			$result["status"]="false";
226 liveuser 5789
 
3 liveuser 5790
			#設置執行錯誤訊息
5791
			$result["error"][]="\$conf變數須為陣列形態";
5792
 
5793
			#如果傳入的參數為 null
5794
			if($conf==null){
226 liveuser 5795
 
3 liveuser 5796
				#設置執行錯誤訊息
5797
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5798
 
3 liveuser 5799
				}#if end
5800
 
5801
			#回傳結果
5802
			return $result;
226 liveuser 5803
 
3 liveuser 5804
			}#if end
226 liveuser 5805
 
3 liveuser 5806
		#檢查參數
5807
		#函式說明:
5808
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5809
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5810
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5811
		#$result["function"],當前執行的函式名稱.
5812
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5813
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5814
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5815
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5816
		#必填寫的參數:
5817
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5818
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5819
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5820
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","compressTarget","createdTarXzFile");
226 liveuser 5821
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5822
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
5823
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5824
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5825
		#可以省略的參數:
5826
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5827
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5828
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5829
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","includeDotStart","includeWaveEnd");
226 liveuser 5830
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5831
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");
5832
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5833
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false","false");
5834
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5835
		#$conf["arrayCountEqualCheck"][]=array();
5836
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5837
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5838
 
3 liveuser 5839
		#若檢查失敗
5840
		if($checkResult["status"]=="false"){
226 liveuser 5841
 
3 liveuser 5842
			#設置執行失敗
5843
			$result["status"]="false";
226 liveuser 5844
 
3 liveuser 5845
			#設置執行錯誤訊息
5846
			$result["error"]=$checkResult;
226 liveuser 5847
 
3 liveuser 5848
			#回傳結果
5849
			return $result;
226 liveuser 5850
 
3 liveuser 5851
			}#if end
226 liveuser 5852
 
3 liveuser 5853
		#若檢查不通過
5854
		if($checkResult["passed"]=="false"){
226 liveuser 5855
 
3 liveuser 5856
			#設置執行失敗
5857
			$result["status"]="false";
226 liveuser 5858
 
3 liveuser 5859
			#設置執行錯誤訊息
5860
			$result["error"]=$checkResult;
226 liveuser 5861
 
3 liveuser 5862
			#回傳結果
5863
			return $result;
226 liveuser 5864
 
3 liveuser 5865
			}#if end
226 liveuser 5866
 
3 liveuser 5867
		#如果 $conf["commentsArray"] 有設定
5868
		if(isset($conf["commentsArray"])){
226 liveuser 5869
 
3 liveuser 5870
			#印出提示文字
5871
			#函式說明:
5872
			#印出多行文字,結尾自動換行.
5873
			#回傳的結果:
5874
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
5875
			#$result["function"],當前執行的函數名稱.
5876
			#$result["error"],錯誤訊息陣列.
5877
			#必填參數:
5878
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
5879
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
5880
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
5881
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 5882
 
3 liveuser 5883
			#如果印出提示文字失敗
5884
			if($echoMultiLine["status"]=="false"){
226 liveuser 5885
 
3 liveuser 5886
				#設置執行失敗
5887
				$result["status"]="false";
226 liveuser 5888
 
3 liveuser 5889
				#設置執行錯誤訊息
5890
				$result["error"]=$echoMultiLine;
226 liveuser 5891
 
3 liveuser 5892
				#回傳結果
5893
				return $result;
226 liveuser 5894
 
3 liveuser 5895
				}#if end
226 liveuser 5896
 
5897
			}#if end
5898
 
3 liveuser 5899
		#解析要處理的檔案路徑
5900
		#函式說明:
5901
		#將含有「*」的多個檔案路徑名稱,變成多個符合條件的路徑檔案.
5902
		#回傳結果:
5903
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
5904
		#$result["error"],錯誤訊息陣列.
226 liveuser 5905
		#$result["function"],函數名稱.
3 liveuser 5906
		#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
5907
		#$result["pathCount"],整數,有幾個路徑.
5908
		#必填參數:
5909
		#$conf["path"],字串陣列,要解析含有「*」的檔案路徑字串.
5910
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["path"]=$conf["compressTarget"];
5911
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
5912
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["fileArgu"]=$conf["fileArgu"];
5913
		#可省略參數:
5914
		#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
5915
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["noDotStart"]=$conf["includeDotStart"]==="true"?"false":"true";
5916
		#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
5917
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["noWaveEnd"]=$conf["includeWaveEnd"]==="true"?"false":"true";
5918
		$realPathArray=fileAccess::resolveMultiPostionStringWhichContainStarSymbol($conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]);
5919
		unset($conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]);
226 liveuser 5920
 
3 liveuser 5921
		#如果解析路徑失敗
5922
		if($realPathArray["status"]=="false"){
226 liveuser 5923
 
3 liveuser 5924
			#設置執行失敗
5925
			$result["status"]="false";
226 liveuser 5926
 
3 liveuser 5927
			#設置執行錯誤訊息
5928
			$result["error"]=$realPathArray;
226 liveuser 5929
 
3 liveuser 5930
			#回傳結果
5931
			return $result;
226 liveuser 5932
 
3 liveuser 5933
			}#if end
226 liveuser 5934
 
3 liveuser 5935
		#取得解析好的檔案路徑陣列
226 liveuser 5936
		$conf["compressTarget"]=$realPathArray["content"];
5937
 
3 liveuser 5938
		#將路徑轉換成相對路徑
5939
		#函式說明:
5940
		#將多個路徑字串變成相對於當前路徑的相對路徑字串
5941
		#回傳結果:
5942
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
5943
		#$result["error"],錯誤訊息陣列.
226 liveuser 5944
		#$result["function"],函數名稱.
3 liveuser 5945
		#$result["content"],字串陣列,多個轉換好的相對路徑字串.
5946
		#必填參數:
5947
		#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
5948
		$conf["fileAccess::getRelativePath"]["path"]=$conf["compressTarget"];
5949
		#$conf["fileArgu"],字串,當前路徑.
5950
		$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
5951
		$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
5952
		unset($conf["fileAccess::getRelativePath"]);
226 liveuser 5953
 
3 liveuser 5954
		#如果轉換失敗
5955
		if($getRelativePath["status"]=="false"){
226 liveuser 5956
 
3 liveuser 5957
			#設置執行失敗
5958
			$result["status"]="false";
226 liveuser 5959
 
3 liveuser 5960
			#設置執行錯誤訊息
5961
			$result["error"]=$getRelativePat;
226 liveuser 5962
 
3 liveuser 5963
			#回傳結果
5964
			return $result;
226 liveuser 5965
 
5966
			}#if end
5967
 
3 liveuser 5968
		#打包成tar檔
5969
		#函式說明:
5970
		#將資料夾或檔案打包成tar檔案
5971
		#回傳的結果:
5972
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5973
		#$result["function"],當前執行的函數名稱
5974
		#$result["error"],錯誤訊息.
5975
		#$result["content"],檔案輸出後的位置與名稱.
5976
		#必填參數:
5977
		#$conf["fileAccess::makeTarFile"]["packetTarget"],陣列,要打包的每個資料夾與檔案位置
5978
		$conf["fileAccess::makeTarFile"]["packetTarget"]=$getRelativePath["content"];
5979
		#$conf["fileAccess::makeTarFile"]["createdTarFile"],字串,打包好的檔案要放在哪裡,副檔名.tar會自動加上.
5980
		$conf["fileAccess::makeTarFile"]["createdTarFile"]=$conf["createdTarXzFile"];
5981
		#$conf["fileAccess::makeTarFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5982
		$conf["fileAccess::makeTarFile"]["fileArgu"]=$conf["fileArgu"];
5983
		$makeTarFile=fileAccess::makeTarFile($conf["fileAccess::makeTarFile"]);
5984
		unset($conf["fileAccess::makeTarFile"]);
226 liveuser 5985
 
3 liveuser 5986
		#如果打包失敗
5987
		if($makeTarFile["status"]=="false"){
226 liveuser 5988
 
3 liveuser 5989
			#設置執行不正常
5990
			$result["status"]="false";
226 liveuser 5991
 
3 liveuser 5992
			#設置錯誤訊息
5993
			$result["error"]=$makeTarFile;
226 liveuser 5994
 
3 liveuser 5995
			#回傳結果
5996
			return $result;
226 liveuser 5997
 
3 liveuser 5998
			}#if end
226 liveuser 5999
 
3 liveuser 6000
		#壓縮成xz檔
6001
		#函式說明:
6002
		#將一個檔案壓縮成xz檔案
6003
		#回傳的結果:
6004
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6005
		#$result["function"],當前執行的函數名稱
6006
		#$result["error"],錯誤訊息.
6007
		#$result["content"],檔案輸出後的位置與名稱.
6008
		#必填參數:
6009
		#$conf["fileAccess::makeXzFile"]["compressTarget"],字串,要打包的每個資料夾與檔案位置
6010
		$conf["fileAccess::makeXzFile"]["compressTarget"]=$makeTarFile["content"];
6011
		#$conf["fileAccess::makeXzFile"]["createdXzFile"],字串,打包好的檔案要放在哪裡,副檔名.xz會自動加上.
6012
		$conf["fileAccess::makeXzFile"]["createdXzFile"]=$makeTarFile["content"];
6013
		#$conf["fileAccess::makeXzFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6014
		$conf["fileAccess::makeXzFile"]["fileArgu"]=$conf["fileArgu"];
6015
		$makeXzFile=fileAccess::makeXzFile($conf["fileAccess::makeXzFile"]);
6016
		unset($conf["fileAccess::makeXzFile"]);
226 liveuser 6017
 
3 liveuser 6018
		#如果壓縮失敗
6019
		if($makeXzFile["status"]=="false"){
226 liveuser 6020
 
3 liveuser 6021
			#設置執行不正常
6022
			$result["status"]="false";
226 liveuser 6023
 
3 liveuser 6024
			#設置錯誤訊息
6025
			$result["error"]=$makeXzFile;
226 liveuser 6026
 
3 liveuser 6027
			#回傳結果
6028
			return $result;
226 liveuser 6029
 
3 liveuser 6030
			}#if end
226 liveuser 6031
 
3 liveuser 6032
		#移除tar檔案
6033
		#函式說明:
6034
		#移除檔案
6035
		#回傳結果:
6036
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
6037
		#$result["error"],錯誤訊息陣列
6038
		#$result["warning"],警告訊息陣列
6039
		#$result["function"],當前執行的函數名稱
6040
		#必填參數:
6041
		$conf["fileAccess::delFile"]["fileAddress"]=$makeTarFile["content"];#要移除檔案的位置
6042
		#$conf["fileAccess::delFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
6043
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
6044
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
6045
		unset($conf["fileAccess::delFile"]);
226 liveuser 6046
 
3 liveuser 6047
		#如果移除tar檔案失敗
6048
		if($delFile["status"]=="false"){
226 liveuser 6049
 
3 liveuser 6050
			#設置執行不正常
6051
			$result["status"]="false";
226 liveuser 6052
 
3 liveuser 6053
			#設置錯誤訊息
6054
			$result["error"]=$delFile;
226 liveuser 6055
 
3 liveuser 6056
			#回傳結果
6057
			return $result;
226 liveuser 6058
 
3 liveuser 6059
			}#if end
226 liveuser 6060
 
3 liveuser 6061
		#取得壓縮好的檔案位置與名稱
6062
		$result["content"]=$makeXzFile["content"];
226 liveuser 6063
 
3 liveuser 6064
		#執行到這邊代表執行正常
6065
		$result["status"]="true";
226 liveuser 6066
 
3 liveuser 6067
		#回傳結果
6068
		return $result;
226 liveuser 6069
 
3 liveuser 6070
		}#function makeTarXzFile end
226 liveuser 6071
 
3 liveuser 6072
	/*
6073
	#函式說明:
6074
	#移動檔案
6075
	#回傳結果:
6076
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6077
	#$result["function"],當前執行的函數名稱
6078
	#$result["error"],錯誤訊息.
6079
	#$result["content"],檔案輸出後的位置與名稱.
6080
	#必填參數:
6081
	#$conf["from"],字串,要移動的檔案名稱與位置.
6082
	$conf["from"]="";
6083
	#$conf["to"],字串,要移動到的位置與名稱
6084
	$conf["to"]="";
6085
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6086
	$conf["fileArgu"]=__FILE__;
6087
	#可省略參數:
6088
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
6089
	#$conf["commentsArray"]=array("");
6090
	#參考資料:
6091
	#無.
6092
	#備註:
6093
	#無.
6094
	*/
6095
	public static function mv(&$conf){
226 liveuser 6096
 
3 liveuser 6097
		#初始化要回傳的結果
6098
		$result=array();
226 liveuser 6099
 
3 liveuser 6100
		#取得當前執行的函數名稱
6101
		$result["function"]=__FUNCTION__;
226 liveuser 6102
 
3 liveuser 6103
		#如果 $conf 不為陣列
6104
		if(gettype($conf)!="array"){
226 liveuser 6105
 
3 liveuser 6106
			#設置執行失敗
6107
			$result["status"]="false";
226 liveuser 6108
 
3 liveuser 6109
			#設置執行錯誤訊息
6110
			$result["error"][]="\$conf變數須為陣列形態";
6111
 
6112
			#如果傳入的參數為 null
6113
			if($conf==null){
226 liveuser 6114
 
3 liveuser 6115
				#設置執行錯誤訊息
6116
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6117
 
3 liveuser 6118
				}#if end
6119
 
6120
			#回傳結果
6121
			return $result;
226 liveuser 6122
 
3 liveuser 6123
			}#if end
226 liveuser 6124
 
3 liveuser 6125
		#檢查參數
6126
		#函式說明:
6127
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6128
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6129
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6130
		#$result["function"],當前執行的函式名稱.
6131
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6132
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6133
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6134
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6135
		#必填寫的參數:
6136
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6137
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6138
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6139
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("from","to","fileArgu");
226 liveuser 6140
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 6141
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
6142
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6143
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6144
		#可以省略的參數:
6145
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
6146
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6147
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6148
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray");
226 liveuser 6149
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 6150
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
6151
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6152
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
6153
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6154
		#$conf["arrayCountEqualCheck"][]=array();
6155
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6156
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 6157
 
3 liveuser 6158
		#若檢查失敗
6159
		if($checkResult["status"]=="false"){
226 liveuser 6160
 
3 liveuser 6161
			#設置執行失敗
6162
			$result["status"]="false";
226 liveuser 6163
 
3 liveuser 6164
			#設置執行錯誤訊息
6165
			$result["error"]=$checkResult;
226 liveuser 6166
 
3 liveuser 6167
			#回傳結果
6168
			return $result;
226 liveuser 6169
 
3 liveuser 6170
			}#if end
226 liveuser 6171
 
3 liveuser 6172
		#若檢查不通過
6173
		if($checkResult["passed"]=="false"){
226 liveuser 6174
 
3 liveuser 6175
			#設置執行失敗
6176
			$result["status"]="false";
226 liveuser 6177
 
3 liveuser 6178
			#設置執行錯誤訊息
6179
			$result["error"]=$checkResult;
226 liveuser 6180
 
3 liveuser 6181
			#回傳結果
6182
			return $result;
226 liveuser 6183
 
3 liveuser 6184
			}#if end
226 liveuser 6185
 
3 liveuser 6186
		#如果 $conf["commentsArray"] 有設定
6187
		if(isset($conf["commentsArray"])){
226 liveuser 6188
 
3 liveuser 6189
			#印出提示文字
6190
			#函式說明:
6191
			#印出多行文字,結尾自動換行.
6192
			#回傳的結果:
6193
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
6194
			#$result["function"],當前執行的函數名稱.
6195
			#$result["error"],錯誤訊息陣列.
6196
			#必填參數:
6197
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
6198
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
6199
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
6200
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 6201
 
3 liveuser 6202
			#如果印出提示文字失敗
6203
			if($echoMultiLine["status"]=="false"){
226 liveuser 6204
 
3 liveuser 6205
				#設置執行失敗
6206
				$result["status"]="false";
226 liveuser 6207
 
3 liveuser 6208
				#設置執行錯誤訊息
6209
				$result["error"]=$echoMultiLine;
226 liveuser 6210
 
3 liveuser 6211
				#回傳結果
6212
				return $result;
226 liveuser 6213
 
3 liveuser 6214
				}#if end
226 liveuser 6215
 
6216
			}#if end
6217
 
3 liveuser 6218
		#檢查要移動的檔案是否存在
6219
		#函式說明:
6220
		#檢查多個檔案與資料夾是否存在.
6221
		#回傳的結果:
6222
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
6223
		#$result["error"],錯誤訊息陣列.
6224
		#$resutl["function"],當前執行的涵式名稱.
6225
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
6226
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
6227
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
6228
		#必填參數:
6229
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["from"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
6230
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
6231
		#參考資料來源:
6232
		#http://php.net/manual/en/function.file-exists.php
6233
		#http://php.net/manual/en/control-structures.foreach.php
6234
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
6235
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 6236
 
3 liveuser 6237
		#如果檢查失敗
6238
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 6239
 
3 liveuser 6240
			#設置執行失敗
6241
			$result["status"]="false";
226 liveuser 6242
 
3 liveuser 6243
			#設置執行錯誤訊息
6244
			$result["error"]=$checkMultiFileExist;
226 liveuser 6245
 
3 liveuser 6246
			#回傳結果
6247
			return $result;
226 liveuser 6248
 
6249
			}#if end
6250
 
3 liveuser 6251
		#如果來源檔案不存在
6252
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 6253
 
3 liveuser 6254
			#設置執行失敗
6255
			$result["status"]="false";
226 liveuser 6256
 
3 liveuser 6257
			#設置執行錯誤訊息
6258
			$result["error"][]="檔案「".$conf["from"]."」不存在";
226 liveuser 6259
 
3 liveuser 6260
			#回傳結果
6261
			return $result;
226 liveuser 6262
 
3 liveuser 6263
			}#if end
226 liveuser 6264
 
3 liveuser 6265
		#函式說明:
6266
		#呼叫shell執行系統命令,並取得回傳的內容.
6267
		#回傳的結果:
6268
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6269
		#$result["error"],錯誤訊息陣列
6270
		#$result["output"],爲執行完二元碼後的輸出陣列
6271
		#必填的參數
6272
		$conf["external::callShell"]["command"]="mv";#要執行的指令與參數
6273
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"]; #__FILE__的內容
6274
		#可省略參數:
6275
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
6276
		$conf["external::callShell"]["argu"]=array("-v",$conf["from"],$conf["to"]);
6277
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
6278
		#$conf["external::callShell"]["enablePrintDescription"]="true";
6279
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
6280
		#$conf["printDescription"]="";
6281
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
6282
		$conf["external::callShell"]["escapeshellarg"]="true";
6283
		#參考資料:
6284
		#http://php.net/manual/en/function.exec.php
6285
		$callShell=external::callShell($conf["external::callShell"]);
6286
		unset($conf["external::callShell"]);
226 liveuser 6287
 
3 liveuser 6288
		#如果移動檔案失敗
6289
		if($callShell["status"]=="false"){
226 liveuser 6290
 
3 liveuser 6291
			#設置執行失敗
6292
			$result["status"]="false";
226 liveuser 6293
 
3 liveuser 6294
			#設置執行錯誤訊息
6295
			$result["error"]=$callShell;
226 liveuser 6296
 
3 liveuser 6297
			#回傳結果
6298
			return $result;
226 liveuser 6299
 
3 liveuser 6300
			}#if end
226 liveuser 6301
 
3 liveuser 6302
		#執行到這邊代表正常
6303
		$result["status"]="true";
226 liveuser 6304
 
3 liveuser 6305
		#儲存移動後的位置與名稱
6306
		$result["content"]=$conf["to"];
226 liveuser 6307
 
3 liveuser 6308
		#回傳結果
6309
		return $result;
226 liveuser 6310
 
3 liveuser 6311
		}#function mv end
226 liveuser 6312
 
3 liveuser 6313
	/*
6314
	#函式說明:
6315
	#取得目錄底下所有目錄與檔案的樹狀結構.
6316
	#回傳結果:
6317
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6318
	#$result["error"],錯誤訊息陣列.
6319
	#$result["function"],函數名稱.
6320
	#$result["position"],根目錄位置.
6321
	#$result["content"],陣列,檔案目錄的樹狀結構.
6322
	#$result["content"][$i]["name"],根目錄底下第$i+1個檔案或目錄的名稱
6323
	#$result["content"][$i]["folder"],根目錄底下第$i+1個名稱是目錄("true")還是檔案("false").
6324
	#$result["content"][$i]["position"],根目錄底下第$i+1個名稱或目錄的位置.
6325
	#$result["content"][$i]["ownerPerm"],根目錄底下第$i+1個使用者的權限.
6326
	#$result["content"][$i]["groupPerm"],根目錄底下第$i+1個群組使用者的權限.
6327
	#$result["content"][$i]["otherPerm"],根目錄底下第$i+1個其他使用者的權限.
6328
	#$result["content"][$i]["ownerName"],根目錄底下第$i+1個擁有者賬戶.
6329
	#$result["content"][$i]["groupName"],根目錄底下第$i+1個群組擁有者賬戶.
6330
	#$result["content"][$i]["next"][$j]["name"],第$i+1個為目錄的名稱的目錄底下第$j+1個檔案或目錄的名稱
6331
	#$result["content"][$i]["next"][$j]["folder"],第$i+1個為目錄的名稱的目錄底下第$j+1個名稱是目錄("true")還是檔案("false").
6332
	#$result["content"][$i]["next"][$j]["position"],第$i+1個為目錄的名稱的目錄底下第$j+1個名稱或目錄的位置.
6333
	#$result["content"][$i]["next"][$j]["ownerPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個使用者的權限.
6334
	#$result["content"][$i]["next"][$j]["groupPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個群組使用者的權限.
6335
	#$result["content"][$i]["next"][$j]["otherPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個其他使用者的權限.
6336
	#$result["content"][$i]["next"][$j]["ownerName"],第$i+1個為目錄的名稱的目錄底下第$j+1個擁有者賬戶.
6337
	#$result["content"][$i]["next"][$j]["groupName"],第$i+1個為目錄的名稱的目錄底下第$j+1個群組擁有者賬戶.
226 liveuser 6338
	#以此類推...
3 liveuser 6339
	#必填參數:
6340
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6341
	$conf["position"]="";
6342
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6343
	$conf["fileArgu"]=__FILE__;
6344
	#可省略參數:
6345
	#無.
6346
	#參考資料:
6347
	#無.
6348
	#備註:
6349
	#無.
6350
	*/
6351
	public static function getListTree(&$conf){
226 liveuser 6352
 
3 liveuser 6353
		#初始化要回傳的結果
6354
		$result=array();
226 liveuser 6355
 
3 liveuser 6356
		#設置當其函數名稱
6357
		$result["function"]=__FUNCTION__;
226 liveuser 6358
 
3 liveuser 6359
		#如果 $conf 不為陣列
6360
		if(gettype($conf)!="array"){
226 liveuser 6361
 
3 liveuser 6362
			#設置執行失敗
6363
			$result["status"]="false";
226 liveuser 6364
 
3 liveuser 6365
			#設置執行錯誤訊息
6366
			$result["error"][]="\$conf變數須為陣列形態";
6367
 
6368
			#如果傳入的參數為 null
6369
			if($conf==null){
226 liveuser 6370
 
3 liveuser 6371
				#設置執行錯誤訊息
6372
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6373
 
3 liveuser 6374
				}#if end
6375
 
6376
			#回傳結果
6377
			return $result;
226 liveuser 6378
 
3 liveuser 6379
			}#if end
226 liveuser 6380
 
3 liveuser 6381
		#檢查必填參數
6382
		#函式說明:
6383
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6384
		#回傳的結果:
6385
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6386
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6387
		#$result["function"],當前執行的函式名稱.
6388
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6389
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6390
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6391
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6392
		#必填寫的參數:
6393
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6394
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileArgu","position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6395
		#可以省略的參數:
226 liveuser 6396
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6397
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6398
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
6399
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 6400
 
3 liveuser 6401
		#如果檢查失敗
6402
		if($checkResult["status"]=="false"){
226 liveuser 6403
 
3 liveuser 6404
			#設置錯誤識別
6405
			$result["status"]="false";
226 liveuser 6406
 
3 liveuser 6407
			#設置錯誤訊息
6408
			$result["error"]=$checkResult;
226 liveuser 6409
 
3 liveuser 6410
			#回傳結果
6411
			return $result;
226 liveuser 6412
 
3 liveuser 6413
			}#if end
226 liveuser 6414
 
3 liveuser 6415
		#如果檢查不通過
6416
		if($checkResult["passed"]=="false"){
226 liveuser 6417
 
3 liveuser 6418
			#設置錯誤識別
6419
			$result["status"]="false";
226 liveuser 6420
 
3 liveuser 6421
			#設置錯誤訊息
6422
			$result["error"]=$checkResult;
226 liveuser 6423
 
3 liveuser 6424
			#回傳結果
6425
			return $result;
226 liveuser 6426
 
3 liveuser 6427
			}#if end
226 liveuser 6428
 
3 liveuser 6429
		#如果目錄不為 . 與 ..
6430
		if(basename($conf["position"])!="." && basename($conf["position"])!=".."){
226 liveuser 6431
 
3 liveuser 6432
			#檢查目錄是否存在
6433
			#函式說明:
6434
			#檢查多個檔案與資料夾是否存在.
6435
			#回傳的結果:
6436
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
6437
			#$result["error"],錯誤訊息陣列.
6438
			#$resutl["function"],當前執行的涵式名稱.
6439
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
6440
			#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
6441
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
6442
			#必填參數:
6443
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["position"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
6444
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6445
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
6446
			#參考資料來源:
6447
			#http://php.net/manual/en/function.file-exists.php
6448
			#http://php.net/manual/en/control-structures.foreach.php
6449
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
6450
			unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 6451
 
3 liveuser 6452
			#如果檢查目錄失敗
6453
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 6454
 
3 liveuser 6455
				#設置錯誤識別
6456
				$result["status"]="false";
226 liveuser 6457
 
3 liveuser 6458
				#設置錯誤訊息
6459
				$result["error"]=$checkMultiFileExist;
226 liveuser 6460
 
3 liveuser 6461
				#回傳結果
6462
				return $result;
226 liveuser 6463
 
6464
				}#if end
6465
 
3 liveuser 6466
			#如果目錄不存在
6467
			if($checkMultiFileExist["varExist"][0]=="false"){
226 liveuser 6468
 
3 liveuser 6469
				#設置錯誤識別
6470
				$result["status"]="false";
226 liveuser 6471
 
3 liveuser 6472
				#設置錯誤訊息
6473
				$result["error"]=$checkMultiFileExist;
226 liveuser 6474
 
3 liveuser 6475
				#回傳結果
6476
				return $result;
226 liveuser 6477
 
6478
				}#if end
6479
 
3 liveuser 6480
			}#if end
226 liveuser 6481
 
3 liveuser 6482
		#取得根目錄的樹狀結構
6483
		#函式說明:
6484
		#取得目錄底下所有目錄與檔案清單.
6485
		#回傳結果:
6486
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6487
		#$result["error"],錯誤訊息陣列.
6488
		#$result["function"],函數名稱.
6489
		#$result["content"],陣列,目錄底下的檔案與子目錄.
6490
		#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
6491
		#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
6492
		#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
6493
		#$result["position"],目前的位置.
6494
		#必填參數:
6495
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6496
		$conf["fileAccess::getList"]["position"]=$conf["position"];
6497
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6498
		$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
6499
		#可省略參數:
6500
		#無
6501
		#參考資料來源:
6502
		#opendir=>http://php.net/manual/en/function.opendir.php
6503
		#is_dir=>http://php.net/manual/en/function.is-dir.php
6504
		$rootList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 6505
		unset($conf["fileAccess::getList"]);
6506
 
3 liveuser 6507
		#如果取得根目錄底下的資料失敗
6508
		if($rootList["status"]=="false"){
226 liveuser 6509
 
3 liveuser 6510
			#設置錯誤識別
6511
			$result["status"]="false";
226 liveuser 6512
 
3 liveuser 6513
			#設置錯誤訊息
6514
			$result["error"]=$rootList;
226 liveuser 6515
 
3 liveuser 6516
			#回傳結果
6517
			return $result;
226 liveuser 6518
 
3 liveuser 6519
			}#if end
226 liveuser 6520
 
6521
		#取得當前目錄
6522
		$result["position"]=$rootList["position"];
6523
 
3 liveuser 6524
		#取得根目錄層級可以看到的檔案與目錄
6525
		$result["content"]=$rootList["content"];
226 liveuser 6526
 
3 liveuser 6527
		#如果當前目錄有檔案與子目錄
6528
		if(isset($result["content"])){
226 liveuser 6529
 
3 liveuser 6530
			#當前層級有幾個檔案目錄就執行幾次
6531
			for($i=0;$i<count($result["content"]);$i++){
226 liveuser 6532
 
3 liveuser 6533
				#如果該單位是目錄
6534
				if($result["content"][$i]["folder"]=="true"){
226 liveuser 6535
 
3 liveuser 6536
					#呼叫當前函數,取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊
6537
					#函式說明:
6538
					#取得目錄底下所有目錄與檔案的樹狀結構.
6539
					#回傳結果:
6540
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6541
					#$result["error"],錯誤訊息陣列.
6542
					#$result["function"],函數名稱.
6543
					#$result["content"],陣列,檔案目錄的樹狀結構.
6544
					#$result["total"],根目錄底下有多少目錄與檔案
6545
					#必填參數:
6546
					#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6547
					$conf["fileAccess::getListTree"]["position"]=$conf["position"]."/".$result["content"][$i]["name"];
6548
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6549
					$conf["fileAccess::getListTree"]["fileArgu"]=$conf["fileArgu"];
6550
					#可省略參數:
6551
					#無
6552
					$getListTree=fileAccess::getListTree($conf["fileAccess::getListTree"]);
6553
					unset($conf["fileAccess::getListTree"]);
226 liveuser 6554
 
3 liveuser 6555
					#如果取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊失敗
6556
					if($getListTree["status"]=="false"){
226 liveuser 6557
 
3 liveuser 6558
						#設置錯誤識別
6559
						$result["status"]="false";
226 liveuser 6560
 
3 liveuser 6561
						#設置錯誤訊息
6562
						$result["error"]=$getListTree;
226 liveuser 6563
 
3 liveuser 6564
						#回傳結果
6565
						return $result;
226 liveuser 6566
 
3 liveuser 6567
						}#if end
226 liveuser 6568
 
3 liveuser 6569
					#如果 $conf["position"]."/".$result["content"][$i]["name"] 目錄有檔案與子目錄
226 liveuser 6570
					if(isset($getListTree["content"])){
6571
 
3 liveuser 6572
						#取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊
6573
						$result["content"][$i]["next"]=$getListTree["content"];
226 liveuser 6574
 
3 liveuser 6575
						}#if end
226 liveuser 6576
 
6577
					#取得當前目錄
6578
					$result["content"][$i]["position"]=$rootList["position"];
6579
 
3 liveuser 6580
					}#if end
226 liveuser 6581
 
3 liveuser 6582
				}#for end
226 liveuser 6583
 
3 liveuser 6584
			}#if end
226 liveuser 6585
 
3 liveuser 6586
		#執行到這邊代表執行正常
6587
		$result["status"]="true";
226 liveuser 6588
 
3 liveuser 6589
		#回傳結果
6590
		return $result;
226 liveuser 6591
 
3 liveuser 6592
		}#function getListTree end
226 liveuser 6593
 
3 liveuser 6594
	/*
6595
	#函式說明:
6596
	#取得目錄底下所有目錄與檔案清單.
6597
	#回傳結果:
6598
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6599
	#$result["error"],錯誤訊息陣列.
6600
	#$result["function"],函數名稱.
6601
	#$result["content"],陣列,目錄底下的檔案與子目錄.
6602
	#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
6603
	#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
6604
	#$result["content"][$i]["ownerPerm"],字串,使用者的權限.
6605
	#$result["content"][$i]["groupPerm"],字串,群組使用者的權限.
6606
	#$result["content"][$i]["otherPerm"],字串,其他使用者的權限.
6607
	#$result["content"][$i]["ownerName"],字串,擁有者賬戶.
6608
	#$result["content"][$i]["groupName"],字串,群組擁有者賬戶.
6609
	#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
6610
	#$result["position"],目前的位置.
6611
	#必填參數:
6612
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6613
	$conf["position"]="";
6614
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6615
	$conf["fileArgu"]=__FILE__;
6616
	#可省略參數:
6617
	#無
6618
	#參考資料:
6619
	#opendir=>http://php.net/manual/en/function.opendir.php
6620
	#is_dir=>http://php.net/manual/en/function.is-dir.php
6621
	#備註:
6622
	#無.
6623
	*/
6624
	public static function getList(&$conf){
6625
 
6626
		#初始化要回傳的結果
6627
		$result=array();
226 liveuser 6628
 
3 liveuser 6629
		#設置當其函數名稱
6630
		$result["function"]=__FUNCTION__;
226 liveuser 6631
 
3 liveuser 6632
		#初始化記載檔案目錄名單的陣列
6633
		$result["content"]=array();
226 liveuser 6634
 
3 liveuser 6635
		#如果 $conf 不為陣列
6636
		if(gettype($conf)!="array"){
226 liveuser 6637
 
3 liveuser 6638
			#設置執行失敗
6639
			$result["status"]="false";
226 liveuser 6640
 
3 liveuser 6641
			#設置執行錯誤訊息
6642
			$result["error"][]="\$conf變數須為陣列形態";
6643
 
6644
			#如果傳入的參數為 null
6645
			if($conf==null){
226 liveuser 6646
 
3 liveuser 6647
				#設置執行錯誤訊息
6648
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6649
 
3 liveuser 6650
				}#if end
6651
 
6652
			#回傳結果
6653
			return $result;
226 liveuser 6654
 
3 liveuser 6655
			}#if end
226 liveuser 6656
 
3 liveuser 6657
		#檢查必填參數
6658
		#函式說明:
6659
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6660
		#回傳的結果:
6661
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6662
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6663
		#$result["function"],當前執行的函式名稱.
6664
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6665
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6666
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6667
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6668
		#必填寫的參數:
6669
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6670
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileArgu","position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6671
		#可以省略的參數:
226 liveuser 6672
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6673
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6674
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
6675
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 6676
 
3 liveuser 6677
		#如果檢查失敗
6678
		if($checkResult["status"]=="false"){
226 liveuser 6679
 
3 liveuser 6680
			#設置錯誤識別
6681
			$result["status"]="false";
226 liveuser 6682
 
3 liveuser 6683
			#設置錯誤訊息
6684
			$result["error"]=$checkResult;
226 liveuser 6685
 
3 liveuser 6686
			#回傳結果
6687
			return $result;
226 liveuser 6688
 
3 liveuser 6689
			}#if end
226 liveuser 6690
 
3 liveuser 6691
		#如果檢查不通過
6692
		if($checkResult["passed"]==="false"){
226 liveuser 6693
 
3 liveuser 6694
			#設置錯誤識別
6695
			$result["status"]="false";
226 liveuser 6696
 
3 liveuser 6697
			#設置錯誤訊息
6698
			$result["error"]=$checkResult;
226 liveuser 6699
 
3 liveuser 6700
			#回傳結果
6701
			return $result;
226 liveuser 6702
 
3 liveuser 6703
			}#if end
226 liveuser 6704
 
3 liveuser 6705
		#檢查目標路徑是否為「/」開頭的路徑
6706
		#函式說明:
6707
		#取得符合特定字首與字尾的字串
6708
		#回傳結果:
6709
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
6710
		#$result["function"],當前執行的函數名稱.
6711
		#$result["error"],錯誤訊息陣列.
6712
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
6713
		#$result["returnString"],爲符合字首條件的字串內容。
6714
		#必填參數:
6715
		#$conf["checkString"],字串,要檢查的字串.
6716
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["position"];
6717
		#可省略參數:
6718
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
6719
		$conf["search::getMeetConditionsString"]["frontWord"]="/";
6720
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
6721
		#$conf["tailWord"]="";
6722
		#參考資料:
6723
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
6724
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
6725
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 6726
 
3 liveuser 6727
		#如果檢查關鍵字失敗
6728
		if($getMeetConditionsString["status"]=="false"){
226 liveuser 6729
 
3 liveuser 6730
			#設置錯誤識別
6731
			$result["status"]="false";
226 liveuser 6732
 
3 liveuser 6733
			#設置錯誤訊息
6734
			$result["error"]=$getMeetConditionsString;
226 liveuser 6735
 
3 liveuser 6736
			#回傳結果
6737
			return $result;
226 liveuser 6738
 
6739
			}#if end
6740
 
3 liveuser 6741
		#如果目標路徑不為「/」開頭的路徑,則為相對路徑
6742
		if($getMeetConditionsString["founded"]=="false"){
226 liveuser 6743
 
3 liveuser 6744
			#取得目標位置的路徑
6745
			#函式說明:
6746
			#將檔案的位置名稱變成網址
6747
			#回傳結果:
6748
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6749
			#$result["error"],錯誤訊息陣列.
226 liveuser 6750
			#$result["function"],函數名稱.
3 liveuser 6751
			#$result["content"],網址.
6752
			#$result["localAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
6753
			#$result["fileSystemAbsoulutePosition"],針對伺服器檔案系統的絕對位置.
6754
			#必填參數:
6755
			#$conf["address"],字串,檔案的相對位置.
6756
			$conf["fileAccess::getInternetAddress"]["address"]=$conf["position"];
6757
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
6758
			$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
6759
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是.
6760
			#$conf["fileAccess::getInternetAddress"]["userDir"]="true";
6761
			$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
226 liveuser 6762
			unset($conf["fileAccess::getInternetAddress"]);
6763
 
3 liveuser 6764
			#如果將檔案的位置名稱變成網址失敗
6765
			if($getInternetAddress["status"]=="false"){
226 liveuser 6766
 
3 liveuser 6767
				#設置錯誤識別
6768
				$result["status"]="false";
226 liveuser 6769
 
3 liveuser 6770
				#設置錯誤訊息
6771
				$result["error"]=$getInternetAddress;
226 liveuser 6772
 
3 liveuser 6773
				#回傳結果
6774
				return $result;
226 liveuser 6775
 
6776
				}#if end
6777
 
3 liveuser 6778
			#置換目標位置為檔案系統路徑的絕對位置
6779
			$conf["position"]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 6780
 
6781
			}#if end
6782
 
6783
		#如果目標是資料夾
3 liveuser 6784
		if(is_dir($conf["position"])) {
226 liveuser 6785
 
3 liveuser 6786
			#設置為資料夾
6787
			$result["folder"]="true";
226 liveuser 6788
 
3 liveuser 6789
			#如果開啟資料夾成功
6790
			if($dh=opendir($conf["position"])){
226 liveuser 6791
 
3 liveuser 6792
				#初始化計數變數
6793
				$count=0;
226 liveuser 6794
 
3 liveuser 6795
				#如果資料夾裡面有檔案
6796
				while(($fileName=readdir($dh))!==false){
226 liveuser 6797
 
3 liveuser 6798
					#debug
6799
					#echo "有檔案";
226 liveuser 6800
 
3 liveuser 6801
					#如果名稱是「.」或「..」
6802
					if($fileName=="." || $fileName==".."){
226 liveuser 6803
 
3 liveuser 6804
						#則跳過
6805
						continue;
226 liveuser 6806
 
3 liveuser 6807
						}#if end
226 liveuser 6808
 
3 liveuser 6809
					#取得檔案或子目錄名稱
226 liveuser 6810
					$result["content"][$count]["name"]=$fileName;
6811
 
3 liveuser 6812
					#取得詳細資訊
6813
					#函式說明:
6814
					#取得節點的資訊.
6815
					#回傳結果:
6816
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6817
					#$result["error"],錯誤訊息陣列.
226 liveuser 6818
					#$result["function"],函數名稱.
3 liveuser 6819
					#$result["content"],檔案資訊陣列.
226 liveuser 6820
					#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 6821
					#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
6822
					#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
6823
					#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
6824
					#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
6825
					#$result["content"]["ownerName"],檔案擁有着資訊.
6826
					#$result["content"]["groupName"],檔案所屬擁有着資訊.
6827
					#$result["content"]["size"],檔案大小.
6828
					#$result["content"]["modifyDate"],檔案變更年月日.
6829
					#$result["content"]["modifyTime"],檔案變更時分秒.
6830
					#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
6831
					#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
6832
					#必填參數:
6833
					#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
6834
					$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];
6835
					#$conf["file"],字串,要查看擁有者資訊的檔案.
6836
					$conf["fileAccess::fileInfo"]["file"]=$conf["position"]."/".$fileName;
6837
					#可省略參數:
6838
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
6839
					$conf["fileAccess::fileInfo"]["web"]="false";
6840
					#參考資料:
6841
					#fileowner=>http://php.net/manual/en/function.fileowner.php
6842
					#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
6843
					#備註:
6844
					#無.
6845
					$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
6846
					unset($conf["fileAccess::fileInfo"]);
226 liveuser 6847
 
3 liveuser 6848
					#如果執行失敗
6849
					if($fileInfo["status"]=="false"){
226 liveuser 6850
 
3 liveuser 6851
						#設置錯誤識別
6852
						$result["status"]="false";
226 liveuser 6853
 
3 liveuser 6854
						#設置錯誤訊息
6855
						$result["error"]=$fileInfo;
226 liveuser 6856
 
3 liveuser 6857
						#回傳結果
6858
						return $result;
226 liveuser 6859
 
3 liveuser 6860
						}#if end
226 liveuser 6861
 
3 liveuser 6862
					#設置是否為資料夾
6863
					$result["content"][$count]["folder"]=$fileInfo["content"]["is_folder"];
226 liveuser 6864
 
3 liveuser 6865
					#設置使用者的權限
6866
					$result["content"][$count]["ownerPerm"]=$fileInfo["content"]["ownerPerm"];
226 liveuser 6867
 
3 liveuser 6868
					#設置群組的權限
6869
					$result["content"][$count]["groupPerm"]=$fileInfo["content"]["groupPerm"];
226 liveuser 6870
 
3 liveuser 6871
					#設置其他使用者的權限
6872
					$result["content"][$count]["otherPerm"]=$fileInfo["content"]["otherPerm"];
226 liveuser 6873
 
3 liveuser 6874
					#設置其擁有者賬戶
6875
					$result["content"][$count]["ownerName"]=$fileInfo["content"]["ownerName"];
226 liveuser 6876
 
3 liveuser 6877
					#設置其群組擁有者賬戶
6878
					$result["content"][$count]["groupName"]=$fileInfo["content"]["groupName"];
226 liveuser 6879
 
3 liveuser 6880
					#計數加1
6881
					$count++;
226 liveuser 6882
 
3 liveuser 6883
					}#while
226 liveuser 6884
 
3 liveuser 6885
				#關閉資料夾
6886
				closedir($dh);
226 liveuser 6887
 
3 liveuser 6888
				}#if end
226 liveuser 6889
 
6890
			#開啟資料夾失敗
3 liveuser 6891
			else{
226 liveuser 6892
 
3 liveuser 6893
				#設置執行失敗
6894
				$result["status"]="false";
226 liveuser 6895
 
3 liveuser 6896
				#設置執行錯誤訊息
6897
				$result["error"][]="開啟資料夾「".$conf["position"]."」失敗";
6898
 
6899
				#回傳結果
6900
				return $result;
226 liveuser 6901
 
3 liveuser 6902
				}#else end
226 liveuser 6903
 
3 liveuser 6904
			}#if end
226 liveuser 6905
 
3 liveuser 6906
		#反之是檔案
6907
		else{
226 liveuser 6908
 
3 liveuser 6909
			#設置不為目錄
6910
			$result["folder"]="false";
226 liveuser 6911
 
3 liveuser 6912
			}#else end
226 liveuser 6913
 
3 liveuser 6914
		#取得目前位置
226 liveuser 6915
		$result["position"]=$conf["position"];
6916
 
3 liveuser 6917
		#執行到這邊代表執行正常
6918
		$result["status"]="true";
226 liveuser 6919
 
3 liveuser 6920
		#回傳結果
226 liveuser 6921
		return $result;
3 liveuser 6922
 
6923
		}#function getList end
226 liveuser 6924
 
3 liveuser 6925
	/*
6926
	#函式說明:
6927
	#取得目錄底下所有目錄與檔案的樹狀結構.
6928
	#回傳結果:
6929
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6930
	#$result["error"],錯誤訊息陣列.
6931
	#$result["function"],函數名稱.
6932
	#$result["content"],陣列,檔案目錄的樹狀結構.
6933
	#必填參數:
6934
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6935
	$conf["position"]="";
6936
	#可省略參數:
6937
	#無.
6938
	#參考資料:
6939
	#無.
6940
	#備註:
6941
	#無.
6942
	*/
6943
	public static function exportListTree(&$conf){
226 liveuser 6944
 
3 liveuser 6945
		#初始化要回傳的結果
6946
		$result=array();
226 liveuser 6947
 
3 liveuser 6948
		#設置當其函數名稱
6949
		$result["function"]=__FUNCTION__;
226 liveuser 6950
 
3 liveuser 6951
		#如果 $conf 不為陣列
6952
		if(gettype($conf)!="array"){
226 liveuser 6953
 
3 liveuser 6954
			#設置執行失敗
6955
			$result["status"]="false";
226 liveuser 6956
 
3 liveuser 6957
			#設置執行錯誤訊息
6958
			$result["error"][]="\$conf變數須為陣列形態";
6959
 
6960
			#如果傳入的參數為 null
6961
			if($conf==null){
226 liveuser 6962
 
3 liveuser 6963
				#設置執行錯誤訊息
6964
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6965
 
3 liveuser 6966
				}#if end
6967
 
6968
			#回傳結果
6969
			return $result;
226 liveuser 6970
 
3 liveuser 6971
			}#if end
226 liveuser 6972
 
3 liveuser 6973
		#檢查必填參數
6974
		#函式說明:
6975
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6976
		#回傳的結果:
6977
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6978
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6979
		#$result["function"],當前執行的函式名稱.
6980
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6981
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6982
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6983
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6984
		#必填寫的參數:
6985
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6986
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6987
		#可以省略的參數:
226 liveuser 6988
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6989
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6990
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
6991
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 6992
 
3 liveuser 6993
		#如果檢查失敗
6994
		if($checkResult["status"]=="false"){
226 liveuser 6995
 
3 liveuser 6996
			#設置錯誤識別
6997
			$result["status"]="false";
226 liveuser 6998
 
3 liveuser 6999
			#設置錯誤訊息
7000
			$result["error"]=$checkResult;
226 liveuser 7001
 
3 liveuser 7002
			#回傳結果
7003
			return $result;
226 liveuser 7004
 
3 liveuser 7005
			}#if end
226 liveuser 7006
 
3 liveuser 7007
		#如果檢查不通過
7008
		if($checkResult["passed"]=="false"){
226 liveuser 7009
 
3 liveuser 7010
			#設置錯誤識別
7011
			$result["status"]="false";
226 liveuser 7012
 
3 liveuser 7013
			#設置錯誤訊息
7014
			$result["error"]=$checkResult;
226 liveuser 7015
 
3 liveuser 7016
			#回傳結果
7017
			return $result;
226 liveuser 7018
 
3 liveuser 7019
			}#if end
226 liveuser 7020
 
3 liveuser 7021
		#函式說明:
7022
		#取得目錄底下所有目錄與檔案的樹狀結構.
7023
		#回傳結果:
7024
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7025
		#$result["error"],錯誤訊息陣列.
7026
		#$result["function"],函數名稱.
7027
		#$result["content"],陣列,檔案目錄的樹狀結構.
7028
		#必填參數:
7029
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
7030
		$conf["fileAccess::getListTree"]["position"]=$conf["position"];
7031
		#可省略參數:
7032
		#無
7033
		#備註:
226 liveuser 7034
		#若檔案與目錄的名稱含有「[」與「]」與「(」與「)」將會無法取得其目錄底下的內容
3 liveuser 7035
		#若檔案與目錄的名稱含有「 」將會無法檢查檔案是否存在
7036
		#改用opendir()函數應該可以解決大部分的bug.
7037
		$getListTree=fileAccess::getListTree($conf["fileAccess::getListTree"]);
7038
		unset($conf["fileAccess::getListTree"]);
226 liveuser 7039
 
3 liveuser 7040
		#如果取得 目標目錄底下所有目錄與檔案的樹狀結構 失敗
7041
		if($getListTree["status"]==="false"){
226 liveuser 7042
 
3 liveuser 7043
			#設置錯誤識別
7044
			$result["status"]="false";
226 liveuser 7045
 
3 liveuser 7046
			#設置錯誤訊息
7047
			$result["error"]=$getListTree;
226 liveuser 7048
 
3 liveuser 7049
			#回傳結果
7050
			return $result;
226 liveuser 7051
 
3 liveuser 7052
			}#if end
226 liveuser 7053
 
3 liveuser 7054
		#目標目錄底下有幾個
226 liveuser 7055
 
3 liveuser 7056
		}#function exportListTree end
7057
 
7058
	/*
7059
	#函式說明:
7060
	#解壓縮tar.xz檔案,解壓縮完畢後,tar.xz檔案會被移除.
7061
	#回傳結果:
7062
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7063
	#$result["error"],錯誤訊息陣列.
226 liveuser 7064
	#$result["function"],函數名稱.
3 liveuser 7065
	#必填參數:
7066
	#$conf["tarXzFile"],字串變數,壓縮檔的位置與名稱,副檔名".tar.xz"會自動補上.
7067
	$conf["tarXzFile"]="";
7068
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7069
	$conf["fileArgu"]=__FILE__;
7070
	#可省略參數:
7071
	#$conf["extractTo"],字串,要解壓縮到哪邊,預設為當前路徑"."
7072
	#$conf["extractTo"]=".";
7073
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7074
	#$conf["commentsArray"]=array("");
7075
	#參考資料:
7076
	#無.
7077
	#備註:
7078
	#無.
7079
	*/
7080
	public static function unpackTarXzFile(&$conf){
226 liveuser 7081
 
3 liveuser 7082
		#初始化要回傳的內容
7083
		$result=array();
226 liveuser 7084
 
3 liveuser 7085
		#記錄當前執行的函數名稱
7086
		$result["function"]=__FUNCTION__;
226 liveuser 7087
 
3 liveuser 7088
		#如果 $conf 不為陣列
7089
		if(gettype($conf)!="array"){
226 liveuser 7090
 
3 liveuser 7091
			#設置執行失敗
7092
			$result["status"]="false";
226 liveuser 7093
 
3 liveuser 7094
			#設置執行錯誤訊息
7095
			$result["error"][]="\$conf變數須為陣列形態";
7096
 
7097
			#如果傳入的參數為 null
7098
			if($conf==null){
226 liveuser 7099
 
3 liveuser 7100
				#設置執行錯誤訊息
7101
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7102
 
3 liveuser 7103
				}#if end
7104
 
7105
			#回傳結果
7106
			return $result;
226 liveuser 7107
 
3 liveuser 7108
			}#if end
226 liveuser 7109
 
3 liveuser 7110
		#檢查參數
7111
		#函式說明:
7112
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7113
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7114
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7115
		#$result["function"],當前執行的函式名稱.
7116
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7117
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7118
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7119
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7120
		#必填寫的參數:
7121
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7122
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7123
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7124
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","tarXzFile");
226 liveuser 7125
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7126
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
7127
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7128
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7129
		#可以省略的參數:
7130
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7131
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7132
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7133
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","extractTo");
226 liveuser 7134
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7135
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string");
7136
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7137
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,".");
7138
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7139
		#$conf["arrayCountEqualCheck"][]=array();
7140
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7141
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 7142
 
3 liveuser 7143
		#若檢查失敗
7144
		if($checkResult["status"]=="false"){
226 liveuser 7145
 
3 liveuser 7146
			#設置執行失敗
7147
			$result["status"]="false";
226 liveuser 7148
 
3 liveuser 7149
			#設置執行錯誤訊息
7150
			$result["error"]=$checkResult;
226 liveuser 7151
 
3 liveuser 7152
			#回傳結果
7153
			return $result;
226 liveuser 7154
 
3 liveuser 7155
			}#if end
226 liveuser 7156
 
3 liveuser 7157
		#若檢查不通過
7158
		if($checkResult["passed"]=="false"){
226 liveuser 7159
 
3 liveuser 7160
			#設置執行失敗
7161
			$result["status"]="false";
226 liveuser 7162
 
3 liveuser 7163
			#設置執行錯誤訊息
7164
			$result["error"]=$checkResult;
226 liveuser 7165
 
3 liveuser 7166
			#回傳結果
7167
			return $result;
226 liveuser 7168
 
3 liveuser 7169
			}#if end
226 liveuser 7170
 
3 liveuser 7171
		#如果 $conf["commentsArray"] 有設定
7172
		if(isset($conf["commentsArray"])){
226 liveuser 7173
 
3 liveuser 7174
			#印出提示文字
7175
			#函式說明:
7176
			#印出多行文字,結尾自動換行.
7177
			#回傳的結果:
7178
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
7179
			#$result["function"],當前執行的函數名稱.
7180
			#$result["error"],錯誤訊息陣列.
7181
			#必填參數:
7182
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
7183
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
7184
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
7185
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 7186
 
3 liveuser 7187
			#如果印出提示文字失敗
7188
			if($echoMultiLine["status"]=="false"){
226 liveuser 7189
 
3 liveuser 7190
				#設置執行失敗
7191
				$result["status"]="false";
226 liveuser 7192
 
3 liveuser 7193
				#設置執行錯誤訊息
7194
				$result["error"]=$echoMultiLine;
226 liveuser 7195
 
3 liveuser 7196
				#回傳結果
7197
				return $result;
226 liveuser 7198
 
3 liveuser 7199
				}#if end
226 liveuser 7200
 
3 liveuser 7201
			}#if end
226 liveuser 7202
 
3 liveuser 7203
		#檢查要移動的檔案是否存在
7204
		#函式說明:
7205
		#檢查多個檔案與資料夾是否存在.
7206
		#回傳的結果:
7207
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
7208
		#$result["error"],錯誤訊息陣列.
7209
		#$resutl["function"],當前執行的涵式名稱.
7210
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
7211
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
7212
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
7213
		#必填參數:
7214
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["tarXzFile"].".tar.xz");#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
7215
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7216
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
7217
		#參考資料來源:
7218
		#http://php.net/manual/en/function.file-exists.php
7219
		#http://php.net/manual/en/control-structures.foreach.php
7220
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
7221
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 7222
 
3 liveuser 7223
		#如果檢查失敗
7224
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 7225
 
3 liveuser 7226
			#設置執行失敗
7227
			$result["status"]="false";
226 liveuser 7228
 
3 liveuser 7229
			#設置執行錯誤訊息
7230
			$result["error"]=$checkMultiFileExist;
226 liveuser 7231
 
3 liveuser 7232
			#回傳結果
7233
			return $result;
226 liveuser 7234
 
7235
			}#if end
7236
 
3 liveuser 7237
		#如果來源檔案不存在
7238
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 7239
 
3 liveuser 7240
			#設置執行失敗
7241
			$result["status"]="false";
226 liveuser 7242
 
3 liveuser 7243
			#設置執行錯誤訊息
7244
			$result["error"][]="檔案「".$conf["tarXzFile"].".tar.xz」不存在";
226 liveuser 7245
 
3 liveuser 7246
			#回傳結果
7247
			return $result;
226 liveuser 7248
 
3 liveuser 7249
			}#if end
226 liveuser 7250
 
3 liveuser 7251
		#進行解壓縮xz檔
7252
		#函式說明:
7253
		#呼叫shell執行系統命令,並取得回傳的內容.
7254
		#回傳的結果:
7255
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7256
		#$result["error"],錯誤訊息陣列.
7257
		#$result["function"],當前執行的函數名稱.
7258
		#$result["cmd"],執行的指令內容.
7259
		#$result["output"],爲執行完二元碼後的輸出陣列.
7260
		#必填的參數
7261
		#$conf["command"],字串,要執行的指令與.
7262
		$conf["fileAccess::callShell"]["command"]="xz -v -v -d -f ".$conf["tarXzFile"].".tar.xz";
7263
		#可省略參數:
7264
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7265
		#$conf["fileAccess::callShell"]["argu"]=array();
7266
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7267
		#$conf["enablePrintDescription"]="true";
7268
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7269
		#$conf["printDescription"]="";
7270
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
7271
		#$conf["escapeshellarg"]="true";
7272
		#備註:
7273
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
7274
		#參考資料:
7275
		#exec=>http://php.net/manual/en/function.exec.php
7276
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7277
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7278
		$callShell=external::callShell($conf["fileAccess::callShell"]);
7279
		unset($conf["fileAccess::callShell"]);
226 liveuser 7280
 
3 liveuser 7281
		#如果解壓縮xz檔案失敗
7282
		if($callShell["status"]=="false"){
226 liveuser 7283
 
3 liveuser 7284
			#設置執行失敗
7285
			$result["status"]="false";
226 liveuser 7286
 
3 liveuser 7287
			#設置執行錯誤訊息
7288
			$result["error"]=$callShell;
226 liveuser 7289
 
3 liveuser 7290
			#回傳結果
7291
			return $result;
226 liveuser 7292
 
3 liveuser 7293
			}#if end
226 liveuser 7294
 
3 liveuser 7295
		#解壓縮tar檔
7296
		#函式說明:
7297
		#呼叫shell執行系統命令,並取得回傳的內容.
7298
		#回傳的結果:
7299
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7300
		#$result["error"],錯誤訊息陣列.
7301
		#$result["function"],當前執行的函數名稱.
7302
		#$result["cmd"],執行的指令內容.
7303
		#$result["output"],爲執行完二元碼後的輸出陣列.
7304
		#必填的參數
7305
		#$conf["command"],字串,要執行的指令與.
7306
		$conf["fileAccess::callShell"]["command"]="tar";
7307
		#可省略參數:
7308
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7309
		$conf["fileAccess::callShell"]["argu"]=array("-xvf",$conf["tarXzFile"]."tar",$conf["extractTo"]);
7310
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7311
		#$conf["enablePrintDescription"]="true";
7312
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7313
		#$conf["printDescription"]="";
7314
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
7315
		$conf["fileAccess::callShell"]["escapeshellarg"]="true";
7316
		#備註:
7317
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
7318
		#參考資料:
7319
		#exec=>http://php.net/manual/en/function.exec.php
7320
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7321
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7322
		$callShell=external::callShell($conf["fileAccess::callShell"]);
7323
		unset($conf["fileAccess::callShell"]);
226 liveuser 7324
 
3 liveuser 7325
		#如果解壓縮xz檔案失敗
7326
		if($callShell["status"]=="false"){
226 liveuser 7327
 
3 liveuser 7328
			#設置執行失敗
7329
			$result["status"]="false";
226 liveuser 7330
 
3 liveuser 7331
			#設置執行錯誤訊息
7332
			$result["error"]=$callShell;
226 liveuser 7333
 
3 liveuser 7334
			#回傳結果
7335
			return $result;
226 liveuser 7336
 
3 liveuser 7337
			}#if end
226 liveuser 7338
 
3 liveuser 7339
		#移除tar檔
7340
		#函式說明:
7341
		#移除檔案
7342
		#回傳結果:
7343
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7344
		#$result["error"],錯誤訊息陣列
7345
		#$result["warning"],警告訊息陣列
7346
		#$result["function"],當前執行的函數名稱
7347
		#必填參數:
7348
		$conf["fileAccess::delFile"]["fileAddress"]=$conf["tarXzFile"].".tar";#要移除檔案的位置
7349
		#可省略參數:
7350
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7351
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
7352
		#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7353
		#$conf["commentsArray"]=array("");
7354
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
226 liveuser 7355
		unset($conf["fileAccess::delFile"]);
7356
 
3 liveuser 7357
		#如果移除檔案失敗
7358
		if($delFile["status"]=="false"){
226 liveuser 7359
 
3 liveuser 7360
			#設置執行失敗
7361
			$result["status"]="false";
226 liveuser 7362
 
3 liveuser 7363
			#設置執行錯誤訊息
7364
			$result["error"]=$delFile;
226 liveuser 7365
 
3 liveuser 7366
			#回傳結果
7367
			return $result;
226 liveuser 7368
 
7369
			}#if end
7370
 
3 liveuser 7371
		#執行到這邊代表執行正常
7372
		$result["status"]="true";
226 liveuser 7373
 
3 liveuser 7374
		#回傳結果
7375
		return $result;
226 liveuser 7376
 
3 liveuser 7377
		}#function unpackTarXzFile end
7378
 
7379
	/*
7380
	#函式說明:
7381
	#用data:mimeType;base64,fileVar的形式來提供檔案的連結,亦即檔案儲存在變數裡面.
7382
	#回傳結果:
7383
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7384
	#$result["error"],錯誤訊息
7385
	#$result["content"],檔案變數的內容
7386
	#$result["fileTypeName"],副檔名,ex:「.tar.xz」.
226 liveuser 7387
	#$result["function"],當前執行的函數名稱
3 liveuser 7388
	#必填參數:
7389
	#$conf["filePosition"],要轉存成2元碼的檔案位置與名稱
7390
	$conf["filePosition"]="";
7391
	#$conf["mimeType"],2元碼的內容是什麼
7392
	$conf["mimeType"]="";
7393
	#可省略參數:
7394
	#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
7395
	#$conf["compressType"]="base64";
7396
	#$conf["delFile"],讀取完檔案後,要移除檔案嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
7397
	#$conf["delFile"]="false";
7398
	#參考資料:
7399
	#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
7400
	#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
7401
	#備註:
7402
	#無.
7403
	*/
7404
	public static function data(&$conf){
226 liveuser 7405
 
3 liveuser 7406
		#初始化要回傳的內容
7407
		$result=array();
226 liveuser 7408
 
3 liveuser 7409
		#取得當前執行的函數名稱
7410
		$result["function"]=__FUNCTION__;
226 liveuser 7411
 
3 liveuser 7412
		#如果 $conf 不為陣列
7413
		if(gettype($conf)!="array"){
226 liveuser 7414
 
3 liveuser 7415
			#設置執行失敗
7416
			$result["status"]="false";
226 liveuser 7417
 
3 liveuser 7418
			#設置執行錯誤訊息
7419
			$result["error"][]="\$conf變數須為陣列形態";
7420
 
7421
			#如果傳入的參數為 null
7422
			if($conf==null){
226 liveuser 7423
 
3 liveuser 7424
				#設置執行錯誤訊息
7425
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7426
 
3 liveuser 7427
				}#if end
7428
 
7429
			#回傳結果
7430
			return $result;
226 liveuser 7431
 
3 liveuser 7432
			}#if end
226 liveuser 7433
 
3 liveuser 7434
		#檢查參數
7435
		#函式說明:
7436
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7437
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7438
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7439
		#$result["function"],當前執行的函式名稱.
7440
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7441
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7442
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7443
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7444
		#必填寫的參數:
7445
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7446
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7447
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7448
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePosition");
226 liveuser 7449
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7450
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7451
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7452
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7453
		#可以省略的參數:
7454
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7455
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7456
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7457
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mimeType","compressType","delFile");
226 liveuser 7458
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7459
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
7460
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,「null」代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7461
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("null","base64","false");
7462
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7463
		#$conf["arrayCountEqualCheck"][]=array();
7464
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7465
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 7466
 
3 liveuser 7467
		#如果檢查參數失敗
7468
		if($checkResult["status"]=="false"){
226 liveuser 7469
 
3 liveuser 7470
			#設置執行失敗
7471
			$result["status"]="false";
226 liveuser 7472
 
3 liveuser 7473
			#設置錯誤訊息
7474
			$result["error"]=$checkResult;
226 liveuser 7475
 
3 liveuser 7476
			#回傳結果
7477
			return $result;
226 liveuser 7478
 
3 liveuser 7479
			}#if end
226 liveuser 7480
 
3 liveuser 7481
		#如果檢查參數不通過
7482
		if($checkResult["passed"]=="false"){
226 liveuser 7483
 
3 liveuser 7484
			#設置執行失敗
7485
			$result["status"]="false";
226 liveuser 7486
 
3 liveuser 7487
			#設置錯誤訊息
7488
			$result["error"]=$checkResult;
226 liveuser 7489
 
3 liveuser 7490
			#回傳結果
7491
			return $result;
226 liveuser 7492
 
3 liveuser 7493
			}#if end
226 liveuser 7494
 
3 liveuser 7495
		#依據檔案名稱取得副檔名 $result["fileTypeName"]
7496
		#函式說明:
7497
		#將固定格式的字串分開,並回傳分開的結果。
7498
		#回傳的參數:
7499
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7500
		#$result["error"],錯誤訊息陣列
7501
		#$result["function"],當前執行的函數名稱.
7502
		#$result["oriStr"],要分割的原始字串內容
7503
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7504
		#$result["dataCounts"],爲總共分成幾段
7505
		#必填參數:
7506
		$conf["stringProcess::spiltString"]["stringIn"]=basename($conf["filePosition"]);#要處理的字串。
7507
		$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
7508
		#備註:
7509
		#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
7510
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
7511
		unset($conf["stringProcess::spiltString"]);
226 liveuser 7512
 
3 liveuser 7513
		#如果分割字串失敗
7514
		if($spiltString["status"]=="false"){
226 liveuser 7515
 
3 liveuser 7516
			#設置執行失敗
7517
			$result["status"]="false";
226 liveuser 7518
 
3 liveuser 7519
			#設置錯誤訊息
7520
			$result["error"]=$spiltString;
226 liveuser 7521
 
3 liveuser 7522
			#回傳結果
7523
			return $result;
226 liveuser 7524
 
3 liveuser 7525
			}#if end
226 liveuser 7526
 
3 liveuser 7527
		#初始化副檔名
226 liveuser 7528
		$result["fileTypeName"]="";
7529
 
3 liveuser 7530
		#如果只有一段代表沒有副檔名
7531
		if($spiltString["dataCounts"]==1){
226 liveuser 7532
 
3 liveuser 7533
			#副檔名設置為 "unknow"
7534
			$result["fileTypeName"]="unknow";
226 liveuser 7535
 
3 liveuser 7536
			}#if end
226 liveuser 7537
 
3 liveuser 7538
		#不符合以上條件,但至少有兩段
7539
		else if($spiltString["dataCounts"]>=2){
226 liveuser 7540
 
3 liveuser 7541
			#執行 $spiltString["dataCounts"] 減一次的迴圈
7542
			for($i=1;$i<$spiltString["dataCounts"];$i++){
226 liveuser 7543
 
3 liveuser 7544
				#串接副檔名
7545
				$result["fileTypeName"]=$result["fileTypeName"].".".$spiltString["dataArray"][$i];
226 liveuser 7546
 
3 liveuser 7547
				}#for end
226 liveuser 7548
 
3 liveuser 7549
			}#if end
226 liveuser 7550
 
3 liveuser 7551
		#讀取檔案內容
7552
		$fileBin=file_get_contents($conf["filePosition"],"rb");
226 liveuser 7553
 
3 liveuser 7554
		#編碼檔案
7555
		$base64fileBin=base64_encode($fileBin);
226 liveuser 7556
 
3 liveuser 7557
		#如果 $conf["delFile"] 等於 "true"
7558
		if($conf["delFile"]=="true"){
226 liveuser 7559
 
3 liveuser 7560
			#移除檔案
7561
			#函式說明:
7562
			#移除檔案
7563
			#回傳結果:
7564
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7565
			#$result["error"],錯誤訊息陣列
7566
			#$result["warning"],警告訊息陣列
7567
			#$result["function"],當前執行的函數名稱
7568
			#必填參數:
7569
			$conf["fileAccess::delFile"]["fileAddress"]=$conf["filePosition"];#要移除檔案的位置
7570
			$del=fileAccess::delFile($conf["fileAccess::delFile"]);
7571
			unset($conf["fileAccess::delFile"]);
226 liveuser 7572
 
3 liveuser 7573
			#如果移除圖片失敗
7574
			if($del["status"]=="false"){
226 liveuser 7575
 
3 liveuser 7576
				#設置執行失敗
7577
				$result["status"]="false";
226 liveuser 7578
 
3 liveuser 7579
				#設置錯誤訊息
7580
				$result["error"]=$del;
226 liveuser 7581
 
3 liveuser 7582
				#回傳結果
7583
				return $result;
226 liveuser 7584
 
3 liveuser 7585
				}#if end
226 liveuser 7586
 
3 liveuser 7587
			}#if end
226 liveuser 7588
 
3 liveuser 7589
		#放置檔案的語法
7590
		$result["content"]="data:".$conf["mimeType"].";".$conf["compressType"].",".$base64fileBin;
226 liveuser 7591
 
3 liveuser 7592
		#執行到這邊代表執行正常
7593
		$result["status"]="true";
226 liveuser 7594
 
3 liveuser 7595
		#回傳結果
7596
		return $result;
226 liveuser 7597
 
3 liveuser 7598
		}#function data end
7599
 
7600
	/*
7601
	#函式說明:
7602
	#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
7603
	#回傳結果:
7604
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7605
	#$result["error"],錯誤訊息陣列.
226 liveuser 7606
	#$result["function"],函數名稱.
3 liveuser 7607
	#$result["argu"],使用的參數.
7608
	#$result["content"],網址,若是在命令列執行,則為"null".
7609
	#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
7610
	#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
7611
	#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
7612
	#必填參數:
7613
	#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
7614
	$conf["address"]="";
7615
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7616
	$conf["fileArgu"]=__FILE__;
7617
	#可省略參數:
7618
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
7619
	#$conf["userDir"]="true";
7620
	#參考資料:
7621
	#無.
7622
	#備註:
7623
	#無.
7624
	*/
7625
	public static function getInternetAddress(&$conf){
226 liveuser 7626
 
3 liveuser 7627
		#初始化要回傳的變數
7628
		$result=array();
226 liveuser 7629
 
3 liveuser 7630
		#記錄當前執行的函數名稱
7631
		$result["function"]=__FUNCTION__;
226 liveuser 7632
 
3 liveuser 7633
		#如果 $conf 不為陣列
7634
		if(gettype($conf)!="array"){
226 liveuser 7635
 
3 liveuser 7636
			#設置執行失敗
7637
			$result["status"]="false";
226 liveuser 7638
 
3 liveuser 7639
			#設置執行錯誤訊息
7640
			$result["error"][]="\$conf變數須為陣列形態";
7641
 
7642
			#如果傳入的參數為 null
7643
			if($conf==null){
226 liveuser 7644
 
3 liveuser 7645
				#設置執行錯誤訊息
7646
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7647
 
3 liveuser 7648
				}#if end
7649
 
7650
			#回傳結果
7651
			return $result;
226 liveuser 7652
 
3 liveuser 7653
			}#if end
7654
 
7655
		#取得使用的參數
7656
		$result["argu"]=$conf;
226 liveuser 7657
 
3 liveuser 7658
		#檢查參數
7659
		#函式說明:
7660
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7661
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7662
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7663
		#$result["function"],當前執行的函式名稱.
7664
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7665
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7666
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7667
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7668
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7669
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7670
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7671
		#必填寫的參數:
7672
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7673
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7674
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7675
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("address","fileArgu");
226 liveuser 7676
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7677
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
7678
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7679
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7680
		#可以省略的參數:
7681
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7682
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7683
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7684
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("userDir");
226 liveuser 7685
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7686
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
7687
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7688
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
7689
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7690
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
7691
		#參考資料來源:
7692
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7693
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7694
		unset($conf["variableCheck::checkArguments"]);
7695
 
7696
		#如果檢查失敗
7697
		if($checkResult["status"]==="false"){
226 liveuser 7698
 
3 liveuser 7699
			#設置錯誤狀態
7700
			$result["status"]="false";
226 liveuser 7701
 
3 liveuser 7702
			#設置錯誤提示
7703
			$result["error"]=$checkResult;
226 liveuser 7704
 
3 liveuser 7705
			#回傳結果
7706
			return $result;
226 liveuser 7707
 
3 liveuser 7708
			}#if end
7709
 
7710
		#如果檢查不通過
7711
		if($checkResult["passed"]==="false"){
226 liveuser 7712
 
3 liveuser 7713
			#設置錯誤狀態
7714
			$result["status"]="false";
226 liveuser 7715
 
3 liveuser 7716
			#設置錯誤提示
7717
			$result["error"]=$checkResult;
226 liveuser 7718
 
3 liveuser 7719
			#回傳結果
7720
			return $result;
226 liveuser 7721
 
3 liveuser 7722
			}#if end
226 liveuser 7723
 
3 liveuser 7724
		#如果是本來就是網址了
7725
		if(strpos($conf["address"],'https://')===0 || strpos($conf["address"],'http://')===0){
226 liveuser 7726
 
3 liveuser 7727
			#設置執行正常
7728
			$result["status"]="true";
226 liveuser 7729
 
3 liveuser 7730
			#取得網址
7731
			$result["content"]=$conf["address"];
226 liveuser 7732
 
3 liveuser 7733
			#回傳結果
226 liveuser 7734
			return $result;
7735
 
7736
			}#if end
7737
 
3 liveuser 7738
		#解析 $conf["fileArgu"]
7739
		#函式說明:
7740
		#將固定格式的字串分開,並回傳分開的結果。
7741
		#回傳的參數:
7742
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7743
		#$result["error"],錯誤訊息陣列
7744
		#$result["function"],當前執行的函數名稱.
7745
		#$result["oriStr"],要分割的原始字串內容
7746
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7747
		#$result["dataCounts"],爲總共分成幾段
7748
		#必填參數:
7749
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
7750
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7751
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7752
		unset($conf["stringProcess::spiltString"]);
7753
 
3 liveuser 7754
		#如果分割字串失敗
7755
		if($spiltString["status"]==="false"){
226 liveuser 7756
 
3 liveuser 7757
			#設置錯誤狀態
7758
			$result["status"]="false";
226 liveuser 7759
 
3 liveuser 7760
			#設置錯誤提示
7761
			$result["error"]=$spiltString;
226 liveuser 7762
 
3 liveuser 7763
			#回傳結果
7764
			return $result;
226 liveuser 7765
 
3 liveuser 7766
			}#if end
226 liveuser 7767
 
3 liveuser 7768
		#函式說明:
7769
		#將多個路徑字串變成相對於當前路徑的相對路徑字串
7770
		#回傳結果:
7771
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7772
		#$result["error"],錯誤訊息陣列.
226 liveuser 7773
		#$result["function"],函數名稱.
3 liveuser 7774
		#$result["content"],字串陣列,多個轉換好的相對路徑字串.
7775
		#必填參數:
7776
		#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
7777
		$conf["fileAccess::getRelativePath"]["path"]=array($conf["address"]);
7778
		#$conf["fileArgu"],字串,當前路徑.
7779
		$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
7780
		$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
7781
		unset($conf["fileAccess::getRelativePath"]);
226 liveuser 7782
 
3 liveuser 7783
		#如果取得相對位置失敗
7784
		if($getRelativePath["status"]==="false"){
226 liveuser 7785
 
3 liveuser 7786
			#設置錯誤狀態
7787
			$result["status"]="false";
226 liveuser 7788
 
3 liveuser 7789
			#設置錯誤提示
7790
			$result["error"]=$getRelativePath;
226 liveuser 7791
 
3 liveuser 7792
			#回傳結果
7793
			return $result;
226 liveuser 7794
 
7795
			}#if end
7796
 
3 liveuser 7797
		#取得轉換成相對路徑的位置
7798
		$result["fileSystemRelativePosition"]=$getRelativePath["content"][0];
226 liveuser 7799
 
3 liveuser 7800
		#解析 $conf["fileArgu"]
7801
		#函式說明:
7802
		#將固定格式的字串分開,並回傳分開的結果。
7803
		#回傳的參數:
7804
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7805
		#$result["error"],錯誤訊息陣列
7806
		#$result["function"],當前執行的函數名稱.
7807
		#$result["oriStr"],要分割的原始字串內容
7808
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7809
		#$result["dataCounts"],爲總共分成幾段
7810
		#必填參數:
7811
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
7812
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7813
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7814
		unset($conf["stringProcess::spiltString"]);
7815
 
3 liveuser 7816
		#如果分割字串失敗
7817
		if($spiltString["status"]==="false"){
226 liveuser 7818
 
3 liveuser 7819
			#設置錯誤狀態
7820
			$result["status"]="false";
226 liveuser 7821
 
3 liveuser 7822
			#設置錯誤提示
7823
			$result["error"]=$spiltString;
226 liveuser 7824
 
3 liveuser 7825
			#回傳結果
7826
			return $result;
226 liveuser 7827
 
3 liveuser 7828
			}#if end
226 liveuser 7829
 
3 liveuser 7830
		#debug
7831
		#var_dump($spiltString);
7832
		#var_dump($_SERVER);
7833
 
7834
		#初始化檔案在伺服器上的檔案系統位置
7835
		$result["fileSystemAbsoulutePosition"]="/";
226 liveuser 7836
 
3 liveuser 7837
		#將最後一段捨棄
7838
		for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7839
 
3 liveuser 7840
			$result["fileSystemAbsoulutePosition"]=$result["fileSystemAbsoulutePosition"].$spiltString["dataArray"][$i]."/";
226 liveuser 7841
 
7842
			}#for end
7843
 
3 liveuser 7844
		#取得非直觀的絕對位置
7845
		$result["fileSystemAbsoulutePosition"]=$result["fileSystemAbsoulutePosition"].$result["fileSystemRelativePosition"];
226 liveuser 7846
 
3 liveuser 7847
		#將檔案的相對路徑進行整理,變成可以直接讀的路徑.
7848
		#函式說明:
7849
		#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
7850
		#回傳的結果:
7851
		#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
7852
		#$result["function"],當前執行的函數.
7853
		#$result["error"],錯誤訊息陣列.
7854
		#$result["changedPath"],處理完後回傳的目錄字串.
7855
		#$result["oriPath"],原始的路徑字串
7856
		#必填參數:
7857
		#$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"],字串,要處理的檔案目錄字串.
7858
		$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$result["fileSystemAbsoulutePosition"];
7859
		$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
7860
		unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 7861
 
3 liveuser 7862
		#如果處理失敗
7863
		if($changeDirByDotDotSolidus["status"]==="false"){
226 liveuser 7864
 
3 liveuser 7865
			#設置錯誤狀態
7866
			$result["status"]="false";
226 liveuser 7867
 
3 liveuser 7868
			#設置錯誤提示
7869
			$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 7870
 
3 liveuser 7871
			#回傳結果
7872
			return $result;
226 liveuser 7873
 
3 liveuser 7874
			}#if end
226 liveuser 7875
 
3 liveuser 7876
		#改變為易讀的絕對路徑
226 liveuser 7877
		$result["fileSystemAbsoulutePosition"]=$changeDirByDotDotSolidus["changedPath"];
7878
 
3 liveuser 7879
		#如果 $conf["userDir"] 為 "true"
7880
		if($conf["userDir"]==="true"){
226 liveuser 7881
 
3 liveuser 7882
			#重設為 絕對路徑 [/~家目錄名稱」
7883
			$result["webPathFromRoot"]="/~".$spiltString["dataArray"][1];
226 liveuser 7884
 
3 liveuser 7885
			#從第四段到倒數第二段,將其內容合併
7886
			for($i=3;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7887
 
3 liveuser 7888
				$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$spiltString["dataArray"][$i];
226 liveuser 7889
 
3 liveuser 7890
				}#for end
226 liveuser 7891
 
3 liveuser 7892
			}#if end
226 liveuser 7893
 
3 liveuser 7894
		#反之 $conf["userDir"] 為 "false",
7895
		else{
226 liveuser 7896
 
3 liveuser 7897
			#重設為 ""
7898
			$result["webPathFromRoot"]="";
7899
 
226 liveuser 7900
			#可能的根目錄層級 - start
7901
 
3 liveuser 7902
			#解析 $conf["fileArgu"]
7903
			#函式說明:
7904
			#將固定格式的字串分開,並回傳分開的結果。
7905
			#回傳的參數:
7906
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7907
			#$result["error"],錯誤訊息陣列
7908
			#$result["function"],當前執行的函數名稱.
7909
			#$result["oriStr"],要分割的原始字串內容
7910
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7911
			#$result["dataCounts"],爲總共分成幾段
7912
			#必填參數:
7913
			$conf["stringProcess::spiltString"]["stringIn"]=$_SERVER["PHP_SELF"];#要處理的字串。
7914
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7915
			$keyWord=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7916
			unset($conf["stringProcess::spiltString"]);
3 liveuser 7917
 
7918
			#如果處理失敗
7919
			if($keyWord["status"]==="false"){
226 liveuser 7920
 
3 liveuser 7921
				#設置錯誤狀態
7922
				$result["status"]="false";
226 liveuser 7923
 
3 liveuser 7924
				#設置錯誤提示
7925
				$result["error"]=$keyWord;
226 liveuser 7926
 
3 liveuser 7927
				#回傳結果
7928
				return $result;
226 liveuser 7929
 
3 liveuser 7930
				}#if end
226 liveuser 7931
 
3 liveuser 7932
			#取得關鍵字
7933
			$keyWord=$keyWord["dataArray"][0];
7934
 
7935
			#預設層級為4層
7936
			$layer=4;
7937
 
7938
			#檢查每個絕對路徑片段
7939
			for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7940
 
3 liveuser 7941
				#如果路徑片段等於 $keyWord
7942
				if($spiltString["dataArray"][$i]===$keyWord){
226 liveuser 7943
 
3 liveuser 7944
					#取得層級
7945
					$layer=$i;
226 liveuser 7946
 
3 liveuser 7947
					#跳出迴圈
7948
					break;
7949
 
7950
					}#if end
226 liveuser 7951
 
3 liveuser 7952
				}#for end
7953
 
7954
			#可能的根目錄層級 - end
7955
 
7956
			#網頁於檔案系統中的存放路徑可能為「/var/www/html」,從第四段到倒數第二段,將其內容合併
7957
			for($i=$layer;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7958
 
3 liveuser 7959
				$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$spiltString["dataArray"][$i];
226 liveuser 7960
 
3 liveuser 7961
				}#for end
226 liveuser 7962
 
3 liveuser 7963
			}#else end
226 liveuser 7964
 
3 liveuser 7965
		#加上檔案的路徑
226 liveuser 7966
		$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$conf["address"];
7967
 
3 liveuser 7968
		#取得檔案位於網頁伺服器的絕對位置
7969
		#函式說明:
7970
		#取得用戶端的資訊,並依據需要寫入到資料表裡面
7971
		#回傳結果:
7972
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
7973
		#$result["error"],錯誤訊息.
7974
		#$result["function"],檔前執行的函數名稱.
7975
		#$result["userBrowserType"],爲使用者的瀏覽器資訊
7976
		#$result["userIp"],爲使用者的IP
7977
		#$result["serverIp"],為伺服器的IP
7978
		#$result["scheme"],通訊協定
7979
		#$result["serverPort"],伺服器給對外下載網頁的port
7980
		#$result["requestUri"],爲使用者要求的網址
7981
		#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
7982
		#$result["clientRequestIP"],用戶端要求的ip與port
7983
		#必填參數:
7984
		$conf["csInformation::getConnectionInfo"]["getAccount"]="false";#是否要取得帳號
7985
		#可省略參數:
7986
		#$conf["accountVar"]=$_SESSION["username"];#帳號儲存在哪個變數裏面,預設爲$_SESSION["username"]
7987
		#$conf["saveToDb"]="true";#是否要除儲存到資料庫,"true"為要儲存",預設為不儲存
7988
		#$conf["dbAddress"]=$dbAddress;;#爲mysql-Server的位置,若#$conf["saveToDb"]設為"true",則該參數為必填。
7989
		#$conf["dbAccount"]=$dbAccount;#爲用於連入mysql-Server時要使用的帳號,若#$conf["saveToDb"]設為"true",則該參數為必填。
7990
		#$conf["dbName"]=$dbName;#要選取的資料庫名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
7991
		#$conf["tableName"]="visitorInfo";#爲要插入資料的資料表名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
7992
		#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");#爲資料表的項目名稱,
7993
			#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
7994
			#寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間
7995
			#$conf["saveToDb"]設為"true",則該參數為必填。
7996
		#$conf["dbPassword"]=$dbPassword;#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
7997
		$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
226 liveuser 7998
		unset($conf["csInformation::getConnectionInfo"]);
7999
 
3 liveuser 8000
		#如果取得連線資訊失敗
8001
		if($getConnectionInfo["status"]==="false"){
226 liveuser 8002
 
3 liveuser 8003
			#設置錯誤狀態
8004
			$result["status"]="false";
226 liveuser 8005
 
3 liveuser 8006
			#設置錯誤提示
8007
			$result["error"]=$getConnectionInfo;
226 liveuser 8008
 
3 liveuser 8009
			#回傳結果
8010
			return $result;
226 liveuser 8011
 
3 liveuser 8012
			}#if end
226 liveuser 8013
 
3 liveuser 8014
		#如果運行環境為 "web"
8015
		if($getConnectionInfo["mode"]=="web"){
226 liveuser 8016
 
3 liveuser 8017
			#為絕對路徑加上通訊協定與ip與port
226 liveuser 8018
			#$result["content"]=$getConnectionInfo["scheme"]."://".$getConnectionInfo["serverIp"].":".$getConnectionInfo["serverPort"].$result["webPathFromRoot"];
8019
 
8020
			#為絕對路徑加上用戶端通訊協定與ip與port
3 liveuser 8021
			$result["content"]=$getConnectionInfo["scheme"]."://".$getConnectionInfo["clientRequestIP"].$result["webPathFromRoot"];
226 liveuser 8022
 
3 liveuser 8023
			}#if end
226 liveuser 8024
 
3 liveuser 8025
		#反之如果為 "cmd" 環境
8026
		else{
226 liveuser 8027
 
3 liveuser 8028
			$result["content"]="null";
226 liveuser 8029
 
3 liveuser 8030
			}#else end
226 liveuser 8031
 
3 liveuser 8032
		#設置執行正常
8033
		$result["status"]="true";
226 liveuser 8034
 
3 liveuser 8035
		#回傳結果
8036
		return $result;
226 liveuser 8037
 
3 liveuser 8038
		}#function getInternetAddress end
8039
 
8040
	/*
8041
	#函式說明:
8042
	#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
8043
	#回傳結果:
8044
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8045
	#$result["error"],錯誤訊息陣列.
226 liveuser 8046
	#$result["function"],函數名稱.
3 liveuser 8047
	#$result["argu"],使用的參數.
8048
	#$result["content"],網址,若是在命令列執行,則為"null".
8049
	#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
8050
	#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
8051
	#必填參數:
8052
	#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
8053
	$conf["address"]="";
8054
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8055
	$conf["fileArgu"]=__FILE__;
8056
	#可省略參數:
8057
	#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
8058
	#$conf["web"]="true";
8059
	#參考資料:
8060
	#無.
8061
	#備註:
8062
	#無.
8063
	*/
8064
	public static function getInternetAddressV2(&$conf){
226 liveuser 8065
 
3 liveuser 8066
		#初始化要回傳的變數
8067
		$result=array();
226 liveuser 8068
 
3 liveuser 8069
		#記錄當前執行的函數名稱
8070
		$result["function"]=__FUNCTION__;
226 liveuser 8071
 
3 liveuser 8072
		#取得參數
8073
		$result["argu"]=$conf;
226 liveuser 8074
 
3 liveuser 8075
		#檢查參數
8076
		#函式說明:
8077
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8078
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8079
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8080
		#$result["function"],當前執行的函式名稱.
8081
		#$result["argu"],設置給予的參數.
8082
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8083
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8084
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8085
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8086
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8087
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8088
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8089
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8090
		#必填寫的參數:
8091
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8092
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8093
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8094
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8095
		#可以省略的參數:
8096
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8097
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("address","fileArgu");
8098
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
8099
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
8100
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8101
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8102
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
8103
		#$conf["canNotBeEmpty"]=array();
8104
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
8105
		#$conf["canBeEmpty"]=array();
8106
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
8107
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
8108
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8109
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
8110
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8111
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
8112
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8113
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
8114
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
8115
		#$conf["disallowAllSkipableVarIsEmpty"]="";
8116
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
8117
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
8118
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8119
		#$conf["arrayCountEqualCheck"][]=array();
8120
		#參考資料來源:
8121
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8122
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8123
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 8124
 
3 liveuser 8125
		#如果檢查失敗
8126
		if($checkArguments["status"]==="false"){
226 liveuser 8127
 
3 liveuser 8128
			#設置錯誤狀態
8129
			$result["status"]="false";
226 liveuser 8130
 
3 liveuser 8131
			#設置錯誤提示
8132
			$result["error"]=$checkArguments;
226 liveuser 8133
 
3 liveuser 8134
			#回傳結果
8135
			return $result;
226 liveuser 8136
 
3 liveuser 8137
			}#if end
226 liveuser 8138
 
3 liveuser 8139
		#如果檢查不通過
8140
		if($checkArguments["passed"]==="false"){
226 liveuser 8141
 
3 liveuser 8142
			#設置錯誤狀態
8143
			$result["status"]="false";
226 liveuser 8144
 
3 liveuser 8145
			#設置錯誤提示
8146
			$result["error"]=$checkArguments;
226 liveuser 8147
 
3 liveuser 8148
			#回傳結果
8149
			return $result;
226 liveuser 8150
 
3 liveuser 8151
			}#if end
226 liveuser 8152
 
3 liveuser 8153
		#如果是本來就是網址了
8154
		if(strpos($conf["address"],'https://')===0 || strpos($conf["address"],'http://')===0){
226 liveuser 8155
 
3 liveuser 8156
			#取得網址
8157
			$result["content"]=$conf["address"];
226 liveuser 8158
 
3 liveuser 8159
			}#if end
226 liveuser 8160
 
3 liveuser 8161
		#反之是絕對或相對路徑
8162
		else{
226 liveuser 8163
 
3 liveuser 8164
			#確認 $conf["address"] 是否為 escaped 後的內容
8165
			#函式說明:
8166
			#判斷字串是否一定需要經過escapeshellarg才能為單一shell參數,並回傳可以成為單一shell參數的結果.
8167
			#回傳結果:
8168
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8169
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
8170
			#$result["function"],當前執行的函式名稱.
8171
			#$result["argu"],使用的參數.
8172
			#$result["content"],字串,單一shell參數.
8173
			#$result["escaped"],字串,"true"代表content為 escape後的結果;反之為"false".
8174
			#$result["urlEncodeStr"],字串,未被escape過的單一shell參數被url encode後的結果.
8175
			#必填參數:
8176
			#$conf["str"],字串,認為要為單一 shell參數的字串.
8177
			$conf["stringProcess::toSingleShellArg"]["str"]=$conf["address"];
8178
			#可省略參數:
8179
			#無.
8180
			#參考資料:
8181
			#無.
8182
			#備註:
8183
			#無.
8184
			$toSingleShellArg=stringProcess::toSingleShellArg($conf["stringProcess::toSingleShellArg"]);
8185
			unset($conf["stringProcess::toSingleShellArg"]);
226 liveuser 8186
 
3 liveuser 8187
			#如果執行失敗
8188
			if($toSingleShellArg["status"]==="false"){
226 liveuser 8189
 
3 liveuser 8190
				#設置錯誤狀態
8191
				$result["status"]="false";
226 liveuser 8192
 
3 liveuser 8193
				#設置錯誤提示
8194
				$result["error"]=$toSingleShellArg;
226 liveuser 8195
 
3 liveuser 8196
				#回傳結果
8197
				return $result;
226 liveuser 8198
 
3 liveuser 8199
				}#if end
226 liveuser 8200
 
3 liveuser 8201
			#取得不含escape字元的address參數
8202
			$conf["address"]=urldecode($toSingleShellArg["urlEncodeStr"]);
226 liveuser 8203
 
3 liveuser 8204
			#不是絕對位置
8205
			if(strpos($conf["address"],"/")!==0){
226 liveuser 8206
 
3 liveuser 8207
				#如果有這些參數
8208
				if( isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT']) ){
226 liveuser 8209
 
3 liveuser 8210
					#網址
8211
					$result["content"]=$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/".$conf["address"];
226 liveuser 8212
 
3 liveuser 8213
					}#if end
226 liveuser 8214
 
3 liveuser 8215
				#反之
8216
				else{
226 liveuser 8217
 
3 liveuser 8218
					#網址設置為 null
8219
					$result["content"]=null;
226 liveuser 8220
 
3 liveuser 8221
					}#else
226 liveuser 8222
 
3 liveuser 8223
				}#if end
226 liveuser 8224
 
3 liveuser 8225
			#反之是絕對位置
8226
			else{
226 liveuser 8227
 
3 liveuser 8228
				#移除開頭的 "/"
8229
				$conf["address"]=substr($conf["address"],1);
226 liveuser 8230
 
3 liveuser 8231
				#如果有這些參數
8232
				if( isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT']) ){
226 liveuser 8233
 
3 liveuser 8234
					#網址
8235
					$result["content"]=$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/".$conf["address"];
226 liveuser 8236
 
3 liveuser 8237
					}#if end
226 liveuser 8238
 
3 liveuser 8239
				#反之
8240
				else{
226 liveuser 8241
 
3 liveuser 8242
					#網址設置為 null
8243
					$result["content"]=null;
226 liveuser 8244
 
3 liveuser 8245
					}#else
226 liveuser 8246
 
3 liveuser 8247
				}#else end
226 liveuser 8248
 
3 liveuser 8249
			#取得 doc root;
8250
			$docRoot=$_SERVER['DOCUMENT_ROOT'];
226 liveuser 8251
 
3 liveuser 8252
			#如果不是網路環境
8253
			if($conf["web"]==="false"){
226 liveuser 8254
 
3 liveuser 8255
				#不採用 docRoot
8256
				$docRoot="";
226 liveuser 8257
 
3 liveuser 8258
				}#if end
226 liveuser 8259
 
3 liveuser 8260
			#如果不存在 DOCUMENT_ROOT 變數或 web 參數為 "false" 且為相對位置.
8261
			if( ($_SERVER['DOCUMENT_ROOT']==="" || $conf["web"]==="false") && (strpos($result["argu"]["address"],"/")!==0) ){
226 liveuser 8262
 
3 liveuser 8263
				#執行 "pwd" 取得當前位置
8264
				exec("pwd",$output,$status);
226 liveuser 8265
 
3 liveuser 8266
				#預設為`pwd`的結果加"/"
8267
				$docRoot=$output[0]."/";
226 liveuser 8268
 
8269
				}#if end
8270
 
3 liveuser 8271
			#如果是絕對位置
8272
			else if(strpos($result["argu"]["address"],"/")===0){
226 liveuser 8273
 
8274
				#補回 "/"
3 liveuser 8275
				$conf["address"]="/".$conf["address"];
226 liveuser 8276
 
3 liveuser 8277
				}#if end
226 liveuser 8278
 
3 liveuser 8279
			#針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
8280
			$result["fileSystemAbsoulutePosition"]=$docRoot.$conf["address"];
226 liveuser 8281
 
3 liveuser 8282
			}#else end
226 liveuser 8283
 
3 liveuser 8284
		#設置執行正常
226 liveuser 8285
		$result["status"]="true";
8286
 
3 liveuser 8287
		#回傳結果
8288
		return $result;
226 liveuser 8289
 
3 liveuser 8290
		}#function getInternetAddressV2 end
8291
 
8292
	/*
8293
	#函式說明:
8294
	#將含有「*」的檔案路徑名稱,變成多個符合條件的路徑檔案.
8295
	#回傳結果:
8296
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8297
	#$result["error"],錯誤訊息陣列.
226 liveuser 8298
	#$result["function"],函數名稱.
3 liveuser 8299
	#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
8300
	#必填參數:
8301
	#$conf["path"],字串,要解析含有「*」的檔案路徑字串.
8302
	$conf["path"]="";
8303
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8304
	$conf["fileArgu"]=__FILE__;
8305
	#可省略參數:
8306
	#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
8307
	#$conf["noDotStart"]="true";
8308
	#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
8309
	#$conf["noWaveEnd"]="true";
8310
	#參考資料:
8311
	#無.
8312
	#備註:
8313
	#無.
8314
	*/
8315
	public static function resolvePostionStringWhichContainStarSymbol(&$conf){
226 liveuser 8316
 
3 liveuser 8317
		#初始化要回傳的結果
8318
		$result=array();
226 liveuser 8319
 
3 liveuser 8320
		#設置當其函數名稱
8321
		$result["function"]=__FUNCTION__;
226 liveuser 8322
 
3 liveuser 8323
		#如果 $conf 不為陣列
8324
		if(gettype($conf)!="array"){
226 liveuser 8325
 
3 liveuser 8326
			#設置執行失敗
8327
			$result["status"]="false";
226 liveuser 8328
 
3 liveuser 8329
			#設置執行錯誤訊息
8330
			$result["error"][]="\$conf變數須為陣列形態";
8331
 
8332
			#如果傳入的參數為 null
8333
			if($conf==null){
226 liveuser 8334
 
3 liveuser 8335
				#設置執行錯誤訊息
8336
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 8337
 
3 liveuser 8338
				}#if end
8339
 
8340
			#回傳結果
8341
			return $result;
226 liveuser 8342
 
3 liveuser 8343
			}#if end
226 liveuser 8344
 
3 liveuser 8345
		#檢查參數
8346
		#函式說明:
8347
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8348
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8349
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8350
		#$result["function"],當前執行的函式名稱.
8351
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8352
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8353
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8354
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
8355
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8356
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8357
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8358
		#必填寫的參數:
8359
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8360
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8361
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8362
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 8363
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 8364
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
8365
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8366
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8367
		#可以省略的參數:
8368
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
8369
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8370
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8371
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noDotStart","noWaveEnd");
226 liveuser 8372
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 8373
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
8374
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8375
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","true");
8376
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8377
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
8378
		#參考資料來源:
8379
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8380
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8381
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 8382
 
3 liveuser 8383
		#如果 $checkResult["status"] 等於 "fasle"
8384
		if($checkResult["status"]==="false"){
226 liveuser 8385
 
3 liveuser 8386
			#設置錯誤識別
8387
			$result["status"]="false";
226 liveuser 8388
 
3 liveuser 8389
			#設置錯誤訊息
8390
			$result["error"]=$checkResult;
226 liveuser 8391
 
3 liveuser 8392
			#回傳結果
8393
			return $result;
226 liveuser 8394
 
3 liveuser 8395
			}#if end
226 liveuser 8396
 
3 liveuser 8397
		#如果 $checkResult["passed"] 等於 "fasle"
8398
		if($checkResult["passed"]==="false"){
226 liveuser 8399
 
3 liveuser 8400
			#設置錯誤識別
8401
			$result["status"]="false";
226 liveuser 8402
 
3 liveuser 8403
			#設置錯誤訊息
8404
			$result["error"]=$checkResult;
226 liveuser 8405
 
3 liveuser 8406
			#回傳結果
8407
			return $result;
226 liveuser 8408
 
3 liveuser 8409
			}#if end
226 liveuser 8410
 
3 liveuser 8411
		#轉換檔案路徑為相對於伺服器檔案系統的絕對路徑
8412
		#函式說明:
8413
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
8414
		#回傳結果:
8415
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8416
		#$result["error"],錯誤訊息陣列.
226 liveuser 8417
		#$result["function"],函數名稱.
3 liveuser 8418
		#$result["content"],網址.
8419
		#$result["localAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
8420
		#$result["fileSystemAbsoulutePosition"],針對伺服器檔案系統的絕對位置.
8421
		#必填參數:
8422
		#$conf["address"],字串,檔案的相對位置.
8423
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["path"];
8424
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8425
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
8426
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是.
8427
		$conf["fileAccess::getInternetAddress"]["userDir"]="true";
8428
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
8429
		unset($conf["fileAccess::getInternetAddress"]);
226 liveuser 8430
 
3 liveuser 8431
		#如果轉換路徑失敗
8432
		if($getInternetAddress["status"]=="false"){
226 liveuser 8433
 
3 liveuser 8434
			#設置錯誤識別
8435
			$result["status"]="false";
226 liveuser 8436
 
3 liveuser 8437
			#設置錯誤訊息
8438
			$result["error"]=$checkResult;
226 liveuser 8439
 
3 liveuser 8440
			#回傳結果
8441
			return $result;
226 liveuser 8442
 
3 liveuser 8443
			}#if end
226 liveuser 8444
 
3 liveuser 8445
		#取得轉換好的路徑
8446
		$conf["path"]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 8447
 
3 liveuser 8448
		#檢查檔案路徑字串是否含有「*」
8449
		#函式說明:
8450
		#檢查字串裡面有無指定的關鍵字
8451
		#回傳結果:
8452
		#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8453
		#$result["error"],錯誤訊息
8454
		#$result["function"],當前執行的函數名稱.
8455
		#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8456
		#$result["keyWordCount"],找到的關鍵字數量.
8457
		#必填參數:
8458
		$conf["search::findKeyWord"]["keyWord"]="*";#想要搜尋的關鍵字
8459
		$conf["search::findKeyWord"]["string"]=$conf["path"];#要被搜尋的字串內容
8460
		#可省略參數:
8461
		#$conf["fileAccess::findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8462
		$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8463
		unset($conf["search::findKeyWord"]);
226 liveuser 8464
 
3 liveuser 8465
		#如果尋找關鍵字出錯
8466
		if($findKeyWord["status"]=="false"){
226 liveuser 8467
 
3 liveuser 8468
			#設置錯誤識別
8469
			$result["status"]="false";
226 liveuser 8470
 
3 liveuser 8471
			#設置錯誤訊息
8472
			$result["error"]=$findKeyWord;
226 liveuser 8473
 
3 liveuser 8474
			#回傳結果
8475
			return $result;
226 liveuser 8476
 
3 liveuser 8477
			}#if end
226 liveuser 8478
 
3 liveuser 8479
		#如果含有「*」
8480
		if($findKeyWord["founded"]=="true"){
226 liveuser 8481
 
3 liveuser 8482
			#透過「/」分割路徑字串
8483
			#函式說明:
8484
			#將固定格式的字串分開,並回傳分開的結果。
8485
			#回傳的參數:
8486
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8487
			#$result["error"],錯誤訊息陣列
8488
			#$result["function"],當前執行的函數名稱.
8489
			#$result["oriStr"],要分割的原始字串內容
8490
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8491
			#$result["dataCounts"],爲總共分成幾段
8492
			#必填參數:
8493
			$conf["stringProcess::spiltString"]["stringIn"]=$conf["path"];#要處理的字串。
8494
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
8495
			$spiltPathStr=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8496
			unset($conf["stringProcess::spiltString"]);
226 liveuser 8497
 
3 liveuser 8498
			#如果分割字串失敗
8499
			if($spiltPathStr["status"]=="false"){
226 liveuser 8500
 
3 liveuser 8501
				#設置錯誤識別
8502
				$result["status"]="false";
226 liveuser 8503
 
3 liveuser 8504
				#設置錯誤訊息
8505
				$result["error"]=$spiltPathStr;
226 liveuser 8506
 
3 liveuser 8507
				#回傳結果
8508
				return $result;
226 liveuser 8509
 
3 liveuser 8510
				}#if end
226 liveuser 8511
 
3 liveuser 8512
			#初始化暫存展開後的檔案路徑字串
226 liveuser 8513
			$extendPath=array("");
8514
 
3 liveuser 8515
			#要解析的路徑分成幾段就執行幾次
8516
			foreach($spiltPathStr["dataArray"] as $pathPart){
226 liveuser 8517
 
3 liveuser 8518
				#檢查該段名稱是否有「*」
8519
				#函式說明:
8520
				#檢查字串裡面有無指定的關鍵字
8521
				#回傳結果:
8522
				#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8523
				#$result["error"],錯誤訊息
8524
				#$result["function"],當前執行的函數名稱.
8525
				#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8526
				#$result["keyWordCount"],找到的關鍵字數量.
8527
				#必填參數:
8528
				$conf["search::findKeyWord"]["keyWord"]="*";#想要搜尋的關鍵字
8529
				$conf["search::findKeyWord"]["string"]=$pathPart;#要被搜尋的字串內容
8530
				#可省略參數:
8531
				#$conf["fileAccess::findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8532
				$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8533
				unset($conf["search::findKeyWord"]);
226 liveuser 8534
 
3 liveuser 8535
				#如果尋找關鍵字出錯
8536
				if($findKeyWord["status"]=="false"){
226 liveuser 8537
 
3 liveuser 8538
					#設置錯誤識別
8539
					$result["status"]="false";
226 liveuser 8540
 
3 liveuser 8541
					#設置錯誤訊息
8542
					$result["error"]=$findKeyWord;
226 liveuser 8543
 
3 liveuser 8544
					#回傳結果
8545
					return $result;
226 liveuser 8546
 
8547
					}#if end
8548
 
3 liveuser 8549
				#如果不含「*」
8550
				if($findKeyWord["founded"]=="false"){
226 liveuser 8551
 
3 liveuser 8552
					#針對每個既有的路徑
8553
					for($i=0;$i<count($extendPath);$i++){
226 liveuser 8554
 
3 liveuser 8555
						#加上切割好的路徑
8556
						$extendPath[$i]=$extendPath[$i]."/".$pathPart;
226 liveuser 8557
 
3 liveuser 8558
						}#for end
226 liveuser 8559
 
3 liveuser 8560
					}#if end
226 liveuser 8561
 
8562
				#反之該段含有「*」
3 liveuser 8563
				else{
226 liveuser 8564
 
3 liveuser 8565
					#用「*」分割該段
8566
					#函式說明:
8567
					#將固定格式的字串分開,並回傳分開的結果。
8568
					#回傳的參數:
8569
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8570
					#$result["error"],錯誤訊息陣列
8571
					#$result["function"],當前執行的函數名稱.
8572
					#$result["oriStr"],要分割的原始字串內容
8573
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8574
					#$result["dataCounts"],爲總共分成幾段
8575
					#必填參數:
8576
					$conf["stringProcess::spiltString"]["stringIn"]=$pathPart;#要處理的字串。
8577
					$conf["stringProcess::spiltString"]["spiltSymbol"]="*";#爲以哪個符號作爲分割
8578
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8579
					unset($conf["stringProcess::spiltString"]);
226 liveuser 8580
 
3 liveuser 8581
					#如果分字串失敗
8582
					if($spiltString["status"]=="false"){
226 liveuser 8583
 
3 liveuser 8584
						#設置錯誤識別
8585
						$result["status"]="false";
226 liveuser 8586
 
3 liveuser 8587
						#設置錯誤訊息
8588
						$result["error"]=$spiltStringByStar;
226 liveuser 8589
 
3 liveuser 8590
						#回傳結果
8591
						return $result;
226 liveuser 8592
 
3 liveuser 8593
						}#if end
226 liveuser 8594
 
3 liveuser 8595
					#如果用「*」分割後的段數為0
8596
					if($spiltString["dataCounts"]==0){
226 liveuser 8597
 
3 liveuser 8598
						#初始化儲存符合條件的路徑
8599
						$newExtendPath=array();
226 liveuser 8600
 
3 liveuser 8601
						#代表沒有塞選條件
8602
						#當前有幾個符合條件的路徑就執行幾次
8603
						for($i=0;$i<count($extendPath);$i++){
226 liveuser 8604
 
3 liveuser 8605
							#取得該目錄下所有的東西
8606
							#取得該目錄底下的檔案目錄清單
8607
							#函式說明:
8608
							#取得目錄底下所有目錄與檔案清單.
8609
							#回傳結果:
8610
							#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8611
							#$result["error"],錯誤訊息陣列.
8612
							#$result["function"],函數名稱.
8613
							#$result["content"],陣列,目錄底下的檔案與子目錄.
8614
							#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
8615
							#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
8616
							#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
8617
							#$result["position"],目前的位置.
8618
							#必填參數:
8619
							#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
8620
							$conf["fileAccess::getList"]["position"]=$extendPath[$i];
8621
							#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8622
							$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
8623
							#可省略參數:
8624
							#無
8625
							#參考資料來源:
8626
							#opendir=>http://php.net/manual/en/function.opendir.php
8627
							#is_dir=>http://php.net/manual/en/function.is-dir.php
8628
							$getList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 8629
							unset($conf["fileAccess::getList"]);
8630
 
3 liveuser 8631
							#如果取得目標目錄底下的檔案目錄清單失敗
8632
							if($getList["status"]=="false"){
226 liveuser 8633
 
3 liveuser 8634
								#設置錯誤識別
8635
								$result["status"]="false";
226 liveuser 8636
 
3 liveuser 8637
								#設置錯誤訊息
226 liveuser 8638
								$result["error"]=$getList;
8639
 
3 liveuser 8640
								#回傳結果
8641
								return $result;
226 liveuser 8642
 
3 liveuser 8643
								}#if end
226 liveuser 8644
 
3 liveuser 8645
							#如果底下有東西
8646
							if(count($getList["content"])>0){
226 liveuser 8647
 
3 liveuser 8648
								#初始化儲存要檢查的檔案或資料夾名稱陣列
8649
								$list=array();
226 liveuser 8650
 
3 liveuser 8651
								#針對每個檔案或資料夾
8652
								foreach($getList["content"] as $num=>$array){
226 liveuser 8653
 
3 liveuser 8654
									#儲存該名稱
8655
									$list[]=$array["name"];
226 liveuser 8656
 
3 liveuser 8657
									}#foreach end
226 liveuser 8658
 
3 liveuser 8659
								#初始化儲存符合新條件字串的陣列
8660
								$tempExtendPath=array();
226 liveuser 8661
 
3 liveuser 8662
								#針對每個現有的路徑字串
8663
								for($j=0;$j<count($extendPath);$j++){
226 liveuser 8664
 
3 liveuser 8665
									#附加每個符合條件的名稱到路徑字串裡面
8666
									for($k=0;$k<count($list);$k++){
226 liveuser 8667
 
3 liveuser 8668
										#如果 $conf["noDotStart"] 為 "true"
8669
										if($conf["noDotStart"]==="true"){
226 liveuser 8670
 
3 liveuser 8671
											#將 $list[$k] 用 "/" 分割
8672
											#函式說明:
8673
											#將固定格式的字串分開,並回傳分開的結果。
8674
											#回傳結果:
8675
											#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8676
											#$result["error"],錯誤訊息陣列
8677
											#$result["function"],當前執行的函數名稱.
8678
											#$result["oriStr"],要分割的原始字串內容
8679
											#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8680
											#$result["dataCounts"],爲總共分成幾段
8681
											#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
8682
											#必填參數:
8683
											$conf["stringProcess::spiltString"]["stringIn"]=$list[$k];#要處理的字串。
8684
											$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
8685
											#可省略參數:
8686
											#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
8687
											$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
8688
											$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8689
											unset($conf["stringProcess::spiltString"]);
226 liveuser 8690
 
3 liveuser 8691
											#如果分割路徑失敗
8692
											if($spiltString["status"]==="false"){
226 liveuser 8693
 
3 liveuser 8694
												#設置執行錯誤識別
8695
												$result["status"]="false";
226 liveuser 8696
 
3 liveuser 8697
												#取得錯誤訊息
8698
												$result["error"]=$spiltString;
226 liveuser 8699
 
3 liveuser 8700
												#回傳結果
8701
												return $result;
226 liveuser 8702
 
3 liveuser 8703
												}#if end
226 liveuser 8704
 
3 liveuser 8705
											#如果有關鍵字「/」存在
8706
											if($spiltString["found"]==="true"){
226 liveuser 8707
 
3 liveuser 8708
												#針對每個段落
8709
												foreach($spiltString["dataArray"] as $pp){
226 liveuser 8710
 
3 liveuser 8711
													#看該符合的名稱開頭是否包含「.」
8712
													#函式說明:
8713
													#取得符合特定字首與字尾的字串
8714
													#回傳結果:
8715
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8716
													#$result["function"],當前執行的函數名稱.
8717
													#$result["error"],錯誤訊息陣列.
8718
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8719
													#$result["returnString"],爲符合字首條件的字串內容。
8720
													#必填參數:
8721
													#$conf["checkString"],字串,要檢查的字串.
8722
													$conf["search::getMeetConditionsString"]["checkString"]=$pp;
8723
													#可省略參數:
8724
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8725
													$conf["search::getMeetConditionsString"]["frontWord"]=".";
8726
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8727
													#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
8728
													#參考資料:
8729
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8730
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8731
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 8732
 
3 liveuser 8733
													#如果 取得符合特定字首的字串 出錯
8734
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 8735
 
3 liveuser 8736
														#設置執行錯誤識別
8737
														$result["status"]="false";
226 liveuser 8738
 
3 liveuser 8739
														#設置錯誤訊息
8740
														$result["error"]=$getMeetConditionsString;
226 liveuser 8741
 
3 liveuser 8742
														#回傳結果
8743
														return $result;
226 liveuser 8744
 
3 liveuser 8745
														}#if end
226 liveuser 8746
 
3 liveuser 8747
													#如果有「.」在開頭
8748
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8749
 
8750
														#忽略這個名稱
3 liveuser 8751
														continue 2;
226 liveuser 8752
 
3 liveuser 8753
														}#if end
226 liveuser 8754
 
3 liveuser 8755
													}#foreach end
226 liveuser 8756
 
3 liveuser 8757
												}#if end
226 liveuser 8758
 
3 liveuser 8759
											#反之沒有關鍵字「/」存在
8760
											else{
226 liveuser 8761
 
3 liveuser 8762
												#看該符合的名稱開頭是否包含「.」
8763
												#函式說明:
8764
												#取得符合特定字首與字尾的字串
8765
												#回傳結果:
8766
												#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8767
												#$result["function"],當前執行的函數名稱.
8768
												#$result["error"],錯誤訊息陣列.
8769
												#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8770
												#$result["returnString"],爲符合字首條件的字串內容。
8771
												#必填參數:
8772
												#$conf["checkString"],字串,要檢查的字串.
8773
												$conf["search::getMeetConditionsString"]["checkString"]=$list[$k];
8774
												#可省略參數:
8775
												#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8776
												$conf["search::getMeetConditionsString"]["frontWord"]=".";
8777
												#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8778
												#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
8779
												#參考資料:
8780
												#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8781
												$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8782
												unset($conf["search::getMeetConditionsString"]);
226 liveuser 8783
 
3 liveuser 8784
												#如果 取得符合特定字首的字串 出錯
8785
												if($getMeetConditionsString["status"]=="false"){
226 liveuser 8786
 
3 liveuser 8787
													#設置執行錯誤識別
8788
													$result["status"]="false";
226 liveuser 8789
 
3 liveuser 8790
													#設置錯誤訊息
8791
													$result["error"]=$getMeetConditionsString;
226 liveuser 8792
 
3 liveuser 8793
													#回傳結果
8794
													return $result;
226 liveuser 8795
 
3 liveuser 8796
													}#if end
226 liveuser 8797
 
3 liveuser 8798
												#如果有「.」在開頭
8799
												if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8800
 
8801
													#忽略這個名稱
3 liveuser 8802
													continue;
226 liveuser 8803
 
3 liveuser 8804
													}#if end
226 liveuser 8805
 
3 liveuser 8806
												}#else end
226 liveuser 8807
 
3 liveuser 8808
											}#if end
226 liveuser 8809
 
3 liveuser 8810
										#如果 $conf["noWaveEnd"] 為 "true"
8811
										if($conf["noWaveEnd"]==="true"){
226 liveuser 8812
 
3 liveuser 8813
											#看該符合的名稱結尾是否包含「~」
8814
											#函式說明:
8815
											#取得符合特定字首與字尾的字串
8816
											#回傳結果:
8817
											#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8818
											#$result["function"],當前執行的函數名稱.
8819
											#$result["error"],錯誤訊息陣列.
8820
											#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8821
											#$result["returnString"],爲符合字首條件的字串內容。
8822
											#必填參數:
8823
											#$conf["checkString"],字串,要檢查的字串.
8824
											$conf["search::getMeetConditionsString"]["checkString"]=$list[$k];
8825
											#可省略參數:
8826
											#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8827
											#$conf["search::getMeetConditionsString"]["frontWord"]=".";
8828
											#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8829
											$conf["search::getMeetConditionsString"]["tailWord"]="~";
8830
											#參考資料:
8831
											#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8832
											$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8833
											unset($conf["search::getMeetConditionsString"]);
226 liveuser 8834
 
3 liveuser 8835
											#如果 取得符合特定字首的字串 出錯
8836
											if($getMeetConditionsString["status"]=="false"){
226 liveuser 8837
 
3 liveuser 8838
												#設置執行錯誤識別
8839
												$result["status"]="false";
226 liveuser 8840
 
3 liveuser 8841
												#設置錯誤訊息
8842
												$result["error"]=$getMeetConditionsString;
226 liveuser 8843
 
3 liveuser 8844
												#回傳結果
8845
												return $result;
226 liveuser 8846
 
3 liveuser 8847
												}#if end
226 liveuser 8848
 
3 liveuser 8849
											#如果有「~」在結尾
8850
											if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8851
 
3 liveuser 8852
												#忽略這個名稱
8853
												continue;
226 liveuser 8854
 
3 liveuser 8855
												}#if end
226 liveuser 8856
 
3 liveuser 8857
											}#if end
226 liveuser 8858
 
3 liveuser 8859
										#暫存該符合的路徑
8860
										$tempExtendPath[]=$extendPath[$j]."/".$list[$k];
226 liveuser 8861
 
3 liveuser 8862
										}#for end
226 liveuser 8863
 
8864
									}#for end
8865
 
3 liveuser 8866
								#該次有幾個符合的路徑就執行幾次
8867
								foreach($tempExtendPath as $path){
226 liveuser 8868
 
3 liveuser 8869
									#暫存符合的路徑
8870
									$newExtendPath[]=$path;
226 liveuser 8871
 
8872
									}#for end
8873
 
3 liveuser 8874
								}#if end
226 liveuser 8875
 
3 liveuser 8876
							#反之該目錄底下沒有東西
8877
							else{
226 liveuser 8878
 
3 liveuser 8879
								#移除該 $extendPath[$i]
8880
								unset($extendPath[$i]);
226 liveuser 8881
 
8882
								}#else end
8883
 
3 liveuser 8884
							}#for end
226 liveuser 8885
 
3 liveuser 8886
						#置換原始符合條件字串的路徑字串陣列
8887
						$extendPath=$newExtendPath;
226 liveuser 8888
 
3 liveuser 8889
						}#if end
226 liveuser 8890
 
3 liveuser 8891
						#反之用「*」分割後有分段
8892
						else{
226 liveuser 8893
 
3 liveuser 8894
							#初始化暫存符合條件的新路徑陣列變數
8895
							$newExtendPath=array();
226 liveuser 8896
 
3 liveuser 8897
							#當前有幾個符合條件的路徑就執行幾次
8898
							for($i=0;$i<count($extendPath);$i++){
226 liveuser 8899
 
3 liveuser 8900
								#取得該目錄下所有的東西
8901
								#函式說明:
8902
								#取得目錄底下所有目錄與檔案清單.
8903
								#回傳結果:
8904
								#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8905
								#$result["error"],錯誤訊息陣列.
8906
								#$result["function"],函數名稱.
8907
								#$result["content"],陣列,目錄底下的檔案與子目錄.
8908
								#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
8909
								#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
8910
								#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
8911
								#$result["position"],目前的位置.
8912
								#必填參數:
8913
								#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
8914
								$conf["fileAccess::getList"]["position"]=$extendPath[$i];
8915
								#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8916
								$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
8917
								#可省略參數:
8918
								#無
8919
								#參考資料來源:
8920
								#opendir=>http://php.net/manual/en/function.opendir.php
8921
								#is_dir=>http://php.net/manual/en/function.is-dir.php
8922
								$getList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 8923
								unset($conf["fileAccess::getList"]);
8924
 
3 liveuser 8925
								#如果取得目標目錄底下的檔案目錄清單失敗
8926
								if($getList["status"]=="false"){
226 liveuser 8927
 
3 liveuser 8928
									#設置錯誤識別
8929
									$result["status"]="false";
226 liveuser 8930
 
3 liveuser 8931
									#設置錯誤訊息
226 liveuser 8932
									$result["error"]=$getList;
8933
 
3 liveuser 8934
									#回傳結果
8935
									return $result;
226 liveuser 8936
 
3 liveuser 8937
									}#if end
226 liveuser 8938
 
3 liveuser 8939
								#如果底下有東西
8940
								if(count($getList["content"])>0){
226 liveuser 8941
 
3 liveuser 8942
									#初始化儲存要檢查的檔案或資料夾名稱陣列
8943
									$list=array();
226 liveuser 8944
 
3 liveuser 8945
									#針對每個檔案或資料夾
8946
									foreach($getList["content"] as $num=>$array){
226 liveuser 8947
 
3 liveuser 8948
										#儲存該名稱
8949
										$list[]=$array["name"];
226 liveuser 8950
 
3 liveuser 8951
										}#foreach end
226 liveuser 8952
 
3 liveuser 8953
									#初始化儲存符合的名稱
8954
									$passedName=array();
226 liveuser 8955
 
3 liveuser 8956
									#依據每個檔案目錄名稱,檢查有無符合篩選條件
8957
									foreach($list as $filteredName){
226 liveuser 8958
 
3 liveuser 8959
										#初始化儲存被檢查的片段檔案資料夾名稱
8960
										$partName=$filteredName;
226 liveuser 8961
 
3 liveuser 8962
										#依據 $pathPart 分割成幾段(關鍵字數量)就執行幾次
8963
										for($i=0;$i<$spiltString["dataCounts"];$i++){
226 liveuser 8964
 
3 liveuser 8965
											#尋找關鍵字 $spiltString["dataArray"][$i]
8966
											#函式說明:
8967
											#檢查字串裡面有無指定的關鍵字
8968
											#回傳結果:
8969
											#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8970
											#$result["error"],錯誤訊息
8971
											#$result["function"],當前執行的函數名稱.
8972
											#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8973
											#$result["keyWordCount"],找到的關鍵字數量.
8974
											#必填參數:
8975
											$conf["search::findKeyWord"]["keyWord"]=$spiltString["dataArray"][$i];#想要搜尋的關鍵字
8976
											$conf["search::findKeyWord"]["string"]=$partName;#要被搜尋的字串內容
8977
											#可省略參數:
8978
											#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8979
											$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8980
											unset($conf["search::findKeyWord"]);
226 liveuser 8981
 
3 liveuser 8982
											#如果尋找關鍵字失敗
8983
											if($findKeyWord["status"]=="false"){
226 liveuser 8984
 
3 liveuser 8985
												#設置執行錯誤識別
8986
												$result["status"]="false";
226 liveuser 8987
 
3 liveuser 8988
												#設置錯誤訊息
8989
												$result["error"]=$findKeyWord;
226 liveuser 8990
 
3 liveuser 8991
												#回傳結果
8992
												return $result;
226 liveuser 8993
 
3 liveuser 8994
												}#if end
226 liveuser 8995
 
3 liveuser 8996
											#如果有找到關鍵字
8997
											if($findKeyWord["founded"]=="true"){
226 liveuser 8998
 
3 liveuser 8999
												#如果是最後一段要檢查的關鍵字
9000
												if($i==$spiltString["dataCounts"]-1){
226 liveuser 9001
 
3 liveuser 9002
													#判斷該關鍵字是否在該未分割的 $pathPart(含有*字號的關鍵字字串) 的開頭
9003
													#函式說明:
9004
													#取得符合特定字首與字尾的字串
9005
													#回傳結果:
9006
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9007
													#$result["function"],當前執行的函數名稱.
9008
													#$result["error"],錯誤訊息陣列.
9009
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9010
													#$result["returnString"],爲符合字首條件的字串內容。
9011
													#必填參數:
9012
													#$conf["checkString"],字串,要檢查的字串.
9013
													$conf["search::getMeetConditionsString"]["checkString"]=$pathPart;
9014
													#可省略參數:
9015
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9016
													$conf["search::getMeetConditionsString"]["frontWord"]=$spiltString["dataArray"][0];
9017
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9018
													#$conf["tailWord"]="";
9019
													#參考資料:
9020
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9021
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9022
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 9023
 
3 liveuser 9024
													#如果 取得符合特定字首的字串 出錯
9025
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 9026
 
3 liveuser 9027
														#設置執行錯誤識別
9028
														$result["status"]="false";
226 liveuser 9029
 
3 liveuser 9030
														#設置錯誤訊息
9031
														$result["error"]=$getMeetConditionsString;
226 liveuser 9032
 
3 liveuser 9033
														#回傳結果
9034
														return $result;
226 liveuser 9035
 
3 liveuser 9036
														}#if end
226 liveuser 9037
 
3 liveuser 9038
													#如果關鍵字是在開頭
9039
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9040
 
3 liveuser 9041
														#判斷關鍵字是否在該檔案目錄名稱的開頭
9042
														#函式說明:
9043
														#取得符合特定字首與字尾的字串
9044
														#回傳結果:
9045
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9046
														#$result["function"],當前執行的函數名稱.
9047
														#$result["error"],錯誤訊息陣列.
9048
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9049
														#$result["returnString"],爲符合字首條件的字串內容。
9050
														#必填參數:
9051
														#$conf["checkString"],字串,要檢查的字串.
9052
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9053
														#可省略參數:
9054
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9055
														$conf["search::getMeetConditionsString"]["frontWord"]=$spiltString["dataArray"][0];
9056
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9057
														#$conf["tailWord"]="";
9058
														#參考資料:
9059
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9060
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9061
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9062
 
3 liveuser 9063
														#如果 取得符合特定字首的字串 出錯
9064
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9065
 
3 liveuser 9066
															#設置執行錯誤識別
9067
															$result["status"]="false";
226 liveuser 9068
 
3 liveuser 9069
															#設置錯誤訊息
9070
															$result["error"]=$getMeetConditionsString;
226 liveuser 9071
 
3 liveuser 9072
															#回傳結果
9073
															return $result;
226 liveuser 9074
 
3 liveuser 9075
															}#if end
226 liveuser 9076
 
3 liveuser 9077
														#如果關鍵字不在開頭
9078
														if($getMeetConditionsString["founded"]=="false"){
226 liveuser 9079
 
3 liveuser 9080
															#不符合條件,跳過該檔案目錄名稱
9081
															break;
226 liveuser 9082
 
3 liveuser 9083
															}#if end
226 liveuser 9084
 
3 liveuser 9085
														}#if end
226 liveuser 9086
 
3 liveuser 9087
													#判斷最後一個關鍵字是否在該未分割的 $pathPart(含有*字號的關鍵字字串) 的結尾
9088
													#函式說明:
9089
													#取得符合特定字首與字尾的字串
9090
													#回傳結果:
9091
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9092
													#$result["function"],當前執行的函數名稱.
9093
													#$result["error"],錯誤訊息陣列.
9094
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9095
													#$result["returnString"],爲符合字首條件的字串內容。
9096
													#必填參數:
9097
													#$conf["checkString"],字串,要檢查的字串.
9098
													$conf["search::getMeetConditionsString"]["checkString"]=$pathPart;
9099
													#可省略參數:
9100
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9101
													#$conf["search::getMeetConditionsString"]["frontWord"]=$partName;
9102
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9103
													$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9104
													#參考資料:
9105
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9106
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9107
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 9108
 
3 liveuser 9109
													#如果 取得符合特定字尾的字串 出錯
9110
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 9111
 
3 liveuser 9112
														#設置執行錯誤識別
9113
														$result["status"]="false";
226 liveuser 9114
 
3 liveuser 9115
														#設置錯誤訊息
9116
														$result["error"]=$getMeetConditionsString;
226 liveuser 9117
 
3 liveuser 9118
														#回傳結果
9119
														return $result;
226 liveuser 9120
 
3 liveuser 9121
														}#if end
226 liveuser 9122
 
3 liveuser 9123
													#如果關鍵字是在字尾
9124
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9125
 
3 liveuser 9126
														#判斷關鍵字是否在該片段的開頭
9127
														#函式說明:
9128
														#取得符合特定字首與字尾的字串
9129
														#回傳結果:
9130
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9131
														#$result["function"],當前執行的函數名稱.
9132
														#$result["error"],錯誤訊息陣列.
9133
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9134
														#$result["returnString"],爲符合字首條件的字串內容。
9135
														#必填參數:
9136
														#$conf["checkString"],字串,要檢查的字串.
9137
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9138
														#可省略參數:
9139
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9140
														#$conf["search::getMeetConditionsString"]["frontWord"]=$partName;
9141
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9142
														$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9143
														#參考資料:
9144
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9145
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9146
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9147
 
3 liveuser 9148
														#如果 取得符合特定字首的字串 出錯
9149
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9150
 
3 liveuser 9151
															#設置執行錯誤識別
9152
															$result["status"]="false";
226 liveuser 9153
 
3 liveuser 9154
															#設置錯誤訊息
9155
															$result["error"]=$getMeetConditionsString;
226 liveuser 9156
 
3 liveuser 9157
															#回傳結果
9158
															return $result;
226 liveuser 9159
 
3 liveuser 9160
															}#if end
226 liveuser 9161
 
3 liveuser 9162
														#如果關鍵字不在結尾
9163
														if($getMeetConditionsString["founded"]=="false"){
226 liveuser 9164
 
3 liveuser 9165
															#不符合條件,跳過該檔案目錄名稱
9166
															break;
226 liveuser 9167
 
3 liveuser 9168
															}#if end
226 liveuser 9169
 
3 liveuser 9170
														}#if end
226 liveuser 9171
 
3 liveuser 9172
													#如果 $conf["noDotStart"] 為 "true"
9173
													if($conf["noDotStart"]==="true"){
226 liveuser 9174
 
3 liveuser 9175
														#看該符合的名稱開頭是否包含「.」
9176
														#函式說明:
9177
														#取得符合特定字首與字尾的字串
9178
														#回傳結果:
9179
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9180
														#$result["function"],當前執行的函數名稱.
9181
														#$result["error"],錯誤訊息陣列.
9182
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9183
														#$result["returnString"],爲符合字首條件的字串內容。
9184
														#必填參數:
9185
														#$conf["checkString"],字串,要檢查的字串.
9186
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9187
														#可省略參數:
9188
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9189
														$conf["search::getMeetConditionsString"]["frontWord"]=".";
9190
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9191
														#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9192
														#參考資料:
9193
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9194
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9195
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9196
 
3 liveuser 9197
														#如果 取得符合特定字首的字串 出錯
9198
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9199
 
3 liveuser 9200
															#設置執行錯誤識別
9201
															$result["status"]="false";
226 liveuser 9202
 
3 liveuser 9203
															#設置錯誤訊息
9204
															$result["error"]=$getMeetConditionsString;
226 liveuser 9205
 
3 liveuser 9206
															#回傳結果
9207
															return $result;
226 liveuser 9208
 
3 liveuser 9209
															}#if end
226 liveuser 9210
 
3 liveuser 9211
														#如果有「.」在開頭
9212
														if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9213
 
3 liveuser 9214
															#中斷迴圈
9215
															break;
226 liveuser 9216
 
3 liveuser 9217
															}#if end
226 liveuser 9218
 
3 liveuser 9219
														}#if end
226 liveuser 9220
 
3 liveuser 9221
													#如果 $conf["noWaveEnd"] 為 "true"
9222
													if($conf["noWaveEnd"]==="true"){
226 liveuser 9223
 
3 liveuser 9224
														#看該符合的名稱結尾是否包含「~」
9225
														#函式說明:
9226
														#取得符合特定字首與字尾的字串
9227
														#回傳結果:
9228
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9229
														#$result["function"],當前執行的函數名稱.
9230
														#$result["error"],錯誤訊息陣列.
9231
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9232
														#$result["returnString"],爲符合字首條件的字串內容。
9233
														#必填參數:
9234
														#$conf["checkString"],字串,要檢查的字串.
9235
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9236
														#可省略參數:
9237
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9238
														#$conf["search::getMeetConditionsString"]["frontWord"]=".";
9239
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9240
														$conf["search::getMeetConditionsString"]["tailWord"]="~";
9241
														#參考資料:
9242
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9243
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9244
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9245
 
3 liveuser 9246
														#如果 取得符合特定字首的字串 出錯
9247
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9248
 
3 liveuser 9249
															#設置執行錯誤識別
9250
															$result["status"]="false";
226 liveuser 9251
 
3 liveuser 9252
															#設置錯誤訊息
9253
															$result["error"]=$getMeetConditionsString;
226 liveuser 9254
 
3 liveuser 9255
															#回傳結果
9256
															return $result;
226 liveuser 9257
 
3 liveuser 9258
															}#if end
226 liveuser 9259
 
3 liveuser 9260
														#如果有「~」在結尾
9261
														if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9262
 
3 liveuser 9263
															#中斷迴圈
9264
															break;
226 liveuser 9265
 
3 liveuser 9266
															}#if end
226 liveuser 9267
 
3 liveuser 9268
														}#if end
226 liveuser 9269
 
3 liveuser 9270
													#取得該符合的名稱
9271
													$passedName[]=$filteredName;
226 liveuser 9272
 
3 liveuser 9273
													#中斷迴圈
9274
													break;
226 liveuser 9275
 
3 liveuser 9276
													}#if end
226 liveuser 9277
 
3 liveuser 9278
												#將 $partName 從左到關鍵字結束的部份剔除
9279
												#函式說明:
9280
												#將特定字串前面的內容剔除
9281
												#回傳結果:
9282
												#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9283
												#$result["error"],錯誤訊息陣列.
9284
												#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
9285
												#$result["function"],當前執行的函數名稱.
9286
												#$result["oriStr"],要處理的原始字串內容.
9287
												#$result["content"],處理好的的字串內容.
9288
												#必填參數:
9289
												$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$partName;#要處理的字串.
9290
												$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$spiltString["dataArray"][$i];#特定字串.
9291
												$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
9292
												unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 9293
 
3 liveuser 9294
												#如果將 $partName 從左到關鍵字結束的部份剔除失敗
9295
												if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 9296
 
3 liveuser 9297
													#設置執行錯誤識別
9298
													$result["status"]="false";
226 liveuser 9299
 
3 liveuser 9300
													#設置錯誤訊息
9301
													$result["error"]=$delStrBeforeKeyWord;
226 liveuser 9302
 
3 liveuser 9303
													#回傳結果
9304
													return $result;
226 liveuser 9305
 
3 liveuser 9306
													}#if end
226 liveuser 9307
 
3 liveuser 9308
												#如果沒有找到特定關鍵字字串
9309
												if($delStrBeforeKeyWord["founded"]=="false"){
226 liveuser 9310
 
3 liveuser 9311
													#設置執行錯誤識別
9312
													$result["status"]="false";
226 liveuser 9313
 
3 liveuser 9314
													#設置錯誤訊息
9315
													$result["error"]=$delStrBeforeKeyWord;
226 liveuser 9316
 
3 liveuser 9317
													#回傳結果
9318
													return $result;
226 liveuser 9319
 
3 liveuser 9320
													}#if end
226 liveuser 9321
 
9322
												#取得剔除過關鍵字前字串的字串
3 liveuser 9323
												$partName=$delStrBeforeKeyWord["content"];
226 liveuser 9324
 
3 liveuser 9325
												}#if end
226 liveuser 9326
 
9327
											#反之關鍵字不存在
3 liveuser 9328
											else{
226 liveuser 9329
 
3 liveuser 9330
												#儲存被拋棄的片段
9331
												#$result["dismissLog"][]="片段「".$partName."」沒有關鍵字「".$spiltString["dataArray"][$i]."」";
226 liveuser 9332
 
3 liveuser 9333
												#該名稱不符合條件
9334
												break;
226 liveuser 9335
 
3 liveuser 9336
												}#else end
226 liveuser 9337
 
3 liveuser 9338
											}#for end
226 liveuser 9339
 
3 liveuser 9340
										}#foreach end
226 liveuser 9341
 
3 liveuser 9342
									#初始化儲存符合的暫存路徑
9343
									$tempExtendPath=array();
226 liveuser 9344
 
3 liveuser 9345
									#針對每個現有的路徑字串
9346
									for($j=0;$j<count($extendPath);$j++){
226 liveuser 9347
 
3 liveuser 9348
										#附加每個符合條件的名稱到路徑字串裡面
9349
										for($k=0;$k<count($passedName);$k++){
226 liveuser 9350
 
3 liveuser 9351
											#暫存該符合的路徑
9352
											$tempExtendPath[]=$extendPath[$j]."/".$passedName[$k];
226 liveuser 9353
 
3 liveuser 9354
											}#for end
226 liveuser 9355
 
9356
										}#for end
9357
 
3 liveuser 9358
									#該次有幾個符合的路徑就執行幾次
9359
									foreach($tempExtendPath as $path){
226 liveuser 9360
 
3 liveuser 9361
										#暫存符合的路徑
9362
										$newExtendPath[]=$path;
226 liveuser 9363
 
9364
										}#foreach end
9365
 
3 liveuser 9366
									}#if end
226 liveuser 9367
 
3 liveuser 9368
								#反之該目錄底下沒有東西
9369
								else{
226 liveuser 9370
 
3 liveuser 9371
									#移除該 $extendPath[$i]
9372
									unset($extendPath[$i]);
226 liveuser 9373
 
9374
									}#else end
9375
 
3 liveuser 9376
								}#for end
226 liveuser 9377
 
3 liveuser 9378
							#如果有新的路徑產生
9379
							if(count($newExtendPath)>0){
226 liveuser 9380
 
3 liveuser 9381
								#置換原始符合條件字串的路徑字串陣列
9382
								$extendPath=$newExtendPath;
226 liveuser 9383
 
3 liveuser 9384
								}#if end
226 liveuser 9385
 
3 liveuser 9386
							#反之找不到後續符合的路徑
9387
							else{
226 liveuser 9388
 
3 liveuser 9389
								$extendPath=array();
226 liveuser 9390
 
3 liveuser 9391
								}#else end
226 liveuser 9392
 
3 liveuser 9393
							}#else end
226 liveuser 9394
 
3 liveuser 9395
					}#else end
226 liveuser 9396
 
3 liveuser 9397
				}#foreach end
226 liveuser 9398
 
3 liveuser 9399
			}#if end
226 liveuser 9400
 
3 liveuser 9401
		#反之沒有含有「*」
9402
		else{
226 liveuser 9403
 
3 liveuser 9404
			#判斷 $conf["path"] 是否存在
9405
			#函式說明:
9406
			#檢查多個檔案與資料夾是否存在.
9407
			#回傳的結果:
9408
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
9409
			#$result["error"],錯誤訊息陣列.
9410
			#$resutl["function"],當前執行的涵式名稱.
9411
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
9412
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
9413
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
9414
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
9415
			#必填參數:
9416
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
9417
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["path"]);
9418
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9419
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
9420
			#可省略參數
9421
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
9422
			#$conf["disableWebSearch"]="false";
9423
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
9424
			#$conf["userDir"]="true";
9425
			#參考資料來源:
9426
			#http://php.net/manual/en/function.file-exists.php
9427
			#http://php.net/manual/en/control-structures.foreach.php
9428
			#備註:
9429
			#函數file_exists檢查的路徑為檔案系統的路徑
9430
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
9431
			unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 9432
 
3 liveuser 9433
			#如果檢查失敗
9434
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 9435
 
3 liveuser 9436
				#設置錯誤識別
9437
				$result["status"]="false";
226 liveuser 9438
 
3 liveuser 9439
				#設置錯誤訊息
9440
				$result["error"]=$checkMultiFileExist;
226 liveuser 9441
 
3 liveuser 9442
				#回傳結果
9443
				return $result;
226 liveuser 9444
 
3 liveuser 9445
				}#if end
226 liveuser 9446
 
3 liveuser 9447
			#如果存在
9448
			if($checkMultiFileExist["varExist"][0]=="true"){
226 liveuser 9449
 
3 liveuser 9450
				#初始化暫存展開後的檔案路徑字串
9451
				$extendPath=array($conf["path"]);
226 liveuser 9452
 
3 liveuser 9453
				}#if end
226 liveuser 9454
 
3 liveuser 9455
			#反之不存在
9456
			else{
226 liveuser 9457
 
3 liveuser 9458
				#置換符合的路徑為空字串
9459
				$extendPath=array();
226 liveuser 9460
 
3 liveuser 9461
				}#else end
226 liveuser 9462
 
3 liveuser 9463
			#初始化暫存展開後的檔案路徑字串
9464
			$extendPath=array($conf["path"]);
226 liveuser 9465
 
3 liveuser 9466
			}#else end
226 liveuser 9467
 
3 liveuser 9468
		#取得解析完「*」的檔案路徑字串
9469
		$result["content"]=$extendPath;
226 liveuser 9470
 
3 liveuser 9471
		#取得有幾個檔案路徑
9472
		$result["pathCount"]=count($result["content"]);
226 liveuser 9473
 
3 liveuser 9474
		#設置執行正常
9475
		$result["status"]="true";
226 liveuser 9476
 
3 liveuser 9477
		#回傳結果
9478
		return $result;
226 liveuser 9479
 
3 liveuser 9480
		}#function resolvePostionStringWhichContainStarSymbol end
9481
 
9482
	/*
9483
	#函式說明:
9484
	#將含有「*」的多個檔案路徑名稱,變成多個符合條件的路徑檔案.
9485
	#回傳結果:
9486
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9487
	#$result["error"],錯誤訊息陣列.
226 liveuser 9488
	#$result["function"],函數名稱.
3 liveuser 9489
	#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
9490
	#$result["pathCount"],整數,有幾個路徑.
9491
	#必填參數:
9492
	#$conf["path"],字串陣列,要解析含有「*」的檔案路徑字串.
9493
	$conf["path"]=array();
9494
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
9495
	$conf["fileArgu"]=__FILE__;
9496
	#可省略參數:
9497
	#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
9498
	#$conf["noDotStart"]="true";
9499
	#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
9500
	#$conf["noWaveEnd"]="true";
9501
	#參考資料:
9502
	#無.
9503
	#備註:
9504
	#無.
9505
	*/
9506
	public static function resolveMultiPostionStringWhichContainStarSymbol(&$conf){
226 liveuser 9507
 
3 liveuser 9508
		#初始化要回傳的結果
9509
		$result=array();
226 liveuser 9510
 
3 liveuser 9511
		#設置當其函數名稱
9512
		$result["function"]=__FUNCTION__;
226 liveuser 9513
 
3 liveuser 9514
		#如果 $conf 不為陣列
9515
		if(gettype($conf)!="array"){
226 liveuser 9516
 
3 liveuser 9517
			#設置執行失敗
9518
			$result["status"]="false";
226 liveuser 9519
 
3 liveuser 9520
			#設置執行錯誤訊息
9521
			$result["error"][]="\$conf變數須為陣列形態";
9522
 
9523
			#如果傳入的參數為 null
9524
			if($conf==null){
226 liveuser 9525
 
3 liveuser 9526
				#設置執行錯誤訊息
9527
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 9528
 
3 liveuser 9529
				}#if end
9530
 
9531
			#回傳結果
9532
			return $result;
226 liveuser 9533
 
3 liveuser 9534
			}#if end
226 liveuser 9535
 
3 liveuser 9536
		#檢查參數
9537
		#函式說明:
9538
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
9539
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9540
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9541
		#$result["function"],當前執行的函式名稱.
9542
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9543
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9544
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9545
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
9546
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9547
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9548
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9549
		#必填寫的參數:
9550
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9551
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9552
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9553
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 9554
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 9555
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
9556
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9557
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9558
		#可以省略的參數:
9559
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
9560
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9561
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9562
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noDotStart","noWaveEnd");
226 liveuser 9563
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 9564
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
9565
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9566
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","true");
9567
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9568
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
9569
		#參考資料來源:
9570
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9571
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9572
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 9573
 
3 liveuser 9574
		#如果 $checkResult["status"] 等於 "fasle"
9575
		if($checkResult["status"]=="false"){
226 liveuser 9576
 
3 liveuser 9577
			#設置錯誤識別
9578
			$result["status"]="false";
226 liveuser 9579
 
3 liveuser 9580
			#設置錯誤訊息
9581
			$result["error"]=$checkResult;
226 liveuser 9582
 
3 liveuser 9583
			#回傳結果
9584
			return $result;
226 liveuser 9585
 
3 liveuser 9586
			}#if end
226 liveuser 9587
 
3 liveuser 9588
		#如果 $checkResult["passed"] 等於 "fasle"
9589
		if($checkResult["passed"]=="false"){
226 liveuser 9590
 
3 liveuser 9591
			#設置錯誤識別
9592
			$result["status"]="false";
226 liveuser 9593
 
3 liveuser 9594
			#設置錯誤訊息
9595
			$result["error"]=$checkResult;
226 liveuser 9596
 
3 liveuser 9597
			#回傳結果
9598
			return $result;
226 liveuser 9599
 
3 liveuser 9600
			}#if end
226 liveuser 9601
 
3 liveuser 9602
		#針對每個要解析的路徑字串
9603
		foreach($conf["path"] as $path){
226 liveuser 9604
 
3 liveuser 9605
			#函式說明:
9606
			#將含有「*」的檔案路徑名稱,變成多個符合條件的路徑檔案.
9607
			#回傳結果:
9608
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9609
			#$result["error"],錯誤訊息陣列.
226 liveuser 9610
			#$result["function"],函數名稱.
3 liveuser 9611
			#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
9612
			#必填參數:
9613
			#$conf["path"],字串,要解析含有「*」的檔案路徑字串.
9614
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["path"]=$path;
9615
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
9616
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["fileArgu"]=$conf["fileArgu"];
9617
			#可省略參數:
9618
			#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
9619
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["noDotStart"]=$conf["noDotStart"];
9620
			#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
9621
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["noWaveEnd"]=$conf["noWaveEnd"];
9622
			$resolvePostionStringWhichContainStarSymbol=fileAccess::resolvePostionStringWhichContainStarSymbol($conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]);
9623
			unset($conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]);
226 liveuser 9624
 
3 liveuser 9625
			#如果解析失敗
9626
			if($resolvePostionStringWhichContainStarSymbol["status"]=="false"){
226 liveuser 9627
 
3 liveuser 9628
				#設置錯誤識別
9629
				$result["status"]="false";
226 liveuser 9630
 
3 liveuser 9631
				#設置錯誤訊息
9632
				$result["error"]=$resolvePostionStringWhichContainStarSymbol;
226 liveuser 9633
 
3 liveuser 9634
				#回傳結果
9635
				return $result;
226 liveuser 9636
 
3 liveuser 9637
				}#if end
226 liveuser 9638
 
3 liveuser 9639
			#針對每個解析出來的路徑
9640
			foreach($resolvePostionStringWhichContainStarSymbol["content"] as $filteredPath){
226 liveuser 9641
 
3 liveuser 9642
				#儲存符合條件的路徑
9643
				$result["content"][]=$filteredPath;
226 liveuser 9644
 
3 liveuser 9645
				}#foreach end
226 liveuser 9646
 
3 liveuser 9647
			}#foreach end
226 liveuser 9648
 
3 liveuser 9649
		#如果有路徑存在
9650
		if(isset($result["content"])){
226 liveuser 9651
 
3 liveuser 9652
			#取得有幾個路徑
9653
			$result["pathCount"]=count($result["content"]);
226 liveuser 9654
 
3 liveuser 9655
			}#if end
226 liveuser 9656
 
9657
		#反之
3 liveuser 9658
		else{
226 liveuser 9659
 
3 liveuser 9660
			#設置空的路徑結果
9661
			$result["content"]=array();
226 liveuser 9662
 
3 liveuser 9663
			#取得有幾個路徑
9664
			$result["pathCount"]=count($result["content"]);
226 liveuser 9665
 
3 liveuser 9666
			}#else end
226 liveuser 9667
 
3 liveuser 9668
		#設置執行正常
9669
		$result["status"]="true";
226 liveuser 9670
 
3 liveuser 9671
		#回傳結果
9672
		return $result;
226 liveuser 9673
 
3 liveuser 9674
		}#function resolveMultiPostionStringWhichContainStarSymbol end
9675
 
9676
	/*
9677
	#函式說明:
9678
	#將多個路徑字串變成相對於當前路徑的相對路徑字串
9679
	#回傳結果:
9680
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9681
	#$result["error"],錯誤訊息陣列.
226 liveuser 9682
	#$result["function"],函數名稱.
3 liveuser 9683
	#$result["argu"],使用的參數.
9684
	#$result["content"],字串陣列,多個轉換好的相對路徑字串.
9685
	#$result["cmd"],使用的指令.
9686
	#必填參數:
9687
	#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
9688
	$conf["path"]=array();
9689
	#$conf["fileArgu"],字串,當前路徑.
9690
	$conf["fileArgu"]=__FILE__;
9691
	#可省略參數:
9692
	#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
9693
	#$conf["baseFrom"]="";
9694
	#參考資料:
9695
	#無.
9696
	#備註:
9697
	#無.
9698
	*/
9699
	public static function getRelativePath(&$conf){
226 liveuser 9700
 
3 liveuser 9701
		#初始化要回傳的結果
9702
		$result=array();
226 liveuser 9703
 
3 liveuser 9704
		#設置當其函數名稱
9705
		$result["function"]=__FUNCTION__;
226 liveuser 9706
 
3 liveuser 9707
		#如果 $conf 不為陣列
9708
		if(gettype($conf)!="array"){
226 liveuser 9709
 
3 liveuser 9710
			#設置執行失敗
9711
			$result["status"]="false";
226 liveuser 9712
 
3 liveuser 9713
			#設置執行錯誤訊息
9714
			$result["error"][]="\$conf變數須為陣列形態";
9715
 
9716
			#如果傳入的參數為 null
9717
			if($conf==null){
226 liveuser 9718
 
3 liveuser 9719
				#設置執行錯誤訊息
9720
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 9721
 
3 liveuser 9722
				}#if end
9723
 
9724
			#回傳結果
9725
			return $result;
226 liveuser 9726
 
3 liveuser 9727
			}#if end
226 liveuser 9728
 
3 liveuser 9729
		#檢查參數
9730
		#函式說明:
9731
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
9732
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9733
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9734
		#$result["function"],當前執行的函式名稱.
9735
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9736
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9737
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9738
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
9739
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9740
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9741
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9742
		#必填寫的參數:
9743
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9744
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9745
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9746
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 9747
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 9748
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
9749
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9750
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9751
		#可以省略的參數:
9752
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
9753
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9754
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9755
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("baseFrom");
226 liveuser 9756
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 9757
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
9758
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9759
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
9760
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9761
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
9762
		#參考資料來源:
9763
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9764
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9765
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 9766
 
3 liveuser 9767
		#如果 $checkResult["status"] 等於 "false"
9768
		if($checkResult["status"]=="false"){
226 liveuser 9769
 
3 liveuser 9770
			#設置錯誤識別
9771
			$result["status"]="false";
226 liveuser 9772
 
3 liveuser 9773
			#設置錯誤訊息
9774
			$result["error"]=$checkResult;
226 liveuser 9775
 
3 liveuser 9776
			#回傳結果
9777
			return $result;
226 liveuser 9778
 
3 liveuser 9779
			}#if end
226 liveuser 9780
 
3 liveuser 9781
		#如果 $checkResult["passed"] 等於 "fasle"
9782
		if($checkResult["passed"]=="false"){
226 liveuser 9783
 
3 liveuser 9784
			#設置錯誤識別
9785
			$result["status"]="false";
226 liveuser 9786
 
3 liveuser 9787
			#設置錯誤訊息
9788
			$result["error"]=$checkResult;
226 liveuser 9789
 
3 liveuser 9790
			#回傳結果
9791
			return $result;
226 liveuser 9792
 
3 liveuser 9793
			}#if end
226 liveuser 9794
 
3 liveuser 9795
		#取得參數
9796
		$result["argu"]=$conf;
226 liveuser 9797
 
3 liveuser 9798
		#函式說明:
9799
		#將固定格式的字串分開,並回傳分開的結果.
9800
		#回傳結果:
9801
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9802
		#$result["error"],錯誤訊息陣列
9803
		#$result["function"],當前執行的函數名稱.
9804
		#$result["argu"],使用的參數.
9805
		#$result["oriStr"],要分割的原始字串內容
9806
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9807
		#$result["dataCounts"],爲總共分成幾段
9808
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9809
		#必填參數:
9810
		#$conf["stringIn"],字串,要處理的字串.
9811
		$conf["fileAccess::spiltString"]["stringIn"]=$conf["fileArgu"];
9812
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
9813
		$conf["fileAccess::spiltString"]["spiltSymbol"]="/";
9814
		#可省略參數:
9815
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9816
		$conf["fileAccess::spiltString"]["allowEmptyStr"]="false";
9817
		#參考資料:
9818
		#無.
9819
		#備註:
9820
		#無.
9821
		$spiltString=stringProcess::spiltString($conf["fileAccess::spiltString"]);
9822
		unset($conf["fileAccess::spiltString"]);
226 liveuser 9823
 
3 liveuser 9824
		#如果執行失敗
9825
		if($spiltString["status"]==="false"){
226 liveuser 9826
 
3 liveuser 9827
			#設置錯誤識別
9828
			$result["status"]="false";
226 liveuser 9829
 
3 liveuser 9830
			#設置錯誤訊息
9831
			$result["error"]=$spiltString;
226 liveuser 9832
 
3 liveuser 9833
			#回傳結果
9834
			return $result;
226 liveuser 9835
 
3 liveuser 9836
			}#if end
226 liveuser 9837
 
3 liveuser 9838
		#如果沒有關鍵字
9839
		if($spiltString["found"]==="false"){
226 liveuser 9840
 
3 liveuser 9841
			#設置錯誤識別
9842
			$result["status"]="false";
226 liveuser 9843
 
3 liveuser 9844
			#設置錯誤訊息
9845
			$result["error"]=$spiltString;
226 liveuser 9846
 
3 liveuser 9847
			#回傳結果
9848
			return $result;
226 liveuser 9849
 
3 liveuser 9850
			}#if end
226 liveuser 9851
 
3 liveuser 9852
		#取得 $conf["fileArgu"] 的路徑
9853
		#函式說明:
9854
		#將固定格式的字串分開,並回傳分開的結果.
9855
		#回傳結果:
9856
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9857
		#$result["error"],錯誤訊息陣列
9858
		#$result["function"],當前執行的函數名稱.
9859
		#$result["argu"],使用的參數.
9860
		#$result["oriStr"],要分割的原始字串內容
9861
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9862
		#$result["dataCounts"],爲總共分成幾段
9863
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9864
		#必填參數:
9865
		#$conf["stringIn"],字串,要處理的字串.
9866
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];
9867
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
9868
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
9869
		#可省略參數:
9870
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9871
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
9872
		#參考資料:
9873
		#無.
9874
		#備註:
9875
		#無.
9876
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
9877
		unset($conf["stringProcess::spiltString"]);
226 liveuser 9878
 
3 liveuser 9879
		#如果執行失敗
9880
		if($spiltString["status"]==="false"){
226 liveuser 9881
 
3 liveuser 9882
			#設置錯誤識別
9883
			$result["status"]="false";
226 liveuser 9884
 
3 liveuser 9885
			#設置錯誤訊息
9886
			$result["error"]=$spiltString;
226 liveuser 9887
 
3 liveuser 9888
			#回傳結果
9889
			return $result;
226 liveuser 9890
 
3 liveuser 9891
			}#if end
226 liveuser 9892
 
3 liveuser 9893
		/*
9894
		#break point
9895
		var_dump($spiltString);
9896
		exit;
9897
		*/
226 liveuser 9898
 
3 liveuser 9899
		#預設 fileArgu 的路徑為 ""
9900
		$fileArguPath="";
226 liveuser 9901
 
3 liveuser 9902
		#針對每個目錄
9903
		for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 9904
 
3 liveuser 9905
			#串接路徑
9906
			$fileArguPath=$fileArguPath."/".$spiltString["dataArray"][$i];
226 liveuser 9907
 
3 liveuser 9908
			}#for end
226 liveuser 9909
 
3 liveuser 9910
		#取得相對於目標的當前位置
9911
		#函式說明:
9912
		#呼叫shell執行系統命令,並取得回傳的內容.
9913
		#回傳結果:
9914
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9915
		#$result["error"],錯誤訊息陣列.
9916
		#$result["function"],當前執行的函數名稱.
9917
		#$result["argu"],使用的參數.
9918
		#$result["cmd"],執行的指令內容.
9919
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9920
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9921
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9922
		#$result["running"],是否還在執行.
9923
		#$result["pid"],pid.
9924
		#$result["statusCode"],執行結束後的代碼.
9925
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
9926
		#必填參數:
9927
		#$conf["command"],字串,要執行的指令.
9928
		$conf["external::callShell"]["command"]="cd";
9929
		#$conf["fileArgu"],字串,變數__FILE__的內容.
9930
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
9931
		#可省略參數:
9932
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9933
		$conf["external::callShell"]["argu"]=array($fileArguPath,";","pwd");
9934
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9935
		#$conf["arguIsAddr"]=array();
9936
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9937
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9938
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9939
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9940
		#$conf["enablePrintDescription"]="true";
9941
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9942
		#$conf["printDescription"]="";
9943
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9944
		$conf["external::callShell"]["escapeshellarg"]="true";
9945
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9946
		#$conf["thereIsShellVar"]=array();
9947
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9948
		#$conf["username"]="";
9949
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9950
		#$conf["password"]="";
9951
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9952
		#$conf["useScript"]="";
9953
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9954
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9955
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9956
		#$conf["inBackGround"]="";
9957
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9958
		#$conf["getErr"]="false";
9959
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9960
		#$conf["doNotRun"]="false";
9961
		#參考資料:
9962
		#exec=>http://php.net/manual/en/function.exec.php
9963
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9964
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9965
		#備註:
9966
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9967
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9968
		$callShell=external::callShell($conf["external::callShell"]);
9969
		unset($conf["external::callShell"]);
226 liveuser 9970
 
3 liveuser 9971
		#如果執行失敗
9972
		if($callShell["status"]==="false"){
226 liveuser 9973
 
3 liveuser 9974
			#設置錯誤識別
9975
			$result["status"]="false";
226 liveuser 9976
 
3 liveuser 9977
			#設置錯誤訊息
9978
			$result["error"]=$callShell;
226 liveuser 9979
 
3 liveuser 9980
			#回傳結果
9981
			return $result;
226 liveuser 9982
 
3 liveuser 9983
			}#if end
226 liveuser 9984
 
3 liveuser 9985
		#如果執行失敗
9986
		if(!isset($callShell["output"][0])){
226 liveuser 9987
 
3 liveuser 9988
			#設置錯誤識別
9989
			$result["status"]="false";
226 liveuser 9990
 
3 liveuser 9991
			#設置錯誤訊息
9992
			$result["error"]=$callShell;
226 liveuser 9993
 
3 liveuser 9994
			#回傳結果
9995
			return $result;
226 liveuser 9996
 
9997
			}#if end
9998
 
3 liveuser 9999
		/*
10000
		#break point
10001
		var_dump($callShell);
10002
		exit;
10003
		*/
226 liveuser 10004
 
3 liveuser 10005
		#記錄執行的指令
10006
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 10007
 
3 liveuser 10008
		#保存相對於目標的當前位置
10009
		$pwd=$callShell["output"][0];
226 liveuser 10010
 
3 liveuser 10011
		#更新 fileArgu
10012
		$conf["fileArgu"]=$pwd."/".$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 10013
 
3 liveuser 10014
		#針對每個 $conf["path"]
10015
		foreach($conf["path"] as $path){
226 liveuser 10016
 
3 liveuser 10017
			#將 $path 變成易讀的格式
10018
			#函式說明:
10019
			#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
10020
			#回傳的結果:
10021
			#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
10022
			#$result["function"],當前執行的函數.
10023
			#$result["error"],錯誤訊息陣列.
10024
			#$result["changedPath"],處理完後回傳的目錄字串.
10025
			#$result["oriPath"],原始的路徑字串
10026
			#必填參數:
10027
			#$conf["dirStr"],字串,要處理的檔案目錄字串.
10028
			$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$path;
10029
			$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
10030
			unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 10031
 
3 liveuser 10032
			#如果處理失敗
10033
			if($changeDirByDotDotSolidus["status"]==="false"){
226 liveuser 10034
 
3 liveuser 10035
				#設置錯誤識別
10036
				$result["status"]="false";
226 liveuser 10037
 
3 liveuser 10038
				#設置錯誤訊息
10039
				$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10040
 
3 liveuser 10041
				#回傳結果
10042
				return $result;
226 liveuser 10043
 
3 liveuser 10044
				}#if end
226 liveuser 10045
 
3 liveuser 10046
			#取得易讀的路徑
10047
			$path=$changeDirByDotDotSolidus["changedPath"];
226 liveuser 10048
 
3 liveuser 10049
			#判斷 $path 是否為絕對路徑
10050
			#函式說明:
10051
			#取得符合特定字首與字尾的字串
10052
			#回傳結果:
10053
			#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10054
			#$result["function"],當前執行的函數名稱.
10055
			#$result["error"],錯誤訊息陣列.
10056
			#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10057
			#$result["returnString"],爲符合字首條件的字串內容。
10058
			#必填參數:
10059
			#$conf["checkString"],字串,要檢查的字串.
10060
			$conf["search::getMeetConditionsString"]["checkString"]=$path;
10061
			#可省略參數:
10062
			#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10063
			$conf["search::getMeetConditionsString"]["frontWord"]="/";
10064
			#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10065
			#$conf["tailWord"]="";
10066
			#參考資料:
10067
			#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10068
			$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
226 liveuser 10069
			unset($conf["search::getMeetConditionsString"]);
10070
 
3 liveuser 10071
			#如果檢查失敗
10072
			if($getMeetConditionsString["status"]=="false"){
226 liveuser 10073
 
3 liveuser 10074
				#設置錯誤識別
10075
				$result["status"]="false";
226 liveuser 10076
 
3 liveuser 10077
				#設置錯誤訊息
10078
				$result["error"]=$getMeetConditionsString;
226 liveuser 10079
 
3 liveuser 10080
				#回傳結果
10081
				return $result;
226 liveuser 10082
 
3 liveuser 10083
				}#if end
226 liveuser 10084
 
3 liveuser 10085
			#如果沒有「/」開頭
10086
			if($getMeetConditionsString["founded"]==="false"){
226 liveuser 10087
 
3 liveuser 10088
				#將 $conf["fileArgu"] 最後面的檔案或目錄名稱剔除
10089
				#函式說明:
10090
				#將固定格式的字串分開,並回傳分開的結果。
10091
				#回傳結果:
10092
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10093
				#$result["error"],錯誤訊息陣列
10094
				#$result["function"],當前執行的函數名稱.
10095
				#$result["oriStr"],要分割的原始字串內容
10096
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
10097
				#$result["dataCounts"],爲總共分成幾段
10098
				#必填參數:
10099
				$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
10100
				$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
10101
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
10102
				unset($conf["stringProcess::spiltString"]);
226 liveuser 10103
 
3 liveuser 10104
				#如果分割字串失敗
10105
				if($spiltString["status"]=="false"){
226 liveuser 10106
 
3 liveuser 10107
					#設置錯誤識別
10108
					$result["status"]="false";
226 liveuser 10109
 
3 liveuser 10110
					#設置錯誤訊息
10111
					$result["error"]=$spiltString;
226 liveuser 10112
 
3 liveuser 10113
					#回傳結果
10114
					return $result;
226 liveuser 10115
 
3 liveuser 10116
					}#if end
226 liveuser 10117
 
3 liveuser 10118
				#初始化相對路徑為開頭片段""
10119
				$relativePathPart="/";
226 liveuser 10120
 
3 liveuser 10121
				#剔除最後一段
10122
				for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 10123
 
3 liveuser 10124
					#串接起來
10125
					$relativePathPart=$relativePathPart.$spiltString["dataArray"][$i]."/";
226 liveuser 10126
 
3 liveuser 10127
					}#for end
226 liveuser 10128
 
3 liveuser 10129
				#如果有設定 baseFrom
10130
				if(isset($conf["baseFrom"])){
226 liveuser 10131
 
3 liveuser 10132
					#函式說明:
10133
					#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
10134
					#回傳結果:
10135
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10136
					#$result["error"],錯誤訊息陣列.
226 liveuser 10137
					#$result["function"],函數名稱.
3 liveuser 10138
					#$result["argu"],使用的參數.
10139
					#$result["content"],網址,若是在命令列執行,則為"null".
10140
					#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
10141
					#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
10142
					#必填參數:
10143
					#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
10144
					$conf["fileAccess::getInternetAddressV2"]["address"]=$path;
10145
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
10146
					$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
10147
					#可省略參數:
10148
					#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
10149
					$conf["fileAccess::getInternetAddressV2"]["web"]="false";
10150
					#參考資料:
10151
					#無.
10152
					#備註:
10153
					#無.
10154
					$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
10155
					unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 10156
 
3 liveuser 10157
					##var_dump(__LINE__." ".print_r($getInternetAddressV2,true));
226 liveuser 10158
 
3 liveuser 10159
					#如果執行失敗
10160
					if($getInternetAddressV2["status"]==="false"){
226 liveuser 10161
 
3 liveuser 10162
						#設置錯誤識別
10163
						$result["status"]="false";
226 liveuser 10164
 
3 liveuser 10165
						#設置錯誤訊息
10166
						$result["error"]=$getInternetAddressV2;
226 liveuser 10167
 
3 liveuser 10168
						#回傳結果
10169
						return $result;
226 liveuser 10170
 
3 liveuser 10171
						}#if end
226 liveuser 10172
 
3 liveuser 10173
					#取得絕對位置
10174
					$path=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 10175
 
3 liveuser 10176
					#函式說明:
10177
					#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
10178
					#回傳結果:
10179
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10180
					#$result["error"],錯誤訊息陣列.
226 liveuser 10181
					#$result["function"],函數名稱.
3 liveuser 10182
					#$result["argu"],使用的參數.
10183
					#$result["content"],網址,若是在命令列執行,則為"null".
10184
					#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
10185
					#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
10186
					#必填參數:
10187
					#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
10188
					$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["baseFrom"];
10189
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
10190
					$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
10191
					#可省略參數:
10192
					#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
10193
					$conf["fileAccess::getInternetAddressV2"]["web"]="false";
10194
					#參考資料:
10195
					#無.
10196
					#備註:
10197
					#無.
10198
					$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
10199
					unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 10200
 
3 liveuser 10201
					#var_dump(__LINE__." ".print_r($getInternetAddressV2,true));
226 liveuser 10202
 
3 liveuser 10203
					#如果執行失敗
10204
					if($getInternetAddressV2["status"]==="false"){
226 liveuser 10205
 
3 liveuser 10206
						#設置錯誤識別
10207
						$result["status"]="false";
226 liveuser 10208
 
3 liveuser 10209
						#設置錯誤訊息
10210
						$result["error"]=$getInternetAddressV2;
226 liveuser 10211
 
3 liveuser 10212
						#回傳結果
10213
						return $result;
226 liveuser 10214
 
3 liveuser 10215
						}#if end
226 liveuser 10216
 
3 liveuser 10217
					#取得絕對位置
10218
					$conf["baseFrom"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 10219
 
3 liveuser 10220
					#函式說明:
10221
					#將多個路徑字串變成相對於當前路徑的相對路徑字串
10222
					#回傳結果:
10223
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10224
					#$result["error"],錯誤訊息陣列.
226 liveuser 10225
					#$result["function"],函數名稱.
3 liveuser 10226
					#$result["argu"],使用的參數.
10227
					#$result["content"],字串陣列,多個轉換好的相對路徑字串.
10228
					#必填參數:
10229
					#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
10230
					$conf["fileAccess::getRelativePath"]["path"]=array($path);
10231
					#$conf["fileArgu"],字串,當前路徑.
10232
					$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["baseFrom"]."/name";
10233
					#可省略參數:
10234
					#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
10235
					#$conf["baseFrom"]="";
10236
					#參考資料:
10237
					#無.
10238
					#備註:
10239
					#無.
10240
					$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
10241
					unset($conf["fileAccess::getRelativePath"]);
226 liveuser 10242
 
3 liveuser 10243
					#var_dump(__LINE__." ".print_r($getRelativePath,true));
226 liveuser 10244
 
3 liveuser 10245
					#如果執行失敗
10246
					if($getRelativePath["status"]==="false"){
226 liveuser 10247
 
3 liveuser 10248
						#設置錯誤識別
10249
						$result["status"]="false";
226 liveuser 10250
 
3 liveuser 10251
						#設置錯誤訊息
10252
						$result["error"]=$getRelativePath;
226 liveuser 10253
 
3 liveuser 10254
						#回傳結果
10255
						return $result;
226 liveuser 10256
 
3 liveuser 10257
						}#if end
226 liveuser 10258
 
3 liveuser 10259
					#取得轉換好的絕對路徑
10260
					$relativePathPart=$getRelativePath["content"][0]."/";
226 liveuser 10261
 
3 liveuser 10262
					#清空path,避免出錯
10263
					$path="";
226 liveuser 10264
 
3 liveuser 10265
					}#if end
226 liveuser 10266
 
3 liveuser 10267
				#轉換成易讀的相對路徑
10268
				#函式說明:
10269
				#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
10270
				#回傳的結果:
10271
				#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
10272
				#$result["function"],當前執行的函數.
10273
				#$result["error"],錯誤訊息陣列.
10274
				#$result["changedPath"],處理完後回傳的目錄字串.
10275
				#$result["oriPath"],原始的路徑字串
10276
				#必填參數:
10277
				#$conf["dirStr"],字串,要處理的檔案目錄字串.
10278
				$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$relativePathPart.$path;
10279
				$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
10280
				unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 10281
 
10282
				#var_dump($changeDirByDotDotSolidus);
10283
 
3 liveuser 10284
				#如果轉換失敗
10285
				if($changeDirByDotDotSolidus["status"]=="false"){
226 liveuser 10286
 
3 liveuser 10287
					#設置錯誤識別
10288
					$result["status"]="false";
226 liveuser 10289
 
3 liveuser 10290
					#設置錯誤訊息
10291
					$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10292
 
3 liveuser 10293
					#回傳結果
10294
					return $result;
226 liveuser 10295
 
3 liveuser 10296
					}#if end
226 liveuser 10297
 
3 liveuser 10298
				#轉換為相對路徑
10299
				#函式說明:
10300
				#將多個路徑字串變成相對於當前路徑的相對路徑字串
10301
				#回傳結果:
10302
				#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10303
				#$result["error"],錯誤訊息陣列.
226 liveuser 10304
				#$result["function"],函數名稱.
3 liveuser 10305
				#$result["content"],字串陣列,多個轉換好的相對路徑字串.
10306
				#必填參數:
10307
				#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
10308
				$conf["fileAccess::getRelativePath"]["path"]=array($changeDirByDotDotSolidus["changedPath"]);
10309
				#$conf["fileArgu"],字串,當前路徑.
10310
				$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
10311
				$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
10312
				unset($conf["fileAccess::getRelativePath"]);
226 liveuser 10313
 
10314
				#var_dump($getRelativePath);
10315
 
3 liveuser 10316
				#如果轉換路徑失敗
10317
				if($getRelativePath["status"]==="false"){
226 liveuser 10318
 
3 liveuser 10319
					#設置錯誤識別
10320
					$result["status"]="false";
226 liveuser 10321
 
3 liveuser 10322
					#設置錯誤訊息
10323
					$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10324
 
3 liveuser 10325
					#回傳結果
10326
					return $result;
226 liveuser 10327
 
3 liveuser 10328
					}#if end
226 liveuser 10329
 
3 liveuser 10330
				#取得相對路徑
10331
				$result["content"][]=$getRelativePath["content"][0];
226 liveuser 10332
 
3 liveuser 10333
				}#if end
226 liveuser 10334
 
3 liveuser 10335
			#反之有「/」開頭
10336
			else{
10337
				#函式說明:
10338
				#移除多個絕對路徑字串開頭相同的部分
10339
				#回傳結果:
10340
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10341
				#$result["error"],錯誤訊息陣列.
10342
				#$result["function"],當前執行的函數名稱.
10343
				#$result["content"],處理好的的字串內容.
10344
				#必填參數:
10345
				#$conf["pathIn"],字串陣列,每個要處理的絕對路徑字串.
226 liveuser 10346
				$conf["fileAccess::delSamePathHead"]["pathIn"]=array($path,$conf["fileArgu"]);
3 liveuser 10347
				$delSamePathHead=fileAccess::delSamePathHead($conf["fileAccess::delSamePathHead"]);
10348
				unset($conf["fileAccess::delSamePathHead"]);
226 liveuser 10349
 
3 liveuser 10350
				#var_dump($delSamePathHead);
226 liveuser 10351
 
3 liveuser 10352
				#如果移除多個絕對路徑字串開頭相同的部分失敗
10353
				if($delSamePathHead["status"]==="false"){
226 liveuser 10354
 
3 liveuser 10355
					#設置錯誤識別
10356
					$result["status"]="false";
226 liveuser 10357
 
3 liveuser 10358
					#設置錯誤訊息
10359
					$result["error"]=$delSameHead;
226 liveuser 10360
 
3 liveuser 10361
					#回傳結果
10362
					return $result;
226 liveuser 10363
 
3 liveuser 10364
					}#if end
226 liveuser 10365
 
3 liveuser 10366
				#如果 $conf["fileArgu"] 剩下空
10367
				if($delSamePathHead["content"][1]===""){
226 liveuser 10368
 
3 liveuser 10369
					#檢查 $delSamePathHead[0] 開頭是否為「/」
10370
					#函式說明:
10371
					#取得符合特定字首與字尾的字串
10372
					#回傳結果:
10373
					#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10374
					#$result["function"],當前執行的函數名稱.
10375
					#$result["error"],錯誤訊息陣列.
10376
					#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10377
					#$result["returnString"],爲符合字首條件的字串內容。
10378
					#必填參數:
10379
					#$conf["checkString"],字串,要檢查的字串.
10380
					$conf["search::getMeetConditionsString"]["checkString"]=$delSamePathHead["content"][0];
10381
					#可省略參數:
10382
					#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10383
					$conf["search::getMeetConditionsString"]["frontWord"]="/";
10384
					#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10385
					#$conf["tailWord"]="";
10386
					#參考資料:
10387
					#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10388
					$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
10389
					unset($conf["search::getMeetConditionsString"]);
226 liveuser 10390
 
3 liveuser 10391
					#如果檢查失敗
10392
					if($getMeetConditionsString["status"]=="false"){
226 liveuser 10393
 
3 liveuser 10394
						#設置錯誤識別
10395
						$result["status"]="false";
226 liveuser 10396
 
3 liveuser 10397
						#設置錯誤訊息
10398
						$result["error"]=$getMeetConditionsString;
226 liveuser 10399
 
3 liveuser 10400
						#回傳結果
10401
						return $result;
226 liveuser 10402
 
3 liveuser 10403
						}#if end
226 liveuser 10404
 
3 liveuser 10405
					#如果有開頭有「/」
10406
					if($getMeetConditionsString["founded"]==="true"){
226 liveuser 10407
 
3 liveuser 10408
						#函式說明:
10409
						#將字串特定關鍵字與其前面的內容剔除
10410
						#回傳結果:
10411
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10412
						#$result["error"],錯誤訊息陣列.
10413
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
10414
						#$result["function"],當前執行的函數名稱.
10415
						#$result["oriStr"],要處理的原始字串內容.
10416
						#$result["content"],處理好的的字串內容.
10417
						#必填參數:
10418
						$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$delSamePathHead["content"][0];#要處理的字串.
10419
						$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="/";#特定字串.
10420
						$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
10421
						unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 10422
 
3 liveuser 10423
						#如果 將字串特定關鍵字與其前面的內容剔除 失敗
10424
						if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 10425
 
3 liveuser 10426
							#設置錯誤識別
10427
							$result["status"]="false";
226 liveuser 10428
 
3 liveuser 10429
							#設置錯誤訊息
10430
							$result["error"]=$delStrBeforeKeyWord;
226 liveuser 10431
 
3 liveuser 10432
							#回傳結果
10433
							return $result;
226 liveuser 10434
 
3 liveuser 10435
							}#if end
226 liveuser 10436
 
3 liveuser 10437
						#取得相對位置
10438
						$result["content"][]=$delStrBeforeKeyWord["content"];
226 liveuser 10439
 
3 liveuser 10440
						}#if end
226 liveuser 10441
 
3 liveuser 10442
					#反之
10443
					else{
226 liveuser 10444
 
3 liveuser 10445
						#取得相對位置
10446
						$result["content"][]=$delSamePathHead["content"][0];
226 liveuser 10447
 
10448
						}#else end
10449
 
3 liveuser 10450
					}#if end
226 liveuser 10451
 
3 liveuser 10452
				#反之剩下的 $conf["fileArgu"] 不為空
10453
				else{
226 liveuser 10454
 
3 liveuser 10455
					#檢查 $delSamePathHead["content"][1] 有幾個「/」
10456
					#函式說明:
10457
					#檢查字串裡面有無指定的關鍵字
10458
					#回傳結果:
10459
					#$result["status"],"true"代表執行成功,"false"代表執行失敗。
10460
					#$result["error"],錯誤訊息
10461
					#$result["function"],當前執行的函數名稱.
10462
					#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
10463
					#$result["keyWordCount"],找到的關鍵字數量.
10464
					#必填參數:
10465
					$conf["search::findKeyWord"]["keyWord"]="/";#想要搜尋的關鍵字
10466
					$conf["search::findKeyWord"]["string"]=$delSamePathHead["content"][1];#要被搜尋的字串內容
10467
					#可省略參數:
10468
					#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
10469
					$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
10470
					unset($conf["search::findKeyWord"]);
226 liveuser 10471
 
3 liveuser 10472
					#如果 檢查字串裡面有無指定的關鍵字 失敗
10473
					if($findKeyWord["status"]==="false"){
226 liveuser 10474
 
3 liveuser 10475
						#設置錯誤識別
10476
						$result["status"]="false";
226 liveuser 10477
 
3 liveuser 10478
						#設置錯誤訊息
10479
						$result["error"]=$findKeyWord;
226 liveuser 10480
 
3 liveuser 10481
						#回傳結果
10482
						return $result;
226 liveuser 10483
 
3 liveuser 10484
						}#if end
226 liveuser 10485
 
3 liveuser 10486
					#有幾個「/」就執行幾次
10487
					for($i=0;$i<$findKeyWord["keyWordCount"];$i++){
226 liveuser 10488
 
3 liveuser 10489
						#在前面加上 "../"
10490
						$delSamePathHead["content"][0]="../".$delSamePathHead["content"][0];
226 liveuser 10491
 
3 liveuser 10492
						}#for end
226 liveuser 10493
 
3 liveuser 10494
					#取得相對位置
10495
					$result["content"][]=$delSamePathHead["content"][0];
226 liveuser 10496
 
3 liveuser 10497
					}#else end
226 liveuser 10498
 
3 liveuser 10499
				}#else end
226 liveuser 10500
 
3 liveuser 10501
			}#foreach end
226 liveuser 10502
 
3 liveuser 10503
		#設置執行正常
10504
		$result["status"]="true";
226 liveuser 10505
 
3 liveuser 10506
		#回傳結果
10507
		return $result;
226 liveuser 10508
 
3 liveuser 10509
		}#function getRelativeParh end
10510
 
10511
	/*
10512
	#函式說明:
10513
	#移除多個絕對路徑字串開頭相同的部分
10514
	#回傳結果:
10515
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10516
	#$result["error"],錯誤訊息陣列.
10517
	#$result["function"],當前執行的函數名稱.
10518
	#$result["argu"],參數.
10519
	#$result["content"],處理好的的字串內容.
10520
	#必填參數:
10521
	#$conf["pathIn"],字串陣列,每個要處理的絕對路徑字串.
226 liveuser 10522
	$conf["pathIn"]=array();
3 liveuser 10523
	#可省略參數:
10524
	#無
10525
	#參考資料:
10526
	#無.
10527
	#備註:
10528
	#無.
10529
	*/
10530
	public static function delSamePathHead(&$conf){
226 liveuser 10531
 
3 liveuser 10532
		#初始化要回傳的結果
10533
		$result=array();
10534
 
10535
		#取得當前執行的函數名稱
10536
		$result["function"]=__FUNCTION__;
10537
 
10538
		#如果沒有參數
10539
		if(func_num_args()==0){
226 liveuser 10540
 
3 liveuser 10541
			#設置執行失敗
10542
			$result["status"]="false";
226 liveuser 10543
 
3 liveuser 10544
			#設置執行錯誤訊息
10545
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 10546
 
3 liveuser 10547
			#回傳結果
10548
			return $result;
226 liveuser 10549
 
3 liveuser 10550
			}#if end
10551
 
10552
		#如果 $conf 不為陣列
10553
		if(gettype($conf)!="array"){
226 liveuser 10554
 
3 liveuser 10555
			#設置執行失敗
10556
			$result["status"]="false";
226 liveuser 10557
 
3 liveuser 10558
			#設置執行錯誤訊息
10559
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 10560
 
3 liveuser 10561
			#如果傳入的參數為 null
10562
			if($conf==null){
226 liveuser 10563
 
3 liveuser 10564
				#設置執行錯誤訊息
10565
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 10566
 
3 liveuser 10567
				}#if end
10568
 
10569
			#回傳結果
10570
			return $result;
226 liveuser 10571
 
3 liveuser 10572
			}#if end
226 liveuser 10573
 
3 liveuser 10574
		#取得參數
226 liveuser 10575
		$result["argv"]=$conf;
10576
 
3 liveuser 10577
		#檢查參數
10578
		#函式說明:
10579
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
10580
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10581
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10582
		#$result["function"],當前執行的函式名稱.
10583
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10584
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10585
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10586
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
10587
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10588
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10589
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10590
		#必填寫的參數:
10591
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10592
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10593
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10594
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("pathIn");
226 liveuser 10595
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 10596
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
10597
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10598
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10599
		#可以省略的參數:
10600
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
10601
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
10602
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10603
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileToRead","output");
226 liveuser 10604
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 10605
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
10606
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10607
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("help","help");
10608
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10609
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
10610
		#參考資料來源:
10611
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10612
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10613
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 10614
 
3 liveuser 10615
		#如果 $checkResult["status"] 等於 "fasle"
10616
		if($checkResult["status"]=="false"){
226 liveuser 10617
 
3 liveuser 10618
			#設置錯誤識別
10619
			$result["status"]="false";
226 liveuser 10620
 
3 liveuser 10621
			#設置錯誤訊息
10622
			$result["error"]=$checkResult;
226 liveuser 10623
 
3 liveuser 10624
			#回傳結果
10625
			return $result;
226 liveuser 10626
 
3 liveuser 10627
			}#if end
226 liveuser 10628
 
3 liveuser 10629
		#如果 $checkResult["passed"] 等於 "fasle"
10630
		if($checkResult["passed"]=="false"){
226 liveuser 10631
 
3 liveuser 10632
			#設置錯誤識別
10633
			$result["status"]="false";
226 liveuser 10634
 
3 liveuser 10635
			#設置錯誤訊息
10636
			$result["error"]=$checkResult;
226 liveuser 10637
 
3 liveuser 10638
			#回傳結果
10639
			return $result;
226 liveuser 10640
 
3 liveuser 10641
			}#if end
226 liveuser 10642
 
3 liveuser 10643
		#檢查是否都為絕對路徑
10644
		#函式說明:
10645
		#取得多個符合特定字首與字尾的字串.
10646
		#回傳結果:
10647
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10648
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10649
		#$result["function"],當前執行的函數名稱.
10650
		#$result["returnString"],爲符合字首條件的字串陣列內容。
10651
		#必填參數:
10652
		#$conf["checkString"],陣列字串,要檢查的字串們.
10653
		$conf["search::getMeetConditionsStringMulti"]["checkString"]=$conf["pathIn"];#要檢查的字串陣列
10654
		#可省略參數:
10655
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10656
		$conf["search::getMeetConditionsStringMulti"]["frontWord"]="/";
10657
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10658
		#$conf["tailWord"]="";
10659
		#參考資料:
10660
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10661
		$getMeetConditionsStringMulti=search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]);
10662
		unset($conf["search::getMeetConditionsStringMulti"]);
226 liveuser 10663
 
3 liveuser 10664
		#如果檢測是否為絕對路徑失敗
10665
		if($getMeetConditionsStringMulti["status"]=="false"){
226 liveuser 10666
 
3 liveuser 10667
			#設置錯誤識別
10668
			$result["status"]="false";
226 liveuser 10669
 
3 liveuser 10670
			#設置錯誤訊息
10671
			$result["error"]=$getMeetConditionsStringMulti;
226 liveuser 10672
 
3 liveuser 10673
			#增加額外的錯誤訊息
10674
			$result["error"][]="僅接受絕對路徑字串";
226 liveuser 10675
 
3 liveuser 10676
			#回傳結果
10677
			return $result;
226 liveuser 10678
 
3 liveuser 10679
			}#if end
226 liveuser 10680
 
3 liveuser 10681
		#函式說明:
10682
		#將多個固定格式的字串分開,並回傳分開的結果
10683
		#回傳的參數:
10684
		#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
10685
		#$result["error"],錯誤訊息陣列.
10686
		#$result["function"],當前執行的函數名稱.
10687
		#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
10688
		#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
10689
		#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
10690
		#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
10691
		#必填參數:
10692
		#$conf["stringIn"],字串陣列,要處理的字串陣列.
10693
		$conf["stringProcess::spiltMutiString"]["stringIn"]=$conf["pathIn"];
10694
		#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
10695
		$conf["stringProcess::spiltMutiString"]["spiltSymbol"]="/";
10696
		$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
226 liveuser 10697
 
3 liveuser 10698
		#如果分割所有路徑字串失敗
10699
		if($spiltMutiString["status"]=="false"){
226 liveuser 10700
 
3 liveuser 10701
			#設置錯誤識別
10702
			$result["status"]="false";
226 liveuser 10703
 
3 liveuser 10704
			#設置錯誤訊息
226 liveuser 10705
			$result["error"]=$spiltMutiString;
10706
 
3 liveuser 10707
			#回傳結果
10708
			return $result;
226 liveuser 10709
 
3 liveuser 10710
			}#if end
226 liveuser 10711
 
3 liveuser 10712
		#初始化暫存每個路徑分割成的段數
226 liveuser 10713
		$spiltedPathCount=array();
10714
 
3 liveuser 10715
		#取得每個路徑分割成的段數
10716
		#針對每個 $spiltMutiString["spiltString"]
10717
		for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
226 liveuser 10718
 
3 liveuser 10719
			$spiltedPathCount[]=$spiltMutiString["spiltString"][$i]["dataCounts"];
226 liveuser 10720
 
3 liveuser 10721
			}#for end
226 liveuser 10722
 
3 liveuser 10723
		#取得所有路徑字串分割後的最小數量
10724
		#涵式說明
10725
		#找最小值,結果會回傳最小值
10726
		#回傳的內容
10727
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
10728
		#$result["error"],錯誤訊息陣列.
10729
		#$result["function"],當前執行的函數名稱.
10730
		#$result["key"],最大值原先的key.
10731
		#$result["value"],陣列裏面最小的數值.
10732
		#必填參數:
10733
		$conf["math::getMinValue"]["rawDataArray"]=$spiltedPathCount;#爲原始數據
10734
		$getMinValue=math::getMinValue($conf["math::getMinValue"]);
10735
		unset($conf["math::getMinValue"]);
226 liveuser 10736
 
3 liveuser 10737
		#如果取得最小數值失敗
10738
		if($getMinValue["status"]=="false"){
226 liveuser 10739
 
3 liveuser 10740
			#設置錯誤識別
10741
			$result["status"]="false";
226 liveuser 10742
 
3 liveuser 10743
			#設置錯誤訊息
226 liveuser 10744
			$result["error"]=$getMinValue;
10745
 
3 liveuser 10746
			#回傳結果
10747
			return $result;
226 liveuser 10748
 
10749
			}#if end
10750
 
3 liveuser 10751
		#初始化暫存每個路徑字串的前面幾個片段是相同的
10752
		$samePartCount=0;
226 liveuser 10753
 
10754
		#var_dump($getMinValue["value"]);
10755
 
3 liveuser 10756
		#依據所有路徑字串分割後的最小數量
10757
		for($j=0;$j<$getMinValue["value"];$j++){
226 liveuser 10758
 
3 liveuser 10759
			#初始化暫存第一個路徑的片段字串
10760
			$firstPathPart="";
226 liveuser 10761
 
3 liveuser 10762
			#針對每個 $spiltMutiString["spiltString"]
10763
			for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
226 liveuser 10764
 
3 liveuser 10765
				#暫存分割的字串
10766
				$spiltedPath=$spiltMutiString["spiltString"][$i];
226 liveuser 10767
 
3 liveuser 10768
				#如果是第一個路徑
10769
				if($i==0){
226 liveuser 10770
 
3 liveuser 10771
					#取得第一個路徑的片段字串
10772
					$firstPathPart=$spiltedPath["dataArray"][$j];
226 liveuser 10773
 
10774
					}#if end
10775
 
3 liveuser 10776
				#如果第$i+1個路徑片段不跟第1個路徑的片段字串一樣
10777
				if($spiltedPath["dataArray"][$j]!=$firstPathPart){
226 liveuser 10778
 
3 liveuser 10779
					#讓最外層迴圈中止
10780
					$getMinValue["value"]=-1;
226 liveuser 10781
 
3 liveuser 10782
					#跳出迴圈
10783
					break;
226 liveuser 10784
 
10785
					}#if end
10786
 
3 liveuser 10787
				}#for end
226 liveuser 10788
 
3 liveuser 10789
			#代表每個路徑字串的第$j段是一樣的.
10790
			$samePartCount=$j;
226 liveuser 10791
 
3 liveuser 10792
			}#for end
226 liveuser 10793
 
3 liveuser 10794
		#var_dump($samePartCount);
226 liveuser 10795
 
3 liveuser 10796
		#依據每個路徑
226 liveuser 10797
		for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
10798
 
3 liveuser 10799
			#初始化儲存第$i+1個處理好的路徑字串
226 liveuser 10800
			$result["content"][$i]="";
10801
 
3 liveuser 10802
			#依據 $samePartCount 與 路徑的段數
10803
			for($j=$samePartCount;$j<$spiltMutiString["spiltString"][$i]["dataCounts"];$j++){
226 liveuser 10804
 
3 liveuser 10805
				#如果不是第一段
10806
				if($j!=$samePartCount){
226 liveuser 10807
 
3 liveuser 10808
					#組裝每個路徑片段
10809
					$result["content"][$i]=$result["content"][$i]."/".$spiltMutiString["spiltString"][$i]["dataArray"][$j];
226 liveuser 10810
 
3 liveuser 10811
					}#if end
226 liveuser 10812
 
3 liveuser 10813
				#反之為第一段
10814
				else{
226 liveuser 10815
 
3 liveuser 10816
					#組裝每個路徑片段
10817
					$result["content"][$i]=$result["content"][$i].$spiltMutiString["spiltString"][$i]["dataArray"][$j];
226 liveuser 10818
 
3 liveuser 10819
					}#else end
226 liveuser 10820
 
3 liveuser 10821
				}#for end
226 liveuser 10822
 
3 liveuser 10823
			}#for end
226 liveuser 10824
 
3 liveuser 10825
		#設置執行正常
10826
		$result["status"]="true";
226 liveuser 10827
 
3 liveuser 10828
		#回傳結果
10829
		return $result;
226 liveuser 10830
 
3 liveuser 10831
		}#function delSamePathHead end
10832
 
10833
	/*
10834
	#函式說明:
226 liveuser 10835
	#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
3 liveuser 10836
	#回傳結果:
10837
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10838
	#$result["error"],錯誤訊息.
10839
	#$result["function"],當前執行的函數名稱.
10840
	#$result["content"],暫存檔案的路徑與名稱.
10841
	#$result["fileName"],暫存檔案的名稱.
10842
	#$result["path"],暫存檔案的路徑.
10843
	#必填參數:
10844
	#無.
10845
	#可省略參數:
36 liveuser 10846
	#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
10847
	#$conf["contant"]=array();
3 liveuser 10848
	#參考資料:
10849
	#無.
10850
	#備註:
10851
	#無.
10852
	*/
36 liveuser 10853
	public static function createTempFile(&$conf){
226 liveuser 10854
 
3 liveuser 10855
		#初始化要回傳的結果
10856
		$result=array();
10857
 
10858
		#取得當前執行的函數名稱
10859
		$result["function"]=__FUNCTION__;
226 liveuser 10860
 
36 liveuser 10861
		#取得參數
10862
		$result["argu"]=$conf;
10863
 
10864
		#如果 $conf 不為陣列
10865
		if(gettype($conf)!="array"){
10866
 
10867
			#設置執行失敗
10868
			$result["status"]="false";
10869
 
10870
			#設置執行錯誤訊息
10871
			$result["error"][]="\$conf變數須為陣列形態";
10872
 
10873
			#如果傳入的參數為 null
10874
			if(is_null($conf)){
10875
 
10876
				#設置執行錯誤訊息
10877
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
10878
 
10879
				}#if end
10880
 
10881
			#回傳結果
10882
			return $result;
10883
 
10884
			}#if end
226 liveuser 10885
 
36 liveuser 10886
		#檢查參數
10887
		#函式說明:
10888
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
10889
		#回傳結果:
10890
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10891
		#$result["error"],執行不正常結束的錯訊息陣列.
10892
		#$result["simpleError"],簡單表示的錯誤訊息.
10893
		#$result["function"],當前執行的函式名稱.
10894
		#$result["argu"],設置給予的參數.
10895
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10896
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10897
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10898
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
10899
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
10900
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10901
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10902
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10903
		#必填參數:
10904
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10905
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10906
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10907
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10908
		#可省略參數:
10909
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10910
		#$conf["mustBeFilledVariableName"]=array();
10911
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
10912
		#$conf["mustBeFilledVariableType"]=array();
10913
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
10914
		#$conf["canBeEmptyString"]="false";
10915
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
10916
		#$conf["canNotBeEmpty"]=array();
10917
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
10918
		#$conf["canBeEmpty"]=array();
10919
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
10920
		#$conf["skipableVariableCanNotBeEmpty"]=array();
10921
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10922
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("content");
10923
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
10924
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
10925
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10926
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array());
10927
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
10928
		#$conf["disallowAllSkipableVarIsEmpty"]="";
10929
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
10930
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
10931
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
10932
		#$conf["disallowAllSkipableVarNotExist"]="";
10933
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10934
		#$conf["arrayCountEqualCheck"][]=array();
10935
		#參考資料:
10936
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10937
		#備註:
10938
		#無.
10939
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10940
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 10941
 
36 liveuser 10942
		#如果執行失敗
10943
		if($checkArguments["status"]==="false"){
226 liveuser 10944
 
36 liveuser 10945
			#設置執行異常
10946
			$result["status"]="false";
226 liveuser 10947
 
36 liveuser 10948
			#設置錯誤訊息
10949
			$result["error"]=$checkArguments;
226 liveuser 10950
 
36 liveuser 10951
			#回傳結果
10952
			return $result;
226 liveuser 10953
 
36 liveuser 10954
			}#if end
226 liveuser 10955
 
36 liveuser 10956
		#如果檢查不通過
10957
		if($checkArguments["passed"]==="false"){
226 liveuser 10958
 
36 liveuser 10959
			#設置執行異常
10960
			$result["status"]="false";
226 liveuser 10961
 
36 liveuser 10962
			#設置錯誤訊息
10963
			$result["error"]=$checkArguments;
226 liveuser 10964
 
36 liveuser 10965
			#回傳結果
10966
			return $result;
226 liveuser 10967
 
36 liveuser 10968
			}#if end
226 liveuser 10969
 
3 liveuser 10970
		#取得相對於當前路徑的  tmp 目錄.
10971
		exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/tmp;pwd;",$output,$status);
226 liveuser 10972
 
3 liveuser 10973
		#如果執行失敗
10974
		if($status!==0){
226 liveuser 10975
 
3 liveuser 10976
			#設置執行失敗
10977
			$result["status"]="false";
10978
 
10979
			#設置執行錯誤訊息
10980
			$result["error"][]="取得暫存目錄失敗";
226 liveuser 10981
 
3 liveuser 10982
			#回傳結果
10983
			return $result;
226 liveuser 10984
 
10985
			}#if end
10986
 
3 liveuser 10987
		#設置預設的暫存目錄
226 liveuser 10988
		$defaultTmpDir=$output[0];
10989
 
3 liveuser 10990
		#取得暫存檔案的路徑與名稱
10991
		$result["content"]=tempnam($defaultTmpDir,"qbpwcf_tmpfile_");
226 liveuser 10992
 
42 liveuser 10993
		#如果產生的暫存檔案位置異常
10994
		#參考資料:
10995
		#https://www.php.net/manual/en/function.tempnam.php
10996
		if(strpos("/tmp/",$result["content"])===0){
226 liveuser 10997
 
42 liveuser 10998
			#設置執行失敗
10999
			$result["status"]="false";
11000
 
11001
			#設置執行錯誤訊息
11002
			$result["error"][]="於暫存目錄建立檔案失敗";
226 liveuser 11003
 
42 liveuser 11004
			#回傳結果
11005
			return $result;
226 liveuser 11006
 
42 liveuser 11007
			}#if end
226 liveuser 11008
 
3 liveuser 11009
		#函式說明:
11010
		#將字串特定關鍵字與其前面的內容剔除
11011
		#回傳結果:
11012
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11013
		#$result["error"],錯誤訊息陣列.
11014
		#$result["warning"],警告訊息鎮列.
11015
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
11016
		#$result["function"],當前執行的函數名稱.
11017
		#$result["argu"],使用的參數.
11018
		#$result["oriStr"],要處理的原始字串內容.
226 liveuser 11019
		#$result["content"],處理好的的字串內容.
3 liveuser 11020
		#必填參數:
11021
		#$conf["stringIn"],字串,要處理的字串.
11022
		$conf["stringPorcess::delStrBeforeKeyWord"]["stringIn"]=$result["content"];
11023
		#$conf["keyWord"],字串,特定字串.
42 liveuser 11024
		$conf["stringPorcess::delStrBeforeKeyWord"]["keyWord"]=$defaultTmpDir."/";
3 liveuser 11025
		#可省略參數:
11026
		#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
42 liveuser 11027
		$conf["stringPorcess::delStrBeforeKeyWord"]["recursive"]="true";
3 liveuser 11028
		#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
11029
		#$conf["lastResult"]=$delStrBeforeKeyWord;
11030
		#參考資料:
11031
		#無.
11032
		#備註:
11033
		#無.
11034
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringPorcess::delStrBeforeKeyWord"]);
11035
		unset($conf["stringPorcess::delStrBeforeKeyWord"]);
226 liveuser 11036
 
3 liveuser 11037
		#如果執行失敗
11038
		if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 11039
 
3 liveuser 11040
			#設置執行失敗
11041
			$result["status"]="false";
11042
 
11043
			#設置執行錯誤訊息
11044
			$result["error"]=$delStrBeforeKeyWord;
226 liveuser 11045
 
3 liveuser 11046
			#回傳結果
11047
			return $result;
226 liveuser 11048
 
3 liveuser 11049
			}#if end
226 liveuser 11050
 
3 liveuser 11051
		#如果應該要存在的路徑關鍵字不在
11052
		if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 11053
 
3 liveuser 11054
			#設置執行失敗
11055
			$result["status"]="false";
11056
 
11057
			#設置執行錯誤訊息
11058
			$result["error"]=$delStrBeforeKeyWord;
226 liveuser 11059
 
3 liveuser 11060
			#回傳結果
11061
			return $result;
226 liveuser 11062
 
3 liveuser 11063
			}#if end
226 liveuser 11064
 
3 liveuser 11065
		#取得檔案名稱
11066
		$result["fileName"]=$delStrBeforeKeyWord["content"];
226 liveuser 11067
 
3 liveuser 11068
		#函式說明:
11069
		#將字串特定關鍵字與其後面的內容剔除
11070
		#回傳結果:
11071
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11072
		#$result["error"],錯誤訊息陣列.
11073
		#$result["warning"],警告訊息鎮列.
11074
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
11075
		#$result["function"],當前執行的函數名稱.
11076
		#$result["oriStr"],要處理的原始字串內容.
11077
		#$result["content"],處理好的的字串內容.
11078
		#$result["argu"],使用的參數.
11079
		#必填參數:
11080
		#$conf["stringIn"],字串,要處理的字串.
11081
		$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$result["content"];
11082
		#$conf["keyWord"],字串,特定字串.
11083
		$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["fileName"];
11084
		#可省略參數:
11085
		#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
11086
		#$conf["deleteLastRepeatedOne"]="";
11087
		#參考資料:
11088
		#無.
11089
		#備註:
11090
		#無.
11091
		$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
11092
		unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 11093
 
3 liveuser 11094
		#如果執行失敗
11095
		if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 11096
 
3 liveuser 11097
			#設置執行失敗
11098
			$result["status"]="false";
11099
 
11100
			#設置執行錯誤訊息
11101
			$result["error"]=$delStrAfterKeyWord;
226 liveuser 11102
 
3 liveuser 11103
			#回傳結果
11104
			return $result;
226 liveuser 11105
 
3 liveuser 11106
			}#if end
226 liveuser 11107
 
3 liveuser 11108
		#如果應該要存在的檔案名稱關鍵字不在
11109
		if($delStrAfterKeyWord["founded"]==="false"){
226 liveuser 11110
 
3 liveuser 11111
			#設置執行失敗
11112
			$result["status"]="false";
11113
 
11114
			#設置執行錯誤訊息
11115
			$result["error"]=$delStrAfterKeyWord;
226 liveuser 11116
 
3 liveuser 11117
			#回傳結果
11118
			return $result;
226 liveuser 11119
 
3 liveuser 11120
			}#if end
226 liveuser 11121
 
3 liveuser 11122
		#取得路徑
11123
		$result["path"]=$delStrAfterKeyWord["content"];
226 liveuser 11124
 
36 liveuser 11125
		#如果有內容要寫入
11126
		if(!empty($conf["content"])){
226 liveuser 11127
 
36 liveuser 11128
			#函式說明:
11129
			#將多行字串寫入到檔案
11130
			#回傳結果:
11131
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
11132
			#$result["error"],錯誤訊息陣列.
11133
			#$result["function"],當前執行函數的名稱.
11134
			#必填參數:
11135
			#$conf["fileName"],字串,爲要編輯的檔案名稱
11136
			$conf["fileAccess::writeMultiLine"]["fileName"]=$result["content"];
11137
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
11138
			$conf["fileAccess::writeMultiLine"]["inputString"]=$conf["content"];
11139
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11140
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=__FILE__;
11141
			#可省略參數:
11142
			#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
11143
			#參考資料:
11144
			#無.
11145
			#備註:
11146
			#無.
11147
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
11148
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 11149
 
36 liveuser 11150
			#如果執行失敗
11151
			if($writeMultiLine["status"]==="false"){
226 liveuser 11152
 
36 liveuser 11153
				#設置執行失敗
11154
				$result["status"]="false";
11155
 
11156
				#設置執行錯誤訊息
11157
				$result["error"]=$writeMultiLine;
226 liveuser 11158
 
36 liveuser 11159
				#回傳結果
11160
				return $result;
226 liveuser 11161
 
36 liveuser 11162
				}#if end
226 liveuser 11163
 
36 liveuser 11164
			}#if end
226 liveuser 11165
 
3 liveuser 11166
		#設置執行正常
11167
		$result["status"]="true";
226 liveuser 11168
 
3 liveuser 11169
		#回傳結果
11170
		return $result;
226 liveuser 11171
 
3 liveuser 11172
		}#function createTempFile end
11173
 
11174
	/*
11175
	#函式說明:
253 liveuser 11176
	#複製檔案、資料夾,只要符合權限就會執行並覆蓋既有內容.
11177
	#回傳結果:
11178
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11179
	#$result["error"],錯誤訊息.
11180
	#$result["function"],當前執行的函式名稱.
11181
	#$result["content"],複製好的檔案路徑與名稱.
11182
	#必填參數:
11183
	#$conf["file"],字串,檔案的位置與名稱.
11184
	$conf["file"]="";
11185
	#$conf["to"],字串,檔案要複製到哪裡.
11186
	$conf["to"]="";
11187
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
11188
	$conf["fileArgu"]=__FILE__;
11189
	#可省略參數:
11190
	#無.
11191
	#參考資料:
11192
	#無.
11193
	#備註:
11194
	#等同於cmd::cp的應用.
11195
	*/
11196
	public static function cp(&$conf){
11197
 
11198
		#初始化要回傳的結果
11199
		$result=array();
11200
 
11201
		#取得當前執行的函式名稱
11202
		$result["function"]=__FUNCTION__;
11203
 
11204
		#如果沒有參數
11205
		if(func_num_args()==0){
11206
 
11207
			#設置執行失敗
11208
			$result["status"]="false";
11209
 
11210
			#設置執行錯誤訊息
11211
			$result["error"]="函式".$result["function"]."需要參數";
11212
 
11213
			#回傳結果
11214
			return $result;
11215
 
11216
			}#if end
11217
 
11218
		#取得參數
11219
		$result["argu"]=$conf;
11220
 
11221
		#如果 $conf 不為陣列
11222
		if(gettype($conf)!=="array"){
11223
 
11224
			#設置執行失敗
11225
			$result["status"]="false";
11226
 
11227
			#設置執行錯誤訊息
11228
			$result["error"][]="\$conf變數須為陣列形態";
11229
 
11230
			#如果傳入的參數為 null
11231
			if($conf===null){
11232
 
11233
				#設置執行錯誤訊息
11234
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
11235
 
11236
				}#if end
11237
 
11238
			#回傳結果
11239
			return $result;
11240
 
11241
			}#if end
11242
 
11243
		#檢查參數
11244
		#函式說明:
11245
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
11246
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11247
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11248
		#$result["function"],當前執行的函式名稱.
11249
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11250
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11251
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11252
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11253
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11254
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11255
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11256
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11257
		#必填寫的參數:
11258
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11259
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11260
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11261
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","to","fileArgu");
11262
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11263
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
11264
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11265
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11266
		#可以省略的參數:
11267
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11268
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11269
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11270
		#$conf["canNotBeEmpty"]=array();
11271
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11272
		#$conf["canBeEmpty"]=array();
11273
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11274
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11275
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11276
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","cmdOnly");
11277
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
11278
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
11279
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11280
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null,"true");
11281
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11282
		#$conf["arrayCountEqualCheck"][]=array();
11283
		#參考資料來源:
11284
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11285
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11286
		unset($conf["variableCheck::checkArguments"]);
11287
 
11288
		#如果參數檢查失敗
11289
		if($checkArguments["status"]==="false"){
11290
 
11291
			#設置執行不正常
11292
			$result["status"]="false";
11293
 
11294
			#設置執行錯誤
11295
			$result["error"]=$checkArguments;
11296
 
11297
			#回傳結果
11298
			return $result;
11299
 
11300
			}#if end
11301
 
11302
		#如果參數檢查不通過
11303
		if($checkArguments["passed"]==="false"){
11304
 
11305
			#設置執行不正常
11306
			$result["status"]="false";
11307
 
11308
			#設置執行錯誤
11309
			$result["error"]=$checkArguments;
11310
 
11311
			#回傳結果
11312
			return $result;
11313
 
11314
			}#if end
11315
 
11316
		#函式說明:
11317
		#複製檔案、資料夾,只要符合權限就會執行並覆蓋既有內容.
11318
		#回傳結果:
11319
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11320
		#$result["error"],錯誤訊息.
11321
		#$result["function"],當前執行的函式名稱.
11322
		#$result["content"],複製好的檔案路徑與名稱.
11323
		#必填參數:
11324
		#$conf["file"],字串,檔案的位置與名稱.
11325
		$conf["cmd::cp"]["file"]=$conf["file"];
11326
		#$conf["to"],字串,檔案要複製到哪裡.
11327
		$conf["cmd::cp"]["to"]=$conf["to"];
11328
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
11329
		$conf["cmd::cp"]["fileArgu"]=$conf["fileArgu"];
11330
		#可省略參數:
11331
		#$conf["cmdOnly"],字串,是否要只允許在cmd環境下運行,預設為"true",代表是;"false"代表沒有限制.
11332
		$conf["cmd::cp"]["cmdOnly"]="false";
11333
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
11334
		#$conf["username"]="";
11335
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
11336
		#$conf["password"]="";
11337
		#參考資料:
11338
		#無.
11339
		#備註:
11340
		#無.
11341
		$cp=cmd::cp($conf["cmd::cp"]);
11342
		unset($conf["cmd::cp"]);
11343
 
11344
		#如果執行異常
11345
		if($cp["status"]==="false"){
11346
 
11347
			#設置執行不正常
11348
			$result["status"]="false";
11349
 
11350
			#設置執行錯誤
11351
			$result["error"]=$cp;
11352
 
11353
			#回傳結果
11354
			return $result;
11355
 
11356
			}#if end
11357
 
11358
		#設置要回傳的 content
11359
		$result["content"]=$cp["content"];
11360
 
11361
		#設置執行正常
11362
		$result["status"]="true";
11363
 
11364
		#回傳結果
11365
		return $result;
11366
 
11367
		}#function cp end
11368
 
11369
	/*
11370
	#函式說明:
3 liveuser 11371
	#分割檔案,分割出來的檔案名稱編號為aa, ab ac...ba, bb, bc...,zx, zy, zz的順序.
11372
	#回傳結果:
11373
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11374
	#$result["error"],錯誤訊息陣列.
11375
	#$result["function"],當前執行的函數名稱.
11376
	#$result["cmd"],執行的指令.
11377
	#$result["content"],執行指令回傳的結果.
11378
	#必填參數:
11379
	#$conf["file"],字串,要分割的檔案名稱.
226 liveuser 11380
	$conf["file"]="";
3 liveuser 11381
	#可省略參數:
11382
	#$conf["splitNameHead"],字串,分割成檔案的名稱開頭,預設為 $conf["file"]."-" .
226 liveuser 11383
	#$conf["splitNameHead"]="";
3 liveuser 11384
	#$conf["partSize"],字串,分割檔的大小為多少?可以為XMB,XGB,XKB,可參見split指令的說明,預設為50MB.
11385
	#$conf["partSize"]="";
11386
	#參考資料:
11387
	#無.
11388
	#備註:
11389
	#需要有split指令
11390
	*/
11391
	public static function split(&$conf=array()){
226 liveuser 11392
 
3 liveuser 11393
		#初始化要回傳的結果
11394
		$result=array();
11395
 
11396
		#取得當前執行的函數名稱
11397
		$result["function"]=__FUNCTION__;
11398
 
11399
		#如果沒有參數
11400
		if(func_num_args()==0){
226 liveuser 11401
 
3 liveuser 11402
			#設置執行失敗
11403
			$result["status"]="false";
226 liveuser 11404
 
3 liveuser 11405
			#設置執行錯誤訊息
11406
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 11407
 
3 liveuser 11408
			#回傳結果
11409
			return $result;
226 liveuser 11410
 
3 liveuser 11411
			}#if end
11412
 
11413
		#函式說明:
11414
		#判斷當前環境為web還是cmd
11415
		#回傳結果:
11416
		#$result,"web"或"cmd"
11417
		if(csInformation::getEnv()==="web"){
226 liveuser 11418
 
3 liveuser 11419
			#設置執行失敗
11420
			$result["status"]="false";
226 liveuser 11421
 
3 liveuser 11422
			#設置執行錯誤訊息
11423
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
226 liveuser 11424
 
3 liveuser 11425
			#回傳結果
11426
			return $result;
226 liveuser 11427
 
3 liveuser 11428
			}#if end
226 liveuser 11429
 
3 liveuser 11430
		#取得參數
11431
		$result["argu"]=$conf;
11432
 
11433
		#如果 $conf 不為陣列
11434
		if(gettype($conf)!=="array"){
226 liveuser 11435
 
3 liveuser 11436
			#設置執行失敗
11437
			$result["status"]="false";
226 liveuser 11438
 
3 liveuser 11439
			#設置執行錯誤訊息
11440
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 11441
 
3 liveuser 11442
			#如果傳入的參數為 null
11443
			if($conf===null){
226 liveuser 11444
 
3 liveuser 11445
				#設置執行錯誤訊息
11446
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 11447
 
3 liveuser 11448
				}#if end
11449
 
11450
			#回傳結果
11451
			return $result;
226 liveuser 11452
 
3 liveuser 11453
			}#if end
226 liveuser 11454
 
3 liveuser 11455
		#檢查參數
11456
		#函式說明:
11457
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
11458
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11459
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11460
		#$result["function"],當前執行的函式名稱.
11461
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11462
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11463
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11464
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11465
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11466
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11467
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11468
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11469
		#必填寫的參數:
11470
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11471
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11472
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11473
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file");
11474
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11475
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
11476
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11477
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11478
		#可以省略的參數:
11479
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11480
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11481
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11482
		#$conf["canNotBeEmpty"]=array();
11483
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11484
		#$conf["canBeEmpty"]=array();
11485
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11486
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11487
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11488
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("splitNameHead","partSize");
226 liveuser 11489
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 11490
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
11491
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]",若後面需要加上內容,則可以再補上\",後面再補上要串接的內容.
11492
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"file\"]\"-","50MB");
11493
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11494
		#$conf["arrayCountEqualCheck"][]=array();
11495
		#參考資料來源:
11496
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11497
		#建議:
11498
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
11499
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11500
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 11501
 
3 liveuser 11502
		#如果檢查參數失敗
11503
		if($checkArguments["status"]==="false"){
226 liveuser 11504
 
3 liveuser 11505
			#設置執行失敗
11506
			$result["status"]="false";
226 liveuser 11507
 
3 liveuser 11508
			#設置錯誤訊息
11509
			$result["error"]=$checkArguments;
226 liveuser 11510
 
3 liveuser 11511
			#回傳結果
11512
			return $result;
226 liveuser 11513
 
3 liveuser 11514
			}#if end
226 liveuser 11515
 
3 liveuser 11516
		#如果要分割的檔案存在
11517
		if(file_exists($conf["file"])){
226 liveuser 11518
 
3 liveuser 11519
			#取得執行的指令
11520
			$result["cmd"]="split -b ".$conf["partSize"]." '".$conf["file"]."' '".$conf["splitNameHead"]."'";
11521
 
11522
			#執行還原的指令
11523
			exec($result["cmd"],$output,$status);
11524
 
11525
			#取得執行後的輸出
11526
			$result["content"]=$output;
226 liveuser 11527
 
3 liveuser 11528
			}#if end
226 liveuser 11529
 
3 liveuser 11530
		#反之
11531
		else{
226 liveuser 11532
 
3 liveuser 11533
			#設置執行失敗
11534
			$result["status"]="false";
226 liveuser 11535
 
3 liveuser 11536
			#設置執行錯誤訊息
11537
			$result["error"][]="要分割的檔案「".$conf["file"]."」不存在";
226 liveuser 11538
 
3 liveuser 11539
			#回傳結果
11540
			return $result;
226 liveuser 11541
 
3 liveuser 11542
			}#else end
226 liveuser 11543
 
3 liveuser 11544
		#設置執行正常
11545
		$result["status"]="true";
226 liveuser 11546
 
3 liveuser 11547
		#回傳結果
11548
		return $result;
226 liveuser 11549
 
3 liveuser 11550
		}#function split end
11551
 
11552
	/*
11553
	#函式說明:
11554
	#合併檔案,檔案編號為aa, ab ac...ba, bb, bc...,zx, zy, zz的順序.
11555
	#回傳結果:
11556
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11557
	#$result["error"],錯誤訊息陣列.
11558
	#$result["function"],當前執行的函數名稱.
11559
	#$result["cmd"],執行的指令.
11560
	#$result["content"],執行指令回傳的結果.
11561
	#必填參數:
11562
	#$conf["filePartHead"],字串,分割檔案的名稱開頭.
11563
	$conf["filePartHead"]="";
11564
	#$conf["oriFileName"],字串,合併後的檔案名稱.
11565
	$conf["oriFileName"]="";
11566
	#可省略參數:
11567
	#無
11568
	#參考資料:
11569
	#無.
11570
	#備註:
11571
	#需要有cat指令.
11572
	#僅能在命令列執行.
11573
	*/
11574
	public static function merge(&$conf=array()){
226 liveuser 11575
 
3 liveuser 11576
		#初始化要回傳的結果
11577
		$result=array();
11578
 
11579
		#取得當前執行的函數名稱
11580
		$result["function"]=__FUNCTION__;
11581
 
11582
		#如果沒有參數
11583
		if(func_num_args()==0){
226 liveuser 11584
 
3 liveuser 11585
			#設置執行失敗
11586
			$result["status"]="false";
226 liveuser 11587
 
3 liveuser 11588
			#設置執行錯誤訊息
11589
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 11590
 
3 liveuser 11591
			#回傳結果
11592
			return $result;
226 liveuser 11593
 
3 liveuser 11594
			}#if end
11595
 
11596
		#函式說明:
11597
		#判斷當前環境為web還是cmd
11598
		#回傳結果:
11599
		#$result,"web"或"cmd"
11600
		if(csInformation::getEnv()==="web"){
226 liveuser 11601
 
3 liveuser 11602
			#設置執行失敗
11603
			$result["status"]="false";
226 liveuser 11604
 
3 liveuser 11605
			#設置執行錯誤訊息
11606
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
226 liveuser 11607
 
3 liveuser 11608
			#回傳結果
11609
			return $result;
226 liveuser 11610
 
3 liveuser 11611
			}#if end
226 liveuser 11612
 
3 liveuser 11613
		#取得參數
11614
		$result["argu"]=$conf;
11615
 
11616
		#如果 $conf 不為陣列
11617
		if(gettype($conf)!=="array"){
226 liveuser 11618
 
3 liveuser 11619
			#設置執行失敗
11620
			$result["status"]="false";
226 liveuser 11621
 
3 liveuser 11622
			#設置執行錯誤訊息
11623
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 11624
 
3 liveuser 11625
			#如果傳入的參數為 null
11626
			if($conf===null){
226 liveuser 11627
 
3 liveuser 11628
				#設置執行錯誤訊息
11629
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 11630
 
3 liveuser 11631
				}#if end
11632
 
11633
			#回傳結果
11634
			return $result;
226 liveuser 11635
 
3 liveuser 11636
			}#if end
226 liveuser 11637
 
3 liveuser 11638
		#檢查參數
11639
		#函式說明:
11640
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
11641
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11642
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11643
		#$result["function"],當前執行的函式名稱.
11644
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11645
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11646
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11647
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11648
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11649
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11650
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11651
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11652
		#必填寫的參數:
11653
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11654
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11655
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11656
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePartHead","oriFileName");
11657
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11658
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
11659
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11660
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11661
		#可以省略的參數:
11662
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11663
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11664
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11665
		#$conf["canNotBeEmpty"]=array();
11666
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11667
		#$conf["canBeEmpty"]=array();
11668
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11669
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11670
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11671
		#$conf["skipableVariableName"]=array();
226 liveuser 11672
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 11673
		#$conf["skipableVariableType"]=array();
11674
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11675
		#$conf["skipableVarDefaultValue"]=array("");
11676
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11677
		#$conf["arrayCountEqualCheck"][]=array();
11678
		#參考資料來源:
11679
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11680
		#建議:
11681
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
11682
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11683
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 11684
 
3 liveuser 11685
		#如果檢查參數失敗
11686
		if($checkArguments["status"]==="false"){
226 liveuser 11687
 
3 liveuser 11688
			#設置執行失敗
11689
			$result["status"]="false";
226 liveuser 11690
 
3 liveuser 11691
			#設置錯誤訊息
11692
			$result["error"]=$checkArguments;
226 liveuser 11693
 
3 liveuser 11694
			#回傳結果
11695
			return $result;
226 liveuser 11696
 
3 liveuser 11697
			}#if end
226 liveuser 11698
 
3 liveuser 11699
		#定義編號
11700
		$charArray=array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","v","u","w","x","y","z");
11701
 
11702
		#定義分割檔案的前置字串
11703
		$filePartHead=$conf["filePartHead"];
11704
 
11705
		#要合併成的檔案名稱
11706
		$oriFileName=$conf["oriFileName"];
11707
 
11708
		#初始化要執行合併的語法
11709
		$restoreCmd="cat ";
11710
 
11711
		#有幾個編號就執行幾次
11712
		for($i=0;$i<count($charArray);$i++){
11713
 
11714
			#有幾個編號就執行幾次
11715
			for($j=0;$j<count($charArray);$j++){
11716
 
11717
				#如果該分割檔存在
11718
				if(file_exists($filePartHead.$charArray[$i].$charArray[$j])){
11719
 
11720
					#串接要還原的分割檔
11721
					$restoreCmd=$restoreCmd." '".$filePartHead.$charArray[$i].$charArray[$j]."'";
11722
 
11723
					}#if end
11724
 
11725
				#反之
11726
				else{
11727
 
11728
					#如果是第一個分割檔就找不到
11729
					if($i===0 && $j===0){
226 liveuser 11730
 
3 liveuser 11731
						#設置執行失敗
11732
						$result["status"]="false";
226 liveuser 11733
 
3 liveuser 11734
						#設置錯誤訊息
11735
						$result["error"][]="找不到第一個分割檔「".$filePartHead.$charArray[$i].$charArray[$j]."」";
226 liveuser 11736
 
3 liveuser 11737
						#回傳結果
11738
						return $result;
226 liveuser 11739
 
3 liveuser 11740
						}#if end
11741
 
11742
					#串接要還原成的檔案名稱
11743
					$restoreCmd=$restoreCmd." > '".$oriFileName."'";
11744
 
11745
					#取得執行的指令
11746
					$result["cmd"]=$restoreCmd;
11747
 
11748
					#執行還原的指令
11749
					exec($restoreCmd,$output,$status);
11750
 
11751
					#取得執行後的輸出
11752
					$result["content"]=$output;
11753
 
11754
					#結束回圈
11755
					break 2;
226 liveuser 11756
 
3 liveuser 11757
					}#else end
11758
 
11759
				}#for end
11760
 
11761
			}#for end
226 liveuser 11762
 
3 liveuser 11763
		#設置執行正常
11764
		$result["status"]="true";
226 liveuser 11765
 
3 liveuser 11766
		#回傳結果
11767
		return $result;
226 liveuser 11768
 
3 liveuser 11769
		}#function merge end
11770
 
11771
	/*
11772
	#函式說明:
11773
	#取得檔案的部分內容
11774
	#回傳結果:
11775
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11776
	#$result["error"],錯誤訊息陣列.
11777
	#$result["function"],當前執行的函數名稱.
11778
	#$result["cmd"],執行的指令.
11779
	#$result["content"],取得的檔案內容.
11780
	#$result["length"],取得的內容長度.
11781
	#$result["EOF"],識別是否已經到檔案結尾,"true"代表是,"false"代表不是.
11782
	#$result["mimeType"],檔案的 mime type.
11783
	#必填參數:
11784
	#$conf["file"],字串,檔案的路徑與名稱.
11785
	$conf["file"]="";
11786
	#$conf["fileArgu"],字串,__FILE__的內容.
11787
	$conf["fileArgu"]=__FILE__;
11788
	#$conf["bytes"],整數字串,要讀取多少bytes.
11789
	$conf["bytes"]="";
11790
	#$conf["startIndex"],要從哪個bytes位置開始,起始點為0.
11791
	$conf["startIndex"]="";
11792
	#可省略參數:
11793
	#無
11794
	#參考資料:
11795
	#無.
11796
	#備註:
11797
	#無
11798
	*/
11799
	public static function getFilePart(&$conf){
226 liveuser 11800
 
3 liveuser 11801
		#初始化要回傳的結果
11802
		$result=array();
11803
 
11804
		#取得當前執行的函數名稱
11805
		$result["function"]=__FUNCTION__;
11806
 
11807
		#如果沒有參數
11808
		if(func_num_args()==0){
11809
 
11810
			#設置執行失敗
11811
			$result["status"]="false";
11812
 
11813
			#設置執行錯誤訊息
11814
			$result["error"]="函數".$result["function"]."需要參數";
11815
 
11816
			#回傳結果
11817
			return $result;
11818
 
11819
			}#if end
226 liveuser 11820
 
3 liveuser 11821
		#取得參數
11822
		$result["argu"]=$conf;
11823
 
11824
		#如果 $conf 不為陣列
11825
		if(gettype($conf)!=="array"){
11826
 
11827
			#設置執行失敗
11828
			$result["status"]="false";
11829
 
11830
			#設置執行錯誤訊息
11831
			$result["error"][]="\$conf變數須為陣列形態";
11832
 
11833
			#如果傳入的參數為 null
11834
			if(is_null($conf)){
11835
 
11836
				#設置執行錯誤訊息
11837
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
11838
 
11839
				}#if end
11840
 
11841
			#回傳結果
11842
			return $result;
11843
 
11844
			}#if end
226 liveuser 11845
 
3 liveuser 11846
		#函式說明:
11847
		#檢查多個檔案與資料夾是否存在.
11848
		#回傳的結果:
11849
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
11850
		#$result["error"],錯誤訊息陣列.
11851
		#$resutl["function"],當前執行的涵式名稱.
11852
		#$result["argu"],使用的參數.
11853
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
11854
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
11855
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
11856
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
11857
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
11858
		#必填參數:
11859
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
11860
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
11861
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11862
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
11863
		#可省略參數:
11864
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
11865
		#$conf["disableWebSearch"]="false";
11866
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
11867
		#$conf["userDir"]="true";
11868
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
11869
		#$conf["web"]="true";
11870
		#參考資料:
11871
		#http://php.net/manual/en/function.file-exists.php
11872
		#http://php.net/manual/en/control-structures.foreach.php
11873
		#備註:
11874
		#函數file_exists檢查的路徑為檔案系統的路徑
11875
		#$result["varName"][$i]結果未實作
11876
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
11877
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 11878
 
3 liveuser 11879
		#如果執行失敗
11880
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 11881
 
3 liveuser 11882
			#設置執行失敗
11883
			$result["status"]="false";
226 liveuser 11884
 
3 liveuser 11885
			#設置執行錯誤訊息
11886
			$result["error"]=$checkMultiFileExist;
226 liveuser 11887
 
3 liveuser 11888
			#回傳結果
11889
			return $result;
226 liveuser 11890
 
3 liveuser 11891
			}#if end
226 liveuser 11892
 
3 liveuser 11893
		#如果檔案不存在
11894
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 11895
 
3 liveuser 11896
			#設置執行失敗
11897
			$result["status"]="false";
226 liveuser 11898
 
3 liveuser 11899
			#設置執行錯誤訊息
11900
			$result["error"]=$checkMultiFileExist;
226 liveuser 11901
 
3 liveuser 11902
			#回傳結果
11903
			return $result;
226 liveuser 11904
 
3 liveuser 11905
			}#if end
226 liveuser 11906
 
3 liveuser 11907
		#取得mimetype
11908
		$mimetype=mime_content_type($conf["file"]);
226 liveuser 11909
 
3 liveuser 11910
		#取得檔案的 mime type
11911
		$result["mimeType"]=$mimetype;
226 liveuser 11912
 
3 liveuser 11913
		#透過 dd 指令,取得部分內容.
11914
		#函式說明:
11915
		#呼叫shell執行系統命令,並取得回傳的內容.
11916
		#回傳結果:
11917
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11918
		#$result["error"],錯誤訊息陣列.
11919
		#$result["function"],當前執行的函數名稱.
11920
		#$result["argu"],使用的參數.
11921
		#$result["cmd"],執行的指令內容.
11922
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11923
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11924
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11925
		#$result["running"],是否還在執行.
11926
		#$result["pid"],pid.
11927
		#$result["statusCode"],執行結束後的代碼.
11928
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11929
		#必填參數:
11930
		#$conf["command"],字串,要執行的指令.
11931
		$conf["external::callShell"]["command"]="dd";
11932
		#$conf["fileArgu"],字串,變數__FILE__的內容.
11933
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
11934
		#可省略參數:
11935
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11936
		$conf["external::callShell"]["argu"]=array("if=".$conf["file"],"bs=".$conf["bytes"],"count=1","status=none");
11937
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11938
		#$conf["arguIsAddr"]=array();
11939
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11940
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11941
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11942
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11943
		#$conf["enablePrintDescription"]="true";
11944
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11945
		#$conf["printDescription"]="";
11946
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11947
		#$conf["escapeshellarg"]="false";
11948
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11949
		#$conf["thereIsShellVar"]=array();
11950
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11951
		#$conf["username"]="";
11952
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11953
		#$conf["password"]="";
11954
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11955
		#$conf["useScript"]="";
11956
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11957
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11958
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11959
		#$conf["inBackGround"]="";
11960
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11961
		#$conf["getErr"]="false";
11962
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11963
		#$conf["doNotRun"]="false";
11964
		#參考資料:
11965
		#exec=>http://php.net/manual/en/function.exec.php
11966
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11967
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11968
		#備註:
11969
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11970
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11971
		$callShell=external::callShell($conf["external::callShell"]);
11972
		unset($conf["external::callShell"]);
226 liveuser 11973
 
3 liveuser 11974
		#如果執行失敗
11975
		if($callShell["status"]==="false"){
226 liveuser 11976
 
3 liveuser 11977
			#設置執行失敗
11978
			$result["status"]="false";
226 liveuser 11979
 
3 liveuser 11980
			#設置執行錯誤訊息
11981
			$result["error"]=$callShell;
226 liveuser 11982
 
3 liveuser 11983
			#回傳結果
11984
			return $result;
226 liveuser 11985
 
3 liveuser 11986
			}#if end
226 liveuser 11987
 
3 liveuser 11988
		#取得結果
11989
		$result["content"]=$callShell["output"][0];
226 liveuser 11990
 
3 liveuser 11991
		#取得內容長度
11992
		$result["length"]=strlen($result["content"]);
226 liveuser 11993
 
11994
		#預設尚未到檔案結尾
3 liveuser 11995
		$result["EOF"]="false";
226 liveuser 11996
 
3 liveuser 11997
		#如果取得的內容長度小於預期
11998
		if($result["length"]<$conf["bytes"]){
226 liveuser 11999
 
3 liveuser 12000
			#設置已經到檔案結尾了
12001
			$result["EOF"]="true";
226 liveuser 12002
 
3 liveuser 12003
			}#if end
226 liveuser 12004
 
3 liveuser 12005
		#設置執行正常
12006
		$result["status"]="true";
226 liveuser 12007
 
3 liveuser 12008
		#回傳結果
12009
		return $result;
226 liveuser 12010
 
3 liveuser 12011
		}#function getFilePart end
12012
 
12013
	/*
12014
	#函式說明:
12015
	#取得節點的資訊.
12016
	#回傳結果:
12017
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12018
	#$result["error"],錯誤訊息陣列.
226 liveuser 12019
	#$result["function"],函數名稱.
3 liveuser 12020
	#$result["content"],檔案資訊陣列.
226 liveuser 12021
	#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 12022
	#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
12023
	#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
12024
	#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
12025
	#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
12026
	#$result["content"]["ownerName"],檔案擁有着資訊.
12027
	#$result["content"]["groupName"],檔案所屬擁有着資訊.
12028
	#$result["content"]["size"],檔案大小.
12029
	#$result["content"]["modifyDate"],檔案變更年月日.
12030
	#$result["content"]["modifyTime"],檔案變更時分秒.
12031
	#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
12032
	#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
12033
	#必填參數:
12034
	#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
12035
	$conf["fileArgu"]=__FILE__;
12036
	#$conf["file"],字串,要查看擁有者資訊的檔案.
12037
	$conf["file"]="";
12038
	#可省略參數:
12039
	#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
12040
	#$conf["web"]="true";
12041
	#參考資料:
12042
	#fileowner=>http://php.net/manual/en/function.fileowner.php
12043
	#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
12044
	#備註:
12045
	#無.
12046
	*/
12047
	public static function fileInfo(&$conf=array()){
226 liveuser 12048
 
3 liveuser 12049
		#初始化要回傳的結果
12050
		$result=array();
12051
 
12052
		#取得當前執行的函數名稱
12053
		$result["function"]=__FUNCTION__;
12054
 
12055
		#如果沒有參數
12056
		if(func_num_args()==0){
226 liveuser 12057
 
3 liveuser 12058
			#設置執行失敗
12059
			$result["status"]="false";
226 liveuser 12060
 
3 liveuser 12061
			#設置執行錯誤訊息
12062
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 12063
 
3 liveuser 12064
			#回傳結果
12065
			return $result;
226 liveuser 12066
 
3 liveuser 12067
			}#if end
12068
 
12069
		#取得參數
12070
		$result["argu"]=$conf;
12071
 
12072
		#如果 $conf 不為陣列
12073
		if(gettype($conf)!=="array"){
226 liveuser 12074
 
3 liveuser 12075
			#設置執行失敗
12076
			$result["status"]="false";
226 liveuser 12077
 
3 liveuser 12078
			#設置執行錯誤訊息
12079
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 12080
 
3 liveuser 12081
			#如果傳入的參數為 null
12082
			if($conf===null){
226 liveuser 12083
 
3 liveuser 12084
				#設置執行錯誤訊息
12085
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12086
 
3 liveuser 12087
				}#if end
12088
 
12089
			#回傳結果
12090
			return $result;
226 liveuser 12091
 
3 liveuser 12092
			}#if end
226 liveuser 12093
 
3 liveuser 12094
		#檢查參數
12095
		#函式說明:
12096
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12097
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12098
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12099
		#$result["function"],當前執行的函式名稱.
12100
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12101
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12102
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12103
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12104
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12105
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12106
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12107
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12108
		#必填寫的參數:
12109
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 12110
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 12111
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12112
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12113
		#可以省略的參數:
12114
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12115
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
12116
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12117
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
12118
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12119
		#$conf["canBeEmptyString"]="false";
12120
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12121
		#$conf["ileAccess::checkArguments"]["canNotBeEmpty"]=array();
12122
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12123
		#$conf["canBeEmpty"]=array();
12124
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12125
		#$conf["skipableVariableCanNotBeEmpty"]=array();
12126
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12127
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 12128
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12129
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
12130
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12131
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
12132
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12133
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12134
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12135
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12136
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12137
		#$conf["arrayCountEqualCheck"][]=array();
12138
		#參考資料來源:
12139
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12140
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12141
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 12142
 
3 liveuser 12143
		#如果檢查參數失敗
12144
		if($checkArguments["status"]==="false"){
226 liveuser 12145
 
3 liveuser 12146
			#設置執行失敗
12147
			$result["status"]="false";
226 liveuser 12148
 
3 liveuser 12149
			#設置執行錯誤訊息
12150
			$result["error"]=$checkArguments;
226 liveuser 12151
 
3 liveuser 12152
			#回傳結果
12153
			return $result;
226 liveuser 12154
 
3 liveuser 12155
			}#if end
226 liveuser 12156
 
3 liveuser 12157
		#如果檢查參數不通過
12158
		if($checkArguments["passed"]==="false"){
226 liveuser 12159
 
3 liveuser 12160
			#設置執行失敗
12161
			$result["status"]="false";
226 liveuser 12162
 
3 liveuser 12163
			#設置執行錯誤訊息
12164
			$result["error"]=$checkArguments;
226 liveuser 12165
 
3 liveuser 12166
			#回傳結果
12167
			return $result;
226 liveuser 12168
 
3 liveuser 12169
			}#if end
226 liveuser 12170
 
3 liveuser 12171
		#函式說明:
12172
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
12173
		#回傳結果:
12174
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12175
		#$result["error"],錯誤訊息陣列.
226 liveuser 12176
		#$result["function"],函數名稱.
3 liveuser 12177
		#$result["argu"],使用的參數.
12178
		#$result["content"],網址,若是在命令列執行,則為"null".
12179
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
12180
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
12181
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
12182
		#必填參數:
12183
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
12184
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["file"];
12185
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
12186
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
12187
		#可省略參數:
12188
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
12189
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
12190
		#備註:
12191
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
12192
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
12193
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 12194
 
3 liveuser 12195
		#如果取得位置失敗
12196
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 12197
 
3 liveuser 12198
			#設置執行失敗
12199
			$result["status"]="false";
226 liveuser 12200
 
3 liveuser 12201
			#設置執行錯誤訊息
12202
			$result["error"]=$getInternetAddressV2;
226 liveuser 12203
 
3 liveuser 12204
			#回傳結果
12205
			return $result;
226 liveuser 12206
 
3 liveuser 12207
			}#if end
12208
 
12209
		#函式說明:
12210
		#檢查多個檔案與資料夾是否存在.
12211
		#回傳的結果:
12212
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
12213
		#$result["error"],錯誤訊息陣列.
12214
		#$resutl["function"],當前執行的涵式名稱.
12215
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
12216
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
12217
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
12218
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
12219
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
12220
		#必填參數:
12221
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
12222
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($getInternetAddressV2["fileSystemAbsoulutePosition"]);
12223
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12224
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
12225
		#可省略參數
12226
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
12227
		#$conf["disableWebSearch"]="false";
12228
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
12229
		#$conf["userDir"]="true";
12230
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
12231
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
12232
		#參考資料來源:
12233
		#http://php.net/manual/en/function.file-exists.php
12234
		#http://php.net/manual/en/control-structures.foreach.php
12235
		#備註:
12236
		#函數file_exists檢查的路徑為檔案系統的路徑
12237
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
12238
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 12239
 
3 liveuser 12240
		#如果檢查檔案存在失敗
12241
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 12242
 
3 liveuser 12243
			#設置執行失敗
12244
			$result["status"]="false";
226 liveuser 12245
 
3 liveuser 12246
			#設置執行錯誤訊息
12247
			$result["error"]=$checkMultiFileExist;
226 liveuser 12248
 
3 liveuser 12249
			#回傳結果
12250
			return $result;
226 liveuser 12251
 
3 liveuser 12252
			}#if end
226 liveuser 12253
 
3 liveuser 12254
		#如果檔案不存在
12255
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 12256
 
3 liveuser 12257
			#設置執行失敗
12258
			$result["status"]="false";
226 liveuser 12259
 
3 liveuser 12260
			#設置執行錯誤訊息
12261
			$result["error"]=$checkMultiFileExist;
226 liveuser 12262
 
3 liveuser 12263
			#回傳結果
12264
			return $result;
226 liveuser 12265
 
3 liveuser 12266
			}#if end
226 liveuser 12267
 
3 liveuser 12268
		#透過ls指令取得檔案的資訊
12269
		#函式說明:
12270
		#呼叫shell執行系統命令,並取得回傳的內容.
12271
		#回傳的結果:
12272
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12273
		#$result["error"],錯誤訊息陣列.
12274
		#$result["function"],當前執行的函數名稱.
12275
		#$result["cmd"],執行的指令內容.
12276
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12277
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12278
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12279
		#$result["running"],是否還在執行.
12280
		#$result["pid"],pid
12281
		#必填的參數
12282
		#$conf["command"],字串,要執行的指令
12283
		$conf["external::callShell"]["command"]="ls";
12284
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12285
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
12286
		#可省略參數:
12287
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12288
		$conf["external::callShell"]["argu"]=array("-l","--full-time","-d",$conf["file"]);
12289
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12290
		$conf["external::callShell"]["arguIsAddr"]=array("false","false","false","false");
12291
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12292
		#$conf["enablePrintDescription"]="true";
12293
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
12294
		#$conf["printDescription"]="";
12295
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
12296
		$conf["external::callShell"]["escapeshellarg"]="true";
12297
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12298
		#$conf["username"]="";
12299
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12300
		#$conf["password"]="";
12301
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12302
		#$conf["useScript"]="";
12303
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12304
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12305
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12306
		#$conf["inBackGround"]="";
12307
		#備註:
12308
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12309
		#參考資料:
12310
		#exec=>http://php.net/manual/en/function.exec.php
12311
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12312
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12313
		$callShell=external::callShell($conf["external::callShell"]);
12314
		unset($conf["external::callShell"]);
226 liveuser 12315
 
3 liveuser 12316
		#如果執行失敗
12317
		if($callShell["status"]==="false"){
226 liveuser 12318
 
3 liveuser 12319
			#設置執行失敗
12320
			$result["status"]="false";
226 liveuser 12321
 
3 liveuser 12322
			#設置執行錯誤訊息
12323
			$result["error"]=$callShell;
226 liveuser 12324
 
3 liveuser 12325
			#回傳結果
12326
			return $result;
226 liveuser 12327
 
12328
			}#if end
12329
 
3 liveuser 12330
		#解析檔案資訊
12331
		#-rwxrwx--x. 1 apache apache 65K 2017-04-16 22:53:19.044545806 +0800 fileAccessT.php
226 liveuser 12332
 
3 liveuser 12333
		#取得權限資訊 -rwxrwx--x
12334
		$perm=substr($callShell["output"][0],0,strpos($callShell["output"][0],'.'));
226 liveuser 12335
 
3 liveuser 12336
		#如果是目錄
12337
		if(substr($perm,0,1)==="d"){
226 liveuser 12338
 
3 liveuser 12339
			#設定為目錄
12340
			$result["content"]["is_folder"]="true";
226 liveuser 12341
 
3 liveuser 12342
			}#if end
226 liveuser 12343
 
3 liveuser 12344
		#反之
12345
		else{
226 liveuser 12346
 
3 liveuser 12347
			#設定不為目錄
12348
			$result["content"]["is_folder"]="false";
226 liveuser 12349
 
3 liveuser 12350
			}#else end
226 liveuser 12351
 
3 liveuser 12352
		#解析檔案擁有者權限資訊
12353
		$result["content"]["ownerPerm"]=substr($perm,1,3);
226 liveuser 12354
 
3 liveuser 12355
		#如果檔案擁有者名稱為空
12356
		if(empty($result["content"]["ownerPerm"])){
226 liveuser 12357
 
3 liveuser 12358
			#設置執行失敗
12359
			$result["status"]="false";
226 liveuser 12360
 
3 liveuser 12361
			#設置執行錯誤訊息
12362
			$result["error"]=$callShell;
226 liveuser 12363
 
3 liveuser 12364
			#回傳結果
12365
			return $result;
226 liveuser 12366
 
3 liveuser 12367
			}#if end
226 liveuser 12368
 
3 liveuser 12369
		#解析檔案歸屬群組權限資訊
12370
		$result["content"]["groupPerm"]=substr($perm,4,3);
226 liveuser 12371
 
3 liveuser 12372
		#解析檔案對於其他身份使用者的權限資訊
12373
		$result["content"]["otherPerm"]=substr($perm,7,3);
226 liveuser 12374
 
3 liveuser 12375
		#取得目錄底下的檔案目錄數量起始點
12376
		$subElementStartPos=strpos($callShell["output"][0],' ');
226 liveuser 12377
 
3 liveuser 12378
		#取得目錄底下的檔案目錄數量結束點
12379
		$subElementEndPos=strpos($callShell["output"][0],' ',$subElementStartPos+1);
226 liveuser 12380
 
3 liveuser 12381
		#取得目錄底下的檔案目錄數量
12382
		$result["content"]["subElementCount"]=substr($callShell["output"][0],$subElementStartPos,$subElementEndPos-$subElementStartPos);
226 liveuser 12383
 
3 liveuser 12384
		#取得檔案擁有着資訊的起點
12385
		$ownerNameStrPos=strpos($callShell["output"][0],' ',$subElementEndPos)+1;
226 liveuser 12386
 
3 liveuser 12387
		#取得檔案擁有着資訊的結束點
12388
		$ownerNameEndPos=strpos($callShell["output"][0],' ',$ownerNameStrPos+1);
226 liveuser 12389
 
3 liveuser 12390
		#取得檔案擁有着資訊
12391
		$result["content"]["ownerName"]=substr($callShell["output"][0],$ownerNameStrPos,$ownerNameEndPos-$ownerNameStrPos);
226 liveuser 12392
 
3 liveuser 12393
		#取取得檔案群組擁有者資訊的起點
12394
		$groupNameStrPos=strpos($callShell["output"][0],' ',$ownerNameEndPos)+1;
226 liveuser 12395
 
3 liveuser 12396
		#取得檔案群組擁有者資訊的結束點
12397
		$groupNameEndPos=strpos($callShell["output"][0],' ',$groupNameStrPos);
226 liveuser 12398
 
3 liveuser 12399
		#取得檔案群組擁有者資訊
12400
		$result["content"]["groupName"]=substr($callShell["output"][0],$groupNameStrPos,$groupNameEndPos-$groupNameStrPos);
226 liveuser 12401
 
3 liveuser 12402
		#取得檔案大小的起點
12403
		$sizeStrPos=strpos($callShell["output"][0],' ',$groupNameEndPos)+1;
226 liveuser 12404
 
3 liveuser 12405
		#取得檔案大小的結束點
12406
		$sizeEndPos=strpos($callShell["output"][0],' ',$sizeStrPos);
226 liveuser 12407
 
3 liveuser 12408
		#取得檔案大小
12409
		$result["content"]["size"]=substr($callShell["output"][0],$sizeStrPos,$sizeEndPos-$sizeStrPos);
226 liveuser 12410
 
3 liveuser 12411
		#取得檔案變更年月日的起點
12412
		$modifyDateStrPos=strpos($callShell["output"][0],' ',$sizeEndPos)+1;
226 liveuser 12413
 
3 liveuser 12414
		#取得檔案變更年月日的結束點
12415
		$modifyDateEndPos=strpos($callShell["output"][0],' ',$modifyDateStrPos);
226 liveuser 12416
 
12417
		#取得檔案變更年月日
3 liveuser 12418
		$result["content"]["modifyDate"]=substr($callShell["output"][0],$modifyDateStrPos,$modifyDateEndPos-$modifyDateStrPos);
226 liveuser 12419
 
3 liveuser 12420
		#取得檔案變更時分秒的起點
12421
		$modifyTimeStrPos=strpos($callShell["output"][0],' ',$modifyDateEndPos)+1;
226 liveuser 12422
 
3 liveuser 12423
		#取得檔案變更時分秒的結束點
12424
		$modifyTimeEndPos=strpos($callShell["output"][0],'.',$modifyTimeStrPos);
226 liveuser 12425
 
3 liveuser 12426
		#取得檔案變更時分秒
12427
		$result["content"]["modifyTime"]=substr($callShell["output"][0],$modifyTimeStrPos,$modifyTimeEndPos-$modifyTimeStrPos);
226 liveuser 12428
 
3 liveuser 12429
		#取得檔版變更時間秒的float數值起點
12430
		$modifyTimeFloatStrPos=strpos($callShell["output"][0],'.',$modifyTimeEndPos)+1;
226 liveuser 12431
 
3 liveuser 12432
		#取得檔版變更時間秒的float數值結束點
12433
		$modifyTimeFloatEndPos=strpos($callShell["output"][0],' ',$modifyTimeFloatStrPos);
226 liveuser 12434
 
12435
		#取得檔版變更時間秒的float數值
3 liveuser 12436
		$result["content"]["modifyTimeFloat"]=substr($callShell["output"][0],$modifyTimeFloatStrPos,$modifyTimeFloatEndPos-$modifyTimeFloatStrPos);
226 liveuser 12437
 
3 liveuser 12438
		#取得時區起始點
12439
		$timezoneStrPos=strpos($callShell["output"][0],' ',$modifyTimeFloatEndPos)+1;
226 liveuser 12440
 
3 liveuser 12441
		#取得時區結束點
226 liveuser 12442
		$timezoneEndPos=strpos($callShell["output"][0],' ',$timezoneStrPos)+1;
12443
 
3 liveuser 12444
		#取得檔案變更時間的時區與UTC的差距.
226 liveuser 12445
		$result["content"]["timezone"]=substr($callShell["output"][0],$timezoneStrPos,$timezoneEndPos-$timezoneStrPos);
12446
 
3 liveuser 12447
		#設置執行正常
12448
		$result["status"]="true";
226 liveuser 12449
 
3 liveuser 12450
		#回傳結果
12451
		return $result;
226 liveuser 12452
 
3 liveuser 12453
		}#function fileInfo end
12454
 
12455
	/*
12456
	#函式說明:
226 liveuser 12457
	#依據函數getListTree執行的結果,將其底下與其子目錄底下的特定檔案內容依據目錄層級輸出成html檔案
3 liveuser 12458
	#回傳結果:
12459
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12460
	#$result["error"],錯誤訊息陣列.
226 liveuser 12461
	#$result["function"],函數名稱.
3 liveuser 12462
	#$result["content"],html檔案輸出的位置與名稱.
12463
	#必填參數:
12464
	#$conf["getListTree"],陣列變數,函數getListTree執行的結果.
12465
	$conf["getListTree"]=$getListTree;
12466
	#可省略參數:
12467
	#$conf["fileToRead"],字串,要讀取的檔案名稱為何?預設為"help".
12468
	#$conf["fileToRead"]="help";
12469
	#$conf["output"],字串,輸出的網頁檔案位置與名稱,副檔名html會自動補上,預設為"help".
226 liveuser 12470
	#$conf["output"]="help.html";
3 liveuser 12471
	#參考資料:
12472
	#無.
12473
	#備註:
12474
	#建構中...
12475
	*/
12476
	public static function createHelpFile($conf){
226 liveuser 12477
 
3 liveuser 12478
		#初始化要回傳的結果
12479
		$result=array();
226 liveuser 12480
 
3 liveuser 12481
		#設置當其函數名稱
12482
		$result["function"]=__FUNCTION__;
226 liveuser 12483
 
3 liveuser 12484
		#如果 $conf 不為陣列
12485
		if(gettype($conf)!="array"){
226 liveuser 12486
 
3 liveuser 12487
			#設置執行失敗
12488
			$result["status"]="false";
226 liveuser 12489
 
3 liveuser 12490
			#設置執行錯誤訊息
12491
			$result["error"][]="\$conf變數須為陣列形態";
12492
 
12493
			#如果傳入的參數為 null
12494
			if($conf==null){
226 liveuser 12495
 
3 liveuser 12496
				#設置執行錯誤訊息
12497
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12498
 
3 liveuser 12499
				}#if end
12500
 
12501
			#回傳結果
12502
			return $result;
226 liveuser 12503
 
3 liveuser 12504
			}#if end
226 liveuser 12505
 
3 liveuser 12506
		#檢查參數
12507
		#函式說明:
12508
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12509
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12510
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12511
		#$result["function"],當前執行的函式名稱.
12512
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12513
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12514
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12515
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
12516
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12517
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12518
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12519
		#必填寫的參數:
12520
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12521
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12522
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12523
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("getListTree");
226 liveuser 12524
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 12525
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
12526
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12527
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12528
		#可以省略的參數:
12529
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
12530
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
12531
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12532
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileToRead","output");
226 liveuser 12533
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12534
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
12535
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12536
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("help","help");
12537
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12538
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
12539
		#參考資料來源:
12540
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12541
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12542
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 12543
 
3 liveuser 12544
		#如果 $checkResult["status"] 等於 "fasle"
12545
		if($checkResult["status"]=="false"){
226 liveuser 12546
 
3 liveuser 12547
			#設置錯誤識別
12548
			$result["status"]="false";
226 liveuser 12549
 
3 liveuser 12550
			#設置錯誤訊息
12551
			$result["error"]=$checkResult;
226 liveuser 12552
 
3 liveuser 12553
			#回傳結果
12554
			return $result;
226 liveuser 12555
 
3 liveuser 12556
			}#if end
226 liveuser 12557
 
3 liveuser 12558
		#如果 $checkResult["passed"] 等於 "fasle"
12559
		if($checkResult["passed"]=="false"){
226 liveuser 12560
 
3 liveuser 12561
			#設置錯誤識別
12562
			$result["status"]="false";
226 liveuser 12563
 
3 liveuser 12564
			#設置錯誤訊息
12565
			$result["error"]=$checkResult;
226 liveuser 12566
 
3 liveuser 12567
			#回傳結果
12568
			return $result;
226 liveuser 12569
 
3 liveuser 12570
			}#if end
226 liveuser 12571
 
3 liveuser 12572
		#如果 $conf["getListTree"]["status"] 不存在
12573
		if(!isset($conf["getListTree"]["status"])){
226 liveuser 12574
 
3 liveuser 12575
			#設置錯誤識別
12576
			$result["status"]="false";
226 liveuser 12577
 
3 liveuser 12578
			#設置錯誤訊息
12579
			$result["error"][]="getListTree參數必須為getListTree函數執行後的結果";
226 liveuser 12580
 
3 liveuser 12581
			#回傳結果
12582
			return $result;
226 liveuser 12583
 
3 liveuser 12584
			}#if end
226 liveuser 12585
 
3 liveuser 12586
		#如果 $conf["getListTree"] 執行失敗
12587
		if($conf["getListTree"]["status"]=="false"){
226 liveuser 12588
 
3 liveuser 12589
			#設置錯誤識別
12590
			$result["status"]="false";
226 liveuser 12591
 
3 liveuser 12592
			#設置錯誤訊息
12593
			$result["error"]=$conf["getListTree"];
226 liveuser 12594
 
3 liveuser 12595
			#回傳結果
12596
			return $result;
226 liveuser 12597
 
3 liveuser 12598
			}#if end
226 liveuser 12599
 
3 liveuser 12600
		#如果有目錄檔案
12601
		if(isset($conf["getListTree"]["content"])){
226 liveuser 12602
 
12603
 
12604
 
3 liveuser 12605
			}#if end
226 liveuser 12606
 
3 liveuser 12607
		}#function createHelpFile end
226 liveuser 12608
 
3 liveuser 12609
	/*
12610
	#函式說明:
12611
	#嵌入pdf檔案到網頁上面
12612
	#回傳結果:
12613
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12614
	#$result["error"],錯誤訊息陣列.
226 liveuser 12615
	#$result["function"],函數名稱.
3 liveuser 12616
	#$result["content"],嵌入pdf檔案的語法
12617
	#必填參數:
12618
	#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
12619
	$conf["fileArgu"]=__FILE__;
12620
	#$conf["file"],字串,pdf檔案位置.
12621
	$conf["file"]="";
12622
	#可省略參數:
12623
	#$conf["type"],字串,要用"iframe"還是"object"的方式嵌入pdf檔案,預設為"iframe".
12624
	#$conf["type"]="iframe";
12625
	#參考資料:
12626
	#嵌入pdf到網頁=>https://stackoverflow.com/questions/14690000/embed-a-pdf-in-html5
12627
	#備註:
12628
	#如果是網址就會出錯.
12629
	*/
12630
	public static function embedPdf(&$conf=array()){
226 liveuser 12631
 
3 liveuser 12632
		#初始化要回傳的結果
12633
		$result=array();
12634
 
12635
		#取得當前執行的函數名稱
12636
		$result["function"]=__FUNCTION__;
12637
 
12638
		#如果沒有參數
12639
		if(func_num_args()==0){
226 liveuser 12640
 
3 liveuser 12641
			#設置執行失敗
12642
			$result["status"]="false";
226 liveuser 12643
 
3 liveuser 12644
			#設置執行錯誤訊息
12645
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 12646
 
3 liveuser 12647
			#回傳結果
12648
			return $result;
226 liveuser 12649
 
3 liveuser 12650
			}#if end
12651
 
12652
		#取得參數
12653
		$result["argu"]=$conf;
12654
 
12655
		#如果 $conf 不為陣列
12656
		if(gettype($conf)!=="array"){
226 liveuser 12657
 
3 liveuser 12658
			#設置執行失敗
12659
			$result["status"]="false";
226 liveuser 12660
 
3 liveuser 12661
			#設置執行錯誤訊息
12662
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 12663
 
3 liveuser 12664
			#如果傳入的參數為 null
12665
			if($conf===null){
226 liveuser 12666
 
3 liveuser 12667
				#設置執行錯誤訊息
12668
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12669
 
3 liveuser 12670
				}#if end
12671
 
12672
			#回傳結果
12673
			return $result;
226 liveuser 12674
 
3 liveuser 12675
			}#if end
226 liveuser 12676
 
3 liveuser 12677
		#檢查參數
12678
		#函式說明:
12679
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12680
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12681
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12682
		#$result["function"],當前執行的函式名稱.
12683
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12684
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12685
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12686
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12687
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12688
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12689
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12690
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12691
		#必填寫的參數:
12692
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12693
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12694
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12695
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
12696
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12697
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
12698
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12699
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12700
		#可以省略的參數:
12701
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12702
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
12703
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12704
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("function");
12705
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12706
		#$conf["canBeEmpty"]=array();
12707
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12708
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("width","height");
12709
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12710
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("type");
226 liveuser 12711
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12712
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
12713
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12714
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("iframe");
12715
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12716
		#$conf["arrayCountEqualCheck"][]=array();
12717
		#參考資料來源:
12718
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12719
		#建議:
12720
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
12721
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
226 liveuser 12722
		unset($conf["variableCheck::checkArguments"]);
12723
 
3 liveuser 12724
		#如果檢查參數失敗
12725
		if($checkArguments["status"]==="false"){
226 liveuser 12726
 
3 liveuser 12727
			#設置執行失敗
12728
			$result["status"]="false";
226 liveuser 12729
 
3 liveuser 12730
			#設置執行錯誤訊息
12731
			$result["error"]=$checkArguments;
226 liveuser 12732
 
3 liveuser 12733
			#回傳結果
12734
			return $result;
226 liveuser 12735
 
3 liveuser 12736
			}#if end
226 liveuser 12737
 
3 liveuser 12738
		#如果參數檢查不通過
12739
		if($checkArguments["passed"]==="false"){
226 liveuser 12740
 
3 liveuser 12741
			#設置執行失敗
12742
			$result["status"]="false";
226 liveuser 12743
 
3 liveuser 12744
			#設置執行錯誤訊息
12745
			$result["error"]=$checkArguments;
226 liveuser 12746
 
3 liveuser 12747
			#回傳結果
12748
			return $result;
226 liveuser 12749
 
3 liveuser 12750
			}#if end
226 liveuser 12751
 
3 liveuser 12752
		#檢查檔案是否存在
12753
		#函式說明:
12754
		#檢查多個檔案與資料夾是否存在.
12755
		#回傳的結果:
12756
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
12757
		#$result["error"],錯誤訊息陣列.
12758
		#$resutl["function"],當前執行的涵式名稱.
12759
		#$result["argu"],使用的參數.
12760
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
12761
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
12762
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
12763
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
12764
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
12765
		#必填參數:
12766
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
12767
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
12768
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12769
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
12770
		#可省略參數
12771
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
12772
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="false";
12773
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
12774
		#$conf["userDir"]="true";
12775
		#參考資料來源:
12776
		#http://php.net/manual/en/function.file-exists.php
12777
		#http://php.net/manual/en/control-structures.foreach.php
12778
		#備註:
12779
		#函數file_exists檢查的路徑為檔案系統的路徑
12780
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
12781
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 12782
 
3 liveuser 12783
		#如果檢查檔案是否存在失敗
12784
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 12785
 
3 liveuser 12786
			#設置執行失敗
12787
			$result["status"]="false";
226 liveuser 12788
 
3 liveuser 12789
			#設置執行錯誤訊息
12790
			$result["error"]=$checkMultiFileExist;
226 liveuser 12791
 
3 liveuser 12792
			#回傳結果
12793
			return $result;
226 liveuser 12794
 
3 liveuser 12795
			}#if end
226 liveuser 12796
 
3 liveuser 12797
		#如果檔案不存在
12798
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 12799
 
3 liveuser 12800
			#設置執行失敗
12801
			$result["status"]="false";
226 liveuser 12802
 
3 liveuser 12803
			#設置執行錯誤訊息
12804
			$result["error"]=$checkMultiFileExist;
226 liveuser 12805
 
3 liveuser 12806
			#回傳結果
12807
			return $result;
226 liveuser 12808
 
3 liveuser 12809
			}#if end
226 liveuser 12810
 
3 liveuser 12811
		#產生 base64 的 pdf 編碼字串
12812
		$base64pdf=base64_encode(file_get_contents($conf["file"]));
226 liveuser 12813
 
3 liveuser 12814
		#產生 base64 的 pdf 編碼字串 data
12815
		$base64pdfData="data:application/pdf;base64,".$base64pdf;
226 liveuser 12816
 
3 liveuser 12817
		#判斷要用哪種方式嵌入pdf
12818
		switch($conf["type"]){
226 liveuser 12819
 
3 liveuser 12820
			#如果是用 object 方式
12821
			case "object":
226 liveuser 12822
 
3 liveuser 12823
				#產生嵌入的語法
12824
				$embedSyntax="<object style=\"width:100%;height:100%;\" data=\"".$base64pdfData."\"></object>";
226 liveuser 12825
 
3 liveuser 12826
				#取得語法
12827
				$result["content"]=&$embedSyntax;
226 liveuser 12828
 
3 liveuser 12829
				#跳出 switch
12830
				break;
226 liveuser 12831
 
3 liveuser 12832
			#預設
12833
			default:
226 liveuser 12834
 
3 liveuser 12835
				#產生嵌入的語法
12836
				$embedSyntax="<iframe style=\"width:100%;height:100%;\" src=\"".$base64pdfData."\"></iframe>";
226 liveuser 12837
 
3 liveuser 12838
				#取得語法
12839
				$result["content"]=&$embedSyntax;
226 liveuser 12840
 
3 liveuser 12841
			}#switch end
226 liveuser 12842
 
3 liveuser 12843
		#設置執行正常
12844
		$result["status"]="true";
226 liveuser 12845
 
3 liveuser 12846
		#回傳結果
12847
		return $result;
226 liveuser 12848
 
3 liveuser 12849
		}#function embedPdf end
226 liveuser 12850
 
3 liveuser 12851
	/*
12852
	#函式說明:
226 liveuser 12853
	#用linux unzip去解壓縮zip檔案
3 liveuser 12854
	#回傳結果:
12855
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12856
	#$result["error"],錯誤訊息.
12857
	#$result["function"],當前執行的函數名稱.
12858
	#$result["content"]["each"],每個檔案的資訊.
12859
	#$result["content"]["each"]["Length"][$i],各別檔案目錄的原始長度.
12860
	#$result["content"]["each"]["Method"][$i],各別檔案目錄的壓縮方法.
12861
	#$result["content"]["each"]["Size"][$i],各別檔案目錄的壓縮後長度.
12862
	#$result["content"]["each"]["Cmpr"][$i],各別檔案目錄的壓縮率.
12863
	#$result["content"]["each"]["Date"][$i],各別檔案目錄的最後修改日期.
12864
	#$result["content"]["each"]["Time"][$i],各別檔案目錄的最後修改時間.
12865
	#$result["content"]["each"]["CRC-32"][$i],各別檔案目錄的CRC-32檢查碼.
12866
	#$result["content"]["each"]["Name"][$i],各別檔案目錄的路徑與名稱.
12867
	#$result["content"]["total"],統整的資訊.
12868
	#$result["content"]["Length"],總共的檔案長度.
12869
	#$result["content"]["Size"],壓縮後的檔案長度.
12870
	#$result["content"]["Cmpr"],平均壓縮率.
12871
	#$result["content"]["count"],壓縮檔裡面總共的檔案跟目錄數目.
12872
	#必填參數;
12873
	#$conf["zip"],字串,要解壓縮的zip檔案.
12874
	$conf["zip"]="";
12875
	#$conf["fileArgu"],字串,__FILE__的內容.
12876
	$conf["fileArgu"]=__FILE__;
12877
	#可省略參數:
12878
	#$conf["extract"],字串,要解壓縮到那個路徑,預設為當前位置"./".
12879
	#$conf["extract"]="";
12880
	#備註:
12881
	#建議加上特定邊碼的支援例如、單
12882
	*/
12883
	public static function unzip(&$conf=array()){
226 liveuser 12884
 
3 liveuser 12885
		#初始化要回傳的結果
12886
		$result=array();
12887
 
12888
		#取得當前執行的函數名稱
12889
		$result["function"]=__FUNCTION__;
12890
 
12891
		#如果沒有參數
12892
		if(func_num_args()==0){
226 liveuser 12893
 
3 liveuser 12894
			#設置執行失敗
12895
			$result["status"]="false";
226 liveuser 12896
 
3 liveuser 12897
			#設置執行錯誤訊息
12898
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 12899
 
3 liveuser 12900
			#回傳結果
12901
			return $result;
226 liveuser 12902
 
3 liveuser 12903
			}#if end
226 liveuser 12904
 
3 liveuser 12905
		#取得參數
12906
		$result["argu"]=$conf;
12907
 
12908
		#如果 $conf 不為陣列
12909
		if(gettype($conf)!=="array"){
226 liveuser 12910
 
3 liveuser 12911
			#設置執行失敗
12912
			$result["status"]="false";
226 liveuser 12913
 
3 liveuser 12914
			#設置執行錯誤訊息
12915
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 12916
 
3 liveuser 12917
			#如果傳入的參數為 null
12918
			if($conf===null){
226 liveuser 12919
 
3 liveuser 12920
				#設置執行錯誤訊息
12921
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12922
 
3 liveuser 12923
				}#if end
12924
 
12925
			#回傳結果
12926
			return $result;
226 liveuser 12927
 
3 liveuser 12928
			}#if end
226 liveuser 12929
 
3 liveuser 12930
		#檢查參數
12931
		#函式說明:
12932
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12933
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12934
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12935
		#$result["function"],當前執行的函式名稱.
12936
		#$result["argu"],設置給予的參數.
12937
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12938
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12939
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12940
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12941
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12942
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12943
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12944
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12945
		#必填寫的參數:
12946
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 12947
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 12948
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12949
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12950
		#可以省略的參數:
12951
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12952
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("zip","fileArgu");
12953
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12954
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
12955
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12956
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
12957
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12958
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("zip","fileArgu");
12959
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12960
		#$conf["canBeEmpty"]=array();
12961
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12962
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("extract");
12963
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12964
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("extract");
226 liveuser 12965
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12966
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
12967
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12968
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("./");
12969
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12970
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12971
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12972
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12973
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12974
		#$conf["arrayCountEqualCheck"][]=array();
12975
		#參考資料來源:
12976
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12977
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12978
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 12979
 
3 liveuser 12980
		#如果檢查參數失敗
12981
		if($checkArguments["status"]==="false"){
226 liveuser 12982
 
3 liveuser 12983
			#設置執行不正常
12984
			$result["status"]="false";
226 liveuser 12985
 
3 liveuser 12986
			#設置錯誤訊息
12987
			$result["error"]=$checkArguments;
226 liveuser 12988
 
3 liveuser 12989
			#回傳結果
12990
			return $result;
226 liveuser 12991
 
3 liveuser 12992
			}#if end
226 liveuser 12993
 
3 liveuser 12994
		#如果檢查參數不通過
12995
		if($checkArguments["passed"]==="false"){
226 liveuser 12996
 
3 liveuser 12997
			#設置執行不正常
12998
			$result["status"]="false";
226 liveuser 12999
 
3 liveuser 13000
			#設置錯誤訊息
13001
			$result["error"]=$checkArguments;
226 liveuser 13002
 
3 liveuser 13003
			#回傳結果
13004
			return $result;
226 liveuser 13005
 
3 liveuser 13006
			}#if end
226 liveuser 13007
 
3 liveuser 13008
		#檢查要解壓縮的檔案是否存在
13009
		#函式說明:
13010
		#檢查多個檔案與資料夾是否存在.
13011
		#回傳的結果:
13012
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13013
		#$result["error"],錯誤訊息陣列.
13014
		#$resutl["function"],當前執行的涵式名稱.
13015
		#$result["argu"],使用的參數.
13016
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
13017
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
13018
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
13019
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
13020
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
13021
		#必填參數:
13022
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
13023
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["zip"]);
13024
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13025
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
13026
		#可省略參數
13027
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
13028
		#$conf["disableWebSearch"]="false";
13029
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
13030
		#$conf["userDir"]="true";
13031
		#參考資料來源:
13032
		#http://php.net/manual/en/function.file-exists.php
13033
		#http://php.net/manual/en/control-structures.foreach.php
13034
		#備註:
13035
		#函數file_exists檢查的路徑為檔案系統的路徑
13036
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
13037
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 13038
 
3 liveuser 13039
		#如果檢查檔案是否存在失敗
13040
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 13041
 
3 liveuser 13042
			#設置執行不正常
13043
			$result["status"]="false";
226 liveuser 13044
 
3 liveuser 13045
			#設置錯誤訊息
13046
			$result["error"]=$checkMultiFileExist;
226 liveuser 13047
 
3 liveuser 13048
			#回傳結果
13049
			return $result;
226 liveuser 13050
 
3 liveuser 13051
			}#if end
226 liveuser 13052
 
3 liveuser 13053
		#如果要解壓縮的檔案不存在
13054
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 13055
 
3 liveuser 13056
			#設置執行不正常
13057
			$result["status"]="false";
226 liveuser 13058
 
3 liveuser 13059
			#設置錯誤訊息
13060
			$result["error"]=$checkMultiFileExist;
226 liveuser 13061
 
3 liveuser 13062
			#回傳結果
13063
			return $result;
226 liveuser 13064
 
3 liveuser 13065
			}#if end
226 liveuser 13066
 
3 liveuser 13067
		#函式說明:
13068
		#呼叫shell執行系統命令,並取得回傳的內容.
13069
		#回傳結果:
13070
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13071
		#$result["error"],錯誤訊息陣列.
13072
		#$result["function"],當前執行的函數名稱.
13073
		#$result["argu"],使用的參數.
13074
		#$result["cmd"],執行的指令內容.
13075
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
13076
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
13077
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
13078
		#$result["running"],是否還在執行.
13079
		#$result["pid"],pid
13080
		#必填參數:
13081
		#$conf["command"],字串,要執行的指令與.
13082
		$conf["external::callShell"]["command"]="unzip";
13083
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 13084
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 13085
		#可省略參數:
13086
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
13087
		$conf["external::callShell"]["argu"]=array("-d",$conf["extract"],"-o","-q",$conf["zip"]);
13088
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
13089
		#$conf["arguIsAddr"]=array();
13090
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
13091
		#$conf["enablePrintDescription"]="true";
13092
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
13093
		#$conf["printDescription"]="";
13094
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
13095
		$conf["external::callShell"]["escapeshellarg"]="true";
13096
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
13097
		#$conf["username"]="";
13098
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
13099
		#$conf["password"]="";
13100
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
13101
		#$conf["useScript"]="";
13102
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
13103
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
13104
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
13105
		#$conf["inBackGround"]="";
13106
		#備註:
13107
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
13108
		#參考資料:
13109
		#exec=>http://php.net/manual/en/function.exec.php
13110
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
13111
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
13112
		$callShell=external::callShell($conf["external::callShell"]);
13113
		unset($conf["external::callShell"]);
226 liveuser 13114
 
3 liveuser 13115
		#如果執行cmd失敗
13116
		if($callShell["status"]==="false"){
226 liveuser 13117
 
3 liveuser 13118
			#設置執行不正常
13119
			$result["status"]="false";
226 liveuser 13120
 
3 liveuser 13121
			#設置錯誤訊息
13122
			$result["error"]=$callShell;
226 liveuser 13123
 
3 liveuser 13124
			#回傳結果
13125
			return $result;
226 liveuser 13126
 
3 liveuser 13127
			}#if end
226 liveuser 13128
 
3 liveuser 13129
		#函式說明:
13130
		#呼叫shell執行系統命令,並取得回傳的內容.
13131
		#回傳的結果:
13132
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13133
		#$result["error"],錯誤訊息陣列.
13134
		#$result["function"],當前執行的函數名稱.
13135
		#$result["argu"],使用的參數.
13136
		#$result["cmd"],執行的指令內容.
13137
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
13138
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
13139
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
13140
		#$result["running"],是否還在執行.
13141
		#$result["pid"],pid
13142
		#必填的參數
13143
		#$conf["command"],字串,要執行的指令與.
13144
		$conf["external::callShell"]["command"]="unzip";
13145
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 13146
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 13147
		#可省略參數:
13148
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
13149
		$conf["external::callShell"]["argu"]=array("-v",$conf["zip"]);
13150
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
13151
		#$conf["arguIsAddr"]=array();
13152
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
13153
		#$conf["enablePrintDescription"]="true";
13154
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
13155
		#$conf["printDescription"]="";
13156
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
13157
		$conf["external::callShell"]["escapeshellarg"]="true";
13158
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
13159
		#$conf["username"]="";
13160
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
13161
		#$conf["password"]="";
13162
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
13163
		#$conf["useScript"]="";
13164
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
13165
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
13166
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
13167
		#$conf["inBackGround"]="";
13168
		#備註:
13169
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
13170
		#參考資料:
13171
		#exec=>http://php.net/manual/en/function.exec.php
13172
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
13173
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
13174
		$callShell=external::callShell($conf["external::callShell"]);
13175
		unset($conf["external::callShell"]);
226 liveuser 13176
 
3 liveuser 13177
		#如果執行cmd失敗
13178
		if($callShell["status"]==="false"){
226 liveuser 13179
 
3 liveuser 13180
			#設置執行不正常
13181
			$result["status"]="false";
226 liveuser 13182
 
3 liveuser 13183
			#設置錯誤訊息
13184
			$result["error"]=$callShell;
226 liveuser 13185
 
3 liveuser 13186
			#回傳結果
13187
			return $result;
226 liveuser 13188
 
13189
			}#if end
13190
 
3 liveuser 13191
		#取得輸出的內容陣列
13192
		$unzipInfo=$callShell["output"];
226 liveuser 13193
 
3 liveuser 13194
		/*
226 liveuser 13195
 
3 liveuser 13196
		 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
13197
		--------  ------  ------- ---- ---------- ----- --------  ----
13198
		 4194304  Defl:X  2507269  40% 05-04-2002 17:30 9386a740  PS2 Bios 30004R V6 Pal.bin
13199
			   4  Defl:X        6 -50% 05-15-2005 06:45 054a6ec2  PS2 Bios 30004R V6 Pal.MEC
13200
			1024  Defl:X       22  98% 06-25-2005 14:55 3493bb06  PS2 Bios 30004R V6 Pal.NVM
13201
		  199680  Defl:X    70524  65% 06-02-2004 16:50 2c3bcd32  rom1.bin
13202
		 4194304  Defl:X  2637496  37% 02-20-2005 21:12 6f8e3c29  SCPH-70004_BIOS_V12_PAL_200.BIN
13203
		 3145728  Defl:X  3138427   0% 02-20-2005 21:12 bf3cbc65  SCPH-70004_BIOS_V12_PAL_200.EROM
13204
			1024  Defl:X      706  31% 02-20-2005 21:12 a8d51ead  SCPH-70004_BIOS_V12_PAL_200.NVM
13205
		  524288  Defl:X   149924  71% 02-20-2005 21:12 0e8797c0  SCPH-70004_BIOS_V12_PAL_200.ROM1
13206
		  524288  Defl:X   149924  71% 02-20-2005 21:12 0e8797c0  SCPH-70004_BIOS_V12_PAL_200.ROM2
13207
		 4194304  Defl:X  2213105  47% 10-18-2000 06:06 b7ef81a9  scph10000.bin
13208
			1024  Defl:X       11  99% 01-01-2005 00:42 efb5af2e  scph10000.NVM
13209
		 4194304  Defl:X  2511182  40% 06-27-2003 10:51 a19e0bf5  scph39001.bin
13210
			   4  Defl:X        6 -50% 05-14-2005 16:00 054a6ec2  scph39001.MEC
13211
			1024  Defl:X       20  98% 05-31-2005 16:09 e14a6cd6  scph39001.NVM
13212
		--------          -------  ---                            -------
13213
		21175304         13378622  37%                            14 files
226 liveuser 13214
 
3 liveuser 13215
		*/
226 liveuser 13216
 
3 liveuser 13217
		#取得行數
13218
		$lineCount=count($unzipInfo);
226 liveuser 13219
 
3 liveuser 13220
		#取得標題
13221
		#函式說明:
13222
		#將固定格式的字串分開,並回傳分開的結果。
13223
		#回傳結果:
13224
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13225
		#$result["error"],錯誤訊息陣列
13226
		#$result["function"],當前執行的函數名稱.
13227
		#$result["oriStr"],要分割的原始字串內容
13228
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13229
		#$result["dataCounts"],爲總共分成幾段
13230
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13231
		#必填參數:
13232
		$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[1];#要處理的字串。
13233
		$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13234
		#可省略參數:
13235
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13236
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13237
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13238
		unset($conf["stringProcess::spiltString"]);
226 liveuser 13239
 
3 liveuser 13240
		#如果分割字串失敗
13241
		if($spiltString["status"]==="false"){
226 liveuser 13242
 
3 liveuser 13243
			#設置執行不正常
13244
			$result["status"]="false";
226 liveuser 13245
 
3 liveuser 13246
			#設置錯誤訊息
13247
			$result["error"]=$spiltString;
226 liveuser 13248
 
3 liveuser 13249
			#回傳結果
13250
			return $result;
226 liveuser 13251
 
3 liveuser 13252
			}#if end
226 liveuser 13253
 
3 liveuser 13254
		#如果沒有分割用的關鍵字
13255
		if($spiltString["found"]==="false"){
226 liveuser 13256
 
3 liveuser 13257
			#設置執行不正常
13258
			$result["status"]="false";
226 liveuser 13259
 
3 liveuser 13260
			#設置錯誤訊息
13261
			$result["error"]=$spiltString;
226 liveuser 13262
 
3 liveuser 13263
			#回傳結果
13264
			return $result;
226 liveuser 13265
 
3 liveuser 13266
			}#if end
226 liveuser 13267
 
3 liveuser 13268
		#取得標題欄位
226 liveuser 13269
		$titles=$spiltString["dataArray"];
13270
 
3 liveuser 13271
		#取得標題欄位數目
13272
		$titleCount=$spiltString["dataCounts"];
226 liveuser 13273
 
3 liveuser 13274
		#針對每列輸出
13275
		for($i=3;$i<$lineCount-2;$i++){
226 liveuser 13276
 
3 liveuser 13277
			#取得各欄位的內容
13278
			#函式說明:
13279
			#將固定格式的字串分開,並回傳分開的結果。
13280
			#回傳結果:
13281
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13282
			#$result["error"],錯誤訊息陣列
13283
			#$result["function"],當前執行的函數名稱.
13284
			#$result["oriStr"],要分割的原始字串內容
13285
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13286
			#$result["dataCounts"],爲總共分成幾段
13287
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13288
			#必填參數:
13289
			$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[$i];#要處理的字串。
13290
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13291
			#可省略參數:
13292
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13293
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13294
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13295
			unset($conf["stringProcess::spiltString"]);
226 liveuser 13296
 
3 liveuser 13297
			#如果分割字串失敗
13298
			if($spiltString["status"]==="false"){
226 liveuser 13299
 
3 liveuser 13300
				#設置執行不正常
13301
				$result["status"]="false";
226 liveuser 13302
 
3 liveuser 13303
				#設置錯誤訊息
13304
				$result["error"]=$spiltString;
226 liveuser 13305
 
3 liveuser 13306
				#回傳結果
13307
				return $result;
226 liveuser 13308
 
3 liveuser 13309
				}#if end
226 liveuser 13310
 
3 liveuser 13311
			#如果沒有分割用的關鍵字
13312
			if($spiltString["found"]==="false"){
226 liveuser 13313
 
3 liveuser 13314
				#設置執行不正常
13315
				$result["status"]="false";
226 liveuser 13316
 
3 liveuser 13317
				#設置錯誤訊息
13318
				$result["error"]=$spiltString;
226 liveuser 13319
 
3 liveuser 13320
				#回傳結果
13321
				return $result;
226 liveuser 13322
 
3 liveuser 13323
				}#if end
226 liveuser 13324
 
3 liveuser 13325
			#取得各欄位的內容
13326
			$cols=$spiltString["dataArray"];
226 liveuser 13327
 
3 liveuser 13328
			#取得欄位的數目
13329
			$colsCount=$spiltString["dataCounts"];
226 liveuser 13330
 
3 liveuser 13331
			#如果實際抓出的內容欄位數量大於標題欄位數量,代表檔案/目錄名稱含有空格
13332
			if($colsCount>$titleCount){
226 liveuser 13333
 
3 liveuser 13334
				#新的檔案名稱
13335
				$newFileName="";
226 liveuser 13336
 
3 liveuser 13337
				#針對每個多出的欄位
13338
				for($j=$titleCount;$j<$colsCount;$j++){
226 liveuser 13339
 
3 liveuser 13340
					#串接屬於檔案名稱的部分
13341
					$newFileName=$newFileName.$cols[$j];
226 liveuser 13342
 
3 liveuser 13343
					#如果不是最後一個項目
13344
					if($j!==$colsCount-1){
226 liveuser 13345
 
3 liveuser 13346
						#增加空格
13347
						$newFileName=$newFileName." ";
226 liveuser 13348
 
3 liveuser 13349
						}#if end
226 liveuser 13350
 
3 liveuser 13351
					}#for end
226 liveuser 13352
 
3 liveuser 13353
				#取代成對的檔案名稱
13354
				$cols[$titleCount-1]=$newFileName;
226 liveuser 13355
 
3 liveuser 13356
				}#if end
226 liveuser 13357
 
3 liveuser 13358
			#針對每個欄位
13359
			for($j=0;$j<$titleCount;$j++){
226 liveuser 13360
 
3 liveuser 13361
				#取得欄位內容
13362
				$result["content"]["each"][$titles[$j]][]=$cols[$j];
226 liveuser 13363
 
3 liveuser 13364
				}#for end
226 liveuser 13365
 
3 liveuser 13366
			}#for end
226 liveuser 13367
 
3 liveuser 13368
		#取得 total 的輸出內容
13369
		#函式說明:
13370
		#將固定格式的字串分開,並回傳分開的結果。
13371
		#回傳結果:
13372
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13373
		#$result["error"],錯誤訊息陣列
13374
		#$result["function"],當前執行的函數名稱.
13375
		#$result["oriStr"],要分割的原始字串內容
13376
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13377
		#$result["dataCounts"],爲總共分成幾段
13378
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13379
		#必填參數:
13380
		$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[$lineCount-1];#要處理的字串。
13381
		$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13382
		#可省略參數:
13383
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13384
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13385
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13386
		unset($conf["stringProcess::spiltString"]);
226 liveuser 13387
 
3 liveuser 13388
		#如果分割字串失敗
13389
		if($spiltString["status"]==="false"){
226 liveuser 13390
 
3 liveuser 13391
			#設置執行不正常
13392
			$result["status"]="false";
226 liveuser 13393
 
3 liveuser 13394
			#設置錯誤訊息
13395
			$result["error"]=$spiltString;
226 liveuser 13396
 
3 liveuser 13397
			#回傳結果
13398
			return $result;
226 liveuser 13399
 
3 liveuser 13400
			}#if end
226 liveuser 13401
 
3 liveuser 13402
		#如果沒有分割用的關鍵字
13403
		if($spiltString["found"]==="false"){
226 liveuser 13404
 
3 liveuser 13405
			#設置執行不正常
13406
			$result["status"]="false";
226 liveuser 13407
 
3 liveuser 13408
			#設置錯誤訊息
13409
			$result["error"]=$spiltString;
226 liveuser 13410
 
3 liveuser 13411
			#回傳結果
13412
			return $result;
226 liveuser 13413
 
3 liveuser 13414
			}#if end
226 liveuser 13415
 
3 liveuser 13416
		#取得各欄位的內容
13417
		$cols=$spiltString["dataArray"];
226 liveuser 13418
 
3 liveuser 13419
		#取得總共的檔案長度
13420
		$result["content"]["total"][$titles[0]]=$cols[0];
226 liveuser 13421
 
3 liveuser 13422
		#取得壓縮時的總共檔案長度
13423
		$result["content"]["total"][$titles[2]]=$cols[1];
226 liveuser 13424
 
3 liveuser 13425
		#取得壓縮時的總共檔案長度
13426
		$result["content"]["total"][$titles[3]]=$cols[2];
226 liveuser 13427
 
3 liveuser 13428
		#取得解壓縮出了多少檔案跟目錄
13429
		$result["content"]["total"]["count"]=explode(" ",$cols[3])[0];
226 liveuser 13430
 
3 liveuser 13431
		#設置執行正常
13432
		$result["status"]="true";
226 liveuser 13433
 
3 liveuser 13434
		#回傳結果
13435
		return $result;
226 liveuser 13436
 
3 liveuser 13437
		}#function unzip end
226 liveuser 13438
 
3 liveuser 13439
	/*
13440
	#函式說明:
13441
	#接收Range: bytes=0-499格式的header, 輸出檔案的片段或完整檔案.
13442
	#回傳結果:
13443
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13444
	#$result["error"],錯誤訊息.
13445
	#$result["function"],當前執行的函式名稱.
13446
	#必填參數:
13447
	#$conf["filePath"],字串,檔案的路徑.
13448
	$conf["filePath"]="";
13449
	#可省略參數:
13450
	#$conf["fileName"],字串,顯示的檔案名稱,預設為basename($conf["filePath"]);
13451
	#$conf["fileName"]="";
13452
	#參考資料:
13453
	#https://gdfan1114.wordpress.com/2015/01/14/php-%E5%AF%A6%E4%BD%9C%E6%94%AF%E6%8F%B4-http-%E7%BA%8C%E5%82%B3%E5%8A%9F%E8%83%BD/
13454
	#http://php.net/manual/en/function.filemtime.php
13455
	#http://php.net/manual/en/function.connection-status.php
13456
	#http://php.net/manual/en/function.fread.php
13457
	#備註:
13458
	#請勿在運行該函式前印出任何內容,這是要給用戶端接收的內容.
13459
	*/
13460
	public static function partDownload(&$conf=array()){
226 liveuser 13461
 
3 liveuser 13462
		#初始化要回傳的結果
13463
		$result=array();
13464
 
13465
		#取得當前執行的函數名稱
13466
		$result["function"]=__FUNCTION__;
13467
 
13468
		#如果沒有參數
13469
		if(func_num_args()==0){
226 liveuser 13470
 
3 liveuser 13471
			#設置執行失敗
13472
			$result["status"]="false";
226 liveuser 13473
 
3 liveuser 13474
			#設置執行錯誤訊息
13475
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 13476
 
3 liveuser 13477
			#回傳結果
13478
			return $result;
226 liveuser 13479
 
3 liveuser 13480
		}#if end
226 liveuser 13481
 
3 liveuser 13482
		#取得參數
13483
		$result["argu"]=$conf;
13484
 
13485
		#如果 $conf 不為陣列
13486
		if(gettype($conf)!=="array"){
226 liveuser 13487
 
3 liveuser 13488
			#設置執行失敗
13489
			$result["status"]="false";
226 liveuser 13490
 
3 liveuser 13491
			#設置執行錯誤訊息
13492
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 13493
 
3 liveuser 13494
			#如果傳入的參數為 null
13495
			if($conf===null){
226 liveuser 13496
 
3 liveuser 13497
				#設置執行錯誤訊息
13498
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 13499
 
3 liveuser 13500
				}#if end
13501
 
13502
			#回傳結果
13503
			return $result;
226 liveuser 13504
 
3 liveuser 13505
			}#if end
226 liveuser 13506
 
3 liveuser 13507
		#檢查參數
13508
		#函式說明:
13509
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13510
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13511
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13512
		#$result["function"],當前執行的函式名稱.
13513
		#$result["argu"],設置給予的參數.
13514
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13515
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13516
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13517
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13518
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13519
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13520
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13521
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13522
		#必填寫的參數:
13523
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 13524
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 13525
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13526
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13527
		#可以省略的參數:
13528
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13529
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePath");
13530
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13531
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
13532
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13533
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
13534
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13535
		#$conf["canNotBeEmpty"]=array();
13536
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13537
		#$conf["canBeEmpty"]=array();
13538
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13539
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("fileName");
13540
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13541
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileName");
226 liveuser 13542
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 13543
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
13544
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13545
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
13546
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
13547
		#$conf["disallowAllSkipableVarIsEmpty"]="";
13548
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
13549
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
13550
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13551
		#$conf["arrayCountEqualCheck"][]=array();
13552
		#參考資料來源:
13553
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13554
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
13555
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 13556
 
3 liveuser 13557
		#如果檢查參數失敗
13558
		if($checkArguments["status"]==="false"){
226 liveuser 13559
 
3 liveuser 13560
			#設置執行失敗
13561
			$result["status"]="false";
226 liveuser 13562
 
3 liveuser 13563
			#設置執行錯誤
13564
			$result["error"]=$checkArguments;
226 liveuser 13565
 
3 liveuser 13566
			#回傳結果
13567
			return $result;
226 liveuser 13568
 
3 liveuser 13569
			}#if end
226 liveuser 13570
 
3 liveuser 13571
		#如果檢查參數不通過
13572
		if($checkArguments["passed"]==="false"){
226 liveuser 13573
 
3 liveuser 13574
			#設置執行失敗
13575
			$result["status"]="false";
226 liveuser 13576
 
3 liveuser 13577
			#設置執行錯誤
13578
			$result["error"]=$checkArguments;
226 liveuser 13579
 
3 liveuser 13580
			#回傳結果
13581
			return $result;
226 liveuser 13582
 
3 liveuser 13583
			}#if end
226 liveuser 13584
 
3 liveuser 13585
		#如果沒有設置 $conf["fileName"]
13586
		if(!isset($conf["fileName"])){
226 liveuser 13587
 
3 liveuser 13588
			#取得檔案名稱
13589
			$filename=basename($conf["filePath"]);
226 liveuser 13590
 
3 liveuser 13591
			}#if end
226 liveuser 13592
 
3 liveuser 13593
		#反之
13594
		else{
226 liveuser 13595
 
3 liveuser 13596
			#取得設定好的檔案名稱
13597
			$filename=&$conf["fileName"];
226 liveuser 13598
 
3 liveuser 13599
			}#else end
226 liveuser 13600
 
3 liveuser 13601
		#取得檔案路徑
13602
		$location=$conf["filePath"];
13603
 
13604
		#取得mimetype
13605
		$mimetype=mime_content_type($location);
226 liveuser 13606
 
3 liveuser 13607
		#如果檔案不存在
13608
		if(!file_exists($location)){
226 liveuser 13609
 
3 liveuser 13610
			#提示找不到檔案
13611
			header("HTTP/1.1 404 Not Found");
226 liveuser 13612
 
3 liveuser 13613
			#設置執行失敗
13614
			$result["status"]="false";
226 liveuser 13615
 
3 liveuser 13616
			#設置錯誤訊息
13617
			$result["error"][]="檔案 ".$location." 不存在.";
226 liveuser 13618
 
3 liveuser 13619
			#回傳結果
13620
			return $result;
226 liveuser 13621
 
3 liveuser 13622
			}#if end
13623
 
13624
		#取得檔案的bytes長度
13625
		$size  = filesize($location);
226 liveuser 13626
 
3 liveuser 13627
		#取得檔案的最後變更日期
13628
		$time  = date('r', filemtime($location));
13629
 
13630
		#讀取檔案的2元碼內容
13631
		$fm = @fopen($location, 'rb');
226 liveuser 13632
 
3 liveuser 13633
		#如果開啟檔案失敗
13634
		if(!$fm){
226 liveuser 13635
 
3 liveuser 13636
			#提示錯誤
13637
			header("HTTP/1.1 505 Internal server error");
226 liveuser 13638
 
3 liveuser 13639
			#設置執行失敗
13640
			$result["status"]="false";
226 liveuser 13641
 
3 liveuser 13642
			#設置錯誤訊息
13643
			$result["error"][]="開啟檔案 ".$location." 失敗.";
226 liveuser 13644
 
3 liveuser 13645
			#回傳結果
13646
			return $result;
226 liveuser 13647
 
3 liveuser 13648
			}#if end
13649
 
13650
		#初始化要提供的bytes長度起始點
13651
		$begin  = 0;
226 liveuser 13652
 
3 liveuser 13653
		#初始化要提供的bytes長度結束點
13654
		$end  = $size - 1;
13655
 
13656
		#如果有接收到 'HTTP_RANGE' 的 header 訊息
13657
		if(isset($_SERVER['HTTP_RANGE'])){
226 liveuser 13658
 
3 liveuser 13659
			#接收到的範例
226 liveuser 13660
			#Range: bytes=0-499
13661
 
3 liveuser 13662
			#取得要求的bytes位置範圍
13663
			sscanf($_SERVER['HTTP_RANGE'], "bytes=%d-%d",$begin,$end);
226 liveuser 13664
 
3 liveuser 13665
			#如果 $begin 或 $end  有缺
13666
			if(!isset($begin) || !isset($end)){
226 liveuser 13667
 
3 liveuser 13668
				#設置執行失敗
13669
				$result["status"]="false";
226 liveuser 13670
 
3 liveuser 13671
				#設置錯誤訊息
13672
				$result["error"][]="header \"Range\" 的數值格式為 \"bytes=0-499\"";
226 liveuser 13673
 
3 liveuser 13674
				#回傳結果
13675
				return $result;
226 liveuser 13676
 
3 liveuser 13677
				}#if end
226 liveuser 13678
 
3 liveuser 13679
			#如果 $begin 沒有小於等於 $end
13680
			if(!($begin<=$end)){
226 liveuser 13681
 
3 liveuser 13682
				#設置執行失敗
13683
				$result["status"]="false";
226 liveuser 13684
 
3 liveuser 13685
				#設置錯誤訊息
13686
				$result["error"][]="header \"Range\" 的數值格式為 \"bytes=0-499\"";
226 liveuser 13687
 
3 liveuser 13688
				#回傳結果
13689
				return $result;
226 liveuser 13690
 
3 liveuser 13691
				}#if end
226 liveuser 13692
 
3 liveuser 13693
			}#if end
226 liveuser 13694
 
3 liveuser 13695
		#提示 200 ok
13696
		header('HTTP/1.1 200 OK');
226 liveuser 13697
 
3 liveuser 13698
		#提示 mimetype
13699
		header("Content-Type: $mimetype");
226 liveuser 13700
 
3 liveuser 13701
		#要先驗證cache中的資料,取得的內容放在快取的時間為0
13702
		header('Cache-Control: public, must-revalidate, max-age=0');
226 liveuser 13703
 
3 liveuser 13704
		#提示不要cache
226 liveuser 13705
		header('Pragma: no-cache');
13706
 
3 liveuser 13707
		#提示接收的 Ranges 單位為 bytes
13708
		header('Accept-Ranges: bytes');
226 liveuser 13709
 
3 liveuser 13710
		#數值傳輸的內容長度為多少
13711
		header('Content-Length:' . (($end - $begin) + 1));
226 liveuser 13712
 
3 liveuser 13713
		#提示內容為檔案的哪邊到哪邊與總共的長度
13714
		header("Content-Range: bytes $begin-$end/$size");
226 liveuser 13715
 
3 liveuser 13716
		#提示檔案的名稱
13717
		header("Content-Disposition: inline; filename=$filename");
226 liveuser 13718
 
3 liveuser 13719
		#提示用2元碼傳輸
13720
		header("Content-Transfer-Encoding: binary");
226 liveuser 13721
 
3 liveuser 13722
		#提示檔案最後變更日期
13723
		header("Last-Modified: $time");
13724
 
13725
		#初始化當前位置
13726
		$cur  = $begin;
226 liveuser 13727
 
13728
		#指定讀取的起始點為 $begin
3 liveuser 13729
		fseek($fm, $begin, 0);
13730
 
13731
		#讀取內容, 若不是檔案結尾, 且當前位置($cur)小於等於 本次要提供的長度結尾($end), 且connection_status為0
13732
		while(!feof($fm) && $cur<=$end && (connection_status()===0)){
226 liveuser 13733
 
3 liveuser 13734
			#一次最多印出 1024*16bytes 的長度,若剩下長度不足則只印出剩下的長度.
13735
			echo fread($fm, min(1024 * 16, ($end - $cur) + 1));
226 liveuser 13736
 
3 liveuser 13737
			#更改位置
13738
			$cur += 1024 * 16;
226 liveuser 13739
 
3 liveuser 13740
			}#while end
226 liveuser 13741
 
3 liveuser 13742
		}#function partDownload end
226 liveuser 13743
 
3 liveuser 13744
	/*
13745
	#函式說明:
226 liveuser 13746
	#尋找檔案.
3 liveuser 13747
	#回傳結果:
13748
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13749
	#$result["error"],錯誤訊息.
13750
	#$result["warning"],警告訊息陣列.
13751
	#$result["function"],當前執行的函數名稱.
13752
	#$result["argu"],所使用的參數.
13753
	#$result["found"],是否有找到可以轉換的檔案,"true"代表有;"false"代表沒有.
13754
	#$result["content"],找到的檔案陣列.
13755
	#必填參數:
13756
	#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
13757
	$conf["keyWord"]="";
13758
	#$conf["path"],字串陣列,虛擬硬碟檔案的搜尋路徑,預設為當前路徑.
13759
	$conf["path"]=array();
13760
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13761
	$conf["fileArgu"]=__FILE__;
13762
	#參考資料:
13763
	#http://php.net/manual/en/function.glob.php
13764
	#備註:
13765
	#無.
13766
	*/
13767
	public static function findFile(&$conf=array()){
226 liveuser 13768
 
3 liveuser 13769
		#初始化要回傳的結果
13770
		$result=array();
13771
 
13772
		#取得當前執行的函數名稱
13773
		$result["function"]=__FUNCTION__;
13774
 
13775
		#如果沒有參數
13776
		if(func_num_args()==0){
226 liveuser 13777
 
3 liveuser 13778
			#設置執行失敗
13779
			$result["status"]="false";
226 liveuser 13780
 
3 liveuser 13781
			#設置執行錯誤訊息
13782
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 13783
 
3 liveuser 13784
			#回傳結果
13785
			return $result;
13786
 
226 liveuser 13787
			}#if end
13788
 
3 liveuser 13789
		#取得參數
13790
		$result["argu"]=$conf;
13791
 
13792
		#如果 $conf 不為陣列
13793
		if(gettype($conf)!=="array"){
226 liveuser 13794
 
3 liveuser 13795
			#設置執行失敗
13796
			$result["status"]="false";
226 liveuser 13797
 
3 liveuser 13798
			#設置執行錯誤訊息
13799
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 13800
 
3 liveuser 13801
			#如果傳入的參數為 null
13802
			if($conf===null){
226 liveuser 13803
 
3 liveuser 13804
				#設置執行錯誤訊息
13805
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 13806
 
3 liveuser 13807
				}#if end
13808
 
13809
			#回傳結果
13810
			return $result;
226 liveuser 13811
 
3 liveuser 13812
			}#if end
226 liveuser 13813
 
3 liveuser 13814
		#函式說明:
13815
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13816
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13817
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13818
		#$result["function"],當前執行的函式名稱.
13819
		#$result["argu"],設置給予的參數.
13820
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13821
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13822
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13823
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13824
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13825
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13826
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13827
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13828
		#必填寫的參數:
13829
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 13830
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 13831
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13832
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13833
		#可以省略的參數:
13834
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13835
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","keyWord","fileArgu");
13836
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13837
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
13838
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13839
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
13840
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13841
		#$conf["canNotBeEmpty"]=array();
13842
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13843
		#$conf["canBeEmpty"]=array();
13844
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13845
		#$conf["skipableVariableCanNotBeEmpty"]=array();
13846
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13847
		#$conf["skipableVariableName"]=array();
226 liveuser 13848
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 13849
		#$conf["skipableVariableType"]=array();
13850
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13851
		#$conf["skipableVarDefaultValue"]=array("");
13852
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
13853
		#$conf["disallowAllSkipableVarIsEmpty"]="";
13854
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
13855
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
13856
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13857
		#$conf["arrayCountEqualCheck"][]=array();
13858
		#參考資料來源:
13859
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13860
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
13861
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 13862
 
3 liveuser 13863
		#如果檢查參數失敗
13864
		if($checkArguments["status"]==="false"){
226 liveuser 13865
 
3 liveuser 13866
			#設置執行失敗
13867
			$result["status"]="false";
226 liveuser 13868
 
3 liveuser 13869
			#設置執行失敗訊息
13870
			$result["error"]=$checkArguments;
226 liveuser 13871
 
3 liveuser 13872
			#回傳結果
13873
			return $result;
226 liveuser 13874
 
3 liveuser 13875
			}#if end
226 liveuser 13876
 
3 liveuser 13877
		#如果檢查參數不通過
13878
		if($checkArguments["passed"]==="false"){
226 liveuser 13879
 
3 liveuser 13880
			#設置執行失敗
13881
			$result["status"]="false";
226 liveuser 13882
 
3 liveuser 13883
			#設置執行失敗訊息
13884
			$result["error"]=$checkArguments;
226 liveuser 13885
 
3 liveuser 13886
			#回傳結果
13887
			return $result;
226 liveuser 13888
 
3 liveuser 13889
			}#if end
226 liveuser 13890
 
3 liveuser 13891
		#檢查要搜尋的路徑是否都存在
13892
		#函式說明:
13893
		#s檢查多個檔案與資料夾是否存在.
13894
		#回傳的結果:
13895
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13896
		#$result["error"],錯誤訊息陣列.
13897
		#$resutl["function"],當前執行的涵式名稱.
13898
		#$result["argu"],使用的參數.
13899
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
13900
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
13901
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
13902
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
13903
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
13904
		#必填參數:
13905
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
13906
		$conf["self::checkMultiFileExist"]["fileArray"]=$conf["path"];
13907
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13908
		$conf["self::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
13909
		#可省略參數
13910
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
13911
		#$conf["disableWebSearch"]="false";
13912
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
13913
		#$conf["userDir"]="true";
13914
		#參考資料來源:
13915
		#http://php.net/manual/en/function.file-exists.php
13916
		#http://php.net/manual/en/control-structures.foreach.php
13917
		#備註:
13918
		#函數file_exists檢查的路徑為檔案系統的路徑
13919
		$checkMultiFileExist=self::checkMultiFileExist($conf["self::checkMultiFileExist"]);
13920
		unset($conf["self::checkMultiFileExist"]);
226 liveuser 13921
 
3 liveuser 13922
		#如果檢查目錄存在失敗
13923
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 13924
 
3 liveuser 13925
			#設置執行失敗
13926
			$result["status"]="false";
226 liveuser 13927
 
3 liveuser 13928
			#設置執行失敗訊息
13929
			$result["error"]=$checkMultiFileExist;
226 liveuser 13930
 
3 liveuser 13931
			#回傳結果
13932
			return $result;
226 liveuser 13933
 
13934
			}#if end
13935
 
3 liveuser 13936
		#如果目錄不存在
13937
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 13938
 
3 liveuser 13939
			#設置執行失敗
13940
			$result["status"]="false";
226 liveuser 13941
 
3 liveuser 13942
			#設置執行失敗訊息
13943
			$result["error"]=$checkMultiFileExist;
226 liveuser 13944
 
3 liveuser 13945
			#回傳結果
13946
			return $result;
226 liveuser 13947
 
3 liveuser 13948
			}#if end
226 liveuser 13949
 
3 liveuser 13950
		#如果有路徑不存在
13951
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 13952
 
3 liveuser 13953
			#設置執行失敗
13954
			$result["status"]="false";
226 liveuser 13955
 
3 liveuser 13956
			#設置執行失敗訊息
13957
			$result["error"]=$checkMultiFileExist;
226 liveuser 13958
 
3 liveuser 13959
			#設置提示有路徑不存在的訊息
13960
			$result["warning"][]="參數path的路徑沒有每個都存在";
226 liveuser 13961
 
3 liveuser 13962
			#回傳結果
13963
			return $result;
226 liveuser 13964
 
3 liveuser 13965
			}#if end
226 liveuser 13966
 
3 liveuser 13967
		#預設沒有找到檔案
226 liveuser 13968
		$result["found"]="false";
13969
 
3 liveuser 13970
		#針對每個要搜尋的路徑
13971
		foreach($conf["path"] as $path){
226 liveuser 13972
 
3 liveuser 13973
			#函式說明:
13974
			#用find指令尋找檔案
13975
			#回傳結果:
13976
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13977
			#$result["error"],錯誤訊息.
13978
			#$result["function"],當前執行的函數名稱.
13979
			#$result["argu"],所使用的參數.
13980
			#$result["found"],是否有找到符合的檔案,"true"代表有;"false"代表沒有.
13981
			#$result["content"],找到的檔案陣列.
13982
			#必填參數:
13983
			#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
226 liveuser 13984
			$conf["cmd::find"]["keyWord"]=$conf["keyWord"];
3 liveuser 13985
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13986
			$conf["cmd::find"]["fileArgu"]=$conf["fileArgu"];
13987
			#可省略參數:
13988
			#$conf["path"],字串,搜尋的路徑,預設為"/".
13989
			$conf["cmd::find"]["path"]=$path;
13990
			#$conf["fileOnly"],字串,"true"代表只要找檔案,"false"代表.
13991
			$conf["cmd::find"]["fileOnly"]="true";
13992
			#參考資料:
13993
			#http://php.net/manual/en/function.glob.php
13994
			$find=cmd::find($conf["cmd::find"]);
13995
			unset($conf["cmd::find"]);
226 liveuser 13996
 
3 liveuser 13997
			#如果尋找檔案失敗
13998
			if($find["status"]==="false"){
226 liveuser 13999
 
3 liveuser 14000
				#設置執行失敗
14001
				$result["status"]="false";
226 liveuser 14002
 
3 liveuser 14003
				#設置執行失敗訊息
14004
				$result["error"]=$find;
226 liveuser 14005
 
3 liveuser 14006
				#回傳結果
14007
				return $result;
226 liveuser 14008
 
3 liveuser 14009
				}#if end
226 liveuser 14010
 
3 liveuser 14011
			#如果有找到符合的檔案
14012
			if($find["found"]==="true"){
226 liveuser 14013
 
3 liveuser 14014
				#設置有找到檔案
14015
				$result["found"]="true";
226 liveuser 14016
 
3 liveuser 14017
				#針對每個找到的檔案
14018
				foreach($find["content"] as $filtedFile){
226 liveuser 14019
 
3 liveuser 14020
					#設置有找到的檔案
14021
					$result["content"][]=$filtedFile;
226 liveuser 14022
 
3 liveuser 14023
					}#foreach end
226 liveuser 14024
 
3 liveuser 14025
				}#if end
226 liveuser 14026
 
14027
			}#foreach end
14028
 
3 liveuser 14029
		#設置執行正常
14030
		$result["status"]="true";
226 liveuser 14031
 
3 liveuser 14032
		#回傳結果
14033
		return $result;
226 liveuser 14034
 
3 liveuser 14035
		}#function findFile end
14036
 
14037
	/*
14038
	#函式說明:
14039
	#判斷檔案位於哪個分割區
14040
	#回傳結果:
14041
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14042
	#$result["error"],錯誤訊息.
14043
	#$result["function"],當前執行的函數名稱.
14044
	#$result["argu"],所使用的參數.
14045
	#$result["content"],找到的檔案所屬分割區資訊.
14046
	#必填參數:
14047
	#$conf["file"],字串,檔案的路徑與名稱.
14048
	$conf["file"]="";
14049
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14050
	$conf["fileArgu"]=__FILE__;
14051
	#可省略參數:
14052
	#無.
14053
	#參考資料:
14054
	#無.
14055
	#備註:
14056
	#無.
14057
	*/
14058
	public static function addrInMountPoint(&$conf=array()){
226 liveuser 14059
 
3 liveuser 14060
		#初始化要回傳的結果
14061
		$result=array();
14062
 
14063
		#取得當前執行的函數名稱
14064
		$result["function"]=__FUNCTION__;
14065
 
14066
		#如果沒有參數
14067
		if(func_num_args()==0){
226 liveuser 14068
 
3 liveuser 14069
			#設置執行失敗
14070
			$result["status"]="false";
226 liveuser 14071
 
3 liveuser 14072
			#設置執行錯誤訊息
14073
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14074
 
3 liveuser 14075
			#回傳結果
14076
			return $result;
14077
 
226 liveuser 14078
			}#if end
14079
 
3 liveuser 14080
		#取得參數
14081
		$result["argu"]=$conf;
14082
 
14083
		#如果 $conf 不為陣列
14084
		if(gettype($conf)!=="array"){
226 liveuser 14085
 
3 liveuser 14086
			#設置執行失敗
14087
			$result["status"]="false";
226 liveuser 14088
 
3 liveuser 14089
			#設置執行錯誤訊息
14090
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14091
 
3 liveuser 14092
			#如果傳入的參數為 null
14093
			if($conf===null){
226 liveuser 14094
 
3 liveuser 14095
				#設置執行錯誤訊息
14096
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14097
 
3 liveuser 14098
				}#if end
14099
 
14100
			#回傳結果
14101
			return $result;
226 liveuser 14102
 
3 liveuser 14103
			}#if end
226 liveuser 14104
 
3 liveuser 14105
		#函式說明:
14106
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14107
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14108
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14109
		#$result["function"],當前執行的函式名稱.
14110
		#$result["argu"],設置給予的參數.
14111
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14112
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14113
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14114
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14115
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14116
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14117
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14118
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14119
		#必填寫的參數:
14120
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14121
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14122
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14123
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14124
		#可以省略的參數:
14125
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14126
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
14127
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14128
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
14129
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14130
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14131
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14132
		#$conf["canNotBeEmpty"]=array();
14133
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14134
		#$conf["canBeEmpty"]=array();
14135
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14136
		#$conf["skipableVariableCanNotBeEmpty"]=array();
14137
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14138
		#$conf["skipableVariableName"]=array();
226 liveuser 14139
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14140
		#$conf["skipableVariableType"]=array();
14141
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14142
		#$conf["skipableVarDefaultValue"]=array("");
14143
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14144
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14145
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14146
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14147
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14148
		#$conf["arrayCountEqualCheck"][]=array();
14149
		#參考資料來源:
14150
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14151
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14152
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14153
 
3 liveuser 14154
		#如果檢查參數失敗
14155
		if($checkArguments["status"]==="false"){
226 liveuser 14156
 
3 liveuser 14157
			#設置執行失敗
14158
			$result["status"]="false";
226 liveuser 14159
 
3 liveuser 14160
			#設置執行失敗訊息
14161
			$result["error"]=$checkArguments;
226 liveuser 14162
 
3 liveuser 14163
			#回傳結果
14164
			return $result;
226 liveuser 14165
 
3 liveuser 14166
			}#if end
226 liveuser 14167
 
3 liveuser 14168
		#如果檢查參數不通過
14169
		if($checkArguments["passed"]==="false"){
226 liveuser 14170
 
3 liveuser 14171
			#設置執行失敗
14172
			$result["status"]="false";
226 liveuser 14173
 
3 liveuser 14174
			#設置執行失敗訊息
14175
			$result["error"]=$checkArguments;
226 liveuser 14176
 
3 liveuser 14177
			#回傳結果
14178
			return $result;
226 liveuser 14179
 
3 liveuser 14180
			}#if end
226 liveuser 14181
 
3 liveuser 14182
		#函式說明:
14183
		#透過lsblk指令的輸出取得已經掛載的blk.
14184
		#回傳結果:
14185
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14186
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14187
		#$result["function"],當前執行的函式名稱.
14188
		#$result["content"],lsblk的輸出內容.
14189
		#必填參數:
14190
		#$conf["fileArgu"],字串,變數__FILE__的內容.
14191
		$conf["cmd::lsblk"]["fileArgu"]=$conf["fileArgu"];
14192
		#可省略參數:
226 liveuser 14193
		#無.
3 liveuser 14194
		$lsblk=cmd::lsblk($conf["cmd::lsblk"]);
14195
		unset($conf["cmd::lsblk"]);
226 liveuser 14196
 
3 liveuser 14197
		#如果執行失敗
14198
		if($lsblk["status"]==="false"){
226 liveuser 14199
 
3 liveuser 14200
			#設置執行失敗
14201
			$result["status"]="false";
226 liveuser 14202
 
3 liveuser 14203
			#設置執行失敗訊息
14204
			$result["error"]=$lsblk;
226 liveuser 14205
 
3 liveuser 14206
			#回傳結果
14207
			return $result;
226 liveuser 14208
 
3 liveuser 14209
			}#if end
226 liveuser 14210
 
3 liveuser 14211
		#將 $conf["file"] 轉換成絕對路徑
14212
		#函式說明:
14213
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
14214
		#回傳結果:
14215
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
14216
		#$result["error"],錯誤訊息陣列.
226 liveuser 14217
		#$result["function"],函數名稱.
3 liveuser 14218
		#$result["argu"],使用的參數.
14219
		#$result["content"],網址,若是在命令列執行,則為"null".
14220
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
14221
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
14222
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
14223
		#必填參數:
14224
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
14225
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["file"];
14226
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
14227
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
14228
		#可省略參數:
14229
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
14230
		#$conf["userDir"]="true";
14231
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
14232
		unset($conf["fileAccess::getInternetAddress"]);
226 liveuser 14233
 
3 liveuser 14234
		#如果執行失敗
14235
		if($getInternetAddress["status"]==="false"){
226 liveuser 14236
 
3 liveuser 14237
			#設置執行失敗
14238
			$result["status"]="false";
226 liveuser 14239
 
3 liveuser 14240
			#設置執行失敗訊息
14241
			$result["error"]=$getInternetAddress;
226 liveuser 14242
 
3 liveuser 14243
			#回傳結果
14244
			return $result;
226 liveuser 14245
 
14246
			}#if end
14247
 
3 liveuser 14248
		#使用絕對位置作為輸入字串
14249
		#函式說明:
14250
		#尋找字串是否存在對應的關鍵字,且符合的最常關鍵字為何?
14251
		#回傳結果:
14252
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14253
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14254
		#$result["function"],當前執行的函式名稱.
14255
		#$result["argu"],所使用的參數.
14256
		#$result["founded"],是否有找到關鍵字,"true"代表有找到,"false"代表沒有找到.
14257
		#$result["content"],最符合的字串完整內容.
14258
		#必填參數:
14259
		#$conf["input"],字串,要比對的字串陣列.
14260
		$conf["search::findLikelyStr"]["input"]=$getInternetAddress["fileSystemAbsoulutePosition"];
14261
		#$conf["keyWord"],字串陣列,要搜尋的關鍵字.
14262
		$conf["search::findLikelyStr"]["keyWord"]=$lsblk["content"]["MOUNTPOINT"];
14263
		$findLikelyStr=search::findLikelyStr($conf["search::findLikelyStr"]);
14264
		unset($conf["search::findLikelyStr"]);
226 liveuser 14265
 
3 liveuser 14266
		#如果執行失敗
14267
		if($findLikelyStr["status"]==="false"){
226 liveuser 14268
 
3 liveuser 14269
			#設置執行失敗
14270
			$result["status"]="false";
226 liveuser 14271
 
3 liveuser 14272
			#設置執行失敗訊息
14273
			$result["error"]=$findLikelyStr;
226 liveuser 14274
 
3 liveuser 14275
			#回傳結果
14276
			return $result;
226 liveuser 14277
 
3 liveuser 14278
			}#if end
226 liveuser 14279
 
3 liveuser 14280
		#如果找不到歸屬的分割區
14281
		if($findLikelyStr["found"]==="false"){
226 liveuser 14282
 
3 liveuser 14283
			#設置執行失敗
14284
			$result["status"]="false";
226 liveuser 14285
 
3 liveuser 14286
			#設置執行失敗訊息
14287
			$result["error"]=$findLikelyStr;
226 liveuser 14288
 
3 liveuser 14289
			#回傳結果
14290
			return $result;
226 liveuser 14291
 
3 liveuser 14292
			}#if end
226 liveuser 14293
 
3 liveuser 14294
		#設置歸屬的分割區資訊
14295
		$result["content"]=$findLikelyStr["content"];
226 liveuser 14296
 
3 liveuser 14297
		#設置執行正常
14298
		$result["status"]="true";
226 liveuser 14299
 
3 liveuser 14300
		#回傳結果
14301
		return $result;
226 liveuser 14302
 
3 liveuser 14303
		}#function addrInMountPoint end
14304
 
14305
	/*
14306
	#函式說明:
14307
	#取得檔案的副檔名
14308
	#回傳結果:
14309
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14310
	#$result["error"],錯誤訊息.
14311
	#$result["function"],當前執行的函數名稱.
226 liveuser 14312
	#$result["argu"],所使用的參數.
3 liveuser 14313
	#$result["content"],副檔名.
14314
	#$result["name"],不含副檔的名稱.
14315
	#$result["fullName"],含副檔的名稱.
14316
	#$result["path"],檔案所處的路徑.
14317
	#必填參數:
14318
	#$conf["file"],字串,檔案的路徑與名稱.
14319
	$conf["file"]="";
14320
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14321
	$conf["fileArgu"]=__FILE__;
14322
	#可省略參數:
14323
	#無.
14324
	#參考資料:
14325
	#無.
14326
	#備註:
14327
	#無.
14328
	*/
14329
	public static function getExtension(&$conf=array()){
226 liveuser 14330
 
3 liveuser 14331
		#初始化要回傳的結果
14332
		$result=array();
14333
 
14334
		#取得當前執行的函數名稱
14335
		$result["function"]=__FUNCTION__;
14336
 
14337
		#如果沒有參數
14338
		if(func_num_args()==0){
226 liveuser 14339
 
3 liveuser 14340
			#設置執行失敗
14341
			$result["status"]="false";
226 liveuser 14342
 
3 liveuser 14343
			#設置執行錯誤訊息
14344
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14345
 
3 liveuser 14346
			#回傳結果
14347
			return $result;
14348
 
226 liveuser 14349
			}#if end
14350
 
3 liveuser 14351
		#取得參數
14352
		$result["argu"]=$conf;
14353
 
14354
		#如果 $conf 不為陣列
14355
		if(gettype($conf)!=="array"){
226 liveuser 14356
 
3 liveuser 14357
			#設置執行失敗
14358
			$result["status"]="false";
226 liveuser 14359
 
3 liveuser 14360
			#設置執行錯誤訊息
14361
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14362
 
3 liveuser 14363
			#如果傳入的參數為 null
14364
			if($conf===null){
226 liveuser 14365
 
3 liveuser 14366
				#設置執行錯誤訊息
14367
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14368
 
3 liveuser 14369
				}#if end
14370
 
14371
			#回傳結果
14372
			return $result;
226 liveuser 14373
 
3 liveuser 14374
			}#if end
226 liveuser 14375
 
3 liveuser 14376
		#函式說明:
14377
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14378
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14379
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14380
		#$result["function"],當前執行的函式名稱.
14381
		#$result["argu"],設置給予的參數.
14382
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14383
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14384
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14385
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14386
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14387
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14388
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14389
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14390
		#必填寫的參數:
14391
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14392
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14393
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14394
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14395
		#可以省略的參數:
14396
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14397
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
14398
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14399
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
14400
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14401
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14402
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14403
		#$conf["canNotBeEmpty"]=array();
14404
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14405
		#$conf["canBeEmpty"]=array();
14406
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14407
		#$conf["skipableVariableCanNotBeEmpty"]=array();
14408
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14409
		#$conf["skipableVariableName"]=array();
226 liveuser 14410
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14411
		#$conf["skipableVariableType"]=array();
14412
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14413
		#$conf["skipableVarDefaultValue"]=array("");
14414
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14415
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14416
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14417
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14418
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14419
		#$conf["arrayCountEqualCheck"][]=array();
14420
		#參考資料來源:
14421
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14422
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14423
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14424
 
3 liveuser 14425
		#如果檢查參數失敗
14426
		if($checkArguments["status"]==="false"){
226 liveuser 14427
 
3 liveuser 14428
			#設置執行失敗
14429
			$result["status"]="false";
226 liveuser 14430
 
3 liveuser 14431
			#設置執行失敗訊息
14432
			$result["error"]=$checkArguments;
226 liveuser 14433
 
3 liveuser 14434
			#回傳結果
14435
			return $result;
226 liveuser 14436
 
3 liveuser 14437
			}#if end
226 liveuser 14438
 
3 liveuser 14439
		#如果檢查參數不通過
14440
		if($checkArguments["passed"]==="false"){
226 liveuser 14441
 
3 liveuser 14442
			#設置執行失敗
14443
			$result["status"]="false";
226 liveuser 14444
 
3 liveuser 14445
			#設置執行失敗訊息
14446
			$result["error"]=$checkArguments;
226 liveuser 14447
 
3 liveuser 14448
			#回傳結果
14449
			return $result;
226 liveuser 14450
 
3 liveuser 14451
			}#if end
226 liveuser 14452
 
3 liveuser 14453
		#初始化檔案的路徑
14454
		$result["path"]="./";
226 liveuser 14455
 
3 liveuser 14456
		#用 "/" 來分割字串
14457
		#函式說明:
14458
		#將固定格式的字串分開,並回傳分開的結果。
14459
		#回傳結果:
14460
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14461
		#$result["error"],錯誤訊息陣列
14462
		#$result["function"],當前執行的函數名稱.
14463
		#$result["oriStr"],要分割的原始字串內容
14464
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
14465
		#$result["dataCounts"],爲總共分成幾段
14466
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
14467
		#必填參數:
14468
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["file"];#要處理的字串。
14469
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
14470
		#可省略參數:
14471
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
14472
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
14473
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
14474
		unset($conf["stringProcess::spiltString"]);
226 liveuser 14475
 
3 liveuser 14476
		#如果檢查參數失敗
14477
		if($spiltString["status"]==="false"){
226 liveuser 14478
 
3 liveuser 14479
			#設置執行失敗
14480
			$result["status"]="false";
226 liveuser 14481
 
3 liveuser 14482
			#設置執行失敗訊息
14483
			$result["error"]=$spiltString;
226 liveuser 14484
 
3 liveuser 14485
			#回傳結果
14486
			return $result;
226 liveuser 14487
 
3 liveuser 14488
			}#if end
226 liveuser 14489
 
3 liveuser 14490
		#初始化含副檔名的檔案名稱
14491
		$result["fullName"]=$conf["file"];
226 liveuser 14492
 
3 liveuser 14493
		#如果有"/"存在
14494
		if($spiltString["found"]==="true"){
226 liveuser 14495
 
3 liveuser 14496
			#取得含副檔名的檔案名稱
14497
			$result["fullName"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 14498
 
3 liveuser 14499
			#取得檔案的路徑
14500
			$result["path"]=substr($conf["file"],0,strlen($conf["file"])-strlen($result["fullName"]));
226 liveuser 14501
 
3 liveuser 14502
			}#if end
226 liveuser 14503
 
3 liveuser 14504
		#用 "." 來分割字串
14505
		#函式說明:
14506
		#將固定格式的字串分開,並回傳分開的結果。
14507
		#回傳結果:
14508
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14509
		#$result["error"],錯誤訊息陣列
14510
		#$result["function"],當前執行的函數名稱.
14511
		#$result["oriStr"],要分割的原始字串內容
14512
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
14513
		#$result["dataCounts"],爲總共分成幾段
14514
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
14515
		#必填參數:
14516
		$conf["stringProcess::spiltString"]["stringIn"]=$result["fullName"];#要處理的字串。
14517
		$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
14518
		#可省略參數:
14519
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
14520
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
14521
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
14522
		unset($conf["stringProcess::spiltString"]);
226 liveuser 14523
 
3 liveuser 14524
		#如果檢查參數失敗
14525
		if($spiltString["status"]==="false"){
226 liveuser 14526
 
3 liveuser 14527
			#設置執行失敗
14528
			$result["status"]="false";
226 liveuser 14529
 
3 liveuser 14530
			#設置執行失敗訊息
14531
			$result["error"]=$spiltString;
226 liveuser 14532
 
3 liveuser 14533
			#回傳結果
14534
			return $result;
226 liveuser 14535
 
3 liveuser 14536
			}#if end
226 liveuser 14537
 
3 liveuser 14538
		#預設副檔名為 ""
14539
		$result["content"]="";
226 liveuser 14540
 
3 liveuser 14541
		#預設不含副檔名的檔案名稱
14542
		$result["name"]=$result["fullName"];
226 liveuser 14543
 
3 liveuser 14544
		#如果有"."存在
14545
		if($spiltString["found"]==="true"){
226 liveuser 14546
 
3 liveuser 14547
			#取得含副檔名
14548
			$result["content"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 14549
 
3 liveuser 14550
			#取得不含副檔名的檔案名稱
226 liveuser 14551
			$result["name"]=substr($result["fullName"],0,strlen($result["fullName"])-strlen($result["content"])-1);
14552
 
3 liveuser 14553
			}#if end
226 liveuser 14554
 
3 liveuser 14555
		#設置執行正常
14556
		$result["status"]="true";
226 liveuser 14557
 
3 liveuser 14558
		#回傳結果
14559
		return $result;
226 liveuser 14560
 
3 liveuser 14561
		}#function getExtension end
14562
 
14563
	/*
14564
	#函式說明:
14565
	#從檔案尾部開始讀取
14566
	#回傳結果:
14567
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14568
	#$result["error"],錯誤訊息.
14569
	#$result["function"],當前執行的函數名稱.
226 liveuser 14570
	#$result["argu"],所使用的參數.
3 liveuser 14571
	#$result["content"],讀取到的內容陣列.
14572
	#$result["totalLineCount"],檔案的總共行數.
14573
	#$result["lines"],取得輸出的行數.
14574
	#$result["lineNum"],取得當前行數.
14575
	#必填參數:
14576
	#$conf["file"],字串,檔案的路徑與名稱.
14577
	$conf["file"]="";
14578
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14579
	$conf["fileArgu"]=__FILE__;
14580
	#可省略參數:
14581
	#$conf["web"],字串,"true"代表位網頁系統,"false"為檔案系統,預設為"false".
14582
	#$conf["web"]="false";
14583
	#$conf["line2start"],字串,從第幾列開始,預設為總行書減去linesPerTime+1.
14584
	#$conf["line2start"]="";
14585
	#$conf["linesPerTime"],字串,一次最多讀取幾列,預設爲10列.
226 liveuser 14586
	#$conf["linesPerTime"]="10";
3 liveuser 14587
	#參考資料:
14588
	#無.
14589
	#備註:
14590
	#無.
14591
	*/
14592
	public static function tail(&$conf){
14593
 
14594
		#初始化要回傳的結果
14595
		$result=array();
14596
 
14597
		#取得當前執行的函數名稱
14598
		$result["function"]=__FUNCTION__;
14599
 
14600
		#如果沒有參數
14601
		if(func_num_args()==0){
226 liveuser 14602
 
3 liveuser 14603
			#設置執行失敗
14604
			$result["status"]="false";
226 liveuser 14605
 
3 liveuser 14606
			#設置執行錯誤訊息
14607
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14608
 
3 liveuser 14609
			#回傳結果
14610
			return $result;
14611
 
226 liveuser 14612
			}#if end
14613
 
3 liveuser 14614
		#取得參數
14615
		$result["argu"]=$conf;
14616
 
14617
		#如果 $conf 不為陣列
14618
		if(gettype($conf)!=="array"){
226 liveuser 14619
 
3 liveuser 14620
			#設置執行失敗
14621
			$result["status"]="false";
226 liveuser 14622
 
3 liveuser 14623
			#設置執行錯誤訊息
14624
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14625
 
3 liveuser 14626
			#如果傳入的參數為 null
14627
			if($conf===null){
226 liveuser 14628
 
3 liveuser 14629
				#設置執行錯誤訊息
14630
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14631
 
3 liveuser 14632
				}#if end
14633
 
14634
			#回傳結果
14635
			return $result;
226 liveuser 14636
 
3 liveuser 14637
			}#if end
226 liveuser 14638
 
3 liveuser 14639
		#函式說明:
14640
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14641
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14642
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14643
		#$result["function"],當前執行的函式名稱.
14644
		#$result["argu"],設置給予的參數.
14645
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14646
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14647
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14648
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14649
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14650
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14651
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14652
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14653
		#必填寫的參數:
14654
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14655
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14656
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14657
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14658
		#可以省略的參數:
14659
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14660
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
14661
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14662
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
14663
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14664
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14665
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14666
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file","fileArgu");
14667
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14668
		#$conf["canBeEmpty"]=array();
14669
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14670
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web","line2start","linesPerTime");
14671
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14672
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web","line2start","linesPerTime");
226 liveuser 14673
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14674
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
14675
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14676
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,"10");
14677
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14678
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14679
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14680
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14681
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14682
		#$conf["arrayCountEqualCheck"][]=array();
14683
		#參考資料來源:
14684
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14685
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14686
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14687
 
3 liveuser 14688
		#如果檢查參數失敗
14689
		if($checkArguments["status"]==="false"){
226 liveuser 14690
 
3 liveuser 14691
			#設置執行失敗
14692
			$result["status"]="false";
226 liveuser 14693
 
3 liveuser 14694
			#設置執行失敗訊息
14695
			$result["error"]=$checkArguments;
226 liveuser 14696
 
3 liveuser 14697
			#回傳結果
14698
			return $result;
226 liveuser 14699
 
3 liveuser 14700
			}#if end
226 liveuser 14701
 
3 liveuser 14702
		#如果檢查參數不通過
14703
		if($checkArguments["passed"]==="false"){
226 liveuser 14704
 
3 liveuser 14705
			#設置執行失敗
14706
			$result["status"]="false";
226 liveuser 14707
 
3 liveuser 14708
			#設置執行失敗訊息
14709
			$result["error"]=$checkArguments;
226 liveuser 14710
 
3 liveuser 14711
			#回傳結果
14712
			return $result;
226 liveuser 14713
 
3 liveuser 14714
			}#if end
14715
 
14716
		#檢查檔案是否存在
14717
		#函式說明:
14718
		#檢查多個檔案與資料夾是否存在.
14719
		#回傳的結果:
14720
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
14721
		#$result["error"],錯誤訊息陣列.
14722
		#$resutl["function"],當前執行的涵式名稱.
14723
		#$result["argu"],使用的參數.
14724
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
14725
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
14726
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
14727
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
14728
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
14729
		#必填參數:
14730
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
14731
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
14732
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14733
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
14734
		#可省略參數
14735
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
14736
		#$conf["disableWebSearch"]="false";
14737
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
14738
		#$conf["userDir"]="true";
14739
		#$conf["web"],字串,"true"代表位網頁系統,"false"為檔案系統,預設為"false".
14740
		$conf["fileAccess::checkMultiFileExist"]["web"]=$conf["web"];
14741
		#參考資料來源:
14742
		#http://php.net/manual/en/function.file-exists.php
14743
		#http://php.net/manual/en/control-structures.foreach.php
14744
		#備註:
14745
		#函數file_exists檢查的路徑為檔案系統的路徑
14746
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
14747
		unset($conf["fileAccess::checkMultiFileExist"]);
14748
 
14749
		#如果執行失敗
14750
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 14751
 
3 liveuser 14752
			#設置執行失敗
14753
			$result["status"]="false";
226 liveuser 14754
 
3 liveuser 14755
			#設置執行失敗訊息
14756
			$result["error"]=$checkMultiFileExist;
226 liveuser 14757
 
3 liveuser 14758
			#回傳結果
14759
			return $result;
226 liveuser 14760
 
3 liveuser 14761
			}#if end
226 liveuser 14762
 
3 liveuser 14763
		#如果檔案無法存取
14764
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 14765
 
3 liveuser 14766
			#設置執行失敗
14767
			$result["status"]="false";
226 liveuser 14768
 
3 liveuser 14769
			#設置執行失敗訊息
14770
			$result["error"]=$checkMultiFileExist;
226 liveuser 14771
 
3 liveuser 14772
			#回傳結果
14773
			return $result;
226 liveuser 14774
 
3 liveuser 14775
			}#if end
14776
 
14777
		#取得檔案的行數
14778
		#函式說明:
14779
		#呼叫shell執行系統命令,並取得回傳的內容.
14780
		#回傳的結果:
14781
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14782
		#$result["error"],錯誤訊息陣列.
14783
		#$result["function"],當前執行的函數名稱.
14784
		#$result["argu"],使用的參數.
14785
		#$result["cmd"],執行的指令內容.
14786
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14787
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14788
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14789
		#$result["running"],是否還在執行.
14790
		#$result["pid"],pid.
14791
		#$result["statusCode"],執行結束後的代碼.
14792
		#必填的參數
14793
		#$conf["command"],字串,要執行的指令與.
14794
		$conf["external::callShell"]["command"]="cat";
14795
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 14796
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 14797
		#可省略參數:
14798
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14799
		$conf["external::callShell"]["argu"]=array($conf["file"],"|","wc","-l");
14800
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 14801
		#$conf["arguIsAddr"]=array();
3 liveuser 14802
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14803
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14804
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14805
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14806
		#$conf["enablePrintDescription"]="true";
14807
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14808
		#$conf["printDescription"]="";
14809
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
14810
		$conf["external::callShell"]["escapeshellarg"]="true";
14811
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14812
		#$conf["username"]="";
14813
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14814
		#$conf["password"]="";
14815
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14816
		#$conf["useScript"]="";
14817
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14818
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14819
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14820
		#$conf["inBackGround"]="";
14821
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
14822
		#$conf["getErr"]="false";
14823
		#備註:
14824
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14825
		#參考資料:
14826
		#exec=>http://php.net/manual/en/function.exec.php
14827
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14828
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14829
		$callShell=external::callShell($conf["external::callShell"]);
14830
		unset($conf["external::callShell"]);
14831
 
14832
		#如果檢查參數失敗
14833
		if($callShell["status"]==="false"){
226 liveuser 14834
 
3 liveuser 14835
			#設置執行失敗
14836
			$result["status"]="false";
226 liveuser 14837
 
3 liveuser 14838
			#設置執行失敗訊息
14839
			$result["error"]=$callShell;
226 liveuser 14840
 
3 liveuser 14841
			#回傳結果
14842
			return $result;
226 liveuser 14843
 
3 liveuser 14844
			}#if end
226 liveuser 14845
 
3 liveuser 14846
		#取得檔案總行數
14847
		$result["totalLineCount"]=$callShell["output"][0];
226 liveuser 14848
 
3 liveuser 14849
		#如果未設置 $conf["line2start"]
14850
		if(!isset($conf["line2start"])){
226 liveuser 14851
 
3 liveuser 14852
			#$conf["line2start"]為總行數減去一次要看的行數減1
14853
			$conf["line2start"]=$result["totalLineCount"]-$conf["linesPerTime"]+1;
226 liveuser 14854
 
14855
			}#if end
14856
 
14857
		#如果開始行數小於1
3 liveuser 14858
		if($conf["line2start"]<1){
226 liveuser 14859
 
3 liveuser 14860
			#$conf["line2start"]為總行數減去一次要看的行數減1
14861
			$conf["line2start"]=$result["totalLineCount"]-$conf["linesPerTime"]+1;
226 liveuser 14862
 
3 liveuser 14863
			}#if end
226 liveuser 14864
 
14865
		#如果開始行數小於1
3 liveuser 14866
		if($conf["line2start"]<1){
226 liveuser 14867
 
3 liveuser 14868
			#$conf["line2start"]為1
14869
			$conf["line2start"]=1;
226 liveuser 14870
 
3 liveuser 14871
			}#if end
226 liveuser 14872
 
3 liveuser 14873
		#取得指定範圍的行數
14874
		#取得檔案的行數
14875
		#函式說明:
14876
		#呼叫shell執行系統命令,並取得回傳的內容.
14877
		#回傳的結果:
14878
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14879
		#$result["error"],錯誤訊息陣列.
14880
		#$result["function"],當前執行的函數名稱.
14881
		#$result["argu"],使用的參數.
14882
		#$result["cmd"],執行的指令內容.
14883
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14884
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14885
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14886
		#$result["running"],是否還在執行.
14887
		#$result["pid"],pid.
14888
		#$result["statusCode"],執行結束後的代碼.
14889
		#必填的參數
14890
		#$conf["command"],字串,要執行的指令與.
14891
		$conf["external::callShell"]["command"]="sed";
14892
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 14893
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 14894
		#可省略參數:
14895
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14896
		$conf["external::callShell"]["argu"]=array("-n",$conf["line2start"].",".($conf["line2start"]+$conf["linesPerTime"]-1)."p",$conf["file"]);
14897
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 14898
		#$conf["arguIsAddr"]=array();
3 liveuser 14899
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14900
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14901
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14902
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14903
		#$conf["enablePrintDescription"]="true";
14904
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14905
		#$conf["printDescription"]="";
14906
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
14907
		$conf["external::callShell"]["escapeshellarg"]="true";
14908
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14909
		#$conf["username"]="";
14910
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14911
		#$conf["password"]="";
14912
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14913
		#$conf["useScript"]="";
14914
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14915
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14916
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14917
		#$conf["inBackGround"]="";
14918
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
14919
		#$conf["getErr"]="false";
14920
		#備註:
14921
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14922
		#參考資料:
14923
		#exec=>http://php.net/manual/en/function.exec.php
14924
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14925
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14926
		$callShell=external::callShell($conf["external::callShell"]);
14927
		unset($conf["external::callShell"]);
14928
 
14929
		#如果檢查參數失敗
14930
		if($callShell["status"]==="false"){
226 liveuser 14931
 
3 liveuser 14932
			#設置執行失敗
14933
			$result["status"]="false";
226 liveuser 14934
 
3 liveuser 14935
			#設置執行失敗訊息
14936
			$result["error"]=$callShell;
226 liveuser 14937
 
3 liveuser 14938
			#回傳結果
14939
			return $result;
226 liveuser 14940
 
3 liveuser 14941
			}#if end
14942
 
14943
		#取得輸出的行數
14944
		$result["lines"]=count($callShell["output"]);
14945
 
14946
		#取得目前的輸出內容
14947
		$result["content"]=$callShell["output"];
14948
 
14949
		#取得當前行數
14950
		$result["lineNum"]=$conf["line2start"]+$result["lines"]-1;
14951
 
226 liveuser 14952
		#如果當前行號小於總行數
3 liveuser 14953
		if($result["lineNum"]<$result["totalLineCount"]){
14954
 
14955
			#設置還有剩餘的內容
14956
			$result["left"]="true";
226 liveuser 14957
 
3 liveuser 14958
			}#if end
14959
 
226 liveuser 14960
		#反之
3 liveuser 14961
		else{
14962
 
14963
			#設置無剩餘的內容
14964
			$result["left"]="false";
14965
 
14966
			}#else end
14967
 
14968
		#設置執行正常
14969
		$result["status"]="true";
14970
 
14971
		#回傳結果
14972
		return $result;
14973
 
14974
		}#function tail end
226 liveuser 14975
 
3 liveuser 14976
	/*
14977
	#函式說明:
14978
	#解析PHP檔案裡面的變數.
14979
	#回傳結果:
14980
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14981
	#$result["error"],錯誤訊息.
14982
	#$result["function"],當前執行的函數名稱.
226 liveuser 14983
	#$result["argu"],所使用的參數.
3 liveuser 14984
	#$result["content"],找到的變數內容陣列,若有多個變數則會用array來表示.
14985
	#必填參數:
14986
	#$conf["file"],字串,檔案的路徑與名稱.
14987
	$conf["file"]="";
14988
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14989
	$conf["fileArgu"]=__FILE__;
14990
	#$conf["varName"],字串陣列,要搜尋的變數名稱,例如要搜尋變數$email則輸入"email".
14991
	$conf["varName"]=array();
14992
	#可省略參數:
14993
	#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false",預設為"false".
14994
	#$conf["web"]="true";
255 liveuser 14995
	#$conf["allVarCountSame"],字串,是否每個參數的數量要一致,預設為"false"不要;反之為"true"代表要.
14996
	#$conf["allVarCountSame"]="false";
3 liveuser 14997
	#參考資料:
14998
	#https://www.php.net/manual/en/function.parse-str.php
14999
	#備註:
15000
	#無.
15001
	*/
15002
	public static function parseVaraiableInPHPfile(&$conf){
226 liveuser 15003
 
3 liveuser 15004
		#初始化要回傳的結果
15005
		$result=array();
15006
 
15007
		#取得當前執行的函數名稱
15008
		$result["function"]=__FUNCTION__;
15009
 
15010
		#如果沒有參數
15011
		if(func_num_args()==0){
226 liveuser 15012
 
3 liveuser 15013
			#設置執行失敗
15014
			$result["status"]="false";
226 liveuser 15015
 
3 liveuser 15016
			#設置執行錯誤訊息
15017
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 15018
 
3 liveuser 15019
			#回傳結果
15020
			return $result;
15021
 
226 liveuser 15022
			}#if end
15023
 
3 liveuser 15024
		#取得參數
15025
		$result["argu"]=$conf;
15026
 
15027
		#如果 $conf 不為陣列
15028
		if(gettype($conf)!=="array"){
226 liveuser 15029
 
3 liveuser 15030
			#設置執行失敗
15031
			$result["status"]="false";
226 liveuser 15032
 
3 liveuser 15033
			#設置執行錯誤訊息
15034
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 15035
 
3 liveuser 15036
			#如果傳入的參數為 null
15037
			if($conf===null){
226 liveuser 15038
 
3 liveuser 15039
				#設置執行錯誤訊息
15040
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 15041
 
3 liveuser 15042
				}#if end
15043
 
15044
			#回傳結果
15045
			return $result;
226 liveuser 15046
 
3 liveuser 15047
			}#if end
226 liveuser 15048
 
3 liveuser 15049
		#函式說明:
15050
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
15051
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15052
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15053
		#$result["function"],當前執行的函式名稱.
15054
		#$result["argu"],設置給予的參數.
15055
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15056
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15057
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15058
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15059
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15060
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15061
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15062
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15063
		#必填寫的參數:
15064
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 15065
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 15066
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15067
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15068
		#可以省略的參數:
15069
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15070
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu","varName");
15071
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15072
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
15073
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15074
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15075
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15076
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file","fileArgu","varName");
15077
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15078
		#$conf["canBeEmpty"]=array();
15079
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
255 liveuser 15080
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web","allVarCountSame");
3 liveuser 15081
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
255 liveuser 15082
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web","allVarCountSame");
226 liveuser 15083
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
255 liveuser 15084
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
3 liveuser 15085
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 15086
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
3 liveuser 15087
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15088
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15089
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15090
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15091
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15092
		#$conf["arrayCountEqualCheck"][]=array();
15093
		#參考資料來源:
15094
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15095
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15096
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15097
 
3 liveuser 15098
		#如果檢查參數失敗
15099
		if($checkArguments["status"]==="false"){
226 liveuser 15100
 
3 liveuser 15101
			#設置執行失敗
15102
			$result["status"]="false";
226 liveuser 15103
 
3 liveuser 15104
			#設置執行失敗訊息
15105
			$result["error"]=$checkArguments;
226 liveuser 15106
 
3 liveuser 15107
			#回傳結果
15108
			return $result;
226 liveuser 15109
 
3 liveuser 15110
			}#if end
226 liveuser 15111
 
3 liveuser 15112
		#如果檢查參數不通過
15113
		if($checkArguments["passed"]==="false"){
226 liveuser 15114
 
3 liveuser 15115
			#設置執行失敗
15116
			$result["status"]="false";
226 liveuser 15117
 
3 liveuser 15118
			#設置執行失敗訊息
15119
			$result["error"]=$checkArguments;
226 liveuser 15120
 
3 liveuser 15121
			#回傳結果
15122
			return $result;
226 liveuser 15123
 
3 liveuser 15124
			}#if end
226 liveuser 15125
 
3 liveuser 15126
		#初始化儲存解析出來的變數內容
15127
		$result["content"]=array();
226 liveuser 15128
 
3 liveuser 15129
		#讀取檔案
15130
		#函式說明:
15131
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
15132
		#回傳的變數說明:
15133
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
15134
		#$result["error"],錯誤訊息提示.
15135
		#$result["warning"],警告訊息.
15136
		#$result["function"],當前執行的函數名稱.
15137
		#$result["fileContent"],爲檔案的內容陣列.
15138
		#$result["lineCount"],爲檔案內容總共的行數.
15139
		#$result["fullContent"],為檔案的完整內容.
15140
		#$result["base64data"],為檔案的base64內容.
15141
		#$result["mimeType"],為檔案的mime type.
15142
		#必填參數:
15143
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
15144
		$conf["ileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
15145
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
15146
		$conf["ileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
15147
		#可省略參數:
15148
		#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
15149
		$conf["ileAccess::getFileContent"]["web"]=$conf["web"];
15150
		#參考資料:
15151
		#file(),取得檔案內容的行數.
15152
		#file=>http:#php.net/manual/en/function.file.php
15153
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
15154
		#filesize=>http://php.net/manual/en/function.filesize.php
15155
		$getFileContent=fileAccess::getFileContent($conf["ileAccess::getFileContent"]);
15156
		unset($conf["ileAccess::getFileContent"]);
15157
 
15158
		#如果讀取檔案失敗
15159
		if($getFileContent["status"]==="false"){
226 liveuser 15160
 
3 liveuser 15161
			#設置執行失敗
15162
			$result["status"]="false";
226 liveuser 15163
 
3 liveuser 15164
			#設置執行失敗訊息
15165
			$result["error"]=$getFileContent;
226 liveuser 15166
 
3 liveuser 15167
			#回傳結果
15168
			return $result;
226 liveuser 15169
 
3 liveuser 15170
			}#if end
226 liveuser 15171
 
3 liveuser 15172
		#針對每列檔案內容
15173
		foreach($getFileContent["fileContent"] as $line){
226 liveuser 15174
 
3 liveuser 15175
			#針對每個要搜尋的變數
15176
			foreach($conf["varName"] as $keyWord){
226 liveuser 15177
 
3 liveuser 15178
				#如果關鍵字小於被搜尋的字串長度
15179
				if( strlen($line) < strlen($keyWord)+1 ){
226 liveuser 15180
 
3 liveuser 15181
					#跳過
15182
					continue;
226 liveuser 15183
 
3 liveuser 15184
					}#if end
226 liveuser 15185
 
3 liveuser 15186
				#函式說明:
15187
				#取得符合特定字首與字尾的字串
15188
				#回傳結果:
15189
				#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
15190
				#$result["function"],當前執行的函數名稱.
15191
				#$result["error"],錯誤訊息陣列.
15192
				#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
15193
				#$result["returnString"],爲符合字首條件的字串內容。
15194
				#$result["argu"],使用的參數.
15195
				#必填參數:
15196
				#$conf["checkString"],字串,要檢查的字串.
15197
				$conf["search::getMeetConditionsString"]["checkString"]=$line;
15198
				#可省略參數:
15199
				#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
15200
				$conf["search::getMeetConditionsString"]["frontWord"]="$".$keyWord;
15201
				#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
15202
				$conf["search::getMeetConditionsString"]["tailWord"]=";";
15203
				#參考資料:
15204
				#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
15205
				$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
15206
				unset($conf["search::getMeetConditionsString"]);
226 liveuser 15207
 
3 liveuser 15208
				#如果失敗
15209
				if($getMeetConditionsString["status"]==="false"){
15210
 
15211
					#設置執行失敗
15212
					$result["status"]="false";
226 liveuser 15213
 
3 liveuser 15214
					#設置執行失敗訊息
15215
					$result["error"]=$getMeetConditionsString;
226 liveuser 15216
 
3 liveuser 15217
					#回傳結果
15218
					return $result;
226 liveuser 15219
 
15220
					}#if end
15221
 
3 liveuser 15222
				#如果有找到關鍵字
15223
				if($getMeetConditionsString["founded"]==="true"){
226 liveuser 15224
 
3 liveuser 15225
					#剔除變數名稱
15226
					#函式說明:
15227
					#將字串特定關鍵字與其前面的內容剔除
15228
					#回傳結果:
15229
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15230
					#$result["error"],錯誤訊息陣列.
15231
					#$result["warning"],警告訊息鎮列.
15232
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
15233
					#$result["function"],當前執行的函數名稱.
15234
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 15235
					#$result["content"],處理好的的字串內容.
3 liveuser 15236
					#必填參數:
15237
					#$conf["stringIn"],字串,要處理的字串.
15238
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$line;
15239
					#$conf["keyWord"],字串,特定字串.
15240
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="$".$keyWord;
15241
					#可省略參數:
15242
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,直到沒有關鍵字為止.
15243
					#$conf["recursive"]="true";
15244
					#參考資料:
15245
					#無.
15246
					#備註:
15247
					#無.
15248
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
15249
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 15250
 
3 liveuser 15251
					#如果執行失敗
15252
					if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 15253
 
3 liveuser 15254
						#設置執行失敗
15255
						$result["status"]="false";
226 liveuser 15256
 
3 liveuser 15257
						#設置執行失敗訊息
15258
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15259
 
3 liveuser 15260
						#回傳結果
15261
						return $result;
226 liveuser 15262
 
3 liveuser 15263
						}#if end
226 liveuser 15264
 
3 liveuser 15265
					#如果沒有找到應該存在的php變數
15266
					if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 15267
 
3 liveuser 15268
						#設置執行失敗
15269
						$result["status"]="false";
226 liveuser 15270
 
3 liveuser 15271
						#設置執行失敗訊息
15272
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15273
 
3 liveuser 15274
						#回傳結果
15275
						return $result;
226 liveuser 15276
 
3 liveuser 15277
						}#if end
226 liveuser 15278
 
3 liveuser 15279
					#剔除 "=" 前面的內容
15280
					#函式說明:
15281
					#將字串特定關鍵字與其前面的內容剔除
15282
					#回傳結果:
15283
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15284
					#$result["error"],錯誤訊息陣列.
15285
					#$result["warning"],警告訊息鎮列.
15286
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
15287
					#$result["function"],當前執行的函數名稱.
15288
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 15289
					#$result["content"],處理好的的字串內容.
3 liveuser 15290
					#必填參數:
15291
					#$conf["stringIn"],字串,要處理的字串.
15292
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
15293
					#$conf["keyWord"],字串,特定字串.
15294
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="=";
15295
					#可省略參數:
15296
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,直到沒有關鍵字為止.
15297
					#$conf["recursive"]="true";
15298
					#參考資料:
15299
					#無.
15300
					#備註:
15301
					#無.
15302
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
15303
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 15304
 
3 liveuser 15305
					#如果執行失敗
15306
					if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 15307
 
3 liveuser 15308
						#設置執行失敗
15309
						$result["status"]="false";
226 liveuser 15310
 
3 liveuser 15311
						#設置執行失敗訊息
15312
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15313
 
3 liveuser 15314
						#回傳結果
15315
						return $result;
226 liveuser 15316
 
3 liveuser 15317
						}#if end
226 liveuser 15318
 
3 liveuser 15319
					#如果沒有找“=”關鍵字
15320
					if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 15321
 
3 liveuser 15322
						#跳過
15323
						continue;
226 liveuser 15324
 
3 liveuser 15325
						}#if end
226 liveuser 15326
 
3 liveuser 15327
					#剔除 value 前面的空白
15328
					#函式說明:
288 liveuser 15329
					#移除字串開頭的特定內容
3 liveuser 15330
					#回傳結果:
288 liveuser 15331
					#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
3 liveuser 15332
					#$result["error"],錯誤訊息陣列.
288 liveuser 15333
					#$result["function"],當前執行的函數.
15334
					#$result["content"],處理好的字串.
15335
					#$result["argu"],使用的參數.
3 liveuser 15336
					#必填參數:
288 liveuser 15337
					#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
15338
					$conf["stringProcess::delKeyWordsInStrHead"]["inputStr"]=$delStrBeforeKeyWord["content"];
15339
					#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
15340
					$conf["stringProcess::delKeyWordsInStrHead"]["keyWord"]=" ";
3 liveuser 15341
					#可省略參數:
288 liveuser 15342
					#$conf["recursive"],字串,"true"代表要遞迴移除開頭的關鍵字,預設為"false",只移除開頭關鍵字1次.
15343
					$conf["stringProcess::delKeyWordsInStrHead"]["recursive"]="true";
3 liveuser 15344
					#參考資料:
15345
					#無.
15346
					#備註:
15347
					#無.
288 liveuser 15348
					$delKeyWordsInStrHead=stringProcess::delKeyWordsInStrHead($conf["stringProcess::delKeyWordsInStrHead"]);
15349
					unset($conf["stringProcess::delKeyWordsInStrHead"]);
226 liveuser 15350
 
3 liveuser 15351
					#如果執行失敗
288 liveuser 15352
					if($delKeyWordsInStrHead["status"]==="false"){
226 liveuser 15353
 
3 liveuser 15354
						#設置執行失敗
15355
						$result["status"]="false";
226 liveuser 15356
 
3 liveuser 15357
						#設置執行失敗訊息
288 liveuser 15358
						$result["error"]=$delKeyWordsInStrHead;
226 liveuser 15359
 
3 liveuser 15360
						#回傳結果
15361
						return $result;
226 liveuser 15362
 
3 liveuser 15363
						}#if end
226 liveuser 15364
 
316 liveuser 15365
					#取得找到的變數的語法
15366
					$phpCode="\$result[\"content\"][\"".$keyWord."\"][]=".$delKeyWordsInStrHead["content"];
15367
 
3 liveuser 15368
					#取得找到的變數
316 liveuser 15369
					eval($phpCode);
226 liveuser 15370
 
3 liveuser 15371
					}#if end
226 liveuser 15372
 
3 liveuser 15373
				}#foreach end
226 liveuser 15374
 
3 liveuser 15375
			}#foreach end
226 liveuser 15376
 
255 liveuser 15377
		#如果 allVarCountSame 設置為 "true"
15378
		if($conf["allVarCountSame"]==="true"){
15379
 
15380
			#每個變數的數量初始為0
15381
			$count=0;
15382
 
15383
			#針對每個解析出來的變數
15384
			foreach($conf["varName"] as $varName){
15385
 
15386
				#取得該變數數量
15387
				$varCount=count($result["content"][$varName]);
15388
 
15389
				#如果尚無變數數量資料
15390
				if($count===0){
15391
 
15392
					#直接儲存之
15393
					$count=$varCount;
15394
 
15395
					#看下一個變數
15396
					continue;
15397
 
15398
					}#if end
15399
 
15400
				#如果變數數量不一樣
15401
				if($count!==$varCount){
15402
 
15403
					#設置執行失敗
15404
					$result["status"]="false";
15405
 
15406
					#設置執行失敗訊息
15407
					$result["error"]="config file error";
15408
 
15409
					#回傳結果
15410
					return $result;
15411
 
15412
					}#if end
15413
 
15414
				}#foreach end
15415
 
15416
			}#if end
15417
 
3 liveuser 15418
		#設置執行正常
15419
		$result["status"]="true";
226 liveuser 15420
 
3 liveuser 15421
		#回傳結果
15422
		return $result;
226 liveuser 15423
 
3 liveuser 15424
		}#function parseVaraiableInPHPfile end
15425
 
15426
	/*
15427
	#函式說明:
15428
	#開啟特定目錄,取得底下的檔案路徑清單.
15429
	#回傳結果:
15430
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15431
	#$result["error"],錯誤訊息.
15432
	#$result["function"],當前執行的函數名稱.
15433
	#$result["argu"],所使用的參數.
15434
	#$result["content"],讀取到的內容陣列.
15435
	#$result["content"][$i],第$i+1個結果.
15436
	#$result["content"][$i]["name"],第$i+1個名稱.
15437
	#$result["content"][$i]["dir"],第$i+1個檔案是否為資料夾.
15438
	#$result["content"][$i]["info"],第$i+1個檔案的額外資訊.
15439
	#$result["content"][$i]["size"],第$i+1個檔案的大小(bytes).
15440
	#必填參數:
15441
	#$conf["path"],字串,要取得檔案資訊的所屬路徑.
15442
	$conf["path"]="";
15443
	#可省略參數:
15444
	#無.
15445
	#參考資料
15446
	#無.
15447
	#備註:
15448
	#無.
15449
	*/
15450
	public static function listInfo(&$conf){
226 liveuser 15451
 
3 liveuser 15452
		#初始化要回傳的結果
15453
		$result=array();
15454
 
15455
		#取得當前執行的函數名稱
15456
		$result["function"]=__FUNCTION__;
15457
 
15458
		#如果沒有參數
15459
		if(func_num_args()==0){
226 liveuser 15460
 
3 liveuser 15461
			#設置執行失敗
15462
			$result["status"]="false";
226 liveuser 15463
 
3 liveuser 15464
			#設置執行錯誤訊息
15465
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 15466
 
3 liveuser 15467
			#回傳結果
15468
			return $result;
15469
 
226 liveuser 15470
			}#if end
15471
 
3 liveuser 15472
		#取得參數
15473
		$result["argu"]=$conf;
15474
 
15475
		#如果 $conf 不為陣列
15476
		if(gettype($conf)!=="array"){
226 liveuser 15477
 
3 liveuser 15478
			#設置執行失敗
15479
			$result["status"]="false";
226 liveuser 15480
 
3 liveuser 15481
			#設置執行錯誤訊息
15482
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 15483
 
3 liveuser 15484
			#如果傳入的參數為 null
15485
			if($conf===null){
226 liveuser 15486
 
3 liveuser 15487
				#設置執行錯誤訊息
15488
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 15489
 
3 liveuser 15490
				}#if end
15491
 
15492
			#回傳結果
15493
			return $result;
226 liveuser 15494
 
3 liveuser 15495
			}#if end
226 liveuser 15496
 
3 liveuser 15497
		#函式說明:
15498
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
15499
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15500
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15501
		#$result["function"],當前執行的函式名稱.
15502
		#$result["argu"],設置給予的參數.
15503
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15504
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15505
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15506
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15507
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15508
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15509
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15510
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15511
		#必填寫的參數:
15512
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 15513
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 15514
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15515
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15516
		#可以省略的參數:
15517
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15518
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
15519
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15520
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
15521
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15522
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15523
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15524
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
15525
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15526
		#$conf["canBeEmpty"]=array();
15527
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
15528
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
15529
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
15530
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 15531
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 15532
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
15533
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
15534
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
15535
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15536
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15537
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15538
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15539
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15540
		#$conf["arrayCountEqualCheck"][]=array();
15541
		#參考資料來源:
15542
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15543
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15544
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15545
 
3 liveuser 15546
		#如果檢查參數失敗
15547
		if($checkArguments["status"]==="false"){
226 liveuser 15548
 
3 liveuser 15549
			#設置執行失敗
15550
			$result["status"]="false";
226 liveuser 15551
 
3 liveuser 15552
			#設置執行失敗訊息
15553
			$result["error"]=$checkArguments;
226 liveuser 15554
 
3 liveuser 15555
			#回傳結果
15556
			return $result;
226 liveuser 15557
 
3 liveuser 15558
			}#if end
226 liveuser 15559
 
3 liveuser 15560
		#如果檢查參數不通過
15561
		if($checkArguments["passed"]==="false"){
226 liveuser 15562
 
3 liveuser 15563
			#設置執行失敗
15564
			$result["status"]="false";
226 liveuser 15565
 
3 liveuser 15566
			#設置執行失敗訊息
15567
			$result["error"]=$checkArguments;
226 liveuser 15568
 
3 liveuser 15569
			#回傳結果
15570
			return $result;
226 liveuser 15571
 
3 liveuser 15572
			}#if end
226 liveuser 15573
 
3 liveuser 15574
		#初始化儲存解析出來的變數內容
15575
		$result["content"]=array();
226 liveuser 15576
 
3 liveuser 15577
		#取得特定位置的資訊
15578
		$pathInfo=@dir($conf["path"]);
226 liveuser 15579
 
3 liveuser 15580
		#如果取得路徑資訊失敗
15581
		if($pathInfo===false){
226 liveuser 15582
 
3 liveuser 15583
			#設置執行失敗
15584
			$result["status"]="false";
226 liveuser 15585
 
3 liveuser 15586
			#設置執行失敗訊息
15587
			$result["error"][]="無法存取路徑(".$conf["path"].")";
226 liveuser 15588
 
3 liveuser 15589
			#回傳結果
15590
			return $result;
226 liveuser 15591
 
3 liveuser 15592
			}#if end
226 liveuser 15593
 
3 liveuser 15594
		#讀取底下一個檔案,暫存到 $tmpItem 裡面,且當結果不為 false 時進入迴圈.
15595
		while(false !== $tmpItem = $pathInfo->read()){
226 liveuser 15596
 
3 liveuser 15597
			#宣告儲存資訊的變數
15598
			$item=array();
226 liveuser 15599
 
3 liveuser 15600
			#儲存名稱
15601
			$item["name"]=$tmpItem;
226 liveuser 15602
 
3 liveuser 15603
			#預設不為資料夾
15604
			$item["dir"]="false";
226 liveuser 15605
 
3 liveuser 15606
			#若為資料夾
15607
			if(is_dir($conf["path"]."/".$tmpItem)){
226 liveuser 15608
 
3 liveuser 15609
				#設置為"true"
15610
				$item["dir"]="true";
226 liveuser 15611
 
3 liveuser 15612
				}#if end
226 liveuser 15613
 
3 liveuser 15614
			#取得檔案識別器
15615
			$finfo = finfo_open(FILEINFO_MIME);
226 liveuser 15616
 
3 liveuser 15617
			#取得 info
15618
			$item["info"]=@finfo_file($finfo,$conf["path"]."/".$tmpItem);
15619
 
15620
			#取得檔案大小
15621
			$item["size"]=filesize($conf["path"]."/".$tmpItem);
15622
 
15623
			#close connection
15624
			finfo_close($finfo);
226 liveuser 15625
 
3 liveuser 15626
			#記錄該檔案資訊
15627
			$result["content"][]=$item;
226 liveuser 15628
 
3 liveuser 15629
			}#while end
226 liveuser 15630
 
3 liveuser 15631
		#設置執行正常
15632
		$result["status"]="true";
226 liveuser 15633
 
3 liveuser 15634
		#回傳結果
15635
		return $result;
226 liveuser 15636
 
3 liveuser 15637
		}#function listInfo end
15638
 
15639
	/*
15640
	#函式說明:
15641
	#取得目錄底下的詳細資訊.
15642
	#回傳結果:
15643
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15644
	#$result["error"],錯誤訊息.
15645
	#$result["function"],當前執行的函數名稱.
15646
	#$result["size"],該清單的大小,單位為bytes.
15647
	#$result["dataCount"],該清單的長度.
15648
	#$result["path"],字串,檢視的路徑,必為"/"結尾.
15649
	#$result["content"],指定目錄底下的所有檔案資訊.
15650
	#$result["content"][$i]["nType&permission"],第$i個節點類型、權限.
15651
	#$result["content"][$i]["nType"],第$i個節點類型,"-"代表檔案,"d"代表資料夾.
15652
	#$result["content"][$i]["permission"],第$i個節點權限.
15653
	#$result["content"][$i]["ownByUser"],第$i個節點擁有者賬號.
15654
	#$result["content"][$i]["ownByGroup"],第$i個節點擁有者群組.
15655
	#$result["content"][$i]["bytes"],第$i個節點大小.
15656
	#$result["content"][$i]["date"],第$i個節點最後變更日期.
15657
	#$result["content"][$i]["time"],第$i個節點最後異動時間.
15658
	#$result["content"][$i]["timeDetail"],第$i個節點最後異動詳細時間.
15659
	#$result["content"][$i]["timezone"],第$i個節點的時區.
15660
	#$result["content"][$i]["name"],第$i個節點的名稱.
15661
	#$result["content"][$i]["secondName"],第$i個節點為檔案時,若有附檔名,會記錄在這.
15662
	#$result["content"][$i]["mimeType"],第$i個節點為檔案且可以讀取時,會有 mime type 可取得.
15663
	#必填參數:
15664
	#$conf["path"],字串,要檢視的路徑,若非"/"結尾,會自動補上.
15665
	$conf["path"]="";
15666
	#可省略參數:
15667
	#無.
15668
	#參考資料:
15669
	#https://www.businessweekly.com.tw/careers/Blog/14307
15670
	#備註:
15671
	#無.
15672
	*/
15673
	public static function ls(&$conf){
226 liveuser 15674
 
3 liveuser 15675
		#初始化要回傳的結果
15676
		$result=array();
15677
 
15678
		#取得當前執行的函數名稱
15679
		$result["function"]=__FUNCTION__;
15680
 
15681
		#如果沒有參數
15682
		if(func_num_args()==0){
15683
 
15684
			#設置執行失敗
15685
			$result["status"]="false";
15686
 
15687
			#設置執行錯誤訊息
15688
			$result["error"]="函數".$result["function"]."需要參數";
15689
 
15690
			#回傳結果
15691
			return $result;
15692
 
15693
			}#if end
15694
 
15695
		#取得參數
15696
		$result["argu"]=$conf;
15697
 
15698
		#如果 $conf 不為陣列
15699
		if(gettype($conf)!=="array"){
15700
 
15701
			#設置執行失敗
15702
			$result["status"]="false";
15703
 
15704
			#設置執行錯誤訊息
15705
			$result["error"][]="\$conf變數須為陣列形態";
15706
 
15707
			#如果傳入的參數為 null
15708
			if(is_null($conf)){
15709
 
15710
				#設置執行錯誤訊息
15711
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
15712
 
15713
				}#if end
15714
 
15715
			#回傳結果
15716
			return $result;
15717
 
15718
			}#if end
226 liveuser 15719
 
3 liveuser 15720
		#函式說明:
15721
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
15722
		#回傳結果:
15723
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15724
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15725
		#$result["simpleError"],簡單表示的錯誤訊息.
15726
		#$result["function"],當前執行的函式名稱.
15727
		#$result["argu"],設置給予的參數.
15728
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15729
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15730
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15731
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15732
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15733
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15734
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15735
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15736
		#必填參數:
15737
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
15738
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
15739
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15740
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15741
		#可省略參數:
15742
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15743
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
15744
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15745
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
15746
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15747
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15748
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15749
		#$conf["canNotBeEmpty"]=array();
15750
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15751
		#$conf["canBeEmpty"]=array();
15752
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
15753
		#$conf["skipableVariableCanNotBeEmpty"]=array();
15754
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
15755
		#$conf["skipableVariableName"]=array();
15756
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
15757
		#$conf["skipableVariableType"]=array();
15758
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
15759
		#$conf["skipableVarDefaultValue"]=array("");
15760
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15761
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15762
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15763
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15764
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15765
		#$conf["arrayCountEqualCheck"][]=array();
15766
		#參考資料:
15767
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15768
		#備註:
15769
		#無.
15770
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15771
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15772
 
3 liveuser 15773
		#如果執行失敗
15774
		if($checkArguments["status"]==="false"){
226 liveuser 15775
 
3 liveuser 15776
			#設置執行錯誤
15777
			$result["status"]="false";
226 liveuser 15778
 
3 liveuser 15779
			#設置錯誤訊息
15780
			$result["error"]=$checkArguments;
226 liveuser 15781
 
3 liveuser 15782
			#回傳結果
15783
			return $result;
226 liveuser 15784
 
3 liveuser 15785
			}#if end
226 liveuser 15786
 
3 liveuser 15787
		#如果參數檢查不通過
15788
		if($checkArguments["passed"]==="false"){
226 liveuser 15789
 
3 liveuser 15790
			#設置執行錯誤
15791
			$result["status"]="false";
226 liveuser 15792
 
3 liveuser 15793
			#設置錯誤訊息
15794
			$result["error"]=$checkArguments;
226 liveuser 15795
 
3 liveuser 15796
			#回傳結果
15797
			return $result;
226 liveuser 15798
 
3 liveuser 15799
			}#if end
226 liveuser 15800
 
3 liveuser 15801
		#確認 $conf["path"] 是否為 "/" 結尾
15802
		#函式說明:
15803
		#取得符合特定字首與字尾的字串
15804
		#回傳結果:
15805
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
15806
		#$result["function"],當前執行的函數名稱.
15807
		#$result["error"],錯誤訊息陣列.
15808
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
15809
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
15810
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
15811
		#$result["argu"],使用的參數.
15812
		#必填參數:
15813
		#$conf["checkString"],字串,要檢查的字串.
15814
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["path"];
15815
		#可省略參數:
15816
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
15817
		#$conf["frontWord"]="";
15818
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
15819
		$conf["search::getMeetConditionsString"]["tailWord"]="/";
15820
		#參考資料:
15821
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
15822
		#備註:
15823
		#無.
15824
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
15825
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 15826
 
3 liveuser 15827
		#如果執行失敗
15828
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 15829
 
3 liveuser 15830
			#設置執行錯誤
15831
			$result["status"]="false";
226 liveuser 15832
 
3 liveuser 15833
			#設置錯誤訊息
15834
			$result["error"]=$getMeetConditionsString;
226 liveuser 15835
 
3 liveuser 15836
			#回傳結果
15837
			return $result;
226 liveuser 15838
 
3 liveuser 15839
			}#if end
226 liveuser 15840
 
3 liveuser 15841
		#如果沒有 "/" 結尾
15842
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 15843
 
3 liveuser 15844
			#於結尾加上 "/"
15845
			$conf["path"]=$conf["path"]."/";
226 liveuser 15846
 
3 liveuser 15847
			}#if end
226 liveuser 15848
 
3 liveuser 15849
		#記錄真正的路徑
15850
		$result["path"]=$conf["path"];
226 liveuser 15851
 
3 liveuser 15852
		#函式說明:
15853
		#呼叫shell執行系統命令,並取得回傳的內容.
15854
		#回傳結果:
15855
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15856
		#$result["error"],錯誤訊息陣列.
15857
		#$result["function"],當前執行的函數名稱.
15858
		#$result["argu"],使用的參數.
15859
		#$result["cmd"],執行的指令內容.
15860
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15861
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15862
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15863
		#$result["running"],是否還在執行.
15864
		#$result["pid"],pid.
15865
		#$result["statusCode"],執行結束後的代碼.
15866
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
15867
		#必填參數:
15868
		#$conf["command"],字串,要執行的指令.
15869
		$conf["external::callShell"]["command"]="ls";
15870
		#$conf["fileArgu"],字串,變數__FILE__的內容.
15871
		$conf["external::callShell"]["fileArgu"]=__FILE__;
15872
		#可省略參數:
15873
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15874
		$conf["external::callShell"]["argu"]=array("-al","--full-time","-t","-B",$conf["path"]);
15875
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
15876
		#$conf["arguIsAddr"]=array();
15877
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15878
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15879
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15880
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15881
		#$conf["enablePrintDescription"]="true";
15882
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15883
		#$conf["printDescription"]="";
15884
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
15885
		$conf["external::callShell"]["escapeshellarg"]="true";
15886
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
15887
		#$conf["thereIsShellVar"]=array();
15888
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15889
		#$conf["username"]="";
15890
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15891
		#$conf["password"]="";
15892
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15893
		#$conf["useScript"]="";
15894
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15895
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15896
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15897
		#$conf["inBackGround"]="";
15898
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
15899
		#$conf["getErr"]="false";
15900
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
15901
		#$conf["doNotRun"]="false";
15902
		#參考資料:
15903
		#exec=>http://php.net/manual/en/function.exec.php
15904
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15905
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15906
		#備註:
15907
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15908
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
15909
		$callShell=external::callShell($conf["external::callShell"]);
15910
		unset($conf["external::callShell"]);
226 liveuser 15911
 
3 liveuser 15912
		#debug
15913
		#var_dump(__FILE__,__LINE__,$callShell);
226 liveuser 15914
 
3 liveuser 15915
		#如果執行失敗
15916
		if($callShell["status"]==="false"){
226 liveuser 15917
 
3 liveuser 15918
			#設置執行錯誤
15919
			$result["status"]="false";
226 liveuser 15920
 
3 liveuser 15921
			#設置錯誤訊息
15922
			$result["error"]=$callShell;
226 liveuser 15923
 
3 liveuser 15924
			#回傳結果
15925
			return $result;
226 liveuser 15926
 
3 liveuser 15927
			}#if end
226 liveuser 15928
 
3 liveuser 15929
		#初始化儲存檔案資訊為空
15930
		$result["content"]=array();
226 liveuser 15931
 
3 liveuser 15932
		#針對每行輸出
15933
		foreach($callShell["output"] as $index=>$line){
226 liveuser 15934
 
3 liveuser 15935
			#如果是第一筆
15936
			if($index===0){
226 liveuser 15937
 
3 liveuser 15938
				#取得資料筆數
15939
				$result["dataCount"]=explode(" ",$line)[0];
226 liveuser 15940
 
3 liveuser 15941
				#換下一輪
15942
				continue;
226 liveuser 15943
 
3 liveuser 15944
				}#if end
226 liveuser 15945
 
3 liveuser 15946
			#函式說明:
15947
			#將固定格式的字串分開,並回傳分開的結果.
15948
			#回傳結果:
15949
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15950
			#$result["error"],錯誤訊息陣列
15951
			#$result["function"],當前執行的函數名稱.
15952
			#$result["argu"],使用的參數.
15953
			#$result["oriStr"],要分割的原始字串內容
15954
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
15955
			#$result["dataCounts"],爲總共分成幾段
15956
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
15957
			#必填參數:
15958
			#$conf["stringIn"],字串,要處理的字串.
15959
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
15960
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
15961
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
15962
			#可省略參數:
15963
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
15964
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
15965
			#參考資料:
15966
			#無.
15967
			#備註:
15968
			#無.
15969
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
15970
			unset($conf["stringProcess::spiltString"]);
226 liveuser 15971
 
3 liveuser 15972
			#如果執行失敗
15973
			if($spiltString["status"]==="false"){
226 liveuser 15974
 
3 liveuser 15975
				#設置執行錯誤
15976
				$result["status"]="false";
226 liveuser 15977
 
3 liveuser 15978
				#設置錯誤訊息
15979
				$result["error"]=$spiltString;
226 liveuser 15980
 
3 liveuser 15981
				#回傳結果
15982
				return $result;
226 liveuser 15983
 
3 liveuser 15984
				}#if end
226 liveuser 15985
 
3 liveuser 15986
			#如果沒有分割用的" "
15987
			if($spiltString["found"]==="false"){
226 liveuser 15988
 
3 liveuser 15989
				#設置執行錯誤
15990
				$result["status"]="false";
226 liveuser 15991
 
3 liveuser 15992
				#設置錯誤訊息
15993
				$result["error"]=$spiltString;
226 liveuser 15994
 
3 liveuser 15995
				#回傳結果
15996
				return $result;
226 liveuser 15997
 
3 liveuser 15998
				}#if end
226 liveuser 15999
 
3 liveuser 16000
			#如果分割好的數量小於8
16001
			if($spiltString["dataCounts"]<8){
226 liveuser 16002
 
3 liveuser 16003
				#設置執行錯誤
16004
				$result["status"]="false";
226 liveuser 16005
 
3 liveuser 16006
				#設置錯誤訊息
16007
				$result["error"]=$spiltString;
226 liveuser 16008
 
3 liveuser 16009
				#回傳結果
16010
				return $result;
226 liveuser 16011
 
3 liveuser 16012
				}#if end
226 liveuser 16013
 
3 liveuser 16014
			#初始化要儲存的檔案資訊陣列
16015
			$fileInfo=array();
226 liveuser 16016
 
3 liveuser 16017
			#取得 節點類型、權限
16018
			$fileInfo["nType&permission"]=$spiltString["dataArray"][0];
226 liveuser 16019
 
3 liveuser 16020
			#剔除結尾的 "."
16021
			$fileInfo["nType&permission"]=substr($fileInfo["nType&permission"],0,strlen($fileInfo["nType&permission"])-1);
226 liveuser 16022
 
3 liveuser 16023
			#取得節點類型
16024
			$fileInfo["nType"]=$fileInfo["nType&permission"][0];
226 liveuser 16025
 
3 liveuser 16026
			#取得節點權限
16027
			$fileInfo["permission"]=substr($fileInfo["nType&permission"],1);
226 liveuser 16028
 
3 liveuser 16029
			#取得擁有者賬號
16030
			$fileInfo["ownByUser"]=$spiltString["dataArray"][2];
226 liveuser 16031
 
3 liveuser 16032
			#取得群組擁有者群組
16033
			$fileInfo["ownByGroup"]=$spiltString["dataArray"][3];
226 liveuser 16034
 
3 liveuser 16035
			#取得size
16036
			$fileInfo["bytes"]=$spiltString["dataArray"][4];
226 liveuser 16037
 
16038
			#取得最後異動日期
3 liveuser 16039
			$fileInfo["date"]=$spiltString["dataArray"][5];
226 liveuser 16040
 
3 liveuser 16041
			#取得最後異動時間
16042
			$fileInfo["time"]=explode(".",$spiltString["dataArray"][6])[0];
226 liveuser 16043
 
3 liveuser 16044
			#取得最後異動的詳細時間
16045
			$fileInfo["timeDetail"]=$spiltString["dataArray"][6];
226 liveuser 16046
 
3 liveuser 16047
			#取得timezone資訊
16048
			$fileInfo["timezone"]=$spiltString["dataArray"][7];
226 liveuser 16049
 
3 liveuser 16050
			#函式說明:
16051
			#將固定格式的字串分開,並回傳分開的結果.
16052
			#回傳結果:
16053
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16054
			#$result["error"],錯誤訊息陣列
16055
			#$result["function"],當前執行的函數名稱.
16056
			#$result["argu"],使用的參數.
16057
			#$result["oriStr"],要分割的原始字串內容
16058
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
16059
			#$result["dataCounts"],爲總共分成幾段
16060
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
16061
			#必填參數:
16062
			#$conf["stringIn"],字串,要處理的字串.
16063
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
16064
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
16065
			$conf["stringProcess::spiltString"]["spiltSymbol"]=$fileInfo["date"]." ".$fileInfo["timeDetail"]." ".$fileInfo["timezone"];
16066
			#可省略參數:
16067
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
16068
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
16069
			#參考資料:
16070
			#無.
16071
			#備註:
16072
			#無.
16073
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
16074
			unset($conf["stringProcess::spiltString"]);
226 liveuser 16075
 
3 liveuser 16076
			#如果執行失敗
16077
			if($spiltString["status"]==="false"){
226 liveuser 16078
 
3 liveuser 16079
				#設置執行錯誤
16080
				$result["status"]="false";
226 liveuser 16081
 
3 liveuser 16082
				#設置錯誤訊息
16083
				$result["error"]=$spiltString;
226 liveuser 16084
 
3 liveuser 16085
				#回傳結果
16086
				return $result;
226 liveuser 16087
 
3 liveuser 16088
				}#if end
226 liveuser 16089
 
3 liveuser 16090
			#如果沒有分割用的" "
16091
			if($spiltString["found"]==="false"){
226 liveuser 16092
 
3 liveuser 16093
				#設置執行錯誤
16094
				$result["status"]="false";
226 liveuser 16095
 
3 liveuser 16096
				#設置錯誤訊息
16097
				$result["error"]=$spiltString;
226 liveuser 16098
 
3 liveuser 16099
				#回傳結果
16100
				return $result;
226 liveuser 16101
 
3 liveuser 16102
				}#if end
226 liveuser 16103
 
3 liveuser 16104
			#如果分割好的數量小於8
16105
			if($spiltString["dataCounts"]<2){
226 liveuser 16106
 
3 liveuser 16107
				#設置執行錯誤
16108
				$result["status"]="false";
226 liveuser 16109
 
3 liveuser 16110
				#設置錯誤訊息
16111
				$result["error"]=$spiltString;
226 liveuser 16112
 
3 liveuser 16113
				#回傳結果
16114
				return $result;
226 liveuser 16115
 
3 liveuser 16116
				}#if end
226 liveuser 16117
 
3 liveuser 16118
			#取得節點名稱,剔除開頭的空白.
16119
			$fileInfo["name"]=substr($spiltString["dataArray"][1],1);
226 liveuser 16120
 
3 liveuser 16121
			#排除 "." 跟 ".."
16122
			if($fileInfo["name"]==="." || $fileInfo["name"]===".."){
226 liveuser 16123
 
3 liveuser 16124
				#跳過
16125
				continue;
226 liveuser 16126
 
3 liveuser 16127
				}#if end
226 liveuser 16128
 
3 liveuser 16129
			#如果是檔案
16130
			if($fileInfo["nType"]==="-"){
226 liveuser 16131
 
3 liveuser 16132
				#取得mime type
16133
				$fileInfo["mimeType"]=@mime_content_type($conf["path"].$fileInfo["name"]);
226 liveuser 16134
 
3 liveuser 16135
				#如果讀取失敗
16136
				if($fileInfo["mimeType"]===false){
226 liveuser 16137
 
3 liveuser 16138
					#通常為沒有權限
226 liveuser 16139
 
3 liveuser 16140
					#跳過該檔案
16141
					continue;
226 liveuser 16142
 
3 liveuser 16143
					}#if end
226 liveuser 16144
 
3 liveuser 16145
				#確認檔案名稱中間含是否有 "."
16146
				#函式說明:
16147
				#取得關鍵字在字串的哪個位置(字首,字尾,中間)
16148
				#回傳結果:
16149
				#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
16150
				#$result["error"],錯誤訊息陣列.
16151
				#$result["function"],當前執行的函數名稱.
16152
				#$result["found"],是否有關鍵字存在,若為"true",代表存在;反之為"false".
16153
				#$result["argu"],傳入的參數.
16154
				#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
16155
				#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
16156
				#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
16157
				#$result["indexS"],關鍵字在被搜尋字串的哪個位置開始.
16158
				#$result["indexE"],關鍵字在被搜尋字串的哪個位置結束.
16159
				#必填參數:
16160
				#$conf["inputStr"],字串,被搜尋的字串.
16161
				$conf["search::findKeyWordPosition"]["inputStr"]=$fileInfo["name"];
16162
				#$conf["keyWord"],字串,關鍵字.
16163
				$conf["search::findKeyWordPosition"]["keyWord"]=".";
16164
				#可省略參數:
16165
				#無.
16166
				#參考資料:
16167
				#http://php.net/manual/en/function.strpos.php
16168
				#備註:
16169
				#無.
16170
				$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
16171
				unset($conf["search::findKeyWordPosition"]);
226 liveuser 16172
 
3 liveuser 16173
				#如果執行失敗
16174
				if($findKeyWordPosition["status"]==="false"){
226 liveuser 16175
 
3 liveuser 16176
					#設置執行錯誤
16177
					$result["status"]="false";
226 liveuser 16178
 
3 liveuser 16179
					#設置錯誤訊息
16180
					$result["error"]=$spiltString;
226 liveuser 16181
 
3 liveuser 16182
					#回傳結果
16183
					return $result;
226 liveuser 16184
 
3 liveuser 16185
					}#if end
226 liveuser 16186
 
3 liveuser 16187
				#如果含有 "." 存在
16188
				if($findKeyWordPosition["found"]==="true"){
226 liveuser 16189
 
3 liveuser 16190
					#如果 "." 是在中間,不是在尾巴.
16191
					if($findKeyWordPosition["center"]==="true" && $findKeyWordPosition["tail"]==="false"){
226 liveuser 16192
 
3 liveuser 16193
						#取得 "." 之後的內容
16194
						#函式說明:
16195
						#將字串特定關鍵字與其前面的內容剔除
16196
						#回傳結果:
16197
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16198
						#$result["error"],錯誤訊息陣列.
16199
						#$result["warning"],警告訊息鎮列.
16200
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
16201
						#$result["function"],當前執行的函數名稱.
16202
						#$result["argu"],使用的參數.
16203
						#$result["oriStr"],要處理的原始字串內容.
16204
						#$result["content"],處理好的的字串內容.
16205
						#$result["deleted"],被移除的內容.
16206
						#必填參數:
16207
						#$conf["stringIn"],字串,要處理的字串.
16208
						$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$fileInfo["name"];
16209
						#$conf["keyWord"],字串,特定字串.
16210
						$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=".";
16211
						#可省略參數:
16212
						#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
16213
						$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
16214
						#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
16215
						#$conf["lastResult"]=$delStrBeforeKeyWord;
16216
						#參考資料:
16217
						#無.
16218
						#備註:
16219
						#無.
16220
						$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
16221
						unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 16222
 
3 liveuser 16223
						#如果執行失敗
16224
						if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 16225
 
3 liveuser 16226
							#設置執行錯誤
16227
							$result["status"]="false";
226 liveuser 16228
 
3 liveuser 16229
							#設置錯誤訊息
16230
							$result["error"]=$spiltString;
226 liveuser 16231
 
3 liveuser 16232
							#回傳結果
16233
							return $result;
226 liveuser 16234
 
3 liveuser 16235
							}#if end
226 liveuser 16236
 
3 liveuser 16237
						#如果該存在的 "." 不存在
16238
						if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 16239
 
3 liveuser 16240
							#設置執行錯誤
16241
							$result["status"]="false";
226 liveuser 16242
 
3 liveuser 16243
							#設置錯誤訊息
16244
							$result["error"]=$spiltString;
226 liveuser 16245
 
3 liveuser 16246
							#回傳結果
16247
							return $result;
226 liveuser 16248
 
3 liveuser 16249
							}#if end
226 liveuser 16250
 
3 liveuser 16251
						#取得附檔名
16252
						$fileInfo["secondName"]=$delStrBeforeKeyWord["content"];
226 liveuser 16253
 
3 liveuser 16254
						}#if end
226 liveuser 16255
 
3 liveuser 16256
					}#if end
226 liveuser 16257
 
3 liveuser 16258
				}#if end
226 liveuser 16259
 
3 liveuser 16260
			#儲存檔案資訊
16261
			$result["content"][]=$fileInfo;
226 liveuser 16262
 
3 liveuser 16263
			}#foreach end
226 liveuser 16264
 
3 liveuser 16265
		#設置清單的長度
16266
		$result["dataCount"]=count($result["content"]);
226 liveuser 16267
 
3 liveuser 16268
		#設置執行正常
16269
		$result["status"]="true";
226 liveuser 16270
 
3 liveuser 16271
		#回傳結果
16272
		return $result;
226 liveuser 16273
 
3 liveuser 16274
		}#function ls end
16275
 
16276
	/*
16277
	#函式說明:
16278
	#將 ~ 轉換為家目錄路徑
16279
	#回傳結果:
16280
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16281
	#$result["error"],錯誤訊息.
16282
	#$result["function"],當前執行的函數名稱.
16283
	#$result["content"],轉換好的內容.
16284
	#必填參數:
16285
	#$conf["fileArgu"],字串,變數__FILE__的內容.
16286
	$conf["fileArgu"]=__FILE__;
16287
	#可省略參數:
16288
	#無.
16289
	#參考資料:
16290
	#https://www.businessweekly.com.tw/careers/Blog/14307
16291
	#備註:
16292
	#無.
16293
	*/
16294
	public static function tildeToPath(&$conf){
226 liveuser 16295
 
3 liveuser 16296
		#初始化要回傳的結果
16297
		$result=array();
16298
 
16299
		#取得當前執行的函數名稱
16300
		$result["function"]=__FUNCTION__;
16301
 
16302
		#如果沒有參數
16303
		if(func_num_args()==0){
226 liveuser 16304
 
3 liveuser 16305
			#設置執行失敗
16306
			$result["status"]="false";
226 liveuser 16307
 
3 liveuser 16308
			#設置執行錯誤訊息
16309
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 16310
 
3 liveuser 16311
			#回傳結果
16312
			return $result;
226 liveuser 16313
 
220 liveuser 16314
			}#if end
3 liveuser 16315
 
16316
		#取得參數
16317
		$result["argu"]=$conf;
16318
 
16319
		#如果 $conf 不為陣列
16320
		if(gettype($conf)!=="array"){
226 liveuser 16321
 
3 liveuser 16322
			#設置執行失敗
16323
			$result["status"]="false";
226 liveuser 16324
 
3 liveuser 16325
			#設置執行錯誤訊息
16326
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 16327
 
3 liveuser 16328
			#如果傳入的參數為 null
16329
			if($conf===null){
226 liveuser 16330
 
3 liveuser 16331
				#設置執行錯誤訊息
16332
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 16333
 
3 liveuser 16334
				}#if end
16335
 
16336
			#回傳結果
16337
			return $result;
226 liveuser 16338
 
3 liveuser 16339
			}#if end
226 liveuser 16340
 
3 liveuser 16341
		#函式說明:
16342
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
16343
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16344
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
16345
		#$result["function"],當前執行的函式名稱.
16346
		#$result["argu"],設置給予的參數.
16347
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
16348
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
16349
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
16350
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
16351
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
16352
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
16353
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
16354
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
16355
		#必填寫的參數:
16356
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 16357
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 16358
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
16359
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
16360
		#可以省略的參數:
16361
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
16362
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
16363
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
16364
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
16365
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
16366
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
16367
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
16368
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
16369
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
16370
		#$conf["canBeEmpty"]=array();
16371
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
16372
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
16373
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
16374
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 16375
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 16376
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
16377
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
16378
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
16379
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
16380
		#$conf["disallowAllSkipableVarIsEmpty"]="";
16381
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
16382
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
16383
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
16384
		#$conf["arrayCountEqualCheck"][]=array();
16385
		#參考資料來源:
16386
		#array_keys=>http://php.net/manual/en/function.array-keys.php
16387
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
16388
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 16389
 
3 liveuser 16390
		#如果檢查參數失敗
16391
		if($checkArguments["status"]==="false"){
226 liveuser 16392
 
3 liveuser 16393
			#設置執行失敗
16394
			$result["status"]="false";
226 liveuser 16395
 
3 liveuser 16396
			#設置執行失敗訊息
16397
			$result["error"]=$checkArguments;
226 liveuser 16398
 
3 liveuser 16399
			#回傳結果
16400
			return $result;
226 liveuser 16401
 
3 liveuser 16402
			}#if end
226 liveuser 16403
 
3 liveuser 16404
		#如果檢查參數不通過
16405
		if($checkArguments["passed"]==="false"){
226 liveuser 16406
 
3 liveuser 16407
			#設置執行失敗
16408
			$result["status"]="false";
226 liveuser 16409
 
3 liveuser 16410
			#設置執行失敗訊息
16411
			$result["error"]=$checkArguments;
226 liveuser 16412
 
3 liveuser 16413
			#回傳結果
16414
			return $result;
226 liveuser 16415
 
3 liveuser 16416
			}#if end
16417
 
16418
		#函式說明:
16419
		#呼叫shell執行系統命令,並取得回傳的內容.
16420
		#回傳結果:
16421
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16422
		#$result["error"],錯誤訊息陣列.
16423
		#$result["function"],當前執行的函數名稱.
16424
		#$result["argu"],使用的參數.
16425
		#$result["cmd"],執行的指令內容.
16426
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16427
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16428
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16429
		#$result["running"],是否還在執行.
16430
		#$result["pid"],pid.
16431
		#$result["statusCode"],執行結束後的代碼.
16432
		#必填參數:
16433
		#$conf["command"],字串,要執行的指令與.
16434
		$conf["external::callShell"]["command"]="echo";
16435
		#$conf["fileArgu"],字串,變數__FILE__的內容.
16436
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16437
		#可省略參數:
16438
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16439
		$conf["external::callShell"]["argu"]=array("~");
16440
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16441
		#$conf["arguIsAddr"]=array();
16442
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16443
		#$conf["plainArgu"]=array();
16444
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16445
		#$conf["useApostrophe"]=array();
16446
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16447
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16448
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16449
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16450
		#$conf["enablePrintDescription"]="true";
16451
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16452
		#$conf["printDescription"]="";
16453
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16454
		$conf["external::callShell"]["escapeshellarg"]="true";
16455
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16456
		#$conf["thereIsShellVar"]=array();
16457
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16458
		#$conf["username"]="";
16459
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16460
		#$conf["password"]="";
16461
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16462
		#$conf["useScript"]="";
16463
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16464
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16465
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16466
		#$conf["inBackGround"]="";
16467
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16468
		#$conf["getErr"]="false";
16469
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16470
		#$conf["doNotRun"]="false";
16471
		#參考資料:
16472
		#exec=>http://php.net/manual/en/function.exec.php
16473
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16474
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16475
		#備註:
16476
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16477
		$callShell=external::callShell($conf["external::callShell"]);
16478
		unset($conf["external::callShell"]);
16479
 
16480
		#如果執行失敗
16481
		if($callShell["status"]==="false"){
226 liveuser 16482
 
3 liveuser 16483
			#設置執行失敗
16484
			$result["status"]="false";
226 liveuser 16485
 
3 liveuser 16486
			#設置執行失敗訊息
16487
			$result["error"]=$callShell;
226 liveuser 16488
 
3 liveuser 16489
			#回傳結果
16490
			return $result;
226 liveuser 16491
 
3 liveuser 16492
			}#if end
226 liveuser 16493
 
3 liveuser 16494
		#如果沒有預期的輸出
16495
		if(!isset($callShell["output"][0])){
226 liveuser 16496
 
3 liveuser 16497
			#設置執行失敗
16498
			$result["status"]="false";
226 liveuser 16499
 
3 liveuser 16500
			#設置執行失敗訊息
16501
			$result["error"][]="沒有得到預期的輸出";
226 liveuser 16502
 
3 liveuser 16503
			#設置執行失敗訊息
16504
			$result["error"][]=$callShell;
226 liveuser 16505
 
3 liveuser 16506
			#回傳結果
16507
			return $result;
226 liveuser 16508
 
3 liveuser 16509
			}#if end
226 liveuser 16510
 
3 liveuser 16511
		#取得輸出
16512
		$result["content"]=$callShell["output"][0];
226 liveuser 16513
 
3 liveuser 16514
		#設置執行正常
16515
		$result["status"]="true";
226 liveuser 16516
 
3 liveuser 16517
		#回傳結果
16518
		return $result;
226 liveuser 16519
 
3 liveuser 16520
		}#function tildeToPath end
16521
 
16522
	/*
16523
	#函式說明:
16524
	#建立軟連結.
16525
	#回傳結果:
16526
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16527
	#$result["error"],錯誤訊息.
16528
	#$result["function"],當前執行的函數名稱.
16529
	#$result["content"],軟連結的資訊.
16530
	#$result["cmd"],執行的指令陣列.
16531
	#必填參數:
16532
	#$conf["fileArgu"],字串,變數__FILE__的內容.
16533
	$conf["fileArgu"]=__FILE__;
16534
	#$conf["linkTo"],字串,軟連結要指向哪邊.
16535
	$conf["linkTo"]="";
16536
	#可省略參數:
16537
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
16538
	#$conf["path"]="";
16539
	#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
16540
	#$conf["name"]="";
16541
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
16542
	#$conf["overWrite"]="true";
16543
	#參考資料:
16544
	#無.
16545
	#備註:
16546
	#無.
16547
	*/
16548
	public static function createLink(&$conf){
226 liveuser 16549
 
3 liveuser 16550
		#初始化要回傳的結果
16551
		$result=array();
16552
 
16553
		#取得當前執行的函數名稱
16554
		$result["function"]=__FUNCTION__;
16555
 
16556
		#如果沒有參數
16557
		if(func_num_args()==0){
226 liveuser 16558
 
3 liveuser 16559
			#設置執行失敗
16560
			$result["status"]="false";
226 liveuser 16561
 
3 liveuser 16562
			#設置執行錯誤訊息
16563
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 16564
 
3 liveuser 16565
			#回傳結果
16566
			return $result;
226 liveuser 16567
 
220 liveuser 16568
			}#if end
3 liveuser 16569
 
16570
		#取得參數
16571
		$result["argu"]=$conf;
16572
 
16573
		#如果 $conf 不為陣列
16574
		if(gettype($conf)!=="array"){
226 liveuser 16575
 
3 liveuser 16576
			#設置執行失敗
16577
			$result["status"]="false";
226 liveuser 16578
 
3 liveuser 16579
			#設置執行錯誤訊息
16580
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 16581
 
3 liveuser 16582
			#如果傳入的參數為 null
16583
			if($conf===null){
226 liveuser 16584
 
3 liveuser 16585
				#設置執行錯誤訊息
16586
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 16587
 
3 liveuser 16588
				}#if end
16589
 
16590
			#回傳結果
16591
			return $result;
226 liveuser 16592
 
3 liveuser 16593
			}#if end
226 liveuser 16594
 
3 liveuser 16595
		#函式說明:
16596
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
16597
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16598
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
16599
		#$result["function"],當前執行的函式名稱.
16600
		#$result["argu"],設置給予的參數.
16601
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
16602
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
16603
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
16604
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
16605
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
16606
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
16607
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
16608
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
16609
		#必填寫的參數:
16610
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 16611
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 16612
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
16613
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
16614
		#可以省略的參數:
16615
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
16616
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkTo");
16617
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
16618
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
16619
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
16620
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
16621
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
16622
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
16623
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
16624
		#$conf["canBeEmpty"]=array();
16625
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
16626
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","name","overWrite");
16627
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
16628
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","name","overWrite");
226 liveuser 16629
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 16630
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
16631
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
16632
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false");
16633
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
16634
		#$conf["disallowAllSkipableVarIsEmpty"]="";
16635
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
16636
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
16637
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
16638
		#$conf["arrayCountEqualCheck"][]=array();
16639
		#參考資料來源:
16640
		#array_keys=>http://php.net/manual/en/function.array-keys.php
16641
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
16642
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 16643
 
3 liveuser 16644
		#如果檢查參數失敗
16645
		if($checkArguments["status"]==="false"){
226 liveuser 16646
 
3 liveuser 16647
			#設置執行失敗
16648
			$result["status"]="false";
226 liveuser 16649
 
3 liveuser 16650
			#設置執行失敗訊息
16651
			$result["error"]=$checkArguments;
226 liveuser 16652
 
3 liveuser 16653
			#回傳結果
16654
			return $result;
226 liveuser 16655
 
3 liveuser 16656
			}#if end
226 liveuser 16657
 
3 liveuser 16658
		#如果檢查參數不通過
16659
		if($checkArguments["passed"]==="false"){
226 liveuser 16660
 
3 liveuser 16661
			#設置執行失敗
16662
			$result["status"]="false";
226 liveuser 16663
 
3 liveuser 16664
			#設置執行失敗訊息
16665
			$result["error"]=$checkArguments;
226 liveuser 16666
 
3 liveuser 16667
			#回傳結果
16668
			return $result;
226 liveuser 16669
 
3 liveuser 16670
			}#if end
16671
 
16672
		#如果是相對位置
16673
		if(!(strpos($conf["linkTo"],"/")===0)){
226 liveuser 16674
 
3 liveuser 16675
			#將 $conf["linkTo"] 轉換為針對產生位置的相對位置.
16676
			#函式說明:
16677
			#將多個路徑字串變成相對於當前路徑的相對路徑字串
16678
			#回傳結果:
16679
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
16680
			#$result["error"],錯誤訊息陣列.
226 liveuser 16681
			#$result["function"],函數名稱.
3 liveuser 16682
			#$result["argu"],使用的參數.
16683
			#$result["content"],字串陣列,多個轉換好的相對路徑字串.
16684
			#必填參數:
16685
			#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
16686
			$conf["fileAccess::getRelativePath"]["path"]=array($conf["linkTo"]);
16687
			#$conf["fileArgu"],字串,當前路徑.
16688
			$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
16689
			#可省略參數:
16690
			#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
16691
			$conf["fileAccess::getRelativePath"]["baseFrom"]=$conf["path"];
16692
			#參考資料:
16693
			#無.
16694
			#備註:
16695
			#無.
16696
			$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
16697
			unset($conf["fileAccess::getRelativePath"]);
16698
 
16699
			#如果執行失敗
16700
			if($getRelativePath["status"]==="false"){
226 liveuser 16701
 
3 liveuser 16702
				#設置執行失敗
16703
				$result["status"]="false";
226 liveuser 16704
 
3 liveuser 16705
				#設置執行失敗訊息
16706
				$result["error"]=$getRelativePath;
226 liveuser 16707
 
3 liveuser 16708
				#回傳結果
16709
				return $result;
226 liveuser 16710
 
3 liveuser 16711
				}#if end
16712
 
16713
			/*
16714
			#break point
16715
			var_dump($conf);
16716
			var_dump($getRelativePath);
16717
			exit;
16718
			*/
16719
 
16720
			#取得執行的指令
16721
			$result["cmd"][]=$getRelativePath["cmd"];
16722
 
16723
			#取得正確的相對位置
16724
			$conf["linkTo"]=$getRelativePath["content"][0];
226 liveuser 16725
 
3 liveuser 16726
			}#if end
16727
 
16728
		#初始化給 ln 指令的參數
16729
		$paramsForLn=array("-s",$conf["linkTo"]);
16730
 
16731
		#函式說明:
16732
		#將字串特定關鍵字與其前面的內容剔除
16733
		#回傳結果:
16734
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16735
		#$result["error"],錯誤訊息陣列.
16736
		#$result["warning"],警告訊息鎮列.
16737
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
16738
		#$result["function"],當前執行的函數名稱.
16739
		#$result["oriStr"],要處理的原始字串內容.
226 liveuser 16740
		#$result["content"],處理好的的字串內容.
3 liveuser 16741
		#必填參數:
16742
		#$conf["stringIn"],字串,要處理的字串.
16743
		$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["linkTo"];
16744
		#$conf["keyWord"],字串,特定字串.
16745
		$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="/";
16746
		#可省略參數:
16747
		#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
16748
		$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
16749
		#參考資料:
16750
		#無.
16751
		#備註:
16752
		#無.
16753
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
16754
		unset($conf["stringProcess::delStrBeforeKeyWord"]);
16755
 
16756
		#var_dump(__LINE__." ".print_r($delStrBeforeKeyWord,true));
16757
 
16758
		#如果執行失敗
16759
		if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 16760
 
3 liveuser 16761
			#設置執行失敗
16762
			$result["status"]="false";
226 liveuser 16763
 
3 liveuser 16764
			#設置執行失敗訊息
16765
			$result["error"]=$delStrBeforeKeyWord;
226 liveuser 16766
 
3 liveuser 16767
			#回傳結果
16768
			return $result;
226 liveuser 16769
 
3 liveuser 16770
			}#if end
226 liveuser 16771
 
3 liveuser 16772
		#如果沒有找到 "/"
16773
		if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 16774
 
3 liveuser 16775
			#設置 預設的 軟連名稱
16776
			$softLink=$conf["linkTo"];
226 liveuser 16777
 
3 liveuser 16778
			}#if end
16779
 
16780
		#反之有 "/"
16781
		else{
226 liveuser 16782
 
3 liveuser 16783
			#設置 預設的 軟連結名稱
16784
			$softLink=$delStrBeforeKeyWord["content"];
226 liveuser 16785
 
3 liveuser 16786
			}#else end
16787
 
16788
		/*
16789
		#break point
16790
		var_dump(__LINE__." ".$softLink);
16791
		exit;
16792
		*/
16793
 
16794
		#預設欲建立的軟連結名稱
16795
		$createdSoftLink=$softLink;
16796
 
16797
		#如果有設置 path
16798
		if(isset($conf["path"])){
226 liveuser 16799
 
3 liveuser 16800
			#確認 path 存在
16801
			#函式說明:
16802
			#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
16803
			#回傳結果:
16804
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
16805
			#$result["error"],錯誤訊息陣列
16806
			#$result["warning"],警告訊息陣列
16807
			#必填參數:
16808
			#$conf["dirPositionAndName"]="";#新建的位置與名稱
16809
			$conf["fileAccess::createNewFolder"]["dirPositionAndName"]=$conf["path"];
16810
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
16811
			$conf["fileAccess::createNewFolder"]["fileArgu"]=$conf["fileArgu"];
16812
			#可省略參數:
16813
			#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
16814
			#$conf["dirPermission"]="";
16815
			#參考資料:
16816
			#mkdir=>http://php.net/manual/en/function.mkdir.php
16817
			#chmod=>http://php.net/manual/en/function.chmod.php
16818
			#參考資料:
16819
			#無.
16820
			#備註:
16821
			#同 function createFolderAfterCheck.
16822
			$createNewFolder=fileAccess::createNewFolder($conf["fileAccess::createNewFolder"]);
16823
			unset($conf["fileAccess::createNewFolder"]);
226 liveuser 16824
 
3 liveuser 16825
			#如果執行失敗
16826
			if($createNewFolder["status"]==="false"){
226 liveuser 16827
 
3 liveuser 16828
				#設置執行失敗
16829
				$result["status"]="false";
226 liveuser 16830
 
3 liveuser 16831
				#設置執行失敗訊息
16832
				$result["error"]=$createNewFolder;
226 liveuser 16833
 
3 liveuser 16834
				#回傳結果
16835
				return $result;
226 liveuser 16836
 
3 liveuser 16837
				}#if end
226 liveuser 16838
 
3 liveuser 16839
			#var_dump(__LINE__." ".print_r($conf,true));
226 liveuser 16840
 
3 liveuser 16841
			#預設要加 slash
16842
			$slash="/";
226 liveuser 16843
 
3 liveuser 16844
			#如果 path 為 "/" 結尾
16845
			if($conf["path"][strlen($conf["path"])-1]==="/"){
226 liveuser 16846
 
3 liveuser 16847
				#不用 slash
16848
				$slash="";
226 liveuser 16849
 
3 liveuser 16850
				}#if end
226 liveuser 16851
 
3 liveuser 16852
			#如果有設置 name
16853
			if(isset($conf["name"])){
226 liveuser 16854
 
3 liveuser 16855
				#指定軟連結要放在哪邊
16856
				$paramsForLn[]=$conf["path"].$slash.$conf["name"];
226 liveuser 16857
 
3 liveuser 16858
				#更新欲建立的軟連結名稱
16859
				$createdSoftLink=$conf["path"].$slash.$conf["name"];
226 liveuser 16860
 
3 liveuser 16861
				/*
16862
				#break point
16863
				var_dump($conf["path"],$softLink,$createdSoftLink);
16864
				exit;
16865
				*/
226 liveuser 16866
 
3 liveuser 16867
				}#if end
226 liveuser 16868
 
3 liveuser 16869
			#反之
16870
			else{
226 liveuser 16871
 
3 liveuser 16872
				#指定軟連結要放在哪邊
16873
				$paramsForLn[]=$conf["path"];
226 liveuser 16874
 
3 liveuser 16875
				#更新欲建立的軟連結名稱
16876
				$createdSoftLink=$conf["path"].$slash.$softLink;
226 liveuser 16877
 
3 liveuser 16878
				/*
16879
				#break point
16880
				var_dump($conf["path"],$softLink,$createdSoftLink);
16881
				exit;
16882
				*/
226 liveuser 16883
 
3 liveuser 16884
				}#else end
226 liveuser 16885
 
3 liveuser 16886
			#var_dump($createdSoftLink);
226 liveuser 16887
 
3 liveuser 16888
			}#if end
226 liveuser 16889
 
3 liveuser 16890
		#反之如果有設置 name
16891
		else if(isset($conf["name"])){
226 liveuser 16892
 
3 liveuser 16893
			#指定軟連結的名稱
16894
			$paramsForLn[]=$conf["name"];
226 liveuser 16895
 
3 liveuser 16896
			#更新欲建立的軟連結名稱
16897
			$createdSoftLink=$conf["name"];
226 liveuser 16898
 
3 liveuser 16899
			#var_dump(__LINE__." ".$createdSoftLink);
226 liveuser 16900
 
3 liveuser 16901
			}#if end
226 liveuser 16902
 
3 liveuser 16903
		/*
16904
		# break point
16905
		var_dump($createdSoftLink);
16906
		exit;
16907
		*/
226 liveuser 16908
 
3 liveuser 16909
		#如果要覆蓋既有的目標
16910
		if($conf["overWrite"]==="true"){
226 liveuser 16911
 
3 liveuser 16912
			#函式說明:
16913
			#移除檔案
16914
			#回傳結果:
16915
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
16916
			#$result["error"],錯誤訊息陣列
16917
			#$result["warning"],警告訊息陣列
16918
			#$result["function"],當前執行的函數名稱
16919
			#必填參數:
16920
			#$conf["fileAddress"],字串,要移除檔案的位置.
16921
			$conf["fileAccess::delFile"]["fileAddress"]=$createdSoftLink;
16922
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
16923
			$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
16924
			#可省略參數:
16925
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
16926
			#$conf["commentsArray"]=array("");
16927
			#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
16928
			$conf["fileAccess::delFile"]["allowDelSymlink"]="true";
16929
			#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
16930
			$conf["fileAccess::delFile"]["allowDelFolder"]="true";
16931
			#參考資料:
16932
			#無.
16933
			#備註:
16934
			#無.
16935
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
226 liveuser 16936
			unset($conf["fileAccess::delFile"]);
16937
 
3 liveuser 16938
			/*
16939
			#break point
16940
			var_dump($delFile);
16941
			exit;
16942
			*/
226 liveuser 16943
 
3 liveuser 16944
			#如果執行失敗
16945
			if($delFile["status"]==="false"){
226 liveuser 16946
 
3 liveuser 16947
				#設置執行失敗
16948
				$result["status"]="false";
226 liveuser 16949
 
3 liveuser 16950
				#設置執行失敗訊息
16951
				$result["error"]=$delFile;
226 liveuser 16952
 
3 liveuser 16953
				#回傳結果
16954
				return $result;
226 liveuser 16955
 
3 liveuser 16956
				}#if end
226 liveuser 16957
 
3 liveuser 16958
			}#if end
16959
 
16960
		#函式說明:
16961
		#呼叫shell執行系統命令,並取得回傳的內容.
16962
		#回傳結果:
16963
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16964
		#$result["error"],錯誤訊息陣列.
16965
		#$result["function"],當前執行的函數名稱.
16966
		#$result["argu"],使用的參數.
16967
		#$result["cmd"],執行的指令內容.
16968
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16969
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16970
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16971
		#$result["running"],是否還在執行.
16972
		#$result["pid"],pid.
16973
		#$result["statusCode"],執行結束後的代碼.
16974
		#必填參數:
16975
		#$conf["command"],字串,要執行的指令與.
16976
		$conf["external::callShell"]["command"]="ln";
16977
		#$conf["fileArgu"],字串,變數__FILE__的內容.
16978
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16979
		#可省略參數:
16980
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16981
		$conf["external::callShell"]["argu"]=$paramsForLn;
16982
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16983
		#$conf["arguIsAddr"]=array();
16984
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16985
		#$conf["plainArgu"]=array();
16986
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16987
		#$conf["useApostrophe"]=array();
16988
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16989
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16990
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16991
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16992
		#$conf["enablePrintDescription"]="true";
16993
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16994
		#$conf["printDescription"]="";
16995
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16996
		$conf["external::callShell"]["escapeshellarg"]="true";
16997
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16998
		#$conf["thereIsShellVar"]=array();
16999
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17000
		#$conf["username"]="";
17001
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17002
		#$conf["password"]="";
17003
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17004
		#$conf["useScript"]="";
17005
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17006
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17007
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17008
		#$conf["inBackGround"]="";
17009
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17010
		$conf["external::callShell"]["getErr"]="true";
17011
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17012
		#$conf["doNotRun"]="false";
17013
		#參考資料:
17014
		#exec=>http://php.net/manual/en/function.exec.php
17015
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17016
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17017
		#備註:
17018
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17019
		$callShell=external::callShell($conf["external::callShell"]);
17020
		unset($conf["external::callShell"]);
17021
 
17022
		#如果執行失敗
17023
		if($callShell["status"]==="false"){
226 liveuser 17024
 
3 liveuser 17025
			#設置執行失敗
17026
			$result["status"]="false";
226 liveuser 17027
 
3 liveuser 17028
			#設置執行失敗訊息
17029
			$result["error"]=$callShell;
226 liveuser 17030
 
3 liveuser 17031
			#回傳結果
17032
			return $result;
226 liveuser 17033
 
3 liveuser 17034
			}#if end
226 liveuser 17035
 
3 liveuser 17036
		#保存執行的指令
17037
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 17038
 
3 liveuser 17039
		#初始化給 ls 指令的參數
17040
		$paramsForLs=array("-l",$paramsForLn[count($paramsForLn)-1]);
226 liveuser 17041
 
3 liveuser 17042
		#取得軟連結的資訊
17043
		#函式說明:
17044
		#呼叫shell執行系統命令,並取得回傳的內容.
17045
		#回傳結果:
17046
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17047
		#$result["error"],錯誤訊息陣列.
17048
		#$result["function"],當前執行的函數名稱.
17049
		#$result["argu"],使用的參數.
17050
		#$result["cmd"],執行的指令內容.
17051
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17052
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17053
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17054
		#$result["running"],是否還在執行.
17055
		#$result["pid"],pid.
17056
		#$result["statusCode"],執行結束後的代碼.
17057
		#必填參數:
17058
		#$conf["command"],字串,要執行的指令與.
17059
		$conf["external::callShell"]["command"]="ls";
17060
		#$conf["fileArgu"],字串,變數__FILE__的內容.
17061
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17062
		#可省略參數:
17063
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17064
		$conf["external::callShell"]["argu"]=$paramsForLs;
17065
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17066
		#$conf["arguIsAddr"]=array();
17067
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
17068
		#$conf["plainArgu"]=array();
17069
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
17070
		#$conf["useApostrophe"]=array();
17071
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17072
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17073
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17074
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17075
		#$conf["enablePrintDescription"]="true";
17076
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17077
		#$conf["printDescription"]="";
17078
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
17079
		$conf["external::callShell"]["escapeshellarg"]="true";
17080
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
17081
		#$conf["thereIsShellVar"]=array();
17082
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17083
		#$conf["username"]="";
17084
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17085
		#$conf["password"]="";
17086
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17087
		#$conf["useScript"]="";
17088
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17089
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17090
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17091
		#$conf["inBackGround"]="";
17092
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17093
		$conf["external::callShell"]["getErr"]="true";
17094
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17095
		#$conf["doNotRun"]="false";
17096
		#參考資料:
17097
		#exec=>http://php.net/manual/en/function.exec.php
17098
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17099
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17100
		#備註:
17101
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17102
		$callShell=external::callShell($conf["external::callShell"]);
17103
		unset($conf["external::callShell"]);
17104
 
17105
		#如果執行失敗
17106
		if($callShell["status"]==="false"){
226 liveuser 17107
 
3 liveuser 17108
			#設置執行失敗
17109
			$result["status"]="false";
226 liveuser 17110
 
3 liveuser 17111
			#設置執行失敗訊息
17112
			$result["error"]=$callShell;
226 liveuser 17113
 
3 liveuser 17114
			#回傳結果
17115
			return $result;
226 liveuser 17116
 
3 liveuser 17117
			}#if end
226 liveuser 17118
 
3 liveuser 17119
		#保存執行的指令
17120
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 17121
 
3 liveuser 17122
		#取得軟連結的資訊
17123
		$result["content"]=$callShell["output"];
226 liveuser 17124
 
3 liveuser 17125
		#設置執行正常
17126
		$result["status"]="true";
226 liveuser 17127
 
3 liveuser 17128
		#回傳結果
17129
		return $result;
226 liveuser 17130
 
3 liveuser 17131
		}#function createLink end
17132
 
17133
	/*
17134
	#函式說明:
17135
	#針對特定目錄下的內容建立軟連結.
17136
	#回傳結果:
17137
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17138
	#$result["error"],錯誤訊息.
17139
	#$result["function"],當前執行的函數名稱.
17140
	#$result["content"],字串陣列,每個建立的軟連結資訊.
17141
	#必填參數:
17142
	#$conf["fileArgu"],字串,變數__FILE__的內容.
17143
	$conf["fileArgu"]=__FILE__;
17144
	#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
17145
	$conf["linkToDir"]="";
17146
	#可省略參數:
17147
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
17148
	#$conf["path"]="";
17149
	#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
17150
	#$conf["name"]=array(array("oriName","newName"));
17151
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
17152
	#$conf["overWrite"]="true";
17153
	#參考資料:
17154
	#無.
17155
	#備註:
17156
	#無.
17157
	*/
17158
	public static function createMultiLinkInDir(&$conf){
226 liveuser 17159
 
3 liveuser 17160
		#初始化要回傳的結果
17161
		$result=array();
17162
 
17163
		#取得當前執行的函數名稱
17164
		$result["function"]=__FUNCTION__;
17165
 
17166
		#如果沒有參數
17167
		if(func_num_args()==0){
226 liveuser 17168
 
3 liveuser 17169
			#設置執行失敗
17170
			$result["status"]="false";
226 liveuser 17171
 
3 liveuser 17172
			#設置執行錯誤訊息
17173
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 17174
 
3 liveuser 17175
			#回傳結果
17176
			return $result;
226 liveuser 17177
 
220 liveuser 17178
			}#if end
3 liveuser 17179
 
17180
		#取得參數
17181
		$result["argu"]=$conf;
17182
 
17183
		#如果 $conf 不為陣列
17184
		if(gettype($conf)!=="array"){
226 liveuser 17185
 
3 liveuser 17186
			#設置執行失敗
17187
			$result["status"]="false";
226 liveuser 17188
 
3 liveuser 17189
			#設置執行錯誤訊息
17190
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 17191
 
3 liveuser 17192
			#如果傳入的參數為 null
17193
			if($conf===null){
226 liveuser 17194
 
3 liveuser 17195
				#設置執行錯誤訊息
17196
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 17197
 
3 liveuser 17198
				}#if end
17199
 
17200
			#回傳結果
17201
			return $result;
226 liveuser 17202
 
3 liveuser 17203
			}#if end
226 liveuser 17204
 
3 liveuser 17205
		#檢查參數
17206
		#函式說明:
17207
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
17208
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17209
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
17210
		#$result["function"],當前執行的函式名稱.
17211
		#$result["argu"],設置給予的參數.
17212
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
17213
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
17214
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
17215
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
17216
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
17217
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
17218
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
17219
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
17220
		#必填寫的參數:
17221
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 17222
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 17223
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
17224
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
17225
		#可以省略的參數:
17226
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
17227
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkToDir");
17228
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
17229
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
17230
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
17231
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
17232
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
17233
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
17234
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
17235
		#$conf["canBeEmpty"]=array();
17236
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
17237
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","name","overWrite");
17238
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
17239
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","name","overWrite");
226 liveuser 17240
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 17241
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string");
17242
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
17243
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".",null,"false");
17244
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
17245
		#$conf["disallowAllSkipableVarIsEmpty"]="";
17246
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
17247
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
17248
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
17249
		#$conf["arrayCountEqualCheck"][]=array();
17250
		#參考資料來源:
17251
		#array_keys=>http://php.net/manual/en/function.array-keys.php
17252
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
17253
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 17254
 
3 liveuser 17255
		#如果檢查參數失敗
17256
		if($checkArguments["status"]==="false"){
226 liveuser 17257
 
3 liveuser 17258
			#設置執行失敗
17259
			$result["status"]="false";
226 liveuser 17260
 
3 liveuser 17261
			#設置執行失敗訊息
17262
			$result["error"]=$checkArguments;
226 liveuser 17263
 
3 liveuser 17264
			#回傳結果
17265
			return $result;
226 liveuser 17266
 
3 liveuser 17267
			}#if end
226 liveuser 17268
 
3 liveuser 17269
		#如果檢查參數不通過
17270
		if($checkArguments["passed"]==="false"){
226 liveuser 17271
 
3 liveuser 17272
			#設置執行失敗
17273
			$result["status"]="false";
226 liveuser 17274
 
3 liveuser 17275
			#設置執行失敗訊息
17276
			$result["error"]=$checkArguments;
226 liveuser 17277
 
3 liveuser 17278
			#回傳結果
17279
			return $result;
226 liveuser 17280
 
3 liveuser 17281
			}#if end
226 liveuser 17282
 
3 liveuser 17283
		#函式說明:
17284
		#取得目錄底下所有目錄與檔案清單.
17285
		#回傳結果:
17286
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
17287
		#$result["error"],錯誤訊息陣列.
17288
		#$result["function"],函數名稱.
17289
		#$result["content"],陣列,目錄底下的檔案與子目錄.
17290
		#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
17291
		#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
17292
		#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
17293
		#$result["position"],目前的位置.
17294
		#必填參數:
17295
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
17296
		$conf["fileAccess::getList"]["position"]=$conf["linkToDir"];
17297
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17298
		$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
17299
		#可省略參數:
17300
		#無
17301
		#參考資料:
17302
		#opendir=>http://php.net/manual/en/function.opendir.php
17303
		#is_dir=>http://php.net/manual/en/function.is-dir.php
17304
		#備註:
17305
		#無.
17306
		$getList=fileAccess::getList($conf["fileAccess::getList"]);
17307
		unset($conf["fileAccess::getList"]);
226 liveuser 17308
 
3 liveuser 17309
		#如果檢查參數失敗
17310
		if($getList["status"]==="false"){
226 liveuser 17311
 
3 liveuser 17312
			#設置執行失敗
17313
			$result["status"]="false";
226 liveuser 17314
 
3 liveuser 17315
			#設置執行失敗訊息
17316
			$result["error"]=$getList;
226 liveuser 17317
 
3 liveuser 17318
			#回傳結果
17319
			return $result;
226 liveuser 17320
 
3 liveuser 17321
			}#if end
226 liveuser 17322
 
3 liveuser 17323
		#針對目標目錄底下的所有檔案
17324
		foreach($getList["content"] as $oriName){
226 liveuser 17325
 
3 liveuser 17326
			#如果有設定 $conf["name"]
17327
			if(isset($conf["name"])){
226 liveuser 17328
 
3 liveuser 17329
				#預設不指定新的軟連結名稱
17330
				unset($newSoftLinkName);
226 liveuser 17331
 
3 liveuser 17332
				#針對每個原始目標的名稱
17333
				foreach($conf["name"] as $customName){
226 liveuser 17334
 
3 liveuser 17335
					#如果是指定的目標
17336
					if($oriName["name"]===$customName[0]){
226 liveuser 17337
 
3 liveuser 17338
						#設置新的軟連結名稱
17339
						$newSoftLinkName=$customName[1];
226 liveuser 17340
 
3 liveuser 17341
						}#if end
226 liveuser 17342
 
3 liveuser 17343
					}#foreach end
226 liveuser 17344
 
3 liveuser 17345
				}#if end
226 liveuser 17346
 
3 liveuser 17347
			#建立軟連結
17348
			#函式說明:
17349
			#建立軟連結.
17350
			#回傳結果:
17351
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17352
			#$result["error"],錯誤訊息.
17353
			#$result["function"],當前執行的函數名稱.
17354
			#$result["content"],軟連結的資訊.
17355
			#必填參數:
17356
			#$conf["fileArgu"],字串,變數__FILE__的內容.
17357
			$conf["fileAccess::createLink"]["fileArgu"]=$conf["fileArgu"];
17358
			#$conf["linkTo"],字串,軟連結要指向哪邊.
17359
			$conf["fileAccess::createLink"]["linkTo"]=$conf["linkToDir"]."/".$oriName["name"];
17360
			#可省略參數:
17361
			#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
17362
			$conf["fileAccess::createLink"]["path"]=$conf["path"];
226 liveuser 17363
 
3 liveuser 17364
			#如果有新的軟連結名稱
17365
			if(isset($newSoftLinkName)){
226 liveuser 17366
 
3 liveuser 17367
				#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
17368
				$conf["fileAccess::createLink"]["name"]=$newSoftLinkName;
226 liveuser 17369
 
3 liveuser 17370
				}#if end
226 liveuser 17371
 
3 liveuser 17372
			#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
17373
			$conf["fileAccess::createLink"]["overWrite"]=$conf["overWrite"];
226 liveuser 17374
 
3 liveuser 17375
			#參考資料:
17376
			#無.
17377
			#備註:
17378
			#無.
17379
			$createLink=fileAccess::createLink($conf["fileAccess::createLink"]);
17380
			unset($conf["fileAccess::createLink"]);
226 liveuser 17381
 
3 liveuser 17382
			#var_dump(__LINE__." ".print_r($createLink,true));
226 liveuser 17383
 
3 liveuser 17384
			#如果檢查參數失敗
17385
			if($createLink["status"]==="false"){
226 liveuser 17386
 
3 liveuser 17387
				#設置執行失敗
17388
				$result["status"]="false";
226 liveuser 17389
 
3 liveuser 17390
				#設置執行失敗訊息
17391
				$result["error"]=$createLink;
226 liveuser 17392
 
3 liveuser 17393
				#回傳結果
17394
				return $result;
226 liveuser 17395
 
3 liveuser 17396
				}#if end
226 liveuser 17397
 
3 liveuser 17398
			#儲存建立好的軟連結資訊
17399
			$result["content"][]=$createLink["content"];
226 liveuser 17400
 
3 liveuser 17401
			}#foreach end
226 liveuser 17402
 
3 liveuser 17403
		#設置執行正常
17404
		$result["status"]="true";
226 liveuser 17405
 
3 liveuser 17406
		#回傳結果
17407
		return $result;
226 liveuser 17408
 
3 liveuser 17409
		}#function createMultiLink end
17410
 
17411
	/*
17412
	#函式說明:
17413
	#更新檔案的內容.
17414
	#回傳結果:
17415
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17416
	#$result["error"],錯誤訊息.
17417
	#$result["function"],當前執行的函數名稱.
220 liveuser 17418
	#$result["content"],更新的資訊.
17419
	#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
17420
	#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
3 liveuser 17421
	#必填參數:
17422
	#$conf["fileArgu"],字串,變數__FILE__的內容.
17423
	$conf["fileArgu"]=__FILE__;
17424
	#$conf["file"],字串,要更新的檔案位置與名稱.
17425
	$conf["file"]="";
17426
	#可省略參數:
17427
	#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
17428
	#$conf["overWriteWith"]=array();
17429
	#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
17430
	#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
17431
	#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
17432
	#$conf["replaceLike"]="false";
17433
	#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
17434
	#$conf["addToTailWhenNoMatch"]="false";
17435
	#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
17436
	#$conf["addToTailBeforeThat"]="?\>";
220 liveuser 17437
	#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
17438
	#$conf["replaceSpecifyLine"]=array();
17439
	#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
17440
	#$conf["outputPath"]="";
3 liveuser 17441
	#參考資料:
17442
	#無.
17443
	#備註:
17444
	#無.
17445
	*/
17446
	public static function updateFile(&$conf){
226 liveuser 17447
 
3 liveuser 17448
		#初始化要回傳的結果
17449
		$result=array();
17450
 
17451
		#取得當前執行的函數名稱
17452
		$result["function"]=__FUNCTION__;
17453
 
17454
		#如果沒有參數
17455
		if(func_num_args()==0){
226 liveuser 17456
 
3 liveuser 17457
			#設置執行失敗
17458
			$result["status"]="false";
226 liveuser 17459
 
3 liveuser 17460
			#設置執行錯誤訊息
17461
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 17462
 
3 liveuser 17463
			#回傳結果
17464
			return $result;
226 liveuser 17465
 
220 liveuser 17466
			}#if end
3 liveuser 17467
 
17468
		#取得參數
17469
		$result["argu"]=$conf;
17470
 
17471
		#如果 $conf 不為陣列
17472
		if(gettype($conf)!=="array"){
226 liveuser 17473
 
3 liveuser 17474
			#設置執行失敗
17475
			$result["status"]="false";
226 liveuser 17476
 
3 liveuser 17477
			#設置執行錯誤訊息
17478
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 17479
 
3 liveuser 17480
			#如果傳入的參數為 null
17481
			if($conf===null){
226 liveuser 17482
 
3 liveuser 17483
				#設置執行錯誤訊息
17484
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 17485
 
3 liveuser 17486
				}#if end
17487
 
17488
			#回傳結果
17489
			return $result;
226 liveuser 17490
 
3 liveuser 17491
			}#if end
226 liveuser 17492
 
3 liveuser 17493
		#檢查參數
17494
		#函式說明:
17495
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
17496
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17497
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
17498
		#$result["function"],當前執行的函式名稱.
17499
		#$result["argu"],設置給予的參數.
17500
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
17501
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
17502
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
17503
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
17504
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
17505
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
17506
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
17507
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
17508
		#必填寫的參數:
17509
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
220 liveuser 17510
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 17511
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
17512
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
17513
		#可以省略的參數:
17514
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
17515
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","file");
17516
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
17517
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
17518
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
17519
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
17520
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
17521
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
17522
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
17523
		#$conf["canBeEmpty"]=array();
17524
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
220 liveuser 17525
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("overWriteWith","replaceWith","addToTailWhenNoMatch","addToTailBeforeThat","replaceLike","replaceSpecifyLine","outputPath");
3 liveuser 17526
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
220 liveuser 17527
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("overWriteWith","replaceWith","addToTailWhenNoMatch","addToTailBeforeThat","replaceLike","replaceSpecifyLine","outputPath");
226 liveuser 17528
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
220 liveuser 17529
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","string","string","string","array","string");
3 liveuser 17530
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
220 liveuser 17531
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false",null,"false",null,null);
3 liveuser 17532
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
17533
		#$conf["disallowAllSkipableVarIsEmpty"]="";
17534
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
17535
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
17536
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
17537
		#$conf["arrayCountEqualCheck"][]=array();
17538
		#參考資料來源:
17539
		#array_keys=>http://php.net/manual/en/function.array-keys.php
17540
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
17541
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 17542
 
3 liveuser 17543
		#如果檢查參數失敗
17544
		if($checkArguments["status"]==="false"){
226 liveuser 17545
 
3 liveuser 17546
			#設置執行失敗
17547
			$result["status"]="false";
226 liveuser 17548
 
3 liveuser 17549
			#設置執行失敗訊息
17550
			$result["error"]=$checkArguments;
226 liveuser 17551
 
3 liveuser 17552
			#回傳結果
17553
			return $result;
226 liveuser 17554
 
3 liveuser 17555
			}#if end
226 liveuser 17556
 
3 liveuser 17557
		#如果檢查參數不通過
17558
		if($checkArguments["passed"]==="false"){
226 liveuser 17559
 
3 liveuser 17560
			#設置執行失敗
17561
			$result["status"]="false";
226 liveuser 17562
 
3 liveuser 17563
			#設置執行失敗訊息
17564
			$result["error"]=$checkArguments;
226 liveuser 17565
 
3 liveuser 17566
			#回傳結果
17567
			return $result;
226 liveuser 17568
 
3 liveuser 17569
			}#if end
226 liveuser 17570
 
3 liveuser 17571
		#檢查檔案是否存在
17572
		#函式說明:
17573
		#檢查多個檔案與資料夾是否存在.
17574
		#回傳的結果:
17575
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
17576
		#$result["error"],錯誤訊息陣列.
17577
		#$resutl["function"],當前執行的涵式名稱.
17578
		#$result["argu"],使用的參數.
17579
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
17580
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
17581
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
17582
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
17583
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
17584
		#必填參數:
17585
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
17586
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
17587
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17588
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
17589
		#可省略參數:
17590
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
17591
		$conf["disableWebSearch"]="true";
17592
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
17593
		$conf["userDir"]="false";
17594
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
17595
		$conf["web"]="false";
17596
		#參考資料:
17597
		#http://php.net/manual/en/function.file-exists.php
17598
		#http://php.net/manual/en/control-structures.foreach.php
17599
		#備註:
17600
		#函數file_exists檢查的路徑為檔案系統的路徑
17601
		#$result["varName"][$i]結果未實作
17602
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
17603
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 17604
 
3 liveuser 17605
		#如果檢查參數失敗
17606
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 17607
 
3 liveuser 17608
			#設置執行失敗
17609
			$result["status"]="false";
226 liveuser 17610
 
3 liveuser 17611
			#設置執行失敗訊息
17612
			$result["error"]=$checkMultiFileExist;
226 liveuser 17613
 
3 liveuser 17614
			#回傳結果
17615
			return $result;
226 liveuser 17616
 
3 liveuser 17617
			}#if end
226 liveuser 17618
 
3 liveuser 17619
		#如果目標檔案不存在
17620
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 17621
 
3 liveuser 17622
			#設置執行失敗
17623
			$result["status"]="false";
226 liveuser 17624
 
3 liveuser 17625
			#設置執行失敗訊息
17626
			$result["error"]=$checkMultiFileExist;
226 liveuser 17627
 
3 liveuser 17628
			#回傳結果
17629
			return $result;
226 liveuser 17630
 
3 liveuser 17631
			}#if end
226 liveuser 17632
 
220 liveuser 17633
		#預設要寫入的位置為原始檔案
17634
		$file2write=$conf["file"];
226 liveuser 17635
 
220 liveuser 17636
		#如果有設置 outputPath
17637
		if(isset($conf["outputPath"])){
226 liveuser 17638
 
220 liveuser 17639
			#寫入檔案的路徑與名稱
17640
			$file2write=$conf["outputPath"]."/".$conf["file"];
226 liveuser 17641
 
220 liveuser 17642
			}#if end
226 liveuser 17643
 
3 liveuser 17644
		#如果有設置 overWriteWith
17645
		if(isset($conf["overWriteWith"])){
226 liveuser 17646
 
3 liveuser 17647
			#函式說明:
17648
			#將多行字串寫入到檔案
17649
			#回傳結果:
17650
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
17651
			#$result["error"],錯誤訊息陣列.
17652
			#$result["function"],當前執行函數的名稱.
17653
			#必填參數:
17654
			#$conf["fileName"],字串,爲要編輯的檔案名稱
220 liveuser 17655
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
3 liveuser 17656
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
17657
			$conf["fileAccess::writeMultiLine"]["inputString"]=$conf["overWriteWith"];
17658
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17659
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
220 liveuser 17660
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
17661
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
3 liveuser 17662
			#可省略參數:
17663
			#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
17664
			#參考資料:
17665
			#無.
17666
			#備註:
17667
			#無.
17668
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
17669
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 17670
 
3 liveuser 17671
			#如果執行失敗
17672
			if($writeMultiLine["status"]==="false"){
226 liveuser 17673
 
3 liveuser 17674
				#設置執行失敗
17675
				$result["status"]="false";
226 liveuser 17676
 
3 liveuser 17677
				#設置執行失敗訊息
17678
				$result["error"]=$writeMultiLine;
226 liveuser 17679
 
3 liveuser 17680
				#回傳結果
17681
				return $result;
226 liveuser 17682
 
3 liveuser 17683
				}#if end
226 liveuser 17684
 
220 liveuser 17685
			#取得原始檔案的內容
17686
			#函式說明:
17687
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
17688
			#回傳的變數說明:
17689
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
17690
			#$result["error"],錯誤訊息提示.
17691
			#$result["warning"],警告訊息.
17692
			#$result["function"],當前執行的函數名稱.
17693
			#$result["fileContent"],爲檔案的內容陣列.
17694
			#$result["lineCount"],爲檔案內容總共的行數.
17695
			#$result["fullContent"],為檔案的完整內容.
17696
			#$result["base64data"],為檔案的base64內容.
17697
			#$result["mimeType"],為檔案的mime type.
17698
			#必填參數:
17699
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
17700
			$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
17701
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17702
			$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
17703
			#可省略參數:
17704
			#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
17705
			$conf["fileAccess::getFileContent"]["web"]="false";
17706
			#參考資料:
17707
			#file(),取得檔案內容的行數.
17708
			#file=>http:#php.net/manual/en/function.file.php
17709
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
17710
			#filesize=>http://php.net/manual/en/function.filesize.php
17711
			#參考資料:
17712
			#無.
17713
			#備註:
17714
			#無.
17715
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
17716
			unset($conf["fileAccess::getFileContent"]);
226 liveuser 17717
 
220 liveuser 17718
			#如果執行失敗
17719
			if($getFileContent["status"]==="false"){
226 liveuser 17720
 
220 liveuser 17721
				#設置執行失敗
17722
				$result["status"]="false";
226 liveuser 17723
 
220 liveuser 17724
				#設置執行失敗訊息
17725
				$result["error"]=$getFileContent;
226 liveuser 17726
 
220 liveuser 17727
				#回傳結果
17728
				return $result;
226 liveuser 17729
 
220 liveuser 17730
				}#if end
226 liveuser 17731
 
220 liveuser 17732
			#無窮迴圈
17733
			for($i=0;$i>=0;$i++){
226 liveuser 17734
 
220 liveuser 17735
				#如果有舊或新的行內容存在
17736
				if( isset($getFileContent["fileContent"][$i]) || isset($conf["overWriteWith"][$i]) ){
226 liveuser 17737
 
220 liveuser 17738
					#初始化暫存舊行內容的變數
17739
					$oriLine=null;
226 liveuser 17740
 
220 liveuser 17741
					#初始化暫存新行內容的變數
17742
					$newLine=null;
226 liveuser 17743
 
220 liveuser 17744
					#如果存在原行內容
17745
					if(isset($getFileContent["fileContent"][$i])){
226 liveuser 17746
 
220 liveuser 17747
						#儲存原行內容
17748
						$oriLine=$getFileContent["fileContent"][$i];
226 liveuser 17749
 
220 liveuser 17750
						}#if end
226 liveuser 17751
 
220 liveuser 17752
					#如果存在新行內容
17753
					if(isset($conf["overWriteWith"][$i])){
226 liveuser 17754
 
220 liveuser 17755
						#儲存新行內容
17756
						$newLine=$conf["overWriteWith"][$i];
226 liveuser 17757
 
220 liveuser 17758
						}#if end
226 liveuser 17759
 
220 liveuser 17760
					#設置更新的資訊
17761
					$result["content"][$i]=array("ori"=>$oriLine,"new"=>$newLine);
226 liveuser 17762
 
220 liveuser 17763
					}#if end
226 liveuser 17764
 
220 liveuser 17765
				#反之
17766
				else{
226 liveuser 17767
 
220 liveuser 17768
					#結束迴圈
17769
					break;
226 liveuser 17770
 
220 liveuser 17771
					}#else end
226 liveuser 17772
 
220 liveuser 17773
				}#for end
226 liveuser 17774
 
3 liveuser 17775
			}#if end
226 liveuser 17776
 
220 liveuser 17777
		#反之如果有設置 "replaceWith"
17778
		else if(isset($conf["replaceWith"])){
226 liveuser 17779
 
3 liveuser 17780
			#取得檔案的內容
17781
			#函式說明:
17782
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
17783
			#回傳的變數說明:
17784
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
17785
			#$result["error"],錯誤訊息提示.
17786
			#$result["warning"],警告訊息.
17787
			#$result["function"],當前執行的函數名稱.
17788
			#$result["fileContent"],爲檔案的內容陣列.
17789
			#$result["lineCount"],爲檔案內容總共的行數.
17790
			#$result["fullContent"],為檔案的完整內容.
17791
			#$result["base64data"],為檔案的base64內容.
17792
			#$result["mimeType"],為檔案的mime type.
17793
			#必填參數:
17794
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
17795
			$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
17796
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17797
			$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
17798
			#可省略參數:
17799
			#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
17800
			$conf["fileAccess::getFileContent"]["web"]="false";
17801
			#參考資料:
17802
			#file(),取得檔案內容的行數.
17803
			#file=>http:#php.net/manual/en/function.file.php
17804
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
17805
			#filesize=>http://php.net/manual/en/function.filesize.php
17806
			#參考資料:
17807
			#無.
17808
			#備註:
17809
			#無.
17810
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
17811
			unset($conf["fileAccess::getFileContent"]);
226 liveuser 17812
 
3 liveuser 17813
			#如果執行失敗
17814
			if($getFileContent["status"]==="false"){
226 liveuser 17815
 
3 liveuser 17816
				#設置執行失敗
17817
				$result["status"]="false";
226 liveuser 17818
 
3 liveuser 17819
				#設置執行失敗訊息
17820
				$result["error"]=$getFileContent;
226 liveuser 17821
 
3 liveuser 17822
				#回傳結果
17823
				return $result;
226 liveuser 17824
 
3 liveuser 17825
				}#if end
226 liveuser 17826
 
3 liveuser 17827
			#取得原始檔案的每行內容
17828
			$oriFileContentByLine=&$getFileContent["fileContent"];
226 liveuser 17829
 
3 liveuser 17830
			#針對每個 replaceWith 條件
17831
			foreach($conf["replaceWith"] as $replaceInfo){
226 liveuser 17832
 
3 liveuser 17833
				#預設尚未找到符合的關鍵字
17834
				$foundKeyWord=false;
226 liveuser 17835
 
3 liveuser 17836
				#取得要替換的目標字串
17837
				$oriStr=$replaceInfo[0];
226 liveuser 17838
 
3 liveuser 17839
				#取得要替換成的字串內容
17840
				$newStr=$replaceInfo[1];
226 liveuser 17841
 
3 liveuser 17842
				#針對每行原始內容
17843
				foreach($oriFileContentByLine as $index => $line){
226 liveuser 17844
 
3 liveuser 17845
					#函式說明:
17846
					#檢查字串裡面有無指定的關鍵字
17847
					#回傳結果:
17848
					#$result["status"],"true"代表執行成功,"false"代表執行失敗。
17849
					#$result["error"],錯誤訊息
17850
					#$result["function"],當前執行的函數名稱.
17851
					#$result["argu"],使用的參數.
17852
					#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
17853
					#$result["keyWordCount"],找到的關鍵字數量.
17854
					#必填參數:
17855
					#$conf["keyWord"],字串,想要搜尋的關鍵字.
17856
					$conf["search::findKeyWord"]["keyWord"]=$oriStr;
17857
					#$conf["string"],字串,要被搜尋的字串內容
17858
					$conf["search::findKeyWord"]["string"]=$line;
17859
					#可省略參數:
226 liveuser 17860
 
3 liveuser 17861
					#如果要完全符合關鍵字
17862
					if($conf["replaceLike"]==="false"){
226 liveuser 17863
 
3 liveuser 17864
						#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
17865
						$conf["search::findKeyWord"]["completeEqual"]="true";
226 liveuser 17866
 
3 liveuser 17867
						}#if end
226 liveuser 17868
 
3 liveuser 17869
					#參考資料:
17870
					#無.
17871
					#備註:
17872
					#無.
17873
					$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
17874
					unset($conf["search::findKeyWord"]);
226 liveuser 17875
 
3 liveuser 17876
					#如果執行失敗
17877
					if($findKeyWord["status"]==="false"){
226 liveuser 17878
 
3 liveuser 17879
						#設置執行失敗
17880
						$result["status"]="false";
226 liveuser 17881
 
3 liveuser 17882
						#設置執行失敗訊息
17883
						$result["error"]=$findKeyWord;
226 liveuser 17884
 
3 liveuser 17885
						#回傳結果
17886
						return $result;
226 liveuser 17887
 
3 liveuser 17888
						}#if end
226 liveuser 17889
 
3 liveuser 17890
					#如果有找到關鍵字
17891
					if($findKeyWord["founded"]==="true"){
226 liveuser 17892
 
220 liveuser 17893
						#設置更新的資訊
17894
						$result["content"][$lineIndex]=array("ori"=>$oriFileContentByLine[$index],"new"=>$newStr);
226 liveuser 17895
 
3 liveuser 17896
						#更新該行內容
17897
						$oriFileContentByLine[$index]=$newStr;
226 liveuser 17898
 
3 liveuser 17899
						#設置有找到符合的關鍵字
17900
						$foundKeyWord=true;
226 liveuser 17901
 
3 liveuser 17902
						}#if end
226 liveuser 17903
 
3 liveuser 17904
					}#foreach end
226 liveuser 17905
 
3 liveuser 17906
				#如果沒有找到關鍵字
17907
				if($foundKeyWord===false){
226 liveuser 17908
 
3 liveuser 17909
					#如果要新增內容
17910
					if($conf["addToTailWhenNoMatch"]==="true"){
226 liveuser 17911
 
3 liveuser 17912
						#如果有設置 addToTailBeforeThat
17913
						if(isset($conf["addToTailBeforeThat"])){
226 liveuser 17914
 
3 liveuser 17915
							#預設沒有找到符合的關鍵字
17916
							$foundKeyWord=false;
226 liveuser 17917
 
3 liveuser 17918
							#初始化要記錄要 append 回去的各行內容.
17919
							$linesToAppend=array();
226 liveuser 17920
 
3 liveuser 17921
							#倒敘,針對每行內容
17922
							for($i=count($oriFileContentByLine)-1;$i>=0;$i--){
226 liveuser 17923
 
3 liveuser 17924
								#儲存要 append 回去的行內容
17925
								$linesToAppend[]=$oriFileContentByLine[$i];
226 liveuser 17926
 
3 liveuser 17927
								#如果找到關鍵字了
17928
								if($oriFileContentByLine[$i]===$conf["addToTailBeforeThat"]){
226 liveuser 17929
 
3 liveuser 17930
									#設置有找到符合的關鍵字
17931
									$foundKeyWord=true;
226 liveuser 17932
 
220 liveuser 17933
									#設置更新的資訊
17934
									$result["content"][$lineIndex]=array("ori"=>$oriFileContentByLine[$i],"new"=>$line);
226 liveuser 17935
 
3 liveuser 17936
									#更新該行內容
17937
									$oriFileContentByLine[$i]=$line;
226 liveuser 17938
 
3 liveuser 17939
									#倒敘陣列
17940
									$linesToAppend=array_reverse($linesToAppend);
226 liveuser 17941
 
3 liveuser 17942
									#針對每行要 append 回去的內容
17943
									foreach($linesToAppend as $lineToAppend){
226 liveuser 17944
 
3 liveuser 17945
										#append 行內容
17946
										$oriFileContentByLine[]=$lineToAppend;
226 liveuser 17947
 
220 liveuser 17948
										#設置更新的資訊
17949
										$result["content"][count($oriFileContentByLine)-1]=array("ori"=>null,"new"=>$lineToAppend);
226 liveuser 17950
 
3 liveuser 17951
										}#foreach end
226 liveuser 17952
 
3 liveuser 17953
									}#if end
226 liveuser 17954
 
3 liveuser 17955
								}#for end
226 liveuser 17956
 
3 liveuser 17957
							#如果沒有找到關鍵字
17958
							if($foundKeyWord===false){
226 liveuser 17959
 
3 liveuser 17960
								#設置執行失敗
17961
								$result["status"]="false";
226 liveuser 17962
 
3 liveuser 17963
								#設置錯誤訊息
17964
								$result["error"]="can't find \"".$conf["addToTailBeforeThat"]."\" to insert before it.";
226 liveuser 17965
 
3 liveuser 17966
								#回傳結果
17967
								return $result;
226 liveuser 17968
 
3 liveuser 17969
								}#if end
226 liveuser 17970
 
3 liveuser 17971
							}#if end
226 liveuser 17972
 
3 liveuser 17973
						}#if end
226 liveuser 17974
 
3 liveuser 17975
					}#if end
226 liveuser 17976
 
3 liveuser 17977
				}#foreach end
226 liveuser 17978
 
3 liveuser 17979
			#函式說明:
17980
			#將多行字串寫入到檔案
17981
			#回傳結果:
17982
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
17983
			#$result["error"],錯誤訊息陣列.
17984
			#$result["function"],當前執行函數的名稱.
17985
			#必填參數:
17986
			#$conf["fileName"],字串,爲要編輯的檔案名稱
220 liveuser 17987
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
3 liveuser 17988
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
17989
			$conf["fileAccess::writeMultiLine"]["inputString"]=$oriFileContentByLine;
17990
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17991
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
17992
			#可省略參數:
17993
			#$conf["fileAccess::writeMultiLine"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
220 liveuser 17994
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
17995
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
3 liveuser 17996
			#參考資料:
17997
			#無.
17998
			#備註:
17999
			#無.
18000
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
18001
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 18002
 
3 liveuser 18003
			#如果執行失敗
18004
			if($writeMultiLine["status"]==="false"){
226 liveuser 18005
 
3 liveuser 18006
				#設置執行失敗
18007
				$result["status"]="false";
226 liveuser 18008
 
3 liveuser 18009
				#設置執行失敗訊息
18010
				$result["error"]=$writeMultiLine;
226 liveuser 18011
 
3 liveuser 18012
				#回傳結果
18013
				return $result;
226 liveuser 18014
 
3 liveuser 18015
				}#if end
226 liveuser 18016
 
3 liveuser 18017
			}#if end
226 liveuser 18018
 
220 liveuser 18019
		#反之如果有設置 replaceSpecifyLine
18020
		else if(isset($conf["replaceSpecifyLine"])){
226 liveuser 18021
 
220 liveuser 18022
			#讀取原始檔案內容
18023
			#函式說明:
18024
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
18025
			#回傳的變數說明:
18026
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
18027
			#$result["error"],錯誤訊息提示.
18028
			#$result["warning"],警告訊息.
18029
			#$result["function"],當前執行的函數名稱.
18030
			#$result["fileContent"],爲檔案的內容陣列.
18031
			#$result["lineCount"],爲檔案內容總共的行數.
18032
			#$result["fullContent"],為檔案的完整內容.
18033
			#$result["base64dataOnly"],檔案的base64data.
18034
			#$result["base64data"],為在網頁上給予src參數的數值.
18035
			#$result["mimeType"],為檔案的mime type.
18036
			#必填參數:
18037
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
18038
			$conf["fileAcceess::getFileContent"]["filePositionAndName"]=$conf["file"];
18039
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18040
			$conf["fileAcceess::getFileContent"]["fileArgu"]=__FILE__;
18041
			#可省略參數:
18042
			#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
18043
			#$conf["web"]="true";
18044
			#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
18045
			#$conf["createIfnotExist"]="false";
18046
			#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
18047
			#$conf["autoDeleteSpaceOnEachLineStart"]="false";
18048
			#參考資料:
18049
			#file(),取得檔案內容的行數.
18050
			#file=>http:#php.net/manual/en/function.file.php
18051
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
18052
			#filesize=>http://php.net/manual/en/function.filesize.php
18053
			#參考資料:
18054
			#無.
18055
			#備註:
18056
			#無.
18057
			$getFileContent=fileAccess::getFileContent($conf["fileAcceess::getFileContent"]);
18058
			unset($conf["fileAcceess::getFileContent"]);
226 liveuser 18059
 
220 liveuser 18060
			#如果執行失敗
18061
			if($getFileContent["status"]==="false"){
226 liveuser 18062
 
220 liveuser 18063
				#設置執行失敗
18064
				$result["status"]="false";
226 liveuser 18065
 
220 liveuser 18066
				#設置執行失敗訊息
18067
				$result["error"]=$getFileContent;
226 liveuser 18068
 
220 liveuser 18069
				#回傳結果
18070
				return $result;
226 liveuser 18071
 
220 liveuser 18072
				}#if end
226 liveuser 18073
 
220 liveuser 18074
			#針對每個要更新的行
18075
			foreach($conf["replaceSpecifyLine"] as $lineIndex => $newLineContent){
226 liveuser 18076
 
220 liveuser 18077
				#設置更新的資訊
18078
				$result["content"][$lineIndex]=array("ori"=>$getFileContent["fileContent"][$lineIndex],"new"=>$newLineContent);
226 liveuser 18079
 
220 liveuser 18080
				#更新行內容
18081
				$getFileContent["fileContent"][$lineIndex]=$newLineContent;
226 liveuser 18082
 
220 liveuser 18083
				}#foreach end
226 liveuser 18084
 
220 liveuser 18085
			#debug
18086
			#var_dump(__FILE__,__LINE__,count($getFileContent["fileContent"]));
226 liveuser 18087
 
220 liveuser 18088
			#將變更寫入到檔案裡面
18089
			#函式說明:
18090
			#將多行字串寫入到檔案
18091
			#回傳結果:
18092
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
18093
			#$result["error"],錯誤訊息陣列.
18094
			#$result["function"],當前執行函數的名稱.
18095
			#必填參數:
18096
			#$conf["fileName"],字串,爲要編輯的檔案名稱
18097
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
18098
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
18099
			$conf["fileAccess::writeMultiLine"]["inputString"]=$getFileContent["fileContent"];
18100
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18101
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=__FILE__;
18102
			#可省略參數:
18103
			$conf["fileAccess::writeMultiLine"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
18104
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
18105
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
18106
			#參考資料:
18107
			#無.
18108
			#備註:
18109
			#無.
18110
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
18111
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 18112
 
220 liveuser 18113
			#如果執行失敗
18114
			if($writeMultiLine["status"]==="false"){
226 liveuser 18115
 
220 liveuser 18116
				#設置執行失敗
18117
				$result["status"]="false";
226 liveuser 18118
 
220 liveuser 18119
				#設置執行失敗訊息
18120
				$result["error"]=$writeMultiLine;
226 liveuser 18121
 
220 liveuser 18122
				#回傳結果
18123
				return $result;
226 liveuser 18124
 
220 liveuser 18125
				}#if end
226 liveuser 18126
 
220 liveuser 18127
			#debug
18128
			#var_dump(__FILE__,__LINE__,$writeMultiLine);exit(1);
226 liveuser 18129
 
220 liveuser 18130
			}#if end
226 liveuser 18131
 
3 liveuser 18132
		#設置執行正常
18133
		$result["status"]="true";
226 liveuser 18134
 
3 liveuser 18135
		#回傳結果
18136
		return $result;
226 liveuser 18137
 
3 liveuser 18138
		}#function updateFile end
226 liveuser 18139
 
3 liveuser 18140
	/*
18141
	#函式說明:
18142
	#輔助使用PHP內建的chmod函式.
18143
	#回傳結果:
18144
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18145
	#$result["error"],錯誤訊息.
18146
	#$result["function"],當前執行的函式名稱.
18147
	#$result["argu"],使用的參數.
18148
	#$result["cmd"],執行的指令.
18149
	#$result["content"],執行的結果陣列,如果參數 "recursive" 跟 "excludeSelf" 都有設定的話,就會回傳該結果.
18150
	#必填參數:
18151
	#$conf["mode"],字串,要變成什麼權限.
18152
	$conf["mode"]="";
18153
	#$conf["target"],字串,需要變更權限的目標.
18154
	$conf["target"]="";
18155
	#可省略參數:
18156
	#無.
18157
	#參考資料:
18158
	#無.
18159
	#備註:
18160
	#無.
18161
	*/
18162
	public static function chmod(&$conf){
226 liveuser 18163
 
3 liveuser 18164
		#初始化要回傳的結果
18165
		$result=array();
18166
 
18167
		#取得當前執行的函數名稱
18168
		$result["function"]=__FUNCTION__;
18169
 
18170
		#如果沒有參數
18171
		if(func_num_args()==0){
18172
 
18173
			#設置執行失敗
18174
			$result["status"]="false";
18175
 
18176
			#設置執行錯誤訊息
18177
			$result["error"]="函數".$result["function"]."需要參數";
18178
 
18179
			#回傳結果
18180
			return $result;
18181
 
18182
			}#if end
18183
 
18184
		#取得參數
18185
		$result["argu"]=$conf;
18186
 
18187
		#如果 $conf 不為陣列
18188
		if(gettype($conf)!=="array"){
18189
 
18190
			#設置執行失敗
18191
			$result["status"]="false";
18192
 
18193
			#設置執行錯誤訊息
18194
			$result["error"][]="\$conf變數須為陣列形態";
18195
 
18196
			#如果傳入的參數為 null
18197
			if(is_null($conf)){
18198
 
18199
				#設置執行錯誤訊息
18200
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
18201
 
18202
				}#if end
18203
 
18204
			#回傳結果
18205
			return $result;
18206
 
18207
			}#if end
226 liveuser 18208
 
3 liveuser 18209
		#函式說明:
18210
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
18211
		#回傳結果:
18212
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18213
		#$result["error"],執行不正常結束的錯訊息陣列.
18214
		#$result["simpleError"],簡單表示的錯誤訊息.
18215
		#$result["function"],當前執行的函式名稱.
18216
		#$result["argu"],設置給予的參數.
18217
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
18218
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
18219
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
18220
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
18221
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
18222
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
18223
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
18224
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
18225
		#必填參數:
18226
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
18227
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
18228
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
18229
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
18230
		#可省略參數:
18231
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
18232
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mode","target");
18233
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
18234
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
18235
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
18236
		#$conf["canBeEmptyString"]="false";
18237
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
18238
		#$conf["canNotBeEmpty"]=array();
18239
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
18240
		#$conf["canBeEmpty"]=array();
18241
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
18242
		#$conf["skipableVariableCanNotBeEmpty"]=array();
18243
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
18244
		#$conf["skipableVariableName"]=array();
18245
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
18246
		#$conf["skipableVariableType"]=array();
18247
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
18248
		#$conf["skipableVarDefaultValue"]=array("");
18249
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
18250
		#$conf["disallowAllSkipableVarIsEmpty"]="";
18251
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
18252
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
18253
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
18254
		#$conf["arrayCountEqualCheck"][]=array();
18255
		#參考資料:
18256
		#array_keys=>http://php.net/manual/en/function.array-keys.php
18257
		#備註:
18258
		#無.
18259
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
18260
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 18261
 
3 liveuser 18262
		#如果檢查參數失敗
18263
		if($checkArguments["status"]==="false"){
226 liveuser 18264
 
3 liveuser 18265
			#設置執行失敗
18266
			$result["status"]="false";
18267
 
18268
			#設置錯誤資訊
18269
			$result["error"]=$checkArguments;
226 liveuser 18270
 
3 liveuser 18271
			#回傳結果
18272
			return $result;
226 liveuser 18273
 
3 liveuser 18274
			}#if end
226 liveuser 18275
 
3 liveuser 18276
		#如果檢查參數不通過
18277
		if($checkArguments["passed"]==="false"){
226 liveuser 18278
 
3 liveuser 18279
			#設置執行失敗
18280
			$result["status"]="false";
18281
 
18282
			#設置錯誤資訊
18283
			$result["error"]=$checkArguments;
226 liveuser 18284
 
3 liveuser 18285
			#回傳結果
18286
			return $result;
226 liveuser 18287
 
3 liveuser 18288
			}#if end
226 liveuser 18289
 
3 liveuser 18290
		#將$conf["mode"]轉換為10進位的整數
18291
		$conf["mode"]=(int)base_convert($conf["mode"],8,10);
226 liveuser 18292
 
3 liveuser 18293
		#變更 target 的檔案權限為代碼
226 liveuser 18294
		$chmod=chmod($conf["target"],$conf["mode"]);
18295
 
3 liveuser 18296
		#如果改變檔案權限失敗
18297
		if($chmod===false){
226 liveuser 18298
 
3 liveuser 18299
			#設置執行失敗
18300
			$result["status"]="false";
226 liveuser 18301
 
3 liveuser 18302
			#設置錯誤訊息
18303
			$result["error"][]="改變 ".$conf["target"]." 檔案的權限資訊為 ".$conf["mode"]." 失敗,通常只有系統帳戶才能變更之.";
226 liveuser 18304
 
3 liveuser 18305
			#回傳結果
226 liveuser 18306
			return $result;
18307
 
3 liveuser 18308
			}#if end
226 liveuser 18309
 
3 liveuser 18310
		#設置執行正常
18311
		$result["status"]="true";
226 liveuser 18312
 
3 liveuser 18313
		#回傳結果
18314
		return $result;
226 liveuser 18315
 
3 liveuser 18316
		}#function chmod end
18317
 
18318
	}#class fileAccess end
18319
 
226 liveuser 18320
?>