ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  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