ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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)

Definition at line 16 of file Background.php.

16  {
17  $def = $config->getCSSDefinition();
18  $this->info['background-color'] = $def->info['background-color'];
19  $this->info['background-image'] = $def->info['background-image'];
20  $this->info['background-repeat'] = $def->info['background-repeat'];
21  $this->info['background-attachment'] = $def->info['background-attachment'];
22  $this->info['background-position'] = $def->info['background-position'];
23  }

Member Function Documentation

◆ validate()

HTMLPurifier_AttrDef_CSS_Background::validate (   $string,
  $config,
  $context 
)

Definition at line 25 of file Background.php.

References $r, $ret, HTMLPurifier_AttrDef\mungeRgb(), and HTMLPurifier_AttrDef\parseCDATA().

25  {
26 
27  // regular pre-processing
28  $string = $this->parseCDATA($string);
29  if ($string === '') return false;
30 
31  // munge rgb() decl if necessary
32  $string = $this->mungeRgb($string);
33 
34  // assumes URI doesn't have spaces in it
35  $bits = explode(' ', $string); // bits to process
36 
37  $caught = array();
38  $caught['color'] = false;
39  $caught['image'] = false;
40  $caught['repeat'] = false;
41  $caught['attachment'] = false;
42  $caught['position'] = false;
43 
44  $i = 0; // number of catches
45  $none = false;
46 
47  foreach ($bits as $bit) {
48  if ($bit === '') continue;
49  foreach ($caught as $key => $status) {
50  if ($key != 'position') {
51  if ($status !== false) continue;
52  $r = $this->info['background-' . $key]->validate($bit, $config, $context);
53  } else {
54  $r = $bit;
55  }
56  if ($r === false) continue;
57  if ($key == 'position') {
58  if ($caught[$key] === false) $caught[$key] = '';
59  $caught[$key] .= $r . ' ';
60  } else {
61  $caught[$key] = $r;
62  }
63  $i++;
64  break;
65  }
66  }
67 
68  if (!$i) return false;
69  if ($caught['position'] !== false) {
70  $caught['position'] = $this->info['background-position']->
71  validate($caught['position'], $config, $context);
72  }
73 
74  $ret = array();
75  foreach ($caught as $value) {
76  if ($value === false) continue;
77  $ret[] = $value;
78  }
79 
80  if (empty($ret)) return false;
81  return implode(' ', $ret);
82 
83  }
validate($string, $config, $context)
Definition: Background.php:25
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:58
mungeRgb($string)
Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly.
Definition: AttrDef.php:81
$r
+ Here is the call graph for this function:

Field Documentation

◆ $info

HTMLPurifier_AttrDef_CSS_Background::$info
protected

Local copy of component validators.

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

Definition at line 14 of file Background.php.


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