I am using TinyMCE and HTMLPurifier in a Symfony2 application.
I need to embed some internals videos of the website with TinyMCE. The problem is that HTML Purifier don't accept HTML5 video tag and remove them.
Is there someone to let me know how can I configure TinyMCE/HTMLPurifier to permit videos embedding?
From https://github.com/Exercise/HTMLPurifierBundle, I sligthly addapt the transformer to accept the video tag.
Find full HTML5 config here : https://github.com/kennberg/php-htmlpurfier-html5
<?php
namespace Exercise\HTMLPurifierBundle\Form;
use Symfony\Component\Form\DataTransformerInterface;
class HTMLPurifierTransformer implements DataTransformerInterface
{
private $purifier;
/**
* Constructor.
*
* @param \HTMLPurifier $purifier
*/
public function __construct()
{
//Find full HTML5 config : https://github.com/kennberg/php-htmlpurfier-html5
$config = \HTMLPurifier_Config::createDefault();
$config->set('HTML.Doctype', 'HTML 4.01 Transitional');
// Set some HTML5 properties
$config->set('HTML.DefinitionID', 'html5-definitions'); // unqiue id
$config->set('HTML.DefinitionRev', 1);
if ($def = $config->maybeGetRawHTMLDefinition()) {
// http://developers.whatwg.org/the-video-element.html#the-video-element
$def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', array(
'src' => 'URI',
'type' => 'Text',
'width' => 'Length',
'height' => 'Length',
'poster' => 'URI',
'preload' => 'Enum#auto,metadata,none',
'controls' => 'Bool',
));
$def->addElement('source', 'Block', 'Flow', 'Common', array(
'src' => 'URI',
'type' => 'Text',
));
}
$this->purifier = new \HTMLPurifier($config);
}
/**
* @see Symfony\Component\Form\DataTransformerInterface::transform()
*/
public function transform($value)
{
return $value;
}
/**
* @see Symfony\Component\Form\DataTransformerInterface::reverseTransform()
*/
public function reverseTransform($value)
{
return $this->purifier->purify($value);
}
}
EDIT 2018-04-16
Adapt code to avoid "src" removing with last HTML Purifier version.
More options : https://github.com/kennberg/php-htmlpurfier-html5/blob/master/htmlpurifier_html5.php