0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-09 23:28:42 +00: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:
Edward Z. Yang 2007-02-04 22:26:56 +00:00
parent 236159242f
commit bb8b38b1e0
5 changed files with 33 additions and 25 deletions

View File

@ -7,7 +7,7 @@ require_once 'HTMLPurifier/AttrDef/Lang.php';
* Defines common attribute collections that modules reference
*/
class HTMLPurifier_AttrCollection
class HTMLPurifier_AttrCollections
{
/**
@ -23,9 +23,11 @@ class HTMLPurifier_AttrCollection
'id' => 'ID',
'title' => 'CDATA',
),
'I18N' => array(
'Lang' => array(
'xml:lang' => false, // see constructor
'lang' => false, // see constructor
),
'I18N' => array(
0 => array('Lang'), // proprietary, for xml:lang/lang
),
'Common' => array(
0 => array('Core', 'I18N')
@ -35,10 +37,9 @@ class HTMLPurifier_AttrCollection
/**
* Sets up direct objects not registered to HTMLPurifier_AttrTypes
*/
function HTMLPurifier_AttrCollection() {
function HTMLPurifier_AttrCollections() {
// setup direct objects
$this->info['I18N']['xml:lang'] =
$this->info['I18N']['lang'] = new HTMLPurifier_AttrDef_Lang();
$this->info['Lang']['xml:lang'] = new HTMLPurifier_AttrDef_Lang();
}
/**
@ -52,7 +53,7 @@ class HTMLPurifier_AttrCollection
$info =& $this->info;
// load extensions from the modules
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) {
if ($attr_i === 0 && isset($info[$coll_i][$attr_i])) {
// merge in includes
@ -109,6 +110,7 @@ class HTMLPurifier_AttrCollection
if (isset($attr_types->info[$def])) {
$attr[$def_i] = $attr_types->info[$def];
} else {
trigger_error('Attempted to reference undefined attribute type', E_USER_ERROR);
unset($attr[$def_i]);
}
}

View File

@ -8,6 +8,10 @@
* way to represent the internals of HTMLDefinition, and our
* implementation is by no means conforming and does not directly
* 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
@ -32,7 +36,8 @@ class HTMLPurifier_HTMLModule
/**
* Associative array of content set names to content set additions.
* 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
*/
var $content_sets = array();
@ -41,10 +46,12 @@ class HTMLPurifier_HTMLModule
* Associative array of attribute collection names to attribute
* collection additions. More rarely used for adding attributes to
* 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
*/
var $attr_collection = array();
var $attr_collections_info = array();
/**
* Boolean flag that indicates whether or not getChildDef is implemented.

View File

@ -13,24 +13,22 @@ class HTMLPurifier_HTMLModule_Bdo extends HTMLPurifier_HTMLModule
var $elements = array('bdo');
var $info = array();
var $content_sets = array('Inline' => 'bdo');
var $attr_collection = array(
var $attr_collections_info = array(
'I18N' => array('dir' => false)
);
function HTMLPurifier_HTMLModule_Bdo() {
$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']->attr = array(
0 => array('Core'),
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)
'lang' => 'Lang',
'xml:lang' => 'Lang'
);
$this->info['bdo']->content_model = '#PCDATA | Inline';
$this->info['bdo']->content_model_type = 'optional';

View File

@ -9,7 +9,7 @@ require_once 'HTMLPurifier/AttrDef/CSS.php';
*/
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
// is in line with the DTD and XML Schemas.
'Style' => array('style' => false), // see constructor
@ -17,7 +17,7 @@ class HTMLPurifier_HTMLModule_StyleAttribute extends HTMLPurifier_HTMLModule
);
function HTMLPurifier_HTMLModule_StyleAttribute() {
$this->attr_collection['Style']['style'] = new HTMLPurifier_AttrDef_CSS();
$this->attr_collections_info['Style']['style'] = new HTMLPurifier_AttrDef_CSS();
}
}

View File

@ -3,7 +3,7 @@
require_once 'HTMLPurifier/HTMLDefinition.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
require_once 'HTMLPurifier/AttrDef.php';
@ -48,10 +48,10 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
var $attr_types;
/**
* Instance of HTMLPurifier_AttrCollection
* Instance of HTMLPurifier_AttrCollections
* @public
*/
var $attr_collection;
var $attr_collections;
/**
* Performs low-cost, preliminary initialization.
@ -70,7 +70,7 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
$this->modules['StyleAttribute']= new HTMLPurifier_HTMLModule_StyleAttribute();
$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) {
// 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
$content_sets = array();
@ -121,8 +121,9 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
$def =& $this->modules[$module_i]->info[$name];
// 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);
// perform content model expansions
@ -169,7 +170,7 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
*/
function setupBlockWrapper($config) {
$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;
} else {
trigger_error('Cannot use non-block element as block wrapper.',