Subversion Repositories php-qbpwcf

Rev

Rev 226 | Go to most recent revision | Details | 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.
6
    Copyright (C) 2015~2024 Min-Jhin,Chen
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
使用LibreOffice的類別
29
備註:
30
無.
31
*/
32
class libreoffice{
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){
48
 
49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
51
 
52
		#設置執行不正常
53
		$result["status"]="false";
54
 
55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
57
 
58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
60
 
61
		#回傳結果
62
		return $result;
63
 
64
		}#function __call end
65
 
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){
80
 
81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
83
 
84
		#設置執行不正常
85
		$result["status"]="false";
86
 
87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
89
 
90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
92
 
93
		#回傳結果
94
		return $result;
95
 
96
		}#function __callStatic end
97
 
98
	/*
99
	#函式說明:
100
	#將可被libreoffice支援的檔案轉存成pdf檔案
101
	#回傳結果:
102
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
103
	#$result["error"],錯誤訊息.
104
	#$result["function"],當前執行的函式名稱.
105
	#$result["argu"],所使用的參數.
106
	#$result["content"],轉換成pdf的檔案路徑與名稱.
107
	#必填參數:
108
	#$conf["inputFile"],字串,要轉換成pdf檔案的來源檔案路徑與名稱.
109
	$conf["inputFile"]="";
110
	#可省略參數:
111
	#無,
112
	#參考資料:
113
	#https://stackoverflow.com/questions/9056776/running-libreoffice-from-php-exec
114
	#備註:
115
	#參考語法 -> libreoffice --convert-to pdf latest.qbpwcf.org.html
116
	#非一般使用者需要指定系統變數 HOME
117
	*/
118
	public static function toPdf(&$conf=array()){
119
 
120
		#初始化要回傳的結果
121
		$result=array();
122
 
123
		#初始化語法
124
		$result["content"]="";
125
 
126
		#取得當前執行的函數名稱
127
		$result["function"]=__FUNCTION__;
128
 
129
		#如果沒有參數
130
		if(func_num_args()==0){
131
 
132
			#設置執行失敗
133
			$result["status"]="false";
134
 
135
			#設置執行錯誤訊息
136
			$result["error"]="函數".$result["function"]."需要參數";
137
 
138
			#回傳結果
139
			return $result;
140
 
141
			}#if end
142
 
143
		#取得參數
144
		$result["argu"]=$conf;
145
 
146
		#如果 $conf 不為陣列
147
		if(gettype($conf)!="array"){
148
 
149
			#設置執行失敗
150
			$result["status"]="false";
151
 
152
			#設置執行錯誤訊息
153
			$result["error"][]="\$conf變數須為陣列形態";
154
 
155
			#如果傳入的參數為 null
156
			if($conf==null){
157
 
158
				#設置執行錯誤訊息
159
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
160
 
161
				}#if end
162
 
163
			#回傳結果
164
			return $result;
165
 
166
			}#if end
167
 
168
		#函式說明:
169
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
170
		#回傳結果:
171
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
172
		#$result["error"],執行不正常結束的錯訊息陣列.
173
		#$result["simpleError"],簡單表示的錯誤訊息.
174
		#$result["function"],當前執行的函式名稱.
175
		#$result["argu"],設置給予的參數.
176
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
177
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
178
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
179
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
180
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
181
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
182
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
183
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
184
		#必填參數:
185
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
186
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
187
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
188
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
189
		#可省略參數:
190
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
191
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("inputFile");
192
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
193
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
194
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
195
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
196
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
197
		#$conf["canNotBeEmpty"]=array();
198
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
199
		#$conf["canBeEmpty"]=array();
200
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
201
		#$conf["skipableVariableCanNotBeEmpty"]=array();
202
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
203
		#$conf["skipableVariableName"]=array();
204
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
205
		#$conf["skipableVariableType"]=array();
206
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
207
		#$conf["skipableVarDefaultValue"]=array("");
208
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
209
		#$conf["disallowAllSkipableVarIsEmpty"]="";
210
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
211
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
212
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
213
		#$conf["arrayCountEqualCheck"][]=array();
214
		#參考資料:
215
		#array_keys=>http://php.net/manual/en/function.array-keys.php
216
		#備註:
217
		#無.
218
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
219
		unset($conf["variableCheck::checkArguments"]);
220
 
221
		#如果執行失敗
222
		if($checkArguments["status"]==="false"){
223
 
224
			#設置執行失敗
225
			$result["status"]="false";
226
 
227
			#設置執行錯誤訊息
228
			$result["error"]=$checkArguments;
229
 
230
			#回傳結果
231
			return $result;
232
 
233
			}#if end
234
 
235
		#如果檢查不通過
236
		if($checkArguments["passed"]==="false"){
237
 
238
			#設置執行失敗
239
			$result["status"]="false";
240
 
241
			#設置執行錯誤訊息
242
			$result["error"]=$checkArguments;
243
 
244
			#回傳結果
245
			return $result;
246
 
247
			}#if end
248
 
249
		#檢查檔案是否存在
250
		#函式說明:
251
		#檢查多個檔案與資料夾是否存在.
252
		#回傳的結果:
253
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
254
		#$result["error"],錯誤訊息陣列.
255
		#$resutl["function"],當前執行的涵式名稱.
256
		#$result["argu"],使用的參數.
257
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
258
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
259
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
260
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
261
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
262
		#必填參數:
263
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
264
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["inputFile"]);
265
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
266
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
267
		#可省略參數:
