| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 239 |
liveuser |
6 |
Copyright (C) 2014~2026 MIN ZHI, CHEN
|
| 3 |
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 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
跟網頁安全性有關的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class security{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#可省略參數:
|
|
|
45 |
#無.
|
|
|
46 |
#參考資料:
|
|
|
47 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
48 |
#備註:
|
|
|
49 |
#無.
|
|
|
50 |
*/
|
|
|
51 |
public function __call($method,$arguments){
|
| 226 |
liveuser |
52 |
|
| 3 |
liveuser |
53 |
#取得當前執行的函式
|
|
|
54 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
55 |
|
| 3 |
liveuser |
56 |
#設置執行不正常
|
|
|
57 |
$result["status"]="false";
|
| 226 |
liveuser |
58 |
|
| 3 |
liveuser |
59 |
#設置執行錯誤
|
|
|
60 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
61 |
|
| 3 |
liveuser |
62 |
#設置所丟入的參數
|
|
|
63 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
64 |
|
| 3 |
liveuser |
65 |
#回傳結果
|
|
|
66 |
return $result;
|
| 226 |
liveuser |
67 |
|
| 3 |
liveuser |
68 |
}#function __call end
|
| 226 |
liveuser |
69 |
|
| 3 |
liveuser |
70 |
/*
|
|
|
71 |
#函式說明:
|
|
|
72 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
73 |
#回傳結果:
|
|
|
74 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
75 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
76 |
#$result["function"],當前執行的函式名稱.
|
|
|
77 |
#必填參數:
|
|
|
78 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
79 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
80 |
#可省略參數:
|
|
|
81 |
#無.
|
|
|
82 |
#參考資料:
|
|
|
83 |
#__callStatic=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
84 |
#備註:
|
|
|
85 |
#無.
|
|
|
86 |
*/
|
|
|
87 |
public static function __callStatic($method,$arguments){
|
| 226 |
liveuser |
88 |
|
| 3 |
liveuser |
89 |
#取得當前執行的函式
|
|
|
90 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
91 |
|
| 3 |
liveuser |
92 |
#設置執行不正常
|
|
|
93 |
$result["status"]="false";
|
| 226 |
liveuser |
94 |
|
| 3 |
liveuser |
95 |
#設置執行錯誤
|
|
|
96 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
97 |
|
| 3 |
liveuser |
98 |
#設置所丟入的參數
|
|
|
99 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
100 |
|
| 3 |
liveuser |
101 |
#回傳結果
|
|
|
102 |
return $result;
|
| 226 |
liveuser |
103 |
|
| 3 |
liveuser |
104 |
}#function __callStatic end
|
| 226 |
liveuser |
105 |
|
| 3 |
liveuser |
106 |
/*
|
| 226 |
liveuser |
107 |
#函式說明:
|
| 3 |
liveuser |
108 |
#禁止特定的angent訪問我們的網站,例如google與百度的搜尋引擎。
|
|
|
109 |
#回傳結果:
|
|
|
110 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
111 |
#$result["error"],錯誤訊息.
|
|
|
112 |
#$result["function"],當前執行的函數名稱.
|
|
|
113 |
#必填參數:
|
|
|
114 |
#$conf["disableAngentName"],字串,要禁止拜訪的用戶端資訊,代表要禁止哪些瀏覽器/搜尋引擎瀏覽,格式爲 /(含有哪些關鍵字,若有多個請用「|」隔開。)/i.
|
|
|
115 |
$conf["disableAngentName"]="/(Chrome|Mozilla|Internet)/i";
|
|
|
116 |
#可省略參數:
|
|
|
117 |
#$conf["transferLocation"],字串,如果是要禁止搜尋引擎,要轉址到那個地方?,若沒設定,則預設爲資安素養網的臉書(https://zh-tw.facebook.com/isafemoe).
|
|
|
118 |
#$conf["transferLocation"]="";
|
|
|
119 |
#參考資料:
|
|
|
120 |
#http://php.net/manual/en/function.preg-match.php
|
|
|
121 |
#備註:
|
|
|
122 |
#無.
|
|
|
123 |
*/
|
|
|
124 |
public static function preventSerchEngine(&$conf){
|
|
|
125 |
|
|
|
126 |
#初始化要回傳的內容
|
|
|
127 |
$result=array();
|
| 226 |
liveuser |
128 |
|
| 3 |
liveuser |
129 |
#取得當前執行的函式
|
|
|
130 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
131 |
|
| 3 |
liveuser |
132 |
#如果 $conf 不為陣列
|
|
|
133 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
134 |
|
| 3 |
liveuser |
135 |
#設置執行失敗
|
|
|
136 |
$result["status"]="false";
|
| 226 |
liveuser |
137 |
|
| 3 |
liveuser |
138 |
#設置執行錯誤訊息
|
|
|
139 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
140 |
|
|
|
141 |
#如果傳入的參數為 null
|
|
|
142 |
if($conf==null){
|
| 226 |
liveuser |
143 |
|
| 3 |
liveuser |
144 |
#設置執行錯誤訊息
|
|
|
145 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
146 |
|
| 3 |
liveuser |
147 |
}#if end
|
|
|
148 |
|
|
|
149 |
#回傳結果
|
|
|
150 |
return $result;
|
| 226 |
liveuser |
151 |
|
| 3 |
liveuser |
152 |
}#if end
|
|
|
153 |
|
|
|
154 |
#debug,檢查 $_SERVER["HTTP_USER_AGENT"] 的內容
|
|
|
155 |
#var_dump($_SERVER['HTTP_USER_AGENT']);
|
| 226 |
liveuser |
156 |
|
| 3 |
liveuser |
157 |
#檢查參數
|
|
|
158 |
#函式說明:
|
|
|
159 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
160 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
161 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
162 |
#$result["function"],當前執行的函式名稱.
|
|
|
163 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
164 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
165 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
166 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
167 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
168 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
169 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
170 |
#必填寫的參數:
|
|
|
171 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
172 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
173 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
174 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("disableAngentName");
|
| 226 |
liveuser |
175 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
176 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
177 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
178 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
179 |
#可以省略的參數:
|
|
|
180 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
181 |
#$conf["canBeEmptyString"]="false";
|
|
|
182 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
183 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("transferLocation");
|
| 226 |
liveuser |
184 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
185 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
186 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
187 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("https://zh-tw.facebook.com/isafemoe");
|
|
|
188 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
189 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
190 |
#參考資料來源:
|
|
|
191 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
192 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
193 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
194 |
|
| 3 |
liveuser |
195 |
#如果檢查失敗
|
|
|
196 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
197 |
|
| 3 |
liveuser |
198 |
#設置執行失敗
|
|
|
199 |
$result["status"]="false";
|
| 226 |
liveuser |
200 |
|
| 3 |
liveuser |
201 |
#設置執行錯誤訊息
|
|
|
202 |
$result["error"]=$checkArguments;
|
|
|
203 |
|
|
|
204 |
#回傳結果
|
|
|
205 |
return $result;
|
| 226 |
liveuser |
206 |
|
|
|
207 |
}#if end
|
|
|
208 |
|
| 3 |
liveuser |
209 |
#如果檢查不通過
|
|
|
210 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
211 |
|
| 3 |
liveuser |
212 |
#設置執行失敗
|
|
|
213 |
$result["status"]="false";
|
| 226 |
liveuser |
214 |
|
| 3 |
liveuser |
215 |
#設置執行錯誤訊息
|
|
|
216 |
$result["error"]=$checkArguments;
|
|
|
217 |
|
|
|
218 |
#回傳結果
|
|
|
219 |
return $result;
|
| 226 |
liveuser |
220 |
|
|
|
221 |
}#if end
|
|
|
222 |
|
| 3 |
liveuser |
223 |
#如果使用者的瀏覽器出現變數 $conf["disableAngentName"] 裡面的關鍵字
|
|
|
224 |
if(preg_match($conf["disableAngentName"],$_SERVER["HTTP_USER_AGENT"])){
|
|
|
225 |
|
|
|
226 |
#則轉址特定頁面
|
|
|
227 |
#函式說明:
|
|
|
228 |
#設定session變數後,立即轉址.
|
|
|
229 |
#回傳結果:
|
|
|
230 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.
|
|
|
231 |
#$result["function"],當前執行的函數名稱.
|
|
|
232 |
#$result["error"],錯誤訊息陣列.
|
|
|
233 |
#必填的參數:
|
|
|
234 |
#$conf["header::redirectionNow"]["headerLocation"],為要轉址到的地方,若爲 $_SERVER["PHP_SELF"],則爲回到目前頁面,全民資安素養網爲 https://isafe.moe.edu.tw/.
|
|
|
235 |
$conf["header::redirectionNow"]["headerLocation"]=$conf["transferLocation"];
|
|
|
236 |
#可省略的參數:
|
|
|
237 |
#$conf["sessionName"],字串陣列,可以指派session變數的名稱.
|
|
|
238 |
#$conf["sessionName"]=array("");
|
|
|
239 |
#$conf["sessionValue"]字串陣列,可以指派session變數的內容.
|
|
|
240 |
#$conf["sessionValue"]=array("");
|
|
|
241 |
#參靠資料來源:
|
|
|
242 |
#http://php.net/manual/en/reserved.variables.server.php
|
|
|
243 |
$redirectionNow=header::redirectionNow($conf["header::redirectionNow"]);
|
| 226 |
liveuser |
244 |
unset($conf["header::redirectionNow"]);
|
|
|
245 |
|
| 3 |
liveuser |
246 |
#如果轉址失敗
|
|
|
247 |
if($redirectionNow["status"]=="false"){
|
| 226 |
liveuser |
248 |
|
| 3 |
liveuser |
249 |
#設置執行失敗
|
|
|
250 |
$result["status"]="false";
|
| 226 |
liveuser |
251 |
|
| 3 |
liveuser |
252 |
#設置執行錯誤訊息
|
|
|
253 |
$result["error"]=$redirectionNow;
|
|
|
254 |
|
|
|
255 |
#回傳結果
|
|
|
256 |
return $result;
|
| 226 |
liveuser |
257 |
|
| 3 |
liveuser |
258 |
}#if end
|
| 226 |
liveuser |
259 |
|
|
|
260 |
}#if end
|
|
|
261 |
|
| 3 |
liveuser |
262 |
#執行到這邊代表是可以拜訪的網頁瀏覽器
|
|
|
263 |
$result["status"]="true";
|
| 226 |
liveuser |
264 |
|
| 3 |
liveuser |
265 |
#回傳結果
|
|
|
266 |
return $result;
|
|
|
267 |
|
|
|
268 |
}#function preventSerchEngine end
|
|
|
269 |
|
|
|
270 |
/*
|
|
|
271 |
#函式說明:
|
|
|
272 |
#禁止做任違反版權的事情,禁止在網頁按下滑鼠右鍵,禁止複製圖片,禁止開新分頁(失敗), 版權所有、Power by訊息.
|
|
|
273 |
#回傳的內容:
|
|
|
274 |
#保護版權的語法
|
|
|
275 |
#必填參數:
|
|
|
276 |
#無
|
|
|
277 |
#可省略參數:
|
|
|
278 |
#$conf["name"],字串,公司、組織、單位的名稱,預設不指定.
|
|
|
279 |
#$conf["name"]="";
|
|
|
280 |
#$conf["powerBy"],字串,由誰提供,預設爲QBPWCF.
|
|
|
281 |
#$conf["powerBy"]="";
|
|
|
282 |
#$conf["powerByLink"],字串,power by字串的連結目標,預設爲"https://www.qbpwcf.org".
|
|
|
283 |
#$conf["powerByLink"]="";
|
|
|
284 |
#$conf["bgColor"],字串,背景顏色,預設爲淡藍色.
|
|
|
285 |
#$conf["bgColor"]="";
|
|
|
286 |
#參考資料:
|
|
|
287 |
#http://www.w3schools.com/jsref/dom_obj_event.asp
|
|
|
288 |
#備註:
|
|
|
289 |
#無.
|
|
|
290 |
*/
|
|
|
291 |
public static function copyRight(&$conf){
|
| 226 |
liveuser |
292 |
|
| 3 |
liveuser |
293 |
#初始化要回傳的結果
|
|
|
294 |
$result=array();
|
|
|
295 |
|
|
|
296 |
#取得當前執行的函數名稱
|
|
|
297 |
$result["function"]=__FUNCTION__;
|
|
|
298 |
|
|
|
299 |
#取得參數
|
|
|
300 |
$result["argu"]=$conf;
|
|
|
301 |
|
|
|
302 |
#如果 $conf 不為陣列
|
|
|
303 |
if(gettype($conf)!="array"){
|
|
|
304 |
|
|
|
305 |
#設置執行失敗
|
|
|
306 |
$result["status"]="false";
|
|
|
307 |
|
|
|
308 |
#設置執行錯誤訊息
|
|
|
309 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
310 |
|
|
|
311 |
#如果傳入的參數為 null
|
|
|
312 |
if(is_null($conf)){
|
|
|
313 |
|
|
|
314 |
#設置執行錯誤訊息
|
|
|
315 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
316 |
|
|
|
317 |
}#if end
|
|
|
318 |
|
|
|
319 |
#回傳結果
|
|
|
320 |
return $result;
|
|
|
321 |
|
|
|
322 |
}#if end
|
| 226 |
liveuser |
323 |
|
| 3 |
liveuser |
324 |
#初始化 content
|
| 226 |
liveuser |
325 |
$result["content"]="";
|
|
|
326 |
|
| 3 |
liveuser |
327 |
#函式說明:
|
|
|
328 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
329 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
330 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
331 |
#$result["function"],當前執行的函式名稱.
|
|
|
332 |
#$result["argu"],設置給予的參數.
|
|
|
333 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
334 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
335 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
336 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
337 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
338 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
339 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
340 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
341 |
#必填寫的參數:
|
|
|
342 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
343 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
344 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
345 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
346 |
#可以省略的參數:
|
|
|
347 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
348 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
349 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
350 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
351 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
352 |
#$conf["canBeEmptyString"]="false";
|
|
|
353 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
354 |
#$conf["canNotBeEmpty"]=array();
|
|
|
355 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
356 |
#$conf["canBeEmpty"]=array();
|
|
|
357 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
358 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("powerBy","powerByLink","bgColor");
|
|
|
359 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
360 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("name","powerBy","powerByLink","bgColor");
|
|
|
361 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
362 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
|
|
|
363 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
364 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("","QBPWCF","https://www.qbpwcf.org","#DDDDFF");
|
|
|
365 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
366 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
367 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
368 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
369 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
370 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
371 |
#參考資料來源:
|
|
|
372 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
373 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
374 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
375 |
|
| 3 |
liveuser |
376 |
#如果檢查失敗
|
|
|
377 |
if($checkArguments["status"]=="false"){
|
|
|
378 |
|
|
|
379 |
#設置錯誤狀態
|
|
|
380 |
$result["status"]="false";
|
|
|
381 |
|
|
|
382 |
#設置錯誤提示
|
|
|
383 |
$result["error"]=$checkArguments;
|
|
|
384 |
|
|
|
385 |
#回傳結果
|
|
|
386 |
return $result;
|
|
|
387 |
|
|
|
388 |
}#if end
|
|
|
389 |
|
|
|
390 |
#如果檢查不通過
|
|
|
391 |
if($checkArguments["passed"]=="false"){
|
|
|
392 |
|
|
|
393 |
#設置錯誤狀態
|
|
|
394 |
$result["status"]="false";
|
|
|
395 |
|
|
|
396 |
#設置錯誤提示
|
|
|
397 |
$result["error"]=$checkArguments;
|
|
|
398 |
|
|
|
399 |
#回傳結果
|
|
|
400 |
return $result;
|
|
|
401 |
|
|
|
402 |
}#if end
|
| 226 |
liveuser |
403 |
|
| 3 |
liveuser |
404 |
#函式說明:
|
|
|
405 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
406 |
#回傳結果:
|
|
|
407 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
408 |
#$result["error"],錯誤訊息陣列
|
|
|
409 |
#$result["function"],當前執行的函數名稱
|
|
|
410 |
#$result["content"],要執行的javaScript語法
|
|
|
411 |
#必填參數:
|
|
|
412 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
413 |
$conf["javaScript::toScript"]["script"]="
|
| 226 |
liveuser |
414 |
|
|
|
415 |
|
|
|
416 |
|
| 3 |
liveuser |
417 |
var copyRightSpan=document.createElement('span');
|
|
|
418 |
var copyRightText=document.createTextNode('".$conf["name"]."');
|
|
|
419 |
copyRightSpan.appendChild(copyRightText);
|
| 226 |
liveuser |
420 |
|
| 207 |
liveuser |
421 |
//建立power by span
|
| 3 |
liveuser |
422 |
var powerBySpan=document.createElement('span');
|
|
|
423 |
var powerByA=document.createElement('a');
|
|
|
424 |
powerByA.href='".$conf["powerByLink"]."';
|
|
|
425 |
powerByA.target='_blank';
|
|
|
426 |
var powerByText=document.createTextNode('Powered by '+'".$conf["powerBy"]."');
|
|
|
427 |
powerByA.appendChild(powerByText);
|
|
|
428 |
powerBySpan.appendChild(powerByA);
|
| 226 |
liveuser |
429 |
|
| 207 |
liveuser |
430 |
//建立 copy right div
|
|
|
431 |
var copyRightDiv=document.createElement('div');
|
| 3 |
liveuser |
432 |
copyRightDiv.appendChild(copyRightSpan);
|
|
|
433 |
copyRightDiv.appendChild(powerBySpan);
|
|
|
434 |
copyRightDiv.style.backgroundColor='".$conf["bgColor"]."';
|
|
|
435 |
copyRightDiv.style.textAlign='center';
|
| 226 |
liveuser |
436 |
|
| 207 |
liveuser |
437 |
//顯現 copy right
|
| 3 |
liveuser |
438 |
document.body.appendChild(copyRightDiv);
|
| 226 |
liveuser |
439 |
|
| 3 |
liveuser |
440 |
";
|
|
|
441 |
#可省略參數:
|
|
|
442 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
443 |
#$conf["onReady"]="true";
|
|
|
444 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
445 |
#$conf["globalJs"]=array();
|
|
|
446 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
447 |
#$conf["jsFunciton"]=array();
|
|
|
448 |
#參考資料:
|
|
|
449 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
450 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
451 |
unset($conf["javaScript::toScript"]);
|
| 226 |
liveuser |
452 |
|
| 3 |
liveuser |
453 |
#如果建立 javascript 語法失敗
|
| 226 |
liveuser |
454 |
if($toScript["status"]==="false"){
|
|
|
455 |
|
| 3 |
liveuser |
456 |
#設置執行失敗
|
|
|
457 |
$result["status"]="false";
|
| 226 |
liveuser |
458 |
|
| 3 |
liveuser |
459 |
#設置執行錯誤訊息
|
|
|
460 |
$result["error"]=$toScript;
|
|
|
461 |
|
|
|
462 |
#回傳結果
|
| 226 |
liveuser |
463 |
return $result;
|
|
|
464 |
|
| 3 |
liveuser |
465 |
}#if end
|
| 226 |
liveuser |
466 |
|
|
|
467 |
#傳接 content
|
| 3 |
liveuser |
468 |
$result["content"]=$result["content"].$toScript["content"];
|
| 226 |
liveuser |
469 |
|
| 3 |
liveuser |
470 |
#保護版權的語法
|
|
|
471 |
#oncontextmenu,按下滑鼠右鍵
|
|
|
472 |
#onContextMenu,按下滑鼠右鍵
|
|
|
473 |
#ondragstart,開始拖曳
|
|
|
474 |
#onselsect,選取區塊時
|
|
|
475 |
#onselectstart,開始選取區塊
|
|
|
476 |
#onkeydown='if(event.tKey && event.ctrlKey),按下ctrl+t開分頁時
|
|
|
477 |
$result["content"]=$result["content"]."
|
|
|
478 |
<html
|
| 226 |
liveuser |
479 |
oncontextmenu=\"return false\"
|
| 3 |
liveuser |
480 |
onContextMenu=\"window.event.returnValue=false\"
|
|
|
481 |
onselect=\"return false\"
|
| 226 |
liveuser |
482 |
onselectstart=\"return false\"
|
|
|
483 |
ondragstart=\"return false\"
|
| 3 |
liveuser |
484 |
oncopy=\"return false\"
|
|
|
485 |
onbeforeprint=\"return false\"
|
|
|
486 |
>\r\n";
|
| 226 |
liveuser |
487 |
|
| 3 |
liveuser |
488 |
#設置執行正常
|
|
|
489 |
$result["status"]="true";
|
| 226 |
liveuser |
490 |
|
| 3 |
liveuser |
491 |
#回傳語法
|
|
|
492 |
return $result;
|
| 226 |
liveuser |
493 |
|
| 3 |
liveuser |
494 |
}#函式結束
|
|
|
495 |
|
|
|
496 |
/*
|
| 226 |
liveuser |
497 |
#函式說明:
|
| 3 |
liveuser |
498 |
#放置用空白圖片擋住要呈現的圖片
|
|
|
499 |
#回傳結果:
|
|
|
500 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
501 |
#$result["error"],錯誤訊息.
|
|
|
502 |
#$result["function"],當前執行的函數名稱.
|
|
|
503 |
#$result["content"],語法.
|
|
|
504 |
#必填參數:
|
|
|
505 |
$conf["imgAddress"],字串,要放的圖片位置和名稱.
|
|
|
506 |
$conf["imgAddress"]="";
|
|
|
507 |
$conf["imgWidth"],字串,爲圖片的寬.
|
|
|
508 |
$conf["imgWidth"]="";
|
|
|
509 |
$conf["imgHeight"],字串,爲圖片的高.
|
|
|
510 |
$conf["imgHeight"]="";
|
|
|
511 |
$conf["imgLeft"]=,字串,爲圖片放置的位置距離網頁左邊多少.
|
|
|
512 |
$conf["imgLeft"]="";
|
|
|
513 |
$conf["imgTop"]=,字串,爲圖片放置的位置距離網頁頂端多少.
|
|
|
514 |
$conf["imgTop"]="";
|
|
|
515 |
#可省略參數:
|
|
|
516 |
#$conf["useBase64"],字串,是否要用base64的方式呈現圖片,預設為"true"代表要用base64的方式呈現,反之可用"false".
|
|
|
517 |
#$conf["useBase64"]="true";
|
|
|
518 |
#參考資料:
|
|
|
519 |
#無.
|
|
|
520 |
#備註:
|
|
|
521 |
#無.
|
| 226 |
liveuser |
522 |
*/
|
| 3 |
liveuser |
523 |
public static function imgProtect(&$conf){
|
|
|
524 |
|
|
|
525 |
#初始化要回傳的內容
|
|
|
526 |
$result=array();
|
| 226 |
liveuser |
527 |
|
| 3 |
liveuser |
528 |
#取得當前執行的函式
|
|
|
529 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
530 |
|
| 3 |
liveuser |
531 |
#如果 $conf 不為陣列
|
|
|
532 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
533 |
|
| 3 |
liveuser |
534 |
#設置執行失敗
|
|
|
535 |
$result["status"]="false";
|
| 226 |
liveuser |
536 |
|
| 3 |
liveuser |
537 |
#設置執行錯誤訊息
|
|
|
538 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
539 |
|
|
|
540 |
#如果傳入的參數為 null
|
|
|
541 |
if($conf==null){
|
| 226 |
liveuser |
542 |
|
| 3 |
liveuser |
543 |
#設置執行錯誤訊息
|
|
|
544 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
545 |
|
| 3 |
liveuser |
546 |
}#if end
|
|
|
547 |
|
|
|
548 |
#回傳結果
|
|
|
549 |
return $result;
|
| 226 |
liveuser |
550 |
|
| 3 |
liveuser |
551 |
}#if end
|
|
|
552 |
|
|
|
553 |
#初始化程式碼
|
|
|
554 |
$result["content"]="";
|
| 226 |
liveuser |
555 |
|
| 3 |
liveuser |
556 |
#檢查參數
|
|
|
557 |
#函式說明:
|
|
|
558 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
559 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
560 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
561 |
#$result["function"],當前執行的函式名稱.
|
|
|
562 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
563 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
564 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
565 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
566 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
567 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
568 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
569 |
#必填寫的參數:
|
|
|
570 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
571 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
572 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
573 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("imgAddress","imgWidth","imgHeight","imgLeft","imgTop");
|
| 226 |
liveuser |
574 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
575 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string");
|
|
|
576 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
577 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
578 |
#可以省略的參數:
|
|
|
579 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
580 |
#$conf["canBeEmptyString"]="false";
|
|
|
581 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
582 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("useBase64");
|
| 226 |
liveuser |
583 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
584 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
585 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
586 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
|
|
|
587 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
588 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
589 |
#參考資料來源:
|
|
|
590 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
591 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
592 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
593 |
|
| 3 |
liveuser |
594 |
#如果檢查失敗
|
|
|
595 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
596 |
|
| 3 |
liveuser |
597 |
#設置執行失敗
|
|
|
598 |
$result["status"]="false";
|
| 226 |
liveuser |
599 |
|
| 3 |
liveuser |
600 |
#設置執行錯誤訊息
|
|
|
601 |
$result["error"]=$checkArguments;
|
|
|
602 |
|
|
|
603 |
#回傳結果
|
|
|
604 |
return $result;
|
| 226 |
liveuser |
605 |
|
|
|
606 |
}#if end
|
|
|
607 |
|
| 3 |
liveuser |
608 |
#如果檢查不通過
|
|
|
609 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
610 |
|
| 3 |
liveuser |
611 |
#設置執行失敗
|
|
|
612 |
$result["status"]="false";
|
| 226 |
liveuser |
613 |
|
| 3 |
liveuser |
614 |
#設置執行錯誤訊息
|
|
|
615 |
$result["error"]=$checkArguments;
|
|
|
616 |
|
|
|
617 |
#回傳結果
|
|
|
618 |
return $result;
|
| 226 |
liveuser |
619 |
|
| 3 |
liveuser |
620 |
}#if end
|
|
|
621 |
|
|
|
622 |
#建立要放置的圖片樣式
|
| 226 |
liveuser |
623 |
#函式說明:
|
| 3 |
liveuser |
624 |
#創建 css 樣式
|
|
|
625 |
#回傳結果:
|
|
|
626 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
627 |
#$result["css"],css設定內容
|
|
|
628 |
#$result["function"],當前執行的函數
|
| 226 |
liveuser |
629 |
#$result["error"],涵式錯誤訊息,若爲""則表示沒有錯誤
|
| 3 |
liveuser |
630 |
$conf["css"]["createCssStyle"]["cssStyleName"]="imgStyle-".$conf["imgLeft"].$conf["imgTop"];
|
|
|
631 |
$conf["css"]["createCssStyle"]["attributes"]=array("width","height","position","top","left");
|
|
|
632 |
$conf["css"]["createCssStyle"]["content"]=array($conf["imgWidth"],$conf["imgHeight"],"absolute",$conf["imgTop"],$conf["imgLeft"]);
|
|
|
633 |
$css=css::createCssStyle($conf["css"]["createCssStyle"]);
|
|
|
634 |
unset($conf["css"]["createCssStyle"]);#清空變數避免出錯
|
| 226 |
liveuser |
635 |
|
| 3 |
liveuser |
636 |
#如果建立css樣式失敗
|
|
|
637 |
if($css["status"]=="false"){
|
| 226 |
liveuser |
638 |
|
| 3 |
liveuser |
639 |
#設置執行失敗
|
|
|
640 |
$result["status"]="false";
|
| 226 |
liveuser |
641 |
|
| 3 |
liveuser |
642 |
#設置執行錯誤訊息
|
|
|
643 |
$result["error"]=$css;
|
|
|
644 |
|
|
|
645 |
#回傳結果
|
|
|
646 |
return $result;
|
| 226 |
liveuser |
647 |
|
| 3 |
liveuser |
648 |
}#if end
|
| 226 |
liveuser |
649 |
|
| 3 |
liveuser |
650 |
#串接css語法
|
|
|
651 |
$result["content"]=$result["content"].$css["css"];
|
|
|
652 |
|
|
|
653 |
#如果要用base64顯示圖片
|
|
|
654 |
if($conf["useBase64"]=="true"){
|
| 226 |
liveuser |
655 |
|
| 3 |
liveuser |
656 |
#將圖片用base64加密呈現
|
|
|
657 |
#函數說明:
|
|
|
658 |
#用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面,本函式包含顯示圖片的語法.
|
|
|
659 |
#回傳結果:
|
|
|
660 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
661 |
#$result["error"],錯誤訊息
|
|
|
662 |
#$result["content"],圖片的連結資訊
|
| 226 |
liveuser |
663 |
#$result["function"],當前執行的函數名稱
|
| 3 |
liveuser |
664 |
#必填參數:
|
|
|
665 |
#$conf["img::data"]["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
|
|
|
666 |
$conf["img::data"]["imgPosition"]=$conf["imgAddress"];
|
|
|
667 |
#可省略參數:
|
|
|
668 |
#$conf["img::data"]["alt"],若沒有圖片要用什麼文字顯示。
|
|
|
669 |
$conf["img::data"]["alt"]="not found";
|
|
|
670 |
#$conf["img::data"]["class"],圖片要套用的css樣式名稱.
|
|
|
671 |
$conf["img::data"]["class"]="imgStyle-".$conf["imgLeft"].$conf["imgTop"];
|
|
|
672 |
#$conf["mimeType"],2元碼的內容是什麼,預設為"image/*".
|
|
|
673 |
#$conf["mimeType"]="image/*";
|
|
|
674 |
#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
|
|
|
675 |
#$conf["compressType"]="base64";
|
|
|
676 |
#$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
|
|
|
677 |
#$conf["delImg"]="false";
|
|
|
678 |
#參考資料:
|
|
|
679 |
#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
|
|
|
680 |
#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
|
|
|
681 |
$data=img::data($conf["img::data"]);
|
|
|
682 |
unset($conf["img::data"]);
|
|
|
683 |
|
|
|
684 |
#將圖片用base64加密呈現失敗
|
|
|
685 |
if($data["status"]=="false"){
|
| 226 |
liveuser |
686 |
|
| 3 |
liveuser |
687 |
#設置執行失敗
|
|
|
688 |
$result["status"]="false";
|
| 226 |
liveuser |
689 |
|
| 3 |
liveuser |
690 |
#設置執行錯誤訊息
|
|
|
691 |
$result["error"]=$data;
|
|
|
692 |
|
|
|
693 |
#回傳結果
|
|
|
694 |
return $result;
|
| 226 |
liveuser |
695 |
|
| 3 |
liveuser |
696 |
}#if end
|
| 226 |
liveuser |
697 |
|
| 3 |
liveuser |
698 |
#取得用base64放置圖片的語法
|
|
|
699 |
$result["content"]=$result["content"].$data["content"];
|
| 226 |
liveuser |
700 |
|
| 3 |
liveuser |
701 |
}#if end
|
|
|
702 |
|
|
|
703 |
#反之為一般放置圖片的方式
|
|
|
704 |
else{
|
| 226 |
liveuser |
705 |
|
| 3 |
liveuser |
706 |
#放置要放的圖片
|
|
|
707 |
#函式說明:
|
|
|
708 |
#放置可以套用css樣式的圖片
|
|
|
709 |
#回傳結果:
|
|
|
710 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
711 |
#$result["error"],錯誤訊息陣列
|
|
|
712 |
#$result["function"],當前函數執行的名稱
|
| 226 |
liveuser |
713 |
#$result["content"],印出圖片的語法。
|
| 3 |
liveuser |
714 |
$conf["img"]["show"]["position"]=$conf["imgAddress"];
|
|
|
715 |
$conf["img"]["show"]["alt"]="not found";
|
|
|
716 |
$conf["img"]["show"]["class"]="imgStyle-".$conf["imgLeft"].$conf["imgTop"];
|
|
|
717 |
$show=img::show($conf["img"]["show"]);
|
|
|
718 |
unset($conf["img"]["show"]);#清空變數避免出錯
|
|
|
719 |
|
|
|
720 |
#如果放置圖片的語法建立失敗
|
|
|
721 |
if($show["status"]=="false"){
|
| 226 |
liveuser |
722 |
|
| 3 |
liveuser |
723 |
#設置執行失敗
|
|
|
724 |
$result["status"]="false";
|
| 226 |
liveuser |
725 |
|
| 3 |
liveuser |
726 |
#設置執行錯誤訊息
|
|
|
727 |
$result["error"]=$show;
|
|
|
728 |
|
|
|
729 |
#回傳結果
|
|
|
730 |
return $result;
|
| 226 |
liveuser |
731 |
|
| 3 |
liveuser |
732 |
}#if end
|
| 226 |
liveuser |
733 |
|
| 3 |
liveuser |
734 |
#串接顯示圖片的語法
|
|
|
735 |
$result["content"]=$result["content"].$show["content"];
|
| 226 |
liveuser |
736 |
|
| 3 |
liveuser |
737 |
}#else end
|
|
|
738 |
|
|
|
739 |
#建立圖片隔離層樣式
|
|
|
740 |
$conf["css"]["createCssStyle"]["cssStyleName"]="imgIsolationLayerStyle".$conf["imgLeft"].$conf["imgTop"];
|
|
|
741 |
$conf["css"]["createCssStyle"]["attributes"]=array("width","height","opacity","position","top","left");
|
|
|
742 |
$conf["css"]["createCssStyle"]["content"]=array($conf["imgWidth"],$conf["imgHeight"],".0","absolute",$conf["imgTop"],$conf["imgLeft"]);
|
|
|
743 |
$css=css::createCssStyle($conf["css"]["createCssStyle"]);
|
|
|
744 |
unset($conf["css"]["createCssStyle"]);#清空變數避免出錯
|
| 226 |
liveuser |
745 |
|
| 3 |
liveuser |
746 |
#如果建立css樣式失敗
|
|
|
747 |
if($css["status"]=="false"){
|
| 226 |
liveuser |
748 |
|
| 3 |
liveuser |
749 |
#設置執行失敗
|
|
|
750 |
$result["status"]="false";
|
| 226 |
liveuser |
751 |
|
| 3 |
liveuser |
752 |
#設置執行錯誤訊息
|
|
|
753 |
$result["error"]=$css;
|
|
|
754 |
|
|
|
755 |
#回傳結果
|
|
|
756 |
return $result;
|
| 226 |
liveuser |
757 |
|
| 3 |
liveuser |
758 |
}#if end
|
| 226 |
liveuser |
759 |
|
| 3 |
liveuser |
760 |
#取得圖片隔離層樣式程式碼
|
|
|
761 |
$result["content"]=$result["content"].$css["css"];
|
|
|
762 |
|
|
|
763 |
#放置隔離層
|
|
|
764 |
#函式說明:
|
|
|
765 |
#放置可以套用css樣式的圖片
|
|
|
766 |
#回傳結果:
|
|
|
767 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
768 |
#$result["error"],錯誤訊息陣列
|
|
|
769 |
#$result["function"],當前函數執行的名稱
|
| 226 |
liveuser |
770 |
#$result["content"],印出圖片的語法。
|
| 3 |
liveuser |
771 |
#必填參數:
|
|
|
772 |
$conf["img"]["show"]["position"]="copyRight.png";#圖片位置
|
|
|
773 |
#可省略參數:
|
|
|
774 |
#$conf["img"]["show"]["alt"]="not found";#若沒有圖片要用什麼文字顯示。
|
|
|
775 |
$conf["img"]["show"]["class"]="imgIsolationLayerStyle".$conf["imgLeft"].$conf["imgTop"];#要套用的css樣式類別名稱。
|
|
|
776 |
$show=img::show($conf["img"]["show"]);
|
|
|
777 |
unset($conf["img"]["show"]);
|
| 226 |
liveuser |
778 |
|
| 3 |
liveuser |
779 |
#如果放置圖片的語法建立失敗
|
|
|
780 |
if($show["status"]=="false"){
|
| 226 |
liveuser |
781 |
|
| 3 |
liveuser |
782 |
#設置執行失敗
|
|
|
783 |
$result["status"]="false";
|
| 226 |
liveuser |
784 |
|
| 3 |
liveuser |
785 |
#設置執行錯誤訊息
|
|
|
786 |
$result["error"]=$show;
|
|
|
787 |
|
|
|
788 |
#回傳結果
|
|
|
789 |
return $result;
|
| 226 |
liveuser |
790 |
|
| 3 |
liveuser |
791 |
}#if end
|
| 226 |
liveuser |
792 |
|
| 3 |
liveuser |
793 |
#串接顯示隔離層圖片的語法
|
|
|
794 |
$result["content"]=$result["content"].$show["content"];
|
|
|
795 |
|
|
|
796 |
#執行到這邊代表執行成功
|
|
|
797 |
$result["status"]="true";
|
| 226 |
liveuser |
798 |
|
| 3 |
liveuser |
799 |
#回傳語法
|
|
|
800 |
return $result;
|
|
|
801 |
|
|
|
802 |
}#function imgProtect end
|
|
|
803 |
|
|
|
804 |
/*
|
|
|
805 |
#函式說明:
|
|
|
806 |
#加密php檔案的內容將結果輸出.
|
|
|
807 |
#回傳結果:
|
|
|
808 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
809 |
#$result["error"],錯誤訊息陣列.
|
|
|
810 |
#$result["function"],當前執行的函式名稱.
|
|
|
811 |
#$result["content"],加密好的php內容字串.
|
|
|
812 |
#必填參數:
|
|
|
813 |
#$conf["phpFile"],字串,要加密的php檔案位置與名稱.
|
|
|
814 |
$conf["phpFile"]="";
|
|
|
815 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
816 |
$conf["fileArgu"]=__FILE__;
|
|
|
817 |
#可省略參數:
|
|
|
818 |
#無.
|
|
|
819 |
#參考資料:
|
|
|
820 |
#無.
|
|
|
821 |
#備註:
|
|
|
822 |
#僅支援單行只出現<?php、?>、其他內容的PHP檔案格式內容.
|
|
|
823 |
*/
|
|
|
824 |
public static function encodePHP(&$conf){
|
| 226 |
liveuser |
825 |
|
| 3 |
liveuser |
826 |
#初始化要回傳的內容
|
|
|
827 |
$result=array();
|
| 226 |
liveuser |
828 |
|
| 3 |
liveuser |
829 |
#取得當前執行的函式
|
|
|
830 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
831 |
|
| 3 |
liveuser |
832 |
#如果 $conf 不為陣列
|
|
|
833 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
834 |
|
| 3 |
liveuser |
835 |
#設置執行失敗
|
|
|
836 |
$result["status"]="false";
|
| 226 |
liveuser |
837 |
|
| 3 |
liveuser |
838 |
#設置執行錯誤訊息
|
|
|
839 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
840 |
|
|
|
841 |
#如果傳入的參數為 null
|
|
|
842 |
if($conf==null){
|
| 226 |
liveuser |
843 |
|
| 3 |
liveuser |
844 |
#設置執行錯誤訊息
|
|
|
845 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
846 |
|
| 3 |
liveuser |
847 |
}#if end
|
|
|
848 |
|
|
|
849 |
#回傳結果
|
|
|
850 |
return $result;
|
| 226 |
liveuser |
851 |
|
| 3 |
liveuser |
852 |
}#if end
|
|
|
853 |
|
|
|
854 |
#初始加密好的php程式內容
|
|
|
855 |
$result["content"]="";
|
| 226 |
liveuser |
856 |
|
| 3 |
liveuser |
857 |
#檢查參數
|
|
|
858 |
#函式說明:
|
|
|
859 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
860 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
861 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
862 |
#$result["function"],當前執行的函式名稱.
|
|
|
863 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
864 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
865 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
866 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
867 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
868 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
869 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
870 |
#必填寫的參數:
|
|
|
871 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
872 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
873 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
874 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("phpFile","fileArgu");
|
| 226 |
liveuser |
875 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
876 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
877 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
878 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
879 |
#可以省略的參數:
|
|
|
880 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
881 |
#$conf["canBeEmptyString"]="false";
|
|
|
882 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
883 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("useBase64");
|
| 226 |
liveuser |
884 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
885 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
886 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
887 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
|
|
|
888 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
889 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
890 |
#參考資料來源:
|
|
|
891 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
892 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
893 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
894 |
|
| 3 |
liveuser |
895 |
#如果檢查失敗
|
|
|
896 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
897 |
|
| 3 |
liveuser |
898 |
#設置執行失敗
|
|
|
899 |
$result["status"]="false";
|
| 226 |
liveuser |
900 |
|
| 3 |
liveuser |
901 |
#設置執行錯誤訊息
|
|
|
902 |
$result["error"]=$checkArguments;
|
|
|
903 |
|
|
|
904 |
#回傳結果
|
|
|
905 |
return $result;
|
| 226 |
liveuser |
906 |
|
|
|
907 |
}#if end
|
|
|
908 |
|
| 3 |
liveuser |
909 |
#如果檢查不通過
|
|
|
910 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
911 |
|
| 3 |
liveuser |
912 |
#設置執行失敗
|
|
|
913 |
$result["status"]="false";
|
| 226 |
liveuser |
914 |
|
| 3 |
liveuser |
915 |
#設置執行錯誤訊息
|
|
|
916 |
$result["error"]=$checkArguments;
|
|
|
917 |
|
|
|
918 |
#回傳結果
|
|
|
919 |
return $result;
|
| 226 |
liveuser |
920 |
|
| 3 |
liveuser |
921 |
}#if end
|
| 226 |
liveuser |
922 |
|
| 3 |
liveuser |
923 |
#函式說明:
|
|
|
924 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
925 |
#回傳的變數說明:
|
|
|
926 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
927 |
#$result["error"],錯誤訊息提示.
|
|
|
928 |
#$result["warning"],警告訊息.
|
|
|
929 |
#$result["function"],當前執行的函數名稱.
|
|
|
930 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
931 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
932 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
933 |
#$result["base64data"],為檔案的base64內容.
|
|
|
934 |
#$result["mimeType"],為檔案的mime type.
|
|
|
935 |
#必填參數:
|
|
|
936 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
937 |
$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["phpFile"];
|
|
|
938 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
939 |
$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
940 |
#可省略參數:
|
|
|
941 |
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
|
|
|
942 |
$conf["fileAccess::getFileContent"]["web"]="false";
|
|
|
943 |
#參考資料:
|
|
|
944 |
#file(),取得檔案內容的行數.
|
|
|
945 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
946 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
947 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
948 |
$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
|
|
|
949 |
unset($conf["fileAccess::getFileContent"]);
|
| 226 |
liveuser |
950 |
|
| 3 |
liveuser |
951 |
#如果讀取檔案內容失敗
|
|
|
952 |
if($getFileContent["status"]==="false"){
|
| 226 |
liveuser |
953 |
|
| 3 |
liveuser |
954 |
#設置執行失敗
|
|
|
955 |
$result["status"]="false";
|
| 226 |
liveuser |
956 |
|
| 3 |
liveuser |
957 |
#設置執行錯誤訊息
|
|
|
958 |
$result["error"]=$getFileContent;
|
|
|
959 |
|
|
|
960 |
#回傳結果
|
|
|
961 |
return $result;
|
| 226 |
liveuser |
962 |
|
| 3 |
liveuser |
963 |
}#if end
|
| 226 |
liveuser |
964 |
|
| 3 |
liveuser |
965 |
#加密過後的php內容
|
|
|
966 |
$contentWithoutPhpTagArray=array();
|
| 226 |
liveuser |
967 |
|
| 3 |
liveuser |
968 |
#識別是否開始php語法了.
|
|
|
969 |
$isPHP=false;
|
| 226 |
liveuser |
970 |
|
| 3 |
liveuser |
971 |
#識別是否讀取到php tag開頭
|
|
|
972 |
$phpStart=false;
|
| 226 |
liveuser |
973 |
|
| 3 |
liveuser |
974 |
#識別是否讀取到php tag結尾
|
|
|
975 |
$phpEed=true;
|
| 226 |
liveuser |
976 |
|
| 3 |
liveuser |
977 |
#針對每行內容
|
|
|
978 |
foreach($getFileContent["fileContent"] as $index=>$line){
|
| 226 |
liveuser |
979 |
|
| 3 |
liveuser |
980 |
#debug
|
|
|
981 |
#echo "處理第".($index+1)."行".PHP_EOL;
|
| 226 |
liveuser |
982 |
|
| 3 |
liveuser |
983 |
#函式說明:
|
|
|
984 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
985 |
#回傳結果:
|
|
|
986 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
987 |
#$result["error"],錯誤訊息陣列
|
|
|
988 |
#$result["function"],當前執行的函數名稱.
|
|
|
989 |
#$result["argu"],使用的參數.
|
|
|
990 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
991 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
992 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
993 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
994 |
#必填的參數:
|
|
|
995 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
996 |
$conf["stringProcess::spiltString"]["stringIn"]=$line;
|
|
|
997 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
998 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="<?php";
|
|
|
999 |
#可省略參數:
|
|
|
1000 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
1001 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
1002 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
1003 |
unset($conf["stringProcess::spiltString"]);
|
|
|
1004 |
|
|
|
1005 |
#如果執行失敗
|
|
|
1006 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
1007 |
|
| 3 |
liveuser |
1008 |
#設置執行失敗
|
|
|
1009 |
$result["status"]="false";
|
| 226 |
liveuser |
1010 |
|
| 3 |
liveuser |
1011 |
#設置執行錯誤訊息
|
|
|
1012 |
$result["error"]=$spiltString;
|
|
|
1013 |
|
|
|
1014 |
#回傳結果
|
|
|
1015 |
return $result;
|
| 226 |
liveuser |
1016 |
|
| 3 |
liveuser |
1017 |
}#if end
|
| 226 |
liveuser |
1018 |
|
| 3 |
liveuser |
1019 |
#初始化該行的資訊描述
|
|
|
1020 |
$lineInfo=array();
|
| 226 |
liveuser |
1021 |
|
| 3 |
liveuser |
1022 |
#如果沒有關鍵字
|
|
|
1023 |
if($spiltString["found"]==="false" && $isPHP===false){
|
| 226 |
liveuser |
1024 |
|
| 3 |
liveuser |
1025 |
#初始化暫存的資訊
|
|
|
1026 |
$tempLineInfo=array();
|
| 226 |
liveuser |
1027 |
|
| 3 |
liveuser |
1028 |
#預設該行不是php的內容
|
|
|
1029 |
$tempLineInfo["isPHP"]=false;
|
| 226 |
liveuser |
1030 |
|
| 3 |
liveuser |
1031 |
#放置內容
|
|
|
1032 |
$tempLineInfo["content"]=$line;
|
| 226 |
liveuser |
1033 |
|
| 3 |
liveuser |
1034 |
#儲存一行資訊描述
|
|
|
1035 |
$lineInfo[]=$tempLineInfo;
|
| 226 |
liveuser |
1036 |
|
| 3 |
liveuser |
1037 |
}#if end
|
|
|
1038 |
|
|
|
1039 |
#反之有關鍵字且 現在是屬於 php 的範圍
|
|
|
1040 |
else if($spiltString["found"]==="false" && $isPHP===true){
|
| 226 |
liveuser |
1041 |
|
| 3 |
liveuser |
1042 |
#確認該段目前沒有 "?".">" 結尾
|
| 226 |
liveuser |
1043 |
|
| 3 |
liveuser |
1044 |
#函式說明:
|
|
|
1045 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
1046 |
#回傳結果:
|
|
|
1047 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1048 |
#$result["error"],錯誤訊息陣列
|
|
|
1049 |
#$result["function"],當前執行的函數名稱.
|
|
|
1050 |
#$result["argu"],使用的參數.
|
|
|
1051 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
1052 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
1053 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
1054 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
1055 |
#必填的參數:
|
|
|
1056 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
1057 |
$conf["stringProcess::spiltString"]["stringIn"]=$line;
|
|
|
1058 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
1059 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="?>";
|
|
|
1060 |
#可省略參數:
|
|
|
1061 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
1062 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
1063 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
1064 |
unset($conf["stringProcess::spiltString"]);
|
|
|
1065 |
|
|
|
1066 |
#如果執行失敗
|
|
|
1067 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
1068 |
|
| 3 |
liveuser |
1069 |
#設置執行失敗
|
|
|
1070 |
$result["status"]="false";
|
| 226 |
liveuser |
1071 |
|
| 3 |
liveuser |
1072 |
#設置執行錯誤訊息
|
|
|
1073 |
$result["error"]=$spiltString;
|
|
|
1074 |
|
|
|
1075 |
#回傳結果
|
|
|
1076 |
return $result;
|
| 226 |
liveuser |
1077 |
|
| 3 |
liveuser |
1078 |
}#if end
|
| 226 |
liveuser |
1079 |
|
| 3 |
liveuser |
1080 |
#反之有關鍵字且 現在是屬於 php 的範圍
|
|
|
1081 |
if($spiltString["found"]==="false" && $isPHP===true){
|
| 226 |
liveuser |
1082 |
|
| 3 |
liveuser |
1083 |
#初始化暫存的資訊
|
|
|
1084 |
$tempLineInfo=array();
|
| 226 |
liveuser |
1085 |
|
| 3 |
liveuser |
1086 |
#預設該行不是php的內容
|
|
|
1087 |
$tempLineInfo["isPHP"]=true;
|
| 226 |
liveuser |
1088 |
|
| 3 |
liveuser |
1089 |
#放置內容
|
|
|
1090 |
$tempLineInfo["content"]=$line;
|
| 226 |
liveuser |
1091 |
|
| 3 |
liveuser |
1092 |
#儲存一行資訊描述
|
|
|
1093 |
$lineInfo[]=$tempLineInfo;
|
| 226 |
liveuser |
1094 |
|
| 3 |
liveuser |
1095 |
}#if end
|
| 226 |
liveuser |
1096 |
|
| 3 |
liveuser |
1097 |
#反之有找到關鍵字,且現在屬於 php 的範圍
|
|
|
1098 |
else if($spiltString["found"]==="true" && $isPHP===true){
|
|
|
1099 |
|
|
|
1100 |
#如果分割成0段
|
|
|
1101 |
if($spiltString["dataCounts"]===0){
|
| 226 |
liveuser |
1102 |
|
| 3 |
liveuser |
1103 |
#識別是否開始php語法了.
|
|
|
1104 |
$isPHP=false;
|
| 226 |
liveuser |
1105 |
|
| 3 |
liveuser |
1106 |
#識別是否讀取到php tag開頭
|
|
|
1107 |
$phpStart=false;
|
| 226 |
liveuser |
1108 |
|
| 3 |
liveuser |
1109 |
#識別是否讀取到php tag結尾
|
|
|
1110 |
$phpEed=true;
|
| 226 |
liveuser |
1111 |
|
| 3 |
liveuser |
1112 |
}#if end
|
| 226 |
liveuser |
1113 |
|
| 3 |
liveuser |
1114 |
#如果分割成其他段落
|
|
|
1115 |
else{
|
| 226 |
liveuser |
1116 |
|
| 3 |
liveuser |
1117 |
#設置執行錯誤訊息
|
|
|
1118 |
$result["error"][]="not supported now";
|
| 226 |
liveuser |
1119 |
|
| 3 |
liveuser |
1120 |
}#else end
|
| 226 |
liveuser |
1121 |
|
| 3 |
liveuser |
1122 |
}#if end
|
| 226 |
liveuser |
1123 |
|
| 3 |
liveuser |
1124 |
}#if end
|
|
|
1125 |
|
|
|
1126 |
#反之有關鍵字
|
|
|
1127 |
else if($spiltString["found"]==="true"){
|
| 226 |
liveuser |
1128 |
|
| 3 |
liveuser |
1129 |
#識別是否開始php語法了.
|
|
|
1130 |
$isPHP=true;
|
| 226 |
liveuser |
1131 |
|
| 3 |
liveuser |
1132 |
#識別是否讀取到php tag開頭
|
|
|
1133 |
$phpStart=true;
|
| 226 |
liveuser |
1134 |
|
| 3 |
liveuser |
1135 |
#識別是否讀取到php tag結尾
|
|
|
1136 |
$phpEed=false;
|
| 226 |
liveuser |
1137 |
|
| 3 |
liveuser |
1138 |
#如果切成兩段
|
|
|
1139 |
if($spiltString["dataCounts"]===2){
|
| 226 |
liveuser |
1140 |
|
| 3 |
liveuser |
1141 |
#儲存非 php 的字串
|
|
|
1142 |
$noPHPstr=$spiltString["dataArray"][0];
|
| 226 |
liveuser |
1143 |
|
| 3 |
liveuser |
1144 |
#初始化暫存的資訊
|
|
|
1145 |
$tempLineInfo=array();
|
| 226 |
liveuser |
1146 |
|
| 3 |
liveuser |
1147 |
#預設該行不是php的內容
|
|
|
1148 |
$tempLineInfo["isPHP"]=false;
|
| 226 |
liveuser |
1149 |
|
| 3 |
liveuser |
1150 |
#放置內容
|
|
|
1151 |
$tempLineInfo["content"]=$noPHPstr;
|
| 226 |
liveuser |
1152 |
|
| 3 |
liveuser |
1153 |
#儲存屬於 php 的字串
|
|
|
1154 |
$phpStr=$spiltString["dataArray"][1];
|
| 226 |
liveuser |
1155 |
|
| 3 |
liveuser |
1156 |
#初始化暫存的資訊
|
|
|
1157 |
$tempLineInfo=array();
|
| 226 |
liveuser |
1158 |
|
| 3 |
liveuser |
1159 |
#預設該行不是php的內容
|
|
|
1160 |
$tempLineInfo["isPHP"]=true;
|
| 226 |
liveuser |
1161 |
|
| 3 |
liveuser |
1162 |
#放置內容
|
|
|
1163 |
$tempLineInfo["content"]=$noPHPstr;
|
| 226 |
liveuser |
1164 |
|
| 3 |
liveuser |
1165 |
}#if end
|
| 226 |
liveuser |
1166 |
|
| 3 |
liveuser |
1167 |
#反之切成一段
|
|
|
1168 |
else if($spiltString["dataCounts"]===1){
|
| 226 |
liveuser |
1169 |
|
| 3 |
liveuser |
1170 |
#設置執行失敗
|
|
|
1171 |
$result["status"]="false";
|
| 226 |
liveuser |
1172 |
|
| 3 |
liveuser |
1173 |
#設置執行錯誤訊息
|
|
|
1174 |
$result["error"][]="not supported now";
|
|
|
1175 |
|
|
|
1176 |
#回傳結果
|
|
|
1177 |
return $result;
|
| 226 |
liveuser |
1178 |
|
| 3 |
liveuser |
1179 |
}#else end
|
| 226 |
liveuser |
1180 |
|
| 3 |
liveuser |
1181 |
#反之切成0段
|
|
|
1182 |
else if($spiltString["dataCounts"]===0){
|
| 226 |
liveuser |
1183 |
|
| 3 |
liveuser |
1184 |
#do nothing
|
| 226 |
liveuser |
1185 |
|
| 3 |
liveuser |
1186 |
}#else end
|
| 226 |
liveuser |
1187 |
|
| 3 |
liveuser |
1188 |
#反之
|
|
|
1189 |
else{
|
|
|
1190 |
#設置執行失敗
|
|
|
1191 |
$result["status"]="false";
|
| 226 |
liveuser |
1192 |
|
| 3 |
liveuser |
1193 |
#設置執行錯誤訊息
|
|
|
1194 |
$result["error"][]="not supported now";
|
|
|
1195 |
|
|
|
1196 |
#回傳結果
|
|
|
1197 |
return $result;
|
| 226 |
liveuser |
1198 |
|
| 3 |
liveuser |
1199 |
}#else end
|
| 226 |
liveuser |
1200 |
|
| 3 |
liveuser |
1201 |
}#else end
|
|
|
1202 |
|
|
|
1203 |
#真對每個字串
|
|
|
1204 |
foreach($lineInfo as $linfo){
|
| 226 |
liveuser |
1205 |
|
|
|
1206 |
#記錄起來
|
| 3 |
liveuser |
1207 |
$contentWithoutPhpTagArray[]=$linfo;
|
| 226 |
liveuser |
1208 |
|
| 3 |
liveuser |
1209 |
}#foreach end
|
| 226 |
liveuser |
1210 |
|
| 3 |
liveuser |
1211 |
}#foreach end
|
| 226 |
liveuser |
1212 |
|
| 3 |
liveuser |
1213 |
#debug
|
|
|
1214 |
#var_dump($contentWithoutPhpTagArray);
|
| 226 |
liveuser |
1215 |
|
| 3 |
liveuser |
1216 |
#儲存每行的檔案內容
|
|
|
1217 |
$res=array();
|
| 226 |
liveuser |
1218 |
|
| 3 |
liveuser |
1219 |
#php段落
|
|
|
1220 |
$phpSection="";
|
| 226 |
liveuser |
1221 |
|
| 3 |
liveuser |
1222 |
#針對每行程式
|
|
|
1223 |
foreach($contentWithoutPhpTagArray as $lineInfo){
|
| 226 |
liveuser |
1224 |
|
| 3 |
liveuser |
1225 |
#如果不是 php
|
|
|
1226 |
if($lineInfo["isPHP"]===false){
|
| 226 |
liveuser |
1227 |
|
| 3 |
liveuser |
1228 |
#如果有php段落
|
|
|
1229 |
if(!empty($phpSection)){
|
| 226 |
liveuser |
1230 |
|
|
|
1231 |
#加密php程式
|
| 3 |
liveuser |
1232 |
$encodedPHP=base64_encode($phpSection);
|
| 226 |
liveuser |
1233 |
|
| 3 |
liveuser |
1234 |
#串接內容
|
|
|
1235 |
$res[]="<?php eval(base64_decode(\"".$encodedPHP."\")); ?>";
|
| 226 |
liveuser |
1236 |
|
| 3 |
liveuser |
1237 |
}#if end
|
| 226 |
liveuser |
1238 |
|
| 3 |
liveuser |
1239 |
#清空php段落
|
|
|
1240 |
$phpSection="";
|
| 226 |
liveuser |
1241 |
|
| 3 |
liveuser |
1242 |
#串接內容
|
|
|
1243 |
$res[]=$lineInfo["content"].PHP_EOL;
|
| 226 |
liveuser |
1244 |
|
| 3 |
liveuser |
1245 |
}#if end
|
| 226 |
liveuser |
1246 |
|
| 3 |
liveuser |
1247 |
#反之是 PHP 內容
|
|
|
1248 |
else{
|
|
|
1249 |
#有內容才處理
|
|
|
1250 |
if(!empty($lineInfo["content"])){
|
| 226 |
liveuser |
1251 |
|
| 3 |
liveuser |
1252 |
#串接php語法
|
|
|
1253 |
$phpSection=$phpSection.$lineInfo["content"].PHP_EOL;
|
| 226 |
liveuser |
1254 |
|
| 3 |
liveuser |
1255 |
}#if end
|
| 226 |
liveuser |
1256 |
|
| 3 |
liveuser |
1257 |
}#else end
|
| 226 |
liveuser |
1258 |
|
| 3 |
liveuser |
1259 |
}#foreach end
|
| 226 |
liveuser |
1260 |
|
| 3 |
liveuser |
1261 |
#如果有php段落
|
|
|
1262 |
if(!empty($phpSection)){
|
| 226 |
liveuser |
1263 |
|
|
|
1264 |
#加密php程式
|
| 3 |
liveuser |
1265 |
$encodedPHP=base64_encode($phpSection);
|
| 226 |
liveuser |
1266 |
|
| 3 |
liveuser |
1267 |
#串接內容
|
|
|
1268 |
$res[]="<?php eval(base64_decode(\"".$encodedPHP."\")); ?>";
|
| 226 |
liveuser |
1269 |
|
| 3 |
liveuser |
1270 |
}#if end
|
| 226 |
liveuser |
1271 |
|
| 3 |
liveuser |
1272 |
#var_dump($res);exit;
|
| 226 |
liveuser |
1273 |
|
| 3 |
liveuser |
1274 |
#針對每個要寫入的行內容
|
|
|
1275 |
foreach($res as $line){
|
| 226 |
liveuser |
1276 |
|
| 3 |
liveuser |
1277 |
$result["content"]=$result["content"].$line;
|
| 226 |
liveuser |
1278 |
|
| 3 |
liveuser |
1279 |
}#foreach end
|
| 226 |
liveuser |
1280 |
|
| 3 |
liveuser |
1281 |
#設置執行正常
|
|
|
1282 |
$result["status"]="true";
|
| 226 |
liveuser |
1283 |
|
| 3 |
liveuser |
1284 |
#回傳結果
|
|
|
1285 |
return $result;
|
| 226 |
liveuser |
1286 |
|
| 3 |
liveuser |
1287 |
}#function encodePHP end
|
|
|
1288 |
|
|
|
1289 |
}#class security end
|
|
|
1290 |
|
|
|
1291 |
?>
|