ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
 HTMLPurifier_AttrDef_CSS_Length More...
 
 $percentage
 HTMLPurifier_AttrDef_CSS_Percentage 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 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 57 of file BackgroundPosition.php.

58  {
59  $this->length = new HTMLPurifier_AttrDef_CSS_Length();
60  $this->percentage = new HTMLPurifier_AttrDef_CSS_Percentage();
61  }
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 
)
Parameters
string$string
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
bool|string

Definition at line 69 of file BackgroundPosition.php.

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

70  {
71  $string = $this->parseCDATA($string);
72  $bits = explode(' ', $string);
73 
74  $keywords = array();
75  $keywords['h'] = false; // left, right
76  $keywords['v'] = false; // top, bottom
77  $keywords['ch'] = false; // center (first word)
78  $keywords['cv'] = false; // center (second word)
79  $measures = array();
80 
81  $i = 0;
82 
83  $lookup = array(
84  'top' => 'v',
85  'bottom' => 'v',
86  'left' => 'h',
87  'right' => 'h',
88  'center' => 'c'
89  );
90 
91  foreach ($bits as $bit) {
92  if ($bit === '') {
93  continue;
94  }
95 
96  // test for keyword
97  $lbit = ctype_lower($bit) ? $bit : strtolower($bit);
98  if (isset($lookup[$lbit])) {
99  $status = $lookup[$lbit];
100  if ($status == 'c') {
101  if ($i == 0) {
102  $status = 'ch';
103  } else {
104  $status = 'cv';
105  }
106  }
107  $keywords[$status] = $lbit;
108  $i++;
109  }
110 
111  // test for length
112  $r = $this->length->validate($bit, $config, $context);
113  if ($r !== false) {
114  $measures[] = $r;
115  $i++;
116  }
117 
118  // test for percentage
119  $r = $this->percentage->validate($bit, $config, $context);
120  if ($r !== false) {
121  $measures[] = $r;
122  $i++;
123  }
124  }
125 
126  if (!$i) {
127  return false;
128  } // no valid values were caught
129 
130  $ret = array();
131 
132  // first keyword
133  if ($keywords['h']) {
134  $ret[] = $keywords['h'];
135  } elseif ($keywords['ch']) {
136  $ret[] = $keywords['ch'];
137  $keywords['cv'] = false; // prevent re-use: center = center center
138  } elseif (count($measures)) {
139  $ret[] = array_shift($measures);
140  }
141 
142  if ($keywords['v']) {
143  $ret[] = $keywords['v'];
144  } elseif ($keywords['cv']) {
145  $ret[] = $keywords['cv'];
146  } elseif (count($measures)) {
147  $ret[] = array_shift($measures);
148  }
149 
150  if (empty($ret)) {
151  return false;
152  }
153  return implode(' ', $ret);
154  }
$context
Definition: webdav.php:25
$config
Definition: bootstrap.php:15
$r
Definition: example_031.php:79
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:60
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:

Field Documentation

◆ $length

HTMLPurifier_AttrDef_CSS_BackgroundPosition::$length
protected

◆ $percentage

HTMLPurifier_AttrDef_CSS_BackgroundPosition::$percentage
protected

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