Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 910 | Rev 915 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php

/*

        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
    Copyright (C) 2015~2024 Min-Jhin,Chen

    This file is part of QBPWCF.

    QBPWCF is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QBPWCF is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.

*/
namespace qbpwcf;

/*
類別說明:
跟影片應用相關的類別.
備註:
無.
*/
class video{

        /*
        #函式說明:
        #當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$reuslt["error"],執行不正常結束的錯訊息陣列.
        #$result["function"],當前執行的函式名稱.
        #必填參數:
        #$method,物件,為物件實體或類別名稱,會自動置入該參數.
        #$arguments,陣列,為呼叫方法時所用的參數.
        #可省略參數:
        #無.
        #參考資料:
        #__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
        #備註:
        #無.
        */
        public function __call($method,$arguments){
                
                #取得當前執行的函式
                $result["function"]=__FUNCTION__;
                
                #設置執行不正常
                $result["status"]="false";
                
                #設置執行錯誤
                $result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
                
                #設置所丟入的參數
                $result["error"][]=$arguments;
                
                #回傳結果
                return $result;
                
                }#function __call end
                
        /*
        #函式說明:
        #當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$reuslt["error"],執行不正常結束的錯訊息陣列.
        #$result["function"],當前執行的函式名稱.
        #必填參數:
        #$method,物件,為物件實體或類別名稱,會自動置入該參數.
        #$arguments,陣列,為呼叫方法時所用的參數.
        #可省略參數:
        #無.
        #參考資料:
        #__callStatic=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
        #備註:
        #無.
        */
        public static function __callStatic($method,$arguments){
                
                #取得當前執行的函式
                $result["function"]=__FUNCTION__;
                
                #設置執行不正常
                $result["status"]="false";
                
                #設置執行錯誤
                $result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
                
                #設置所丟入的參數
                $result["error"][]=$arguments;
                
                #回傳結果
                return $result;
                
                }#function __callStatic end
        
        /*
        #函式說明:
        #放置html5支援的webm格式影片(webm),結果會回傳語法.
        #回傳結果:
        #$result["status"],執行正常與否,"true"代表正常;"false"代表不正常.
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前函數名稱.
        #$result["content"],放置html5支援的webm格式影片語法.
        #$result["base64data"],用base64加密影片後放置html5支援的webm格式影片語法.
        #必填參數:
        #$conf["videoFilePosition"],字串,爲影片的路徑,需要有附檔名.
        $conf["videoFilePosition"]="";
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["width"],字串,爲影片的寬度,預設不設置.
        #$conf["width"]="";
        #$conf["height"],字串,爲影片的高度,預設不設置.
        #$conf["height"]="";
        #$conf["codecs"],字串,爲解碼器名稱,預設爲 "vp8, vorbis"
        #$conf["codecs"]="vp8, vorbis"
        #$conf["autoplay"],字串,為是否要自動播放,"true"代表要,"false"代表不要,預設為"false".
        #$conf["autoplay"]="true";
        #$conf["loop"],字串,爲是否重複播放,若要重複播放則應填入 "true" ,預設爲不重複
        #$conf["loop"]="false";
        #$conf["controlls"],字串,是否要顯示控制面板,預設為"false"不顯示;反之為"true"要顯示.
        #$conf["controlls"]="true";
        #$conf["muted"],字串,是否要靜音,"true"代表要;預設為"false",不靜音.
        #$conf["muted"]="true";
        #$conf["styleAttr"],字串陣列,要套用的style樣式屬性.
        #$conf["styleAttr"]=array("");
        #$conf["styleVal"],字串陣列,要套用的style樣式數值.
        #$conf["styleVal"]=array("");
        #$conf["class"],字串,要套用的css類別樣式名稱.
        #$conf["class"]="";
        #參考資料:
        #無.
        #備註:
        #建議增加影片載入完畢就自動播放的js.
        */      
        public static function html5(&$conf){
        
                #初始化要回傳的內容
                $result=array();
                
                #取得當前函數名稱
                $result["function"]=__FUNCTION__;
                
                #如果 $conf 不為陣列
                if(gettype($conf)!="array"){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="\$conf變數須為陣列形態";

                        #如果傳入的參數為 null
                        if($conf==null){
                                
                                #設置執行錯誤訊息
                                $result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
                                
                                }#if end

                        #回傳結果
                        return $result;
                        
                        }#if end
                        
                #初始化要回傳的語法
                $result["content"]="";
                
                #檢查參數
                #函式說明:
                #檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$reuslt["error"],執行不正常結束的錯訊息陣列.
                #$result["function"],當前執行的函式名稱.
                #$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
                #$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
                #$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
                #$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
                #$result["argu"],字串陣列,目前輸入的參數名稱陣列.
                #$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
                #$result["notNeedVar"],字串陣列,多餘的參數名稱.
                #必填寫的參數:
                #$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
                $conf["variableCheck::checkArguments"]["varInput"]=&$conf;
                #$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","videoFilePosition");
                #$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); 
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
                #$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
                $conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
                #可以省略的參數:
                #$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
                $conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
                #$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["skipableVariableName"]=array("width","height","codecs","autoplay","loop","controlls","class","muted","styleAttr","styleVal");
                #$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
                $conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string","string","array","array");
                #$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
                $conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"vp8, vorbis","false","false","false",null,"false",null,null);
                #$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
                $conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("styleAttr","styleVal");
                #參考資料來源:
                #array_keys=>http://php.net/manual/en/function.array-keys.php
                $checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
                unset($conf["variableCheck::checkArguments"]);
        
