ILIAS  Release_4_4_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 
20  public $minimized = false;
21 
26  public $required = false;
27 
35  abstract public function validate($string, $config, $context);
36 
58  public function parseCDATA($string) {
59  $string = trim($string);
60  $string = str_replace(array("\n", "\t", "\r"), ' ', $string);
61  return $string;
62  }
63 
69  public function make($string) {
70  // default implementation, return a flyweight of this object.
71  // If $string has an effect on the returned object (i.e. you
72  // need to overload this method), it is best
73  // to clone or instantiate new copies. (Instantiation is safer.)
74  return $this;
75  }
76 
81  protected function mungeRgb($string) {
82  return preg_replace('/rgb\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\)/', 'rgb(\1,\2,\3)', $string);
83  }
84 
89  protected function expandCSSEscape($string) {
90  // flexibly parse it
91  $ret = '';
92  for ($i = 0, $c = strlen($string); $i < $c; $i++) {
93  if ($string[$i] === '\\') {
94  $i++;
95  if ($i >= $c) {
96  $ret .= '\\';
97  break;
98  }
99  if (ctype_xdigit($string[$i])) {
100  $code = $string[$i];
101  for ($a = 1, $i++; $i < $c && $a < 6; $i++, $a++) {
102  if (!ctype_xdigit($string[$i])) break;
103  $code .= $string[$i];
104  }
105  // We have to be extremely careful when adding
106  // new characters, to make sure we're not breaking
107  // the encoding.
108  $char = HTMLPurifier_Encoder::unichr(hexdec($code));
109  if (HTMLPurifier_Encoder::cleanUTF8($char) === '') continue;
110  $ret .= $char;
111  if ($i < $c && trim($string[$i]) !== '') $i--;
112  continue;
113  }
114  if ($string[$i] === "\n") continue;
115  }
116  $ret .= $string[$i];
117  }
118  return $ret;
119  }
120 
121 }
122 
123 // vim: et sw=4 sts=4