Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 915 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
616 liveuser 6
    Copyright (C) 2015~2024 Min-Jhin,Chen
1 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
 
242 liveuser 26
/*
27
類別說明:
28
跟影片應用相關的類別.
29
備註:
30
無.
31
*/
1 liveuser 32
class video{
33
 
34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
224 liveuser 44
	#可省略參數:
45
	#無.
1 liveuser 46
	#參考資料:
47
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
224 liveuser 48
	#備註:
49
	#無.
1 liveuser 50
	*/
51
	public function __call($method,$arguments){
52
 
53
		#取得當前執行的函式
54
		$result["function"]=__FUNCTION__;
55
 
56
		#設置執行不正常
57
		$result["status"]="false";
58
 
59
		#設置執行錯誤
60
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
61
 
62
		#設置所丟入的參數
63
		$result["error"][]=$arguments;
64
 
65
		#回傳結果
66
		return $result;
67
 
68
		}#function __call end
69
 
70
	/*
71
	#函式說明:
72
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
73
	#回傳結果:
74
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
75
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
76
	#$result["function"],當前執行的函式名稱.
77
	#必填參數:
78
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
79
	#$arguments,陣列,為呼叫方法時所用的參數.
224 liveuser 80
	#可省略參數:
81
	#無.
1 liveuser 82
	#參考資料:
224 liveuser 83
	#__callStatic=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
84
	#備註:
85
	#無.
1 liveuser 86
	*/
87
	public static function __callStatic($method,$arguments){
88
 
89
		#取得當前執行的函式
90
		$result["function"]=__FUNCTION__;
91
 
92
		#設置執行不正常
93
		$result["status"]="false";
94
 
95
		#設置執行錯誤
96
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
97
 
98
		#設置所丟入的參數
99
		$result["error"][]=$arguments;
100
 
101
		#回傳結果
102
		return $result;
103
 
104
		}#function __callStatic end
105
 
106
	/*
57 liveuser 107
	#函式說明:
224 liveuser 108
	#放置html5支援的webm格式影片(webm),結果會回傳語法.
1 liveuser 109
	#回傳結果:
224 liveuser 110
	#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常.
111
	#$result["error"],錯誤訊息陣列.
112
	#$result["function"],當前函數名稱.
113
	#$result["content"],放置html5支援的webm格式影片語法.
114
	#$result["base64data"],用base64加密影片後放置html5支援的webm格式影片語法.
57 liveuser 115
	#必填參數:
224 liveuser 116
	#$conf["videoFilePosition"],字串,爲影片的路徑,需要有附檔名.
1 liveuser 117
	$conf["videoFilePosition"]="";
118
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
119
	$conf["fileArgu"]=__FILE__;
57 liveuser 120
	#可省略參數:
1 liveuser 121
	#$conf["width"],字串,爲影片的寬度,預設不設置.
122
	#$conf["width"]="";
123
	#$conf["height"],字串,爲影片的高度,預設不設置.
124
	#$conf["height"]="";
125
	#$conf["codecs"],字串,爲解碼器名稱,預設爲 "vp8, vorbis"
126
	#$conf["codecs"]="vp8, vorbis"
127
	#$conf["autoplay"],字串,為是否要自動播放,"true"代表要,"false"代表不要,預設為"false".
128
	#$conf["autoplay"]="true";
129
	#$conf["loop"],字串,爲是否重複播放,若要重複播放則應填入 "true" ,預設爲不重複
130
	#$conf["loop"]="false";
131
	#$conf["controlls"],字串,是否要顯示控制面板,預設為"false"不顯示;反之為"true"要顯示.
132
	#$conf["controlls"]="true";
367 liveuser 133
	#$conf["muted"],字串,是否要靜音,"true"代表要;預設為"false",不靜音.
134
	#$conf["muted"]="true";
782 liveuser 135
	#$conf["styleAttr"],字串陣列,要套用的style樣式屬性.
136
	#$conf["styleAttr"]=array("");
137
	#$conf["styleVal"],字串陣列,要套用的style樣式數值.
138
	#$conf["styleVal"]=array("");
1 liveuser 139
	#$conf["class"],字串,要套用的css類別樣式名稱.
140
	#$conf["class"]="";
224 liveuser 141
	#參考資料:
142
	#無.
1 liveuser 143
	#備註:
144
	#建議增加影片載入完畢就自動播放的js.
145
	*/	
224 liveuser 146
	public static function html5(&$conf){
1 liveuser 147
 
148
		#初始化要回傳的內容
149
		$result=array();
150
 
151
		#取得當前函數名稱
152
		$result["function"]=__FUNCTION__;
153
 
154
		#如果 $conf 不為陣列
155
		if(gettype($conf)!="array"){
156
 
157
			#設置執行失敗
158
			$result["status"]="false";
159
 
160
			#設置執行錯誤訊息
161
			$result["error"][]="\$conf變數須為陣列形態";
162
 
163
			#如果傳入的參數為 null
164
			if($conf==null){
165
 
166
				#設置執行錯誤訊息
167
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
168
 
169
				}#if end
170
 
171
			#回傳結果
172
			return $result;
173
 
174
			}#if end
175
 
176
		#初始化要回傳的語法
177
		$result["content"]="";
178
 
179
		#檢查參數
180
		#函式說明:
181
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
182
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
183
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
184
		#$result["function"],當前執行的函式名稱.
185
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
186
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
187
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
188
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
189
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
190
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
191
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
192
		#必填寫的參數:
193
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
194
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
195
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
196
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","videoFilePosition");
197
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
198
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
199
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
200
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
201
		#可以省略的參數:
202
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
203
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
204
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
782 liveuser 205
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("width","height","codecs","autoplay","loop","controlls","class","muted","styleAttr","styleVal");
1 liveuser 206
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
782 liveuser 207
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string","string","array","array");
1 liveuser 208
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
782 liveuser 209
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"vp8, vorbis","false","false","false",null,"false",null,null);
1 liveuser 210
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
782 liveuser 211
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("styleAttr","styleVal");
1 liveuser 212
		#參考資料來源:
213
		#array_keys=>http://php.net/manual/en/function.array-keys.php
214
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
215
		unset($conf["variableCheck::checkArguments"]);
216
 
217
		#如果檢查失敗
367 liveuser 218
		if($checkArguments["status"]==="false"){
1 liveuser 219
 
220
			#設置錯誤識別
221
			$result["status"]="false";
222
 
223
			#設置錯誤訊息
224
			$result["error"]=$checkArguments;
225
 
226
			#回傳結果
227
			return $result;
228
 
229
			}#if end
230
 
231
		#如果檢查不通過
232
		if($checkArguments["passed"]=="false"){
233
 
234
			#設置錯誤識別
235
			$result["status"]="false";
236
 
237
			#設置錯誤訊息
238
			$result["error"]=$checkArguments;
239
 
240
			#回傳結果
241
			return $result;
242
 
243
			}#if end
244
 
245
		#檢查影片檔案是否存在
57 liveuser 246
		#函式說明:檢查多個檔案與資料夾是否存在.
1 liveuser 247
		#回傳的結果:
248
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
249
		#$result["error"],錯誤訊息陣列.
250
		#$resutl["function"],當前執行的涵式名稱.
251
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
252
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
253
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
57 liveuser 254
		#必填參數:
1 liveuser 255
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["videoFilePosition"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
256
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
257
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
362 liveuser 258
		#可省略參數:
259
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
260
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
261
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
262
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
263
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
264
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
1 liveuser 265
		#參考資料來源:
266
		#http://php.net/manual/en/function.file-exists.php
267
		#http://php.net/manual/en/control-structures.foreach.php
268
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
269
		unset($conf["fileAccess::checkMultiFileExist"]);
270
 
271
		#如果檢查失敗
272
		if($checkMultiFileExist["status"]=="false"){
273
 
274
			#設置執行不正常
275
			$result["status"]="false";
276
 
277
			#設置執行錯誤
278
			$result["error"]=$checkMultiFileExist;
279
 
280
			#回傳結果
281
			return $result;
282
 
283
			}#if end
284
 
285
		#如果聲音檔案不存在
286
		if($checkMultiFileExist["varExist"][0]=="false"){
287
 
288
			#設置執行不正常
289
			$result["status"]="false";
290
 
291
			#設置執行錯誤
292
			$result["error"][]="影片檔案「".$checkMultiFileExist["varName"][0]."」不存在!";
293
 
294
			#回傳結果
295
			return $result;
296
 
297
			}#if end
298
 
299
		#將聲音檔案用 base64 形式壓縮成16近位的英文數字
300
		#函數說明:
301
		#用data:mimeType;base64,fileVar的形式來提供檔案的連結,亦即檔案儲存在變數裡面.
302
		#回傳結果:
303
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
304
		#$result["error"],錯誤訊息
305
		#$result["content"],檔案變數的內容
306
		#$result["fileTypeName"],副檔名,ex:「.tar.xz」.
307
		#$result["function"],當前執行的函數名稱 
308
		#必填參數:
309
		#$conf["filePosition"],要轉存成2元碼的圖片檔案位置與名稱
310
		$conf["fileAccess::data"]["filePosition"]=$conf["videoFilePosition"];
311
		#$conf["mimeType"],2元碼的內容是什麼
312
		$conf["fileAccess::data"]["mimeType"]="video/*";
313
		#可省略參數:
314
		#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
315
		#$conf["compressType"]="base64";
316
		#$conf["delFile"],讀取完檔案後,要移除檔案嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
317
		#$conf["delFile"]="false";
318
		#參考資料:
319
		#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
320
		#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
321
		$data=fileAccess::data($conf["fileAccess::data"]);
322
		unset($conf["fileAccess::data"]);
323
 
324
		#如果將聲音檔案用 base64 形式壓縮成16近位的英文數字失敗
325
		if($data["status"]=="false"){
326
 
327
			#設置執行不正常
328
			$result["status"]="false";
329
 
330
			#設置執行錯誤
331
			$result["error"]=$data;
332
 
333
			#回傳結果
334
			return $result;
335
 
336
			}#if end
337
 
338
		#如果$conf["width"]有設定
339
		if(isset($conf["width"])){
340
 
341
			#則按照指定的寬度	
342
			$conf["width"]="width = ".$conf["width"];
343
 
344
			}#if end
345
 
346
		#如果$conf["width"]沒有設定
347
		else{
348
 
349
			$conf["width"]="";
350
 
351
			}#else end
352
 
353
		#如果$conf["height"]有設定
354
		if(isset($conf["height"])){
355
 
356
			#則按照指定的高度
357
			$conf["height"]="height = ".$conf["height"];
358
 
359
			}#if end
360
 
361
		#如果$conf["height"]沒有設定
362
		else{
363
 
364
			#則$conf["height"]爲空
365
			$conf["height"]="";
366
 
367
			}#else end
368
 
369
		#設置解碼器
370
		$conf["codecs"]=" codecs=".$conf["codecs"];
371
 
367 liveuser 372
		#預設不自動播放
373
		$autoplay="";
374
 
1 liveuser 375
		#如果 $conf["autoplay"] 為 "true"
367 liveuser 376
		if($conf["autoplay"]==="true"){
1 liveuser 377
 
378
			#設置自動播放
367 liveuser 379
			$autoplay="autoplay";
1 liveuser 380
 
381
			}#if end
367 liveuser 382
 
1 liveuser 383
		#如果$conf["loop"]為"true"
384
		if($conf["loop"]=="true"){
385
 
386
			#則放置重複播放的語法		
387
			$conf["loop"]=" loop=loop";
388
 
389
			}#if end
390
 
391
		#反之	
392
		else{
393
 
394
			#設為空字串
395
			$conf["loop"]="";
396
 
397
			}#else end
398
 
399
		#如果有設置 class 
400
		if(isset($conf["class"])){
401
 
402
			#設置 class
403
			$conf["class"]="class='".$conf["class"]."'";
404
 
405
			}#if end
406
 
407
		#反之
408
		else{
409
 
410
			#設置為空字串
411
			$conf["class"]="";
412
 
413
			}
414
 
415
		#初始化控制器語法
416
		$controls="";
417
 
418
		#如果要顯示控制列
419
		if($conf["controlls"]==="true"){
420
 
421
			#設定要顯示控制列
422
			$controls="controls=controls";
423
 
424
			}#if end
425
 
367 liveuser 426
		#預設不靜音
427
		$muted="";	
428
 
429
		#如果要靜音
430
		if($conf["muted"]==="true"){
431
 
432
			#設置要靜音
433
			$muted="muted";
434
 
435
			}#if end	
436
 
782 liveuser 437
		#初始化style為空
438
		$style="";
439
 
440
		#如果有設定 styleName 跟 styleVal
441
		if( isset($conf["styleName"]) && isset($conf["styleVal"]) ){
442
 
443
			#函式說明:
444
			#建立給與html標籤使用的style屬性字串.
445
			#回傳結果:
446
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
447
			#$result["function"],當前執行的函數
448
			#$result["error"],錯誤訊息陣列
449
			#$result["content"],css設定內容
450
			#必填參數:
451
			$conf["css::styleStr"]["styleName"]=$conf["styleName"];#為屬性名稱,須為陣列值
452
			$conf["css::styleStr"]["styleValue"]=$conf["styleVal"];#為屬性值,須為陣列值
453
			#可省略參數:
454
			#無.
455
			#參考資料:
456
			#無.
457
			#備註:
458
			#無.
459
			$styleStr=css::styleStr($conf["css::styleStr"]);
460
			unset($conf["css::styleStr"]);
461
 
462
			if($styleStr["status"]=="false"){
463
 
464
				#設置執行不正常
465
				$result["status"]="false";
466
 
467
				#設置執行錯誤
468
				$result["error"]=$styleStr;
469
 
470
				#回傳結果
471
				return $result;
472
 
473
				}#if end
474
 
475
			#設置style
476
			$style=$styleStr["content"];
477
 
478
			}#if end
479
 
1 liveuser 480
		#語法開始,寬度,高度,控制面板		
367 liveuser 481
		$result["content"]=$result["content"]."<video ".$conf["width"]." ".$conf["height"]." ".$controls." ".$autoplay." ".$conf["loop"]." ".$conf["class"]." >";
782 liveuser 482
		$base64data="<video ".$conf["width"]." ".$conf["height"]." controls=controls ".$autoplay." ".$conf["loop"]." ".$conf["class"]." ".$muted." ".$style.">";
1 liveuser 483
 
484
		#影片檔案位置,類型,所使用的解碼器
485
		$result["content"]=$result["content"]."<source src=\"".$conf["videoFilePosition"]."\" type=\"video/webm\" />";
486
		$base64data=$base64data."<source src=\"".$conf["videoFilePosition"]."\" type=\"video/webm\" />";
487
 
488
		#語法結束
489
		$result["content"]=$result["content"]."</video>";	
490
		$base64data=$base64data."</video>";
491
 
492
		#取得用base64加密影片後的影片放置語法
493
		$result["base64data"]=$base64data;
494
 
495
		#設置執行正常
496
		$result["status"]="true";
497
 
498
		#回傳語法
499
		return $result;
500
 
501
		}#function html5 end
502
 
503
	}#class video end
504
 
505
?>