ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
CSS.php
Go to the documentation of this file.
1<?php
2
15{
16
23 public function validate($css, $config, $context)
24 {
25 $css = $this->parseCDATA($css);
26
27 $definition = $config->getCSSDefinition();
28 $allow_duplicates = $config->get("CSS.AllowDuplicates");
29
30 // we're going to break the spec and explode by semicolons.
31 // This is because semicolon rarely appears in escaped form
32 // Doing this is generally flaky but fast
33 // IT MIGHT APPEAR IN URIs, see HTMLPurifier_AttrDef_CSSURI
34 // for details
35
36 $declarations = explode(';', $css);
37 $propvalues = array();
38 $new_declarations = '';
39
43 $property = false;
44 $context->register('CurrentCSSProperty', $property);
45
46 foreach ($declarations as $declaration) {
47 if (!$declaration) {
48 continue;
49 }
50 if (!strpos($declaration, ':')) {
51 continue;
52 }
53 list($property, $value) = explode(':', $declaration, 2);
54 $property = trim($property);
55 $value = trim($value);
56 $ok = false;
57 do {
58 if (isset($definition->info[$property])) {
59 $ok = true;
60 break;
61 }
62 if (ctype_lower($property)) {
63 break;
64 }
65 $property = strtolower($property);
66 if (isset($definition->info[$property])) {
67 $ok = true;
68 break;
69 }
70 } while (0);
71 if (!$ok) {
72 continue;
73 }
74 // inefficient call, since the validator will do this again
75 if (strtolower(trim($value)) !== 'inherit') {
76 // inherit works for everything (but only on the base property)
77 $result = $definition->info[$property]->validate(
78 $value,
79 $config,
80 $context
81 );
82 } else {
83 $result = 'inherit';
84 }
85 if ($result === false) {
86 continue;
87 }
88 if ($allow_duplicates) {
89 $new_declarations .= "$property:$result;";
90 } else {
91 $propvalues[$property] = $result;
92 }
93 }
94
95 $context->destroy('CurrentCSSProperty');
96
97 // procedure does not write the new CSS simultaneously, so it's
98 // slightly inefficient, but it's the only way of getting rid of
99 // duplicates. Perhaps config to optimize it, but not now.
100
101 foreach ($propvalues as $prop => $value) {
102 $new_declarations .= "$prop:$value;";
103 }
104
105 return $new_declarations ? $new_declarations : false;
106
107 }
108
109}
110
111// vim: et sw=4 sts=4
$result
An exception for terminatinating execution or to throw for unit testing.
Validates the HTML attribute style, otherwise known as CSS.
Definition: CSS.php:15
validate($css, $config, $context)
Definition: CSS.php:23
Base class for all validating attribute definitions.
Definition: AttrDef.php:14
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:60