ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
HTMLPurifier_AttrDef_CSS_Background Class Reference

Validates shorthand CSS property background. More...

+ Inheritance diagram for HTMLPurifier_AttrDef_CSS_Background:
+ Collaboration diagram for HTMLPurifier_AttrDef_CSS_Background:

Public Member Functions

 __construct ($config)
 
 validate ($string, $config, $context)
 
- Public Member Functions inherited from HTMLPurifier_AttrDef
 validate ($string, $config, $context)
 Validates and cleans passed string according to a definition. More...
 
 parseCDATA ($string)
 Convenience method that parses a string as if it were CDATA. More...
 
 make ($string)
 Factory method for creating this class from a string. More...
 

Protected Attributes

 $info
 Local copy of component validators. More...
 

Additional Inherited Members

- Data Fields inherited from HTMLPurifier_AttrDef
 $minimized = false
 Tells us whether or not an HTML attribute is minimized. More...
 
 $required = false
 Tells us whether or not an HTML attribute is required. More...
 
- Protected Member Functions inherited from HTMLPurifier_AttrDef
 mungeRgb ($string)
 Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly. More...
 
 expandCSSEscape ($string)
 Parses a possibly escaped CSS string and returns the "pure" version of it. More...
 

Detailed Description

Validates shorthand CSS property background.

Warning
Does not support url tokens that have internal spaces.

Definition at line 7 of file Background.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_AttrDef_CSS_Background::__construct (   $config)
Parameters
HTMLPurifier_Config$config

Definition at line 20 of file Background.php.

References $config, and $def.

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  }
$def
Definition: croninfo.php:21

Member Function Documentation

◆ validate()

HTMLPurifier_AttrDef_CSS_Background::validate (   $string,
  $config,
  $context 
)
Parameters
string$string
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
bool|string

Definition at line 36 of file Background.php.

References $config, $i, $key, $r, $ret, array, HTMLPurifier_AttrDef\mungeRgb(), and HTMLPurifier_AttrDef\parseCDATA().

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  }
$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
$i
Definition: disco.tpl.php:19
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

Field Documentation

◆ $info

HTMLPurifier_AttrDef_CSS_Background::$info
protected

Local copy of component validators.

HTMLPurifier_AttrDef[]

Note
See HTMLPurifier_AttrDef_Font::$info for a similar impl.

Definition at line 15 of file Background.php.


The documentation for this class was generated from the following file: