ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AttrDef.php
Go to the documentation of this file.
1 <?php
2 
13 abstract class HTMLPurifier_AttrDef
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  $p = '\s*(\d+(\.\d+)?([%]?))\s*';
90 
91  if (preg_match('/(rgba|hsla)\(/', $string)) {
92  return preg_replace('/(rgba|hsla)\('.$p.','.$p.','.$p.','.$p.'\)/', '\1(\2,\5,\8,\11)', $string);
93  }
94 
95  return preg_replace('/(rgb|hsl)\('.$p.','.$p.','.$p.'\)/', '\1(\2,\5,\8)', $string);
96  }
97 
102  protected function expandCSSEscape($string)
103  {
104  // flexibly parse it
105  $ret = '';
106  for ($i = 0, $c = strlen($string); $i < $c; $i++) {
107  if ($string[$i] === '\\') {
108  $i++;
109  if ($i >= $c) {
110  $ret .= '\\';
111  break;
112  }
113  if (ctype_xdigit($string[$i])) {
114  $code = $string[$i];
115  for ($a = 1, $i++; $i < $c && $a < 6; $i++, $a++) {
116  if (!ctype_xdigit($string[$i])) {
117  break;
118  }
119  $code .= $string[$i];
120  }
121  // We have to be extremely careful when adding
122  // new characters, to make sure we're not breaking
123  // the encoding.
124  $char = HTMLPurifier_Encoder::unichr(hexdec($code));
125  if (HTMLPurifier_Encoder::cleanUTF8($char) === '') {
126  continue;
127  }
128  $ret .= $char;
129  if ($i < $c && trim($string[$i]) !== '') {
130  $i--;
131  }
132  continue;
133  }
134  if ($string[$i] === "\n") {
135  continue;
136  }
137  }
138  $ret .= $string[$i];
139  }
140  return $ret;
141  }
142 }
143 
144 // vim: et sw=4 sts=4
$context
Definition: webdav.php:25
Base class for all validating attribute definitions.
Definition: AttrDef.php:13
$config
Definition: bootstrap.php:15
$code
Definition: example_050.php:99
static unichr($code)
Translates a Unicode codepoint into its corresponding UTF-8 character.
Definition: Encoder.php:315
static cleanUTF8($str, $force_php=false)
Cleans a UTF-8 string for well-formedness and SGML validity.
Definition: Encoder.php:134
validate($string, $config, $context)
Validates and cleans passed string according to a definition.
make($string)
Factory method for creating this class from a string.
Definition: AttrDef.php:72
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:60
expandCSSEscape($string)
Parses a possibly escaped CSS string and returns the "pure" version of it.
Definition: AttrDef.php:102
$minimized
Tells us whether or not an HTML attribute is minimized.
Definition: AttrDef.php:21
$required
Tells us whether or not an HTML attribute is required.
Definition: AttrDef.php:28
mungeRgb($string)
Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly.
Definition: AttrDef.php:87
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19