forked from Code4SierraLeone/MembaO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_filter.php
529 lines (476 loc) · 15.2 KB
/
class_filter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
<?php
/**
* Filter Class
*
* @package Membao
* @author Alan Kawamara
* @copyright 2017
*/
if (!defined("_VALID_PHP"))
die('Direct access to this location is not allowed.');
final class Filter
{
public static $id = null;
public static $get = array();
public static $post = array();
public static $cookie = array();
public static $files = array();
public static $server = array();
private static $marker = array();
public static $msgs = array();
public static $showMsg;
public static $action = null;
public static $do = null;
/**
* Filter::__construct()
*
* @return
*/
public function __construct()
{
$_GET = self::clean($_GET);
$_POST = self::clean($_POST);
$_COOKIE = self::clean($_COOKIE);
$_FILES = self::clean($_FILES);
$_SERVER = self::clean($_SERVER);
self::$get = $_GET;
self::$post = $_POST;
self::$cookie = $_COOKIE;
self::$files = $_FILES;
self::$server = $_SERVER;
self::getAction();
self::getDo();
self::$id = self::getId();
}
/**
* Filter::getId()
*
* @return
*/
private static function getId()
{
if (isset($_REQUEST['id'])) {
self::$id = (is_numeric($_REQUEST['id']) && $_REQUEST['id'] > -1) ? intval($_REQUEST['id']) : false;
self::$id = sanitize(self::$id);
if (self::$id == false) {
DEBUG == true ? self::error("You have selected an Invalid Id", "Filter::getId()") : self::ooops();
} else
return self::$id;
}
}
/**
* Filter::clean()
*
* @param mixed $data
* @return
*/
public static function clean($data)
{
if (is_array($data)) {
foreach ($data as $key => $value) {
unset($data[$key]);
$data[self::clean($key)] = self::clean($value);
}
} else {
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
} else {
$data = htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
}
}
return $data;
}
/**
* Filter::msgAlert()
*
* @param mixed $msg
* @param bool $fader
* @param bool $print
* @param bool $altholder
* @return
*/
public static function msgAlert($msg, $print = true, $fader = false, $altholder = false)
{
self::$showMsg = "<div class=\"corporato icon message warning\"><i class=\"exclamation icon\"></i><i class=\"close icon\"></i><div class=\"content\"><div class=\"header\"> " . Lang::$word->ALERT . "</div><p>" . $msg . "</p></div></div>";
if ($fader == true)
self::$showMsg .= "<script type=\"text/javascript\">
// <![CDATA[
setTimeout(function() {
$(\".msgAlert\").fadeOut(\"slow\",
function() {
$(\".msgAlert\").remove();
});
},
4000);
// ]]>
</script>";
if ($print == true) {
print ($altholder) ? '<div id="alt-msgholder">' . self::$showMsg . '</div>' : self::$showMsg;
} else {
return ($altholder) ? '<div id="alt-msgholder">' . self::$showMsg . '</div>' : self::$showMsg;
}
}
/**
* Filter::msgSingleAlert()
*
* @param mixed $msg
* @param bool $print
* @return
*/
public static function msgSingleAlert($msg, $print = true)
{
self::$showMsg = "<div class=\"corporato warning message\"><i class=\"attention icon\"></i> " . $msg . "</div>";
if ($print == true) {
print self::$showMsg;
} else {
return self::$showMsg;
}
}
/**
* Filter::msgOk()
*
* @param mixed $msg
* @param bool $fader
* @param bool $print
* @param bool $altholder
* @return
*/
public static function msgOk($msg, $print = true, $fader = false, $altholder = false)
{
self::$showMsg = "<div class=\"corporato icon message success\"><i class=\"checked icon\"></i><i class=\"close icon\"></i><div class=\"content\"><div class=\"header\"> " . Lang::$word->SUCCESS . "</div><p>" . $msg .
"</p></div></div>";
if ($fader == true)
self::$showMsg .= "<script type=\"text/javascript\">
// <![CDATA[
setTimeout(function() {
$(\".msgOk\").fadeOut(\"slow\",
function() {
$(\".msgOk\").remove();
});
},
4000);
// ]]>
</script>";
if ($print == true) {
print ($altholder) ? '<div id="alt-msgholder">' . self::$showMsg . '</div>' : self::$showMsg;
} else {
return ($altholder) ? '<div id="alt-msgholder">' . self::$showMsg . '</div>' : self::$showMsg;
}
}
/**
* Filter::msgSingleOk()
*
* @param mixed $msg
* @param bool $print
* @return
*/
public static function msgSingleOk($msg, $print = true)
{
self::$showMsg = "<div class=\"corporato success message\"><i class=\"ok sign icon\"></i> " . $msg . "</div>";
if ($print == true) {
print self::$showMsg;
} else {
return self::$showMsg;
}
}
/**
* Filter::msgInfo()
*
* @param mixed $msg
* @param bool $fader
* @param bool $print
* @param bool $altholder
* @return
*/
public static function msgInfo($msg, $print = true, $fader = false, $altholder = false)
{
self::$showMsg = "<div class=\"corporato icon message info\"><i class=\"information icon\"></i><i class=\"close icon\"></i><div class=\"content\"><div class=\"header\"> " . Lang::$word->INFO . "</div><p>" . $msg . "</p></div></div>";
if ($fader == true)
self::$showMsg .= "<script type=\"text/javascript\">
// <![CDATA[
setTimeout(function() {
$(\".msgInfo\").fadeOut(\"slow\",
function() {
$(\".msgInfo\").remove();
});
},
4000);
// ]]>
</script>";
if ($print == true) {
print ($altholder) ? '<div id="alt-msgholder">' . self::$showMsg . '</div>' : self::$showMsg;
} else {
return ($altholder) ? '<div id="alt-msgholder">' . self::$showMsg . '</div>' : self::$showMsg;
}
}
/**
* Filter::msgSingleInfo()
*
* @param mixed $msg
* @param bool $print
* @return
*/
public static function msgSingleInfo($msg, $print = true)
{
self::$showMsg = "<div class=\"corporato info message\"><i class=\"information icon\"></i> " . $msg . "</div>";
if ($print == true) {
print self::$showMsg;
} else {
return self::$showMsg;
}
}
/**
* Filter::msgError()
*
* @param mixed $msg
* @param bool $fader
* @param bool $print
* @param bool $altholder
* @return
*/
public static function msgError($msg, $print = true, $fader = false, $altholder = false)
{
self::$showMsg = "<div class=\"corporato icon message error\"><i class=\"exclamation icon\"></i><i class=\"close icon\"></i><div class=\"content\"><div class=\"header\"> " . Lang::$word->ERROR . "</div><p>" . $msg .
"</p></div></div>";
if ($fader == true)
self::$showMsg .= "<script type=\"text/javascript\">
// <![CDATA[
setTimeout(function() {
$(\".msgError\").fadeOut(\"slow\",
function() {
$(\".msgError\").remove();
});
},
4000);
// ]]>
</script>";
if ($print == true) {
print ($altholder) ? '<div id="alt-msgholder">' . self::$showMsg . '</div>' : self::$showMsg;
} else {
return ($altholder) ? '<div id="alt-msgholder">' . self::$showMsg . '</div>' : self::$showMsg;
}
}
/**
* Filter::msgSingleError()
*
* @param mixed $msg
* @param bool $print
* @return
*/
public static function msgSingleError($msg, $print = true)
{
self::$showMsg = "<div class=\"corporato error message\"><i class=\"ban circle icon\"></i> " . $msg . "</div>";
if ($print == true) {
print self::$showMsg;
} else {
return self::$showMsg;
}
}
/**
* Filter::msgStatus()
*
* @return
*/
public static function msgStatus()
{
self::$showMsg = "<div class=\"corporato error message\"><i class=\"close icon\"></i><div class=\"header\">" . Lang::$word->PROCCESS_ERR . "</div><div class=\"content\"><ul class=\"corporato list\">";
$i = count(self::$showMsg);
foreach (self::$msgs as $msg) {
self::$showMsg .= "<li>" . $msg . "</li>\n";
}
self::$showMsg .= "</ul></div></div>";
return self::$showMsg;
}
/**
* Filter::error()
*
* @param mixed $msg
* @param mixed $source
* @return
*/
public static function error($msg, $source)
{
if(DEBUG == true) {
$the_error = "<div class=\"bgred\"><p>";
$the_error .= "<span>System ERROR!</span><br />";
$the_error .= "DB Error: " . $msg . " <br /> More Information: </p>";
$the_error .= "<ul class=\"error\">";
$the_error .= "<li> Date : " . date("F j, Y, g:i a") . "</li>";
$the_error .= "<li> Function: " . $source . "</li>";
$the_error .= "<li> Script: " . $_SERVER['REQUEST_URI'] . "</li>";
$the_error .= "<li>‹ <a href=\"javascript:history.go(-1)\"><strong>Go Back to previous page</strong></a></li>";
$the_error .= '</ul>';
$the_error .= '</div>';
} else {
$the_error = "<div class=\"bgred\" style=\"color:#444;width:400px;margin-left:auto;margin-right:auto;border:1px solid #C3C3C3;font-family:Arial, Helvetica, sans-serif;font-size:13px;padding:10px;background:#f2f2f2;border-radius:5px;text-shadow:1px 1px 0 #fff\">";
$the_error .= "<h4 style=\"font-size:18px;margin:0;padding:0\">Oops!!!</h4>";
$the_error .= "<p>Something went wrong. Looks like the page you're looking for was moved or never existed. Make sure you typed the correct URL or followed a valid link.</p>";
$the_error .= "<p>‹ <a href=\"javascript:history.go(-1)\" style=\"color:#0084FF;\"><strong>Go Back to previous page</strong></a></p>";
$the_error .= '</div>';
}
print $the_error;
die();
}
/**
* Filter::ooops()
*
* @return
*/
public static function ooops()
{
$the_error = "<div class=\"red\" style=\"color:#444;width:400px;margin-left:auto;margin-right:auto;border:1px solid #C3C3C3;font-family:Arial, Helvetica, sans-serif;font-size:13px;padding:10px;background:#f2f2f2;border-radius:5px;text-shadow:1px 1px 0 #fff\">";
$the_error .= "<h4 style=\"font-size:18px;margin:0;padding:0\">Oops!!!</h4>";
$the_error .= "<p>Something went wrong. Looks like the page you're looking for was moved or never existed. Make sure you typed the correct URL or followed a valid link.</p>";
$the_error .= "<p>‹ <a href=\"javascript:history.go(-1)\" style=\"color:#0084FF;\"><strong>Go Back to previous page</strong></a></p>";
$the_error .= '</div>';
print $the_error;
die();
}
/**
* Filter::getAction()
*
* @return
*/
private static function getAction()
{
if (isset(self::$get['action'])) {
$action = ((string)self::$get['action']) ? (string)self::$get['action'] : false;
$action = sanitize($action);
if ($action == false) {
self::error("You have selected an Invalid Action Method","Filter::getAction()");
} else
return self::$action = $action;
}
}
/**
* Filter::getDo()
*
* @return
*/
private static function getDo()
{
if (isset(self::$get['do'])) {
$do = ((string)self::$get['do']) ? (string)self::$get['do'] : false;
$do = sanitize($do);
if ($do == false) {
self::error("You have selected an Invalid Do Method","Filter::getDo()");
} else
return self::$do = $do;
}
}
/**
* Filter::checkPost()
*
* @param mixed $index
* @param mixed $msg
* @return
*/
public static function checkPost($index, $msg) {
if(empty($_POST[$index]))
self::$msgs[$index] = $msg;
}
/**
* Filter::dodate()
*
* @param mixed $format
* @param mixed $date
* @return
*/
public static function dodate($format, $date) {
return utf8_encode(strftime(Registry::get("Core")->$format, strtotime($date)));
}
/**
* Filter::dotime()
*
* @param mixed $time
* @return
*/
public static function dotime($time) {
return utf8_encode(strftime(Registry::get("Core")->time_format, strtotime($time)));
}
/**
* Filter::readFile()
*
* @param mixed $filename
* @param boll $retbytes
* @return
*/
public static function readFile($filename,$retbytes=true) {
$chunksize = 1*(1024*1024);
$buffer = '';
$cnt =0;
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status) {
return $cnt;
}
return $status;
}
/**
* Filter::fetchFile()
*
* @param mixed $dirname
* @param mixed $fname
* @param mixed $file_path
* @return
*/
public function fetchFile($dirname, $fname, &$file_path)
{
$dir = opendir($dirname);
while ($file = readdir($dir)) {
if (empty($file_path) && $file != '.' && $file != '..') {
if (is_dir($dirname . '/' . $file)) {
self::fetchFile($dirname . '/' . $file, $fname, $file_path);
} else {
if (file_exists($dirname . '/' . $fname)) {
$file_path = $dirname . '/' . $fname;
return;
}
}
}
}
}
/**
* Filter::mark()
*
* @param mixed $name
* @return
*/
public static function mark($name)
{
self::$marker[$name] = microtime();
}
/**
* Filter::elapsed()
*
* @param string $point1
* @param string $point2
* @param integer $decimals
* @return
*/
public static function elapsed($point1 = '', $point2 = '', $decimals = 4)
{
if (!isset(self::$marker[$point1])) {
return '';
}
if (!isset(self::$marker[$point2])) {
self::$marker[$point2] = microtime();
}
list($sm, $ss) = explode(' ', self::$marker[$point1]);
list($em, $es) = explode(' ', self::$marker[$point2]);
return number_format(($em + $es) - ($sm + $ss), $decimals);
}
}
?>