App\Libraries\CleanHTML::purify PHP Метод

purify() публичный статический Метод

public static purify ( $text )
    public static function purify($text)
    {
        $config = HTMLPurifier_Config::createDefault();
        $config->set('Cache.SerializerPath', storage_path() . '/htmlpurifier');
        $config->set('Attr.AllowedRel', ['nofollow']);
        $config->set('HTML.Trusted', true);
        $def = $config->getHTMLDefinition(true);
        $def->addElement('audio', 'Inline', 'Inline', 'Common', ['src' => 'URI', 'controls' => 'Text']);
        $def->addAttribute('img', 'data-normal', 'Text');
        $def->addAttribute('img', 'src', 'Text');
        $def->addAttribute('span', 'data-src', 'Text');
        $def->addAttribute('span', 'data-height', 'Text');
        $def->addAttribute('span', 'data-width', 'Text');
        $def->addAttribute('span', 'data-index', 'Text');
        $def->addAttribute('span', 'data-gallery-id', 'Text');
        return (new HTMLPurifier($config))->purify($text);
    }

Usage Example

Пример #1
0
 public function toHTML()
 {
     $text = $this->text;
     // block
     $text = $this->parseBox($text);
     $text = $this->parseCode($text);
     $text = $this->parseList($text);
     $text = $this->parseNotice($text);
     $text = $this->parseQuote($text);
     $text = $this->parseHeading($text);
     $text = $this->clearSpacesBetweenTags($text);
     // inline
     $text = $this->parseBold($text);
     $text = $this->parseCentre($text);
     $text = $this->parseColour($text);
     $text = $this->parseEmail($text);
     $text = $this->parseImage($text);
     $text = $this->parseItalic($text);
     $text = $this->parseSize($text);
     $text = $this->parseSmilies($text);
     $text = $this->parseSpoiler($text);
     $text = $this->parseStrike($text);
     $text = $this->parseUnderline($text);
     $text = $this->parseUrl($text);
     $text = $this->parseYoutube($text);
     $text = $this->parseProfile($text);
     $text = preg_replace('/\\n/', "\n<br />", $text);
     $text = CleanHTML::purify($text);
     return "<div class='bbcode'>{$text}</div>";
 }
CleanHTML