Exercise / HTMLPurifierBundle

HTML Purifier is a standards-compliant HTML filter library written in PHP.
http://htmlpurifier.org/
Other
275 stars 56 forks source link

Support <video> tags #34

Closed sdespont closed 4 years ago

sdespont commented 8 years ago

I adapted the code some times ago to accept the "< video >" tags, but it is not working anymore since versions 0.2.X and I really don't know why. The "< video >" tag is still present after purrifying, but the "src" element is removed.

Any hints to figure this out?

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');
          $config->set('HTML.SafeIframe', true);

          // 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',
            ));
          }
          $this->purifier = new \HTMLPurifier($config);
    }
           ...
alister commented 8 years ago

It may be more useful to try to add video element support to the main HTMLPurifier library.

sdespont commented 6 years ago

Hello,

updated code working with last version :

Source : https://github.com/kennberg/php-htmlpurfier-html5/blob/master/htmlpurifier_html5.php

/**
 * Constructor.
 *
 * @param \HTMLPurifier $purifier
 */
public function __construct($purifier)
{
    //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);
}
HeahDude commented 4 years ago

Closing this old issue because the problem of the OP has been resolved and we already have #26 to track the featuring of such configuration with YAML too. Thanks!