GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b119a5...2262ef )
by gyeong-won
19:32 queued 13:26
created
classes/security/htmlpurifier/library/HTMLPurifier/Bootstrap.php 3 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -2,22 +2,22 @@  discard block
 block discarded – undo
2 2
 
3 3
 // constants are slow, so we use as few as possible
4 4
 if (!defined('HTMLPURIFIER_PREFIX')) {
5
-    define('HTMLPURIFIER_PREFIX', realpath(dirname(__FILE__) . '/..'));
5
+	define('HTMLPURIFIER_PREFIX', realpath(dirname(__FILE__) . '/..'));
6 6
 }
7 7
 
8 8
 // accomodations for versions earlier than 5.0.2
9 9
 // borrowed from PHP_Compat, LGPL licensed, by Aidan Lister <[email protected]>
10 10
 if (!defined('PHP_EOL')) {
11
-    switch (strtoupper(substr(PHP_OS, 0, 3))) {
12
-        case 'WIN':
13
-            define('PHP_EOL', "\r\n");
14
-            break;
15
-        case 'DAR':
16
-            define('PHP_EOL', "\r");
17
-            break;
18
-        default:
19
-            define('PHP_EOL', "\n");
20
-    }
11
+	switch (strtoupper(substr(PHP_OS, 0, 3))) {
12
+		case 'WIN':
13
+			define('PHP_EOL', "\r\n");
14
+			break;
15
+		case 'DAR':
16
+			define('PHP_EOL', "\r");
17
+			break;
18
+		default:
19
+			define('PHP_EOL', "\n");
20
+	}
21 21
 }
22 22
 
23 23
 /**
@@ -30,56 +30,56 @@  discard block
 block discarded – undo
30 30
 class HTMLPurifier_Bootstrap
31 31
 {
32 32
 
33
-    /**
34
-     * Autoload function for HTML Purifier
35
-     * @param $class Class to load
36
-     */
37
-    public static function autoload($class) {
38
-        $file = HTMLPurifier_Bootstrap::getPath($class);
39
-        if (!$file) return false;
40
-        // Technically speaking, it should be ok and more efficient to
41
-        // just do 'require', but Antonio Parraga reports that with
42
-        // Zend extensions such as Zend debugger and APC, this invariant
43
-        // may be broken.  Since we have efficient alternatives, pay
44
-        // the cost here and avoid the bug.
45
-        require_once HTMLPURIFIER_PREFIX . '/' . $file;
46
-        return true;
47
-    }
33
+	/**
34
+	 * Autoload function for HTML Purifier
35
+	 * @param $class Class to load
36
+	 */
37
+	public static function autoload($class) {
38
+		$file = HTMLPurifier_Bootstrap::getPath($class);
39
+		if (!$file) return false;
40
+		// Technically speaking, it should be ok and more efficient to
41
+		// just do 'require', but Antonio Parraga reports that with
42
+		// Zend extensions such as Zend debugger and APC, this invariant
43
+		// may be broken.  Since we have efficient alternatives, pay
44
+		// the cost here and avoid the bug.
45
+		require_once HTMLPURIFIER_PREFIX . '/' . $file;
46
+		return true;
47
+	}
48 48
 
49
-    /**
50
-     * Returns the path for a specific class.
51
-     */
52
-    public static function getPath($class) {
53
-        if (strncmp('HTMLPurifier', $class, 12) !== 0) return false;
54
-        // Custom implementations
55
-        if (strncmp('HTMLPurifier_Language_', $class, 22) === 0) {
56
-            $code = str_replace('_', '-', substr($class, 22));
57
-            $file = 'HTMLPurifier/Language/classes/' . $code . '.php';
58
-        } else {
59
-            $file = str_replace('_', '/', $class) . '.php';
60
-        }
61
-        if (!file_exists(HTMLPURIFIER_PREFIX . '/' . $file)) return false;
62
-        return $file;
63
-    }
49
+	/**
50
+	 * Returns the path for a specific class.
51
+	 */
52
+	public static function getPath($class) {
53
+		if (strncmp('HTMLPurifier', $class, 12) !== 0) return false;
54
+		// Custom implementations
55
+		if (strncmp('HTMLPurifier_Language_', $class, 22) === 0) {
56
+			$code = str_replace('_', '-', substr($class, 22));
57
+			$file = 'HTMLPurifier/Language/classes/' . $code . '.php';
58
+		} else {
59
+			$file = str_replace('_', '/', $class) . '.php';
60
+		}
61
+		if (!file_exists(HTMLPURIFIER_PREFIX . '/' . $file)) return false;
62
+		return $file;
63
+	}
64 64
 
65
-    /**
66
-     * "Pre-registers" our autoloader on the SPL stack.
67
-     */
68
-    public static function registerAutoload() {
69
-        $autoload = array('HTMLPurifier_Bootstrap', 'autoload');
70
-        if ( ($funcs = spl_autoload_functions()) === false ) {
71
-            spl_autoload_register($autoload);
72
-        } elseif (function_exists('spl_autoload_unregister')) {
73
-            $buggy  = version_compare(PHP_VERSION, '5.2.11', '<');
74
-            $compat = version_compare(PHP_VERSION, '5.1.2', '<=') &&
75
-                      version_compare(PHP_VERSION, '5.1.0', '>=');
76
-            foreach ($funcs as $func) {
77
-                if ($buggy && is_array($func)) {
78
-                    // :TRICKY: There are some compatibility issues and some
79
-                    // places where we need to error out
80
-                    $reflector = new ReflectionMethod($func[0], $func[1]);
81
-                    if (!$reflector->isStatic()) {
82
-                        throw new Exception('
65
+	/**
66
+	 * "Pre-registers" our autoloader on the SPL stack.
67
+	 */
68
+	public static function registerAutoload() {
69
+		$autoload = array('HTMLPurifier_Bootstrap', 'autoload');
70
+		if ( ($funcs = spl_autoload_functions()) === false ) {
71
+			spl_autoload_register($autoload);
72
+		} elseif (function_exists('spl_autoload_unregister')) {
73
+			$buggy  = version_compare(PHP_VERSION, '5.2.11', '<');
74
+			$compat = version_compare(PHP_VERSION, '5.1.2', '<=') &&
75
+					  version_compare(PHP_VERSION, '5.1.0', '>=');
76
+			foreach ($funcs as $func) {
77
+				if ($buggy && is_array($func)) {
78
+					// :TRICKY: There are some compatibility issues and some
79
+					// places where we need to error out
80
+					$reflector = new ReflectionMethod($func[0], $func[1]);
81
+					if (!$reflector->isStatic()) {
82
+						throw new Exception('
83 83
                             HTML Purifier autoloader registrar is not compatible
84 84
                             with non-static object methods due to PHP Bug #44144;
85 85
                             Please do not use HTMLPurifier.autoload.php (or any
@@ -87,17 +87,17 @@  discard block
 block discarded – undo
87 87
                             spl_autoload_register(array(\'HTMLPurifier_Bootstrap\', \'autoload\'))
88 88
                             after your own autoloaders.
89 89
                         ');
90
-                    }
91
-                    // Suprisingly, spl_autoload_register supports the
92
-                    // Class::staticMethod callback format, although call_user_func doesn't
93
-                    if ($compat) $func = implode('::', $func);
94
-                }
95
-                spl_autoload_unregister($func);
96
-            }
97
-            spl_autoload_register($autoload);
98
-            foreach ($funcs as $func) spl_autoload_register($func);
99
-        }
100
-    }
90
+					}
91
+					// Suprisingly, spl_autoload_register supports the
92
+					// Class::staticMethod callback format, although call_user_func doesn't
93
+					if ($compat) $func = implode('::', $func);
94
+				}
95
+				spl_autoload_unregister($func);
96
+			}
97
+			spl_autoload_register($autoload);
98
+			foreach ($funcs as $func) spl_autoload_register($func);
99
+		}
100
+	}
101 101
 
102 102
 }
103 103
 
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -36,7 +36,9 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public static function autoload($class) {
38 38
         $file = HTMLPurifier_Bootstrap::getPath($class);
39
-        if (!$file) return false;
39
+        if (!$file) {
40
+        	return false;
41
+        }
40 42
         // Technically speaking, it should be ok and more efficient to
41 43
         // just do 'require', but Antonio Parraga reports that with
42 44
         // Zend extensions such as Zend debugger and APC, this invariant
@@ -50,7 +52,9 @@  discard block
 block discarded – undo
50 52
      * Returns the path for a specific class.
51 53
      */
52 54
     public static function getPath($class) {
53
-        if (strncmp('HTMLPurifier', $class, 12) !== 0) return false;
55
+        if (strncmp('HTMLPurifier', $class, 12) !== 0) {
56
+        	return false;
57
+        }
54 58
         // Custom implementations
55 59
         if (strncmp('HTMLPurifier_Language_', $class, 22) === 0) {
56 60
             $code = str_replace('_', '-', substr($class, 22));
@@ -58,7 +62,9 @@  discard block
 block discarded – undo
58 62
         } else {
59 63
             $file = str_replace('_', '/', $class) . '.php';
60 64
         }
61
-        if (!file_exists(HTMLPURIFIER_PREFIX . '/' . $file)) return false;
65
+        if (!file_exists(HTMLPURIFIER_PREFIX . '/' . $file)) {
66
+        	return false;
67
+        }
62 68
         return $file;
63 69
     }
64 70
 
@@ -90,12 +96,16 @@  discard block
 block discarded – undo
90 96
                     }
91 97
                     // Suprisingly, spl_autoload_register supports the
92 98
                     // Class::staticMethod callback format, although call_user_func doesn't
93
-                    if ($compat) $func = implode('::', $func);
99
+                    if ($compat) {
100
+                    	$func = implode('::', $func);
101
+                    }
94 102
                 }
95 103
                 spl_autoload_unregister($func);
96 104
             }
97 105
             spl_autoload_register($autoload);
98
-            foreach ($funcs as $func) spl_autoload_register($func);
106
+            foreach ($funcs as $func) {
107
+            	spl_autoload_register($func);
108
+            }
99 109
         }
100 110
     }
