1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* -------------------------------------------------------------------------- |
5
|
|
|
* Helper: squantoCleanupString |
6
|
|
|
* -------------------------------------------------------------------------- |
7
|
|
|
* |
8
|
|
|
* Takes an input and cleans up a regular string from unwanted input |
9
|
|
|
* |
10
|
|
|
* @param string $value |
11
|
|
|
* @return string |
12
|
|
|
*/ |
13
|
|
|
if(!function_exists('squantoCleanupString')) |
14
|
|
|
{ |
15
|
|
|
function squantoCleanupString( $value ) |
16
|
|
|
{ |
17
|
|
|
$value = strip_tags($value); |
18
|
|
|
|
19
|
|
|
return trim($value); |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* -------------------------------------------------------------------------- |
25
|
|
|
* Helper: squantoCleanupHTML |
26
|
|
|
* -------------------------------------------------------------------------- |
27
|
|
|
* |
28
|
|
|
* Takes an input and cleans up unwanted / malicious HTML |
29
|
|
|
* |
30
|
|
|
* @param string $value |
31
|
|
|
* @param string $whitelist - if false no tagstripping will occur - other than htmLawed |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
if(!function_exists('squantoCleanupHTML')) |
35
|
|
|
{ |
36
|
|
|
function squantoCleanupHTML( $value, $whitelist = null ) |
37
|
|
|
{ |
38
|
|
|
if(!function_exists('htmLawed')) |
39
|
|
|
{ |
40
|
|
|
require_once __DIR__ . '/vendors/htmlLawed.php'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if(is_null($whitelist)) |
44
|
|
|
{ |
45
|
|
|
$whitelist = '<code><span><div><label><a><br><p><b><i><del><strike><u><img><video><audio><iframe><object><embed><param><blockquote><mark><cite><small><ul><ol><li><hr><dl><dt><dd><sup><sub><big><pre><code><figure><figcaption><strong><em><table><tr><td><th><tbody><thead><tfoot><h1><h2><h3><h4><h5><h6>'; |
46
|
|
|
} |
47
|
|
|
// Strip entire blocks of malicious code |
48
|
|
|
$value = preg_replace(array( |
49
|
|
|
'@<script[^>]*?>.*?</script>@si', |
50
|
|
|
'@onclick=[^ ].*? @si' |
51
|
|
|
),'',$value); |
52
|
|
|
// strip unwanted tags via whitelist... |
53
|
|
|
if(false !== $whitelist) $value = strip_tags($value, $whitelist); |
54
|
|
|
// cleanup HTML and any unwanted attributes |
55
|
|
|
$value = htmLawed($value); |
56
|
|
|
return $value; |
57
|
|
|
} |
58
|
|
|
} |