00001 <?php 00002 00007 class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition 00008 { 00009 00010 public $type = 'CSS'; 00011 00015 public $info = array(); 00016 00020 protected function doSetup($config) { 00021 00022 $this->info['text-align'] = new HTMLPurifier_AttrDef_Enum( 00023 array('left', 'right', 'center', 'justify'), false); 00024 00025 $border_style = 00026 $this->info['border-bottom-style'] = 00027 $this->info['border-right-style'] = 00028 $this->info['border-left-style'] = 00029 $this->info['border-top-style'] = new HTMLPurifier_AttrDef_Enum( 00030 array('none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 00031 'groove', 'ridge', 'inset', 'outset'), false); 00032 00033 $this->info['border-style'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_style); 00034 00035 $this->info['clear'] = new HTMLPurifier_AttrDef_Enum( 00036 array('none', 'left', 'right', 'both'), false); 00037 $this->info['float'] = new HTMLPurifier_AttrDef_Enum( 00038 array('none', 'left', 'right'), false); 00039 $this->info['font-style'] = new HTMLPurifier_AttrDef_Enum( 00040 array('normal', 'italic', 'oblique'), false); 00041 $this->info['font-variant'] = new HTMLPurifier_AttrDef_Enum( 00042 array('normal', 'small-caps'), false); 00043 00044 $uri_or_none = new HTMLPurifier_AttrDef_CSS_Composite( 00045 array( 00046 new HTMLPurifier_AttrDef_Enum(array('none')), 00047 new HTMLPurifier_AttrDef_CSS_URI() 00048 ) 00049 ); 00050 00051 $this->info['list-style-position'] = new HTMLPurifier_AttrDef_Enum( 00052 array('inside', 'outside'), false); 00053 $this->info['list-style-type'] = new HTMLPurifier_AttrDef_Enum( 00054 array('disc', 'circle', 'square', 'decimal', 'lower-roman', 00055 'upper-roman', 'lower-alpha', 'upper-alpha', 'none'), false); 00056 $this->info['list-style-image'] = $uri_or_none; 00057 00058 $this->info['list-style'] = new HTMLPurifier_AttrDef_CSS_ListStyle($config); 00059 00060 $this->info['text-transform'] = new HTMLPurifier_AttrDef_Enum( 00061 array('capitalize', 'uppercase', 'lowercase', 'none'), false); 00062 $this->info['color'] = new HTMLPurifier_AttrDef_CSS_Color(); 00063 00064 $this->info['background-image'] = $uri_or_none; 00065 $this->info['background-repeat'] = new HTMLPurifier_AttrDef_Enum( 00066 array('repeat', 'repeat-x', 'repeat-y', 'no-repeat') 00067 ); 00068 $this->info['background-attachment'] = new HTMLPurifier_AttrDef_Enum( 00069 array('scroll', 'fixed') 00070 ); 00071 $this->info['background-position'] = new HTMLPurifier_AttrDef_CSS_BackgroundPosition(); 00072 00073 $border_color = 00074 $this->info['border-top-color'] = 00075 $this->info['border-bottom-color'] = 00076 $this->info['border-left-color'] = 00077 $this->info['border-right-color'] = 00078 $this->info['background-color'] = new HTMLPurifier_AttrDef_CSS_Composite(array( 00079 new HTMLPurifier_AttrDef_Enum(array('transparent')), 00080 new HTMLPurifier_AttrDef_CSS_Color() 00081 )); 00082 00083 $this->info['background'] = new HTMLPurifier_AttrDef_CSS_Background($config); 00084 00085 $this->info['border-color'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_color); 00086 00087 $border_width = 00088 $this->info['border-top-width'] = 00089 $this->info['border-bottom-width'] = 00090 $this->info['border-left-width'] = 00091 $this->info['border-right-width'] = new HTMLPurifier_AttrDef_CSS_Composite(array( 00092 new HTMLPurifier_AttrDef_Enum(array('thin', 'medium', 'thick')), 00093 new HTMLPurifier_AttrDef_CSS_Length('0') //disallow negative 00094 )); 00095 00096 $this->info['border-width'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_width); 00097 00098 $this->info['letter-spacing'] = new HTMLPurifier_AttrDef_CSS_Composite(array( 00099 new HTMLPurifier_AttrDef_Enum(array('normal')), 00100 new HTMLPurifier_AttrDef_CSS_Length() 00101 )); 00102 00103 $this->info['word-spacing'] = new HTMLPurifier_AttrDef_CSS_Composite(array( 00104 new HTMLPurifier_AttrDef_Enum(array('normal')), 00105 new HTMLPurifier_AttrDef_CSS_Length() 00106 )); 00107 00108 $this->info['font-size'] = new HTMLPurifier_AttrDef_CSS_Composite(array( 00109 new HTMLPurifier_AttrDef_Enum(array('xx-small', 'x-small', 00110 'small', 'medium', 'large', 'x-large', 'xx-large', 00111 'larger', 'smaller')), 00112 new HTMLPurifier_AttrDef_CSS_Percentage(), 00113 new HTMLPurifier_AttrDef_CSS_Length() 00114 )); 00115 00116 $this->info['line-height'] = new HTMLPurifier_AttrDef_CSS_Composite(array( 00117 new HTMLPurifier_AttrDef_Enum(array('normal')), 00118 new HTMLPurifier_AttrDef_CSS_Number(true), // no negatives 00119 new HTMLPurifier_AttrDef_CSS_Length('0'), 00120 new HTMLPurifier_AttrDef_CSS_Percentage(true) 00121 )); 00122 00123 $margin = 00124 $this->info['margin-top'] = 00125 $this->info['margin-bottom'] = 00126 $this->info['margin-left'] = 00127 $this->info['margin-right'] = new HTMLPurifier_AttrDef_CSS_Composite(array( 00128 new HTMLPurifier_AttrDef_CSS_Length(), 00129 new HTMLPurifier_AttrDef_CSS_Percentage(), 00130 new HTMLPurifier_AttrDef_Enum(array('auto')) 00131 )); 00132 00133 $this->info['margin'] = new HTMLPurifier_AttrDef_CSS_Multiple($margin); 00134 00135 // non-negative 00136 $padding = 00137 $this->info['padding-top'] = 00138 $this->info['padding-bottom'] = 00139 $this->info['padding-left'] = 00140 $this->info['padding-right'] = new HTMLPurifier_AttrDef_CSS_Composite(array( 00141 new HTMLPurifier_AttrDef_CSS_Length('0'), 00142 new HTMLPurifier_AttrDef_CSS_Percentage(true) 00143 )); 00144 00145 $this->info['padding'] = new HTMLPurifier_AttrDef_CSS_Multiple($padding); 00146 00147 $this->info['text-indent'] = new HTMLPurifier_AttrDef_CSS_Composite(array( 00148 new HTMLPurifier_AttrDef_CSS_Length(), 00149 new HTMLPurifier_AttrDef_CSS_Percentage() 00150 )); 00151 00152 $trusted_wh = new HTMLPurifier_AttrDef_CSS_Composite(array( 00153 new HTMLPurifier_AttrDef_CSS_Length('0'), 00154 new HTMLPurifier_AttrDef_CSS_Percentage(true), 00155 new HTMLPurifier_AttrDef_Enum(array('auto')) 00156 )); 00157 $max = $config->get('CSS.MaxImgLength'); 00158 00159 $this->info['width'] = 00160 $this->info['height'] = 00161 $max === null ? 00162 $trusted_wh : 00163 new HTMLPurifier_AttrDef_Switch('img', 00164 // For img tags: 00165 new HTMLPurifier_AttrDef_CSS_Composite(array( 00166 new HTMLPurifier_AttrDef_CSS_Length('0', $max), 00167 new HTMLPurifier_AttrDef_Enum(array('auto')) 00168 )), 00169 // For everyone else: 00170 $trusted_wh 00171 ); 00172 00173 $this->info['text-decoration'] = new HTMLPurifier_AttrDef_CSS_TextDecoration(); 00174 00175 $this->info['font-family'] = new HTMLPurifier_AttrDef_CSS_FontFamily(); 00176 00177 // this could use specialized code 00178 $this->info['font-weight'] = new HTMLPurifier_AttrDef_Enum( 00179 array('normal', 'bold', 'bolder', 'lighter', '100', '200', '300', 00180 '400', '500', '600', '700', '800', '900'), false); 00181 00182 // MUST be called after other font properties, as it references 00183 // a CSSDefinition object 00184 $this->info['font'] = new HTMLPurifier_AttrDef_CSS_Font($config); 00185 00186 // same here 00187 $this->info['border'] = 00188 $this->info['border-bottom'] = 00189 $this->info['border-top'] = 00190 $this->info['border-left'] = 00191 $this->info['border-right'] = new HTMLPurifier_AttrDef_CSS_Border($config); 00192 00193 $this->info['border-collapse'] = new HTMLPurifier_AttrDef_Enum(array( 00194 'collapse', 'separate')); 00195 00196 $this->info['caption-side'] = new HTMLPurifier_AttrDef_Enum(array( 00197 'top', 'bottom')); 00198 00199 $this->info['table-layout'] = new HTMLPurifier_AttrDef_Enum(array( 00200 'auto', 'fixed')); 00201 00202 $this->info['vertical-align'] = new HTMLPurifier_AttrDef_CSS_Composite(array( 00203 new HTMLPurifier_AttrDef_Enum(array('baseline', 'sub', 'super', 00204 'top', 'text-top', 'middle', 'bottom', 'text-bottom')), 00205 new HTMLPurifier_AttrDef_CSS_Length(), 00206 new HTMLPurifier_AttrDef_CSS_Percentage() 00207 )); 00208 00209 $this->info['border-spacing'] = new HTMLPurifier_AttrDef_CSS_Multiple(new HTMLPurifier_AttrDef_CSS_Length(), 2); 00210 00211 // partial support 00212 $this->info['white-space'] = new HTMLPurifier_AttrDef_Enum(array('nowrap')); 00213 00214 if ($config->get('CSS.Proprietary')) { 00215 $this->doSetupProprietary($config); 00216 } 00217 00218 if ($config->get('CSS.AllowTricky')) { 00219 $this->doSetupTricky($config); 00220 } 00221 00222 $allow_important = $config->get('CSS.AllowImportant'); 00223 // wrap all attr-defs with decorator that handles !important 00224 foreach ($this->info as $k => $v) { 00225 $this->info[$k] = new HTMLPurifier_AttrDef_CSS_ImportantDecorator($v, $allow_important); 00226 } 00227 00228 $this->setupConfigStuff($config); 00229 } 00230 00231 protected function doSetupProprietary($config) { 00232 // Internet Explorer only scrollbar colors 00233 $this->info['scrollbar-arrow-color'] = new HTMLPurifier_AttrDef_CSS_Color(); 00234 $this->info['scrollbar-base-color'] = new HTMLPurifier_AttrDef_CSS_Color(); 00235 $this->info['scrollbar-darkshadow-color'] = new HTMLPurifier_AttrDef_CSS_Color(); 00236 $this->info['scrollbar-face-color'] = new HTMLPurifier_AttrDef_CSS_Color(); 00237 $this->info['scrollbar-highlight-color'] = new HTMLPurifier_AttrDef_CSS_Color(); 00238 $this->info['scrollbar-shadow-color'] = new HTMLPurifier_AttrDef_CSS_Color(); 00239 00240 // technically not proprietary, but CSS3, and no one supports it 00241 $this->info['opacity'] = new HTMLPurifier_AttrDef_CSS_AlphaValue(); 00242 $this->info['-moz-opacity'] = new HTMLPurifier_AttrDef_CSS_AlphaValue(); 00243 $this->info['-khtml-opacity'] = new HTMLPurifier_AttrDef_CSS_AlphaValue(); 00244 00245 // only opacity, for now 00246 $this->info['filter'] = new HTMLPurifier_AttrDef_CSS_Filter(); 00247 00248 } 00249 00250 protected function doSetupTricky($config) { 00251 $this->info['display'] = new HTMLPurifier_AttrDef_Enum(array( 00252 'inline', 'block', 'list-item', 'run-in', 'compact', 00253 'marker', 'table', 'inline-table', 'table-row-group', 00254 'table-header-group', 'table-footer-group', 'table-row', 00255 'table-column-group', 'table-column', 'table-cell', 'table-caption', 'none' 00256 )); 00257 $this->info['visibility'] = new HTMLPurifier_AttrDef_Enum(array( 00258 'visible', 'hidden', 'collapse' 00259 )); 00260 $this->info['overflow'] = new HTMLPurifier_AttrDef_Enum(array('visible', 'hidden', 'auto', 'scroll')); 00261 } 00262 00263 00270 protected function setupConfigStuff($config) { 00271 00272 // setup allowed elements 00273 $support = "(for information on implementing this, see the ". 00274 "support forums) "; 00275 $allowed_attributes = $config->get('CSS.AllowedProperties'); 00276 if ($allowed_attributes !== null) { 00277 foreach ($this->info as $name => $d) { 00278 if(!isset($allowed_attributes[$name])) unset($this->info[$name]); 00279 unset($allowed_attributes[$name]); 00280 } 00281 // emit errors 00282 foreach ($allowed_attributes as $name => $d) { 00283 // :TODO: Is this htmlspecialchars() call really necessary? 00284 $name = htmlspecialchars($name); 00285 trigger_error("Style attribute '$name' is not supported $support", E_USER_WARNING); 00286 } 00287 } 00288 00289 } 00290 } 00291 00292 // vim: et sw=4 sts=4
| Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved. MyOOS [Shopsystem] is Free Software released under the GNU/GPL License. Webmaster: info@r23.de (Impressum) |
|