268
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
269
		#$conf["disableWebSearch"]="false";
270
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
271
		#$conf["fileAccess::checkMultiFileExist"]["userDir"]="true";
272
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
273
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
274
		#參考資料:
275
		#http://php.net/manual/en/function.file-exists.php
276
		#http://php.net/manual/en/control-structures.foreach.php
277
		#備註:
278
		#函數file_exists檢查的路徑為檔案系統的路徑
279
		#$result["varName"][$i]結果未實作
280
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
281
		unset($conf["fileAccess::checkMultiFileExist"]);
282
 
283
		#如果執行失敗
284
		if($checkMultiFileExist["status"]==="false"){
285
 
286
			#設置執行失敗
287
			$result["status"]="false";
288
 
289
			#設置執行錯誤訊息
290
			$result["error"]=$checkMultiFileExist;
291
 
292
			#回傳結果
293
			return $result;
294
 
295
			}#if end
296
 
297
		#如果檔案不存在
298
		if($checkMultiFileExist["allExist"]==="false"){
299
 
300
			#設置執行失敗
301
			$result["status"]="false";
302
 
303
			#設置執行錯誤訊息
304
			$result["error"]=$checkMultiFileExist;
305
 
306
			#回傳結果
307
			return $result;
308
 
309
			}#if end
310
 
311
		#debug
312
		#var_dump($checkMultiFileExist);exit;
313
 
314
		#取得輸出目錄
315
		$outDir=pathinfo($conf["inputFile"])["dirname"];
316
 
317
		#函式說明:
318
		#呼叫shell執行系統命令,並取得回傳的內容.
319
		#回傳結果:
320
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
321
		#$result["error"],錯誤訊息陣列.
322
		#$result["function"],當前執行的函數名稱.
323
		#$result["argu"],使用的參數.
324
		#$result["cmd"],執行的指令內容.
325
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
326
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
327
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
328
		#$result["running"],是否還在執行.
329
		#$result["pid"],pid.
330
		#$result["statusCode"],執行結束後的代碼.
331
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
332
		#必填參數:
333
		#$conf["command"],字串,要執行的指令.
334
		$conf["external::callShell"]["command"]="env";
335
		#$conf["fileArgu"],字串,變數__FILE__的內容.
336
		$conf["external::callShell"]["fileArgu"]=__FILE__;
337
		#可省略參數:
338
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
339
		$conf["external::callShell"]["argu"]=array("HOME=/tmp");
340
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
341
		#$conf["arguIsAddr"]=array();
342
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
343
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
344
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
345
		#$conf["external::callShell"]["pre"][]=array("cmd"=>"env","param"=>array("HOME=/tmp"));
346
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
347
		#$conf["enablePrintDescription"]="true";
348
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
349
		#$conf["printDescription"]="";
350
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
351
		$conf["external::callShell"]["escapeshellarg"]="true";
352
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
353
		#$conf["thereIsShellVar"]=array();
354
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
355
		#$conf["username"]="";
356
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
357
		#$conf["password"]="";