                #如果檢查失敗
                if($checkArguments["status"]==="false"){
                        
                        #設置錯誤識別
                        $result["status"]="false";
                        
                        #設置錯誤訊息
                        $result["error"]=$checkArguments;
                        
                        #回傳結果
                        return $result;
                        
                        }#if end
        
                #如果檢查不通過
                if($checkArguments["passed"]=="false"){
                        
                        #設置錯誤識別
                        $result["status"]="false";
                        
                        #設置錯誤訊息
                        $result["error"]=$checkArguments;
                        
                        #回傳結果
                        return $result;
                        
                        }#if end
                
                #檢查影片檔案是否存在
                #函式說明:檢查多個檔案與資料夾是否存在.
                #回傳的結果:
                #$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息陣列.
                #$resutl["function"],當前執行的涵式名稱.
                #$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
                #$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
                #$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
                #必填參數:
                $conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["videoFilePosition"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
                #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
                $conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
                #可省略參數:
                #$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
                $conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
                #$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
                $conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
                #$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
                $conf["fileAccess::checkMultiFileExist"]["web"]="false";
                #參考資料來源:
                #http://php.net/manual/en/function.file-exists.php
                #http://php.net/manual/en/control-structures.foreach.php
                $checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
                unset($conf["fileAccess::checkMultiFileExist"]);

                #如果檢查失敗
                if($checkMultiFileExist["status"]=="false"){
                        
                        #設置執行不正常
                        $result["status"]="false";
                        
                        #設置執行錯誤
                        $result["error"]=$checkMultiFileExist;
                        
                        #回傳結果
                        return $result;
                        
                        }#if end
                        
                #如果聲音檔案不存在
                if($checkMultiFileExist["varExist"][0]=="false"){
                        
                        #設置執行不正常
                        $result["status"]="false";
                        
                        #設置執行錯誤
                        $result["error"][]="影片檔案「".$checkMultiFileExist["varName"][0]."」不存在!";
                        
                        #回傳結果
                        return $result;
                        
                        }#if end
                        
                #將聲音檔案用 base64 形式壓縮成16近位的英文數字
                #函數說明:
                #用data:mimeType;base64,fileVar的形式來提供檔案的連結,亦即檔案儲存在變數裡面.
                #回傳結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息
                #$result["content"],檔案變數的內容
                #$result["fileTypeName"],副檔名,ex:「.tar.xz」.
                #$result["function"],當前執行的函數名稱 
                #必填參數:
                #$conf["filePosition"],要轉存成2元碼的圖片檔案位置與名稱
                $conf["fileAccess::data"]["filePosition"]=$conf["videoFilePosition"];
                #$conf["mimeType"],2元碼的內容是什麼
                $conf["fileAccess::data"]["mimeType"]="video/*";
                #可省略參數:
                #$conf["compressType"],2元碼壓縮的方式,預設為"base64".
                #$conf["compressType"]="base64";
                #$conf["delFile"],讀取完檔案後,要移除檔案嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
                #$conf["delFile"]="false";
                #參考資料:
                #將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
                #壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
                $data=fileAccess::data($conf["fileAccess::data"]);
                unset($conf["fileAccess::data"]);

                #如果將聲音檔案用 base64 形式壓縮成16近位的英文數字失敗
                if($data["status"]=="false"){
                        
                        #設置執行不正常
                        $result["status"]="false";
                        
                        #設置執行錯誤
                        $result["error"]=$data;
                        
                        #回傳結果
                        return $result;
                        
                        }#if end
                
                #如果$conf["width"]有設定
                if(isset($conf["width"])){

                        #則按照指定的寬度       
                        $conf["width"]="width = ".$conf["width"];
                        
                        }#if end

                #如果$conf["width"]沒有設定
                else{
                        
                        $conf["width"]="";
                        
                        }#else end

                #如果$conf["height"]有設定
                if(isset($conf["height"])){

                        #則按照指定的高度
                        $conf["height"]="height = ".$conf["height"];
                        
                        }#if end

                #如果$conf["height"]沒有設定
                else{
                        
                        #則$conf["height"]爲空
                        $conf["height"]="";
                        
                        }#else end

                #設置解碼器
                $conf["codecs"]=" codecs=".$conf["codecs"];
                
                #預設不自動播放
                $autoplay="";
                
                #如果 $conf["autoplay"] 為 "true"
                if($conf["autoplay"]==="true"){
                        
                        #設置自動播放
                        $autoplay="autoplay";
                        
                        }#if end
                                        
                #如果$conf["loop"]為"true"
                if($conf["loop"]=="true"){

                        #則放置重複播放的語法         
                        $conf["loop"]=" loop=loop";
                        
                        }#if end
                        
                #反之 
                else{
                        
                        #設為空字串
                        $conf["loop"]="";
                        
                        }#else end
                
                #如果有設置 class 
                if(isset($conf["class"])){
                
                        #設置 class
                        $conf["class"]="class='".$conf["class"]."'";
                
                        }#if end
                
                #反之
                else{
                
                        #設置為空字串
                        $conf["class"]="";
                
                        }
                        
                #初始化控制器語法
                $controls="";
        
                #如果要顯示控制列
                if($conf["controlls"]==="true"){
                
                        #設定要顯示控制列
                        $controls="controls=controls";
                
                        }#if end
                
                #預設不靜音
                $muted="";      
                        
                #如果要靜音
                if($conf["muted"]==="true"){
                
                        #設置要靜音
                        $muted="muted";
                
                        }#if end        
                
                #初始化style為空
                $style="";
                
                #如果有設定 styleName 跟 styleVal
                if( isset($conf["styleName"]) && isset($conf["styleVal"]) ){
                
                        #函式說明:
                        #建立給與html標籤使用的style屬性字串.
                        #回傳結果:
                        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                        #$result["function"],當前執行的函數
                        #$result["error"],錯誤訊息陣列
                        #$result["content"],css設定內容
                        #必填參數:
                        $conf["css::styleStr"]["styleName"]=$conf["styleName"];#為屬性名稱,須為陣列值
                        $conf["css::styleStr"]["styleValue"]=$conf["styleVal"];#為屬性值,須為陣列值
                        #可省略參數:
                        #無.
                        #參考資料:
                        #無.
                        #備註:
                        #無.
                        $styleStr=css::styleStr($conf["css::styleStr"]);
                        unset($conf["css::styleStr"]);
                
                        if($styleStr["status"]=="false"){
                        
                                #設置執行不正常
                                $result["status"]="false";
                                
                                #設置執行錯誤
                                $result["error"]=$styleStr;
                        
                                #回傳結果
                                return $result;
                        
                                }#if end
                                
                        #設置style
                        $style=$styleStr["content"];
                
                        }#if end
                
                #語法開始,寬度,高度,控制面板            
                $result["content"]=$result["content"]."<video ".$conf["width"]." ".$conf["height"]." ".$controls." ".$autoplay." ".$conf["loop"]." ".$conf["class"]." >";
                $base64data="<video ".$conf["width"]." ".$conf["height"]." controls=controls ".$autoplay." ".$conf["loop"]." ".$conf["class"]." ".$muted." ".$style.">";
        
                #影片檔案位置,類型,所使用的解碼器
                $result["content"]=$result["content"]."<source src=\"".$conf["videoFilePosition"]."\" type=\"video/webm\" />";
                $base64data=$base64data."<source src=\"".$conf["videoFilePosition"]."\" type=\"video/webm\" />";

                #語法結束
                $result["content"]=$result["content"]."</video>";       
                $base64data=$base64data."</video>";
                
                #取得用base64加密影片後的影片放置語法
                $result["base64data"]=$base64data;
                
                #設置執行正常
                $result["status"]="true";
                
                #回傳語法
                return $result;
                        
                }#function html5 end
                
        }#class video end
        
?>