HTMLPurifier/AttrDef/CSS/Background.php Quellcode

Background.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
8 {
9 
15  protected $info;
16 
20  public function __construct($config)
21  {
22  $def = $config->getCSSDefinition();
23  $this->info['background-color'] = $def->info['background-color'];
24  $this->info['background-image'] = $def->info['background-image'];
25  $this->info['background-repeat'] = $def->info['background-repeat'];
26  $this->info['background-attachment'] = $def->info['background-attachment'];
27  $this->info['background-position'] = $def->info['background-position'];
28  }
29 
36  public function validate($string, $config, $context)
37  {
38  // regular pre-processing
39  $string = $this->parseCDATA($string);
40  if ($string === '') {
41  return false;
42  }
43 
44  // munge rgb() decl if necessary
45  $string = $this->mungeRgb($string);
46 
47  // assumes URI doesn't have spaces in it
48  $bits = explode(' ', $string); // bits to process
49 
50  $caught = array();
51  $caught['color'] = false;
52  $caught['image'] = false;
53  $caught['repeat'] = false;
54  $caught['attachment'] = false;
55  $caught['position'] = false;
56 
57  $i = 0; // number of catches
58 
59  foreach ($bits as $bit) {
60  if ($bit === '') {
61  continue;
62  }
63  foreach ($caught as $key => $status) {
64  if ($key != 'position') {
65  if ($status !== false) {
66  continue;
67  }
68  $r = $this->info['background-' . $key]->validate($bit, $config, $context);
69  } else {
70  $r = $bit;
71  }
72  if ($r === false) {
73  continue;
74  }
75  if ($key == 'position') {
76  if ($caught[$key] === false) {
77  $caught[$key] = '';
78  }
79  $caught[$key] .= $r . ' ';
80  } else {
81  $caught[$key] = $r;
82  }
83  $i++;
84  break;
85  }
86  }
87 
88  if (!$i) {
89  return false;
90  }
91  if ($caught['position'] !== false) {
92  $caught['position'] = $this->info['background-position']->
93  validate($caught['position'], $config, $context);
94  }
95 
96  $ret = array();
97  foreach ($caught as $value) {
98  if ($value === false) {
99  continue;
100  }
101  $ret[] = $value;
102  }
103 
104  if (empty($ret)) {
105  return false;
106  }
107  return implode(' ', $ret);
108  }
109 }
110 
111 // 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.