00001 <?php
00002
00006 class HTMLPurifier_ContentSets
00007 {
00008
00012 public $info = array();
00013
00018 public $lookup = array();
00019
00023 protected $keys = array();
00027 protected $values = array();
00028
00034 public function __construct($modules) {
00035 if (!is_array($modules)) $modules = array($modules);
00036
00037
00038 foreach ($modules as $module_i => $module) {
00039 foreach ($module->content_sets as $key => $value) {
00040 if (isset($this->info[$key])) {
00041
00042 $this->info[$key] = $this->info[$key] . ' | ' . $value;
00043 } else {
00044 $this->info[$key] = $value;
00045 }
00046 }
00047 }
00048
00049 $this->keys = array_keys($this->info);
00050 foreach ($this->info as $i => $set) {
00051
00052
00053 $this->info[$i] =
00054 str_replace(
00055 $this->keys,
00056
00057
00058 array_values($this->info),
00059 $set);
00060 }
00061 $this->values = array_values($this->info);
00062
00063
00064 foreach ($this->info as $name => $set) {
00065 $this->lookup[$name] = $this->convertToLookup($set);
00066 }
00067 }
00068
00074 public function generateChildDef(&$def, $module) {
00075 if (!empty($def->child)) return;
00076 $content_model = $def->content_model;
00077 if (is_string($content_model)) {
00078 $def->content_model = str_replace(
00079 $this->keys, $this->values, $content_model);
00080 }
00081 $def->child = $this->getChildDef($def, $module);
00082 }
00083
00092 public function getChildDef($def, $module) {
00093 $value = $def->content_model;
00094 if (is_object($value)) {
00095 trigger_error(
00096 'Literal object child definitions should be stored in '.
00097 'ElementDef->child not ElementDef->content_model',
00098 E_USER_NOTICE
00099 );
00100 return $value;
00101 }
00102 switch ($def->content_model_type) {
00103 case 'required':
00104 return new HTMLPurifier_ChildDef_Required($value);
00105 case 'optional':
00106 return new HTMLPurifier_ChildDef_Optional($value);
00107 case 'empty':
00108 return new HTMLPurifier_ChildDef_Empty();
00109 case 'custom':
00110 return new HTMLPurifier_ChildDef_Custom($value);
00111 }
00112
00113 $return = false;
00114 if ($module->defines_child_def) {
00115 $return = $module->getChildDef($def);
00116 }
00117 if ($return !== false) return $return;
00118
00119 trigger_error(
00120 'Could not determine which ChildDef class to instantiate',
00121 E_USER_ERROR
00122 );
00123 return false;
00124 }
00125
00132 protected function convertToLookup($string) {
00133 $array = explode('|', str_replace(' ', '', $string));
00134 $ret = array();
00135 foreach ($array as $i => $k) {
00136 $ret[$k] = true;
00137 }
00138 return $ret;
00139 }
00140
00141 }
00142