HTMLPurifier/AttrDef/CSS/Filter.php Quellcode

Filter.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
9 {
13  protected $intValidator;
14 
15  public function __construct()
16  {
17  $this->intValidator = new HTMLPurifier_AttrDef_Integer();
18  }
19 
26  public function validate($value, $config, $context)
27  {
28  $value = $this->parseCDATA($value);
29  if ($value === 'none') {
30  return $value;
31  }
32  // if we looped this we could support multiple filters
33  $function_length = strcspn($value, '(');
34  $function = trim(substr($value, 0, $function_length));
35  if ($function !== 'alpha' &&
36  $function !== 'Alpha' &&
37  $function !== 'progid:DXImageTransform.Microsoft.Alpha'
38  ) {
39  return false;
40  }
41  $cursor = $function_length + 1;
42  $parameters_length = strcspn($value, ')', $cursor);
43  $parameters = substr($value, $cursor, $parameters_length);
44  $params = explode(',', $parameters);
45  $ret_params = array();
46  $lookup = array();
47  foreach ($params as $param) {
48  list($key, $value) = explode('=', $param);
49  $key = trim($key);
50  $value = trim($value);
51  if (isset($lookup[$key])) {
52  continue;
53  }
54  if ($key !== 'opacity') {
55  continue;
56  }
57  $value = $this->intValidator->validate($value, $config, $context);
58  if ($value === false) {
59  continue;
60  }
61  $int = (int)$value;
62  if ($int > 100) {
63  $value = '100';
64  }
65  if ($int < 0) {
66  $value = '0';
67  }
68  $ret_params[] = "$key=$value";
69  $lookup[$key] = true;
70  }
71  $ret_parameters = implode(',', $ret_params);
72  $ret_function = "$function($ret_parameters)";
73  return $ret_function;
74  }
75 }
76 
77 // vim: et sw=4 sts=4




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.