ILIAS  release_4-4 Revision
HTMLPurifier_AttrDef_CSS_BackgroundPosition Class Reference

Validates the value of background-position. More...

+ Inheritance diagram for HTMLPurifier_AttrDef_CSS_BackgroundPosition:
+ Collaboration diagram for HTMLPurifier_AttrDef_CSS_BackgroundPosition:

Public Member Functions

 __construct ()
 
 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

 $length
 
 $percentage
 

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 the value of background-position.

Definition at line 44 of file BackgroundPosition.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_AttrDef_CSS_BackgroundPosition::__construct ( )

Definition at line 50 of file BackgroundPosition.php.

50  {
51  $this->length = new HTMLPurifier_AttrDef_CSS_Length();
52  $this->percentage = new HTMLPurifier_AttrDef_CSS_Percentage();
53  }
Represents a Length as defined by CSS.
Definition: Length.php:6
Validates a Percentage as defined by the CSS spec.
Definition: Percentage.php:6

Member Function Documentation

◆ validate()

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

Definition at line 55 of file BackgroundPosition.php.

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

55  {
56  $string = $this->parseCDATA($string);
57  $bits = explode(' ', $string);
58 
59  $keywords = array();
60  $keywords['h'] = false; // left, right
61  $keywords['v'] = false; // top, bottom
62  $keywords['ch'] = false; // center (first word)
63  $keywords['cv'] = false; // center (second word)
64  $measures = array();
65 
66  $i = 0;
67 
68  $lookup = array(
69  'top' => 'v',
70  'bottom' => 'v',
71  'left' => 'h',
72  'right' => 'h',
73  'center' => 'c'
74  );
75 
76  foreach ($bits as $bit) {
77  if ($bit === '') continue;
78 
79  // test for keyword
80  $lbit = ctype_lower($bit) ? $bit : strtolower($bit);
81  if (isset($lookup[$lbit])) {
82  $status = $lookup[$lbit];
83  if ($status == 'c') {
84  if ($i == 0) {
85  $status = 'ch';
86  } else {
87  $status = 'cv';
88  }
89  }
90  $keywords[$status] = $lbit;
91  $i++;
92  }
93 
94  // test for length
95  $r = $this->length->validate($bit, $config, $context);
96  if ($r !== false) {
97  $measures[] = $r;
98  $i++;
99  }
100 
101  // test for percentage
102  $r = $this->percentage->validate($bit, $config, $context);
103  if ($r !== false) {
104  $measures[] = $r;
105  $i++;
106  }
107 
108  }
109 
110  if (!$i) return false; // no valid values were caught
111 
112  $ret = array();
113 
114  // first keyword
115  if ($keywords['h']) $ret[] = $keywords['h'];
116  elseif ($keywords['ch']) {
117  $ret[] = $keywords['ch'];
118  $keywords['cv'] = false; // prevent re-use: center = center center
119  }
120  elseif (count($measures)) $ret[] = array_shift($measures);
121 
122  if ($keywords['v']) $ret[] = $keywords['v'];
123  elseif ($keywords['cv']) $ret[] = $keywords['cv'];
124  elseif (count($measures)) $ret[] = array_shift($measures);
125 
126  if (empty($ret)) return false;
127  return implode(' ', $ret);
128 
129  }
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:58
$r
+ Here is the call graph for this function:

Field Documentation

◆ $length

HTMLPurifier_AttrDef_CSS_BackgroundPosition::$length
protected

Definition at line 47 of file BackgroundPosition.php.

◆ $percentage

HTMLPurifier_AttrDef_CSS_BackgroundPosition::$percentage
protected

Definition at line 48 of file BackgroundPosition.php.


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