ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
AttrDef.php
Go to the documentation of this file.
1<?php
2
14{
15
21 public $minimized = false;
22
28 public $required = false;
29
37 abstract public function validate($string, $config, $context);
38
60 public function parseCDATA($string)
61 {
62 $string = trim($string);
63 $string = str_replace(array("\n", "\t", "\r"), ' ', $string);
64 return $string;
65 }
66
72 public function make($string)
73 {
74 // default implementation, return a flyweight of this object.
75 // If $string has an effect on the returned object (i.e. you
76 // need to overload this method), it is best
77 // to clone or instantiate new copies. (Instantiation is safer.)
78 return $this;
79 }
80
87 protected function mungeRgb($string)
88 {
89 return preg_replace('/rgb\‍((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\‍)/', 'rgb(\1,\2,\3)', $string);
90 }
91
96 protected function expandCSSEscape($string)
97 {
98 // flexibly parse it
99 $ret = '';
100 for ($i = 0, $c = strlen($string); $i < $c; $i++) {
101 if ($string[$i] === '\\') {
102 $i++;
103 if ($i >= $c) {
104 $ret .= '\\';
105 break;
106 }
107 if (ctype_xdigit($string[$i])) {
108 $code = $string[$i];
109 for ($a = 1, $i++; $i < $c && $a < 6; $i++, $a++) {
110 if (!ctype_xdigit($string[$i])) {
111 break;
112 }
113 $code .= $string[$i];
114 }
115 // We have to be extremely careful when adding
116 // new characters, to make sure we're not breaking
117 // the encoding.
118 $char = HTMLPurifier_Encoder::unichr(hexdec($code));
119 if (HTMLPurifier_Encoder::cleanUTF8($char) === '') {
120 continue;
121 }
122 $ret .= $char;
123 if ($i < $c && trim($string[$i]) !== '') {
124 $i--;
125 }
126 continue;
127 }
128 if ($string[$i] === "\n") {
129 continue;
130 }
131 }
132 $ret .= $string[$i];
133 }
134 return $ret;
135 }
136}
137
138// vim: et sw=4 sts=4
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
$required
Tells us whether or not an HTML attribute is required.
Definition: AttrDef.php:28
$minimized
Tells us whether or not an HTML attribute is minimized.
Definition: AttrDef.php:21
mungeRgb($string)
Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly.
Definition: AttrDef.php:87
expandCSSEscape($string)
Parses a possibly escaped CSS string and returns the "pure" version of it.
Definition: AttrDef.php:96
make($string)
Factory method for creating this class from a string.
Definition: AttrDef.php:72
validate($string, $config, $context)
Validates and cleans passed string according to a definition.
static unichr($code)
Translates a Unicode codepoint into its corresponding UTF-8 character.
Definition: Encoder.php:309
static cleanUTF8($str, $force_php=false)
Cleans a UTF-8 string for well-formedness and SGML validity.
Definition: Encoder.php:127
$code
Definition: example_050.php:99