Completed
Pull Request — master (#7)
by
unknown
05:35 queued 03:54
created

Htmlawed   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
dl 0
loc 82
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B filter() 0 21 5
A filterRSS() 0 19 1
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 1730
    public static function filter($html, array $config = null, $spec = null) {
44 1730
        require_once __DIR__.'/htmLawed/htmLawed.php';
45
46 1730
        if ($config === null) {
47 583
            $config = self::$defaultConfig;
48
        }
49
50 1730
        if (isset($config['spec']) && !$spec) {
51
            $spec = $config['spec'];
52
        }
53
54 1730
        if ($spec === null) {
55 612
            $spec = static::$defaultSpec;
56
        }
57
58 1730
        $filtered = htmLawed($html, $config, $spec);
0 ignored issues
show
Documentation introduced by
$config is of type array, but the function expects a integer.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
59
        // Replace empty paragraphs.
60
        // Htmlawed balances <p><pre><code>Code</code></pre></p> into <p></p><pre><code>Code</code></pre>
61 1730
        $filtered = str_replace('<p></p>', null, $filtered);
62 1730
        return $filtered;
63
    }
64
65
66
    /**
67
     * Filter a string of html so that it can be put into an rss feed.
68
     *
69
     * @param $html The html text to fitlter.
70
     * @return string Returns the filtered html.
71
     * @see Htmlawed::filter().
72
     */
73 559
    public static function filterRSS($html) {
74
        $config = array(
75 559
            'anti_link_spam' => ['`.`', ''],
76
            'comment' => 1,
77
            'cdata' => 3,
78
            'css_expression' => 1,
79
            'deny_attribute' => 'on*,style,class',
80
            'elements' => '*-applet-form-input-textarea-iframe-script-style-object-embed-comment-link-listing-meta-noscript-plaintext-xmp',
81
            'keep_bad' => 0,
82
            '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
83
            'valid_xml' => 2,
84
            'balance' => 1
85
        );
86 559
        $spec = static::$defaultSpec;
87
88 559
        $result = static::filter($html, $config, $spec);
89
90 559
        return $result;
91
    }
92
}
93