1
0
mirror of https://github.com/flarum/core.git synced 2025-08-01 14:10:37 +02:00

Make HTMLPurifier config extensible; allow images

This commit is contained in:
Toby Zerner
2015-06-08 09:37:30 +09:30
parent f928e746d9
commit 7a76bf175d

View File

@@ -15,6 +15,8 @@ class FormatterManager
*/ */
protected $container; protected $container;
public $config;
/** /**
* Create a new formatter manager instance. * Create a new formatter manager instance.
* *
@@ -24,6 +26,17 @@ class FormatterManager
public function __construct(Container $container = null) public function __construct(Container $container = null)
{ {
$this->container = $container ?: new Container; $this->container = $container ?: new Container;
// Studio does not yet merge autoload_files...
// https://github.com/franzliedke/studio/commit/4f0f4314db4ed3e36c869a5f79b855c97bdd1be7
require __DIR__.'/../../../vendor/ezyang/htmlpurifier/library/HTMLPurifier.composer.php';
$this->config = HTMLPurifier_Config::createDefault();
$this->config->set('Core.Encoding', 'UTF-8');
$this->config->set('Core.EscapeInvalidTags', true);
$this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
$this->config->set('HTML.Allowed', 'p,em,strong,a[href|title],ul,ol,li,code,pre,blockquote,h1,h2,h3,h4,h5,h6,br,hr,img[src|alt]');
$this->config->set('HTML.Nofollow', true);
} }
public function add($name, $formatter, $priority = 0) public function add($name, $formatter, $priority = 0)
@@ -67,18 +80,7 @@ class FormatterManager
$text = $formatter->beforePurification($text, $post); $text = $formatter->beforePurification($text, $post);
} }
// Studio does not yet merge autoload_files... $purifier = new HTMLPurifier($this->config);
// https://github.com/franzliedke/studio/commit/4f0f4314db4ed3e36c869a5f79b855c97bdd1be7
require __DIR__.'/../../../vendor/ezyang/htmlpurifier/library/HTMLPurifier.composer.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('Core.Encoding', 'UTF-8');
$config->set('Core.EscapeInvalidTags', true);
$config->set('HTML.Doctype', 'HTML 4.01 Strict');
$config->set('HTML.Allowed', 'p,em,strong,a[href|title],ul,ol,li,code,pre,blockquote,h1,h2,h3,h4,h5,h6,br,hr');
$config->set('HTML.Nofollow', true);
$purifier = new HTMLPurifier($config);
$text = $purifier->purify($text); $text = $purifier->purify($text);