| 1: | <?php
|
| 2: |
|
| 3: | |
| 4: | |
| 5: |
|
| 6: |
|
| 7: | class HTMLPurifier_AttrCollections
|
| 8: | {
|
| 9: |
|
| 10: | |
| 11: | |
| 12: | |
| 13: |
|
| 14: | public $info = array();
|
| 15: |
|
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: |
|
| 23: | public function __construct($attr_types, $modules)
|
| 24: | {
|
| 25: | $this->doConstruct($attr_types, $modules);
|
| 26: | }
|
| 27: |
|
| 28: | public function doConstruct($attr_types, $modules)
|
| 29: | {
|
| 30: |
|
| 31: | foreach ($modules as $module) {
|
| 32: | foreach ($module->attr_collections as $coll_i => $coll) {
|
| 33: | if (!isset($this->info[$coll_i])) {
|
| 34: | $this->info[$coll_i] = array();
|
| 35: | }
|
| 36: | foreach ($coll as $attr_i => $attr) {
|
| 37: | if ($attr_i === 0 && isset($this->info[$coll_i][$attr_i])) {
|
| 38: |
|
| 39: | $this->info[$coll_i][$attr_i] = array_merge(
|
| 40: | $this->info[$coll_i][$attr_i],
|
| 41: | $attr
|
| 42: | );
|
| 43: | continue;
|
| 44: | }
|
| 45: | $this->info[$coll_i][$attr_i] = $attr;
|
| 46: | }
|
| 47: | }
|
| 48: | }
|
| 49: |
|
| 50: | foreach ($this->info as $name => $attr) {
|
| 51: |
|
| 52: | $this->performInclusions($this->info[$name]);
|
| 53: |
|
| 54: | $this->expandIdentifiers($this->info[$name], $attr_types);
|
| 55: | }
|
| 56: | }
|
| 57: |
|
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: |
|
| 63: | public function performInclusions(&$attr)
|
| 64: | {
|
| 65: | if (!isset($attr[0])) {
|
| 66: | return;
|
| 67: | }
|
| 68: | $merge = $attr[0];
|
| 69: | $seen = array();
|
| 70: |
|
| 71: | for ($i = 0; isset($merge[$i]); $i++) {
|
| 72: | if (isset($seen[$merge[$i]])) {
|
| 73: | continue;
|
| 74: | }
|
| 75: | $seen[$merge[$i]] = true;
|
| 76: |
|
| 77: | if (!isset($this->info[$merge[$i]])) {
|
| 78: | continue;
|
| 79: | }
|
| 80: | foreach ($this->info[$merge[$i]] as $key => $value) {
|
| 81: | if (isset($attr[$key])) {
|
| 82: | continue;
|
| 83: | }
|
| 84: | $attr[$key] = $value;
|
| 85: | }
|
| 86: | if (isset($this->info[$merge[$i]][0])) {
|
| 87: |
|
| 88: | $merge = array_merge($merge, $this->info[$merge[$i]][0]);
|
| 89: | }
|
| 90: | }
|
| 91: | unset($attr[0]);
|
| 92: | }
|
| 93: |
|
| 94: | |
| 95: | |
| 96: | |
| 97: | |
| 98: | |
| 99: |
|
| 100: | public function expandIdentifiers(&$attr, $attr_types)
|
| 101: | {
|
| 102: |
|
| 103: |
|
| 104: | $processed = array();
|
| 105: |
|
| 106: | foreach ($attr as $def_i => $def) {
|
| 107: |
|
| 108: | if ($def_i === 0) {
|
| 109: | continue;
|
| 110: | }
|
| 111: |
|
| 112: | if (isset($processed[$def_i])) {
|
| 113: | continue;
|
| 114: | }
|
| 115: |
|
| 116: |
|
| 117: | if ($required = (strpos($def_i, '*') !== false)) {
|
| 118: |
|
| 119: | unset($attr[$def_i]);
|
| 120: | $def_i = trim($def_i, '*');
|
| 121: | $attr[$def_i] = $def;
|
| 122: | }
|
| 123: |
|
| 124: | $processed[$def_i] = true;
|
| 125: |
|
| 126: |
|
| 127: | if (is_object($def)) {
|
| 128: |
|
| 129: | $attr[$def_i]->required = ($required || $attr[$def_i]->required);
|
| 130: | continue;
|
| 131: | }
|
| 132: |
|
| 133: | if ($def === false) {
|
| 134: | unset($attr[$def_i]);
|
| 135: | continue;
|
| 136: | }
|
| 137: |
|
| 138: | if ($t = $attr_types->get($def)) {
|
| 139: | $attr[$def_i] = $t;
|
| 140: | $attr[$def_i]->required = $required;
|
| 141: | } else {
|
| 142: | unset($attr[$def_i]);
|
| 143: | }
|
| 144: | }
|
| 145: | }
|
| 146: | }
|
| 147: |
|
| 148: |
|
| 149: | |