Subversion Repositories php-qbpwcf

Rev

Rev 3 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 226
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2024 Min-Jhin,Chen
6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
7
 
7
 
8
    This file is part of QBPWCF.
8
    This file is part of QBPWCF.
9
 
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
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
11
    it under the terms of the GNU General Public License as published by
Line 43... Line 43...
43
	#$arguments,陣列,為呼叫方法時所用的參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	*/
46
	*/
47
	public function __call($method,$arguments){
47
	public function __call($method,$arguments){
48
		
48
 
49
		#取得當前執行的函式
49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
50
		$result["function"]=__FUNCTION__;
51
		
51
 
52
		#設置執行不正常
52
		#設置執行不正常
53
		$result["status"]="false";
53
		$result["status"]="false";
54
		
54
 
55
		#設置執行錯誤
55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
57
		
57
 
58
		#設置所丟入的參數
58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
59
		$result["error"][]=$arguments;
60
		
60
 
61
		#回傳結果
61
		#回傳結果
62
		return $result;
62
		return $result;
63
		
63
 
64
		}#function __call end
64
		}#function __call end
65
		
65
 
66
	/*
66
	/*
67
	#函式說明:
67
	#函式說明:
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
69
	#回傳結果:
69
	#回傳結果:
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 75... Line 75...
75
	#$arguments,陣列,為呼叫方法時所用的參數.
75
	#$arguments,陣列,為呼叫方法時所用的參數.
76
	#參考資料:
76
	#參考資料:
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
78
	*/
78
	*/
79
	public static function __callStatic($method,$arguments){
79
	public static function __callStatic($method,$arguments){
80
		
80
 
81
		#取得當前執行的函式
81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
82
		$result["function"]=__FUNCTION__;
83
		
83
 
84
		#設置執行不正常
84
		#設置執行不正常
85
		$result["status"]="false";
85
		$result["status"]="false";
86
		
86
 
87
		#設置執行錯誤
87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
89
		
89
 
90
		#設置所丟入的參數
90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
91
		$result["error"][]=$arguments;
92
		
92
 
93
		#回傳結果
93
		#回傳結果
94
		return $result;
94
		return $result;
95
		
95
 
96
		}#function __callStatic end
96
		}#function __callStatic end
97
		
97
 
98
	/*
98
	/*
99
	#函式說明:
99
	#函式說明:
100
	#將可被libreoffice支援的檔案轉存成pdf檔案
100
	#將可被libreoffice支援的檔案轉存成pdf檔案
101
	#回傳結果:
101
	#回傳結果:
102
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
102
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 114... Line 114...
114
	#備註:
114
	#備註:
115
	#參考語法 -> libreoffice --convert-to pdf latest.qbpwcf.org.html
115
	#參考語法 -> libreoffice --convert-to pdf latest.qbpwcf.org.html
116
	#非一般使用者需要指定系統變數 HOME
116
	#非一般使用者需要指定系統變數 HOME
117
	*/
117
	*/