101 111
 
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 // constants are slow, so we use as few as possible
4 4
 if (!defined('HTMLPURIFIER_PREFIX')) {
5
-    define('HTMLPURIFIER_PREFIX', realpath(dirname(__FILE__) . '/..'));
5
+    define('HTMLPURIFIER_PREFIX', realpath(dirname(__FILE__).'/..'));
6 6
 }
7 7
 
8 8
 // accomodations for versions earlier than 5.0.2
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
         // Zend extensions such as Zend debugger and APC, this invariant
43 43
         // may be broken.  Since we have efficient alternatives, pay
44 44
         // the cost here and avoid the bug.
45
-        require_once HTMLPURIFIER_PREFIX . '/' . $file;
45
+        require_once HTMLPURIFIER_PREFIX.'/'.$file;
46 46
         return true;
47 47
     }
48 48
 
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
         // Custom implementations
55 55
         if (strncmp('HTMLPurifier_Language_', $class, 22) === 0) {
56 56
             $code = str_replace('_', '-', substr($class, 22));
57
-            $file = 'HTMLPurifier/Language/classes/' . $code . '.php';
57
+            $file = 'HTMLPurifier/Language/classes/'.$code.'.php';
58 58
         } else {
59
-            $file = str_replace('_', '/', $class) . '.php';
59
+            $file = str_replace('_', '/', $class).'.php';
60 60
         }
61
-        if (!file_exists(HTMLPURIFIER_PREFIX . '/' . $file)) return false;
61
+        if (!file_exists(HTMLPURIFIER_PREFIX.'/'.$file)) return false;
62 62
         return $file;
63 63
     }
