HTMLPurifier/AttrDef/CSS.php Quellcode

CSS.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
15 {
16 
23  public function validate($css, $config, $context)
24  {
25  $css = $this->parseCDATA($css);
26 
27  $definition = $config->getCSSDefinition();
28 
29  // we're going to break the spec and explode by semicolons.
30  // This is because semicolon rarely appears in escaped form
31  // Doing this is generally flaky but fast
32  // IT MIGHT APPEAR IN URIs, see HTMLPurifier_AttrDef_CSSURI
33  // for details
34 
35  $declarations = explode(';', $css);
36  $propvalues = array();
37 
41  $property = false;
42  $context->register('CurrentCSSProperty', $property);
43 
44  foreach ($declarations as $declaration) {
45  if (!$declaration) {
46  continue;
47  }
48  if (!strpos($declaration, ':')) {
49  continue;
50  }
51  list($property, $value) = explode(':', $declaration, 2);
52  $property = trim($property);
53  $value = trim($value);
54  $ok = false;
55  do {
56  if (isset($definition->info[$property])) {
57  $ok = true;
58  break;
59  }
60  if (ctype_lower($property)) {
61  break;
62  }
63  $property = strtolower($property);
64  if (isset($definition->info[$property])) {
65  $ok = true;
66  break;
67  }
68  } while (0);
69  if (!$ok) {
70  continue;
71  }
72  // inefficient call, since the validator will do this again
73  if (strtolower(trim($value)) !== 'inherit') {
74  // inherit works for everything (but only on the base property)
75  $result = $definition->info[$property]->validate(
76  $value,
77  $config,
78  $context
79  );
80  } else {
81  $result = 'inherit';
82  }
83  if ($result === false) {
84  continue;
85  }
86  $propvalues[$property] = $result;
87  }
88 
89  $context->destroy('CurrentCSSProperty');
90 
91  // procedure does not write the new CSS simultaneously, so it's
92  // slightly inefficient, but it's the only way of getting rid of
93  // duplicates. Perhaps config to optimize it, but not now.
94 
95  $new_declarations = '';
96  foreach ($propvalues as $prop => $value) {
97  $new_declarations .= "$prop:$value;";
98  }
99 
100  return $new_declarations ? $new_declarations : false;
101 
102  }
103 
104 }
105 
106 // 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.