358
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
359
		#$conf["useScript"]="";
360
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
361
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
362
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
363
		#$conf["inBackGround"]="";
364
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
365
		#$conf["getErr"]="false";
366
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
367
		$conf["external::callShell"]["doNotRun"]="true";
368
		#參考資料:
369
		#exec=>http://php.net/manual/en/function.exec.php
370
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
371
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
372
		#備註:
373
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
374
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
375
		$callShell=external::callShell($conf["external::callShell"]);
376
		unset($conf["external::callShell"]);
377
 
378
		#如果執行失敗
379
		if($callShell["status"]==="false"){
380
 
381
			#設置執行失敗
382
			$result["status"]="false";
383
 
384
			#設置執行錯誤訊息
385
			$result["error"]=$callShell;
386
 
387
			#回傳結果
388
			return $result;
389
 
390
			}#if end
391
 
392
		#取得 escape 後內容
393
		$envPart1=$callShell["escape"]["array"];
394
 
395
		#函式說明:
396
		#呼叫shell執行系統命令,並取得回傳的內容.
397
		#回傳結果:
398
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
399
		#$result["error"],錯誤訊息陣列.
400
		#$result["function"],當前執行的函數名稱.
401
		#$result["argu"],使用的參數.
402
		#$result["cmd"],執行的指令內容.
403
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
404
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
405
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
406
		#$result["running"],是否還在執行.
407
		#$result["pid"],pid.
408
		#$result["statusCode"],執行結束後的代碼.
409
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
410
		#必填參數:
411
		#$conf["command"],字串,要執行的指令.
412
		$conf["external::callShell"]["command"]="libreoffice";
413
		#$conf["fileArgu"],字串,變數__FILE__的內容.
414
		$conf["external::callShell"]["fileArgu"]=__FILE__;
415
		#可省略參數:
416
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
417
		$conf["external::callShell"]["argu"]=array("--convert-to","pdf","--outdir",$outDir,$conf["inputFile"]);
418
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
419
		#$conf["arguIsAddr"]=array();
420
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
421
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
422
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
423
		#$conf["external::callShell"]["pre"][]=array("cmd"=>"env","param"=>array("HOME=/tmp"));
424
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
425
		#$conf["enablePrintDescription"]="true";
426
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
427
		#$conf["printDescription"]="";
428
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
429
		$conf["external::callShell"]["escapeshellarg"]="true";
430
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
431
		#$conf["thereIsShellVar"]=array();
432
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
433
		#$conf["username"]="";
434
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
435
		#$conf["password"]="";
436
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
437
		#$conf["useScript"]="";
438
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
439
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
440
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
441
		#$conf["inBackGround"]="";
442
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
443
		#$conf["getErr"]="false";
444
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
445
		$conf["external::callShell"]["doNotRun"]="true";
446
		#參考資料:
447
		#exec=>http://php.net/manual/en/function.exec.php
448
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
449
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
450
		#備註:
451
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
452
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
453
		$callShell=external::callShell($conf["external::callShell"]);
454
		unset($conf["external::callShell"]);
455
 
456
		#如果執行失敗
457
		if($callShell["status"]==="false"){
458
 
459
			#設置執行失敗
460
			$result["status"]="false";
461
 
462
			#設置執行錯誤訊息
463
			$result["error"]=$callShell;
464
 
465
			#回傳結果
466
			return $result;
467
 
468
			}#if end
469
 
470
		#取得 escape 後內容
471
		$envPart2=$callShell["escape"]["array"];
472
 
473
		#合併 $envPart1 與 $envPart2
474
		#函式說明:
475
		#將多個一維陣列串聯起來,key從0開始排序.
476
		#回傳的結果:
477
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
478
		#$result["error"],錯誤訊息陣列.
479
		#$result["function"],當前執行的函數.
480
		#$result["content"],合併好的一維陣列.
481
		#必填參數
482
		#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
483
		$conf["arrays::mergeArray"]["inputArray"]=array($envPart1,$envPart2);
484
		#可省略參數:
485
		#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
486
		#$conf["allowRepeat"]="true";
487
		#參考資料:
488
		#無.
489
		#備註:
490
		#無.
491
		$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
492
		unset($conf["arrays::mergeArray"]);
