mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-09 07:36:40 +02:00
[1.7.0] Create convenience functions for HTMLModule constructors, HTMLModule_Bdo was hooked up
- Add initial "safe" property for elements, is not set for most though git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1039 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -58,6 +58,7 @@ class HTMLPurifier_ElementDef
|
||||
/**
|
||||
* Value of $child->type, used to determine which ChildDef to use,
|
||||
* used in combination with $content_model.
|
||||
* @warning This must be lowercase
|
||||
* @public
|
||||
*/
|
||||
var $content_model_type;
|
||||
@@ -86,6 +87,24 @@ class HTMLPurifier_ElementDef
|
||||
*/
|
||||
var $excludes = array();
|
||||
|
||||
/**
|
||||
* Is this element safe for untrusted users to use?
|
||||
*/
|
||||
var $safe = false;
|
||||
|
||||
/**
|
||||
* Factory constructor for creating new standalone element defs
|
||||
* @static
|
||||
*/
|
||||
function create($safe, $content_model, $content_model_type, $attr) {
|
||||
$def = new HTMLPurifier_ElementDef();
|
||||
$def->safe = (bool) $safe;
|
||||
$def->content_model = $content_model;
|
||||
$def->content_model_type = $content_model_type;
|
||||
$def->attr = $attr;
|
||||
return $def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the values of another element definition into this one.
|
||||
* Values from the new element def take precedence if a value is
|
||||
|
@@ -120,6 +120,49 @@ class HTMLPurifier_HTMLModule
|
||||
*/
|
||||
function setup(&$definition) {}
|
||||
|
||||
/**
|
||||
* Convenience function that sets up a new element
|
||||
* @param $element Name of element to add
|
||||
* @param $safe Is element safe for untrusted users to use?
|
||||
* @param $type What content set should element be registered to?
|
||||
* Set as false to skip this step.
|
||||
* @param $content_model Content model definition in form of:
|
||||
* "$content_model_type: $content_model"
|
||||
* @param $attr_includes What attribute collections to register to
|
||||
* element?
|
||||
* @param $attr What unique attributes does the element define?
|
||||
* @note See ElementDef for in-depth descriptions of these parameters.
|
||||
* @protected
|
||||
*/
|
||||
function addElement($element, $safe, $type, $content_model, $attr_includes, $attr) {
|
||||
$this->elements[] = $element;
|
||||
// parse content_model
|
||||
list($content_model_type, $content_model) = explode(':', $content_model);
|
||||
$content_model_type = strtolower(trim($content_model_type));
|
||||
$content_model = trim($content_model);
|
||||
// merge in attribute inclusions
|
||||
$attr[0] = $attr_includes;
|
||||
// add element to content sets
|
||||
if ($type) $this->addElementToContentSet($element, $type);
|
||||
// create element
|
||||
$this->info[$element] = HTMLPurifier_ElementDef::create(
|
||||
$safe, $content_model, $content_model_type, $attr
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function that registers an element to a content set
|
||||
* @param Element to register
|
||||
* @param Name content set (warning: case sensitive, usually upper-case
|
||||
* first letter)
|
||||
* @protected
|
||||
*/
|
||||
function addElementToContentSet($element, $type) {
|
||||
if (!isset($this->content_sets[$type])) $this->content_sets[$type] = '';
|
||||
else $this->content_sets[$type] .= ' | ';
|
||||
$this->content_sets[$type] .= $element;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -11,30 +11,25 @@ class HTMLPurifier_HTMLModule_Bdo extends HTMLPurifier_HTMLModule
|
||||
{
|
||||
|
||||
var $name = 'Bdo';
|
||||
var $elements = array('bdo');
|
||||
var $content_sets = array('Inline' => 'bdo');
|
||||
var $attr_collections = array(
|
||||
'I18N' => array('dir' => false)
|
||||
);
|
||||
|
||||
function HTMLPurifier_HTMLModule_Bdo() {
|
||||
$dir = new HTMLPurifier_AttrDef_Enum(array('ltr','rtl'), false);
|
||||
$this->attr_collections['I18N']['dir'] = $dir;
|
||||
$this->info['bdo'] = new HTMLPurifier_ElementDef();
|
||||
$this->info['bdo']->attr = array(
|
||||
0 => array('Core', 'Lang'),
|
||||
'dir' => $dir, // required
|
||||
// The Abstract Module specification has the attribute
|
||||
// inclusions wrong for bdo: bdo allows
|
||||
// xml:lang too (and we'll toss in lang for good measure,
|
||||
// though it is not allowed for XHTML 1.1, this will
|
||||
// be managed with a global attribute transform)
|
||||
$this->addElement(
|
||||
'bdo', true, 'Inline', 'Optional: #PCDATA | Inline', array('Core', 'Lang'),
|
||||
array(
|
||||
'dir' => $dir, // required
|
||||
// The Abstract Module specification has the attribute
|
||||
// inclusions wrong for bdo: bdo allows
|
||||
// xml:lang too (and we'll toss in lang for good measure,
|
||||
// though it is not allowed for XHTML 1.1, this will
|
||||
// be managed with a global attribute transform)
|
||||
)
|
||||
);
|
||||
$this->info['bdo']->content_model = '#PCDATA | Inline';
|
||||
$this->info['bdo']->content_model_type = 'optional';
|
||||
// provides fallback behavior if dir's missing (dir is required)
|
||||
$this->info['bdo']->attr_transform_post['required-dir'] =
|
||||
new HTMLPurifier_AttrTransform_BdoDir();
|
||||
$this->info['bdo']->attr_transform_post['required-dir'] = new HTMLPurifier_AttrTransform_BdoDir();
|
||||
$this->attr_collections['I18N']['dir'] = $dir;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user