3 require_once 'HTMLPurifier/AttrTypes.php';
4 require_once 'HTMLPurifier/AttrDef/Lang.php';
7 * Defines common attribute collections that modules reference
10 class HTMLPurifier_AttrCollections
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 * Performs all expansions on internal data for use by other inclusions
22 * It also collects all attribute collection extensions from
24 * @param $attr_types HTMLPurifier_AttrTypes instance
25 * @param $modules Hash array of HTMLPurifier_HTMLModule members
27 function HTMLPurifier_AttrCollections($attr_types, $modules) {
29 // load extensions from the modules
30 foreach ($modules as $module) {
31 foreach ($module->attr_collections
as $coll_i => $coll) {
32 foreach ($coll as $attr_i => $attr) {
33 if ($attr_i === 0 && isset($info[$coll_i][$attr_i])) {
35 $info[$coll_i][$attr_i] = array_merge(
36 $info[$coll_i][$attr_i], $attr);
39 $info[$coll_i][$attr_i] = $attr;
43 // perform internal expansions and inclusions
44 foreach ($info as $name => $attr) {
45 // merge attribute collections that include others
46 $this->performInclusions($info[$name]);
47 // replace string identifiers with actual attribute objects
48 $this->expandIdentifiers($info[$name], $attr_types);
53 * Takes a reference to an attribute associative array and performs
54 * all inclusions specified by the zero index.
55 * @param &$attr Reference to attribute array
57 function performInclusions(&$attr) {
58 if (!isset($attr[0])) return;
60 // loop through all the inclusions
61 for ($i = 0; isset($merge[$i]); $i++
) {
62 // foreach attribute of the inclusion, copy it over
63 foreach ($this->info
[$merge[$i]] as $key => $value) {
64 if (isset($attr[$key])) continue; // also catches more inclusions
67 if (isset($info[$merge[$i]][0])) {
69 $merge = array_merge($merge, isset($info[$merge[$i]][0]));
76 * Expands all string identifiers in an attribute array by replacing
77 * them with the appropriate values inside HTMLPurifier_AttrTypes
78 * @param &$attr Reference to attribute array
79 * @param $attr_types HTMLPurifier_AttrTypes instance
81 function expandIdentifiers(&$attr, $attr_types) {
82 foreach ($attr as $def_i => $def) {
83 if ($def_i === 0) continue;
84 if (!is_string($def)) continue;
89 if (isset($attr_types->info
[$def])) {
90 $attr[$def_i] = $attr_types->info
[$def];
92 trigger_error('Attempted to reference undefined attribute type', E_USER_ERROR
);