HTMLPurifier 4.4.0
|
00001 <?php 00002 00011 class HTMLPurifier_ElementDef 00012 { 00013 00018 public $standalone = true; 00019 00031 public $attr = array(); 00032 00036 public $attr_transform_pre = array(); 00037 00041 public $attr_transform_post = array(); 00042 00046 public $child; 00047 00055 public $content_model; 00056 00064 public $content_model_type; 00065 00066 00067 00074 public $descendants_are_inline = false; 00075 00080 public $required_attr = array(); 00081 00093 public $excludes = array(); 00094 00098 public $autoclose = array(); 00099 00105 public $wrap; 00106 00111 public $formatting; 00112 00116 public static function create($content_model, $content_model_type, $attr) { 00117 $def = new HTMLPurifier_ElementDef(); 00118 $def->content_model = $content_model; 00119 $def->content_model_type = $content_model_type; 00120 $def->attr = $attr; 00121 return $def; 00122 } 00123 00129 public function mergeIn($def) { 00130 00131 // later keys takes precedence 00132 foreach($def->attr as $k => $v) { 00133 if ($k === 0) { 00134 // merge in the includes 00135 // sorry, no way to override an include 00136 foreach ($v as $v2) { 00137 $this->attr[0][] = $v2; 00138 } 00139 continue; 00140 } 00141 if ($v === false) { 00142 if (isset($this->attr[$k])) unset($this->attr[$k]); 00143 continue; 00144 } 00145 $this->attr[$k] = $v; 00146 } 00147 $this->_mergeAssocArray($this->attr_transform_pre, $def->attr_transform_pre); 00148 $this->_mergeAssocArray($this->attr_transform_post, $def->attr_transform_post); 00149 $this->_mergeAssocArray($this->excludes, $def->excludes); 00150 00151 if(!empty($def->content_model)) { 00152 $this->content_model = 00153 str_replace("#SUPER", $this->content_model, $def->content_model); 00154 $this->child = false; 00155 } 00156 if(!empty($def->content_model_type)) { 00157 $this->content_model_type = $def->content_model_type; 00158 $this->child = false; 00159 } 00160 if(!is_null($def->child)) $this->child = $def->child; 00161 if(!is_null($def->formatting)) $this->formatting = $def->formatting; 00162 if($def->descendants_are_inline) $this->descendants_are_inline = $def->descendants_are_inline; 00163 00164 } 00165 00171 private function _mergeAssocArray(&$a1, $a2) { 00172 foreach ($a2 as $k => $v) { 00173 if ($v === false) { 00174 if (isset($a1[$k])) unset($a1[$k]); 00175 continue; 00176 } 00177 $a1[$k] = $v; 00178 } 00179 } 00180 00181 } 00182 00183 // vim: et sw=4 sts=4