ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
Background.php
Go to the documentation of this file.
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
Base class for all validating attribute definitions.
Definition: AttrDef.php:13
Validates shorthand CSS property background.
Definition: Background.php:7
$r
Definition: example_031.php:79
validate($string, $config, $context)
Definition: Background.php:36
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:60
Create styles array
The data for the language used.
mungeRgb($string)
Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly.
Definition: AttrDef.php:87
$ret
Definition: parser.php:6
$info
Local copy of component validators.
Definition: Background.php:15