Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / lib / htmlpurifier / HTMLPurifier / AttrCollections.php
blob8318abb15c40dfe14317d9f6f45d3ac9935c211d
1 <?php
3 require_once 'HTMLPurifier/AttrTypes.php';
4 require_once 'HTMLPurifier/AttrDef/Lang.php';
6 /**
7 * Defines common attribute collections that modules reference
8 */
10 class HTMLPurifier_AttrCollections
13 /**
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
18 var $info = array();
20 /**
21 * Performs all expansions on internal data for use by other inclusions
22 * It also collects all attribute collection extensions from
23 * modules
24 * @param $attr_types HTMLPurifier_AttrTypes instance
25 * @param $modules Hash array of HTMLPurifier_HTMLModule members
27 function HTMLPurifier_AttrCollections($attr_types, $modules) {
28 $info =& $this->info;
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])) {
34 // merge in includes
35 $info[$coll_i][$attr_i] = array_merge(
36 $info[$coll_i][$attr_i], $attr);
37 continue;
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);
52 /**
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;
59 $merge = $attr[0];
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
65 $attr[$key] = $value;
67 if (isset($info[$merge[$i]][0])) {
68 // recursion
69 $merge = array_merge($merge, isset($info[$merge[$i]][0]));
72 unset($attr[0]);
75 /**
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;
85 if ($def === false) {
86 unset($attr[$def_i]);
87 continue;
89 if (isset($attr_types->info[$def])) {
90 $attr[$def_i] = $attr_types->info[$def];
91 } else {
92 trigger_error('Attempted to reference undefined attribute type', E_USER_ERROR);
93 unset($attr[$def_i]);