Conventions: All member variables that are prefixed with info (including the main $info array) are used by HTML Purifier internals and should not be directly edited when customizing the HTMLDefinition. They can usually be set via configuration directives or custom modules. On the other hand, member variables without the info prefix are used internally by the HTMLDefinition and MUST NOT be used by other HTML Purifier internals. Many of them, however, are public, and may be edited by userspace code to tweak the behavior of HTMLDefinition.
Inheritance: extends HTMLPurifier_Definition
Exemple #1
0
 /**
  * Get info message about allowed html tags
  * 
  * @return string
  **/
 public function allowed_html()
 {
     require_once APPPATH . 'libraries/htmlpurifier/HTMLPurifier.auto.php';
     $def = new HTMLPurifier_HTMLDefinition();
     list($el, $attr) = $def->parseTinyMCEAllowedList(Kohana::config('config.allowed_html', FALSE, TRUE));
     $iframes = explode('|', str_replace(array('%^http://(', ')%'), '', Kohana::config('config.safe_iframe_regexp', FALSE, TRUE)));
     $output = "";
     $output .= Kohana::lang('ui_main.allowed_tags', implode(', ', array_keys($el)));
     $output .= "<br/> ";
     $output .= Kohana::lang('ui_main.allowed_iframes', implode(', ', $iframes));
     return $output;
 }
    function test_parseTinyMCEAllowedList()
    {
        $def = new HTMLPurifier_HTMLDefinition();
        // note: this is case-sensitive, but its config schema
        // counterpart is not. This is generally a good thing for users,
        // but it's a slight internal inconsistency
        $this->assertEqual($def->parseTinyMCEAllowedList(''), array(array(), array()));
        $this->assertEqual($def->parseTinyMCEAllowedList('a,b,c'), array(array('a' => true, 'b' => true, 'c' => true), array()));
        $this->assertEqual($def->parseTinyMCEAllowedList('a[x|y|z]'), array(array('a' => true), array('a.x' => true, 'a.y' => true, 'a.z' => true)));
        $this->assertEqual($def->parseTinyMCEAllowedList('*[id]'), array(array(), array('*.id' => true)));
        $this->assertEqual($def->parseTinyMCEAllowedList('a[*]'), array(array('a' => true), array('a.*' => true)));
        $this->assertEqual($def->parseTinyMCEAllowedList('span[style],strong,a[href|title]'), array(array('span' => true, 'strong' => true, 'a' => true), array('span.style' => true, 'a.href' => true, 'a.title' => true)));
        $this->assertEqual($def->parseTinyMCEAllowedList('span[style]
strong
a[href|title]
'), $val = array(array('span' => true, 'strong' => true, 'a' => true), array('span.style' => true, 'a.href' => true, 'a.title' => true)));
        $this->assertEqual($def->parseTinyMCEAllowedList(' span [ style ], strong' . "\n\t" . 'a[href | title]'), $val);
    }
 /**
  * Adds HTML5 element and attributes to a provided definition object.
  *
  * @param  HTMLPurifier_HTMLDefinition $def
  * @return HTMLPurifier_HTMLDefinition
  */
 public static function setup(HTMLPurifier_HTMLDefinition $def)
 {
     // use fixed implementation of Boolean attributes, instead of a buggy
     // one provided with 4.6.0
     $def->manager->attrTypes->set('Bool', new HTMLPurifier_AttrDef_HTML_Bool2());
     // http://developers.whatwg.org/sections.html
     $def->addElement('section', 'Block', 'Flow', 'Common');
     $def->addElement('nav', 'Block', 'Flow', 'Common');
     $def->addElement('article', 'Block', 'Flow', 'Common');
     $def->addElement('aside', 'Block', 'Flow', 'Common');
     $def->addElement('header', 'Block', 'Flow', 'Common');
     $def->addElement('footer', 'Block', 'Flow', 'Common');
     $def->addElement('main', 'Block', 'Flow', 'Common');
     // Content model actually excludes several tags, not modelled here
     $def->addElement('address', 'Block', 'Flow', 'Common');
     $def->addElement('hgroup', 'Block', 'Required: h1 | h2 | h3 | h4 | h5 | h6', 'Common');
     // http://developers.whatwg.org/grouping-content.html
     $def->addElement('figure', 'Block', 'Optional: (figcaption, Flow) | (Flow, figcaption) | Flow', 'Common');
     $def->addElement('figcaption', 'Inline', 'Flow', 'Common');
     // 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', 'Empty', 'Common', array('src' => 'URI', 'type' => 'Text'));
     // http://developers.whatwg.org/text-level-semantics.html
     $def->addElement('s', 'Inline', 'Inline', 'Common');
     $def->addElement('var', 'Inline', 'Inline', 'Common');
     $def->addElement('sub', 'Inline', 'Inline', 'Common');
     $def->addElement('sup', 'Inline', 'Inline', 'Common');
     $def->addElement('mark', 'Inline', 'Inline', 'Common');
     $def->addElement('wbr', 'Inline', 'Empty', 'Core');
     // http://developers.whatwg.org/edits.html
     $def->addElement('ins', 'Block', 'Flow', 'Common', array('cite' => 'URI', 'datetime' => 'Text'));
     $def->addElement('del', 'Block', 'Flow', 'Common', array('cite' => 'URI', 'datetime' => 'Text'));
     // TIME
     $time = $def->addElement('time', 'Inline', 'Inline', 'Common', array('datetime' => 'Text', 'pubdate' => 'Bool'));
     $time->excludes = array('time' => true);
     // IMG
     $def->addAttribute('img', 'srcset', 'Text');
     // IFRAME
     $def->addAttribute('iframe', 'allowfullscreen', 'Bool');
     return $def;
 }
/**
 * Implements hook_htmlpurifier_html_definition_alter().
 *
 * Allows modules to alter the HTML Definition used by HTML Purifier.
 *
 * @param HTMLPurifier_HTMLDefinition $html_definition
 *   The HTMLPurifier definition object to alter.
 */
function hook_htmlpurifier_html_definition_alter($html_definition)
{
    // Allow to use the 'data-type' attribute on images.
    $html_definition->addAttribute('img', 'data-type', 'Text');
}