Passed
Push — master ( 9dbdd9...d5a428 )
by Alexander
04:15
created

framework/helpers/BaseHtmlPurifier.php (1 issue)

1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace yii\helpers;
9
10
/**
11
 * BaseHtmlPurifier provides concrete implementation for [[HtmlPurifier]].
12
 *
13
 * Do not use BaseHtmlPurifier. Use [[HtmlPurifier]] instead.
14
 *
15
 * @author Alexander Makarov <[email protected]>
16
 * @since 2.0
17
 */
18
class BaseHtmlPurifier
19
{
20
    /**
21
     * Passes markup through HTMLPurifier making it safe to output to end user.
22
     *
23
     * @param string $content The HTML content to purify
24
     * @param array|\Closure|null $config The config to use for HtmlPurifier.
25
     * If not specified or `null` the default config will be used.
26
     * You can use an array or an anonymous function to provide configuration options:
27
     *
28
     * - An array will be passed to the `HTMLPurifier_Config::create()` method.
29
     * - An anonymous function will be called after the config was created.
30
     *   The signature should be: `function($config)` where `$config` will be an
31
     *   instance of `HTMLPurifier_Config`.
32
     *
33
     *   Here is a usage example of such a function:
34
     *
35
     *   ```php
36
     *   // Allow the HTML5 data attribute `data-type` on `img` elements.
37
     *   $content = HtmlPurifier::process($content, function ($config) {
38
     *     $config->getHTMLDefinition(true)
39
     *            ->addAttribute('img', 'data-type', 'Text');
40
     *   });
41
     * ```
42
     *
43
     * @return string the purified HTML content.
44
     */
45
    public static function process($content, $config = null)
46
    {
47
        $configInstance = \HTMLPurifier_Config::create($config instanceof \Closure ? null : $config);
48
        $configInstance->autoFinalize = false;
49
        $purifier = \HTMLPurifier::instance($configInstance);
50
        $purifier->config->set('Cache.SerializerPath', \Yii::$app->getRuntimePath());
51
        $purifier->config->set('Cache.SerializerPermissions', 0775);
52
53
        static::configure($configInstance);
54
        if ($config instanceof \Closure) {
55
            call_user_func($config, $configInstance);
56
        }
57
58
        return $purifier->purify($content);
59
    }
60
61
    /**
62
     * Allow the extended HtmlPurifier class to set some default config options.
63
     * @param \HTMLPurifier_Config $config
64
     * @since 2.0.3
65
     */
66
    protected static function configure($config)
0 ignored issues
show
The parameter $config is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

66
    protected static function configure(/** @scrutinizer ignore-unused */ $config)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
    {
68
    }
69
}
70