Subversion Repositories php-qbpwcf

Rev

Rev 376 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
namespace qbpwcf;
25
 
26
/*
27
類別說明:
28
檔案存取應用的類別.
29
備註:
30
無.
31
*/
32
class fileAccess{
33
 
34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	*/
47
	public function __call($method,$arguments){
226 liveuser 48
 
3 liveuser 49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
226 liveuser 51
 
3 liveuser 52
		#設置執行不正常
53
		$result["status"]="false";
226 liveuser 54
 
3 liveuser 55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 57
 
3 liveuser 58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
226 liveuser 60
 
3 liveuser 61
		#回傳結果
62
		return $result;
226 liveuser 63
 
3 liveuser 64
		}#function __call end
226 liveuser 65
 
3 liveuser 66
	/*
67
	#函式說明:
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
69
	#回傳結果:
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
71
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
72
	#$result["function"],當前執行的函式名稱.
73
	#必填參數:
74
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
75
	#$arguments,陣列,為呼叫方法時所用的參數.
76
	#參考資料:
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
78
	*/
79
	public static function __callStatic($method,$arguments){
226 liveuser 80
 
3 liveuser 81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
226 liveuser 83
 
3 liveuser 84
		#設置執行不正常
85
		$result["status"]="false";
226 liveuser 86
 
3 liveuser 87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 89
 
3 liveuser 90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
226 liveuser 92
 
3 liveuser 93
		#回傳結果
94
		return $result;
226 liveuser 95
 
3 liveuser 96
		}#function __callStatic end
97
 
98
	/*
99
	#函式說明:
100
	#將字串寫入到檔案
101
	#回傳結果:
102
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
103
	#$result["error"],錯誤訊息陣列.
104
	#$result["function"],當前執行的函數名稱.
105
	#$result["fileInfo"],實際上寫入的檔案資訊陣列.
106
	#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
107
	#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
108
	#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
109
	#$result["argu"],使用的參數.
110
	#必填參數:
111
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
112
	$conf["fileArgu"]=__FILE__;
113
	#可省略參數:
114
	#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
115
	#$conf["fileName"]="";
116
	#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
117
	#$conf["inputString"]="";
118
	#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
119
	#$conf["writeMethod"]="a";
120
	#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
121
	#$conf["checkRepeat"]="";
122
	#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
123
	#$conf["filenameExtensionStartPoint"]="";
124
	#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
125
	#$conf["repeatNameRule"]="";
126
	#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
127
	#$conf["web"]="true";
128
	#參考資料:
129
	#無.
130
	#備註:
131
	#無.
132
	*/
133
	public static function writeTextIntoFile(&$conf){
134
 
135
		#初始化要回傳的變數
136
		$result=array();
137
 
138
		#初始化當前執行的函數名稱
139
		$result["function"]=__FUNCTION__;
140
 
141
		#如果 $conf 不為陣列
142
		if(gettype($conf)!="array"){
226 liveuser 143
 
3 liveuser 144
			#設置執行失敗
145
			$result["status"]="false";
226 liveuser 146
 
3 liveuser 147
			#設置執行錯誤訊息
148
			$result["error"][]="\$conf變數須為陣列形態";
149
 
150
			#如果傳入的參數為 null
151
			if($conf==null){
226 liveuser 152
 
3 liveuser 153
				#設置執行錯誤訊息
154
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 155
 
3 liveuser 156
				}#if end
157
 
158
			#回傳結果
159
			return $result;
226 liveuser 160
 
3 liveuser 161
			}#if end
226 liveuser 162
 
3 liveuser 163
		#取得使用的參數
164
		$result["argu"]=$conf;
165
 
166
		#檢查參數
167
		#函式說明:
168
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
169
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
170
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
171
		#$result["function"],當前執行的函式名稱.
172
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
173
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
174
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
175
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
176
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
177
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
178
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
179
		#必填寫的參數:
180
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
181
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
182
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
183
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
226 liveuser 184
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 185
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
186
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
187
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
188
		#可以省略的參數:
189
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
190
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
191
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
192
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileName","inputString","writeMethod","checkRepeat","filenameExtensionStartPoint","repeatNameRule","web");
226 liveuser 193
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 194
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
195
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
196
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"","w","false",null,null,"true");
197
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
198
		#$conf["arrayCountEqualCheck"][]=array();
199
		#參考資料來源:
200
		#array_keys=>http://php.net/manual/en/function.array-keys.php
201
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
202
		unset($conf["variableCheck::checkArguments"]);
203
 
204
		#如果 $checkArguments["status"] 等於 "false"
205
		if($checkArguments["status"]=="false"){
226 liveuser 206
 
3 liveuser 207
			#設置錯誤識別
208
			$result["status"]="false";
226 liveuser 209
 
3 liveuser 210
			#設置錯誤訊息
211
			$result["error"]=$checkArguments;
226 liveuser 212
 
3 liveuser 213
			#回傳結果
220 liveuser 214
			return $result;
226 liveuser 215
 
3 liveuser 216
			}#if end
226 liveuser 217
 
3 liveuser 218
		#如果 $checkArguments["passed"] 等於 "false"
219
		if($checkArguments["passed"]=="false"){
226 liveuser 220
 
3 liveuser 221
			#設置錯誤識別
222
			$result["status"]="false";
226 liveuser 223
 
3 liveuser 224
			#設置錯誤訊息
225
			$result["error"]=$checkArguments;
226 liveuser 226
 
3 liveuser 227
			#回傳結果
220 liveuser 228
			return $result;
226 liveuser 229
 
3 liveuser 230
			}#if end
231
 
232
		#如果沒有設置 $conf["fileName"]
233
		if(!isset($conf["fileName"])){
226 liveuser 234
 
3 liveuser 235
			#設定要檢查是否有重複的檔案名稱
236
			$conf["checkRepeat"]="true";
226 liveuser 237
 
3 liveuser 238
			#亂數產生檔案名稱
239
			#函式說明:
240
			#建立以圖片(PNG格式)呈現的驗證碼.
241
			#回傳的解果:
242
			#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
243
			#$result["error"],錯誤訊息.
244
			#$result["function"],檔前執行的函數名稱.
245
			#$result["randNumberWord"],傳驗證碼的內容.
246
			#$result["imgAddress"],圖片的位置與名稱.
247
			#必填參數:
248
			#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
249
			$conf["authenticate::validationCode"]["imgAddressAndName"]="don't need!";
250
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
251
			$conf["authenticate::validationCode"]["fileArgu"]=$conf["fileArgu"];
252
			#可省略參數:
253
			#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
254
			$conf["authenticate::validationCode"]["num"]="10";
255
			#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
256
			$conf["authenticate::validationCode"]["disableImg"]="true";
257
			#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
258
			#$conf["imgToData"]="true";
259
			$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
260
			unset($conf["authenticate::validationCode"]);
226 liveuser 261
 
3 liveuser 262
			#如果亂數產生錯誤
263
			if($validationCode["status"]=="false"){
226 liveuser 264
 
3 liveuser 265
				#設置錯誤識別
266
				$result["status"]="false";
226 liveuser 267
 
3 liveuser 268
				#設置錯誤訊息
269
				$result["error"]=$validationCode;
226 liveuser 270
 
3 liveuser 271
				#回傳結果
226 liveuser 272
				return $result;
273
 
3 liveuser 274
				}#if end
226 liveuser 275
 
3 liveuser 276
			#取得產生的檔案名稱
277
			$conf["fileName"]=$validationCode["randNumberWord"];
226 liveuser 278
 
3 liveuser 279
			}#if end
280
 
281
		#剃除 $conf["fileName"] 開頭的 "./"
282
		#函式說明:
283
		#移除字串開頭的特定內容
284
		#回傳的接結果:
285
		#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
286
		#$result["error"],錯誤訊息陣列.
287
		#$result["function"],當前執行的函數.
288
		#$result["content"],處理好的字串.
289
		#必填參數:
290
		#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
291
		$conf["stringProcess::delKeyWordsInStrHead"]["inputStr"]=$conf["fileName"];
292
		#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
226 liveuser 293
		$conf["stringProcess::delKeyWordsInStrHead"]["keyWord"]="./";
3 liveuser 294
		#可省略參數:
295
		#無.
296
		$delKeyWordsInStrHead=stringProcess::delKeyWordsInStrHead($conf["stringProcess::delKeyWordsInStrHead"]);
297
		unset($conf["stringProcess::delKeyWordsInStrHead"]);
298
 
299
		#如果處理失敗
300
		if($delKeyWordsInStrHead["status"]=="false"){
226 liveuser 301
 
3 liveuser 302
			#設置錯誤識別
303
			$result["status"]="false";
226 liveuser 304
 
3 liveuser 305
			#設置錯誤訊息
306
			$result["error"]=$delKeyWordsInStrHead;
226 liveuser 307
 
3 liveuser 308
			#回傳結果
226 liveuser 309
			return $result;
310
 
3 liveuser 311
			}#if end
226 liveuser 312
 
3 liveuser 313
		#取得處理好的檔案名稱
314
		$conf["fileName"]=$delKeyWordsInStrHead["content"];
315
 
316
		#函式說明:
317
		#確保路徑存在.
318
		#回傳結果:
319
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
320
		#$result["error"],錯誤訊息陣列.
321
		#$resutl["function"],當前執行的涵式名稱.
322
		#必填參數:
323
		#$conf["path"],要檢查的路徑
220 liveuser 324
		$conf["fileAccess::validatePath"]["path"]=$conf["fileName"];
3 liveuser 325
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
326
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
327
		#可省略參數:
328
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
329
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
330
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
331
		#$conf["dirPermission"]="";
332
		$conf["fileAccess::validatePath"]["web"]=$conf["web"];
333
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
334
		unset($conf["fileAccess::validatePath"]);
226 liveuser 335
 
3 liveuser 336
		#debug
337
		#var_dump($validatePath);exit;
226 liveuser 338
 
3 liveuser 339
		#如果確保路徑失敗
340
		if($validatePath["status"]=="false"){
226 liveuser 341
 
3 liveuser 342
			#設置錯誤識別
343
			$result["status"]="false";
226 liveuser 344
 
3 liveuser 345
			#設置錯誤訊息
346
			$result["error"]=$validatePath;
226 liveuser 347
 
3 liveuser 348
			#回傳結果
226 liveuser 349
			return $result;
350
 
3 liveuser 351
			}#if end
226 liveuser 352
 
220 liveuser 353
		#如果要檢查是否有同名的檔案
3 liveuser 354
		if($conf["checkRepeat"]=="true"){
226 liveuser 355
 
3 liveuser 356
			#函式說明:
357
			#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
358
			#回傳的結果:
359
			#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
360
			#$result["error"],錯誤訊息陣列.
361
			#$result["function"],當前執行的函數名稱.
362
			#$result["createdFileName"],建立好的檔案名稱.
363
			#$result["createdFilePath"],檔案建立的路徑.
364
			#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
365
			#必填參數:
366
			#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
367
			$conf["fileAccess::createFileAfterCheck"]["checkedFileAndPath"]=$conf["fileName"];
368
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
369
			$conf["fileAccess::createFileAfterCheck"]["fileArgu"]=$conf["fileArgu"];
370
			#可省略參數:
226 liveuser 371
 
3 liveuser 372
			#如果有設定 $conf["filenameExtensionStartPoint"]
373
			if(isset($conf["filenameExtensionStartPoint"])){
226 liveuser 374
 
3 liveuser 375
				#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點.
376
				$conf["fileAccess::createFileAfterCheck"]["filenameExtensionStartPoint"]=$conf["filenameExtensionStartPoint"];
226 liveuser 377
 
3 liveuser 378
				}#if end
226 liveuser 379
 
3 liveuser 380
			#如果有設定 $conf["repeatNameRule"]
381
			if(isset($conf["repeatNameRule"])){
226 liveuser 382
 
3 liveuser 383
				#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)".
384
				$conf["fileAccess::createFileAfterCheck"]["repeatNameRule"]=$conf["repeatNameRule"];
226 liveuser 385
 
3 liveuser 386
				}#if end
226 liveuser 387
 
3 liveuser 388
			#如果有設定 $conf["web"] 參數
389
			if(isset($conf["web"])){
226 liveuser 390
 
3 liveuser 391
				$conf["fileAccess::createFileAfterCheck"]["web"]=$conf["web"];
226 liveuser 392
 
3 liveuser 393
				}#if end
226 liveuser 394
 
3 liveuser 395
			$createFileAfterCheck=fileAccess::createFileAfterCheck($conf["fileAccess::createFileAfterCheck"]);
396
			unset($conf["fileAccess::createFileAfterCheck"]);
226 liveuser 397
 
3 liveuser 398
			#debug
399
			#var_dump($createFileAfterCheck);
400
			#exit;
226 liveuser 401
 
3 liveuser 402
			#如果嘗試建立檔案失敗
403
			if($createFileAfterCheck["status"]=="false"){
226 liveuser 404
 
3 liveuser 405
				#設置執行不正常
406
				$result["status"]="false";
226 liveuser 407
 
3 liveuser 408
				#設置錯誤訊息
409
				$result["error"]=$createFileAfterCheck;
226 liveuser 410
 
3 liveuser 411
				#回傳結果
412
				return $result;
226 liveuser 413
 
3 liveuser 414
				}#if end
226 liveuser 415
 
3 liveuser 416
			#取得建立的檔案資訊
417
			$result["fileInfo"]["createdFilePathAndName"]=$createFileAfterCheck["createdFilePathAndName"];
418
			$result["fileInfo"]["createdFilePath"]=$createFileAfterCheck["createdFilePath"];
226 liveuser 419
			$result["fileInfo"]["createdFileName"]=$createFileAfterCheck["createdFileName"];
420
 
3 liveuser 421
			#取得建立好的檔案路徑與名稱
422
			$conf["fileName"]=$createFileAfterCheck["createdFilePathAndName"];
226 liveuser 423
 
220 liveuser 424
			}#if end
3 liveuser 425
 
426
		#反之沒有要檢查檔案是否存在
427
		else{
226 liveuser 428
 
3 liveuser 429
			#取得建立的檔案資訊
430
			$result["fileInfo"]["createdFilePathAndName"]=$conf["fileName"];
431
			$result["fileInfo"]["createdFilePath"]=$validatePath["path"];
220 liveuser 432
			$result["fileInfo"]["createdFileName"]=$validatePath["fileName"];
226 liveuser 433
 
3 liveuser 434
			}#else end
435
 
436
		#設定要寫入或複寫的檔案
437
		$fileopenResult=fopen($conf["fileName"],$conf["writeMethod"]);
226 liveuser 438
 
3 liveuser 439
		#如果 $fileopenResult 等於 FALSE
440
		if($fileopenResult==FALSE){
226 liveuser 441
 
3 liveuser 442
			#設置錯誤識別
443
			$result["status"]="false";
226 liveuser 444
 
3 liveuser 445
			#代表打開檔案失敗
446
			$result["error"][]="檔案".$conf["fileName"]."開啟失敗";
226 liveuser 447
 
3 liveuser 448
			#回傳結果
449
			return $result;
226 liveuser 450
 
3 liveuser 451
			}#if end
226 liveuser 452
 
3 liveuser 453
		#將資料寫入到檔案裡面
454
		$fwriteResult=fwrite($fileopenResult,$conf["inputString"]);
455
 
456
		#如果 $fwriteResult 等於 FALSE
457
		if($fwriteResult!=0 && $fwriteResult==FALSE){
226 liveuser 458
 
3 liveuser 459
			#設置錯誤識別
460
			$result["status"]="false";
226 liveuser 461
 
3 liveuser 462
			#代表檔案寫入失敗
463
			$result["error"][]="檔案".$conf["fileName"]."寫入失敗";
226 liveuser 464
 
3 liveuser 465
			#回傳結果
466
			return $result;
226 liveuser 467
 
3 liveuser 468
			}#if end
469
 
470
		#存檔並關閉檔案
471
		$fcloseResult=fclose($fileopenResult);
472
 
473
		#如果 $fcloseResult 等於 FALSE
474
		if($fcloseResult==FALSE){
226 liveuser 475
 
3 liveuser 476
			#設置錯誤識別
477
			$result["status"]="false";
226 liveuser 478
 
3 liveuser 479
			#代表檔案寫入失敗
480
			$result["error"][]="檔案".$conf["fileName"]."儲存失敗";
226 liveuser 481
 
3 liveuser 482
			#回傳結果
483
			return $result;
226 liveuser 484
 
3 liveuser 485
			}#if end
486
 
487
		#檢查用來寫入的檔案是否存在
488
		#函式說明:檢查多個檔案與資料夾是否存在
489
		#回傳的結果:
490
		#$result["varName"][$i],爲第$i個變數的名稱。
491
		#$result["varExist"][$i],爲第$i個變數是否存在,true代表存在,false代表不存在。
492
		#必填參數:
493
		$conf["fileAccess::checkMutiFileExist"]["fileArray"]=array($conf["fileName"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
494
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
495
		$conf["fileAccess::checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
496
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false".
497
		$conf["fileAccess::checkMutiFileExist"]["web"]=$conf["web"];
498
		#參考資料來源:
499
		#http:#php.net/manual/en/function.file-exists.php
500
		#http:#php.net/manual/en/control-structures.foreach.php
501
		$fileAccess["checkMutiFileExist"]=fileAccess::checkMultiFileExist($conf["fileAccess::checkMutiFileExist"]);
502
		unset($conf["fileAccess::checkMutiFileExist"]);
503
 
504
		#如果檢查檔案是否存在失敗
505
		if($fileAccess["checkMutiFileExist"]["status"]==="false"){
226 liveuser 506
 
3 liveuser 507
			#設置錯誤識別
508
			$result["status"]="false";
226 liveuser 509
 
3 liveuser 510
			#設置錯誤訊息陣列
511
			$result["error"]=$fileAccess["checkMutiFileExist"];
226 liveuser 512
 
3 liveuser 513
			#回傳結果
514
			return $result;
226 liveuser 515
 
3 liveuser 516
			}#if end
517
 
226 liveuser 518
		#如果$fileAccess["checkMutiFileExist"]["varExist"][0] 等於 "false"
3 liveuser 519
		if($fileAccess["checkMutiFileExist"]["varExist"][0]==="false"){
226 liveuser 520
 
3 liveuser 521
			#設置錯誤識別
522
			$result["status"]="false";
226 liveuser 523
 
3 liveuser 524
			#設置錯誤訊息
525
			$result["error"]=$fileAccess["checkMutiFileExist"];
226 liveuser 526
 
3 liveuser 527
			#設置錯誤訊息陣列
528
			$result["error"][]="愈建立的檔案不存在";
226 liveuser 529
 
3 liveuser 530
			#回傳結果
531
			return $result;
226 liveuser 532
 
3 liveuser 533
			}#if end
226 liveuser 534
 
3 liveuser 535
		#函式說明:
536
		#依據取得檔案的擁有着資訊
537
		#回傳結果:
538
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
539
		#$result["error"],錯誤訊息陣列.
226 liveuser 540
		#$result["function"],函數名稱.
3 liveuser 541
		#$result["content"],檔案擁有着資訊.
542
		#$result["content"],檔案資訊陣列.
226 liveuser 543
		#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 544
		#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
545
		#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
546
		#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
547
		#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
548
		#$result["content"]["ownerName"],檔案擁有着資訊.
549
		#$result["content"]["groupName"],檔案所屬擁有着資訊.
550
		#$result["content"]["size"],檔案大小.
551
		#$result["content"]["modifyDate"],檔案變更年月日.
552
		#$result["content"]["modifyTime"],檔案變更時分秒.
553
		#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
554
		#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
555
		#必填參數:
556
		#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
557
		$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];
558
		#$conf["file"],字串,要查看擁有者資訊的檔案.
559
		$conf["fileAccess::fileInfo"]["file"]=$conf["fileName"];
560
		#可省略參數:
561
		#$conf["fileToRead"],字串,要讀取的檔案名稱為何?預設為"help".
562
		#$conf["fileToRead"]="help";
563
		#$conf["output"],字串,輸出的網頁檔案位置與名稱,副檔名html會自動補上,預設為"help".
226 liveuser 564
		#$conf["output"]="help.html";
3 liveuser 565
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false".
566
		$conf["fileAccess::fileInfo"]["web"]=$conf["web"];
567
		#參考資料:
568
		#fileowner=>http://php.net/manual/en/function.fileowner.php
569
		#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
570
		$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
571
		unset($conf["fileAccess::fileInfo"]);
226 liveuser 572
 
3 liveuser 573
		#如果取得檔案資訊失敗
574
		if($fileInfo["status"]==="false"){
226 liveuser 575
 
3 liveuser 576
			#設置執行失敗
577
			$result["status"]="false";
226 liveuser 578
 
3 liveuser 579
			#設置錯誤訊息
580
			$result["error"]=$fileInfo;
226 liveuser 581
 
3 liveuser 582
			#回傳結果
583
			return $result;
226 liveuser 584
 
220 liveuser 585
			}#if end
226 liveuser 586
 
3 liveuser 587
		#取得檔案的擁有者名稱
588
		$fileOwner=$fileInfo["content"]["ownerName"];
226 liveuser 589
 
3 liveuser 590
		#執行php的帳戶
220 liveuser 591
		$runner=csInformation::runner();
226 liveuser 592
 
3 liveuser 593
		#如果執行php的使用者等於檔案的擁有者名稱或為root
594
		if($runner===$fileOwner || $runner==="root"){
226 liveuser 595
 
3 liveuser 596
			#改變檔案的權限為0770
597
			chmod($conf["fileName"],0770);
226 liveuser 598
 
3 liveuser 599
			}#if end
226 liveuser 600
 
3 liveuser 601
		#執行到這邊代表執行正常
602
		$result["status"]="true";
226 liveuser 603
 
3 liveuser 604
		#回傳結果
605
		return $result;
226 liveuser 606
 
3 liveuser 607
		}#function writeTextIntoFile end
608
 
609
	/*
610
	#函式說明:
611
	#一次建立多個檔案,並寫入內容.
612
	#回傳結果:
613
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
614
	#$result["error"],錯誤訊息陣列.
615
	#$result["function"],當前執行的函數名稱.
616
	#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
617
	#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
618
	#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
619
	#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
620
	#$result["argu"],使用的參數.
621
	#必填參數:
622
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
623
	$conf["fileArgu"]=__FILE__;
624
	#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
625
	$conf["fileName"]=array("");
626
	#可省略參數:
627
	#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
628
	#$conf["inputString"]=array("");
629
	#參考資料:
630
	#無.
631
	#備註:
632
	#無.
633
	*/
634
	public static function writeMultiFile(&$conf){
226 liveuser 635
 
3 liveuser 636
		#初始化要回傳的變數
637
		$result=array();
638
 
639
		#初始化當前執行的函數名稱
640
		$result["function"]=__FUNCTION__;
641
 
642
		#如果 $conf 不為陣列
643
		if(gettype($conf)!="array"){
226 liveuser 644
 
3 liveuser 645
			#設置執行失敗
646
			$result["status"]="false";
226 liveuser 647
 
3 liveuser 648
			#設置執行錯誤訊息
649
			$result["error"][]="\$conf變數須為陣列形態";
650
 
651
			#如果傳入的參數為 null
652
			if($conf==null){
226 liveuser 653
 
3 liveuser 654
				#設置執行錯誤訊息
655
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 656
 
3 liveuser 657
				}#if end
658
 
659
			#回傳結果
660
			return $result;
226 liveuser 661
 
3 liveuser 662
			}#if end
226 liveuser 663
 
3 liveuser 664
		#取得使用的參數
665
		$result["argu"]=$conf;
666
 
667
		#檢查參數
668
		#函式說明:
669
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
670
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
671
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
672
		#$result["function"],當前執行的函式名稱.
673
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
674
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
675
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
676
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
677
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
678
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
679
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
680
		#必填寫的參數:
681
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
682
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
683
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
684
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileName");
226 liveuser 685
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 686
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
687
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
688
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
689
		#可以省略的參數:
690
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
691
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
692
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
693
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("inputString");
226 liveuser 694
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 695
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
696
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
697
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
698
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
699
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("fileName","inputString");
700
		#參考資料來源:
701
		#array_keys=>http://php.net/manual/en/function.array-keys.php
702
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
703
		unset($conf["variableCheck::checkArguments"]);
704
 
705
		#如果 $checkArguments["status"] 等於 "false"
706
		if($checkArguments["status"]=="false"){
226 liveuser 707
 
3 liveuser 708
			#設置錯誤識別
709
			$result["status"]="false";
226 liveuser 710
 
3 liveuser 711
			#設置錯誤訊息
712
			$result["error"]=$checkArguments;
226 liveuser 713
 
3 liveuser 714
			#回傳結果
220 liveuser 715
			return $result;
226 liveuser 716
 
3 liveuser 717
			}#if end
226 liveuser 718
 
3 liveuser 719
		#如果 $checkArguments["passed"] 等於 "false"
720
		if($checkArguments["passed"]=="false"){
226 liveuser 721
 
3 liveuser 722
			#設置錯誤識別
723
			$result["status"]="false";
226 liveuser 724
 
3 liveuser 725
			#設置錯誤訊息
726
			$result["error"]=$checkArguments;
226 liveuser 727
 
3 liveuser 728
			#回傳結果
220 liveuser 729
			return $result;
226 liveuser 730
 
3 liveuser 731
			}#if end
226 liveuser 732
 
3 liveuser 733
		#如果沒有設定要個別寫入的內容
734
		if(!isset($conf["inputString"])){
226 liveuser 735
 
3 liveuser 736
			#針對每個檔案名稱
737
			for($i=0;$i<count($conf["fileName"]);$i++){
226 liveuser 738
 
3 liveuser 739
				#建立空的 $conf["inputString"]
740
				$conf["inputString"][$i]="";
226 liveuser 741
 
3 liveuser 742
				}#for end
226 liveuser 743
 
3 liveuser 744
			}#if end
226 liveuser 745
 
3 liveuser 746
		#針對每個要寫入的檔案
747
		foreach($conf["fileName"] as $index => $file2writre){
226 liveuser 748
 
3 liveuser 749
			#取得要寫入的內容
750
			$content2writre=$conf["inputString"][$index];
226 liveuser 751
 
3 liveuser 752
			#函式說明:
753
			#將字串寫入到檔案
754
			#回傳結果:
755
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
756
			#$result["error"],錯誤訊息陣列.
757
			#$result["function"],當前執行的函數名稱.
758
			#$result["fileInfo"],實際上寫入的檔案資訊陣列.
759
			#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
760
			#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
761
			#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
762
			#$result["argu"],使用的參數.
763
			#必填參數:
764
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
765
			$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
766
			#可省略參數:
767
			#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
768
			$conf["fileAccess::writeTextIntoFile"]["fileName"]=$file2writre;
769
			#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
770
			$conf["fileAccess::writeTextIntoFile"]["inputString"]=$content2writre;
771
			#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
772
			#$conf["writeMethod"]="a";
773
			#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
774
			#$conf["checkRepeat"]="";
775
			#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
776
			#$conf["filenameExtensionStartPoint"]="";
777
			#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
778
			#$conf["repeatNameRule"]="";
779
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
780
			$conf["fileAccess::writeTextIntoFile"]["web"]="false";
781
			#備註:
782
			#無.
783
			$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
784
			unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 785
 
3 liveuser 786
			#如果建立檔案失敗
787
			if($writeTextIntoFile["status"]==="false"){
226 liveuser 788
 
3 liveuser 789
				#設置錯誤識別
790
				$result["status"]="false";
226 liveuser 791
 
3 liveuser 792
				#設置錯誤訊息
793
				$result["error"]=$writeTextIntoFile;
226 liveuser 794
 
3 liveuser 795
				#回傳結果
220 liveuser 796
				return $result;
226 liveuser 797
 
3 liveuser 798
				}#if end
226 liveuser 799
 
3 liveuser 800
			#設置建立好的檔案資訊
220 liveuser 801
			$result["content"][]=$writeTextIntoFile["fileInfo"];
226 liveuser 802
 
3 liveuser 803
			}#foreach end
226 liveuser 804
 
3 liveuser 805
			#設置執行正常
806
			$result["status"]="true";
226 liveuser 807
 
3 liveuser 808
			#回傳結果
226 liveuser 809
			return $result;
810
 
3 liveuser 811
		}#function writeMultiFile end
812
 
813
	/*
814
	#函式說明:
815
	#將多行字串寫入到檔案
816
	#回傳結果:
817
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
818
	#$result["error"],錯誤訊息陣列.
819
	#$result["function"],當前執行函數的名稱.
820
	#必填參數:
821
	#$conf["fileName"],字串,爲要編輯的檔案名稱
822
	$conf["fileName"]="";
823
	#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
824
	$conf["inputString"]=array("");
825
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
826
	$conf["fileArgu"]=__FILE__;
827
	#可省略參數:
220 liveuser 828
	#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
829
	#$conf["writeMethod"]="a";
830
	#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
831
	#$conf["fastWrite"]="false";
3 liveuser 832
	#參考資料:
833
	#無.
834
	#備註:
835
	#無.
836
	*/
837
	public static function writeMultiLine(&$conf){
226 liveuser 838
 
3 liveuser 839
		#初始化要回傳的結果
840
		$result=array();
226 liveuser 841
 
3 liveuser 842
		#取得當前執行的函數
843
		$result["function"]=__FUNCTION__;
844
 
845
		#如果 $conf 不為陣列
846
		if(gettype($conf)!="array"){
226 liveuser 847
 
3 liveuser 848
			#設置執行失敗
849
			$result["status"]="false";
226 liveuser 850
 
3 liveuser 851
			#設置執行錯誤訊息
852
			$result["error"][]="\$conf變數須為陣列形態";
853
 
854
			#如果傳入的參數為 null
855
			if($conf==null){
226 liveuser 856
 
3 liveuser 857
				#設置執行錯誤訊息
858
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 859
 
3 liveuser 860
				}#if end
861
 
862
			#回傳結果
863
			return $result;
226 liveuser 864
 
3 liveuser 865
			}#if end
226 liveuser 866
 
3 liveuser 867
		#檢查必填參數
868
		#函式說明:
869
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
870
		#回傳的結果:
871
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
872
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
873
		#$result["function"],當前執行的函式名稱.
874
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
875
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
876
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
877
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
878
		#必填寫的參數:
879
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
880
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileName","inputString","fileArgu");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
881
		#可以省略的參數:
226 liveuser 882
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","array","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 883
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
884
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
885
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 886
 
3 liveuser 887
		#如果檢查失敗
888
		if($checkResult["status"]=="false"){
226 liveuser 889
 
3 liveuser 890
			#設置執行錯誤
891
			$result["status"]="false";
226 liveuser 892
 
3 liveuser 893
			#設置執行錯誤訊息
894
			$result["error"]=$checkResult;
226 liveuser 895
 
3 liveuser 896
			#回傳結果
897
			return $result;
226 liveuser 898
 
3 liveuser 899
			}#if end
226 liveuser 900
 
3 liveuser 901
		#如果檢查不通過
902
		if($checkResult["passed"]=="false"){
226 liveuser 903
 
3 liveuser 904
			#設置執行錯誤
905
			$result["status"]="false";
226 liveuser 906
 
3 liveuser 907
			#設置執行錯誤訊息
908
			$result["error"]=$checkResult;
226 liveuser 909
 
3 liveuser 910
			#回傳結果
911
			return $result;
226 liveuser 912
 
3 liveuser 913
			}#if end
226 liveuser 914
 
915
		#檢查可省略參數
3 liveuser 916
		#函式說明:
917
		#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
918
		#回傳結果:
919
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
920
		#$result["error"],錯誤訊息陣列.
921
		#$result["function"],當前執行的函式名稱.
922
		#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
923
		#必填參數:
924
		#$conf["variableCheck.checkSkipableVarType"]["checkedVar"],陣列,要檢查的變數陣列名稱為?
925
		$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf;
926
		#$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
220 liveuser 927
		$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array("writeMethod","fastWrite");
3 liveuser 928
		#$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
220 liveuser 929
		$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array("string","string");
3 liveuser 930
		#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
931
		$argu=&$conf;
932
		#可省略參數:
933
		#$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"],字串陣列,每個不存的變數要初始化為什麼,"null"代表不指定.
220 liveuser 934
		$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array("w","false");
3 liveuser 935
		#無
936
		$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
937
		unset($conf["variableCheck.checkSkipableVarType"]);
226 liveuser 938
 
3 liveuser 939
		#如果檢查不通過
940
		if($checkResult["status"]=="false"){
226 liveuser 941
 
3 liveuser 942
			#設置執行錯誤
943
			$result["status"]="false";
226 liveuser 944
 
3 liveuser 945
			#設置執行錯誤訊息
946
			$result["error"]=$checkResult;
226 liveuser 947
 
3 liveuser 948
			#回傳結果
949
			return $result;
226 liveuser 950
 
3 liveuser 951
			}#if end
226 liveuser 952
 
3 liveuser 953
		#如果檢查不通過
954
		if($checkResult["passed"]=="false"){
226 liveuser 955
 
3 liveuser 956
			#設置執行錯誤
957
			$result["status"]="false";
226 liveuser 958
 
3 liveuser 959
			#設置執行錯誤訊息
960
			$result["error"]=$checkResult;
226 liveuser 961
 
3 liveuser 962
			#回傳結果
963
			return $result;
226 liveuser 964
 
3 liveuser 965
			}#if end
966
 
220 liveuser 967
		#如果有設置快速寫入
968
		if($conf["fastWrite"]==="true"){
226 liveuser 969
 
220 liveuser 970
			#初始化要寫入的字串
971
			$inputStrAll="";
226 liveuser 972
 
220 liveuser 973
			#有幾行字要寫就執行幾次
974
			foreach($conf["inputString"] as $inputStr){
975
 
976
				#附加 "\r\n"
977
				$inputStrAll=$inputStrAll.$inputStr.PHP_EOL;
978
 
979
				}#foreach end
226 liveuser 980
 
220 liveuser 981
			#函式說明:
982
			#將字串寫入到檔案
983
			#回傳結果:
984
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
985
			#$result["error"],錯誤訊息陣列.
986
			#必填參數:
987
			$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
988
			$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStrAll;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
989
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
990
			$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
991
			#可省略參數:
992
			$conf["fileAccess.writeTextIntoFile"]["writeMethod"]=$conf["writeMethod"];#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
993
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
994
			$conf["fileAccess.writeTextIntoFile"]["web"]="false";
995
			$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
996
			unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 997
 
220 liveuser 998
			#如果寫入失敗
999
			if($writeStatus["status"]=="false"){
226 liveuser 1000
 
220 liveuser 1001
				#設置執行錯誤
1002
				$result["status"]="false";
226 liveuser 1003
 
220 liveuser 1004
				#設置執行錯誤訊息
1005
				$result["error"]=$writeStatus;
226 liveuser 1006
 
220 liveuser 1007
				#回傳結果
1008
				return $result;
226 liveuser 1009
 
220 liveuser 1010
				}#if end
226 liveuser 1011
 
220 liveuser 1012
			#設置執行正常
1013
			$result["status"]="true";
226 liveuser 1014
 
220 liveuser 1015
			#回傳結果
1016
			return $result;
226 liveuser 1017
 
220 liveuser 1018
			}#if end
1019
 
3 liveuser 1020
		#初始化第一次寫入識別變數
1021
		$firstTimeToWrite="true";
226 liveuser 1022
 
3 liveuser 1023
		#有幾行字要寫就執行幾次
1024
		foreach($conf["inputString"] as $inputStr){
1025
 
1026
			#附加 "\r\n"
1027
			$inputStr=$inputStr.PHP_EOL;
1028
 
1029
			#如果是第一次寫入
1030
			if($firstTimeToWrite=="true"){
226 liveuser 1031
 
3 liveuser 1032
				#如果是要重新寫入
220 liveuser 1033
				if($conf["writeMethod"]==="w"){
226 liveuser 1034
 
3 liveuser 1035
					#函式說明:
1036
					#將字串寫入到檔案
1037
					#回傳結果:
1038
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1039
					#$result["error"],錯誤訊息陣列.
1040
					#必填參數:
1041
					$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
1042
					$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStr;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1043
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1044
					$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1045
					#可省略參數:
1046
					$conf["fileAccess.writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1047
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1048
					$conf["fileAccess.writeTextIntoFile"]["web"]="false";
1049
					$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
1050
					unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 1051
 
3 liveuser 1052
					#如果寫入失敗
1053
					if($writeStatus["status"]=="false"){
226 liveuser 1054
 
3 liveuser 1055
						#設置執行錯誤
1056
						$result["status"]="false";
226 liveuser 1057
 
3 liveuser 1058
						#設置執行錯誤訊息
1059
						$result["error"]=$writeStatus;
226 liveuser 1060
 
3 liveuser 1061
						#回傳結果
1062
						return $result;
226 liveuser 1063
 
3 liveuser 1064
						}#if end
226 liveuser 1065
 
3 liveuser 1066
					}#if end
226 liveuser 1067
 
3 liveuser 1068
				#反之不是重新寫入,而是附加寫入。
1069
				else{
226 liveuser 1070
 
3 liveuser 1071
					#函式說明:
1072
					#將字串寫入到檔案
1073
					#回傳結果:
1074
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1075
					#$result["error"],錯誤訊息陣列.
1076
					#必填參數:
1077
					$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
1078
					$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStr;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1079
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1080
					$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1081
					#可省略參數:
1082
					$conf["fileAccess.writeTextIntoFile"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1083
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1084
					$conf["fileAccess.writeTextIntoFile"]["web"]="false";
1085
					$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
1086
					unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 1087
 
3 liveuser 1088
					#如果寫入失敗
1089
					if($writeStatus["status"]=="false"){
226 liveuser 1090
 
3 liveuser 1091
						#設置執行錯誤
1092
						$result["status"]="false";
226 liveuser 1093
 
3 liveuser 1094
						#設置執行錯誤訊息
1095
						$result["error"]=$writeStatus;
226 liveuser 1096
 
3 liveuser 1097
						#回傳結果
1098
						return $result;
226 liveuser 1099
 
3 liveuser 1100
						}#if end
226 liveuser 1101
 
3 liveuser 1102
					}#else end
226 liveuser 1103
 
3 liveuser 1104
				#將之設為不是第一次寫入
1105
				$firstTimeToWrite="false";
226 liveuser 1106
 
3 liveuser 1107
				}#if end
226 liveuser 1108
 
3 liveuser 1109
			#反之不是第一次寫入
1110
			else{
226 liveuser 1111
 
3 liveuser 1112
				#函式說明:
1113
				#將字串寫入到檔案
1114
				#回傳結果:
1115
				#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1116
				#$result["error"],錯誤訊息陣列.
1117
				#必填參數:
1118
				$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
1119
				$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStr;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1120
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1121
				$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1122
				#可省略參數:
1123
				$conf["fileAccess.writeTextIntoFile"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1124
				#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1125
				$conf["fileAccess.writeTextIntoFile"]["web"]="false";
1126
				$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
1127
				unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 1128
 
3 liveuser 1129
				#如果寫入失敗
1130
				if($writeStatus["status"]=="false"){
226 liveuser 1131
 
3 liveuser 1132
					#設置執行錯誤
1133
					$result["status"]="false";
226 liveuser 1134
 
3 liveuser 1135
					#設置執行錯誤訊息
1136
					$result["error"]=$writeStatus;
226 liveuser 1137
 
3 liveuser 1138
					#回傳結果
1139
					return $result;
226 liveuser 1140
 
3 liveuser 1141
					}#if end
226 liveuser 1142
 
3 liveuser 1143
				}#else end
226 liveuser 1144
 
3 liveuser 1145
			}#foreach end
226 liveuser 1146
 
3 liveuser 1147
		#執行到這邊代表一切正常
1148
		$result["status"]="true";
226 liveuser 1149
 
3 liveuser 1150
		#回傳結果
1151
		return $result;
226 liveuser 1152
 
3 liveuser 1153
		}#function writeMultiLine end
226 liveuser 1154
 
3 liveuser 1155
	/*
1156
	#函式說明:
1157
	#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1158
	#回傳的變數說明:
1159
	#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1160
	#$result["error"],錯誤訊息提示.
374 liveuser 1161
	#$result["fileNotExist"],字串,"true"代表目標檔案不存在;"false"代表目標檔案存在.
1162
	#$result["fileCreated"],字串,"true"代表目標檔案被本函式建立;"false"代表檔案不是透過本函式建立.
3 liveuser 1163
	#$result["function"],當前執行的函數名稱.
1164
	#$result["fileContent"],爲檔案的內容陣列.
1165
	#$result["lineCount"],爲檔案內容總共的行數.
1166
	#$result["fullContent"],為檔案的完整內容.
200 liveuser 1167
	#$result["base64dataOnly"],檔案的base64data.
1168
	#$result["base64data"],為在網頁上給予src參數的數值.
3 liveuser 1169
	#$result["mimeType"],為檔案的mime type.
1170
	#必填參數:
1171
	#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
1172
	$conf["filePositionAndName"]="";
1173
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1174
	$conf["fileArgu"]=__FILE__;
1175
	#可省略參數:
1176
	#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
1177
	#$conf["web"]="true";
1178
	#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
1179
	#$conf["createIfnotExist"]="false";
1180
	#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
1181
	#$conf["autoDeleteSpaceOnEachLineStart"]="false";
391 liveuser 1182
	#$conf["disableReturnBase64"],字串,預設為"false"代表要回傳base64結果,反之為"true".
1183
	#$conf["disableReturnBase64"]="false";
3 liveuser 1184
	#參考資料:
1185
	#file(),取得檔案內容的行數.
1186
	#file=>http:#php.net/manual/en/function.file.php
1187
	#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1188
	#filesize=>http://php.net/manual/en/function.filesize.php
1189
	#參考資料:
1190
	#無.
1191
	#備註:
1192
	#無.
1193
	*/
249 liveuser 1194
	public static function getFileContent(&$conf){
3 liveuser 1195
 
1196
		#初始化要回傳的內容
1197
		$result=array();
226 liveuser 1198
 
3 liveuser 1199
		#取得當前執行函數名稱
1200
		$result["function"]=__FUNCTION__;
374 liveuser 1201
 
1202
		#設置預設檔案不存在的識別
376 liveuser 1203
		$result["fileNotExist"]="true";
374 liveuser 1204
 
1205
		#設置預設檔案不為本函式所建立
1206
		$result["fileCreated"]="false";
3 liveuser 1207
 
1208
		#如果 $conf 不為陣列
1209
		if(gettype($conf)!="array"){
226 liveuser 1210
 
3 liveuser 1211
			#設置執行失敗
1212
			$result["status"]="false";
226 liveuser 1213
 
3 liveuser 1214
			#設置執行錯誤訊息
1215
			$result["error"][]="\$conf變數須為陣列形態";
1216
 
1217
			#如果傳入的參數為 null
1218
			if($conf==null){
226 liveuser 1219
 
3 liveuser 1220
				#設置執行錯誤訊息
1221
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1222
 
3 liveuser 1223
				}#if end
1224
 
1225
			#回傳結果
1226
			return $result;
226 liveuser 1227
 
3 liveuser 1228
			}#if end
1229
 
1230
		#檢查參數
1231
		#函式說明:
1232
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
1233
		#回傳結果:
1234
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1235
		#$result["error"],執行不正常結束的錯訊息陣列.
1236
		#$result["simpleError"],簡單表示的錯誤訊息.
1237
		#$result["function"],當前執行的函式名稱.
1238
		#$result["argu"],設置給予的參數.
1239
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1240
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1241
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1242
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1243
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1244
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1245
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1246
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1247
		#必填參數:
1248
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1249
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1250
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1251
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1252
		#可省略參數:
1253
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1254
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePositionAndName","fileArgu");
1255
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
1256
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
1257
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1258
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1259
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
1260
		#$conf["canNotBeEmpty"]=array();
1261
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
1262
		#$conf["canBeEmpty"]=array();
1263
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
391 liveuser 1264
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("createIfnotExist","web","autoDeleteSpaceOnEachLineStart","disableReturnBase64");
3 liveuser 1265
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
391 liveuser 1266
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("createIfnotExist","web","autoDeleteSpaceOnEachLineStart","disableReturnBase64");
3 liveuser 1267
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
391 liveuser 1268
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
3 liveuser 1269
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
391 liveuser 1270
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false","false");
3 liveuser 1271
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
1272
		#$conf["disallowAllSkipableVarIsEmpty"]="";
1273
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
1274
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
1275
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
1276
		#$conf["disallowAllSkipableVarNotExist"]="";
1277
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1278
		#$conf["arrayCountEqualCheck"][]=array();
1279
		#參考資料:
1280
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1281
		#備註:
1282
		#無.
1283
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1284
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 1285
 
3 liveuser 1286
		#如果檢查出錯
1287
		if($checkArguments["status"]==="false"){
226 liveuser 1288
 
3 liveuser 1289
			#設置執行錯誤識別
1290
			$result["status"]="false";
226 liveuser 1291
 
3 liveuser 1292
			#設置執行錯誤訊息
1293
			$result["error"]=$checkArguments;
226 liveuser 1294
 
3 liveuser 1295
			#回傳結果
1296
			return $result;
226 liveuser 1297
 
3 liveuser 1298
			}#if end
226 liveuser 1299
 
3 liveuser 1300
		#如果檢查參數不通過
1301
		if($checkArguments["passed"]==="false"){
226 liveuser 1302
 
3 liveuser 1303
			#設置執行錯誤識別
1304
			$result["status"]="false";
226 liveuser 1305
 
3 liveuser 1306
			#設置執行錯誤訊息
1307
			$result["error"]=$checkArguments;
226 liveuser 1308
 
3 liveuser 1309
			#回傳結果
1310
			return $result;
226 liveuser 1311
 
3 liveuser 1312
			}#if end
226 liveuser 1313
 
3 liveuser 1314
		#檢查檔案是否存在
1315
		#函式說明:檢查多個檔案與資料夾是否存在
1316
		#回傳的結果:
1317
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1318
		#$result["error"],錯誤訊息陣列.
1319
		#$resutl["function"],當前執行的涵式名稱.
1320
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1321
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
1322
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1323
		#必填參數:
1324
		$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($conf["filePositionAndName"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
1325
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1326
		$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
1327
		#可省略參數:
1328
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1329
		$conf["fileAccess"]["checkMutiFileExist"]["disableWebSearch"]="true";
226 liveuser 1330
 
3 liveuser 1331
		#如果有設置 $conf["web"]
1332
		if(isset($conf["web"])){
226 liveuser 1333
 
3 liveuser 1334
			#設置 web 參數.
1335
			$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
226 liveuser 1336
 
3 liveuser 1337
			}#if end
226 liveuser 1338
 
3 liveuser 1339
		#參考資料來源:
1340
		#http:#php.net/manual/en/function.file-exists.php
1341
		#http:#php.net/manual/en/control-structures.foreach.php
1342
		$fileCheckResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
1343
		unset($conf["fileAccess"]["checkMutiFileExist"]);
1344
 
1345
		#如果檢查檔案是否存在出錯
1346
		if($fileCheckResult["status"]=="false"){
226 liveuser 1347
 
3 liveuser 1348
			#設置執行錯誤識別
1349
			$result["status"]="false";
226 liveuser 1350
 
3 liveuser 1351
			#設置執行錯誤訊息
1352
			$result["error"]=$fileCheckResult;
226 liveuser 1353
 
3 liveuser 1354
			#回傳結果
1355
			return $result;
226 liveuser 1356
 
3 liveuser 1357
			}#if end
1358
 
1359
		#如果該檔案不存在
1360
		if($fileCheckResult["varExist"][0]=="false"){
226 liveuser 1361
 
3 liveuser 1362
			#如果也不要自動建立檔案
1363
			if($conf["createIfnotExist"]==="false"){
226 liveuser 1364
 
3 liveuser 1365
				#設置執行錯誤識別
1366
				$result["status"]="false";
226 liveuser 1367
 
3 liveuser 1368
				#設置執行錯誤訊息
1369
				$result["error"]=$fileCheckResult;
226 liveuser 1370
 
3 liveuser 1371
				#設置易讀的錯誤訊息
1372
				$result["error"][]="名為".$fileCheckResult["varName"][0]."的檔案不存在";
226 liveuser 1373
 
3 liveuser 1374
				#回傳結果
1375
				return $result;
226 liveuser 1376
 
3 liveuser 1377
				}#if end
226 liveuser 1378
 
3 liveuser 1379
			#執行到這邊代表需要建立該檔案
1380
			#函式說明:
1381
			#將字串寫入到檔案
1382
			#回傳結果:
1383
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1384
			#$result["error"],錯誤訊息陣列.
1385
			#$result["function"],當前執行的函數名稱.
1386
			#$result["fileInfo"],實際上寫入的檔案資訊陣列.
1387
			#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
1388
			#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
1389
			#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
1390
			#$result["argu"],使用的參數.
1391
			#必填參數:
1392
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1393
			$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1394
			#可省略參數:
1395
			#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
1396
			$conf["fileAccess::writeTextIntoFile"]["fileName"]=$fileCheckResult["varNameFullPath"][0];
1397
			#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
200 liveuser 1398
			$conf["fileAccess::writeTextIntoFile"]["inputString"]="";
3 liveuser 1399
			#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
1400
			#$conf["checkRepeat"]="";
1401
			#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
1402
			#$conf["filenameExtensionStartPoint"]="";
1403
			#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
1404
			#$conf["repeatNameRule"]="";
226 liveuser 1405
 
3 liveuser 1406
			#如果有設置 $conf["web"]
1407
			if(isset($conf["web"])){
226 liveuser 1408
 
3 liveuser 1409
				#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1410
				$conf["fileAccess::writeTextIntoFile"]["web"]=$conf["web"];
226 liveuser 1411
 
200 liveuser 1412
				}#if end
226 liveuser 1413
 
3 liveuser 1414
			#參考資料:
1415
			#無.
1416
			#備註:
1417
			#無.
1418
			$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
1419
			unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 1420
 
3 liveuser 1421
			#如果建立檔案失敗
1422
			if($writeTextIntoFile["status"]=="false"){
226 liveuser 1423
 
3 liveuser 1424
				#設置執行錯誤識別
1425
				$result["status"]="false";
226 liveuser 1426
 
3 liveuser 1427
				#設置執行錯誤訊息
1428
				$result["error"]=$writeTextIntoFile;
226 liveuser 1429
 
3 liveuser 1430
				#回傳結果
1431
				return $result;
226 liveuser 1432
 
3 liveuser 1433
				}#if end
374 liveuser 1434
 
1435
			#設置檔案存在的識別
376 liveuser 1436
			$result["fileNotExist"]="false";
374 liveuser 1437
 
1438
			#設置檔案為本函式所建立
1439
			$result["fileCreated"]="true";
226 liveuser 1440
 
3 liveuser 1441
			}#if end
374 liveuser 1442
 
1443
		#反之
1444
		else{
1445
 
1446
			#設置檔案存在的識別
376 liveuser 1447
			$result["fileNotExist"]="false";
374 liveuser 1448
 
1449
			}#else end
3 liveuser 1450
 
1451
		#file absolute addr
1452
		$fileAbAddr=$fileCheckResult["varNameFullPath"][0];
226 liveuser 1453
 
3 liveuser 1454
		#將檔案的內容放進變數裡面(會得到陣列)
1455
		$fileContent=file($fileAbAddr);
1456
 
1457
		#如果 $fileContent 等於
376 liveuser 1458
		if($fileContent===FALSE){
3 liveuser 1459
 
376 liveuser 1460
			#設置錯誤識別
1461
			$result["status"]="false";
226 liveuser 1462
 
376 liveuser 1463
			#設置錯誤訊息
1464
			$result["error"][]="讀取檔案失敗";
3 liveuser 1465
 
376 liveuser 1466
			#取得詳細的錯誤訊息
1467
			$result["error"][]=$fileCheckResult;
226 liveuser 1468
 
376 liveuser 1469
			#回傳結果
1470
			return $result;
3 liveuser 1471
 
1472
			}#if end
1473
 
1474
		#針對每行內容
1475
		for($i=0;$i<count($fileContent);$i++){
226 liveuser 1476
 
3 liveuser 1477
			#剔除字串尾的換行符號
1478
			$fileContent[$i]=rtrim($fileContent[$i]);
226 liveuser 1479
 
3 liveuser 1480
			#如果要移除開頭的空白
1481
			if($conf["autoDeleteSpaceOnEachLineStart"]==="true"){
226 liveuser 1482
 
3 liveuser 1483
				#如果開頭是空格
1484
				while(strpos($fileContent[$i]," ")===0){
226 liveuser 1485
 
3 liveuser 1486
					#函式說明:
1487
					#將字串特定關鍵字與其前面的內容剔除
1488
					#回傳結果:
1489
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1490
					#$result["error"],錯誤訊息陣列.
1491
					#$result["warning"],警告訊息鎮列.
1492
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
1493
					#$result["function"],當前執行的函數名稱.
1494
					#$result["argu"],使用的參數.
1495
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 1496
					#$result["content"],處理好的的字串內容.
3 liveuser 1497
					#必填參數:
1498
					#$conf["stringIn"],字串,要處理的字串.
1499
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$fileContent[$i];
1500
					#$conf["keyWord"],字串,特定字串.
1501
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
1502
					#可省略參數:
1503
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
1504
					#$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
1505
					#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
1506
					#$conf["lastResult"]=$delStrBeforeKeyWord;
1507
					#參考資料:
1508
					#無.
1509
					#備註:
1510
					#無.
1511
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
1512
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 1513
 
3 liveuser 1514
					#如果建立檔案失敗
1515
					if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 1516
 
3 liveuser 1517
						#設置執行錯誤識別
1518
						$result["status"]="false";
226 liveuser 1519
 
3 liveuser 1520
						#設置執行錯誤訊息
1521
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 1522
 
3 liveuser 1523
						#回傳結果
1524
						return $result;
226 liveuser 1525
 
3 liveuser 1526
						}#if end
226 liveuser 1527
 
3 liveuser 1528
					#取得剔除開頭空格後的內容
1529
					$fileContent[$i]=$delStrBeforeKeyWord["content"];
226 liveuser 1530
 
3 liveuser 1531
					}#while end
226 liveuser 1532
 
3 liveuser 1533
				}#if end
226 liveuser 1534
 
3 liveuser 1535
			}#for end
1536
 
1537
		#取得總共有幾行
1538
		$lineCount=count($fileContent);
1539
 
1540
		#將檔案內容的陣列放進 $result 陣列變數裏面
1541
		$result["fileContent"]=$fileContent;
226 liveuser 1542
 
3 liveuser 1543
		#建立暫存檔案
1544
		$tmpFile=tempnam("/tmp", "qbpwcf");
226 liveuser 1545
 
3 liveuser 1546
		#讀取要取得的檔案內容
1547
		$content=file_get_contents($fileAbAddr);
226 liveuser 1548
 
3 liveuser 1549
		#開啟暫存檔案(寫入模式)
1550
		$file=fopen($tmpFile,'w');
226 liveuser 1551
 
3 liveuser 1552
		#寫入讀取到的內容
1553
		fwrite($file,$content);
226 liveuser 1554
 
3 liveuser 1555
		#關閉暫存檔案
1556
		fclose($file);
226 liveuser 1557
 
3 liveuser 1558
		#取得檔案的 mime 類型
1559
		$mimeType=mime_content_type($tmpFile);
226 liveuser 1560
 
3 liveuser 1561
		#設置檔案的mime類型
1562
		$result["mimeType"]=$mimeType;
226 liveuser 1563
 
3 liveuser 1564
		#取得檔案的內容為字串
1565
		$result["fullContent"]=file_get_contents($tmpFile);
226 liveuser 1566
 
391 liveuser 1567
		#如果沒有要停用回傳base64結果
1568
		if($conf["disableReturnBase64"]==="false"){
226 liveuser 1569
 
391 liveuser 1570
			#取得檔案的base64data
1571
			$result["base64dataOnly"]=base64_encode($result["fullContent"]);
226 liveuser 1572
 
391 liveuser 1573
			#取得檔案用 data:mimeType;base64,base64data 表示的字串
1574
			$result["base64data"]="data:".$result["mimeType"].";base64,".$result["base64dataOnly"];
1575
 
1576
			}#if end
1577
 
3 liveuser 1578
		#移除暫存檔案
1579
		unlink($tmpFile);
226 liveuser 1580
 
3 liveuser 1581
		#將檔案內容的行數放進 $result 陣列變數裏面
1582
		$result["lineCount"]=$lineCount;
1583
 
1584
		#執行到這邊代表執行成功
1585
		$result["status"]="true";
1586
 
1587
		#回傳結果
1588
		return $result;
1589
 
1590
		}#function getFileContent end
1591
 
1592
	/*
1593
	#函式說明:
1594
	#依據逗號分隔抓取檔案的內容,結果會回傳一個陣列
226 liveuser 1595
	#回傳結果:
3 liveuser 1596
	#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1597
	#$result["error"],錯誤訊息提示.
1598
	#$result["function"],函數名稱.
1599
	#$result["lineCount"]爲總共有幾行
1600
	#$result["lineContent"][i]["dataCounts"],爲第 i+1 行總共有幾個字串
1601
	#$result["lineContent"][0][i],爲第1行第 i+1 個分割好的字串
1602
	#$result["lineContent"][1][i],爲第2行第 i+1 個分割好的字串
1603
	#必填參數:
1604
	#$conf["filePositionAndName"],字串,要抓取的檔案位置與名稱
1605
	$conf["filePositionAndName"]="";
1606
	#可省略參數:
1607
	#$conf["spiltSign"],字串,爲要用來分割字串的符號,可省略,預設爲「,」
1608
	#$conf["spiltSign"]="";
1609
	#參考資料:
1610
	#無.
1611
	#備註:
1612
	#無.
1613
	*/
249 liveuser 1614
	public static function getFileContentSpiltBySomething(&$conf){
3 liveuser 1615
 
1616
		#初始化要回傳的內容
1617
		$result=array();
226 liveuser 1618
 
3 liveuser 1619
		#取得當前執行函數名稱
1620
		$result["function"]=__FUNCTION__;
1621
 
1622
		#如果 $conf 不為陣列
1623
		if(gettype($conf)!="array"){
226 liveuser 1624
 
3 liveuser 1625
			#設置執行失敗
1626
			$result["status"]="false";
226 liveuser 1627
 
3 liveuser 1628
			#設置執行錯誤訊息
1629
			$result["error"][]="\$conf變數須為陣列形態";
1630
 
1631
			#如果傳入的參數為 null
1632
			if($conf==null){
226 liveuser 1633
 
3 liveuser 1634
				#設置執行錯誤訊息
1635
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1636
 
3 liveuser 1637
				}#if end
1638
 
1639
			#回傳結果
1640
			return $result;
226 liveuser 1641
 
3 liveuser 1642
			}#if end
1643
 
1644
		#如果 $conf["spiltSign"] 爲空,則預設爲","。
1645
		if(!isset($conf["spiltSign"])){
1646
 
1647
			$conf["spiltSign"]=",";
1648
 
1649
			}#if end
1650
 
1651
		#依據行號抓取所有的內容
1652
		#函式說明:
1653
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1654
		#回傳的變數說明:
1655
		#$result["fileContent"],爲檔案的內容陣列
1656
		#$result["lineCount"],爲檔案內容總共的行數
1657
		#必填參數:
1658
		$conf["fileAccess"]["getFileContent"]["filePositionAndName"]=$conf["filePositionAndName"];#爲檔案的位置以及名稱
1659
		#參考資料:
1660
		#file():取得檔案內容的行數
1661
		#http:#php.net/manual/en/function.file.php
1662
		$fileContent=fileAccess::getFileContent($conf["fileAccess"]["getFileContent"]);
1663
		unset($conf["fileAccess"]["getFileContent"]);
1664
 
1665
		#如果取得檔案內容失敗
1666
		if($fileContent["status"]=="false"){
226 liveuser 1667
 
3 liveuser 1668
			#設置執行失敗
1669
			$result["status"]="false";
226 liveuser 1670
 
3 liveuser 1671
			#設置執行錯誤訊息
1672
			$result["error"]=$fileContent;
1673
 
1674
			#回傳結果
1675
			return $result;
226 liveuser 1676
 
3 liveuser 1677
			}#if end
1678
 
1679
		#迴圈,有幾行資料就執行幾次
1680
		for($i=0;$i<$fileContent["lineCount"];$i++){
1681
 
1682
			#將該行內容用逗號分隔
1683
			$conf["stringProcess"]["spiltString"]["stringIn"]=$fileContent["fileContent"][$i];#要處理的字串。
1684
			$conf["stringProcess"]["spiltString"]["spiltSymbol"]=$conf["spiltSign"];#爲以哪個符號作爲分割
1685
			$lineSpiltResult[$i]=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
226 liveuser 1686
			unset($conf["stringProcess"]["spiltString"]);
3 liveuser 1687
 
1688
			#如果分割字串失敗
1689
			if($lineSpiltResult[$i]["status"]=="false"){
226 liveuser 1690
 
3 liveuser 1691
				#設置執行失敗
1692
				$result["status"]="false";
226 liveuser 1693
 
3 liveuser 1694
				#設置執行錯誤訊息
1695
				$result["error"]=$lineSpiltResult[$i];
1696
 
1697
				#回傳結果
1698
				return $result;
226 liveuser 1699
 
3 liveuser 1700
				}#if end
1701
 
1702
			}#for end
1703
 
1704
		#取得
1705
		$result["lineContent"]=$lineSpiltResult;
1706
 
1707
		#取得資料的行數
1708
		$result["lineCount"]=$fileContent["lineCount"];
1709
 
1710
		#回傳結果
1711
		return $result;
226 liveuser 1712
 
3 liveuser 1713
		}#function getFileContentSpiltBySomething end
1714
 
1715
	/*
1716
	#函式說明:
1717
	#檢查多個檔案與資料夾是否存在.
1718
	#回傳的結果:
1719
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1720
	#$result["error"],錯誤訊息陣列.
1721
	#$resutl["function"],當前執行的涵式名稱.
1722
	#$result["argu"],使用的參數.
1723
	#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1724
	#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
1725
	#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
1726
	#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
1727
	#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1728
	#必填參數:
1729
	#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
1730
	$conf["fileArray"]=array();
1731
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1732
	$conf["fileArgu"]=__FILE__;
1733
	#可省略參數:
1734
	#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1735
	#$conf["disableWebSearch"]="false";
1736
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
1737
	#$conf["userDir"]="true";
1738
	#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
1739
	#$conf["web"]="true";
1740
	#參考資料:
1741
	#http://php.net/manual/en/function.file-exists.php
1742
	#http://php.net/manual/en/control-structures.foreach.php
1743
	#備註:
1744
	#函數file_exists檢查的路徑為檔案系統的路徑
1745
	#$result["varName"][$i]結果未實作
1746
	*/
1747
	public static function checkMultiFileExist(&$conf){
226 liveuser 1748
 
3 liveuser 1749
		#初始化要回傳的變數
1750
		$result=array();
226 liveuser 1751
 
3 liveuser 1752
		#設置當前執行的涵式
1753
		$result["function"]=__FUNCTION__;
226 liveuser 1754
 
3 liveuser 1755
		#如果 $conf 不為陣列
1756
		if(gettype($conf)!="array"){
226 liveuser 1757
 
3 liveuser 1758
			#設置執行失敗
1759
			$result["status"]="false";
226 liveuser 1760
 
3 liveuser 1761
			#設置執行錯誤訊息
1762
			$result["error"][]="\$conf變數須為陣列形態";
1763
 
1764
			#如果傳入的參數為 null
1765
			if($conf==null){
226 liveuser 1766
 
3 liveuser 1767
				#設置執行錯誤訊息
1768
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1769
 
3 liveuser 1770
				}#if end
1771
 
1772
			#回傳結果
1773
			return $result;
226 liveuser 1774
 
3 liveuser 1775
			}#if end
226 liveuser 1776
 
3 liveuser 1777
		#取得使用的參數
1778
		$result["argu"]=$conf;
226 liveuser 1779
 
3 liveuser 1780
		#檢查參數
1781
		#函式說明:
1782
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1783
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1784
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1785
		#$result["function"],當前執行的函式名稱.
1786
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1787
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1788
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1789
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
1790
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1791
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1792
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1793
		#必填寫的參數:
1794
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1795
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1796
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1797
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArray","fileArgu");
226 liveuser 1798
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 1799
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
1800
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1801
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1802
		#可以省略的參數:
1803
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1804
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1805
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1806
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("disableWebSearch","userDir","web");
226 liveuser 1807
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 1808
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1809
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1810
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true","true","true");
1811
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1812
		#$conf["arrayCountEqualCheck"][]=array();
1813
		#參考資料來源:
1814
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1815
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1816
		unset($conf["variableCheck::checkArguments"]);
1817
 
1818
		#如果 $checkArguments["status"] 等於 "false"
1819
		if($checkArguments["status"]=="false"){
226 liveuser 1820
 
3 liveuser 1821
			#設置錯誤識別
1822
			$result["status"]="false";
226 liveuser 1823
 
3 liveuser 1824
			#設置錯誤訊息
1825
			$result["error"]=$checkArguments;
226 liveuser 1826
 
3 liveuser 1827
			#回傳結果
42 liveuser 1828
			return $result;
226 liveuser 1829
 
3 liveuser 1830
			}#if end
226 liveuser 1831
 
3 liveuser 1832
		#如果 $checkArguments["passed"] 等於 "false"
1833
		if($checkArguments["passed"]=="false"){
226 liveuser 1834
 
3 liveuser 1835
			#設置錯誤識別
1836
			$result["status"]="false";
226 liveuser 1837
 
3 liveuser 1838
			#設置錯誤訊息
1839
			$result["error"]=$checkArguments;
226 liveuser 1840
 
3 liveuser 1841
			#回傳結果
42 liveuser 1842
			return $result;
226 liveuser 1843
 
3 liveuser 1844
			}#if end
226 liveuser 1845
 
3 liveuser 1846
		#初始化儲存每個檔案是否存在的陣列變數
1847
		$result["varName"]=array();
1848
		$result["varExist"]=array();
1849
 
1850
		#針對每個要檢查的檔案
1851
		foreach($conf["fileArray"] as $i=>$varName){
226 liveuser 1852
 
3 liveuser 1853
			#儲存要判斷是否存在的物件
1854
			$result["varName"][]=$varName;
226 liveuser 1855
 
3 liveuser 1856
			#函式說明:
1857
			#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
1858
			#回傳結果:
1859
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1860
			#$result["error"],錯誤訊息陣列.
226 liveuser 1861
			#$result["function"],函數名稱.
3 liveuser 1862
			#$result["argu"],使用的參數.
1863
			#$result["content"],網址,若是在命令列執行,則為"null".
1864
			#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
1865
			#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
1866
			#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
1867
			#必填參數:
1868
			#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
1869
			$conf["fileAccess::getInternetAddressV2"]["address"]=$varName;
1870
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1871
			$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
1872
			#可省略參數:
1873
			$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
1874
			#備註:
1875
			#建構中,fileSystemRelativePosition尚未實作.
1876
			$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
1877
			unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 1878
 
3 liveuser 1879
			#如果轉換成絕對路徑失敗
1880
			if($getInternetAddressV2["status"]=="false"){
226 liveuser 1881
 
3 liveuser 1882
				#設置錯誤識別
1883
				$result["status"]="false";
226 liveuser 1884
 
3 liveuser 1885
				#設置錯誤訊息
1886
				$result["error"]=$getInternetAddressV2;
226 liveuser 1887
 
3 liveuser 1888
				#回傳結果
1889
				return $result;
226 liveuser 1890
 
3 liveuser 1891
				}#if end
226 liveuser 1892
 
3 liveuser 1893
			#傳參考
1894
			$getInternetAddress=&$getInternetAddressV2;
226 liveuser 1895
 
3 liveuser 1896
			#如果沒有檔案的絕對路徑位置
1897
			if(!isset($getInternetAddress["fileSystemAbsoulutePosition"])){
226 liveuser 1898
 
3 liveuser 1899
				#置換成給予的參數網址
1900
				$conf["fileArray"][$i]=$getInternetAddress["content"];
226 liveuser 1901
 
3 liveuser 1902
				#設置無法從檔案系統找到
1903
				$exist=FALSE;
226 liveuser 1904
 
3 liveuser 1905
				}#if end
226 liveuser 1906
 
3 liveuser 1907
			#反之取得
1908
			else{
226 liveuser 1909
 
3 liveuser 1910
				#轉換好的絕對路徑
1911
				$conf["fileArray"][$i]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 1912
 
42 liveuser 1913
				#無窮迴圈
1914
				while(true){
226 liveuser 1915
 
42 liveuser 1916
					#判斷該檔案是否存在
1917
					$exist=file_exists($conf["fileArray"][$i]);
226 liveuser 1918
 
42 liveuser 1919
					#如果不存在
1920
					if($exist===false){
226 liveuser 1921
 
42 liveuser 1922
						#無窮迴圈
1923
						while(true){
226 liveuser 1924
 
42 liveuser 1925
							#當要檢查的目標是 link 時
1926
							if(is_link($conf["fileArray"][$i])){
226 liveuser 1927
 
42 liveuser 1928
								#取得link的路徑
1929
								$conf["fileArray"][$i]=readlink($conf["fileArray"][$i]);
226 liveuser 1930
 
42 liveuser 1931
								#結束連結的判斷,回到判斷目標是否存在的地方.
1932
								continue 2;
226 liveuser 1933
 
42 liveuser 1934
								}#if end
226 liveuser 1935
 
42 liveuser 1936
							#結束連結的判斷
1937
							break;
226 liveuser 1938
 
42 liveuser 1939
							}#while end
226 liveuser 1940
 
42 liveuser 1941
						}#if end
226 liveuser 1942
 
42 liveuser 1943
					#結束到判斷目標是否存在
1944
					break;
226 liveuser 1945
 
42 liveuser 1946
					}#while end
226 liveuser 1947
 
3 liveuser 1948
				}#else end
226 liveuser 1949
 
3 liveuser 1950
			#如果 $exist 等於 false (檔案不存在) 且 沒有停用網路搜尋功能
1951
			if($exist===FALSE && $conf["disableWebSearch"]==="false"){
1952
 
1953
				#將目標轉換成網址
1954
				#函式說明:
1955
				#將檔案的位置名稱變成網址
1956
				#回傳結果:
1957
				#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1958
				#$result["error"],錯誤訊息陣列.
226 liveuser 1959
				#$result["function"],函數名稱.
3 liveuser 1960
				#$result["content"],網址.
1961
				#必填參數:
1962
				#$conf["address"],字串,檔案的相對位置.
1963
				$conf["fileAccess::getInternetAddress"]["address"]=$conf["fileArray"][$i];
1964
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1965
				$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
1966
				$getInternetAddress=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddress"]);
1967
				unset($conf["fileAccess::getInternetAddress"]);
1968
 
1969
				#如果轉換失敗
1970
				if($getInternetAddress["status"]=="false"){
226 liveuser 1971
 
3 liveuser 1972
					#設置錯誤識別
1973
					$result["status"]="false";
226 liveuser 1974
 
3 liveuser 1975
					#設置錯誤訊息
1976
					$result["error"]=$getInternetAddress;
226 liveuser 1977
 
3 liveuser 1978
					#回傳結果
226 liveuser 1979
					return $result;
1980
 
3 liveuser 1981
					}#if end
226 liveuser 1982
 
3 liveuser 1983
				#函式說明:
1984
				#運行curl cmd
1985
				#回傳結果:
1986
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1987
				#$result["error"],錯誤訊息陣列.
1988
				#$result["function"],當前執行的函式名稱.
1989
				#$result["content"],取得的回應內容.
1990
				#$result["cookie"],cookie檔案的位置與名稱.
1991
				#$result["cmd"],執行的command.
1992
				#$result["argu],使用的參數.
1993
				#必填參數:
1994
				#$conf["url"],字串,目標url.
1995
				$conf["catchWebContent::curlCmd"]["url"]=$getInternetAddress["content"];
1996
				#$conf["fileArgu"],字串,變數__FILE__的內容.
1997
				$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
1998
				#可省略參數:
1999
				#$conf["header"],字串陣列,要傳送的header.
2000
				#$conf["header"]=array();
2001
				#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
2002
				#$conf["allowAnySSLcertificate"]="";
2003
				#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
2004
				#$conf["postVar"]=array();
2005
				#$conf["rawPost"]="字串",要傳送的raw post內容.
2006
				#$conf["rawPost"]="";
2007
				#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
2008
				#$conf["urlEncode"]="false";
2009
				#$conf["agent"],字串,user agent的名稱.
2010
				#$conf["agent"]="";
2011
				#$conf["cookie"],字串,cookie位置與檔案位置.
2012
				#$conf["cookie"]="";
2013
				#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
2014
				#$conf["forceNewCookie"]="";
2015
				$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
2016
				unset($conf["catchWebContent::curlCmd"]);
226 liveuser 2017
 
3 liveuser 2018
				#如果抓取資料失敗
2019
				if($curlCmd["status"]==="false"){
226 liveuser 2020
 
3 liveuser 2021
					#設置錯誤識別
2022
					$result["status"]="false";
226 liveuser 2023
 
3 liveuser 2024
					#設置錯誤訊息
2025
					$result["error"]=$curlCmd;
226 liveuser 2026
 
3 liveuser 2027
					#回傳結果
2028
					return $result;
226 liveuser 2029
 
3 liveuser 2030
					}#if end
226 liveuser 2031
 
3 liveuser 2032
				#反之檔案存在網路上
2033
				else{
226 liveuser 2034
 
3 liveuser 2035
					#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2036
					$result["varName"][$i]=$getInternetAddress["content"];
226 liveuser 2037
 
3 liveuser 2038
					#如果存在檔案路徑的絕對位置
2039
					if(isset($getInternetAddress["fileSystemAbsoulutePosition"])){
226 liveuser 2040
 
42 liveuser 2041
						#設置該檔案的絕對路徑位置
3 liveuser 2042
						$result["varNameFullPath"][$i]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 2043
 
3 liveuser 2044
						}#if end
226 liveuser 2045
 
2046
					#反之代表輸入參數是網址
3 liveuser 2047
					else{
226 liveuser 2048
 
3 liveuser 2049
						#設置該檔案的網址
2050
						$result["varNameWebPath"][$i]=$getInternetAddress["content"];
226 liveuser 2051
 
3 liveuser 2052
						}#else end
226 liveuser 2053
 
3 liveuser 2054
					#設置有無找到的識別
2055
					$result["varExist"][$i]=$curlCmd["founded"];
226 liveuser 2056
 
3 liveuser 2057
					}#else end
226 liveuser 2058
 
3 liveuser 2059
				}#if end
2060
 
2061
			#反之檔案不存在,且停用網路搜尋.
2062
			else if($exist===FALSE){
226 liveuser 2063
 
3 liveuser 2064
				#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2065
				$result["varName"][$i]=$conf["fileArray"][$i];
2066
				$result["varNameFullPath"][$i]=$conf["fileArray"][$i];
2067
				$result["varExist"][$i]="false";
2068
 
2069
				#設置全部檔案都存在的識別變數為 "false"
2070
				$result["allExist"]="false";
226 liveuser 2071
 
3 liveuser 2072
				}#if end
2073
 
2074
			#反之代表檔案存在
2075
			else{
226 liveuser 2076
 
3 liveuser 2077
				#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2078
				$result["varNameFullPath"][$i]=$conf["fileArray"][$i];
226 liveuser 2079
 
3 liveuser 2080
				#如果 web 參數為 "true"
2081
				if($conf["web"]==="true"){
226 liveuser 2082
 
3 liveuser 2083
					#設置網路上的位置
2084
					$result["varNameWebPath"][$i]=$getInternetAddress["content"];
226 liveuser 2085
 
3 liveuser 2086
					}#if end
226 liveuser 2087
 
3 liveuser 2088
				$result["varExist"][$i]="true";
2089
 
2090
				}#else end
226 liveuser 2091
 
3 liveuser 2092
			}#foreach end
226 liveuser 2093
 
3 liveuser 2094
		#如果所有檔案與資料夾都找到的識別變數不存在
2095
		if(!isset($result["allExist"])){
226 liveuser 2096
 
3 liveuser 2097
			#設置全部檔案與資料夾都有找到
2098
			$result["allExist"]="true";
226 liveuser 2099
 
3 liveuser 2100
			}#if end
2101
 
2102
		#執行到這邊代表執行正常
2103
		$result["status"]="true";
2104
 
2105
		#回傳結果
2106
		return $result;
2107
 
2108
		}#function checkMutiFileExist
2109
 
2110
	/*
2111
	#函式說明:
2112
	#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
2113
	#回傳結果:
2114
	#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
2115
	#$result["error"],錯誤訊息陣列.
2116
	#$result["function"],當前執行的函數名稱.
2117
	#$result["argu"],使用的參數.
2118
	#$result["createdFileName"],建立好的檔案名稱.
2119
	#$result["createdFilePath"],檔案建立的路徑.
2120
	#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
2121
	#必填參數:
2122
	#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
2123
	$conf["checkedFileAndPath"]="";
2124
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2125
	$conf["fileArgu"]=__FILE__;
2126
	#可省略參數:
2127
	#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點.
2128
	#$conf["filenameExtensionStartPoint"]="";
2129
	#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)".
2130
	#$conf["repeatNameRule"]="";
2131
	#$conf["web"],"true"代表為網頁系統,"false"代表檔案系統,預設為"false".
2132
	#$conf["web"]="false";
2133
	#參考資料:
2134
	#無.
2135
	#備註:
2136
	#如果要在/tmp底下建立檔案,若在apache環境下則會被作業系統特殊處理,即不等於實際上的路徑.
2137
	*/
2138
	public static function createFileAfterCheck(&$conf){
226 liveuser 2139
 
3 liveuser 2140
		#初始化要回傳的結果
2141
		$result=array();
226 liveuser 2142
 
3 liveuser 2143
		#設置當前執行的涵式
2144
		$result["function"]=__FUNCTION__;
226 liveuser 2145
 
3 liveuser 2146
		#如果 $conf 不為陣列
2147
		if(gettype($conf)!="array"){
226 liveuser 2148
 
3 liveuser 2149
			#設置執行失敗
2150
			$result["status"]="false";
226 liveuser 2151
 
3 liveuser 2152
			#設置執行錯誤訊息
2153
			$result["error"][]="\$conf變數須為陣列形態";
2154
 
2155
			#如果傳入的參數為 null
2156
			if($conf==null){
226 liveuser 2157
 
3 liveuser 2158
				#設置執行錯誤訊息
2159
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 2160
 
3 liveuser 2161
				}#if end
2162
 
2163
			#回傳結果
2164
			return $result;
226 liveuser 2165
 
3 liveuser 2166
			}#if end
226 liveuser 2167
 
3 liveuser 2168
		#取得參數
2169
		$result["argu"]=$conf;
226 liveuser 2170
 
3 liveuser 2171
		#檢查參數
2172
		#函式說明:
2173
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2174
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2175
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2176
		#$result["function"],當前執行的函式名稱.
2177
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2178
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2179
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2180
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2181
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2182
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2183
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2184
		#必填寫的參數:
2185
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2186
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2187
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2188
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","checkedFileAndPath");
226 liveuser 2189
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 2190
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
2191
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2192
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2193
		#可以省略的參數:
2194
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2195
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2196
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2197
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("filenameExtensionStartPoint","repeatNameRule","web");
226 liveuser 2198
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 2199
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
2200
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2201
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("1","(\$i)","false");
2202
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2203
		#$conf["arrayCountEqualCheck"][]=array();
2204
		#參考資料來源:
2205
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2206
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2207
		unset($conf["variableCheck::checkArguments"]);
2208
 
2209
		#如果 $checkArguments["status"] 等於 "false"
2210
		if($checkArguments["status"]=="false"){
226 liveuser 2211
 
3 liveuser 2212
			#設置錯誤識別
2213
			$result["status"]="false";
226 liveuser 2214
 
3 liveuser 2215
			#設置錯誤訊息
2216
			$result["error"]=$checkArguments;
226 liveuser 2217
 
3 liveuser 2218
			#回傳結果
226 liveuser 2219
			return $result;
2220
 
3 liveuser 2221
			}#if end
226 liveuser 2222
 
3 liveuser 2223
		#如果 $checkArguments["passed"] 等於 "false"
2224
		if($checkArguments["passed"]=="false"){
226 liveuser 2225
 
3 liveuser 2226
			#設置錯誤識別
2227
			$result["status"]="false";
226 liveuser 2228
 
3 liveuser 2229
			#設置錯誤訊息
2230
			$result["error"]=$checkArguments;
226 liveuser 2231
 
3 liveuser 2232
			#回傳結果
226 liveuser 2233
			return $result;
2234
 
2235
			}#if end
2236
 
3 liveuser 2237
		#確保要建立檔案的路徑
2238
		#函式說明:
2239
		#確保路徑存在.
2240
		#回傳結果:
2241
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
2242
		#$result["error"],錯誤訊息陣列.
2243
		#$resutl["function"],當前執行的涵式名稱.
2244
		#$result["path"],建立好的路徑字串.
2245
		#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
2246
		#必填參數:
2247
		#$conf["path"],要檢查的路徑
226 liveuser 2248
		$conf["fileAccess::validatePath"]["path"]=$conf["checkedFileAndPath"];
3 liveuser 2249
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2250
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
2251
		#可省略參數:
2252
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
2253
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
2254
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
2255
		#$conf["dirPermission"]="";
2256
		$conf["fileAccess::validatePath"]["web"]=$conf["web"];
2257
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
226 liveuser 2258
		unset($conf["fileAccess::validatePath"]);
2259
 
3 liveuser 2260
		#debug
2261
		#var_dump($validatePath);
226 liveuser 2262
		#exit;
2263
 
3 liveuser 2264
		#如果確保路徑失敗
2265
		if($validatePath["status"]==="false"){
226 liveuser 2266
 
3 liveuser 2267
			#設置錯誤識別
2268
			$result["status"]="false";
226 liveuser 2269
 
3 liveuser 2270
			#設置錯誤訊息
2271
			$result["error"]=$validatePath;
226 liveuser 2272
 
3 liveuser 2273
			#回傳結果
2274
			return $result;
226 liveuser 2275
 
3 liveuser 2276
			}#if end
226 liveuser 2277
 
3 liveuser 2278
		#取得要建立的檔案名稱
2279
		$createdFileName=$validatePath["fileName"];
226 liveuser 2280
 
2281
		#取得要建立的路徑
3 liveuser 2282
		$createdFilePath=$validatePath["path"];
226 liveuser 2283
 
3 liveuser 2284
		#透過無窮迴圈嘗試建立不同編號的檔案
2285
		for($i=0;$i>-1;$i++){
226 liveuser 2286
 
3 liveuser 2287
			#如果 $i 為 0
2288
			if($i==0){
226 liveuser 2289
 
3 liveuser 2290
				#檢查該檔案是否存在
2291
				#函式說明:
2292
				#檢查多個檔案與資料夾是否存在.
2293
				#回傳的結果:
2294
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
2295
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2296
				#必填參數:
2297
				$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($createdFilePath."/".$createdFileName);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
2298
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2299
				$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
2300
				#參考資料來源:
2301
				#http://php.net/manual/en/function.file-exists.php
2302
				#http://php.net/manual/en/control-structures.foreach.php
2303
				$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
2304
				$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
2305
				unset($conf["fileAccess"]["checkMutiFileExist"]);
226 liveuser 2306
 
3 liveuser 2307
				#debug
2308
				#var_dump($checkResult);
2309
				#exit;
226 liveuser 2310
 
3 liveuser 2311
				#如果檢查檔案是否存在失敗
2312
				if($checkResult["status"]=="false"){
226 liveuser 2313
 
3 liveuser 2314
					#設置執行失敗
2315
					$result["status"]="false";
226 liveuser 2316
 
3 liveuser 2317
					#設置錯誤訊息
2318
					$result["error"]=$checkResult;
226 liveuser 2319
 
3 liveuser 2320
					#回傳結果
2321
					return $result;
226 liveuser 2322
 
3 liveuser 2323
					}#if end
226 liveuser 2324
 
3 liveuser 2325
				#如果 $createFilePath.$createdFileName 檔案存在
2326
				if($checkResult["varExist"][0]=="true"){
226 liveuser 2327
 
3 liveuser 2328
					#跳過這次迴圈
2329
					continue;
226 liveuser 2330
 
3 liveuser 2331
					}#if end
226 liveuser 2332
 
3 liveuser 2333
				#反之代表 $createFilePath.$createdFileName 檔案不存在
2334
				else{
226 liveuser 2335
 
3 liveuser 2336
					#嘗試建立該檔案
2337
					#函式說明:
2338
					#將字串寫入到檔案
2339
					#回傳結果:
2340
					#$result["status"],true表示檔案寫入成功,false表示檔案寫入失敗.
2341
					#$result["error"],錯誤訊息陣列.
2342
					#必填參數:
2343
					$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$createdFilePath."/".$createdFileName;#爲要編輯的檔案名稱
2344
					$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
2345
					$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
2346
					#可省略參數:
2347
					$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
2348
					$conf["fileAccess"]["writeTextIntoFile"]["web"]=$conf["web"];
2349
					$fileCreateResult=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
2350
					unset($conf["fileAccess"]["writeTextIntoFile"]);
226 liveuser 2351
 
3 liveuser 2352
					#如果 $fileCreateResult["status"] 等於 "true"
2353
					if($fileCreateResult["status"]=="true"){
226 liveuser 2354
 
3 liveuser 2355
						#代表檔案建立成功
226 liveuser 2356
 
3 liveuser 2357
						#更新建立的檔案名稱
2358
						$result["createdFileName"]=$createdFileName;
226 liveuser 2359
 
3 liveuser 2360
						#設置新建立的檔案名稱與路徑
2361
						$result["createdFilePathAndName"]=$createdFilePath."/".$result["createdFileName"];
226 liveuser 2362
 
3 liveuser 2363
						#設置新建立的檔與路徑
2364
						$result["createdFilePath"]=$createdFilePath;
226 liveuser 2365
 
3 liveuser 2366
						#跳出迴圈
2367
						break;
226 liveuser 2368
 
3 liveuser 2369
						}#if end
226 liveuser 2370
 
3 liveuser 2371
					#反之代表檔案建立失敗
2372
					else{
226 liveuser 2373
 
3 liveuser 2374
						#設置錯誤識別
2375
						$result["status"]="false";
226 liveuser 2376
 
3 liveuser 2377
						#設置錯誤訊息
2378
						$result["error"]=$fileCreateResult;
226 liveuser 2379
 
3 liveuser 2380
						#回傳結果
2381
						return $result;
226 liveuser 2382
 
3 liveuser 2383
						}#else end
226 liveuser 2384
 
2385
					}#else end
2386
 
3 liveuser 2387
				}#if end
226 liveuser 2388
 
3 liveuser 2389
			#反之代表有相同檔名存在
226 liveuser 2390
			else{
2391
 
3 liveuser 2392
				#用「.」分割檔案名稱
2393
				#函式說明:
2394
				#將固定格式的字串分開,並回傳分開的結果。
2395
				#回傳結果:
2396
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2397
				#$result["error"],錯誤訊息陣列
2398
				#$result["function"],當前執行的函數名稱.
2399
				#$result["oriStr"],要分割的原始字串內容
2400
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2401
				#$result["dataCounts"],爲總共分成幾段
2402
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
2403
				#必填參數:
2404
				$conf["stringProcess::spiltString"]["stringIn"]=$createdFileName;#要處理的字串。
2405
				$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
2406
				#可省略參數:
2407
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2408
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2409
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2410
				unset($conf["stringProcess::spiltString"]);
2411
 
3 liveuser 2412
				#如果分割檔案名稱失敗
2413
				if($spiltString["status"]=="false"){
226 liveuser 2414
 
3 liveuser 2415
					#設置執行失敗
2416
					$result["status"]="false";
226 liveuser 2417
 
3 liveuser 2418
					#設置錯誤訊息
2419
					$result["error"]=$spiltString;
226 liveuser 2420
 
3 liveuser 2421
					#回傳結果
2422
					return $result;
226 liveuser 2423
 
3 liveuser 2424
					}#if end
226 liveuser 2425
 
3 liveuser 2426
				#初始化儲存建立的檔案名稱
2427
				$createdFileName="";
226 liveuser 2428
 
3 liveuser 2429
				#初始化儲存編號的變數
2430
				$no="";
226 liveuser 2431
 
3 liveuser 2432
				#如果沒有dot存在
2433
				if($spiltString["found"]=="false"){
226 liveuser 2434
 
3 liveuser 2435
					#解析 $conf["repeatNameRule"],用 \$i 分割.
2436
					#函式說明:
2437
					#將固定格式的字串分開,並回傳分開的結果。
2438
					#回傳結果:
2439
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2440
					#$result["error"],錯誤訊息陣列
2441
					#$result["function"],當前執行的函數名稱.
2442
					#$result["oriStr"],要分割的原始字串內容
2443
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2444
					#$result["dataCounts"],爲總共分成幾段
2445
					#必填參數:
2446
					$conf["stringProcess::spiltString"]["stringIn"]=$conf["repeatNameRule"];#要處理的字串。
2447
					$conf["stringProcess::spiltString"]["spiltSymbol"]="\$i";#爲以哪個符號作爲分割
2448
					#可省略參數:
2449
					#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2450
					$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2451
					$noString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2452
					unset($conf["stringProcess::spiltString"]);
2453
 
3 liveuser 2454
					#如果分割檔案名稱失敗
2455
					if($noString["status"]=="false"){
226 liveuser 2456
 
3 liveuser 2457
						#設置執行失敗
2458
						$result["status"]="false";
226 liveuser 2459
 
3 liveuser 2460
						#設置錯誤訊息
2461
						$result["error"]=$noString;
226 liveuser 2462
 
3 liveuser 2463
						#回傳結果
2464
						return $result;
226 liveuser 2465
 
3 liveuser 2466
						}#if end
226 liveuser 2467
 
3 liveuser 2468
					#如果 編號規則字串 分割出來的段數為2
2469
					if($noString["dataCounts"]==2){
226 liveuser 2470
 
3 liveuser 2471
						#組合編號
2472
						$no=$noString["dataArray"][0].$i.$noString["dataArray"][1];
226 liveuser 2473
 
3 liveuser 2474
						}#if end
226 liveuser 2475
 
3 liveuser 2476
					#反之 號規則字串 分割出來的段數為1
2477
					else if($noString["dataCounts"]==1){
226 liveuser 2478
 
3 liveuser 2479
						#判斷 "\$i" 在開頭或結尾
2480
						#函式說明:
2481
						#取得關鍵字在字串的哪個位置
2482
						#回傳結果:
2483
						#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
2484
						#$result["error"],錯誤訊息陣列.
2485
						#$result["function"],當前執行的函數名稱.
2486
						#$result["argu"],傳入的參數.
2487
						#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
2488
						#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
2489
						#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
2490
						#必填參數:
2491
						#$conf["inputStr"],字串,被搜尋的字串.
2492
						$conf["search::findKeyWordPosition"]["inputStr"]=$conf["repeatNameRule"];
2493
						#$conf["keyWord"],字串,關鍵字.
2494
						$conf["search::findKeyWordPosition"]["keyWord"]="\$i";
2495
						#參考資料:
2496
						#http://php.net/manual/en/function.strpos.php
2497
						$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
2498
						unset($conf["search::findKeyWordPosition"]);
226 liveuser 2499
 
3 liveuser 2500
						#如果取得關鍵字位置失敗
2501
						if($findKeyWordPosition["status"]=="false"){
226 liveuser 2502
 
3 liveuser 2503
							#設置執行失敗
2504
							$result["status"]="false";
226 liveuser 2505
 
3 liveuser 2506
							#設置錯誤訊息
2507
							$result["error"]=$findKeyWordPosition;
226 liveuser 2508
 
3 liveuser 2509
							#回傳結果
2510
							return $result;
226 liveuser 2511
 
3 liveuser 2512
							}#if end
226 liveuser 2513
 
3 liveuser 2514
						#如果關鍵字在開頭
2515
						if($findKeyWordPosition["head"]=="true"){
226 liveuser 2516
 
3 liveuser 2517
							#組合編號
2518
							$no=$i.$noString["dataArray"][0];
226 liveuser 2519
 
3 liveuser 2520
							}#if end
226 liveuser 2521
 
3 liveuser 2522
						#反之如果關鍵字在結尾
2523
						else if($findKeyWordPosition["tail"]=="true"){
226 liveuser 2524
 
3 liveuser 2525
							#組合編號
2526
							$no=$noString["dataArray"][0].$i;
226 liveuser 2527
 
3 liveuser 2528
							}#if end
226 liveuser 2529
 
3 liveuser 2530
						#其他情況
2531
						else{
226 liveuser 2532
 
3 liveuser 2533
							#設置執行失敗
2534
							$result["status"]="false";
226 liveuser 2535
 
3 liveuser 2536
							#設置錯誤訊息
2537
							$result["error"]=$findKeyWordPosition;
226 liveuser 2538
 
3 liveuser 2539
							#設置額外的錯誤訊息
2540
							$result["error"][]="非預期的結果";
226 liveuser 2541
 
3 liveuser 2542
							#回傳結果
2543
							return $result;
226 liveuser 2544
 
3 liveuser 2545
							}#else end
226 liveuser 2546
 
3 liveuser 2547
						}#if end
226 liveuser 2548
 
3 liveuser 2549
					#反之 編號規則字串 分割出來的段數為0
2550
					else if($noString["dataCounts"]==0){
226 liveuser 2551
 
3 liveuser 2552
						#組合編號
2553
						$no=$j;
226 liveuser 2554
 
3 liveuser 2555
						}#if end
226 liveuser 2556
 
3 liveuser 2557
					#其他結果
2558
					else{
226 liveuser 2559
 
3 liveuser 2560
						#設置執行失敗
2561
						$result["status"]="false";
226 liveuser 2562
 
3 liveuser 2563
						#設置錯誤訊息
2564
						$result["error"]=$noString;
226 liveuser 2565
 
3 liveuser 2566
						#設置額外的錯誤訊息
2567
						$result["error"][]="非預期的結果";
226 liveuser 2568
 
3 liveuser 2569
						#回傳結果
2570
						return $result;
226 liveuser 2571
 
2572
						}#else end
2573
 
3 liveuser 2574
					#串接編號到檔案名稱上
2575
					$createdFileName=$validatePath["fileName"].$no;
226 liveuser 2576
 
3 liveuser 2577
					}#if end
226 liveuser 2578
 
2579
				#反之有dot存在
3 liveuser 2580
				else{
226 liveuser 2581
 
3 liveuser 2582
					#依據 $spiltString["dataCounts"] 值來組裝新的檔案名稱
2583
					for($j=0;$j<$spiltString["dataCounts"];$j++){
226 liveuser 2584
 
3 liveuser 2585
						#如果是副檔名的前一段內容
2586
						if(($conf["filenameExtensionStartPoint"]+1)==($spiltString["dataCounts"]-$j)){
226 liveuser 2587
 
3 liveuser 2588
							#解析 $conf["repeatNameRule"],用 \$i 分割.
2589
							#函式說明:
2590
							#將固定格式的字串分開,並回傳分開的結果。
2591
							#回傳結果:
2592
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2593
							#$result["error"],錯誤訊息陣列
2594
							#$result["function"],當前執行的函數名稱.
2595
							#$result["oriStr"],要分割的原始字串內容
2596
							#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2597
							#$result["dataCounts"],爲總共分成幾段
2598
							#必填參數:
2599
							$conf["stringProcess::spiltString"]["stringIn"]=$conf["repeatNameRule"];#要處理的字串。
2600
							$conf["stringProcess::spiltString"]["spiltSymbol"]="\$i";#爲以哪個符號作爲分割
2601
							#可省略參數:
2602
							#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2603
							$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2604
							$noString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2605
							unset($conf["stringProcess::spiltString"]);
2606
 
3 liveuser 2607
							#如果分割檔案名稱失敗
2608
							if($noString["status"]=="false"){
226 liveuser 2609
 
3 liveuser 2610
								#設置執行失敗
2611
								$result["status"]="false";
226 liveuser 2612
 
3 liveuser 2613
								#設置錯誤訊息
2614
								$result["error"]=$noString;
226 liveuser 2615
 
3 liveuser 2616
								#回傳結果
2617
								return $result;
226 liveuser 2618
 
3 liveuser 2619
								}#if end
226 liveuser 2620
 
3 liveuser 2621
							#如果 編號規則字串 分割出來的段數為2
2622
							if($noString["dataCounts"]==2){
226 liveuser 2623
 
3 liveuser 2624
								#組合編號
2625
								$no=$noString["dataArray"][0].$i.$noString["dataArray"][1];
226 liveuser 2626
 
3 liveuser 2627
								}#if end
226 liveuser 2628
 
3 liveuser 2629
							#反之 號規則字串 分割出來的段數為1
2630
							else if($noString["dataCounts"]==1){
226 liveuser 2631
 
3 liveuser 2632
								#判斷 "\$i" 在開頭或結尾
2633
								#函式說明:
2634
								#取得關鍵字在字串的哪個位置
2635
								#回傳結果:
2636
								#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
2637
								#$result["error"],錯誤訊息陣列.
2638
								#$result["function"],當前執行的函數名稱.
2639
								#$result["argu"],傳入的參數.
2640
								#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
2641
								#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
2642
								#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
2643
								#必填參數:
2644
								#$conf["inputStr"],字串,被搜尋的字串.
2645
								$conf["search::findKeyWordPosition"]["inputStr"]=$conf["repeatNameRule"];
2646
								#$conf["keyWord"],字串,關鍵字.
2647
								$conf["search::findKeyWordPosition"]["keyWord"]="\$i";
2648
								#參考資料:
2649
								#http://php.net/manual/en/function.strpos.php
2650
								$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
2651
								unset($conf["search::findKeyWordPosition"]);
226 liveuser 2652
 
3 liveuser 2653
								#如果取得關鍵字位置失敗
2654
								if($findKeyWordPosition["status"]=="false"){
226 liveuser 2655
 
3 liveuser 2656
									#設置執行失敗
2657
									$result["status"]="false";
226 liveuser 2658
 
3 liveuser 2659
									#設置錯誤訊息
2660
									$result["error"]=$findKeyWordPosition;
226 liveuser 2661
 
3 liveuser 2662
									#回傳結果
2663
									return $result;
226 liveuser 2664
 
3 liveuser 2665
									}#if end
226 liveuser 2666
 
3 liveuser 2667
								#如果關鍵字在開頭
2668
								if($findKeyWordPosition["head"]=="true"){
226 liveuser 2669
 
3 liveuser 2670
									#組合編號
2671
									$no=$i.$noString["dataArray"][0];
226 liveuser 2672
 
3 liveuser 2673
									}#if end
226 liveuser 2674
 
3 liveuser 2675
								#反之如果關鍵字在結尾
2676
								else if($findKeyWordPosition["tail"]=="true"){
226 liveuser 2677
 
3 liveuser 2678
									#組合編號
2679
									$no=$noString["dataArray"][0].$i;
226 liveuser 2680
 
3 liveuser 2681
									}#if end
226 liveuser 2682
 
3 liveuser 2683
								#其他情況
2684
								else{
226 liveuser 2685
 
3 liveuser 2686
									#設置執行失敗
2687
									$result["status"]="false";
226 liveuser 2688
 
3 liveuser 2689
									#設置錯誤訊息
2690
									$result["error"]=$findKeyWordPosition;
226 liveuser 2691
 
3 liveuser 2692
									#設置額外的錯誤訊息
2693
									$result["error"][]="非預期的結果";
226 liveuser 2694
 
3 liveuser 2695
									#回傳結果
2696
									return $result;
226 liveuser 2697
 
3 liveuser 2698
									}#else end
226 liveuser 2699
 
3 liveuser 2700
								}#if end
226 liveuser 2701
 
3 liveuser 2702
							#反之 編號規則字串 分割出來的段數為0
2703
							else if($noString["dataCounts"]==0){
226 liveuser 2704
 
3 liveuser 2705
								#組合編號
2706
								$no=$j;
226 liveuser 2707
 
3 liveuser 2708
								}#if end
226 liveuser 2709
 
3 liveuser 2710
							#其他結果
2711
							else{
226 liveuser 2712
 
3 liveuser 2713
								#設置執行失敗
2714
								$result["status"]="false";
226 liveuser 2715
 
3 liveuser 2716
								#設置錯誤訊息
2717
								$result["error"]=$noString;
226 liveuser 2718
 
3 liveuser 2719
								#設置額外的錯誤訊息
2720
								$result["error"][]="非預期的結果";
226 liveuser 2721
 
3 liveuser 2722
								#回傳結果
2723
								return $result;
226 liveuser 2724
 
2725
								}#else end
2726
 
3 liveuser 2727
							#串接編號到檔案名稱上
2728
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j].$no;
226 liveuser 2729
 
3 liveuser 2730
							#如果不是最後一段
2731
							if($j!=$spiltString["dataCounts"]-1){
226 liveuser 2732
 
3 liveuser 2733
								#串接並加上 dot
2734
								$createdFileName=$createdFileName.".";
226 liveuser 2735
 
3 liveuser 2736
								}#if end
226 liveuser 2737
 
3 liveuser 2738
							}#if end
226 liveuser 2739
 
3 liveuser 2740
						#反之如果不是最後一段
2741
						else if($j!=$spiltString["dataCounts"]-1){
226 liveuser 2742
 
3 liveuser 2743
							#串接並加上 dot
2744
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j].".";
226 liveuser 2745
 
3 liveuser 2746
							}#if end
226 liveuser 2747
 
2748
						#反之是最後一段
3 liveuser 2749
						else{
226 liveuser 2750
 
3 liveuser 2751
							#串接並加上 dot
2752
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j];
226 liveuser 2753
 
3 liveuser 2754
							}#else end
226 liveuser 2755
 
3 liveuser 2756
						}#for end
226 liveuser 2757
 
3 liveuser 2758
					}#else end
226 liveuser 2759
 
3 liveuser 2760
				#檢查加上編號的檔案是否存在
2761
				#函式說明:
2762
				#檢查多個檔案與資料夾是否存在.
2763
				#回傳的結果:
2764
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
2765
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2766
				#必填參數:
2767
				$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($createdFilePath."/".$createdFileName);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
2768
				$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
2769
				#參考資料來源:
2770
				#http://php.net/manual/en/function.file-exists.php
2771
				#http://php.net/manual/en/control-structures.foreach.php
2772
				$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
2773
				$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
2774
				unset($conf["fileAccess"]["checkMutiFileExist"]);
226 liveuser 2775
 
3 liveuser 2776
				#如果檢查檔案是否存在失敗
2777
				if($checkResult["status"]=="false"){
226 liveuser 2778
 
3 liveuser 2779
					#設置執行失敗
2780
					$result["status"]="false";
226 liveuser 2781
 
3 liveuser 2782
					#設置錯誤訊息
2783
					$result["error"]=$checkResult;
226 liveuser 2784
 
3 liveuser 2785
					#回傳結果
2786
					return $result;
226 liveuser 2787
 
2788
					}#if end
2789
 
3 liveuser 2790
				#如果 $checkResult["varExist"][0] 等於 "true"
226 liveuser 2791
				if($checkResult["varExist"][0]=="true"){
2792
 
3 liveuser 2793
					#取得要建立的檔案名稱
2794
					$createdFileName=$validatePath["fileName"];
226 liveuser 2795
 
3 liveuser 2796
					#跳到下個迴圈
2797
					continue;
226 liveuser 2798
 
3 liveuser 2799
					}#if end
226 liveuser 2800
 
3 liveuser 2801
				#反之代表 $createFilePath.$createdFileName."(".$i.")" 檔檔案不存在
2802
				else{
226 liveuser 2803
 
3 liveuser 2804
					#嘗試建立該檔案
2805
					#函式說明:
2806
					#將字串寫入到檔案
2807
					#回傳結果:
2808
					#$result["status"],true表示檔案寫入成功,false表示檔案寫入失敗.
2809
					#$result["error"],錯誤訊息陣列.
2810
					#必填參數:
2811
					$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$createdFilePath."/".$createdFileName;#爲要編輯的檔案名稱
2812
					$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
2813
					$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
2814
					#可省略參數:
2815
					$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
2816
					$conf["fileAccess"]["writeTextIntoFile"]["web"]=$conf["web"];
2817
					$fileCreateResult=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
2818
					unset($conf["fileAccess"]["writeTextIntoFile"]);
226 liveuser 2819
 
3 liveuser 2820
					#如果 $fileCreateResult["status"] 等於 "true"
2821
					if($fileCreateResult["status"]=="true"){
226 liveuser 2822
 
3 liveuser 2823
						#代表檔案建立成功
226 liveuser 2824
 
3 liveuser 2825
						#更新建立的檔案名稱
2826
						$result["createdFileName"]=$createdFileName;
226 liveuser 2827
 
3 liveuser 2828
						#跳出迴圈
2829
						break;
226 liveuser 2830
 
3 liveuser 2831
						}#if end
226 liveuser 2832
 
3 liveuser 2833
					#反之代表檔案建立失敗
2834
					else{
226 liveuser 2835
 
3 liveuser 2836
						#設置錯誤識別
2837
						$result["status"]="false";
226 liveuser 2838
 
3 liveuser 2839
						#設置錯誤訊息
2840
						$result["error"]=$fileCreateResult;
226 liveuser 2841
 
3 liveuser 2842
						#回傳結果
2843
						return $result;
226 liveuser 2844
 
3 liveuser 2845
						}#else end
226 liveuser 2846
 
3 liveuser 2847
					}#else end
226 liveuser 2848
 
3 liveuser 2849
				}#else end
226 liveuser 2850
 
3 liveuser 2851
			}#for end
226 liveuser 2852
 
3 liveuser 2853
		#如果不存在建立的檔案名稱
2854
		if(!isset($result["createdFileName"])){
226 liveuser 2855
 
3 liveuser 2856
			#設置錯誤識別
2857
			$result["status"]="false";
226 liveuser 2858
 
3 liveuser 2859
			#設置錯誤訊息
2860
			$result["error"][]="建立的檔案名稱不存在";
226 liveuser 2861
 
3 liveuser 2862
			#回傳結果
2863
			return $result;
226 liveuser 2864
 
2865
			}#if end
2866
 
3 liveuser 2867
		#執行到這邊代表執行成功
2868
		$result["status"]="true";
226 liveuser 2869
 
3 liveuser 2870
		#設置新建立的檔案名稱與路徑
2871
		$result["createdFilePathAndName"]=$createdFilePath."/".$result["createdFileName"];
226 liveuser 2872
 
3 liveuser 2873
		#設置新建立的檔與路徑
2874
		$result["createdFilePath"]=$createdFilePath;
226 liveuser 2875
 
3 liveuser 2876
		#回傳結果
2877
		return $result;
226 liveuser 2878
 
3 liveuser 2879
		}#fucntion createFileAfterCheck end
2880
 
2881
	/*
2882
	#函式說明:
2883
	#將檔案內容清空
2884
	#回傳結果:
2885
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
2886
	#$result["error"],錯誤訊息陣列
2887
	#必填參數:
2888
	#$conf["fileAddr"],字串,要清空的檔案位置與名稱.
2889
	$conf["fileAddr"]="";
2890
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2891
	$conf["fileArgu"]=__FILE__;
2892
	#可省略參數:
2893
	#$conf["web"],"true"代表為網頁系統,"false"代表檔案系統,預設為"false".
2894
	#$conf["web"]="false";
2895
	#參考資料:
2896
	#無.
2897
	#備註:
2898
	#無.
2899
	*/
2900
	public static function emptyFile(&$conf){
226 liveuser 2901
 
3 liveuser 2902
		#初始化要回傳的結果
2903
		$result=array();
226 liveuser 2904
 
3 liveuser 2905
		#設置當前執行的涵式
2906
		$result["function"]=__FUNCTION__;
226 liveuser 2907
 
3 liveuser 2908
		#如果 $conf 不為陣列
2909
		if(gettype($conf)!="array"){
226 liveuser 2910
 
3 liveuser 2911
			#設置執行失敗
2912
			$result["status"]="false";
226 liveuser 2913
 
3 liveuser 2914
			#設置執行錯誤訊息
2915
			$result["error"][]="\$conf變數須為陣列形態";
2916
 
2917
			#如果傳入的參數為 null
2918
			if($conf==null){
226 liveuser 2919
 
3 liveuser 2920
				#設置執行錯誤訊息
2921
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 2922
 
3 liveuser 2923
				}#if end
2924
 
2925
			#回傳結果
2926
			return $result;
226 liveuser 2927
 
3 liveuser 2928
			}#if end
226 liveuser 2929
 
3 liveuser 2930
		#取得參數
2931
		$result["argu"]=$conf;
226 liveuser 2932
 
3 liveuser 2933
		#檢查參數
2934
		#函式說明:
2935
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2936
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2937
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2938
		#$result["function"],當前執行的函式名稱.
2939
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2940
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2941
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2942
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2943
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2944
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2945
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2946
		#必填寫的參數:
2947
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2948
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2949
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2950
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddr");
226 liveuser 2951
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 2952
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
2953
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2954
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2955
		#可以省略的參數:
2956
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2957
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2958
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2959
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 2960
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 2961
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
2962
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2963
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
2964
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2965
		#$conf["arrayCountEqualCheck"][]=array();
2966
		#參考資料來源:
2967
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2968
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2969
		unset($conf["variableCheck::checkArguments"]);
2970
 
2971
		#如果 $checkArguments["status"] 等於 "false"
2972
		if($checkArguments["status"]=="false"){
226 liveuser 2973
 
3 liveuser 2974
			#設置錯誤識別
2975
			$result["status"]="false";
226 liveuser 2976
 
3 liveuser 2977
			#設置錯誤訊息
2978
			$result["error"]=$checkArguments;
226 liveuser 2979
 
3 liveuser 2980
			#回傳結果
226 liveuser 2981
			return $result;
2982
 
3 liveuser 2983
			}#if end
226 liveuser 2984
 
3 liveuser 2985
		#如果 $checkArguments["passed"] 等於 "false"
2986
		if($checkArguments["passed"]=="false"){
226 liveuser 2987
 
3 liveuser 2988
			#設置錯誤識別
2989
			$result["status"]="false";
226 liveuser 2990
 
3 liveuser 2991
			#設置錯誤訊息
2992
			$result["error"]=$checkArguments;
226 liveuser 2993
 
3 liveuser 2994
			#回傳結果
226 liveuser 2995
			return $result;
2996
 
2997
			}#if end
2998
 
3 liveuser 2999
		#函式說明:
3000
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
3001
		#回傳結果:
3002
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3003
		#$result["error"],錯誤訊息陣列.
226 liveuser 3004
		#$result["function"],函數名稱.
3 liveuser 3005
		#$result["argu"],使用的參數.
3006
		#$result["content"],網址,若是在命令列執行,則為"null".
3007
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
3008
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
3009
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
3010
		#必填參數:
3011
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
3012
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["fileAddr"];
3013
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3014
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
3015
		#可省略參數:
3016
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3017
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
3018
		#備註:
3019
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
3020
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
3021
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 3022
 
3 liveuser 3023
		#如果確保路徑失敗
3024
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 3025
 
3 liveuser 3026
			#設置錯誤識別
3027
			$result["status"]="false";
226 liveuser 3028
 
3 liveuser 3029
			#設置錯誤訊息
3030
			$result["error"]=$getInternetAddressV2;
226 liveuser 3031
 
3 liveuser 3032
			#回傳結果
3033
			return $result;
226 liveuser 3034
 
3 liveuser 3035
			}#if end
226 liveuser 3036
 
3 liveuser 3037
		#更新檔案路徑
3038
		$conf["fileAddr"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 3039
 
3 liveuser 3040
		#確保要建立檔案的路徑
3041
		#函式說明:
3042
		#確保路徑存在.
3043
		#回傳結果:
3044
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3045
		#$result["error"],錯誤訊息陣列.
3046
		#$resutl["function"],當前執行的涵式名稱.
3047
		#$result["path"],建立好的路徑字串.
3048
		#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
3049
		#必填參數:
3050
		#$conf["path"],要檢查的路徑
226 liveuser 3051
		$conf["fileAccess::validatePath"]["path"]=$conf["fileAddr"];
3 liveuser 3052
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3053
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
3054
		#可省略參數:
3055
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
3056
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
3057
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3058
		#$conf["dirPermission"]="";
3059
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3060
		$conf["fileAccess::validatePath"]["web"]="false";
3061
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
226 liveuser 3062
		unset($conf["fileAccess::validatePath"]);
3063
 
3 liveuser 3064
		#如果確保路徑失敗
3065
		if($validatePath["status"]==="false"){
226 liveuser 3066
 
3 liveuser 3067
			#設置錯誤識別
3068
			$result["status"]="false";
226 liveuser 3069
 
3 liveuser 3070
			#設置錯誤訊息
3071
			$result["error"]=$validatePath;
226 liveuser 3072
 
3 liveuser 3073
			#回傳結果
3074
			return $result;
226 liveuser 3075
 
3 liveuser 3076
			}#if end
226 liveuser 3077
 
3 liveuser 3078
		#清空檔案
3079
		#函式說明:
3080
		#將字串寫入到檔案
3081
		#回傳結果:
3082
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
3083
		#$result["error"],錯誤訊息陣列.
3084
		#$result["function"],當前執行的函數名稱.
3085
		#$result["fileInfo"],實際上寫入的檔案資訊陣列.
3086
		#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
3087
		#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
3088
		#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
3089
		#$result["argu"],使用的參數.
3090
		#必填參數:
3091
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3092
		$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
3093
		#可省略參數:
3094
		#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
3095
		#$conf["fileAccess::writeTextIntoFile"]["fileName"]=$validatePath["path"]."/".$validatePath["fileName"];
3096
		$conf["fileAccess::writeTextIntoFile"]["fileName"]=$validatePath["path"]."/".$validatePath["fileName"];;
3097
		#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
3098
		#$conf["inputString"]="";
3099
		#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
3100
		#$conf["writeMethod"]="a";
3101
		#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
3102
		#$conf["checkRepeat"]="";
3103
		#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
3104
		#$conf["filenameExtensionStartPoint"]="";
3105
		#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
3106
		#$conf["repeatNameRule"]="";
3107
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3108
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
3109
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
3110
		unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 3111
 
3 liveuser 3112
		#如果確保路徑失敗
3113
		if($writeTextIntoFile["status"]==="false"){
226 liveuser 3114
 
3 liveuser 3115
			#設置錯誤識別
3116
			$result["status"]="false";
226 liveuser 3117
 
3 liveuser 3118
			#設置錯誤訊息
3119
			$result["error"]=$writeTextIntoFile;
226 liveuser 3120
 
3 liveuser 3121
			#回傳結果
3122
			return $result;
226 liveuser 3123
 
3 liveuser 3124
			}#if end
226 liveuser 3125
 
3 liveuser 3126
		#設置執行正常
3127
		$result["status"]="true";
226 liveuser 3128
 
3 liveuser 3129
		#儲存建立的結果
3130
		$result["content"]=$writeTextIntoFile;
226 liveuser 3131
 
3 liveuser 3132
		#回傳結果
3133
		return $result;
226 liveuser 3134
 
3 liveuser 3135
		}#function emptyFile end
3136
 
3137
	/*
3138
	#函式說明:
3139
	#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
3140
	#回傳結果:
3141
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3142
	#$result["error"],錯誤訊息陣列
3143
	#$result["warning"],警告訊息陣列
3144
	#必填參數:
3145
	#$conf["dirPositionAndName"]="";#新建的位置與名稱
3146
	$conf["dirPositionAndName"]="";
3147
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3148
	$conf["fileArgu"]=__FILE__;
3149
	#可省略參數:
3150
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3151
	#$conf["dirPermission"]="";
3152
	#參考資料:
3153
	#mkdir=>http://php.net/manual/en/function.mkdir.php
3154
	#chmod=>http://php.net/manual/en/function.chmod.php
3155
	#參考資料:
3156
	#無.
3157
	#備註:
3158
	#同 function createFolderAfterCheck.
3159
	*/
3160
	public static function createNewFolder(&$conf){
3161
 
3162
		/*
3163
		#函式說明:
3164
		#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
3165
		#回傳的結果:
3166
		#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
3167
		#$result["error"],錯誤訊息陣列.
3168
		#$result["function"],當前執行的函數名稱.
3169
		#$result["createdFileName"],建立好的檔案名稱.
3170
		#$result["createdFilePath"],檔案建立的路徑.
3171
		#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
3172
		#必填參數:
3173
		#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
3174
		$conf["checkedFileAndPath"]="";
3175
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3176
		$conf["fileArgu"]=__FILE__;
3177
		*/
3178
		return fileAccess::createFolderAfterCheck($conf);
3179
		unset($conf);
3180
 
3181
		}#function createNewFolder end
226 liveuser 3182
 
3 liveuser 3183
	/*
3184
	#函式說明:
3185
	#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
3186
	#回傳結果:
3187
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3188
	#$result["error"],錯誤訊息陣列
3189
	#$result["warning"],警告訊息陣列
3190
	#$result["argu"],使用的參數.
3191
	#$result["content"],建立的目錄路徑.
3192
	#必填參數:
3193
	#$conf["dirPositionAndName"]="";#新建的位置與名稱
3194
	$conf["dirPositionAndName"]="";
3195
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3196
	$conf["fileArgu"]=__FILE__;
3197
	#可省略參數:
3198
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3199
	#$conf["dirPermission"]="";
3200
	#$conf["web"],"false"代表在檔案系統環境,"true"代表在網頁稀系統環境.
3201
	#$conf["web"]="false";
3202
	#參考資料:
3203
	#mkdir=>http://php.net/manual/en/function.mkdir.php
3204
	#chmod=>http://php.net/manual/en/function.chmod.php
3205
	#備註:
3206
	#無.
3207
	*/
3208
	public static function createFolderAfterCheck(&$conf){
226 liveuser 3209
 
3 liveuser 3210
		#初始化要回傳的結果
3211
		$result=array();
226 liveuser 3212
 
3 liveuser 3213
		#初始化警告訊息陣列
3214
		$result["warning"]=array();
226 liveuser 3215
 
3 liveuser 3216
		#記錄當前執行的函數名稱
3217
		$result["function"]=__FUNCTION__;
226 liveuser 3218
 
3 liveuser 3219
		#如果 $conf 不為陣列
3220
		if(gettype($conf)!="array"){
226 liveuser 3221
 
3 liveuser 3222
			#設置執行失敗
3223
			$result["status"]="false";
226 liveuser 3224
 
3 liveuser 3225
			#設置執行錯誤訊息
3226
			$result["error"][]="\$conf變數須為陣列形態";
3227
 
3228
			#如果傳入的參數為 null
3229
			if($conf==null){
226 liveuser 3230
 
3 liveuser 3231
				#設置執行錯誤訊息
3232
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3233
 
3 liveuser 3234
				}#if end
3235
 
3236
			#回傳結果
3237
			return $result;
226 liveuser 3238
 
3 liveuser 3239
			}#if end
226 liveuser 3240
 
3 liveuser 3241
		#取得參數
3242
		$result["argu"]=$conf;
226 liveuser 3243
 
3 liveuser 3244
		#檢查參數
3245
		#函式說明:
3246
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3247
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3248
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3249
		#$result["function"],當前執行的函式名稱.
3250
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3251
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3252
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3253
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3254
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3255
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3256
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3257
		#必填寫的參數:
3258
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3259
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3260
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3261
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","dirPositionAndName");
226 liveuser 3262
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3263
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
3264
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3265
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3266
		#可以省略的參數:
3267
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3268
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3269
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3270
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dirPermission","web");
226 liveuser 3271
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3272
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
3273
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3274
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("0770","false");
3275
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3276
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
3277
		#參考資料來源:
3278
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3279
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3280
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3281
 
3 liveuser 3282
		#如果 $checkArguments["status"] 等於 "false"
3283
		if($checkArguments["status"]==="false"){
226 liveuser 3284
 
3 liveuser 3285
			#設置 $result["status"] 為 "false"
3286
			$result["status"]="false";
226 liveuser 3287
 
3 liveuser 3288
			#設置 $result["error"]
3289
			$result["error"]=$checkArguments;
226 liveuser 3290
 
3 liveuser 3291
			#回傳結果
3292
			return $result;
226 liveuser 3293
 
3 liveuser 3294
			}#if end
226 liveuser 3295
 
3 liveuser 3296
		#如果 $checkArguments["passed"] 等於 "false"
3297
		if($checkArguments["passed"]==="false"){
226 liveuser 3298
 
3 liveuser 3299
			#設置 $result["status"] 為 "false"
3300
			$result["status"]="false";
226 liveuser 3301
 
3 liveuser 3302
			#設置 $result["error"]
3303
			$result["error"]=$checkArguments;
226 liveuser 3304
 
3 liveuser 3305
			#回傳結果
3306
			return $result;
226 liveuser 3307
 
3308
			}#if end
3309
 
3 liveuser 3310
		#函式說明:
3311
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
3312
		#回傳結果:
3313
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3314
		#$result["error"],錯誤訊息陣列.
226 liveuser 3315
		#$result["function"],函數名稱.
3 liveuser 3316
		#$result["argu"],使用的參數.
3317
		#$result["content"],網址,若是在命令列執行,則為"null".
3318
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
3319
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
3320
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
3321
		#必填參數:
3322
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
3323
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["dirPositionAndName"];
3324
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3325
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
3326
		#可省略參數:
3327
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3328
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
3329
		#備註:
3330
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
3331
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
3332
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 3333
 
3 liveuser 3334
		#如果 $getInternetAddressV2["status"] 等於 "false"
3335
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 3336
 
3 liveuser 3337
			#設置 $result["status"] 為 "false"
3338
			$result["status"]="false";
226 liveuser 3339
 
3 liveuser 3340
			#設置 $result["error"]
3341
			$result["error"]=$getInternetAddressV2;
226 liveuser 3342
 
3 liveuser 3343
			#回傳結果
3344
			return $result;
226 liveuser 3345
 
3 liveuser 3346
			}#if end
226 liveuser 3347
 
3 liveuser 3348
		#取得絕對位置
3349
		$conf["dirPositionAndName"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 3350
 
3 liveuser 3351
		#用「/」分割要建立的路徑
3352
		#函式說明:
3353
		#將固定格式的字串分開,並回傳分開的結果。
3354
		#回傳結果:
3355
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3356
		#$result["error"],錯誤訊息陣列
3357
		#$result["function"],當前執行的函數名稱.
3358
		#$result["oriStr"],要分割的原始字串內容
3359
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
3360
		#$result["dataCounts"],爲總共分成幾段
3361
		#必填參數:
3362
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["dirPositionAndName"];
3363
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
3364
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 3365
		unset($conf["stringProcess::spiltString"]);
3366
 
3 liveuser 3367
		#如果分割失敗
3368
		if($spiltString["status"]=="false"){
226 liveuser 3369
 
3 liveuser 3370
			#設置 $result["status"] 為 "false"
3371
			$result["status"]="false";
226 liveuser 3372
 
3 liveuser 3373
			#設置 $result["error"]
3374
			$result["error"]=$spiltString;
226 liveuser 3375
 
3 liveuser 3376
			#回傳結果
3377
			return $result;
226 liveuser 3378
 
3 liveuser 3379
			}#if end
226 liveuser 3380
 
3 liveuser 3381
		$checkedPath="";
226 liveuser 3382
 
3 liveuser 3383
		#依據切割成的路徑片段數目
3384
		for($i=0;$i<$spiltString["dataCounts"];$i++){
226 liveuser 3385
 
3 liveuser 3386
			$checkedPath=$checkedPath."/".$spiltString["dataArray"][$i];
226 liveuser 3387
 
3 liveuser 3388
			#檢查路徑是否存在
3389
			#函式說明:
3390
			#檢查多個檔案與資料夾是否存在.
3391
			#回傳的結果:
3392
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3393
			#$result["error"],錯誤訊息陣列.
3394
			#$resutl["function"],當前執行的涵式名稱.
3395
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
3396
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
3397
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
3398
			#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
3399
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
3400
			#必填參數:
3401
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
3402
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($checkedPath);
3403
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3404
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
3405
			#可省略參數
3406
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
3407
			#$conf["disableWebSearch"]="false";
3408
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
3409
			#$conf["userDir"]="true";
3410
			#參考資料來源:
3411
			#http://php.net/manual/en/function.file-exists.php
3412
			#http://php.net/manual/en/control-structures.foreach.php
3413
			#備註:
3414
			#函數file_exists檢查的路徑為檔案系統的路徑
3415
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 3416
 
3 liveuser 3417
			#如果檢查資料夾路徑失敗
3418
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 3419
 
3 liveuser 3420
				#設置 $result["status"] 為 "false"
3421
				$result["status"]="false";
226 liveuser 3422
 
3 liveuser 3423
				#設置 $result["error"]
3424
				$result["error"]=$spiltString;
226 liveuser 3425
 
3 liveuser 3426
				#回傳結果
3427
				return $result;
226 liveuser 3428
 
3 liveuser 3429
				}#if end
226 liveuser 3430
 
3 liveuser 3431
			#如果目錄不存在
3432
			if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 3433
 
3 liveuser 3434
				#如果有這個名稱的東西存在
3435
				if(file_exists($checkedPath)){
226 liveuser 3436
 
3 liveuser 3437
					#如果目錄存在
3438
					if(is_dir($checkedPath)){
226 liveuser 3439
 
3 liveuser 3440
						#目錄已經存在換下一層
3441
						continue;
226 liveuser 3442
 
3 liveuser 3443
						}#if end
226 liveuser 3444
 
3 liveuser 3445
					}#if end
226 liveuser 3446
 
3 liveuser 3447
				#建立目錄
3448
				$mkdir=@mkdir($checkedPath,0770);
226 liveuser 3449
 
3 liveuser 3450
				#如果建立目錄失敗
3451
				#參考資料:
3452
				#http://php.net/manual/en/function.mkdir.php
3453
				if($mkdir===false){
226 liveuser 3454
 
3 liveuser 3455
					#設置 $result["status"] 為 "false"
3456
					$result["status"]="false";
226 liveuser 3457
 
3 liveuser 3458
					#設置 $result["error"]
3459
					$result["error"][]="建立目錄「".$checkedPath."」失敗";
226 liveuser 3460
 
3 liveuser 3461
					#回傳結果
3462
					return $result;
226 liveuser 3463
 
3 liveuser 3464
					}#if end
226 liveuser 3465
 
3 liveuser 3466
				#更改目錄的權限為 0770
3467
				chmod($checkedPath,0770);
226 liveuser 3468
 
3 liveuser 3469
				}#if end
226 liveuser 3470
 
3 liveuser 3471
			}#for end
226 liveuser 3472
 
3 liveuser 3473
		#取得建立好的目錄
226 liveuser 3474
		$result["content"]=$checkedPath;
3475
 
3 liveuser 3476
		#執行到這邊代表執行成功
3477
		$result["status"]="true";
226 liveuser 3478
 
3 liveuser 3479
		#回傳結果
3480
		return $result;
226 liveuser 3481
 
3 liveuser 3482
		}#function createFolderAfterCheck end
3483
 
3484
	/*
3485
	#函式說明:
3486
	#移除檔案
3487
	#回傳結果:
3488
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
3489
	#$result["error"],錯誤訊息陣列.
3490
	#$result["warning"],警告訊息陣列.
3491
	#$result["function"],當前執行的函數名稱.
3492
	#$result["argu"],當前函式使用的參數.
3493
	#必填參數:
3494
	#$conf["fileAddress"],字串,要移除檔案的位置.
3495
	$conf["fileAddress"]="";
3496
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3497
	$conf["fileArgu"]=__FILE__;
3498
	#可省略參數:
3499
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
3500
	#$conf["commentsArray"]=array("");
3501
	#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
3502
	#$conf["allowDelSymlink"]="true";
3503
	#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
3504
	#$conf["allowDelFolder"]="true";
3505
	#參考資料:
3506
	#無.
3507
	#備註:
3508
	#無.
220 liveuser 3509
	*/
3 liveuser 3510
	public static function delFile(&$conf){
3511
 
3512
		#初始化要回傳的結果
3513
		$result=array();
226 liveuser 3514
 
3 liveuser 3515
		#設置當其函數名稱
3516
		$result["function"]=__FUNCTION__;
226 liveuser 3517
 
3 liveuser 3518
		#如果 $conf 不為陣列
3519
		if(gettype($conf)!="array"){
226 liveuser 3520
 
3 liveuser 3521
			#設置執行失敗
3522
			$result["status"]="false";
226 liveuser 3523
 
3 liveuser 3524
			#設置執行錯誤訊息
3525
			$result["error"][]="\$conf變數須為陣列形態";
3526
 
3527
			#如果傳入的參數為 null
3528
			if($conf==null){
226 liveuser 3529
 
3 liveuser 3530
				#設置執行錯誤訊息
3531
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3532
 
3 liveuser 3533
				}#if end
3534
 
3535
			#回傳結果
3536
			return $result;
226 liveuser 3537
 
3 liveuser 3538
			}#if end
226 liveuser 3539
 
3 liveuser 3540
		#取得參數
3541
		$result["argu"]=$conf;
226 liveuser 3542
 
3 liveuser 3543
		#檢查參數
3544
		#函式說明:
3545
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3546
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3547
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3548
		#$result["function"],當前執行的函式名稱.
3549
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3550
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3551
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3552
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3553
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3554
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3555
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3556
		#必填寫的參數:
3557
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3558
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3559
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3560
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddress");
226 liveuser 3561
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3562
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
3563
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3564
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3565
		#可以省略的參數:
3566
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3567
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3568
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3569
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","allowDelSymlink","allowDelFolder");
226 liveuser 3570
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3571
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");
3572
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3573
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false","false");
3574
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3575
		#$conf["arrayCountEqualCheck"][]=array();
3576
		#參考資料來源:
3577
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3578
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3579
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3580
 
3 liveuser 3581
		#如果檢查失敗
3582
		if($checkResult["status"]=="false"){
226 liveuser 3583
 
3 liveuser 3584
			#設置錯誤識別
3585
			$result["status"]="false";
226 liveuser 3586
 
3 liveuser 3587
			#設置錯誤訊息
3588
			$result["error"]=$checkResult;
226 liveuser 3589
 
3 liveuser 3590
			#回傳結果
3591
			return $result;
226 liveuser 3592
 
3 liveuser 3593
			}#if end
226 liveuser 3594
 
3 liveuser 3595
		#如果檢查不通過
3596
		if($checkResult["passed"]=="false"){
226 liveuser 3597
 
3 liveuser 3598
			#設置錯誤識別
3599
			$result["status"]="false";
226 liveuser 3600
 
3 liveuser 3601
			#設置錯誤訊息
3602
			$result["error"]=$checkResult;
226 liveuser 3603
 
3 liveuser 3604
			#回傳結果
3605
			return $result;
226 liveuser 3606
 
3 liveuser 3607
			}#if end
3608
 
3609
		#如果 $conf["commentsArray"] 有設定
3610
		if(isset($conf["commentsArray"])){
226 liveuser 3611
 
3 liveuser 3612
			#印出提示文字
3613
			#函式說明:
3614
			#印出多行文字,結尾自動換行.
3615
			#回傳的結果:
3616
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
3617
			#$result["function"],當前執行的函數名稱.
3618
			#$result["error"],錯誤訊息陣列.
3619
			#必填參數:
3620
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
3621
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
3622
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
3623
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 3624
 
3 liveuser 3625
			#如果印出提示文字失敗
3626
			if($echoMultiLine["status"]=="false"){
226 liveuser 3627
 
3 liveuser 3628
				#設置執行失敗
3629
				$result["status"]="false";
226 liveuser 3630
 
3 liveuser 3631
				#設置執行錯誤訊息
3632
				$result["error"]=$echoMultiLine;
226 liveuser 3633
 
3 liveuser 3634
				#回傳結果
3635
				return $result;
226 liveuser 3636
 
3 liveuser 3637
				}#if end
226 liveuser 3638
 
3 liveuser 3639
			}#if end
3640
 
3641
		#檢查要移除的檔案是否存在
3642
		#函式說明:
3643
		#檢查多個檔案與資料夾是否存在.
3644
		#回傳的結果:
3645
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3646
		#$result["error"],錯誤訊息陣列.
3647
		#$resutl["function"],當前執行的涵式名稱.
3648
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
3649
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
3650
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
3651
		#必填參數:
3652
		$conf["fileAccess.checkMultiFileExist"]["fileArray"]=array($conf["fileAddress"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
3653
		#$conf["fileAccess.checkMultiFileExist"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3654
		$conf["fileAccess.checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
3655
		#可省略參數:
3656
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
3657
		#$conf["disableWebSearch"]="false";
3658
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
3659
		#$conf["userDir"]="true";
3660
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
3661
		$conf["fileAccess.checkMultiFileExist"]["web"]="false";
3662
		#參考資料來源:
3663
		#http://php.net/manual/en/function.file-exists.php
3664
		#http://php.net/manual/en/control-structures.foreach.php
3665
		$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess.checkMultiFileExist"]);
3666
		unset($conf["fileAccess.checkMultiFileExist"]);
3667
 
3668
		#var_dump($checkResult);
3669
 
3670
		#如果檢查檔案是否存在失敗
3671
		if($checkResult["status"]==="false"){
226 liveuser 3672
 
3 liveuser 3673
			#設置執行失敗
3674
			$result["status"]="false";
3675
 
3676
			#回傳錯誤訊息
3677
			$result["error"]=$checkResult;
3678
 
3679
			#回傳結果
3680
			return $result;
226 liveuser 3681
 
3 liveuser 3682
			}#if end
3683
 
3684
		#如果目標檔案不存在
3685
		if($checkResult["varExist"][0]==="false"){
226 liveuser 3686
 
3 liveuser 3687
			#設置錯誤識別
3688
			$result["status"]="true";
3689
 
3690
			#回傳錯誤訊息
3691
			$result["warning"][]="要移除的檔案不存在";
3692
 
3693
			#回傳結果
3694
			return $result;
226 liveuser 3695
 
3 liveuser 3696
			}#if end
3697
 
3698
		#如果要移除的目標是檔案
3699
		if(is_file($conf["fileAddress"])){
226 liveuser 3700
 
3 liveuser 3701
			#移除檔案,並回傳移除的結果
3702
			$eraseResult=(@unlink($conf["fileAddress"]));
3703
 
3704
			#如果 $eraseResult 等於 false
3705
			if($eraseResult===false){
226 liveuser 3706
 
3 liveuser 3707
				#設置錯誤識別
3708
				$result["status"]="false";
3709
 
3710
				#回傳錯誤訊息
3711
				$result["error"][]="檔案移除失敗";
3712
 
3713
				#回傳結果
3714
				return $result;
226 liveuser 3715
 
3 liveuser 3716
				}#if end
226 liveuser 3717
 
3 liveuser 3718
			}#if end
3719
 
3720
		#反之要移除的目標是目錄
3721
		else if(is_dir($conf["fileAddress"])){
226 liveuser 3722
 
3 liveuser 3723
			#如果允許移除目錄
3724
			if($conf["allowDelFolder"]==="true"){
226 liveuser 3725
 
3 liveuser 3726
				#移除目錄跟底下的內容
3727
				w函式說明:
3728
				#呼叫shell執行系統命令,並取得回傳的內容.
3729
				#回傳結果:
3730
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3731
				#$result["error"],錯誤訊息陣列.
3732
				#$result["function"],當前執行的函數名稱.
3733
				#$result["argu"],使用的參數.
3734
				#$result["cmd"],執行的指令內容.
3735
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
3736
				#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
3737
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
3738
				#$result["running"],是否還在執行.
3739
				#$result["pid"],pid.
3740
				#$result["statusCode"],執行結束後的代碼.
3741
				#必填參數:
3742
				#$conf["command"],字串,要執行的指令.
3743
				$conf["external::callShell"]["command"]="rm";
3744
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3745
				$conf["external::callShell"]["fileArgu"]=__FILE__;
3746
				#可省略參數:
3747
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3748
				$conf["external::callShell"]["argu"]=array("-rf",$conf["fileAddress"]);
3749
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
3750
				#$conf["arguIsAddr"]=array();
3751
				#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
3752
				#$conf["plainArgu"]=array();
3753
				#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
3754
				#$conf["useApostrophe"]=array();
3755
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
3756
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
3757
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
3758
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
3759
				#$conf["enablePrintDescription"]="true";
3760
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
3761
				#$conf["printDescription"]="";
3762
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
3763
				$conf["external::callShell"]["escapeshellarg"]="true";
3764
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
3765
				#$conf["thereIsShellVar"]=array();
3766
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
3767
				#$conf["username"]="";
3768
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
3769
				#$conf["password"]="";
3770
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
3771
				#$conf["useScript"]="";
3772
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
3773
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
3774
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
3775
				#$conf["inBackGround"]="";
3776
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
3777
				#$conf["getErr"]="false";
3778
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
3779
				#$conf["doNotRun"]="false";
3780
				#參考資料:
3781
				#exec=>http://php.net/manual/en/function.exec.php
3782
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
3783
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
3784
				#備註:
3785
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
3786
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
3787
				$callShell=external::callShell($conf["external::callShell"]);
3788
				unset($conf["external::callShell"]);
226 liveuser 3789
 
3 liveuser 3790
				#如果執行失敗
3791
				if($callShell["status"]==="false"){
226 liveuser 3792
 
3 liveuser 3793
					#設置錯誤識別
3794
					$result["status"]="false";
3795
 
3796
					#回傳錯誤訊息
3797
					$result["error"]=$callShell;
3798
 
3799
					#回傳結果
3800
					return $result;
226 liveuser 3801
 
3 liveuser 3802
					}#if end
226 liveuser 3803
 
3804
				}#if end
3805
 
3 liveuser 3806
			#反之不允許
3807
			else{
226 liveuser 3808
 
3 liveuser 3809
				#設置錯誤識別
3810
				$result["status"]="false";
3811
 
3812
				#回傳錯誤訊息
3813
				$result["error"][]="不允許移除目錄";
226 liveuser 3814
 
3 liveuser 3815
				#回傳結果
3816
				return $result;
226 liveuser 3817
 
3 liveuser 3818
				}#else end
226 liveuser 3819
 
3 liveuser 3820
			}#if end
226 liveuser 3821
 
3 liveuser 3822
		#反之
3823
		else{
226 liveuser 3824
 
3 liveuser 3825
			#可能為 軟連結
226 liveuser 3826
 
3 liveuser 3827
			#如果允許移除
3828
			if($conf["allowDelSymlink"]==="true"){
226 liveuser 3829
 
3 liveuser 3830
				#移除檔案,並回傳移除的結果
3831
				$eraseResult=(@unlink($conf["fileAddress"]));
3832
 
3833
				#如果 $eraseResult 等於 false
3834
				if($eraseResult===false){
226 liveuser 3835
 
3 liveuser 3836
					#設置錯誤識別
3837
					$result["status"]="false";
3838
 
3839
					#回傳錯誤訊息
3840
					$result["error"][]="檔案移除失敗";
3841
 
3842
					#回傳結果
3843
					return $result;
226 liveuser 3844
 
3 liveuser 3845
					}#if end
226 liveuser 3846
 
3 liveuser 3847
				}#if end
226 liveuser 3848
 
3 liveuser 3849
			#反之
3850
			else{
226 liveuser 3851
 
3 liveuser 3852
				#設置錯誤識別
3853
				$result["status"]="false";
226 liveuser 3854
 
3 liveuser 3855
				#設置錯誤訊息
3856
				$result["error"][]="不允許移除 檔案、目錄 以外類型的目標";
3857
 
3858
				#回傳結果
3859
				return $result;
226 liveuser 3860
 
3 liveuser 3861
				}#else end
226 liveuser 3862
 
3 liveuser 3863
			}#else end
226 liveuser 3864
 
3 liveuser 3865
		#執行到這邊代表執行正常.
3866
		$result["status"]="true";
226 liveuser 3867
 
3 liveuser 3868
		#回傳結果
3869
		return $result;
3870
 
3871
		}#function delFile end
226 liveuser 3872
 
3 liveuser 3873
	/*
3874
	#函式說明:
3875
	#移除多個檔案
3876
	#回傳結果:
3877
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
3878
	#$result["error"],錯誤訊息陣列
3879
	#$result["function"],當前執行的函數名稱.
3880
	#$result["argu"],使用的參數.
3881
	#$result["content"],陣列,移除各個檔案的結果.
3882
	#必填參數:
3883
	#$conf["fileAddress"],字串陣列,要移除檔案的位置.
3884
	$conf["fileAddress"]=array("");
3885
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3886
	$conf["fileArgu"]=__FILE__;
3887
	#可省略參數:
3888
	#無.
3889
	#參考資料:
3890
	#無.
3891
	#備註:
3892
	#無.
220 liveuser 3893
	*/
3 liveuser 3894
	public static function delMultiFile(&$conf){
226 liveuser 3895
 
3 liveuser 3896
		#初始化要回傳的結果
3897
		$result=array();
226 liveuser 3898
 
3 liveuser 3899
		#設置當其函數名稱
3900
		$result["function"]=__FUNCTION__;
226 liveuser 3901
 
3 liveuser 3902
		#如果 $conf 不為陣列
3903
		if(gettype($conf)!="array"){
226 liveuser 3904
 
3 liveuser 3905
			#設置執行失敗
3906
			$result["status"]="false";
226 liveuser 3907
 
3 liveuser 3908
			#設置執行錯誤訊息
3909
			$result["error"][]="\$conf變數須為陣列形態";
3910
 
3911
			#如果傳入的參數為 null
3912
			if($conf==null){
226 liveuser 3913
 
3 liveuser 3914
				#設置執行錯誤訊息
3915
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3916
 
3 liveuser 3917
				}#if end
3918
 
3919
			#回傳結果
3920
			return $result;
226 liveuser 3921
 
3 liveuser 3922
			}#if end
226 liveuser 3923
 
3 liveuser 3924
		#取得使用的參數.
3925
		$result["argu"]=$conf;
226 liveuser 3926
 
3 liveuser 3927
		#檢查參數
3928
		#函式說明:
3929
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3930
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3931
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3932
		#$result["function"],當前執行的函式名稱.
3933
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3934
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3935
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3936
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3937
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3938
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3939
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3940
		#必填寫的參數:
3941
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3942
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3943
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3944
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddress");
226 liveuser 3945
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3946
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
3947
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3948
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3949
		#可以省略的參數:
3950
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3951
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3952
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3953
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray");
226 liveuser 3954
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3955
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
3956
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3957
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
3958
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3959
		#$conf["arrayCountEqualCheck"][]=array();
3960
		#參考資料來源:
3961
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3962
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3963
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3964
 
3 liveuser 3965
		#如果檢查失敗
3966
		if($checkResult["status"]=="false"){
226 liveuser 3967
 
3 liveuser 3968
			#設置錯誤識別
3969
			$result["status"]="false";
226 liveuser 3970
 
3 liveuser 3971
			#設置錯誤訊息
3972
			$result["error"]=$checkResult;
226 liveuser 3973
 
3 liveuser 3974
			#回傳結果
3975
			return $result;
226 liveuser 3976
 
3 liveuser 3977
			}#if end
226 liveuser 3978
 
3 liveuser 3979
		#如果檢查不通過
3980
		if($checkResult["passed"]=="false"){
226 liveuser 3981
 
3 liveuser 3982
			#設置錯誤識別
3983
			$result["status"]="false";
226 liveuser 3984
 
3 liveuser 3985
			#設置錯誤訊息
3986
			$result["error"]=$checkResult;
226 liveuser 3987
 
3 liveuser 3988
			#回傳結果
3989
			return $result;
226 liveuser 3990
 
3 liveuser 3991
			}#if end
226 liveuser 3992
 
3 liveuser 3993
		#針對每個要移除的檔案
3994
		foreach($conf["fileAddress"] as $fileAddr){
226 liveuser 3995
 
3 liveuser 3996
			#函式說明:
3997
			#移除檔案
3998
			#回傳結果:
3999
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
4000
			#$result["error"],錯誤訊息陣列
4001
			#$result["warning"],警告訊息陣列
4002
			#$result["function"],當前執行的函數名稱
4003
			#必填參數:
4004
			#$conf["fileAddress"],字串,要移除檔案的位置.
4005
			$conf["fileAccess::delFile"]["fileAddress"]=$fileAddr;
4006
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
4007
			$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
4008
			#可省略參數:
4009
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
4010
			#$conf["commentsArray"]=array("");
4011
			#備註:
4012
			#無.
4013
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
4014
			unset($conf["fileAccess::delFile"]);
226 liveuser 4015
 
3 liveuser 4016
			#如果檢查失敗
4017
			if($delFile["status"]==="false"){
226 liveuser 4018
 
3 liveuser 4019
				#設置錯誤識別
4020
				$result["status"]="false";
226 liveuser 4021
 
3 liveuser 4022
				#設置錯誤訊息
4023
				$result["error"]=$delFile;
226 liveuser 4024
 
3 liveuser 4025
				#回傳結果
4026
				return $result;
226 liveuser 4027
 
3 liveuser 4028
				}#if end
226 liveuser 4029
 
3 liveuser 4030
			#取得移除檔案的結果
4031
			$result["content"][]=$delFile;
226 liveuser 4032
 
3 liveuser 4033
			}#foreach end
226 liveuser 4034
 
3 liveuser 4035
		#設置執行正常
4036
		$result["status"]="true";
226 liveuser 4037
 
3 liveuser 4038
		#回傳結果
4039
		return $result;
226 liveuser 4040
 
3 liveuser 4041
		}#function delMultiFile end
226 liveuser 4042
 
3 liveuser 4043
	/*
4044
	#函式說明:
4045
	#確保路徑存在.
4046
	#回傳結果:
4047
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4048
	#$result["error"],錯誤訊息陣列.
4049
	#$resutl["function"],當前執行的涵式名稱.
4050
	#$result["path"],建立好的路徑字串.
4051
	#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
4052
	#$result["argu"],使用的參數.
4053
	#必填參數:
4054
	#$conf["path"],要檢查的路徑
226 liveuser 4055
	$conf["path"]="";
3 liveuser 4056
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4057
	$conf["fileArgu"]=__FILE__;
4058
	#可省略參數:
4059
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4060
	#$conf["haveFileName"]="false";
4061
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人無法使用.
4062
	#$conf["dirPermission"]="";
4063
	#$conf["web"],是否為檔案系統,"true"為網頁路徑,"false"為網頁系統,預設為"false".
4064
	#$conf["web"]="";
4065
	#參考資料:
4066
	#無.
4067
	#備註:
4068
	#無.
226 liveuser 4069
	*/
3 liveuser 4070
	public static function validatePath(&$conf){
226 liveuser 4071
 
3 liveuser 4072
		#初始化要回傳的結果
4073
		$result=array();
226 liveuser 4074
 
3 liveuser 4075
		#設置當其函數名稱
4076
		$result["function"]=__FUNCTION__;
226 liveuser 4077
 
3 liveuser 4078
		#如果 $conf 不為陣列
4079
		if(gettype($conf)!="array"){
226 liveuser 4080
 
3 liveuser 4081
			#設置執行失敗
4082
			$result["status"]="false";
226 liveuser 4083
 
3 liveuser 4084
			#設置執行錯誤訊息
4085
			$result["error"][]="\$conf變數須為陣列形態";
4086
 
4087
			#如果傳入的參數為 null
4088
			if($conf==null){
226 liveuser 4089
 
3 liveuser 4090
				#設置執行錯誤訊息
4091
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4092
 
3 liveuser 4093
				}#if end
226 liveuser 4094
 
3 liveuser 4095
			#回傳結果
4096
			return $result;
226 liveuser 4097
 
3 liveuser 4098
			}#if end
226 liveuser 4099
 
3 liveuser 4100
		#取得使用的參數
226 liveuser 4101
		$result["argu"]=$conf;
4102
 
3 liveuser 4103
		#檢查參數
4104
		#函式說明:
4105
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4106
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4107
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4108
		#$result["function"],當前執行的函式名稱.
4109
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4110
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4111
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4112
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
4113
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
4114
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4115
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4116
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4117
		#必填寫的參數:
4118
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4119
		$conf["variableCheck::checkArgument"]["varInput"]=&$conf;
4120
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4121
		$conf["variableCheck::checkArgument"]["mustBeFilledVariableName"]=array("path","fileArgu");
4122
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
4123
		$conf["variableCheck::checkArgument"]["mustBeFilledVariableType"]=array("string","string");
4124
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4125
		$conf["variableCheck::checkArgument"]["referenceVarKey"]="variableCheck::checkArgument";
4126
		#可以省略的參數:
4127
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4128
		$conf["variableCheck::checkArgument"]["canBeEmptyString"]="false";
4129
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
4130
		$conf["variableCheck::checkArgument"]["skipableVariableCanNotBeEmpty"]=array("haveFileName","dirPermission","web");
4131
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4132
		$conf["variableCheck::checkArgument"]["skipableVariableName"]=array("haveFileName","dirPermission","web");
226 liveuser 4133
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4134
		$conf["variableCheck::checkArgument"]["skipableVariableType"]=array("string","string","string");
4135
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4136
		$conf["variableCheck::checkArgument"]["skipableVarDefaultValue"]=array("false","0770","false");
4137
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4138
		#$conf["arrayCountEqualCheck"][]=array();
4139
		#參考資料來源:
4140
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4141
		$checkArgument=variableCheck::checkArguments($conf["variableCheck::checkArgument"]);
4142
		unset($conf["variableCheck::checkArgument"]);
226 liveuser 4143
 
3 liveuser 4144
		#如果檢查過程出錯
4145
		if($checkArgument["status"]==="false"){
226 liveuser 4146
 
3 liveuser 4147
			#設置執行失敗
4148
			$result["status"]="false";
226 liveuser 4149
 
3 liveuser 4150
			#設置執行錯誤訊息
4151
			$result["error"]=$checkArgument;
4152
 
4153
			#回傳結果
4154
			return $result;
226 liveuser 4155
 
3 liveuser 4156
			}#if end
226 liveuser 4157
 
3 liveuser 4158
		#如果檢查不通過
4159
		if($checkArgument["passed"]==="false"){
226 liveuser 4160
 
3 liveuser 4161
			#設置執行失敗
4162
			$result["status"]="false";
226 liveuser 4163
 
3 liveuser 4164
			#設置執行錯誤訊息
4165
			$result["error"]=$checkArgument;
4166
 
4167
			#回傳結果
4168
			return $result;
226 liveuser 4169
 
3 liveuser 4170
			}#if end
226 liveuser 4171
 
3 liveuser 4172
		#函式說明:
4173
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
4174
		#回傳結果:
4175
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
4176
		#$result["error"],錯誤訊息陣列.
226 liveuser 4177
		#$result["function"],函數名稱.
3 liveuser 4178
		#$result["argu"],使用的參數.
4179
		#$result["content"],網址,若是在命令列執行,則為"null".
4180
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
4181
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
4182
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
4183
		#必填參數:
4184
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
4185
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["path"];
4186
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
4187
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
4188
		#可省略參數:
4189
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
4190
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
4191
		#備註:
4192
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
4193
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 4194
		unset($conf["fileAccess::getInternetAddressV2"]);
4195
 
3 liveuser 4196
		#如果檢查過程出錯
4197
		if($getInternetAddressV2["status"]=="false"){
226 liveuser 4198
 
3 liveuser 4199
			#設置執行失敗
4200
			$result["status"]="false";
226 liveuser 4201
 
3 liveuser 4202
			#設置執行錯誤訊息
4203
			$result["error"]=$getInternetAddressV2;
4204
 
4205
			#回傳結果
4206
			return $result;
226 liveuser 4207
 
4208
			}#if end
4209
 
3 liveuser 4210
		#取得轉換好的絕對路徑
4211
		$result["path"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 4212
 
3 liveuser 4213
		#debug
4214
		#var_dump($getInternetAddressV2);exit;
226 liveuser 4215
 
3 liveuser 4216
		#如果 路徑 含有檔案名稱
4217
		if($conf["haveFileName"]==="true"){
226 liveuser 4218
 
3 liveuser 4219
			#預設要加回去的結束字串為空字串
4220
			$endStr="";
226 liveuser 4221
 
3 liveuser 4222
			#如果開頭跟結尾都是 "'"
4223
			if( strpos($result["path"],"'")===0 && strpos($result["path"],"'")===(strlen($result["path"])-1) ){
226 liveuser 4224
 
3 liveuser 4225
				#設置要加回去的結束字串
4226
				$endStr="'";
226 liveuser 4227
 
3 liveuser 4228
				}#if end
226 liveuser 4229
 
3 liveuser 4230
			#函式說明:
4231
			#將固定格式的字串分開,並回傳分開的結果。
4232
			#回傳結果:
4233
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4234
			#$result["error"],錯誤訊息陣列
4235
			#$result["function"],當前執行的函數名稱.
4236
			#$result["argu"],使用的參數.
4237
			#$result["oriStr"],要分割的原始字串內容
4238
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4239
			#$result["dataCounts"],爲總共分成幾段
4240
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
4241
			#必填參數:
4242
			#$conf["stringIn"],字串,要處理的字串.
4243
			$conf["stringProcess::spiltString"]["stringIn"]=$result["path"];
4244
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
4245
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
4246
			#可省略參數:
4247
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
4248
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
4249
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4250
			unset($conf["stringProcess::spiltString"]);
226 liveuser 4251
 
3 liveuser 4252
			#如果檢查過程出錯
4253
			if($spiltString["status"]==="false"){
226 liveuser 4254
 
3 liveuser 4255
				#設置執行失敗
4256
				$result["status"]="false";
226 liveuser 4257
 
3 liveuser 4258
				#設置執行錯誤訊息
4259
				$result["error"]=$spiltString;
4260
 
4261
				#回傳結果
4262
				return $result;
226 liveuser 4263
 
3 liveuser 4264
				}#if end
226 liveuser 4265
 
3 liveuser 4266
			#初始化儲存 path
4267
			$path="";
226 liveuser 4268
 
3 liveuser 4269
			#針對n-1段的內容
4270
			for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 4271
 
3 liveuser 4272
				#串接路徑
4273
				$path=$path."/".$spiltString["dataArray"][$i];
226 liveuser 4274
 
3 liveuser 4275
				}#for end
226 liveuser 4276
 
3 liveuser 4277
			#如果路徑為空
4278
			if($path===""){
226 liveuser 4279
 
3 liveuser 4280
				#則與設為根目錄
4281
				$path="/";
226 liveuser 4282
 
3 liveuser 4283
				}#if end
226 liveuser 4284
 
3 liveuser 4285
			#設置檔案名稱
4286
			$result["fileName"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 4287
 
3 liveuser 4288
			#取得不含檔案名稱的路徑
4289
			$conf["path"]=$path.$endStr;
226 liveuser 4290
 
3 liveuser 4291
			#取得不含檔案名稱的路徑
4292
			$result["path"]=$path.$endStr;
226 liveuser 4293
 
3 liveuser 4294
			}#if end
226 liveuser 4295
 
3 liveuser 4296
		#函式說明:
4297
		#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
4298
		#回傳結果:
4299
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
4300
		#$result["error"],錯誤訊息陣列
4301
		#必填參數:
4302
		$conf["fileAccess::createFolderAfterCheck"]["dirPositionAndName"]=$conf["path"];#新建的位置與名稱
4303
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4304
		$conf["fileAccess::createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
4305
		#可省略參數:
4306
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
4307
		$conf["fileAccess::createFolderAfterCheck"]["dirPermission"]=$conf["dirPermission"];
4308
		$conf["fileAccess::createFolderAfterCheck"]["web"]="false";
4309
		#參考資料:
4310
		#mkdir=>http://php.net/manual/en/function.mkdir.php
4311
		#chmod=>http://php.net/manual/en/function.chmod.php
4312
		$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf["fileAccess::createFolderAfterCheck"]);
4313
		unset($conf["fileAccess::createFolderAfterCheck"]);
226 liveuser 4314
 
3 liveuser 4315
		#如果建立路徑過程出錯
4316
		if($createFolderAfterCheck["status"]==="false"){
226 liveuser 4317
 
3 liveuser 4318
			#設置執行失敗
4319
			$result["status"]="false";
226 liveuser 4320
 
3 liveuser 4321
			#設置執行錯誤訊息
4322
			$result["error"]=$createFolderAfterCheck;
4323
 
4324
			#回傳結果
4325
			return $result;
226 liveuser 4326
 
3 liveuser 4327
			}#if end
226 liveuser 4328
 
3 liveuser 4329
		#如果有警告訊息
4330
		if(count($createFolderAfterCheck["warning"])>0){
226 liveuser 4331
 
3 liveuser 4332
			#取得警告訊息
4333
			$result["error"]=$createFolderAfterCheck["warning"];
226 liveuser 4334
 
3 liveuser 4335
			#設置執行失敗
4336
			$result["status"]="false";
226 liveuser 4337
 
3 liveuser 4338
			#回傳結果
4339
			return $result;
226 liveuser 4340
 
3 liveuser 4341
			}#if end
226 liveuser 4342
 
3 liveuser 4343
		#執行到這邊代表成功
4344
		$result["status"]="true";
226 liveuser 4345
 
3 liveuser 4346
		#回傳結果
4347
		return $result;
226 liveuser 4348
 
3 liveuser 4349
		}#function validatePath end
226 liveuser 4350
 
3 liveuser 4351
	/*
4352
	#函式說明:
4353
	#解析路徑的每個層級.
4354
	#回傳結果:
4355
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4356
	#$result["error"],錯誤訊息陣列.
4357
	#$resutl["function"],當前執行的涵式名稱.
4358
	#$result["argu"],使用的參數.
4359
	#$result["content"],解析出來的路徑階層.
4360
	#必填參數:
4361
	#$conf["path"],要檢查的路徑
4362
	$conf["path"]="";
4363
	#可省略參數:
4364
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4365
	#$conf["haveFileName"]="false";
4366
	#參考資料:
4367
	#無.
4368
	#備註:
4369
	#無.
4370
	*/
4371
	public static function parsePath(&$conf){
226 liveuser 4372
 
3 liveuser 4373
		#初始化要回傳的內容
4374
		$result=array();
4375
 
4376
		#取得當前執行的函數名稱
4377
		$result["function"]=__FUNCTION__;
4378
 
4379
		#如果 $conf 不為陣列
4380
		if(gettype($conf)!="array"){
226 liveuser 4381
 
3 liveuser 4382
			#設置執行失敗
4383
			$result["status"]="false";
226 liveuser 4384
 
3 liveuser 4385
			#設置執行錯誤訊息
4386
			$result["error"][]="\$conf變數須為陣列形態";
4387
 
4388
			#如果傳入的參數為 null
4389
			if($conf==null){
226 liveuser 4390
 
3 liveuser 4391
				#設置執行錯誤訊息
4392
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4393
 
3 liveuser 4394
				}#if end
4395
 
4396
			#回傳結果
4397
			return $result;
226 liveuser 4398
 
3 liveuser 4399
			}#if end
4400
 
4401
		#記錄使用的參數
4402
		$result["argu"]=$conf;
4403
 
4404
		#檢查參數
4405
		#函式說明:
4406
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4407
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4408
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4409
		#$result["function"],當前執行的函式名稱.
4410
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4411
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4412
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4413
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4414
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4415
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4416
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4417
		#必填寫的參數:
4418
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4419
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4420
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4421
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
226 liveuser 4422
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 4423
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
4424
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4425
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4426
		#可以省略的參數:
4427
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4428
		#$conf["canBeEmptyString"]="false";
4429
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4430
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("haveFileName");
226 liveuser 4431
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4432
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
4433
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4434
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
4435
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4436
		#$conf["arrayCountEqualCheck"][]=array();
4437
		#參考資料來源:
4438
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4439
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4440
		unset($conf["variableCheck::checkArguments"]);
4441
 
4442
		#如果檢查有誤
4443
		if($checkResult["status"]=="false"){
226 liveuser 4444
 
3 liveuser 4445
			#設置錯誤識別
4446
			$result["status"]="false";
226 liveuser 4447
 
3 liveuser 4448
			#設置錯誤訊息
4449
			$result["error"]=$checkResult;
226 liveuser 4450
 
3 liveuser 4451
			#回傳結果
4452
			return $result;
226 liveuser 4453
 
3 liveuser 4454
			}#if end
226 liveuser 4455
 
3 liveuser 4456
		#如果檢查不通過
4457
		if($checkResult["passed"]=="false"){
226 liveuser 4458
 
3 liveuser 4459
			#設置錯誤識別
4460
			$result["status"]="false";
226 liveuser 4461
 
3 liveuser 4462
			#設置錯誤訊息
4463
			$result["error"]=$checkResult;
226 liveuser 4464
 
3 liveuser 4465
			#回傳結果
4466
			return $result;
226 liveuser 4467
 
3 liveuser 4468
			}#if end
226 liveuser 4469
 
3 liveuser 4470
		#函式說明:
4471
		#將固定格式的字串分開,並回傳分開的結果.
4472
		#回傳結果:
4473
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4474
		#$result["error"],錯誤訊息陣列
4475
		#$result["function"],當前執行的函數名稱.
4476
		#$result["argu"],使用的參數.
4477
		#$result["oriStr"],要分割的原始字串內容
4478
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4479
		#$result["dataCounts"],爲總共分成幾段
4480
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
4481
		#必填參數:
4482
		#$conf["stringIn"],字串,要處理的字串.
4483
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["path"];
4484
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
4485
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
4486
		#可省略參數:
4487
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
4488
		#$conf["allowEmptyStr"]="false";
4489
		#參考資料:
4490
		#無.
4491
		#備註:
4492
		#無.
4493
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4494
		unset($conf["stringProcess::spiltString"]);
226 liveuser 4495
 
3 liveuser 4496
		#如果檢查有誤
4497
		if($spiltString["status"]==="false"){
226 liveuser 4498
 
3 liveuser 4499
			#設置錯誤識別
4500
			$result["status"]="false";
226 liveuser 4501
 
3 liveuser 4502
			#設置錯誤訊息
4503
			$result["error"]=$spiltString;
226 liveuser 4504
 
3 liveuser 4505
			#回傳結果
4506
			return $result;
226 liveuser 4507
 
3 liveuser 4508
			}#if end
226 liveuser 4509
 
3 liveuser 4510
		#確認是否為絕對路徑
4511
		#函式說明:
4512
		#取得符合特定字首與字尾的字串
4513
		#回傳結果:
4514
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
4515
		#$result["function"],當前執行的函數名稱.
4516
		#$result["error"],錯誤訊息陣列.
4517
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
4518
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
4519
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
4520
		#$result["argu"],使用的參數.
4521
		#必填參數:
4522
		#$conf["checkString"],字串,要檢查的字串.
4523
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["path"];
4524
		#可省略參數:
4525
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
4526
		$conf["search::getMeetConditionsString"]["frontWord"]="/";
4527
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
4528
		#$conf["search::getMeetConditionsString"]["tailWord"]="";
4529
		#參考資料:
4530
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
4531
		#備註:
4532
		#無.
4533
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
4534
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 4535
 
3 liveuser 4536
		#如果檢查有誤
4537
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 4538
 
3 liveuser 4539
			#設置錯誤識別
4540
			$result["status"]="false";
226 liveuser 4541
 
3 liveuser 4542
			#設置錯誤訊息
4543
			$result["error"]=$getMeetConditionsString;
226 liveuser 4544
 
3 liveuser 4545
			#回傳結果
4546
			return $result;
226 liveuser 4547
 
3 liveuser 4548
			}#if end
226 liveuser 4549
 
3 liveuser 4550
		#如果是絕對路徑
4551
		if($getMeetConditionsString["founded"]==="true"){
226 liveuser 4552
 
3 liveuser 4553
			#初始化路徑為 "/"
4554
			$result["content"][]="/";
226 liveuser 4555
 
3 liveuser 4556
			}#if end
226 liveuser 4557
 
3 liveuser 4558
		#針對每個切割出來的路徑階層
4559
		foreach($spiltString["dataArray"] as $index => $dir){
226 liveuser 4560
 
3 liveuser 4561
			#如果路徑結尾含有檔案名稱
4562
			if($conf["haveFileName"]==="true"){
226 liveuser 4563
 
3 liveuser 4564
				#如果是最後一段
4565
				if($index===$spiltString["dataCounts"]-1){
226 liveuser 4566
 
3 liveuser 4567
					#忽略
4568
					continue;
226 liveuser 4569
 
3 liveuser 4570
					}#if end
226 liveuser 4571
 
3 liveuser 4572
				}#if end
226 liveuser 4573
 
3 liveuser 4574
			#後面加上 資料夾名稱 跟 "/"
4575
			$newPath=$dir."/";
226 liveuser 4576
 
3 liveuser 4577
			#如果有 content
4578
			if(isset($result["content"])){
226 liveuser 4579
 
3 liveuser 4580
				#如果有上個資料夾
4581
				if(isset($result["content"][count($result["content"])-1])){
226 liveuser 4582
 
3 liveuser 4583
					#後面加上 上個資料夾名稱 加上資料夾名稱 跟 "/"
4584
					$newPath=$result["content"][count($result["content"])-1].$dir."/";
226 liveuser 4585
 
3 liveuser 4586
					}#if end
226 liveuser 4587
 
3 liveuser 4588
				}#if end
226 liveuser 4589
 
3 liveuser 4590
			#並新增置結果
4591
			$result["content"][]=$newPath;
226 liveuser 4592
 
3 liveuser 4593
			}#foreach end
226 liveuser 4594
 
3 liveuser 4595
		#var_dump($result["content"]);
226 liveuser 4596
 
3 liveuser 4597
		#設置執行正常
4598
		$result["status"]="true";
226 liveuser 4599
 
3 liveuser 4600
		#回傳結果
4601
		return $result;
226 liveuser 4602
 
3 liveuser 4603
		}#function parsePath end
226 liveuser 4604
 
3 liveuser 4605
	/*
4606
	#函式說明:
4607
	#檢查路徑是否存在.
4608
	#回傳結果:
4609
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4610
	#$result["error"],錯誤訊息陣列.
4611
	#$resutl["function"],當前執行的涵式名稱.
4612
	#$result["argu"],使用的參數.
4613
	#$result["found"],路徑是否存在,"true"代表存在,"false"代表不存在.
4614
	#$result["content"],每個階層路徑的檢查結果,每個元素有檢查的路徑"path"跟是否有存在或可存取的識別"found".
4615
	#必填參數:
4616
	#$conf["path"],要檢查的路徑
4617
	$conf["path"]="";
4618
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4619
	$conf["fileArgu"]=__FILE__;
4620
	#可省略參數:
4621
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4622
	#$conf["haveFileName"]="false";
4623
	#參考資料:
4624
	#無.
4625
	#備註:
4626
	#無.
4627
	*/
4628
	public static function checkPathExist(&$conf){
226 liveuser 4629
 
3 liveuser 4630
		#初始化要回傳的內容
4631
		$result=array();
4632
 
4633
		#取得當前執行的函數名稱
4634
		$result["function"]=__FUNCTION__;
4635
 
4636
		#如果 $conf 不為陣列
4637
		if(gettype($conf)!="array"){
226 liveuser 4638
 
3 liveuser 4639
			#設置執行失敗
4640
			$result["status"]="false";
226 liveuser 4641
 
3 liveuser 4642
			#設置執行錯誤訊息
4643
			$result["error"][]="\$conf變數須為陣列形態";
4644
 
4645
			#如果傳入的參數為 null
4646
			if($conf==null){
226 liveuser 4647
 
3 liveuser 4648
				#設置執行錯誤訊息
4649
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4650
 
3 liveuser 4651
				}#if end
4652
 
4653
			#回傳結果
4654
			return $result;
226 liveuser 4655
 
3 liveuser 4656
			}#if end
4657
 
4658
		#記錄使用的參數
4659
		$result["argu"]=$conf;
4660
 
4661
		#檢查參數
4662
		#函式說明:
4663
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4664
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4665
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4666
		#$result["function"],當前執行的函式名稱.
4667
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4668
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4669
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4670
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4671
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4672
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4673
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4674
		#必填寫的參數:
4675
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4676
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4677
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4678
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 4679
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 4680
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
4681
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4682
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4683
		#可以省略的參數:
4684
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4685
		#$conf["canBeEmptyString"]="false";
4686
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4687
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("haveFileName");
226 liveuser 4688
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4689
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
4690
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4691
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
4692
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4693
		#$conf["arrayCountEqualCheck"][]=array();
4694
		#參考資料來源:
4695
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4696
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4697
		unset($conf["variableCheck::checkArguments"]);
4698
 
4699
		#如果檢查有誤
4700
		if($checkResult["status"]=="false"){
226 liveuser 4701
 
3 liveuser 4702
			#設置錯誤識別
4703
			$result["status"]="false";
226 liveuser 4704
 
3 liveuser 4705
			#設置錯誤訊息
4706
			$result["error"]=$checkResult;
226 liveuser 4707
 
3 liveuser 4708
			#回傳結果
4709
			return $result;
226 liveuser 4710
 
3 liveuser 4711
			}#if end
226 liveuser 4712
 
3 liveuser 4713
		#如果檢查不通過
4714
		if($checkResult["passed"]=="false"){
226 liveuser 4715
 
3 liveuser 4716
			#設置錯誤識別
4717
			$result["status"]="false";
226 liveuser 4718
 
3 liveuser 4719
			#設置錯誤訊息
4720
			$result["error"]=$checkResult;
226 liveuser 4721
 
3 liveuser 4722
			#回傳結果
4723
			return $result;
226 liveuser 4724
 
3 liveuser 4725
			}#if end
226 liveuser 4726
 
3 liveuser 4727
		#函式說明:
4728
		#解析路徑的每個層級.
4729
		#回傳結果:
4730
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4731
		#$result["error"],錯誤訊息陣列.
4732
		#$resutl["function"],當前執行的涵式名稱.
4733
		#$result["argu"],使用的參數.
4734
		#$result["content"],解析出來的路徑階層.
4735
		#必填參數:
4736
		#$conf["path"],要檢查的路徑
4737
		$conf["fileAccess::parsePath"]["path"]=$conf["path"];
4738
		#可省略參數:
4739
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4740
		$conf["fileAccess::parsePath"]["haveFileName"]=$conf["haveFileName"];
4741
		#參考資料:
4742
		#無.
4743
		#備註:
4744
		#無.
4745
		$parsePath=fileAccess::parsePath($conf["fileAccess::parsePath"]);
4746
		unset($conf["fileAccess::parsePath"]);
226 liveuser 4747
 
3 liveuser 4748
		#如果檢查有誤
4749
		if($parsePath["status"]==="false"){
226 liveuser 4750
 
3 liveuser 4751
			#設置錯誤識別
4752
			$result["status"]="false";
226 liveuser 4753
 
3 liveuser 4754
			#設置錯誤訊息
4755
			$result["error"]=$parsePath;
226 liveuser 4756
 
3 liveuser 4757
			#回傳結果
4758
			return $result;
226 liveuser 4759
 
3 liveuser 4760
			}#if end
226 liveuser 4761
 
3 liveuser 4762
		#函式說明:
4763
		#檢查多個檔案與資料夾是否存在.
4764
		#回傳的結果:
4765
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4766
		#$result["error"],錯誤訊息陣列.
4767
		#$resutl["function"],當前執行的涵式名稱.
4768
		#$result["argu"],使用的參數.
4769
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
4770
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
4771
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
4772
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
4773
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
4774
		#必填參數:
4775
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
4776
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$parsePath["content"];
4777
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4778
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
4779
		#可省略參數:
4780
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
4781
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
4782
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
4783
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
4784
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
4785
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
4786
		#參考資料:
4787
		#http://php.net/manual/en/function.file-exists.php
4788
		#http://php.net/manual/en/control-structures.foreach.php
4789
		#備註:
4790
		#函數file_exists檢查的路徑為檔案系統的路徑
4791
		#$result["varName"][$i]結果未實作
4792
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
4793
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 4794
 
3 liveuser 4795
		#如果執行異常
4796
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 4797
 
3 liveuser 4798
			#設置錯誤識別
4799
			$result["status"]="false";
226 liveuser 4800
 
3 liveuser 4801
			#設置錯誤訊息
4802
			$result["error"]=$checkMultiFileExist;
226 liveuser 4803
 
3 liveuser 4804
			#回傳結果
4805
			return $result;
226 liveuser 4806
 
3 liveuser 4807
			}#if end
226 liveuser 4808
 
3 liveuser 4809
		#如果有路徑無法存取
4810
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 4811
 
3 liveuser 4812
			#設置執行正常識別
4813
			$result["status"]="true";
226 liveuser 4814
 
3 liveuser 4815
			#設置路徑找不到
4816
			$result["found"]="false";
226 liveuser 4817
 
3 liveuser 4818
			#針對每個路徑的搜尋結果
4819
			foreach($checkMultiFileExist["varExist"] as $index => $found){
226 liveuser 4820
 
3 liveuser 4821
				#設置路徑尋找結果
4822
				$result["content"][]=array("found"=>$found,"path"=>$checkMultiFileExist["varNameFullPath"][$index]);
226 liveuser 4823
 
3 liveuser 4824
				}#foreach end
226 liveuser 4825
 
3 liveuser 4826
			#回傳結果
4827
			return $result;
226 liveuser 4828
 
3 liveuser 4829
			}#if end
226 liveuser 4830
 
3 liveuser 4831
		#設置路徑有找到
4832
		$result["found"]="true";
226 liveuser 4833
 
3 liveuser 4834
		#設置執行正常識別
4835
		$result["status"]="true";
226 liveuser 4836
 
3 liveuser 4837
		#回傳結果
4838
		return $result;
226 liveuser 4839
 
3 liveuser 4840
		}#function checkPathExist end
226 liveuser 4841
 
4842
	/*
3 liveuser 4843
	#函式說明:
4844
	#demo建立pdf檔
4845
	#必填參數:
4846
	#無
4847
	#可省略參數:
4848
	#無
4849
	#參考資料:
4850
	#tcpdf=>http://www.tcpdf.org/examples.php
4851
	#備註:
4852
	#開發中,需要安裝 php-tcpdf 套件.
4853
	*/
4854
	public static function demoCreateTcPdfFile(){
226 liveuser 4855
 
3 liveuser 4856
		#避免 TCPDF ERROR: Some data has already been output, can't send PDF file 錯誤產生
4857
		ob_end_clean();
226 liveuser 4858
 
3 liveuser 4859
		#create new PDF document
4860
		$pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
226 liveuser 4861
 
3 liveuser 4862
		#set document information
4863
		$pdf->SetCreator(PDF_CREATOR);
4864
		$pdf->SetAuthor('qbpwc');
4865
		$pdf->SetTitle('pdf sample title');
4866
		$pdf->SetSubject('pdf sample subject');
4867
		$pdf->SetKeywords('pdf, sample, tcpdf, qbpwc');
226 liveuser 4868
 
3 liveuser 4869
		#set default header data
4870
		$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
4871
		$pdf->setFooterData(array(0,64,0), array(0,64,128));
226 liveuser 4872
 
3 liveuser 4873
		#set header and footer fonts
4874
		$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
4875
		$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
226 liveuser 4876
 
3 liveuser 4877
		#set default monospaced font
4878
		$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
226 liveuser 4879
 
3 liveuser 4880
		#set margins
4881
		$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
4882
		$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
4883
		$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
4884
 
4885
		#set auto page breaks
4886
		$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
4887
 
4888
		#set image scale factor
4889
		$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
4890
 
4891
		#set some language-dependent strings (optional)
4892
		if (@file_exists(dirname(__FILE__).'/lang/eng.php')){
226 liveuser 4893
 
3 liveuser 4894
			require_once(dirname(__FILE__).'/lang/eng.php');
226 liveuser 4895
 
3 liveuser 4896
			$pdf->setLanguageArray($l);
226 liveuser 4897
 
3 liveuser 4898
			}#if end
226 liveuser 4899
 
3 liveuser 4900
		#set default font subsetting mode
4901
		$pdf->setFontSubsetting(true);
226 liveuser 4902
 
3 liveuser 4903
		#Set font
4904
		#dejavusans is a UTF-8 Unicode font, if you only need to
4905
		#print standard ASCII chars, you can use core fonts like
4906
		#helvetica or times to reduce file size.
4907
		$pdf->SetFont('dejavusans', '', 14, '', true);
226 liveuser 4908
 
3 liveuser 4909
		#Add a page
4910
		#This method has several options, check the source code documentation for more information.
4911
		$pdf->AddPage();
226 liveuser 4912
 
3 liveuser 4913
		#set text shadow effect
4914
		$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 4915
 
3 liveuser 4916
		#Set some content to print
4917
		$html="<h5>Hello World!</h5>";
226 liveuser 4918
 
3 liveuser 4919
		// Print text using writeHTMLCell()
4920
		$pdf->writeHTMLCell(0,0,'','',$html,0,1,0,true,'',true);
4921
 
4922
		// Close and output PDF document
4923
		// This method has several options, check the source code documentation for more information.
4924
		$pdf->Output('fileAccessT/example_001.pdf','I');
226 liveuser 4925
 
3 liveuser 4926
		}#function demoCreateTcPdfFile end
226 liveuser 4927
 
3 liveuser 4928
	/*
4929
	#函式說明:
4930
	#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
4931
	#回傳的結果:
4932
	#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
4933
	#$result["error"],錯誤訊息.
4934
	#$result["function"],當前執行的函式名稱.
4935
	#$result["filePath"],路徑字串.
4936
	#$result["fileName"],檔案名稱字串.
4937
	#$result["fileExtention"],檔案的副檔名.
4938
	#$result["fullFileName"],含副檔名的檔案名稱.
4939
	#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
4940
	#必填參數:
4941
	#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
4942
	$conf["fileAddressAndName"]="";
4943
	#可省略參數:
4944
	#無.
4945
	#參考資料:
4946
	#無.
4947
	#備註:
4948
	#無.
4949
	*/
4950
	public static function getFileAddressAndNameAndFileExtention(&$conf){
226 liveuser 4951
 
3 liveuser 4952
		#初始化要回傳的參數
4953
		$result=array();
226 liveuser 4954
 
3 liveuser 4955
		#取得當前執行函數名稱
4956
		$result["function"]=__FUNCTION__;
4957
 
4958
		#如果 $conf 不為陣列
4959
		if(gettype($conf)!="array"){
226 liveuser 4960
 
3 liveuser 4961
			#設置執行失敗
4962
			$result["status"]="false";
226 liveuser 4963
 
3 liveuser 4964
			#設置執行錯誤訊息
4965
			$result["error"][]="\$conf變數須為陣列形態";
4966
 
4967
			#如果傳入的參數為 null
4968
			if($conf==null){
226 liveuser 4969
 
3 liveuser 4970
				#設置執行錯誤訊息
4971
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4972
 
3 liveuser 4973
				}#if end
4974
 
4975
			#回傳結果
4976
			return $result;
226 liveuser 4977
 
3 liveuser 4978
			}#if end
4979
 
4980
		#檢查參數
4981
		#函式說明:
4982
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4983
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4984
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4985
		#$result["function"],當前執行的函式名稱.
4986
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4987
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4988
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4989
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4990
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4991
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4992
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4993
		#必填寫的參數:
4994
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4995
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4996
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4997
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileAddressAndName");
226 liveuser 4998
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 4999
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
5000
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5001
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5002
		#可以省略的參數:
5003
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5004
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5005
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5006
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("outputAddress","noDownload");
226 liveuser 5007
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5008
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
5009
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5010
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".bin/".$conf["cppAddress"].".bin","true");
5011
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5012
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
5013
		#參考資料來源:
5014
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5015
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5016
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5017
 
3 liveuser 5018
		#如果 $checkArguments["status"] 等於 "false"
5019
		if($checkArguments["status"]=="false"){
226 liveuser 5020
 
3 liveuser 5021
			#設置 $result["status"] 為 "false"
5022
			$result["status"]="false";
226 liveuser 5023
 
3 liveuser 5024
			#設置 $result["error"]
5025
			$result["error"]=$checkArguments;
226 liveuser 5026
 
3 liveuser 5027
			#回傳結果
5028
			return $result;
226 liveuser 5029
 
3 liveuser 5030
			}#if end
226 liveuser 5031
 
3 liveuser 5032
		#如果 $checkArguments["passed"] 等於 "false"
5033
		if($checkArguments["passed"]=="false"){
226 liveuser 5034
 
3 liveuser 5035
			#設置 $result["status"] 為 "false"
5036
			$result["status"]="false";
226 liveuser 5037
 
3 liveuser 5038
			#設置 $result["error"]
5039
			$result["error"]=$checkArguments;
226 liveuser 5040
 
3 liveuser 5041
			#回傳結果
5042
			return $result;
226 liveuser 5043
 
3 liveuser 5044
			}#if end
226 liveuser 5045
 
3 liveuser 5046
		#確認路徑是否為絕對路徑
5047
		#函式說明:
5048
		#取得符合特定字首與字尾的字串
5049
		#回傳結果:
5050
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
5051
		#$result["function"],當前執行的函數名稱.
5052
		#$result["error"],錯誤訊息陣列.
5053
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
5054
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
5055
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
5056
		#$result["argu"],使用的參數.
5057
		#必填參數:
5058
		#$conf["checkString"],字串,要檢查的字串.
5059
		$conf["fileAccess::getMeetConditionsString"]["checkString"]=$conf["fileAddressAndName"];
5060
		#可省略參數:
5061
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
5062
		$conf["fileAccess::getMeetConditionsString"]["frontWord"]="/";
5063
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
5064
		#$conf["tailWord"]="";
5065
		#參考資料:
5066
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
5067
		#備註:
5068
		#無.
5069
		$getMeetConditionsString=search::getMeetConditionsString($conf["fileAccess::getMeetConditionsString"]);
5070
		unset($conf["fileAccess::getMeetConditionsString"]);
226 liveuser 5071
 
3 liveuser 5072
		#如果執行出錯
5073
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 5074
 
3 liveuser 5075
			#設置錯誤識別
5076
			$result["status"]="false";
226 liveuser 5077
 
3 liveuser 5078
			#設置錯誤訊息
5079
			$result["error"]=$getMeetConditionsString;
226 liveuser 5080
 
3 liveuser 5081
			#回傳結果
5082
			return $result;
226 liveuser 5083
 
3 liveuser 5084
			}#if end
226 liveuser 5085
 
3 liveuser 5086
		#預設參數 $conf["fileAddressAndName"] 不為 "/" 開始
5087
		$fileAddressAndNameStarFromRoot="true";
226 liveuser 5088
 
3 liveuser 5089
		#如果是 "/" 開頭
5090
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 5091
 
3 liveuser 5092
			#設置參數 $conf["fileAddressAndName"] 為 "/" 開始
5093
			$fileAddressAndNameStarFromRoot="true";
226 liveuser 5094
 
3 liveuser 5095
			}#if end
226 liveuser 5096
 
5097
		#檢查是否有路徑資訊
3 liveuser 5098
		#函式說明:
5099
		#將固定格式的字串分開,並回傳分開的結果。
5100
		#回傳的參數:
5101
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5102
		#$result["error"],錯誤訊息陣列
5103
		#$result["oriStr"],要分割的原始字串內容
5104
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5105
		#$result["dataCounts"],爲總共分成幾段
5106
		#必填參數:
5107
		$conf["stringProcess"]["spiltString"]["stringIn"]=$conf["fileAddressAndName"];#要處理的字串。
5108
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
5109
		$spiledResult=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5110
		unset($conf["stringProcess"]["spiltString"]);
226 liveuser 5111
 
3 liveuser 5112
		#如果 $spiledResult["status"] 等於 "false"
5113
		if($spiledResult["status"]==="false"){
226 liveuser 5114
 
3 liveuser 5115
			#設置錯誤識別
5116
			$result["status"]="false";
226 liveuser 5117
 
3 liveuser 5118
			#設置錯誤訊息
5119
			$result["error"]=$spiledResult;
226 liveuser 5120
 
3 liveuser 5121
			#回傳結果
5122
			return $result;
226 liveuser 5123
 
3 liveuser 5124
			}#if end
226 liveuser 5125
 
3 liveuser 5126
		#如果 $spiledResult["dataCounts"] 大於 1
5127
		if($spiledResult["dataCounts"]>1){
226 liveuser 5128
 
3 liveuser 5129
			#代表有路徑字串
226 liveuser 5130
 
3 liveuser 5131
			#初始化路徑字串暫存變數
5132
			$tempPathStr="";
226 liveuser 5133
 
3 liveuser 5134
			#如果是絕對路徑
5135
			if($fileAddressAndNameStarFromRoot==="true"){
226 liveuser 5136
 
3 liveuser 5137
				#加上根目錄
5138
				$tempPathStr=$tempPathStr."/";
226 liveuser 5139
 
3 liveuser 5140
				}#if end
226 liveuser 5141
 
3 liveuser 5142
			#取得路徑字串
5143
			for($i=0;$i<$spiledResult["dataCounts"]-1;$i++){
226 liveuser 5144
 
3 liveuser 5145
				#串連片段路徑字串
5146
				$tempPathStr=$tempPathStr.$spiledResult["dataArray"][$i]."/";
226 liveuser 5147
 
3 liveuser 5148
				}#for end
226 liveuser 5149
 
3 liveuser 5150
			#取得檔案的路徑
5151
			$result["filePath"]=$tempPathStr;
226 liveuser 5152
 
3 liveuser 5153
			}#if end
226 liveuser 5154
 
3 liveuser 5155
		#反之 $spiledResult["dataCounts"] 等於 1
5156
		else{
226 liveuser 5157
 
3 liveuser 5158
			#檔案的路徑設為""
5159
			$result["filePath"]="";
226 liveuser 5160
 
3 liveuser 5161
			}#else end
226 liveuser 5162
 
3 liveuser 5163
		#取得檔案名稱(含副檔名)
5164
		$result["fullFileName"]=$spiledResult["dataArray"][$spiledResult["dataCounts"]-1];
226 liveuser 5165
 
3 liveuser 5166
		#取得副檔名
5167
		#函式說明:
5168
		#將固定格式的字串分開,並回傳分開的結果。
5169
		#回傳的參數:
5170
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5171
		#$result["error"],錯誤訊息陣列
5172
		#$result["oriStr"],要分割的原始字串內容
5173
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5174
		#$result["dataCounts"],爲總共分成幾段
5175
		#必填參數:
5176
		$conf["stringProcess"]["spiltString"]["stringIn"]=$result["fullFileName"];#要處理的字串。
5177
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
5178
		$spiledResult=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5179
		unset($conf["stringProcess"]["spiltString"]);
226 liveuser 5180
 
3 liveuser 5181
		#如果 $spiledResult["status"] 等於 "false"
5182
		if($spiledResult["status"]=="false"){
226 liveuser 5183
 
3 liveuser 5184
			#設置錯誤識別
5185
			$result["status"]="false";
226 liveuser 5186
 
3 liveuser 5187
			#設置錯誤訊息
5188
			$result["error"]=$spiledResult;
226 liveuser 5189
 
3 liveuser 5190
			#回傳結果
5191
			return $result;
226 liveuser 5192
 
3 liveuser 5193
			}#if end
226 liveuser 5194
 
3 liveuser 5195
		#如果 $spiledResult["dataCounts"] 大於 1
5196
		if($spiledResult["dataCounts"]>1){
226 liveuser 5197
 
3 liveuser 5198
			#代表有副檔名
226 liveuser 5199
 
3 liveuser 5200
			#初始化檔名字串暫存變數
5201
			$tempFileNameStr="";
226 liveuser 5202
 
3 liveuser 5203
			#取得路徑字串
5204
			for($i=0;$i<$spiledResult["dataCounts"]-1;$i++){
226 liveuser 5205
 
3 liveuser 5206
				#如果是最後一個小黑點前面的字串片段
5207
				if($i==$spiledResult["dataCounts"]-2){
226 liveuser 5208
 
3 liveuser 5209
					#串連片段路徑字串
5210
					$tempFileNameStr=$tempFileNameStr.$spiledResult["dataArray"][$i];
226 liveuser 5211
 
3 liveuser 5212
					}#if end
226 liveuser 5213
 
3 liveuser 5214
				#反之不是最後一個小黑點前面的字串片段
5215
				else{
226 liveuser 5216
 
3 liveuser 5217
					#串連片段路徑字串(含小黑點)
5218
					$tempFileNameStr=$tempFileNameStr.$spiledResult["dataArray"][$i].".";
226 liveuser 5219
 
3 liveuser 5220
					}#else end
226 liveuser 5221
 
3 liveuser 5222
				}#for end
226 liveuser 5223
 
3 liveuser 5224
			#取得檔名
5225
			$result["fileName"]=$tempFileNameStr;
226 liveuser 5226
 
3 liveuser 5227
			#取得副檔名
5228
			$result["fileExtention"]=$spiledResult["dataArray"][$spiledResult["dataCounts"]-1];
226 liveuser 5229
 
3 liveuser 5230
			}#if end
226 liveuser 5231
 
3 liveuser 5232
		#反之 $spiledResult["dataCounts"] 等於 1
5233
		else{
226 liveuser 5234
 
3 liveuser 5235
			#檔案的副檔名設為""
5236
			$result["fileExtention"]="";
226 liveuser 5237
 
3 liveuser 5238
			#取得檔案的名稱
5239
			$result["fileName"]=$spiledResult["dataArray"][0];
226 liveuser 5240
 
3 liveuser 5241
			}#else end
226 liveuser 5242
 
3 liveuser 5243
		#如果 $result["fileExtention"] 不等於 ""
5244
		if($result["fileExtention"]!=""){
226 liveuser 5245
 
3 liveuser 5246
			#將副檔名用小黑點跟檔案名稱連在一塊
5247
			$result["fullFileName"]=$result["fileName"].".".$result["fileExtention"];
226 liveuser 5248
 
3 liveuser 5249
			}#if end
226 liveuser 5250
 
3 liveuser 5251
		#反之代表沒有副檔名
5252
		else{
226 liveuser 5253
 
3 liveuser 5254
			#取得含副檔名的檔案名稱
5255
			$result["fullFileName"]=$result["fileName"].$result["fileExtention"];
226 liveuser 5256
 
3 liveuser 5257
			}#else end
226 liveuser 5258
 
3 liveuser 5259
		#完整的檔案路徑(含副檔名).
5260
		$result["fullFilePathAndName"]=$result["filePath"].$result["fullFileName"];
226 liveuser 5261
 
3 liveuser 5262
		#設置執行正常的識別
5263
		$result["status"]="true";
226 liveuser 5264
 
3 liveuser 5265
		#回傳結果
5266
		return $result;
226 liveuser 5267
 
3 liveuser 5268
		}#funciton getFileAddressAndNameAndFileExtention end
5269
 
5270
	/*
5271
	#函式說明:
5272
	#將資料夾或檔案打包成tar檔案
5273
	#回傳結果:
5274
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5275
	#$result["function"],當前執行的函數名稱
5276
	#$result["error"],錯誤訊息.
5277
	#$result["content"],檔案輸出後的位置與名稱.
5278
	#必填參數:
5279
	#$conf["packetTarget"],陣列,要打包的每個資料夾與檔案位置
5280
	$conf["packetTarget"]=array("");
5281
	#$conf["createdTarFile"],字串,打包好的檔案要放在哪裡,副檔名.tar會自動加上.
5282
	$conf["createdTarFile"]="";
5283
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5284
	$conf["fileArgu"]=__FILE__;
5285
	#可省略參數:
5286
	#無.
5287
	#參考資料:
5288
	#無.
5289
	#備註:
5290
	#無.
5291
	*/
5292
	public static function makeTarFile(&$conf){
226 liveuser 5293
 
3 liveuser 5294
		#初始化要回傳的內容
5295
		$result=array();
226 liveuser 5296
 
3 liveuser 5297
		#記錄當前執行的函數名稱
5298
		$result["function"]=__FUNCTION__;
226 liveuser 5299
 
3 liveuser 5300
		#如果 $conf 不為陣列
5301
		if(gettype($conf)!="array"){
226 liveuser 5302
 
3 liveuser 5303
			#設置執行失敗
5304
			$result["status"]="false";
226 liveuser 5305
 
3 liveuser 5306
			#設置執行錯誤訊息
5307
			$result["error"][]="\$conf變數須為陣列形態";
5308
 
5309
			#如果傳入的參數為 null
5310
			if($conf==null){
226 liveuser 5311
 
3 liveuser 5312
				#設置執行錯誤訊息
5313
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5314
 
3 liveuser 5315
				}#if end
5316
 
5317
			#回傳結果
5318
			return $result;
226 liveuser 5319
 
3 liveuser 5320
			}#if end
226 liveuser 5321
 
3 liveuser 5322
		#檢查參數
5323
		#函式說明:
5324
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5325
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5326
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5327
		#$result["function"],當前執行的函式名稱.
5328
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5329
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5330
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5331
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5332
		#必填寫的參數:
5333
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5334
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5335
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5336
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","packetTarget","createdTarFile");
226 liveuser 5337
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5338
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
5339
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5340
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5341
		#可以省略的參數:
5342
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5343
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5344
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5345
		#$conf["skipableVariableName"]=array();
226 liveuser 5346
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5347
		#$conf["skipableVariableType"]=array();
5348
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5349
		#$conf["skipableVarDefaultValue"]=array("");
5350
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5351
		#$conf["arrayCountEqualCheck"][]=array();
5352
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5353
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5354
 
3 liveuser 5355
		#若檢查失敗
5356
		if($checkResult["status"]=="false"){
226 liveuser 5357
 
3 liveuser 5358
			#設置執行失敗
5359
			$result["status"]="false";
226 liveuser 5360
 
3 liveuser 5361
			#設置執行錯誤訊息
5362
			$result["error"]=$checkResult;
226 liveuser 5363
 
3 liveuser 5364
			#回傳結果
5365
			return $result;
226 liveuser 5366
 
3 liveuser 5367
			}#if end
226 liveuser 5368
 
3 liveuser 5369
		#若檢查不通過
5370
		if($checkResult["passed"]=="false"){
226 liveuser 5371
 
3 liveuser 5372
			#設置執行失敗
5373
			$result["status"]="false";
226 liveuser 5374
 
3 liveuser 5375
			#設置執行錯誤訊息
5376
			$result["error"]=$checkResult;
226 liveuser 5377
 
3 liveuser 5378
			#回傳結果
5379
			return $result;
226 liveuser 5380
 
3 liveuser 5381
			}#if end
226 liveuser 5382
 
3 liveuser 5383
		#初始化打包要用的tar指令參數
5384
		$paramsArray=array("-cvf",$conf["createdTarFile"].".tar");
226 liveuser 5385
 
3 liveuser 5386
		#檢查要打包的檔案是否存在
5387
		#函式說明:
5388
		#檢查多個檔案與資料夾是否存在.
5389
		#回傳的結果:
5390
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5391
		#$result["error"],錯誤訊息陣列.
5392
		#$resutl["function"],當前執行的涵式名稱.
5393
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
5394
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
5395
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
5396
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
5397
		#必填參數:
5398
		#$conf["fileArray"],陣列字串,要檢查書否存在的檔案有哪些,須爲一維陣列數值。
5399
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$conf["packetTarget"];
5400
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5401
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
5402
		#可省略參數
5403
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
5404
		#$conf["disableWebSearch"]="false";
5405
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5406
		#$conf["userDir"]="true";
5407
		#參考資料來源:
5408
		#http://php.net/manual/en/function.file-exists.php
5409
		#http://php.net/manual/en/control-structures.foreach.php
5410
		#備註:
5411
		#函數file_exists檢查的路徑為檔案系統的路徑
5412
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
5413
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 5414
 
3 liveuser 5415
		#如果檢查要打包的檔案失敗
5416
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 5417
 
3 liveuser 5418
			#設置執行失敗
5419
			$result["status"]="false";
226 liveuser 5420
 
3 liveuser 5421
			#設置執行錯誤訊息
5422
			$result["error"]=$checkMultiFileExist;
226 liveuser 5423
 
3 liveuser 5424
			#回傳結果
5425
			return $result;
226 liveuser 5426
 
3 liveuser 5427
			}#if end
226 liveuser 5428
 
3 liveuser 5429
		#如果要打包的檔案有缺
5430
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 5431
 
3 liveuser 5432
			#設置執行失敗
5433
			$result["status"]="false";
226 liveuser 5434
 
3 liveuser 5435
			#設置執行錯誤訊息
5436
			$result["error"]=$checkMultiFileExist;
226 liveuser 5437
 
3 liveuser 5438
			#回傳結果
5439
			return $result;
226 liveuser 5440
 
3 liveuser 5441
			}#if end
226 liveuser 5442
 
3 liveuser 5443
		#有幾個要打包的目標就執行幾次
5444
		for($i=0;$i<count($conf["packetTarget"]);$i++){
226 liveuser 5445
 
3 liveuser 5446
			#串接上要打包的檔案或資料夾
5447
			$paramsArray[]=$conf["packetTarget"][$i];
226 liveuser 5448
 
3 liveuser 5449
			}#for end
226 liveuser 5450
 
3 liveuser 5451
		#函式說明:
5452
		#呼叫shell執行系統命令,並取得回傳的內容.
5453
		#回傳結果:
5454
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5455
		#$result["error"],錯誤訊息陣列.
5456
		#$result["function"],當前執行的函數名稱.
5457
		#$result["argu"],使用的參數.
5458
		#$result["cmd"],執行的指令內容.
5459
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
5460
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
5461
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
5462
		#$result["running"],是否還在執行.
5463
		#$result["pid"],pid.
5464
		#$result["statusCode"],執行結束後的代碼.
5465
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
5466
		#必填參數:
5467
		#$conf["command"],字串,要執行的指令.
5468
		$conf["external::callShell"]["command"]="tar";
5469
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5470
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5471
		#可省略參數:
5472
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5473
		$conf["external::callShell"]["argu"]=$paramsArray;
5474
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
5475
		#$conf["arguIsAddr"]=array();
5476
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
5477
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
5478
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
5479
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5480
		#$conf["enablePrintDescription"]="true";
5481
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
5482
		#$conf["printDescription"]="";
5483
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
5484
		$conf["external::callShell"]["escapeshellarg"]="true";
5485
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
5486
		#$conf["thereIsShellVar"]=array();
5487
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
5488
		#$conf["username"]="";
5489
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
5490
		#$conf["password"]="";
5491
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
5492
		#$conf["useScript"]="";
5493
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
5494
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
5495
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
5496
		#$conf["inBackGround"]="";
5497
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
5498
		#$conf["getErr"]="false";
5499
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
5500
		#$conf["doNotRun"]="false";
5501
		#參考資料:
5502
		#exec=>http://php.net/manual/en/function.exec.php
5503
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
5504
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
5505
		#備註:
5506
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
5507
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
5508
		$conf["external::callShell"]=external::callShell($conf["external::callShell"]);
5509
		unset($conf["external::callShell"]);
226 liveuser 5510
 
3 liveuser 5511
		#如果執行shell失敗
5512
		if($callShell["status"]=="false"){
226 liveuser 5513
 
3 liveuser 5514
			#設置執行失敗
5515
			$result["status"]="false";
226 liveuser 5516
 
3 liveuser 5517
			#設置執行錯誤訊息
5518
			$result["error"]=$callShell;
226 liveuser 5519
 
3 liveuser 5520
			#回傳結果
5521
			return $result;
226 liveuser 5522
 
3 liveuser 5523
			}#if end
226 liveuser 5524
 
3 liveuser 5525
		#打包好的檔案位置與名稱
5526
		$result["content"]=$conf["createdTarFile"].".tar";
226 liveuser 5527
 
3 liveuser 5528
		#執行到這邊代表執行正常
5529
		$result["status"]="true";
226 liveuser 5530
 
3 liveuser 5531
		#回傳結果
5532
		return $result;
226 liveuser 5533
 
3 liveuser 5534
		}#function makeTarFile end
226 liveuser 5535
 
3 liveuser 5536
	/*
5537
	#函式說明:
5538
	#將一個檔案壓縮成xz檔案
5539
	#回傳結果:
5540
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5541
	#$result["function"],當前執行的函數名稱
5542
	#$result["error"],錯誤訊息.
5543
	#$result["content"],檔案輸出後的位置與名稱.
5544
	#必填參數:
5545
	#$conf["compressTarget"],字串,要打包的每個資料夾與檔案位置
5546
	$conf["compressTarget"]="";
5547
	#$conf["createdXzFile"],字串,打包好的檔案要放在哪裡,副檔名.xz會自動加上.
5548
	$conf["createdXzFile"]="";
5549
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5550
	$conf["fileArgu"]=__FILE__;
5551
	#可省略參數:
5552
	#無.
5553
	#參考資料:
5554
	#無.
5555
	#備註:
5556
	#無.
5557
	*/
5558
	public static function makeXzFile(&$conf){
5559
 
5560
		#初始化要回傳的內容
5561
		$result=array();
226 liveuser 5562
 
3 liveuser 5563
		#記錄當前執行的函數名稱
5564
		$result["function"]=__FUNCTION__;
226 liveuser 5565
 
3 liveuser 5566
		#如果 $conf 不為陣列
5567
		if(gettype($conf)!="array"){
226 liveuser 5568
 
3 liveuser 5569
			#設置執行失敗
5570
			$result["status"]="false";
226 liveuser 5571
 
3 liveuser 5572
			#設置執行錯誤訊息
5573
			$result["error"][]="\$conf變數須為陣列形態";
5574
 
5575
			#如果傳入的參數為 null
5576
			if($conf==null){
226 liveuser 5577
 
3 liveuser 5578
				#設置執行錯誤訊息
5579
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5580
 
3 liveuser 5581
				}#if end
5582
 
5583
			#回傳結果
5584
			return $result;
226 liveuser 5585
 
3 liveuser 5586
			}#if end
226 liveuser 5587
 
3 liveuser 5588
		#檢查參數
5589
		#函式說明:
5590
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5591
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5592
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5593
		#$result["function"],當前執行的函式名稱.
5594
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5595
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5596
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5597
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5598
		#必填寫的參數:
5599
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5600
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5601
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5602
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","compressTarget","createdXzFile");
226 liveuser 5603
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5604
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
5605
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5606
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5607
		#可以省略的參數:
5608
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5609
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5610
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5611
		#$conf["skipableVariableName"]=array();
226 liveuser 5612
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5613
		#$conf["skipableVariableType"]=array();
5614
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5615
		#$conf["skipableVarDefaultValue"]=array("");
5616
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5617
		#$conf["arrayCountEqualCheck"][]=array();
5618
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5619
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5620
 
3 liveuser 5621
		#若檢查失敗
5622
		if($checkResult["status"]=="false"){
226 liveuser 5623
 
3 liveuser 5624
			#設置執行失敗
5625
			$result["status"]="false";
226 liveuser 5626
 
3 liveuser 5627
			#設置執行錯誤訊息
5628
			$result["error"]=$checkResult;
226 liveuser 5629
 
3 liveuser 5630
			#回傳結果
5631
			return $result;
226 liveuser 5632
 
3 liveuser 5633
			}#if end
226 liveuser 5634
 
3 liveuser 5635
		#若檢查不通過
5636
		if($checkResult["passed"]=="false"){
226 liveuser 5637
 
3 liveuser 5638
			#設置執行失敗
5639
			$result["status"]="false";
226 liveuser 5640
 
3 liveuser 5641
			#設置執行錯誤訊息
5642
			$result["error"]=$checkResult;
226 liveuser 5643
 
3 liveuser 5644
			#回傳結果
5645
			return $result;
226 liveuser 5646
 
3 liveuser 5647
			}#if end
226 liveuser 5648
 
3 liveuser 5649
		#檢查要用xz壓縮的檔案是否存在
5650
		#函式說明:
5651
		#檢查多個檔案與資料夾是否存在.
5652
		#回傳的結果:
5653
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5654
		#$result["error"],錯誤訊息陣列.
5655
		#$resutl["function"],當前執行的涵式名稱.
5656
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
5657
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
5658
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
5659
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
5660
		#必填參數:
5661
		#$conf["fileArray"],陣列字串,要檢查書否存在的檔案有哪些,須爲一維陣列數值。
5662
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["compressTarget"]);
5663
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5664
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
5665
		#可省略參數
5666
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
5667
		#$conf["disableWebSearch"]="false";
5668
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5669
		#$conf["userDir"]="true";
5670
		#參考資料來源:
5671
		#http://php.net/manual/en/function.file-exists.php
5672
		#http://php.net/manual/en/control-structures.foreach.php
5673
		#備註:
5674
		#函數file_exists檢查的路徑為檔案系統的路徑
5675
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
5676
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 5677
 
3 liveuser 5678
		#如果檢查要用xz壓縮的檔案失敗
5679
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 5680
 
3 liveuser 5681
			#設置執行失敗
5682
			$result["status"]="false";
226 liveuser 5683
 
3 liveuser 5684
			#設置執行錯誤訊息
5685
			$result["error"]=$checkMultiFileExist;
226 liveuser 5686
 
3 liveuser 5687
			#回傳結果
5688
			return $result;
226 liveuser 5689
 
3 liveuser 5690
			}#if end
226 liveuser 5691
 
3 liveuser 5692
		#如果要用xz壓縮的檔案有缺
5693
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 5694
 
3 liveuser 5695
			#設置執行失敗
5696
			$result["status"]="false";
226 liveuser 5697
 
3 liveuser 5698
			#設置執行錯誤訊息
5699
			$result["error"]=$checkMultiFileExist;
226 liveuser 5700
 
3 liveuser 5701
			#回傳結果
5702
			return $result;
226 liveuser 5703
 
3 liveuser 5704
			}#if end
226 liveuser 5705
 
3 liveuser 5706
		#壓縮要用的xz語法
5707
		#函式說明:
5708
		#呼叫shell執行系統命令,並取得回傳的內容.
5709
		#回傳的結果:
5710
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5711
		#$result["error"],錯誤訊息陣列
5712
		#$result["output"],爲執行完二元碼後的輸出陣列
5713
		#必填的參數
5714
		$conf["external::callShell"]["command"]="xz";#要執行的指令與參數
5715
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5716
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5717
		#可省略參數:
5718
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5719
		$conf["external::callShell"]["argu"]=array("-v","-v","-z","-c",$conf["compressTarget"],">",$conf["createdXzFile"].".xz ");
5720
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5721
		#$conf["enablePrintDescription"]="true";
5722
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
5723
		#$conf["printDescription"]="";
5724
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
5725
		$conf["external::callShell"]["escapeshellarg"]="true";
5726
		#參考資料:
5727
		#http://php.net/manual/en/function.exec.php
5728
		$callShell=external::callShell($conf["external::callShell"]);
5729
		unset($conf["external::callShell"]);
226 liveuser 5730
 
3 liveuser 5731
		#如果執行shell失敗
5732
		if($callShell["status"]=="false"){
226 liveuser 5733
 
3 liveuser 5734
			#設置執行失敗
5735
			$result["status"]="false";
226 liveuser 5736
 
3 liveuser 5737
			#設置執行錯誤訊息
5738
			$result["error"]=$callShell;
226 liveuser 5739
 
3 liveuser 5740
			#回傳結果
5741
			return $result;
226 liveuser 5742
 
3 liveuser 5743
			}#if end
226 liveuser 5744
 
3 liveuser 5745
		#壓縮好的檔案位置與名稱
5746
		$result["content"]=$conf["createdXzFile"].".xz";
226 liveuser 5747
 
3 liveuser 5748
		#執行到這邊代表執行正常
5749
		$result["status"]="status";
226 liveuser 5750
 
3 liveuser 5751
		#回傳結果
5752
		return $result;
5753
 
5754
		}#function makeXzFile end
226 liveuser 5755
 
3 liveuser 5756
	/*
5757
	#函式說明:
5758
	#將資料夾或檔案打包壓縮成tar.xz檔案
5759
	#回傳結果:
5760
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5761
	#$result["function"],當前執行的函數名稱
5762
	#$result["error"],錯誤訊息.
5763
	#$result["content"],檔案輸出後的位置與名稱.
5764
	#必填參數:
5765
	#$conf["compressTarget"],陣列,要打包壓縮的每個資料夾與檔案位置
5766
	$conf["compressTarget"]=array();
5767
	#$conf["createdTarXzFile"],字串,打包壓縮好的檔案要放在哪裡,副檔名.tar.xz會自動加上.
5768
	$conf["createdTarXzFile"]="";
5769
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5770
	$conf["fileArgu"]=__FILE__;
5771
	#可省略參數:
5772
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
5773
	#$conf["commentsArray"]=array("");
5774
	#$conf["includeDotStart"],字串,當參數$conf["commentsArray"]含有星號時是否要包含「.」開頭的檔案目錄,預設為"false",不包含,"true"為要包含.
5775
	#$conf["includeDotStart"]="false";
5776
	#$conf["includeWaveEnd"],字串,當參數$conf["commentsArray"]含有星號時是否要包含「~」結尾的檔案.預設為"false",不包含,"true"為要包含.
5777
	#$conf["includeWaveEnd"]="false";
5778
	#參考資料:
5779
	#無.
5780
	#備註:
226 liveuser 5781
	#建議加上 --exclude-backups, --exclude-caches-all
3 liveuser 5782
	*/
5783
	public static function makeTarXzFile(&$conf){
226 liveuser 5784
 
3 liveuser 5785
		#初始化要回傳的內容
5786
		$result=array();
226 liveuser 5787
 
3 liveuser 5788
		#記錄當前執行的函數名稱
5789
		$result["function"]=__FUNCTION__;
226 liveuser 5790
 
3 liveuser 5791
		#如果 $conf 不為陣列
5792
		if(gettype($conf)!="array"){
226 liveuser 5793
 
3 liveuser 5794
			#設置執行失敗
5795
			$result["status"]="false";
226 liveuser 5796
 
3 liveuser 5797
			#設置執行錯誤訊息
5798
			$result["error"][]="\$conf變數須為陣列形態";
5799
 
5800
			#如果傳入的參數為 null
5801
			if($conf==null){
226 liveuser 5802
 
3 liveuser 5803
				#設置執行錯誤訊息
5804
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5805
 
3 liveuser 5806
				}#if end
5807
 
5808
			#回傳結果
5809
			return $result;
226 liveuser 5810
 
3 liveuser 5811
			}#if end
226 liveuser 5812
 
3 liveuser 5813
		#檢查參數
5814
		#函式說明:
5815
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5816
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5817
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5818
		#$result["function"],當前執行的函式名稱.
5819
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5820
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5821
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5822
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5823
		#必填寫的參數:
5824
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5825
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5826
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5827
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","compressTarget","createdTarXzFile");
226 liveuser 5828
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5829
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
5830
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5831
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5832
		#可以省略的參數:
5833
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5834
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5835
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5836
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","includeDotStart","includeWaveEnd");
226 liveuser 5837
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5838
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");
5839
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5840
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false","false");
5841
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5842
		#$conf["arrayCountEqualCheck"][]=array();
5843
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5844
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5845
 
3 liveuser 5846
		#若檢查失敗
5847
		if($checkResult["status"]=="false"){
226 liveuser 5848
 
3 liveuser 5849
			#設置執行失敗
5850
			$result["status"]="false";
226 liveuser 5851
 
3 liveuser 5852
			#設置執行錯誤訊息
5853
			$result["error"]=$checkResult;
226 liveuser 5854
 
3 liveuser 5855
			#回傳結果
5856
			return $result;
226 liveuser 5857
 
3 liveuser 5858
			}#if end
226 liveuser 5859
 
3 liveuser 5860
		#若檢查不通過
5861
		if($checkResult["passed"]=="false"){
226 liveuser 5862
 
3 liveuser 5863
			#設置執行失敗
5864
			$result["status"]="false";
226 liveuser 5865
 
3 liveuser 5866
			#設置執行錯誤訊息
5867
			$result["error"]=$checkResult;
226 liveuser 5868
 
3 liveuser 5869
			#回傳結果
5870
			return $result;
226 liveuser 5871
 
3 liveuser 5872
			}#if end
226 liveuser 5873
 
3 liveuser 5874
		#如果 $conf["commentsArray"] 有設定
5875
		if(isset($conf["commentsArray"])){
226 liveuser 5876
 
3 liveuser 5877
			#印出提示文字
5878
			#函式說明:
5879
			#印出多行文字,結尾自動換行.
5880
			#回傳的結果:
5881
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
5882
			#$result["function"],當前執行的函數名稱.
5883
			#$result["error"],錯誤訊息陣列.
5884
			#必填參數:
5885
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
5886
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
5887
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
5888
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 5889
 
3 liveuser 5890
			#如果印出提示文字失敗
5891
			if($echoMultiLine["status"]=="false"){
226 liveuser 5892
 
3 liveuser 5893
				#設置執行失敗
5894
				$result["status"]="false";
226 liveuser 5895
 
3 liveuser 5896
				#設置執行錯誤訊息
5897
				$result["error"]=$echoMultiLine;
226 liveuser 5898
 
3 liveuser 5899
				#回傳結果
5900
				return $result;
226 liveuser 5901
 
3 liveuser 5902
				}#if end
226 liveuser 5903
 
5904
			}#if end
5905
 
3 liveuser 5906
		#解析要處理的檔案路徑
5907
		#函式說明:
5908
		#將含有「*」的多個檔案路徑名稱,變成多個符合條件的路徑檔案.
5909
		#回傳結果:
5910
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
5911
		#$result["error"],錯誤訊息陣列.
226 liveuser 5912
		#$result["function"],函數名稱.
3 liveuser 5913
		#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
5914
		#$result["pathCount"],整數,有幾個路徑.
5915
		#必填參數:
5916
		#$conf["path"],字串陣列,要解析含有「*」的檔案路徑字串.
5917
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["path"]=$conf["compressTarget"];
5918
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
5919
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["fileArgu"]=$conf["fileArgu"];
5920
		#可省略參數:
5921
		#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
5922
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["noDotStart"]=$conf["includeDotStart"]==="true"?"false":"true";
5923
		#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
5924
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["noWaveEnd"]=$conf["includeWaveEnd"]==="true"?"false":"true";
5925
		$realPathArray=fileAccess::resolveMultiPostionStringWhichContainStarSymbol($conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]);
5926
		unset($conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]);
226 liveuser 5927
 
3 liveuser 5928
		#如果解析路徑失敗
5929
		if($realPathArray["status"]=="false"){
226 liveuser 5930
 
3 liveuser 5931
			#設置執行失敗
5932
			$result["status"]="false";
226 liveuser 5933
 
3 liveuser 5934
			#設置執行錯誤訊息
5935
			$result["error"]=$realPathArray;
226 liveuser 5936
 
3 liveuser 5937
			#回傳結果
5938
			return $result;
226 liveuser 5939
 
3 liveuser 5940
			}#if end
226 liveuser 5941
 
3 liveuser 5942
		#取得解析好的檔案路徑陣列
226 liveuser 5943
		$conf["compressTarget"]=$realPathArray["content"];
5944
 
3 liveuser 5945
		#將路徑轉換成相對路徑
5946
		#函式說明:
5947
		#將多個路徑字串變成相對於當前路徑的相對路徑字串
5948
		#回傳結果:
5949
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
5950
		#$result["error"],錯誤訊息陣列.
226 liveuser 5951
		#$result["function"],函數名稱.
3 liveuser 5952
		#$result["content"],字串陣列,多個轉換好的相對路徑字串.
5953
		#必填參數:
5954
		#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
5955
		$conf["fileAccess::getRelativePath"]["path"]=$conf["compressTarget"];
5956
		#$conf["fileArgu"],字串,當前路徑.
5957
		$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
5958
		$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
5959
		unset($conf["fileAccess::getRelativePath"]);
226 liveuser 5960
 
3 liveuser 5961
		#如果轉換失敗
5962
		if($getRelativePath["status"]=="false"){
226 liveuser 5963
 
3 liveuser 5964
			#設置執行失敗
5965
			$result["status"]="false";
226 liveuser 5966
 
3 liveuser 5967
			#設置執行錯誤訊息
5968
			$result["error"]=$getRelativePat;
226 liveuser 5969
 
3 liveuser 5970
			#回傳結果
5971
			return $result;
226 liveuser 5972
 
5973
			}#if end
5974
 
3 liveuser 5975
		#打包成tar檔
5976
		#函式說明:
5977
		#將資料夾或檔案打包成tar檔案
5978
		#回傳的結果:
5979
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5980
		#$result["function"],當前執行的函數名稱
5981
		#$result["error"],錯誤訊息.
5982
		#$result["content"],檔案輸出後的位置與名稱.
5983
		#必填參數:
5984
		#$conf["fileAccess::makeTarFile"]["packetTarget"],陣列,要打包的每個資料夾與檔案位置
5985
		$conf["fileAccess::makeTarFile"]["packetTarget"]=$getRelativePath["content"];
5986
		#$conf["fileAccess::makeTarFile"]["createdTarFile"],字串,打包好的檔案要放在哪裡,副檔名.tar會自動加上.
5987
		$conf["fileAccess::makeTarFile"]["createdTarFile"]=$conf["createdTarXzFile"];
5988
		#$conf["fileAccess::makeTarFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5989
		$conf["fileAccess::makeTarFile"]["fileArgu"]=$conf["fileArgu"];
5990
		$makeTarFile=fileAccess::makeTarFile($conf["fileAccess::makeTarFile"]);
5991
		unset($conf["fileAccess::makeTarFile"]);
226 liveuser 5992
 
3 liveuser 5993
		#如果打包失敗
5994
		if($makeTarFile["status"]=="false"){
226 liveuser 5995
 
3 liveuser 5996
			#設置執行不正常
5997
			$result["status"]="false";
226 liveuser 5998
 
3 liveuser 5999
			#設置錯誤訊息
6000
			$result["error"]=$makeTarFile;
226 liveuser 6001
 
3 liveuser 6002
			#回傳結果
6003
			return $result;
226 liveuser 6004
 
3 liveuser 6005
			}#if end
226 liveuser 6006
 
3 liveuser 6007
		#壓縮成xz檔
6008
		#函式說明:
6009
		#將一個檔案壓縮成xz檔案
6010
		#回傳的結果:
6011
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6012
		#$result["function"],當前執行的函數名稱
6013
		#$result["error"],錯誤訊息.
6014
		#$result["content"],檔案輸出後的位置與名稱.
6015
		#必填參數:
6016
		#$conf["fileAccess::makeXzFile"]["compressTarget"],字串,要打包的每個資料夾與檔案位置
6017
		$conf["fileAccess::makeXzFile"]["compressTarget"]=$makeTarFile["content"];
6018
		#$conf["fileAccess::makeXzFile"]["createdXzFile"],字串,打包好的檔案要放在哪裡,副檔名.xz會自動加上.
6019
		$conf["fileAccess::makeXzFile"]["createdXzFile"]=$makeTarFile["content"];
6020
		#$conf["fileAccess::makeXzFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6021
		$conf["fileAccess::makeXzFile"]["fileArgu"]=$conf["fileArgu"];
6022
		$makeXzFile=fileAccess::makeXzFile($conf["fileAccess::makeXzFile"]);
6023
		unset($conf["fileAccess::makeXzFile"]);
226 liveuser 6024
 
3 liveuser 6025
		#如果壓縮失敗
6026
		if($makeXzFile["status"]=="false"){
226 liveuser 6027
 
3 liveuser 6028
			#設置執行不正常
6029
			$result["status"]="false";
226 liveuser 6030
 
3 liveuser 6031
			#設置錯誤訊息
6032
			$result["error"]=$makeXzFile;
226 liveuser 6033
 
3 liveuser 6034
			#回傳結果
6035
			return $result;
226 liveuser 6036
 
3 liveuser 6037
			}#if end
226 liveuser 6038
 
3 liveuser 6039
		#移除tar檔案
6040
		#函式說明:
6041
		#移除檔案
6042
		#回傳結果:
6043
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
6044
		#$result["error"],錯誤訊息陣列
6045
		#$result["warning"],警告訊息陣列
6046
		#$result["function"],當前執行的函數名稱
6047
		#必填參數:
6048
		$conf["fileAccess::delFile"]["fileAddress"]=$makeTarFile["content"];#要移除檔案的位置
6049
		#$conf["fileAccess::delFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
6050
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
6051
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
6052
		unset($conf["fileAccess::delFile"]);
226 liveuser 6053
 
3 liveuser 6054
		#如果移除tar檔案失敗
6055
		if($delFile["status"]=="false"){
226 liveuser 6056
 
3 liveuser 6057
			#設置執行不正常
6058
			$result["status"]="false";
226 liveuser 6059
 
3 liveuser 6060
			#設置錯誤訊息
6061
			$result["error"]=$delFile;
226 liveuser 6062
 
3 liveuser 6063
			#回傳結果
6064
			return $result;
226 liveuser 6065
 
3 liveuser 6066
			}#if end
226 liveuser 6067
 
3 liveuser 6068
		#取得壓縮好的檔案位置與名稱
6069
		$result["content"]=$makeXzFile["content"];
226 liveuser 6070
 
3 liveuser 6071
		#執行到這邊代表執行正常
6072
		$result["status"]="true";
226 liveuser 6073
 
3 liveuser 6074
		#回傳結果
6075
		return $result;
226 liveuser 6076
 
3 liveuser 6077
		}#function makeTarXzFile end
226 liveuser 6078
 
3 liveuser 6079
	/*
6080
	#函式說明:
6081
	#移動檔案
6082
	#回傳結果:
6083
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6084
	#$result["function"],當前執行的函數名稱
6085
	#$result["error"],錯誤訊息.
6086
	#$result["content"],檔案輸出後的位置與名稱.
6087
	#必填參數:
6088
	#$conf["from"],字串,要移動的檔案名稱與位置.
6089
	$conf["from"]="";
6090
	#$conf["to"],字串,要移動到的位置與名稱
6091
	$conf["to"]="";
6092
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6093
	$conf["fileArgu"]=__FILE__;
6094
	#可省略參數:
6095
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
6096
	#$conf["commentsArray"]=array("");
6097
	#參考資料:
6098
	#無.
6099
	#備註:
6100
	#無.
6101
	*/
6102
	public static function mv(&$conf){
226 liveuser 6103
 
3 liveuser 6104
		#初始化要回傳的結果
6105
		$result=array();
226 liveuser 6106
 
3 liveuser 6107
		#取得當前執行的函數名稱
6108
		$result["function"]=__FUNCTION__;
226 liveuser 6109
 
3 liveuser 6110
		#如果 $conf 不為陣列
6111
		if(gettype($conf)!="array"){
226 liveuser 6112
 
3 liveuser 6113
			#設置執行失敗
6114
			$result["status"]="false";
226 liveuser 6115
 
3 liveuser 6116
			#設置執行錯誤訊息
6117
			$result["error"][]="\$conf變數須為陣列形態";
6118
 
6119
			#如果傳入的參數為 null
6120
			if($conf==null){
226 liveuser 6121
 
3 liveuser 6122
				#設置執行錯誤訊息
6123
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6124
 
3 liveuser 6125
				}#if end
6126
 
6127
			#回傳結果
6128
			return $result;
226 liveuser 6129
 
3 liveuser 6130
			}#if end
226 liveuser 6131
 
3 liveuser 6132
		#檢查參數
6133
		#函式說明:
6134
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6135
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6136
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6137
		#$result["function"],當前執行的函式名稱.
6138
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6139
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6140
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6141
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6142
		#必填寫的參數:
6143
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6144
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6145
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6146
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("from","to","fileArgu");
226 liveuser 6147
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 6148
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
6149
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6150
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6151
		#可以省略的參數:
6152
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
6153
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6154
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6155
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray");
226 liveuser 6156
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 6157
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
6158
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6159
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
6160
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6161
		#$conf["arrayCountEqualCheck"][]=array();
6162
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6163
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 6164
 
3 liveuser 6165
		#若檢查失敗
6166
		if($checkResult["status"]=="false"){
226 liveuser 6167
 
3 liveuser 6168
			#設置執行失敗
6169
			$result["status"]="false";
226 liveuser 6170
 
3 liveuser 6171
			#設置執行錯誤訊息
6172
			$result["error"]=$checkResult;
226 liveuser 6173
 
3 liveuser 6174
			#回傳結果
6175
			return $result;
226 liveuser 6176
 
3 liveuser 6177
			}#if end
226 liveuser 6178
 
3 liveuser 6179
		#若檢查不通過
6180
		if($checkResult["passed"]=="false"){
226 liveuser 6181
 
3 liveuser 6182
			#設置執行失敗
6183
			$result["status"]="false";
226 liveuser 6184
 
3 liveuser 6185
			#設置執行錯誤訊息
6186
			$result["error"]=$checkResult;
226 liveuser 6187
 
3 liveuser 6188
			#回傳結果
6189
			return $result;
226 liveuser 6190
 
3 liveuser 6191
			}#if end
226 liveuser 6192
 
3 liveuser 6193
		#如果 $conf["commentsArray"] 有設定
6194
		if(isset($conf["commentsArray"])){
226 liveuser 6195
 
3 liveuser 6196
			#印出提示文字
6197
			#函式說明:
6198
			#印出多行文字,結尾自動換行.
6199
			#回傳的結果:
6200
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
6201
			#$result["function"],當前執行的函數名稱.
6202
			#$result["error"],錯誤訊息陣列.
6203
			#必填參數:
6204
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
6205
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
6206
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
6207
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 6208
 
3 liveuser 6209
			#如果印出提示文字失敗
6210
			if($echoMultiLine["status"]=="false"){
226 liveuser 6211
 
3 liveuser 6212
				#設置執行失敗
6213
				$result["status"]="false";
226 liveuser 6214
 
3 liveuser 6215
				#設置執行錯誤訊息
6216
				$result["error"]=$echoMultiLine;
226 liveuser 6217
 
3 liveuser 6218
				#回傳結果
6219
				return $result;
226 liveuser 6220
 
3 liveuser 6221
				}#if end
226 liveuser 6222
 
6223
			}#if end
6224
 
3 liveuser 6225
		#檢查要移動的檔案是否存在
6226
		#函式說明:
6227
		#檢查多個檔案與資料夾是否存在.
6228
		#回傳的結果:
6229
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
6230
		#$result["error"],錯誤訊息陣列.
6231
		#$resutl["function"],當前執行的涵式名稱.
6232
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
6233
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
6234
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
6235
		#必填參數:
6236
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["from"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
6237
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
6238
		#參考資料來源:
6239
		#http://php.net/manual/en/function.file-exists.php
6240
		#http://php.net/manual/en/control-structures.foreach.php
6241
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
6242
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 6243
 
3 liveuser 6244
		#如果檢查失敗
6245
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 6246
 
3 liveuser 6247
			#設置執行失敗
6248
			$result["status"]="false";
226 liveuser 6249
 
3 liveuser 6250
			#設置執行錯誤訊息
6251
			$result["error"]=$checkMultiFileExist;
226 liveuser 6252
 
3 liveuser 6253
			#回傳結果
6254
			return $result;
226 liveuser 6255
 
6256
			}#if end
6257
 
3 liveuser 6258
		#如果來源檔案不存在
6259
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 6260
 
3 liveuser 6261
			#設置執行失敗
6262
			$result["status"]="false";
226 liveuser 6263
 
3 liveuser 6264
			#設置執行錯誤訊息
6265
			$result["error"][]="檔案「".$conf["from"]."」不存在";
226 liveuser 6266
 
3 liveuser 6267
			#回傳結果
6268
			return $result;
226 liveuser 6269
 
3 liveuser 6270
			}#if end
226 liveuser 6271
 
3 liveuser 6272
		#函式說明:
6273
		#呼叫shell執行系統命令,並取得回傳的內容.
6274
		#回傳的結果:
6275
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6276
		#$result["error"],錯誤訊息陣列
6277
		#$result["output"],爲執行完二元碼後的輸出陣列
6278
		#必填的參數
6279
		$conf["external::callShell"]["command"]="mv";#要執行的指令與參數
6280
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"]; #__FILE__的內容
6281
		#可省略參數:
6282
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
6283
		$conf["external::callShell"]["argu"]=array("-v",$conf["from"],$conf["to"]);
6284
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
6285
		#$conf["external::callShell"]["enablePrintDescription"]="true";
6286
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
6287
		#$conf["printDescription"]="";
6288
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
6289
		$conf["external::callShell"]["escapeshellarg"]="true";
6290
		#參考資料:
6291
		#http://php.net/manual/en/function.exec.php
6292
		$callShell=external::callShell($conf["external::callShell"]);
6293
		unset($conf["external::callShell"]);
226 liveuser 6294
 
3 liveuser 6295
		#如果移動檔案失敗
6296
		if($callShell["status"]=="false"){
226 liveuser 6297
 
3 liveuser 6298
			#設置執行失敗
6299
			$result["status"]="false";
226 liveuser 6300
 
3 liveuser 6301
			#設置執行錯誤訊息
6302
			$result["error"]=$callShell;
226 liveuser 6303
 
3 liveuser 6304
			#回傳結果
6305
			return $result;
226 liveuser 6306
 
3 liveuser 6307
			}#if end
226 liveuser 6308
 
3 liveuser 6309
		#執行到這邊代表正常
6310
		$result["status"]="true";
226 liveuser 6311
 
3 liveuser 6312
		#儲存移動後的位置與名稱
6313
		$result["content"]=$conf["to"];
226 liveuser 6314
 
3 liveuser 6315
		#回傳結果
6316
		return $result;
226 liveuser 6317
 
3 liveuser 6318
		}#function mv end
226 liveuser 6319
 
3 liveuser 6320
	/*
6321
	#函式說明:
6322
	#取得目錄底下所有目錄與檔案的樹狀結構.
6323
	#回傳結果:
6324
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6325
	#$result["error"],錯誤訊息陣列.
6326
	#$result["function"],函數名稱.
6327
	#$result["position"],根目錄位置.
6328
	#$result["content"],陣列,檔案目錄的樹狀結構.
6329
	#$result["content"][$i]["name"],根目錄底下第$i+1個檔案或目錄的名稱
6330
	#$result["content"][$i]["folder"],根目錄底下第$i+1個名稱是目錄("true")還是檔案("false").
6331
	#$result["content"][$i]["position"],根目錄底下第$i+1個名稱或目錄的位置.
6332
	#$result["content"][$i]["ownerPerm"],根目錄底下第$i+1個使用者的權限.
6333
	#$result["content"][$i]["groupPerm"],根目錄底下第$i+1個群組使用者的權限.
6334
	#$result["content"][$i]["otherPerm"],根目錄底下第$i+1個其他使用者的權限.
6335
	#$result["content"][$i]["ownerName"],根目錄底下第$i+1個擁有者賬戶.
6336
	#$result["content"][$i]["groupName"],根目錄底下第$i+1個群組擁有者賬戶.
6337
	#$result["content"][$i]["next"][$j]["name"],第$i+1個為目錄的名稱的目錄底下第$j+1個檔案或目錄的名稱
6338
	#$result["content"][$i]["next"][$j]["folder"],第$i+1個為目錄的名稱的目錄底下第$j+1個名稱是目錄("true")還是檔案("false").
6339
	#$result["content"][$i]["next"][$j]["position"],第$i+1個為目錄的名稱的目錄底下第$j+1個名稱或目錄的位置.
6340
	#$result["content"][$i]["next"][$j]["ownerPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個使用者的權限.
6341
	#$result["content"][$i]["next"][$j]["groupPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個群組使用者的權限.
6342
	#$result["content"][$i]["next"][$j]["otherPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個其他使用者的權限.
6343
	#$result["content"][$i]["next"][$j]["ownerName"],第$i+1個為目錄的名稱的目錄底下第$j+1個擁有者賬戶.
6344
	#$result["content"][$i]["next"][$j]["groupName"],第$i+1個為目錄的名稱的目錄底下第$j+1個群組擁有者賬戶.
226 liveuser 6345
	#以此類推...
3 liveuser 6346
	#必填參數:
6347
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6348
	$conf["position"]="";
6349
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6350
	$conf["fileArgu"]=__FILE__;
6351
	#可省略參數:
6352
	#無.
6353
	#參考資料:
6354
	#無.
6355
	#備註:
6356
	#無.
6357
	*/
6358
	public static function getListTree(&$conf){
226 liveuser 6359
 
3 liveuser 6360
		#初始化要回傳的結果
6361
		$result=array();
226 liveuser 6362
 
3 liveuser 6363
		#設置當其函數名稱
6364
		$result["function"]=__FUNCTION__;
226 liveuser 6365
 
3 liveuser 6366
		#如果 $conf 不為陣列
6367
		if(gettype($conf)!="array"){
226 liveuser 6368
 
3 liveuser 6369
			#設置執行失敗
6370
			$result["status"]="false";
226 liveuser 6371
 
3 liveuser 6372
			#設置執行錯誤訊息
6373
			$result["error"][]="\$conf變數須為陣列形態";
6374
 
6375
			#如果傳入的參數為 null
6376
			if($conf==null){
226 liveuser 6377
 
3 liveuser 6378
				#設置執行錯誤訊息
6379
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6380
 
3 liveuser 6381
				}#if end
6382
 
6383
			#回傳結果
6384
			return $result;
226 liveuser 6385
 
3 liveuser 6386
			}#if end
226 liveuser 6387
 
3 liveuser 6388
		#檢查必填參數
6389
		#函式說明:
6390
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6391
		#回傳的結果:
6392
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6393
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6394
		#$result["function"],當前執行的函式名稱.
6395
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6396
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6397
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6398
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6399
		#必填寫的參數:
6400
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6401
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileArgu","position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6402
		#可以省略的參數:
226 liveuser 6403
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6404
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6405
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
6406
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 6407
 
3 liveuser 6408
		#如果檢查失敗
6409
		if($checkResult["status"]=="false"){
226 liveuser 6410
 
3 liveuser 6411
			#設置錯誤識別
6412
			$result["status"]="false";
226 liveuser 6413
 
3 liveuser 6414
			#設置錯誤訊息
6415
			$result["error"]=$checkResult;
226 liveuser 6416
 
3 liveuser 6417
			#回傳結果
6418
			return $result;
226 liveuser 6419
 
3 liveuser 6420
			}#if end
226 liveuser 6421
 
3 liveuser 6422
		#如果檢查不通過
6423
		if($checkResult["passed"]=="false"){
226 liveuser 6424
 
3 liveuser 6425
			#設置錯誤識別
6426
			$result["status"]="false";
226 liveuser 6427
 
3 liveuser 6428
			#設置錯誤訊息
6429
			$result["error"]=$checkResult;
226 liveuser 6430
 
3 liveuser 6431
			#回傳結果
6432
			return $result;
226 liveuser 6433
 
3 liveuser 6434
			}#if end
226 liveuser 6435
 
3 liveuser 6436
		#如果目錄不為 . 與 ..
6437
		if(basename($conf["position"])!="." && basename($conf["position"])!=".."){
226 liveuser 6438
 
3 liveuser 6439
			#檢查目錄是否存在
6440
			#函式說明:
6441
			#檢查多個檔案與資料夾是否存在.
6442
			#回傳的結果:
6443
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
6444
			#$result["error"],錯誤訊息陣列.
6445
			#$resutl["function"],當前執行的涵式名稱.
6446
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
6447
			#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
6448
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
6449
			#必填參數:
6450
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["position"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
6451
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6452
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
6453
			#參考資料來源:
6454
			#http://php.net/manual/en/function.file-exists.php
6455
			#http://php.net/manual/en/control-structures.foreach.php
6456
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
6457
			unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 6458
 
3 liveuser 6459
			#如果檢查目錄失敗
6460
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 6461
 
3 liveuser 6462
				#設置錯誤識別
6463
				$result["status"]="false";
226 liveuser 6464
 
3 liveuser 6465
				#設置錯誤訊息
6466
				$result["error"]=$checkMultiFileExist;
226 liveuser 6467
 
3 liveuser 6468
				#回傳結果
6469
				return $result;
226 liveuser 6470
 
6471
				}#if end
6472
 
3 liveuser 6473
			#如果目錄不存在
6474
			if($checkMultiFileExist["varExist"][0]=="false"){
226 liveuser 6475
 
3 liveuser 6476
				#設置錯誤識別
6477
				$result["status"]="false";
226 liveuser 6478
 
3 liveuser 6479
				#設置錯誤訊息
6480
				$result["error"]=$checkMultiFileExist;
226 liveuser 6481
 
3 liveuser 6482
				#回傳結果
6483
				return $result;
226 liveuser 6484
 
6485
				}#if end
6486
 
3 liveuser 6487
			}#if end
226 liveuser 6488
 
3 liveuser 6489
		#取得根目錄的樹狀結構
6490
		#函式說明:
6491
		#取得目錄底下所有目錄與檔案清單.
6492
		#回傳結果:
6493
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6494
		#$result["error"],錯誤訊息陣列.
6495
		#$result["function"],函數名稱.
6496
		#$result["content"],陣列,目錄底下的檔案與子目錄.
6497
		#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
6498
		#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
6499
		#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
6500
		#$result["position"],目前的位置.
6501
		#必填參數:
6502
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6503
		$conf["fileAccess::getList"]["position"]=$conf["position"];
6504
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6505
		$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
6506
		#可省略參數:
6507
		#無
6508
		#參考資料來源:
6509
		#opendir=>http://php.net/manual/en/function.opendir.php
6510
		#is_dir=>http://php.net/manual/en/function.is-dir.php
6511
		$rootList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 6512
		unset($conf["fileAccess::getList"]);
6513
 
3 liveuser 6514
		#如果取得根目錄底下的資料失敗
6515
		if($rootList["status"]=="false"){
226 liveuser 6516
 
3 liveuser 6517
			#設置錯誤識別
6518
			$result["status"]="false";
226 liveuser 6519
 
3 liveuser 6520
			#設置錯誤訊息
6521
			$result["error"]=$rootList;
226 liveuser 6522
 
3 liveuser 6523
			#回傳結果
6524
			return $result;
226 liveuser 6525
 
3 liveuser 6526
			}#if end
226 liveuser 6527
 
6528
		#取得當前目錄
6529
		$result["position"]=$rootList["position"];
6530
 
3 liveuser 6531
		#取得根目錄層級可以看到的檔案與目錄
6532
		$result["content"]=$rootList["content"];
226 liveuser 6533
 
3 liveuser 6534
		#如果當前目錄有檔案與子目錄
6535
		if(isset($result["content"])){
226 liveuser 6536
 
3 liveuser 6537
			#當前層級有幾個檔案目錄就執行幾次
6538
			for($i=0;$i<count($result["content"]);$i++){
226 liveuser 6539
 
3 liveuser 6540
				#如果該單位是目錄
6541
				if($result["content"][$i]["folder"]=="true"){
226 liveuser 6542
 
3 liveuser 6543
					#呼叫當前函數,取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊
6544
					#函式說明:
6545
					#取得目錄底下所有目錄與檔案的樹狀結構.
6546
					#回傳結果:
6547
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6548
					#$result["error"],錯誤訊息陣列.
6549
					#$result["function"],函數名稱.
6550
					#$result["content"],陣列,檔案目錄的樹狀結構.
6551
					#$result["total"],根目錄底下有多少目錄與檔案
6552
					#必填參數:
6553
					#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6554
					$conf["fileAccess::getListTree"]["position"]=$conf["position"]."/".$result["content"][$i]["name"];
6555
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6556
					$conf["fileAccess::getListTree"]["fileArgu"]=$conf["fileArgu"];
6557
					#可省略參數:
6558
					#無
6559
					$getListTree=fileAccess::getListTree($conf["fileAccess::getListTree"]);
6560
					unset($conf["fileAccess::getListTree"]);
226 liveuser 6561
 
3 liveuser 6562
					#如果取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊失敗
6563
					if($getListTree["status"]=="false"){
226 liveuser 6564
 
3 liveuser 6565
						#設置錯誤識別
6566
						$result["status"]="false";
226 liveuser 6567
 
3 liveuser 6568
						#設置錯誤訊息
6569
						$result["error"]=$getListTree;
226 liveuser 6570
 
3 liveuser 6571
						#回傳結果
6572
						return $result;
226 liveuser 6573
 
3 liveuser 6574
						}#if end
226 liveuser 6575
 
3 liveuser 6576
					#如果 $conf["position"]."/".$result["content"][$i]["name"] 目錄有檔案與子目錄
226 liveuser 6577
					if(isset($getListTree["content"])){
6578
 
3 liveuser 6579
						#取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊
6580
						$result["content"][$i]["next"]=$getListTree["content"];
226 liveuser 6581
 
3 liveuser 6582
						}#if end
226 liveuser 6583
 
6584
					#取得當前目錄
6585
					$result["content"][$i]["position"]=$rootList["position"];
6586
 
3 liveuser 6587
					}#if end
226 liveuser 6588
 
3 liveuser 6589
				}#for end
226 liveuser 6590
 
3 liveuser 6591
			}#if end
226 liveuser 6592
 
3 liveuser 6593
		#執行到這邊代表執行正常
6594
		$result["status"]="true";
226 liveuser 6595
 
3 liveuser 6596
		#回傳結果
6597
		return $result;
226 liveuser 6598
 
3 liveuser 6599
		}#function getListTree end
226 liveuser 6600
 
3 liveuser 6601
	/*
6602
	#函式說明:
6603
	#取得目錄底下所有目錄與檔案清單.
6604
	#回傳結果:
6605
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6606
	#$result["error"],錯誤訊息陣列.
6607
	#$result["function"],函數名稱.
6608
	#$result["content"],陣列,目錄底下的檔案與子目錄.
6609
	#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
6610
	#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
6611
	#$result["content"][$i]["ownerPerm"],字串,使用者的權限.
6612
	#$result["content"][$i]["groupPerm"],字串,群組使用者的權限.
6613
	#$result["content"][$i]["otherPerm"],字串,其他使用者的權限.
6614
	#$result["content"][$i]["ownerName"],字串,擁有者賬戶.
6615
	#$result["content"][$i]["groupName"],字串,群組擁有者賬戶.
6616
	#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
6617
	#$result["position"],目前的位置.
6618
	#必填參數:
6619
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6620
	$conf["position"]="";
6621
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6622
	$conf["fileArgu"]=__FILE__;
6623
	#可省略參數:
6624
	#無
6625
	#參考資料:
6626
	#opendir=>http://php.net/manual/en/function.opendir.php
6627
	#is_dir=>http://php.net/manual/en/function.is-dir.php
6628
	#備註:
6629
	#無.
6630
	*/
6631
	public static function getList(&$conf){
6632
 
6633
		#初始化要回傳的結果
6634
		$result=array();
226 liveuser 6635
 
3 liveuser 6636
		#設置當其函數名稱
6637
		$result["function"]=__FUNCTION__;
226 liveuser 6638
 
3 liveuser 6639
		#初始化記載檔案目錄名單的陣列
6640
		$result["content"]=array();
226 liveuser 6641
 
3 liveuser 6642
		#如果 $conf 不為陣列
6643
		if(gettype($conf)!="array"){
226 liveuser 6644
 
3 liveuser 6645
			#設置執行失敗
6646
			$result["status"]="false";
226 liveuser 6647
 
3 liveuser 6648
			#設置執行錯誤訊息
6649
			$result["error"][]="\$conf變數須為陣列形態";
6650
 
6651
			#如果傳入的參數為 null
6652
			if($conf==null){
226 liveuser 6653
 
3 liveuser 6654
				#設置執行錯誤訊息
6655
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6656
 
3 liveuser 6657
				}#if end
6658
 
6659
			#回傳結果
6660
			return $result;
226 liveuser 6661
 
3 liveuser 6662
			}#if end
226 liveuser 6663
 
3 liveuser 6664
		#檢查必填參數
6665
		#函式說明:
6666
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6667
		#回傳的結果:
6668
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6669
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6670
		#$result["function"],當前執行的函式名稱.
6671
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6672
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6673
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6674
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6675
		#必填寫的參數:
6676
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6677
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileArgu","position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6678
		#可以省略的參數:
226 liveuser 6679
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6680
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6681
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
6682
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 6683
 
3 liveuser 6684
		#如果檢查失敗
6685
		if($checkResult["status"]=="false"){
226 liveuser 6686
 
3 liveuser 6687
			#設置錯誤識別
6688
			$result["status"]="false";
226 liveuser 6689
 
3 liveuser 6690
			#設置錯誤訊息
6691
			$result["error"]=$checkResult;
226 liveuser 6692
 
3 liveuser 6693
			#回傳結果
6694
			return $result;
226 liveuser 6695
 
3 liveuser 6696
			}#if end
226 liveuser 6697
 
3 liveuser 6698
		#如果檢查不通過
6699
		if($checkResult["passed"]==="false"){
226 liveuser 6700
 
3 liveuser 6701
			#設置錯誤識別
6702
			$result["status"]="false";
226 liveuser 6703
 
3 liveuser 6704
			#設置錯誤訊息
6705
			$result["error"]=$checkResult;
226 liveuser 6706
 
3 liveuser 6707
			#回傳結果
6708
			return $result;
226 liveuser 6709
 
3 liveuser 6710
			}#if end
226 liveuser 6711
 
3 liveuser 6712
		#檢查目標路徑是否為「/」開頭的路徑
6713
		#函式說明:
6714
		#取得符合特定字首與字尾的字串
6715
		#回傳結果:
6716
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
6717
		#$result["function"],當前執行的函數名稱.
6718
		#$result["error"],錯誤訊息陣列.
6719
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
6720
		#$result["returnString"],爲符合字首條件的字串內容。
6721
		#必填參數:
6722
		#$conf["checkString"],字串,要檢查的字串.
6723
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["position"];
6724
		#可省略參數:
6725
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
6726
		$conf["search::getMeetConditionsString"]["frontWord"]="/";
6727
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
6728
		#$conf["tailWord"]="";
6729
		#參考資料:
6730
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
6731
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
6732
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 6733
 
3 liveuser 6734
		#如果檢查關鍵字失敗
6735
		if($getMeetConditionsString["status"]=="false"){
226 liveuser 6736
 
3 liveuser 6737
			#設置錯誤識別
6738
			$result["status"]="false";
226 liveuser 6739
 
3 liveuser 6740
			#設置錯誤訊息
6741
			$result["error"]=$getMeetConditionsString;
226 liveuser 6742
 
3 liveuser 6743
			#回傳結果
6744
			return $result;
226 liveuser 6745
 
6746
			}#if end
6747
 
3 liveuser 6748
		#如果目標路徑不為「/」開頭的路徑,則為相對路徑
6749
		if($getMeetConditionsString["founded"]=="false"){
226 liveuser 6750
 
3 liveuser 6751
			#取得目標位置的路徑
6752
			#函式說明:
6753
			#將檔案的位置名稱變成網址
6754
			#回傳結果:
6755
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6756
			#$result["error"],錯誤訊息陣列.
226 liveuser 6757
			#$result["function"],函數名稱.
3 liveuser 6758
			#$result["content"],網址.
6759
			#$result["localAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
6760
			#$result["fileSystemAbsoulutePosition"],針對伺服器檔案系統的絕對位置.
6761
			#必填參數:
6762
			#$conf["address"],字串,檔案的相對位置.
6763
			$conf["fileAccess::getInternetAddress"]["address"]=$conf["position"];
6764
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
6765
			$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
6766
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是.
6767
			#$conf["fileAccess::getInternetAddress"]["userDir"]="true";
6768
			$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
226 liveuser 6769
			unset($conf["fileAccess::getInternetAddress"]);
6770
 
3 liveuser 6771
			#如果將檔案的位置名稱變成網址失敗
6772
			if($getInternetAddress["status"]=="false"){
226 liveuser 6773
 
3 liveuser 6774
				#設置錯誤識別
6775
				$result["status"]="false";
226 liveuser 6776
 
3 liveuser 6777
				#設置錯誤訊息
6778
				$result["error"]=$getInternetAddress;
226 liveuser 6779
 
3 liveuser 6780
				#回傳結果
6781
				return $result;
226 liveuser 6782
 
6783
				}#if end
6784
 
3 liveuser 6785
			#置換目標位置為檔案系統路徑的絕對位置
6786
			$conf["position"]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 6787
 
6788
			}#if end
6789
 
6790
		#如果目標是資料夾
3 liveuser 6791
		if(is_dir($conf["position"])) {
226 liveuser 6792
 
3 liveuser 6793
			#設置為資料夾
6794
			$result["folder"]="true";
226 liveuser 6795
 
3 liveuser 6796
			#如果開啟資料夾成功
6797
			if($dh=opendir($conf["position"])){
226 liveuser 6798
 
3 liveuser 6799
				#初始化計數變數
6800
				$count=0;
226 liveuser 6801
 
3 liveuser 6802
				#如果資料夾裡面有檔案
6803
				while(($fileName=readdir($dh))!==false){
226 liveuser 6804
 
3 liveuser 6805
					#debug
6806
					#echo "有檔案";
226 liveuser 6807
 
3 liveuser 6808
					#如果名稱是「.」或「..」
6809
					if($fileName=="." || $fileName==".."){
226 liveuser 6810
 
3 liveuser 6811
						#則跳過
6812
						continue;
226 liveuser 6813
 
3 liveuser 6814
						}#if end
226 liveuser 6815
 
3 liveuser 6816
					#取得檔案或子目錄名稱
226 liveuser 6817
					$result["content"][$count]["name"]=$fileName;
6818
 
3 liveuser 6819
					#取得詳細資訊
6820
					#函式說明:
6821
					#取得節點的資訊.
6822
					#回傳結果:
6823
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6824
					#$result["error"],錯誤訊息陣列.
226 liveuser 6825
					#$result["function"],函數名稱.
3 liveuser 6826
					#$result["content"],檔案資訊陣列.
226 liveuser 6827
					#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 6828
					#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
6829
					#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
6830
					#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
6831
					#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
6832
					#$result["content"]["ownerName"],檔案擁有着資訊.
6833
					#$result["content"]["groupName"],檔案所屬擁有着資訊.
6834
					#$result["content"]["size"],檔案大小.
6835
					#$result["content"]["modifyDate"],檔案變更年月日.
6836
					#$result["content"]["modifyTime"],檔案變更時分秒.
6837
					#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
6838
					#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
6839
					#必填參數:
6840
					#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
6841
					$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];
6842
					#$conf["file"],字串,要查看擁有者資訊的檔案.
6843
					$conf["fileAccess::fileInfo"]["file"]=$conf["position"]."/".$fileName;
6844
					#可省略參數:
6845
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
6846
					$conf["fileAccess::fileInfo"]["web"]="false";
6847
					#參考資料:
6848
					#fileowner=>http://php.net/manual/en/function.fileowner.php
6849
					#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
6850
					#備註:
6851
					#無.
6852
					$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
6853
					unset($conf["fileAccess::fileInfo"]);
226 liveuser 6854
 
3 liveuser 6855
					#如果執行失敗
6856
					if($fileInfo["status"]=="false"){
226 liveuser 6857
 
3 liveuser 6858
						#設置錯誤識別
6859
						$result["status"]="false";
226 liveuser 6860
 
3 liveuser 6861
						#設置錯誤訊息
6862
						$result["error"]=$fileInfo;
226 liveuser 6863
 
3 liveuser 6864
						#回傳結果
6865
						return $result;
226 liveuser 6866
 
3 liveuser 6867
						}#if end
226 liveuser 6868
 
3 liveuser 6869
					#設置是否為資料夾
6870
					$result["content"][$count]["folder"]=$fileInfo["content"]["is_folder"];
226 liveuser 6871
 
3 liveuser 6872
					#設置使用者的權限
6873
					$result["content"][$count]["ownerPerm"]=$fileInfo["content"]["ownerPerm"];
226 liveuser 6874
 
3 liveuser 6875
					#設置群組的權限
6876
					$result["content"][$count]["groupPerm"]=$fileInfo["content"]["groupPerm"];
226 liveuser 6877
 
3 liveuser 6878
					#設置其他使用者的權限
6879
					$result["content"][$count]["otherPerm"]=$fileInfo["content"]["otherPerm"];
226 liveuser 6880
 
3 liveuser 6881
					#設置其擁有者賬戶
6882
					$result["content"][$count]["ownerName"]=$fileInfo["content"]["ownerName"];
226 liveuser 6883
 
3 liveuser 6884
					#設置其群組擁有者賬戶
6885
					$result["content"][$count]["groupName"]=$fileInfo["content"]["groupName"];
226 liveuser 6886
 
3 liveuser 6887
					#計數加1
6888
					$count++;
226 liveuser 6889
 
3 liveuser 6890
					}#while
226 liveuser 6891
 
3 liveuser 6892
				#關閉資料夾
6893
				closedir($dh);
226 liveuser 6894
 
3 liveuser 6895
				}#if end
226 liveuser 6896
 
6897
			#開啟資料夾失敗
3 liveuser 6898
			else{
226 liveuser 6899
 
3 liveuser 6900
				#設置執行失敗
6901
				$result["status"]="false";
226 liveuser 6902
 
3 liveuser 6903
				#設置執行錯誤訊息
6904
				$result["error"][]="開啟資料夾「".$conf["position"]."」失敗";
6905
 
6906
				#回傳結果
6907
				return $result;
226 liveuser 6908
 
3 liveuser 6909
				}#else end
226 liveuser 6910
 
3 liveuser 6911
			}#if end
226 liveuser 6912
 
3 liveuser 6913
		#反之是檔案
6914
		else{
226 liveuser 6915
 
3 liveuser 6916
			#設置不為目錄
6917
			$result["folder"]="false";
226 liveuser 6918
 
3 liveuser 6919
			}#else end
226 liveuser 6920
 
3 liveuser 6921
		#取得目前位置
226 liveuser 6922
		$result["position"]=$conf["position"];
6923
 
3 liveuser 6924
		#執行到這邊代表執行正常
6925
		$result["status"]="true";
226 liveuser 6926
 
3 liveuser 6927
		#回傳結果
226 liveuser 6928
		return $result;
3 liveuser 6929
 
6930
		}#function getList end
226 liveuser 6931
 
3 liveuser 6932
	/*
6933
	#函式說明:
6934
	#取得目錄底下所有目錄與檔案的樹狀結構.
6935
	#回傳結果:
6936
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6937
	#$result["error"],錯誤訊息陣列.
6938
	#$result["function"],函數名稱.
6939
	#$result["content"],陣列,檔案目錄的樹狀結構.
6940
	#必填參數:
6941
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6942
	$conf["position"]="";
6943
	#可省略參數:
6944
	#無.
6945
	#參考資料:
6946
	#無.
6947
	#備註:
6948
	#無.
6949
	*/
6950
	public static function exportListTree(&$conf){
226 liveuser 6951
 
3 liveuser 6952
		#初始化要回傳的結果
6953
		$result=array();
226 liveuser 6954
 
3 liveuser 6955
		#設置當其函數名稱
6956
		$result["function"]=__FUNCTION__;
226 liveuser 6957
 
3 liveuser 6958
		#如果 $conf 不為陣列
6959
		if(gettype($conf)!="array"){
226 liveuser 6960
 
3 liveuser 6961
			#設置執行失敗
6962
			$result["status"]="false";
226 liveuser 6963
 
3 liveuser 6964
			#設置執行錯誤訊息
6965
			$result["error"][]="\$conf變數須為陣列形態";
6966
 
6967
			#如果傳入的參數為 null
6968
			if($conf==null){
226 liveuser 6969
 
3 liveuser 6970
				#設置執行錯誤訊息
6971
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6972
 
3 liveuser 6973
				}#if end
6974
 
6975
			#回傳結果
6976
			return $result;
226 liveuser 6977
 
3 liveuser 6978
			}#if end
226 liveuser 6979
 
3 liveuser 6980
		#檢查必填參數
6981
		#函式說明:
6982
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6983
		#回傳的結果:
6984
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6985
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6986
		#$result["function"],當前執行的函式名稱.
6987
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6988
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6989
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6990
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6991
		#必填寫的參數:
6992
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6993
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6994
		#可以省略的參數:
226 liveuser 6995
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6996
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6997
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
6998
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 6999
 
3 liveuser 7000
		#如果檢查失敗
7001
		if($checkResult["status"]=="false"){
226 liveuser 7002
 
3 liveuser 7003
			#設置錯誤識別
7004
			$result["status"]="false";
226 liveuser 7005
 
3 liveuser 7006
			#設置錯誤訊息
7007
			$result["error"]=$checkResult;
226 liveuser 7008
 
3 liveuser 7009
			#回傳結果
7010
			return $result;
226 liveuser 7011
 
3 liveuser 7012
			}#if end
226 liveuser 7013
 
3 liveuser 7014
		#如果檢查不通過
7015
		if($checkResult["passed"]=="false"){
226 liveuser 7016
 
3 liveuser 7017
			#設置錯誤識別
7018
			$result["status"]="false";
226 liveuser 7019
 
3 liveuser 7020
			#設置錯誤訊息
7021
			$result["error"]=$checkResult;
226 liveuser 7022
 
3 liveuser 7023
			#回傳結果
7024
			return $result;
226 liveuser 7025
 
3 liveuser 7026
			}#if end
226 liveuser 7027
 
3 liveuser 7028
		#函式說明:
7029
		#取得目錄底下所有目錄與檔案的樹狀結構.
7030
		#回傳結果:
7031
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7032
		#$result["error"],錯誤訊息陣列.
7033
		#$result["function"],函數名稱.
7034
		#$result["content"],陣列,檔案目錄的樹狀結構.
7035
		#必填參數:
7036
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
7037
		$conf["fileAccess::getListTree"]["position"]=$conf["position"];
7038
		#可省略參數:
7039
		#無
7040
		#備註:
226 liveuser 7041
		#若檔案與目錄的名稱含有「[」與「]」與「(」與「)」將會無法取得其目錄底下的內容
3 liveuser 7042
		#若檔案與目錄的名稱含有「 」將會無法檢查檔案是否存在
7043
		#改用opendir()函數應該可以解決大部分的bug.
7044
		$getListTree=fileAccess::getListTree($conf["fileAccess::getListTree"]);
7045
		unset($conf["fileAccess::getListTree"]);
226 liveuser 7046
 
3 liveuser 7047
		#如果取得 目標目錄底下所有目錄與檔案的樹狀結構 失敗
7048
		if($getListTree["status"]==="false"){
226 liveuser 7049
 
3 liveuser 7050
			#設置錯誤識別
7051
			$result["status"]="false";
226 liveuser 7052
 
3 liveuser 7053
			#設置錯誤訊息
7054
			$result["error"]=$getListTree;
226 liveuser 7055
 
3 liveuser 7056
			#回傳結果
7057
			return $result;
226 liveuser 7058
 
3 liveuser 7059
			}#if end
226 liveuser 7060
 
3 liveuser 7061
		#目標目錄底下有幾個
226 liveuser 7062
 
3 liveuser 7063
		}#function exportListTree end
7064
 
7065
	/*
7066
	#函式說明:
7067
	#解壓縮tar.xz檔案,解壓縮完畢後,tar.xz檔案會被移除.
7068
	#回傳結果:
7069
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7070
	#$result["error"],錯誤訊息陣列.
226 liveuser 7071
	#$result["function"],函數名稱.
3 liveuser 7072
	#必填參數:
7073
	#$conf["tarXzFile"],字串變數,壓縮檔的位置與名稱,副檔名".tar.xz"會自動補上.
7074
	$conf["tarXzFile"]="";
7075
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7076
	$conf["fileArgu"]=__FILE__;
7077
	#可省略參數:
7078
	#$conf["extractTo"],字串,要解壓縮到哪邊,預設為當前路徑"."
7079
	#$conf["extractTo"]=".";
7080
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7081
	#$conf["commentsArray"]=array("");
7082
	#參考資料:
7083
	#無.
7084
	#備註:
7085
	#無.
7086
	*/
7087
	public static function unpackTarXzFile(&$conf){
226 liveuser 7088
 
3 liveuser 7089
		#初始化要回傳的內容
7090
		$result=array();
226 liveuser 7091
 
3 liveuser 7092
		#記錄當前執行的函數名稱
7093
		$result["function"]=__FUNCTION__;
226 liveuser 7094
 
3 liveuser 7095
		#如果 $conf 不為陣列
7096
		if(gettype($conf)!="array"){
226 liveuser 7097
 
3 liveuser 7098
			#設置執行失敗
7099
			$result["status"]="false";
226 liveuser 7100
 
3 liveuser 7101
			#設置執行錯誤訊息
7102
			$result["error"][]="\$conf變數須為陣列形態";
7103
 
7104
			#如果傳入的參數為 null
7105
			if($conf==null){
226 liveuser 7106
 
3 liveuser 7107
				#設置執行錯誤訊息
7108
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7109
 
3 liveuser 7110
				}#if end
7111
 
7112
			#回傳結果
7113
			return $result;
226 liveuser 7114
 
3 liveuser 7115
			}#if end
226 liveuser 7116
 
3 liveuser 7117
		#檢查參數
7118
		#函式說明:
7119
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7120
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7121
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7122
		#$result["function"],當前執行的函式名稱.
7123
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7124
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7125
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7126
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7127
		#必填寫的參數:
7128
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7129
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7130
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7131
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","tarXzFile");
226 liveuser 7132
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7133
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
7134
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7135
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7136
		#可以省略的參數:
7137
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7138
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7139
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7140
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","extractTo");
226 liveuser 7141
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7142
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string");
7143
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7144
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,".");
7145
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7146
		#$conf["arrayCountEqualCheck"][]=array();
7147
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7148
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 7149
 
3 liveuser 7150
		#若檢查失敗
7151
		if($checkResult["status"]=="false"){
226 liveuser 7152
 
3 liveuser 7153
			#設置執行失敗
7154
			$result["status"]="false";
226 liveuser 7155
 
3 liveuser 7156
			#設置執行錯誤訊息
7157
			$result["error"]=$checkResult;
226 liveuser 7158
 
3 liveuser 7159
			#回傳結果
7160
			return $result;
226 liveuser 7161
 
3 liveuser 7162
			}#if end
226 liveuser 7163
 
3 liveuser 7164
		#若檢查不通過
7165
		if($checkResult["passed"]=="false"){
226 liveuser 7166
 
3 liveuser 7167
			#設置執行失敗
7168
			$result["status"]="false";
226 liveuser 7169
 
3 liveuser 7170
			#設置執行錯誤訊息
7171
			$result["error"]=$checkResult;
226 liveuser 7172
 
3 liveuser 7173
			#回傳結果
7174
			return $result;
226 liveuser 7175
 
3 liveuser 7176
			}#if end
226 liveuser 7177
 
3 liveuser 7178
		#如果 $conf["commentsArray"] 有設定
7179
		if(isset($conf["commentsArray"])){
226 liveuser 7180
 
3 liveuser 7181
			#印出提示文字
7182
			#函式說明:
7183
			#印出多行文字,結尾自動換行.
7184
			#回傳的結果:
7185
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
7186
			#$result["function"],當前執行的函數名稱.
7187
			#$result["error"],錯誤訊息陣列.
7188
			#必填參數:
7189
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
7190
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
7191
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
7192
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 7193
 
3 liveuser 7194
			#如果印出提示文字失敗
7195
			if($echoMultiLine["status"]=="false"){
226 liveuser 7196
 
3 liveuser 7197
				#設置執行失敗
7198
				$result["status"]="false";
226 liveuser 7199
 
3 liveuser 7200
				#設置執行錯誤訊息
7201
				$result["error"]=$echoMultiLine;
226 liveuser 7202
 
3 liveuser 7203
				#回傳結果
7204
				return $result;
226 liveuser 7205
 
3 liveuser 7206
				}#if end
226 liveuser 7207
 
3 liveuser 7208
			}#if end
226 liveuser 7209
 
3 liveuser 7210
		#檢查要移動的檔案是否存在
7211
		#函式說明:
7212
		#檢查多個檔案與資料夾是否存在.
7213
		#回傳的結果:
7214
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
7215
		#$result["error"],錯誤訊息陣列.
7216
		#$resutl["function"],當前執行的涵式名稱.
7217
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
7218
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
7219
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
7220
		#必填參數:
7221
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["tarXzFile"].".tar.xz");#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
7222
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7223
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
7224
		#參考資料來源:
7225
		#http://php.net/manual/en/function.file-exists.php
7226
		#http://php.net/manual/en/control-structures.foreach.php
7227
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
7228
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 7229
 
3 liveuser 7230
		#如果檢查失敗
7231
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 7232
 
3 liveuser 7233
			#設置執行失敗
7234
			$result["status"]="false";
226 liveuser 7235
 
3 liveuser 7236
			#設置執行錯誤訊息
7237
			$result["error"]=$checkMultiFileExist;
226 liveuser 7238
 
3 liveuser 7239
			#回傳結果
7240
			return $result;
226 liveuser 7241
 
7242
			}#if end
7243
 
3 liveuser 7244
		#如果來源檔案不存在
7245
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 7246
 
3 liveuser 7247
			#設置執行失敗
7248
			$result["status"]="false";
226 liveuser 7249
 
3 liveuser 7250
			#設置執行錯誤訊息
7251
			$result["error"][]="檔案「".$conf["tarXzFile"].".tar.xz」不存在";
226 liveuser 7252
 
3 liveuser 7253
			#回傳結果
7254
			return $result;
226 liveuser 7255
 
3 liveuser 7256
			}#if end
226 liveuser 7257
 
3 liveuser 7258
		#進行解壓縮xz檔
7259
		#函式說明:
7260
		#呼叫shell執行系統命令,並取得回傳的內容.
7261
		#回傳的結果:
7262
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7263
		#$result["error"],錯誤訊息陣列.
7264
		#$result["function"],當前執行的函數名稱.
7265
		#$result["cmd"],執行的指令內容.
7266
		#$result["output"],爲執行完二元碼後的輸出陣列.
7267
		#必填的參數
7268
		#$conf["command"],字串,要執行的指令與.
7269
		$conf["fileAccess::callShell"]["command"]="xz -v -v -d -f ".$conf["tarXzFile"].".tar.xz";
7270
		#可省略參數:
7271
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7272
		#$conf["fileAccess::callShell"]["argu"]=array();
7273
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7274
		#$conf["enablePrintDescription"]="true";
7275
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7276
		#$conf["printDescription"]="";
7277
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
7278
		#$conf["escapeshellarg"]="true";
7279
		#備註:
7280
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
7281
		#參考資料:
7282
		#exec=>http://php.net/manual/en/function.exec.php
7283
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7284
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7285
		$callShell=external::callShell($conf["fileAccess::callShell"]);
7286
		unset($conf["fileAccess::callShell"]);
226 liveuser 7287
 
3 liveuser 7288
		#如果解壓縮xz檔案失敗
7289
		if($callShell["status"]=="false"){
226 liveuser 7290
 
3 liveuser 7291
			#設置執行失敗
7292
			$result["status"]="false";
226 liveuser 7293
 
3 liveuser 7294
			#設置執行錯誤訊息
7295
			$result["error"]=$callShell;
226 liveuser 7296
 
3 liveuser 7297
			#回傳結果
7298
			return $result;
226 liveuser 7299
 
3 liveuser 7300
			}#if end
226 liveuser 7301
 
3 liveuser 7302
		#解壓縮tar檔
7303
		#函式說明:
7304
		#呼叫shell執行系統命令,並取得回傳的內容.
7305
		#回傳的結果:
7306
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7307
		#$result["error"],錯誤訊息陣列.
7308
		#$result["function"],當前執行的函數名稱.
7309
		#$result["cmd"],執行的指令內容.
7310
		#$result["output"],爲執行完二元碼後的輸出陣列.
7311
		#必填的參數
7312
		#$conf["command"],字串,要執行的指令與.
7313
		$conf["fileAccess::callShell"]["command"]="tar";
7314
		#可省略參數:
7315
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7316
		$conf["fileAccess::callShell"]["argu"]=array("-xvf",$conf["tarXzFile"]."tar",$conf["extractTo"]);
7317
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7318
		#$conf["enablePrintDescription"]="true";
7319
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7320
		#$conf["printDescription"]="";
7321
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
7322
		$conf["fileAccess::callShell"]["escapeshellarg"]="true";
7323
		#備註:
7324
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
7325
		#參考資料:
7326
		#exec=>http://php.net/manual/en/function.exec.php
7327
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7328
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7329
		$callShell=external::callShell($conf["fileAccess::callShell"]);
7330
		unset($conf["fileAccess::callShell"]);
226 liveuser 7331
 
3 liveuser 7332
		#如果解壓縮xz檔案失敗
7333
		if($callShell["status"]=="false"){
226 liveuser 7334
 
3 liveuser 7335
			#設置執行失敗
7336
			$result["status"]="false";
226 liveuser 7337
 
3 liveuser 7338
			#設置執行錯誤訊息
7339
			$result["error"]=$callShell;
226 liveuser 7340
 
3 liveuser 7341
			#回傳結果
7342
			return $result;
226 liveuser 7343
 
3 liveuser 7344
			}#if end
226 liveuser 7345
 
3 liveuser 7346
		#移除tar檔
7347
		#函式說明:
7348
		#移除檔案
7349
		#回傳結果:
7350
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7351
		#$result["error"],錯誤訊息陣列
7352
		#$result["warning"],警告訊息陣列
7353
		#$result["function"],當前執行的函數名稱
7354
		#必填參數:
7355
		$conf["fileAccess::delFile"]["fileAddress"]=$conf["tarXzFile"].".tar";#要移除檔案的位置
7356
		#可省略參數:
7357
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7358
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
7359
		#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7360
		#$conf["commentsArray"]=array("");
7361
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
226 liveuser 7362
		unset($conf["fileAccess::delFile"]);
7363
 
3 liveuser 7364
		#如果移除檔案失敗
7365
		if($delFile["status"]=="false"){
226 liveuser 7366
 
3 liveuser 7367
			#設置執行失敗
7368
			$result["status"]="false";
226 liveuser 7369
 
3 liveuser 7370
			#設置執行錯誤訊息
7371
			$result["error"]=$delFile;
226 liveuser 7372
 
3 liveuser 7373
			#回傳結果
7374
			return $result;
226 liveuser 7375
 
7376
			}#if end
7377
 
3 liveuser 7378
		#執行到這邊代表執行正常
7379
		$result["status"]="true";
226 liveuser 7380
 
3 liveuser 7381
		#回傳結果
7382
		return $result;
226 liveuser 7383
 
3 liveuser 7384
		}#function unpackTarXzFile end
7385
 
7386
	/*
7387
	#函式說明:
7388
	#用data:mimeType;base64,fileVar的形式來提供檔案的連結,亦即檔案儲存在變數裡面.
7389
	#回傳結果:
7390
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7391
	#$result["error"],錯誤訊息
7392
	#$result["content"],檔案變數的內容
7393
	#$result["fileTypeName"],副檔名,ex:「.tar.xz」.
226 liveuser 7394
	#$result["function"],當前執行的函數名稱
3 liveuser 7395
	#必填參數:
7396
	#$conf["filePosition"],要轉存成2元碼的檔案位置與名稱
7397
	$conf["filePosition"]="";
7398
	#$conf["mimeType"],2元碼的內容是什麼
7399
	$conf["mimeType"]="";
7400
	#可省略參數:
7401
	#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
7402
	#$conf["compressType"]="base64";
7403
	#$conf["delFile"],讀取完檔案後,要移除檔案嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
7404
	#$conf["delFile"]="false";
7405
	#參考資料:
7406
	#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
7407
	#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
7408
	#備註:
7409
	#無.
7410
	*/
7411
	public static function data(&$conf){
226 liveuser 7412
 
3 liveuser 7413
		#初始化要回傳的內容
7414
		$result=array();
226 liveuser 7415
 
3 liveuser 7416
		#取得當前執行的函數名稱
7417
		$result["function"]=__FUNCTION__;
226 liveuser 7418
 
3 liveuser 7419
		#如果 $conf 不為陣列
7420
		if(gettype($conf)!="array"){
226 liveuser 7421
 
3 liveuser 7422
			#設置執行失敗
7423
			$result["status"]="false";
226 liveuser 7424
 
3 liveuser 7425
			#設置執行錯誤訊息
7426
			$result["error"][]="\$conf變數須為陣列形態";
7427
 
7428
			#如果傳入的參數為 null
7429
			if($conf==null){
226 liveuser 7430
 
3 liveuser 7431
				#設置執行錯誤訊息
7432
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7433
 
3 liveuser 7434
				}#if end
7435
 
7436
			#回傳結果
7437
			return $result;
226 liveuser 7438
 
3 liveuser 7439
			}#if end
226 liveuser 7440
 
3 liveuser 7441
		#檢查參數
7442
		#函式說明:
7443
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7444
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7445
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7446
		#$result["function"],當前執行的函式名稱.
7447
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7448
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7449
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7450
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7451
		#必填寫的參數:
7452
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7453
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7454
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7455
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePosition");
226 liveuser 7456
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7457
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7458
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7459
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7460
		#可以省略的參數:
7461
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7462
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7463
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7464
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mimeType","compressType","delFile");
226 liveuser 7465
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7466
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
7467
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,「null」代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7468
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("null","base64","false");
7469
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7470
		#$conf["arrayCountEqualCheck"][]=array();
7471
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7472
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 7473
 
3 liveuser 7474
		#如果檢查參數失敗
7475
		if($checkResult["status"]=="false"){
226 liveuser 7476
 
3 liveuser 7477
			#設置執行失敗
7478
			$result["status"]="false";
226 liveuser 7479
 
3 liveuser 7480
			#設置錯誤訊息
7481
			$result["error"]=$checkResult;
226 liveuser 7482
 
3 liveuser 7483
			#回傳結果
7484
			return $result;
226 liveuser 7485
 
3 liveuser 7486
			}#if end
226 liveuser 7487
 
3 liveuser 7488
		#如果檢查參數不通過
7489
		if($checkResult["passed"]=="false"){
226 liveuser 7490
 
3 liveuser 7491
			#設置執行失敗
7492
			$result["status"]="false";
226 liveuser 7493
 
3 liveuser 7494
			#設置錯誤訊息
7495
			$result["error"]=$checkResult;
226 liveuser 7496
 
3 liveuser 7497
			#回傳結果
7498
			return $result;
226 liveuser 7499
 
3 liveuser 7500
			}#if end
226 liveuser 7501
 
3 liveuser 7502
		#依據檔案名稱取得副檔名 $result["fileTypeName"]
7503
		#函式說明:
7504
		#將固定格式的字串分開,並回傳分開的結果。
7505
		#回傳的參數:
7506
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7507
		#$result["error"],錯誤訊息陣列
7508
		#$result["function"],當前執行的函數名稱.
7509
		#$result["oriStr"],要分割的原始字串內容
7510
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7511
		#$result["dataCounts"],爲總共分成幾段
7512
		#必填參數:
7513
		$conf["stringProcess::spiltString"]["stringIn"]=basename($conf["filePosition"]);#要處理的字串。
7514
		$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
7515
		#備註:
7516
		#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
7517
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
7518
		unset($conf["stringProcess::spiltString"]);
226 liveuser 7519
 
3 liveuser 7520
		#如果分割字串失敗
7521
		if($spiltString["status"]=="false"){
226 liveuser 7522
 
3 liveuser 7523
			#設置執行失敗
7524
			$result["status"]="false";
226 liveuser 7525
 
3 liveuser 7526
			#設置錯誤訊息
7527
			$result["error"]=$spiltString;
226 liveuser 7528
 
3 liveuser 7529
			#回傳結果
7530
			return $result;
226 liveuser 7531
 
3 liveuser 7532
			}#if end
226 liveuser 7533
 
3 liveuser 7534
		#初始化副檔名
226 liveuser 7535
		$result["fileTypeName"]="";
7536
 
3 liveuser 7537
		#如果只有一段代表沒有副檔名
7538
		if($spiltString["dataCounts"]==1){
226 liveuser 7539
 
3 liveuser 7540
			#副檔名設置為 "unknow"
7541
			$result["fileTypeName"]="unknow";
226 liveuser 7542
 
3 liveuser 7543
			}#if end
226 liveuser 7544
 
3 liveuser 7545
		#不符合以上條件,但至少有兩段
7546
		else if($spiltString["dataCounts"]>=2){
226 liveuser 7547
 
3 liveuser 7548
			#執行 $spiltString["dataCounts"] 減一次的迴圈
7549
			for($i=1;$i<$spiltString["dataCounts"];$i++){
226 liveuser 7550
 
3 liveuser 7551
				#串接副檔名
7552
				$result["fileTypeName"]=$result["fileTypeName"].".".$spiltString["dataArray"][$i];
226 liveuser 7553
 
3 liveuser 7554
				}#for end
226 liveuser 7555
 
3 liveuser 7556
			}#if end
226 liveuser 7557
 
3 liveuser 7558
		#讀取檔案內容
7559
		$fileBin=file_get_contents($conf["filePosition"],"rb");
226 liveuser 7560
 
3 liveuser 7561
		#編碼檔案
7562
		$base64fileBin=base64_encode($fileBin);
226 liveuser 7563
 
3 liveuser 7564
		#如果 $conf["delFile"] 等於 "true"
7565
		if($conf["delFile"]=="true"){
226 liveuser 7566
 
3 liveuser 7567
			#移除檔案
7568
			#函式說明:
7569
			#移除檔案
7570
			#回傳結果:
7571
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7572
			#$result["error"],錯誤訊息陣列
7573
			#$result["warning"],警告訊息陣列
7574
			#$result["function"],當前執行的函數名稱
7575
			#必填參數:
7576
			$conf["fileAccess::delFile"]["fileAddress"]=$conf["filePosition"];#要移除檔案的位置
7577
			$del=fileAccess::delFile($conf["fileAccess::delFile"]);
7578
			unset($conf["fileAccess::delFile"]);
226 liveuser 7579
 
3 liveuser 7580
			#如果移除圖片失敗
7581
			if($del["status"]=="false"){
226 liveuser 7582
 
3 liveuser 7583
				#設置執行失敗
7584
				$result["status"]="false";
226 liveuser 7585
 
3 liveuser 7586
				#設置錯誤訊息
7587
				$result["error"]=$del;
226 liveuser 7588
 
3 liveuser 7589
				#回傳結果
7590
				return $result;
226 liveuser 7591
 
3 liveuser 7592
				}#if end
226 liveuser 7593
 
3 liveuser 7594
			}#if end
226 liveuser 7595
 
3 liveuser 7596
		#放置檔案的語法
7597
		$result["content"]="data:".$conf["mimeType"].";".$conf["compressType"].",".$base64fileBin;
226 liveuser 7598
 
3 liveuser 7599
		#執行到這邊代表執行正常
7600
		$result["status"]="true";
226 liveuser 7601
 
3 liveuser 7602
		#回傳結果
7603
		return $result;
226 liveuser 7604
 
3 liveuser 7605
		}#function data end
7606
 
7607
	/*
7608
	#函式說明:
7609
	#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
7610
	#回傳結果:
7611
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7612
	#$result["error"],錯誤訊息陣列.
226 liveuser 7613
	#$result["function"],函數名稱.
3 liveuser 7614
	#$result["argu"],使用的參數.
7615
	#$result["content"],網址,若是在命令列執行,則為"null".
7616
	#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
7617
	#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
7618
	#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
7619
	#必填參數:
7620
	#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
7621
	$conf["address"]="";
7622
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7623
	$conf["fileArgu"]=__FILE__;
7624
	#可省略參數:
7625
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
7626
	#$conf["userDir"]="true";
7627
	#參考資料:
7628
	#無.
7629
	#備註:
7630
	#無.
7631
	*/
7632
	public static function getInternetAddress(&$conf){
226 liveuser 7633
 
3 liveuser 7634
		#初始化要回傳的變數
7635
		$result=array();
226 liveuser 7636
 
3 liveuser 7637
		#記錄當前執行的函數名稱
7638
		$result["function"]=__FUNCTION__;
226 liveuser 7639
 
3 liveuser 7640
		#如果 $conf 不為陣列
7641
		if(gettype($conf)!="array"){
226 liveuser 7642
 
3 liveuser 7643
			#設置執行失敗
7644
			$result["status"]="false";
226 liveuser 7645
 
3 liveuser 7646
			#設置執行錯誤訊息
7647
			$result["error"][]="\$conf變數須為陣列形態";
7648
 
7649
			#如果傳入的參數為 null
7650
			if($conf==null){
226 liveuser 7651
 
3 liveuser 7652
				#設置執行錯誤訊息
7653
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7654
 
3 liveuser 7655
				}#if end
7656
 
7657
			#回傳結果
7658
			return $result;
226 liveuser 7659
 
3 liveuser 7660
			}#if end
7661
 
7662
		#取得使用的參數
7663
		$result["argu"]=$conf;
226 liveuser 7664
 
3 liveuser 7665
		#檢查參數
7666
		#函式說明:
7667
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7668
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7669
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7670
		#$result["function"],當前執行的函式名稱.
7671
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7672
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7673
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7674
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7675
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7676
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7677
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7678
		#必填寫的參數:
7679
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7680
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7681
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7682
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("address","fileArgu");
226 liveuser 7683
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7684
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
7685
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7686
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7687
		#可以省略的參數:
7688
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7689
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7690
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7691
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("userDir");
226 liveuser 7692
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7693
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
7694
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7695
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
7696
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7697
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
7698
		#參考資料來源:
7699
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7700
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7701
		unset($conf["variableCheck::checkArguments"]);
7702
 
7703
		#如果檢查失敗
7704
		if($checkResult["status"]==="false"){
226 liveuser 7705
 
3 liveuser 7706
			#設置錯誤狀態
7707
			$result["status"]="false";
226 liveuser 7708
 
3 liveuser 7709
			#設置錯誤提示
7710
			$result["error"]=$checkResult;
226 liveuser 7711
 
3 liveuser 7712
			#回傳結果
7713
			return $result;
226 liveuser 7714
 
3 liveuser 7715
			}#if end
7716
 
7717
		#如果檢查不通過
7718
		if($checkResult["passed"]==="false"){
226 liveuser 7719
 
3 liveuser 7720
			#設置錯誤狀態
7721
			$result["status"]="false";
226 liveuser 7722
 
3 liveuser 7723
			#設置錯誤提示
7724
			$result["error"]=$checkResult;
226 liveuser 7725
 
3 liveuser 7726
			#回傳結果
7727
			return $result;
226 liveuser 7728
 
3 liveuser 7729
			}#if end
226 liveuser 7730
 
3 liveuser 7731
		#如果是本來就是網址了
7732
		if(strpos($conf["address"],'https://')===0 || strpos($conf["address"],'http://')===0){
226 liveuser 7733
 
3 liveuser 7734
			#設置執行正常
7735
			$result["status"]="true";
226 liveuser 7736
 
3 liveuser 7737
			#取得網址
7738
			$result["content"]=$conf["address"];
226 liveuser 7739
 
3 liveuser 7740
			#回傳結果
226 liveuser 7741
			return $result;
7742
 
7743
			}#if end
7744
 
3 liveuser 7745
		#解析 $conf["fileArgu"]
7746
		#函式說明:
7747
		#將固定格式的字串分開,並回傳分開的結果。
7748
		#回傳的參數:
7749
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7750
		#$result["error"],錯誤訊息陣列
7751
		#$result["function"],當前執行的函數名稱.
7752
		#$result["oriStr"],要分割的原始字串內容
7753
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7754
		#$result["dataCounts"],爲總共分成幾段
7755
		#必填參數:
7756
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
7757
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7758
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7759
		unset($conf["stringProcess::spiltString"]);
7760
 
3 liveuser 7761
		#如果分割字串失敗
7762
		if($spiltString["status"]==="false"){
226 liveuser 7763
 
3 liveuser 7764
			#設置錯誤狀態
7765
			$result["status"]="false";
226 liveuser 7766
 
3 liveuser 7767
			#設置錯誤提示
7768
			$result["error"]=$spiltString;
226 liveuser 7769
 
3 liveuser 7770
			#回傳結果
7771
			return $result;
226 liveuser 7772
 
3 liveuser 7773
			}#if end
226 liveuser 7774
 
3 liveuser 7775
		#函式說明:
7776
		#將多個路徑字串變成相對於當前路徑的相對路徑字串
7777
		#回傳結果:
7778
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7779
		#$result["error"],錯誤訊息陣列.
226 liveuser 7780
		#$result["function"],函數名稱.
3 liveuser 7781
		#$result["content"],字串陣列,多個轉換好的相對路徑字串.
7782
		#必填參數:
7783
		#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
7784
		$conf["fileAccess::getRelativePath"]["path"]=array($conf["address"]);
7785
		#$conf["fileArgu"],字串,當前路徑.
7786
		$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
7787
		$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
7788
		unset($conf["fileAccess::getRelativePath"]);
226 liveuser 7789
 
3 liveuser 7790
		#如果取得相對位置失敗
7791
		if($getRelativePath["status"]==="false"){
226 liveuser 7792
 
3 liveuser 7793
			#設置錯誤狀態
7794
			$result["status"]="false";
226 liveuser 7795
 
3 liveuser 7796
			#設置錯誤提示
7797
			$result["error"]=$getRelativePath;
226 liveuser 7798
 
3 liveuser 7799
			#回傳結果
7800
			return $result;
226 liveuser 7801
 
7802
			}#if end
7803
 
3 liveuser 7804
		#取得轉換成相對路徑的位置
7805
		$result["fileSystemRelativePosition"]=$getRelativePath["content"][0];
226 liveuser 7806
 
3 liveuser 7807
		#解析 $conf["fileArgu"]
7808
		#函式說明:
7809
		#將固定格式的字串分開,並回傳分開的結果。
7810
		#回傳的參數:
7811
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7812
		#$result["error"],錯誤訊息陣列
7813
		#$result["function"],當前執行的函數名稱.
7814
		#$result["oriStr"],要分割的原始字串內容
7815
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7816
		#$result["dataCounts"],爲總共分成幾段
7817
		#必填參數:
7818
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
7819
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7820
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7821
		unset($conf["stringProcess::spiltString"]);
7822
 
3 liveuser 7823
		#如果分割字串失敗
7824
		if($spiltString["status"]==="false"){
226 liveuser 7825
 
3 liveuser 7826
			#設置錯誤狀態
7827
			$result["status"]="false";
226 liveuser 7828
 
3 liveuser 7829
			#設置錯誤提示
7830
			$result["error"]=$spiltString;
226 liveuser 7831
 
3 liveuser 7832
			#回傳結果
7833
			return $result;
226 liveuser 7834
 
3 liveuser 7835
			}#if end
226 liveuser 7836
 
3 liveuser 7837
		#debug
7838
		#var_dump($spiltString);
7839
		#var_dump($_SERVER);
7840
 
7841
		#初始化檔案在伺服器上的檔案系統位置
7842
		$result["fileSystemAbsoulutePosition"]="/";
226 liveuser 7843
 
3 liveuser 7844
		#將最後一段捨棄
7845
		for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7846
 
3 liveuser 7847
			$result["fileSystemAbsoulutePosition"]=$result["fileSystemAbsoulutePosition"].$spiltString["dataArray"][$i]."/";
226 liveuser 7848
 
7849
			}#for end
7850
 
3 liveuser 7851
		#取得非直觀的絕對位置
7852
		$result["fileSystemAbsoulutePosition"]=$result["fileSystemAbsoulutePosition"].$result["fileSystemRelativePosition"];
226 liveuser 7853
 
3 liveuser 7854
		#將檔案的相對路徑進行整理,變成可以直接讀的路徑.
7855
		#函式說明:
7856
		#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
7857
		#回傳的結果:
7858
		#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
7859
		#$result["function"],當前執行的函數.
7860
		#$result["error"],錯誤訊息陣列.
7861
		#$result["changedPath"],處理完後回傳的目錄字串.
7862
		#$result["oriPath"],原始的路徑字串
7863
		#必填參數:
7864
		#$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"],字串,要處理的檔案目錄字串.
7865
		$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$result["fileSystemAbsoulutePosition"];
7866
		$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
7867
		unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 7868
 
3 liveuser 7869
		#如果處理失敗
7870
		if($changeDirByDotDotSolidus["status"]==="false"){
226 liveuser 7871
 
3 liveuser 7872
			#設置錯誤狀態
7873
			$result["status"]="false";
226 liveuser 7874
 
3 liveuser 7875
			#設置錯誤提示
7876
			$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 7877
 
3 liveuser 7878
			#回傳結果
7879
			return $result;
226 liveuser 7880
 
3 liveuser 7881
			}#if end
226 liveuser 7882
 
3 liveuser 7883
		#改變為易讀的絕對路徑
226 liveuser 7884
		$result["fileSystemAbsoulutePosition"]=$changeDirByDotDotSolidus["changedPath"];
7885
 
3 liveuser 7886
		#如果 $conf["userDir"] 為 "true"
7887
		if($conf["userDir"]==="true"){
226 liveuser 7888
 
3 liveuser 7889
			#重設為 絕對路徑 [/~家目錄名稱」
7890
			$result["webPathFromRoot"]="/~".$spiltString["dataArray"][1];
226 liveuser 7891
 
3 liveuser 7892
			#從第四段到倒數第二段,將其內容合併
7893
			for($i=3;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7894
 
3 liveuser 7895
				$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$spiltString["dataArray"][$i];
226 liveuser 7896
 
3 liveuser 7897
				}#for end
226 liveuser 7898
 
3 liveuser 7899
			}#if end
226 liveuser 7900
 
3 liveuser 7901
		#反之 $conf["userDir"] 為 "false",
7902
		else{
226 liveuser 7903
 
3 liveuser 7904
			#重設為 ""
7905
			$result["webPathFromRoot"]="";
7906
 
226 liveuser 7907
			#可能的根目錄層級 - start
7908
 
3 liveuser 7909
			#解析 $conf["fileArgu"]
7910
			#函式說明:
7911
			#將固定格式的字串分開,並回傳分開的結果。
7912
			#回傳的參數:
7913
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7914
			#$result["error"],錯誤訊息陣列
7915
			#$result["function"],當前執行的函數名稱.
7916
			#$result["oriStr"],要分割的原始字串內容
7917
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7918
			#$result["dataCounts"],爲總共分成幾段
7919
			#必填參數:
7920
			$conf["stringProcess::spiltString"]["stringIn"]=$_SERVER["PHP_SELF"];#要處理的字串。
7921
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7922
			$keyWord=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7923
			unset($conf["stringProcess::spiltString"]);
3 liveuser 7924
 
7925
			#如果處理失敗
7926
			if($keyWord["status"]==="false"){
226 liveuser 7927
 
3 liveuser 7928
				#設置錯誤狀態
7929
				$result["status"]="false";
226 liveuser 7930
 
3 liveuser 7931
				#設置錯誤提示
7932
				$result["error"]=$keyWord;
226 liveuser 7933
 
3 liveuser 7934
				#回傳結果
7935
				return $result;
226 liveuser 7936
 
3 liveuser 7937
				}#if end
226 liveuser 7938
 
3 liveuser 7939
			#取得關鍵字
7940
			$keyWord=$keyWord["dataArray"][0];
7941
 
7942
			#預設層級為4層
7943
			$layer=4;
7944
 
7945
			#檢查每個絕對路徑片段
7946
			for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7947
 
3 liveuser 7948
				#如果路徑片段等於 $keyWord
7949
				if($spiltString["dataArray"][$i]===$keyWord){
226 liveuser 7950
 
3 liveuser 7951
					#取得層級
7952
					$layer=$i;
226 liveuser 7953
 
3 liveuser 7954
					#跳出迴圈
7955
					break;
7956
 
7957
					}#if end
226 liveuser 7958
 
3 liveuser 7959
				}#for end
7960
 
7961
			#可能的根目錄層級 - end
7962
 
7963
			#網頁於檔案系統中的存放路徑可能為「/var/www/html」,從第四段到倒數第二段,將其內容合併
7964
			for($i=$layer;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7965
 
3 liveuser 7966
				$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$spiltString["dataArray"][$i];
226 liveuser 7967
 
3 liveuser 7968
				}#for end
226 liveuser 7969
 
3 liveuser 7970
			}#else end
226 liveuser 7971
 
3 liveuser 7972
		#加上檔案的路徑
226 liveuser 7973
		$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$conf["address"];
7974
 
3 liveuser 7975
		#取得檔案位於網頁伺服器的絕對位置
7976
		#函式說明:
7977
		#取得用戶端的資訊,並依據需要寫入到資料表裡面
7978
		#回傳結果:
7979
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
7980
		#$result["error"],錯誤訊息.
7981
		#$result["function"],檔前執行的函數名稱.
7982
		#$result["userBrowserType"],爲使用者的瀏覽器資訊
7983
		#$result["userIp"],爲使用者的IP
7984
		#$result["serverIp"],為伺服器的IP
7985
		#$result["scheme"],通訊協定
7986
		#$result["serverPort"],伺服器給對外下載網頁的port
7987
		#$result["requestUri"],爲使用者要求的網址
7988
		#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
7989
		#$result["clientRequestIP"],用戶端要求的ip與port
7990
		#必填參數:
7991
		$conf["csInformation::getConnectionInfo"]["getAccount"]="false";#是否要取得帳號
7992
		#可省略參數:
7993
		#$conf["accountVar"]=$_SESSION["username"];#帳號儲存在哪個變數裏面,預設爲$_SESSION["username"]
7994
		#$conf["saveToDb"]="true";#是否要除儲存到資料庫,"true"為要儲存",預設為不儲存
7995
		#$conf["dbAddress"]=$dbAddress;;#爲mysql-Server的位置,若#$conf["saveToDb"]設為"true",則該參數為必填。
7996
		#$conf["dbAccount"]=$dbAccount;#爲用於連入mysql-Server時要使用的帳號,若#$conf["saveToDb"]設為"true",則該參數為必填。
7997
		#$conf["dbName"]=$dbName;#要選取的資料庫名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
7998
		#$conf["tableName"]="visitorInfo";#爲要插入資料的資料表名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
7999
		#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");#爲資料表的項目名稱,
8000
			#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
8001
			#寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間
8002
			#$conf["saveToDb"]設為"true",則該參數為必填。
8003
		#$conf["dbPassword"]=$dbPassword;#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
8004
		$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
226 liveuser 8005
		unset($conf["csInformation::getConnectionInfo"]);
8006
 
3 liveuser 8007
		#如果取得連線資訊失敗
8008
		if($getConnectionInfo["status"]==="false"){
226 liveuser 8009
 
3 liveuser 8010
			#設置錯誤狀態
8011
			$result["status"]="false";
226 liveuser 8012
 
3 liveuser 8013
			#設置錯誤提示
8014
			$result["error"]=$getConnectionInfo;
226 liveuser 8015
 
3 liveuser 8016
			#回傳結果
8017
			return $result;
226 liveuser 8018
 
3 liveuser 8019
			}#if end
226 liveuser 8020
 
3 liveuser 8021
		#如果運行環境為 "web"
8022
		if($getConnectionInfo["mode"]=="web"){
226 liveuser 8023
 
3 liveuser 8024
			#為絕對路徑加上通訊協定與ip與port
226 liveuser 8025
			#$result["content"]=$getConnectionInfo["scheme"]."://".$getConnectionInfo["serverIp"].":".$getConnectionInfo["serverPort"].$result["webPathFromRoot"];
8026
 
8027
			#為絕對路徑加上用戶端通訊協定與ip與port
3 liveuser 8028
			$result["content"]=$getConnectionInfo["scheme"]."://".$getConnectionInfo["clientRequestIP"].$result["webPathFromRoot"];
226 liveuser 8029
 
3 liveuser 8030
			}#if end
226 liveuser 8031
 
3 liveuser 8032
		#反之如果為 "cmd" 環境
8033
		else{
226 liveuser 8034
 
3 liveuser 8035
			$result["content"]="null";
226 liveuser 8036
 
3 liveuser 8037
			}#else end
226 liveuser 8038
 
3 liveuser 8039
		#設置執行正常
8040
		$result["status"]="true";
226 liveuser 8041
 
3 liveuser 8042
		#回傳結果
8043
		return $result;
226 liveuser 8044
 
3 liveuser 8045
		}#function getInternetAddress end
8046
 
8047
	/*
8048
	#函式說明:
8049
	#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
8050
	#回傳結果:
8051
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8052
	#$result["error"],錯誤訊息陣列.
226 liveuser 8053
	#$result["function"],函數名稱.
3 liveuser 8054
	#$result["argu"],使用的參數.
8055
	#$result["content"],網址,若是在命令列執行,則為"null".
8056
	#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
8057
	#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
8058
	#必填參數:
8059
	#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
8060
	$conf["address"]="";
8061
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8062
	$conf["fileArgu"]=__FILE__;
8063
	#可省略參數:
8064
	#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
8065
	#$conf["web"]="true";
8066
	#參考資料:
8067
	#無.
8068
	#備註:
8069
	#無.
8070
	*/
8071
	public static function getInternetAddressV2(&$conf){
226 liveuser 8072
 
3 liveuser 8073
		#初始化要回傳的變數
8074
		$result=array();
226 liveuser 8075
 
3 liveuser 8076
		#記錄當前執行的函數名稱
8077
		$result["function"]=__FUNCTION__;
226 liveuser 8078
 
3 liveuser 8079
		#取得參數
8080
		$result["argu"]=$conf;
226 liveuser 8081
 
3 liveuser 8082
		#檢查參數
8083
		#函式說明:
8084
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8085
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8086
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8087
		#$result["function"],當前執行的函式名稱.
8088
		#$result["argu"],設置給予的參數.
8089
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8090
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8091
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8092
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8093
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8094
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8095
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8096
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8097
		#必填寫的參數:
8098
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8099
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8100
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8101
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8102
		#可以省略的參數:
8103
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8104
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("address","fileArgu");
8105
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
8106
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
8107
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8108
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8109
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
8110
		#$conf["canNotBeEmpty"]=array();
8111
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
8112
		#$conf["canBeEmpty"]=array();
8113
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
8114
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
8115
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8116
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
8117
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8118
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
8119
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8120
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
8121
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
8122
		#$conf["disallowAllSkipableVarIsEmpty"]="";
8123
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
8124
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
8125
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8126
		#$conf["arrayCountEqualCheck"][]=array();
8127
		#參考資料來源:
8128
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8129
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8130
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 8131
 
3 liveuser 8132
		#如果檢查失敗
8133
		if($checkArguments["status"]==="false"){
226 liveuser 8134
 
3 liveuser 8135
			#設置錯誤狀態
8136
			$result["status"]="false";
226 liveuser 8137
 
3 liveuser 8138
			#設置錯誤提示
8139
			$result["error"]=$checkArguments;
226 liveuser 8140
 
3 liveuser 8141
			#回傳結果
8142
			return $result;
226 liveuser 8143
 
3 liveuser 8144
			}#if end
226 liveuser 8145
 
3 liveuser 8146
		#如果檢查不通過
8147
		if($checkArguments["passed"]==="false"){
226 liveuser 8148
 
3 liveuser 8149
			#設置錯誤狀態
8150
			$result["status"]="false";
226 liveuser 8151
 
3 liveuser 8152
			#設置錯誤提示
8153
			$result["error"]=$checkArguments;
226 liveuser 8154
 
3 liveuser 8155
			#回傳結果
8156
			return $result;
226 liveuser 8157
 
3 liveuser 8158
			}#if end
226 liveuser 8159
 
3 liveuser 8160
		#如果是本來就是網址了
8161
		if(strpos($conf["address"],'https://')===0 || strpos($conf["address"],'http://')===0){
226 liveuser 8162
 
3 liveuser 8163
			#取得網址
8164
			$result["content"]=$conf["address"];
226 liveuser 8165
 
3 liveuser 8166
			}#if end
226 liveuser 8167
 
3 liveuser 8168
		#反之是絕對或相對路徑
8169
		else{
226 liveuser 8170
 
3 liveuser 8171
			#確認 $conf["address"] 是否為 escaped 後的內容
8172
			#函式說明:
8173
			#判斷字串是否一定需要經過escapeshellarg才能為單一shell參數,並回傳可以成為單一shell參數的結果.
8174
			#回傳結果:
8175
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8176
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
8177
			#$result["function"],當前執行的函式名稱.
8178
			#$result["argu"],使用的參數.
8179
			#$result["content"],字串,單一shell參數.
8180
			#$result["escaped"],字串,"true"代表content為 escape後的結果;反之為"false".
8181
			#$result["urlEncodeStr"],字串,未被escape過的單一shell參數被url encode後的結果.
8182
			#必填參數:
8183
			#$conf["str"],字串,認為要為單一 shell參數的字串.
8184
			$conf["stringProcess::toSingleShellArg"]["str"]=$conf["address"];
8185
			#可省略參數:
8186
			#無.
8187
			#參考資料:
8188
			#無.
8189
			#備註:
8190
			#無.
8191
			$toSingleShellArg=stringProcess::toSingleShellArg($conf["stringProcess::toSingleShellArg"]);
8192
			unset($conf["stringProcess::toSingleShellArg"]);
226 liveuser 8193
 
3 liveuser 8194
			#如果執行失敗
8195
			if($toSingleShellArg["status"]==="false"){
226 liveuser 8196
 
3 liveuser 8197
				#設置錯誤狀態
8198
				$result["status"]="false";
226 liveuser 8199
 
3 liveuser 8200
				#設置錯誤提示
8201
				$result["error"]=$toSingleShellArg;
226 liveuser 8202
 
3 liveuser 8203
				#回傳結果
8204
				return $result;
226 liveuser 8205
 
3 liveuser 8206
				}#if end
226 liveuser 8207
 
3 liveuser 8208
			#取得不含escape字元的address參數
8209
			$conf["address"]=urldecode($toSingleShellArg["urlEncodeStr"]);
226 liveuser 8210
 
3 liveuser 8211
			#不是絕對位置
8212
			if(strpos($conf["address"],"/")!==0){
226 liveuser 8213
 
3 liveuser 8214
				#如果有這些參數
8215
				if( isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT']) ){
226 liveuser 8216
 
3 liveuser 8217
					#網址
8218
					$result["content"]=$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/".$conf["address"];
226 liveuser 8219
 
3 liveuser 8220
					}#if end
226 liveuser 8221
 
3 liveuser 8222
				#反之
8223
				else{
226 liveuser 8224
 
3 liveuser 8225
					#網址設置為 null
8226
					$result["content"]=null;
226 liveuser 8227
 
3 liveuser 8228
					}#else
226 liveuser 8229
 
3 liveuser 8230
				}#if end
226 liveuser 8231
 
3 liveuser 8232
			#反之是絕對位置
8233
			else{
226 liveuser 8234
 
3 liveuser 8235
				#移除開頭的 "/"
8236
				$conf["address"]=substr($conf["address"],1);
226 liveuser 8237
 
3 liveuser 8238
				#如果有這些參數
8239
				if( isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT']) ){
226 liveuser 8240
 
3 liveuser 8241
					#網址
8242
					$result["content"]=$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/".$conf["address"];
226 liveuser 8243
 
3 liveuser 8244
					}#if end
226 liveuser 8245
 
3 liveuser 8246
				#反之
8247
				else{
226 liveuser 8248
 
3 liveuser 8249
					#網址設置為 null
8250
					$result["content"]=null;
226 liveuser 8251
 
3 liveuser 8252
					}#else
226 liveuser 8253
 
3 liveuser 8254
				}#else end
226 liveuser 8255
 
3 liveuser 8256
			#取得 doc root;
8257
			$docRoot=$_SERVER['DOCUMENT_ROOT'];
226 liveuser 8258
 
3 liveuser 8259
			#如果不是網路環境
8260
			if($conf["web"]==="false"){
226 liveuser 8261
 
3 liveuser 8262
				#不採用 docRoot
8263
				$docRoot="";
226 liveuser 8264
 
3 liveuser 8265
				}#if end
226 liveuser 8266
 
3 liveuser 8267
			#如果不存在 DOCUMENT_ROOT 變數或 web 參數為 "false" 且為相對位置.
8268
			if( ($_SERVER['DOCUMENT_ROOT']==="" || $conf["web"]==="false") && (strpos($result["argu"]["address"],"/")!==0) ){
226 liveuser 8269
 
3 liveuser 8270
				#執行 "pwd" 取得當前位置
8271
				exec("pwd",$output,$status);
226 liveuser 8272
 
3 liveuser 8273
				#預設為`pwd`的結果加"/"
8274
				$docRoot=$output[0]."/";
226 liveuser 8275
 
8276
				}#if end
8277
 
3 liveuser 8278
			#如果是絕對位置
8279
			else if(strpos($result["argu"]["address"],"/")===0){
226 liveuser 8280
 
8281
				#補回 "/"
3 liveuser 8282
				$conf["address"]="/".$conf["address"];
226 liveuser 8283
 
3 liveuser 8284
				}#if end
226 liveuser 8285
 
3 liveuser 8286
			#針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
8287
			$result["fileSystemAbsoulutePosition"]=$docRoot.$conf["address"];
226 liveuser 8288
 
3 liveuser 8289
			}#else end
226 liveuser 8290
 
3 liveuser 8291
		#設置執行正常
226 liveuser 8292
		$result["status"]="true";
8293
 
3 liveuser 8294
		#回傳結果
8295
		return $result;
226 liveuser 8296
 
3 liveuser 8297
		}#function getInternetAddressV2 end
8298
 
8299
	/*
8300
	#函式說明:
8301
	#將含有「*」的檔案路徑名稱,變成多個符合條件的路徑檔案.
8302
	#回傳結果:
8303
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8304
	#$result["error"],錯誤訊息陣列.
226 liveuser 8305
	#$result["function"],函數名稱.
3 liveuser 8306
	#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
8307
	#必填參數:
8308
	#$conf["path"],字串,要解析含有「*」的檔案路徑字串.
8309
	$conf["path"]="";
8310
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8311
	$conf["fileArgu"]=__FILE__;
8312
	#可省略參數:
8313
	#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
8314
	#$conf["noDotStart"]="true";
8315
	#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
8316
	#$conf["noWaveEnd"]="true";
8317
	#參考資料:
8318
	#無.
8319
	#備註:
8320
	#無.
8321
	*/
8322
	public static function resolvePostionStringWhichContainStarSymbol(&$conf){
226 liveuser 8323
 
3 liveuser 8324
		#初始化要回傳的結果
8325
		$result=array();
226 liveuser 8326
 
3 liveuser 8327
		#設置當其函數名稱
8328
		$result["function"]=__FUNCTION__;
226 liveuser 8329
 
3 liveuser 8330
		#如果 $conf 不為陣列
8331
		if(gettype($conf)!="array"){
226 liveuser 8332
 
3 liveuser 8333
			#設置執行失敗
8334
			$result["status"]="false";
226 liveuser 8335
 
3 liveuser 8336
			#設置執行錯誤訊息
8337
			$result["error"][]="\$conf變數須為陣列形態";
8338
 
8339
			#如果傳入的參數為 null
8340
			if($conf==null){
226 liveuser 8341
 
3 liveuser 8342
				#設置執行錯誤訊息
8343
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 8344
 
3 liveuser 8345
				}#if end
8346
 
8347
			#回傳結果
8348
			return $result;
226 liveuser 8349
 
3 liveuser 8350
			}#if end
226 liveuser 8351
 
3 liveuser 8352
		#檢查參數
8353
		#函式說明:
8354
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8355
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8356
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8357
		#$result["function"],當前執行的函式名稱.
8358
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8359
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8360
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8361
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
8362
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8363
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8364
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8365
		#必填寫的參數:
8366
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8367
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8368
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8369
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 8370
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 8371
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
8372
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8373
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8374
		#可以省略的參數:
8375
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
8376
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8377
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8378
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noDotStart","noWaveEnd");
226 liveuser 8379
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 8380
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
8381
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8382
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","true");
8383
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8384
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
8385
		#參考資料來源:
8386
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8387
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8388
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 8389
 
3 liveuser 8390
		#如果 $checkResult["status"] 等於 "fasle"
8391
		if($checkResult["status"]==="false"){
226 liveuser 8392
 
3 liveuser 8393
			#設置錯誤識別
8394
			$result["status"]="false";
226 liveuser 8395
 
3 liveuser 8396
			#設置錯誤訊息
8397
			$result["error"]=$checkResult;
226 liveuser 8398
 
3 liveuser 8399
			#回傳結果
8400
			return $result;
226 liveuser 8401
 
3 liveuser 8402
			}#if end
226 liveuser 8403
 
3 liveuser 8404
		#如果 $checkResult["passed"] 等於 "fasle"
8405
		if($checkResult["passed"]==="false"){
226 liveuser 8406
 
3 liveuser 8407
			#設置錯誤識別
8408
			$result["status"]="false";
226 liveuser 8409
 
3 liveuser 8410
			#設置錯誤訊息
8411
			$result["error"]=$checkResult;
226 liveuser 8412
 
3 liveuser 8413
			#回傳結果
8414
			return $result;
226 liveuser 8415
 
3 liveuser 8416
			}#if end
226 liveuser 8417
 
3 liveuser 8418
		#轉換檔案路徑為相對於伺服器檔案系統的絕對路徑
8419
		#函式說明:
8420
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
8421
		#回傳結果:
8422
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8423
		#$result["error"],錯誤訊息陣列.
226 liveuser 8424
		#$result["function"],函數名稱.
3 liveuser 8425
		#$result["content"],網址.
8426
		#$result["localAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
8427
		#$result["fileSystemAbsoulutePosition"],針對伺服器檔案系統的絕對位置.
8428
		#必填參數:
8429
		#$conf["address"],字串,檔案的相對位置.
8430
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["path"];
8431
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8432
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
8433
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是.
8434
		$conf["fileAccess::getInternetAddress"]["userDir"]="true";
8435
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
8436
		unset($conf["fileAccess::getInternetAddress"]);
226 liveuser 8437
 
3 liveuser 8438
		#如果轉換路徑失敗
8439
		if($getInternetAddress["status"]=="false"){
226 liveuser 8440
 
3 liveuser 8441
			#設置錯誤識別
8442
			$result["status"]="false";
226 liveuser 8443
 
3 liveuser 8444
			#設置錯誤訊息
8445
			$result["error"]=$checkResult;
226 liveuser 8446
 
3 liveuser 8447
			#回傳結果
8448
			return $result;
226 liveuser 8449
 
3 liveuser 8450
			}#if end
226 liveuser 8451
 
3 liveuser 8452
		#取得轉換好的路徑
8453
		$conf["path"]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 8454
 
3 liveuser 8455
		#檢查檔案路徑字串是否含有「*」
8456
		#函式說明:
8457
		#檢查字串裡面有無指定的關鍵字
8458
		#回傳結果:
8459
		#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8460
		#$result["error"],錯誤訊息
8461
		#$result["function"],當前執行的函數名稱.
8462
		#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8463
		#$result["keyWordCount"],找到的關鍵字數量.
8464
		#必填參數:
8465
		$conf["search::findKeyWord"]["keyWord"]="*";#想要搜尋的關鍵字
8466
		$conf["search::findKeyWord"]["string"]=$conf["path"];#要被搜尋的字串內容
8467
		#可省略參數:
8468
		#$conf["fileAccess::findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8469
		$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8470
		unset($conf["search::findKeyWord"]);
226 liveuser 8471
 
3 liveuser 8472
		#如果尋找關鍵字出錯
8473
		if($findKeyWord["status"]=="false"){
226 liveuser 8474
 
3 liveuser 8475
			#設置錯誤識別
8476
			$result["status"]="false";
226 liveuser 8477
 
3 liveuser 8478
			#設置錯誤訊息
8479
			$result["error"]=$findKeyWord;
226 liveuser 8480
 
3 liveuser 8481
			#回傳結果
8482
			return $result;
226 liveuser 8483
 
3 liveuser 8484
			}#if end
226 liveuser 8485
 
3 liveuser 8486
		#如果含有「*」
8487
		if($findKeyWord["founded"]=="true"){
226 liveuser 8488
 
3 liveuser 8489
			#透過「/」分割路徑字串
8490
			#函式說明:
8491
			#將固定格式的字串分開,並回傳分開的結果。
8492
			#回傳的參數:
8493
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8494
			#$result["error"],錯誤訊息陣列
8495
			#$result["function"],當前執行的函數名稱.
8496
			#$result["oriStr"],要分割的原始字串內容
8497
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8498
			#$result["dataCounts"],爲總共分成幾段
8499
			#必填參數:
8500
			$conf["stringProcess::spiltString"]["stringIn"]=$conf["path"];#要處理的字串。
8501
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
8502
			$spiltPathStr=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8503
			unset($conf["stringProcess::spiltString"]);
226 liveuser 8504
 
3 liveuser 8505
			#如果分割字串失敗
8506
			if($spiltPathStr["status"]=="false"){
226 liveuser 8507
 
3 liveuser 8508
				#設置錯誤識別
8509
				$result["status"]="false";
226 liveuser 8510
 
3 liveuser 8511
				#設置錯誤訊息
8512
				$result["error"]=$spiltPathStr;
226 liveuser 8513
 
3 liveuser 8514
				#回傳結果
8515
				return $result;
226 liveuser 8516
 
3 liveuser 8517
				}#if end
226 liveuser 8518
 
3 liveuser 8519
			#初始化暫存展開後的檔案路徑字串
226 liveuser 8520
			$extendPath=array("");
8521
 
3 liveuser 8522
			#要解析的路徑分成幾段就執行幾次
8523
			foreach($spiltPathStr["dataArray"] as $pathPart){
226 liveuser 8524
 
3 liveuser 8525
				#檢查該段名稱是否有「*」
8526
				#函式說明:
8527
				#檢查字串裡面有無指定的關鍵字
8528
				#回傳結果:
8529
				#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8530
				#$result["error"],錯誤訊息
8531
				#$result["function"],當前執行的函數名稱.
8532
				#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8533
				#$result["keyWordCount"],找到的關鍵字數量.
8534
				#必填參數:
8535
				$conf["search::findKeyWord"]["keyWord"]="*";#想要搜尋的關鍵字
8536
				$conf["search::findKeyWord"]["string"]=$pathPart;#要被搜尋的字串內容
8537
				#可省略參數:
8538
				#$conf["fileAccess::findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8539
				$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8540
				unset($conf["search::findKeyWord"]);
226 liveuser 8541
 
3 liveuser 8542
				#如果尋找關鍵字出錯
8543
				if($findKeyWord["status"]=="false"){
226 liveuser 8544
 
3 liveuser 8545
					#設置錯誤識別
8546
					$result["status"]="false";
226 liveuser 8547
 
3 liveuser 8548
					#設置錯誤訊息
8549
					$result["error"]=$findKeyWord;
226 liveuser 8550
 
3 liveuser 8551
					#回傳結果
8552
					return $result;
226 liveuser 8553
 
8554
					}#if end
8555
 
3 liveuser 8556
				#如果不含「*」
8557
				if($findKeyWord["founded"]=="false"){
226 liveuser 8558
 
3 liveuser 8559
					#針對每個既有的路徑
8560
					for($i=0;$i<count($extendPath);$i++){
226 liveuser 8561
 
3 liveuser 8562
						#加上切割好的路徑
8563
						$extendPath[$i]=$extendPath[$i]."/".$pathPart;
226 liveuser 8564
 
3 liveuser 8565
						}#for end
226 liveuser 8566
 
3 liveuser 8567
					}#if end
226 liveuser 8568
 
8569
				#反之該段含有「*」
3 liveuser 8570
				else{
226 liveuser 8571
 
3 liveuser 8572
					#用「*」分割該段
8573
					#函式說明:
8574
					#將固定格式的字串分開,並回傳分開的結果。
8575
					#回傳的參數:
8576
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8577
					#$result["error"],錯誤訊息陣列
8578
					#$result["function"],當前執行的函數名稱.
8579
					#$result["oriStr"],要分割的原始字串內容
8580
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8581
					#$result["dataCounts"],爲總共分成幾段
8582
					#必填參數:
8583
					$conf["stringProcess::spiltString"]["stringIn"]=$pathPart;#要處理的字串。
8584
					$conf["stringProcess::spiltString"]["spiltSymbol"]="*";#爲以哪個符號作爲分割
8585
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8586
					unset($conf["stringProcess::spiltString"]);
226 liveuser 8587
 
3 liveuser 8588
					#如果分字串失敗
8589
					if($spiltString["status"]=="false"){
226 liveuser 8590
 
3 liveuser 8591
						#設置錯誤識別
8592
						$result["status"]="false";
226 liveuser 8593
 
3 liveuser 8594
						#設置錯誤訊息
8595
						$result["error"]=$spiltStringByStar;
226 liveuser 8596
 
3 liveuser 8597
						#回傳結果
8598
						return $result;
226 liveuser 8599
 
3 liveuser 8600
						}#if end
226 liveuser 8601
 
3 liveuser 8602
					#如果用「*」分割後的段數為0
8603
					if($spiltString["dataCounts"]==0){
226 liveuser 8604
 
3 liveuser 8605
						#初始化儲存符合條件的路徑
8606
						$newExtendPath=array();
226 liveuser 8607
 
3 liveuser 8608
						#代表沒有塞選條件
8609
						#當前有幾個符合條件的路徑就執行幾次
8610
						for($i=0;$i<count($extendPath);$i++){
226 liveuser 8611
 
3 liveuser 8612
							#取得該目錄下所有的東西
8613
							#取得該目錄底下的檔案目錄清單
8614
							#函式說明:
8615
							#取得目錄底下所有目錄與檔案清單.
8616
							#回傳結果:
8617
							#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8618
							#$result["error"],錯誤訊息陣列.
8619
							#$result["function"],函數名稱.
8620
							#$result["content"],陣列,目錄底下的檔案與子目錄.
8621
							#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
8622
							#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
8623
							#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
8624
							#$result["position"],目前的位置.
8625
							#必填參數:
8626
							#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
8627
							$conf["fileAccess::getList"]["position"]=$extendPath[$i];
8628
							#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8629
							$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
8630
							#可省略參數:
8631
							#無
8632
							#參考資料來源:
8633
							#opendir=>http://php.net/manual/en/function.opendir.php
8634
							#is_dir=>http://php.net/manual/en/function.is-dir.php
8635
							$getList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 8636
							unset($conf["fileAccess::getList"]);
8637
 
3 liveuser 8638
							#如果取得目標目錄底下的檔案目錄清單失敗
8639
							if($getList["status"]=="false"){
226 liveuser 8640
 
3 liveuser 8641
								#設置錯誤識別
8642
								$result["status"]="false";
226 liveuser 8643
 
3 liveuser 8644
								#設置錯誤訊息
226 liveuser 8645
								$result["error"]=$getList;
8646
 
3 liveuser 8647
								#回傳結果
8648
								return $result;
226 liveuser 8649
 
3 liveuser 8650
								}#if end
226 liveuser 8651
 
3 liveuser 8652
							#如果底下有東西
8653
							if(count($getList["content"])>0){
226 liveuser 8654
 
3 liveuser 8655
								#初始化儲存要檢查的檔案或資料夾名稱陣列
8656
								$list=array();
226 liveuser 8657
 
3 liveuser 8658
								#針對每個檔案或資料夾
8659
								foreach($getList["content"] as $num=>$array){
226 liveuser 8660
 
3 liveuser 8661
									#儲存該名稱
8662
									$list[]=$array["name"];
226 liveuser 8663
 
3 liveuser 8664
									}#foreach end
226 liveuser 8665
 
3 liveuser 8666
								#初始化儲存符合新條件字串的陣列
8667
								$tempExtendPath=array();
226 liveuser 8668
 
3 liveuser 8669
								#針對每個現有的路徑字串
8670
								for($j=0;$j<count($extendPath);$j++){
226 liveuser 8671
 
3 liveuser 8672
									#附加每個符合條件的名稱到路徑字串裡面
8673
									for($k=0;$k<count($list);$k++){
226 liveuser 8674
 
3 liveuser 8675
										#如果 $conf["noDotStart"] 為 "true"
8676
										if($conf["noDotStart"]==="true"){
226 liveuser 8677
 
3 liveuser 8678
											#將 $list[$k] 用 "/" 分割
8679
											#函式說明:
8680
											#將固定格式的字串分開,並回傳分開的結果。
8681
											#回傳結果:
8682
											#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8683
											#$result["error"],錯誤訊息陣列
8684
											#$result["function"],當前執行的函數名稱.
8685
											#$result["oriStr"],要分割的原始字串內容
8686
											#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8687
											#$result["dataCounts"],爲總共分成幾段
8688
											#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
8689
											#必填參數:
8690
											$conf["stringProcess::spiltString"]["stringIn"]=$list[$k];#要處理的字串。
8691
											$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
8692
											#可省略參數:
8693
											#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
8694
											$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
8695
											$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8696
											unset($conf["stringProcess::spiltString"]);
226 liveuser 8697
 
3 liveuser 8698
											#如果分割路徑失敗
8699
											if($spiltString["status"]==="false"){
226 liveuser 8700
 
3 liveuser 8701
												#設置執行錯誤識別
8702
												$result["status"]="false";
226 liveuser 8703
 
3 liveuser 8704
												#取得錯誤訊息
8705
												$result["error"]=$spiltString;
226 liveuser 8706
 
3 liveuser 8707
												#回傳結果
8708
												return $result;
226 liveuser 8709
 
3 liveuser 8710
												}#if end
226 liveuser 8711
 
3 liveuser 8712
											#如果有關鍵字「/」存在
8713
											if($spiltString["found"]==="true"){
226 liveuser 8714
 
3 liveuser 8715
												#針對每個段落
8716
												foreach($spiltString["dataArray"] as $pp){
226 liveuser 8717
 
3 liveuser 8718
													#看該符合的名稱開頭是否包含「.」
8719
													#函式說明:
8720
													#取得符合特定字首與字尾的字串
8721
													#回傳結果:
8722
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8723
													#$result["function"],當前執行的函數名稱.
8724
													#$result["error"],錯誤訊息陣列.
8725
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8726
													#$result["returnString"],爲符合字首條件的字串內容。
8727
													#必填參數:
8728
													#$conf["checkString"],字串,要檢查的字串.
8729
													$conf["search::getMeetConditionsString"]["checkString"]=$pp;
8730
													#可省略參數:
8731
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8732
													$conf["search::getMeetConditionsString"]["frontWord"]=".";
8733
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8734
													#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
8735
													#參考資料:
8736
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8737
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8738
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 8739
 
3 liveuser 8740
													#如果 取得符合特定字首的字串 出錯
8741
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 8742
 
3 liveuser 8743
														#設置執行錯誤識別
8744
														$result["status"]="false";
226 liveuser 8745
 
3 liveuser 8746
														#設置錯誤訊息
8747
														$result["error"]=$getMeetConditionsString;
226 liveuser 8748
 
3 liveuser 8749
														#回傳結果
8750
														return $result;
226 liveuser 8751
 
3 liveuser 8752
														}#if end
226 liveuser 8753
 
3 liveuser 8754
													#如果有「.」在開頭
8755
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8756
 
8757
														#忽略這個名稱
3 liveuser 8758
														continue 2;
226 liveuser 8759
 
3 liveuser 8760
														}#if end
226 liveuser 8761
 
3 liveuser 8762
													}#foreach end
226 liveuser 8763
 
3 liveuser 8764
												}#if end
226 liveuser 8765
 
3 liveuser 8766
											#反之沒有關鍵字「/」存在
8767
											else{
226 liveuser 8768
 
3 liveuser 8769
												#看該符合的名稱開頭是否包含「.」
8770
												#函式說明:
8771
												#取得符合特定字首與字尾的字串
8772
												#回傳結果:
8773
												#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8774
												#$result["function"],當前執行的函數名稱.
8775
												#$result["error"],錯誤訊息陣列.
8776
												#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8777
												#$result["returnString"],爲符合字首條件的字串內容。
8778
												#必填參數:
8779
												#$conf["checkString"],字串,要檢查的字串.
8780
												$conf["search::getMeetConditionsString"]["checkString"]=$list[$k];
8781
												#可省略參數:
8782
												#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8783
												$conf["search::getMeetConditionsString"]["frontWord"]=".";
8784
												#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8785
												#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
8786
												#參考資料:
8787
												#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8788
												$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8789
												unset($conf["search::getMeetConditionsString"]);
226 liveuser 8790
 
3 liveuser 8791
												#如果 取得符合特定字首的字串 出錯
8792
												if($getMeetConditionsString["status"]=="false"){
226 liveuser 8793
 
3 liveuser 8794
													#設置執行錯誤識別
8795
													$result["status"]="false";
226 liveuser 8796
 
3 liveuser 8797
													#設置錯誤訊息
8798
													$result["error"]=$getMeetConditionsString;
226 liveuser 8799
 
3 liveuser 8800
													#回傳結果
8801
													return $result;
226 liveuser 8802
 
3 liveuser 8803
													}#if end
226 liveuser 8804
 
3 liveuser 8805
												#如果有「.」在開頭
8806
												if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8807
 
8808
													#忽略這個名稱
3 liveuser 8809
													continue;
226 liveuser 8810
 
3 liveuser 8811
													}#if end
226 liveuser 8812
 
3 liveuser 8813
												}#else end
226 liveuser 8814
 
3 liveuser 8815
											}#if end
226 liveuser 8816
 
3 liveuser 8817
										#如果 $conf["noWaveEnd"] 為 "true"
8818
										if($conf["noWaveEnd"]==="true"){
226 liveuser 8819
 
3 liveuser 8820
											#看該符合的名稱結尾是否包含「~」
8821
											#函式說明:
8822
											#取得符合特定字首與字尾的字串
8823
											#回傳結果:
8824
											#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8825
											#$result["function"],當前執行的函數名稱.
8826
											#$result["error"],錯誤訊息陣列.
8827
											#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8828
											#$result["returnString"],爲符合字首條件的字串內容。
8829
											#必填參數:
8830
											#$conf["checkString"],字串,要檢查的字串.
8831
											$conf["search::getMeetConditionsString"]["checkString"]=$list[$k];
8832
											#可省略參數:
8833
											#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8834
											#$conf["search::getMeetConditionsString"]["frontWord"]=".";
8835
											#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8836
											$conf["search::getMeetConditionsString"]["tailWord"]="~";
8837
											#參考資料:
8838
											#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8839
											$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8840
											unset($conf["search::getMeetConditionsString"]);
226 liveuser 8841
 
3 liveuser 8842
											#如果 取得符合特定字首的字串 出錯
8843
											if($getMeetConditionsString["status"]=="false"){
226 liveuser 8844
 
3 liveuser 8845
												#設置執行錯誤識別
8846
												$result["status"]="false";
226 liveuser 8847
 
3 liveuser 8848
												#設置錯誤訊息
8849
												$result["error"]=$getMeetConditionsString;
226 liveuser 8850
 
3 liveuser 8851
												#回傳結果
8852
												return $result;
226 liveuser 8853
 
3 liveuser 8854
												}#if end
226 liveuser 8855
 
3 liveuser 8856
											#如果有「~」在結尾
8857
											if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8858
 
3 liveuser 8859
												#忽略這個名稱
8860
												continue;
226 liveuser 8861
 
3 liveuser 8862
												}#if end
226 liveuser 8863
 
3 liveuser 8864
											}#if end
226 liveuser 8865
 
3 liveuser 8866
										#暫存該符合的路徑
8867
										$tempExtendPath[]=$extendPath[$j]."/".$list[$k];
226 liveuser 8868
 
3 liveuser 8869
										}#for end
226 liveuser 8870
 
8871
									}#for end
8872
 
3 liveuser 8873
								#該次有幾個符合的路徑就執行幾次
8874
								foreach($tempExtendPath as $path){
226 liveuser 8875
 
3 liveuser 8876
									#暫存符合的路徑
8877
									$newExtendPath[]=$path;
226 liveuser 8878
 
8879
									}#for end
8880
 
3 liveuser 8881
								}#if end
226 liveuser 8882
 
3 liveuser 8883
							#反之該目錄底下沒有東西
8884
							else{
226 liveuser 8885
 
3 liveuser 8886
								#移除該 $extendPath[$i]
8887
								unset($extendPath[$i]);
226 liveuser 8888
 
8889
								}#else end
8890
 
3 liveuser 8891
							}#for end
226 liveuser 8892
 
3 liveuser 8893
						#置換原始符合條件字串的路徑字串陣列
8894
						$extendPath=$newExtendPath;
226 liveuser 8895
 
3 liveuser 8896
						}#if end
226 liveuser 8897
 
3 liveuser 8898
						#反之用「*」分割後有分段
8899
						else{
226 liveuser 8900
 
3 liveuser 8901
							#初始化暫存符合條件的新路徑陣列變數
8902
							$newExtendPath=array();
226 liveuser 8903
 
3 liveuser 8904
							#當前有幾個符合條件的路徑就執行幾次
8905
							for($i=0;$i<count($extendPath);$i++){
226 liveuser 8906
 
3 liveuser 8907
								#取得該目錄下所有的東西
8908
								#函式說明:
8909
								#取得目錄底下所有目錄與檔案清單.
8910
								#回傳結果:
8911
								#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8912
								#$result["error"],錯誤訊息陣列.
8913
								#$result["function"],函數名稱.
8914
								#$result["content"],陣列,目錄底下的檔案與子目錄.
8915
								#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
8916
								#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
8917
								#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
8918
								#$result["position"],目前的位置.
8919
								#必填參數:
8920
								#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
8921
								$conf["fileAccess::getList"]["position"]=$extendPath[$i];
8922
								#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8923
								$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
8924
								#可省略參數:
8925
								#無
8926
								#參考資料來源:
8927
								#opendir=>http://php.net/manual/en/function.opendir.php
8928
								#is_dir=>http://php.net/manual/en/function.is-dir.php
8929
								$getList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 8930
								unset($conf["fileAccess::getList"]);
8931
 
3 liveuser 8932
								#如果取得目標目錄底下的檔案目錄清單失敗
8933
								if($getList["status"]=="false"){
226 liveuser 8934
 
3 liveuser 8935
									#設置錯誤識別
8936
									$result["status"]="false";
226 liveuser 8937
 
3 liveuser 8938
									#設置錯誤訊息
226 liveuser 8939
									$result["error"]=$getList;
8940
 
3 liveuser 8941
									#回傳結果
8942
									return $result;
226 liveuser 8943
 
3 liveuser 8944
									}#if end
226 liveuser 8945
 
3 liveuser 8946
								#如果底下有東西
8947
								if(count($getList["content"])>0){
226 liveuser 8948
 
3 liveuser 8949
									#初始化儲存要檢查的檔案或資料夾名稱陣列
8950
									$list=array();
226 liveuser 8951
 
3 liveuser 8952
									#針對每個檔案或資料夾
8953
									foreach($getList["content"] as $num=>$array){
226 liveuser 8954
 
3 liveuser 8955
										#儲存該名稱
8956
										$list[]=$array["name"];
226 liveuser 8957
 
3 liveuser 8958
										}#foreach end
226 liveuser 8959
 
3 liveuser 8960
									#初始化儲存符合的名稱
8961
									$passedName=array();
226 liveuser 8962
 
3 liveuser 8963
									#依據每個檔案目錄名稱,檢查有無符合篩選條件
8964
									foreach($list as $filteredName){
226 liveuser 8965
 
3 liveuser 8966
										#初始化儲存被檢查的片段檔案資料夾名稱
8967
										$partName=$filteredName;
226 liveuser 8968
 
3 liveuser 8969
										#依據 $pathPart 分割成幾段(關鍵字數量)就執行幾次
8970
										for($i=0;$i<$spiltString["dataCounts"];$i++){
226 liveuser 8971
 
3 liveuser 8972
											#尋找關鍵字 $spiltString["dataArray"][$i]
8973
											#函式說明:
8974
											#檢查字串裡面有無指定的關鍵字
8975
											#回傳結果:
8976
											#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8977
											#$result["error"],錯誤訊息
8978
											#$result["function"],當前執行的函數名稱.
8979
											#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8980
											#$result["keyWordCount"],找到的關鍵字數量.
8981
											#必填參數:
8982
											$conf["search::findKeyWord"]["keyWord"]=$spiltString["dataArray"][$i];#想要搜尋的關鍵字
8983
											$conf["search::findKeyWord"]["string"]=$partName;#要被搜尋的字串內容
8984
											#可省略參數:
8985
											#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8986
											$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8987
											unset($conf["search::findKeyWord"]);
226 liveuser 8988
 
3 liveuser 8989
											#如果尋找關鍵字失敗
8990
											if($findKeyWord["status"]=="false"){
226 liveuser 8991
 
3 liveuser 8992
												#設置執行錯誤識別
8993
												$result["status"]="false";
226 liveuser 8994
 
3 liveuser 8995
												#設置錯誤訊息
8996
												$result["error"]=$findKeyWord;
226 liveuser 8997
 
3 liveuser 8998
												#回傳結果
8999
												return $result;
226 liveuser 9000
 
3 liveuser 9001
												}#if end
226 liveuser 9002
 
3 liveuser 9003
											#如果有找到關鍵字
9004
											if($findKeyWord["founded"]=="true"){
226 liveuser 9005
 
3 liveuser 9006
												#如果是最後一段要檢查的關鍵字
9007
												if($i==$spiltString["dataCounts"]-1){
226 liveuser 9008
 
3 liveuser 9009
													#判斷該關鍵字是否在該未分割的 $pathPart(含有*字號的關鍵字字串) 的開頭
9010
													#函式說明:
9011
													#取得符合特定字首與字尾的字串
9012
													#回傳結果:
9013
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9014
													#$result["function"],當前執行的函數名稱.
9015
													#$result["error"],錯誤訊息陣列.
9016
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9017
													#$result["returnString"],爲符合字首條件的字串內容。
9018
													#必填參數:
9019
													#$conf["checkString"],字串,要檢查的字串.
9020
													$conf["search::getMeetConditionsString"]["checkString"]=$pathPart;
9021
													#可省略參數:
9022
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9023
													$conf["search::getMeetConditionsString"]["frontWord"]=$spiltString["dataArray"][0];
9024
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9025
													#$conf["tailWord"]="";
9026
													#參考資料:
9027
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9028
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9029
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 9030
 
3 liveuser 9031
													#如果 取得符合特定字首的字串 出錯
9032
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 9033
 
3 liveuser 9034
														#設置執行錯誤識別
9035
														$result["status"]="false";
226 liveuser 9036
 
3 liveuser 9037
														#設置錯誤訊息
9038
														$result["error"]=$getMeetConditionsString;
226 liveuser 9039
 
3 liveuser 9040
														#回傳結果
9041
														return $result;
226 liveuser 9042
 
3 liveuser 9043
														}#if end
226 liveuser 9044
 
3 liveuser 9045
													#如果關鍵字是在開頭
9046
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9047
 
3 liveuser 9048
														#判斷關鍵字是否在該檔案目錄名稱的開頭
9049
														#函式說明:
9050
														#取得符合特定字首與字尾的字串
9051
														#回傳結果:
9052
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9053
														#$result["function"],當前執行的函數名稱.
9054
														#$result["error"],錯誤訊息陣列.
9055
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9056
														#$result["returnString"],爲符合字首條件的字串內容。
9057
														#必填參數:
9058
														#$conf["checkString"],字串,要檢查的字串.
9059
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9060
														#可省略參數:
9061
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9062
														$conf["search::getMeetConditionsString"]["frontWord"]=$spiltString["dataArray"][0];
9063
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9064
														#$conf["tailWord"]="";
9065
														#參考資料:
9066
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9067
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9068
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9069
 
3 liveuser 9070
														#如果 取得符合特定字首的字串 出錯
9071
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9072
 
3 liveuser 9073
															#設置執行錯誤識別
9074
															$result["status"]="false";
226 liveuser 9075
 
3 liveuser 9076
															#設置錯誤訊息
9077
															$result["error"]=$getMeetConditionsString;
226 liveuser 9078
 
3 liveuser 9079
															#回傳結果
9080
															return $result;
226 liveuser 9081
 
3 liveuser 9082
															}#if end
226 liveuser 9083
 
3 liveuser 9084
														#如果關鍵字不在開頭
9085
														if($getMeetConditionsString["founded"]=="false"){
226 liveuser 9086
 
3 liveuser 9087
															#不符合條件,跳過該檔案目錄名稱
9088
															break;
226 liveuser 9089
 
3 liveuser 9090
															}#if end
226 liveuser 9091
 
3 liveuser 9092
														}#if end
226 liveuser 9093
 
3 liveuser 9094
													#判斷最後一個關鍵字是否在該未分割的 $pathPart(含有*字號的關鍵字字串) 的結尾
9095
													#函式說明:
9096
													#取得符合特定字首與字尾的字串
9097
													#回傳結果:
9098
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9099
													#$result["function"],當前執行的函數名稱.
9100
													#$result["error"],錯誤訊息陣列.
9101
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9102
													#$result["returnString"],爲符合字首條件的字串內容。
9103
													#必填參數:
9104
													#$conf["checkString"],字串,要檢查的字串.
9105
													$conf["search::getMeetConditionsString"]["checkString"]=$pathPart;
9106
													#可省略參數:
9107
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9108
													#$conf["search::getMeetConditionsString"]["frontWord"]=$partName;
9109
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9110
													$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9111
													#參考資料:
9112
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9113
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9114
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 9115
 
3 liveuser 9116
													#如果 取得符合特定字尾的字串 出錯
9117
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 9118
 
3 liveuser 9119
														#設置執行錯誤識別
9120
														$result["status"]="false";
226 liveuser 9121
 
3 liveuser 9122
														#設置錯誤訊息
9123
														$result["error"]=$getMeetConditionsString;
226 liveuser 9124
 
3 liveuser 9125
														#回傳結果
9126
														return $result;
226 liveuser 9127
 
3 liveuser 9128
														}#if end
226 liveuser 9129
 
3 liveuser 9130
													#如果關鍵字是在字尾
9131
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9132
 
3 liveuser 9133
														#判斷關鍵字是否在該片段的開頭
9134
														#函式說明:
9135
														#取得符合特定字首與字尾的字串
9136
														#回傳結果:
9137
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9138
														#$result["function"],當前執行的函數名稱.
9139
														#$result["error"],錯誤訊息陣列.
9140
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9141
														#$result["returnString"],爲符合字首條件的字串內容。
9142
														#必填參數:
9143
														#$conf["checkString"],字串,要檢查的字串.
9144
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9145
														#可省略參數:
9146
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9147
														#$conf["search::getMeetConditionsString"]["frontWord"]=$partName;
9148
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9149
														$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9150
														#參考資料:
9151
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9152
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9153
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9154
 
3 liveuser 9155
														#如果 取得符合特定字首的字串 出錯
9156
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9157
 
3 liveuser 9158
															#設置執行錯誤識別
9159
															$result["status"]="false";
226 liveuser 9160
 
3 liveuser 9161
															#設置錯誤訊息
9162
															$result["error"]=$getMeetConditionsString;
226 liveuser 9163
 
3 liveuser 9164
															#回傳結果
9165
															return $result;
226 liveuser 9166
 
3 liveuser 9167
															}#if end
226 liveuser 9168
 
3 liveuser 9169
														#如果關鍵字不在結尾
9170
														if($getMeetConditionsString["founded"]=="false"){
226 liveuser 9171
 
3 liveuser 9172
															#不符合條件,跳過該檔案目錄名稱
9173
															break;
226 liveuser 9174
 
3 liveuser 9175
															}#if end
226 liveuser 9176
 
3 liveuser 9177
														}#if end
226 liveuser 9178
 
3 liveuser 9179
													#如果 $conf["noDotStart"] 為 "true"
9180
													if($conf["noDotStart"]==="true"){
226 liveuser 9181
 
3 liveuser 9182
														#看該符合的名稱開頭是否包含「.」
9183
														#函式說明:
9184
														#取得符合特定字首與字尾的字串
9185
														#回傳結果:
9186
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9187
														#$result["function"],當前執行的函數名稱.
9188
														#$result["error"],錯誤訊息陣列.
9189
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9190
														#$result["returnString"],爲符合字首條件的字串內容。
9191
														#必填參數:
9192
														#$conf["checkString"],字串,要檢查的字串.
9193
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9194
														#可省略參數:
9195
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9196
														$conf["search::getMeetConditionsString"]["frontWord"]=".";
9197
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9198
														#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9199
														#參考資料:
9200
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9201
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9202
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9203
 
3 liveuser 9204
														#如果 取得符合特定字首的字串 出錯
9205
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9206
 
3 liveuser 9207
															#設置執行錯誤識別
9208
															$result["status"]="false";
226 liveuser 9209
 
3 liveuser 9210
															#設置錯誤訊息
9211
															$result["error"]=$getMeetConditionsString;
226 liveuser 9212
 
3 liveuser 9213
															#回傳結果
9214
															return $result;
226 liveuser 9215
 
3 liveuser 9216
															}#if end
226 liveuser 9217
 
3 liveuser 9218
														#如果有「.」在開頭
9219
														if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9220
 
3 liveuser 9221
															#中斷迴圈
9222
															break;
226 liveuser 9223
 
3 liveuser 9224
															}#if end
226 liveuser 9225
 
3 liveuser 9226
														}#if end
226 liveuser 9227
 
3 liveuser 9228
													#如果 $conf["noWaveEnd"] 為 "true"
9229
													if($conf["noWaveEnd"]==="true"){
226 liveuser 9230
 
3 liveuser 9231
														#看該符合的名稱結尾是否包含「~」
9232
														#函式說明:
9233
														#取得符合特定字首與字尾的字串
9234
														#回傳結果:
9235
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9236
														#$result["function"],當前執行的函數名稱.
9237
														#$result["error"],錯誤訊息陣列.
9238
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9239
														#$result["returnString"],爲符合字首條件的字串內容。
9240
														#必填參數:
9241
														#$conf["checkString"],字串,要檢查的字串.
9242
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9243
														#可省略參數:
9244
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9245
														#$conf["search::getMeetConditionsString"]["frontWord"]=".";
9246
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9247
														$conf["search::getMeetConditionsString"]["tailWord"]="~";
9248
														#參考資料:
9249
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9250
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9251
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9252
 
3 liveuser 9253
														#如果 取得符合特定字首的字串 出錯
9254
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9255
 
3 liveuser 9256
															#設置執行錯誤識別
9257
															$result["status"]="false";
226 liveuser 9258
 
3 liveuser 9259
															#設置錯誤訊息
9260
															$result["error"]=$getMeetConditionsString;
226 liveuser 9261
 
3 liveuser 9262
															#回傳結果
9263
															return $result;
226 liveuser 9264
 
3 liveuser 9265
															}#if end
226 liveuser 9266
 
3 liveuser 9267
														#如果有「~」在結尾
9268
														if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9269
 
3 liveuser 9270
															#中斷迴圈
9271
															break;
226 liveuser 9272
 
3 liveuser 9273
															}#if end
226 liveuser 9274
 
3 liveuser 9275
														}#if end
226 liveuser 9276
 
3 liveuser 9277
													#取得該符合的名稱
9278
													$passedName[]=$filteredName;
226 liveuser 9279
 
3 liveuser 9280
													#中斷迴圈
9281
													break;
226 liveuser 9282
 
3 liveuser 9283
													}#if end
226 liveuser 9284
 
3 liveuser 9285
												#將 $partName 從左到關鍵字結束的部份剔除
9286
												#函式說明:
9287
												#將特定字串前面的內容剔除
9288
												#回傳結果:
9289
												#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9290
												#$result["error"],錯誤訊息陣列.
9291
												#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
9292
												#$result["function"],當前執行的函數名稱.
9293
												#$result["oriStr"],要處理的原始字串內容.
9294
												#$result["content"],處理好的的字串內容.
9295
												#必填參數:
9296
												$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$partName;#要處理的字串.
9297
												$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$spiltString["dataArray"][$i];#特定字串.
9298
												$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
9299
												unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 9300
 
3 liveuser 9301
												#如果將 $partName 從左到關鍵字結束的部份剔除失敗
9302
												if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 9303
 
3 liveuser 9304
													#設置執行錯誤識別
9305
													$result["status"]="false";
226 liveuser 9306
 
3 liveuser 9307
													#設置錯誤訊息
9308
													$result["error"]=$delStrBeforeKeyWord;
226 liveuser 9309
 
3 liveuser 9310
													#回傳結果
9311
													return $result;
226 liveuser 9312
 
3 liveuser 9313
													}#if end
226 liveuser 9314
 
3 liveuser 9315
												#如果沒有找到特定關鍵字字串
9316
												if($delStrBeforeKeyWord["founded"]=="false"){
226 liveuser 9317
 
3 liveuser 9318
													#設置執行錯誤識別
9319
													$result["status"]="false";
226 liveuser 9320
 
3 liveuser 9321
													#設置錯誤訊息
9322
													$result["error"]=$delStrBeforeKeyWord;
226 liveuser 9323
 
3 liveuser 9324
													#回傳結果
9325
													return $result;
226 liveuser 9326
 
3 liveuser 9327
													}#if end
226 liveuser 9328
 
9329
												#取得剔除過關鍵字前字串的字串
3 liveuser 9330
												$partName=$delStrBeforeKeyWord["content"];
226 liveuser 9331
 
3 liveuser 9332
												}#if end
226 liveuser 9333
 
9334
											#反之關鍵字不存在
3 liveuser 9335
											else{
226 liveuser 9336
 
3 liveuser 9337
												#儲存被拋棄的片段
9338
												#$result["dismissLog"][]="片段「".$partName."」沒有關鍵字「".$spiltString["dataArray"][$i]."」";
226 liveuser 9339
 
3 liveuser 9340
												#該名稱不符合條件
9341
												break;
226 liveuser 9342
 
3 liveuser 9343
												}#else end
226 liveuser 9344
 
3 liveuser 9345
											}#for end
226 liveuser 9346
 
3 liveuser 9347
										}#foreach end
226 liveuser 9348
 
3 liveuser 9349
									#初始化儲存符合的暫存路徑
9350
									$tempExtendPath=array();
226 liveuser 9351
 
3 liveuser 9352
									#針對每個現有的路徑字串
9353
									for($j=0;$j<count($extendPath);$j++){
226 liveuser 9354
 
3 liveuser 9355
										#附加每個符合條件的名稱到路徑字串裡面
9356
										for($k=0;$k<count($passedName);$k++){
226 liveuser 9357
 
3 liveuser 9358
											#暫存該符合的路徑
9359
											$tempExtendPath[]=$extendPath[$j]."/".$passedName[$k];
226 liveuser 9360
 
3 liveuser 9361
											}#for end
226 liveuser 9362
 
9363
										}#for end
9364
 
3 liveuser 9365
									#該次有幾個符合的路徑就執行幾次
9366
									foreach($tempExtendPath as $path){
226 liveuser 9367
 
3 liveuser 9368
										#暫存符合的路徑
9369
										$newExtendPath[]=$path;
226 liveuser 9370
 
9371
										}#foreach end
9372
 
3 liveuser 9373
									}#if end
226 liveuser 9374
 
3 liveuser 9375
								#反之該目錄底下沒有東西
9376
								else{
226 liveuser 9377
 
3 liveuser 9378
									#移除該 $extendPath[$i]
9379
									unset($extendPath[$i]);
226 liveuser 9380
 
9381
									}#else end
9382
 
3 liveuser 9383
								}#for end
226 liveuser 9384
 
3 liveuser 9385
							#如果有新的路徑產生
9386
							if(count($newExtendPath)>0){
226 liveuser 9387
 
3 liveuser 9388
								#置換原始符合條件字串的路徑字串陣列
9389
								$extendPath=$newExtendPath;
226 liveuser 9390
 
3 liveuser 9391
								}#if end
226 liveuser 9392
 
3 liveuser 9393
							#反之找不到後續符合的路徑
9394
							else{
226 liveuser 9395
 
3 liveuser 9396
								$extendPath=array();
226 liveuser 9397
 
3 liveuser 9398
								}#else end
226 liveuser 9399
 
3 liveuser 9400
							}#else end
226 liveuser 9401
 
3 liveuser 9402
					}#else end
226 liveuser 9403
 
3 liveuser 9404
				}#foreach end
226 liveuser 9405
 
3 liveuser 9406
			}#if end
226 liveuser 9407
 
3 liveuser 9408
		#反之沒有含有「*」
9409
		else{
226 liveuser 9410
 
3 liveuser 9411
			#判斷 $conf["path"] 是否存在
9412
			#函式說明:
9413
			#檢查多個檔案與資料夾是否存在.
9414
			#回傳的結果:
9415
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
9416
			#$result["error"],錯誤訊息陣列.
9417
			#$resutl["function"],當前執行的涵式名稱.
9418
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
9419
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
9420
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
9421
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
9422
			#必填參數:
9423
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
9424
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["path"]);
9425
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9426
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
9427
			#可省略參數
9428
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
9429
			#$conf["disableWebSearch"]="false";
9430
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
9431
			#$conf["userDir"]="true";
9432
			#參考資料來源:
9433
			#http://php.net/manual/en/function.file-exists.php
9434
			#http://php.net/manual/en/control-structures.foreach.php
9435
			#備註:
9436
			#函數file_exists檢查的路徑為檔案系統的路徑
9437
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
9438
			unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 9439
 
3 liveuser 9440
			#如果檢查失敗
9441
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 9442
 
3 liveuser 9443
				#設置錯誤識別
9444
				$result["status"]="false";
226 liveuser 9445
 
3 liveuser 9446
				#設置錯誤訊息
9447
				$result["error"]=$checkMultiFileExist;
226 liveuser 9448
 
3 liveuser 9449
				#回傳結果
9450
				return $result;
226 liveuser 9451
 
3 liveuser 9452
				}#if end
226 liveuser 9453
 
3 liveuser 9454
			#如果存在
9455
			if($checkMultiFileExist["varExist"][0]=="true"){
226 liveuser 9456
 
3 liveuser 9457
				#初始化暫存展開後的檔案路徑字串
9458
				$extendPath=array($conf["path"]);
226 liveuser 9459
 
3 liveuser 9460
				}#if end
226 liveuser 9461
 
3 liveuser 9462
			#反之不存在
9463
			else{
226 liveuser 9464
 
3 liveuser 9465
				#置換符合的路徑為空字串
9466
				$extendPath=array();
226 liveuser 9467
 
3 liveuser 9468
				}#else end
226 liveuser 9469
 
3 liveuser 9470
			#初始化暫存展開後的檔案路徑字串
9471
			$extendPath=array($conf["path"]);
226 liveuser 9472
 
3 liveuser 9473
			}#else end
226 liveuser 9474
 
3 liveuser 9475
		#取得解析完「*」的檔案路徑字串
9476
		$result["content"]=$extendPath;
226 liveuser 9477
 
3 liveuser 9478
		#取得有幾個檔案路徑
9479
		$result["pathCount"]=count($result["content"]);
226 liveuser 9480
 
3 liveuser 9481
		#設置執行正常
9482
		$result["status"]="true";
226 liveuser 9483
 
3 liveuser 9484
		#回傳結果
9485
		return $result;
226 liveuser 9486
 
3 liveuser 9487
		}#function resolvePostionStringWhichContainStarSymbol end
9488
 
9489
	/*
9490
	#函式說明:
9491
	#將含有「*」的多個檔案路徑名稱,變成多個符合條件的路徑檔案.
9492
	#回傳結果:
9493
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9494
	#$result["error"],錯誤訊息陣列.
226 liveuser 9495
	#$result["function"],函數名稱.
3 liveuser 9496
	#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
9497
	#$result["pathCount"],整數,有幾個路徑.
9498
	#必填參數:
9499
	#$conf["path"],字串陣列,要解析含有「*」的檔案路徑字串.
9500
	$conf["path"]=array();
9501
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
9502
	$conf["fileArgu"]=__FILE__;
9503
	#可省略參數:
9504
	#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
9505
	#$conf["noDotStart"]="true";
9506
	#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
9507
	#$conf["noWaveEnd"]="true";
9508
	#參考資料:
9509
	#無.
9510
	#備註:
9511
	#無.
9512
	*/
9513
	public static function resolveMultiPostionStringWhichContainStarSymbol(&$conf){
226 liveuser 9514
 
3 liveuser 9515
		#初始化要回傳的結果
9516
		$result=array();
226 liveuser 9517
 
3 liveuser 9518
		#設置當其函數名稱
9519
		$result["function"]=__FUNCTION__;
226 liveuser 9520
 
3 liveuser 9521
		#如果 $conf 不為陣列
9522
		if(gettype($conf)!="array"){
226 liveuser 9523
 
3 liveuser 9524
			#設置執行失敗
9525
			$result["status"]="false";
226 liveuser 9526
 
3 liveuser 9527
			#設置執行錯誤訊息
9528
			$result["error"][]="\$conf變數須為陣列形態";
9529
 
9530
			#如果傳入的參數為 null
9531
			if($conf==null){
226 liveuser 9532
 
3 liveuser 9533
				#設置執行錯誤訊息
9534
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 9535
 
3 liveuser 9536
				}#if end
9537
 
9538
			#回傳結果
9539
			return $result;
226 liveuser 9540
 
3 liveuser 9541
			}#if end
226 liveuser 9542
 
3 liveuser 9543
		#檢查參數
9544
		#函式說明:
9545
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
9546
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9547
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9548
		#$result["function"],當前執行的函式名稱.
9549
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9550
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9551
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9552
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
9553
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9554
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9555
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9556
		#必填寫的參數:
9557
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9558
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9559
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9560
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 9561
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 9562
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
9563
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9564
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9565
		#可以省略的參數:
9566
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
9567
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9568
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9569
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noDotStart","noWaveEnd");
226 liveuser 9570
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 9571
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
9572
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9573
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","true");
9574
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9575
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
9576
		#參考資料來源:
9577
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9578
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9579
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 9580
 
3 liveuser 9581
		#如果 $checkResult["status"] 等於 "fasle"
9582
		if($checkResult["status"]=="false"){
226 liveuser 9583
 
3 liveuser 9584
			#設置錯誤識別
9585
			$result["status"]="false";
226 liveuser 9586
 
3 liveuser 9587
			#設置錯誤訊息
9588
			$result["error"]=$checkResult;
226 liveuser 9589
 
3 liveuser 9590
			#回傳結果
9591
			return $result;
226 liveuser 9592
 
3 liveuser 9593
			}#if end
226 liveuser 9594
 
3 liveuser 9595
		#如果 $checkResult["passed"] 等於 "fasle"
9596
		if($checkResult["passed"]=="false"){
226 liveuser 9597
 
3 liveuser 9598
			#設置錯誤識別
9599
			$result["status"]="false";
226 liveuser 9600
 
3 liveuser 9601
			#設置錯誤訊息
9602
			$result["error"]=$checkResult;
226 liveuser 9603
 
3 liveuser 9604
			#回傳結果
9605
			return $result;
226 liveuser 9606
 
3 liveuser 9607
			}#if end
226 liveuser 9608
 
3 liveuser 9609
		#針對每個要解析的路徑字串
9610
		foreach($conf["path"] as $path){
226 liveuser 9611
 
3 liveuser 9612
			#函式說明:
9613
			#將含有「*」的檔案路徑名稱,變成多個符合條件的路徑檔案.
9614
			#回傳結果:
9615
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9616
			#$result["error"],錯誤訊息陣列.
226 liveuser 9617
			#$result["function"],函數名稱.
3 liveuser 9618
			#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
9619
			#必填參數:
9620
			#$conf["path"],字串,要解析含有「*」的檔案路徑字串.
9621
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["path"]=$path;
9622
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
9623
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["fileArgu"]=$conf["fileArgu"];
9624
			#可省略參數:
9625
			#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
9626
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["noDotStart"]=$conf["noDotStart"];
9627
			#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
9628
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["noWaveEnd"]=$conf["noWaveEnd"];
9629
			$resolvePostionStringWhichContainStarSymbol=fileAccess::resolvePostionStringWhichContainStarSymbol($conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]);
9630
			unset($conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]);
226 liveuser 9631
 
3 liveuser 9632
			#如果解析失敗
9633
			if($resolvePostionStringWhichContainStarSymbol["status"]=="false"){
226 liveuser 9634
 
3 liveuser 9635
				#設置錯誤識別
9636
				$result["status"]="false";
226 liveuser 9637
 
3 liveuser 9638
				#設置錯誤訊息
9639
				$result["error"]=$resolvePostionStringWhichContainStarSymbol;
226 liveuser 9640
 
3 liveuser 9641
				#回傳結果
9642
				return $result;
226 liveuser 9643
 
3 liveuser 9644
				}#if end
226 liveuser 9645
 
3 liveuser 9646
			#針對每個解析出來的路徑
9647
			foreach($resolvePostionStringWhichContainStarSymbol["content"] as $filteredPath){
226 liveuser 9648
 
3 liveuser 9649
				#儲存符合條件的路徑
9650
				$result["content"][]=$filteredPath;
226 liveuser 9651
 
3 liveuser 9652
				}#foreach end
226 liveuser 9653
 
3 liveuser 9654
			}#foreach end
226 liveuser 9655
 
3 liveuser 9656
		#如果有路徑存在
9657
		if(isset($result["content"])){
226 liveuser 9658
 
3 liveuser 9659
			#取得有幾個路徑
9660
			$result["pathCount"]=count($result["content"]);
226 liveuser 9661
 
3 liveuser 9662
			}#if end
226 liveuser 9663
 
9664
		#反之
3 liveuser 9665
		else{
226 liveuser 9666
 
3 liveuser 9667
			#設置空的路徑結果
9668
			$result["content"]=array();
226 liveuser 9669
 
3 liveuser 9670
			#取得有幾個路徑
9671
			$result["pathCount"]=count($result["content"]);
226 liveuser 9672
 
3 liveuser 9673
			}#else end
226 liveuser 9674
 
3 liveuser 9675
		#設置執行正常
9676
		$result["status"]="true";
226 liveuser 9677
 
3 liveuser 9678
		#回傳結果
9679
		return $result;
226 liveuser 9680
 
3 liveuser 9681
		}#function resolveMultiPostionStringWhichContainStarSymbol end
9682
 
9683
	/*
9684
	#函式說明:
9685
	#將多個路徑字串變成相對於當前路徑的相對路徑字串
9686
	#回傳結果:
9687
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9688
	#$result["error"],錯誤訊息陣列.
226 liveuser 9689
	#$result["function"],函數名稱.
3 liveuser 9690
	#$result["argu"],使用的參數.
9691
	#$result["content"],字串陣列,多個轉換好的相對路徑字串.
9692
	#$result["cmd"],使用的指令.
9693
	#必填參數:
9694
	#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
9695
	$conf["path"]=array();
9696
	#$conf["fileArgu"],字串,當前路徑.
9697
	$conf["fileArgu"]=__FILE__;
9698
	#可省略參數:
9699
	#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
9700
	#$conf["baseFrom"]="";
9701
	#參考資料:
9702
	#無.
9703
	#備註:
9704
	#無.
9705
	*/
9706
	public static function getRelativePath(&$conf){
226 liveuser 9707
 
3 liveuser 9708
		#初始化要回傳的結果
9709
		$result=array();
226 liveuser 9710
 
3 liveuser 9711
		#設置當其函數名稱
9712
		$result["function"]=__FUNCTION__;
226 liveuser 9713
 
3 liveuser 9714
		#如果 $conf 不為陣列
9715
		if(gettype($conf)!="array"){
226 liveuser 9716
 
3 liveuser 9717
			#設置執行失敗
9718
			$result["status"]="false";
226 liveuser 9719
 
3 liveuser 9720
			#設置執行錯誤訊息
9721
			$result["error"][]="\$conf變數須為陣列形態";
9722
 
9723
			#如果傳入的參數為 null
9724
			if($conf==null){
226 liveuser 9725
 
3 liveuser 9726
				#設置執行錯誤訊息
9727
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 9728
 
3 liveuser 9729
				}#if end
9730
 
9731
			#回傳結果
9732
			return $result;
226 liveuser 9733
 
3 liveuser 9734
			}#if end
226 liveuser 9735
 
3 liveuser 9736
		#檢查參數
9737
		#函式說明:
9738
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
9739
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9740
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9741
		#$result["function"],當前執行的函式名稱.
9742
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9743
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9744
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9745
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
9746
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9747
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9748
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9749
		#必填寫的參數:
9750
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9751
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9752
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9753
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 9754
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 9755
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
9756
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9757
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9758
		#可以省略的參數:
9759
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
9760
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9761
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9762
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("baseFrom");
226 liveuser 9763
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 9764
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
9765
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9766
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
9767
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9768
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
9769
		#參考資料來源:
9770
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9771
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9772
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 9773
 
3 liveuser 9774
		#如果 $checkResult["status"] 等於 "false"
9775
		if($checkResult["status"]=="false"){
226 liveuser 9776
 
3 liveuser 9777
			#設置錯誤識別
9778
			$result["status"]="false";
226 liveuser 9779
 
3 liveuser 9780
			#設置錯誤訊息
9781
			$result["error"]=$checkResult;
226 liveuser 9782
 
3 liveuser 9783
			#回傳結果
9784
			return $result;
226 liveuser 9785
 
3 liveuser 9786
			}#if end
226 liveuser 9787
 
3 liveuser 9788
		#如果 $checkResult["passed"] 等於 "fasle"
9789
		if($checkResult["passed"]=="false"){
226 liveuser 9790
 
3 liveuser 9791
			#設置錯誤識別
9792
			$result["status"]="false";
226 liveuser 9793
 
3 liveuser 9794
			#設置錯誤訊息
9795
			$result["error"]=$checkResult;
226 liveuser 9796
 
3 liveuser 9797
			#回傳結果
9798
			return $result;
226 liveuser 9799
 
3 liveuser 9800
			}#if end
226 liveuser 9801
 
3 liveuser 9802
		#取得參數
9803
		$result["argu"]=$conf;
226 liveuser 9804
 
3 liveuser 9805
		#函式說明:
9806
		#將固定格式的字串分開,並回傳分開的結果.
9807
		#回傳結果:
9808
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9809
		#$result["error"],錯誤訊息陣列
9810
		#$result["function"],當前執行的函數名稱.
9811
		#$result["argu"],使用的參數.
9812
		#$result["oriStr"],要分割的原始字串內容
9813
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9814
		#$result["dataCounts"],爲總共分成幾段
9815
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9816
		#必填參數:
9817
		#$conf["stringIn"],字串,要處理的字串.
9818
		$conf["fileAccess::spiltString"]["stringIn"]=$conf["fileArgu"];
9819
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
9820
		$conf["fileAccess::spiltString"]["spiltSymbol"]="/";
9821
		#可省略參數:
9822
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9823
		$conf["fileAccess::spiltString"]["allowEmptyStr"]="false";
9824
		#參考資料:
9825
		#無.
9826
		#備註:
9827
		#無.
9828
		$spiltString=stringProcess::spiltString($conf["fileAccess::spiltString"]);
9829
		unset($conf["fileAccess::spiltString"]);
226 liveuser 9830
 
3 liveuser 9831
		#如果執行失敗
9832
		if($spiltString["status"]==="false"){
226 liveuser 9833
 
3 liveuser 9834
			#設置錯誤識別
9835
			$result["status"]="false";
226 liveuser 9836
 
3 liveuser 9837
			#設置錯誤訊息
9838
			$result["error"]=$spiltString;
226 liveuser 9839
 
3 liveuser 9840
			#回傳結果
9841
			return $result;
226 liveuser 9842
 
3 liveuser 9843
			}#if end
226 liveuser 9844
 
3 liveuser 9845
		#如果沒有關鍵字
9846
		if($spiltString["found"]==="false"){
226 liveuser 9847
 
3 liveuser 9848
			#設置錯誤識別
9849
			$result["status"]="false";
226 liveuser 9850
 
3 liveuser 9851
			#設置錯誤訊息
9852
			$result["error"]=$spiltString;
226 liveuser 9853
 
3 liveuser 9854
			#回傳結果
9855
			return $result;
226 liveuser 9856
 
3 liveuser 9857
			}#if end
226 liveuser 9858
 
3 liveuser 9859
		#取得 $conf["fileArgu"] 的路徑
9860
		#函式說明:
9861
		#將固定格式的字串分開,並回傳分開的結果.
9862
		#回傳結果:
9863
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9864
		#$result["error"],錯誤訊息陣列
9865
		#$result["function"],當前執行的函數名稱.
9866
		#$result["argu"],使用的參數.
9867
		#$result["oriStr"],要分割的原始字串內容
9868
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9869
		#$result["dataCounts"],爲總共分成幾段
9870
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9871
		#必填參數:
9872
		#$conf["stringIn"],字串,要處理的字串.
9873
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];
9874
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
9875
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
9876
		#可省略參數:
9877
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9878
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
9879
		#參考資料:
9880
		#無.
9881
		#備註:
9882
		#無.
9883
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
9884
		unset($conf["stringProcess::spiltString"]);
226 liveuser 9885
 
3 liveuser 9886
		#如果執行失敗
9887
		if($spiltString["status"]==="false"){
226 liveuser 9888
 
3 liveuser 9889
			#設置錯誤識別
9890
			$result["status"]="false";
226 liveuser 9891
 
3 liveuser 9892
			#設置錯誤訊息
9893
			$result["error"]=$spiltString;
226 liveuser 9894
 
3 liveuser 9895
			#回傳結果
9896
			return $result;
226 liveuser 9897
 
3 liveuser 9898
			}#if end
226 liveuser 9899
 
3 liveuser 9900
		/*
9901
		#break point
9902
		var_dump($spiltString);
9903
		exit;
9904
		*/
226 liveuser 9905
 
3 liveuser 9906
		#預設 fileArgu 的路徑為 ""
9907
		$fileArguPath="";
226 liveuser 9908
 
3 liveuser 9909
		#針對每個目錄
9910
		for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 9911
 
3 liveuser 9912
			#串接路徑
9913
			$fileArguPath=$fileArguPath."/".$spiltString["dataArray"][$i];
226 liveuser 9914
 
3 liveuser 9915
			}#for end
226 liveuser 9916
 
3 liveuser 9917
		#取得相對於目標的當前位置
9918
		#函式說明:
9919
		#呼叫shell執行系統命令,並取得回傳的內容.
9920
		#回傳結果:
9921
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9922
		#$result["error"],錯誤訊息陣列.
9923
		#$result["function"],當前執行的函數名稱.
9924
		#$result["argu"],使用的參數.
9925
		#$result["cmd"],執行的指令內容.
9926
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9927
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9928
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9929
		#$result["running"],是否還在執行.
9930
		#$result["pid"],pid.
9931
		#$result["statusCode"],執行結束後的代碼.
9932
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
9933
		#必填參數:
9934
		#$conf["command"],字串,要執行的指令.
9935
		$conf["external::callShell"]["command"]="cd";
9936
		#$conf["fileArgu"],字串,變數__FILE__的內容.
9937
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
9938
		#可省略參數:
9939
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9940
		$conf["external::callShell"]["argu"]=array($fileArguPath,";","pwd");
9941
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9942
		#$conf["arguIsAddr"]=array();
9943
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9944
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9945
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9946
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9947
		#$conf["enablePrintDescription"]="true";
9948
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9949
		#$conf["printDescription"]="";
9950
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9951
		$conf["external::callShell"]["escapeshellarg"]="true";
9952
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9953
		#$conf["thereIsShellVar"]=array();
9954
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9955
		#$conf["username"]="";
9956
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9957
		#$conf["password"]="";
9958
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9959
		#$conf["useScript"]="";
9960
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9961
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9962
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9963
		#$conf["inBackGround"]="";
9964
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9965
		#$conf["getErr"]="false";
9966
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9967
		#$conf["doNotRun"]="false";
9968
		#參考資料:
9969
		#exec=>http://php.net/manual/en/function.exec.php
9970
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9971
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9972
		#備註:
9973
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9974
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9975
		$callShell=external::callShell($conf["external::callShell"]);
9976
		unset($conf["external::callShell"]);
226 liveuser 9977
 
3 liveuser 9978
		#如果執行失敗
9979
		if($callShell["status"]==="false"){
226 liveuser 9980
 
3 liveuser 9981
			#設置錯誤識別
9982
			$result["status"]="false";
226 liveuser 9983
 
3 liveuser 9984
			#設置錯誤訊息
9985
			$result["error"]=$callShell;
226 liveuser 9986
 
3 liveuser 9987
			#回傳結果
9988
			return $result;
226 liveuser 9989
 
3 liveuser 9990
			}#if end
226 liveuser 9991
 
3 liveuser 9992
		#如果執行失敗
9993
		if(!isset($callShell["output"][0])){
226 liveuser 9994
 
3 liveuser 9995
			#設置錯誤識別
9996
			$result["status"]="false";
226 liveuser 9997
 
3 liveuser 9998
			#設置錯誤訊息
9999
			$result["error"]=$callShell;
226 liveuser 10000
 
3 liveuser 10001
			#回傳結果
10002
			return $result;
226 liveuser 10003
 
10004
			}#if end
10005
 
3 liveuser 10006
		/*
10007
		#break point
10008
		var_dump($callShell);
10009
		exit;
10010
		*/
226 liveuser 10011
 
3 liveuser 10012
		#記錄執行的指令
10013
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 10014
 
3 liveuser 10015
		#保存相對於目標的當前位置
10016
		$pwd=$callShell["output"][0];
226 liveuser 10017
 
3 liveuser 10018
		#更新 fileArgu
10019
		$conf["fileArgu"]=$pwd."/".$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 10020
 
3 liveuser 10021
		#針對每個 $conf["path"]
10022
		foreach($conf["path"] as $path){
226 liveuser 10023
 
3 liveuser 10024
			#將 $path 變成易讀的格式
10025
			#函式說明:
10026
			#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
10027
			#回傳的結果:
10028
			#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
10029
			#$result["function"],當前執行的函數.
10030
			#$result["error"],錯誤訊息陣列.
10031
			#$result["changedPath"],處理完後回傳的目錄字串.
10032
			#$result["oriPath"],原始的路徑字串
10033
			#必填參數:
10034
			#$conf["dirStr"],字串,要處理的檔案目錄字串.
10035
			$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$path;
10036
			$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
10037
			unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 10038
 
3 liveuser 10039
			#如果處理失敗
10040
			if($changeDirByDotDotSolidus["status"]==="false"){
226 liveuser 10041
 
3 liveuser 10042
				#設置錯誤識別
10043
				$result["status"]="false";
226 liveuser 10044
 
3 liveuser 10045
				#設置錯誤訊息
10046
				$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10047
 
3 liveuser 10048
				#回傳結果
10049
				return $result;
226 liveuser 10050
 
3 liveuser 10051
				}#if end
226 liveuser 10052
 
3 liveuser 10053
			#取得易讀的路徑
10054
			$path=$changeDirByDotDotSolidus["changedPath"];
226 liveuser 10055
 
3 liveuser 10056
			#判斷 $path 是否為絕對路徑
10057
			#函式說明:
10058
			#取得符合特定字首與字尾的字串
10059
			#回傳結果:
10060
			#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10061
			#$result["function"],當前執行的函數名稱.
10062
			#$result["error"],錯誤訊息陣列.
10063
			#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10064
			#$result["returnString"],爲符合字首條件的字串內容。
10065
			#必填參數:
10066
			#$conf["checkString"],字串,要檢查的字串.
10067
			$conf["search::getMeetConditionsString"]["checkString"]=$path;
10068
			#可省略參數:
10069
			#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10070
			$conf["search::getMeetConditionsString"]["frontWord"]="/";
10071
			#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10072
			#$conf["tailWord"]="";
10073
			#參考資料:
10074
			#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10075
			$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
226 liveuser 10076
			unset($conf["search::getMeetConditionsString"]);
10077
 
3 liveuser 10078
			#如果檢查失敗
10079
			if($getMeetConditionsString["status"]=="false"){
226 liveuser 10080
 
3 liveuser 10081
				#設置錯誤識別
10082
				$result["status"]="false";
226 liveuser 10083
 
3 liveuser 10084
				#設置錯誤訊息
10085
				$result["error"]=$getMeetConditionsString;
226 liveuser 10086
 
3 liveuser 10087
				#回傳結果
10088
				return $result;
226 liveuser 10089
 
3 liveuser 10090
				}#if end
226 liveuser 10091
 
3 liveuser 10092
			#如果沒有「/」開頭
10093
			if($getMeetConditionsString["founded"]==="false"){
226 liveuser 10094
 
3 liveuser 10095
				#將 $conf["fileArgu"] 最後面的檔案或目錄名稱剔除
10096
				#函式說明:
10097
				#將固定格式的字串分開,並回傳分開的結果。
10098
				#回傳結果:
10099
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10100
				#$result["error"],錯誤訊息陣列
10101
				#$result["function"],當前執行的函數名稱.
10102
				#$result["oriStr"],要分割的原始字串內容
10103
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
10104
				#$result["dataCounts"],爲總共分成幾段
10105
				#必填參數:
10106
				$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
10107
				$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
10108
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
10109
				unset($conf["stringProcess::spiltString"]);
226 liveuser 10110
 
3 liveuser 10111
				#如果分割字串失敗
10112
				if($spiltString["status"]=="false"){
226 liveuser 10113
 
3 liveuser 10114
					#設置錯誤識別
10115
					$result["status"]="false";
226 liveuser 10116
 
3 liveuser 10117
					#設置錯誤訊息
10118
					$result["error"]=$spiltString;
226 liveuser 10119
 
3 liveuser 10120
					#回傳結果
10121
					return $result;
226 liveuser 10122
 
3 liveuser 10123
					}#if end
226 liveuser 10124
 
3 liveuser 10125
				#初始化相對路徑為開頭片段""
10126
				$relativePathPart="/";
226 liveuser 10127
 
3 liveuser 10128
				#剔除最後一段
10129
				for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 10130
 
3 liveuser 10131
					#串接起來
10132
					$relativePathPart=$relativePathPart.$spiltString["dataArray"][$i]."/";
226 liveuser 10133
 
3 liveuser 10134
					}#for end
226 liveuser 10135
 
3 liveuser 10136
				#如果有設定 baseFrom
10137
				if(isset($conf["baseFrom"])){
226 liveuser 10138
 
3 liveuser 10139
					#函式說明:
10140
					#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
10141
					#回傳結果:
10142
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10143
					#$result["error"],錯誤訊息陣列.
226 liveuser 10144
					#$result["function"],函數名稱.
3 liveuser 10145
					#$result["argu"],使用的參數.
10146
					#$result["content"],網址,若是在命令列執行,則為"null".
10147
					#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
10148
					#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
10149
					#必填參數:
10150
					#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
10151
					$conf["fileAccess::getInternetAddressV2"]["address"]=$path;
10152
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
10153
					$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
10154
					#可省略參數:
10155
					#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
10156
					$conf["fileAccess::getInternetAddressV2"]["web"]="false";
10157
					#參考資料:
10158
					#無.
10159
					#備註:
10160
					#無.
10161
					$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
10162
					unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 10163
 
3 liveuser 10164
					##var_dump(__LINE__." ".print_r($getInternetAddressV2,true));
226 liveuser 10165
 
3 liveuser 10166
					#如果執行失敗
10167
					if($getInternetAddressV2["status"]==="false"){
226 liveuser 10168
 
3 liveuser 10169
						#設置錯誤識別
10170
						$result["status"]="false";
226 liveuser 10171
 
3 liveuser 10172
						#設置錯誤訊息
10173
						$result["error"]=$getInternetAddressV2;
226 liveuser 10174
 
3 liveuser 10175
						#回傳結果
10176
						return $result;
226 liveuser 10177
 
3 liveuser 10178
						}#if end
226 liveuser 10179
 
3 liveuser 10180
					#取得絕對位置
10181
					$path=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 10182
 
3 liveuser 10183
					#函式說明:
10184
					#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
10185
					#回傳結果:
10186
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10187
					#$result["error"],錯誤訊息陣列.
226 liveuser 10188
					#$result["function"],函數名稱.
3 liveuser 10189
					#$result["argu"],使用的參數.
10190
					#$result["content"],網址,若是在命令列執行,則為"null".
10191
					#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
10192
					#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
10193
					#必填參數:
10194
					#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
10195
					$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["baseFrom"];
10196
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
10197
					$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
10198
					#可省略參數:
10199
					#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
10200
					$conf["fileAccess::getInternetAddressV2"]["web"]="false";
10201
					#參考資料:
10202
					#無.
10203
					#備註:
10204
					#無.
10205
					$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
10206
					unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 10207
 
3 liveuser 10208
					#var_dump(__LINE__." ".print_r($getInternetAddressV2,true));
226 liveuser 10209
 
3 liveuser 10210
					#如果執行失敗
10211
					if($getInternetAddressV2["status"]==="false"){
226 liveuser 10212
 
3 liveuser 10213
						#設置錯誤識別
10214
						$result["status"]="false";
226 liveuser 10215
 
3 liveuser 10216
						#設置錯誤訊息
10217
						$result["error"]=$getInternetAddressV2;
226 liveuser 10218
 
3 liveuser 10219
						#回傳結果
10220
						return $result;
226 liveuser 10221
 
3 liveuser 10222
						}#if end
226 liveuser 10223
 
3 liveuser 10224
					#取得絕對位置
10225
					$conf["baseFrom"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 10226
 
3 liveuser 10227
					#函式說明:
10228
					#將多個路徑字串變成相對於當前路徑的相對路徑字串
10229
					#回傳結果:
10230
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10231
					#$result["error"],錯誤訊息陣列.
226 liveuser 10232
					#$result["function"],函數名稱.
3 liveuser 10233
					#$result["argu"],使用的參數.
10234
					#$result["content"],字串陣列,多個轉換好的相對路徑字串.
10235
					#必填參數:
10236
					#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
10237
					$conf["fileAccess::getRelativePath"]["path"]=array($path);
10238
					#$conf["fileArgu"],字串,當前路徑.
10239
					$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["baseFrom"]."/name";
10240
					#可省略參數:
10241
					#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
10242
					#$conf["baseFrom"]="";
10243
					#參考資料:
10244
					#無.
10245
					#備註:
10246
					#無.
10247
					$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
10248
					unset($conf["fileAccess::getRelativePath"]);
226 liveuser 10249
 
3 liveuser 10250
					#var_dump(__LINE__." ".print_r($getRelativePath,true));
226 liveuser 10251
 
3 liveuser 10252
					#如果執行失敗
10253
					if($getRelativePath["status"]==="false"){
226 liveuser 10254
 
3 liveuser 10255
						#設置錯誤識別
10256
						$result["status"]="false";
226 liveuser 10257
 
3 liveuser 10258
						#設置錯誤訊息
10259
						$result["error"]=$getRelativePath;
226 liveuser 10260
 
3 liveuser 10261
						#回傳結果
10262
						return $result;
226 liveuser 10263
 
3 liveuser 10264
						}#if end
226 liveuser 10265
 
3 liveuser 10266
					#取得轉換好的絕對路徑
10267
					$relativePathPart=$getRelativePath["content"][0]."/";
226 liveuser 10268
 
3 liveuser 10269
					#清空path,避免出錯
10270
					$path="";
226 liveuser 10271
 
3 liveuser 10272
					}#if end
226 liveuser 10273
 
3 liveuser 10274
				#轉換成易讀的相對路徑
10275
				#函式說明:
10276
				#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
10277
				#回傳的結果:
10278
				#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
10279
				#$result["function"],當前執行的函數.
10280
				#$result["error"],錯誤訊息陣列.
10281
				#$result["changedPath"],處理完後回傳的目錄字串.
10282
				#$result["oriPath"],原始的路徑字串
10283
				#必填參數:
10284
				#$conf["dirStr"],字串,要處理的檔案目錄字串.
10285
				$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$relativePathPart.$path;
10286
				$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
10287
				unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 10288
 
10289
				#var_dump($changeDirByDotDotSolidus);
10290
 
3 liveuser 10291
				#如果轉換失敗
10292
				if($changeDirByDotDotSolidus["status"]=="false"){
226 liveuser 10293
 
3 liveuser 10294
					#設置錯誤識別
10295
					$result["status"]="false";
226 liveuser 10296
 
3 liveuser 10297
					#設置錯誤訊息
10298
					$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10299
 
3 liveuser 10300
					#回傳結果
10301
					return $result;
226 liveuser 10302
 
3 liveuser 10303
					}#if end
226 liveuser 10304
 
3 liveuser 10305
				#轉換為相對路徑
10306
				#函式說明:
10307
				#將多個路徑字串變成相對於當前路徑的相對路徑字串
10308
				#回傳結果:
10309
				#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10310
				#$result["error"],錯誤訊息陣列.
226 liveuser 10311
				#$result["function"],函數名稱.
3 liveuser 10312
				#$result["content"],字串陣列,多個轉換好的相對路徑字串.
10313
				#必填參數:
10314
				#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
10315
				$conf["fileAccess::getRelativePath"]["path"]=array($changeDirByDotDotSolidus["changedPath"]);
10316
				#$conf["fileArgu"],字串,當前路徑.
10317
				$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
10318
				$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
10319
				unset($conf["fileAccess::getRelativePath"]);
226 liveuser 10320
 
10321
				#var_dump($getRelativePath);
10322
 
3 liveuser 10323
				#如果轉換路徑失敗
10324
				if($getRelativePath["status"]==="false"){
226 liveuser 10325
 
3 liveuser 10326
					#設置錯誤識別
10327
					$result["status"]="false";
226 liveuser 10328
 
3 liveuser 10329
					#設置錯誤訊息
10330
					$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10331
 
3 liveuser 10332
					#回傳結果
10333
					return $result;
226 liveuser 10334
 
3 liveuser 10335
					}#if end
226 liveuser 10336
 
3 liveuser 10337
				#取得相對路徑
10338
				$result["content"][]=$getRelativePath["content"][0];
226 liveuser 10339
 
3 liveuser 10340
				}#if end
226 liveuser 10341
 
3 liveuser 10342
			#反之有「/」開頭
10343
			else{
10344
				#函式說明:
10345
				#移除多個絕對路徑字串開頭相同的部分
10346
				#回傳結果:
10347
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10348
				#$result["error"],錯誤訊息陣列.
10349
				#$result["function"],當前執行的函數名稱.
10350
				#$result["content"],處理好的的字串內容.
10351
				#必填參數:
10352
				#$conf["pathIn"],字串陣列,每個要處理的絕對路徑字串.
226 liveuser 10353
				$conf["fileAccess::delSamePathHead"]["pathIn"]=array($path,$conf["fileArgu"]);
3 liveuser 10354
				$delSamePathHead=fileAccess::delSamePathHead($conf["fileAccess::delSamePathHead"]);
10355
				unset($conf["fileAccess::delSamePathHead"]);
226 liveuser 10356
 
3 liveuser 10357
				#var_dump($delSamePathHead);
226 liveuser 10358
 
3 liveuser 10359
				#如果移除多個絕對路徑字串開頭相同的部分失敗
10360
				if($delSamePathHead["status"]==="false"){
226 liveuser 10361
 
3 liveuser 10362
					#設置錯誤識別
10363
					$result["status"]="false";
226 liveuser 10364
 
3 liveuser 10365
					#設置錯誤訊息
10366
					$result["error"]=$delSameHead;
226 liveuser 10367
 
3 liveuser 10368
					#回傳結果
10369
					return $result;
226 liveuser 10370
 
3 liveuser 10371
					}#if end
226 liveuser 10372
 
3 liveuser 10373
				#如果 $conf["fileArgu"] 剩下空
10374
				if($delSamePathHead["content"][1]===""){
226 liveuser 10375
 
3 liveuser 10376
					#檢查 $delSamePathHead[0] 開頭是否為「/」
10377
					#函式說明:
10378
					#取得符合特定字首與字尾的字串
10379
					#回傳結果:
10380
					#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10381
					#$result["function"],當前執行的函數名稱.
10382
					#$result["error"],錯誤訊息陣列.
10383
					#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10384
					#$result["returnString"],爲符合字首條件的字串內容。
10385
					#必填參數:
10386
					#$conf["checkString"],字串,要檢查的字串.
10387
					$conf["search::getMeetConditionsString"]["checkString"]=$delSamePathHead["content"][0];
10388
					#可省略參數:
10389
					#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10390
					$conf["search::getMeetConditionsString"]["frontWord"]="/";
10391
					#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10392
					#$conf["tailWord"]="";
10393
					#參考資料:
10394
					#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10395
					$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
10396
					unset($conf["search::getMeetConditionsString"]);
226 liveuser 10397
 
3 liveuser 10398
					#如果檢查失敗
10399
					if($getMeetConditionsString["status"]=="false"){
226 liveuser 10400
 
3 liveuser 10401
						#設置錯誤識別
10402
						$result["status"]="false";
226 liveuser 10403
 
3 liveuser 10404
						#設置錯誤訊息
10405
						$result["error"]=$getMeetConditionsString;
226 liveuser 10406
 
3 liveuser 10407
						#回傳結果
10408
						return $result;
226 liveuser 10409
 
3 liveuser 10410
						}#if end
226 liveuser 10411
 
3 liveuser 10412
					#如果有開頭有「/」
10413
					if($getMeetConditionsString["founded"]==="true"){
226 liveuser 10414
 
3 liveuser 10415
						#函式說明:
10416
						#將字串特定關鍵字與其前面的內容剔除
10417
						#回傳結果:
10418
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10419
						#$result["error"],錯誤訊息陣列.
10420
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
10421
						#$result["function"],當前執行的函數名稱.
10422
						#$result["oriStr"],要處理的原始字串內容.
10423
						#$result["content"],處理好的的字串內容.
10424
						#必填參數:
10425
						$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$delSamePathHead["content"][0];#要處理的字串.
10426
						$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="/";#特定字串.
10427
						$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
10428
						unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 10429
 
3 liveuser 10430
						#如果 將字串特定關鍵字與其前面的內容剔除 失敗
10431
						if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 10432
 
3 liveuser 10433
							#設置錯誤識別
10434
							$result["status"]="false";
226 liveuser 10435
 
3 liveuser 10436
							#設置錯誤訊息
10437
							$result["error"]=$delStrBeforeKeyWord;
226 liveuser 10438
 
3 liveuser 10439
							#回傳結果
10440
							return $result;
226 liveuser 10441
 
3 liveuser 10442
							}#if end
226 liveuser 10443
 
3 liveuser 10444
						#取得相對位置
10445
						$result["content"][]=$delStrBeforeKeyWord["content"];
226 liveuser 10446
 
3 liveuser 10447
						}#if end
226 liveuser 10448
 
3 liveuser 10449
					#反之
10450
					else{
226 liveuser 10451
 
3 liveuser 10452
						#取得相對位置
10453
						$result["content"][]=$delSamePathHead["content"][0];
226 liveuser 10454
 
10455
						}#else end
10456
 
3 liveuser 10457
					}#if end
226 liveuser 10458
 
3 liveuser 10459
				#反之剩下的 $conf["fileArgu"] 不為空
10460
				else{
226 liveuser 10461
 
3 liveuser 10462
					#檢查 $delSamePathHead["content"][1] 有幾個「/」
10463
					#函式說明:
10464
					#檢查字串裡面有無指定的關鍵字
10465
					#回傳結果:
10466
					#$result["status"],"true"代表執行成功,"false"代表執行失敗。
10467
					#$result["error"],錯誤訊息
10468
					#$result["function"],當前執行的函數名稱.
10469
					#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
10470
					#$result["keyWordCount"],找到的關鍵字數量.
10471
					#必填參數:
10472
					$conf["search::findKeyWord"]["keyWord"]="/";#想要搜尋的關鍵字
10473
					$conf["search::findKeyWord"]["string"]=$delSamePathHead["content"][1];#要被搜尋的字串內容
10474
					#可省略參數:
10475
					#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
10476
					$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
10477
					unset($conf["search::findKeyWord"]);
226 liveuser 10478
 
3 liveuser 10479
					#如果 檢查字串裡面有無指定的關鍵字 失敗
10480
					if($findKeyWord["status"]==="false"){
226 liveuser 10481
 
3 liveuser 10482
						#設置錯誤識別
10483
						$result["status"]="false";
226 liveuser 10484
 
3 liveuser 10485
						#設置錯誤訊息
10486
						$result["error"]=$findKeyWord;
226 liveuser 10487
 
3 liveuser 10488
						#回傳結果
10489
						return $result;
226 liveuser 10490
 
3 liveuser 10491
						}#if end
226 liveuser 10492
 
3 liveuser 10493
					#有幾個「/」就執行幾次
10494
					for($i=0;$i<$findKeyWord["keyWordCount"];$i++){
226 liveuser 10495
 
3 liveuser 10496
						#在前面加上 "../"
10497
						$delSamePathHead["content"][0]="../".$delSamePathHead["content"][0];
226 liveuser 10498
 
3 liveuser 10499
						}#for end
226 liveuser 10500
 
3 liveuser 10501
					#取得相對位置
10502
					$result["content"][]=$delSamePathHead["content"][0];
226 liveuser 10503
 
3 liveuser 10504
					}#else end
226 liveuser 10505
 
3 liveuser 10506
				}#else end
226 liveuser 10507
 
3 liveuser 10508
			}#foreach end
226 liveuser 10509
 
3 liveuser 10510
		#設置執行正常
10511
		$result["status"]="true";
226 liveuser 10512
 
3 liveuser 10513
		#回傳結果
10514
		return $result;
226 liveuser 10515
 
3 liveuser 10516
		}#function getRelativeParh end
10517
 
10518
	/*
10519
	#函式說明:
10520
	#移除多個絕對路徑字串開頭相同的部分
10521
	#回傳結果:
10522
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10523
	#$result["error"],錯誤訊息陣列.
10524
	#$result["function"],當前執行的函數名稱.
10525
	#$result["argu"],參數.
10526
	#$result["content"],處理好的的字串內容.
10527
	#必填參數:
10528
	#$conf["pathIn"],字串陣列,每個要處理的絕對路徑字串.
226 liveuser 10529
	$conf["pathIn"]=array();
3 liveuser 10530
	#可省略參數:
10531
	#無
10532
	#參考資料:
10533
	#無.
10534
	#備註:
10535
	#無.
10536
	*/
10537
	public static function delSamePathHead(&$conf){
226 liveuser 10538
 
3 liveuser 10539
		#初始化要回傳的結果
10540
		$result=array();
10541
 
10542
		#取得當前執行的函數名稱
10543
		$result["function"]=__FUNCTION__;
10544
 
10545
		#如果沒有參數
10546
		if(func_num_args()==0){
226 liveuser 10547
 
3 liveuser 10548
			#設置執行失敗
10549
			$result["status"]="false";
226 liveuser 10550
 
3 liveuser 10551
			#設置執行錯誤訊息
10552
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 10553
 
3 liveuser 10554
			#回傳結果
10555
			return $result;
226 liveuser 10556
 
3 liveuser 10557
			}#if end
10558
 
10559
		#如果 $conf 不為陣列
10560
		if(gettype($conf)!="array"){
226 liveuser 10561
 
3 liveuser 10562
			#設置執行失敗
10563
			$result["status"]="false";
226 liveuser 10564
 
3 liveuser 10565
			#設置執行錯誤訊息
10566
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 10567
 
3 liveuser 10568
			#如果傳入的參數為 null
10569
			if($conf==null){
226 liveuser 10570
 
3 liveuser 10571
				#設置執行錯誤訊息
10572
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 10573
 
3 liveuser 10574
				}#if end
10575
 
10576
			#回傳結果
10577
			return $result;
226 liveuser 10578
 
3 liveuser 10579
			}#if end
226 liveuser 10580
 
3 liveuser 10581
		#取得參數
226 liveuser 10582
		$result["argv"]=$conf;
10583
 
3 liveuser 10584
		#檢查參數
10585
		#函式說明:
10586
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
10587
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10588
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10589
		#$result["function"],當前執行的函式名稱.
10590
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10591
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10592
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10593
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
10594
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10595
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10596
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10597
		#必填寫的參數:
10598
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10599
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10600
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10601
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("pathIn");
226 liveuser 10602
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 10603
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
10604
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10605
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10606
		#可以省略的參數:
10607
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
10608
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
10609
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10610
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileToRead","output");
226 liveuser 10611
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 10612
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
10613
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10614
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("help","help");
10615
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10616
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
10617
		#參考資料來源:
10618
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10619
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10620
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 10621
 
3 liveuser 10622
		#如果 $checkResult["status"] 等於 "fasle"
10623
		if($checkResult["status"]=="false"){
226 liveuser 10624
 
3 liveuser 10625
			#設置錯誤識別
10626
			$result["status"]="false";
226 liveuser 10627
 
3 liveuser 10628
			#設置錯誤訊息
10629
			$result["error"]=$checkResult;
226 liveuser 10630
 
3 liveuser 10631
			#回傳結果
10632
			return $result;
226 liveuser 10633
 
3 liveuser 10634
			}#if end
226 liveuser 10635
 
3 liveuser 10636
		#如果 $checkResult["passed"] 等於 "fasle"
10637
		if($checkResult["passed"]=="false"){
226 liveuser 10638
 
3 liveuser 10639
			#設置錯誤識別
10640
			$result["status"]="false";
226 liveuser 10641
 
3 liveuser 10642
			#設置錯誤訊息
10643
			$result["error"]=$checkResult;
226 liveuser 10644
 
3 liveuser 10645
			#回傳結果
10646
			return $result;
226 liveuser 10647
 
3 liveuser 10648
			}#if end
226 liveuser 10649
 
3 liveuser 10650
		#檢查是否都為絕對路徑
10651
		#函式說明:
10652
		#取得多個符合特定字首與字尾的字串.
10653
		#回傳結果:
10654
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10655
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10656
		#$result["function"],當前執行的函數名稱.
10657
		#$result["returnString"],爲符合字首條件的字串陣列內容。
10658
		#必填參數:
10659
		#$conf["checkString"],陣列字串,要檢查的字串們.
10660
		$conf["search::getMeetConditionsStringMulti"]["checkString"]=$conf["pathIn"];#要檢查的字串陣列
10661
		#可省略參數:
10662
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10663
		$conf["search::getMeetConditionsStringMulti"]["frontWord"]="/";
10664
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10665
		#$conf["tailWord"]="";
10666
		#參考資料:
10667
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10668
		$getMeetConditionsStringMulti=search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]);
10669
		unset($conf["search::getMeetConditionsStringMulti"]);
226 liveuser 10670
 
3 liveuser 10671
		#如果檢測是否為絕對路徑失敗
10672
		if($getMeetConditionsStringMulti["status"]=="false"){
226 liveuser 10673
 
3 liveuser 10674
			#設置錯誤識別
10675
			$result["status"]="false";
226 liveuser 10676
 
3 liveuser 10677
			#設置錯誤訊息
10678
			$result["error"]=$getMeetConditionsStringMulti;
226 liveuser 10679
 
3 liveuser 10680
			#增加額外的錯誤訊息
10681
			$result["error"][]="僅接受絕對路徑字串";
226 liveuser 10682
 
3 liveuser 10683
			#回傳結果
10684
			return $result;
226 liveuser 10685
 
3 liveuser 10686
			}#if end
226 liveuser 10687
 
3 liveuser 10688
		#函式說明:
10689
		#將多個固定格式的字串分開,並回傳分開的結果
10690
		#回傳的參數:
10691
		#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
10692
		#$result["error"],錯誤訊息陣列.
10693
		#$result["function"],當前執行的函數名稱.
10694
		#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
10695
		#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
10696
		#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
10697
		#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
10698
		#必填參數:
10699
		#$conf["stringIn"],字串陣列,要處理的字串陣列.
10700
		$conf["stringProcess::spiltMutiString"]["stringIn"]=$conf["pathIn"];
10701
		#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
10702
		$conf["stringProcess::spiltMutiString"]["spiltSymbol"]="/";
10703
		$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
226 liveuser 10704
 
3 liveuser 10705
		#如果分割所有路徑字串失敗
10706
		if($spiltMutiString["status"]=="false"){
226 liveuser 10707
 
3 liveuser 10708
			#設置錯誤識別
10709
			$result["status"]="false";
226 liveuser 10710
 
3 liveuser 10711
			#設置錯誤訊息
226 liveuser 10712
			$result["error"]=$spiltMutiString;
10713
 
3 liveuser 10714
			#回傳結果
10715
			return $result;
226 liveuser 10716
 
3 liveuser 10717
			}#if end
226 liveuser 10718
 
3 liveuser 10719
		#初始化暫存每個路徑分割成的段數
226 liveuser 10720
		$spiltedPathCount=array();
10721
 
3 liveuser 10722
		#取得每個路徑分割成的段數
10723
		#針對每個 $spiltMutiString["spiltString"]
10724
		for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
226 liveuser 10725
 
3 liveuser 10726
			$spiltedPathCount[]=$spiltMutiString["spiltString"][$i]["dataCounts"];
226 liveuser 10727
 
3 liveuser 10728
			}#for end
226 liveuser 10729
 
3 liveuser 10730
		#取得所有路徑字串分割後的最小數量
10731
		#涵式說明
10732
		#找最小值,結果會回傳最小值
10733
		#回傳的內容
10734
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
10735
		#$result["error"],錯誤訊息陣列.
10736
		#$result["function"],當前執行的函數名稱.
10737
		#$result["key"],最大值原先的key.
10738
		#$result["value"],陣列裏面最小的數值.
10739
		#必填參數:
10740
		$conf["math::getMinValue"]["rawDataArray"]=$spiltedPathCount;#爲原始數據
10741
		$getMinValue=math::getMinValue($conf["math::getMinValue"]);
10742
		unset($conf["math::getMinValue"]);
226 liveuser 10743
 
3 liveuser 10744
		#如果取得最小數值失敗
10745
		if($getMinValue["status"]=="false"){
226 liveuser 10746
 
3 liveuser 10747
			#設置錯誤識別
10748
			$result["status"]="false";
226 liveuser 10749
 
3 liveuser 10750
			#設置錯誤訊息
226 liveuser 10751
			$result["error"]=$getMinValue;
10752
 
3 liveuser 10753
			#回傳結果
10754
			return $result;
226 liveuser 10755
 
10756
			}#if end
10757
 
3 liveuser 10758
		#初始化暫存每個路徑字串的前面幾個片段是相同的
10759
		$samePartCount=0;
226 liveuser 10760
 
10761
		#var_dump($getMinValue["value"]);
10762
 
3 liveuser 10763
		#依據所有路徑字串分割後的最小數量
10764
		for($j=0;$j<$getMinValue["value"];$j++){
226 liveuser 10765
 
3 liveuser 10766
			#初始化暫存第一個路徑的片段字串
10767
			$firstPathPart="";
226 liveuser 10768
 
3 liveuser 10769
			#針對每個 $spiltMutiString["spiltString"]
10770
			for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
226 liveuser 10771
 
3 liveuser 10772
				#暫存分割的字串
10773
				$spiltedPath=$spiltMutiString["spiltString"][$i];
226 liveuser 10774
 
3 liveuser 10775
				#如果是第一個路徑
10776
				if($i==0){
226 liveuser 10777
 
3 liveuser 10778
					#取得第一個路徑的片段字串
10779
					$firstPathPart=$spiltedPath["dataArray"][$j];
226 liveuser 10780
 
10781
					}#if end
10782
 
3 liveuser 10783
				#如果第$i+1個路徑片段不跟第1個路徑的片段字串一樣
10784
				if($spiltedPath["dataArray"][$j]!=$firstPathPart){
226 liveuser 10785
 
3 liveuser 10786
					#讓最外層迴圈中止
10787
					$getMinValue["value"]=-1;
226 liveuser 10788
 
3 liveuser 10789
					#跳出迴圈
10790
					break;
226 liveuser 10791
 
10792
					}#if end
10793
 
3 liveuser 10794
				}#for end
226 liveuser 10795
 
3 liveuser 10796
			#代表每個路徑字串的第$j段是一樣的.
10797
			$samePartCount=$j;
226 liveuser 10798
 
3 liveuser 10799
			}#for end
226 liveuser 10800
 
3 liveuser 10801
		#var_dump($samePartCount);
226 liveuser 10802
 
3 liveuser 10803
		#依據每個路徑
226 liveuser 10804
		for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
10805
 
3 liveuser 10806
			#初始化儲存第$i+1個處理好的路徑字串
226 liveuser 10807
			$result["content"][$i]="";
10808
 
3 liveuser 10809
			#依據 $samePartCount 與 路徑的段數
10810
			for($j=$samePartCount;$j<$spiltMutiString["spiltString"][$i]["dataCounts"];$j++){
226 liveuser 10811
 
3 liveuser 10812
				#如果不是第一段
10813
				if($j!=$samePartCount){
226 liveuser 10814
 
3 liveuser 10815
					#組裝每個路徑片段
10816
					$result["content"][$i]=$result["content"][$i]."/".$spiltMutiString["spiltString"][$i]["dataArray"][$j];
226 liveuser 10817
 
3 liveuser 10818
					}#if end
226 liveuser 10819
 
3 liveuser 10820
				#反之為第一段
10821
				else{
226 liveuser 10822
 
3 liveuser 10823
					#組裝每個路徑片段
10824
					$result["content"][$i]=$result["content"][$i].$spiltMutiString["spiltString"][$i]["dataArray"][$j];
226 liveuser 10825
 
3 liveuser 10826
					}#else end
226 liveuser 10827
 
3 liveuser 10828
				}#for end
226 liveuser 10829
 
3 liveuser 10830
			}#for end
226 liveuser 10831
 
3 liveuser 10832
		#設置執行正常
10833
		$result["status"]="true";
226 liveuser 10834
 
3 liveuser 10835
		#回傳結果
10836
		return $result;
226 liveuser 10837
 
3 liveuser 10838
		}#function delSamePathHead end
10839
 
10840
	/*
10841
	#函式說明:
226 liveuser 10842
	#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
3 liveuser 10843
	#回傳結果:
10844
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10845
	#$result["error"],錯誤訊息.
10846
	#$result["function"],當前執行的函數名稱.
10847
	#$result["content"],暫存檔案的路徑與名稱.
10848
	#$result["fileName"],暫存檔案的名稱.
10849
	#$result["path"],暫存檔案的路徑.
10850
	#必填參數:
10851
	#無.
10852
	#可省略參數:
36 liveuser 10853
	#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
10854
	#$conf["contant"]=array();
3 liveuser 10855
	#參考資料:
10856
	#無.
10857
	#備註:
10858
	#無.
10859
	*/
36 liveuser 10860
	public static function createTempFile(&$conf){
226 liveuser 10861
 
3 liveuser 10862
		#初始化要回傳的結果
10863
		$result=array();
10864
 
10865
		#取得當前執行的函數名稱
10866
		$result["function"]=__FUNCTION__;
226 liveuser 10867
 
36 liveuser 10868
		#取得參數
10869
		$result["argu"]=$conf;
10870
 
10871
		#如果 $conf 不為陣列
10872
		if(gettype($conf)!="array"){
10873
 
10874
			#設置執行失敗
10875
			$result["status"]="false";
10876
 
10877
			#設置執行錯誤訊息
10878
			$result["error"][]="\$conf變數須為陣列形態";
10879
 
10880
			#如果傳入的參數為 null
10881
			if(is_null($conf)){
10882
 
10883
				#設置執行錯誤訊息
10884
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
10885
 
10886
				}#if end
10887
 
10888
			#回傳結果
10889
			return $result;
10890
 
10891
			}#if end
226 liveuser 10892
 
36 liveuser 10893
		#檢查參數
10894
		#函式說明:
10895
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
10896
		#回傳結果:
10897
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10898
		#$result["error"],執行不正常結束的錯訊息陣列.
10899
		#$result["simpleError"],簡單表示的錯誤訊息.
10900
		#$result["function"],當前執行的函式名稱.
10901
		#$result["argu"],設置給予的參數.
10902
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10903
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10904
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10905
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
10906
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
10907
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10908
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10909
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10910
		#必填參數:
10911
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10912
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10913
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10914
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10915
		#可省略參數:
10916
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10917
		#$conf["mustBeFilledVariableName"]=array();
10918
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
10919
		#$conf["mustBeFilledVariableType"]=array();
10920
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
10921
		#$conf["canBeEmptyString"]="false";
10922
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
10923
		#$conf["canNotBeEmpty"]=array();
10924
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
10925
		#$conf["canBeEmpty"]=array();
10926
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
10927
		#$conf["skipableVariableCanNotBeEmpty"]=array();
10928
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10929
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("content");
10930
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
10931
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
10932
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10933
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array());
10934
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
10935
		#$conf["disallowAllSkipableVarIsEmpty"]="";
10936
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
10937
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
10938
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
10939
		#$conf["disallowAllSkipableVarNotExist"]="";
10940
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10941
		#$conf["arrayCountEqualCheck"][]=array();
10942
		#參考資料:
10943
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10944
		#備註:
10945
		#無.
10946
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10947
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 10948
 
36 liveuser 10949
		#如果執行失敗
10950
		if($checkArguments["status"]==="false"){
226 liveuser 10951
 
36 liveuser 10952
			#設置執行異常
10953
			$result["status"]="false";
226 liveuser 10954
 
36 liveuser 10955
			#設置錯誤訊息
10956
			$result["error"]=$checkArguments;
226 liveuser 10957
 
36 liveuser 10958
			#回傳結果
10959
			return $result;
226 liveuser 10960
 
36 liveuser 10961
			}#if end
226 liveuser 10962
 
36 liveuser 10963
		#如果檢查不通過
10964
		if($checkArguments["passed"]==="false"){
226 liveuser 10965
 
36 liveuser 10966
			#設置執行異常
10967
			$result["status"]="false";
226 liveuser 10968
 
36 liveuser 10969
			#設置錯誤訊息
10970
			$result["error"]=$checkArguments;
226 liveuser 10971
 
36 liveuser 10972
			#回傳結果
10973
			return $result;
226 liveuser 10974
 
36 liveuser 10975
			}#if end
226 liveuser 10976
 
3 liveuser 10977
		#取得相對於當前路徑的  tmp 目錄.
10978
		exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/tmp;pwd;",$output,$status);
226 liveuser 10979
 
3 liveuser 10980
		#如果執行失敗
10981
		if($status!==0){
226 liveuser 10982
 
3 liveuser 10983
			#設置執行失敗
10984
			$result["status"]="false";
10985
 
10986
			#設置執行錯誤訊息
10987
			$result["error"][]="取得暫存目錄失敗";
226 liveuser 10988
 
3 liveuser 10989
			#回傳結果
10990
			return $result;
226 liveuser 10991
 
10992
			}#if end
10993
 
3 liveuser 10994
		#設置預設的暫存目錄
226 liveuser 10995
		$defaultTmpDir=$output[0];
10996
 
3 liveuser 10997
		#取得暫存檔案的路徑與名稱
10998
		$result["content"]=tempnam($defaultTmpDir,"qbpwcf_tmpfile_");
226 liveuser 10999
 
42 liveuser 11000
		#如果產生的暫存檔案位置異常
11001
		#參考資料:
11002
		#https://www.php.net/manual/en/function.tempnam.php
11003
		if(strpos("/tmp/",$result["content"])===0){
226 liveuser 11004
 
42 liveuser 11005
			#設置執行失敗
11006
			$result["status"]="false";
11007
 
11008
			#設置執行錯誤訊息
11009
			$result["error"][]="於暫存目錄建立檔案失敗";
226 liveuser 11010
 
42 liveuser 11011
			#回傳結果
11012
			return $result;
226 liveuser 11013
 
42 liveuser 11014
			}#if end
226 liveuser 11015
 
3 liveuser 11016
		#函式說明:
11017
		#將字串特定關鍵字與其前面的內容剔除
11018
		#回傳結果:
11019
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11020
		#$result["error"],錯誤訊息陣列.
11021
		#$result["warning"],警告訊息鎮列.
11022
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
11023
		#$result["function"],當前執行的函數名稱.
11024
		#$result["argu"],使用的參數.
11025
		#$result["oriStr"],要處理的原始字串內容.
226 liveuser 11026
		#$result["content"],處理好的的字串內容.
3 liveuser 11027
		#必填參數:
11028
		#$conf["stringIn"],字串,要處理的字串.
11029
		$conf["stringPorcess::delStrBeforeKeyWord"]["stringIn"]=$result["content"];
11030
		#$conf["keyWord"],字串,特定字串.
42 liveuser 11031
		$conf["stringPorcess::delStrBeforeKeyWord"]["keyWord"]=$defaultTmpDir."/";
3 liveuser 11032
		#可省略參數:
11033
		#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
42 liveuser 11034
		$conf["stringPorcess::delStrBeforeKeyWord"]["recursive"]="true";
3 liveuser 11035
		#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
11036
		#$conf["lastResult"]=$delStrBeforeKeyWord;
11037
		#參考資料:
11038
		#無.
11039
		#備註:
11040
		#無.
11041
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringPorcess::delStrBeforeKeyWord"]);
11042
		unset($conf["stringPorcess::delStrBeforeKeyWord"]);
226 liveuser 11043
 
3 liveuser 11044
		#如果執行失敗
11045
		if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 11046
 
3 liveuser 11047
			#設置執行失敗
11048
			$result["status"]="false";
11049
 
11050
			#設置執行錯誤訊息
11051
			$result["error"]=$delStrBeforeKeyWord;
226 liveuser 11052
 
3 liveuser 11053
			#回傳結果
11054
			return $result;
226 liveuser 11055
 
3 liveuser 11056
			}#if end
226 liveuser 11057
 
3 liveuser 11058
		#如果應該要存在的路徑關鍵字不在
11059
		if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 11060
 
3 liveuser 11061
			#設置執行失敗
11062
			$result["status"]="false";
11063
 
11064
			#設置執行錯誤訊息
11065
			$result["error"]=$delStrBeforeKeyWord;
226 liveuser 11066
 
3 liveuser 11067
			#回傳結果
11068
			return $result;
226 liveuser 11069
 
3 liveuser 11070
			}#if end
226 liveuser 11071
 
3 liveuser 11072
		#取得檔案名稱
11073
		$result["fileName"]=$delStrBeforeKeyWord["content"];
226 liveuser 11074
 
3 liveuser 11075
		#函式說明:
11076
		#將字串特定關鍵字與其後面的內容剔除
11077
		#回傳結果:
11078
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11079
		#$result["error"],錯誤訊息陣列.
11080
		#$result["warning"],警告訊息鎮列.
11081
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
11082
		#$result["function"],當前執行的函數名稱.
11083
		#$result["oriStr"],要處理的原始字串內容.
11084
		#$result["content"],處理好的的字串內容.
11085
		#$result["argu"],使用的參數.
11086
		#必填參數:
11087
		#$conf["stringIn"],字串,要處理的字串.
11088
		$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$result["content"];
11089
		#$conf["keyWord"],字串,特定字串.
11090
		$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["fileName"];
11091
		#可省略參數:
11092
		#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
11093
		#$conf["deleteLastRepeatedOne"]="";
11094
		#參考資料:
11095
		#無.
11096
		#備註:
11097
		#無.
11098
		$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
11099
		unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 11100
 
3 liveuser 11101
		#如果執行失敗
11102
		if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 11103
 
3 liveuser 11104
			#設置執行失敗
11105
			$result["status"]="false";
11106
 
11107
			#設置執行錯誤訊息
11108
			$result["error"]=$delStrAfterKeyWord;
226 liveuser 11109
 
3 liveuser 11110
			#回傳結果
11111
			return $result;
226 liveuser 11112
 
3 liveuser 11113
			}#if end
226 liveuser 11114
 
3 liveuser 11115
		#如果應該要存在的檔案名稱關鍵字不在
11116
		if($delStrAfterKeyWord["founded"]==="false"){
226 liveuser 11117
 
3 liveuser 11118
			#設置執行失敗
11119
			$result["status"]="false";
11120
 
11121
			#設置執行錯誤訊息
11122
			$result["error"]=$delStrAfterKeyWord;
226 liveuser 11123
 
3 liveuser 11124
			#回傳結果
11125
			return $result;
226 liveuser 11126
 
3 liveuser 11127
			}#if end
226 liveuser 11128
 
3 liveuser 11129
		#取得路徑
11130
		$result["path"]=$delStrAfterKeyWord["content"];
226 liveuser 11131
 
36 liveuser 11132
		#如果有內容要寫入
11133
		if(!empty($conf["content"])){
226 liveuser 11134
 
36 liveuser 11135
			#函式說明:
11136
			#將多行字串寫入到檔案
11137
			#回傳結果:
11138
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
11139
			#$result["error"],錯誤訊息陣列.
11140
			#$result["function"],當前執行函數的名稱.
11141
			#必填參數:
11142
			#$conf["fileName"],字串,爲要編輯的檔案名稱
11143
			$conf["fileAccess::writeMultiLine"]["fileName"]=$result["content"];
11144
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
11145
			$conf["fileAccess::writeMultiLine"]["inputString"]=$conf["content"];
11146
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11147
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=__FILE__;
11148
			#可省略參數:
11149
			#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
11150
			#參考資料:
11151
			#無.
11152
			#備註:
11153
			#無.
11154
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
11155
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 11156
 
36 liveuser 11157
			#如果執行失敗
11158
			if($writeMultiLine["status"]==="false"){
226 liveuser 11159
 
36 liveuser 11160
				#設置執行失敗
11161
				$result["status"]="false";
11162
 
11163
				#設置執行錯誤訊息
11164
				$result["error"]=$writeMultiLine;
226 liveuser 11165
 
36 liveuser 11166
				#回傳結果
11167
				return $result;
226 liveuser 11168
 
36 liveuser 11169
				}#if end
226 liveuser 11170
 
36 liveuser 11171
			}#if end
226 liveuser 11172
 
3 liveuser 11173
		#設置執行正常
11174
		$result["status"]="true";
226 liveuser 11175
 
3 liveuser 11176
		#回傳結果
11177
		return $result;
226 liveuser 11178
 
3 liveuser 11179
		}#function createTempFile end
11180
 
11181
	/*
11182
	#函式說明:
253 liveuser 11183
	#複製檔案、資料夾,只要符合權限就會執行並覆蓋既有內容.
11184
	#回傳結果:
11185
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11186
	#$result["error"],錯誤訊息.
11187
	#$result["function"],當前執行的函式名稱.
11188
	#$result["content"],複製好的檔案路徑與名稱.
11189
	#必填參數:
11190
	#$conf["file"],字串,檔案的位置與名稱.
11191
	$conf["file"]="";
11192
	#$conf["to"],字串,檔案要複製到哪裡.
11193
	$conf["to"]="";
11194
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
11195
	$conf["fileArgu"]=__FILE__;
11196
	#可省略參數:
11197
	#無.
11198
	#參考資料:
11199
	#無.
11200
	#備註:
11201
	#等同於cmd::cp的應用.
11202
	*/
11203
	public static function cp(&$conf){
11204
 
11205
		#初始化要回傳的結果
11206
		$result=array();
11207
 
11208
		#取得當前執行的函式名稱
11209
		$result["function"]=__FUNCTION__;
11210
 
11211
		#如果沒有參數
11212
		if(func_num_args()==0){
11213
 
11214
			#設置執行失敗
11215
			$result["status"]="false";
11216
 
11217
			#設置執行錯誤訊息
11218
			$result["error"]="函式".$result["function"]."需要參數";
11219
 
11220
			#回傳結果
11221
			return $result;
11222
 
11223
			}#if end
11224
 
11225
		#取得參數
11226
		$result["argu"]=$conf;
11227
 
11228
		#如果 $conf 不為陣列
11229
		if(gettype($conf)!=="array"){
11230
 
11231
			#設置執行失敗
11232
			$result["status"]="false";
11233
 
11234
			#設置執行錯誤訊息
11235
			$result["error"][]="\$conf變數須為陣列形態";
11236
 
11237
			#如果傳入的參數為 null
11238
			if($conf===null){
11239
 
11240
				#設置執行錯誤訊息
11241
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
11242
 
11243
				}#if end
11244
 
11245
			#回傳結果
11246
			return $result;
11247
 
11248
			}#if end
11249
 
11250
		#檢查參數
11251
		#函式說明:
11252
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
11253
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11254
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11255
		#$result["function"],當前執行的函式名稱.
11256
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11257
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11258
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11259
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11260
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11261
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11262
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11263
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11264
		#必填寫的參數:
11265
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11266
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11267
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11268
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","to","fileArgu");
11269
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11270
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
11271
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11272
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11273
		#可以省略的參數:
11274
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11275
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11276
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11277
		#$conf["canNotBeEmpty"]=array();
11278
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11279
		#$conf["canBeEmpty"]=array();
11280
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11281
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11282
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11283
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","cmdOnly");
11284
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
11285
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
11286
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11287
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null,"true");
11288
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11289
		#$conf["arrayCountEqualCheck"][]=array();
11290
		#參考資料來源:
11291
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11292
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11293
		unset($conf["variableCheck::checkArguments"]);
11294
 
11295
		#如果參數檢查失敗
11296
		if($checkArguments["status"]==="false"){
11297
 
11298
			#設置執行不正常
11299
			$result["status"]="false";
11300
 
11301
			#設置執行錯誤
11302
			$result["error"]=$checkArguments;
11303
 
11304
			#回傳結果
11305
			return $result;
11306
 
11307
			}#if end
11308
 
11309
		#如果參數檢查不通過
11310
		if($checkArguments["passed"]==="false"){
11311
 
11312
			#設置執行不正常
11313
			$result["status"]="false";
11314
 
11315
			#設置執行錯誤
11316
			$result["error"]=$checkArguments;
11317
 
11318
			#回傳結果
11319
			return $result;
11320
 
11321
			}#if end
11322
 
11323
		#函式說明:
11324
		#複製檔案、資料夾,只要符合權限就會執行並覆蓋既有內容.
11325
		#回傳結果:
11326
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11327
		#$result["error"],錯誤訊息.
11328
		#$result["function"],當前執行的函式名稱.
11329
		#$result["content"],複製好的檔案路徑與名稱.
11330
		#必填參數:
11331
		#$conf["file"],字串,檔案的位置與名稱.
11332
		$conf["cmd::cp"]["file"]=$conf["file"];
11333
		#$conf["to"],字串,檔案要複製到哪裡.
11334
		$conf["cmd::cp"]["to"]=$conf["to"];
11335
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
11336
		$conf["cmd::cp"]["fileArgu"]=$conf["fileArgu"];
11337
		#可省略參數:
11338
		#$conf["cmdOnly"],字串,是否要只允許在cmd環境下運行,預設為"true",代表是;"false"代表沒有限制.
11339
		$conf["cmd::cp"]["cmdOnly"]="false";
11340
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
11341
		#$conf["username"]="";
11342
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
11343
		#$conf["password"]="";
11344
		#參考資料:
11345
		#無.
11346
		#備註:
11347
		#無.
11348
		$cp=cmd::cp($conf["cmd::cp"]);
11349
		unset($conf["cmd::cp"]);
11350
 
11351
		#如果執行異常
11352
		if($cp["status"]==="false"){
11353
 
11354
			#設置執行不正常
11355
			$result["status"]="false";
11356
 
11357
			#設置執行錯誤
11358
			$result["error"]=$cp;
11359
 
11360
			#回傳結果
11361
			return $result;
11362
 
11363
			}#if end
11364
 
11365
		#設置要回傳的 content
11366
		$result["content"]=$cp["content"];
11367
 
11368
		#設置執行正常
11369
		$result["status"]="true";
11370
 
11371
		#回傳結果
11372
		return $result;
11373
 
11374
		}#function cp end
11375
 
11376
	/*
11377
	#函式說明:
3 liveuser 11378
	#分割檔案,分割出來的檔案名稱編號為aa, ab ac...ba, bb, bc...,zx, zy, zz的順序.
11379
	#回傳結果:
11380
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11381
	#$result["error"],錯誤訊息陣列.
11382
	#$result["function"],當前執行的函數名稱.
11383
	#$result["cmd"],執行的指令.
11384
	#$result["content"],執行指令回傳的結果.
11385
	#必填參數:
11386
	#$conf["file"],字串,要分割的檔案名稱.
226 liveuser 11387
	$conf["file"]="";
3 liveuser 11388
	#可省略參數:
11389
	#$conf["splitNameHead"],字串,分割成檔案的名稱開頭,預設為 $conf["file"]."-" .
226 liveuser 11390
	#$conf["splitNameHead"]="";
3 liveuser 11391
	#$conf["partSize"],字串,分割檔的大小為多少?可以為XMB,XGB,XKB,可參見split指令的說明,預設為50MB.
11392
	#$conf["partSize"]="";
11393
	#參考資料:
11394
	#無.
11395
	#備註:
11396
	#需要有split指令
11397
	*/
11398
	public static function split(&$conf=array()){
226 liveuser 11399
 
3 liveuser 11400
		#初始化要回傳的結果
11401
		$result=array();
11402
 
11403
		#取得當前執行的函數名稱
11404
		$result["function"]=__FUNCTION__;
11405
 
11406
		#如果沒有參數
11407
		if(func_num_args()==0){
226 liveuser 11408
 
3 liveuser 11409
			#設置執行失敗
11410
			$result["status"]="false";
226 liveuser 11411
 
3 liveuser 11412
			#設置執行錯誤訊息
11413
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 11414
 
3 liveuser 11415
			#回傳結果
11416
			return $result;
226 liveuser 11417
 
3 liveuser 11418
			}#if end
11419
 
11420
		#函式說明:
11421
		#判斷當前環境為web還是cmd
11422
		#回傳結果:
11423
		#$result,"web"或"cmd"
11424
		if(csInformation::getEnv()==="web"){
226 liveuser 11425
 
3 liveuser 11426
			#設置執行失敗
11427
			$result["status"]="false";
226 liveuser 11428
 
3 liveuser 11429
			#設置執行錯誤訊息
11430
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
226 liveuser 11431
 
3 liveuser 11432
			#回傳結果
11433
			return $result;
226 liveuser 11434
 
3 liveuser 11435
			}#if end
226 liveuser 11436
 
3 liveuser 11437
		#取得參數
11438
		$result["argu"]=$conf;
11439
 
11440
		#如果 $conf 不為陣列
11441
		if(gettype($conf)!=="array"){
226 liveuser 11442
 
3 liveuser 11443
			#設置執行失敗
11444
			$result["status"]="false";
226 liveuser 11445
 
3 liveuser 11446
			#設置執行錯誤訊息
11447
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 11448
 
3 liveuser 11449
			#如果傳入的參數為 null
11450
			if($conf===null){
226 liveuser 11451
 
3 liveuser 11452
				#設置執行錯誤訊息
11453
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 11454
 
3 liveuser 11455
				}#if end
11456
 
11457
			#回傳結果
11458
			return $result;
226 liveuser 11459
 
3 liveuser 11460
			}#if end
226 liveuser 11461
 
3 liveuser 11462
		#檢查參數
11463
		#函式說明:
11464
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
11465
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11466
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11467
		#$result["function"],當前執行的函式名稱.
11468
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11469
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11470
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11471
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11472
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11473
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11474
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11475
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11476
		#必填寫的參數:
11477
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11478
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11479
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11480
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file");
11481
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11482
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
11483
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11484
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11485
		#可以省略的參數:
11486
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11487
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11488
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11489
		#$conf["canNotBeEmpty"]=array();
11490
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11491
		#$conf["canBeEmpty"]=array();
11492
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11493
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11494
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11495
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("splitNameHead","partSize");
226 liveuser 11496
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 11497
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
11498
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]",若後面需要加上內容,則可以再補上\",後面再補上要串接的內容.
11499
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"file\"]\"-","50MB");
11500
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11501
		#$conf["arrayCountEqualCheck"][]=array();
11502
		#參考資料來源:
11503
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11504
		#建議:
11505
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
11506
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11507
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 11508
 
3 liveuser 11509
		#如果檢查參數失敗
11510
		if($checkArguments["status"]==="false"){
226 liveuser 11511
 
3 liveuser 11512
			#設置執行失敗
11513
			$result["status"]="false";
226 liveuser 11514
 
3 liveuser 11515
			#設置錯誤訊息
11516
			$result["error"]=$checkArguments;
226 liveuser 11517
 
3 liveuser 11518
			#回傳結果
11519
			return $result;
226 liveuser 11520
 
3 liveuser 11521
			}#if end
226 liveuser 11522
 
3 liveuser 11523
		#如果要分割的檔案存在
11524
		if(file_exists($conf["file"])){
226 liveuser 11525
 
3 liveuser 11526
			#取得執行的指令
11527
			$result["cmd"]="split -b ".$conf["partSize"]." '".$conf["file"]."' '".$conf["splitNameHead"]."'";
11528
 
11529
			#執行還原的指令
11530
			exec($result["cmd"],$output,$status);
11531
 
11532
			#取得執行後的輸出
11533
			$result["content"]=$output;
226 liveuser 11534
 
3 liveuser 11535
			}#if end
226 liveuser 11536
 
3 liveuser 11537
		#反之
11538
		else{
226 liveuser 11539
 
3 liveuser 11540
			#設置執行失敗
11541
			$result["status"]="false";
226 liveuser 11542
 
3 liveuser 11543
			#設置執行錯誤訊息
11544
			$result["error"][]="要分割的檔案「".$conf["file"]."」不存在";
226 liveuser 11545
 
3 liveuser 11546
			#回傳結果
11547
			return $result;
226 liveuser 11548
 
3 liveuser 11549
			}#else end
226 liveuser 11550
 
3 liveuser 11551
		#設置執行正常
11552
		$result["status"]="true";
226 liveuser 11553
 
3 liveuser 11554
		#回傳結果
11555
		return $result;
226 liveuser 11556
 
3 liveuser 11557
		}#function split end
11558
 
11559
	/*
11560
	#函式說明:
11561
	#合併檔案,檔案編號為aa, ab ac...ba, bb, bc...,zx, zy, zz的順序.
11562
	#回傳結果:
11563
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11564
	#$result["error"],錯誤訊息陣列.
11565
	#$result["function"],當前執行的函數名稱.
11566
	#$result["cmd"],執行的指令.
11567
	#$result["content"],執行指令回傳的結果.
11568
	#必填參數:
11569
	#$conf["filePartHead"],字串,分割檔案的名稱開頭.
11570
	$conf["filePartHead"]="";
11571
	#$conf["oriFileName"],字串,合併後的檔案名稱.
11572
	$conf["oriFileName"]="";
11573
	#可省略參數:
11574
	#無
11575
	#參考資料:
11576
	#無.
11577
	#備註:
11578
	#需要有cat指令.
11579
	#僅能在命令列執行.
11580
	*/
11581
	public static function merge(&$conf=array()){
226 liveuser 11582
 
3 liveuser 11583
		#初始化要回傳的結果
11584
		$result=array();
11585
 
11586
		#取得當前執行的函數名稱
11587
		$result["function"]=__FUNCTION__;
11588
 
11589
		#如果沒有參數
11590
		if(func_num_args()==0){
226 liveuser 11591
 
3 liveuser 11592
			#設置執行失敗
11593
			$result["status"]="false";
226 liveuser 11594
 
3 liveuser 11595
			#設置執行錯誤訊息
11596
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 11597
 
3 liveuser 11598
			#回傳結果
11599
			return $result;
226 liveuser 11600
 
3 liveuser 11601
			}#if end
11602
 
11603
		#函式說明:
11604
		#判斷當前環境為web還是cmd
11605
		#回傳結果:
11606
		#$result,"web"或"cmd"
11607
		if(csInformation::getEnv()==="web"){
226 liveuser 11608
 
3 liveuser 11609
			#設置執行失敗
11610
			$result["status"]="false";
226 liveuser 11611
 
3 liveuser 11612
			#設置執行錯誤訊息
11613
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
226 liveuser 11614
 
3 liveuser 11615
			#回傳結果
11616
			return $result;
226 liveuser 11617
 
3 liveuser 11618
			}#if end
226 liveuser 11619
 
3 liveuser 11620
		#取得參數
11621
		$result["argu"]=$conf;
11622
 
11623
		#如果 $conf 不為陣列
11624
		if(gettype($conf)!=="array"){
226 liveuser 11625
 
3 liveuser 11626
			#設置執行失敗
11627
			$result["status"]="false";
226 liveuser 11628
 
3 liveuser 11629
			#設置執行錯誤訊息
11630
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 11631
 
3 liveuser 11632
			#如果傳入的參數為 null
11633
			if($conf===null){
226 liveuser 11634
 
3 liveuser 11635
				#設置執行錯誤訊息
11636
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 11637
 
3 liveuser 11638
				}#if end
11639
 
11640
			#回傳結果
11641
			return $result;
226 liveuser 11642
 
3 liveuser 11643
			}#if end
226 liveuser 11644
 
3 liveuser 11645
		#檢查參數
11646
		#函式說明:
11647
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
11648
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11649
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11650
		#$result["function"],當前執行的函式名稱.
11651
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11652
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11653
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11654
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11655
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11656
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11657
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11658
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11659
		#必填寫的參數:
11660
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11661
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11662
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11663
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePartHead","oriFileName");
11664
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11665
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
11666
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11667
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11668
		#可以省略的參數:
11669
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11670
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11671
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11672
		#$conf["canNotBeEmpty"]=array();
11673
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11674
		#$conf["canBeEmpty"]=array();
11675
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11676
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11677
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11678
		#$conf["skipableVariableName"]=array();
226 liveuser 11679
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 11680
		#$conf["skipableVariableType"]=array();
11681
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11682
		#$conf["skipableVarDefaultValue"]=array("");
11683
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11684
		#$conf["arrayCountEqualCheck"][]=array();
11685
		#參考資料來源:
11686
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11687
		#建議:
11688
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
11689
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11690
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 11691
 
3 liveuser 11692
		#如果檢查參數失敗
11693
		if($checkArguments["status"]==="false"){
226 liveuser 11694
 
3 liveuser 11695
			#設置執行失敗
11696
			$result["status"]="false";
226 liveuser 11697
 
3 liveuser 11698
			#設置錯誤訊息
11699
			$result["error"]=$checkArguments;
226 liveuser 11700
 
3 liveuser 11701
			#回傳結果
11702
			return $result;
226 liveuser 11703
 
3 liveuser 11704
			}#if end
226 liveuser 11705
 
3 liveuser 11706
		#定義編號
11707
		$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");
11708
 
11709
		#定義分割檔案的前置字串
11710
		$filePartHead=$conf["filePartHead"];
11711
 
11712
		#要合併成的檔案名稱
11713
		$oriFileName=$conf["oriFileName"];
11714
 
11715
		#初始化要執行合併的語法
11716
		$restoreCmd="cat ";
11717
 
11718
		#有幾個編號就執行幾次
11719
		for($i=0;$i<count($charArray);$i++){
11720
 
11721
			#有幾個編號就執行幾次
11722
			for($j=0;$j<count($charArray);$j++){
11723
 
11724
				#如果該分割檔存在
11725
				if(file_exists($filePartHead.$charArray[$i].$charArray[$j])){
11726
 
11727
					#串接要還原的分割檔
11728
					$restoreCmd=$restoreCmd." '".$filePartHead.$charArray[$i].$charArray[$j]."'";
11729
 
11730
					}#if end
11731
 
11732
				#反之
11733
				else{
11734
 
11735
					#如果是第一個分割檔就找不到
11736
					if($i===0 && $j===0){
226 liveuser 11737
 
3 liveuser 11738
						#設置執行失敗
11739
						$result["status"]="false";
226 liveuser 11740
 
3 liveuser 11741
						#設置錯誤訊息
11742
						$result["error"][]="找不到第一個分割檔「".$filePartHead.$charArray[$i].$charArray[$j]."」";
226 liveuser 11743
 
3 liveuser 11744
						#回傳結果
11745
						return $result;
226 liveuser 11746
 
3 liveuser 11747
						}#if end
11748
 
11749
					#串接要還原成的檔案名稱
11750
					$restoreCmd=$restoreCmd." > '".$oriFileName."'";
11751
 
11752
					#取得執行的指令
11753
					$result["cmd"]=$restoreCmd;
11754
 
11755
					#執行還原的指令
11756
					exec($restoreCmd,$output,$status);
11757
 
11758
					#取得執行後的輸出
11759
					$result["content"]=$output;
11760
 
11761
					#結束回圈
11762
					break 2;
226 liveuser 11763
 
3 liveuser 11764
					}#else end
11765
 
11766
				}#for end
11767
 
11768
			}#for end
226 liveuser 11769
 
3 liveuser 11770
		#設置執行正常
11771
		$result["status"]="true";
226 liveuser 11772
 
3 liveuser 11773
		#回傳結果
11774
		return $result;
226 liveuser 11775
 
3 liveuser 11776
		}#function merge end
11777
 
11778
	/*
11779
	#函式說明:
11780
	#取得檔案的部分內容
11781
	#回傳結果:
11782
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11783
	#$result["error"],錯誤訊息陣列.
11784
	#$result["function"],當前執行的函數名稱.
11785
	#$result["cmd"],執行的指令.
11786
	#$result["content"],取得的檔案內容.
11787
	#$result["length"],取得的內容長度.
11788
	#$result["EOF"],識別是否已經到檔案結尾,"true"代表是,"false"代表不是.
11789
	#$result["mimeType"],檔案的 mime type.
11790
	#必填參數:
11791
	#$conf["file"],字串,檔案的路徑與名稱.
11792
	$conf["file"]="";
11793
	#$conf["fileArgu"],字串,__FILE__的內容.
11794
	$conf["fileArgu"]=__FILE__;
11795
	#$conf["bytes"],整數字串,要讀取多少bytes.
11796
	$conf["bytes"]="";
11797
	#$conf["startIndex"],要從哪個bytes位置開始,起始點為0.
11798
	$conf["startIndex"]="";
11799
	#可省略參數:
11800
	#無
11801
	#參考資料:
11802
	#無.
11803
	#備註:
11804
	#無
11805
	*/
11806
	public static function getFilePart(&$conf){
226 liveuser 11807
 
3 liveuser 11808
		#初始化要回傳的結果
11809
		$result=array();
11810
 
11811
		#取得當前執行的函數名稱
11812
		$result["function"]=__FUNCTION__;
11813
 
11814
		#如果沒有參數
11815
		if(func_num_args()==0){
11816
 
11817
			#設置執行失敗
11818
			$result["status"]="false";
11819
 
11820
			#設置執行錯誤訊息
11821
			$result["error"]="函數".$result["function"]."需要參數";
11822
 
11823
			#回傳結果
11824
			return $result;
11825
 
11826
			}#if end
226 liveuser 11827
 
3 liveuser 11828
		#取得參數
11829
		$result["argu"]=$conf;
11830
 
11831
		#如果 $conf 不為陣列
11832
		if(gettype($conf)!=="array"){
11833
 
11834
			#設置執行失敗
11835
			$result["status"]="false";
11836
 
11837
			#設置執行錯誤訊息
11838
			$result["error"][]="\$conf變數須為陣列形態";
11839
 
11840
			#如果傳入的參數為 null
11841
			if(is_null($conf)){
11842
 
11843
				#設置執行錯誤訊息
11844
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
11845
 
11846
				}#if end
11847
 
11848
			#回傳結果
11849
			return $result;
11850
 
11851
			}#if end
226 liveuser 11852
 
3 liveuser 11853
		#函式說明:
11854
		#檢查多個檔案與資料夾是否存在.
11855
		#回傳的結果:
11856
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
11857
		#$result["error"],錯誤訊息陣列.
11858
		#$resutl["function"],當前執行的涵式名稱.
11859
		#$result["argu"],使用的參數.
11860
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
11861
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
11862
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
11863
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
11864
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
11865
		#必填參數:
11866
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
11867
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
11868
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11869
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
11870
		#可省略參數:
11871
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
11872
		#$conf["disableWebSearch"]="false";
11873
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
11874
		#$conf["userDir"]="true";
11875
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
11876
		#$conf["web"]="true";
11877
		#參考資料:
11878
		#http://php.net/manual/en/function.file-exists.php
11879
		#http://php.net/manual/en/control-structures.foreach.php
11880
		#備註:
11881
		#函數file_exists檢查的路徑為檔案系統的路徑
11882
		#$result["varName"][$i]結果未實作
11883
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
11884
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 11885
 
3 liveuser 11886
		#如果執行失敗
11887
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 11888
 
3 liveuser 11889
			#設置執行失敗
11890
			$result["status"]="false";
226 liveuser 11891
 
3 liveuser 11892
			#設置執行錯誤訊息
11893
			$result["error"]=$checkMultiFileExist;
226 liveuser 11894
 
3 liveuser 11895
			#回傳結果
11896
			return $result;
226 liveuser 11897
 
3 liveuser 11898
			}#if end
226 liveuser 11899
 
3 liveuser 11900
		#如果檔案不存在
11901
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 11902
 
3 liveuser 11903
			#設置執行失敗
11904
			$result["status"]="false";
226 liveuser 11905
 
3 liveuser 11906
			#設置執行錯誤訊息
11907
			$result["error"]=$checkMultiFileExist;
226 liveuser 11908
 
3 liveuser 11909
			#回傳結果
11910
			return $result;
226 liveuser 11911
 
3 liveuser 11912
			}#if end
226 liveuser 11913
 
3 liveuser 11914
		#取得mimetype
11915
		$mimetype=mime_content_type($conf["file"]);
226 liveuser 11916
 
3 liveuser 11917
		#取得檔案的 mime type
11918
		$result["mimeType"]=$mimetype;
226 liveuser 11919
 
3 liveuser 11920
		#透過 dd 指令,取得部分內容.
11921
		#函式說明:
11922
		#呼叫shell執行系統命令,並取得回傳的內容.
11923
		#回傳結果:
11924
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11925
		#$result["error"],錯誤訊息陣列.
11926
		#$result["function"],當前執行的函數名稱.
11927
		#$result["argu"],使用的參數.
11928
		#$result["cmd"],執行的指令內容.
11929
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11930
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11931
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11932
		#$result["running"],是否還在執行.
11933
		#$result["pid"],pid.
11934
		#$result["statusCode"],執行結束後的代碼.
11935
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11936
		#必填參數:
11937
		#$conf["command"],字串,要執行的指令.
11938
		$conf["external::callShell"]["command"]="dd";
11939
		#$conf["fileArgu"],字串,變數__FILE__的內容.
11940
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
11941
		#可省略參數:
11942
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11943
		$conf["external::callShell"]["argu"]=array("if=".$conf["file"],"bs=".$conf["bytes"],"count=1","status=none");
11944
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11945
		#$conf["arguIsAddr"]=array();
11946
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11947
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11948
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11949
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11950
		#$conf["enablePrintDescription"]="true";
11951
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11952
		#$conf["printDescription"]="";
11953
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11954
		#$conf["escapeshellarg"]="false";
11955
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11956
		#$conf["thereIsShellVar"]=array();
11957
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11958
		#$conf["username"]="";
11959
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11960
		#$conf["password"]="";
11961
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11962
		#$conf["useScript"]="";
11963
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11964
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11965
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11966
		#$conf["inBackGround"]="";
11967
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11968
		#$conf["getErr"]="false";
11969
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11970
		#$conf["doNotRun"]="false";
11971
		#參考資料:
11972
		#exec=>http://php.net/manual/en/function.exec.php
11973
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11974
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11975
		#備註:
11976
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11977
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11978
		$callShell=external::callShell($conf["external::callShell"]);
11979
		unset($conf["external::callShell"]);
226 liveuser 11980
 
3 liveuser 11981
		#如果執行失敗
11982
		if($callShell["status"]==="false"){
226 liveuser 11983
 
3 liveuser 11984
			#設置執行失敗
11985
			$result["status"]="false";
226 liveuser 11986
 
3 liveuser 11987
			#設置執行錯誤訊息
11988
			$result["error"]=$callShell;
226 liveuser 11989
 
3 liveuser 11990
			#回傳結果
11991
			return $result;
226 liveuser 11992
 
3 liveuser 11993
			}#if end
226 liveuser 11994
 
3 liveuser 11995
		#取得結果
11996
		$result["content"]=$callShell["output"][0];
226 liveuser 11997
 
3 liveuser 11998
		#取得內容長度
11999
		$result["length"]=strlen($result["content"]);
226 liveuser 12000
 
12001
		#預設尚未到檔案結尾
3 liveuser 12002
		$result["EOF"]="false";
226 liveuser 12003
 
3 liveuser 12004
		#如果取得的內容長度小於預期
12005
		if($result["length"]<$conf["bytes"]){
226 liveuser 12006
 
3 liveuser 12007
			#設置已經到檔案結尾了
12008
			$result["EOF"]="true";
226 liveuser 12009
 
3 liveuser 12010
			}#if end
226 liveuser 12011
 
3 liveuser 12012
		#設置執行正常
12013
		$result["status"]="true";
226 liveuser 12014
 
3 liveuser 12015
		#回傳結果
12016
		return $result;
226 liveuser 12017
 
3 liveuser 12018
		}#function getFilePart end
12019
 
12020
	/*
12021
	#函式說明:
391 liveuser 12022
	#一次讀取一行純文字檔案的內容.
12023
	#回傳結果:
12024
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
12025
	#$result["error"],錯誤訊息陣列.
12026
	#$result["function"],當前執行的函數名稱.
12027
	#$result["cmd"],執行的指令.
12028
	#$result["content"],取得的檔案內容,若沒有內容則為null,反之為字串.
12029
	#$result["length"],取得的內容長度.
12030
	#$result["EOF"],識別是否已經到檔案結尾,"true"代表是,"false"代表不是.
12031
	#$result["nextLine"],整數,下一行的行號,亦即下次來讀取下一行時,lineStart參數要給予的數值.
12032
	#$result["fileSize"],整數,檔案的大小,用於下次來讀取下一行時,preFileSize參數要給予的數值.
12033
	#必填參數:
12034
	#$conf["file"],字串,檔案的路徑與名稱.
12035
	$conf["file"]="";
12036
	#可省略參數:
12037
	#$conf["lineStart"],整數,要從第幾行開始,起始點為1.
12038
	#$conf["lineStart"]=1;
12039
	#$conf["preFileSize"],整數,上次透過本函式取得的fileSize結果,用於確認檔案是否有被rotate過,預設不設置.
12040
	#$conf["preFileSize"]=;
12041
	#可省略參數:
12042
	#無
12043
	#參考資料:
12044
	#無.
12045
	#備註:
12046
	#無
12047
	*/
12048
	public static function getTextFilePart(&$conf){
12049
 
12050
		#初始化要回傳的結果
12051
		$result=array();
12052
 
12053
		#取得當前執行的函數名稱
12054
		$result["function"]=__FUNCTION__;
12055
 
12056
		#如果沒有參數
12057
		if(func_num_args()===0){
12058
 
12059
			#設置執行失敗
12060
			$result["status"]="false";
12061
 
12062
			#設置執行錯誤訊息
12063
			$result["error"]="函數".$result["function"]."需要參數";
12064
 
12065
			#回傳結果
12066
			return $result;
12067
 
12068
			}#if end
12069
 
12070
		#取得參數
12071
		$result["argu"]=$conf;
12072
 
12073
		#如果 $conf 不為陣列
12074
		if(gettype($conf)!=="array"){
12075
 
12076
			#設置執行失敗
12077
			$result["status"]="false";
12078
 
12079
			#設置執行錯誤訊息
12080
			$result["error"][]="\$conf變數須為陣列形態";
12081
 
12082
			#如果傳入的參數為 null
12083
			if(is_null($conf)){
12084
 
12085
				#設置執行錯誤訊息
12086
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
12087
 
12088
				}#if end
12089
 
12090
			#回傳結果
12091
			return $result;
12092
 
12093
			}#if end
12094
 
12095
		#函式說明:
12096
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
12097
		#回傳結果:
12098
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12099
		#$result["error"],執行不正常結束的錯訊息陣列.
12100
		#$result["simpleError"],簡單表示的錯誤訊息.
12101
		#$result["function"],當前執行的函式名稱.
12102
		#$result["argu"],設置給予的參數.
12103
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12104
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12105
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12106
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12107
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12108
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12109
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12110
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12111
		#必填參數:
12112
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12113
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12114
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12115
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12116
		#可省略參數:
12117
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12118
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file");
12119
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
12120
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
12121
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12122
		#$conf["canBeEmptyString"]="false";
12123
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12124
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("lineStart");
12125
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12126
		#$conf["canBeEmpty"]=array();
12127
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12128
		#$conf["skipableVariableCanNotBeEmpty"]=array();
12129
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12130
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("lineStart","preFileSize");
12131
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
12132
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer","integer");
12133
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12134
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(1,null);
12135
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12136
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12137
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12138
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12139
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
12140
		#$conf["disallowAllSkipableVarNotExist"]="";
12141
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12142
		#$conf["arrayCountEqualCheck"][]=array();
12143
		#參考資料:
12144
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12145
		#備註:
12146
		#無.
12147
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12148
		unset($conf["variableCheck::checkArguments"]);
12149
 
12150
		#如果執行異常
12151
		if($checkArguments["status"]==="false"){
12152
 
12153
			#設置執行失敗
12154
			$result["status"]="false";
12155
 
12156
			#設置執行錯誤訊息
12157
			$result["error"]=$checkArguments;
12158
 
12159
			#回傳結果
12160
			return $result;
12161
 
12162
			}#if end
12163
 
12164
		#如果參數檢查不通過
12165
		if($checkArguments["passed"]==="false"){
12166
 
12167
			#設置執行失敗
12168
			$result["status"]="false";
12169
 
12170
			#設置執行錯誤訊息
12171
			$result["error"]=$checkArguments;
12172
 
12173
			#回傳結果
12174
			return $result;
12175
 
12176
			}#if end
12177
 
12178
		#取得檔案資訊,包含檔案的大小
12179
		#函式說明:
12180
		#取得節點的資訊.
12181
		#回傳結果:
12182
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12183
		#$result["error"],錯誤訊息陣列.
12184
		#$result["function"],函數名稱.
12185
		#$result["content"],檔案資訊陣列.
12186
		#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
12187
		#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
12188
		#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
12189
		#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
12190
		#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
12191
		#$result["content"]["ownerName"],檔案擁有着資訊.
12192
		#$result["content"]["groupName"],檔案所屬擁有着資訊.
12193
		#$result["content"]["size"],檔案大小.
12194
		#$result["content"]["modifyDate"],檔案變更年月日.
12195
		#$result["content"]["modifyTime"],檔案變更時分秒.
12196
		#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
12197
		#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
12198
		#必填參數:
12199
		#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
12200
		$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;
12201
		#$conf["file"],字串,要查看擁有者資訊的檔案.
12202
		$conf["fileAccess::fileInfo"]["file"]=$conf["file"];
12203
		#可省略參數:
12204
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
12205
		$conf["fileAccess::fileInfo"]["web"]="false";
12206
		#參考資料:
12207
		#fileowner=>http://php.net/manual/en/function.fileowner.php
12208
		#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
12209
		#備註:
12210
		#無.
12211
		$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
12212
		unset($conf["fileAccess::fileInfo"]);
12213
 
12214
		#如果執行異常
12215
		if($fileInfo["status"]==="false"){
12216
 
12217
			#設置執行失敗
12218
			$result["status"]="false";
12219
 
12220
			#設置執行錯誤訊息
12221
			$result["error"]=$fileInfo;
12222
 
12223
			#回傳結果
12224
			return $result;
12225
 
12226
			}#if end
12227
 
12228
		#如果有設置
12229
		if(isset($conf["preFileSize"])){
12230
 
12231
			#如果檔案大小變小
12232
			if( $conf["preFileSize"] < (int)$fileInfo["content"]["size"] ){
12233
 
12234
				#代表檔案被 rotate 了
12235
 
12236
				#設置從頭開始讀取
12237
				$conf["lineStart"]=1;
12238
 
12239
				}#if end
12240
 
12241
			}#if end
12242
 
12243
		#取得檔案大小
12244
		$result["fileSize"]=$fileInfo["content"]["size"];
12245
 
12246
		#函式說明:
12247
		#呼叫shell執行系統命令,並取得回傳的內容.
12248
		#回傳結果:
12249
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12250
		#$result["error"],錯誤訊息陣列.
12251
		#$result["function"],當前執行的函數名稱.
12252
		#$result["argu"],使用的參數.
12253
		#$result["cmd"],執行的指令內容.
12254
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12255
		#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12256
		#$result["content"],為執行完後的輸出字串.
12257
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12258
		#$result["running"],是否還在執行.
12259
		#$result["pid"],pid.
12260
		#$result["statusCode"],執行結束後的代碼.
12261
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
12262
		#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
12263
		#必填參數:
12264
		#$conf["command"],字串,要執行的指令.
12265
		$conf["fileAccess::callShell"]["command"]="getContentByLineRange.php";
12266
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12267
		$conf["fileAccess::callShell"]["fileArgu"]=__FILE__;
12268
		#可省略參數:
12269
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12270
		$conf["fileAccess::callShell"]["argu"]=array($conf["lineStart"],$conf["lineStart"]+1,$conf["file"]);
12271
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12272
		#$conf["arguIsAddr"]=array();
12273
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
12274
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
12275
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
12276
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12277
		#$conf["enablePrintDescription"]="true";
12278
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
12279
		#$conf["printDescription"]="";
12280
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
12281
		$conf["fileAccess::callShell"]["escapeshellarg"]="true";
12282
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
12283
		#$conf["thereIsShellVar"]=array();
12284
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12285
		#$conf["username"]="";
12286
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12287
		#$conf["password"]="";
12288
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12289
		#$conf["useScript"]="";
12290
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12291
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12292
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12293
		#$conf["inBackGround"]="";
12294
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
12295
		#$conf["getErr"]="false";
12296
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
12297
		#$conf["doNotRun"]="false";
12298
		#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
12299
		#$conf["cmdContainArgu"]="false";
12300
		#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
12301
		#$conf["remoteIp"]="";
12302
		#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
12303
		#$conf["remoteUser"]="";
12304
		#$conf["sshOptions"],陣列,當具備 "remoteIp" 參數時,該參數每個元素為ssh指令的參數.
12305
		#$conf["sshOptions"]=array();
12306
		#參考資料:
12307
		#exec=>http://php.net/manual/en/function.exec.php
12308
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12309
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12310
		#備註:
12311
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12312
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
12313
		$callShell=external::callShell($conf["fileAccess::callShell"]);
12314
		unset($conf["fileAccess::callShell"]);
12315
 
12316
		#debug
12317
		#var_dump(__LINE__,$callShell);
12318
 
12319
		#預設尚未到檔案結尾
12320
		$result["EOF"]="false";
12321
 
12322
		#如果沒有內容
12323
		if(empty($callShell["output"])){
12324
 
12325
			#代表檔案被 rotate 了
12326
 
12327
			#設置到檔案結尾了
12328
			$result["EOF"]="true";
12329
 
12330
			#設置下一行的行號為當前行號
12331
			$result["nextLine"]=$conf["lineStart"];
12332
 
12333
			#設置沒有內容
12334
			$result["content"]=null;
12335
 
12336
			}#if end
12337
 
12338
		#反之
12339
		else{
12340
 
12341
			#取得行內容
12342
			$result["content"]=$callShell["output"][0];
12343
 
12344
			}#else end
12345
 
12346
		#如果沒有下一行的內容
12347
		if(!isset($callShell["output"][1])){
12348
 
12349
			#設置已經到檔案結尾了
12350
			$result["EOF"]="true";
12351
 
12352
			#設置下一行的行號為當前行號
12353
			$result["nextLine"]=$conf["lineStart"];
12354
 
12355
			}#if end
12356
 
12357
		#反之
12358
		else{
12359
 
12360
			#設置下一行的行號
12361
			$result["nextLine"]=$conf["lineStart"]+1;
12362
 
12363
			}#else end
12364
 
12365
		#儲存執行的指令內容
12366
		$result["cmd"]=$callShell["cmd"];
12367
 
12368
		#取得行內容長度
12369
		$result["length"]=strlen($result["content"]);
12370
 
12371
		#設置執行正常
12372
		$result["status"]="true";
12373
 
12374
		#回傳結果
12375
		return $result;
12376
 
12377
		}#function getTextFilePart end
12378
 
12379
	/*
12380
	#函式說明:
3 liveuser 12381
	#取得節點的資訊.
12382
	#回傳結果:
12383
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12384
	#$result["error"],錯誤訊息陣列.
226 liveuser 12385
	#$result["function"],函數名稱.
3 liveuser 12386
	#$result["content"],檔案資訊陣列.
226 liveuser 12387
	#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 12388
	#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
12389
	#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
12390
	#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
12391
	#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
12392
	#$result["content"]["ownerName"],檔案擁有着資訊.
12393
	#$result["content"]["groupName"],檔案所屬擁有着資訊.
391 liveuser 12394
	#$result["content"]["size"],字串,檔案大小.
3 liveuser 12395
	#$result["content"]["modifyDate"],檔案變更年月日.
12396
	#$result["content"]["modifyTime"],檔案變更時分秒.
12397
	#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
12398
	#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
12399
	#必填參數:
12400
	#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
12401
	$conf["fileArgu"]=__FILE__;
12402
	#$conf["file"],字串,要查看擁有者資訊的檔案.
12403
	$conf["file"]="";
12404
	#可省略參數:
12405
	#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
12406
	#$conf["web"]="true";
12407
	#參考資料:
12408
	#fileowner=>http://php.net/manual/en/function.fileowner.php
12409
	#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
12410
	#備註:
12411
	#無.
12412
	*/
12413
	public static function fileInfo(&$conf=array()){
226 liveuser 12414
 
3 liveuser 12415
		#初始化要回傳的結果
12416
		$result=array();
12417
 
12418
		#取得當前執行的函數名稱
12419
		$result["function"]=__FUNCTION__;
12420
 
12421
		#如果沒有參數
12422
		if(func_num_args()==0){
226 liveuser 12423
 
3 liveuser 12424
			#設置執行失敗
12425
			$result["status"]="false";
226 liveuser 12426
 
3 liveuser 12427
			#設置執行錯誤訊息
12428
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 12429
 
3 liveuser 12430
			#回傳結果
12431
			return $result;
226 liveuser 12432
 
3 liveuser 12433
			}#if end
12434
 
12435
		#取得參數
12436
		$result["argu"]=$conf;
12437
 
12438
		#如果 $conf 不為陣列
12439
		if(gettype($conf)!=="array"){
226 liveuser 12440
 
3 liveuser 12441
			#設置執行失敗
12442
			$result["status"]="false";
226 liveuser 12443
 
3 liveuser 12444
			#設置執行錯誤訊息
12445
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 12446
 
3 liveuser 12447
			#如果傳入的參數為 null
12448
			if($conf===null){
226 liveuser 12449
 
3 liveuser 12450
				#設置執行錯誤訊息
12451
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12452
 
3 liveuser 12453
				}#if end
12454
 
12455
			#回傳結果
12456
			return $result;
226 liveuser 12457
 
3 liveuser 12458
			}#if end
226 liveuser 12459
 
3 liveuser 12460
		#檢查參數
12461
		#函式說明:
12462
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12463
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12464
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12465
		#$result["function"],當前執行的函式名稱.
12466
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12467
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12468
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12469
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12470
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12471
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12472
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12473
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12474
		#必填寫的參數:
12475
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 12476
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 12477
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12478
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12479
		#可以省略的參數:
12480
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12481
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
12482
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12483
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
12484
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12485
		#$conf["canBeEmptyString"]="false";
12486
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12487
		#$conf["ileAccess::checkArguments"]["canNotBeEmpty"]=array();
12488
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12489
		#$conf["canBeEmpty"]=array();
12490
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12491
		#$conf["skipableVariableCanNotBeEmpty"]=array();
12492
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12493
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 12494
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12495
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
12496
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12497
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
12498
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12499
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12500
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12501
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12502
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12503
		#$conf["arrayCountEqualCheck"][]=array();
12504
		#參考資料來源:
12505
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12506
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12507
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 12508
 
3 liveuser 12509
		#如果檢查參數失敗
12510
		if($checkArguments["status"]==="false"){
226 liveuser 12511
 
3 liveuser 12512
			#設置執行失敗
12513
			$result["status"]="false";
226 liveuser 12514
 
3 liveuser 12515
			#設置執行錯誤訊息
12516
			$result["error"]=$checkArguments;
226 liveuser 12517
 
3 liveuser 12518
			#回傳結果
12519
			return $result;
226 liveuser 12520
 
3 liveuser 12521
			}#if end
226 liveuser 12522
 
3 liveuser 12523
		#如果檢查參數不通過
12524
		if($checkArguments["passed"]==="false"){
226 liveuser 12525
 
3 liveuser 12526
			#設置執行失敗
12527
			$result["status"]="false";
226 liveuser 12528
 
3 liveuser 12529
			#設置執行錯誤訊息
12530
			$result["error"]=$checkArguments;
226 liveuser 12531
 
3 liveuser 12532
			#回傳結果
12533
			return $result;
226 liveuser 12534
 
3 liveuser 12535
			}#if end
226 liveuser 12536
 
3 liveuser 12537
		#函式說明:
12538
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
12539
		#回傳結果:
12540
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12541
		#$result["error"],錯誤訊息陣列.
226 liveuser 12542
		#$result["function"],函數名稱.
3 liveuser 12543
		#$result["argu"],使用的參數.
12544
		#$result["content"],網址,若是在命令列執行,則為"null".
12545
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
12546
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
12547
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
12548
		#必填參數:
12549
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
12550
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["file"];
12551
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
12552
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
12553
		#可省略參數:
12554
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
12555
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
12556
		#備註:
12557
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
12558
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
12559
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 12560
 
3 liveuser 12561
		#如果取得位置失敗
12562
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 12563
 
3 liveuser 12564
			#設置執行失敗
12565
			$result["status"]="false";
226 liveuser 12566
 
3 liveuser 12567
			#設置執行錯誤訊息
12568
			$result["error"]=$getInternetAddressV2;
226 liveuser 12569
 
3 liveuser 12570
			#回傳結果
12571
			return $result;
226 liveuser 12572
 
3 liveuser 12573
			}#if end
12574
 
12575
		#函式說明:
12576
		#檢查多個檔案與資料夾是否存在.
12577
		#回傳的結果:
12578
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
12579
		#$result["error"],錯誤訊息陣列.
12580
		#$resutl["function"],當前執行的涵式名稱.
12581
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
12582
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
12583
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
12584
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
12585
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
12586
		#必填參數:
12587
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
12588
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($getInternetAddressV2["fileSystemAbsoulutePosition"]);
12589
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12590
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
12591
		#可省略參數
12592
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
12593
		#$conf["disableWebSearch"]="false";
12594
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
12595
		#$conf["userDir"]="true";
12596
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
12597
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
12598
		#參考資料來源:
12599
		#http://php.net/manual/en/function.file-exists.php
12600
		#http://php.net/manual/en/control-structures.foreach.php
12601
		#備註:
12602
		#函數file_exists檢查的路徑為檔案系統的路徑
12603
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
12604
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 12605
 
3 liveuser 12606
		#如果檢查檔案存在失敗
12607
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 12608
 
3 liveuser 12609
			#設置執行失敗
12610
			$result["status"]="false";
226 liveuser 12611
 
3 liveuser 12612
			#設置執行錯誤訊息
12613
			$result["error"]=$checkMultiFileExist;
226 liveuser 12614
 
3 liveuser 12615
			#回傳結果
12616
			return $result;
226 liveuser 12617
 
3 liveuser 12618
			}#if end
226 liveuser 12619
 
3 liveuser 12620
		#如果檔案不存在
12621
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 12622
 
3 liveuser 12623
			#設置執行失敗
12624
			$result["status"]="false";
226 liveuser 12625
 
3 liveuser 12626
			#設置執行錯誤訊息
12627
			$result["error"]=$checkMultiFileExist;
226 liveuser 12628
 
3 liveuser 12629
			#回傳結果
12630
			return $result;
226 liveuser 12631
 
3 liveuser 12632
			}#if end
226 liveuser 12633
 
3 liveuser 12634
		#透過ls指令取得檔案的資訊
12635
		#函式說明:
12636
		#呼叫shell執行系統命令,並取得回傳的內容.
12637
		#回傳的結果:
12638
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12639
		#$result["error"],錯誤訊息陣列.
12640
		#$result["function"],當前執行的函數名稱.
12641
		#$result["cmd"],執行的指令內容.
12642
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12643
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12644
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12645
		#$result["running"],是否還在執行.
12646
		#$result["pid"],pid
12647
		#必填的參數
12648
		#$conf["command"],字串,要執行的指令
12649
		$conf["external::callShell"]["command"]="ls";
12650
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12651
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
12652
		#可省略參數:
12653
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12654
		$conf["external::callShell"]["argu"]=array("-l","--full-time","-d",$conf["file"]);
12655
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12656
		$conf["external::callShell"]["arguIsAddr"]=array("false","false","false","false");
12657
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12658
		#$conf["enablePrintDescription"]="true";
12659
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
12660
		#$conf["printDescription"]="";
12661
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
12662
		$conf["external::callShell"]["escapeshellarg"]="true";
12663
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12664
		#$conf["username"]="";
12665
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12666
		#$conf["password"]="";
12667
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12668
		#$conf["useScript"]="";
12669
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12670
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12671
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12672
		#$conf["inBackGround"]="";
12673
		#備註:
12674
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12675
		#參考資料:
12676
		#exec=>http://php.net/manual/en/function.exec.php
12677
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12678
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12679
		$callShell=external::callShell($conf["external::callShell"]);
12680
		unset($conf["external::callShell"]);
226 liveuser 12681
 
3 liveuser 12682
		#如果執行失敗
12683
		if($callShell["status"]==="false"){
226 liveuser 12684
 
3 liveuser 12685
			#設置執行失敗
12686
			$result["status"]="false";
226 liveuser 12687
 
3 liveuser 12688
			#設置執行錯誤訊息
12689
			$result["error"]=$callShell;
226 liveuser 12690
 
3 liveuser 12691
			#回傳結果
12692
			return $result;
226 liveuser 12693
 
12694
			}#if end
12695
 
3 liveuser 12696
		#解析檔案資訊
12697
		#-rwxrwx--x. 1 apache apache 65K 2017-04-16 22:53:19.044545806 +0800 fileAccessT.php
226 liveuser 12698
 
3 liveuser 12699
		#取得權限資訊 -rwxrwx--x
12700
		$perm=substr($callShell["output"][0],0,strpos($callShell["output"][0],'.'));
226 liveuser 12701
 
3 liveuser 12702
		#如果是目錄
12703
		if(substr($perm,0,1)==="d"){
226 liveuser 12704
 
3 liveuser 12705
			#設定為目錄
12706
			$result["content"]["is_folder"]="true";
226 liveuser 12707
 
3 liveuser 12708
			}#if end
226 liveuser 12709
 
3 liveuser 12710
		#反之
12711
		else{
226 liveuser 12712
 
3 liveuser 12713
			#設定不為目錄
12714
			$result["content"]["is_folder"]="false";
226 liveuser 12715
 
3 liveuser 12716
			}#else end
226 liveuser 12717
 
3 liveuser 12718
		#解析檔案擁有者權限資訊
12719
		$result["content"]["ownerPerm"]=substr($perm,1,3);
226 liveuser 12720
 
3 liveuser 12721
		#如果檔案擁有者名稱為空
12722
		if(empty($result["content"]["ownerPerm"])){
226 liveuser 12723
 
3 liveuser 12724
			#設置執行失敗
12725
			$result["status"]="false";
226 liveuser 12726
 
3 liveuser 12727
			#設置執行錯誤訊息
12728
			$result["error"]=$callShell;
226 liveuser 12729
 
3 liveuser 12730
			#回傳結果
12731
			return $result;
226 liveuser 12732
 
3 liveuser 12733
			}#if end
226 liveuser 12734
 
3 liveuser 12735
		#解析檔案歸屬群組權限資訊
12736
		$result["content"]["groupPerm"]=substr($perm,4,3);
226 liveuser 12737
 
3 liveuser 12738
		#解析檔案對於其他身份使用者的權限資訊
12739
		$result["content"]["otherPerm"]=substr($perm,7,3);
226 liveuser 12740
 
3 liveuser 12741
		#取得目錄底下的檔案目錄數量起始點
12742
		$subElementStartPos=strpos($callShell["output"][0],' ');
226 liveuser 12743
 
3 liveuser 12744
		#取得目錄底下的檔案目錄數量結束點
12745
		$subElementEndPos=strpos($callShell["output"][0],' ',$subElementStartPos+1);
226 liveuser 12746
 
3 liveuser 12747
		#取得目錄底下的檔案目錄數量
12748
		$result["content"]["subElementCount"]=substr($callShell["output"][0],$subElementStartPos,$subElementEndPos-$subElementStartPos);
226 liveuser 12749
 
3 liveuser 12750
		#取得檔案擁有着資訊的起點
12751
		$ownerNameStrPos=strpos($callShell["output"][0],' ',$subElementEndPos)+1;
226 liveuser 12752
 
3 liveuser 12753
		#取得檔案擁有着資訊的結束點
12754
		$ownerNameEndPos=strpos($callShell["output"][0],' ',$ownerNameStrPos+1);
226 liveuser 12755
 
3 liveuser 12756
		#取得檔案擁有着資訊
12757
		$result["content"]["ownerName"]=substr($callShell["output"][0],$ownerNameStrPos,$ownerNameEndPos-$ownerNameStrPos);
226 liveuser 12758
 
3 liveuser 12759
		#取取得檔案群組擁有者資訊的起點
12760
		$groupNameStrPos=strpos($callShell["output"][0],' ',$ownerNameEndPos)+1;
226 liveuser 12761
 
3 liveuser 12762
		#取得檔案群組擁有者資訊的結束點
12763
		$groupNameEndPos=strpos($callShell["output"][0],' ',$groupNameStrPos);
226 liveuser 12764
 
3 liveuser 12765
		#取得檔案群組擁有者資訊
12766
		$result["content"]["groupName"]=substr($callShell["output"][0],$groupNameStrPos,$groupNameEndPos-$groupNameStrPos);
226 liveuser 12767
 
3 liveuser 12768
		#取得檔案大小的起點
12769
		$sizeStrPos=strpos($callShell["output"][0],' ',$groupNameEndPos)+1;
226 liveuser 12770
 
3 liveuser 12771
		#取得檔案大小的結束點
12772
		$sizeEndPos=strpos($callShell["output"][0],' ',$sizeStrPos);
226 liveuser 12773
 
3 liveuser 12774
		#取得檔案大小
12775
		$result["content"]["size"]=substr($callShell["output"][0],$sizeStrPos,$sizeEndPos-$sizeStrPos);
226 liveuser 12776
 
3 liveuser 12777
		#取得檔案變更年月日的起點
12778
		$modifyDateStrPos=strpos($callShell["output"][0],' ',$sizeEndPos)+1;
226 liveuser 12779
 
3 liveuser 12780
		#取得檔案變更年月日的結束點
12781
		$modifyDateEndPos=strpos($callShell["output"][0],' ',$modifyDateStrPos);
226 liveuser 12782
 
12783
		#取得檔案變更年月日
3 liveuser 12784
		$result["content"]["modifyDate"]=substr($callShell["output"][0],$modifyDateStrPos,$modifyDateEndPos-$modifyDateStrPos);
226 liveuser 12785
 
3 liveuser 12786
		#取得檔案變更時分秒的起點
12787
		$modifyTimeStrPos=strpos($callShell["output"][0],' ',$modifyDateEndPos)+1;
226 liveuser 12788
 
3 liveuser 12789
		#取得檔案變更時分秒的結束點
12790
		$modifyTimeEndPos=strpos($callShell["output"][0],'.',$modifyTimeStrPos);
226 liveuser 12791
 
3 liveuser 12792
		#取得檔案變更時分秒
12793
		$result["content"]["modifyTime"]=substr($callShell["output"][0],$modifyTimeStrPos,$modifyTimeEndPos-$modifyTimeStrPos);
226 liveuser 12794
 
3 liveuser 12795
		#取得檔版變更時間秒的float數值起點
12796
		$modifyTimeFloatStrPos=strpos($callShell["output"][0],'.',$modifyTimeEndPos)+1;
226 liveuser 12797
 
3 liveuser 12798
		#取得檔版變更時間秒的float數值結束點
12799
		$modifyTimeFloatEndPos=strpos($callShell["output"][0],' ',$modifyTimeFloatStrPos);
226 liveuser 12800
 
12801
		#取得檔版變更時間秒的float數值
3 liveuser 12802
		$result["content"]["modifyTimeFloat"]=substr($callShell["output"][0],$modifyTimeFloatStrPos,$modifyTimeFloatEndPos-$modifyTimeFloatStrPos);
226 liveuser 12803
 
3 liveuser 12804
		#取得時區起始點
12805
		$timezoneStrPos=strpos($callShell["output"][0],' ',$modifyTimeFloatEndPos)+1;
226 liveuser 12806
 
3 liveuser 12807
		#取得時區結束點
226 liveuser 12808
		$timezoneEndPos=strpos($callShell["output"][0],' ',$timezoneStrPos)+1;
12809
 
3 liveuser 12810
		#取得檔案變更時間的時區與UTC的差距.
226 liveuser 12811
		$result["content"]["timezone"]=substr($callShell["output"][0],$timezoneStrPos,$timezoneEndPos-$timezoneStrPos);
12812
 
3 liveuser 12813
		#設置執行正常
12814
		$result["status"]="true";
226 liveuser 12815
 
3 liveuser 12816
		#回傳結果
12817
		return $result;
226 liveuser 12818
 
3 liveuser 12819
		}#function fileInfo end
12820
 
12821
	/*
12822
	#函式說明:
226 liveuser 12823
	#依據函數getListTree執行的結果,將其底下與其子目錄底下的特定檔案內容依據目錄層級輸出成html檔案
3 liveuser 12824
	#回傳結果:
12825
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12826
	#$result["error"],錯誤訊息陣列.
226 liveuser 12827
	#$result["function"],函數名稱.
3 liveuser 12828
	#$result["content"],html檔案輸出的位置與名稱.
12829
	#必填參數:
12830
	#$conf["getListTree"],陣列變數,函數getListTree執行的結果.
12831
	$conf["getListTree"]=$getListTree;
12832
	#可省略參數:
12833
	#$conf["fileToRead"],字串,要讀取的檔案名稱為何?預設為"help".
12834
	#$conf["fileToRead"]="help";
12835
	#$conf["output"],字串,輸出的網頁檔案位置與名稱,副檔名html會自動補上,預設為"help".
226 liveuser 12836
	#$conf["output"]="help.html";
3 liveuser 12837
	#參考資料:
12838
	#無.
12839
	#備註:
12840
	#建構中...
12841
	*/
12842
	public static function createHelpFile($conf){
226 liveuser 12843
 
3 liveuser 12844
		#初始化要回傳的結果
12845
		$result=array();
226 liveuser 12846
 
3 liveuser 12847
		#設置當其函數名稱
12848
		$result["function"]=__FUNCTION__;
226 liveuser 12849
 
3 liveuser 12850
		#如果 $conf 不為陣列
12851
		if(gettype($conf)!="array"){
226 liveuser 12852
 
3 liveuser 12853
			#設置執行失敗
12854
			$result["status"]="false";
226 liveuser 12855
 
3 liveuser 12856
			#設置執行錯誤訊息
12857
			$result["error"][]="\$conf變數須為陣列形態";
12858
 
12859
			#如果傳入的參數為 null
12860
			if($conf==null){
226 liveuser 12861
 
3 liveuser 12862
				#設置執行錯誤訊息
12863
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12864
 
3 liveuser 12865
				}#if end
12866
 
12867
			#回傳結果
12868
			return $result;
226 liveuser 12869
 
3 liveuser 12870
			}#if end
226 liveuser 12871
 
3 liveuser 12872
		#檢查參數
12873
		#函式說明:
12874
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12875
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12876
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12877
		#$result["function"],當前執行的函式名稱.
12878
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12879
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12880
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12881
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
12882
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12883
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12884
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12885
		#必填寫的參數:
12886
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12887
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12888
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12889
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("getListTree");
226 liveuser 12890
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 12891
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
12892
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12893
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12894
		#可以省略的參數:
12895
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
12896
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
12897
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12898
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileToRead","output");
226 liveuser 12899
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12900
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
12901
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12902
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("help","help");
12903
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12904
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
12905
		#參考資料來源:
12906
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12907
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12908
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 12909
 
3 liveuser 12910
		#如果 $checkResult["status"] 等於 "fasle"
12911
		if($checkResult["status"]=="false"){
226 liveuser 12912
 
3 liveuser 12913
			#設置錯誤識別
12914
			$result["status"]="false";
226 liveuser 12915
 
3 liveuser 12916
			#設置錯誤訊息
12917
			$result["error"]=$checkResult;
226 liveuser 12918
 
3 liveuser 12919
			#回傳結果
12920
			return $result;
226 liveuser 12921
 
3 liveuser 12922
			}#if end
226 liveuser 12923
 
3 liveuser 12924
		#如果 $checkResult["passed"] 等於 "fasle"
12925
		if($checkResult["passed"]=="false"){
226 liveuser 12926
 
3 liveuser 12927
			#設置錯誤識別
12928
			$result["status"]="false";
226 liveuser 12929
 
3 liveuser 12930
			#設置錯誤訊息
12931
			$result["error"]=$checkResult;
226 liveuser 12932
 
3 liveuser 12933
			#回傳結果
12934
			return $result;
226 liveuser 12935
 
3 liveuser 12936
			}#if end
226 liveuser 12937
 
3 liveuser 12938
		#如果 $conf["getListTree"]["status"] 不存在
12939
		if(!isset($conf["getListTree"]["status"])){
226 liveuser 12940
 
3 liveuser 12941
			#設置錯誤識別
12942
			$result["status"]="false";
226 liveuser 12943
 
3 liveuser 12944
			#設置錯誤訊息
12945
			$result["error"][]="getListTree參數必須為getListTree函數執行後的結果";
226 liveuser 12946
 
3 liveuser 12947
			#回傳結果
12948
			return $result;
226 liveuser 12949
 
3 liveuser 12950
			}#if end
226 liveuser 12951
 
3 liveuser 12952
		#如果 $conf["getListTree"] 執行失敗
12953
		if($conf["getListTree"]["status"]=="false"){
226 liveuser 12954
 
3 liveuser 12955
			#設置錯誤識別
12956
			$result["status"]="false";
226 liveuser 12957
 
3 liveuser 12958
			#設置錯誤訊息
12959
			$result["error"]=$conf["getListTree"];
226 liveuser 12960
 
3 liveuser 12961
			#回傳結果
12962
			return $result;
226 liveuser 12963
 
3 liveuser 12964
			}#if end
226 liveuser 12965
 
3 liveuser 12966
		#如果有目錄檔案
12967
		if(isset($conf["getListTree"]["content"])){
226 liveuser 12968
 
12969
 
12970
 
3 liveuser 12971
			}#if end
226 liveuser 12972
 
3 liveuser 12973
		}#function createHelpFile end
226 liveuser 12974
 
3 liveuser 12975
	/*
12976
	#函式說明:
12977
	#嵌入pdf檔案到網頁上面
12978
	#回傳結果:
12979
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12980
	#$result["error"],錯誤訊息陣列.
226 liveuser 12981
	#$result["function"],函數名稱.
3 liveuser 12982
	#$result["content"],嵌入pdf檔案的語法
12983
	#必填參數:
12984
	#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
12985
	$conf["fileArgu"]=__FILE__;
12986
	#$conf["file"],字串,pdf檔案位置.
12987
	$conf["file"]="";
12988
	#可省略參數:
12989
	#$conf["type"],字串,要用"iframe"還是"object"的方式嵌入pdf檔案,預設為"iframe".
12990
	#$conf["type"]="iframe";
12991
	#參考資料:
12992
	#嵌入pdf到網頁=>https://stackoverflow.com/questions/14690000/embed-a-pdf-in-html5
12993
	#備註:
12994
	#如果是網址就會出錯.
12995
	*/
12996
	public static function embedPdf(&$conf=array()){
226 liveuser 12997
 
3 liveuser 12998
		#初始化要回傳的結果
12999
		$result=array();
13000
 
13001
		#取得當前執行的函數名稱
13002
		$result["function"]=__FUNCTION__;
13003
 
13004
		#如果沒有參數
13005
		if(func_num_args()==0){
226 liveuser 13006
 
3 liveuser 13007
			#設置執行失敗
13008
			$result["status"]="false";
226 liveuser 13009
 
3 liveuser 13010
			#設置執行錯誤訊息
13011
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 13012
 
3 liveuser 13013
			#回傳結果
13014
			return $result;
226 liveuser 13015
 
3 liveuser 13016
			}#if end
13017
 
13018
		#取得參數
13019
		$result["argu"]=$conf;
13020
 
13021
		#如果 $conf 不為陣列
13022
		if(gettype($conf)!=="array"){
226 liveuser 13023
 
3 liveuser 13024
			#設置執行失敗
13025
			$result["status"]="false";
226 liveuser 13026
 
3 liveuser 13027
			#設置執行錯誤訊息
13028
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 13029
 
3 liveuser 13030
			#如果傳入的參數為 null
13031
			if($conf===null){
226 liveuser 13032
 
3 liveuser 13033
				#設置執行錯誤訊息
13034
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 13035
 
3 liveuser 13036
				}#if end
13037
 
13038
			#回傳結果
13039
			return $result;
226 liveuser 13040
 
3 liveuser 13041
			}#if end
226 liveuser 13042
 
3 liveuser 13043
		#檢查參數
13044
		#函式說明:
13045
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13046
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13047
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13048
		#$result["function"],當前執行的函式名稱.
13049
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13050
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13051
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13052
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13053
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13054
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13055
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13056
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13057
		#必填寫的參數:
13058
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
13059
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
13060
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13061
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
13062
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13063
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
13064
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13065
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13066
		#可以省略的參數:
13067
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13068
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
13069
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13070
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("function");
13071
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13072
		#$conf["canBeEmpty"]=array();
13073
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13074
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("width","height");
13075
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13076
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("type");
226 liveuser 13077
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 13078
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
13079
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13080
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("iframe");
13081
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13082
		#$conf["arrayCountEqualCheck"][]=array();
13083
		#參考資料來源:
13084
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13085
		#建議:
13086
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
13087
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
226 liveuser 13088
		unset($conf["variableCheck::checkArguments"]);
13089
 
3 liveuser 13090
		#如果檢查參數失敗
13091
		if($checkArguments["status"]==="false"){
226 liveuser 13092
 
3 liveuser 13093
			#設置執行失敗
13094
			$result["status"]="false";
226 liveuser 13095
 
3 liveuser 13096
			#設置執行錯誤訊息
13097
			$result["error"]=$checkArguments;
226 liveuser 13098
 
3 liveuser 13099
			#回傳結果
13100
			return $result;
226 liveuser 13101
 
3 liveuser 13102
			}#if end
226 liveuser 13103
 
3 liveuser 13104
		#如果參數檢查不通過
13105
		if($checkArguments["passed"]==="false"){
226 liveuser 13106
 
3 liveuser 13107
			#設置執行失敗
13108
			$result["status"]="false";
226 liveuser 13109
 
3 liveuser 13110
			#設置執行錯誤訊息
13111
			$result["error"]=$checkArguments;
226 liveuser 13112
 
3 liveuser 13113
			#回傳結果
13114
			return $result;
226 liveuser 13115
 
3 liveuser 13116
			}#if end
226 liveuser 13117
 
3 liveuser 13118
		#檢查檔案是否存在
13119
		#函式說明:
13120
		#檢查多個檔案與資料夾是否存在.
13121
		#回傳的結果:
13122
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13123
		#$result["error"],錯誤訊息陣列.
13124
		#$resutl["function"],當前執行的涵式名稱.
13125
		#$result["argu"],使用的參數.
13126
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
13127
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
13128
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
13129
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
13130
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
13131
		#必填參數:
13132
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
13133
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
13134
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13135
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
13136
		#可省略參數
13137
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
13138
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="false";
13139
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
13140
		#$conf["userDir"]="true";
13141
		#參考資料來源:
13142
		#http://php.net/manual/en/function.file-exists.php
13143
		#http://php.net/manual/en/control-structures.foreach.php
13144
		#備註:
13145
		#函數file_exists檢查的路徑為檔案系統的路徑
13146
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
13147
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 13148
 
3 liveuser 13149
		#如果檢查檔案是否存在失敗
13150
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 13151
 
3 liveuser 13152
			#設置執行失敗
13153
			$result["status"]="false";
226 liveuser 13154
 
3 liveuser 13155
			#設置執行錯誤訊息
13156
			$result["error"]=$checkMultiFileExist;
226 liveuser 13157
 
3 liveuser 13158
			#回傳結果
13159
			return $result;
226 liveuser 13160
 
3 liveuser 13161
			}#if end
226 liveuser 13162
 
3 liveuser 13163
		#如果檔案不存在
13164
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 13165
 
3 liveuser 13166
			#設置執行失敗
13167
			$result["status"]="false";
226 liveuser 13168
 
3 liveuser 13169
			#設置執行錯誤訊息
13170
			$result["error"]=$checkMultiFileExist;
226 liveuser 13171
 
3 liveuser 13172
			#回傳結果
13173
			return $result;
226 liveuser 13174
 
3 liveuser 13175
			}#if end
226 liveuser 13176
 
3 liveuser 13177
		#產生 base64 的 pdf 編碼字串
13178
		$base64pdf=base64_encode(file_get_contents($conf["file"]));
226 liveuser 13179
 
3 liveuser 13180
		#產生 base64 的 pdf 編碼字串 data
13181
		$base64pdfData="data:application/pdf;base64,".$base64pdf;
226 liveuser 13182
 
3 liveuser 13183
		#判斷要用哪種方式嵌入pdf
13184
		switch($conf["type"]){
226 liveuser 13185
 
3 liveuser 13186
			#如果是用 object 方式
13187
			case "object":
226 liveuser 13188
 
3 liveuser 13189
				#產生嵌入的語法
13190
				$embedSyntax="<object style=\"width:100%;height:100%;\" data=\"".$base64pdfData."\"></object>";
226 liveuser 13191
 
3 liveuser 13192
				#取得語法
13193
				$result["content"]=&$embedSyntax;
226 liveuser 13194
 
3 liveuser 13195
				#跳出 switch
13196
				break;
226 liveuser 13197
 
3 liveuser 13198
			#預設
13199
			default:
226 liveuser 13200
 
3 liveuser 13201
				#產生嵌入的語法
13202
				$embedSyntax="<iframe style=\"width:100%;height:100%;\" src=\"".$base64pdfData."\"></iframe>";
226 liveuser 13203
 
3 liveuser 13204
				#取得語法
13205
				$result["content"]=&$embedSyntax;
226 liveuser 13206
 
3 liveuser 13207
			}#switch end
226 liveuser 13208
 
3 liveuser 13209
		#設置執行正常
13210
		$result["status"]="true";
226 liveuser 13211
 
3 liveuser 13212
		#回傳結果
13213
		return $result;
226 liveuser 13214
 
3 liveuser 13215
		}#function embedPdf end
226 liveuser 13216
 
3 liveuser 13217
	/*
13218
	#函式說明:
226 liveuser 13219
	#用linux unzip去解壓縮zip檔案
3 liveuser 13220
	#回傳結果:
13221
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13222
	#$result["error"],錯誤訊息.
13223
	#$result["function"],當前執行的函數名稱.
13224
	#$result["content"]["each"],每個檔案的資訊.
13225
	#$result["content"]["each"]["Length"][$i],各別檔案目錄的原始長度.
13226
	#$result["content"]["each"]["Method"][$i],各別檔案目錄的壓縮方法.
13227
	#$result["content"]["each"]["Size"][$i],各別檔案目錄的壓縮後長度.
13228
	#$result["content"]["each"]["Cmpr"][$i],各別檔案目錄的壓縮率.
13229
	#$result["content"]["each"]["Date"][$i],各別檔案目錄的最後修改日期.
13230
	#$result["content"]["each"]["Time"][$i],各別檔案目錄的最後修改時間.
13231
	#$result["content"]["each"]["CRC-32"][$i],各別檔案目錄的CRC-32檢查碼.
13232
	#$result["content"]["each"]["Name"][$i],各別檔案目錄的路徑與名稱.
13233
	#$result["content"]["total"],統整的資訊.
13234
	#$result["content"]["Length"],總共的檔案長度.
13235
	#$result["content"]["Size"],壓縮後的檔案長度.
13236
	#$result["content"]["Cmpr"],平均壓縮率.
13237
	#$result["content"]["count"],壓縮檔裡面總共的檔案跟目錄數目.
13238
	#必填參數;
13239
	#$conf["zip"],字串,要解壓縮的zip檔案.
13240
	$conf["zip"]="";
13241
	#$conf["fileArgu"],字串,__FILE__的內容.
13242
	$conf["fileArgu"]=__FILE__;
13243
	#可省略參數:
13244
	#$conf["extract"],字串,要解壓縮到那個路徑,預設為當前位置"./".
13245
	#$conf["extract"]="";
13246
	#備註:
391 liveuser 13247
	#建議加上特定邊碼的支援例如,big5、shilf_jis.
3 liveuser 13248
	*/
13249
	public static function unzip(&$conf=array()){
226 liveuser 13250
 
3 liveuser 13251
		#初始化要回傳的結果
13252
		$result=array();
13253
 
13254
		#取得當前執行的函數名稱
13255
		$result["function"]=__FUNCTION__;
13256
 
13257
		#如果沒有參數
13258
		if(func_num_args()==0){
226 liveuser 13259
 
3 liveuser 13260
			#設置執行失敗
13261
			$result["status"]="false";
226 liveuser 13262
 
3 liveuser 13263
			#設置執行錯誤訊息
13264
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 13265
 
3 liveuser 13266
			#回傳結果
13267
			return $result;
226 liveuser 13268
 
3 liveuser 13269
			}#if end
226 liveuser 13270
 
3 liveuser 13271
		#取得參數
13272
		$result["argu"]=$conf;
13273
 
13274
		#如果 $conf 不為陣列
13275
		if(gettype($conf)!=="array"){
226 liveuser 13276
 
3 liveuser 13277
			#設置執行失敗
13278
			$result["status"]="false";
226 liveuser 13279
 
3 liveuser 13280
			#設置執行錯誤訊息
13281
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 13282
 
3 liveuser 13283
			#如果傳入的參數為 null
13284
			if($conf===null){
226 liveuser 13285
 
3 liveuser 13286
				#設置執行錯誤訊息
13287
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 13288
 
3 liveuser 13289
				}#if end
13290
 
13291
			#回傳結果
13292
			return $result;
226 liveuser 13293
 
3 liveuser 13294
			}#if end
226 liveuser 13295
 
3 liveuser 13296
		#檢查參數
13297
		#函式說明:
13298
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13299
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13300
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13301
		#$result["function"],當前執行的函式名稱.
13302
		#$result["argu"],設置給予的參數.
13303
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13304
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13305
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13306
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13307
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13308
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13309
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13310
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13311
		#必填寫的參數:
13312
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 13313
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 13314
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13315
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13316
		#可以省略的參數:
13317
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13318
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("zip","fileArgu");
13319
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13320
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
13321
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13322
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
13323
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13324
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("zip","fileArgu");
13325
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13326
		#$conf["canBeEmpty"]=array();
13327
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13328
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("extract");
13329
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13330
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("extract");
226 liveuser 13331
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 13332
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
13333
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13334
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("./");
13335
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
13336
		#$conf["disallowAllSkipableVarIsEmpty"]="";
13337
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
13338
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
13339
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13340
		#$conf["arrayCountEqualCheck"][]=array();
13341
		#參考資料來源:
13342
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13343
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
13344
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 13345
 
3 liveuser 13346
		#如果檢查參數失敗
13347
		if($checkArguments["status"]==="false"){
226 liveuser 13348
 
3 liveuser 13349
			#設置執行不正常
13350
			$result["status"]="false";
226 liveuser 13351
 
3 liveuser 13352
			#設置錯誤訊息
13353
			$result["error"]=$checkArguments;
226 liveuser 13354
 
3 liveuser 13355
			#回傳結果
13356
			return $result;
226 liveuser 13357
 
3 liveuser 13358
			}#if end
226 liveuser 13359
 
3 liveuser 13360
		#如果檢查參數不通過
13361
		if($checkArguments["passed"]==="false"){
226 liveuser 13362
 
3 liveuser 13363
			#設置執行不正常
13364
			$result["status"]="false";
226 liveuser 13365
 
3 liveuser 13366
			#設置錯誤訊息
13367
			$result["error"]=$checkArguments;
226 liveuser 13368
 
3 liveuser 13369
			#回傳結果
13370
			return $result;
226 liveuser 13371
 
3 liveuser 13372
			}#if end
226 liveuser 13373
 
3 liveuser 13374
		#檢查要解壓縮的檔案是否存在
13375
		#函式說明:
13376
		#檢查多個檔案與資料夾是否存在.
13377
		#回傳的結果:
13378
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13379
		#$result["error"],錯誤訊息陣列.
13380
		#$resutl["function"],當前執行的涵式名稱.
13381
		#$result["argu"],使用的參數.
13382
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
13383
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
13384
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
13385
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
13386
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
13387
		#必填參數:
13388
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
13389
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["zip"]);
13390
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13391
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
13392
		#可省略參數
13393
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
13394
		#$conf["disableWebSearch"]="false";
13395
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
13396
		#$conf["userDir"]="true";
13397
		#參考資料來源:
13398
		#http://php.net/manual/en/function.file-exists.php
13399
		#http://php.net/manual/en/control-structures.foreach.php
13400
		#備註:
13401
		#函數file_exists檢查的路徑為檔案系統的路徑
13402
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
13403
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 13404
 
3 liveuser 13405
		#如果檢查檔案是否存在失敗
13406
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 13407
 
3 liveuser 13408
			#設置執行不正常
13409
			$result["status"]="false";
226 liveuser 13410
 
3 liveuser 13411
			#設置錯誤訊息
13412
			$result["error"]=$checkMultiFileExist;
226 liveuser 13413
 
3 liveuser 13414
			#回傳結果
13415
			return $result;
226 liveuser 13416
 
3 liveuser 13417
			}#if end
226 liveuser 13418
 
3 liveuser 13419
		#如果要解壓縮的檔案不存在
13420
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 13421
 
3 liveuser 13422
			#設置執行不正常
13423
			$result["status"]="false";
226 liveuser 13424
 
3 liveuser 13425
			#設置錯誤訊息
13426
			$result["error"]=$checkMultiFileExist;
226 liveuser 13427
 
3 liveuser 13428
			#回傳結果
13429
			return $result;
226 liveuser 13430
 
3 liveuser 13431
			}#if end
226 liveuser 13432
 
3 liveuser 13433
		#函式說明:
13434
		#呼叫shell執行系統命令,並取得回傳的內容.
13435
		#回傳結果:
13436
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13437
		#$result["error"],錯誤訊息陣列.
13438
		#$result["function"],當前執行的函數名稱.
13439
		#$result["argu"],使用的參數.
13440
		#$result["cmd"],執行的指令內容.
13441
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
13442
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
13443
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
13444
		#$result["running"],是否還在執行.
13445
		#$result["pid"],pid
13446
		#必填參數:
13447
		#$conf["command"],字串,要執行的指令與.
13448
		$conf["external::callShell"]["command"]="unzip";
13449
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 13450
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 13451
		#可省略參數:
13452
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
13453
		$conf["external::callShell"]["argu"]=array("-d",$conf["extract"],"-o","-q",$conf["zip"]);
13454
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
13455
		#$conf["arguIsAddr"]=array();
13456
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
13457
		#$conf["enablePrintDescription"]="true";
13458
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
13459
		#$conf["printDescription"]="";
13460
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
13461
		$conf["external::callShell"]["escapeshellarg"]="true";
13462
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
13463
		#$conf["username"]="";
13464
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
13465
		#$conf["password"]="";
13466
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
13467
		#$conf["useScript"]="";
13468
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
13469
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
13470
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
13471
		#$conf["inBackGround"]="";
13472
		#備註:
13473
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
13474
		#參考資料:
13475
		#exec=>http://php.net/manual/en/function.exec.php
13476
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
13477
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
13478
		$callShell=external::callShell($conf["external::callShell"]);
13479
		unset($conf["external::callShell"]);
226 liveuser 13480
 
3 liveuser 13481
		#如果執行cmd失敗
13482
		if($callShell["status"]==="false"){
226 liveuser 13483
 
3 liveuser 13484
			#設置執行不正常
13485
			$result["status"]="false";
226 liveuser 13486
 
3 liveuser 13487
			#設置錯誤訊息
13488
			$result["error"]=$callShell;
226 liveuser 13489
 
3 liveuser 13490
			#回傳結果
13491
			return $result;
226 liveuser 13492
 
3 liveuser 13493
			}#if end
226 liveuser 13494
 
3 liveuser 13495
		#函式說明:
13496
		#呼叫shell執行系統命令,並取得回傳的內容.
13497
		#回傳的結果:
13498
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13499
		#$result["error"],錯誤訊息陣列.
13500
		#$result["function"],當前執行的函數名稱.
13501
		#$result["argu"],使用的參數.
13502
		#$result["cmd"],執行的指令內容.
13503
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
13504
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
13505
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
13506
		#$result["running"],是否還在執行.
13507
		#$result["pid"],pid
13508
		#必填的參數
13509
		#$conf["command"],字串,要執行的指令與.
13510
		$conf["external::callShell"]["command"]="unzip";
13511
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 13512
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 13513
		#可省略參數:
13514
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
13515
		$conf["external::callShell"]["argu"]=array("-v",$conf["zip"]);
13516
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
13517
		#$conf["arguIsAddr"]=array();
13518
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
13519
		#$conf["enablePrintDescription"]="true";
13520
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
13521
		#$conf["printDescription"]="";
13522
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
13523
		$conf["external::callShell"]["escapeshellarg"]="true";
13524
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
13525
		#$conf["username"]="";
13526
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
13527
		#$conf["password"]="";
13528
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
13529
		#$conf["useScript"]="";
13530
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
13531
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
13532
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
13533
		#$conf["inBackGround"]="";
13534
		#備註:
13535
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
13536
		#參考資料:
13537
		#exec=>http://php.net/manual/en/function.exec.php
13538
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
13539
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
13540
		$callShell=external::callShell($conf["external::callShell"]);
13541
		unset($conf["external::callShell"]);
226 liveuser 13542
 
3 liveuser 13543
		#如果執行cmd失敗
13544
		if($callShell["status"]==="false"){
226 liveuser 13545
 
3 liveuser 13546
			#設置執行不正常
13547
			$result["status"]="false";
226 liveuser 13548
 
3 liveuser 13549
			#設置錯誤訊息
13550
			$result["error"]=$callShell;
226 liveuser 13551
 
3 liveuser 13552
			#回傳結果
13553
			return $result;
226 liveuser 13554
 
13555
			}#if end
13556
 
3 liveuser 13557
		#取得輸出的內容陣列
13558
		$unzipInfo=$callShell["output"];
226 liveuser 13559
 
3 liveuser 13560
		/*
226 liveuser 13561
 
3 liveuser 13562
		 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
13563
		--------  ------  ------- ---- ---------- ----- --------  ----
13564
		 4194304  Defl:X  2507269  40% 05-04-2002 17:30 9386a740  PS2 Bios 30004R V6 Pal.bin
13565
			   4  Defl:X        6 -50% 05-15-2005 06:45 054a6ec2  PS2 Bios 30004R V6 Pal.MEC
13566
			1024  Defl:X       22  98% 06-25-2005 14:55 3493bb06  PS2 Bios 30004R V6 Pal.NVM
13567
		  199680  Defl:X    70524  65% 06-02-2004 16:50 2c3bcd32  rom1.bin
13568
		 4194304  Defl:X  2637496  37% 02-20-2005 21:12 6f8e3c29  SCPH-70004_BIOS_V12_PAL_200.BIN
13569
		 3145728  Defl:X  3138427   0% 02-20-2005 21:12 bf3cbc65  SCPH-70004_BIOS_V12_PAL_200.EROM
13570
			1024  Defl:X      706  31% 02-20-2005 21:12 a8d51ead  SCPH-70004_BIOS_V12_PAL_200.NVM
13571
		  524288  Defl:X   149924  71% 02-20-2005 21:12 0e8797c0  SCPH-70004_BIOS_V12_PAL_200.ROM1
13572
		  524288  Defl:X   149924  71% 02-20-2005 21:12 0e8797c0  SCPH-70004_BIOS_V12_PAL_200.ROM2
13573
		 4194304  Defl:X  2213105  47% 10-18-2000 06:06 b7ef81a9  scph10000.bin
13574
			1024  Defl:X       11  99% 01-01-2005 00:42 efb5af2e  scph10000.NVM
13575
		 4194304  Defl:X  2511182  40% 06-27-2003 10:51 a19e0bf5  scph39001.bin
13576
			   4  Defl:X        6 -50% 05-14-2005 16:00 054a6ec2  scph39001.MEC
13577
			1024  Defl:X       20  98% 05-31-2005 16:09 e14a6cd6  scph39001.NVM
13578
		--------          -------  ---                            -------
13579
		21175304         13378622  37%                            14 files
226 liveuser 13580
 
3 liveuser 13581
		*/
226 liveuser 13582
 
3 liveuser 13583
		#取得行數
13584
		$lineCount=count($unzipInfo);
226 liveuser 13585
 
3 liveuser 13586
		#取得標題
13587
		#函式說明:
13588
		#將固定格式的字串分開,並回傳分開的結果。
13589
		#回傳結果:
13590
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13591
		#$result["error"],錯誤訊息陣列
13592
		#$result["function"],當前執行的函數名稱.
13593
		#$result["oriStr"],要分割的原始字串內容
13594
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13595
		#$result["dataCounts"],爲總共分成幾段
13596
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13597
		#必填參數:
13598
		$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[1];#要處理的字串。
13599
		$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13600
		#可省略參數:
13601
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13602
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13603
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13604
		unset($conf["stringProcess::spiltString"]);
226 liveuser 13605
 
3 liveuser 13606
		#如果分割字串失敗
13607
		if($spiltString["status"]==="false"){
226 liveuser 13608
 
3 liveuser 13609
			#設置執行不正常
13610
			$result["status"]="false";
226 liveuser 13611
 
3 liveuser 13612
			#設置錯誤訊息
13613
			$result["error"]=$spiltString;
226 liveuser 13614
 
3 liveuser 13615
			#回傳結果
13616
			return $result;
226 liveuser 13617
 
3 liveuser 13618
			}#if end
226 liveuser 13619
 
3 liveuser 13620
		#如果沒有分割用的關鍵字
13621
		if($spiltString["found"]==="false"){
226 liveuser 13622
 
3 liveuser 13623
			#設置執行不正常
13624
			$result["status"]="false";
226 liveuser 13625
 
3 liveuser 13626
			#設置錯誤訊息
13627
			$result["error"]=$spiltString;
226 liveuser 13628
 
3 liveuser 13629
			#回傳結果
13630
			return $result;
226 liveuser 13631
 
3 liveuser 13632
			}#if end
226 liveuser 13633
 
3 liveuser 13634
		#取得標題欄位
226 liveuser 13635
		$titles=$spiltString["dataArray"];
13636
 
3 liveuser 13637
		#取得標題欄位數目
13638
		$titleCount=$spiltString["dataCounts"];
226 liveuser 13639
 
3 liveuser 13640
		#針對每列輸出
13641
		for($i=3;$i<$lineCount-2;$i++){
226 liveuser 13642
 
3 liveuser 13643
			#取得各欄位的內容
13644
			#函式說明:
13645
			#將固定格式的字串分開,並回傳分開的結果。
13646
			#回傳結果:
13647
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13648
			#$result["error"],錯誤訊息陣列
13649
			#$result["function"],當前執行的函數名稱.
13650
			#$result["oriStr"],要分割的原始字串內容
13651
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13652
			#$result["dataCounts"],爲總共分成幾段
13653
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13654
			#必填參數:
13655
			$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[$i];#要處理的字串。
13656
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13657
			#可省略參數:
13658
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13659
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13660
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13661
			unset($conf["stringProcess::spiltString"]);
226 liveuser 13662
 
3 liveuser 13663
			#如果分割字串失敗
13664
			if($spiltString["status"]==="false"){
226 liveuser 13665
 
3 liveuser 13666
				#設置執行不正常
13667
				$result["status"]="false";
226 liveuser 13668
 
3 liveuser 13669
				#設置錯誤訊息
13670
				$result["error"]=$spiltString;
226 liveuser 13671
 
3 liveuser 13672
				#回傳結果
13673
				return $result;
226 liveuser 13674
 
3 liveuser 13675
				}#if end
226 liveuser 13676
 
3 liveuser 13677
			#如果沒有分割用的關鍵字
13678
			if($spiltString["found"]==="false"){
226 liveuser 13679
 
3 liveuser 13680
				#設置執行不正常
13681
				$result["status"]="false";
226 liveuser 13682
 
3 liveuser 13683
				#設置錯誤訊息
13684
				$result["error"]=$spiltString;
226 liveuser 13685
 
3 liveuser 13686
				#回傳結果
13687
				return $result;
226 liveuser 13688
 
3 liveuser 13689
				}#if end
226 liveuser 13690
 
3 liveuser 13691
			#取得各欄位的內容
13692
			$cols=$spiltString["dataArray"];
226 liveuser 13693
 
3 liveuser 13694
			#取得欄位的數目
13695
			$colsCount=$spiltString["dataCounts"];
226 liveuser 13696
 
3 liveuser 13697
			#如果實際抓出的內容欄位數量大於標題欄位數量,代表檔案/目錄名稱含有空格
13698
			if($colsCount>$titleCount){
226 liveuser 13699
 
3 liveuser 13700
				#新的檔案名稱
13701
				$newFileName="";
226 liveuser 13702
 
3 liveuser 13703
				#針對每個多出的欄位
13704
				for($j=$titleCount;$j<$colsCount;$j++){
226 liveuser 13705
 
3 liveuser 13706
					#串接屬於檔案名稱的部分
13707
					$newFileName=$newFileName.$cols[$j];
226 liveuser 13708
 
3 liveuser 13709
					#如果不是最後一個項目
13710
					if($j!==$colsCount-1){
226 liveuser 13711
 
3 liveuser 13712
						#增加空格
13713
						$newFileName=$newFileName." ";
226 liveuser 13714
 
3 liveuser 13715
						}#if end
226 liveuser 13716
 
3 liveuser 13717
					}#for end
226 liveuser 13718
 
3 liveuser 13719
				#取代成對的檔案名稱
13720
				$cols[$titleCount-1]=$newFileName;
226 liveuser 13721
 
3 liveuser 13722
				}#if end
226 liveuser 13723
 
3 liveuser 13724
			#針對每個欄位
13725
			for($j=0;$j<$titleCount;$j++){
226 liveuser 13726
 
3 liveuser 13727
				#取得欄位內容
13728
				$result["content"]["each"][$titles[$j]][]=$cols[$j];
226 liveuser 13729
 
3 liveuser 13730
				}#for end
226 liveuser 13731
 
3 liveuser 13732
			}#for end
226 liveuser 13733
 
3 liveuser 13734
		#取得 total 的輸出內容
13735
		#函式說明:
13736
		#將固定格式的字串分開,並回傳分開的結果。
13737
		#回傳結果:
13738
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13739
		#$result["error"],錯誤訊息陣列
13740
		#$result["function"],當前執行的函數名稱.
13741
		#$result["oriStr"],要分割的原始字串內容
13742
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13743
		#$result["dataCounts"],爲總共分成幾段
13744
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13745
		#必填參數:
13746
		$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[$lineCount-1];#要處理的字串。
13747
		$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13748
		#可省略參數:
13749
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13750
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13751
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13752
		unset($conf["stringProcess::spiltString"]);
226 liveuser 13753
 
3 liveuser 13754
		#如果分割字串失敗
13755
		if($spiltString["status"]==="false"){
226 liveuser 13756
 
3 liveuser 13757
			#設置執行不正常
13758
			$result["status"]="false";
226 liveuser 13759
 
3 liveuser 13760
			#設置錯誤訊息
13761
			$result["error"]=$spiltString;
226 liveuser 13762
 
3 liveuser 13763
			#回傳結果
13764
			return $result;
226 liveuser 13765
 
3 liveuser 13766
			}#if end
226 liveuser 13767
 
3 liveuser 13768
		#如果沒有分割用的關鍵字
13769
		if($spiltString["found"]==="false"){
226 liveuser 13770
 
3 liveuser 13771
			#設置執行不正常
13772
			$result["status"]="false";
226 liveuser 13773
 
3 liveuser 13774
			#設置錯誤訊息
13775
			$result["error"]=$spiltString;
226 liveuser 13776
 
3 liveuser 13777
			#回傳結果
13778
			return $result;
226 liveuser 13779
 
3 liveuser 13780
			}#if end
226 liveuser 13781
 
3 liveuser 13782
		#取得各欄位的內容
13783
		$cols=$spiltString["dataArray"];
226 liveuser 13784
 
3 liveuser 13785
		#取得總共的檔案長度
13786
		$result["content"]["total"][$titles[0]]=$cols[0];
226 liveuser 13787
 
3 liveuser 13788
		#取得壓縮時的總共檔案長度
13789
		$result["content"]["total"][$titles[2]]=$cols[1];
226 liveuser 13790
 
3 liveuser 13791
		#取得壓縮時的總共檔案長度
13792
		$result["content"]["total"][$titles[3]]=$cols[2];
226 liveuser 13793
 
3 liveuser 13794
		#取得解壓縮出了多少檔案跟目錄
13795
		$result["content"]["total"]["count"]=explode(" ",$cols[3])[0];
226 liveuser 13796
 
3 liveuser 13797
		#設置執行正常
13798
		$result["status"]="true";
226 liveuser 13799
 
3 liveuser 13800
		#回傳結果
13801
		return $result;
226 liveuser 13802
 
3 liveuser 13803
		}#function unzip end
226 liveuser 13804
 
3 liveuser 13805
	/*
13806
	#函式說明:
13807
	#接收Range: bytes=0-499格式的header, 輸出檔案的片段或完整檔案.
13808
	#回傳結果:
13809
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13810
	#$result["error"],錯誤訊息.
13811
	#$result["function"],當前執行的函式名稱.
13812
	#必填參數:
13813
	#$conf["filePath"],字串,檔案的路徑.
13814
	$conf["filePath"]="";
13815
	#可省略參數:
13816
	#$conf["fileName"],字串,顯示的檔案名稱,預設為basename($conf["filePath"]);
13817
	#$conf["fileName"]="";
13818
	#參考資料:
13819
	#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/
13820
	#http://php.net/manual/en/function.filemtime.php
13821
	#http://php.net/manual/en/function.connection-status.php
13822
	#http://php.net/manual/en/function.fread.php
13823
	#備註:
13824
	#請勿在運行該函式前印出任何內容,這是要給用戶端接收的內容.
13825
	*/
13826
	public static function partDownload(&$conf=array()){
226 liveuser 13827
 
3 liveuser 13828
		#初始化要回傳的結果
13829
		$result=array();
13830
 
13831
		#取得當前執行的函數名稱
13832
		$result["function"]=__FUNCTION__;
13833
 
13834
		#如果沒有參數
13835
		if(func_num_args()==0){
226 liveuser 13836
 
3 liveuser 13837
			#設置執行失敗
13838
			$result["status"]="false";
226 liveuser 13839
 
3 liveuser 13840
			#設置執行錯誤訊息
13841
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 13842
 
3 liveuser 13843
			#回傳結果
13844
			return $result;
226 liveuser 13845
 
3 liveuser 13846
		}#if end
226 liveuser 13847
 
3 liveuser 13848
		#取得參數
13849
		$result["argu"]=$conf;
13850
 
13851
		#如果 $conf 不為陣列
13852
		if(gettype($conf)!=="array"){
226 liveuser 13853
 
3 liveuser 13854
			#設置執行失敗
13855
			$result["status"]="false";
226 liveuser 13856
 
3 liveuser 13857
			#設置執行錯誤訊息
13858
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 13859
 
3 liveuser 13860
			#如果傳入的參數為 null
13861
			if($conf===null){
226 liveuser 13862
 
3 liveuser 13863
				#設置執行錯誤訊息
13864
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 13865
 
3 liveuser 13866
				}#if end
13867
 
13868
			#回傳結果
13869
			return $result;
226 liveuser 13870
 
3 liveuser 13871
			}#if end
226 liveuser 13872
 
3 liveuser 13873
		#檢查參數
13874
		#函式說明:
13875
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13876
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13877
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13878
		#$result["function"],當前執行的函式名稱.
13879
		#$result["argu"],設置給予的參數.
13880
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13881
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13882
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13883
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13884
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13885
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13886
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13887
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13888
		#必填寫的參數:
13889
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 13890
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 13891
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13892
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13893
		#可以省略的參數:
13894
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13895
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePath");
13896
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13897
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
13898
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13899
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
13900
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13901
		#$conf["canNotBeEmpty"]=array();
13902
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13903
		#$conf["canBeEmpty"]=array();
13904
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13905
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("fileName");
13906
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13907
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileName");
226 liveuser 13908
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 13909
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
13910
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13911
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
13912
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
13913
		#$conf["disallowAllSkipableVarIsEmpty"]="";
13914
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
13915
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
13916
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13917
		#$conf["arrayCountEqualCheck"][]=array();
13918
		#參考資料來源:
13919
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13920
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
13921
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 13922
 
3 liveuser 13923
		#如果檢查參數失敗
13924
		if($checkArguments["status"]==="false"){
226 liveuser 13925
 
3 liveuser 13926
			#設置執行失敗
13927
			$result["status"]="false";
226 liveuser 13928
 
3 liveuser 13929
			#設置執行錯誤
13930
			$result["error"]=$checkArguments;
226 liveuser 13931
 
3 liveuser 13932
			#回傳結果
13933
			return $result;
226 liveuser 13934
 
3 liveuser 13935
			}#if end
226 liveuser 13936
 
3 liveuser 13937
		#如果檢查參數不通過
13938
		if($checkArguments["passed"]==="false"){
226 liveuser 13939
 
3 liveuser 13940
			#設置執行失敗
13941
			$result["status"]="false";
226 liveuser 13942
 
3 liveuser 13943
			#設置執行錯誤
13944
			$result["error"]=$checkArguments;
226 liveuser 13945
 
3 liveuser 13946
			#回傳結果
13947
			return $result;
226 liveuser 13948
 
3 liveuser 13949
			}#if end
226 liveuser 13950
 
3 liveuser 13951
		#如果沒有設置 $conf["fileName"]
13952
		if(!isset($conf["fileName"])){
226 liveuser 13953
 
3 liveuser 13954
			#取得檔案名稱
13955
			$filename=basename($conf["filePath"]);
226 liveuser 13956
 
3 liveuser 13957
			}#if end
226 liveuser 13958
 
3 liveuser 13959
		#反之
13960
		else{
226 liveuser 13961
 
3 liveuser 13962
			#取得設定好的檔案名稱
13963
			$filename=&$conf["fileName"];
226 liveuser 13964
 
3 liveuser 13965
			}#else end
226 liveuser 13966
 
3 liveuser 13967
		#取得檔案路徑
13968
		$location=$conf["filePath"];
13969
 
13970
		#取得mimetype
13971
		$mimetype=mime_content_type($location);
226 liveuser 13972
 
3 liveuser 13973
		#如果檔案不存在
13974
		if(!file_exists($location)){
226 liveuser 13975
 
3 liveuser 13976
			#提示找不到檔案
13977
			header("HTTP/1.1 404 Not Found");
226 liveuser 13978
 
3 liveuser 13979
			#設置執行失敗
13980
			$result["status"]="false";
226 liveuser 13981
 
3 liveuser 13982
			#設置錯誤訊息
13983
			$result["error"][]="檔案 ".$location." 不存在.";
226 liveuser 13984
 
3 liveuser 13985
			#回傳結果
13986
			return $result;
226 liveuser 13987
 
3 liveuser 13988
			}#if end
13989
 
13990
		#取得檔案的bytes長度
13991
		$size  = filesize($location);
226 liveuser 13992
 
3 liveuser 13993
		#取得檔案的最後變更日期
13994
		$time  = date('r', filemtime($location));
13995
 
13996
		#讀取檔案的2元碼內容
13997
		$fm = @fopen($location, 'rb');
226 liveuser 13998
 
3 liveuser 13999
		#如果開啟檔案失敗
14000
		if(!$fm){
226 liveuser 14001
 
3 liveuser 14002
			#提示錯誤
14003
			header("HTTP/1.1 505 Internal server error");
226 liveuser 14004
 
3 liveuser 14005
			#設置執行失敗
14006
			$result["status"]="false";
226 liveuser 14007
 
3 liveuser 14008
			#設置錯誤訊息
14009
			$result["error"][]="開啟檔案 ".$location." 失敗.";
226 liveuser 14010
 
3 liveuser 14011
			#回傳結果
14012
			return $result;
226 liveuser 14013
 
3 liveuser 14014
			}#if end
14015
 
14016
		#初始化要提供的bytes長度起始點
14017
		$begin  = 0;
226 liveuser 14018
 
3 liveuser 14019
		#初始化要提供的bytes長度結束點
14020
		$end  = $size - 1;
14021
 
14022
		#如果有接收到 'HTTP_RANGE' 的 header 訊息
14023
		if(isset($_SERVER['HTTP_RANGE'])){
226 liveuser 14024
 
3 liveuser 14025
			#接收到的範例
226 liveuser 14026
			#Range: bytes=0-499
14027
 
3 liveuser 14028
			#取得要求的bytes位置範圍
14029
			sscanf($_SERVER['HTTP_RANGE'], "bytes=%d-%d",$begin,$end);
226 liveuser 14030
 
3 liveuser 14031
			#如果 $begin 或 $end  有缺
14032
			if(!isset($begin) || !isset($end)){
226 liveuser 14033
 
3 liveuser 14034
				#設置執行失敗
14035
				$result["status"]="false";
226 liveuser 14036
 
3 liveuser 14037
				#設置錯誤訊息
14038
				$result["error"][]="header \"Range\" 的數值格式為 \"bytes=0-499\"";
226 liveuser 14039
 
3 liveuser 14040
				#回傳結果
14041
				return $result;
226 liveuser 14042
 
3 liveuser 14043
				}#if end
226 liveuser 14044
 
3 liveuser 14045
			#如果 $begin 沒有小於等於 $end
14046
			if(!($begin<=$end)){
226 liveuser 14047
 
3 liveuser 14048
				#設置執行失敗
14049
				$result["status"]="false";
226 liveuser 14050
 
3 liveuser 14051
				#設置錯誤訊息
14052
				$result["error"][]="header \"Range\" 的數值格式為 \"bytes=0-499\"";
226 liveuser 14053
 
3 liveuser 14054
				#回傳結果
14055
				return $result;
226 liveuser 14056
 
3 liveuser 14057
				}#if end
226 liveuser 14058
 
3 liveuser 14059
			}#if end
226 liveuser 14060
 
3 liveuser 14061
		#提示 200 ok
14062
		header('HTTP/1.1 200 OK');
226 liveuser 14063
 
3 liveuser 14064
		#提示 mimetype
14065
		header("Content-Type: $mimetype");
226 liveuser 14066
 
3 liveuser 14067
		#要先驗證cache中的資料,取得的內容放在快取的時間為0
14068
		header('Cache-Control: public, must-revalidate, max-age=0');
226 liveuser 14069
 
3 liveuser 14070
		#提示不要cache
226 liveuser 14071
		header('Pragma: no-cache');
14072
 
3 liveuser 14073
		#提示接收的 Ranges 單位為 bytes
14074
		header('Accept-Ranges: bytes');
226 liveuser 14075
 
3 liveuser 14076
		#數值傳輸的內容長度為多少
14077
		header('Content-Length:' . (($end - $begin) + 1));
226 liveuser 14078
 
3 liveuser 14079
		#提示內容為檔案的哪邊到哪邊與總共的長度
14080
		header("Content-Range: bytes $begin-$end/$size");
226 liveuser 14081
 
3 liveuser 14082
		#提示檔案的名稱
14083
		header("Content-Disposition: inline; filename=$filename");
226 liveuser 14084
 
3 liveuser 14085
		#提示用2元碼傳輸
14086
		header("Content-Transfer-Encoding: binary");
226 liveuser 14087
 
3 liveuser 14088
		#提示檔案最後變更日期
14089
		header("Last-Modified: $time");
14090
 
14091
		#初始化當前位置
14092
		$cur  = $begin;
226 liveuser 14093
 
14094
		#指定讀取的起始點為 $begin
3 liveuser 14095
		fseek($fm, $begin, 0);
14096
 
14097
		#讀取內容, 若不是檔案結尾, 且當前位置($cur)小於等於 本次要提供的長度結尾($end), 且connection_status為0
14098
		while(!feof($fm) && $cur<=$end && (connection_status()===0)){
226 liveuser 14099
 
3 liveuser 14100
			#一次最多印出 1024*16bytes 的長度,若剩下長度不足則只印出剩下的長度.
14101
			echo fread($fm, min(1024 * 16, ($end - $cur) + 1));
226 liveuser 14102
 
3 liveuser 14103
			#更改位置
14104
			$cur += 1024 * 16;
226 liveuser 14105
 
3 liveuser 14106
			}#while end
226 liveuser 14107
 
3 liveuser 14108
		}#function partDownload end
226 liveuser 14109
 
3 liveuser 14110
	/*
14111
	#函式說明:
226 liveuser 14112
	#尋找檔案.
3 liveuser 14113
	#回傳結果:
14114
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14115
	#$result["error"],錯誤訊息.
14116
	#$result["warning"],警告訊息陣列.
14117
	#$result["function"],當前執行的函數名稱.
14118
	#$result["argu"],所使用的參數.
14119
	#$result["found"],是否有找到可以轉換的檔案,"true"代表有;"false"代表沒有.
14120
	#$result["content"],找到的檔案陣列.
14121
	#必填參數:
14122
	#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
14123
	$conf["keyWord"]="";
14124
	#$conf["path"],字串陣列,虛擬硬碟檔案的搜尋路徑,預設為當前路徑.
14125
	$conf["path"]=array();
14126
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14127
	$conf["fileArgu"]=__FILE__;
14128
	#參考資料:
14129
	#http://php.net/manual/en/function.glob.php
14130
	#備註:
14131
	#無.
14132
	*/
14133
	public static function findFile(&$conf=array()){
226 liveuser 14134
 
3 liveuser 14135
		#初始化要回傳的結果
14136
		$result=array();
14137
 
14138
		#取得當前執行的函數名稱
14139
		$result["function"]=__FUNCTION__;
14140
 
14141
		#如果沒有參數
14142
		if(func_num_args()==0){
226 liveuser 14143
 
3 liveuser 14144
			#設置執行失敗
14145
			$result["status"]="false";
226 liveuser 14146
 
3 liveuser 14147
			#設置執行錯誤訊息
14148
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14149
 
3 liveuser 14150
			#回傳結果
14151
			return $result;
14152
 
226 liveuser 14153
			}#if end
14154
 
3 liveuser 14155
		#取得參數
14156
		$result["argu"]=$conf;
14157
 
14158
		#如果 $conf 不為陣列
14159
		if(gettype($conf)!=="array"){
226 liveuser 14160
 
3 liveuser 14161
			#設置執行失敗
14162
			$result["status"]="false";
226 liveuser 14163
 
3 liveuser 14164
			#設置執行錯誤訊息
14165
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14166
 
3 liveuser 14167
			#如果傳入的參數為 null
14168
			if($conf===null){
226 liveuser 14169
 
3 liveuser 14170
				#設置執行錯誤訊息
14171
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14172
 
3 liveuser 14173
				}#if end
14174
 
14175
			#回傳結果
14176
			return $result;
226 liveuser 14177
 
3 liveuser 14178
			}#if end
226 liveuser 14179
 
3 liveuser 14180
		#函式說明:
14181
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14182
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14183
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14184
		#$result["function"],當前執行的函式名稱.
14185
		#$result["argu"],設置給予的參數.
14186
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14187
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14188
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14189
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14190
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14191
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14192
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14193
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14194
		#必填寫的參數:
14195
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14196
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14197
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14198
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14199
		#可以省略的參數:
14200
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14201
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","keyWord","fileArgu");
14202
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14203
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
14204
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14205
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14206
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14207
		#$conf["canNotBeEmpty"]=array();
14208
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14209
		#$conf["canBeEmpty"]=array();
14210
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14211
		#$conf["skipableVariableCanNotBeEmpty"]=array();
14212
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14213
		#$conf["skipableVariableName"]=array();
226 liveuser 14214
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14215
		#$conf["skipableVariableType"]=array();
14216
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14217
		#$conf["skipableVarDefaultValue"]=array("");
14218
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14219
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14220
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14221
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14222
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14223
		#$conf["arrayCountEqualCheck"][]=array();
14224
		#參考資料來源:
14225
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14226
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14227
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14228
 
3 liveuser 14229
		#如果檢查參數失敗
14230
		if($checkArguments["status"]==="false"){
226 liveuser 14231
 
3 liveuser 14232
			#設置執行失敗
14233
			$result["status"]="false";
226 liveuser 14234
 
3 liveuser 14235
			#設置執行失敗訊息
14236
			$result["error"]=$checkArguments;
226 liveuser 14237
 
3 liveuser 14238
			#回傳結果
14239
			return $result;
226 liveuser 14240
 
3 liveuser 14241
			}#if end
226 liveuser 14242
 
3 liveuser 14243
		#如果檢查參數不通過
14244
		if($checkArguments["passed"]==="false"){
226 liveuser 14245
 
3 liveuser 14246
			#設置執行失敗
14247
			$result["status"]="false";
226 liveuser 14248
 
3 liveuser 14249
			#設置執行失敗訊息
14250
			$result["error"]=$checkArguments;
226 liveuser 14251
 
3 liveuser 14252
			#回傳結果
14253
			return $result;
226 liveuser 14254
 
3 liveuser 14255
			}#if end
226 liveuser 14256
 
3 liveuser 14257
		#檢查要搜尋的路徑是否都存在
14258
		#函式說明:
14259
		#s檢查多個檔案與資料夾是否存在.
14260
		#回傳的結果:
14261
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
14262
		#$result["error"],錯誤訊息陣列.
14263
		#$resutl["function"],當前執行的涵式名稱.
14264
		#$result["argu"],使用的參數.
14265
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
14266
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
14267
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
14268
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
14269
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
14270
		#必填參數:
14271
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
14272
		$conf["self::checkMultiFileExist"]["fileArray"]=$conf["path"];
14273
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14274
		$conf["self::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
14275
		#可省略參數
14276
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
14277
		#$conf["disableWebSearch"]="false";
14278
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
14279
		#$conf["userDir"]="true";
14280
		#參考資料來源:
14281
		#http://php.net/manual/en/function.file-exists.php
14282
		#http://php.net/manual/en/control-structures.foreach.php
14283
		#備註:
14284
		#函數file_exists檢查的路徑為檔案系統的路徑
14285
		$checkMultiFileExist=self::checkMultiFileExist($conf["self::checkMultiFileExist"]);
14286
		unset($conf["self::checkMultiFileExist"]);
226 liveuser 14287
 
3 liveuser 14288
		#如果檢查目錄存在失敗
14289
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 14290
 
3 liveuser 14291
			#設置執行失敗
14292
			$result["status"]="false";
226 liveuser 14293
 
3 liveuser 14294
			#設置執行失敗訊息
14295
			$result["error"]=$checkMultiFileExist;
226 liveuser 14296
 
3 liveuser 14297
			#回傳結果
14298
			return $result;
226 liveuser 14299
 
14300
			}#if end
14301
 
3 liveuser 14302
		#如果目錄不存在
14303
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 14304
 
3 liveuser 14305
			#設置執行失敗
14306
			$result["status"]="false";
226 liveuser 14307
 
3 liveuser 14308
			#設置執行失敗訊息
14309
			$result["error"]=$checkMultiFileExist;
226 liveuser 14310
 
3 liveuser 14311
			#回傳結果
14312
			return $result;
226 liveuser 14313
 
3 liveuser 14314
			}#if end
226 liveuser 14315
 
3 liveuser 14316
		#如果有路徑不存在
14317
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 14318
 
3 liveuser 14319
			#設置執行失敗
14320
			$result["status"]="false";
226 liveuser 14321
 
3 liveuser 14322
			#設置執行失敗訊息
14323
			$result["error"]=$checkMultiFileExist;
226 liveuser 14324
 
3 liveuser 14325
			#設置提示有路徑不存在的訊息
14326
			$result["warning"][]="參數path的路徑沒有每個都存在";
226 liveuser 14327
 
3 liveuser 14328
			#回傳結果
14329
			return $result;
226 liveuser 14330
 
3 liveuser 14331
			}#if end
226 liveuser 14332
 
3 liveuser 14333
		#預設沒有找到檔案
226 liveuser 14334
		$result["found"]="false";
14335
 
3 liveuser 14336
		#針對每個要搜尋的路徑
14337
		foreach($conf["path"] as $path){
226 liveuser 14338
 
3 liveuser 14339
			#函式說明:
14340
			#用find指令尋找檔案
14341
			#回傳結果:
14342
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14343
			#$result["error"],錯誤訊息.
14344
			#$result["function"],當前執行的函數名稱.
14345
			#$result["argu"],所使用的參數.
14346
			#$result["found"],是否有找到符合的檔案,"true"代表有;"false"代表沒有.
14347
			#$result["content"],找到的檔案陣列.
14348
			#必填參數:
14349
			#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
226 liveuser 14350
			$conf["cmd::find"]["keyWord"]=$conf["keyWord"];
3 liveuser 14351
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14352
			$conf["cmd::find"]["fileArgu"]=$conf["fileArgu"];
14353
			#可省略參數:
14354
			#$conf["path"],字串,搜尋的路徑,預設為"/".
14355
			$conf["cmd::find"]["path"]=$path;
14356
			#$conf["fileOnly"],字串,"true"代表只要找檔案,"false"代表.
14357
			$conf["cmd::find"]["fileOnly"]="true";
14358
			#參考資料:
14359
			#http://php.net/manual/en/function.glob.php
14360
			$find=cmd::find($conf["cmd::find"]);
14361
			unset($conf["cmd::find"]);
226 liveuser 14362
 
3 liveuser 14363
			#如果尋找檔案失敗
14364
			if($find["status"]==="false"){
226 liveuser 14365
 
3 liveuser 14366
				#設置執行失敗
14367
				$result["status"]="false";
226 liveuser 14368
 
3 liveuser 14369
				#設置執行失敗訊息
14370
				$result["error"]=$find;
226 liveuser 14371
 
3 liveuser 14372
				#回傳結果
14373
				return $result;
226 liveuser 14374
 
3 liveuser 14375
				}#if end
226 liveuser 14376
 
3 liveuser 14377
			#如果有找到符合的檔案
14378
			if($find["found"]==="true"){
226 liveuser 14379
 
3 liveuser 14380
				#設置有找到檔案
14381
				$result["found"]="true";
226 liveuser 14382
 
3 liveuser 14383
				#針對每個找到的檔案
14384
				foreach($find["content"] as $filtedFile){
226 liveuser 14385
 
3 liveuser 14386
					#設置有找到的檔案
14387
					$result["content"][]=$filtedFile;
226 liveuser 14388
 
3 liveuser 14389
					}#foreach end
226 liveuser 14390
 
3 liveuser 14391
				}#if end
226 liveuser 14392
 
14393
			}#foreach end
14394
 
3 liveuser 14395
		#設置執行正常
14396
		$result["status"]="true";
226 liveuser 14397
 
3 liveuser 14398
		#回傳結果
14399
		return $result;
226 liveuser 14400
 
3 liveuser 14401
		}#function findFile end
14402
 
14403
	/*
14404
	#函式說明:
14405
	#判斷檔案位於哪個分割區
14406
	#回傳結果:
14407
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14408
	#$result["error"],錯誤訊息.
14409
	#$result["function"],當前執行的函數名稱.
14410
	#$result["argu"],所使用的參數.
14411
	#$result["content"],找到的檔案所屬分割區資訊.
14412
	#必填參數:
14413
	#$conf["file"],字串,檔案的路徑與名稱.
14414
	$conf["file"]="";
14415
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14416
	$conf["fileArgu"]=__FILE__;
14417
	#可省略參數:
14418
	#無.
14419
	#參考資料:
14420
	#無.
14421
	#備註:
14422
	#無.
14423
	*/
14424
	public static function addrInMountPoint(&$conf=array()){
226 liveuser 14425
 
3 liveuser 14426
		#初始化要回傳的結果
14427
		$result=array();
14428
 
14429
		#取得當前執行的函數名稱
14430
		$result["function"]=__FUNCTION__;
14431
 
14432
		#如果沒有參數
14433
		if(func_num_args()==0){
226 liveuser 14434
 
3 liveuser 14435
			#設置執行失敗
14436
			$result["status"]="false";
226 liveuser 14437
 
3 liveuser 14438
			#設置執行錯誤訊息
14439
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14440
 
3 liveuser 14441
			#回傳結果
14442
			return $result;
14443
 
226 liveuser 14444
			}#if end
14445
 
3 liveuser 14446
		#取得參數
14447
		$result["argu"]=$conf;
14448
 
14449
		#如果 $conf 不為陣列
14450
		if(gettype($conf)!=="array"){
226 liveuser 14451
 
3 liveuser 14452
			#設置執行失敗
14453
			$result["status"]="false";
226 liveuser 14454
 
3 liveuser 14455
			#設置執行錯誤訊息
14456
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14457
 
3 liveuser 14458
			#如果傳入的參數為 null
14459
			if($conf===null){
226 liveuser 14460
 
3 liveuser 14461
				#設置執行錯誤訊息
14462
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14463
 
3 liveuser 14464
				}#if end
14465
 
14466
			#回傳結果
14467
			return $result;
226 liveuser 14468
 
3 liveuser 14469
			}#if end
226 liveuser 14470
 
3 liveuser 14471
		#函式說明:
14472
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14473
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14474
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14475
		#$result["function"],當前執行的函式名稱.
14476
		#$result["argu"],設置給予的參數.
14477
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14478
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14479
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14480
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14481
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14482
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14483
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14484
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14485
		#必填寫的參數:
14486
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14487
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14488
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14489
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14490
		#可以省略的參數:
14491
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14492
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
14493
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14494
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
14495
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14496
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14497
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14498
		#$conf["canNotBeEmpty"]=array();
14499
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14500
		#$conf["canBeEmpty"]=array();
14501
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14502
		#$conf["skipableVariableCanNotBeEmpty"]=array();
14503
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14504
		#$conf["skipableVariableName"]=array();
226 liveuser 14505
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14506
		#$conf["skipableVariableType"]=array();
14507
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14508
		#$conf["skipableVarDefaultValue"]=array("");
14509
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14510
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14511
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14512
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14513
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14514
		#$conf["arrayCountEqualCheck"][]=array();
14515
		#參考資料來源:
14516
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14517
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14518
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14519
 
3 liveuser 14520
		#如果檢查參數失敗
14521
		if($checkArguments["status"]==="false"){
226 liveuser 14522
 
3 liveuser 14523
			#設置執行失敗
14524
			$result["status"]="false";
226 liveuser 14525
 
3 liveuser 14526
			#設置執行失敗訊息
14527
			$result["error"]=$checkArguments;
226 liveuser 14528
 
3 liveuser 14529
			#回傳結果
14530
			return $result;
226 liveuser 14531
 
3 liveuser 14532
			}#if end
226 liveuser 14533
 
3 liveuser 14534
		#如果檢查參數不通過
14535
		if($checkArguments["passed"]==="false"){
226 liveuser 14536
 
3 liveuser 14537
			#設置執行失敗
14538
			$result["status"]="false";
226 liveuser 14539
 
3 liveuser 14540
			#設置執行失敗訊息
14541
			$result["error"]=$checkArguments;
226 liveuser 14542
 
3 liveuser 14543
			#回傳結果
14544
			return $result;
226 liveuser 14545
 
3 liveuser 14546
			}#if end
226 liveuser 14547
 
3 liveuser 14548
		#函式說明:
14549
		#透過lsblk指令的輸出取得已經掛載的blk.
14550
		#回傳結果:
14551
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14552
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14553
		#$result["function"],當前執行的函式名稱.
14554
		#$result["content"],lsblk的輸出內容.
14555
		#必填參數:
14556
		#$conf["fileArgu"],字串,變數__FILE__的內容.
14557
		$conf["cmd::lsblk"]["fileArgu"]=$conf["fileArgu"];
14558
		#可省略參數:
226 liveuser 14559
		#無.
3 liveuser 14560
		$lsblk=cmd::lsblk($conf["cmd::lsblk"]);
14561
		unset($conf["cmd::lsblk"]);
226 liveuser 14562
 
3 liveuser 14563
		#如果執行失敗
14564
		if($lsblk["status"]==="false"){
226 liveuser 14565
 
3 liveuser 14566
			#設置執行失敗
14567
			$result["status"]="false";
226 liveuser 14568
 
3 liveuser 14569
			#設置執行失敗訊息
14570
			$result["error"]=$lsblk;
226 liveuser 14571
 
3 liveuser 14572
			#回傳結果
14573
			return $result;
226 liveuser 14574
 
3 liveuser 14575
			}#if end
226 liveuser 14576
 
3 liveuser 14577
		#將 $conf["file"] 轉換成絕對路徑
14578
		#函式說明:
14579
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
14580
		#回傳結果:
14581
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
14582
		#$result["error"],錯誤訊息陣列.
226 liveuser 14583
		#$result["function"],函數名稱.
3 liveuser 14584
		#$result["argu"],使用的參數.
14585
		#$result["content"],網址,若是在命令列執行,則為"null".
14586
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
14587
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
14588
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
14589
		#必填參數:
14590
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
14591
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["file"];
14592
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
14593
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
14594
		#可省略參數:
14595
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
14596
		#$conf["userDir"]="true";
14597
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
14598
		unset($conf["fileAccess::getInternetAddress"]);
226 liveuser 14599
 
3 liveuser 14600
		#如果執行失敗
14601
		if($getInternetAddress["status"]==="false"){
226 liveuser 14602
 
3 liveuser 14603
			#設置執行失敗
14604
			$result["status"]="false";
226 liveuser 14605
 
3 liveuser 14606
			#設置執行失敗訊息
14607
			$result["error"]=$getInternetAddress;
226 liveuser 14608
 
3 liveuser 14609
			#回傳結果
14610
			return $result;
226 liveuser 14611
 
14612
			}#if end
14613
 
3 liveuser 14614
		#使用絕對位置作為輸入字串
14615
		#函式說明:
14616
		#尋找字串是否存在對應的關鍵字,且符合的最常關鍵字為何?
14617
		#回傳結果:
14618
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14619
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14620
		#$result["function"],當前執行的函式名稱.
14621
		#$result["argu"],所使用的參數.
14622
		#$result["founded"],是否有找到關鍵字,"true"代表有找到,"false"代表沒有找到.
14623
		#$result["content"],最符合的字串完整內容.
14624
		#必填參數:
14625
		#$conf["input"],字串,要比對的字串陣列.
14626
		$conf["search::findLikelyStr"]["input"]=$getInternetAddress["fileSystemAbsoulutePosition"];
14627
		#$conf["keyWord"],字串陣列,要搜尋的關鍵字.
14628
		$conf["search::findLikelyStr"]["keyWord"]=$lsblk["content"]["MOUNTPOINT"];
14629
		$findLikelyStr=search::findLikelyStr($conf["search::findLikelyStr"]);
14630
		unset($conf["search::findLikelyStr"]);
226 liveuser 14631
 
3 liveuser 14632
		#如果執行失敗
14633
		if($findLikelyStr["status"]==="false"){
226 liveuser 14634
 
3 liveuser 14635
			#設置執行失敗
14636
			$result["status"]="false";
226 liveuser 14637
 
3 liveuser 14638
			#設置執行失敗訊息
14639
			$result["error"]=$findLikelyStr;
226 liveuser 14640
 
3 liveuser 14641
			#回傳結果
14642
			return $result;
226 liveuser 14643
 
3 liveuser 14644
			}#if end
226 liveuser 14645
 
3 liveuser 14646
		#如果找不到歸屬的分割區
14647
		if($findLikelyStr["found"]==="false"){
226 liveuser 14648
 
3 liveuser 14649
			#設置執行失敗
14650
			$result["status"]="false";
226 liveuser 14651
 
3 liveuser 14652
			#設置執行失敗訊息
14653
			$result["error"]=$findLikelyStr;
226 liveuser 14654
 
3 liveuser 14655
			#回傳結果
14656
			return $result;
226 liveuser 14657
 
3 liveuser 14658
			}#if end
226 liveuser 14659
 
3 liveuser 14660
		#設置歸屬的分割區資訊
14661
		$result["content"]=$findLikelyStr["content"];
226 liveuser 14662
 
3 liveuser 14663
		#設置執行正常
14664
		$result["status"]="true";
226 liveuser 14665
 
3 liveuser 14666
		#回傳結果
14667
		return $result;
226 liveuser 14668
 
3 liveuser 14669
		}#function addrInMountPoint end
14670
 
14671
	/*
14672
	#函式說明:
14673
	#取得檔案的副檔名
14674
	#回傳結果:
14675
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14676
	#$result["error"],錯誤訊息.
14677
	#$result["function"],當前執行的函數名稱.
226 liveuser 14678
	#$result["argu"],所使用的參數.
3 liveuser 14679
	#$result["content"],副檔名.
14680
	#$result["name"],不含副檔的名稱.
14681
	#$result["fullName"],含副檔的名稱.
14682
	#$result["path"],檔案所處的路徑.
14683
	#必填參數:
14684
	#$conf["file"],字串,檔案的路徑與名稱.
14685
	$conf["file"]="";
14686
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14687
	$conf["fileArgu"]=__FILE__;
14688
	#可省略參數:
14689
	#無.
14690
	#參考資料:
14691
	#無.
14692
	#備註:
14693
	#無.
14694
	*/
14695
	public static function getExtension(&$conf=array()){
226 liveuser 14696
 
3 liveuser 14697
		#初始化要回傳的結果
14698
		$result=array();
14699
 
14700
		#取得當前執行的函數名稱
14701
		$result["function"]=__FUNCTION__;
14702
 
14703
		#如果沒有參數
14704
		if(func_num_args()==0){
226 liveuser 14705
 
3 liveuser 14706
			#設置執行失敗
14707
			$result["status"]="false";
226 liveuser 14708
 
3 liveuser 14709
			#設置執行錯誤訊息
14710
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14711
 
3 liveuser 14712
			#回傳結果
14713
			return $result;
14714
 
226 liveuser 14715
			}#if end
14716
 
3 liveuser 14717
		#取得參數
14718
		$result["argu"]=$conf;
14719
 
14720
		#如果 $conf 不為陣列
14721
		if(gettype($conf)!=="array"){
226 liveuser 14722
 
3 liveuser 14723
			#設置執行失敗
14724
			$result["status"]="false";
226 liveuser 14725
 
3 liveuser 14726
			#設置執行錯誤訊息
14727
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14728
 
3 liveuser 14729
			#如果傳入的參數為 null
14730
			if($conf===null){
226 liveuser 14731
 
3 liveuser 14732
				#設置執行錯誤訊息
14733
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14734
 
3 liveuser 14735
				}#if end
14736
 
14737
			#回傳結果
14738
			return $result;
226 liveuser 14739
 
3 liveuser 14740
			}#if end
226 liveuser 14741
 
3 liveuser 14742
		#函式說明:
14743
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14744
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14745
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14746
		#$result["function"],當前執行的函式名稱.
14747
		#$result["argu"],設置給予的參數.
14748
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14749
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14750
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14751
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14752
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14753
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14754
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14755
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14756
		#必填寫的參數:
14757
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14758
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14759
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14760
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14761
		#可以省略的參數:
14762
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14763
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
14764
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14765
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
14766
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14767
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14768
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14769
		#$conf["canNotBeEmpty"]=array();
14770
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14771
		#$conf["canBeEmpty"]=array();
14772
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14773
		#$conf["skipableVariableCanNotBeEmpty"]=array();
14774
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14775
		#$conf["skipableVariableName"]=array();
226 liveuser 14776
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14777
		#$conf["skipableVariableType"]=array();
14778
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14779
		#$conf["skipableVarDefaultValue"]=array("");
14780
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14781
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14782
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14783
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14784
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14785
		#$conf["arrayCountEqualCheck"][]=array();
14786
		#參考資料來源:
14787
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14788
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14789
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14790
 
3 liveuser 14791
		#如果檢查參數失敗
14792
		if($checkArguments["status"]==="false"){
226 liveuser 14793
 
3 liveuser 14794
			#設置執行失敗
14795
			$result["status"]="false";
226 liveuser 14796
 
3 liveuser 14797
			#設置執行失敗訊息
14798
			$result["error"]=$checkArguments;
226 liveuser 14799
 
3 liveuser 14800
			#回傳結果
14801
			return $result;
226 liveuser 14802
 
3 liveuser 14803
			}#if end
226 liveuser 14804
 
3 liveuser 14805
		#如果檢查參數不通過
14806
		if($checkArguments["passed"]==="false"){
226 liveuser 14807
 
3 liveuser 14808
			#設置執行失敗
14809
			$result["status"]="false";
226 liveuser 14810
 
3 liveuser 14811
			#設置執行失敗訊息
14812
			$result["error"]=$checkArguments;
226 liveuser 14813
 
3 liveuser 14814
			#回傳結果
14815
			return $result;
226 liveuser 14816
 
3 liveuser 14817
			}#if end
226 liveuser 14818
 
3 liveuser 14819
		#初始化檔案的路徑
14820
		$result["path"]="./";
226 liveuser 14821
 
3 liveuser 14822
		#用 "/" 來分割字串
14823
		#函式說明:
14824
		#將固定格式的字串分開,並回傳分開的結果。
14825
		#回傳結果:
14826
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14827
		#$result["error"],錯誤訊息陣列
14828
		#$result["function"],當前執行的函數名稱.
14829
		#$result["oriStr"],要分割的原始字串內容
14830
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
14831
		#$result["dataCounts"],爲總共分成幾段
14832
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
14833
		#必填參數:
14834
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["file"];#要處理的字串。
14835
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
14836
		#可省略參數:
14837
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
14838
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
14839
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
14840
		unset($conf["stringProcess::spiltString"]);
226 liveuser 14841
 
3 liveuser 14842
		#如果檢查參數失敗
14843
		if($spiltString["status"]==="false"){
226 liveuser 14844
 
3 liveuser 14845
			#設置執行失敗
14846
			$result["status"]="false";
226 liveuser 14847
 
3 liveuser 14848
			#設置執行失敗訊息
14849
			$result["error"]=$spiltString;
226 liveuser 14850
 
3 liveuser 14851
			#回傳結果
14852
			return $result;
226 liveuser 14853
 
3 liveuser 14854
			}#if end
226 liveuser 14855
 
3 liveuser 14856
		#初始化含副檔名的檔案名稱
14857
		$result["fullName"]=$conf["file"];
226 liveuser 14858
 
3 liveuser 14859
		#如果有"/"存在
14860
		if($spiltString["found"]==="true"){
226 liveuser 14861
 
3 liveuser 14862
			#取得含副檔名的檔案名稱
14863
			$result["fullName"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 14864
 
3 liveuser 14865
			#取得檔案的路徑
14866
			$result["path"]=substr($conf["file"],0,strlen($conf["file"])-strlen($result["fullName"]));
226 liveuser 14867
 
3 liveuser 14868
			}#if end
226 liveuser 14869
 
3 liveuser 14870
		#用 "." 來分割字串
14871
		#函式說明:
14872
		#將固定格式的字串分開,並回傳分開的結果。
14873
		#回傳結果:
14874
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14875
		#$result["error"],錯誤訊息陣列
14876
		#$result["function"],當前執行的函數名稱.
14877
		#$result["oriStr"],要分割的原始字串內容
14878
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
14879
		#$result["dataCounts"],爲總共分成幾段
14880
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
14881
		#必填參數:
14882
		$conf["stringProcess::spiltString"]["stringIn"]=$result["fullName"];#要處理的字串。
14883
		$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
14884
		#可省略參數:
14885
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
14886
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
14887
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
14888
		unset($conf["stringProcess::spiltString"]);
226 liveuser 14889
 
3 liveuser 14890
		#如果檢查參數失敗
14891
		if($spiltString["status"]==="false"){
226 liveuser 14892
 
3 liveuser 14893
			#設置執行失敗
14894
			$result["status"]="false";
226 liveuser 14895
 
3 liveuser 14896
			#設置執行失敗訊息
14897
			$result["error"]=$spiltString;
226 liveuser 14898
 
3 liveuser 14899
			#回傳結果
14900
			return $result;
226 liveuser 14901
 
3 liveuser 14902
			}#if end
226 liveuser 14903
 
3 liveuser 14904
		#預設副檔名為 ""
14905
		$result["content"]="";
226 liveuser 14906
 
3 liveuser 14907
		#預設不含副檔名的檔案名稱
14908
		$result["name"]=$result["fullName"];
226 liveuser 14909
 
3 liveuser 14910
		#如果有"."存在
14911
		if($spiltString["found"]==="true"){
226 liveuser 14912
 
3 liveuser 14913
			#取得含副檔名
14914
			$result["content"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 14915
 
3 liveuser 14916
			#取得不含副檔名的檔案名稱
226 liveuser 14917
			$result["name"]=substr($result["fullName"],0,strlen($result["fullName"])-strlen($result["content"])-1);
14918
 
3 liveuser 14919
			}#if end
226 liveuser 14920
 
3 liveuser 14921
		#設置執行正常
14922
		$result["status"]="true";
226 liveuser 14923
 
3 liveuser 14924
		#回傳結果
14925
		return $result;
226 liveuser 14926
 
3 liveuser 14927
		}#function getExtension end
14928
 
14929
	/*
14930
	#函式說明:
14931
	#從檔案尾部開始讀取
14932
	#回傳結果:
14933
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14934
	#$result["error"],錯誤訊息.
14935
	#$result["function"],當前執行的函數名稱.
226 liveuser 14936
	#$result["argu"],所使用的參數.
3 liveuser 14937
	#$result["content"],讀取到的內容陣列.
14938
	#$result["totalLineCount"],檔案的總共行數.
14939
	#$result["lines"],取得輸出的行數.
14940
	#$result["lineNum"],取得當前行數.
14941
	#必填參數:
14942
	#$conf["file"],字串,檔案的路徑與名稱.
14943
	$conf["file"]="";
14944
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14945
	$conf["fileArgu"]=__FILE__;
14946
	#可省略參數:
14947
	#$conf["web"],字串,"true"代表位網頁系統,"false"為檔案系統,預設為"false".
14948
	#$conf["web"]="false";
14949
	#$conf["line2start"],字串,從第幾列開始,預設為總行書減去linesPerTime+1.
14950
	#$conf["line2start"]="";
14951
	#$conf["linesPerTime"],字串,一次最多讀取幾列,預設爲10列.
226 liveuser 14952
	#$conf["linesPerTime"]="10";
3 liveuser 14953
	#參考資料:
14954
	#無.
14955
	#備註:
14956
	#無.
14957
	*/
14958
	public static function tail(&$conf){
14959
 
14960
		#初始化要回傳的結果
14961
		$result=array();
14962
 
14963
		#取得當前執行的函數名稱
14964
		$result["function"]=__FUNCTION__;
14965
 
14966
		#如果沒有參數
14967
		if(func_num_args()==0){
226 liveuser 14968
 
3 liveuser 14969
			#設置執行失敗
14970
			$result["status"]="false";
226 liveuser 14971
 
3 liveuser 14972
			#設置執行錯誤訊息
14973
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14974
 
3 liveuser 14975
			#回傳結果
14976
			return $result;
14977
 
226 liveuser 14978
			}#if end
14979
 
3 liveuser 14980
		#取得參數
14981
		$result["argu"]=$conf;
14982
 
14983
		#如果 $conf 不為陣列
14984
		if(gettype($conf)!=="array"){
226 liveuser 14985
 
3 liveuser 14986
			#設置執行失敗
14987
			$result["status"]="false";
226 liveuser 14988
 
3 liveuser 14989
			#設置執行錯誤訊息
14990
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14991
 
3 liveuser 14992
			#如果傳入的參數為 null
14993
			if($conf===null){
226 liveuser 14994
 
3 liveuser 14995
				#設置執行錯誤訊息
14996
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14997
 
3 liveuser 14998
				}#if end
14999
 
15000
			#回傳結果
15001
			return $result;
226 liveuser 15002
 
3 liveuser 15003
			}#if end
226 liveuser 15004
 
3 liveuser 15005
		#函式說明:
15006
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
15007
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15008
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15009
		#$result["function"],當前執行的函式名稱.
15010
		#$result["argu"],設置給予的參數.
15011
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15012
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15013
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15014
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15015
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15016
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15017
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15018
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15019
		#必填寫的參數:
15020
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 15021
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 15022
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15023
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15024
		#可以省略的參數:
15025
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15026
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
15027
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15028
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
15029
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15030
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15031
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15032
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file","fileArgu");
15033
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15034
		#$conf["canBeEmpty"]=array();
15035
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
15036
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web","line2start","linesPerTime");
15037
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
15038
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web","line2start","linesPerTime");
226 liveuser 15039
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 15040
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
15041
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
15042
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,"10");
15043
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15044
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15045
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15046
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15047
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15048
		#$conf["arrayCountEqualCheck"][]=array();
15049
		#參考資料來源:
15050
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15051
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15052
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15053
 
3 liveuser 15054
		#如果檢查參數失敗
15055
		if($checkArguments["status"]==="false"){
226 liveuser 15056
 
3 liveuser 15057
			#設置執行失敗
15058
			$result["status"]="false";
226 liveuser 15059
 
3 liveuser 15060
			#設置執行失敗訊息
15061
			$result["error"]=$checkArguments;
226 liveuser 15062
 
3 liveuser 15063
			#回傳結果
15064
			return $result;
226 liveuser 15065
 
3 liveuser 15066
			}#if end
226 liveuser 15067
 
3 liveuser 15068
		#如果檢查參數不通過
15069
		if($checkArguments["passed"]==="false"){
226 liveuser 15070
 
3 liveuser 15071
			#設置執行失敗
15072
			$result["status"]="false";
226 liveuser 15073
 
3 liveuser 15074
			#設置執行失敗訊息
15075
			$result["error"]=$checkArguments;
226 liveuser 15076
 
3 liveuser 15077
			#回傳結果
15078
			return $result;
226 liveuser 15079
 
3 liveuser 15080
			}#if end
15081
 
15082
		#檢查檔案是否存在
15083
		#函式說明:
15084
		#檢查多個檔案與資料夾是否存在.
15085
		#回傳的結果:
15086
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
15087
		#$result["error"],錯誤訊息陣列.
15088
		#$resutl["function"],當前執行的涵式名稱.
15089
		#$result["argu"],使用的參數.
15090
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
15091
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
15092
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
15093
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
15094
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
15095
		#必填參數:
15096
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
15097
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
15098
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
15099
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
15100
		#可省略參數
15101
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
15102
		#$conf["disableWebSearch"]="false";
15103
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
15104
		#$conf["userDir"]="true";
15105
		#$conf["web"],字串,"true"代表位網頁系統,"false"為檔案系統,預設為"false".
15106
		$conf["fileAccess::checkMultiFileExist"]["web"]=$conf["web"];
15107
		#參考資料來源:
15108
		#http://php.net/manual/en/function.file-exists.php
15109
		#http://php.net/manual/en/control-structures.foreach.php
15110
		#備註:
15111
		#函數file_exists檢查的路徑為檔案系統的路徑
15112
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
15113
		unset($conf["fileAccess::checkMultiFileExist"]);
15114
 
15115
		#如果執行失敗
15116
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 15117
 
3 liveuser 15118
			#設置執行失敗
15119
			$result["status"]="false";
226 liveuser 15120
 
3 liveuser 15121
			#設置執行失敗訊息
15122
			$result["error"]=$checkMultiFileExist;
226 liveuser 15123
 
3 liveuser 15124
			#回傳結果
15125
			return $result;
226 liveuser 15126
 
3 liveuser 15127
			}#if end
226 liveuser 15128
 
3 liveuser 15129
		#如果檔案無法存取
15130
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 15131
 
3 liveuser 15132
			#設置執行失敗
15133
			$result["status"]="false";
226 liveuser 15134
 
3 liveuser 15135
			#設置執行失敗訊息
15136
			$result["error"]=$checkMultiFileExist;
226 liveuser 15137
 
3 liveuser 15138
			#回傳結果
15139
			return $result;
226 liveuser 15140
 
3 liveuser 15141
			}#if end
15142
 
15143
		#取得檔案的行數
15144
		#函式說明:
15145
		#呼叫shell執行系統命令,並取得回傳的內容.
15146
		#回傳的結果:
15147
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15148
		#$result["error"],錯誤訊息陣列.
15149
		#$result["function"],當前執行的函數名稱.
15150
		#$result["argu"],使用的參數.
15151
		#$result["cmd"],執行的指令內容.
15152
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15153
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15154
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15155
		#$result["running"],是否還在執行.
15156
		#$result["pid"],pid.
15157
		#$result["statusCode"],執行結束後的代碼.
15158
		#必填的參數
15159
		#$conf["command"],字串,要執行的指令與.
15160
		$conf["external::callShell"]["command"]="cat";
15161
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 15162
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 15163
		#可省略參數:
15164
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15165
		$conf["external::callShell"]["argu"]=array($conf["file"],"|","wc","-l");
15166
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 15167
		#$conf["arguIsAddr"]=array();
3 liveuser 15168
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15169
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15170
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15171
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15172
		#$conf["enablePrintDescription"]="true";
15173
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15174
		#$conf["printDescription"]="";
15175
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
15176
		$conf["external::callShell"]["escapeshellarg"]="true";
15177
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15178
		#$conf["username"]="";
15179
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15180
		#$conf["password"]="";
15181
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15182
		#$conf["useScript"]="";
15183
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15184
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15185
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15186
		#$conf["inBackGround"]="";
15187
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
15188
		#$conf["getErr"]="false";
15189
		#備註:
15190
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15191
		#參考資料:
15192
		#exec=>http://php.net/manual/en/function.exec.php
15193
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15194
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15195
		$callShell=external::callShell($conf["external::callShell"]);
15196
		unset($conf["external::callShell"]);
15197
 
15198
		#如果檢查參數失敗
15199
		if($callShell["status"]==="false"){
226 liveuser 15200
 
3 liveuser 15201
			#設置執行失敗
15202
			$result["status"]="false";
226 liveuser 15203
 
3 liveuser 15204
			#設置執行失敗訊息
15205
			$result["error"]=$callShell;
226 liveuser 15206
 
3 liveuser 15207
			#回傳結果
15208
			return $result;
226 liveuser 15209
 
3 liveuser 15210
			}#if end
226 liveuser 15211
 
3 liveuser 15212
		#取得檔案總行數
15213
		$result["totalLineCount"]=$callShell["output"][0];
226 liveuser 15214
 
3 liveuser 15215
		#如果未設置 $conf["line2start"]
15216
		if(!isset($conf["line2start"])){
226 liveuser 15217
 
3 liveuser 15218
			#$conf["line2start"]為總行數減去一次要看的行數減1
15219
			$conf["line2start"]=$result["totalLineCount"]-$conf["linesPerTime"]+1;
226 liveuser 15220
 
15221
			}#if end
15222
 
15223
		#如果開始行數小於1
3 liveuser 15224
		if($conf["line2start"]<1){
226 liveuser 15225
 
3 liveuser 15226
			#$conf["line2start"]為總行數減去一次要看的行數減1
15227
			$conf["line2start"]=$result["totalLineCount"]-$conf["linesPerTime"]+1;
226 liveuser 15228
 
3 liveuser 15229
			}#if end
226 liveuser 15230
 
15231
		#如果開始行數小於1
3 liveuser 15232
		if($conf["line2start"]<1){
226 liveuser 15233
 
3 liveuser 15234
			#$conf["line2start"]為1
15235
			$conf["line2start"]=1;
226 liveuser 15236
 
3 liveuser 15237
			}#if end
226 liveuser 15238
 
3 liveuser 15239
		#取得指定範圍的行數
15240
		#取得檔案的行數
15241
		#函式說明:
15242
		#呼叫shell執行系統命令,並取得回傳的內容.
15243
		#回傳的結果:
15244
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15245
		#$result["error"],錯誤訊息陣列.
15246
		#$result["function"],當前執行的函數名稱.
15247
		#$result["argu"],使用的參數.
15248
		#$result["cmd"],執行的指令內容.
15249
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15250
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15251
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15252
		#$result["running"],是否還在執行.
15253
		#$result["pid"],pid.
15254
		#$result["statusCode"],執行結束後的代碼.
15255
		#必填的參數
15256
		#$conf["command"],字串,要執行的指令與.
15257
		$conf["external::callShell"]["command"]="sed";
15258
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 15259
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 15260
		#可省略參數:
15261
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15262
		$conf["external::callShell"]["argu"]=array("-n",$conf["line2start"].",".($conf["line2start"]+$conf["linesPerTime"]-1)."p",$conf["file"]);
15263
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 15264
		#$conf["arguIsAddr"]=array();
3 liveuser 15265
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15266
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15267
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15268
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15269
		#$conf["enablePrintDescription"]="true";
15270
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15271
		#$conf["printDescription"]="";
15272
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
15273
		$conf["external::callShell"]["escapeshellarg"]="true";
15274
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15275
		#$conf["username"]="";
15276
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15277
		#$conf["password"]="";
15278
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15279
		#$conf["useScript"]="";
15280
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15281
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15282
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15283
		#$conf["inBackGround"]="";
15284
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
15285
		#$conf["getErr"]="false";
15286
		#備註:
15287
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15288
		#參考資料:
15289
		#exec=>http://php.net/manual/en/function.exec.php
15290
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15291
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15292
		$callShell=external::callShell($conf["external::callShell"]);
15293
		unset($conf["external::callShell"]);
15294
 
15295
		#如果檢查參數失敗
15296
		if($callShell["status"]==="false"){
226 liveuser 15297
 
3 liveuser 15298
			#設置執行失敗
15299
			$result["status"]="false";
226 liveuser 15300
 
3 liveuser 15301
			#設置執行失敗訊息
15302
			$result["error"]=$callShell;
226 liveuser 15303
 
3 liveuser 15304
			#回傳結果
15305
			return $result;
226 liveuser 15306
 
3 liveuser 15307
			}#if end
15308
 
15309
		#取得輸出的行數
15310
		$result["lines"]=count($callShell["output"]);
15311
 
15312
		#取得目前的輸出內容
15313
		$result["content"]=$callShell["output"];
15314
 
15315
		#取得當前行數
15316
		$result["lineNum"]=$conf["line2start"]+$result["lines"]-1;
15317
 
226 liveuser 15318
		#如果當前行號小於總行數
3 liveuser 15319
		if($result["lineNum"]<$result["totalLineCount"]){
15320
 
15321
			#設置還有剩餘的內容
15322
			$result["left"]="true";
226 liveuser 15323
 
3 liveuser 15324
			}#if end
15325
 
226 liveuser 15326
		#反之
3 liveuser 15327
		else{
15328
 
15329
			#設置無剩餘的內容
15330
			$result["left"]="false";
15331
 
15332
			}#else end
15333
 
15334
		#設置執行正常
15335
		$result["status"]="true";
15336
 
15337
		#回傳結果
15338
		return $result;
15339
 
15340
		}#function tail end
226 liveuser 15341
 
3 liveuser 15342
	/*
15343
	#函式說明:
15344
	#解析PHP檔案裡面的變數.
15345
	#回傳結果:
15346
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15347
	#$result["error"],錯誤訊息.
15348
	#$result["function"],當前執行的函數名稱.
226 liveuser 15349
	#$result["argu"],所使用的參數.
3 liveuser 15350
	#$result["content"],找到的變數內容陣列,若有多個變數則會用array來表示.
15351
	#必填參數:
15352
	#$conf["file"],字串,檔案的路徑與名稱.
15353
	$conf["file"]="";
15354
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
15355
	$conf["fileArgu"]=__FILE__;
15356
	#$conf["varName"],字串陣列,要搜尋的變數名稱,例如要搜尋變數$email則輸入"email".
15357
	$conf["varName"]=array();
15358
	#可省略參數:
15359
	#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false",預設為"false".
15360
	#$conf["web"]="true";
255 liveuser 15361
	#$conf["allVarCountSame"],字串,是否每個參數的數量要一致,預設為"false"不要;反之為"true"代表要.
15362
	#$conf["allVarCountSame"]="false";
3 liveuser 15363
	#參考資料:
15364
	#https://www.php.net/manual/en/function.parse-str.php
15365
	#備註:
15366
	#無.
15367
	*/
15368
	public static function parseVaraiableInPHPfile(&$conf){
226 liveuser 15369
 
3 liveuser 15370
		#初始化要回傳的結果
15371
		$result=array();
15372
 
15373
		#取得當前執行的函數名稱
15374
		$result["function"]=__FUNCTION__;
15375
 
15376
		#如果沒有參數
15377
		if(func_num_args()==0){
226 liveuser 15378
 
3 liveuser 15379
			#設置執行失敗
15380
			$result["status"]="false";
226 liveuser 15381
 
3 liveuser 15382
			#設置執行錯誤訊息
15383
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 15384
 
3 liveuser 15385
			#回傳結果
15386
			return $result;
15387
 
226 liveuser 15388
			}#if end
15389
 
3 liveuser 15390
		#取得參數
15391
		$result["argu"]=$conf;
15392
 
15393
		#如果 $conf 不為陣列
15394
		if(gettype($conf)!=="array"){
226 liveuser 15395
 
3 liveuser 15396
			#設置執行失敗
15397
			$result["status"]="false";
226 liveuser 15398
 
3 liveuser 15399
			#設置執行錯誤訊息
15400
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 15401
 
3 liveuser 15402
			#如果傳入的參數為 null
15403
			if($conf===null){
226 liveuser 15404
 
3 liveuser 15405
				#設置執行錯誤訊息
15406
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 15407
 
3 liveuser 15408
				}#if end
15409
 
15410
			#回傳結果
15411
			return $result;
226 liveuser 15412
 
3 liveuser 15413
			}#if end
226 liveuser 15414
 
3 liveuser 15415
		#函式說明:
15416
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
15417
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15418
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15419
		#$result["function"],當前執行的函式名稱.
15420
		#$result["argu"],設置給予的參數.
15421
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15422
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15423
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15424
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15425
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15426
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15427
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15428
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15429
		#必填寫的參數:
15430
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 15431
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 15432
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15433
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15434
		#可以省略的參數:
15435
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15436
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu","varName");
15437
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15438
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
15439
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15440
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15441
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15442
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file","fileArgu","varName");
15443
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15444
		#$conf["canBeEmpty"]=array();
15445
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
255 liveuser 15446
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web","allVarCountSame");
3 liveuser 15447
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
255 liveuser 15448
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web","allVarCountSame");
226 liveuser 15449
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
255 liveuser 15450
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
3 liveuser 15451
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
255 liveuser 15452
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
3 liveuser 15453
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15454
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15455
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15456
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15457
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15458
		#$conf["arrayCountEqualCheck"][]=array();
15459
		#參考資料來源:
15460
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15461
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15462
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15463
 
3 liveuser 15464
		#如果檢查參數失敗
15465
		if($checkArguments["status"]==="false"){
226 liveuser 15466
 
3 liveuser 15467
			#設置執行失敗
15468
			$result["status"]="false";
226 liveuser 15469
 
3 liveuser 15470
			#設置執行失敗訊息
15471
			$result["error"]=$checkArguments;
226 liveuser 15472
 
3 liveuser 15473
			#回傳結果
15474
			return $result;
226 liveuser 15475
 
3 liveuser 15476
			}#if end
226 liveuser 15477
 
3 liveuser 15478
		#如果檢查參數不通過
15479
		if($checkArguments["passed"]==="false"){
226 liveuser 15480
 
3 liveuser 15481
			#設置執行失敗
15482
			$result["status"]="false";
226 liveuser 15483
 
3 liveuser 15484
			#設置執行失敗訊息
15485
			$result["error"]=$checkArguments;
226 liveuser 15486
 
3 liveuser 15487
			#回傳結果
15488
			return $result;
226 liveuser 15489
 
3 liveuser 15490
			}#if end
226 liveuser 15491
 
3 liveuser 15492
		#初始化儲存解析出來的變數內容
15493
		$result["content"]=array();
226 liveuser 15494
 
3 liveuser 15495
		#讀取檔案
15496
		#函式說明:
15497
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
15498
		#回傳的變數說明:
15499
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
15500
		#$result["error"],錯誤訊息提示.
15501
		#$result["warning"],警告訊息.
15502
		#$result["function"],當前執行的函數名稱.
15503
		#$result["fileContent"],爲檔案的內容陣列.
15504
		#$result["lineCount"],爲檔案內容總共的行數.
15505
		#$result["fullContent"],為檔案的完整內容.
15506
		#$result["base64data"],為檔案的base64內容.
15507
		#$result["mimeType"],為檔案的mime type.
15508
		#必填參數:
15509
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
15510
		$conf["ileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
15511
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
15512
		$conf["ileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
15513
		#可省略參數:
15514
		#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
15515
		$conf["ileAccess::getFileContent"]["web"]=$conf["web"];
15516
		#參考資料:
15517
		#file(),取得檔案內容的行數.
15518
		#file=>http:#php.net/manual/en/function.file.php
15519
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
15520
		#filesize=>http://php.net/manual/en/function.filesize.php
15521
		$getFileContent=fileAccess::getFileContent($conf["ileAccess::getFileContent"]);
15522
		unset($conf["ileAccess::getFileContent"]);
15523
 
15524
		#如果讀取檔案失敗
15525
		if($getFileContent["status"]==="false"){
226 liveuser 15526
 
3 liveuser 15527
			#設置執行失敗
15528
			$result["status"]="false";
226 liveuser 15529
 
3 liveuser 15530
			#設置執行失敗訊息
15531
			$result["error"]=$getFileContent;
226 liveuser 15532
 
3 liveuser 15533
			#回傳結果
15534
			return $result;
226 liveuser 15535
 
3 liveuser 15536
			}#if end
226 liveuser 15537
 
3 liveuser 15538
		#針對每列檔案內容
15539
		foreach($getFileContent["fileContent"] as $line){
226 liveuser 15540
 
3 liveuser 15541
			#針對每個要搜尋的變數
15542
			foreach($conf["varName"] as $keyWord){
226 liveuser 15543
 
3 liveuser 15544
				#如果關鍵字小於被搜尋的字串長度
15545
				if( strlen($line) < strlen($keyWord)+1 ){
226 liveuser 15546
 
3 liveuser 15547
					#跳過
15548
					continue;
226 liveuser 15549
 
3 liveuser 15550
					}#if end
226 liveuser 15551
 
3 liveuser 15552
				#函式說明:
15553
				#取得符合特定字首與字尾的字串
15554
				#回傳結果:
15555
				#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
15556
				#$result["function"],當前執行的函數名稱.
15557
				#$result["error"],錯誤訊息陣列.
15558
				#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
15559
				#$result["returnString"],爲符合字首條件的字串內容。
15560
				#$result["argu"],使用的參數.
15561
				#必填參數:
15562
				#$conf["checkString"],字串,要檢查的字串.
15563
				$conf["search::getMeetConditionsString"]["checkString"]=$line;
15564
				#可省略參數:
15565
				#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
15566
				$conf["search::getMeetConditionsString"]["frontWord"]="$".$keyWord;
15567
				#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
15568
				$conf["search::getMeetConditionsString"]["tailWord"]=";";
15569
				#參考資料:
15570
				#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
15571
				$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
15572
				unset($conf["search::getMeetConditionsString"]);
226 liveuser 15573
 
3 liveuser 15574
				#如果失敗
15575
				if($getMeetConditionsString["status"]==="false"){
15576
 
15577
					#設置執行失敗
15578
					$result["status"]="false";
226 liveuser 15579
 
3 liveuser 15580
					#設置執行失敗訊息
15581
					$result["error"]=$getMeetConditionsString;
226 liveuser 15582
 
3 liveuser 15583
					#回傳結果
15584
					return $result;
226 liveuser 15585
 
15586
					}#if end
15587
 
3 liveuser 15588
				#如果有找到關鍵字
15589
				if($getMeetConditionsString["founded"]==="true"){
226 liveuser 15590
 
3 liveuser 15591
					#剔除變數名稱
15592
					#函式說明:
15593
					#將字串特定關鍵字與其前面的內容剔除
15594
					#回傳結果:
15595
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15596
					#$result["error"],錯誤訊息陣列.
15597
					#$result["warning"],警告訊息鎮列.
15598
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
15599
					#$result["function"],當前執行的函數名稱.
15600
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 15601
					#$result["content"],處理好的的字串內容.
3 liveuser 15602
					#必填參數:
15603
					#$conf["stringIn"],字串,要處理的字串.
15604
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$line;
15605
					#$conf["keyWord"],字串,特定字串.
15606
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="$".$keyWord;
15607
					#可省略參數:
15608
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,直到沒有關鍵字為止.
15609
					#$conf["recursive"]="true";
15610
					#參考資料:
15611
					#無.
15612
					#備註:
15613
					#無.
15614
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
15615
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 15616
 
3 liveuser 15617
					#如果執行失敗
15618
					if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 15619
 
3 liveuser 15620
						#設置執行失敗
15621
						$result["status"]="false";
226 liveuser 15622
 
3 liveuser 15623
						#設置執行失敗訊息
15624
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15625
 
3 liveuser 15626
						#回傳結果
15627
						return $result;
226 liveuser 15628
 
3 liveuser 15629
						}#if end
226 liveuser 15630
 
3 liveuser 15631
					#如果沒有找到應該存在的php變數
15632
					if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 15633
 
3 liveuser 15634
						#設置執行失敗
15635
						$result["status"]="false";
226 liveuser 15636
 
3 liveuser 15637
						#設置執行失敗訊息
15638
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15639
 
3 liveuser 15640
						#回傳結果
15641
						return $result;
226 liveuser 15642
 
3 liveuser 15643
						}#if end
226 liveuser 15644
 
3 liveuser 15645
					#剔除 "=" 前面的內容
15646
					#函式說明:
15647
					#將字串特定關鍵字與其前面的內容剔除
15648
					#回傳結果:
15649
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15650
					#$result["error"],錯誤訊息陣列.
15651
					#$result["warning"],警告訊息鎮列.
15652
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
15653
					#$result["function"],當前執行的函數名稱.
15654
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 15655
					#$result["content"],處理好的的字串內容.
3 liveuser 15656
					#必填參數:
15657
					#$conf["stringIn"],字串,要處理的字串.
15658
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
15659
					#$conf["keyWord"],字串,特定字串.
15660
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="=";
15661
					#可省略參數:
15662
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,直到沒有關鍵字為止.
15663
					#$conf["recursive"]="true";
15664
					#參考資料:
15665
					#無.
15666
					#備註:
15667
					#無.
15668
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
15669
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 15670
 
3 liveuser 15671
					#如果執行失敗
15672
					if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 15673
 
3 liveuser 15674
						#設置執行失敗
15675
						$result["status"]="false";
226 liveuser 15676
 
3 liveuser 15677
						#設置執行失敗訊息
15678
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15679
 
3 liveuser 15680
						#回傳結果
15681
						return $result;
226 liveuser 15682
 
3 liveuser 15683
						}#if end
226 liveuser 15684
 
3 liveuser 15685
					#如果沒有找“=”關鍵字
15686
					if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 15687
 
3 liveuser 15688
						#跳過
15689
						continue;
226 liveuser 15690
 
3 liveuser 15691
						}#if end
226 liveuser 15692
 
3 liveuser 15693
					#剔除 value 前面的空白
15694
					#函式說明:
288 liveuser 15695
					#移除字串開頭的特定內容
3 liveuser 15696
					#回傳結果:
288 liveuser 15697
					#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
3 liveuser 15698
					#$result["error"],錯誤訊息陣列.
288 liveuser 15699
					#$result["function"],當前執行的函數.
15700
					#$result["content"],處理好的字串.
15701
					#$result["argu"],使用的參數.
3 liveuser 15702
					#必填參數:
288 liveuser 15703
					#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
15704
					$conf["stringProcess::delKeyWordsInStrHead"]["inputStr"]=$delStrBeforeKeyWord["content"];
15705
					#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
15706
					$conf["stringProcess::delKeyWordsInStrHead"]["keyWord"]=" ";
3 liveuser 15707
					#可省略參數:
288 liveuser 15708
					#$conf["recursive"],字串,"true"代表要遞迴移除開頭的關鍵字,預設為"false",只移除開頭關鍵字1次.
15709
					$conf["stringProcess::delKeyWordsInStrHead"]["recursive"]="true";
3 liveuser 15710
					#參考資料:
15711
					#無.
15712
					#備註:
15713
					#無.
288 liveuser 15714
					$delKeyWordsInStrHead=stringProcess::delKeyWordsInStrHead($conf["stringProcess::delKeyWordsInStrHead"]);
15715
					unset($conf["stringProcess::delKeyWordsInStrHead"]);
226 liveuser 15716
 
3 liveuser 15717
					#如果執行失敗
288 liveuser 15718
					if($delKeyWordsInStrHead["status"]==="false"){
226 liveuser 15719
 
3 liveuser 15720
						#設置執行失敗
15721
						$result["status"]="false";
226 liveuser 15722
 
3 liveuser 15723
						#設置執行失敗訊息
288 liveuser 15724
						$result["error"]=$delKeyWordsInStrHead;
226 liveuser 15725
 
3 liveuser 15726
						#回傳結果
15727
						return $result;
226 liveuser 15728
 
3 liveuser 15729
						}#if end
226 liveuser 15730
 
316 liveuser 15731
					#取得找到的變數的語法
15732
					$phpCode="\$result[\"content\"][\"".$keyWord."\"][]=".$delKeyWordsInStrHead["content"];
15733
 
3 liveuser 15734
					#取得找到的變數
316 liveuser 15735
					eval($phpCode);
226 liveuser 15736
 
3 liveuser 15737
					}#if end
226 liveuser 15738
 
3 liveuser 15739
				}#foreach end
226 liveuser 15740
 
3 liveuser 15741
			}#foreach end
226 liveuser 15742
 
255 liveuser 15743
		#如果 allVarCountSame 設置為 "true"
15744
		if($conf["allVarCountSame"]==="true"){
15745
 
15746
			#每個變數的數量初始為0
15747
			$count=0;
15748
 
15749
			#針對每個解析出來的變數
15750
			foreach($conf["varName"] as $varName){
15751
 
15752
				#取得該變數數量
15753
				$varCount=count($result["content"][$varName]);
15754
 
15755
				#如果尚無變數數量資料
15756
				if($count===0){
15757
 
15758
					#直接儲存之
15759
					$count=$varCount;
15760
 
15761
					#看下一個變數
15762
					continue;
15763
 
15764
					}#if end
15765
 
15766
				#如果變數數量不一樣
15767
				if($count!==$varCount){
15768
 
15769
					#設置執行失敗
15770
					$result["status"]="false";
15771
 
15772
					#設置執行失敗訊息
15773
					$result["error"]="config file error";
15774
 
15775
					#回傳結果
15776
					return $result;
15777
 
15778
					}#if end
15779
 
15780
				}#foreach end
15781
 
15782
			}#if end
15783
 
3 liveuser 15784
		#設置執行正常
15785
		$result["status"]="true";
226 liveuser 15786
 
3 liveuser 15787
		#回傳結果
15788
		return $result;
226 liveuser 15789
 
3 liveuser 15790
		}#function parseVaraiableInPHPfile end
15791
 
15792
	/*
15793
	#函式說明:
15794
	#開啟特定目錄,取得底下的檔案路徑清單.
15795
	#回傳結果:
15796
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15797
	#$result["error"],錯誤訊息.
15798
	#$result["function"],當前執行的函數名稱.
15799
	#$result["argu"],所使用的參數.
15800
	#$result["content"],讀取到的內容陣列.
15801
	#$result["content"][$i],第$i+1個結果.
15802
	#$result["content"][$i]["name"],第$i+1個名稱.
15803
	#$result["content"][$i]["dir"],第$i+1個檔案是否為資料夾.
15804
	#$result["content"][$i]["info"],第$i+1個檔案的額外資訊.
15805
	#$result["content"][$i]["size"],第$i+1個檔案的大小(bytes).
15806
	#必填參數:
15807
	#$conf["path"],字串,要取得檔案資訊的所屬路徑.
15808
	$conf["path"]="";
15809
	#可省略參數:
15810
	#無.
15811
	#參考資料
15812
	#無.
15813
	#備註:
15814
	#無.
15815
	*/
15816
	public static function listInfo(&$conf){
226 liveuser 15817
 
3 liveuser 15818
		#初始化要回傳的結果
15819
		$result=array();
15820
 
15821
		#取得當前執行的函數名稱
15822
		$result["function"]=__FUNCTION__;
15823
 
15824
		#如果沒有參數
15825
		if(func_num_args()==0){
226 liveuser 15826
 
3 liveuser 15827
			#設置執行失敗
15828
			$result["status"]="false";
226 liveuser 15829
 
3 liveuser 15830
			#設置執行錯誤訊息
15831
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 15832
 
3 liveuser 15833
			#回傳結果
15834
			return $result;
15835
 
226 liveuser 15836
			}#if end
15837
 
3 liveuser 15838
		#取得參數
15839
		$result["argu"]=$conf;
15840
 
15841
		#如果 $conf 不為陣列
15842
		if(gettype($conf)!=="array"){
226 liveuser 15843
 
3 liveuser 15844
			#設置執行失敗
15845
			$result["status"]="false";
226 liveuser 15846
 
3 liveuser 15847
			#設置執行錯誤訊息
15848
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 15849
 
3 liveuser 15850
			#如果傳入的參數為 null
15851
			if($conf===null){
226 liveuser 15852
 
3 liveuser 15853
				#設置執行錯誤訊息
15854
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 15855
 
3 liveuser 15856
				}#if end
15857
 
15858
			#回傳結果
15859
			return $result;
226 liveuser 15860
 
3 liveuser 15861
			}#if end
226 liveuser 15862
 
3 liveuser 15863
		#函式說明:
15864
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
15865
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15866
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15867
		#$result["function"],當前執行的函式名稱.
15868
		#$result["argu"],設置給予的參數.
15869
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15870
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15871
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15872
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15873
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15874
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15875
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15876
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15877
		#必填寫的參數:
15878
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 15879
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 15880
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15881
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15882
		#可以省略的參數:
15883
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15884
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
15885
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15886
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
15887
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15888
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15889
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15890
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
15891
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15892
		#$conf["canBeEmpty"]=array();
15893
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
15894
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
15895
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
15896
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 15897
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 15898
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
15899
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
15900
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
15901
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15902
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15903
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15904
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15905
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15906
		#$conf["arrayCountEqualCheck"][]=array();
15907
		#參考資料來源:
15908
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15909
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15910
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15911
 
3 liveuser 15912
		#如果檢查參數失敗
15913
		if($checkArguments["status"]==="false"){
226 liveuser 15914
 
3 liveuser 15915
			#設置執行失敗
15916
			$result["status"]="false";
226 liveuser 15917
 
3 liveuser 15918
			#設置執行失敗訊息
15919
			$result["error"]=$checkArguments;
226 liveuser 15920
 
3 liveuser 15921
			#回傳結果
15922
			return $result;
226 liveuser 15923
 
3 liveuser 15924
			}#if end
226 liveuser 15925
 
3 liveuser 15926
		#如果檢查參數不通過
15927
		if($checkArguments["passed"]==="false"){
226 liveuser 15928
 
3 liveuser 15929
			#設置執行失敗
15930
			$result["status"]="false";
226 liveuser 15931
 
3 liveuser 15932
			#設置執行失敗訊息
15933
			$result["error"]=$checkArguments;
226 liveuser 15934
 
3 liveuser 15935
			#回傳結果
15936
			return $result;
226 liveuser 15937
 
3 liveuser 15938
			}#if end
226 liveuser 15939
 
3 liveuser 15940
		#初始化儲存解析出來的變數內容
15941
		$result["content"]=array();
226 liveuser 15942
 
3 liveuser 15943
		#取得特定位置的資訊
15944
		$pathInfo=@dir($conf["path"]);
226 liveuser 15945
 
3 liveuser 15946
		#如果取得路徑資訊失敗
15947
		if($pathInfo===false){
226 liveuser 15948
 
3 liveuser 15949
			#設置執行失敗
15950
			$result["status"]="false";
226 liveuser 15951
 
3 liveuser 15952
			#設置執行失敗訊息
15953
			$result["error"][]="無法存取路徑(".$conf["path"].")";
226 liveuser 15954
 
3 liveuser 15955
			#回傳結果
15956
			return $result;
226 liveuser 15957
 
3 liveuser 15958
			}#if end
226 liveuser 15959
 
3 liveuser 15960
		#讀取底下一個檔案,暫存到 $tmpItem 裡面,且當結果不為 false 時進入迴圈.
15961
		while(false !== $tmpItem = $pathInfo->read()){
226 liveuser 15962
 
3 liveuser 15963
			#宣告儲存資訊的變數
15964
			$item=array();
226 liveuser 15965
 
3 liveuser 15966
			#儲存名稱
15967
			$item["name"]=$tmpItem;
226 liveuser 15968
 
3 liveuser 15969
			#預設不為資料夾
15970
			$item["dir"]="false";
226 liveuser 15971
 
3 liveuser 15972
			#若為資料夾
15973
			if(is_dir($conf["path"]."/".$tmpItem)){
226 liveuser 15974
 
3 liveuser 15975
				#設置為"true"
15976
				$item["dir"]="true";
226 liveuser 15977
 
3 liveuser 15978
				}#if end
226 liveuser 15979
 
3 liveuser 15980
			#取得檔案識別器
15981
			$finfo = finfo_open(FILEINFO_MIME);
226 liveuser 15982
 
3 liveuser 15983
			#取得 info
15984
			$item["info"]=@finfo_file($finfo,$conf["path"]."/".$tmpItem);
15985
 
15986
			#取得檔案大小
15987
			$item["size"]=filesize($conf["path"]."/".$tmpItem);
15988
 
15989
			#close connection
15990
			finfo_close($finfo);
226 liveuser 15991
 
3 liveuser 15992
			#記錄該檔案資訊
15993
			$result["content"][]=$item;
226 liveuser 15994
 
3 liveuser 15995
			}#while end
226 liveuser 15996
 
3 liveuser 15997
		#設置執行正常
15998
		$result["status"]="true";
226 liveuser 15999
 
3 liveuser 16000
		#回傳結果
16001
		return $result;
226 liveuser 16002
 
3 liveuser 16003
		}#function listInfo end
16004
 
16005
	/*
16006
	#函式說明:
16007
	#取得目錄底下的詳細資訊.
16008
	#回傳結果:
16009
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16010
	#$result["error"],錯誤訊息.
16011
	#$result["function"],當前執行的函數名稱.
16012
	#$result["size"],該清單的大小,單位為bytes.
16013
	#$result["dataCount"],該清單的長度.
16014
	#$result["path"],字串,檢視的路徑,必為"/"結尾.
16015
	#$result["content"],指定目錄底下的所有檔案資訊.
16016
	#$result["content"][$i]["nType&permission"],第$i個節點類型、權限.
16017
	#$result["content"][$i]["nType"],第$i個節點類型,"-"代表檔案,"d"代表資料夾.
16018
	#$result["content"][$i]["permission"],第$i個節點權限.
16019
	#$result["content"][$i]["ownByUser"],第$i個節點擁有者賬號.
16020
	#$result["content"][$i]["ownByGroup"],第$i個節點擁有者群組.
16021
	#$result["content"][$i]["bytes"],第$i個節點大小.
16022
	#$result["content"][$i]["date"],第$i個節點最後變更日期.
16023
	#$result["content"][$i]["time"],第$i個節點最後異動時間.
16024
	#$result["content"][$i]["timeDetail"],第$i個節點最後異動詳細時間.
16025
	#$result["content"][$i]["timezone"],第$i個節點的時區.
16026
	#$result["content"][$i]["name"],第$i個節點的名稱.
16027
	#$result["content"][$i]["secondName"],第$i個節點為檔案時,若有附檔名,會記錄在這.
16028
	#$result["content"][$i]["mimeType"],第$i個節點為檔案且可以讀取時,會有 mime type 可取得.
16029
	#必填參數:
16030
	#$conf["path"],字串,要檢視的路徑,若非"/"結尾,會自動補上.
16031
	$conf["path"]="";
16032
	#可省略參數:
16033
	#無.
16034
	#參考資料:
16035
	#https://www.businessweekly.com.tw/careers/Blog/14307
16036
	#備註:
16037
	#無.
16038
	*/
16039
	public static function ls(&$conf){
226 liveuser 16040
 
3 liveuser 16041
		#初始化要回傳的結果
16042
		$result=array();
16043
 
16044
		#取得當前執行的函數名稱
16045
		$result["function"]=__FUNCTION__;
16046
 
16047
		#如果沒有參數
16048
		if(func_num_args()==0){
16049
 
16050
			#設置執行失敗
16051
			$result["status"]="false";
16052
 
16053
			#設置執行錯誤訊息
16054
			$result["error"]="函數".$result["function"]."需要參數";
16055
 
16056
			#回傳結果
16057
			return $result;
16058
 
16059
			}#if end
16060
 
16061
		#取得參數
16062
		$result["argu"]=$conf;
16063
 
16064
		#如果 $conf 不為陣列
16065
		if(gettype($conf)!=="array"){
16066
 
16067
			#設置執行失敗
16068
			$result["status"]="false";
16069
 
16070
			#設置執行錯誤訊息
16071
			$result["error"][]="\$conf變數須為陣列形態";
16072
 
16073
			#如果傳入的參數為 null
16074
			if(is_null($conf)){
16075
 
16076
				#設置執行錯誤訊息
16077
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
16078
 
16079
				}#if end
16080
 
16081
			#回傳結果
16082
			return $result;
16083
 
16084
			}#if end
226 liveuser 16085
 
3 liveuser 16086
		#函式說明:
16087
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
16088
		#回傳結果:
16089
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16090
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
16091
		#$result["simpleError"],簡單表示的錯誤訊息.
16092
		#$result["function"],當前執行的函式名稱.
16093
		#$result["argu"],設置給予的參數.
16094
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
16095
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
16096
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
16097
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
16098
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
16099
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
16100
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
16101
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
16102
		#必填參數:
16103
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
16104
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
16105
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
16106
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
16107
		#可省略參數:
16108
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
16109
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
16110
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
16111
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
16112
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
16113
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
16114
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
16115
		#$conf["canNotBeEmpty"]=array();
16116
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
16117
		#$conf["canBeEmpty"]=array();
16118
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
16119
		#$conf["skipableVariableCanNotBeEmpty"]=array();
16120
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
16121
		#$conf["skipableVariableName"]=array();
16122
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
16123
		#$conf["skipableVariableType"]=array();
16124
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
16125
		#$conf["skipableVarDefaultValue"]=array("");
16126
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
16127
		#$conf["disallowAllSkipableVarIsEmpty"]="";
16128
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
16129
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
16130
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
16131
		#$conf["arrayCountEqualCheck"][]=array();
16132
		#參考資料:
16133
		#array_keys=>http://php.net/manual/en/function.array-keys.php
16134
		#備註:
16135
		#無.
16136
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
16137
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 16138
 
3 liveuser 16139
		#如果執行失敗
16140
		if($checkArguments["status"]==="false"){
226 liveuser 16141
 
3 liveuser 16142
			#設置執行錯誤
16143
			$result["status"]="false";
226 liveuser 16144
 
3 liveuser 16145
			#設置錯誤訊息
16146
			$result["error"]=$checkArguments;
226 liveuser 16147
 
3 liveuser 16148
			#回傳結果
16149
			return $result;
226 liveuser 16150
 
3 liveuser 16151
			}#if end
226 liveuser 16152
 
3 liveuser 16153
		#如果參數檢查不通過
16154
		if($checkArguments["passed"]==="false"){
226 liveuser 16155
 
3 liveuser 16156
			#設置執行錯誤
16157
			$result["status"]="false";
226 liveuser 16158
 
3 liveuser 16159
			#設置錯誤訊息
16160
			$result["error"]=$checkArguments;
226 liveuser 16161
 
3 liveuser 16162
			#回傳結果
16163
			return $result;
226 liveuser 16164
 
3 liveuser 16165
			}#if end
226 liveuser 16166
 
3 liveuser 16167
		#確認 $conf["path"] 是否為 "/" 結尾
16168
		#函式說明:
16169
		#取得符合特定字首與字尾的字串
16170
		#回傳結果:
16171
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
16172
		#$result["function"],當前執行的函數名稱.
16173
		#$result["error"],錯誤訊息陣列.
16174
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
16175
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
16176
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
16177
		#$result["argu"],使用的參數.
16178
		#必填參數:
16179
		#$conf["checkString"],字串,要檢查的字串.
16180
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["path"];
16181
		#可省略參數:
16182
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
16183
		#$conf["frontWord"]="";
16184
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
16185
		$conf["search::getMeetConditionsString"]["tailWord"]="/";
16186
		#參考資料:
16187
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
16188
		#備註:
16189
		#無.
16190
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
16191
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 16192
 
3 liveuser 16193
		#如果執行失敗
16194
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 16195
 
3 liveuser 16196
			#設置執行錯誤
16197
			$result["status"]="false";
226 liveuser 16198
 
3 liveuser 16199
			#設置錯誤訊息
16200
			$result["error"]=$getMeetConditionsString;
226 liveuser 16201
 
3 liveuser 16202
			#回傳結果
16203
			return $result;
226 liveuser 16204
 
3 liveuser 16205
			}#if end
226 liveuser 16206
 
3 liveuser 16207
		#如果沒有 "/" 結尾
16208
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 16209
 
3 liveuser 16210
			#於結尾加上 "/"
16211
			$conf["path"]=$conf["path"]."/";
226 liveuser 16212
 
3 liveuser 16213
			}#if end
226 liveuser 16214
 
3 liveuser 16215
		#記錄真正的路徑
16216
		$result["path"]=$conf["path"];
226 liveuser 16217
 
3 liveuser 16218
		#函式說明:
16219
		#呼叫shell執行系統命令,並取得回傳的內容.
16220
		#回傳結果:
16221
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16222
		#$result["error"],錯誤訊息陣列.
16223
		#$result["function"],當前執行的函數名稱.
16224
		#$result["argu"],使用的參數.
16225
		#$result["cmd"],執行的指令內容.
16226
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16227
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16228
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16229
		#$result["running"],是否還在執行.
16230
		#$result["pid"],pid.
16231
		#$result["statusCode"],執行結束後的代碼.
16232
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
16233
		#必填參數:
16234
		#$conf["command"],字串,要執行的指令.
16235
		$conf["external::callShell"]["command"]="ls";
16236
		#$conf["fileArgu"],字串,變數__FILE__的內容.
16237
		$conf["external::callShell"]["fileArgu"]=__FILE__;
16238
		#可省略參數:
16239
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16240
		$conf["external::callShell"]["argu"]=array("-al","--full-time","-t","-B",$conf["path"]);
16241
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16242
		#$conf["arguIsAddr"]=array();
16243
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16244
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16245
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16246
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16247
		#$conf["enablePrintDescription"]="true";
16248
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16249
		#$conf["printDescription"]="";
16250
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16251
		$conf["external::callShell"]["escapeshellarg"]="true";
16252
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16253
		#$conf["thereIsShellVar"]=array();
16254
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16255
		#$conf["username"]="";
16256
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16257
		#$conf["password"]="";
16258
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16259
		#$conf["useScript"]="";
16260
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16261
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16262
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16263
		#$conf["inBackGround"]="";
16264
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16265
		#$conf["getErr"]="false";
16266
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16267
		#$conf["doNotRun"]="false";
16268
		#參考資料:
16269
		#exec=>http://php.net/manual/en/function.exec.php
16270
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16271
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16272
		#備註:
16273
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16274
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
16275
		$callShell=external::callShell($conf["external::callShell"]);
16276
		unset($conf["external::callShell"]);
226 liveuser 16277
 
3 liveuser 16278
		#debug
16279
		#var_dump(__FILE__,__LINE__,$callShell);
226 liveuser 16280
 
3 liveuser 16281
		#如果執行失敗
16282
		if($callShell["status"]==="false"){
226 liveuser 16283
 
3 liveuser 16284
			#設置執行錯誤
16285
			$result["status"]="false";
226 liveuser 16286
 
3 liveuser 16287
			#設置錯誤訊息
16288
			$result["error"]=$callShell;
226 liveuser 16289
 
3 liveuser 16290
			#回傳結果
16291
			return $result;
226 liveuser 16292
 
3 liveuser 16293
			}#if end
226 liveuser 16294
 
3 liveuser 16295
		#初始化儲存檔案資訊為空
16296
		$result["content"]=array();
226 liveuser 16297
 
3 liveuser 16298
		#針對每行輸出
16299
		foreach($callShell["output"] as $index=>$line){
226 liveuser 16300
 
3 liveuser 16301
			#如果是第一筆
16302
			if($index===0){
226 liveuser 16303
 
3 liveuser 16304
				#取得資料筆數
16305
				$result["dataCount"]=explode(" ",$line)[0];
226 liveuser 16306
 
3 liveuser 16307
				#換下一輪
16308
				continue;
226 liveuser 16309
 
3 liveuser 16310
				}#if end
226 liveuser 16311
 
3 liveuser 16312
			#函式說明:
16313
			#將固定格式的字串分開,並回傳分開的結果.
16314
			#回傳結果:
16315
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16316
			#$result["error"],錯誤訊息陣列
16317
			#$result["function"],當前執行的函數名稱.
16318
			#$result["argu"],使用的參數.
16319
			#$result["oriStr"],要分割的原始字串內容
16320
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
16321
			#$result["dataCounts"],爲總共分成幾段
16322
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
16323
			#必填參數:
16324
			#$conf["stringIn"],字串,要處理的字串.
16325
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
16326
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
16327
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
16328
			#可省略參數:
16329
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
16330
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
16331
			#參考資料:
16332
			#無.
16333
			#備註:
16334
			#無.
16335
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
16336
			unset($conf["stringProcess::spiltString"]);
226 liveuser 16337
 
3 liveuser 16338
			#如果執行失敗
16339
			if($spiltString["status"]==="false"){
226 liveuser 16340
 
3 liveuser 16341
				#設置執行錯誤
16342
				$result["status"]="false";
226 liveuser 16343
 
3 liveuser 16344
				#設置錯誤訊息
16345
				$result["error"]=$spiltString;
226 liveuser 16346
 
3 liveuser 16347
				#回傳結果
16348
				return $result;
226 liveuser 16349
 
3 liveuser 16350
				}#if end
226 liveuser 16351
 
3 liveuser 16352
			#如果沒有分割用的" "
16353
			if($spiltString["found"]==="false"){
226 liveuser 16354
 
3 liveuser 16355
				#設置執行錯誤
16356
				$result["status"]="false";
226 liveuser 16357
 
3 liveuser 16358
				#設置錯誤訊息
16359
				$result["error"]=$spiltString;
226 liveuser 16360
 
3 liveuser 16361
				#回傳結果
16362
				return $result;
226 liveuser 16363
 
3 liveuser 16364
				}#if end
226 liveuser 16365
 
3 liveuser 16366
			#如果分割好的數量小於8
16367
			if($spiltString["dataCounts"]<8){
226 liveuser 16368
 
3 liveuser 16369
				#設置執行錯誤
16370
				$result["status"]="false";
226 liveuser 16371
 
3 liveuser 16372
				#設置錯誤訊息
16373
				$result["error"]=$spiltString;
226 liveuser 16374
 
3 liveuser 16375
				#回傳結果
16376
				return $result;
226 liveuser 16377
 
3 liveuser 16378
				}#if end
226 liveuser 16379
 
3 liveuser 16380
			#初始化要儲存的檔案資訊陣列
16381
			$fileInfo=array();
226 liveuser 16382
 
3 liveuser 16383
			#取得 節點類型、權限
16384
			$fileInfo["nType&permission"]=$spiltString["dataArray"][0];
226 liveuser 16385
 
3 liveuser 16386
			#剔除結尾的 "."
16387
			$fileInfo["nType&permission"]=substr($fileInfo["nType&permission"],0,strlen($fileInfo["nType&permission"])-1);
226 liveuser 16388
 
3 liveuser 16389
			#取得節點類型
16390
			$fileInfo["nType"]=$fileInfo["nType&permission"][0];
226 liveuser 16391
 
3 liveuser 16392
			#取得節點權限
16393
			$fileInfo["permission"]=substr($fileInfo["nType&permission"],1);
226 liveuser 16394
 
3 liveuser 16395
			#取得擁有者賬號
16396
			$fileInfo["ownByUser"]=$spiltString["dataArray"][2];
226 liveuser 16397
 
3 liveuser 16398
			#取得群組擁有者群組
16399
			$fileInfo["ownByGroup"]=$spiltString["dataArray"][3];
226 liveuser 16400
 
3 liveuser 16401
			#取得size
16402
			$fileInfo["bytes"]=$spiltString["dataArray"][4];
226 liveuser 16403
 
16404
			#取得最後異動日期
3 liveuser 16405
			$fileInfo["date"]=$spiltString["dataArray"][5];
226 liveuser 16406
 
3 liveuser 16407
			#取得最後異動時間
16408
			$fileInfo["time"]=explode(".",$spiltString["dataArray"][6])[0];
226 liveuser 16409
 
3 liveuser 16410
			#取得最後異動的詳細時間
16411
			$fileInfo["timeDetail"]=$spiltString["dataArray"][6];
226 liveuser 16412
 
3 liveuser 16413
			#取得timezone資訊
16414
			$fileInfo["timezone"]=$spiltString["dataArray"][7];
226 liveuser 16415
 
3 liveuser 16416
			#函式說明:
16417
			#將固定格式的字串分開,並回傳分開的結果.
16418
			#回傳結果:
16419
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16420
			#$result["error"],錯誤訊息陣列
16421
			#$result["function"],當前執行的函數名稱.
16422
			#$result["argu"],使用的參數.
16423
			#$result["oriStr"],要分割的原始字串內容
16424
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
16425
			#$result["dataCounts"],爲總共分成幾段
16426
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
16427
			#必填參數:
16428
			#$conf["stringIn"],字串,要處理的字串.
16429
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
16430
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
16431
			$conf["stringProcess::spiltString"]["spiltSymbol"]=$fileInfo["date"]." ".$fileInfo["timeDetail"]." ".$fileInfo["timezone"];
16432
			#可省略參數:
16433
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
16434
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
16435
			#參考資料:
16436
			#無.
16437
			#備註:
16438
			#無.
16439
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
16440
			unset($conf["stringProcess::spiltString"]);
226 liveuser 16441
 
3 liveuser 16442
			#如果執行失敗
16443
			if($spiltString["status"]==="false"){
226 liveuser 16444
 
3 liveuser 16445
				#設置執行錯誤
16446
				$result["status"]="false";
226 liveuser 16447
 
3 liveuser 16448
				#設置錯誤訊息
16449
				$result["error"]=$spiltString;
226 liveuser 16450
 
3 liveuser 16451
				#回傳結果
16452
				return $result;
226 liveuser 16453
 
3 liveuser 16454
				}#if end
226 liveuser 16455
 
3 liveuser 16456
			#如果沒有分割用的" "
16457
			if($spiltString["found"]==="false"){
226 liveuser 16458
 
3 liveuser 16459
				#設置執行錯誤
16460
				$result["status"]="false";
226 liveuser 16461
 
3 liveuser 16462
				#設置錯誤訊息
16463
				$result["error"]=$spiltString;
226 liveuser 16464
 
3 liveuser 16465
				#回傳結果
16466
				return $result;
226 liveuser 16467
 
3 liveuser 16468
				}#if end
226 liveuser 16469
 
3 liveuser 16470
			#如果分割好的數量小於8
16471
			if($spiltString["dataCounts"]<2){
226 liveuser 16472
 
3 liveuser 16473
				#設置執行錯誤
16474
				$result["status"]="false";
226 liveuser 16475
 
3 liveuser 16476
				#設置錯誤訊息
16477
				$result["error"]=$spiltString;
226 liveuser 16478
 
3 liveuser 16479
				#回傳結果
16480
				return $result;
226 liveuser 16481
 
3 liveuser 16482
				}#if end
226 liveuser 16483
 
3 liveuser 16484
			#取得節點名稱,剔除開頭的空白.
16485
			$fileInfo["name"]=substr($spiltString["dataArray"][1],1);
226 liveuser 16486
 
3 liveuser 16487
			#排除 "." 跟 ".."
16488
			if($fileInfo["name"]==="." || $fileInfo["name"]===".."){
226 liveuser 16489
 
3 liveuser 16490
				#跳過
16491
				continue;
226 liveuser 16492
 
3 liveuser 16493
				}#if end
226 liveuser 16494
 
3 liveuser 16495
			#如果是檔案
16496
			if($fileInfo["nType"]==="-"){
226 liveuser 16497
 
3 liveuser 16498
				#取得mime type
16499
				$fileInfo["mimeType"]=@mime_content_type($conf["path"].$fileInfo["name"]);
226 liveuser 16500
 
3 liveuser 16501
				#如果讀取失敗
16502
				if($fileInfo["mimeType"]===false){
226 liveuser 16503
 
3 liveuser 16504
					#通常為沒有權限
226 liveuser 16505
 
3 liveuser 16506
					#跳過該檔案
16507
					continue;
226 liveuser 16508
 
3 liveuser 16509
					}#if end
226 liveuser 16510
 
3 liveuser 16511
				#確認檔案名稱中間含是否有 "."
16512
				#函式說明:
16513
				#取得關鍵字在字串的哪個位置(字首,字尾,中間)
16514
				#回傳結果:
16515
				#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
16516
				#$result["error"],錯誤訊息陣列.
16517
				#$result["function"],當前執行的函數名稱.
16518
				#$result["found"],是否有關鍵字存在,若為"true",代表存在;反之為"false".
16519
				#$result["argu"],傳入的參數.
16520
				#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
16521
				#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
16522
				#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
16523
				#$result["indexS"],關鍵字在被搜尋字串的哪個位置開始.
16524
				#$result["indexE"],關鍵字在被搜尋字串的哪個位置結束.
16525
				#必填參數:
16526
				#$conf["inputStr"],字串,被搜尋的字串.
16527
				$conf["search::findKeyWordPosition"]["inputStr"]=$fileInfo["name"];
16528
				#$conf["keyWord"],字串,關鍵字.
16529
				$conf["search::findKeyWordPosition"]["keyWord"]=".";
16530
				#可省略參數:
16531
				#無.
16532
				#參考資料:
16533
				#http://php.net/manual/en/function.strpos.php
16534
				#備註:
16535
				#無.
16536
				$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
16537
				unset($conf["search::findKeyWordPosition"]);
226 liveuser 16538
 
3 liveuser 16539
				#如果執行失敗
16540
				if($findKeyWordPosition["status"]==="false"){
226 liveuser 16541
 
3 liveuser 16542
					#設置執行錯誤
16543
					$result["status"]="false";
226 liveuser 16544
 
3 liveuser 16545
					#設置錯誤訊息
16546
					$result["error"]=$spiltString;
226 liveuser 16547
 
3 liveuser 16548
					#回傳結果
16549
					return $result;
226 liveuser 16550
 
3 liveuser 16551
					}#if end
226 liveuser 16552
 
3 liveuser 16553
				#如果含有 "." 存在
16554
				if($findKeyWordPosition["found"]==="true"){
226 liveuser 16555
 
3 liveuser 16556
					#如果 "." 是在中間,不是在尾巴.
16557
					if($findKeyWordPosition["center"]==="true" && $findKeyWordPosition["tail"]==="false"){
226 liveuser 16558
 
3 liveuser 16559
						#取得 "." 之後的內容
16560
						#函式說明:
16561
						#將字串特定關鍵字與其前面的內容剔除
16562
						#回傳結果:
16563
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16564
						#$result["error"],錯誤訊息陣列.
16565
						#$result["warning"],警告訊息鎮列.
16566
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
16567
						#$result["function"],當前執行的函數名稱.
16568
						#$result["argu"],使用的參數.
16569
						#$result["oriStr"],要處理的原始字串內容.
16570
						#$result["content"],處理好的的字串內容.
16571
						#$result["deleted"],被移除的內容.
16572
						#必填參數:
16573
						#$conf["stringIn"],字串,要處理的字串.
16574
						$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$fileInfo["name"];
16575
						#$conf["keyWord"],字串,特定字串.
16576
						$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=".";
16577
						#可省略參數:
16578
						#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
16579
						$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
16580
						#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
16581
						#$conf["lastResult"]=$delStrBeforeKeyWord;
16582
						#參考資料:
16583
						#無.
16584
						#備註:
16585
						#無.
16586
						$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
16587
						unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 16588
 
3 liveuser 16589
						#如果執行失敗
16590
						if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 16591
 
3 liveuser 16592
							#設置執行錯誤
16593
							$result["status"]="false";
226 liveuser 16594
 
3 liveuser 16595
							#設置錯誤訊息
16596
							$result["error"]=$spiltString;
226 liveuser 16597
 
3 liveuser 16598
							#回傳結果
16599
							return $result;
226 liveuser 16600
 
3 liveuser 16601
							}#if end
226 liveuser 16602
 
3 liveuser 16603
						#如果該存在的 "." 不存在
16604
						if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 16605
 
3 liveuser 16606
							#設置執行錯誤
16607
							$result["status"]="false";
226 liveuser 16608
 
3 liveuser 16609
							#設置錯誤訊息
16610
							$result["error"]=$spiltString;
226 liveuser 16611
 
3 liveuser 16612
							#回傳結果
16613
							return $result;
226 liveuser 16614
 
3 liveuser 16615
							}#if end
226 liveuser 16616
 
3 liveuser 16617
						#取得附檔名
16618
						$fileInfo["secondName"]=$delStrBeforeKeyWord["content"];
226 liveuser 16619
 
3 liveuser 16620
						}#if end
226 liveuser 16621
 
3 liveuser 16622
					}#if end
226 liveuser 16623
 
3 liveuser 16624
				}#if end
226 liveuser 16625
 
3 liveuser 16626
			#儲存檔案資訊
16627
			$result["content"][]=$fileInfo;
226 liveuser 16628
 
3 liveuser 16629
			}#foreach end
226 liveuser 16630
 
3 liveuser 16631
		#設置清單的長度
16632
		$result["dataCount"]=count($result["content"]);
226 liveuser 16633
 
3 liveuser 16634
		#設置執行正常
16635
		$result["status"]="true";
226 liveuser 16636
 
3 liveuser 16637
		#回傳結果
16638
		return $result;
226 liveuser 16639
 
3 liveuser 16640
		}#function ls end
16641
 
16642
	/*
16643
	#函式說明:
16644
	#將 ~ 轉換為家目錄路徑
16645
	#回傳結果:
16646
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16647
	#$result["error"],錯誤訊息.
16648
	#$result["function"],當前執行的函數名稱.
16649
	#$result["content"],轉換好的內容.
16650
	#必填參數:
16651
	#$conf["fileArgu"],字串,變數__FILE__的內容.
16652
	$conf["fileArgu"]=__FILE__;
16653
	#可省略參數:
16654
	#無.
16655
	#參考資料:
16656
	#https://www.businessweekly.com.tw/careers/Blog/14307
16657
	#備註:
16658
	#無.
16659
	*/
16660
	public static function tildeToPath(&$conf){
226 liveuser 16661
 
3 liveuser 16662
		#初始化要回傳的結果
16663
		$result=array();
16664
 
16665
		#取得當前執行的函數名稱
16666
		$result["function"]=__FUNCTION__;
16667
 
16668
		#如果沒有參數
16669
		if(func_num_args()==0){
226 liveuser 16670
 
3 liveuser 16671
			#設置執行失敗
16672
			$result["status"]="false";
226 liveuser 16673
 
3 liveuser 16674
			#設置執行錯誤訊息
16675
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 16676
 
3 liveuser 16677
			#回傳結果
16678
			return $result;
226 liveuser 16679
 
220 liveuser 16680
			}#if end
3 liveuser 16681
 
16682
		#取得參數
16683
		$result["argu"]=$conf;
16684
 
16685
		#如果 $conf 不為陣列
16686
		if(gettype($conf)!=="array"){
226 liveuser 16687
 
3 liveuser 16688
			#設置執行失敗
16689
			$result["status"]="false";
226 liveuser 16690
 
3 liveuser 16691
			#設置執行錯誤訊息
16692
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 16693
 
3 liveuser 16694
			#如果傳入的參數為 null
16695
			if($conf===null){
226 liveuser 16696
 
3 liveuser 16697
				#設置執行錯誤訊息
16698
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 16699
 
3 liveuser 16700
				}#if end
16701
 
16702
			#回傳結果
16703
			return $result;
226 liveuser 16704
 
3 liveuser 16705
			}#if end
226 liveuser 16706
 
3 liveuser 16707
		#函式說明:
16708
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
16709
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16710
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
16711
		#$result["function"],當前執行的函式名稱.
16712
		#$result["argu"],設置給予的參數.
16713
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
16714
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
16715
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
16716
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
16717
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
16718
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
16719
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
16720
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
16721
		#必填寫的參數:
16722
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 16723
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 16724
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
16725
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
16726
		#可以省略的參數:
16727
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
16728
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
16729
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
16730
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
16731
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
16732
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
16733
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
16734
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
16735
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
16736
		#$conf["canBeEmpty"]=array();
16737
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
16738
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
16739
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
16740
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 16741
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 16742
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
16743
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
16744
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
16745
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
16746
		#$conf["disallowAllSkipableVarIsEmpty"]="";
16747
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
16748
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
16749
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
16750
		#$conf["arrayCountEqualCheck"][]=array();
16751
		#參考資料來源:
16752
		#array_keys=>http://php.net/manual/en/function.array-keys.php
16753
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
16754
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 16755
 
3 liveuser 16756
		#如果檢查參數失敗
16757
		if($checkArguments["status"]==="false"){
226 liveuser 16758
 
3 liveuser 16759
			#設置執行失敗
16760
			$result["status"]="false";
226 liveuser 16761
 
3 liveuser 16762
			#設置執行失敗訊息
16763
			$result["error"]=$checkArguments;
226 liveuser 16764
 
3 liveuser 16765
			#回傳結果
16766
			return $result;
226 liveuser 16767
 
3 liveuser 16768
			}#if end
226 liveuser 16769
 
3 liveuser 16770
		#如果檢查參數不通過
16771
		if($checkArguments["passed"]==="false"){
226 liveuser 16772
 
3 liveuser 16773
			#設置執行失敗
16774
			$result["status"]="false";
226 liveuser 16775
 
3 liveuser 16776
			#設置執行失敗訊息
16777
			$result["error"]=$checkArguments;
226 liveuser 16778
 
3 liveuser 16779
			#回傳結果
16780
			return $result;
226 liveuser 16781
 
3 liveuser 16782
			}#if end
16783
 
16784
		#函式說明:
16785
		#呼叫shell執行系統命令,並取得回傳的內容.
16786
		#回傳結果:
16787
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16788
		#$result["error"],錯誤訊息陣列.
16789
		#$result["function"],當前執行的函數名稱.
16790
		#$result["argu"],使用的參數.
16791
		#$result["cmd"],執行的指令內容.
16792
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16793
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16794
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16795
		#$result["running"],是否還在執行.
16796
		#$result["pid"],pid.
16797
		#$result["statusCode"],執行結束後的代碼.
16798
		#必填參數:
16799
		#$conf["command"],字串,要執行的指令與.
16800
		$conf["external::callShell"]["command"]="echo";
16801
		#$conf["fileArgu"],字串,變數__FILE__的內容.
16802
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16803
		#可省略參數:
16804
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16805
		$conf["external::callShell"]["argu"]=array("~");
16806
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16807
		#$conf["arguIsAddr"]=array();
16808
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16809
		#$conf["plainArgu"]=array();
16810
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16811
		#$conf["useApostrophe"]=array();
16812
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16813
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16814
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16815
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16816
		#$conf["enablePrintDescription"]="true";
16817
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16818
		#$conf["printDescription"]="";
16819
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16820
		$conf["external::callShell"]["escapeshellarg"]="true";
16821
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16822
		#$conf["thereIsShellVar"]=array();
16823
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16824
		#$conf["username"]="";
16825
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16826
		#$conf["password"]="";
16827
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16828
		#$conf["useScript"]="";
16829
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16830
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16831
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16832
		#$conf["inBackGround"]="";
16833
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16834
		#$conf["getErr"]="false";
16835
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16836
		#$conf["doNotRun"]="false";
16837
		#參考資料:
16838
		#exec=>http://php.net/manual/en/function.exec.php
16839
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16840
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16841
		#備註:
16842
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16843
		$callShell=external::callShell($conf["external::callShell"]);
16844
		unset($conf["external::callShell"]);
16845
 
16846
		#如果執行失敗
16847
		if($callShell["status"]==="false"){
226 liveuser 16848
 
3 liveuser 16849
			#設置執行失敗
16850
			$result["status"]="false";
226 liveuser 16851
 
3 liveuser 16852
			#設置執行失敗訊息
16853
			$result["error"]=$callShell;
226 liveuser 16854
 
3 liveuser 16855
			#回傳結果
16856
			return $result;
226 liveuser 16857
 
3 liveuser 16858
			}#if end
226 liveuser 16859
 
3 liveuser 16860
		#如果沒有預期的輸出
16861
		if(!isset($callShell["output"][0])){
226 liveuser 16862
 
3 liveuser 16863
			#設置執行失敗
16864
			$result["status"]="false";
226 liveuser 16865
 
3 liveuser 16866
			#設置執行失敗訊息
16867
			$result["error"][]="沒有得到預期的輸出";
226 liveuser 16868
 
3 liveuser 16869
			#設置執行失敗訊息
16870
			$result["error"][]=$callShell;
226 liveuser 16871
 
3 liveuser 16872
			#回傳結果
16873
			return $result;
226 liveuser 16874
 
3 liveuser 16875
			}#if end
226 liveuser 16876
 
3 liveuser 16877
		#取得輸出
16878
		$result["content"]=$callShell["output"][0];
226 liveuser 16879
 
3 liveuser 16880
		#設置執行正常
16881
		$result["status"]="true";
226 liveuser 16882
 
3 liveuser 16883
		#回傳結果
16884
		return $result;
226 liveuser 16885
 
3 liveuser 16886
		}#function tildeToPath end
16887
 
16888
	/*
16889
	#函式說明:
16890
	#建立軟連結.
16891
	#回傳結果:
16892
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16893
	#$result["error"],錯誤訊息.
16894
	#$result["function"],當前執行的函數名稱.
16895
	#$result["content"],軟連結的資訊.
16896
	#$result["cmd"],執行的指令陣列.
16897
	#必填參數:
16898
	#$conf["fileArgu"],字串,變數__FILE__的內容.
16899
	$conf["fileArgu"]=__FILE__;
16900
	#$conf["linkTo"],字串,軟連結要指向哪邊.
16901
	$conf["linkTo"]="";
16902
	#可省略參數:
16903
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
16904
	#$conf["path"]="";
16905
	#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
16906
	#$conf["name"]="";
16907
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
16908
	#$conf["overWrite"]="true";
16909
	#參考資料:
16910
	#無.
16911
	#備註:
16912
	#無.
16913
	*/
16914
	public static function createLink(&$conf){
226 liveuser 16915
 
3 liveuser 16916
		#初始化要回傳的結果
16917
		$result=array();
16918
 
16919
		#取得當前執行的函數名稱
16920
		$result["function"]=__FUNCTION__;
16921
 
16922
		#如果沒有參數
16923
		if(func_num_args()==0){
226 liveuser 16924
 
3 liveuser 16925
			#設置執行失敗
16926
			$result["status"]="false";
226 liveuser 16927
 
3 liveuser 16928
			#設置執行錯誤訊息
16929
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 16930
 
3 liveuser 16931
			#回傳結果
16932
			return $result;
226 liveuser 16933
 
220 liveuser 16934
			}#if end
3 liveuser 16935
 
16936
		#取得參數
16937
		$result["argu"]=$conf;
16938
 
16939
		#如果 $conf 不為陣列
16940
		if(gettype($conf)!=="array"){
226 liveuser 16941
 
3 liveuser 16942
			#設置執行失敗
16943
			$result["status"]="false";
226 liveuser 16944
 
3 liveuser 16945
			#設置執行錯誤訊息
16946
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 16947
 
3 liveuser 16948
			#如果傳入的參數為 null
16949
			if($conf===null){
226 liveuser 16950
 
3 liveuser 16951
				#設置執行錯誤訊息
16952
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 16953
 
3 liveuser 16954
				}#if end
16955
 
16956
			#回傳結果
16957
			return $result;
226 liveuser 16958
 
3 liveuser 16959
			}#if end
226 liveuser 16960
 
3 liveuser 16961
		#函式說明:
16962
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
16963
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16964
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
16965
		#$result["function"],當前執行的函式名稱.
16966
		#$result["argu"],設置給予的參數.
16967
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
16968
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
16969
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
16970
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
16971
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
16972
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
16973
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
16974
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
16975
		#必填寫的參數:
16976
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 16977
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 16978
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
16979
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
16980
		#可以省略的參數:
16981
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
16982
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkTo");
16983
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
16984
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
16985
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
16986
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
16987
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
16988
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
16989
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
16990
		#$conf["canBeEmpty"]=array();
16991
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
16992
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","name","overWrite");
16993
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
16994
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","name","overWrite");
226 liveuser 16995
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 16996
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
16997
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
16998
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false");
16999
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
17000
		#$conf["disallowAllSkipableVarIsEmpty"]="";
17001
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
17002
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
17003
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
17004
		#$conf["arrayCountEqualCheck"][]=array();
17005
		#參考資料來源:
17006
		#array_keys=>http://php.net/manual/en/function.array-keys.php
17007
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
17008
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 17009
 
3 liveuser 17010
		#如果檢查參數失敗
17011
		if($checkArguments["status"]==="false"){
226 liveuser 17012
 
3 liveuser 17013
			#設置執行失敗
17014
			$result["status"]="false";
226 liveuser 17015
 
3 liveuser 17016
			#設置執行失敗訊息
17017
			$result["error"]=$checkArguments;
226 liveuser 17018
 
3 liveuser 17019
			#回傳結果
17020
			return $result;
226 liveuser 17021
 
3 liveuser 17022
			}#if end
226 liveuser 17023
 
3 liveuser 17024
		#如果檢查參數不通過
17025
		if($checkArguments["passed"]==="false"){
226 liveuser 17026
 
3 liveuser 17027
			#設置執行失敗
17028
			$result["status"]="false";
226 liveuser 17029
 
3 liveuser 17030
			#設置執行失敗訊息
17031
			$result["error"]=$checkArguments;
226 liveuser 17032
 
3 liveuser 17033
			#回傳結果
17034
			return $result;
226 liveuser 17035
 
3 liveuser 17036
			}#if end
17037
 
17038
		#如果是相對位置
17039
		if(!(strpos($conf["linkTo"],"/")===0)){
226 liveuser 17040
 
3 liveuser 17041
			#將 $conf["linkTo"] 轉換為針對產生位置的相對位置.
17042
			#函式說明:
17043
			#將多個路徑字串變成相對於當前路徑的相對路徑字串
17044
			#回傳結果:
17045
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
17046
			#$result["error"],錯誤訊息陣列.
226 liveuser 17047
			#$result["function"],函數名稱.
3 liveuser 17048
			#$result["argu"],使用的參數.
17049
			#$result["content"],字串陣列,多個轉換好的相對路徑字串.
17050
			#必填參數:
17051
			#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
17052
			$conf["fileAccess::getRelativePath"]["path"]=array($conf["linkTo"]);
17053
			#$conf["fileArgu"],字串,當前路徑.
17054
			$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
17055
			#可省略參數:
17056
			#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
17057
			$conf["fileAccess::getRelativePath"]["baseFrom"]=$conf["path"];
17058
			#參考資料:
17059
			#無.
17060
			#備註:
17061
			#無.
17062
			$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
17063
			unset($conf["fileAccess::getRelativePath"]);
17064
 
17065
			#如果執行失敗
17066
			if($getRelativePath["status"]==="false"){
226 liveuser 17067
 
3 liveuser 17068
				#設置執行失敗
17069
				$result["status"]="false";
226 liveuser 17070
 
3 liveuser 17071
				#設置執行失敗訊息
17072
				$result["error"]=$getRelativePath;
226 liveuser 17073
 
3 liveuser 17074
				#回傳結果
17075
				return $result;
226 liveuser 17076
 
3 liveuser 17077
				}#if end
17078
 
17079
			/*
17080
			#break point
17081
			var_dump($conf);
17082
			var_dump($getRelativePath);
17083
			exit;
17084
			*/
17085
 
17086
			#取得執行的指令
17087
			$result["cmd"][]=$getRelativePath["cmd"];
17088
 
17089
			#取得正確的相對位置
17090
			$conf["linkTo"]=$getRelativePath["content"][0];
226 liveuser 17091
 
3 liveuser 17092
			}#if end
17093
 
17094
		#初始化給 ln 指令的參數
17095
		$paramsForLn=array("-s",$conf["linkTo"]);
17096
 
17097
		#函式說明:
17098
		#將字串特定關鍵字與其前面的內容剔除
17099
		#回傳結果:
17100
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17101
		#$result["error"],錯誤訊息陣列.
17102
		#$result["warning"],警告訊息鎮列.
17103
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
17104
		#$result["function"],當前執行的函數名稱.
17105
		#$result["oriStr"],要處理的原始字串內容.
226 liveuser 17106
		#$result["content"],處理好的的字串內容.
3 liveuser 17107
		#必填參數:
17108
		#$conf["stringIn"],字串,要處理的字串.
17109
		$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["linkTo"];
17110
		#$conf["keyWord"],字串,特定字串.
17111
		$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="/";
17112
		#可省略參數:
17113
		#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
17114
		$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
17115
		#參考資料:
17116
		#無.
17117
		#備註:
17118
		#無.
17119
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
17120
		unset($conf["stringProcess::delStrBeforeKeyWord"]);
17121
 
17122
		#var_dump(__LINE__." ".print_r($delStrBeforeKeyWord,true));
17123
 
17124
		#如果執行失敗
17125
		if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 17126
 
3 liveuser 17127
			#設置執行失敗
17128
			$result["status"]="false";
226 liveuser 17129
 
3 liveuser 17130
			#設置執行失敗訊息
17131
			$result["error"]=$delStrBeforeKeyWord;
226 liveuser 17132
 
3 liveuser 17133
			#回傳結果
17134
			return $result;
226 liveuser 17135
 
3 liveuser 17136
			}#if end
226 liveuser 17137
 
3 liveuser 17138
		#如果沒有找到 "/"
17139
		if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 17140
 
3 liveuser 17141
			#設置 預設的 軟連名稱
17142
			$softLink=$conf["linkTo"];
226 liveuser 17143
 
3 liveuser 17144
			}#if end
17145
 
17146
		#反之有 "/"
17147
		else{
226 liveuser 17148
 
3 liveuser 17149
			#設置 預設的 軟連結名稱
17150
			$softLink=$delStrBeforeKeyWord["content"];
226 liveuser 17151
 
3 liveuser 17152
			}#else end
17153
 
17154
		/*
17155
		#break point
17156
		var_dump(__LINE__." ".$softLink);
17157
		exit;
17158
		*/
17159
 
17160
		#預設欲建立的軟連結名稱
17161
		$createdSoftLink=$softLink;
17162
 
17163
		#如果有設置 path
17164
		if(isset($conf["path"])){
226 liveuser 17165
 
3 liveuser 17166
			#確認 path 存在
17167
			#函式說明:
17168
			#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
17169
			#回傳結果:
17170
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
17171
			#$result["error"],錯誤訊息陣列
17172
			#$result["warning"],警告訊息陣列
17173
			#必填參數:
17174
			#$conf["dirPositionAndName"]="";#新建的位置與名稱
17175
			$conf["fileAccess::createNewFolder"]["dirPositionAndName"]=$conf["path"];
17176
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17177
			$conf["fileAccess::createNewFolder"]["fileArgu"]=$conf["fileArgu"];
17178
			#可省略參數:
17179
			#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
17180
			#$conf["dirPermission"]="";
17181
			#參考資料:
17182
			#mkdir=>http://php.net/manual/en/function.mkdir.php
17183
			#chmod=>http://php.net/manual/en/function.chmod.php
17184
			#參考資料:
17185
			#無.
17186
			#備註:
17187
			#同 function createFolderAfterCheck.
17188
			$createNewFolder=fileAccess::createNewFolder($conf["fileAccess::createNewFolder"]);
17189
			unset($conf["fileAccess::createNewFolder"]);
226 liveuser 17190
 
3 liveuser 17191
			#如果執行失敗
17192
			if($createNewFolder["status"]==="false"){
226 liveuser 17193
 
3 liveuser 17194
				#設置執行失敗
17195
				$result["status"]="false";
226 liveuser 17196
 
3 liveuser 17197
				#設置執行失敗訊息
17198
				$result["error"]=$createNewFolder;
226 liveuser 17199
 
3 liveuser 17200
				#回傳結果
17201
				return $result;
226 liveuser 17202
 
3 liveuser 17203
				}#if end
226 liveuser 17204
 
3 liveuser 17205
			#var_dump(__LINE__." ".print_r($conf,true));
226 liveuser 17206
 
3 liveuser 17207
			#預設要加 slash
17208
			$slash="/";
226 liveuser 17209
 
3 liveuser 17210
			#如果 path 為 "/" 結尾
17211
			if($conf["path"][strlen($conf["path"])-1]==="/"){
226 liveuser 17212
 
3 liveuser 17213
				#不用 slash
17214
				$slash="";
226 liveuser 17215
 
3 liveuser 17216
				}#if end
226 liveuser 17217
 
3 liveuser 17218
			#如果有設置 name
17219
			if(isset($conf["name"])){
226 liveuser 17220
 
3 liveuser 17221
				#指定軟連結要放在哪邊
17222
				$paramsForLn[]=$conf["path"].$slash.$conf["name"];
226 liveuser 17223
 
3 liveuser 17224
				#更新欲建立的軟連結名稱
17225
				$createdSoftLink=$conf["path"].$slash.$conf["name"];
226 liveuser 17226
 
3 liveuser 17227
				/*
17228
				#break point
17229
				var_dump($conf["path"],$softLink,$createdSoftLink);
17230
				exit;
17231
				*/
226 liveuser 17232
 
3 liveuser 17233
				}#if end
226 liveuser 17234
 
3 liveuser 17235
			#反之
17236
			else{
226 liveuser 17237
 
3 liveuser 17238
				#指定軟連結要放在哪邊
17239
				$paramsForLn[]=$conf["path"];
226 liveuser 17240
 
3 liveuser 17241
				#更新欲建立的軟連結名稱
17242
				$createdSoftLink=$conf["path"].$slash.$softLink;
226 liveuser 17243
 
3 liveuser 17244
				/*
17245
				#break point
17246
				var_dump($conf["path"],$softLink,$createdSoftLink);
17247
				exit;
17248
				*/
226 liveuser 17249
 
3 liveuser 17250
				}#else end
226 liveuser 17251
 
3 liveuser 17252
			#var_dump($createdSoftLink);
226 liveuser 17253
 
3 liveuser 17254
			}#if end
226 liveuser 17255
 
3 liveuser 17256
		#反之如果有設置 name
17257
		else if(isset($conf["name"])){
226 liveuser 17258
 
3 liveuser 17259
			#指定軟連結的名稱
17260
			$paramsForLn[]=$conf["name"];
226 liveuser 17261
 
3 liveuser 17262
			#更新欲建立的軟連結名稱
17263
			$createdSoftLink=$conf["name"];
226 liveuser 17264
 
3 liveuser 17265
			#var_dump(__LINE__." ".$createdSoftLink);
226 liveuser 17266
 
3 liveuser 17267
			}#if end
226 liveuser 17268
 
3 liveuser 17269
		/*
17270
		# break point
17271
		var_dump($createdSoftLink);
17272
		exit;
17273
		*/
226 liveuser 17274
 
3 liveuser 17275
		#如果要覆蓋既有的目標
17276
		if($conf["overWrite"]==="true"){
226 liveuser 17277
 
3 liveuser 17278
			#函式說明:
17279
			#移除檔案
17280
			#回傳結果:
17281
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
17282
			#$result["error"],錯誤訊息陣列
17283
			#$result["warning"],警告訊息陣列
17284
			#$result["function"],當前執行的函數名稱
17285
			#必填參數:
17286
			#$conf["fileAddress"],字串,要移除檔案的位置.
17287
			$conf["fileAccess::delFile"]["fileAddress"]=$createdSoftLink;
17288
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
17289
			$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
17290
			#可省略參數:
17291
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
17292
			#$conf["commentsArray"]=array("");
17293
			#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
17294
			$conf["fileAccess::delFile"]["allowDelSymlink"]="true";
17295
			#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
17296
			$conf["fileAccess::delFile"]["allowDelFolder"]="true";
17297
			#參考資料:
17298
			#無.
17299
			#備註:
17300
			#無.
17301
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
226 liveuser 17302
			unset($conf["fileAccess::delFile"]);
17303
 
3 liveuser 17304
			/*
17305
			#break point
17306
			var_dump($delFile);
17307
			exit;
17308
			*/
226 liveuser 17309
 
3 liveuser 17310
			#如果執行失敗
17311
			if($delFile["status"]==="false"){
226 liveuser 17312
 
3 liveuser 17313
				#設置執行失敗
17314
				$result["status"]="false";
226 liveuser 17315
 
3 liveuser 17316
				#設置執行失敗訊息
17317
				$result["error"]=$delFile;
226 liveuser 17318
 
3 liveuser 17319
				#回傳結果
17320
				return $result;
226 liveuser 17321
 
3 liveuser 17322
				}#if end
226 liveuser 17323
 
3 liveuser 17324
			}#if end
17325
 
17326
		#函式說明:
17327
		#呼叫shell執行系統命令,並取得回傳的內容.
17328
		#回傳結果:
17329
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17330
		#$result["error"],錯誤訊息陣列.
17331
		#$result["function"],當前執行的函數名稱.
17332
		#$result["argu"],使用的參數.
17333
		#$result["cmd"],執行的指令內容.
17334
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17335
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17336
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17337
		#$result["running"],是否還在執行.
17338
		#$result["pid"],pid.
17339
		#$result["statusCode"],執行結束後的代碼.
17340
		#必填參數:
17341
		#$conf["command"],字串,要執行的指令與.
17342
		$conf["external::callShell"]["command"]="ln";
17343
		#$conf["fileArgu"],字串,變數__FILE__的內容.
17344
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17345
		#可省略參數:
17346
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17347
		$conf["external::callShell"]["argu"]=$paramsForLn;
17348
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17349
		#$conf["arguIsAddr"]=array();
17350
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
17351
		#$conf["plainArgu"]=array();
17352
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
17353
		#$conf["useApostrophe"]=array();
17354
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17355
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17356
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17357
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17358
		#$conf["enablePrintDescription"]="true";
17359
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17360
		#$conf["printDescription"]="";
17361
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
17362
		$conf["external::callShell"]["escapeshellarg"]="true";
17363
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
17364
		#$conf["thereIsShellVar"]=array();
17365
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17366
		#$conf["username"]="";
17367
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17368
		#$conf["password"]="";
17369
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17370
		#$conf["useScript"]="";
17371
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17372
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17373
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17374
		#$conf["inBackGround"]="";
17375
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17376
		$conf["external::callShell"]["getErr"]="true";
17377
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17378
		#$conf["doNotRun"]="false";
17379
		#參考資料:
17380
		#exec=>http://php.net/manual/en/function.exec.php
17381
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17382
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17383
		#備註:
17384
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17385
		$callShell=external::callShell($conf["external::callShell"]);
17386
		unset($conf["external::callShell"]);
17387
 
17388
		#如果執行失敗
17389
		if($callShell["status"]==="false"){
226 liveuser 17390
 
3 liveuser 17391
			#設置執行失敗
17392
			$result["status"]="false";
226 liveuser 17393
 
3 liveuser 17394
			#設置執行失敗訊息
17395
			$result["error"]=$callShell;
226 liveuser 17396
 
3 liveuser 17397
			#回傳結果
17398
			return $result;
226 liveuser 17399
 
3 liveuser 17400
			}#if end
226 liveuser 17401
 
3 liveuser 17402
		#保存執行的指令
17403
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 17404
 
3 liveuser 17405
		#初始化給 ls 指令的參數
17406
		$paramsForLs=array("-l",$paramsForLn[count($paramsForLn)-1]);
226 liveuser 17407
 
3 liveuser 17408
		#取得軟連結的資訊
17409
		#函式說明:
17410
		#呼叫shell執行系統命令,並取得回傳的內容.
17411
		#回傳結果:
17412
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17413
		#$result["error"],錯誤訊息陣列.
17414
		#$result["function"],當前執行的函數名稱.
17415
		#$result["argu"],使用的參數.
17416
		#$result["cmd"],執行的指令內容.
17417
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17418
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17419
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17420
		#$result["running"],是否還在執行.
17421
		#$result["pid"],pid.
17422
		#$result["statusCode"],執行結束後的代碼.
17423
		#必填參數:
17424
		#$conf["command"],字串,要執行的指令與.
17425
		$conf["external::callShell"]["command"]="ls";
17426
		#$conf["fileArgu"],字串,變數__FILE__的內容.
17427
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17428
		#可省略參數:
17429
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17430
		$conf["external::callShell"]["argu"]=$paramsForLs;
17431
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17432
		#$conf["arguIsAddr"]=array();
17433
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
17434
		#$conf["plainArgu"]=array();
17435
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
17436
		#$conf["useApostrophe"]=array();
17437
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17438
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17439
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17440
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17441
		#$conf["enablePrintDescription"]="true";
17442
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17443
		#$conf["printDescription"]="";
17444
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
17445
		$conf["external::callShell"]["escapeshellarg"]="true";
17446
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
17447
		#$conf["thereIsShellVar"]=array();
17448
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17449
		#$conf["username"]="";
17450
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17451
		#$conf["password"]="";
17452
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17453
		#$conf["useScript"]="";
17454
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17455
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17456
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17457
		#$conf["inBackGround"]="";
17458
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17459
		$conf["external::callShell"]["getErr"]="true";
17460
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17461
		#$conf["doNotRun"]="false";
17462
		#參考資料:
17463
		#exec=>http://php.net/manual/en/function.exec.php
17464
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17465
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17466
		#備註:
17467
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17468
		$callShell=external::callShell($conf["external::callShell"]);
17469
		unset($conf["external::callShell"]);
17470
 
17471
		#如果執行失敗
17472
		if($callShell["status"]==="false"){
226 liveuser 17473
 
3 liveuser 17474
			#設置執行失敗
17475
			$result["status"]="false";
226 liveuser 17476
 
3 liveuser 17477
			#設置執行失敗訊息
17478
			$result["error"]=$callShell;
226 liveuser 17479
 
3 liveuser 17480
			#回傳結果
17481
			return $result;
226 liveuser 17482
 
3 liveuser 17483
			}#if end
226 liveuser 17484
 
3 liveuser 17485
		#保存執行的指令
17486
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 17487
 
3 liveuser 17488
		#取得軟連結的資訊
17489
		$result["content"]=$callShell["output"];
226 liveuser 17490
 
3 liveuser 17491
		#設置執行正常
17492
		$result["status"]="true";
226 liveuser 17493
 
3 liveuser 17494
		#回傳結果
17495
		return $result;
226 liveuser 17496
 
3 liveuser 17497
		}#function createLink end
17498
 
17499
	/*
17500
	#函式說明:
17501
	#針對特定目錄下的內容建立軟連結.
17502
	#回傳結果:
17503
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17504
	#$result["error"],錯誤訊息.
17505
	#$result["function"],當前執行的函數名稱.
17506
	#$result["content"],字串陣列,每個建立的軟連結資訊.
17507
	#必填參數:
17508
	#$conf["fileArgu"],字串,變數__FILE__的內容.
17509
	$conf["fileArgu"]=__FILE__;
17510
	#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
17511
	$conf["linkToDir"]="";
17512
	#可省略參數:
17513
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
17514
	#$conf["path"]="";
17515
	#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
17516
	#$conf["name"]=array(array("oriName","newName"));
17517
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
17518
	#$conf["overWrite"]="true";
17519
	#參考資料:
17520
	#無.
17521
	#備註:
17522
	#無.
17523
	*/
17524
	public static function createMultiLinkInDir(&$conf){
226 liveuser 17525
 
3 liveuser 17526
		#初始化要回傳的結果
17527
		$result=array();
17528
 
17529
		#取得當前執行的函數名稱
17530
		$result["function"]=__FUNCTION__;
17531
 
17532
		#如果沒有參數
17533
		if(func_num_args()==0){
226 liveuser 17534
 
3 liveuser 17535
			#設置執行失敗
17536
			$result["status"]="false";
226 liveuser 17537
 
3 liveuser 17538
			#設置執行錯誤訊息
17539
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 17540
 
3 liveuser 17541
			#回傳結果
17542
			return $result;
226 liveuser 17543
 
220 liveuser 17544
			}#if end
3 liveuser 17545
 
17546
		#取得參數
17547
		$result["argu"]=$conf;
17548
 
17549
		#如果 $conf 不為陣列
17550
		if(gettype($conf)!=="array"){
226 liveuser 17551
 
3 liveuser 17552
			#設置執行失敗
17553
			$result["status"]="false";
226 liveuser 17554
 
3 liveuser 17555
			#設置執行錯誤訊息
17556
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 17557
 
3 liveuser 17558
			#如果傳入的參數為 null
17559
			if($conf===null){
226 liveuser 17560
 
3 liveuser 17561
				#設置執行錯誤訊息
17562
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 17563
 
3 liveuser 17564
				}#if end
17565
 
17566
			#回傳結果
17567
			return $result;
226 liveuser 17568
 
3 liveuser 17569
			}#if end
226 liveuser 17570
 
3 liveuser 17571
		#檢查參數
17572
		#函式說明:
17573
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
17574
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17575
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
17576
		#$result["function"],當前執行的函式名稱.
17577
		#$result["argu"],設置給予的參數.
17578
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
17579
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
17580
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
17581
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
17582
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
17583
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
17584
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
17585
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
17586
		#必填寫的參數:
17587
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 17588
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 17589
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
17590
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
17591
		#可以省略的參數:
17592
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
17593
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkToDir");
17594
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
17595
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
17596
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
17597
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
17598
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
17599
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
17600
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
17601
		#$conf["canBeEmpty"]=array();
17602
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
17603
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","name","overWrite");
17604
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
17605
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","name","overWrite");
226 liveuser 17606
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 17607
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string");
17608
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
17609
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".",null,"false");
17610
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
17611
		#$conf["disallowAllSkipableVarIsEmpty"]="";
17612
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
17613
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
17614
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
17615
		#$conf["arrayCountEqualCheck"][]=array();
17616
		#參考資料來源:
17617
		#array_keys=>http://php.net/manual/en/function.array-keys.php
17618
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
17619
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 17620
 
3 liveuser 17621
		#如果檢查參數失敗
17622
		if($checkArguments["status"]==="false"){
226 liveuser 17623
 
3 liveuser 17624
			#設置執行失敗
17625
			$result["status"]="false";
226 liveuser 17626
 
3 liveuser 17627
			#設置執行失敗訊息
17628
			$result["error"]=$checkArguments;
226 liveuser 17629
 
3 liveuser 17630
			#回傳結果
17631
			return $result;
226 liveuser 17632
 
3 liveuser 17633
			}#if end
226 liveuser 17634
 
3 liveuser 17635
		#如果檢查參數不通過
17636
		if($checkArguments["passed"]==="false"){
226 liveuser 17637
 
3 liveuser 17638
			#設置執行失敗
17639
			$result["status"]="false";
226 liveuser 17640
 
3 liveuser 17641
			#設置執行失敗訊息
17642
			$result["error"]=$checkArguments;
226 liveuser 17643
 
3 liveuser 17644
			#回傳結果
17645
			return $result;
226 liveuser 17646
 
3 liveuser 17647
			}#if end
226 liveuser 17648
 
3 liveuser 17649
		#函式說明:
17650
		#取得目錄底下所有目錄與檔案清單.
17651
		#回傳結果:
17652
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
17653
		#$result["error"],錯誤訊息陣列.
17654
		#$result["function"],函數名稱.
17655
		#$result["content"],陣列,目錄底下的檔案與子目錄.
17656
		#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
17657
		#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
17658
		#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
17659
		#$result["position"],目前的位置.
17660
		#必填參數:
17661
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
17662
		$conf["fileAccess::getList"]["position"]=$conf["linkToDir"];
17663
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17664
		$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
17665
		#可省略參數:
17666
		#無
17667
		#參考資料:
17668
		#opendir=>http://php.net/manual/en/function.opendir.php
17669
		#is_dir=>http://php.net/manual/en/function.is-dir.php
17670
		#備註:
17671
		#無.
17672
		$getList=fileAccess::getList($conf["fileAccess::getList"]);
17673
		unset($conf["fileAccess::getList"]);
226 liveuser 17674
 
3 liveuser 17675
		#如果檢查參數失敗
17676
		if($getList["status"]==="false"){
226 liveuser 17677
 
3 liveuser 17678
			#設置執行失敗
17679
			$result["status"]="false";
226 liveuser 17680
 
3 liveuser 17681
			#設置執行失敗訊息
17682
			$result["error"]=$getList;
226 liveuser 17683
 
3 liveuser 17684
			#回傳結果
17685
			return $result;
226 liveuser 17686
 
3 liveuser 17687
			}#if end
226 liveuser 17688
 
3 liveuser 17689
		#針對目標目錄底下的所有檔案
17690
		foreach($getList["content"] as $oriName){
226 liveuser 17691
 
3 liveuser 17692
			#如果有設定 $conf["name"]
17693
			if(isset($conf["name"])){
226 liveuser 17694
 
3 liveuser 17695
				#預設不指定新的軟連結名稱
17696
				unset($newSoftLinkName);
226 liveuser 17697
 
3 liveuser 17698
				#針對每個原始目標的名稱
17699
				foreach($conf["name"] as $customName){
226 liveuser 17700
 
3 liveuser 17701
					#如果是指定的目標
17702
					if($oriName["name"]===$customName[0]){
226 liveuser 17703
 
3 liveuser 17704
						#設置新的軟連結名稱
17705
						$newSoftLinkName=$customName[1];
226 liveuser 17706
 
3 liveuser 17707
						}#if end
226 liveuser 17708
 
3 liveuser 17709
					}#foreach end
226 liveuser 17710
 
3 liveuser 17711
				}#if end
226 liveuser 17712
 
3 liveuser 17713
			#建立軟連結
17714
			#函式說明:
17715
			#建立軟連結.
17716
			#回傳結果:
17717
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17718
			#$result["error"],錯誤訊息.
17719
			#$result["function"],當前執行的函數名稱.
17720
			#$result["content"],軟連結的資訊.
17721
			#必填參數:
17722
			#$conf["fileArgu"],字串,變數__FILE__的內容.
17723
			$conf["fileAccess::createLink"]["fileArgu"]=$conf["fileArgu"];
17724
			#$conf["linkTo"],字串,軟連結要指向哪邊.
17725
			$conf["fileAccess::createLink"]["linkTo"]=$conf["linkToDir"]."/".$oriName["name"];
17726
			#可省略參數:
17727
			#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
17728
			$conf["fileAccess::createLink"]["path"]=$conf["path"];
226 liveuser 17729
 
3 liveuser 17730
			#如果有新的軟連結名稱
17731
			if(isset($newSoftLinkName)){
226 liveuser 17732
 
3 liveuser 17733
				#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
17734
				$conf["fileAccess::createLink"]["name"]=$newSoftLinkName;
226 liveuser 17735
 
3 liveuser 17736
				}#if end
226 liveuser 17737
 
3 liveuser 17738
			#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
17739
			$conf["fileAccess::createLink"]["overWrite"]=$conf["overWrite"];
226 liveuser 17740
 
3 liveuser 17741
			#參考資料:
17742
			#無.
17743
			#備註:
17744
			#無.
17745
			$createLink=fileAccess::createLink($conf["fileAccess::createLink"]);
17746
			unset($conf["fileAccess::createLink"]);
226 liveuser 17747
 
3 liveuser 17748
			#var_dump(__LINE__." ".print_r($createLink,true));
226 liveuser 17749
 
3 liveuser 17750
			#如果檢查參數失敗
17751
			if($createLink["status"]==="false"){
226 liveuser 17752
 
3 liveuser 17753
				#設置執行失敗
17754
				$result["status"]="false";
226 liveuser 17755
 
3 liveuser 17756
				#設置執行失敗訊息
17757
				$result["error"]=$createLink;
226 liveuser 17758
 
3 liveuser 17759
				#回傳結果
17760
				return $result;
226 liveuser 17761
 
3 liveuser 17762
				}#if end
226 liveuser 17763
 
3 liveuser 17764
			#儲存建立好的軟連結資訊
17765
			$result["content"][]=$createLink["content"];
226 liveuser 17766
 
3 liveuser 17767
			}#foreach end
226 liveuser 17768
 
3 liveuser 17769
		#設置執行正常
17770
		$result["status"]="true";
226 liveuser 17771
 
3 liveuser 17772
		#回傳結果
17773
		return $result;
226 liveuser 17774
 
3 liveuser 17775
		}#function createMultiLink end
17776
 
17777
	/*
17778
	#函式說明:
17779
	#更新檔案的內容.
17780
	#回傳結果:
17781
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17782
	#$result["error"],錯誤訊息.
17783
	#$result["function"],當前執行的函數名稱.
220 liveuser 17784
	#$result["content"],更新的資訊.
17785
	#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
17786
	#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
3 liveuser 17787
	#必填參數:
17788
	#$conf["fileArgu"],字串,變數__FILE__的內容.
17789
	$conf["fileArgu"]=__FILE__;
17790
	#$conf["file"],字串,要更新的檔案位置與名稱.
17791
	$conf["file"]="";
17792
	#可省略參數:
17793
	#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
17794
	#$conf["overWriteWith"]=array();
17795
	#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
17796
	#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
17797
	#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
17798
	#$conf["replaceLike"]="false";
17799
	#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
17800
	#$conf["addToTailWhenNoMatch"]="false";
17801
	#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
17802
	#$conf["addToTailBeforeThat"]="?\>";
220 liveuser 17803
	#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
17804
	#$conf["replaceSpecifyLine"]=array();
17805
	#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
17806
	#$conf["outputPath"]="";
3 liveuser 17807
	#參考資料:
17808
	#無.
17809
	#備註:
17810
	#無.
17811
	*/
17812
	public static function updateFile(&$conf){
226 liveuser 17813
 
3 liveuser 17814
		#初始化要回傳的結果
17815
		$result=array();
17816
 
17817
		#取得當前執行的函數名稱
17818
		$result["function"]=__FUNCTION__;
17819
 
17820
		#如果沒有參數
17821
		if(func_num_args()==0){
226 liveuser 17822
 
3 liveuser 17823
			#設置執行失敗
17824
			$result["status"]="false";
226 liveuser 17825
 
3 liveuser 17826
			#設置執行錯誤訊息
17827
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 17828
 
3 liveuser 17829
			#回傳結果
17830
			return $result;
226 liveuser 17831
 
220 liveuser 17832
			}#if end
3 liveuser 17833
 
17834
		#取得參數
17835
		$result["argu"]=$conf;
17836
 
17837
		#如果 $conf 不為陣列
17838
		if(gettype($conf)!=="array"){
226 liveuser 17839
 
3 liveuser 17840
			#設置執行失敗
17841
			$result["status"]="false";
226 liveuser 17842
 
3 liveuser 17843
			#設置執行錯誤訊息
17844
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 17845
 
3 liveuser 17846
			#如果傳入的參數為 null
17847
			if($conf===null){
226 liveuser 17848
 
3 liveuser 17849
				#設置執行錯誤訊息
17850
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 17851
 
3 liveuser 17852
				}#if end
17853
 
17854
			#回傳結果
17855
			return $result;
226 liveuser 17856
 
3 liveuser 17857
			}#if end
226 liveuser 17858
 
3 liveuser 17859
		#檢查參數
17860
		#函式說明:
17861
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
17862
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17863
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
17864
		#$result["function"],當前執行的函式名稱.
17865
		#$result["argu"],設置給予的參數.
17866
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
17867
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
17868
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
17869
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
17870
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
17871
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
17872
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
17873
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
17874
		#必填寫的參數:
17875
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
220 liveuser 17876
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 17877
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
17878
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
17879
		#可以省略的參數:
17880
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
17881
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","file");
17882
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
17883
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
17884
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
17885
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
17886
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
17887
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
17888
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
17889
		#$conf["canBeEmpty"]=array();
17890
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
220 liveuser 17891
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("overWriteWith","replaceWith","addToTailWhenNoMatch","addToTailBeforeThat","replaceLike","replaceSpecifyLine","outputPath");
3 liveuser 17892
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
220 liveuser 17893
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("overWriteWith","replaceWith","addToTailWhenNoMatch","addToTailBeforeThat","replaceLike","replaceSpecifyLine","outputPath");
226 liveuser 17894
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
220 liveuser 17895
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","string","string","string","array","string");
3 liveuser 17896
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
220 liveuser 17897
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false",null,"false",null,null);
3 liveuser 17898
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
17899
		#$conf["disallowAllSkipableVarIsEmpty"]="";
17900
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
17901
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
17902
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
17903
		#$conf["arrayCountEqualCheck"][]=array();
17904
		#參考資料來源:
17905
		#array_keys=>http://php.net/manual/en/function.array-keys.php
17906
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
17907
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 17908
 
3 liveuser 17909
		#如果檢查參數失敗
17910
		if($checkArguments["status"]==="false"){
226 liveuser 17911
 
3 liveuser 17912
			#設置執行失敗
17913
			$result["status"]="false";
226 liveuser 17914
 
3 liveuser 17915
			#設置執行失敗訊息
17916
			$result["error"]=$checkArguments;
226 liveuser 17917
 
3 liveuser 17918
			#回傳結果
17919
			return $result;
226 liveuser 17920
 
3 liveuser 17921
			}#if end
226 liveuser 17922
 
3 liveuser 17923
		#如果檢查參數不通過
17924
		if($checkArguments["passed"]==="false"){
226 liveuser 17925
 
3 liveuser 17926
			#設置執行失敗
17927
			$result["status"]="false";
226 liveuser 17928
 
3 liveuser 17929
			#設置執行失敗訊息
17930
			$result["error"]=$checkArguments;
226 liveuser 17931
 
3 liveuser 17932
			#回傳結果
17933
			return $result;
226 liveuser 17934
 
3 liveuser 17935
			}#if end
226 liveuser 17936
 
3 liveuser 17937
		#檢查檔案是否存在
17938
		#函式說明:
17939
		#檢查多個檔案與資料夾是否存在.
17940
		#回傳的結果:
17941
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
17942
		#$result["error"],錯誤訊息陣列.
17943
		#$resutl["function"],當前執行的涵式名稱.
17944
		#$result["argu"],使用的參數.
17945
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
17946
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
17947
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
17948
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
17949
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
17950
		#必填參數:
17951
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
17952
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
17953
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17954
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
17955
		#可省略參數:
17956
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
17957
		$conf["disableWebSearch"]="true";
17958
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
17959
		$conf["userDir"]="false";
17960
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
17961
		$conf["web"]="false";
17962
		#參考資料:
17963
		#http://php.net/manual/en/function.file-exists.php
17964
		#http://php.net/manual/en/control-structures.foreach.php
17965
		#備註:
17966
		#函數file_exists檢查的路徑為檔案系統的路徑
17967
		#$result["varName"][$i]結果未實作
17968
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
17969
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 17970
 
3 liveuser 17971
		#如果檢查參數失敗
17972
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 17973
 
3 liveuser 17974
			#設置執行失敗
17975
			$result["status"]="false";
226 liveuser 17976
 
3 liveuser 17977
			#設置執行失敗訊息
17978
			$result["error"]=$checkMultiFileExist;
226 liveuser 17979
 
3 liveuser 17980
			#回傳結果
17981
			return $result;
226 liveuser 17982
 
3 liveuser 17983
			}#if end
226 liveuser 17984
 
3 liveuser 17985
		#如果目標檔案不存在
17986
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 17987
 
3 liveuser 17988
			#設置執行失敗
17989
			$result["status"]="false";
226 liveuser 17990
 
3 liveuser 17991
			#設置執行失敗訊息
17992
			$result["error"]=$checkMultiFileExist;
226 liveuser 17993
 
3 liveuser 17994
			#回傳結果
17995
			return $result;
226 liveuser 17996
 
3 liveuser 17997
			}#if end
226 liveuser 17998
 
220 liveuser 17999
		#預設要寫入的位置為原始檔案
18000
		$file2write=$conf["file"];
226 liveuser 18001
 
220 liveuser 18002
		#如果有設置 outputPath
18003
		if(isset($conf["outputPath"])){
226 liveuser 18004
 
220 liveuser 18005
			#寫入檔案的路徑與名稱
18006
			$file2write=$conf["outputPath"]."/".$conf["file"];
226 liveuser 18007
 
220 liveuser 18008
			}#if end
226 liveuser 18009
 
3 liveuser 18010
		#如果有設置 overWriteWith
18011
		if(isset($conf["overWriteWith"])){
226 liveuser 18012
 
3 liveuser 18013
			#函式說明:
18014
			#將多行字串寫入到檔案
18015
			#回傳結果:
18016
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
18017
			#$result["error"],錯誤訊息陣列.
18018
			#$result["function"],當前執行函數的名稱.
18019
			#必填參數:
18020
			#$conf["fileName"],字串,爲要編輯的檔案名稱
220 liveuser 18021
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
3 liveuser 18022
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
18023
			$conf["fileAccess::writeMultiLine"]["inputString"]=$conf["overWriteWith"];
18024
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18025
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
220 liveuser 18026
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
18027
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
3 liveuser 18028
			#可省略參數:
18029
			#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
18030
			#參考資料:
18031
			#無.
18032
			#備註:
18033
			#無.
18034
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
18035
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 18036
 
3 liveuser 18037
			#如果執行失敗
18038
			if($writeMultiLine["status"]==="false"){
226 liveuser 18039
 
3 liveuser 18040
				#設置執行失敗
18041
				$result["status"]="false";
226 liveuser 18042
 
3 liveuser 18043
				#設置執行失敗訊息
18044
				$result["error"]=$writeMultiLine;
226 liveuser 18045
 
3 liveuser 18046
				#回傳結果
18047
				return $result;
226 liveuser 18048
 
3 liveuser 18049
				}#if end
226 liveuser 18050
 
220 liveuser 18051
			#取得原始檔案的內容
18052
			#函式說明:
18053
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
18054
			#回傳的變數說明:
18055
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
18056
			#$result["error"],錯誤訊息提示.
18057
			#$result["warning"],警告訊息.
18058
			#$result["function"],當前執行的函數名稱.
18059
			#$result["fileContent"],爲檔案的內容陣列.
18060
			#$result["lineCount"],爲檔案內容總共的行數.
18061
			#$result["fullContent"],為檔案的完整內容.
18062
			#$result["base64data"],為檔案的base64內容.
18063
			#$result["mimeType"],為檔案的mime type.
18064
			#必填參數:
18065
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
18066
			$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
18067
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18068
			$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
18069
			#可省略參數:
18070
			#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
18071
			$conf["fileAccess::getFileContent"]["web"]="false";
18072
			#參考資料:
18073
			#file(),取得檔案內容的行數.
18074
			#file=>http:#php.net/manual/en/function.file.php
18075
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
18076
			#filesize=>http://php.net/manual/en/function.filesize.php
18077
			#參考資料:
18078
			#無.
18079
			#備註:
18080
			#無.
18081
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
18082
			unset($conf["fileAccess::getFileContent"]);
226 liveuser 18083
 
220 liveuser 18084
			#如果執行失敗
18085
			if($getFileContent["status"]==="false"){
226 liveuser 18086
 
220 liveuser 18087
				#設置執行失敗
18088
				$result["status"]="false";
226 liveuser 18089
 
220 liveuser 18090
				#設置執行失敗訊息
18091
				$result["error"]=$getFileContent;
226 liveuser 18092
 
220 liveuser 18093
				#回傳結果
18094
				return $result;
226 liveuser 18095
 
220 liveuser 18096
				}#if end
226 liveuser 18097
 
220 liveuser 18098
			#無窮迴圈
18099
			for($i=0;$i>=0;$i++){
226 liveuser 18100
 
220 liveuser 18101
				#如果有舊或新的行內容存在
18102
				if( isset($getFileContent["fileContent"][$i]) || isset($conf["overWriteWith"][$i]) ){
226 liveuser 18103
 
220 liveuser 18104
					#初始化暫存舊行內容的變數
18105
					$oriLine=null;
226 liveuser 18106
 
220 liveuser 18107
					#初始化暫存新行內容的變數
18108
					$newLine=null;
226 liveuser 18109
 
220 liveuser 18110
					#如果存在原行內容
18111
					if(isset($getFileContent["fileContent"][$i])){
226 liveuser 18112
 
220 liveuser 18113
						#儲存原行內容
18114
						$oriLine=$getFileContent["fileContent"][$i];
226 liveuser 18115
 
220 liveuser 18116
						}#if end
226 liveuser 18117
 
220 liveuser 18118
					#如果存在新行內容
18119
					if(isset($conf["overWriteWith"][$i])){
226 liveuser 18120
 
220 liveuser 18121
						#儲存新行內容
18122
						$newLine=$conf["overWriteWith"][$i];
226 liveuser 18123
 
220 liveuser 18124
						}#if end
226 liveuser 18125
 
220 liveuser 18126
					#設置更新的資訊
18127
					$result["content"][$i]=array("ori"=>$oriLine,"new"=>$newLine);
226 liveuser 18128
 
220 liveuser 18129
					}#if end
226 liveuser 18130
 
220 liveuser 18131
				#反之
18132
				else{
226 liveuser 18133
 
220 liveuser 18134
					#結束迴圈
18135
					break;
226 liveuser 18136
 
220 liveuser 18137
					}#else end
226 liveuser 18138
 
220 liveuser 18139
				}#for end
226 liveuser 18140
 
3 liveuser 18141
			}#if end
226 liveuser 18142
 
220 liveuser 18143
		#反之如果有設置 "replaceWith"
18144
		else if(isset($conf["replaceWith"])){
226 liveuser 18145
 
3 liveuser 18146
			#取得檔案的內容
18147
			#函式說明:
18148
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
18149
			#回傳的變數說明:
18150
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
18151
			#$result["error"],錯誤訊息提示.
18152
			#$result["warning"],警告訊息.
18153
			#$result["function"],當前執行的函數名稱.
18154
			#$result["fileContent"],爲檔案的內容陣列.
18155
			#$result["lineCount"],爲檔案內容總共的行數.
18156
			#$result["fullContent"],為檔案的完整內容.
18157
			#$result["base64data"],為檔案的base64內容.
18158
			#$result["mimeType"],為檔案的mime type.
18159
			#必填參數:
18160
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
18161
			$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
18162
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18163
			$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
18164
			#可省略參數:
18165
			#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
18166
			$conf["fileAccess::getFileContent"]["web"]="false";
18167
			#參考資料:
18168
			#file(),取得檔案內容的行數.
18169
			#file=>http:#php.net/manual/en/function.file.php
18170
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
18171
			#filesize=>http://php.net/manual/en/function.filesize.php
18172
			#參考資料:
18173
			#無.
18174
			#備註:
18175
			#無.
18176
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
18177
			unset($conf["fileAccess::getFileContent"]);
226 liveuser 18178
 
3 liveuser 18179
			#如果執行失敗
18180
			if($getFileContent["status"]==="false"){
226 liveuser 18181
 
3 liveuser 18182
				#設置執行失敗
18183
				$result["status"]="false";
226 liveuser 18184
 
3 liveuser 18185
				#設置執行失敗訊息
18186
				$result["error"]=$getFileContent;
226 liveuser 18187
 
3 liveuser 18188
				#回傳結果
18189
				return $result;
226 liveuser 18190
 
3 liveuser 18191
				}#if end
226 liveuser 18192
 
3 liveuser 18193
			#取得原始檔案的每行內容
18194
			$oriFileContentByLine=&$getFileContent["fileContent"];
226 liveuser 18195
 
3 liveuser 18196
			#針對每個 replaceWith 條件
18197
			foreach($conf["replaceWith"] as $replaceInfo){
226 liveuser 18198
 
3 liveuser 18199
				#預設尚未找到符合的關鍵字
18200
				$foundKeyWord=false;
226 liveuser 18201
 
3 liveuser 18202
				#取得要替換的目標字串
18203
				$oriStr=$replaceInfo[0];
226 liveuser 18204
 
3 liveuser 18205
				#取得要替換成的字串內容
18206
				$newStr=$replaceInfo[1];
226 liveuser 18207
 
3 liveuser 18208
				#針對每行原始內容
18209
				foreach($oriFileContentByLine as $index => $line){
226 liveuser 18210
 
3 liveuser 18211
					#函式說明:
18212
					#檢查字串裡面有無指定的關鍵字
18213
					#回傳結果:
18214
					#$result["status"],"true"代表執行成功,"false"代表執行失敗。
18215
					#$result["error"],錯誤訊息
18216
					#$result["function"],當前執行的函數名稱.
18217
					#$result["argu"],使用的參數.
18218
					#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
18219
					#$result["keyWordCount"],找到的關鍵字數量.
18220
					#必填參數:
18221
					#$conf["keyWord"],字串,想要搜尋的關鍵字.
18222
					$conf["search::findKeyWord"]["keyWord"]=$oriStr;
18223
					#$conf["string"],字串,要被搜尋的字串內容
18224
					$conf["search::findKeyWord"]["string"]=$line;
18225
					#可省略參數:
226 liveuser 18226
 
3 liveuser 18227
					#如果要完全符合關鍵字
18228
					if($conf["replaceLike"]==="false"){
226 liveuser 18229
 
3 liveuser 18230
						#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
18231
						$conf["search::findKeyWord"]["completeEqual"]="true";
226 liveuser 18232
 
3 liveuser 18233
						}#if end
226 liveuser 18234
 
3 liveuser 18235
					#參考資料:
18236
					#無.
18237
					#備註:
18238
					#無.
18239
					$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
18240
					unset($conf["search::findKeyWord"]);
226 liveuser 18241
 
3 liveuser 18242
					#如果執行失敗
18243
					if($findKeyWord["status"]==="false"){
226 liveuser 18244
 
3 liveuser 18245
						#設置執行失敗
18246
						$result["status"]="false";
226 liveuser 18247
 
3 liveuser 18248
						#設置執行失敗訊息
18249
						$result["error"]=$findKeyWord;
226 liveuser 18250
 
3 liveuser 18251
						#回傳結果
18252
						return $result;
226 liveuser 18253
 
3 liveuser 18254
						}#if end
226 liveuser 18255
 
3 liveuser 18256
					#如果有找到關鍵字
18257
					if($findKeyWord["founded"]==="true"){
226 liveuser 18258
 
220 liveuser 18259
						#設置更新的資訊
18260
						$result["content"][$lineIndex]=array("ori"=>$oriFileContentByLine[$index],"new"=>$newStr);
226 liveuser 18261
 
3 liveuser 18262
						#更新該行內容
18263
						$oriFileContentByLine[$index]=$newStr;
226 liveuser 18264
 
3 liveuser 18265
						#設置有找到符合的關鍵字
18266
						$foundKeyWord=true;
226 liveuser 18267
 
3 liveuser 18268
						}#if end
226 liveuser 18269
 
3 liveuser 18270
					}#foreach end
226 liveuser 18271
 
3 liveuser 18272
				#如果沒有找到關鍵字
18273
				if($foundKeyWord===false){
226 liveuser 18274
 
3 liveuser 18275
					#如果要新增內容
18276
					if($conf["addToTailWhenNoMatch"]==="true"){
226 liveuser 18277
 
3 liveuser 18278
						#如果有設置 addToTailBeforeThat
18279
						if(isset($conf["addToTailBeforeThat"])){
226 liveuser 18280
 
3 liveuser 18281
							#預設沒有找到符合的關鍵字
18282
							$foundKeyWord=false;
226 liveuser 18283
 
3 liveuser 18284
							#初始化要記錄要 append 回去的各行內容.
18285
							$linesToAppend=array();
226 liveuser 18286
 
3 liveuser 18287
							#倒敘,針對每行內容
18288
							for($i=count($oriFileContentByLine)-1;$i>=0;$i--){
226 liveuser 18289
 
3 liveuser 18290
								#儲存要 append 回去的行內容
18291
								$linesToAppend[]=$oriFileContentByLine[$i];
226 liveuser 18292
 
3 liveuser 18293
								#如果找到關鍵字了
18294
								if($oriFileContentByLine[$i]===$conf["addToTailBeforeThat"]){
226 liveuser 18295
 
3 liveuser 18296
									#設置有找到符合的關鍵字
18297
									$foundKeyWord=true;
226 liveuser 18298
 
220 liveuser 18299
									#設置更新的資訊
18300
									$result["content"][$lineIndex]=array("ori"=>$oriFileContentByLine[$i],"new"=>$line);
226 liveuser 18301
 
3 liveuser 18302
									#更新該行內容
18303
									$oriFileContentByLine[$i]=$line;
226 liveuser 18304
 
3 liveuser 18305
									#倒敘陣列
18306
									$linesToAppend=array_reverse($linesToAppend);
226 liveuser 18307
 
3 liveuser 18308
									#針對每行要 append 回去的內容
18309
									foreach($linesToAppend as $lineToAppend){
226 liveuser 18310
 
3 liveuser 18311
										#append 行內容
18312
										$oriFileContentByLine[]=$lineToAppend;
226 liveuser 18313
 
220 liveuser 18314
										#設置更新的資訊
18315
										$result["content"][count($oriFileContentByLine)-1]=array("ori"=>null,"new"=>$lineToAppend);
226 liveuser 18316
 
3 liveuser 18317
										}#foreach end
226 liveuser 18318
 
3 liveuser 18319
									}#if end
226 liveuser 18320
 
3 liveuser 18321
								}#for end
226 liveuser 18322
 
3 liveuser 18323
							#如果沒有找到關鍵字
18324
							if($foundKeyWord===false){
226 liveuser 18325
 
3 liveuser 18326
								#設置執行失敗
18327
								$result["status"]="false";
226 liveuser 18328
 
3 liveuser 18329
								#設置錯誤訊息
18330
								$result["error"]="can't find \"".$conf["addToTailBeforeThat"]."\" to insert before it.";
226 liveuser 18331
 
3 liveuser 18332
								#回傳結果
18333
								return $result;
226 liveuser 18334
 
3 liveuser 18335
								}#if end
226 liveuser 18336
 
3 liveuser 18337
							}#if end
226 liveuser 18338
 
3 liveuser 18339
						}#if end
226 liveuser 18340
 
3 liveuser 18341
					}#if end
226 liveuser 18342
 
3 liveuser 18343
				}#foreach end
226 liveuser 18344
 
3 liveuser 18345
			#函式說明:
18346
			#將多行字串寫入到檔案
18347
			#回傳結果:
18348
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
18349
			#$result["error"],錯誤訊息陣列.
18350
			#$result["function"],當前執行函數的名稱.
18351
			#必填參數:
18352
			#$conf["fileName"],字串,爲要編輯的檔案名稱
220 liveuser 18353
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
3 liveuser 18354
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
18355
			$conf["fileAccess::writeMultiLine"]["inputString"]=$oriFileContentByLine;
18356
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18357
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
18358
			#可省略參數:
18359
			#$conf["fileAccess::writeMultiLine"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
220 liveuser 18360
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
18361
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
3 liveuser 18362
			#參考資料:
18363
			#無.
18364
			#備註:
18365
			#無.
18366
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
18367
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 18368
 
3 liveuser 18369
			#如果執行失敗
18370
			if($writeMultiLine["status"]==="false"){
226 liveuser 18371
 
3 liveuser 18372
				#設置執行失敗
18373
				$result["status"]="false";
226 liveuser 18374
 
3 liveuser 18375
				#設置執行失敗訊息
18376
				$result["error"]=$writeMultiLine;
226 liveuser 18377
 
3 liveuser 18378
				#回傳結果
18379
				return $result;
226 liveuser 18380
 
3 liveuser 18381
				}#if end
226 liveuser 18382
 
3 liveuser 18383
			}#if end
226 liveuser 18384
 
220 liveuser 18385
		#反之如果有設置 replaceSpecifyLine
18386
		else if(isset($conf["replaceSpecifyLine"])){
226 liveuser 18387
 
220 liveuser 18388
			#讀取原始檔案內容
18389
			#函式說明:
18390
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
18391
			#回傳的變數說明:
18392
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
18393
			#$result["error"],錯誤訊息提示.
18394
			#$result["warning"],警告訊息.
18395
			#$result["function"],當前執行的函數名稱.
18396
			#$result["fileContent"],爲檔案的內容陣列.
18397
			#$result["lineCount"],爲檔案內容總共的行數.
18398
			#$result["fullContent"],為檔案的完整內容.
18399
			#$result["base64dataOnly"],檔案的base64data.
18400
			#$result["base64data"],為在網頁上給予src參數的數值.
18401
			#$result["mimeType"],為檔案的mime type.
18402
			#必填參數:
18403
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
18404
			$conf["fileAcceess::getFileContent"]["filePositionAndName"]=$conf["file"];
18405
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18406
			$conf["fileAcceess::getFileContent"]["fileArgu"]=__FILE__;
18407
			#可省略參數:
18408
			#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
18409
			#$conf["web"]="true";
18410
			#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
18411
			#$conf["createIfnotExist"]="false";
18412
			#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
18413
			#$conf["autoDeleteSpaceOnEachLineStart"]="false";
18414
			#參考資料:
18415
			#file(),取得檔案內容的行數.
18416
			#file=>http:#php.net/manual/en/function.file.php
18417
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
18418
			#filesize=>http://php.net/manual/en/function.filesize.php
18419
			#參考資料:
18420
			#無.
18421
			#備註:
18422
			#無.
18423
			$getFileContent=fileAccess::getFileContent($conf["fileAcceess::getFileContent"]);
18424
			unset($conf["fileAcceess::getFileContent"]);
226 liveuser 18425
 
220 liveuser 18426
			#如果執行失敗
18427
			if($getFileContent["status"]==="false"){
226 liveuser 18428
 
220 liveuser 18429
				#設置執行失敗
18430
				$result["status"]="false";
226 liveuser 18431
 
220 liveuser 18432
				#設置執行失敗訊息
18433
				$result["error"]=$getFileContent;
226 liveuser 18434
 
220 liveuser 18435
				#回傳結果
18436
				return $result;
226 liveuser 18437
 
220 liveuser 18438
				}#if end
226 liveuser 18439
 
220 liveuser 18440
			#針對每個要更新的行
18441
			foreach($conf["replaceSpecifyLine"] as $lineIndex => $newLineContent){
226 liveuser 18442
 
220 liveuser 18443
				#設置更新的資訊
18444
				$result["content"][$lineIndex]=array("ori"=>$getFileContent["fileContent"][$lineIndex],"new"=>$newLineContent);
226 liveuser 18445
 
220 liveuser 18446
				#更新行內容
18447
				$getFileContent["fileContent"][$lineIndex]=$newLineContent;
226 liveuser 18448
 
220 liveuser 18449
				}#foreach end
226 liveuser 18450
 
220 liveuser 18451
			#debug
18452
			#var_dump(__FILE__,__LINE__,count($getFileContent["fileContent"]));
226 liveuser 18453
 
220 liveuser 18454
			#將變更寫入到檔案裡面
18455
			#函式說明:
18456
			#將多行字串寫入到檔案
18457
			#回傳結果:
18458
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
18459
			#$result["error"],錯誤訊息陣列.
18460
			#$result["function"],當前執行函數的名稱.
18461
			#必填參數:
18462
			#$conf["fileName"],字串,爲要編輯的檔案名稱
18463
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
18464
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
18465
			$conf["fileAccess::writeMultiLine"]["inputString"]=$getFileContent["fileContent"];
18466
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
18467
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=__FILE__;
18468
			#可省略參數:
18469
			$conf["fileAccess::writeMultiLine"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
18470
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
18471
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
18472
			#參考資料:
18473
			#無.
18474
			#備註:
18475
			#無.
18476
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
18477
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 18478
 
220 liveuser 18479
			#如果執行失敗
18480
			if($writeMultiLine["status"]==="false"){
226 liveuser 18481
 
220 liveuser 18482
				#設置執行失敗
18483
				$result["status"]="false";
226 liveuser 18484
 
220 liveuser 18485
				#設置執行失敗訊息
18486
				$result["error"]=$writeMultiLine;
226 liveuser 18487
 
220 liveuser 18488
				#回傳結果
18489
				return $result;
226 liveuser 18490
 
220 liveuser 18491
				}#if end
226 liveuser 18492
 
220 liveuser 18493
			#debug
18494
			#var_dump(__FILE__,__LINE__,$writeMultiLine);exit(1);
226 liveuser 18495
 
220 liveuser 18496
			}#if end
226 liveuser 18497
 
3 liveuser 18498
		#設置執行正常
18499
		$result["status"]="true";
226 liveuser 18500
 
3 liveuser 18501
		#回傳結果
18502
		return $result;
226 liveuser 18503
 
3 liveuser 18504
		}#function updateFile end
226 liveuser 18505
 
3 liveuser 18506
	/*
18507
	#函式說明:
18508
	#輔助使用PHP內建的chmod函式.
18509
	#回傳結果:
18510
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18511
	#$result["error"],錯誤訊息.
18512
	#$result["function"],當前執行的函式名稱.
18513
	#$result["argu"],使用的參數.
18514
	#$result["cmd"],執行的指令.
18515
	#$result["content"],執行的結果陣列,如果參數 "recursive" 跟 "excludeSelf" 都有設定的話,就會回傳該結果.
18516
	#必填參數:
18517
	#$conf["mode"],字串,要變成什麼權限.
18518
	$conf["mode"]="";
18519
	#$conf["target"],字串,需要變更權限的目標.
18520
	$conf["target"]="";
18521
	#可省略參數:
18522
	#無.
18523
	#參考資料:
18524
	#無.
18525
	#備註:
18526
	#無.
18527
	*/
18528
	public static function chmod(&$conf){
226 liveuser 18529
 
3 liveuser 18530
		#初始化要回傳的結果
18531
		$result=array();
18532
 
18533
		#取得當前執行的函數名稱
18534
		$result["function"]=__FUNCTION__;
18535
 
18536
		#如果沒有參數
18537
		if(func_num_args()==0){
18538
 
18539
			#設置執行失敗
18540
			$result["status"]="false";
18541
 
18542
			#設置執行錯誤訊息
18543
			$result["error"]="函數".$result["function"]."需要參數";
18544
 
18545
			#回傳結果
18546
			return $result;
18547
 
18548
			}#if end
18549
 
18550
		#取得參數
18551
		$result["argu"]=$conf;
18552
 
18553
		#如果 $conf 不為陣列
18554
		if(gettype($conf)!=="array"){
18555
 
18556
			#設置執行失敗
18557
			$result["status"]="false";
18558
 
18559
			#設置執行錯誤訊息
18560
			$result["error"][]="\$conf變數須為陣列形態";
18561
 
18562
			#如果傳入的參數為 null
18563
			if(is_null($conf)){
18564
 
18565
				#設置執行錯誤訊息
18566
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
18567
 
18568
				}#if end
18569
 
18570
			#回傳結果
18571
			return $result;
18572
 
18573
			}#if end
226 liveuser 18574
 
3 liveuser 18575
		#函式說明:
18576
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
18577
		#回傳結果:
18578
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18579
		#$result["error"],執行不正常結束的錯訊息陣列.
18580
		#$result["simpleError"],簡單表示的錯誤訊息.
18581
		#$result["function"],當前執行的函式名稱.
18582
		#$result["argu"],設置給予的參數.
18583
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
18584
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
18585
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
18586
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
18587
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
18588
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
18589
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
18590
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
18591
		#必填參數:
18592
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
18593
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
18594
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
18595
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
18596
		#可省略參數:
18597
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
18598
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mode","target");
18599
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
18600
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
18601
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
18602
		#$conf["canBeEmptyString"]="false";
18603
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
18604
		#$conf["canNotBeEmpty"]=array();
18605
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
18606
		#$conf["canBeEmpty"]=array();
18607
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
18608
		#$conf["skipableVariableCanNotBeEmpty"]=array();
18609
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
18610
		#$conf["skipableVariableName"]=array();
18611
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
18612
		#$conf["skipableVariableType"]=array();
18613
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
18614
		#$conf["skipableVarDefaultValue"]=array("");
18615
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
18616
		#$conf["disallowAllSkipableVarIsEmpty"]="";
18617
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
18618
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
18619
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
18620
		#$conf["arrayCountEqualCheck"][]=array();
18621
		#參考資料:
18622
		#array_keys=>http://php.net/manual/en/function.array-keys.php
18623
		#備註:
18624
		#無.
18625
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
18626
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 18627
 
3 liveuser 18628
		#如果檢查參數失敗
18629
		if($checkArguments["status"]==="false"){
226 liveuser 18630
 
3 liveuser 18631
			#設置執行失敗
18632
			$result["status"]="false";
18633
 
18634
			#設置錯誤資訊
18635
			$result["error"]=$checkArguments;
226 liveuser 18636
 
3 liveuser 18637
			#回傳結果
18638
			return $result;
226 liveuser 18639
 
3 liveuser 18640
			}#if end
226 liveuser 18641
 
3 liveuser 18642
		#如果檢查參數不通過
18643
		if($checkArguments["passed"]==="false"){
226 liveuser 18644
 
3 liveuser 18645
			#設置執行失敗
18646
			$result["status"]="false";
18647
 
18648
			#設置錯誤資訊
18649
			$result["error"]=$checkArguments;
226 liveuser 18650
 
3 liveuser 18651
			#回傳結果
18652
			return $result;
226 liveuser 18653
 
3 liveuser 18654
			}#if end
226 liveuser 18655
 
3 liveuser 18656
		#將$conf["mode"]轉換為10進位的整數
18657
		$conf["mode"]=(int)base_convert($conf["mode"],8,10);
226 liveuser 18658
 
3 liveuser 18659
		#變更 target 的檔案權限為代碼
226 liveuser 18660
		$chmod=chmod($conf["target"],$conf["mode"]);
18661
 
3 liveuser 18662
		#如果改變檔案權限失敗
18663
		if($chmod===false){
226 liveuser 18664
 
3 liveuser 18665
			#設置執行失敗
18666
			$result["status"]="false";
226 liveuser 18667
 
3 liveuser 18668
			#設置錯誤訊息
18669
			$result["error"][]="改變 ".$conf["target"]." 檔案的權限資訊為 ".$conf["mode"]." 失敗,通常只有系統帳戶才能變更之.";
226 liveuser 18670
 
3 liveuser 18671
			#回傳結果
226 liveuser 18672
			return $result;
18673
 
3 liveuser 18674
			}#if end
226 liveuser 18675
 
3 liveuser 18676
		#設置執行正常
18677
		$result["status"]="true";
226 liveuser 18678
 
3 liveuser 18679
		#回傳結果
18680
		return $result;
226 liveuser 18681
 
3 liveuser 18682
		}#function chmod end
18683
 
18684
	}#class fileAccess end
18685
 
226 liveuser 18686
?>