| 1: | <?php
|
| 2: |
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: |
|
| 28: |
|
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: |
|
| 37: |
|
| 38: |
|
| 39: |
|
| 40: |
|
| 41: | |
| 42: | |
| 43: |
|
| 44: | class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef
|
| 45: | {
|
| 46: |
|
| 47: | |
| 48: | |
| 49: |
|
| 50: | protected $length;
|
| 51: |
|
| 52: | |
| 53: | |
| 54: |
|
| 55: | protected $percentage;
|
| 56: |
|
| 57: | public function __construct()
|
| 58: | {
|
| 59: | $this->length = new HTMLPurifier_AttrDef_CSS_Length();
|
| 60: | $this->percentage = new HTMLPurifier_AttrDef_CSS_Percentage();
|
| 61: | }
|
| 62: |
|
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: |
|
| 69: | public function validate($string, $config, $context)
|
| 70: | {
|
| 71: | $string = $this->parseCDATA($string);
|
| 72: | $bits = explode(' ', $string);
|
| 73: |
|
| 74: | $keywords = array();
|
| 75: | $keywords['h'] = false;
|
| 76: | $keywords['v'] = false;
|
| 77: | $keywords['ch'] = false;
|
| 78: | $keywords['cv'] = false;
|
| 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: |
|
| 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: |
|
| 112: | $r = $this->length->validate($bit, $config, $context);
|
| 113: | if ($r !== false) {
|
| 114: | $measures[] = $r;
|
| 115: | $i++;
|
| 116: | }
|
| 117: |
|
| 118: |
|
| 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: | }
|
| 129: |
|
| 130: | $ret = array();
|
| 131: |
|
| 132: |
|
| 133: | if ($keywords['h']) {
|
| 134: | $ret[] = $keywords['h'];
|
| 135: | } elseif ($keywords['ch']) {
|
| 136: | $ret[] = $keywords['ch'];
|
| 137: | $keywords['cv'] = false;
|
| 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: | }
|
| 155: | }
|
| 156: |
|
| 157: |
|
| 158: | |