Completed
Push — master ( 014c18...79149c )
by Richard
33s queued 22s
created

kses()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 18
rs 9.8333
cc 4
nc 6
nop 3
1
<?php
2
3
/**
4
 * @file
5
 * Emulation layer for code that used kses(), substituting in HTML Purifier.
6
 */
7
8
require_once dirname(__FILE__) . '/HTMLPurifier.auto.php';
9
10
function kses($string, $allowed_html, $allowed_protocols = null)
11
{
12
    $config = HTMLPurifier_Config::createDefault();
13
    $allowed_elements = array();
14
    $allowed_attributes = array();
15
    foreach ($allowed_html as $element => $attributes) {
16
        $allowed_elements[$element] = true;
17
        foreach ($attributes as $attribute => $x) {
18
            $allowed_attributes["$element.$attribute"] = true;
19
        }
20
    }
21
    $config->set('HTML.AllowedElements', $allowed_elements);
22
    $config->set('HTML.AllowedAttributes', $allowed_attributes);
23
    if ($allowed_protocols !== null) {
24
        $config->set('URI.AllowedSchemes', $allowed_protocols);
25
    }
26
    $purifier = new HTMLPurifier($config);
27
    return $purifier->purify($string);
28
}
29
30
// vim: et sw=4 sts=4
31