64 64
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      */
68 68
     public static function registerAutoload() {
69 69
         $autoload = array('HTMLPurifier_Bootstrap', 'autoload');
70
-        if ( ($funcs = spl_autoload_functions()) === false ) {
70
+        if (($funcs = spl_autoload_functions()) === false) {
71 71
             spl_autoload_register($autoload);
72 72
         } elseif (function_exists('spl_autoload_unregister')) {
73 73
             $buggy  = version_compare(PHP_VERSION, '5.2.11', '<');
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/CSSDefinition.php 3 patches
Indentation   +310 added lines, -310 removed lines patch added patch discarded remove patch
@@ -7,316 +7,316 @@
 block discarded – undo
7 7
 class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition
8 8
 {
9 9
 
10
-    public $type = 'CSS';
11
-
12
-    /**
13
-     * Assoc array of attribute name to definition object.
14
-     */
15
-    public $info = array();
16
-
17
-    /**
18
-     * Constructs the info array.  The meat of this class.
19
-     */
20
-    protected function doSetup($config) {
21
-
22
-        $this->info['text-align'] = new HTMLPurifier_AttrDef_Enum(
23
-            array('left', 'right', 'center', 'justify'), false);
24
-
25
-        $border_style =
26
-        $this->info['border-bottom-style'] =
27
-        $this->info['border-right-style'] =
28
-        $this->info['border-left-style'] =
29
-        $this->info['border-top-style'] =  new HTMLPurifier_AttrDef_Enum(
30
-            array('none', 'hidden', 'dotted', 'dashed', 'solid', 'double',
31
-            'groove', 'ridge', 'inset', 'outset'), false);
32
-
33
-        $this->info['border-style'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_style);
34
-
35
-        $this->info['clear'] = new HTMLPurifier_AttrDef_Enum(
36
-            array('none', 'left', 'right', 'both'), false);
37
-        $this->info['float'] = new HTMLPurifier_AttrDef_Enum(
38
-            array('none', 'left', 'right'), false);
39
-        $this->info['font-style'] = new HTMLPurifier_AttrDef_Enum(
40
-            array('normal', 'italic', 'oblique'), false);
41
-        $this->info['font-variant'] = new HTMLPurifier_AttrDef_Enum(
42
-            array('normal', 'small-caps'), false);
43
-
44
-        $uri_or_none = new HTMLPurifier_AttrDef_CSS_Composite(
45
-            array(
46
-                new HTMLPurifier_AttrDef_Enum(array('none')),
47
-                new HTMLPurifier_AttrDef_CSS_URI()
48
-            )
49
-        );
50
-
51
-        $this->info['list-style-position'] = new HTMLPurifier_AttrDef_Enum(
52
-            array('inside', 'outside'), false);
53
-        $this->info['list-style-type'] = new HTMLPurifier_AttrDef_Enum(
54
-            array('disc', 'circle', 'square', 'decimal', 'lower-roman',
55
-            'upper-roman', 'lower-alpha', 'upper-alpha', 'none'), false);
56
-        $this->info['list-style-image'] = $uri_or_none;
57
-
58
-        $this->info['list-style'] = new HTMLPurifier_AttrDef_CSS_ListStyle($config);
59
-
60
-        $this->info['text-transform'] = new HTMLPurifier_AttrDef_Enum(
61
-            array('capitalize', 'uppercase', 'lowercase', 'none'), false);
62
-        $this->info['color'] = new HTMLPurifier_AttrDef_CSS_Color();
63
-
64
-        $this->info['background-image'] = $uri_or_none;
65
-        $this->info['background-repeat'] = new HTMLPurifier_AttrDef_Enum(
66
-            array('repeat', 'repeat-x', 'repeat-y', 'no-repeat')
67
-        );
68
-        $this->info['background-attachment'] = new HTMLPurifier_AttrDef_Enum(
69
-            array('scroll', 'fixed')
70
-        );
71
-        $this->info['background-position'] = new HTMLPurifier_AttrDef_CSS_BackgroundPosition();
72
-
73
-        $border_color =
74
-        $this->info['border-top-color'] =
75
-        $this->info['border-bottom-color'] =
76
-        $this->info['border-left-color'] =
77
-        $this->info['border-right-color'] =
78
-        $this->info['background-color'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
79
-            new HTMLPurifier_AttrDef_Enum(array('transparent')),
80
-            new HTMLPurifier_AttrDef_CSS_Color()
81
-        ));
82
-
83
-        $this->info['background'] = new HTMLPurifier_AttrDef_CSS_Background($config);
84
-
85
-        $this->info['border-color'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_color);
86
-
87
-        $border_width =
88
-        $this->info['border-top-width'] =
89
-        $this->info['border-bottom-width'] =
90
-        $this->info['border-left-width'] =
91
-        $this->info['border-right-width'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
92
-            new HTMLPurifier_AttrDef_Enum(array('thin', 'medium', 'thick')),
93
-            new HTMLPurifier_AttrDef_CSS_Length('0') //disallow negative
94
-        ));
95
-
96
-        $this->info['border-width'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_width);
97
-
98
-        $this->info['letter-spacing'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
99
-            new HTMLPurifier_AttrDef_Enum(array('normal')),
100
-            new HTMLPurifier_AttrDef_CSS_Length()
101
-        ));
102
-
103
-        $this->info['word-spacing'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
104
-            new HTMLPurifier_AttrDef_Enum(array('normal')),
105
-            new HTMLPurifier_AttrDef_CSS_Length()
106
-        ));
107
-
108
-        $this->info['font-size'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
109
-            new HTMLPurifier_AttrDef_Enum(array('xx-small', 'x-small',
110
-                'small', 'medium', 'large', 'x-large', 'xx-large',
111
-                'larger', 'smaller')),
112
-            new HTMLPurifier_AttrDef_CSS_Percentage(),
113
-            new HTMLPurifier_AttrDef_CSS_Length()
114
-        ));
115
-
116
-        $this->info['line-height'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
117
-            new HTMLPurifier_AttrDef_Enum(array('normal')),
118
-            new HTMLPurifier_AttrDef_CSS_Number(true), // no negatives
119
-            new HTMLPurifier_AttrDef_CSS_Length('0'),
120
-            new HTMLPurifier_AttrDef_CSS_Percentage(true)
121
-        ));
122
-
123
-        $margin =
124
-        $this->info['margin-top'] =
125
-        $this->info['margin-bottom'] =
126
-        $this->info['margin-left'] =
127
-        $this->info['margin-right'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
128
-            new HTMLPurifier_AttrDef_CSS_Length(),
129
-            new HTMLPurifier_AttrDef_CSS_Percentage(),
130
-            new HTMLPurifier_AttrDef_Enum(array('auto'))
131
-        ));
132
-
133
-        $this->info['margin'] = new HTMLPurifier_AttrDef_CSS_Multiple($margin);
134
-
135
-        // non-negative
136
-        $padding =
137
-        $this->info['padding-top'] =
138
-        $this->info['padding-bottom'] =
139
-        $this->info['padding-left'] =
140
-        $this->info['padding-right'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
141
-            new HTMLPurifier_AttrDef_CSS_Length('0'),
142
-            new HTMLPurifier_AttrDef_CSS_Percentage(true)
143
-        ));
144
-
145
-        $this->info['padding'] = new HTMLPurifier_AttrDef_CSS_Multiple($padding);
146
-
147
-        $this->info['text-indent'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
148
-            new HTMLPurifier_AttrDef_CSS_Length(),
149
-            new HTMLPurifier_AttrDef_CSS_Percentage()
150
-        ));
151
-
152
-        $trusted_wh = new HTMLPurifier_AttrDef_CSS_Composite(array(
153
-            new HTMLPurifier_AttrDef_CSS_Length('0'),
154
-            new HTMLPurifier_AttrDef_CSS_Percentage(true),
155
-            new HTMLPurifier_AttrDef_Enum(array('auto'))
156
-        ));
157
-        $max = $config->get('CSS.MaxImgLength');
158
-
159
-        $this->info['width'] =
160
-        $this->info['height'] =
161
-            $max === null ?
162
-            $trusted_wh :
163
-            new HTMLPurifier_AttrDef_Switch('img',
164
-                // For img tags:
165
-                new HTMLPurifier_AttrDef_CSS_Composite(array(
166
-                    new HTMLPurifier_AttrDef_CSS_Length('0', $max),
167
-                    new HTMLPurifier_AttrDef_Enum(array('auto'))
168
-                )),
169
-                // For everyone else:
170
-                $trusted_wh
171
-            );
172
-
173
-        $this->info['text-decoration'] = new HTMLPurifier_AttrDef_CSS_TextDecoration();
174
-
175
-        $this->info['font-family'] = new HTMLPurifier_AttrDef_CSS_FontFamily();
176
-
177
-        // this could use specialized code
178
-        $this->info['font-weight'] = new HTMLPurifier_AttrDef_Enum(
179
-            array('normal', 'bold', 'bolder', 'lighter', '100', '200', '300',
180
-            '400', '500', '600', '700', '800', '900'), false);
181
-
182
-        // MUST be called after other font properties, as it references
183
-        // a CSSDefinition object
184
-        $this->info['font'] = new HTMLPurifier_AttrDef_CSS_Font($config);
185
-
186
-        // same here
187
-        $this->info['border'] =
188
-        $this->info['border-bottom'] =
189
-        $this->info['border-top'] =
190
-        $this->info['border-left'] =
191
-        $this->info['border-right'] = new HTMLPurifier_AttrDef_CSS_Border($config);
192
-
193
-        $this->info['border-collapse'] = new HTMLPurifier_AttrDef_Enum(array(
194
-            'collapse', 'separate'));
195
-
196
-        $this->info['caption-side'] = new HTMLPurifier_AttrDef_Enum(array(
197
-            'top', 'bottom'));
198
-
199
-        $this->info['table-layout'] = new HTMLPurifier_AttrDef_Enum(array(
200
-            'auto', 'fixed'));
201
-
202
-        $this->info['vertical-align'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
203
-            new HTMLPurifier_AttrDef_Enum(array('baseline', 'sub', 'super',
204
-                'top', 'text-top', 'middle', 'bottom', 'text-bottom')),
205
-            new HTMLPurifier_AttrDef_CSS_Length(),
206
-            new HTMLPurifier_AttrDef_CSS_Percentage()
207
-        ));
208
-
209
-        $this->info['border-spacing'] = new HTMLPurifier_AttrDef_CSS_Multiple(new HTMLPurifier_AttrDef_CSS_Length(), 2);
210
-
211
-        // partial support
212
-        $this->info['white-space'] = new HTMLPurifier_AttrDef_Enum(array('nowrap'));
213
-
214
-        if ($config->get('CSS.Proprietary')) {
215
-            $this->doSetupProprietary($config);
216
-        }
217
-
218
-        if ($config->get('CSS.AllowTricky')) {
219
-            $this->doSetupTricky($config);
220
-        }
221
-
222
-        if ($config->get('CSS.Trusted')) {
223
-            $this->doSetupTrusted($config);
224
-        }
225
-
226
-        $allow_important = $config->get('CSS.AllowImportant');
227
-        // wrap all attr-defs with decorator that handles !important
228
-        foreach ($this->info as $k => $v) {
229
-            $this->info[$k] = new HTMLPurifier_AttrDef_CSS_ImportantDecorator($v, $allow_important);
230
-        }
231
-
232
-        $this->setupConfigStuff($config);
233
-    }
234
-
235
-    protected function doSetupProprietary($config) {
236
-        // Internet Explorer only scrollbar colors
237
-        $this->info['scrollbar-arrow-color']        = new HTMLPurifier_AttrDef_CSS_Color();
238
-        $this->info['scrollbar-base-color']         = new HTMLPurifier_AttrDef_CSS_Color();
239
-        $this->info['scrollbar-darkshadow-color']   = new HTMLPurifier_AttrDef_CSS_Color();
240
-        $this->info['scrollbar-face-color']         = new HTMLPurifier_AttrDef_CSS_Color();
241
-        $this->info['scrollbar-highlight-color']    = new HTMLPurifier_AttrDef_CSS_Color();
242
-        $this->info['scrollbar-shadow-color']       = new HTMLPurifier_AttrDef_CSS_Color();
243
-
244
-        // technically not proprietary, but CSS3, and no one supports it
245
-        $this->info['opacity']          = new HTMLPurifier_AttrDef_CSS_AlphaValue();
246
-        $this->info['-moz-opacity']     = new HTMLPurifier_AttrDef_CSS_AlphaValue();
247
-        $this->info['-khtml-opacity']   = new HTMLPurifier_AttrDef_CSS_AlphaValue();
248
-
249
-        // only opacity, for now
250
-        $this->info['filter'] = new HTMLPurifier_AttrDef_CSS_Filter();
251
-
252
-    }
253
-
254
-    protected function doSetupTricky($config) {
255
-        $this->info['display'] = new HTMLPurifier_AttrDef_Enum(array(
256
-            'inline', 'block', 'list-item', 'run-in', 'compact',
257
-            'marker', 'table', 'inline-table', 'table-row-group',
258
-            'table-header-group', 'table-footer-group', 'table-row',
259
-            'table-column-group', 'table-column', 'table-cell', 'table-caption', 'none'
260
-        ));
261
-        $this->info['visibility'] = new HTMLPurifier_AttrDef_Enum(array(
262
-            'visible', 'hidden', 'collapse'
263
-        ));
264
-        $this->info['overflow'] = new HTMLPurifier_AttrDef_Enum(array('visible', 'hidden', 'auto', 'scroll'));
265
-    }
266
-
267
-    protected function doSetupTrusted($config) {
268
-        $this->info['position'] = new HTMLPurifier_AttrDef_Enum(array(
269
-            'static', 'relative', 'absolute', 'fixed'
270
-        ));
271
-        $this->info['top'] =
272
-        $this->info['left'] =
273
-        $this->info['right'] =
274
-        $this->info['bottom'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
275
-            new HTMLPurifier_AttrDef_CSS_Length(),
276
-            new HTMLPurifier_AttrDef_CSS_Percentage(),
277
-            new HTMLPurifier_AttrDef_Enum(array('auto')),
278
-        ));
279
-        $this->info['z-index'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
280
-            new HTMLPurifier_AttrDef_Integer(),
281
-            new HTMLPurifier_AttrDef_Enum(array('auto')),
282
-        ));
283
-    }
284
-
285
-    /**
286
-     * Performs extra config-based processing. Based off of
287
-     * HTMLPurifier_HTMLDefinition.
288
-     * @todo Refactor duplicate elements into common class (probably using
289
-     *       composition, not inheritance).
290
-     */
291
-    protected function setupConfigStuff($config) {
292
-
293
-        // setup allowed elements
294
-        $support = "(for information on implementing this, see the ".
295
-                   "support forums) ";
296
-        $allowed_properties = $config->get('CSS.AllowedProperties');
297
-        if ($allowed_properties !== null) {
298
-            foreach ($this->info as $name => $d) {
299
-                if(!isset($allowed_properties[$name])) unset($this->info[$name]);
300
-                unset($allowed_properties[$name]);
301
-            }
302
-            // emit errors
303
-            foreach ($allowed_properties as $name => $d) {
304
-                // :TODO: Is this htmlspecialchars() call really necessary?
305
-                $name = htmlspecialchars($name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
306
-                trigger_error("Style attribute '$name' is not supported $support", E_USER_WARNING);
307
-            }
308
-        }
309
-
310
-        $forbidden_properties = $config->get('CSS.ForbiddenProperties');
311
-        if ($forbidden_properties !== null) {
312
-            foreach ($this->info as $name => $d) {
313
-                if (isset($forbidden_properties[$name])) {
314
-                    unset($this->info[$name]);
315
-                }
316
-            }
317
-        }
318
-
319
-    }
10
+	public $type = 'CSS';
11
+
12
+	/**
13
+	 * Assoc array of attribute name to definition object.
14
+	 */
15
+	public $info = array();
16
+
17
+	/**
18
+	 * Constructs the info array.  The meat of this class.
19
+	 */
20
+	protected function doSetup($config) {
21
+
22
+		$this->info['text-align'] = new HTMLPurifier_AttrDef_Enum(
23
+			array('left', 'right', 'center', 'justify'), false);
24
+
25
+		$border_style =
26
+		$this->info['border-bottom-style'] =
27
+		$this->info['border-right-style'] =
28
+		$this->info['border-left-style'] =
29
+		$this->info['border-top-style'] =  new HTMLPurifier_AttrDef_Enum(
30
+			array('none', 'hidden', 'dotted', 'dashed', 'solid', 'double',
31
+			'groove', 'ridge', 'inset', 'outset'), false);
32
+
33
+		$this->info['border-style'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_style);
34
+
35
+		$this->info['clear'] = new HTMLPurifier_AttrDef_Enum(
36
+			array('none', 'left', 'right', 'both'), false);
37
+		$this->info['float'] = new HTMLPurifier_AttrDef_Enum(
38
+			array('none', 'left', 'right'), false);
39
+		$this->info['font-style'] = new HTMLPurifier_AttrDef_Enum(
40
+			array('normal', 'italic', 'oblique'), false);
41
+		$this->info['font-variant'] = new HTMLPurifier_AttrDef_Enum(
42
+			array('normal', 'small-caps'), false);
43
+
44
+		$uri_or_none = new HTMLPurifier_AttrDef_CSS_Composite(
45
+			array(
46
+				new HTMLPurifier_AttrDef_Enum(array('none')),
47
+				new HTMLPurifier_AttrDef_CSS_URI()
48
+			)
49
+		);
50
+
51
+		$this->info['list-style-position'] = new HTMLPurifier_AttrDef_Enum(
52
+			array('inside', 'outside'), false);
53
+		$this->info['list-style-type'] = new HTMLPurifier_AttrDef_Enum(
54
+			array('disc', 'circle', 'square', 'decimal', 'lower-roman',
55
+			'upper-roman', 'lower-alpha', 'upper-alpha', 'none'), false);
56
+		$this->info['list-style-image'] = $uri_or_none;
57
+
58
+		$this->info['list-style'] = new HTMLPurifier_AttrDef_CSS_ListStyle($config);
59
+
60
+		$this->info['text-transform'] = new HTMLPurifier_AttrDef_Enum(
61
+			array('capitalize', 'uppercase', 'lowercase', 'none'), false);
62
+		$this->info['color'] = new HTMLPurifier_AttrDef_CSS_Color();
63
+
64
+		$this->info['background-image'] = $uri_or_none;
65
+		$this->info['background-repeat'] = new HTMLPurifier_AttrDef_Enum(
66
+			array('repeat', 'repeat-x', 'repeat-y', 'no-repeat')
67
+		);
68
+		$this->info['background-attachment'] = new HTMLPurifier_AttrDef_Enum(
69
+			array('scroll', 'fixed')
70
+		);
71
+		$this->info['background-position'] = new HTMLPurifier_AttrDef_CSS_BackgroundPosition();
72
+
73
+		$border_color =
74
+		$this->info['border-top-color'] =
75
+		$this->info['border-bottom-color'] =
76
+		$this->info['border-left-color'] =
77
+		$this->info['border-right-color'] =
78
+		$this->info['background-color'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
79
+			new HTMLPurifier_AttrDef_Enum(array('transparent')),
80
+			new HTMLPurifier_AttrDef_CSS_Color()
81
+		));
82
+
83
+		$this->info['background'] = new HTMLPurifier_AttrDef_CSS_Background($config);
84
+
85
+		$this->info['border-color'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_color);
86
+
87
+		$border_width =
88
+		$this->info['border-top-width'] =
89
+		$this->info['border-bottom-width'] =
90
+		$this->info['border-left-width'] =
91
+		$this->info['border-right-width'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
92
+			new HTMLPurifier_AttrDef_Enum(array('thin', 'medium', 'thick')),
93
+			new HTMLPurifier_AttrDef_CSS_Length('0') //disallow negative
94
+		));
95
+
96
+		$this->info['border-width'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_width);
97
+
98
+		$this->info['letter-spacing'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
99
+			new HTMLPurifier_AttrDef_Enum(array('normal')),
100
+			new HTMLPurifier_AttrDef_CSS_Length()
101
+		));
102
+
103
+		$this->info['word-spacing'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
104
+			new HTMLPurifier_AttrDef_Enum(array('normal')),
105
+			new HTMLPurifier_AttrDef_CSS_Length()
106
+		));
107
+
108
+		$this->info['font-size'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
109
+			new HTMLPurifier_AttrDef_Enum(array('xx-small', 'x-small',
110
+				'small', 'medium', 'large', 'x-large', 'xx-large',
111
+				'larger', 'smaller')),
112
+			new HTMLPurifier_AttrDef_CSS_Percentage(),
113
+			new HTMLPurifier_AttrDef_CSS_Length()
114
+		));
115
+
116
+		$this->info['line-height'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
117
+			new HTMLPurifier_AttrDef_Enum(array('normal')),
118
+			new HTMLPurifier_AttrDef_CSS_Number(true), // no negatives
119
+			new HTMLPurifier_AttrDef_CSS_Length('0'),
120
+			new HTMLPurifier_AttrDef_CSS_Percentage(true)
121
+		));
122
+
123
+		$margin =
124
+		$this->info['margin-top'] =
125
+		$this->info['margin-bottom'] =
126
+		$this->info['margin-left'] =
127
+		$this->info['margin-right'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
128
+			new HTMLPurifier_AttrDef_CSS_Length(),
129
+			new HTMLPurifier_AttrDef_CSS_Percentage(),
130
+			new HTMLPurifier_AttrDef_Enum(array('auto'))
131
+		));
132
+
133
+		$this->info['margin'] = new HTMLPurifier_AttrDef_CSS_Multiple($margin);
134
+
135
+		// non-negative
136
+		$padding =
137
+		$this->info['padding-top'] =
138
+		$this->info['padding-bottom'] =
139
+		$this->info['padding-left'] =
140
+		$this->info['padding-right'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
141
+			new HTMLPurifier_AttrDef_CSS_Length('0'),
142
+			new HTMLPurifier_AttrDef_CSS_Percentage(true)
143
+		));
144
+
145
+		$this->info['padding'] = new HTMLPurifier_AttrDef_CSS_Multiple($padding);
146
+
147
+		$this->info['text-indent'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
148
+			new HTMLPurifier_AttrDef_CSS_Length(),
149
+			new HTMLPurifier_AttrDef_CSS_Percentage()
150
+		));
151
+
152
+		$trusted_wh = new HTMLPurifier_AttrDef_CSS_Composite(array(
153
+			new HTMLPurifier_AttrDef_CSS_Length('0'),
154
+			new HTMLPurifier_AttrDef_CSS_Percentage(true),
155
+			new HTMLPurifier_AttrDef_Enum(array('auto'))
156
+		));
157
+		$max = $config->get('CSS.MaxImgLength');
158
+
159
+		$this->info['width'] =
160
+		$this->info['height'] =
161
+			$max === null ?
162
+			$trusted_wh :
163
+			new HTMLPurifier_AttrDef_Switch('img',
164
+				// For img tags:
165
+				new HTMLPurifier_AttrDef_CSS_Composite(array(
166
+					new HTMLPurifier_AttrDef_CSS_Length('0', $max),
167
+					new HTMLPurifier_AttrDef_Enum(array('auto'))
168
+				)),
169
+				// For everyone else:
170
+				$trusted_wh
171
+			);
172
+
173
+		$this->info['text-decoration'] = new HTMLPurifier_AttrDef_CSS_TextDecoration();
174
+
175
+		$this->info['font-family'] = new HTMLPurifier_AttrDef_CSS_FontFamily();
176
+
177
+		// this could use specialized code
178
+		$this->info['font-weight'] = new HTMLPurifier_AttrDef_Enum(
179
+			array('normal', 'bold', 'bolder', 'lighter', '100', '200', '300',
180
+			'400', '500', '600', '700', '800', '900'), false);
181
+
182
+		// MUST be called after other font properties, as it references
183
+		// a CSSDefinition object
184
+		$this->info['font'] = new HTMLPurifier_AttrDef_CSS_Font($config);
185
+
186
+		// same here
187
+		$this->info['border'] =
188
+		$this->info['border-bottom'] =
189
+		$this->info['border-top'] =
190
+		$this->info['border-left'] =
191
+		$this->info['border-right'] = new HTMLPurifier_AttrDef_CSS_Border($config);
192
+
193
+		$this->info['border-collapse'] = new HTMLPurifier_AttrDef_Enum(array(
194
+			'collapse', 'separate'));
195
+
196
+		$this->info['caption-side'] = new HTMLPurifier_AttrDef_Enum(array(
197
+			'top', 'bottom'));
198
+
199
+		$this->info['table-layout'] = new HTMLPurifier_AttrDef_Enum(array(
200
+			'auto', 'fixed'));
201
+
202
+		$this->info['vertical-align'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
203
+			new HTMLPurifier_AttrDef_Enum(array('baseline', 'sub', 'super',
204
+				'top', 'text-top', 'middle', 'bottom', 'text-bottom')),
205
+			new HTMLPurifier_AttrDef_CSS_Length(),
206
+			new HTMLPurifier_AttrDef_CSS_Percentage()
207
+		));
208
+
209
+		$this->info['border-spacing'] = new HTMLPurifier_AttrDef_CSS_Multiple(new HTMLPurifier_AttrDef_CSS_Length(), 2);
210
+
211
+		// partial support
212
+		$this->info['white-space'] = new HTMLPurifier_AttrDef_Enum(array('nowrap'));
213
+
214
+		if ($config->get('CSS.Proprietary')) {
215
+			$this->doSetupProprietary($config);
216
+		}
217
+
218
+		if ($config->get('CSS.AllowTricky')) {
219
+			$this->doSetupTricky($config);
220
+		}
221
+
222
+		if ($config->get('CSS.Trusted')) {
223
+			$this->doSetupTrusted($config);
224
+		}
225
+
226
+		$allow_important = $config->get('CSS.AllowImportant');
227
+		// wrap all attr-defs with decorator that handles !important
228
+		foreach ($this->info as $k => $v) {
229
+			$this->info[$k] = new HTMLPurifier_AttrDef_CSS_ImportantDecorator($v, $allow_important);
230
+		}
231
+
232
+		$this->setupConfigStuff($config);
233
+	}
234
+
235
+	protected function doSetupProprietary($config) {
236
+		// Internet Explorer only scrollbar colors
237
+		$this->info['scrollbar-arrow-color']        = new HTMLPurifier_AttrDef_CSS_Color();
238
+		$this->info['scrollbar-base-color']         = new HTMLPurifier_AttrDef_CSS_Color();
239
+		$this->info['scrollbar-darkshadow-color']   = new HTMLPurifier_AttrDef_CSS_Color();
240
+		$this->info['scrollbar-face-color']         = new HTMLPurifier_AttrDef_CSS_Color();
241
+		$this->info['scrollbar-highlight-color']    = new HTMLPurifier_AttrDef_CSS_Color();
242
+		$this->info['scrollbar-shadow-color']       = new HTMLPurifier_AttrDef_CSS_Color();
243
+
244
+		// technically not proprietary, but CSS3, and no one supports it
245
+		$this->info['opacity']          = new HTMLPurifier_AttrDef_CSS_AlphaValue();
246
+		$this->info['-moz-opacity']     = new HTMLPurifier_AttrDef_CSS_AlphaValue();
247
+		$this->info['-khtml-opacity']   = new HTMLPurifier_AttrDef_CSS_AlphaValue();
248
+
249
+		// only opacity, for now
250
+		$this->info['filter'] = new HTMLPurifier_AttrDef_CSS_Filter();
251
+
252
+	}
253
+
254
+	protected function doSetupTricky($config) {
255
+		$this->info['display'] = new HTMLPurifier_AttrDef_Enum(array(
256
+			'inline', 'block', 'list-item', 'run-in', 'compact',
257
+			'marker', 'table', 'inline-table', 'table-row-group',
258
+			'table-header-group', 'table-footer-group', 'table-row',
259
+			'table-column-group', 'table-column', 'table-cell', 'table-caption', 'none'
260
+		));
261
+		$this->info['visibility'] = new HTMLPurifier_AttrDef_Enum(array(
262
+			'visible', 'hidden', 'collapse'
263
+		));
264
+		$this->info['overflow'] = new HTMLPurifier_AttrDef_Enum(array('visible', 'hidden', 'auto', 'scroll'));
265
+	}
266
+
267
+	protected function doSetupTrusted($config) {
268
+		$this->info['position'] = new HTMLPurifier_AttrDef_Enum(array(
269
+			'static', 'relative', 'absolute', 'fixed'
270
+		));
271
+		$this->info['top'] =
272
+		$this->info['left'] =
273
+		$this->info['right'] =
274
+		$this->info['bottom'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
275
+			new HTMLPurifier_AttrDef_CSS_Length(),
276
+			new HTMLPurifier_AttrDef_CSS_Percentage(),
277
+			new HTMLPurifier_AttrDef_Enum(array('auto')),
278
+		));
279
+		$this->info['z-index'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
280
+			new HTMLPurifier_AttrDef_Integer(),
281
+			new HTMLPurifier_AttrDef_Enum(array('auto')),
282
+		));
283
+	}
284
+
285
+	/**
286
+	 * Performs extra config-based processing. Based off of
287
+	 * HTMLPurifier_HTMLDefinition.
288
+	 * @todo Refactor duplicate elements into common class (probably using
289
+	 *       composition, not inheritance).
290
+	 */
291
+	protected function setupConfigStuff($config) {
292
+
293
+		// setup allowed elements
294
+		$support = "(for information on implementing this, see the ".
295
+				   "support forums) ";
296
+		$allowed_properties = $config->get('CSS.AllowedProperties');
297
+		if ($allowed_properties !== null) {
298
+			foreach ($this->info as $name => $d) {
299
+				if(!isset($allowed_properties[$name])) unset($this->info[$name]);
300
+				unset($allowed_properties[$name]);
301
+			}
302
+			// emit errors
303
+			foreach ($allowed_properties as $name => $d) {
304
+				// :TODO: Is this htmlspecialchars() call really necessary?
305
+				$name = htmlspecialchars($name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
306
+				trigger_error("Style attribute '$name' is not supported $support", E_USER_WARNING);
307
+			}
308
+		}
309
+
310
+		$forbidden_properties = $config->get('CSS.ForbiddenProperties');
311
+		if ($forbidden_properties !== null) {
312
+			foreach ($this->info as $name => $d) {
313
+				if (isset($forbidden_properties[$name])) {
314
+					unset($this->info[$name]);
315
+				}
316
+			}
317
+		}
318
+
319
+	}
320 320
 }
