mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 11:20:13 +02:00
Rename attr_collection to attr_collections, which is more accurate. HTMLModule now has attr_collections_info rather than attr_collections which implied an object. Further clarified naming conventions.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@721 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -7,7 +7,7 @@ require_once 'HTMLPurifier/AttrDef/Lang.php';
|
|||||||
* Defines common attribute collections that modules reference
|
* Defines common attribute collections that modules reference
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class HTMLPurifier_AttrCollection
|
class HTMLPurifier_AttrCollections
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,9 +23,11 @@ class HTMLPurifier_AttrCollection
|
|||||||
'id' => 'ID',
|
'id' => 'ID',
|
||||||
'title' => 'CDATA',
|
'title' => 'CDATA',
|
||||||
),
|
),
|
||||||
'I18N' => array(
|
'Lang' => array(
|
||||||
'xml:lang' => false, // see constructor
|
'xml:lang' => false, // see constructor
|
||||||
'lang' => false, // see constructor
|
),
|
||||||
|
'I18N' => array(
|
||||||
|
0 => array('Lang'), // proprietary, for xml:lang/lang
|
||||||
),
|
),
|
||||||
'Common' => array(
|
'Common' => array(
|
||||||
0 => array('Core', 'I18N')
|
0 => array('Core', 'I18N')
|
||||||
@@ -35,10 +37,9 @@ class HTMLPurifier_AttrCollection
|
|||||||
/**
|
/**
|
||||||
* Sets up direct objects not registered to HTMLPurifier_AttrTypes
|
* Sets up direct objects not registered to HTMLPurifier_AttrTypes
|
||||||
*/
|
*/
|
||||||
function HTMLPurifier_AttrCollection() {
|
function HTMLPurifier_AttrCollections() {
|
||||||
// setup direct objects
|
// setup direct objects
|
||||||
$this->info['I18N']['xml:lang'] =
|
$this->info['Lang']['xml:lang'] = new HTMLPurifier_AttrDef_Lang();
|
||||||
$this->info['I18N']['lang'] = new HTMLPurifier_AttrDef_Lang();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,7 +53,7 @@ class HTMLPurifier_AttrCollection
|
|||||||
$info =& $this->info;
|
$info =& $this->info;
|
||||||
// load extensions from the modules
|
// load extensions from the modules
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
foreach ($module->attr_collection as $coll_i => $coll) {
|
foreach ($module->attr_collections_info as $coll_i => $coll) {
|
||||||
foreach ($coll as $attr_i => $attr) {
|
foreach ($coll as $attr_i => $attr) {
|
||||||
if ($attr_i === 0 && isset($info[$coll_i][$attr_i])) {
|
if ($attr_i === 0 && isset($info[$coll_i][$attr_i])) {
|
||||||
// merge in includes
|
// merge in includes
|
||||||
@@ -109,6 +110,7 @@ class HTMLPurifier_AttrCollection
|
|||||||
if (isset($attr_types->info[$def])) {
|
if (isset($attr_types->info[$def])) {
|
||||||
$attr[$def_i] = $attr_types->info[$def];
|
$attr[$def_i] = $attr_types->info[$def];
|
||||||
} else {
|
} else {
|
||||||
|
trigger_error('Attempted to reference undefined attribute type', E_USER_ERROR);
|
||||||
unset($attr[$def_i]);
|
unset($attr[$def_i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -8,6 +8,10 @@
|
|||||||
* way to represent the internals of HTMLDefinition, and our
|
* way to represent the internals of HTMLDefinition, and our
|
||||||
* implementation is by no means conforming and does not directly
|
* implementation is by no means conforming and does not directly
|
||||||
* use the normative DTDs or XML schemas.
|
* use the normative DTDs or XML schemas.
|
||||||
|
* @note The public variables in a module should almost directly
|
||||||
|
* correspond to the variables in HTMLPurifier_HTMLDefinition.
|
||||||
|
* However, the prefix info carries no special meaning in these
|
||||||
|
* objects (include it anyway if that's the correspondence though).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class HTMLPurifier_HTMLModule
|
class HTMLPurifier_HTMLModule
|
||||||
@@ -32,7 +36,8 @@ class HTMLPurifier_HTMLModule
|
|||||||
/**
|
/**
|
||||||
* Associative array of content set names to content set additions.
|
* Associative array of content set names to content set additions.
|
||||||
* This is commonly used to, say, add an A element to the Inline
|
* This is commonly used to, say, add an A element to the Inline
|
||||||
* content set.
|
* content set. This corresponds to an internal variable $content_sets
|
||||||
|
* and NOT info_content_sets member variable of HTMLDefinition.
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
var $content_sets = array();
|
var $content_sets = array();
|
||||||
@@ -41,10 +46,12 @@ class HTMLPurifier_HTMLModule
|
|||||||
* Associative array of attribute collection names to attribute
|
* Associative array of attribute collection names to attribute
|
||||||
* collection additions. More rarely used for adding attributes to
|
* collection additions. More rarely used for adding attributes to
|
||||||
* the global collections. Example is the StyleAttribute module adding
|
* the global collections. Example is the StyleAttribute module adding
|
||||||
* the style attribute to the Core.
|
* the style attribute to the Core. Corresponds to attr_collections
|
||||||
|
* attr_collections->info, as only one object with behavior is
|
||||||
|
* necessary.
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
var $attr_collection = array();
|
var $attr_collections_info = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boolean flag that indicates whether or not getChildDef is implemented.
|
* Boolean flag that indicates whether or not getChildDef is implemented.
|
||||||
|
@@ -13,24 +13,22 @@ class HTMLPurifier_HTMLModule_Bdo extends HTMLPurifier_HTMLModule
|
|||||||
var $elements = array('bdo');
|
var $elements = array('bdo');
|
||||||
var $info = array();
|
var $info = array();
|
||||||
var $content_sets = array('Inline' => 'bdo');
|
var $content_sets = array('Inline' => 'bdo');
|
||||||
var $attr_collection = array(
|
var $attr_collections_info = array(
|
||||||
'I18N' => array('dir' => false)
|
'I18N' => array('dir' => false)
|
||||||
);
|
);
|
||||||
|
|
||||||
function HTMLPurifier_HTMLModule_Bdo() {
|
function HTMLPurifier_HTMLModule_Bdo() {
|
||||||
$dir = new HTMLPurifier_AttrDef_Enum(array('ltr','rtl'), false);
|
$dir = new HTMLPurifier_AttrDef_Enum(array('ltr','rtl'), false);
|
||||||
$this->attr_collection['I18N']['dir'] = $dir;
|
$this->attr_collections_info['I18N']['dir'] = $dir;
|
||||||
$this->info['bdo'] = new HTMLPurifier_ElementDef();
|
$this->info['bdo'] = new HTMLPurifier_ElementDef();
|
||||||
$this->info['bdo']->attr = array(
|
$this->info['bdo']->attr = array(
|
||||||
0 => array('Core'),
|
0 => array('Core', 'Lang'),
|
||||||
'dir' => $dir, // required
|
'dir' => $dir, // required
|
||||||
// The Abstract Module specification has the attribute
|
// The Abstract Module specification has the attribute
|
||||||
// inclusions wrong for bdo: bdo allows
|
// inclusions wrong for bdo: bdo allows
|
||||||
// xml:lang too (and we'll toss in lang for good measure,
|
// xml:lang too (and we'll toss in lang for good measure,
|
||||||
// though it is not allowed for XHTML 1.1, this will
|
// though it is not allowed for XHTML 1.1, this will
|
||||||
// be managed with a global attribute transform)
|
// be managed with a global attribute transform)
|
||||||
'lang' => 'Lang',
|
|
||||||
'xml:lang' => 'Lang'
|
|
||||||
);
|
);
|
||||||
$this->info['bdo']->content_model = '#PCDATA | Inline';
|
$this->info['bdo']->content_model = '#PCDATA | Inline';
|
||||||
$this->info['bdo']->content_model_type = 'optional';
|
$this->info['bdo']->content_model_type = 'optional';
|
||||||
|
@@ -9,7 +9,7 @@ require_once 'HTMLPurifier/AttrDef/CSS.php';
|
|||||||
*/
|
*/
|
||||||
class HTMLPurifier_HTMLModule_StyleAttribute extends HTMLPurifier_HTMLModule
|
class HTMLPurifier_HTMLModule_StyleAttribute extends HTMLPurifier_HTMLModule
|
||||||
{
|
{
|
||||||
var $attr_collection = array(
|
var $attr_collections_info = array(
|
||||||
// The inclusion routine differs from the Abstract Modules but
|
// The inclusion routine differs from the Abstract Modules but
|
||||||
// is in line with the DTD and XML Schemas.
|
// is in line with the DTD and XML Schemas.
|
||||||
'Style' => array('style' => false), // see constructor
|
'Style' => array('style' => false), // see constructor
|
||||||
@@ -17,7 +17,7 @@ class HTMLPurifier_HTMLModule_StyleAttribute extends HTMLPurifier_HTMLModule
|
|||||||
);
|
);
|
||||||
|
|
||||||
function HTMLPurifier_HTMLModule_StyleAttribute() {
|
function HTMLPurifier_HTMLModule_StyleAttribute() {
|
||||||
$this->attr_collection['Style']['style'] = new HTMLPurifier_AttrDef_CSS();
|
$this->attr_collections_info['Style']['style'] = new HTMLPurifier_AttrDef_CSS();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
require_once 'HTMLPurifier/HTMLDefinition.php';
|
require_once 'HTMLPurifier/HTMLDefinition.php';
|
||||||
|
|
||||||
require_once 'HTMLPurifier/AttrTypes.php';
|
require_once 'HTMLPurifier/AttrTypes.php';
|
||||||
require_once 'HTMLPurifier/AttrCollection.php';
|
require_once 'HTMLPurifier/AttrCollections.php';
|
||||||
|
|
||||||
// we'll manage loading extremely commonly used attr definitions
|
// we'll manage loading extremely commonly used attr definitions
|
||||||
require_once 'HTMLPurifier/AttrDef.php';
|
require_once 'HTMLPurifier/AttrDef.php';
|
||||||
@@ -48,10 +48,10 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
|
|||||||
var $attr_types;
|
var $attr_types;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance of HTMLPurifier_AttrCollection
|
* Instance of HTMLPurifier_AttrCollections
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
var $attr_collection;
|
var $attr_collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs low-cost, preliminary initialization.
|
* Performs low-cost, preliminary initialization.
|
||||||
@@ -70,7 +70,7 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
|
|||||||
$this->modules['StyleAttribute']= new HTMLPurifier_HTMLModule_StyleAttribute();
|
$this->modules['StyleAttribute']= new HTMLPurifier_HTMLModule_StyleAttribute();
|
||||||
|
|
||||||
$this->attr_types = new HTMLPurifier_AttrTypes();
|
$this->attr_types = new HTMLPurifier_AttrTypes();
|
||||||
$this->attr_collection = new HTMLPurifier_AttrCollection();
|
$this->attr_collections = new HTMLPurifier_AttrCollections();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
|
|||||||
function setup($config) {
|
function setup($config) {
|
||||||
|
|
||||||
// perform attribute collection substitutions
|
// perform attribute collection substitutions
|
||||||
$this->attr_collection->setup($this->attr_types, $this->modules);
|
$this->attr_collections->setup($this->attr_types, $this->modules);
|
||||||
|
|
||||||
// populate content_sets based on module hints
|
// populate content_sets based on module hints
|
||||||
$content_sets = array();
|
$content_sets = array();
|
||||||
@@ -121,8 +121,9 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
|
|||||||
$def =& $this->modules[$module_i]->info[$name];
|
$def =& $this->modules[$module_i]->info[$name];
|
||||||
|
|
||||||
// attribute value expansions
|
// attribute value expansions
|
||||||
$this->attr_collection->performInclusions($def->attr);
|
|
||||||
$this->attr_collection->expandIdentifiers(
|
$this->attr_collections->performInclusions($def->attr);
|
||||||
|
$this->attr_collections->expandIdentifiers(
|
||||||
$def->attr, $this->attr_types);
|
$def->attr, $this->attr_types);
|
||||||
|
|
||||||
// perform content model expansions
|
// perform content model expansions
|
||||||
@@ -169,7 +170,7 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
|
|||||||
*/
|
*/
|
||||||
function setupBlockWrapper($config) {
|
function setupBlockWrapper($config) {
|
||||||
$block_wrapper = $config->get('HTML', 'BlockWrapper');
|
$block_wrapper = $config->get('HTML', 'BlockWrapper');
|
||||||
if (isset($this->content_sets['Block'][$block_wrapper])) {
|
if (isset($this->info_content_sets['Block'][$block_wrapper])) {
|
||||||
$this->info_block_wrapper = $block_wrapper;
|
$this->info_block_wrapper = $block_wrapper;
|
||||||
} else {
|
} else {
|
||||||
trigger_error('Cannot use non-block element as block wrapper.',
|
trigger_error('Cannot use non-block element as block wrapper.',
|
||||||
|
Reference in New Issue
Block a user