3 require_once 'HTMLPurifier/AttrTypes.php';
4 require_once 'HTMLPurifier/AttrDef/Lang.php';
7 * Defines common attribute collections that modules reference
10 class HTMLPurifier_AttrCollection
14 * Associative array of attribute collections, indexed by name
15 * @note Technically, the composition of these is more complicated,
16 * but we bypass it using our own excludes property
21 // 'xml:space' => false,
22 'class' => 'NMTOKENS',
27 'xml:lang' => false, // see constructor
28 'lang' => false, // see constructor
31 0 => array('Core', 'I18N')
36 * Sets up direct objects not registered to HTMLPurifier_AttrTypes
38 function HTMLPurifier_AttrCollection() {
39 // setup direct objects
40 $this->info
['I18N']['xml:lang'] =
41 $this->info
['I18N']['lang'] = new HTMLPurifier_AttrDef_Lang();
45 * Performs all expansions on internal data for use by other inclusions
46 * It also collects all attribute collection extensions from
48 * @param $attr_types HTMLPurifier_AttrTypes instance
49 * @param $modules Hash array of HTMLPurifier_HTMLModule members
51 function setup($attr_types, $modules) {
53 // load extensions from the modules
54 foreach ($modules as $module) {
55 foreach ($module->attr_collection
as $coll_i => $coll) {
56 foreach ($coll as $attr_i => $attr) {
57 if ($attr_i === 0 && isset($info[$coll_i][$attr_i])) {
59 $info[$coll_i][$attr_i] = array_merge(
60 $info[$coll_i][$attr_i], $attr);
63 $info[$coll_i][$attr_i] = $attr;
67 // perform internal expansions and inclusions
68 foreach ($info as $name => $attr) {
69 // merge attribute collections that include others
70 $this->performInclusions($info[$name]);
71 // replace string identifiers with actual attribute objects
72 $this->expandIdentifiers($info[$name], $attr_types);
77 * Takes a reference to an attribute associative array and performs
78 * all inclusions specified by the zero index.
79 * @param &$attr Reference to attribute array
81 function performInclusions(&$attr) {
82 if (!isset($attr[0])) return;
84 // loop through all the inclusions
85 for ($i = 0; isset($merge[$i]); $i++
) {
86 // foreach attribute of the inclusion, copy it over
87 foreach ($this->info
[$merge[$i]] as $key => $value) {
88 if (isset($attr[$key])) continue; // also catches more inclusions
91 if (isset($info[$merge[$i]][0])) {
93 $merge = array_merge($merge, isset($info[$merge[$i]][0]));
100 * Expands all string identifiers in an attribute array by replacing
101 * them with the appropriate values inside HTMLPurifier_AttrTypes
102 * @param &$attr Reference to attribute array
103 * @param $attr_types HTMLPurifier_AttrTypes instance
105 function expandIdentifiers(&$attr, $attr_types) {
106 foreach ($attr as $def_i => $def) {
107 if ($def_i === 0) continue;
108 if (!is_string($def)) continue;
109 if (isset($attr_types->info
[$def])) {
110 $attr[$def_i] = $attr_types->info
[$def];
112 unset($attr[$def_i]);