321 321
 
322 322
 // vim: et sw=4 sts=4
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -296,7 +296,9 @@
 block discarded – undo
296 296
         $allowed_properties = $config->get('CSS.AllowedProperties');
297 297
         if ($allowed_properties !== null) {
298 298
             foreach ($this->info as $name => $d) {
299
-                if(!isset($allowed_properties[$name])) unset($this->info[$name]);
299
+                if(!isset($allowed_properties[$name])) {
300
+                	unset($this->info[$name]);
301
+                }
300 302
                 unset($allowed_properties[$name]);
301 303
             }
302 304
             // emit errors
Please login to merge, or discard this patch.
Spacing   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         $this->info['border-bottom-style'] =
27 27
         $this->info['border-right-style'] =
28 28
         $this->info['border-left-style'] =
29
-        $this->info['border-top-style'] =  new HTMLPurifier_AttrDef_Enum(
29
+        $this->info['border-top-style'] = new HTMLPurifier_AttrDef_Enum(
30 30
             array('none', 'hidden', 'dotted', 'dashed', 'solid', 'double',
31 31
             'groove', 'ridge', 'inset', 'outset'), false);
32 32
 
@@ -159,8 +159,7 @@  discard block
 block discarded – undo
159 159
         $this->info['width'] =
160 160
         $this->info['height'] =
161 161
             $max === null ?
162
-            $trusted_wh :
163
-            new HTMLPurifier_AttrDef_Switch('img',
162
+            $trusted_wh : new HTMLPurifier_AttrDef_Switch('img',
164 163
                 // For img tags:
165 164
                 new HTMLPurifier_AttrDef_CSS_Composite(array(
166 165
                     new HTMLPurifier_AttrDef_CSS_Length('0', $max),
@@ -296,7 +295,7 @@  discard block
 block discarded – undo
296 295
         $allowed_properties = $config->get('CSS.AllowedProperties');
297 296
         if ($allowed_properties !== null) {
298 297
             foreach ($this->info as $name => $d) {
299
-                if(!isset($allowed_properties[$name])) unset($this->info[$name]);
298
+                if (!isset($allowed_properties[$name])) unset($this->info[$name]);
300 299
                 unset($allowed_properties[$name]);
301 300
             }
302 301
             // emit errors
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/ChildDef.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -5,44 +5,44 @@
 block discarded – undo
5 5
  */
6 6
 abstract class HTMLPurifier_ChildDef
7 7
 {
8
-    /**
9
-     * Type of child definition, usually right-most part of class name lowercase.
10
-     * Used occasionally in terms of context.
11
-     */
12
-    public $type;
8
+	/**
9
+	 * Type of child definition, usually right-most part of class name lowercase.
10
+	 * Used occasionally in terms of context.
11
+	 */
12
+	public $type;
13 13
 
14
-    /**
15
-     * Bool that indicates whether or not an empty array of children is okay
16
-     *
17
-     * This is necessary for redundant checking when changes affecting
18
-     * a child node may cause a parent node to now be disallowed.
19
-     */
20
-    public $allow_empty;
14
+	/**
15
+	 * Bool that indicates whether or not an empty array of children is okay
16
+	 *
17
+	 * This is necessary for redundant checking when changes affecting
18
+	 * a child node may cause a parent node to now be disallowed.
19
+	 */
20
+	public $allow_empty;
21 21
 
22
-    /**
23
-     * Lookup array of all elements that this definition could possibly allow
24
-     */
25
-    public $elements = array();
22
+	/**
23
+	 * Lookup array of all elements that this definition could possibly allow
24
+	 */
25
+	public $elements = array();
26 26
 
27
-    /**
28
-     * Get lookup of tag names that should not close this element automatically.
29
-     * All other elements will do so.
30
-     */
31
-    public function getAllowedElements($config) {
32
-        return $this->elements;
33
-    }
27
+	/**
28
+	 * Get lookup of tag names that should not close this element automatically.
29
+	 * All other elements will do so.
30
+	 */
31
+	public function getAllowedElements($config) {
32
+		return $this->elements;
33
+	}
34 34
 
35
-    /**
36
-     * Validates nodes according to definition and returns modification.
37
-     *
38
-     * @param $tokens_of_children Array of HTMLPurifier_Token
39
-     * @param $config HTMLPurifier_Config object
40
-     * @param $context HTMLPurifier_Context object
41
-     * @return bool true to leave nodes as is
42
-     * @return bool false to remove parent node
43
-     * @return array of replacement child tokens
44
-     */
45
-    abstract public function validateChildren($tokens_of_children, $config, $context);
35
+	/**
36
+	 * Validates nodes according to definition and returns modification.
37
+	 *
38
+	 * @param $tokens_of_children Array of HTMLPurifier_Token
39
+	 * @param $config HTMLPurifier_Config object
40
+	 * @param $context HTMLPurifier_Context object
41
+	 * @return bool true to leave nodes as is
42
+	 * @return bool false to remove parent node
43
+	 * @return array of replacement child tokens
44
+	 */
45
+	abstract public function validateChildren($tokens_of_children, $config, $context);
46 46
 }
47 47
 
48 48
 // vim: et sw=4 sts=4
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/ChildDef/Chameleon.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -12,37 +12,37 @@
 block discarded – undo
12 12
 class HTMLPurifier_ChildDef_Chameleon extends HTMLPurifier_ChildDef
13 13
 {
14 14
 
15
-    /**
16
-     * Instance of the definition object to use when inline. Usually stricter.
17
-     */
18
-    public $inline;
15
+	/**
16
+	 * Instance of the definition object to use when inline. Usually stricter.
17
+	 */
18
+	public $inline;
19 19
 
20
-    /**
21
-     * Instance of the definition object to use when block.
22
-     */
23
-    public $block;
20
+	/**
21
+	 * Instance of the definition object to use when block.
22
+	 */
23
+	public $block;
24 24
 
25
-    public $type = 'chameleon';
25
+	public $type = 'chameleon';
26 26
 
27
-    /**
28
-     * @param $inline List of elements to allow when inline.
29
-     * @param $block List of elements to allow when block.
30
-     */
31
-    public function __construct($inline, $block) {
32
-        $this->inline = new HTMLPurifier_ChildDef_Optional($inline);
33
-        $this->block  = new HTMLPurifier_ChildDef_Optional($block);
34
-        $this->elements = $this->block->elements;
35
-    }
27
+	/**
28
+	 * @param $inline List of elements to allow when inline.
29
+	 * @param $block List of elements to allow when block.
30
+	 */
31
+	public function __construct($inline, $block) {
32
+		$this->inline = new HTMLPurifier_ChildDef_Optional($inline);
33
+		$this->block  = new HTMLPurifier_ChildDef_Optional($block);
34
+		$this->elements = $this->block->elements;
35
+	}
36 36
 
37
-    public function validateChildren($tokens_of_children, $config, $context) {
38
-        if ($context->get('IsInline') === false) {
39
-            return $this->block->validateChildren(
40
-                $tokens_of_children, $config, $context);
41
-        } else {
42
-            return $this->inline->validateChildren(
43
-                $tokens_of_children, $config, $context);
44
-        }
45
-    }
37
+	public function validateChildren($tokens_of_children, $config, $context) {
38
+		if ($context->get('IsInline') === false) {
39
+			return $this->block->validateChildren(
40
+				$tokens_of_children, $config, $context);
41
+		} else {
42
+			return $this->inline->validateChildren(
43
+				$tokens_of_children, $config, $context);
44
+		}
45
+	}
46 46
 }
47 47
 
48 48
 // vim: et sw=4 sts=4
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/ChildDef/Custom.php 3 patches
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -8,83 +8,83 @@
 block discarded – undo
8 8
  */
9 9
 class HTMLPurifier_ChildDef_Custom extends HTMLPurifier_ChildDef
10 10
 {
11
-    public $type = 'custom';
12
-    public $allow_empty = false;
13
-    /**
14
-     * Allowed child pattern as defined by the DTD
15
-     */
16
-    public $dtd_regex;
17
-    /**
18
-     * PCRE regex derived from $dtd_regex
19
-     * @private
20
-     */
21
-    private $_pcre_regex;
22
-    /**
23
-     * @param $dtd_regex Allowed child pattern from the DTD
24
-     */
25
-    public function __construct($dtd_regex) {
26
-        $this->dtd_regex = $dtd_regex;
27
-        $this->_compileRegex();
28
-    }
29
-    /**
30
-     * Compiles the PCRE regex from a DTD regex ($dtd_regex to $_pcre_regex)
31
-     */
32
-    protected function _compileRegex() {
33
-        $raw = str_replace(' ', '', $this->dtd_regex);
34
-        if ($raw{0} != '(') {
35
-            $raw = "($raw)";
36
-        }
37
-        $el = '[#a-zA-Z0-9_.-]+';
38
-        $reg = $raw;
11
+	public $type = 'custom';
12
+	public $allow_empty = false;
13
+	/**
14
+	 * Allowed child pattern as defined by the DTD
15
+	 */
16
+	public $dtd_regex;
17
+	/**
18
+	 * PCRE regex derived from $dtd_regex
19
+	 * @private
20
+	 */
21
+	private $_pcre_regex;
22
+	/**
23
+	 * @param $dtd_regex Allowed child pattern from the DTD
24
+	 */
25
+	public function __construct($dtd_regex) {
26
+		$this->dtd_regex = $dtd_regex;
27
+		$this->_compileRegex();
28
+	}
29
+	/**
30
+	 * Compiles the PCRE regex from a DTD regex ($dtd_regex to $_pcre_regex)
31
+	 */
32
+	protected function _compileRegex() {
33
+		$raw = str_replace(' ', '', $this->dtd_regex);
34
+		if ($raw{0} != '(') {
35
+			$raw = "($raw)";
36
+		}
37
+		$el = '[#a-zA-Z0-9_.-]+';
38
+		$reg = $raw;
39 39
 
40
-        // COMPLICATED! AND MIGHT BE BUGGY! I HAVE NO CLUE WHAT I'M
41
-        // DOING! Seriously: if there's problems, please report them.
40
+		// COMPLICATED! AND MIGHT BE BUGGY! I HAVE NO CLUE WHAT I'M
41
+		// DOING! Seriously: if there's problems, please report them.
42 42
 
43
-        // collect all elements into the $elements array
44
-        preg_match_all("/$el/", $reg, $matches);
45
-        foreach ($matches[0] as $match) {
46
-            $this->elements[$match] = true;
47
-        }
43
+		// collect all elements into the $elements array
44
+		preg_match_all("/$el/", $reg, $matches);
45
+		foreach ($matches[0] as $match) {
46
+			$this->elements[$match] = true;
47
+		}
48 48
 
49
-        // setup all elements as parentheticals with leading commas
50
-        $reg = preg_replace("/$el/", '(,\\0)', $reg);
49
+		// setup all elements as parentheticals with leading commas
50
+		$reg = preg_replace("/$el/", '(,\\0)', $reg);
51 51
 
52
-        // remove commas when they were not solicited
53
-        $reg = preg_replace("/([^,(|]\(+),/", '\\1', $reg);
52
+		// remove commas when they were not solicited
53
+		$reg = preg_replace("/([^,(|]\(+),/", '\\1', $reg);
54 54
 
55
-        // remove all non-paranthetical commas: they are handled by first regex
56
-        $reg = preg_replace("/,\(/", '(', $reg);
55
+		// remove all non-paranthetical commas: they are handled by first regex
56
+		$reg = preg_replace("/,\(/", '(', $reg);
57 57
 
58
-        $this->_pcre_regex = $reg;
59
-    }
60
-    public function validateChildren($tokens_of_children, $config, $context) {
61
-        $list_of_children = '';
62
-        $nesting = 0; // depth into the nest
63
-        foreach ($tokens_of_children as $token) {
64
-            if (!empty($token->is_whitespace)) continue;
58
+		$this->_pcre_regex = $reg;
59
+	}
60
+	public function validateChildren($tokens_of_children, $config, $context) {
61
+		$list_of_children = '';
62
+		$nesting = 0; // depth into the nest
63
+		foreach ($tokens_of_children as $token) {
64
+			if (!empty($token->is_whitespace)) continue;
65 65
 
66
-            $is_child = ($nesting == 0); // direct
66
+			$is_child = ($nesting == 0); // direct
67 67
 
68
-            if ($token instanceof HTMLPurifier_Token_Start) {
69
-                $nesting++;
70
-            } elseif ($token instanceof HTMLPurifier_Token_End) {
71
-                $nesting--;
72
-            }
68
+			if ($token instanceof HTMLPurifier_Token_Start) {
69
+				$nesting++;
70
+			} elseif ($token instanceof HTMLPurifier_Token_End) {
71
+				$nesting--;
72
+			}
73 73
 
74
-            if ($is_child) {
75
-                $list_of_children .= $token->name . ',';
76
-            }
77
-        }
78
-        // add leading comma to deal with stray comma declarations
79
-        $list_of_children = ',' . rtrim($list_of_children, ',');
80
-        $okay =
81
-            preg_match(
82
-                '/^,?'.$this->_pcre_regex.'$/',
83
-                $list_of_children
84
-            );
74
+			if ($is_child) {
75
+				$list_of_children .= $token->name . ',';
76
+			}
77
+		}
78
+		// add leading comma to deal with stray comma declarations
79
+		$list_of_children = ',' . rtrim($list_of_children, ',');
80
+		$okay =
81
+			preg_match(
82
+				'/^,?'.$this->_pcre_regex.'$/',
83
+				$list_of_children
84
+			);
85 85
 
86
-        return (bool) $okay;
87
-    }
86
+		return (bool) $okay;
87
+	}
88 88
 }
89 89
 
90 90
 // vim: et sw=4 sts=4
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,9 @@
 block discarded – undo
61 61
         $list_of_children = '';
62 62
         $nesting = 0; // depth into the nest
63 63
         foreach ($tokens_of_children as $token) {
64
-            if (!empty($token->is_whitespace)) continue;
64
+            if (!empty($token->is_whitespace)) {
65
+            	continue;
66
+            }
65 67
 
66 68
             $is_child = ($nesting == 0); // direct
67 69
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -72,11 +72,11 @@
 block discarded – undo
72 72
             }
73 73
 
74 74
             if ($is_child) {
75
-                $list_of_children .= $token->name . ',';
75
+                $list_of_children .= $token->name.',';
76 76
             }
77 77
         }
78 78
         // add leading comma to deal with stray comma declarations
79
-        $list_of_children = ',' . rtrim($list_of_children, ',');
79
+        $list_of_children = ','.rtrim($list_of_children, ',');
80 80
         $okay =
81 81
             preg_match(
82 82
                 '/^,?'.$this->_pcre_regex.'$/',
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/ChildDef/Empty.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@
 block discarded – undo
9 9
  */
10 10
 class HTMLPurifier_ChildDef_Empty extends HTMLPurifier_ChildDef
11 11
 {
12
-    public $allow_empty = true;
13
-    public $type = 'empty';
14
-    public function __construct() {}
15
-    public function validateChildren($tokens_of_children, $config, $context) {
16
-        return array();
17
-    }
12
+	public $allow_empty = true;
13
+	public $type = 'empty';
14
+	public function __construct() {}
15
+	public function validateChildren($tokens_of_children, $config, $context) {
16
+		return array();
17
+	}
18 18
 }
19 19
 
20 20
 // vim: et sw=4 sts=4
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/ChildDef/List.php 3 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -5,116 +5,116 @@
 block discarded – undo
5 5
  */
6 6
 class HTMLPurifier_ChildDef_List extends HTMLPurifier_ChildDef
7 7
 {
8
-    public $type = 'list';
9
-    // lying a little bit, so that we can handle ul and ol ourselves
10
-    // XXX: This whole business with 'wrap' is all a bit unsatisfactory
11
-    public $elements = array('li' => true, 'ul' => true, 'ol' => true);
12
-    public function validateChildren($tokens_of_children, $config, $context) {
13
-        // Flag for subclasses
14
-        $this->whitespace = false;
8
+	public $type = 'list';
9
+	// lying a little bit, so that we can handle ul and ol ourselves
10
+	// XXX: This whole business with 'wrap' is all a bit unsatisfactory
11
+	public $elements = array('li' => true, 'ul' => true, 'ol' => true);
12
+	public function validateChildren($tokens_of_children, $config, $context) {
13
+		// Flag for subclasses
14
+		$this->whitespace = false;
15 15
 
16
-        // if there are no tokens, delete parent node
17
-        if (empty($tokens_of_children)) return false;
16
+		// if there are no tokens, delete parent node
17
+		if (empty($tokens_of_children)) return false;
18 18
 
19
-        // the new set of children
20
-        $result = array();
19
+		// the new set of children
20
+		$result = array();
21 21
 
22
-        // current depth into the nest
23
-        $nesting = 0;
22
+		// current depth into the nest
23
+		$nesting = 0;
24 24
 
25
-        // a little sanity check to make sure it's not ALL whitespace
26
-        $all_whitespace = true;
25
+		// a little sanity check to make sure it's not ALL whitespace
26
+		$all_whitespace = true;
27 27
 
28
-        $seen_li = false;
29
-        $need_close_li = false;
28
+		$seen_li = false;
29
+		$need_close_li = false;
30 30
 
31
-        foreach ($tokens_of_children as $token) {
32
-            if (!empty($token->is_whitespace)) {
33
-                $result[] = $token;
34
-                continue;
35
-            }
36
-            $all_whitespace = false; // phew, we're not talking about whitespace
31
+		foreach ($tokens_of_children as $token) {
32
+			if (!empty($token->is_whitespace)) {
33
+				$result[] = $token;
34
+				continue;
35
+			}
36
+			$all_whitespace = false; // phew, we're not talking about whitespace
37 37
 
38
-            if ($nesting == 1 && $need_close_li) {
39
-                $result[] = new HTMLPurifier_Token_End('li');
40
-                $nesting--;
41
-                $need_close_li = false;
42
-            }
38
+			if ($nesting == 1 && $need_close_li) {
39
+				$result[] = new HTMLPurifier_Token_End('li');
40
+				$nesting--;
41
+				$need_close_li = false;
42
+			}
43 43
 
44
-            $is_child = ($nesting == 0);
44
+			$is_child = ($nesting == 0);
45 45
 
46
-            if ($token instanceof HTMLPurifier_Token_Start) {
47
-                $nesting++;
48
-            } elseif ($token instanceof HTMLPurifier_Token_End) {
49
-                $nesting--;
50
-            }
46
+			if ($token instanceof HTMLPurifier_Token_Start) {
47
+				$nesting++;
48
+			} elseif ($token instanceof HTMLPurifier_Token_End) {
49
+				$nesting--;
50
+			}
51 51
 
52
-            if ($is_child) {
53
-                if ($token->name === 'li') {
54
-                    // good
55
-                    $seen_li = true;
56
-                } elseif ($token->name === 'ul' || $token->name === 'ol') {
57
-                    // we want to tuck this into the previous li
58
-                    $need_close_li = true;
59
-                    $nesting++;
60
-                    if (!$seen_li) {
61
-                        // create a new li element
62
-                        $result[] = new HTMLPurifier_Token_Start('li');
63
-                    } else {
64
-                        // backtrack until </li> found
65
-                        while(true) {
66
-                            $t = array_pop($result);
67
-                            if ($t instanceof HTMLPurifier_Token_End) {
68
-                                // XXX actually, these invariants could very plausibly be violated
69
-                                // if we are doing silly things with modifying the set of allowed elements.
70
-                                // FORTUNATELY, it doesn't make a difference, since the allowed
71
-                                // elements are hard-coded here!
72
-                                if ($t->name !== 'li') {
73
-                                    trigger_error("Only li present invariant violated in List ChildDef", E_USER_ERROR);
74
-                                    return false;
75
-                                }
76
-                                break;
77
-                            } elseif ($t instanceof HTMLPurifier_Token_Empty) { // bleagh
78
-                                if ($t->name !== 'li') {
79
-                                    trigger_error("Only li present invariant violated in List ChildDef", E_USER_ERROR);
80
-                                    return false;
81
-                                }
82
-                                // XXX this should have a helper for it...
83
-                                $result[] = new HTMLPurifier_Token_Start('li', $t->attr, $t->line, $t->col, $t->armor);
84
-                                break;
85
-                            } else {
86
-                                if (!$t->is_whitespace) {
87
-                                    trigger_error("Only whitespace present invariant violated in List ChildDef", E_USER_ERROR);
88
-                                    return false;
89
-                                }
90
-                            }
91
-                        }
92
-                    }
93
-                } else {
94
-                    // start wrapping (this doesn't precisely mimic
95
-                    // browser behavior, but what browsers do is kind of
96
-                    // hard to mimic in a standards compliant way
97
-                    // XXX Actually, this has no impact in practice,
98
-                    // because this gets handled earlier. Arguably,
99
-                    // we should rip out all of that processing
100
-                    $result[] = new HTMLPurifier_Token_Start('li');
101
-                    $nesting++;
102
-                    $seen_li = true;
103
-                    $need_close_li = true;
104
-                }
105
-            }
106
-            $result[] = $token;
107
-        }
108
-        if ($need_close_li) {
109
-            $result[] = new HTMLPurifier_Token_End('li');
110
-        }
111
-        if (empty($result)) return false;
112
-        if ($all_whitespace) {
113
-            return false;
114
-        }
115
-        if ($tokens_of_children == $result) return true;
116
-        return $result;
117
-    }
52
+			if ($is_child) {
53
+				if ($token->name === 'li') {
54
+					// good
55
+					$seen_li = true;
56
+				} elseif ($token->name === 'ul' || $token->name === 'ol') {
57
+					// we want to tuck this into the previous li
58
+					$need_close_li = true;
59
+					$nesting++;
60
+					if (!$seen_li) {
61
+						// create a new li element
62
+						$result[] = new HTMLPurifier_Token_Start('li');
63
+					} else {
64
+						// backtrack until </li> found
65
+						while(true) {
66
+							$t = array_pop($result);
67
+							if ($t instanceof HTMLPurifier_Token_End) {
68
+								// XXX actually, these invariants could very plausibly be violated
69
+								// if we are doing silly things with modifying the set of allowed elements.
70
+								// FORTUNATELY, it doesn't make a difference, since the allowed
71
+								// elements are hard-coded here!
72
+								if ($t->name !== 'li') {
73
+									trigger_error("Only li present invariant violated in List ChildDef", E_USER_ERROR);
74
+									return false;
75
+								}
76
+								break;
77
+							} elseif ($t instanceof HTMLPurifier_Token_Empty) { // bleagh
78
+								if ($t->name !== 'li') {
79
+									trigger_error("Only li present invariant violated in List ChildDef", E_USER_ERROR);
80
+									return false;
81
+								}
82
+								// XXX this should have a helper for it...
83
+								$result[] = new HTMLPurifier_Token_Start('li', $t->attr, $t->line, $t->col, $t->armor);
84
+								break;
85
+							} else {
86
+								if (!$t->is_whitespace) {
87
+									trigger_error("Only whitespace present invariant violated in List ChildDef", E_USER_ERROR);
88
+									return false;
89
+								}
90
+							}
91
+						}
92
+					}
93
+				} else {
94
+					// start wrapping (this doesn't precisely mimic
95
+					// browser behavior, but what browsers do is kind of
96
+					// hard to mimic in a standards compliant way
97
+					// XXX Actually, this has no impact in practice,
98
+					// because this gets handled earlier. Arguably,
99
+					// we should rip out all of that processing
100
+					$result[] = new HTMLPurifier_Token_Start('li');
101
+					$nesting++;
102
+					$seen_li = true;
103
+					$need_close_li = true;
104
+				}
105
+			}
106
+			$result[] = $token;
107
+		}
108
+		if ($need_close_li) {
109
+			$result[] = new HTMLPurifier_Token_End('li');
110
+		}
111
+		if (empty($result)) return false;
112
+		if ($all_whitespace) {
113
+			return false;
114
+		}
115
+		if ($tokens_of_children == $result) return true;
116
+		return $result;
117
+	}
118 118
 }
119 119
 
120 120
 // vim: et sw=4 sts=4
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@
 block discarded – undo
62 62
                         $result[] = new HTMLPurifier_Token_Start('li');
63 63
                     } else {
64 64
                         // backtrack until </li> found
65
-                        while(true) {
65
+                        while (true) {
66 66
                             $t = array_pop($result);
67 67
                             if ($t instanceof HTMLPurifier_Token_End) {
68 68
                                 // XXX actually, these invariants could very plausibly be violated
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,7 +14,9 @@  discard block
 block discarded – undo
14 14
         $this->whitespace = false;
15 15
 
16 16
         // if there are no tokens, delete parent node
17
-        if (empty($tokens_of_children)) return false;
17
+        if (empty($tokens_of_children)) {
18
+        	return false;
19
+        }
18 20
 
19 21
         // the new set of children
20 22
         $result = array();
@@ -108,11 +110,15 @@  discard block
 block discarded – undo
108 110
         if ($need_close_li) {
109 111
             $result[] = new HTMLPurifier_Token_End('li');
110 112
         }
111
-        if (empty($result)) return false;
113
+        if (empty($result)) {
114
+        	return false;
115
+        }
112 116
         if ($all_whitespace) {
113 117
             return false;
114 118
         }
115
-        if ($tokens_of_children == $result) return true;
119
+        if ($tokens_of_children == $result) {
120
+        	return true;
121
+        }
116 122
         return $result;
117 123
     }
118 124
 }
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/ChildDef/Optional.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -9,18 +9,18 @@
 block discarded – undo
9 9
  */
10 10
 class HTMLPurifier_ChildDef_Optional extends HTMLPurifier_ChildDef_Required
11 11
 {
12
-    public $allow_empty = true;
13
-    public $type = 'optional';
14
-    public function validateChildren($tokens_of_children, $config, $context) {
15
-        $result = parent::validateChildren($tokens_of_children, $config, $context);
16
-        // we assume that $tokens_of_children is not modified
17
-        if ($result === false) {
18
-            if (empty($tokens_of_children)) return true;
19
-            elseif ($this->whitespace) return $tokens_of_children;
20
-            else return array();
21
-        }
22
-        return $result;
23
-    }
12
+	public $allow_empty = true;
13
+	public $type = 'optional';
14
+	public function validateChildren($tokens_of_children, $config, $context) {
15
+		$result = parent::validateChildren($tokens_of_children, $config, $context);
16
+		// we assume that $tokens_of_children is not modified
17
+		if ($result === false) {
18
+			if (empty($tokens_of_children)) return true;
19
+			elseif ($this->whitespace) return $tokens_of_children;
20
+			else return array();
21
+		}
22
+		return $result;
23
+	}
24 24
 }
25 25
 
26 26
 // vim: et sw=4 sts=4
Please login to merge, or discard this patch.
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,9 +15,13 @@
 block discarded – undo
15 15
         $result = parent::validateChildren($tokens_of_children, $config, $context);
16 16
         // we assume that $tokens_of_children is not modified
17 17
         if ($result === false) {
18
-            if (empty($tokens_of_children)) return true;
19
-            elseif ($this->whitespace) return $tokens_of_children;
20
-            else return array();
18
+            if (empty($tokens_of_children)) {
19
+            	return true;
20
+            } elseif ($this->whitespace) {
21
+            	return $tokens_of_children;
22
+            } else {
23
+            	return array();
24
+            }
21 25
         }
22 26
         return $result;
23 27
     }
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/ChildDef/Required.php 2 patches
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -5,113 +5,113 @@
 block discarded – undo
5 5
  */
6 6
 class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
7 7
 {
8
-    /**
9
-     * Lookup table of allowed elements.
10
-     * @public
11
-     */
12
-    public $elements = array();
13
-    /**
14
-     * Whether or not the last passed node was all whitespace.
15
-     */
16
-    protected $whitespace = false;
17
-    /**
18
-     * @param $elements List of allowed element names (lowercase).
19
-     */
20
-    public function __construct($elements) {
21
-        if (is_string($elements)) {
22
-            $elements = str_replace(' ', '', $elements);
23
-            $elements = explode('|', $elements);
24
-        }
25
-        $keys = array_keys($elements);
26
-        if ($keys == array_keys($keys)) {
27
-            $elements = array_flip($elements);
28
-            foreach ($elements as $i => $x) {
29
-                $elements[$i] = true;
30
-                if (empty($i)) unset($elements[$i]); // remove blank
31
-            }
32
-        }
33
-        $this->elements = $elements;
34
-    }
35
-    public $allow_empty = false;
36
-    public $type = 'required';
37
-    public function validateChildren($tokens_of_children, $config, $context) {
38
-        // Flag for subclasses
39
-        $this->whitespace = false;
8
+	/**
9
+	 * Lookup table of allowed elements.
10
+	 * @public
11
+	 */
12
+	public $elements = array();
13
+	/**
14
+	 * Whether or not the last passed node was all whitespace.
15
+	 */
16
+	protected $whitespace = false;
17
+	/**
18
+	 * @param $elements List of allowed element names (lowercase).
19
+	 */
20
+	public function __construct($elements) {
21
+		if (is_string($elements)) {
22
+			$elements = str_replace(' ', '', $elements);
23
+			$elements = explode('|', $elements);
24
+		}
25
+		$keys = array_keys($elements);
26
+		if ($keys == array_keys($keys)) {
27
+			$elements = array_flip($elements);
28
+			foreach ($elements as $i => $x) {
29
+				$elements[$i] = true;
30
+				if (empty($i)) unset($elements[$i]); // remove blank
31
+			}
32
+		}
33
+		$this->elements = $elements;
34
+	}
35
+	public $allow_empty = false;
36
+	public $type = 'required';
37
+	public function validateChildren($tokens_of_children, $config, $context) {
38
+		// Flag for subclasses
39
+		$this->whitespace = false;
40 40
 
41
-        // if there are no tokens, delete parent node
42
-        if (empty($tokens_of_children)) return false;
41
+		// if there are no tokens, delete parent node
42
+		if (empty($tokens_of_children)) return false;
43 43
 
44
-        // the new set of children
45
-        $result = array();
44
+		// the new set of children
45
+		$result = array();
46 46
 
47
-        // current depth into the nest
48
-        $nesting = 0;
47
+		// current depth into the nest
48
+		$nesting = 0;
49 49
 
50
-        // whether or not we're deleting a node
51
-        $is_deleting = false;
50
+		// whether or not we're deleting a node
51
+		$is_deleting = false;
52 52
 
53
-        // whether or not parsed character data is allowed
54
-        // this controls whether or not we silently drop a tag
55
-        // or generate escaped HTML from it
56
-        $pcdata_allowed = isset($this->elements['#PCDATA']);
53
+		// whether or not parsed character data is allowed
54
+		// this controls whether or not we silently drop a tag
55
+		// or generate escaped HTML from it
56
+		$pcdata_allowed = isset($this->elements['#PCDATA']);
57 57
 
58
-        // a little sanity check to make sure it's not ALL whitespace
59
-        $all_whitespace = true;
58
+		// a little sanity check to make sure it's not ALL whitespace
59
+		$all_whitespace = true;
60 60
 
61
-        // some configuration
62
-        $escape_invalid_children = $config->get('Core.EscapeInvalidChildren');
61
+		// some configuration
62
+		$escape_invalid_children = $config->get('Core.EscapeInvalidChildren');
63 63
 
64
-        // generator
65
-        $gen = new HTMLPurifier_Generator($config, $context);
64
+		// generator
65
+		$gen = new HTMLPurifier_Generator($config, $context);
66 66
 
67
-        foreach ($tokens_of_children as $token) {
68
-            if (!empty($token->is_whitespace)) {
69
-                $result[] = $token;
70
-                continue;
71
-            }
72
-            $all_whitespace = false; // phew, we're not talking about whitespace
67
+		foreach ($tokens_of_children as $token) {
68
+			if (!empty($token->is_whitespace)) {
69
+				$result[] = $token;
70
+				continue;
71
+			}
72
+			$all_whitespace = false; // phew, we're not talking about whitespace
73 73
 
74
-            $is_child = ($nesting == 0);
74
+			$is_child = ($nesting == 0);
75 75
 
76
-            if ($token instanceof HTMLPurifier_Token_Start) {
77
-                $nesting++;
78
-            } elseif ($token instanceof HTMLPurifier_Token_End) {
79
-                $nesting--;
80
-            }
76
+			if ($token instanceof HTMLPurifier_Token_Start) {
77
+				$nesting++;
78
+			} elseif ($token instanceof HTMLPurifier_Token_End) {
79
+				$nesting--;
80
+			}
81 81
 
82
-            if ($is_child) {
83
-                $is_deleting = false;
84
-                if (!isset($this->elements[$token->name])) {
85
-                    $is_deleting = true;
86
-                    if ($pcdata_allowed && $token instanceof HTMLPurifier_Token_Text) {
87
-                        $result[] = $token;
88
-                    } elseif ($pcdata_allowed && $escape_invalid_children) {
89
-                        $result[] = new HTMLPurifier_Token_Text(
90
-                            $gen->generateFromToken($token)
91
-                        );
92
-                    }
93
-                    continue;
94
-                }
95
-            }
96
-            if (!$is_deleting || ($pcdata_allowed && $token instanceof HTMLPurifier_Token_Text)) {
97
-                $result[] = $token;
98
-            } elseif ($pcdata_allowed && $escape_invalid_children) {
99
-                $result[] =
100
-                    new HTMLPurifier_Token_Text(
101
-                        $gen->generateFromToken($token)
102
-                    );
103
-            } else {
104
-                // drop silently
105
-            }
106
-        }
107
-        if (empty($result)) return false;
108
-        if ($all_whitespace) {
109
-            $this->whitespace = true;
110
-            return false;
111
-        }
112
-        if ($tokens_of_children == $result) return true;
113
-        return $result;
114
-    }
82
+			if ($is_child) {
83
+				$is_deleting = false;
84
+				if (!isset($this->elements[$token->name])) {
85
+					$is_deleting = true;
86
+					if ($pcdata_allowed && $token instanceof HTMLPurifier_Token_Text) {
87
+						$result[] = $token;
88
+					} elseif ($pcdata_allowed && $escape_invalid_children) {
89
+						$result[] = new HTMLPurifier_Token_Text(
90
+							$gen->generateFromToken($token)
91
+						);
92
+					}
93
+					continue;
94
+				}
95
+			}
96
+			if (!$is_deleting || ($pcdata_allowed && $token instanceof HTMLPurifier_Token_Text)) {
97
+				$result[] = $token;
98
+			} elseif ($pcdata_allowed && $escape_invalid_children) {
99
+				$result[] =
100
+					new HTMLPurifier_Token_Text(
101
+						$gen->generateFromToken($token)
102
+					);
103
+			} else {
104
+				// drop silently
105
+			}
106
+		}
107
+		if (empty($result)) return false;
108
+		if ($all_whitespace) {
109
+			$this->whitespace = true;
110
+			return false;
111
+		}
112
+		if ($tokens_of_children == $result) return true;
113
+		return $result;
114
+	}
115 115
 }
116 116
 
117 117
 // vim: et sw=4 sts=4
Please login to merge, or discard this patch.
Braces   +13 added lines, -4 removed lines patch added patch discarded remove patch
@@ -27,7 +27,10 @@  discard block
 block discarded – undo
27 27
             $elements = array_flip($elements);
28 28
             foreach ($elements as $i => $x) {
29 29
                 $elements[$i] = true;
30
-                if (empty($i)) unset($elements[$i]); // remove blank
30
+                if (empty($i)) {
31
+                	unset($elements[$i]);
32
+                }
33
+                // remove blank
31 34
             }
32 35
         }
33 36
         $this->elements = $elements;
@@ -39,7 +42,9 @@  discard block
 block discarded – undo
39 42
         $this->whitespace = false;
40 43
 
41 44
         // if there are no tokens, delete parent node
42
-        if (empty($tokens_of_children)) return false;
45
+        if (empty($tokens_of_children)) {
46
+        	return false;
47
+        }
43 48
 
44 49
         // the new set of children
45 50
         $result = array();
@@ -104,12 +109,16 @@  discard block
 block discarded – undo
104 109
                 // drop silently
105 110
             }
106 111
         }
107
-        if (empty($result)) return false;
112
+        if (empty($result)) {
113
+        	return false;
114
+        }
108 115
         if ($all_whitespace) {
109 116
             $this->whitespace = true;
110 117
             return false;
111 118
         }
112
-        if ($tokens_of_children == $result) return true;
119
+        if ($tokens_of_children == $result) {
120
+        	return true;
121
+        }
113 122
         return $result;
114 123
     }
115 124
 }
Please login to merge, or discard this patch.