Subversion Repositories php-qbpwcf

Rev

Rev 391 | 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
 
406 liveuser 436
		#debug
437
		#var_dump(__LINE__,$conf["fileName"]);
438
 
3 liveuser 439
		#設定要寫入或複寫的檔案
440
		$fileopenResult=fopen($conf["fileName"],$conf["writeMethod"]);
226 liveuser 441
 
3 liveuser 442
		#如果 $fileopenResult 等於 FALSE
406 liveuser 443
		if($fileopenResult===FALSE){
226 liveuser 444
 
3 liveuser 445
			#設置錯誤識別
446
			$result["status"]="false";
226 liveuser 447
 
3 liveuser 448
			#代表打開檔案失敗
449
			$result["error"][]="檔案".$conf["fileName"]."開啟失敗";
226 liveuser 450
 
3 liveuser 451
			#回傳結果
452
			return $result;
226 liveuser 453
 
3 liveuser 454
			}#if end
226 liveuser 455
 
3 liveuser 456
		#將資料寫入到檔案裡面
457
		$fwriteResult=fwrite($fileopenResult,$conf["inputString"]);
458
 
459
		#如果 $fwriteResult 等於 FALSE
460
		if($fwriteResult!=0 && $fwriteResult==FALSE){
226 liveuser 461
 
3 liveuser 462
			#設置錯誤識別
463
			$result["status"]="false";
226 liveuser 464
 
3 liveuser 465
			#代表檔案寫入失敗
466
			$result["error"][]="檔案".$conf["fileName"]."寫入失敗";
226 liveuser 467
 
3 liveuser 468
			#回傳結果
469
			return $result;
226 liveuser 470
 
3 liveuser 471
			}#if end
472
 
473
		#存檔並關閉檔案
474
		$fcloseResult=fclose($fileopenResult);
475
 
476
		#如果 $fcloseResult 等於 FALSE
477
		if($fcloseResult==FALSE){
226 liveuser 478
 
3 liveuser 479
			#設置錯誤識別
480
			$result["status"]="false";
226 liveuser 481
 
3 liveuser 482
			#代表檔案寫入失敗
483
			$result["error"][]="檔案".$conf["fileName"]."儲存失敗";
226 liveuser 484
 
3 liveuser 485
			#回傳結果
486
			return $result;
226 liveuser 487
 
3 liveuser 488
			}#if end
489
 
490
		#檢查用來寫入的檔案是否存在
491
		#函式說明:檢查多個檔案與資料夾是否存在
492
		#回傳的結果:
493
		#$result["varName"][$i],爲第$i個變數的名稱。
494
		#$result["varExist"][$i],爲第$i個變數是否存在,true代表存在,false代表不存在。
495
		#必填參數:
496
		$conf["fileAccess::checkMutiFileExist"]["fileArray"]=array($conf["fileName"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
497
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
498
		$conf["fileAccess::checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
499
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false".
500
		$conf["fileAccess::checkMutiFileExist"]["web"]=$conf["web"];
501
		#參考資料來源:
502
		#http:#php.net/manual/en/function.file-exists.php
503
		#http:#php.net/manual/en/control-structures.foreach.php
504
		$fileAccess["checkMutiFileExist"]=fileAccess::checkMultiFileExist($conf["fileAccess::checkMutiFileExist"]);
505
		unset($conf["fileAccess::checkMutiFileExist"]);
506
 
507
		#如果檢查檔案是否存在失敗
508
		if($fileAccess["checkMutiFileExist"]["status"]==="false"){
226 liveuser 509
 
3 liveuser 510
			#設置錯誤識別
511
			$result["status"]="false";
226 liveuser 512
 
3 liveuser 513
			#設置錯誤訊息陣列
514
			$result["error"]=$fileAccess["checkMutiFileExist"];
226 liveuser 515
 
3 liveuser 516
			#回傳結果
517
			return $result;
226 liveuser 518
 
3 liveuser 519
			}#if end
520
 
226 liveuser 521
		#如果$fileAccess["checkMutiFileExist"]["varExist"][0] 等於 "false"
3 liveuser 522
		if($fileAccess["checkMutiFileExist"]["varExist"][0]==="false"){
226 liveuser 523
 
3 liveuser 524
			#設置錯誤識別
525
			$result["status"]="false";
226 liveuser 526
 
3 liveuser 527
			#設置錯誤訊息
528
			$result["error"]=$fileAccess["checkMutiFileExist"];
226 liveuser 529
 
3 liveuser 530
			#設置錯誤訊息陣列
531
			$result["error"][]="愈建立的檔案不存在";
226 liveuser 532
 
3 liveuser 533
			#回傳結果
534
			return $result;
226 liveuser 535
 
3 liveuser 536
			}#if end
226 liveuser 537
 
3 liveuser 538
		#函式說明:
539
		#依據取得檔案的擁有着資訊
540
		#回傳結果:
541
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
542
		#$result["error"],錯誤訊息陣列.
226 liveuser 543
		#$result["function"],函數名稱.
3 liveuser 544
		#$result["content"],檔案擁有着資訊.
545
		#$result["content"],檔案資訊陣列.
226 liveuser 546
		#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 547
		#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
548
		#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
549
		#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
550
		#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
551
		#$result["content"]["ownerName"],檔案擁有着資訊.
552
		#$result["content"]["groupName"],檔案所屬擁有着資訊.
553
		#$result["content"]["size"],檔案大小.
554
		#$result["content"]["modifyDate"],檔案變更年月日.
555
		#$result["content"]["modifyTime"],檔案變更時分秒.
556
		#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
557
		#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
558
		#必填參數:
559
		#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
560
		$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];
561
		#$conf["file"],字串,要查看擁有者資訊的檔案.
562
		$conf["fileAccess::fileInfo"]["file"]=$conf["fileName"];
563
		#可省略參數:
564
		#$conf["fileToRead"],字串,要讀取的檔案名稱為何?預設為"help".
565
		#$conf["fileToRead"]="help";
566
		#$conf["output"],字串,輸出的網頁檔案位置與名稱,副檔名html會自動補上,預設為"help".
226 liveuser 567
		#$conf["output"]="help.html";
3 liveuser 568
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false".
569
		$conf["fileAccess::fileInfo"]["web"]=$conf["web"];
570
		#參考資料:
571
		#fileowner=>http://php.net/manual/en/function.fileowner.php
572
		#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
573
		$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
574
		unset($conf["fileAccess::fileInfo"]);
226 liveuser 575
 
3 liveuser 576
		#如果取得檔案資訊失敗
577
		if($fileInfo["status"]==="false"){
226 liveuser 578
 
3 liveuser 579
			#設置執行失敗
580
			$result["status"]="false";
226 liveuser 581
 
3 liveuser 582
			#設置錯誤訊息
583
			$result["error"]=$fileInfo;
226 liveuser 584
 
3 liveuser 585
			#回傳結果
586
			return $result;
226 liveuser 587
 
220 liveuser 588
			}#if end
226 liveuser 589
 
3 liveuser 590
		#取得檔案的擁有者名稱
591
		$fileOwner=$fileInfo["content"]["ownerName"];
226 liveuser 592
 
3 liveuser 593
		#執行php的帳戶
220 liveuser 594
		$runner=csInformation::runner();
226 liveuser 595
 
3 liveuser 596
		#如果執行php的使用者等於檔案的擁有者名稱或為root
597
		if($runner===$fileOwner || $runner==="root"){
226 liveuser 598
 
3 liveuser 599
			#改變檔案的權限為0770
600
			chmod($conf["fileName"],0770);
226 liveuser 601
 
3 liveuser 602
			}#if end
226 liveuser 603
 
3 liveuser 604
		#執行到這邊代表執行正常
605
		$result["status"]="true";
226 liveuser 606
 
3 liveuser 607
		#回傳結果
608
		return $result;
226 liveuser 609
 
3 liveuser 610
		}#function writeTextIntoFile end
611
 
612
	/*
613
	#函式說明:
614
	#一次建立多個檔案,並寫入內容.
615
	#回傳結果:
616
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
617
	#$result["error"],錯誤訊息陣列.
618
	#$result["function"],當前執行的函數名稱.
619
	#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
620
	#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
621
	#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
622
	#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
623
	#$result["argu"],使用的參數.
624
	#必填參數:
625
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
626
	$conf["fileArgu"]=__FILE__;
627
	#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
628
	$conf["fileName"]=array("");
629
	#可省略參數:
630
	#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
631
	#$conf["inputString"]=array("");
632
	#參考資料:
633
	#無.
634
	#備註:
635
	#無.
636
	*/
637
	public static function writeMultiFile(&$conf){
226 liveuser 638
 
3 liveuser 639
		#初始化要回傳的變數
640
		$result=array();
641
 
642
		#初始化當前執行的函數名稱
643
		$result["function"]=__FUNCTION__;
644
 
645
		#如果 $conf 不為陣列
646
		if(gettype($conf)!="array"){
226 liveuser 647
 
3 liveuser 648
			#設置執行失敗
649
			$result["status"]="false";
226 liveuser 650
 
3 liveuser 651
			#設置執行錯誤訊息
652
			$result["error"][]="\$conf變數須為陣列形態";
653
 
654
			#如果傳入的參數為 null
655
			if($conf==null){
226 liveuser 656
 
3 liveuser 657
				#設置執行錯誤訊息
658
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 659
 
3 liveuser 660
				}#if end
661
 
662
			#回傳結果
663
			return $result;
226 liveuser 664
 
3 liveuser 665
			}#if end
226 liveuser 666
 
3 liveuser 667
		#取得使用的參數
668
		$result["argu"]=$conf;
669
 
670
		#檢查參數
671
		#函式說明:
672
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
673
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
674
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
675
		#$result["function"],當前執行的函式名稱.
676
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
677
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
678
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
679
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
680
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
681
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
682
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
683
		#必填寫的參數:
684
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
685
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
686
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
687
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileName");
226 liveuser 688
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 689
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
690
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
691
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
692
		#可以省略的參數:
693
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
694
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
695
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
696
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("inputString");
226 liveuser 697
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 698
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
699
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
700
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
701
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
702
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("fileName","inputString");
703
		#參考資料來源:
704
		#array_keys=>http://php.net/manual/en/function.array-keys.php
705
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
706
		unset($conf["variableCheck::checkArguments"]);
707
 
708
		#如果 $checkArguments["status"] 等於 "false"
709
		if($checkArguments["status"]=="false"){
226 liveuser 710
 
3 liveuser 711
			#設置錯誤識別
712
			$result["status"]="false";
226 liveuser 713
 
3 liveuser 714
			#設置錯誤訊息
715
			$result["error"]=$checkArguments;
226 liveuser 716
 
3 liveuser 717
			#回傳結果
220 liveuser 718
			return $result;
226 liveuser 719
 
3 liveuser 720
			}#if end
226 liveuser 721
 
3 liveuser 722
		#如果 $checkArguments["passed"] 等於 "false"
723
		if($checkArguments["passed"]=="false"){
226 liveuser 724
 
3 liveuser 725
			#設置錯誤識別
726
			$result["status"]="false";
226 liveuser 727
 
3 liveuser 728
			#設置錯誤訊息
729
			$result["error"]=$checkArguments;
226 liveuser 730
 
3 liveuser 731
			#回傳結果
220 liveuser 732
			return $result;
226 liveuser 733
 
3 liveuser 734
			}#if end
226 liveuser 735
 
3 liveuser 736
		#如果沒有設定要個別寫入的內容
737
		if(!isset($conf["inputString"])){
226 liveuser 738
 
3 liveuser 739
			#針對每個檔案名稱
740
			for($i=0;$i<count($conf["fileName"]);$i++){
226 liveuser 741
 
3 liveuser 742
				#建立空的 $conf["inputString"]
743
				$conf["inputString"][$i]="";
226 liveuser 744
 
3 liveuser 745
				}#for end
226 liveuser 746
 
3 liveuser 747
			}#if end
226 liveuser 748
 
3 liveuser 749
		#針對每個要寫入的檔案
750
		foreach($conf["fileName"] as $index => $file2writre){
226 liveuser 751
 
3 liveuser 752
			#取得要寫入的內容
753
			$content2writre=$conf["inputString"][$index];
226 liveuser 754
 
3 liveuser 755
			#函式說明:
756
			#將字串寫入到檔案
757
			#回傳結果:
758
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
759
			#$result["error"],錯誤訊息陣列.
760
			#$result["function"],當前執行的函數名稱.
761
			#$result["fileInfo"],實際上寫入的檔案資訊陣列.
762
			#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
763
			#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
764
			#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
765
			#$result["argu"],使用的參數.
766
			#必填參數:
767
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
768
			$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
769
			#可省略參數:
770
			#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
771
			$conf["fileAccess::writeTextIntoFile"]["fileName"]=$file2writre;
772
			#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
773
			$conf["fileAccess::writeTextIntoFile"]["inputString"]=$content2writre;
774
			#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
775
			#$conf["writeMethod"]="a";
776
			#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
777
			#$conf["checkRepeat"]="";
778
			#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
779
			#$conf["filenameExtensionStartPoint"]="";
780
			#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
781
			#$conf["repeatNameRule"]="";
782
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
783
			$conf["fileAccess::writeTextIntoFile"]["web"]="false";
784
			#備註:
785
			#無.
786
			$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
787
			unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 788
 
3 liveuser 789
			#如果建立檔案失敗
790
			if($writeTextIntoFile["status"]==="false"){
226 liveuser 791
 
3 liveuser 792
				#設置錯誤識別
793
				$result["status"]="false";
226 liveuser 794
 
3 liveuser 795
				#設置錯誤訊息
796
				$result["error"]=$writeTextIntoFile;
226 liveuser 797
 
3 liveuser 798
				#回傳結果
220 liveuser 799
				return $result;
226 liveuser 800
 
3 liveuser 801
				}#if end
226 liveuser 802
 
3 liveuser 803
			#設置建立好的檔案資訊
220 liveuser 804
			$result["content"][]=$writeTextIntoFile["fileInfo"];
226 liveuser 805
 
3 liveuser 806
			}#foreach end
226 liveuser 807
 
3 liveuser 808
			#設置執行正常
809
			$result["status"]="true";
226 liveuser 810
 
3 liveuser 811
			#回傳結果
226 liveuser 812
			return $result;
813
 
3 liveuser 814
		}#function writeMultiFile end
815
 
816
	/*
817
	#函式說明:
818
	#將多行字串寫入到檔案
819
	#回傳結果:
820
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
821
	#$result["error"],錯誤訊息陣列.
822
	#$result["function"],當前執行函數的名稱.
823
	#必填參數:
824
	#$conf["fileName"],字串,爲要編輯的檔案名稱
825
	$conf["fileName"]="";
826
	#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
827
	$conf["inputString"]=array("");
828
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
829
	$conf["fileArgu"]=__FILE__;
830
	#可省略參數:
220 liveuser 831
	#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
832
	#$conf["writeMethod"]="a";
833
	#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
834
	#$conf["fastWrite"]="false";
3 liveuser 835
	#參考資料:
836
	#無.
837
	#備註:
838
	#無.
839
	*/
840
	public static function writeMultiLine(&$conf){
226 liveuser 841
 
3 liveuser 842
		#初始化要回傳的結果
843
		$result=array();
226 liveuser 844
 
3 liveuser 845
		#取得當前執行的函數
846
		$result["function"]=__FUNCTION__;
847
 
848
		#如果 $conf 不為陣列
849
		if(gettype($conf)!="array"){
226 liveuser 850
 
3 liveuser 851
			#設置執行失敗
852
			$result["status"]="false";
226 liveuser 853
 
3 liveuser 854
			#設置執行錯誤訊息
855
			$result["error"][]="\$conf變數須為陣列形態";
856
 
857
			#如果傳入的參數為 null
858
			if($conf==null){
226 liveuser 859
 
3 liveuser 860
				#設置執行錯誤訊息
861
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 862
 
3 liveuser 863
				}#if end
864
 
865
			#回傳結果
866
			return $result;
226 liveuser 867
 
3 liveuser 868
			}#if end
226 liveuser 869
 
3 liveuser 870
		#檢查必填參數
871
		#函式說明:
872
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
873
		#回傳的結果:
874
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
875
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
876
		#$result["function"],當前執行的函式名稱.
877
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
878
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
879
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
880
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
881
		#必填寫的參數:
882
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
883
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileName","inputString","fileArgu");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
884
		#可以省略的參數:
226 liveuser 885
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","array","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 886
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
887
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
888
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 889
 
3 liveuser 890
		#如果檢查失敗
891
		if($checkResult["status"]=="false"){
226 liveuser 892
 
3 liveuser 893
			#設置執行錯誤
894
			$result["status"]="false";
226 liveuser 895
 
3 liveuser 896
			#設置執行錯誤訊息
897
			$result["error"]=$checkResult;
226 liveuser 898
 
3 liveuser 899
			#回傳結果
900
			return $result;
226 liveuser 901
 
3 liveuser 902
			}#if end
226 liveuser 903
 
3 liveuser 904
		#如果檢查不通過
905
		if($checkResult["passed"]=="false"){
226 liveuser 906
 
3 liveuser 907
			#設置執行錯誤
908
			$result["status"]="false";
226 liveuser 909
 
3 liveuser 910
			#設置執行錯誤訊息
911
			$result["error"]=$checkResult;
226 liveuser 912
 
3 liveuser 913
			#回傳結果
914
			return $result;
226 liveuser 915
 
3 liveuser 916
			}#if end
226 liveuser 917
 
918
		#檢查可省略參數
3 liveuser 919
		#函式說明:
920
		#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
921
		#回傳結果:
922
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
923
		#$result["error"],錯誤訊息陣列.
924
		#$result["function"],當前執行的函式名稱.
925
		#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
926
		#必填參數:
927
		#$conf["variableCheck.checkSkipableVarType"]["checkedVar"],陣列,要檢查的變數陣列名稱為?
928
		$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf;
929
		#$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
220 liveuser 930
		$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array("writeMethod","fastWrite");
3 liveuser 931
		#$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
220 liveuser 932
		$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array("string","string");
3 liveuser 933
		#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
934
		$argu=&$conf;
935
		#可省略參數:
936
		#$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"],字串陣列,每個不存的變數要初始化為什麼,"null"代表不指定.
220 liveuser 937
		$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array("w","false");
3 liveuser 938
		#無
939
		$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
940
		unset($conf["variableCheck.checkSkipableVarType"]);
226 liveuser 941
 
3 liveuser 942
		#如果檢查不通過
943
		if($checkResult["status"]=="false"){
226 liveuser 944
 
3 liveuser 945
			#設置執行錯誤
946
			$result["status"]="false";
226 liveuser 947
 
3 liveuser 948
			#設置執行錯誤訊息
949
			$result["error"]=$checkResult;
226 liveuser 950
 
3 liveuser 951
			#回傳結果
952
			return $result;
226 liveuser 953
 
3 liveuser 954
			}#if end
226 liveuser 955
 
3 liveuser 956
		#如果檢查不通過
957
		if($checkResult["passed"]=="false"){
226 liveuser 958
 
3 liveuser 959
			#設置執行錯誤
960
			$result["status"]="false";
226 liveuser 961
 
3 liveuser 962
			#設置執行錯誤訊息
963
			$result["error"]=$checkResult;
226 liveuser 964
 
3 liveuser 965
			#回傳結果
966
			return $result;
226 liveuser 967
 
3 liveuser 968
			}#if end
969
 
220 liveuser 970
		#如果有設置快速寫入
971
		if($conf["fastWrite"]==="true"){
226 liveuser 972
 
220 liveuser 973
			#初始化要寫入的字串
974
			$inputStrAll="";
226 liveuser 975
 
220 liveuser 976
			#有幾行字要寫就執行幾次
977
			foreach($conf["inputString"] as $inputStr){
978
 
979
				#附加 "\r\n"
980
				$inputStrAll=$inputStrAll.$inputStr.PHP_EOL;
981
 
982
				}#foreach end
226 liveuser 983
 
220 liveuser 984
			#函式說明:
985
			#將字串寫入到檔案
986
			#回傳結果:
987
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
988
			#$result["error"],錯誤訊息陣列.
989
			#必填參數:
990
			$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
991
			$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStrAll;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
992
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
993
			$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
994
			#可省略參數:
995
			$conf["fileAccess.writeTextIntoFile"]["writeMethod"]=$conf["writeMethod"];#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
996
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
997
			$conf["fileAccess.writeTextIntoFile"]["web"]="false";
998
			$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
999
			unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 1000
 
220 liveuser 1001
			#如果寫入失敗
1002
			if($writeStatus["status"]=="false"){
226 liveuser 1003
 
220 liveuser 1004
				#設置執行錯誤
1005
				$result["status"]="false";
226 liveuser 1006
 
220 liveuser 1007
				#設置執行錯誤訊息
1008
				$result["error"]=$writeStatus;
226 liveuser 1009
 
220 liveuser 1010
				#回傳結果
1011
				return $result;
226 liveuser 1012
 
220 liveuser 1013
				}#if end
226 liveuser 1014
 
220 liveuser 1015
			#設置執行正常
1016
			$result["status"]="true";
226 liveuser 1017
 
220 liveuser 1018
			#回傳結果
1019
			return $result;
226 liveuser 1020
 
220 liveuser 1021
			}#if end
1022
 
3 liveuser 1023
		#初始化第一次寫入識別變數
1024
		$firstTimeToWrite="true";
226 liveuser 1025
 
3 liveuser 1026
		#有幾行字要寫就執行幾次
1027
		foreach($conf["inputString"] as $inputStr){
1028
 
1029
			#附加 "\r\n"
1030
			$inputStr=$inputStr.PHP_EOL;
1031
 
1032
			#如果是第一次寫入
1033
			if($firstTimeToWrite=="true"){
226 liveuser 1034
 
3 liveuser 1035
				#如果是要重新寫入
220 liveuser 1036
				if($conf["writeMethod"]==="w"){
226 liveuser 1037
 
3 liveuser 1038
					#函式說明:
1039
					#將字串寫入到檔案
1040
					#回傳結果:
1041
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1042
					#$result["error"],錯誤訊息陣列.
1043
					#必填參數:
1044
					$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
1045
					$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStr;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1046
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1047
					$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1048
					#可省略參數:
1049
					$conf["fileAccess.writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1050
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1051
					$conf["fileAccess.writeTextIntoFile"]["web"]="false";
1052
					$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
1053
					unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 1054
 
3 liveuser 1055
					#如果寫入失敗
1056
					if($writeStatus["status"]=="false"){
226 liveuser 1057
 
3 liveuser 1058
						#設置執行錯誤
1059
						$result["status"]="false";
226 liveuser 1060
 
3 liveuser 1061
						#設置執行錯誤訊息
1062
						$result["error"]=$writeStatus;
226 liveuser 1063
 
3 liveuser 1064
						#回傳結果
1065
						return $result;
226 liveuser 1066
 
3 liveuser 1067
						}#if end
226 liveuser 1068
 
3 liveuser 1069
					}#if end
226 liveuser 1070
 
3 liveuser 1071
				#反之不是重新寫入,而是附加寫入。
1072
				else{
226 liveuser 1073
 
3 liveuser 1074
					#函式說明:
1075
					#將字串寫入到檔案
1076
					#回傳結果:
1077
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1078
					#$result["error"],錯誤訊息陣列.
1079
					#必填參數:
1080
					$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
1081
					$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStr;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1082
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1083
					$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1084
					#可省略參數:
1085
					$conf["fileAccess.writeTextIntoFile"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1086
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1087
					$conf["fileAccess.writeTextIntoFile"]["web"]="false";
1088
					$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
1089
					unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 1090
 
3 liveuser 1091
					#如果寫入失敗
1092
					if($writeStatus["status"]=="false"){
226 liveuser 1093
 
3 liveuser 1094
						#設置執行錯誤
1095
						$result["status"]="false";
226 liveuser 1096
 
3 liveuser 1097
						#設置執行錯誤訊息
1098
						$result["error"]=$writeStatus;
226 liveuser 1099
 
3 liveuser 1100
						#回傳結果
1101
						return $result;
226 liveuser 1102
 
3 liveuser 1103
						}#if end
226 liveuser 1104
 
3 liveuser 1105
					}#else end
226 liveuser 1106
 
3 liveuser 1107
				#將之設為不是第一次寫入
1108
				$firstTimeToWrite="false";
226 liveuser 1109
 
3 liveuser 1110
				}#if end
226 liveuser 1111
 
3 liveuser 1112
			#反之不是第一次寫入
1113
			else{
226 liveuser 1114
 
3 liveuser 1115
				#函式說明:
1116
				#將字串寫入到檔案
1117
				#回傳結果:
1118
				#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1119
				#$result["error"],錯誤訊息陣列.
1120
				#必填參數:
1121
				$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
1122
				$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStr;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1123
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1124
				$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1125
				#可省略參數:
1126
				$conf["fileAccess.writeTextIntoFile"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1127
				#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1128
				$conf["fileAccess.writeTextIntoFile"]["web"]="false";
1129
				$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
1130
				unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 1131
 
3 liveuser 1132
				#如果寫入失敗
1133
				if($writeStatus["status"]=="false"){
226 liveuser 1134
 
3 liveuser 1135
					#設置執行錯誤
1136
					$result["status"]="false";
226 liveuser 1137
 
3 liveuser 1138
					#設置執行錯誤訊息
1139
					$result["error"]=$writeStatus;
226 liveuser 1140
 
3 liveuser 1141
					#回傳結果
1142
					return $result;
226 liveuser 1143
 
3 liveuser 1144
					}#if end
226 liveuser 1145
 
3 liveuser 1146
				}#else end
226 liveuser 1147
 
3 liveuser 1148
			}#foreach end
226 liveuser 1149
 
3 liveuser 1150
		#執行到這邊代表一切正常
1151
		$result["status"]="true";
226 liveuser 1152
 
3 liveuser 1153
		#回傳結果
1154
		return $result;
226 liveuser 1155
 
3 liveuser 1156
		}#function writeMultiLine end
226 liveuser 1157
 
3 liveuser 1158
	/*
1159
	#函式說明:
1160
	#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1161
	#回傳的變數說明:
1162
	#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1163
	#$result["error"],錯誤訊息提示.
374 liveuser 1164
	#$result["fileNotExist"],字串,"true"代表目標檔案不存在;"false"代表目標檔案存在.
1165
	#$result["fileCreated"],字串,"true"代表目標檔案被本函式建立;"false"代表檔案不是透過本函式建立.
3 liveuser 1166
	#$result["function"],當前執行的函數名稱.
1167
	#$result["fileContent"],爲檔案的內容陣列.
1168
	#$result["lineCount"],爲檔案內容總共的行數.
1169
	#$result["fullContent"],為檔案的完整內容.
200 liveuser 1170
	#$result["base64dataOnly"],檔案的base64data.
1171
	#$result["base64data"],為在網頁上給予src參數的數值.
3 liveuser 1172
	#$result["mimeType"],為檔案的mime type.
1173
	#必填參數:
1174
	#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
1175
	$conf["filePositionAndName"]="";
1176
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1177
	$conf["fileArgu"]=__FILE__;
1178
	#可省略參數:
1179
	#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
1180
	#$conf["web"]="true";
1181
	#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
1182
	#$conf["createIfnotExist"]="false";
1183
	#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
1184
	#$conf["autoDeleteSpaceOnEachLineStart"]="false";
391 liveuser 1185
	#$conf["disableReturnBase64"],字串,預設為"false"代表要回傳base64結果,反之為"true".
1186
	#$conf["disableReturnBase64"]="false";
3 liveuser 1187
	#參考資料:
1188
	#file(),取得檔案內容的行數.
1189
	#file=>http:#php.net/manual/en/function.file.php
1190
	#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1191
	#filesize=>http://php.net/manual/en/function.filesize.php
1192
	#參考資料:
1193
	#無.
1194
	#備註:
1195
	#無.
1196
	*/
249 liveuser 1197
	public static function getFileContent(&$conf){
3 liveuser 1198
 
1199
		#初始化要回傳的內容
1200
		$result=array();
226 liveuser 1201
 
3 liveuser 1202
		#取得當前執行函數名稱
1203
		$result["function"]=__FUNCTION__;
374 liveuser 1204
 
1205
		#設置預設檔案不存在的識別
376 liveuser 1206
		$result["fileNotExist"]="true";
374 liveuser 1207
 
1208
		#設置預設檔案不為本函式所建立
1209
		$result["fileCreated"]="false";
3 liveuser 1210
 
1211
		#如果 $conf 不為陣列
1212
		if(gettype($conf)!="array"){
226 liveuser 1213
 
3 liveuser 1214
			#設置執行失敗
1215
			$result["status"]="false";
226 liveuser 1216
 
3 liveuser 1217
			#設置執行錯誤訊息
1218
			$result["error"][]="\$conf變數須為陣列形態";
1219
 
1220
			#如果傳入的參數為 null
1221
			if($conf==null){
226 liveuser 1222
 
3 liveuser 1223
				#設置執行錯誤訊息
1224
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1225
 
3 liveuser 1226
				}#if end
1227
 
1228
			#回傳結果
1229
			return $result;
226 liveuser 1230
 
3 liveuser 1231
			}#if end
1232
 
1233
		#檢查參數
1234
		#函式說明:
1235
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
1236
		#回傳結果:
1237
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1238
		#$result["error"],執行不正常結束的錯訊息陣列.
1239
		#$result["simpleError"],簡單表示的錯誤訊息.
1240
		#$result["function"],當前執行的函式名稱.
1241
		#$result["argu"],設置給予的參數.
1242
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1243
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1244
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1245
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1246
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1247
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1248
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1249
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1250
		#必填參數:
1251
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1252
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1253
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1254
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1255
		#可省略參數:
1256
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1257
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePositionAndName","fileArgu");
1258
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
1259
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
1260
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1261
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1262
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
1263
		#$conf["canNotBeEmpty"]=array();
1264
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
1265
		#$conf["canBeEmpty"]=array();
1266
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
391 liveuser 1267
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("createIfnotExist","web","autoDeleteSpaceOnEachLineStart","disableReturnBase64");
3 liveuser 1268
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
391 liveuser 1269
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("createIfnotExist","web","autoDeleteSpaceOnEachLineStart","disableReturnBase64");
3 liveuser 1270
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
391 liveuser 1271
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
3 liveuser 1272
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
391 liveuser 1273
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false","false");
3 liveuser 1274
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
1275
		#$conf["disallowAllSkipableVarIsEmpty"]="";
1276
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
1277
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
1278
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
1279
		#$conf["disallowAllSkipableVarNotExist"]="";
1280
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1281
		#$conf["arrayCountEqualCheck"][]=array();
1282
		#參考資料:
1283
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1284
		#備註:
1285
		#無.
1286
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1287
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 1288
 
3 liveuser 1289
		#如果檢查出錯
1290
		if($checkArguments["status"]==="false"){
226 liveuser 1291
 
3 liveuser 1292
			#設置執行錯誤識別
1293
			$result["status"]="false";
226 liveuser 1294
 
3 liveuser 1295
			#設置執行錯誤訊息
1296
			$result["error"]=$checkArguments;
226 liveuser 1297
 
3 liveuser 1298
			#回傳結果
1299
			return $result;
226 liveuser 1300
 
3 liveuser 1301
			}#if end
226 liveuser 1302
 
3 liveuser 1303
		#如果檢查參數不通過
1304
		if($checkArguments["passed"]==="false"){
226 liveuser 1305
 
3 liveuser 1306
			#設置執行錯誤識別
1307
			$result["status"]="false";
226 liveuser 1308
 
3 liveuser 1309
			#設置執行錯誤訊息
1310
			$result["error"]=$checkArguments;
226 liveuser 1311
 
3 liveuser 1312
			#回傳結果
1313
			return $result;
226 liveuser 1314
 
3 liveuser 1315
			}#if end
226 liveuser 1316
 
3 liveuser 1317
		#檢查檔案是否存在
1318
		#函式說明:檢查多個檔案與資料夾是否存在
1319
		#回傳的結果:
1320
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1321
		#$result["error"],錯誤訊息陣列.
1322
		#$resutl["function"],當前執行的涵式名稱.
1323
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1324
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
1325
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1326
		#必填參數:
1327
		$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($conf["filePositionAndName"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
1328
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1329
		$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
1330
		#可省略參數:
1331
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1332
		$conf["fileAccess"]["checkMutiFileExist"]["disableWebSearch"]="true";
226 liveuser 1333
 
3 liveuser 1334
		#如果有設置 $conf["web"]
1335
		if(isset($conf["web"])){
226 liveuser 1336
 
3 liveuser 1337
			#設置 web 參數.
1338
			$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
226 liveuser 1339
 
3 liveuser 1340
			}#if end
226 liveuser 1341
 
3 liveuser 1342
		#參考資料來源:
1343
		#http:#php.net/manual/en/function.file-exists.php
1344
		#http:#php.net/manual/en/control-structures.foreach.php
1345
		$fileCheckResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
1346
		unset($conf["fileAccess"]["checkMutiFileExist"]);
1347
 
1348
		#如果檢查檔案是否存在出錯
1349
		if($fileCheckResult["status"]=="false"){
226 liveuser 1350
 
3 liveuser 1351
			#設置執行錯誤識別
1352
			$result["status"]="false";
226 liveuser 1353
 
3 liveuser 1354
			#設置執行錯誤訊息
1355
			$result["error"]=$fileCheckResult;
226 liveuser 1356
 
3 liveuser 1357
			#回傳結果
1358
			return $result;
226 liveuser 1359
 
3 liveuser 1360
			}#if end
1361
 
1362
		#如果該檔案不存在
1363
		if($fileCheckResult["varExist"][0]=="false"){
226 liveuser 1364
 
3 liveuser 1365
			#如果也不要自動建立檔案
1366
			if($conf["createIfnotExist"]==="false"){
226 liveuser 1367
 
3 liveuser 1368
				#設置執行錯誤識別
1369
				$result["status"]="false";
226 liveuser 1370
 
3 liveuser 1371
				#設置執行錯誤訊息
1372
				$result["error"]=$fileCheckResult;
226 liveuser 1373
 
3 liveuser 1374
				#設置易讀的錯誤訊息
1375
				$result["error"][]="名為".$fileCheckResult["varName"][0]."的檔案不存在";
226 liveuser 1376
 
3 liveuser 1377
				#回傳結果
1378
				return $result;
226 liveuser 1379
 
3 liveuser 1380
				}#if end
226 liveuser 1381
 
3 liveuser 1382
			#執行到這邊代表需要建立該檔案
1383
			#函式說明:
1384
			#將字串寫入到檔案
1385
			#回傳結果:
1386
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1387
			#$result["error"],錯誤訊息陣列.
1388
			#$result["function"],當前執行的函數名稱.
1389
			#$result["fileInfo"],實際上寫入的檔案資訊陣列.
1390
			#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
1391
			#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
1392
			#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
1393
			#$result["argu"],使用的參數.
1394
			#必填參數:
1395
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1396
			$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1397
			#可省略參數:
1398
			#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
1399
			$conf["fileAccess::writeTextIntoFile"]["fileName"]=$fileCheckResult["varNameFullPath"][0];
1400
			#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
200 liveuser 1401
			$conf["fileAccess::writeTextIntoFile"]["inputString"]="";
3 liveuser 1402
			#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
1403
			#$conf["checkRepeat"]="";
1404
			#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
1405
			#$conf["filenameExtensionStartPoint"]="";
1406
			#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
1407
			#$conf["repeatNameRule"]="";
226 liveuser 1408
 
3 liveuser 1409
			#如果有設置 $conf["web"]
1410
			if(isset($conf["web"])){
226 liveuser 1411
 
3 liveuser 1412
				#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1413
				$conf["fileAccess::writeTextIntoFile"]["web"]=$conf["web"];
226 liveuser 1414
 
200 liveuser 1415
				}#if end
226 liveuser 1416
 
3 liveuser 1417
			#參考資料:
1418
			#無.
1419
			#備註:
1420
			#無.
1421
			$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
1422
			unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 1423
 
3 liveuser 1424
			#如果建立檔案失敗
1425
			if($writeTextIntoFile["status"]=="false"){
226 liveuser 1426
 
3 liveuser 1427
				#設置執行錯誤識別
1428
				$result["status"]="false";
226 liveuser 1429
 
3 liveuser 1430
				#設置執行錯誤訊息
1431
				$result["error"]=$writeTextIntoFile;
226 liveuser 1432
 
3 liveuser 1433
				#回傳結果
1434
				return $result;
226 liveuser 1435
 
3 liveuser 1436
				}#if end
374 liveuser 1437
 
1438
			#設置檔案存在的識別
376 liveuser 1439
			$result["fileNotExist"]="false";
374 liveuser 1440
 
1441
			#設置檔案為本函式所建立
1442
			$result["fileCreated"]="true";
226 liveuser 1443
 
3 liveuser 1444
			}#if end
374 liveuser 1445
 
1446
		#反之
1447
		else{
1448
 
1449
			#設置檔案存在的識別
376 liveuser 1450
			$result["fileNotExist"]="false";
374 liveuser 1451
 
1452
			}#else end
3 liveuser 1453
 
1454
		#file absolute addr
1455
		$fileAbAddr=$fileCheckResult["varNameFullPath"][0];
226 liveuser 1456
 
3 liveuser 1457
		#將檔案的內容放進變數裡面(會得到陣列)
1458
		$fileContent=file($fileAbAddr);
1459
 
1460
		#如果 $fileContent 等於
376 liveuser 1461
		if($fileContent===FALSE){
3 liveuser 1462
 
376 liveuser 1463
			#設置錯誤識別
1464
			$result["status"]="false";
226 liveuser 1465
 
376 liveuser 1466
			#設置錯誤訊息
1467
			$result["error"][]="讀取檔案失敗";
3 liveuser 1468
 
376 liveuser 1469
			#取得詳細的錯誤訊息
1470
			$result["error"][]=$fileCheckResult;
226 liveuser 1471
 
376 liveuser 1472
			#回傳結果
1473
			return $result;
3 liveuser 1474
 
1475
			}#if end
1476
 
1477
		#針對每行內容
1478
		for($i=0;$i<count($fileContent);$i++){
226 liveuser 1479
 
3 liveuser 1480
			#剔除字串尾的換行符號
1481
			$fileContent[$i]=rtrim($fileContent[$i]);
226 liveuser 1482
 
3 liveuser 1483
			#如果要移除開頭的空白
1484
			if($conf["autoDeleteSpaceOnEachLineStart"]==="true"){
226 liveuser 1485
 
3 liveuser 1486
				#如果開頭是空格
1487
				while(strpos($fileContent[$i]," ")===0){
226 liveuser 1488
 
3 liveuser 1489
					#函式說明:
1490
					#將字串特定關鍵字與其前面的內容剔除
1491
					#回傳結果:
1492
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1493
					#$result["error"],錯誤訊息陣列.
1494
					#$result["warning"],警告訊息鎮列.
1495
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
1496
					#$result["function"],當前執行的函數名稱.
1497
					#$result["argu"],使用的參數.
1498
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 1499
					#$result["content"],處理好的的字串內容.
3 liveuser 1500
					#必填參數:
1501
					#$conf["stringIn"],字串,要處理的字串.
1502
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$fileContent[$i];
1503
					#$conf["keyWord"],字串,特定字串.
1504
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
1505
					#可省略參數:
1506
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
1507
					#$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
1508
					#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
1509
					#$conf["lastResult"]=$delStrBeforeKeyWord;
1510
					#參考資料:
1511
					#無.
1512
					#備註:
1513
					#無.
1514
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
1515
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 1516
 
3 liveuser 1517
					#如果建立檔案失敗
1518
					if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 1519
 
3 liveuser 1520
						#設置執行錯誤識別
1521
						$result["status"]="false";
226 liveuser 1522
 
3 liveuser 1523
						#設置執行錯誤訊息
1524
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 1525
 
3 liveuser 1526
						#回傳結果
1527
						return $result;
226 liveuser 1528
 
3 liveuser 1529
						}#if end
226 liveuser 1530
 
3 liveuser 1531
					#取得剔除開頭空格後的內容
1532
					$fileContent[$i]=$delStrBeforeKeyWord["content"];
226 liveuser 1533
 
3 liveuser 1534
					}#while end
226 liveuser 1535
 
3 liveuser 1536
				}#if end
226 liveuser 1537
 
3 liveuser 1538
			}#for end
1539
 
1540
		#取得總共有幾行
1541
		$lineCount=count($fileContent);
1542
 
1543
		#將檔案內容的陣列放進 $result 陣列變數裏面
1544
		$result["fileContent"]=$fileContent;
226 liveuser 1545
 
3 liveuser 1546
		#建立暫存檔案
1547
		$tmpFile=tempnam("/tmp", "qbpwcf");
226 liveuser 1548
 
3 liveuser 1549
		#讀取要取得的檔案內容
1550
		$content=file_get_contents($fileAbAddr);
226 liveuser 1551
 
3 liveuser 1552
		#開啟暫存檔案(寫入模式)
1553
		$file=fopen($tmpFile,'w');
226 liveuser 1554
 
3 liveuser 1555
		#寫入讀取到的內容
1556
		fwrite($file,$content);
226 liveuser 1557
 
3 liveuser 1558
		#關閉暫存檔案
1559
		fclose($file);
226 liveuser 1560
 
3 liveuser 1561
		#取得檔案的 mime 類型
1562
		$mimeType=mime_content_type($tmpFile);
226 liveuser 1563
 
3 liveuser 1564
		#設置檔案的mime類型
1565
		$result["mimeType"]=$mimeType;
226 liveuser 1566
 
3 liveuser 1567
		#取得檔案的內容為字串
1568
		$result["fullContent"]=file_get_contents($tmpFile);
226 liveuser 1569
 
391 liveuser 1570
		#如果沒有要停用回傳base64結果
1571
		if($conf["disableReturnBase64"]==="false"){
226 liveuser 1572
 
391 liveuser 1573
			#取得檔案的base64data
1574
			$result["base64dataOnly"]=base64_encode($result["fullContent"]);
226 liveuser 1575
 
391 liveuser 1576
			#取得檔案用 data:mimeType;base64,base64data 表示的字串
1577
			$result["base64data"]="data:".$result["mimeType"].";base64,".$result["base64dataOnly"];
1578
 
1579
			}#if end
1580
 
3 liveuser 1581
		#移除暫存檔案
1582
		unlink($tmpFile);
226 liveuser 1583
 
3 liveuser 1584
		#將檔案內容的行數放進 $result 陣列變數裏面
1585
		$result["lineCount"]=$lineCount;
1586
 
1587
		#執行到這邊代表執行成功
1588
		$result["status"]="true";
1589
 
1590
		#回傳結果
1591
		return $result;
1592
 
1593
		}#function getFileContent end
1594
 
1595
	/*
1596
	#函式說明:
1597
	#依據逗號分隔抓取檔案的內容,結果會回傳一個陣列
226 liveuser 1598
	#回傳結果:
3 liveuser 1599
	#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1600
	#$result["error"],錯誤訊息提示.
1601
	#$result["function"],函數名稱.
1602
	#$result["lineCount"]爲總共有幾行
1603
	#$result["lineContent"][i]["dataCounts"],爲第 i+1 行總共有幾個字串
1604
	#$result["lineContent"][0][i],爲第1行第 i+1 個分割好的字串
1605
	#$result["lineContent"][1][i],爲第2行第 i+1 個分割好的字串
1606
	#必填參數:
1607
	#$conf["filePositionAndName"],字串,要抓取的檔案位置與名稱
1608
	$conf["filePositionAndName"]="";
1609
	#可省略參數:
1610
	#$conf["spiltSign"],字串,爲要用來分割字串的符號,可省略,預設爲「,」
1611
	#$conf["spiltSign"]="";
1612
	#參考資料:
1613
	#無.
1614
	#備註:
1615
	#無.
1616
	*/
249 liveuser 1617
	public static function getFileContentSpiltBySomething(&$conf){
3 liveuser 1618
 
1619
		#初始化要回傳的內容
1620
		$result=array();
226 liveuser 1621
 
3 liveuser 1622
		#取得當前執行函數名稱
1623
		$result["function"]=__FUNCTION__;
1624
 
1625
		#如果 $conf 不為陣列
1626
		if(gettype($conf)!="array"){
226 liveuser 1627
 
3 liveuser 1628
			#設置執行失敗
1629
			$result["status"]="false";
226 liveuser 1630
 
3 liveuser 1631
			#設置執行錯誤訊息
1632
			$result["error"][]="\$conf變數須為陣列形態";
1633
 
1634
			#如果傳入的參數為 null
1635
			if($conf==null){
226 liveuser 1636
 
3 liveuser 1637
				#設置執行錯誤訊息
1638
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1639
 
3 liveuser 1640
				}#if end
1641
 
1642
			#回傳結果
1643
			return $result;
226 liveuser 1644
 
3 liveuser 1645
			}#if end
1646
 
1647
		#如果 $conf["spiltSign"] 爲空,則預設爲","。
1648
		if(!isset($conf["spiltSign"])){
1649
 
1650
			$conf["spiltSign"]=",";
1651
 
1652
			}#if end
1653
 
1654
		#依據行號抓取所有的內容
1655
		#函式說明:
1656
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1657
		#回傳的變數說明:
1658
		#$result["fileContent"],爲檔案的內容陣列
1659
		#$result["lineCount"],爲檔案內容總共的行數
1660
		#必填參數:
1661
		$conf["fileAccess"]["getFileContent"]["filePositionAndName"]=$conf["filePositionAndName"];#爲檔案的位置以及名稱
1662
		#參考資料:
1663
		#file():取得檔案內容的行數
1664
		#http:#php.net/manual/en/function.file.php
1665
		$fileContent=fileAccess::getFileContent($conf["fileAccess"]["getFileContent"]);
1666
		unset($conf["fileAccess"]["getFileContent"]);
1667
 
1668
		#如果取得檔案內容失敗
1669
		if($fileContent["status"]=="false"){
226 liveuser 1670
 
3 liveuser 1671
			#設置執行失敗
1672
			$result["status"]="false";
226 liveuser 1673
 
3 liveuser 1674
			#設置執行錯誤訊息
1675
			$result["error"]=$fileContent;
1676
 
1677
			#回傳結果
1678
			return $result;
226 liveuser 1679
 
3 liveuser 1680
			}#if end
1681
 
1682
		#迴圈,有幾行資料就執行幾次
1683
		for($i=0;$i<$fileContent["lineCount"];$i++){
1684
 
1685
			#將該行內容用逗號分隔
1686
			$conf["stringProcess"]["spiltString"]["stringIn"]=$fileContent["fileContent"][$i];#要處理的字串。
1687
			$conf["stringProcess"]["spiltString"]["spiltSymbol"]=$conf["spiltSign"];#爲以哪個符號作爲分割
1688
			$lineSpiltResult[$i]=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
226 liveuser 1689
			unset($conf["stringProcess"]["spiltString"]);
3 liveuser 1690
 
1691
			#如果分割字串失敗
1692
			if($lineSpiltResult[$i]["status"]=="false"){
226 liveuser 1693
 
3 liveuser 1694
				#設置執行失敗
1695
				$result["status"]="false";
226 liveuser 1696
 
3 liveuser 1697
				#設置執行錯誤訊息
1698
				$result["error"]=$lineSpiltResult[$i];
1699
 
1700
				#回傳結果
1701
				return $result;
226 liveuser 1702
 
3 liveuser 1703
				}#if end
1704
 
1705
			}#for end
1706
 
1707
		#取得
1708
		$result["lineContent"]=$lineSpiltResult;
1709
 
1710
		#取得資料的行數
1711
		$result["lineCount"]=$fileContent["lineCount"];
1712
 
1713
		#回傳結果
1714
		return $result;
226 liveuser 1715
 
3 liveuser 1716
		}#function getFileContentSpiltBySomething end
1717
 
1718
	/*
1719
	#函式說明:
1720
	#檢查多個檔案與資料夾是否存在.
1721
	#回傳的結果:
1722
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1723
	#$result["error"],錯誤訊息陣列.
1724
	#$resutl["function"],當前執行的涵式名稱.
1725
	#$result["argu"],使用的參數.
1726
	#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1727
	#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
1728
	#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
1729
	#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
1730
	#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1731
	#必填參數:
1732
	#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
1733
	$conf["fileArray"]=array();
1734
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1735
	$conf["fileArgu"]=__FILE__;
1736
	#可省略參數:
1737
	#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1738
	#$conf["disableWebSearch"]="false";
1739
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
1740
	#$conf["userDir"]="true";
1741
	#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
1742
	#$conf["web"]="true";
1743
	#參考資料:
1744
	#http://php.net/manual/en/function.file-exists.php
1745
	#http://php.net/manual/en/control-structures.foreach.php
1746
	#備註:
1747
	#函數file_exists檢查的路徑為檔案系統的路徑
1748
	#$result["varName"][$i]結果未實作
1749
	*/
1750
	public static function checkMultiFileExist(&$conf){
226 liveuser 1751
 
3 liveuser 1752
		#初始化要回傳的變數
1753
		$result=array();
226 liveuser 1754
 
3 liveuser 1755
		#設置當前執行的涵式
1756
		$result["function"]=__FUNCTION__;
226 liveuser 1757
 
3 liveuser 1758
		#如果 $conf 不為陣列
1759
		if(gettype($conf)!="array"){
226 liveuser 1760
 
3 liveuser 1761
			#設置執行失敗
1762
			$result["status"]="false";
226 liveuser 1763
 
3 liveuser 1764
			#設置執行錯誤訊息
1765
			$result["error"][]="\$conf變數須為陣列形態";
1766
 
1767
			#如果傳入的參數為 null
1768
			if($conf==null){
226 liveuser 1769
 
3 liveuser 1770
				#設置執行錯誤訊息
1771
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1772
 
3 liveuser 1773
				}#if end
1774
 
1775
			#回傳結果
1776
			return $result;
226 liveuser 1777
 
3 liveuser 1778
			}#if end
226 liveuser 1779
 
3 liveuser 1780
		#取得使用的參數
1781
		$result["argu"]=$conf;
226 liveuser 1782
 
3 liveuser 1783
		#檢查參數
1784
		#函式說明:
1785
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1786
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1787
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1788
		#$result["function"],當前執行的函式名稱.
1789
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1790
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1791
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1792
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
1793
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1794
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1795
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1796
		#必填寫的參數:
1797
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1798
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1799
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1800
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArray","fileArgu");
226 liveuser 1801
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 1802
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
1803
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1804
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1805
		#可以省略的參數:
1806
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1807
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1808
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1809
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("disableWebSearch","userDir","web");
226 liveuser 1810
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 1811
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1812
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1813
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true","true","true");
1814
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1815
		#$conf["arrayCountEqualCheck"][]=array();
1816
		#參考資料來源:
1817
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1818
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1819
		unset($conf["variableCheck::checkArguments"]);
1820
 
1821
		#如果 $checkArguments["status"] 等於 "false"
1822
		if($checkArguments["status"]=="false"){
226 liveuser 1823
 
3 liveuser 1824
			#設置錯誤識別
1825
			$result["status"]="false";
226 liveuser 1826
 
3 liveuser 1827
			#設置錯誤訊息
1828
			$result["error"]=$checkArguments;
226 liveuser 1829
 
3 liveuser 1830
			#回傳結果
42 liveuser 1831
			return $result;
226 liveuser 1832
 
3 liveuser 1833
			}#if end
226 liveuser 1834
 
3 liveuser 1835
		#如果 $checkArguments["passed"] 等於 "false"
1836
		if($checkArguments["passed"]=="false"){
226 liveuser 1837
 
3 liveuser 1838
			#設置錯誤識別
1839
			$result["status"]="false";
226 liveuser 1840
 
3 liveuser 1841
			#設置錯誤訊息
1842
			$result["error"]=$checkArguments;
226 liveuser 1843
 
3 liveuser 1844
			#回傳結果
42 liveuser 1845
			return $result;
226 liveuser 1846
 
3 liveuser 1847
			}#if end
226 liveuser 1848
 
3 liveuser 1849
		#初始化儲存每個檔案是否存在的陣列變數
1850
		$result["varName"]=array();
1851
		$result["varExist"]=array();
1852
 
1853
		#針對每個要檢查的檔案
1854
		foreach($conf["fileArray"] as $i=>$varName){
226 liveuser 1855
 
3 liveuser 1856
			#儲存要判斷是否存在的物件
1857
			$result["varName"][]=$varName;
226 liveuser 1858
 
3 liveuser 1859
			#函式說明:
1860
			#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
1861
			#回傳結果:
1862
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1863
			#$result["error"],錯誤訊息陣列.
226 liveuser 1864
			#$result["function"],函數名稱.
3 liveuser 1865
			#$result["argu"],使用的參數.
1866
			#$result["content"],網址,若是在命令列執行,則為"null".
1867
			#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
1868
			#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
1869
			#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
1870
			#必填參數:
1871
			#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
1872
			$conf["fileAccess::getInternetAddressV2"]["address"]=$varName;
1873
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1874
			$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
1875
			#可省略參數:
1876
			$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
1877
			#備註:
1878
			#建構中,fileSystemRelativePosition尚未實作.
1879
			$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
1880
			unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 1881
 
3 liveuser 1882
			#如果轉換成絕對路徑失敗
1883
			if($getInternetAddressV2["status"]=="false"){
226 liveuser 1884
 
3 liveuser 1885
				#設置錯誤識別
1886
				$result["status"]="false";
226 liveuser 1887
 
3 liveuser 1888
				#設置錯誤訊息
1889
				$result["error"]=$getInternetAddressV2;
226 liveuser 1890
 
3 liveuser 1891
				#回傳結果
1892
				return $result;
226 liveuser 1893
 
3 liveuser 1894
				}#if end
226 liveuser 1895
 
3 liveuser 1896
			#傳參考
1897
			$getInternetAddress=&$getInternetAddressV2;
226 liveuser 1898
 
3 liveuser 1899
			#如果沒有檔案的絕對路徑位置
1900
			if(!isset($getInternetAddress["fileSystemAbsoulutePosition"])){
226 liveuser 1901
 
3 liveuser 1902
				#置換成給予的參數網址
1903
				$conf["fileArray"][$i]=$getInternetAddress["content"];
226 liveuser 1904
 
3 liveuser 1905
				#設置無法從檔案系統找到
1906
				$exist=FALSE;
226 liveuser 1907
 
3 liveuser 1908
				}#if end
226 liveuser 1909
 
3 liveuser 1910
			#反之取得
1911
			else{
226 liveuser 1912
 
3 liveuser 1913
				#轉換好的絕對路徑
1914
				$conf["fileArray"][$i]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 1915
 
42 liveuser 1916
				#無窮迴圈
1917
				while(true){
226 liveuser 1918
 
42 liveuser 1919
					#判斷該檔案是否存在
1920
					$exist=file_exists($conf["fileArray"][$i]);
226 liveuser 1921
 
42 liveuser 1922
					#如果不存在
1923
					if($exist===false){
226 liveuser 1924
 
42 liveuser 1925
						#無窮迴圈
1926
						while(true){
226 liveuser 1927
 
42 liveuser 1928
							#當要檢查的目標是 link 時
1929
							if(is_link($conf["fileArray"][$i])){
226 liveuser 1930
 
42 liveuser 1931
								#取得link的路徑
1932
								$conf["fileArray"][$i]=readlink($conf["fileArray"][$i]);
226 liveuser 1933
 
42 liveuser 1934
								#結束連結的判斷,回到判斷目標是否存在的地方.
1935
								continue 2;
226 liveuser 1936
 
42 liveuser 1937
								}#if end
226 liveuser 1938
 
42 liveuser 1939
							#結束連結的判斷
1940
							break;
226 liveuser 1941
 
42 liveuser 1942
							}#while end
226 liveuser 1943
 
42 liveuser 1944
						}#if end
226 liveuser 1945
 
42 liveuser 1946
					#結束到判斷目標是否存在
1947
					break;
226 liveuser 1948
 
42 liveuser 1949
					}#while end
226 liveuser 1950
 
3 liveuser 1951
				}#else end
226 liveuser 1952
 
3 liveuser 1953
			#如果 $exist 等於 false (檔案不存在) 且 沒有停用網路搜尋功能
1954
			if($exist===FALSE && $conf["disableWebSearch"]==="false"){
1955
 
1956
				#將目標轉換成網址
1957
				#函式說明:
1958
				#將檔案的位置名稱變成網址
1959
				#回傳結果:
1960
				#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1961
				#$result["error"],錯誤訊息陣列.
226 liveuser 1962
				#$result["function"],函數名稱.
3 liveuser 1963
				#$result["content"],網址.
1964
				#必填參數:
1965
				#$conf["address"],字串,檔案的相對位置.
1966
				$conf["fileAccess::getInternetAddress"]["address"]=$conf["fileArray"][$i];
1967
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1968
				$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
1969
				$getInternetAddress=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddress"]);
1970
				unset($conf["fileAccess::getInternetAddress"]);
1971
 
1972
				#如果轉換失敗
1973
				if($getInternetAddress["status"]=="false"){
226 liveuser 1974
 
3 liveuser 1975
					#設置錯誤識別
1976
					$result["status"]="false";
226 liveuser 1977
 
3 liveuser 1978
					#設置錯誤訊息
1979
					$result["error"]=$getInternetAddress;
226 liveuser 1980
 
3 liveuser 1981
					#回傳結果
226 liveuser 1982
					return $result;
1983
 
3 liveuser 1984
					}#if end
226 liveuser 1985
 
3 liveuser 1986
				#函式說明:
1987
				#運行curl cmd
1988
				#回傳結果:
1989
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1990
				#$result["error"],錯誤訊息陣列.
1991
				#$result["function"],當前執行的函式名稱.
1992
				#$result["content"],取得的回應內容.
1993
				#$result["cookie"],cookie檔案的位置與名稱.
1994
				#$result["cmd"],執行的command.
1995
				#$result["argu],使用的參數.
1996
				#必填參數:
1997
				#$conf["url"],字串,目標url.
1998
				$conf["catchWebContent::curlCmd"]["url"]=$getInternetAddress["content"];
1999
				#$conf["fileArgu"],字串,變數__FILE__的內容.
2000
				$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
2001
				#可省略參數:
2002
				#$conf["header"],字串陣列,要傳送的header.
2003
				#$conf["header"]=array();
2004
				#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
2005
				#$conf["allowAnySSLcertificate"]="";
2006
				#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
2007
				#$conf["postVar"]=array();
2008
				#$conf["rawPost"]="字串",要傳送的raw post內容.
2009
				#$conf["rawPost"]="";
2010
				#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
2011
				#$conf["urlEncode"]="false";
2012
				#$conf["agent"],字串,user agent的名稱.
2013
				#$conf["agent"]="";
2014
				#$conf["cookie"],字串,cookie位置與檔案位置.
2015
				#$conf["cookie"]="";
2016
				#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
2017
				#$conf["forceNewCookie"]="";
2018
				$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
2019
				unset($conf["catchWebContent::curlCmd"]);
226 liveuser 2020
 
3 liveuser 2021
				#如果抓取資料失敗
2022
				if($curlCmd["status"]==="false"){
226 liveuser 2023
 
3 liveuser 2024
					#設置錯誤識別
2025
					$result["status"]="false";
226 liveuser 2026
 
3 liveuser 2027
					#設置錯誤訊息
2028
					$result["error"]=$curlCmd;
226 liveuser 2029
 
3 liveuser 2030
					#回傳結果
2031
					return $result;
226 liveuser 2032
 
3 liveuser 2033
					}#if end
226 liveuser 2034
 
3 liveuser 2035
				#反之檔案存在網路上
2036
				else{
226 liveuser 2037
 
3 liveuser 2038
					#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2039
					$result["varName"][$i]=$getInternetAddress["content"];
226 liveuser 2040
 
3 liveuser 2041
					#如果存在檔案路徑的絕對位置
2042
					if(isset($getInternetAddress["fileSystemAbsoulutePosition"])){
226 liveuser 2043
 
42 liveuser 2044
						#設置該檔案的絕對路徑位置
3 liveuser 2045
						$result["varNameFullPath"][$i]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 2046
 
3 liveuser 2047
						}#if end
226 liveuser 2048
 
2049
					#反之代表輸入參數是網址
3 liveuser 2050
					else{
226 liveuser 2051
 
3 liveuser 2052
						#設置該檔案的網址
2053
						$result["varNameWebPath"][$i]=$getInternetAddress["content"];
226 liveuser 2054
 
3 liveuser 2055
						}#else end
226 liveuser 2056
 
3 liveuser 2057
					#設置有無找到的識別
2058
					$result["varExist"][$i]=$curlCmd["founded"];
226 liveuser 2059
 
3 liveuser 2060
					}#else end
226 liveuser 2061
 
3 liveuser 2062
				}#if end
2063
 
2064
			#反之檔案不存在,且停用網路搜尋.
2065
			else if($exist===FALSE){
226 liveuser 2066
 
3 liveuser 2067
				#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2068
				$result["varName"][$i]=$conf["fileArray"][$i];
2069
				$result["varNameFullPath"][$i]=$conf["fileArray"][$i];
2070
				$result["varExist"][$i]="false";
2071
 
2072
				#設置全部檔案都存在的識別變數為 "false"
2073
				$result["allExist"]="false";
226 liveuser 2074
 
3 liveuser 2075
				}#if end
2076
 
2077
			#反之代表檔案存在
2078
			else{
226 liveuser 2079
 
3 liveuser 2080
				#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2081
				$result["varNameFullPath"][$i]=$conf["fileArray"][$i];
226 liveuser 2082
 
3 liveuser 2083
				#如果 web 參數為 "true"
2084
				if($conf["web"]==="true"){
226 liveuser 2085
 
3 liveuser 2086
					#設置網路上的位置
2087
					$result["varNameWebPath"][$i]=$getInternetAddress["content"];
226 liveuser 2088
 
3 liveuser 2089
					}#if end
226 liveuser 2090
 
3 liveuser 2091
				$result["varExist"][$i]="true";
2092
 
2093
				}#else end
226 liveuser 2094
 
3 liveuser 2095
			}#foreach end
226 liveuser 2096
 
3 liveuser 2097
		#如果所有檔案與資料夾都找到的識別變數不存在
2098
		if(!isset($result["allExist"])){
226 liveuser 2099
 
3 liveuser 2100
			#設置全部檔案與資料夾都有找到
2101
			$result["allExist"]="true";
226 liveuser 2102
 
3 liveuser 2103
			}#if end
2104
 
2105
		#執行到這邊代表執行正常
2106
		$result["status"]="true";
2107
 
2108
		#回傳結果
2109
		return $result;
2110
 
2111
		}#function checkMutiFileExist
2112
 
2113
	/*
2114
	#函式說明:
2115
	#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
2116
	#回傳結果:
2117
	#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
2118
	#$result["error"],錯誤訊息陣列.
2119
	#$result["function"],當前執行的函數名稱.
2120
	#$result["argu"],使用的參數.
2121
	#$result["createdFileName"],建立好的檔案名稱.
2122
	#$result["createdFilePath"],檔案建立的路徑.
2123
	#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
2124
	#必填參數:
2125
	#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
2126
	$conf["checkedFileAndPath"]="";
2127
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2128
	$conf["fileArgu"]=__FILE__;
2129
	#可省略參數:
2130
	#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點.
2131
	#$conf["filenameExtensionStartPoint"]="";
2132
	#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)".
2133
	#$conf["repeatNameRule"]="";
2134
	#$conf["web"],"true"代表為網頁系統,"false"代表檔案系統,預設為"false".
2135
	#$conf["web"]="false";
2136
	#參考資料:
2137
	#無.
2138
	#備註:
2139
	#如果要在/tmp底下建立檔案,若在apache環境下則會被作業系統特殊處理,即不等於實際上的路徑.
2140
	*/
2141
	public static function createFileAfterCheck(&$conf){
226 liveuser 2142
 
3 liveuser 2143
		#初始化要回傳的結果
2144
		$result=array();
226 liveuser 2145
 
3 liveuser 2146
		#設置當前執行的涵式
2147
		$result["function"]=__FUNCTION__;
226 liveuser 2148
 
3 liveuser 2149
		#如果 $conf 不為陣列
2150
		if(gettype($conf)!="array"){
226 liveuser 2151
 
3 liveuser 2152
			#設置執行失敗
2153
			$result["status"]="false";
226 liveuser 2154
 
3 liveuser 2155
			#設置執行錯誤訊息
2156
			$result["error"][]="\$conf變數須為陣列形態";
2157
 
2158
			#如果傳入的參數為 null
2159
			if($conf==null){
226 liveuser 2160
 
3 liveuser 2161
				#設置執行錯誤訊息
2162
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 2163
 
3 liveuser 2164
				}#if end
2165
 
2166
			#回傳結果
2167
			return $result;
226 liveuser 2168
 
3 liveuser 2169
			}#if end
226 liveuser 2170
 
3 liveuser 2171
		#取得參數
2172
		$result["argu"]=$conf;
226 liveuser 2173
 
3 liveuser 2174
		#檢查參數
2175
		#函式說明:
2176
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2177
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2178
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2179
		#$result["function"],當前執行的函式名稱.
2180
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2181
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2182
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2183
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2184
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2185
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2186
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2187
		#必填寫的參數:
2188
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2189
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2190
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2191
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","checkedFileAndPath");
226 liveuser 2192
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 2193
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
2194
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2195
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2196
		#可以省略的參數:
2197
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2198
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2199
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2200
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("filenameExtensionStartPoint","repeatNameRule","web");
226 liveuser 2201
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 2202
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
2203
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2204
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("1","(\$i)","false");
2205
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2206
		#$conf["arrayCountEqualCheck"][]=array();
2207
		#參考資料來源:
2208
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2209
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2210
		unset($conf["variableCheck::checkArguments"]);
2211
 
2212
		#如果 $checkArguments["status"] 等於 "false"
2213
		if($checkArguments["status"]=="false"){
226 liveuser 2214
 
3 liveuser 2215
			#設置錯誤識別
2216
			$result["status"]="false";
226 liveuser 2217
 
3 liveuser 2218
			#設置錯誤訊息
2219
			$result["error"]=$checkArguments;
226 liveuser 2220
 
3 liveuser 2221
			#回傳結果
226 liveuser 2222
			return $result;
2223
 
3 liveuser 2224
			}#if end
226 liveuser 2225
 
3 liveuser 2226
		#如果 $checkArguments["passed"] 等於 "false"
2227
		if($checkArguments["passed"]=="false"){
226 liveuser 2228
 
3 liveuser 2229
			#設置錯誤識別
2230
			$result["status"]="false";
226 liveuser 2231
 
3 liveuser 2232
			#設置錯誤訊息
2233
			$result["error"]=$checkArguments;
226 liveuser 2234
 
3 liveuser 2235
			#回傳結果
226 liveuser 2236
			return $result;
2237
 
2238
			}#if end
2239
 
3 liveuser 2240
		#確保要建立檔案的路徑
2241
		#函式說明:
2242
		#確保路徑存在.
2243
		#回傳結果:
2244
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
2245
		#$result["error"],錯誤訊息陣列.
2246
		#$resutl["function"],當前執行的涵式名稱.
2247
		#$result["path"],建立好的路徑字串.
2248
		#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
2249
		#必填參數:
2250
		#$conf["path"],要檢查的路徑
226 liveuser 2251
		$conf["fileAccess::validatePath"]["path"]=$conf["checkedFileAndPath"];
3 liveuser 2252
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2253
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
2254
		#可省略參數:
2255
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
2256
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
2257
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
2258
		#$conf["dirPermission"]="";
2259
		$conf["fileAccess::validatePath"]["web"]=$conf["web"];
2260
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
226 liveuser 2261
		unset($conf["fileAccess::validatePath"]);
2262
 
3 liveuser 2263
		#debug
2264
		#var_dump($validatePath);
226 liveuser 2265
		#exit;
2266
 
3 liveuser 2267
		#如果確保路徑失敗
2268
		if($validatePath["status"]==="false"){
226 liveuser 2269
 
3 liveuser 2270
			#設置錯誤識別
2271
			$result["status"]="false";
226 liveuser 2272
 
3 liveuser 2273
			#設置錯誤訊息
2274
			$result["error"]=$validatePath;
226 liveuser 2275
 
3 liveuser 2276
			#回傳結果
2277
			return $result;
226 liveuser 2278
 
3 liveuser 2279
			}#if end
226 liveuser 2280
 
3 liveuser 2281
		#取得要建立的檔案名稱
2282
		$createdFileName=$validatePath["fileName"];
226 liveuser 2283
 
2284
		#取得要建立的路徑
3 liveuser 2285
		$createdFilePath=$validatePath["path"];
226 liveuser 2286
 
3 liveuser 2287
		#透過無窮迴圈嘗試建立不同編號的檔案
2288
		for($i=0;$i>-1;$i++){
226 liveuser 2289
 
3 liveuser 2290
			#如果 $i 為 0
2291
			if($i==0){
226 liveuser 2292
 
3 liveuser 2293
				#檢查該檔案是否存在
2294
				#函式說明:
2295
				#檢查多個檔案與資料夾是否存在.
2296
				#回傳的結果:
2297
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
2298
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2299
				#必填參數:
2300
				$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($createdFilePath."/".$createdFileName);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
2301
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2302
				$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
2303
				#參考資料來源:
2304
				#http://php.net/manual/en/function.file-exists.php
2305
				#http://php.net/manual/en/control-structures.foreach.php
2306
				$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
2307
				$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
2308
				unset($conf["fileAccess"]["checkMutiFileExist"]);
226 liveuser 2309
 
3 liveuser 2310
				#debug
2311
				#var_dump($checkResult);
2312
				#exit;
226 liveuser 2313
 
3 liveuser 2314
				#如果檢查檔案是否存在失敗
2315
				if($checkResult["status"]=="false"){
226 liveuser 2316
 
3 liveuser 2317
					#設置執行失敗
2318
					$result["status"]="false";
226 liveuser 2319
 
3 liveuser 2320
					#設置錯誤訊息
2321
					$result["error"]=$checkResult;
226 liveuser 2322
 
3 liveuser 2323
					#回傳結果
2324
					return $result;
226 liveuser 2325
 
3 liveuser 2326
					}#if end
226 liveuser 2327
 
3 liveuser 2328
				#如果 $createFilePath.$createdFileName 檔案存在
2329
				if($checkResult["varExist"][0]=="true"){
226 liveuser 2330
 
3 liveuser 2331
					#跳過這次迴圈
2332
					continue;
226 liveuser 2333
 
3 liveuser 2334
					}#if end
226 liveuser 2335
 
3 liveuser 2336
				#反之代表 $createFilePath.$createdFileName 檔案不存在
2337
				else{
226 liveuser 2338
 
3 liveuser 2339
					#嘗試建立該檔案
2340
					#函式說明:
2341
					#將字串寫入到檔案
2342
					#回傳結果:
2343
					#$result["status"],true表示檔案寫入成功,false表示檔案寫入失敗.
2344
					#$result["error"],錯誤訊息陣列.
2345
					#必填參數:
2346
					$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$createdFilePath."/".$createdFileName;#爲要編輯的檔案名稱
2347
					$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
2348
					$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
2349
					#可省略參數:
2350
					$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
2351
					$conf["fileAccess"]["writeTextIntoFile"]["web"]=$conf["web"];
2352
					$fileCreateResult=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
2353
					unset($conf["fileAccess"]["writeTextIntoFile"]);
226 liveuser 2354
 
3 liveuser 2355
					#如果 $fileCreateResult["status"] 等於 "true"
2356
					if($fileCreateResult["status"]=="true"){
226 liveuser 2357
 
3 liveuser 2358
						#代表檔案建立成功
226 liveuser 2359
 
3 liveuser 2360
						#更新建立的檔案名稱
2361
						$result["createdFileName"]=$createdFileName;
226 liveuser 2362
 
3 liveuser 2363
						#設置新建立的檔案名稱與路徑
2364
						$result["createdFilePathAndName"]=$createdFilePath."/".$result["createdFileName"];
226 liveuser 2365
 
3 liveuser 2366
						#設置新建立的檔與路徑
2367
						$result["createdFilePath"]=$createdFilePath;
226 liveuser 2368
 
3 liveuser 2369
						#跳出迴圈
2370
						break;
226 liveuser 2371
 
3 liveuser 2372
						}#if end
226 liveuser 2373
 
3 liveuser 2374
					#反之代表檔案建立失敗
2375
					else{
226 liveuser 2376
 
3 liveuser 2377
						#設置錯誤識別
2378
						$result["status"]="false";
226 liveuser 2379
 
3 liveuser 2380
						#設置錯誤訊息
2381
						$result["error"]=$fileCreateResult;
226 liveuser 2382
 
3 liveuser 2383
						#回傳結果
2384
						return $result;
226 liveuser 2385
 
3 liveuser 2386
						}#else end
226 liveuser 2387
 
2388
					}#else end
2389
 
3 liveuser 2390
				}#if end
226 liveuser 2391
 
3 liveuser 2392
			#反之代表有相同檔名存在
226 liveuser 2393
			else{
2394
 
3 liveuser 2395
				#用「.」分割檔案名稱
2396
				#函式說明:
2397
				#將固定格式的字串分開,並回傳分開的結果。
2398
				#回傳結果:
2399
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2400
				#$result["error"],錯誤訊息陣列
2401
				#$result["function"],當前執行的函數名稱.
2402
				#$result["oriStr"],要分割的原始字串內容
2403
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2404
				#$result["dataCounts"],爲總共分成幾段
2405
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
2406
				#必填參數:
2407
				$conf["stringProcess::spiltString"]["stringIn"]=$createdFileName;#要處理的字串。
2408
				$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
2409
				#可省略參數:
2410
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2411
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2412
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2413
				unset($conf["stringProcess::spiltString"]);
2414
 
3 liveuser 2415
				#如果分割檔案名稱失敗
2416
				if($spiltString["status"]=="false"){
226 liveuser 2417
 
3 liveuser 2418
					#設置執行失敗
2419
					$result["status"]="false";
226 liveuser 2420
 
3 liveuser 2421
					#設置錯誤訊息
2422
					$result["error"]=$spiltString;
226 liveuser 2423
 
3 liveuser 2424
					#回傳結果
2425
					return $result;
226 liveuser 2426
 
3 liveuser 2427
					}#if end
226 liveuser 2428
 
3 liveuser 2429
				#初始化儲存建立的檔案名稱
2430
				$createdFileName="";
226 liveuser 2431
 
3 liveuser 2432
				#初始化儲存編號的變數
2433
				$no="";
226 liveuser 2434
 
3 liveuser 2435
				#如果沒有dot存在
2436
				if($spiltString["found"]=="false"){
226 liveuser 2437
 
3 liveuser 2438
					#解析 $conf["repeatNameRule"],用 \$i 分割.
2439
					#函式說明:
2440
					#將固定格式的字串分開,並回傳分開的結果。
2441
					#回傳結果:
2442
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2443
					#$result["error"],錯誤訊息陣列
2444
					#$result["function"],當前執行的函數名稱.
2445
					#$result["oriStr"],要分割的原始字串內容
2446
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2447
					#$result["dataCounts"],爲總共分成幾段
2448
					#必填參數:
2449
					$conf["stringProcess::spiltString"]["stringIn"]=$conf["repeatNameRule"];#要處理的字串。
2450
					$conf["stringProcess::spiltString"]["spiltSymbol"]="\$i";#爲以哪個符號作爲分割
2451
					#可省略參數:
2452
					#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2453
					$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2454
					$noString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2455
					unset($conf["stringProcess::spiltString"]);
2456
 
3 liveuser 2457
					#如果分割檔案名稱失敗
2458
					if($noString["status"]=="false"){
226 liveuser 2459
 
3 liveuser 2460
						#設置執行失敗
2461
						$result["status"]="false";
226 liveuser 2462
 
3 liveuser 2463
						#設置錯誤訊息
2464
						$result["error"]=$noString;
226 liveuser 2465
 
3 liveuser 2466
						#回傳結果
2467
						return $result;
226 liveuser 2468
 
3 liveuser 2469
						}#if end
226 liveuser 2470
 
3 liveuser 2471
					#如果 編號規則字串 分割出來的段數為2
2472
					if($noString["dataCounts"]==2){
226 liveuser 2473
 
3 liveuser 2474
						#組合編號
2475
						$no=$noString["dataArray"][0].$i.$noString["dataArray"][1];
226 liveuser 2476
 
3 liveuser 2477
						}#if end
226 liveuser 2478
 
3 liveuser 2479
					#反之 號規則字串 分割出來的段數為1
2480
					else if($noString["dataCounts"]==1){
226 liveuser 2481
 
3 liveuser 2482
						#判斷 "\$i" 在開頭或結尾
2483
						#函式說明:
2484
						#取得關鍵字在字串的哪個位置
2485
						#回傳結果:
2486
						#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
2487
						#$result["error"],錯誤訊息陣列.
2488
						#$result["function"],當前執行的函數名稱.
2489
						#$result["argu"],傳入的參數.
2490
						#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
2491
						#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
2492
						#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
2493
						#必填參數:
2494
						#$conf["inputStr"],字串,被搜尋的字串.
2495
						$conf["search::findKeyWordPosition"]["inputStr"]=$conf["repeatNameRule"];
2496
						#$conf["keyWord"],字串,關鍵字.
2497
						$conf["search::findKeyWordPosition"]["keyWord"]="\$i";
2498
						#參考資料:
2499
						#http://php.net/manual/en/function.strpos.php
2500
						$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
2501
						unset($conf["search::findKeyWordPosition"]);
226 liveuser 2502
 
3 liveuser 2503
						#如果取得關鍵字位置失敗
2504
						if($findKeyWordPosition["status"]=="false"){
226 liveuser 2505
 
3 liveuser 2506
							#設置執行失敗
2507
							$result["status"]="false";
226 liveuser 2508
 
3 liveuser 2509
							#設置錯誤訊息
2510
							$result["error"]=$findKeyWordPosition;
226 liveuser 2511
 
3 liveuser 2512
							#回傳結果
2513
							return $result;
226 liveuser 2514
 
3 liveuser 2515
							}#if end
226 liveuser 2516
 
3 liveuser 2517
						#如果關鍵字在開頭
2518
						if($findKeyWordPosition["head"]=="true"){
226 liveuser 2519
 
3 liveuser 2520
							#組合編號
2521
							$no=$i.$noString["dataArray"][0];
226 liveuser 2522
 
3 liveuser 2523
							}#if end
226 liveuser 2524
 
3 liveuser 2525
						#反之如果關鍵字在結尾
2526
						else if($findKeyWordPosition["tail"]=="true"){
226 liveuser 2527
 
3 liveuser 2528
							#組合編號
2529
							$no=$noString["dataArray"][0].$i;
226 liveuser 2530
 
3 liveuser 2531
							}#if end
226 liveuser 2532
 
3 liveuser 2533
						#其他情況
2534
						else{
226 liveuser 2535
 
3 liveuser 2536
							#設置執行失敗
2537
							$result["status"]="false";
226 liveuser 2538
 
3 liveuser 2539
							#設置錯誤訊息
2540
							$result["error"]=$findKeyWordPosition;
226 liveuser 2541
 
3 liveuser 2542
							#設置額外的錯誤訊息
2543
							$result["error"][]="非預期的結果";
226 liveuser 2544
 
3 liveuser 2545
							#回傳結果
2546
							return $result;
226 liveuser 2547
 
3 liveuser 2548
							}#else end
226 liveuser 2549
 
3 liveuser 2550
						}#if end
226 liveuser 2551
 
3 liveuser 2552
					#反之 編號規則字串 分割出來的段數為0
2553
					else if($noString["dataCounts"]==0){
226 liveuser 2554
 
3 liveuser 2555
						#組合編號
2556
						$no=$j;
226 liveuser 2557
 
3 liveuser 2558
						}#if end
226 liveuser 2559
 
3 liveuser 2560
					#其他結果
2561
					else{
226 liveuser 2562
 
3 liveuser 2563
						#設置執行失敗
2564
						$result["status"]="false";
226 liveuser 2565
 
3 liveuser 2566
						#設置錯誤訊息
2567
						$result["error"]=$noString;
226 liveuser 2568
 
3 liveuser 2569
						#設置額外的錯誤訊息
2570
						$result["error"][]="非預期的結果";
226 liveuser 2571
 
3 liveuser 2572
						#回傳結果
2573
						return $result;
226 liveuser 2574
 
2575
						}#else end
2576
 
3 liveuser 2577
					#串接編號到檔案名稱上
2578
					$createdFileName=$validatePath["fileName"].$no;
226 liveuser 2579
 
3 liveuser 2580
					}#if end
226 liveuser 2581
 
2582
				#反之有dot存在
3 liveuser 2583
				else{
226 liveuser 2584
 
3 liveuser 2585
					#依據 $spiltString["dataCounts"] 值來組裝新的檔案名稱
2586
					for($j=0;$j<$spiltString["dataCounts"];$j++){
226 liveuser 2587
 
3 liveuser 2588
						#如果是副檔名的前一段內容
2589
						if(($conf["filenameExtensionStartPoint"]+1)==($spiltString["dataCounts"]-$j)){
226 liveuser 2590
 
3 liveuser 2591
							#解析 $conf["repeatNameRule"],用 \$i 分割.
2592
							#函式說明:
2593
							#將固定格式的字串分開,並回傳分開的結果。
2594
							#回傳結果:
2595
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2596
							#$result["error"],錯誤訊息陣列
2597
							#$result["function"],當前執行的函數名稱.
2598
							#$result["oriStr"],要分割的原始字串內容
2599
							#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2600
							#$result["dataCounts"],爲總共分成幾段
2601
							#必填參數:
2602
							$conf["stringProcess::spiltString"]["stringIn"]=$conf["repeatNameRule"];#要處理的字串。
2603
							$conf["stringProcess::spiltString"]["spiltSymbol"]="\$i";#爲以哪個符號作爲分割
2604
							#可省略參數:
2605
							#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2606
							$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2607
							$noString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2608
							unset($conf["stringProcess::spiltString"]);
2609
 
3 liveuser 2610
							#如果分割檔案名稱失敗
2611
							if($noString["status"]=="false"){
226 liveuser 2612
 
3 liveuser 2613
								#設置執行失敗
2614
								$result["status"]="false";
226 liveuser 2615
 
3 liveuser 2616
								#設置錯誤訊息
2617
								$result["error"]=$noString;
226 liveuser 2618
 
3 liveuser 2619
								#回傳結果
2620
								return $result;
226 liveuser 2621
 
3 liveuser 2622
								}#if end
226 liveuser 2623
 
3 liveuser 2624
							#如果 編號規則字串 分割出來的段數為2
2625
							if($noString["dataCounts"]==2){
226 liveuser 2626
 
3 liveuser 2627
								#組合編號
2628
								$no=$noString["dataArray"][0].$i.$noString["dataArray"][1];
226 liveuser 2629
 
3 liveuser 2630
								}#if end
226 liveuser 2631
 
3 liveuser 2632
							#反之 號規則字串 分割出來的段數為1
2633
							else if($noString["dataCounts"]==1){
226 liveuser 2634
 
3 liveuser 2635
								#判斷 "\$i" 在開頭或結尾
2636
								#函式說明:
2637
								#取得關鍵字在字串的哪個位置
2638
								#回傳結果:
2639
								#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
2640
								#$result["error"],錯誤訊息陣列.
2641
								#$result["function"],當前執行的函數名稱.
2642
								#$result["argu"],傳入的參數.
2643
								#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
2644
								#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
2645
								#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
2646
								#必填參數:
2647
								#$conf["inputStr"],字串,被搜尋的字串.
2648
								$conf["search::findKeyWordPosition"]["inputStr"]=$conf["repeatNameRule"];
2649
								#$conf["keyWord"],字串,關鍵字.
2650
								$conf["search::findKeyWordPosition"]["keyWord"]="\$i";
2651
								#參考資料:
2652
								#http://php.net/manual/en/function.strpos.php
2653
								$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
2654
								unset($conf["search::findKeyWordPosition"]);
226 liveuser 2655
 
3 liveuser 2656
								#如果取得關鍵字位置失敗
2657
								if($findKeyWordPosition["status"]=="false"){
226 liveuser 2658
 
3 liveuser 2659
									#設置執行失敗
2660
									$result["status"]="false";
226 liveuser 2661
 
3 liveuser 2662
									#設置錯誤訊息
2663
									$result["error"]=$findKeyWordPosition;
226 liveuser 2664
 
3 liveuser 2665
									#回傳結果
2666
									return $result;
226 liveuser 2667
 
3 liveuser 2668
									}#if end
226 liveuser 2669
 
3 liveuser 2670
								#如果關鍵字在開頭
2671
								if($findKeyWordPosition["head"]=="true"){
226 liveuser 2672
 
3 liveuser 2673
									#組合編號
2674
									$no=$i.$noString["dataArray"][0];
226 liveuser 2675
 
3 liveuser 2676
									}#if end
226 liveuser 2677
 
3 liveuser 2678
								#反之如果關鍵字在結尾
2679
								else if($findKeyWordPosition["tail"]=="true"){
226 liveuser 2680
 
3 liveuser 2681
									#組合編號
2682
									$no=$noString["dataArray"][0].$i;
226 liveuser 2683
 
3 liveuser 2684
									}#if end
226 liveuser 2685
 
3 liveuser 2686
								#其他情況
2687
								else{
226 liveuser 2688
 
3 liveuser 2689
									#設置執行失敗
2690
									$result["status"]="false";
226 liveuser 2691
 
3 liveuser 2692
									#設置錯誤訊息
2693
									$result["error"]=$findKeyWordPosition;
226 liveuser 2694
 
3 liveuser 2695
									#設置額外的錯誤訊息
2696
									$result["error"][]="非預期的結果";
226 liveuser 2697
 
3 liveuser 2698
									#回傳結果
2699
									return $result;
226 liveuser 2700
 
3 liveuser 2701
									}#else end
226 liveuser 2702
 
3 liveuser 2703
								}#if end
226 liveuser 2704
 
3 liveuser 2705
							#反之 編號規則字串 分割出來的段數為0
2706
							else if($noString["dataCounts"]==0){
226 liveuser 2707
 
3 liveuser 2708
								#組合編號
2709
								$no=$j;
226 liveuser 2710
 
3 liveuser 2711
								}#if end
226 liveuser 2712
 
3 liveuser 2713
							#其他結果
2714
							else{
226 liveuser 2715
 
3 liveuser 2716
								#設置執行失敗
2717
								$result["status"]="false";
226 liveuser 2718
 
3 liveuser 2719
								#設置錯誤訊息
2720
								$result["error"]=$noString;
226 liveuser 2721
 
3 liveuser 2722
								#設置額外的錯誤訊息
2723
								$result["error"][]="非預期的結果";
226 liveuser 2724
 
3 liveuser 2725
								#回傳結果
2726
								return $result;
226 liveuser 2727
 
2728
								}#else end
2729
 
3 liveuser 2730
							#串接編號到檔案名稱上
2731
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j].$no;
226 liveuser 2732
 
3 liveuser 2733
							#如果不是最後一段
2734
							if($j!=$spiltString["dataCounts"]-1){
226 liveuser 2735
 
3 liveuser 2736
								#串接並加上 dot
2737
								$createdFileName=$createdFileName.".";
226 liveuser 2738
 
3 liveuser 2739
								}#if end
226 liveuser 2740
 
3 liveuser 2741
							}#if end
226 liveuser 2742
 
3 liveuser 2743
						#反之如果不是最後一段
2744
						else if($j!=$spiltString["dataCounts"]-1){
226 liveuser 2745
 
3 liveuser 2746
							#串接並加上 dot
2747
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j].".";
226 liveuser 2748
 
3 liveuser 2749
							}#if end
226 liveuser 2750
 
2751
						#反之是最後一段
3 liveuser 2752
						else{
226 liveuser 2753
 
3 liveuser 2754
							#串接並加上 dot
2755
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j];
226 liveuser 2756
 
3 liveuser 2757
							}#else end
226 liveuser 2758
 
3 liveuser 2759
						}#for end
226 liveuser 2760
 
3 liveuser 2761
					}#else end
226 liveuser 2762
 
3 liveuser 2763
				#檢查加上編號的檔案是否存在
2764
				#函式說明:
2765
				#檢查多個檔案與資料夾是否存在.
2766
				#回傳的結果:
2767
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
2768
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2769
				#必填參數:
2770
				$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($createdFilePath."/".$createdFileName);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
2771
				$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
2772
				#參考資料來源:
2773
				#http://php.net/manual/en/function.file-exists.php
2774
				#http://php.net/manual/en/control-structures.foreach.php
2775
				$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
2776
				$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
2777
				unset($conf["fileAccess"]["checkMutiFileExist"]);
226 liveuser 2778
 
3 liveuser 2779
				#如果檢查檔案是否存在失敗
2780
				if($checkResult["status"]=="false"){
226 liveuser 2781
 
3 liveuser 2782
					#設置執行失敗
2783
					$result["status"]="false";
226 liveuser 2784
 
3 liveuser 2785
					#設置錯誤訊息
2786
					$result["error"]=$checkResult;
226 liveuser 2787
 
3 liveuser 2788
					#回傳結果
2789
					return $result;
226 liveuser 2790
 
2791
					}#if end
2792
 
3 liveuser 2793
				#如果 $checkResult["varExist"][0] 等於 "true"
226 liveuser 2794
				if($checkResult["varExist"][0]=="true"){
2795
 
3 liveuser 2796
					#取得要建立的檔案名稱
2797
					$createdFileName=$validatePath["fileName"];
226 liveuser 2798
 
3 liveuser 2799
					#跳到下個迴圈
2800
					continue;
226 liveuser 2801
 
3 liveuser 2802
					}#if end
226 liveuser 2803
 
3 liveuser 2804
				#反之代表 $createFilePath.$createdFileName."(".$i.")" 檔檔案不存在
2805
				else{
226 liveuser 2806
 
3 liveuser 2807
					#嘗試建立該檔案
2808
					#函式說明:
2809
					#將字串寫入到檔案
2810
					#回傳結果:
2811
					#$result["status"],true表示檔案寫入成功,false表示檔案寫入失敗.
2812
					#$result["error"],錯誤訊息陣列.
2813
					#必填參數:
2814
					$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$createdFilePath."/".$createdFileName;#爲要編輯的檔案名稱
2815
					$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
2816
					$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
2817
					#可省略參數:
2818
					$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
2819
					$conf["fileAccess"]["writeTextIntoFile"]["web"]=$conf["web"];
2820
					$fileCreateResult=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
2821
					unset($conf["fileAccess"]["writeTextIntoFile"]);
226 liveuser 2822
 
3 liveuser 2823
					#如果 $fileCreateResult["status"] 等於 "true"
2824
					if($fileCreateResult["status"]=="true"){
226 liveuser 2825
 
3 liveuser 2826
						#代表檔案建立成功
226 liveuser 2827
 
3 liveuser 2828
						#更新建立的檔案名稱
2829
						$result["createdFileName"]=$createdFileName;
226 liveuser 2830
 
3 liveuser 2831
						#跳出迴圈
2832
						break;
226 liveuser 2833
 
3 liveuser 2834
						}#if end
226 liveuser 2835
 
3 liveuser 2836
					#反之代表檔案建立失敗
2837
					else{
226 liveuser 2838
 
3 liveuser 2839
						#設置錯誤識別
2840
						$result["status"]="false";
226 liveuser 2841
 
3 liveuser 2842
						#設置錯誤訊息
2843
						$result["error"]=$fileCreateResult;
226 liveuser 2844
 
3 liveuser 2845
						#回傳結果
2846
						return $result;
226 liveuser 2847
 
3 liveuser 2848
						}#else end
226 liveuser 2849
 
3 liveuser 2850
					}#else end
226 liveuser 2851
 
3 liveuser 2852
				}#else end
226 liveuser 2853
 
3 liveuser 2854
			}#for end
226 liveuser 2855
 
3 liveuser 2856
		#如果不存在建立的檔案名稱
2857
		if(!isset($result["createdFileName"])){
226 liveuser 2858
 
3 liveuser 2859
			#設置錯誤識別
2860
			$result["status"]="false";
226 liveuser 2861
 
3 liveuser 2862
			#設置錯誤訊息
2863
			$result["error"][]="建立的檔案名稱不存在";
226 liveuser 2864
 
3 liveuser 2865
			#回傳結果
2866
			return $result;
226 liveuser 2867
 
2868
			}#if end
2869
 
3 liveuser 2870
		#執行到這邊代表執行成功
2871
		$result["status"]="true";
226 liveuser 2872
 
3 liveuser 2873
		#設置新建立的檔案名稱與路徑
2874
		$result["createdFilePathAndName"]=$createdFilePath."/".$result["createdFileName"];
226 liveuser 2875
 
3 liveuser 2876
		#設置新建立的檔與路徑
2877
		$result["createdFilePath"]=$createdFilePath;
226 liveuser 2878
 
3 liveuser 2879
		#回傳結果
2880
		return $result;
226 liveuser 2881
 
3 liveuser 2882
		}#fucntion createFileAfterCheck end
2883
 
2884
	/*
2885
	#函式說明:
2886
	#將檔案內容清空
2887
	#回傳結果:
2888
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
2889
	#$result["error"],錯誤訊息陣列
2890
	#必填參數:
2891
	#$conf["fileAddr"],字串,要清空的檔案位置與名稱.
2892
	$conf["fileAddr"]="";
2893
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2894
	$conf["fileArgu"]=__FILE__;
2895
	#可省略參數:
2896
	#$conf["web"],"true"代表為網頁系統,"false"代表檔案系統,預設為"false".
2897
	#$conf["web"]="false";
2898
	#參考資料:
2899
	#無.
2900
	#備註:
2901
	#無.
2902
	*/
2903
	public static function emptyFile(&$conf){
226 liveuser 2904
 
3 liveuser 2905
		#初始化要回傳的結果
2906
		$result=array();
226 liveuser 2907
 
3 liveuser 2908
		#設置當前執行的涵式
2909
		$result["function"]=__FUNCTION__;
226 liveuser 2910
 
3 liveuser 2911
		#如果 $conf 不為陣列
2912
		if(gettype($conf)!="array"){
226 liveuser 2913
 
3 liveuser 2914
			#設置執行失敗
2915
			$result["status"]="false";
226 liveuser 2916
 
3 liveuser 2917
			#設置執行錯誤訊息
2918
			$result["error"][]="\$conf變數須為陣列形態";
2919
 
2920
			#如果傳入的參數為 null
2921
			if($conf==null){
226 liveuser 2922
 
3 liveuser 2923
				#設置執行錯誤訊息
2924
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 2925
 
3 liveuser 2926
				}#if end
2927
 
2928
			#回傳結果
2929
			return $result;
226 liveuser 2930
 
3 liveuser 2931
			}#if end
226 liveuser 2932
 
3 liveuser 2933
		#取得參數
2934
		$result["argu"]=$conf;
226 liveuser 2935
 
3 liveuser 2936
		#檢查參數
2937
		#函式說明:
2938
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2939
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2940
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2941
		#$result["function"],當前執行的函式名稱.
2942
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2943
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2944
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2945
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2946
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2947
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2948
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2949
		#必填寫的參數:
2950
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2951
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2952
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2953
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddr");
226 liveuser 2954
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 2955
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
2956
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2957
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2958
		#可以省略的參數:
2959
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2960
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2961
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2962
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 2963
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 2964
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
2965
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2966
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
2967
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2968
		#$conf["arrayCountEqualCheck"][]=array();
2969
		#參考資料來源:
2970
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2971
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2972
		unset($conf["variableCheck::checkArguments"]);
2973
 
2974
		#如果 $checkArguments["status"] 等於 "false"
2975
		if($checkArguments["status"]=="false"){
226 liveuser 2976
 
3 liveuser 2977
			#設置錯誤識別
2978
			$result["status"]="false";
226 liveuser 2979
 
3 liveuser 2980
			#設置錯誤訊息
2981
			$result["error"]=$checkArguments;
226 liveuser 2982
 
3 liveuser 2983
			#回傳結果
226 liveuser 2984
			return $result;
2985
 
3 liveuser 2986
			}#if end
226 liveuser 2987
 
3 liveuser 2988
		#如果 $checkArguments["passed"] 等於 "false"
2989
		if($checkArguments["passed"]=="false"){
226 liveuser 2990
 
3 liveuser 2991
			#設置錯誤識別
2992
			$result["status"]="false";
226 liveuser 2993
 
3 liveuser 2994
			#設置錯誤訊息
2995
			$result["error"]=$checkArguments;
226 liveuser 2996
 
3 liveuser 2997
			#回傳結果
226 liveuser 2998
			return $result;
2999
 
3000
			}#if end
3001
 
3 liveuser 3002
		#函式說明:
3003
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
3004
		#回傳結果:
3005
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3006
		#$result["error"],錯誤訊息陣列.
226 liveuser 3007
		#$result["function"],函數名稱.
3 liveuser 3008
		#$result["argu"],使用的參數.
3009
		#$result["content"],網址,若是在命令列執行,則為"null".
3010
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
3011
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
3012
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
3013
		#必填參數:
3014
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
3015
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["fileAddr"];
3016
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3017
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
3018
		#可省略參數:
3019
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3020
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
3021
		#備註:
3022
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
3023
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
3024
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 3025
 
3 liveuser 3026
		#如果確保路徑失敗
3027
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 3028
 
3 liveuser 3029
			#設置錯誤識別
3030
			$result["status"]="false";
226 liveuser 3031
 
3 liveuser 3032
			#設置錯誤訊息
3033
			$result["error"]=$getInternetAddressV2;
226 liveuser 3034
 
3 liveuser 3035
			#回傳結果
3036
			return $result;
226 liveuser 3037
 
3 liveuser 3038
			}#if end
226 liveuser 3039
 
3 liveuser 3040
		#更新檔案路徑
3041
		$conf["fileAddr"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 3042
 
3 liveuser 3043
		#確保要建立檔案的路徑
3044
		#函式說明:
3045
		#確保路徑存在.
3046
		#回傳結果:
3047
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3048
		#$result["error"],錯誤訊息陣列.
3049
		#$resutl["function"],當前執行的涵式名稱.
3050
		#$result["path"],建立好的路徑字串.
3051
		#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
3052
		#必填參數:
3053
		#$conf["path"],要檢查的路徑
226 liveuser 3054
		$conf["fileAccess::validatePath"]["path"]=$conf["fileAddr"];
3 liveuser 3055
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3056
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
3057
		#可省略參數:
3058
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
3059
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
3060
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3061
		#$conf["dirPermission"]="";
3062
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3063
		$conf["fileAccess::validatePath"]["web"]="false";
3064
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
226 liveuser 3065
		unset($conf["fileAccess::validatePath"]);
3066
 
3 liveuser 3067
		#如果確保路徑失敗
3068
		if($validatePath["status"]==="false"){
226 liveuser 3069
 
3 liveuser 3070
			#設置錯誤識別
3071
			$result["status"]="false";
226 liveuser 3072
 
3 liveuser 3073
			#設置錯誤訊息
3074
			$result["error"]=$validatePath;
226 liveuser 3075
 
3 liveuser 3076
			#回傳結果
3077
			return $result;
226 liveuser 3078
 
3 liveuser 3079
			}#if end
226 liveuser 3080
 
3 liveuser 3081
		#清空檔案
3082
		#函式說明:
3083
		#將字串寫入到檔案
3084
		#回傳結果:
3085
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
3086
		#$result["error"],錯誤訊息陣列.
3087
		#$result["function"],當前執行的函數名稱.
3088
		#$result["fileInfo"],實際上寫入的檔案資訊陣列.
3089
		#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
3090
		#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
3091
		#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
3092
		#$result["argu"],使用的參數.
3093
		#必填參數:
3094
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3095
		$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
3096
		#可省略參數:
3097
		#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
3098
		#$conf["fileAccess::writeTextIntoFile"]["fileName"]=$validatePath["path"]."/".$validatePath["fileName"];
3099
		$conf["fileAccess::writeTextIntoFile"]["fileName"]=$validatePath["path"]."/".$validatePath["fileName"];;
3100
		#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
3101
		#$conf["inputString"]="";
3102
		#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
3103
		#$conf["writeMethod"]="a";
3104
		#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
3105
		#$conf["checkRepeat"]="";
3106
		#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
3107
		#$conf["filenameExtensionStartPoint"]="";
3108
		#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
3109
		#$conf["repeatNameRule"]="";
3110
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3111
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
3112
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
3113
		unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 3114
 
3 liveuser 3115
		#如果確保路徑失敗
3116
		if($writeTextIntoFile["status"]==="false"){
226 liveuser 3117
 
3 liveuser 3118
			#設置錯誤識別
3119
			$result["status"]="false";
226 liveuser 3120
 
3 liveuser 3121
			#設置錯誤訊息
3122
			$result["error"]=$writeTextIntoFile;
226 liveuser 3123
 
3 liveuser 3124
			#回傳結果
3125
			return $result;
226 liveuser 3126
 
3 liveuser 3127
			}#if end
226 liveuser 3128
 
3 liveuser 3129
		#設置執行正常
3130
		$result["status"]="true";
226 liveuser 3131
 
3 liveuser 3132
		#儲存建立的結果
3133
		$result["content"]=$writeTextIntoFile;
226 liveuser 3134
 
3 liveuser 3135
		#回傳結果
3136
		return $result;
226 liveuser 3137
 
3 liveuser 3138
		}#function emptyFile end
3139
 
3140
	/*
3141
	#函式說明:
3142
	#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
3143
	#回傳結果:
3144
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3145
	#$result["error"],錯誤訊息陣列
3146
	#$result["warning"],警告訊息陣列
3147
	#必填參數:
3148
	#$conf["dirPositionAndName"]="";#新建的位置與名稱
3149
	$conf["dirPositionAndName"]="";
3150
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3151
	$conf["fileArgu"]=__FILE__;
3152
	#可省略參數:
3153
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3154
	#$conf["dirPermission"]="";
3155
	#參考資料:
3156
	#mkdir=>http://php.net/manual/en/function.mkdir.php
3157
	#chmod=>http://php.net/manual/en/function.chmod.php
3158
	#參考資料:
3159
	#無.
3160
	#備註:
3161
	#同 function createFolderAfterCheck.
3162
	*/
3163
	public static function createNewFolder(&$conf){
3164
 
3165
		/*
3166
		#函式說明:
3167
		#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
3168
		#回傳的結果:
3169
		#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
3170
		#$result["error"],錯誤訊息陣列.
3171
		#$result["function"],當前執行的函數名稱.
3172
		#$result["createdFileName"],建立好的檔案名稱.
3173
		#$result["createdFilePath"],檔案建立的路徑.
3174
		#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
3175
		#必填參數:
3176
		#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
3177
		$conf["checkedFileAndPath"]="";
3178
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3179
		$conf["fileArgu"]=__FILE__;
3180
		*/
3181
		return fileAccess::createFolderAfterCheck($conf);
3182
		unset($conf);
3183
 
3184
		}#function createNewFolder end
226 liveuser 3185
 
3 liveuser 3186
	/*
3187
	#函式說明:
3188
	#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
3189
	#回傳結果:
3190
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3191
	#$result["error"],錯誤訊息陣列
3192
	#$result["warning"],警告訊息陣列
3193
	#$result["argu"],使用的參數.
3194
	#$result["content"],建立的目錄路徑.
3195
	#必填參數:
3196
	#$conf["dirPositionAndName"]="";#新建的位置與名稱
3197
	$conf["dirPositionAndName"]="";
3198
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3199
	$conf["fileArgu"]=__FILE__;
3200
	#可省略參數:
3201
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3202
	#$conf["dirPermission"]="";
3203
	#$conf["web"],"false"代表在檔案系統環境,"true"代表在網頁稀系統環境.
3204
	#$conf["web"]="false";
3205
	#參考資料:
3206
	#mkdir=>http://php.net/manual/en/function.mkdir.php
3207
	#chmod=>http://php.net/manual/en/function.chmod.php
3208
	#備註:
3209
	#無.
3210
	*/
3211
	public static function createFolderAfterCheck(&$conf){
226 liveuser 3212
 
3 liveuser 3213
		#初始化要回傳的結果
3214
		$result=array();
226 liveuser 3215
 
3 liveuser 3216
		#初始化警告訊息陣列
3217
		$result["warning"]=array();
226 liveuser 3218
 
3 liveuser 3219
		#記錄當前執行的函數名稱
3220
		$result["function"]=__FUNCTION__;
226 liveuser 3221
 
3 liveuser 3222
		#如果 $conf 不為陣列
3223
		if(gettype($conf)!="array"){
226 liveuser 3224
 
3 liveuser 3225
			#設置執行失敗
3226
			$result["status"]="false";
226 liveuser 3227
 
3 liveuser 3228
			#設置執行錯誤訊息
3229
			$result["error"][]="\$conf變數須為陣列形態";
3230
 
3231
			#如果傳入的參數為 null
3232
			if($conf==null){
226 liveuser 3233
 
3 liveuser 3234
				#設置執行錯誤訊息
3235
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3236
 
3 liveuser 3237
				}#if end
3238
 
3239
			#回傳結果
3240
			return $result;
226 liveuser 3241
 
3 liveuser 3242
			}#if end
226 liveuser 3243
 
3 liveuser 3244
		#取得參數
3245
		$result["argu"]=$conf;
226 liveuser 3246
 
3 liveuser 3247
		#檢查參數
3248
		#函式說明:
3249
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3250
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3251
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3252
		#$result["function"],當前執行的函式名稱.
3253
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3254
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3255
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3256
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3257
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3258
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3259
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3260
		#必填寫的參數:
3261
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3262
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3263
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3264
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","dirPositionAndName");
226 liveuser 3265
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3266
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
3267
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3268
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3269
		#可以省略的參數:
3270
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3271
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3272
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3273
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dirPermission","web");
226 liveuser 3274
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3275
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
3276
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3277
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("0770","false");
3278
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3279
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
3280
		#參考資料來源:
3281
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3282
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3283
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3284
 
3 liveuser 3285
		#如果 $checkArguments["status"] 等於 "false"
3286
		if($checkArguments["status"]==="false"){
226 liveuser 3287
 
3 liveuser 3288
			#設置 $result["status"] 為 "false"
3289
			$result["status"]="false";
226 liveuser 3290
 
3 liveuser 3291
			#設置 $result["error"]
3292
			$result["error"]=$checkArguments;
226 liveuser 3293
 
3 liveuser 3294
			#回傳結果
3295
			return $result;
226 liveuser 3296
 
3 liveuser 3297
			}#if end
226 liveuser 3298
 
3 liveuser 3299
		#如果 $checkArguments["passed"] 等於 "false"
3300
		if($checkArguments["passed"]==="false"){
226 liveuser 3301
 
3 liveuser 3302
			#設置 $result["status"] 為 "false"
3303
			$result["status"]="false";
226 liveuser 3304
 
3 liveuser 3305
			#設置 $result["error"]
3306
			$result["error"]=$checkArguments;
226 liveuser 3307
 
3 liveuser 3308
			#回傳結果
3309
			return $result;
226 liveuser 3310
 
3311
			}#if end
3312
 
3 liveuser 3313
		#函式說明:
3314
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
3315
		#回傳結果:
3316
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3317
		#$result["error"],錯誤訊息陣列.
226 liveuser 3318
		#$result["function"],函數名稱.
3 liveuser 3319
		#$result["argu"],使用的參數.
3320
		#$result["content"],網址,若是在命令列執行,則為"null".
3321
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
3322
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
3323
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
3324
		#必填參數:
3325
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
3326
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["dirPositionAndName"];
3327
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3328
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
3329
		#可省略參數:
3330
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3331
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
3332
		#備註:
3333
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
3334
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
3335
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 3336
 
3 liveuser 3337
		#如果 $getInternetAddressV2["status"] 等於 "false"
3338
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 3339
 
3 liveuser 3340
			#設置 $result["status"] 為 "false"
3341
			$result["status"]="false";
226 liveuser 3342
 
3 liveuser 3343
			#設置 $result["error"]
3344
			$result["error"]=$getInternetAddressV2;
226 liveuser 3345
 
3 liveuser 3346
			#回傳結果
3347
			return $result;
226 liveuser 3348
 
3 liveuser 3349
			}#if end
226 liveuser 3350
 
3 liveuser 3351
		#取得絕對位置
3352
		$conf["dirPositionAndName"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 3353
 
3 liveuser 3354
		#用「/」分割要建立的路徑
3355
		#函式說明:
3356
		#將固定格式的字串分開,並回傳分開的結果。
3357
		#回傳結果:
3358
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3359
		#$result["error"],錯誤訊息陣列
3360
		#$result["function"],當前執行的函數名稱.
3361
		#$result["oriStr"],要分割的原始字串內容
3362
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
3363
		#$result["dataCounts"],爲總共分成幾段
3364
		#必填參數:
3365
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["dirPositionAndName"];
3366
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
3367
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 3368
		unset($conf["stringProcess::spiltString"]);
3369
 
3 liveuser 3370
		#如果分割失敗
3371
		if($spiltString["status"]=="false"){
226 liveuser 3372
 
3 liveuser 3373
			#設置 $result["status"] 為 "false"
3374
			$result["status"]="false";
226 liveuser 3375
 
3 liveuser 3376
			#設置 $result["error"]
3377
			$result["error"]=$spiltString;
226 liveuser 3378
 
3 liveuser 3379
			#回傳結果
3380
			return $result;
226 liveuser 3381
 
3 liveuser 3382
			}#if end
226 liveuser 3383
 
3 liveuser 3384
		$checkedPath="";
226 liveuser 3385
 
3 liveuser 3386
		#依據切割成的路徑片段數目
3387
		for($i=0;$i<$spiltString["dataCounts"];$i++){
226 liveuser 3388
 
3 liveuser 3389
			$checkedPath=$checkedPath."/".$spiltString["dataArray"][$i];
226 liveuser 3390
 
3 liveuser 3391
			#檢查路徑是否存在
3392
			#函式說明:
3393
			#檢查多個檔案與資料夾是否存在.
3394
			#回傳的結果:
3395
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3396
			#$result["error"],錯誤訊息陣列.
3397
			#$resutl["function"],當前執行的涵式名稱.
3398
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
3399
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
3400
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
3401
			#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
3402
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
3403
			#必填參數:
3404
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
3405
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($checkedPath);
3406
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3407
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
3408
			#可省略參數
3409
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
3410
			#$conf["disableWebSearch"]="false";
3411
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
3412
			#$conf["userDir"]="true";
3413
			#參考資料來源:
3414
			#http://php.net/manual/en/function.file-exists.php
3415
			#http://php.net/manual/en/control-structures.foreach.php
3416
			#備註:
3417
			#函數file_exists檢查的路徑為檔案系統的路徑
3418
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 3419
 
3 liveuser 3420
			#如果檢查資料夾路徑失敗
3421
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 3422
 
3 liveuser 3423
				#設置 $result["status"] 為 "false"
3424
				$result["status"]="false";
226 liveuser 3425
 
3 liveuser 3426
				#設置 $result["error"]
3427
				$result["error"]=$spiltString;
226 liveuser 3428
 
3 liveuser 3429
				#回傳結果
3430
				return $result;
226 liveuser 3431
 
3 liveuser 3432
				}#if end
226 liveuser 3433
 
3 liveuser 3434
			#如果目錄不存在
3435
			if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 3436
 
3 liveuser 3437
				#如果有這個名稱的東西存在
3438
				if(file_exists($checkedPath)){
226 liveuser 3439
 
3 liveuser 3440
					#如果目錄存在
3441
					if(is_dir($checkedPath)){
226 liveuser 3442
 
3 liveuser 3443
						#目錄已經存在換下一層
3444
						continue;
226 liveuser 3445
 
3 liveuser 3446
						}#if end
226 liveuser 3447
 
3 liveuser 3448
					}#if end
226 liveuser 3449
 
3 liveuser 3450
				#建立目錄
3451
				$mkdir=@mkdir($checkedPath,0770);
226 liveuser 3452
 
3 liveuser 3453
				#如果建立目錄失敗
3454
				#參考資料:
3455
				#http://php.net/manual/en/function.mkdir.php
3456
				if($mkdir===false){
226 liveuser 3457
 
3 liveuser 3458
					#設置 $result["status"] 為 "false"
3459
					$result["status"]="false";
226 liveuser 3460
 
3 liveuser 3461
					#設置 $result["error"]
3462
					$result["error"][]="建立目錄「".$checkedPath."」失敗";
226 liveuser 3463
 
3 liveuser 3464
					#回傳結果
3465
					return $result;
226 liveuser 3466
 
3 liveuser 3467
					}#if end
226 liveuser 3468
 
3 liveuser 3469
				#更改目錄的權限為 0770
3470
				chmod($checkedPath,0770);
226 liveuser 3471
 
3 liveuser 3472
				}#if end
226 liveuser 3473
 
3 liveuser 3474
			}#for end
226 liveuser 3475
 
3 liveuser 3476
		#取得建立好的目錄
226 liveuser 3477
		$result["content"]=$checkedPath;
3478
 
3 liveuser 3479
		#執行到這邊代表執行成功
3480
		$result["status"]="true";
226 liveuser 3481
 
3 liveuser 3482
		#回傳結果
3483
		return $result;
226 liveuser 3484
 
3 liveuser 3485
		}#function createFolderAfterCheck end
3486
 
3487
	/*
3488
	#函式說明:
3489
	#移除檔案
3490
	#回傳結果:
3491
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
3492
	#$result["error"],錯誤訊息陣列.
3493
	#$result["warning"],警告訊息陣列.
3494
	#$result["function"],當前執行的函數名稱.
3495
	#$result["argu"],當前函式使用的參數.
3496
	#必填參數:
3497
	#$conf["fileAddress"],字串,要移除檔案的位置.
3498
	$conf["fileAddress"]="";
3499
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3500
	$conf["fileArgu"]=__FILE__;
3501
	#可省略參數:
3502
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
3503
	#$conf["commentsArray"]=array("");
3504
	#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
3505
	#$conf["allowDelSymlink"]="true";
3506
	#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
3507
	#$conf["allowDelFolder"]="true";
3508
	#參考資料:
3509
	#無.
3510
	#備註:
3511
	#無.
220 liveuser 3512
	*/
3 liveuser 3513
	public static function delFile(&$conf){
3514
 
3515
		#初始化要回傳的結果
3516
		$result=array();
226 liveuser 3517
 
3 liveuser 3518
		#設置當其函數名稱
3519
		$result["function"]=__FUNCTION__;
226 liveuser 3520
 
3 liveuser 3521
		#如果 $conf 不為陣列
3522
		if(gettype($conf)!="array"){
226 liveuser 3523
 
3 liveuser 3524
			#設置執行失敗
3525
			$result["status"]="false";
226 liveuser 3526
 
3 liveuser 3527
			#設置執行錯誤訊息
3528
			$result["error"][]="\$conf變數須為陣列形態";
3529
 
3530
			#如果傳入的參數為 null
3531
			if($conf==null){
226 liveuser 3532
 
3 liveuser 3533
				#設置執行錯誤訊息
3534
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3535
 
3 liveuser 3536
				}#if end
3537
 
3538
			#回傳結果
3539
			return $result;
226 liveuser 3540
 
3 liveuser 3541
			}#if end
226 liveuser 3542
 
3 liveuser 3543
		#取得參數
3544
		$result["argu"]=$conf;
226 liveuser 3545
 
3 liveuser 3546
		#檢查參數
3547
		#函式說明:
3548
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3549
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3550
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3551
		#$result["function"],當前執行的函式名稱.
3552
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3553
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3554
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3555
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3556
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3557
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3558
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3559
		#必填寫的參數:
3560
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3561
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3562
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3563
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddress");
226 liveuser 3564
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3565
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
3566
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3567
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3568
		#可以省略的參數:
3569
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3570
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3571
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3572
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","allowDelSymlink","allowDelFolder");
226 liveuser 3573
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3574
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");
3575
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3576
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false","false");
3577
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3578
		#$conf["arrayCountEqualCheck"][]=array();
3579
		#參考資料來源:
3580
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3581
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3582
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3583
 
3 liveuser 3584
		#如果檢查失敗
3585
		if($checkResult["status"]=="false"){
226 liveuser 3586
 
3 liveuser 3587
			#設置錯誤識別
3588
			$result["status"]="false";
226 liveuser 3589
 
3 liveuser 3590
			#設置錯誤訊息
3591
			$result["error"]=$checkResult;
226 liveuser 3592
 
3 liveuser 3593
			#回傳結果
3594
			return $result;
226 liveuser 3595
 
3 liveuser 3596
			}#if end
226 liveuser 3597
 
3 liveuser 3598
		#如果檢查不通過
3599
		if($checkResult["passed"]=="false"){
226 liveuser 3600
 
3 liveuser 3601
			#設置錯誤識別
3602
			$result["status"]="false";
226 liveuser 3603
 
3 liveuser 3604
			#設置錯誤訊息
3605
			$result["error"]=$checkResult;
226 liveuser 3606
 
3 liveuser 3607
			#回傳結果
3608
			return $result;
226 liveuser 3609
 
3 liveuser 3610
			}#if end
3611
 
3612
		#如果 $conf["commentsArray"] 有設定
3613
		if(isset($conf["commentsArray"])){
226 liveuser 3614
 
3 liveuser 3615
			#印出提示文字
3616
			#函式說明:
3617
			#印出多行文字,結尾自動換行.
3618
			#回傳的結果:
3619
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
3620
			#$result["function"],當前執行的函數名稱.
3621
			#$result["error"],錯誤訊息陣列.
3622
			#必填參數:
3623
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
3624
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
3625
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
3626
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 3627
 
3 liveuser 3628
			#如果印出提示文字失敗
3629
			if($echoMultiLine["status"]=="false"){
226 liveuser 3630
 
3 liveuser 3631
				#設置執行失敗
3632
				$result["status"]="false";
226 liveuser 3633
 
3 liveuser 3634
				#設置執行錯誤訊息
3635
				$result["error"]=$echoMultiLine;
226 liveuser 3636
 
3 liveuser 3637
				#回傳結果
3638
				return $result;
226 liveuser 3639
 
3 liveuser 3640
				}#if end
226 liveuser 3641
 
3 liveuser 3642
			}#if end
3643
 
3644
		#檢查要移除的檔案是否存在
3645
		#函式說明:
3646
		#檢查多個檔案與資料夾是否存在.
3647
		#回傳的結果:
3648
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3649
		#$result["error"],錯誤訊息陣列.
3650
		#$resutl["function"],當前執行的涵式名稱.
3651
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
3652
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
3653
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
3654
		#必填參數:
3655
		$conf["fileAccess.checkMultiFileExist"]["fileArray"]=array($conf["fileAddress"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
3656
		#$conf["fileAccess.checkMultiFileExist"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3657
		$conf["fileAccess.checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
3658
		#可省略參數:
3659
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
3660
		#$conf["disableWebSearch"]="false";
3661
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
3662
		#$conf["userDir"]="true";
3663
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
3664
		$conf["fileAccess.checkMultiFileExist"]["web"]="false";
3665
		#參考資料來源:
3666
		#http://php.net/manual/en/function.file-exists.php
3667
		#http://php.net/manual/en/control-structures.foreach.php
3668
		$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess.checkMultiFileExist"]);
3669
		unset($conf["fileAccess.checkMultiFileExist"]);
3670
 
3671
		#var_dump($checkResult);
3672
 
3673
		#如果檢查檔案是否存在失敗
3674
		if($checkResult["status"]==="false"){
226 liveuser 3675
 
3 liveuser 3676
			#設置執行失敗
3677
			$result["status"]="false";
3678
 
3679
			#回傳錯誤訊息
3680
			$result["error"]=$checkResult;
3681
 
3682
			#回傳結果
3683
			return $result;
226 liveuser 3684
 
3 liveuser 3685
			}#if end
3686
 
3687
		#如果目標檔案不存在
3688
		if($checkResult["varExist"][0]==="false"){
226 liveuser 3689
 
3 liveuser 3690
			#設置錯誤識別
3691
			$result["status"]="true";
3692
 
3693
			#回傳錯誤訊息
3694
			$result["warning"][]="要移除的檔案不存在";
3695
 
3696
			#回傳結果
3697
			return $result;
226 liveuser 3698
 
3 liveuser 3699
			}#if end
3700
 
3701
		#如果要移除的目標是檔案
3702
		if(is_file($conf["fileAddress"])){
226 liveuser 3703
 
3 liveuser 3704
			#移除檔案,並回傳移除的結果
3705
			$eraseResult=(@unlink($conf["fileAddress"]));
3706
 
3707
			#如果 $eraseResult 等於 false
3708
			if($eraseResult===false){
226 liveuser 3709
 
3 liveuser 3710
				#設置錯誤識別
3711
				$result["status"]="false";
3712
 
3713
				#回傳錯誤訊息
3714
				$result["error"][]="檔案移除失敗";
3715
 
3716
				#回傳結果
3717
				return $result;
226 liveuser 3718
 
3 liveuser 3719
				}#if end
226 liveuser 3720
 
3 liveuser 3721
			}#if end
3722
 
3723
		#反之要移除的目標是目錄
3724
		else if(is_dir($conf["fileAddress"])){
226 liveuser 3725
 
3 liveuser 3726
			#如果允許移除目錄
3727
			if($conf["allowDelFolder"]==="true"){
226 liveuser 3728
 
3 liveuser 3729
				#移除目錄跟底下的內容
3730
				w函式說明:
3731
				#呼叫shell執行系統命令,並取得回傳的內容.
3732
				#回傳結果:
3733
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3734
				#$result["error"],錯誤訊息陣列.
3735
				#$result["function"],當前執行的函數名稱.
3736
				#$result["argu"],使用的參數.
3737
				#$result["cmd"],執行的指令內容.
3738
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
3739
				#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
3740
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
3741
				#$result["running"],是否還在執行.
3742
				#$result["pid"],pid.
3743
				#$result["statusCode"],執行結束後的代碼.
3744
				#必填參數:
3745
				#$conf["command"],字串,要執行的指令.
3746
				$conf["external::callShell"]["command"]="rm";
3747
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3748
				$conf["external::callShell"]["fileArgu"]=__FILE__;
3749
				#可省略參數:
3750
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3751
				$conf["external::callShell"]["argu"]=array("-rf",$conf["fileAddress"]);
3752
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
3753
				#$conf["arguIsAddr"]=array();
3754
				#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
3755
				#$conf["plainArgu"]=array();
3756
				#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
3757
				#$conf["useApostrophe"]=array();
3758
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
3759
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
3760
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
3761
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
3762
				#$conf["enablePrintDescription"]="true";
3763
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
3764
				#$conf["printDescription"]="";
3765
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
3766
				$conf["external::callShell"]["escapeshellarg"]="true";
3767
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
3768
				#$conf["thereIsShellVar"]=array();
3769
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
3770
				#$conf["username"]="";
3771
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
3772
				#$conf["password"]="";
3773
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
3774
				#$conf["useScript"]="";
3775
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
3776
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
3777
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
3778
				#$conf["inBackGround"]="";
3779
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
3780
				#$conf["getErr"]="false";
3781
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
3782
				#$conf["doNotRun"]="false";
3783
				#參考資料:
3784
				#exec=>http://php.net/manual/en/function.exec.php
3785
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
3786
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
3787
				#備註:
3788
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
3789
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
3790
				$callShell=external::callShell($conf["external::callShell"]);
3791
				unset($conf["external::callShell"]);
226 liveuser 3792
 
3 liveuser 3793
				#如果執行失敗
3794
				if($callShell["status"]==="false"){
226 liveuser 3795
 
3 liveuser 3796
					#設置錯誤識別
3797
					$result["status"]="false";
3798
 
3799
					#回傳錯誤訊息
3800
					$result["error"]=$callShell;
3801
 
3802
					#回傳結果
3803
					return $result;
226 liveuser 3804
 
3 liveuser 3805
					}#if end
226 liveuser 3806
 
3807
				}#if end
3808
 
3 liveuser 3809
			#反之不允許
3810
			else{
226 liveuser 3811
 
3 liveuser 3812
				#設置錯誤識別
3813
				$result["status"]="false";
3814
 
3815
				#回傳錯誤訊息
3816
				$result["error"][]="不允許移除目錄";
226 liveuser 3817
 
3 liveuser 3818
				#回傳結果
3819
				return $result;
226 liveuser 3820
 
3 liveuser 3821
				}#else end
226 liveuser 3822
 
3 liveuser 3823
			}#if end
226 liveuser 3824
 
3 liveuser 3825
		#反之
3826
		else{
226 liveuser 3827
 
3 liveuser 3828
			#可能為 軟連結
226 liveuser 3829
 
3 liveuser 3830
			#如果允許移除
3831
			if($conf["allowDelSymlink"]==="true"){
226 liveuser 3832
 
3 liveuser 3833
				#移除檔案,並回傳移除的結果
3834
				$eraseResult=(@unlink($conf["fileAddress"]));
3835
 
3836
				#如果 $eraseResult 等於 false
3837
				if($eraseResult===false){
226 liveuser 3838
 
3 liveuser 3839
					#設置錯誤識別
3840
					$result["status"]="false";
3841
 
3842
					#回傳錯誤訊息
3843
					$result["error"][]="檔案移除失敗";
3844
 
3845
					#回傳結果
3846
					return $result;
226 liveuser 3847
 
3 liveuser 3848
					}#if end
226 liveuser 3849
 
3 liveuser 3850
				}#if end
226 liveuser 3851
 
3 liveuser 3852
			#反之
3853
			else{
226 liveuser 3854
 
3 liveuser 3855
				#設置錯誤識別
3856
				$result["status"]="false";
226 liveuser 3857
 
3 liveuser 3858
				#設置錯誤訊息
3859
				$result["error"][]="不允許移除 檔案、目錄 以外類型的目標";
3860
 
3861
				#回傳結果
3862
				return $result;
226 liveuser 3863
 
3 liveuser 3864
				}#else end
226 liveuser 3865
 
3 liveuser 3866
			}#else end
226 liveuser 3867
 
3 liveuser 3868
		#執行到這邊代表執行正常.
3869
		$result["status"]="true";
226 liveuser 3870
 
3 liveuser 3871
		#回傳結果
3872
		return $result;
3873
 
3874
		}#function delFile end
226 liveuser 3875
 
3 liveuser 3876
	/*
3877
	#函式說明:
3878
	#移除多個檔案
3879
	#回傳結果:
3880
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
3881
	#$result["error"],錯誤訊息陣列
3882
	#$result["function"],當前執行的函數名稱.
3883
	#$result["argu"],使用的參數.
3884
	#$result["content"],陣列,移除各個檔案的結果.
3885
	#必填參數:
3886
	#$conf["fileAddress"],字串陣列,要移除檔案的位置.
3887
	$conf["fileAddress"]=array("");
3888
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3889
	$conf["fileArgu"]=__FILE__;
3890
	#可省略參數:
3891
	#無.
3892
	#參考資料:
3893
	#無.
3894
	#備註:
3895
	#無.
220 liveuser 3896
	*/
3 liveuser 3897
	public static function delMultiFile(&$conf){
226 liveuser 3898
 
3 liveuser 3899
		#初始化要回傳的結果
3900
		$result=array();
226 liveuser 3901
 
3 liveuser 3902
		#設置當其函數名稱
3903
		$result["function"]=__FUNCTION__;
226 liveuser 3904
 
3 liveuser 3905
		#如果 $conf 不為陣列
3906
		if(gettype($conf)!="array"){
226 liveuser 3907
 
3 liveuser 3908
			#設置執行失敗
3909
			$result["status"]="false";
226 liveuser 3910
 
3 liveuser 3911
			#設置執行錯誤訊息
3912
			$result["error"][]="\$conf變數須為陣列形態";
3913
 
3914
			#如果傳入的參數為 null
3915
			if($conf==null){
226 liveuser 3916
 
3 liveuser 3917
				#設置執行錯誤訊息
3918
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3919
 
3 liveuser 3920
				}#if end
3921
 
3922
			#回傳結果
3923
			return $result;
226 liveuser 3924
 
3 liveuser 3925
			}#if end
226 liveuser 3926
 
3 liveuser 3927
		#取得使用的參數.
3928
		$result["argu"]=$conf;
226 liveuser 3929
 
3 liveuser 3930
		#檢查參數
3931
		#函式說明:
3932
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3933
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3934
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3935
		#$result["function"],當前執行的函式名稱.
3936
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3937
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3938
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3939
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3940
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3941
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3942
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3943
		#必填寫的參數:
3944
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3945
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3946
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3947
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddress");
226 liveuser 3948
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3949
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
3950
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3951
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3952
		#可以省略的參數:
3953
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3954
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3955
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3956
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray");
226 liveuser 3957
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3958
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
3959
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3960
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
3961
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3962
		#$conf["arrayCountEqualCheck"][]=array();
3963
		#參考資料來源:
3964
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3965
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3966
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3967
 
3 liveuser 3968
		#如果檢查失敗
3969
		if($checkResult["status"]=="false"){
226 liveuser 3970
 
3 liveuser 3971
			#設置錯誤識別
3972
			$result["status"]="false";
226 liveuser 3973
 
3 liveuser 3974
			#設置錯誤訊息
3975
			$result["error"]=$checkResult;
226 liveuser 3976
 
3 liveuser 3977
			#回傳結果
3978
			return $result;
226 liveuser 3979
 
3 liveuser 3980
			}#if end
226 liveuser 3981
 
3 liveuser 3982
		#如果檢查不通過
3983
		if($checkResult["passed"]=="false"){
226 liveuser 3984
 
3 liveuser 3985
			#設置錯誤識別
3986
			$result["status"]="false";
226 liveuser 3987
 
3 liveuser 3988
			#設置錯誤訊息
3989
			$result["error"]=$checkResult;
226 liveuser 3990
 
3 liveuser 3991
			#回傳結果
3992
			return $result;
226 liveuser 3993
 
3 liveuser 3994
			}#if end
226 liveuser 3995
 
3 liveuser 3996
		#針對每個要移除的檔案
3997
		foreach($conf["fileAddress"] as $fileAddr){
226 liveuser 3998
 
3 liveuser 3999
			#函式說明:
4000
			#移除檔案
4001
			#回傳結果:
4002
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
4003
			#$result["error"],錯誤訊息陣列
4004
			#$result["warning"],警告訊息陣列
4005
			#$result["function"],當前執行的函數名稱
4006
			#必填參數:
4007
			#$conf["fileAddress"],字串,要移除檔案的位置.
4008
			$conf["fileAccess::delFile"]["fileAddress"]=$fileAddr;
4009
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
4010
			$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
4011
			#可省略參數:
4012
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
4013
			#$conf["commentsArray"]=array("");
4014
			#備註:
4015
			#無.
4016
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
4017
			unset($conf["fileAccess::delFile"]);
226 liveuser 4018
 
3 liveuser 4019
			#如果檢查失敗
4020
			if($delFile["status"]==="false"){
226 liveuser 4021
 
3 liveuser 4022
				#設置錯誤識別
4023
				$result["status"]="false";
226 liveuser 4024
 
3 liveuser 4025
				#設置錯誤訊息
4026
				$result["error"]=$delFile;
226 liveuser 4027
 
3 liveuser 4028
				#回傳結果
4029
				return $result;
226 liveuser 4030
 
3 liveuser 4031
				}#if end
226 liveuser 4032
 
3 liveuser 4033
			#取得移除檔案的結果
4034
			$result["content"][]=$delFile;
226 liveuser 4035
 
3 liveuser 4036
			}#foreach end
226 liveuser 4037
 
3 liveuser 4038
		#設置執行正常
4039
		$result["status"]="true";
226 liveuser 4040
 
3 liveuser 4041
		#回傳結果
4042
		return $result;
226 liveuser 4043
 
3 liveuser 4044
		}#function delMultiFile end
226 liveuser 4045
 
3 liveuser 4046
	/*
4047
	#函式說明:
4048
	#確保路徑存在.
4049
	#回傳結果:
4050
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4051
	#$result["error"],錯誤訊息陣列.
4052
	#$resutl["function"],當前執行的涵式名稱.
4053
	#$result["path"],建立好的路徑字串.
4054
	#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
4055
	#$result["argu"],使用的參數.
4056
	#必填參數:
4057
	#$conf["path"],要檢查的路徑
226 liveuser 4058
	$conf["path"]="";
3 liveuser 4059
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4060
	$conf["fileArgu"]=__FILE__;
4061
	#可省略參數:
4062
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4063
	#$conf["haveFileName"]="false";
4064
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人無法使用.
4065
	#$conf["dirPermission"]="";
4066
	#$conf["web"],是否為檔案系統,"true"為網頁路徑,"false"為網頁系統,預設為"false".
4067
	#$conf["web"]="";
4068
	#參考資料:
4069
	#無.
4070
	#備註:
4071
	#無.
226 liveuser 4072
	*/
3 liveuser 4073
	public static function validatePath(&$conf){
226 liveuser 4074
 
3 liveuser 4075
		#初始化要回傳的結果
4076
		$result=array();
226 liveuser 4077
 
3 liveuser 4078
		#設置當其函數名稱
4079
		$result["function"]=__FUNCTION__;
226 liveuser 4080
 
3 liveuser 4081
		#如果 $conf 不為陣列
4082
		if(gettype($conf)!="array"){
226 liveuser 4083
 
3 liveuser 4084
			#設置執行失敗
4085
			$result["status"]="false";
226 liveuser 4086
 
3 liveuser 4087
			#設置執行錯誤訊息
4088
			$result["error"][]="\$conf變數須為陣列形態";
4089
 
4090
			#如果傳入的參數為 null
4091
			if($conf==null){
226 liveuser 4092
 
3 liveuser 4093
				#設置執行錯誤訊息
4094
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4095
 
3 liveuser 4096
				}#if end
226 liveuser 4097
 
3 liveuser 4098
			#回傳結果
4099
			return $result;
226 liveuser 4100
 
3 liveuser 4101
			}#if end
226 liveuser 4102
 
3 liveuser 4103
		#取得使用的參數
226 liveuser 4104
		$result["argu"]=$conf;
4105
 
3 liveuser 4106
		#檢查參數
4107
		#函式說明:
4108
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4109
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4110
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4111
		#$result["function"],當前執行的函式名稱.
4112
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4113
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4114
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4115
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
4116
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
4117
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4118
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4119
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4120
		#必填寫的參數:
4121
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4122
		$conf["variableCheck::checkArgument"]["varInput"]=&$conf;
4123
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4124
		$conf["variableCheck::checkArgument"]["mustBeFilledVariableName"]=array("path","fileArgu");
4125
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
4126
		$conf["variableCheck::checkArgument"]["mustBeFilledVariableType"]=array("string","string");
4127
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4128
		$conf["variableCheck::checkArgument"]["referenceVarKey"]="variableCheck::checkArgument";
4129
		#可以省略的參數:
4130
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4131
		$conf["variableCheck::checkArgument"]["canBeEmptyString"]="false";
4132
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
4133
		$conf["variableCheck::checkArgument"]["skipableVariableCanNotBeEmpty"]=array("haveFileName","dirPermission","web");
4134
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4135
		$conf["variableCheck::checkArgument"]["skipableVariableName"]=array("haveFileName","dirPermission","web");
226 liveuser 4136
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4137
		$conf["variableCheck::checkArgument"]["skipableVariableType"]=array("string","string","string");
4138
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4139
		$conf["variableCheck::checkArgument"]["skipableVarDefaultValue"]=array("false","0770","false");
4140
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4141
		#$conf["arrayCountEqualCheck"][]=array();
4142
		#參考資料來源:
4143
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4144
		$checkArgument=variableCheck::checkArguments($conf["variableCheck::checkArgument"]);
4145
		unset($conf["variableCheck::checkArgument"]);
226 liveuser 4146
 
3 liveuser 4147
		#如果檢查過程出錯
4148
		if($checkArgument["status"]==="false"){
226 liveuser 4149
 
3 liveuser 4150
			#設置執行失敗
4151
			$result["status"]="false";
226 liveuser 4152
 
3 liveuser 4153
			#設置執行錯誤訊息
4154
			$result["error"]=$checkArgument;
4155
 
4156
			#回傳結果
4157
			return $result;
226 liveuser 4158
 
3 liveuser 4159
			}#if end
226 liveuser 4160
 
3 liveuser 4161
		#如果檢查不通過
4162
		if($checkArgument["passed"]==="false"){
226 liveuser 4163
 
3 liveuser 4164
			#設置執行失敗
4165
			$result["status"]="false";
226 liveuser 4166
 
3 liveuser 4167
			#設置執行錯誤訊息
4168
			$result["error"]=$checkArgument;
4169
 
4170
			#回傳結果
4171
			return $result;
226 liveuser 4172
 
3 liveuser 4173
			}#if end
226 liveuser 4174
 
3 liveuser 4175
		#函式說明:
4176
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
4177
		#回傳結果:
4178
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
4179
		#$result["error"],錯誤訊息陣列.
226 liveuser 4180
		#$result["function"],函數名稱.
3 liveuser 4181
		#$result["argu"],使用的參數.
4182
		#$result["content"],網址,若是在命令列執行,則為"null".
4183
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
4184
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
4185
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
4186
		#必填參數:
4187
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
4188
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["path"];
4189
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
4190
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
4191
		#可省略參數:
4192
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
4193
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
4194
		#備註:
4195
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
4196
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 4197
		unset($conf["fileAccess::getInternetAddressV2"]);
4198
 
3 liveuser 4199
		#如果檢查過程出錯
4200
		if($getInternetAddressV2["status"]=="false"){
226 liveuser 4201
 
3 liveuser 4202
			#設置執行失敗
4203
			$result["status"]="false";
226 liveuser 4204
 
3 liveuser 4205
			#設置執行錯誤訊息
4206
			$result["error"]=$getInternetAddressV2;
4207
 
4208
			#回傳結果
4209
			return $result;
226 liveuser 4210
 
4211
			}#if end
4212
 
3 liveuser 4213
		#取得轉換好的絕對路徑
4214
		$result["path"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 4215
 
3 liveuser 4216
		#debug
4217
		#var_dump($getInternetAddressV2);exit;
226 liveuser 4218
 
3 liveuser 4219
		#如果 路徑 含有檔案名稱
4220
		if($conf["haveFileName"]==="true"){
226 liveuser 4221
 
3 liveuser 4222
			#預設要加回去的結束字串為空字串
4223
			$endStr="";
226 liveuser 4224
 
3 liveuser 4225
			#如果開頭跟結尾都是 "'"
4226
			if( strpos($result["path"],"'")===0 && strpos($result["path"],"'")===(strlen($result["path"])-1) ){
226 liveuser 4227
 
3 liveuser 4228
				#設置要加回去的結束字串
4229
				$endStr="'";
226 liveuser 4230
 
3 liveuser 4231
				}#if end
226 liveuser 4232
 
3 liveuser 4233
			#函式說明:
4234
			#將固定格式的字串分開,並回傳分開的結果。
4235
			#回傳結果:
4236
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4237
			#$result["error"],錯誤訊息陣列
4238
			#$result["function"],當前執行的函數名稱.
4239
			#$result["argu"],使用的參數.
4240
			#$result["oriStr"],要分割的原始字串內容
4241
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4242
			#$result["dataCounts"],爲總共分成幾段
4243
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
4244
			#必填參數:
4245
			#$conf["stringIn"],字串,要處理的字串.
4246
			$conf["stringProcess::spiltString"]["stringIn"]=$result["path"];
4247
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
4248
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
4249
			#可省略參數:
4250
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
4251
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
4252
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4253
			unset($conf["stringProcess::spiltString"]);
226 liveuser 4254
 
3 liveuser 4255
			#如果檢查過程出錯
4256
			if($spiltString["status"]==="false"){
226 liveuser 4257
 
3 liveuser 4258
				#設置執行失敗
4259
				$result["status"]="false";
226 liveuser 4260
 
3 liveuser 4261
				#設置執行錯誤訊息
4262
				$result["error"]=$spiltString;
4263
 
4264
				#回傳結果
4265
				return $result;
226 liveuser 4266
 
3 liveuser 4267
				}#if end
226 liveuser 4268
 
3 liveuser 4269
			#初始化儲存 path
4270
			$path="";
226 liveuser 4271
 
3 liveuser 4272
			#針對n-1段的內容
4273
			for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 4274
 
3 liveuser 4275
				#串接路徑
4276
				$path=$path."/".$spiltString["dataArray"][$i];
226 liveuser 4277
 
3 liveuser 4278
				}#for end
226 liveuser 4279
 
3 liveuser 4280
			#如果路徑為空
4281
			if($path===""){
226 liveuser 4282
 
3 liveuser 4283
				#則與設為根目錄
4284
				$path="/";
226 liveuser 4285
 
3 liveuser 4286
				}#if end
226 liveuser 4287
 
3 liveuser 4288
			#設置檔案名稱
4289
			$result["fileName"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 4290
 
3 liveuser 4291
			#取得不含檔案名稱的路徑
4292
			$conf["path"]=$path.$endStr;
226 liveuser 4293
 
3 liveuser 4294
			#取得不含檔案名稱的路徑
4295
			$result["path"]=$path.$endStr;
226 liveuser 4296
 
3 liveuser 4297
			}#if end
226 liveuser 4298
 
3 liveuser 4299
		#函式說明:
4300
		#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
4301
		#回傳結果:
4302
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
4303
		#$result["error"],錯誤訊息陣列
4304
		#必填參數:
4305
		$conf["fileAccess::createFolderAfterCheck"]["dirPositionAndName"]=$conf["path"];#新建的位置與名稱
4306
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4307
		$conf["fileAccess::createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
4308
		#可省略參數:
4309
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
4310
		$conf["fileAccess::createFolderAfterCheck"]["dirPermission"]=$conf["dirPermission"];
4311
		$conf["fileAccess::createFolderAfterCheck"]["web"]="false";
4312
		#參考資料:
4313
		#mkdir=>http://php.net/manual/en/function.mkdir.php
4314
		#chmod=>http://php.net/manual/en/function.chmod.php
4315
		$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf["fileAccess::createFolderAfterCheck"]);
4316
		unset($conf["fileAccess::createFolderAfterCheck"]);
226 liveuser 4317
 
3 liveuser 4318
		#如果建立路徑過程出錯
4319
		if($createFolderAfterCheck["status"]==="false"){
226 liveuser 4320
 
3 liveuser 4321
			#設置執行失敗
4322
			$result["status"]="false";
226 liveuser 4323
 
3 liveuser 4324
			#設置執行錯誤訊息
4325
			$result["error"]=$createFolderAfterCheck;
4326
 
4327
			#回傳結果
4328
			return $result;
226 liveuser 4329
 
3 liveuser 4330
			}#if end
226 liveuser 4331
 
3 liveuser 4332
		#如果有警告訊息
4333
		if(count($createFolderAfterCheck["warning"])>0){
226 liveuser 4334
 
3 liveuser 4335
			#取得警告訊息
4336
			$result["error"]=$createFolderAfterCheck["warning"];
226 liveuser 4337
 
3 liveuser 4338
			#設置執行失敗
4339
			$result["status"]="false";
226 liveuser 4340
 
3 liveuser 4341
			#回傳結果
4342
			return $result;
226 liveuser 4343
 
3 liveuser 4344
			}#if end
226 liveuser 4345
 
3 liveuser 4346
		#執行到這邊代表成功
4347
		$result["status"]="true";
226 liveuser 4348
 
3 liveuser 4349
		#回傳結果
4350
		return $result;
226 liveuser 4351
 
3 liveuser 4352
		}#function validatePath end
226 liveuser 4353
 
3 liveuser 4354
	/*
4355
	#函式說明:
4356
	#解析路徑的每個層級.
4357
	#回傳結果:
4358
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4359
	#$result["error"],錯誤訊息陣列.
4360
	#$resutl["function"],當前執行的涵式名稱.
4361
	#$result["argu"],使用的參數.
4362
	#$result["content"],解析出來的路徑階層.
4363
	#必填參數:
4364
	#$conf["path"],要檢查的路徑
4365
	$conf["path"]="";
4366
	#可省略參數:
4367
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4368
	#$conf["haveFileName"]="false";
4369
	#參考資料:
4370
	#無.
4371
	#備註:
4372
	#無.
4373
	*/
4374
	public static function parsePath(&$conf){
226 liveuser 4375
 
3 liveuser 4376
		#初始化要回傳的內容
4377
		$result=array();
4378
 
4379
		#取得當前執行的函數名稱
4380
		$result["function"]=__FUNCTION__;
4381
 
4382
		#如果 $conf 不為陣列
4383
		if(gettype($conf)!="array"){
226 liveuser 4384
 
3 liveuser 4385
			#設置執行失敗
4386
			$result["status"]="false";
226 liveuser 4387
 
3 liveuser 4388
			#設置執行錯誤訊息
4389
			$result["error"][]="\$conf變數須為陣列形態";
4390
 
4391
			#如果傳入的參數為 null
4392
			if($conf==null){
226 liveuser 4393
 
3 liveuser 4394
				#設置執行錯誤訊息
4395
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4396
 
3 liveuser 4397
				}#if end
4398
 
4399
			#回傳結果
4400
			return $result;
226 liveuser 4401
 
3 liveuser 4402
			}#if end
4403
 
4404
		#記錄使用的參數
4405
		$result["argu"]=$conf;
4406
 
4407
		#檢查參數
4408
		#函式說明:
4409
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4410
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4411
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4412
		#$result["function"],當前執行的函式名稱.
4413
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4414
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4415
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4416
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4417
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4418
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4419
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4420
		#必填寫的參數:
4421
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4422
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4423
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4424
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
226 liveuser 4425
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 4426
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
4427
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4428
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4429
		#可以省略的參數:
4430
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4431
		#$conf["canBeEmptyString"]="false";
4432
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4433
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("haveFileName");
226 liveuser 4434
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4435
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
4436
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4437
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
4438
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4439
		#$conf["arrayCountEqualCheck"][]=array();
4440
		#參考資料來源:
4441
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4442
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4443
		unset($conf["variableCheck::checkArguments"]);
4444
 
4445
		#如果檢查有誤
4446
		if($checkResult["status"]=="false"){
226 liveuser 4447
 
3 liveuser 4448
			#設置錯誤識別
4449
			$result["status"]="false";
226 liveuser 4450
 
3 liveuser 4451
			#設置錯誤訊息
4452
			$result["error"]=$checkResult;
226 liveuser 4453
 
3 liveuser 4454
			#回傳結果
4455
			return $result;
226 liveuser 4456
 
3 liveuser 4457
			}#if end
226 liveuser 4458
 
3 liveuser 4459
		#如果檢查不通過
4460
		if($checkResult["passed"]=="false"){
226 liveuser 4461
 
3 liveuser 4462
			#設置錯誤識別
4463
			$result["status"]="false";
226 liveuser 4464
 
3 liveuser 4465
			#設置錯誤訊息
4466
			$result["error"]=$checkResult;
226 liveuser 4467
 
3 liveuser 4468
			#回傳結果
4469
			return $result;
226 liveuser 4470
 
3 liveuser 4471
			}#if end
226 liveuser 4472
 
3 liveuser 4473
		#函式說明:
4474
		#將固定格式的字串分開,並回傳分開的結果.
4475
		#回傳結果:
4476
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4477
		#$result["error"],錯誤訊息陣列
4478
		#$result["function"],當前執行的函數名稱.
4479
		#$result["argu"],使用的參數.
4480
		#$result["oriStr"],要分割的原始字串內容
4481
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4482
		#$result["dataCounts"],爲總共分成幾段
4483
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
4484
		#必填參數:
4485
		#$conf["stringIn"],字串,要處理的字串.
4486
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["path"];
4487
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
4488
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
4489
		#可省略參數:
4490
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
4491
		#$conf["allowEmptyStr"]="false";
4492
		#參考資料:
4493
		#無.
4494
		#備註:
4495
		#無.
4496
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4497
		unset($conf["stringProcess::spiltString"]);
226 liveuser 4498
 
3 liveuser 4499
		#如果檢查有誤
4500
		if($spiltString["status"]==="false"){
226 liveuser 4501
 
3 liveuser 4502
			#設置錯誤識別
4503
			$result["status"]="false";
226 liveuser 4504
 
3 liveuser 4505
			#設置錯誤訊息
4506
			$result["error"]=$spiltString;
226 liveuser 4507
 
3 liveuser 4508
			#回傳結果
4509
			return $result;
226 liveuser 4510
 
3 liveuser 4511
			}#if end
226 liveuser 4512
 
3 liveuser 4513
		#確認是否為絕對路徑
4514
		#函式說明:
4515
		#取得符合特定字首與字尾的字串
4516
		#回傳結果:
4517
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
4518
		#$result["function"],當前執行的函數名稱.
4519
		#$result["error"],錯誤訊息陣列.
4520
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
4521
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
4522
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
4523
		#$result["argu"],使用的參數.
4524
		#必填參數:
4525
		#$conf["checkString"],字串,要檢查的字串.
4526
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["path"];
4527
		#可省略參數:
4528
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
4529
		$conf["search::getMeetConditionsString"]["frontWord"]="/";
4530
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
4531
		#$conf["search::getMeetConditionsString"]["tailWord"]="";
4532
		#參考資料:
4533
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
4534
		#備註:
4535
		#無.
4536
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
4537
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 4538
 
3 liveuser 4539
		#如果檢查有誤
4540
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 4541
 
3 liveuser 4542
			#設置錯誤識別
4543
			$result["status"]="false";
226 liveuser 4544
 
3 liveuser 4545
			#設置錯誤訊息
4546
			$result["error"]=$getMeetConditionsString;
226 liveuser 4547
 
3 liveuser 4548
			#回傳結果
4549
			return $result;
226 liveuser 4550
 
3 liveuser 4551
			}#if end
226 liveuser 4552
 
3 liveuser 4553
		#如果是絕對路徑
4554
		if($getMeetConditionsString["founded"]==="true"){
226 liveuser 4555
 
3 liveuser 4556
			#初始化路徑為 "/"
4557
			$result["content"][]="/";
226 liveuser 4558
 
3 liveuser 4559
			}#if end
226 liveuser 4560
 
3 liveuser 4561
		#針對每個切割出來的路徑階層
4562
		foreach($spiltString["dataArray"] as $index => $dir){
226 liveuser 4563
 
3 liveuser 4564
			#如果路徑結尾含有檔案名稱
4565
			if($conf["haveFileName"]==="true"){
226 liveuser 4566
 
3 liveuser 4567
				#如果是最後一段
4568
				if($index===$spiltString["dataCounts"]-1){
226 liveuser 4569
 
3 liveuser 4570
					#忽略
4571
					continue;
226 liveuser 4572
 
3 liveuser 4573
					}#if end
226 liveuser 4574
 
3 liveuser 4575
				}#if end
226 liveuser 4576
 
3 liveuser 4577
			#後面加上 資料夾名稱 跟 "/"
4578
			$newPath=$dir."/";
226 liveuser 4579
 
3 liveuser 4580
			#如果有 content
4581
			if(isset($result["content"])){
226 liveuser 4582
 
3 liveuser 4583
				#如果有上個資料夾
4584
				if(isset($result["content"][count($result["content"])-1])){
226 liveuser 4585
 
3 liveuser 4586
					#後面加上 上個資料夾名稱 加上資料夾名稱 跟 "/"
4587
					$newPath=$result["content"][count($result["content"])-1].$dir."/";
226 liveuser 4588
 
3 liveuser 4589
					}#if end
226 liveuser 4590
 
3 liveuser 4591
				}#if end
226 liveuser 4592
 
3 liveuser 4593
			#並新增置結果
4594
			$result["content"][]=$newPath;
226 liveuser 4595
 
3 liveuser 4596
			}#foreach end
226 liveuser 4597
 
3 liveuser 4598
		#var_dump($result["content"]);
226 liveuser 4599
 
3 liveuser 4600
		#設置執行正常
4601
		$result["status"]="true";
226 liveuser 4602
 
3 liveuser 4603
		#回傳結果
4604
		return $result;
226 liveuser 4605
 
3 liveuser 4606
		}#function parsePath end
226 liveuser 4607
 
3 liveuser 4608
	/*
4609
	#函式說明:
4610
	#檢查路徑是否存在.
4611
	#回傳結果:
4612
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4613
	#$result["error"],錯誤訊息陣列.
4614
	#$resutl["function"],當前執行的涵式名稱.
4615
	#$result["argu"],使用的參數.
4616
	#$result["found"],路徑是否存在,"true"代表存在,"false"代表不存在.
4617
	#$result["content"],每個階層路徑的檢查結果,每個元素有檢查的路徑"path"跟是否有存在或可存取的識別"found".
4618
	#必填參數:
4619
	#$conf["path"],要檢查的路徑
4620
	$conf["path"]="";
4621
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4622
	$conf["fileArgu"]=__FILE__;
4623
	#可省略參數:
4624
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4625
	#$conf["haveFileName"]="false";
4626
	#參考資料:
4627
	#無.
4628
	#備註:
4629
	#無.
4630
	*/
4631
	public static function checkPathExist(&$conf){
226 liveuser 4632
 
3 liveuser 4633
		#初始化要回傳的內容
4634
		$result=array();
4635
 
4636
		#取得當前執行的函數名稱
4637
		$result["function"]=__FUNCTION__;
4638
 
4639
		#如果 $conf 不為陣列
4640
		if(gettype($conf)!="array"){
226 liveuser 4641
 
3 liveuser 4642
			#設置執行失敗
4643
			$result["status"]="false";
226 liveuser 4644
 
3 liveuser 4645
			#設置執行錯誤訊息
4646
			$result["error"][]="\$conf變數須為陣列形態";
4647
 
4648
			#如果傳入的參數為 null
4649
			if($conf==null){
226 liveuser 4650
 
3 liveuser 4651
				#設置執行錯誤訊息
4652
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4653
 
3 liveuser 4654
				}#if end
4655
 
4656
			#回傳結果
4657
			return $result;
226 liveuser 4658
 
3 liveuser 4659
			}#if end
4660
 
4661
		#記錄使用的參數
4662
		$result["argu"]=$conf;
4663
 
4664
		#檢查參數
4665
		#函式說明:
4666
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4667
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4668
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4669
		#$result["function"],當前執行的函式名稱.
4670
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4671
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4672
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4673
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4674
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4675
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4676
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4677
		#必填寫的參數:
4678
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4679
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4680
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4681
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 4682
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 4683
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
4684
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4685
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4686
		#可以省略的參數:
4687
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4688
		#$conf["canBeEmptyString"]="false";
4689
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4690
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("haveFileName");
226 liveuser 4691
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4692
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
4693
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4694
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
4695
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4696
		#$conf["arrayCountEqualCheck"][]=array();
4697
		#參考資料來源:
4698
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4699
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4700
		unset($conf["variableCheck::checkArguments"]);
4701
 
4702
		#如果檢查有誤
4703
		if($checkResult["status"]=="false"){
226 liveuser 4704
 
3 liveuser 4705
			#設置錯誤識別
4706
			$result["status"]="false";
226 liveuser 4707
 
3 liveuser 4708
			#設置錯誤訊息
4709
			$result["error"]=$checkResult;
226 liveuser 4710
 
3 liveuser 4711
			#回傳結果
4712
			return $result;
226 liveuser 4713
 
3 liveuser 4714
			}#if end
226 liveuser 4715
 
3 liveuser 4716
		#如果檢查不通過
4717
		if($checkResult["passed"]=="false"){
226 liveuser 4718
 
3 liveuser 4719
			#設置錯誤識別
4720
			$result["status"]="false";
226 liveuser 4721
 
3 liveuser 4722
			#設置錯誤訊息
4723
			$result["error"]=$checkResult;
226 liveuser 4724
 
3 liveuser 4725
			#回傳結果
4726
			return $result;
226 liveuser 4727
 
3 liveuser 4728
			}#if end
226 liveuser 4729
 
3 liveuser 4730
		#函式說明:
4731
		#解析路徑的每個層級.
4732
		#回傳結果:
4733
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4734
		#$result["error"],錯誤訊息陣列.
4735
		#$resutl["function"],當前執行的涵式名稱.
4736
		#$result["argu"],使用的參數.
4737
		#$result["content"],解析出來的路徑階層.
4738
		#必填參數:
4739
		#$conf["path"],要檢查的路徑
4740
		$conf["fileAccess::parsePath"]["path"]=$conf["path"];
4741
		#可省略參數:
4742
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4743
		$conf["fileAccess::parsePath"]["haveFileName"]=$conf["haveFileName"];
4744
		#參考資料:
4745
		#無.
4746
		#備註:
4747
		#無.
4748
		$parsePath=fileAccess::parsePath($conf["fileAccess::parsePath"]);
4749
		unset($conf["fileAccess::parsePath"]);
226 liveuser 4750
 
3 liveuser 4751
		#如果檢查有誤
4752
		if($parsePath["status"]==="false"){
226 liveuser 4753
 
3 liveuser 4754
			#設置錯誤識別
4755
			$result["status"]="false";
226 liveuser 4756
 
3 liveuser 4757
			#設置錯誤訊息
4758
			$result["error"]=$parsePath;
226 liveuser 4759
 
3 liveuser 4760
			#回傳結果
4761
			return $result;
226 liveuser 4762
 
3 liveuser 4763
			}#if end
226 liveuser 4764
 
3 liveuser 4765
		#函式說明:
4766
		#檢查多個檔案與資料夾是否存在.
4767
		#回傳的結果:
4768
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4769
		#$result["error"],錯誤訊息陣列.
4770
		#$resutl["function"],當前執行的涵式名稱.
4771
		#$result["argu"],使用的參數.
4772
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
4773
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
4774
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
4775
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
4776
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
4777
		#必填參數:
4778
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
4779
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$parsePath["content"];
4780
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4781
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
4782
		#可省略參數:
4783
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
4784
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
4785
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
4786
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
4787
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
4788
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
4789
		#參考資料:
4790
		#http://php.net/manual/en/function.file-exists.php
4791
		#http://php.net/manual/en/control-structures.foreach.php
4792
		#備註:
4793
		#函數file_exists檢查的路徑為檔案系統的路徑
4794
		#$result["varName"][$i]結果未實作
4795
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
4796
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 4797
 
3 liveuser 4798
		#如果執行異常
4799
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 4800
 
3 liveuser 4801
			#設置錯誤識別
4802
			$result["status"]="false";
226 liveuser 4803
 
3 liveuser 4804
			#設置錯誤訊息
4805
			$result["error"]=$checkMultiFileExist;
226 liveuser 4806
 
3 liveuser 4807
			#回傳結果
4808
			return $result;
226 liveuser 4809
 
3 liveuser 4810
			}#if end
226 liveuser 4811
 
3 liveuser 4812
		#如果有路徑無法存取
4813
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 4814
 
3 liveuser 4815
			#設置執行正常識別
4816
			$result["status"]="true";
226 liveuser 4817
 
3 liveuser 4818
			#設置路徑找不到
4819
			$result["found"]="false";
226 liveuser 4820
 
3 liveuser 4821
			#針對每個路徑的搜尋結果
4822
			foreach($checkMultiFileExist["varExist"] as $index => $found){
226 liveuser 4823
 
3 liveuser 4824
				#設置路徑尋找結果
4825
				$result["content"][]=array("found"=>$found,"path"=>$checkMultiFileExist["varNameFullPath"][$index]);
226 liveuser 4826
 
3 liveuser 4827
				}#foreach end
226 liveuser 4828
 
3 liveuser 4829
			#回傳結果
4830
			return $result;
226 liveuser 4831
 
3 liveuser 4832
			}#if end
226 liveuser 4833
 
3 liveuser 4834
		#設置路徑有找到
4835
		$result["found"]="true";
226 liveuser 4836
 
3 liveuser 4837
		#設置執行正常識別
4838
		$result["status"]="true";
226 liveuser 4839
 
3 liveuser 4840
		#回傳結果
4841
		return $result;
226 liveuser 4842
 
3 liveuser 4843
		}#function checkPathExist end
226 liveuser 4844
 
4845
	/*
3 liveuser 4846
	#函式說明:
4847
	#demo建立pdf檔
4848
	#必填參數:
4849
	#無
4850
	#可省略參數:
4851
	#無
4852
	#參考資料:
4853
	#tcpdf=>http://www.tcpdf.org/examples.php
4854
	#備註:
4855
	#開發中,需要安裝 php-tcpdf 套件.
4856
	*/
4857
	public static function demoCreateTcPdfFile(){
226 liveuser 4858
 
3 liveuser 4859
		#避免 TCPDF ERROR: Some data has already been output, can't send PDF file 錯誤產生
4860
		ob_end_clean();
226 liveuser 4861
 
3 liveuser 4862
		#create new PDF document
4863
		$pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
226 liveuser 4864
 
3 liveuser 4865
		#set document information
4866
		$pdf->SetCreator(PDF_CREATOR);
4867
		$pdf->SetAuthor('qbpwc');
4868
		$pdf->SetTitle('pdf sample title');
4869
		$pdf->SetSubject('pdf sample subject');
4870
		$pdf->SetKeywords('pdf, sample, tcpdf, qbpwc');
226 liveuser 4871
 
3 liveuser 4872
		#set default header data
4873
		$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
4874
		$pdf->setFooterData(array(0,64,0), array(0,64,128));
226 liveuser 4875
 
3 liveuser 4876
		#set header and footer fonts
4877
		$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
4878
		$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
226 liveuser 4879
 
3 liveuser 4880
		#set default monospaced font
4881
		$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
226 liveuser 4882
 
3 liveuser 4883
		#set margins
4884
		$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
4885
		$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
4886
		$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
4887
 
4888
		#set auto page breaks
4889
		$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
4890
 
4891
		#set image scale factor
4892
		$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
4893
 
4894
		#set some language-dependent strings (optional)
4895
		if (@file_exists(dirname(__FILE__).'/lang/eng.php')){
226 liveuser 4896
 
3 liveuser 4897
			require_once(dirname(__FILE__).'/lang/eng.php');
226 liveuser 4898
 
3 liveuser 4899
			$pdf->setLanguageArray($l);
226 liveuser 4900
 
3 liveuser 4901
			}#if end
226 liveuser 4902
 
3 liveuser 4903
		#set default font subsetting mode
4904
		$pdf->setFontSubsetting(true);
226 liveuser 4905
 
3 liveuser 4906
		#Set font
4907
		#dejavusans is a UTF-8 Unicode font, if you only need to
4908
		#print standard ASCII chars, you can use core fonts like
4909
		#helvetica or times to reduce file size.
4910
		$pdf->SetFont('dejavusans', '', 14, '', true);
226 liveuser 4911
 
3 liveuser 4912
		#Add a page
4913
		#This method has several options, check the source code documentation for more information.
4914
		$pdf->AddPage();
226 liveuser 4915
 
3 liveuser 4916
		#set text shadow effect
4917
		$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 4918
 
3 liveuser 4919
		#Set some content to print
4920
		$html="<h5>Hello World!</h5>";
226 liveuser 4921
 
3 liveuser 4922
		// Print text using writeHTMLCell()
4923
		$pdf->writeHTMLCell(0,0,'','',$html,0,1,0,true,'',true);
4924
 
4925
		// Close and output PDF document
4926
		// This method has several options, check the source code documentation for more information.
4927
		$pdf->Output('fileAccessT/example_001.pdf','I');
226 liveuser 4928
 
3 liveuser 4929
		}#function demoCreateTcPdfFile end
226 liveuser 4930
 
3 liveuser 4931
	/*
4932
	#函式說明:
4933
	#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
4934
	#回傳的結果:
4935
	#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
4936
	#$result["error"],錯誤訊息.
4937
	#$result["function"],當前執行的函式名稱.
4938
	#$result["filePath"],路徑字串.
4939
	#$result["fileName"],檔案名稱字串.
4940
	#$result["fileExtention"],檔案的副檔名.
4941
	#$result["fullFileName"],含副檔名的檔案名稱.
4942
	#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
4943
	#必填參數:
4944
	#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
4945
	$conf["fileAddressAndName"]="";
4946
	#可省略參數:
4947
	#無.
4948
	#參考資料:
4949
	#無.
4950
	#備註:
4951
	#無.
4952
	*/
4953
	public static function getFileAddressAndNameAndFileExtention(&$conf){
226 liveuser 4954
 
3 liveuser 4955
		#初始化要回傳的參數
4956
		$result=array();
226 liveuser 4957
 
3 liveuser 4958
		#取得當前執行函數名稱
4959
		$result["function"]=__FUNCTION__;
4960
 
4961
		#如果 $conf 不為陣列
4962
		if(gettype($conf)!="array"){
226 liveuser 4963
 
3 liveuser 4964
			#設置執行失敗
4965
			$result["status"]="false";
226 liveuser 4966
 
3 liveuser 4967
			#設置執行錯誤訊息
4968
			$result["error"][]="\$conf變數須為陣列形態";
4969
 
4970
			#如果傳入的參數為 null
4971
			if($conf==null){
226 liveuser 4972
 
3 liveuser 4973
				#設置執行錯誤訊息
4974
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4975
 
3 liveuser 4976
				}#if end
4977
 
4978
			#回傳結果
4979
			return $result;
226 liveuser 4980
 
3 liveuser 4981
			}#if end
4982
 
4983
		#檢查參數
4984
		#函式說明:
4985
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4986
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4987
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4988
		#$result["function"],當前執行的函式名稱.
4989
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4990
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4991
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4992
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4993
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4994
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4995
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4996
		#必填寫的參數:
4997
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4998
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4999
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5000
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileAddressAndName");
226 liveuser 5001
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5002
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5003
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5004
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5005
		#可以省略的參數:
5006
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5007
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5008
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5009
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("outputAddress","noDownload");
226 liveuser 5010
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5011
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
5012
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5013
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".bin/".$conf["cppAddress"].".bin","true");
5014
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5015
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
5016
		#參考資料來源:
5017
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5018
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5019
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5020
 
3 liveuser 5021
		#如果 $checkArguments["status"] 等於 "false"
5022
		if($checkArguments["status"]=="false"){
226 liveuser 5023
 
3 liveuser 5024
			#設置 $result["status"] 為 "false"
5025
			$result["status"]="false";
226 liveuser 5026
 
3 liveuser 5027
			#設置 $result["error"]
5028
			$result["error"]=$checkArguments;
226 liveuser 5029
 
3 liveuser 5030
			#回傳結果
5031
			return $result;
226 liveuser 5032
 
3 liveuser 5033
			}#if end
226 liveuser 5034
 
3 liveuser 5035
		#如果 $checkArguments["passed"] 等於 "false"
5036
		if($checkArguments["passed"]=="false"){
226 liveuser 5037
 
3 liveuser 5038
			#設置 $result["status"] 為 "false"
5039
			$result["status"]="false";
226 liveuser 5040
 
3 liveuser 5041
			#設置 $result["error"]
5042
			$result["error"]=$checkArguments;
226 liveuser 5043
 
3 liveuser 5044
			#回傳結果
5045
			return $result;
226 liveuser 5046
 
3 liveuser 5047
			}#if end
226 liveuser 5048
 
3 liveuser 5049
		#確認路徑是否為絕對路徑
5050
		#函式說明:
5051
		#取得符合特定字首與字尾的字串
5052
		#回傳結果:
5053
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
5054
		#$result["function"],當前執行的函數名稱.
5055
		#$result["error"],錯誤訊息陣列.
5056
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
5057
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
5058
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
5059
		#$result["argu"],使用的參數.
5060
		#必填參數:
5061
		#$conf["checkString"],字串,要檢查的字串.
5062
		$conf["fileAccess::getMeetConditionsString"]["checkString"]=$conf["fileAddressAndName"];
5063
		#可省略參數:
5064
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
5065
		$conf["fileAccess::getMeetConditionsString"]["frontWord"]="/";
5066
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
5067
		#$conf["tailWord"]="";
5068
		#參考資料:
5069
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
5070
		#備註:
5071
		#無.
5072
		$getMeetConditionsString=search::getMeetConditionsString($conf["fileAccess::getMeetConditionsString"]);
5073
		unset($conf["fileAccess::getMeetConditionsString"]);
226 liveuser 5074
 
3 liveuser 5075
		#如果執行出錯
5076
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 5077
 
3 liveuser 5078
			#設置錯誤識別
5079
			$result["status"]="false";
226 liveuser 5080
 
3 liveuser 5081
			#設置錯誤訊息
5082
			$result["error"]=$getMeetConditionsString;
226 liveuser 5083
 
3 liveuser 5084
			#回傳結果
5085
			return $result;
226 liveuser 5086
 
3 liveuser 5087
			}#if end
226 liveuser 5088
 
3 liveuser 5089
		#預設參數 $conf["fileAddressAndName"] 不為 "/" 開始
5090
		$fileAddressAndNameStarFromRoot="true";
226 liveuser 5091
 
3 liveuser 5092
		#如果是 "/" 開頭
5093
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 5094
 
3 liveuser 5095
			#設置參數 $conf["fileAddressAndName"] 為 "/" 開始
5096
			$fileAddressAndNameStarFromRoot="true";
226 liveuser 5097
 
3 liveuser 5098
			}#if end
226 liveuser 5099
 
5100
		#檢查是否有路徑資訊
3 liveuser 5101
		#函式說明:
5102
		#將固定格式的字串分開,並回傳分開的結果。
5103
		#回傳的參數:
5104
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5105
		#$result["error"],錯誤訊息陣列
5106
		#$result["oriStr"],要分割的原始字串內容
5107
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5108
		#$result["dataCounts"],爲總共分成幾段
5109
		#必填參數:
5110
		$conf["stringProcess"]["spiltString"]["stringIn"]=$conf["fileAddressAndName"];#要處理的字串。
5111
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
5112
		$spiledResult=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5113
		unset($conf["stringProcess"]["spiltString"]);
226 liveuser 5114
 
3 liveuser 5115
		#如果 $spiledResult["status"] 等於 "false"
5116
		if($spiledResult["status"]==="false"){
226 liveuser 5117
 
3 liveuser 5118
			#設置錯誤識別
5119
			$result["status"]="false";
226 liveuser 5120
 
3 liveuser 5121
			#設置錯誤訊息
5122
			$result["error"]=$spiledResult;
226 liveuser 5123
 
3 liveuser 5124
			#回傳結果
5125
			return $result;
226 liveuser 5126
 
3 liveuser 5127
			}#if end
226 liveuser 5128
 
3 liveuser 5129
		#如果 $spiledResult["dataCounts"] 大於 1
5130
		if($spiledResult["dataCounts"]>1){
226 liveuser 5131
 
3 liveuser 5132
			#代表有路徑字串
226 liveuser 5133
 
3 liveuser 5134
			#初始化路徑字串暫存變數
5135
			$tempPathStr="";
226 liveuser 5136
 
3 liveuser 5137
			#如果是絕對路徑
5138
			if($fileAddressAndNameStarFromRoot==="true"){
226 liveuser 5139
 
3 liveuser 5140
				#加上根目錄
5141
				$tempPathStr=$tempPathStr."/";
226 liveuser 5142
 
3 liveuser 5143
				}#if end
226 liveuser 5144
 
3 liveuser 5145
			#取得路徑字串
5146
			for($i=0;$i<$spiledResult["dataCounts"]-1;$i++){
226 liveuser 5147
 
3 liveuser 5148
				#串連片段路徑字串
5149
				$tempPathStr=$tempPathStr.$spiledResult["dataArray"][$i]."/";
226 liveuser 5150
 
3 liveuser 5151
				}#for end
226 liveuser 5152
 
3 liveuser 5153
			#取得檔案的路徑
5154
			$result["filePath"]=$tempPathStr;
226 liveuser 5155
 
3 liveuser 5156
			}#if end
226 liveuser 5157
 
3 liveuser 5158
		#反之 $spiledResult["dataCounts"] 等於 1
5159
		else{
226 liveuser 5160
 
3 liveuser 5161
			#檔案的路徑設為""
5162
			$result["filePath"]="";
226 liveuser 5163
 
3 liveuser 5164
			}#else end
226 liveuser 5165
 
3 liveuser 5166
		#取得檔案名稱(含副檔名)
5167
		$result["fullFileName"]=$spiledResult["dataArray"][$spiledResult["dataCounts"]-1];
226 liveuser 5168
 
3 liveuser 5169
		#取得副檔名
5170
		#函式說明:
5171
		#將固定格式的字串分開,並回傳分開的結果。
5172
		#回傳的參數:
5173
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5174
		#$result["error"],錯誤訊息陣列
5175
		#$result["oriStr"],要分割的原始字串內容
5176
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5177
		#$result["dataCounts"],爲總共分成幾段
5178
		#必填參數:
5179
		$conf["stringProcess"]["spiltString"]["stringIn"]=$result["fullFileName"];#要處理的字串。
5180
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
5181
		$spiledResult=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5182
		unset($conf["stringProcess"]["spiltString"]);
226 liveuser 5183
 
3 liveuser 5184
		#如果 $spiledResult["status"] 等於 "false"
5185
		if($spiledResult["status"]=="false"){
226 liveuser 5186
 
3 liveuser 5187
			#設置錯誤識別
5188
			$result["status"]="false";
226 liveuser 5189
 
3 liveuser 5190
			#設置錯誤訊息
5191
			$result["error"]=$spiledResult;
226 liveuser 5192
 
3 liveuser 5193
			#回傳結果
5194
			return $result;
226 liveuser 5195
 
3 liveuser 5196
			}#if end
226 liveuser 5197
 
3 liveuser 5198
		#如果 $spiledResult["dataCounts"] 大於 1
5199
		if($spiledResult["dataCounts"]>1){
226 liveuser 5200
 
3 liveuser 5201
			#代表有副檔名
226 liveuser 5202
 
3 liveuser 5203
			#初始化檔名字串暫存變數
5204
			$tempFileNameStr="";
226 liveuser 5205
 
3 liveuser 5206
			#取得路徑字串
5207
			for($i=0;$i<$spiledResult["dataCounts"]-1;$i++){
226 liveuser 5208
 
3 liveuser 5209
				#如果是最後一個小黑點前面的字串片段
5210
				if($i==$spiledResult["dataCounts"]-2){
226 liveuser 5211
 
3 liveuser 5212
					#串連片段路徑字串
5213
					$tempFileNameStr=$tempFileNameStr.$spiledResult["dataArray"][$i];
226 liveuser 5214
 
3 liveuser 5215
					}#if end
226 liveuser 5216
 
3 liveuser 5217
				#反之不是最後一個小黑點前面的字串片段
5218
				else{
226 liveuser 5219
 
3 liveuser 5220
					#串連片段路徑字串(含小黑點)
5221
					$tempFileNameStr=$tempFileNameStr.$spiledResult["dataArray"][$i].".";
226 liveuser 5222
 
3 liveuser 5223
					}#else end
226 liveuser 5224
 
3 liveuser 5225
				}#for end
226 liveuser 5226
 
3 liveuser 5227
			#取得檔名
5228
			$result["fileName"]=$tempFileNameStr;
226 liveuser 5229
 
3 liveuser 5230
			#取得副檔名
5231
			$result["fileExtention"]=$spiledResult["dataArray"][$spiledResult["dataCounts"]-1];
226 liveuser 5232
 
3 liveuser 5233
			}#if end
226 liveuser 5234
 
3 liveuser 5235
		#反之 $spiledResult["dataCounts"] 等於 1
5236
		else{
226 liveuser 5237
 
3 liveuser 5238
			#檔案的副檔名設為""
5239
			$result["fileExtention"]="";
226 liveuser 5240
 
3 liveuser 5241
			#取得檔案的名稱
5242
			$result["fileName"]=$spiledResult["dataArray"][0];
226 liveuser 5243
 
3 liveuser 5244
			}#else end
226 liveuser 5245
 
3 liveuser 5246
		#如果 $result["fileExtention"] 不等於 ""
5247
		if($result["fileExtention"]!=""){
226 liveuser 5248
 
3 liveuser 5249
			#將副檔名用小黑點跟檔案名稱連在一塊
5250
			$result["fullFileName"]=$result["fileName"].".".$result["fileExtention"];
226 liveuser 5251
 
3 liveuser 5252
			}#if end
226 liveuser 5253
 
3 liveuser 5254
		#反之代表沒有副檔名
5255
		else{
226 liveuser 5256
 
3 liveuser 5257
			#取得含副檔名的檔案名稱
5258
			$result["fullFileName"]=$result["fileName"].$result["fileExtention"];
226 liveuser 5259
 
3 liveuser 5260
			}#else end
226 liveuser 5261
 
3 liveuser 5262
		#完整的檔案路徑(含副檔名).
5263
		$result["fullFilePathAndName"]=$result["filePath"].$result["fullFileName"];
226 liveuser 5264
 
3 liveuser 5265
		#設置執行正常的識別
5266
		$result["status"]="true";
226 liveuser 5267
 
3 liveuser 5268
		#回傳結果
5269
		return $result;
226 liveuser 5270
 
3 liveuser 5271
		}#funciton getFileAddressAndNameAndFileExtention end
5272
 
5273
	/*
5274
	#函式說明:
5275
	#將資料夾或檔案打包成tar檔案
5276
	#回傳結果:
5277
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5278
	#$result["function"],當前執行的函數名稱
5279
	#$result["error"],錯誤訊息.
5280
	#$result["content"],檔案輸出後的位置與名稱.
5281
	#必填參數:
5282
	#$conf["packetTarget"],陣列,要打包的每個資料夾與檔案位置
5283
	$conf["packetTarget"]=array("");
5284
	#$conf["createdTarFile"],字串,打包好的檔案要放在哪裡,副檔名.tar會自動加上.
5285
	$conf["createdTarFile"]="";
5286
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5287
	$conf["fileArgu"]=__FILE__;
5288
	#可省略參數:
5289
	#無.
5290
	#參考資料:
5291
	#無.
5292
	#備註:
5293
	#無.
5294
	*/
5295
	public static function makeTarFile(&$conf){
226 liveuser 5296
 
3 liveuser 5297
		#初始化要回傳的內容
5298
		$result=array();
226 liveuser 5299
 
3 liveuser 5300
		#記錄當前執行的函數名稱
5301
		$result["function"]=__FUNCTION__;
226 liveuser 5302
 
3 liveuser 5303
		#如果 $conf 不為陣列
5304
		if(gettype($conf)!="array"){
226 liveuser 5305
 
3 liveuser 5306
			#設置執行失敗
5307
			$result["status"]="false";
226 liveuser 5308
 
3 liveuser 5309
			#設置執行錯誤訊息
5310
			$result["error"][]="\$conf變數須為陣列形態";
5311
 
5312
			#如果傳入的參數為 null
5313
			if($conf==null){
226 liveuser 5314
 
3 liveuser 5315
				#設置執行錯誤訊息
5316
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5317
 
3 liveuser 5318
				}#if end
5319
 
5320
			#回傳結果
5321
			return $result;
226 liveuser 5322
 
3 liveuser 5323
			}#if end
226 liveuser 5324
 
3 liveuser 5325
		#檢查參數
5326
		#函式說明:
5327
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5328
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5329
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5330
		#$result["function"],當前執行的函式名稱.
5331
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5332
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5333
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5334
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5335
		#必填寫的參數:
5336
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5337
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5338
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5339
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","packetTarget","createdTarFile");
226 liveuser 5340
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5341
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
5342
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5343
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5344
		#可以省略的參數:
5345
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5346
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5347
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5348
		#$conf["skipableVariableName"]=array();
226 liveuser 5349
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5350
		#$conf["skipableVariableType"]=array();
5351
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5352
		#$conf["skipableVarDefaultValue"]=array("");
5353
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5354
		#$conf["arrayCountEqualCheck"][]=array();
5355
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5356
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5357
 
3 liveuser 5358
		#若檢查失敗
5359
		if($checkResult["status"]=="false"){
226 liveuser 5360
 
3 liveuser 5361
			#設置執行失敗
5362
			$result["status"]="false";
226 liveuser 5363
 
3 liveuser 5364
			#設置執行錯誤訊息
5365
			$result["error"]=$checkResult;
226 liveuser 5366
 
3 liveuser 5367
			#回傳結果
5368
			return $result;
226 liveuser 5369
 
3 liveuser 5370
			}#if end
226 liveuser 5371
 
3 liveuser 5372
		#若檢查不通過
5373
		if($checkResult["passed"]=="false"){
226 liveuser 5374
 
3 liveuser 5375
			#設置執行失敗
5376
			$result["status"]="false";
226 liveuser 5377
 
3 liveuser 5378
			#設置執行錯誤訊息
5379
			$result["error"]=$checkResult;
226 liveuser 5380
 
3 liveuser 5381
			#回傳結果
5382
			return $result;
226 liveuser 5383
 
3 liveuser 5384
			}#if end
226 liveuser 5385
 
3 liveuser 5386
		#初始化打包要用的tar指令參數
5387
		$paramsArray=array("-cvf",$conf["createdTarFile"].".tar");
226 liveuser 5388
 
3 liveuser 5389
		#檢查要打包的檔案是否存在
5390
		#函式說明:
5391
		#檢查多個檔案與資料夾是否存在.
5392
		#回傳的結果:
5393
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5394
		#$result["error"],錯誤訊息陣列.
5395
		#$resutl["function"],當前執行的涵式名稱.
5396
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
5397
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
5398
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
5399
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
5400
		#必填參數:
5401
		#$conf["fileArray"],陣列字串,要檢查書否存在的檔案有哪些,須爲一維陣列數值。
5402
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$conf["packetTarget"];
5403
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5404
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
5405
		#可省略參數
5406
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
5407
		#$conf["disableWebSearch"]="false";
5408
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5409
		#$conf["userDir"]="true";
5410
		#參考資料來源:
5411
		#http://php.net/manual/en/function.file-exists.php
5412
		#http://php.net/manual/en/control-structures.foreach.php
5413
		#備註:
5414
		#函數file_exists檢查的路徑為檔案系統的路徑
5415
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
5416
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 5417
 
3 liveuser 5418
		#如果檢查要打包的檔案失敗
5419
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 5420
 
3 liveuser 5421
			#設置執行失敗
5422
			$result["status"]="false";
226 liveuser 5423
 
3 liveuser 5424
			#設置執行錯誤訊息
5425
			$result["error"]=$checkMultiFileExist;
226 liveuser 5426
 
3 liveuser 5427
			#回傳結果
5428
			return $result;
226 liveuser 5429
 
3 liveuser 5430
			}#if end
226 liveuser 5431
 
3 liveuser 5432
		#如果要打包的檔案有缺
5433
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 5434
 
3 liveuser 5435
			#設置執行失敗
5436
			$result["status"]="false";
226 liveuser 5437
 
3 liveuser 5438
			#設置執行錯誤訊息
5439
			$result["error"]=$checkMultiFileExist;
226 liveuser 5440
 
3 liveuser 5441
			#回傳結果
5442
			return $result;
226 liveuser 5443
 
3 liveuser 5444
			}#if end
226 liveuser 5445
 
3 liveuser 5446
		#有幾個要打包的目標就執行幾次
5447
		for($i=0;$i<count($conf["packetTarget"]);$i++){
226 liveuser 5448
 
3 liveuser 5449
			#串接上要打包的檔案或資料夾
5450
			$paramsArray[]=$conf["packetTarget"][$i];
226 liveuser 5451
 
3 liveuser 5452
			}#for end
226 liveuser 5453
 
3 liveuser 5454
		#函式說明:
5455
		#呼叫shell執行系統命令,並取得回傳的內容.
5456
		#回傳結果:
5457
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5458
		#$result["error"],錯誤訊息陣列.
5459
		#$result["function"],當前執行的函數名稱.
5460
		#$result["argu"],使用的參數.
5461
		#$result["cmd"],執行的指令內容.
5462
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
5463
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
5464
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
5465
		#$result["running"],是否還在執行.
5466
		#$result["pid"],pid.
5467
		#$result["statusCode"],執行結束後的代碼.
5468
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
5469
		#必填參數:
5470
		#$conf["command"],字串,要執行的指令.
5471
		$conf["external::callShell"]["command"]="tar";
5472
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5473
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5474
		#可省略參數:
5475
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5476
		$conf["external::callShell"]["argu"]=$paramsArray;
5477
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
5478
		#$conf["arguIsAddr"]=array();
5479
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
5480
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
5481
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
5482
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5483
		#$conf["enablePrintDescription"]="true";
5484
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
5485
		#$conf["printDescription"]="";
5486
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
5487
		$conf["external::callShell"]["escapeshellarg"]="true";
5488
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
5489
		#$conf["thereIsShellVar"]=array();
5490
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
5491
		#$conf["username"]="";
5492
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
5493
		#$conf["password"]="";
5494
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
5495
		#$conf["useScript"]="";
5496
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
5497
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
5498
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
5499
		#$conf["inBackGround"]="";
5500
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
5501
		#$conf["getErr"]="false";
5502
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
5503
		#$conf["doNotRun"]="false";
5504
		#參考資料:
5505
		#exec=>http://php.net/manual/en/function.exec.php
5506
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
5507
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
5508
		#備註:
5509
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
5510
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
5511
		$conf["external::callShell"]=external::callShell($conf["external::callShell"]);
5512
		unset($conf["external::callShell"]);
226 liveuser 5513
 
3 liveuser 5514
		#如果執行shell失敗
5515
		if($callShell["status"]=="false"){
226 liveuser 5516
 
3 liveuser 5517
			#設置執行失敗
5518
			$result["status"]="false";
226 liveuser 5519
 
3 liveuser 5520
			#設置執行錯誤訊息
5521
			$result["error"]=$callShell;
226 liveuser 5522
 
3 liveuser 5523
			#回傳結果
5524
			return $result;
226 liveuser 5525
 
3 liveuser 5526
			}#if end
226 liveuser 5527
 
3 liveuser 5528
		#打包好的檔案位置與名稱
5529
		$result["content"]=$conf["createdTarFile"].".tar";
226 liveuser 5530
 
3 liveuser 5531
		#執行到這邊代表執行正常
5532
		$result["status"]="true";
226 liveuser 5533
 
3 liveuser 5534
		#回傳結果
5535
		return $result;
226 liveuser 5536
 
3 liveuser 5537
		}#function makeTarFile end
226 liveuser 5538
 
3 liveuser 5539
	/*
5540
	#函式說明:
5541
	#將一個檔案壓縮成xz檔案
5542
	#回傳結果:
5543
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5544
	#$result["function"],當前執行的函數名稱
5545
	#$result["error"],錯誤訊息.
5546
	#$result["content"],檔案輸出後的位置與名稱.
5547
	#必填參數:
5548
	#$conf["compressTarget"],字串,要打包的每個資料夾與檔案位置
5549
	$conf["compressTarget"]="";
5550
	#$conf["createdXzFile"],字串,打包好的檔案要放在哪裡,副檔名.xz會自動加上.
5551
	$conf["createdXzFile"]="";
5552
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5553
	$conf["fileArgu"]=__FILE__;
5554
	#可省略參數:
5555
	#無.
5556
	#參考資料:
5557
	#無.
5558
	#備註:
5559
	#無.
5560
	*/
5561
	public static function makeXzFile(&$conf){
5562
 
5563
		#初始化要回傳的內容
5564
		$result=array();
226 liveuser 5565
 
3 liveuser 5566
		#記錄當前執行的函數名稱
5567
		$result["function"]=__FUNCTION__;
226 liveuser 5568
 
3 liveuser 5569
		#如果 $conf 不為陣列
5570
		if(gettype($conf)!="array"){
226 liveuser 5571
 
3 liveuser 5572
			#設置執行失敗
5573
			$result["status"]="false";
226 liveuser 5574
 
3 liveuser 5575
			#設置執行錯誤訊息
5576
			$result["error"][]="\$conf變數須為陣列形態";
5577
 
5578
			#如果傳入的參數為 null
5579
			if($conf==null){
226 liveuser 5580
 
3 liveuser 5581
				#設置執行錯誤訊息
5582
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5583
 
3 liveuser 5584
				}#if end
5585
 
5586
			#回傳結果
5587
			return $result;
226 liveuser 5588
 
3 liveuser 5589
			}#if end
226 liveuser 5590
 
3 liveuser 5591
		#檢查參數
5592
		#函式說明:
5593
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5594
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5595
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5596
		#$result["function"],當前執行的函式名稱.
5597
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5598
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5599
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5600
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5601
		#必填寫的參數:
5602
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5603
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5604
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5605
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","compressTarget","createdXzFile");
226 liveuser 5606
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5607
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
5608
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5609
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5610
		#可以省略的參數:
5611
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5612
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5613
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5614
		#$conf["skipableVariableName"]=array();
226 liveuser 5615
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5616
		#$conf["skipableVariableType"]=array();
5617
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5618
		#$conf["skipableVarDefaultValue"]=array("");
5619
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5620
		#$conf["arrayCountEqualCheck"][]=array();
5621
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5622
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5623
 
3 liveuser 5624
		#若檢查失敗
5625
		if($checkResult["status"]=="false"){
226 liveuser 5626
 
3 liveuser 5627
			#設置執行失敗
5628
			$result["status"]="false";
226 liveuser 5629
 
3 liveuser 5630
			#設置執行錯誤訊息
5631
			$result["error"]=$checkResult;
226 liveuser 5632
 
3 liveuser 5633
			#回傳結果
5634
			return $result;
226 liveuser 5635
 
3 liveuser 5636
			}#if end
226 liveuser 5637
 
3 liveuser 5638
		#若檢查不通過
5639
		if($checkResult["passed"]=="false"){
226 liveuser 5640
 
3 liveuser 5641
			#設置執行失敗
5642
			$result["status"]="false";
226 liveuser 5643
 
3 liveuser 5644
			#設置執行錯誤訊息
5645
			$result["error"]=$checkResult;
226 liveuser 5646
 
3 liveuser 5647
			#回傳結果
5648
			return $result;
226 liveuser 5649
 
3 liveuser 5650
			}#if end
226 liveuser 5651
 
3 liveuser 5652
		#檢查要用xz壓縮的檔案是否存在
5653
		#函式說明:
5654
		#檢查多個檔案與資料夾是否存在.
5655
		#回傳的結果:
5656
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5657
		#$result["error"],錯誤訊息陣列.
5658
		#$resutl["function"],當前執行的涵式名稱.
5659
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
5660
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
5661
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
5662
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
5663
		#必填參數:
5664
		#$conf["fileArray"],陣列字串,要檢查書否存在的檔案有哪些,須爲一維陣列數值。
5665
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["compressTarget"]);
5666
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5667
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
5668
		#可省略參數
5669
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
5670
		#$conf["disableWebSearch"]="false";
5671
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5672
		#$conf["userDir"]="true";
5673
		#參考資料來源:
5674
		#http://php.net/manual/en/function.file-exists.php
5675
		#http://php.net/manual/en/control-structures.foreach.php
5676
		#備註:
5677
		#函數file_exists檢查的路徑為檔案系統的路徑
5678
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
5679
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 5680
 
3 liveuser 5681
		#如果檢查要用xz壓縮的檔案失敗
5682
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 5683
 
3 liveuser 5684
			#設置執行失敗
5685
			$result["status"]="false";
226 liveuser 5686
 
3 liveuser 5687
			#設置執行錯誤訊息
5688
			$result["error"]=$checkMultiFileExist;
226 liveuser 5689
 
3 liveuser 5690
			#回傳結果
5691
			return $result;
226 liveuser 5692
 
3 liveuser 5693
			}#if end
226 liveuser 5694
 
3 liveuser 5695
		#如果要用xz壓縮的檔案有缺
5696
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 5697
 
3 liveuser 5698
			#設置執行失敗
5699
			$result["status"]="false";
226 liveuser 5700
 
3 liveuser 5701
			#設置執行錯誤訊息
5702
			$result["error"]=$checkMultiFileExist;
226 liveuser 5703
 
3 liveuser 5704
			#回傳結果
5705
			return $result;
226 liveuser 5706
 
3 liveuser 5707
			}#if end
226 liveuser 5708
 
3 liveuser 5709
		#壓縮要用的xz語法
5710
		#函式說明:
5711
		#呼叫shell執行系統命令,並取得回傳的內容.
5712
		#回傳的結果:
5713
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5714
		#$result["error"],錯誤訊息陣列
5715
		#$result["output"],爲執行完二元碼後的輸出陣列
5716
		#必填的參數
5717
		$conf["external::callShell"]["command"]="xz";#要執行的指令與參數
5718
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5719
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5720
		#可省略參數:
5721
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5722
		$conf["external::callShell"]["argu"]=array("-v","-v","-z","-c",$conf["compressTarget"],">",$conf["createdXzFile"].".xz ");
5723
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5724
		#$conf["enablePrintDescription"]="true";
5725
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
5726
		#$conf["printDescription"]="";
5727
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
5728
		$conf["external::callShell"]["escapeshellarg"]="true";
5729
		#參考資料:
5730
		#http://php.net/manual/en/function.exec.php
5731
		$callShell=external::callShell($conf["external::callShell"]);
5732
		unset($conf["external::callShell"]);
226 liveuser 5733
 
3 liveuser 5734
		#如果執行shell失敗
5735
		if($callShell["status"]=="false"){
226 liveuser 5736
 
3 liveuser 5737
			#設置執行失敗
5738
			$result["status"]="false";
226 liveuser 5739
 
3 liveuser 5740
			#設置執行錯誤訊息
5741
			$result["error"]=$callShell;
226 liveuser 5742
 
3 liveuser 5743
			#回傳結果
5744
			return $result;
226 liveuser 5745
 
3 liveuser 5746
			}#if end
226 liveuser 5747
 
3 liveuser 5748
		#壓縮好的檔案位置與名稱
5749
		$result["content"]=$conf["createdXzFile"].".xz";
226 liveuser 5750
 
3 liveuser 5751
		#執行到這邊代表執行正常
5752
		$result["status"]="status";
226 liveuser 5753
 
3 liveuser 5754
		#回傳結果
5755
		return $result;
5756
 
5757
		}#function makeXzFile end
226 liveuser 5758
 
3 liveuser 5759
	/*
5760
	#函式說明:
5761
	#將資料夾或檔案打包壓縮成tar.xz檔案
5762
	#回傳結果:
5763
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5764
	#$result["function"],當前執行的函數名稱
5765
	#$result["error"],錯誤訊息.
5766
	#$result["content"],檔案輸出後的位置與名稱.
5767
	#必填參數:
5768
	#$conf["compressTarget"],陣列,要打包壓縮的每個資料夾與檔案位置
5769
	$conf["compressTarget"]=array();
5770
	#$conf["createdTarXzFile"],字串,打包壓縮好的檔案要放在哪裡,副檔名.tar.xz會自動加上.
5771
	$conf["createdTarXzFile"]="";
5772
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5773
	$conf["fileArgu"]=__FILE__;
5774
	#可省略參數:
5775
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
5776
	#$conf["commentsArray"]=array("");
5777
	#$conf["includeDotStart"],字串,當參數$conf["commentsArray"]含有星號時是否要包含「.」開頭的檔案目錄,預設為"false",不包含,"true"為要包含.
5778
	#$conf["includeDotStart"]="false";
5779
	#$conf["includeWaveEnd"],字串,當參數$conf["commentsArray"]含有星號時是否要包含「~」結尾的檔案.預設為"false",不包含,"true"為要包含.
5780
	#$conf["includeWaveEnd"]="false";
5781
	#參考資料:
5782
	#無.
5783
	#備註:
226 liveuser 5784
	#建議加上 --exclude-backups, --exclude-caches-all
3 liveuser 5785
	*/
5786
	public static function makeTarXzFile(&$conf){
226 liveuser 5787
 
3 liveuser 5788
		#初始化要回傳的內容
5789
		$result=array();
226 liveuser 5790
 
3 liveuser 5791
		#記錄當前執行的函數名稱
5792
		$result["function"]=__FUNCTION__;
226 liveuser 5793
 
3 liveuser 5794
		#如果 $conf 不為陣列
5795
		if(gettype($conf)!="array"){
226 liveuser 5796
 
3 liveuser 5797
			#設置執行失敗
5798
			$result["status"]="false";
226 liveuser 5799
 
3 liveuser 5800
			#設置執行錯誤訊息
5801
			$result["error"][]="\$conf變數須為陣列形態";
5802
 
5803
			#如果傳入的參數為 null
5804
			if($conf==null){
226 liveuser 5805
 
3 liveuser 5806
				#設置執行錯誤訊息
5807
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5808
 
3 liveuser 5809
				}#if end
5810
 
5811
			#回傳結果
5812
			return $result;
226 liveuser 5813
 
3 liveuser 5814
			}#if end
226 liveuser 5815
 
3 liveuser 5816
		#檢查參數
5817
		#函式說明:
5818
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5819
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5820
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5821
		#$result["function"],當前執行的函式名稱.
5822
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5823
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5824
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5825
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5826
		#必填寫的參數:
5827
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5828
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5829
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5830
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","compressTarget","createdTarXzFile");
226 liveuser 5831
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5832
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
5833
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5834
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5835
		#可以省略的參數:
5836
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5837
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5838
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5839
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","includeDotStart","includeWaveEnd");
226 liveuser 5840
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5841
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");
5842
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5843
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false","false");
5844
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5845
		#$conf["arrayCountEqualCheck"][]=array();
5846
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5847
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5848
 
3 liveuser 5849
		#若檢查失敗
5850
		if($checkResult["status"]=="false"){
226 liveuser 5851
 
3 liveuser 5852
			#設置執行失敗
5853
			$result["status"]="false";
226 liveuser 5854
 
3 liveuser 5855
			#設置執行錯誤訊息
5856
			$result["error"]=$checkResult;
226 liveuser 5857
 
3 liveuser 5858
			#回傳結果
5859
			return $result;
226 liveuser 5860
 
3 liveuser 5861
			}#if end
226 liveuser 5862
 
3 liveuser 5863
		#若檢查不通過
5864
		if($checkResult["passed"]=="false"){
226 liveuser 5865
 
3 liveuser 5866
			#設置執行失敗
5867
			$result["status"]="false";
226 liveuser 5868
 
3 liveuser 5869
			#設置執行錯誤訊息
5870
			$result["error"]=$checkResult;
226 liveuser 5871
 
3 liveuser 5872
			#回傳結果
5873
			return $result;
226 liveuser 5874
 
3 liveuser 5875
			}#if end
226 liveuser 5876
 
3 liveuser 5877
		#如果 $conf["commentsArray"] 有設定
5878
		if(isset($conf["commentsArray"])){
226 liveuser 5879
 
3 liveuser 5880
			#印出提示文字
5881
			#函式說明:
5882
			#印出多行文字,結尾自動換行.
5883
			#回傳的結果:
5884
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
5885
			#$result["function"],當前執行的函數名稱.
5886
			#$result["error"],錯誤訊息陣列.
5887
			#必填參數:
5888
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
5889
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
5890
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
5891
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 5892
 
3 liveuser 5893
			#如果印出提示文字失敗
5894
			if($echoMultiLine["status"]=="false"){
226 liveuser 5895
 
3 liveuser 5896
				#設置執行失敗
5897
				$result["status"]="false";
226 liveuser 5898
 
3 liveuser 5899
				#設置執行錯誤訊息
5900
				$result["error"]=$echoMultiLine;
226 liveuser 5901
 
3 liveuser 5902
				#回傳結果
5903
				return $result;
226 liveuser 5904
 
3 liveuser 5905
				}#if end
226 liveuser 5906
 
5907
			}#if end
5908
 
3 liveuser 5909
		#解析要處理的檔案路徑
5910
		#函式說明:
5911
		#將含有「*」的多個檔案路徑名稱,變成多個符合條件的路徑檔案.
5912
		#回傳結果:
5913
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
5914
		#$result["error"],錯誤訊息陣列.
226 liveuser 5915
		#$result["function"],函數名稱.
3 liveuser 5916
		#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
5917
		#$result["pathCount"],整數,有幾個路徑.
5918
		#必填參數:
5919
		#$conf["path"],字串陣列,要解析含有「*」的檔案路徑字串.
5920
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["path"]=$conf["compressTarget"];
5921
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
5922
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["fileArgu"]=$conf["fileArgu"];
5923
		#可省略參數:
5924
		#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
5925
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["noDotStart"]=$conf["includeDotStart"]==="true"?"false":"true";
5926
		#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
5927
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["noWaveEnd"]=$conf["includeWaveEnd"]==="true"?"false":"true";
5928
		$realPathArray=fileAccess::resolveMultiPostionStringWhichContainStarSymbol($conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]);
5929
		unset($conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]);
226 liveuser 5930
 
3 liveuser 5931
		#如果解析路徑失敗
5932
		if($realPathArray["status"]=="false"){
226 liveuser 5933
 
3 liveuser 5934
			#設置執行失敗
5935
			$result["status"]="false";
226 liveuser 5936
 
3 liveuser 5937
			#設置執行錯誤訊息
5938
			$result["error"]=$realPathArray;
226 liveuser 5939
 
3 liveuser 5940
			#回傳結果
5941
			return $result;
226 liveuser 5942
 
3 liveuser 5943
			}#if end
226 liveuser 5944
 
3 liveuser 5945
		#取得解析好的檔案路徑陣列
226 liveuser 5946
		$conf["compressTarget"]=$realPathArray["content"];
5947
 
3 liveuser 5948
		#將路徑轉換成相對路徑
5949
		#函式說明:
5950
		#將多個路徑字串變成相對於當前路徑的相對路徑字串
5951
		#回傳結果:
5952
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
5953
		#$result["error"],錯誤訊息陣列.
226 liveuser 5954
		#$result["function"],函數名稱.
3 liveuser 5955
		#$result["content"],字串陣列,多個轉換好的相對路徑字串.
5956
		#必填參數:
5957
		#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
5958
		$conf["fileAccess::getRelativePath"]["path"]=$conf["compressTarget"];
5959
		#$conf["fileArgu"],字串,當前路徑.
5960
		$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
5961
		$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
5962
		unset($conf["fileAccess::getRelativePath"]);
226 liveuser 5963
 
3 liveuser 5964
		#如果轉換失敗
5965
		if($getRelativePath["status"]=="false"){
226 liveuser 5966
 
3 liveuser 5967
			#設置執行失敗
5968
			$result["status"]="false";
226 liveuser 5969
 
3 liveuser 5970
			#設置執行錯誤訊息
5971
			$result["error"]=$getRelativePat;
226 liveuser 5972
 
3 liveuser 5973
			#回傳結果
5974
			return $result;
226 liveuser 5975
 
5976
			}#if end
5977
 
3 liveuser 5978
		#打包成tar檔
5979
		#函式說明:
5980
		#將資料夾或檔案打包成tar檔案
5981
		#回傳的結果:
5982
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5983
		#$result["function"],當前執行的函數名稱
5984
		#$result["error"],錯誤訊息.
5985
		#$result["content"],檔案輸出後的位置與名稱.
5986
		#必填參數:
5987
		#$conf["fileAccess::makeTarFile"]["packetTarget"],陣列,要打包的每個資料夾與檔案位置
5988
		$conf["fileAccess::makeTarFile"]["packetTarget"]=$getRelativePath["content"];
5989
		#$conf["fileAccess::makeTarFile"]["createdTarFile"],字串,打包好的檔案要放在哪裡,副檔名.tar會自動加上.
5990
		$conf["fileAccess::makeTarFile"]["createdTarFile"]=$conf["createdTarXzFile"];
5991
		#$conf["fileAccess::makeTarFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5992
		$conf["fileAccess::makeTarFile"]["fileArgu"]=$conf["fileArgu"];
5993
		$makeTarFile=fileAccess::makeTarFile($conf["fileAccess::makeTarFile"]);
5994
		unset($conf["fileAccess::makeTarFile"]);
226 liveuser 5995
 
3 liveuser 5996
		#如果打包失敗
5997
		if($makeTarFile["status"]=="false"){
226 liveuser 5998
 
3 liveuser 5999
			#設置執行不正常
6000
			$result["status"]="false";
226 liveuser 6001
 
3 liveuser 6002
			#設置錯誤訊息
6003
			$result["error"]=$makeTarFile;
226 liveuser 6004
 
3 liveuser 6005
			#回傳結果
6006
			return $result;
226 liveuser 6007
 
3 liveuser 6008
			}#if end
226 liveuser 6009
 
3 liveuser 6010
		#壓縮成xz檔
6011
		#函式說明:
6012
		#將一個檔案壓縮成xz檔案
6013
		#回傳的結果:
6014
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6015
		#$result["function"],當前執行的函數名稱
6016
		#$result["error"],錯誤訊息.
6017
		#$result["content"],檔案輸出後的位置與名稱.
6018
		#必填參數:
6019
		#$conf["fileAccess::makeXzFile"]["compressTarget"],字串,要打包的每個資料夾與檔案位置
6020
		$conf["fileAccess::makeXzFile"]["compressTarget"]=$makeTarFile["content"];
6021
		#$conf["fileAccess::makeXzFile"]["createdXzFile"],字串,打包好的檔案要放在哪裡,副檔名.xz會自動加上.
6022
		$conf["fileAccess::makeXzFile"]["createdXzFile"]=$makeTarFile["content"];
6023
		#$conf["fileAccess::makeXzFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6024
		$conf["fileAccess::makeXzFile"]["fileArgu"]=$conf["fileArgu"];
6025
		$makeXzFile=fileAccess::makeXzFile($conf["fileAccess::makeXzFile"]);
6026
		unset($conf["fileAccess::makeXzFile"]);
226 liveuser 6027
 
3 liveuser 6028
		#如果壓縮失敗
6029
		if($makeXzFile["status"]=="false"){
226 liveuser 6030
 
3 liveuser 6031
			#設置執行不正常
6032
			$result["status"]="false";
226 liveuser 6033
 
3 liveuser 6034
			#設置錯誤訊息
6035
			$result["error"]=$makeXzFile;
226 liveuser 6036
 
3 liveuser 6037
			#回傳結果
6038
			return $result;
226 liveuser 6039
 
3 liveuser 6040
			}#if end
226 liveuser 6041
 
3 liveuser 6042
		#移除tar檔案
6043
		#函式說明:
6044
		#移除檔案
6045
		#回傳結果:
6046
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
6047
		#$result["error"],錯誤訊息陣列
6048
		#$result["warning"],警告訊息陣列
6049
		#$result["function"],當前執行的函數名稱
6050
		#必填參數:
6051
		$conf["fileAccess::delFile"]["fileAddress"]=$makeTarFile["content"];#要移除檔案的位置
6052
		#$conf["fileAccess::delFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
6053
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
6054
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
6055
		unset($conf["fileAccess::delFile"]);
226 liveuser 6056
 
3 liveuser 6057
		#如果移除tar檔案失敗
6058
		if($delFile["status"]=="false"){
226 liveuser 6059
 
3 liveuser 6060
			#設置執行不正常
6061
			$result["status"]="false";
226 liveuser 6062
 
3 liveuser 6063
			#設置錯誤訊息
6064
			$result["error"]=$delFile;
226 liveuser 6065
 
3 liveuser 6066
			#回傳結果
6067
			return $result;
226 liveuser 6068
 
3 liveuser 6069
			}#if end
226 liveuser 6070
 
3 liveuser 6071
		#取得壓縮好的檔案位置與名稱
6072
		$result["content"]=$makeXzFile["content"];
226 liveuser 6073
 
3 liveuser 6074
		#執行到這邊代表執行正常
6075
		$result["status"]="true";
226 liveuser 6076
 
3 liveuser 6077
		#回傳結果
6078
		return $result;
226 liveuser 6079
 
3 liveuser 6080
		}#function makeTarXzFile end
226 liveuser 6081
 
3 liveuser 6082
	/*
6083
	#函式說明:
6084
	#移動檔案
6085
	#回傳結果:
6086
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6087
	#$result["function"],當前執行的函數名稱
6088
	#$result["error"],錯誤訊息.
6089
	#$result["content"],檔案輸出後的位置與名稱.
6090
	#必填參數:
6091
	#$conf["from"],字串,要移動的檔案名稱與位置.
6092
	$conf["from"]="";
6093
	#$conf["to"],字串,要移動到的位置與名稱
6094
	$conf["to"]="";
6095
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6096
	$conf["fileArgu"]=__FILE__;
6097
	#可省略參數:
6098
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
6099
	#$conf["commentsArray"]=array("");
6100
	#參考資料:
6101
	#無.
6102
	#備註:
6103
	#無.
6104
	*/
6105
	public static function mv(&$conf){
226 liveuser 6106
 
3 liveuser 6107
		#初始化要回傳的結果
6108
		$result=array();
226 liveuser 6109
 
3 liveuser 6110
		#取得當前執行的函數名稱
6111
		$result["function"]=__FUNCTION__;
226 liveuser 6112
 
3 liveuser 6113
		#如果 $conf 不為陣列
6114
		if(gettype($conf)!="array"){
226 liveuser 6115
 
3 liveuser 6116
			#設置執行失敗
6117
			$result["status"]="false";
226 liveuser 6118
 
3 liveuser 6119
			#設置執行錯誤訊息
6120
			$result["error"][]="\$conf變數須為陣列形態";
6121
 
6122
			#如果傳入的參數為 null
6123
			if($conf==null){
226 liveuser 6124
 
3 liveuser 6125
				#設置執行錯誤訊息
6126
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6127
 
3 liveuser 6128
				}#if end
6129
 
6130
			#回傳結果
6131
			return $result;
226 liveuser 6132
 
3 liveuser 6133
			}#if end
226 liveuser 6134
 
3 liveuser 6135
		#檢查參數
6136
		#函式說明:
6137
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6138
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6139
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6140
		#$result["function"],當前執行的函式名稱.
6141
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6142
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6143
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6144
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6145
		#必填寫的參數:
6146
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6147
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6148
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6149
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("from","to","fileArgu");
226 liveuser 6150
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 6151
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
6152
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6153
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6154
		#可以省略的參數:
6155
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
6156
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6157
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6158
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray");
226 liveuser 6159
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 6160
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
6161
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6162
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
6163
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6164
		#$conf["arrayCountEqualCheck"][]=array();
6165
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6166
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 6167
 
3 liveuser 6168
		#若檢查失敗
6169
		if($checkResult["status"]=="false"){
226 liveuser 6170
 
3 liveuser 6171
			#設置執行失敗
6172
			$result["status"]="false";
226 liveuser 6173
 
3 liveuser 6174
			#設置執行錯誤訊息
6175
			$result["error"]=$checkResult;
226 liveuser 6176
 
3 liveuser 6177
			#回傳結果
6178
			return $result;
226 liveuser 6179
 
3 liveuser 6180
			}#if end
226 liveuser 6181
 
3 liveuser 6182
		#若檢查不通過
6183
		if($checkResult["passed"]=="false"){
226 liveuser 6184
 
3 liveuser 6185
			#設置執行失敗
6186
			$result["status"]="false";
226 liveuser 6187
 
3 liveuser 6188
			#設置執行錯誤訊息
6189
			$result["error"]=$checkResult;
226 liveuser 6190
 
3 liveuser 6191
			#回傳結果
6192
			return $result;
226 liveuser 6193
 
3 liveuser 6194
			}#if end
226 liveuser 6195
 
3 liveuser 6196
		#如果 $conf["commentsArray"] 有設定
6197
		if(isset($conf["commentsArray"])){
226 liveuser 6198
 
3 liveuser 6199
			#印出提示文字
6200
			#函式說明:
6201
			#印出多行文字,結尾自動換行.
6202
			#回傳的結果:
6203
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
6204
			#$result["function"],當前執行的函數名稱.
6205
			#$result["error"],錯誤訊息陣列.
6206
			#必填參數:
6207
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
6208
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
6209
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
6210
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 6211
 
3 liveuser 6212
			#如果印出提示文字失敗
6213
			if($echoMultiLine["status"]=="false"){
226 liveuser 6214
 
3 liveuser 6215
				#設置執行失敗
6216
				$result["status"]="false";
226 liveuser 6217
 
3 liveuser 6218
				#設置執行錯誤訊息
6219
				$result["error"]=$echoMultiLine;
226 liveuser 6220
 
3 liveuser 6221
				#回傳結果
6222
				return $result;
226 liveuser 6223
 
3 liveuser 6224
				}#if end
226 liveuser 6225
 
6226
			}#if end
6227
 
3 liveuser 6228
		#檢查要移動的檔案是否存在
6229
		#函式說明:
6230
		#檢查多個檔案與資料夾是否存在.
6231
		#回傳的結果:
6232
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
6233
		#$result["error"],錯誤訊息陣列.
6234
		#$resutl["function"],當前執行的涵式名稱.
6235
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
6236
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
6237
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
6238
		#必填參數:
6239
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["from"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
6240
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
6241
		#參考資料來源:
6242
		#http://php.net/manual/en/function.file-exists.php
6243
		#http://php.net/manual/en/control-structures.foreach.php
6244
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
6245
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 6246
 
3 liveuser 6247
		#如果檢查失敗
6248
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 6249
 
3 liveuser 6250
			#設置執行失敗
6251
			$result["status"]="false";
226 liveuser 6252
 
3 liveuser 6253
			#設置執行錯誤訊息
6254
			$result["error"]=$checkMultiFileExist;
226 liveuser 6255
 
3 liveuser 6256
			#回傳結果
6257
			return $result;
226 liveuser 6258
 
6259
			}#if end
6260
 
3 liveuser 6261
		#如果來源檔案不存在
6262
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 6263
 
3 liveuser 6264
			#設置執行失敗
6265
			$result["status"]="false";
226 liveuser 6266
 
3 liveuser 6267
			#設置執行錯誤訊息
6268
			$result["error"][]="檔案「".$conf["from"]."」不存在";
226 liveuser 6269
 
3 liveuser 6270
			#回傳結果
6271
			return $result;
226 liveuser 6272
 
3 liveuser 6273
			}#if end
226 liveuser 6274
 
3 liveuser 6275
		#函式說明:
6276
		#呼叫shell執行系統命令,並取得回傳的內容.
6277
		#回傳的結果:
6278
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6279
		#$result["error"],錯誤訊息陣列
6280
		#$result["output"],爲執行完二元碼後的輸出陣列
6281
		#必填的參數
6282
		$conf["external::callShell"]["command"]="mv";#要執行的指令與參數
6283
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"]; #__FILE__的內容
6284
		#可省略參數:
6285
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
6286
		$conf["external::callShell"]["argu"]=array("-v",$conf["from"],$conf["to"]);
6287
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
6288
		#$conf["external::callShell"]["enablePrintDescription"]="true";
6289
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
6290
		#$conf["printDescription"]="";
6291
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
6292
		$conf["external::callShell"]["escapeshellarg"]="true";
6293
		#參考資料:
6294
		#http://php.net/manual/en/function.exec.php
6295
		$callShell=external::callShell($conf["external::callShell"]);
6296
		unset($conf["external::callShell"]);
226 liveuser 6297
 
3 liveuser 6298
		#如果移動檔案失敗
6299
		if($callShell["status"]=="false"){
226 liveuser 6300
 
3 liveuser 6301
			#設置執行失敗
6302
			$result["status"]="false";
226 liveuser 6303
 
3 liveuser 6304
			#設置執行錯誤訊息
6305
			$result["error"]=$callShell;
226 liveuser 6306
 
3 liveuser 6307
			#回傳結果
6308
			return $result;
226 liveuser 6309
 
3 liveuser 6310
			}#if end
226 liveuser 6311
 
3 liveuser 6312
		#執行到這邊代表正常
6313
		$result["status"]="true";
226 liveuser 6314
 
3 liveuser 6315
		#儲存移動後的位置與名稱
6316
		$result["content"]=$conf["to"];
226 liveuser 6317
 
3 liveuser 6318
		#回傳結果
6319
		return $result;
226 liveuser 6320
 
3 liveuser 6321
		}#function mv end
226 liveuser 6322
 
3 liveuser 6323
	/*
6324
	#函式說明:
6325
	#取得目錄底下所有目錄與檔案的樹狀結構.
6326
	#回傳結果:
6327
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6328
	#$result["error"],錯誤訊息陣列.
6329
	#$result["function"],函數名稱.
6330
	#$result["position"],根目錄位置.
6331
	#$result["content"],陣列,檔案目錄的樹狀結構.
6332
	#$result["content"][$i]["name"],根目錄底下第$i+1個檔案或目錄的名稱
6333
	#$result["content"][$i]["folder"],根目錄底下第$i+1個名稱是目錄("true")還是檔案("false").
6334
	#$result["content"][$i]["position"],根目錄底下第$i+1個名稱或目錄的位置.
6335
	#$result["content"][$i]["ownerPerm"],根目錄底下第$i+1個使用者的權限.
6336
	#$result["content"][$i]["groupPerm"],根目錄底下第$i+1個群組使用者的權限.
6337
	#$result["content"][$i]["otherPerm"],根目錄底下第$i+1個其他使用者的權限.
6338
	#$result["content"][$i]["ownerName"],根目錄底下第$i+1個擁有者賬戶.
6339
	#$result["content"][$i]["groupName"],根目錄底下第$i+1個群組擁有者賬戶.
6340
	#$result["content"][$i]["next"][$j]["name"],第$i+1個為目錄的名稱的目錄底下第$j+1個檔案或目錄的名稱
6341
	#$result["content"][$i]["next"][$j]["folder"],第$i+1個為目錄的名稱的目錄底下第$j+1個名稱是目錄("true")還是檔案("false").
6342
	#$result["content"][$i]["next"][$j]["position"],第$i+1個為目錄的名稱的目錄底下第$j+1個名稱或目錄的位置.
6343
	#$result["content"][$i]["next"][$j]["ownerPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個使用者的權限.
6344
	#$result["content"][$i]["next"][$j]["groupPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個群組使用者的權限.
6345
	#$result["content"][$i]["next"][$j]["otherPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個其他使用者的權限.
6346
	#$result["content"][$i]["next"][$j]["ownerName"],第$i+1個為目錄的名稱的目錄底下第$j+1個擁有者賬戶.
6347
	#$result["content"][$i]["next"][$j]["groupName"],第$i+1個為目錄的名稱的目錄底下第$j+1個群組擁有者賬戶.
226 liveuser 6348
	#以此類推...
3 liveuser 6349
	#必填參數:
6350
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6351
	$conf["position"]="";
6352
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6353
	$conf["fileArgu"]=__FILE__;
6354
	#可省略參數:
6355
	#無.
6356
	#參考資料:
6357
	#無.
6358
	#備註:
6359
	#無.
6360
	*/
6361
	public static function getListTree(&$conf){
226 liveuser 6362
 
3 liveuser 6363
		#初始化要回傳的結果
6364
		$result=array();
226 liveuser 6365
 
3 liveuser 6366
		#設置當其函數名稱
6367
		$result["function"]=__FUNCTION__;
226 liveuser 6368
 
3 liveuser 6369
		#如果 $conf 不為陣列
6370
		if(gettype($conf)!="array"){
226 liveuser 6371
 
3 liveuser 6372
			#設置執行失敗
6373
			$result["status"]="false";
226 liveuser 6374
 
3 liveuser 6375
			#設置執行錯誤訊息
6376
			$result["error"][]="\$conf變數須為陣列形態";
6377
 
6378
			#如果傳入的參數為 null
6379
			if($conf==null){
226 liveuser 6380
 
3 liveuser 6381
				#設置執行錯誤訊息
6382
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6383
 
3 liveuser 6384
				}#if end
6385
 
6386
			#回傳結果
6387
			return $result;
226 liveuser 6388
 
3 liveuser 6389
			}#if end
226 liveuser 6390
 
3 liveuser 6391
		#檢查必填參數
6392
		#函式說明:
6393
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6394
		#回傳的結果:
6395
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6396
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6397
		#$result["function"],當前執行的函式名稱.
6398
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6399
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6400
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6401
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6402
		#必填寫的參數:
6403
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6404
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileArgu","position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6405
		#可以省略的參數:
226 liveuser 6406
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6407
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6408
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
6409
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 6410
 
3 liveuser 6411
		#如果檢查失敗
6412
		if($checkResult["status"]=="false"){
226 liveuser 6413
 
3 liveuser 6414
			#設置錯誤識別
6415
			$result["status"]="false";
226 liveuser 6416
 
3 liveuser 6417
			#設置錯誤訊息
6418
			$result["error"]=$checkResult;
226 liveuser 6419
 
3 liveuser 6420
			#回傳結果
6421
			return $result;
226 liveuser 6422
 
3 liveuser 6423
			}#if end
226 liveuser 6424
 
3 liveuser 6425
		#如果檢查不通過
6426
		if($checkResult["passed"]=="false"){
226 liveuser 6427
 
3 liveuser 6428
			#設置錯誤識別
6429
			$result["status"]="false";
226 liveuser 6430
 
3 liveuser 6431
			#設置錯誤訊息
6432
			$result["error"]=$checkResult;
226 liveuser 6433
 
3 liveuser 6434
			#回傳結果
6435
			return $result;
226 liveuser 6436
 
3 liveuser 6437
			}#if end
226 liveuser 6438
 
3 liveuser 6439
		#如果目錄不為 . 與 ..
6440
		if(basename($conf["position"])!="." && basename($conf["position"])!=".."){
226 liveuser 6441
 
3 liveuser 6442
			#檢查目錄是否存在
6443
			#函式說明:
6444
			#檢查多個檔案與資料夾是否存在.
6445
			#回傳的結果:
6446
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
6447
			#$result["error"],錯誤訊息陣列.
6448
			#$resutl["function"],當前執行的涵式名稱.
6449
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
6450
			#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
6451
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
6452
			#必填參數:
6453
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["position"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
6454
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6455
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
6456
			#參考資料來源:
6457
			#http://php.net/manual/en/function.file-exists.php
6458
			#http://php.net/manual/en/control-structures.foreach.php
6459
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
6460
			unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 6461
 
3 liveuser 6462
			#如果檢查目錄失敗
6463
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 6464
 
3 liveuser 6465
				#設置錯誤識別
6466
				$result["status"]="false";
226 liveuser 6467
 
3 liveuser 6468
				#設置錯誤訊息
6469
				$result["error"]=$checkMultiFileExist;
226 liveuser 6470
 
3 liveuser 6471
				#回傳結果
6472
				return $result;
226 liveuser 6473
 
6474
				}#if end
6475
 
3 liveuser 6476
			#如果目錄不存在
6477
			if($checkMultiFileExist["varExist"][0]=="false"){
226 liveuser 6478
 
3 liveuser 6479
				#設置錯誤識別
6480
				$result["status"]="false";
226 liveuser 6481
 
3 liveuser 6482
				#設置錯誤訊息
6483
				$result["error"]=$checkMultiFileExist;
226 liveuser 6484
 
3 liveuser 6485
				#回傳結果
6486
				return $result;
226 liveuser 6487
 
6488
				}#if end
6489
 
3 liveuser 6490
			}#if end
226 liveuser 6491
 
3 liveuser 6492
		#取得根目錄的樹狀結構
6493
		#函式說明:
6494
		#取得目錄底下所有目錄與檔案清單.
6495
		#回傳結果:
6496
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6497
		#$result["error"],錯誤訊息陣列.
6498
		#$result["function"],函數名稱.
6499
		#$result["content"],陣列,目錄底下的檔案與子目錄.
6500
		#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
6501
		#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
6502
		#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
6503
		#$result["position"],目前的位置.
6504
		#必填參數:
6505
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6506
		$conf["fileAccess::getList"]["position"]=$conf["position"];
6507
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6508
		$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
6509
		#可省略參數:
6510
		#無
6511
		#參考資料來源:
6512
		#opendir=>http://php.net/manual/en/function.opendir.php
6513
		#is_dir=>http://php.net/manual/en/function.is-dir.php
6514
		$rootList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 6515
		unset($conf["fileAccess::getList"]);
6516
 
3 liveuser 6517
		#如果取得根目錄底下的資料失敗
6518
		if($rootList["status"]=="false"){
226 liveuser 6519
 
3 liveuser 6520
			#設置錯誤識別
6521
			$result["status"]="false";
226 liveuser 6522
 
3 liveuser 6523
			#設置錯誤訊息
6524
			$result["error"]=$rootList;
226 liveuser 6525
 
3 liveuser 6526
			#回傳結果
6527
			return $result;
226 liveuser 6528
 
3 liveuser 6529
			}#if end
226 liveuser 6530
 
6531
		#取得當前目錄
6532
		$result["position"]=$rootList["position"];
6533
 
3 liveuser 6534
		#取得根目錄層級可以看到的檔案與目錄
6535
		$result["content"]=$rootList["content"];
226 liveuser 6536
 
3 liveuser 6537
		#如果當前目錄有檔案與子目錄
6538
		if(isset($result["content"])){
226 liveuser 6539
 
3 liveuser 6540
			#當前層級有幾個檔案目錄就執行幾次
6541
			for($i=0;$i<count($result["content"]);$i++){
226 liveuser 6542
 
3 liveuser 6543
				#如果該單位是目錄
6544
				if($result["content"][$i]["folder"]=="true"){
226 liveuser 6545
 
3 liveuser 6546
					#呼叫當前函數,取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊
6547
					#函式說明:
6548
					#取得目錄底下所有目錄與檔案的樹狀結構.
6549
					#回傳結果:
6550
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6551
					#$result["error"],錯誤訊息陣列.
6552
					#$result["function"],函數名稱.
6553
					#$result["content"],陣列,檔案目錄的樹狀結構.
6554
					#$result["total"],根目錄底下有多少目錄與檔案
6555
					#必填參數:
6556
					#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6557
					$conf["fileAccess::getListTree"]["position"]=$conf["position"]."/".$result["content"][$i]["name"];
6558
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6559
					$conf["fileAccess::getListTree"]["fileArgu"]=$conf["fileArgu"];
6560
					#可省略參數:
6561
					#無
6562
					$getListTree=fileAccess::getListTree($conf["fileAccess::getListTree"]);
6563
					unset($conf["fileAccess::getListTree"]);
226 liveuser 6564
 
3 liveuser 6565
					#如果取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊失敗
6566
					if($getListTree["status"]=="false"){
226 liveuser 6567
 
3 liveuser 6568
						#設置錯誤識別
6569
						$result["status"]="false";
226 liveuser 6570
 
3 liveuser 6571
						#設置錯誤訊息
6572
						$result["error"]=$getListTree;
226 liveuser 6573
 
3 liveuser 6574
						#回傳結果
6575
						return $result;
226 liveuser 6576
 
3 liveuser 6577
						}#if end
226 liveuser 6578
 
3 liveuser 6579
					#如果 $conf["position"]."/".$result["content"][$i]["name"] 目錄有檔案與子目錄
226 liveuser 6580
					if(isset($getListTree["content"])){
6581
 
3 liveuser 6582
						#取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊
6583
						$result["content"][$i]["next"]=$getListTree["content"];
226 liveuser 6584
 
3 liveuser 6585
						}#if end
226 liveuser 6586
 
6587
					#取得當前目錄
6588
					$result["content"][$i]["position"]=$rootList["position"];
6589
 
3 liveuser 6590
					}#if end
226 liveuser 6591
 
3 liveuser 6592
				}#for end
226 liveuser 6593
 
3 liveuser 6594
			}#if end
226 liveuser 6595
 
3 liveuser 6596
		#執行到這邊代表執行正常
6597
		$result["status"]="true";
226 liveuser 6598
 
3 liveuser 6599
		#回傳結果
6600
		return $result;
226 liveuser 6601
 
3 liveuser 6602
		}#function getListTree end
226 liveuser 6603
 
3 liveuser 6604
	/*
6605
	#函式說明:
6606
	#取得目錄底下所有目錄與檔案清單.
6607
	#回傳結果:
6608
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6609
	#$result["error"],錯誤訊息陣列.
6610
	#$result["function"],函數名稱.
6611
	#$result["content"],陣列,目錄底下的檔案與子目錄.
6612
	#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
6613
	#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
6614
	#$result["content"][$i]["ownerPerm"],字串,使用者的權限.
6615
	#$result["content"][$i]["groupPerm"],字串,群組使用者的權限.
6616
	#$result["content"][$i]["otherPerm"],字串,其他使用者的權限.
6617
	#$result["content"][$i]["ownerName"],字串,擁有者賬戶.
6618
	#$result["content"][$i]["groupName"],字串,群組擁有者賬戶.
6619
	#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
6620
	#$result["position"],目前的位置.
6621
	#必填參數:
6622
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6623
	$conf["position"]="";
6624
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6625
	$conf["fileArgu"]=__FILE__;
6626
	#可省略參數:
6627
	#無
6628
	#參考資料:
6629
	#opendir=>http://php.net/manual/en/function.opendir.php
6630
	#is_dir=>http://php.net/manual/en/function.is-dir.php
6631
	#備註:
6632
	#無.
6633
	*/
6634
	public static function getList(&$conf){
6635
 
6636
		#初始化要回傳的結果
6637
		$result=array();
226 liveuser 6638
 
3 liveuser 6639
		#設置當其函數名稱
6640
		$result["function"]=__FUNCTION__;
226 liveuser 6641
 
3 liveuser 6642
		#初始化記載檔案目錄名單的陣列
6643
		$result["content"]=array();
226 liveuser 6644
 
3 liveuser 6645
		#如果 $conf 不為陣列
6646
		if(gettype($conf)!="array"){
226 liveuser 6647
 
3 liveuser 6648
			#設置執行失敗
6649
			$result["status"]="false";
226 liveuser 6650
 
3 liveuser 6651
			#設置執行錯誤訊息
6652
			$result["error"][]="\$conf變數須為陣列形態";
6653
 
6654
			#如果傳入的參數為 null
6655
			if($conf==null){
226 liveuser 6656
 
3 liveuser 6657
				#設置執行錯誤訊息
6658
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6659
 
3 liveuser 6660
				}#if end
6661
 
6662
			#回傳結果
6663
			return $result;
226 liveuser 6664
 
3 liveuser 6665
			}#if end
226 liveuser 6666
 
3 liveuser 6667
		#檢查必填參數
6668
		#函式說明:
6669
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6670
		#回傳的結果:
6671
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6672
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6673
		#$result["function"],當前執行的函式名稱.
6674
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6675
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6676
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6677
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6678
		#必填寫的參數:
6679
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6680
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileArgu","position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6681
		#可以省略的參數:
226 liveuser 6682
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6683
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6684
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
6685
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 6686
 
3 liveuser 6687
		#如果檢查失敗
6688
		if($checkResult["status"]=="false"){
226 liveuser 6689
 
3 liveuser 6690
			#設置錯誤識別
6691
			$result["status"]="false";
226 liveuser 6692
 
3 liveuser 6693
			#設置錯誤訊息
6694
			$result["error"]=$checkResult;
226 liveuser 6695
 
3 liveuser 6696
			#回傳結果
6697
			return $result;
226 liveuser 6698
 
3 liveuser 6699
			}#if end
226 liveuser 6700
 
3 liveuser 6701
		#如果檢查不通過
6702
		if($checkResult["passed"]==="false"){
226 liveuser 6703
 
3 liveuser 6704
			#設置錯誤識別
6705
			$result["status"]="false";
226 liveuser 6706
 
3 liveuser 6707
			#設置錯誤訊息
6708
			$result["error"]=$checkResult;
226 liveuser 6709
 
3 liveuser 6710
			#回傳結果
6711
			return $result;
226 liveuser 6712
 
3 liveuser 6713
			}#if end
226 liveuser 6714
 
3 liveuser 6715
		#檢查目標路徑是否為「/」開頭的路徑
6716
		#函式說明:
6717
		#取得符合特定字首與字尾的字串
6718
		#回傳結果:
6719
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
6720
		#$result["function"],當前執行的函數名稱.
6721
		#$result["error"],錯誤訊息陣列.
6722
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
6723
		#$result["returnString"],爲符合字首條件的字串內容。
6724
		#必填參數:
6725
		#$conf["checkString"],字串,要檢查的字串.
6726
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["position"];
6727
		#可省略參數:
6728
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
6729
		$conf["search::getMeetConditionsString"]["frontWord"]="/";
6730
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
6731
		#$conf["tailWord"]="";
6732
		#參考資料:
6733
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
6734
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
6735
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 6736
 
3 liveuser 6737
		#如果檢查關鍵字失敗
6738
		if($getMeetConditionsString["status"]=="false"){
226 liveuser 6739
 
3 liveuser 6740
			#設置錯誤識別
6741
			$result["status"]="false";
226 liveuser 6742
 
3 liveuser 6743
			#設置錯誤訊息
6744
			$result["error"]=$getMeetConditionsString;
226 liveuser 6745
 
3 liveuser 6746
			#回傳結果
6747
			return $result;
226 liveuser 6748
 
6749
			}#if end
6750
 
3 liveuser 6751
		#如果目標路徑不為「/」開頭的路徑,則為相對路徑
6752
		if($getMeetConditionsString["founded"]=="false"){
226 liveuser 6753
 
3 liveuser 6754
			#取得目標位置的路徑
6755
			#函式說明:
6756
			#將檔案的位置名稱變成網址
6757
			#回傳結果:
6758
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6759
			#$result["error"],錯誤訊息陣列.
226 liveuser 6760
			#$result["function"],函數名稱.
3 liveuser 6761
			#$result["content"],網址.
6762
			#$result["localAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
6763
			#$result["fileSystemAbsoulutePosition"],針對伺服器檔案系統的絕對位置.
6764
			#必填參數:
6765
			#$conf["address"],字串,檔案的相對位置.
6766
			$conf["fileAccess::getInternetAddress"]["address"]=$conf["position"];
6767
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
6768
			$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
6769
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是.
6770
			#$conf["fileAccess::getInternetAddress"]["userDir"]="true";
6771
			$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
226 liveuser 6772
			unset($conf["fileAccess::getInternetAddress"]);
6773
 
3 liveuser 6774
			#如果將檔案的位置名稱變成網址失敗
6775
			if($getInternetAddress["status"]=="false"){
226 liveuser 6776
 
3 liveuser 6777
				#設置錯誤識別
6778
				$result["status"]="false";
226 liveuser 6779
 
3 liveuser 6780
				#設置錯誤訊息
6781
				$result["error"]=$getInternetAddress;
226 liveuser 6782
 
3 liveuser 6783
				#回傳結果
6784
				return $result;
226 liveuser 6785
 
6786
				}#if end
6787
 
3 liveuser 6788
			#置換目標位置為檔案系統路徑的絕對位置
6789
			$conf["position"]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 6790
 
6791
			}#if end
6792
 
6793
		#如果目標是資料夾
3 liveuser 6794
		if(is_dir($conf["position"])) {
226 liveuser 6795
 
3 liveuser 6796
			#設置為資料夾
6797
			$result["folder"]="true";
226 liveuser 6798
 
3 liveuser 6799
			#如果開啟資料夾成功
6800
			if($dh=opendir($conf["position"])){
226 liveuser 6801
 
3 liveuser 6802
				#初始化計數變數
6803
				$count=0;
226 liveuser 6804
 
3 liveuser 6805
				#如果資料夾裡面有檔案
6806
				while(($fileName=readdir($dh))!==false){
226 liveuser 6807
 
3 liveuser 6808
					#debug
6809
					#echo "有檔案";
226 liveuser 6810
 
3 liveuser 6811
					#如果名稱是「.」或「..」
6812
					if($fileName=="." || $fileName==".."){
226 liveuser 6813
 
3 liveuser 6814
						#則跳過
6815
						continue;
226 liveuser 6816
 
3 liveuser 6817
						}#if end
226 liveuser 6818
 
3 liveuser 6819
					#取得檔案或子目錄名稱
226 liveuser 6820
					$result["content"][$count]["name"]=$fileName;
6821
 
3 liveuser 6822
					#取得詳細資訊
6823
					#函式說明:
6824
					#取得節點的資訊.
6825
					#回傳結果:
6826
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6827
					#$result["error"],錯誤訊息陣列.
226 liveuser 6828
					#$result["function"],函數名稱.
3 liveuser 6829
					#$result["content"],檔案資訊陣列.
226 liveuser 6830
					#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 6831
					#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
6832
					#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
6833
					#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
6834
					#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
6835
					#$result["content"]["ownerName"],檔案擁有着資訊.
6836
					#$result["content"]["groupName"],檔案所屬擁有着資訊.
6837
					#$result["content"]["size"],檔案大小.
6838
					#$result["content"]["modifyDate"],檔案變更年月日.
6839
					#$result["content"]["modifyTime"],檔案變更時分秒.
6840
					#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
6841
					#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
6842
					#必填參數:
6843
					#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
6844
					$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];
6845
					#$conf["file"],字串,要查看擁有者資訊的檔案.
6846
					$conf["fileAccess::fileInfo"]["file"]=$conf["position"]."/".$fileName;
6847
					#可省略參數:
6848
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
6849
					$conf["fileAccess::fileInfo"]["web"]="false";
6850
					#參考資料:
6851
					#fileowner=>http://php.net/manual/en/function.fileowner.php
6852
					#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
6853
					#備註:
6854
					#無.
6855
					$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
6856
					unset($conf["fileAccess::fileInfo"]);
226 liveuser 6857
 
3 liveuser 6858
					#如果執行失敗
6859
					if($fileInfo["status"]=="false"){
226 liveuser 6860
 
3 liveuser 6861
						#設置錯誤識別
6862
						$result["status"]="false";
226 liveuser 6863
 
3 liveuser 6864
						#設置錯誤訊息
6865
						$result["error"]=$fileInfo;
226 liveuser 6866
 
3 liveuser 6867
						#回傳結果
6868
						return $result;
226 liveuser 6869
 
3 liveuser 6870
						}#if end
226 liveuser 6871
 
3 liveuser 6872
					#設置是否為資料夾
6873
					$result["content"][$count]["folder"]=$fileInfo["content"]["is_folder"];
226 liveuser 6874
 
3 liveuser 6875
					#設置使用者的權限
6876
					$result["content"][$count]["ownerPerm"]=$fileInfo["content"]["ownerPerm"];
226 liveuser 6877
 
3 liveuser 6878
					#設置群組的權限
6879
					$result["content"][$count]["groupPerm"]=$fileInfo["content"]["groupPerm"];
226 liveuser 6880
 
3 liveuser 6881
					#設置其他使用者的權限
6882
					$result["content"][$count]["otherPerm"]=$fileInfo["content"]["otherPerm"];
226 liveuser 6883
 
3 liveuser 6884
					#設置其擁有者賬戶
6885
					$result["content"][$count]["ownerName"]=$fileInfo["content"]["ownerName"];
226 liveuser 6886
 
3 liveuser 6887
					#設置其群組擁有者賬戶
6888
					$result["content"][$count]["groupName"]=$fileInfo["content"]["groupName"];
226 liveuser 6889
 
3 liveuser 6890
					#計數加1
6891
					$count++;
226 liveuser 6892
 
3 liveuser 6893
					}#while
226 liveuser 6894
 
3 liveuser 6895
				#關閉資料夾
6896
				closedir($dh);
226 liveuser 6897
 
3 liveuser 6898
				}#if end
226 liveuser 6899
 
6900
			#開啟資料夾失敗
3 liveuser 6901
			else{
226 liveuser 6902
 
3 liveuser 6903
				#設置執行失敗
6904
				$result["status"]="false";
226 liveuser 6905
 
3 liveuser 6906
				#設置執行錯誤訊息
6907
				$result["error"][]="開啟資料夾「".$conf["position"]."」失敗";
6908
 
6909
				#回傳結果
6910
				return $result;
226 liveuser 6911
 
3 liveuser 6912
				}#else end
226 liveuser 6913
 
3 liveuser 6914
			}#if end
226 liveuser 6915
 
3 liveuser 6916
		#反之是檔案
6917
		else{
226 liveuser 6918
 
3 liveuser 6919
			#設置不為目錄
6920
			$result["folder"]="false";
226 liveuser 6921
 
3 liveuser 6922
			}#else end
226 liveuser 6923
 
3 liveuser 6924
		#取得目前位置
226 liveuser 6925
		$result["position"]=$conf["position"];
6926
 
3 liveuser 6927
		#執行到這邊代表執行正常
6928
		$result["status"]="true";
226 liveuser 6929
 
3 liveuser 6930
		#回傳結果
226 liveuser 6931
		return $result;
3 liveuser 6932
 
6933
		}#function getList end
226 liveuser 6934
 
3 liveuser 6935
	/*
6936
	#函式說明:
6937
	#取得目錄底下所有目錄與檔案的樹狀結構.
6938
	#回傳結果:
6939
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6940
	#$result["error"],錯誤訊息陣列.
6941
	#$result["function"],函數名稱.
6942
	#$result["content"],陣列,檔案目錄的樹狀結構.
6943
	#必填參數:
6944
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6945
	$conf["position"]="";
6946
	#可省略參數:
6947
	#無.
6948
	#參考資料:
6949
	#無.
6950
	#備註:
6951
	#無.
6952
	*/
6953
	public static function exportListTree(&$conf){
226 liveuser 6954
 
3 liveuser 6955
		#初始化要回傳的結果
6956
		$result=array();
226 liveuser 6957
 
3 liveuser 6958
		#設置當其函數名稱
6959
		$result["function"]=__FUNCTION__;
226 liveuser 6960
 
3 liveuser 6961
		#如果 $conf 不為陣列
6962
		if(gettype($conf)!="array"){
226 liveuser 6963
 
3 liveuser 6964
			#設置執行失敗
6965
			$result["status"]="false";
226 liveuser 6966
 
3 liveuser 6967
			#設置執行錯誤訊息
6968
			$result["error"][]="\$conf變數須為陣列形態";
6969
 
6970
			#如果傳入的參數為 null
6971
			if($conf==null){
226 liveuser 6972
 
3 liveuser 6973
				#設置執行錯誤訊息
6974
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6975
 
3 liveuser 6976
				}#if end
6977
 
6978
			#回傳結果
6979
			return $result;
226 liveuser 6980
 
3 liveuser 6981
			}#if end
226 liveuser 6982
 
3 liveuser 6983
		#檢查必填參數
6984
		#函式說明:
6985
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6986
		#回傳的結果:
6987
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6988
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6989
		#$result["function"],當前執行的函式名稱.
6990
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6991
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6992
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6993
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6994
		#必填寫的參數:
6995
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6996
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6997
		#可以省略的參數:
226 liveuser 6998
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6999
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
7000
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
7001
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 7002
 
3 liveuser 7003
		#如果檢查失敗
7004
		if($checkResult["status"]=="false"){
226 liveuser 7005
 
3 liveuser 7006
			#設置錯誤識別
7007
			$result["status"]="false";
226 liveuser 7008
 
3 liveuser 7009
			#設置錯誤訊息
7010
			$result["error"]=$checkResult;
226 liveuser 7011
 
3 liveuser 7012
			#回傳結果
7013
			return $result;
226 liveuser 7014
 
3 liveuser 7015
			}#if end
226 liveuser 7016
 
3 liveuser 7017
		#如果檢查不通過
7018
		if($checkResult["passed"]=="false"){
226 liveuser 7019
 
3 liveuser 7020
			#設置錯誤識別
7021
			$result["status"]="false";
226 liveuser 7022
 
3 liveuser 7023
			#設置錯誤訊息
7024
			$result["error"]=$checkResult;
226 liveuser 7025
 
3 liveuser 7026
			#回傳結果
7027
			return $result;
226 liveuser 7028
 
3 liveuser 7029
			}#if end
226 liveuser 7030
 
3 liveuser 7031
		#函式說明:
7032
		#取得目錄底下所有目錄與檔案的樹狀結構.
7033
		#回傳結果:
7034
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7035
		#$result["error"],錯誤訊息陣列.
7036
		#$result["function"],函數名稱.
7037
		#$result["content"],陣列,檔案目錄的樹狀結構.
7038
		#必填參數:
7039
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
7040
		$conf["fileAccess::getListTree"]["position"]=$conf["position"];
7041
		#可省略參數:
7042
		#無
7043
		#備註:
226 liveuser 7044
		#若檔案與目錄的名稱含有「[」與「]」與「(」與「)」將會無法取得其目錄底下的內容
3 liveuser 7045
		#若檔案與目錄的名稱含有「 」將會無法檢查檔案是否存在
7046
		#改用opendir()函數應該可以解決大部分的bug.
7047
		$getListTree=fileAccess::getListTree($conf["fileAccess::getListTree"]);
7048
		unset($conf["fileAccess::getListTree"]);
226 liveuser 7049
 
3 liveuser 7050
		#如果取得 目標目錄底下所有目錄與檔案的樹狀結構 失敗
7051
		if($getListTree["status"]==="false"){
226 liveuser 7052
 
3 liveuser 7053
			#設置錯誤識別
7054
			$result["status"]="false";
226 liveuser 7055
 
3 liveuser 7056
			#設置錯誤訊息
7057
			$result["error"]=$getListTree;
226 liveuser 7058
 
3 liveuser 7059
			#回傳結果
7060
			return $result;
226 liveuser 7061
 
3 liveuser 7062
			}#if end
226 liveuser 7063
 
3 liveuser 7064
		#目標目錄底下有幾個
226 liveuser 7065
 
3 liveuser 7066
		}#function exportListTree end
7067
 
7068
	/*
7069
	#函式說明:
7070
	#解壓縮tar.xz檔案,解壓縮完畢後,tar.xz檔案會被移除.
7071
	#回傳結果:
7072
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7073
	#$result["error"],錯誤訊息陣列.
226 liveuser 7074
	#$result["function"],函數名稱.
3 liveuser 7075
	#必填參數:
7076
	#$conf["tarXzFile"],字串變數,壓縮檔的位置與名稱,副檔名".tar.xz"會自動補上.
7077
	$conf["tarXzFile"]="";
7078
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7079
	$conf["fileArgu"]=__FILE__;
7080
	#可省略參數:
7081
	#$conf["extractTo"],字串,要解壓縮到哪邊,預設為當前路徑"."
7082
	#$conf["extractTo"]=".";
7083
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7084
	#$conf["commentsArray"]=array("");
7085
	#參考資料:
7086
	#無.
7087
	#備註:
7088
	#無.
7089
	*/
7090
	public static function unpackTarXzFile(&$conf){
226 liveuser 7091
 
3 liveuser 7092
		#初始化要回傳的內容
7093
		$result=array();
226 liveuser 7094
 
3 liveuser 7095
		#記錄當前執行的函數名稱
7096
		$result["function"]=__FUNCTION__;
226 liveuser 7097
 
3 liveuser 7098
		#如果 $conf 不為陣列
7099
		if(gettype($conf)!="array"){
226 liveuser 7100
 
3 liveuser 7101
			#設置執行失敗
7102
			$result["status"]="false";
226 liveuser 7103
 
3 liveuser 7104
			#設置執行錯誤訊息
7105
			$result["error"][]="\$conf變數須為陣列形態";
7106
 
7107
			#如果傳入的參數為 null
7108
			if($conf==null){
226 liveuser 7109
 
3 liveuser 7110
				#設置執行錯誤訊息
7111
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7112
 
3 liveuser 7113
				}#if end
7114
 
7115
			#回傳結果
7116
			return $result;
226 liveuser 7117
 
3 liveuser 7118
			}#if end
226 liveuser 7119
 
3 liveuser 7120
		#檢查參數
7121
		#函式說明:
7122
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7123
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7124
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7125
		#$result["function"],當前執行的函式名稱.
7126
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7127
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7128
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7129
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7130
		#必填寫的參數:
7131
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7132
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7133
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7134
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","tarXzFile");
226 liveuser 7135
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7136
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
7137
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7138
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7139
		#可以省略的參數:
7140
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7141
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7142
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7143
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","extractTo");
226 liveuser 7144
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7145
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string");
7146
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7147
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,".");
7148
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7149
		#$conf["arrayCountEqualCheck"][]=array();
7150
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7151
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 7152
 
3 liveuser 7153
		#若檢查失敗
7154
		if($checkResult["status"]=="false"){
226 liveuser 7155
 
3 liveuser 7156
			#設置執行失敗
7157
			$result["status"]="false";
226 liveuser 7158
 
3 liveuser 7159
			#設置執行錯誤訊息
7160
			$result["error"]=$checkResult;
226 liveuser 7161
 
3 liveuser 7162
			#回傳結果
7163
			return $result;
226 liveuser 7164
 
3 liveuser 7165
			}#if end
226 liveuser 7166
 
3 liveuser 7167
		#若檢查不通過
7168
		if($checkResult["passed"]=="false"){
226 liveuser 7169
 
3 liveuser 7170
			#設置執行失敗
7171
			$result["status"]="false";
226 liveuser 7172
 
3 liveuser 7173
			#設置執行錯誤訊息
7174
			$result["error"]=$checkResult;
226 liveuser 7175
 
3 liveuser 7176
			#回傳結果
7177
			return $result;
226 liveuser 7178
 
3 liveuser 7179
			}#if end
226 liveuser 7180
 
3 liveuser 7181
		#如果 $conf["commentsArray"] 有設定
7182
		if(isset($conf["commentsArray"])){
226 liveuser 7183
 
3 liveuser 7184
			#印出提示文字
7185
			#函式說明:
7186
			#印出多行文字,結尾自動換行.
7187
			#回傳的結果:
7188
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
7189
			#$result["function"],當前執行的函數名稱.
7190
			#$result["error"],錯誤訊息陣列.
7191
			#必填參數:
7192
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
7193
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
7194
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
7195
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 7196
 
3 liveuser 7197
			#如果印出提示文字失敗
7198
			if($echoMultiLine["status"]=="false"){
226 liveuser 7199
 
3 liveuser 7200
				#設置執行失敗
7201
				$result["status"]="false";
226 liveuser 7202
 
3 liveuser 7203
				#設置執行錯誤訊息
7204
				$result["error"]=$echoMultiLine;
226 liveuser 7205
 
3 liveuser 7206
				#回傳結果
7207
				return $result;
226 liveuser 7208
 
3 liveuser 7209
				}#if end
226 liveuser 7210
 
3 liveuser 7211
			}#if end
226 liveuser 7212
 
3 liveuser 7213
		#檢查要移動的檔案是否存在
7214
		#函式說明:
7215
		#檢查多個檔案與資料夾是否存在.
7216
		#回傳的結果:
7217
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
7218
		#$result["error"],錯誤訊息陣列.
7219
		#$resutl["function"],當前執行的涵式名稱.
7220
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
7221
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
7222
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
7223
		#必填參數:
7224
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["tarXzFile"].".tar.xz");#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
7225
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7226
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
7227
		#參考資料來源:
7228
		#http://php.net/manual/en/function.file-exists.php
7229
		#http://php.net/manual/en/control-structures.foreach.php
7230
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
7231
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 7232
 
3 liveuser 7233
		#如果檢查失敗
7234
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 7235
 
3 liveuser 7236
			#設置執行失敗
7237
			$result["status"]="false";
226 liveuser 7238
 
3 liveuser 7239
			#設置執行錯誤訊息
7240
			$result["error"]=$checkMultiFileExist;
226 liveuser 7241
 
3 liveuser 7242
			#回傳結果
7243
			return $result;
226 liveuser 7244
 
7245
			}#if end
7246
 
3 liveuser 7247
		#如果來源檔案不存在
7248
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 7249
 
3 liveuser 7250
			#設置執行失敗
7251
			$result["status"]="false";
226 liveuser 7252
 
3 liveuser 7253
			#設置執行錯誤訊息
7254
			$result["error"][]="檔案「".$conf["tarXzFile"].".tar.xz」不存在";
226 liveuser 7255
 
3 liveuser 7256
			#回傳結果
7257
			return $result;
226 liveuser 7258
 
3 liveuser 7259
			}#if end
226 liveuser 7260
 
3 liveuser 7261
		#進行解壓縮xz檔
7262
		#函式說明:
7263
		#呼叫shell執行系統命令,並取得回傳的內容.
7264
		#回傳的結果:
7265
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7266
		#$result["error"],錯誤訊息陣列.
7267
		#$result["function"],當前執行的函數名稱.
7268
		#$result["cmd"],執行的指令內容.
7269
		#$result["output"],爲執行完二元碼後的輸出陣列.
7270
		#必填的參數
7271
		#$conf["command"],字串,要執行的指令與.
7272
		$conf["fileAccess::callShell"]["command"]="xz -v -v -d -f ".$conf["tarXzFile"].".tar.xz";
7273
		#可省略參數:
7274
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7275
		#$conf["fileAccess::callShell"]["argu"]=array();
7276
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7277
		#$conf["enablePrintDescription"]="true";
7278
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7279
		#$conf["printDescription"]="";
7280
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
7281
		#$conf["escapeshellarg"]="true";
7282
		#備註:
7283
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
7284
		#參考資料:
7285
		#exec=>http://php.net/manual/en/function.exec.php
7286
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7287
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7288
		$callShell=external::callShell($conf["fileAccess::callShell"]);
7289
		unset($conf["fileAccess::callShell"]);
226 liveuser 7290
 
3 liveuser 7291
		#如果解壓縮xz檔案失敗
7292
		if($callShell["status"]=="false"){
226 liveuser 7293
 
3 liveuser 7294
			#設置執行失敗
7295
			$result["status"]="false";
226 liveuser 7296
 
3 liveuser 7297
			#設置執行錯誤訊息
7298
			$result["error"]=$callShell;
226 liveuser 7299
 
3 liveuser 7300
			#回傳結果
7301
			return $result;
226 liveuser 7302
 
3 liveuser 7303
			}#if end
226 liveuser 7304
 
3 liveuser 7305
		#解壓縮tar檔
7306
		#函式說明:
7307
		#呼叫shell執行系統命令,並取得回傳的內容.
7308
		#回傳的結果:
7309
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7310
		#$result["error"],錯誤訊息陣列.
7311
		#$result["function"],當前執行的函數名稱.
7312
		#$result["cmd"],執行的指令內容.
7313
		#$result["output"],爲執行完二元碼後的輸出陣列.
7314
		#必填的參數
7315
		#$conf["command"],字串,要執行的指令與.
7316
		$conf["fileAccess::callShell"]["command"]="tar";
7317
		#可省略參數:
7318
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7319
		$conf["fileAccess::callShell"]["argu"]=array("-xvf",$conf["tarXzFile"]."tar",$conf["extractTo"]);
7320
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7321
		#$conf["enablePrintDescription"]="true";
7322
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7323
		#$conf["printDescription"]="";
7324
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
7325
		$conf["fileAccess::callShell"]["escapeshellarg"]="true";
7326
		#備註:
7327
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
7328
		#參考資料:
7329
		#exec=>http://php.net/manual/en/function.exec.php
7330
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7331
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7332
		$callShell=external::callShell($conf["fileAccess::callShell"]);
7333
		unset($conf["fileAccess::callShell"]);
226 liveuser 7334
 
3 liveuser 7335
		#如果解壓縮xz檔案失敗
7336
		if($callShell["status"]=="false"){
226 liveuser 7337
 
3 liveuser 7338
			#設置執行失敗
7339
			$result["status"]="false";
226 liveuser 7340
 
3 liveuser 7341
			#設置執行錯誤訊息
7342
			$result["error"]=$callShell;
226 liveuser 7343
 
3 liveuser 7344
			#回傳結果
7345
			return $result;
226 liveuser 7346
 
3 liveuser 7347
			}#if end
226 liveuser 7348
 
3 liveuser 7349
		#移除tar檔
7350
		#函式說明:
7351
		#移除檔案
7352
		#回傳結果:
7353
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7354
		#$result["error"],錯誤訊息陣列
7355
		#$result["warning"],警告訊息陣列
7356
		#$result["function"],當前執行的函數名稱
7357
		#必填參數:
7358
		$conf["fileAccess::delFile"]["fileAddress"]=$conf["tarXzFile"].".tar";#要移除檔案的位置
7359
		#可省略參數:
7360
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7361
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
7362
		#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7363
		#$conf["commentsArray"]=array("");
7364
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
226 liveuser 7365
		unset($conf["fileAccess::delFile"]);
7366
 
3 liveuser 7367
		#如果移除檔案失敗
7368
		if($delFile["status"]=="false"){
226 liveuser 7369
 
3 liveuser 7370
			#設置執行失敗
7371
			$result["status"]="false";
226 liveuser 7372
 
3 liveuser 7373
			#設置執行錯誤訊息
7374
			$result["error"]=$delFile;
226 liveuser 7375
 
3 liveuser 7376
			#回傳結果
7377
			return $result;
226 liveuser 7378
 
7379
			}#if end
7380
 
3 liveuser 7381
		#執行到這邊代表執行正常
7382
		$result["status"]="true";
226 liveuser 7383
 
3 liveuser 7384
		#回傳結果
7385
		return $result;
226 liveuser 7386
 
3 liveuser 7387
		}#function unpackTarXzFile end
7388
 
7389
	/*
7390
	#函式說明:
7391
	#用data:mimeType;base64,fileVar的形式來提供檔案的連結,亦即檔案儲存在變數裡面.
7392
	#回傳結果:
7393
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7394
	#$result["error"],錯誤訊息
7395
	#$result["content"],檔案變數的內容
7396
	#$result["fileTypeName"],副檔名,ex:「.tar.xz」.
226 liveuser 7397
	#$result["function"],當前執行的函數名稱
3 liveuser 7398
	#必填參數:
7399
	#$conf["filePosition"],要轉存成2元碼的檔案位置與名稱
7400
	$conf["filePosition"]="";
7401
	#$conf["mimeType"],2元碼的內容是什麼
7402
	$conf["mimeType"]="";
7403
	#可省略參數:
7404
	#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
7405
	#$conf["compressType"]="base64";
7406
	#$conf["delFile"],讀取完檔案後,要移除檔案嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
7407
	#$conf["delFile"]="false";
7408
	#參考資料:
7409
	#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
7410
	#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
7411
	#備註:
7412
	#無.
7413
	*/
7414
	public static function data(&$conf){
226 liveuser 7415
 
3 liveuser 7416
		#初始化要回傳的內容
7417
		$result=array();
226 liveuser 7418
 
3 liveuser 7419
		#取得當前執行的函數名稱
7420
		$result["function"]=__FUNCTION__;
226 liveuser 7421
 
3 liveuser 7422
		#如果 $conf 不為陣列
7423
		if(gettype($conf)!="array"){
226 liveuser 7424
 
3 liveuser 7425
			#設置執行失敗
7426
			$result["status"]="false";
226 liveuser 7427
 
3 liveuser 7428
			#設置執行錯誤訊息
7429
			$result["error"][]="\$conf變數須為陣列形態";
7430
 
7431
			#如果傳入的參數為 null
7432
			if($conf==null){
226 liveuser 7433
 
3 liveuser 7434
				#設置執行錯誤訊息
7435
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7436
 
3 liveuser 7437
				}#if end
7438
 
7439
			#回傳結果
7440
			return $result;
226 liveuser 7441
 
3 liveuser 7442
			}#if end
226 liveuser 7443
 
3 liveuser 7444
		#檢查參數
7445
		#函式說明:
7446
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7447
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7448
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7449
		#$result["function"],當前執行的函式名稱.
7450
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7451
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7452
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7453
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7454
		#必填寫的參數:
7455
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7456
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7457
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7458
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePosition");
226 liveuser 7459
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7460
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7461
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7462
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7463
		#可以省略的參數:
7464
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7465
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7466
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7467
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mimeType","compressType","delFile");
226 liveuser 7468
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7469
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
7470
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,「null」代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7471
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("null","base64","false");
7472
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7473
		#$conf["arrayCountEqualCheck"][]=array();
7474
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7475
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 7476
 
3 liveuser 7477
		#如果檢查參數失敗
7478
		if($checkResult["status"]=="false"){
226 liveuser 7479
 
3 liveuser 7480
			#設置執行失敗
7481
			$result["status"]="false";
226 liveuser 7482
 
3 liveuser 7483
			#設置錯誤訊息
7484
			$result["error"]=$checkResult;
226 liveuser 7485
 
3 liveuser 7486
			#回傳結果
7487
			return $result;
226 liveuser 7488
 
3 liveuser 7489
			}#if end
226 liveuser 7490
 
3 liveuser 7491
		#如果檢查參數不通過
7492
		if($checkResult["passed"]=="false"){
226 liveuser 7493
 
3 liveuser 7494
			#設置執行失敗
7495
			$result["status"]="false";
226 liveuser 7496
 
3 liveuser 7497
			#設置錯誤訊息
7498
			$result["error"]=$checkResult;
226 liveuser 7499
 
3 liveuser 7500
			#回傳結果
7501
			return $result;
226 liveuser 7502
 
3 liveuser 7503
			}#if end
226 liveuser 7504
 
3 liveuser 7505
		#依據檔案名稱取得副檔名 $result["fileTypeName"]
7506
		#函式說明:
7507
		#將固定格式的字串分開,並回傳分開的結果。
7508
		#回傳的參數:
7509
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7510
		#$result["error"],錯誤訊息陣列
7511
		#$result["function"],當前執行的函數名稱.
7512
		#$result["oriStr"],要分割的原始字串內容
7513
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7514
		#$result["dataCounts"],爲總共分成幾段
7515
		#必填參數:
7516
		$conf["stringProcess::spiltString"]["stringIn"]=basename($conf["filePosition"]);#要處理的字串。
7517
		$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
7518
		#備註:
7519
		#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
7520
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
7521
		unset($conf["stringProcess::spiltString"]);
226 liveuser 7522
 
3 liveuser 7523
		#如果分割字串失敗
7524
		if($spiltString["status"]=="false"){
226 liveuser 7525
 
3 liveuser 7526
			#設置執行失敗
7527
			$result["status"]="false";
226 liveuser 7528
 
3 liveuser 7529
			#設置錯誤訊息
7530
			$result["error"]=$spiltString;
226 liveuser 7531
 
3 liveuser 7532
			#回傳結果
7533
			return $result;
226 liveuser 7534
 
3 liveuser 7535
			}#if end
226 liveuser 7536
 
3 liveuser 7537
		#初始化副檔名
226 liveuser 7538
		$result["fileTypeName"]="";
7539
 
3 liveuser 7540
		#如果只有一段代表沒有副檔名
7541
		if($spiltString["dataCounts"]==1){
226 liveuser 7542
 
3 liveuser 7543
			#副檔名設置為 "unknow"
7544
			$result["fileTypeName"]="unknow";
226 liveuser 7545
 
3 liveuser 7546
			}#if end
226 liveuser 7547
 
3 liveuser 7548
		#不符合以上條件,但至少有兩段
7549
		else if($spiltString["dataCounts"]>=2){
226 liveuser 7550
 
3 liveuser 7551
			#執行 $spiltString["dataCounts"] 減一次的迴圈
7552
			for($i=1;$i<$spiltString["dataCounts"];$i++){
226 liveuser 7553
 
3 liveuser 7554
				#串接副檔名
7555
				$result["fileTypeName"]=$result["fileTypeName"].".".$spiltString["dataArray"][$i];
226 liveuser 7556
 
3 liveuser 7557
				}#for end
226 liveuser 7558
 
3 liveuser 7559
			}#if end
226 liveuser 7560
 
3 liveuser 7561
		#讀取檔案內容
7562
		$fileBin=file_get_contents($conf["filePosition"],"rb");
226 liveuser 7563
 
3 liveuser 7564
		#編碼檔案
7565
		$base64fileBin=base64_encode($fileBin);
226 liveuser 7566
 
3 liveuser 7567
		#如果 $conf["delFile"] 等於 "true"
7568
		if($conf["delFile"]=="true"){
226 liveuser 7569
 
3 liveuser 7570
			#移除檔案
7571
			#函式說明:
7572
			#移除檔案
7573
			#回傳結果:
7574
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7575
			#$result["error"],錯誤訊息陣列
7576
			#$result["warning"],警告訊息陣列
7577
			#$result["function"],當前執行的函數名稱
7578
			#必填參數:
7579
			$conf["fileAccess::delFile"]["fileAddress"]=$conf["filePosition"];#要移除檔案的位置
7580
			$del=fileAccess::delFile($conf["fileAccess::delFile"]);
7581
			unset($conf["fileAccess::delFile"]);
226 liveuser 7582
 
3 liveuser 7583
			#如果移除圖片失敗
7584
			if($del["status"]=="false"){
226 liveuser 7585
 
3 liveuser 7586
				#設置執行失敗
7587
				$result["status"]="false";
226 liveuser 7588
 
3 liveuser 7589
				#設置錯誤訊息
7590
				$result["error"]=$del;
226 liveuser 7591
 
3 liveuser 7592
				#回傳結果
7593
				return $result;
226 liveuser 7594
 
3 liveuser 7595
				}#if end
226 liveuser 7596
 
3 liveuser 7597
			}#if end
226 liveuser 7598
 
3 liveuser 7599
		#放置檔案的語法
7600
		$result["content"]="data:".$conf["mimeType"].";".$conf["compressType"].",".$base64fileBin;
226 liveuser 7601
 
3 liveuser 7602
		#執行到這邊代表執行正常
7603
		$result["status"]="true";
226 liveuser 7604
 
3 liveuser 7605
		#回傳結果
7606
		return $result;
226 liveuser 7607
 
3 liveuser 7608
		}#function data end
7609
 
7610
	/*
7611
	#函式說明:
7612
	#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
7613
	#回傳結果:
7614
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7615
	#$result["error"],錯誤訊息陣列.
226 liveuser 7616
	#$result["function"],函數名稱.
3 liveuser 7617
	#$result["argu"],使用的參數.
7618
	#$result["content"],網址,若是在命令列執行,則為"null".
7619
	#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
7620
	#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
7621
	#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
7622
	#必填參數:
7623
	#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
7624
	$conf["address"]="";
7625
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7626
	$conf["fileArgu"]=__FILE__;
7627
	#可省略參數:
7628
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
7629
	#$conf["userDir"]="true";
7630
	#參考資料:
7631
	#無.
7632
	#備註:
7633
	#無.
7634
	*/
7635
	public static function getInternetAddress(&$conf){
226 liveuser 7636
 
3 liveuser 7637
		#初始化要回傳的變數
7638
		$result=array();
226 liveuser 7639
 
3 liveuser 7640
		#記錄當前執行的函數名稱
7641
		$result["function"]=__FUNCTION__;
226 liveuser 7642
 
3 liveuser 7643
		#如果 $conf 不為陣列
7644
		if(gettype($conf)!="array"){
226 liveuser 7645
 
3 liveuser 7646
			#設置執行失敗
7647
			$result["status"]="false";
226 liveuser 7648
 
3 liveuser 7649
			#設置執行錯誤訊息
7650
			$result["error"][]="\$conf變數須為陣列形態";
7651
 
7652
			#如果傳入的參數為 null
7653
			if($conf==null){
226 liveuser 7654
 
3 liveuser 7655
				#設置執行錯誤訊息
7656
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7657
 
3 liveuser 7658
				}#if end
7659
 
7660
			#回傳結果
7661
			return $result;
226 liveuser 7662
 
3 liveuser 7663
			}#if end
7664
 
7665
		#取得使用的參數
7666
		$result["argu"]=$conf;
226 liveuser 7667
 
3 liveuser 7668
		#檢查參數
7669
		#函式說明:
7670
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7671
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7672
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7673
		#$result["function"],當前執行的函式名稱.
7674
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7675
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7676
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7677
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7678
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7679
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7680
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7681
		#必填寫的參數:
7682
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7683
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7684
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7685
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("address","fileArgu");
226 liveuser 7686
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7687
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
7688
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7689
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7690
		#可以省略的參數:
7691
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7692
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7693
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7694
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("userDir");
226 liveuser 7695
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7696
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
7697
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7698
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
7699
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7700
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
7701
		#參考資料來源:
7702
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7703
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7704
		unset($conf["variableCheck::checkArguments"]);
7705
 
7706
		#如果檢查失敗
7707
		if($checkResult["status"]==="false"){
226 liveuser 7708
 
3 liveuser 7709
			#設置錯誤狀態
7710
			$result["status"]="false";
226 liveuser 7711
 
3 liveuser 7712
			#設置錯誤提示
7713
			$result["error"]=$checkResult;
226 liveuser 7714
 
3 liveuser 7715
			#回傳結果
7716
			return $result;
226 liveuser 7717
 
3 liveuser 7718
			}#if end
7719
 
7720
		#如果檢查不通過
7721
		if($checkResult["passed"]==="false"){
226 liveuser 7722
 
3 liveuser 7723
			#設置錯誤狀態
7724
			$result["status"]="false";
226 liveuser 7725
 
3 liveuser 7726
			#設置錯誤提示
7727
			$result["error"]=$checkResult;
226 liveuser 7728
 
3 liveuser 7729
			#回傳結果
7730
			return $result;
226 liveuser 7731
 
3 liveuser 7732
			}#if end
226 liveuser 7733
 
3 liveuser 7734
		#如果是本來就是網址了
7735
		if(strpos($conf["address"],'https://')===0 || strpos($conf["address"],'http://')===0){
226 liveuser 7736
 
3 liveuser 7737
			#設置執行正常
7738
			$result["status"]="true";
226 liveuser 7739
 
3 liveuser 7740
			#取得網址
7741
			$result["content"]=$conf["address"];
226 liveuser 7742
 
3 liveuser 7743
			#回傳結果
226 liveuser 7744
			return $result;
7745
 
7746
			}#if end
7747
 
3 liveuser 7748
		#解析 $conf["fileArgu"]
7749
		#函式說明:
7750
		#將固定格式的字串分開,並回傳分開的結果。
7751
		#回傳的參數:
7752
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7753
		#$result["error"],錯誤訊息陣列
7754
		#$result["function"],當前執行的函數名稱.
7755
		#$result["oriStr"],要分割的原始字串內容
7756
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7757
		#$result["dataCounts"],爲總共分成幾段
7758
		#必填參數:
7759
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
7760
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7761
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7762
		unset($conf["stringProcess::spiltString"]);
7763
 
3 liveuser 7764
		#如果分割字串失敗
7765
		if($spiltString["status"]==="false"){
226 liveuser 7766
 
3 liveuser 7767
			#設置錯誤狀態
7768
			$result["status"]="false";
226 liveuser 7769
 
3 liveuser 7770
			#設置錯誤提示
7771
			$result["error"]=$spiltString;
226 liveuser 7772
 
3 liveuser 7773
			#回傳結果
7774
			return $result;
226 liveuser 7775
 
3 liveuser 7776
			}#if end
226 liveuser 7777
 
3 liveuser 7778
		#函式說明:
7779
		#將多個路徑字串變成相對於當前路徑的相對路徑字串
7780
		#回傳結果:
7781
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7782
		#$result["error"],錯誤訊息陣列.
226 liveuser 7783
		#$result["function"],函數名稱.
3 liveuser 7784
		#$result["content"],字串陣列,多個轉換好的相對路徑字串.
7785
		#必填參數:
7786
		#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
7787
		$conf["fileAccess::getRelativePath"]["path"]=array($conf["address"]);
7788
		#$conf["fileArgu"],字串,當前路徑.
7789
		$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
7790
		$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
7791
		unset($conf["fileAccess::getRelativePath"]);
226 liveuser 7792
 
3 liveuser 7793
		#如果取得相對位置失敗
7794
		if($getRelativePath["status"]==="false"){
226 liveuser 7795
 
3 liveuser 7796
			#設置錯誤狀態
7797
			$result["status"]="false";
226 liveuser 7798
 
3 liveuser 7799
			#設置錯誤提示
7800
			$result["error"]=$getRelativePath;
226 liveuser 7801
 
3 liveuser 7802
			#回傳結果
7803
			return $result;
226 liveuser 7804
 
7805
			}#if end
7806
 
3 liveuser 7807
		#取得轉換成相對路徑的位置
7808
		$result["fileSystemRelativePosition"]=$getRelativePath["content"][0];
226 liveuser 7809
 
3 liveuser 7810
		#解析 $conf["fileArgu"]
7811
		#函式說明:
7812
		#將固定格式的字串分開,並回傳分開的結果。
7813
		#回傳的參數:
7814
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7815
		#$result["error"],錯誤訊息陣列
7816
		#$result["function"],當前執行的函數名稱.
7817
		#$result["oriStr"],要分割的原始字串內容
7818
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7819
		#$result["dataCounts"],爲總共分成幾段
7820
		#必填參數:
7821
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
7822
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7823
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7824
		unset($conf["stringProcess::spiltString"]);
7825
 
3 liveuser 7826
		#如果分割字串失敗
7827
		if($spiltString["status"]==="false"){
226 liveuser 7828
 
3 liveuser 7829
			#設置錯誤狀態
7830
			$result["status"]="false";
226 liveuser 7831
 
3 liveuser 7832
			#設置錯誤提示
7833
			$result["error"]=$spiltString;
226 liveuser 7834
 
3 liveuser 7835
			#回傳結果
7836
			return $result;
226 liveuser 7837
 
3 liveuser 7838
			}#if end
226 liveuser 7839
 
3 liveuser 7840
		#debug
7841
		#var_dump($spiltString);
7842
		#var_dump($_SERVER);
7843
 
7844
		#初始化檔案在伺服器上的檔案系統位置
7845
		$result["fileSystemAbsoulutePosition"]="/";
226 liveuser 7846
 
3 liveuser 7847
		#將最後一段捨棄
7848
		for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7849
 
3 liveuser 7850
			$result["fileSystemAbsoulutePosition"]=$result["fileSystemAbsoulutePosition"].$spiltString["dataArray"][$i]."/";
226 liveuser 7851
 
7852
			}#for end
7853
 
3 liveuser 7854
		#取得非直觀的絕對位置
7855
		$result["fileSystemAbsoulutePosition"]=$result["fileSystemAbsoulutePosition"].$result["fileSystemRelativePosition"];
226 liveuser 7856
 
3 liveuser 7857
		#將檔案的相對路徑進行整理,變成可以直接讀的路徑.
7858
		#函式說明:
7859
		#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
7860
		#回傳的結果:
7861
		#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
7862
		#$result["function"],當前執行的函數.
7863
		#$result["error"],錯誤訊息陣列.
7864
		#$result["changedPath"],處理完後回傳的目錄字串.
7865
		#$result["oriPath"],原始的路徑字串
7866
		#必填參數:
7867
		#$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"],字串,要處理的檔案目錄字串.
7868
		$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$result["fileSystemAbsoulutePosition"];
7869
		$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
7870
		unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 7871
 
3 liveuser 7872
		#如果處理失敗
7873
		if($changeDirByDotDotSolidus["status"]==="false"){
226 liveuser 7874
 
3 liveuser 7875
			#設置錯誤狀態
7876
			$result["status"]="false";
226 liveuser 7877
 
3 liveuser 7878
			#設置錯誤提示
7879
			$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 7880
 
3 liveuser 7881
			#回傳結果
7882
			return $result;
226 liveuser 7883
 
3 liveuser 7884
			}#if end
226 liveuser 7885
 
3 liveuser 7886
		#改變為易讀的絕對路徑
226 liveuser 7887
		$result["fileSystemAbsoulutePosition"]=$changeDirByDotDotSolidus["changedPath"];
7888
 
3 liveuser 7889
		#如果 $conf["userDir"] 為 "true"
7890
		if($conf["userDir"]==="true"){
226 liveuser 7891
 
3 liveuser 7892
			#重設為 絕對路徑 [/~家目錄名稱」
7893
			$result["webPathFromRoot"]="/~".$spiltString["dataArray"][1];
226 liveuser 7894
 
3 liveuser 7895
			#從第四段到倒數第二段,將其內容合併
7896
			for($i=3;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7897
 
3 liveuser 7898
				$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$spiltString["dataArray"][$i];
226 liveuser 7899
 
3 liveuser 7900
				}#for end
226 liveuser 7901
 
3 liveuser 7902
			}#if end
226 liveuser 7903
 
3 liveuser 7904
		#反之 $conf["userDir"] 為 "false",
7905
		else{
226 liveuser 7906
 
3 liveuser 7907
			#重設為 ""
7908
			$result["webPathFromRoot"]="";
7909
 
226 liveuser 7910
			#可能的根目錄層級 - start
7911
 
3 liveuser 7912
			#解析 $conf["fileArgu"]
7913
			#函式說明:
7914
			#將固定格式的字串分開,並回傳分開的結果。
7915
			#回傳的參數:
7916
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7917
			#$result["error"],錯誤訊息陣列
7918
			#$result["function"],當前執行的函數名稱.
7919
			#$result["oriStr"],要分割的原始字串內容
7920
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7921
			#$result["dataCounts"],爲總共分成幾段
7922
			#必填參數:
7923
			$conf["stringProcess::spiltString"]["stringIn"]=$_SERVER["PHP_SELF"];#要處理的字串。
7924
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7925
			$keyWord=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7926
			unset($conf["stringProcess::spiltString"]);
3 liveuser 7927
 
7928
			#如果處理失敗
7929
			if($keyWord["status"]==="false"){
226 liveuser 7930
 
3 liveuser 7931
				#設置錯誤狀態
7932
				$result["status"]="false";
226 liveuser 7933
 
3 liveuser 7934
				#設置錯誤提示
7935
				$result["error"]=$keyWord;
226 liveuser 7936
 
3 liveuser 7937
				#回傳結果
7938
				return $result;
226 liveuser 7939
 
3 liveuser 7940
				}#if end
226 liveuser 7941
 
3 liveuser 7942
			#取得關鍵字
7943
			$keyWord=$keyWord["dataArray"][0];
7944
 
7945
			#預設層級為4層
7946
			$layer=4;
7947
 
7948
			#檢查每個絕對路徑片段
7949
			for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7950
 
3 liveuser 7951
				#如果路徑片段等於 $keyWord
7952
				if($spiltString["dataArray"][$i]===$keyWord){
226 liveuser 7953
 
3 liveuser 7954
					#取得層級
7955
					$layer=$i;
226 liveuser 7956
 
3 liveuser 7957
					#跳出迴圈
7958
					break;
7959
 
7960
					}#if end
226 liveuser 7961
 
3 liveuser 7962
				}#for end
7963
 
7964
			#可能的根目錄層級 - end
7965
 
7966
			#網頁於檔案系統中的存放路徑可能為「/var/www/html」,從第四段到倒數第二段,將其內容合併
7967
			for($i=$layer;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7968
 
3 liveuser 7969
				$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$spiltString["dataArray"][$i];
226 liveuser 7970
 
3 liveuser 7971
				}#for end
226 liveuser 7972
 
3 liveuser 7973
			}#else end
226 liveuser 7974
 
3 liveuser 7975
		#加上檔案的路徑
226 liveuser 7976
		$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$conf["address"];
7977
 
3 liveuser 7978
		#取得檔案位於網頁伺服器的絕對位置
7979
		#函式說明:
7980
		#取得用戶端的資訊,並依據需要寫入到資料表裡面
7981
		#回傳結果:
7982
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
7983
		#$result["error"],錯誤訊息.
7984
		#$result["function"],檔前執行的函數名稱.
7985
		#$result["userBrowserType"],爲使用者的瀏覽器資訊
7986
		#$result["userIp"],爲使用者的IP
7987
		#$result["serverIp"],為伺服器的IP
7988
		#$result["scheme"],通訊協定
7989
		#$result["serverPort"],伺服器給對外下載網頁的port
7990
		#$result["requestUri"],爲使用者要求的網址
7991
		#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
7992
		#$result["clientRequestIP"],用戶端要求的ip與port
7993
		#必填參數:
7994
		$conf["csInformation::getConnectionInfo"]["getAccount"]="false";#是否要取得帳號
7995
		#可省略參數:
7996
		#$conf["accountVar"]=$_SESSION["username"];#帳號儲存在哪個變數裏面,預設爲$_SESSION["username"]
7997
		#$conf["saveToDb"]="true";#是否要除儲存到資料庫,"true"為要儲存",預設為不儲存
7998
		#$conf["dbAddress"]=$dbAddress;;#爲mysql-Server的位置,若#$conf["saveToDb"]設為"true",則該參數為必填。
7999
		#$conf["dbAccount"]=$dbAccount;#爲用於連入mysql-Server時要使用的帳號,若#$conf["saveToDb"]設為"true",則該參數為必填。
8000
		#$conf["dbName"]=$dbName;#要選取的資料庫名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
8001
		#$conf["tableName"]="visitorInfo";#爲要插入資料的資料表名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
8002
		#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");#爲資料表的項目名稱,
8003
			#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
8004
			#寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間
8005
			#$conf["saveToDb"]設為"true",則該參數為必填。
8006
		#$conf["dbPassword"]=$dbPassword;#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
8007
		$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
226 liveuser 8008
		unset($conf["csInformation::getConnectionInfo"]);
8009
 
3 liveuser 8010
		#如果取得連線資訊失敗
8011
		if($getConnectionInfo["status"]==="false"){
226 liveuser 8012
 
3 liveuser 8013
			#設置錯誤狀態
8014
			$result["status"]="false";
226 liveuser 8015
 
3 liveuser 8016
			#設置錯誤提示
8017
			$result["error"]=$getConnectionInfo;
226 liveuser 8018
 
3 liveuser 8019
			#回傳結果
8020
			return $result;
226 liveuser 8021
 
3 liveuser 8022
			}#if end
226 liveuser 8023
 
3 liveuser 8024
		#如果運行環境為 "web"
8025
		if($getConnectionInfo["mode"]=="web"){
226 liveuser 8026
 
3 liveuser 8027
			#為絕對路徑加上通訊協定與ip與port
226 liveuser 8028
			#$result["content"]=$getConnectionInfo["scheme"]."://".$getConnectionInfo["serverIp"].":".$getConnectionInfo["serverPort"].$result["webPathFromRoot"];
8029
 
8030
			#為絕對路徑加上用戶端通訊協定與ip與port
3 liveuser 8031
			$result["content"]=$getConnectionInfo["scheme"]."://".$getConnectionInfo["clientRequestIP"].$result["webPathFromRoot"];
226 liveuser 8032
 
3 liveuser 8033
			}#if end
226 liveuser 8034
 
3 liveuser 8035
		#反之如果為 "cmd" 環境
8036
		else{
226 liveuser 8037
 
3 liveuser 8038
			$result["content"]="null";
226 liveuser 8039
 
3 liveuser 8040
			}#else end
226 liveuser 8041
 
3 liveuser 8042
		#設置執行正常
8043
		$result["status"]="true";
226 liveuser 8044
 
3 liveuser 8045
		#回傳結果
8046
		return $result;
226 liveuser 8047
 
3 liveuser 8048
		}#function getInternetAddress end
8049
 
8050
	/*
8051
	#函式說明:
8052
	#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
8053
	#回傳結果:
8054
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8055
	#$result["error"],錯誤訊息陣列.
226 liveuser 8056
	#$result["function"],函數名稱.
3 liveuser 8057
	#$result["argu"],使用的參數.
8058
	#$result["content"],網址,若是在命令列執行,則為"null".
8059
	#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
8060
	#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
8061
	#必填參數:
8062
	#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
8063
	$conf["address"]="";
8064
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8065
	$conf["fileArgu"]=__FILE__;
8066
	#可省略參數:
8067
	#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
8068
	#$conf["web"]="true";
8069
	#參考資料:
8070
	#無.
8071
	#備註:
8072
	#無.
8073
	*/
8074
	public static function getInternetAddressV2(&$conf){
226 liveuser 8075
 
3 liveuser 8076
		#初始化要回傳的變數
8077
		$result=array();
226 liveuser 8078
 
3 liveuser 8079
		#記錄當前執行的函數名稱
8080
		$result["function"]=__FUNCTION__;
226 liveuser 8081
 
3 liveuser 8082
		#取得參數
8083
		$result["argu"]=$conf;
226 liveuser 8084
 
3 liveuser 8085
		#檢查參數
8086
		#函式說明:
8087
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8088
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8089
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8090
		#$result["function"],當前執行的函式名稱.
8091
		#$result["argu"],設置給予的參數.
8092
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8093
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8094
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8095
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8096
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8097
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8098
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8099
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8100
		#必填寫的參數:
8101
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8102
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8103
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8104
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8105
		#可以省略的參數:
8106
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8107
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("address","fileArgu");
8108
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
8109
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
8110
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8111
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8112
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
8113
		#$conf["canNotBeEmpty"]=array();
8114
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
8115
		#$conf["canBeEmpty"]=array();
8116
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
8117
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
8118
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8119
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
8120
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8121
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
8122
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8123
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
8124
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
8125
		#$conf["disallowAllSkipableVarIsEmpty"]="";
8126
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
8127
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
8128
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8129
		#$conf["arrayCountEqualCheck"][]=array();
8130
		#參考資料來源:
8131
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8132
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8133
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 8134
 
3 liveuser 8135
		#如果檢查失敗
8136
		if($checkArguments["status"]==="false"){
226 liveuser 8137
 
3 liveuser 8138
			#設置錯誤狀態
8139
			$result["status"]="false";
226 liveuser 8140
 
3 liveuser 8141
			#設置錯誤提示
8142
			$result["error"]=$checkArguments;
226 liveuser 8143
 
3 liveuser 8144
			#回傳結果
8145
			return $result;
226 liveuser 8146
 
3 liveuser 8147
			}#if end
226 liveuser 8148
 
3 liveuser 8149
		#如果檢查不通過
8150
		if($checkArguments["passed"]==="false"){
226 liveuser 8151
 
3 liveuser 8152
			#設置錯誤狀態
8153
			$result["status"]="false";
226 liveuser 8154
 
3 liveuser 8155
			#設置錯誤提示
8156
			$result["error"]=$checkArguments;
226 liveuser 8157
 
3 liveuser 8158
			#回傳結果
8159
			return $result;
226 liveuser 8160
 
3 liveuser 8161
			}#if end
226 liveuser 8162
 
3 liveuser 8163
		#如果是本來就是網址了
8164
		if(strpos($conf["address"],'https://')===0 || strpos($conf["address"],'http://')===0){
226 liveuser 8165
 
3 liveuser 8166
			#取得網址
8167
			$result["content"]=$conf["address"];
226 liveuser 8168
 
3 liveuser 8169
			}#if end
226 liveuser 8170
 
3 liveuser 8171
		#反之是絕對或相對路徑
8172
		else{
226 liveuser 8173
 
3 liveuser 8174
			#確認 $conf["address"] 是否為 escaped 後的內容
8175
			#函式說明:
8176
			#判斷字串是否一定需要經過escapeshellarg才能為單一shell參數,並回傳可以成為單一shell參數的結果.
8177
			#回傳結果:
8178
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8179
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
8180
			#$result["function"],當前執行的函式名稱.
8181
			#$result["argu"],使用的參數.
8182
			#$result["content"],字串,單一shell參數.
8183
			#$result["escaped"],字串,"true"代表content為 escape後的結果;反之為"false".
8184
			#$result["urlEncodeStr"],字串,未被escape過的單一shell參數被url encode後的結果.
8185
			#必填參數:
8186
			#$conf["str"],字串,認為要為單一 shell參數的字串.
8187
			$conf["stringProcess::toSingleShellArg"]["str"]=$conf["address"];
8188
			#可省略參數:
8189
			#無.
8190
			#參考資料:
8191
			#無.
8192
			#備註:
8193
			#無.
8194
			$toSingleShellArg=stringProcess::toSingleShellArg($conf["stringProcess::toSingleShellArg"]);
8195
			unset($conf["stringProcess::toSingleShellArg"]);
226 liveuser 8196
 
3 liveuser 8197
			#如果執行失敗
8198
			if($toSingleShellArg["status"]==="false"){
226 liveuser 8199
 
3 liveuser 8200
				#設置錯誤狀態
8201
				$result["status"]="false";
226 liveuser 8202
 
3 liveuser 8203
				#設置錯誤提示
8204
				$result["error"]=$toSingleShellArg;
226 liveuser 8205
 
3 liveuser 8206
				#回傳結果
8207
				return $result;
226 liveuser 8208
 
3 liveuser 8209
				}#if end
226 liveuser 8210
 
3 liveuser 8211
			#取得不含escape字元的address參數
8212
			$conf["address"]=urldecode($toSingleShellArg["urlEncodeStr"]);
226 liveuser 8213
 
3 liveuser 8214
			#不是絕對位置
8215
			if(strpos($conf["address"],"/")!==0){
226 liveuser 8216
 
3 liveuser 8217
				#如果有這些參數
8218
				if( isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT']) ){
226 liveuser 8219
 
3 liveuser 8220
					#網址
8221
					$result["content"]=$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/".$conf["address"];
226 liveuser 8222
 
3 liveuser 8223
					}#if end
226 liveuser 8224
 
3 liveuser 8225
				#反之
8226
				else{
226 liveuser 8227
 
3 liveuser 8228
					#網址設置為 null
8229
					$result["content"]=null;
226 liveuser 8230
 
3 liveuser 8231
					}#else
226 liveuser 8232
 
3 liveuser 8233
				}#if end
226 liveuser 8234
 
3 liveuser 8235
			#反之是絕對位置
8236
			else{
226 liveuser 8237
 
3 liveuser 8238
				#移除開頭的 "/"
8239
				$conf["address"]=substr($conf["address"],1);
226 liveuser 8240
 
3 liveuser 8241
				#如果有這些參數
8242
				if( isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT']) ){
226 liveuser 8243
 
3 liveuser 8244
					#網址
8245
					$result["content"]=$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/".$conf["address"];
226 liveuser 8246
 
3 liveuser 8247
					}#if end
226 liveuser 8248
 
3 liveuser 8249
				#反之
8250
				else{
226 liveuser 8251
 
3 liveuser 8252
					#網址設置為 null
8253
					$result["content"]=null;
226 liveuser 8254
 
3 liveuser 8255
					}#else
226 liveuser 8256
 
3 liveuser 8257
				}#else end
226 liveuser 8258
 
3 liveuser 8259
			#取得 doc root;
8260
			$docRoot=$_SERVER['DOCUMENT_ROOT'];
226 liveuser 8261
 
3 liveuser 8262
			#如果不是網路環境
8263
			if($conf["web"]==="false"){
226 liveuser 8264
 
3 liveuser 8265
				#不採用 docRoot
8266
				$docRoot="";
226 liveuser 8267
 
3 liveuser 8268
				}#if end
226 liveuser 8269
 
3 liveuser 8270
			#如果不存在 DOCUMENT_ROOT 變數或 web 參數為 "false" 且為相對位置.
8271
			if( ($_SERVER['DOCUMENT_ROOT']==="" || $conf["web"]==="false") && (strpos($result["argu"]["address"],"/")!==0) ){
226 liveuser 8272
 
3 liveuser 8273
				#執行 "pwd" 取得當前位置
8274
				exec("pwd",$output,$status);
226 liveuser 8275
 
3 liveuser 8276
				#預設為`pwd`的結果加"/"
8277
				$docRoot=$output[0]."/";
226 liveuser 8278
 
8279
				}#if end
8280
 
3 liveuser 8281
			#如果是絕對位置
8282
			else if(strpos($result["argu"]["address"],"/")===0){
226 liveuser 8283
 
8284
				#補回 "/"
3 liveuser 8285
				$conf["address"]="/".$conf["address"];
226 liveuser 8286
 
3 liveuser 8287
				}#if end
226 liveuser 8288
 
3 liveuser 8289
			#針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
8290
			$result["fileSystemAbsoulutePosition"]=$docRoot.$conf["address"];
226 liveuser 8291
 
3 liveuser 8292
			}#else end
226 liveuser 8293
 
3 liveuser 8294
		#設置執行正常
226 liveuser 8295
		$result["status"]="true";
8296
 
3 liveuser 8297
		#回傳結果
8298
		return $result;
226 liveuser 8299
 
3 liveuser 8300
		}#function getInternetAddressV2 end
8301
 
8302
	/*
8303
	#函式說明:
8304
	#將含有「*」的檔案路徑名稱,變成多個符合條件的路徑檔案.
8305
	#回傳結果:
8306
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8307
	#$result["error"],錯誤訊息陣列.
226 liveuser 8308
	#$result["function"],函數名稱.
3 liveuser 8309
	#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
8310
	#必填參數:
8311
	#$conf["path"],字串,要解析含有「*」的檔案路徑字串.
8312
	$conf["path"]="";
8313
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8314
	$conf["fileArgu"]=__FILE__;
8315
	#可省略參數:
8316
	#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
8317
	#$conf["noDotStart"]="true";
8318
	#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
8319
	#$conf["noWaveEnd"]="true";
8320
	#參考資料:
8321
	#無.
8322
	#備註:
8323
	#無.
8324
	*/
8325
	public static function resolvePostionStringWhichContainStarSymbol(&$conf){
226 liveuser 8326
 
3 liveuser 8327
		#初始化要回傳的結果
8328
		$result=array();
226 liveuser 8329
 
3 liveuser 8330
		#設置當其函數名稱
8331
		$result["function"]=__FUNCTION__;
226 liveuser 8332
 
3 liveuser 8333
		#如果 $conf 不為陣列
8334
		if(gettype($conf)!="array"){
226 liveuser 8335
 
3 liveuser 8336
			#設置執行失敗
8337
			$result["status"]="false";
226 liveuser 8338
 
3 liveuser 8339
			#設置執行錯誤訊息
8340
			$result["error"][]="\$conf變數須為陣列形態";
8341
 
8342
			#如果傳入的參數為 null
8343
			if($conf==null){
226 liveuser 8344
 
3 liveuser 8345
				#設置執行錯誤訊息
8346
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 8347
 
3 liveuser 8348
				}#if end
8349
 
8350
			#回傳結果
8351
			return $result;
226 liveuser 8352
 
3 liveuser 8353
			}#if end
226 liveuser 8354
 
3 liveuser 8355
		#檢查參數
8356
		#函式說明:
8357
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8358
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8359
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8360
		#$result["function"],當前執行的函式名稱.
8361
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8362
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8363
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8364
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
8365
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8366
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8367
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8368
		#必填寫的參數:
8369
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8370
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8371
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8372
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 8373
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 8374
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
8375
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8376
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8377
		#可以省略的參數:
8378
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
8379
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8380
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8381
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noDotStart","noWaveEnd");
226 liveuser 8382
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 8383
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
8384
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8385
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","true");
8386
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8387
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
8388
		#參考資料來源:
8389
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8390
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8391
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 8392
 
3 liveuser 8393
		#如果 $checkResult["status"] 等於 "fasle"
8394
		if($checkResult["status"]==="false"){
226 liveuser 8395
 
3 liveuser 8396
			#設置錯誤識別
8397
			$result["status"]="false";
226 liveuser 8398
 
3 liveuser 8399
			#設置錯誤訊息
8400
			$result["error"]=$checkResult;
226 liveuser 8401
 
3 liveuser 8402
			#回傳結果
8403
			return $result;
226 liveuser 8404
 
3 liveuser 8405
			}#if end
226 liveuser 8406
 
3 liveuser 8407
		#如果 $checkResult["passed"] 等於 "fasle"
8408
		if($checkResult["passed"]==="false"){
226 liveuser 8409
 
3 liveuser 8410
			#設置錯誤識別
8411
			$result["status"]="false";
226 liveuser 8412
 
3 liveuser 8413
			#設置錯誤訊息
8414
			$result["error"]=$checkResult;
226 liveuser 8415
 
3 liveuser 8416
			#回傳結果
8417
			return $result;
226 liveuser 8418
 
3 liveuser 8419
			}#if end
226 liveuser 8420
 
3 liveuser 8421
		#轉換檔案路徑為相對於伺服器檔案系統的絕對路徑
8422
		#函式說明:
8423
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
8424
		#回傳結果:
8425
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8426
		#$result["error"],錯誤訊息陣列.
226 liveuser 8427
		#$result["function"],函數名稱.
3 liveuser 8428
		#$result["content"],網址.
8429
		#$result["localAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
8430
		#$result["fileSystemAbsoulutePosition"],針對伺服器檔案系統的絕對位置.
8431
		#必填參數:
8432
		#$conf["address"],字串,檔案的相對位置.
8433
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["path"];
8434
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8435
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
8436
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是.
8437
		$conf["fileAccess::getInternetAddress"]["userDir"]="true";
8438
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
8439
		unset($conf["fileAccess::getInternetAddress"]);
226 liveuser 8440
 
3 liveuser 8441
		#如果轉換路徑失敗
8442
		if($getInternetAddress["status"]=="false"){
226 liveuser 8443
 
3 liveuser 8444
			#設置錯誤識別
8445
			$result["status"]="false";
226 liveuser 8446
 
3 liveuser 8447
			#設置錯誤訊息
8448
			$result["error"]=$checkResult;
226 liveuser 8449
 
3 liveuser 8450
			#回傳結果
8451
			return $result;
226 liveuser 8452
 
3 liveuser 8453
			}#if end
226 liveuser 8454
 
3 liveuser 8455
		#取得轉換好的路徑
8456
		$conf["path"]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 8457
 
3 liveuser 8458
		#檢查檔案路徑字串是否含有「*」
8459
		#函式說明:
8460
		#檢查字串裡面有無指定的關鍵字
8461
		#回傳結果:
8462
		#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8463
		#$result["error"],錯誤訊息
8464
		#$result["function"],當前執行的函數名稱.
8465
		#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8466
		#$result["keyWordCount"],找到的關鍵字數量.
8467
		#必填參數:
8468
		$conf["search::findKeyWord"]["keyWord"]="*";#想要搜尋的關鍵字
8469
		$conf["search::findKeyWord"]["string"]=$conf["path"];#要被搜尋的字串內容
8470
		#可省略參數:
8471
		#$conf["fileAccess::findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8472
		$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8473
		unset($conf["search::findKeyWord"]);
226 liveuser 8474
 
3 liveuser 8475
		#如果尋找關鍵字出錯
8476
		if($findKeyWord["status"]=="false"){
226 liveuser 8477
 
3 liveuser 8478
			#設置錯誤識別
8479
			$result["status"]="false";
226 liveuser 8480
 
3 liveuser 8481
			#設置錯誤訊息
8482
			$result["error"]=$findKeyWord;
226 liveuser 8483
 
3 liveuser 8484
			#回傳結果
8485
			return $result;
226 liveuser 8486
 
3 liveuser 8487
			}#if end
226 liveuser 8488
 
3 liveuser 8489
		#如果含有「*」
8490
		if($findKeyWord["founded"]=="true"){
226 liveuser 8491
 
3 liveuser 8492
			#透過「/」分割路徑字串
8493
			#函式說明:
8494
			#將固定格式的字串分開,並回傳分開的結果。
8495
			#回傳的參數:
8496
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8497
			#$result["error"],錯誤訊息陣列
8498
			#$result["function"],當前執行的函數名稱.
8499
			#$result["oriStr"],要分割的原始字串內容
8500
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8501
			#$result["dataCounts"],爲總共分成幾段
8502
			#必填參數:
8503
			$conf["stringProcess::spiltString"]["stringIn"]=$conf["path"];#要處理的字串。
8504
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
8505
			$spiltPathStr=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8506
			unset($conf["stringProcess::spiltString"]);
226 liveuser 8507
 
3 liveuser 8508
			#如果分割字串失敗
8509
			if($spiltPathStr["status"]=="false"){
226 liveuser 8510
 
3 liveuser 8511
				#設置錯誤識別
8512
				$result["status"]="false";
226 liveuser 8513
 
3 liveuser 8514
				#設置錯誤訊息
8515
				$result["error"]=$spiltPathStr;
226 liveuser 8516
 
3 liveuser 8517
				#回傳結果
8518
				return $result;
226 liveuser 8519
 
3 liveuser 8520
				}#if end
226 liveuser 8521
 
3 liveuser 8522
			#初始化暫存展開後的檔案路徑字串
226 liveuser 8523
			$extendPath=array("");
8524
 
3 liveuser 8525
			#要解析的路徑分成幾段就執行幾次
8526
			foreach($spiltPathStr["dataArray"] as $pathPart){
226 liveuser 8527
 
3 liveuser 8528
				#檢查該段名稱是否有「*」
8529
				#函式說明:
8530
				#檢查字串裡面有無指定的關鍵字
8531
				#回傳結果:
8532
				#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8533
				#$result["error"],錯誤訊息
8534
				#$result["function"],當前執行的函數名稱.
8535
				#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8536
				#$result["keyWordCount"],找到的關鍵字數量.
8537
				#必填參數:
8538
				$conf["search::findKeyWord"]["keyWord"]="*";#想要搜尋的關鍵字
8539
				$conf["search::findKeyWord"]["string"]=$pathPart;#要被搜尋的字串內容
8540
				#可省略參數:
8541
				#$conf["fileAccess::findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8542
				$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8543
				unset($conf["search::findKeyWord"]);
226 liveuser 8544
 
3 liveuser 8545
				#如果尋找關鍵字出錯
8546
				if($findKeyWord["status"]=="false"){
226 liveuser 8547
 
3 liveuser 8548
					#設置錯誤識別
8549
					$result["status"]="false";
226 liveuser 8550
 
3 liveuser 8551
					#設置錯誤訊息
8552
					$result["error"]=$findKeyWord;
226 liveuser 8553
 
3 liveuser 8554
					#回傳結果
8555
					return $result;
226 liveuser 8556
 
8557
					}#if end
8558
 
3 liveuser 8559
				#如果不含「*」
8560
				if($findKeyWord["founded"]=="false"){
226 liveuser 8561
 
3 liveuser 8562
					#針對每個既有的路徑
8563
					for($i=0;$i<count($extendPath);$i++){
226 liveuser 8564
 
3 liveuser 8565
						#加上切割好的路徑
8566
						$extendPath[$i]=$extendPath[$i]."/".$pathPart;
226 liveuser 8567
 
3 liveuser 8568
						}#for end
226 liveuser 8569
 
3 liveuser 8570
					}#if end
226 liveuser 8571
 
8572
				#反之該段含有「*」
3 liveuser 8573
				else{
226 liveuser 8574
 
3 liveuser 8575
					#用「*」分割該段
8576
					#函式說明:
8577
					#將固定格式的字串分開,並回傳分開的結果。
8578
					#回傳的參數:
8579
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8580
					#$result["error"],錯誤訊息陣列
8581
					#$result["function"],當前執行的函數名稱.
8582
					#$result["oriStr"],要分割的原始字串內容
8583
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8584
					#$result["dataCounts"],爲總共分成幾段
8585
					#必填參數:
8586
					$conf["stringProcess::spiltString"]["stringIn"]=$pathPart;#要處理的字串。
8587
					$conf["stringProcess::spiltString"]["spiltSymbol"]="*";#爲以哪個符號作爲分割
8588
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8589
					unset($conf["stringProcess::spiltString"]);
226 liveuser 8590
 
3 liveuser 8591
					#如果分字串失敗
8592
					if($spiltString["status"]=="false"){
226 liveuser 8593
 
3 liveuser 8594
						#設置錯誤識別
8595
						$result["status"]="false";
226 liveuser 8596
 
3 liveuser 8597
						#設置錯誤訊息
8598
						$result["error"]=$spiltStringByStar;
226 liveuser 8599
 
3 liveuser 8600
						#回傳結果
8601
						return $result;
226 liveuser 8602
 
3 liveuser 8603
						}#if end
226 liveuser 8604
 
3 liveuser 8605
					#如果用「*」分割後的段數為0
8606
					if($spiltString["dataCounts"]==0){
226 liveuser 8607
 
3 liveuser 8608
						#初始化儲存符合條件的路徑
8609
						$newExtendPath=array();
226 liveuser 8610
 
3 liveuser 8611
						#代表沒有塞選條件
8612
						#當前有幾個符合條件的路徑就執行幾次
8613
						for($i=0;$i<count($extendPath);$i++){
226 liveuser 8614
 
3 liveuser 8615
							#取得該目錄下所有的東西
8616
							#取得該目錄底下的檔案目錄清單
8617
							#函式說明:
8618
							#取得目錄底下所有目錄與檔案清單.
8619
							#回傳結果:
8620
							#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8621
							#$result["error"],錯誤訊息陣列.
8622
							#$result["function"],函數名稱.
8623
							#$result["content"],陣列,目錄底下的檔案與子目錄.
8624
							#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
8625
							#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
8626
							#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
8627
							#$result["position"],目前的位置.
8628
							#必填參數:
8629
							#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
8630
							$conf["fileAccess::getList"]["position"]=$extendPath[$i];
8631
							#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8632
							$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
8633
							#可省略參數:
8634
							#無
8635
							#參考資料來源:
8636
							#opendir=>http://php.net/manual/en/function.opendir.php
8637
							#is_dir=>http://php.net/manual/en/function.is-dir.php
8638
							$getList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 8639
							unset($conf["fileAccess::getList"]);
8640
 
3 liveuser 8641
							#如果取得目標目錄底下的檔案目錄清單失敗
8642
							if($getList["status"]=="false"){
226 liveuser 8643
 
3 liveuser 8644
								#設置錯誤識別
8645
								$result["status"]="false";
226 liveuser 8646
 
3 liveuser 8647
								#設置錯誤訊息
226 liveuser 8648
								$result["error"]=$getList;
8649
 
3 liveuser 8650
								#回傳結果
8651
								return $result;
226 liveuser 8652
 
3 liveuser 8653
								}#if end
226 liveuser 8654
 
3 liveuser 8655
							#如果底下有東西
8656
							if(count($getList["content"])>0){
226 liveuser 8657
 
3 liveuser 8658
								#初始化儲存要檢查的檔案或資料夾名稱陣列
8659
								$list=array();
226 liveuser 8660
 
3 liveuser 8661
								#針對每個檔案或資料夾
8662
								foreach($getList["content"] as $num=>$array){
226 liveuser 8663
 
3 liveuser 8664
									#儲存該名稱
8665
									$list[]=$array["name"];
226 liveuser 8666
 
3 liveuser 8667
									}#foreach end
226 liveuser 8668
 
3 liveuser 8669
								#初始化儲存符合新條件字串的陣列
8670
								$tempExtendPath=array();
226 liveuser 8671
 
3 liveuser 8672
								#針對每個現有的路徑字串
8673
								for($j=0;$j<count($extendPath);$j++){
226 liveuser 8674
 
3 liveuser 8675
									#附加每個符合條件的名稱到路徑字串裡面
8676
									for($k=0;$k<count($list);$k++){
226 liveuser 8677
 
3 liveuser 8678
										#如果 $conf["noDotStart"] 為 "true"
8679
										if($conf["noDotStart"]==="true"){
226 liveuser 8680
 
3 liveuser 8681
											#將 $list[$k] 用 "/" 分割
8682
											#函式說明:
8683
											#將固定格式的字串分開,並回傳分開的結果。
8684
											#回傳結果:
8685
											#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8686
											#$result["error"],錯誤訊息陣列
8687
											#$result["function"],當前執行的函數名稱.
8688
											#$result["oriStr"],要分割的原始字串內容
8689
											#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8690
											#$result["dataCounts"],爲總共分成幾段
8691
											#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
8692
											#必填參數:
8693
											$conf["stringProcess::spiltString"]["stringIn"]=$list[$k];#要處理的字串。
8694
											$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
8695
											#可省略參數:
8696
											#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
8697
											$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
8698
											$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8699
											unset($conf["stringProcess::spiltString"]);
226 liveuser 8700
 
3 liveuser 8701
											#如果分割路徑失敗
8702
											if($spiltString["status"]==="false"){
226 liveuser 8703
 
3 liveuser 8704
												#設置執行錯誤識別
8705
												$result["status"]="false";
226 liveuser 8706
 
3 liveuser 8707
												#取得錯誤訊息
8708
												$result["error"]=$spiltString;
226 liveuser 8709
 
3 liveuser 8710
												#回傳結果
8711
												return $result;
226 liveuser 8712
 
3 liveuser 8713
												}#if end
226 liveuser 8714
 
3 liveuser 8715
											#如果有關鍵字「/」存在
8716
											if($spiltString["found"]==="true"){
226 liveuser 8717
 
3 liveuser 8718
												#針對每個段落
8719
												foreach($spiltString["dataArray"] as $pp){
226 liveuser 8720
 
3 liveuser 8721
													#看該符合的名稱開頭是否包含「.」
8722
													#函式說明:
8723
													#取得符合特定字首與字尾的字串
8724
													#回傳結果:
8725
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8726
													#$result["function"],當前執行的函數名稱.
8727
													#$result["error"],錯誤訊息陣列.
8728
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8729
													#$result["returnString"],爲符合字首條件的字串內容。
8730
													#必填參數:
8731
													#$conf["checkString"],字串,要檢查的字串.
8732
													$conf["search::getMeetConditionsString"]["checkString"]=$pp;
8733
													#可省略參數:
8734
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8735
													$conf["search::getMeetConditionsString"]["frontWord"]=".";
8736
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8737
													#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
8738
													#參考資料:
8739
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8740
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8741
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 8742
 
3 liveuser 8743
													#如果 取得符合特定字首的字串 出錯
8744
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 8745
 
3 liveuser 8746
														#設置執行錯誤識別
8747
														$result["status"]="false";
226 liveuser 8748
 
3 liveuser 8749
														#設置錯誤訊息
8750
														$result["error"]=$getMeetConditionsString;
226 liveuser 8751
 
3 liveuser 8752
														#回傳結果
8753
														return $result;
226 liveuser 8754
 
3 liveuser 8755
														}#if end
226 liveuser 8756
 
3 liveuser 8757
													#如果有「.」在開頭
8758
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8759
 
8760
														#忽略這個名稱
3 liveuser 8761
														continue 2;
226 liveuser 8762
 
3 liveuser 8763
														}#if end
226 liveuser 8764
 
3 liveuser 8765
													}#foreach end
226 liveuser 8766
 
3 liveuser 8767
												}#if end
226 liveuser 8768
 
3 liveuser 8769
											#反之沒有關鍵字「/」存在
8770
											else{
226 liveuser 8771
 
3 liveuser 8772
												#看該符合的名稱開頭是否包含「.」
8773
												#函式說明:
8774
												#取得符合特定字首與字尾的字串
8775
												#回傳結果:
8776
												#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8777
												#$result["function"],當前執行的函數名稱.
8778
												#$result["error"],錯誤訊息陣列.
8779
												#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8780
												#$result["returnString"],爲符合字首條件的字串內容。
8781
												#必填參數:
8782
												#$conf["checkString"],字串,要檢查的字串.
8783
												$conf["search::getMeetConditionsString"]["checkString"]=$list[$k];
8784
												#可省略參數:
8785
												#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8786
												$conf["search::getMeetConditionsString"]["frontWord"]=".";
8787
												#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8788
												#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
8789
												#參考資料:
8790
												#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8791
												$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8792
												unset($conf["search::getMeetConditionsString"]);
226 liveuser 8793
 
3 liveuser 8794
												#如果 取得符合特定字首的字串 出錯
8795
												if($getMeetConditionsString["status"]=="false"){
226 liveuser 8796
 
3 liveuser 8797
													#設置執行錯誤識別
8798
													$result["status"]="false";
226 liveuser 8799
 
3 liveuser 8800
													#設置錯誤訊息
8801
													$result["error"]=$getMeetConditionsString;
226 liveuser 8802
 
3 liveuser 8803
													#回傳結果
8804
													return $result;
226 liveuser 8805
 
3 liveuser 8806
													}#if end
226 liveuser 8807
 
3 liveuser 8808
												#如果有「.」在開頭
8809
												if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8810
 
8811
													#忽略這個名稱
3 liveuser 8812
													continue;
226 liveuser 8813
 
3 liveuser 8814
													}#if end
226 liveuser 8815
 
3 liveuser 8816
												}#else end
226 liveuser 8817
 
3 liveuser 8818
											}#if end
226 liveuser 8819
 
3 liveuser 8820
										#如果 $conf["noWaveEnd"] 為 "true"
8821
										if($conf["noWaveEnd"]==="true"){
226 liveuser 8822
 
3 liveuser 8823
											#看該符合的名稱結尾是否包含「~」
8824
											#函式說明:
8825
											#取得符合特定字首與字尾的字串
8826
											#回傳結果:
8827
											#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8828
											#$result["function"],當前執行的函數名稱.
8829
											#$result["error"],錯誤訊息陣列.
8830
											#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8831
											#$result["returnString"],爲符合字首條件的字串內容。
8832
											#必填參數:
8833
											#$conf["checkString"],字串,要檢查的字串.
8834
											$conf["search::getMeetConditionsString"]["checkString"]=$list[$k];
8835
											#可省略參數:
8836
											#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8837
											#$conf["search::getMeetConditionsString"]["frontWord"]=".";
8838
											#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8839
											$conf["search::getMeetConditionsString"]["tailWord"]="~";
8840
											#參考資料:
8841
											#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8842
											$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8843
											unset($conf["search::getMeetConditionsString"]);
226 liveuser 8844
 
3 liveuser 8845
											#如果 取得符合特定字首的字串 出錯
8846
											if($getMeetConditionsString["status"]=="false"){
226 liveuser 8847
 
3 liveuser 8848
												#設置執行錯誤識別
8849
												$result["status"]="false";
226 liveuser 8850
 
3 liveuser 8851
												#設置錯誤訊息
8852
												$result["error"]=$getMeetConditionsString;
226 liveuser 8853
 
3 liveuser 8854
												#回傳結果
8855
												return $result;
226 liveuser 8856
 
3 liveuser 8857
												}#if end
226 liveuser 8858
 
3 liveuser 8859
											#如果有「~」在結尾
8860
											if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8861
 
3 liveuser 8862
												#忽略這個名稱
8863
												continue;
226 liveuser 8864
 
3 liveuser 8865
												}#if end
226 liveuser 8866
 
3 liveuser 8867
											}#if end
226 liveuser 8868
 
3 liveuser 8869
										#暫存該符合的路徑
8870
										$tempExtendPath[]=$extendPath[$j]."/".$list[$k];
226 liveuser 8871
 
3 liveuser 8872
										}#for end
226 liveuser 8873
 
8874
									}#for end
8875
 
3 liveuser 8876
								#該次有幾個符合的路徑就執行幾次
8877
								foreach($tempExtendPath as $path){
226 liveuser 8878
 
3 liveuser 8879
									#暫存符合的路徑
8880
									$newExtendPath[]=$path;
226 liveuser 8881
 
8882
									}#for end
8883
 
3 liveuser 8884
								}#if end
226 liveuser 8885
 
3 liveuser 8886
							#反之該目錄底下沒有東西
8887
							else{
226 liveuser 8888
 
3 liveuser 8889
								#移除該 $extendPath[$i]
8890
								unset($extendPath[$i]);
226 liveuser 8891
 
8892
								}#else end
8893
 
3 liveuser 8894
							}#for end
226 liveuser 8895
 
3 liveuser 8896
						#置換原始符合條件字串的路徑字串陣列
8897
						$extendPath=$newExtendPath;
226 liveuser 8898
 
3 liveuser 8899
						}#if end
226 liveuser 8900
 
3 liveuser 8901
						#反之用「*」分割後有分段
8902
						else{
226 liveuser 8903
 
3 liveuser 8904
							#初始化暫存符合條件的新路徑陣列變數
8905
							$newExtendPath=array();
226 liveuser 8906
 
3 liveuser 8907
							#當前有幾個符合條件的路徑就執行幾次
8908
							for($i=0;$i<count($extendPath);$i++){
226 liveuser 8909
 
3 liveuser 8910
								#取得該目錄下所有的東西
8911
								#函式說明:
8912
								#取得目錄底下所有目錄與檔案清單.
8913
								#回傳結果:
8914
								#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8915
								#$result["error"],錯誤訊息陣列.
8916
								#$result["function"],函數名稱.
8917
								#$result["content"],陣列,目錄底下的檔案與子目錄.
8918
								#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
8919
								#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
8920
								#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
8921
								#$result["position"],目前的位置.
8922
								#必填參數:
8923
								#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
8924
								$conf["fileAccess::getList"]["position"]=$extendPath[$i];
8925
								#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8926
								$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
8927
								#可省略參數:
8928
								#無
8929
								#參考資料來源:
8930
								#opendir=>http://php.net/manual/en/function.opendir.php
8931
								#is_dir=>http://php.net/manual/en/function.is-dir.php
8932
								$getList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 8933
								unset($conf["fileAccess::getList"]);
8934
 
3 liveuser 8935
								#如果取得目標目錄底下的檔案目錄清單失敗
8936
								if($getList["status"]=="false"){
226 liveuser 8937
 
3 liveuser 8938
									#設置錯誤識別
8939
									$result["status"]="false";
226 liveuser 8940
 
3 liveuser 8941
									#設置錯誤訊息
226 liveuser 8942
									$result["error"]=$getList;
8943
 
3 liveuser 8944
									#回傳結果
8945
									return $result;
226 liveuser 8946
 
3 liveuser 8947
									}#if end
226 liveuser 8948
 
3 liveuser 8949
								#如果底下有東西
8950
								if(count($getList["content"])>0){
226 liveuser 8951
 
3 liveuser 8952
									#初始化儲存要檢查的檔案或資料夾名稱陣列
8953
									$list=array();
226 liveuser 8954
 
3 liveuser 8955
									#針對每個檔案或資料夾
8956
									foreach($getList["content"] as $num=>$array){
226 liveuser 8957
 
3 liveuser 8958
										#儲存該名稱
8959
										$list[]=$array["name"];
226 liveuser 8960
 
3 liveuser 8961
										}#foreach end
226 liveuser 8962
 
3 liveuser 8963
									#初始化儲存符合的名稱
8964
									$passedName=array();
226 liveuser 8965
 
3 liveuser 8966
									#依據每個檔案目錄名稱,檢查有無符合篩選條件
8967
									foreach($list as $filteredName){
226 liveuser 8968
 
3 liveuser 8969
										#初始化儲存被檢查的片段檔案資料夾名稱
8970
										$partName=$filteredName;
226 liveuser 8971
 
3 liveuser 8972
										#依據 $pathPart 分割成幾段(關鍵字數量)就執行幾次
8973
										for($i=0;$i<$spiltString["dataCounts"];$i++){
226 liveuser 8974
 
3 liveuser 8975
											#尋找關鍵字 $spiltString["dataArray"][$i]
8976
											#函式說明:
8977
											#檢查字串裡面有無指定的關鍵字
8978
											#回傳結果:
8979
											#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8980
											#$result["error"],錯誤訊息
8981
											#$result["function"],當前執行的函數名稱.
8982
											#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8983
											#$result["keyWordCount"],找到的關鍵字數量.
8984
											#必填參數:
8985
											$conf["search::findKeyWord"]["keyWord"]=$spiltString["dataArray"][$i];#想要搜尋的關鍵字
8986
											$conf["search::findKeyWord"]["string"]=$partName;#要被搜尋的字串內容
8987
											#可省略參數:
8988
											#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8989
											$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8990
											unset($conf["search::findKeyWord"]);
226 liveuser 8991
 
3 liveuser 8992
											#如果尋找關鍵字失敗
8993
											if($findKeyWord["status"]=="false"){
226 liveuser 8994
 
3 liveuser 8995
												#設置執行錯誤識別
8996
												$result["status"]="false";
226 liveuser 8997
 
3 liveuser 8998
												#設置錯誤訊息
8999
												$result["error"]=$findKeyWord;
226 liveuser 9000
 
3 liveuser 9001
												#回傳結果
9002
												return $result;
226 liveuser 9003
 
3 liveuser 9004
												}#if end
226 liveuser 9005
 
3 liveuser 9006
											#如果有找到關鍵字
9007
											if($findKeyWord["founded"]=="true"){
226 liveuser 9008
 
3 liveuser 9009
												#如果是最後一段要檢查的關鍵字
9010
												if($i==$spiltString["dataCounts"]-1){
226 liveuser 9011
 
3 liveuser 9012
													#判斷該關鍵字是否在該未分割的 $pathPart(含有*字號的關鍵字字串) 的開頭
9013
													#函式說明:
9014
													#取得符合特定字首與字尾的字串
9015
													#回傳結果:
9016
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9017
													#$result["function"],當前執行的函數名稱.
9018
													#$result["error"],錯誤訊息陣列.
9019
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9020
													#$result["returnString"],爲符合字首條件的字串內容。
9021
													#必填參數:
9022
													#$conf["checkString"],字串,要檢查的字串.
9023
													$conf["search::getMeetConditionsString"]["checkString"]=$pathPart;
9024
													#可省略參數:
9025
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9026
													$conf["search::getMeetConditionsString"]["frontWord"]=$spiltString["dataArray"][0];
9027
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9028
													#$conf["tailWord"]="";
9029
													#參考資料:
9030
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9031
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9032
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 9033
 
3 liveuser 9034
													#如果 取得符合特定字首的字串 出錯
9035
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 9036
 
3 liveuser 9037
														#設置執行錯誤識別
9038
														$result["status"]="false";
226 liveuser 9039
 
3 liveuser 9040
														#設置錯誤訊息
9041
														$result["error"]=$getMeetConditionsString;
226 liveuser 9042
 
3 liveuser 9043
														#回傳結果
9044
														return $result;
226 liveuser 9045
 
3 liveuser 9046
														}#if end
226 liveuser 9047
 
3 liveuser 9048
													#如果關鍵字是在開頭
9049
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9050
 
3 liveuser 9051
														#判斷關鍵字是否在該檔案目錄名稱的開頭
9052
														#函式說明:
9053
														#取得符合特定字首與字尾的字串
9054
														#回傳結果:
9055
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9056
														#$result["function"],當前執行的函數名稱.
9057
														#$result["error"],錯誤訊息陣列.
9058
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9059
														#$result["returnString"],爲符合字首條件的字串內容。
9060
														#必填參數:
9061
														#$conf["checkString"],字串,要檢查的字串.
9062
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9063
														#可省略參數:
9064
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9065
														$conf["search::getMeetConditionsString"]["frontWord"]=$spiltString["dataArray"][0];
9066
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9067
														#$conf["tailWord"]="";
9068
														#參考資料:
9069
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9070
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9071
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9072
 
3 liveuser 9073
														#如果 取得符合特定字首的字串 出錯
9074
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9075
 
3 liveuser 9076
															#設置執行錯誤識別
9077
															$result["status"]="false";
226 liveuser 9078
 
3 liveuser 9079
															#設置錯誤訊息
9080
															$result["error"]=$getMeetConditionsString;
226 liveuser 9081
 
3 liveuser 9082
															#回傳結果
9083
															return $result;
226 liveuser 9084
 
3 liveuser 9085
															}#if end
226 liveuser 9086
 
3 liveuser 9087
														#如果關鍵字不在開頭
9088
														if($getMeetConditionsString["founded"]=="false"){
226 liveuser 9089
 
3 liveuser 9090
															#不符合條件,跳過該檔案目錄名稱
9091
															break;
226 liveuser 9092
 
3 liveuser 9093
															}#if end
226 liveuser 9094
 
3 liveuser 9095
														}#if end
226 liveuser 9096
 
3 liveuser 9097
													#判斷最後一個關鍵字是否在該未分割的 $pathPart(含有*字號的關鍵字字串) 的結尾
9098
													#函式說明:
9099
													#取得符合特定字首與字尾的字串
9100
													#回傳結果:
9101
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9102
													#$result["function"],當前執行的函數名稱.
9103
													#$result["error"],錯誤訊息陣列.
9104
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9105
													#$result["returnString"],爲符合字首條件的字串內容。
9106
													#必填參數:
9107
													#$conf["checkString"],字串,要檢查的字串.
9108
													$conf["search::getMeetConditionsString"]["checkString"]=$pathPart;
9109
													#可省略參數:
9110
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9111
													#$conf["search::getMeetConditionsString"]["frontWord"]=$partName;
9112
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9113
													$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9114
													#參考資料:
9115
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9116
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9117
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 9118
 
3 liveuser 9119
													#如果 取得符合特定字尾的字串 出錯
9120
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 9121
 
3 liveuser 9122
														#設置執行錯誤識別
9123
														$result["status"]="false";
226 liveuser 9124
 
3 liveuser 9125
														#設置錯誤訊息
9126
														$result["error"]=$getMeetConditionsString;
226 liveuser 9127
 
3 liveuser 9128
														#回傳結果
9129
														return $result;
226 liveuser 9130
 
3 liveuser 9131
														}#if end
226 liveuser 9132
 
3 liveuser 9133
													#如果關鍵字是在字尾
9134
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9135
 
3 liveuser 9136
														#判斷關鍵字是否在該片段的開頭
9137
														#函式說明:
9138
														#取得符合特定字首與字尾的字串
9139
														#回傳結果:
9140
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9141
														#$result["function"],當前執行的函數名稱.
9142
														#$result["error"],錯誤訊息陣列.
9143
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9144
														#$result["returnString"],爲符合字首條件的字串內容。
9145
														#必填參數:
9146
														#$conf["checkString"],字串,要檢查的字串.
9147
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9148
														#可省略參數:
9149
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9150
														#$conf["search::getMeetConditionsString"]["frontWord"]=$partName;
9151
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9152
														$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9153
														#參考資料:
9154
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9155
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9156
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9157
 
3 liveuser 9158
														#如果 取得符合特定字首的字串 出錯
9159
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9160
 
3 liveuser 9161
															#設置執行錯誤識別
9162
															$result["status"]="false";
226 liveuser 9163
 
3 liveuser 9164
															#設置錯誤訊息
9165
															$result["error"]=$getMeetConditionsString;
226 liveuser 9166
 
3 liveuser 9167
															#回傳結果
9168
															return $result;
226 liveuser 9169
 
3 liveuser 9170
															}#if end
226 liveuser 9171
 
3 liveuser 9172
														#如果關鍵字不在結尾
9173
														if($getMeetConditionsString["founded"]=="false"){
226 liveuser 9174
 
3 liveuser 9175
															#不符合條件,跳過該檔案目錄名稱
9176
															break;
226 liveuser 9177
 
3 liveuser 9178
															}#if end
226 liveuser 9179
 
3 liveuser 9180
														}#if end
226 liveuser 9181
 
3 liveuser 9182
													#如果 $conf["noDotStart"] 為 "true"
9183
													if($conf["noDotStart"]==="true"){
226 liveuser 9184
 
3 liveuser 9185
														#看該符合的名稱開頭是否包含「.」
9186
														#函式說明:
9187
														#取得符合特定字首與字尾的字串
9188
														#回傳結果:
9189
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9190
														#$result["function"],當前執行的函數名稱.
9191
														#$result["error"],錯誤訊息陣列.
9192
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9193
														#$result["returnString"],爲符合字首條件的字串內容。
9194
														#必填參數:
9195
														#$conf["checkString"],字串,要檢查的字串.
9196
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9197
														#可省略參數:
9198
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9199
														$conf["search::getMeetConditionsString"]["frontWord"]=".";
9200
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9201
														#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9202
														#參考資料:
9203
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9204
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9205
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9206
 
3 liveuser 9207
														#如果 取得符合特定字首的字串 出錯
9208
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9209
 
3 liveuser 9210
															#設置執行錯誤識別
9211
															$result["status"]="false";
226 liveuser 9212
 
3 liveuser 9213
															#設置錯誤訊息
9214
															$result["error"]=$getMeetConditionsString;
226 liveuser 9215
 
3 liveuser 9216
															#回傳結果
9217
															return $result;
226 liveuser 9218
 
3 liveuser 9219
															}#if end
226 liveuser 9220
 
3 liveuser 9221
														#如果有「.」在開頭
9222
														if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9223
 
3 liveuser 9224
															#中斷迴圈
9225
															break;
226 liveuser 9226
 
3 liveuser 9227
															}#if end
226 liveuser 9228
 
3 liveuser 9229
														}#if end
226 liveuser 9230
 
3 liveuser 9231
													#如果 $conf["noWaveEnd"] 為 "true"
9232
													if($conf["noWaveEnd"]==="true"){
226 liveuser 9233
 
3 liveuser 9234
														#看該符合的名稱結尾是否包含「~」
9235
														#函式說明:
9236
														#取得符合特定字首與字尾的字串
9237
														#回傳結果:
9238
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9239
														#$result["function"],當前執行的函數名稱.
9240
														#$result["error"],錯誤訊息陣列.
9241
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9242
														#$result["returnString"],爲符合字首條件的字串內容。
9243
														#必填參數:
9244
														#$conf["checkString"],字串,要檢查的字串.
9245
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9246
														#可省略參數:
9247
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9248
														#$conf["search::getMeetConditionsString"]["frontWord"]=".";
9249
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9250
														$conf["search::getMeetConditionsString"]["tailWord"]="~";
9251
														#參考資料:
9252
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9253
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9254
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9255
 
3 liveuser 9256
														#如果 取得符合特定字首的字串 出錯
9257
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9258
 
3 liveuser 9259
															#設置執行錯誤識別
9260
															$result["status"]="false";
226 liveuser 9261
 
3 liveuser 9262
															#設置錯誤訊息
9263
															$result["error"]=$getMeetConditionsString;
226 liveuser 9264
 
3 liveuser 9265
															#回傳結果
9266
															return $result;
226 liveuser 9267
 
3 liveuser 9268
															}#if end
226 liveuser 9269
 
3 liveuser 9270
														#如果有「~」在結尾
9271
														if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9272
 
3 liveuser 9273
															#中斷迴圈
9274
															break;
226 liveuser 9275
 
3 liveuser 9276
															}#if end
226 liveuser 9277
 
3 liveuser 9278
														}#if end
226 liveuser 9279
 
3 liveuser 9280
													#取得該符合的名稱
9281
													$passedName[]=$filteredName;
226 liveuser 9282
 
3 liveuser 9283
													#中斷迴圈
9284
													break;
226 liveuser 9285
 
3 liveuser 9286
													}#if end
226 liveuser 9287
 
3 liveuser 9288
												#將 $partName 從左到關鍵字結束的部份剔除
9289
												#函式說明:
9290
												#將特定字串前面的內容剔除
9291
												#回傳結果:
9292
												#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9293
												#$result["error"],錯誤訊息陣列.
9294
												#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
9295
												#$result["function"],當前執行的函數名稱.
9296
												#$result["oriStr"],要處理的原始字串內容.
9297
												#$result["content"],處理好的的字串內容.
9298
												#必填參數:
9299
												$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$partName;#要處理的字串.
9300
												$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$spiltString["dataArray"][$i];#特定字串.
9301
												$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
9302
												unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 9303
 
3 liveuser 9304
												#如果將 $partName 從左到關鍵字結束的部份剔除失敗
9305
												if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 9306
 
3 liveuser 9307
													#設置執行錯誤識別
9308
													$result["status"]="false";
226 liveuser 9309
 
3 liveuser 9310
													#設置錯誤訊息
9311
													$result["error"]=$delStrBeforeKeyWord;
226 liveuser 9312
 
3 liveuser 9313
													#回傳結果
9314
													return $result;
226 liveuser 9315
 
3 liveuser 9316
													}#if end
226 liveuser 9317
 
3 liveuser 9318
												#如果沒有找到特定關鍵字字串
9319
												if($delStrBeforeKeyWord["founded"]=="false"){
226 liveuser 9320
 
3 liveuser 9321
													#設置執行錯誤識別
9322
													$result["status"]="false";
226 liveuser 9323
 
3 liveuser 9324
													#設置錯誤訊息
9325
													$result["error"]=$delStrBeforeKeyWord;
226 liveuser 9326
 
3 liveuser 9327
													#回傳結果
9328
													return $result;
226 liveuser 9329
 
3 liveuser 9330
													}#if end
226 liveuser 9331
 
9332
												#取得剔除過關鍵字前字串的字串
3 liveuser 9333
												$partName=$delStrBeforeKeyWord["content"];
226 liveuser 9334
 
3 liveuser 9335
												}#if end
226 liveuser 9336
 
9337
											#反之關鍵字不存在
3 liveuser 9338
											else{
226 liveuser 9339
 
3 liveuser 9340
												#儲存被拋棄的片段
9341
												#$result["dismissLog"][]="片段「".$partName."」沒有關鍵字「".$spiltString["dataArray"][$i]."」";
226 liveuser 9342
 
3 liveuser 9343
												#該名稱不符合條件
9344
												break;
226 liveuser 9345
 
3 liveuser 9346
												}#else end
226 liveuser 9347
 
3 liveuser 9348
											}#for end
226 liveuser 9349
 
3 liveuser 9350
										}#foreach end
226 liveuser 9351
 
3 liveuser 9352
									#初始化儲存符合的暫存路徑
9353
									$tempExtendPath=array();
226 liveuser 9354
 
3 liveuser 9355
									#針對每個現有的路徑字串
9356
									for($j=0;$j<count($extendPath);$j++){
226 liveuser 9357
 
3 liveuser 9358
										#附加每個符合條件的名稱到路徑字串裡面
9359
										for($k=0;$k<count($passedName);$k++){
226 liveuser 9360
 
3 liveuser 9361
											#暫存該符合的路徑
9362
											$tempExtendPath[]=$extendPath[$j]."/".$passedName[$k];
226 liveuser 9363
 
3 liveuser 9364
											}#for end
226 liveuser 9365
 
9366
										}#for end
9367
 
3 liveuser 9368
									#該次有幾個符合的路徑就執行幾次
9369
									foreach($tempExtendPath as $path){
226 liveuser 9370
 
3 liveuser 9371
										#暫存符合的路徑
9372
										$newExtendPath[]=$path;
226 liveuser 9373
 
9374
										}#foreach end
9375
 
3 liveuser 9376
									}#if end
226 liveuser 9377
 
3 liveuser 9378
								#反之該目錄底下沒有東西
9379
								else{
226 liveuser 9380
 
3 liveuser 9381
									#移除該 $extendPath[$i]
9382
									unset($extendPath[$i]);
226 liveuser 9383
 
9384
									}#else end
9385
 
3 liveuser 9386
								}#for end
226 liveuser 9387
 
3 liveuser 9388
							#如果有新的路徑產生
9389
							if(count($newExtendPath)>0){
226 liveuser 9390
 
3 liveuser 9391
								#置換原始符合條件字串的路徑字串陣列
9392
								$extendPath=$newExtendPath;
226 liveuser 9393
 
3 liveuser 9394
								}#if end
226 liveuser 9395
 
3 liveuser 9396
							#反之找不到後續符合的路徑
9397
							else{
226 liveuser 9398
 
3 liveuser 9399
								$extendPath=array();
226 liveuser 9400
 
3 liveuser 9401
								}#else end
226 liveuser 9402
 
3 liveuser 9403
							}#else end
226 liveuser 9404
 
3 liveuser 9405
					}#else end
226 liveuser 9406
 
3 liveuser 9407
				}#foreach end
226 liveuser 9408
 
3 liveuser 9409
			}#if end
226 liveuser 9410
 
3 liveuser 9411
		#反之沒有含有「*」
9412
		else{
226 liveuser 9413
 
3 liveuser 9414
			#判斷 $conf["path"] 是否存在
9415
			#函式說明:
9416
			#檢查多個檔案與資料夾是否存在.
9417
			#回傳的結果:
9418
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
9419
			#$result["error"],錯誤訊息陣列.
9420
			#$resutl["function"],當前執行的涵式名稱.
9421
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
9422
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
9423
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
9424
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
9425
			#必填參數:
9426
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
9427
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["path"]);
9428
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9429
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
9430
			#可省略參數
9431
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
9432
			#$conf["disableWebSearch"]="false";
9433
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
9434
			#$conf["userDir"]="true";
9435
			#參考資料來源:
9436
			#http://php.net/manual/en/function.file-exists.php
9437
			#http://php.net/manual/en/control-structures.foreach.php
9438
			#備註:
9439
			#函數file_exists檢查的路徑為檔案系統的路徑
9440
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
9441
			unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 9442
 
3 liveuser 9443
			#如果檢查失敗
9444
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 9445
 
3 liveuser 9446
				#設置錯誤識別
9447
				$result["status"]="false";
226 liveuser 9448
 
3 liveuser 9449
				#設置錯誤訊息
9450
				$result["error"]=$checkMultiFileExist;
226 liveuser 9451
 
3 liveuser 9452
				#回傳結果
9453
				return $result;
226 liveuser 9454
 
3 liveuser 9455
				}#if end
226 liveuser 9456
 
3 liveuser 9457
			#如果存在
9458
			if($checkMultiFileExist["varExist"][0]=="true"){
226 liveuser 9459
 
3 liveuser 9460
				#初始化暫存展開後的檔案路徑字串
9461
				$extendPath=array($conf["path"]);
226 liveuser 9462
 
3 liveuser 9463
				}#if end
226 liveuser 9464
 
3 liveuser 9465
			#反之不存在
9466
			else{
226 liveuser 9467
 
3 liveuser 9468
				#置換符合的路徑為空字串
9469
				$extendPath=array();
226 liveuser 9470
 
3 liveuser 9471
				}#else end
226 liveuser 9472
 
3 liveuser 9473
			#初始化暫存展開後的檔案路徑字串
9474
			$extendPath=array($conf["path"]);
226 liveuser 9475
 
3 liveuser 9476
			}#else end
226 liveuser 9477
 
3 liveuser 9478
		#取得解析完「*」的檔案路徑字串
9479
		$result["content"]=$extendPath;
226 liveuser 9480
 
3 liveuser 9481
		#取得有幾個檔案路徑
9482
		$result["pathCount"]=count($result["content"]);
226 liveuser 9483
 
3 liveuser 9484
		#設置執行正常
9485
		$result["status"]="true";
226 liveuser 9486
 
3 liveuser 9487
		#回傳結果
9488
		return $result;
226 liveuser 9489
 
3 liveuser 9490
		}#function resolvePostionStringWhichContainStarSymbol end
9491
 
9492
	/*
9493
	#函式說明:
9494
	#將含有「*」的多個檔案路徑名稱,變成多個符合條件的路徑檔案.
9495
	#回傳結果:
9496
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9497
	#$result["error"],錯誤訊息陣列.
226 liveuser 9498
	#$result["function"],函數名稱.
3 liveuser 9499
	#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
9500
	#$result["pathCount"],整數,有幾個路徑.
9501
	#必填參數:
9502
	#$conf["path"],字串陣列,要解析含有「*」的檔案路徑字串.
9503
	$conf["path"]=array();
9504
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
9505
	$conf["fileArgu"]=__FILE__;
9506
	#可省略參數:
9507
	#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
9508
	#$conf["noDotStart"]="true";
9509
	#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
9510
	#$conf["noWaveEnd"]="true";
9511
	#參考資料:
9512
	#無.
9513
	#備註:
9514
	#無.
9515
	*/
9516
	public static function resolveMultiPostionStringWhichContainStarSymbol(&$conf){
226 liveuser 9517
 
3 liveuser 9518
		#初始化要回傳的結果
9519
		$result=array();
226 liveuser 9520
 
3 liveuser 9521
		#設置當其函數名稱
9522
		$result["function"]=__FUNCTION__;
226 liveuser 9523
 
3 liveuser 9524
		#如果 $conf 不為陣列
9525
		if(gettype($conf)!="array"){
226 liveuser 9526
 
3 liveuser 9527
			#設置執行失敗
9528
			$result["status"]="false";
226 liveuser 9529
 
3 liveuser 9530
			#設置執行錯誤訊息
9531
			$result["error"][]="\$conf變數須為陣列形態";
9532
 
9533
			#如果傳入的參數為 null
9534
			if($conf==null){
226 liveuser 9535
 
3 liveuser 9536
				#設置執行錯誤訊息
9537
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 9538
 
3 liveuser 9539
				}#if end
9540
 
9541
			#回傳結果
9542
			return $result;
226 liveuser 9543
 
3 liveuser 9544
			}#if end
226 liveuser 9545
 
3 liveuser 9546
		#檢查參數
9547
		#函式說明:
9548
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
9549
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9550
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9551
		#$result["function"],當前執行的函式名稱.
9552
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9553
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9554
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9555
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
9556
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9557
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9558
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9559
		#必填寫的參數:
9560
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9561
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9562
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9563
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 9564
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 9565
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
9566
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9567
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9568
		#可以省略的參數:
9569
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
9570
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9571
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9572
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noDotStart","noWaveEnd");
226 liveuser 9573
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 9574
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
9575
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9576
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","true");
9577
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9578
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
9579
		#參考資料來源:
9580
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9581
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9582
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 9583
 
3 liveuser 9584
		#如果 $checkResult["status"] 等於 "fasle"
9585
		if($checkResult["status"]=="false"){
226 liveuser 9586
 
3 liveuser 9587
			#設置錯誤識別
9588
			$result["status"]="false";
226 liveuser 9589
 
3 liveuser 9590
			#設置錯誤訊息
9591
			$result["error"]=$checkResult;
226 liveuser 9592
 
3 liveuser 9593
			#回傳結果
9594
			return $result;
226 liveuser 9595
 
3 liveuser 9596
			}#if end
226 liveuser 9597
 
3 liveuser 9598
		#如果 $checkResult["passed"] 等於 "fasle"
9599
		if($checkResult["passed"]=="false"){
226 liveuser 9600
 
3 liveuser 9601
			#設置錯誤識別
9602
			$result["status"]="false";
226 liveuser 9603
 
3 liveuser 9604
			#設置錯誤訊息
9605
			$result["error"]=$checkResult;
226 liveuser 9606
 
3 liveuser 9607
			#回傳結果
9608
			return $result;
226 liveuser 9609
 
3 liveuser 9610
			}#if end
226 liveuser 9611
 
3 liveuser 9612
		#針對每個要解析的路徑字串
9613
		foreach($conf["path"] as $path){
226 liveuser 9614
 
3 liveuser 9615
			#函式說明:
9616
			#將含有「*」的檔案路徑名稱,變成多個符合條件的路徑檔案.
9617
			#回傳結果:
9618
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9619
			#$result["error"],錯誤訊息陣列.
226 liveuser 9620
			#$result["function"],函數名稱.
3 liveuser 9621
			#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
9622
			#必填參數:
9623
			#$conf["path"],字串,要解析含有「*」的檔案路徑字串.
9624
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["path"]=$path;
9625
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
9626
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["fileArgu"]=$conf["fileArgu"];
9627
			#可省略參數:
9628
			#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
9629
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["noDotStart"]=$conf["noDotStart"];
9630
			#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
9631
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["noWaveEnd"]=$conf["noWaveEnd"];
9632
			$resolvePostionStringWhichContainStarSymbol=fileAccess::resolvePostionStringWhichContainStarSymbol($conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]);
9633
			unset($conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]);
226 liveuser 9634
 
3 liveuser 9635
			#如果解析失敗
9636
			if($resolvePostionStringWhichContainStarSymbol["status"]=="false"){
226 liveuser 9637
 
3 liveuser 9638
				#設置錯誤識別
9639
				$result["status"]="false";
226 liveuser 9640
 
3 liveuser 9641
				#設置錯誤訊息
9642
				$result["error"]=$resolvePostionStringWhichContainStarSymbol;
226 liveuser 9643
 
3 liveuser 9644
				#回傳結果
9645
				return $result;
226 liveuser 9646
 
3 liveuser 9647
				}#if end
226 liveuser 9648
 
3 liveuser 9649
			#針對每個解析出來的路徑
9650
			foreach($resolvePostionStringWhichContainStarSymbol["content"] as $filteredPath){
226 liveuser 9651
 
3 liveuser 9652
				#儲存符合條件的路徑
9653
				$result["content"][]=$filteredPath;
226 liveuser 9654
 
3 liveuser 9655
				}#foreach end
226 liveuser 9656
 
3 liveuser 9657
			}#foreach end
226 liveuser 9658
 
3 liveuser 9659
		#如果有路徑存在
9660
		if(isset($result["content"])){
226 liveuser 9661
 
3 liveuser 9662
			#取得有幾個路徑
9663
			$result["pathCount"]=count($result["content"]);
226 liveuser 9664
 
3 liveuser 9665
			}#if end
226 liveuser 9666
 
9667
		#反之
3 liveuser 9668
		else{
226 liveuser 9669
 
3 liveuser 9670
			#設置空的路徑結果
9671
			$result["content"]=array();
226 liveuser 9672
 
3 liveuser 9673
			#取得有幾個路徑
9674
			$result["pathCount"]=count($result["content"]);
226 liveuser 9675
 
3 liveuser 9676
			}#else end
226 liveuser 9677
 
3 liveuser 9678
		#設置執行正常
9679
		$result["status"]="true";
226 liveuser 9680
 
3 liveuser 9681
		#回傳結果
9682
		return $result;
226 liveuser 9683
 
3 liveuser 9684
		}#function resolveMultiPostionStringWhichContainStarSymbol end
9685
 
9686
	/*
9687
	#函式說明:
9688
	#將多個路徑字串變成相對於當前路徑的相對路徑字串
9689
	#回傳結果:
9690
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9691
	#$result["error"],錯誤訊息陣列.
226 liveuser 9692
	#$result["function"],函數名稱.
3 liveuser 9693
	#$result["argu"],使用的參數.
9694
	#$result["content"],字串陣列,多個轉換好的相對路徑字串.
9695
	#$result["cmd"],使用的指令.
9696
	#必填參數:
9697
	#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
9698
	$conf["path"]=array();
9699
	#$conf["fileArgu"],字串,當前路徑.
9700
	$conf["fileArgu"]=__FILE__;
9701
	#可省略參數:
9702
	#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
9703
	#$conf["baseFrom"]="";
9704
	#參考資料:
9705
	#無.
9706
	#備註:
9707
	#無.
9708
	*/
9709
	public static function getRelativePath(&$conf){
226 liveuser 9710
 
3 liveuser 9711
		#初始化要回傳的結果
9712
		$result=array();
226 liveuser 9713
 
3 liveuser 9714
		#設置當其函數名稱
9715
		$result["function"]=__FUNCTION__;
226 liveuser 9716
 
3 liveuser 9717
		#如果 $conf 不為陣列
9718
		if(gettype($conf)!="array"){
226 liveuser 9719
 
3 liveuser 9720
			#設置執行失敗
9721
			$result["status"]="false";
226 liveuser 9722
 
3 liveuser 9723
			#設置執行錯誤訊息
9724
			$result["error"][]="\$conf變數須為陣列形態";
9725
 
9726
			#如果傳入的參數為 null
9727
			if($conf==null){
226 liveuser 9728
 
3 liveuser 9729
				#設置執行錯誤訊息
9730
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 9731
 
3 liveuser 9732
				}#if end
9733
 
9734
			#回傳結果
9735
			return $result;
226 liveuser 9736
 
3 liveuser 9737
			}#if end
226 liveuser 9738
 
3 liveuser 9739
		#檢查參數
9740
		#函式說明:
9741
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
9742
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9743
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9744
		#$result["function"],當前執行的函式名稱.
9745
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9746
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9747
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9748
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
9749
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9750
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9751
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9752
		#必填寫的參數:
9753
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9754
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9755
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9756
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 9757
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 9758
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
9759
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9760
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9761
		#可以省略的參數:
9762
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
9763
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9764
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9765
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("baseFrom");
226 liveuser 9766
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 9767
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
9768
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9769
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
9770
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9771
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
9772
		#參考資料來源:
9773
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9774
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9775
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 9776
 
3 liveuser 9777
		#如果 $checkResult["status"] 等於 "false"
9778
		if($checkResult["status"]=="false"){
226 liveuser 9779
 
3 liveuser 9780
			#設置錯誤識別
9781
			$result["status"]="false";
226 liveuser 9782
 
3 liveuser 9783
			#設置錯誤訊息
9784
			$result["error"]=$checkResult;
226 liveuser 9785
 
3 liveuser 9786
			#回傳結果
9787
			return $result;
226 liveuser 9788
 
3 liveuser 9789
			}#if end
226 liveuser 9790
 
3 liveuser 9791
		#如果 $checkResult["passed"] 等於 "fasle"
9792
		if($checkResult["passed"]=="false"){
226 liveuser 9793
 
3 liveuser 9794
			#設置錯誤識別
9795
			$result["status"]="false";
226 liveuser 9796
 
3 liveuser 9797
			#設置錯誤訊息
9798
			$result["error"]=$checkResult;
226 liveuser 9799
 
3 liveuser 9800
			#回傳結果
9801
			return $result;
226 liveuser 9802
 
3 liveuser 9803
			}#if end
226 liveuser 9804
 
3 liveuser 9805
		#取得參數
9806
		$result["argu"]=$conf;
226 liveuser 9807
 
3 liveuser 9808
		#函式說明:
9809
		#將固定格式的字串分開,並回傳分開的結果.
9810
		#回傳結果:
9811
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9812
		#$result["error"],錯誤訊息陣列
9813
		#$result["function"],當前執行的函數名稱.
9814
		#$result["argu"],使用的參數.
9815
		#$result["oriStr"],要分割的原始字串內容
9816
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9817
		#$result["dataCounts"],爲總共分成幾段
9818
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9819
		#必填參數:
9820
		#$conf["stringIn"],字串,要處理的字串.
9821
		$conf["fileAccess::spiltString"]["stringIn"]=$conf["fileArgu"];
9822
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
9823
		$conf["fileAccess::spiltString"]["spiltSymbol"]="/";
9824
		#可省略參數:
9825
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9826
		$conf["fileAccess::spiltString"]["allowEmptyStr"]="false";
9827
		#參考資料:
9828
		#無.
9829
		#備註:
9830
		#無.
9831
		$spiltString=stringProcess::spiltString($conf["fileAccess::spiltString"]);
9832
		unset($conf["fileAccess::spiltString"]);
226 liveuser 9833
 
3 liveuser 9834
		#如果執行失敗
9835
		if($spiltString["status"]==="false"){
226 liveuser 9836
 
3 liveuser 9837
			#設置錯誤識別
9838
			$result["status"]="false";
226 liveuser 9839
 
3 liveuser 9840
			#設置錯誤訊息
9841
			$result["error"]=$spiltString;
226 liveuser 9842
 
3 liveuser 9843
			#回傳結果
9844
			return $result;
226 liveuser 9845
 
3 liveuser 9846
			}#if end
226 liveuser 9847
 
3 liveuser 9848
		#如果沒有關鍵字
9849
		if($spiltString["found"]==="false"){
226 liveuser 9850
 
3 liveuser 9851
			#設置錯誤識別
9852
			$result["status"]="false";
226 liveuser 9853
 
3 liveuser 9854
			#設置錯誤訊息
9855
			$result["error"]=$spiltString;
226 liveuser 9856
 
3 liveuser 9857
			#回傳結果
9858
			return $result;
226 liveuser 9859
 
3 liveuser 9860
			}#if end
226 liveuser 9861
 
3 liveuser 9862
		#取得 $conf["fileArgu"] 的路徑
9863
		#函式說明:
9864
		#將固定格式的字串分開,並回傳分開的結果.
9865
		#回傳結果:
9866
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9867
		#$result["error"],錯誤訊息陣列
9868
		#$result["function"],當前執行的函數名稱.
9869
		#$result["argu"],使用的參數.
9870
		#$result["oriStr"],要分割的原始字串內容
9871
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9872
		#$result["dataCounts"],爲總共分成幾段
9873
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9874
		#必填參數:
9875
		#$conf["stringIn"],字串,要處理的字串.
9876
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];
9877
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
9878
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
9879
		#可省略參數:
9880
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9881
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
9882
		#參考資料:
9883
		#無.
9884
		#備註:
9885
		#無.
9886
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
9887
		unset($conf["stringProcess::spiltString"]);
226 liveuser 9888
 
3 liveuser 9889
		#如果執行失敗
9890
		if($spiltString["status"]==="false"){
226 liveuser 9891
 
3 liveuser 9892
			#設置錯誤識別
9893
			$result["status"]="false";
226 liveuser 9894
 
3 liveuser 9895
			#設置錯誤訊息
9896
			$result["error"]=$spiltString;
226 liveuser 9897
 
3 liveuser 9898
			#回傳結果
9899
			return $result;
226 liveuser 9900
 
3 liveuser 9901
			}#if end
226 liveuser 9902
 
3 liveuser 9903
		/*
9904
		#break point
9905
		var_dump($spiltString);
9906
		exit;
9907
		*/
226 liveuser 9908
 
3 liveuser 9909
		#預設 fileArgu 的路徑為 ""
9910
		$fileArguPath="";
226 liveuser 9911
 
3 liveuser 9912
		#針對每個目錄
9913
		for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 9914
 
3 liveuser 9915
			#串接路徑
9916
			$fileArguPath=$fileArguPath."/".$spiltString["dataArray"][$i];
226 liveuser 9917
 
3 liveuser 9918
			}#for end
226 liveuser 9919
 
3 liveuser 9920
		#取得相對於目標的當前位置
9921
		#函式說明:
9922
		#呼叫shell執行系統命令,並取得回傳的內容.
9923
		#回傳結果:
9924
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9925
		#$result["error"],錯誤訊息陣列.
9926
		#$result["function"],當前執行的函數名稱.
9927
		#$result["argu"],使用的參數.
9928
		#$result["cmd"],執行的指令內容.
9929
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9930
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9931
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9932
		#$result["running"],是否還在執行.
9933
		#$result["pid"],pid.
9934
		#$result["statusCode"],執行結束後的代碼.
9935
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
9936
		#必填參數:
9937
		#$conf["command"],字串,要執行的指令.
9938
		$conf["external::callShell"]["command"]="cd";
9939
		#$conf["fileArgu"],字串,變數__FILE__的內容.
9940
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
9941
		#可省略參數:
9942
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9943
		$conf["external::callShell"]["argu"]=array($fileArguPath,";","pwd");
9944
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9945
		#$conf["arguIsAddr"]=array();
9946
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9947
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9948
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9949
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9950
		#$conf["enablePrintDescription"]="true";
9951
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9952
		#$conf["printDescription"]="";
9953
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9954
		$conf["external::callShell"]["escapeshellarg"]="true";
9955
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9956
		#$conf["thereIsShellVar"]=array();
9957
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9958
		#$conf["username"]="";
9959
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9960
		#$conf["password"]="";
9961
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9962
		#$conf["useScript"]="";
9963
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9964
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9965
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9966
		#$conf["inBackGround"]="";
9967
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9968
		#$conf["getErr"]="false";
9969
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9970
		#$conf["doNotRun"]="false";
9971
		#參考資料:
9972
		#exec=>http://php.net/manual/en/function.exec.php
9973
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9974
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9975
		#備註:
9976
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9977
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9978
		$callShell=external::callShell($conf["external::callShell"]);
9979
		unset($conf["external::callShell"]);
226 liveuser 9980
 
3 liveuser 9981
		#如果執行失敗
9982
		if($callShell["status"]==="false"){
226 liveuser 9983
 
3 liveuser 9984
			#設置錯誤識別
9985
			$result["status"]="false";
226 liveuser 9986
 
3 liveuser 9987
			#設置錯誤訊息
9988
			$result["error"]=$callShell;
226 liveuser 9989
 
3 liveuser 9990
			#回傳結果
9991
			return $result;
226 liveuser 9992
 
3 liveuser 9993
			}#if end
226 liveuser 9994
 
3 liveuser 9995
		#如果執行失敗
9996
		if(!isset($callShell["output"][0])){
226 liveuser 9997
 
3 liveuser 9998
			#設置錯誤識別
9999
			$result["status"]="false";
226 liveuser 10000
 
3 liveuser 10001
			#設置錯誤訊息
10002
			$result["error"]=$callShell;
226 liveuser 10003
 
3 liveuser 10004
			#回傳結果
10005
			return $result;
226 liveuser 10006
 
10007
			}#if end
10008
 
3 liveuser 10009
		/*
10010
		#break point
10011
		var_dump($callShell);
10012
		exit;
10013
		*/
226 liveuser 10014
 
3 liveuser 10015
		#記錄執行的指令
10016
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 10017
 
3 liveuser 10018
		#保存相對於目標的當前位置
10019
		$pwd=$callShell["output"][0];
226 liveuser 10020
 
3 liveuser 10021
		#更新 fileArgu
10022
		$conf["fileArgu"]=$pwd."/".$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 10023
 
3 liveuser 10024
		#針對每個 $conf["path"]
10025
		foreach($conf["path"] as $path){
226 liveuser 10026
 
3 liveuser 10027
			#將 $path 變成易讀的格式
10028
			#函式說明:
10029
			#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
10030
			#回傳的結果:
10031
			#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
10032
			#$result["function"],當前執行的函數.
10033
			#$result["error"],錯誤訊息陣列.
10034
			#$result["changedPath"],處理完後回傳的目錄字串.
10035
			#$result["oriPath"],原始的路徑字串
10036
			#必填參數:
10037
			#$conf["dirStr"],字串,要處理的檔案目錄字串.
10038
			$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$path;
10039
			$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
10040
			unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 10041
 
3 liveuser 10042
			#如果處理失敗
10043
			if($changeDirByDotDotSolidus["status"]==="false"){
226 liveuser 10044
 
3 liveuser 10045
				#設置錯誤識別
10046
				$result["status"]="false";
226 liveuser 10047
 
3 liveuser 10048
				#設置錯誤訊息
10049
				$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10050
 
3 liveuser 10051
				#回傳結果
10052
				return $result;
226 liveuser 10053
 
3 liveuser 10054
				}#if end
226 liveuser 10055
 
3 liveuser 10056
			#取得易讀的路徑
10057
			$path=$changeDirByDotDotSolidus["changedPath"];
226 liveuser 10058
 
3 liveuser 10059
			#判斷 $path 是否為絕對路徑
10060
			#函式說明:
10061
			#取得符合特定字首與字尾的字串
10062
			#回傳結果:
10063
			#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10064
			#$result["function"],當前執行的函數名稱.
10065
			#$result["error"],錯誤訊息陣列.
10066
			#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10067
			#$result["returnString"],爲符合字首條件的字串內容。
10068
			#必填參數:
10069
			#$conf["checkString"],字串,要檢查的字串.
10070
			$conf["search::getMeetConditionsString"]["checkString"]=$path;
10071
			#可省略參數:
10072
			#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10073
			$conf["search::getMeetConditionsString"]["frontWord"]="/";
10074
			#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10075
			#$conf["tailWord"]="";
10076
			#參考資料:
10077
			#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10078
			$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
226 liveuser 10079
			unset($conf["search::getMeetConditionsString"]);
10080
 
3 liveuser 10081
			#如果檢查失敗
10082
			if($getMeetConditionsString["status"]=="false"){
226 liveuser 10083
 
3 liveuser 10084
				#設置錯誤識別
10085
				$result["status"]="false";
226 liveuser 10086
 
3 liveuser 10087
				#設置錯誤訊息
10088
				$result["error"]=$getMeetConditionsString;
226 liveuser 10089
 
3 liveuser 10090
				#回傳結果
10091
				return $result;
226 liveuser 10092
 
3 liveuser 10093
				}#if end
226 liveuser 10094
 
3 liveuser 10095
			#如果沒有「/」開頭
10096
			if($getMeetConditionsString["founded"]==="false"){
226 liveuser 10097
 
3 liveuser 10098
				#將 $conf["fileArgu"] 最後面的檔案或目錄名稱剔除
10099
				#函式說明:
10100
				#將固定格式的字串分開,並回傳分開的結果。
10101
				#回傳結果:
10102
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10103
				#$result["error"],錯誤訊息陣列
10104
				#$result["function"],當前執行的函數名稱.
10105
				#$result["oriStr"],要分割的原始字串內容
10106
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
10107
				#$result["dataCounts"],爲總共分成幾段
10108
				#必填參數:
10109
				$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
10110
				$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
10111
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
10112
				unset($conf["stringProcess::spiltString"]);
226 liveuser 10113
 
3 liveuser 10114
				#如果分割字串失敗
10115
				if($spiltString["status"]=="false"){
226 liveuser 10116
 
3 liveuser 10117
					#設置錯誤識別
10118
					$result["status"]="false";
226 liveuser 10119
 
3 liveuser 10120
					#設置錯誤訊息
10121
					$result["error"]=$spiltString;
226 liveuser 10122
 
3 liveuser 10123
					#回傳結果
10124
					return $result;
226 liveuser 10125
 
3 liveuser 10126
					}#if end
226 liveuser 10127
 
3 liveuser 10128
				#初始化相對路徑為開頭片段""
10129
				$relativePathPart="/";
226 liveuser 10130
 
3 liveuser 10131
				#剔除最後一段
10132
				for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 10133
 
3 liveuser 10134
					#串接起來
10135
					$relativePathPart=$relativePathPart.$spiltString["dataArray"][$i]."/";
226 liveuser 10136
 
3 liveuser 10137
					}#for end
226 liveuser 10138
 
3 liveuser 10139
				#如果有設定 baseFrom
10140
				if(isset($conf["baseFrom"])){
226 liveuser 10141
 
3 liveuser 10142
					#函式說明:
10143
					#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
10144
					#回傳結果:
10145
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10146
					#$result["error"],錯誤訊息陣列.
226 liveuser 10147
					#$result["function"],函數名稱.
3 liveuser 10148
					#$result["argu"],使用的參數.
10149
					#$result["content"],網址,若是在命令列執行,則為"null".
10150
					#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
10151
					#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
10152
					#必填參數:
10153
					#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
10154
					$conf["fileAccess::getInternetAddressV2"]["address"]=$path;
10155
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
10156
					$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
10157
					#可省略參數:
10158
					#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
10159
					$conf["fileAccess::getInternetAddressV2"]["web"]="false";
10160
					#參考資料:
10161
					#無.
10162
					#備註:
10163
					#無.
10164
					$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
10165
					unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 10166
 
3 liveuser 10167
					##var_dump(__LINE__." ".print_r($getInternetAddressV2,true));
226 liveuser 10168
 
3 liveuser 10169
					#如果執行失敗
10170
					if($getInternetAddressV2["status"]==="false"){
226 liveuser 10171
 
3 liveuser 10172
						#設置錯誤識別
10173
						$result["status"]="false";
226 liveuser 10174
 
3 liveuser 10175
						#設置錯誤訊息
10176
						$result["error"]=$getInternetAddressV2;
226 liveuser 10177
 
3 liveuser 10178
						#回傳結果
10179
						return $result;
226 liveuser 10180
 
3 liveuser 10181
						}#if end
226 liveuser 10182
 
3 liveuser 10183
					#取得絕對位置
10184
					$path=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 10185
 
3 liveuser 10186
					#函式說明:
10187
					#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
10188
					#回傳結果:
10189
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10190
					#$result["error"],錯誤訊息陣列.
226 liveuser 10191
					#$result["function"],函數名稱.
3 liveuser 10192
					#$result["argu"],使用的參數.
10193
					#$result["content"],網址,若是在命令列執行,則為"null".
10194
					#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
10195
					#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
10196
					#必填參數:
10197
					#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
10198
					$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["baseFrom"];
10199
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
10200
					$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
10201
					#可省略參數:
10202
					#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
10203
					$conf["fileAccess::getInternetAddressV2"]["web"]="false";
10204
					#參考資料:
10205
					#無.
10206
					#備註:
10207
					#無.
10208
					$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
10209
					unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 10210
 
3 liveuser 10211
					#var_dump(__LINE__." ".print_r($getInternetAddressV2,true));
226 liveuser 10212
 
3 liveuser 10213
					#如果執行失敗
10214
					if($getInternetAddressV2["status"]==="false"){
226 liveuser 10215
 
3 liveuser 10216
						#設置錯誤識別
10217
						$result["status"]="false";
226 liveuser 10218
 
3 liveuser 10219
						#設置錯誤訊息
10220
						$result["error"]=$getInternetAddressV2;
226 liveuser 10221
 
3 liveuser 10222
						#回傳結果
10223
						return $result;
226 liveuser 10224
 
3 liveuser 10225
						}#if end
226 liveuser 10226
 
3 liveuser 10227
					#取得絕對位置
10228
					$conf["baseFrom"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 10229
 
3 liveuser 10230
					#函式說明:
10231
					#將多個路徑字串變成相對於當前路徑的相對路徑字串
10232
					#回傳結果:
10233
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10234
					#$result["error"],錯誤訊息陣列.
226 liveuser 10235
					#$result["function"],函數名稱.
3 liveuser 10236
					#$result["argu"],使用的參數.
10237
					#$result["content"],字串陣列,多個轉換好的相對路徑字串.
10238
					#必填參數:
10239
					#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
10240
					$conf["fileAccess::getRelativePath"]["path"]=array($path);
10241
					#$conf["fileArgu"],字串,當前路徑.
10242
					$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["baseFrom"]."/name";
10243
					#可省略參數:
10244
					#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
10245
					#$conf["baseFrom"]="";
10246
					#參考資料:
10247
					#無.
10248
					#備註:
10249
					#無.
10250
					$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
10251
					unset($conf["fileAccess::getRelativePath"]);
226 liveuser 10252
 
3 liveuser 10253
					#var_dump(__LINE__." ".print_r($getRelativePath,true));
226 liveuser 10254
 
3 liveuser 10255
					#如果執行失敗
10256
					if($getRelativePath["status"]==="false"){
226 liveuser 10257
 
3 liveuser 10258
						#設置錯誤識別
10259
						$result["status"]="false";
226 liveuser 10260
 
3 liveuser 10261
						#設置錯誤訊息
10262
						$result["error"]=$getRelativePath;
226 liveuser 10263
 
3 liveuser 10264
						#回傳結果
10265
						return $result;
226 liveuser 10266
 
3 liveuser 10267
						}#if end
226 liveuser 10268
 
3 liveuser 10269
					#取得轉換好的絕對路徑
10270
					$relativePathPart=$getRelativePath["content"][0]."/";
226 liveuser 10271
 
3 liveuser 10272
					#清空path,避免出錯
10273
					$path="";
226 liveuser 10274
 
3 liveuser 10275
					}#if end
226 liveuser 10276
 
3 liveuser 10277
				#轉換成易讀的相對路徑
10278
				#函式說明:
10279
				#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
10280
				#回傳的結果:
10281
				#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
10282
				#$result["function"],當前執行的函數.
10283
				#$result["error"],錯誤訊息陣列.
10284
				#$result["changedPath"],處理完後回傳的目錄字串.
10285
				#$result["oriPath"],原始的路徑字串
10286
				#必填參數:
10287
				#$conf["dirStr"],字串,要處理的檔案目錄字串.
10288
				$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$relativePathPart.$path;
10289
				$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
10290
				unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 10291
 
10292
				#var_dump($changeDirByDotDotSolidus);
10293
 
3 liveuser 10294
				#如果轉換失敗
10295
				if($changeDirByDotDotSolidus["status"]=="false"){
226 liveuser 10296
 
3 liveuser 10297
					#設置錯誤識別
10298
					$result["status"]="false";
226 liveuser 10299
 
3 liveuser 10300
					#設置錯誤訊息
10301
					$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10302
 
3 liveuser 10303
					#回傳結果
10304
					return $result;
226 liveuser 10305
 
3 liveuser 10306
					}#if end
226 liveuser 10307
 
3 liveuser 10308
				#轉換為相對路徑
10309
				#函式說明:
10310
				#將多個路徑字串變成相對於當前路徑的相對路徑字串
10311
				#回傳結果:
10312
				#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10313
				#$result["error"],錯誤訊息陣列.
226 liveuser 10314
				#$result["function"],函數名稱.
3 liveuser 10315
				#$result["content"],字串陣列,多個轉換好的相對路徑字串.
10316
				#必填參數:
10317
				#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
10318
				$conf["fileAccess::getRelativePath"]["path"]=array($changeDirByDotDotSolidus["changedPath"]);
10319
				#$conf["fileArgu"],字串,當前路徑.
10320
				$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
10321
				$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
10322
				unset($conf["fileAccess::getRelativePath"]);
226 liveuser 10323
 
10324
				#var_dump($getRelativePath);
10325
 
3 liveuser 10326
				#如果轉換路徑失敗
10327
				if($getRelativePath["status"]==="false"){
226 liveuser 10328
 
3 liveuser 10329
					#設置錯誤識別
10330
					$result["status"]="false";
226 liveuser 10331
 
3 liveuser 10332
					#設置錯誤訊息
10333
					$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10334
 
3 liveuser 10335
					#回傳結果
10336
					return $result;
226 liveuser 10337
 
3 liveuser 10338
					}#if end
226 liveuser 10339
 
3 liveuser 10340
				#取得相對路徑
10341
				$result["content"][]=$getRelativePath["content"][0];
226 liveuser 10342
 
3 liveuser 10343
				}#if end
226 liveuser 10344
 
3 liveuser 10345
			#反之有「/」開頭
10346
			else{
10347
				#函式說明:
10348
				#移除多個絕對路徑字串開頭相同的部分
10349
				#回傳結果:
10350
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10351
				#$result["error"],錯誤訊息陣列.
10352
				#$result["function"],當前執行的函數名稱.
10353
				#$result["content"],處理好的的字串內容.
10354
				#必填參數:
10355
				#$conf["pathIn"],字串陣列,每個要處理的絕對路徑字串.
226 liveuser 10356
				$conf["fileAccess::delSamePathHead"]["pathIn"]=array($path,$conf["fileArgu"]);
3 liveuser 10357
				$delSamePathHead=fileAccess::delSamePathHead($conf["fileAccess::delSamePathHead"]);
10358
				unset($conf["fileAccess::delSamePathHead"]);
226 liveuser 10359
 
3 liveuser 10360
				#var_dump($delSamePathHead);
226 liveuser 10361
 
3 liveuser 10362
				#如果移除多個絕對路徑字串開頭相同的部分失敗
10363
				if($delSamePathHead["status"]==="false"){
226 liveuser 10364
 
3 liveuser 10365
					#設置錯誤識別
10366
					$result["status"]="false";
226 liveuser 10367
 
3 liveuser 10368
					#設置錯誤訊息
10369
					$result["error"]=$delSameHead;
226 liveuser 10370
 
3 liveuser 10371
					#回傳結果
10372
					return $result;
226 liveuser 10373
 
3 liveuser 10374
					}#if end
226 liveuser 10375
 
3 liveuser 10376
				#如果 $conf["fileArgu"] 剩下空
10377
				if($delSamePathHead["content"][1]===""){
226 liveuser 10378
 
3 liveuser 10379
					#檢查 $delSamePathHead[0] 開頭是否為「/」
10380
					#函式說明:
10381
					#取得符合特定字首與字尾的字串
10382
					#回傳結果:
10383
					#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10384
					#$result["function"],當前執行的函數名稱.
10385
					#$result["error"],錯誤訊息陣列.
10386
					#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10387
					#$result["returnString"],爲符合字首條件的字串內容。
10388
					#必填參數:
10389
					#$conf["checkString"],字串,要檢查的字串.
10390
					$conf["search::getMeetConditionsString"]["checkString"]=$delSamePathHead["content"][0];
10391
					#可省略參數:
10392
					#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10393
					$conf["search::getMeetConditionsString"]["frontWord"]="/";
10394
					#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10395
					#$conf["tailWord"]="";
10396
					#參考資料:
10397
					#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10398
					$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
10399
					unset($conf["search::getMeetConditionsString"]);
226 liveuser 10400
 
3 liveuser 10401
					#如果檢查失敗
10402
					if($getMeetConditionsString["status"]=="false"){
226 liveuser 10403
 
3 liveuser 10404
						#設置錯誤識別
10405
						$result["status"]="false";
226 liveuser 10406
 
3 liveuser 10407
						#設置錯誤訊息
10408
						$result["error"]=$getMeetConditionsString;
226 liveuser 10409
 
3 liveuser 10410
						#回傳結果
10411
						return $result;
226 liveuser 10412
 
3 liveuser 10413
						}#if end
226 liveuser 10414
 
3 liveuser 10415
					#如果有開頭有「/」
10416
					if($getMeetConditionsString["founded"]==="true"){
226 liveuser 10417
 
3 liveuser 10418
						#函式說明:
10419
						#將字串特定關鍵字與其前面的內容剔除
10420
						#回傳結果:
10421
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10422
						#$result["error"],錯誤訊息陣列.
10423
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
10424
						#$result["function"],當前執行的函數名稱.
10425
						#$result["oriStr"],要處理的原始字串內容.
10426
						#$result["content"],處理好的的字串內容.
10427
						#必填參數:
10428
						$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$delSamePathHead["content"][0];#要處理的字串.
10429
						$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="/";#特定字串.
10430
						$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
10431
						unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 10432
 
3 liveuser 10433
						#如果 將字串特定關鍵字與其前面的內容剔除 失敗
10434
						if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 10435
 
3 liveuser 10436
							#設置錯誤識別
10437
							$result["status"]="false";
226 liveuser 10438
 
3 liveuser 10439
							#設置錯誤訊息
10440
							$result["error"]=$delStrBeforeKeyWord;
226 liveuser 10441
 
3 liveuser 10442
							#回傳結果
10443
							return $result;
226 liveuser 10444
 
3 liveuser 10445
							}#if end
226 liveuser 10446
 
3 liveuser 10447
						#取得相對位置
10448
						$result["content"][]=$delStrBeforeKeyWord["content"];
226 liveuser 10449
 
3 liveuser 10450
						}#if end
226 liveuser 10451
 
3 liveuser 10452
					#反之
10453
					else{
226 liveuser 10454
 
3 liveuser 10455
						#取得相對位置
10456
						$result["content"][]=$delSamePathHead["content"][0];
226 liveuser 10457
 
10458
						}#else end
10459
 
3 liveuser 10460
					}#if end
226 liveuser 10461
 
3 liveuser 10462
				#反之剩下的 $conf["fileArgu"] 不為空
10463
				else{
226 liveuser 10464
 
3 liveuser 10465
					#檢查 $delSamePathHead["content"][1] 有幾個「/」
10466
					#函式說明:
10467
					#檢查字串裡面有無指定的關鍵字
10468
					#回傳結果:
10469
					#$result["status"],"true"代表執行成功,"false"代表執行失敗。
10470
					#$result["error"],錯誤訊息
10471
					#$result["function"],當前執行的函數名稱.
10472
					#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
10473
					#$result["keyWordCount"],找到的關鍵字數量.
10474
					#必填參數:
10475
					$conf["search::findKeyWord"]["keyWord"]="/";#想要搜尋的關鍵字
10476
					$conf["search::findKeyWord"]["string"]=$delSamePathHead["content"][1];#要被搜尋的字串內容
10477
					#可省略參數:
10478
					#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
10479
					$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
10480
					unset($conf["search::findKeyWord"]);
226 liveuser 10481
 
3 liveuser 10482
					#如果 檢查字串裡面有無指定的關鍵字 失敗
10483
					if($findKeyWord["status"]==="false"){
226 liveuser 10484
 
3 liveuser 10485
						#設置錯誤識別
10486
						$result["status"]="false";
226 liveuser 10487
 
3 liveuser 10488
						#設置錯誤訊息
10489
						$result["error"]=$findKeyWord;
226 liveuser 10490
 
3 liveuser 10491
						#回傳結果
10492
						return $result;
226 liveuser 10493
 
3 liveuser 10494
						}#if end
226 liveuser 10495
 
3 liveuser 10496
					#有幾個「/」就執行幾次
10497
					for($i=0;$i<$findKeyWord["keyWordCount"];$i++){
226 liveuser 10498
 
3 liveuser 10499
						#在前面加上 "../"
10500
						$delSamePathHead["content"][0]="../".$delSamePathHead["content"][0];
226 liveuser 10501
 
3 liveuser 10502
						}#for end
226 liveuser 10503
 
3 liveuser 10504
					#取得相對位置
10505
					$result["content"][]=$delSamePathHead["content"][0];
226 liveuser 10506
 
3 liveuser 10507
					}#else end
226 liveuser 10508
 
3 liveuser 10509
				}#else end
226 liveuser 10510
 
3 liveuser 10511
			}#foreach end
226 liveuser 10512
 
3 liveuser 10513
		#設置執行正常
10514
		$result["status"]="true";
226 liveuser 10515
 
3 liveuser 10516
		#回傳結果
10517
		return $result;
226 liveuser 10518
 
3 liveuser 10519
		}#function getRelativeParh end
10520
 
10521
	/*
10522
	#函式說明:
10523
	#移除多個絕對路徑字串開頭相同的部分
10524
	#回傳結果:
10525
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10526
	#$result["error"],錯誤訊息陣列.
10527
	#$result["function"],當前執行的函數名稱.
10528
	#$result["argu"],參數.
10529
	#$result["content"],處理好的的字串內容.
10530
	#必填參數:
10531
	#$conf["pathIn"],字串陣列,每個要處理的絕對路徑字串.
226 liveuser 10532
	$conf["pathIn"]=array();
3 liveuser 10533
	#可省略參數:
10534
	#無
10535
	#參考資料:
10536
	#無.
10537
	#備註:
10538
	#無.
10539
	*/
10540
	public static function delSamePathHead(&$conf){
226 liveuser 10541
 
3 liveuser 10542
		#初始化要回傳的結果
10543
		$result=array();
10544
 
10545
		#取得當前執行的函數名稱
10546
		$result["function"]=__FUNCTION__;
10547
 
10548
		#如果沒有參數
10549
		if(func_num_args()==0){
226 liveuser 10550
 
3 liveuser 10551
			#設置執行失敗
10552
			$result["status"]="false";
226 liveuser 10553
 
3 liveuser 10554
			#設置執行錯誤訊息
10555
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 10556
 
3 liveuser 10557
			#回傳結果
10558
			return $result;
226 liveuser 10559
 
3 liveuser 10560
			}#if end
10561
 
10562
		#如果 $conf 不為陣列
10563
		if(gettype($conf)!="array"){
226 liveuser 10564
 
3 liveuser 10565
			#設置執行失敗
10566
			$result["status"]="false";
226 liveuser 10567
 
3 liveuser 10568
			#設置執行錯誤訊息
10569
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 10570
 
3 liveuser 10571
			#如果傳入的參數為 null
10572
			if($conf==null){
226 liveuser 10573
 
3 liveuser 10574
				#設置執行錯誤訊息
10575
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 10576
 
3 liveuser 10577
				}#if end
10578
 
10579
			#回傳結果
10580
			return $result;
226 liveuser 10581
 
3 liveuser 10582
			}#if end
226 liveuser 10583
 
3 liveuser 10584
		#取得參數
226 liveuser 10585
		$result["argv"]=$conf;
10586
 
3 liveuser 10587
		#檢查參數
10588
		#函式說明:
10589
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
10590
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10591
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10592
		#$result["function"],當前執行的函式名稱.
10593
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10594
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10595
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10596
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
10597
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10598
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10599
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10600
		#必填寫的參數:
10601
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10602
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10603
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10604
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("pathIn");
226 liveuser 10605
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 10606
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
10607
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10608
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10609
		#可以省略的參數:
10610
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
10611
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
10612
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10613
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileToRead","output");
226 liveuser 10614
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 10615
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
10616
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10617
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("help","help");
10618
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10619
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
10620
		#參考資料來源:
10621
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10622
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10623
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 10624
 
3 liveuser 10625
		#如果 $checkResult["status"] 等於 "fasle"
10626
		if($checkResult["status"]=="false"){
226 liveuser 10627
 
3 liveuser 10628
			#設置錯誤識別
10629
			$result["status"]="false";
226 liveuser 10630
 
3 liveuser 10631
			#設置錯誤訊息
10632
			$result["error"]=$checkResult;
226 liveuser 10633
 
3 liveuser 10634
			#回傳結果
10635
			return $result;
226 liveuser 10636
 
3 liveuser 10637
			}#if end
226 liveuser 10638
 
3 liveuser 10639
		#如果 $checkResult["passed"] 等於 "fasle"
10640
		if($checkResult["passed"]=="false"){
226 liveuser 10641
 
3 liveuser 10642
			#設置錯誤識別
10643
			$result["status"]="false";
226 liveuser 10644
 
3 liveuser 10645
			#設置錯誤訊息
10646
			$result["error"]=$checkResult;
226 liveuser 10647
 
3 liveuser 10648
			#回傳結果
10649
			return $result;
226 liveuser 10650
 
3 liveuser 10651
			}#if end
226 liveuser 10652
 
3 liveuser 10653
		#檢查是否都為絕對路徑
10654
		#函式說明:
10655
		#取得多個符合特定字首與字尾的字串.
10656
		#回傳結果:
10657
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10658
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10659
		#$result["function"],當前執行的函數名稱.
10660
		#$result["returnString"],爲符合字首條件的字串陣列內容。
10661
		#必填參數:
10662
		#$conf["checkString"],陣列字串,要檢查的字串們.
10663
		$conf["search::getMeetConditionsStringMulti"]["checkString"]=$conf["pathIn"];#要檢查的字串陣列
10664
		#可省略參數:
10665
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10666
		$conf["search::getMeetConditionsStringMulti"]["frontWord"]="/";
10667
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10668
		#$conf["tailWord"]="";
10669
		#參考資料:
10670
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10671
		$getMeetConditionsStringMulti=search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]);
10672
		unset($conf["search::getMeetConditionsStringMulti"]);
226 liveuser 10673
 
3 liveuser 10674
		#如果檢測是否為絕對路徑失敗
10675
		if($getMeetConditionsStringMulti["status"]=="false"){
226 liveuser 10676
 
3 liveuser 10677
			#設置錯誤識別
10678
			$result["status"]="false";
226 liveuser 10679
 
3 liveuser 10680
			#設置錯誤訊息
10681
			$result["error"]=$getMeetConditionsStringMulti;
226 liveuser 10682
 
3 liveuser 10683
			#增加額外的錯誤訊息
10684
			$result["error"][]="僅接受絕對路徑字串";
226 liveuser 10685
 
3 liveuser 10686
			#回傳結果
10687
			return $result;
226 liveuser 10688
 
3 liveuser 10689
			}#if end
226 liveuser 10690
 
3 liveuser 10691
		#函式說明:
10692
		#將多個固定格式的字串分開,並回傳分開的結果
10693
		#回傳的參數:
10694
		#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
10695
		#$result["error"],錯誤訊息陣列.
10696
		#$result["function"],當前執行的函數名稱.
10697
		#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
10698
		#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
10699
		#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
10700
		#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
10701
		#必填參數:
10702
		#$conf["stringIn"],字串陣列,要處理的字串陣列.
10703
		$conf["stringProcess::spiltMutiString"]["stringIn"]=$conf["pathIn"];
10704
		#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
10705
		$conf["stringProcess::spiltMutiString"]["spiltSymbol"]="/";
10706
		$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
226 liveuser 10707
 
3 liveuser 10708
		#如果分割所有路徑字串失敗
10709
		if($spiltMutiString["status"]=="false"){
226 liveuser 10710
 
3 liveuser 10711
			#設置錯誤識別
10712
			$result["status"]="false";
226 liveuser 10713
 
3 liveuser 10714
			#設置錯誤訊息
226 liveuser 10715
			$result["error"]=$spiltMutiString;
10716
 
3 liveuser 10717
			#回傳結果
10718
			return $result;
226 liveuser 10719
 
3 liveuser 10720
			}#if end
226 liveuser 10721
 
3 liveuser 10722
		#初始化暫存每個路徑分割成的段數
226 liveuser 10723
		$spiltedPathCount=array();
10724
 
3 liveuser 10725
		#取得每個路徑分割成的段數
10726
		#針對每個 $spiltMutiString["spiltString"]
10727
		for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
226 liveuser 10728
 
3 liveuser 10729
			$spiltedPathCount[]=$spiltMutiString["spiltString"][$i]["dataCounts"];
226 liveuser 10730
 
3 liveuser 10731
			}#for end
226 liveuser 10732
 
3 liveuser 10733
		#取得所有路徑字串分割後的最小數量
10734
		#涵式說明
10735
		#找最小值,結果會回傳最小值
10736
		#回傳的內容
10737
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
10738
		#$result["error"],錯誤訊息陣列.
10739
		#$result["function"],當前執行的函數名稱.
10740
		#$result["key"],最大值原先的key.
10741
		#$result["value"],陣列裏面最小的數值.
10742
		#必填參數:
10743
		$conf["math::getMinValue"]["rawDataArray"]=$spiltedPathCount;#爲原始數據
10744
		$getMinValue=math::getMinValue($conf["math::getMinValue"]);
10745
		unset($conf["math::getMinValue"]);
226 liveuser 10746
 
3 liveuser 10747
		#如果取得最小數值失敗
10748
		if($getMinValue["status"]=="false"){
226 liveuser 10749
 
3 liveuser 10750
			#設置錯誤識別
10751
			$result["status"]="false";
226 liveuser 10752
 
3 liveuser 10753
			#設置錯誤訊息
226 liveuser 10754
			$result["error"]=$getMinValue;
10755
 
3 liveuser 10756
			#回傳結果
10757
			return $result;
226 liveuser 10758
 
10759
			}#if end
10760
 
3 liveuser 10761
		#初始化暫存每個路徑字串的前面幾個片段是相同的
10762
		$samePartCount=0;
226 liveuser 10763
 
10764
		#var_dump($getMinValue["value"]);
10765
 
3 liveuser 10766
		#依據所有路徑字串分割後的最小數量
10767
		for($j=0;$j<$getMinValue["value"];$j++){
226 liveuser 10768
 
3 liveuser 10769
			#初始化暫存第一個路徑的片段字串
10770
			$firstPathPart="";
226 liveuser 10771
 
3 liveuser 10772
			#針對每個 $spiltMutiString["spiltString"]
10773
			for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
226 liveuser 10774
 
3 liveuser 10775
				#暫存分割的字串
10776
				$spiltedPath=$spiltMutiString["spiltString"][$i];
226 liveuser 10777
 
3 liveuser 10778
				#如果是第一個路徑
10779
				if($i==0){
226 liveuser 10780
 
3 liveuser 10781
					#取得第一個路徑的片段字串
10782
					$firstPathPart=$spiltedPath["dataArray"][$j];
226 liveuser 10783
 
10784
					}#if end
10785
 
3 liveuser 10786
				#如果第$i+1個路徑片段不跟第1個路徑的片段字串一樣
10787
				if($spiltedPath["dataArray"][$j]!=$firstPathPart){
226 liveuser 10788
 
3 liveuser 10789
					#讓最外層迴圈中止
10790
					$getMinValue["value"]=-1;
226 liveuser 10791
 
3 liveuser 10792
					#跳出迴圈
10793
					break;
226 liveuser 10794
 
10795
					}#if end
10796
 
3 liveuser 10797
				}#for end
226 liveuser 10798
 
3 liveuser 10799
			#代表每個路徑字串的第$j段是一樣的.
10800
			$samePartCount=$j;
226 liveuser 10801
 
3 liveuser 10802
			}#for end
226 liveuser 10803
 
3 liveuser 10804
		#var_dump($samePartCount);
226 liveuser 10805
 
3 liveuser 10806
		#依據每個路徑
226 liveuser 10807
		for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
10808
 
3 liveuser 10809
			#初始化儲存第$i+1個處理好的路徑字串
226 liveuser 10810
			$result["content"][$i]="";
10811
 
3 liveuser 10812
			#依據 $samePartCount 與 路徑的段數
10813
			for($j=$samePartCount;$j<$spiltMutiString["spiltString"][$i]["dataCounts"];$j++){
226 liveuser 10814
 
3 liveuser 10815
				#如果不是第一段
10816
				if($j!=$samePartCount){
226 liveuser 10817
 
3 liveuser 10818
					#組裝每個路徑片段
10819
					$result["content"][$i]=$result["content"][$i]."/".$spiltMutiString["spiltString"][$i]["dataArray"][$j];
226 liveuser 10820
 
3 liveuser 10821
					}#if end
226 liveuser 10822
 
3 liveuser 10823
				#反之為第一段
10824
				else{
226 liveuser 10825
 
3 liveuser 10826
					#組裝每個路徑片段
10827
					$result["content"][$i]=$result["content"][$i].$spiltMutiString["spiltString"][$i]["dataArray"][$j];
226 liveuser 10828
 
3 liveuser 10829
					}#else end
226 liveuser 10830
 
3 liveuser 10831
				}#for end
226 liveuser 10832
 
3 liveuser 10833
			}#for end
226 liveuser 10834
 
3 liveuser 10835
		#設置執行正常
10836
		$result["status"]="true";
226 liveuser 10837
 
3 liveuser 10838
		#回傳結果
10839
		return $result;
226 liveuser 10840
 
3 liveuser 10841
		}#function delSamePathHead end
10842
 
10843
	/*
10844
	#函式說明:
226 liveuser 10845
	#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
3 liveuser 10846
	#回傳結果:
10847
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10848
	#$result["error"],錯誤訊息.
10849
	#$result["function"],當前執行的函數名稱.
10850
	#$result["content"],暫存檔案的路徑與名稱.
10851
	#$result["fileName"],暫存檔案的名稱.
10852
	#$result["path"],暫存檔案的路徑.
10853
	#必填參數:
10854
	#無.
10855
	#可省略參數:
36 liveuser 10856
	#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
10857
	#$conf["contant"]=array();
3 liveuser 10858
	#參考資料:
10859
	#無.
10860
	#備註:
10861
	#無.
10862
	*/
36 liveuser 10863
	public static function createTempFile(&$conf){
226 liveuser 10864
 
3 liveuser 10865
		#初始化要回傳的結果
10866
		$result=array();
10867
 
10868
		#取得當前執行的函數名稱
10869
		$result["function"]=__FUNCTION__;
226 liveuser 10870
 
36 liveuser 10871
		#取得參數
10872
		$result["argu"]=$conf;
10873
 
10874
		#如果 $conf 不為陣列
10875
		if(gettype($conf)!="array"){
10876
 
10877
			#設置執行失敗
10878
			$result["status"]="false";
10879
 
10880
			#設置執行錯誤訊息
10881
			$result["error"][]="\$conf變數須為陣列形態";
10882
 
10883
			#如果傳入的參數為 null
10884
			if(is_null($conf)){
10885
 
10886
				#設置執行錯誤訊息
10887
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
10888
 
10889
				}#if end
10890
 
10891
			#回傳結果
10892
			return $result;
10893
 
10894
			}#if end
226 liveuser 10895
 
36 liveuser 10896
		#檢查參數
10897
		#函式說明:
10898
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
10899
		#回傳結果:
10900
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10901
		#$result["error"],執行不正常結束的錯訊息陣列.
10902
		#$result["simpleError"],簡單表示的錯誤訊息.
10903
		#$result["function"],當前執行的函式名稱.
10904
		#$result["argu"],設置給予的參數.
10905
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10906
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10907
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10908
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
10909
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
10910
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10911
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10912
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10913
		#必填參數:
10914
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10915
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10916
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10917
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10918
		#可省略參數:
10919
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10920
		#$conf["mustBeFilledVariableName"]=array();
10921
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
10922
		#$conf["mustBeFilledVariableType"]=array();
10923
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
10924
		#$conf["canBeEmptyString"]="false";
10925
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
10926
		#$conf["canNotBeEmpty"]=array();
10927
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
10928
		#$conf["canBeEmpty"]=array();
10929
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
10930
		#$conf["skipableVariableCanNotBeEmpty"]=array();
10931
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10932
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("content");
10933
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
10934
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
10935
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10936
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array());
10937
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
10938
		#$conf["disallowAllSkipableVarIsEmpty"]="";
10939
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
10940
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
10941
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
10942
		#$conf["disallowAllSkipableVarNotExist"]="";
10943
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10944
		#$conf["arrayCountEqualCheck"][]=array();
10945
		#參考資料:
10946
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10947
		#備註:
10948
		#無.
10949
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10950
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 10951
 
36 liveuser 10952
		#如果執行失敗
10953
		if($checkArguments["status"]==="false"){
226 liveuser 10954
 
36 liveuser 10955
			#設置執行異常
10956
			$result["status"]="false";
226 liveuser 10957
 
36 liveuser 10958
			#設置錯誤訊息
10959
			$result["error"]=$checkArguments;
226 liveuser 10960
 
36 liveuser 10961
			#回傳結果
10962
			return $result;
226 liveuser 10963
 
36 liveuser 10964
			}#if end
226 liveuser 10965
 
36 liveuser 10966
		#如果檢查不通過
10967
		if($checkArguments["passed"]==="false"){
226 liveuser 10968
 
36 liveuser 10969
			#設置執行異常
10970
			$result["status"]="false";
226 liveuser 10971
 
36 liveuser 10972
			#設置錯誤訊息
10973
			$result["error"]=$checkArguments;
226 liveuser 10974
 
36 liveuser 10975
			#回傳結果
10976
			return $result;
226 liveuser 10977
 
36 liveuser 10978
			}#if end
226 liveuser 10979
 
3 liveuser 10980
		#取得相對於當前路徑的  tmp 目錄.
10981
		exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/tmp;pwd;",$output,$status);
226 liveuser 10982
 
3 liveuser 10983
		#如果執行失敗
10984
		if($status!==0){
226 liveuser 10985
 
3 liveuser 10986
			#設置執行失敗
10987
			$result["status"]="false";
10988
 
10989
			#設置執行錯誤訊息
10990
			$result["error"][]="取得暫存目錄失敗";
226 liveuser 10991
 
3 liveuser 10992
			#回傳結果
10993
			return $result;
226 liveuser 10994
 
10995
			}#if end
10996
 
3 liveuser 10997
		#設置預設的暫存目錄
226 liveuser 10998
		$defaultTmpDir=$output[0];
10999
 
3 liveuser 11000
		#取得暫存檔案的路徑與名稱
406 liveuser 11001
		#雖然有指定存放的目錄,但系統還是會先嘗試在系統暫存目錄建立,不過最後還會在指定的目錄產生暫存檔案.
3 liveuser 11002
		$result["content"]=tempnam($defaultTmpDir,"qbpwcf_tmpfile_");
226 liveuser 11003
 
42 liveuser 11004
		#如果產生的暫存檔案位置異常
11005
		#參考資料:
11006
		#https://www.php.net/manual/en/function.tempnam.php
11007
		if(strpos("/tmp/",$result["content"])===0){
226 liveuser 11008
 
42 liveuser 11009
			#設置執行失敗
11010
			$result["status"]="false";
11011
 
11012
			#設置執行錯誤訊息
11013
			$result["error"][]="於暫存目錄建立檔案失敗";
226 liveuser 11014
 
42 liveuser 11015
			#回傳結果
11016
			return $result;
226 liveuser 11017
 
42 liveuser 11018
			}#if end
226 liveuser 11019
 
406 liveuser 11020
		#函式說明:
11021
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3 liveuser 11022
		#回傳結果:
11023
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
406 liveuser 11024
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11025
		#$result["function"],當前執行的函式名稱.
11026
		#$result["argu"],所使用的參數.
11027
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
11028
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
11029
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
3 liveuser 11030
		#必填參數:
406 liveuser 11031
		#$conf["input"],字串,要檢查的字串.
11032
		$conf["search::findSpecifyStrFormat"]["input"]=$result["content"];
11033
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
11034
		$conf["search::findSpecifyStrFormat"]["format"]="\${path}/tmp/qbpwcf_tmpfile_\${randomStr}";
3 liveuser 11035
		#可省略參數:
406 liveuser 11036
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
11037
		#$conf["varEqual"]=array(null,"found");
11038
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
11039
		#$conf["varCon"]=array("no_tail"=>" not");
3 liveuser 11040
		#參考資料:
11041
		#無.
11042
		#備註:
11043
		#無.
406 liveuser 11044
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
11045
		unset($conf["search::findSpecifyStrFormat"]);
226 liveuser 11046
 
406 liveuser 11047
		#如果執行異常
11048
		if($findSpecifyStrFormat["status"]==="false"){
11049
 
3 liveuser 11050
			#設置執行失敗
11051
			$result["status"]="false";
11052
 
11053
			#設置執行錯誤訊息
406 liveuser 11054
			$result["error"]=$findSpecifyStrFormat;
226 liveuser 11055
 
3 liveuser 11056
			#回傳結果
11057
			return $result;
406 liveuser 11058
 
3 liveuser 11059
			}#if end
406 liveuser 11060
 
11061
		#如果執行異常
11062
		if($findSpecifyStrFormat["found"]==="false"){
11063
 
3 liveuser 11064
			#設置執行失敗
11065
			$result["status"]="false";
11066
 
11067
			#設置執行錯誤訊息
406 liveuser 11068
			$result["error"]=$findSpecifyStrFormat;
226 liveuser 11069
 
3 liveuser 11070
			#回傳結果
11071
			return $result;
406 liveuser 11072
 
3 liveuser 11073
			}#if end
226 liveuser 11074
 
3 liveuser 11075
		#取得檔案名稱
406 liveuser 11076
		$result["fileName"]="qbpwcf_tmpfile_".$findSpecifyStrFormat["parsedVar"]["randomStr"][0];
226 liveuser 11077
 
3 liveuser 11078
		#函式說明:
11079
		#將字串特定關鍵字與其後面的內容剔除
11080
		#回傳結果:
11081
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11082
		#$result["error"],錯誤訊息陣列.
11083
		#$result["warning"],警告訊息鎮列.
11084
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
11085
		#$result["function"],當前執行的函數名稱.
11086
		#$result["oriStr"],要處理的原始字串內容.
11087
		#$result["content"],處理好的的字串內容.
11088
		#$result["argu"],使用的參數.
11089
		#必填參數:
11090
		#$conf["stringIn"],字串,要處理的字串.
11091
		$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$result["content"];
11092
		#$conf["keyWord"],字串,特定字串.
11093
		$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["fileName"];
11094
		#可省略參數:
11095
		#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
11096
		#$conf["deleteLastRepeatedOne"]="";
11097
		#參考資料:
11098
		#無.
11099
		#備註:
11100
		#無.
11101
		$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
11102
		unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 11103
 
3 liveuser 11104
		#如果執行失敗
11105
		if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 11106
 
3 liveuser 11107
			#設置執行失敗
11108
			$result["status"]="false";
11109
 
11110
			#設置執行錯誤訊息
11111
			$result["error"]=$delStrAfterKeyWord;
226 liveuser 11112
 
3 liveuser 11113
			#回傳結果
11114
			return $result;
226 liveuser 11115
 
3 liveuser 11116
			}#if end
226 liveuser 11117
 
3 liveuser 11118
		#如果應該要存在的檔案名稱關鍵字不在
11119
		if($delStrAfterKeyWord["founded"]==="false"){
226 liveuser 11120
 
3 liveuser 11121
			#設置執行失敗
11122
			$result["status"]="false";
11123
 
11124
			#設置執行錯誤訊息
11125
			$result["error"]=$delStrAfterKeyWord;
226 liveuser 11126
 
3 liveuser 11127
			#回傳結果
11128
			return $result;
226 liveuser 11129
 
3 liveuser 11130
			}#if end
226 liveuser 11131
 
3 liveuser 11132
		#取得路徑
11133
		$result["path"]=$delStrAfterKeyWord["content"];
226 liveuser 11134
 
36 liveuser 11135
		#如果有內容要寫入
11136
		if(!empty($conf["content"])){
226 liveuser 11137
 
36 liveuser 11138
			#函式說明:
11139
			#將多行字串寫入到檔案
11140
			#回傳結果:
11141
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
11142
			#$result["error"],錯誤訊息陣列.
11143
			#$result["function"],當前執行函數的名稱.
11144
			#必填參數:
11145
			#$conf["fileName"],字串,爲要編輯的檔案名稱
11146
			$conf["fileAccess::writeMultiLine"]["fileName"]=$result["content"];
11147
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
11148
			$conf["fileAccess::writeMultiLine"]["inputString"]=$conf["content"];
11149
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11150
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=__FILE__;
11151
			#可省略參數:
11152
			#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
11153
			#參考資料:
11154
			#無.
11155
			#備註:
11156
			#無.
11157
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
11158
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 11159
 
36 liveuser 11160
			#如果執行失敗
11161
			if($writeMultiLine["status"]==="false"){
226 liveuser 11162
 
36 liveuser 11163
				#設置執行失敗
11164
				$result["status"]="false";
11165
 
11166
				#設置執行錯誤訊息
11167
				$result["error"]=$writeMultiLine;
226 liveuser 11168
 
36 liveuser 11169
				#回傳結果
11170
				return $result;
226 liveuser 11171
 
36 liveuser 11172
				}#if end
226 liveuser 11173
 
36 liveuser 11174
			}#if end
226 liveuser 11175
 
3 liveuser 11176
		#設置執行正常
11177
		$result["status"]="true";
226 liveuser 11178
 
3 liveuser 11179
		#回傳結果
11180
		return $result;
226 liveuser 11181
 
3 liveuser 11182
		}#function createTempFile end
11183
 
11184
	/*
11185
	#函式說明:
253 liveuser 11186
	#複製檔案、資料夾,只要符合權限就會執行並覆蓋既有內容.
11187
	#回傳結果:
11188
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11189
	#$result["error"],錯誤訊息.
11190
	#$result["function"],當前執行的函式名稱.
11191
	#$result["content"],複製好的檔案路徑與名稱.
11192
	#必填參數:
11193
	#$conf["file"],字串,檔案的位置與名稱.
11194
	$conf["file"]="";
11195
	#$conf["to"],字串,檔案要複製到哪裡.
11196
	$conf["to"]="";
11197
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
11198
	$conf["fileArgu"]=__FILE__;
11199
	#可省略參數:
11200
	#無.
11201
	#參考資料:
11202
	#無.
11203
	#備註:
11204
	#等同於cmd::cp的應用.
11205
	*/
11206
	public static function cp(&$conf){
11207
 
11208
		#初始化要回傳的結果
11209
		$result=array();
11210
 
11211
		#取得當前執行的函式名稱
11212
		$result["function"]=__FUNCTION__;
11213
 
11214
		#如果沒有參數
11215
		if(func_num_args()==0){
11216
 
11217
			#設置執行失敗
11218
			$result["status"]="false";
11219
 
11220
			#設置執行錯誤訊息
11221
			$result["error"]="函式".$result["function"]."需要參數";
11222
 
11223
			#回傳結果
11224
			return $result;
11225
 
11226
			}#if end
11227
 
11228
		#取得參數
11229
		$result["argu"]=$conf;
11230
 
11231
		#如果 $conf 不為陣列
11232
		if(gettype($conf)!=="array"){
11233
 
11234
			#設置執行失敗
11235
			$result["status"]="false";
11236
 
11237
			#設置執行錯誤訊息
11238
			$result["error"][]="\$conf變數須為陣列形態";
11239
 
11240
			#如果傳入的參數為 null
11241
			if($conf===null){
11242
 
11243
				#設置執行錯誤訊息
11244
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
11245
 
11246
				}#if end
11247
 
11248
			#回傳結果
11249
			return $result;
11250
 
11251
			}#if end
11252
 
11253
		#檢查參數
11254
		#函式說明:
11255
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
11256
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11257
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11258
		#$result["function"],當前執行的函式名稱.
11259
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11260
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11261
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11262
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11263
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11264
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11265
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11266
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11267
		#必填寫的參數:
11268
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11269
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11270
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11271
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","to","fileArgu");
11272
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11273
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
11274
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11275
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11276
		#可以省略的參數:
11277
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11278
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11279
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11280
		#$conf["canNotBeEmpty"]=array();
11281
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11282
		#$conf["canBeEmpty"]=array();
11283
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11284
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11285
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11286
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","cmdOnly");
11287
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
11288
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
11289
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11290
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null,"true");
11291
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11292
		#$conf["arrayCountEqualCheck"][]=array();
11293
		#參考資料來源:
11294
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11295
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11296
		unset($conf["variableCheck::checkArguments"]);
11297
 
11298
		#如果參數檢查失敗
11299
		if($checkArguments["status"]==="false"){
11300
 
11301
			#設置執行不正常
11302
			$result["status"]="false";
11303
 
11304
			#設置執行錯誤
11305
			$result["error"]=$checkArguments;
11306
 
11307
			#回傳結果
11308
			return $result;
11309
 
11310
			}#if end
11311
 
11312
		#如果參數檢查不通過
11313
		if($checkArguments["passed"]==="false"){
11314
 
11315
			#設置執行不正常
11316
			$result["status"]="false";
11317
 
11318
			#設置執行錯誤
11319
			$result["error"]=$checkArguments;
11320
 
11321
			#回傳結果
11322
			return $result;
11323
 
11324
			}#if end
11325
 
11326
		#函式說明:
11327
		#複製檔案、資料夾,只要符合權限就會執行並覆蓋既有內容.
11328
		#回傳結果:
11329
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11330
		#$result["error"],錯誤訊息.
11331
		#$result["function"],當前執行的函式名稱.
11332
		#$result["content"],複製好的檔案路徑與名稱.
11333
		#必填參數:
11334
		#$conf["file"],字串,檔案的位置與名稱.
11335
		$conf["cmd::cp"]["file"]=$conf["file"];
11336
		#$conf["to"],字串,檔案要複製到哪裡.
11337
		$conf["cmd::cp"]["to"]=$conf["to"];
11338
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
11339
		$conf["cmd::cp"]["fileArgu"]=$conf["fileArgu"];
11340
		#可省略參數:
11341
		#$conf["cmdOnly"],字串,是否要只允許在cmd環境下運行,預設為"true",代表是;"false"代表沒有限制.
11342
		$conf["cmd::cp"]["cmdOnly"]="false";
11343
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
11344
		#$conf["username"]="";
11345
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
11346
		#$conf["password"]="";
11347
		#參考資料:
11348
		#無.
11349
		#備註:
11350
		#無.
11351
		$cp=cmd::cp($conf["cmd::cp"]);
11352
		unset($conf["cmd::cp"]);
11353
 
11354
		#如果執行異常
11355
		if($cp["status"]==="false"){
11356
 
11357
			#設置執行不正常
11358
			$result["status"]="false";
11359
 
11360
			#設置執行錯誤
11361
			$result["error"]=$cp;
11362
 
11363
			#回傳結果
11364
			return $result;
11365
 
11366
			}#if end
11367
 
11368
		#設置要回傳的 content
11369
		$result["content"]=$cp["content"];
11370
 
11371
		#設置執行正常
11372
		$result["status"]="true";
11373
 
11374
		#回傳結果
11375
		return $result;
11376
 
11377
		}#function cp end
11378
 
11379
	/*
11380
	#函式說明:
3 liveuser 11381
	#分割檔案,分割出來的檔案名稱編號為aa, ab ac...ba, bb, bc...,zx, zy, zz的順序.
11382
	#回傳結果:
11383
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11384
	#$result["error"],錯誤訊息陣列.
11385
	#$result["function"],當前執行的函數名稱.
11386
	#$result["cmd"],執行的指令.
11387
	#$result["content"],執行指令回傳的結果.
11388
	#必填參數:
11389
	#$conf["file"],字串,要分割的檔案名稱.
226 liveuser 11390
	$conf["file"]="";
3 liveuser 11391
	#可省略參數:
11392
	#$conf["splitNameHead"],字串,分割成檔案的名稱開頭,預設為 $conf["file"]."-" .
226 liveuser 11393
	#$conf["splitNameHead"]="";
3 liveuser 11394
	#$conf["partSize"],字串,分割檔的大小為多少?可以為XMB,XGB,XKB,可參見split指令的說明,預設為50MB.
11395
	#$conf["partSize"]="";
11396
	#參考資料:
11397
	#無.
11398
	#備註:
11399
	#需要有split指令
11400
	*/
11401
	public static function split(&$conf=array()){
226 liveuser 11402
 
3 liveuser 11403
		#初始化要回傳的結果
11404
		$result=array();
11405
 
11406
		#取得當前執行的函數名稱
11407
		$result["function"]=__FUNCTION__;
11408
 
11409
		#如果沒有參數
11410
		if(func_num_args()==0){
226 liveuser 11411
 
3 liveuser 11412
			#設置執行失敗
11413
			$result["status"]="false";
226 liveuser 11414
 
3 liveuser 11415
			#設置執行錯誤訊息
11416
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 11417
 
3 liveuser 11418
			#回傳結果
11419
			return $result;
226 liveuser 11420
 
3 liveuser 11421
			}#if end
11422
 
11423
		#函式說明:
11424
		#判斷當前環境為web還是cmd
11425
		#回傳結果:
11426
		#$result,"web"或"cmd"
11427
		if(csInformation::getEnv()==="web"){
226 liveuser 11428
 
3 liveuser 11429
			#設置執行失敗
11430
			$result["status"]="false";
226 liveuser 11431
 
3 liveuser 11432
			#設置執行錯誤訊息
11433
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
226 liveuser 11434
 
3 liveuser 11435
			#回傳結果
11436
			return $result;
226 liveuser 11437
 
3 liveuser 11438
			}#if end
226 liveuser 11439
 
3 liveuser 11440
		#取得參數
11441
		$result["argu"]=$conf;
11442
 
11443
		#如果 $conf 不為陣列
11444
		if(gettype($conf)!=="array"){
226 liveuser 11445
 
3 liveuser 11446
			#設置執行失敗
11447
			$result["status"]="false";
226 liveuser 11448
 
3 liveuser 11449
			#設置執行錯誤訊息
11450
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 11451
 
3 liveuser 11452
			#如果傳入的參數為 null
11453
			if($conf===null){
226 liveuser 11454
 
3 liveuser 11455
				#設置執行錯誤訊息
11456
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 11457
 
3 liveuser 11458
				}#if end
11459
 
11460
			#回傳結果
11461
			return $result;
226 liveuser 11462
 
3 liveuser 11463
			}#if end
226 liveuser 11464
 
3 liveuser 11465
		#檢查參數
11466
		#函式說明:
11467
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
11468
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11469
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11470
		#$result["function"],當前執行的函式名稱.
11471
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11472
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11473
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11474
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11475
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11476
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11477
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11478
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11479
		#必填寫的參數:
11480
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11481
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11482
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11483
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file");
11484
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11485
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
11486
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11487
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11488
		#可以省略的參數:
11489
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11490
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11491
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11492
		#$conf["canNotBeEmpty"]=array();
11493
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11494
		#$conf["canBeEmpty"]=array();
11495
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11496
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11497
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11498
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("splitNameHead","partSize");
226 liveuser 11499
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 11500
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
11501
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]",若後面需要加上內容,則可以再補上\",後面再補上要串接的內容.
11502
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"file\"]\"-","50MB");
11503
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11504
		#$conf["arrayCountEqualCheck"][]=array();
11505
		#參考資料來源:
11506
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11507
		#建議:
11508
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
11509
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11510
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 11511
 
3 liveuser 11512
		#如果檢查參數失敗
11513
		if($checkArguments["status"]==="false"){
226 liveuser 11514
 
3 liveuser 11515
			#設置執行失敗
11516
			$result["status"]="false";
226 liveuser 11517
 
3 liveuser 11518
			#設置錯誤訊息
11519
			$result["error"]=$checkArguments;
226 liveuser 11520
 
3 liveuser 11521
			#回傳結果
11522
			return $result;
226 liveuser 11523
 
3 liveuser 11524
			}#if end
226 liveuser 11525
 
3 liveuser 11526
		#如果要分割的檔案存在
11527
		if(file_exists($conf["file"])){
226 liveuser 11528
 
3 liveuser 11529
			#取得執行的指令
11530
			$result["cmd"]="split -b ".$conf["partSize"]." '".$conf["file"]."' '".$conf["splitNameHead"]."'";
11531
 
11532
			#執行還原的指令
11533
			exec($result["cmd"],$output,$status);
11534
 
11535
			#取得執行後的輸出
11536
			$result["content"]=$output;
226 liveuser 11537
 
3 liveuser 11538
			}#if end
226 liveuser 11539
 
3 liveuser 11540
		#反之
11541
		else{
226 liveuser 11542
 
3 liveuser 11543
			#設置執行失敗
11544
			$result["status"]="false";
226 liveuser 11545
 
3 liveuser 11546
			#設置執行錯誤訊息
11547
			$result["error"][]="要分割的檔案「".$conf["file"]."」不存在";
226 liveuser 11548
 
3 liveuser 11549
			#回傳結果
11550
			return $result;
226 liveuser 11551
 
3 liveuser 11552
			}#else end
226 liveuser 11553
 
3 liveuser 11554
		#設置執行正常
11555
		$result["status"]="true";
226 liveuser 11556
 
3 liveuser 11557
		#回傳結果
11558
		return $result;
226 liveuser 11559
 
3 liveuser 11560
		}#function split end
11561
 
11562
	/*
11563
	#函式說明:
11564
	#合併檔案,檔案編號為aa, ab ac...ba, bb, bc...,zx, zy, zz的順序.
11565
	#回傳結果:
11566
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11567
	#$result["error"],錯誤訊息陣列.
11568
	#$result["function"],當前執行的函數名稱.
11569
	#$result["cmd"],執行的指令.
11570
	#$result["content"],執行指令回傳的結果.
11571
	#必填參數:
11572
	#$conf["filePartHead"],字串,分割檔案的名稱開頭.
11573
	$conf["filePartHead"]="";
11574
	#$conf["oriFileName"],字串,合併後的檔案名稱.
11575
	$conf["oriFileName"]="";
11576
	#可省略參數:
11577
	#無
11578
	#參考資料:
11579
	#無.
11580
	#備註:
11581
	#需要有cat指令.
11582
	#僅能在命令列執行.
11583
	*/
11584
	public static function merge(&$conf=array()){
226 liveuser 11585
 
3 liveuser 11586
		#初始化要回傳的結果
11587
		$result=array();
11588
 
11589
		#取得當前執行的函數名稱
11590
		$result["function"]=__FUNCTION__;
11591
 
11592
		#如果沒有參數
11593
		if(func_num_args()==0){
226 liveuser 11594
 
3 liveuser 11595
			#設置執行失敗
11596
			$result["status"]="false";
226 liveuser 11597
 
3 liveuser 11598
			#設置執行錯誤訊息
11599
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 11600
 
3 liveuser 11601
			#回傳結果
11602
			return $result;
226 liveuser 11603
 
3 liveuser 11604
			}#if end
11605
 
11606
		#函式說明:
11607
		#判斷當前環境為web還是cmd
11608
		#回傳結果:
11609
		#$result,"web"或"cmd"
11610
		if(csInformation::getEnv()==="web"){
226 liveuser 11611
 
3 liveuser 11612
			#設置執行失敗
11613
			$result["status"]="false";
226 liveuser 11614
 
3 liveuser 11615
			#設置執行錯誤訊息
11616
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
226 liveuser 11617
 
3 liveuser 11618
			#回傳結果
11619
			return $result;
226 liveuser 11620
 
3 liveuser 11621
			}#if end
226 liveuser 11622
 
3 liveuser 11623
		#取得參數
11624
		$result["argu"]=$conf;
11625
 
11626
		#如果 $conf 不為陣列
11627
		if(gettype($conf)!=="array"){
226 liveuser 11628
 
3 liveuser 11629
			#設置執行失敗
11630
			$result["status"]="false";
226 liveuser 11631
 
3 liveuser 11632
			#設置執行錯誤訊息
11633
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 11634
 
3 liveuser 11635
			#如果傳入的參數為 null
11636
			if($conf===null){
226 liveuser 11637
 
3 liveuser 11638
				#設置執行錯誤訊息
11639
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 11640
 
3 liveuser 11641
				}#if end
11642
 
11643
			#回傳結果
11644
			return $result;
226 liveuser 11645
 
3 liveuser 11646
			}#if end
226 liveuser 11647
 
3 liveuser 11648
		#檢查參數
11649
		#函式說明:
11650
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
11651
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11652
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11653
		#$result["function"],當前執行的函式名稱.
11654
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11655
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11656
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11657
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11658
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11659
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11660
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11661
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11662
		#必填寫的參數:
11663
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11664
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11665
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11666
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePartHead","oriFileName");
11667
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11668
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
11669
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11670
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11671
		#可以省略的參數:
11672
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11673
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11674
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11675
		#$conf["canNotBeEmpty"]=array();
11676
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11677
		#$conf["canBeEmpty"]=array();
11678
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11679
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11680
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11681
		#$conf["skipableVariableName"]=array();
226 liveuser 11682
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 11683
		#$conf["skipableVariableType"]=array();
11684
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11685
		#$conf["skipableVarDefaultValue"]=array("");
11686
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11687
		#$conf["arrayCountEqualCheck"][]=array();
11688
		#參考資料來源:
11689
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11690
		#建議:
11691
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
11692
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11693
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 11694
 
3 liveuser 11695
		#如果檢查參數失敗
11696
		if($checkArguments["status"]==="false"){
226 liveuser 11697
 
3 liveuser 11698
			#設置執行失敗
11699
			$result["status"]="false";
226 liveuser 11700
 
3 liveuser 11701
			#設置錯誤訊息
11702
			$result["error"]=$checkArguments;
226 liveuser 11703
 
3 liveuser 11704
			#回傳結果
11705
			return $result;
226 liveuser 11706
 
3 liveuser 11707
			}#if end
226 liveuser 11708
 
3 liveuser 11709
		#定義編號
11710
		$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");
11711
 
11712
		#定義分割檔案的前置字串
11713
		$filePartHead=$conf["filePartHead"];
11714
 
11715
		#要合併成的檔案名稱
11716
		$oriFileName=$conf["oriFileName"];
11717
 
11718
		#初始化要執行合併的語法
11719
		$restoreCmd="cat ";
11720
 
11721
		#有幾個編號就執行幾次
11722
		for($i=0;$i<count($charArray);$i++){
11723
 
11724
			#有幾個編號就執行幾次
11725
			for($j=0;$j<count($charArray);$j++){
11726
 
11727
				#如果該分割檔存在
11728
				if(file_exists($filePartHead.$charArray[$i].$charArray[$j])){
11729
 
11730
					#串接要還原的分割檔
11731
					$restoreCmd=$restoreCmd." '".$filePartHead.$charArray[$i].$charArray[$j]."'";
11732
 
11733
					}#if end
11734
 
11735
				#反之
11736
				else{
11737
 
11738
					#如果是第一個分割檔就找不到
11739
					if($i===0 && $j===0){
226 liveuser 11740
 
3 liveuser 11741
						#設置執行失敗
11742
						$result["status"]="false";
226 liveuser 11743
 
3 liveuser 11744
						#設置錯誤訊息
11745
						$result["error"][]="找不到第一個分割檔「".$filePartHead.$charArray[$i].$charArray[$j]."」";
226 liveuser 11746
 
3 liveuser 11747
						#回傳結果
11748
						return $result;
226 liveuser 11749
 
3 liveuser 11750
						}#if end
11751
 
11752
					#串接要還原成的檔案名稱
11753
					$restoreCmd=$restoreCmd." > '".$oriFileName."'";
11754
 
11755
					#取得執行的指令
11756
					$result["cmd"]=$restoreCmd;
11757
 
11758
					#執行還原的指令
11759
					exec($restoreCmd,$output,$status);
11760
 
11761
					#取得執行後的輸出
11762
					$result["content"]=$output;
11763
 
11764
					#結束回圈
11765
					break 2;
226 liveuser 11766
 
3 liveuser 11767
					}#else end
11768
 
11769
				}#for end
11770
 
11771
			}#for end
226 liveuser 11772
 
3 liveuser 11773
		#設置執行正常
11774
		$result["status"]="true";
226 liveuser 11775
 
3 liveuser 11776
		#回傳結果
11777
		return $result;
226 liveuser 11778
 
3 liveuser 11779
		}#function merge end
11780
 
11781
	/*
11782
	#函式說明:
11783
	#取得檔案的部分內容
11784
	#回傳結果:
11785
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11786
	#$result["error"],錯誤訊息陣列.
11787
	#$result["function"],當前執行的函數名稱.
11788
	#$result["cmd"],執行的指令.
11789
	#$result["content"],取得的檔案內容.
11790
	#$result["length"],取得的內容長度.
11791
	#$result["EOF"],識別是否已經到檔案結尾,"true"代表是,"false"代表不是.
11792
	#$result["mimeType"],檔案的 mime type.
11793
	#必填參數:
11794
	#$conf["file"],字串,檔案的路徑與名稱.
11795
	$conf["file"]="";
11796
	#$conf["fileArgu"],字串,__FILE__的內容.
11797
	$conf["fileArgu"]=__FILE__;
11798
	#$conf["bytes"],整數字串,要讀取多少bytes.
11799
	$conf["bytes"]="";
11800
	#$conf["startIndex"],要從哪個bytes位置開始,起始點為0.
11801
	$conf["startIndex"]="";
11802
	#可省略參數:
11803
	#無
11804
	#參考資料:
11805
	#無.
11806
	#備註:
11807
	#無
11808
	*/
11809
	public static function getFilePart(&$conf){
226 liveuser 11810
 
3 liveuser 11811
		#初始化要回傳的結果
11812
		$result=array();
11813
 
11814
		#取得當前執行的函數名稱
11815
		$result["function"]=__FUNCTION__;
11816
 
11817
		#如果沒有參數
11818
		if(func_num_args()==0){
11819
 
11820
			#設置執行失敗
11821
			$result["status"]="false";
11822
 
11823
			#設置執行錯誤訊息
11824
			$result["error"]="函數".$result["function"]."需要參數";
11825
 
11826
			#回傳結果
11827
			return $result;
11828
 
11829
			}#if end
226 liveuser 11830
 
3 liveuser 11831
		#取得參數
11832
		$result["argu"]=$conf;
11833
 
11834
		#如果 $conf 不為陣列
11835
		if(gettype($conf)!=="array"){
11836
 
11837
			#設置執行失敗
11838
			$result["status"]="false";
11839
 
11840
			#設置執行錯誤訊息
11841
			$result["error"][]="\$conf變數須為陣列形態";
11842
 
11843
			#如果傳入的參數為 null
11844
			if(is_null($conf)){
11845
 
11846
				#設置執行錯誤訊息
11847
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
11848
 
11849
				}#if end
11850
 
11851
			#回傳結果
11852
			return $result;
11853
 
11854
			}#if end
226 liveuser 11855
 
3 liveuser 11856
		#函式說明:
11857
		#檢查多個檔案與資料夾是否存在.
11858
		#回傳的結果:
11859
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
11860
		#$result["error"],錯誤訊息陣列.
11861
		#$resutl["function"],當前執行的涵式名稱.
11862
		#$result["argu"],使用的參數.
11863
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
11864
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
11865
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
11866
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
11867
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
11868
		#必填參數:
11869
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
11870
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
11871
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11872
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
11873
		#可省略參數:
11874
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
11875
		#$conf["disableWebSearch"]="false";
11876
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
11877
		#$conf["userDir"]="true";
11878
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
11879
		#$conf["web"]="true";
11880
		#參考資料:
11881
		#http://php.net/manual/en/function.file-exists.php
11882
		#http://php.net/manual/en/control-structures.foreach.php
11883
		#備註:
11884
		#函數file_exists檢查的路徑為檔案系統的路徑
11885
		#$result["varName"][$i]結果未實作
11886
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
11887
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 11888
 
3 liveuser 11889
		#如果執行失敗
11890
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 11891
 
3 liveuser 11892
			#設置執行失敗
11893
			$result["status"]="false";
226 liveuser 11894
 
3 liveuser 11895
			#設置執行錯誤訊息
11896
			$result["error"]=$checkMultiFileExist;
226 liveuser 11897
 
3 liveuser 11898
			#回傳結果
11899
			return $result;
226 liveuser 11900
 
3 liveuser 11901
			}#if end
226 liveuser 11902
 
3 liveuser 11903
		#如果檔案不存在
11904
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 11905
 
3 liveuser 11906
			#設置執行失敗
11907
			$result["status"]="false";
226 liveuser 11908
 
3 liveuser 11909
			#設置執行錯誤訊息
11910
			$result["error"]=$checkMultiFileExist;
226 liveuser 11911
 
3 liveuser 11912
			#回傳結果
11913
			return $result;
226 liveuser 11914
 
3 liveuser 11915
			}#if end
226 liveuser 11916
 
3 liveuser 11917
		#取得mimetype
11918
		$mimetype=mime_content_type($conf["file"]);
226 liveuser 11919
 
3 liveuser 11920
		#取得檔案的 mime type
11921
		$result["mimeType"]=$mimetype;
226 liveuser 11922
 
3 liveuser 11923
		#透過 dd 指令,取得部分內容.
11924
		#函式說明:
11925
		#呼叫shell執行系統命令,並取得回傳的內容.
11926
		#回傳結果:
11927
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11928
		#$result["error"],錯誤訊息陣列.
11929
		#$result["function"],當前執行的函數名稱.
11930
		#$result["argu"],使用的參數.
11931
		#$result["cmd"],執行的指令內容.
11932
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11933
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11934
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11935
		#$result["running"],是否還在執行.
11936
		#$result["pid"],pid.
11937
		#$result["statusCode"],執行結束後的代碼.
11938
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11939
		#必填參數:
11940
		#$conf["command"],字串,要執行的指令.
11941
		$conf["external::callShell"]["command"]="dd";
11942
		#$conf["fileArgu"],字串,變數__FILE__的內容.
11943
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
11944
		#可省略參數:
11945
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11946
		$conf["external::callShell"]["argu"]=array("if=".$conf["file"],"bs=".$conf["bytes"],"count=1","status=none");
11947
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11948
		#$conf["arguIsAddr"]=array();
11949
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11950
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11951
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11952
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11953
		#$conf["enablePrintDescription"]="true";
11954
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11955
		#$conf["printDescription"]="";
11956
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11957
		#$conf["escapeshellarg"]="false";
11958
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11959
		#$conf["thereIsShellVar"]=array();
11960
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11961
		#$conf["username"]="";
11962
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11963
		#$conf["password"]="";
11964
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11965
		#$conf["useScript"]="";
11966
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11967
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11968
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11969
		#$conf["inBackGround"]="";
11970
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11971
		#$conf["getErr"]="false";
11972
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11973
		#$conf["doNotRun"]="false";
11974
		#參考資料:
11975
		#exec=>http://php.net/manual/en/function.exec.php
11976
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11977
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11978
		#備註:
11979
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11980
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11981
		$callShell=external::callShell($conf["external::callShell"]);
11982
		unset($conf["external::callShell"]);
226 liveuser 11983
 
3 liveuser 11984
		#如果執行失敗
11985
		if($callShell["status"]==="false"){
226 liveuser 11986
 
3 liveuser 11987
			#設置執行失敗
11988
			$result["status"]="false";
226 liveuser 11989
 
3 liveuser 11990
			#設置執行錯誤訊息
11991
			$result["error"]=$callShell;
226 liveuser 11992
 
3 liveuser 11993
			#回傳結果
11994
			return $result;
226 liveuser 11995
 
3 liveuser 11996
			}#if end
226 liveuser 11997
 
3 liveuser 11998
		#取得結果
11999
		$result["content"]=$callShell["output"][0];
226 liveuser 12000
 
3 liveuser 12001
		#取得內容長度
12002
		$result["length"]=strlen($result["content"]);
226 liveuser 12003
 
12004
		#預設尚未到檔案結尾
3 liveuser 12005
		$result["EOF"]="false";
226 liveuser 12006
 
3 liveuser 12007
		#如果取得的內容長度小於預期
12008
		if($result["length"]<$conf["bytes"]){
226 liveuser 12009
 
3 liveuser 12010
			#設置已經到檔案結尾了
12011
			$result["EOF"]="true";
226 liveuser 12012
 
3 liveuser 12013
			}#if end
226 liveuser 12014
 
3 liveuser 12015
		#設置執行正常
12016
		$result["status"]="true";
226 liveuser 12017
 
3 liveuser 12018
		#回傳結果
12019
		return $result;
226 liveuser 12020
 
3 liveuser 12021
		}#function getFilePart end
12022
 
12023
	/*
12024
	#函式說明:
391 liveuser 12025
	#一次讀取一行純文字檔案的內容.
12026
	#回傳結果:
12027
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
12028
	#$result["error"],錯誤訊息陣列.
12029
	#$result["function"],當前執行的函數名稱.
12030
	#$result["cmd"],執行的指令.
12031
	#$result["content"],取得的檔案內容,若沒有內容則為null,反之為字串.
12032
	#$result["length"],取得的內容長度.
12033
	#$result["EOF"],識別是否已經到檔案結尾,"true"代表是,"false"代表不是.
12034
	#$result["nextLine"],整數,下一行的行號,亦即下次來讀取下一行時,lineStart參數要給予的數值.
12035
	#$result["fileSize"],整數,檔案的大小,用於下次來讀取下一行時,preFileSize參數要給予的數值.
12036
	#必填參數:
12037
	#$conf["file"],字串,檔案的路徑與名稱.
12038
	$conf["file"]="";
12039
	#可省略參數:
12040
	#$conf["lineStart"],整數,要從第幾行開始,起始點為1.
12041
	#$conf["lineStart"]=1;
12042
	#$conf["preFileSize"],整數,上次透過本函式取得的fileSize結果,用於確認檔案是否有被rotate過,預設不設置.
12043
	#$conf["preFileSize"]=;
12044
	#可省略參數:
12045
	#無
12046
	#參考資料:
12047
	#無.
12048
	#備註:
12049
	#無
12050
	*/
12051
	public static function getTextFilePart(&$conf){
12052
 
12053
		#初始化要回傳的結果
12054
		$result=array();
12055
 
12056
		#取得當前執行的函數名稱
12057
		$result["function"]=__FUNCTION__;
12058
 
12059
		#如果沒有參數
12060
		if(func_num_args()===0){
12061
 
12062
			#設置執行失敗
12063
			$result["status"]="false";
12064
 
12065
			#設置執行錯誤訊息
12066
			$result["error"]="函數".$result["function"]."需要參數";
12067
 
12068
			#回傳結果
12069
			return $result;
12070
 
12071
			}#if end
12072
 
12073
		#取得參數
12074
		$result["argu"]=$conf;
12075
 
12076
		#如果 $conf 不為陣列
12077
		if(gettype($conf)!=="array"){
12078
 
12079
			#設置執行失敗
12080
			$result["status"]="false";
12081
 
12082
			#設置執行錯誤訊息
12083
			$result["error"][]="\$conf變數須為陣列形態";
12084
 
12085
			#如果傳入的參數為 null
12086
			if(is_null($conf)){
12087
 
12088
				#設置執行錯誤訊息
12089
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
12090
 
12091
				}#if end
12092
 
12093
			#回傳結果
12094
			return $result;
12095
 
12096
			}#if end
12097
 
12098
		#函式說明:
12099
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
12100
		#回傳結果:
12101
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12102
		#$result["error"],執行不正常結束的錯訊息陣列.
12103
		#$result["simpleError"],簡單表示的錯誤訊息.
12104
		#$result["function"],當前執行的函式名稱.
12105
		#$result["argu"],設置給予的參數.
12106
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12107
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12108
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12109
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12110
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12111
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12112
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12113
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12114
		#必填參數:
12115
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12116
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12117
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12118
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12119
		#可省略參數:
12120
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12121
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file");
12122
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
12123
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
12124
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12125
		#$conf["canBeEmptyString"]="false";
12126
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12127
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("lineStart");
12128
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12129
		#$conf["canBeEmpty"]=array();
12130
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12131
		#$conf["skipableVariableCanNotBeEmpty"]=array();
12132
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12133
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("lineStart","preFileSize");
12134
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
12135
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer","integer");
12136
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12137
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(1,null);
12138
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12139
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12140
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12141
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12142
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
12143
		#$conf["disallowAllSkipableVarNotExist"]="";
12144
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12145
		#$conf["arrayCountEqualCheck"][]=array();
12146
		#參考資料:
12147
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12148
		#備註:
12149
		#無.
12150
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12151
		unset($conf["variableCheck::checkArguments"]);
12152
 
12153
		#如果執行異常
12154
		if($checkArguments["status"]==="false"){
12155
 
12156
			#設置執行失敗
12157
			$result["status"]="false";
12158
 
12159
			#設置執行錯誤訊息
12160
			$result["error"]=$checkArguments;
12161
 
12162
			#回傳結果
12163
			return $result;
12164
 
12165
			}#if end
12166
 
12167
		#如果參數檢查不通過
12168
		if($checkArguments["passed"]==="false"){
12169
 
12170
			#設置執行失敗
12171
			$result["status"]="false";
12172
 
12173
			#設置執行錯誤訊息
12174
			$result["error"]=$checkArguments;
12175
 
12176
			#回傳結果
12177
			return $result;
12178
 
12179
			}#if end
12180
 
12181
		#取得檔案資訊,包含檔案的大小
12182
		#函式說明:
12183
		#取得節點的資訊.
12184
		#回傳結果:
12185
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12186
		#$result["error"],錯誤訊息陣列.
12187
		#$result["function"],函數名稱.
12188
		#$result["content"],檔案資訊陣列.
12189
		#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
12190
		#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
12191
		#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
12192
		#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
12193
		#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
12194
		#$result["content"]["ownerName"],檔案擁有着資訊.
12195
		#$result["content"]["groupName"],檔案所屬擁有着資訊.
12196
		#$result["content"]["size"],檔案大小.
12197
		#$result["content"]["modifyDate"],檔案變更年月日.
12198
		#$result["content"]["modifyTime"],檔案變更時分秒.
12199
		#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
12200
		#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
12201
		#必填參數:
12202
		#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
12203
		$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;
12204
		#$conf["file"],字串,要查看擁有者資訊的檔案.
12205
		$conf["fileAccess::fileInfo"]["file"]=$conf["file"];
12206
		#可省略參數:
12207
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
12208
		$conf["fileAccess::fileInfo"]["web"]="false";
12209
		#參考資料:
12210
		#fileowner=>http://php.net/manual/en/function.fileowner.php
12211
		#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
12212
		#備註:
12213
		#無.
12214
		$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
12215
		unset($conf["fileAccess::fileInfo"]);
12216
 
12217
		#如果執行異常
12218
		if($fileInfo["status"]==="false"){
12219
 
12220
			#設置執行失敗
12221
			$result["status"]="false";
12222
 
12223
			#設置執行錯誤訊息
12224
			$result["error"]=$fileInfo;
12225
 
12226
			#回傳結果
12227
			return $result;
12228
 
12229
			}#if end
12230
 
12231
		#如果有設置
12232
		if(isset($conf["preFileSize"])){
12233
 
12234
			#如果檔案大小變小
12235
			if( $conf["preFileSize"] < (int)$fileInfo["content"]["size"] ){
12236
 
12237
				#代表檔案被 rotate 了
12238
 
12239
				#設置從頭開始讀取
12240
				$conf["lineStart"]=1;
12241
 
12242
				}#if end
12243
 
12244
			}#if end
12245
 
12246
		#取得檔案大小
12247
		$result["fileSize"]=$fileInfo["content"]["size"];
12248
 
12249
		#函式說明:
12250
		#呼叫shell執行系統命令,並取得回傳的內容.
12251
		#回傳結果:
12252
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12253
		#$result["error"],錯誤訊息陣列.
12254
		#$result["function"],當前執行的函數名稱.
12255
		#$result["argu"],使用的參數.
12256
		#$result["cmd"],執行的指令內容.
12257
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12258
		#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12259
		#$result["content"],為執行完後的輸出字串.
12260
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12261
		#$result["running"],是否還在執行.
12262
		#$result["pid"],pid.
12263
		#$result["statusCode"],執行結束後的代碼.
12264
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
12265
		#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
12266
		#必填參數:
12267
		#$conf["command"],字串,要執行的指令.
12268
		$conf["fileAccess::callShell"]["command"]="getContentByLineRange.php";
12269
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12270
		$conf["fileAccess::callShell"]["fileArgu"]=__FILE__;
12271
		#可省略參數:
12272
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12273
		$conf["fileAccess::callShell"]["argu"]=array($conf["lineStart"],$conf["lineStart"]+1,$conf["file"]);
12274
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12275
		#$conf["arguIsAddr"]=array();
12276
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
12277
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
12278
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
12279
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12280
		#$conf["enablePrintDescription"]="true";
12281
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
12282
		#$conf["printDescription"]="";
12283
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
12284
		$conf["fileAccess::callShell"]["escapeshellarg"]="true";
12285
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
12286
		#$conf["thereIsShellVar"]=array();
12287
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12288
		#$conf["username"]="";
12289
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12290
		#$conf["password"]="";
12291
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12292
		#$conf["useScript"]="";
12293
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12294
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12295
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12296
		#$conf["inBackGround"]="";
12297
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
12298
		#$conf["getErr"]="false";
12299
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
12300
		#$conf["doNotRun"]="false";
12301
		#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
12302
		#$conf["cmdContainArgu"]="false";
12303
		#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
12304
		#$conf["remoteIp"]="";
12305
		#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
12306
		#$conf["remoteUser"]="";
12307
		#$conf["sshOptions"],陣列,當具備 "remoteIp" 參數時,該參數每個元素為ssh指令的參數.
12308
		#$conf["sshOptions"]=array();
12309
		#參考資料:
12310
		#exec=>http://php.net/manual/en/function.exec.php
12311
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12312
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12313
		#備註:
12314
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12315
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
12316
		$callShell=external::callShell($conf["fileAccess::callShell"]);
12317
		unset($conf["fileAccess::callShell"]);
12318
 
12319
		#debug
12320
		#var_dump(__LINE__,$callShell);
12321
 
12322
		#預設尚未到檔案結尾
12323
		$result["EOF"]="false";
12324
 
12325
		#如果沒有內容
12326
		if(empty($callShell["output"])){
12327
 
12328
			#代表檔案被 rotate 了
12329
 
12330
			#設置到檔案結尾了
12331
			$result["EOF"]="true";
12332
 
12333
			#設置下一行的行號為當前行號
12334
			$result["nextLine"]=$conf["lineStart"];
12335
 
12336
			#設置沒有內容
12337
			$result["content"]=null;
12338
 
12339
			}#if end
12340
 
12341
		#反之
12342
		else{
12343
 
12344
			#取得行內容
12345
			$result["content"]=$callShell["output"][0];
12346
 
12347
			}#else end
12348
 
12349
		#如果沒有下一行的內容
12350
		if(!isset($callShell["output"][1])){
12351
 
12352
			#設置已經到檔案結尾了
12353
			$result["EOF"]="true";
12354
 
12355
			#設置下一行的行號為當前行號
12356
			$result["nextLine"]=$conf["lineStart"];
12357
 
12358
			}#if end
12359
 
12360
		#反之
12361
		else{
12362
 
12363
			#設置下一行的行號
12364
			$result["nextLine"]=$conf["lineStart"]+1;
12365
 
12366
			}#else end
12367
 
12368
		#儲存執行的指令內容
12369
		$result["cmd"]=$callShell["cmd"];
12370
 
12371
		#取得行內容長度
12372
		$result["length"]=strlen($result["content"]);
12373
 
12374
		#設置執行正常
12375
		$result["status"]="true";
12376
 
12377
		#回傳結果
12378
		return $result;
12379
 
12380
		}#function getTextFilePart end
12381
 
12382
	/*
12383
	#函式說明:
3 liveuser 12384
	#取得節點的資訊.
12385
	#回傳結果:
12386
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12387
	#$result["error"],錯誤訊息陣列.
226 liveuser 12388
	#$result["function"],函數名稱.
3 liveuser 12389
	#$result["content"],檔案資訊陣列.
226 liveuser 12390
	#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 12391
	#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
12392
	#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
12393
	#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
12394
	#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
12395
	#$result["content"]["ownerName"],檔案擁有着資訊.
12396
	#$result["content"]["groupName"],檔案所屬擁有着資訊.
391 liveuser 12397
	#$result["content"]["size"],字串,檔案大小.
3 liveuser 12398
	#$result["content"]["modifyDate"],檔案變更年月日.
12399
	#$result["content"]["modifyTime"],檔案變更時分秒.
12400
	#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
12401
	#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
12402
	#必填參數:
12403
	#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
12404
	$conf["fileArgu"]=__FILE__;
12405
	#$conf["file"],字串,要查看擁有者資訊的檔案.
12406
	$conf["file"]="";
12407
	#可省略參數:
12408
	#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
12409
	#$conf["web"]="true";
12410
	#參考資料:
12411
	#fileowner=>http://php.net/manual/en/function.fileowner.php
12412
	#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
12413
	#備註:
12414
	#無.
12415
	*/
12416
	public static function fileInfo(&$conf=array()){
226 liveuser 12417
 
3 liveuser 12418
		#初始化要回傳的結果
12419
		$result=array();
12420
 
12421
		#取得當前執行的函數名稱
12422
		$result["function"]=__FUNCTION__;
12423
 
12424
		#如果沒有參數
12425
		if(func_num_args()==0){
226 liveuser 12426
 
3 liveuser 12427
			#設置執行失敗
12428
			$result["status"]="false";
226 liveuser 12429
 
3 liveuser 12430
			#設置執行錯誤訊息
12431
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 12432
 
3 liveuser 12433
			#回傳結果
12434
			return $result;
226 liveuser 12435
 
3 liveuser 12436
			}#if end
12437
 
12438
		#取得參數
12439
		$result["argu"]=$conf;
12440
 
12441
		#如果 $conf 不為陣列
12442
		if(gettype($conf)!=="array"){
226 liveuser 12443
 
3 liveuser 12444
			#設置執行失敗
12445
			$result["status"]="false";
226 liveuser 12446
 
3 liveuser 12447
			#設置執行錯誤訊息
12448
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 12449
 
3 liveuser 12450
			#如果傳入的參數為 null
12451
			if($conf===null){
226 liveuser 12452
 
3 liveuser 12453
				#設置執行錯誤訊息
12454
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12455
 
3 liveuser 12456
				}#if end
12457
 
12458
			#回傳結果
12459
			return $result;
226 liveuser 12460
 
3 liveuser 12461
			}#if end
226 liveuser 12462
 
3 liveuser 12463
		#檢查參數
12464
		#函式說明:
12465
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12466
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12467
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12468
		#$result["function"],當前執行的函式名稱.
12469
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12470
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12471
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12472
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12473
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12474
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12475
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12476
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12477
		#必填寫的參數:
12478
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 12479
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 12480
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12481
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12482
		#可以省略的參數:
12483
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12484
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
12485
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12486
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
12487
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12488
		#$conf["canBeEmptyString"]="false";
12489
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12490
		#$conf["ileAccess::checkArguments"]["canNotBeEmpty"]=array();
12491
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12492
		#$conf["canBeEmpty"]=array();
12493
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12494
		#$conf["skipableVariableCanNotBeEmpty"]=array();
12495
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12496
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 12497
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12498
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
12499
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12500
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
12501
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12502
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12503
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12504
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12505
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12506
		#$conf["arrayCountEqualCheck"][]=array();
12507
		#參考資料來源:
12508
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12509
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12510
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 12511
 
3 liveuser 12512
		#如果檢查參數失敗
12513
		if($checkArguments["status"]==="false"){
226 liveuser 12514
 
3 liveuser 12515
			#設置執行失敗
12516
			$result["status"]="false";
226 liveuser 12517
 
3 liveuser 12518
			#設置執行錯誤訊息
12519
			$result["error"]=$checkArguments;
226 liveuser 12520
 
3 liveuser 12521
			#回傳結果
12522
			return $result;
226 liveuser 12523
 
3 liveuser 12524
			}#if end
226 liveuser 12525
 
3 liveuser 12526
		#如果檢查參數不通過
12527
		if($checkArguments["passed"]==="false"){
226 liveuser 12528
 
3 liveuser 12529
			#設置執行失敗
12530
			$result["status"]="false";
226 liveuser 12531
 
3 liveuser 12532
			#設置執行錯誤訊息
12533
			$result["error"]=$checkArguments;
226 liveuser 12534
 
3 liveuser 12535
			#回傳結果
12536
			return $result;
226 liveuser 12537
 
3 liveuser 12538
			}#if end
226 liveuser 12539
 
3 liveuser 12540
		#函式說明:
12541
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
12542
		#回傳結果:
12543
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12544
		#$result["error"],錯誤訊息陣列.
226 liveuser 12545
		#$result["function"],函數名稱.
3 liveuser 12546
		#$result["argu"],使用的參數.
12547
		#$result["content"],網址,若是在命令列執行,則為"null".
12548
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
12549
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
12550
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
12551
		#必填參數:
12552
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
12553
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["file"];
12554
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
12555
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
12556
		#可省略參數:
12557
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
12558
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
12559
		#備註:
12560
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
12561
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
12562
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 12563
 
3 liveuser 12564
		#如果取得位置失敗
12565
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 12566
 
3 liveuser 12567
			#設置執行失敗
12568
			$result["status"]="false";
226 liveuser 12569
 
3 liveuser 12570
			#設置執行錯誤訊息
12571
			$result["error"]=$getInternetAddressV2;
226 liveuser 12572
 
3 liveuser 12573
			#回傳結果
12574
			return $result;
226 liveuser 12575
 
3 liveuser 12576
			}#if end
12577
 
12578
		#函式說明:
12579
		#檢查多個檔案與資料夾是否存在.
12580
		#回傳的結果:
12581
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
12582
		#$result["error"],錯誤訊息陣列.
12583
		#$resutl["function"],當前執行的涵式名稱.
12584
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
12585
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
12586
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
12587
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
12588
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
12589
		#必填參數:
12590
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
12591
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($getInternetAddressV2["fileSystemAbsoulutePosition"]);
12592
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12593
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
12594
		#可省略參數
12595
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
12596
		#$conf["disableWebSearch"]="false";
12597
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
12598
		#$conf["userDir"]="true";
12599
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
12600
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
12601
		#參考資料來源:
12602
		#http://php.net/manual/en/function.file-exists.php
12603
		#http://php.net/manual/en/control-structures.foreach.php
12604
		#備註:
12605
		#函數file_exists檢查的路徑為檔案系統的路徑
12606
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
12607
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 12608
 
3 liveuser 12609
		#如果檢查檔案存在失敗
12610
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 12611
 
3 liveuser 12612
			#設置執行失敗
12613
			$result["status"]="false";
226 liveuser 12614
 
3 liveuser 12615
			#設置執行錯誤訊息
12616
			$result["error"]=$checkMultiFileExist;
226 liveuser 12617
 
3 liveuser 12618
			#回傳結果
12619
			return $result;
226 liveuser 12620
 
3 liveuser 12621
			}#if end
226 liveuser 12622
 
3 liveuser 12623
		#如果檔案不存在
12624
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 12625
 
3 liveuser 12626
			#設置執行失敗
12627
			$result["status"]="false";
226 liveuser 12628
 
3 liveuser 12629
			#設置執行錯誤訊息
12630
			$result["error"]=$checkMultiFileExist;
226 liveuser 12631
 
3 liveuser 12632
			#回傳結果
12633
			return $result;
226 liveuser 12634
 
3 liveuser 12635
			}#if end
226 liveuser 12636
 
3 liveuser 12637
		#透過ls指令取得檔案的資訊
12638
		#函式說明:
12639
		#呼叫shell執行系統命令,並取得回傳的內容.
12640
		#回傳的結果:
12641
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12642
		#$result["error"],錯誤訊息陣列.
12643
		#$result["function"],當前執行的函數名稱.
12644
		#$result["cmd"],執行的指令內容.
12645
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12646
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12647
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12648
		#$result["running"],是否還在執行.
12649
		#$result["pid"],pid
12650
		#必填的參數
12651
		#$conf["command"],字串,要執行的指令
12652
		$conf["external::callShell"]["command"]="ls";
12653
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12654
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
12655
		#可省略參數:
12656
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12657
		$conf["external::callShell"]["argu"]=array("-l","--full-time","-d",$conf["file"]);
12658
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12659
		$conf["external::callShell"]["arguIsAddr"]=array("false","false","false","false");
12660
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12661
		#$conf["enablePrintDescription"]="true";
12662
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
12663
		#$conf["printDescription"]="";
12664
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
12665
		$conf["external::callShell"]["escapeshellarg"]="true";
12666
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12667
		#$conf["username"]="";
12668
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12669
		#$conf["password"]="";
12670
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12671
		#$conf["useScript"]="";
12672
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12673
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12674
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12675
		#$conf["inBackGround"]="";
12676
		#備註:
12677
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12678
		#參考資料:
12679
		#exec=>http://php.net/manual/en/function.exec.php
12680
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12681
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12682
		$callShell=external::callShell($conf["external::callShell"]);
12683
		unset($conf["external::callShell"]);
226 liveuser 12684
 
3 liveuser 12685
		#如果執行失敗
12686
		if($callShell["status"]==="false"){
226 liveuser 12687
 
3 liveuser 12688
			#設置執行失敗
12689
			$result["status"]="false";
226 liveuser 12690
 
3 liveuser 12691
			#設置執行錯誤訊息
12692
			$result["error"]=$callShell;
226 liveuser 12693
 
3 liveuser 12694
			#回傳結果
12695
			return $result;
226 liveuser 12696
 
12697
			}#if end
12698
 
3 liveuser 12699
		#解析檔案資訊
12700
		#-rwxrwx--x. 1 apache apache 65K 2017-04-16 22:53:19.044545806 +0800 fileAccessT.php
226 liveuser 12701
 
3 liveuser 12702
		#取得權限資訊 -rwxrwx--x
12703
		$perm=substr($callShell["output"][0],0,strpos($callShell["output"][0],'.'));
226 liveuser 12704
 
3 liveuser 12705
		#如果是目錄
12706
		if(substr($perm,0,1)==="d"){
226 liveuser 12707
 
3 liveuser 12708
			#設定為目錄
12709
			$result["content"]["is_folder"]="true";
226 liveuser 12710
 
3 liveuser 12711
			}#if end
226 liveuser 12712
 
3 liveuser 12713
		#反之
12714
		else{
226 liveuser 12715
 
3 liveuser 12716
			#設定不為目錄
12717
			$result["content"]["is_folder"]="false";
226 liveuser 12718
 
3 liveuser 12719
			}#else end
226 liveuser 12720
 
3 liveuser 12721
		#解析檔案擁有者權限資訊
12722
		$result["content"]["ownerPerm"]=substr($perm,1,3);
226 liveuser 12723
 
3 liveuser 12724
		#如果檔案擁有者名稱為空
12725
		if(empty($result["content"]["ownerPerm"])){
226 liveuser 12726
 
3 liveuser 12727
			#設置執行失敗
12728
			$result["status"]="false";
226 liveuser 12729
 
3 liveuser 12730
			#設置執行錯誤訊息
12731
			$result["error"]=$callShell;
226 liveuser 12732
 
3 liveuser 12733
			#回傳結果
12734
			return $result;
226 liveuser 12735
 
3 liveuser 12736
			}#if end
226 liveuser 12737
 
3 liveuser 12738
		#解析檔案歸屬群組權限資訊
12739
		$result["content"]["groupPerm"]=substr($perm,4,3);
226 liveuser 12740
 
3 liveuser 12741
		#解析檔案對於其他身份使用者的權限資訊
12742
		$result["content"]["otherPerm"]=substr($perm,7,3);
226 liveuser 12743
 
3 liveuser 12744
		#取得目錄底下的檔案目錄數量起始點
12745
		$subElementStartPos=strpos($callShell["output"][0],' ');
226 liveuser 12746
 
3 liveuser 12747
		#取得目錄底下的檔案目錄數量結束點
12748
		$subElementEndPos=strpos($callShell["output"][0],' ',$subElementStartPos+1);
226 liveuser 12749
 
3 liveuser 12750
		#取得目錄底下的檔案目錄數量
12751
		$result["content"]["subElementCount"]=substr($callShell["output"][0],$subElementStartPos,$subElementEndPos-$subElementStartPos);
226 liveuser 12752
 
3 liveuser 12753
		#取得檔案擁有着資訊的起點
12754
		$ownerNameStrPos=strpos($callShell["output"][0],' ',$subElementEndPos)+1;
226 liveuser 12755
 
3 liveuser 12756
		#取得檔案擁有着資訊的結束點
12757
		$ownerNameEndPos=strpos($callShell["output"][0],' ',$ownerNameStrPos+1);
226 liveuser 12758
 
3 liveuser 12759
		#取得檔案擁有着資訊
12760
		$result["content"]["ownerName"]=substr($callShell["output"][0],$ownerNameStrPos,$ownerNameEndPos-$ownerNameStrPos);
226 liveuser 12761
 
3 liveuser 12762
		#取取得檔案群組擁有者資訊的起點
12763
		$groupNameStrPos=strpos($callShell["output"][0],' ',$ownerNameEndPos)+1;
226 liveuser 12764
 
3 liveuser 12765
		#取得檔案群組擁有者資訊的結束點
12766
		$groupNameEndPos=strpos($callShell["output"][0],' ',$groupNameStrPos);
226 liveuser 12767
 
3 liveuser 12768
		#取得檔案群組擁有者資訊
12769
		$result["content"]["groupName"]=substr($callShell["output"][0],$groupNameStrPos,$groupNameEndPos-$groupNameStrPos);
226 liveuser 12770
 
3 liveuser 12771
		#取得檔案大小的起點
12772
		$sizeStrPos=strpos($callShell["output"][0],' ',$groupNameEndPos)+1;
226 liveuser 12773
 
3 liveuser 12774
		#取得檔案大小的結束點
12775
		$sizeEndPos=strpos($callShell["output"][0],' ',$sizeStrPos);
226 liveuser 12776
 
3 liveuser 12777
		#取得檔案大小
12778
		$result["content"]["size"]=substr($callShell["output"][0],$sizeStrPos,$sizeEndPos-$sizeStrPos);
226 liveuser 12779
 
3 liveuser 12780
		#取得檔案變更年月日的起點
12781
		$modifyDateStrPos=strpos($callShell["output"][0],' ',$sizeEndPos)+1;
226 liveuser 12782
 
3 liveuser 12783
		#取得檔案變更年月日的結束點
12784
		$modifyDateEndPos=strpos($callShell["output"][0],' ',$modifyDateStrPos);
226 liveuser 12785
 
12786
		#取得檔案變更年月日
3 liveuser 12787
		$result["content"]["modifyDate"]=substr($callShell["output"][0],$modifyDateStrPos,$modifyDateEndPos-$modifyDateStrPos);
226 liveuser 12788
 
3 liveuser 12789
		#取得檔案變更時分秒的起點
12790
		$modifyTimeStrPos=strpos($callShell["output"][0],' ',$modifyDateEndPos)+1;
226 liveuser 12791
 
3 liveuser 12792
		#取得檔案變更時分秒的結束點
12793
		$modifyTimeEndPos=strpos($callShell["output"][0],'.',$modifyTimeStrPos);
226 liveuser 12794
 
3 liveuser 12795
		#取得檔案變更時分秒
12796
		$result["content"]["modifyTime"]=substr($callShell["output"][0],$modifyTimeStrPos,$modifyTimeEndPos-$modifyTimeStrPos);
226 liveuser 12797
 
3 liveuser 12798
		#取得檔版變更時間秒的float數值起點
12799
		$modifyTimeFloatStrPos=strpos($callShell["output"][0],'.',$modifyTimeEndPos)+1;
226 liveuser 12800
 
3 liveuser 12801
		#取得檔版變更時間秒的float數值結束點
12802
		$modifyTimeFloatEndPos=strpos($callShell["output"][0],' ',$modifyTimeFloatStrPos);
226 liveuser 12803
 
12804
		#取得檔版變更時間秒的float數值
3 liveuser 12805
		$result["content"]["modifyTimeFloat"]=substr($callShell["output"][0],$modifyTimeFloatStrPos,$modifyTimeFloatEndPos-$modifyTimeFloatStrPos);
226 liveuser 12806
 
3 liveuser 12807
		#取得時區起始點
12808
		$timezoneStrPos=strpos($callShell["output"][0],' ',$modifyTimeFloatEndPos)+1;
226 liveuser 12809
 
3 liveuser 12810
		#取得時區結束點
226 liveuser 12811
		$timezoneEndPos=strpos($callShell["output"][0],' ',$timezoneStrPos)+1;
12812
 
3 liveuser 12813
		#取得檔案變更時間的時區與UTC的差距.
226 liveuser 12814
		$result["content"]["timezone"]=substr($callShell["output"][0],$timezoneStrPos,$timezoneEndPos-$timezoneStrPos);
12815
 
3 liveuser 12816
		#設置執行正常
12817
		$result["status"]="true";
226 liveuser 12818
 
3 liveuser 12819
		#回傳結果
12820
		return $result;
226 liveuser 12821
 
3 liveuser 12822
		}#function fileInfo end
12823
 
12824
	/*
12825
	#函式說明:
226 liveuser 12826
	#依據函數getListTree執行的結果,將其底下與其子目錄底下的特定檔案內容依據目錄層級輸出成html檔案
3 liveuser 12827
	#回傳結果:
12828
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12829
	#$result["error"],錯誤訊息陣列.
226 liveuser 12830
	#$result["function"],函數名稱.
3 liveuser 12831
	#$result["content"],html檔案輸出的位置與名稱.
12832
	#必填參數:
12833
	#$conf["getListTree"],陣列變數,函數getListTree執行的結果.
12834
	$conf["getListTree"]=$getListTree;
12835
	#可省略參數:
12836
	#$conf["fileToRead"],字串,要讀取的檔案名稱為何?預設為"help".
12837
	#$conf["fileToRead"]="help";
12838
	#$conf["output"],字串,輸出的網頁檔案位置與名稱,副檔名html會自動補上,預設為"help".
226 liveuser 12839
	#$conf["output"]="help.html";
3 liveuser 12840
	#參考資料:
12841
	#無.
12842
	#備註:
12843
	#建構中...
12844
	*/
12845
	public static function createHelpFile($conf){
226 liveuser 12846
 
3 liveuser 12847
		#初始化要回傳的結果
12848
		$result=array();
226 liveuser 12849
 
3 liveuser 12850
		#設置當其函數名稱
12851
		$result["function"]=__FUNCTION__;
226 liveuser 12852
 
3 liveuser 12853
		#如果 $conf 不為陣列
12854
		if(gettype($conf)!="array"){
226 liveuser 12855
 
3 liveuser 12856
			#設置執行失敗
12857
			$result["status"]="false";
226 liveuser 12858
 
3 liveuser 12859
			#設置執行錯誤訊息
12860
			$result["error"][]="\$conf變數須為陣列形態";
12861
 
12862
			#如果傳入的參數為 null
12863
			if($conf==null){
226 liveuser 12864
 
3 liveuser 12865
				#設置執行錯誤訊息
12866
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12867
 
3 liveuser 12868
				}#if end
12869
 
12870
			#回傳結果
12871
			return $result;
226 liveuser 12872
 
3 liveuser 12873
			}#if end
226 liveuser 12874
 
3 liveuser 12875
		#檢查參數
12876
		#函式說明:
12877
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12878
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12879
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12880
		#$result["function"],當前執行的函式名稱.
12881
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12882
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12883
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12884
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
12885
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12886
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12887
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12888
		#必填寫的參數:
12889
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12890
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12891
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12892
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("getListTree");
226 liveuser 12893
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 12894
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
12895
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12896
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12897
		#可以省略的參數:
12898
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
12899
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
12900
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12901
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileToRead","output");
226 liveuser 12902
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12903
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
12904
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12905
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("help","help");
12906
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12907
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
12908
		#參考資料來源:
12909
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12910
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12911
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 12912
 
3 liveuser 12913
		#如果 $checkResult["status"] 等於 "fasle"
12914
		if($checkResult["status"]=="false"){
226 liveuser 12915
 
3 liveuser 12916
			#設置錯誤識別
12917
			$result["status"]="false";
226 liveuser 12918
 
3 liveuser 12919
			#設置錯誤訊息
12920
			$result["error"]=$checkResult;
226 liveuser 12921
 
3 liveuser 12922
			#回傳結果
12923
			return $result;
226 liveuser 12924
 
3 liveuser 12925
			}#if end
226 liveuser 12926
 
3 liveuser 12927
		#如果 $checkResult["passed"] 等於 "fasle"
12928
		if($checkResult["passed"]=="false"){
226 liveuser 12929
 
3 liveuser 12930
			#設置錯誤識別
12931
			$result["status"]="false";
226 liveuser 12932
 
3 liveuser 12933
			#設置錯誤訊息
12934
			$result["error"]=$checkResult;
226 liveuser 12935
 
3 liveuser 12936
			#回傳結果
12937
			return $result;
226 liveuser 12938
 
3 liveuser 12939
			}#if end
226 liveuser 12940
 
3 liveuser 12941
		#如果 $conf["getListTree"]["status"] 不存在
12942
		if(!isset($conf["getListTree"]["status"])){
226 liveuser 12943
 
3 liveuser 12944
			#設置錯誤識別
12945
			$result["status"]="false";
226 liveuser 12946
 
3 liveuser 12947
			#設置錯誤訊息
12948
			$result["error"][]="getListTree參數必須為getListTree函數執行後的結果";
226 liveuser 12949
 
3 liveuser 12950
			#回傳結果
12951
			return $result;
226 liveuser 12952
 
3 liveuser 12953
			}#if end
226 liveuser 12954
 
3 liveuser 12955
		#如果 $conf["getListTree"] 執行失敗
12956
		if($conf["getListTree"]["status"]=="false"){
226 liveuser 12957
 
3 liveuser 12958
			#設置錯誤識別
12959
			$result["status"]="false";
226 liveuser 12960
 
3 liveuser 12961
			#設置錯誤訊息
12962
			$result["error"]=$conf["getListTree"];
226 liveuser 12963
 
3 liveuser 12964
			#回傳結果
12965
			return $result;
226 liveuser 12966
 
3 liveuser 12967
			}#if end
226 liveuser 12968
 
3 liveuser 12969
		#如果有目錄檔案
12970
		if(isset($conf["getListTree"]["content"])){
226 liveuser 12971
 
12972
 
12973
 
3 liveuser 12974
			}#if end
226 liveuser 12975
 
3 liveuser 12976
		}#function createHelpFile end
226 liveuser 12977
 
3 liveuser 12978
	/*
12979
	#函式說明:
12980
	#嵌入pdf檔案到網頁上面
12981
	#回傳結果:
12982
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12983
	#$result["error"],錯誤訊息陣列.
226 liveuser 12984
	#$result["function"],函數名稱.
3 liveuser 12985
	#$result["content"],嵌入pdf檔案的語法
12986
	#必填參數:
12987
	#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
12988
	$conf["fileArgu"]=__FILE__;
12989
	#$conf["file"],字串,pdf檔案位置.
12990
	$conf["file"]="";
12991
	#可省略參數:
12992
	#$conf["type"],字串,要用"iframe"還是"object"的方式嵌入pdf檔案,預設為"iframe".
12993
	#$conf["type"]="iframe";
12994
	#參考資料:
12995
	#嵌入pdf到網頁=>https://stackoverflow.com/questions/14690000/embed-a-pdf-in-html5
12996
	#備註:
12997
	#如果是網址就會出錯.
12998
	*/
12999
	public static function embedPdf(&$conf=array()){
226 liveuser 13000
 
3 liveuser 13001
		#初始化要回傳的結果
13002
		$result=array();
13003
 
13004
		#取得當前執行的函數名稱
13005
		$result["function"]=__FUNCTION__;
13006
 
13007
		#如果沒有參數
13008
		if(func_num_args()==0){
226 liveuser 13009
 
3 liveuser 13010
			#設置執行失敗
13011
			$result["status"]="false";
226 liveuser 13012
 
3 liveuser 13013
			#設置執行錯誤訊息
13014
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 13015
 
3 liveuser 13016
			#回傳結果
13017
			return $result;
226 liveuser 13018
 
3 liveuser 13019
			}#if end
13020
 
13021
		#取得參數
13022
		$result["argu"]=$conf;
13023
 
13024
		#如果 $conf 不為陣列
13025
		if(gettype($conf)!=="array"){
226 liveuser 13026
 
3 liveuser 13027
			#設置執行失敗
13028
			$result["status"]="false";
226 liveuser 13029
 
3 liveuser 13030
			#設置執行錯誤訊息
13031
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 13032
 
3 liveuser 13033
			#如果傳入的參數為 null
13034
			if($conf===null){
226 liveuser 13035
 
3 liveuser 13036
				#設置執行錯誤訊息
13037
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 13038
 
3 liveuser 13039
				}#if end
13040
 
13041
			#回傳結果
13042
			return $result;
226 liveuser 13043
 
3 liveuser 13044
			}#if end
226 liveuser 13045
 
3 liveuser 13046
		#檢查參數
13047
		#函式說明:
13048
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13049
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13050
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13051
		#$result["function"],當前執行的函式名稱.
13052
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13053
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13054
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13055
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13056
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13057
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13058
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13059
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13060
		#必填寫的參數:
13061
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
13062
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
13063
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13064
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
13065
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13066
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
13067
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13068
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13069
		#可以省略的參數:
13070
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13071
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
13072
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13073
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("function");
13074
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13075
		#$conf["canBeEmpty"]=array();
13076
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13077
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("width","height");
13078
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13079
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("type");
226 liveuser 13080
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 13081
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
13082
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13083
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("iframe");
13084
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13085
		#$conf["arrayCountEqualCheck"][]=array();
13086
		#參考資料來源:
13087
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13088
		#建議:
13089
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
13090
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
226 liveuser 13091
		unset($conf["variableCheck::checkArguments"]);
13092
 
3 liveuser 13093
		#如果檢查參數失敗
13094
		if($checkArguments["status"]==="false"){
226 liveuser 13095
 
3 liveuser 13096
			#設置執行失敗
13097
			$result["status"]="false";
226 liveuser 13098
 
3 liveuser 13099
			#設置執行錯誤訊息
13100
			$result["error"]=$checkArguments;
226 liveuser 13101
 
3 liveuser 13102
			#回傳結果
13103
			return $result;
226 liveuser 13104
 
3 liveuser 13105
			}#if end
226 liveuser 13106
 
3 liveuser 13107
		#如果參數檢查不通過
13108
		if($checkArguments["passed"]==="false"){
226 liveuser 13109
 
3 liveuser 13110
			#設置執行失敗
13111
			$result["status"]="false";
226 liveuser 13112
 
3 liveuser 13113
			#設置執行錯誤訊息
13114
			$result["error"]=$checkArguments;
226 liveuser 13115
 
3 liveuser 13116
			#回傳結果
13117
			return $result;
226 liveuser 13118
 
3 liveuser 13119
			}#if end
226 liveuser 13120
 
3 liveuser 13121
		#檢查檔案是否存在
13122
		#函式說明:
13123
		#檢查多個檔案與資料夾是否存在.
13124
		#回傳的結果:
13125
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13126
		#$result["error"],錯誤訊息陣列.
13127
		#$resutl["function"],當前執行的涵式名稱.
13128
		#$result["argu"],使用的參數.
13129
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
13130
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
13131
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
13132
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
13133
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
13134
		#必填參數:
13135
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
13136
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
13137
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13138
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
13139
		#可省略參數
13140
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
13141
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="false";
13142
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
13143
		#$conf["userDir"]="true";
13144
		#參考資料來源:
13145
		#http://php.net/manual/en/function.file-exists.php
13146
		#http://php.net/manual/en/control-structures.foreach.php
13147
		#備註:
13148
		#函數file_exists檢查的路徑為檔案系統的路徑
13149
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
13150
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 13151
 
3 liveuser 13152
		#如果檢查檔案是否存在失敗
13153
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 13154
 
3 liveuser 13155
			#設置執行失敗
13156
			$result["status"]="false";
226 liveuser 13157
 
3 liveuser 13158
			#設置執行錯誤訊息
13159
			$result["error"]=$checkMultiFileExist;
226 liveuser 13160
 
3 liveuser 13161
			#回傳結果
13162
			return $result;
226 liveuser 13163
 
3 liveuser 13164
			}#if end
226 liveuser 13165
 
3 liveuser 13166
		#如果檔案不存在
13167
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 13168
 
3 liveuser 13169
			#設置執行失敗
13170
			$result["status"]="false";
226 liveuser 13171
 
3 liveuser 13172
			#設置執行錯誤訊息
13173
			$result["error"]=$checkMultiFileExist;
226 liveuser 13174
 
3 liveuser 13175
			#回傳結果
13176
			return $result;
226 liveuser 13177
 
3 liveuser 13178
			}#if end
226 liveuser 13179
 
3 liveuser 13180
		#產生 base64 的 pdf 編碼字串
13181
		$base64pdf=base64_encode(file_get_contents($conf["file"]));
226 liveuser 13182
 
3 liveuser 13183
		#產生 base64 的 pdf 編碼字串 data
13184
		$base64pdfData="data:application/pdf;base64,".$base64pdf;
226 liveuser 13185
 
3 liveuser 13186
		#判斷要用哪種方式嵌入pdf
13187
		switch($conf["type"]){
226 liveuser 13188
 
3 liveuser 13189
			#如果是用 object 方式
13190
			case "object":
226 liveuser 13191
 
3 liveuser 13192
				#產生嵌入的語法
13193
				$embedSyntax="<object style=\"width:100%;height:100%;\" data=\"".$base64pdfData."\"></object>";
226 liveuser 13194
 
3 liveuser 13195
				#取得語法
13196
				$result["content"]=&$embedSyntax;
226 liveuser 13197
 
3 liveuser 13198
				#跳出 switch
13199
				break;
226 liveuser 13200
 
3 liveuser 13201
			#預設
13202
			default:
226 liveuser 13203
 
3 liveuser 13204
				#產生嵌入的語法
13205
				$embedSyntax="<iframe style=\"width:100%;height:100%;\" src=\"".$base64pdfData."\"></iframe>";
226 liveuser 13206
 
3 liveuser 13207
				#取得語法
13208
				$result["content"]=&$embedSyntax;
226 liveuser 13209
 
3 liveuser 13210
			}#switch end
226 liveuser 13211
 
3 liveuser 13212
		#設置執行正常
13213
		$result["status"]="true";
226 liveuser 13214
 
3 liveuser 13215
		#回傳結果
13216
		return $result;
226 liveuser 13217
 
3 liveuser 13218
		}#function embedPdf end
226 liveuser 13219
 
3 liveuser 13220
	/*
13221
	#函式說明:
226 liveuser 13222
	#用linux unzip去解壓縮zip檔案
3 liveuser 13223
	#回傳結果:
13224
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13225
	#$result["error"],錯誤訊息.
13226
	#$result["function"],當前執行的函數名稱.
13227
	#$result["content"]["each"],每個檔案的資訊.
13228
	#$result["content"]["each"]["Length"][$i],各別檔案目錄的原始長度.
13229
	#$result["content"]["each"]["Method"][$i],各別檔案目錄的壓縮方法.
13230
	#$result["content"]["each"]["Size"][$i],各別檔案目錄的壓縮後長度.
13231
	#$result["content"]["each"]["Cmpr"][$i],各別檔案目錄的壓縮率.
13232
	#$result["content"]["each"]["Date"][$i],各別檔案目錄的最後修改日期.
13233
	#$result["content"]["each"]["Time"][$i],各別檔案目錄的最後修改時間.
13234
	#$result["content"]["each"]["CRC-32"][$i],各別檔案目錄的CRC-32檢查碼.
13235
	#$result["content"]["each"]["Name"][$i],各別檔案目錄的路徑與名稱.
13236
	#$result["content"]["total"],統整的資訊.
13237
	#$result["content"]["Length"],總共的檔案長度.
13238
	#$result["content"]["Size"],壓縮後的檔案長度.
13239
	#$result["content"]["Cmpr"],平均壓縮率.
13240
	#$result["content"]["count"],壓縮檔裡面總共的檔案跟目錄數目.
13241
	#必填參數;
13242
	#$conf["zip"],字串,要解壓縮的zip檔案.
13243
	$conf["zip"]="";
13244
	#$conf["fileArgu"],字串,__FILE__的內容.
13245
	$conf["fileArgu"]=__FILE__;
13246
	#可省略參數:
13247
	#$conf["extract"],字串,要解壓縮到那個路徑,預設為當前位置"./".
13248
	#$conf["extract"]="";
13249
	#備註:
391 liveuser 13250
	#建議加上特定邊碼的支援例如,big5、shilf_jis.
3 liveuser 13251
	*/
13252
	public static function unzip(&$conf=array()){
226 liveuser 13253
 
3 liveuser 13254
		#初始化要回傳的結果
13255
		$result=array();
13256
 
13257
		#取得當前執行的函數名稱
13258
		$result["function"]=__FUNCTION__;
13259
 
13260
		#如果沒有參數
13261
		if(func_num_args()==0){
226 liveuser 13262
 
3 liveuser 13263
			#設置執行失敗
13264
			$result["status"]="false";
226 liveuser 13265
 
3 liveuser 13266
			#設置執行錯誤訊息
13267
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 13268
 
3 liveuser 13269
			#回傳結果
13270
			return $result;
226 liveuser 13271
 
3 liveuser 13272
			}#if end
226 liveuser 13273
 
3 liveuser 13274
		#取得參數
13275
		$result["argu"]=$conf;
13276
 
13277
		#如果 $conf 不為陣列
13278
		if(gettype($conf)!=="array"){
226 liveuser 13279
 
3 liveuser 13280
			#設置執行失敗
13281
			$result["status"]="false";
226 liveuser 13282
 
3 liveuser 13283
			#設置執行錯誤訊息
13284
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 13285
 
3 liveuser 13286
			#如果傳入的參數為 null
13287
			if($conf===null){
226 liveuser 13288
 
3 liveuser 13289
				#設置執行錯誤訊息
13290
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 13291
 
3 liveuser 13292
				}#if end
13293
 
13294
			#回傳結果
13295
			return $result;
226 liveuser 13296
 
3 liveuser 13297
			}#if end
226 liveuser 13298
 
3 liveuser 13299
		#檢查參數
13300
		#函式說明:
13301
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13302
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13303
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13304
		#$result["function"],當前執行的函式名稱.
13305
		#$result["argu"],設置給予的參數.
13306
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13307
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13308
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13309
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13310
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13311
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13312
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13313
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13314
		#必填寫的參數:
13315
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 13316
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 13317
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13318
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13319
		#可以省略的參數:
13320
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13321
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("zip","fileArgu");
13322
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13323
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
13324
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13325
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
13326
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13327
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("zip","fileArgu");
13328
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13329
		#$conf["canBeEmpty"]=array();
13330
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13331
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("extract");
13332
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13333
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("extract");
226 liveuser 13334
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 13335
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
13336
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13337
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("./");
13338
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
13339
		#$conf["disallowAllSkipableVarIsEmpty"]="";
13340
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
13341
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
13342
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13343
		#$conf["arrayCountEqualCheck"][]=array();
13344
		#參考資料來源:
13345
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13346
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
13347
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 13348
 
3 liveuser 13349
		#如果檢查參數失敗
13350
		if($checkArguments["status"]==="false"){
226 liveuser 13351
 
3 liveuser 13352
			#設置執行不正常
13353
			$result["status"]="false";
226 liveuser 13354
 
3 liveuser 13355
			#設置錯誤訊息
13356
			$result["error"]=$checkArguments;
226 liveuser 13357
 
3 liveuser 13358
			#回傳結果
13359
			return $result;
226 liveuser 13360
 
3 liveuser 13361
			}#if end
226 liveuser 13362
 
3 liveuser 13363
		#如果檢查參數不通過
13364
		if($checkArguments["passed"]==="false"){
226 liveuser 13365
 
3 liveuser 13366
			#設置執行不正常
13367
			$result["status"]="false";
226 liveuser 13368
 
3 liveuser 13369
			#設置錯誤訊息
13370
			$result["error"]=$checkArguments;
226 liveuser 13371
 
3 liveuser 13372
			#回傳結果
13373
			return $result;
226 liveuser 13374
 
3 liveuser 13375
			}#if end
226 liveuser 13376
 
3 liveuser 13377
		#檢查要解壓縮的檔案是否存在
13378
		#函式說明:
13379
		#檢查多個檔案與資料夾是否存在.
13380
		#回傳的結果:
13381
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13382
		#$result["error"],錯誤訊息陣列.
13383
		#$resutl["function"],當前執行的涵式名稱.
13384
		#$result["argu"],使用的參數.
13385
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
13386
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
13387
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
13388
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
13389
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
13390
		#必填參數:
13391
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
13392
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["zip"]);
13393
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13394
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
13395
		#可省略參數
13396
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
13397
		#$conf["disableWebSearch"]="false";
13398
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
13399
		#$conf["userDir"]="true";
13400
		#參考資料來源:
13401
		#http://php.net/manual/en/function.file-exists.php
13402
		#http://php.net/manual/en/control-structures.foreach.php
13403
		#備註:
13404
		#函數file_exists檢查的路徑為檔案系統的路徑
13405
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
13406
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 13407
 
3 liveuser 13408
		#如果檢查檔案是否存在失敗
13409
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 13410
 
3 liveuser 13411
			#設置執行不正常
13412
			$result["status"]="false";
226 liveuser 13413
 
3 liveuser 13414
			#設置錯誤訊息
13415
			$result["error"]=$checkMultiFileExist;
226 liveuser 13416
 
3 liveuser 13417
			#回傳結果
13418
			return $result;
226 liveuser 13419
 
3 liveuser 13420
			}#if end
226 liveuser 13421
 
3 liveuser 13422
		#如果要解壓縮的檔案不存在
13423
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 13424
 
3 liveuser 13425
			#設置執行不正常
13426
			$result["status"]="false";
226 liveuser 13427
 
3 liveuser 13428
			#設置錯誤訊息
13429
			$result["error"]=$checkMultiFileExist;
226 liveuser 13430
 
3 liveuser 13431
			#回傳結果
13432
			return $result;
226 liveuser 13433
 
3 liveuser 13434
			}#if end
226 liveuser 13435
 
3 liveuser 13436
		#函式說明:
13437
		#呼叫shell執行系統命令,並取得回傳的內容.
13438
		#回傳結果:
13439
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13440
		#$result["error"],錯誤訊息陣列.
13441
		#$result["function"],當前執行的函數名稱.
13442
		#$result["argu"],使用的參數.
13443
		#$result["cmd"],執行的指令內容.
13444
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
13445
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
13446
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
13447
		#$result["running"],是否還在執行.
13448
		#$result["pid"],pid
13449
		#必填參數:
13450
		#$conf["command"],字串,要執行的指令與.
13451
		$conf["external::callShell"]["command"]="unzip";
13452
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 13453
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 13454
		#可省略參數:
13455
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
13456
		$conf["external::callShell"]["argu"]=array("-d",$conf["extract"],"-o","-q",$conf["zip"]);
13457
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
13458
		#$conf["arguIsAddr"]=array();
13459
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
13460
		#$conf["enablePrintDescription"]="true";
13461
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
13462
		#$conf["printDescription"]="";
13463
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
13464
		$conf["external::callShell"]["escapeshellarg"]="true";
13465
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
13466
		#$conf["username"]="";
13467
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
13468
		#$conf["password"]="";
13469
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
13470
		#$conf["useScript"]="";
13471
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
13472
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
13473
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
13474
		#$conf["inBackGround"]="";
13475
		#備註:
13476
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
13477
		#參考資料:
13478
		#exec=>http://php.net/manual/en/function.exec.php
13479
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
13480
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
13481
		$callShell=external::callShell($conf["external::callShell"]);
13482
		unset($conf["external::callShell"]);
226 liveuser 13483
 
3 liveuser 13484
		#如果執行cmd失敗
13485
		if($callShell["status"]==="false"){
226 liveuser 13486
 
3 liveuser 13487
			#設置執行不正常
13488
			$result["status"]="false";
226 liveuser 13489
 
3 liveuser 13490
			#設置錯誤訊息
13491
			$result["error"]=$callShell;
226 liveuser 13492
 
3 liveuser 13493
			#回傳結果
13494
			return $result;
226 liveuser 13495
 
3 liveuser 13496
			}#if end
226 liveuser 13497
 
3 liveuser 13498
		#函式說明:
13499
		#呼叫shell執行系統命令,並取得回傳的內容.
13500
		#回傳的結果:
13501
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13502
		#$result["error"],錯誤訊息陣列.
13503
		#$result["function"],當前執行的函數名稱.
13504
		#$result["argu"],使用的參數.
13505
		#$result["cmd"],執行的指令內容.
13506
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
13507
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
13508
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
13509
		#$result["running"],是否還在執行.
13510
		#$result["pid"],pid
13511
		#必填的參數
13512
		#$conf["command"],字串,要執行的指令與.
13513
		$conf["external::callShell"]["command"]="unzip";
13514
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 13515
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 13516
		#可省略參數:
13517
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
13518
		$conf["external::callShell"]["argu"]=array("-v",$conf["zip"]);
13519
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
13520
		#$conf["arguIsAddr"]=array();
13521
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
13522
		#$conf["enablePrintDescription"]="true";
13523
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
13524
		#$conf["printDescription"]="";
13525
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
13526
		$conf["external::callShell"]["escapeshellarg"]="true";
13527
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
13528
		#$conf["username"]="";
13529
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
13530
		#$conf["password"]="";
13531
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
13532
		#$conf["useScript"]="";
13533
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
13534
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
13535
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
13536
		#$conf["inBackGround"]="";
13537
		#備註:
13538
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
13539
		#參考資料:
13540
		#exec=>http://php.net/manual/en/function.exec.php
13541
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
13542
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
13543
		$callShell=external::callShell($conf["external::callShell"]);
13544
		unset($conf["external::callShell"]);
226 liveuser 13545
 
3 liveuser 13546
		#如果執行cmd失敗
13547
		if($callShell["status"]==="false"){
226 liveuser 13548
 
3 liveuser 13549
			#設置執行不正常
13550
			$result["status"]="false";
226 liveuser 13551
 
3 liveuser 13552
			#設置錯誤訊息
13553
			$result["error"]=$callShell;
226 liveuser 13554
 
3 liveuser 13555
			#回傳結果
13556
			return $result;
226 liveuser 13557
 
13558
			}#if end
13559
 
3 liveuser 13560
		#取得輸出的內容陣列
13561
		$unzipInfo=$callShell["output"];
226 liveuser 13562
 
3 liveuser 13563
		/*
226 liveuser 13564
 
3 liveuser 13565
		 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
13566
		--------  ------  ------- ---- ---------- ----- --------  ----
13567
		 4194304  Defl:X  2507269  40% 05-04-2002 17:30 9386a740  PS2 Bios 30004R V6 Pal.bin
13568
			   4  Defl:X        6 -50% 05-15-2005 06:45 054a6ec2  PS2 Bios 30004R V6 Pal.MEC
13569
			1024  Defl:X       22  98% 06-25-2005 14:55 3493bb06  PS2 Bios 30004R V6 Pal.NVM
13570
		  199680  Defl:X    70524  65% 06-02-2004 16:50 2c3bcd32  rom1.bin
13571
		 4194304  Defl:X  2637496  37% 02-20-2005 21:12 6f8e3c29  SCPH-70004_BIOS_V12_PAL_200.BIN
13572
		 3145728  Defl:X  3138427   0% 02-20-2005 21:12 bf3cbc65  SCPH-70004_BIOS_V12_PAL_200.EROM
13573
			1024  Defl:X      706  31% 02-20-2005 21:12 a8d51ead  SCPH-70004_BIOS_V12_PAL_200.NVM
13574
		  524288  Defl:X   149924  71% 02-20-2005 21:12 0e8797c0  SCPH-70004_BIOS_V12_PAL_200.ROM1
13575
		  524288  Defl:X   149924  71% 02-20-2005 21:12 0e8797c0  SCPH-70004_BIOS_V12_PAL_200.ROM2
13576
		 4194304  Defl:X  2213105  47% 10-18-2000 06:06 b7ef81a9  scph10000.bin
13577
			1024  Defl:X       11  99% 01-01-2005 00:42 efb5af2e  scph10000.NVM
13578
		 4194304  Defl:X  2511182  40% 06-27-2003 10:51 a19e0bf5  scph39001.bin
13579
			   4  Defl:X        6 -50% 05-14-2005 16:00 054a6ec2  scph39001.MEC
13580
			1024  Defl:X       20  98% 05-31-2005 16:09 e14a6cd6  scph39001.NVM
13581
		--------          -------  ---                            -------
13582
		21175304         13378622  37%                            14 files
226 liveuser 13583
 
3 liveuser 13584
		*/
226 liveuser 13585
 
3 liveuser 13586
		#取得行數
13587
		$lineCount=count($unzipInfo);
226 liveuser 13588
 
3 liveuser 13589
		#取得標題
13590
		#函式說明:
13591
		#將固定格式的字串分開,並回傳分開的結果。
13592
		#回傳結果:
13593
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13594
		#$result["error"],錯誤訊息陣列
13595
		#$result["function"],當前執行的函數名稱.
13596
		#$result["oriStr"],要分割的原始字串內容
13597
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13598
		#$result["dataCounts"],爲總共分成幾段
13599
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13600
		#必填參數:
13601
		$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[1];#要處理的字串。
13602
		$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13603
		#可省略參數:
13604
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13605
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13606
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13607
		unset($conf["stringProcess::spiltString"]);
226 liveuser 13608
 
3 liveuser 13609
		#如果分割字串失敗
13610
		if($spiltString["status"]==="false"){
226 liveuser 13611
 
3 liveuser 13612
			#設置執行不正常
13613
			$result["status"]="false";
226 liveuser 13614
 
3 liveuser 13615
			#設置錯誤訊息
13616
			$result["error"]=$spiltString;
226 liveuser 13617
 
3 liveuser 13618
			#回傳結果
13619
			return $result;
226 liveuser 13620
 
3 liveuser 13621
			}#if end
226 liveuser 13622
 
3 liveuser 13623
		#如果沒有分割用的關鍵字
13624
		if($spiltString["found"]==="false"){
226 liveuser 13625
 
3 liveuser 13626
			#設置執行不正常
13627
			$result["status"]="false";
226 liveuser 13628
 
3 liveuser 13629
			#設置錯誤訊息
13630
			$result["error"]=$spiltString;
226 liveuser 13631
 
3 liveuser 13632
			#回傳結果
13633
			return $result;
226 liveuser 13634
 
3 liveuser 13635
			}#if end
226 liveuser 13636
 
3 liveuser 13637
		#取得標題欄位
226 liveuser 13638
		$titles=$spiltString["dataArray"];
13639
 
3 liveuser 13640
		#取得標題欄位數目
13641
		$titleCount=$spiltString["dataCounts"];
226 liveuser 13642
 
3 liveuser 13643
		#針對每列輸出
13644
		for($i=3;$i<$lineCount-2;$i++){
226 liveuser 13645
 
3 liveuser 13646
			#取得各欄位的內容
13647
			#函式說明:
13648
			#將固定格式的字串分開,並回傳分開的結果。
13649
			#回傳結果:
13650
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13651
			#$result["error"],錯誤訊息陣列
13652
			#$result["function"],當前執行的函數名稱.
13653
			#$result["oriStr"],要分割的原始字串內容
13654
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13655
			#$result["dataCounts"],爲總共分成幾段
13656
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13657
			#必填參數:
13658
			$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[$i];#要處理的字串。
13659
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13660
			#可省略參數:
13661
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13662
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13663
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13664
			unset($conf["stringProcess::spiltString"]);
226 liveuser 13665
 
3 liveuser 13666
			#如果分割字串失敗
13667
			if($spiltString["status"]==="false"){
226 liveuser 13668
 
3 liveuser 13669
				#設置執行不正常
13670
				$result["status"]="false";
226 liveuser 13671
 
3 liveuser 13672
				#設置錯誤訊息
13673
				$result["error"]=$spiltString;
226 liveuser 13674
 
3 liveuser 13675
				#回傳結果
13676
				return $result;
226 liveuser 13677
 
3 liveuser 13678
				}#if end
226 liveuser 13679
 
3 liveuser 13680
			#如果沒有分割用的關鍵字
13681
			if($spiltString["found"]==="false"){
226 liveuser 13682
 
3 liveuser 13683
				#設置執行不正常
13684
				$result["status"]="false";
226 liveuser 13685
 
3 liveuser 13686
				#設置錯誤訊息
13687
				$result["error"]=$spiltString;
226 liveuser 13688
 
3 liveuser 13689
				#回傳結果
13690
				return $result;
226 liveuser 13691
 
3 liveuser 13692
				}#if end
226 liveuser 13693
 
3 liveuser 13694
			#取得各欄位的內容
13695
			$cols=$spiltString["dataArray"];
226 liveuser 13696
 
3 liveuser 13697
			#取得欄位的數目
13698
			$colsCount=$spiltString["dataCounts"];
226 liveuser 13699
 
3 liveuser 13700
			#如果實際抓出的內容欄位數量大於標題欄位數量,代表檔案/目錄名稱含有空格
13701
			if($colsCount>$titleCount){
226 liveuser 13702
 
3 liveuser 13703
				#新的檔案名稱
13704
				$newFileName="";
226 liveuser 13705
 
3 liveuser 13706
				#針對每個多出的欄位
13707
				for($j=$titleCount;$j<$colsCount;$j++){
226 liveuser 13708
 
3 liveuser 13709
					#串接屬於檔案名稱的部分
13710
					$newFileName=$newFileName.$cols[$j];
226 liveuser 13711
 
3 liveuser 13712
					#如果不是最後一個項目
13713
					if($j!==$colsCount-1){
226 liveuser 13714
 
3 liveuser 13715
						#增加空格
13716
						$newFileName=$newFileName." ";
226 liveuser 13717
 
3 liveuser 13718
						}#if end
226 liveuser 13719
 
3 liveuser 13720
					}#for end
226 liveuser 13721
 
3 liveuser 13722
				#取代成對的檔案名稱
13723
				$cols[$titleCount-1]=$newFileName;
226 liveuser 13724
 
3 liveuser 13725
				}#if end
226 liveuser 13726
 
3 liveuser 13727
			#針對每個欄位
13728
			for($j=0;$j<$titleCount;$j++){
226 liveuser 13729
 
3 liveuser 13730
				#取得欄位內容
13731
				$result["content"]["each"][$titles[$j]][]=$cols[$j];
226 liveuser 13732
 
3 liveuser 13733
				}#for end
226 liveuser 13734
 
3 liveuser 13735
			}#for end
226 liveuser 13736
 
3 liveuser 13737
		#取得 total 的輸出內容
13738
		#函式說明:
13739
		#將固定格式的字串分開,並回傳分開的結果。
13740
		#回傳結果:
13741
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13742
		#$result["error"],錯誤訊息陣列
13743
		#$result["function"],當前執行的函數名稱.
13744
		#$result["oriStr"],要分割的原始字串內容
13745
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13746
		#$result["dataCounts"],爲總共分成幾段
13747
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13748
		#必填參數:
13749
		$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[$lineCount-1];#要處理的字串。
13750
		$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13751
		#可省略參數:
13752
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13753
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13754
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13755
		unset($conf["stringProcess::spiltString"]);
226 liveuser 13756
 
3 liveuser 13757
		#如果分割字串失敗
13758
		if($spiltString["status"]==="false"){
226 liveuser 13759
 
3 liveuser 13760
			#設置執行不正常
13761
			$result["status"]="false";
226 liveuser 13762
 
3 liveuser 13763
			#設置錯誤訊息
13764
			$result["error"]=$spiltString;
226 liveuser 13765
 
3 liveuser 13766
			#回傳結果
13767
			return $result;
226 liveuser 13768
 
3 liveuser 13769
			}#if end
226 liveuser 13770
 
3 liveuser 13771
		#如果沒有分割用的關鍵字
13772
		if($spiltString["found"]==="false"){
226 liveuser 13773
 
3 liveuser 13774
			#設置執行不正常
13775
			$result["status"]="false";
226 liveuser 13776
 
3 liveuser 13777
			#設置錯誤訊息
13778
			$result["error"]=$spiltString;
226 liveuser 13779
 
3 liveuser 13780
			#回傳結果
13781
			return $result;
226 liveuser 13782
 
3 liveuser 13783
			}#if end
226 liveuser 13784
 
3 liveuser 13785
		#取得各欄位的內容
13786
		$cols=$spiltString["dataArray"];
226 liveuser 13787
 
3 liveuser 13788
		#取得總共的檔案長度
13789
		$result["content"]["total"][$titles[0]]=$cols[0];
226 liveuser 13790
 
3 liveuser 13791
		#取得壓縮時的總共檔案長度
13792
		$result["content"]["total"][$titles[2]]=$cols[1];
226 liveuser 13793
 
3 liveuser 13794
		#取得壓縮時的總共檔案長度
13795
		$result["content"]["total"][$titles[3]]=$cols[2];
226 liveuser 13796
 
3 liveuser 13797
		#取得解壓縮出了多少檔案跟目錄
13798
		$result["content"]["total"]["count"]=explode(" ",$cols[3])[0];
226 liveuser 13799
 
3 liveuser 13800
		#設置執行正常
13801
		$result["status"]="true";
226 liveuser 13802
 
3 liveuser 13803
		#回傳結果
13804
		return $result;
226 liveuser 13805
 
3 liveuser 13806
		}#function unzip end
226 liveuser 13807
 
3 liveuser 13808
	/*
13809
	#函式說明:
13810
	#接收Range: bytes=0-499格式的header, 輸出檔案的片段或完整檔案.
13811
	#回傳結果:
13812
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13813
	#$result["error"],錯誤訊息.
13814
	#$result["function"],當前執行的函式名稱.
13815
	#必填參數:
13816
	#$conf["filePath"],字串,檔案的路徑.
13817
	$conf["filePath"]="";
13818
	#可省略參數:
13819
	#$conf["fileName"],字串,顯示的檔案名稱,預設為basename($conf["filePath"]);
13820
	#$conf["fileName"]="";
13821
	#參考資料:
13822
	#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/
13823
	#http://php.net/manual/en/function.filemtime.php
13824
	#http://php.net/manual/en/function.connection-status.php
13825
	#http://php.net/manual/en/function.fread.php
13826
	#備註:
13827
	#請勿在運行該函式前印出任何內容,這是要給用戶端接收的內容.
13828
	*/
13829
	public static function partDownload(&$conf=array()){
226 liveuser 13830
 
3 liveuser 13831
		#初始化要回傳的結果
13832
		$result=array();
13833
 
13834
		#取得當前執行的函數名稱
13835
		$result["function"]=__FUNCTION__;
13836
 
13837
		#如果沒有參數
13838
		if(func_num_args()==0){
226 liveuser 13839
 
3 liveuser 13840
			#設置執行失敗
13841
			$result["status"]="false";
226 liveuser 13842
 
3 liveuser 13843
			#設置執行錯誤訊息
13844
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 13845
 
3 liveuser 13846
			#回傳結果
13847
			return $result;
226 liveuser 13848
 
3 liveuser 13849
		}#if end
226 liveuser 13850
 
3 liveuser 13851
		#取得參數
13852
		$result["argu"]=$conf;
13853
 
13854
		#如果 $conf 不為陣列
13855
		if(gettype($conf)!=="array"){
226 liveuser 13856
 
3 liveuser 13857
			#設置執行失敗
13858
			$result["status"]="false";
226 liveuser 13859
 
3 liveuser 13860
			#設置執行錯誤訊息
13861
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 13862
 
3 liveuser 13863
			#如果傳入的參數為 null
13864
			if($conf===null){
226 liveuser 13865
 
3 liveuser 13866
				#設置執行錯誤訊息
13867
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 13868
 
3 liveuser 13869
				}#if end
13870
 
13871
			#回傳結果
13872
			return $result;
226 liveuser 13873
 
3 liveuser 13874
			}#if end
226 liveuser 13875
 
3 liveuser 13876
		#檢查參數
13877
		#函式說明:
13878
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13879
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13880
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13881
		#$result["function"],當前執行的函式名稱.
13882
		#$result["argu"],設置給予的參數.
13883
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13884
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13885
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13886
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13887
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13888
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13889
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13890
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13891
		#必填寫的參數:
13892
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 13893
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 13894
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13895
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13896
		#可以省略的參數:
13897
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13898
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePath");
13899
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13900
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
13901
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13902
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
13903
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13904
		#$conf["canNotBeEmpty"]=array();
13905
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13906
		#$conf["canBeEmpty"]=array();
13907
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13908
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("fileName");
13909
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13910
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileName");
226 liveuser 13911
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 13912
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
13913
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13914
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
13915
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
13916
		#$conf["disallowAllSkipableVarIsEmpty"]="";
13917
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
13918
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
13919
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13920
		#$conf["arrayCountEqualCheck"][]=array();
13921
		#參考資料來源:
13922
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13923
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
13924
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 13925
 
3 liveuser 13926
		#如果檢查參數失敗
13927
		if($checkArguments["status"]==="false"){
226 liveuser 13928
 
3 liveuser 13929
			#設置執行失敗
13930
			$result["status"]="false";
226 liveuser 13931
 
3 liveuser 13932
			#設置執行錯誤
13933
			$result["error"]=$checkArguments;
226 liveuser 13934
 
3 liveuser 13935
			#回傳結果
13936
			return $result;
226 liveuser 13937
 
3 liveuser 13938
			}#if end
226 liveuser 13939
 
3 liveuser 13940
		#如果檢查參數不通過
13941
		if($checkArguments["passed"]==="false"){
226 liveuser 13942
 
3 liveuser 13943
			#設置執行失敗
13944
			$result["status"]="false";
226 liveuser 13945
 
3 liveuser 13946
			#設置執行錯誤
13947
			$result["error"]=$checkArguments;
226 liveuser 13948
 
3 liveuser 13949
			#回傳結果
13950
			return $result;
226 liveuser 13951
 
3 liveuser 13952
			}#if end
226 liveuser 13953
 
3 liveuser 13954
		#如果沒有設置 $conf["fileName"]
13955
		if(!isset($conf["fileName"])){
226 liveuser 13956
 
3 liveuser 13957
			#取得檔案名稱
13958
			$filename=basename($conf["filePath"]);
226 liveuser 13959
 
3 liveuser 13960
			}#if end
226 liveuser 13961
 
3 liveuser 13962
		#反之
13963
		else{
226 liveuser 13964
 
3 liveuser 13965
			#取得設定好的檔案名稱
13966
			$filename=&$conf["fileName"];
226 liveuser 13967
 
3 liveuser 13968
			}#else end
226 liveuser 13969
 
3 liveuser 13970
		#取得檔案路徑
13971
		$location=$conf["filePath"];
13972
 
13973
		#取得mimetype
13974
		$mimetype=mime_content_type($location);
226 liveuser 13975
 
3 liveuser 13976
		#如果檔案不存在
13977
		if(!file_exists($location)){
226 liveuser 13978
 
3 liveuser 13979
			#提示找不到檔案
13980
			header("HTTP/1.1 404 Not Found");
226 liveuser 13981
 
3 liveuser 13982
			#設置執行失敗
13983
			$result["status"]="false";
226 liveuser 13984
 
3 liveuser 13985
			#設置錯誤訊息
13986
			$result["error"][]="檔案 ".$location." 不存在.";
226 liveuser 13987
 
3 liveuser 13988
			#回傳結果
13989
			return $result;
226 liveuser 13990
 
3 liveuser 13991
			}#if end
13992
 
13993
		#取得檔案的bytes長度
13994
		$size  = filesize($location);
226 liveuser 13995
 
3 liveuser 13996
		#取得檔案的最後變更日期
13997
		$time  = date('r', filemtime($location));
13998
 
13999
		#讀取檔案的2元碼內容
14000
		$fm = @fopen($location, 'rb');
226 liveuser 14001
 
3 liveuser 14002
		#如果開啟檔案失敗
14003
		if(!$fm){
226 liveuser 14004
 
3 liveuser 14005
			#提示錯誤
14006
			header("HTTP/1.1 505 Internal server error");
226 liveuser 14007
 
3 liveuser 14008
			#設置執行失敗
14009
			$result["status"]="false";
226 liveuser 14010
 
3 liveuser 14011
			#設置錯誤訊息
14012
			$result["error"][]="開啟檔案 ".$location." 失敗.";
226 liveuser 14013
 
3 liveuser 14014
			#回傳結果
14015
			return $result;
226 liveuser 14016
 
3 liveuser 14017
			}#if end
14018
 
14019
		#初始化要提供的bytes長度起始點
14020
		$begin  = 0;
226 liveuser 14021
 
3 liveuser 14022
		#初始化要提供的bytes長度結束點
14023
		$end  = $size - 1;
14024
 
14025
		#如果有接收到 'HTTP_RANGE' 的 header 訊息
14026
		if(isset($_SERVER['HTTP_RANGE'])){
226 liveuser 14027
 
3 liveuser 14028
			#接收到的範例
226 liveuser 14029
			#Range: bytes=0-499
14030
 
3 liveuser 14031
			#取得要求的bytes位置範圍
14032
			sscanf($_SERVER['HTTP_RANGE'], "bytes=%d-%d",$begin,$end);
226 liveuser 14033
 
3 liveuser 14034
			#如果 $begin 或 $end  有缺
14035
			if(!isset($begin) || !isset($end)){
226 liveuser 14036
 
3 liveuser 14037
				#設置執行失敗
14038
				$result["status"]="false";
226 liveuser 14039
 
3 liveuser 14040
				#設置錯誤訊息
14041
				$result["error"][]="header \"Range\" 的數值格式為 \"bytes=0-499\"";
226 liveuser 14042
 
3 liveuser 14043
				#回傳結果
14044
				return $result;
226 liveuser 14045
 
3 liveuser 14046
				}#if end
226 liveuser 14047
 
3 liveuser 14048
			#如果 $begin 沒有小於等於 $end
14049
			if(!($begin<=$end)){
226 liveuser 14050
 
3 liveuser 14051
				#設置執行失敗
14052
				$result["status"]="false";
226 liveuser 14053
 
3 liveuser 14054
				#設置錯誤訊息
14055
				$result["error"][]="header \"Range\" 的數值格式為 \"bytes=0-499\"";
226 liveuser 14056
 
3 liveuser 14057
				#回傳結果
14058
				return $result;
226 liveuser 14059
 
3 liveuser 14060
				}#if end
226 liveuser 14061
 
3 liveuser 14062
			}#if end
226 liveuser 14063
 
3 liveuser 14064
		#提示 200 ok
14065
		header('HTTP/1.1 200 OK');
226 liveuser 14066
 
3 liveuser 14067
		#提示 mimetype
14068
		header("Content-Type: $mimetype");
226 liveuser 14069
 
3 liveuser 14070
		#要先驗證cache中的資料,取得的內容放在快取的時間為0
14071
		header('Cache-Control: public, must-revalidate, max-age=0');
226 liveuser 14072
 
3 liveuser 14073
		#提示不要cache
226 liveuser 14074
		header('Pragma: no-cache');
14075
 
3 liveuser 14076
		#提示接收的 Ranges 單位為 bytes
14077
		header('Accept-Ranges: bytes');
226 liveuser 14078
 
3 liveuser 14079
		#數值傳輸的內容長度為多少
14080
		header('Content-Length:' . (($end - $begin) + 1));
226 liveuser 14081
 
3 liveuser 14082
		#提示內容為檔案的哪邊到哪邊與總共的長度
14083
		header("Content-Range: bytes $begin-$end/$size");
226 liveuser 14084
 
3 liveuser 14085
		#提示檔案的名稱
14086
		header("Content-Disposition: inline; filename=$filename");
226 liveuser 14087
 
3 liveuser 14088
		#提示用2元碼傳輸
14089
		header("Content-Transfer-Encoding: binary");
226 liveuser 14090
 
3 liveuser 14091
		#提示檔案最後變更日期
14092
		header("Last-Modified: $time");
14093
 
14094
		#初始化當前位置
14095
		$cur  = $begin;
226 liveuser 14096
 
14097
		#指定讀取的起始點為 $begin
3 liveuser 14098
		fseek($fm, $begin, 0);
14099
 
14100
		#讀取內容, 若不是檔案結尾, 且當前位置($cur)小於等於 本次要提供的長度結尾($end), 且connection_status為0
14101
		while(!feof($fm) && $cur<=$end && (connection_status()===0)){
226 liveuser 14102
 
3 liveuser 14103
			#一次最多印出 1024*16bytes 的長度,若剩下長度不足則只印出剩下的長度.
14104
			echo fread($fm, min(1024 * 16, ($end - $cur) + 1));
226 liveuser 14105
 
3 liveuser 14106
			#更改位置
14107
			$cur += 1024 * 16;
226 liveuser 14108
 
3 liveuser 14109
			}#while end
226 liveuser 14110
 
3 liveuser 14111
		}#function partDownload end
226 liveuser 14112
 
3 liveuser 14113
	/*
14114
	#函式說明:
226 liveuser 14115
	#尋找檔案.
3 liveuser 14116
	#回傳結果:
14117
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14118
	#$result["error"],錯誤訊息.
14119
	#$result["warning"],警告訊息陣列.
14120
	#$result["function"],當前執行的函數名稱.
14121
	#$result["argu"],所使用的參數.
14122
	#$result["found"],是否有找到可以轉換的檔案,"true"代表有;"false"代表沒有.
14123
	#$result["content"],找到的檔案陣列.
14124
	#必填參數:
14125
	#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
14126
	$conf["keyWord"]="";
14127
	#$conf["path"],字串陣列,虛擬硬碟檔案的搜尋路徑,預設為當前路徑.
14128
	$conf["path"]=array();
14129
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14130
	$conf["fileArgu"]=__FILE__;
14131
	#參考資料:
14132
	#http://php.net/manual/en/function.glob.php
14133
	#備註:
14134
	#無.
14135
	*/
14136
	public static function findFile(&$conf=array()){
226 liveuser 14137
 
3 liveuser 14138
		#初始化要回傳的結果
14139
		$result=array();
14140
 
14141
		#取得當前執行的函數名稱
14142
		$result["function"]=__FUNCTION__;
14143
 
14144
		#如果沒有參數
14145
		if(func_num_args()==0){
226 liveuser 14146
 
3 liveuser 14147
			#設置執行失敗
14148
			$result["status"]="false";
226 liveuser 14149
 
3 liveuser 14150
			#設置執行錯誤訊息
14151
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14152
 
3 liveuser 14153
			#回傳結果
14154
			return $result;
14155
 
226 liveuser 14156
			}#if end
14157
 
3 liveuser 14158
		#取得參數
14159
		$result["argu"]=$conf;
14160
 
14161
		#如果 $conf 不為陣列
14162
		if(gettype($conf)!=="array"){
226 liveuser 14163
 
3 liveuser 14164
			#設置執行失敗
14165
			$result["status"]="false";
226 liveuser 14166
 
3 liveuser 14167
			#設置執行錯誤訊息
14168
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14169
 
3 liveuser 14170
			#如果傳入的參數為 null
14171
			if($conf===null){
226 liveuser 14172
 
3 liveuser 14173
				#設置執行錯誤訊息
14174
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14175
 
3 liveuser 14176
				}#if end
14177
 
14178
			#回傳結果
14179
			return $result;
226 liveuser 14180
 
3 liveuser 14181
			}#if end
226 liveuser 14182
 
3 liveuser 14183
		#函式說明:
14184
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14185
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14186
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14187
		#$result["function"],當前執行的函式名稱.
14188
		#$result["argu"],設置給予的參數.
14189
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14190
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14191
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14192
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14193
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14194
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14195
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14196
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14197
		#必填寫的參數:
14198
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14199
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14200
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14201
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14202
		#可以省略的參數:
14203
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14204
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","keyWord","fileArgu");
14205
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14206
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
14207
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14208
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14209
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14210
		#$conf["canNotBeEmpty"]=array();
14211
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14212
		#$conf["canBeEmpty"]=array();
14213
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14214
		#$conf["skipableVariableCanNotBeEmpty"]=array();
14215
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14216
		#$conf["skipableVariableName"]=array();
226 liveuser 14217
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14218
		#$conf["skipableVariableType"]=array();
14219
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14220
		#$conf["skipableVarDefaultValue"]=array("");
14221
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14222
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14223
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14224
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14225
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14226
		#$conf["arrayCountEqualCheck"][]=array();
14227
		#參考資料來源:
14228
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14229
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14230
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14231
 
3 liveuser 14232
		#如果檢查參數失敗
14233
		if($checkArguments["status"]==="false"){
226 liveuser 14234
 
3 liveuser 14235
			#設置執行失敗
14236
			$result["status"]="false";
226 liveuser 14237
 
3 liveuser 14238
			#設置執行失敗訊息
14239
			$result["error"]=$checkArguments;
226 liveuser 14240
 
3 liveuser 14241
			#回傳結果
14242
			return $result;
226 liveuser 14243
 
3 liveuser 14244
			}#if end
226 liveuser 14245
 
3 liveuser 14246
		#如果檢查參數不通過
14247
		if($checkArguments["passed"]==="false"){
226 liveuser 14248
 
3 liveuser 14249
			#設置執行失敗
14250
			$result["status"]="false";
226 liveuser 14251
 
3 liveuser 14252
			#設置執行失敗訊息
14253
			$result["error"]=$checkArguments;
226 liveuser 14254
 
3 liveuser 14255
			#回傳結果
14256
			return $result;
226 liveuser 14257
 
3 liveuser 14258
			}#if end
226 liveuser 14259
 
3 liveuser 14260
		#檢查要搜尋的路徑是否都存在
14261
		#函式說明:
14262
		#s檢查多個檔案與資料夾是否存在.
14263
		#回傳的結果:
14264
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
14265
		#$result["error"],錯誤訊息陣列.
14266
		#$resutl["function"],當前執行的涵式名稱.
14267
		#$result["argu"],使用的參數.
14268
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
14269
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
14270
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
14271
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
14272
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
14273
		#必填參數:
14274
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
14275
		$conf["self::checkMultiFileExist"]["fileArray"]=$conf["path"];
14276
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14277
		$conf["self::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
14278
		#可省略參數
14279
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
14280
		#$conf["disableWebSearch"]="false";
14281
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
14282
		#$conf["userDir"]="true";
14283
		#參考資料來源:
14284
		#http://php.net/manual/en/function.file-exists.php
14285
		#http://php.net/manual/en/control-structures.foreach.php
14286
		#備註:
14287
		#函數file_exists檢查的路徑為檔案系統的路徑
14288
		$checkMultiFileExist=self::checkMultiFileExist($conf["self::checkMultiFileExist"]);
14289
		unset($conf["self::checkMultiFileExist"]);
226 liveuser 14290
 
3 liveuser 14291
		#如果檢查目錄存在失敗
14292
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 14293
 
3 liveuser 14294
			#設置執行失敗
14295
			$result["status"]="false";
226 liveuser 14296
 
3 liveuser 14297
			#設置執行失敗訊息
14298
			$result["error"]=$checkMultiFileExist;
226 liveuser 14299
 
3 liveuser 14300
			#回傳結果
14301
			return $result;
226 liveuser 14302
 
14303
			}#if end
14304
 
3 liveuser 14305
		#如果目錄不存在
14306
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 14307
 
3 liveuser 14308
			#設置執行失敗
14309
			$result["status"]="false";
226 liveuser 14310
 
3 liveuser 14311
			#設置執行失敗訊息
14312
			$result["error"]=$checkMultiFileExist;
226 liveuser 14313
 
3 liveuser 14314
			#回傳結果
14315
			return $result;
226 liveuser 14316
 
3 liveuser 14317
			}#if end
226 liveuser 14318
 
3 liveuser 14319
		#如果有路徑不存在
14320
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 14321
 
3 liveuser 14322
			#設置執行失敗
14323
			$result["status"]="false";
226 liveuser 14324
 
3 liveuser 14325
			#設置執行失敗訊息
14326
			$result["error"]=$checkMultiFileExist;
226 liveuser 14327
 
3 liveuser 14328
			#設置提示有路徑不存在的訊息
14329
			$result["warning"][]="參數path的路徑沒有每個都存在";
226 liveuser 14330
 
3 liveuser 14331
			#回傳結果
14332
			return $result;
226 liveuser 14333
 
3 liveuser 14334
			}#if end
226 liveuser 14335
 
3 liveuser 14336
		#預設沒有找到檔案
226 liveuser 14337
		$result["found"]="false";
14338
 
3 liveuser 14339
		#針對每個要搜尋的路徑
14340
		foreach($conf["path"] as $path){
226 liveuser 14341
 
3 liveuser 14342
			#函式說明:
14343
			#用find指令尋找檔案
14344
			#回傳結果:
14345
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14346
			#$result["error"],錯誤訊息.
14347
			#$result["function"],當前執行的函數名稱.
14348
			#$result["argu"],所使用的參數.
14349
			#$result["found"],是否有找到符合的檔案,"true"代表有;"false"代表沒有.
14350
			#$result["content"],找到的檔案陣列.
14351
			#必填參數:
14352
			#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
226 liveuser 14353
			$conf["cmd::find"]["keyWord"]=$conf["keyWord"];
3 liveuser 14354
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14355
			$conf["cmd::find"]["fileArgu"]=$conf["fileArgu"];
14356
			#可省略參數:
14357
			#$conf["path"],字串,搜尋的路徑,預設為"/".
14358
			$conf["cmd::find"]["path"]=$path;
14359
			#$conf["fileOnly"],字串,"true"代表只要找檔案,"false"代表.
14360
			$conf["cmd::find"]["fileOnly"]="true";
14361
			#參考資料:
14362
			#http://php.net/manual/en/function.glob.php
14363
			$find=cmd::find($conf["cmd::find"]);
14364
			unset($conf["cmd::find"]);
226 liveuser 14365
 
3 liveuser 14366
			#如果尋找檔案失敗
14367
			if($find["status"]==="false"){
226 liveuser 14368
 
3 liveuser 14369
				#設置執行失敗
14370
				$result["status"]="false";
226 liveuser 14371
 
3 liveuser 14372
				#設置執行失敗訊息
14373
				$result["error"]=$find;
226 liveuser 14374
 
3 liveuser 14375
				#回傳結果
14376
				return $result;
226 liveuser 14377
 
3 liveuser 14378
				}#if end
226 liveuser 14379
 
3 liveuser 14380
			#如果有找到符合的檔案
14381
			if($find["found"]==="true"){
226 liveuser 14382
 
3 liveuser 14383
				#設置有找到檔案
14384
				$result["found"]="true";
226 liveuser 14385
 
3 liveuser 14386
				#針對每個找到的檔案
14387
				foreach($find["content"] as $filtedFile){
226 liveuser 14388
 
3 liveuser 14389
					#設置有找到的檔案
14390
					$result["content"][]=$filtedFile;
226 liveuser 14391
 
3 liveuser 14392
					}#foreach end
226 liveuser 14393
 
3 liveuser 14394
				}#if end
226 liveuser 14395
 
14396
			}#foreach end
14397
 
3 liveuser 14398
		#設置執行正常
14399
		$result["status"]="true";
226 liveuser 14400
 
3 liveuser 14401
		#回傳結果
14402
		return $result;
226 liveuser 14403
 
3 liveuser 14404
		}#function findFile end
14405
 
14406
	/*
14407
	#函式說明:
14408
	#判斷檔案位於哪個分割區
14409
	#回傳結果:
14410
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14411
	#$result["error"],錯誤訊息.
14412
	#$result["function"],當前執行的函數名稱.
14413
	#$result["argu"],所使用的參數.
14414
	#$result["content"],找到的檔案所屬分割區資訊.
14415
	#必填參數:
14416
	#$conf["file"],字串,檔案的路徑與名稱.
14417
	$conf["file"]="";
14418
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14419
	$conf["fileArgu"]=__FILE__;
14420
	#可省略參數:
14421
	#無.
14422
	#參考資料:
14423
	#無.
14424
	#備註:
14425
	#無.
14426
	*/
14427
	public static function addrInMountPoint(&$conf=array()){
226 liveuser 14428
 
3 liveuser 14429
		#初始化要回傳的結果
14430
		$result=array();
14431
 
14432
		#取得當前執行的函數名稱
14433
		$result["function"]=__FUNCTION__;
14434
 
14435
		#如果沒有參數
14436
		if(func_num_args()==0){
226 liveuser 14437
 
3 liveuser 14438
			#設置執行失敗
14439
			$result["status"]="false";
226 liveuser 14440
 
3 liveuser 14441
			#設置執行錯誤訊息
14442
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14443
 
3 liveuser 14444
			#回傳結果
14445
			return $result;
14446
 
226 liveuser 14447
			}#if end
14448
 
3 liveuser 14449
		#取得參數
14450
		$result["argu"]=$conf;
14451
 
14452
		#如果 $conf 不為陣列
14453
		if(gettype($conf)!=="array"){
226 liveuser 14454
 
3 liveuser 14455
			#設置執行失敗
14456
			$result["status"]="false";
226 liveuser 14457
 
3 liveuser 14458
			#設置執行錯誤訊息
14459
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14460
 
3 liveuser 14461
			#如果傳入的參數為 null
14462
			if($conf===null){
226 liveuser 14463
 
3 liveuser 14464
				#設置執行錯誤訊息
14465
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14466
 
3 liveuser 14467
				}#if end
14468
 
14469
			#回傳結果
14470
			return $result;
226 liveuser 14471
 
3 liveuser 14472
			}#if end
226 liveuser 14473
 
3 liveuser 14474
		#函式說明:
14475
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14476
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14477
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14478
		#$result["function"],當前執行的函式名稱.
14479
		#$result["argu"],設置給予的參數.
14480
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14481
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14482
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14483
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14484
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14485
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14486
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14487
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14488
		#必填寫的參數:
14489
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14490
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14491
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14492
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14493
		#可以省略的參數:
14494
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14495
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
14496
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14497
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
14498
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14499
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14500
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14501
		#$conf["canNotBeEmpty"]=array();
14502
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14503
		#$conf["canBeEmpty"]=array();
14504
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14505
		#$conf["skipableVariableCanNotBeEmpty"]=array();
14506
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14507
		#$conf["skipableVariableName"]=array();
226 liveuser 14508
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14509
		#$conf["skipableVariableType"]=array();
14510
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14511
		#$conf["skipableVarDefaultValue"]=array("");
14512
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14513
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14514
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14515
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14516
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14517
		#$conf["arrayCountEqualCheck"][]=array();
14518
		#參考資料來源:
14519
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14520
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14521
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14522
 
3 liveuser 14523
		#如果檢查參數失敗
14524
		if($checkArguments["status"]==="false"){
226 liveuser 14525
 
3 liveuser 14526
			#設置執行失敗
14527
			$result["status"]="false";
226 liveuser 14528
 
3 liveuser 14529
			#設置執行失敗訊息
14530
			$result["error"]=$checkArguments;
226 liveuser 14531
 
3 liveuser 14532
			#回傳結果
14533
			return $result;
226 liveuser 14534
 
3 liveuser 14535
			}#if end
226 liveuser 14536
 
3 liveuser 14537
		#如果檢查參數不通過
14538
		if($checkArguments["passed"]==="false"){
226 liveuser 14539
 
3 liveuser 14540
			#設置執行失敗
14541
			$result["status"]="false";
226 liveuser 14542
 
3 liveuser 14543
			#設置執行失敗訊息
14544
			$result["error"]=$checkArguments;
226 liveuser 14545
 
3 liveuser 14546
			#回傳結果
14547
			return $result;
226 liveuser 14548
 
3 liveuser 14549
			}#if end
226 liveuser 14550
 
3 liveuser 14551
		#函式說明:
14552
		#透過lsblk指令的輸出取得已經掛載的blk.
14553
		#回傳結果:
14554
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14555
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14556
		#$result["function"],當前執行的函式名稱.
14557
		#$result["content"],lsblk的輸出內容.
14558
		#必填參數:
14559
		#$conf["fileArgu"],字串,變數__FILE__的內容.
14560
		$conf["cmd::lsblk"]["fileArgu"]=$conf["fileArgu"];
14561
		#可省略參數:
226 liveuser 14562
		#無.
3 liveuser 14563
		$lsblk=cmd::lsblk($conf["cmd::lsblk"]);
14564
		unset($conf["cmd::lsblk"]);
226 liveuser 14565
 
3 liveuser 14566
		#如果執行失敗
14567
		if($lsblk["status"]==="false"){
226 liveuser 14568
 
3 liveuser 14569
			#設置執行失敗
14570
			$result["status"]="false";
226 liveuser 14571
 
3 liveuser 14572
			#設置執行失敗訊息
14573
			$result["error"]=$lsblk;
226 liveuser 14574
 
3 liveuser 14575
			#回傳結果
14576
			return $result;
226 liveuser 14577
 
3 liveuser 14578
			}#if end
226 liveuser 14579
 
3 liveuser 14580
		#將 $conf["file"] 轉換成絕對路徑
14581
		#函式說明:
14582
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
14583
		#回傳結果:
14584
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
14585
		#$result["error"],錯誤訊息陣列.
226 liveuser 14586
		#$result["function"],函數名稱.
3 liveuser 14587
		#$result["argu"],使用的參數.
14588
		#$result["content"],網址,若是在命令列執行,則為"null".
14589
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
14590
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
14591
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
14592
		#必填參數:
14593
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
14594
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["file"];
14595
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
14596
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
14597
		#可省略參數:
14598
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
14599
		#$conf["userDir"]="true";
14600
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
14601
		unset($conf["fileAccess::getInternetAddress"]);
226 liveuser 14602
 
3 liveuser 14603
		#如果執行失敗
14604
		if($getInternetAddress["status"]==="false"){
226 liveuser 14605
 
3 liveuser 14606
			#設置執行失敗
14607
			$result["status"]="false";
226 liveuser 14608
 
3 liveuser 14609
			#設置執行失敗訊息
14610
			$result["error"]=$getInternetAddress;
226 liveuser 14611
 
3 liveuser 14612
			#回傳結果
14613
			return $result;
226 liveuser 14614
 
14615
			}#if end
14616
 
3 liveuser 14617
		#使用絕對位置作為輸入字串
14618
		#函式說明:
14619
		#尋找字串是否存在對應的關鍵字,且符合的最常關鍵字為何?
14620
		#回傳結果:
14621
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14622
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14623
		#$result["function"],當前執行的函式名稱.
14624
		#$result["argu"],所使用的參數.
14625
		#$result["founded"],是否有找到關鍵字,"true"代表有找到,"false"代表沒有找到.
14626
		#$result["content"],最符合的字串完整內容.
14627
		#必填參數:
14628
		#$conf["input"],字串,要比對的字串陣列.
14629
		$conf["search::findLikelyStr"]["input"]=$getInternetAddress["fileSystemAbsoulutePosition"];
14630
		#$conf["keyWord"],字串陣列,要搜尋的關鍵字.
14631
		$conf["search::findLikelyStr"]["keyWord"]=$lsblk["content"]["MOUNTPOINT"];
14632
		$findLikelyStr=search::findLikelyStr($conf["search::findLikelyStr"]);
14633
		unset($conf["search::findLikelyStr"]);
226 liveuser 14634
 
3 liveuser 14635
		#如果執行失敗
14636
		if($findLikelyStr["status"]==="false"){
226 liveuser 14637
 
3 liveuser 14638
			#設置執行失敗
14639
			$result["status"]="false";
226 liveuser 14640
 
3 liveuser 14641
			#設置執行失敗訊息
14642
			$result["error"]=$findLikelyStr;
226 liveuser 14643
 
3 liveuser 14644
			#回傳結果
14645
			return $result;
226 liveuser 14646
 
3 liveuser 14647
			}#if end
226 liveuser 14648
 
3 liveuser 14649
		#如果找不到歸屬的分割區
14650
		if($findLikelyStr["found"]==="false"){
226 liveuser 14651
 
3 liveuser 14652
			#設置執行失敗
14653
			$result["status"]="false";
226 liveuser 14654
 
3 liveuser 14655
			#設置執行失敗訊息
14656
			$result["error"]=$findLikelyStr;
226 liveuser 14657
 
3 liveuser 14658
			#回傳結果
14659
			return $result;
226 liveuser 14660
 
3 liveuser 14661
			}#if end
226 liveuser 14662
 
3 liveuser 14663
		#設置歸屬的分割區資訊
14664
		$result["content"]=$findLikelyStr["content"];
226 liveuser 14665
 
3 liveuser 14666
		#設置執行正常
14667
		$result["status"]="true";
226 liveuser 14668
 
3 liveuser 14669
		#回傳結果
14670
		return $result;
226 liveuser 14671
 
3 liveuser 14672
		}#function addrInMountPoint end
14673
 
14674
	/*
14675
	#函式說明:
14676
	#取得檔案的副檔名
14677
	#回傳結果:
14678
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14679
	#$result["error"],錯誤訊息.
14680
	#$result["function"],當前執行的函數名稱.
226 liveuser 14681
	#$result["argu"],所使用的參數.
3 liveuser 14682
	#$result["content"],副檔名.
14683
	#$result["name"],不含副檔的名稱.
14684
	#$result["fullName"],含副檔的名稱.
14685
	#$result["path"],檔案所處的路徑.
14686
	#必填參數:
14687
	#$conf["file"],字串,檔案的路徑與名稱.
14688
	$conf["file"]="";
14689
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14690
	$conf["fileArgu"]=__FILE__;
14691
	#可省略參數:
14692
	#無.
14693
	#參考資料:
14694
	#無.
14695
	#備註:
14696
	#無.
14697
	*/
14698
	public static function getExtension(&$conf=array()){
226 liveuser 14699
 
3 liveuser 14700
		#初始化要回傳的結果
14701
		$result=array();
14702
 
14703
		#取得當前執行的函數名稱
14704
		$result["function"]=__FUNCTION__;
14705
 
14706
		#如果沒有參數
14707
		if(func_num_args()==0){
226 liveuser 14708
 
3 liveuser 14709
			#設置執行失敗
14710
			$result["status"]="false";
226 liveuser 14711
 
3 liveuser 14712
			#設置執行錯誤訊息
14713
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14714
 
3 liveuser 14715
			#回傳結果
14716
			return $result;
14717
 
226 liveuser 14718
			}#if end
14719
 
3 liveuser 14720
		#取得參數
14721
		$result["argu"]=$conf;
14722
 
14723
		#如果 $conf 不為陣列
14724
		if(gettype($conf)!=="array"){
226 liveuser 14725
 
3 liveuser 14726
			#設置執行失敗
14727
			$result["status"]="false";
226 liveuser 14728
 
3 liveuser 14729
			#設置執行錯誤訊息
14730
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14731
 
3 liveuser 14732
			#如果傳入的參數為 null
14733
			if($conf===null){
226 liveuser 14734
 
3 liveuser 14735
				#設置執行錯誤訊息
14736
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14737
 
3 liveuser 14738
				}#if end
14739
 
14740
			#回傳結果
14741
			return $result;
226 liveuser 14742
 
3 liveuser 14743
			}#if end
226 liveuser 14744
 
3 liveuser 14745
		#函式說明:
14746
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14747
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14748
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14749
		#$result["function"],當前執行的函式名稱.
14750
		#$result["argu"],設置給予的參數.
14751
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14752
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14753
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14754
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14755
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14756
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14757
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14758
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14759
		#必填寫的參數:
14760
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14761
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14762
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14763
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14764
		#可以省略的參數:
14765
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14766
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
14767
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14768
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
14769
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14770
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14771
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14772
		#$conf["canNotBeEmpty"]=array();
14773
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14774
		#$conf["canBeEmpty"]=array();
14775
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14776
		#$conf["skipableVariableCanNotBeEmpty"]=array();
14777
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14778
		#$conf["skipableVariableName"]=array();
226 liveuser 14779
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14780
		#$conf["skipableVariableType"]=array();
14781
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14782
		#$conf["skipableVarDefaultValue"]=array("");
14783
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14784
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14785
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14786
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14787
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14788
		#$conf["arrayCountEqualCheck"][]=array();
14789
		#參考資料來源:
14790
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14791
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14792
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14793
 
3 liveuser 14794
		#如果檢查參數失敗
14795
		if($checkArguments["status"]==="false"){
226 liveuser 14796
 
3 liveuser 14797
			#設置執行失敗
14798
			$result["status"]="false";
226 liveuser 14799
 
3 liveuser 14800
			#設置執行失敗訊息
14801
			$result["error"]=$checkArguments;
226 liveuser 14802
 
3 liveuser 14803
			#回傳結果
14804
			return $result;
226 liveuser 14805
 
3 liveuser 14806
			}#if end
226 liveuser 14807
 
3 liveuser 14808
		#如果檢查參數不通過
14809
		if($checkArguments["passed"]==="false"){
226 liveuser 14810
 
3 liveuser 14811
			#設置執行失敗
14812
			$result["status"]="false";
226 liveuser 14813
 
3 liveuser 14814
			#設置執行失敗訊息
14815
			$result["error"]=$checkArguments;
226 liveuser 14816
 
3 liveuser 14817
			#回傳結果
14818
			return $result;
226 liveuser 14819
 
3 liveuser 14820
			}#if end
226 liveuser 14821
 
3 liveuser 14822
		#初始化檔案的路徑
14823
		$result["path"]="./";
226 liveuser 14824
 
3 liveuser 14825
		#用 "/" 來分割字串
14826
		#函式說明:
14827
		#將固定格式的字串分開,並回傳分開的結果。
14828
		#回傳結果:
14829
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14830
		#$result["error"],錯誤訊息陣列
14831
		#$result["function"],當前執行的函數名稱.
14832
		#$result["oriStr"],要分割的原始字串內容
14833
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
14834
		#$result["dataCounts"],爲總共分成幾段
14835
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
14836
		#必填參數:
14837
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["file"];#要處理的字串。
14838
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
14839
		#可省略參數:
14840
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
14841
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
14842
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
14843
		unset($conf["stringProcess::spiltString"]);
226 liveuser 14844
 
3 liveuser 14845
		#如果檢查參數失敗
14846
		if($spiltString["status"]==="false"){
226 liveuser 14847
 
3 liveuser 14848
			#設置執行失敗
14849
			$result["status"]="false";
226 liveuser 14850
 
3 liveuser 14851
			#設置執行失敗訊息
14852
			$result["error"]=$spiltString;
226 liveuser 14853
 
3 liveuser 14854
			#回傳結果
14855
			return $result;
226 liveuser 14856
 
3 liveuser 14857
			}#if end
226 liveuser 14858
 
3 liveuser 14859
		#初始化含副檔名的檔案名稱
14860
		$result["fullName"]=$conf["file"];
226 liveuser 14861
 
3 liveuser 14862
		#如果有"/"存在
14863
		if($spiltString["found"]==="true"){
226 liveuser 14864
 
3 liveuser 14865
			#取得含副檔名的檔案名稱
14866
			$result["fullName"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 14867
 
3 liveuser 14868
			#取得檔案的路徑
14869
			$result["path"]=substr($conf["file"],0,strlen($conf["file"])-strlen($result["fullName"]));
226 liveuser 14870
 
3 liveuser 14871
			}#if end
226 liveuser 14872
 
3 liveuser 14873
		#用 "." 來分割字串
14874
		#函式說明:
14875
		#將固定格式的字串分開,並回傳分開的結果。
14876
		#回傳結果:
14877
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14878
		#$result["error"],錯誤訊息陣列
14879
		#$result["function"],當前執行的函數名稱.
14880
		#$result["oriStr"],要分割的原始字串內容
14881
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
14882
		#$result["dataCounts"],爲總共分成幾段
14883
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
14884
		#必填參數:
14885
		$conf["stringProcess::spiltString"]["stringIn"]=$result["fullName"];#要處理的字串。
14886
		$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
14887
		#可省略參數:
14888
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
14889
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
14890
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
14891
		unset($conf["stringProcess::spiltString"]);
226 liveuser 14892
 
3 liveuser 14893
		#如果檢查參數失敗
14894
		if($spiltString["status"]==="false"){
226 liveuser 14895
 
3 liveuser 14896
			#設置執行失敗
14897
			$result["status"]="false";
226 liveuser 14898
 
3 liveuser 14899
			#設置執行失敗訊息
14900
			$result["error"]=$spiltString;
226 liveuser 14901
 
3 liveuser 14902
			#回傳結果
14903
			return $result;
226 liveuser 14904
 
3 liveuser 14905
			}#if end
226 liveuser 14906
 
3 liveuser 14907
		#預設副檔名為 ""
14908
		$result["content"]="";
226 liveuser 14909
 
3 liveuser 14910
		#預設不含副檔名的檔案名稱
14911
		$result["name"]=$result["fullName"];
226 liveuser 14912
 
3 liveuser 14913
		#如果有"."存在
14914
		if($spiltString["found"]==="true"){
226 liveuser 14915
 
3 liveuser 14916
			#取得含副檔名
14917
			$result["content"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 14918
 
3 liveuser 14919
			#取得不含副檔名的檔案名稱
226 liveuser 14920
			$result["name"]=substr($result["fullName"],0,strlen($result["fullName"])-strlen($result["content"])-1);
14921
 
3 liveuser 14922
			}#if end
226 liveuser 14923
 
3 liveuser 14924
		#設置執行正常
14925
		$result["status"]="true";
226 liveuser 14926
 
3 liveuser 14927
		#回傳結果
14928
		return $result;
226 liveuser 14929
 
3 liveuser 14930
		}#function getExtension end
14931
 
14932
	/*
14933
	#函式說明:
14934
	#從檔案尾部開始讀取
14935
	#回傳結果:
14936
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14937
	#$result["error"],錯誤訊息.
14938
	#$result["function"],當前執行的函數名稱.
226 liveuser 14939
	#$result["argu"],所使用的參數.
3 liveuser 14940
	#$result["content"],讀取到的內容陣列.
14941
	#$result["totalLineCount"],檔案的總共行數.
14942
	#$result["lines"],取得輸出的行數.
14943
	#$result["lineNum"],取得當前行數.
14944
	#必填參數:
14945
	#$conf["file"],字串,檔案的路徑與名稱.
14946
	$conf["file"]="";
14947
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14948
	$conf["fileArgu"]=__FILE__;
14949
	#可省略參數:
14950
	#$conf["web"],字串,"true"代表位網頁系統,"false"為檔案系統,預設為"false".
14951
	#$conf["web"]="false";
14952
	#$conf["line2start"],字串,從第幾列開始,預設為總行書減去linesPerTime+1.
14953
	#$conf["line2start"]="";
14954
	#$conf["linesPerTime"],字串,一次最多讀取幾列,預設爲10列.
226 liveuser 14955
	#$conf["linesPerTime"]="10";
3 liveuser 14956
	#參考資料:
14957
	#無.
14958
	#備註:
14959
	#無.
14960
	*/
14961
	public static function tail(&$conf){
14962
 
14963
		#初始化要回傳的結果
14964
		$result=array();
14965
 
14966
		#取得當前執行的函數名稱
14967
		$result["function"]=__FUNCTION__;
14968
 
14969
		#如果沒有參數
14970
		if(func_num_args()==0){
226 liveuser 14971
 
3 liveuser 14972
			#設置執行失敗
14973
			$result["status"]="false";
226 liveuser 14974
 
3 liveuser 14975
			#設置執行錯誤訊息
14976
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14977
 
3 liveuser 14978
			#回傳結果
14979
			return $result;
14980
 
226 liveuser 14981
			}#if end
14982
 
3 liveuser 14983
		#取得參數
14984
		$result["argu"]=$conf;
14985
 
14986
		#如果 $conf 不為陣列
14987
		if(gettype($conf)!=="array"){
226 liveuser 14988
 
3 liveuser 14989
			#設置執行失敗
14990
			$result["status"]="false";
226 liveuser 14991
 
3 liveuser 14992
			#設置執行錯誤訊息
14993
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14994
 
3 liveuser 14995
			#如果傳入的參數為 null
14996
			if($conf===null){
226 liveuser 14997
 
3 liveuser 14998
				#設置執行錯誤訊息
14999
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 15000
 
3 liveuser 15001
				}#if end
15002
 
15003
			#回傳結果
15004
			return $result;
226 liveuser 15005
 
3 liveuser 15006
			}#if end
226 liveuser 15007
 
3 liveuser 15008
		#函式說明:
15009
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
15010
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15011
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15012
		#$result["function"],當前執行的函式名稱.
15013
		#$result["argu"],設置給予的參數.
15014
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15015
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15016
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15017
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15018
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15019
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15020
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15021
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15022
		#必填寫的參數:
15023
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 15024
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 15025
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15026
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15027
		#可以省略的參數:
15028
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15029
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
15030
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15031
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
15032
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15033
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15034
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15035
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file","fileArgu");
15036
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15037
		#$conf["canBeEmpty"]=array();
15038
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
15039
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web","line2start","linesPerTime");
15040
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
15041
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web","line2start","linesPerTime");
226 liveuser 15042
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 15043
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
15044
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
15045
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,"10");
15046
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15047
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15048
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15049
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15050
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15051
		#$conf["arrayCountEqualCheck"][]=array();
15052
		#參考資料來源:
15053
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15054
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15055
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15056
 
3 liveuser 15057
		#如果檢查參數失敗
15058
		if($checkArguments["status"]==="false"){
226 liveuser 15059
 
3 liveuser 15060
			#設置執行失敗
15061
			$result["status"]="false";
226 liveuser 15062
 
3 liveuser 15063
			#設置執行失敗訊息
15064
			$result["error"]=$checkArguments;
226 liveuser 15065
 
3 liveuser 15066
			#回傳結果
15067
			return $result;
226 liveuser 15068
 
3 liveuser 15069
			}#if end
226 liveuser 15070
 
3 liveuser 15071
		#如果檢查參數不通過
15072
		if($checkArguments["passed"]==="false"){
226 liveuser 15073
 
3 liveuser 15074
			#設置執行失敗
15075
			$result["status"]="false";
226 liveuser 15076
 
3 liveuser 15077
			#設置執行失敗訊息
15078
			$result["error"]=$checkArguments;
226 liveuser 15079
 
3 liveuser 15080
			#回傳結果
15081
			return $result;
226 liveuser 15082
 
3 liveuser 15083
			}#if end
15084
 
15085
		#檢查檔案是否存在
15086
		#函式說明:
15087
		#檢查多個檔案與資料夾是否存在.
15088
		#回傳的結果:
15089
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
15090
		#$result["error"],錯誤訊息陣列.
15091
		#$resutl["function"],當前執行的涵式名稱.
15092
		#$result["argu"],使用的參數.
15093
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
15094
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
15095
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
15096
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
15097
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
15098
		#必填參數:
15099
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
15100
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
15101
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
15102
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
15103
		#可省略參數
15104
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
15105
		#$conf["disableWebSearch"]="false";
15106
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
15107
		#$conf["userDir"]="true";
15108
		#$conf["web"],字串,"true"代表位網頁系統,"false"為檔案系統,預設為"false".
15109
		$conf["fileAccess::checkMultiFileExist"]["web"]=$conf["web"];
15110
		#參考資料來源:
15111
		#http://php.net/manual/en/function.file-exists.php
15112
		#http://php.net/manual/en/control-structures.foreach.php
15113
		#備註:
15114
		#函數file_exists檢查的路徑為檔案系統的路徑
15115
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
15116
		unset($conf["fileAccess::checkMultiFileExist"]);
15117
 
15118
		#如果執行失敗
15119
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 15120
 
3 liveuser 15121
			#設置執行失敗
15122
			$result["status"]="false";
226 liveuser 15123
 
3 liveuser 15124
			#設置執行失敗訊息
15125
			$result["error"]=$checkMultiFileExist;
226 liveuser 15126
 
3 liveuser 15127
			#回傳結果
15128
			return $result;
226 liveuser 15129
 
3 liveuser 15130
			}#if end
226 liveuser 15131
 
3 liveuser 15132
		#如果檔案無法存取
15133
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 15134
 
3 liveuser 15135
			#設置執行失敗
15136
			$result["status"]="false";
226 liveuser 15137
 
3 liveuser 15138
			#設置執行失敗訊息
15139
			$result["error"]=$checkMultiFileExist;
226 liveuser 15140
 
3 liveuser 15141
			#回傳結果
15142
			return $result;
226 liveuser 15143
 
3 liveuser 15144
			}#if end
15145
 
15146
		#取得檔案的行數
15147
		#函式說明:
15148
		#呼叫shell執行系統命令,並取得回傳的內容.
15149
		#回傳的結果:
15150
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15151
		#$result["error"],錯誤訊息陣列.
15152
		#$result["function"],當前執行的函數名稱.
15153
		#$result["argu"],使用的參數.
15154
		#$result["cmd"],執行的指令內容.
15155
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15156
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15157
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15158
		#$result["running"],是否還在執行.
15159
		#$result["pid"],pid.
15160
		#$result["statusCode"],執行結束後的代碼.
15161
		#必填的參數
15162
		#$conf["command"],字串,要執行的指令與.
15163
		$conf["external::callShell"]["command"]="cat";
15164
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 15165
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 15166
		#可省略參數:
15167
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15168
		$conf["external::callShell"]["argu"]=array($conf["file"],"|","wc","-l");
15169
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 15170
		#$conf["arguIsAddr"]=array();
3 liveuser 15171
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15172
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15173
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15174
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15175
		#$conf["enablePrintDescription"]="true";
15176
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15177
		#$conf["printDescription"]="";
15178
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
15179
		$conf["external::callShell"]["escapeshellarg"]="true";
15180
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15181
		#$conf["username"]="";
15182
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15183
		#$conf["password"]="";
15184
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15185
		#$conf["useScript"]="";
15186
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15187
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15188
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15189
		#$conf["inBackGround"]="";
15190
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
15191
		#$conf["getErr"]="false";
15192
		#備註:
15193
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15194
		#參考資料:
15195
		#exec=>http://php.net/manual/en/function.exec.php
15196
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15197
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15198
		$callShell=external::callShell($conf["external::callShell"]);
15199
		unset($conf["external::callShell"]);
15200
 
15201
		#如果檢查參數失敗
15202
		if($callShell["status"]==="false"){
226 liveuser 15203
 
3 liveuser 15204
			#設置執行失敗
15205
			$result["status"]="false";
226 liveuser 15206
 
3 liveuser 15207
			#設置執行失敗訊息
15208
			$result["error"]=$callShell;
226 liveuser 15209
 
3 liveuser 15210
			#回傳結果
15211
			return $result;
226 liveuser 15212
 
3 liveuser 15213
			}#if end
226 liveuser 15214
 
3 liveuser 15215
		#取得檔案總行數
15216
		$result["totalLineCount"]=$callShell["output"][0];
226 liveuser 15217
 
3 liveuser 15218
		#如果未設置 $conf["line2start"]
15219
		if(!isset($conf["line2start"])){
226 liveuser 15220
 
3 liveuser 15221
			#$conf["line2start"]為總行數減去一次要看的行數減1
15222
			$conf["line2start"]=$result["totalLineCount"]-$conf["linesPerTime"]+1;
226 liveuser 15223
 
15224
			}#if end
15225
 
15226
		#如果開始行數小於1
3 liveuser 15227
		if($conf["line2start"]<1){
226 liveuser 15228
 
3 liveuser 15229
			#$conf["line2start"]為總行數減去一次要看的行數減1
15230
			$conf["line2start"]=$result["totalLineCount"]-$conf["linesPerTime"]+1;
226 liveuser 15231
 
3 liveuser 15232
			}#if end
226 liveuser 15233
 
15234
		#如果開始行數小於1
3 liveuser 15235
		if($conf["line2start"]<1){
226 liveuser 15236
 
3 liveuser 15237
			#$conf["line2start"]為1
15238
			$conf["line2start"]=1;
226 liveuser 15239
 
3 liveuser 15240
			}#if end
226 liveuser 15241
 
3 liveuser 15242
		#取得指定範圍的行數
15243
		#取得檔案的行數
15244
		#函式說明:
15245
		#呼叫shell執行系統命令,並取得回傳的內容.
15246
		#回傳的結果:
15247
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15248
		#$result["error"],錯誤訊息陣列.
15249
		#$result["function"],當前執行的函數名稱.
15250
		#$result["argu"],使用的參數.
15251
		#$result["cmd"],執行的指令內容.
15252
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15253
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15254
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15255
		#$result["running"],是否還在執行.
15256
		#$result["pid"],pid.
15257
		#$result["statusCode"],執行結束後的代碼.
15258
		#必填的參數
15259
		#$conf["command"],字串,要執行的指令與.
15260
		$conf["external::callShell"]["command"]="sed";
15261
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 15262
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 15263
		#可省略參數:
15264
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15265
		$conf["external::callShell"]["argu"]=array("-n",$conf["line2start"].",".($conf["line2start"]+$conf["linesPerTime"]-1)."p",$conf["file"]);
15266
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 15267
		#$conf["arguIsAddr"]=array();
3 liveuser 15268
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15269
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15270
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15271
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15272
		#$conf["enablePrintDescription"]="true";
15273
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15274
		#$conf["printDescription"]="";
15275
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
15276
		$conf["external::callShell"]["escapeshellarg"]="true";
15277
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15278
		#$conf["username"]="";
15279
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15280
		#$conf["password"]="";
15281
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15282
		#$conf["useScript"]="";
15283
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15284
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15285
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15286
		#$conf["inBackGround"]="";
15287
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
15288
		#$conf["getErr"]="false";
15289
		#備註:
15290
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15291
		#參考資料:
15292
		#exec=>http://php.net/manual/en/function.exec.php
15293
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15294
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15295
		$callShell=external::callShell($conf["external::callShell"]);
15296
		unset($conf["external::callShell"]);
15297
 
15298
		#如果檢查參數失敗
15299
		if($callShell["status"]==="false"){
226 liveuser 15300
 
3 liveuser 15301
			#設置執行失敗
15302
			$result["status"]="false";
226 liveuser 15303
 
3 liveuser 15304
			#設置執行失敗訊息
15305
			$result["error"]=$callShell;
226 liveuser 15306
 
3 liveuser 15307
			#回傳結果
15308
			return $result;
226 liveuser 15309
 
3 liveuser 15310
			}#if end
15311
 
15312
		#取得輸出的行數
15313
		$result["lines"]=count($callShell["output"]);
15314
 
15315
		#取得目前的輸出內容
15316
		$result["content"]=$callShell["output"];
15317
 
15318
		#取得當前行數
15319
		$result["lineNum"]=$conf["line2start"]+$result["lines"]-1;
15320
 
226 liveuser 15321
		#如果當前行號小於總行數
3 liveuser 15322
		if($result["lineNum"]<$result["totalLineCount"]){
15323
 
15324
			#設置還有剩餘的內容
15325
			$result["left"]="true";
226 liveuser 15326
 
3 liveuser 15327
			}#if end
15328
 
226 liveuser 15329
		#反之
3 liveuser 15330
		else{
15331
 
15332
			#設置無剩餘的內容
15333
			$result["left"]="false";
15334
 
15335
			}#else end
15336
 
15337
		#設置執行正常
15338
		$result["status"]="true";
15339
 
15340
		#回傳結果
15341
		return $result;
15342
 
15343
		}#function tail end
226 liveuser 15344
 
3 liveuser 15345
	/*
15346
	#函式說明:
15347
	#解析PHP檔案裡面的變數.
15348
	#回傳結果:
15349
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15350
	#$result["error"],錯誤訊息.
15351
	#$result["function"],當前執行的函數名稱.
226 liveuser 15352
	#$result["argu"],所使用的參數.
3 liveuser 15353
	#$result["content"],找到的變數內容陣列,若有多個變數則會用array來表示.
15354
	#必填參數:
15355
	#$conf["file"],字串,檔案的路徑與名稱.
15356
	$conf["file"]="";
15357
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
15358
	$conf["fileArgu"]=__FILE__;
15359
	#$conf["varName"],字串陣列,要搜尋的變數名稱,例如要搜尋變數$email則輸入"email".
15360
	$conf["varName"]=array();
15361
	#可省略參數:
15362
	#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false",預設為"false".
15363
	#$conf["web"]="true";
255 liveuser 15364
	#$conf["allVarCountSame"],字串,是否每個參數的數量要一致,預設為"false"不要;反之為"true"代表要.
15365
	#$conf["allVarCountSame"]="false";
3 liveuser 15366
	#參考資料:
15367
	#https://www.php.net/manual/en/function.parse-str.php
15368
	#備註:
15369
	#無.
15370
	*/
15371
	public static function parseVaraiableInPHPfile(&$conf){
226 liveuser 15372
 
3 liveuser 15373
		#初始化要回傳的結果
15374
		$result=array();
15375
 
15376
		#取得當前執行的函數名稱
15377
		$result["function"]=__FUNCTION__;
15378
 
15379
		#如果沒有參數
15380
		if(func_num_args()==0){
226 liveuser 15381
 
3 liveuser 15382
			#設置執行失敗
15383
			$result["status"]="false";
226 liveuser 15384
 
3 liveuser 15385
			#設置執行錯誤訊息
15386
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 15387
 
3 liveuser 15388
			#回傳結果
15389
			return $result;
15390
 
226 liveuser 15391
			}#if end
15392
 
3 liveuser 15393
		#取得參數
15394
		$result["argu"]=$conf;
15395
 
15396
		#如果 $conf 不為陣列
15397
		if(gettype($conf)!=="array"){
226 liveuser 15398
 
3 liveuser 15399
			#設置執行失敗
15400
			$result["status"]="false";
226 liveuser 15401
 
3 liveuser 15402
			#設置執行錯誤訊息
15403
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 15404
 
3 liveuser 15405
			#如果傳入的參數為 null
15406
			if($conf===null){
226 liveuser 15407
 
3 liveuser 15408
				#設置執行錯誤訊息
15409
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 15410
 
3 liveuser 15411
				}#if end
15412
 
15413
			#回傳結果
15414
			return $result;
226 liveuser 15415
 
3 liveuser 15416
			}#if end
226 liveuser 15417
 
3 liveuser 15418
		#函式說明:
15419
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
15420
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15421
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15422
		#$result["function"],當前執行的函式名稱.
15423
		#$result["argu"],設置給予的參數.
15424
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15425
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15426
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15427
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15428
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15429
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15430
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15431
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15432
		#必填寫的參數:
15433
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 15434
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 15435
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15436
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15437
		#可以省略的參數:
15438
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15439
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu","varName");
15440
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15441
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
15442
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15443
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15444
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15445
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file","fileArgu","varName");
15446
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15447
		#$conf["canBeEmpty"]=array();
15448
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
255 liveuser 15449
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web","allVarCountSame");
3 liveuser 15450
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
255 liveuser 15451
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web","allVarCountSame");
226 liveuser 15452
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
255 liveuser 15453
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
3 liveuser 15454
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 15455
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
3 liveuser 15456
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15457
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15458
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15459
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15460
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15461
		#$conf["arrayCountEqualCheck"][]=array();
15462
		#參考資料來源:
15463
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15464
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15465
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15466
 
3 liveuser 15467
		#如果檢查參數失敗
15468
		if($checkArguments["status"]==="false"){
226 liveuser 15469
 
3 liveuser 15470
			#設置執行失敗
15471
			$result["status"]="false";
226 liveuser 15472
 
3 liveuser 15473
			#設置執行失敗訊息
15474
			$result["error"]=$checkArguments;
226 liveuser 15475
 
3 liveuser 15476
			#回傳結果
15477
			return $result;
226 liveuser 15478
 
3 liveuser 15479
			}#if end
226 liveuser 15480
 
3 liveuser 15481
		#如果檢查參數不通過
15482
		if($checkArguments["passed"]==="false"){
226 liveuser 15483
 
3 liveuser 15484
			#設置執行失敗
15485
			$result["status"]="false";
226 liveuser 15486
 
3 liveuser 15487
			#設置執行失敗訊息
15488
			$result["error"]=$checkArguments;
226 liveuser 15489
 
3 liveuser 15490
			#回傳結果
15491
			return $result;
226 liveuser 15492
 
3 liveuser 15493
			}#if end
226 liveuser 15494
 
3 liveuser 15495
		#初始化儲存解析出來的變數內容
15496
		$result["content"]=array();
226 liveuser 15497
 
3 liveuser 15498
		#讀取檔案
15499
		#函式說明:
15500
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
15501
		#回傳的變數說明:
15502
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
15503
		#$result["error"],錯誤訊息提示.
15504
		#$result["warning"],警告訊息.
15505
		#$result["function"],當前執行的函數名稱.
15506
		#$result["fileContent"],爲檔案的內容陣列.
15507
		#$result["lineCount"],爲檔案內容總共的行數.
15508
		#$result["fullContent"],為檔案的完整內容.
15509
		#$result["base64data"],為檔案的base64內容.
15510
		#$result["mimeType"],為檔案的mime type.
15511
		#必填參數:
15512
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
15513
		$conf["ileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
15514
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
15515
		$conf["ileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
15516
		#可省略參數:
15517
		#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
15518
		$conf["ileAccess::getFileContent"]["web"]=$conf["web"];
15519
		#參考資料:
15520
		#file(),取得檔案內容的行數.
15521
		#file=>http:#php.net/manual/en/function.file.php
15522
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
15523
		#filesize=>http://php.net/manual/en/function.filesize.php
15524
		$getFileContent=fileAccess::getFileContent($conf["ileAccess::getFileContent"]);
15525
		unset($conf["ileAccess::getFileContent"]);
15526
 
15527
		#如果讀取檔案失敗
15528
		if($getFileContent["status"]==="false"){
226 liveuser 15529
 
3 liveuser 15530
			#設置執行失敗
15531
			$result["status"]="false";
226 liveuser 15532
 
3 liveuser 15533
			#設置執行失敗訊息
15534
			$result["error"]=$getFileContent;
226 liveuser 15535
 
3 liveuser 15536
			#回傳結果
15537
			return $result;
226 liveuser 15538
 
3 liveuser 15539
			}#if end
226 liveuser 15540
 
3 liveuser 15541
		#針對每列檔案內容
15542
		foreach($getFileContent["fileContent"] as $line){
226 liveuser 15543
 
3 liveuser 15544
			#針對每個要搜尋的變數
15545
			foreach($conf["varName"] as $keyWord){
226 liveuser 15546
 
3 liveuser 15547
				#如果關鍵字小於被搜尋的字串長度
15548
				if( strlen($line) < strlen($keyWord)+1 ){
226 liveuser 15549
 
3 liveuser 15550
					#跳過
15551
					continue;
226 liveuser 15552
 
3 liveuser 15553
					}#if end
226 liveuser 15554
 
3 liveuser 15555
				#函式說明:
15556
				#取得符合特定字首與字尾的字串
15557
				#回傳結果:
15558
				#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
15559
				#$result["function"],當前執行的函數名稱.
15560
				#$result["error"],錯誤訊息陣列.
15561
				#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
15562
				#$result["returnString"],爲符合字首條件的字串內容。
15563
				#$result["argu"],使用的參數.
15564
				#必填參數:
15565
				#$conf["checkString"],字串,要檢查的字串.
15566
				$conf["search::getMeetConditionsString"]["checkString"]=$line;
15567
				#可省略參數:
15568
				#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
15569
				$conf["search::getMeetConditionsString"]["frontWord"]="$".$keyWord;
15570
				#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
15571
				$conf["search::getMeetConditionsString"]["tailWord"]=";";
15572
				#參考資料:
15573
				#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
15574
				$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
15575
				unset($conf["search::getMeetConditionsString"]);
226 liveuser 15576
 
3 liveuser 15577
				#如果失敗
15578
				if($getMeetConditionsString["status"]==="false"){
15579
 
15580
					#設置執行失敗
15581
					$result["status"]="false";
226 liveuser 15582
 
3 liveuser 15583
					#設置執行失敗訊息
15584
					$result["error"]=$getMeetConditionsString;
226 liveuser 15585
 
3 liveuser 15586
					#回傳結果
15587
					return $result;
226 liveuser 15588
 
15589
					}#if end
15590
 
3 liveuser 15591
				#如果有找到關鍵字
15592
				if($getMeetConditionsString["founded"]==="true"){
226 liveuser 15593
 
3 liveuser 15594
					#剔除變數名稱
15595
					#函式說明:
15596
					#將字串特定關鍵字與其前面的內容剔除
15597
					#回傳結果:
15598
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15599
					#$result["error"],錯誤訊息陣列.
15600
					#$result["warning"],警告訊息鎮列.
15601
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
15602
					#$result["function"],當前執行的函數名稱.
15603
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 15604
					#$result["content"],處理好的的字串內容.
3 liveuser 15605
					#必填參數:
15606
					#$conf["stringIn"],字串,要處理的字串.
15607
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$line;
15608
					#$conf["keyWord"],字串,特定字串.
15609
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="$".$keyWord;
15610
					#可省略參數:
15611
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,直到沒有關鍵字為止.
15612
					#$conf["recursive"]="true";
15613
					#參考資料:
15614
					#無.
15615
					#備註:
15616
					#無.
15617
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
15618
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 15619
 
3 liveuser 15620
					#如果執行失敗
15621
					if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 15622
 
3 liveuser 15623
						#設置執行失敗
15624
						$result["status"]="false";
226 liveuser 15625
 
3 liveuser 15626
						#設置執行失敗訊息
15627
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15628
 
3 liveuser 15629
						#回傳結果
15630
						return $result;
226 liveuser 15631
 
3 liveuser 15632
						}#if end
226 liveuser 15633
 
3 liveuser 15634
					#如果沒有找到應該存在的php變數
15635
					if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 15636
 
3 liveuser 15637
						#設置執行失敗
15638
						$result["status"]="false";
226 liveuser 15639
 
3 liveuser 15640
						#設置執行失敗訊息
15641
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15642
 
3 liveuser 15643
						#回傳結果
15644
						return $result;
226 liveuser 15645
 
3 liveuser 15646
						}#if end
226 liveuser 15647
 
3 liveuser 15648
					#剔除 "=" 前面的內容
15649
					#函式說明:
15650
					#將字串特定關鍵字與其前面的內容剔除
15651
					#回傳結果:
15652
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15653
					#$result["error"],錯誤訊息陣列.
15654
					#$result["warning"],警告訊息鎮列.
15655
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
15656
					#$result["function"],當前執行的函數名稱.
15657
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 15658
					#$result["content"],處理好的的字串內容.
3 liveuser 15659
					#必填參數:
15660
					#$conf["stringIn"],字串,要處理的字串.
15661
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
15662
					#$conf["keyWord"],字串,特定字串.
15663
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="=";
15664
					#可省略參數:
15665
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,直到沒有關鍵字為止.
15666
					#$conf["recursive"]="true";
15667
					#參考資料:
15668
					#無.
15669
					#備註:
15670
					#無.
15671
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
15672
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 15673
 
3 liveuser 15674
					#如果執行失敗
15675
					if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 15676
 
3 liveuser 15677
						#設置執行失敗
15678
						$result["status"]="false";
226 liveuser 15679
 
3 liveuser 15680
						#設置執行失敗訊息
15681
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15682
 
3 liveuser 15683
						#回傳結果
15684
						return $result;
226 liveuser 15685
 
3 liveuser 15686
						}#if end
226 liveuser 15687
 
3 liveuser 15688
					#如果沒有找“=”關鍵字
15689
					if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 15690
 
3 liveuser 15691
						#跳過
15692
						continue;
226 liveuser 15693
 
3 liveuser 15694
						}#if end
226 liveuser 15695
 
3 liveuser 15696
					#剔除 value 前面的空白
15697
					#函式說明:
288 liveuser 15698
					#移除字串開頭的特定內容
3 liveuser 15699
					#回傳結果:
288 liveuser 15700
					#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
3 liveuser 15701
					#$result["error"],錯誤訊息陣列.
288 liveuser 15702
					#$result["function"],當前執行的函數.
15703
					#$result["content"],處理好的字串.
15704
					#$result["argu"],使用的參數.
3 liveuser 15705
					#必填參數:
288 liveuser 15706
					#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
15707
					$conf["stringProcess::delKeyWordsInStrHead"]["inputStr"]=$delStrBeforeKeyWord["content"];
15708
					#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
15709
					$conf["stringProcess::delKeyWordsInStrHead"]["keyWord"]=" ";
3 liveuser 15710
					#可省略參數:
288 liveuser 15711
					#$conf["recursive"],字串,"true"代表要遞迴移除開頭的關鍵字,預設為"false",只移除開頭關鍵字1次.
15712
					$conf["stringProcess::delKeyWordsInStrHead"]["recursive"]="true";
3 liveuser 15713
					#參考資料:
15714
					#無.
15715
					#備註:
15716
					#無.
288 liveuser 15717
					$delKeyWordsInStrHead=stringProcess::delKeyWordsInStrHead($conf["stringProcess::delKeyWordsInStrHead"]);
15718
					unset($conf["stringProcess::delKeyWordsInStrHead"]);
226 liveuser 15719
 
3 liveuser 15720
					#如果執行失敗
288 liveuser 15721
					if($delKeyWordsInStrHead["status"]==="false"){
226 liveuser 15722
 
3 liveuser 15723
						#設置執行失敗
15724
						$result["status"]="false";
226 liveuser 15725
 
3 liveuser 15726
						#設置執行失敗訊息
288 liveuser 15727
						$result["error"]=$delKeyWordsInStrHead;
226 liveuser 15728
 
3 liveuser 15729
						#回傳結果
15730
						return $result;
226 liveuser 15731
 
3 liveuser 15732
						}#if end
226 liveuser 15733
 
316 liveuser 15734
					#取得找到的變數的語法
15735
					$phpCode="\$result[\"content\"][\"".$keyWord."\"][]=".$delKeyWordsInStrHead["content"];
15736
 
3 liveuser 15737
					#取得找到的變數
316 liveuser 15738
					eval($phpCode);
226 liveuser 15739
 
3 liveuser 15740
					}#if end
226 liveuser 15741
 
3 liveuser 15742
				}#foreach end
226 liveuser 15743
 
3 liveuser 15744
			}#foreach end
226 liveuser 15745
 
255 liveuser 15746
		#如果 allVarCountSame 設置為 "true"
15747
		if($conf["allVarCountSame"]==="true"){
15748
 
15749
			#每個變數的數量初始為0
15750
			$count=0;
15751
 
15752
			#針對每個解析出來的變數
15753
			foreach($conf["varName"] as $varName){
15754
 
15755
				#取得該變數數量
15756
				$varCount=count($result["content"][$varName]);
15757
 
15758
				#如果尚無變數數量資料
15759
				if($count===0){
15760
 
15761
					#直接儲存之
15762
					$count=$varCount;
15763
 
15764
					#看下一個變數
15765
					continue;
15766
 
15767
					}#if end
15768
 
15769
				#如果變數數量不一樣
15770
				if($count!==$varCount){
15771
 
15772
					#設置執行失敗
15773
					$result["status"]="false";
15774
 
15775
					#設置執行失敗訊息
15776
					$result["error"]="config file error";
15777
 
15778
					#回傳結果
15779
					return $result;
15780
 
15781
					}#if end
15782
 
15783
				}#foreach end
15784
 
15785
			}#if end
15786
 
3 liveuser 15787
		#設置執行正常
15788
		$result["status"]="true";
226 liveuser 15789
 
3 liveuser 15790
		#回傳結果
15791
		return $result;
226 liveuser 15792
 
3 liveuser 15793
		}#function parseVaraiableInPHPfile end
15794
 
15795
	/*
15796
	#函式說明:
15797
	#開啟特定目錄,取得底下的檔案路徑清單.
15798
	#回傳結果:
15799
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15800
	#$result["error"],錯誤訊息.
15801
	#$result["function"],當前執行的函數名稱.
15802
	#$result["argu"],所使用的參數.
15803
	#$result["content"],讀取到的內容陣列.
15804
	#$result["content"][$i],第$i+1個結果.
15805
	#$result["content"][$i]["name"],第$i+1個名稱.
15806
	#$result["content"][$i]["dir"],第$i+1個檔案是否為資料夾.
15807
	#$result["content"][$i]["info"],第$i+1個檔案的額外資訊.
15808
	#$result["content"][$i]["size"],第$i+1個檔案的大小(bytes).
15809
	#必填參數:
15810
	#$conf["path"],字串,要取得檔案資訊的所屬路徑.
15811
	$conf["path"]="";
15812
	#可省略參數:
15813
	#無.
15814
	#參考資料
15815
	#無.
15816
	#備註:
15817
	#無.
15818
	*/
15819
	public static function listInfo(&$conf){
226 liveuser 15820
 
3 liveuser 15821
		#初始化要回傳的結果
15822
		$result=array();
15823
 
15824
		#取得當前執行的函數名稱
15825
		$result["function"]=__FUNCTION__;
15826
 
15827
		#如果沒有參數
15828
		if(func_num_args()==0){
226 liveuser 15829
 
3 liveuser 15830
			#設置執行失敗
15831
			$result["status"]="false";
226 liveuser 15832
 
3 liveuser 15833
			#設置執行錯誤訊息
15834
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 15835
 
3 liveuser 15836
			#回傳結果
15837
			return $result;
15838
 
226 liveuser 15839
			}#if end
15840
 
3 liveuser 15841
		#取得參數
15842
		$result["argu"]=$conf;
15843
 
15844
		#如果 $conf 不為陣列
15845
		if(gettype($conf)!=="array"){
226 liveuser 15846
 
3 liveuser 15847
			#設置執行失敗
15848
			$result["status"]="false";
226 liveuser 15849
 
3 liveuser 15850
			#設置執行錯誤訊息
15851
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 15852
 
3 liveuser 15853
			#如果傳入的參數為 null
15854
			if($conf===null){
226 liveuser 15855
 
3 liveuser 15856
				#設置執行錯誤訊息
15857
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 15858
 
3 liveuser 15859
				}#if end
15860
 
15861
			#回傳結果
15862
			return $result;
226 liveuser 15863
 
3 liveuser 15864
			}#if end
226 liveuser 15865
 
3 liveuser 15866
		#函式說明:
15867
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
15868
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15869
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15870
		#$result["function"],當前執行的函式名稱.
15871
		#$result["argu"],設置給予的參數.
15872
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15873
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15874
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15875
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15876
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15877
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15878
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15879
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15880
		#必填寫的參數:
15881
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 15882
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 15883
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15884
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15885
		#可以省略的參數:
15886
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15887
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
15888
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15889
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
15890
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15891
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15892
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15893
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
15894
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15895
		#$conf["canBeEmpty"]=array();
15896
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
15897
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
15898
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
15899
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 15900
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 15901
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
15902
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
15903
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
15904
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15905
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15906
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15907
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15908
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15909
		#$conf["arrayCountEqualCheck"][]=array();
15910
		#參考資料來源:
15911
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15912
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15913
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15914
 
3 liveuser 15915
		#如果檢查參數失敗
15916
		if($checkArguments["status"]==="false"){
226 liveuser 15917
 
3 liveuser 15918
			#設置執行失敗
15919
			$result["status"]="false";
226 liveuser 15920
 
3 liveuser 15921
			#設置執行失敗訊息
15922
			$result["error"]=$checkArguments;
226 liveuser 15923
 
3 liveuser 15924
			#回傳結果
15925
			return $result;
226 liveuser 15926
 
3 liveuser 15927
			}#if end
226 liveuser 15928
 
3 liveuser 15929
		#如果檢查參數不通過
15930
		if($checkArguments["passed"]==="false"){
226 liveuser 15931
 
3 liveuser 15932
			#設置執行失敗
15933
			$result["status"]="false";
226 liveuser 15934
 
3 liveuser 15935
			#設置執行失敗訊息
15936
			$result["error"]=$checkArguments;
226 liveuser 15937
 
3 liveuser 15938
			#回傳結果
15939
			return $result;
226 liveuser 15940
 
3 liveuser 15941
			}#if end
226 liveuser 15942
 
3 liveuser 15943
		#初始化儲存解析出來的變數內容
15944
		$result["content"]=array();
226 liveuser 15945
 
3 liveuser 15946
		#取得特定位置的資訊
15947
		$pathInfo=@dir($conf["path"]);
226 liveuser 15948
 
3 liveuser 15949
		#如果取得路徑資訊失敗
15950
		if($pathInfo===false){
226 liveuser 15951
 
3 liveuser 15952
			#設置執行失敗
15953
			$result["status"]="false";
226 liveuser 15954
 
3 liveuser 15955
			#設置執行失敗訊息
15956
			$result["error"][]="無法存取路徑(".$conf["path"].")";
226 liveuser 15957
 
3 liveuser 15958
			#回傳結果
15959
			return $result;
226 liveuser 15960
 
3 liveuser 15961
			}#if end
226 liveuser 15962
 
3 liveuser 15963
		#讀取底下一個檔案,暫存到 $tmpItem 裡面,且當結果不為 false 時進入迴圈.
15964
		while(false !== $tmpItem = $pathInfo->read()){
226 liveuser 15965
 
3 liveuser 15966
			#宣告儲存資訊的變數
15967
			$item=array();
226 liveuser 15968
 
3 liveuser 15969
			#儲存名稱
15970
			$item["name"]=$tmpItem;
226 liveuser 15971
 
3 liveuser 15972
			#預設不為資料夾
15973
			$item["dir"]="false";
226 liveuser 15974
 
3 liveuser 15975
			#若為資料夾
15976
			if(is_dir($conf["path"]."/".$tmpItem)){
226 liveuser 15977
 
3 liveuser 15978
				#設置為"true"
15979
				$item["dir"]="true";
226 liveuser 15980
 
3 liveuser 15981
				}#if end
226 liveuser 15982
 
3 liveuser 15983
			#取得檔案識別器
15984
			$finfo = finfo_open(FILEINFO_MIME);
226 liveuser 15985
 
3 liveuser 15986
			#取得 info
15987
			$item["info"]=@finfo_file($finfo,$conf["path"]."/".$tmpItem);
15988
 
15989
			#取得檔案大小
15990
			$item["size"]=filesize($conf["path"]."/".$tmpItem);
15991
 
15992
			#close connection
15993
			finfo_close($finfo);
226 liveuser 15994
 
3 liveuser 15995
			#記錄該檔案資訊
15996
			$result["content"][]=$item;
226 liveuser 15997
 
3 liveuser 15998
			}#while end
226 liveuser 15999
 
3 liveuser 16000
		#設置執行正常
16001
		$result["status"]="true";
226 liveuser 16002
 
3 liveuser 16003
		#回傳結果
16004
		return $result;
226 liveuser 16005
 
3 liveuser 16006
		}#function listInfo end
16007
 
16008
	/*
16009
	#函式說明:
16010
	#取得目錄底下的詳細資訊.
16011
	#回傳結果:
16012
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16013
	#$result["error"],錯誤訊息.
16014
	#$result["function"],當前執行的函數名稱.
16015
	#$result["size"],該清單的大小,單位為bytes.
16016
	#$result["dataCount"],該清單的長度.
16017
	#$result["path"],字串,檢視的路徑,必為"/"結尾.
16018
	#$result["content"],指定目錄底下的所有檔案資訊.
16019
	#$result["content"][$i]["nType&permission"],第$i個節點類型、權限.
16020
	#$result["content"][$i]["nType"],第$i個節點類型,"-"代表檔案,"d"代表資料夾.
16021
	#$result["content"][$i]["permission"],第$i個節點權限.
16022
	#$result["content"][$i]["ownByUser"],第$i個節點擁有者賬號.
16023
	#$result["content"][$i]["ownByGroup"],第$i個節點擁有者群組.
16024
	#$result["content"][$i]["bytes"],第$i個節點大小.
16025
	#$result["content"][$i]["date"],第$i個節點最後變更日期.
16026
	#$result["content"][$i]["time"],第$i個節點最後異動時間.
16027
	#$result["content"][$i]["timeDetail"],第$i個節點最後異動詳細時間.
16028
	#$result["content"][$i]["timezone"],第$i個節點的時區.
16029
	#$result["content"][$i]["name"],第$i個節點的名稱.
16030
	#$result["content"][$i]["secondName"],第$i個節點為檔案時,若有附檔名,會記錄在這.
16031
	#$result["content"][$i]["mimeType"],第$i個節點為檔案且可以讀取時,會有 mime type 可取得.
16032
	#必填參數:
16033
	#$conf["path"],字串,要檢視的路徑,若非"/"結尾,會自動補上.
16034
	$conf["path"]="";
16035
	#可省略參數:
16036
	#無.
16037
	#參考資料:
16038
	#https://www.businessweekly.com.tw/careers/Blog/14307
16039
	#備註:
16040
	#無.
16041
	*/
16042
	public static function ls(&$conf){
226 liveuser 16043
 
3 liveuser 16044
		#初始化要回傳的結果
16045
		$result=array();
16046
 
16047
		#取得當前執行的函數名稱
16048
		$result["function"]=__FUNCTION__;
16049
 
16050
		#如果沒有參數
16051
		if(func_num_args()==0){
16052
 
16053
			#設置執行失敗
16054
			$result["status"]="false";
16055
 
16056
			#設置執行錯誤訊息
16057
			$result["error"]="函數".$result["function"]."需要參數";
16058
 
16059
			#回傳結果
16060
			return $result;
16061
 
16062
			}#if end
16063
 
16064
		#取得參數
16065
		$result["argu"]=$conf;
16066
 
16067
		#如果 $conf 不為陣列
16068
		if(gettype($conf)!=="array"){
16069
 
16070
			#設置執行失敗
16071
			$result["status"]="false";
16072
 
16073
			#設置執行錯誤訊息
16074
			$result["error"][]="\$conf變數須為陣列形態";
16075
 
16076
			#如果傳入的參數為 null
16077
			if(is_null($conf)){
16078
 
16079
				#設置執行錯誤訊息
16080
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
16081
 
16082
				}#if end
16083
 
16084
			#回傳結果
16085
			return $result;
16086
 
16087
			}#if end
226 liveuser 16088
 
3 liveuser 16089
		#函式說明:
16090
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
16091
		#回傳結果:
16092
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16093
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
16094
		#$result["simpleError"],簡單表示的錯誤訊息.
16095
		#$result["function"],當前執行的函式名稱.
16096
		#$result["argu"],設置給予的參數.
16097
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
16098
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
16099
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
16100
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
16101
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
16102
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
16103
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
16104
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
16105
		#必填參數:
16106
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
16107
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
16108
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
16109
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
16110
		#可省略參數:
16111
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
16112
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
16113
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
16114
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
16115
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
16116
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
16117
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
16118
		#$conf["canNotBeEmpty"]=array();
16119
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
16120
		#$conf["canBeEmpty"]=array();
16121
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
16122
		#$conf["skipableVariableCanNotBeEmpty"]=array();
16123
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
16124
		#$conf["skipableVariableName"]=array();
16125
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
16126
		#$conf["skipableVariableType"]=array();
16127
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
16128
		#$conf["skipableVarDefaultValue"]=array("");
16129
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
16130
		#$conf["disallowAllSkipableVarIsEmpty"]="";
16131
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
16132
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
16133
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
16134
		#$conf["arrayCountEqualCheck"][]=array();
16135
		#參考資料:
16136
		#array_keys=>http://php.net/manual/en/function.array-keys.php
16137
		#備註:
16138
		#無.
16139
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
16140
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 16141
 
3 liveuser 16142
		#如果執行失敗
16143
		if($checkArguments["status"]==="false"){
226 liveuser 16144
 
3 liveuser 16145
			#設置執行錯誤
16146
			$result["status"]="false";
226 liveuser 16147
 
3 liveuser 16148
			#設置錯誤訊息
16149
			$result["error"]=$checkArguments;
226 liveuser 16150
 
3 liveuser 16151
			#回傳結果
16152
			return $result;
226 liveuser 16153
 
3 liveuser 16154
			}#if end
226 liveuser 16155
 
3 liveuser 16156
		#如果參數檢查不通過
16157
		if($checkArguments["passed"]==="false"){
226 liveuser 16158
 
3 liveuser 16159
			#設置執行錯誤
16160
			$result["status"]="false";
226 liveuser 16161
 
3 liveuser 16162
			#設置錯誤訊息
16163
			$result["error"]=$checkArguments;
226 liveuser 16164
 
3 liveuser 16165
			#回傳結果
16166
			return $result;
226 liveuser 16167
 
3 liveuser 16168
			}#if end
226 liveuser 16169
 
3 liveuser 16170
		#確認 $conf["path"] 是否為 "/" 結尾
16171
		#函式說明:
16172
		#取得符合特定字首與字尾的字串
16173
		#回傳結果:
16174
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
16175
		#$result["function"],當前執行的函數名稱.
16176
		#$result["error"],錯誤訊息陣列.
16177
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
16178
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
16179
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
16180
		#$result["argu"],使用的參數.
16181
		#必填參數:
16182
		#$conf["checkString"],字串,要檢查的字串.
16183
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["path"];
16184
		#可省略參數:
16185
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
16186
		#$conf["frontWord"]="";
16187
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
16188
		$conf["search::getMeetConditionsString"]["tailWord"]="/";
16189
		#參考資料:
16190
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
16191
		#備註:
16192
		#無.
16193
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
16194
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 16195
 
3 liveuser 16196
		#如果執行失敗
16197
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 16198
 
3 liveuser 16199
			#設置執行錯誤
16200
			$result["status"]="false";
226 liveuser 16201
 
3 liveuser 16202
			#設置錯誤訊息
16203
			$result["error"]=$getMeetConditionsString;
226 liveuser 16204
 
3 liveuser 16205
			#回傳結果
16206
			return $result;
226 liveuser 16207
 
3 liveuser 16208
			}#if end
226 liveuser 16209
 
3 liveuser 16210
		#如果沒有 "/" 結尾
16211
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 16212
 
3 liveuser 16213
			#於結尾加上 "/"
16214
			$conf["path"]=$conf["path"]."/";
226 liveuser 16215
 
3 liveuser 16216
			}#if end
226 liveuser 16217
 
3 liveuser 16218
		#記錄真正的路徑
16219
		$result["path"]=$conf["path"];
226 liveuser 16220
 
3 liveuser 16221
		#函式說明:
16222
		#呼叫shell執行系統命令,並取得回傳的內容.
16223
		#回傳結果:
16224
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16225
		#$result["error"],錯誤訊息陣列.
16226
		#$result["function"],當前執行的函數名稱.
16227
		#$result["argu"],使用的參數.
16228
		#$result["cmd"],執行的指令內容.
16229
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16230
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16231
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16232
		#$result["running"],是否還在執行.
16233
		#$result["pid"],pid.
16234
		#$result["statusCode"],執行結束後的代碼.
16235
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
16236
		#必填參數:
16237
		#$conf["command"],字串,要執行的指令.
16238
		$conf["external::callShell"]["command"]="ls";
16239
		#$conf["fileArgu"],字串,變數__FILE__的內容.
16240
		$conf["external::callShell"]["fileArgu"]=__FILE__;
16241
		#可省略參數:
16242
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16243
		$conf["external::callShell"]["argu"]=array("-al","--full-time","-t","-B",$conf["path"]);
16244
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16245
		#$conf["arguIsAddr"]=array();
16246
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16247
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16248
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16249
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16250
		#$conf["enablePrintDescription"]="true";
16251
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16252
		#$conf["printDescription"]="";
16253
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16254
		$conf["external::callShell"]["escapeshellarg"]="true";
16255
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16256
		#$conf["thereIsShellVar"]=array();
16257
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16258
		#$conf["username"]="";
16259
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16260
		#$conf["password"]="";
16261
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16262
		#$conf["useScript"]="";
16263
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16264
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16265
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16266
		#$conf["inBackGround"]="";
16267
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16268
		#$conf["getErr"]="false";
16269
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16270
		#$conf["doNotRun"]="false";
16271
		#參考資料:
16272
		#exec=>http://php.net/manual/en/function.exec.php
16273
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16274
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16275
		#備註:
16276
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16277
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
16278
		$callShell=external::callShell($conf["external::callShell"]);
16279
		unset($conf["external::callShell"]);
226 liveuser 16280
 
3 liveuser 16281
		#debug
16282
		#var_dump(__FILE__,__LINE__,$callShell);
226 liveuser 16283
 
3 liveuser 16284
		#如果執行失敗
16285
		if($callShell["status"]==="false"){
226 liveuser 16286
 
3 liveuser 16287
			#設置執行錯誤
16288
			$result["status"]="false";
226 liveuser 16289
 
3 liveuser 16290
			#設置錯誤訊息
16291
			$result["error"]=$callShell;
226 liveuser 16292
 
3 liveuser 16293
			#回傳結果
16294
			return $result;
226 liveuser 16295
 
3 liveuser 16296
			}#if end
226 liveuser 16297
 
3 liveuser 16298
		#初始化儲存檔案資訊為空
16299
		$result["content"]=array();
226 liveuser 16300
 
3 liveuser 16301
		#針對每行輸出
16302
		foreach($callShell["output"] as $index=>$line){
226 liveuser 16303
 
3 liveuser 16304
			#如果是第一筆
16305
			if($index===0){
226 liveuser 16306
 
3 liveuser 16307
				#取得資料筆數
16308
				$result["dataCount"]=explode(" ",$line)[0];
226 liveuser 16309
 
3 liveuser 16310
				#換下一輪
16311
				continue;
226 liveuser 16312
 
3 liveuser 16313
				}#if end
226 liveuser 16314
 
3 liveuser 16315
			#函式說明:
16316
			#將固定格式的字串分開,並回傳分開的結果.
16317
			#回傳結果:
16318
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16319
			#$result["error"],錯誤訊息陣列
16320
			#$result["function"],當前執行的函數名稱.
16321
			#$result["argu"],使用的參數.
16322
			#$result["oriStr"],要分割的原始字串內容
16323
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
16324
			#$result["dataCounts"],爲總共分成幾段
16325
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
16326
			#必填參數:
16327
			#$conf["stringIn"],字串,要處理的字串.
16328
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
16329
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
16330
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
16331
			#可省略參數:
16332
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
16333
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
16334
			#參考資料:
16335
			#無.
16336
			#備註:
16337
			#無.
16338
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
16339
			unset($conf["stringProcess::spiltString"]);
226 liveuser 16340
 
3 liveuser 16341
			#如果執行失敗
16342
			if($spiltString["status"]==="false"){
226 liveuser 16343
 
3 liveuser 16344
				#設置執行錯誤
16345
				$result["status"]="false";
226 liveuser 16346
 
3 liveuser 16347
				#設置錯誤訊息
16348
				$result["error"]=$spiltString;
226 liveuser 16349
 
3 liveuser 16350
				#回傳結果
16351
				return $result;
226 liveuser 16352
 
3 liveuser 16353
				}#if end
226 liveuser 16354
 
3 liveuser 16355
			#如果沒有分割用的" "
16356
			if($spiltString["found"]==="false"){
226 liveuser 16357
 
3 liveuser 16358
				#設置執行錯誤
16359
				$result["status"]="false";
226 liveuser 16360
 
3 liveuser 16361
				#設置錯誤訊息
16362
				$result["error"]=$spiltString;
226 liveuser 16363
 
3 liveuser 16364
				#回傳結果
16365
				return $result;
226 liveuser 16366
 
3 liveuser 16367
				}#if end
226 liveuser 16368
 
3 liveuser 16369
			#如果分割好的數量小於8
16370
			if($spiltString["dataCounts"]<8){
226 liveuser 16371
 
3 liveuser 16372
				#設置執行錯誤
16373
				$result["status"]="false";
226 liveuser 16374
 
3 liveuser 16375
				#設置錯誤訊息
16376
				$result["error"]=$spiltString;
226 liveuser 16377
 
3 liveuser 16378
				#回傳結果
16379
				return $result;
226 liveuser 16380
 
3 liveuser 16381
				}#if end
226 liveuser 16382
 
3 liveuser 16383
			#初始化要儲存的檔案資訊陣列
16384
			$fileInfo=array();
226 liveuser 16385
 
3 liveuser 16386
			#取得 節點類型、權限
16387
			$fileInfo["nType&permission"]=$spiltString["dataArray"][0];
226 liveuser 16388
 
3 liveuser 16389
			#剔除結尾的 "."
16390
			$fileInfo["nType&permission"]=substr($fileInfo["nType&permission"],0,strlen($fileInfo["nType&permission"])-1);
226 liveuser 16391
 
3 liveuser 16392
			#取得節點類型
16393
			$fileInfo["nType"]=$fileInfo["nType&permission"][0];
226 liveuser 16394
 
3 liveuser 16395
			#取得節點權限
16396
			$fileInfo["permission"]=substr($fileInfo["nType&permission"],1);
226 liveuser 16397
 
3 liveuser 16398
			#取得擁有者賬號
16399
			$fileInfo["ownByUser"]=$spiltString["dataArray"][2];
226 liveuser 16400
 
3 liveuser 16401
			#取得群組擁有者群組
16402
			$fileInfo["ownByGroup"]=$spiltString["dataArray"][3];
226 liveuser 16403
 
3 liveuser 16404
			#取得size
16405
			$fileInfo["bytes"]=$spiltString["dataArray"][4];
226 liveuser 16406
 
16407
			#取得最後異動日期
3 liveuser 16408
			$fileInfo["date"]=$spiltString["dataArray"][5];
226 liveuser 16409
 
3 liveuser 16410
			#取得最後異動時間
16411
			$fileInfo["time"]=explode(".",$spiltString["dataArray"][6])[0];
226 liveuser 16412
 
3 liveuser 16413
			#取得最後異動的詳細時間
16414
			$fileInfo["timeDetail"]=$spiltString["dataArray"][6];
226 liveuser 16415
 
3 liveuser 16416
			#取得timezone資訊
16417
			$fileInfo["timezone"]=$spiltString["dataArray"][7];
226 liveuser 16418
 
3 liveuser 16419
			#函式說明:
16420
			#將固定格式的字串分開,並回傳分開的結果.
16421
			#回傳結果:
16422
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16423
			#$result["error"],錯誤訊息陣列
16424
			#$result["function"],當前執行的函數名稱.
16425
			#$result["argu"],使用的參數.
16426
			#$result["oriStr"],要分割的原始字串內容
16427
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
16428
			#$result["dataCounts"],爲總共分成幾段
16429
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
16430
			#必填參數:
16431
			#$conf["stringIn"],字串,要處理的字串.
16432
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
16433
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
16434
			$conf["stringProcess::spiltString"]["spiltSymbol"]=$fileInfo["date"]." ".$fileInfo["timeDetail"]." ".$fileInfo["timezone"];
16435
			#可省略參數:
16436
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
16437
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
16438
			#參考資料:
16439
			#無.
16440
			#備註:
16441
			#無.
16442
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
16443
			unset($conf["stringProcess::spiltString"]);
226 liveuser 16444
 
3 liveuser 16445
			#如果執行失敗
16446
			if($spiltString["status"]==="false"){
226 liveuser 16447
 
3 liveuser 16448
				#設置執行錯誤
16449
				$result["status"]="false";
226 liveuser 16450
 
3 liveuser 16451
				#設置錯誤訊息
16452
				$result["error"]=$spiltString;
226 liveuser 16453
 
3 liveuser 16454
				#回傳結果
16455
				return $result;
226 liveuser 16456
 
3 liveuser 16457
				}#if end
226 liveuser 16458
 
3 liveuser 16459
			#如果沒有分割用的" "
16460
			if($spiltString["found"]==="false"){
226 liveuser 16461
 
3 liveuser 16462
				#設置執行錯誤
16463
				$result["status"]="false";
226 liveuser 16464
 
3 liveuser 16465
				#設置錯誤訊息
16466
				$result["error"]=$spiltString;
226 liveuser 16467
 
3 liveuser 16468
				#回傳結果
16469
				return $result;
226 liveuser 16470
 
3 liveuser 16471
				}#if end
226 liveuser 16472
 
3 liveuser 16473
			#如果分割好的數量小於8
16474
			if($spiltString["dataCounts"]<2){
226 liveuser 16475
 
3 liveuser 16476
				#設置執行錯誤
16477
				$result["status"]="false";
226 liveuser 16478
 
3 liveuser 16479
				#設置錯誤訊息
16480
				$result["error"]=$spiltString;
226 liveuser 16481
 
3 liveuser 16482
				#回傳結果
16483
				return $result;
226 liveuser 16484
 
3 liveuser 16485
				}#if end
226 liveuser 16486
 
3 liveuser 16487
			#取得節點名稱,剔除開頭的空白.
16488
			$fileInfo["name"]=substr($spiltString["dataArray"][1],1);
226 liveuser 16489
 
3 liveuser 16490
			#排除 "." 跟 ".."
16491
			if($fileInfo["name"]==="." || $fileInfo["name"]===".."){
226 liveuser 16492
 
3 liveuser 16493
				#跳過
16494
				continue;
226 liveuser 16495
 
3 liveuser 16496
				}#if end
226 liveuser 16497
 
3 liveuser 16498
			#如果是檔案
16499
			if($fileInfo["nType"]==="-"){
226 liveuser 16500
 
3 liveuser 16501
				#取得mime type
16502
				$fileInfo["mimeType"]=@mime_content_type($conf["path"].$fileInfo["name"]);
226 liveuser 16503
 
3 liveuser 16504
				#如果讀取失敗
16505
				if($fileInfo["mimeType"]===false){
226 liveuser 16506
 
3 liveuser 16507
					#通常為沒有權限
226 liveuser 16508
 
3 liveuser 16509
					#跳過該檔案
16510
					continue;
226 liveuser 16511
 
3 liveuser 16512
					}#if end
226 liveuser 16513
 
3 liveuser 16514
				#確認檔案名稱中間含是否有 "."
16515
				#函式說明:
16516
				#取得關鍵字在字串的哪個位置(字首,字尾,中間)
16517
				#回傳結果:
16518
				#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
16519
				#$result["error"],錯誤訊息陣列.
16520
				#$result["function"],當前執行的函數名稱.
16521
				#$result["found"],是否有關鍵字存在,若為"true",代表存在;反之為"false".
16522
				#$result["argu"],傳入的參數.
16523
				#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
16524
				#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
16525
				#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
16526
				#$result["indexS"],關鍵字在被搜尋字串的哪個位置開始.
16527
				#$result["indexE"],關鍵字在被搜尋字串的哪個位置結束.
16528
				#必填參數:
16529
				#$conf["inputStr"],字串,被搜尋的字串.
16530
				$conf["search::findKeyWordPosition"]["inputStr"]=$fileInfo["name"];
16531
				#$conf["keyWord"],字串,關鍵字.
16532
				$conf["search::findKeyWordPosition"]["keyWord"]=".";
16533
				#可省略參數:
16534
				#無.
16535
				#參考資料:
16536
				#http://php.net/manual/en/function.strpos.php
16537
				#備註:
16538
				#無.
16539
				$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
16540
				unset($conf["search::findKeyWordPosition"]);
226 liveuser 16541
 
3 liveuser 16542
				#如果執行失敗
16543
				if($findKeyWordPosition["status"]==="false"){
226 liveuser 16544
 
3 liveuser 16545
					#設置執行錯誤
16546
					$result["status"]="false";
226 liveuser 16547
 
3 liveuser 16548
					#設置錯誤訊息
16549
					$result["error"]=$spiltString;
226 liveuser 16550
 
3 liveuser 16551
					#回傳結果
16552
					return $result;
226 liveuser 16553
 
3 liveuser 16554
					}#if end
226 liveuser 16555
 
3 liveuser 16556
				#如果含有 "." 存在
16557
				if($findKeyWordPosition["found"]==="true"){
226 liveuser 16558
 
3 liveuser 16559
					#如果 "." 是在中間,不是在尾巴.
16560
					if($findKeyWordPosition["center"]==="true" && $findKeyWordPosition["tail"]==="false"){
226 liveuser 16561
 
3 liveuser 16562
						#取得 "." 之後的內容
16563
						#函式說明:
16564
						#將字串特定關鍵字與其前面的內容剔除
16565
						#回傳結果:
16566
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16567
						#$result["error"],錯誤訊息陣列.
16568
						#$result["warning"],警告訊息鎮列.
16569
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
16570
						#$result["function"],當前執行的函數名稱.
16571
						#$result["argu"],使用的參數.
16572
						#$result["oriStr"],要處理的原始字串內容.
16573
						#$result["content"],處理好的的字串內容.
16574
						#$result["deleted"],被移除的內容.
16575
						#必填參數:
16576
						#$conf["stringIn"],字串,要處理的字串.
16577
						$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$fileInfo["name"];
16578
						#$conf["keyWord"],字串,特定字串.
16579
						$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=".";
16580
						#可省略參數:
16581
						#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
16582
						$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
16583
						#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
16584
						#$conf["lastResult"]=$delStrBeforeKeyWord;
16585
						#參考資料:
16586
						#無.
16587
						#備註:
16588
						#無.
16589
						$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
16590
						unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 16591
 
3 liveuser 16592
						#如果執行失敗
16593
						if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 16594
 
3 liveuser 16595
							#設置執行錯誤
16596
							$result["status"]="false";
226 liveuser 16597
 
3 liveuser 16598
							#設置錯誤訊息
16599
							$result["error"]=$spiltString;
226 liveuser 16600
 
3 liveuser 16601
							#回傳結果
16602
							return $result;
226 liveuser 16603
 
3 liveuser 16604
							}#if end
226 liveuser 16605
 
3 liveuser 16606
						#如果該存在的 "." 不存在
16607
						if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 16608
 
3 liveuser 16609
							#設置執行錯誤
16610
							$result["status"]="false";
226 liveuser 16611
 
3 liveuser 16612
							#設置錯誤訊息
16613
							$result["error"]=$spiltString;
226 liveuser 16614
 
3 liveuser 16615
							#回傳結果
16616
							return $result;
226 liveuser 16617
 
3 liveuser 16618
							}#if end
226 liveuser 16619
 
3 liveuser 16620
						#取得附檔名
16621
						$fileInfo["secondName"]=$delStrBeforeKeyWord["content"];
226 liveuser 16622
 
3 liveuser 16623
						}#if end
226 liveuser 16624
 
3 liveuser 16625
					}#if end
226 liveuser 16626
 
3 liveuser 16627
				}#if end
226 liveuser 16628
 
3 liveuser 16629
			#儲存檔案資訊
16630
			$result["content"][]=$fileInfo;
226 liveuser 16631
 
3 liveuser 16632
			}#foreach end
226 liveuser 16633
 
3 liveuser 16634
		#設置清單的長度
16635
		$result["dataCount"]=count($result["content"]);
226 liveuser 16636
 
3 liveuser 16637
		#設置執行正常
16638
		$result["status"]="true";
226 liveuser 16639
 
3 liveuser 16640
		#回傳結果
16641
		return $result;
226 liveuser 16642
 
3 liveuser 16643
		}#function ls end
16644
 
16645
	/*
16646
	#函式說明:
16647
	#將 ~ 轉換為家目錄路徑
16648
	#回傳結果:
16649
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16650
	#$result["error"],錯誤訊息.
16651
	#$result["function"],當前執行的函數名稱.
16652
	#$result["content"],轉換好的內容.
16653
	#必填參數:
16654
	#$conf["fileArgu"],字串,變數__FILE__的內容.
16655
	$conf["fileArgu"]=__FILE__;
16656
	#可省略參數:
16657
	#無.
16658
	#參考資料:
16659
	#https://www.businessweekly.com.tw/careers/Blog/14307
16660
	#備註:
16661
	#無.
16662
	*/
16663
	public static function tildeToPath(&$conf){
226 liveuser 16664
 
3 liveuser 16665
		#初始化要回傳的結果
16666
		$result=array();
16667
 
16668
		#取得當前執行的函數名稱
16669
		$result["function"]=__FUNCTION__;
16670
 
16671
		#如果沒有參數
16672
		if(func_num_args()==0){
226 liveuser 16673
 
3 liveuser 16674
			#設置執行失敗
16675
			$result["status"]="false";
226 liveuser 16676
 
3 liveuser 16677
			#設置執行錯誤訊息
16678
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 16679
 
3 liveuser 16680
			#回傳結果
16681
			return $result;
226 liveuser 16682
 
220 liveuser 16683
			}#if end
3 liveuser 16684
 
16685
		#取得參數
16686
		$result["argu"]=$conf;
16687
 
16688
		#如果 $conf 不為陣列
16689
		if(gettype($conf)!=="array"){
226 liveuser 16690
 
3 liveuser 16691
			#設置執行失敗
16692
			$result["status"]="false";
226 liveuser 16693
 
3 liveuser 16694
			#設置執行錯誤訊息
16695
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 16696
 
3 liveuser 16697
			#如果傳入的參數為 null
16698
			if($conf===null){
226 liveuser 16699
 
3 liveuser 16700
				#設置執行錯誤訊息
16701
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 16702
 
3 liveuser 16703
				}#if end
16704
 
16705
			#回傳結果
16706
			return $result;
226 liveuser 16707
 
3 liveuser 16708
			}#if end
226 liveuser 16709
 
3 liveuser 16710
		#函式說明:
16711
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
16712
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16713
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
16714
		#$result["function"],當前執行的函式名稱.
16715
		#$result["argu"],設置給予的參數.
16716
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
16717
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
16718
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
16719
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
16720
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
16721
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
16722
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
16723
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
16724
		#必填寫的參數:
16725
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 16726
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 16727
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
16728
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
16729
		#可以省略的參數:
16730
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
16731
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
16732
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
16733
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
16734
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
16735
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
16736
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
16737
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
16738
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
16739
		#$conf["canBeEmpty"]=array();
16740
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
16741
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
16742
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
16743
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 16744
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 16745
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
16746
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
16747
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
16748
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
16749
		#$conf["disallowAllSkipableVarIsEmpty"]="";
16750
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
16751
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
16752
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
16753
		#$conf["arrayCountEqualCheck"][]=array();
16754
		#參考資料來源:
16755
		#array_keys=>http://php.net/manual/en/function.array-keys.php
16756
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
16757
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 16758
 
3 liveuser 16759
		#如果檢查參數失敗
16760
		if($checkArguments["status"]==="false"){
226 liveuser 16761
 
3 liveuser 16762
			#設置執行失敗
16763
			$result["status"]="false";
226 liveuser 16764
 
3 liveuser 16765
			#設置執行失敗訊息
16766
			$result["error"]=$checkArguments;
226 liveuser 16767
 
3 liveuser 16768
			#回傳結果
16769
			return $result;
226 liveuser 16770
 
3 liveuser 16771
			}#if end
226 liveuser 16772
 
3 liveuser 16773
		#如果檢查參數不通過
16774
		if($checkArguments["passed"]==="false"){
226 liveuser 16775
 
3 liveuser 16776
			#設置執行失敗
16777
			$result["status"]="false";
226 liveuser 16778
 
3 liveuser 16779
			#設置執行失敗訊息
16780
			$result["error"]=$checkArguments;
226 liveuser 16781
 
3 liveuser 16782
			#回傳結果
16783
			return $result;
226 liveuser 16784
 
3 liveuser 16785
			}#if end
16786
 
16787
		#函式說明:
16788
		#呼叫shell執行系統命令,並取得回傳的內容.
16789
		#回傳結果:
16790
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16791
		#$result["error"],錯誤訊息陣列.
16792
		#$result["function"],當前執行的函數名稱.
16793
		#$result["argu"],使用的參數.
16794
		#$result["cmd"],執行的指令內容.
16795
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16796
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16797
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16798
		#$result["running"],是否還在執行.
16799
		#$result["pid"],pid.
16800
		#$result["statusCode"],執行結束後的代碼.
16801
		#必填參數:
16802
		#$conf["command"],字串,要執行的指令與.
16803
		$conf["external::callShell"]["command"]="echo";
16804
		#$conf["fileArgu"],字串,變數__FILE__的內容.
16805
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16806
		#可省略參數:
16807
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16808
		$conf["external::callShell"]["argu"]=array("~");
16809
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16810
		#$conf["arguIsAddr"]=array();
16811
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16812
		#$conf["plainArgu"]=array();
16813
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16814
		#$conf["useApostrophe"]=array();
16815
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16816
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16817
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16818
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16819
		#$conf["enablePrintDescription"]="true";
16820
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16821
		#$conf["printDescription"]="";
16822
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16823
		$conf["external::callShell"]["escapeshellarg"]="true";
16824
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16825
		#$conf["thereIsShellVar"]=array();
16826
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16827
		#$conf["username"]="";
16828
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16829
		#$conf["password"]="";
16830
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16831
		#$conf["useScript"]="";
16832
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16833
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16834
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16835
		#$conf["inBackGround"]="";
16836
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16837
		#$conf["getErr"]="false";
16838
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16839
		#$conf["doNotRun"]="false";
16840
		#參考資料:
16841
		#exec=>http://php.net/manual/en/function.exec.php
16842
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16843
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16844
		#備註:
16845
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16846
		$callShell=external::callShell($conf["external::callShell"]);
16847
		unset($conf["external::callShell"]);
16848
 
16849
		#如果執行失敗
16850
		if($callShell["status"]==="false"){
226 liveuser 16851
 
3 liveuser 16852
			#設置執行失敗
16853
			$result["status"]="false";
226 liveuser 16854
 
3 liveuser 16855
			#設置執行失敗訊息
16856
			$result["error"]=$callShell;
226 liveuser 16857
 
3 liveuser 16858
			#回傳結果
16859
			return $result;
226 liveuser 16860
 
3 liveuser 16861
			}#if end
226 liveuser 16862
 
3 liveuser 16863
		#如果沒有預期的輸出
16864
		if(!isset($callShell["output"][0])){
226 liveuser 16865
 
3 liveuser 16866
			#設置執行失敗
16867
			$result["status"]="false";
226 liveuser 16868
 
3 liveuser 16869
			#設置執行失敗訊息
16870
			$result["error"][]="沒有得到預期的輸出";
226 liveuser 16871
 
3 liveuser 16872
			#設置執行失敗訊息
16873
			$result["error"][]=$callShell;
226 liveuser 16874
 
3 liveuser 16875
			#回傳結果
16876
			return $result;
226 liveuser 16877
 
3 liveuser 16878
			}#if end
226 liveuser 16879
 
3 liveuser 16880
		#取得輸出
16881
		$result["content"]=$callShell["output"][0];
226 liveuser 16882
 
3 liveuser 16883
		#設置執行正常
16884
		$result["status"]="true";
226 liveuser 16885
 
3 liveuser 16886
		#回傳結果
16887
		return $result;
226 liveuser 16888
 
3 liveuser 16889
		}#function tildeToPath end
16890
 
16891
	/*
16892
	#函式說明:
16893
	#建立軟連結.
16894
	#回傳結果:
16895
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16896
	#$result["error"],錯誤訊息.
16897
	#$result["function"],當前執行的函數名稱.
16898
	#$result["content"],軟連結的資訊.
16899
	#$result["cmd"],執行的指令陣列.
16900
	#必填參數:
16901
	#$conf["fileArgu"],字串,變數__FILE__的內容.
16902
	$conf["fileArgu"]=__FILE__;
16903
	#$conf["linkTo"],字串,軟連結要指向哪邊.
16904
	$conf["linkTo"]="";
16905
	#可省略參數:
16906
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
16907
	#$conf["path"]="";
16908
	#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
16909
	#$conf["name"]="";
16910
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
16911
	#$conf["overWrite"]="true";
16912
	#參考資料:
16913
	#無.
16914
	#備註:
16915
	#無.
16916
	*/
16917
	public static function createLink(&$conf){
226 liveuser 16918
 
3 liveuser 16919
		#初始化要回傳的結果
16920
		$result=array();
16921
 
16922
		#取得當前執行的函數名稱
16923
		$result["function"]=__FUNCTION__;
16924
 
16925
		#如果沒有參數
16926
		if(func_num_args()==0){
226 liveuser 16927
 
3 liveuser 16928
			#設置執行失敗
16929
			$result["status"]="false";
226 liveuser 16930
 
3 liveuser 16931
			#設置執行錯誤訊息
16932
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 16933
 
3 liveuser 16934
			#回傳結果
16935
			return $result;
226 liveuser 16936
 
220 liveuser 16937
			}#if end
3 liveuser 16938
 
16939
		#取得參數
16940
		$result["argu"]=$conf;
16941
 
16942
		#如果 $conf 不為陣列
16943
		if(gettype($conf)!=="array"){
226 liveuser 16944
 
3 liveuser 16945
			#設置執行失敗
16946
			$result["status"]="false";
226 liveuser 16947
 
3 liveuser 16948
			#設置執行錯誤訊息
16949
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 16950
 
3 liveuser 16951
			#如果傳入的參數為 null
16952
			if($conf===null){
226 liveuser 16953
 
3 liveuser 16954
				#設置執行錯誤訊息
16955
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 16956
 
3 liveuser 16957
				}#if end
16958
 
16959
			#回傳結果
16960
			return $result;
226 liveuser 16961
 
3 liveuser 16962
			}#if end
226 liveuser 16963
 
3 liveuser 16964
		#函式說明:
16965
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
16966
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16967
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
16968
		#$result["function"],當前執行的函式名稱.
16969
		#$result["argu"],設置給予的參數.
16970
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
16971
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
16972
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
16973
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
16974
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
16975
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
16976
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
16977
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
16978
		#必填寫的參數:
16979
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 16980
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 16981
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
16982
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
16983
		#可以省略的參數:
16984
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
16985
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkTo");
16986
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
16987
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
16988
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
16989
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
16990
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
16991
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
16992
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
16993
		#$conf["canBeEmpty"]=array();
16994
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
16995
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","name","overWrite");
16996
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
16997
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","name","overWrite");
226 liveuser 16998
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 16999
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
17000
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
17001
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false");
17002
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
17003
		#$conf["disallowAllSkipableVarIsEmpty"]="";
17004
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
17005
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
17006
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
17007
		#$conf["arrayCountEqualCheck"][]=array();
17008
		#參考資料來源:
17009
		#array_keys=>http://php.net/manual/en/function.array-keys.php
17010
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
17011
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 17012
 
3 liveuser 17013
		#如果檢查參數失敗
17014
		if($checkArguments["status"]==="false"){
226 liveuser 17015
 
3 liveuser 17016
			#設置執行失敗
17017
			$result["status"]="false";
226 liveuser 17018
 
3 liveuser 17019
			#設置執行失敗訊息
17020
			$result["error"]=$checkArguments;
226 liveuser 17021
 
3 liveuser 17022
			#回傳結果
17023
			return $result;
226 liveuser 17024
 
3 liveuser 17025
			}#if end
226 liveuser 17026
 
3 liveuser 17027
		#如果檢查參數不通過
17028
		if($checkArguments["passed"]==="false"){
226 liveuser 17029
 
3 liveuser 17030
			#設置執行失敗
17031
			$result["status"]="false";
226 liveuser 17032
 
3 liveuser 17033
			#設置執行失敗訊息
17034
			$result["error"]=$checkArguments;
226 liveuser 17035
 
3 liveuser 17036
			#回傳結果
17037
			return $result;
226 liveuser 17038
 
3 liveuser 17039
			}#if end
17040
 
17041
		#如果是相對位置
17042
		if(!(strpos($conf["linkTo"],"/")===0)){
226 liveuser 17043
 
3 liveuser 17044
			#將 $conf["linkTo"] 轉換為針對產生位置的相對位置.
17045
			#函式說明:
17046
			#將多個路徑字串變成相對於當前路徑的相對路徑字串
17047
			#回傳結果:
17048
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
17049
			#$result["error"],錯誤訊息陣列.
226 liveuser 17050
			#$result["function"],函數名稱.
3 liveuser 17051
			#$result["argu"],使用的參數.
17052
			#$result["content"],字串陣列,多個轉換好的相對路徑字串.
17053
			#必填參數:
17054
			#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
17055
			$conf["fileAccess::getRelativePath"]["path"]=array($conf["linkTo"]);
17056
			#$conf["fileArgu"],字串,當前路徑.
17057
			$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
17058
			#可省略參數:
17059
			#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
17060
			$conf["fileAccess::getRelativePath"]["baseFrom"]=$conf["path"];
17061
			#參考資料:
17062
			#無.
17063
			#備註:
17064
			#無.
17065
			$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
17066
			unset($conf["fileAccess::getRelativePath"]);
17067
 
17068
			#如果執行失敗
17069
			if($getRelativePath["status"]==="false"){
226 liveuser 17070
 
3 liveuser 17071
				#設置執行失敗
17072
				$result["status"]="false";
226 liveuser 17073
 
3 liveuser 17074
				#設置執行失敗訊息
17075
				$result["error"]=$getRelativePath;
226 liveuser 17076
 
3 liveuser 17077
				#回傳結果
17078
				return $result;
226 liveuser 17079
 
3 liveuser 17080
				}#if end
17081
 
17082
			/*
17083
			#break point
17084
			var_dump($conf);
17085
			var_dump($getRelativePath);
17086
			exit;
17087
			*/
17088
 
17089
			#取得執行的指令
17090
			$result["cmd"][]=$getRelativePath["cmd"];
17091
 
17092
			#取得正確的相對位置
17093
			$conf["linkTo"]=$getRelativePath["content"][0];
226 liveuser 17094
 
3 liveuser 17095
			}#if end
17096
 
17097
		#初始化給 ln 指令的參數
17098
		$paramsForLn=array("-s",$conf["linkTo"]);
17099
 
17100
		#函式說明:
17101
		#將字串特定關鍵字與其前面的內容剔除
17102
		#回傳結果:
17103
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17104
		#$result["error"],錯誤訊息陣列.
17105
		#$result["warning"],警告訊息鎮列.
17106
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
17107
		#$result["function"],當前執行的函數名稱.
17108
		#$result["oriStr"],要處理的原始字串內容.
226 liveuser 17109
		#$result["content"],處理好的的字串內容.
3 liveuser 17110
		#必填參數:
17111
		#$conf["stringIn"],字串,要處理的字串.
17112
		$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["linkTo"];
17113
		#$conf["keyWord"],字串,特定字串.
17114
		$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="/";
17115
		#可省略參數:
17116
		#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
17117
		$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
17118
		#參考資料:
17119
		#無.
17120
		#備註:
17121
		#無.
17122
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
17123
		unset($conf["stringProcess::delStrBeforeKeyWord"]);
17124
 
17125
		#var_dump(__LINE__." ".print_r($delStrBeforeKeyWord,true));
17126
 
17127
		#如果執行失敗
17128
		if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 17129
 
3 liveuser 17130
			#設置執行失敗
17131
			$result["status"]="false";
226 liveuser 17132
 
3 liveuser 17133
			#設置執行失敗訊息
17134
			$result["error"]=$delStrBeforeKeyWord;
226 liveuser 17135
 
3 liveuser 17136
			#回傳結果
17137
			return $result;
226 liveuser 17138
 
3 liveuser 17139
			}#if end
226 liveuser 17140
 
3 liveuser 17141
		#如果沒有找到 "/"
17142
		if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 17143
 
3 liveuser 17144
			#設置 預設的 軟連名稱
17145
			$softLink=$conf["linkTo"];
226 liveuser 17146
 
3 liveuser 17147
			}#if end
17148
 
17149
		#反之有 "/"
17150
		else{
226 liveuser 17151
 
3 liveuser 17152
			#設置 預設的 軟連結名稱
17153
			$softLink=$delStrBeforeKeyWord["content"];
226 liveuser 17154
 
3 liveuser 17155
			}#else end
17156
 
17157
		/*
17158
		#break point
17159
		var_dump(__LINE__." ".$softLink);
17160
		exit;
17161
		*/
17162
 
17163
		#預設欲建立的軟連結名稱
17164
		$createdSoftLink=$softLink;
17165
 
17166
		#如果有設置 path
17167
		if(isset($conf["path"])){
226 liveuser 17168
 
3 liveuser 17169
			#確認 path 存在
17170
			#函式說明:
17171
			#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
17172
			#回傳結果:
17173
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
17174
			#$result["error"],錯誤訊息陣列
17175
			#$result["warning"],警告訊息陣列
17176
			#必填參數:
17177
			#$conf["dirPositionAndName"]="";#新建的位置與名稱
17178
			$conf["fileAccess::createNewFolder"]["dirPositionAndName"]=$conf["path"];
17179
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17180
			$conf["fileAccess::createNewFolder"]["fileArgu"]=$conf["fileArgu"];
17181
			#可省略參數:
17182
			#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
17183
			#$conf["dirPermission"]="";
17184
			#參考資料:
17185
			#mkdir=>http://php.net/manual/en/function.mkdir.php
17186
			#chmod=>http://php.net/manual/en/function.chmod.php
17187
			#參考資料:
17188
			#無.
17189
			#備註:
17190
			#同 function createFolderAfterCheck.
17191
			$createNewFolder=fileAccess::createNewFolder($conf["fileAccess::createNewFolder"]);
17192
			unset($conf["fileAccess::createNewFolder"]);
226 liveuser 17193
 
3 liveuser 17194
			#如果執行失敗
17195
			if($createNewFolder["status"]==="false"){
226 liveuser 17196
 
3 liveuser 17197
				#設置執行失敗
17198
				$result["status"]="false";
226 liveuser 17199
 
3 liveuser 17200
				#設置執行失敗訊息
17201
				$result["error"]=$createNewFolder;
226 liveuser 17202
 
3 liveuser 17203
				#回傳結果
17204
				return $result;
226 liveuser 17205
 
3 liveuser 17206
				}#if end
226 liveuser 17207
 
3 liveuser 17208
			#var_dump(__LINE__." ".print_r($conf,true));
226 liveuser 17209
 
3 liveuser 17210
			#預設要加 slash
17211
			$slash="/";
226 liveuser 17212
 
3 liveuser 17213
			#如果 path 為 "/" 結尾
17214
			if($conf["path"][strlen($conf["path"])-1]==="/"){
226 liveuser 17215
 
3 liveuser 17216
				#不用 slash
17217
				$slash="";
226 liveuser 17218
 
3 liveuser 17219
				}#if end
226 liveuser 17220
 
3 liveuser 17221
			#如果有設置 name
17222
			if(isset($conf["name"])){
226 liveuser 17223
 
3 liveuser 17224
				#指定軟連結要放在哪邊
17225
				$paramsForLn[]=$conf["path"].$slash.$conf["name"];
226 liveuser 17226
 
3 liveuser 17227
				#更新欲建立的軟連結名稱
17228
				$createdSoftLink=$conf["path"].$slash.$conf["name"];
226 liveuser 17229
 
3 liveuser 17230
				/*
17231
				#break point
17232
				var_dump($conf["path"],$softLink,$createdSoftLink);
17233
				exit;
17234
				*/
226 liveuser 17235
 
3 liveuser 17236
				}#if end
226 liveuser 17237
 
3 liveuser 17238
			#反之
17239
			else{
226 liveuser 17240
 
3 liveuser 17241
				#指定軟連結要放在哪邊
17242
				$paramsForLn[]=$conf["path"];
226 liveuser 17243
 
3 liveuser 17244
				#更新欲建立的軟連結名稱
17245
				$createdSoftLink=$conf["path"].$slash.$softLink;
226 liveuser 17246
 
3 liveuser 17247
				/*
17248
				#break point
17249
				var_dump($conf["path"],$softLink,$createdSoftLink);
17250
				exit;
17251
				*/
226 liveuser 17252
 
3 liveuser 17253
				}#else end
226 liveuser 17254
 
3 liveuser 17255
			#var_dump($createdSoftLink);
226 liveuser 17256
 
3 liveuser 17257
			}#if end
226 liveuser 17258
 
3 liveuser 17259
		#反之如果有設置 name
17260
		else if(isset($conf["name"])){
226 liveuser 17261
 
3 liveuser 17262
			#指定軟連結的名稱
17263
			$paramsForLn[]=$conf["name"];
226 liveuser 17264
 
3 liveuser 17265
			#更新欲建立的軟連結名稱
17266
			$createdSoftLink=$conf["name"];
226 liveuser 17267
 
3 liveuser 17268
			#var_dump(__LINE__." ".$createdSoftLink);
226 liveuser 17269
 
3 liveuser 17270
			}#if end
226 liveuser 17271
 
3 liveuser 17272
		/*
17273
		# break point
17274
		var_dump($createdSoftLink);
17275
		exit;
17276
		*/
226 liveuser 17277
 
3 liveuser 17278
		#如果要覆蓋既有的目標
17279
		if($conf["overWrite"]==="true"){
226 liveuser 17280
 
3 liveuser 17281
			#函式說明:
17282
			#移除檔案
17283
			#回傳結果:
17284
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
17285
			#$result["error"],錯誤訊息陣列
17286
			#$result["warning"],警告訊息陣列
17287
			#$result["function"],當前執行的函數名稱
17288
			#必填參數:
17289
			#$conf["fileAddress"],字串,要移除檔案的位置.
17290
			$conf["fileAccess::delFile"]["fileAddress"]=$createdSoftLink;
17291
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
17292
			$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
17293
			#可省略參數:
17294
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
17295
			#$conf["commentsArray"]=array("");
17296
			#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
17297
			$conf["fileAccess::delFile"]["allowDelSymlink"]="true";
17298
			#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
17299
			$conf["fileAccess::delFile"]["allowDelFolder"]="true";
17300
			#參考資料:
17301
			#無.
17302
			#備註:
17303
			#無.
17304
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
226 liveuser 17305
			unset($conf["fileAccess::delFile"]);
17306
 
3 liveuser 17307
			/*
17308
			#break point
17309
			var_dump($delFile);
17310
			exit;
17311
			*/
226 liveuser 17312
 
3 liveuser 17313
			#如果執行失敗
17314
			if($delFile["status"]==="false"){
226 liveuser 17315
 
3 liveuser 17316
				#設置執行失敗
17317
				$result["status"]="false";
226 liveuser 17318
 
3 liveuser 17319
				#設置執行失敗訊息
17320
				$result["error"]=$delFile;
226 liveuser 17321
 
3 liveuser 17322
				#回傳結果
17323
				return $result;
226 liveuser 17324
 
3 liveuser 17325
				}#if end
226 liveuser 17326
 
3 liveuser 17327
			}#if end
17328
 
17329
		#函式說明:
17330
		#呼叫shell執行系統命令,並取得回傳的內容.
17331
		#回傳結果:
17332
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17333
		#$result["error"],錯誤訊息陣列.
17334
		#$result["function"],當前執行的函數名稱.
17335
		#$result["argu"],使用的參數.
17336
		#$result["cmd"],執行的指令內容.
17337
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17338
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17339
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17340
		#$result["running"],是否還在執行.
17341
		#$result["pid"],pid.
17342
		#$result["statusCode"],執行結束後的代碼.
17343
		#必填參數:
17344
		#$conf["command"],字串,要執行的指令與.
17345
		$conf["external::callShell"]["command"]="ln";
17346
		#$conf["fileArgu"],字串,變數__FILE__的內容.
17347
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17348
		#可省略參數:
17349
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17350
		$conf["external::callShell"]["argu"]=$paramsForLn;
17351
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17352
		#$conf["arguIsAddr"]=array();
17353
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
17354
		#$conf["plainArgu"]=array();
17355
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
17356
		#$conf["useApostrophe"]=array();
17357
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17358
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17359
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17360
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17361
		#$conf["enablePrintDescription"]="true";
17362
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17363
		#$conf["printDescription"]="";
17364
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
17365
		$conf["external::callShell"]["escapeshellarg"]="true";
17366
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
17367
		#$conf["thereIsShellVar"]=array();
17368
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17369
		#$conf["username"]="";
17370
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17371
		#$conf["password"]="";
17372
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17373
		#$conf["useScript"]="";
17374
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17375
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17376
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17377
		#$conf["inBackGround"]="";
17378
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17379
		$conf["external::callShell"]["getErr"]="true";
17380
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17381
		#$conf["doNotRun"]="false";
17382
		#參考資料:
17383
		#exec=>http://php.net/manual/en/function.exec.php
17384
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17385
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17386
		#備註:
17387
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17388
		$callShell=external::callShell($conf["external::callShell"]);
17389
		unset($conf["external::callShell"]);
17390
 
17391
		#如果執行失敗
17392
		if($callShell["status"]==="false"){
226 liveuser 17393
 
3 liveuser 17394
			#設置執行失敗
17395
			$result["status"]="false";
226 liveuser 17396
 
3 liveuser 17397
			#設置執行失敗訊息
17398
			$result["error"]=$callShell;
226 liveuser 17399
 
3 liveuser 17400
			#回傳結果
17401
			return $result;
226 liveuser 17402
 
3 liveuser 17403
			}#if end
226 liveuser 17404
 
3 liveuser 17405
		#保存執行的指令
17406
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 17407
 
3 liveuser 17408
		#初始化給 ls 指令的參數
17409
		$paramsForLs=array("-l",$paramsForLn[count($paramsForLn)-1]);
226 liveuser 17410
 
3 liveuser 17411
		#取得軟連結的資訊
17412
		#函式說明:
17413
		#呼叫shell執行系統命令,並取得回傳的內容.
17414
		#回傳結果:
17415
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17416
		#$result["error"],錯誤訊息陣列.
17417
		#$result["function"],當前執行的函數名稱.
17418
		#$result["argu"],使用的參數.
17419
		#$result["cmd"],執行的指令內容.
17420
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17421
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17422
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17423
		#$result["running"],是否還在執行.
17424
		#$result["pid"],pid.
17425
		#$result["statusCode"],執行結束後的代碼.
17426
		#必填參數:
17427
		#$conf["command"],字串,要執行的指令與.
17428
		$conf["external::callShell"]["command"]="ls";
17429
		#$conf["fileArgu"],字串,變數__FILE__的內容.
17430
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17431
		#可省略參數:
17432
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17433
		$conf["external::callShell"]["argu"]=$paramsForLs;
17434
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17435
		#$conf["arguIsAddr"]=array();
17436
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
17437
		#$conf["plainArgu"]=array();
17438
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
17439
		#$conf["useApostrophe"]=array();
17440
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17441
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17442
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17443
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17444
		#$conf["enablePrintDescription"]="true";
17445
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17446
		#$conf["printDescription"]="";
17447
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
17448
		$conf["external::callShell"]["escapeshellarg"]="true";
17449
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
17450
		#$conf["thereIsShellVar"]=array();
17451
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17452
		#$conf["username"]="";
17453
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17454
		#$conf["password"]="";
17455
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17456
		#$conf["useScript"]="";
17457
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17458
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17459
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17460
		#$conf["inBackGround"]="";
17461
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17462
		$conf["external::callShell"]["getErr"]="true";
17463
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17464
		#$conf["doNotRun"]="false";
17465
		#參考資料:
17466
		#exec=>http://php.net/manual/en/function.exec.php
17467
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17468
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17469
		#備註:
17470
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17471
		$callShell=external::callShell($conf["external::callShell"]);
17472
		unset($conf["external::callShell"]);
17473
 
17474
		#如果執行失敗
17475
		if($callShell["status"]==="false"){
226 liveuser 17476
 
3 liveuser 17477
			#設置執行失敗
17478
			$result["status"]="false";
226 liveuser 17479
 
3 liveuser 17480
			#設置執行失敗訊息
17481
			$result["error"]=$callShell;
226 liveuser 17482
 
3 liveuser 17483
			#回傳結果
17484
			return $result;
226 liveuser 17485
 
3 liveuser 17486
			}#if end
226 liveuser 17487
 
3 liveuser 17488
		#保存執行的指令
17489
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 17490
 
3 liveuser 17491
		#取得軟連結的資訊
17492
		$result["content"]=$callShell["output"];
226 liveuser 17493
 
3 liveuser 17494
		#設置執行正常
17495
		$result["status"]="true";
226 liveuser 17496
 
3 liveuser 17497
		#回傳結果
17498
		return $result;
226 liveuser 17499
 
3 liveuser 17500
		}#function createLink end
17501
 
17502
	/*
17503
	#函式說明:
17504
	#針對特定目錄下的內容建立軟連結.
17505
	#回傳結果:
17506
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17507
	#$result["error"],錯誤訊息.
17508
	#$result["function"],當前執行的函數名稱.
17509
	#$result["content"],字串陣列,每個建立的軟連結資訊.
17510
	#必填參數:
17511
	#$conf["fileArgu"],字串,變數__FILE__的內容.
17512
	$conf["fileArgu"]=__FILE__;
17513
	#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
17514
	$conf["linkToDir"]="";
17515
	#可省略參數:
17516
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
17517
	#$conf["path"]="";
17518
	#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
17519
	#$conf["name"]=array(array("oriName","newName"));
17520
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
17521
	#$conf["overWrite"]="true";
17522
	#參考資料:
17523
	#無.
17524
	#備註:
17525
	#無.
17526
	*/
17527
	public static function createMultiLinkInDir(&$conf){
226 liveuser 17528
 
3 liveuser 17529
		#初始化要回傳的結果
17530
		$result=array();
17531
 
17532
		#取得當前執行的函數名稱
17533
		$result["function"]=__FUNCTION__;
17534
 
17535
		#如果沒有參數
17536
		if(func_num_args()==0){
226 liveuser 17537
 
3 liveuser 17538
			#設置執行失敗
17539
			$result["status"]="false";
226 liveuser 17540
 
3 liveuser 17541
			#設置執行錯誤訊息
17542
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 17543
 
3 liveuser 17544
			#回傳結果
17545
			return $result;
226 liveuser 17546
 
220 liveuser 17547
			}#if end
3 liveuser 17548
 
17549
		#取得參數
17550
		$result["argu"]=$conf;
17551
 
17552
		#如果 $conf 不為陣列
17553
		if(gettype($conf)!=="array"){
226 liveuser 17554
 
3 liveuser 17555
			#設置執行失敗
17556
			$result["status"]="false";
226 liveuser 17557
 
3 liveuser 17558
			#設置執行錯誤訊息
17559
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 17560
 
3 liveuser 17561
			#如果傳入的參數為 null
17562
			if($conf===null){
226 liveuser 17563
 
3 liveuser 17564
				#設置執行錯誤訊息
17565
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 17566
 
3 liveuser 17567
				}#if end
17568
 
17569
			#回傳結果
17570
			return $result;
226 liveuser 17571
 
3 liveuser 17572
			}#if end
226 liveuser 17573
 
3 liveuser 17574
		#檢查參數
17575
		#函式說明:
17576
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
17577
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17578
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
17579
		#$result["function"],當前執行的函式名稱.
17580
		#$result["argu"],設置給予的參數.
17581
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
17582
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
17583
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
17584
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
17585
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
17586
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
17587
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
17588
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
17589
		#必填寫的參數:
17590
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 17591
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 17592
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
17593
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
17594
		#可以省略的參數:
17595
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
17596
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkToDir");
17597
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
17598
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
17599
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
17600
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
17601
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
17602
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
17603
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
17604
		#$conf["canBeEmpty"]=array();
17605
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
17606
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","name","overWrite");
17607
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
17608
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","name","overWrite");
226 liveuser 17609
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 17610
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string");
17611
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
17612
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".",null,"false");
17613
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
17614
		#$conf["disallowAllSkipableVarIsEmpty"]="";
17615
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
17616
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
17617
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
17618
		#$conf["arrayCountEqualCheck"][]=array();
17619
		#參考資料來源:
17620
		#array_keys=>http://php.net/manual/en/function.array-keys.php
17621
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
17622
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 17623
 
3 liveuser 17624
		#如果檢查參數失敗
17625
		if($checkArguments["status"]==="false"){
226 liveuser 17626
 
3 liveuser 17627
			#設置執行失敗
17628
			$result["status"]="false";
226 liveuser 17629
 
3 liveuser 17630
			#設置執行失敗訊息
17631
			$result["error"]=$checkArguments;
226 liveuser 17632
 
3 liveuser 17633
			#回傳結果
17634
			return $result;
226 liveuser 17635
 
3 liveuser 17636
			}#if end
226 liveuser 17637
 
3 liveuser 17638
		#如果檢查參數不通過
17639
		if($checkArguments["passed"]==="false"){
226 liveuser 17640
 
3 liveuser 17641
			#設置執行失敗
17642
			$result["status"]="false";
226 liveuser 17643
 
3 liveuser 17644
			#設置執行失敗訊息
17645
			$result["error"]=$checkArguments;
226 liveuser 17646
 
3 liveuser 17647
			#回傳結果
17648
			return $result;
226 liveuser 17649
 
3 liveuser 17650
			}#if end
226 liveuser 17651
 
3 liveuser 17652
		#函式說明:
17653
		#取得目錄底下所有目錄與檔案清單.
17654
		#回傳結果:
17655
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
17656
		#$result["error"],錯誤訊息陣列.
17657
		#$result["function"],函數名稱.
17658
		#$result["content"],陣列,目錄底下的檔案與子目錄.
17659
		#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
17660
		#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
17661
		#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
17662
		#$result["position"],目前的位置.
17663
		#必填參數:
17664
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
17665
		$conf["fileAccess::getList"]["position"]=$conf["linkToDir"];
17666
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17667
		$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
17668
		#可省略參數:
17669
		#無
17670
		#參考資料:
17671
		#opendir=>http://php.net/manual/en/function.opendir.php
17672
		#is_dir=>http://php.net/manual/en/function.is-dir.php
17673
		#備註:
17674
		#無.
17675
		$getList=fileAccess::getList($conf["fileAccess::getList"]);
17676
		unset($conf["fileAccess::getList"]);
226 liveuser 17677
 
3 liveuser 17678
		#如果檢查參數失敗
17679
		if($getList["status"]==="false"){
226 liveuser 17680
 
3 liveuser 17681
			#設置執行失敗
17682
			$result["status"]="false";
226 liveuser 17683
 
3 liveuser 17684
			#設置執行失敗訊息
17685
			$result["error"]=$getList;
226 liveuser 17686
 
3 liveuser 17687
			#回傳結果
17688
			return $result;
226 liveuser 17689
 
3 liveuser 17690
			}#if end
226 liveuser 17691
 
3 liveuser 17692
		#針對目標目錄底下的所有檔案
17693
		foreach($getList["content"] as $oriName){
226 liveuser 17694
 
3 liveuser 17695
			#如果有設定 $conf["name"]
17696
			if(isset($conf["name"])){
226 liveuser 17697
 
3 liveuser 17698
				#預設不指定新的軟連結名稱
17699
				unset($newSoftLinkName);
226 liveuser 17700
 
3 liveuser 17701
				#針對每個原始目標的名稱
17702
				foreach($conf["name"] as $customName){
226 liveuser 17703
 
3 liveuser 17704
					#如果是指定的目標
17705
					if($oriName["name"]===$customName[0]){
226 liveuser 17706
 
3 liveuser 17707
						#設置新的軟連結名稱
17708
						$newSoftLinkName=$customName[1];
226 liveuser 17709
 
3 liveuser 17710
						}#if end
226 liveuser 17711
 
3 liveuser 17712
					}#foreach end
226 liveuser 17713
 
3 liveuser 17714
				}#if end
226 liveuser 17715
 
3 liveuser 17716
			#建立軟連結
17717
			#函式說明:
17718
			#建立軟連結.
17719
			#回傳結果:
17720
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17721
			#$result["error"],錯誤訊息.
17722
			#$result["function"],當前執行的函數名稱.
17723
			#$result["content"],軟連結的資訊.
17724
			#必填參數:
17725
			#$conf["fileArgu"],字串,變數__FILE__的內容.
17726
			$conf["fileAccess::createLink"]["fileArgu"]=$conf["fileArgu"];
17727
			#$conf["linkTo"],字串,軟連結要指向哪邊.
17728
			$conf["fileAccess::createLink"]["linkTo"]=$conf["linkToDir"]."/".$oriName["name"];
17729
			#可省略參數:
17730
			#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
17731
			$conf["fileAccess::createLink"]["path"]=$conf["path"];
226 liveuser 17732
 
3 liveuser 17733
			#如果有新的軟連結名稱
17734
			if(isset($newSoftLinkName)){
226 liveuser 17735
 
3 liveuser 17736
				#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
17737
				$conf["fileAccess::createLink"]["name"]=$newSoftLinkName;
226 liveuser 17738
 
3 liveuser 17739
				}#if end
226 liveuser 17740
 
3 liveuser 17741
			#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
17742
			$conf["fileAccess::createLink"]["overWrite"]=$conf["overWrite"];
226 liveuser 17743
 
3 liveuser 17744
			#參考資料:
17745
			#無.
17746
			#備註:
17747
			#無.
17748
			$createLink=fileAccess::createLink($conf["fileAccess::createLink"]);
17749
			unset($conf["fileAccess::createLink"]);
226 liveuser 17750
 
3 liveuser 17751
			#var_dump(__LINE__." ".print_r($createLink,true));
226 liveuser 17752
 
3 liveuser 17753
			#如果檢查參數失敗
17754
			if($createLink["status"]==="false"){
226 liveuser 17755
 
3 liveuser 17756
				#設置執行失敗
17757
				$result["status"]="false";
226 liveuser 17758
 
3 liveuser 17759
				#設置執行失敗訊息
17760
				$result["error"]=$createLink;
226 liveuser 17761
 
3 liveuser 17762
				#回傳結果
17763
				return $result;
226 liveuser 17764
 
3 liveuser 17765
				}#if end
226 liveuser 17766
 
3 liveuser 17767
			#儲存建立好的軟連結資訊
17768
			$result["content"][]=$createLink["content"];
226 liveuser 17769
 
3 liveuser 17770
			}#foreach end
226 liveuser 17771
 
3 liveuser 17772
		#設置執行正常
17773
		$result["status"]="true";
226 liveuser 17774
 
3 liveuser 17775
		#回傳結果
17776
		return $result;
226 liveuser 17777
 
3 liveuser 17778
		}#function createMultiLink end
17779
 
17780
	/*
17781
	#函式說明:
17782
	#更新檔案的內容.
17783
	#回傳結果:
17784
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17785
	#$result["error"],錯誤訊息.
17786
	#$result["function"],當前執行的函數名稱.
220 liveuser 17787
	#$result["content"],更新的資訊.
17788
	#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
17789
	#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
3 liveuser 17790
	#必填參數:
17791
	#$conf["fileArgu"],字串,變數__FILE__的內容.
17792
	$conf["fileArgu"]=__FILE__;
17793
	#$conf["file"],字串,要更新的檔案位置與名稱.
17794
	$conf["file"]="";
17795
	#可省略參數:
17796
	#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
17797
	#$conf["overWriteWith"]=array();
17798
	#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
17799
	#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
17800
	#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
17801
	#$conf["replaceLike"]="false";
17802
	#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
17803
	#$conf["addToTailWhenNoMatch"]="false";
17804
	#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
17805
	#$conf["addToTailBeforeThat"]="?\>";
220 liveuser 17806
	#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
17807
	#$conf["replaceSpecifyLine"]=array();
17808
	#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
17809
	#$conf["outputPath"]="";
3 liveuser 17810
	#參考資料:
17811
	#無.
17812
	#備註:
17813
	#無.
17814
	*/
17815
	public static function updateFile(&$conf){
226 liveuser 17816
 
3 liveuser 17817
		#初始化要回傳的結果
17818
		$result=array();
17819
 
17820
		#取得當前執行的函數名稱
17821
		$result["function"]=__FUNCTION__;
17822
 
17823
		#如果沒有參數
17824
		if(func_num_args()==0){
226 liveuser 17825
 
3 liveuser 17826
			#設置執行失敗
17827
			$result["status"]="false";
226 liveuser 17828
 
3 liveuser 17829
			#設置執行錯誤訊息
17830
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 17831
 
3 liveuser 17832
			#回傳結果
17833
			return $result;
226 liveuser 17834
 
220 liveuser 17835
			}#if end
3 liveuser 17836
 
17837
		#取得參數
17838
		$result["argu"]=$conf;
17839
 
17840
		#如果 $conf 不為陣列
17841
		if(gettype($conf)!=="array"){
226 liveuser 17842
 
3 liveuser 17843
			#設置執行失敗
17844
			$result["status"]="false";
226 liveuser 17845
 
3 liveuser 17846
			#設置執行錯誤訊息
17847
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 17848
 
3 liveuser 17849
			#如果傳入的參數為 null
17850
			if($conf===null){
226 liveuser 17851
 
3 liveuser 17852
				#設置執行錯誤訊息
17853
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 17854
 
3 liveuser 17855
				}#if end
17856
 
17857
			#回傳結果
17858
			return $result;
226 liveuser 17859
 
3 liveuser 17860
			}#if end
226 liveuser 17861
 
3 liveuser 17862
		#檢查參數
17863
		#函式說明:
17864
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
17865
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17866
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
17867
		#$result["function"],當前執行的函式名稱.
17868
		#$result["argu"],設置給予的參數.
17869
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
17870
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
17871
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
17872
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
17873
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
17874
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
17875
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
17876
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
17877
		#必填寫的參數:
17878
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
220 liveuser 17879
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 17880
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
17881
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
17882
		#可以省略的參數:
17883
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
17884
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","file");
17885
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
17886
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
17887
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
17888
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
17889
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
17890
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
17891
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
17892
		#$conf["canBeEmpty"]=array();
17893
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
220 liveuser 17894
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("overWriteWith","replaceWith","addToTailWhenNoMatch","addToTailBeforeThat","replaceLike","replaceSpecifyLine","outputPath");
3 liveuser 17895
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
220 liveuser 17896
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("overWriteWith","replaceWith","addToTailWhenNoMatch","addToTailBeforeThat","replaceLike","replaceSpecifyLine","outputPath");
226 liveuser 17897
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
220 liveuser 17898
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","string","string","string","array","string");
3 liveuser 17899
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
220 liveuser 17900
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false",null,"false",null,null);
3 liveuser 17901
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
17902
		#$conf["disallowAllSkipableVarIsEmpty"]="";
17903
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
17904
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
17905
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
17906
		#$conf["arrayCountEqualCheck"][]=array();
17907
		#參考資料來源:
17908
		#array_keys=>http://php.net/manual/en/function.array-keys.php
17909
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
17910
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 17911
 
3 liveuser 17912
		#如果檢查參數失敗
17913
		if($checkArguments["status"]==="false"){
226 liveuser 17914
 
3 liveuser 17915
			#設置執行失敗
17916
			$result["status"]="false";
226 liveuser 17917
 
3 liveuser 17918
			#設置執行失敗訊息
17919
			$result["error"]=$checkArguments;
226 liveuser 17920
 
3 liveuser 17921
			#回傳結果
17922
			return $result;
226 liveuser 17923
 
3 liveuser 17924
			}#if end
226 liveuser 17925
 
3 liveuser 17926
		#如果檢查參數不通過
17927
		if($checkArguments["passed"]==="false"){
226 liveuser 17928
 
3 liveuser 17929
			#設置執行失敗
17930
			$result["status"]="false";
226 liveuser 17931
 
3 liveuser 17932
			#設置執行失敗訊息
17933
			$result["error"]=$checkArguments;
226 liveuser 17934
 
3 liveuser 17935
			#回傳結果
17936
			return $result;
226 liveuser 17937
 
3 liveuser 17938
			}#if end
226 liveuser 17939
 
3 liveuser 17940
		#檢查檔案是否存在
17941
		#函式說明:
17942
		#檢查多個檔案與資料夾是否存在.
17943
		#回傳的結果:
17944
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
17945
		#$result["error"],錯誤訊息陣列.
17946
		#$resutl["function"],當前執行的涵式名稱.
17947
		#$result["argu"],使用的參數.
17948
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
17949
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
17950
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
17951
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
17952
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
17953
		#必填參數:
17954
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
17955
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
17956
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17957
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
17958
		#可省略參數:
17959
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
17960
		$conf["disableWebSearch"]="true";
17961
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
17962
		$conf["userDir"]="false";
17963
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
17964
		$conf["web"]="false";
17965
		#參考資料:
17966
		#http://php.net/manual/en/function.file-exists.php
17967
		#http://php.net/manual/en/control-structures.foreach.php
17968
		#備註:
17969
		#函數file_exists檢查的路徑為檔案系統的路徑
17970
		#$result["varName"][$i]結果未實作
17971
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
17972
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 17973
 
3 liveuser 17974
		#如果檢查參數失敗
17975
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 17976
 
3 liveuser 17977
			#設置執行失敗
17978
			$result["status"]="false";
226 liveuser 17979
 
3 liveuser 17980
			#設置執行失敗訊息
17981
			$result["error"]=$checkMultiFileExist;
226 liveuser 17982
 
3 liveuser 17983
			#回傳結果
17984
			return $result;
226 liveuser 17985
 
3 liveuser 17986
			}#if end
226 liveuser 17987
 
3 liveuser 17988
		#如果目標檔案不存在
17989
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 17990
 
3 liveuser 17991
			#設置執行失敗
17992
			$result["status"]="false";
226 liveuser 17993
 
3 liveuser 17994
			#設置執行失敗訊息
17995
			$result["error"]=$checkMultiFileExist;
226 liveuser 17996
 
3 liveuser 17997
			#回傳結果
17998
			return $result;
226 liveuser 17999
 
3 liveuser 18000
			}#if end
226 liveuser 18001
 
220 liveuser 18002
		#預設要寫入的位置為原始檔案
18003
		$file2write=$conf["file"];
226 liveuser 18004
 
220 liveuser 18005
		#如果有設置 outputPath
18006
		if(isset($conf["outputPath"])){
226 liveuser 18007
 
220 liveuser 18008
			#寫入檔案的路徑與名稱
18009
			$file2write=$conf["outputPath"]."/".$conf["file"];
226 liveuser 18010
 
220 liveuser 18011
			}#if end
226 liveuser 18012
 
3 liveuser 18013
		#如果有設置 overWriteWith
18014
		if(isset($conf["overWriteWith"])){
226 liveuser 18015
 
3 liveuser 18016
			#函式說明:
18017
			#將多行字串寫入到檔案
18018
			#回傳結果:
18019
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
18020
			#$result["error"],錯誤訊息陣列.
18021
			#$result["function"],當前執行函數的名稱.
18022
			#必填參數:
18023
			#$conf["fileName"],字串,爲要編輯的檔案名稱
220 liveuser 18024
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
3 liveuser 18025
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
18026
			$conf["fileAccess::writeMultiLine"]["inputString"]=$conf["overWriteWith"];
18027
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18028
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
220 liveuser 18029
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
18030
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
3 liveuser 18031
			#可省略參數:
18032
			#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
18033
			#參考資料:
18034
			#無.
18035
			#備註:
18036
			#無.
18037
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
18038
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 18039
 
3 liveuser 18040
			#如果執行失敗
18041
			if($writeMultiLine["status"]==="false"){
226 liveuser 18042
 
3 liveuser 18043
				#設置執行失敗
18044
				$result["status"]="false";
226 liveuser 18045
 
3 liveuser 18046
				#設置執行失敗訊息
18047
				$result["error"]=$writeMultiLine;
226 liveuser 18048
 
3 liveuser 18049
				#回傳結果
18050
				return $result;
226 liveuser 18051
 
3 liveuser 18052
				}#if end
226 liveuser 18053
 
220 liveuser 18054
			#取得原始檔案的內容
18055
			#函式說明:
18056
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
18057
			#回傳的變數說明:
18058
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
18059
			#$result["error"],錯誤訊息提示.
18060
			#$result["warning"],警告訊息.
18061
			#$result["function"],當前執行的函數名稱.
18062
			#$result["fileContent"],爲檔案的內容陣列.
18063
			#$result["lineCount"],爲檔案內容總共的行數.
18064
			#$result["fullContent"],為檔案的完整內容.
18065
			#$result["base64data"],為檔案的base64內容.
18066
			#$result["mimeType"],為檔案的mime type.
18067
			#必填參數:
18068
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
18069
			$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
18070
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18071
			$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
18072
			#可省略參數:
18073
			#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
18074
			$conf["fileAccess::getFileContent"]["web"]="false";
18075
			#參考資料:
18076
			#file(),取得檔案內容的行數.
18077
			#file=>http:#php.net/manual/en/function.file.php
18078
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
18079
			#filesize=>http://php.net/manual/en/function.filesize.php
18080
			#參考資料:
18081
			#無.
18082
			#備註:
18083
			#無.
18084
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
18085
			unset($conf["fileAccess::getFileContent"]);
226 liveuser 18086
 
220 liveuser 18087
			#如果執行失敗
18088
			if($getFileContent["status"]==="false"){
226 liveuser 18089
 
220 liveuser 18090
				#設置執行失敗
18091
				$result["status"]="false";
226 liveuser 18092
 
220 liveuser 18093
				#設置執行失敗訊息
18094
				$result["error"]=$getFileContent;
226 liveuser 18095
 
220 liveuser 18096
				#回傳結果
18097
				return $result;
226 liveuser 18098
 
220 liveuser 18099
				}#if end
226 liveuser 18100
 
220 liveuser 18101
			#無窮迴圈
18102
			for($i=0;$i>=0;$i++){
226 liveuser 18103
 
220 liveuser 18104
				#如果有舊或新的行內容存在
18105
				if( isset($getFileContent["fileContent"][$i]) || isset($conf["overWriteWith"][$i]) ){
226 liveuser 18106
 
220 liveuser 18107
					#初始化暫存舊行內容的變數
18108
					$oriLine=null;
226 liveuser 18109
 
220 liveuser 18110
					#初始化暫存新行內容的變數
18111
					$newLine=null;
226 liveuser 18112
 
220 liveuser 18113
					#如果存在原行內容
18114
					if(isset($getFileContent["fileContent"][$i])){
226 liveuser 18115
 
220 liveuser 18116
						#儲存原行內容
18117
						$oriLine=$getFileContent["fileContent"][$i];
226 liveuser 18118
 
220 liveuser 18119
						}#if end
226 liveuser 18120
 
220 liveuser 18121
					#如果存在新行內容
18122
					if(isset($conf["overWriteWith"][$i])){
226 liveuser 18123
 
220 liveuser 18124
						#儲存新行內容
18125
						$newLine=$conf["overWriteWith"][$i];
226 liveuser 18126
 
220 liveuser 18127
						}#if end
226 liveuser 18128
 
220 liveuser 18129
					#設置更新的資訊
18130
					$result["content"][$i]=array("ori"=>$oriLine,"new"=>$newLine);
226 liveuser 18131
 
220 liveuser 18132
					}#if end
226 liveuser 18133
 
220 liveuser 18134
				#反之
18135
				else{
226 liveuser 18136
 
220 liveuser 18137
					#結束迴圈
18138
					break;
226 liveuser 18139
 
220 liveuser 18140
					}#else end
226 liveuser 18141
 
220 liveuser 18142
				}#for end
226 liveuser 18143
 
3 liveuser 18144
			}#if end
226 liveuser 18145
 
220 liveuser 18146
		#反之如果有設置 "replaceWith"
18147
		else if(isset($conf["replaceWith"])){
226 liveuser 18148
 
3 liveuser 18149
			#取得檔案的內容
18150
			#函式說明:
18151
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
18152
			#回傳的變數說明:
18153
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
18154
			#$result["error"],錯誤訊息提示.
18155
			#$result["warning"],警告訊息.
18156
			#$result["function"],當前執行的函數名稱.
18157
			#$result["fileContent"],爲檔案的內容陣列.
18158
			#$result["lineCount"],爲檔案內容總共的行數.
18159
			#$result["fullContent"],為檔案的完整內容.
18160
			#$result["base64data"],為檔案的base64內容.
18161
			#$result["mimeType"],為檔案的mime type.
18162
			#必填參數:
18163
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
18164
			$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
18165
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18166
			$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
18167
			#可省略參數:
18168
			#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
18169
			$conf["fileAccess::getFileContent"]["web"]="false";
18170
			#參考資料:
18171
			#file(),取得檔案內容的行數.
18172
			#file=>http:#php.net/manual/en/function.file.php
18173
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
18174
			#filesize=>http://php.net/manual/en/function.filesize.php
18175
			#參考資料:
18176
			#無.
18177
			#備註:
18178
			#無.
18179
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
18180
			unset($conf["fileAccess::getFileContent"]);
226 liveuser 18181
 
3 liveuser 18182
			#如果執行失敗
18183
			if($getFileContent["status"]==="false"){
226 liveuser 18184
 
3 liveuser 18185
				#設置執行失敗
18186
				$result["status"]="false";
226 liveuser 18187
 
3 liveuser 18188
				#設置執行失敗訊息
18189
				$result["error"]=$getFileContent;
226 liveuser 18190
 
3 liveuser 18191
				#回傳結果
18192
				return $result;
226 liveuser 18193
 
3 liveuser 18194
				}#if end
226 liveuser 18195
 
3 liveuser 18196
			#取得原始檔案的每行內容
18197
			$oriFileContentByLine=&$getFileContent["fileContent"];
226 liveuser 18198
 
3 liveuser 18199
			#針對每個 replaceWith 條件
18200
			foreach($conf["replaceWith"] as $replaceInfo){
226 liveuser 18201
 
3 liveuser 18202
				#預設尚未找到符合的關鍵字
18203
				$foundKeyWord=false;
226 liveuser 18204
 
3 liveuser 18205
				#取得要替換的目標字串
18206
				$oriStr=$replaceInfo[0];
226 liveuser 18207
 
3 liveuser 18208
				#取得要替換成的字串內容
18209
				$newStr=$replaceInfo[1];
226 liveuser 18210
 
3 liveuser 18211
				#針對每行原始內容
18212
				foreach($oriFileContentByLine as $index => $line){
226 liveuser 18213
 
3 liveuser 18214
					#函式說明:
18215
					#檢查字串裡面有無指定的關鍵字
18216
					#回傳結果:
18217
					#$result["status"],"true"代表執行成功,"false"代表執行失敗。
18218
					#$result["error"],錯誤訊息
18219
					#$result["function"],當前執行的函數名稱.
18220
					#$result["argu"],使用的參數.
18221
					#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
18222
					#$result["keyWordCount"],找到的關鍵字數量.
18223
					#必填參數:
18224
					#$conf["keyWord"],字串,想要搜尋的關鍵字.
18225
					$conf["search::findKeyWord"]["keyWord"]=$oriStr;
18226
					#$conf["string"],字串,要被搜尋的字串內容
18227
					$conf["search::findKeyWord"]["string"]=$line;
18228
					#可省略參數:
226 liveuser 18229
 
3 liveuser 18230
					#如果要完全符合關鍵字
18231
					if($conf["replaceLike"]==="false"){
226 liveuser 18232
 
3 liveuser 18233
						#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
18234
						$conf["search::findKeyWord"]["completeEqual"]="true";
226 liveuser 18235
 
3 liveuser 18236
						}#if end
226 liveuser 18237
 
3 liveuser 18238
					#參考資料:
18239
					#無.
18240
					#備註:
18241
					#無.
18242
					$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
18243
					unset($conf["search::findKeyWord"]);
226 liveuser 18244
 
3 liveuser 18245
					#如果執行失敗
18246
					if($findKeyWord["status"]==="false"){
226 liveuser 18247
 
3 liveuser 18248
						#設置執行失敗
18249
						$result["status"]="false";
226 liveuser 18250
 
3 liveuser 18251
						#設置執行失敗訊息
18252
						$result["error"]=$findKeyWord;
226 liveuser 18253
 
3 liveuser 18254
						#回傳結果
18255
						return $result;
226 liveuser 18256
 
3 liveuser 18257
						}#if end
226 liveuser 18258
 
3 liveuser 18259
					#如果有找到關鍵字
18260
					if($findKeyWord["founded"]==="true"){
226 liveuser 18261
 
220 liveuser 18262
						#設置更新的資訊
18263
						$result["content"][$lineIndex]=array("ori"=>$oriFileContentByLine[$index],"new"=>$newStr);
226 liveuser 18264
 
3 liveuser 18265
						#更新該行內容
18266
						$oriFileContentByLine[$index]=$newStr;
226 liveuser 18267
 
3 liveuser 18268
						#設置有找到符合的關鍵字
18269
						$foundKeyWord=true;
226 liveuser 18270
 
3 liveuser 18271
						}#if end
226 liveuser 18272
 
3 liveuser 18273
					}#foreach end
226 liveuser 18274
 
3 liveuser 18275
				#如果沒有找到關鍵字
18276
				if($foundKeyWord===false){
226 liveuser 18277
 
3 liveuser 18278
					#如果要新增內容
18279
					if($conf["addToTailWhenNoMatch"]==="true"){
226 liveuser 18280
 
3 liveuser 18281
						#如果有設置 addToTailBeforeThat
18282
						if(isset($conf["addToTailBeforeThat"])){
226 liveuser 18283
 
3 liveuser 18284
							#預設沒有找到符合的關鍵字
18285
							$foundKeyWord=false;
226 liveuser 18286
 
3 liveuser 18287
							#初始化要記錄要 append 回去的各行內容.
18288
							$linesToAppend=array();
226 liveuser 18289
 
3 liveuser 18290
							#倒敘,針對每行內容
18291
							for($i=count($oriFileContentByLine)-1;$i>=0;$i--){
226 liveuser 18292
 
3 liveuser 18293
								#儲存要 append 回去的行內容
18294
								$linesToAppend[]=$oriFileContentByLine[$i];
226 liveuser 18295
 
3 liveuser 18296
								#如果找到關鍵字了
18297
								if($oriFileContentByLine[$i]===$conf["addToTailBeforeThat"]){
226 liveuser 18298
 
3 liveuser 18299
									#設置有找到符合的關鍵字
18300
									$foundKeyWord=true;
226 liveuser 18301
 
220 liveuser 18302
									#設置更新的資訊
18303
									$result["content"][$lineIndex]=array("ori"=>$oriFileContentByLine[$i],"new"=>$line);
226 liveuser 18304
 
3 liveuser 18305
									#更新該行內容
18306
									$oriFileContentByLine[$i]=$line;
226 liveuser 18307
 
3 liveuser 18308
									#倒敘陣列
18309
									$linesToAppend=array_reverse($linesToAppend);
226 liveuser 18310
 
3 liveuser 18311
									#針對每行要 append 回去的內容
18312
									foreach($linesToAppend as $lineToAppend){
226 liveuser 18313
 
3 liveuser 18314
										#append 行內容
18315
										$oriFileContentByLine[]=$lineToAppend;
226 liveuser 18316
 
220 liveuser 18317
										#設置更新的資訊
18318
										$result["content"][count($oriFileContentByLine)-1]=array("ori"=>null,"new"=>$lineToAppend);
226 liveuser 18319
 
3 liveuser 18320
										}#foreach end
226 liveuser 18321
 
3 liveuser 18322
									}#if end
226 liveuser 18323
 
3 liveuser 18324
								}#for end
226 liveuser 18325
 
3 liveuser 18326
							#如果沒有找到關鍵字
18327
							if($foundKeyWord===false){
226 liveuser 18328
 
3 liveuser 18329
								#設置執行失敗
18330
								$result["status"]="false";
226 liveuser 18331
 
3 liveuser 18332
								#設置錯誤訊息
18333
								$result["error"]="can't find \"".$conf["addToTailBeforeThat"]."\" to insert before it.";
226 liveuser 18334
 
3 liveuser 18335
								#回傳結果
18336
								return $result;
226 liveuser 18337
 
3 liveuser 18338
								}#if end
226 liveuser 18339
 
3 liveuser 18340
							}#if end
226 liveuser 18341
 
3 liveuser 18342
						}#if end
226 liveuser 18343
 
3 liveuser 18344
					}#if end
226 liveuser 18345
 
3 liveuser 18346
				}#foreach end
226 liveuser 18347
 
3 liveuser 18348
			#函式說明:
18349
			#將多行字串寫入到檔案
18350
			#回傳結果:
18351
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
18352
			#$result["error"],錯誤訊息陣列.
18353
			#$result["function"],當前執行函數的名稱.
18354
			#必填參數:
18355
			#$conf["fileName"],字串,爲要編輯的檔案名稱
220 liveuser 18356
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
3 liveuser 18357
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
18358
			$conf["fileAccess::writeMultiLine"]["inputString"]=$oriFileContentByLine;
18359
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18360
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
18361
			#可省略參數:
18362
			#$conf["fileAccess::writeMultiLine"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
220 liveuser 18363
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
18364
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
3 liveuser 18365
			#參考資料:
18366
			#無.
18367
			#備註:
18368
			#無.
18369
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
18370
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 18371
 
3 liveuser 18372
			#如果執行失敗
18373
			if($writeMultiLine["status"]==="false"){
226 liveuser 18374
 
3 liveuser 18375
				#設置執行失敗
18376
				$result["status"]="false";
226 liveuser 18377
 
3 liveuser 18378
				#設置執行失敗訊息
18379
				$result["error"]=$writeMultiLine;
226 liveuser 18380
 
3 liveuser 18381
				#回傳結果
18382
				return $result;
226 liveuser 18383
 
3 liveuser 18384
				}#if end
226 liveuser 18385
 
3 liveuser 18386
			}#if end
226 liveuser 18387
 
220 liveuser 18388
		#反之如果有設置 replaceSpecifyLine
18389
		else if(isset($conf["replaceSpecifyLine"])){
226 liveuser 18390
 
220 liveuser 18391
			#讀取原始檔案內容
18392
			#函式說明:
18393
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
18394
			#回傳的變數說明:
18395
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
18396
			#$result["error"],錯誤訊息提示.
18397
			#$result["warning"],警告訊息.
18398
			#$result["function"],當前執行的函數名稱.
18399
			#$result["fileContent"],爲檔案的內容陣列.
18400
			#$result["lineCount"],爲檔案內容總共的行數.
18401
			#$result["fullContent"],為檔案的完整內容.
18402
			#$result["base64dataOnly"],檔案的base64data.
18403
			#$result["base64data"],為在網頁上給予src參數的數值.
18404
			#$result["mimeType"],為檔案的mime type.
18405
			#必填參數:
18406
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
18407
			$conf["fileAcceess::getFileContent"]["filePositionAndName"]=$conf["file"];
18408
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18409
			$conf["fileAcceess::getFileContent"]["fileArgu"]=__FILE__;
18410
			#可省略參數:
18411
			#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
18412
			#$conf["web"]="true";
18413
			#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
18414
			#$conf["createIfnotExist"]="false";
18415
			#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
18416
			#$conf["autoDeleteSpaceOnEachLineStart"]="false";
18417
			#參考資料:
18418
			#file(),取得檔案內容的行數.
18419
			#file=>http:#php.net/manual/en/function.file.php
18420
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
18421
			#filesize=>http://php.net/manual/en/function.filesize.php
18422
			#參考資料:
18423
			#無.
18424
			#備註:
18425
			#無.
18426
			$getFileContent=fileAccess::getFileContent($conf["fileAcceess::getFileContent"]);
18427
			unset($conf["fileAcceess::getFileContent"]);
226 liveuser 18428
 
220 liveuser 18429
			#如果執行失敗
18430
			if($getFileContent["status"]==="false"){
226 liveuser 18431
 
220 liveuser 18432
				#設置執行失敗
18433
				$result["status"]="false";
226 liveuser 18434
 
220 liveuser 18435
				#設置執行失敗訊息
18436
				$result["error"]=$getFileContent;
226 liveuser 18437
 
220 liveuser 18438
				#回傳結果
18439
				return $result;
226 liveuser 18440
 
220 liveuser 18441
				}#if end
226 liveuser 18442
 
220 liveuser 18443
			#針對每個要更新的行
18444
			foreach($conf["replaceSpecifyLine"] as $lineIndex => $newLineContent){
226 liveuser 18445
 
220 liveuser 18446
				#設置更新的資訊
18447
				$result["content"][$lineIndex]=array("ori"=>$getFileContent["fileContent"][$lineIndex],"new"=>$newLineContent);
226 liveuser 18448
 
220 liveuser 18449
				#更新行內容
18450
				$getFileContent["fileContent"][$lineIndex]=$newLineContent;
226 liveuser 18451
 
220 liveuser 18452
				}#foreach end
226 liveuser 18453
 
220 liveuser 18454
			#debug
18455
			#var_dump(__FILE__,__LINE__,count($getFileContent["fileContent"]));
226 liveuser 18456
 
220 liveuser 18457
			#將變更寫入到檔案裡面
18458
			#函式說明:
18459
			#將多行字串寫入到檔案
18460
			#回傳結果:
18461
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
18462
			#$result["error"],錯誤訊息陣列.
18463
			#$result["function"],當前執行函數的名稱.
18464
			#必填參數:
18465
			#$conf["fileName"],字串,爲要編輯的檔案名稱
18466
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
18467
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
18468
			$conf["fileAccess::writeMultiLine"]["inputString"]=$getFileContent["fileContent"];
18469
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18470
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=__FILE__;
18471
			#可省略參數:
18472
			$conf["fileAccess::writeMultiLine"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
18473
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
18474
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
18475
			#參考資料:
18476
			#無.
18477
			#備註:
18478
			#無.
18479
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
18480
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 18481
 
220 liveuser 18482
			#如果執行失敗
18483
			if($writeMultiLine["status"]==="false"){
226 liveuser 18484
 
220 liveuser 18485
				#設置執行失敗
18486
				$result["status"]="false";
226 liveuser 18487
 
220 liveuser 18488
				#設置執行失敗訊息
18489
				$result["error"]=$writeMultiLine;
226 liveuser 18490
 
220 liveuser 18491
				#回傳結果
18492
				return $result;
226 liveuser 18493
 
220 liveuser 18494
				}#if end
226 liveuser 18495
 
220 liveuser 18496
			#debug
18497
			#var_dump(__FILE__,__LINE__,$writeMultiLine);exit(1);
226 liveuser 18498
 
220 liveuser 18499
			}#if end
226 liveuser 18500
 
3 liveuser 18501
		#設置執行正常
18502
		$result["status"]="true";
226 liveuser 18503
 
3 liveuser 18504
		#回傳結果
18505
		return $result;
226 liveuser 18506
 
3 liveuser 18507
		}#function updateFile end
226 liveuser 18508
 
3 liveuser 18509
	/*
18510
	#函式說明:
18511
	#輔助使用PHP內建的chmod函式.
18512
	#回傳結果:
18513
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18514
	#$result["error"],錯誤訊息.
18515
	#$result["function"],當前執行的函式名稱.
18516
	#$result["argu"],使用的參數.
18517
	#$result["cmd"],執行的指令.
18518
	#$result["content"],執行的結果陣列,如果參數 "recursive" 跟 "excludeSelf" 都有設定的話,就會回傳該結果.
18519
	#必填參數:
18520
	#$conf["mode"],字串,要變成什麼權限.
18521
	$conf["mode"]="";
18522
	#$conf["target"],字串,需要變更權限的目標.
18523
	$conf["target"]="";
18524
	#可省略參數:
18525
	#無.
18526
	#參考資料:
18527
	#無.
18528
	#備註:
18529
	#無.
18530
	*/
18531
	public static function chmod(&$conf){
226 liveuser 18532
 
3 liveuser 18533
		#初始化要回傳的結果
18534
		$result=array();
18535
 
18536
		#取得當前執行的函數名稱
18537
		$result["function"]=__FUNCTION__;
18538
 
18539
		#如果沒有參數
18540
		if(func_num_args()==0){
18541
 
18542
			#設置執行失敗
18543
			$result["status"]="false";
18544
 
18545
			#設置執行錯誤訊息
18546
			$result["error"]="函數".$result["function"]."需要參數";
18547
 
18548
			#回傳結果
18549
			return $result;
18550
 
18551
			}#if end
18552
 
18553
		#取得參數
18554
		$result["argu"]=$conf;
18555
 
18556
		#如果 $conf 不為陣列
18557
		if(gettype($conf)!=="array"){
18558
 
18559
			#設置執行失敗
18560
			$result["status"]="false";
18561
 
18562
			#設置執行錯誤訊息
18563
			$result["error"][]="\$conf變數須為陣列形態";
18564
 
18565
			#如果傳入的參數為 null
18566
			if(is_null($conf)){
18567
 
18568
				#設置執行錯誤訊息
18569
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
18570
 
18571
				}#if end
18572
 
18573
			#回傳結果
18574
			return $result;
18575
 
18576
			}#if end
226 liveuser 18577
 
3 liveuser 18578
		#函式說明:
18579
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
18580
		#回傳結果:
18581
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18582
		#$result["error"],執行不正常結束的錯訊息陣列.
18583
		#$result["simpleError"],簡單表示的錯誤訊息.
18584
		#$result["function"],當前執行的函式名稱.
18585
		#$result["argu"],設置給予的參數.
18586
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
18587
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
18588
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
18589
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
18590
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
18591
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
18592
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
18593
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
18594
		#必填參數:
18595
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
18596
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
18597
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
18598
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
18599
		#可省略參數:
18600
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
18601
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mode","target");
18602
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
18603
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
18604
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
18605
		#$conf["canBeEmptyString"]="false";
18606
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
18607
		#$conf["canNotBeEmpty"]=array();
18608
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
18609
		#$conf["canBeEmpty"]=array();
18610
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
18611
		#$conf["skipableVariableCanNotBeEmpty"]=array();
18612
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
18613
		#$conf["skipableVariableName"]=array();
18614
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
18615
		#$conf["skipableVariableType"]=array();
18616
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
18617
		#$conf["skipableVarDefaultValue"]=array("");
18618
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
18619
		#$conf["disallowAllSkipableVarIsEmpty"]="";
18620
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
18621
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
18622
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
18623
		#$conf["arrayCountEqualCheck"][]=array();
18624
		#參考資料:
18625
		#array_keys=>http://php.net/manual/en/function.array-keys.php
18626
		#備註:
18627
		#無.
18628
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
18629
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 18630
 
3 liveuser 18631
		#如果檢查參數失敗
18632
		if($checkArguments["status"]==="false"){
226 liveuser 18633
 
3 liveuser 18634
			#設置執行失敗
18635
			$result["status"]="false";
18636
 
18637
			#設置錯誤資訊
18638
			$result["error"]=$checkArguments;
226 liveuser 18639
 
3 liveuser 18640
			#回傳結果
18641
			return $result;
226 liveuser 18642
 
3 liveuser 18643
			}#if end
226 liveuser 18644
 
3 liveuser 18645
		#如果檢查參數不通過
18646
		if($checkArguments["passed"]==="false"){
226 liveuser 18647
 
3 liveuser 18648
			#設置執行失敗
18649
			$result["status"]="false";
18650
 
18651
			#設置錯誤資訊
18652
			$result["error"]=$checkArguments;
226 liveuser 18653
 
3 liveuser 18654
			#回傳結果
18655
			return $result;
226 liveuser 18656
 
3 liveuser 18657
			}#if end
226 liveuser 18658
 
3 liveuser 18659
		#將$conf["mode"]轉換為10進位的整數
18660
		$conf["mode"]=(int)base_convert($conf["mode"],8,10);
226 liveuser 18661
 
3 liveuser 18662
		#變更 target 的檔案權限為代碼
226 liveuser 18663
		$chmod=chmod($conf["target"],$conf["mode"]);
18664
 
3 liveuser 18665
		#如果改變檔案權限失敗
18666
		if($chmod===false){
226 liveuser 18667
 
3 liveuser 18668
			#設置執行失敗
18669
			$result["status"]="false";
226 liveuser 18670
 
3 liveuser 18671
			#設置錯誤訊息
18672
			$result["error"][]="改變 ".$conf["target"]." 檔案的權限資訊為 ".$conf["mode"]." 失敗,通常只有系統帳戶才能變更之.";
226 liveuser 18673
 
3 liveuser 18674
			#回傳結果
226 liveuser 18675
			return $result;
18676
 
3 liveuser 18677
			}#if end
226 liveuser 18678
 
3 liveuser 18679
		#設置執行正常
18680
		$result["status"]="true";
226 liveuser 18681
 
3 liveuser 18682
		#回傳結果
18683
		return $result;
226 liveuser 18684
 
3 liveuser 18685
		}#function chmod end
18686
 
18687
	}#class fileAccess end
18688
 
226 liveuser 18689
?>