| 1 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 624 |
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 |
|
| 243 |
liveuser |
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
處理聲音的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
| 1 |
liveuser |
32 |
class sound{
|
|
|
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 |
#放置html5支援的聲音
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
103 |
#$result["error"],錯誤訊息陣列
|
|
|
104 |
#$result["function"],當前函數名稱
|
|
|
105 |
#$result["content"],放置html5聲音檔的語法
|
|
|
106 |
#$result["base64data"],用base64加密聲音檔後放置html5聲音檔的語法
|
|
|
107 |
#必填的參數:
|
|
|
108 |
#$conf["audioPosition"],字串,爲聲音檔的位置,需包和檔名(目前支援ogg與mp3)
|
|
|
109 |
$conf["audioPosition"]="";
|
|
|
110 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
111 |
$conf["fileArgu"]=__FILE__;
|
|
|
112 |
#可省略的參數:
|
|
|
113 |
#$conf["type"],字串,爲聲音格式的mime識別名稱,ogg對應到audio/ogg;mp3對應到 audio/mp3,預設爲"audio/ogg",如果是只有聲音的影片檔也可以使用,譬如ogv格式的檔案,就可以當作聲音檔來播放.
|
|
|
114 |
#$conf["type"]="audio/ogg";
|
|
|
115 |
#$conf["autoplay"],字串,爲是否自動播放,若要自動播放則應填入"true",預設爲不自動播放
|
|
|
116 |
#$conf["autoplay"]="true";
|
|
|
117 |
#$conf["loop"],字串,爲是否重複播放,若要重複播放則應填入 "true" ,預設爲不重複
|
|
|
118 |
#$conf["loop"]="false";
|
|
|
119 |
*/
|
|
|
120 |
function html5($conf){
|
|
|
121 |
|
|
|
122 |
#初始化要回傳的內容
|
|
|
123 |
$result=array();
|
|
|
124 |
|
|
|
125 |
#取得當前函數名稱
|
|
|
126 |
$result["function"]=__FUNCTION__;
|
|
|
127 |
|
|
|
128 |
#如果 $conf 不為陣列
|
|
|
129 |
if(gettype($conf)!="array"){
|
|
|
130 |
|
|
|
131 |
#設置執行失敗
|
|
|
132 |
$result["status"]="false";
|
|
|
133 |
|
|
|
134 |
#設置執行錯誤訊息
|
|
|
135 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
136 |
|
|
|
137 |
#如果傳入的參數為 null
|
|
|
138 |
if($conf==null){
|
|
|
139 |
|
|
|
140 |
#設置執行錯誤訊息
|
|
|
141 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
142 |
|
|
|
143 |
}#if end
|
|
|
144 |
|
|
|
145 |
#回傳結果
|
|
|
146 |
return $result;
|
|
|
147 |
|
|
|
148 |
}#if end
|
|
|
149 |
|
|
|
150 |
#初始化要回傳的語法
|
|
|
151 |
$result["content"]="";
|
|
|
152 |
|
|
|
153 |
#檢查參數
|
|
|
154 |
#函式說明:
|
|
|
155 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
156 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
157 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
158 |
#$result["function"],當前執行的函式名稱.
|
|
|
159 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
160 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
161 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
162 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
163 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
164 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
165 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
166 |
#必填寫的參數:
|
|
|
167 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
168 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
169 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
170 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","audioPosition");
|
|
|
171 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
172 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
173 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
174 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
175 |
#可以省略的參數:
|
|
|
176 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
177 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
178 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
179 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("type","autoplay","loop");
|
|
|
180 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
181 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
182 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
183 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("audio/ogg","false","false");
|
|
|
184 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
185 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
186 |
#參考資料來源:
|
|
|
187 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
188 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
189 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
190 |
|
|
|
191 |
#如果檢查失敗
|
|
|
192 |
if($checkArguments["status"]=="false"){
|
|
|
193 |
|
|
|
194 |
#設置錯誤識別
|
|
|
195 |
$result["status"]="false";
|
|
|
196 |
|
|
|
197 |
#設置錯誤訊息
|
|
|
198 |
$result["error"]=$checkArguments;
|
|
|
199 |
|
|
|
200 |
#回傳結果
|
|
|
201 |
return $result;
|
|
|
202 |
|
|
|
203 |
}#if end
|
|
|
204 |
|
|
|
205 |
#如果檢查不通過
|
|
|
206 |
if($checkArguments["passed"]=="false"){
|
|
|
207 |
|
|
|
208 |
#設置錯誤識別
|
|
|
209 |
$result["status"]="false";
|
|
|
210 |
|
|
|
211 |
#設置錯誤訊息
|
|
|
212 |
$result["error"]=$checkArguments;
|
|
|
213 |
|
|
|
214 |
#回傳結果
|
|
|
215 |
return $result;
|
|
|
216 |
|
|
|
217 |
}#if end
|
|
|
218 |
|
|
|
219 |
#檢查語音檔案是否存在
|
|
|
220 |
#涵式說明:檢查多個檔案與資料夾是否存在.
|
|
|
221 |
#回傳的結果:
|
|
|
222 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
223 |
#$result["error"],錯誤訊息陣列.
|
|
|
224 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
225 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
226 |
#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
|
|
|
227 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
228 |
#必填的參數:
|
|
|
229 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["audioPosition"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
230 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
231 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
232 |
#參考資料來源:
|
|
|
233 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
234 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
235 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
236 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
|
|
237 |
|
|
|
238 |
#如果檢查失敗
|
|
|
239 |
if($checkMultiFileExist["status"]=="false"){
|
|
|
240 |
|
|
|
241 |
#設置執行不正常
|
|
|
242 |
$result["status"]="false";
|
|
|
243 |
|
|
|
244 |
#設置執行錯誤
|
|
|
245 |
$result["error"]=$checkMultiFileExist;
|
|
|
246 |
|
|
|
247 |
#回傳結果
|
|
|
248 |
return $result;
|
|
|
249 |
|
|
|
250 |
}#if end
|
|
|
251 |
|
|
|
252 |
#如果聲音檔案不存在
|
|
|
253 |
if($checkMultiFileExist["varExist"][0]=="false"){
|
|
|
254 |
|
|
|
255 |
#設置執行不正常
|
|
|
256 |
$result["status"]="false";
|
|
|
257 |
|
|
|
258 |
#設置執行錯誤
|
|
|
259 |
$result["error"][]="聲音檔案「".$checkMultiFileExist["varName"][0]."」不存在!";
|
|
|
260 |
|
|
|
261 |
#回傳結果
|
|
|
262 |
return $result;
|
|
|
263 |
|
|
|
264 |
}#if end
|
|
|
265 |
|
|
|
266 |
#將聲音檔案用 base64 形式壓縮成16近位的英文數字
|
|
|
267 |
#函數說明:
|
|
|
268 |
#用data:mimeType;base64,fileVar的形式來提供檔案的連結,亦即檔案儲存在變數裡面.
|
|
|
269 |
#回傳結果:
|
|
|
270 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
271 |
#$result["error"],錯誤訊息
|
|
|
272 |
#$result["content"],檔案變數的內容
|
|
|
273 |
#$result["fileTypeName"],副檔名,ex:「.tar.xz」.
|
|
|
274 |
#$result["function"],當前執行的函數名稱
|
|
|
275 |
#必填參數:
|
|
|
276 |
#$conf["filePosition"],要轉存成2元碼的圖片檔案位置與名稱
|
|
|
277 |
$conf["fileAccess::data"]["filePosition"]=$conf["audioPosition"];
|
|
|
278 |
#$conf["mimeType"],2元碼的內容是什麼
|
|
|
279 |
$conf["fileAccess::data"]["mimeType"]=$conf["type"];
|
|
|
280 |
#可省略參數:
|
|
|
281 |
#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
|
|
|
282 |
#$conf["compressType"]="base64";
|
|
|
283 |
#$conf["delFile"],讀取完檔案後,要移除檔案嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
|
|
|
284 |
#$conf["delFile"]="false";
|
|
|
285 |
#參考資料:
|
|
|
286 |
#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
|
|
|
287 |
#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
|
|
|
288 |
$data=fileAccess::data($conf["fileAccess::data"]);
|
|
|
289 |
unset($conf["fileAccess::data"]);
|
|
|
290 |
|
|
|
291 |
#如果將聲音檔案用 base64 形式壓縮成16近位的英文數字失敗
|
|
|
292 |
if($data["status"]=="false"){
|
|
|
293 |
|
|
|
294 |
#設置執行不正常
|
|
|
295 |
$result["status"]="false";
|
|
|
296 |
|
|
|
297 |
#設置執行錯誤
|
|
|
298 |
$result["error"]=$data;
|
|
|
299 |
|
|
|
300 |
#回傳結果
|
|
|
301 |
return $result;
|
|
|
302 |
|
|
|
303 |
}#if end
|
|
|
304 |
|
|
|
305 |
#如果$conf["autoplay"]為"true"
|
|
|
306 |
if($conf["autoplay"]=="true"){
|
|
|
307 |
|
|
|
308 |
#則放置自動播放的語法
|
|
|
309 |
$conf["autoplay"]=" autoplay=autoplay";
|
|
|
310 |
|
|
|
311 |
}#if end
|
|
|
312 |
|
|
|
313 |
#反之
|
|
|
314 |
else{
|
|
|
315 |
|
|
|
316 |
#設為空字串
|
|
|
317 |
$conf["autoplay"]="";
|
|
|
318 |
|
|
|
319 |
}#else end
|
|
|
320 |
|
|
|
321 |
#如果$conf["loop"]為"true"
|
|
|
322 |
if($conf["loop"]=="true"){
|
|
|
323 |
|
|
|
324 |
#則放置重複播放的語法
|
|
|
325 |
$conf["loop"]=" loop=loop";
|
|
|
326 |
|
|
|
327 |
}#if end
|
|
|
328 |
|
|
|
329 |
#反之
|
|
|
330 |
else{
|
|
|
331 |
|
|
|
332 |
#設為空字串
|
|
|
333 |
$conf["loop"]="";
|
|
|
334 |
|
|
|
335 |
}#else end
|
|
|
336 |
|
|
|
337 |
#設定語音類型
|
|
|
338 |
$conf["type"]=" type=".$conf["type"];
|
|
|
339 |
|
|
|
340 |
#顯示聲音播放器控制面板,是否自動播放、是否重複播放。
|
|
|
341 |
$result["content"]=$result["content"]."<audio controls=controls ".$conf["autoplay"]." ".$conf["loop"].">";
|
|
|
342 |
$base64data="<audio controls=controls ".$conf["autoplay"]." ".$conf["loop"].">";
|
|
|
343 |
|
|
|
344 |
#聲音檔案位置、形態、
|
|
|
345 |
$result["content"]=$result["content"]."<source src = ".$conf["audioPosition"]." ".$conf["type"]." preload=auto />";
|
|
|
346 |
$base64data=$base64data."<source src = ".$data["content"]." ".$conf["type"]." preload=auto />";
|
|
|
347 |
|
|
|
348 |
#放置聲音的html5標籤結束
|
|
|
349 |
$result["content"]=$result["content"]."</audio>";
|
|
|
350 |
$base64data=$base64data."</audio>";
|
|
|
351 |
|
|
|
352 |
#儲存用 base64 形式壓縮成16近位英文數字的聲音檔案
|
|
|
353 |
$result["base64data"]=$base64data;
|
|
|
354 |
|
|
|
355 |
#設置執行正常
|
|
|
356 |
$result["status"]="true";
|
|
|
357 |
|
|
|
358 |
#回傳語法
|
|
|
359 |
return $result;
|
|
|
360 |
|
|
|
361 |
}#function html5 end
|
|
|
362 |
|
|
|
363 |
}#class sound end
|
|
|
364 |
|
|
|
365 |
?>
|