1: | <?php
|
2: |
|
3: | |
4: | |
5: |
|
6: | class HTMLPurifier_AttrDef_CSS_Length extends HTMLPurifier_AttrDef
|
7: | {
|
8: |
|
9: | |
10: | |
11: |
|
12: | protected $min;
|
13: |
|
14: | |
15: | |
16: |
|
17: | protected $max;
|
18: |
|
19: | |
20: | |
21: | |
22: |
|
23: | public function __construct($min = null, $max = null)
|
24: | {
|
25: | $this->min = $min !== null ? HTMLPurifier_Length::make($min) : null;
|
26: | $this->max = $max !== null ? HTMLPurifier_Length::make($max) : null;
|
27: | }
|
28: |
|
29: | |
30: | |
31: | |
32: | |
33: | |
34: |
|
35: | public function validate($string, $config, $context)
|
36: | {
|
37: | $string = $this->parseCDATA($string);
|
38: |
|
39: |
|
40: | if ($string === '') {
|
41: | return false;
|
42: | }
|
43: | if ($string === '0') {
|
44: | return '0';
|
45: | }
|
46: | if (strlen($string) === 1) {
|
47: | return false;
|
48: | }
|
49: |
|
50: | $length = HTMLPurifier_Length::make($string);
|
51: | if (!$length->isValid()) {
|
52: | return false;
|
53: | }
|
54: |
|
55: | if ($this->min) {
|
56: | $c = $length->compareTo($this->min);
|
57: | if ($c === false) {
|
58: | return false;
|
59: | }
|
60: | if ($c < 0) {
|
61: | return false;
|
62: | }
|
63: | }
|
64: | if ($this->max) {
|
65: | $c = $length->compareTo($this->max);
|
66: | if ($c === false) {
|
67: | return false;
|
68: | }
|
69: | if ($c > 0) {
|
70: | return false;
|
71: | }
|
72: | }
|
73: | return $length->toString();
|
74: | }
|
75: | }
|
76: |
|
77: |
|
78: | |