|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Todd Burry <[email protected]> |
|
4
|
|
|
* @copyright 2009-2014 Vanilla Forums Inc. |
|
5
|
|
|
* @license LGPL-3.0 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* A class wrapper for the htmLawed library. |
|
10
|
|
|
*/ |
|
11
|
|
|
class Htmlawed { |
|
12
|
|
|
/// Methods /// |
|
13
|
|
|
|
|
14
|
|
|
public static $defaultConfig = [ |
|
15
|
|
|
'anti_link_spam' => ['`.`', ''], |
|
16
|
|
|
'balance' => 1, |
|
17
|
|
|
'cdata' => 3, |
|
18
|
|
|
'comment' => 1, |
|
19
|
|
|
'css_expression' => 0, |
|
20
|
|
|
'deny_attribute' => 'on*,style', |
|
21
|
|
|
'direct_list_nest' => 1, |
|
22
|
|
|
'elements' => '*-applet-button-form-input-textarea-iframe-script-style-embed-object', |
|
23
|
|
|
'keep_bad' => 0, |
|
24
|
|
|
'schemes' => 'classid:clsid; href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; style: nil; *:file, http, https', // clsid allowed in class |
|
25
|
|
|
'unique_ids' => 0, |
|
26
|
|
|
'valid_xhtml' => 0, |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
public static $defaultSpec = [ |
|
30
|
|
|
'object=-classid-type, -codebase', |
|
31
|
|
|
'embed=type(oneof=application/x-shockwave-flash)' |
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Filters a string of html with the htmLawed library. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $html The text to filter. |
|
38
|
|
|
* @param array|null $config Config settings for the array. |
|
39
|
|
|
* @param string|array|null $spec A specification to further limit the allowed attribute values in the html. |
|
40
|
|
|
* @return string Returns the filtered html. |
|
41
|
|
|
* @see http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/htmLawed_README.htm |
|
42
|
|
|
*/ |
|
43
|
1731 |
|
public static function filter($html, array $config = null, $spec = null) { |
|
44
|
1731 |
|
require_once __DIR__.'/htmLawed/htmLawed.php'; |
|
45
|
|
|
|
|
46
|
1731 |
|
if ($config === null) { |
|
47
|
584 |
|
$config = self::$defaultConfig; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1731 |
|
if (isset($config['spec']) && !$spec) { |
|
51
|
|
|
$spec = $config['spec']; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1731 |
|
if ($spec === null) { |
|
55
|
613 |
|
$spec = static::$defaultSpec; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1731 |
|
return htmLawed($html, $config, $spec); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Filter a string of html so that it can be put into an rss feed. |
|
64
|
|
|
* |
|
65
|
|
|
* @param $html The html text to fitlter. |
|
66
|
|
|
* @return string Returns the filtered html. |
|
67
|
|
|
* @see Htmlawed::filter(). |
|
68
|
|
|
*/ |
|
69
|
559 |
|
public static function filterRSS($html) { |
|
70
|
|
|
$config = array( |
|
71
|
559 |
|
'anti_link_spam' => ['`.`', ''], |
|
72
|
|
|
'comment' => 1, |
|
73
|
|
|
'cdata' => 3, |
|
74
|
|
|
'css_expression' => 1, |
|
75
|
|
|
'deny_attribute' => 'on*,style,class', |
|
76
|
|
|
'elements' => '*-applet-form-input-textarea-iframe-script-style-object-embed-comment-link-listing-meta-noscript-plaintext-xmp', |
|
77
|
|
|
'keep_bad' => 0, |
|
78
|
|
|
'schemes' => 'classid:clsid; href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; style: nil; *:file, http, https', // clsid allowed in class |
|
79
|
|
|
'valid_xhtml' => 1, |
|
80
|
|
|
'balance' => 1 |
|
81
|
|
|
); |
|
82
|
559 |
|
$spec = static::$defaultSpec; |
|
83
|
|
|
|
|
84
|
559 |
|
$result = static::filter($html, $config, $spec); |
|
85
|
|
|
|
|
86
|
559 |
|
return $result; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: