Subversion Repositories php-qbpwcf

Rev

Rev 350 | Rev 376 | 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
		#設置預設檔案不存在的識別
1201
		$result["fileNotExist"]="false";
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
 
374 liveuser 1360
			#設置檔案不存在的識別
1361
			$result["fileNotExist"]="false";
1362
 
3 liveuser 1363
			#如果也不要自動建立檔案
1364
			if($conf["createIfnotExist"]==="false"){
226 liveuser 1365
 
3 liveuser 1366
				#設置執行錯誤識別
1367
				$result["status"]="false";
226 liveuser 1368
 
3 liveuser 1369
				#設置執行錯誤訊息
1370
				$result["error"]=$fileCheckResult;
226 liveuser 1371
 
3 liveuser 1372
				#設置易讀的錯誤訊息
1373
				$result["error"][]="名為".$fileCheckResult["varName"][0]."的檔案不存在";
226 liveuser 1374
 
3 liveuser 1375
				#回傳結果
1376
				return $result;
226 liveuser 1377
 
3 liveuser 1378
				}#if end
226 liveuser 1379
 
3 liveuser 1380
			#執行到這邊代表需要建立該檔案
1381
			#函式說明:
1382
			#將字串寫入到檔案
1383
			#回傳結果:
1384
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1385
			#$result["error"],錯誤訊息陣列.
1386
			#$result["function"],當前執行的函數名稱.
1387
			#$result["fileInfo"],實際上寫入的檔案資訊陣列.
1388
			#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
1389
			#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
1390
			#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
1391
			#$result["argu"],使用的參數.
1392
			#必填參數:
1393
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1394
			$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1395
			#可省略參數:
1396
			#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
1397
			$conf["fileAccess::writeTextIntoFile"]["fileName"]=$fileCheckResult["varNameFullPath"][0];
1398
			#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
200 liveuser 1399
			$conf["fileAccess::writeTextIntoFile"]["inputString"]="";
3 liveuser 1400
			#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
1401
			#$conf["checkRepeat"]="";
1402
			#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
1403
			#$conf["filenameExtensionStartPoint"]="";
1404
			#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
1405
			#$conf["repeatNameRule"]="";
226 liveuser 1406
 
3 liveuser 1407
			#如果有設置 $conf["web"]
1408
			if(isset($conf["web"])){
226 liveuser 1409
 
3 liveuser 1410
				#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1411
				$conf["fileAccess::writeTextIntoFile"]["web"]=$conf["web"];
226 liveuser 1412
 
200 liveuser 1413
				}#if end
226 liveuser 1414
 
3 liveuser 1415
			#參考資料:
1416
			#無.
1417
			#備註:
1418
			#無.
1419
			$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
1420
			unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 1421
 
3 liveuser 1422
			#如果建立檔案失敗
1423
			if($writeTextIntoFile["status"]=="false"){
226 liveuser 1424
 
3 liveuser 1425
				#設置執行錯誤識別
1426
				$result["status"]="false";
226 liveuser 1427
 
3 liveuser 1428
				#設置執行錯誤訊息
1429
				$result["error"]=$writeTextIntoFile;
226 liveuser 1430
 
3 liveuser 1431
				#回傳結果
1432
				return $result;
226 liveuser 1433
 
3 liveuser 1434
				}#if end
374 liveuser 1435
 
1436
			#設置檔案存在的識別
1437
			$result["fileNotExist"]="true";
1438
 
1439
			#設置檔案為本函式所建立
1440
			$result["fileCreated"]="true";
226 liveuser 1441
 
3 liveuser 1442
			}#if end
374 liveuser 1443
 
1444
		#反之
1445
		else{
1446
 
1447
			#設置檔案存在的識別
1448
			$result["fileNotExist"]="true";
1449
 
1450
			}#else end
3 liveuser 1451
 
1452
		#file absolute addr
1453
		$fileAbAddr=$fileCheckResult["varNameFullPath"][0];
226 liveuser 1454
 
3 liveuser 1455
		#將檔案的內容放進變數裡面(會得到陣列)
1456
		$fileContent=file($fileAbAddr);
1457
 
1458
		#如果 $fileContent 等於
1459
		if($fileContent==FALSE){
1460
 
1461
			#如果檔案大小為0bytes
1462
			if(filesize($fileAbAddr)==0){
226 liveuser 1463
 
3 liveuser 1464
				#設置錯誤識別
1465
				$result["warning"][]="執行結果沒有輸出內容";
1466
 
1467
				}#if end
226 liveuser 1468
 
3 liveuser 1469
			#反之檔案有內容
1470
			else{
1471
 
1472
				#設置錯誤識別
1473
				$result["status"]="false";
1474
 
1475
				#設置錯誤訊息
1476
				$result["error"][]="讀取檔案失敗";
1477
 
42 liveuser 1478
				#取得詳細的錯誤訊息
1479
				$result["error"][]=$fileCheckResult;
226 liveuser 1480
 
3 liveuser 1481
				#回傳結果
1482
				return $result;
226 liveuser 1483
 
3 liveuser 1484
				}#else end
1485
 
1486
			}#if end
1487
 
1488
		#針對每行內容
1489
		for($i=0;$i<count($fileContent);$i++){
226 liveuser 1490
 
3 liveuser 1491
			#剔除字串尾的換行符號
1492
			$fileContent[$i]=rtrim($fileContent[$i]);
226 liveuser 1493
 
3 liveuser 1494
			#如果要移除開頭的空白
1495
			if($conf["autoDeleteSpaceOnEachLineStart"]==="true"){
226 liveuser 1496
 
3 liveuser 1497
				#如果開頭是空格
1498
				while(strpos($fileContent[$i]," ")===0){
226 liveuser 1499
 
3 liveuser 1500
					#函式說明:
1501
					#將字串特定關鍵字與其前面的內容剔除
1502
					#回傳結果:
1503
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1504
					#$result["error"],錯誤訊息陣列.
1505
					#$result["warning"],警告訊息鎮列.
1506
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
1507
					#$result["function"],當前執行的函數名稱.
1508
					#$result["argu"],使用的參數.
1509
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 1510
					#$result["content"],處理好的的字串內容.
3 liveuser 1511
					#必填參數:
1512
					#$conf["stringIn"],字串,要處理的字串.
1513
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$fileContent[$i];
1514
					#$conf["keyWord"],字串,特定字串.
1515
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
1516
					#可省略參數:
1517
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
1518
					#$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
1519
					#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
1520
					#$conf["lastResult"]=$delStrBeforeKeyWord;
1521
					#參考資料:
1522
					#無.
1523
					#備註:
1524
					#無.
1525
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
1526
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 1527
 
3 liveuser 1528
					#如果建立檔案失敗
1529
					if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 1530
 
3 liveuser 1531
						#設置執行錯誤識別
1532
						$result["status"]="false";
226 liveuser 1533
 
3 liveuser 1534
						#設置執行錯誤訊息
1535
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 1536
 
3 liveuser 1537
						#回傳結果
1538
						return $result;
226 liveuser 1539
 
3 liveuser 1540
						}#if end
226 liveuser 1541
 
3 liveuser 1542
					#取得剔除開頭空格後的內容
1543
					$fileContent[$i]=$delStrBeforeKeyWord["content"];
226 liveuser 1544
 
3 liveuser 1545
					}#while end
226 liveuser 1546
 
3 liveuser 1547
				}#if end
226 liveuser 1548
 
3 liveuser 1549
			}#for end
1550
 
1551
		#取得總共有幾行
1552
		$lineCount=count($fileContent);
1553
 
1554
		#將檔案內容的陣列放進 $result 陣列變數裏面
1555
		$result["fileContent"]=$fileContent;
226 liveuser 1556
 
3 liveuser 1557
		#建立暫存檔案
1558
		$tmpFile=tempnam("/tmp", "qbpwcf");
226 liveuser 1559
 
3 liveuser 1560
		#讀取要取得的檔案內容
1561
		$content=file_get_contents($fileAbAddr);
226 liveuser 1562
 
3 liveuser 1563
		#開啟暫存檔案(寫入模式)
1564
		$file=fopen($tmpFile,'w');
226 liveuser 1565
 
3 liveuser 1566
		#寫入讀取到的內容
1567
		fwrite($file,$content);
226 liveuser 1568
 
3 liveuser 1569
		#關閉暫存檔案
1570
		fclose($file);
226 liveuser 1571
 
3 liveuser 1572
		#取得檔案的 mime 類型
1573
		$mimeType=mime_content_type($tmpFile);
226 liveuser 1574
 
3 liveuser 1575
		#設置檔案的mime類型
1576
		$result["mimeType"]=$mimeType;
226 liveuser 1577
 
3 liveuser 1578
		#取得檔案的內容為字串
1579
		$result["fullContent"]=file_get_contents($tmpFile);
226 liveuser 1580
 
3 liveuser 1581
		#取得檔案的base64data
200 liveuser 1582
		$result["base64dataOnly"]=base64_encode($result["fullContent"]);
226 liveuser 1583
 
200 liveuser 1584
		#取得檔案用 data:mimeType;base64,base64data 表示的字串
203 liveuser 1585
		$result["base64data"]="data:".$result["mimeType"].";base64,".$result["base64dataOnly"];
226 liveuser 1586
 
3 liveuser 1587
		#移除暫存檔案
1588
		unlink($tmpFile);
226 liveuser 1589
 
3 liveuser 1590
		#將檔案內容的行數放進 $result 陣列變數裏面
1591
		$result["lineCount"]=$lineCount;
1592
 
1593
		#執行到這邊代表執行成功
1594
		$result["status"]="true";
1595
 
1596
		#回傳結果
1597
		return $result;
1598
 
1599
		}#function getFileContent end
1600
 
1601
	/*
1602
	#函式說明:
1603
	#依據逗號分隔抓取檔案的內容,結果會回傳一個陣列
226 liveuser 1604
	#回傳結果:
3 liveuser 1605
	#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1606
	#$result["error"],錯誤訊息提示.
1607
	#$result["function"],函數名稱.
1608
	#$result["lineCount"]爲總共有幾行
1609
	#$result["lineContent"][i]["dataCounts"],爲第 i+1 行總共有幾個字串
1610
	#$result["lineContent"][0][i],爲第1行第 i+1 個分割好的字串
1611
	#$result["lineContent"][1][i],爲第2行第 i+1 個分割好的字串
1612
	#必填參數:
1613
	#$conf["filePositionAndName"],字串,要抓取的檔案位置與名稱
1614
	$conf["filePositionAndName"]="";
1615
	#可省略參數:
1616
	#$conf["spiltSign"],字串,爲要用來分割字串的符號,可省略,預設爲「,」
1617
	#$conf["spiltSign"]="";
1618
	#參考資料:
1619
	#無.
1620
	#備註:
1621
	#無.
1622
	*/
249 liveuser 1623
	public static function getFileContentSpiltBySomething(&$conf){
3 liveuser 1624
 
1625
		#初始化要回傳的內容
1626
		$result=array();
226 liveuser 1627
 
3 liveuser 1628
		#取得當前執行函數名稱
1629
		$result["function"]=__FUNCTION__;
1630
 
1631
		#如果 $conf 不為陣列
1632
		if(gettype($conf)!="array"){
226 liveuser 1633
 
3 liveuser 1634
			#設置執行失敗
1635
			$result["status"]="false";
226 liveuser 1636
 
3 liveuser 1637
			#設置執行錯誤訊息
1638
			$result["error"][]="\$conf變數須為陣列形態";
1639
 
1640
			#如果傳入的參數為 null
1641
			if($conf==null){
226 liveuser 1642
 
3 liveuser 1643
				#設置執行錯誤訊息
1644
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1645
 
3 liveuser 1646
				}#if end
1647
 
1648
			#回傳結果
1649
			return $result;
226 liveuser 1650
 
3 liveuser 1651
			}#if end
1652
 
1653
		#如果 $conf["spiltSign"] 爲空,則預設爲","。
1654
		if(!isset($conf["spiltSign"])){
1655
 
1656
			$conf["spiltSign"]=",";
1657
 
1658
			}#if end
1659
 
1660
		#依據行號抓取所有的內容
1661
		#函式說明:
1662
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1663
		#回傳的變數說明:
1664
		#$result["fileContent"],爲檔案的內容陣列
1665
		#$result["lineCount"],爲檔案內容總共的行數
1666
		#必填參數:
1667
		$conf["fileAccess"]["getFileContent"]["filePositionAndName"]=$conf["filePositionAndName"];#爲檔案的位置以及名稱
1668
		#參考資料:
1669
		#file():取得檔案內容的行數
1670
		#http:#php.net/manual/en/function.file.php
1671
		$fileContent=fileAccess::getFileContent($conf["fileAccess"]["getFileContent"]);
1672
		unset($conf["fileAccess"]["getFileContent"]);
1673
 
1674
		#如果取得檔案內容失敗
1675
		if($fileContent["status"]=="false"){
226 liveuser 1676
 
3 liveuser 1677
			#設置執行失敗
1678
			$result["status"]="false";
226 liveuser 1679
 
3 liveuser 1680
			#設置執行錯誤訊息
1681
			$result["error"]=$fileContent;
1682
 
1683
			#回傳結果
1684
			return $result;
226 liveuser 1685
 
3 liveuser 1686
			}#if end
1687
 
1688
		#迴圈,有幾行資料就執行幾次
1689
		for($i=0;$i<$fileContent["lineCount"];$i++){
1690
 
1691
			#將該行內容用逗號分隔
1692
			$conf["stringProcess"]["spiltString"]["stringIn"]=$fileContent["fileContent"][$i];#要處理的字串。
1693
			$conf["stringProcess"]["spiltString"]["spiltSymbol"]=$conf["spiltSign"];#爲以哪個符號作爲分割
1694
			$lineSpiltResult[$i]=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
226 liveuser 1695
			unset($conf["stringProcess"]["spiltString"]);
3 liveuser 1696
 
1697
			#如果分割字串失敗
1698
			if($lineSpiltResult[$i]["status"]=="false"){
226 liveuser 1699
 
3 liveuser 1700
				#設置執行失敗
1701
				$result["status"]="false";
226 liveuser 1702
 
3 liveuser 1703
				#設置執行錯誤訊息
1704
				$result["error"]=$lineSpiltResult[$i];
1705
 
1706
				#回傳結果
1707
				return $result;
226 liveuser 1708
 
3 liveuser 1709
				}#if end
1710
 
1711
			}#for end
1712
 
1713
		#取得
1714
		$result["lineContent"]=$lineSpiltResult;
1715
 
1716
		#取得資料的行數
1717
		$result["lineCount"]=$fileContent["lineCount"];
1718
 
1719
		#回傳結果
1720
		return $result;
226 liveuser 1721
 
3 liveuser 1722
		}#function getFileContentSpiltBySomething end
1723
 
1724
	/*
1725
	#函式說明:
1726
	#檢查多個檔案與資料夾是否存在.
1727
	#回傳的結果:
1728
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1729
	#$result["error"],錯誤訊息陣列.
1730
	#$resutl["function"],當前執行的涵式名稱.
1731
	#$result["argu"],使用的參數.
1732
	#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1733
	#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
1734
	#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
1735
	#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
1736
	#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1737
	#必填參數:
1738
	#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
1739
	$conf["fileArray"]=array();
1740
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1741
	$conf["fileArgu"]=__FILE__;
1742
	#可省略參數:
1743
	#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1744
	#$conf["disableWebSearch"]="false";
1745
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
1746
	#$conf["userDir"]="true";
1747
	#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
1748
	#$conf["web"]="true";
1749
	#參考資料:
1750
	#http://php.net/manual/en/function.file-exists.php
1751
	#http://php.net/manual/en/control-structures.foreach.php
1752
	#備註:
1753
	#函數file_exists檢查的路徑為檔案系統的路徑
1754
	#$result["varName"][$i]結果未實作
1755
	*/
1756
	public static function checkMultiFileExist(&$conf){
226 liveuser 1757
 
3 liveuser 1758
		#初始化要回傳的變數
1759
		$result=array();
226 liveuser 1760
 
3 liveuser 1761
		#設置當前執行的涵式
1762
		$result["function"]=__FUNCTION__;
226 liveuser 1763
 
3 liveuser 1764
		#如果 $conf 不為陣列
1765
		if(gettype($conf)!="array"){
226 liveuser 1766
 
3 liveuser 1767
			#設置執行失敗
1768
			$result["status"]="false";
226 liveuser 1769
 
3 liveuser 1770
			#設置執行錯誤訊息
1771
			$result["error"][]="\$conf變數須為陣列形態";
1772
 
1773
			#如果傳入的參數為 null
1774
			if($conf==null){
226 liveuser 1775
 
3 liveuser 1776
				#設置執行錯誤訊息
1777
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1778
 
3 liveuser 1779
				}#if end
1780
 
1781
			#回傳結果
1782
			return $result;
226 liveuser 1783
 
3 liveuser 1784
			}#if end
226 liveuser 1785
 
3 liveuser 1786
		#取得使用的參數
1787
		$result["argu"]=$conf;
226 liveuser 1788
 
3 liveuser 1789
		#檢查參數
1790
		#函式說明:
1791
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1792
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1793
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1794
		#$result["function"],當前執行的函式名稱.
1795
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1796
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1797
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1798
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
1799
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1800
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1801
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1802
		#必填寫的參數:
1803
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1804
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1805
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1806
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArray","fileArgu");
226 liveuser 1807
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 1808
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
1809
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1810
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1811
		#可以省略的參數:
1812
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1813
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1814
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1815
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("disableWebSearch","userDir","web");
226 liveuser 1816
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 1817
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1818
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1819
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true","true","true");
1820
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1821
		#$conf["arrayCountEqualCheck"][]=array();
1822
		#參考資料來源:
1823
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1824
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1825
		unset($conf["variableCheck::checkArguments"]);
1826
 
1827
		#如果 $checkArguments["status"] 等於 "false"
1828
		if($checkArguments["status"]=="false"){
226 liveuser 1829
 
3 liveuser 1830
			#設置錯誤識別
1831
			$result["status"]="false";
226 liveuser 1832
 
3 liveuser 1833
			#設置錯誤訊息
1834
			$result["error"]=$checkArguments;
226 liveuser 1835
 
3 liveuser 1836
			#回傳結果
42 liveuser 1837
			return $result;
226 liveuser 1838
 
3 liveuser 1839
			}#if end
226 liveuser 1840
 
3 liveuser 1841
		#如果 $checkArguments["passed"] 等於 "false"
1842
		if($checkArguments["passed"]=="false"){
226 liveuser 1843
 
3 liveuser 1844
			#設置錯誤識別
1845
			$result["status"]="false";
226 liveuser 1846
 
3 liveuser 1847
			#設置錯誤訊息
1848
			$result["error"]=$checkArguments;
226 liveuser 1849
 
3 liveuser 1850
			#回傳結果
42 liveuser 1851
			return $result;
226 liveuser 1852
 
3 liveuser 1853
			}#if end
226 liveuser 1854
 
3 liveuser 1855
		#初始化儲存每個檔案是否存在的陣列變數
1856
		$result["varName"]=array();
1857
		$result["varExist"]=array();
1858
 
1859
		#針對每個要檢查的檔案
1860
		foreach($conf["fileArray"] as $i=>$varName){
226 liveuser 1861
 
3 liveuser 1862
			#儲存要判斷是否存在的物件
1863
			$result["varName"][]=$varName;
226 liveuser 1864
 
3 liveuser 1865
			#函式說明:
1866
			#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
1867
			#回傳結果:
1868
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1869
			#$result["error"],錯誤訊息陣列.
226 liveuser 1870
			#$result["function"],函數名稱.
3 liveuser 1871
			#$result["argu"],使用的參數.
1872
			#$result["content"],網址,若是在命令列執行,則為"null".
1873
			#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
1874
			#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
1875
			#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
1876
			#必填參數:
1877
			#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
1878
			$conf["fileAccess::getInternetAddressV2"]["address"]=$varName;
1879
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1880
			$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
1881
			#可省略參數:
1882
			$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
1883
			#備註:
1884
			#建構中,fileSystemRelativePosition尚未實作.
1885
			$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
1886
			unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 1887
 
3 liveuser 1888
			#如果轉換成絕對路徑失敗
1889
			if($getInternetAddressV2["status"]=="false"){
226 liveuser 1890
 
3 liveuser 1891
				#設置錯誤識別
1892
				$result["status"]="false";
226 liveuser 1893
 
3 liveuser 1894
				#設置錯誤訊息
1895
				$result["error"]=$getInternetAddressV2;
226 liveuser 1896
 
3 liveuser 1897
				#回傳結果
1898
				return $result;
226 liveuser 1899
 
3 liveuser 1900
				}#if end
226 liveuser 1901
 
3 liveuser 1902
			#傳參考
1903
			$getInternetAddress=&$getInternetAddressV2;
226 liveuser 1904
 
3 liveuser 1905
			#如果沒有檔案的絕對路徑位置
1906
			if(!isset($getInternetAddress["fileSystemAbsoulutePosition"])){
226 liveuser 1907
 
3 liveuser 1908
				#置換成給予的參數網址
1909
				$conf["fileArray"][$i]=$getInternetAddress["content"];
226 liveuser 1910
 
3 liveuser 1911
				#設置無法從檔案系統找到
1912
				$exist=FALSE;
226 liveuser 1913
 
3 liveuser 1914
				}#if end
226 liveuser 1915
 
3 liveuser 1916
			#反之取得
1917
			else{
226 liveuser 1918
 
3 liveuser 1919
				#轉換好的絕對路徑
1920
				$conf["fileArray"][$i]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 1921
 
42 liveuser 1922
				#無窮迴圈
1923
				while(true){
226 liveuser 1924
 
42 liveuser 1925
					#判斷該檔案是否存在
1926
					$exist=file_exists($conf["fileArray"][$i]);
226 liveuser 1927
 
42 liveuser 1928
					#如果不存在
1929
					if($exist===false){
226 liveuser 1930
 
42 liveuser 1931
						#無窮迴圈
1932
						while(true){
226 liveuser 1933
 
42 liveuser 1934
							#當要檢查的目標是 link 時
1935
							if(is_link($conf["fileArray"][$i])){
226 liveuser 1936
 
42 liveuser 1937
								#取得link的路徑
1938
								$conf["fileArray"][$i]=readlink($conf["fileArray"][$i]);
226 liveuser 1939
 
42 liveuser 1940
								#結束連結的判斷,回到判斷目標是否存在的地方.
1941
								continue 2;
226 liveuser 1942
 
42 liveuser 1943
								}#if end
226 liveuser 1944
 
42 liveuser 1945
							#結束連結的判斷
1946
							break;
226 liveuser 1947
 
42 liveuser 1948
							}#while end
226 liveuser 1949
 
42 liveuser 1950
						}#if end
226 liveuser 1951
 
42 liveuser 1952
					#結束到判斷目標是否存在
1953
					break;
226 liveuser 1954
 
42 liveuser 1955
					}#while end
226 liveuser 1956
 
3 liveuser 1957
				}#else end
226 liveuser 1958
 
3 liveuser 1959
			#如果 $exist 等於 false (檔案不存在) 且 沒有停用網路搜尋功能
1960
			if($exist===FALSE && $conf["disableWebSearch"]==="false"){
1961
 
1962
				#將目標轉換成網址
1963
				#函式說明:
1964
				#將檔案的位置名稱變成網址
1965
				#回傳結果:
1966
				#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1967
				#$result["error"],錯誤訊息陣列.
226 liveuser 1968
				#$result["function"],函數名稱.
3 liveuser 1969
				#$result["content"],網址.
1970
				#必填參數:
1971
				#$conf["address"],字串,檔案的相對位置.
1972
				$conf["fileAccess::getInternetAddress"]["address"]=$conf["fileArray"][$i];
1973
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1974
				$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
1975
				$getInternetAddress=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddress"]);
1976
				unset($conf["fileAccess::getInternetAddress"]);
1977
 
1978
				#如果轉換失敗
1979
				if($getInternetAddress["status"]=="false"){
226 liveuser 1980
 
3 liveuser 1981
					#設置錯誤識別
1982
					$result["status"]="false";
226 liveuser 1983
 
3 liveuser 1984
					#設置錯誤訊息
1985
					$result["error"]=$getInternetAddress;
226 liveuser 1986
 
3 liveuser 1987
					#回傳結果
226 liveuser 1988
					return $result;
1989
 
3 liveuser 1990
					}#if end
226 liveuser 1991
 
3 liveuser 1992
				#函式說明:
1993
				#運行curl cmd
1994
				#回傳結果:
1995
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1996
				#$result["error"],錯誤訊息陣列.
1997
				#$result["function"],當前執行的函式名稱.
1998
				#$result["content"],取得的回應內容.
1999
				#$result["cookie"],cookie檔案的位置與名稱.
2000
				#$result["cmd"],執行的command.
2001
				#$result["argu],使用的參數.
2002
				#必填參數:
2003
				#$conf["url"],字串,目標url.
2004
				$conf["catchWebContent::curlCmd"]["url"]=$getInternetAddress["content"];
2005
				#$conf["fileArgu"],字串,變數__FILE__的內容.
2006
				$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
2007
				#可省略參數:
2008
				#$conf["header"],字串陣列,要傳送的header.
2009
				#$conf["header"]=array();
2010
				#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
2011
				#$conf["allowAnySSLcertificate"]="";
2012
				#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
2013
				#$conf["postVar"]=array();
2014
				#$conf["rawPost"]="字串",要傳送的raw post內容.
2015
				#$conf["rawPost"]="";
2016
				#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
2017
				#$conf["urlEncode"]="false";
2018
				#$conf["agent"],字串,user agent的名稱.
2019
				#$conf["agent"]="";
2020
				#$conf["cookie"],字串,cookie位置與檔案位置.
2021
				#$conf["cookie"]="";
2022
				#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
2023
				#$conf["forceNewCookie"]="";
2024
				$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
2025
				unset($conf["catchWebContent::curlCmd"]);
226 liveuser 2026
 
3 liveuser 2027
				#如果抓取資料失敗
2028
				if($curlCmd["status"]==="false"){
226 liveuser 2029
 
3 liveuser 2030
					#設置錯誤識別
2031
					$result["status"]="false";
226 liveuser 2032
 
3 liveuser 2033
					#設置錯誤訊息
2034
					$result["error"]=$curlCmd;
226 liveuser 2035
 
3 liveuser 2036
					#回傳結果
2037
					return $result;
226 liveuser 2038
 
3 liveuser 2039
					}#if end
226 liveuser 2040
 
3 liveuser 2041
				#反之檔案存在網路上
2042
				else{
226 liveuser 2043
 
3 liveuser 2044
					#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2045
					$result["varName"][$i]=$getInternetAddress["content"];
226 liveuser 2046
 
3 liveuser 2047
					#如果存在檔案路徑的絕對位置
2048
					if(isset($getInternetAddress["fileSystemAbsoulutePosition"])){
226 liveuser 2049
 
42 liveuser 2050
						#設置該檔案的絕對路徑位置
3 liveuser 2051
						$result["varNameFullPath"][$i]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 2052
 
3 liveuser 2053
						}#if end
226 liveuser 2054
 
2055
					#反之代表輸入參數是網址
3 liveuser 2056
					else{
226 liveuser 2057
 
3 liveuser 2058
						#設置該檔案的網址
2059
						$result["varNameWebPath"][$i]=$getInternetAddress["content"];
226 liveuser 2060
 
3 liveuser 2061
						}#else end
226 liveuser 2062
 
3 liveuser 2063
					#設置有無找到的識別
2064
					$result["varExist"][$i]=$curlCmd["founded"];
226 liveuser 2065
 
3 liveuser 2066
					}#else end
226 liveuser 2067
 
3 liveuser 2068
				}#if end
2069
 
2070
			#反之檔案不存在,且停用網路搜尋.
2071
			else if($exist===FALSE){
226 liveuser 2072
 
3 liveuser 2073
				#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2074
				$result["varName"][$i]=$conf["fileArray"][$i];
2075
				$result["varNameFullPath"][$i]=$conf["fileArray"][$i];
2076
				$result["varExist"][$i]="false";
2077
 
2078
				#設置全部檔案都存在的識別變數為 "false"
2079
				$result["allExist"]="false";
226 liveuser 2080
 
3 liveuser 2081
				}#if end
2082
 
2083
			#反之代表檔案存在
2084
			else{
226 liveuser 2085
 
3 liveuser 2086
				#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2087
				$result["varNameFullPath"][$i]=$conf["fileArray"][$i];
226 liveuser 2088
 
3 liveuser 2089
				#如果 web 參數為 "true"
2090
				if($conf["web"]==="true"){
226 liveuser 2091
 
3 liveuser 2092
					#設置網路上的位置
2093
					$result["varNameWebPath"][$i]=$getInternetAddress["content"];
226 liveuser 2094
 
3 liveuser 2095
					}#if end
226 liveuser 2096
 
3 liveuser 2097
				$result["varExist"][$i]="true";
2098
 
2099
				}#else end
226 liveuser 2100
 
3 liveuser 2101
			}#foreach end
226 liveuser 2102
 
3 liveuser 2103
		#如果所有檔案與資料夾都找到的識別變數不存在
2104
		if(!isset($result["allExist"])){
226 liveuser 2105
 
3 liveuser 2106
			#設置全部檔案與資料夾都有找到
2107
			$result["allExist"]="true";
226 liveuser 2108
 
3 liveuser 2109
			}#if end
2110
 
2111
		#執行到這邊代表執行正常
2112
		$result["status"]="true";
2113
 
2114
		#回傳結果
2115
		return $result;
2116
 
2117
		}#function checkMutiFileExist
2118
 
2119
	/*
2120
	#函式說明:
2121
	#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
2122
	#回傳結果:
2123
	#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
2124
	#$result["error"],錯誤訊息陣列.
2125
	#$result["function"],當前執行的函數名稱.
2126
	#$result["argu"],使用的參數.
2127
	#$result["createdFileName"],建立好的檔案名稱.
2128
	#$result["createdFilePath"],檔案建立的路徑.
2129
	#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
2130
	#必填參數:
2131
	#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
2132
	$conf["checkedFileAndPath"]="";
2133
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2134
	$conf["fileArgu"]=__FILE__;
2135
	#可省略參數:
2136
	#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點.
2137
	#$conf["filenameExtensionStartPoint"]="";
2138
	#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)".
2139
	#$conf["repeatNameRule"]="";
2140
	#$conf["web"],"true"代表為網頁系統,"false"代表檔案系統,預設為"false".
2141
	#$conf["web"]="false";
2142
	#參考資料:
2143
	#無.
2144
	#備註:
2145
	#如果要在/tmp底下建立檔案,若在apache環境下則會被作業系統特殊處理,即不等於實際上的路徑.
2146
	*/
2147
	public static function createFileAfterCheck(&$conf){
226 liveuser 2148
 
3 liveuser 2149
		#初始化要回傳的結果
2150
		$result=array();
226 liveuser 2151
 
3 liveuser 2152
		#設置當前執行的涵式
2153
		$result["function"]=__FUNCTION__;
226 liveuser 2154
 
3 liveuser 2155
		#如果 $conf 不為陣列
2156
		if(gettype($conf)!="array"){
226 liveuser 2157
 
3 liveuser 2158
			#設置執行失敗
2159
			$result["status"]="false";
226 liveuser 2160
 
3 liveuser 2161
			#設置執行錯誤訊息
2162
			$result["error"][]="\$conf變數須為陣列形態";
2163
 
2164
			#如果傳入的參數為 null
2165
			if($conf==null){
226 liveuser 2166
 
3 liveuser 2167
				#設置執行錯誤訊息
2168
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 2169
 
3 liveuser 2170
				}#if end
2171
 
2172
			#回傳結果
2173
			return $result;
226 liveuser 2174
 
3 liveuser 2175
			}#if end
226 liveuser 2176
 
3 liveuser 2177
		#取得參數
2178
		$result["argu"]=$conf;
226 liveuser 2179
 
3 liveuser 2180
		#檢查參數
2181
		#函式說明:
2182
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2183
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2184
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2185
		#$result["function"],當前執行的函式名稱.
2186
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2187
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2188
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2189
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2190
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2191
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2192
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2193
		#必填寫的參數:
2194
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2195
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2196
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2197
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","checkedFileAndPath");
226 liveuser 2198
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 2199
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
2200
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2201
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2202
		#可以省略的參數:
2203
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2204
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2205
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2206
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("filenameExtensionStartPoint","repeatNameRule","web");
226 liveuser 2207
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 2208
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
2209
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2210
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("1","(\$i)","false");
2211
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2212
		#$conf["arrayCountEqualCheck"][]=array();
2213
		#參考資料來源:
2214
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2215
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2216
		unset($conf["variableCheck::checkArguments"]);
2217
 
2218
		#如果 $checkArguments["status"] 等於 "false"
2219
		if($checkArguments["status"]=="false"){
226 liveuser 2220
 
3 liveuser 2221
			#設置錯誤識別
2222
			$result["status"]="false";
226 liveuser 2223
 
3 liveuser 2224
			#設置錯誤訊息
2225
			$result["error"]=$checkArguments;
226 liveuser 2226
 
3 liveuser 2227
			#回傳結果
226 liveuser 2228
			return $result;
2229
 
3 liveuser 2230
			}#if end
226 liveuser 2231
 
3 liveuser 2232
		#如果 $checkArguments["passed"] 等於 "false"
2233
		if($checkArguments["passed"]=="false"){
226 liveuser 2234
 
3 liveuser 2235
			#設置錯誤識別
2236
			$result["status"]="false";
226 liveuser 2237
 
3 liveuser 2238
			#設置錯誤訊息
2239
			$result["error"]=$checkArguments;
226 liveuser 2240
 
3 liveuser 2241
			#回傳結果
226 liveuser 2242
			return $result;
2243
 
2244
			}#if end
2245
 
3 liveuser 2246
		#確保要建立檔案的路徑
2247
		#函式說明:
2248
		#確保路徑存在.
2249
		#回傳結果:
2250
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
2251
		#$result["error"],錯誤訊息陣列.
2252
		#$resutl["function"],當前執行的涵式名稱.
2253
		#$result["path"],建立好的路徑字串.
2254
		#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
2255
		#必填參數:
2256
		#$conf["path"],要檢查的路徑
226 liveuser 2257
		$conf["fileAccess::validatePath"]["path"]=$conf["checkedFileAndPath"];
3 liveuser 2258
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2259
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
2260
		#可省略參數:
2261
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
2262
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
2263
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
2264
		#$conf["dirPermission"]="";
2265
		$conf["fileAccess::validatePath"]["web"]=$conf["web"];
2266
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
226 liveuser 2267
		unset($conf["fileAccess::validatePath"]);
2268
 
3 liveuser 2269
		#debug
2270
		#var_dump($validatePath);
226 liveuser 2271
		#exit;
2272
 
3 liveuser 2273
		#如果確保路徑失敗
2274
		if($validatePath["status"]==="false"){
226 liveuser 2275
 
3 liveuser 2276
			#設置錯誤識別
2277
			$result["status"]="false";
226 liveuser 2278
 
3 liveuser 2279
			#設置錯誤訊息
2280
			$result["error"]=$validatePath;
226 liveuser 2281
 
3 liveuser 2282
			#回傳結果
2283
			return $result;
226 liveuser 2284
 
3 liveuser 2285
			}#if end
226 liveuser 2286
 
3 liveuser 2287
		#取得要建立的檔案名稱
2288
		$createdFileName=$validatePath["fileName"];
226 liveuser 2289
 
2290
		#取得要建立的路徑
3 liveuser 2291
		$createdFilePath=$validatePath["path"];
226 liveuser 2292
 
3 liveuser 2293
		#透過無窮迴圈嘗試建立不同編號的檔案
2294
		for($i=0;$i>-1;$i++){
226 liveuser 2295
 
3 liveuser 2296
			#如果 $i 為 0
2297
			if($i==0){
226 liveuser 2298
 
3 liveuser 2299
				#檢查該檔案是否存在
2300
				#函式說明:
2301
				#檢查多個檔案與資料夾是否存在.
2302
				#回傳的結果:
2303
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
2304
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2305
				#必填參數:
2306
				$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($createdFilePath."/".$createdFileName);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
2307
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2308
				$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
2309
				#參考資料來源:
2310
				#http://php.net/manual/en/function.file-exists.php
2311
				#http://php.net/manual/en/control-structures.foreach.php
2312
				$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
2313
				$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
2314
				unset($conf["fileAccess"]["checkMutiFileExist"]);
226 liveuser 2315
 
3 liveuser 2316
				#debug
2317
				#var_dump($checkResult);
2318
				#exit;
226 liveuser 2319
 
3 liveuser 2320
				#如果檢查檔案是否存在失敗
2321
				if($checkResult["status"]=="false"){
226 liveuser 2322
 
3 liveuser 2323
					#設置執行失敗
2324
					$result["status"]="false";
226 liveuser 2325
 
3 liveuser 2326
					#設置錯誤訊息
2327
					$result["error"]=$checkResult;
226 liveuser 2328
 
3 liveuser 2329
					#回傳結果
2330
					return $result;
226 liveuser 2331
 
3 liveuser 2332
					}#if end
226 liveuser 2333
 
3 liveuser 2334
				#如果 $createFilePath.$createdFileName 檔案存在
2335
				if($checkResult["varExist"][0]=="true"){
226 liveuser 2336
 
3 liveuser 2337
					#跳過這次迴圈
2338
					continue;
226 liveuser 2339
 
3 liveuser 2340
					}#if end
226 liveuser 2341
 
3 liveuser 2342
				#反之代表 $createFilePath.$createdFileName 檔案不存在
2343
				else{
226 liveuser 2344
 
3 liveuser 2345
					#嘗試建立該檔案
2346
					#函式說明:
2347
					#將字串寫入到檔案
2348
					#回傳結果:
2349
					#$result["status"],true表示檔案寫入成功,false表示檔案寫入失敗.
2350
					#$result["error"],錯誤訊息陣列.
2351
					#必填參數:
2352
					$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$createdFilePath."/".$createdFileName;#爲要編輯的檔案名稱
2353
					$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
2354
					$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
2355
					#可省略參數:
2356
					$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
2357
					$conf["fileAccess"]["writeTextIntoFile"]["web"]=$conf["web"];
2358
					$fileCreateResult=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
2359
					unset($conf["fileAccess"]["writeTextIntoFile"]);
226 liveuser 2360
 
3 liveuser 2361
					#如果 $fileCreateResult["status"] 等於 "true"
2362
					if($fileCreateResult["status"]=="true"){
226 liveuser 2363
 
3 liveuser 2364
						#代表檔案建立成功
226 liveuser 2365
 
3 liveuser 2366
						#更新建立的檔案名稱
2367
						$result["createdFileName"]=$createdFileName;
226 liveuser 2368
 
3 liveuser 2369
						#設置新建立的檔案名稱與路徑
2370
						$result["createdFilePathAndName"]=$createdFilePath."/".$result["createdFileName"];
226 liveuser 2371
 
3 liveuser 2372
						#設置新建立的檔與路徑
2373
						$result["createdFilePath"]=$createdFilePath;
226 liveuser 2374
 
3 liveuser 2375
						#跳出迴圈
2376
						break;
226 liveuser 2377
 
3 liveuser 2378
						}#if end
226 liveuser 2379
 
3 liveuser 2380
					#反之代表檔案建立失敗
2381
					else{
226 liveuser 2382
 
3 liveuser 2383
						#設置錯誤識別
2384
						$result["status"]="false";
226 liveuser 2385
 
3 liveuser 2386
						#設置錯誤訊息
2387
						$result["error"]=$fileCreateResult;
226 liveuser 2388
 
3 liveuser 2389
						#回傳結果
2390
						return $result;
226 liveuser 2391
 
3 liveuser 2392
						}#else end
226 liveuser 2393
 
2394
					}#else end
2395
 
3 liveuser 2396
				}#if end
226 liveuser 2397
 
3 liveuser 2398
			#反之代表有相同檔名存在
226 liveuser 2399
			else{
2400
 
3 liveuser 2401
				#用「.」分割檔案名稱
2402
				#函式說明:
2403
				#將固定格式的字串分開,並回傳分開的結果。
2404
				#回傳結果:
2405
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2406
				#$result["error"],錯誤訊息陣列
2407
				#$result["function"],當前執行的函數名稱.
2408
				#$result["oriStr"],要分割的原始字串內容
2409
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2410
				#$result["dataCounts"],爲總共分成幾段
2411
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
2412
				#必填參數:
2413
				$conf["stringProcess::spiltString"]["stringIn"]=$createdFileName;#要處理的字串。
2414
				$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
2415
				#可省略參數:
2416
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2417
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2418
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2419
				unset($conf["stringProcess::spiltString"]);
2420
 
3 liveuser 2421
				#如果分割檔案名稱失敗
2422
				if($spiltString["status"]=="false"){
226 liveuser 2423
 
3 liveuser 2424
					#設置執行失敗
2425
					$result["status"]="false";
226 liveuser 2426
 
3 liveuser 2427
					#設置錯誤訊息
2428
					$result["error"]=$spiltString;
226 liveuser 2429
 
3 liveuser 2430
					#回傳結果
2431
					return $result;
226 liveuser 2432
 
3 liveuser 2433
					}#if end
226 liveuser 2434
 
3 liveuser 2435
				#初始化儲存建立的檔案名稱
2436
				$createdFileName="";
226 liveuser 2437
 
3 liveuser 2438
				#初始化儲存編號的變數
2439
				$no="";
226 liveuser 2440
 
3 liveuser 2441
				#如果沒有dot存在
2442
				if($spiltString["found"]=="false"){
226 liveuser 2443
 
3 liveuser 2444
					#解析 $conf["repeatNameRule"],用 \$i 分割.
2445
					#函式說明:
2446
					#將固定格式的字串分開,並回傳分開的結果。
2447
					#回傳結果:
2448
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2449
					#$result["error"],錯誤訊息陣列
2450
					#$result["function"],當前執行的函數名稱.
2451
					#$result["oriStr"],要分割的原始字串內容
2452
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2453
					#$result["dataCounts"],爲總共分成幾段
2454
					#必填參數:
2455
					$conf["stringProcess::spiltString"]["stringIn"]=$conf["repeatNameRule"];#要處理的字串。
2456
					$conf["stringProcess::spiltString"]["spiltSymbol"]="\$i";#爲以哪個符號作爲分割
2457
					#可省略參數:
2458
					#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2459
					$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2460
					$noString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2461
					unset($conf["stringProcess::spiltString"]);
2462
 
3 liveuser 2463
					#如果分割檔案名稱失敗
2464
					if($noString["status"]=="false"){
226 liveuser 2465
 
3 liveuser 2466
						#設置執行失敗
2467
						$result["status"]="false";
226 liveuser 2468
 
3 liveuser 2469
						#設置錯誤訊息
2470
						$result["error"]=$noString;
226 liveuser 2471
 
3 liveuser 2472
						#回傳結果
2473
						return $result;
226 liveuser 2474
 
3 liveuser 2475
						}#if end
226 liveuser 2476
 
3 liveuser 2477
					#如果 編號規則字串 分割出來的段數為2
2478
					if($noString["dataCounts"]==2){
226 liveuser 2479
 
3 liveuser 2480
						#組合編號
2481
						$no=$noString["dataArray"][0].$i.$noString["dataArray"][1];
226 liveuser 2482
 
3 liveuser 2483
						}#if end
226 liveuser 2484
 
3 liveuser 2485
					#反之 號規則字串 分割出來的段數為1
2486
					else if($noString["dataCounts"]==1){
226 liveuser 2487
 
3 liveuser 2488
						#判斷 "\$i" 在開頭或結尾
2489
						#函式說明:
2490
						#取得關鍵字在字串的哪個位置
2491
						#回傳結果:
2492
						#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
2493
						#$result["error"],錯誤訊息陣列.
2494
						#$result["function"],當前執行的函數名稱.
2495
						#$result["argu"],傳入的參數.
2496
						#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
2497
						#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
2498
						#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
2499
						#必填參數:
2500
						#$conf["inputStr"],字串,被搜尋的字串.
2501
						$conf["search::findKeyWordPosition"]["inputStr"]=$conf["repeatNameRule"];
2502
						#$conf["keyWord"],字串,關鍵字.
2503
						$conf["search::findKeyWordPosition"]["keyWord"]="\$i";
2504
						#參考資料:
2505
						#http://php.net/manual/en/function.strpos.php
2506
						$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
2507
						unset($conf["search::findKeyWordPosition"]);
226 liveuser 2508
 
3 liveuser 2509
						#如果取得關鍵字位置失敗
2510
						if($findKeyWordPosition["status"]=="false"){
226 liveuser 2511
 
3 liveuser 2512
							#設置執行失敗
2513
							$result["status"]="false";
226 liveuser 2514
 
3 liveuser 2515
							#設置錯誤訊息
2516
							$result["error"]=$findKeyWordPosition;
226 liveuser 2517
 
3 liveuser 2518
							#回傳結果
2519
							return $result;
226 liveuser 2520
 
3 liveuser 2521
							}#if end
226 liveuser 2522
 
3 liveuser 2523
						#如果關鍵字在開頭
2524
						if($findKeyWordPosition["head"]=="true"){
226 liveuser 2525
 
3 liveuser 2526
							#組合編號
2527
							$no=$i.$noString["dataArray"][0];
226 liveuser 2528
 
3 liveuser 2529
							}#if end
226 liveuser 2530
 
3 liveuser 2531
						#反之如果關鍵字在結尾
2532
						else if($findKeyWordPosition["tail"]=="true"){
226 liveuser 2533
 
3 liveuser 2534
							#組合編號
2535
							$no=$noString["dataArray"][0].$i;
226 liveuser 2536
 
3 liveuser 2537
							}#if end
226 liveuser 2538
 
3 liveuser 2539
						#其他情況
2540
						else{
226 liveuser 2541
 
3 liveuser 2542
							#設置執行失敗
2543
							$result["status"]="false";
226 liveuser 2544
 
3 liveuser 2545
							#設置錯誤訊息
2546
							$result["error"]=$findKeyWordPosition;
226 liveuser 2547
 
3 liveuser 2548
							#設置額外的錯誤訊息
2549
							$result["error"][]="非預期的結果";
226 liveuser 2550
 
3 liveuser 2551
							#回傳結果
2552
							return $result;
226 liveuser 2553
 
3 liveuser 2554
							}#else end
226 liveuser 2555
 
3 liveuser 2556
						}#if end
226 liveuser 2557
 
3 liveuser 2558
					#反之 編號規則字串 分割出來的段數為0
2559
					else if($noString["dataCounts"]==0){
226 liveuser 2560
 
3 liveuser 2561
						#組合編號
2562
						$no=$j;
226 liveuser 2563
 
3 liveuser 2564
						}#if end
226 liveuser 2565
 
3 liveuser 2566
					#其他結果
2567
					else{
226 liveuser 2568
 
3 liveuser 2569
						#設置執行失敗
2570
						$result["status"]="false";
226 liveuser 2571
 
3 liveuser 2572
						#設置錯誤訊息
2573
						$result["error"]=$noString;
226 liveuser 2574
 
3 liveuser 2575
						#設置額外的錯誤訊息
2576
						$result["error"][]="非預期的結果";
226 liveuser 2577
 
3 liveuser 2578
						#回傳結果
2579
						return $result;
226 liveuser 2580
 
2581
						}#else end
2582
 
3 liveuser 2583
					#串接編號到檔案名稱上
2584
					$createdFileName=$validatePath["fileName"].$no;
226 liveuser 2585
 
3 liveuser 2586
					}#if end
226 liveuser 2587
 
2588
				#反之有dot存在
3 liveuser 2589
				else{
226 liveuser 2590
 
3 liveuser 2591
					#依據 $spiltString["dataCounts"] 值來組裝新的檔案名稱
2592
					for($j=0;$j<$spiltString["dataCounts"];$j++){
226 liveuser 2593
 
3 liveuser 2594
						#如果是副檔名的前一段內容
2595
						if(($conf["filenameExtensionStartPoint"]+1)==($spiltString["dataCounts"]-$j)){
226 liveuser 2596
 
3 liveuser 2597
							#解析 $conf["repeatNameRule"],用 \$i 分割.
2598
							#函式說明:
2599
							#將固定格式的字串分開,並回傳分開的結果。
2600
							#回傳結果:
2601
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2602
							#$result["error"],錯誤訊息陣列
2603
							#$result["function"],當前執行的函數名稱.
2604
							#$result["oriStr"],要分割的原始字串內容
2605
							#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2606
							#$result["dataCounts"],爲總共分成幾段
2607
							#必填參數:
2608
							$conf["stringProcess::spiltString"]["stringIn"]=$conf["repeatNameRule"];#要處理的字串。
2609
							$conf["stringProcess::spiltString"]["spiltSymbol"]="\$i";#爲以哪個符號作爲分割
2610
							#可省略參數:
2611
							#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2612
							$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2613
							$noString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2614
							unset($conf["stringProcess::spiltString"]);
2615
 
3 liveuser 2616
							#如果分割檔案名稱失敗
2617
							if($noString["status"]=="false"){
226 liveuser 2618
 
3 liveuser 2619
								#設置執行失敗
2620
								$result["status"]="false";
226 liveuser 2621
 
3 liveuser 2622
								#設置錯誤訊息
2623
								$result["error"]=$noString;
226 liveuser 2624
 
3 liveuser 2625
								#回傳結果
2626
								return $result;
226 liveuser 2627
 
3 liveuser 2628
								}#if end
226 liveuser 2629
 
3 liveuser 2630
							#如果 編號規則字串 分割出來的段數為2
2631
							if($noString["dataCounts"]==2){
226 liveuser 2632
 
3 liveuser 2633
								#組合編號
2634
								$no=$noString["dataArray"][0].$i.$noString["dataArray"][1];
226 liveuser 2635
 
3 liveuser 2636
								}#if end
226 liveuser 2637
 
3 liveuser 2638
							#反之 號規則字串 分割出來的段數為1
2639
							else if($noString["dataCounts"]==1){
226 liveuser 2640
 
3 liveuser 2641
								#判斷 "\$i" 在開頭或結尾
2642
								#函式說明:
2643
								#取得關鍵字在字串的哪個位置
2644
								#回傳結果:
2645
								#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
2646
								#$result["error"],錯誤訊息陣列.
2647
								#$result["function"],當前執行的函數名稱.
2648
								#$result["argu"],傳入的參數.
2649
								#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
2650
								#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
2651
								#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
2652
								#必填參數:
2653
								#$conf["inputStr"],字串,被搜尋的字串.
2654
								$conf["search::findKeyWordPosition"]["inputStr"]=$conf["repeatNameRule"];
2655
								#$conf["keyWord"],字串,關鍵字.
2656
								$conf["search::findKeyWordPosition"]["keyWord"]="\$i";
2657
								#參考資料:
2658
								#http://php.net/manual/en/function.strpos.php
2659
								$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
2660
								unset($conf["search::findKeyWordPosition"]);
226 liveuser 2661
 
3 liveuser 2662
								#如果取得關鍵字位置失敗
2663
								if($findKeyWordPosition["status"]=="false"){
226 liveuser 2664
 
3 liveuser 2665
									#設置執行失敗
2666
									$result["status"]="false";
226 liveuser 2667
 
3 liveuser 2668
									#設置錯誤訊息
2669
									$result["error"]=$findKeyWordPosition;
226 liveuser 2670
 
3 liveuser 2671
									#回傳結果
2672
									return $result;
226 liveuser 2673
 
3 liveuser 2674
									}#if end
226 liveuser 2675
 
3 liveuser 2676
								#如果關鍵字在開頭
2677
								if($findKeyWordPosition["head"]=="true"){
226 liveuser 2678
 
3 liveuser 2679
									#組合編號
2680
									$no=$i.$noString["dataArray"][0];
226 liveuser 2681
 
3 liveuser 2682
									}#if end
226 liveuser 2683
 
3 liveuser 2684
								#反之如果關鍵字在結尾
2685
								else if($findKeyWordPosition["tail"]=="true"){
226 liveuser 2686
 
3 liveuser 2687
									#組合編號
2688
									$no=$noString["dataArray"][0].$i;
226 liveuser 2689
 
3 liveuser 2690
									}#if end
226 liveuser 2691
 
3 liveuser 2692
								#其他情況
2693
								else{
226 liveuser 2694
 
3 liveuser 2695
									#設置執行失敗
2696
									$result["status"]="false";
226 liveuser 2697
 
3 liveuser 2698
									#設置錯誤訊息
2699
									$result["error"]=$findKeyWordPosition;
226 liveuser 2700
 
3 liveuser 2701
									#設置額外的錯誤訊息
2702
									$result["error"][]="非預期的結果";
226 liveuser 2703
 
3 liveuser 2704
									#回傳結果
2705
									return $result;
226 liveuser 2706
 
3 liveuser 2707
									}#else end
226 liveuser 2708
 
3 liveuser 2709
								}#if end
226 liveuser 2710
 
3 liveuser 2711
							#反之 編號規則字串 分割出來的段數為0
2712
							else if($noString["dataCounts"]==0){
226 liveuser 2713
 
3 liveuser 2714
								#組合編號
2715
								$no=$j;
226 liveuser 2716
 
3 liveuser 2717
								}#if end
226 liveuser 2718
 
3 liveuser 2719
							#其他結果
2720
							else{
226 liveuser 2721
 
3 liveuser 2722
								#設置執行失敗
2723
								$result["status"]="false";
226 liveuser 2724
 
3 liveuser 2725
								#設置錯誤訊息
2726
								$result["error"]=$noString;
226 liveuser 2727
 
3 liveuser 2728
								#設置額外的錯誤訊息
2729
								$result["error"][]="非預期的結果";
226 liveuser 2730
 
3 liveuser 2731
								#回傳結果
2732
								return $result;
226 liveuser 2733
 
2734
								}#else end
2735
 
3 liveuser 2736
							#串接編號到檔案名稱上
2737
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j].$no;
226 liveuser 2738
 
3 liveuser 2739
							#如果不是最後一段
2740
							if($j!=$spiltString["dataCounts"]-1){
226 liveuser 2741
 
3 liveuser 2742
								#串接並加上 dot
2743
								$createdFileName=$createdFileName.".";
226 liveuser 2744
 
3 liveuser 2745
								}#if end
226 liveuser 2746
 
3 liveuser 2747
							}#if end
226 liveuser 2748
 
3 liveuser 2749
						#反之如果不是最後一段
2750
						else if($j!=$spiltString["dataCounts"]-1){
226 liveuser 2751
 
3 liveuser 2752
							#串接並加上 dot
2753
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j].".";
226 liveuser 2754
 
3 liveuser 2755
							}#if end
226 liveuser 2756
 
2757
						#反之是最後一段
3 liveuser 2758
						else{
226 liveuser 2759
 
3 liveuser 2760
							#串接並加上 dot
2761
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j];
226 liveuser 2762
 
3 liveuser 2763
							}#else end
226 liveuser 2764
 
3 liveuser 2765
						}#for end
226 liveuser 2766
 
3 liveuser 2767
					}#else end
226 liveuser 2768
 
3 liveuser 2769
				#檢查加上編號的檔案是否存在
2770
				#函式說明:
2771
				#檢查多個檔案與資料夾是否存在.
2772
				#回傳的結果:
2773
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
2774
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2775
				#必填參數:
2776
				$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($createdFilePath."/".$createdFileName);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
2777
				$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
2778
				#參考資料來源:
2779
				#http://php.net/manual/en/function.file-exists.php
2780
				#http://php.net/manual/en/control-structures.foreach.php
2781
				$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
2782
				$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
2783
				unset($conf["fileAccess"]["checkMutiFileExist"]);
226 liveuser 2784
 
3 liveuser 2785
				#如果檢查檔案是否存在失敗
2786
				if($checkResult["status"]=="false"){
226 liveuser 2787
 
3 liveuser 2788
					#設置執行失敗
2789
					$result["status"]="false";
226 liveuser 2790
 
3 liveuser 2791
					#設置錯誤訊息
2792
					$result["error"]=$checkResult;
226 liveuser 2793
 
3 liveuser 2794
					#回傳結果
2795
					return $result;
226 liveuser 2796
 
2797
					}#if end
2798
 
3 liveuser 2799
				#如果 $checkResult["varExist"][0] 等於 "true"
226 liveuser 2800
				if($checkResult["varExist"][0]=="true"){
2801
 
3 liveuser 2802
					#取得要建立的檔案名稱
2803
					$createdFileName=$validatePath["fileName"];
226 liveuser 2804
 
3 liveuser 2805
					#跳到下個迴圈
2806
					continue;
226 liveuser 2807
 
3 liveuser 2808
					}#if end
226 liveuser 2809
 
3 liveuser 2810
				#反之代表 $createFilePath.$createdFileName."(".$i.")" 檔檔案不存在
2811
				else{
226 liveuser 2812
 
3 liveuser 2813
					#嘗試建立該檔案
2814
					#函式說明:
2815
					#將字串寫入到檔案
2816
					#回傳結果:
2817
					#$result["status"],true表示檔案寫入成功,false表示檔案寫入失敗.
2818
					#$result["error"],錯誤訊息陣列.
2819
					#必填參數:
2820
					$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$createdFilePath."/".$createdFileName;#爲要編輯的檔案名稱
2821
					$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
2822
					$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
2823
					#可省略參數:
2824
					$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
2825
					$conf["fileAccess"]["writeTextIntoFile"]["web"]=$conf["web"];
2826
					$fileCreateResult=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
2827
					unset($conf["fileAccess"]["writeTextIntoFile"]);
226 liveuser 2828
 
3 liveuser 2829
					#如果 $fileCreateResult["status"] 等於 "true"
2830
					if($fileCreateResult["status"]=="true"){
226 liveuser 2831
 
3 liveuser 2832
						#代表檔案建立成功
226 liveuser 2833
 
3 liveuser 2834
						#更新建立的檔案名稱
2835
						$result["createdFileName"]=$createdFileName;
226 liveuser 2836
 
3 liveuser 2837
						#跳出迴圈
2838
						break;
226 liveuser 2839
 
3 liveuser 2840
						}#if end
226 liveuser 2841
 
3 liveuser 2842
					#反之代表檔案建立失敗
2843
					else{
226 liveuser 2844
 
3 liveuser 2845
						#設置錯誤識別
2846
						$result["status"]="false";
226 liveuser 2847
 
3 liveuser 2848
						#設置錯誤訊息
2849
						$result["error"]=$fileCreateResult;
226 liveuser 2850
 
3 liveuser 2851
						#回傳結果
2852
						return $result;
226 liveuser 2853
 
3 liveuser 2854
						}#else end
226 liveuser 2855
 
3 liveuser 2856
					}#else end
226 liveuser 2857
 
3 liveuser 2858
				}#else end
226 liveuser 2859
 
3 liveuser 2860
			}#for end
226 liveuser 2861
 
3 liveuser 2862
		#如果不存在建立的檔案名稱
2863
		if(!isset($result["createdFileName"])){
226 liveuser 2864
 
3 liveuser 2865
			#設置錯誤識別
2866
			$result["status"]="false";
226 liveuser 2867
 
3 liveuser 2868
			#設置錯誤訊息
2869
			$result["error"][]="建立的檔案名稱不存在";
226 liveuser 2870
 
3 liveuser 2871
			#回傳結果
2872
			return $result;
226 liveuser 2873
 
2874
			}#if end
2875
 
3 liveuser 2876
		#執行到這邊代表執行成功
2877
		$result["status"]="true";
226 liveuser 2878
 
3 liveuser 2879
		#設置新建立的檔案名稱與路徑
2880
		$result["createdFilePathAndName"]=$createdFilePath."/".$result["createdFileName"];
226 liveuser 2881
 
3 liveuser 2882
		#設置新建立的檔與路徑
2883
		$result["createdFilePath"]=$createdFilePath;
226 liveuser 2884
 
3 liveuser 2885
		#回傳結果
2886
		return $result;
226 liveuser 2887
 
3 liveuser 2888
		}#fucntion createFileAfterCheck end
2889
 
2890
	/*
2891
	#函式說明:
2892
	#將檔案內容清空
2893
	#回傳結果:
2894
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
2895
	#$result["error"],錯誤訊息陣列
2896
	#必填參數:
2897
	#$conf["fileAddr"],字串,要清空的檔案位置與名稱.
2898
	$conf["fileAddr"]="";
2899
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2900
	$conf["fileArgu"]=__FILE__;
2901
	#可省略參數:
2902
	#$conf["web"],"true"代表為網頁系統,"false"代表檔案系統,預設為"false".
2903
	#$conf["web"]="false";
2904
	#參考資料:
2905
	#無.
2906
	#備註:
2907
	#無.
2908
	*/
2909
	public static function emptyFile(&$conf){
226 liveuser 2910
 
3 liveuser 2911
		#初始化要回傳的結果
2912
		$result=array();
226 liveuser 2913
 
3 liveuser 2914
		#設置當前執行的涵式
2915
		$result["function"]=__FUNCTION__;
226 liveuser 2916
 
3 liveuser 2917
		#如果 $conf 不為陣列
2918
		if(gettype($conf)!="array"){
226 liveuser 2919
 
3 liveuser 2920
			#設置執行失敗
2921
			$result["status"]="false";
226 liveuser 2922
 
3 liveuser 2923
			#設置執行錯誤訊息
2924
			$result["error"][]="\$conf變數須為陣列形態";
2925
 
2926
			#如果傳入的參數為 null
2927
			if($conf==null){
226 liveuser 2928
 
3 liveuser 2929
				#設置執行錯誤訊息
2930
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 2931
 
3 liveuser 2932
				}#if end
2933
 
2934
			#回傳結果
2935
			return $result;
226 liveuser 2936
 
3 liveuser 2937
			}#if end
226 liveuser 2938
 
3 liveuser 2939
		#取得參數
2940
		$result["argu"]=$conf;
226 liveuser 2941
 
3 liveuser 2942
		#檢查參數
2943
		#函式說明:
2944
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2945
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2946
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2947
		#$result["function"],當前執行的函式名稱.
2948
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2949
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2950
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2951
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2952
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2953
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2954
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2955
		#必填寫的參數:
2956
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2957
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2958
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2959
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddr");
226 liveuser 2960
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 2961
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
2962
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2963
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2964
		#可以省略的參數:
2965
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2966
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2967
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2968
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 2969
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 2970
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
2971
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2972
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
2973
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2974
		#$conf["arrayCountEqualCheck"][]=array();
2975
		#參考資料來源:
2976
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2977
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2978
		unset($conf["variableCheck::checkArguments"]);
2979
 
2980
		#如果 $checkArguments["status"] 等於 "false"
2981
		if($checkArguments["status"]=="false"){
226 liveuser 2982
 
3 liveuser 2983
			#設置錯誤識別
2984
			$result["status"]="false";
226 liveuser 2985
 
3 liveuser 2986
			#設置錯誤訊息
2987
			$result["error"]=$checkArguments;
226 liveuser 2988
 
3 liveuser 2989
			#回傳結果
226 liveuser 2990
			return $result;
2991
 
3 liveuser 2992
			}#if end
226 liveuser 2993
 
3 liveuser 2994
		#如果 $checkArguments["passed"] 等於 "false"
2995
		if($checkArguments["passed"]=="false"){
226 liveuser 2996
 
3 liveuser 2997
			#設置錯誤識別
2998
			$result["status"]="false";
226 liveuser 2999
 
3 liveuser 3000
			#設置錯誤訊息
3001
			$result["error"]=$checkArguments;
226 liveuser 3002
 
3 liveuser 3003
			#回傳結果
226 liveuser 3004
			return $result;
3005
 
3006
			}#if end
3007
 
3 liveuser 3008
		#函式說明:
3009
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
3010
		#回傳結果:
3011
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3012
		#$result["error"],錯誤訊息陣列.
226 liveuser 3013
		#$result["function"],函數名稱.
3 liveuser 3014
		#$result["argu"],使用的參數.
3015
		#$result["content"],網址,若是在命令列執行,則為"null".
3016
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
3017
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
3018
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
3019
		#必填參數:
3020
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
3021
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["fileAddr"];
3022
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3023
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
3024
		#可省略參數:
3025
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3026
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
3027
		#備註:
3028
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
3029
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
3030
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 3031
 
3 liveuser 3032
		#如果確保路徑失敗
3033
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 3034
 
3 liveuser 3035
			#設置錯誤識別
3036
			$result["status"]="false";
226 liveuser 3037
 
3 liveuser 3038
			#設置錯誤訊息
3039
			$result["error"]=$getInternetAddressV2;
226 liveuser 3040
 
3 liveuser 3041
			#回傳結果
3042
			return $result;
226 liveuser 3043
 
3 liveuser 3044
			}#if end
226 liveuser 3045
 
3 liveuser 3046
		#更新檔案路徑
3047
		$conf["fileAddr"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 3048
 
3 liveuser 3049
		#確保要建立檔案的路徑
3050
		#函式說明:
3051
		#確保路徑存在.
3052
		#回傳結果:
3053
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3054
		#$result["error"],錯誤訊息陣列.
3055
		#$resutl["function"],當前執行的涵式名稱.
3056
		#$result["path"],建立好的路徑字串.
3057
		#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
3058
		#必填參數:
3059
		#$conf["path"],要檢查的路徑
226 liveuser 3060
		$conf["fileAccess::validatePath"]["path"]=$conf["fileAddr"];
3 liveuser 3061
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3062
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
3063
		#可省略參數:
3064
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
3065
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
3066
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3067
		#$conf["dirPermission"]="";
3068
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3069
		$conf["fileAccess::validatePath"]["web"]="false";
3070
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
226 liveuser 3071
		unset($conf["fileAccess::validatePath"]);
3072
 
3 liveuser 3073
		#如果確保路徑失敗
3074
		if($validatePath["status"]==="false"){
226 liveuser 3075
 
3 liveuser 3076
			#設置錯誤識別
3077
			$result["status"]="false";
226 liveuser 3078
 
3 liveuser 3079
			#設置錯誤訊息
3080
			$result["error"]=$validatePath;
226 liveuser 3081
 
3 liveuser 3082
			#回傳結果
3083
			return $result;
226 liveuser 3084
 
3 liveuser 3085
			}#if end
226 liveuser 3086
 
3 liveuser 3087
		#清空檔案
3088
		#函式說明:
3089
		#將字串寫入到檔案
3090
		#回傳結果:
3091
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
3092
		#$result["error"],錯誤訊息陣列.
3093
		#$result["function"],當前執行的函數名稱.
3094
		#$result["fileInfo"],實際上寫入的檔案資訊陣列.
3095
		#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
3096
		#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
3097
		#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
3098
		#$result["argu"],使用的參數.
3099
		#必填參數:
3100
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3101
		$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
3102
		#可省略參數:
3103
		#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
3104
		#$conf["fileAccess::writeTextIntoFile"]["fileName"]=$validatePath["path"]."/".$validatePath["fileName"];
3105
		$conf["fileAccess::writeTextIntoFile"]["fileName"]=$validatePath["path"]."/".$validatePath["fileName"];;
3106
		#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
3107
		#$conf["inputString"]="";
3108
		#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
3109
		#$conf["writeMethod"]="a";
3110
		#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
3111
		#$conf["checkRepeat"]="";
3112
		#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
3113
		#$conf["filenameExtensionStartPoint"]="";
3114
		#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
3115
		#$conf["repeatNameRule"]="";
3116
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3117
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
3118
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
3119
		unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 3120
 
3 liveuser 3121
		#如果確保路徑失敗
3122
		if($writeTextIntoFile["status"]==="false"){
226 liveuser 3123
 
3 liveuser 3124
			#設置錯誤識別
3125
			$result["status"]="false";
226 liveuser 3126
 
3 liveuser 3127
			#設置錯誤訊息
3128
			$result["error"]=$writeTextIntoFile;
226 liveuser 3129
 
3 liveuser 3130
			#回傳結果
3131
			return $result;
226 liveuser 3132
 
3 liveuser 3133
			}#if end
226 liveuser 3134
 
3 liveuser 3135
		#設置執行正常
3136
		$result["status"]="true";
226 liveuser 3137
 
3 liveuser 3138
		#儲存建立的結果
3139
		$result["content"]=$writeTextIntoFile;
226 liveuser 3140
 
3 liveuser 3141
		#回傳結果
3142
		return $result;
226 liveuser 3143
 
3 liveuser 3144
		}#function emptyFile end
3145
 
3146
	/*
3147
	#函式說明:
3148
	#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
3149
	#回傳結果:
3150
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3151
	#$result["error"],錯誤訊息陣列
3152
	#$result["warning"],警告訊息陣列
3153
	#必填參數:
3154
	#$conf["dirPositionAndName"]="";#新建的位置與名稱
3155
	$conf["dirPositionAndName"]="";
3156
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3157
	$conf["fileArgu"]=__FILE__;
3158
	#可省略參數:
3159
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3160
	#$conf["dirPermission"]="";
3161
	#參考資料:
3162
	#mkdir=>http://php.net/manual/en/function.mkdir.php
3163
	#chmod=>http://php.net/manual/en/function.chmod.php
3164
	#參考資料:
3165
	#無.
3166
	#備註:
3167
	#同 function createFolderAfterCheck.
3168
	*/
3169
	public static function createNewFolder(&$conf){
3170
 
3171
		/*
3172
		#函式說明:
3173
		#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
3174
		#回傳的結果:
3175
		#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
3176
		#$result["error"],錯誤訊息陣列.
3177
		#$result["function"],當前執行的函數名稱.
3178
		#$result["createdFileName"],建立好的檔案名稱.
3179
		#$result["createdFilePath"],檔案建立的路徑.
3180
		#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
3181
		#必填參數:
3182
		#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
3183
		$conf["checkedFileAndPath"]="";
3184
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3185
		$conf["fileArgu"]=__FILE__;
3186
		*/
3187
		return fileAccess::createFolderAfterCheck($conf);
3188
		unset($conf);
3189
 
3190
		}#function createNewFolder end
226 liveuser 3191
 
3 liveuser 3192
	/*
3193
	#函式說明:
3194
	#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
3195
	#回傳結果:
3196
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3197
	#$result["error"],錯誤訊息陣列
3198
	#$result["warning"],警告訊息陣列
3199
	#$result["argu"],使用的參數.
3200
	#$result["content"],建立的目錄路徑.
3201
	#必填參數:
3202
	#$conf["dirPositionAndName"]="";#新建的位置與名稱
3203
	$conf["dirPositionAndName"]="";
3204
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3205
	$conf["fileArgu"]=__FILE__;
3206
	#可省略參數:
3207
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3208
	#$conf["dirPermission"]="";
3209
	#$conf["web"],"false"代表在檔案系統環境,"true"代表在網頁稀系統環境.
3210
	#$conf["web"]="false";
3211
	#參考資料:
3212
	#mkdir=>http://php.net/manual/en/function.mkdir.php
3213
	#chmod=>http://php.net/manual/en/function.chmod.php
3214
	#備註:
3215
	#無.
3216
	*/
3217
	public static function createFolderAfterCheck(&$conf){
226 liveuser 3218
 
3 liveuser 3219
		#初始化要回傳的結果
3220
		$result=array();
226 liveuser 3221
 
3 liveuser 3222
		#初始化警告訊息陣列
3223
		$result["warning"]=array();
226 liveuser 3224
 
3 liveuser 3225
		#記錄當前執行的函數名稱
3226
		$result["function"]=__FUNCTION__;
226 liveuser 3227
 
3 liveuser 3228
		#如果 $conf 不為陣列
3229
		if(gettype($conf)!="array"){
226 liveuser 3230
 
3 liveuser 3231
			#設置執行失敗
3232
			$result["status"]="false";
226 liveuser 3233
 
3 liveuser 3234
			#設置執行錯誤訊息
3235
			$result["error"][]="\$conf變數須為陣列形態";
3236
 
3237
			#如果傳入的參數為 null
3238
			if($conf==null){
226 liveuser 3239
 
3 liveuser 3240
				#設置執行錯誤訊息
3241
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3242
 
3 liveuser 3243
				}#if end
3244
 
3245
			#回傳結果
3246
			return $result;
226 liveuser 3247
 
3 liveuser 3248
			}#if end
226 liveuser 3249
 
3 liveuser 3250
		#取得參數
3251
		$result["argu"]=$conf;
226 liveuser 3252
 
3 liveuser 3253
		#檢查參數
3254
		#函式說明:
3255
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3256
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3257
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3258
		#$result["function"],當前執行的函式名稱.
3259
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3260
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3261
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3262
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3263
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3264
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3265
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3266
		#必填寫的參數:
3267
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3268
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3269
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3270
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","dirPositionAndName");
226 liveuser 3271
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3272
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
3273
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3274
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3275
		#可以省略的參數:
3276
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3277
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3278
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3279
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dirPermission","web");
226 liveuser 3280
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3281
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
3282
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3283
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("0770","false");
3284
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3285
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
3286
		#參考資料來源:
3287
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3288
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3289
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3290
 
3 liveuser 3291
		#如果 $checkArguments["status"] 等於 "false"
3292
		if($checkArguments["status"]==="false"){
226 liveuser 3293
 
3 liveuser 3294
			#設置 $result["status"] 為 "false"
3295
			$result["status"]="false";
226 liveuser 3296
 
3 liveuser 3297
			#設置 $result["error"]
3298
			$result["error"]=$checkArguments;
226 liveuser 3299
 
3 liveuser 3300
			#回傳結果
3301
			return $result;
226 liveuser 3302
 
3 liveuser 3303
			}#if end
226 liveuser 3304
 
3 liveuser 3305
		#如果 $checkArguments["passed"] 等於 "false"
3306
		if($checkArguments["passed"]==="false"){
226 liveuser 3307
 
3 liveuser 3308
			#設置 $result["status"] 為 "false"
3309
			$result["status"]="false";
226 liveuser 3310
 
3 liveuser 3311
			#設置 $result["error"]
3312
			$result["error"]=$checkArguments;
226 liveuser 3313
 
3 liveuser 3314
			#回傳結果
3315
			return $result;
226 liveuser 3316
 
3317
			}#if end
3318
 
3 liveuser 3319
		#函式說明:
3320
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
3321
		#回傳結果:
3322
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3323
		#$result["error"],錯誤訊息陣列.
226 liveuser 3324
		#$result["function"],函數名稱.
3 liveuser 3325
		#$result["argu"],使用的參數.
3326
		#$result["content"],網址,若是在命令列執行,則為"null".
3327
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
3328
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
3329
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
3330
		#必填參數:
3331
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
3332
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["dirPositionAndName"];
3333
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3334
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
3335
		#可省略參數:
3336
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3337
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
3338
		#備註:
3339
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
3340
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
3341
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 3342
 
3 liveuser 3343
		#如果 $getInternetAddressV2["status"] 等於 "false"
3344
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 3345
 
3 liveuser 3346
			#設置 $result["status"] 為 "false"
3347
			$result["status"]="false";
226 liveuser 3348
 
3 liveuser 3349
			#設置 $result["error"]
3350
			$result["error"]=$getInternetAddressV2;
226 liveuser 3351
 
3 liveuser 3352
			#回傳結果
3353
			return $result;
226 liveuser 3354
 
3 liveuser 3355
			}#if end
226 liveuser 3356
 
3 liveuser 3357
		#取得絕對位置
3358
		$conf["dirPositionAndName"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 3359
 
3 liveuser 3360
		#用「/」分割要建立的路徑
3361
		#函式說明:
3362
		#將固定格式的字串分開,並回傳分開的結果。
3363
		#回傳結果:
3364
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3365
		#$result["error"],錯誤訊息陣列
3366
		#$result["function"],當前執行的函數名稱.
3367
		#$result["oriStr"],要分割的原始字串內容
3368
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
3369
		#$result["dataCounts"],爲總共分成幾段
3370
		#必填參數:
3371
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["dirPositionAndName"];
3372
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
3373
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 3374
		unset($conf["stringProcess::spiltString"]);
3375
 
3 liveuser 3376
		#如果分割失敗
3377
		if($spiltString["status"]=="false"){
226 liveuser 3378
 
3 liveuser 3379
			#設置 $result["status"] 為 "false"
3380
			$result["status"]="false";
226 liveuser 3381
 
3 liveuser 3382
			#設置 $result["error"]
3383
			$result["error"]=$spiltString;
226 liveuser 3384
 
3 liveuser 3385
			#回傳結果
3386
			return $result;
226 liveuser 3387
 
3 liveuser 3388
			}#if end
226 liveuser 3389
 
3 liveuser 3390
		$checkedPath="";
226 liveuser 3391
 
3 liveuser 3392
		#依據切割成的路徑片段數目
3393
		for($i=0;$i<$spiltString["dataCounts"];$i++){
226 liveuser 3394
 
3 liveuser 3395
			$checkedPath=$checkedPath."/".$spiltString["dataArray"][$i];
226 liveuser 3396
 
3 liveuser 3397
			#檢查路徑是否存在
3398
			#函式說明:
3399
			#檢查多個檔案與資料夾是否存在.
3400
			#回傳的結果:
3401
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3402
			#$result["error"],錯誤訊息陣列.
3403
			#$resutl["function"],當前執行的涵式名稱.
3404
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
3405
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
3406
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
3407
			#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
3408
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
3409
			#必填參數:
3410
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
3411
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($checkedPath);
3412
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3413
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
3414
			#可省略參數
3415
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
3416
			#$conf["disableWebSearch"]="false";
3417
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
3418
			#$conf["userDir"]="true";
3419
			#參考資料來源:
3420
			#http://php.net/manual/en/function.file-exists.php
3421
			#http://php.net/manual/en/control-structures.foreach.php
3422
			#備註:
3423
			#函數file_exists檢查的路徑為檔案系統的路徑
3424
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 3425
 
3 liveuser 3426
			#如果檢查資料夾路徑失敗
3427
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 3428
 
3 liveuser 3429
				#設置 $result["status"] 為 "false"
3430
				$result["status"]="false";
226 liveuser 3431
 
3 liveuser 3432
				#設置 $result["error"]
3433
				$result["error"]=$spiltString;
226 liveuser 3434
 
3 liveuser 3435
				#回傳結果
3436
				return $result;
226 liveuser 3437
 
3 liveuser 3438
				}#if end
226 liveuser 3439
 
3 liveuser 3440
			#如果目錄不存在
3441
			if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 3442
 
3 liveuser 3443
				#如果有這個名稱的東西存在
3444
				if(file_exists($checkedPath)){
226 liveuser 3445
 
3 liveuser 3446
					#如果目錄存在
3447
					if(is_dir($checkedPath)){
226 liveuser 3448
 
3 liveuser 3449
						#目錄已經存在換下一層
3450
						continue;
226 liveuser 3451
 
3 liveuser 3452
						}#if end
226 liveuser 3453
 
3 liveuser 3454
					}#if end
226 liveuser 3455
 
3 liveuser 3456
				#建立目錄
3457
				$mkdir=@mkdir($checkedPath,0770);
226 liveuser 3458
 
3 liveuser 3459
				#如果建立目錄失敗
3460
				#參考資料:
3461
				#http://php.net/manual/en/function.mkdir.php
3462
				if($mkdir===false){
226 liveuser 3463
 
3 liveuser 3464
					#設置 $result["status"] 為 "false"
3465
					$result["status"]="false";
226 liveuser 3466
 
3 liveuser 3467
					#設置 $result["error"]
3468
					$result["error"][]="建立目錄「".$checkedPath."」失敗";
226 liveuser 3469
 
3 liveuser 3470
					#回傳結果
3471
					return $result;
226 liveuser 3472
 
3 liveuser 3473
					}#if end
226 liveuser 3474
 
3 liveuser 3475
				#更改目錄的權限為 0770
3476
				chmod($checkedPath,0770);
226 liveuser 3477
 
3 liveuser 3478
				}#if end
226 liveuser 3479
 
3 liveuser 3480
			}#for end
226 liveuser 3481
 
3 liveuser 3482
		#取得建立好的目錄
226 liveuser 3483
		$result["content"]=$checkedPath;
3484
 
3 liveuser 3485
		#執行到這邊代表執行成功
3486
		$result["status"]="true";
226 liveuser 3487
 
3 liveuser 3488
		#回傳結果
3489
		return $result;
226 liveuser 3490
 
3 liveuser 3491
		}#function createFolderAfterCheck end
3492
 
3493
	/*
3494
	#函式說明:
3495
	#移除檔案
3496
	#回傳結果:
3497
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
3498
	#$result["error"],錯誤訊息陣列.
3499
	#$result["warning"],警告訊息陣列.
3500
	#$result["function"],當前執行的函數名稱.
3501
	#$result["argu"],當前函式使用的參數.
3502
	#必填參數:
3503
	#$conf["fileAddress"],字串,要移除檔案的位置.
3504
	$conf["fileAddress"]="";
3505
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3506
	$conf["fileArgu"]=__FILE__;
3507
	#可省略參數:
3508
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
3509
	#$conf["commentsArray"]=array("");
3510
	#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
3511
	#$conf["allowDelSymlink"]="true";
3512
	#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
3513
	#$conf["allowDelFolder"]="true";
3514
	#參考資料:
3515
	#無.
3516
	#備註:
3517
	#無.
220 liveuser 3518
	*/
3 liveuser 3519
	public static function delFile(&$conf){
3520
 
3521
		#初始化要回傳的結果
3522
		$result=array();
226 liveuser 3523
 
3 liveuser 3524
		#設置當其函數名稱
3525
		$result["function"]=__FUNCTION__;
226 liveuser 3526
 
3 liveuser 3527
		#如果 $conf 不為陣列
3528
		if(gettype($conf)!="array"){
226 liveuser 3529
 
3 liveuser 3530
			#設置執行失敗
3531
			$result["status"]="false";
226 liveuser 3532
 
3 liveuser 3533
			#設置執行錯誤訊息
3534
			$result["error"][]="\$conf變數須為陣列形態";
3535
 
3536
			#如果傳入的參數為 null
3537
			if($conf==null){
226 liveuser 3538
 
3 liveuser 3539
				#設置執行錯誤訊息
3540
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3541
 
3 liveuser 3542
				}#if end
3543
 
3544
			#回傳結果
3545
			return $result;
226 liveuser 3546
 
3 liveuser 3547
			}#if end
226 liveuser 3548
 
3 liveuser 3549
		#取得參數
3550
		$result["argu"]=$conf;
226 liveuser 3551
 
3 liveuser 3552
		#檢查參數
3553
		#函式說明:
3554
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3555
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3556
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3557
		#$result["function"],當前執行的函式名稱.
3558
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3559
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3560
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3561
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3562
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3563
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3564
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3565
		#必填寫的參數:
3566
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3567
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3568
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3569
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddress");
226 liveuser 3570
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3571
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
3572
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3573
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3574
		#可以省略的參數:
3575
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3576
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3577
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3578
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","allowDelSymlink","allowDelFolder");
226 liveuser 3579
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3580
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");
3581
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3582
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false","false");
3583
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3584
		#$conf["arrayCountEqualCheck"][]=array();
3585
		#參考資料來源:
3586
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3587
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3588
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3589
 
3 liveuser 3590
		#如果檢查失敗
3591
		if($checkResult["status"]=="false"){
226 liveuser 3592
 
3 liveuser 3593
			#設置錯誤識別
3594
			$result["status"]="false";
226 liveuser 3595
 
3 liveuser 3596
			#設置錯誤訊息
3597
			$result["error"]=$checkResult;
226 liveuser 3598
 
3 liveuser 3599
			#回傳結果
3600
			return $result;
226 liveuser 3601
 
3 liveuser 3602
			}#if end
226 liveuser 3603
 
3 liveuser 3604
		#如果檢查不通過
3605
		if($checkResult["passed"]=="false"){
226 liveuser 3606
 
3 liveuser 3607
			#設置錯誤識別
3608
			$result["status"]="false";
226 liveuser 3609
 
3 liveuser 3610
			#設置錯誤訊息
3611
			$result["error"]=$checkResult;
226 liveuser 3612
 
3 liveuser 3613
			#回傳結果
3614
			return $result;
226 liveuser 3615
 
3 liveuser 3616
			}#if end
3617
 
3618
		#如果 $conf["commentsArray"] 有設定
3619
		if(isset($conf["commentsArray"])){
226 liveuser 3620
 
3 liveuser 3621
			#印出提示文字
3622
			#函式說明:
3623
			#印出多行文字,結尾自動換行.
3624
			#回傳的結果:
3625
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
3626
			#$result["function"],當前執行的函數名稱.
3627
			#$result["error"],錯誤訊息陣列.
3628
			#必填參數:
3629
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
3630
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
3631
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
3632
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 3633
 
3 liveuser 3634
			#如果印出提示文字失敗
3635
			if($echoMultiLine["status"]=="false"){
226 liveuser 3636
 
3 liveuser 3637
				#設置執行失敗
3638
				$result["status"]="false";
226 liveuser 3639
 
3 liveuser 3640
				#設置執行錯誤訊息
3641
				$result["error"]=$echoMultiLine;
226 liveuser 3642
 
3 liveuser 3643
				#回傳結果
3644
				return $result;
226 liveuser 3645
 
3 liveuser 3646
				}#if end
226 liveuser 3647
 
3 liveuser 3648
			}#if end
3649
 
3650
		#檢查要移除的檔案是否存在
3651
		#函式說明:
3652
		#檢查多個檔案與資料夾是否存在.
3653
		#回傳的結果:
3654
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3655
		#$result["error"],錯誤訊息陣列.
3656
		#$resutl["function"],當前執行的涵式名稱.
3657
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
3658
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
3659
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
3660
		#必填參數:
3661
		$conf["fileAccess.checkMultiFileExist"]["fileArray"]=array($conf["fileAddress"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
3662
		#$conf["fileAccess.checkMultiFileExist"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3663
		$conf["fileAccess.checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
3664
		#可省略參數:
3665
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
3666
		#$conf["disableWebSearch"]="false";
3667
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
3668
		#$conf["userDir"]="true";
3669
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
3670
		$conf["fileAccess.checkMultiFileExist"]["web"]="false";
3671
		#參考資料來源:
3672
		#http://php.net/manual/en/function.file-exists.php
3673
		#http://php.net/manual/en/control-structures.foreach.php
3674
		$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess.checkMultiFileExist"]);
3675
		unset($conf["fileAccess.checkMultiFileExist"]);
3676
 
3677
		#var_dump($checkResult);
3678
 
3679
		#如果檢查檔案是否存在失敗
3680
		if($checkResult["status"]==="false"){
226 liveuser 3681
 
3 liveuser 3682
			#設置執行失敗
3683
			$result["status"]="false";
3684
 
3685
			#回傳錯誤訊息
3686
			$result["error"]=$checkResult;
3687
 
3688
			#回傳結果
3689
			return $result;
226 liveuser 3690
 
3 liveuser 3691
			}#if end
3692
 
3693
		#如果目標檔案不存在
3694
		if($checkResult["varExist"][0]==="false"){
226 liveuser 3695
 
3 liveuser 3696
			#設置錯誤識別
3697
			$result["status"]="true";
3698
 
3699
			#回傳錯誤訊息
3700
			$result["warning"][]="要移除的檔案不存在";
3701
 
3702
			#回傳結果
3703
			return $result;
226 liveuser 3704
 
3 liveuser 3705
			}#if end
3706
 
3707
		#如果要移除的目標是檔案
3708
		if(is_file($conf["fileAddress"])){
226 liveuser 3709
 
3 liveuser 3710
			#移除檔案,並回傳移除的結果
3711
			$eraseResult=(@unlink($conf["fileAddress"]));
3712
 
3713
			#如果 $eraseResult 等於 false
3714
			if($eraseResult===false){
226 liveuser 3715
 
3 liveuser 3716
				#設置錯誤識別
3717
				$result["status"]="false";
3718
 
3719
				#回傳錯誤訊息
3720
				$result["error"][]="檔案移除失敗";
3721
 
3722
				#回傳結果
3723
				return $result;
226 liveuser 3724
 
3 liveuser 3725
				}#if end
226 liveuser 3726
 
3 liveuser 3727
			}#if end
3728
 
3729
		#反之要移除的目標是目錄
3730
		else if(is_dir($conf["fileAddress"])){
226 liveuser 3731
 
3 liveuser 3732
			#如果允許移除目錄
3733
			if($conf["allowDelFolder"]==="true"){
226 liveuser 3734
 
3 liveuser 3735
				#移除目錄跟底下的內容
3736
				w函式說明:
3737
				#呼叫shell執行系統命令,並取得回傳的內容.
3738
				#回傳結果:
3739
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3740
				#$result["error"],錯誤訊息陣列.
3741
				#$result["function"],當前執行的函數名稱.
3742
				#$result["argu"],使用的參數.
3743
				#$result["cmd"],執行的指令內容.
3744
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
3745
				#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
3746
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
3747
				#$result["running"],是否還在執行.
3748
				#$result["pid"],pid.
3749
				#$result["statusCode"],執行結束後的代碼.
3750
				#必填參數:
3751
				#$conf["command"],字串,要執行的指令.
3752
				$conf["external::callShell"]["command"]="rm";
3753
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3754
				$conf["external::callShell"]["fileArgu"]=__FILE__;
3755
				#可省略參數:
3756
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3757
				$conf["external::callShell"]["argu"]=array("-rf",$conf["fileAddress"]);
3758
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
3759
				#$conf["arguIsAddr"]=array();
3760
				#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
3761
				#$conf["plainArgu"]=array();
3762
				#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
3763
				#$conf["useApostrophe"]=array();
3764
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
3765
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
3766
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
3767
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
3768
				#$conf["enablePrintDescription"]="true";
3769
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
3770
				#$conf["printDescription"]="";
3771
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
3772
				$conf["external::callShell"]["escapeshellarg"]="true";
3773
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
3774
				#$conf["thereIsShellVar"]=array();
3775
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
3776
				#$conf["username"]="";
3777
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
3778
				#$conf["password"]="";
3779
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
3780
				#$conf["useScript"]="";
3781
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
3782
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
3783
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
3784
				#$conf["inBackGround"]="";
3785
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
3786
				#$conf["getErr"]="false";
3787
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
3788
				#$conf["doNotRun"]="false";
3789
				#參考資料:
3790
				#exec=>http://php.net/manual/en/function.exec.php
3791
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
3792
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
3793
				#備註:
3794
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
3795
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
3796
				$callShell=external::callShell($conf["external::callShell"]);
3797
				unset($conf["external::callShell"]);
226 liveuser 3798
 
3 liveuser 3799
				#如果執行失敗
3800
				if($callShell["status"]==="false"){
226 liveuser 3801
 
3 liveuser 3802
					#設置錯誤識別
3803
					$result["status"]="false";
3804
 
3805
					#回傳錯誤訊息
3806
					$result["error"]=$callShell;
3807
 
3808
					#回傳結果
3809
					return $result;
226 liveuser 3810
 
3 liveuser 3811
					}#if end
226 liveuser 3812
 
3813
				}#if end
3814
 
3 liveuser 3815
			#反之不允許
3816
			else{
226 liveuser 3817
 
3 liveuser 3818
				#設置錯誤識別
3819
				$result["status"]="false";
3820
 
3821
				#回傳錯誤訊息
3822
				$result["error"][]="不允許移除目錄";
226 liveuser 3823
 
3 liveuser 3824
				#回傳結果
3825
				return $result;
226 liveuser 3826
 
3 liveuser 3827
				}#else end
226 liveuser 3828
 
3 liveuser 3829
			}#if end
226 liveuser 3830
 
3 liveuser 3831
		#反之
3832
		else{
226 liveuser 3833
 
3 liveuser 3834
			#可能為 軟連結
226 liveuser 3835
 
3 liveuser 3836
			#如果允許移除
3837
			if($conf["allowDelSymlink"]==="true"){
226 liveuser 3838
 
3 liveuser 3839
				#移除檔案,並回傳移除的結果
3840
				$eraseResult=(@unlink($conf["fileAddress"]));
3841
 
3842
				#如果 $eraseResult 等於 false
3843
				if($eraseResult===false){
226 liveuser 3844
 
3 liveuser 3845
					#設置錯誤識別
3846
					$result["status"]="false";
3847
 
3848
					#回傳錯誤訊息
3849
					$result["error"][]="檔案移除失敗";
3850
 
3851
					#回傳結果
3852
					return $result;
226 liveuser 3853
 
3 liveuser 3854
					}#if end
226 liveuser 3855
 
3 liveuser 3856
				}#if end
226 liveuser 3857
 
3 liveuser 3858
			#反之
3859
			else{
226 liveuser 3860
 
3 liveuser 3861
				#設置錯誤識別
3862
				$result["status"]="false";
226 liveuser 3863
 
3 liveuser 3864
				#設置錯誤訊息
3865
				$result["error"][]="不允許移除 檔案、目錄 以外類型的目標";
3866
 
3867
				#回傳結果
3868
				return $result;
226 liveuser 3869
 
3 liveuser 3870
				}#else end
226 liveuser 3871
 
3 liveuser 3872
			}#else end
226 liveuser 3873
 
3 liveuser 3874
		#執行到這邊代表執行正常.
3875
		$result["status"]="true";
226 liveuser 3876
 
3 liveuser 3877
		#回傳結果
3878
		return $result;
3879
 
3880
		}#function delFile end
226 liveuser 3881
 
3 liveuser 3882
	/*
3883
	#函式說明:
3884
	#移除多個檔案
3885
	#回傳結果:
3886
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
3887
	#$result["error"],錯誤訊息陣列
3888
	#$result["function"],當前執行的函數名稱.
3889
	#$result["argu"],使用的參數.
3890
	#$result["content"],陣列,移除各個檔案的結果.
3891
	#必填參數:
3892
	#$conf["fileAddress"],字串陣列,要移除檔案的位置.
3893
	$conf["fileAddress"]=array("");
3894
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3895
	$conf["fileArgu"]=__FILE__;
3896
	#可省略參數:
3897
	#無.
3898
	#參考資料:
3899
	#無.
3900
	#備註:
3901
	#無.
220 liveuser 3902
	*/
3 liveuser 3903
	public static function delMultiFile(&$conf){
226 liveuser 3904
 
3 liveuser 3905
		#初始化要回傳的結果
3906
		$result=array();
226 liveuser 3907
 
3 liveuser 3908
		#設置當其函數名稱
3909
		$result["function"]=__FUNCTION__;
226 liveuser 3910
 
3 liveuser 3911
		#如果 $conf 不為陣列
3912
		if(gettype($conf)!="array"){
226 liveuser 3913
 
3 liveuser 3914
			#設置執行失敗
3915
			$result["status"]="false";
226 liveuser 3916
 
3 liveuser 3917
			#設置執行錯誤訊息
3918
			$result["error"][]="\$conf變數須為陣列形態";
3919
 
3920
			#如果傳入的參數為 null
3921
			if($conf==null){
226 liveuser 3922
 
3 liveuser 3923
				#設置執行錯誤訊息
3924
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3925
 
3 liveuser 3926
				}#if end
3927
 
3928
			#回傳結果
3929
			return $result;
226 liveuser 3930
 
3 liveuser 3931
			}#if end
226 liveuser 3932
 
3 liveuser 3933
		#取得使用的參數.
3934
		$result["argu"]=$conf;
226 liveuser 3935
 
3 liveuser 3936
		#檢查參數
3937
		#函式說明:
3938
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3939
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3940
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3941
		#$result["function"],當前執行的函式名稱.
3942
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3943
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3944
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3945
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3946
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3947
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3948
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3949
		#必填寫的參數:
3950
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3951
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3952
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3953
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddress");
226 liveuser 3954
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3955
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
3956
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3957
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3958
		#可以省略的參數:
3959
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3960
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3961
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3962
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray");
226 liveuser 3963
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3964
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
3965
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3966
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
3967
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3968
		#$conf["arrayCountEqualCheck"][]=array();
3969
		#參考資料來源:
3970
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3971
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3972
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3973
 
3 liveuser 3974
		#如果檢查失敗
3975
		if($checkResult["status"]=="false"){
226 liveuser 3976
 
3 liveuser 3977
			#設置錯誤識別
3978
			$result["status"]="false";
226 liveuser 3979
 
3 liveuser 3980
			#設置錯誤訊息
3981
			$result["error"]=$checkResult;
226 liveuser 3982
 
3 liveuser 3983
			#回傳結果
3984
			return $result;
226 liveuser 3985
 
3 liveuser 3986
			}#if end
226 liveuser 3987
 
3 liveuser 3988
		#如果檢查不通過
3989
		if($checkResult["passed"]=="false"){
226 liveuser 3990
 
3 liveuser 3991
			#設置錯誤識別
3992
			$result["status"]="false";
226 liveuser 3993
 
3 liveuser 3994
			#設置錯誤訊息
3995
			$result["error"]=$checkResult;
226 liveuser 3996
 
3 liveuser 3997
			#回傳結果
3998
			return $result;
226 liveuser 3999
 
3 liveuser 4000
			}#if end
226 liveuser 4001
 
3 liveuser 4002
		#針對每個要移除的檔案
4003
		foreach($conf["fileAddress"] as $fileAddr){
226 liveuser 4004
 
3 liveuser 4005
			#函式說明:
4006
			#移除檔案
4007
			#回傳結果:
4008
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
4009
			#$result["error"],錯誤訊息陣列
4010
			#$result["warning"],警告訊息陣列
4011
			#$result["function"],當前執行的函數名稱
4012
			#必填參數:
4013
			#$conf["fileAddress"],字串,要移除檔案的位置.
4014
			$conf["fileAccess::delFile"]["fileAddress"]=$fileAddr;
4015
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
4016
			$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
4017
			#可省略參數:
4018
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
4019
			#$conf["commentsArray"]=array("");
4020
			#備註:
4021
			#無.
4022
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
4023
			unset($conf["fileAccess::delFile"]);
226 liveuser 4024
 
3 liveuser 4025
			#如果檢查失敗
4026
			if($delFile["status"]==="false"){
226 liveuser 4027
 
3 liveuser 4028
				#設置錯誤識別
4029
				$result["status"]="false";
226 liveuser 4030
 
3 liveuser 4031
				#設置錯誤訊息
4032
				$result["error"]=$delFile;
226 liveuser 4033
 
3 liveuser 4034
				#回傳結果
4035
				return $result;
226 liveuser 4036
 
3 liveuser 4037
				}#if end
226 liveuser 4038
 
3 liveuser 4039
			#取得移除檔案的結果
4040
			$result["content"][]=$delFile;
226 liveuser 4041
 
3 liveuser 4042
			}#foreach end
226 liveuser 4043
 
3 liveuser 4044
		#設置執行正常
4045
		$result["status"]="true";
226 liveuser 4046
 
3 liveuser 4047
		#回傳結果
4048
		return $result;
226 liveuser 4049
 
3 liveuser 4050
		}#function delMultiFile end
226 liveuser 4051
 
3 liveuser 4052
	/*
4053
	#函式說明:
4054
	#確保路徑存在.
4055
	#回傳結果:
4056
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4057
	#$result["error"],錯誤訊息陣列.
4058
	#$resutl["function"],當前執行的涵式名稱.
4059
	#$result["path"],建立好的路徑字串.
4060
	#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
4061
	#$result["argu"],使用的參數.
4062
	#必填參數:
4063
	#$conf["path"],要檢查的路徑
226 liveuser 4064
	$conf["path"]="";
3 liveuser 4065
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4066
	$conf["fileArgu"]=__FILE__;
4067
	#可省略參數:
4068
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4069
	#$conf["haveFileName"]="false";
4070
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人無法使用.
4071
	#$conf["dirPermission"]="";
4072
	#$conf["web"],是否為檔案系統,"true"為網頁路徑,"false"為網頁系統,預設為"false".
4073
	#$conf["web"]="";
4074
	#參考資料:
4075
	#無.
4076
	#備註:
4077
	#無.
226 liveuser 4078
	*/
3 liveuser 4079
	public static function validatePath(&$conf){
226 liveuser 4080
 
3 liveuser 4081
		#初始化要回傳的結果
4082
		$result=array();
226 liveuser 4083
 
3 liveuser 4084
		#設置當其函數名稱
4085
		$result["function"]=__FUNCTION__;
226 liveuser 4086
 
3 liveuser 4087
		#如果 $conf 不為陣列
4088
		if(gettype($conf)!="array"){
226 liveuser 4089
 
3 liveuser 4090
			#設置執行失敗
4091
			$result["status"]="false";
226 liveuser 4092
 
3 liveuser 4093
			#設置執行錯誤訊息
4094
			$result["error"][]="\$conf變數須為陣列形態";
4095
 
4096
			#如果傳入的參數為 null
4097
			if($conf==null){
226 liveuser 4098
 
3 liveuser 4099
				#設置執行錯誤訊息
4100
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4101
 
3 liveuser 4102
				}#if end
226 liveuser 4103
 
3 liveuser 4104
			#回傳結果
4105
			return $result;
226 liveuser 4106
 
3 liveuser 4107
			}#if end
226 liveuser 4108
 
3 liveuser 4109
		#取得使用的參數
226 liveuser 4110
		$result["argu"]=$conf;
4111
 
3 liveuser 4112
		#檢查參數
4113
		#函式說明:
4114
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4115
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4116
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4117
		#$result["function"],當前執行的函式名稱.
4118
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4119
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4120
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4121
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
4122
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
4123
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4124
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4125
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4126
		#必填寫的參數:
4127
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4128
		$conf["variableCheck::checkArgument"]["varInput"]=&$conf;
4129
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4130
		$conf["variableCheck::checkArgument"]["mustBeFilledVariableName"]=array("path","fileArgu");
4131
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
4132
		$conf["variableCheck::checkArgument"]["mustBeFilledVariableType"]=array("string","string");
4133
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4134
		$conf["variableCheck::checkArgument"]["referenceVarKey"]="variableCheck::checkArgument";
4135
		#可以省略的參數:
4136
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4137
		$conf["variableCheck::checkArgument"]["canBeEmptyString"]="false";
4138
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
4139
		$conf["variableCheck::checkArgument"]["skipableVariableCanNotBeEmpty"]=array("haveFileName","dirPermission","web");
4140
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4141
		$conf["variableCheck::checkArgument"]["skipableVariableName"]=array("haveFileName","dirPermission","web");
226 liveuser 4142
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4143
		$conf["variableCheck::checkArgument"]["skipableVariableType"]=array("string","string","string");
4144
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4145
		$conf["variableCheck::checkArgument"]["skipableVarDefaultValue"]=array("false","0770","false");
4146
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4147
		#$conf["arrayCountEqualCheck"][]=array();
4148
		#參考資料來源:
4149
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4150
		$checkArgument=variableCheck::checkArguments($conf["variableCheck::checkArgument"]);
4151
		unset($conf["variableCheck::checkArgument"]);
226 liveuser 4152
 
3 liveuser 4153
		#如果檢查過程出錯
4154
		if($checkArgument["status"]==="false"){
226 liveuser 4155
 
3 liveuser 4156
			#設置執行失敗
4157
			$result["status"]="false";
226 liveuser 4158
 
3 liveuser 4159
			#設置執行錯誤訊息
4160
			$result["error"]=$checkArgument;
4161
 
4162
			#回傳結果
4163
			return $result;
226 liveuser 4164
 
3 liveuser 4165
			}#if end
226 liveuser 4166
 
3 liveuser 4167
		#如果檢查不通過
4168
		if($checkArgument["passed"]==="false"){
226 liveuser 4169
 
3 liveuser 4170
			#設置執行失敗
4171
			$result["status"]="false";
226 liveuser 4172
 
3 liveuser 4173
			#設置執行錯誤訊息
4174
			$result["error"]=$checkArgument;
4175
 
4176
			#回傳結果
4177
			return $result;
226 liveuser 4178
 
3 liveuser 4179
			}#if end
226 liveuser 4180
 
3 liveuser 4181
		#函式說明:
4182
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
4183
		#回傳結果:
4184
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
4185
		#$result["error"],錯誤訊息陣列.
226 liveuser 4186
		#$result["function"],函數名稱.
3 liveuser 4187
		#$result["argu"],使用的參數.
4188
		#$result["content"],網址,若是在命令列執行,則為"null".
4189
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
4190
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
4191
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
4192
		#必填參數:
4193
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
4194
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["path"];
4195
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
4196
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
4197
		#可省略參數:
4198
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
4199
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
4200
		#備註:
4201
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
4202
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 4203
		unset($conf["fileAccess::getInternetAddressV2"]);
4204
 
3 liveuser 4205
		#如果檢查過程出錯
4206
		if($getInternetAddressV2["status"]=="false"){
226 liveuser 4207
 
3 liveuser 4208
			#設置執行失敗
4209
			$result["status"]="false";
226 liveuser 4210
 
3 liveuser 4211
			#設置執行錯誤訊息
4212
			$result["error"]=$getInternetAddressV2;
4213
 
4214
			#回傳結果
4215
			return $result;
226 liveuser 4216
 
4217
			}#if end
4218
 
3 liveuser 4219
		#取得轉換好的絕對路徑
4220
		$result["path"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 4221
 
3 liveuser 4222
		#debug
4223
		#var_dump($getInternetAddressV2);exit;
226 liveuser 4224
 
3 liveuser 4225
		#如果 路徑 含有檔案名稱
4226
		if($conf["haveFileName"]==="true"){
226 liveuser 4227
 
3 liveuser 4228
			#預設要加回去的結束字串為空字串
4229
			$endStr="";
226 liveuser 4230
 
3 liveuser 4231
			#如果開頭跟結尾都是 "'"
4232
			if( strpos($result["path"],"'")===0 && strpos($result["path"],"'")===(strlen($result["path"])-1) ){
226 liveuser 4233
 
3 liveuser 4234
				#設置要加回去的結束字串
4235
				$endStr="'";
226 liveuser 4236
 
3 liveuser 4237
				}#if end
226 liveuser 4238
 
3 liveuser 4239
			#函式說明:
4240
			#將固定格式的字串分開,並回傳分開的結果。
4241
			#回傳結果:
4242
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4243
			#$result["error"],錯誤訊息陣列
4244
			#$result["function"],當前執行的函數名稱.
4245
			#$result["argu"],使用的參數.
4246
			#$result["oriStr"],要分割的原始字串內容
4247
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4248
			#$result["dataCounts"],爲總共分成幾段
4249
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
4250
			#必填參數:
4251
			#$conf["stringIn"],字串,要處理的字串.
4252
			$conf["stringProcess::spiltString"]["stringIn"]=$result["path"];
4253
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
4254
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
4255
			#可省略參數:
4256
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
4257
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
4258
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4259
			unset($conf["stringProcess::spiltString"]);
226 liveuser 4260
 
3 liveuser 4261
			#如果檢查過程出錯
4262
			if($spiltString["status"]==="false"){
226 liveuser 4263
 
3 liveuser 4264
				#設置執行失敗
4265
				$result["status"]="false";
226 liveuser 4266
 
3 liveuser 4267
				#設置執行錯誤訊息
4268
				$result["error"]=$spiltString;
4269
 
4270
				#回傳結果
4271
				return $result;
226 liveuser 4272
 
3 liveuser 4273
				}#if end
226 liveuser 4274
 
3 liveuser 4275
			#初始化儲存 path
4276
			$path="";
226 liveuser 4277
 
3 liveuser 4278
			#針對n-1段的內容
4279
			for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 4280
 
3 liveuser 4281
				#串接路徑
4282
				$path=$path."/".$spiltString["dataArray"][$i];
226 liveuser 4283
 
3 liveuser 4284
				}#for end
226 liveuser 4285
 
3 liveuser 4286
			#如果路徑為空
4287
			if($path===""){
226 liveuser 4288
 
3 liveuser 4289
				#則與設為根目錄
4290
				$path="/";
226 liveuser 4291
 
3 liveuser 4292
				}#if end
226 liveuser 4293
 
3 liveuser 4294
			#設置檔案名稱
4295
			$result["fileName"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 4296
 
3 liveuser 4297
			#取得不含檔案名稱的路徑
4298
			$conf["path"]=$path.$endStr;
226 liveuser 4299
 
3 liveuser 4300
			#取得不含檔案名稱的路徑
4301
			$result["path"]=$path.$endStr;
226 liveuser 4302
 
3 liveuser 4303
			}#if end
226 liveuser 4304
 
3 liveuser 4305
		#函式說明:
4306
		#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
4307
		#回傳結果:
4308
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
4309
		#$result["error"],錯誤訊息陣列
4310
		#必填參數:
4311
		$conf["fileAccess::createFolderAfterCheck"]["dirPositionAndName"]=$conf["path"];#新建的位置與名稱
4312
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4313
		$conf["fileAccess::createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
4314
		#可省略參數:
4315
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
4316
		$conf["fileAccess::createFolderAfterCheck"]["dirPermission"]=$conf["dirPermission"];
4317
		$conf["fileAccess::createFolderAfterCheck"]["web"]="false";
4318
		#參考資料:
4319
		#mkdir=>http://php.net/manual/en/function.mkdir.php
4320
		#chmod=>http://php.net/manual/en/function.chmod.php
4321
		$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf["fileAccess::createFolderAfterCheck"]);
4322
		unset($conf["fileAccess::createFolderAfterCheck"]);
226 liveuser 4323
 
3 liveuser 4324
		#如果建立路徑過程出錯
4325
		if($createFolderAfterCheck["status"]==="false"){
226 liveuser 4326
 
3 liveuser 4327
			#設置執行失敗
4328
			$result["status"]="false";
226 liveuser 4329
 
3 liveuser 4330
			#設置執行錯誤訊息
4331
			$result["error"]=$createFolderAfterCheck;
4332
 
4333
			#回傳結果
4334
			return $result;
226 liveuser 4335
 
3 liveuser 4336
			}#if end
226 liveuser 4337
 
3 liveuser 4338
		#如果有警告訊息
4339
		if(count($createFolderAfterCheck["warning"])>0){
226 liveuser 4340
 
3 liveuser 4341
			#取得警告訊息
4342
			$result["error"]=$createFolderAfterCheck["warning"];
226 liveuser 4343
 
3 liveuser 4344
			#設置執行失敗
4345
			$result["status"]="false";
226 liveuser 4346
 
3 liveuser 4347
			#回傳結果
4348
			return $result;
226 liveuser 4349
 
3 liveuser 4350
			}#if end
226 liveuser 4351
 
3 liveuser 4352
		#執行到這邊代表成功
4353
		$result["status"]="true";
226 liveuser 4354
 
3 liveuser 4355
		#回傳結果
4356
		return $result;
226 liveuser 4357
 
3 liveuser 4358
		}#function validatePath end
226 liveuser 4359
 
3 liveuser 4360
	/*
4361
	#函式說明:
4362
	#解析路徑的每個層級.
4363
	#回傳結果:
4364
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4365
	#$result["error"],錯誤訊息陣列.
4366
	#$resutl["function"],當前執行的涵式名稱.
4367
	#$result["argu"],使用的參數.
4368
	#$result["content"],解析出來的路徑階層.
4369
	#必填參數:
4370
	#$conf["path"],要檢查的路徑
4371
	$conf["path"]="";
4372
	#可省略參數:
4373
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4374
	#$conf["haveFileName"]="false";
4375
	#參考資料:
4376
	#無.
4377
	#備註:
4378
	#無.
4379
	*/
4380
	public static function parsePath(&$conf){
226 liveuser 4381
 
3 liveuser 4382
		#初始化要回傳的內容
4383
		$result=array();
4384
 
4385
		#取得當前執行的函數名稱
4386
		$result["function"]=__FUNCTION__;
4387
 
4388
		#如果 $conf 不為陣列
4389
		if(gettype($conf)!="array"){
226 liveuser 4390
 
3 liveuser 4391
			#設置執行失敗
4392
			$result["status"]="false";
226 liveuser 4393
 
3 liveuser 4394
			#設置執行錯誤訊息
4395
			$result["error"][]="\$conf變數須為陣列形態";
4396
 
4397
			#如果傳入的參數為 null
4398
			if($conf==null){
226 liveuser 4399
 
3 liveuser 4400
				#設置執行錯誤訊息
4401
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4402
 
3 liveuser 4403
				}#if end
4404
 
4405
			#回傳結果
4406
			return $result;
226 liveuser 4407
 
3 liveuser 4408
			}#if end
4409
 
4410
		#記錄使用的參數
4411
		$result["argu"]=$conf;
4412
 
4413
		#檢查參數
4414
		#函式說明:
4415
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4416
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4417
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4418
		#$result["function"],當前執行的函式名稱.
4419
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4420
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4421
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4422
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4423
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4424
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4425
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4426
		#必填寫的參數:
4427
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4428
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4429
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4430
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
226 liveuser 4431
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 4432
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
4433
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4434
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4435
		#可以省略的參數:
4436
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4437
		#$conf["canBeEmptyString"]="false";
4438
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4439
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("haveFileName");
226 liveuser 4440
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4441
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
4442
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4443
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
4444
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4445
		#$conf["arrayCountEqualCheck"][]=array();
4446
		#參考資料來源:
4447
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4448
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4449
		unset($conf["variableCheck::checkArguments"]);
4450
 
4451
		#如果檢查有誤
4452
		if($checkResult["status"]=="false"){
226 liveuser 4453
 
3 liveuser 4454
			#設置錯誤識別
4455
			$result["status"]="false";
226 liveuser 4456
 
3 liveuser 4457
			#設置錯誤訊息
4458
			$result["error"]=$checkResult;
226 liveuser 4459
 
3 liveuser 4460
			#回傳結果
4461
			return $result;
226 liveuser 4462
 
3 liveuser 4463
			}#if end
226 liveuser 4464
 
3 liveuser 4465
		#如果檢查不通過
4466
		if($checkResult["passed"]=="false"){
226 liveuser 4467
 
3 liveuser 4468
			#設置錯誤識別
4469
			$result["status"]="false";
226 liveuser 4470
 
3 liveuser 4471
			#設置錯誤訊息
4472
			$result["error"]=$checkResult;
226 liveuser 4473
 
3 liveuser 4474
			#回傳結果
4475
			return $result;
226 liveuser 4476
 
3 liveuser 4477
			}#if end
226 liveuser 4478
 
3 liveuser 4479
		#函式說明:
4480
		#將固定格式的字串分開,並回傳分開的結果.
4481
		#回傳結果:
4482
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4483
		#$result["error"],錯誤訊息陣列
4484
		#$result["function"],當前執行的函數名稱.
4485
		#$result["argu"],使用的參數.
4486
		#$result["oriStr"],要分割的原始字串內容
4487
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4488
		#$result["dataCounts"],爲總共分成幾段
4489
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
4490
		#必填參數:
4491
		#$conf["stringIn"],字串,要處理的字串.
4492
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["path"];
4493
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
4494
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
4495
		#可省略參數:
4496
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
4497
		#$conf["allowEmptyStr"]="false";
4498
		#參考資料:
4499
		#無.
4500
		#備註:
4501
		#無.
4502
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4503
		unset($conf["stringProcess::spiltString"]);
226 liveuser 4504
 
3 liveuser 4505
		#如果檢查有誤
4506
		if($spiltString["status"]==="false"){
226 liveuser 4507
 
3 liveuser 4508
			#設置錯誤識別
4509
			$result["status"]="false";
226 liveuser 4510
 
3 liveuser 4511
			#設置錯誤訊息
4512
			$result["error"]=$spiltString;
226 liveuser 4513
 
3 liveuser 4514
			#回傳結果
4515
			return $result;
226 liveuser 4516
 
3 liveuser 4517
			}#if end
226 liveuser 4518
 
3 liveuser 4519
		#確認是否為絕對路徑
4520
		#函式說明:
4521
		#取得符合特定字首與字尾的字串
4522
		#回傳結果:
4523
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
4524
		#$result["function"],當前執行的函數名稱.
4525
		#$result["error"],錯誤訊息陣列.
4526
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
4527
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
4528
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
4529
		#$result["argu"],使用的參數.
4530
		#必填參數:
4531
		#$conf["checkString"],字串,要檢查的字串.
4532
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["path"];
4533
		#可省略參數:
4534
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
4535
		$conf["search::getMeetConditionsString"]["frontWord"]="/";
4536
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
4537
		#$conf["search::getMeetConditionsString"]["tailWord"]="";
4538
		#參考資料:
4539
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
4540
		#備註:
4541
		#無.
4542
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
4543
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 4544
 
3 liveuser 4545
		#如果檢查有誤
4546
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 4547
 
3 liveuser 4548
			#設置錯誤識別
4549
			$result["status"]="false";
226 liveuser 4550
 
3 liveuser 4551
			#設置錯誤訊息
4552
			$result["error"]=$getMeetConditionsString;
226 liveuser 4553
 
3 liveuser 4554
			#回傳結果
4555
			return $result;
226 liveuser 4556
 
3 liveuser 4557
			}#if end
226 liveuser 4558
 
3 liveuser 4559
		#如果是絕對路徑
4560
		if($getMeetConditionsString["founded"]==="true"){
226 liveuser 4561
 
3 liveuser 4562
			#初始化路徑為 "/"
4563
			$result["content"][]="/";
226 liveuser 4564
 
3 liveuser 4565
			}#if end
226 liveuser 4566
 
3 liveuser 4567
		#針對每個切割出來的路徑階層
4568
		foreach($spiltString["dataArray"] as $index => $dir){
226 liveuser 4569
 
3 liveuser 4570
			#如果路徑結尾含有檔案名稱
4571
			if($conf["haveFileName"]==="true"){
226 liveuser 4572
 
3 liveuser 4573
				#如果是最後一段
4574
				if($index===$spiltString["dataCounts"]-1){
226 liveuser 4575
 
3 liveuser 4576
					#忽略
4577
					continue;
226 liveuser 4578
 
3 liveuser 4579
					}#if end
226 liveuser 4580
 
3 liveuser 4581
				}#if end
226 liveuser 4582
 
3 liveuser 4583
			#後面加上 資料夾名稱 跟 "/"
4584
			$newPath=$dir."/";
226 liveuser 4585
 
3 liveuser 4586
			#如果有 content
4587
			if(isset($result["content"])){
226 liveuser 4588
 
3 liveuser 4589
				#如果有上個資料夾
4590
				if(isset($result["content"][count($result["content"])-1])){
226 liveuser 4591
 
3 liveuser 4592
					#後面加上 上個資料夾名稱 加上資料夾名稱 跟 "/"
4593
					$newPath=$result["content"][count($result["content"])-1].$dir."/";
226 liveuser 4594
 
3 liveuser 4595
					}#if end
226 liveuser 4596
 
3 liveuser 4597
				}#if end
226 liveuser 4598
 
3 liveuser 4599
			#並新增置結果
4600
			$result["content"][]=$newPath;
226 liveuser 4601
 
3 liveuser 4602
			}#foreach end
226 liveuser 4603
 
3 liveuser 4604
		#var_dump($result["content"]);
226 liveuser 4605
 
3 liveuser 4606
		#設置執行正常
4607
		$result["status"]="true";
226 liveuser 4608
 
3 liveuser 4609
		#回傳結果
4610
		return $result;
226 liveuser 4611
 
3 liveuser 4612
		}#function parsePath end
226 liveuser 4613
 
3 liveuser 4614
	/*
4615
	#函式說明:
4616
	#檢查路徑是否存在.
4617
	#回傳結果:
4618
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4619
	#$result["error"],錯誤訊息陣列.
4620
	#$resutl["function"],當前執行的涵式名稱.
4621
	#$result["argu"],使用的參數.
4622
	#$result["found"],路徑是否存在,"true"代表存在,"false"代表不存在.
4623
	#$result["content"],每個階層路徑的檢查結果,每個元素有檢查的路徑"path"跟是否有存在或可存取的識別"found".
4624
	#必填參數:
4625
	#$conf["path"],要檢查的路徑
4626
	$conf["path"]="";
4627
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4628
	$conf["fileArgu"]=__FILE__;
4629
	#可省略參數:
4630
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4631
	#$conf["haveFileName"]="false";
4632
	#參考資料:
4633
	#無.
4634
	#備註:
4635
	#無.
4636
	*/
4637
	public static function checkPathExist(&$conf){
226 liveuser 4638
 
3 liveuser 4639
		#初始化要回傳的內容
4640
		$result=array();
4641
 
4642
		#取得當前執行的函數名稱
4643
		$result["function"]=__FUNCTION__;
4644
 
4645
		#如果 $conf 不為陣列
4646
		if(gettype($conf)!="array"){
226 liveuser 4647
 
3 liveuser 4648
			#設置執行失敗
4649
			$result["status"]="false";
226 liveuser 4650
 
3 liveuser 4651
			#設置執行錯誤訊息
4652
			$result["error"][]="\$conf變數須為陣列形態";
4653
 
4654
			#如果傳入的參數為 null
4655
			if($conf==null){
226 liveuser 4656
 
3 liveuser 4657
				#設置執行錯誤訊息
4658
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4659
 
3 liveuser 4660
				}#if end
4661
 
4662
			#回傳結果
4663
			return $result;
226 liveuser 4664
 
3 liveuser 4665
			}#if end
4666
 
4667
		#記錄使用的參數
4668
		$result["argu"]=$conf;
4669
 
4670
		#檢查參數
4671
		#函式說明:
4672
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4673
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4674
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4675
		#$result["function"],當前執行的函式名稱.
4676
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4677
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4678
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4679
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4680
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4681
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4682
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4683
		#必填寫的參數:
4684
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4685
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4686
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4687
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 4688
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 4689
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
4690
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4691
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4692
		#可以省略的參數:
4693
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4694
		#$conf["canBeEmptyString"]="false";
4695
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4696
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("haveFileName");
226 liveuser 4697
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4698
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
4699
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4700
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
4701
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4702
		#$conf["arrayCountEqualCheck"][]=array();
4703
		#參考資料來源:
4704
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4705
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4706
		unset($conf["variableCheck::checkArguments"]);
4707
 
4708
		#如果檢查有誤
4709
		if($checkResult["status"]=="false"){
226 liveuser 4710
 
3 liveuser 4711
			#設置錯誤識別
4712
			$result["status"]="false";
226 liveuser 4713
 
3 liveuser 4714
			#設置錯誤訊息
4715
			$result["error"]=$checkResult;
226 liveuser 4716
 
3 liveuser 4717
			#回傳結果
4718
			return $result;
226 liveuser 4719
 
3 liveuser 4720
			}#if end
226 liveuser 4721
 
3 liveuser 4722
		#如果檢查不通過
4723
		if($checkResult["passed"]=="false"){
226 liveuser 4724
 
3 liveuser 4725
			#設置錯誤識別
4726
			$result["status"]="false";
226 liveuser 4727
 
3 liveuser 4728
			#設置錯誤訊息
4729
			$result["error"]=$checkResult;
226 liveuser 4730
 
3 liveuser 4731
			#回傳結果
4732
			return $result;
226 liveuser 4733
 
3 liveuser 4734
			}#if end
226 liveuser 4735
 
3 liveuser 4736
		#函式說明:
4737
		#解析路徑的每個層級.
4738
		#回傳結果:
4739
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4740
		#$result["error"],錯誤訊息陣列.
4741
		#$resutl["function"],當前執行的涵式名稱.
4742
		#$result["argu"],使用的參數.
4743
		#$result["content"],解析出來的路徑階層.
4744
		#必填參數:
4745
		#$conf["path"],要檢查的路徑
4746
		$conf["fileAccess::parsePath"]["path"]=$conf["path"];
4747
		#可省略參數:
4748
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4749
		$conf["fileAccess::parsePath"]["haveFileName"]=$conf["haveFileName"];
4750
		#參考資料:
4751
		#無.
4752
		#備註:
4753
		#無.
4754
		$parsePath=fileAccess::parsePath($conf["fileAccess::parsePath"]);
4755
		unset($conf["fileAccess::parsePath"]);
226 liveuser 4756
 
3 liveuser 4757
		#如果檢查有誤
4758
		if($parsePath["status"]==="false"){
226 liveuser 4759
 
3 liveuser 4760
			#設置錯誤識別
4761
			$result["status"]="false";
226 liveuser 4762
 
3 liveuser 4763
			#設置錯誤訊息
4764
			$result["error"]=$parsePath;
226 liveuser 4765
 
3 liveuser 4766
			#回傳結果
4767
			return $result;
226 liveuser 4768
 
3 liveuser 4769
			}#if end
226 liveuser 4770
 
3 liveuser 4771
		#函式說明:
4772
		#檢查多個檔案與資料夾是否存在.
4773
		#回傳的結果:
4774
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4775
		#$result["error"],錯誤訊息陣列.
4776
		#$resutl["function"],當前執行的涵式名稱.
4777
		#$result["argu"],使用的參數.
4778
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
4779
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
4780
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
4781
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
4782
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
4783
		#必填參數:
4784
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
4785
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$parsePath["content"];
4786
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4787
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
4788
		#可省略參數:
4789
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
4790
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
4791
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
4792
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
4793
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
4794
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
4795
		#參考資料:
4796
		#http://php.net/manual/en/function.file-exists.php
4797
		#http://php.net/manual/en/control-structures.foreach.php
4798
		#備註:
4799
		#函數file_exists檢查的路徑為檔案系統的路徑
4800
		#$result["varName"][$i]結果未實作
4801
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
4802
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 4803
 
3 liveuser 4804
		#如果執行異常
4805
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 4806
 
3 liveuser 4807
			#設置錯誤識別
4808
			$result["status"]="false";
226 liveuser 4809
 
3 liveuser 4810
			#設置錯誤訊息
4811
			$result["error"]=$checkMultiFileExist;
226 liveuser 4812
 
3 liveuser 4813
			#回傳結果
4814
			return $result;
226 liveuser 4815
 
3 liveuser 4816
			}#if end
226 liveuser 4817
 
3 liveuser 4818
		#如果有路徑無法存取
4819
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 4820
 
3 liveuser 4821
			#設置執行正常識別
4822
			$result["status"]="true";
226 liveuser 4823
 
3 liveuser 4824
			#設置路徑找不到
4825
			$result["found"]="false";
226 liveuser 4826
 
3 liveuser 4827
			#針對每個路徑的搜尋結果
4828
			foreach($checkMultiFileExist["varExist"] as $index => $found){
226 liveuser 4829
 
3 liveuser 4830
				#設置路徑尋找結果
4831
				$result["content"][]=array("found"=>$found,"path"=>$checkMultiFileExist["varNameFullPath"][$index]);
226 liveuser 4832
 
3 liveuser 4833
				}#foreach end
226 liveuser 4834
 
3 liveuser 4835
			#回傳結果
4836
			return $result;
226 liveuser 4837
 
3 liveuser 4838
			}#if end
226 liveuser 4839
 
3 liveuser 4840
		#設置路徑有找到
4841
		$result["found"]="true";
226 liveuser 4842
 
3 liveuser 4843
		#設置執行正常識別
4844
		$result["status"]="true";
226 liveuser 4845
 
3 liveuser 4846
		#回傳結果
4847
		return $result;
226 liveuser 4848
 
3 liveuser 4849
		}#function checkPathExist end
226 liveuser 4850
 
4851
	/*
3 liveuser 4852
	#函式說明:
4853
	#demo建立pdf檔
4854
	#必填參數:
4855
	#無
4856
	#可省略參數:
4857
	#無
4858
	#參考資料:
4859
	#tcpdf=>http://www.tcpdf.org/examples.php
4860
	#備註:
4861
	#開發中,需要安裝 php-tcpdf 套件.
4862
	*/
4863
	public static function demoCreateTcPdfFile(){
226 liveuser 4864
 
3 liveuser 4865
		#避免 TCPDF ERROR: Some data has already been output, can't send PDF file 錯誤產生
4866
		ob_end_clean();
226 liveuser 4867
 
3 liveuser 4868
		#create new PDF document
4869
		$pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
226 liveuser 4870
 
3 liveuser 4871
		#set document information
4872
		$pdf->SetCreator(PDF_CREATOR);
4873
		$pdf->SetAuthor('qbpwc');
4874
		$pdf->SetTitle('pdf sample title');
4875
		$pdf->SetSubject('pdf sample subject');
4876
		$pdf->SetKeywords('pdf, sample, tcpdf, qbpwc');
226 liveuser 4877
 
3 liveuser 4878
		#set default header data
4879
		$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
4880
		$pdf->setFooterData(array(0,64,0), array(0,64,128));
226 liveuser 4881
 
3 liveuser 4882
		#set header and footer fonts
4883
		$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
4884
		$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
226 liveuser 4885
 
3 liveuser 4886
		#set default monospaced font
4887
		$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
226 liveuser 4888
 
3 liveuser 4889
		#set margins
4890
		$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
4891
		$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
4892
		$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
4893
 
4894
		#set auto page breaks
4895
		$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
4896
 
4897
		#set image scale factor
4898
		$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
4899
 
4900
		#set some language-dependent strings (optional)
4901
		if (@file_exists(dirname(__FILE__).'/lang/eng.php')){
226 liveuser 4902
 
3 liveuser 4903
			require_once(dirname(__FILE__).'/lang/eng.php');
226 liveuser 4904
 
3 liveuser 4905
			$pdf->setLanguageArray($l);
226 liveuser 4906
 
3 liveuser 4907
			}#if end
226 liveuser 4908
 
3 liveuser 4909
		#set default font subsetting mode
4910
		$pdf->setFontSubsetting(true);
226 liveuser 4911
 
3 liveuser 4912
		#Set font
4913
		#dejavusans is a UTF-8 Unicode font, if you only need to
4914
		#print standard ASCII chars, you can use core fonts like
4915
		#helvetica or times to reduce file size.
4916
		$pdf->SetFont('dejavusans', '', 14, '', true);
226 liveuser 4917
 
3 liveuser 4918
		#Add a page
4919
		#This method has several options, check the source code documentation for more information.
4920
		$pdf->AddPage();
226 liveuser 4921
 
3 liveuser 4922
		#set text shadow effect
4923
		$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 4924
 
3 liveuser 4925
		#Set some content to print
4926
		$html="<h5>Hello World!</h5>";
226 liveuser 4927
 
3 liveuser 4928
		// Print text using writeHTMLCell()
4929
		$pdf->writeHTMLCell(0,0,'','',$html,0,1,0,true,'',true);
4930
 
4931
		// Close and output PDF document
4932
		// This method has several options, check the source code documentation for more information.
4933
		$pdf->Output('fileAccessT/example_001.pdf','I');
226 liveuser 4934
 
3 liveuser 4935
		}#function demoCreateTcPdfFile end
226 liveuser 4936
 
3 liveuser 4937
	/*
4938
	#函式說明:
4939
	#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
4940
	#回傳的結果:
4941
	#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
4942
	#$result["error"],錯誤訊息.
4943
	#$result["function"],當前執行的函式名稱.
4944
	#$result["filePath"],路徑字串.
4945
	#$result["fileName"],檔案名稱字串.
4946
	#$result["fileExtention"],檔案的副檔名.
4947
	#$result["fullFileName"],含副檔名的檔案名稱.
4948
	#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
4949
	#必填參數:
4950
	#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
4951
	$conf["fileAddressAndName"]="";
4952
	#可省略參數:
4953
	#無.
4954
	#參考資料:
4955
	#無.
4956
	#備註:
4957
	#無.
4958
	*/
4959
	public static function getFileAddressAndNameAndFileExtention(&$conf){
226 liveuser 4960
 
3 liveuser 4961
		#初始化要回傳的參數
4962
		$result=array();
226 liveuser 4963
 
3 liveuser 4964
		#取得當前執行函數名稱
4965
		$result["function"]=__FUNCTION__;
4966
 
4967
		#如果 $conf 不為陣列
4968
		if(gettype($conf)!="array"){
226 liveuser 4969
 
3 liveuser 4970
			#設置執行失敗
4971
			$result["status"]="false";
226 liveuser 4972
 
3 liveuser 4973
			#設置執行錯誤訊息
4974
			$result["error"][]="\$conf變數須為陣列形態";
4975
 
4976
			#如果傳入的參數為 null
4977
			if($conf==null){
226 liveuser 4978
 
3 liveuser 4979
				#設置執行錯誤訊息
4980
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4981
 
3 liveuser 4982
				}#if end
4983
 
4984
			#回傳結果
4985
			return $result;
226 liveuser 4986
 
3 liveuser 4987
			}#if end
4988
 
4989
		#檢查參數
4990
		#函式說明:
4991
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4992
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4993
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4994
		#$result["function"],當前執行的函式名稱.
4995
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4996
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4997
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4998
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4999
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5000
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5001
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5002
		#必填寫的參數:
5003
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5004
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5005
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5006
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileAddressAndName");
226 liveuser 5007
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5008
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5009
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5010
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5011
		#可以省略的參數:
5012
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5013
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5014
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5015
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("outputAddress","noDownload");
226 liveuser 5016
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5017
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
5018
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5019
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".bin/".$conf["cppAddress"].".bin","true");
5020
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5021
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
5022
		#參考資料來源:
5023
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5024
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5025
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5026
 
3 liveuser 5027
		#如果 $checkArguments["status"] 等於 "false"
5028
		if($checkArguments["status"]=="false"){
226 liveuser 5029
 
3 liveuser 5030
			#設置 $result["status"] 為 "false"
5031
			$result["status"]="false";
226 liveuser 5032
 
3 liveuser 5033
			#設置 $result["error"]
5034
			$result["error"]=$checkArguments;
226 liveuser 5035
 
3 liveuser 5036
			#回傳結果
5037
			return $result;
226 liveuser 5038
 
3 liveuser 5039
			}#if end
226 liveuser 5040
 
3 liveuser 5041
		#如果 $checkArguments["passed"] 等於 "false"
5042
		if($checkArguments["passed"]=="false"){
226 liveuser 5043
 
3 liveuser 5044
			#設置 $result["status"] 為 "false"
5045
			$result["status"]="false";
226 liveuser 5046
 
3 liveuser 5047
			#設置 $result["error"]
5048
			$result["error"]=$checkArguments;
226 liveuser 5049
 
3 liveuser 5050
			#回傳結果
5051
			return $result;
226 liveuser 5052
 
3 liveuser 5053
			}#if end
226 liveuser 5054
 
3 liveuser 5055
		#確認路徑是否為絕對路徑
5056
		#函式說明:
5057
		#取得符合特定字首與字尾的字串
5058
		#回傳結果:
5059
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
5060
		#$result["function"],當前執行的函數名稱.
5061
		#$result["error"],錯誤訊息陣列.
5062
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
5063
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
5064
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
5065
		#$result["argu"],使用的參數.
5066
		#必填參數:
5067
		#$conf["checkString"],字串,要檢查的字串.
5068
		$conf["fileAccess::getMeetConditionsString"]["checkString"]=$conf["fileAddressAndName"];
5069
		#可省略參數:
5070
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
5071
		$conf["fileAccess::getMeetConditionsString"]["frontWord"]="/";
5072
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
5073
		#$conf["tailWord"]="";
5074
		#參考資料:
5075
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
5076
		#備註:
5077
		#無.
5078
		$getMeetConditionsString=search::getMeetConditionsString($conf["fileAccess::getMeetConditionsString"]);
5079
		unset($conf["fileAccess::getMeetConditionsString"]);
226 liveuser 5080
 
3 liveuser 5081
		#如果執行出錯
5082
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 5083
 
3 liveuser 5084
			#設置錯誤識別
5085
			$result["status"]="false";
226 liveuser 5086
 
3 liveuser 5087
			#設置錯誤訊息
5088
			$result["error"]=$getMeetConditionsString;
226 liveuser 5089
 
3 liveuser 5090
			#回傳結果
5091
			return $result;
226 liveuser 5092
 
3 liveuser 5093
			}#if end
226 liveuser 5094
 
3 liveuser 5095
		#預設參數 $conf["fileAddressAndName"] 不為 "/" 開始
5096
		$fileAddressAndNameStarFromRoot="true";
226 liveuser 5097
 
3 liveuser 5098
		#如果是 "/" 開頭
5099
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 5100
 
3 liveuser 5101
			#設置參數 $conf["fileAddressAndName"] 為 "/" 開始
5102
			$fileAddressAndNameStarFromRoot="true";
226 liveuser 5103
 
3 liveuser 5104
			}#if end
226 liveuser 5105
 
5106
		#檢查是否有路徑資訊
3 liveuser 5107
		#函式說明:
5108
		#將固定格式的字串分開,並回傳分開的結果。
5109
		#回傳的參數:
5110
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5111
		#$result["error"],錯誤訊息陣列
5112
		#$result["oriStr"],要分割的原始字串內容
5113
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5114
		#$result["dataCounts"],爲總共分成幾段
5115
		#必填參數:
5116
		$conf["stringProcess"]["spiltString"]["stringIn"]=$conf["fileAddressAndName"];#要處理的字串。
5117
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
5118
		$spiledResult=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5119
		unset($conf["stringProcess"]["spiltString"]);
226 liveuser 5120
 
3 liveuser 5121
		#如果 $spiledResult["status"] 等於 "false"
5122
		if($spiledResult["status"]==="false"){
226 liveuser 5123
 
3 liveuser 5124
			#設置錯誤識別
5125
			$result["status"]="false";
226 liveuser 5126
 
3 liveuser 5127
			#設置錯誤訊息
5128
			$result["error"]=$spiledResult;
226 liveuser 5129
 
3 liveuser 5130
			#回傳結果
5131
			return $result;
226 liveuser 5132
 
3 liveuser 5133
			}#if end
226 liveuser 5134
 
3 liveuser 5135
		#如果 $spiledResult["dataCounts"] 大於 1
5136
		if($spiledResult["dataCounts"]>1){
226 liveuser 5137
 
3 liveuser 5138
			#代表有路徑字串
226 liveuser 5139
 
3 liveuser 5140
			#初始化路徑字串暫存變數
5141
			$tempPathStr="";
226 liveuser 5142
 
3 liveuser 5143
			#如果是絕對路徑
5144
			if($fileAddressAndNameStarFromRoot==="true"){
226 liveuser 5145
 
3 liveuser 5146
				#加上根目錄
5147
				$tempPathStr=$tempPathStr."/";
226 liveuser 5148
 
3 liveuser 5149
				}#if end
226 liveuser 5150
 
3 liveuser 5151
			#取得路徑字串
5152
			for($i=0;$i<$spiledResult["dataCounts"]-1;$i++){
226 liveuser 5153
 
3 liveuser 5154
				#串連片段路徑字串
5155
				$tempPathStr=$tempPathStr.$spiledResult["dataArray"][$i]."/";
226 liveuser 5156
 
3 liveuser 5157
				}#for end
226 liveuser 5158
 
3 liveuser 5159
			#取得檔案的路徑
5160
			$result["filePath"]=$tempPathStr;
226 liveuser 5161
 
3 liveuser 5162
			}#if end
226 liveuser 5163
 
3 liveuser 5164
		#反之 $spiledResult["dataCounts"] 等於 1
5165
		else{
226 liveuser 5166
 
3 liveuser 5167
			#檔案的路徑設為""
5168
			$result["filePath"]="";
226 liveuser 5169
 
3 liveuser 5170
			}#else end
226 liveuser 5171
 
3 liveuser 5172
		#取得檔案名稱(含副檔名)
5173
		$result["fullFileName"]=$spiledResult["dataArray"][$spiledResult["dataCounts"]-1];
226 liveuser 5174
 
3 liveuser 5175
		#取得副檔名
5176
		#函式說明:
5177
		#將固定格式的字串分開,並回傳分開的結果。
5178
		#回傳的參數:
5179
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5180
		#$result["error"],錯誤訊息陣列
5181
		#$result["oriStr"],要分割的原始字串內容
5182
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5183
		#$result["dataCounts"],爲總共分成幾段
5184
		#必填參數:
5185
		$conf["stringProcess"]["spiltString"]["stringIn"]=$result["fullFileName"];#要處理的字串。
5186
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
5187
		$spiledResult=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5188
		unset($conf["stringProcess"]["spiltString"]);
226 liveuser 5189
 
3 liveuser 5190
		#如果 $spiledResult["status"] 等於 "false"
5191
		if($spiledResult["status"]=="false"){
226 liveuser 5192
 
3 liveuser 5193
			#設置錯誤識別
5194
			$result["status"]="false";
226 liveuser 5195
 
3 liveuser 5196
			#設置錯誤訊息
5197
			$result["error"]=$spiledResult;
226 liveuser 5198
 
3 liveuser 5199
			#回傳結果
5200
			return $result;
226 liveuser 5201
 
3 liveuser 5202
			}#if end
226 liveuser 5203
 
3 liveuser 5204
		#如果 $spiledResult["dataCounts"] 大於 1
5205
		if($spiledResult["dataCounts"]>1){
226 liveuser 5206
 
3 liveuser 5207
			#代表有副檔名
226 liveuser 5208
 
3 liveuser 5209
			#初始化檔名字串暫存變數
5210
			$tempFileNameStr="";
226 liveuser 5211
 
3 liveuser 5212
			#取得路徑字串
5213
			for($i=0;$i<$spiledResult["dataCounts"]-1;$i++){
226 liveuser 5214
 
3 liveuser 5215
				#如果是最後一個小黑點前面的字串片段
5216
				if($i==$spiledResult["dataCounts"]-2){
226 liveuser 5217
 
3 liveuser 5218
					#串連片段路徑字串
5219
					$tempFileNameStr=$tempFileNameStr.$spiledResult["dataArray"][$i];
226 liveuser 5220
 
3 liveuser 5221
					}#if end
226 liveuser 5222
 
3 liveuser 5223
				#反之不是最後一個小黑點前面的字串片段
5224
				else{
226 liveuser 5225
 
3 liveuser 5226
					#串連片段路徑字串(含小黑點)
5227
					$tempFileNameStr=$tempFileNameStr.$spiledResult["dataArray"][$i].".";
226 liveuser 5228
 
3 liveuser 5229
					}#else end
226 liveuser 5230
 
3 liveuser 5231
				}#for end
226 liveuser 5232
 
3 liveuser 5233
			#取得檔名
5234
			$result["fileName"]=$tempFileNameStr;
226 liveuser 5235
 
3 liveuser 5236
			#取得副檔名
5237
			$result["fileExtention"]=$spiledResult["dataArray"][$spiledResult["dataCounts"]-1];
226 liveuser 5238
 
3 liveuser 5239
			}#if end
226 liveuser 5240
 
3 liveuser 5241
		#反之 $spiledResult["dataCounts"] 等於 1
5242
		else{
226 liveuser 5243
 
3 liveuser 5244
			#檔案的副檔名設為""
5245
			$result["fileExtention"]="";
226 liveuser 5246
 
3 liveuser 5247
			#取得檔案的名稱
5248
			$result["fileName"]=$spiledResult["dataArray"][0];
226 liveuser 5249
 
3 liveuser 5250
			}#else end
226 liveuser 5251
 
3 liveuser 5252
		#如果 $result["fileExtention"] 不等於 ""
5253
		if($result["fileExtention"]!=""){
226 liveuser 5254
 
3 liveuser 5255
			#將副檔名用小黑點跟檔案名稱連在一塊
5256
			$result["fullFileName"]=$result["fileName"].".".$result["fileExtention"];
226 liveuser 5257
 
3 liveuser 5258
			}#if end
226 liveuser 5259
 
3 liveuser 5260
		#反之代表沒有副檔名
5261
		else{
226 liveuser 5262
 
3 liveuser 5263
			#取得含副檔名的檔案名稱
5264
			$result["fullFileName"]=$result["fileName"].$result["fileExtention"];
226 liveuser 5265
 
3 liveuser 5266
			}#else end
226 liveuser 5267
 
3 liveuser 5268
		#完整的檔案路徑(含副檔名).
5269
		$result["fullFilePathAndName"]=$result["filePath"].$result["fullFileName"];
226 liveuser 5270
 
3 liveuser 5271
		#設置執行正常的識別
5272
		$result["status"]="true";
226 liveuser 5273
 
3 liveuser 5274
		#回傳結果
5275
		return $result;
226 liveuser 5276
 
3 liveuser 5277
		}#funciton getFileAddressAndNameAndFileExtention end
5278
 
5279
	/*
5280
	#函式說明:
5281
	#將資料夾或檔案打包成tar檔案
5282
	#回傳結果:
5283
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5284
	#$result["function"],當前執行的函數名稱
5285
	#$result["error"],錯誤訊息.
5286
	#$result["content"],檔案輸出後的位置與名稱.
5287
	#必填參數:
5288
	#$conf["packetTarget"],陣列,要打包的每個資料夾與檔案位置
5289
	$conf["packetTarget"]=array("");
5290
	#$conf["createdTarFile"],字串,打包好的檔案要放在哪裡,副檔名.tar會自動加上.
5291
	$conf["createdTarFile"]="";
5292
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5293
	$conf["fileArgu"]=__FILE__;
5294
	#可省略參數:
5295
	#無.
5296
	#參考資料:
5297
	#無.
5298
	#備註:
5299
	#無.
5300
	*/
5301
	public static function makeTarFile(&$conf){
226 liveuser 5302
 
3 liveuser 5303
		#初始化要回傳的內容
5304
		$result=array();
226 liveuser 5305
 
3 liveuser 5306
		#記錄當前執行的函數名稱
5307
		$result["function"]=__FUNCTION__;
226 liveuser 5308
 
3 liveuser 5309
		#如果 $conf 不為陣列
5310
		if(gettype($conf)!="array"){
226 liveuser 5311
 
3 liveuser 5312
			#設置執行失敗
5313
			$result["status"]="false";
226 liveuser 5314
 
3 liveuser 5315
			#設置執行錯誤訊息
5316
			$result["error"][]="\$conf變數須為陣列形態";
5317
 
5318
			#如果傳入的參數為 null
5319
			if($conf==null){
226 liveuser 5320
 
3 liveuser 5321
				#設置執行錯誤訊息
5322
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5323
 
3 liveuser 5324
				}#if end
5325
 
5326
			#回傳結果
5327
			return $result;
226 liveuser 5328
 
3 liveuser 5329
			}#if end
226 liveuser 5330
 
3 liveuser 5331
		#檢查參數
5332
		#函式說明:
5333
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5334
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5335
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5336
		#$result["function"],當前執行的函式名稱.
5337
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5338
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5339
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5340
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5341
		#必填寫的參數:
5342
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5343
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5344
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5345
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","packetTarget","createdTarFile");
226 liveuser 5346
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5347
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
5348
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5349
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5350
		#可以省略的參數:
5351
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5352
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5353
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5354
		#$conf["skipableVariableName"]=array();
226 liveuser 5355
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5356
		#$conf["skipableVariableType"]=array();
5357
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5358
		#$conf["skipableVarDefaultValue"]=array("");
5359
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5360
		#$conf["arrayCountEqualCheck"][]=array();
5361
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5362
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5363
 
3 liveuser 5364
		#若檢查失敗
5365
		if($checkResult["status"]=="false"){
226 liveuser 5366
 
3 liveuser 5367
			#設置執行失敗
5368
			$result["status"]="false";
226 liveuser 5369
 
3 liveuser 5370
			#設置執行錯誤訊息
5371
			$result["error"]=$checkResult;
226 liveuser 5372
 
3 liveuser 5373
			#回傳結果
5374
			return $result;
226 liveuser 5375
 
3 liveuser 5376
			}#if end
226 liveuser 5377
 
3 liveuser 5378
		#若檢查不通過
5379
		if($checkResult["passed"]=="false"){
226 liveuser 5380
 
3 liveuser 5381
			#設置執行失敗
5382
			$result["status"]="false";
226 liveuser 5383
 
3 liveuser 5384
			#設置執行錯誤訊息
5385
			$result["error"]=$checkResult;
226 liveuser 5386
 
3 liveuser 5387
			#回傳結果
5388
			return $result;
226 liveuser 5389
 
3 liveuser 5390
			}#if end
226 liveuser 5391
 
3 liveuser 5392
		#初始化打包要用的tar指令參數
5393
		$paramsArray=array("-cvf",$conf["createdTarFile"].".tar");
226 liveuser 5394
 
3 liveuser 5395
		#檢查要打包的檔案是否存在
5396
		#函式說明:
5397
		#檢查多個檔案與資料夾是否存在.
5398
		#回傳的結果:
5399
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5400
		#$result["error"],錯誤訊息陣列.
5401
		#$resutl["function"],當前執行的涵式名稱.
5402
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
5403
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
5404
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
5405
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
5406
		#必填參數:
5407
		#$conf["fileArray"],陣列字串,要檢查書否存在的檔案有哪些,須爲一維陣列數值。
5408
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$conf["packetTarget"];
5409
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5410
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
5411
		#可省略參數
5412
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
5413
		#$conf["disableWebSearch"]="false";
5414
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5415
		#$conf["userDir"]="true";
5416
		#參考資料來源:
5417
		#http://php.net/manual/en/function.file-exists.php
5418
		#http://php.net/manual/en/control-structures.foreach.php
5419
		#備註:
5420
		#函數file_exists檢查的路徑為檔案系統的路徑
5421
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
5422
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 5423
 
3 liveuser 5424
		#如果檢查要打包的檔案失敗
5425
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 5426
 
3 liveuser 5427
			#設置執行失敗
5428
			$result["status"]="false";
226 liveuser 5429
 
3 liveuser 5430
			#設置執行錯誤訊息
5431
			$result["error"]=$checkMultiFileExist;
226 liveuser 5432
 
3 liveuser 5433
			#回傳結果
5434
			return $result;
226 liveuser 5435
 
3 liveuser 5436
			}#if end
226 liveuser 5437
 
3 liveuser 5438
		#如果要打包的檔案有缺
5439
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 5440
 
3 liveuser 5441
			#設置執行失敗
5442
			$result["status"]="false";
226 liveuser 5443
 
3 liveuser 5444
			#設置執行錯誤訊息
5445
			$result["error"]=$checkMultiFileExist;
226 liveuser 5446
 
3 liveuser 5447
			#回傳結果
5448
			return $result;
226 liveuser 5449
 
3 liveuser 5450
			}#if end
226 liveuser 5451
 
3 liveuser 5452
		#有幾個要打包的目標就執行幾次
5453
		for($i=0;$i<count($conf["packetTarget"]);$i++){
226 liveuser 5454
 
3 liveuser 5455
			#串接上要打包的檔案或資料夾
5456
			$paramsArray[]=$conf["packetTarget"][$i];
226 liveuser 5457
 
3 liveuser 5458
			}#for end
226 liveuser 5459
 
3 liveuser 5460
		#函式說明:
5461
		#呼叫shell執行系統命令,並取得回傳的內容.
5462
		#回傳結果:
5463
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5464
		#$result["error"],錯誤訊息陣列.
5465
		#$result["function"],當前執行的函數名稱.
5466
		#$result["argu"],使用的參數.
5467
		#$result["cmd"],執行的指令內容.
5468
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
5469
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
5470
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
5471
		#$result["running"],是否還在執行.
5472
		#$result["pid"],pid.
5473
		#$result["statusCode"],執行結束後的代碼.
5474
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
5475
		#必填參數:
5476
		#$conf["command"],字串,要執行的指令.
5477
		$conf["external::callShell"]["command"]="tar";
5478
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5479
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5480
		#可省略參數:
5481
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5482
		$conf["external::callShell"]["argu"]=$paramsArray;
5483
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
5484
		#$conf["arguIsAddr"]=array();
5485
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
5486
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
5487
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
5488
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5489
		#$conf["enablePrintDescription"]="true";
5490
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
5491
		#$conf["printDescription"]="";
5492
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
5493
		$conf["external::callShell"]["escapeshellarg"]="true";
5494
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
5495
		#$conf["thereIsShellVar"]=array();
5496
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
5497
		#$conf["username"]="";
5498
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
5499
		#$conf["password"]="";
5500
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
5501
		#$conf["useScript"]="";
5502
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
5503
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
5504
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
5505
		#$conf["inBackGround"]="";
5506
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
5507
		#$conf["getErr"]="false";
5508
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
5509
		#$conf["doNotRun"]="false";
5510
		#參考資料:
5511
		#exec=>http://php.net/manual/en/function.exec.php
5512
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
5513
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
5514
		#備註:
5515
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
5516
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
5517
		$conf["external::callShell"]=external::callShell($conf["external::callShell"]);
5518
		unset($conf["external::callShell"]);
226 liveuser 5519
 
3 liveuser 5520
		#如果執行shell失敗
5521
		if($callShell["status"]=="false"){
226 liveuser 5522
 
3 liveuser 5523
			#設置執行失敗
5524
			$result["status"]="false";
226 liveuser 5525
 
3 liveuser 5526
			#設置執行錯誤訊息
5527
			$result["error"]=$callShell;
226 liveuser 5528
 
3 liveuser 5529
			#回傳結果
5530
			return $result;
226 liveuser 5531
 
3 liveuser 5532
			}#if end
226 liveuser 5533
 
3 liveuser 5534
		#打包好的檔案位置與名稱
5535
		$result["content"]=$conf["createdTarFile"].".tar";
226 liveuser 5536
 
3 liveuser 5537
		#執行到這邊代表執行正常
5538
		$result["status"]="true";
226 liveuser 5539
 
3 liveuser 5540
		#回傳結果
5541
		return $result;
226 liveuser 5542
 
3 liveuser 5543
		}#function makeTarFile end
226 liveuser 5544
 
3 liveuser 5545
	/*
5546
	#函式說明:
5547
	#將一個檔案壓縮成xz檔案
5548
	#回傳結果:
5549
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5550
	#$result["function"],當前執行的函數名稱
5551
	#$result["error"],錯誤訊息.
5552
	#$result["content"],檔案輸出後的位置與名稱.
5553
	#必填參數:
5554
	#$conf["compressTarget"],字串,要打包的每個資料夾與檔案位置
5555
	$conf["compressTarget"]="";
5556
	#$conf["createdXzFile"],字串,打包好的檔案要放在哪裡,副檔名.xz會自動加上.
5557
	$conf["createdXzFile"]="";
5558
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5559
	$conf["fileArgu"]=__FILE__;
5560
	#可省略參數:
5561
	#無.
5562
	#參考資料:
5563
	#無.
5564
	#備註:
5565
	#無.
5566
	*/
5567
	public static function makeXzFile(&$conf){
5568
 
5569
		#初始化要回傳的內容
5570
		$result=array();
226 liveuser 5571
 
3 liveuser 5572
		#記錄當前執行的函數名稱
5573
		$result["function"]=__FUNCTION__;
226 liveuser 5574
 
3 liveuser 5575
		#如果 $conf 不為陣列
5576
		if(gettype($conf)!="array"){
226 liveuser 5577
 
3 liveuser 5578
			#設置執行失敗
5579
			$result["status"]="false";
226 liveuser 5580
 
3 liveuser 5581
			#設置執行錯誤訊息
5582
			$result["error"][]="\$conf變數須為陣列形態";
5583
 
5584
			#如果傳入的參數為 null
5585
			if($conf==null){
226 liveuser 5586
 
3 liveuser 5587
				#設置執行錯誤訊息
5588
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5589
 
3 liveuser 5590
				}#if end
5591
 
5592
			#回傳結果
5593
			return $result;
226 liveuser 5594
 
3 liveuser 5595
			}#if end
226 liveuser 5596
 
3 liveuser 5597
		#檢查參數
5598
		#函式說明:
5599
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5600
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5601
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5602
		#$result["function"],當前執行的函式名稱.
5603
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5604
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5605
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5606
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5607
		#必填寫的參數:
5608
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5609
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5610
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5611
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","compressTarget","createdXzFile");
226 liveuser 5612
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5613
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
5614
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5615
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5616
		#可以省略的參數:
5617
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5618
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5619
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5620
		#$conf["skipableVariableName"]=array();
226 liveuser 5621
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5622
		#$conf["skipableVariableType"]=array();
5623
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5624
		#$conf["skipableVarDefaultValue"]=array("");
5625
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5626
		#$conf["arrayCountEqualCheck"][]=array();
5627
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5628
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5629
 
3 liveuser 5630
		#若檢查失敗
5631
		if($checkResult["status"]=="false"){
226 liveuser 5632
 
3 liveuser 5633
			#設置執行失敗
5634
			$result["status"]="false";
226 liveuser 5635
 
3 liveuser 5636
			#設置執行錯誤訊息
5637
			$result["error"]=$checkResult;
226 liveuser 5638
 
3 liveuser 5639
			#回傳結果
5640
			return $result;
226 liveuser 5641
 
3 liveuser 5642
			}#if end
226 liveuser 5643
 
3 liveuser 5644
		#若檢查不通過
5645
		if($checkResult["passed"]=="false"){
226 liveuser 5646
 
3 liveuser 5647
			#設置執行失敗
5648
			$result["status"]="false";
226 liveuser 5649
 
3 liveuser 5650
			#設置執行錯誤訊息
5651
			$result["error"]=$checkResult;
226 liveuser 5652
 
3 liveuser 5653
			#回傳結果
5654
			return $result;
226 liveuser 5655
 
3 liveuser 5656
			}#if end
226 liveuser 5657
 
3 liveuser 5658
		#檢查要用xz壓縮的檔案是否存在
5659
		#函式說明:
5660
		#檢查多個檔案與資料夾是否存在.
5661
		#回傳的結果:
5662
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5663
		#$result["error"],錯誤訊息陣列.
5664
		#$resutl["function"],當前執行的涵式名稱.
5665
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
5666
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
5667
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
5668
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
5669
		#必填參數:
5670
		#$conf["fileArray"],陣列字串,要檢查書否存在的檔案有哪些,須爲一維陣列數值。
5671
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["compressTarget"]);
5672
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5673
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
5674
		#可省略參數
5675
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
5676
		#$conf["disableWebSearch"]="false";
5677
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5678
		#$conf["userDir"]="true";
5679
		#參考資料來源:
5680
		#http://php.net/manual/en/function.file-exists.php
5681
		#http://php.net/manual/en/control-structures.foreach.php
5682
		#備註:
5683
		#函數file_exists檢查的路徑為檔案系統的路徑
5684
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
5685
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 5686
 
3 liveuser 5687
		#如果檢查要用xz壓縮的檔案失敗
5688
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 5689
 
3 liveuser 5690
			#設置執行失敗
5691
			$result["status"]="false";
226 liveuser 5692
 
3 liveuser 5693
			#設置執行錯誤訊息
5694
			$result["error"]=$checkMultiFileExist;
226 liveuser 5695
 
3 liveuser 5696
			#回傳結果
5697
			return $result;
226 liveuser 5698
 
3 liveuser 5699
			}#if end
226 liveuser 5700
 
3 liveuser 5701
		#如果要用xz壓縮的檔案有缺
5702
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 5703
 
3 liveuser 5704
			#設置執行失敗
5705
			$result["status"]="false";
226 liveuser 5706
 
3 liveuser 5707
			#設置執行錯誤訊息
5708
			$result["error"]=$checkMultiFileExist;
226 liveuser 5709
 
3 liveuser 5710
			#回傳結果
5711
			return $result;
226 liveuser 5712
 
3 liveuser 5713
			}#if end
226 liveuser 5714
 
3 liveuser 5715
		#壓縮要用的xz語法
5716
		#函式說明:
5717
		#呼叫shell執行系統命令,並取得回傳的內容.
5718
		#回傳的結果:
5719
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5720
		#$result["error"],錯誤訊息陣列
5721
		#$result["output"],爲執行完二元碼後的輸出陣列
5722
		#必填的參數
5723
		$conf["external::callShell"]["command"]="xz";#要執行的指令與參數
5724
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5725
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5726
		#可省略參數:
5727
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5728
		$conf["external::callShell"]["argu"]=array("-v","-v","-z","-c",$conf["compressTarget"],">",$conf["createdXzFile"].".xz ");
5729
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5730
		#$conf["enablePrintDescription"]="true";
5731
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
5732
		#$conf["printDescription"]="";
5733
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
5734
		$conf["external::callShell"]["escapeshellarg"]="true";
5735
		#參考資料:
5736
		#http://php.net/manual/en/function.exec.php
5737
		$callShell=external::callShell($conf["external::callShell"]);
5738
		unset($conf["external::callShell"]);
226 liveuser 5739
 
3 liveuser 5740
		#如果執行shell失敗
5741
		if($callShell["status"]=="false"){
226 liveuser 5742
 
3 liveuser 5743
			#設置執行失敗
5744
			$result["status"]="false";
226 liveuser 5745
 
3 liveuser 5746
			#設置執行錯誤訊息
5747
			$result["error"]=$callShell;
226 liveuser 5748
 
3 liveuser 5749
			#回傳結果
5750
			return $result;
226 liveuser 5751
 
3 liveuser 5752
			}#if end
226 liveuser 5753
 
3 liveuser 5754
		#壓縮好的檔案位置與名稱
5755
		$result["content"]=$conf["createdXzFile"].".xz";
226 liveuser 5756
 
3 liveuser 5757
		#執行到這邊代表執行正常
5758
		$result["status"]="status";
226 liveuser 5759
 
3 liveuser 5760
		#回傳結果
5761
		return $result;
5762
 
5763
		}#function makeXzFile end
226 liveuser 5764
 
3 liveuser 5765
	/*
5766
	#函式說明:
5767
	#將資料夾或檔案打包壓縮成tar.xz檔案
5768
	#回傳結果:
5769
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5770
	#$result["function"],當前執行的函數名稱
5771
	#$result["error"],錯誤訊息.
5772
	#$result["content"],檔案輸出後的位置與名稱.
5773
	#必填參數:
5774
	#$conf["compressTarget"],陣列,要打包壓縮的每個資料夾與檔案位置
5775
	$conf["compressTarget"]=array();
5776
	#$conf["createdTarXzFile"],字串,打包壓縮好的檔案要放在哪裡,副檔名.tar.xz會自動加上.
5777
	$conf["createdTarXzFile"]="";
5778
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5779
	$conf["fileArgu"]=__FILE__;
5780
	#可省略參數:
5781
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
5782
	#$conf["commentsArray"]=array("");
5783
	#$conf["includeDotStart"],字串,當參數$conf["commentsArray"]含有星號時是否要包含「.」開頭的檔案目錄,預設為"false",不包含,"true"為要包含.
5784
	#$conf["includeDotStart"]="false";
5785
	#$conf["includeWaveEnd"],字串,當參數$conf["commentsArray"]含有星號時是否要包含「~」結尾的檔案.預設為"false",不包含,"true"為要包含.
5786
	#$conf["includeWaveEnd"]="false";
5787
	#參考資料:
5788
	#無.
5789
	#備註:
226 liveuser 5790
	#建議加上 --exclude-backups, --exclude-caches-all
3 liveuser 5791
	*/
5792
	public static function makeTarXzFile(&$conf){
226 liveuser 5793
 
3 liveuser 5794
		#初始化要回傳的內容
5795
		$result=array();
226 liveuser 5796
 
3 liveuser 5797
		#記錄當前執行的函數名稱
5798
		$result["function"]=__FUNCTION__;
226 liveuser 5799
 
3 liveuser 5800
		#如果 $conf 不為陣列
5801
		if(gettype($conf)!="array"){
226 liveuser 5802
 
3 liveuser 5803
			#設置執行失敗
5804
			$result["status"]="false";
226 liveuser 5805
 
3 liveuser 5806
			#設置執行錯誤訊息
5807
			$result["error"][]="\$conf變數須為陣列形態";
5808
 
5809
			#如果傳入的參數為 null
5810
			if($conf==null){
226 liveuser 5811
 
3 liveuser 5812
				#設置執行錯誤訊息
5813
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5814
 
3 liveuser 5815
				}#if end
5816
 
5817
			#回傳結果
5818
			return $result;
226 liveuser 5819
 
3 liveuser 5820
			}#if end
226 liveuser 5821
 
3 liveuser 5822
		#檢查參數
5823
		#函式說明:
5824
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5825
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5826
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5827
		#$result["function"],當前執行的函式名稱.
5828
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5829
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5830
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5831
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5832
		#必填寫的參數:
5833
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5834
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5835
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5836
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","compressTarget","createdTarXzFile");
226 liveuser 5837
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5838
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
5839
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5840
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5841
		#可以省略的參數:
5842
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5843
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5844
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5845
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","includeDotStart","includeWaveEnd");
226 liveuser 5846
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5847
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");
5848
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5849
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false","false");
5850
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5851
		#$conf["arrayCountEqualCheck"][]=array();
5852
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5853
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5854
 
3 liveuser 5855
		#若檢查失敗
5856
		if($checkResult["status"]=="false"){
226 liveuser 5857
 
3 liveuser 5858
			#設置執行失敗
5859
			$result["status"]="false";
226 liveuser 5860
 
3 liveuser 5861
			#設置執行錯誤訊息
5862
			$result["error"]=$checkResult;
226 liveuser 5863
 
3 liveuser 5864
			#回傳結果
5865
			return $result;
226 liveuser 5866
 
3 liveuser 5867
			}#if end
226 liveuser 5868
 
3 liveuser 5869
		#若檢查不通過
5870
		if($checkResult["passed"]=="false"){
226 liveuser 5871
 
3 liveuser 5872
			#設置執行失敗
5873
			$result["status"]="false";
226 liveuser 5874
 
3 liveuser 5875
			#設置執行錯誤訊息
5876
			$result["error"]=$checkResult;
226 liveuser 5877
 
3 liveuser 5878
			#回傳結果
5879
			return $result;
226 liveuser 5880
 
3 liveuser 5881
			}#if end
226 liveuser 5882
 
3 liveuser 5883
		#如果 $conf["commentsArray"] 有設定
5884
		if(isset($conf["commentsArray"])){
226 liveuser 5885
 
3 liveuser 5886
			#印出提示文字
5887
			#函式說明:
5888
			#印出多行文字,結尾自動換行.
5889
			#回傳的結果:
5890
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
5891
			#$result["function"],當前執行的函數名稱.
5892
			#$result["error"],錯誤訊息陣列.
5893
			#必填參數:
5894
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
5895
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
5896
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
5897
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 5898
 
3 liveuser 5899
			#如果印出提示文字失敗
5900
			if($echoMultiLine["status"]=="false"){
226 liveuser 5901
 
3 liveuser 5902
				#設置執行失敗
5903
				$result["status"]="false";
226 liveuser 5904
 
3 liveuser 5905
				#設置執行錯誤訊息
5906
				$result["error"]=$echoMultiLine;
226 liveuser 5907
 
3 liveuser 5908
				#回傳結果
5909
				return $result;
226 liveuser 5910
 
3 liveuser 5911
				}#if end
226 liveuser 5912
 
5913
			}#if end
5914
 
3 liveuser 5915
		#解析要處理的檔案路徑
5916
		#函式說明:
5917
		#將含有「*」的多個檔案路徑名稱,變成多個符合條件的路徑檔案.
5918
		#回傳結果:
5919
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
5920
		#$result["error"],錯誤訊息陣列.
226 liveuser 5921
		#$result["function"],函數名稱.
3 liveuser 5922
		#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
5923
		#$result["pathCount"],整數,有幾個路徑.
5924
		#必填參數:
5925
		#$conf["path"],字串陣列,要解析含有「*」的檔案路徑字串.
5926
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["path"]=$conf["compressTarget"];
5927
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
5928
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["fileArgu"]=$conf["fileArgu"];
5929
		#可省略參數:
5930
		#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
5931
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["noDotStart"]=$conf["includeDotStart"]==="true"?"false":"true";
5932
		#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
5933
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["noWaveEnd"]=$conf["includeWaveEnd"]==="true"?"false":"true";
5934
		$realPathArray=fileAccess::resolveMultiPostionStringWhichContainStarSymbol($conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]);
5935
		unset($conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]);
226 liveuser 5936
 
3 liveuser 5937
		#如果解析路徑失敗
5938
		if($realPathArray["status"]=="false"){
226 liveuser 5939
 
3 liveuser 5940
			#設置執行失敗
5941
			$result["status"]="false";
226 liveuser 5942
 
3 liveuser 5943
			#設置執行錯誤訊息
5944
			$result["error"]=$realPathArray;
226 liveuser 5945
 
3 liveuser 5946
			#回傳結果
5947
			return $result;
226 liveuser 5948
 
3 liveuser 5949
			}#if end
226 liveuser 5950
 
3 liveuser 5951
		#取得解析好的檔案路徑陣列
226 liveuser 5952
		$conf["compressTarget"]=$realPathArray["content"];
5953
 
3 liveuser 5954
		#將路徑轉換成相對路徑
5955
		#函式說明:
5956
		#將多個路徑字串變成相對於當前路徑的相對路徑字串
5957
		#回傳結果:
5958
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
5959
		#$result["error"],錯誤訊息陣列.
226 liveuser 5960
		#$result["function"],函數名稱.
3 liveuser 5961
		#$result["content"],字串陣列,多個轉換好的相對路徑字串.
5962
		#必填參數:
5963
		#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
5964
		$conf["fileAccess::getRelativePath"]["path"]=$conf["compressTarget"];
5965
		#$conf["fileArgu"],字串,當前路徑.
5966
		$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
5967
		$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
5968
		unset($conf["fileAccess::getRelativePath"]);
226 liveuser 5969
 
3 liveuser 5970
		#如果轉換失敗
5971
		if($getRelativePath["status"]=="false"){
226 liveuser 5972
 
3 liveuser 5973
			#設置執行失敗
5974
			$result["status"]="false";
226 liveuser 5975
 
3 liveuser 5976
			#設置執行錯誤訊息
5977
			$result["error"]=$getRelativePat;
226 liveuser 5978
 
3 liveuser 5979
			#回傳結果
5980
			return $result;
226 liveuser 5981
 
5982
			}#if end
5983
 
3 liveuser 5984
		#打包成tar檔
5985
		#函式說明:
5986
		#將資料夾或檔案打包成tar檔案
5987
		#回傳的結果:
5988
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5989
		#$result["function"],當前執行的函數名稱
5990
		#$result["error"],錯誤訊息.
5991
		#$result["content"],檔案輸出後的位置與名稱.
5992
		#必填參數:
5993
		#$conf["fileAccess::makeTarFile"]["packetTarget"],陣列,要打包的每個資料夾與檔案位置
5994
		$conf["fileAccess::makeTarFile"]["packetTarget"]=$getRelativePath["content"];
5995
		#$conf["fileAccess::makeTarFile"]["createdTarFile"],字串,打包好的檔案要放在哪裡,副檔名.tar會自動加上.
5996
		$conf["fileAccess::makeTarFile"]["createdTarFile"]=$conf["createdTarXzFile"];
5997
		#$conf["fileAccess::makeTarFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5998
		$conf["fileAccess::makeTarFile"]["fileArgu"]=$conf["fileArgu"];
5999
		$makeTarFile=fileAccess::makeTarFile($conf["fileAccess::makeTarFile"]);
6000
		unset($conf["fileAccess::makeTarFile"]);
226 liveuser 6001
 
3 liveuser 6002
		#如果打包失敗
6003
		if($makeTarFile["status"]=="false"){
226 liveuser 6004
 
3 liveuser 6005
			#設置執行不正常
6006
			$result["status"]="false";
226 liveuser 6007
 
3 liveuser 6008
			#設置錯誤訊息
6009
			$result["error"]=$makeTarFile;
226 liveuser 6010
 
3 liveuser 6011
			#回傳結果
6012
			return $result;
226 liveuser 6013
 
3 liveuser 6014
			}#if end
226 liveuser 6015
 
3 liveuser 6016
		#壓縮成xz檔
6017
		#函式說明:
6018
		#將一個檔案壓縮成xz檔案
6019
		#回傳的結果:
6020
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6021
		#$result["function"],當前執行的函數名稱
6022
		#$result["error"],錯誤訊息.
6023
		#$result["content"],檔案輸出後的位置與名稱.
6024
		#必填參數:
6025
		#$conf["fileAccess::makeXzFile"]["compressTarget"],字串,要打包的每個資料夾與檔案位置
6026
		$conf["fileAccess::makeXzFile"]["compressTarget"]=$makeTarFile["content"];
6027
		#$conf["fileAccess::makeXzFile"]["createdXzFile"],字串,打包好的檔案要放在哪裡,副檔名.xz會自動加上.
6028
		$conf["fileAccess::makeXzFile"]["createdXzFile"]=$makeTarFile["content"];
6029
		#$conf["fileAccess::makeXzFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6030
		$conf["fileAccess::makeXzFile"]["fileArgu"]=$conf["fileArgu"];
6031
		$makeXzFile=fileAccess::makeXzFile($conf["fileAccess::makeXzFile"]);
6032
		unset($conf["fileAccess::makeXzFile"]);
226 liveuser 6033
 
3 liveuser 6034
		#如果壓縮失敗
6035
		if($makeXzFile["status"]=="false"){
226 liveuser 6036
 
3 liveuser 6037
			#設置執行不正常
6038
			$result["status"]="false";
226 liveuser 6039
 
3 liveuser 6040
			#設置錯誤訊息
6041
			$result["error"]=$makeXzFile;
226 liveuser 6042
 
3 liveuser 6043
			#回傳結果
6044
			return $result;
226 liveuser 6045
 
3 liveuser 6046
			}#if end
226 liveuser 6047
 
3 liveuser 6048
		#移除tar檔案
6049
		#函式說明:
6050
		#移除檔案
6051
		#回傳結果:
6052
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
6053
		#$result["error"],錯誤訊息陣列
6054
		#$result["warning"],警告訊息陣列
6055
		#$result["function"],當前執行的函數名稱
6056
		#必填參數:
6057
		$conf["fileAccess::delFile"]["fileAddress"]=$makeTarFile["content"];#要移除檔案的位置
6058
		#$conf["fileAccess::delFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
6059
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
6060
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
6061
		unset($conf["fileAccess::delFile"]);
226 liveuser 6062
 
3 liveuser 6063
		#如果移除tar檔案失敗
6064
		if($delFile["status"]=="false"){
226 liveuser 6065
 
3 liveuser 6066
			#設置執行不正常
6067
			$result["status"]="false";
226 liveuser 6068
 
3 liveuser 6069
			#設置錯誤訊息
6070
			$result["error"]=$delFile;
226 liveuser 6071
 
3 liveuser 6072
			#回傳結果
6073
			return $result;
226 liveuser 6074
 
3 liveuser 6075
			}#if end
226 liveuser 6076
 
3 liveuser 6077
		#取得壓縮好的檔案位置與名稱
6078
		$result["content"]=$makeXzFile["content"];
226 liveuser 6079
 
3 liveuser 6080
		#執行到這邊代表執行正常
6081
		$result["status"]="true";
226 liveuser 6082
 
3 liveuser 6083
		#回傳結果
6084
		return $result;
226 liveuser 6085
 
3 liveuser 6086
		}#function makeTarXzFile end
226 liveuser 6087
 
3 liveuser 6088
	/*
6089
	#函式說明:
6090
	#移動檔案
6091
	#回傳結果:
6092
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6093
	#$result["function"],當前執行的函數名稱
6094
	#$result["error"],錯誤訊息.
6095
	#$result["content"],檔案輸出後的位置與名稱.
6096
	#必填參數:
6097
	#$conf["from"],字串,要移動的檔案名稱與位置.
6098
	$conf["from"]="";
6099
	#$conf["to"],字串,要移動到的位置與名稱
6100
	$conf["to"]="";
6101
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6102
	$conf["fileArgu"]=__FILE__;
6103
	#可省略參數:
6104
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
6105
	#$conf["commentsArray"]=array("");
6106
	#參考資料:
6107
	#無.
6108
	#備註:
6109
	#無.
6110
	*/
6111
	public static function mv(&$conf){
226 liveuser 6112
 
3 liveuser 6113
		#初始化要回傳的結果
6114
		$result=array();
226 liveuser 6115
 
3 liveuser 6116
		#取得當前執行的函數名稱
6117
		$result["function"]=__FUNCTION__;
226 liveuser 6118
 
3 liveuser 6119
		#如果 $conf 不為陣列
6120
		if(gettype($conf)!="array"){
226 liveuser 6121
 
3 liveuser 6122
			#設置執行失敗
6123
			$result["status"]="false";
226 liveuser 6124
 
3 liveuser 6125
			#設置執行錯誤訊息
6126
			$result["error"][]="\$conf變數須為陣列形態";
6127
 
6128
			#如果傳入的參數為 null
6129
			if($conf==null){
226 liveuser 6130
 
3 liveuser 6131
				#設置執行錯誤訊息
6132
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6133
 
3 liveuser 6134
				}#if end
6135
 
6136
			#回傳結果
6137
			return $result;
226 liveuser 6138
 
3 liveuser 6139
			}#if end
226 liveuser 6140
 
3 liveuser 6141
		#檢查參數
6142
		#函式說明:
6143
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6144
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6145
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6146
		#$result["function"],當前執行的函式名稱.
6147
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6148
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6149
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6150
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6151
		#必填寫的參數:
6152
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6153
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6154
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6155
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("from","to","fileArgu");
226 liveuser 6156
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 6157
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
6158
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6159
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6160
		#可以省略的參數:
6161
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
6162
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6163
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6164
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray");
226 liveuser 6165
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 6166
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
6167
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6168
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
6169
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6170
		#$conf["arrayCountEqualCheck"][]=array();
6171
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6172
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 6173
 
3 liveuser 6174
		#若檢查失敗
6175
		if($checkResult["status"]=="false"){
226 liveuser 6176
 
3 liveuser 6177
			#設置執行失敗
6178
			$result["status"]="false";
226 liveuser 6179
 
3 liveuser 6180
			#設置執行錯誤訊息
6181
			$result["error"]=$checkResult;
226 liveuser 6182
 
3 liveuser 6183
			#回傳結果
6184
			return $result;
226 liveuser 6185
 
3 liveuser 6186
			}#if end
226 liveuser 6187
 
3 liveuser 6188
		#若檢查不通過
6189
		if($checkResult["passed"]=="false"){
226 liveuser 6190
 
3 liveuser 6191
			#設置執行失敗
6192
			$result["status"]="false";
226 liveuser 6193
 
3 liveuser 6194
			#設置執行錯誤訊息
6195
			$result["error"]=$checkResult;
226 liveuser 6196
 
3 liveuser 6197
			#回傳結果
6198
			return $result;
226 liveuser 6199
 
3 liveuser 6200
			}#if end
226 liveuser 6201
 
3 liveuser 6202
		#如果 $conf["commentsArray"] 有設定
6203
		if(isset($conf["commentsArray"])){
226 liveuser 6204
 
3 liveuser 6205
			#印出提示文字
6206
			#函式說明:
6207
			#印出多行文字,結尾自動換行.
6208
			#回傳的結果:
6209
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
6210
			#$result["function"],當前執行的函數名稱.
6211
			#$result["error"],錯誤訊息陣列.
6212
			#必填參數:
6213
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
6214
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
6215
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
6216
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 6217
 
3 liveuser 6218
			#如果印出提示文字失敗
6219
			if($echoMultiLine["status"]=="false"){
226 liveuser 6220
 
3 liveuser 6221
				#設置執行失敗
6222
				$result["status"]="false";
226 liveuser 6223
 
3 liveuser 6224
				#設置執行錯誤訊息
6225
				$result["error"]=$echoMultiLine;
226 liveuser 6226
 
3 liveuser 6227
				#回傳結果
6228
				return $result;
226 liveuser 6229
 
3 liveuser 6230
				}#if end
226 liveuser 6231
 
6232
			}#if end
6233
 
3 liveuser 6234
		#檢查要移動的檔案是否存在
6235
		#函式說明:
6236
		#檢查多個檔案與資料夾是否存在.
6237
		#回傳的結果:
6238
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
6239
		#$result["error"],錯誤訊息陣列.
6240
		#$resutl["function"],當前執行的涵式名稱.
6241
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
6242
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
6243
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
6244
		#必填參數:
6245
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["from"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
6246
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
6247
		#參考資料來源:
6248
		#http://php.net/manual/en/function.file-exists.php
6249
		#http://php.net/manual/en/control-structures.foreach.php
6250
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
6251
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 6252
 
3 liveuser 6253
		#如果檢查失敗
6254
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 6255
 
3 liveuser 6256
			#設置執行失敗
6257
			$result["status"]="false";
226 liveuser 6258
 
3 liveuser 6259
			#設置執行錯誤訊息
6260
			$result["error"]=$checkMultiFileExist;
226 liveuser 6261
 
3 liveuser 6262
			#回傳結果
6263
			return $result;
226 liveuser 6264
 
6265
			}#if end
6266
 
3 liveuser 6267
		#如果來源檔案不存在
6268
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 6269
 
3 liveuser 6270
			#設置執行失敗
6271
			$result["status"]="false";
226 liveuser 6272
 
3 liveuser 6273
			#設置執行錯誤訊息
6274
			$result["error"][]="檔案「".$conf["from"]."」不存在";
226 liveuser 6275
 
3 liveuser 6276
			#回傳結果
6277
			return $result;
226 liveuser 6278
 
3 liveuser 6279
			}#if end
226 liveuser 6280
 
3 liveuser 6281
		#函式說明:
6282
		#呼叫shell執行系統命令,並取得回傳的內容.
6283
		#回傳的結果:
6284
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6285
		#$result["error"],錯誤訊息陣列
6286
		#$result["output"],爲執行完二元碼後的輸出陣列
6287
		#必填的參數
6288
		$conf["external::callShell"]["command"]="mv";#要執行的指令與參數
6289
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"]; #__FILE__的內容
6290
		#可省略參數:
6291
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
6292
		$conf["external::callShell"]["argu"]=array("-v",$conf["from"],$conf["to"]);
6293
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
6294
		#$conf["external::callShell"]["enablePrintDescription"]="true";
6295
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
6296
		#$conf["printDescription"]="";
6297
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
6298
		$conf["external::callShell"]["escapeshellarg"]="true";
6299
		#參考資料:
6300
		#http://php.net/manual/en/function.exec.php
6301
		$callShell=external::callShell($conf["external::callShell"]);
6302
		unset($conf["external::callShell"]);
226 liveuser 6303
 
3 liveuser 6304
		#如果移動檔案失敗
6305
		if($callShell["status"]=="false"){
226 liveuser 6306
 
3 liveuser 6307
			#設置執行失敗
6308
			$result["status"]="false";
226 liveuser 6309
 
3 liveuser 6310
			#設置執行錯誤訊息
6311
			$result["error"]=$callShell;
226 liveuser 6312
 
3 liveuser 6313
			#回傳結果
6314
			return $result;
226 liveuser 6315
 
3 liveuser 6316
			}#if end
226 liveuser 6317
 
3 liveuser 6318
		#執行到這邊代表正常
6319
		$result["status"]="true";
226 liveuser 6320
 
3 liveuser 6321
		#儲存移動後的位置與名稱
6322
		$result["content"]=$conf["to"];
226 liveuser 6323
 
3 liveuser 6324
		#回傳結果
6325
		return $result;
226 liveuser 6326
 
3 liveuser 6327
		}#function mv end
226 liveuser 6328
 
3 liveuser 6329
	/*
6330
	#函式說明:
6331
	#取得目錄底下所有目錄與檔案的樹狀結構.
6332
	#回傳結果:
6333
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6334
	#$result["error"],錯誤訊息陣列.
6335
	#$result["function"],函數名稱.
6336
	#$result["position"],根目錄位置.
6337
	#$result["content"],陣列,檔案目錄的樹狀結構.
6338
	#$result["content"][$i]["name"],根目錄底下第$i+1個檔案或目錄的名稱
6339
	#$result["content"][$i]["folder"],根目錄底下第$i+1個名稱是目錄("true")還是檔案("false").
6340
	#$result["content"][$i]["position"],根目錄底下第$i+1個名稱或目錄的位置.
6341
	#$result["content"][$i]["ownerPerm"],根目錄底下第$i+1個使用者的權限.
6342
	#$result["content"][$i]["groupPerm"],根目錄底下第$i+1個群組使用者的權限.
6343
	#$result["content"][$i]["otherPerm"],根目錄底下第$i+1個其他使用者的權限.
6344
	#$result["content"][$i]["ownerName"],根目錄底下第$i+1個擁有者賬戶.
6345
	#$result["content"][$i]["groupName"],根目錄底下第$i+1個群組擁有者賬戶.
6346
	#$result["content"][$i]["next"][$j]["name"],第$i+1個為目錄的名稱的目錄底下第$j+1個檔案或目錄的名稱
6347
	#$result["content"][$i]["next"][$j]["folder"],第$i+1個為目錄的名稱的目錄底下第$j+1個名稱是目錄("true")還是檔案("false").
6348
	#$result["content"][$i]["next"][$j]["position"],第$i+1個為目錄的名稱的目錄底下第$j+1個名稱或目錄的位置.
6349
	#$result["content"][$i]["next"][$j]["ownerPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個使用者的權限.
6350
	#$result["content"][$i]["next"][$j]["groupPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個群組使用者的權限.
6351
	#$result["content"][$i]["next"][$j]["otherPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個其他使用者的權限.
6352
	#$result["content"][$i]["next"][$j]["ownerName"],第$i+1個為目錄的名稱的目錄底下第$j+1個擁有者賬戶.
6353
	#$result["content"][$i]["next"][$j]["groupName"],第$i+1個為目錄的名稱的目錄底下第$j+1個群組擁有者賬戶.
226 liveuser 6354
	#以此類推...
3 liveuser 6355
	#必填參數:
6356
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6357
	$conf["position"]="";
6358
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6359
	$conf["fileArgu"]=__FILE__;
6360
	#可省略參數:
6361
	#無.
6362
	#參考資料:
6363
	#無.
6364
	#備註:
6365
	#無.
6366
	*/
6367
	public static function getListTree(&$conf){
226 liveuser 6368
 
3 liveuser 6369
		#初始化要回傳的結果
6370
		$result=array();
226 liveuser 6371
 
3 liveuser 6372
		#設置當其函數名稱
6373
		$result["function"]=__FUNCTION__;
226 liveuser 6374
 
3 liveuser 6375
		#如果 $conf 不為陣列
6376
		if(gettype($conf)!="array"){
226 liveuser 6377
 
3 liveuser 6378
			#設置執行失敗
6379
			$result["status"]="false";
226 liveuser 6380
 
3 liveuser 6381
			#設置執行錯誤訊息
6382
			$result["error"][]="\$conf變數須為陣列形態";
6383
 
6384
			#如果傳入的參數為 null
6385
			if($conf==null){
226 liveuser 6386
 
3 liveuser 6387
				#設置執行錯誤訊息
6388
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6389
 
3 liveuser 6390
				}#if end
6391
 
6392
			#回傳結果
6393
			return $result;
226 liveuser 6394
 
3 liveuser 6395
			}#if end
226 liveuser 6396
 
3 liveuser 6397
		#檢查必填參數
6398
		#函式說明:
6399
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6400
		#回傳的結果:
6401
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6402
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6403
		#$result["function"],當前執行的函式名稱.
6404
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6405
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6406
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6407
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6408
		#必填寫的參數:
6409
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6410
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileArgu","position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6411
		#可以省略的參數:
226 liveuser 6412
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6413
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6414
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
6415
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 6416
 
3 liveuser 6417
		#如果檢查失敗
6418
		if($checkResult["status"]=="false"){
226 liveuser 6419
 
3 liveuser 6420
			#設置錯誤識別
6421
			$result["status"]="false";
226 liveuser 6422
 
3 liveuser 6423
			#設置錯誤訊息
6424
			$result["error"]=$checkResult;
226 liveuser 6425
 
3 liveuser 6426
			#回傳結果
6427
			return $result;
226 liveuser 6428
 
3 liveuser 6429
			}#if end
226 liveuser 6430
 
3 liveuser 6431
		#如果檢查不通過
6432
		if($checkResult["passed"]=="false"){
226 liveuser 6433
 
3 liveuser 6434
			#設置錯誤識別
6435
			$result["status"]="false";
226 liveuser 6436
 
3 liveuser 6437
			#設置錯誤訊息
6438
			$result["error"]=$checkResult;
226 liveuser 6439
 
3 liveuser 6440
			#回傳結果
6441
			return $result;
226 liveuser 6442
 
3 liveuser 6443
			}#if end
226 liveuser 6444
 
3 liveuser 6445
		#如果目錄不為 . 與 ..
6446
		if(basename($conf["position"])!="." && basename($conf["position"])!=".."){
226 liveuser 6447
 
3 liveuser 6448
			#檢查目錄是否存在
6449
			#函式說明:
6450
			#檢查多個檔案與資料夾是否存在.
6451
			#回傳的結果:
6452
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
6453
			#$result["error"],錯誤訊息陣列.
6454
			#$resutl["function"],當前執行的涵式名稱.
6455
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
6456
			#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
6457
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
6458
			#必填參數:
6459
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["position"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
6460
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6461
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
6462
			#參考資料來源:
6463
			#http://php.net/manual/en/function.file-exists.php
6464
			#http://php.net/manual/en/control-structures.foreach.php
6465
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
6466
			unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 6467
 
3 liveuser 6468
			#如果檢查目錄失敗
6469
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 6470
 
3 liveuser 6471
				#設置錯誤識別
6472
				$result["status"]="false";
226 liveuser 6473
 
3 liveuser 6474
				#設置錯誤訊息
6475
				$result["error"]=$checkMultiFileExist;
226 liveuser 6476
 
3 liveuser 6477
				#回傳結果
6478
				return $result;
226 liveuser 6479
 
6480
				}#if end
6481
 
3 liveuser 6482
			#如果目錄不存在
6483
			if($checkMultiFileExist["varExist"][0]=="false"){
226 liveuser 6484
 
3 liveuser 6485
				#設置錯誤識別
6486
				$result["status"]="false";
226 liveuser 6487
 
3 liveuser 6488
				#設置錯誤訊息
6489
				$result["error"]=$checkMultiFileExist;
226 liveuser 6490
 
3 liveuser 6491
				#回傳結果
6492
				return $result;
226 liveuser 6493
 
6494
				}#if end
6495
 
3 liveuser 6496
			}#if end
226 liveuser 6497
 
3 liveuser 6498
		#取得根目錄的樹狀結構
6499
		#函式說明:
6500
		#取得目錄底下所有目錄與檔案清單.
6501
		#回傳結果:
6502
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6503
		#$result["error"],錯誤訊息陣列.
6504
		#$result["function"],函數名稱.
6505
		#$result["content"],陣列,目錄底下的檔案與子目錄.
6506
		#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
6507
		#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
6508
		#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
6509
		#$result["position"],目前的位置.
6510
		#必填參數:
6511
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6512
		$conf["fileAccess::getList"]["position"]=$conf["position"];
6513
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6514
		$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
6515
		#可省略參數:
6516
		#無
6517
		#參考資料來源:
6518
		#opendir=>http://php.net/manual/en/function.opendir.php
6519
		#is_dir=>http://php.net/manual/en/function.is-dir.php
6520
		$rootList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 6521
		unset($conf["fileAccess::getList"]);
6522
 
3 liveuser 6523
		#如果取得根目錄底下的資料失敗
6524
		if($rootList["status"]=="false"){
226 liveuser 6525
 
3 liveuser 6526
			#設置錯誤識別
6527
			$result["status"]="false";
226 liveuser 6528
 
3 liveuser 6529
			#設置錯誤訊息
6530
			$result["error"]=$rootList;
226 liveuser 6531
 
3 liveuser 6532
			#回傳結果
6533
			return $result;
226 liveuser 6534
 
3 liveuser 6535
			}#if end
226 liveuser 6536
 
6537
		#取得當前目錄
6538
		$result["position"]=$rootList["position"];
6539
 
3 liveuser 6540
		#取得根目錄層級可以看到的檔案與目錄
6541
		$result["content"]=$rootList["content"];
226 liveuser 6542
 
3 liveuser 6543
		#如果當前目錄有檔案與子目錄
6544
		if(isset($result["content"])){
226 liveuser 6545
 
3 liveuser 6546
			#當前層級有幾個檔案目錄就執行幾次
6547
			for($i=0;$i<count($result["content"]);$i++){
226 liveuser 6548
 
3 liveuser 6549
				#如果該單位是目錄
6550
				if($result["content"][$i]["folder"]=="true"){
226 liveuser 6551
 
3 liveuser 6552
					#呼叫當前函數,取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊
6553
					#函式說明:
6554
					#取得目錄底下所有目錄與檔案的樹狀結構.
6555
					#回傳結果:
6556
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6557
					#$result["error"],錯誤訊息陣列.
6558
					#$result["function"],函數名稱.
6559
					#$result["content"],陣列,檔案目錄的樹狀結構.
6560
					#$result["total"],根目錄底下有多少目錄與檔案
6561
					#必填參數:
6562
					#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6563
					$conf["fileAccess::getListTree"]["position"]=$conf["position"]."/".$result["content"][$i]["name"];
6564
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6565
					$conf["fileAccess::getListTree"]["fileArgu"]=$conf["fileArgu"];
6566
					#可省略參數:
6567
					#無
6568
					$getListTree=fileAccess::getListTree($conf["fileAccess::getListTree"]);
6569
					unset($conf["fileAccess::getListTree"]);
226 liveuser 6570
 
3 liveuser 6571
					#如果取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊失敗
6572
					if($getListTree["status"]=="false"){
226 liveuser 6573
 
3 liveuser 6574
						#設置錯誤識別
6575
						$result["status"]="false";
226 liveuser 6576
 
3 liveuser 6577
						#設置錯誤訊息
6578
						$result["error"]=$getListTree;
226 liveuser 6579
 
3 liveuser 6580
						#回傳結果
6581
						return $result;
226 liveuser 6582
 
3 liveuser 6583
						}#if end
226 liveuser 6584
 
3 liveuser 6585
					#如果 $conf["position"]."/".$result["content"][$i]["name"] 目錄有檔案與子目錄
226 liveuser 6586
					if(isset($getListTree["content"])){
6587
 
3 liveuser 6588
						#取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊
6589
						$result["content"][$i]["next"]=$getListTree["content"];
226 liveuser 6590
 
3 liveuser 6591
						}#if end
226 liveuser 6592
 
6593
					#取得當前目錄
6594
					$result["content"][$i]["position"]=$rootList["position"];
6595
 
3 liveuser 6596
					}#if end
226 liveuser 6597
 
3 liveuser 6598
				}#for end
226 liveuser 6599
 
3 liveuser 6600
			}#if end
226 liveuser 6601
 
3 liveuser 6602
		#執行到這邊代表執行正常
6603
		$result["status"]="true";
226 liveuser 6604
 
3 liveuser 6605
		#回傳結果
6606
		return $result;
226 liveuser 6607
 
3 liveuser 6608
		}#function getListTree end
226 liveuser 6609
 
3 liveuser 6610
	/*
6611
	#函式說明:
6612
	#取得目錄底下所有目錄與檔案清單.
6613
	#回傳結果:
6614
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6615
	#$result["error"],錯誤訊息陣列.
6616
	#$result["function"],函數名稱.
6617
	#$result["content"],陣列,目錄底下的檔案與子目錄.
6618
	#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
6619
	#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
6620
	#$result["content"][$i]["ownerPerm"],字串,使用者的權限.
6621
	#$result["content"][$i]["groupPerm"],字串,群組使用者的權限.
6622
	#$result["content"][$i]["otherPerm"],字串,其他使用者的權限.
6623
	#$result["content"][$i]["ownerName"],字串,擁有者賬戶.
6624
	#$result["content"][$i]["groupName"],字串,群組擁有者賬戶.
6625
	#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
6626
	#$result["position"],目前的位置.
6627
	#必填參數:
6628
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6629
	$conf["position"]="";
6630
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6631
	$conf["fileArgu"]=__FILE__;
6632
	#可省略參數:
6633
	#無
6634
	#參考資料:
6635
	#opendir=>http://php.net/manual/en/function.opendir.php
6636
	#is_dir=>http://php.net/manual/en/function.is-dir.php
6637
	#備註:
6638
	#無.
6639
	*/
6640
	public static function getList(&$conf){
6641
 
6642
		#初始化要回傳的結果
6643
		$result=array();
226 liveuser 6644
 
3 liveuser 6645
		#設置當其函數名稱
6646
		$result["function"]=__FUNCTION__;
226 liveuser 6647
 
3 liveuser 6648
		#初始化記載檔案目錄名單的陣列
6649
		$result["content"]=array();
226 liveuser 6650
 
3 liveuser 6651
		#如果 $conf 不為陣列
6652
		if(gettype($conf)!="array"){
226 liveuser 6653
 
3 liveuser 6654
			#設置執行失敗
6655
			$result["status"]="false";
226 liveuser 6656
 
3 liveuser 6657
			#設置執行錯誤訊息
6658
			$result["error"][]="\$conf變數須為陣列形態";
6659
 
6660
			#如果傳入的參數為 null
6661
			if($conf==null){
226 liveuser 6662
 
3 liveuser 6663
				#設置執行錯誤訊息
6664
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6665
 
3 liveuser 6666
				}#if end
6667
 
6668
			#回傳結果
6669
			return $result;
226 liveuser 6670
 
3 liveuser 6671
			}#if end
226 liveuser 6672
 
3 liveuser 6673
		#檢查必填參數
6674
		#函式說明:
6675
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6676
		#回傳的結果:
6677
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6678
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6679
		#$result["function"],當前執行的函式名稱.
6680
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6681
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6682
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6683
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6684
		#必填寫的參數:
6685
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6686
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileArgu","position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6687
		#可以省略的參數:
226 liveuser 6688
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6689
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6690
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
6691
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 6692
 
3 liveuser 6693
		#如果檢查失敗
6694
		if($checkResult["status"]=="false"){
226 liveuser 6695
 
3 liveuser 6696
			#設置錯誤識別
6697
			$result["status"]="false";
226 liveuser 6698
 
3 liveuser 6699
			#設置錯誤訊息
6700
			$result["error"]=$checkResult;
226 liveuser 6701
 
3 liveuser 6702
			#回傳結果
6703
			return $result;
226 liveuser 6704
 
3 liveuser 6705
			}#if end
226 liveuser 6706
 
3 liveuser 6707
		#如果檢查不通過
6708
		if($checkResult["passed"]==="false"){
226 liveuser 6709
 
3 liveuser 6710
			#設置錯誤識別
6711
			$result["status"]="false";
226 liveuser 6712
 
3 liveuser 6713
			#設置錯誤訊息
6714
			$result["error"]=$checkResult;
226 liveuser 6715
 
3 liveuser 6716
			#回傳結果
6717
			return $result;
226 liveuser 6718
 
3 liveuser 6719
			}#if end
226 liveuser 6720
 
3 liveuser 6721
		#檢查目標路徑是否為「/」開頭的路徑
6722
		#函式說明:
6723
		#取得符合特定字首與字尾的字串
6724
		#回傳結果:
6725
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
6726
		#$result["function"],當前執行的函數名稱.
6727
		#$result["error"],錯誤訊息陣列.
6728
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
6729
		#$result["returnString"],爲符合字首條件的字串內容。
6730
		#必填參數:
6731
		#$conf["checkString"],字串,要檢查的字串.
6732
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["position"];
6733
		#可省略參數:
6734
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
6735
		$conf["search::getMeetConditionsString"]["frontWord"]="/";
6736
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
6737
		#$conf["tailWord"]="";
6738
		#參考資料:
6739
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
6740
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
6741
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 6742
 
3 liveuser 6743
		#如果檢查關鍵字失敗
6744
		if($getMeetConditionsString["status"]=="false"){
226 liveuser 6745
 
3 liveuser 6746
			#設置錯誤識別
6747
			$result["status"]="false";
226 liveuser 6748
 
3 liveuser 6749
			#設置錯誤訊息
6750
			$result["error"]=$getMeetConditionsString;
226 liveuser 6751
 
3 liveuser 6752
			#回傳結果
6753
			return $result;
226 liveuser 6754
 
6755
			}#if end
6756
 
3 liveuser 6757
		#如果目標路徑不為「/」開頭的路徑,則為相對路徑
6758
		if($getMeetConditionsString["founded"]=="false"){
226 liveuser 6759
 
3 liveuser 6760
			#取得目標位置的路徑
6761
			#函式說明:
6762
			#將檔案的位置名稱變成網址
6763
			#回傳結果:
6764
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6765
			#$result["error"],錯誤訊息陣列.
226 liveuser 6766
			#$result["function"],函數名稱.
3 liveuser 6767
			#$result["content"],網址.
6768
			#$result["localAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
6769
			#$result["fileSystemAbsoulutePosition"],針對伺服器檔案系統的絕對位置.
6770
			#必填參數:
6771
			#$conf["address"],字串,檔案的相對位置.
6772
			$conf["fileAccess::getInternetAddress"]["address"]=$conf["position"];
6773
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
6774
			$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
6775
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是.
6776
			#$conf["fileAccess::getInternetAddress"]["userDir"]="true";
6777
			$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
226 liveuser 6778
			unset($conf["fileAccess::getInternetAddress"]);
6779
 
3 liveuser 6780
			#如果將檔案的位置名稱變成網址失敗
6781
			if($getInternetAddress["status"]=="false"){
226 liveuser 6782
 
3 liveuser 6783
				#設置錯誤識別
6784
				$result["status"]="false";
226 liveuser 6785
 
3 liveuser 6786
				#設置錯誤訊息
6787
				$result["error"]=$getInternetAddress;
226 liveuser 6788
 
3 liveuser 6789
				#回傳結果
6790
				return $result;
226 liveuser 6791
 
6792
				}#if end
6793
 
3 liveuser 6794
			#置換目標位置為檔案系統路徑的絕對位置
6795
			$conf["position"]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 6796
 
6797
			}#if end
6798
 
6799
		#如果目標是資料夾
3 liveuser 6800
		if(is_dir($conf["position"])) {
226 liveuser 6801
 
3 liveuser 6802
			#設置為資料夾
6803
			$result["folder"]="true";
226 liveuser 6804
 
3 liveuser 6805
			#如果開啟資料夾成功
6806
			if($dh=opendir($conf["position"])){
226 liveuser 6807
 
3 liveuser 6808
				#初始化計數變數
6809
				$count=0;
226 liveuser 6810
 
3 liveuser 6811
				#如果資料夾裡面有檔案
6812
				while(($fileName=readdir($dh))!==false){
226 liveuser 6813
 
3 liveuser 6814
					#debug
6815
					#echo "有檔案";
226 liveuser 6816
 
3 liveuser 6817
					#如果名稱是「.」或「..」
6818
					if($fileName=="." || $fileName==".."){
226 liveuser 6819
 
3 liveuser 6820
						#則跳過
6821
						continue;
226 liveuser 6822
 
3 liveuser 6823
						}#if end
226 liveuser 6824
 
3 liveuser 6825
					#取得檔案或子目錄名稱
226 liveuser 6826
					$result["content"][$count]["name"]=$fileName;
6827
 
3 liveuser 6828
					#取得詳細資訊
6829
					#函式說明:
6830
					#取得節點的資訊.
6831
					#回傳結果:
6832
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6833
					#$result["error"],錯誤訊息陣列.
226 liveuser 6834
					#$result["function"],函數名稱.
3 liveuser 6835
					#$result["content"],檔案資訊陣列.
226 liveuser 6836
					#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 6837
					#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
6838
					#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
6839
					#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
6840
					#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
6841
					#$result["content"]["ownerName"],檔案擁有着資訊.
6842
					#$result["content"]["groupName"],檔案所屬擁有着資訊.
6843
					#$result["content"]["size"],檔案大小.
6844
					#$result["content"]["modifyDate"],檔案變更年月日.
6845
					#$result["content"]["modifyTime"],檔案變更時分秒.
6846
					#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
6847
					#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
6848
					#必填參數:
6849
					#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
6850
					$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];
6851
					#$conf["file"],字串,要查看擁有者資訊的檔案.
6852
					$conf["fileAccess::fileInfo"]["file"]=$conf["position"]."/".$fileName;
6853
					#可省略參數:
6854
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
6855
					$conf["fileAccess::fileInfo"]["web"]="false";
6856
					#參考資料:
6857
					#fileowner=>http://php.net/manual/en/function.fileowner.php
6858
					#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
6859
					#備註:
6860
					#無.
6861
					$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
6862
					unset($conf["fileAccess::fileInfo"]);
226 liveuser 6863
 
3 liveuser 6864
					#如果執行失敗
6865
					if($fileInfo["status"]=="false"){
226 liveuser 6866
 
3 liveuser 6867
						#設置錯誤識別
6868
						$result["status"]="false";
226 liveuser 6869
 
3 liveuser 6870
						#設置錯誤訊息
6871
						$result["error"]=$fileInfo;
226 liveuser 6872
 
3 liveuser 6873
						#回傳結果
6874
						return $result;
226 liveuser 6875
 
3 liveuser 6876
						}#if end
226 liveuser 6877
 
3 liveuser 6878
					#設置是否為資料夾
6879
					$result["content"][$count]["folder"]=$fileInfo["content"]["is_folder"];
226 liveuser 6880
 
3 liveuser 6881
					#設置使用者的權限
6882
					$result["content"][$count]["ownerPerm"]=$fileInfo["content"]["ownerPerm"];
226 liveuser 6883
 
3 liveuser 6884
					#設置群組的權限
6885
					$result["content"][$count]["groupPerm"]=$fileInfo["content"]["groupPerm"];
226 liveuser 6886
 
3 liveuser 6887
					#設置其他使用者的權限
6888
					$result["content"][$count]["otherPerm"]=$fileInfo["content"]["otherPerm"];
226 liveuser 6889
 
3 liveuser 6890
					#設置其擁有者賬戶
6891
					$result["content"][$count]["ownerName"]=$fileInfo["content"]["ownerName"];
226 liveuser 6892
 
3 liveuser 6893
					#設置其群組擁有者賬戶
6894
					$result["content"][$count]["groupName"]=$fileInfo["content"]["groupName"];
226 liveuser 6895
 
3 liveuser 6896
					#計數加1
6897
					$count++;
226 liveuser 6898
 
3 liveuser 6899
					}#while
226 liveuser 6900
 
3 liveuser 6901
				#關閉資料夾
6902
				closedir($dh);
226 liveuser 6903
 
3 liveuser 6904
				}#if end
226 liveuser 6905
 
6906
			#開啟資料夾失敗
3 liveuser 6907
			else{
226 liveuser 6908
 
3 liveuser 6909
				#設置執行失敗
6910
				$result["status"]="false";
226 liveuser 6911
 
3 liveuser 6912
				#設置執行錯誤訊息
6913
				$result["error"][]="開啟資料夾「".$conf["position"]."」失敗";
6914
 
6915
				#回傳結果
6916
				return $result;
226 liveuser 6917
 
3 liveuser 6918
				}#else end
226 liveuser 6919
 
3 liveuser 6920
			}#if end
226 liveuser 6921
 
3 liveuser 6922
		#反之是檔案
6923
		else{
226 liveuser 6924
 
3 liveuser 6925
			#設置不為目錄
6926
			$result["folder"]="false";
226 liveuser 6927
 
3 liveuser 6928
			}#else end
226 liveuser 6929
 
3 liveuser 6930
		#取得目前位置
226 liveuser 6931
		$result["position"]=$conf["position"];
6932
 
3 liveuser 6933
		#執行到這邊代表執行正常
6934
		$result["status"]="true";
226 liveuser 6935
 
3 liveuser 6936
		#回傳結果
226 liveuser 6937
		return $result;
3 liveuser 6938
 
6939
		}#function getList end
226 liveuser 6940
 
3 liveuser 6941
	/*
6942
	#函式說明:
6943
	#取得目錄底下所有目錄與檔案的樹狀結構.
6944
	#回傳結果:
6945
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6946
	#$result["error"],錯誤訊息陣列.
6947
	#$result["function"],函數名稱.
6948
	#$result["content"],陣列,檔案目錄的樹狀結構.
6949
	#必填參數:
6950
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6951
	$conf["position"]="";
6952
	#可省略參數:
6953
	#無.
6954
	#參考資料:
6955
	#無.
6956
	#備註:
6957
	#無.
6958
	*/
6959
	public static function exportListTree(&$conf){
226 liveuser 6960
 
3 liveuser 6961
		#初始化要回傳的結果
6962
		$result=array();
226 liveuser 6963
 
3 liveuser 6964
		#設置當其函數名稱
6965
		$result["function"]=__FUNCTION__;
226 liveuser 6966
 
3 liveuser 6967
		#如果 $conf 不為陣列
6968
		if(gettype($conf)!="array"){
226 liveuser 6969
 
3 liveuser 6970
			#設置執行失敗
6971
			$result["status"]="false";
226 liveuser 6972
 
3 liveuser 6973
			#設置執行錯誤訊息
6974
			$result["error"][]="\$conf變數須為陣列形態";
6975
 
6976
			#如果傳入的參數為 null
6977
			if($conf==null){
226 liveuser 6978
 
3 liveuser 6979
				#設置執行錯誤訊息
6980
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6981
 
3 liveuser 6982
				}#if end
6983
 
6984
			#回傳結果
6985
			return $result;
226 liveuser 6986
 
3 liveuser 6987
			}#if end
226 liveuser 6988
 
3 liveuser 6989
		#檢查必填參數
6990
		#函式說明:
6991
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6992
		#回傳的結果:
6993
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6994
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6995
		#$result["function"],當前執行的函式名稱.
6996
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6997
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6998
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6999
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7000
		#必填寫的參數:
7001
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
7002
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
7003
		#可以省略的參數:
226 liveuser 7004
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 7005
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
7006
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
7007
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 7008
 
3 liveuser 7009
		#如果檢查失敗
7010
		if($checkResult["status"]=="false"){
226 liveuser 7011
 
3 liveuser 7012
			#設置錯誤識別
7013
			$result["status"]="false";
226 liveuser 7014
 
3 liveuser 7015
			#設置錯誤訊息
7016
			$result["error"]=$checkResult;
226 liveuser 7017
 
3 liveuser 7018
			#回傳結果
7019
			return $result;
226 liveuser 7020
 
3 liveuser 7021
			}#if end
226 liveuser 7022
 
3 liveuser 7023
		#如果檢查不通過
7024
		if($checkResult["passed"]=="false"){
226 liveuser 7025
 
3 liveuser 7026
			#設置錯誤識別
7027
			$result["status"]="false";
226 liveuser 7028
 
3 liveuser 7029
			#設置錯誤訊息
7030
			$result["error"]=$checkResult;
226 liveuser 7031
 
3 liveuser 7032
			#回傳結果
7033
			return $result;
226 liveuser 7034
 
3 liveuser 7035
			}#if end
226 liveuser 7036
 
3 liveuser 7037
		#函式說明:
7038
		#取得目錄底下所有目錄與檔案的樹狀結構.
7039
		#回傳結果:
7040
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7041
		#$result["error"],錯誤訊息陣列.
7042
		#$result["function"],函數名稱.
7043
		#$result["content"],陣列,檔案目錄的樹狀結構.
7044
		#必填參數:
7045
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
7046
		$conf["fileAccess::getListTree"]["position"]=$conf["position"];
7047
		#可省略參數:
7048
		#無
7049
		#備註:
226 liveuser 7050
		#若檔案與目錄的名稱含有「[」與「]」與「(」與「)」將會無法取得其目錄底下的內容
3 liveuser 7051
		#若檔案與目錄的名稱含有「 」將會無法檢查檔案是否存在
7052
		#改用opendir()函數應該可以解決大部分的bug.
7053
		$getListTree=fileAccess::getListTree($conf["fileAccess::getListTree"]);
7054
		unset($conf["fileAccess::getListTree"]);
226 liveuser 7055
 
3 liveuser 7056
		#如果取得 目標目錄底下所有目錄與檔案的樹狀結構 失敗
7057
		if($getListTree["status"]==="false"){
226 liveuser 7058
 
3 liveuser 7059
			#設置錯誤識別
7060
			$result["status"]="false";
226 liveuser 7061
 
3 liveuser 7062
			#設置錯誤訊息
7063
			$result["error"]=$getListTree;
226 liveuser 7064
 
3 liveuser 7065
			#回傳結果
7066
			return $result;
226 liveuser 7067
 
3 liveuser 7068
			}#if end
226 liveuser 7069
 
3 liveuser 7070
		#目標目錄底下有幾個
226 liveuser 7071
 
3 liveuser 7072
		}#function exportListTree end
7073
 
7074
	/*
7075
	#函式說明:
7076
	#解壓縮tar.xz檔案,解壓縮完畢後,tar.xz檔案會被移除.
7077
	#回傳結果:
7078
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7079
	#$result["error"],錯誤訊息陣列.
226 liveuser 7080
	#$result["function"],函數名稱.
3 liveuser 7081
	#必填參數:
7082
	#$conf["tarXzFile"],字串變數,壓縮檔的位置與名稱,副檔名".tar.xz"會自動補上.
7083
	$conf["tarXzFile"]="";
7084
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7085
	$conf["fileArgu"]=__FILE__;
7086
	#可省略參數:
7087
	#$conf["extractTo"],字串,要解壓縮到哪邊,預設為當前路徑"."
7088
	#$conf["extractTo"]=".";
7089
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7090
	#$conf["commentsArray"]=array("");
7091
	#參考資料:
7092
	#無.
7093
	#備註:
7094
	#無.
7095
	*/
7096
	public static function unpackTarXzFile(&$conf){
226 liveuser 7097
 
3 liveuser 7098
		#初始化要回傳的內容
7099
		$result=array();
226 liveuser 7100
 
3 liveuser 7101
		#記錄當前執行的函數名稱
7102
		$result["function"]=__FUNCTION__;
226 liveuser 7103
 
3 liveuser 7104
		#如果 $conf 不為陣列
7105
		if(gettype($conf)!="array"){
226 liveuser 7106
 
3 liveuser 7107
			#設置執行失敗
7108
			$result["status"]="false";
226 liveuser 7109
 
3 liveuser 7110
			#設置執行錯誤訊息
7111
			$result["error"][]="\$conf變數須為陣列形態";
7112
 
7113
			#如果傳入的參數為 null
7114
			if($conf==null){
226 liveuser 7115
 
3 liveuser 7116
				#設置執行錯誤訊息
7117
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7118
 
3 liveuser 7119
				}#if end
7120
 
7121
			#回傳結果
7122
			return $result;
226 liveuser 7123
 
3 liveuser 7124
			}#if end
226 liveuser 7125
 
3 liveuser 7126
		#檢查參數
7127
		#函式說明:
7128
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7129
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7130
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7131
		#$result["function"],當前執行的函式名稱.
7132
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7133
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7134
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7135
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7136
		#必填寫的參數:
7137
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7138
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7139
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7140
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","tarXzFile");
226 liveuser 7141
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7142
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
7143
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7144
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7145
		#可以省略的參數:
7146
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7147
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7148
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7149
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","extractTo");
226 liveuser 7150
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7151
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string");
7152
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7153
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,".");
7154
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7155
		#$conf["arrayCountEqualCheck"][]=array();
7156
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7157
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 7158
 
3 liveuser 7159
		#若檢查失敗
7160
		if($checkResult["status"]=="false"){
226 liveuser 7161
 
3 liveuser 7162
			#設置執行失敗
7163
			$result["status"]="false";
226 liveuser 7164
 
3 liveuser 7165
			#設置執行錯誤訊息
7166
			$result["error"]=$checkResult;
226 liveuser 7167
 
3 liveuser 7168
			#回傳結果
7169
			return $result;
226 liveuser 7170
 
3 liveuser 7171
			}#if end
226 liveuser 7172
 
3 liveuser 7173
		#若檢查不通過
7174
		if($checkResult["passed"]=="false"){
226 liveuser 7175
 
3 liveuser 7176
			#設置執行失敗
7177
			$result["status"]="false";
226 liveuser 7178
 
3 liveuser 7179
			#設置執行錯誤訊息
7180
			$result["error"]=$checkResult;
226 liveuser 7181
 
3 liveuser 7182
			#回傳結果
7183
			return $result;
226 liveuser 7184
 
3 liveuser 7185
			}#if end
226 liveuser 7186
 
3 liveuser 7187
		#如果 $conf["commentsArray"] 有設定
7188
		if(isset($conf["commentsArray"])){
226 liveuser 7189
 
3 liveuser 7190
			#印出提示文字
7191
			#函式說明:
7192
			#印出多行文字,結尾自動換行.
7193
			#回傳的結果:
7194
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
7195
			#$result["function"],當前執行的函數名稱.
7196
			#$result["error"],錯誤訊息陣列.
7197
			#必填參數:
7198
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
7199
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
7200
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
7201
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 7202
 
3 liveuser 7203
			#如果印出提示文字失敗
7204
			if($echoMultiLine["status"]=="false"){
226 liveuser 7205
 
3 liveuser 7206
				#設置執行失敗
7207
				$result["status"]="false";
226 liveuser 7208
 
3 liveuser 7209
				#設置執行錯誤訊息
7210
				$result["error"]=$echoMultiLine;
226 liveuser 7211
 
3 liveuser 7212
				#回傳結果
7213
				return $result;
226 liveuser 7214
 
3 liveuser 7215
				}#if end
226 liveuser 7216
 
3 liveuser 7217
			}#if end
226 liveuser 7218
 
3 liveuser 7219
		#檢查要移動的檔案是否存在
7220
		#函式說明:
7221
		#檢查多個檔案與資料夾是否存在.
7222
		#回傳的結果:
7223
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
7224
		#$result["error"],錯誤訊息陣列.
7225
		#$resutl["function"],當前執行的涵式名稱.
7226
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
7227
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
7228
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
7229
		#必填參數:
7230
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["tarXzFile"].".tar.xz");#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
7231
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7232
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
7233
		#參考資料來源:
7234
		#http://php.net/manual/en/function.file-exists.php
7235
		#http://php.net/manual/en/control-structures.foreach.php
7236
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
7237
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 7238
 
3 liveuser 7239
		#如果檢查失敗
7240
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 7241
 
3 liveuser 7242
			#設置執行失敗
7243
			$result["status"]="false";
226 liveuser 7244
 
3 liveuser 7245
			#設置執行錯誤訊息
7246
			$result["error"]=$checkMultiFileExist;
226 liveuser 7247
 
3 liveuser 7248
			#回傳結果
7249
			return $result;
226 liveuser 7250
 
7251
			}#if end
7252
 
3 liveuser 7253
		#如果來源檔案不存在
7254
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 7255
 
3 liveuser 7256
			#設置執行失敗
7257
			$result["status"]="false";
226 liveuser 7258
 
3 liveuser 7259
			#設置執行錯誤訊息
7260
			$result["error"][]="檔案「".$conf["tarXzFile"].".tar.xz」不存在";
226 liveuser 7261
 
3 liveuser 7262
			#回傳結果
7263
			return $result;
226 liveuser 7264
 
3 liveuser 7265
			}#if end
226 liveuser 7266
 
3 liveuser 7267
		#進行解壓縮xz檔
7268
		#函式說明:
7269
		#呼叫shell執行系統命令,並取得回傳的內容.
7270
		#回傳的結果:
7271
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7272
		#$result["error"],錯誤訊息陣列.
7273
		#$result["function"],當前執行的函數名稱.
7274
		#$result["cmd"],執行的指令內容.
7275
		#$result["output"],爲執行完二元碼後的輸出陣列.
7276
		#必填的參數
7277
		#$conf["command"],字串,要執行的指令與.
7278
		$conf["fileAccess::callShell"]["command"]="xz -v -v -d -f ".$conf["tarXzFile"].".tar.xz";
7279
		#可省略參數:
7280
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7281
		#$conf["fileAccess::callShell"]["argu"]=array();
7282
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7283
		#$conf["enablePrintDescription"]="true";
7284
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7285
		#$conf["printDescription"]="";
7286
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
7287
		#$conf["escapeshellarg"]="true";
7288
		#備註:
7289
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
7290
		#參考資料:
7291
		#exec=>http://php.net/manual/en/function.exec.php
7292
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7293
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7294
		$callShell=external::callShell($conf["fileAccess::callShell"]);
7295
		unset($conf["fileAccess::callShell"]);
226 liveuser 7296
 
3 liveuser 7297
		#如果解壓縮xz檔案失敗
7298
		if($callShell["status"]=="false"){
226 liveuser 7299
 
3 liveuser 7300
			#設置執行失敗
7301
			$result["status"]="false";
226 liveuser 7302
 
3 liveuser 7303
			#設置執行錯誤訊息
7304
			$result["error"]=$callShell;
226 liveuser 7305
 
3 liveuser 7306
			#回傳結果
7307
			return $result;
226 liveuser 7308
 
3 liveuser 7309
			}#if end
226 liveuser 7310
 
3 liveuser 7311
		#解壓縮tar檔
7312
		#函式說明:
7313
		#呼叫shell執行系統命令,並取得回傳的內容.
7314
		#回傳的結果:
7315
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7316
		#$result["error"],錯誤訊息陣列.
7317
		#$result["function"],當前執行的函數名稱.
7318
		#$result["cmd"],執行的指令內容.
7319
		#$result["output"],爲執行完二元碼後的輸出陣列.
7320
		#必填的參數
7321
		#$conf["command"],字串,要執行的指令與.
7322
		$conf["fileAccess::callShell"]["command"]="tar";
7323
		#可省略參數:
7324
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7325
		$conf["fileAccess::callShell"]["argu"]=array("-xvf",$conf["tarXzFile"]."tar",$conf["extractTo"]);
7326
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7327
		#$conf["enablePrintDescription"]="true";
7328
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7329
		#$conf["printDescription"]="";
7330
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
7331
		$conf["fileAccess::callShell"]["escapeshellarg"]="true";
7332
		#備註:
7333
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
7334
		#參考資料:
7335
		#exec=>http://php.net/manual/en/function.exec.php
7336
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7337
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7338
		$callShell=external::callShell($conf["fileAccess::callShell"]);
7339
		unset($conf["fileAccess::callShell"]);
226 liveuser 7340
 
3 liveuser 7341
		#如果解壓縮xz檔案失敗
7342
		if($callShell["status"]=="false"){
226 liveuser 7343
 
3 liveuser 7344
			#設置執行失敗
7345
			$result["status"]="false";
226 liveuser 7346
 
3 liveuser 7347
			#設置執行錯誤訊息
7348
			$result["error"]=$callShell;
226 liveuser 7349
 
3 liveuser 7350
			#回傳結果
7351
			return $result;
226 liveuser 7352
 
3 liveuser 7353
			}#if end
226 liveuser 7354
 
3 liveuser 7355
		#移除tar檔
7356
		#函式說明:
7357
		#移除檔案
7358
		#回傳結果:
7359
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7360
		#$result["error"],錯誤訊息陣列
7361
		#$result["warning"],警告訊息陣列
7362
		#$result["function"],當前執行的函數名稱
7363
		#必填參數:
7364
		$conf["fileAccess::delFile"]["fileAddress"]=$conf["tarXzFile"].".tar";#要移除檔案的位置
7365
		#可省略參數:
7366
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7367
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
7368
		#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7369
		#$conf["commentsArray"]=array("");
7370
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
226 liveuser 7371
		unset($conf["fileAccess::delFile"]);
7372
 
3 liveuser 7373
		#如果移除檔案失敗
7374
		if($delFile["status"]=="false"){
226 liveuser 7375
 
3 liveuser 7376
			#設置執行失敗
7377
			$result["status"]="false";
226 liveuser 7378
 
3 liveuser 7379
			#設置執行錯誤訊息
7380
			$result["error"]=$delFile;
226 liveuser 7381
 
3 liveuser 7382
			#回傳結果
7383
			return $result;
226 liveuser 7384
 
7385
			}#if end
7386
 
3 liveuser 7387
		#執行到這邊代表執行正常
7388
		$result["status"]="true";
226 liveuser 7389
 
3 liveuser 7390
		#回傳結果
7391
		return $result;
226 liveuser 7392
 
3 liveuser 7393
		}#function unpackTarXzFile end
7394
 
7395
	/*
7396
	#函式說明:
7397
	#用data:mimeType;base64,fileVar的形式來提供檔案的連結,亦即檔案儲存在變數裡面.
7398
	#回傳結果:
7399
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7400
	#$result["error"],錯誤訊息
7401
	#$result["content"],檔案變數的內容
7402
	#$result["fileTypeName"],副檔名,ex:「.tar.xz」.
226 liveuser 7403
	#$result["function"],當前執行的函數名稱
3 liveuser 7404
	#必填參數:
7405
	#$conf["filePosition"],要轉存成2元碼的檔案位置與名稱
7406
	$conf["filePosition"]="";
7407
	#$conf["mimeType"],2元碼的內容是什麼
7408
	$conf["mimeType"]="";
7409
	#可省略參數:
7410
	#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
7411
	#$conf["compressType"]="base64";
7412
	#$conf["delFile"],讀取完檔案後,要移除檔案嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
7413
	#$conf["delFile"]="false";
7414
	#參考資料:
7415
	#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
7416
	#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
7417
	#備註:
7418
	#無.
7419
	*/
7420
	public static function data(&$conf){
226 liveuser 7421
 
3 liveuser 7422
		#初始化要回傳的內容
7423
		$result=array();
226 liveuser 7424
 
3 liveuser 7425
		#取得當前執行的函數名稱
7426
		$result["function"]=__FUNCTION__;
226 liveuser 7427
 
3 liveuser 7428
		#如果 $conf 不為陣列
7429
		if(gettype($conf)!="array"){
226 liveuser 7430
 
3 liveuser 7431
			#設置執行失敗
7432
			$result["status"]="false";
226 liveuser 7433
 
3 liveuser 7434
			#設置執行錯誤訊息
7435
			$result["error"][]="\$conf變數須為陣列形態";
7436
 
7437
			#如果傳入的參數為 null
7438
			if($conf==null){
226 liveuser 7439
 
3 liveuser 7440
				#設置執行錯誤訊息
7441
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7442
 
3 liveuser 7443
				}#if end
7444
 
7445
			#回傳結果
7446
			return $result;
226 liveuser 7447
 
3 liveuser 7448
			}#if end
226 liveuser 7449
 
3 liveuser 7450
		#檢查參數
7451
		#函式說明:
7452
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7453
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7454
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7455
		#$result["function"],當前執行的函式名稱.
7456
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7457
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7458
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7459
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7460
		#必填寫的參數:
7461
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7462
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7463
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7464
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePosition");
226 liveuser 7465
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7466
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7467
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7468
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7469
		#可以省略的參數:
7470
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7471
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7472
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7473
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mimeType","compressType","delFile");
226 liveuser 7474
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7475
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
7476
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,「null」代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7477
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("null","base64","false");
7478
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7479
		#$conf["arrayCountEqualCheck"][]=array();
7480
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7481
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 7482
 
3 liveuser 7483
		#如果檢查參數失敗
7484
		if($checkResult["status"]=="false"){
226 liveuser 7485
 
3 liveuser 7486
			#設置執行失敗
7487
			$result["status"]="false";
226 liveuser 7488
 
3 liveuser 7489
			#設置錯誤訊息
7490
			$result["error"]=$checkResult;
226 liveuser 7491
 
3 liveuser 7492
			#回傳結果
7493
			return $result;
226 liveuser 7494
 
3 liveuser 7495
			}#if end
226 liveuser 7496
 
3 liveuser 7497
		#如果檢查參數不通過
7498
		if($checkResult["passed"]=="false"){
226 liveuser 7499
 
3 liveuser 7500
			#設置執行失敗
7501
			$result["status"]="false";
226 liveuser 7502
 
3 liveuser 7503
			#設置錯誤訊息
7504
			$result["error"]=$checkResult;
226 liveuser 7505
 
3 liveuser 7506
			#回傳結果
7507
			return $result;
226 liveuser 7508
 
3 liveuser 7509
			}#if end
226 liveuser 7510
 
3 liveuser 7511
		#依據檔案名稱取得副檔名 $result["fileTypeName"]
7512
		#函式說明:
7513
		#將固定格式的字串分開,並回傳分開的結果。
7514
		#回傳的參數:
7515
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7516
		#$result["error"],錯誤訊息陣列
7517
		#$result["function"],當前執行的函數名稱.
7518
		#$result["oriStr"],要分割的原始字串內容
7519
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7520
		#$result["dataCounts"],爲總共分成幾段
7521
		#必填參數:
7522
		$conf["stringProcess::spiltString"]["stringIn"]=basename($conf["filePosition"]);#要處理的字串。
7523
		$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
7524
		#備註:
7525
		#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
7526
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
7527
		unset($conf["stringProcess::spiltString"]);
226 liveuser 7528
 
3 liveuser 7529
		#如果分割字串失敗
7530
		if($spiltString["status"]=="false"){
226 liveuser 7531
 
3 liveuser 7532
			#設置執行失敗
7533
			$result["status"]="false";
226 liveuser 7534
 
3 liveuser 7535
			#設置錯誤訊息
7536
			$result["error"]=$spiltString;
226 liveuser 7537
 
3 liveuser 7538
			#回傳結果
7539
			return $result;
226 liveuser 7540
 
3 liveuser 7541
			}#if end
226 liveuser 7542
 
3 liveuser 7543
		#初始化副檔名
226 liveuser 7544
		$result["fileTypeName"]="";
7545
 
3 liveuser 7546
		#如果只有一段代表沒有副檔名
7547
		if($spiltString["dataCounts"]==1){
226 liveuser 7548
 
3 liveuser 7549
			#副檔名設置為 "unknow"
7550
			$result["fileTypeName"]="unknow";
226 liveuser 7551
 
3 liveuser 7552
			}#if end
226 liveuser 7553
 
3 liveuser 7554
		#不符合以上條件,但至少有兩段
7555
		else if($spiltString["dataCounts"]>=2){
226 liveuser 7556
 
3 liveuser 7557
			#執行 $spiltString["dataCounts"] 減一次的迴圈
7558
			for($i=1;$i<$spiltString["dataCounts"];$i++){
226 liveuser 7559
 
3 liveuser 7560
				#串接副檔名
7561
				$result["fileTypeName"]=$result["fileTypeName"].".".$spiltString["dataArray"][$i];
226 liveuser 7562
 
3 liveuser 7563
				}#for end
226 liveuser 7564
 
3 liveuser 7565
			}#if end
226 liveuser 7566
 
3 liveuser 7567
		#讀取檔案內容
7568
		$fileBin=file_get_contents($conf["filePosition"],"rb");
226 liveuser 7569
 
3 liveuser 7570
		#編碼檔案
7571
		$base64fileBin=base64_encode($fileBin);
226 liveuser 7572
 
3 liveuser 7573
		#如果 $conf["delFile"] 等於 "true"
7574
		if($conf["delFile"]=="true"){
226 liveuser 7575
 
3 liveuser 7576
			#移除檔案
7577
			#函式說明:
7578
			#移除檔案
7579
			#回傳結果:
7580
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7581
			#$result["error"],錯誤訊息陣列
7582
			#$result["warning"],警告訊息陣列
7583
			#$result["function"],當前執行的函數名稱
7584
			#必填參數:
7585
			$conf["fileAccess::delFile"]["fileAddress"]=$conf["filePosition"];#要移除檔案的位置
7586
			$del=fileAccess::delFile($conf["fileAccess::delFile"]);
7587
			unset($conf["fileAccess::delFile"]);
226 liveuser 7588
 
3 liveuser 7589
			#如果移除圖片失敗
7590
			if($del["status"]=="false"){
226 liveuser 7591
 
3 liveuser 7592
				#設置執行失敗
7593
				$result["status"]="false";
226 liveuser 7594
 
3 liveuser 7595
				#設置錯誤訊息
7596
				$result["error"]=$del;
226 liveuser 7597
 
3 liveuser 7598
				#回傳結果
7599
				return $result;
226 liveuser 7600
 
3 liveuser 7601
				}#if end
226 liveuser 7602
 
3 liveuser 7603
			}#if end
226 liveuser 7604
 
3 liveuser 7605
		#放置檔案的語法
7606
		$result["content"]="data:".$conf["mimeType"].";".$conf["compressType"].",".$base64fileBin;
226 liveuser 7607
 
3 liveuser 7608
		#執行到這邊代表執行正常
7609
		$result["status"]="true";
226 liveuser 7610
 
3 liveuser 7611
		#回傳結果
7612
		return $result;
226 liveuser 7613
 
3 liveuser 7614
		}#function data end
7615
 
7616
	/*
7617
	#函式說明:
7618
	#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
7619
	#回傳結果:
7620
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7621
	#$result["error"],錯誤訊息陣列.
226 liveuser 7622
	#$result["function"],函數名稱.
3 liveuser 7623
	#$result["argu"],使用的參數.
7624
	#$result["content"],網址,若是在命令列執行,則為"null".
7625
	#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
7626
	#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
7627
	#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
7628
	#必填參數:
7629
	#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
7630
	$conf["address"]="";
7631
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7632
	$conf["fileArgu"]=__FILE__;
7633
	#可省略參數:
7634
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
7635
	#$conf["userDir"]="true";
7636
	#參考資料:
7637
	#無.
7638
	#備註:
7639
	#無.
7640
	*/
7641
	public static function getInternetAddress(&$conf){
226 liveuser 7642
 
3 liveuser 7643
		#初始化要回傳的變數
7644
		$result=array();
226 liveuser 7645
 
3 liveuser 7646
		#記錄當前執行的函數名稱
7647
		$result["function"]=__FUNCTION__;
226 liveuser 7648
 
3 liveuser 7649
		#如果 $conf 不為陣列
7650
		if(gettype($conf)!="array"){
226 liveuser 7651
 
3 liveuser 7652
			#設置執行失敗
7653
			$result["status"]="false";
226 liveuser 7654
 
3 liveuser 7655
			#設置執行錯誤訊息
7656
			$result["error"][]="\$conf變數須為陣列形態";
7657
 
7658
			#如果傳入的參數為 null
7659
			if($conf==null){
226 liveuser 7660
 
3 liveuser 7661
				#設置執行錯誤訊息
7662
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7663
 
3 liveuser 7664
				}#if end
7665
 
7666
			#回傳結果
7667
			return $result;
226 liveuser 7668
 
3 liveuser 7669
			}#if end
7670
 
7671
		#取得使用的參數
7672
		$result["argu"]=$conf;
226 liveuser 7673
 
3 liveuser 7674
		#檢查參數
7675
		#函式說明:
7676
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7677
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7678
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7679
		#$result["function"],當前執行的函式名稱.
7680
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7681
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7682
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7683
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7684
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7685
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7686
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7687
		#必填寫的參數:
7688
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7689
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7690
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7691
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("address","fileArgu");
226 liveuser 7692
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7693
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
7694
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7695
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7696
		#可以省略的參數:
7697
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7698
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7699
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7700
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("userDir");
226 liveuser 7701
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7702
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
7703
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7704
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
7705
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7706
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
7707
		#參考資料來源:
7708
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7709
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7710
		unset($conf["variableCheck::checkArguments"]);
7711
 
7712
		#如果檢查失敗
7713
		if($checkResult["status"]==="false"){
226 liveuser 7714
 
3 liveuser 7715
			#設置錯誤狀態
7716
			$result["status"]="false";
226 liveuser 7717
 
3 liveuser 7718
			#設置錯誤提示
7719
			$result["error"]=$checkResult;
226 liveuser 7720
 
3 liveuser 7721
			#回傳結果
7722
			return $result;
226 liveuser 7723
 
3 liveuser 7724
			}#if end
7725
 
7726
		#如果檢查不通過
7727
		if($checkResult["passed"]==="false"){
226 liveuser 7728
 
3 liveuser 7729
			#設置錯誤狀態
7730
			$result["status"]="false";
226 liveuser 7731
 
3 liveuser 7732
			#設置錯誤提示
7733
			$result["error"]=$checkResult;
226 liveuser 7734
 
3 liveuser 7735
			#回傳結果
7736
			return $result;
226 liveuser 7737
 
3 liveuser 7738
			}#if end
226 liveuser 7739
 
3 liveuser 7740
		#如果是本來就是網址了
7741
		if(strpos($conf["address"],'https://')===0 || strpos($conf["address"],'http://')===0){
226 liveuser 7742
 
3 liveuser 7743
			#設置執行正常
7744
			$result["status"]="true";
226 liveuser 7745
 
3 liveuser 7746
			#取得網址
7747
			$result["content"]=$conf["address"];
226 liveuser 7748
 
3 liveuser 7749
			#回傳結果
226 liveuser 7750
			return $result;
7751
 
7752
			}#if end
7753
 
3 liveuser 7754
		#解析 $conf["fileArgu"]
7755
		#函式說明:
7756
		#將固定格式的字串分開,並回傳分開的結果。
7757
		#回傳的參數:
7758
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7759
		#$result["error"],錯誤訊息陣列
7760
		#$result["function"],當前執行的函數名稱.
7761
		#$result["oriStr"],要分割的原始字串內容
7762
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7763
		#$result["dataCounts"],爲總共分成幾段
7764
		#必填參數:
7765
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
7766
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7767
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7768
		unset($conf["stringProcess::spiltString"]);
7769
 
3 liveuser 7770
		#如果分割字串失敗
7771
		if($spiltString["status"]==="false"){
226 liveuser 7772
 
3 liveuser 7773
			#設置錯誤狀態
7774
			$result["status"]="false";
226 liveuser 7775
 
3 liveuser 7776
			#設置錯誤提示
7777
			$result["error"]=$spiltString;
226 liveuser 7778
 
3 liveuser 7779
			#回傳結果
7780
			return $result;
226 liveuser 7781
 
3 liveuser 7782
			}#if end
226 liveuser 7783
 
3 liveuser 7784
		#函式說明:
7785
		#將多個路徑字串變成相對於當前路徑的相對路徑字串
7786
		#回傳結果:
7787
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7788
		#$result["error"],錯誤訊息陣列.
226 liveuser 7789
		#$result["function"],函數名稱.
3 liveuser 7790
		#$result["content"],字串陣列,多個轉換好的相對路徑字串.
7791
		#必填參數:
7792
		#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
7793
		$conf["fileAccess::getRelativePath"]["path"]=array($conf["address"]);
7794
		#$conf["fileArgu"],字串,當前路徑.
7795
		$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
7796
		$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
7797
		unset($conf["fileAccess::getRelativePath"]);
226 liveuser 7798
 
3 liveuser 7799
		#如果取得相對位置失敗
7800
		if($getRelativePath["status"]==="false"){
226 liveuser 7801
 
3 liveuser 7802
			#設置錯誤狀態
7803
			$result["status"]="false";
226 liveuser 7804
 
3 liveuser 7805
			#設置錯誤提示
7806
			$result["error"]=$getRelativePath;
226 liveuser 7807
 
3 liveuser 7808
			#回傳結果
7809
			return $result;
226 liveuser 7810
 
7811
			}#if end
7812
 
3 liveuser 7813
		#取得轉換成相對路徑的位置
7814
		$result["fileSystemRelativePosition"]=$getRelativePath["content"][0];
226 liveuser 7815
 
3 liveuser 7816
		#解析 $conf["fileArgu"]
7817
		#函式說明:
7818
		#將固定格式的字串分開,並回傳分開的結果。
7819
		#回傳的參數:
7820
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7821
		#$result["error"],錯誤訊息陣列
7822
		#$result["function"],當前執行的函數名稱.
7823
		#$result["oriStr"],要分割的原始字串內容
7824
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7825
		#$result["dataCounts"],爲總共分成幾段
7826
		#必填參數:
7827
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
7828
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7829
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7830
		unset($conf["stringProcess::spiltString"]);
7831
 
3 liveuser 7832
		#如果分割字串失敗
7833
		if($spiltString["status"]==="false"){
226 liveuser 7834
 
3 liveuser 7835
			#設置錯誤狀態
7836
			$result["status"]="false";
226 liveuser 7837
 
3 liveuser 7838
			#設置錯誤提示
7839
			$result["error"]=$spiltString;
226 liveuser 7840
 
3 liveuser 7841
			#回傳結果
7842
			return $result;
226 liveuser 7843
 
3 liveuser 7844
			}#if end
226 liveuser 7845
 
3 liveuser 7846
		#debug
7847
		#var_dump($spiltString);
7848
		#var_dump($_SERVER);
7849
 
7850
		#初始化檔案在伺服器上的檔案系統位置
7851
		$result["fileSystemAbsoulutePosition"]="/";
226 liveuser 7852
 
3 liveuser 7853
		#將最後一段捨棄
7854
		for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7855
 
3 liveuser 7856
			$result["fileSystemAbsoulutePosition"]=$result["fileSystemAbsoulutePosition"].$spiltString["dataArray"][$i]."/";
226 liveuser 7857
 
7858
			}#for end
7859
 
3 liveuser 7860
		#取得非直觀的絕對位置
7861
		$result["fileSystemAbsoulutePosition"]=$result["fileSystemAbsoulutePosition"].$result["fileSystemRelativePosition"];
226 liveuser 7862
 
3 liveuser 7863
		#將檔案的相對路徑進行整理,變成可以直接讀的路徑.
7864
		#函式說明:
7865
		#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
7866
		#回傳的結果:
7867
		#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
7868
		#$result["function"],當前執行的函數.
7869
		#$result["error"],錯誤訊息陣列.
7870
		#$result["changedPath"],處理完後回傳的目錄字串.
7871
		#$result["oriPath"],原始的路徑字串
7872
		#必填參數:
7873
		#$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"],字串,要處理的檔案目錄字串.
7874
		$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$result["fileSystemAbsoulutePosition"];
7875
		$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
7876
		unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 7877
 
3 liveuser 7878
		#如果處理失敗
7879
		if($changeDirByDotDotSolidus["status"]==="false"){
226 liveuser 7880
 
3 liveuser 7881
			#設置錯誤狀態
7882
			$result["status"]="false";
226 liveuser 7883
 
3 liveuser 7884
			#設置錯誤提示
7885
			$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 7886
 
3 liveuser 7887
			#回傳結果
7888
			return $result;
226 liveuser 7889
 
3 liveuser 7890
			}#if end
226 liveuser 7891
 
3 liveuser 7892
		#改變為易讀的絕對路徑
226 liveuser 7893
		$result["fileSystemAbsoulutePosition"]=$changeDirByDotDotSolidus["changedPath"];
7894
 
3 liveuser 7895
		#如果 $conf["userDir"] 為 "true"
7896
		if($conf["userDir"]==="true"){
226 liveuser 7897
 
3 liveuser 7898
			#重設為 絕對路徑 [/~家目錄名稱」
7899
			$result["webPathFromRoot"]="/~".$spiltString["dataArray"][1];
226 liveuser 7900
 
3 liveuser 7901
			#從第四段到倒數第二段,將其內容合併
7902
			for($i=3;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7903
 
3 liveuser 7904
				$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$spiltString["dataArray"][$i];
226 liveuser 7905
 
3 liveuser 7906
				}#for end
226 liveuser 7907
 
3 liveuser 7908
			}#if end
226 liveuser 7909
 
3 liveuser 7910
		#反之 $conf["userDir"] 為 "false",
7911
		else{
226 liveuser 7912
 
3 liveuser 7913
			#重設為 ""
7914
			$result["webPathFromRoot"]="";
7915
 
226 liveuser 7916
			#可能的根目錄層級 - start
7917
 
3 liveuser 7918
			#解析 $conf["fileArgu"]
7919
			#函式說明:
7920
			#將固定格式的字串分開,並回傳分開的結果。
7921
			#回傳的參數:
7922
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7923
			#$result["error"],錯誤訊息陣列
7924
			#$result["function"],當前執行的函數名稱.
7925
			#$result["oriStr"],要分割的原始字串內容
7926
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7927
			#$result["dataCounts"],爲總共分成幾段
7928
			#必填參數:
7929
			$conf["stringProcess::spiltString"]["stringIn"]=$_SERVER["PHP_SELF"];#要處理的字串。
7930
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7931
			$keyWord=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7932
			unset($conf["stringProcess::spiltString"]);
3 liveuser 7933
 
7934
			#如果處理失敗
7935
			if($keyWord["status"]==="false"){
226 liveuser 7936
 
3 liveuser 7937
				#設置錯誤狀態
7938
				$result["status"]="false";
226 liveuser 7939
 
3 liveuser 7940
				#設置錯誤提示
7941
				$result["error"]=$keyWord;
226 liveuser 7942
 
3 liveuser 7943
				#回傳結果
7944
				return $result;
226 liveuser 7945
 
3 liveuser 7946
				}#if end
226 liveuser 7947
 
3 liveuser 7948
			#取得關鍵字
7949
			$keyWord=$keyWord["dataArray"][0];
7950
 
7951
			#預設層級為4層
7952
			$layer=4;
7953
 
7954
			#檢查每個絕對路徑片段
7955
			for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7956
 
3 liveuser 7957
				#如果路徑片段等於 $keyWord
7958
				if($spiltString["dataArray"][$i]===$keyWord){
226 liveuser 7959
 
3 liveuser 7960
					#取得層級
7961
					$layer=$i;
226 liveuser 7962
 
3 liveuser 7963
					#跳出迴圈
7964
					break;
7965
 
7966
					}#if end
226 liveuser 7967
 
3 liveuser 7968
				}#for end
7969
 
7970
			#可能的根目錄層級 - end
7971
 
7972
			#網頁於檔案系統中的存放路徑可能為「/var/www/html」,從第四段到倒數第二段,將其內容合併
7973
			for($i=$layer;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7974
 
3 liveuser 7975
				$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$spiltString["dataArray"][$i];
226 liveuser 7976
 
3 liveuser 7977
				}#for end
226 liveuser 7978
 
3 liveuser 7979
			}#else end
226 liveuser 7980
 
3 liveuser 7981
		#加上檔案的路徑
226 liveuser 7982
		$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$conf["address"];
7983
 
3 liveuser 7984
		#取得檔案位於網頁伺服器的絕對位置
7985
		#函式說明:
7986
		#取得用戶端的資訊,並依據需要寫入到資料表裡面
7987
		#回傳結果:
7988
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
7989
		#$result["error"],錯誤訊息.
7990
		#$result["function"],檔前執行的函數名稱.
7991
		#$result["userBrowserType"],爲使用者的瀏覽器資訊
7992
		#$result["userIp"],爲使用者的IP
7993
		#$result["serverIp"],為伺服器的IP
7994
		#$result["scheme"],通訊協定
7995
		#$result["serverPort"],伺服器給對外下載網頁的port
7996
		#$result["requestUri"],爲使用者要求的網址
7997
		#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
7998
		#$result["clientRequestIP"],用戶端要求的ip與port
7999
		#必填參數:
8000
		$conf["csInformation::getConnectionInfo"]["getAccount"]="false";#是否要取得帳號
8001
		#可省略參數:
8002
		#$conf["accountVar"]=$_SESSION["username"];#帳號儲存在哪個變數裏面,預設爲$_SESSION["username"]
8003
		#$conf["saveToDb"]="true";#是否要除儲存到資料庫,"true"為要儲存",預設為不儲存
8004
		#$conf["dbAddress"]=$dbAddress;;#爲mysql-Server的位置,若#$conf["saveToDb"]設為"true",則該參數為必填。
8005
		#$conf["dbAccount"]=$dbAccount;#爲用於連入mysql-Server時要使用的帳號,若#$conf["saveToDb"]設為"true",則該參數為必填。
8006
		#$conf["dbName"]=$dbName;#要選取的資料庫名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
8007
		#$conf["tableName"]="visitorInfo";#爲要插入資料的資料表名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
8008
		#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");#爲資料表的項目名稱,
8009
			#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
8010
			#寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間
8011
			#$conf["saveToDb"]設為"true",則該參數為必填。
8012
		#$conf["dbPassword"]=$dbPassword;#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
8013
		$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
226 liveuser 8014
		unset($conf["csInformation::getConnectionInfo"]);
8015
 
3 liveuser 8016
		#如果取得連線資訊失敗
8017
		if($getConnectionInfo["status"]==="false"){
226 liveuser 8018
 
3 liveuser 8019
			#設置錯誤狀態
8020
			$result["status"]="false";
226 liveuser 8021
 
3 liveuser 8022
			#設置錯誤提示
8023
			$result["error"]=$getConnectionInfo;
226 liveuser 8024
 
3 liveuser 8025
			#回傳結果
8026
			return $result;
226 liveuser 8027
 
3 liveuser 8028
			}#if end
226 liveuser 8029
 
3 liveuser 8030
		#如果運行環境為 "web"
8031
		if($getConnectionInfo["mode"]=="web"){
226 liveuser 8032
 
3 liveuser 8033
			#為絕對路徑加上通訊協定與ip與port
226 liveuser 8034
			#$result["content"]=$getConnectionInfo["scheme"]."://".$getConnectionInfo["serverIp"].":".$getConnectionInfo["serverPort"].$result["webPathFromRoot"];
8035
 
8036
			#為絕對路徑加上用戶端通訊協定與ip與port
3 liveuser 8037
			$result["content"]=$getConnectionInfo["scheme"]."://".$getConnectionInfo["clientRequestIP"].$result["webPathFromRoot"];
226 liveuser 8038
 
3 liveuser 8039
			}#if end
226 liveuser 8040
 
3 liveuser 8041
		#反之如果為 "cmd" 環境
8042
		else{
226 liveuser 8043
 
3 liveuser 8044
			$result["content"]="null";
226 liveuser 8045
 
3 liveuser 8046
			}#else end
226 liveuser 8047
 
3 liveuser 8048
		#設置執行正常
8049
		$result["status"]="true";
226 liveuser 8050
 
3 liveuser 8051
		#回傳結果
8052
		return $result;
226 liveuser 8053
 
3 liveuser 8054
		}#function getInternetAddress end
8055
 
8056
	/*
8057
	#函式說明:
8058
	#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
8059
	#回傳結果:
8060
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8061
	#$result["error"],錯誤訊息陣列.
226 liveuser 8062
	#$result["function"],函數名稱.
3 liveuser 8063
	#$result["argu"],使用的參數.
8064
	#$result["content"],網址,若是在命令列執行,則為"null".
8065
	#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
8066
	#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
8067
	#必填參數:
8068
	#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
8069
	$conf["address"]="";
8070
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8071
	$conf["fileArgu"]=__FILE__;
8072
	#可省略參數:
8073
	#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
8074
	#$conf["web"]="true";
8075
	#參考資料:
8076
	#無.
8077
	#備註:
8078
	#無.
8079
	*/
8080
	public static function getInternetAddressV2(&$conf){
226 liveuser 8081
 
3 liveuser 8082
		#初始化要回傳的變數
8083
		$result=array();
226 liveuser 8084
 
3 liveuser 8085
		#記錄當前執行的函數名稱
8086
		$result["function"]=__FUNCTION__;
226 liveuser 8087
 
3 liveuser 8088
		#取得參數
8089
		$result["argu"]=$conf;
226 liveuser 8090
 
3 liveuser 8091
		#檢查參數
8092
		#函式說明:
8093
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8094
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8095
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8096
		#$result["function"],當前執行的函式名稱.
8097
		#$result["argu"],設置給予的參數.
8098
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8099
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8100
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8101
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8102
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8103
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8104
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8105
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8106
		#必填寫的參數:
8107
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8108
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8109
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8110
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8111
		#可以省略的參數:
8112
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8113
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("address","fileArgu");
8114
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
8115
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
8116
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8117
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8118
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
8119
		#$conf["canNotBeEmpty"]=array();
8120
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
8121
		#$conf["canBeEmpty"]=array();
8122
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
8123
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
8124
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8125
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
8126
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8127
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
8128
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8129
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
8130
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
8131
		#$conf["disallowAllSkipableVarIsEmpty"]="";
8132
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
8133
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
8134
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8135
		#$conf["arrayCountEqualCheck"][]=array();
8136
		#參考資料來源:
8137
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8138
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8139
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 8140
 
3 liveuser 8141
		#如果檢查失敗
8142
		if($checkArguments["status"]==="false"){
226 liveuser 8143
 
3 liveuser 8144
			#設置錯誤狀態
8145
			$result["status"]="false";
226 liveuser 8146
 
3 liveuser 8147
			#設置錯誤提示
8148
			$result["error"]=$checkArguments;
226 liveuser 8149
 
3 liveuser 8150
			#回傳結果
8151
			return $result;
226 liveuser 8152
 
3 liveuser 8153
			}#if end
226 liveuser 8154
 
3 liveuser 8155
		#如果檢查不通過
8156
		if($checkArguments["passed"]==="false"){
226 liveuser 8157
 
3 liveuser 8158
			#設置錯誤狀態
8159
			$result["status"]="false";
226 liveuser 8160
 
3 liveuser 8161
			#設置錯誤提示
8162
			$result["error"]=$checkArguments;
226 liveuser 8163
 
3 liveuser 8164
			#回傳結果
8165
			return $result;
226 liveuser 8166
 
3 liveuser 8167
			}#if end
226 liveuser 8168
 
3 liveuser 8169
		#如果是本來就是網址了
8170
		if(strpos($conf["address"],'https://')===0 || strpos($conf["address"],'http://')===0){
226 liveuser 8171
 
3 liveuser 8172
			#取得網址
8173
			$result["content"]=$conf["address"];
226 liveuser 8174
 
3 liveuser 8175
			}#if end
226 liveuser 8176
 
3 liveuser 8177
		#反之是絕對或相對路徑
8178
		else{
226 liveuser 8179
 
3 liveuser 8180
			#確認 $conf["address"] 是否為 escaped 後的內容
8181
			#函式說明:
8182
			#判斷字串是否一定需要經過escapeshellarg才能為單一shell參數,並回傳可以成為單一shell參數的結果.
8183
			#回傳結果:
8184
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8185
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
8186
			#$result["function"],當前執行的函式名稱.
8187
			#$result["argu"],使用的參數.
8188
			#$result["content"],字串,單一shell參數.
8189
			#$result["escaped"],字串,"true"代表content為 escape後的結果;反之為"false".
8190
			#$result["urlEncodeStr"],字串,未被escape過的單一shell參數被url encode後的結果.
8191
			#必填參數:
8192
			#$conf["str"],字串,認為要為單一 shell參數的字串.
8193
			$conf["stringProcess::toSingleShellArg"]["str"]=$conf["address"];
8194
			#可省略參數:
8195
			#無.
8196
			#參考資料:
8197
			#無.
8198
			#備註:
8199
			#無.
8200
			$toSingleShellArg=stringProcess::toSingleShellArg($conf["stringProcess::toSingleShellArg"]);
8201
			unset($conf["stringProcess::toSingleShellArg"]);
226 liveuser 8202
 
3 liveuser 8203
			#如果執行失敗
8204
			if($toSingleShellArg["status"]==="false"){
226 liveuser 8205
 
3 liveuser 8206
				#設置錯誤狀態
8207
				$result["status"]="false";
226 liveuser 8208
 
3 liveuser 8209
				#設置錯誤提示
8210
				$result["error"]=$toSingleShellArg;
226 liveuser 8211
 
3 liveuser 8212
				#回傳結果
8213
				return $result;
226 liveuser 8214
 
3 liveuser 8215
				}#if end
226 liveuser 8216
 
3 liveuser 8217
			#取得不含escape字元的address參數
8218
			$conf["address"]=urldecode($toSingleShellArg["urlEncodeStr"]);
226 liveuser 8219
 
3 liveuser 8220
			#不是絕對位置
8221
			if(strpos($conf["address"],"/")!==0){
226 liveuser 8222
 
3 liveuser 8223
				#如果有這些參數
8224
				if( isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT']) ){
226 liveuser 8225
 
3 liveuser 8226
					#網址
8227
					$result["content"]=$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/".$conf["address"];
226 liveuser 8228
 
3 liveuser 8229
					}#if end
226 liveuser 8230
 
3 liveuser 8231
				#反之
8232
				else{
226 liveuser 8233
 
3 liveuser 8234
					#網址設置為 null
8235
					$result["content"]=null;
226 liveuser 8236
 
3 liveuser 8237
					}#else
226 liveuser 8238
 
3 liveuser 8239
				}#if end
226 liveuser 8240
 
3 liveuser 8241
			#反之是絕對位置
8242
			else{
226 liveuser 8243
 
3 liveuser 8244
				#移除開頭的 "/"
8245
				$conf["address"]=substr($conf["address"],1);
226 liveuser 8246
 
3 liveuser 8247
				#如果有這些參數
8248
				if( isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT']) ){
226 liveuser 8249
 
3 liveuser 8250
					#網址
8251
					$result["content"]=$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/".$conf["address"];
226 liveuser 8252
 
3 liveuser 8253
					}#if end
226 liveuser 8254
 
3 liveuser 8255
				#反之
8256
				else{
226 liveuser 8257
 
3 liveuser 8258
					#網址設置為 null
8259
					$result["content"]=null;
226 liveuser 8260
 
3 liveuser 8261
					}#else
226 liveuser 8262
 
3 liveuser 8263
				}#else end
226 liveuser 8264
 
3 liveuser 8265
			#取得 doc root;
8266
			$docRoot=$_SERVER['DOCUMENT_ROOT'];
226 liveuser 8267
 
3 liveuser 8268
			#如果不是網路環境
8269
			if($conf["web"]==="false"){
226 liveuser 8270
 
3 liveuser 8271
				#不採用 docRoot
8272
				$docRoot="";
226 liveuser 8273
 
3 liveuser 8274
				}#if end
226 liveuser 8275
 
3 liveuser 8276
			#如果不存在 DOCUMENT_ROOT 變數或 web 參數為 "false" 且為相對位置.
8277
			if( ($_SERVER['DOCUMENT_ROOT']==="" || $conf["web"]==="false") && (strpos($result["argu"]["address"],"/")!==0) ){
226 liveuser 8278
 
3 liveuser 8279
				#執行 "pwd" 取得當前位置
8280
				exec("pwd",$output,$status);
226 liveuser 8281
 
3 liveuser 8282
				#預設為`pwd`的結果加"/"
8283
				$docRoot=$output[0]."/";
226 liveuser 8284
 
8285
				}#if end
8286
 
3 liveuser 8287
			#如果是絕對位置
8288
			else if(strpos($result["argu"]["address"],"/")===0){
226 liveuser 8289
 
8290
				#補回 "/"
3 liveuser 8291
				$conf["address"]="/".$conf["address"];
226 liveuser 8292
 
3 liveuser 8293
				}#if end
226 liveuser 8294
 
3 liveuser 8295
			#針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
8296
			$result["fileSystemAbsoulutePosition"]=$docRoot.$conf["address"];
226 liveuser 8297
 
3 liveuser 8298
			}#else end
226 liveuser 8299
 
3 liveuser 8300
		#設置執行正常
226 liveuser 8301
		$result["status"]="true";
8302
 
3 liveuser 8303
		#回傳結果
8304
		return $result;
226 liveuser 8305
 
3 liveuser 8306
		}#function getInternetAddressV2 end
8307
 
8308
	/*
8309
	#函式說明:
8310
	#將含有「*」的檔案路徑名稱,變成多個符合條件的路徑檔案.
8311
	#回傳結果:
8312
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8313
	#$result["error"],錯誤訊息陣列.
226 liveuser 8314
	#$result["function"],函數名稱.
3 liveuser 8315
	#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
8316
	#必填參數:
8317
	#$conf["path"],字串,要解析含有「*」的檔案路徑字串.
8318
	$conf["path"]="";
8319
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8320
	$conf["fileArgu"]=__FILE__;
8321
	#可省略參數:
8322
	#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
8323
	#$conf["noDotStart"]="true";
8324
	#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
8325
	#$conf["noWaveEnd"]="true";
8326
	#參考資料:
8327
	#無.
8328
	#備註:
8329
	#無.
8330
	*/
8331
	public static function resolvePostionStringWhichContainStarSymbol(&$conf){
226 liveuser 8332
 
3 liveuser 8333
		#初始化要回傳的結果
8334
		$result=array();
226 liveuser 8335
 
3 liveuser 8336
		#設置當其函數名稱
8337
		$result["function"]=__FUNCTION__;
226 liveuser 8338
 
3 liveuser 8339
		#如果 $conf 不為陣列
8340
		if(gettype($conf)!="array"){
226 liveuser 8341
 
3 liveuser 8342
			#設置執行失敗
8343
			$result["status"]="false";
226 liveuser 8344
 
3 liveuser 8345
			#設置執行錯誤訊息
8346
			$result["error"][]="\$conf變數須為陣列形態";
8347
 
8348
			#如果傳入的參數為 null
8349
			if($conf==null){
226 liveuser 8350
 
3 liveuser 8351
				#設置執行錯誤訊息
8352
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 8353
 
3 liveuser 8354
				}#if end
8355
 
8356
			#回傳結果
8357
			return $result;
226 liveuser 8358
 
3 liveuser 8359
			}#if end
226 liveuser 8360
 
3 liveuser 8361
		#檢查參數
8362
		#函式說明:
8363
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8364
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8365
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8366
		#$result["function"],當前執行的函式名稱.
8367
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8368
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8369
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8370
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
8371
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8372
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8373
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8374
		#必填寫的參數:
8375
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8376
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8377
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8378
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 8379
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 8380
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
8381
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8382
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8383
		#可以省略的參數:
8384
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
8385
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8386
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8387
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noDotStart","noWaveEnd");
226 liveuser 8388
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 8389
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
8390
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8391
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","true");
8392
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8393
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
8394
		#參考資料來源:
8395
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8396
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8397
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 8398
 
3 liveuser 8399
		#如果 $checkResult["status"] 等於 "fasle"
8400
		if($checkResult["status"]==="false"){
226 liveuser 8401
 
3 liveuser 8402
			#設置錯誤識別
8403
			$result["status"]="false";
226 liveuser 8404
 
3 liveuser 8405
			#設置錯誤訊息
8406
			$result["error"]=$checkResult;
226 liveuser 8407
 
3 liveuser 8408
			#回傳結果
8409
			return $result;
226 liveuser 8410
 
3 liveuser 8411
			}#if end
226 liveuser 8412
 
3 liveuser 8413
		#如果 $checkResult["passed"] 等於 "fasle"
8414
		if($checkResult["passed"]==="false"){
226 liveuser 8415
 
3 liveuser 8416
			#設置錯誤識別
8417
			$result["status"]="false";
226 liveuser 8418
 
3 liveuser 8419
			#設置錯誤訊息
8420
			$result["error"]=$checkResult;
226 liveuser 8421
 
3 liveuser 8422
			#回傳結果
8423
			return $result;
226 liveuser 8424
 
3 liveuser 8425
			}#if end
226 liveuser 8426
 
3 liveuser 8427
		#轉換檔案路徑為相對於伺服器檔案系統的絕對路徑
8428
		#函式說明:
8429
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
8430
		#回傳結果:
8431
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8432
		#$result["error"],錯誤訊息陣列.
226 liveuser 8433
		#$result["function"],函數名稱.
3 liveuser 8434
		#$result["content"],網址.
8435
		#$result["localAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
8436
		#$result["fileSystemAbsoulutePosition"],針對伺服器檔案系統的絕對位置.
8437
		#必填參數:
8438
		#$conf["address"],字串,檔案的相對位置.
8439
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["path"];
8440
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8441
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
8442
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是.
8443
		$conf["fileAccess::getInternetAddress"]["userDir"]="true";
8444
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
8445
		unset($conf["fileAccess::getInternetAddress"]);
226 liveuser 8446
 
3 liveuser 8447
		#如果轉換路徑失敗
8448
		if($getInternetAddress["status"]=="false"){
226 liveuser 8449
 
3 liveuser 8450
			#設置錯誤識別
8451
			$result["status"]="false";
226 liveuser 8452
 
3 liveuser 8453
			#設置錯誤訊息
8454
			$result["error"]=$checkResult;
226 liveuser 8455
 
3 liveuser 8456
			#回傳結果
8457
			return $result;
226 liveuser 8458
 
3 liveuser 8459
			}#if end
226 liveuser 8460
 
3 liveuser 8461
		#取得轉換好的路徑
8462
		$conf["path"]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 8463
 
3 liveuser 8464
		#檢查檔案路徑字串是否含有「*」
8465
		#函式說明:
8466
		#檢查字串裡面有無指定的關鍵字
8467
		#回傳結果:
8468
		#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8469
		#$result["error"],錯誤訊息
8470
		#$result["function"],當前執行的函數名稱.
8471
		#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8472
		#$result["keyWordCount"],找到的關鍵字數量.
8473
		#必填參數:
8474
		$conf["search::findKeyWord"]["keyWord"]="*";#想要搜尋的關鍵字
8475
		$conf["search::findKeyWord"]["string"]=$conf["path"];#要被搜尋的字串內容
8476
		#可省略參數:
8477
		#$conf["fileAccess::findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8478
		$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8479
		unset($conf["search::findKeyWord"]);
226 liveuser 8480
 
3 liveuser 8481
		#如果尋找關鍵字出錯
8482
		if($findKeyWord["status"]=="false"){
226 liveuser 8483
 
3 liveuser 8484
			#設置錯誤識別
8485
			$result["status"]="false";
226 liveuser 8486
 
3 liveuser 8487
			#設置錯誤訊息
8488
			$result["error"]=$findKeyWord;
226 liveuser 8489
 
3 liveuser 8490
			#回傳結果
8491
			return $result;
226 liveuser 8492
 
3 liveuser 8493
			}#if end
226 liveuser 8494
 
3 liveuser 8495
		#如果含有「*」
8496
		if($findKeyWord["founded"]=="true"){
226 liveuser 8497
 
3 liveuser 8498
			#透過「/」分割路徑字串
8499
			#函式說明:
8500
			#將固定格式的字串分開,並回傳分開的結果。
8501
			#回傳的參數:
8502
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8503
			#$result["error"],錯誤訊息陣列
8504
			#$result["function"],當前執行的函數名稱.
8505
			#$result["oriStr"],要分割的原始字串內容
8506
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8507
			#$result["dataCounts"],爲總共分成幾段
8508
			#必填參數:
8509
			$conf["stringProcess::spiltString"]["stringIn"]=$conf["path"];#要處理的字串。
8510
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
8511
			$spiltPathStr=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8512
			unset($conf["stringProcess::spiltString"]);
226 liveuser 8513
 
3 liveuser 8514
			#如果分割字串失敗
8515
			if($spiltPathStr["status"]=="false"){
226 liveuser 8516
 
3 liveuser 8517
				#設置錯誤識別
8518
				$result["status"]="false";
226 liveuser 8519
 
3 liveuser 8520
				#設置錯誤訊息
8521
				$result["error"]=$spiltPathStr;
226 liveuser 8522
 
3 liveuser 8523
				#回傳結果
8524
				return $result;
226 liveuser 8525
 
3 liveuser 8526
				}#if end
226 liveuser 8527
 
3 liveuser 8528
			#初始化暫存展開後的檔案路徑字串
226 liveuser 8529
			$extendPath=array("");
8530
 
3 liveuser 8531
			#要解析的路徑分成幾段就執行幾次
8532
			foreach($spiltPathStr["dataArray"] as $pathPart){
226 liveuser 8533
 
3 liveuser 8534
				#檢查該段名稱是否有「*」
8535
				#函式說明:
8536
				#檢查字串裡面有無指定的關鍵字
8537
				#回傳結果:
8538
				#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8539
				#$result["error"],錯誤訊息
8540
				#$result["function"],當前執行的函數名稱.
8541
				#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8542
				#$result["keyWordCount"],找到的關鍵字數量.
8543
				#必填參數:
8544
				$conf["search::findKeyWord"]["keyWord"]="*";#想要搜尋的關鍵字
8545
				$conf["search::findKeyWord"]["string"]=$pathPart;#要被搜尋的字串內容
8546
				#可省略參數:
8547
				#$conf["fileAccess::findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8548
				$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8549
				unset($conf["search::findKeyWord"]);
226 liveuser 8550
 
3 liveuser 8551
				#如果尋找關鍵字出錯
8552
				if($findKeyWord["status"]=="false"){
226 liveuser 8553
 
3 liveuser 8554
					#設置錯誤識別
8555
					$result["status"]="false";
226 liveuser 8556
 
3 liveuser 8557
					#設置錯誤訊息
8558
					$result["error"]=$findKeyWord;
226 liveuser 8559
 
3 liveuser 8560
					#回傳結果
8561
					return $result;
226 liveuser 8562
 
8563
					}#if end
8564
 
3 liveuser 8565
				#如果不含「*」
8566
				if($findKeyWord["founded"]=="false"){
226 liveuser 8567
 
3 liveuser 8568
					#針對每個既有的路徑
8569
					for($i=0;$i<count($extendPath);$i++){
226 liveuser 8570
 
3 liveuser 8571
						#加上切割好的路徑
8572
						$extendPath[$i]=$extendPath[$i]."/".$pathPart;
226 liveuser 8573
 
3 liveuser 8574
						}#for end
226 liveuser 8575
 
3 liveuser 8576
					}#if end
226 liveuser 8577
 
8578
				#反之該段含有「*」
3 liveuser 8579
				else{
226 liveuser 8580
 
3 liveuser 8581
					#用「*」分割該段
8582
					#函式說明:
8583
					#將固定格式的字串分開,並回傳分開的結果。
8584
					#回傳的參數:
8585
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8586
					#$result["error"],錯誤訊息陣列
8587
					#$result["function"],當前執行的函數名稱.
8588
					#$result["oriStr"],要分割的原始字串內容
8589
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8590
					#$result["dataCounts"],爲總共分成幾段
8591
					#必填參數:
8592
					$conf["stringProcess::spiltString"]["stringIn"]=$pathPart;#要處理的字串。
8593
					$conf["stringProcess::spiltString"]["spiltSymbol"]="*";#爲以哪個符號作爲分割
8594
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8595
					unset($conf["stringProcess::spiltString"]);
226 liveuser 8596
 
3 liveuser 8597
					#如果分字串失敗
8598
					if($spiltString["status"]=="false"){
226 liveuser 8599
 
3 liveuser 8600
						#設置錯誤識別
8601
						$result["status"]="false";
226 liveuser 8602
 
3 liveuser 8603
						#設置錯誤訊息
8604
						$result["error"]=$spiltStringByStar;
226 liveuser 8605
 
3 liveuser 8606
						#回傳結果
8607
						return $result;
226 liveuser 8608
 
3 liveuser 8609
						}#if end
226 liveuser 8610
 
3 liveuser 8611
					#如果用「*」分割後的段數為0
8612
					if($spiltString["dataCounts"]==0){
226 liveuser 8613
 
3 liveuser 8614
						#初始化儲存符合條件的路徑
8615
						$newExtendPath=array();
226 liveuser 8616
 
3 liveuser 8617
						#代表沒有塞選條件
8618
						#當前有幾個符合條件的路徑就執行幾次
8619
						for($i=0;$i<count($extendPath);$i++){
226 liveuser 8620
 
3 liveuser 8621
							#取得該目錄下所有的東西
8622
							#取得該目錄底下的檔案目錄清單
8623
							#函式說明:
8624
							#取得目錄底下所有目錄與檔案清單.
8625
							#回傳結果:
8626
							#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8627
							#$result["error"],錯誤訊息陣列.
8628
							#$result["function"],函數名稱.
8629
							#$result["content"],陣列,目錄底下的檔案與子目錄.
8630
							#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
8631
							#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
8632
							#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
8633
							#$result["position"],目前的位置.
8634
							#必填參數:
8635
							#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
8636
							$conf["fileAccess::getList"]["position"]=$extendPath[$i];
8637
							#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8638
							$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
8639
							#可省略參數:
8640
							#無
8641
							#參考資料來源:
8642
							#opendir=>http://php.net/manual/en/function.opendir.php
8643
							#is_dir=>http://php.net/manual/en/function.is-dir.php
8644
							$getList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 8645
							unset($conf["fileAccess::getList"]);
8646
 
3 liveuser 8647
							#如果取得目標目錄底下的檔案目錄清單失敗
8648
							if($getList["status"]=="false"){
226 liveuser 8649
 
3 liveuser 8650
								#設置錯誤識別
8651
								$result["status"]="false";
226 liveuser 8652
 
3 liveuser 8653
								#設置錯誤訊息
226 liveuser 8654
								$result["error"]=$getList;
8655
 
3 liveuser 8656
								#回傳結果
8657
								return $result;
226 liveuser 8658
 
3 liveuser 8659
								}#if end
226 liveuser 8660
 
3 liveuser 8661
							#如果底下有東西
8662
							if(count($getList["content"])>0){
226 liveuser 8663
 
3 liveuser 8664
								#初始化儲存要檢查的檔案或資料夾名稱陣列
8665
								$list=array();
226 liveuser 8666
 
3 liveuser 8667
								#針對每個檔案或資料夾
8668
								foreach($getList["content"] as $num=>$array){
226 liveuser 8669
 
3 liveuser 8670
									#儲存該名稱
8671
									$list[]=$array["name"];
226 liveuser 8672
 
3 liveuser 8673
									}#foreach end
226 liveuser 8674
 
3 liveuser 8675
								#初始化儲存符合新條件字串的陣列
8676
								$tempExtendPath=array();
226 liveuser 8677
 
3 liveuser 8678
								#針對每個現有的路徑字串
8679
								for($j=0;$j<count($extendPath);$j++){
226 liveuser 8680
 
3 liveuser 8681
									#附加每個符合條件的名稱到路徑字串裡面
8682
									for($k=0;$k<count($list);$k++){
226 liveuser 8683
 
3 liveuser 8684
										#如果 $conf["noDotStart"] 為 "true"
8685
										if($conf["noDotStart"]==="true"){
226 liveuser 8686
 
3 liveuser 8687
											#將 $list[$k] 用 "/" 分割
8688
											#函式說明:
8689
											#將固定格式的字串分開,並回傳分開的結果。
8690
											#回傳結果:
8691
											#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8692
											#$result["error"],錯誤訊息陣列
8693
											#$result["function"],當前執行的函數名稱.
8694
											#$result["oriStr"],要分割的原始字串內容
8695
											#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8696
											#$result["dataCounts"],爲總共分成幾段
8697
											#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
8698
											#必填參數:
8699
											$conf["stringProcess::spiltString"]["stringIn"]=$list[$k];#要處理的字串。
8700
											$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
8701
											#可省略參數:
8702
											#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
8703
											$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
8704
											$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8705
											unset($conf["stringProcess::spiltString"]);
226 liveuser 8706
 
3 liveuser 8707
											#如果分割路徑失敗
8708
											if($spiltString["status"]==="false"){
226 liveuser 8709
 
3 liveuser 8710
												#設置執行錯誤識別
8711
												$result["status"]="false";
226 liveuser 8712
 
3 liveuser 8713
												#取得錯誤訊息
8714
												$result["error"]=$spiltString;
226 liveuser 8715
 
3 liveuser 8716
												#回傳結果
8717
												return $result;
226 liveuser 8718
 
3 liveuser 8719
												}#if end
226 liveuser 8720
 
3 liveuser 8721
											#如果有關鍵字「/」存在
8722
											if($spiltString["found"]==="true"){
226 liveuser 8723
 
3 liveuser 8724
												#針對每個段落
8725
												foreach($spiltString["dataArray"] as $pp){
226 liveuser 8726
 
3 liveuser 8727
													#看該符合的名稱開頭是否包含「.」
8728
													#函式說明:
8729
													#取得符合特定字首與字尾的字串
8730
													#回傳結果:
8731
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8732
													#$result["function"],當前執行的函數名稱.
8733
													#$result["error"],錯誤訊息陣列.
8734
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8735
													#$result["returnString"],爲符合字首條件的字串內容。
8736
													#必填參數:
8737
													#$conf["checkString"],字串,要檢查的字串.
8738
													$conf["search::getMeetConditionsString"]["checkString"]=$pp;
8739
													#可省略參數:
8740
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8741
													$conf["search::getMeetConditionsString"]["frontWord"]=".";
8742
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8743
													#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
8744
													#參考資料:
8745
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8746
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8747
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 8748
 
3 liveuser 8749
													#如果 取得符合特定字首的字串 出錯
8750
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 8751
 
3 liveuser 8752
														#設置執行錯誤識別
8753
														$result["status"]="false";
226 liveuser 8754
 
3 liveuser 8755
														#設置錯誤訊息
8756
														$result["error"]=$getMeetConditionsString;
226 liveuser 8757
 
3 liveuser 8758
														#回傳結果
8759
														return $result;
226 liveuser 8760
 
3 liveuser 8761
														}#if end
226 liveuser 8762
 
3 liveuser 8763
													#如果有「.」在開頭
8764
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8765
 
8766
														#忽略這個名稱
3 liveuser 8767
														continue 2;
226 liveuser 8768
 
3 liveuser 8769
														}#if end
226 liveuser 8770
 
3 liveuser 8771
													}#foreach end
226 liveuser 8772
 
3 liveuser 8773
												}#if end
226 liveuser 8774
 
3 liveuser 8775
											#反之沒有關鍵字「/」存在
8776
											else{
226 liveuser 8777
 
3 liveuser 8778
												#看該符合的名稱開頭是否包含「.」
8779
												#函式說明:
8780
												#取得符合特定字首與字尾的字串
8781
												#回傳結果:
8782
												#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8783
												#$result["function"],當前執行的函數名稱.
8784
												#$result["error"],錯誤訊息陣列.
8785
												#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8786
												#$result["returnString"],爲符合字首條件的字串內容。
8787
												#必填參數:
8788
												#$conf["checkString"],字串,要檢查的字串.
8789
												$conf["search::getMeetConditionsString"]["checkString"]=$list[$k];
8790
												#可省略參數:
8791
												#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8792
												$conf["search::getMeetConditionsString"]["frontWord"]=".";
8793
												#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8794
												#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
8795
												#參考資料:
8796
												#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8797
												$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8798
												unset($conf["search::getMeetConditionsString"]);
226 liveuser 8799
 
3 liveuser 8800
												#如果 取得符合特定字首的字串 出錯
8801
												if($getMeetConditionsString["status"]=="false"){
226 liveuser 8802
 
3 liveuser 8803
													#設置執行錯誤識別
8804
													$result["status"]="false";
226 liveuser 8805
 
3 liveuser 8806
													#設置錯誤訊息
8807
													$result["error"]=$getMeetConditionsString;
226 liveuser 8808
 
3 liveuser 8809
													#回傳結果
8810
													return $result;
226 liveuser 8811
 
3 liveuser 8812
													}#if end
226 liveuser 8813
 
3 liveuser 8814
												#如果有「.」在開頭
8815
												if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8816
 
8817
													#忽略這個名稱
3 liveuser 8818
													continue;
226 liveuser 8819
 
3 liveuser 8820
													}#if end
226 liveuser 8821
 
3 liveuser 8822
												}#else end
226 liveuser 8823
 
3 liveuser 8824
											}#if end
226 liveuser 8825
 
3 liveuser 8826
										#如果 $conf["noWaveEnd"] 為 "true"
8827
										if($conf["noWaveEnd"]==="true"){
226 liveuser 8828
 
3 liveuser 8829
											#看該符合的名稱結尾是否包含「~」
8830
											#函式說明:
8831
											#取得符合特定字首與字尾的字串
8832
											#回傳結果:
8833
											#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8834
											#$result["function"],當前執行的函數名稱.
8835
											#$result["error"],錯誤訊息陣列.
8836
											#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8837
											#$result["returnString"],爲符合字首條件的字串內容。
8838
											#必填參數:
8839
											#$conf["checkString"],字串,要檢查的字串.
8840
											$conf["search::getMeetConditionsString"]["checkString"]=$list[$k];
8841
											#可省略參數:
8842
											#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8843
											#$conf["search::getMeetConditionsString"]["frontWord"]=".";
8844
											#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8845
											$conf["search::getMeetConditionsString"]["tailWord"]="~";
8846
											#參考資料:
8847
											#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8848
											$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8849
											unset($conf["search::getMeetConditionsString"]);
226 liveuser 8850
 
3 liveuser 8851
											#如果 取得符合特定字首的字串 出錯
8852
											if($getMeetConditionsString["status"]=="false"){
226 liveuser 8853
 
3 liveuser 8854
												#設置執行錯誤識別
8855
												$result["status"]="false";
226 liveuser 8856
 
3 liveuser 8857
												#設置錯誤訊息
8858
												$result["error"]=$getMeetConditionsString;
226 liveuser 8859
 
3 liveuser 8860
												#回傳結果
8861
												return $result;
226 liveuser 8862
 
3 liveuser 8863
												}#if end
226 liveuser 8864
 
3 liveuser 8865
											#如果有「~」在結尾
8866
											if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8867
 
3 liveuser 8868
												#忽略這個名稱
8869
												continue;
226 liveuser 8870
 
3 liveuser 8871
												}#if end
226 liveuser 8872
 
3 liveuser 8873
											}#if end
226 liveuser 8874
 
3 liveuser 8875
										#暫存該符合的路徑
8876
										$tempExtendPath[]=$extendPath[$j]."/".$list[$k];
226 liveuser 8877
 
3 liveuser 8878
										}#for end
226 liveuser 8879
 
8880
									}#for end
8881
 
3 liveuser 8882
								#該次有幾個符合的路徑就執行幾次
8883
								foreach($tempExtendPath as $path){
226 liveuser 8884
 
3 liveuser 8885
									#暫存符合的路徑
8886
									$newExtendPath[]=$path;
226 liveuser 8887
 
8888
									}#for end
8889
 
3 liveuser 8890
								}#if end
226 liveuser 8891
 
3 liveuser 8892
							#反之該目錄底下沒有東西
8893
							else{
226 liveuser 8894
 
3 liveuser 8895
								#移除該 $extendPath[$i]
8896
								unset($extendPath[$i]);
226 liveuser 8897
 
8898
								}#else end
8899
 
3 liveuser 8900
							}#for end
226 liveuser 8901
 
3 liveuser 8902
						#置換原始符合條件字串的路徑字串陣列
8903
						$extendPath=$newExtendPath;
226 liveuser 8904
 
3 liveuser 8905
						}#if end
226 liveuser 8906
 
3 liveuser 8907
						#反之用「*」分割後有分段
8908
						else{
226 liveuser 8909
 
3 liveuser 8910
							#初始化暫存符合條件的新路徑陣列變數
8911
							$newExtendPath=array();
226 liveuser 8912
 
3 liveuser 8913
							#當前有幾個符合條件的路徑就執行幾次
8914
							for($i=0;$i<count($extendPath);$i++){
226 liveuser 8915
 
3 liveuser 8916
								#取得該目錄下所有的東西
8917
								#函式說明:
8918
								#取得目錄底下所有目錄與檔案清單.
8919
								#回傳結果:
8920
								#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8921
								#$result["error"],錯誤訊息陣列.
8922
								#$result["function"],函數名稱.
8923
								#$result["content"],陣列,目錄底下的檔案與子目錄.
8924
								#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
8925
								#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
8926
								#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
8927
								#$result["position"],目前的位置.
8928
								#必填參數:
8929
								#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
8930
								$conf["fileAccess::getList"]["position"]=$extendPath[$i];
8931
								#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8932
								$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
8933
								#可省略參數:
8934
								#無
8935
								#參考資料來源:
8936
								#opendir=>http://php.net/manual/en/function.opendir.php
8937
								#is_dir=>http://php.net/manual/en/function.is-dir.php
8938
								$getList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 8939
								unset($conf["fileAccess::getList"]);
8940
 
3 liveuser 8941
								#如果取得目標目錄底下的檔案目錄清單失敗
8942
								if($getList["status"]=="false"){
226 liveuser 8943
 
3 liveuser 8944
									#設置錯誤識別
8945
									$result["status"]="false";
226 liveuser 8946
 
3 liveuser 8947
									#設置錯誤訊息
226 liveuser 8948
									$result["error"]=$getList;
8949
 
3 liveuser 8950
									#回傳結果
8951
									return $result;
226 liveuser 8952
 
3 liveuser 8953
									}#if end
226 liveuser 8954
 
3 liveuser 8955
								#如果底下有東西
8956
								if(count($getList["content"])>0){
226 liveuser 8957
 
3 liveuser 8958
									#初始化儲存要檢查的檔案或資料夾名稱陣列
8959
									$list=array();
226 liveuser 8960
 
3 liveuser 8961
									#針對每個檔案或資料夾
8962
									foreach($getList["content"] as $num=>$array){
226 liveuser 8963
 
3 liveuser 8964
										#儲存該名稱
8965
										$list[]=$array["name"];
226 liveuser 8966
 
3 liveuser 8967
										}#foreach end
226 liveuser 8968
 
3 liveuser 8969
									#初始化儲存符合的名稱
8970
									$passedName=array();
226 liveuser 8971
 
3 liveuser 8972
									#依據每個檔案目錄名稱,檢查有無符合篩選條件
8973
									foreach($list as $filteredName){
226 liveuser 8974
 
3 liveuser 8975
										#初始化儲存被檢查的片段檔案資料夾名稱
8976
										$partName=$filteredName;
226 liveuser 8977
 
3 liveuser 8978
										#依據 $pathPart 分割成幾段(關鍵字數量)就執行幾次
8979
										for($i=0;$i<$spiltString["dataCounts"];$i++){
226 liveuser 8980
 
3 liveuser 8981
											#尋找關鍵字 $spiltString["dataArray"][$i]
8982
											#函式說明:
8983
											#檢查字串裡面有無指定的關鍵字
8984
											#回傳結果:
8985
											#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8986
											#$result["error"],錯誤訊息
8987
											#$result["function"],當前執行的函數名稱.
8988
											#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8989
											#$result["keyWordCount"],找到的關鍵字數量.
8990
											#必填參數:
8991
											$conf["search::findKeyWord"]["keyWord"]=$spiltString["dataArray"][$i];#想要搜尋的關鍵字
8992
											$conf["search::findKeyWord"]["string"]=$partName;#要被搜尋的字串內容
8993
											#可省略參數:
8994
											#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8995
											$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8996
											unset($conf["search::findKeyWord"]);
226 liveuser 8997
 
3 liveuser 8998
											#如果尋找關鍵字失敗
8999
											if($findKeyWord["status"]=="false"){
226 liveuser 9000
 
3 liveuser 9001
												#設置執行錯誤識別
9002
												$result["status"]="false";
226 liveuser 9003
 
3 liveuser 9004
												#設置錯誤訊息
9005
												$result["error"]=$findKeyWord;
226 liveuser 9006
 
3 liveuser 9007
												#回傳結果
9008
												return $result;
226 liveuser 9009
 
3 liveuser 9010
												}#if end
226 liveuser 9011
 
3 liveuser 9012
											#如果有找到關鍵字
9013
											if($findKeyWord["founded"]=="true"){
226 liveuser 9014
 
3 liveuser 9015
												#如果是最後一段要檢查的關鍵字
9016
												if($i==$spiltString["dataCounts"]-1){
226 liveuser 9017
 
3 liveuser 9018
													#判斷該關鍵字是否在該未分割的 $pathPart(含有*字號的關鍵字字串) 的開頭
9019
													#函式說明:
9020
													#取得符合特定字首與字尾的字串
9021
													#回傳結果:
9022
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9023
													#$result["function"],當前執行的函數名稱.
9024
													#$result["error"],錯誤訊息陣列.
9025
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9026
													#$result["returnString"],爲符合字首條件的字串內容。
9027
													#必填參數:
9028
													#$conf["checkString"],字串,要檢查的字串.
9029
													$conf["search::getMeetConditionsString"]["checkString"]=$pathPart;
9030
													#可省略參數:
9031
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9032
													$conf["search::getMeetConditionsString"]["frontWord"]=$spiltString["dataArray"][0];
9033
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9034
													#$conf["tailWord"]="";
9035
													#參考資料:
9036
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9037
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9038
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 9039
 
3 liveuser 9040
													#如果 取得符合特定字首的字串 出錯
9041
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 9042
 
3 liveuser 9043
														#設置執行錯誤識別
9044
														$result["status"]="false";
226 liveuser 9045
 
3 liveuser 9046
														#設置錯誤訊息
9047
														$result["error"]=$getMeetConditionsString;
226 liveuser 9048
 
3 liveuser 9049
														#回傳結果
9050
														return $result;
226 liveuser 9051
 
3 liveuser 9052
														}#if end
226 liveuser 9053
 
3 liveuser 9054
													#如果關鍵字是在開頭
9055
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9056
 
3 liveuser 9057
														#判斷關鍵字是否在該檔案目錄名稱的開頭
9058
														#函式說明:
9059
														#取得符合特定字首與字尾的字串
9060
														#回傳結果:
9061
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9062
														#$result["function"],當前執行的函數名稱.
9063
														#$result["error"],錯誤訊息陣列.
9064
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9065
														#$result["returnString"],爲符合字首條件的字串內容。
9066
														#必填參數:
9067
														#$conf["checkString"],字串,要檢查的字串.
9068
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9069
														#可省略參數:
9070
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9071
														$conf["search::getMeetConditionsString"]["frontWord"]=$spiltString["dataArray"][0];
9072
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9073
														#$conf["tailWord"]="";
9074
														#參考資料:
9075
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9076
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9077
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9078
 
3 liveuser 9079
														#如果 取得符合特定字首的字串 出錯
9080
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9081
 
3 liveuser 9082
															#設置執行錯誤識別
9083
															$result["status"]="false";
226 liveuser 9084
 
3 liveuser 9085
															#設置錯誤訊息
9086
															$result["error"]=$getMeetConditionsString;
226 liveuser 9087
 
3 liveuser 9088
															#回傳結果
9089
															return $result;
226 liveuser 9090
 
3 liveuser 9091
															}#if end
226 liveuser 9092
 
3 liveuser 9093
														#如果關鍵字不在開頭
9094
														if($getMeetConditionsString["founded"]=="false"){
226 liveuser 9095
 
3 liveuser 9096
															#不符合條件,跳過該檔案目錄名稱
9097
															break;
226 liveuser 9098
 
3 liveuser 9099
															}#if end
226 liveuser 9100
 
3 liveuser 9101
														}#if end
226 liveuser 9102
 
3 liveuser 9103
													#判斷最後一個關鍵字是否在該未分割的 $pathPart(含有*字號的關鍵字字串) 的結尾
9104
													#函式說明:
9105
													#取得符合特定字首與字尾的字串
9106
													#回傳結果:
9107
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9108
													#$result["function"],當前執行的函數名稱.
9109
													#$result["error"],錯誤訊息陣列.
9110
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9111
													#$result["returnString"],爲符合字首條件的字串內容。
9112
													#必填參數:
9113
													#$conf["checkString"],字串,要檢查的字串.
9114
													$conf["search::getMeetConditionsString"]["checkString"]=$pathPart;
9115
													#可省略參數:
9116
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9117
													#$conf["search::getMeetConditionsString"]["frontWord"]=$partName;
9118
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9119
													$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9120
													#參考資料:
9121
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9122
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9123
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 9124
 
3 liveuser 9125
													#如果 取得符合特定字尾的字串 出錯
9126
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 9127
 
3 liveuser 9128
														#設置執行錯誤識別
9129
														$result["status"]="false";
226 liveuser 9130
 
3 liveuser 9131
														#設置錯誤訊息
9132
														$result["error"]=$getMeetConditionsString;
226 liveuser 9133
 
3 liveuser 9134
														#回傳結果
9135
														return $result;
226 liveuser 9136
 
3 liveuser 9137
														}#if end
226 liveuser 9138
 
3 liveuser 9139
													#如果關鍵字是在字尾
9140
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9141
 
3 liveuser 9142
														#判斷關鍵字是否在該片段的開頭
9143
														#函式說明:
9144
														#取得符合特定字首與字尾的字串
9145
														#回傳結果:
9146
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9147
														#$result["function"],當前執行的函數名稱.
9148
														#$result["error"],錯誤訊息陣列.
9149
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9150
														#$result["returnString"],爲符合字首條件的字串內容。
9151
														#必填參數:
9152
														#$conf["checkString"],字串,要檢查的字串.
9153
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9154
														#可省略參數:
9155
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9156
														#$conf["search::getMeetConditionsString"]["frontWord"]=$partName;
9157
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9158
														$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9159
														#參考資料:
9160
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9161
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9162
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9163
 
3 liveuser 9164
														#如果 取得符合特定字首的字串 出錯
9165
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9166
 
3 liveuser 9167
															#設置執行錯誤識別
9168
															$result["status"]="false";
226 liveuser 9169
 
3 liveuser 9170
															#設置錯誤訊息
9171
															$result["error"]=$getMeetConditionsString;
226 liveuser 9172
 
3 liveuser 9173
															#回傳結果
9174
															return $result;
226 liveuser 9175
 
3 liveuser 9176
															}#if end
226 liveuser 9177
 
3 liveuser 9178
														#如果關鍵字不在結尾
9179
														if($getMeetConditionsString["founded"]=="false"){
226 liveuser 9180
 
3 liveuser 9181
															#不符合條件,跳過該檔案目錄名稱
9182
															break;
226 liveuser 9183
 
3 liveuser 9184
															}#if end
226 liveuser 9185
 
3 liveuser 9186
														}#if end
226 liveuser 9187
 
3 liveuser 9188
													#如果 $conf["noDotStart"] 為 "true"
9189
													if($conf["noDotStart"]==="true"){
226 liveuser 9190
 
3 liveuser 9191
														#看該符合的名稱開頭是否包含「.」
9192
														#函式說明:
9193
														#取得符合特定字首與字尾的字串
9194
														#回傳結果:
9195
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9196
														#$result["function"],當前執行的函數名稱.
9197
														#$result["error"],錯誤訊息陣列.
9198
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9199
														#$result["returnString"],爲符合字首條件的字串內容。
9200
														#必填參數:
9201
														#$conf["checkString"],字串,要檢查的字串.
9202
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9203
														#可省略參數:
9204
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9205
														$conf["search::getMeetConditionsString"]["frontWord"]=".";
9206
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9207
														#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9208
														#參考資料:
9209
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9210
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9211
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9212
 
3 liveuser 9213
														#如果 取得符合特定字首的字串 出錯
9214
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9215
 
3 liveuser 9216
															#設置執行錯誤識別
9217
															$result["status"]="false";
226 liveuser 9218
 
3 liveuser 9219
															#設置錯誤訊息
9220
															$result["error"]=$getMeetConditionsString;
226 liveuser 9221
 
3 liveuser 9222
															#回傳結果
9223
															return $result;
226 liveuser 9224
 
3 liveuser 9225
															}#if end
226 liveuser 9226
 
3 liveuser 9227
														#如果有「.」在開頭
9228
														if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9229
 
3 liveuser 9230
															#中斷迴圈
9231
															break;
226 liveuser 9232
 
3 liveuser 9233
															}#if end
226 liveuser 9234
 
3 liveuser 9235
														}#if end
226 liveuser 9236
 
3 liveuser 9237
													#如果 $conf["noWaveEnd"] 為 "true"
9238
													if($conf["noWaveEnd"]==="true"){
226 liveuser 9239
 
3 liveuser 9240
														#看該符合的名稱結尾是否包含「~」
9241
														#函式說明:
9242
														#取得符合特定字首與字尾的字串
9243
														#回傳結果:
9244
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9245
														#$result["function"],當前執行的函數名稱.
9246
														#$result["error"],錯誤訊息陣列.
9247
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9248
														#$result["returnString"],爲符合字首條件的字串內容。
9249
														#必填參數:
9250
														#$conf["checkString"],字串,要檢查的字串.
9251
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9252
														#可省略參數:
9253
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9254
														#$conf["search::getMeetConditionsString"]["frontWord"]=".";
9255
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9256
														$conf["search::getMeetConditionsString"]["tailWord"]="~";
9257
														#參考資料:
9258
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9259
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9260
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9261
 
3 liveuser 9262
														#如果 取得符合特定字首的字串 出錯
9263
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9264
 
3 liveuser 9265
															#設置執行錯誤識別
9266
															$result["status"]="false";
226 liveuser 9267
 
3 liveuser 9268
															#設置錯誤訊息
9269
															$result["error"]=$getMeetConditionsString;
226 liveuser 9270
 
3 liveuser 9271
															#回傳結果
9272
															return $result;
226 liveuser 9273
 
3 liveuser 9274
															}#if end
226 liveuser 9275
 
3 liveuser 9276
														#如果有「~」在結尾
9277
														if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9278
 
3 liveuser 9279
															#中斷迴圈
9280
															break;
226 liveuser 9281
 
3 liveuser 9282
															}#if end
226 liveuser 9283
 
3 liveuser 9284
														}#if end
226 liveuser 9285
 
3 liveuser 9286
													#取得該符合的名稱
9287
													$passedName[]=$filteredName;
226 liveuser 9288
 
3 liveuser 9289
													#中斷迴圈
9290
													break;
226 liveuser 9291
 
3 liveuser 9292
													}#if end
226 liveuser 9293
 
3 liveuser 9294
												#將 $partName 從左到關鍵字結束的部份剔除
9295
												#函式說明:
9296
												#將特定字串前面的內容剔除
9297
												#回傳結果:
9298
												#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9299
												#$result["error"],錯誤訊息陣列.
9300
												#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
9301
												#$result["function"],當前執行的函數名稱.
9302
												#$result["oriStr"],要處理的原始字串內容.
9303
												#$result["content"],處理好的的字串內容.
9304
												#必填參數:
9305
												$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$partName;#要處理的字串.
9306
												$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$spiltString["dataArray"][$i];#特定字串.
9307
												$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
9308
												unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 9309
 
3 liveuser 9310
												#如果將 $partName 從左到關鍵字結束的部份剔除失敗
9311
												if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 9312
 
3 liveuser 9313
													#設置執行錯誤識別
9314
													$result["status"]="false";
226 liveuser 9315
 
3 liveuser 9316
													#設置錯誤訊息
9317
													$result["error"]=$delStrBeforeKeyWord;
226 liveuser 9318
 
3 liveuser 9319
													#回傳結果
9320
													return $result;
226 liveuser 9321
 
3 liveuser 9322
													}#if end
226 liveuser 9323
 
3 liveuser 9324
												#如果沒有找到特定關鍵字字串
9325
												if($delStrBeforeKeyWord["founded"]=="false"){
226 liveuser 9326
 
3 liveuser 9327
													#設置執行錯誤識別
9328
													$result["status"]="false";
226 liveuser 9329
 
3 liveuser 9330
													#設置錯誤訊息
9331
													$result["error"]=$delStrBeforeKeyWord;
226 liveuser 9332
 
3 liveuser 9333
													#回傳結果
9334
													return $result;
226 liveuser 9335
 
3 liveuser 9336
													}#if end
226 liveuser 9337
 
9338
												#取得剔除過關鍵字前字串的字串
3 liveuser 9339
												$partName=$delStrBeforeKeyWord["content"];
226 liveuser 9340
 
3 liveuser 9341
												}#if end
226 liveuser 9342
 
9343
											#反之關鍵字不存在
3 liveuser 9344
											else{
226 liveuser 9345
 
3 liveuser 9346
												#儲存被拋棄的片段
9347
												#$result["dismissLog"][]="片段「".$partName."」沒有關鍵字「".$spiltString["dataArray"][$i]."」";
226 liveuser 9348
 
3 liveuser 9349
												#該名稱不符合條件
9350
												break;
226 liveuser 9351
 
3 liveuser 9352
												}#else end
226 liveuser 9353
 
3 liveuser 9354
											}#for end
226 liveuser 9355
 
3 liveuser 9356
										}#foreach end
226 liveuser 9357
 
3 liveuser 9358
									#初始化儲存符合的暫存路徑
9359
									$tempExtendPath=array();
226 liveuser 9360
 
3 liveuser 9361
									#針對每個現有的路徑字串
9362
									for($j=0;$j<count($extendPath);$j++){
226 liveuser 9363
 
3 liveuser 9364
										#附加每個符合條件的名稱到路徑字串裡面
9365
										for($k=0;$k<count($passedName);$k++){
226 liveuser 9366
 
3 liveuser 9367
											#暫存該符合的路徑
9368
											$tempExtendPath[]=$extendPath[$j]."/".$passedName[$k];
226 liveuser 9369
 
3 liveuser 9370
											}#for end
226 liveuser 9371
 
9372
										}#for end
9373
 
3 liveuser 9374
									#該次有幾個符合的路徑就執行幾次
9375
									foreach($tempExtendPath as $path){
226 liveuser 9376
 
3 liveuser 9377
										#暫存符合的路徑
9378
										$newExtendPath[]=$path;
226 liveuser 9379
 
9380
										}#foreach end
9381
 
3 liveuser 9382
									}#if end
226 liveuser 9383
 
3 liveuser 9384
								#反之該目錄底下沒有東西
9385
								else{
226 liveuser 9386
 
3 liveuser 9387
									#移除該 $extendPath[$i]
9388
									unset($extendPath[$i]);
226 liveuser 9389
 
9390
									}#else end
9391
 
3 liveuser 9392
								}#for end
226 liveuser 9393
 
3 liveuser 9394
							#如果有新的路徑產生
9395
							if(count($newExtendPath)>0){
226 liveuser 9396
 
3 liveuser 9397
								#置換原始符合條件字串的路徑字串陣列
9398
								$extendPath=$newExtendPath;
226 liveuser 9399
 
3 liveuser 9400
								}#if end
226 liveuser 9401
 
3 liveuser 9402
							#反之找不到後續符合的路徑
9403
							else{
226 liveuser 9404
 
3 liveuser 9405
								$extendPath=array();
226 liveuser 9406
 
3 liveuser 9407
								}#else end
226 liveuser 9408
 
3 liveuser 9409
							}#else end
226 liveuser 9410
 
3 liveuser 9411
					}#else end
226 liveuser 9412
 
3 liveuser 9413
				}#foreach end
226 liveuser 9414
 
3 liveuser 9415
			}#if end
226 liveuser 9416
 
3 liveuser 9417
		#反之沒有含有「*」
9418
		else{
226 liveuser 9419
 
3 liveuser 9420
			#判斷 $conf["path"] 是否存在
9421
			#函式說明:
9422
			#檢查多個檔案與資料夾是否存在.
9423
			#回傳的結果:
9424
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
9425
			#$result["error"],錯誤訊息陣列.
9426
			#$resutl["function"],當前執行的涵式名稱.
9427
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
9428
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
9429
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
9430
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
9431
			#必填參數:
9432
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
9433
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["path"]);
9434
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9435
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
9436
			#可省略參數
9437
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
9438
			#$conf["disableWebSearch"]="false";
9439
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
9440
			#$conf["userDir"]="true";
9441
			#參考資料來源:
9442
			#http://php.net/manual/en/function.file-exists.php
9443
			#http://php.net/manual/en/control-structures.foreach.php
9444
			#備註:
9445
			#函數file_exists檢查的路徑為檔案系統的路徑
9446
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
9447
			unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 9448
 
3 liveuser 9449
			#如果檢查失敗
9450
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 9451
 
3 liveuser 9452
				#設置錯誤識別
9453
				$result["status"]="false";
226 liveuser 9454
 
3 liveuser 9455
				#設置錯誤訊息
9456
				$result["error"]=$checkMultiFileExist;
226 liveuser 9457
 
3 liveuser 9458
				#回傳結果
9459
				return $result;
226 liveuser 9460
 
3 liveuser 9461
				}#if end
226 liveuser 9462
 
3 liveuser 9463
			#如果存在
9464
			if($checkMultiFileExist["varExist"][0]=="true"){
226 liveuser 9465
 
3 liveuser 9466
				#初始化暫存展開後的檔案路徑字串
9467
				$extendPath=array($conf["path"]);
226 liveuser 9468
 
3 liveuser 9469
				}#if end
226 liveuser 9470
 
3 liveuser 9471
			#反之不存在
9472
			else{
226 liveuser 9473
 
3 liveuser 9474
				#置換符合的路徑為空字串
9475
				$extendPath=array();
226 liveuser 9476
 
3 liveuser 9477
				}#else end
226 liveuser 9478
 
3 liveuser 9479
			#初始化暫存展開後的檔案路徑字串
9480
			$extendPath=array($conf["path"]);
226 liveuser 9481
 
3 liveuser 9482
			}#else end
226 liveuser 9483
 
3 liveuser 9484
		#取得解析完「*」的檔案路徑字串
9485
		$result["content"]=$extendPath;
226 liveuser 9486
 
3 liveuser 9487
		#取得有幾個檔案路徑
9488
		$result["pathCount"]=count($result["content"]);
226 liveuser 9489
 
3 liveuser 9490
		#設置執行正常
9491
		$result["status"]="true";
226 liveuser 9492
 
3 liveuser 9493
		#回傳結果
9494
		return $result;
226 liveuser 9495
 
3 liveuser 9496
		}#function resolvePostionStringWhichContainStarSymbol end
9497
 
9498
	/*
9499
	#函式說明:
9500
	#將含有「*」的多個檔案路徑名稱,變成多個符合條件的路徑檔案.
9501
	#回傳結果:
9502
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9503
	#$result["error"],錯誤訊息陣列.
226 liveuser 9504
	#$result["function"],函數名稱.
3 liveuser 9505
	#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
9506
	#$result["pathCount"],整數,有幾個路徑.
9507
	#必填參數:
9508
	#$conf["path"],字串陣列,要解析含有「*」的檔案路徑字串.
9509
	$conf["path"]=array();
9510
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
9511
	$conf["fileArgu"]=__FILE__;
9512
	#可省略參數:
9513
	#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
9514
	#$conf["noDotStart"]="true";
9515
	#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
9516
	#$conf["noWaveEnd"]="true";
9517
	#參考資料:
9518
	#無.
9519
	#備註:
9520
	#無.
9521
	*/
9522
	public static function resolveMultiPostionStringWhichContainStarSymbol(&$conf){
226 liveuser 9523
 
3 liveuser 9524
		#初始化要回傳的結果
9525
		$result=array();
226 liveuser 9526
 
3 liveuser 9527
		#設置當其函數名稱
9528
		$result["function"]=__FUNCTION__;
226 liveuser 9529
 
3 liveuser 9530
		#如果 $conf 不為陣列
9531
		if(gettype($conf)!="array"){
226 liveuser 9532
 
3 liveuser 9533
			#設置執行失敗
9534
			$result["status"]="false";
226 liveuser 9535
 
3 liveuser 9536
			#設置執行錯誤訊息
9537
			$result["error"][]="\$conf變數須為陣列形態";
9538
 
9539
			#如果傳入的參數為 null
9540
			if($conf==null){
226 liveuser 9541
 
3 liveuser 9542
				#設置執行錯誤訊息
9543
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 9544
 
3 liveuser 9545
				}#if end
9546
 
9547
			#回傳結果
9548
			return $result;
226 liveuser 9549
 
3 liveuser 9550
			}#if end
226 liveuser 9551
 
3 liveuser 9552
		#檢查參數
9553
		#函式說明:
9554
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
9555
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9556
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9557
		#$result["function"],當前執行的函式名稱.
9558
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9559
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9560
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9561
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
9562
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9563
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9564
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9565
		#必填寫的參數:
9566
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9567
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9568
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9569
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 9570
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 9571
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
9572
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9573
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9574
		#可以省略的參數:
9575
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
9576
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9577
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9578
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noDotStart","noWaveEnd");
226 liveuser 9579
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 9580
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
9581
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9582
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","true");
9583
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9584
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
9585
		#參考資料來源:
9586
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9587
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9588
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 9589
 
3 liveuser 9590
		#如果 $checkResult["status"] 等於 "fasle"
9591
		if($checkResult["status"]=="false"){
226 liveuser 9592
 
3 liveuser 9593
			#設置錯誤識別
9594
			$result["status"]="false";
226 liveuser 9595
 
3 liveuser 9596
			#設置錯誤訊息
9597
			$result["error"]=$checkResult;
226 liveuser 9598
 
3 liveuser 9599
			#回傳結果
9600
			return $result;
226 liveuser 9601
 
3 liveuser 9602
			}#if end
226 liveuser 9603
 
3 liveuser 9604
		#如果 $checkResult["passed"] 等於 "fasle"
9605
		if($checkResult["passed"]=="false"){
226 liveuser 9606
 
3 liveuser 9607
			#設置錯誤識別
9608
			$result["status"]="false";
226 liveuser 9609
 
3 liveuser 9610
			#設置錯誤訊息
9611
			$result["error"]=$checkResult;
226 liveuser 9612
 
3 liveuser 9613
			#回傳結果
9614
			return $result;
226 liveuser 9615
 
3 liveuser 9616
			}#if end
226 liveuser 9617
 
3 liveuser 9618
		#針對每個要解析的路徑字串
9619
		foreach($conf["path"] as $path){
226 liveuser 9620
 
3 liveuser 9621
			#函式說明:
9622
			#將含有「*」的檔案路徑名稱,變成多個符合條件的路徑檔案.
9623
			#回傳結果:
9624
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9625
			#$result["error"],錯誤訊息陣列.
226 liveuser 9626
			#$result["function"],函數名稱.
3 liveuser 9627
			#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
9628
			#必填參數:
9629
			#$conf["path"],字串,要解析含有「*」的檔案路徑字串.
9630
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["path"]=$path;
9631
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
9632
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["fileArgu"]=$conf["fileArgu"];
9633
			#可省略參數:
9634
			#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
9635
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["noDotStart"]=$conf["noDotStart"];
9636
			#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
9637
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["noWaveEnd"]=$conf["noWaveEnd"];
9638
			$resolvePostionStringWhichContainStarSymbol=fileAccess::resolvePostionStringWhichContainStarSymbol($conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]);
9639
			unset($conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]);
226 liveuser 9640
 
3 liveuser 9641
			#如果解析失敗
9642
			if($resolvePostionStringWhichContainStarSymbol["status"]=="false"){
226 liveuser 9643
 
3 liveuser 9644
				#設置錯誤識別
9645
				$result["status"]="false";
226 liveuser 9646
 
3 liveuser 9647
				#設置錯誤訊息
9648
				$result["error"]=$resolvePostionStringWhichContainStarSymbol;
226 liveuser 9649
 
3 liveuser 9650
				#回傳結果
9651
				return $result;
226 liveuser 9652
 
3 liveuser 9653
				}#if end
226 liveuser 9654
 
3 liveuser 9655
			#針對每個解析出來的路徑
9656
			foreach($resolvePostionStringWhichContainStarSymbol["content"] as $filteredPath){
226 liveuser 9657
 
3 liveuser 9658
				#儲存符合條件的路徑
9659
				$result["content"][]=$filteredPath;
226 liveuser 9660
 
3 liveuser 9661
				}#foreach end
226 liveuser 9662
 
3 liveuser 9663
			}#foreach end
226 liveuser 9664
 
3 liveuser 9665
		#如果有路徑存在
9666
		if(isset($result["content"])){
226 liveuser 9667
 
3 liveuser 9668
			#取得有幾個路徑
9669
			$result["pathCount"]=count($result["content"]);
226 liveuser 9670
 
3 liveuser 9671
			}#if end
226 liveuser 9672
 
9673
		#反之
3 liveuser 9674
		else{
226 liveuser 9675
 
3 liveuser 9676
			#設置空的路徑結果
9677
			$result["content"]=array();
226 liveuser 9678
 
3 liveuser 9679
			#取得有幾個路徑
9680
			$result["pathCount"]=count($result["content"]);
226 liveuser 9681
 
3 liveuser 9682
			}#else end
226 liveuser 9683
 
3 liveuser 9684
		#設置執行正常
9685
		$result["status"]="true";
226 liveuser 9686
 
3 liveuser 9687
		#回傳結果
9688
		return $result;
226 liveuser 9689
 
3 liveuser 9690
		}#function resolveMultiPostionStringWhichContainStarSymbol end
9691
 
9692
	/*
9693
	#函式說明:
9694
	#將多個路徑字串變成相對於當前路徑的相對路徑字串
9695
	#回傳結果:
9696
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9697
	#$result["error"],錯誤訊息陣列.
226 liveuser 9698
	#$result["function"],函數名稱.
3 liveuser 9699
	#$result["argu"],使用的參數.
9700
	#$result["content"],字串陣列,多個轉換好的相對路徑字串.
9701
	#$result["cmd"],使用的指令.
9702
	#必填參數:
9703
	#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
9704
	$conf["path"]=array();
9705
	#$conf["fileArgu"],字串,當前路徑.
9706
	$conf["fileArgu"]=__FILE__;
9707
	#可省略參數:
9708
	#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
9709
	#$conf["baseFrom"]="";
9710
	#參考資料:
9711
	#無.
9712
	#備註:
9713
	#無.
9714
	*/
9715
	public static function getRelativePath(&$conf){
226 liveuser 9716
 
3 liveuser 9717
		#初始化要回傳的結果
9718
		$result=array();
226 liveuser 9719
 
3 liveuser 9720
		#設置當其函數名稱
9721
		$result["function"]=__FUNCTION__;
226 liveuser 9722
 
3 liveuser 9723
		#如果 $conf 不為陣列
9724
		if(gettype($conf)!="array"){
226 liveuser 9725
 
3 liveuser 9726
			#設置執行失敗
9727
			$result["status"]="false";
226 liveuser 9728
 
3 liveuser 9729
			#設置執行錯誤訊息
9730
			$result["error"][]="\$conf變數須為陣列形態";
9731
 
9732
			#如果傳入的參數為 null
9733
			if($conf==null){
226 liveuser 9734
 
3 liveuser 9735
				#設置執行錯誤訊息
9736
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 9737
 
3 liveuser 9738
				}#if end
9739
 
9740
			#回傳結果
9741
			return $result;
226 liveuser 9742
 
3 liveuser 9743
			}#if end
226 liveuser 9744
 
3 liveuser 9745
		#檢查參數
9746
		#函式說明:
9747
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
9748
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9749
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9750
		#$result["function"],當前執行的函式名稱.
9751
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9752
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9753
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9754
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
9755
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9756
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9757
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9758
		#必填寫的參數:
9759
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9760
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9761
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9762
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 9763
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 9764
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
9765
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9766
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9767
		#可以省略的參數:
9768
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
9769
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9770
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9771
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("baseFrom");
226 liveuser 9772
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 9773
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
9774
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9775
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
9776
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9777
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
9778
		#參考資料來源:
9779
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9780
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9781
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 9782
 
3 liveuser 9783
		#如果 $checkResult["status"] 等於 "false"
9784
		if($checkResult["status"]=="false"){
226 liveuser 9785
 
3 liveuser 9786
			#設置錯誤識別
9787
			$result["status"]="false";
226 liveuser 9788
 
3 liveuser 9789
			#設置錯誤訊息
9790
			$result["error"]=$checkResult;
226 liveuser 9791
 
3 liveuser 9792
			#回傳結果
9793
			return $result;
226 liveuser 9794
 
3 liveuser 9795
			}#if end
226 liveuser 9796
 
3 liveuser 9797
		#如果 $checkResult["passed"] 等於 "fasle"
9798
		if($checkResult["passed"]=="false"){
226 liveuser 9799
 
3 liveuser 9800
			#設置錯誤識別
9801
			$result["status"]="false";
226 liveuser 9802
 
3 liveuser 9803
			#設置錯誤訊息
9804
			$result["error"]=$checkResult;
226 liveuser 9805
 
3 liveuser 9806
			#回傳結果
9807
			return $result;
226 liveuser 9808
 
3 liveuser 9809
			}#if end
226 liveuser 9810
 
3 liveuser 9811
		#取得參數
9812
		$result["argu"]=$conf;
226 liveuser 9813
 
3 liveuser 9814
		#函式說明:
9815
		#將固定格式的字串分開,並回傳分開的結果.
9816
		#回傳結果:
9817
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9818
		#$result["error"],錯誤訊息陣列
9819
		#$result["function"],當前執行的函數名稱.
9820
		#$result["argu"],使用的參數.
9821
		#$result["oriStr"],要分割的原始字串內容
9822
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9823
		#$result["dataCounts"],爲總共分成幾段
9824
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9825
		#必填參數:
9826
		#$conf["stringIn"],字串,要處理的字串.
9827
		$conf["fileAccess::spiltString"]["stringIn"]=$conf["fileArgu"];
9828
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
9829
		$conf["fileAccess::spiltString"]["spiltSymbol"]="/";
9830
		#可省略參數:
9831
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9832
		$conf["fileAccess::spiltString"]["allowEmptyStr"]="false";
9833
		#參考資料:
9834
		#無.
9835
		#備註:
9836
		#無.
9837
		$spiltString=stringProcess::spiltString($conf["fileAccess::spiltString"]);
9838
		unset($conf["fileAccess::spiltString"]);
226 liveuser 9839
 
3 liveuser 9840
		#如果執行失敗
9841
		if($spiltString["status"]==="false"){
226 liveuser 9842
 
3 liveuser 9843
			#設置錯誤識別
9844
			$result["status"]="false";
226 liveuser 9845
 
3 liveuser 9846
			#設置錯誤訊息
9847
			$result["error"]=$spiltString;
226 liveuser 9848
 
3 liveuser 9849
			#回傳結果
9850
			return $result;
226 liveuser 9851
 
3 liveuser 9852
			}#if end
226 liveuser 9853
 
3 liveuser 9854
		#如果沒有關鍵字
9855
		if($spiltString["found"]==="false"){
226 liveuser 9856
 
3 liveuser 9857
			#設置錯誤識別
9858
			$result["status"]="false";
226 liveuser 9859
 
3 liveuser 9860
			#設置錯誤訊息
9861
			$result["error"]=$spiltString;
226 liveuser 9862
 
3 liveuser 9863
			#回傳結果
9864
			return $result;
226 liveuser 9865
 
3 liveuser 9866
			}#if end
226 liveuser 9867
 
3 liveuser 9868
		#取得 $conf["fileArgu"] 的路徑
9869
		#函式說明:
9870
		#將固定格式的字串分開,並回傳分開的結果.
9871
		#回傳結果:
9872
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9873
		#$result["error"],錯誤訊息陣列
9874
		#$result["function"],當前執行的函數名稱.
9875
		#$result["argu"],使用的參數.
9876
		#$result["oriStr"],要分割的原始字串內容
9877
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9878
		#$result["dataCounts"],爲總共分成幾段
9879
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9880
		#必填參數:
9881
		#$conf["stringIn"],字串,要處理的字串.
9882
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];
9883
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
9884
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
9885
		#可省略參數:
9886
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9887
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
9888
		#參考資料:
9889
		#無.
9890
		#備註:
9891
		#無.
9892
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
9893
		unset($conf["stringProcess::spiltString"]);
226 liveuser 9894
 
3 liveuser 9895
		#如果執行失敗
9896
		if($spiltString["status"]==="false"){
226 liveuser 9897
 
3 liveuser 9898
			#設置錯誤識別
9899
			$result["status"]="false";
226 liveuser 9900
 
3 liveuser 9901
			#設置錯誤訊息
9902
			$result["error"]=$spiltString;
226 liveuser 9903
 
3 liveuser 9904
			#回傳結果
9905
			return $result;
226 liveuser 9906
 
3 liveuser 9907
			}#if end
226 liveuser 9908
 
3 liveuser 9909
		/*
9910
		#break point
9911
		var_dump($spiltString);
9912
		exit;
9913
		*/
226 liveuser 9914
 
3 liveuser 9915
		#預設 fileArgu 的路徑為 ""
9916
		$fileArguPath="";
226 liveuser 9917
 
3 liveuser 9918
		#針對每個目錄
9919
		for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 9920
 
3 liveuser 9921
			#串接路徑
9922
			$fileArguPath=$fileArguPath."/".$spiltString["dataArray"][$i];
226 liveuser 9923
 
3 liveuser 9924
			}#for end
226 liveuser 9925
 
3 liveuser 9926
		#取得相對於目標的當前位置
9927
		#函式說明:
9928
		#呼叫shell執行系統命令,並取得回傳的內容.
9929
		#回傳結果:
9930
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9931
		#$result["error"],錯誤訊息陣列.
9932
		#$result["function"],當前執行的函數名稱.
9933
		#$result["argu"],使用的參數.
9934
		#$result["cmd"],執行的指令內容.
9935
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9936
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9937
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9938
		#$result["running"],是否還在執行.
9939
		#$result["pid"],pid.
9940
		#$result["statusCode"],執行結束後的代碼.
9941
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
9942
		#必填參數:
9943
		#$conf["command"],字串,要執行的指令.
9944
		$conf["external::callShell"]["command"]="cd";
9945
		#$conf["fileArgu"],字串,變數__FILE__的內容.
9946
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
9947
		#可省略參數:
9948
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9949
		$conf["external::callShell"]["argu"]=array($fileArguPath,";","pwd");
9950
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9951
		#$conf["arguIsAddr"]=array();
9952
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9953
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9954
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9955
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9956
		#$conf["enablePrintDescription"]="true";
9957
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9958
		#$conf["printDescription"]="";
9959
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9960
		$conf["external::callShell"]["escapeshellarg"]="true";
9961
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9962
		#$conf["thereIsShellVar"]=array();
9963
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9964
		#$conf["username"]="";
9965
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9966
		#$conf["password"]="";
9967
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9968
		#$conf["useScript"]="";
9969
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9970
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9971
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9972
		#$conf["inBackGround"]="";
9973
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9974
		#$conf["getErr"]="false";
9975
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9976
		#$conf["doNotRun"]="false";
9977
		#參考資料:
9978
		#exec=>http://php.net/manual/en/function.exec.php
9979
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9980
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9981
		#備註:
9982
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9983
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9984
		$callShell=external::callShell($conf["external::callShell"]);
9985
		unset($conf["external::callShell"]);
226 liveuser 9986
 
3 liveuser 9987
		#如果執行失敗
9988
		if($callShell["status"]==="false"){
226 liveuser 9989
 
3 liveuser 9990
			#設置錯誤識別
9991
			$result["status"]="false";
226 liveuser 9992
 
3 liveuser 9993
			#設置錯誤訊息
9994
			$result["error"]=$callShell;
226 liveuser 9995
 
3 liveuser 9996
			#回傳結果
9997
			return $result;
226 liveuser 9998
 
3 liveuser 9999
			}#if end
226 liveuser 10000
 
3 liveuser 10001
		#如果執行失敗
10002
		if(!isset($callShell["output"][0])){
226 liveuser 10003
 
3 liveuser 10004
			#設置錯誤識別
10005
			$result["status"]="false";
226 liveuser 10006
 
3 liveuser 10007
			#設置錯誤訊息
10008
			$result["error"]=$callShell;
226 liveuser 10009
 
3 liveuser 10010
			#回傳結果
10011
			return $result;
226 liveuser 10012
 
10013
			}#if end
10014
 
3 liveuser 10015
		/*
10016
		#break point
10017
		var_dump($callShell);
10018
		exit;
10019
		*/
226 liveuser 10020
 
3 liveuser 10021
		#記錄執行的指令
10022
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 10023
 
3 liveuser 10024
		#保存相對於目標的當前位置
10025
		$pwd=$callShell["output"][0];
226 liveuser 10026
 
3 liveuser 10027
		#更新 fileArgu
10028
		$conf["fileArgu"]=$pwd."/".$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 10029
 
3 liveuser 10030
		#針對每個 $conf["path"]
10031
		foreach($conf["path"] as $path){
226 liveuser 10032
 
3 liveuser 10033
			#將 $path 變成易讀的格式
10034
			#函式說明:
10035
			#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
10036
			#回傳的結果:
10037
			#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
10038
			#$result["function"],當前執行的函數.
10039
			#$result["error"],錯誤訊息陣列.
10040
			#$result["changedPath"],處理完後回傳的目錄字串.
10041
			#$result["oriPath"],原始的路徑字串
10042
			#必填參數:
10043
			#$conf["dirStr"],字串,要處理的檔案目錄字串.
10044
			$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$path;
10045
			$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
10046
			unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 10047
 
3 liveuser 10048
			#如果處理失敗
10049
			if($changeDirByDotDotSolidus["status"]==="false"){
226 liveuser 10050
 
3 liveuser 10051
				#設置錯誤識別
10052
				$result["status"]="false";
226 liveuser 10053
 
3 liveuser 10054
				#設置錯誤訊息
10055
				$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10056
 
3 liveuser 10057
				#回傳結果
10058
				return $result;
226 liveuser 10059
 
3 liveuser 10060
				}#if end
226 liveuser 10061
 
3 liveuser 10062
			#取得易讀的路徑
10063
			$path=$changeDirByDotDotSolidus["changedPath"];
226 liveuser 10064
 
3 liveuser 10065
			#判斷 $path 是否為絕對路徑
10066
			#函式說明:
10067
			#取得符合特定字首與字尾的字串
10068
			#回傳結果:
10069
			#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10070
			#$result["function"],當前執行的函數名稱.
10071
			#$result["error"],錯誤訊息陣列.
10072
			#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10073
			#$result["returnString"],爲符合字首條件的字串內容。
10074
			#必填參數:
10075
			#$conf["checkString"],字串,要檢查的字串.
10076
			$conf["search::getMeetConditionsString"]["checkString"]=$path;
10077
			#可省略參數:
10078
			#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10079
			$conf["search::getMeetConditionsString"]["frontWord"]="/";
10080
			#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10081
			#$conf["tailWord"]="";
10082
			#參考資料:
10083
			#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10084
			$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
226 liveuser 10085
			unset($conf["search::getMeetConditionsString"]);
10086
 
3 liveuser 10087
			#如果檢查失敗
10088
			if($getMeetConditionsString["status"]=="false"){
226 liveuser 10089
 
3 liveuser 10090
				#設置錯誤識別
10091
				$result["status"]="false";
226 liveuser 10092
 
3 liveuser 10093
				#設置錯誤訊息
10094
				$result["error"]=$getMeetConditionsString;
226 liveuser 10095
 
3 liveuser 10096
				#回傳結果
10097
				return $result;
226 liveuser 10098
 
3 liveuser 10099
				}#if end
226 liveuser 10100
 
3 liveuser 10101
			#如果沒有「/」開頭
10102
			if($getMeetConditionsString["founded"]==="false"){
226 liveuser 10103
 
3 liveuser 10104
				#將 $conf["fileArgu"] 最後面的檔案或目錄名稱剔除
10105
				#函式說明:
10106
				#將固定格式的字串分開,並回傳分開的結果。
10107
				#回傳結果:
10108
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10109
				#$result["error"],錯誤訊息陣列
10110
				#$result["function"],當前執行的函數名稱.
10111
				#$result["oriStr"],要分割的原始字串內容
10112
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
10113
				#$result["dataCounts"],爲總共分成幾段
10114
				#必填參數:
10115
				$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
10116
				$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
10117
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
10118
				unset($conf["stringProcess::spiltString"]);
226 liveuser 10119
 
3 liveuser 10120
				#如果分割字串失敗
10121
				if($spiltString["status"]=="false"){
226 liveuser 10122
 
3 liveuser 10123
					#設置錯誤識別
10124
					$result["status"]="false";
226 liveuser 10125
 
3 liveuser 10126
					#設置錯誤訊息
10127
					$result["error"]=$spiltString;
226 liveuser 10128
 
3 liveuser 10129
					#回傳結果
10130
					return $result;
226 liveuser 10131
 
3 liveuser 10132
					}#if end
226 liveuser 10133
 
3 liveuser 10134
				#初始化相對路徑為開頭片段""
10135
				$relativePathPart="/";
226 liveuser 10136
 
3 liveuser 10137
				#剔除最後一段
10138
				for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 10139
 
3 liveuser 10140
					#串接起來
10141
					$relativePathPart=$relativePathPart.$spiltString["dataArray"][$i]."/";
226 liveuser 10142
 
3 liveuser 10143
					}#for end
226 liveuser 10144
 
3 liveuser 10145
				#如果有設定 baseFrom
10146
				if(isset($conf["baseFrom"])){
226 liveuser 10147
 
3 liveuser 10148
					#函式說明:
10149
					#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
10150
					#回傳結果:
10151
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10152
					#$result["error"],錯誤訊息陣列.
226 liveuser 10153
					#$result["function"],函數名稱.
3 liveuser 10154
					#$result["argu"],使用的參數.
10155
					#$result["content"],網址,若是在命令列執行,則為"null".
10156
					#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
10157
					#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
10158
					#必填參數:
10159
					#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
10160
					$conf["fileAccess::getInternetAddressV2"]["address"]=$path;
10161
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
10162
					$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
10163
					#可省略參數:
10164
					#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
10165
					$conf["fileAccess::getInternetAddressV2"]["web"]="false";
10166
					#參考資料:
10167
					#無.
10168
					#備註:
10169
					#無.
10170
					$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
10171
					unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 10172
 
3 liveuser 10173
					##var_dump(__LINE__." ".print_r($getInternetAddressV2,true));
226 liveuser 10174
 
3 liveuser 10175
					#如果執行失敗
10176
					if($getInternetAddressV2["status"]==="false"){
226 liveuser 10177
 
3 liveuser 10178
						#設置錯誤識別
10179
						$result["status"]="false";
226 liveuser 10180
 
3 liveuser 10181
						#設置錯誤訊息
10182
						$result["error"]=$getInternetAddressV2;
226 liveuser 10183
 
3 liveuser 10184
						#回傳結果
10185
						return $result;
226 liveuser 10186
 
3 liveuser 10187
						}#if end
226 liveuser 10188
 
3 liveuser 10189
					#取得絕對位置
10190
					$path=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 10191
 
3 liveuser 10192
					#函式說明:
10193
					#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
10194
					#回傳結果:
10195
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10196
					#$result["error"],錯誤訊息陣列.
226 liveuser 10197
					#$result["function"],函數名稱.
3 liveuser 10198
					#$result["argu"],使用的參數.
10199
					#$result["content"],網址,若是在命令列執行,則為"null".
10200
					#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
10201
					#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
10202
					#必填參數:
10203
					#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
10204
					$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["baseFrom"];
10205
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
10206
					$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
10207
					#可省略參數:
10208
					#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
10209
					$conf["fileAccess::getInternetAddressV2"]["web"]="false";
10210
					#參考資料:
10211
					#無.
10212
					#備註:
10213
					#無.
10214
					$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
10215
					unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 10216
 
3 liveuser 10217
					#var_dump(__LINE__." ".print_r($getInternetAddressV2,true));
226 liveuser 10218
 
3 liveuser 10219
					#如果執行失敗
10220
					if($getInternetAddressV2["status"]==="false"){
226 liveuser 10221
 
3 liveuser 10222
						#設置錯誤識別
10223
						$result["status"]="false";
226 liveuser 10224
 
3 liveuser 10225
						#設置錯誤訊息
10226
						$result["error"]=$getInternetAddressV2;
226 liveuser 10227
 
3 liveuser 10228
						#回傳結果
10229
						return $result;
226 liveuser 10230
 
3 liveuser 10231
						}#if end
226 liveuser 10232
 
3 liveuser 10233
					#取得絕對位置
10234
					$conf["baseFrom"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 10235
 
3 liveuser 10236
					#函式說明:
10237
					#將多個路徑字串變成相對於當前路徑的相對路徑字串
10238
					#回傳結果:
10239
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10240
					#$result["error"],錯誤訊息陣列.
226 liveuser 10241
					#$result["function"],函數名稱.
3 liveuser 10242
					#$result["argu"],使用的參數.
10243
					#$result["content"],字串陣列,多個轉換好的相對路徑字串.
10244
					#必填參數:
10245
					#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
10246
					$conf["fileAccess::getRelativePath"]["path"]=array($path);
10247
					#$conf["fileArgu"],字串,當前路徑.
10248
					$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["baseFrom"]."/name";
10249
					#可省略參數:
10250
					#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
10251
					#$conf["baseFrom"]="";
10252
					#參考資料:
10253
					#無.
10254
					#備註:
10255
					#無.
10256
					$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
10257
					unset($conf["fileAccess::getRelativePath"]);
226 liveuser 10258
 
3 liveuser 10259
					#var_dump(__LINE__." ".print_r($getRelativePath,true));
226 liveuser 10260
 
3 liveuser 10261
					#如果執行失敗
10262
					if($getRelativePath["status"]==="false"){
226 liveuser 10263
 
3 liveuser 10264
						#設置錯誤識別
10265
						$result["status"]="false";
226 liveuser 10266
 
3 liveuser 10267
						#設置錯誤訊息
10268
						$result["error"]=$getRelativePath;
226 liveuser 10269
 
3 liveuser 10270
						#回傳結果
10271
						return $result;
226 liveuser 10272
 
3 liveuser 10273
						}#if end
226 liveuser 10274
 
3 liveuser 10275
					#取得轉換好的絕對路徑
10276
					$relativePathPart=$getRelativePath["content"][0]."/";
226 liveuser 10277
 
3 liveuser 10278
					#清空path,避免出錯
10279
					$path="";
226 liveuser 10280
 
3 liveuser 10281
					}#if end
226 liveuser 10282
 
3 liveuser 10283
				#轉換成易讀的相對路徑
10284
				#函式說明:
10285
				#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
10286
				#回傳的結果:
10287
				#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
10288
				#$result["function"],當前執行的函數.
10289
				#$result["error"],錯誤訊息陣列.
10290
				#$result["changedPath"],處理完後回傳的目錄字串.
10291
				#$result["oriPath"],原始的路徑字串
10292
				#必填參數:
10293
				#$conf["dirStr"],字串,要處理的檔案目錄字串.
10294
				$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$relativePathPart.$path;
10295
				$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
10296
				unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 10297
 
10298
				#var_dump($changeDirByDotDotSolidus);
10299
 
3 liveuser 10300
				#如果轉換失敗
10301
				if($changeDirByDotDotSolidus["status"]=="false"){
226 liveuser 10302
 
3 liveuser 10303
					#設置錯誤識別
10304
					$result["status"]="false";
226 liveuser 10305
 
3 liveuser 10306
					#設置錯誤訊息
10307
					$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10308
 
3 liveuser 10309
					#回傳結果
10310
					return $result;
226 liveuser 10311
 
3 liveuser 10312
					}#if end
226 liveuser 10313
 
3 liveuser 10314
				#轉換為相對路徑
10315
				#函式說明:
10316
				#將多個路徑字串變成相對於當前路徑的相對路徑字串
10317
				#回傳結果:
10318
				#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10319
				#$result["error"],錯誤訊息陣列.
226 liveuser 10320
				#$result["function"],函數名稱.
3 liveuser 10321
				#$result["content"],字串陣列,多個轉換好的相對路徑字串.
10322
				#必填參數:
10323
				#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
10324
				$conf["fileAccess::getRelativePath"]["path"]=array($changeDirByDotDotSolidus["changedPath"]);
10325
				#$conf["fileArgu"],字串,當前路徑.
10326
				$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
10327
				$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
10328
				unset($conf["fileAccess::getRelativePath"]);
226 liveuser 10329
 
10330
				#var_dump($getRelativePath);
10331
 
3 liveuser 10332
				#如果轉換路徑失敗
10333
				if($getRelativePath["status"]==="false"){
226 liveuser 10334
 
3 liveuser 10335
					#設置錯誤識別
10336
					$result["status"]="false";
226 liveuser 10337
 
3 liveuser 10338
					#設置錯誤訊息
10339
					$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10340
 
3 liveuser 10341
					#回傳結果
10342
					return $result;
226 liveuser 10343
 
3 liveuser 10344
					}#if end
226 liveuser 10345
 
3 liveuser 10346
				#取得相對路徑
10347
				$result["content"][]=$getRelativePath["content"][0];
226 liveuser 10348
 
3 liveuser 10349
				}#if end
226 liveuser 10350
 
3 liveuser 10351
			#反之有「/」開頭
10352
			else{
10353
				#函式說明:
10354
				#移除多個絕對路徑字串開頭相同的部分
10355
				#回傳結果:
10356
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10357
				#$result["error"],錯誤訊息陣列.
10358
				#$result["function"],當前執行的函數名稱.
10359
				#$result["content"],處理好的的字串內容.
10360
				#必填參數:
10361
				#$conf["pathIn"],字串陣列,每個要處理的絕對路徑字串.
226 liveuser 10362
				$conf["fileAccess::delSamePathHead"]["pathIn"]=array($path,$conf["fileArgu"]);
3 liveuser 10363
				$delSamePathHead=fileAccess::delSamePathHead($conf["fileAccess::delSamePathHead"]);
10364
				unset($conf["fileAccess::delSamePathHead"]);
226 liveuser 10365
 
3 liveuser 10366
				#var_dump($delSamePathHead);
226 liveuser 10367
 
3 liveuser 10368
				#如果移除多個絕對路徑字串開頭相同的部分失敗
10369
				if($delSamePathHead["status"]==="false"){
226 liveuser 10370
 
3 liveuser 10371
					#設置錯誤識別
10372
					$result["status"]="false";
226 liveuser 10373
 
3 liveuser 10374
					#設置錯誤訊息
10375
					$result["error"]=$delSameHead;
226 liveuser 10376
 
3 liveuser 10377
					#回傳結果
10378
					return $result;
226 liveuser 10379
 
3 liveuser 10380
					}#if end
226 liveuser 10381
 
3 liveuser 10382
				#如果 $conf["fileArgu"] 剩下空
10383
				if($delSamePathHead["content"][1]===""){
226 liveuser 10384
 
3 liveuser 10385
					#檢查 $delSamePathHead[0] 開頭是否為「/」
10386
					#函式說明:
10387
					#取得符合特定字首與字尾的字串
10388
					#回傳結果:
10389
					#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10390
					#$result["function"],當前執行的函數名稱.
10391
					#$result["error"],錯誤訊息陣列.
10392
					#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10393
					#$result["returnString"],爲符合字首條件的字串內容。
10394
					#必填參數:
10395
					#$conf["checkString"],字串,要檢查的字串.
10396
					$conf["search::getMeetConditionsString"]["checkString"]=$delSamePathHead["content"][0];
10397
					#可省略參數:
10398
					#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10399
					$conf["search::getMeetConditionsString"]["frontWord"]="/";
10400
					#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10401
					#$conf["tailWord"]="";
10402
					#參考資料:
10403
					#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10404
					$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
10405
					unset($conf["search::getMeetConditionsString"]);
226 liveuser 10406
 
3 liveuser 10407
					#如果檢查失敗
10408
					if($getMeetConditionsString["status"]=="false"){
226 liveuser 10409
 
3 liveuser 10410
						#設置錯誤識別
10411
						$result["status"]="false";
226 liveuser 10412
 
3 liveuser 10413
						#設置錯誤訊息
10414
						$result["error"]=$getMeetConditionsString;
226 liveuser 10415
 
3 liveuser 10416
						#回傳結果
10417
						return $result;
226 liveuser 10418
 
3 liveuser 10419
						}#if end
226 liveuser 10420
 
3 liveuser 10421
					#如果有開頭有「/」
10422
					if($getMeetConditionsString["founded"]==="true"){
226 liveuser 10423
 
3 liveuser 10424
						#函式說明:
10425
						#將字串特定關鍵字與其前面的內容剔除
10426
						#回傳結果:
10427
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10428
						#$result["error"],錯誤訊息陣列.
10429
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
10430
						#$result["function"],當前執行的函數名稱.
10431
						#$result["oriStr"],要處理的原始字串內容.
10432
						#$result["content"],處理好的的字串內容.
10433
						#必填參數:
10434
						$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$delSamePathHead["content"][0];#要處理的字串.
10435
						$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="/";#特定字串.
10436
						$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
10437
						unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 10438
 
3 liveuser 10439
						#如果 將字串特定關鍵字與其前面的內容剔除 失敗
10440
						if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 10441
 
3 liveuser 10442
							#設置錯誤識別
10443
							$result["status"]="false";
226 liveuser 10444
 
3 liveuser 10445
							#設置錯誤訊息
10446
							$result["error"]=$delStrBeforeKeyWord;
226 liveuser 10447
 
3 liveuser 10448
							#回傳結果
10449
							return $result;
226 liveuser 10450
 
3 liveuser 10451
							}#if end
226 liveuser 10452
 
3 liveuser 10453
						#取得相對位置
10454
						$result["content"][]=$delStrBeforeKeyWord["content"];
226 liveuser 10455
 
3 liveuser 10456
						}#if end
226 liveuser 10457
 
3 liveuser 10458
					#反之
10459
					else{
226 liveuser 10460
 
3 liveuser 10461
						#取得相對位置
10462
						$result["content"][]=$delSamePathHead["content"][0];
226 liveuser 10463
 
10464
						}#else end
10465
 
3 liveuser 10466
					}#if end
226 liveuser 10467
 
3 liveuser 10468
				#反之剩下的 $conf["fileArgu"] 不為空
10469
				else{
226 liveuser 10470
 
3 liveuser 10471
					#檢查 $delSamePathHead["content"][1] 有幾個「/」
10472
					#函式說明:
10473
					#檢查字串裡面有無指定的關鍵字
10474
					#回傳結果:
10475
					#$result["status"],"true"代表執行成功,"false"代表執行失敗。
10476
					#$result["error"],錯誤訊息
10477
					#$result["function"],當前執行的函數名稱.
10478
					#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
10479
					#$result["keyWordCount"],找到的關鍵字數量.
10480
					#必填參數:
10481
					$conf["search::findKeyWord"]["keyWord"]="/";#想要搜尋的關鍵字
10482
					$conf["search::findKeyWord"]["string"]=$delSamePathHead["content"][1];#要被搜尋的字串內容
10483
					#可省略參數:
10484
					#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
10485
					$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
10486
					unset($conf["search::findKeyWord"]);
226 liveuser 10487
 
3 liveuser 10488
					#如果 檢查字串裡面有無指定的關鍵字 失敗
10489
					if($findKeyWord["status"]==="false"){
226 liveuser 10490
 
3 liveuser 10491
						#設置錯誤識別
10492
						$result["status"]="false";
226 liveuser 10493
 
3 liveuser 10494
						#設置錯誤訊息
10495
						$result["error"]=$findKeyWord;
226 liveuser 10496
 
3 liveuser 10497
						#回傳結果
10498
						return $result;
226 liveuser 10499
 
3 liveuser 10500
						}#if end
226 liveuser 10501
 
3 liveuser 10502
					#有幾個「/」就執行幾次
10503
					for($i=0;$i<$findKeyWord["keyWordCount"];$i++){
226 liveuser 10504
 
3 liveuser 10505
						#在前面加上 "../"
10506
						$delSamePathHead["content"][0]="../".$delSamePathHead["content"][0];
226 liveuser 10507
 
3 liveuser 10508
						}#for end
226 liveuser 10509
 
3 liveuser 10510
					#取得相對位置
10511
					$result["content"][]=$delSamePathHead["content"][0];
226 liveuser 10512
 
3 liveuser 10513
					}#else end
226 liveuser 10514
 
3 liveuser 10515
				}#else end
226 liveuser 10516
 
3 liveuser 10517
			}#foreach end
226 liveuser 10518
 
3 liveuser 10519
		#設置執行正常
10520
		$result["status"]="true";
226 liveuser 10521
 
3 liveuser 10522
		#回傳結果
10523
		return $result;
226 liveuser 10524
 
3 liveuser 10525
		}#function getRelativeParh end
10526
 
10527
	/*
10528
	#函式說明:
10529
	#移除多個絕對路徑字串開頭相同的部分
10530
	#回傳結果:
10531
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10532
	#$result["error"],錯誤訊息陣列.
10533
	#$result["function"],當前執行的函數名稱.
10534
	#$result["argu"],參數.
10535
	#$result["content"],處理好的的字串內容.
10536
	#必填參數:
10537
	#$conf["pathIn"],字串陣列,每個要處理的絕對路徑字串.
226 liveuser 10538
	$conf["pathIn"]=array();
3 liveuser 10539
	#可省略參數:
10540
	#無
10541
	#參考資料:
10542
	#無.
10543
	#備註:
10544
	#無.
10545
	*/
10546
	public static function delSamePathHead(&$conf){
226 liveuser 10547
 
3 liveuser 10548
		#初始化要回傳的結果
10549
		$result=array();
10550
 
10551
		#取得當前執行的函數名稱
10552
		$result["function"]=__FUNCTION__;
10553
 
10554
		#如果沒有參數
10555
		if(func_num_args()==0){
226 liveuser 10556
 
3 liveuser 10557
			#設置執行失敗
10558
			$result["status"]="false";
226 liveuser 10559
 
3 liveuser 10560
			#設置執行錯誤訊息
10561
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 10562
 
3 liveuser 10563
			#回傳結果
10564
			return $result;
226 liveuser 10565
 
3 liveuser 10566
			}#if end
10567
 
10568
		#如果 $conf 不為陣列
10569
		if(gettype($conf)!="array"){
226 liveuser 10570
 
3 liveuser 10571
			#設置執行失敗
10572
			$result["status"]="false";
226 liveuser 10573
 
3 liveuser 10574
			#設置執行錯誤訊息
10575
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 10576
 
3 liveuser 10577
			#如果傳入的參數為 null
10578
			if($conf==null){
226 liveuser 10579
 
3 liveuser 10580
				#設置執行錯誤訊息
10581
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 10582
 
3 liveuser 10583
				}#if end
10584
 
10585
			#回傳結果
10586
			return $result;
226 liveuser 10587
 
3 liveuser 10588
			}#if end
226 liveuser 10589
 
3 liveuser 10590
		#取得參數
226 liveuser 10591
		$result["argv"]=$conf;
10592
 
3 liveuser 10593
		#檢查參數
10594
		#函式說明:
10595
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
10596
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10597
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10598
		#$result["function"],當前執行的函式名稱.
10599
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10600
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10601
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10602
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
10603
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10604
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10605
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10606
		#必填寫的參數:
10607
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10608
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10609
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10610
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("pathIn");
226 liveuser 10611
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 10612
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
10613
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10614
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10615
		#可以省略的參數:
10616
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
10617
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
10618
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10619
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileToRead","output");
226 liveuser 10620
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 10621
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
10622
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10623
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("help","help");
10624
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10625
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
10626
		#參考資料來源:
10627
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10628
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10629
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 10630
 
3 liveuser 10631
		#如果 $checkResult["status"] 等於 "fasle"
10632
		if($checkResult["status"]=="false"){
226 liveuser 10633
 
3 liveuser 10634
			#設置錯誤識別
10635
			$result["status"]="false";
226 liveuser 10636
 
3 liveuser 10637
			#設置錯誤訊息
10638
			$result["error"]=$checkResult;
226 liveuser 10639
 
3 liveuser 10640
			#回傳結果
10641
			return $result;
226 liveuser 10642
 
3 liveuser 10643
			}#if end
226 liveuser 10644
 
3 liveuser 10645
		#如果 $checkResult["passed"] 等於 "fasle"
10646
		if($checkResult["passed"]=="false"){
226 liveuser 10647
 
3 liveuser 10648
			#設置錯誤識別
10649
			$result["status"]="false";
226 liveuser 10650
 
3 liveuser 10651
			#設置錯誤訊息
10652
			$result["error"]=$checkResult;
226 liveuser 10653
 
3 liveuser 10654
			#回傳結果
10655
			return $result;
226 liveuser 10656
 
3 liveuser 10657
			}#if end
226 liveuser 10658
 
3 liveuser 10659
		#檢查是否都為絕對路徑
10660
		#函式說明:
10661
		#取得多個符合特定字首與字尾的字串.
10662
		#回傳結果:
10663
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10664
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10665
		#$result["function"],當前執行的函數名稱.
10666
		#$result["returnString"],爲符合字首條件的字串陣列內容。
10667
		#必填參數:
10668
		#$conf["checkString"],陣列字串,要檢查的字串們.
10669
		$conf["search::getMeetConditionsStringMulti"]["checkString"]=$conf["pathIn"];#要檢查的字串陣列
10670
		#可省略參數:
10671
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10672
		$conf["search::getMeetConditionsStringMulti"]["frontWord"]="/";
10673
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10674
		#$conf["tailWord"]="";
10675
		#參考資料:
10676
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10677
		$getMeetConditionsStringMulti=search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]);
10678
		unset($conf["search::getMeetConditionsStringMulti"]);
226 liveuser 10679
 
3 liveuser 10680
		#如果檢測是否為絕對路徑失敗
10681
		if($getMeetConditionsStringMulti["status"]=="false"){
226 liveuser 10682
 
3 liveuser 10683
			#設置錯誤識別
10684
			$result["status"]="false";
226 liveuser 10685
 
3 liveuser 10686
			#設置錯誤訊息
10687
			$result["error"]=$getMeetConditionsStringMulti;
226 liveuser 10688
 
3 liveuser 10689
			#增加額外的錯誤訊息
10690
			$result["error"][]="僅接受絕對路徑字串";
226 liveuser 10691
 
3 liveuser 10692
			#回傳結果
10693
			return $result;
226 liveuser 10694
 
3 liveuser 10695
			}#if end
226 liveuser 10696
 
3 liveuser 10697
		#函式說明:
10698
		#將多個固定格式的字串分開,並回傳分開的結果
10699
		#回傳的參數:
10700
		#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
10701
		#$result["error"],錯誤訊息陣列.
10702
		#$result["function"],當前執行的函數名稱.
10703
		#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
10704
		#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
10705
		#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
10706
		#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
10707
		#必填參數:
10708
		#$conf["stringIn"],字串陣列,要處理的字串陣列.
10709
		$conf["stringProcess::spiltMutiString"]["stringIn"]=$conf["pathIn"];
10710
		#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
10711
		$conf["stringProcess::spiltMutiString"]["spiltSymbol"]="/";
10712
		$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
226 liveuser 10713
 
3 liveuser 10714
		#如果分割所有路徑字串失敗
10715
		if($spiltMutiString["status"]=="false"){
226 liveuser 10716
 
3 liveuser 10717
			#設置錯誤識別
10718
			$result["status"]="false";
226 liveuser 10719
 
3 liveuser 10720
			#設置錯誤訊息
226 liveuser 10721
			$result["error"]=$spiltMutiString;
10722
 
3 liveuser 10723
			#回傳結果
10724
			return $result;
226 liveuser 10725
 
3 liveuser 10726
			}#if end
226 liveuser 10727
 
3 liveuser 10728
		#初始化暫存每個路徑分割成的段數
226 liveuser 10729
		$spiltedPathCount=array();
10730
 
3 liveuser 10731
		#取得每個路徑分割成的段數
10732
		#針對每個 $spiltMutiString["spiltString"]
10733
		for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
226 liveuser 10734
 
3 liveuser 10735
			$spiltedPathCount[]=$spiltMutiString["spiltString"][$i]["dataCounts"];
226 liveuser 10736
 
3 liveuser 10737
			}#for end
226 liveuser 10738
 
3 liveuser 10739
		#取得所有路徑字串分割後的最小數量
10740
		#涵式說明
10741
		#找最小值,結果會回傳最小值
10742
		#回傳的內容
10743
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
10744
		#$result["error"],錯誤訊息陣列.
10745
		#$result["function"],當前執行的函數名稱.
10746
		#$result["key"],最大值原先的key.
10747
		#$result["value"],陣列裏面最小的數值.
10748
		#必填參數:
10749
		$conf["math::getMinValue"]["rawDataArray"]=$spiltedPathCount;#爲原始數據
10750
		$getMinValue=math::getMinValue($conf["math::getMinValue"]);
10751
		unset($conf["math::getMinValue"]);
226 liveuser 10752
 
3 liveuser 10753
		#如果取得最小數值失敗
10754
		if($getMinValue["status"]=="false"){
226 liveuser 10755
 
3 liveuser 10756
			#設置錯誤識別
10757
			$result["status"]="false";
226 liveuser 10758
 
3 liveuser 10759
			#設置錯誤訊息
226 liveuser 10760
			$result["error"]=$getMinValue;
10761
 
3 liveuser 10762
			#回傳結果
10763
			return $result;
226 liveuser 10764
 
10765
			}#if end
10766
 
3 liveuser 10767
		#初始化暫存每個路徑字串的前面幾個片段是相同的
10768
		$samePartCount=0;
226 liveuser 10769
 
10770
		#var_dump($getMinValue["value"]);
10771
 
3 liveuser 10772
		#依據所有路徑字串分割後的最小數量
10773
		for($j=0;$j<$getMinValue["value"];$j++){
226 liveuser 10774
 
3 liveuser 10775
			#初始化暫存第一個路徑的片段字串
10776
			$firstPathPart="";
226 liveuser 10777
 
3 liveuser 10778
			#針對每個 $spiltMutiString["spiltString"]
10779
			for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
226 liveuser 10780
 
3 liveuser 10781
				#暫存分割的字串
10782
				$spiltedPath=$spiltMutiString["spiltString"][$i];
226 liveuser 10783
 
3 liveuser 10784
				#如果是第一個路徑
10785
				if($i==0){
226 liveuser 10786
 
3 liveuser 10787
					#取得第一個路徑的片段字串
10788
					$firstPathPart=$spiltedPath["dataArray"][$j];
226 liveuser 10789
 
10790
					}#if end
10791
 
3 liveuser 10792
				#如果第$i+1個路徑片段不跟第1個路徑的片段字串一樣
10793
				if($spiltedPath["dataArray"][$j]!=$firstPathPart){
226 liveuser 10794
 
3 liveuser 10795
					#讓最外層迴圈中止
10796
					$getMinValue["value"]=-1;
226 liveuser 10797
 
3 liveuser 10798
					#跳出迴圈
10799
					break;
226 liveuser 10800
 
10801
					}#if end
10802
 
3 liveuser 10803
				}#for end
226 liveuser 10804
 
3 liveuser 10805
			#代表每個路徑字串的第$j段是一樣的.
10806
			$samePartCount=$j;
226 liveuser 10807
 
3 liveuser 10808
			}#for end
226 liveuser 10809
 
3 liveuser 10810
		#var_dump($samePartCount);
226 liveuser 10811
 
3 liveuser 10812
		#依據每個路徑
226 liveuser 10813
		for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
10814
 
3 liveuser 10815
			#初始化儲存第$i+1個處理好的路徑字串
226 liveuser 10816
			$result["content"][$i]="";
10817
 
3 liveuser 10818
			#依據 $samePartCount 與 路徑的段數
10819
			for($j=$samePartCount;$j<$spiltMutiString["spiltString"][$i]["dataCounts"];$j++){
226 liveuser 10820
 
3 liveuser 10821
				#如果不是第一段
10822
				if($j!=$samePartCount){
226 liveuser 10823
 
3 liveuser 10824
					#組裝每個路徑片段
10825
					$result["content"][$i]=$result["content"][$i]."/".$spiltMutiString["spiltString"][$i]["dataArray"][$j];
226 liveuser 10826
 
3 liveuser 10827
					}#if end
226 liveuser 10828
 
3 liveuser 10829
				#反之為第一段
10830
				else{
226 liveuser 10831
 
3 liveuser 10832
					#組裝每個路徑片段
10833
					$result["content"][$i]=$result["content"][$i].$spiltMutiString["spiltString"][$i]["dataArray"][$j];
226 liveuser 10834
 
3 liveuser 10835
					}#else end
226 liveuser 10836
 
3 liveuser 10837
				}#for end
226 liveuser 10838
 
3 liveuser 10839
			}#for end
226 liveuser 10840
 
3 liveuser 10841
		#設置執行正常
10842
		$result["status"]="true";
226 liveuser 10843
 
3 liveuser 10844
		#回傳結果
10845
		return $result;
226 liveuser 10846
 
3 liveuser 10847
		}#function delSamePathHead end
10848
 
10849
	/*
10850
	#函式說明:
226 liveuser 10851
	#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
3 liveuser 10852
	#回傳結果:
10853
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10854
	#$result["error"],錯誤訊息.
10855
	#$result["function"],當前執行的函數名稱.
10856
	#$result["content"],暫存檔案的路徑與名稱.
10857
	#$result["fileName"],暫存檔案的名稱.
10858
	#$result["path"],暫存檔案的路徑.
10859
	#必填參數:
10860
	#無.
10861
	#可省略參數:
36 liveuser 10862
	#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
10863
	#$conf["contant"]=array();
3 liveuser 10864
	#參考資料:
10865
	#無.
10866
	#備註:
10867
	#無.
10868
	*/
36 liveuser 10869
	public static function createTempFile(&$conf){
226 liveuser 10870
 
3 liveuser 10871
		#初始化要回傳的結果
10872
		$result=array();
10873
 
10874
		#取得當前執行的函數名稱
10875
		$result["function"]=__FUNCTION__;
226 liveuser 10876
 
36 liveuser 10877
		#取得參數
10878
		$result["argu"]=$conf;
10879
 
10880
		#如果 $conf 不為陣列
10881
		if(gettype($conf)!="array"){
10882
 
10883
			#設置執行失敗
10884
			$result["status"]="false";
10885
 
10886
			#設置執行錯誤訊息
10887
			$result["error"][]="\$conf變數須為陣列形態";
10888
 
10889
			#如果傳入的參數為 null
10890
			if(is_null($conf)){
10891
 
10892
				#設置執行錯誤訊息
10893
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
10894
 
10895
				}#if end
10896
 
10897
			#回傳結果
10898
			return $result;
10899
 
10900
			}#if end
226 liveuser 10901
 
36 liveuser 10902
		#檢查參數
10903
		#函式說明:
10904
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
10905
		#回傳結果:
10906
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10907
		#$result["error"],執行不正常結束的錯訊息陣列.
10908
		#$result["simpleError"],簡單表示的錯誤訊息.
10909
		#$result["function"],當前執行的函式名稱.
10910
		#$result["argu"],設置給予的參數.
10911
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10912
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10913
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10914
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
10915
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
10916
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10917
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10918
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10919
		#必填參數:
10920
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10921
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10922
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10923
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10924
		#可省略參數:
10925
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10926
		#$conf["mustBeFilledVariableName"]=array();
10927
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
10928
		#$conf["mustBeFilledVariableType"]=array();
10929
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
10930
		#$conf["canBeEmptyString"]="false";
10931
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
10932
		#$conf["canNotBeEmpty"]=array();
10933
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
10934
		#$conf["canBeEmpty"]=array();
10935
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
10936
		#$conf["skipableVariableCanNotBeEmpty"]=array();
10937
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10938
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("content");
10939
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
10940
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
10941
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10942
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array());
10943
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
10944
		#$conf["disallowAllSkipableVarIsEmpty"]="";
10945
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
10946
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
10947
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
10948
		#$conf["disallowAllSkipableVarNotExist"]="";
10949
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10950
		#$conf["arrayCountEqualCheck"][]=array();
10951
		#參考資料:
10952
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10953
		#備註:
10954
		#無.
10955
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10956
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 10957
 
36 liveuser 10958
		#如果執行失敗
10959
		if($checkArguments["status"]==="false"){
226 liveuser 10960
 
36 liveuser 10961
			#設置執行異常
10962
			$result["status"]="false";
226 liveuser 10963
 
36 liveuser 10964
			#設置錯誤訊息
10965
			$result["error"]=$checkArguments;
226 liveuser 10966
 
36 liveuser 10967
			#回傳結果
10968
			return $result;
226 liveuser 10969
 
36 liveuser 10970
			}#if end
226 liveuser 10971
 
36 liveuser 10972
		#如果檢查不通過
10973
		if($checkArguments["passed"]==="false"){
226 liveuser 10974
 
36 liveuser 10975
			#設置執行異常
10976
			$result["status"]="false";
226 liveuser 10977
 
36 liveuser 10978
			#設置錯誤訊息
10979
			$result["error"]=$checkArguments;
226 liveuser 10980
 
36 liveuser 10981
			#回傳結果
10982
			return $result;
226 liveuser 10983
 
36 liveuser 10984
			}#if end
226 liveuser 10985
 
3 liveuser 10986
		#取得相對於當前路徑的  tmp 目錄.
10987
		exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/tmp;pwd;",$output,$status);
226 liveuser 10988
 
3 liveuser 10989
		#如果執行失敗
10990
		if($status!==0){
226 liveuser 10991
 
3 liveuser 10992
			#設置執行失敗
10993
			$result["status"]="false";
10994
 
10995
			#設置執行錯誤訊息
10996
			$result["error"][]="取得暫存目錄失敗";
226 liveuser 10997
 
3 liveuser 10998
			#回傳結果
10999
			return $result;
226 liveuser 11000
 
11001
			}#if end
11002
 
3 liveuser 11003
		#設置預設的暫存目錄
226 liveuser 11004
		$defaultTmpDir=$output[0];
11005
 
3 liveuser 11006
		#取得暫存檔案的路徑與名稱
11007
		$result["content"]=tempnam($defaultTmpDir,"qbpwcf_tmpfile_");
226 liveuser 11008
 
42 liveuser 11009
		#如果產生的暫存檔案位置異常
11010
		#參考資料:
11011
		#https://www.php.net/manual/en/function.tempnam.php
11012
		if(strpos("/tmp/",$result["content"])===0){
226 liveuser 11013
 
42 liveuser 11014
			#設置執行失敗
11015
			$result["status"]="false";
11016
 
11017
			#設置執行錯誤訊息
11018
			$result["error"][]="於暫存目錄建立檔案失敗";
226 liveuser 11019
 
42 liveuser 11020
			#回傳結果
11021
			return $result;
226 liveuser 11022
 
42 liveuser 11023
			}#if end
226 liveuser 11024
 
3 liveuser 11025
		#函式說明:
11026
		#將字串特定關鍵字與其前面的內容剔除
11027
		#回傳結果:
11028
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11029
		#$result["error"],錯誤訊息陣列.
11030
		#$result["warning"],警告訊息鎮列.
11031
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
11032
		#$result["function"],當前執行的函數名稱.
11033
		#$result["argu"],使用的參數.
11034
		#$result["oriStr"],要處理的原始字串內容.
226 liveuser 11035
		#$result["content"],處理好的的字串內容.
3 liveuser 11036
		#必填參數:
11037
		#$conf["stringIn"],字串,要處理的字串.
11038
		$conf["stringPorcess::delStrBeforeKeyWord"]["stringIn"]=$result["content"];
11039
		#$conf["keyWord"],字串,特定字串.
42 liveuser 11040
		$conf["stringPorcess::delStrBeforeKeyWord"]["keyWord"]=$defaultTmpDir."/";
3 liveuser 11041
		#可省略參數:
11042
		#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
42 liveuser 11043
		$conf["stringPorcess::delStrBeforeKeyWord"]["recursive"]="true";
3 liveuser 11044
		#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
11045
		#$conf["lastResult"]=$delStrBeforeKeyWord;
11046
		#參考資料:
11047
		#無.
11048
		#備註:
11049
		#無.
11050
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringPorcess::delStrBeforeKeyWord"]);
11051
		unset($conf["stringPorcess::delStrBeforeKeyWord"]);
226 liveuser 11052
 
3 liveuser 11053
		#如果執行失敗
11054
		if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 11055
 
3 liveuser 11056
			#設置執行失敗
11057
			$result["status"]="false";
11058
 
11059
			#設置執行錯誤訊息
11060
			$result["error"]=$delStrBeforeKeyWord;
226 liveuser 11061
 
3 liveuser 11062
			#回傳結果
11063
			return $result;
226 liveuser 11064
 
3 liveuser 11065
			}#if end
226 liveuser 11066
 
3 liveuser 11067
		#如果應該要存在的路徑關鍵字不在
11068
		if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 11069
 
3 liveuser 11070
			#設置執行失敗
11071
			$result["status"]="false";
11072
 
11073
			#設置執行錯誤訊息
11074
			$result["error"]=$delStrBeforeKeyWord;
226 liveuser 11075
 
3 liveuser 11076
			#回傳結果
11077
			return $result;
226 liveuser 11078
 
3 liveuser 11079
			}#if end
226 liveuser 11080
 
3 liveuser 11081
		#取得檔案名稱
11082
		$result["fileName"]=$delStrBeforeKeyWord["content"];
226 liveuser 11083
 
3 liveuser 11084
		#函式說明:
11085
		#將字串特定關鍵字與其後面的內容剔除
11086
		#回傳結果:
11087
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11088
		#$result["error"],錯誤訊息陣列.
11089
		#$result["warning"],警告訊息鎮列.
11090
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
11091
		#$result["function"],當前執行的函數名稱.
11092
		#$result["oriStr"],要處理的原始字串內容.
11093
		#$result["content"],處理好的的字串內容.
11094
		#$result["argu"],使用的參數.
11095
		#必填參數:
11096
		#$conf["stringIn"],字串,要處理的字串.
11097
		$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$result["content"];
11098
		#$conf["keyWord"],字串,特定字串.
11099
		$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["fileName"];
11100
		#可省略參數:
11101
		#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
11102
		#$conf["deleteLastRepeatedOne"]="";
11103
		#參考資料:
11104
		#無.
11105
		#備註:
11106
		#無.
11107
		$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
11108
		unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 11109
 
3 liveuser 11110
		#如果執行失敗
11111
		if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 11112
 
3 liveuser 11113
			#設置執行失敗
11114
			$result["status"]="false";
11115
 
11116
			#設置執行錯誤訊息
11117
			$result["error"]=$delStrAfterKeyWord;
226 liveuser 11118
 
3 liveuser 11119
			#回傳結果
11120
			return $result;
226 liveuser 11121
 
3 liveuser 11122
			}#if end
226 liveuser 11123
 
3 liveuser 11124
		#如果應該要存在的檔案名稱關鍵字不在
11125
		if($delStrAfterKeyWord["founded"]==="false"){
226 liveuser 11126
 
3 liveuser 11127
			#設置執行失敗
11128
			$result["status"]="false";
11129
 
11130
			#設置執行錯誤訊息
11131
			$result["error"]=$delStrAfterKeyWord;
226 liveuser 11132
 
3 liveuser 11133
			#回傳結果
11134
			return $result;
226 liveuser 11135
 
3 liveuser 11136
			}#if end
226 liveuser 11137
 
3 liveuser 11138
		#取得路徑
11139
		$result["path"]=$delStrAfterKeyWord["content"];
226 liveuser 11140
 
36 liveuser 11141
		#如果有內容要寫入
11142
		if(!empty($conf["content"])){
226 liveuser 11143
 
36 liveuser 11144
			#函式說明:
11145
			#將多行字串寫入到檔案
11146
			#回傳結果:
11147
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
11148
			#$result["error"],錯誤訊息陣列.
11149
			#$result["function"],當前執行函數的名稱.
11150
			#必填參數:
11151
			#$conf["fileName"],字串,爲要編輯的檔案名稱
11152
			$conf["fileAccess::writeMultiLine"]["fileName"]=$result["content"];
11153
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
11154
			$conf["fileAccess::writeMultiLine"]["inputString"]=$conf["content"];
11155
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11156
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=__FILE__;
11157
			#可省略參數:
11158
			#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
11159
			#參考資料:
11160
			#無.
11161
			#備註:
11162
			#無.
11163
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
11164
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 11165
 
36 liveuser 11166
			#如果執行失敗
11167
			if($writeMultiLine["status"]==="false"){
226 liveuser 11168
 
36 liveuser 11169
				#設置執行失敗
11170
				$result["status"]="false";
11171
 
11172
				#設置執行錯誤訊息
11173
				$result["error"]=$writeMultiLine;
226 liveuser 11174
 
36 liveuser 11175
				#回傳結果
11176
				return $result;
226 liveuser 11177
 
36 liveuser 11178
				}#if end
226 liveuser 11179
 
36 liveuser 11180
			}#if end
226 liveuser 11181
 
3 liveuser 11182
		#設置執行正常
11183
		$result["status"]="true";
226 liveuser 11184
 
3 liveuser 11185
		#回傳結果
11186
		return $result;
226 liveuser 11187
 
3 liveuser 11188
		}#function createTempFile end
11189
 
11190
	/*
11191
	#函式說明:
253 liveuser 11192
	#複製檔案、資料夾,只要符合權限就會執行並覆蓋既有內容.
11193
	#回傳結果:
11194
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11195
	#$result["error"],錯誤訊息.
11196
	#$result["function"],當前執行的函式名稱.
11197
	#$result["content"],複製好的檔案路徑與名稱.
11198
	#必填參數:
11199
	#$conf["file"],字串,檔案的位置與名稱.
11200
	$conf["file"]="";
11201
	#$conf["to"],字串,檔案要複製到哪裡.
11202
	$conf["to"]="";
11203
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
11204
	$conf["fileArgu"]=__FILE__;
11205
	#可省略參數:
11206
	#無.
11207
	#參考資料:
11208
	#無.
11209
	#備註:
11210
	#等同於cmd::cp的應用.
11211
	*/
11212
	public static function cp(&$conf){
11213
 
11214
		#初始化要回傳的結果
11215
		$result=array();
11216
 
11217
		#取得當前執行的函式名稱
11218
		$result["function"]=__FUNCTION__;
11219
 
11220
		#如果沒有參數
11221
		if(func_num_args()==0){
11222
 
11223
			#設置執行失敗
11224
			$result["status"]="false";
11225
 
11226
			#設置執行錯誤訊息
11227
			$result["error"]="函式".$result["function"]."需要參數";
11228
 
11229
			#回傳結果
11230
			return $result;
11231
 
11232
			}#if end
11233
 
11234
		#取得參數
11235
		$result["argu"]=$conf;
11236
 
11237
		#如果 $conf 不為陣列
11238
		if(gettype($conf)!=="array"){
11239
 
11240
			#設置執行失敗
11241
			$result["status"]="false";
11242
 
11243
			#設置執行錯誤訊息
11244
			$result["error"][]="\$conf變數須為陣列形態";
11245
 
11246
			#如果傳入的參數為 null
11247
			if($conf===null){
11248
 
11249
				#設置執行錯誤訊息
11250
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
11251
 
11252
				}#if end
11253
 
11254
			#回傳結果
11255
			return $result;
11256
 
11257
			}#if end
11258
 
11259
		#檢查參數
11260
		#函式說明:
11261
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
11262
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11263
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11264
		#$result["function"],當前執行的函式名稱.
11265
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11266
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11267
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11268
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11269
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11270
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11271
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11272
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11273
		#必填寫的參數:
11274
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11275
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11276
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11277
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","to","fileArgu");
11278
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11279
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
11280
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11281
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11282
		#可以省略的參數:
11283
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11284
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11285
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11286
		#$conf["canNotBeEmpty"]=array();
11287
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11288
		#$conf["canBeEmpty"]=array();
11289
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11290
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11291
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11292
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","cmdOnly");
11293
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
11294
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
11295
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11296
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null,"true");
11297
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11298
		#$conf["arrayCountEqualCheck"][]=array();
11299
		#參考資料來源:
11300
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11301
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11302
		unset($conf["variableCheck::checkArguments"]);
11303
 
11304
		#如果參數檢查失敗
11305
		if($checkArguments["status"]==="false"){
11306
 
11307
			#設置執行不正常
11308
			$result["status"]="false";
11309
 
11310
			#設置執行錯誤
11311
			$result["error"]=$checkArguments;
11312
 
11313
			#回傳結果
11314
			return $result;
11315
 
11316
			}#if end
11317
 
11318
		#如果參數檢查不通過
11319
		if($checkArguments["passed"]==="false"){
11320
 
11321
			#設置執行不正常
11322
			$result["status"]="false";
11323
 
11324
			#設置執行錯誤
11325
			$result["error"]=$checkArguments;
11326
 
11327
			#回傳結果
11328
			return $result;
11329
 
11330
			}#if end
11331
 
11332
		#函式說明:
11333
		#複製檔案、資料夾,只要符合權限就會執行並覆蓋既有內容.
11334
		#回傳結果:
11335
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11336
		#$result["error"],錯誤訊息.
11337
		#$result["function"],當前執行的函式名稱.
11338
		#$result["content"],複製好的檔案路徑與名稱.
11339
		#必填參數:
11340
		#$conf["file"],字串,檔案的位置與名稱.
11341
		$conf["cmd::cp"]["file"]=$conf["file"];
11342
		#$conf["to"],字串,檔案要複製到哪裡.
11343
		$conf["cmd::cp"]["to"]=$conf["to"];
11344
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
11345
		$conf["cmd::cp"]["fileArgu"]=$conf["fileArgu"];
11346
		#可省略參數:
11347
		#$conf["cmdOnly"],字串,是否要只允許在cmd環境下運行,預設為"true",代表是;"false"代表沒有限制.
11348
		$conf["cmd::cp"]["cmdOnly"]="false";
11349
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
11350
		#$conf["username"]="";
11351
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
11352
		#$conf["password"]="";
11353
		#參考資料:
11354
		#無.
11355
		#備註:
11356
		#無.
11357
		$cp=cmd::cp($conf["cmd::cp"]);
11358
		unset($conf["cmd::cp"]);
11359
 
11360
		#如果執行異常
11361
		if($cp["status"]==="false"){
11362
 
11363
			#設置執行不正常
11364
			$result["status"]="false";
11365
 
11366
			#設置執行錯誤
11367
			$result["error"]=$cp;
11368
 
11369
			#回傳結果
11370
			return $result;
11371
 
11372
			}#if end
11373
 
11374
		#設置要回傳的 content
11375
		$result["content"]=$cp["content"];
11376
 
11377
		#設置執行正常
11378
		$result["status"]="true";
11379
 
11380
		#回傳結果
11381
		return $result;
11382
 
11383
		}#function cp end
11384
 
11385
	/*
11386
	#函式說明:
3 liveuser 11387
	#分割檔案,分割出來的檔案名稱編號為aa, ab ac...ba, bb, bc...,zx, zy, zz的順序.
11388
	#回傳結果:
11389
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11390
	#$result["error"],錯誤訊息陣列.
11391
	#$result["function"],當前執行的函數名稱.
11392
	#$result["cmd"],執行的指令.
11393
	#$result["content"],執行指令回傳的結果.
11394
	#必填參數:
11395
	#$conf["file"],字串,要分割的檔案名稱.
226 liveuser 11396
	$conf["file"]="";
3 liveuser 11397
	#可省略參數:
11398
	#$conf["splitNameHead"],字串,分割成檔案的名稱開頭,預設為 $conf["file"]."-" .
226 liveuser 11399
	#$conf["splitNameHead"]="";
3 liveuser 11400
	#$conf["partSize"],字串,分割檔的大小為多少?可以為XMB,XGB,XKB,可參見split指令的說明,預設為50MB.
11401
	#$conf["partSize"]="";
11402
	#參考資料:
11403
	#無.
11404
	#備註:
11405
	#需要有split指令
11406
	*/
11407
	public static function split(&$conf=array()){
226 liveuser 11408
 
3 liveuser 11409
		#初始化要回傳的結果
11410
		$result=array();
11411
 
11412
		#取得當前執行的函數名稱
11413
		$result["function"]=__FUNCTION__;
11414
 
11415
		#如果沒有參數
11416
		if(func_num_args()==0){
226 liveuser 11417
 
3 liveuser 11418
			#設置執行失敗
11419
			$result["status"]="false";
226 liveuser 11420
 
3 liveuser 11421
			#設置執行錯誤訊息
11422
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 11423
 
3 liveuser 11424
			#回傳結果
11425
			return $result;
226 liveuser 11426
 
3 liveuser 11427
			}#if end
11428
 
11429
		#函式說明:
11430
		#判斷當前環境為web還是cmd
11431
		#回傳結果:
11432
		#$result,"web"或"cmd"
11433
		if(csInformation::getEnv()==="web"){
226 liveuser 11434
 
3 liveuser 11435
			#設置執行失敗
11436
			$result["status"]="false";
226 liveuser 11437
 
3 liveuser 11438
			#設置執行錯誤訊息
11439
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
226 liveuser 11440
 
3 liveuser 11441
			#回傳結果
11442
			return $result;
226 liveuser 11443
 
3 liveuser 11444
			}#if end
226 liveuser 11445
 
3 liveuser 11446
		#取得參數
11447
		$result["argu"]=$conf;
11448
 
11449
		#如果 $conf 不為陣列
11450
		if(gettype($conf)!=="array"){
226 liveuser 11451
 
3 liveuser 11452
			#設置執行失敗
11453
			$result["status"]="false";
226 liveuser 11454
 
3 liveuser 11455
			#設置執行錯誤訊息
11456
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 11457
 
3 liveuser 11458
			#如果傳入的參數為 null
11459
			if($conf===null){
226 liveuser 11460
 
3 liveuser 11461
				#設置執行錯誤訊息
11462
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 11463
 
3 liveuser 11464
				}#if end
11465
 
11466
			#回傳結果
11467
			return $result;
226 liveuser 11468
 
3 liveuser 11469
			}#if end
226 liveuser 11470
 
3 liveuser 11471
		#檢查參數
11472
		#函式說明:
11473
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
11474
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11475
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11476
		#$result["function"],當前執行的函式名稱.
11477
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11478
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11479
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11480
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11481
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11482
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11483
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11484
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11485
		#必填寫的參數:
11486
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11487
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11488
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11489
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file");
11490
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11491
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
11492
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11493
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11494
		#可以省略的參數:
11495
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11496
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11497
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11498
		#$conf["canNotBeEmpty"]=array();
11499
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11500
		#$conf["canBeEmpty"]=array();
11501
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11502
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11503
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11504
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("splitNameHead","partSize");
226 liveuser 11505
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 11506
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
11507
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]",若後面需要加上內容,則可以再補上\",後面再補上要串接的內容.
11508
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"file\"]\"-","50MB");
11509
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11510
		#$conf["arrayCountEqualCheck"][]=array();
11511
		#參考資料來源:
11512
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11513
		#建議:
11514
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
11515
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11516
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 11517
 
3 liveuser 11518
		#如果檢查參數失敗
11519
		if($checkArguments["status"]==="false"){
226 liveuser 11520
 
3 liveuser 11521
			#設置執行失敗
11522
			$result["status"]="false";
226 liveuser 11523
 
3 liveuser 11524
			#設置錯誤訊息
11525
			$result["error"]=$checkArguments;
226 liveuser 11526
 
3 liveuser 11527
			#回傳結果
11528
			return $result;
226 liveuser 11529
 
3 liveuser 11530
			}#if end
226 liveuser 11531
 
3 liveuser 11532
		#如果要分割的檔案存在
11533
		if(file_exists($conf["file"])){
226 liveuser 11534
 
3 liveuser 11535
			#取得執行的指令
11536
			$result["cmd"]="split -b ".$conf["partSize"]." '".$conf["file"]."' '".$conf["splitNameHead"]."'";
11537
 
11538
			#執行還原的指令
11539
			exec($result["cmd"],$output,$status);
11540
 
11541
			#取得執行後的輸出
11542
			$result["content"]=$output;
226 liveuser 11543
 
3 liveuser 11544
			}#if end
226 liveuser 11545
 
3 liveuser 11546
		#反之
11547
		else{
226 liveuser 11548
 
3 liveuser 11549
			#設置執行失敗
11550
			$result["status"]="false";
226 liveuser 11551
 
3 liveuser 11552
			#設置執行錯誤訊息
11553
			$result["error"][]="要分割的檔案「".$conf["file"]."」不存在";
226 liveuser 11554
 
3 liveuser 11555
			#回傳結果
11556
			return $result;
226 liveuser 11557
 
3 liveuser 11558
			}#else end
226 liveuser 11559
 
3 liveuser 11560
		#設置執行正常
11561
		$result["status"]="true";
226 liveuser 11562
 
3 liveuser 11563
		#回傳結果
11564
		return $result;
226 liveuser 11565
 
3 liveuser 11566
		}#function split end
11567
 
11568
	/*
11569
	#函式說明:
11570
	#合併檔案,檔案編號為aa, ab ac...ba, bb, bc...,zx, zy, zz的順序.
11571
	#回傳結果:
11572
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11573
	#$result["error"],錯誤訊息陣列.
11574
	#$result["function"],當前執行的函數名稱.
11575
	#$result["cmd"],執行的指令.
11576
	#$result["content"],執行指令回傳的結果.
11577
	#必填參數:
11578
	#$conf["filePartHead"],字串,分割檔案的名稱開頭.
11579
	$conf["filePartHead"]="";
11580
	#$conf["oriFileName"],字串,合併後的檔案名稱.
11581
	$conf["oriFileName"]="";
11582
	#可省略參數:
11583
	#無
11584
	#參考資料:
11585
	#無.
11586
	#備註:
11587
	#需要有cat指令.
11588
	#僅能在命令列執行.
11589
	*/
11590
	public static function merge(&$conf=array()){
226 liveuser 11591
 
3 liveuser 11592
		#初始化要回傳的結果
11593
		$result=array();
11594
 
11595
		#取得當前執行的函數名稱
11596
		$result["function"]=__FUNCTION__;
11597
 
11598
		#如果沒有參數
11599
		if(func_num_args()==0){
226 liveuser 11600
 
3 liveuser 11601
			#設置執行失敗
11602
			$result["status"]="false";
226 liveuser 11603
 
3 liveuser 11604
			#設置執行錯誤訊息
11605
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 11606
 
3 liveuser 11607
			#回傳結果
11608
			return $result;
226 liveuser 11609
 
3 liveuser 11610
			}#if end
11611
 
11612
		#函式說明:
11613
		#判斷當前環境為web還是cmd
11614
		#回傳結果:
11615
		#$result,"web"或"cmd"
11616
		if(csInformation::getEnv()==="web"){
226 liveuser 11617
 
3 liveuser 11618
			#設置執行失敗
11619
			$result["status"]="false";
226 liveuser 11620
 
3 liveuser 11621
			#設置執行錯誤訊息
11622
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
226 liveuser 11623
 
3 liveuser 11624
			#回傳結果
11625
			return $result;
226 liveuser 11626
 
3 liveuser 11627
			}#if end
226 liveuser 11628
 
3 liveuser 11629
		#取得參數
11630
		$result["argu"]=$conf;
11631
 
11632
		#如果 $conf 不為陣列
11633
		if(gettype($conf)!=="array"){
226 liveuser 11634
 
3 liveuser 11635
			#設置執行失敗
11636
			$result["status"]="false";
226 liveuser 11637
 
3 liveuser 11638
			#設置執行錯誤訊息
11639
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 11640
 
3 liveuser 11641
			#如果傳入的參數為 null
11642
			if($conf===null){
226 liveuser 11643
 
3 liveuser 11644
				#設置執行錯誤訊息
11645
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 11646
 
3 liveuser 11647
				}#if end
11648
 
11649
			#回傳結果
11650
			return $result;
226 liveuser 11651
 
3 liveuser 11652
			}#if end
226 liveuser 11653
 
3 liveuser 11654
		#檢查參數
11655
		#函式說明:
11656
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
11657
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11658
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11659
		#$result["function"],當前執行的函式名稱.
11660
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11661
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11662
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11663
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11664
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11665
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11666
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11667
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11668
		#必填寫的參數:
11669
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11670
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11671
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11672
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePartHead","oriFileName");
11673
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11674
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
11675
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11676
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11677
		#可以省略的參數:
11678
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11679
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11680
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11681
		#$conf["canNotBeEmpty"]=array();
11682
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11683
		#$conf["canBeEmpty"]=array();
11684
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11685
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11686
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11687
		#$conf["skipableVariableName"]=array();
226 liveuser 11688
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 11689
		#$conf["skipableVariableType"]=array();
11690
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11691
		#$conf["skipableVarDefaultValue"]=array("");
11692
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11693
		#$conf["arrayCountEqualCheck"][]=array();
11694
		#參考資料來源:
11695
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11696
		#建議:
11697
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
11698
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11699
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 11700
 
3 liveuser 11701
		#如果檢查參數失敗
11702
		if($checkArguments["status"]==="false"){
226 liveuser 11703
 
3 liveuser 11704
			#設置執行失敗
11705
			$result["status"]="false";
226 liveuser 11706
 
3 liveuser 11707
			#設置錯誤訊息
11708
			$result["error"]=$checkArguments;
226 liveuser 11709
 
3 liveuser 11710
			#回傳結果
11711
			return $result;
226 liveuser 11712
 
3 liveuser 11713
			}#if end
226 liveuser 11714
 
3 liveuser 11715
		#定義編號
11716
		$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");
11717
 
11718
		#定義分割檔案的前置字串
11719
		$filePartHead=$conf["filePartHead"];
11720
 
11721
		#要合併成的檔案名稱
11722
		$oriFileName=$conf["oriFileName"];
11723
 
11724
		#初始化要執行合併的語法
11725
		$restoreCmd="cat ";
11726
 
11727
		#有幾個編號就執行幾次
11728
		for($i=0;$i<count($charArray);$i++){
11729
 
11730
			#有幾個編號就執行幾次
11731
			for($j=0;$j<count($charArray);$j++){
11732
 
11733
				#如果該分割檔存在
11734
				if(file_exists($filePartHead.$charArray[$i].$charArray[$j])){
11735
 
11736
					#串接要還原的分割檔
11737
					$restoreCmd=$restoreCmd." '".$filePartHead.$charArray[$i].$charArray[$j]."'";
11738
 
11739
					}#if end
11740
 
11741
				#反之
11742
				else{
11743
 
11744
					#如果是第一個分割檔就找不到
11745
					if($i===0 && $j===0){
226 liveuser 11746
 
3 liveuser 11747
						#設置執行失敗
11748
						$result["status"]="false";
226 liveuser 11749
 
3 liveuser 11750
						#設置錯誤訊息
11751
						$result["error"][]="找不到第一個分割檔「".$filePartHead.$charArray[$i].$charArray[$j]."」";
226 liveuser 11752
 
3 liveuser 11753
						#回傳結果
11754
						return $result;
226 liveuser 11755
 
3 liveuser 11756
						}#if end
11757
 
11758
					#串接要還原成的檔案名稱
11759
					$restoreCmd=$restoreCmd." > '".$oriFileName."'";
11760
 
11761
					#取得執行的指令
11762
					$result["cmd"]=$restoreCmd;
11763
 
11764
					#執行還原的指令
11765
					exec($restoreCmd,$output,$status);
11766
 
11767
					#取得執行後的輸出
11768
					$result["content"]=$output;
11769
 
11770
					#結束回圈
11771
					break 2;
226 liveuser 11772
 
3 liveuser 11773
					}#else end
11774
 
11775
				}#for end
11776
 
11777
			}#for end
226 liveuser 11778
 
3 liveuser 11779
		#設置執行正常
11780
		$result["status"]="true";
226 liveuser 11781
 
3 liveuser 11782
		#回傳結果
11783
		return $result;
226 liveuser 11784
 
3 liveuser 11785
		}#function merge end
11786
 
11787
	/*
11788
	#函式說明:
11789
	#取得檔案的部分內容
11790
	#回傳結果:
11791
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11792
	#$result["error"],錯誤訊息陣列.
11793
	#$result["function"],當前執行的函數名稱.
11794
	#$result["cmd"],執行的指令.
11795
	#$result["content"],取得的檔案內容.
11796
	#$result["length"],取得的內容長度.
11797
	#$result["EOF"],識別是否已經到檔案結尾,"true"代表是,"false"代表不是.
11798
	#$result["mimeType"],檔案的 mime type.
11799
	#必填參數:
11800
	#$conf["file"],字串,檔案的路徑與名稱.
11801
	$conf["file"]="";
11802
	#$conf["fileArgu"],字串,__FILE__的內容.
11803
	$conf["fileArgu"]=__FILE__;
11804
	#$conf["bytes"],整數字串,要讀取多少bytes.
11805
	$conf["bytes"]="";
11806
	#$conf["startIndex"],要從哪個bytes位置開始,起始點為0.
11807
	$conf["startIndex"]="";
11808
	#可省略參數:
11809
	#無
11810
	#參考資料:
11811
	#無.
11812
	#備註:
11813
	#無
11814
	*/
11815
	public static function getFilePart(&$conf){
226 liveuser 11816
 
3 liveuser 11817
		#初始化要回傳的結果
11818
		$result=array();
11819
 
11820
		#取得當前執行的函數名稱
11821
		$result["function"]=__FUNCTION__;
11822
 
11823
		#如果沒有參數
11824
		if(func_num_args()==0){
11825
 
11826
			#設置執行失敗
11827
			$result["status"]="false";
11828
 
11829
			#設置執行錯誤訊息
11830
			$result["error"]="函數".$result["function"]."需要參數";
11831
 
11832
			#回傳結果
11833
			return $result;
11834
 
11835
			}#if end
226 liveuser 11836
 
3 liveuser 11837
		#取得參數
11838
		$result["argu"]=$conf;
11839
 
11840
		#如果 $conf 不為陣列
11841
		if(gettype($conf)!=="array"){
11842
 
11843
			#設置執行失敗
11844
			$result["status"]="false";
11845
 
11846
			#設置執行錯誤訊息
11847
			$result["error"][]="\$conf變數須為陣列形態";
11848
 
11849
			#如果傳入的參數為 null
11850
			if(is_null($conf)){
11851
 
11852
				#設置執行錯誤訊息
11853
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
11854
 
11855
				}#if end
11856
 
11857
			#回傳結果
11858
			return $result;
11859
 
11860
			}#if end
226 liveuser 11861
 
3 liveuser 11862
		#函式說明:
11863
		#檢查多個檔案與資料夾是否存在.
11864
		#回傳的結果:
11865
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
11866
		#$result["error"],錯誤訊息陣列.
11867
		#$resutl["function"],當前執行的涵式名稱.
11868
		#$result["argu"],使用的參數.
11869
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
11870
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
11871
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
11872
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
11873
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
11874
		#必填參數:
11875
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
11876
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
11877
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11878
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
11879
		#可省略參數:
11880
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
11881
		#$conf["disableWebSearch"]="false";
11882
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
11883
		#$conf["userDir"]="true";
11884
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
11885
		#$conf["web"]="true";
11886
		#參考資料:
11887
		#http://php.net/manual/en/function.file-exists.php
11888
		#http://php.net/manual/en/control-structures.foreach.php
11889
		#備註:
11890
		#函數file_exists檢查的路徑為檔案系統的路徑
11891
		#$result["varName"][$i]結果未實作
11892
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
11893
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 11894
 
3 liveuser 11895
		#如果執行失敗
11896
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 11897
 
3 liveuser 11898
			#設置執行失敗
11899
			$result["status"]="false";
226 liveuser 11900
 
3 liveuser 11901
			#設置執行錯誤訊息
11902
			$result["error"]=$checkMultiFileExist;
226 liveuser 11903
 
3 liveuser 11904
			#回傳結果
11905
			return $result;
226 liveuser 11906
 
3 liveuser 11907
			}#if end
226 liveuser 11908
 
3 liveuser 11909
		#如果檔案不存在
11910
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 11911
 
3 liveuser 11912
			#設置執行失敗
11913
			$result["status"]="false";
226 liveuser 11914
 
3 liveuser 11915
			#設置執行錯誤訊息
11916
			$result["error"]=$checkMultiFileExist;
226 liveuser 11917
 
3 liveuser 11918
			#回傳結果
11919
			return $result;
226 liveuser 11920
 
3 liveuser 11921
			}#if end
226 liveuser 11922
 
3 liveuser 11923
		#取得mimetype
11924
		$mimetype=mime_content_type($conf["file"]);
226 liveuser 11925
 
3 liveuser 11926
		#取得檔案的 mime type
11927
		$result["mimeType"]=$mimetype;
226 liveuser 11928
 
3 liveuser 11929
		#透過 dd 指令,取得部分內容.
11930
		#函式說明:
11931
		#呼叫shell執行系統命令,並取得回傳的內容.
11932
		#回傳結果:
11933
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11934
		#$result["error"],錯誤訊息陣列.
11935
		#$result["function"],當前執行的函數名稱.
11936
		#$result["argu"],使用的參數.
11937
		#$result["cmd"],執行的指令內容.
11938
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11939
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11940
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11941
		#$result["running"],是否還在執行.
11942
		#$result["pid"],pid.
11943
		#$result["statusCode"],執行結束後的代碼.
11944
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11945
		#必填參數:
11946
		#$conf["command"],字串,要執行的指令.
11947
		$conf["external::callShell"]["command"]="dd";
11948
		#$conf["fileArgu"],字串,變數__FILE__的內容.
11949
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
11950
		#可省略參數:
11951
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11952
		$conf["external::callShell"]["argu"]=array("if=".$conf["file"],"bs=".$conf["bytes"],"count=1","status=none");
11953
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11954
		#$conf["arguIsAddr"]=array();
11955
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11956
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11957
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11958
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11959
		#$conf["enablePrintDescription"]="true";
11960
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11961
		#$conf["printDescription"]="";
11962
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11963
		#$conf["escapeshellarg"]="false";
11964
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11965
		#$conf["thereIsShellVar"]=array();
11966
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11967
		#$conf["username"]="";
11968
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11969
		#$conf["password"]="";
11970
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11971
		#$conf["useScript"]="";
11972
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11973
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11974
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11975
		#$conf["inBackGround"]="";
11976
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11977
		#$conf["getErr"]="false";
11978
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11979
		#$conf["doNotRun"]="false";
11980
		#參考資料:
11981
		#exec=>http://php.net/manual/en/function.exec.php
11982
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11983
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11984
		#備註:
11985
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11986
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11987
		$callShell=external::callShell($conf["external::callShell"]);
11988
		unset($conf["external::callShell"]);
226 liveuser 11989
 
3 liveuser 11990
		#如果執行失敗
11991
		if($callShell["status"]==="false"){
226 liveuser 11992
 
3 liveuser 11993
			#設置執行失敗
11994
			$result["status"]="false";
226 liveuser 11995
 
3 liveuser 11996
			#設置執行錯誤訊息
11997
			$result["error"]=$callShell;
226 liveuser 11998
 
3 liveuser 11999
			#回傳結果
12000
			return $result;
226 liveuser 12001
 
3 liveuser 12002
			}#if end
226 liveuser 12003
 
3 liveuser 12004
		#取得結果
12005
		$result["content"]=$callShell["output"][0];
226 liveuser 12006
 
3 liveuser 12007
		#取得內容長度
12008
		$result["length"]=strlen($result["content"]);
226 liveuser 12009
 
12010
		#預設尚未到檔案結尾
3 liveuser 12011
		$result["EOF"]="false";
226 liveuser 12012
 
3 liveuser 12013
		#如果取得的內容長度小於預期
12014
		if($result["length"]<$conf["bytes"]){
226 liveuser 12015
 
3 liveuser 12016
			#設置已經到檔案結尾了
12017
			$result["EOF"]="true";
226 liveuser 12018
 
3 liveuser 12019
			}#if end
226 liveuser 12020
 
3 liveuser 12021
		#設置執行正常
12022
		$result["status"]="true";
226 liveuser 12023
 
3 liveuser 12024
		#回傳結果
12025
		return $result;
226 liveuser 12026
 
3 liveuser 12027
		}#function getFilePart end
12028
 
12029
	/*
12030
	#函式說明:
12031
	#取得節點的資訊.
12032
	#回傳結果:
12033
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12034
	#$result["error"],錯誤訊息陣列.
226 liveuser 12035
	#$result["function"],函數名稱.
3 liveuser 12036
	#$result["content"],檔案資訊陣列.
226 liveuser 12037
	#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 12038
	#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
12039
	#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
12040
	#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
12041
	#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
12042
	#$result["content"]["ownerName"],檔案擁有着資訊.
12043
	#$result["content"]["groupName"],檔案所屬擁有着資訊.
12044
	#$result["content"]["size"],檔案大小.
12045
	#$result["content"]["modifyDate"],檔案變更年月日.
12046
	#$result["content"]["modifyTime"],檔案變更時分秒.
12047
	#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
12048
	#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
12049
	#必填參數:
12050
	#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
12051
	$conf["fileArgu"]=__FILE__;
12052
	#$conf["file"],字串,要查看擁有者資訊的檔案.
12053
	$conf["file"]="";
12054
	#可省略參數:
12055
	#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
12056
	#$conf["web"]="true";
12057
	#參考資料:
12058
	#fileowner=>http://php.net/manual/en/function.fileowner.php
12059
	#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
12060
	#備註:
12061
	#無.
12062
	*/
12063
	public static function fileInfo(&$conf=array()){
226 liveuser 12064
 
3 liveuser 12065
		#初始化要回傳的結果
12066
		$result=array();
12067
 
12068
		#取得當前執行的函數名稱
12069
		$result["function"]=__FUNCTION__;
12070
 
12071
		#如果沒有參數
12072
		if(func_num_args()==0){
226 liveuser 12073
 
3 liveuser 12074
			#設置執行失敗
12075
			$result["status"]="false";
226 liveuser 12076
 
3 liveuser 12077
			#設置執行錯誤訊息
12078
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 12079
 
3 liveuser 12080
			#回傳結果
12081
			return $result;
226 liveuser 12082
 
3 liveuser 12083
			}#if end
12084
 
12085
		#取得參數
12086
		$result["argu"]=$conf;
12087
 
12088
		#如果 $conf 不為陣列
12089
		if(gettype($conf)!=="array"){
226 liveuser 12090
 
3 liveuser 12091
			#設置執行失敗
12092
			$result["status"]="false";
226 liveuser 12093
 
3 liveuser 12094
			#設置執行錯誤訊息
12095
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 12096
 
3 liveuser 12097
			#如果傳入的參數為 null
12098
			if($conf===null){
226 liveuser 12099
 
3 liveuser 12100
				#設置執行錯誤訊息
12101
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12102
 
3 liveuser 12103
				}#if end
12104
 
12105
			#回傳結果
12106
			return $result;
226 liveuser 12107
 
3 liveuser 12108
			}#if end
226 liveuser 12109
 
3 liveuser 12110
		#檢查參數
12111
		#函式說明:
12112
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12113
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12114
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12115
		#$result["function"],當前執行的函式名稱.
12116
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12117
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12118
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12119
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12120
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12121
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12122
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12123
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12124
		#必填寫的參數:
12125
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 12126
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 12127
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12128
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12129
		#可以省略的參數:
12130
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12131
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
12132
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12133
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
12134
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12135
		#$conf["canBeEmptyString"]="false";
12136
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12137
		#$conf["ileAccess::checkArguments"]["canNotBeEmpty"]=array();
12138
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12139
		#$conf["canBeEmpty"]=array();
12140
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12141
		#$conf["skipableVariableCanNotBeEmpty"]=array();
12142
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12143
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 12144
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12145
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
12146
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12147
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
12148
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12149
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12150
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12151
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12152
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12153
		#$conf["arrayCountEqualCheck"][]=array();
12154
		#參考資料來源:
12155
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12156
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12157
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 12158
 
3 liveuser 12159
		#如果檢查參數失敗
12160
		if($checkArguments["status"]==="false"){
226 liveuser 12161
 
3 liveuser 12162
			#設置執行失敗
12163
			$result["status"]="false";
226 liveuser 12164
 
3 liveuser 12165
			#設置執行錯誤訊息
12166
			$result["error"]=$checkArguments;
226 liveuser 12167
 
3 liveuser 12168
			#回傳結果
12169
			return $result;
226 liveuser 12170
 
3 liveuser 12171
			}#if end
226 liveuser 12172
 
3 liveuser 12173
		#如果檢查參數不通過
12174
		if($checkArguments["passed"]==="false"){
226 liveuser 12175
 
3 liveuser 12176
			#設置執行失敗
12177
			$result["status"]="false";
226 liveuser 12178
 
3 liveuser 12179
			#設置執行錯誤訊息
12180
			$result["error"]=$checkArguments;
226 liveuser 12181
 
3 liveuser 12182
			#回傳結果
12183
			return $result;
226 liveuser 12184
 
3 liveuser 12185
			}#if end
226 liveuser 12186
 
3 liveuser 12187
		#函式說明:
12188
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
12189
		#回傳結果:
12190
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12191
		#$result["error"],錯誤訊息陣列.
226 liveuser 12192
		#$result["function"],函數名稱.
3 liveuser 12193
		#$result["argu"],使用的參數.
12194
		#$result["content"],網址,若是在命令列執行,則為"null".
12195
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
12196
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
12197
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
12198
		#必填參數:
12199
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
12200
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["file"];
12201
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
12202
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
12203
		#可省略參數:
12204
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
12205
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
12206
		#備註:
12207
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
12208
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
12209
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 12210
 
3 liveuser 12211
		#如果取得位置失敗
12212
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 12213
 
3 liveuser 12214
			#設置執行失敗
12215
			$result["status"]="false";
226 liveuser 12216
 
3 liveuser 12217
			#設置執行錯誤訊息
12218
			$result["error"]=$getInternetAddressV2;
226 liveuser 12219
 
3 liveuser 12220
			#回傳結果
12221
			return $result;
226 liveuser 12222
 
3 liveuser 12223
			}#if end
12224
 
12225
		#函式說明:
12226
		#檢查多個檔案與資料夾是否存在.
12227
		#回傳的結果:
12228
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
12229
		#$result["error"],錯誤訊息陣列.
12230
		#$resutl["function"],當前執行的涵式名稱.
12231
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
12232
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
12233
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
12234
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
12235
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
12236
		#必填參數:
12237
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
12238
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($getInternetAddressV2["fileSystemAbsoulutePosition"]);
12239
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12240
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
12241
		#可省略參數
12242
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
12243
		#$conf["disableWebSearch"]="false";
12244
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
12245
		#$conf["userDir"]="true";
12246
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
12247
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
12248
		#參考資料來源:
12249
		#http://php.net/manual/en/function.file-exists.php
12250
		#http://php.net/manual/en/control-structures.foreach.php
12251
		#備註:
12252
		#函數file_exists檢查的路徑為檔案系統的路徑
12253
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
12254
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 12255
 
3 liveuser 12256
		#如果檢查檔案存在失敗
12257
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 12258
 
3 liveuser 12259
			#設置執行失敗
12260
			$result["status"]="false";
226 liveuser 12261
 
3 liveuser 12262
			#設置執行錯誤訊息
12263
			$result["error"]=$checkMultiFileExist;
226 liveuser 12264
 
3 liveuser 12265
			#回傳結果
12266
			return $result;
226 liveuser 12267
 
3 liveuser 12268
			}#if end
226 liveuser 12269
 
3 liveuser 12270
		#如果檔案不存在
12271
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 12272
 
3 liveuser 12273
			#設置執行失敗
12274
			$result["status"]="false";
226 liveuser 12275
 
3 liveuser 12276
			#設置執行錯誤訊息
12277
			$result["error"]=$checkMultiFileExist;
226 liveuser 12278
 
3 liveuser 12279
			#回傳結果
12280
			return $result;
226 liveuser 12281
 
3 liveuser 12282
			}#if end
226 liveuser 12283
 
3 liveuser 12284
		#透過ls指令取得檔案的資訊
12285
		#函式說明:
12286
		#呼叫shell執行系統命令,並取得回傳的內容.
12287
		#回傳的結果:
12288
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12289
		#$result["error"],錯誤訊息陣列.
12290
		#$result["function"],當前執行的函數名稱.
12291
		#$result["cmd"],執行的指令內容.
12292
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12293
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12294
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12295
		#$result["running"],是否還在執行.
12296
		#$result["pid"],pid
12297
		#必填的參數
12298
		#$conf["command"],字串,要執行的指令
12299
		$conf["external::callShell"]["command"]="ls";
12300
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12301
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
12302
		#可省略參數:
12303
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12304
		$conf["external::callShell"]["argu"]=array("-l","--full-time","-d",$conf["file"]);
12305
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12306
		$conf["external::callShell"]["arguIsAddr"]=array("false","false","false","false");
12307
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12308
		#$conf["enablePrintDescription"]="true";
12309
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
12310
		#$conf["printDescription"]="";
12311
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
12312
		$conf["external::callShell"]["escapeshellarg"]="true";
12313
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12314
		#$conf["username"]="";
12315
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12316
		#$conf["password"]="";
12317
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12318
		#$conf["useScript"]="";
12319
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12320
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12321
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12322
		#$conf["inBackGround"]="";
12323
		#備註:
12324
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12325
		#參考資料:
12326
		#exec=>http://php.net/manual/en/function.exec.php
12327
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12328
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12329
		$callShell=external::callShell($conf["external::callShell"]);
12330
		unset($conf["external::callShell"]);
226 liveuser 12331
 
3 liveuser 12332
		#如果執行失敗
12333
		if($callShell["status"]==="false"){
226 liveuser 12334
 
3 liveuser 12335
			#設置執行失敗
12336
			$result["status"]="false";
226 liveuser 12337
 
3 liveuser 12338
			#設置執行錯誤訊息
12339
			$result["error"]=$callShell;
226 liveuser 12340
 
3 liveuser 12341
			#回傳結果
12342
			return $result;
226 liveuser 12343
 
12344
			}#if end
12345
 
3 liveuser 12346
		#解析檔案資訊
12347
		#-rwxrwx--x. 1 apache apache 65K 2017-04-16 22:53:19.044545806 +0800 fileAccessT.php
226 liveuser 12348
 
3 liveuser 12349
		#取得權限資訊 -rwxrwx--x
12350
		$perm=substr($callShell["output"][0],0,strpos($callShell["output"][0],'.'));
226 liveuser 12351
 
3 liveuser 12352
		#如果是目錄
12353
		if(substr($perm,0,1)==="d"){
226 liveuser 12354
 
3 liveuser 12355
			#設定為目錄
12356
			$result["content"]["is_folder"]="true";
226 liveuser 12357
 
3 liveuser 12358
			}#if end
226 liveuser 12359
 
3 liveuser 12360
		#反之
12361
		else{
226 liveuser 12362
 
3 liveuser 12363
			#設定不為目錄
12364
			$result["content"]["is_folder"]="false";
226 liveuser 12365
 
3 liveuser 12366
			}#else end
226 liveuser 12367
 
3 liveuser 12368
		#解析檔案擁有者權限資訊
12369
		$result["content"]["ownerPerm"]=substr($perm,1,3);
226 liveuser 12370
 
3 liveuser 12371
		#如果檔案擁有者名稱為空
12372
		if(empty($result["content"]["ownerPerm"])){
226 liveuser 12373
 
3 liveuser 12374
			#設置執行失敗
12375
			$result["status"]="false";
226 liveuser 12376
 
3 liveuser 12377
			#設置執行錯誤訊息
12378
			$result["error"]=$callShell;
226 liveuser 12379
 
3 liveuser 12380
			#回傳結果
12381
			return $result;
226 liveuser 12382
 
3 liveuser 12383
			}#if end
226 liveuser 12384
 
3 liveuser 12385
		#解析檔案歸屬群組權限資訊
12386
		$result["content"]["groupPerm"]=substr($perm,4,3);
226 liveuser 12387
 
3 liveuser 12388
		#解析檔案對於其他身份使用者的權限資訊
12389
		$result["content"]["otherPerm"]=substr($perm,7,3);
226 liveuser 12390
 
3 liveuser 12391
		#取得目錄底下的檔案目錄數量起始點
12392
		$subElementStartPos=strpos($callShell["output"][0],' ');
226 liveuser 12393
 
3 liveuser 12394
		#取得目錄底下的檔案目錄數量結束點
12395
		$subElementEndPos=strpos($callShell["output"][0],' ',$subElementStartPos+1);
226 liveuser 12396
 
3 liveuser 12397
		#取得目錄底下的檔案目錄數量
12398
		$result["content"]["subElementCount"]=substr($callShell["output"][0],$subElementStartPos,$subElementEndPos-$subElementStartPos);
226 liveuser 12399
 
3 liveuser 12400
		#取得檔案擁有着資訊的起點
12401
		$ownerNameStrPos=strpos($callShell["output"][0],' ',$subElementEndPos)+1;
226 liveuser 12402
 
3 liveuser 12403
		#取得檔案擁有着資訊的結束點
12404
		$ownerNameEndPos=strpos($callShell["output"][0],' ',$ownerNameStrPos+1);
226 liveuser 12405
 
3 liveuser 12406
		#取得檔案擁有着資訊
12407
		$result["content"]["ownerName"]=substr($callShell["output"][0],$ownerNameStrPos,$ownerNameEndPos-$ownerNameStrPos);
226 liveuser 12408
 
3 liveuser 12409
		#取取得檔案群組擁有者資訊的起點
12410
		$groupNameStrPos=strpos($callShell["output"][0],' ',$ownerNameEndPos)+1;
226 liveuser 12411
 
3 liveuser 12412
		#取得檔案群組擁有者資訊的結束點
12413
		$groupNameEndPos=strpos($callShell["output"][0],' ',$groupNameStrPos);
226 liveuser 12414
 
3 liveuser 12415
		#取得檔案群組擁有者資訊
12416
		$result["content"]["groupName"]=substr($callShell["output"][0],$groupNameStrPos,$groupNameEndPos-$groupNameStrPos);
226 liveuser 12417
 
3 liveuser 12418
		#取得檔案大小的起點
12419
		$sizeStrPos=strpos($callShell["output"][0],' ',$groupNameEndPos)+1;
226 liveuser 12420
 
3 liveuser 12421
		#取得檔案大小的結束點
12422
		$sizeEndPos=strpos($callShell["output"][0],' ',$sizeStrPos);
226 liveuser 12423
 
3 liveuser 12424
		#取得檔案大小
12425
		$result["content"]["size"]=substr($callShell["output"][0],$sizeStrPos,$sizeEndPos-$sizeStrPos);
226 liveuser 12426
 
3 liveuser 12427
		#取得檔案變更年月日的起點
12428
		$modifyDateStrPos=strpos($callShell["output"][0],' ',$sizeEndPos)+1;
226 liveuser 12429
 
3 liveuser 12430
		#取得檔案變更年月日的結束點
12431
		$modifyDateEndPos=strpos($callShell["output"][0],' ',$modifyDateStrPos);
226 liveuser 12432
 
12433
		#取得檔案變更年月日
3 liveuser 12434
		$result["content"]["modifyDate"]=substr($callShell["output"][0],$modifyDateStrPos,$modifyDateEndPos-$modifyDateStrPos);
226 liveuser 12435
 
3 liveuser 12436
		#取得檔案變更時分秒的起點
12437
		$modifyTimeStrPos=strpos($callShell["output"][0],' ',$modifyDateEndPos)+1;
226 liveuser 12438
 
3 liveuser 12439
		#取得檔案變更時分秒的結束點
12440
		$modifyTimeEndPos=strpos($callShell["output"][0],'.',$modifyTimeStrPos);
226 liveuser 12441
 
3 liveuser 12442
		#取得檔案變更時分秒
12443
		$result["content"]["modifyTime"]=substr($callShell["output"][0],$modifyTimeStrPos,$modifyTimeEndPos-$modifyTimeStrPos);
226 liveuser 12444
 
3 liveuser 12445
		#取得檔版變更時間秒的float數值起點
12446
		$modifyTimeFloatStrPos=strpos($callShell["output"][0],'.',$modifyTimeEndPos)+1;
226 liveuser 12447
 
3 liveuser 12448
		#取得檔版變更時間秒的float數值結束點
12449
		$modifyTimeFloatEndPos=strpos($callShell["output"][0],' ',$modifyTimeFloatStrPos);
226 liveuser 12450
 
12451
		#取得檔版變更時間秒的float數值
3 liveuser 12452
		$result["content"]["modifyTimeFloat"]=substr($callShell["output"][0],$modifyTimeFloatStrPos,$modifyTimeFloatEndPos-$modifyTimeFloatStrPos);
226 liveuser 12453
 
3 liveuser 12454
		#取得時區起始點
12455
		$timezoneStrPos=strpos($callShell["output"][0],' ',$modifyTimeFloatEndPos)+1;
226 liveuser 12456
 
3 liveuser 12457
		#取得時區結束點
226 liveuser 12458
		$timezoneEndPos=strpos($callShell["output"][0],' ',$timezoneStrPos)+1;
12459
 
3 liveuser 12460
		#取得檔案變更時間的時區與UTC的差距.
226 liveuser 12461
		$result["content"]["timezone"]=substr($callShell["output"][0],$timezoneStrPos,$timezoneEndPos-$timezoneStrPos);
12462
 
3 liveuser 12463
		#設置執行正常
12464
		$result["status"]="true";
226 liveuser 12465
 
3 liveuser 12466
		#回傳結果
12467
		return $result;
226 liveuser 12468
 
3 liveuser 12469
		}#function fileInfo end
12470
 
12471
	/*
12472
	#函式說明:
226 liveuser 12473
	#依據函數getListTree執行的結果,將其底下與其子目錄底下的特定檔案內容依據目錄層級輸出成html檔案
3 liveuser 12474
	#回傳結果:
12475
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12476
	#$result["error"],錯誤訊息陣列.
226 liveuser 12477
	#$result["function"],函數名稱.
3 liveuser 12478
	#$result["content"],html檔案輸出的位置與名稱.
12479
	#必填參數:
12480
	#$conf["getListTree"],陣列變數,函數getListTree執行的結果.
12481
	$conf["getListTree"]=$getListTree;
12482
	#可省略參數:
12483
	#$conf["fileToRead"],字串,要讀取的檔案名稱為何?預設為"help".
12484
	#$conf["fileToRead"]="help";
12485
	#$conf["output"],字串,輸出的網頁檔案位置與名稱,副檔名html會自動補上,預設為"help".
226 liveuser 12486
	#$conf["output"]="help.html";
3 liveuser 12487
	#參考資料:
12488
	#無.
12489
	#備註:
12490
	#建構中...
12491
	*/
12492
	public static function createHelpFile($conf){
226 liveuser 12493
 
3 liveuser 12494
		#初始化要回傳的結果
12495
		$result=array();
226 liveuser 12496
 
3 liveuser 12497
		#設置當其函數名稱
12498
		$result["function"]=__FUNCTION__;
226 liveuser 12499
 
3 liveuser 12500
		#如果 $conf 不為陣列
12501
		if(gettype($conf)!="array"){
226 liveuser 12502
 
3 liveuser 12503
			#設置執行失敗
12504
			$result["status"]="false";
226 liveuser 12505
 
3 liveuser 12506
			#設置執行錯誤訊息
12507
			$result["error"][]="\$conf變數須為陣列形態";
12508
 
12509
			#如果傳入的參數為 null
12510
			if($conf==null){
226 liveuser 12511
 
3 liveuser 12512
				#設置執行錯誤訊息
12513
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12514
 
3 liveuser 12515
				}#if end
12516
 
12517
			#回傳結果
12518
			return $result;
226 liveuser 12519
 
3 liveuser 12520
			}#if end
226 liveuser 12521
 
3 liveuser 12522
		#檢查參數
12523
		#函式說明:
12524
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12525
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12526
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12527
		#$result["function"],當前執行的函式名稱.
12528
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12529
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12530
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12531
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
12532
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12533
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12534
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12535
		#必填寫的參數:
12536
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12537
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12538
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12539
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("getListTree");
226 liveuser 12540
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 12541
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
12542
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12543
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12544
		#可以省略的參數:
12545
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
12546
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
12547
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12548
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileToRead","output");
226 liveuser 12549
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12550
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
12551
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12552
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("help","help");
12553
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12554
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
12555
		#參考資料來源:
12556
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12557
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12558
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 12559
 
3 liveuser 12560
		#如果 $checkResult["status"] 等於 "fasle"
12561
		if($checkResult["status"]=="false"){
226 liveuser 12562
 
3 liveuser 12563
			#設置錯誤識別
12564
			$result["status"]="false";
226 liveuser 12565
 
3 liveuser 12566
			#設置錯誤訊息
12567
			$result["error"]=$checkResult;
226 liveuser 12568
 
3 liveuser 12569
			#回傳結果
12570
			return $result;
226 liveuser 12571
 
3 liveuser 12572
			}#if end
226 liveuser 12573
 
3 liveuser 12574
		#如果 $checkResult["passed"] 等於 "fasle"
12575
		if($checkResult["passed"]=="false"){
226 liveuser 12576
 
3 liveuser 12577
			#設置錯誤識別
12578
			$result["status"]="false";
226 liveuser 12579
 
3 liveuser 12580
			#設置錯誤訊息
12581
			$result["error"]=$checkResult;
226 liveuser 12582
 
3 liveuser 12583
			#回傳結果
12584
			return $result;
226 liveuser 12585
 
3 liveuser 12586
			}#if end
226 liveuser 12587
 
3 liveuser 12588
		#如果 $conf["getListTree"]["status"] 不存在
12589
		if(!isset($conf["getListTree"]["status"])){
226 liveuser 12590
 
3 liveuser 12591
			#設置錯誤識別
12592
			$result["status"]="false";
226 liveuser 12593
 
3 liveuser 12594
			#設置錯誤訊息
12595
			$result["error"][]="getListTree參數必須為getListTree函數執行後的結果";
226 liveuser 12596
 
3 liveuser 12597
			#回傳結果
12598
			return $result;
226 liveuser 12599
 
3 liveuser 12600
			}#if end
226 liveuser 12601
 
3 liveuser 12602
		#如果 $conf["getListTree"] 執行失敗
12603
		if($conf["getListTree"]["status"]=="false"){
226 liveuser 12604
 
3 liveuser 12605
			#設置錯誤識別
12606
			$result["status"]="false";
226 liveuser 12607
 
3 liveuser 12608
			#設置錯誤訊息
12609
			$result["error"]=$conf["getListTree"];
226 liveuser 12610
 
3 liveuser 12611
			#回傳結果
12612
			return $result;
226 liveuser 12613
 
3 liveuser 12614
			}#if end
226 liveuser 12615
 
3 liveuser 12616
		#如果有目錄檔案
12617
		if(isset($conf["getListTree"]["content"])){
226 liveuser 12618
 
12619
 
12620
 
3 liveuser 12621
			}#if end
226 liveuser 12622
 
3 liveuser 12623
		}#function createHelpFile end
226 liveuser 12624
 
3 liveuser 12625
	/*
12626
	#函式說明:
12627
	#嵌入pdf檔案到網頁上面
12628
	#回傳結果:
12629
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12630
	#$result["error"],錯誤訊息陣列.
226 liveuser 12631
	#$result["function"],函數名稱.
3 liveuser 12632
	#$result["content"],嵌入pdf檔案的語法
12633
	#必填參數:
12634
	#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
12635
	$conf["fileArgu"]=__FILE__;
12636
	#$conf["file"],字串,pdf檔案位置.
12637
	$conf["file"]="";
12638
	#可省略參數:
12639
	#$conf["type"],字串,要用"iframe"還是"object"的方式嵌入pdf檔案,預設為"iframe".
12640
	#$conf["type"]="iframe";
12641
	#參考資料:
12642
	#嵌入pdf到網頁=>https://stackoverflow.com/questions/14690000/embed-a-pdf-in-html5
12643
	#備註:
12644
	#如果是網址就會出錯.
12645
	*/
12646
	public static function embedPdf(&$conf=array()){
226 liveuser 12647
 
3 liveuser 12648
		#初始化要回傳的結果
12649
		$result=array();
12650
 
12651
		#取得當前執行的函數名稱
12652
		$result["function"]=__FUNCTION__;
12653
 
12654
		#如果沒有參數
12655
		if(func_num_args()==0){
226 liveuser 12656
 
3 liveuser 12657
			#設置執行失敗
12658
			$result["status"]="false";
226 liveuser 12659
 
3 liveuser 12660
			#設置執行錯誤訊息
12661
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 12662
 
3 liveuser 12663
			#回傳結果
12664
			return $result;
226 liveuser 12665
 
3 liveuser 12666
			}#if end
12667
 
12668
		#取得參數
12669
		$result["argu"]=$conf;
12670
 
12671
		#如果 $conf 不為陣列
12672
		if(gettype($conf)!=="array"){
226 liveuser 12673
 
3 liveuser 12674
			#設置執行失敗
12675
			$result["status"]="false";
226 liveuser 12676
 
3 liveuser 12677
			#設置執行錯誤訊息
12678
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 12679
 
3 liveuser 12680
			#如果傳入的參數為 null
12681
			if($conf===null){
226 liveuser 12682
 
3 liveuser 12683
				#設置執行錯誤訊息
12684
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12685
 
3 liveuser 12686
				}#if end
12687
 
12688
			#回傳結果
12689
			return $result;
226 liveuser 12690
 
3 liveuser 12691
			}#if end
226 liveuser 12692
 
3 liveuser 12693
		#檢查參數
12694
		#函式說明:
12695
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12696
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12697
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12698
		#$result["function"],當前執行的函式名稱.
12699
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12700
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12701
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12702
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12703
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12704
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12705
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12706
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12707
		#必填寫的參數:
12708
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12709
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12710
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12711
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
12712
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12713
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
12714
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12715
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12716
		#可以省略的參數:
12717
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12718
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
12719
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12720
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("function");
12721
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12722
		#$conf["canBeEmpty"]=array();
12723
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12724
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("width","height");
12725
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12726
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("type");
226 liveuser 12727
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12728
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
12729
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12730
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("iframe");
12731
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12732
		#$conf["arrayCountEqualCheck"][]=array();
12733
		#參考資料來源:
12734
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12735
		#建議:
12736
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
12737
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
226 liveuser 12738
		unset($conf["variableCheck::checkArguments"]);
12739
 
3 liveuser 12740
		#如果檢查參數失敗
12741
		if($checkArguments["status"]==="false"){
226 liveuser 12742
 
3 liveuser 12743
			#設置執行失敗
12744
			$result["status"]="false";
226 liveuser 12745
 
3 liveuser 12746
			#設置執行錯誤訊息
12747
			$result["error"]=$checkArguments;
226 liveuser 12748
 
3 liveuser 12749
			#回傳結果
12750
			return $result;
226 liveuser 12751
 
3 liveuser 12752
			}#if end
226 liveuser 12753
 
3 liveuser 12754
		#如果參數檢查不通過
12755
		if($checkArguments["passed"]==="false"){
226 liveuser 12756
 
3 liveuser 12757
			#設置執行失敗
12758
			$result["status"]="false";
226 liveuser 12759
 
3 liveuser 12760
			#設置執行錯誤訊息
12761
			$result["error"]=$checkArguments;
226 liveuser 12762
 
3 liveuser 12763
			#回傳結果
12764
			return $result;
226 liveuser 12765
 
3 liveuser 12766
			}#if end
226 liveuser 12767
 
3 liveuser 12768
		#檢查檔案是否存在
12769
		#函式說明:
12770
		#檢查多個檔案與資料夾是否存在.
12771
		#回傳的結果:
12772
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
12773
		#$result["error"],錯誤訊息陣列.
12774
		#$resutl["function"],當前執行的涵式名稱.
12775
		#$result["argu"],使用的參數.
12776
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
12777
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
12778
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
12779
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
12780
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
12781
		#必填參數:
12782
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
12783
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
12784
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12785
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
12786
		#可省略參數
12787
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
12788
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="false";
12789
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
12790
		#$conf["userDir"]="true";
12791
		#參考資料來源:
12792
		#http://php.net/manual/en/function.file-exists.php
12793
		#http://php.net/manual/en/control-structures.foreach.php
12794
		#備註:
12795
		#函數file_exists檢查的路徑為檔案系統的路徑
12796
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
12797
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 12798
 
3 liveuser 12799
		#如果檢查檔案是否存在失敗
12800
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 12801
 
3 liveuser 12802
			#設置執行失敗
12803
			$result["status"]="false";
226 liveuser 12804
 
3 liveuser 12805
			#設置執行錯誤訊息
12806
			$result["error"]=$checkMultiFileExist;
226 liveuser 12807
 
3 liveuser 12808
			#回傳結果
12809
			return $result;
226 liveuser 12810
 
3 liveuser 12811
			}#if end
226 liveuser 12812
 
3 liveuser 12813
		#如果檔案不存在
12814
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 12815
 
3 liveuser 12816
			#設置執行失敗
12817
			$result["status"]="false";
226 liveuser 12818
 
3 liveuser 12819
			#設置執行錯誤訊息
12820
			$result["error"]=$checkMultiFileExist;
226 liveuser 12821
 
3 liveuser 12822
			#回傳結果
12823
			return $result;
226 liveuser 12824
 
3 liveuser 12825
			}#if end
226 liveuser 12826
 
3 liveuser 12827
		#產生 base64 的 pdf 編碼字串
12828
		$base64pdf=base64_encode(file_get_contents($conf["file"]));
226 liveuser 12829
 
3 liveuser 12830
		#產生 base64 的 pdf 編碼字串 data
12831
		$base64pdfData="data:application/pdf;base64,".$base64pdf;
226 liveuser 12832
 
3 liveuser 12833
		#判斷要用哪種方式嵌入pdf
12834
		switch($conf["type"]){
226 liveuser 12835
 
3 liveuser 12836
			#如果是用 object 方式
12837
			case "object":
226 liveuser 12838
 
3 liveuser 12839
				#產生嵌入的語法
12840
				$embedSyntax="<object style=\"width:100%;height:100%;\" data=\"".$base64pdfData."\"></object>";
226 liveuser 12841
 
3 liveuser 12842
				#取得語法
12843
				$result["content"]=&$embedSyntax;
226 liveuser 12844
 
3 liveuser 12845
				#跳出 switch
12846
				break;
226 liveuser 12847
 
3 liveuser 12848
			#預設
12849
			default:
226 liveuser 12850
 
3 liveuser 12851
				#產生嵌入的語法
12852
				$embedSyntax="<iframe style=\"width:100%;height:100%;\" src=\"".$base64pdfData."\"></iframe>";
226 liveuser 12853
 
3 liveuser 12854
				#取得語法
12855
				$result["content"]=&$embedSyntax;
226 liveuser 12856
 
3 liveuser 12857
			}#switch end
226 liveuser 12858
 
3 liveuser 12859
		#設置執行正常
12860
		$result["status"]="true";
226 liveuser 12861
 
3 liveuser 12862
		#回傳結果
12863
		return $result;
226 liveuser 12864
 
3 liveuser 12865
		}#function embedPdf end
226 liveuser 12866
 
3 liveuser 12867
	/*
12868
	#函式說明:
226 liveuser 12869
	#用linux unzip去解壓縮zip檔案
3 liveuser 12870
	#回傳結果:
12871
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12872
	#$result["error"],錯誤訊息.
12873
	#$result["function"],當前執行的函數名稱.
12874
	#$result["content"]["each"],每個檔案的資訊.
12875
	#$result["content"]["each"]["Length"][$i],各別檔案目錄的原始長度.
12876
	#$result["content"]["each"]["Method"][$i],各別檔案目錄的壓縮方法.
12877
	#$result["content"]["each"]["Size"][$i],各別檔案目錄的壓縮後長度.
12878
	#$result["content"]["each"]["Cmpr"][$i],各別檔案目錄的壓縮率.
12879
	#$result["content"]["each"]["Date"][$i],各別檔案目錄的最後修改日期.
12880
	#$result["content"]["each"]["Time"][$i],各別檔案目錄的最後修改時間.
12881
	#$result["content"]["each"]["CRC-32"][$i],各別檔案目錄的CRC-32檢查碼.
12882
	#$result["content"]["each"]["Name"][$i],各別檔案目錄的路徑與名稱.
12883
	#$result["content"]["total"],統整的資訊.
12884
	#$result["content"]["Length"],總共的檔案長度.
12885
	#$result["content"]["Size"],壓縮後的檔案長度.
12886
	#$result["content"]["Cmpr"],平均壓縮率.
12887
	#$result["content"]["count"],壓縮檔裡面總共的檔案跟目錄數目.
12888
	#必填參數;
12889
	#$conf["zip"],字串,要解壓縮的zip檔案.
12890
	$conf["zip"]="";
12891
	#$conf["fileArgu"],字串,__FILE__的內容.
12892
	$conf["fileArgu"]=__FILE__;
12893
	#可省略參數:
12894
	#$conf["extract"],字串,要解壓縮到那個路徑,預設為當前位置"./".
12895
	#$conf["extract"]="";
12896
	#備註:
12897
	#建議加上特定邊碼的支援例如、單
12898
	*/
12899
	public static function unzip(&$conf=array()){
226 liveuser 12900
 
3 liveuser 12901
		#初始化要回傳的結果
12902
		$result=array();
12903
 
12904
		#取得當前執行的函數名稱
12905
		$result["function"]=__FUNCTION__;
12906
 
12907
		#如果沒有參數
12908
		if(func_num_args()==0){
226 liveuser 12909
 
3 liveuser 12910
			#設置執行失敗
12911
			$result["status"]="false";
226 liveuser 12912
 
3 liveuser 12913
			#設置執行錯誤訊息
12914
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 12915
 
3 liveuser 12916
			#回傳結果
12917
			return $result;
226 liveuser 12918
 
3 liveuser 12919
			}#if end
226 liveuser 12920
 
3 liveuser 12921
		#取得參數
12922
		$result["argu"]=$conf;
12923
 
12924
		#如果 $conf 不為陣列
12925
		if(gettype($conf)!=="array"){
226 liveuser 12926
 
3 liveuser 12927
			#設置執行失敗
12928
			$result["status"]="false";
226 liveuser 12929
 
3 liveuser 12930
			#設置執行錯誤訊息
12931
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 12932
 
3 liveuser 12933
			#如果傳入的參數為 null
12934
			if($conf===null){
226 liveuser 12935
 
3 liveuser 12936
				#設置執行錯誤訊息
12937
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12938
 
3 liveuser 12939
				}#if end
12940
 
12941
			#回傳結果
12942
			return $result;
226 liveuser 12943
 
3 liveuser 12944
			}#if end
226 liveuser 12945
 
3 liveuser 12946
		#檢查參數
12947
		#函式說明:
12948
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12949
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12950
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12951
		#$result["function"],當前執行的函式名稱.
12952
		#$result["argu"],設置給予的參數.
12953
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12954
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12955
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12956
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12957
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12958
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12959
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12960
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12961
		#必填寫的參數:
12962
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 12963
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 12964
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12965
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12966
		#可以省略的參數:
12967
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12968
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("zip","fileArgu");
12969
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12970
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
12971
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12972
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
12973
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12974
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("zip","fileArgu");
12975
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12976
		#$conf["canBeEmpty"]=array();
12977
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12978
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("extract");
12979
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12980
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("extract");
226 liveuser 12981
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12982
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
12983
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12984
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("./");
12985
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12986
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12987
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12988
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12989
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12990
		#$conf["arrayCountEqualCheck"][]=array();
12991
		#參考資料來源:
12992
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12993
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12994
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 12995
 
3 liveuser 12996
		#如果檢查參數失敗
12997
		if($checkArguments["status"]==="false"){
226 liveuser 12998
 
3 liveuser 12999
			#設置執行不正常
13000
			$result["status"]="false";
226 liveuser 13001
 
3 liveuser 13002
			#設置錯誤訊息
13003
			$result["error"]=$checkArguments;
226 liveuser 13004
 
3 liveuser 13005
			#回傳結果
13006
			return $result;
226 liveuser 13007
 
3 liveuser 13008
			}#if end
226 liveuser 13009
 
3 liveuser 13010
		#如果檢查參數不通過
13011
		if($checkArguments["passed"]==="false"){
226 liveuser 13012
 
3 liveuser 13013
			#設置執行不正常
13014
			$result["status"]="false";
226 liveuser 13015
 
3 liveuser 13016
			#設置錯誤訊息
13017
			$result["error"]=$checkArguments;
226 liveuser 13018
 
3 liveuser 13019
			#回傳結果
13020
			return $result;
226 liveuser 13021
 
3 liveuser 13022
			}#if end
226 liveuser 13023
 
3 liveuser 13024
		#檢查要解壓縮的檔案是否存在
13025
		#函式說明:
13026
		#檢查多個檔案與資料夾是否存在.
13027
		#回傳的結果:
13028
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13029
		#$result["error"],錯誤訊息陣列.
13030
		#$resutl["function"],當前執行的涵式名稱.
13031
		#$result["argu"],使用的參數.
13032
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
13033
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
13034
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
13035
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
13036
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
13037
		#必填參數:
13038
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
13039
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["zip"]);
13040
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13041
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
13042
		#可省略參數
13043
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
13044
		#$conf["disableWebSearch"]="false";
13045
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
13046
		#$conf["userDir"]="true";
13047
		#參考資料來源:
13048
		#http://php.net/manual/en/function.file-exists.php
13049
		#http://php.net/manual/en/control-structures.foreach.php
13050
		#備註:
13051
		#函數file_exists檢查的路徑為檔案系統的路徑
13052
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
13053
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 13054
 
3 liveuser 13055
		#如果檢查檔案是否存在失敗
13056
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 13057
 
3 liveuser 13058
			#設置執行不正常
13059
			$result["status"]="false";
226 liveuser 13060
 
3 liveuser 13061
			#設置錯誤訊息
13062
			$result["error"]=$checkMultiFileExist;
226 liveuser 13063
 
3 liveuser 13064
			#回傳結果
13065
			return $result;
226 liveuser 13066
 
3 liveuser 13067
			}#if end
226 liveuser 13068
 
3 liveuser 13069
		#如果要解壓縮的檔案不存在
13070
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 13071
 
3 liveuser 13072
			#設置執行不正常
13073
			$result["status"]="false";
226 liveuser 13074
 
3 liveuser 13075
			#設置錯誤訊息
13076
			$result["error"]=$checkMultiFileExist;
226 liveuser 13077
 
3 liveuser 13078
			#回傳結果
13079
			return $result;
226 liveuser 13080
 
3 liveuser 13081
			}#if end
226 liveuser 13082
 
3 liveuser 13083
		#函式說明:
13084
		#呼叫shell執行系統命令,並取得回傳的內容.
13085
		#回傳結果:
13086
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13087
		#$result["error"],錯誤訊息陣列.
13088
		#$result["function"],當前執行的函數名稱.
13089
		#$result["argu"],使用的參數.
13090
		#$result["cmd"],執行的指令內容.
13091
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
13092
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
13093
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
13094
		#$result["running"],是否還在執行.
13095
		#$result["pid"],pid
13096
		#必填參數:
13097
		#$conf["command"],字串,要執行的指令與.
13098
		$conf["external::callShell"]["command"]="unzip";
13099
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 13100
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 13101
		#可省略參數:
13102
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
13103
		$conf["external::callShell"]["argu"]=array("-d",$conf["extract"],"-o","-q",$conf["zip"]);
13104
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
13105
		#$conf["arguIsAddr"]=array();
13106
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
13107
		#$conf["enablePrintDescription"]="true";
13108
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
13109
		#$conf["printDescription"]="";
13110
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
13111
		$conf["external::callShell"]["escapeshellarg"]="true";
13112
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
13113
		#$conf["username"]="";
13114
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
13115
		#$conf["password"]="";
13116
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
13117
		#$conf["useScript"]="";
13118
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
13119
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
13120
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
13121
		#$conf["inBackGround"]="";
13122
		#備註:
13123
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
13124
		#參考資料:
13125
		#exec=>http://php.net/manual/en/function.exec.php
13126
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
13127
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
13128
		$callShell=external::callShell($conf["external::callShell"]);
13129
		unset($conf["external::callShell"]);
226 liveuser 13130
 
3 liveuser 13131
		#如果執行cmd失敗
13132
		if($callShell["status"]==="false"){
226 liveuser 13133
 
3 liveuser 13134
			#設置執行不正常
13135
			$result["status"]="false";
226 liveuser 13136
 
3 liveuser 13137
			#設置錯誤訊息
13138
			$result["error"]=$callShell;
226 liveuser 13139
 
3 liveuser 13140
			#回傳結果
13141
			return $result;
226 liveuser 13142
 
3 liveuser 13143
			}#if end
226 liveuser 13144
 
3 liveuser 13145
		#函式說明:
13146
		#呼叫shell執行系統命令,並取得回傳的內容.
13147
		#回傳的結果:
13148
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13149
		#$result["error"],錯誤訊息陣列.
13150
		#$result["function"],當前執行的函數名稱.
13151
		#$result["argu"],使用的參數.
13152
		#$result["cmd"],執行的指令內容.
13153
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
13154
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
13155
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
13156
		#$result["running"],是否還在執行.
13157
		#$result["pid"],pid
13158
		#必填的參數
13159
		#$conf["command"],字串,要執行的指令與.
13160
		$conf["external::callShell"]["command"]="unzip";
13161
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 13162
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 13163
		#可省略參數:
13164
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
13165
		$conf["external::callShell"]["argu"]=array("-v",$conf["zip"]);
13166
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
13167
		#$conf["arguIsAddr"]=array();
13168
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
13169
		#$conf["enablePrintDescription"]="true";
13170
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
13171
		#$conf["printDescription"]="";
13172
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
13173
		$conf["external::callShell"]["escapeshellarg"]="true";
13174
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
13175
		#$conf["username"]="";
13176
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
13177
		#$conf["password"]="";
13178
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
13179
		#$conf["useScript"]="";
13180
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
13181
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
13182
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
13183
		#$conf["inBackGround"]="";
13184
		#備註:
13185
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
13186
		#參考資料:
13187
		#exec=>http://php.net/manual/en/function.exec.php
13188
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
13189
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
13190
		$callShell=external::callShell($conf["external::callShell"]);
13191
		unset($conf["external::callShell"]);
226 liveuser 13192
 
3 liveuser 13193
		#如果執行cmd失敗
13194
		if($callShell["status"]==="false"){
226 liveuser 13195
 
3 liveuser 13196
			#設置執行不正常
13197
			$result["status"]="false";
226 liveuser 13198
 
3 liveuser 13199
			#設置錯誤訊息
13200
			$result["error"]=$callShell;
226 liveuser 13201
 
3 liveuser 13202
			#回傳結果
13203
			return $result;
226 liveuser 13204
 
13205
			}#if end
13206
 
3 liveuser 13207
		#取得輸出的內容陣列
13208
		$unzipInfo=$callShell["output"];
226 liveuser 13209
 
3 liveuser 13210
		/*
226 liveuser 13211
 
3 liveuser 13212
		 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
13213
		--------  ------  ------- ---- ---------- ----- --------  ----
13214
		 4194304  Defl:X  2507269  40% 05-04-2002 17:30 9386a740  PS2 Bios 30004R V6 Pal.bin
13215
			   4  Defl:X        6 -50% 05-15-2005 06:45 054a6ec2  PS2 Bios 30004R V6 Pal.MEC
13216
			1024  Defl:X       22  98% 06-25-2005 14:55 3493bb06  PS2 Bios 30004R V6 Pal.NVM
13217
		  199680  Defl:X    70524  65% 06-02-2004 16:50 2c3bcd32  rom1.bin
13218
		 4194304  Defl:X  2637496  37% 02-20-2005 21:12 6f8e3c29  SCPH-70004_BIOS_V12_PAL_200.BIN
13219
		 3145728  Defl:X  3138427   0% 02-20-2005 21:12 bf3cbc65  SCPH-70004_BIOS_V12_PAL_200.EROM
13220
			1024  Defl:X      706  31% 02-20-2005 21:12 a8d51ead  SCPH-70004_BIOS_V12_PAL_200.NVM
13221
		  524288  Defl:X   149924  71% 02-20-2005 21:12 0e8797c0  SCPH-70004_BIOS_V12_PAL_200.ROM1
13222
		  524288  Defl:X   149924  71% 02-20-2005 21:12 0e8797c0  SCPH-70004_BIOS_V12_PAL_200.ROM2
13223
		 4194304  Defl:X  2213105  47% 10-18-2000 06:06 b7ef81a9  scph10000.bin
13224
			1024  Defl:X       11  99% 01-01-2005 00:42 efb5af2e  scph10000.NVM
13225
		 4194304  Defl:X  2511182  40% 06-27-2003 10:51 a19e0bf5  scph39001.bin
13226
			   4  Defl:X        6 -50% 05-14-2005 16:00 054a6ec2  scph39001.MEC
13227
			1024  Defl:X       20  98% 05-31-2005 16:09 e14a6cd6  scph39001.NVM
13228
		--------          -------  ---                            -------
13229
		21175304         13378622  37%                            14 files
226 liveuser 13230
 
3 liveuser 13231
		*/
226 liveuser 13232
 
3 liveuser 13233
		#取得行數
13234
		$lineCount=count($unzipInfo);
226 liveuser 13235
 
3 liveuser 13236
		#取得標題
13237
		#函式說明:
13238
		#將固定格式的字串分開,並回傳分開的結果。
13239
		#回傳結果:
13240
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13241
		#$result["error"],錯誤訊息陣列
13242
		#$result["function"],當前執行的函數名稱.
13243
		#$result["oriStr"],要分割的原始字串內容
13244
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13245
		#$result["dataCounts"],爲總共分成幾段
13246
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13247
		#必填參數:
13248
		$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[1];#要處理的字串。
13249
		$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13250
		#可省略參數:
13251
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13252
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13253
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13254
		unset($conf["stringProcess::spiltString"]);
226 liveuser 13255
 
3 liveuser 13256
		#如果分割字串失敗
13257
		if($spiltString["status"]==="false"){
226 liveuser 13258
 
3 liveuser 13259
			#設置執行不正常
13260
			$result["status"]="false";
226 liveuser 13261
 
3 liveuser 13262
			#設置錯誤訊息
13263
			$result["error"]=$spiltString;
226 liveuser 13264
 
3 liveuser 13265
			#回傳結果
13266
			return $result;
226 liveuser 13267
 
3 liveuser 13268
			}#if end
226 liveuser 13269
 
3 liveuser 13270
		#如果沒有分割用的關鍵字
13271
		if($spiltString["found"]==="false"){
226 liveuser 13272
 
3 liveuser 13273
			#設置執行不正常
13274
			$result["status"]="false";
226 liveuser 13275
 
3 liveuser 13276
			#設置錯誤訊息
13277
			$result["error"]=$spiltString;
226 liveuser 13278
 
3 liveuser 13279
			#回傳結果
13280
			return $result;
226 liveuser 13281
 
3 liveuser 13282
			}#if end
226 liveuser 13283
 
3 liveuser 13284
		#取得標題欄位
226 liveuser 13285
		$titles=$spiltString["dataArray"];
13286
 
3 liveuser 13287
		#取得標題欄位數目
13288
		$titleCount=$spiltString["dataCounts"];
226 liveuser 13289
 
3 liveuser 13290
		#針對每列輸出
13291
		for($i=3;$i<$lineCount-2;$i++){
226 liveuser 13292
 
3 liveuser 13293
			#取得各欄位的內容
13294
			#函式說明:
13295
			#將固定格式的字串分開,並回傳分開的結果。
13296
			#回傳結果:
13297
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13298
			#$result["error"],錯誤訊息陣列
13299
			#$result["function"],當前執行的函數名稱.
13300
			#$result["oriStr"],要分割的原始字串內容
13301
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13302
			#$result["dataCounts"],爲總共分成幾段
13303
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13304
			#必填參數:
13305
			$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[$i];#要處理的字串。
13306
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13307
			#可省略參數:
13308
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13309
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13310
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13311
			unset($conf["stringProcess::spiltString"]);
226 liveuser 13312
 
3 liveuser 13313
			#如果分割字串失敗
13314
			if($spiltString["status"]==="false"){
226 liveuser 13315
 
3 liveuser 13316
				#設置執行不正常
13317
				$result["status"]="false";
226 liveuser 13318
 
3 liveuser 13319
				#設置錯誤訊息
13320
				$result["error"]=$spiltString;
226 liveuser 13321
 
3 liveuser 13322
				#回傳結果
13323
				return $result;
226 liveuser 13324
 
3 liveuser 13325
				}#if end
226 liveuser 13326
 
3 liveuser 13327
			#如果沒有分割用的關鍵字
13328
			if($spiltString["found"]==="false"){
226 liveuser 13329
 
3 liveuser 13330
				#設置執行不正常
13331
				$result["status"]="false";
226 liveuser 13332
 
3 liveuser 13333
				#設置錯誤訊息
13334
				$result["error"]=$spiltString;
226 liveuser 13335
 
3 liveuser 13336
				#回傳結果
13337
				return $result;
226 liveuser 13338
 
3 liveuser 13339
				}#if end
226 liveuser 13340
 
3 liveuser 13341
			#取得各欄位的內容
13342
			$cols=$spiltString["dataArray"];
226 liveuser 13343
 
3 liveuser 13344
			#取得欄位的數目
13345
			$colsCount=$spiltString["dataCounts"];
226 liveuser 13346
 
3 liveuser 13347
			#如果實際抓出的內容欄位數量大於標題欄位數量,代表檔案/目錄名稱含有空格
13348
			if($colsCount>$titleCount){
226 liveuser 13349
 
3 liveuser 13350
				#新的檔案名稱
13351
				$newFileName="";
226 liveuser 13352
 
3 liveuser 13353
				#針對每個多出的欄位
13354
				for($j=$titleCount;$j<$colsCount;$j++){
226 liveuser 13355
 
3 liveuser 13356
					#串接屬於檔案名稱的部分
13357
					$newFileName=$newFileName.$cols[$j];
226 liveuser 13358
 
3 liveuser 13359
					#如果不是最後一個項目
13360
					if($j!==$colsCount-1){
226 liveuser 13361
 
3 liveuser 13362
						#增加空格
13363
						$newFileName=$newFileName." ";
226 liveuser 13364
 
3 liveuser 13365
						}#if end
226 liveuser 13366
 
3 liveuser 13367
					}#for end
226 liveuser 13368
 
3 liveuser 13369
				#取代成對的檔案名稱
13370
				$cols[$titleCount-1]=$newFileName;
226 liveuser 13371
 
3 liveuser 13372
				}#if end
226 liveuser 13373
 
3 liveuser 13374
			#針對每個欄位
13375
			for($j=0;$j<$titleCount;$j++){
226 liveuser 13376
 
3 liveuser 13377
				#取得欄位內容
13378
				$result["content"]["each"][$titles[$j]][]=$cols[$j];
226 liveuser 13379
 
3 liveuser 13380
				}#for end
226 liveuser 13381
 
3 liveuser 13382
			}#for end
226 liveuser 13383
 
3 liveuser 13384
		#取得 total 的輸出內容
13385
		#函式說明:
13386
		#將固定格式的字串分開,並回傳分開的結果。
13387
		#回傳結果:
13388
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13389
		#$result["error"],錯誤訊息陣列
13390
		#$result["function"],當前執行的函數名稱.
13391
		#$result["oriStr"],要分割的原始字串內容
13392
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13393
		#$result["dataCounts"],爲總共分成幾段
13394
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13395
		#必填參數:
13396
		$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[$lineCount-1];#要處理的字串。
13397
		$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13398
		#可省略參數:
13399
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13400
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13401
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13402
		unset($conf["stringProcess::spiltString"]);
226 liveuser 13403
 
3 liveuser 13404
		#如果分割字串失敗
13405
		if($spiltString["status"]==="false"){
226 liveuser 13406
 
3 liveuser 13407
			#設置執行不正常
13408
			$result["status"]="false";
226 liveuser 13409
 
3 liveuser 13410
			#設置錯誤訊息
13411
			$result["error"]=$spiltString;
226 liveuser 13412
 
3 liveuser 13413
			#回傳結果
13414
			return $result;
226 liveuser 13415
 
3 liveuser 13416
			}#if end
226 liveuser 13417
 
3 liveuser 13418
		#如果沒有分割用的關鍵字
13419
		if($spiltString["found"]==="false"){
226 liveuser 13420
 
3 liveuser 13421
			#設置執行不正常
13422
			$result["status"]="false";
226 liveuser 13423
 
3 liveuser 13424
			#設置錯誤訊息
13425
			$result["error"]=$spiltString;
226 liveuser 13426
 
3 liveuser 13427
			#回傳結果
13428
			return $result;
226 liveuser 13429
 
3 liveuser 13430
			}#if end
226 liveuser 13431
 
3 liveuser 13432
		#取得各欄位的內容
13433
		$cols=$spiltString["dataArray"];
226 liveuser 13434
 
3 liveuser 13435
		#取得總共的檔案長度
13436
		$result["content"]["total"][$titles[0]]=$cols[0];
226 liveuser 13437
 
3 liveuser 13438
		#取得壓縮時的總共檔案長度
13439
		$result["content"]["total"][$titles[2]]=$cols[1];
226 liveuser 13440
 
3 liveuser 13441
		#取得壓縮時的總共檔案長度
13442
		$result["content"]["total"][$titles[3]]=$cols[2];
226 liveuser 13443
 
3 liveuser 13444
		#取得解壓縮出了多少檔案跟目錄
13445
		$result["content"]["total"]["count"]=explode(" ",$cols[3])[0];
226 liveuser 13446
 
3 liveuser 13447
		#設置執行正常
13448
		$result["status"]="true";
226 liveuser 13449
 
3 liveuser 13450
		#回傳結果
13451
		return $result;
226 liveuser 13452
 
3 liveuser 13453
		}#function unzip end
226 liveuser 13454
 
3 liveuser 13455
	/*
13456
	#函式說明:
13457
	#接收Range: bytes=0-499格式的header, 輸出檔案的片段或完整檔案.
13458
	#回傳結果:
13459
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13460
	#$result["error"],錯誤訊息.
13461
	#$result["function"],當前執行的函式名稱.
13462
	#必填參數:
13463
	#$conf["filePath"],字串,檔案的路徑.
13464
	$conf["filePath"]="";
13465
	#可省略參數:
13466
	#$conf["fileName"],字串,顯示的檔案名稱,預設為basename($conf["filePath"]);
13467
	#$conf["fileName"]="";
13468
	#參考資料:
13469
	#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/
13470
	#http://php.net/manual/en/function.filemtime.php
13471
	#http://php.net/manual/en/function.connection-status.php
13472
	#http://php.net/manual/en/function.fread.php
13473
	#備註:
13474
	#請勿在運行該函式前印出任何內容,這是要給用戶端接收的內容.
13475
	*/
13476
	public static function partDownload(&$conf=array()){
226 liveuser 13477
 
3 liveuser 13478
		#初始化要回傳的結果
13479
		$result=array();
13480
 
13481
		#取得當前執行的函數名稱
13482
		$result["function"]=__FUNCTION__;
13483
 
13484
		#如果沒有參數
13485
		if(func_num_args()==0){
226 liveuser 13486
 
3 liveuser 13487
			#設置執行失敗
13488
			$result["status"]="false";
226 liveuser 13489
 
3 liveuser 13490
			#設置執行錯誤訊息
13491
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 13492
 
3 liveuser 13493
			#回傳結果
13494
			return $result;
226 liveuser 13495
 
3 liveuser 13496
		}#if end
226 liveuser 13497
 
3 liveuser 13498
		#取得參數
13499
		$result["argu"]=$conf;
13500
 
13501
		#如果 $conf 不為陣列
13502
		if(gettype($conf)!=="array"){
226 liveuser 13503
 
3 liveuser 13504
			#設置執行失敗
13505
			$result["status"]="false";
226 liveuser 13506
 
3 liveuser 13507
			#設置執行錯誤訊息
13508
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 13509
 
3 liveuser 13510
			#如果傳入的參數為 null
13511
			if($conf===null){
226 liveuser 13512
 
3 liveuser 13513
				#設置執行錯誤訊息
13514
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 13515
 
3 liveuser 13516
				}#if end
13517
 
13518
			#回傳結果
13519
			return $result;
226 liveuser 13520
 
3 liveuser 13521
			}#if end
226 liveuser 13522
 
3 liveuser 13523
		#檢查參數
13524
		#函式說明:
13525
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13526
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13527
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13528
		#$result["function"],當前執行的函式名稱.
13529
		#$result["argu"],設置給予的參數.
13530
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13531
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13532
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13533
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13534
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13535
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13536
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13537
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13538
		#必填寫的參數:
13539
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 13540
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 13541
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13542
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13543
		#可以省略的參數:
13544
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13545
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePath");
13546
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13547
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
13548
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13549
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
13550
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13551
		#$conf["canNotBeEmpty"]=array();
13552
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13553
		#$conf["canBeEmpty"]=array();
13554
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13555
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("fileName");
13556
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13557
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileName");
226 liveuser 13558
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 13559
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
13560
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13561
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
13562
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
13563
		#$conf["disallowAllSkipableVarIsEmpty"]="";
13564
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
13565
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
13566
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13567
		#$conf["arrayCountEqualCheck"][]=array();
13568
		#參考資料來源:
13569
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13570
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
13571
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 13572
 
3 liveuser 13573
		#如果檢查參數失敗
13574
		if($checkArguments["status"]==="false"){
226 liveuser 13575
 
3 liveuser 13576
			#設置執行失敗
13577
			$result["status"]="false";
226 liveuser 13578
 
3 liveuser 13579
			#設置執行錯誤
13580
			$result["error"]=$checkArguments;
226 liveuser 13581
 
3 liveuser 13582
			#回傳結果
13583
			return $result;
226 liveuser 13584
 
3 liveuser 13585
			}#if end
226 liveuser 13586
 
3 liveuser 13587
		#如果檢查參數不通過
13588
		if($checkArguments["passed"]==="false"){
226 liveuser 13589
 
3 liveuser 13590
			#設置執行失敗
13591
			$result["status"]="false";
226 liveuser 13592
 
3 liveuser 13593
			#設置執行錯誤
13594
			$result["error"]=$checkArguments;
226 liveuser 13595
 
3 liveuser 13596
			#回傳結果
13597
			return $result;
226 liveuser 13598
 
3 liveuser 13599
			}#if end
226 liveuser 13600
 
3 liveuser 13601
		#如果沒有設置 $conf["fileName"]
13602
		if(!isset($conf["fileName"])){
226 liveuser 13603
 
3 liveuser 13604
			#取得檔案名稱
13605
			$filename=basename($conf["filePath"]);
226 liveuser 13606
 
3 liveuser 13607
			}#if end
226 liveuser 13608
 
3 liveuser 13609
		#反之
13610
		else{
226 liveuser 13611
 
3 liveuser 13612
			#取得設定好的檔案名稱
13613
			$filename=&$conf["fileName"];
226 liveuser 13614
 
3 liveuser 13615
			}#else end
226 liveuser 13616
 
3 liveuser 13617
		#取得檔案路徑
13618
		$location=$conf["filePath"];
13619
 
13620
		#取得mimetype
13621
		$mimetype=mime_content_type($location);
226 liveuser 13622
 
3 liveuser 13623
		#如果檔案不存在
13624
		if(!file_exists($location)){
226 liveuser 13625
 
3 liveuser 13626
			#提示找不到檔案
13627
			header("HTTP/1.1 404 Not Found");
226 liveuser 13628
 
3 liveuser 13629
			#設置執行失敗
13630
			$result["status"]="false";
226 liveuser 13631
 
3 liveuser 13632
			#設置錯誤訊息
13633
			$result["error"][]="檔案 ".$location." 不存在.";
226 liveuser 13634
 
3 liveuser 13635
			#回傳結果
13636
			return $result;
226 liveuser 13637
 
3 liveuser 13638
			}#if end
13639
 
13640
		#取得檔案的bytes長度
13641
		$size  = filesize($location);
226 liveuser 13642
 
3 liveuser 13643
		#取得檔案的最後變更日期
13644
		$time  = date('r', filemtime($location));
13645
 
13646
		#讀取檔案的2元碼內容
13647
		$fm = @fopen($location, 'rb');
226 liveuser 13648
 
3 liveuser 13649
		#如果開啟檔案失敗
13650
		if(!$fm){
226 liveuser 13651
 
3 liveuser 13652
			#提示錯誤
13653
			header("HTTP/1.1 505 Internal server error");
226 liveuser 13654
 
3 liveuser 13655
			#設置執行失敗
13656
			$result["status"]="false";
226 liveuser 13657
 
3 liveuser 13658
			#設置錯誤訊息
13659
			$result["error"][]="開啟檔案 ".$location." 失敗.";
226 liveuser 13660
 
3 liveuser 13661
			#回傳結果
13662
			return $result;
226 liveuser 13663
 
3 liveuser 13664
			}#if end
13665
 
13666
		#初始化要提供的bytes長度起始點
13667
		$begin  = 0;
226 liveuser 13668
 
3 liveuser 13669
		#初始化要提供的bytes長度結束點
13670
		$end  = $size - 1;
13671
 
13672
		#如果有接收到 'HTTP_RANGE' 的 header 訊息
13673
		if(isset($_SERVER['HTTP_RANGE'])){
226 liveuser 13674
 
3 liveuser 13675
			#接收到的範例
226 liveuser 13676
			#Range: bytes=0-499
13677
 
3 liveuser 13678
			#取得要求的bytes位置範圍
13679
			sscanf($_SERVER['HTTP_RANGE'], "bytes=%d-%d",$begin,$end);
226 liveuser 13680
 
3 liveuser 13681
			#如果 $begin 或 $end  有缺
13682
			if(!isset($begin) || !isset($end)){
226 liveuser 13683
 
3 liveuser 13684
				#設置執行失敗
13685
				$result["status"]="false";
226 liveuser 13686
 
3 liveuser 13687
				#設置錯誤訊息
13688
				$result["error"][]="header \"Range\" 的數值格式為 \"bytes=0-499\"";
226 liveuser 13689
 
3 liveuser 13690
				#回傳結果
13691
				return $result;
226 liveuser 13692
 
3 liveuser 13693
				}#if end
226 liveuser 13694
 
3 liveuser 13695
			#如果 $begin 沒有小於等於 $end
13696
			if(!($begin<=$end)){
226 liveuser 13697
 
3 liveuser 13698
				#設置執行失敗
13699
				$result["status"]="false";
226 liveuser 13700
 
3 liveuser 13701
				#設置錯誤訊息
13702
				$result["error"][]="header \"Range\" 的數值格式為 \"bytes=0-499\"";
226 liveuser 13703
 
3 liveuser 13704
				#回傳結果
13705
				return $result;
226 liveuser 13706
 
3 liveuser 13707
				}#if end
226 liveuser 13708
 
3 liveuser 13709
			}#if end
226 liveuser 13710
 
3 liveuser 13711
		#提示 200 ok
13712
		header('HTTP/1.1 200 OK');
226 liveuser 13713
 
3 liveuser 13714
		#提示 mimetype
13715
		header("Content-Type: $mimetype");
226 liveuser 13716
 
3 liveuser 13717
		#要先驗證cache中的資料,取得的內容放在快取的時間為0
13718
		header('Cache-Control: public, must-revalidate, max-age=0');
226 liveuser 13719
 
3 liveuser 13720
		#提示不要cache
226 liveuser 13721
		header('Pragma: no-cache');
13722
 
3 liveuser 13723
		#提示接收的 Ranges 單位為 bytes
13724
		header('Accept-Ranges: bytes');
226 liveuser 13725
 
3 liveuser 13726
		#數值傳輸的內容長度為多少
13727
		header('Content-Length:' . (($end - $begin) + 1));
226 liveuser 13728
 
3 liveuser 13729
		#提示內容為檔案的哪邊到哪邊與總共的長度
13730
		header("Content-Range: bytes $begin-$end/$size");
226 liveuser 13731
 
3 liveuser 13732
		#提示檔案的名稱
13733
		header("Content-Disposition: inline; filename=$filename");
226 liveuser 13734
 
3 liveuser 13735
		#提示用2元碼傳輸
13736
		header("Content-Transfer-Encoding: binary");
226 liveuser 13737
 
3 liveuser 13738
		#提示檔案最後變更日期
13739
		header("Last-Modified: $time");
13740
 
13741
		#初始化當前位置
13742
		$cur  = $begin;
226 liveuser 13743
 
13744
		#指定讀取的起始點為 $begin
3 liveuser 13745
		fseek($fm, $begin, 0);
13746
 
13747
		#讀取內容, 若不是檔案結尾, 且當前位置($cur)小於等於 本次要提供的長度結尾($end), 且connection_status為0
13748
		while(!feof($fm) && $cur<=$end && (connection_status()===0)){
226 liveuser 13749
 
3 liveuser 13750
			#一次最多印出 1024*16bytes 的長度,若剩下長度不足則只印出剩下的長度.
13751
			echo fread($fm, min(1024 * 16, ($end - $cur) + 1));
226 liveuser 13752
 
3 liveuser 13753
			#更改位置
13754
			$cur += 1024 * 16;
226 liveuser 13755
 
3 liveuser 13756
			}#while end
226 liveuser 13757
 
3 liveuser 13758
		}#function partDownload end
226 liveuser 13759
 
3 liveuser 13760
	/*
13761
	#函式說明:
226 liveuser 13762
	#尋找檔案.
3 liveuser 13763
	#回傳結果:
13764
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13765
	#$result["error"],錯誤訊息.
13766
	#$result["warning"],警告訊息陣列.
13767
	#$result["function"],當前執行的函數名稱.
13768
	#$result["argu"],所使用的參數.
13769
	#$result["found"],是否有找到可以轉換的檔案,"true"代表有;"false"代表沒有.
13770
	#$result["content"],找到的檔案陣列.
13771
	#必填參數:
13772
	#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
13773
	$conf["keyWord"]="";
13774
	#$conf["path"],字串陣列,虛擬硬碟檔案的搜尋路徑,預設為當前路徑.
13775
	$conf["path"]=array();
13776
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13777
	$conf["fileArgu"]=__FILE__;
13778
	#參考資料:
13779
	#http://php.net/manual/en/function.glob.php
13780
	#備註:
13781
	#無.
13782
	*/
13783
	public static function findFile(&$conf=array()){
226 liveuser 13784
 
3 liveuser 13785
		#初始化要回傳的結果
13786
		$result=array();
13787
 
13788
		#取得當前執行的函數名稱
13789
		$result["function"]=__FUNCTION__;
13790
 
13791
		#如果沒有參數
13792
		if(func_num_args()==0){
226 liveuser 13793
 
3 liveuser 13794
			#設置執行失敗
13795
			$result["status"]="false";
226 liveuser 13796
 
3 liveuser 13797
			#設置執行錯誤訊息
13798
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 13799
 
3 liveuser 13800
			#回傳結果
13801
			return $result;
13802
 
226 liveuser 13803
			}#if end
13804
 
3 liveuser 13805
		#取得參數
13806
		$result["argu"]=$conf;
13807
 
13808
		#如果 $conf 不為陣列
13809
		if(gettype($conf)!=="array"){
226 liveuser 13810
 
3 liveuser 13811
			#設置執行失敗
13812
			$result["status"]="false";
226 liveuser 13813
 
3 liveuser 13814
			#設置執行錯誤訊息
13815
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 13816
 
3 liveuser 13817
			#如果傳入的參數為 null
13818
			if($conf===null){
226 liveuser 13819
 
3 liveuser 13820
				#設置執行錯誤訊息
13821
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 13822
 
3 liveuser 13823
				}#if end
13824
 
13825
			#回傳結果
13826
			return $result;
226 liveuser 13827
 
3 liveuser 13828
			}#if end
226 liveuser 13829
 
3 liveuser 13830
		#函式說明:
13831
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13832
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13833
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13834
		#$result["function"],當前執行的函式名稱.
13835
		#$result["argu"],設置給予的參數.
13836
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13837
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13838
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13839
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13840
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13841
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13842
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13843
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13844
		#必填寫的參數:
13845
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 13846
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 13847
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13848
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13849
		#可以省略的參數:
13850
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13851
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","keyWord","fileArgu");
13852
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13853
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
13854
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13855
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
13856
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13857
		#$conf["canNotBeEmpty"]=array();
13858
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13859
		#$conf["canBeEmpty"]=array();
13860
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13861
		#$conf["skipableVariableCanNotBeEmpty"]=array();
13862
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13863
		#$conf["skipableVariableName"]=array();
226 liveuser 13864
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 13865
		#$conf["skipableVariableType"]=array();
13866
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13867
		#$conf["skipableVarDefaultValue"]=array("");
13868
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
13869
		#$conf["disallowAllSkipableVarIsEmpty"]="";
13870
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
13871
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
13872
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13873
		#$conf["arrayCountEqualCheck"][]=array();
13874
		#參考資料來源:
13875
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13876
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
13877
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 13878
 
3 liveuser 13879
		#如果檢查參數失敗
13880
		if($checkArguments["status"]==="false"){
226 liveuser 13881
 
3 liveuser 13882
			#設置執行失敗
13883
			$result["status"]="false";
226 liveuser 13884
 
3 liveuser 13885
			#設置執行失敗訊息
13886
			$result["error"]=$checkArguments;
226 liveuser 13887
 
3 liveuser 13888
			#回傳結果
13889
			return $result;
226 liveuser 13890
 
3 liveuser 13891
			}#if end
226 liveuser 13892
 
3 liveuser 13893
		#如果檢查參數不通過
13894
		if($checkArguments["passed"]==="false"){
226 liveuser 13895
 
3 liveuser 13896
			#設置執行失敗
13897
			$result["status"]="false";
226 liveuser 13898
 
3 liveuser 13899
			#設置執行失敗訊息
13900
			$result["error"]=$checkArguments;
226 liveuser 13901
 
3 liveuser 13902
			#回傳結果
13903
			return $result;
226 liveuser 13904
 
3 liveuser 13905
			}#if end
226 liveuser 13906
 
3 liveuser 13907
		#檢查要搜尋的路徑是否都存在
13908
		#函式說明:
13909
		#s檢查多個檔案與資料夾是否存在.
13910
		#回傳的結果:
13911
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13912
		#$result["error"],錯誤訊息陣列.
13913
		#$resutl["function"],當前執行的涵式名稱.
13914
		#$result["argu"],使用的參數.
13915
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
13916
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
13917
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
13918
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
13919
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
13920
		#必填參數:
13921
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
13922
		$conf["self::checkMultiFileExist"]["fileArray"]=$conf["path"];
13923
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13924
		$conf["self::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
13925
		#可省略參數
13926
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
13927
		#$conf["disableWebSearch"]="false";
13928
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
13929
		#$conf["userDir"]="true";
13930
		#參考資料來源:
13931
		#http://php.net/manual/en/function.file-exists.php
13932
		#http://php.net/manual/en/control-structures.foreach.php
13933
		#備註:
13934
		#函數file_exists檢查的路徑為檔案系統的路徑
13935
		$checkMultiFileExist=self::checkMultiFileExist($conf["self::checkMultiFileExist"]);
13936
		unset($conf["self::checkMultiFileExist"]);
226 liveuser 13937
 
3 liveuser 13938
		#如果檢查目錄存在失敗
13939
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 13940
 
3 liveuser 13941
			#設置執行失敗
13942
			$result["status"]="false";
226 liveuser 13943
 
3 liveuser 13944
			#設置執行失敗訊息
13945
			$result["error"]=$checkMultiFileExist;
226 liveuser 13946
 
3 liveuser 13947
			#回傳結果
13948
			return $result;
226 liveuser 13949
 
13950
			}#if end
13951
 
3 liveuser 13952
		#如果目錄不存在
13953
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 13954
 
3 liveuser 13955
			#設置執行失敗
13956
			$result["status"]="false";
226 liveuser 13957
 
3 liveuser 13958
			#設置執行失敗訊息
13959
			$result["error"]=$checkMultiFileExist;
226 liveuser 13960
 
3 liveuser 13961
			#回傳結果
13962
			return $result;
226 liveuser 13963
 
3 liveuser 13964
			}#if end
226 liveuser 13965
 
3 liveuser 13966
		#如果有路徑不存在
13967
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 13968
 
3 liveuser 13969
			#設置執行失敗
13970
			$result["status"]="false";
226 liveuser 13971
 
3 liveuser 13972
			#設置執行失敗訊息
13973
			$result["error"]=$checkMultiFileExist;
226 liveuser 13974
 
3 liveuser 13975
			#設置提示有路徑不存在的訊息
13976
			$result["warning"][]="參數path的路徑沒有每個都存在";
226 liveuser 13977
 
3 liveuser 13978
			#回傳結果
13979
			return $result;
226 liveuser 13980
 
3 liveuser 13981
			}#if end
226 liveuser 13982
 
3 liveuser 13983
		#預設沒有找到檔案
226 liveuser 13984
		$result["found"]="false";
13985
 
3 liveuser 13986
		#針對每個要搜尋的路徑
13987
		foreach($conf["path"] as $path){
226 liveuser 13988
 
3 liveuser 13989
			#函式說明:
13990
			#用find指令尋找檔案
13991
			#回傳結果:
13992
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13993
			#$result["error"],錯誤訊息.
13994
			#$result["function"],當前執行的函數名稱.
13995
			#$result["argu"],所使用的參數.
13996
			#$result["found"],是否有找到符合的檔案,"true"代表有;"false"代表沒有.
13997
			#$result["content"],找到的檔案陣列.
13998
			#必填參數:
13999
			#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
226 liveuser 14000
			$conf["cmd::find"]["keyWord"]=$conf["keyWord"];
3 liveuser 14001
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14002
			$conf["cmd::find"]["fileArgu"]=$conf["fileArgu"];
14003
			#可省略參數:
14004
			#$conf["path"],字串,搜尋的路徑,預設為"/".
14005
			$conf["cmd::find"]["path"]=$path;
14006
			#$conf["fileOnly"],字串,"true"代表只要找檔案,"false"代表.
14007
			$conf["cmd::find"]["fileOnly"]="true";
14008
			#參考資料:
14009
			#http://php.net/manual/en/function.glob.php
14010
			$find=cmd::find($conf["cmd::find"]);
14011
			unset($conf["cmd::find"]);
226 liveuser 14012
 
3 liveuser 14013
			#如果尋找檔案失敗
14014
			if($find["status"]==="false"){
226 liveuser 14015
 
3 liveuser 14016
				#設置執行失敗
14017
				$result["status"]="false";
226 liveuser 14018
 
3 liveuser 14019
				#設置執行失敗訊息
14020
				$result["error"]=$find;
226 liveuser 14021
 
3 liveuser 14022
				#回傳結果
14023
				return $result;
226 liveuser 14024
 
3 liveuser 14025
				}#if end
226 liveuser 14026
 
3 liveuser 14027
			#如果有找到符合的檔案
14028
			if($find["found"]==="true"){
226 liveuser 14029
 
3 liveuser 14030
				#設置有找到檔案
14031
				$result["found"]="true";
226 liveuser 14032
 
3 liveuser 14033
				#針對每個找到的檔案
14034
				foreach($find["content"] as $filtedFile){
226 liveuser 14035
 
3 liveuser 14036
					#設置有找到的檔案
14037
					$result["content"][]=$filtedFile;
226 liveuser 14038
 
3 liveuser 14039
					}#foreach end
226 liveuser 14040
 
3 liveuser 14041
				}#if end
226 liveuser 14042
 
14043
			}#foreach end
14044
 
3 liveuser 14045
		#設置執行正常
14046
		$result["status"]="true";
226 liveuser 14047
 
3 liveuser 14048
		#回傳結果
14049
		return $result;
226 liveuser 14050
 
3 liveuser 14051
		}#function findFile end
14052
 
14053
	/*
14054
	#函式說明:
14055
	#判斷檔案位於哪個分割區
14056
	#回傳結果:
14057
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14058
	#$result["error"],錯誤訊息.
14059
	#$result["function"],當前執行的函數名稱.
14060
	#$result["argu"],所使用的參數.
14061
	#$result["content"],找到的檔案所屬分割區資訊.
14062
	#必填參數:
14063
	#$conf["file"],字串,檔案的路徑與名稱.
14064
	$conf["file"]="";
14065
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14066
	$conf["fileArgu"]=__FILE__;
14067
	#可省略參數:
14068
	#無.
14069
	#參考資料:
14070
	#無.
14071
	#備註:
14072
	#無.
14073
	*/
14074
	public static function addrInMountPoint(&$conf=array()){
226 liveuser 14075
 
3 liveuser 14076
		#初始化要回傳的結果
14077
		$result=array();
14078
 
14079
		#取得當前執行的函數名稱
14080
		$result["function"]=__FUNCTION__;
14081
 
14082
		#如果沒有參數
14083
		if(func_num_args()==0){
226 liveuser 14084
 
3 liveuser 14085
			#設置執行失敗
14086
			$result["status"]="false";
226 liveuser 14087
 
3 liveuser 14088
			#設置執行錯誤訊息
14089
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14090
 
3 liveuser 14091
			#回傳結果
14092
			return $result;
14093
 
226 liveuser 14094
			}#if end
14095
 
3 liveuser 14096
		#取得參數
14097
		$result["argu"]=$conf;
14098
 
14099
		#如果 $conf 不為陣列
14100
		if(gettype($conf)!=="array"){
226 liveuser 14101
 
3 liveuser 14102
			#設置執行失敗
14103
			$result["status"]="false";
226 liveuser 14104
 
3 liveuser 14105
			#設置執行錯誤訊息
14106
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14107
 
3 liveuser 14108
			#如果傳入的參數為 null
14109
			if($conf===null){
226 liveuser 14110
 
3 liveuser 14111
				#設置執行錯誤訊息
14112
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14113
 
3 liveuser 14114
				}#if end
14115
 
14116
			#回傳結果
14117
			return $result;
226 liveuser 14118
 
3 liveuser 14119
			}#if end
226 liveuser 14120
 
3 liveuser 14121
		#函式說明:
14122
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14123
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14124
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14125
		#$result["function"],當前執行的函式名稱.
14126
		#$result["argu"],設置給予的參數.
14127
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14128
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14129
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14130
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14131
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14132
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14133
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14134
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14135
		#必填寫的參數:
14136
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14137
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14138
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14139
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14140
		#可以省略的參數:
14141
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14142
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
14143
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14144
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
14145
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14146
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14147
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14148
		#$conf["canNotBeEmpty"]=array();
14149
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14150
		#$conf["canBeEmpty"]=array();
14151
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14152
		#$conf["skipableVariableCanNotBeEmpty"]=array();
14153
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14154
		#$conf["skipableVariableName"]=array();
226 liveuser 14155
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14156
		#$conf["skipableVariableType"]=array();
14157
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14158
		#$conf["skipableVarDefaultValue"]=array("");
14159
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14160
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14161
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14162
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14163
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14164
		#$conf["arrayCountEqualCheck"][]=array();
14165
		#參考資料來源:
14166
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14167
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14168
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14169
 
3 liveuser 14170
		#如果檢查參數失敗
14171
		if($checkArguments["status"]==="false"){
226 liveuser 14172
 
3 liveuser 14173
			#設置執行失敗
14174
			$result["status"]="false";
226 liveuser 14175
 
3 liveuser 14176
			#設置執行失敗訊息
14177
			$result["error"]=$checkArguments;
226 liveuser 14178
 
3 liveuser 14179
			#回傳結果
14180
			return $result;
226 liveuser 14181
 
3 liveuser 14182
			}#if end
226 liveuser 14183
 
3 liveuser 14184
		#如果檢查參數不通過
14185
		if($checkArguments["passed"]==="false"){
226 liveuser 14186
 
3 liveuser 14187
			#設置執行失敗
14188
			$result["status"]="false";
226 liveuser 14189
 
3 liveuser 14190
			#設置執行失敗訊息
14191
			$result["error"]=$checkArguments;
226 liveuser 14192
 
3 liveuser 14193
			#回傳結果
14194
			return $result;
226 liveuser 14195
 
3 liveuser 14196
			}#if end
226 liveuser 14197
 
3 liveuser 14198
		#函式說明:
14199
		#透過lsblk指令的輸出取得已經掛載的blk.
14200
		#回傳結果:
14201
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14202
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14203
		#$result["function"],當前執行的函式名稱.
14204
		#$result["content"],lsblk的輸出內容.
14205
		#必填參數:
14206
		#$conf["fileArgu"],字串,變數__FILE__的內容.
14207
		$conf["cmd::lsblk"]["fileArgu"]=$conf["fileArgu"];
14208
		#可省略參數:
226 liveuser 14209
		#無.
3 liveuser 14210
		$lsblk=cmd::lsblk($conf["cmd::lsblk"]);
14211
		unset($conf["cmd::lsblk"]);
226 liveuser 14212
 
3 liveuser 14213
		#如果執行失敗
14214
		if($lsblk["status"]==="false"){
226 liveuser 14215
 
3 liveuser 14216
			#設置執行失敗
14217
			$result["status"]="false";
226 liveuser 14218
 
3 liveuser 14219
			#設置執行失敗訊息
14220
			$result["error"]=$lsblk;
226 liveuser 14221
 
3 liveuser 14222
			#回傳結果
14223
			return $result;
226 liveuser 14224
 
3 liveuser 14225
			}#if end
226 liveuser 14226
 
3 liveuser 14227
		#將 $conf["file"] 轉換成絕對路徑
14228
		#函式說明:
14229
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
14230
		#回傳結果:
14231
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
14232
		#$result["error"],錯誤訊息陣列.
226 liveuser 14233
		#$result["function"],函數名稱.
3 liveuser 14234
		#$result["argu"],使用的參數.
14235
		#$result["content"],網址,若是在命令列執行,則為"null".
14236
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
14237
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
14238
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
14239
		#必填參數:
14240
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
14241
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["file"];
14242
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
14243
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
14244
		#可省略參數:
14245
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
14246
		#$conf["userDir"]="true";
14247
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
14248
		unset($conf["fileAccess::getInternetAddress"]);
226 liveuser 14249
 
3 liveuser 14250
		#如果執行失敗
14251
		if($getInternetAddress["status"]==="false"){
226 liveuser 14252
 
3 liveuser 14253
			#設置執行失敗
14254
			$result["status"]="false";
226 liveuser 14255
 
3 liveuser 14256
			#設置執行失敗訊息
14257
			$result["error"]=$getInternetAddress;
226 liveuser 14258
 
3 liveuser 14259
			#回傳結果
14260
			return $result;
226 liveuser 14261
 
14262
			}#if end
14263
 
3 liveuser 14264
		#使用絕對位置作為輸入字串
14265
		#函式說明:
14266
		#尋找字串是否存在對應的關鍵字,且符合的最常關鍵字為何?
14267
		#回傳結果:
14268
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14269
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14270
		#$result["function"],當前執行的函式名稱.
14271
		#$result["argu"],所使用的參數.
14272
		#$result["founded"],是否有找到關鍵字,"true"代表有找到,"false"代表沒有找到.
14273
		#$result["content"],最符合的字串完整內容.
14274
		#必填參數:
14275
		#$conf["input"],字串,要比對的字串陣列.
14276
		$conf["search::findLikelyStr"]["input"]=$getInternetAddress["fileSystemAbsoulutePosition"];
14277
		#$conf["keyWord"],字串陣列,要搜尋的關鍵字.
14278
		$conf["search::findLikelyStr"]["keyWord"]=$lsblk["content"]["MOUNTPOINT"];
14279
		$findLikelyStr=search::findLikelyStr($conf["search::findLikelyStr"]);
14280
		unset($conf["search::findLikelyStr"]);
226 liveuser 14281
 
3 liveuser 14282
		#如果執行失敗
14283
		if($findLikelyStr["status"]==="false"){
226 liveuser 14284
 
3 liveuser 14285
			#設置執行失敗
14286
			$result["status"]="false";
226 liveuser 14287
 
3 liveuser 14288
			#設置執行失敗訊息
14289
			$result["error"]=$findLikelyStr;
226 liveuser 14290
 
3 liveuser 14291
			#回傳結果
14292
			return $result;
226 liveuser 14293
 
3 liveuser 14294
			}#if end
226 liveuser 14295
 
3 liveuser 14296
		#如果找不到歸屬的分割區
14297
		if($findLikelyStr["found"]==="false"){
226 liveuser 14298
 
3 liveuser 14299
			#設置執行失敗
14300
			$result["status"]="false";
226 liveuser 14301
 
3 liveuser 14302
			#設置執行失敗訊息
14303
			$result["error"]=$findLikelyStr;
226 liveuser 14304
 
3 liveuser 14305
			#回傳結果
14306
			return $result;
226 liveuser 14307
 
3 liveuser 14308
			}#if end
226 liveuser 14309
 
3 liveuser 14310
		#設置歸屬的分割區資訊
14311
		$result["content"]=$findLikelyStr["content"];
226 liveuser 14312
 
3 liveuser 14313
		#設置執行正常
14314
		$result["status"]="true";
226 liveuser 14315
 
3 liveuser 14316
		#回傳結果
14317
		return $result;
226 liveuser 14318
 
3 liveuser 14319
		}#function addrInMountPoint end
14320
 
14321
	/*
14322
	#函式說明:
14323
	#取得檔案的副檔名
14324
	#回傳結果:
14325
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14326
	#$result["error"],錯誤訊息.
14327
	#$result["function"],當前執行的函數名稱.
226 liveuser 14328
	#$result["argu"],所使用的參數.
3 liveuser 14329
	#$result["content"],副檔名.
14330
	#$result["name"],不含副檔的名稱.
14331
	#$result["fullName"],含副檔的名稱.
14332
	#$result["path"],檔案所處的路徑.
14333
	#必填參數:
14334
	#$conf["file"],字串,檔案的路徑與名稱.
14335
	$conf["file"]="";
14336
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14337
	$conf["fileArgu"]=__FILE__;
14338
	#可省略參數:
14339
	#無.
14340
	#參考資料:
14341
	#無.
14342
	#備註:
14343
	#無.
14344
	*/
14345
	public static function getExtension(&$conf=array()){
226 liveuser 14346
 
3 liveuser 14347
		#初始化要回傳的結果
14348
		$result=array();
14349
 
14350
		#取得當前執行的函數名稱
14351
		$result["function"]=__FUNCTION__;
14352
 
14353
		#如果沒有參數
14354
		if(func_num_args()==0){
226 liveuser 14355
 
3 liveuser 14356
			#設置執行失敗
14357
			$result["status"]="false";
226 liveuser 14358
 
3 liveuser 14359
			#設置執行錯誤訊息
14360
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14361
 
3 liveuser 14362
			#回傳結果
14363
			return $result;
14364
 
226 liveuser 14365
			}#if end
14366
 
3 liveuser 14367
		#取得參數
14368
		$result["argu"]=$conf;
14369
 
14370
		#如果 $conf 不為陣列
14371
		if(gettype($conf)!=="array"){
226 liveuser 14372
 
3 liveuser 14373
			#設置執行失敗
14374
			$result["status"]="false";
226 liveuser 14375
 
3 liveuser 14376
			#設置執行錯誤訊息
14377
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14378
 
3 liveuser 14379
			#如果傳入的參數為 null
14380
			if($conf===null){
226 liveuser 14381
 
3 liveuser 14382
				#設置執行錯誤訊息
14383
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14384
 
3 liveuser 14385
				}#if end
14386
 
14387
			#回傳結果
14388
			return $result;
226 liveuser 14389
 
3 liveuser 14390
			}#if end
226 liveuser 14391
 
3 liveuser 14392
		#函式說明:
14393
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14394
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14395
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14396
		#$result["function"],當前執行的函式名稱.
14397
		#$result["argu"],設置給予的參數.
14398
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14399
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14400
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14401
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14402
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14403
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14404
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14405
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14406
		#必填寫的參數:
14407
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14408
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14409
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14410
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14411
		#可以省略的參數:
14412
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14413
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
14414
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14415
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
14416
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14417
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14418
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14419
		#$conf["canNotBeEmpty"]=array();
14420
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14421
		#$conf["canBeEmpty"]=array();
14422
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14423
		#$conf["skipableVariableCanNotBeEmpty"]=array();
14424
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14425
		#$conf["skipableVariableName"]=array();
226 liveuser 14426
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14427
		#$conf["skipableVariableType"]=array();
14428
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14429
		#$conf["skipableVarDefaultValue"]=array("");
14430
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14431
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14432
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14433
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14434
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14435
		#$conf["arrayCountEqualCheck"][]=array();
14436
		#參考資料來源:
14437
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14438
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14439
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14440
 
3 liveuser 14441
		#如果檢查參數失敗
14442
		if($checkArguments["status"]==="false"){
226 liveuser 14443
 
3 liveuser 14444
			#設置執行失敗
14445
			$result["status"]="false";
226 liveuser 14446
 
3 liveuser 14447
			#設置執行失敗訊息
14448
			$result["error"]=$checkArguments;
226 liveuser 14449
 
3 liveuser 14450
			#回傳結果
14451
			return $result;
226 liveuser 14452
 
3 liveuser 14453
			}#if end
226 liveuser 14454
 
3 liveuser 14455
		#如果檢查參數不通過
14456
		if($checkArguments["passed"]==="false"){
226 liveuser 14457
 
3 liveuser 14458
			#設置執行失敗
14459
			$result["status"]="false";
226 liveuser 14460
 
3 liveuser 14461
			#設置執行失敗訊息
14462
			$result["error"]=$checkArguments;
226 liveuser 14463
 
3 liveuser 14464
			#回傳結果
14465
			return $result;
226 liveuser 14466
 
3 liveuser 14467
			}#if end
226 liveuser 14468
 
3 liveuser 14469
		#初始化檔案的路徑
14470
		$result["path"]="./";
226 liveuser 14471
 
3 liveuser 14472
		#用 "/" 來分割字串
14473
		#函式說明:
14474
		#將固定格式的字串分開,並回傳分開的結果。
14475
		#回傳結果:
14476
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14477
		#$result["error"],錯誤訊息陣列
14478
		#$result["function"],當前執行的函數名稱.
14479
		#$result["oriStr"],要分割的原始字串內容
14480
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
14481
		#$result["dataCounts"],爲總共分成幾段
14482
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
14483
		#必填參數:
14484
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["file"];#要處理的字串。
14485
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
14486
		#可省略參數:
14487
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
14488
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
14489
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
14490
		unset($conf["stringProcess::spiltString"]);
226 liveuser 14491
 
3 liveuser 14492
		#如果檢查參數失敗
14493
		if($spiltString["status"]==="false"){
226 liveuser 14494
 
3 liveuser 14495
			#設置執行失敗
14496
			$result["status"]="false";
226 liveuser 14497
 
3 liveuser 14498
			#設置執行失敗訊息
14499
			$result["error"]=$spiltString;
226 liveuser 14500
 
3 liveuser 14501
			#回傳結果
14502
			return $result;
226 liveuser 14503
 
3 liveuser 14504
			}#if end
226 liveuser 14505
 
3 liveuser 14506
		#初始化含副檔名的檔案名稱
14507
		$result["fullName"]=$conf["file"];
226 liveuser 14508
 
3 liveuser 14509
		#如果有"/"存在
14510
		if($spiltString["found"]==="true"){
226 liveuser 14511
 
3 liveuser 14512
			#取得含副檔名的檔案名稱
14513
			$result["fullName"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 14514
 
3 liveuser 14515
			#取得檔案的路徑
14516
			$result["path"]=substr($conf["file"],0,strlen($conf["file"])-strlen($result["fullName"]));
226 liveuser 14517
 
3 liveuser 14518
			}#if end
226 liveuser 14519
 
3 liveuser 14520
		#用 "." 來分割字串
14521
		#函式說明:
14522
		#將固定格式的字串分開,並回傳分開的結果。
14523
		#回傳結果:
14524
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14525
		#$result["error"],錯誤訊息陣列
14526
		#$result["function"],當前執行的函數名稱.
14527
		#$result["oriStr"],要分割的原始字串內容
14528
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
14529
		#$result["dataCounts"],爲總共分成幾段
14530
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
14531
		#必填參數:
14532
		$conf["stringProcess::spiltString"]["stringIn"]=$result["fullName"];#要處理的字串。
14533
		$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
14534
		#可省略參數:
14535
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
14536
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
14537
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
14538
		unset($conf["stringProcess::spiltString"]);
226 liveuser 14539
 
3 liveuser 14540
		#如果檢查參數失敗
14541
		if($spiltString["status"]==="false"){
226 liveuser 14542
 
3 liveuser 14543
			#設置執行失敗
14544
			$result["status"]="false";
226 liveuser 14545
 
3 liveuser 14546
			#設置執行失敗訊息
14547
			$result["error"]=$spiltString;
226 liveuser 14548
 
3 liveuser 14549
			#回傳結果
14550
			return $result;
226 liveuser 14551
 
3 liveuser 14552
			}#if end
226 liveuser 14553
 
3 liveuser 14554
		#預設副檔名為 ""
14555
		$result["content"]="";
226 liveuser 14556
 
3 liveuser 14557
		#預設不含副檔名的檔案名稱
14558
		$result["name"]=$result["fullName"];
226 liveuser 14559
 
3 liveuser 14560
		#如果有"."存在
14561
		if($spiltString["found"]==="true"){
226 liveuser 14562
 
3 liveuser 14563
			#取得含副檔名
14564
			$result["content"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 14565
 
3 liveuser 14566
			#取得不含副檔名的檔案名稱
226 liveuser 14567
			$result["name"]=substr($result["fullName"],0,strlen($result["fullName"])-strlen($result["content"])-1);
14568
 
3 liveuser 14569
			}#if end
226 liveuser 14570
 
3 liveuser 14571
		#設置執行正常
14572
		$result["status"]="true";
226 liveuser 14573
 
3 liveuser 14574
		#回傳結果
14575
		return $result;
226 liveuser 14576
 
3 liveuser 14577
		}#function getExtension end
14578
 
14579
	/*
14580
	#函式說明:
14581
	#從檔案尾部開始讀取
14582
	#回傳結果:
14583
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14584
	#$result["error"],錯誤訊息.
14585
	#$result["function"],當前執行的函數名稱.
226 liveuser 14586
	#$result["argu"],所使用的參數.
3 liveuser 14587
	#$result["content"],讀取到的內容陣列.
14588
	#$result["totalLineCount"],檔案的總共行數.
14589
	#$result["lines"],取得輸出的行數.
14590
	#$result["lineNum"],取得當前行數.
14591
	#必填參數:
14592
	#$conf["file"],字串,檔案的路徑與名稱.
14593
	$conf["file"]="";
14594
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14595
	$conf["fileArgu"]=__FILE__;
14596
	#可省略參數:
14597
	#$conf["web"],字串,"true"代表位網頁系統,"false"為檔案系統,預設為"false".
14598
	#$conf["web"]="false";
14599
	#$conf["line2start"],字串,從第幾列開始,預設為總行書減去linesPerTime+1.
14600
	#$conf["line2start"]="";
14601
	#$conf["linesPerTime"],字串,一次最多讀取幾列,預設爲10列.
226 liveuser 14602
	#$conf["linesPerTime"]="10";
3 liveuser 14603
	#參考資料:
14604
	#無.
14605
	#備註:
14606
	#無.
14607
	*/
14608
	public static function tail(&$conf){
14609
 
14610
		#初始化要回傳的結果
14611
		$result=array();
14612
 
14613
		#取得當前執行的函數名稱
14614
		$result["function"]=__FUNCTION__;
14615
 
14616
		#如果沒有參數
14617
		if(func_num_args()==0){
226 liveuser 14618
 
3 liveuser 14619
			#設置執行失敗
14620
			$result["status"]="false";
226 liveuser 14621
 
3 liveuser 14622
			#設置執行錯誤訊息
14623
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14624
 
3 liveuser 14625
			#回傳結果
14626
			return $result;
14627
 
226 liveuser 14628
			}#if end
14629
 
3 liveuser 14630
		#取得參數
14631
		$result["argu"]=$conf;
14632
 
14633
		#如果 $conf 不為陣列
14634
		if(gettype($conf)!=="array"){
226 liveuser 14635
 
3 liveuser 14636
			#設置執行失敗
14637
			$result["status"]="false";
226 liveuser 14638
 
3 liveuser 14639
			#設置執行錯誤訊息
14640
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14641
 
3 liveuser 14642
			#如果傳入的參數為 null
14643
			if($conf===null){
226 liveuser 14644
 
3 liveuser 14645
				#設置執行錯誤訊息
14646
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14647
 
3 liveuser 14648
				}#if end
14649
 
14650
			#回傳結果
14651
			return $result;
226 liveuser 14652
 
3 liveuser 14653
			}#if end
226 liveuser 14654
 
3 liveuser 14655
		#函式說明:
14656
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14657
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14658
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14659
		#$result["function"],當前執行的函式名稱.
14660
		#$result["argu"],設置給予的參數.
14661
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14662
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14663
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14664
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14665
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14666
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14667
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14668
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14669
		#必填寫的參數:
14670
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14671
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14672
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14673
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14674
		#可以省略的參數:
14675
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14676
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
14677
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14678
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
14679
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14680
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14681
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14682
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file","fileArgu");
14683
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14684
		#$conf["canBeEmpty"]=array();
14685
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14686
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web","line2start","linesPerTime");
14687
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14688
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web","line2start","linesPerTime");
226 liveuser 14689
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14690
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
14691
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14692
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,"10");
14693
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14694
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14695
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14696
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14697
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14698
		#$conf["arrayCountEqualCheck"][]=array();
14699
		#參考資料來源:
14700
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14701
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14702
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14703
 
3 liveuser 14704
		#如果檢查參數失敗
14705
		if($checkArguments["status"]==="false"){
226 liveuser 14706
 
3 liveuser 14707
			#設置執行失敗
14708
			$result["status"]="false";
226 liveuser 14709
 
3 liveuser 14710
			#設置執行失敗訊息
14711
			$result["error"]=$checkArguments;
226 liveuser 14712
 
3 liveuser 14713
			#回傳結果
14714
			return $result;
226 liveuser 14715
 
3 liveuser 14716
			}#if end
226 liveuser 14717
 
3 liveuser 14718
		#如果檢查參數不通過
14719
		if($checkArguments["passed"]==="false"){
226 liveuser 14720
 
3 liveuser 14721
			#設置執行失敗
14722
			$result["status"]="false";
226 liveuser 14723
 
3 liveuser 14724
			#設置執行失敗訊息
14725
			$result["error"]=$checkArguments;
226 liveuser 14726
 
3 liveuser 14727
			#回傳結果
14728
			return $result;
226 liveuser 14729
 
3 liveuser 14730
			}#if end
14731
 
14732
		#檢查檔案是否存在
14733
		#函式說明:
14734
		#檢查多個檔案與資料夾是否存在.
14735
		#回傳的結果:
14736
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
14737
		#$result["error"],錯誤訊息陣列.
14738
		#$resutl["function"],當前執行的涵式名稱.
14739
		#$result["argu"],使用的參數.
14740
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
14741
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
14742
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
14743
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
14744
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
14745
		#必填參數:
14746
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
14747
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
14748
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14749
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
14750
		#可省略參數
14751
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
14752
		#$conf["disableWebSearch"]="false";
14753
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
14754
		#$conf["userDir"]="true";
14755
		#$conf["web"],字串,"true"代表位網頁系統,"false"為檔案系統,預設為"false".
14756
		$conf["fileAccess::checkMultiFileExist"]["web"]=$conf["web"];
14757
		#參考資料來源:
14758
		#http://php.net/manual/en/function.file-exists.php
14759
		#http://php.net/manual/en/control-structures.foreach.php
14760
		#備註:
14761
		#函數file_exists檢查的路徑為檔案系統的路徑
14762
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
14763
		unset($conf["fileAccess::checkMultiFileExist"]);
14764
 
14765
		#如果執行失敗
14766
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 14767
 
3 liveuser 14768
			#設置執行失敗
14769
			$result["status"]="false";
226 liveuser 14770
 
3 liveuser 14771
			#設置執行失敗訊息
14772
			$result["error"]=$checkMultiFileExist;
226 liveuser 14773
 
3 liveuser 14774
			#回傳結果
14775
			return $result;
226 liveuser 14776
 
3 liveuser 14777
			}#if end
226 liveuser 14778
 
3 liveuser 14779
		#如果檔案無法存取
14780
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 14781
 
3 liveuser 14782
			#設置執行失敗
14783
			$result["status"]="false";
226 liveuser 14784
 
3 liveuser 14785
			#設置執行失敗訊息
14786
			$result["error"]=$checkMultiFileExist;
226 liveuser 14787
 
3 liveuser 14788
			#回傳結果
14789
			return $result;
226 liveuser 14790
 
3 liveuser 14791
			}#if end
14792
 
14793
		#取得檔案的行數
14794
		#函式說明:
14795
		#呼叫shell執行系統命令,並取得回傳的內容.
14796
		#回傳的結果:
14797
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14798
		#$result["error"],錯誤訊息陣列.
14799
		#$result["function"],當前執行的函數名稱.
14800
		#$result["argu"],使用的參數.
14801
		#$result["cmd"],執行的指令內容.
14802
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14803
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14804
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14805
		#$result["running"],是否還在執行.
14806
		#$result["pid"],pid.
14807
		#$result["statusCode"],執行結束後的代碼.
14808
		#必填的參數
14809
		#$conf["command"],字串,要執行的指令與.
14810
		$conf["external::callShell"]["command"]="cat";
14811
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 14812
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 14813
		#可省略參數:
14814
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14815
		$conf["external::callShell"]["argu"]=array($conf["file"],"|","wc","-l");
14816
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 14817
		#$conf["arguIsAddr"]=array();
3 liveuser 14818
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14819
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14820
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14821
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14822
		#$conf["enablePrintDescription"]="true";
14823
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14824
		#$conf["printDescription"]="";
14825
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
14826
		$conf["external::callShell"]["escapeshellarg"]="true";
14827
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14828
		#$conf["username"]="";
14829
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14830
		#$conf["password"]="";
14831
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14832
		#$conf["useScript"]="";
14833
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14834
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14835
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14836
		#$conf["inBackGround"]="";
14837
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
14838
		#$conf["getErr"]="false";
14839
		#備註:
14840
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14841
		#參考資料:
14842
		#exec=>http://php.net/manual/en/function.exec.php
14843
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14844
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14845
		$callShell=external::callShell($conf["external::callShell"]);
14846
		unset($conf["external::callShell"]);
14847
 
14848
		#如果檢查參數失敗
14849
		if($callShell["status"]==="false"){
226 liveuser 14850
 
3 liveuser 14851
			#設置執行失敗
14852
			$result["status"]="false";
226 liveuser 14853
 
3 liveuser 14854
			#設置執行失敗訊息
14855
			$result["error"]=$callShell;
226 liveuser 14856
 
3 liveuser 14857
			#回傳結果
14858
			return $result;
226 liveuser 14859
 
3 liveuser 14860
			}#if end
226 liveuser 14861
 
3 liveuser 14862
		#取得檔案總行數
14863
		$result["totalLineCount"]=$callShell["output"][0];
226 liveuser 14864
 
3 liveuser 14865
		#如果未設置 $conf["line2start"]
14866
		if(!isset($conf["line2start"])){
226 liveuser 14867
 
3 liveuser 14868
			#$conf["line2start"]為總行數減去一次要看的行數減1
14869
			$conf["line2start"]=$result["totalLineCount"]-$conf["linesPerTime"]+1;
226 liveuser 14870
 
14871
			}#if end
14872
 
14873
		#如果開始行數小於1
3 liveuser 14874
		if($conf["line2start"]<1){
226 liveuser 14875
 
3 liveuser 14876
			#$conf["line2start"]為總行數減去一次要看的行數減1
14877
			$conf["line2start"]=$result["totalLineCount"]-$conf["linesPerTime"]+1;
226 liveuser 14878
 
3 liveuser 14879
			}#if end
226 liveuser 14880
 
14881
		#如果開始行數小於1
3 liveuser 14882
		if($conf["line2start"]<1){
226 liveuser 14883
 
3 liveuser 14884
			#$conf["line2start"]為1
14885
			$conf["line2start"]=1;
226 liveuser 14886
 
3 liveuser 14887
			}#if end
226 liveuser 14888
 
3 liveuser 14889
		#取得指定範圍的行數
14890
		#取得檔案的行數
14891
		#函式說明:
14892
		#呼叫shell執行系統命令,並取得回傳的內容.
14893
		#回傳的結果:
14894
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14895
		#$result["error"],錯誤訊息陣列.
14896
		#$result["function"],當前執行的函數名稱.
14897
		#$result["argu"],使用的參數.
14898
		#$result["cmd"],執行的指令內容.
14899
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14900
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14901
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14902
		#$result["running"],是否還在執行.
14903
		#$result["pid"],pid.
14904
		#$result["statusCode"],執行結束後的代碼.
14905
		#必填的參數
14906
		#$conf["command"],字串,要執行的指令與.
14907
		$conf["external::callShell"]["command"]="sed";
14908
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 14909
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 14910
		#可省略參數:
14911
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14912
		$conf["external::callShell"]["argu"]=array("-n",$conf["line2start"].",".($conf["line2start"]+$conf["linesPerTime"]-1)."p",$conf["file"]);
14913
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 14914
		#$conf["arguIsAddr"]=array();
3 liveuser 14915
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14916
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14917
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14918
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14919
		#$conf["enablePrintDescription"]="true";
14920
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14921
		#$conf["printDescription"]="";
14922
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
14923
		$conf["external::callShell"]["escapeshellarg"]="true";
14924
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14925
		#$conf["username"]="";
14926
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14927
		#$conf["password"]="";
14928
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14929
		#$conf["useScript"]="";
14930
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14931
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14932
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14933
		#$conf["inBackGround"]="";
14934
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
14935
		#$conf["getErr"]="false";
14936
		#備註:
14937
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14938
		#參考資料:
14939
		#exec=>http://php.net/manual/en/function.exec.php
14940
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14941
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14942
		$callShell=external::callShell($conf["external::callShell"]);
14943
		unset($conf["external::callShell"]);
14944
 
14945
		#如果檢查參數失敗
14946
		if($callShell["status"]==="false"){
226 liveuser 14947
 
3 liveuser 14948
			#設置執行失敗
14949
			$result["status"]="false";
226 liveuser 14950
 
3 liveuser 14951
			#設置執行失敗訊息
14952
			$result["error"]=$callShell;
226 liveuser 14953
 
3 liveuser 14954
			#回傳結果
14955
			return $result;
226 liveuser 14956
 
3 liveuser 14957
			}#if end
14958
 
14959
		#取得輸出的行數
14960
		$result["lines"]=count($callShell["output"]);
14961
 
14962
		#取得目前的輸出內容
14963
		$result["content"]=$callShell["output"];
14964
 
14965
		#取得當前行數
14966
		$result["lineNum"]=$conf["line2start"]+$result["lines"]-1;
14967
 
226 liveuser 14968
		#如果當前行號小於總行數
3 liveuser 14969
		if($result["lineNum"]<$result["totalLineCount"]){
14970
 
14971
			#設置還有剩餘的內容
14972
			$result["left"]="true";
226 liveuser 14973
 
3 liveuser 14974
			}#if end
14975
 
226 liveuser 14976
		#反之
3 liveuser 14977
		else{
14978
 
14979
			#設置無剩餘的內容
14980
			$result["left"]="false";
14981
 
14982
			}#else end
14983
 
14984
		#設置執行正常
14985
		$result["status"]="true";
14986
 
14987
		#回傳結果
14988
		return $result;
14989
 
14990
		}#function tail end
226 liveuser 14991
 
3 liveuser 14992
	/*
14993
	#函式說明:
14994
	#解析PHP檔案裡面的變數.
14995
	#回傳結果:
14996
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14997
	#$result["error"],錯誤訊息.
14998
	#$result["function"],當前執行的函數名稱.
226 liveuser 14999
	#$result["argu"],所使用的參數.
3 liveuser 15000
	#$result["content"],找到的變數內容陣列,若有多個變數則會用array來表示.
15001
	#必填參數:
15002
	#$conf["file"],字串,檔案的路徑與名稱.
15003
	$conf["file"]="";
15004
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
15005
	$conf["fileArgu"]=__FILE__;
15006
	#$conf["varName"],字串陣列,要搜尋的變數名稱,例如要搜尋變數$email則輸入"email".
15007
	$conf["varName"]=array();
15008
	#可省略參數:
15009
	#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false",預設為"false".
15010
	#$conf["web"]="true";
255 liveuser 15011
	#$conf["allVarCountSame"],字串,是否每個參數的數量要一致,預設為"false"不要;反之為"true"代表要.
15012
	#$conf["allVarCountSame"]="false";
3 liveuser 15013
	#參考資料:
15014
	#https://www.php.net/manual/en/function.parse-str.php
15015
	#備註:
15016
	#無.
15017
	*/
15018
	public static function parseVaraiableInPHPfile(&$conf){
226 liveuser 15019
 
3 liveuser 15020
		#初始化要回傳的結果
15021
		$result=array();
15022
 
15023
		#取得當前執行的函數名稱
15024
		$result["function"]=__FUNCTION__;
15025
 
15026
		#如果沒有參數
15027
		if(func_num_args()==0){
226 liveuser 15028
 
3 liveuser 15029
			#設置執行失敗
15030
			$result["status"]="false";
226 liveuser 15031
 
3 liveuser 15032
			#設置執行錯誤訊息
15033
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 15034
 
3 liveuser 15035
			#回傳結果
15036
			return $result;
15037
 
226 liveuser 15038
			}#if end
15039
 
3 liveuser 15040
		#取得參數
15041
		$result["argu"]=$conf;
15042
 
15043
		#如果 $conf 不為陣列
15044
		if(gettype($conf)!=="array"){
226 liveuser 15045
 
3 liveuser 15046
			#設置執行失敗
15047
			$result["status"]="false";
226 liveuser 15048
 
3 liveuser 15049
			#設置執行錯誤訊息
15050
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 15051
 
3 liveuser 15052
			#如果傳入的參數為 null
15053
			if($conf===null){
226 liveuser 15054
 
3 liveuser 15055
				#設置執行錯誤訊息
15056
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 15057
 
3 liveuser 15058
				}#if end
15059
 
15060
			#回傳結果
15061
			return $result;
226 liveuser 15062
 
3 liveuser 15063
			}#if end
226 liveuser 15064
 
3 liveuser 15065
		#函式說明:
15066
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
15067
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15068
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15069
		#$result["function"],當前執行的函式名稱.
15070
		#$result["argu"],設置給予的參數.
15071
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15072
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15073
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15074
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15075
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15076
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15077
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15078
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15079
		#必填寫的參數:
15080
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 15081
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 15082
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15083
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15084
		#可以省略的參數:
15085
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15086
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu","varName");
15087
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15088
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
15089
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15090
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15091
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15092
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file","fileArgu","varName");
15093
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15094
		#$conf["canBeEmpty"]=array();
15095
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
255 liveuser 15096
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web","allVarCountSame");
3 liveuser 15097
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
255 liveuser 15098
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web","allVarCountSame");
226 liveuser 15099
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
255 liveuser 15100
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
3 liveuser 15101
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 15102
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
3 liveuser 15103
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15104
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15105
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15106
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15107
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15108
		#$conf["arrayCountEqualCheck"][]=array();
15109
		#參考資料來源:
15110
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15111
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15112
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15113
 
3 liveuser 15114
		#如果檢查參數失敗
15115
		if($checkArguments["status"]==="false"){
226 liveuser 15116
 
3 liveuser 15117
			#設置執行失敗
15118
			$result["status"]="false";
226 liveuser 15119
 
3 liveuser 15120
			#設置執行失敗訊息
15121
			$result["error"]=$checkArguments;
226 liveuser 15122
 
3 liveuser 15123
			#回傳結果
15124
			return $result;
226 liveuser 15125
 
3 liveuser 15126
			}#if end
226 liveuser 15127
 
3 liveuser 15128
		#如果檢查參數不通過
15129
		if($checkArguments["passed"]==="false"){
226 liveuser 15130
 
3 liveuser 15131
			#設置執行失敗
15132
			$result["status"]="false";
226 liveuser 15133
 
3 liveuser 15134
			#設置執行失敗訊息
15135
			$result["error"]=$checkArguments;
226 liveuser 15136
 
3 liveuser 15137
			#回傳結果
15138
			return $result;
226 liveuser 15139
 
3 liveuser 15140
			}#if end
226 liveuser 15141
 
3 liveuser 15142
		#初始化儲存解析出來的變數內容
15143
		$result["content"]=array();
226 liveuser 15144
 
3 liveuser 15145
		#讀取檔案
15146
		#函式說明:
15147
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
15148
		#回傳的變數說明:
15149
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
15150
		#$result["error"],錯誤訊息提示.
15151
		#$result["warning"],警告訊息.
15152
		#$result["function"],當前執行的函數名稱.
15153
		#$result["fileContent"],爲檔案的內容陣列.
15154
		#$result["lineCount"],爲檔案內容總共的行數.
15155
		#$result["fullContent"],為檔案的完整內容.
15156
		#$result["base64data"],為檔案的base64內容.
15157
		#$result["mimeType"],為檔案的mime type.
15158
		#必填參數:
15159
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
15160
		$conf["ileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
15161
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
15162
		$conf["ileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
15163
		#可省略參數:
15164
		#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
15165
		$conf["ileAccess::getFileContent"]["web"]=$conf["web"];
15166
		#參考資料:
15167
		#file(),取得檔案內容的行數.
15168
		#file=>http:#php.net/manual/en/function.file.php
15169
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
15170
		#filesize=>http://php.net/manual/en/function.filesize.php
15171
		$getFileContent=fileAccess::getFileContent($conf["ileAccess::getFileContent"]);
15172
		unset($conf["ileAccess::getFileContent"]);
15173
 
15174
		#如果讀取檔案失敗
15175
		if($getFileContent["status"]==="false"){
226 liveuser 15176
 
3 liveuser 15177
			#設置執行失敗
15178
			$result["status"]="false";
226 liveuser 15179
 
3 liveuser 15180
			#設置執行失敗訊息
15181
			$result["error"]=$getFileContent;
226 liveuser 15182
 
3 liveuser 15183
			#回傳結果
15184
			return $result;
226 liveuser 15185
 
3 liveuser 15186
			}#if end
226 liveuser 15187
 
3 liveuser 15188
		#針對每列檔案內容
15189
		foreach($getFileContent["fileContent"] as $line){
226 liveuser 15190
 
3 liveuser 15191
			#針對每個要搜尋的變數
15192
			foreach($conf["varName"] as $keyWord){
226 liveuser 15193
 
3 liveuser 15194
				#如果關鍵字小於被搜尋的字串長度
15195
				if( strlen($line) < strlen($keyWord)+1 ){
226 liveuser 15196
 
3 liveuser 15197
					#跳過
15198
					continue;
226 liveuser 15199
 
3 liveuser 15200
					}#if end
226 liveuser 15201
 
3 liveuser 15202
				#函式說明:
15203
				#取得符合特定字首與字尾的字串
15204
				#回傳結果:
15205
				#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
15206
				#$result["function"],當前執行的函數名稱.
15207
				#$result["error"],錯誤訊息陣列.
15208
				#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
15209
				#$result["returnString"],爲符合字首條件的字串內容。
15210
				#$result["argu"],使用的參數.
15211
				#必填參數:
15212
				#$conf["checkString"],字串,要檢查的字串.
15213
				$conf["search::getMeetConditionsString"]["checkString"]=$line;
15214
				#可省略參數:
15215
				#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
15216
				$conf["search::getMeetConditionsString"]["frontWord"]="$".$keyWord;
15217
				#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
15218
				$conf["search::getMeetConditionsString"]["tailWord"]=";";
15219
				#參考資料:
15220
				#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
15221
				$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
15222
				unset($conf["search::getMeetConditionsString"]);
226 liveuser 15223
 
3 liveuser 15224
				#如果失敗
15225
				if($getMeetConditionsString["status"]==="false"){
15226
 
15227
					#設置執行失敗
15228
					$result["status"]="false";
226 liveuser 15229
 
3 liveuser 15230
					#設置執行失敗訊息
15231
					$result["error"]=$getMeetConditionsString;
226 liveuser 15232
 
3 liveuser 15233
					#回傳結果
15234
					return $result;
226 liveuser 15235
 
15236
					}#if end
15237
 
3 liveuser 15238
				#如果有找到關鍵字
15239
				if($getMeetConditionsString["founded"]==="true"){
226 liveuser 15240
 
3 liveuser 15241
					#剔除變數名稱
15242
					#函式說明:
15243
					#將字串特定關鍵字與其前面的內容剔除
15244
					#回傳結果:
15245
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15246
					#$result["error"],錯誤訊息陣列.
15247
					#$result["warning"],警告訊息鎮列.
15248
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
15249
					#$result["function"],當前執行的函數名稱.
15250
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 15251
					#$result["content"],處理好的的字串內容.
3 liveuser 15252
					#必填參數:
15253
					#$conf["stringIn"],字串,要處理的字串.
15254
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$line;
15255
					#$conf["keyWord"],字串,特定字串.
15256
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="$".$keyWord;
15257
					#可省略參數:
15258
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,直到沒有關鍵字為止.
15259
					#$conf["recursive"]="true";
15260
					#參考資料:
15261
					#無.
15262
					#備註:
15263
					#無.
15264
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
15265
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 15266
 
3 liveuser 15267
					#如果執行失敗
15268
					if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 15269
 
3 liveuser 15270
						#設置執行失敗
15271
						$result["status"]="false";
226 liveuser 15272
 
3 liveuser 15273
						#設置執行失敗訊息
15274
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15275
 
3 liveuser 15276
						#回傳結果
15277
						return $result;
226 liveuser 15278
 
3 liveuser 15279
						}#if end
226 liveuser 15280
 
3 liveuser 15281
					#如果沒有找到應該存在的php變數
15282
					if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 15283
 
3 liveuser 15284
						#設置執行失敗
15285
						$result["status"]="false";
226 liveuser 15286
 
3 liveuser 15287
						#設置執行失敗訊息
15288
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15289
 
3 liveuser 15290
						#回傳結果
15291
						return $result;
226 liveuser 15292
 
3 liveuser 15293
						}#if end
226 liveuser 15294
 
3 liveuser 15295
					#剔除 "=" 前面的內容
15296
					#函式說明:
15297
					#將字串特定關鍵字與其前面的內容剔除
15298
					#回傳結果:
15299
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15300
					#$result["error"],錯誤訊息陣列.
15301
					#$result["warning"],警告訊息鎮列.
15302
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
15303
					#$result["function"],當前執行的函數名稱.
15304
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 15305
					#$result["content"],處理好的的字串內容.
3 liveuser 15306
					#必填參數:
15307
					#$conf["stringIn"],字串,要處理的字串.
15308
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
15309
					#$conf["keyWord"],字串,特定字串.
15310
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="=";
15311
					#可省略參數:
15312
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,直到沒有關鍵字為止.
15313
					#$conf["recursive"]="true";
15314
					#參考資料:
15315
					#無.
15316
					#備註:
15317
					#無.
15318
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
15319
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 15320
 
3 liveuser 15321
					#如果執行失敗
15322
					if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 15323
 
3 liveuser 15324
						#設置執行失敗
15325
						$result["status"]="false";
226 liveuser 15326
 
3 liveuser 15327
						#設置執行失敗訊息
15328
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15329
 
3 liveuser 15330
						#回傳結果
15331
						return $result;
226 liveuser 15332
 
3 liveuser 15333
						}#if end
226 liveuser 15334
 
3 liveuser 15335
					#如果沒有找“=”關鍵字
15336
					if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 15337
 
3 liveuser 15338
						#跳過
15339
						continue;
226 liveuser 15340
 
3 liveuser 15341
						}#if end
226 liveuser 15342
 
3 liveuser 15343
					#剔除 value 前面的空白
15344
					#函式說明:
288 liveuser 15345
					#移除字串開頭的特定內容
3 liveuser 15346
					#回傳結果:
288 liveuser 15347
					#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
3 liveuser 15348
					#$result["error"],錯誤訊息陣列.
288 liveuser 15349
					#$result["function"],當前執行的函數.
15350
					#$result["content"],處理好的字串.
15351
					#$result["argu"],使用的參數.
3 liveuser 15352
					#必填參數:
288 liveuser 15353
					#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
15354
					$conf["stringProcess::delKeyWordsInStrHead"]["inputStr"]=$delStrBeforeKeyWord["content"];
15355
					#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
15356
					$conf["stringProcess::delKeyWordsInStrHead"]["keyWord"]=" ";
3 liveuser 15357
					#可省略參數:
288 liveuser 15358
					#$conf["recursive"],字串,"true"代表要遞迴移除開頭的關鍵字,預設為"false",只移除開頭關鍵字1次.
15359
					$conf["stringProcess::delKeyWordsInStrHead"]["recursive"]="true";
3 liveuser 15360
					#參考資料:
15361
					#無.
15362
					#備註:
15363
					#無.
288 liveuser 15364
					$delKeyWordsInStrHead=stringProcess::delKeyWordsInStrHead($conf["stringProcess::delKeyWordsInStrHead"]);
15365
					unset($conf["stringProcess::delKeyWordsInStrHead"]);
226 liveuser 15366
 
3 liveuser 15367
					#如果執行失敗
288 liveuser 15368
					if($delKeyWordsInStrHead["status"]==="false"){
226 liveuser 15369
 
3 liveuser 15370
						#設置執行失敗
15371
						$result["status"]="false";
226 liveuser 15372
 
3 liveuser 15373
						#設置執行失敗訊息
288 liveuser 15374
						$result["error"]=$delKeyWordsInStrHead;
226 liveuser 15375
 
3 liveuser 15376
						#回傳結果
15377
						return $result;
226 liveuser 15378
 
3 liveuser 15379
						}#if end
226 liveuser 15380
 
316 liveuser 15381
					#取得找到的變數的語法
15382
					$phpCode="\$result[\"content\"][\"".$keyWord."\"][]=".$delKeyWordsInStrHead["content"];
15383
 
3 liveuser 15384
					#取得找到的變數
316 liveuser 15385
					eval($phpCode);
226 liveuser 15386
 
3 liveuser 15387
					}#if end
226 liveuser 15388
 
3 liveuser 15389
				}#foreach end
226 liveuser 15390
 
3 liveuser 15391
			}#foreach end
226 liveuser 15392
 
255 liveuser 15393
		#如果 allVarCountSame 設置為 "true"
15394
		if($conf["allVarCountSame"]==="true"){
15395
 
15396
			#每個變數的數量初始為0
15397
			$count=0;
15398
 
15399
			#針對每個解析出來的變數
15400
			foreach($conf["varName"] as $varName){
15401
 
15402
				#取得該變數數量
15403
				$varCount=count($result["content"][$varName]);
15404
 
15405
				#如果尚無變數數量資料
15406
				if($count===0){
15407
 
15408
					#直接儲存之
15409
					$count=$varCount;
15410
 
15411
					#看下一個變數
15412
					continue;
15413
 
15414
					}#if end
15415
 
15416
				#如果變數數量不一樣
15417
				if($count!==$varCount){
15418
 
15419
					#設置執行失敗
15420
					$result["status"]="false";
15421
 
15422
					#設置執行失敗訊息
15423
					$result["error"]="config file error";
15424
 
15425
					#回傳結果
15426
					return $result;
15427
 
15428
					}#if end
15429
 
15430
				}#foreach end
15431
 
15432
			}#if end
15433
 
3 liveuser 15434
		#設置執行正常
15435
		$result["status"]="true";
226 liveuser 15436
 
3 liveuser 15437
		#回傳結果
15438
		return $result;
226 liveuser 15439
 
3 liveuser 15440
		}#function parseVaraiableInPHPfile end
15441
 
15442
	/*
15443
	#函式說明:
15444
	#開啟特定目錄,取得底下的檔案路徑清單.
15445
	#回傳結果:
15446
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15447
	#$result["error"],錯誤訊息.
15448
	#$result["function"],當前執行的函數名稱.
15449
	#$result["argu"],所使用的參數.
15450
	#$result["content"],讀取到的內容陣列.
15451
	#$result["content"][$i],第$i+1個結果.
15452
	#$result["content"][$i]["name"],第$i+1個名稱.
15453
	#$result["content"][$i]["dir"],第$i+1個檔案是否為資料夾.
15454
	#$result["content"][$i]["info"],第$i+1個檔案的額外資訊.
15455
	#$result["content"][$i]["size"],第$i+1個檔案的大小(bytes).
15456
	#必填參數:
15457
	#$conf["path"],字串,要取得檔案資訊的所屬路徑.
15458
	$conf["path"]="";
15459
	#可省略參數:
15460
	#無.
15461
	#參考資料
15462
	#無.
15463
	#備註:
15464
	#無.
15465
	*/
15466
	public static function listInfo(&$conf){
226 liveuser 15467
 
3 liveuser 15468
		#初始化要回傳的結果
15469
		$result=array();
15470
 
15471
		#取得當前執行的函數名稱
15472
		$result["function"]=__FUNCTION__;
15473
 
15474
		#如果沒有參數
15475
		if(func_num_args()==0){
226 liveuser 15476
 
3 liveuser 15477
			#設置執行失敗
15478
			$result["status"]="false";
226 liveuser 15479
 
3 liveuser 15480
			#設置執行錯誤訊息
15481
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 15482
 
3 liveuser 15483
			#回傳結果
15484
			return $result;
15485
 
226 liveuser 15486
			}#if end
15487
 
3 liveuser 15488
		#取得參數
15489
		$result["argu"]=$conf;
15490
 
15491
		#如果 $conf 不為陣列
15492
		if(gettype($conf)!=="array"){
226 liveuser 15493
 
3 liveuser 15494
			#設置執行失敗
15495
			$result["status"]="false";
226 liveuser 15496
 
3 liveuser 15497
			#設置執行錯誤訊息
15498
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 15499
 
3 liveuser 15500
			#如果傳入的參數為 null
15501
			if($conf===null){
226 liveuser 15502
 
3 liveuser 15503
				#設置執行錯誤訊息
15504
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 15505
 
3 liveuser 15506
				}#if end
15507
 
15508
			#回傳結果
15509
			return $result;
226 liveuser 15510
 
3 liveuser 15511
			}#if end
226 liveuser 15512
 
3 liveuser 15513
		#函式說明:
15514
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
15515
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15516
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15517
		#$result["function"],當前執行的函式名稱.
15518
		#$result["argu"],設置給予的參數.
15519
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15520
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15521
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15522
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15523
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15524
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15525
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15526
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15527
		#必填寫的參數:
15528
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 15529
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 15530
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15531
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15532
		#可以省略的參數:
15533
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15534
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
15535
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15536
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
15537
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15538
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15539
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15540
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
15541
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15542
		#$conf["canBeEmpty"]=array();
15543
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
15544
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
15545
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
15546
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 15547
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 15548
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
15549
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
15550
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
15551
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15552
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15553
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15554
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15555
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15556
		#$conf["arrayCountEqualCheck"][]=array();
15557
		#參考資料來源:
15558
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15559
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15560
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15561
 
3 liveuser 15562
		#如果檢查參數失敗
15563
		if($checkArguments["status"]==="false"){
226 liveuser 15564
 
3 liveuser 15565
			#設置執行失敗
15566
			$result["status"]="false";
226 liveuser 15567
 
3 liveuser 15568
			#設置執行失敗訊息
15569
			$result["error"]=$checkArguments;
226 liveuser 15570
 
3 liveuser 15571
			#回傳結果
15572
			return $result;
226 liveuser 15573
 
3 liveuser 15574
			}#if end
226 liveuser 15575
 
3 liveuser 15576
		#如果檢查參數不通過
15577
		if($checkArguments["passed"]==="false"){
226 liveuser 15578
 
3 liveuser 15579
			#設置執行失敗
15580
			$result["status"]="false";
226 liveuser 15581
 
3 liveuser 15582
			#設置執行失敗訊息
15583
			$result["error"]=$checkArguments;
226 liveuser 15584
 
3 liveuser 15585
			#回傳結果
15586
			return $result;
226 liveuser 15587
 
3 liveuser 15588
			}#if end
226 liveuser 15589
 
3 liveuser 15590
		#初始化儲存解析出來的變數內容
15591
		$result["content"]=array();
226 liveuser 15592
 
3 liveuser 15593
		#取得特定位置的資訊
15594
		$pathInfo=@dir($conf["path"]);
226 liveuser 15595
 
3 liveuser 15596
		#如果取得路徑資訊失敗
15597
		if($pathInfo===false){
226 liveuser 15598
 
3 liveuser 15599
			#設置執行失敗
15600
			$result["status"]="false";
226 liveuser 15601
 
3 liveuser 15602
			#設置執行失敗訊息
15603
			$result["error"][]="無法存取路徑(".$conf["path"].")";
226 liveuser 15604
 
3 liveuser 15605
			#回傳結果
15606
			return $result;
226 liveuser 15607
 
3 liveuser 15608
			}#if end
226 liveuser 15609
 
3 liveuser 15610
		#讀取底下一個檔案,暫存到 $tmpItem 裡面,且當結果不為 false 時進入迴圈.
15611
		while(false !== $tmpItem = $pathInfo->read()){
226 liveuser 15612
 
3 liveuser 15613
			#宣告儲存資訊的變數
15614
			$item=array();
226 liveuser 15615
 
3 liveuser 15616
			#儲存名稱
15617
			$item["name"]=$tmpItem;
226 liveuser 15618
 
3 liveuser 15619
			#預設不為資料夾
15620
			$item["dir"]="false";
226 liveuser 15621
 
3 liveuser 15622
			#若為資料夾
15623
			if(is_dir($conf["path"]."/".$tmpItem)){
226 liveuser 15624
 
3 liveuser 15625
				#設置為"true"
15626
				$item["dir"]="true";
226 liveuser 15627
 
3 liveuser 15628
				}#if end
226 liveuser 15629
 
3 liveuser 15630
			#取得檔案識別器
15631
			$finfo = finfo_open(FILEINFO_MIME);
226 liveuser 15632
 
3 liveuser 15633
			#取得 info
15634
			$item["info"]=@finfo_file($finfo,$conf["path"]."/".$tmpItem);
15635
 
15636
			#取得檔案大小
15637
			$item["size"]=filesize($conf["path"]."/".$tmpItem);
15638
 
15639
			#close connection
15640
			finfo_close($finfo);
226 liveuser 15641
 
3 liveuser 15642
			#記錄該檔案資訊
15643
			$result["content"][]=$item;
226 liveuser 15644
 
3 liveuser 15645
			}#while end
226 liveuser 15646
 
3 liveuser 15647
		#設置執行正常
15648
		$result["status"]="true";
226 liveuser 15649
 
3 liveuser 15650
		#回傳結果
15651
		return $result;
226 liveuser 15652
 
3 liveuser 15653
		}#function listInfo end
15654
 
15655
	/*
15656
	#函式說明:
15657
	#取得目錄底下的詳細資訊.
15658
	#回傳結果:
15659
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15660
	#$result["error"],錯誤訊息.
15661
	#$result["function"],當前執行的函數名稱.
15662
	#$result["size"],該清單的大小,單位為bytes.
15663
	#$result["dataCount"],該清單的長度.
15664
	#$result["path"],字串,檢視的路徑,必為"/"結尾.
15665
	#$result["content"],指定目錄底下的所有檔案資訊.
15666
	#$result["content"][$i]["nType&permission"],第$i個節點類型、權限.
15667
	#$result["content"][$i]["nType"],第$i個節點類型,"-"代表檔案,"d"代表資料夾.
15668
	#$result["content"][$i]["permission"],第$i個節點權限.
15669
	#$result["content"][$i]["ownByUser"],第$i個節點擁有者賬號.
15670
	#$result["content"][$i]["ownByGroup"],第$i個節點擁有者群組.
15671
	#$result["content"][$i]["bytes"],第$i個節點大小.
15672
	#$result["content"][$i]["date"],第$i個節點最後變更日期.
15673
	#$result["content"][$i]["time"],第$i個節點最後異動時間.
15674
	#$result["content"][$i]["timeDetail"],第$i個節點最後異動詳細時間.
15675
	#$result["content"][$i]["timezone"],第$i個節點的時區.
15676
	#$result["content"][$i]["name"],第$i個節點的名稱.
15677
	#$result["content"][$i]["secondName"],第$i個節點為檔案時,若有附檔名,會記錄在這.
15678
	#$result["content"][$i]["mimeType"],第$i個節點為檔案且可以讀取時,會有 mime type 可取得.
15679
	#必填參數:
15680
	#$conf["path"],字串,要檢視的路徑,若非"/"結尾,會自動補上.
15681
	$conf["path"]="";
15682
	#可省略參數:
15683
	#無.
15684
	#參考資料:
15685
	#https://www.businessweekly.com.tw/careers/Blog/14307
15686
	#備註:
15687
	#無.
15688
	*/
15689
	public static function ls(&$conf){
226 liveuser 15690
 
3 liveuser 15691
		#初始化要回傳的結果
15692
		$result=array();
15693
 
15694
		#取得當前執行的函數名稱
15695
		$result["function"]=__FUNCTION__;
15696
 
15697
		#如果沒有參數
15698
		if(func_num_args()==0){
15699
 
15700
			#設置執行失敗
15701
			$result["status"]="false";
15702
 
15703
			#設置執行錯誤訊息
15704
			$result["error"]="函數".$result["function"]."需要參數";
15705
 
15706
			#回傳結果
15707
			return $result;
15708
 
15709
			}#if end
15710
 
15711
		#取得參數
15712
		$result["argu"]=$conf;
15713
 
15714
		#如果 $conf 不為陣列
15715
		if(gettype($conf)!=="array"){
15716
 
15717
			#設置執行失敗
15718
			$result["status"]="false";
15719
 
15720
			#設置執行錯誤訊息
15721
			$result["error"][]="\$conf變數須為陣列形態";
15722
 
15723
			#如果傳入的參數為 null
15724
			if(is_null($conf)){
15725
 
15726
				#設置執行錯誤訊息
15727
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
15728
 
15729
				}#if end
15730
 
15731
			#回傳結果
15732
			return $result;
15733
 
15734
			}#if end
226 liveuser 15735
 
3 liveuser 15736
		#函式說明:
15737
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
15738
		#回傳結果:
15739
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15740
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15741
		#$result["simpleError"],簡單表示的錯誤訊息.
15742
		#$result["function"],當前執行的函式名稱.
15743
		#$result["argu"],設置給予的參數.
15744
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15745
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15746
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15747
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15748
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15749
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15750
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15751
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15752
		#必填參數:
15753
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
15754
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
15755
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15756
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15757
		#可省略參數:
15758
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15759
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
15760
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15761
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
15762
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15763
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15764
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15765
		#$conf["canNotBeEmpty"]=array();
15766
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15767
		#$conf["canBeEmpty"]=array();
15768
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
15769
		#$conf["skipableVariableCanNotBeEmpty"]=array();
15770
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
15771
		#$conf["skipableVariableName"]=array();
15772
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
15773
		#$conf["skipableVariableType"]=array();
15774
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
15775
		#$conf["skipableVarDefaultValue"]=array("");
15776
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15777
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15778
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15779
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15780
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15781
		#$conf["arrayCountEqualCheck"][]=array();
15782
		#參考資料:
15783
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15784
		#備註:
15785
		#無.
15786
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15787
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15788
 
3 liveuser 15789
		#如果執行失敗
15790
		if($checkArguments["status"]==="false"){
226 liveuser 15791
 
3 liveuser 15792
			#設置執行錯誤
15793
			$result["status"]="false";
226 liveuser 15794
 
3 liveuser 15795
			#設置錯誤訊息
15796
			$result["error"]=$checkArguments;
226 liveuser 15797
 
3 liveuser 15798
			#回傳結果
15799
			return $result;
226 liveuser 15800
 
3 liveuser 15801
			}#if end
226 liveuser 15802
 
3 liveuser 15803
		#如果參數檢查不通過
15804
		if($checkArguments["passed"]==="false"){
226 liveuser 15805
 
3 liveuser 15806
			#設置執行錯誤
15807
			$result["status"]="false";
226 liveuser 15808
 
3 liveuser 15809
			#設置錯誤訊息
15810
			$result["error"]=$checkArguments;
226 liveuser 15811
 
3 liveuser 15812
			#回傳結果
15813
			return $result;
226 liveuser 15814
 
3 liveuser 15815
			}#if end
226 liveuser 15816
 
3 liveuser 15817
		#確認 $conf["path"] 是否為 "/" 結尾
15818
		#函式說明:
15819
		#取得符合特定字首與字尾的字串
15820
		#回傳結果:
15821
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
15822
		#$result["function"],當前執行的函數名稱.
15823
		#$result["error"],錯誤訊息陣列.
15824
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
15825
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
15826
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
15827
		#$result["argu"],使用的參數.
15828
		#必填參數:
15829
		#$conf["checkString"],字串,要檢查的字串.
15830
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["path"];
15831
		#可省略參數:
15832
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
15833
		#$conf["frontWord"]="";
15834
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
15835
		$conf["search::getMeetConditionsString"]["tailWord"]="/";
15836
		#參考資料:
15837
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
15838
		#備註:
15839
		#無.
15840
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
15841
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 15842
 
3 liveuser 15843
		#如果執行失敗
15844
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 15845
 
3 liveuser 15846
			#設置執行錯誤
15847
			$result["status"]="false";
226 liveuser 15848
 
3 liveuser 15849
			#設置錯誤訊息
15850
			$result["error"]=$getMeetConditionsString;
226 liveuser 15851
 
3 liveuser 15852
			#回傳結果
15853
			return $result;
226 liveuser 15854
 
3 liveuser 15855
			}#if end
226 liveuser 15856
 
3 liveuser 15857
		#如果沒有 "/" 結尾
15858
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 15859
 
3 liveuser 15860
			#於結尾加上 "/"
15861
			$conf["path"]=$conf["path"]."/";
226 liveuser 15862
 
3 liveuser 15863
			}#if end
226 liveuser 15864
 
3 liveuser 15865
		#記錄真正的路徑
15866
		$result["path"]=$conf["path"];
226 liveuser 15867
 
3 liveuser 15868
		#函式說明:
15869
		#呼叫shell執行系統命令,並取得回傳的內容.
15870
		#回傳結果:
15871
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15872
		#$result["error"],錯誤訊息陣列.
15873
		#$result["function"],當前執行的函數名稱.
15874
		#$result["argu"],使用的參數.
15875
		#$result["cmd"],執行的指令內容.
15876
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15877
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15878
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15879
		#$result["running"],是否還在執行.
15880
		#$result["pid"],pid.
15881
		#$result["statusCode"],執行結束後的代碼.
15882
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
15883
		#必填參數:
15884
		#$conf["command"],字串,要執行的指令.
15885
		$conf["external::callShell"]["command"]="ls";
15886
		#$conf["fileArgu"],字串,變數__FILE__的內容.
15887
		$conf["external::callShell"]["fileArgu"]=__FILE__;
15888
		#可省略參數:
15889
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15890
		$conf["external::callShell"]["argu"]=array("-al","--full-time","-t","-B",$conf["path"]);
15891
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
15892
		#$conf["arguIsAddr"]=array();
15893
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15894
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15895
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15896
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15897
		#$conf["enablePrintDescription"]="true";
15898
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15899
		#$conf["printDescription"]="";
15900
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
15901
		$conf["external::callShell"]["escapeshellarg"]="true";
15902
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
15903
		#$conf["thereIsShellVar"]=array();
15904
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15905
		#$conf["username"]="";
15906
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15907
		#$conf["password"]="";
15908
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15909
		#$conf["useScript"]="";
15910
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15911
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15912
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15913
		#$conf["inBackGround"]="";
15914
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
15915
		#$conf["getErr"]="false";
15916
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
15917
		#$conf["doNotRun"]="false";
15918
		#參考資料:
15919
		#exec=>http://php.net/manual/en/function.exec.php
15920
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15921
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15922
		#備註:
15923
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15924
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
15925
		$callShell=external::callShell($conf["external::callShell"]);
15926
		unset($conf["external::callShell"]);
226 liveuser 15927
 
3 liveuser 15928
		#debug
15929
		#var_dump(__FILE__,__LINE__,$callShell);
226 liveuser 15930
 
3 liveuser 15931
		#如果執行失敗
15932
		if($callShell["status"]==="false"){
226 liveuser 15933
 
3 liveuser 15934
			#設置執行錯誤
15935
			$result["status"]="false";
226 liveuser 15936
 
3 liveuser 15937
			#設置錯誤訊息
15938
			$result["error"]=$callShell;
226 liveuser 15939
 
3 liveuser 15940
			#回傳結果
15941
			return $result;
226 liveuser 15942
 
3 liveuser 15943
			}#if end
226 liveuser 15944
 
3 liveuser 15945
		#初始化儲存檔案資訊為空
15946
		$result["content"]=array();
226 liveuser 15947
 
3 liveuser 15948
		#針對每行輸出
15949
		foreach($callShell["output"] as $index=>$line){
226 liveuser 15950
 
3 liveuser 15951
			#如果是第一筆
15952
			if($index===0){
226 liveuser 15953
 
3 liveuser 15954
				#取得資料筆數
15955
				$result["dataCount"]=explode(" ",$line)[0];
226 liveuser 15956
 
3 liveuser 15957
				#換下一輪
15958
				continue;
226 liveuser 15959
 
3 liveuser 15960
				}#if end
226 liveuser 15961
 
3 liveuser 15962
			#函式說明:
15963
			#將固定格式的字串分開,並回傳分開的結果.
15964
			#回傳結果:
15965
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15966
			#$result["error"],錯誤訊息陣列
15967
			#$result["function"],當前執行的函數名稱.
15968
			#$result["argu"],使用的參數.
15969
			#$result["oriStr"],要分割的原始字串內容
15970
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
15971
			#$result["dataCounts"],爲總共分成幾段
15972
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
15973
			#必填參數:
15974
			#$conf["stringIn"],字串,要處理的字串.
15975
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
15976
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
15977
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
15978
			#可省略參數:
15979
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
15980
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
15981
			#參考資料:
15982
			#無.
15983
			#備註:
15984
			#無.
15985
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
15986
			unset($conf["stringProcess::spiltString"]);
226 liveuser 15987
 
3 liveuser 15988
			#如果執行失敗
15989
			if($spiltString["status"]==="false"){
226 liveuser 15990
 
3 liveuser 15991
				#設置執行錯誤
15992
				$result["status"]="false";
226 liveuser 15993
 
3 liveuser 15994
				#設置錯誤訊息
15995
				$result["error"]=$spiltString;
226 liveuser 15996
 
3 liveuser 15997
				#回傳結果
15998
				return $result;
226 liveuser 15999
 
3 liveuser 16000
				}#if end
226 liveuser 16001
 
3 liveuser 16002
			#如果沒有分割用的" "
16003
			if($spiltString["found"]==="false"){
226 liveuser 16004
 
3 liveuser 16005
				#設置執行錯誤
16006
				$result["status"]="false";
226 liveuser 16007
 
3 liveuser 16008
				#設置錯誤訊息
16009
				$result["error"]=$spiltString;
226 liveuser 16010
 
3 liveuser 16011
				#回傳結果
16012
				return $result;
226 liveuser 16013
 
3 liveuser 16014
				}#if end
226 liveuser 16015
 
3 liveuser 16016
			#如果分割好的數量小於8
16017
			if($spiltString["dataCounts"]<8){
226 liveuser 16018
 
3 liveuser 16019
				#設置執行錯誤
16020
				$result["status"]="false";
226 liveuser 16021
 
3 liveuser 16022
				#設置錯誤訊息
16023
				$result["error"]=$spiltString;
226 liveuser 16024
 
3 liveuser 16025
				#回傳結果
16026
				return $result;
226 liveuser 16027
 
3 liveuser 16028
				}#if end
226 liveuser 16029
 
3 liveuser 16030
			#初始化要儲存的檔案資訊陣列
16031
			$fileInfo=array();
226 liveuser 16032
 
3 liveuser 16033
			#取得 節點類型、權限
16034
			$fileInfo["nType&permission"]=$spiltString["dataArray"][0];
226 liveuser 16035
 
3 liveuser 16036
			#剔除結尾的 "."
16037
			$fileInfo["nType&permission"]=substr($fileInfo["nType&permission"],0,strlen($fileInfo["nType&permission"])-1);
226 liveuser 16038
 
3 liveuser 16039
			#取得節點類型
16040
			$fileInfo["nType"]=$fileInfo["nType&permission"][0];
226 liveuser 16041
 
3 liveuser 16042
			#取得節點權限
16043
			$fileInfo["permission"]=substr($fileInfo["nType&permission"],1);
226 liveuser 16044
 
3 liveuser 16045
			#取得擁有者賬號
16046
			$fileInfo["ownByUser"]=$spiltString["dataArray"][2];
226 liveuser 16047
 
3 liveuser 16048
			#取得群組擁有者群組
16049
			$fileInfo["ownByGroup"]=$spiltString["dataArray"][3];
226 liveuser 16050
 
3 liveuser 16051
			#取得size
16052
			$fileInfo["bytes"]=$spiltString["dataArray"][4];
226 liveuser 16053
 
16054
			#取得最後異動日期
3 liveuser 16055
			$fileInfo["date"]=$spiltString["dataArray"][5];
226 liveuser 16056
 
3 liveuser 16057
			#取得最後異動時間
16058
			$fileInfo["time"]=explode(".",$spiltString["dataArray"][6])[0];
226 liveuser 16059
 
3 liveuser 16060
			#取得最後異動的詳細時間
16061
			$fileInfo["timeDetail"]=$spiltString["dataArray"][6];
226 liveuser 16062
 
3 liveuser 16063
			#取得timezone資訊
16064
			$fileInfo["timezone"]=$spiltString["dataArray"][7];
226 liveuser 16065
 
3 liveuser 16066
			#函式說明:
16067
			#將固定格式的字串分開,並回傳分開的結果.
16068
			#回傳結果:
16069
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16070
			#$result["error"],錯誤訊息陣列
16071
			#$result["function"],當前執行的函數名稱.
16072
			#$result["argu"],使用的參數.
16073
			#$result["oriStr"],要分割的原始字串內容
16074
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
16075
			#$result["dataCounts"],爲總共分成幾段
16076
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
16077
			#必填參數:
16078
			#$conf["stringIn"],字串,要處理的字串.
16079
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
16080
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
16081
			$conf["stringProcess::spiltString"]["spiltSymbol"]=$fileInfo["date"]." ".$fileInfo["timeDetail"]." ".$fileInfo["timezone"];
16082
			#可省略參數:
16083
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
16084
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
16085
			#參考資料:
16086
			#無.
16087
			#備註:
16088
			#無.
16089
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
16090
			unset($conf["stringProcess::spiltString"]);
226 liveuser 16091
 
3 liveuser 16092
			#如果執行失敗
16093
			if($spiltString["status"]==="false"){
226 liveuser 16094
 
3 liveuser 16095
				#設置執行錯誤
16096
				$result["status"]="false";
226 liveuser 16097
 
3 liveuser 16098
				#設置錯誤訊息
16099
				$result["error"]=$spiltString;
226 liveuser 16100
 
3 liveuser 16101
				#回傳結果
16102
				return $result;
226 liveuser 16103
 
3 liveuser 16104
				}#if end
226 liveuser 16105
 
3 liveuser 16106
			#如果沒有分割用的" "
16107
			if($spiltString["found"]==="false"){
226 liveuser 16108
 
3 liveuser 16109
				#設置執行錯誤
16110
				$result["status"]="false";
226 liveuser 16111
 
3 liveuser 16112
				#設置錯誤訊息
16113
				$result["error"]=$spiltString;
226 liveuser 16114
 
3 liveuser 16115
				#回傳結果
16116
				return $result;
226 liveuser 16117
 
3 liveuser 16118
				}#if end
226 liveuser 16119
 
3 liveuser 16120
			#如果分割好的數量小於8
16121
			if($spiltString["dataCounts"]<2){
226 liveuser 16122
 
3 liveuser 16123
				#設置執行錯誤
16124
				$result["status"]="false";
226 liveuser 16125
 
3 liveuser 16126
				#設置錯誤訊息
16127
				$result["error"]=$spiltString;
226 liveuser 16128
 
3 liveuser 16129
				#回傳結果
16130
				return $result;
226 liveuser 16131
 
3 liveuser 16132
				}#if end
226 liveuser 16133
 
3 liveuser 16134
			#取得節點名稱,剔除開頭的空白.
16135
			$fileInfo["name"]=substr($spiltString["dataArray"][1],1);
226 liveuser 16136
 
3 liveuser 16137
			#排除 "." 跟 ".."
16138
			if($fileInfo["name"]==="." || $fileInfo["name"]===".."){
226 liveuser 16139
 
3 liveuser 16140
				#跳過
16141
				continue;
226 liveuser 16142
 
3 liveuser 16143
				}#if end
226 liveuser 16144
 
3 liveuser 16145
			#如果是檔案
16146
			if($fileInfo["nType"]==="-"){
226 liveuser 16147
 
3 liveuser 16148
				#取得mime type
16149
				$fileInfo["mimeType"]=@mime_content_type($conf["path"].$fileInfo["name"]);
226 liveuser 16150
 
3 liveuser 16151
				#如果讀取失敗
16152
				if($fileInfo["mimeType"]===false){
226 liveuser 16153
 
3 liveuser 16154
					#通常為沒有權限
226 liveuser 16155
 
3 liveuser 16156
					#跳過該檔案
16157
					continue;
226 liveuser 16158
 
3 liveuser 16159
					}#if end
226 liveuser 16160
 
3 liveuser 16161
				#確認檔案名稱中間含是否有 "."
16162
				#函式說明:
16163
				#取得關鍵字在字串的哪個位置(字首,字尾,中間)
16164
				#回傳結果:
16165
				#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
16166
				#$result["error"],錯誤訊息陣列.
16167
				#$result["function"],當前執行的函數名稱.
16168
				#$result["found"],是否有關鍵字存在,若為"true",代表存在;反之為"false".
16169
				#$result["argu"],傳入的參數.
16170
				#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
16171
				#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
16172
				#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
16173
				#$result["indexS"],關鍵字在被搜尋字串的哪個位置開始.
16174
				#$result["indexE"],關鍵字在被搜尋字串的哪個位置結束.
16175
				#必填參數:
16176
				#$conf["inputStr"],字串,被搜尋的字串.
16177
				$conf["search::findKeyWordPosition"]["inputStr"]=$fileInfo["name"];
16178
				#$conf["keyWord"],字串,關鍵字.
16179
				$conf["search::findKeyWordPosition"]["keyWord"]=".";
16180
				#可省略參數:
16181
				#無.
16182
				#參考資料:
16183
				#http://php.net/manual/en/function.strpos.php
16184
				#備註:
16185
				#無.
16186
				$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
16187
				unset($conf["search::findKeyWordPosition"]);
226 liveuser 16188
 
3 liveuser 16189
				#如果執行失敗
16190
				if($findKeyWordPosition["status"]==="false"){
226 liveuser 16191
 
3 liveuser 16192
					#設置執行錯誤
16193
					$result["status"]="false";
226 liveuser 16194
 
3 liveuser 16195
					#設置錯誤訊息
16196
					$result["error"]=$spiltString;
226 liveuser 16197
 
3 liveuser 16198
					#回傳結果
16199
					return $result;
226 liveuser 16200
 
3 liveuser 16201
					}#if end
226 liveuser 16202
 
3 liveuser 16203
				#如果含有 "." 存在
16204
				if($findKeyWordPosition["found"]==="true"){
226 liveuser 16205
 
3 liveuser 16206
					#如果 "." 是在中間,不是在尾巴.
16207
					if($findKeyWordPosition["center"]==="true" && $findKeyWordPosition["tail"]==="false"){
226 liveuser 16208
 
3 liveuser 16209
						#取得 "." 之後的內容
16210
						#函式說明:
16211
						#將字串特定關鍵字與其前面的內容剔除
16212
						#回傳結果:
16213
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16214
						#$result["error"],錯誤訊息陣列.
16215
						#$result["warning"],警告訊息鎮列.
16216
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
16217
						#$result["function"],當前執行的函數名稱.
16218
						#$result["argu"],使用的參數.
16219
						#$result["oriStr"],要處理的原始字串內容.
16220
						#$result["content"],處理好的的字串內容.
16221
						#$result["deleted"],被移除的內容.
16222
						#必填參數:
16223
						#$conf["stringIn"],字串,要處理的字串.
16224
						$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$fileInfo["name"];
16225
						#$conf["keyWord"],字串,特定字串.
16226
						$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=".";
16227
						#可省略參數:
16228
						#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
16229
						$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
16230
						#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
16231
						#$conf["lastResult"]=$delStrBeforeKeyWord;
16232
						#參考資料:
16233
						#無.
16234
						#備註:
16235
						#無.
16236
						$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
16237
						unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 16238
 
3 liveuser 16239
						#如果執行失敗
16240
						if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 16241
 
3 liveuser 16242
							#設置執行錯誤
16243
							$result["status"]="false";
226 liveuser 16244
 
3 liveuser 16245
							#設置錯誤訊息
16246
							$result["error"]=$spiltString;
226 liveuser 16247
 
3 liveuser 16248
							#回傳結果
16249
							return $result;
226 liveuser 16250
 
3 liveuser 16251
							}#if end
226 liveuser 16252
 
3 liveuser 16253
						#如果該存在的 "." 不存在
16254
						if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 16255
 
3 liveuser 16256
							#設置執行錯誤
16257
							$result["status"]="false";
226 liveuser 16258
 
3 liveuser 16259
							#設置錯誤訊息
16260
							$result["error"]=$spiltString;
226 liveuser 16261
 
3 liveuser 16262
							#回傳結果
16263
							return $result;
226 liveuser 16264
 
3 liveuser 16265
							}#if end
226 liveuser 16266
 
3 liveuser 16267
						#取得附檔名
16268
						$fileInfo["secondName"]=$delStrBeforeKeyWord["content"];
226 liveuser 16269
 
3 liveuser 16270
						}#if end
226 liveuser 16271
 
3 liveuser 16272
					}#if end
226 liveuser 16273
 
3 liveuser 16274
				}#if end
226 liveuser 16275
 
3 liveuser 16276
			#儲存檔案資訊
16277
			$result["content"][]=$fileInfo;
226 liveuser 16278
 
3 liveuser 16279
			}#foreach end
226 liveuser 16280
 
3 liveuser 16281
		#設置清單的長度
16282
		$result["dataCount"]=count($result["content"]);
226 liveuser 16283
 
3 liveuser 16284
		#設置執行正常
16285
		$result["status"]="true";
226 liveuser 16286
 
3 liveuser 16287
		#回傳結果
16288
		return $result;
226 liveuser 16289
 
3 liveuser 16290
		}#function ls end
16291
 
16292
	/*
16293
	#函式說明:
16294
	#將 ~ 轉換為家目錄路徑
16295
	#回傳結果:
16296
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16297
	#$result["error"],錯誤訊息.
16298
	#$result["function"],當前執行的函數名稱.
16299
	#$result["content"],轉換好的內容.
16300
	#必填參數:
16301
	#$conf["fileArgu"],字串,變數__FILE__的內容.
16302
	$conf["fileArgu"]=__FILE__;
16303
	#可省略參數:
16304
	#無.
16305
	#參考資料:
16306
	#https://www.businessweekly.com.tw/careers/Blog/14307
16307
	#備註:
16308
	#無.
16309
	*/
16310
	public static function tildeToPath(&$conf){
226 liveuser 16311
 
3 liveuser 16312
		#初始化要回傳的結果
16313
		$result=array();
16314
 
16315
		#取得當前執行的函數名稱
16316
		$result["function"]=__FUNCTION__;
16317
 
16318
		#如果沒有參數
16319
		if(func_num_args()==0){
226 liveuser 16320
 
3 liveuser 16321
			#設置執行失敗
16322
			$result["status"]="false";
226 liveuser 16323
 
3 liveuser 16324
			#設置執行錯誤訊息
16325
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 16326
 
3 liveuser 16327
			#回傳結果
16328
			return $result;
226 liveuser 16329
 
220 liveuser 16330
			}#if end
3 liveuser 16331
 
16332
		#取得參數
16333
		$result["argu"]=$conf;
16334
 
16335
		#如果 $conf 不為陣列
16336
		if(gettype($conf)!=="array"){
226 liveuser 16337
 
3 liveuser 16338
			#設置執行失敗
16339
			$result["status"]="false";
226 liveuser 16340
 
3 liveuser 16341
			#設置執行錯誤訊息
16342
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 16343
 
3 liveuser 16344
			#如果傳入的參數為 null
16345
			if($conf===null){
226 liveuser 16346
 
3 liveuser 16347
				#設置執行錯誤訊息
16348
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 16349
 
3 liveuser 16350
				}#if end
16351
 
16352
			#回傳結果
16353
			return $result;
226 liveuser 16354
 
3 liveuser 16355
			}#if end
226 liveuser 16356
 
3 liveuser 16357
		#函式說明:
16358
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
16359
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16360
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
16361
		#$result["function"],當前執行的函式名稱.
16362
		#$result["argu"],設置給予的參數.
16363
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
16364
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
16365
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
16366
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
16367
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
16368
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
16369
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
16370
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
16371
		#必填寫的參數:
16372
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 16373
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 16374
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
16375
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
16376
		#可以省略的參數:
16377
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
16378
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
16379
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
16380
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
16381
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
16382
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
16383
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
16384
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
16385
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
16386
		#$conf["canBeEmpty"]=array();
16387
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
16388
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
16389
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
16390
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 16391
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 16392
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
16393
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
16394
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
16395
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
16396
		#$conf["disallowAllSkipableVarIsEmpty"]="";
16397
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
16398
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
16399
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
16400
		#$conf["arrayCountEqualCheck"][]=array();
16401
		#參考資料來源:
16402
		#array_keys=>http://php.net/manual/en/function.array-keys.php
16403
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
16404
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 16405
 
3 liveuser 16406
		#如果檢查參數失敗
16407
		if($checkArguments["status"]==="false"){
226 liveuser 16408
 
3 liveuser 16409
			#設置執行失敗
16410
			$result["status"]="false";
226 liveuser 16411
 
3 liveuser 16412
			#設置執行失敗訊息
16413
			$result["error"]=$checkArguments;
226 liveuser 16414
 
3 liveuser 16415
			#回傳結果
16416
			return $result;
226 liveuser 16417
 
3 liveuser 16418
			}#if end
226 liveuser 16419
 
3 liveuser 16420
		#如果檢查參數不通過
16421
		if($checkArguments["passed"]==="false"){
226 liveuser 16422
 
3 liveuser 16423
			#設置執行失敗
16424
			$result["status"]="false";
226 liveuser 16425
 
3 liveuser 16426
			#設置執行失敗訊息
16427
			$result["error"]=$checkArguments;
226 liveuser 16428
 
3 liveuser 16429
			#回傳結果
16430
			return $result;
226 liveuser 16431
 
3 liveuser 16432
			}#if end
16433
 
16434
		#函式說明:
16435
		#呼叫shell執行系統命令,並取得回傳的內容.
16436
		#回傳結果:
16437
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16438
		#$result["error"],錯誤訊息陣列.
16439
		#$result["function"],當前執行的函數名稱.
16440
		#$result["argu"],使用的參數.
16441
		#$result["cmd"],執行的指令內容.
16442
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16443
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16444
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16445
		#$result["running"],是否還在執行.
16446
		#$result["pid"],pid.
16447
		#$result["statusCode"],執行結束後的代碼.
16448
		#必填參數:
16449
		#$conf["command"],字串,要執行的指令與.
16450
		$conf["external::callShell"]["command"]="echo";
16451
		#$conf["fileArgu"],字串,變數__FILE__的內容.
16452
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16453
		#可省略參數:
16454
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16455
		$conf["external::callShell"]["argu"]=array("~");
16456
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16457
		#$conf["arguIsAddr"]=array();
16458
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16459
		#$conf["plainArgu"]=array();
16460
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16461
		#$conf["useApostrophe"]=array();
16462
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16463
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16464
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16465
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16466
		#$conf["enablePrintDescription"]="true";
16467
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16468
		#$conf["printDescription"]="";
16469
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16470
		$conf["external::callShell"]["escapeshellarg"]="true";
16471
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16472
		#$conf["thereIsShellVar"]=array();
16473
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16474
		#$conf["username"]="";
16475
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16476
		#$conf["password"]="";
16477
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16478
		#$conf["useScript"]="";
16479
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16480
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16481
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16482
		#$conf["inBackGround"]="";
16483
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16484
		#$conf["getErr"]="false";
16485
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16486
		#$conf["doNotRun"]="false";
16487
		#參考資料:
16488
		#exec=>http://php.net/manual/en/function.exec.php
16489
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16490
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16491
		#備註:
16492
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16493
		$callShell=external::callShell($conf["external::callShell"]);
16494
		unset($conf["external::callShell"]);
16495
 
16496
		#如果執行失敗
16497
		if($callShell["status"]==="false"){
226 liveuser 16498
 
3 liveuser 16499
			#設置執行失敗
16500
			$result["status"]="false";
226 liveuser 16501
 
3 liveuser 16502
			#設置執行失敗訊息
16503
			$result["error"]=$callShell;
226 liveuser 16504
 
3 liveuser 16505
			#回傳結果
16506
			return $result;
226 liveuser 16507
 
3 liveuser 16508
			}#if end
226 liveuser 16509
 
3 liveuser 16510
		#如果沒有預期的輸出
16511
		if(!isset($callShell["output"][0])){
226 liveuser 16512
 
3 liveuser 16513
			#設置執行失敗
16514
			$result["status"]="false";
226 liveuser 16515
 
3 liveuser 16516
			#設置執行失敗訊息
16517
			$result["error"][]="沒有得到預期的輸出";
226 liveuser 16518
 
3 liveuser 16519
			#設置執行失敗訊息
16520
			$result["error"][]=$callShell;
226 liveuser 16521
 
3 liveuser 16522
			#回傳結果
16523
			return $result;
226 liveuser 16524
 
3 liveuser 16525
			}#if end
226 liveuser 16526
 
3 liveuser 16527
		#取得輸出
16528
		$result["content"]=$callShell["output"][0];
226 liveuser 16529
 
3 liveuser 16530
		#設置執行正常
16531
		$result["status"]="true";
226 liveuser 16532
 
3 liveuser 16533
		#回傳結果
16534
		return $result;
226 liveuser 16535
 
3 liveuser 16536
		}#function tildeToPath end
16537
 
16538
	/*
16539
	#函式說明:
16540
	#建立軟連結.
16541
	#回傳結果:
16542
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16543
	#$result["error"],錯誤訊息.
16544
	#$result["function"],當前執行的函數名稱.
16545
	#$result["content"],軟連結的資訊.
16546
	#$result["cmd"],執行的指令陣列.
16547
	#必填參數:
16548
	#$conf["fileArgu"],字串,變數__FILE__的內容.
16549
	$conf["fileArgu"]=__FILE__;
16550
	#$conf["linkTo"],字串,軟連結要指向哪邊.
16551
	$conf["linkTo"]="";
16552
	#可省略參數:
16553
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
16554
	#$conf["path"]="";
16555
	#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
16556
	#$conf["name"]="";
16557
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
16558
	#$conf["overWrite"]="true";
16559
	#參考資料:
16560
	#無.
16561
	#備註:
16562
	#無.
16563
	*/
16564
	public static function createLink(&$conf){
226 liveuser 16565
 
3 liveuser 16566
		#初始化要回傳的結果
16567
		$result=array();
16568
 
16569
		#取得當前執行的函數名稱
16570
		$result["function"]=__FUNCTION__;
16571
 
16572
		#如果沒有參數
16573
		if(func_num_args()==0){
226 liveuser 16574
 
3 liveuser 16575
			#設置執行失敗
16576
			$result["status"]="false";
226 liveuser 16577
 
3 liveuser 16578
			#設置執行錯誤訊息
16579
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 16580
 
3 liveuser 16581
			#回傳結果
16582
			return $result;
226 liveuser 16583
 
220 liveuser 16584
			}#if end
3 liveuser 16585
 
16586
		#取得參數
16587
		$result["argu"]=$conf;
16588
 
16589
		#如果 $conf 不為陣列
16590
		if(gettype($conf)!=="array"){
226 liveuser 16591
 
3 liveuser 16592
			#設置執行失敗
16593
			$result["status"]="false";
226 liveuser 16594
 
3 liveuser 16595
			#設置執行錯誤訊息
16596
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 16597
 
3 liveuser 16598
			#如果傳入的參數為 null
16599
			if($conf===null){
226 liveuser 16600
 
3 liveuser 16601
				#設置執行錯誤訊息
16602
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 16603
 
3 liveuser 16604
				}#if end
16605
 
16606
			#回傳結果
16607
			return $result;
226 liveuser 16608
 
3 liveuser 16609
			}#if end
226 liveuser 16610
 
3 liveuser 16611
		#函式說明:
16612
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
16613
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16614
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
16615
		#$result["function"],當前執行的函式名稱.
16616
		#$result["argu"],設置給予的參數.
16617
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
16618
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
16619
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
16620
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
16621
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
16622
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
16623
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
16624
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
16625
		#必填寫的參數:
16626
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 16627
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 16628
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
16629
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
16630
		#可以省略的參數:
16631
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
16632
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkTo");
16633
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
16634
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
16635
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
16636
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
16637
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
16638
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
16639
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
16640
		#$conf["canBeEmpty"]=array();
16641
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
16642
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","name","overWrite");
16643
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
16644
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","name","overWrite");
226 liveuser 16645
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 16646
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
16647
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
16648
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false");
16649
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
16650
		#$conf["disallowAllSkipableVarIsEmpty"]="";
16651
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
16652
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
16653
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
16654
		#$conf["arrayCountEqualCheck"][]=array();
16655
		#參考資料來源:
16656
		#array_keys=>http://php.net/manual/en/function.array-keys.php
16657
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
16658
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 16659
 
3 liveuser 16660
		#如果檢查參數失敗
16661
		if($checkArguments["status"]==="false"){
226 liveuser 16662
 
3 liveuser 16663
			#設置執行失敗
16664
			$result["status"]="false";
226 liveuser 16665
 
3 liveuser 16666
			#設置執行失敗訊息
16667
			$result["error"]=$checkArguments;
226 liveuser 16668
 
3 liveuser 16669
			#回傳結果
16670
			return $result;
226 liveuser 16671
 
3 liveuser 16672
			}#if end
226 liveuser 16673
 
3 liveuser 16674
		#如果檢查參數不通過
16675
		if($checkArguments["passed"]==="false"){
226 liveuser 16676
 
3 liveuser 16677
			#設置執行失敗
16678
			$result["status"]="false";
226 liveuser 16679
 
3 liveuser 16680
			#設置執行失敗訊息
16681
			$result["error"]=$checkArguments;
226 liveuser 16682
 
3 liveuser 16683
			#回傳結果
16684
			return $result;
226 liveuser 16685
 
3 liveuser 16686
			}#if end
16687
 
16688
		#如果是相對位置
16689
		if(!(strpos($conf["linkTo"],"/")===0)){
226 liveuser 16690
 
3 liveuser 16691
			#將 $conf["linkTo"] 轉換為針對產生位置的相對位置.
16692
			#函式說明:
16693
			#將多個路徑字串變成相對於當前路徑的相對路徑字串
16694
			#回傳結果:
16695
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
16696
			#$result["error"],錯誤訊息陣列.
226 liveuser 16697
			#$result["function"],函數名稱.
3 liveuser 16698
			#$result["argu"],使用的參數.
16699
			#$result["content"],字串陣列,多個轉換好的相對路徑字串.
16700
			#必填參數:
16701
			#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
16702
			$conf["fileAccess::getRelativePath"]["path"]=array($conf["linkTo"]);
16703
			#$conf["fileArgu"],字串,當前路徑.
16704
			$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
16705
			#可省略參數:
16706
			#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
16707
			$conf["fileAccess::getRelativePath"]["baseFrom"]=$conf["path"];
16708
			#參考資料:
16709
			#無.
16710
			#備註:
16711
			#無.
16712
			$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
16713
			unset($conf["fileAccess::getRelativePath"]);
16714
 
16715
			#如果執行失敗
16716
			if($getRelativePath["status"]==="false"){
226 liveuser 16717
 
3 liveuser 16718
				#設置執行失敗
16719
				$result["status"]="false";
226 liveuser 16720
 
3 liveuser 16721
				#設置執行失敗訊息
16722
				$result["error"]=$getRelativePath;
226 liveuser 16723
 
3 liveuser 16724
				#回傳結果
16725
				return $result;
226 liveuser 16726
 
3 liveuser 16727
				}#if end
16728
 
16729
			/*
16730
			#break point
16731
			var_dump($conf);
16732
			var_dump($getRelativePath);
16733
			exit;
16734
			*/
16735
 
16736
			#取得執行的指令
16737
			$result["cmd"][]=$getRelativePath["cmd"];
16738
 
16739
			#取得正確的相對位置
16740
			$conf["linkTo"]=$getRelativePath["content"][0];
226 liveuser 16741
 
3 liveuser 16742
			}#if end
16743
 
16744
		#初始化給 ln 指令的參數
16745
		$paramsForLn=array("-s",$conf["linkTo"]);
16746
 
16747
		#函式說明:
16748
		#將字串特定關鍵字與其前面的內容剔除
16749
		#回傳結果:
16750
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16751
		#$result["error"],錯誤訊息陣列.
16752
		#$result["warning"],警告訊息鎮列.
16753
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
16754
		#$result["function"],當前執行的函數名稱.
16755
		#$result["oriStr"],要處理的原始字串內容.
226 liveuser 16756
		#$result["content"],處理好的的字串內容.
3 liveuser 16757
		#必填參數:
16758
		#$conf["stringIn"],字串,要處理的字串.
16759
		$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["linkTo"];
16760
		#$conf["keyWord"],字串,特定字串.
16761
		$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="/";
16762
		#可省略參數:
16763
		#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
16764
		$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
16765
		#參考資料:
16766
		#無.
16767
		#備註:
16768
		#無.
16769
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
16770
		unset($conf["stringProcess::delStrBeforeKeyWord"]);
16771
 
16772
		#var_dump(__LINE__." ".print_r($delStrBeforeKeyWord,true));
16773
 
16774
		#如果執行失敗
16775
		if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 16776
 
3 liveuser 16777
			#設置執行失敗
16778
			$result["status"]="false";
226 liveuser 16779
 
3 liveuser 16780
			#設置執行失敗訊息
16781
			$result["error"]=$delStrBeforeKeyWord;
226 liveuser 16782
 
3 liveuser 16783
			#回傳結果
16784
			return $result;
226 liveuser 16785
 
3 liveuser 16786
			}#if end
226 liveuser 16787
 
3 liveuser 16788
		#如果沒有找到 "/"
16789
		if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 16790
 
3 liveuser 16791
			#設置 預設的 軟連名稱
16792
			$softLink=$conf["linkTo"];
226 liveuser 16793
 
3 liveuser 16794
			}#if end
16795
 
16796
		#反之有 "/"
16797
		else{
226 liveuser 16798
 
3 liveuser 16799
			#設置 預設的 軟連結名稱
16800
			$softLink=$delStrBeforeKeyWord["content"];
226 liveuser 16801
 
3 liveuser 16802
			}#else end
16803
 
16804
		/*
16805
		#break point
16806
		var_dump(__LINE__." ".$softLink);
16807
		exit;
16808
		*/
16809
 
16810
		#預設欲建立的軟連結名稱
16811
		$createdSoftLink=$softLink;
16812
 
16813
		#如果有設置 path
16814
		if(isset($conf["path"])){
226 liveuser 16815
 
3 liveuser 16816
			#確認 path 存在
16817
			#函式說明:
16818
			#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
16819
			#回傳結果:
16820
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
16821
			#$result["error"],錯誤訊息陣列
16822
			#$result["warning"],警告訊息陣列
16823
			#必填參數:
16824
			#$conf["dirPositionAndName"]="";#新建的位置與名稱
16825
			$conf["fileAccess::createNewFolder"]["dirPositionAndName"]=$conf["path"];
16826
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
16827
			$conf["fileAccess::createNewFolder"]["fileArgu"]=$conf["fileArgu"];
16828
			#可省略參數:
16829
			#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
16830
			#$conf["dirPermission"]="";
16831
			#參考資料:
16832
			#mkdir=>http://php.net/manual/en/function.mkdir.php
16833
			#chmod=>http://php.net/manual/en/function.chmod.php
16834
			#參考資料:
16835
			#無.
16836
			#備註:
16837
			#同 function createFolderAfterCheck.
16838
			$createNewFolder=fileAccess::createNewFolder($conf["fileAccess::createNewFolder"]);
16839
			unset($conf["fileAccess::createNewFolder"]);
226 liveuser 16840
 
3 liveuser 16841
			#如果執行失敗
16842
			if($createNewFolder["status"]==="false"){
226 liveuser 16843
 
3 liveuser 16844
				#設置執行失敗
16845
				$result["status"]="false";
226 liveuser 16846
 
3 liveuser 16847
				#設置執行失敗訊息
16848
				$result["error"]=$createNewFolder;
226 liveuser 16849
 
3 liveuser 16850
				#回傳結果
16851
				return $result;
226 liveuser 16852
 
3 liveuser 16853
				}#if end
226 liveuser 16854
 
3 liveuser 16855
			#var_dump(__LINE__." ".print_r($conf,true));
226 liveuser 16856
 
3 liveuser 16857
			#預設要加 slash
16858
			$slash="/";
226 liveuser 16859
 
3 liveuser 16860
			#如果 path 為 "/" 結尾
16861
			if($conf["path"][strlen($conf["path"])-1]==="/"){
226 liveuser 16862
 
3 liveuser 16863
				#不用 slash
16864
				$slash="";
226 liveuser 16865
 
3 liveuser 16866
				}#if end
226 liveuser 16867
 
3 liveuser 16868
			#如果有設置 name
16869
			if(isset($conf["name"])){
226 liveuser 16870
 
3 liveuser 16871
				#指定軟連結要放在哪邊
16872
				$paramsForLn[]=$conf["path"].$slash.$conf["name"];
226 liveuser 16873
 
3 liveuser 16874
				#更新欲建立的軟連結名稱
16875
				$createdSoftLink=$conf["path"].$slash.$conf["name"];
226 liveuser 16876
 
3 liveuser 16877
				/*
16878
				#break point
16879
				var_dump($conf["path"],$softLink,$createdSoftLink);
16880
				exit;
16881
				*/
226 liveuser 16882
 
3 liveuser 16883
				}#if end
226 liveuser 16884
 
3 liveuser 16885
			#反之
16886
			else{
226 liveuser 16887
 
3 liveuser 16888
				#指定軟連結要放在哪邊
16889
				$paramsForLn[]=$conf["path"];
226 liveuser 16890
 
3 liveuser 16891
				#更新欲建立的軟連結名稱
16892
				$createdSoftLink=$conf["path"].$slash.$softLink;
226 liveuser 16893
 
3 liveuser 16894
				/*
16895
				#break point
16896
				var_dump($conf["path"],$softLink,$createdSoftLink);
16897
				exit;
16898
				*/
226 liveuser 16899
 
3 liveuser 16900
				}#else end
226 liveuser 16901
 
3 liveuser 16902
			#var_dump($createdSoftLink);
226 liveuser 16903
 
3 liveuser 16904
			}#if end
226 liveuser 16905
 
3 liveuser 16906
		#反之如果有設置 name
16907
		else if(isset($conf["name"])){
226 liveuser 16908
 
3 liveuser 16909
			#指定軟連結的名稱
16910
			$paramsForLn[]=$conf["name"];
226 liveuser 16911
 
3 liveuser 16912
			#更新欲建立的軟連結名稱
16913
			$createdSoftLink=$conf["name"];
226 liveuser 16914
 
3 liveuser 16915
			#var_dump(__LINE__." ".$createdSoftLink);
226 liveuser 16916
 
3 liveuser 16917
			}#if end
226 liveuser 16918
 
3 liveuser 16919
		/*
16920
		# break point
16921
		var_dump($createdSoftLink);
16922
		exit;
16923
		*/
226 liveuser 16924
 
3 liveuser 16925
		#如果要覆蓋既有的目標
16926
		if($conf["overWrite"]==="true"){
226 liveuser 16927
 
3 liveuser 16928
			#函式說明:
16929
			#移除檔案
16930
			#回傳結果:
16931
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
16932
			#$result["error"],錯誤訊息陣列
16933
			#$result["warning"],警告訊息陣列
16934
			#$result["function"],當前執行的函數名稱
16935
			#必填參數:
16936
			#$conf["fileAddress"],字串,要移除檔案的位置.
16937
			$conf["fileAccess::delFile"]["fileAddress"]=$createdSoftLink;
16938
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
16939
			$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
16940
			#可省略參數:
16941
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
16942
			#$conf["commentsArray"]=array("");
16943
			#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
16944
			$conf["fileAccess::delFile"]["allowDelSymlink"]="true";
16945
			#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
16946
			$conf["fileAccess::delFile"]["allowDelFolder"]="true";
16947
			#參考資料:
16948
			#無.
16949
			#備註:
16950
			#無.
16951
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
226 liveuser 16952
			unset($conf["fileAccess::delFile"]);
16953
 
3 liveuser 16954
			/*
16955
			#break point
16956
			var_dump($delFile);
16957
			exit;
16958
			*/
226 liveuser 16959
 
3 liveuser 16960
			#如果執行失敗
16961
			if($delFile["status"]==="false"){
226 liveuser 16962
 
3 liveuser 16963
				#設置執行失敗
16964
				$result["status"]="false";
226 liveuser 16965
 
3 liveuser 16966
				#設置執行失敗訊息
16967
				$result["error"]=$delFile;
226 liveuser 16968
 
3 liveuser 16969
				#回傳結果
16970
				return $result;
226 liveuser 16971
 
3 liveuser 16972
				}#if end
226 liveuser 16973
 
3 liveuser 16974
			}#if end
16975
 
16976
		#函式說明:
16977
		#呼叫shell執行系統命令,並取得回傳的內容.
16978
		#回傳結果:
16979
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16980
		#$result["error"],錯誤訊息陣列.
16981
		#$result["function"],當前執行的函數名稱.
16982
		#$result["argu"],使用的參數.
16983
		#$result["cmd"],執行的指令內容.
16984
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16985
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16986
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16987
		#$result["running"],是否還在執行.
16988
		#$result["pid"],pid.
16989
		#$result["statusCode"],執行結束後的代碼.
16990
		#必填參數:
16991
		#$conf["command"],字串,要執行的指令與.
16992
		$conf["external::callShell"]["command"]="ln";
16993
		#$conf["fileArgu"],字串,變數__FILE__的內容.
16994
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16995
		#可省略參數:
16996
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16997
		$conf["external::callShell"]["argu"]=$paramsForLn;
16998
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16999
		#$conf["arguIsAddr"]=array();
17000
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
17001
		#$conf["plainArgu"]=array();
17002
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
17003
		#$conf["useApostrophe"]=array();
17004
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17005
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17006
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17007
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17008
		#$conf["enablePrintDescription"]="true";
17009
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17010
		#$conf["printDescription"]="";
17011
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
17012
		$conf["external::callShell"]["escapeshellarg"]="true";
17013
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
17014
		#$conf["thereIsShellVar"]=array();
17015
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17016
		#$conf["username"]="";
17017
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17018
		#$conf["password"]="";
17019
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17020
		#$conf["useScript"]="";
17021
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17022
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17023
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17024
		#$conf["inBackGround"]="";
17025
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17026
		$conf["external::callShell"]["getErr"]="true";
17027
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17028
		#$conf["doNotRun"]="false";
17029
		#參考資料:
17030
		#exec=>http://php.net/manual/en/function.exec.php
17031
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17032
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17033
		#備註:
17034
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17035
		$callShell=external::callShell($conf["external::callShell"]);
17036
		unset($conf["external::callShell"]);
17037
 
17038
		#如果執行失敗
17039
		if($callShell["status"]==="false"){
226 liveuser 17040
 
3 liveuser 17041
			#設置執行失敗
17042
			$result["status"]="false";
226 liveuser 17043
 
3 liveuser 17044
			#設置執行失敗訊息
17045
			$result["error"]=$callShell;
226 liveuser 17046
 
3 liveuser 17047
			#回傳結果
17048
			return $result;
226 liveuser 17049
 
3 liveuser 17050
			}#if end
226 liveuser 17051
 
3 liveuser 17052
		#保存執行的指令
17053
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 17054
 
3 liveuser 17055
		#初始化給 ls 指令的參數
17056
		$paramsForLs=array("-l",$paramsForLn[count($paramsForLn)-1]);
226 liveuser 17057
 
3 liveuser 17058
		#取得軟連結的資訊
17059
		#函式說明:
17060
		#呼叫shell執行系統命令,並取得回傳的內容.
17061
		#回傳結果:
17062
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17063
		#$result["error"],錯誤訊息陣列.
17064
		#$result["function"],當前執行的函數名稱.
17065
		#$result["argu"],使用的參數.
17066
		#$result["cmd"],執行的指令內容.
17067
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17068
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17069
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17070
		#$result["running"],是否還在執行.
17071
		#$result["pid"],pid.
17072
		#$result["statusCode"],執行結束後的代碼.
17073
		#必填參數:
17074
		#$conf["command"],字串,要執行的指令與.
17075
		$conf["external::callShell"]["command"]="ls";
17076
		#$conf["fileArgu"],字串,變數__FILE__的內容.
17077
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17078
		#可省略參數:
17079
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17080
		$conf["external::callShell"]["argu"]=$paramsForLs;
17081
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17082
		#$conf["arguIsAddr"]=array();
17083
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
17084
		#$conf["plainArgu"]=array();
17085
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
17086
		#$conf["useApostrophe"]=array();
17087
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17088
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17089
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17090
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17091
		#$conf["enablePrintDescription"]="true";
17092
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17093
		#$conf["printDescription"]="";
17094
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
17095
		$conf["external::callShell"]["escapeshellarg"]="true";
17096
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
17097
		#$conf["thereIsShellVar"]=array();
17098
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17099
		#$conf["username"]="";
17100
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17101
		#$conf["password"]="";
17102
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17103
		#$conf["useScript"]="";
17104
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17105
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17106
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17107
		#$conf["inBackGround"]="";
17108
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17109
		$conf["external::callShell"]["getErr"]="true";
17110
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17111
		#$conf["doNotRun"]="false";
17112
		#參考資料:
17113
		#exec=>http://php.net/manual/en/function.exec.php
17114
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17115
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17116
		#備註:
17117
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17118
		$callShell=external::callShell($conf["external::callShell"]);
17119
		unset($conf["external::callShell"]);
17120
 
17121
		#如果執行失敗
17122
		if($callShell["status"]==="false"){
226 liveuser 17123
 
3 liveuser 17124
			#設置執行失敗
17125
			$result["status"]="false";
226 liveuser 17126
 
3 liveuser 17127
			#設置執行失敗訊息
17128
			$result["error"]=$callShell;
226 liveuser 17129
 
3 liveuser 17130
			#回傳結果
17131
			return $result;
226 liveuser 17132
 
3 liveuser 17133
			}#if end
226 liveuser 17134
 
3 liveuser 17135
		#保存執行的指令
17136
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 17137
 
3 liveuser 17138
		#取得軟連結的資訊
17139
		$result["content"]=$callShell["output"];
226 liveuser 17140
 
3 liveuser 17141
		#設置執行正常
17142
		$result["status"]="true";
226 liveuser 17143
 
3 liveuser 17144
		#回傳結果
17145
		return $result;
226 liveuser 17146
 
3 liveuser 17147
		}#function createLink end
17148
 
17149
	/*
17150
	#函式說明:
17151
	#針對特定目錄下的內容建立軟連結.
17152
	#回傳結果:
17153
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17154
	#$result["error"],錯誤訊息.
17155
	#$result["function"],當前執行的函數名稱.
17156
	#$result["content"],字串陣列,每個建立的軟連結資訊.
17157
	#必填參數:
17158
	#$conf["fileArgu"],字串,變數__FILE__的內容.
17159
	$conf["fileArgu"]=__FILE__;
17160
	#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
17161
	$conf["linkToDir"]="";
17162
	#可省略參數:
17163
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
17164
	#$conf["path"]="";
17165
	#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
17166
	#$conf["name"]=array(array("oriName","newName"));
17167
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
17168
	#$conf["overWrite"]="true";
17169
	#參考資料:
17170
	#無.
17171
	#備註:
17172
	#無.
17173
	*/
17174
	public static function createMultiLinkInDir(&$conf){
226 liveuser 17175
 
3 liveuser 17176
		#初始化要回傳的結果
17177
		$result=array();
17178
 
17179
		#取得當前執行的函數名稱
17180
		$result["function"]=__FUNCTION__;
17181
 
17182
		#如果沒有參數
17183
		if(func_num_args()==0){
226 liveuser 17184
 
3 liveuser 17185
			#設置執行失敗
17186
			$result["status"]="false";
226 liveuser 17187
 
3 liveuser 17188
			#設置執行錯誤訊息
17189
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 17190
 
3 liveuser 17191
			#回傳結果
17192
			return $result;
226 liveuser 17193
 
220 liveuser 17194
			}#if end
3 liveuser 17195
 
17196
		#取得參數
17197
		$result["argu"]=$conf;
17198
 
17199
		#如果 $conf 不為陣列
17200
		if(gettype($conf)!=="array"){
226 liveuser 17201
 
3 liveuser 17202
			#設置執行失敗
17203
			$result["status"]="false";
226 liveuser 17204
 
3 liveuser 17205
			#設置執行錯誤訊息
17206
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 17207
 
3 liveuser 17208
			#如果傳入的參數為 null
17209
			if($conf===null){
226 liveuser 17210
 
3 liveuser 17211
				#設置執行錯誤訊息
17212
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 17213
 
3 liveuser 17214
				}#if end
17215
 
17216
			#回傳結果
17217
			return $result;
226 liveuser 17218
 
3 liveuser 17219
			}#if end
226 liveuser 17220
 
3 liveuser 17221
		#檢查參數
17222
		#函式說明:
17223
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
17224
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17225
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
17226
		#$result["function"],當前執行的函式名稱.
17227
		#$result["argu"],設置給予的參數.
17228
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
17229
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
17230
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
17231
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
17232
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
17233
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
17234
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
17235
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
17236
		#必填寫的參數:
17237
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 17238
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 17239
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
17240
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
17241
		#可以省略的參數:
17242
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
17243
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkToDir");
17244
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
17245
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
17246
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
17247
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
17248
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
17249
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
17250
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
17251
		#$conf["canBeEmpty"]=array();
17252
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
17253
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","name","overWrite");
17254
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
17255
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","name","overWrite");
226 liveuser 17256
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 17257
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string");
17258
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
17259
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".",null,"false");
17260
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
17261
		#$conf["disallowAllSkipableVarIsEmpty"]="";
17262
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
17263
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
17264
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
17265
		#$conf["arrayCountEqualCheck"][]=array();
17266
		#參考資料來源:
17267
		#array_keys=>http://php.net/manual/en/function.array-keys.php
17268
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
17269
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 17270
 
3 liveuser 17271
		#如果檢查參數失敗
17272
		if($checkArguments["status"]==="false"){
226 liveuser 17273
 
3 liveuser 17274
			#設置執行失敗
17275
			$result["status"]="false";
226 liveuser 17276
 
3 liveuser 17277
			#設置執行失敗訊息
17278
			$result["error"]=$checkArguments;
226 liveuser 17279
 
3 liveuser 17280
			#回傳結果
17281
			return $result;
226 liveuser 17282
 
3 liveuser 17283
			}#if end
226 liveuser 17284
 
3 liveuser 17285
		#如果檢查參數不通過
17286
		if($checkArguments["passed"]==="false"){
226 liveuser 17287
 
3 liveuser 17288
			#設置執行失敗
17289
			$result["status"]="false";
226 liveuser 17290
 
3 liveuser 17291
			#設置執行失敗訊息
17292
			$result["error"]=$checkArguments;
226 liveuser 17293
 
3 liveuser 17294
			#回傳結果
17295
			return $result;
226 liveuser 17296
 
3 liveuser 17297
			}#if end
226 liveuser 17298
 
3 liveuser 17299
		#函式說明:
17300
		#取得目錄底下所有目錄與檔案清單.
17301
		#回傳結果:
17302
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
17303
		#$result["error"],錯誤訊息陣列.
17304
		#$result["function"],函數名稱.
17305
		#$result["content"],陣列,目錄底下的檔案與子目錄.
17306
		#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
17307
		#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
17308
		#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
17309
		#$result["position"],目前的位置.
17310
		#必填參數:
17311
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
17312
		$conf["fileAccess::getList"]["position"]=$conf["linkToDir"];
17313
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17314
		$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
17315
		#可省略參數:
17316
		#無
17317
		#參考資料:
17318
		#opendir=>http://php.net/manual/en/function.opendir.php
17319
		#is_dir=>http://php.net/manual/en/function.is-dir.php
17320
		#備註:
17321
		#無.
17322
		$getList=fileAccess::getList($conf["fileAccess::getList"]);
17323
		unset($conf["fileAccess::getList"]);
226 liveuser 17324
 
3 liveuser 17325
		#如果檢查參數失敗
17326
		if($getList["status"]==="false"){
226 liveuser 17327
 
3 liveuser 17328
			#設置執行失敗
17329
			$result["status"]="false";
226 liveuser 17330
 
3 liveuser 17331
			#設置執行失敗訊息
17332
			$result["error"]=$getList;
226 liveuser 17333
 
3 liveuser 17334
			#回傳結果
17335
			return $result;
226 liveuser 17336
 
3 liveuser 17337
			}#if end
226 liveuser 17338
 
3 liveuser 17339
		#針對目標目錄底下的所有檔案
17340
		foreach($getList["content"] as $oriName){
226 liveuser 17341
 
3 liveuser 17342
			#如果有設定 $conf["name"]
17343
			if(isset($conf["name"])){
226 liveuser 17344
 
3 liveuser 17345
				#預設不指定新的軟連結名稱
17346
				unset($newSoftLinkName);
226 liveuser 17347
 
3 liveuser 17348
				#針對每個原始目標的名稱
17349
				foreach($conf["name"] as $customName){
226 liveuser 17350
 
3 liveuser 17351
					#如果是指定的目標
17352
					if($oriName["name"]===$customName[0]){
226 liveuser 17353
 
3 liveuser 17354
						#設置新的軟連結名稱
17355
						$newSoftLinkName=$customName[1];
226 liveuser 17356
 
3 liveuser 17357
						}#if end
226 liveuser 17358
 
3 liveuser 17359
					}#foreach end
226 liveuser 17360
 
3 liveuser 17361
				}#if end
226 liveuser 17362
 
3 liveuser 17363
			#建立軟連結
17364
			#函式說明:
17365
			#建立軟連結.
17366
			#回傳結果:
17367
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17368
			#$result["error"],錯誤訊息.
17369
			#$result["function"],當前執行的函數名稱.
17370
			#$result["content"],軟連結的資訊.
17371
			#必填參數:
17372
			#$conf["fileArgu"],字串,變數__FILE__的內容.
17373
			$conf["fileAccess::createLink"]["fileArgu"]=$conf["fileArgu"];
17374
			#$conf["linkTo"],字串,軟連結要指向哪邊.
17375
			$conf["fileAccess::createLink"]["linkTo"]=$conf["linkToDir"]."/".$oriName["name"];
17376
			#可省略參數:
17377
			#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
17378
			$conf["fileAccess::createLink"]["path"]=$conf["path"];
226 liveuser 17379
 
3 liveuser 17380
			#如果有新的軟連結名稱
17381
			if(isset($newSoftLinkName)){
226 liveuser 17382
 
3 liveuser 17383
				#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
17384
				$conf["fileAccess::createLink"]["name"]=$newSoftLinkName;
226 liveuser 17385
 
3 liveuser 17386
				}#if end
226 liveuser 17387
 
3 liveuser 17388
			#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
17389
			$conf["fileAccess::createLink"]["overWrite"]=$conf["overWrite"];
226 liveuser 17390
 
3 liveuser 17391
			#參考資料:
17392
			#無.
17393
			#備註:
17394
			#無.
17395
			$createLink=fileAccess::createLink($conf["fileAccess::createLink"]);
17396
			unset($conf["fileAccess::createLink"]);
226 liveuser 17397
 
3 liveuser 17398
			#var_dump(__LINE__." ".print_r($createLink,true));
226 liveuser 17399
 
3 liveuser 17400
			#如果檢查參數失敗
17401
			if($createLink["status"]==="false"){
226 liveuser 17402
 
3 liveuser 17403
				#設置執行失敗
17404
				$result["status"]="false";
226 liveuser 17405
 
3 liveuser 17406
				#設置執行失敗訊息
17407
				$result["error"]=$createLink;
226 liveuser 17408
 
3 liveuser 17409
				#回傳結果
17410
				return $result;
226 liveuser 17411
 
3 liveuser 17412
				}#if end
226 liveuser 17413
 
3 liveuser 17414
			#儲存建立好的軟連結資訊
17415
			$result["content"][]=$createLink["content"];
226 liveuser 17416
 
3 liveuser 17417
			}#foreach end
226 liveuser 17418
 
3 liveuser 17419
		#設置執行正常
17420
		$result["status"]="true";
226 liveuser 17421
 
3 liveuser 17422
		#回傳結果
17423
		return $result;
226 liveuser 17424
 
3 liveuser 17425
		}#function createMultiLink end
17426
 
17427
	/*
17428
	#函式說明:
17429
	#更新檔案的內容.
17430
	#回傳結果:
17431
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17432
	#$result["error"],錯誤訊息.
17433
	#$result["function"],當前執行的函數名稱.
220 liveuser 17434
	#$result["content"],更新的資訊.
17435
	#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
17436
	#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
3 liveuser 17437
	#必填參數:
17438
	#$conf["fileArgu"],字串,變數__FILE__的內容.
17439
	$conf["fileArgu"]=__FILE__;
17440
	#$conf["file"],字串,要更新的檔案位置與名稱.
17441
	$conf["file"]="";
17442
	#可省略參數:
17443
	#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
17444
	#$conf["overWriteWith"]=array();
17445
	#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
17446
	#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
17447
	#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
17448
	#$conf["replaceLike"]="false";
17449
	#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
17450
	#$conf["addToTailWhenNoMatch"]="false";
17451
	#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
17452
	#$conf["addToTailBeforeThat"]="?\>";
220 liveuser 17453
	#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
17454
	#$conf["replaceSpecifyLine"]=array();
17455
	#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
17456
	#$conf["outputPath"]="";
3 liveuser 17457
	#參考資料:
17458
	#無.
17459
	#備註:
17460
	#無.
17461
	*/
17462
	public static function updateFile(&$conf){
226 liveuser 17463
 
3 liveuser 17464
		#初始化要回傳的結果
17465
		$result=array();
17466
 
17467
		#取得當前執行的函數名稱
17468
		$result["function"]=__FUNCTION__;
17469
 
17470
		#如果沒有參數
17471
		if(func_num_args()==0){
226 liveuser 17472
 
3 liveuser 17473
			#設置執行失敗
17474
			$result["status"]="false";
226 liveuser 17475
 
3 liveuser 17476
			#設置執行錯誤訊息
17477
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 17478
 
3 liveuser 17479
			#回傳結果
17480
			return $result;
226 liveuser 17481
 
220 liveuser 17482
			}#if end
3 liveuser 17483
 
17484
		#取得參數
17485
		$result["argu"]=$conf;
17486
 
17487
		#如果 $conf 不為陣列
17488
		if(gettype($conf)!=="array"){
226 liveuser 17489
 
3 liveuser 17490
			#設置執行失敗
17491
			$result["status"]="false";
226 liveuser 17492
 
3 liveuser 17493
			#設置執行錯誤訊息
17494
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 17495
 
3 liveuser 17496
			#如果傳入的參數為 null
17497
			if($conf===null){
226 liveuser 17498
 
3 liveuser 17499
				#設置執行錯誤訊息
17500
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 17501
 
3 liveuser 17502
				}#if end
17503
 
17504
			#回傳結果
17505
			return $result;
226 liveuser 17506
 
3 liveuser 17507
			}#if end
226 liveuser 17508
 
3 liveuser 17509
		#檢查參數
17510
		#函式說明:
17511
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
17512
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17513
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
17514
		#$result["function"],當前執行的函式名稱.
17515
		#$result["argu"],設置給予的參數.
17516
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
17517
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
17518
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
17519
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
17520
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
17521
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
17522
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
17523
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
17524
		#必填寫的參數:
17525
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
220 liveuser 17526
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 17527
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
17528
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
17529
		#可以省略的參數:
17530
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
17531
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","file");
17532
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
17533
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
17534
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
17535
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
17536
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
17537
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
17538
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
17539
		#$conf["canBeEmpty"]=array();
17540
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
220 liveuser 17541
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("overWriteWith","replaceWith","addToTailWhenNoMatch","addToTailBeforeThat","replaceLike","replaceSpecifyLine","outputPath");
3 liveuser 17542
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
220 liveuser 17543
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("overWriteWith","replaceWith","addToTailWhenNoMatch","addToTailBeforeThat","replaceLike","replaceSpecifyLine","outputPath");
226 liveuser 17544
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
220 liveuser 17545
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","string","string","string","array","string");
3 liveuser 17546
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
220 liveuser 17547
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false",null,"false",null,null);
3 liveuser 17548
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
17549
		#$conf["disallowAllSkipableVarIsEmpty"]="";
17550
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
17551
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
17552
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
17553
		#$conf["arrayCountEqualCheck"][]=array();
17554
		#參考資料來源:
17555
		#array_keys=>http://php.net/manual/en/function.array-keys.php
17556
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
17557
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 17558
 
3 liveuser 17559
		#如果檢查參數失敗
17560
		if($checkArguments["status"]==="false"){
226 liveuser 17561
 
3 liveuser 17562
			#設置執行失敗
17563
			$result["status"]="false";
226 liveuser 17564
 
3 liveuser 17565
			#設置執行失敗訊息
17566
			$result["error"]=$checkArguments;
226 liveuser 17567
 
3 liveuser 17568
			#回傳結果
17569
			return $result;
226 liveuser 17570
 
3 liveuser 17571
			}#if end
226 liveuser 17572
 
3 liveuser 17573
		#如果檢查參數不通過
17574
		if($checkArguments["passed"]==="false"){
226 liveuser 17575
 
3 liveuser 17576
			#設置執行失敗
17577
			$result["status"]="false";
226 liveuser 17578
 
3 liveuser 17579
			#設置執行失敗訊息
17580
			$result["error"]=$checkArguments;
226 liveuser 17581
 
3 liveuser 17582
			#回傳結果
17583
			return $result;
226 liveuser 17584
 
3 liveuser 17585
			}#if end
226 liveuser 17586
 
3 liveuser 17587
		#檢查檔案是否存在
17588
		#函式說明:
17589
		#檢查多個檔案與資料夾是否存在.
17590
		#回傳的結果:
17591
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
17592
		#$result["error"],錯誤訊息陣列.
17593
		#$resutl["function"],當前執行的涵式名稱.
17594
		#$result["argu"],使用的參數.
17595
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
17596
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
17597
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
17598
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
17599
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
17600
		#必填參數:
17601
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
17602
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
17603
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17604
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
17605
		#可省略參數:
17606
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
17607
		$conf["disableWebSearch"]="true";
17608
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
17609
		$conf["userDir"]="false";
17610
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
17611
		$conf["web"]="false";
17612
		#參考資料:
17613
		#http://php.net/manual/en/function.file-exists.php
17614
		#http://php.net/manual/en/control-structures.foreach.php
17615
		#備註:
17616
		#函數file_exists檢查的路徑為檔案系統的路徑
17617
		#$result["varName"][$i]結果未實作
17618
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
17619
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 17620
 
3 liveuser 17621
		#如果檢查參數失敗
17622
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 17623
 
3 liveuser 17624
			#設置執行失敗
17625
			$result["status"]="false";
226 liveuser 17626
 
3 liveuser 17627
			#設置執行失敗訊息
17628
			$result["error"]=$checkMultiFileExist;
226 liveuser 17629
 
3 liveuser 17630
			#回傳結果
17631
			return $result;
226 liveuser 17632
 
3 liveuser 17633
			}#if end
226 liveuser 17634
 
3 liveuser 17635
		#如果目標檔案不存在
17636
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 17637
 
3 liveuser 17638
			#設置執行失敗
17639
			$result["status"]="false";
226 liveuser 17640
 
3 liveuser 17641
			#設置執行失敗訊息
17642
			$result["error"]=$checkMultiFileExist;
226 liveuser 17643
 
3 liveuser 17644
			#回傳結果
17645
			return $result;
226 liveuser 17646
 
3 liveuser 17647
			}#if end
226 liveuser 17648
 
220 liveuser 17649
		#預設要寫入的位置為原始檔案
17650
		$file2write=$conf["file"];
226 liveuser 17651
 
220 liveuser 17652
		#如果有設置 outputPath
17653
		if(isset($conf["outputPath"])){
226 liveuser 17654
 
220 liveuser 17655
			#寫入檔案的路徑與名稱
17656
			$file2write=$conf["outputPath"]."/".$conf["file"];
226 liveuser 17657
 
220 liveuser 17658
			}#if end
226 liveuser 17659
 
3 liveuser 17660
		#如果有設置 overWriteWith
17661
		if(isset($conf["overWriteWith"])){
226 liveuser 17662
 
3 liveuser 17663
			#函式說明:
17664
			#將多行字串寫入到檔案
17665
			#回傳結果:
17666
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
17667
			#$result["error"],錯誤訊息陣列.
17668
			#$result["function"],當前執行函數的名稱.
17669
			#必填參數:
17670
			#$conf["fileName"],字串,爲要編輯的檔案名稱
220 liveuser 17671
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
3 liveuser 17672
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
17673
			$conf["fileAccess::writeMultiLine"]["inputString"]=$conf["overWriteWith"];
17674
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17675
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
220 liveuser 17676
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
17677
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
3 liveuser 17678
			#可省略參數:
17679
			#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
17680
			#參考資料:
17681
			#無.
17682
			#備註:
17683
			#無.
17684
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
17685
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 17686
 
3 liveuser 17687
			#如果執行失敗
17688
			if($writeMultiLine["status"]==="false"){
226 liveuser 17689
 
3 liveuser 17690
				#設置執行失敗
17691
				$result["status"]="false";
226 liveuser 17692
 
3 liveuser 17693
				#設置執行失敗訊息
17694
				$result["error"]=$writeMultiLine;
226 liveuser 17695
 
3 liveuser 17696
				#回傳結果
17697
				return $result;
226 liveuser 17698
 
3 liveuser 17699
				}#if end
226 liveuser 17700
 
220 liveuser 17701
			#取得原始檔案的內容
17702
			#函式說明:
17703
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
17704
			#回傳的變數說明:
17705
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
17706
			#$result["error"],錯誤訊息提示.
17707
			#$result["warning"],警告訊息.
17708
			#$result["function"],當前執行的函數名稱.
17709
			#$result["fileContent"],爲檔案的內容陣列.
17710
			#$result["lineCount"],爲檔案內容總共的行數.
17711
			#$result["fullContent"],為檔案的完整內容.
17712
			#$result["base64data"],為檔案的base64內容.
17713
			#$result["mimeType"],為檔案的mime type.
17714
			#必填參數:
17715
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
17716
			$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
17717
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17718
			$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
17719
			#可省略參數:
17720
			#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
17721
			$conf["fileAccess::getFileContent"]["web"]="false";
17722
			#參考資料:
17723
			#file(),取得檔案內容的行數.
17724
			#file=>http:#php.net/manual/en/function.file.php
17725
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
17726
			#filesize=>http://php.net/manual/en/function.filesize.php
17727
			#參考資料:
17728
			#無.
17729
			#備註:
17730
			#無.
17731
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
17732
			unset($conf["fileAccess::getFileContent"]);
226 liveuser 17733
 
220 liveuser 17734
			#如果執行失敗
17735
			if($getFileContent["status"]==="false"){
226 liveuser 17736
 
220 liveuser 17737
				#設置執行失敗
17738
				$result["status"]="false";
226 liveuser 17739
 
220 liveuser 17740
				#設置執行失敗訊息
17741
				$result["error"]=$getFileContent;
226 liveuser 17742
 
220 liveuser 17743
				#回傳結果
17744
				return $result;
226 liveuser 17745
 
220 liveuser 17746
				}#if end
226 liveuser 17747
 
220 liveuser 17748
			#無窮迴圈
17749
			for($i=0;$i>=0;$i++){
226 liveuser 17750
 
220 liveuser 17751
				#如果有舊或新的行內容存在
17752
				if( isset($getFileContent["fileContent"][$i]) || isset($conf["overWriteWith"][$i]) ){
226 liveuser 17753
 
220 liveuser 17754
					#初始化暫存舊行內容的變數
17755
					$oriLine=null;
226 liveuser 17756
 
220 liveuser 17757
					#初始化暫存新行內容的變數
17758
					$newLine=null;
226 liveuser 17759
 
220 liveuser 17760
					#如果存在原行內容
17761
					if(isset($getFileContent["fileContent"][$i])){
226 liveuser 17762
 
220 liveuser 17763
						#儲存原行內容
17764
						$oriLine=$getFileContent["fileContent"][$i];
226 liveuser 17765
 
220 liveuser 17766
						}#if end
226 liveuser 17767
 
220 liveuser 17768
					#如果存在新行內容
17769
					if(isset($conf["overWriteWith"][$i])){
226 liveuser 17770
 
220 liveuser 17771
						#儲存新行內容
17772
						$newLine=$conf["overWriteWith"][$i];
226 liveuser 17773
 
220 liveuser 17774
						}#if end
226 liveuser 17775
 
220 liveuser 17776
					#設置更新的資訊
17777
					$result["content"][$i]=array("ori"=>$oriLine,"new"=>$newLine);
226 liveuser 17778
 
220 liveuser 17779
					}#if end
226 liveuser 17780
 
220 liveuser 17781
				#反之
17782
				else{
226 liveuser 17783
 
220 liveuser 17784
					#結束迴圈
17785
					break;
226 liveuser 17786
 
220 liveuser 17787
					}#else end
226 liveuser 17788
 
220 liveuser 17789
				}#for end
226 liveuser 17790
 
3 liveuser 17791
			}#if end
226 liveuser 17792
 
220 liveuser 17793
		#反之如果有設置 "replaceWith"
17794
		else if(isset($conf["replaceWith"])){
226 liveuser 17795
 
3 liveuser 17796
			#取得檔案的內容
17797
			#函式說明:
17798
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
17799
			#回傳的變數說明:
17800
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
17801
			#$result["error"],錯誤訊息提示.
17802
			#$result["warning"],警告訊息.
17803
			#$result["function"],當前執行的函數名稱.
17804
			#$result["fileContent"],爲檔案的內容陣列.
17805
			#$result["lineCount"],爲檔案內容總共的行數.
17806
			#$result["fullContent"],為檔案的完整內容.
17807
			#$result["base64data"],為檔案的base64內容.
17808
			#$result["mimeType"],為檔案的mime type.
17809
			#必填參數:
17810
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
17811
			$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
17812
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17813
			$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
17814
			#可省略參數:
17815
			#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
17816
			$conf["fileAccess::getFileContent"]["web"]="false";
17817
			#參考資料:
17818
			#file(),取得檔案內容的行數.
17819
			#file=>http:#php.net/manual/en/function.file.php
17820
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
17821
			#filesize=>http://php.net/manual/en/function.filesize.php
17822
			#參考資料:
17823
			#無.
17824
			#備註:
17825
			#無.
17826
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
17827
			unset($conf["fileAccess::getFileContent"]);
226 liveuser 17828
 
3 liveuser 17829
			#如果執行失敗
17830
			if($getFileContent["status"]==="false"){
226 liveuser 17831
 
3 liveuser 17832
				#設置執行失敗
17833
				$result["status"]="false";
226 liveuser 17834
 
3 liveuser 17835
				#設置執行失敗訊息
17836
				$result["error"]=$getFileContent;
226 liveuser 17837
 
3 liveuser 17838
				#回傳結果
17839
				return $result;
226 liveuser 17840
 
3 liveuser 17841
				}#if end
226 liveuser 17842
 
3 liveuser 17843
			#取得原始檔案的每行內容
17844
			$oriFileContentByLine=&$getFileContent["fileContent"];
226 liveuser 17845
 
3 liveuser 17846
			#針對每個 replaceWith 條件
17847
			foreach($conf["replaceWith"] as $replaceInfo){
226 liveuser 17848
 
3 liveuser 17849
				#預設尚未找到符合的關鍵字
17850
				$foundKeyWord=false;
226 liveuser 17851
 
3 liveuser 17852
				#取得要替換的目標字串
17853
				$oriStr=$replaceInfo[0];
226 liveuser 17854
 
3 liveuser 17855
				#取得要替換成的字串內容
17856
				$newStr=$replaceInfo[1];
226 liveuser 17857
 
3 liveuser 17858
				#針對每行原始內容
17859
				foreach($oriFileContentByLine as $index => $line){
226 liveuser 17860
 
3 liveuser 17861
					#函式說明:
17862
					#檢查字串裡面有無指定的關鍵字
17863
					#回傳結果:
17864
					#$result["status"],"true"代表執行成功,"false"代表執行失敗。
17865
					#$result["error"],錯誤訊息
17866
					#$result["function"],當前執行的函數名稱.
17867
					#$result["argu"],使用的參數.
17868
					#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
17869
					#$result["keyWordCount"],找到的關鍵字數量.
17870
					#必填參數:
17871
					#$conf["keyWord"],字串,想要搜尋的關鍵字.
17872
					$conf["search::findKeyWord"]["keyWord"]=$oriStr;
17873
					#$conf["string"],字串,要被搜尋的字串內容
17874
					$conf["search::findKeyWord"]["string"]=$line;
17875
					#可省略參數:
226 liveuser 17876
 
3 liveuser 17877
					#如果要完全符合關鍵字
17878
					if($conf["replaceLike"]==="false"){
226 liveuser 17879
 
3 liveuser 17880
						#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
17881
						$conf["search::findKeyWord"]["completeEqual"]="true";
226 liveuser 17882
 
3 liveuser 17883
						}#if end
226 liveuser 17884
 
3 liveuser 17885
					#參考資料:
17886
					#無.
17887
					#備註:
17888
					#無.
17889
					$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
17890
					unset($conf["search::findKeyWord"]);
226 liveuser 17891
 
3 liveuser 17892
					#如果執行失敗
17893
					if($findKeyWord["status"]==="false"){
226 liveuser 17894
 
3 liveuser 17895
						#設置執行失敗
17896
						$result["status"]="false";
226 liveuser 17897
 
3 liveuser 17898
						#設置執行失敗訊息
17899
						$result["error"]=$findKeyWord;
226 liveuser 17900
 
3 liveuser 17901
						#回傳結果
17902
						return $result;
226 liveuser 17903
 
3 liveuser 17904
						}#if end
226 liveuser 17905
 
3 liveuser 17906
					#如果有找到關鍵字
17907
					if($findKeyWord["founded"]==="true"){
226 liveuser 17908
 
220 liveuser 17909
						#設置更新的資訊
17910
						$result["content"][$lineIndex]=array("ori"=>$oriFileContentByLine[$index],"new"=>$newStr);
226 liveuser 17911
 
3 liveuser 17912
						#更新該行內容
17913
						$oriFileContentByLine[$index]=$newStr;
226 liveuser 17914
 
3 liveuser 17915
						#設置有找到符合的關鍵字
17916
						$foundKeyWord=true;
226 liveuser 17917
 
3 liveuser 17918
						}#if end
226 liveuser 17919
 
3 liveuser 17920
					}#foreach end
226 liveuser 17921
 
3 liveuser 17922
				#如果沒有找到關鍵字
17923
				if($foundKeyWord===false){
226 liveuser 17924
 
3 liveuser 17925
					#如果要新增內容
17926
					if($conf["addToTailWhenNoMatch"]==="true"){
226 liveuser 17927
 
3 liveuser 17928
						#如果有設置 addToTailBeforeThat
17929
						if(isset($conf["addToTailBeforeThat"])){
226 liveuser 17930
 
3 liveuser 17931
							#預設沒有找到符合的關鍵字
17932
							$foundKeyWord=false;
226 liveuser 17933
 
3 liveuser 17934
							#初始化要記錄要 append 回去的各行內容.
17935
							$linesToAppend=array();
226 liveuser 17936
 
3 liveuser 17937
							#倒敘,針對每行內容
17938
							for($i=count($oriFileContentByLine)-1;$i>=0;$i--){
226 liveuser 17939
 
3 liveuser 17940
								#儲存要 append 回去的行內容
17941
								$linesToAppend[]=$oriFileContentByLine[$i];
226 liveuser 17942
 
3 liveuser 17943
								#如果找到關鍵字了
17944
								if($oriFileContentByLine[$i]===$conf["addToTailBeforeThat"]){
226 liveuser 17945
 
3 liveuser 17946
									#設置有找到符合的關鍵字
17947
									$foundKeyWord=true;
226 liveuser 17948
 
220 liveuser 17949
									#設置更新的資訊
17950
									$result["content"][$lineIndex]=array("ori"=>$oriFileContentByLine[$i],"new"=>$line);
226 liveuser 17951
 
3 liveuser 17952
									#更新該行內容
17953
									$oriFileContentByLine[$i]=$line;
226 liveuser 17954
 
3 liveuser 17955
									#倒敘陣列
17956
									$linesToAppend=array_reverse($linesToAppend);
226 liveuser 17957
 
3 liveuser 17958
									#針對每行要 append 回去的內容
17959
									foreach($linesToAppend as $lineToAppend){
226 liveuser 17960
 
3 liveuser 17961
										#append 行內容
17962
										$oriFileContentByLine[]=$lineToAppend;
226 liveuser 17963
 
220 liveuser 17964
										#設置更新的資訊
17965
										$result["content"][count($oriFileContentByLine)-1]=array("ori"=>null,"new"=>$lineToAppend);
226 liveuser 17966
 
3 liveuser 17967
										}#foreach end
226 liveuser 17968
 
3 liveuser 17969
									}#if end
226 liveuser 17970
 
3 liveuser 17971
								}#for end
226 liveuser 17972
 
3 liveuser 17973
							#如果沒有找到關鍵字
17974
							if($foundKeyWord===false){
226 liveuser 17975
 
3 liveuser 17976
								#設置執行失敗
17977
								$result["status"]="false";
226 liveuser 17978
 
3 liveuser 17979
								#設置錯誤訊息
17980
								$result["error"]="can't find \"".$conf["addToTailBeforeThat"]."\" to insert before it.";
226 liveuser 17981
 
3 liveuser 17982
								#回傳結果
17983
								return $result;
226 liveuser 17984
 
3 liveuser 17985
								}#if end
226 liveuser 17986
 
3 liveuser 17987
							}#if end
226 liveuser 17988
 
3 liveuser 17989
						}#if end
226 liveuser 17990
 
3 liveuser 17991
					}#if end
226 liveuser 17992
 
3 liveuser 17993
				}#foreach end
226 liveuser 17994
 
3 liveuser 17995
			#函式說明:
17996
			#將多行字串寫入到檔案
17997
			#回傳結果:
17998
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
17999
			#$result["error"],錯誤訊息陣列.
18000
			#$result["function"],當前執行函數的名稱.
18001
			#必填參數:
18002
			#$conf["fileName"],字串,爲要編輯的檔案名稱
220 liveuser 18003
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
3 liveuser 18004
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
18005
			$conf["fileAccess::writeMultiLine"]["inputString"]=$oriFileContentByLine;
18006
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18007
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
18008
			#可省略參數:
18009
			#$conf["fileAccess::writeMultiLine"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
220 liveuser 18010
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
18011
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
3 liveuser 18012
			#參考資料:
18013
			#無.
18014
			#備註:
18015
			#無.
18016
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
18017
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 18018
 
3 liveuser 18019
			#如果執行失敗
18020
			if($writeMultiLine["status"]==="false"){
226 liveuser 18021
 
3 liveuser 18022
				#設置執行失敗
18023
				$result["status"]="false";
226 liveuser 18024
 
3 liveuser 18025
				#設置執行失敗訊息
18026
				$result["error"]=$writeMultiLine;
226 liveuser 18027
 
3 liveuser 18028
				#回傳結果
18029
				return $result;
226 liveuser 18030
 
3 liveuser 18031
				}#if end
226 liveuser 18032
 
3 liveuser 18033
			}#if end
226 liveuser 18034
 
220 liveuser 18035
		#反之如果有設置 replaceSpecifyLine
18036
		else if(isset($conf["replaceSpecifyLine"])){
226 liveuser 18037
 
220 liveuser 18038
			#讀取原始檔案內容
18039
			#函式說明:
18040
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
18041
			#回傳的變數說明:
18042
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
18043
			#$result["error"],錯誤訊息提示.
18044
			#$result["warning"],警告訊息.
18045
			#$result["function"],當前執行的函數名稱.
18046
			#$result["fileContent"],爲檔案的內容陣列.
18047
			#$result["lineCount"],爲檔案內容總共的行數.
18048
			#$result["fullContent"],為檔案的完整內容.
18049
			#$result["base64dataOnly"],檔案的base64data.
18050
			#$result["base64data"],為在網頁上給予src參數的數值.
18051
			#$result["mimeType"],為檔案的mime type.
18052
			#必填參數:
18053
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
18054
			$conf["fileAcceess::getFileContent"]["filePositionAndName"]=$conf["file"];
18055
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18056
			$conf["fileAcceess::getFileContent"]["fileArgu"]=__FILE__;
18057
			#可省略參數:
18058
			#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
18059
			#$conf["web"]="true";
18060
			#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
18061
			#$conf["createIfnotExist"]="false";
18062
			#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
18063
			#$conf["autoDeleteSpaceOnEachLineStart"]="false";
18064
			#參考資料:
18065
			#file(),取得檔案內容的行數.
18066
			#file=>http:#php.net/manual/en/function.file.php
18067
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
18068
			#filesize=>http://php.net/manual/en/function.filesize.php
18069
			#參考資料:
18070
			#無.
18071
			#備註:
18072
			#無.
18073
			$getFileContent=fileAccess::getFileContent($conf["fileAcceess::getFileContent"]);
18074
			unset($conf["fileAcceess::getFileContent"]);
226 liveuser 18075
 
220 liveuser 18076
			#如果執行失敗
18077
			if($getFileContent["status"]==="false"){
226 liveuser 18078
 
220 liveuser 18079
				#設置執行失敗
18080
				$result["status"]="false";
226 liveuser 18081
 
220 liveuser 18082
				#設置執行失敗訊息
18083
				$result["error"]=$getFileContent;
226 liveuser 18084
 
220 liveuser 18085
				#回傳結果
18086
				return $result;
226 liveuser 18087
 
220 liveuser 18088
				}#if end
226 liveuser 18089
 
220 liveuser 18090
			#針對每個要更新的行
18091
			foreach($conf["replaceSpecifyLine"] as $lineIndex => $newLineContent){
226 liveuser 18092
 
220 liveuser 18093
				#設置更新的資訊
18094
				$result["content"][$lineIndex]=array("ori"=>$getFileContent["fileContent"][$lineIndex],"new"=>$newLineContent);
226 liveuser 18095
 
220 liveuser 18096
				#更新行內容
18097
				$getFileContent["fileContent"][$lineIndex]=$newLineContent;
226 liveuser 18098
 
220 liveuser 18099
				}#foreach end
226 liveuser 18100
 
220 liveuser 18101
			#debug
18102
			#var_dump(__FILE__,__LINE__,count($getFileContent["fileContent"]));
226 liveuser 18103
 
220 liveuser 18104
			#將變更寫入到檔案裡面
18105
			#函式說明:
18106
			#將多行字串寫入到檔案
18107
			#回傳結果:
18108
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
18109
			#$result["error"],錯誤訊息陣列.
18110
			#$result["function"],當前執行函數的名稱.
18111
			#必填參數:
18112
			#$conf["fileName"],字串,爲要編輯的檔案名稱
18113
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
18114
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
18115
			$conf["fileAccess::writeMultiLine"]["inputString"]=$getFileContent["fileContent"];
18116
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18117
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=__FILE__;
18118
			#可省略參數:
18119
			$conf["fileAccess::writeMultiLine"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
18120
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
18121
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
18122
			#參考資料:
18123
			#無.
18124
			#備註:
18125
			#無.
18126
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
18127
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 18128
 
220 liveuser 18129
			#如果執行失敗
18130
			if($writeMultiLine["status"]==="false"){
226 liveuser 18131
 
220 liveuser 18132
				#設置執行失敗
18133
				$result["status"]="false";
226 liveuser 18134
 
220 liveuser 18135
				#設置執行失敗訊息
18136
				$result["error"]=$writeMultiLine;
226 liveuser 18137
 
220 liveuser 18138
				#回傳結果
18139
				return $result;
226 liveuser 18140
 
220 liveuser 18141
				}#if end
226 liveuser 18142
 
220 liveuser 18143
			#debug
18144
			#var_dump(__FILE__,__LINE__,$writeMultiLine);exit(1);
226 liveuser 18145
 
220 liveuser 18146
			}#if end
226 liveuser 18147
 
3 liveuser 18148
		#設置執行正常
18149
		$result["status"]="true";
226 liveuser 18150
 
3 liveuser 18151
		#回傳結果
18152
		return $result;
226 liveuser 18153
 
3 liveuser 18154
		}#function updateFile end
226 liveuser 18155
 
3 liveuser 18156
	/*
18157
	#函式說明:
18158
	#輔助使用PHP內建的chmod函式.
18159
	#回傳結果:
18160
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18161
	#$result["error"],錯誤訊息.
18162
	#$result["function"],當前執行的函式名稱.
18163
	#$result["argu"],使用的參數.
18164
	#$result["cmd"],執行的指令.
18165
	#$result["content"],執行的結果陣列,如果參數 "recursive" 跟 "excludeSelf" 都有設定的話,就會回傳該結果.
18166
	#必填參數:
18167
	#$conf["mode"],字串,要變成什麼權限.
18168
	$conf["mode"]="";
18169
	#$conf["target"],字串,需要變更權限的目標.
18170
	$conf["target"]="";
18171
	#可省略參數:
18172
	#無.
18173
	#參考資料:
18174
	#無.
18175
	#備註:
18176
	#無.
18177
	*/
18178
	public static function chmod(&$conf){
226 liveuser 18179
 
3 liveuser 18180
		#初始化要回傳的結果
18181
		$result=array();
18182
 
18183
		#取得當前執行的函數名稱
18184
		$result["function"]=__FUNCTION__;
18185
 
18186
		#如果沒有參數
18187
		if(func_num_args()==0){
18188
 
18189
			#設置執行失敗
18190
			$result["status"]="false";
18191
 
18192
			#設置執行錯誤訊息
18193
			$result["error"]="函數".$result["function"]."需要參數";
18194
 
18195
			#回傳結果
18196
			return $result;
18197
 
18198
			}#if end
18199
 
18200
		#取得參數
18201
		$result["argu"]=$conf;
18202
 
18203
		#如果 $conf 不為陣列
18204
		if(gettype($conf)!=="array"){
18205
 
18206
			#設置執行失敗
18207
			$result["status"]="false";
18208
 
18209
			#設置執行錯誤訊息
18210
			$result["error"][]="\$conf變數須為陣列形態";
18211
 
18212
			#如果傳入的參數為 null
18213
			if(is_null($conf)){
18214
 
18215
				#設置執行錯誤訊息
18216
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
18217
 
18218
				}#if end
18219
 
18220
			#回傳結果
18221
			return $result;
18222
 
18223
			}#if end
226 liveuser 18224
 
3 liveuser 18225
		#函式說明:
18226
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
18227
		#回傳結果:
18228
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18229
		#$result["error"],執行不正常結束的錯訊息陣列.
18230
		#$result["simpleError"],簡單表示的錯誤訊息.
18231
		#$result["function"],當前執行的函式名稱.
18232
		#$result["argu"],設置給予的參數.
18233
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
18234
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
18235
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
18236
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
18237
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
18238
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
18239
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
18240
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
18241
		#必填參數:
18242
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
18243
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
18244
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
18245
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
18246
		#可省略參數:
18247
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
18248
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mode","target");
18249
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
18250
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
18251
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
18252
		#$conf["canBeEmptyString"]="false";
18253
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
18254
		#$conf["canNotBeEmpty"]=array();
18255
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
18256
		#$conf["canBeEmpty"]=array();
18257
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
18258
		#$conf["skipableVariableCanNotBeEmpty"]=array();
18259
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
18260
		#$conf["skipableVariableName"]=array();
18261
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
18262
		#$conf["skipableVariableType"]=array();
18263
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
18264
		#$conf["skipableVarDefaultValue"]=array("");
18265
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
18266
		#$conf["disallowAllSkipableVarIsEmpty"]="";
18267
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
18268
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
18269
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
18270
		#$conf["arrayCountEqualCheck"][]=array();
18271
		#參考資料:
18272
		#array_keys=>http://php.net/manual/en/function.array-keys.php
18273
		#備註:
18274
		#無.
18275
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
18276
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 18277
 
3 liveuser 18278
		#如果檢查參數失敗
18279
		if($checkArguments["status"]==="false"){
226 liveuser 18280
 
3 liveuser 18281
			#設置執行失敗
18282
			$result["status"]="false";
18283
 
18284
			#設置錯誤資訊
18285
			$result["error"]=$checkArguments;
226 liveuser 18286
 
3 liveuser 18287
			#回傳結果
18288
			return $result;
226 liveuser 18289
 
3 liveuser 18290
			}#if end
226 liveuser 18291
 
3 liveuser 18292
		#如果檢查參數不通過
18293
		if($checkArguments["passed"]==="false"){
226 liveuser 18294
 
3 liveuser 18295
			#設置執行失敗
18296
			$result["status"]="false";
18297
 
18298
			#設置錯誤資訊
18299
			$result["error"]=$checkArguments;
226 liveuser 18300
 
3 liveuser 18301
			#回傳結果
18302
			return $result;
226 liveuser 18303
 
3 liveuser 18304
			}#if end
226 liveuser 18305
 
3 liveuser 18306
		#將$conf["mode"]轉換為10進位的整數
18307
		$conf["mode"]=(int)base_convert($conf["mode"],8,10);
226 liveuser 18308
 
3 liveuser 18309
		#變更 target 的檔案權限為代碼
226 liveuser 18310
		$chmod=chmod($conf["target"],$conf["mode"]);
18311
 
3 liveuser 18312
		#如果改變檔案權限失敗
18313
		if($chmod===false){
226 liveuser 18314
 
3 liveuser 18315
			#設置執行失敗
18316
			$result["status"]="false";
226 liveuser 18317
 
3 liveuser 18318
			#設置錯誤訊息
18319
			$result["error"][]="改變 ".$conf["target"]." 檔案的權限資訊為 ".$conf["mode"]." 失敗,通常只有系統帳戶才能變更之.";
226 liveuser 18320
 
3 liveuser 18321
			#回傳結果
226 liveuser 18322
			return $result;
18323
 
3 liveuser 18324
			}#if end
226 liveuser 18325
 
3 liveuser 18326
		#設置執行正常
18327
		$result["status"]="true";
226 liveuser 18328
 
3 liveuser 18329
		#回傳結果
18330
		return $result;
226 liveuser 18331
 
3 liveuser 18332
		}#function chmod end
18333
 
18334
	}#class fileAccess end
18335
 
226 liveuser 18336
?>