ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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
 parseCDATA ($string)
 Convenience method that parses a string as if it were CDATA.
 make ($string)
 Factory method for creating this class from a string.

Protected Attributes

 $length
 HTMLPurifier_AttrDef_CSS_Length
 $percentage
 HTMLPurifier_AttrDef_CSS_Percentage

Additional Inherited Members

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

Detailed Description

Validates the value of background-position.

Definition at line 44 of file BackgroundPosition.php.

Constructor & Destructor Documentation

HTMLPurifier_AttrDef_CSS_BackgroundPosition::__construct ( )

Definition at line 57 of file BackgroundPosition.php.

{
$this->length = new HTMLPurifier_AttrDef_CSS_Length();
$this->percentage = new HTMLPurifier_AttrDef_CSS_Percentage();
}

Member Function Documentation

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

Reimplemented from HTMLPurifier_AttrDef.

Definition at line 69 of file BackgroundPosition.php.

References $ret, and HTMLPurifier_AttrDef\parseCDATA().

{
$string = $this->parseCDATA($string);
$bits = explode(' ', $string);
$keywords = array();
$keywords['h'] = false; // left, right
$keywords['v'] = false; // top, bottom
$keywords['ch'] = false; // center (first word)
$keywords['cv'] = false; // center (second word)
$measures = array();
$i = 0;
$lookup = array(
'top' => 'v',
'bottom' => 'v',
'left' => 'h',
'right' => 'h',
'center' => 'c'
);
foreach ($bits as $bit) {
if ($bit === '') {
continue;
}
// test for keyword
$lbit = ctype_lower($bit) ? $bit : strtolower($bit);
if (isset($lookup[$lbit])) {
$status = $lookup[$lbit];
if ($status == 'c') {
if ($i == 0) {
$status = 'ch';
} else {
$status = 'cv';
}
}
$keywords[$status] = $lbit;
$i++;
}
// test for length
$r = $this->length->validate($bit, $config, $context);
if ($r !== false) {
$measures[] = $r;
$i++;
}
// test for percentage
$r = $this->percentage->validate($bit, $config, $context);
if ($r !== false) {
$measures[] = $r;
$i++;
}
}
if (!$i) {
return false;
} // no valid values were caught
$ret = array();
// first keyword
if ($keywords['h']) {
$ret[] = $keywords['h'];
} elseif ($keywords['ch']) {
$ret[] = $keywords['ch'];
$keywords['cv'] = false; // prevent re-use: center = center center
} elseif (count($measures)) {
$ret[] = array_shift($measures);
}
if ($keywords['v']) {
$ret[] = $keywords['v'];
} elseif ($keywords['cv']) {
$ret[] = $keywords['cv'];
} elseif (count($measures)) {
$ret[] = array_shift($measures);
}
if (empty($ret)) {
return false;
}
return implode(' ', $ret);
}

+ Here is the call graph for this function:

Field Documentation

HTMLPurifier_AttrDef_CSS_BackgroundPosition::$length
protected
HTMLPurifier_AttrDef_CSS_BackgroundPosition::$percentage
protected

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