00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00044 class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef
00045 {
00046
00047 protected $length;
00048 protected $percentage;
00049
00050 public function __construct() {
00051 $this->length = new HTMLPurifier_AttrDef_CSS_Length();
00052 $this->percentage = new HTMLPurifier_AttrDef_CSS_Percentage();
00053 }
00054
00055 public function validate($string, $config, $context) {
00056 $string = $this->parseCDATA($string);
00057 $bits = explode(' ', $string);
00058
00059 $keywords = array();
00060 $keywords['h'] = false;
00061 $keywords['v'] = false;
00062 $keywords['c'] = false;
00063 $measures = array();
00064
00065 $i = 0;
00066
00067 $lookup = array(
00068 'top' => 'v',
00069 'bottom' => 'v',
00070 'left' => 'h',
00071 'right' => 'h',
00072 'center' => 'c'
00073 );
00074
00075 foreach ($bits as $bit) {
00076 if ($bit === '') continue;
00077
00078
00079 $lbit = ctype_lower($bit) ? $bit : strtolower($bit);
00080 if (isset($lookup[$lbit])) {
00081 $status = $lookup[$lbit];
00082 $keywords[$status] = $lbit;
00083 $i++;
00084 }
00085
00086
00087 $r = $this->length->validate($bit, $config, $context);
00088 if ($r !== false) {
00089 $measures[] = $r;
00090 $i++;
00091 }
00092
00093
00094 $r = $this->percentage->validate($bit, $config, $context);
00095 if ($r !== false) {
00096 $measures[] = $r;
00097 $i++;
00098 }
00099
00100 }
00101
00102 if (!$i) return false;
00103
00104
00105 $ret = array();
00106
00107
00108 if ($keywords['h']) $ret[] = $keywords['h'];
00109 elseif (count($measures)) $ret[] = array_shift($measures);
00110 elseif ($keywords['c']) {
00111 $ret[] = $keywords['c'];
00112 $keywords['c'] = false;
00113 }
00114
00115 if ($keywords['v']) $ret[] = $keywords['v'];
00116 elseif (count($measures)) $ret[] = array_shift($measures);
00117 elseif ($keywords['c']) $ret[] = $keywords['c'];
00118
00119 if (empty($ret)) return false;
00120 return implode(' ', $ret);
00121
00122 }
00123
00124 }
00125