| 1 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 627 |
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 |
|
| 245 |
liveuser |
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
管理QBPWCFW適用套件的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
| 1 |
liveuser |
32 |
class lib{
|
|
|
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 |
#取得多個js,css等套件,該套件必須存放在同目錄的lib目錄底下.
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],執行正確與否,"true"代表執行正確,"false"代表執行失敗.
|
|
|
103 |
#$result["error"],錯誤訊息陣列.
|
|
|
104 |
#$result["content"],取得好的Jquery檔案路徑.
|
|
|
105 |
#$result["function"],當前執行的函數名稱.
|
|
|
106 |
#必填參數:
|
|
|
107 |
#無
|
|
|
108 |
#可省略參數:
|
|
|
109 |
#$conf["libAddr"],字串陣列,套件的本機位置預設為 array("lib/jquery-2.2.2.js","lib/notify.js","lib/bootstrap-3.3.6-dist/js/bootstrap","lib/Chart.js")
|
|
|
110 |
#$conf["libAddr"]=array("");
|
|
|
111 |
#$conf["libWebAddr"],字串陣列,套件的網路位置,預設為 array("https://code.jquery.com/jquery-2.2.2.js","https://rawgit.com/notifyjs/notifyjs/master/dist/notify.js","https://github.com/twbs/bootstrap/archive/v3.3.6.zip","https://github.com/chartjs/Chart.js/releases/download/v2.6.0/Chart.js.zip")
|
|
|
112 |
#$conf["libWebAddr"]=array("");
|
|
|
113 |
#參考資料來源:
|
|
|
114 |
#https://code.jquery.com/jquery-2.2.2.js
|
|
|
115 |
#https://rawgit.com/notifyjs/notifyjs/master/dist/notify.js
|
|
|
116 |
#https://github.com/twbs/bootstrap/archive/v3.3.6.zip
|
|
|
117 |
#https://github.com/chartjs/Chart.js/releases/tag/v2.6.0
|
|
|
118 |
#備註:
|
|
|
119 |
#尚未增加的套件 ckeditor ods-php-0.1rc1 phpodt-0.3.3 webrtc apache-hive amchart tcpdf
|
|
|
120 |
#建構中...
|
|
|
121 |
*/
|
|
|
122 |
public static function getLib(&$conf=array()){
|
|
|
123 |
|
|
|
124 |
#初始化要回傳的結果
|
|
|
125 |
$result=array();
|
|
|
126 |
|
|
|
127 |
#取得當前執行的函數名稱
|
|
|
128 |
$result["function"]=__FUNCTION__;
|
|
|
129 |
|
|
|
130 |
#取得參數
|
|
|
131 |
$result["argu"]=$conf;
|
|
|
132 |
|
|
|
133 |
#如果 $conf 不為陣列
|
|
|
134 |
if(gettype($conf)!="array"){
|
|
|
135 |
|
|
|
136 |
#設置執行失敗
|
|
|
137 |
$result["status"]="false";
|
|
|
138 |
|
|
|
139 |
#設置執行錯誤訊息
|
|
|
140 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
141 |
|
|
|
142 |
#如果傳入的參數為 null
|
|
|
143 |
if($conf==null){
|
|
|
144 |
|
|
|
145 |
#設置執行錯誤訊息
|
|
|
146 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
147 |
|
|
|
148 |
}#if end
|
|
|
149 |
|
|
|
150 |
#回傳結果
|
|
|
151 |
return $result;
|
|
|
152 |
|
|
|
153 |
}#if end
|
|
|
154 |
|
|
|
155 |
#檢查參數
|
|
|
156 |
#函式說明:
|
|
|
157 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
158 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
159 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
160 |
#$result["function"],當前執行的函式名稱.
|
|
|
161 |
#$result["argu"],設置給予的參數.
|
|
|
162 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
163 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
164 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
165 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
166 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
167 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
168 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
169 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
170 |
#必填寫的參數:
|
|
|
171 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
172 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
173 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
174 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
175 |
#可以省略的參數:
|
|
|
176 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
177 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
178 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
179 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
180 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
181 |
#$conf["canBeEmptyString"]="false";
|
|
|
182 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
183 |
#$conf["canNotBeEmpty"]=array();
|
|
|
184 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
185 |
#$conf["canBeEmpty"]=array();
|
|
|
186 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
187 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("libAddr","libWebAddr");
|
|
|
188 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
189 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("libAddr","libWebAddr");
|
|
|
190 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
191 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array");
|
|
|
192 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
193 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array("lib/jquery-2.2.2.js","lib/notify.js","lib/bootstrap-3.3.6-dist","lib/Chart.js"),array("https://code.jquery.com/jquery-2.2.2.js","https://rawgit.com/notifyjs/notifyjs/master/dist/notify.js","https://github.com/twbs/bootstrap/archive/v3.3.6.zip","https://github.com/chartjs/Chart.js/releases/download/v2.6.0/Chart.js.zip"));
|
|
|
194 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
195 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
196 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
197 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
198 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
199 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
200 |
#參考資料來源:
|
|
|
201 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
202 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
203 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
204 |
|
|
|
205 |
#如果檢查參數失敗
|
|
|
206 |
if($checkArguments["status"]==="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 |
if($checkArguments["passed"]==="false"){
|
|
|
221 |
|
|
|
222 |
#設置執行失敗
|
|
|
223 |
$result["status"]="false";
|
|
|
224 |
|
|
|
225 |
#設置錯誤訊息
|
|
|
226 |
$result["error"]=$checkArguments;
|
|
|
227 |
|
|
|
228 |
#回傳結果
|
|
|
229 |
return $result;
|
|
|
230 |
|
|
|
231 |
}#if end
|
|
|
232 |
|
|
|
233 |
#針對每個 js lib
|
|
|
234 |
foreach($libAddr as $index => $lib){
|
|
|
235 |
|
|
|
236 |
#js套件應該要存放的地方
|
|
|
237 |
$jsAddr=&$lib;
|
|
|
238 |
|
|
|
239 |
#js套件的網路位置
|
|
|
240 |
$jsWebAddr=&$libWebAddr[$index];
|
|
|
241 |
|
|
|
242 |
#檢查jqery套件是否存在
|
|
|
243 |
#涵式說明:檢查多個檔案與資料夾是否存在.
|
|
|
244 |
#回傳的結果:
|
|
|
245 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
246 |
#$result["error"],錯誤訊息陣列.
|
|
|
247 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
248 |
#$result["argu"],使用的參數.
|
|
|
249 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
250 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
251 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
|
|
|
252 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
|
|
|
253 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
254 |
#必填參數:
|
|
|
255 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
256 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($jsAddr);
|
|
|
257 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
258 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
259 |
#可省略參數
|
|
|
260 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
261 |
#$conf["disableWebSearch"]="false";
|
|
|
262 |
#參考資料來源:
|
|
|
263 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
264 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
265 |
#備註:
|
|
|
266 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
267 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
268 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
|
|
269 |
|
|
|
270 |
#如果檢查js套件失敗
|
|
|
271 |
if($checkMultiFileExist["status"]==="false"){
|
|
|
272 |
|
|
|
273 |
#設置執行失敗
|
|
|
274 |
$result["status"]="false";
|
|
|
275 |
|
|
|
276 |
#設置錯誤訊息
|
|
|
277 |
$result["error"]=$checkMultiFileExist;
|
|
|
278 |
|
|
|
279 |
#回傳結果
|
|
|
280 |
return $result;
|
|
|
281 |
|
|
|
282 |
}#if end
|
|
|
283 |
|
|
|
284 |
#如果檢查js套件不存在
|
|
|
285 |
if($checkMultiFileExist["varExist"][0]==="false"){
|
|
|
286 |
|
|
|
287 |
#函式說明:
|
|
|
288 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
289 |
#回傳的變數說明:
|
|
|
290 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
291 |
#$result["error"],錯誤訊息提示.
|
|
|
292 |
#$result["warning"],警告訊息.
|
|
|
293 |
#$result["function"],當前執行的函數名稱.
|
|
|
294 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
295 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
296 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
297 |
#必填的參數:
|
|
|
298 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
299 |
$conf["fileAccess::getFileContent"]["filePositionAndName"]=$jsWebAddr;
|
|
|
300 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
301 |
$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
302 |
#參考資料:
|
|
|
303 |
#file(),取得檔案內容的行數.
|
|
|
304 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
305 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
306 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
307 |
$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
|
|
|
308 |
unset($conf["fileAccess::getFileContent"]);
|
|
|
309 |
|
|
|
310 |
#如果取得套件失敗
|
|
|
311 |
if($getFileContent["status"]==="false"){
|
|
|
312 |
|
|
|
313 |
#設置執行失敗
|
|
|
314 |
$result["status"]="false";
|
|
|
315 |
|
|
|
316 |
#設置錯誤訊息
|
|
|
317 |
$result["error"]=$getFileContent;
|
|
|
318 |
|
|
|
319 |
#回傳結果
|
|
|
320 |
return $result;
|
|
|
321 |
|
|
|
322 |
}#if end
|
|
|
323 |
|
|
|
324 |
#如果是js檔案
|
|
|
325 |
if(strpos($jsWebAddr,".js")!==false && ){
|
|
|
326 |
|
|
|
327 |
#寫入js套件的內容
|
|
|
328 |
#涵式說明:
|
|
|
329 |
#將字串寫入到檔案
|
|
|
330 |
#回傳的結果:
|
|
|
331 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
332 |
#$result["error"],錯誤訊息陣列.
|
|
|
333 |
#$result["function"],當前執行的函數名稱.
|
|
|
334 |
#$result["fileInfo"],實際上寫入的檔案資訊陣列.
|
|
|
335 |
#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
|
|
|
336 |
#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
|
|
|
337 |
#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
338 |
#必填的參數:
|
|
|
339 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
340 |
$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
341 |
#可省略的參數:
|
|
|
342 |
#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
|
|
|
343 |
$conf["fileAccess::writeTextIntoFile"]["fileName"]=$jsAddr;
|
|
|
344 |
#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
|
|
|
345 |
$conf["fileAccess::writeTextIntoFile"]["inputString"]=$getFileContent["fullContent"];
|
|
|
346 |
#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
|
|
|
347 |
#$conf["writeMethod"]="a";
|
|
|
348 |
#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
|
|
|
349 |
#$conf["checkRepeat"]="";
|
|
|
350 |
#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
351 |
#$conf["filenameExtensionStartPoint"]="";
|
|
|
352 |
#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
353 |
#$conf["repeatNameRule"]="";
|
|
|
354 |
$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
|
|
|
355 |
unset($conf["fileAccess::writeTextIntoFile"]);
|
|
|
356 |
|
|
|
357 |
#如果建立js lib檔案失敗
|
|
|
358 |
if($writeTextIntoFile["status"]="false"){
|
|
|
359 |
|
|
|
360 |
#設置執行失敗
|
|
|
361 |
$result["status"]="false";
|
|
|
362 |
|
|
|
363 |
#設置錯誤訊息
|
|
|
364 |
$result["error"]=$writeTextIntoFile;
|
|
|
365 |
|
|
|
366 |
#回傳結果
|
|
|
367 |
return $result;
|
|
|
368 |
|
|
|
369 |
}#if end
|
|
|
370 |
|
|
|
371 |
#轉換js lib檔案路徑為相對路徑
|
|
|
372 |
#函數說明:
|
|
|
373 |
#將多個路徑字串變成相對於當前路徑的相對路徑字串
|
|
|
374 |
#回傳結果:
|
|
|
375 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
376 |
#$result["error"],錯誤訊息陣列.
|
|
|
377 |
#$result["function"],函數名稱.
|
|
|
378 |
#$result["argu"],使用的參數.
|
|
|
379 |
#$result["content"],字串陣列,多個轉換好的相對路徑字串.
|
|
|
380 |
#必填參數:
|
|
|
381 |
#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
|
|
|
382 |
$conf["fileAccess::getRelativePath"]["path"]=array($writeTextIntoFile["fileInfo"]["createdFilePathAndName"]);
|
|
|
383 |
#$conf["fileArgu"],字串,當前路徑.
|
|
|
384 |
$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
|
|
|
385 |
$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
|
|
|
386 |
unset($conf["fileAccess::getRelativePath"]);
|
|
|
387 |
|
|
|
388 |
#如果轉換成相對位置失敗
|
|
|
389 |
if($getRelativePath["status"]==="false"){
|
|
|
390 |
|
|
|
391 |
#設置執行失敗
|
|
|
392 |
$result["status"]="false";
|
|
|
393 |
|
|
|
394 |
#設置錯誤訊息
|
|
|
395 |
$result["error"]=$getRelativePath;
|
|
|
396 |
|
|
|
397 |
#回傳結果
|
|
|
398 |
return $result;
|
|
|
399 |
|
|
|
400 |
}#if end
|
|
|
401 |
|
|
|
402 |
#取得 js 套件的相對路徑
|
|
|
403 |
$result["content"][]=$getRelativePath["content"];
|
|
|
404 |
|
|
|
405 |
}#if end
|
|
|
406 |
|
|
|
407 |
#反之為 zip 檔案
|
|
|
408 |
else if(strpos($jsWebAddr,".zip")){
|
|
|
409 |
|
|
|
410 |
#取得zip檔案的名稱
|
|
|
411 |
$zipFile=basename($jsAddr).".zip";
|
|
|
412 |
|
|
|
413 |
#取得zip檔案的內容
|
|
|
414 |
$zipFileContent=&$getFileContent["fullContent"];
|
|
|
415 |
|
|
|
416 |
#打開要建立的zip檔案
|
|
|
417 |
$jsLibZipFile=fopen($jsAddr.".zip","w");
|
|
|
418 |
|
|
|
419 |
#寫入zip檔案的內容
|
|
|
420 |
fwrite($jsLibZipFile,$zipFileContent);
|
|
|
421 |
|
|
|
422 |
#關閉檔案
|
|
|
423 |
fclose($jsLibZipFile);
|
|
|
424 |
|
|
|
425 |
#取得要解壓縮的目錄
|
|
|
426 |
#涵式說明:
|
|
|
427 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
428 |
#回傳結果:
|
|
|
429 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
430 |
#$result["error"],錯誤訊息陣列
|
|
|
431 |
#$result["function"],當前執行的函數名稱.
|
|
|
432 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
433 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
434 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
435 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
436 |
#必填的參數:
|
|
|
437 |
$conf["stringProcess::spiltString"]["stringIn"]=$zipFile;#要處理的字串。
|
|
|
438 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
|
|
|
439 |
#可省略參數:
|
|
|
440 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
441 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
442 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
443 |
unset($conf["stringProcess::spiltString"]);
|
|
|
444 |
|
|
|
445 |
#如果分割內容失敗
|
|
|
446 |
if($spiltString["status"]==="false"){
|
|
|
447 |
|
|
|
448 |
#設置執行失敗
|
|
|
449 |
$result["status"]="false";
|
|
|
450 |
|
|
|
451 |
#設置錯誤訊息
|
|
|
452 |
$result["error"]=$spiltString;
|
|
|
453 |
|
|
|
454 |
#回傳結果
|
|
|
455 |
return $result;
|
|
|
456 |
|
|
|
457 |
}#if end
|
|
|
458 |
|
|
|
459 |
#如果沒有分割用的符號 /
|
|
|
460 |
if($spiltString["found"]==="false"){
|
|
|
461 |
|
|
|
462 |
#設置執行失敗
|
|
|
463 |
$result["status"]="false";
|
|
|
464 |
|
|
|
465 |
#設置錯誤訊息
|
|
|
466 |
$result["error"]=$spiltString;
|
|
|
467 |
|
|
|
468 |
#回傳結果
|
|
|
469 |
return $result;
|
|
|
470 |
|
|
|
471 |
}#if end
|
|
|
472 |
|
|
|
473 |
#要進入的目錄
|
|
|
474 |
$libPath=&$spiltString["dataArray"][0];
|
|
|
475 |
|
|
|
476 |
#進入要解壓縮的目錄
|
|
|
477 |
$cmd[]="cd";
|
|
|
478 |
$argu[]=array($libPath);
|
|
|
479 |
|
|
|
480 |
#解壓縮lib
|
|
|
481 |
$cmd[]="unzip ".$libPath;
|
|
|
482 |
$argu[]=array($libPath);
|
|
|
483 |
|
|
|
484 |
#移除lib
|
|
|
485 |
$cmd[]="rm";
|
|
|
486 |
$argu[]=array($libPath);
|
|
|
487 |
|
|
|
488 |
#離開要解壓縮的目錄
|
|
|
489 |
$cmd[]="cd";
|
|
|
490 |
$argu[]=array("..");
|
|
|
491 |
|
|
|
492 |
#涵式說明:
|
|
|
493 |
#呼叫shell依序執行系統命令,並取得回傳的內容.
|
|
|
494 |
#回傳的結果:
|
|
|
495 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
496 |
#$result["error"],錯誤訊息陣列.
|
|
|
497 |
#$result["function"],當前執行的函數名稱.
|
|
|
498 |
#$result["cmd"],執行的指令內容.
|
|
|
499 |
#$result["output"],爲執行完每個指令後的輸出陣列.
|
|
|
500 |
#必填的參數
|
|
|
501 |
#$conf["command"],字串陣列,要執行的指令.
|
|
|
502 |
$conf["external::callShellMulti"]["command"]=&$cmd;
|
|
|
503 |
#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
|
|
|
504 |
$conf["external::callShellMulti"]["fileArgu"]=$conf["fileArgu"];
|
|
|
505 |
#可省略參數:
|
|
|
506 |
#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.
|
|
|
507 |
$conf["external::callShellMulti"]=&$argu;
|
|
|
508 |
#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
|
|
|
509 |
#$conf["enablePrintDescription"]=array("false");
|
|
|
510 |
#$conf["printDescription"],字串陣列,執行各個$conf["command"]前要印出來的的文字,預設為$conf["command"]的內容,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
|
|
|
511 |
#$conf["printDescription"]=array("");
|
|
|
512 |
#$conf["escapeshellarg"],字串陣列,執行各個$conf["command"]時是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false",其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
|
| 453 |
liveuser |
513 |
$conf["external::callShellMulti"]["escapeshellarg"]=array("true");
|
| 1 |
liveuser |
514 |
#$conf["username"],陣列字串,每個指令要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
515 |
#$conf["username"]=array("");
|
|
|
516 |
#$conf["password"],陣列字串,每個指令與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
517 |
#$conf["password"]=array("");
|
|
|
518 |
#$conf["useScript"],字串,每個指令的執行是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
|
|
|
519 |
#$conf["useScript"]="";
|
|
|
520 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
|
|
|
521 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
522 |
#$conf["inBackGround"],字串,每個指令的執行是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
523 |
#$conf["inBackGround"]="";
|
|
|
524 |
#備註:
|
|
|
525 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
|
|
|
526 |
#參考資料:
|
|
|
527 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
528 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
529 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
530 |
$callShellMulti=external::callShellMulti($conf["external::callShellMulti"]);
|
|
|
531 |
unset($conf["external::callShellMulti"]);
|
|
|
532 |
|
|
|
533 |
#如果運行指令失敗
|
|
|
534 |
if($callShellMulti["status"]==="false"){
|
|
|
535 |
|
|
|
536 |
#設置執行失敗
|
|
|
537 |
$result["status"]="false";
|
|
|
538 |
|
|
|
539 |
#設置錯誤訊息
|
|
|
540 |
$result["error"]=$callShellMulti;
|
|
|
541 |
|
|
|
542 |
#回傳結果
|
|
|
543 |
return $result;
|
|
|
544 |
|
|
|
545 |
}#if end
|
|
|
546 |
|
|
|
547 |
#如果就壓縮好的 js 套件目錄不存在
|
|
|
548 |
if(!file_exists($jsAddr)){
|
|
|
549 |
|
|
|
550 |
#設置執行失敗
|
|
|
551 |
$result["status"]="false";
|
|
|
552 |
|
|
|
553 |
#設置錯誤訊息
|
|
|
554 |
$result["error"][]=$jsAddr." 不存在";
|
|
|
555 |
|
|
|
556 |
#回傳結果
|
|
|
557 |
return $result;
|
|
|
558 |
|
|
|
559 |
}#if end
|
|
|
560 |
|
|
|
561 |
#如果解壓縮好的 js 套件最外層不是目錄
|
|
|
562 |
if(!is_dir($jsAddr)){
|
|
|
563 |
|
|
|
564 |
#設置執行失敗
|
|
|
565 |
$result["status"]="false";
|
|
|
566 |
|
|
|
567 |
#設置錯誤訊息
|
|
|
568 |
$result["error"][]=$jsAddr." 應該為目錄";
|
|
|
569 |
|
|
|
570 |
#回傳結果
|
|
|
571 |
return $result;
|
|
|
572 |
|
|
|
573 |
}#if end
|
|
|
574 |
|
|
|
575 |
#取得 js 套件的相對路徑
|
|
|
576 |
$result["content"][]=$jsAddr;
|
|
|
577 |
|
|
|
578 |
}#else end
|
|
|
579 |
|
|
|
580 |
#反之
|
|
|
581 |
else{
|
|
|
582 |
|
|
|
583 |
#設置執行失敗
|
|
|
584 |
$result["status"]="false";
|
|
|
585 |
|
|
|
586 |
#設置錯誤訊息
|
|
|
587 |
$result["error"][]=$jsAddr."為不支援的js套件格式.";
|
|
|
588 |
|
|
|
589 |
#回傳結果
|
|
|
590 |
return $result;
|
|
|
591 |
|
|
|
592 |
}#else end
|
|
|
593 |
|
|
|
594 |
}#if end
|
|
|
595 |
|
|
|
596 |
#反之存在
|
|
|
597 |
else if($checkMultiFileExist["varExist"][0]==="true"){
|
|
|
598 |
|
|
|
599 |
#轉換 js 套件的位置為相對位置
|
|
|
600 |
#函數說明:
|
|
|
601 |
#將多個路徑字串變成相對於當前路徑的相對路徑字串
|
|
|
602 |
#回傳結果:
|
|
|
603 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
604 |
#$result["error"],錯誤訊息陣列.
|
|
|
605 |
#$result["function"],函數名稱.
|
|
|
606 |
#$result["argu"],使用的參數.
|
|
|
607 |
#$result["content"],字串陣列,多個轉換好的相對路徑字串.
|
|
|
608 |
#必填參數:
|
|
|
609 |
#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
|
|
|
610 |
$conf["fileAccess::getRelativePath"]["path"]=array($checkMultiFileExist["varNameFullPath"][0]);
|
|
|
611 |
#$conf["fileArgu"],字串,當前路徑.
|
|
|
612 |
$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
|
|
|
613 |
$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
|
|
|
614 |
unset($conf["fileAccess::getRelativePath"]);
|
|
|
615 |
|
|
|
616 |
#如果轉換成相對位置失敗
|
|
|
617 |
if($getRelativePath["status"]==="false"){
|
|
|
618 |
|
|
|
619 |
#設置執行失敗
|
|
|
620 |
$result["status"]="false";
|
|
|
621 |
|
|
|
622 |
#設置錯誤訊息
|
|
|
623 |
$result["error"]=$getRelativePath;
|
|
|
624 |
|
|
|
625 |
#回傳結果
|
|
|
626 |
return $result;
|
|
|
627 |
|
|
|
628 |
}#if end
|
|
|
629 |
|
|
|
630 |
#取得 js 套件的相對路徑
|
|
|
631 |
$result["content"]=$getRelativePath["content"];
|
|
|
632 |
|
|
|
633 |
}#if end
|
|
|
634 |
|
|
|
635 |
}#foreach end
|
|
|
636 |
|
|
|
637 |
#設置執行成功
|
|
|
638 |
$result["status"]="true";
|
|
|
639 |
|
|
|
640 |
#回傳結果
|
|
|
641 |
return $result;
|
|
|
642 |
|
|
|
643 |
}#function getLib end
|
|
|
644 |
|
|
|
645 |
}#class lib end
|
|
|
646 |
|
|
|
647 |
?>
|