Retrieves object reference to the CSS definition
public getCSSDefinition ( boolean $raw = false, boolean $optimized = false ) : HTMLPurifier_CSSDefinition | ||
$raw | boolean | Return a copy that has not been setup yet. Must be called before it's been setup, otherwise won't work. |
$optimized | boolean | If true, this method may return null, to indicate that a cached version of the modified definition object is available and no further edits are necessary. Consider using maybeGetRawCSSDefinition, which is more explicitly named, instead. |
return | HTMLPurifier_CSSDefinition |
/** * @param HTMLPurifier_Config $config */ public function __construct($config) { $def = $config->getCSSDefinition(); $this->info['list-style-type'] = $def->info['list-style-type']; $this->info['list-style-position'] = $def->info['list-style-position']; $this->info['list-style-image'] = $def->info['list-style-image']; }
/** * @param HTMLPurifier_Config $config */ public function __construct($config) { $def = $config->getCSSDefinition(); $this->info['border-width'] = $def->info['border-width']; $this->info['border-style'] = $def->info['border-style']; $this->info['border-top-color'] = $def->info['border-top-color']; }
/** * @param HTMLPurifier_Config $config */ public function __construct($config) { $def = $config->getCSSDefinition(); $this->info['background-color'] = $def->info['background-color']; $this->info['background-image'] = $def->info['background-image']; $this->info['background-repeat'] = $def->info['background-repeat']; $this->info['background-attachment'] = $def->info['background-attachment']; $this->info['background-position'] = $def->info['background-position']; }
/** * @param HTMLPurifier_Config $config */ public function __construct($config) { $def = $config->getCSSDefinition(); $this->info['font-style'] = $def->info['font-style']; $this->info['font-variant'] = $def->info['font-variant']; $this->info['font-weight'] = $def->info['font-weight']; $this->info['font-size'] = $def->info['font-size']; $this->info['line-height'] = $def->info['line-height']; $this->info['font-family'] = $def->info['font-family']; }
/** * @param HTMLPurifier_Config $config * @return string */ public function render($config) { $this->def = $config->getCSSDefinition(); $ret = ''; $ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer')); $ret .= $this->start('table'); $ret .= $this->element('caption', 'Properties ($info)'); $ret .= $this->start('thead'); $ret .= $this->start('tr'); $ret .= $this->element('th', 'Property', array('class' => 'heavy')); $ret .= $this->element('th', 'Definition', array('class' => 'heavy', 'style' => 'width:auto;')); $ret .= $this->end('tr'); $ret .= $this->end('thead'); ksort($this->def->info); foreach ($this->def->info as $property => $obj) { $name = $this->getClass($obj, 'AttrDef_'); $ret .= $this->row($property, $name); } $ret .= $this->end('table'); $ret .= $this->end('div'); return $ret; }
/** * @param string $css * @param HTMLPurifier_Config $config * @param HTMLPurifier_Context $context * @return bool|string */ public function validate($css, $config, $context) { $css = $this->parseCDATA($css); $definition = $config->getCSSDefinition(); // we're going to break the spec and explode by semicolons. // This is because semicolon rarely appears in escaped form // Doing this is generally flaky but fast // IT MIGHT APPEAR IN URIs, see HTMLPurifier_AttrDef_CSSURI // for details $declarations = explode(';', $css); $propvalues = array(); /** * Name of the current CSS property being validated. */ $property = false; $context->register('CurrentCSSProperty', $property); foreach ($declarations as $declaration) { if (!$declaration) { continue; } if (!strpos($declaration, ':')) { continue; } list($property, $value) = explode(':', $declaration, 2); $property = trim($property); $value = trim($value); $ok = false; do { if (isset($definition->info[$property])) { $ok = true; break; } if (ctype_lower($property)) { break; } $property = strtolower($property); if (isset($definition->info[$property])) { $ok = true; break; } } while (0); if (!$ok) { continue; } // inefficient call, since the validator will do this again if (strtolower(trim($value)) !== 'inherit') { // inherit works for everything (but only on the base property) $result = $definition->info[$property]->validate($value, $config, $context); } else { $result = 'inherit'; } if ($result === false) { continue; } $propvalues[$property] = $result; } $context->destroy('CurrentCSSProperty'); // procedure does not write the new CSS simultaneously, so it's // slightly inefficient, but it's the only way of getting rid of // duplicates. Perhaps config to optimize it, but not now. $new_declarations = ''; foreach ($propvalues as $prop => $value) { $new_declarations .= "{$prop}:{$value};"; } return $new_declarations ? $new_declarations : false; }
/** * @param string $css * @param HTMLPurifier_Config $config * @param HTMLPurifier_Context $context * @return bool|string */ public function validate($css, $config, $context) { $css = $this->parseCDATA($css); $definition = $config->getCSSDefinition(); $allow_duplicates = $config->get("CSS.AllowDuplicates"); // According to the CSS2.1 spec, the places where a // non-delimiting semicolon can appear are in strings // escape sequences. So here is some dumb hack to // handle quotes. $len = strlen($css); $accum = ""; $declarations = array(); $quoted = false; for ($i = 0; $i < $len; $i++) { $c = strcspn($css, ";'\"", $i); $accum .= substr($css, $i, $c); $i += $c; if ($i == $len) { break; } $d = $css[$i]; if ($quoted) { $accum .= $d; if ($d == $quoted) { $quoted = false; } } else { if ($d == ";") { $declarations[] = $accum; $accum = ""; } else { $accum .= $d; $quoted = $d; } } } if ($accum != "") { $declarations[] = $accum; } $propvalues = array(); $new_declarations = ''; /** * Name of the current CSS property being validated. */ $property = false; $context->register('CurrentCSSProperty', $property); foreach ($declarations as $declaration) { if (!$declaration) { continue; } if (!strpos($declaration, ':')) { continue; } list($property, $value) = explode(':', $declaration, 2); $property = trim($property); $value = trim($value); $ok = false; do { if (isset($definition->info[$property])) { $ok = true; break; } if (ctype_lower($property)) { break; } $property = strtolower($property); if (isset($definition->info[$property])) { $ok = true; break; } } while (0); if (!$ok) { continue; } // inefficient call, since the validator will do this again if (strtolower(trim($value)) !== 'inherit') { // inherit works for everything (but only on the base property) $result = $definition->info[$property]->validate($value, $config, $context); } else { $result = 'inherit'; } if ($result === false) { continue; } if ($allow_duplicates) { $new_declarations .= "{$property}:{$result};"; } else { $propvalues[$property] = $result; } } $context->destroy('CurrentCSSProperty'); // procedure does not write the new CSS simultaneously, so it's // slightly inefficient, but it's the only way of getting rid of // duplicates. Perhaps config to optimize it, but not now. foreach ($propvalues as $prop => $value) { $new_declarations .= "{$prop}:{$value};"; } return $new_declarations ? $new_declarations : false; }
/** * CSS定義を追加 * * @param HTMLPurifier_Config $config HTMLPurifier_Config instance * @return void */ private function __addCssDef(HTMLPurifier_Config $config) { if ($def = $config->getCSSDefinition()) { $def->info['position'] = new HTMLPurifier_AttrDef_Enum(array('absolute', 'fixed', 'relative', 'static')); $def->info['top'] = $def->info['bottom'] = $def->info['left'] = $def->info['right'] = new HTMLPurifier_AttrDef_CSS_Composite(array(new HTMLPurifier_AttrDef_CSS_Length(), new HTMLPurifier_AttrDef_CSS_Percentage(), new HTMLPurifier_AttrDef_Enum(array('auto')))); $def->info['z-index'] = new HTMLPurifier_AttrDef_CSS_Composite(array(new HTMLPurifier_AttrDef_CSS_Number(), new HTMLPurifier_AttrDef_Enum(array('auto')))); $def->info['direction'] = new HTMLPurifier_AttrDef_Enum(array('ltr', 'rtl')); $def->info['unicode-bidi'] = new HTMLPurifier_AttrDef_Enum(array('normal', 'embed', 'bidi-override')); $def->info['width'] = $def->info['height'] = new HTMLPurifier_AttrDef_CSS_Composite(array(new HTMLPurifier_AttrDef_CSS_Length(), new HTMLPurifier_AttrDef_CSS_Percentage(), new HTMLPurifier_AttrDef_Enum(array('auto')))); $def->info['min-width'] = $def->info['min-height'] = new HTMLPurifier_AttrDef_CSS_Composite(array(new HTMLPurifier_AttrDef_CSS_Length(), new HTMLPurifier_AttrDef_CSS_Percentage())); $def->info['max-width'] = $def->info['max-height'] = new HTMLPurifier_AttrDef_CSS_Composite(array(new HTMLPurifier_AttrDef_CSS_Length(), new HTMLPurifier_AttrDef_CSS_Percentage(), new HTMLPurifier_AttrDef_Enum(array('none')))); $def->info['text-justify'] = new HTMLPurifier_AttrDef_Enum(array('auto', 'distribute', 'distribute-all-lines', 'inter-cluster', 'inter-ideograph', 'inter-word', 'kashida', 'newspaper')); $def->info['text-underline-position'] = new HTMLPurifier_AttrDef_Enum(array('above', 'below')); $def->info['empty-cells'] = new HTMLPurifier_AttrDef_Enum(array('show', 'hide')); $def->info['cursor'] = new HTMLPurifier_AttrDef_CSS_Composite(array(new HTMLPurifier_AttrDef_Enum(array('auto', 'default', 'pointer', 'crosshair', 'move', 'text', 'wait', 'help', 'n-resize', 's-resize', 'w-resize', 'e-resize', 'ne-resize', 'nw-resize', 'se-resize', 'sw-resize', 'progress', 'hand', 'no-drop', 'all-scroll', 'col-resize', 'row-resize', 'not-allowed', 'vertical-text')), new HTMLPurifier_AttrDef_CSS_URI())); } }