118
	public static function toPdf(&$conf=array()){
118
	public static function toPdf(&$conf=array()){
119
	
119
 
120
		#初始化要回傳的結果
120
		#初始化要回傳的結果
121
		$result=array();
121
		$result=array();
122
 
122
 
123
		#初始化語法
123
		#初始化語法
124
		$result["content"]="";
124
		$result["content"]="";
Line 126... Line 126...
126
		#取得當前執行的函數名稱
126
		#取得當前執行的函數名稱
127
		$result["function"]=__FUNCTION__;
127
		$result["function"]=__FUNCTION__;
128
 
128
 
129
		#如果沒有參數
129
		#如果沒有參數
130
		if(func_num_args()==0){
130
		if(func_num_args()==0){
131
			
131
 
132
			#設置執行失敗
132
			#設置執行失敗
133
			$result["status"]="false";
133
			$result["status"]="false";
134
			
134
 
135
			#設置執行錯誤訊息
135
			#設置執行錯誤訊息
136
			$result["error"]="函數".$result["function"]."需要參數";
136
			$result["error"]="函數".$result["function"]."需要參數";
137
			
137
 
138
			#回傳結果
138
			#回傳結果
139
			return $result;
139
			return $result;
140
			
140
 
141
			}#if end
141
			}#if end
142
			
142
 
143
		#取得參數
143
		#取得參數
144
		$result["argu"]=$conf;
144
		$result["argu"]=$conf;
145
 
145
 
146
		#如果 $conf 不為陣列
146
		#如果 $conf 不為陣列
147
		if(gettype($conf)!="array"){
147
		if(gettype($conf)!="array"){
148
			
148
 
149
			#設置執行失敗
149
			#設置執行失敗
150
			$result["status"]="false";
150
			$result["status"]="false";
151
			
151
 
152
			#設置執行錯誤訊息
152
			#設置執行錯誤訊息
153
			$result["error"][]="\$conf變數須為陣列形態";
153
			$result["error"][]="\$conf變數須為陣列形態";
154
			
154
 
155
			#如果傳入的參數為 null
155
			#如果傳入的參數為 null
156
			if($conf==null){
156
			if($conf==null){
157
				
157
 
158
				#設置執行錯誤訊息
158
				#設置執行錯誤訊息
159
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
159
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
160
				
160
 
161
				}#if end
161
				}#if end
162
 
162
 
163
			#回傳結果
163
			#回傳結果
164
			return $result;
164
			return $result;
165
			
165
 
166
			}#if end
166
			}#if end
167
			
167
 
168
		#函式說明:
168
		#函式說明:
169
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
169
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
170
		#回傳結果:
170
		#回傳結果:
171
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
171
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
172
		#$result["error"],執行不正常結束的錯訊息陣列.
172
		#$result["error"],執行不正常結束的錯訊息陣列.
Line 215... Line 215...
215
		#array_keys=>http://php.net/manual/en/function.array-keys.php
215
		#array_keys=>http://php.net/manual/en/function.array-keys.php
216
		#備註:
216
		#備註:
217
		#無.
217
		#無.
218
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
218
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
219
		unset($conf["variableCheck::checkArguments"]);
219
		unset($conf["variableCheck::checkArguments"]);
220
	
220
 
221
		#如果執行失敗
221
		#如果執行失敗
222
		if($checkArguments["status"]==="false"){
222
		if($checkArguments["status"]==="false"){
223
		
223
 
224
			#設置執行失敗
224
			#設置執行失敗
225
			$result["status"]="false";
225
			$result["status"]="false";
226
 
226
 
227
			#設置執行錯誤訊息
227
			#設置執行錯誤訊息
228
			$result["error"]=$checkArguments;
228
			$result["error"]=$checkArguments;
229
 
229
 
230
			#回傳結果
230
			#回傳結果
231
			return $result;
231
			return $result;
232
		
232
 
233
			}#if end
233
			}#if end
234
			
234
 
235
		#如果檢查不通過
235
		#如果檢查不通過
236
		if($checkArguments["passed"]==="false"){
236
		if($checkArguments["passed"]==="false"){
237
		
237
 
238
			#設置執行失敗
238
			#設置執行失敗
239
			$result["status"]="false";
239
			$result["status"]="false";
240
 
240
 
241
			#設置執行錯誤訊息
241
			#設置執行錯誤訊息
242
			$result["error"]=$checkArguments;
242
			$result["error"]=$checkArguments;
243
 
243
 
244
			#回傳結果
244
			#回傳結果
245
			return $result;
245
			return $result;
246
		
246
 
247
			}#if end
247
			}#if end
248
		
248
 
249
		#檢查檔案是否存在
249
		#檢查檔案是否存在
250
		#函式說明:
250
		#函式說明:
251
		#檢查多個檔案與資料夾是否存在.
251
		#檢查多個檔案與資料夾是否存在.
252
		#回傳的結果:
252
		#回傳的結果:
253
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
253
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
Line 277... Line 277...
277
		#備註:
277
		#備註:
278
		#函數file_exists檢查的路徑為檔案系統的路徑
278
		#函數file_exists檢查的路徑為檔案系統的路徑
279
		#$result["varName"][$i]結果未實作
279
		#$result["varName"][$i]結果未實作
280
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
280
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
281
		unset($conf["fileAccess::checkMultiFileExist"]);
281
		unset($conf["fileAccess::checkMultiFileExist"]);
282
		
282
 
283
		#如果執行失敗
283
		#如果執行失敗
284
		if($checkMultiFileExist["status"]==="false"){
284
		if($checkMultiFileExist["status"]==="false"){
285
		
285
 
286
			#設置執行失敗
286
			#設置執行失敗
287
			$result["status"]="false";
287
			$result["status"]="false";
288
 
288
 
289
			#設置執行錯誤訊息
289
			#設置執行錯誤訊息
290
			$result["error"]=$checkMultiFileExist;
290
			$result["error"]=$checkMultiFileExist;
291
 
291
 
292
			#回傳結果
292
			#回傳結果
293
			return $result;
293
			return $result;
294
		
294
 
295
			}#if end
295
			}#if end
296
			
296
 
297
		#如果檔案不存在
297
		#如果檔案不存在
298
		if($checkMultiFileExist["allExist"]==="false"){
298
		if($checkMultiFileExist["allExist"]==="false"){
299
		
299
 
300
			#設置執行失敗
300
			#設置執行失敗
301
			$result["status"]="false";
301
			$result["status"]="false";
302
 
302
 
303
			#設置執行錯誤訊息
303
			#設置執行錯誤訊息
304
			$result["error"]=$checkMultiFileExist;
304
			$result["error"]=$checkMultiFileExist;
305
 
305
 
306
			#回傳結果
306
			#回傳結果
307
			return $result;
307
			return $result;
308
		
308
 
309
			}#if end
309
			}#if end
310
		
310
 
311
		#debug
311
		#debug
312
		#var_dump($checkMultiFileExist);exit;
312
		#var_dump($checkMultiFileExist);exit;
313
		
313
 
314
		#取得輸出目錄
314
		#取得輸出目錄
315
		$outDir=pathinfo($conf["inputFile"])["dirname"];
315
		$outDir=pathinfo($conf["inputFile"])["dirname"];
316
		
316
 
317
		#函式說明:
317
		#函式說明:
318
		#呼叫shell執行系統命令,並取得回傳的內容.
318
		#呼叫shell執行系統命令,並取得回傳的內容.
319
		#回傳結果:
319
		#回傳結果:
320
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
320
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
321
		#$result["error"],錯誤訊息陣列.
321
		#$result["error"],錯誤訊息陣列.
Line 372... Line 372...
372
		#備註:
372
		#備註:
373
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
373
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
374
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
374
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
375
		$callShell=external::callShell($conf["external::callShell"]);
375
		$callShell=external::callShell($conf["external::callShell"]);
376
		unset($conf["external::callShell"]);
376
		unset($conf["external::callShell"]);
377
	
377
 
378
		#如果執行失敗
378
		#如果執行失敗
379
		if($callShell["status"]==="false"){
379
		if($callShell["status"]==="false"){
380
		
380
 
381
			#設置執行失敗
381
			#設置執行失敗
382
			$result["status"]="false";
382
			$result["status"]="false";
383
 
383
 
384
			#設置執行錯誤訊息
384
			#設置執行錯誤訊息
385
			$result["error"]=$callShell;
385
			$result["error"]=$callShell;
386
 
386
 
387
			#回傳結果
387
			#回傳結果
388
			return $result;
388
			return $result;
389
		
389
 
390
			}#if end
390
			}#if end
391
			
391
 
392
		#取得 escape 後內容
392
		#取得 escape 後內容
393
		$envPart1=$callShell["escape"]["array"];
393
		$envPart1=$callShell["escape"]["array"];
394
		
394
 
395
		#函式說明:
395
		#函式說明:
396
		#呼叫shell執行系統命令,並取得回傳的內容.
396
		#呼叫shell執行系統命令,並取得回傳的內容.
397
		#回傳結果:
397
		#回傳結果:
398
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
398
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
399
		#$result["error"],錯誤訊息陣列.
399
		#$result["error"],錯誤訊息陣列.
Line 450... Line 450...
450
		#備註:
450
		#備註:
451
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
451
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
452
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
452
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
453
		$callShell=external::callShell($conf["external::callShell"]);
453
		$callShell=external::callShell($conf["external::callShell"]);
454
		unset($conf["external::callShell"]);
454
		unset($conf["external::callShell"]);
455
	
455
 
456
		#如果執行失敗
456
		#如果執行失敗
457
		if($callShell["status"]==="false"){
457
		if($callShell["status"]==="false"){
458
		
458
 
459
			#設置執行失敗
459
			#設置執行失敗
460
			$result["status"]="false";
460
			$result["status"]="false";
461
 
461
 
462
			#設置執行錯誤訊息
462
			#設置執行錯誤訊息
463
			$result["error"]=$callShell;
463
			$result["error"]=$callShell;
464
 
464
 
465
			#回傳結果
465
			#回傳結果
466
			return $result;
466
			return $result;
467
		
467
 
468
			}#if end
468
			}#if end
469
		
469
 
470
		#取得 escape 後內容
470
		#取得 escape 後內容
471
		$envPart2=$callShell["escape"]["array"];
471
		$envPart2=$callShell["escape"]["array"];
472
		
472
 
473
		#合併 $envPart1 與 $envPart2
473
		#合併 $envPart1 與 $envPart2
474
		#函式說明:
474
		#函式說明:
475
		#將多個一維陣列串聯起來,key從0開始排序.
475
		#將多個一維陣列串聯起來,key從0開始排序.
476
		#回傳的結果:
476
		#回傳的結果:
477
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
477
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
Line 488... Line 488...
488
		#無.
488
		#無.
489
		#備註:
489
		#備註:
490
		#無.
490
		#無.
491
		$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
491
		$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
492
		unset($conf["arrays::mergeArray"]);
492
		unset($conf["arrays::mergeArray"]);
493
		
493
 
494
		#如果執行失敗
494
		#如果執行失敗
495
		if($mergeArray["status"]==="false"){
495
		if($mergeArray["status"]==="false"){
496
		
496
 
497
			#設置執行失敗
497
			#設置執行失敗
498
			$result["status"]="false";
498
			$result["status"]="false";
499
 
499
 
500
			#設置執行錯誤訊息
500
			#設置執行錯誤訊息
501
			$result["error"]=$mergeArray;
501
			$result["error"]=$mergeArray;
502
 
502
 
503
			#回傳結果
503
			#回傳結果
504
			return $result;
504
			return $result;
505
		
505
 
506
			}#if end
506
			}#if end
507
		
507
 
508
		#重新組合要給 external::callShell 的參數
508
		#重新組合要給 external::callShell 的參數
509
		#函式說明:
509
		#函式說明:
510
		#解析指令與參數,回傳指令與參數給 callShell 函式使用.
510
		#解析指令與參數,回傳指令與參數給 callShell 函式使用.
511
		#回傳結果:
511
		#回傳結果:
512
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
512
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 524... Line 524...
524
		#array_shift=>https://www.php.net/manual/en/function.array-shift.php
524
		#array_shift=>https://www.php.net/manual/en/function.array-shift.php
525
		#備註:
525
		#備註:
526
		#無.
526
		#無.
527
		$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
527
		$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
528
		unset($conf["external::callShellHelper"]);
528
		unset($conf["external::callShellHelper"]);
529
		
529
 
530
		#如果執行失敗
530
		#如果執行失敗
531
		if($callShellHelper["status"]==="false"){
531
		if($callShellHelper["status"]==="false"){
532
		
532
 
533
			#設置執行失敗
533
			#設置執行失敗
534
			$result["status"]="false";
534
			$result["status"]="false";
535
 
535
 
536
			#設置執行錯誤訊息
536
			#設置執行錯誤訊息
537
			$result["error"]=$callShellHelper;
537
			$result["error"]=$callShellHelper;
538
 
538
 
539
			#回傳結果
539
			#回傳結果
540
			return $result;
540
			return $result;
541
		
541
 
542
			}#if end
542
			}#if end
543
		
543
 
544
		#函式說明:
544
		#函式說明:
545
		#呼叫shell執行系統命令,並取得回傳的內容.
545
		#呼叫shell執行系統命令,並取得回傳的內容.
546
		#回傳結果:
546
		#回傳結果:
547
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
547
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
548
		#$result["error"],錯誤訊息陣列.
548
		#$result["error"],錯誤訊息陣列.
Line 599... Line 599...
599
		#備註:
599
		#備註:
600
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
600
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
601
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
601
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
602
		$callShell=external::callShell($conf["external::callShell"]);
602
		$callShell=external::callShell($conf["external::callShell"]);
603
		unset($conf["external::callShell"]);
603
		unset($conf["external::callShell"]);
604
	
604
 
605
		#如果執行失敗
605
		#如果執行失敗
606
		if($callShell["status"]==="false"){
606
		if($callShell["status"]==="false"){
607
		
607
 
608
			#設置執行失敗
608
			#設置執行失敗
609
			$result["status"]="false";
609
			$result["status"]="false";
610
 
610
 
611
			#設置執行錯誤訊息
611
			#設置執行錯誤訊息
612
			$result["error"]=$callShell;
612
			$result["error"]=$callShell;
613
 
613
 
614
			#回傳結果
614
			#回傳結果
615
			return $result;
615
			return $result;
616
		
616
 
617
			}#if end
617
			}#if end
618
		
618
 
619
		#設置結果陣列
619
		#設置結果陣列
620
		$result["content"]=$callShell["output"];
620
		$result["content"]=$callShell["output"];
621
	
621
 
622
		#設置執行正常
622
		#設置執行正常
623
		$result["status"]="true";
623
		$result["status"]="true";
624
		
624
 
625
		#回傳結果
625
		#回傳結果
626
		return $result;
626
		return $result;
627
	
627
 
628
		}#function toPdf end
628
		}#function toPdf end
629
 
629
 
630
	}#class libreoffice end
-
 
631
630
	}#class libreoffice end
-
 
631