493
 
494
		#如果執行失敗
495
		if($mergeArray["status"]==="false"){
496
 
497
			#設置執行失敗
498
			$result["status"]="false";
499
 
500
			#設置執行錯誤訊息
501
			$result["error"]=$mergeArray;
502
 
503
			#回傳結果
504
			return $result;
505
 
506
			}#if end
507
 
508
		#重新組合要給 external::callShell 的參數
509
		#函式說明:
510
		#解析指令與參數,回傳指令與參數給 callShell 函式使用.
511
		#回傳結果:
512
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
513
		#$result["error"],錯誤訊息陣列.
514
		#$result["function"],當前執行的函數名稱.
515
		#$result["argu"],使用的參數.
516
		#$result["cmd"],執行的指令名稱.
517
		#$result["params"],執行指令伴隨的參數.
518
		#必填參數:
519
		#$conf["cmdArray"],字串陣列,要執行的指令字串.
520
		$conf["external::callShellHelper"]["cmdArray"]=$mergeArray["content"];
521
		#可省略參數:
522
		#無.
523
		#參考資料:
524
		#array_shift=>https://www.php.net/manual/en/function.array-shift.php
525
		#備註:
526
		#無.
527
		$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
528
		unset($conf["external::callShellHelper"]);
529
 
530
		#如果執行失敗
531
		if($callShellHelper["status"]==="false"){
532
 
533
			#設置執行失敗
534
			$result["status"]="false";
535
 
536
			#設置執行錯誤訊息
537
			$result["error"]=$callShellHelper;
538
 
539
			#回傳結果
540
			return $result;
541
 
542
			}#if end
543
 
544
		#函式說明:
545
		#呼叫shell執行系統命令,並取得回傳的內容.
546
		#回傳結果:
547
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
548
		#$result["error"],錯誤訊息陣列.
549
		#$result["function"],當前執行的函數名稱.
550
		#$result["argu"],使用的參數.
551
		#$result["cmd"],執行的指令內容.
552
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
553
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
554
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
555
		#$result["running"],是否還在執行.
556
		#$result["pid"],pid.
557
		#$result["statusCode"],執行結束後的代碼.
558
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
559
		#必填參數:
560
		#$conf["command"],字串,要執行的指令.
561
		$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
562
		#$conf["fileArgu"],字串,變數__FILE__的內容.
563
		$conf["external::callShell"]["fileArgu"]=__FILE__;
564
		#可省略參數:
565
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
566
		$conf["external::callShell"]["argu"]=$callShellHelper["params"];
567
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
568
		#$conf["arguIsAddr"]=array();
569
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
570
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
571
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
572
		#$conf["external::callShell"]["pre"][]=array("cmd"=>"env","param"=>array("HOME=/tmp"));
573
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
574
		#$conf["enablePrintDescription"]="true";
575
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
576
		#$conf["printDescription"]="";
577
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
578
		#$conf["external::callShell"]["escapeshellarg"]="true";
579
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
580
		#$conf["thereIsShellVar"]=array();
581
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
582
		#$conf["username"]="";
583
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
584
		#$conf["password"]="";
585
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
586
		#$conf["useScript"]="";
587
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
588
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
589
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
590
		#$conf["inBackGround"]="";
591
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
592
		#$conf["getErr"]="false";
593
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
594
		#$conf["external::callShell"]["doNotRun"]="true";
595
		#參考資料:
596
		#exec=>http://php.net/manual/en/function.exec.php
597
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
598
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
599
		#備註:
600
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
601
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
602
		$callShell=external::callShell($conf["external::callShell"]);
603
		unset($conf["external::callShell"]);
604
 
605
		#如果執行失敗
606
		if($callShell["status"]==="false"){
607
 
608
			#設置執行失敗
609
			$result["status"]="false";
610
 
611
			#設置執行錯誤訊息
612
			$result["error"]=$callShell;
613
 
614
			#回傳結果
615
			return $result;
616
 
617
			}#if end
618
 
619
		#設置結果陣列
620
		$result["content"]=$callShell["output"];
621
 
622
		#設置執行正常
623
		$result["status"]="true";
624
 
625
		#回傳結果
626
		return $result;
627
 
628
		}#function toPdf end
629
 
630
	}#class libreoffice end