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 ( 78ace2...4b54c6 )
by gyeong-won
09:15
created
classes/security/htmlpurifier/library/HTMLPurifier/Printer/ConfigForm.php 3 patches
Indentation   +316 added lines, -316 removed lines patch added patch discarded remove patch
@@ -6,179 +6,179 @@  discard block
 block discarded – undo
6 6
 class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer
7 7
 {
8 8
 
9
-    /**
10
-     * Printers for specific fields
11
-     */
12
-    protected $fields = array();
9
+	/**
10
+	 * Printers for specific fields
11
+	 */
12
+	protected $fields = array();
13 13
 
14
-    /**
15
-     * Documentation URL, can have fragment tagged on end
16
-     */
17
-    protected $docURL;
14
+	/**
15
+	 * Documentation URL, can have fragment tagged on end
16
+	 */
17
+	protected $docURL;
18 18
 
19
-    /**
20
-     * Name of form element to stuff config in
21
-     */
22
-    protected $name;
19
+	/**
20
+	 * Name of form element to stuff config in
21
+	 */
22
+	protected $name;
23 23
 
24
-    /**
25
-     * Whether or not to compress directive names, clipping them off
26
-     * after a certain amount of letters. False to disable or integer letters
27
-     * before clipping.
28
-     */
29
-    protected $compress = false;
24
+	/**
25
+	 * Whether or not to compress directive names, clipping them off
26
+	 * after a certain amount of letters. False to disable or integer letters
27
+	 * before clipping.
28
+	 */
29
+	protected $compress = false;
30 30
 
31
-    /**
32
-     * @param $name Form element name for directives to be stuffed into
33
-     * @param $doc_url String documentation URL, will have fragment tagged on
34
-     * @param $compress Integer max length before compressing a directive name, set to false to turn off
35
-     */
36
-    public function __construct(
37
-        $name, $doc_url = null, $compress = false
38
-    ) {
39
-        parent::__construct();
40
-        $this->docURL = $doc_url;
41
-        $this->name   = $name;
42
-        $this->compress = $compress;
43
-        // initialize sub-printers
44
-        $this->fields[0]    = new HTMLPurifier_Printer_ConfigForm_default();
45
-        $this->fields[HTMLPurifier_VarParser::BOOL]       = new HTMLPurifier_Printer_ConfigForm_bool();
46
-    }
31
+	/**
32
+	 * @param $name Form element name for directives to be stuffed into
33
+	 * @param $doc_url String documentation URL, will have fragment tagged on
34
+	 * @param $compress Integer max length before compressing a directive name, set to false to turn off
35
+	 */
36
+	public function __construct(
37
+		$name, $doc_url = null, $compress = false
38
+	) {
39
+		parent::__construct();
40
+		$this->docURL = $doc_url;
41
+		$this->name   = $name;
42
+		$this->compress = $compress;
43
+		// initialize sub-printers
44
+		$this->fields[0]    = new HTMLPurifier_Printer_ConfigForm_default();
45
+		$this->fields[HTMLPurifier_VarParser::BOOL]       = new HTMLPurifier_Printer_ConfigForm_bool();
46
+	}
47 47
 
48
-    /**
49
-     * Sets default column and row size for textareas in sub-printers
50
-     * @param $cols Integer columns of textarea, null to use default
51
-     * @param $rows Integer rows of textarea, null to use default
52
-     */
53
-    public function setTextareaDimensions($cols = null, $rows = null) {
54
-        if ($cols) $this->fields['default']->cols = $cols;
55
-        if ($rows) $this->fields['default']->rows = $rows;
56
-    }
48
+	/**
49
+	 * Sets default column and row size for textareas in sub-printers
50
+	 * @param $cols Integer columns of textarea, null to use default
51
+	 * @param $rows Integer rows of textarea, null to use default
52
+	 */
53
+	public function setTextareaDimensions($cols = null, $rows = null) {
54
+		if ($cols) $this->fields['default']->cols = $cols;
55
+		if ($rows) $this->fields['default']->rows = $rows;
56
+	}
57 57
 
58
-    /**
59
-     * Retrieves styling, in case it is not accessible by webserver
60
-     */
61
-    public static function getCSS() {
62
-        return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.css');
63
-    }
58
+	/**
59
+	 * Retrieves styling, in case it is not accessible by webserver
60
+	 */
61
+	public static function getCSS() {
62
+		return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.css');
63
+	}
64 64
 
65
-    /**
66
-     * Retrieves JavaScript, in case it is not accessible by webserver
67
-     */
68
-    public static function getJavaScript() {
69
-        return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.js');
70
-    }
65
+	/**
66
+	 * Retrieves JavaScript, in case it is not accessible by webserver
67
+	 */
68
+	public static function getJavaScript() {
69
+		return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.js');
70
+	}
71 71
 
72
-    /**
73
-     * Returns HTML output for a configuration form
74
-     * @param $config Configuration object of current form state, or an array
75
-     *        where [0] has an HTML namespace and [1] is being rendered.
76
-     * @param $allowed Optional namespace(s) and directives to restrict form to.
77
-     */
78
-    public function render($config, $allowed = true, $render_controls = true) {
79
-        if (is_array($config) && isset($config[0])) {
80
-            $gen_config = $config[0];
81
-            $config = $config[1];
82
-        } else {
83
-            $gen_config = $config;
84
-        }
72
+	/**
73
+	 * Returns HTML output for a configuration form
74
+	 * @param $config Configuration object of current form state, or an array
75
+	 *        where [0] has an HTML namespace and [1] is being rendered.
76
+	 * @param $allowed Optional namespace(s) and directives to restrict form to.
77
+	 */
78
+	public function render($config, $allowed = true, $render_controls = true) {
79
+		if (is_array($config) && isset($config[0])) {
80
+			$gen_config = $config[0];
81
+			$config = $config[1];
82
+		} else {
83
+			$gen_config = $config;
84
+		}
85 85
 
86
-        $this->config = $config;
87
-        $this->genConfig = $gen_config;
88
-        $this->prepareGenerator($gen_config);
86
+		$this->config = $config;
87
+		$this->genConfig = $gen_config;
88
+		$this->prepareGenerator($gen_config);
89 89
 
90
-        $allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $config->def);
91
-        $all = array();
92
-        foreach ($allowed as $key) {
93
-            list($ns, $directive) = $key;
94
-            $all[$ns][$directive] = $config->get($ns .'.'. $directive);
95
-        }
90
+		$allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $config->def);
91
+		$all = array();
92
+		foreach ($allowed as $key) {
93
+			list($ns, $directive) = $key;
94
+			$all[$ns][$directive] = $config->get($ns .'.'. $directive);
95
+		}
96 96
 
97
-        $ret = '';
98
-        $ret .= $this->start('table', array('class' => 'hp-config'));
99
-        $ret .= $this->start('thead');
100
-        $ret .= $this->start('tr');
101
-            $ret .= $this->element('th', 'Directive', array('class' => 'hp-directive'));
102
-            $ret .= $this->element('th', 'Value', array('class' => 'hp-value'));
103
-        $ret .= $this->end('tr');
104
-        $ret .= $this->end('thead');
105
-        foreach ($all as $ns => $directives) {
106
-            $ret .= $this->renderNamespace($ns, $directives);
107
-        }
108
-        if ($render_controls) {
109
-             $ret .= $this->start('tbody');
110
-             $ret .= $this->start('tr');
111
-                 $ret .= $this->start('td', array('colspan' => 2, 'class' => 'controls'));
112
-                     $ret .= $this->elementEmpty('input', array('type' => 'submit', 'value' => 'Submit'));
113
-                     $ret .= '[<a href="?">Reset</a>]';
114
-                 $ret .= $this->end('td');
115
-             $ret .= $this->end('tr');
116
-             $ret .= $this->end('tbody');
117
-        }
118
-        $ret .= $this->end('table');
119
-        return $ret;
120
-    }
97
+		$ret = '';
98
+		$ret .= $this->start('table', array('class' => 'hp-config'));
99
+		$ret .= $this->start('thead');
100
+		$ret .= $this->start('tr');
101
+			$ret .= $this->element('th', 'Directive', array('class' => 'hp-directive'));
102
+			$ret .= $this->element('th', 'Value', array('class' => 'hp-value'));
103
+		$ret .= $this->end('tr');
104
+		$ret .= $this->end('thead');
105
+		foreach ($all as $ns => $directives) {
106
+			$ret .= $this->renderNamespace($ns, $directives);
107
+		}
108
+		if ($render_controls) {
109
+			 $ret .= $this->start('tbody');
110
+			 $ret .= $this->start('tr');
111
+				 $ret .= $this->start('td', array('colspan' => 2, 'class' => 'controls'));
112
+					 $ret .= $this->elementEmpty('input', array('type' => 'submit', 'value' => 'Submit'));
113
+					 $ret .= '[<a href="?">Reset</a>]';
114
+				 $ret .= $this->end('td');
115
+			 $ret .= $this->end('tr');
116
+			 $ret .= $this->end('tbody');
117
+		}
118
+		$ret .= $this->end('table');
119
+		return $ret;
120
+	}
121 121
 
122
-    /**
123
-     * Renders a single namespace
124
-     * @param $ns String namespace name
125
-     * @param $directive Associative array of directives to values
126
-     */
127
-    protected function renderNamespace($ns, $directives) {
128
-        $ret = '';
129
-        $ret .= $this->start('tbody', array('class' => 'namespace'));
130
-        $ret .= $this->start('tr');
131
-            $ret .= $this->element('th', $ns, array('colspan' => 2));
132
-        $ret .= $this->end('tr');
133
-        $ret .= $this->end('tbody');
134
-        $ret .= $this->start('tbody');
135
-        foreach ($directives as $directive => $value) {
136
-            $ret .= $this->start('tr');
137
-            $ret .= $this->start('th');
138
-            if ($this->docURL) {
139
-                $url = str_replace('%s', urlencode("$ns.$directive"), $this->docURL);
140
-                $ret .= $this->start('a', array('href' => $url));
141
-            }
142
-                $attr = array('for' => "{$this->name}:$ns.$directive");
122
+	/**
123
+	 * Renders a single namespace
124
+	 * @param $ns String namespace name
125
+	 * @param $directive Associative array of directives to values
126
+	 */
127
+	protected function renderNamespace($ns, $directives) {
128
+		$ret = '';
129
+		$ret .= $this->start('tbody', array('class' => 'namespace'));
130
+		$ret .= $this->start('tr');
131
+			$ret .= $this->element('th', $ns, array('colspan' => 2));
132
+		$ret .= $this->end('tr');
133
+		$ret .= $this->end('tbody');
134
+		$ret .= $this->start('tbody');
135
+		foreach ($directives as $directive => $value) {
136
+			$ret .= $this->start('tr');
137
+			$ret .= $this->start('th');
138
+			if ($this->docURL) {
139
+				$url = str_replace('%s', urlencode("$ns.$directive"), $this->docURL);
140
+				$ret .= $this->start('a', array('href' => $url));
141
+			}
142
+				$attr = array('for' => "{$this->name}:$ns.$directive");
143 143
 
144
-                // crop directive name if it's too long
145
-                if (!$this->compress || (strlen($directive) < $this->compress)) {
146
-                    $directive_disp = $directive;
147
-                } else {
148
-                    $directive_disp = substr($directive, 0, $this->compress - 2) . '...';
149
-                    $attr['title'] = $directive;
150
-                }
144
+				// crop directive name if it's too long
145
+				if (!$this->compress || (strlen($directive) < $this->compress)) {
146
+					$directive_disp = $directive;
147
+				} else {
148
+					$directive_disp = substr($directive, 0, $this->compress - 2) . '...';
149
+					$attr['title'] = $directive;
150
+				}
151 151
 
152
-                $ret .= $this->element(
153
-                    'label',
154
-                    $directive_disp,
155
-                    // component printers must create an element with this id
156
-                    $attr
157
-                );
158
-            if ($this->docURL) $ret .= $this->end('a');
159
-            $ret .= $this->end('th');
152
+				$ret .= $this->element(
153
+					'label',
154
+					$directive_disp,
155
+					// component printers must create an element with this id
156
+					$attr
157
+				);
158
+			if ($this->docURL) $ret .= $this->end('a');
159
+			$ret .= $this->end('th');
160 160
 
161
-            $ret .= $this->start('td');
162
-                $def = $this->config->def->info["$ns.$directive"];
163
-                if (is_int($def)) {
164
-                    $allow_null = $def < 0;
165
-                    $type = abs($def);
166
-                } else {
167
-                    $type = $def->type;
168
-                    $allow_null = isset($def->allow_null);
169
-                }
170
-                if (!isset($this->fields[$type])) $type = 0; // default
171
-                $type_obj = $this->fields[$type];
172
-                if ($allow_null) {
173
-                    $type_obj = new HTMLPurifier_Printer_ConfigForm_NullDecorator($type_obj);
174
-                }
175
-                $ret .= $type_obj->render($ns, $directive, $value, $this->name, array($this->genConfig, $this->config));
176
-            $ret .= $this->end('td');
177
-            $ret .= $this->end('tr');
178
-        }
179
-        $ret .= $this->end('tbody');
180
-        return $ret;
181
-    }
161
+			$ret .= $this->start('td');
162
+				$def = $this->config->def->info["$ns.$directive"];
163
+				if (is_int($def)) {
164
+					$allow_null = $def < 0;
165
+					$type = abs($def);
166
+				} else {
167
+					$type = $def->type;
168
+					$allow_null = isset($def->allow_null);
169
+				}
170
+				if (!isset($this->fields[$type])) $type = 0; // default
171
+				$type_obj = $this->fields[$type];
172
+				if ($allow_null) {
173
+					$type_obj = new HTMLPurifier_Printer_ConfigForm_NullDecorator($type_obj);
174
+				}
175
+				$ret .= $type_obj->render($ns, $directive, $value, $this->name, array($this->genConfig, $this->config));
176
+			$ret .= $this->end('td');
177
+			$ret .= $this->end('tr');
178
+		}
179
+		$ret .= $this->end('tbody');
180
+		return $ret;
181
+	}
182 182
 
183 183
 }
184 184
 
@@ -186,183 +186,183 @@  discard block
 block discarded – undo
186 186
  * Printer decorator for directives that accept null
187 187
  */
188 188
 class HTMLPurifier_Printer_ConfigForm_NullDecorator extends HTMLPurifier_Printer {
189
-    /**
190
-     * Printer being decorated
191
-     */
192
-    protected $obj;
193
-    /**
194
-     * @param $obj Printer to decorate
195
-     */
196
-    public function __construct($obj) {
197
-        parent::__construct();
198
-        $this->obj = $obj;
199
-    }
200
-    public function render($ns, $directive, $value, $name, $config) {
201
-        if (is_array($config) && isset($config[0])) {
202
-            $gen_config = $config[0];
203
-            $config = $config[1];
204
-        } else {
205
-            $gen_config = $config;
206
-        }
207
-        $this->prepareGenerator($gen_config);
189
+	/**
190
+	 * Printer being decorated
191
+	 */
192
+	protected $obj;
193
+	/**
194
+	 * @param $obj Printer to decorate
195
+	 */
196
+	public function __construct($obj) {
197
+		parent::__construct();
198
+		$this->obj = $obj;
199
+	}
200
+	public function render($ns, $directive, $value, $name, $config) {
201
+		if (is_array($config) && isset($config[0])) {
202
+			$gen_config = $config[0];
203
+			$config = $config[1];
204
+		} else {
205
+			$gen_config = $config;
206
+		}
207
+		$this->prepareGenerator($gen_config);
208 208
 
209
-        $ret = '';
210
-        $ret .= $this->start('label', array('for' => "$name:Null_$ns.$directive"));
211
-        $ret .= $this->element('span', "$ns.$directive:", array('class' => 'verbose'));
212
-        $ret .= $this->text(' Null/Disabled');
213
-        $ret .= $this->end('label');
214
-        $attr = array(
215
-            'type' => 'checkbox',
216
-            'value' => '1',
217
-            'class' => 'null-toggle',
218
-            'name' => "$name"."[Null_$ns.$directive]",
219
-            'id' => "$name:Null_$ns.$directive",
220
-            'onclick' => "toggleWriteability('$name:$ns.$directive',checked)" // INLINE JAVASCRIPT!!!!
221
-        );
222
-        if ($this->obj instanceof HTMLPurifier_Printer_ConfigForm_bool) {
223
-            // modify inline javascript slightly
224
-            $attr['onclick'] = "toggleWriteability('$name:Yes_$ns.$directive',checked);toggleWriteability('$name:No_$ns.$directive',checked)";
225
-        }
226
-        if ($value === null) $attr['checked'] = 'checked';
227
-        $ret .= $this->elementEmpty('input', $attr);
228
-        $ret .= $this->text(' or ');
229
-        $ret .= $this->elementEmpty('br');
230
-        $ret .= $this->obj->render($ns, $directive, $value, $name, array($gen_config, $config));
231
-        return $ret;
232
-    }
209
+		$ret = '';
210
+		$ret .= $this->start('label', array('for' => "$name:Null_$ns.$directive"));
211
+		$ret .= $this->element('span', "$ns.$directive:", array('class' => 'verbose'));
212
+		$ret .= $this->text(' Null/Disabled');
213
+		$ret .= $this->end('label');
214
+		$attr = array(
215
+			'type' => 'checkbox',
216
+			'value' => '1',
217
+			'class' => 'null-toggle',
218
+			'name' => "$name"."[Null_$ns.$directive]",
219
+			'id' => "$name:Null_$ns.$directive",
220
+			'onclick' => "toggleWriteability('$name:$ns.$directive',checked)" // INLINE JAVASCRIPT!!!!
221
+		);
222
+		if ($this->obj instanceof HTMLPurifier_Printer_ConfigForm_bool) {
223
+			// modify inline javascript slightly
224
+			$attr['onclick'] = "toggleWriteability('$name:Yes_$ns.$directive',checked);toggleWriteability('$name:No_$ns.$directive',checked)";
225
+		}
226
+		if ($value === null) $attr['checked'] = 'checked';
227
+		$ret .= $this->elementEmpty('input', $attr);
228
+		$ret .= $this->text(' or ');
229
+		$ret .= $this->elementEmpty('br');
230
+		$ret .= $this->obj->render($ns, $directive, $value, $name, array($gen_config, $config));
231
+		return $ret;
232
+	}
233 233
 }
234 234
 
235 235
 /**
236 236
  * Swiss-army knife configuration form field printer
237 237
  */
238 238
 class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer {
239
-    public $cols = 18;
240
-    public $rows = 5;
241
-    public function render($ns, $directive, $value, $name, $config) {
242
-        if (is_array($config) && isset($config[0])) {
243
-            $gen_config = $config[0];
244
-            $config = $config[1];
245
-        } else {
246
-            $gen_config = $config;
247
-        }
248
-        $this->prepareGenerator($gen_config);
249
-        // this should probably be split up a little
250
-        $ret = '';
251
-        $def = $config->def->info["$ns.$directive"];
252
-        if (is_int($def)) {
253
-            $type = abs($def);
254
-        } else {
255
-            $type = $def->type;
256
-        }
257
-        if (is_array($value)) {
258
-            switch ($type) {
259
-                case HTMLPurifier_VarParser::LOOKUP:
260
-                    $array = $value;
261
-                    $value = array();
262
-                    foreach ($array as $val => $b) {
263
-                        $value[] = $val;
264
-                    }
265
-                case HTMLPurifier_VarParser::ALIST:
266
-                    $value = implode(PHP_EOL, $value);
267
-                    break;
268
-                case HTMLPurifier_VarParser::HASH:
269
-                    $nvalue = '';
270
-                    foreach ($value as $i => $v) {
271
-                        $nvalue .= "$i:$v" . PHP_EOL;
272
-                    }
273
-                    $value = $nvalue;
274
-                    break;
275
-                default:
276
-                    $value = '';
277
-            }
278
-        }
279
-        if ($type === HTMLPurifier_VarParser::MIXED) {
280
-            return 'Not supported';
281
-            $value = serialize($value);
282
-        }
283
-        $attr = array(
284
-            'name' => "$name"."[$ns.$directive]",
285
-            'id' => "$name:$ns.$directive"
286
-        );
287
-        if ($value === null) $attr['disabled'] = 'disabled';
288
-        if (isset($def->allowed)) {
289
-            $ret .= $this->start('select', $attr);
290
-            foreach ($def->allowed as $val => $b) {
291
-                $attr = array();
292
-                if ($value == $val) $attr['selected'] = 'selected';
293
-                $ret .= $this->element('option', $val, $attr);
294
-            }
295
-            $ret .= $this->end('select');
296
-        } elseif (
297
-            $type === HTMLPurifier_VarParser::TEXT ||
298
-            $type === HTMLPurifier_VarParser::ITEXT ||
299
-            $type === HTMLPurifier_VarParser::ALIST ||
300
-            $type === HTMLPurifier_VarParser::HASH ||
301
-            $type === HTMLPurifier_VarParser::LOOKUP
302
-        ) {
303
-            $attr['cols'] = $this->cols;
304
-            $attr['rows'] = $this->rows;
305
-            $ret .= $this->start('textarea', $attr);
306
-            $ret .= $this->text($value);
307
-            $ret .= $this->end('textarea');
308
-        } else {
309
-            $attr['value'] = $value;
310
-            $attr['type'] = 'text';
311
-            $ret .= $this->elementEmpty('input', $attr);
312
-        }
313
-        return $ret;
314
-    }
239
+	public $cols = 18;
240
+	public $rows = 5;
241
+	public function render($ns, $directive, $value, $name, $config) {
242
+		if (is_array($config) && isset($config[0])) {
243
+			$gen_config = $config[0];
244
+			$config = $config[1];
245
+		} else {
246
+			$gen_config = $config;
247
+		}
248
+		$this->prepareGenerator($gen_config);
249
+		// this should probably be split up a little
250
+		$ret = '';
251
+		$def = $config->def->info["$ns.$directive"];
252
+		if (is_int($def)) {
253
+			$type = abs($def);
254
+		} else {
255
+			$type = $def->type;
256
+		}
257
+		if (is_array($value)) {
258
+			switch ($type) {
259
+				case HTMLPurifier_VarParser::LOOKUP:
260
+					$array = $value;
261
+					$value = array();
262
+					foreach ($array as $val => $b) {
263
+						$value[] = $val;
264
+					}
265
+				case HTMLPurifier_VarParser::ALIST:
266
+					$value = implode(PHP_EOL, $value);
267
+					break;
268
+				case HTMLPurifier_VarParser::HASH:
269
+					$nvalue = '';
270
+					foreach ($value as $i => $v) {
271
+						$nvalue .= "$i:$v" . PHP_EOL;
272
+					}
273
+					$value = $nvalue;
274
+					break;
275
+				default:
276
+					$value = '';
277
+			}
278
+		}
279
+		if ($type === HTMLPurifier_VarParser::MIXED) {
280
+			return 'Not supported';
281
+			$value = serialize($value);
282
+		}
283
+		$attr = array(
284
+			'name' => "$name"."[$ns.$directive]",
285
+			'id' => "$name:$ns.$directive"
286
+		);
287
+		if ($value === null) $attr['disabled'] = 'disabled';
288
+		if (isset($def->allowed)) {
289
+			$ret .= $this->start('select', $attr);
290
+			foreach ($def->allowed as $val => $b) {
291
+				$attr = array();
292
+				if ($value == $val) $attr['selected'] = 'selected';
293
+				$ret .= $this->element('option', $val, $attr);
294
+			}
295
+			$ret .= $this->end('select');
296
+		} elseif (
297
+			$type === HTMLPurifier_VarParser::TEXT ||
298
+			$type === HTMLPurifier_VarParser::ITEXT ||
299
+			$type === HTMLPurifier_VarParser::ALIST ||
300
+			$type === HTMLPurifier_VarParser::HASH ||
301
+			$type === HTMLPurifier_VarParser::LOOKUP
302
+		) {
303
+			$attr['cols'] = $this->cols;
304
+			$attr['rows'] = $this->rows;
305
+			$ret .= $this->start('textarea', $attr);
306
+			$ret .= $this->text($value);
307
+			$ret .= $this->end('textarea');
308
+		} else {
309
+			$attr['value'] = $value;
310
+			$attr['type'] = 'text';
311
+			$ret .= $this->elementEmpty('input', $attr);
312
+		}
313
+		return $ret;
314
+	}
315 315
 }
316 316
 
317 317
 /**
318 318
  * Bool form field printer
319 319
  */
320 320
 class HTMLPurifier_Printer_ConfigForm_bool extends HTMLPurifier_Printer {
321
-    public function render($ns, $directive, $value, $name, $config) {
322
-        if (is_array($config) && isset($config[0])) {
323
-            $gen_config = $config[0];
324
-            $config = $config[1];
325
-        } else {
326
-            $gen_config = $config;
327
-        }
328
-        $this->prepareGenerator($gen_config);
329
-        $ret = '';
330
-        $ret .= $this->start('div', array('id' => "$name:$ns.$directive"));
321
+	public function render($ns, $directive, $value, $name, $config) {
322
+		if (is_array($config) && isset($config[0])) {
323
+			$gen_config = $config[0];
324
+			$config = $config[1];
325
+		} else {
326
+			$gen_config = $config;
327
+		}
328
+		$this->prepareGenerator($gen_config);
329
+		$ret = '';
330
+		$ret .= $this->start('div', array('id' => "$name:$ns.$directive"));
331 331
 
332
-        $ret .= $this->start('label', array('for' => "$name:Yes_$ns.$directive"));
333
-        $ret .= $this->element('span', "$ns.$directive:", array('class' => 'verbose'));
334
-        $ret .= $this->text(' Yes');
335
-        $ret .= $this->end('label');
332
+		$ret .= $this->start('label', array('for' => "$name:Yes_$ns.$directive"));
333
+		$ret .= $this->element('span', "$ns.$directive:", array('class' => 'verbose'));
334
+		$ret .= $this->text(' Yes');
335
+		$ret .= $this->end('label');
336 336
 
337
-        $attr = array(
338
-            'type' => 'radio',
339
-            'name' => "$name"."[$ns.$directive]",
340
-            'id' => "$name:Yes_$ns.$directive",
341
-            'value' => '1'
342
-        );
343
-        if ($value === true) $attr['checked'] = 'checked';
344
-        if ($value === null) $attr['disabled'] = 'disabled';
345
-        $ret .= $this->elementEmpty('input', $attr);
337
+		$attr = array(
338
+			'type' => 'radio',
339
+			'name' => "$name"."[$ns.$directive]",
340
+			'id' => "$name:Yes_$ns.$directive",
341
+			'value' => '1'
342
+		);
343
+		if ($value === true) $attr['checked'] = 'checked';
344
+		if ($value === null) $attr['disabled'] = 'disabled';
345
+		$ret .= $this->elementEmpty('input', $attr);
346 346
 
347
-        $ret .= $this->start('label', array('for' => "$name:No_$ns.$directive"));
348
-        $ret .= $this->element('span', "$ns.$directive:", array('class' => 'verbose'));
349
-        $ret .= $this->text(' No');
350
-        $ret .= $this->end('label');
347
+		$ret .= $this->start('label', array('for' => "$name:No_$ns.$directive"));
348
+		$ret .= $this->element('span', "$ns.$directive:", array('class' => 'verbose'));
349
+		$ret .= $this->text(' No');
350
+		$ret .= $this->end('label');
351 351
 
352
-        $attr = array(
353
-            'type' => 'radio',
354
-            'name' => "$name"."[$ns.$directive]",
355
-            'id' => "$name:No_$ns.$directive",
356
-            'value' => '0'
357
-        );
358
-        if ($value === false) $attr['checked'] = 'checked';
359
-        if ($value === null) $attr['disabled'] = 'disabled';
360
-        $ret .= $this->elementEmpty('input', $attr);
352
+		$attr = array(
353
+			'type' => 'radio',
354
+			'name' => "$name"."[$ns.$directive]",
355
+			'id' => "$name:No_$ns.$directive",
356
+			'value' => '0'
357
+		);
358
+		if ($value === false) $attr['checked'] = 'checked';
359
+		if ($value === null) $attr['disabled'] = 'disabled';
360
+		$ret .= $this->elementEmpty('input', $attr);
361 361
 
362
-        $ret .= $this->end('div');
362
+		$ret .= $this->end('div');
363 363
 
364
-        return $ret;
365
-    }
364
+		return $ret;
365
+	}
366 366
 }
367 367
 
368 368
 // vim: et sw=4 sts=4
Please login to merge, or discard this patch.
Braces   +34 added lines, -11 removed lines patch added patch discarded remove patch
@@ -51,8 +51,12 @@  discard block
 block discarded – undo
51 51
      * @param $rows Integer rows of textarea, null to use default
52 52
      */
53 53
     public function setTextareaDimensions($cols = null, $rows = null) {
54
-        if ($cols) $this->fields['default']->cols = $cols;
55
-        if ($rows) $this->fields['default']->rows = $rows;
54
+        if ($cols) {
55
+        	$this->fields['default']->cols = $cols;
56
+        }
57
+        if ($rows) {
58
+        	$this->fields['default']->rows = $rows;
59
+        }
56 60
     }
57 61
 
58 62
     /**
@@ -155,7 +159,9 @@  discard block
 block discarded – undo
155 159
                     // component printers must create an element with this id
156 160
                     $attr
157 161
                 );
158
-            if ($this->docURL) $ret .= $this->end('a');
162
+            if ($this->docURL) {
163
+            	$ret .= $this->end('a');
164
+            }
159 165
             $ret .= $this->end('th');
160 166
 
161 167
             $ret .= $this->start('td');
@@ -167,7 +173,10 @@  discard block
 block discarded – undo
167 173
                     $type = $def->type;
168 174
                     $allow_null = isset($def->allow_null);
169 175
                 }
170
-                if (!isset($this->fields[$type])) $type = 0; // default
176
+                if (!isset($this->fields[$type])) {
177
+                	$type = 0;
178
+                }
179
+                // default
171 180
                 $type_obj = $this->fields[$type];
172 181
                 if ($allow_null) {
173 182
                     $type_obj = new HTMLPurifier_Printer_ConfigForm_NullDecorator($type_obj);
@@ -223,7 +232,9 @@  discard block
 block discarded – undo
223 232
             // modify inline javascript slightly
224 233
             $attr['onclick'] = "toggleWriteability('$name:Yes_$ns.$directive',checked);toggleWriteability('$name:No_$ns.$directive',checked)";
225 234
         }
226
-        if ($value === null) $attr['checked'] = 'checked';
235
+        if ($value === null) {
236
+        	$attr['checked'] = 'checked';
237
+        }
227 238
         $ret .= $this->elementEmpty('input', $attr);
228 239
         $ret .= $this->text(' or ');
229 240
         $ret .= $this->elementEmpty('br');
@@ -284,12 +295,16 @@  discard block
 block discarded – undo
284 295
             'name' => "$name"."[$ns.$directive]",
285 296
             'id' => "$name:$ns.$directive"
286 297
         );
287
-        if ($value === null) $attr['disabled'] = 'disabled';
298
+        if ($value === null) {
299
+        	$attr['disabled'] = 'disabled';
300
+        }
288 301
         if (isset($def->allowed)) {
289 302
             $ret .= $this->start('select', $attr);
290 303
             foreach ($def->allowed as $val => $b) {
291 304
                 $attr = array();
292
-                if ($value == $val) $attr['selected'] = 'selected';
305
+                if ($value == $val) {
306
+                	$attr['selected'] = 'selected';
307
+                }
293 308
                 $ret .= $this->element('option', $val, $attr);
294 309
             }
295 310
             $ret .= $this->end('select');
@@ -340,8 +355,12 @@  discard block
 block discarded – undo
340 355
             'id' => "$name:Yes_$ns.$directive",
341 356
             'value' => '1'
342 357
         );
343
-        if ($value === true) $attr['checked'] = 'checked';
344
-        if ($value === null) $attr['disabled'] = 'disabled';
358
+        if ($value === true) {
359
+        	$attr['checked'] = 'checked';
360
+        }
361
+        if ($value === null) {
362
+        	$attr['disabled'] = 'disabled';
363
+        }
345 364
         $ret .= $this->elementEmpty('input', $attr);
346 365
 
347 366
         $ret .= $this->start('label', array('for' => "$name:No_$ns.$directive"));
@@ -355,8 +374,12 @@  discard block
 block discarded – undo
355 374
             'id' => "$name:No_$ns.$directive",
356 375
             'value' => '0'
357 376
         );
358
-        if ($value === false) $attr['checked'] = 'checked';
359
-        if ($value === null) $attr['disabled'] = 'disabled';
377
+        if ($value === false) {
378
+        	$attr['checked'] = 'checked';
379
+        }
380
+        if ($value === null) {
381
+        	$attr['disabled'] = 'disabled';
382
+        }
360 383
         $ret .= $this->elementEmpty('input', $attr);
361 384
 
362 385
         $ret .= $this->end('div');
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
         $this->name   = $name;
42 42
         $this->compress = $compress;
43 43
         // initialize sub-printers
44
-        $this->fields[0]    = new HTMLPurifier_Printer_ConfigForm_default();
45
-        $this->fields[HTMLPurifier_VarParser::BOOL]       = new HTMLPurifier_Printer_ConfigForm_bool();
44
+        $this->fields[0] = new HTMLPurifier_Printer_ConfigForm_default();
45
+        $this->fields[HTMLPurifier_VarParser::BOOL] = new HTMLPurifier_Printer_ConfigForm_bool();
46 46
     }
47 47
 
48 48
     /**
@@ -59,14 +59,14 @@  discard block
 block discarded – undo
59 59
      * Retrieves styling, in case it is not accessible by webserver
60 60
      */
61 61
     public static function getCSS() {
62
-        return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.css');
62
+        return file_get_contents(HTMLPURIFIER_PREFIX.'/HTMLPurifier/Printer/ConfigForm.css');
63 63
     }
64 64
 
65 65
     /**
66 66
      * Retrieves JavaScript, in case it is not accessible by webserver
67 67
      */
68 68
     public static function getJavaScript() {
69
-        return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.js');
69
+        return file_get_contents(HTMLPURIFIER_PREFIX.'/HTMLPurifier/Printer/ConfigForm.js');
70 70
     }
71 71
 
72 72
     /**
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         $all = array();
92 92
         foreach ($allowed as $key) {
93 93
             list($ns, $directive) = $key;
94
-            $all[$ns][$directive] = $config->get($ns .'.'. $directive);
94
+            $all[$ns][$directive] = $config->get($ns.'.'.$directive);
95 95
         }
96 96
 
97 97
         $ret = '';
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
                 if (!$this->compress || (strlen($directive) < $this->compress)) {
146 146
                     $directive_disp = $directive;
147 147
                 } else {
148
-                    $directive_disp = substr($directive, 0, $this->compress - 2) . '...';
148
+                    $directive_disp = substr($directive, 0, $this->compress - 2).'...';
149 149
                     $attr['title'] = $directive;
150 150
                 }
151 151
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
                 case HTMLPurifier_VarParser::HASH:
269 269
                     $nvalue = '';
270 270
                     foreach ($value as $i => $v) {
271
-                        $nvalue .= "$i:$v" . PHP_EOL;
271
+                        $nvalue .= "$i:$v".PHP_EOL;
272 272
                     }
273 273
                     $value = $nvalue;
274 274
                     break;
Please login to merge, or discard this patch.
security/htmlpurifier/library/HTMLPurifier/Printer/HTMLDefinition.php 3 patches
Indentation   +263 added lines, -263 removed lines patch added patch discarded remove patch
@@ -3,269 +3,269 @@
 block discarded – undo
3 3
 class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
4 4
 {
5 5
 
6
-    /**
7
-     * Instance of HTMLPurifier_HTMLDefinition, for easy access
8
-     */
9
-    protected $def;
10
-
11
-    public function render($config) {
12
-        $ret = '';
13
-        $this->config =& $config;
14
-
15
-        $this->def = $config->getHTMLDefinition();
16
-
17
-        $ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer'));
18
-
19
-        $ret .= $this->renderDoctype();
20
-        $ret .= $this->renderEnvironment();
21
-        $ret .= $this->renderContentSets();
22
-        $ret .= $this->renderInfo();
23
-
24
-        $ret .= $this->end('div');
25
-
26
-        return $ret;
27
-    }
28
-
29
-    /**
30
-     * Renders the Doctype table
31
-     */
32
-    protected function renderDoctype() {
33
-        $doctype = $this->def->doctype;
34
-        $ret = '';
35
-        $ret .= $this->start('table');
36
-        $ret .= $this->element('caption', 'Doctype');
37
-        $ret .= $this->row('Name', $doctype->name);
38
-        $ret .= $this->row('XML', $doctype->xml ? 'Yes' : 'No');
39
-        $ret .= $this->row('Default Modules', implode($doctype->modules, ', '));
40
-        $ret .= $this->row('Default Tidy Modules', implode($doctype->tidyModules, ', '));
41
-        $ret .= $this->end('table');
42
-        return $ret;
43
-    }
44
-
45
-
46
-    /**
47
-     * Renders environment table, which is miscellaneous info
48
-     */
49
-    protected function renderEnvironment() {
50
-        $def = $this->def;
51
-
52
-        $ret = '';
53
-
54
-        $ret .= $this->start('table');
55
-        $ret .= $this->element('caption', 'Environment');
56
-
57
-        $ret .= $this->row('Parent of fragment', $def->info_parent);
58
-        $ret .= $this->renderChildren($def->info_parent_def->child);
59
-        $ret .= $this->row('Block wrap name', $def->info_block_wrapper);
60
-
61
-        $ret .= $this->start('tr');
62
-            $ret .= $this->element('th', 'Global attributes');
63
-            $ret .= $this->element('td', $this->listifyAttr($def->info_global_attr),0,0);
64
-        $ret .= $this->end('tr');
65
-
66
-        $ret .= $this->start('tr');
67
-            $ret .= $this->element('th', 'Tag transforms');
68
-            $list = array();
69
-            foreach ($def->info_tag_transform as $old => $new) {
70
-                $new = $this->getClass($new, 'TagTransform_');
71
-                $list[] = "<$old> with $new";
72
-            }
73
-            $ret .= $this->element('td', $this->listify($list));
74
-        $ret .= $this->end('tr');
75
-
76
-        $ret .= $this->start('tr');
77
-            $ret .= $this->element('th', 'Pre-AttrTransform');
78
-            $ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_pre));
79
-        $ret .= $this->end('tr');
80
-
81
-        $ret .= $this->start('tr');
82
-            $ret .= $this->element('th', 'Post-AttrTransform');
83
-            $ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_post));
84
-        $ret .= $this->end('tr');
85
-
86
-        $ret .= $this->end('table');
87
-        return $ret;
88
-    }
89
-
90
-    /**
91
-     * Renders the Content Sets table
92
-     */
93
-    protected function renderContentSets() {
94
-        $ret = '';
95
-        $ret .= $this->start('table');
96
-        $ret .= $this->element('caption', 'Content Sets');
97
-        foreach ($this->def->info_content_sets as $name => $lookup) {
98
-            $ret .= $this->heavyHeader($name);
99
-            $ret .= $this->start('tr');
100
-            $ret .= $this->element('td', $this->listifyTagLookup($lookup));
101
-            $ret .= $this->end('tr');
102
-        }
103
-        $ret .= $this->end('table');
104
-        return $ret;
105
-    }
106
-
107
-    /**
108
-     * Renders the Elements ($info) table
109
-     */
110
-    protected function renderInfo() {
111
-        $ret = '';
112
-        $ret .= $this->start('table');
113
-        $ret .= $this->element('caption', 'Elements ($info)');
114
-        ksort($this->def->info);
115
-        $ret .= $this->heavyHeader('Allowed tags', 2);
116
-        $ret .= $this->start('tr');
117
-        $ret .= $this->element('td', $this->listifyTagLookup($this->def->info), array('colspan' => 2));
118
-        $ret .= $this->end('tr');
119
-        foreach ($this->def->info as $name => $def) {
120
-            $ret .= $this->start('tr');
121
-                $ret .= $this->element('th', "<$name>", array('class'=>'heavy', 'colspan' => 2));
122
-            $ret .= $this->end('tr');
123
-            $ret .= $this->start('tr');
124
-                $ret .= $this->element('th', 'Inline content');
125
-                $ret .= $this->element('td', $def->descendants_are_inline ? 'Yes' : 'No');
126
-            $ret .= $this->end('tr');
127
-            if (!empty($def->excludes)) {
128
-                $ret .= $this->start('tr');
129
-                    $ret .= $this->element('th', 'Excludes');
130
-                    $ret .= $this->element('td', $this->listifyTagLookup($def->excludes));
131
-                $ret .= $this->end('tr');
132
-            }
133
-            if (!empty($def->attr_transform_pre)) {
134
-                $ret .= $this->start('tr');
135
-                    $ret .= $this->element('th', 'Pre-AttrTransform');
136
-                    $ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_pre));
137
-                $ret .= $this->end('tr');
138
-            }
139
-            if (!empty($def->attr_transform_post)) {
140
-                $ret .= $this->start('tr');
141
-                    $ret .= $this->element('th', 'Post-AttrTransform');
142
-                    $ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_post));
143
-                $ret .= $this->end('tr');
144
-            }
145
-            if (!empty($def->auto_close)) {
146
-                $ret .= $this->start('tr');
147
-                    $ret .= $this->element('th', 'Auto closed by');
148
-                    $ret .= $this->element('td', $this->listifyTagLookup($def->auto_close));
149
-                $ret .= $this->end('tr');
150
-            }
151
-            $ret .= $this->start('tr');
152
-                $ret .= $this->element('th', 'Allowed attributes');
153
-                $ret .= $this->element('td',$this->listifyAttr($def->attr), array(), 0);
154
-            $ret .= $this->end('tr');
155
-
156
-            if (!empty($def->required_attr)) {
157
-                $ret .= $this->row('Required attributes', $this->listify($def->required_attr));
158
-            }
159
-
160
-            $ret .= $this->renderChildren($def->child);
161
-        }
162
-        $ret .= $this->end('table');
163
-        return $ret;
164
-    }
165
-
166
-    /**
167
-     * Renders a row describing the allowed children of an element
168
-     * @param $def HTMLPurifier_ChildDef of pertinent element
169
-     */
170
-    protected function renderChildren($def) {
171
-        $context = new HTMLPurifier_Context();
172
-        $ret = '';
173
-        $ret .= $this->start('tr');
174
-            $elements = array();
175
-            $attr = array();
176
-            if (isset($def->elements)) {
177
-                if ($def->type == 'strictblockquote') {
178
-                    $def->validateChildren(array(), $this->config, $context);
179
-                }
180
-                $elements = $def->elements;
181
-            }
182
-            if ($def->type == 'chameleon') {
183
-                $attr['rowspan'] = 2;
184
-            } elseif ($def->type == 'empty') {
185
-                $elements = array();
186
-            } elseif ($def->type == 'table') {
187
-                $elements = array_flip(array('col', 'caption', 'colgroup', 'thead',
188
-                    'tfoot', 'tbody', 'tr'));
189
-            }
190
-            $ret .= $this->element('th', 'Allowed children', $attr);
191
-
192
-            if ($def->type == 'chameleon') {
193
-
194
-                $ret .= $this->element('td',
195
-                    '<em>Block</em>: ' .
196
-                    $this->escape($this->listifyTagLookup($def->block->elements)),0,0);
197
-                $ret .= $this->end('tr');
198
-                $ret .= $this->start('tr');
199
-                $ret .= $this->element('td',
200
-                    '<em>Inline</em>: ' .
201
-                    $this->escape($this->listifyTagLookup($def->inline->elements)),0,0);
202
-
203
-            } elseif ($def->type == 'custom') {
204
-
205
-                $ret .= $this->element('td', '<em>'.ucfirst($def->type).'</em>: ' .
206
-                    $def->dtd_regex);
207
-
208
-            } else {
209
-                $ret .= $this->element('td',
210
-                    '<em>'.ucfirst($def->type).'</em>: ' .
211
-                    $this->escape($this->listifyTagLookup($elements)),0,0);
212
-            }
213
-        $ret .= $this->end('tr');
214
-        return $ret;
215
-    }
216
-
217
-    /**
218
-     * Listifies a tag lookup table.
219
-     * @param $array Tag lookup array in form of array('tagname' => true)
220
-     */
221
-    protected function listifyTagLookup($array) {
222
-        ksort($array);
223
-        $list = array();
224
-        foreach ($array as $name => $discard) {
225
-            if ($name !== '#PCDATA' && !isset($this->def->info[$name])) continue;
226
-            $list[] = $name;
227
-        }
228
-        return $this->listify($list);
229
-    }
230
-
231
-    /**
232
-     * Listifies a list of objects by retrieving class names and internal state
233
-     * @param $array List of objects
234
-     * @todo Also add information about internal state
235
-     */
236
-    protected function listifyObjectList($array) {
237
-        ksort($array);
238
-        $list = array();
239
-        foreach ($array as $discard => $obj) {
240
-            $list[] = $this->getClass($obj, 'AttrTransform_');
241
-        }
242
-        return $this->listify($list);
243
-    }
244
-
245
-    /**
246
-     * Listifies a hash of attributes to AttrDef classes
247
-     * @param $array Array hash in form of array('attrname' => HTMLPurifier_AttrDef)
248
-     */
249
-    protected function listifyAttr($array) {
250
-        ksort($array);
251
-        $list = array();
252
-        foreach ($array as $name => $obj) {
253
-            if ($obj === false) continue;
254
-            $list[] = "$name&nbsp;=&nbsp;<i>" . $this->getClass($obj, 'AttrDef_') . '</i>';
255
-        }
256
-        return $this->listify($list);
257
-    }
258
-
259
-    /**
260
-     * Creates a heavy header row
261
-     */
262
-    protected function heavyHeader($text, $num = 1) {
263
-        $ret = '';
264
-        $ret .= $this->start('tr');
265
-        $ret .= $this->element('th', $text, array('colspan' => $num, 'class' => 'heavy'));
266
-        $ret .= $this->end('tr');
267
-        return $ret;
268
-    }
6
+	/**
7
+	 * Instance of HTMLPurifier_HTMLDefinition, for easy access
8
+	 */
9
+	protected $def;
10
+
11
+	public function render($config) {
12
+		$ret = '';
13
+		$this->config =& $config;
14
+
15
+		$this->def = $config->getHTMLDefinition();
16
+
17
+		$ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer'));
18
+
19
+		$ret .= $this->renderDoctype();
20
+		$ret .= $this->renderEnvironment();
21
+		$ret .= $this->renderContentSets();
22
+		$ret .= $this->renderInfo();
23
+
24
+		$ret .= $this->end('div');
25
+
26
+		return $ret;
27
+	}
28
+
29
+	/**
30
+	 * Renders the Doctype table
31
+	 */
32
+	protected function renderDoctype() {
33
+		$doctype = $this->def->doctype;
34
+		$ret = '';
35
+		$ret .= $this->start('table');
36
+		$ret .= $this->element('caption', 'Doctype');
37
+		$ret .= $this->row('Name', $doctype->name);
38
+		$ret .= $this->row('XML', $doctype->xml ? 'Yes' : 'No');
39
+		$ret .= $this->row('Default Modules', implode($doctype->modules, ', '));
40
+		$ret .= $this->row('Default Tidy Modules', implode($doctype->tidyModules, ', '));
41
+		$ret .= $this->end('table');
42
+		return $ret;
43
+	}
44
+
45
+
46
+	/**
47
+	 * Renders environment table, which is miscellaneous info
48
+	 */
49
+	protected function renderEnvironment() {
50
+		$def = $this->def;
51
+
52
+		$ret = '';
53
+
54
+		$ret .= $this->start('table');
55
+		$ret .= $this->element('caption', 'Environment');
56
+
57
+		$ret .= $this->row('Parent of fragment', $def->info_parent);
58
+		$ret .= $this->renderChildren($def->info_parent_def->child);
59
+		$ret .= $this->row('Block wrap name', $def->info_block_wrapper);
60
+
61
+		$ret .= $this->start('tr');
62
+			$ret .= $this->element('th', 'Global attributes');
63
+			$ret .= $this->element('td', $this->listifyAttr($def->info_global_attr),0,0);
64
+		$ret .= $this->end('tr');
65
+
66
+		$ret .= $this->start('tr');
67
+			$ret .= $this->element('th', 'Tag transforms');
68
+			$list = array();
69
+			foreach ($def->info_tag_transform as $old => $new) {
70
+				$new = $this->getClass($new, 'TagTransform_');
71
+				$list[] = "<$old> with $new";
72
+			}
73
+			$ret .= $this->element('td', $this->listify($list));
74
+		$ret .= $this->end('tr');
75
+
76
+		$ret .= $this->start('tr');
77
+			$ret .= $this->element('th', 'Pre-AttrTransform');
78
+			$ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_pre));
79
+		$ret .= $this->end('tr');
80
+
81
+		$ret .= $this->start('tr');
82
+			$ret .= $this->element('th', 'Post-AttrTransform');
83
+			$ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_post));
84
+		$ret .= $this->end('tr');
85
+
86
+		$ret .= $this->end('table');
87
+		return $ret;
88
+	}
89
+
90
+	/**
91
+	 * Renders the Content Sets table
92
+	 */
93
+	protected function renderContentSets() {
94
+		$ret = '';
95
+		$ret .= $this->start('table');
96
+		$ret .= $this->element('caption', 'Content Sets');
97
+		foreach ($this->def->info_content_sets as $name => $lookup) {
98
+			$ret .= $this->heavyHeader($name);
99
+			$ret .= $this->start('tr');
100
+			$ret .= $this->element('td', $this->listifyTagLookup($lookup));
101
+			$ret .= $this->end('tr');
102
+		}
103
+		$ret .= $this->end('table');
104
+		return $ret;
105
+	}
106
+
107
+	/**
108
+	 * Renders the Elements ($info) table
109
+	 */
110
+	protected function renderInfo() {
111
+		$ret = '';
112
+		$ret .= $this->start('table');
113
+		$ret .= $this->element('caption', 'Elements ($info)');
114
+		ksort($this->def->info);
115
+		$ret .= $this->heavyHeader('Allowed tags', 2);
116
+		$ret .= $this->start('tr');
117
+		$ret .= $this->element('td', $this->listifyTagLookup($this->def->info), array('colspan' => 2));
118
+		$ret .= $this->end('tr');
119
+		foreach ($this->def->info as $name => $def) {
120
+			$ret .= $this->start('tr');
121
+				$ret .= $this->element('th', "<$name>", array('class'=>'heavy', 'colspan' => 2));
122
+			$ret .= $this->end('tr');
123
+			$ret .= $this->start('tr');
124
+				$ret .= $this->element('th', 'Inline content');
125
+				$ret .= $this->element('td', $def->descendants_are_inline ? 'Yes' : 'No');
126
+			$ret .= $this->end('tr');
127
+			if (!empty($def->excludes)) {
128
+				$ret .= $this->start('tr');
129
+					$ret .= $this->element('th', 'Excludes');
130
+					$ret .= $this->element('td', $this->listifyTagLookup($def->excludes));
131
+				$ret .= $this->end('tr');
132
+			}
133
+			if (!empty($def->attr_transform_pre)) {
134
+				$ret .= $this->start('tr');
135
+					$ret .= $this->element('th', 'Pre-AttrTransform');
136
+					$ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_pre));
137
+				$ret .= $this->end('tr');
138
+			}
139
+			if (!empty($def->attr_transform_post)) {
140
+				$ret .= $this->start('tr');
141
+					$ret .= $this->element('th', 'Post-AttrTransform');
142
+					$ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_post));
143
+				$ret .= $this->end('tr');
144
+			}
145
+			if (!empty($def->auto_close)) {
146
+				$ret .= $this->start('tr');
147
+					$ret .= $this->element('th', 'Auto closed by');
148
+					$ret .= $this->element('td', $this->listifyTagLookup($def->auto_close));
149
+				$ret .= $this->end('tr');
150
+			}
151
+			$ret .= $this->start('tr');
152
+				$ret .= $this->element('th', 'Allowed attributes');
153
+				$ret .= $this->element('td',$this->listifyAttr($def->attr), array(), 0);
154
+			$ret .= $this->end('tr');
155
+
156
+			if (!empty($def->required_attr)) {
157
+				$ret .= $this->row('Required attributes', $this->listify($def->required_attr));
158
+			}
159
+
160
+			$ret .= $this->renderChildren($def->child);
161
+		}
162
+		$ret .= $this->end('table');
163
+		return $ret;
164
+	}
165
+
166
+	/**
167
+	 * Renders a row describing the allowed children of an element
168
+	 * @param $def HTMLPurifier_ChildDef of pertinent element
169
+	 */
170
+	protected function renderChildren($def) {
171
+		$context = new HTMLPurifier_Context();
172
+		$ret = '';
173
+		$ret .= $this->start('tr');
174
+			$elements = array();
175
+			$attr = array();
176
+			if (isset($def->elements)) {
177
+				if ($def->type == 'strictblockquote') {
178
+					$def->validateChildren(array(), $this->config, $context);
179
+				}
180
+				$elements = $def->elements;
181
+			}
182
+			if ($def->type == 'chameleon') {
183
+				$attr['rowspan'] = 2;
184
+			} elseif ($def->type == 'empty') {
185
+				$elements = array();
186
+			} elseif ($def->type == 'table') {
187
+				$elements = array_flip(array('col', 'caption', 'colgroup', 'thead',
188
+					'tfoot', 'tbody', 'tr'));
189
+			}
190
+			$ret .= $this->element('th', 'Allowed children', $attr);
191
+
192
+			if ($def->type == 'chameleon') {
193
+
194
+				$ret .= $this->element('td',
195
+					'<em>Block</em>: ' .
196
+					$this->escape($this->listifyTagLookup($def->block->elements)),0,0);
197
+				$ret .= $this->end('tr');
198
+				$ret .= $this->start('tr');
199
+				$ret .= $this->element('td',
200
+					'<em>Inline</em>: ' .
201
+					$this->escape($this->listifyTagLookup($def->inline->elements)),0,0);
202
+
203
+			} elseif ($def->type == 'custom') {
204
+
205
+				$ret .= $this->element('td', '<em>'.ucfirst($def->type).'</em>: ' .
206
+					$def->dtd_regex);
207
+
208
+			} else {
209
+				$ret .= $this->element('td',
210
+					'<em>'.ucfirst($def->type).'</em>: ' .
211
+					$this->escape($this->listifyTagLookup($elements)),0,0);
212
+			}
213
+		$ret .= $this->end('tr');
214
+		return $ret;
215
+	}
216
+
217
+	/**
218
+	 * Listifies a tag lookup table.
219
+	 * @param $array Tag lookup array in form of array('tagname' => true)
220
+	 */
221
+	protected function listifyTagLookup($array) {
222
+		ksort($array);
223
+		$list = array();
224
+		foreach ($array as $name => $discard) {
225
+			if ($name !== '#PCDATA' && !isset($this->def->info[$name])) continue;
226
+			$list[] = $name;
227
+		}
228
+		return $this->listify($list);
229
+	}
230
+
231
+	/**
232
+	 * Listifies a list of objects by retrieving class names and internal state
233
+	 * @param $array List of objects
234
+	 * @todo Also add information about internal state
235
+	 */
236
+	protected function listifyObjectList($array) {
237
+		ksort($array);
238
+		$list = array();
239
+		foreach ($array as $discard => $obj) {
240
+			$list[] = $this->getClass($obj, 'AttrTransform_');
241
+		}
242
+		return $this->listify($list);
243
+	}
244
+
245
+	/**
246
+	 * Listifies a hash of attributes to AttrDef classes
247
+	 * @param $array Array hash in form of array('attrname' => HTMLPurifier_AttrDef)
248
+	 */
249
+	protected function listifyAttr($array) {
250
+		ksort($array);
251
+		$list = array();
252
+		foreach ($array as $name => $obj) {
253
+			if ($obj === false) continue;
254
+			$list[] = "$name&nbsp;=&nbsp;<i>" . $this->getClass($obj, 'AttrDef_') . '</i>';
255
+		}
256
+		return $this->listify($list);
257
+	}
258
+
259
+	/**
260
+	 * Creates a heavy header row
261
+	 */
262
+	protected function heavyHeader($text, $num = 1) {
263
+		$ret = '';
264
+		$ret .= $this->start('tr');
265
+		$ret .= $this->element('th', $text, array('colspan' => $num, 'class' => 'heavy'));
266
+		$ret .= $this->end('tr');
267
+		return $ret;
268
+	}
269 269
 
270 270
 }
271 271
 
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -222,7 +222,9 @@  discard block
 block discarded – undo
222 222
         ksort($array);
223 223
         $list = array();
224 224
         foreach ($array as $name => $discard) {
225
-            if ($name !== '#PCDATA' && !isset($this->def->info[$name])) continue;
225
+            if ($name !== '#PCDATA' && !isset($this->def->info[$name])) {
226
+            	continue;
227
+            }
226 228
             $list[] = $name;
227 229
         }
228 230
         return $this->listify($list);
@@ -250,7 +252,9 @@  discard block
 block discarded – undo
250 252
         ksort($array);
251 253
         $list = array();
252 254
         foreach ($array as $name => $obj) {
253
-            if ($obj === false) continue;
255
+            if ($obj === false) {
256
+            	continue;
257
+            }
254 258
             $list[] = "$name&nbsp;=&nbsp;<i>" . $this->getClass($obj, 'AttrDef_') . '</i>';
255 259
         }
256 260
         return $this->listify($list);
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 
11 11
     public function render($config) {
12 12
         $ret = '';
13
-        $this->config =& $config;
13
+        $this->config = & $config;
14 14
 
15 15
         $this->def = $config->getHTMLDefinition();
16 16
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 
61 61
         $ret .= $this->start('tr');
62 62
             $ret .= $this->element('th', 'Global attributes');
63
-            $ret .= $this->element('td', $this->listifyAttr($def->info_global_attr),0,0);
63
+            $ret .= $this->element('td', $this->listifyAttr($def->info_global_attr), 0, 0);
64 64
         $ret .= $this->end('tr');
65 65
 
66 66
         $ret .= $this->start('tr');
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
             }
151 151
             $ret .= $this->start('tr');
152 152
                 $ret .= $this->element('th', 'Allowed attributes');
153
-                $ret .= $this->element('td',$this->listifyAttr($def->attr), array(), 0);
153
+                $ret .= $this->element('td', $this->listifyAttr($def->attr), array(), 0);
154 154
             $ret .= $this->end('tr');
155 155
 
156 156
             if (!empty($def->required_attr)) {
@@ -192,23 +192,23 @@  discard block
 block discarded – undo
192 192
             if ($def->type == 'chameleon') {
193 193
 
194 194
                 $ret .= $this->element('td',
195
-                    '<em>Block</em>: ' .
196
-                    $this->escape($this->listifyTagLookup($def->block->elements)),0,0);
195
+                    '<em>Block</em>: '.
196
+                    $this->escape($this->listifyTagLookup($def->block->elements)), 0, 0);
197 197
                 $ret .= $this->end('tr');
198 198
                 $ret .= $this->start('tr');
199 199
                 $ret .= $this->element('td',
200
-                    '<em>Inline</em>: ' .
201
-                    $this->escape($this->listifyTagLookup($def->inline->elements)),0,0);
200
+                    '<em>Inline</em>: '.
201
+                    $this->escape($this->listifyTagLookup($def->inline->elements)), 0, 0);
202 202
 
203 203
             } elseif ($def->type == 'custom') {
204 204
 
205
-                $ret .= $this->element('td', '<em>'.ucfirst($def->type).'</em>: ' .
205
+                $ret .= $this->element('td', '<em>'.ucfirst($def->type).'</em>: '.
206 206
                     $def->dtd_regex);
207 207
 
208 208
             } else {
209 209
                 $ret .= $this->element('td',
210
-                    '<em>'.ucfirst($def->type).'</em>: ' .
211
-                    $this->escape($this->listifyTagLookup($elements)),0,0);
210
+                    '<em>'.ucfirst($def->type).'</em>: '.
211
+                    $this->escape($this->listifyTagLookup($elements)), 0, 0);
212 212
             }
213 213
         $ret .= $this->end('tr');
214 214
         return $ret;
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
         $list = array();
252 252
         foreach ($array as $name => $obj) {
253 253
             if ($obj === false) continue;
254
-            $list[] = "$name&nbsp;=&nbsp;<i>" . $this->getClass($obj, 'AttrDef_') . '</i>';
254
+            $list[] = "$name&nbsp;=&nbsp;<i>".$this->getClass($obj, 'AttrDef_').'</i>';
255 255
         }
256 256
         return $this->listify($list);
257 257
     }
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/PropertyList.php 2 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -5,82 +5,82 @@
 block discarded – undo
5 5
  */
6 6
 class HTMLPurifier_PropertyList
7 7
 {
8
-    /**
9
-     * Internal data-structure for properties
10
-     */
11
-    protected $data = array();
8
+	/**
9
+	 * Internal data-structure for properties
10
+	 */
11
+	protected $data = array();
12 12
 
13
-    /**
14
-     * Parent plist
15
-     */
16
-    protected $parent;
13
+	/**
14
+	 * Parent plist
15
+	 */
16
+	protected $parent;
17 17
 
18
-    protected $cache;
18
+	protected $cache;
19 19
 
20
-    public function __construct($parent = null) {
21
-        $this->parent = $parent;
22
-    }
20
+	public function __construct($parent = null) {
21
+		$this->parent = $parent;
22
+	}
23 23
 
24
-    /**
25
-     * Recursively retrieves the value for a key
26
-     */
27
-    public function get($name) {
28
-        if ($this->has($name)) return $this->data[$name];
29
-        // possible performance bottleneck, convert to iterative if necessary
30
-        if ($this->parent) return $this->parent->get($name);
31
-        throw new HTMLPurifier_Exception("Key '$name' not found");
32
-    }
24
+	/**
25
+	 * Recursively retrieves the value for a key
26
+	 */
27
+	public function get($name) {
28
+		if ($this->has($name)) return $this->data[$name];
29
+		// possible performance bottleneck, convert to iterative if necessary
30
+		if ($this->parent) return $this->parent->get($name);
31
+		throw new HTMLPurifier_Exception("Key '$name' not found");
32
+	}
33 33
 
34
-    /**
35
-     * Sets the value of a key, for this plist
36
-     */
37
-    public function set($name, $value) {
38
-        $this->data[$name] = $value;
39
-    }
34
+	/**
35
+	 * Sets the value of a key, for this plist
36
+	 */
37
+	public function set($name, $value) {
38
+		$this->data[$name] = $value;
39
+	}
40 40
 
41
-    /**
42
-     * Returns true if a given key exists
43
-     */
44
-    public function has($name) {
45
-        return array_key_exists($name, $this->data);
46
-    }
41
+	/**
42
+	 * Returns true if a given key exists
43
+	 */
44
+	public function has($name) {
45
+		return array_key_exists($name, $this->data);
46
+	}
47 47
 
48
-    /**
49
-     * Resets a value to the value of it's parent, usually the default. If
50
-     * no value is specified, the entire plist is reset.
51
-     */
52
-    public function reset($name = null) {
53
-        if ($name == null) $this->data = array();
54
-        else unset($this->data[$name]);
55
-    }
48
+	/**
49
+	 * Resets a value to the value of it's parent, usually the default. If
50
+	 * no value is specified, the entire plist is reset.
51
+	 */
52
+	public function reset($name = null) {
53
+		if ($name == null) $this->data = array();
54
+		else unset($this->data[$name]);
55
+	}
56 56
 
57
-    /**
58
-     * Squashes this property list and all of its property lists into a single
59
-     * array, and returns the array. This value is cached by default.
60
-     * @param $force If true, ignores the cache and regenerates the array.
61
-     */
62
-    public function squash($force = false) {
63
-        if ($this->cache !== null && !$force) return $this->cache;
64
-        if ($this->parent) {
65
-            return $this->cache = array_merge($this->parent->squash($force), $this->data);
66
-        } else {
67
-            return $this->cache = $this->data;
68
-        }
69
-    }
57
+	/**
58
+	 * Squashes this property list and all of its property lists into a single
59
+	 * array, and returns the array. This value is cached by default.
60
+	 * @param $force If true, ignores the cache and regenerates the array.
61
+	 */
62
+	public function squash($force = false) {
63
+		if ($this->cache !== null && !$force) return $this->cache;
64
+		if ($this->parent) {
65
+			return $this->cache = array_merge($this->parent->squash($force), $this->data);
66
+		} else {
67
+			return $this->cache = $this->data;
68
+		}
69
+	}
70 70
 
71
-    /**
72
-     * Returns the parent plist.
73
-     */
74
-    public function getParent() {
75
-        return $this->parent;
76
-    }
71
+	/**
72
+	 * Returns the parent plist.
73
+	 */
74
+	public function getParent() {
75
+		return $this->parent;
76
+	}
77 77
 
78
-    /**
79
-     * Sets the parent plist.
80
-     */
81
-    public function setParent($plist) {
82
-        $this->parent = $plist;
83
-    }
78
+	/**
79
+	 * Sets the parent plist.
80
+	 */
81
+	public function setParent($plist) {
82
+		$this->parent = $plist;
83
+	}
84 84
 }
85 85
 
86 86
 // vim: et sw=4 sts=4
Please login to merge, or discard this patch.
Braces   +14 added lines, -5 removed lines patch added patch discarded remove patch
@@ -25,9 +25,13 @@  discard block
 block discarded – undo
25 25
      * Recursively retrieves the value for a key
26 26
      */
27 27
     public function get($name) {
28
-        if ($this->has($name)) return $this->data[$name];
28
+        if ($this->has($name)) {
29
+        	return $this->data[$name];
30
+        }
29 31
         // possible performance bottleneck, convert to iterative if necessary
30
-        if ($this->parent) return $this->parent->get($name);
32
+        if ($this->parent) {
33
+        	return $this->parent->get($name);
34
+        }
31 35
         throw new HTMLPurifier_Exception("Key '$name' not found");
32 36
     }
33 37
 
@@ -50,8 +54,11 @@  discard block
 block discarded – undo
50 54
      * no value is specified, the entire plist is reset.
51 55
      */
52 56
     public function reset($name = null) {
53
-        if ($name == null) $this->data = array();
54
-        else unset($this->data[$name]);
57
+        if ($name == null) {
58
+        	$this->data = array();
59
+        } else {
60
+        	unset($this->data[$name]);
61
+        }
55 62
     }
56 63
 
57 64
     /**
@@ -60,7 +67,9 @@  discard block
 block discarded – undo
60 67
      * @param $force If true, ignores the cache and regenerates the array.
61 68
      */
62 69
     public function squash($force = false) {
63
-        if ($this->cache !== null && !$force) return $this->cache;
70
+        if ($this->cache !== null && !$force) {
71
+        	return $this->cache;
72
+        }
64 73
         if ($this->parent) {
65 74
             return $this->cache = array_merge($this->parent->squash($force), $this->data);
66 75
         } else {
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/PropertyListIterator.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -6,26 +6,26 @@
 block discarded – undo
6 6
 class HTMLPurifier_PropertyListIterator extends FilterIterator
7 7
 {
8 8
 
9
-    protected $l;
10
-    protected $filter;
9
+	protected $l;
10
+	protected $filter;
11 11
 
12
-    /**
13
-     * @param $data Array of data to iterate over
14
-     * @param $filter Optional prefix to only allow values of
15
-     */
16
-    public function __construct(Iterator $iterator, $filter = null) {
17
-        parent::__construct($iterator);
18
-        $this->l = strlen($filter);
19
-        $this->filter = $filter;
20
-    }
12
+	/**
13
+	 * @param $data Array of data to iterate over
14
+	 * @param $filter Optional prefix to only allow values of
15
+	 */
16
+	public function __construct(Iterator $iterator, $filter = null) {
17
+		parent::__construct($iterator);
18
+		$this->l = strlen($filter);
19
+		$this->filter = $filter;
20
+	}
21 21
 
22
-    public function accept() {
23
-        $key = $this->getInnerIterator()->key();
24
-        if( strncmp($key, $this->filter, $this->l) !== 0 ) {
25
-            return false;
26
-        }
27
-        return true;
28
-    }
22
+	public function accept() {
23
+		$key = $this->getInnerIterator()->key();
24
+		if( strncmp($key, $this->filter, $this->l) !== 0 ) {
25
+			return false;
26
+		}
27
+		return true;
28
+	}
29 29
 
30 30
 }
31 31
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
 
22 22
     public function accept() {
23 23
         $key = $this->getInnerIterator()->key();
24
-        if( strncmp($key, $this->filter, $this->l) !== 0 ) {
24
+        if (strncmp($key, $this->filter, $this->l) !== 0) {
25 25
             return false;
26 26
         }
27 27
         return true;
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/Strategy.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@
 block discarded – undo
12 12
 abstract class HTMLPurifier_Strategy
13 13
 {
14 14
 
15
-    /**
16
-     * Executes the strategy on the tokens.
17
-     *
18
-     * @param $tokens Array of HTMLPurifier_Token objects to be operated on.
19
-     * @param $config Configuration options
20
-     * @returns Processed array of token objects.
21
-     */
22
-    abstract public function execute($tokens, $config, $context);
15
+	/**
16
+	 * Executes the strategy on the tokens.
17
+	 *
18
+	 * @param $tokens Array of HTMLPurifier_Token objects to be operated on.
19
+	 * @param $config Configuration options
20
+	 * @returns Processed array of token objects.
21
+	 */
22
+	abstract public function execute($tokens, $config, $context);
23 23
 
24 24
 }
25 25
 
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/Strategy/Composite.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -6,17 +6,17 @@
 block discarded – undo
6 6
 abstract class HTMLPurifier_Strategy_Composite extends HTMLPurifier_Strategy
7 7
 {
8 8
 
9
-    /**
10
-     * List of strategies to run tokens through.
11
-     */
12
-    protected $strategies = array();
9
+	/**
10
+	 * List of strategies to run tokens through.
11
+	 */
12
+	protected $strategies = array();
13 13
 
14
-    public function execute($tokens, $config, $context) {
15
-        foreach ($this->strategies as $strategy) {
16
-            $tokens = $strategy->execute($tokens, $config, $context);
17
-        }
18
-        return $tokens;
19
-    }
14
+	public function execute($tokens, $config, $context) {
15
+		foreach ($this->strategies as $strategy) {
16
+			$tokens = $strategy->execute($tokens, $config, $context);
17
+		}
18
+		return $tokens;
19
+	}
20 20
 
21 21
 }
22 22
 
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/Strategy/Core.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,12 +6,12 @@
 block discarded – undo
6 6
 class HTMLPurifier_Strategy_Core extends HTMLPurifier_Strategy_Composite
7 7
 {
8 8
 
9
-    public function __construct() {
10
-        $this->strategies[] = new HTMLPurifier_Strategy_RemoveForeignElements();
11
-        $this->strategies[] = new HTMLPurifier_Strategy_MakeWellFormed();
12
-        $this->strategies[] = new HTMLPurifier_Strategy_FixNesting();
13
-        $this->strategies[] = new HTMLPurifier_Strategy_ValidateAttributes();
14
-    }
9
+	public function __construct() {
10
+		$this->strategies[] = new HTMLPurifier_Strategy_RemoveForeignElements();
11
+		$this->strategies[] = new HTMLPurifier_Strategy_MakeWellFormed();
12
+		$this->strategies[] = new HTMLPurifier_Strategy_FixNesting();
13
+		$this->strategies[] = new HTMLPurifier_Strategy_ValidateAttributes();
14
+	}
15 15
 
16 16
 }
17 17
 
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/Strategy/FixNesting.php 3 patches
Indentation   +291 added lines, -291 removed lines patch added patch discarded remove patch
@@ -31,297 +31,297 @@
 block discarded – undo
31 31
 class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy
32 32
 {
33 33
 
34
-    public function execute($tokens, $config, $context) {
35
-        //####################################################################//
36
-        // Pre-processing
37
-
38
-        // get a copy of the HTML definition
39
-        $definition = $config->getHTMLDefinition();
40
-
41
-        // insert implicit "parent" node, will be removed at end.
42
-        // DEFINITION CALL
43
-        $parent_name = $definition->info_parent;
44
-        array_unshift($tokens, new HTMLPurifier_Token_Start($parent_name));
45
-        $tokens[] = new HTMLPurifier_Token_End($parent_name);
46
-
47
-        // setup the context variable 'IsInline', for chameleon processing
48
-        // is 'false' when we are not inline, 'true' when it must always
49
-        // be inline, and an integer when it is inline for a certain
50
-        // branch of the document tree
51
-        $is_inline = $definition->info_parent_def->descendants_are_inline;
52
-        $context->register('IsInline', $is_inline);
53
-
54
-        // setup error collector
55
-        $e =& $context->get('ErrorCollector', true);
56
-
57
-        //####################################################################//
58
-        // Loop initialization
59
-
60
-        // stack that contains the indexes of all parents,
61
-        // $stack[count($stack)-1] being the current parent
62
-        $stack = array();
63
-
64
-        // stack that contains all elements that are excluded
65
-        // it is organized by parent elements, similar to $stack,
66
-        // but it is only populated when an element with exclusions is
67
-        // processed, i.e. there won't be empty exclusions.
68
-        $exclude_stack = array();
69
-
70
-        // variable that contains the start token while we are processing
71
-        // nodes. This enables error reporting to do its job
72
-        $start_token = false;
73
-        $context->register('CurrentToken', $start_token);
74
-
75
-        //####################################################################//
76
-        // Loop
77
-
78
-        // iterate through all start nodes. Determining the start node
79
-        // is complicated so it has been omitted from the loop construct
80
-        for ($i = 0, $size = count($tokens) ; $i < $size; ) {
81
-
82
-            //################################################################//
83
-            // Gather information on children
84
-
85
-            // child token accumulator
86
-            $child_tokens = array();
87
-
88
-            // scroll to the end of this node, report number, and collect
89
-            // all children
90
-            for ($j = $i, $depth = 0; ; $j++) {
91
-                if ($tokens[$j] instanceof HTMLPurifier_Token_Start) {
92
-                    $depth++;
93
-                    // skip token assignment on first iteration, this is the
94
-                    // token we currently are on
95
-                    if ($depth == 1) continue;
96
-                } elseif ($tokens[$j] instanceof HTMLPurifier_Token_End) {
97
-                    $depth--;
98
-                    // skip token assignment on last iteration, this is the
99
-                    // end token of the token we're currently on
100
-                    if ($depth == 0) break;
101
-                }
102
-                $child_tokens[] = $tokens[$j];
103
-            }
104
-
105
-            // $i is index of start token
106
-            // $j is index of end token
107
-
108
-            $start_token = $tokens[$i]; // to make token available via CurrentToken
109
-
110
-            //################################################################//
111
-            // Gather information on parent
112
-
113
-            // calculate parent information
114
-            if ($count = count($stack)) {
115
-                $parent_index = $stack[$count-1];
116
-                $parent_name  = $tokens[$parent_index]->name;
117
-                if ($parent_index == 0) {
118
-                    $parent_def   = $definition->info_parent_def;
119
-                } else {
120
-                    $parent_def   = $definition->info[$parent_name];
121
-                }
122
-            } else {
123
-                // processing as if the parent were the "root" node
124
-                // unknown info, it won't be used anyway, in the future,
125
-                // we may want to enforce one element only (this is
126
-                // necessary for HTML Purifier to clean entire documents
127
-                $parent_index = $parent_name = $parent_def = null;
128
-            }
129
-
130
-            // calculate context
131
-            if ($is_inline === false) {
132
-                // check if conditions make it inline
133
-                if (!empty($parent_def) && $parent_def->descendants_are_inline) {
134
-                    $is_inline = $count - 1;
135
-                }
136
-            } else {
137
-                // check if we're out of inline
138
-                if ($count === $is_inline) {
139
-                    $is_inline = false;
140
-                }
141
-            }
142
-
143
-            //################################################################//
144
-            // Determine whether element is explicitly excluded SGML-style
145
-
146
-            // determine whether or not element is excluded by checking all
147
-            // parent exclusions. The array should not be very large, two
148
-            // elements at most.
149
-            $excluded = false;
150
-            if (!empty($exclude_stack)) {
151
-                foreach ($exclude_stack as $lookup) {
152
-                    if (isset($lookup[$tokens[$i]->name])) {
153
-                        $excluded = true;
154
-                        // no need to continue processing
155
-                        break;
156
-                    }
157
-                }
158
-            }
159
-
160
-            //################################################################//
161
-            // Perform child validation
162
-
163
-            if ($excluded) {
164
-                // there is an exclusion, remove the entire node
165
-                $result = false;
166
-                $excludes = array(); // not used, but good to initialize anyway
167
-            } else {
168
-                // DEFINITION CALL
169
-                if ($i === 0) {
170
-                    // special processing for the first node
171
-                    $def = $definition->info_parent_def;
172
-                } else {
173
-                    $def = $definition->info[$tokens[$i]->name];
174
-
175
-                }
176
-
177
-                if (!empty($def->child)) {
178
-                    // have DTD child def validate children
179
-                    $result = $def->child->validateChildren(
180
-                        $child_tokens, $config, $context);
181
-                } else {
182
-                    // weird, no child definition, get rid of everything
183
-                    $result = false;
184
-                }
185
-
186
-                // determine whether or not this element has any exclusions
187
-                $excludes = $def->excludes;
188
-            }
189
-
190
-            // $result is now a bool or array
191
-
192
-            //################################################################//
193
-            // Process result by interpreting $result
194
-
195
-            if ($result === true || $child_tokens === $result) {
196
-                // leave the node as is
197
-
198
-                // register start token as a parental node start
199
-                $stack[] = $i;
200
-
201
-                // register exclusions if there are any
202
-                if (!empty($excludes)) $exclude_stack[] = $excludes;
203
-
204
-                // move cursor to next possible start node
205
-                $i++;
206
-
207
-            } elseif($result === false) {
208
-                // remove entire node
209
-
210
-                if ($e) {
211
-                    if ($excluded) {
212
-                        $e->send(E_ERROR, 'Strategy_FixNesting: Node excluded');
213
-                    } else {
214
-                        $e->send(E_ERROR, 'Strategy_FixNesting: Node removed');
215
-                    }
216
-                }
217
-
218
-                // calculate length of inner tokens and current tokens
219
-                $length = $j - $i + 1;
220
-
221
-                // perform removal
222
-                array_splice($tokens, $i, $length);
223
-
224
-                // update size
225
-                $size -= $length;
226
-
227
-                // there is no start token to register,
228
-                // current node is now the next possible start node
229
-                // unless it turns out that we need to do a double-check
230
-
231
-                // this is a rought heuristic that covers 100% of HTML's
232
-                // cases and 99% of all other cases. A child definition
233
-                // that would be tricked by this would be something like:
234
-                // ( | a b c) where it's all or nothing. Fortunately,
235
-                // our current implementation claims that that case would
236
-                // not allow empty, even if it did
237
-                if (!$parent_def->child->allow_empty) {
238
-                    // we need to do a double-check
239
-                    $i = $parent_index;
240
-                    array_pop($stack);
241
-                }
242
-
243
-                // PROJECTED OPTIMIZATION: Process all children elements before
244
-                // reprocessing parent node.
245
-
246
-            } else {
247
-                // replace node with $result
248
-
249
-                // calculate length of inner tokens
250
-                $length = $j - $i - 1;
251
-
252
-                if ($e) {
253
-                    if (empty($result) && $length) {
254
-                        $e->send(E_ERROR, 'Strategy_FixNesting: Node contents removed');
255
-                    } else {
256
-                        $e->send(E_WARNING, 'Strategy_FixNesting: Node reorganized');
257
-                    }
258
-                }
259
-
260
-                // perform replacement
261
-                array_splice($tokens, $i + 1, $length, $result);
262
-
263
-                // update size
264
-                $size -= $length;
265
-                $size += count($result);
266
-
267
-                // register start token as a parental node start
268
-                $stack[] = $i;
269
-
270
-                // register exclusions if there are any
271
-                if (!empty($excludes)) $exclude_stack[] = $excludes;
272
-
273
-                // move cursor to next possible start node
274
-                $i++;
275
-
276
-            }
277
-
278
-            //################################################################//
279
-            // Scroll to next start node
280
-
281
-            // We assume, at this point, that $i is the index of the token
282
-            // that is the first possible new start point for a node.
283
-
284
-            // Test if the token indeed is a start tag, if not, move forward
285
-            // and test again.
286
-            $size = count($tokens);
287
-            while ($i < $size and !$tokens[$i] instanceof HTMLPurifier_Token_Start) {
288
-                if ($tokens[$i] instanceof HTMLPurifier_Token_End) {
289
-                    // pop a token index off the stack if we ended a node
290
-                    array_pop($stack);
291
-                    // pop an exclusion lookup off exclusion stack if
292
-                    // we ended node and that node had exclusions
293
-                    if ($i == 0 || $i == $size - 1) {
294
-                        // use specialized var if it's the super-parent
295
-                        $s_excludes = $definition->info_parent_def->excludes;
296
-                    } else {
297
-                        $s_excludes = $definition->info[$tokens[$i]->name]->excludes;
298
-                    }
299
-                    if ($s_excludes) {
300
-                        array_pop($exclude_stack);
301
-                    }
302
-                }
303
-                $i++;
304
-            }
305
-
306
-        }
307
-
308
-        //####################################################################//
309
-        // Post-processing
310
-
311
-        // remove implicit parent tokens at the beginning and end
312
-        array_shift($tokens);
313
-        array_pop($tokens);
314
-
315
-        // remove context variables
316
-        $context->destroy('IsInline');
317
-        $context->destroy('CurrentToken');
318
-
319
-        //####################################################################//
320
-        // Return
321
-
322
-        return $tokens;
323
-
324
-    }
34
+	public function execute($tokens, $config, $context) {
35
+		//####################################################################//
36
+		// Pre-processing
37
+
38
+		// get a copy of the HTML definition
39
+		$definition = $config->getHTMLDefinition();
40
+
41
+		// insert implicit "parent" node, will be removed at end.
42
+		// DEFINITION CALL
43
+		$parent_name = $definition->info_parent;
44
+		array_unshift($tokens, new HTMLPurifier_Token_Start($parent_name));
45
+		$tokens[] = new HTMLPurifier_Token_End($parent_name);
46
+
47
+		// setup the context variable 'IsInline', for chameleon processing
48
+		// is 'false' when we are not inline, 'true' when it must always
49
+		// be inline, and an integer when it is inline for a certain
50
+		// branch of the document tree
51
+		$is_inline = $definition->info_parent_def->descendants_are_inline;
52
+		$context->register('IsInline', $is_inline);
53
+
54
+		// setup error collector
55
+		$e =& $context->get('ErrorCollector', true);
56
+
57
+		//####################################################################//
58
+		// Loop initialization
59
+
60
+		// stack that contains the indexes of all parents,
61
+		// $stack[count($stack)-1] being the current parent
62
+		$stack = array();
63
+
64
+		// stack that contains all elements that are excluded
65
+		// it is organized by parent elements, similar to $stack,
66
+		// but it is only populated when an element with exclusions is
67
+		// processed, i.e. there won't be empty exclusions.
68
+		$exclude_stack = array();
69
+
70
+		// variable that contains the start token while we are processing
71
+		// nodes. This enables error reporting to do its job
72
+		$start_token = false;
73
+		$context->register('CurrentToken', $start_token);
74
+
75
+		//####################################################################//
76
+		// Loop
77
+
78
+		// iterate through all start nodes. Determining the start node
79
+		// is complicated so it has been omitted from the loop construct
80
+		for ($i = 0, $size = count($tokens) ; $i < $size; ) {
81
+
82
+			//################################################################//
83
+			// Gather information on children
84
+
85
+			// child token accumulator
86
+			$child_tokens = array();
87
+
88
+			// scroll to the end of this node, report number, and collect
89
+			// all children
90
+			for ($j = $i, $depth = 0; ; $j++) {
91
+				if ($tokens[$j] instanceof HTMLPurifier_Token_Start) {
92
+					$depth++;
93
+					// skip token assignment on first iteration, this is the
94
+					// token we currently are on
95
+					if ($depth == 1) continue;
96
+				} elseif ($tokens[$j] instanceof HTMLPurifier_Token_End) {
97
+					$depth--;
98
+					// skip token assignment on last iteration, this is the
99
+					// end token of the token we're currently on
100
+					if ($depth == 0) break;
101
+				}
102
+				$child_tokens[] = $tokens[$j];
103
+			}
104
+
105
+			// $i is index of start token
106
+			// $j is index of end token
107
+
108
+			$start_token = $tokens[$i]; // to make token available via CurrentToken
109
+
110
+			//################################################################//
111
+			// Gather information on parent
112
+
113
+			// calculate parent information
114
+			if ($count = count($stack)) {
115
+				$parent_index = $stack[$count-1];
116
+				$parent_name  = $tokens[$parent_index]->name;
117
+				if ($parent_index == 0) {
118
+					$parent_def   = $definition->info_parent_def;
119
+				} else {
120
+					$parent_def   = $definition->info[$parent_name];
121
+				}
122
+			} else {
123
+				// processing as if the parent were the "root" node
124
+				// unknown info, it won't be used anyway, in the future,
125
+				// we may want to enforce one element only (this is
126
+				// necessary for HTML Purifier to clean entire documents
127
+				$parent_index = $parent_name = $parent_def = null;
128
+			}
129
+
130
+			// calculate context
131
+			if ($is_inline === false) {
132
+				// check if conditions make it inline
133
+				if (!empty($parent_def) && $parent_def->descendants_are_inline) {
134
+					$is_inline = $count - 1;
135
+				}
136
+			} else {
137
+				// check if we're out of inline
138
+				if ($count === $is_inline) {
139
+					$is_inline = false;
140
+				}
141
+			}
142
+
143
+			//################################################################//
144
+			// Determine whether element is explicitly excluded SGML-style
145
+
146
+			// determine whether or not element is excluded by checking all
147
+			// parent exclusions. The array should not be very large, two
148
+			// elements at most.
149
+			$excluded = false;
150
+			if (!empty($exclude_stack)) {
151
+				foreach ($exclude_stack as $lookup) {
152
+					if (isset($lookup[$tokens[$i]->name])) {
153
+						$excluded = true;
154
+						// no need to continue processing
155
+						break;
156
+					}
157
+				}
158
+			}
159
+
160
+			//################################################################//
161
+			// Perform child validation
162
+
163
+			if ($excluded) {
164
+				// there is an exclusion, remove the entire node
165
+				$result = false;
166
+				$excludes = array(); // not used, but good to initialize anyway
167
+			} else {
168
+				// DEFINITION CALL
169
+				if ($i === 0) {
170
+					// special processing for the first node
171
+					$def = $definition->info_parent_def;
172
+				} else {
173
+					$def = $definition->info[$tokens[$i]->name];
174
+
175
+				}
176
+
177
+				if (!empty($def->child)) {
178
+					// have DTD child def validate children
179
+					$result = $def->child->validateChildren(
180
+						$child_tokens, $config, $context);
181
+				} else {
182
+					// weird, no child definition, get rid of everything
183
+					$result = false;
184
+				}
185
+
186
+				// determine whether or not this element has any exclusions
187
+				$excludes = $def->excludes;
188
+			}
189
+
190
+			// $result is now a bool or array
191
+
192
+			//################################################################//
193
+			// Process result by interpreting $result
194
+
195
+			if ($result === true || $child_tokens === $result) {
196
+				// leave the node as is
197
+
198
+				// register start token as a parental node start
199
+				$stack[] = $i;
200
+
201
+				// register exclusions if there are any
202
+				if (!empty($excludes)) $exclude_stack[] = $excludes;
203
+
204
+				// move cursor to next possible start node
205
+				$i++;
206
+
207
+			} elseif($result === false) {
208
+				// remove entire node
209
+
210
+				if ($e) {
211
+					if ($excluded) {
212
+						$e->send(E_ERROR, 'Strategy_FixNesting: Node excluded');
213
+					} else {
214
+						$e->send(E_ERROR, 'Strategy_FixNesting: Node removed');
215
+					}
216
+				}
217
+
218
+				// calculate length of inner tokens and current tokens
219
+				$length = $j - $i + 1;
220
+
221
+				// perform removal
222
+				array_splice($tokens, $i, $length);
223
+
224
+				// update size
225
+				$size -= $length;
226
+
227
+				// there is no start token to register,
228
+				// current node is now the next possible start node
229
+				// unless it turns out that we need to do a double-check
230
+
231
+				// this is a rought heuristic that covers 100% of HTML's
232
+				// cases and 99% of all other cases. A child definition
233
+				// that would be tricked by this would be something like:
234
+				// ( | a b c) where it's all or nothing. Fortunately,
235
+				// our current implementation claims that that case would
236
+				// not allow empty, even if it did
237
+				if (!$parent_def->child->allow_empty) {
238
+					// we need to do a double-check
239
+					$i = $parent_index;
240
+					array_pop($stack);
241
+				}
242
+
243
+				// PROJECTED OPTIMIZATION: Process all children elements before
244
+				// reprocessing parent node.
245
+
246
+			} else {
247
+				// replace node with $result
248
+
249
+				// calculate length of inner tokens
250
+				$length = $j - $i - 1;
251
+
252
+				if ($e) {
253
+					if (empty($result) && $length) {
254
+						$e->send(E_ERROR, 'Strategy_FixNesting: Node contents removed');
255
+					} else {
256
+						$e->send(E_WARNING, 'Strategy_FixNesting: Node reorganized');
257
+					}
258
+				}
259
+
260
+				// perform replacement
261
+				array_splice($tokens, $i + 1, $length, $result);
262
+
263
+				// update size
264
+				$size -= $length;
265
+				$size += count($result);
266
+
267
+				// register start token as a parental node start
268
+				$stack[] = $i;
269
+
270
+				// register exclusions if there are any
271
+				if (!empty($excludes)) $exclude_stack[] = $excludes;
272
+
273
+				// move cursor to next possible start node
274
+				$i++;
275
+
276
+			}
277
+
278
+			//################################################################//
279
+			// Scroll to next start node
280
+
281
+			// We assume, at this point, that $i is the index of the token
282
+			// that is the first possible new start point for a node.
283
+
284
+			// Test if the token indeed is a start tag, if not, move forward
285
+			// and test again.
286
+			$size = count($tokens);
287
+			while ($i < $size and !$tokens[$i] instanceof HTMLPurifier_Token_Start) {
288
+				if ($tokens[$i] instanceof HTMLPurifier_Token_End) {
289
+					// pop a token index off the stack if we ended a node
290
+					array_pop($stack);
291
+					// pop an exclusion lookup off exclusion stack if
292
+					// we ended node and that node had exclusions
293
+					if ($i == 0 || $i == $size - 1) {
294
+						// use specialized var if it's the super-parent
295
+						$s_excludes = $definition->info_parent_def->excludes;
296
+					} else {
297
+						$s_excludes = $definition->info[$tokens[$i]->name]->excludes;
298
+					}
299
+					if ($s_excludes) {
300
+						array_pop($exclude_stack);
301
+					}
302
+				}
303
+				$i++;
304
+			}
305
+
306
+		}
307
+
308
+		//####################################################################//
309
+		// Post-processing
310
+
311
+		// remove implicit parent tokens at the beginning and end
312
+		array_shift($tokens);
313
+		array_pop($tokens);
314
+
315
+		// remove context variables
316
+		$context->destroy('IsInline');
317
+		$context->destroy('CurrentToken');
318
+
319
+		//####################################################################//
320
+		// Return
321
+
322
+		return $tokens;
323
+
324
+	}
325 325
 
326 326
 }
327 327
 
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
         $context->register('IsInline', $is_inline);
53 53
 
54 54
         // setup error collector
55
-        $e =& $context->get('ErrorCollector', true);
55
+        $e = & $context->get('ErrorCollector', true);
56 56
 
57 57
         //####################################################################//
58 58
         // Loop initialization
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 
78 78
         // iterate through all start nodes. Determining the start node
79 79
         // is complicated so it has been omitted from the loop construct
80
-        for ($i = 0, $size = count($tokens) ; $i < $size; ) {
80
+        for ($i = 0, $size = count($tokens); $i < $size;) {
81 81
 
82 82
             //################################################################//
83 83
             // Gather information on children
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 
113 113
             // calculate parent information
114 114
             if ($count = count($stack)) {
115
-                $parent_index = $stack[$count-1];
115
+                $parent_index = $stack[$count - 1];
116 116
                 $parent_name  = $tokens[$parent_index]->name;
117 117
                 if ($parent_index == 0) {
118 118
                     $parent_def   = $definition->info_parent_def;
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
                 // move cursor to next possible start node
205 205
                 $i++;
206 206
 
207
-            } elseif($result === false) {
207
+            } elseif ($result === false) {
208 208
                 // remove entire node
209 209
 
210 210
                 if ($e) {
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -92,12 +92,16 @@  discard block
 block discarded – undo
92 92
                     $depth++;
93 93
                     // skip token assignment on first iteration, this is the
94 94
                     // token we currently are on
95
-                    if ($depth == 1) continue;
95
+                    if ($depth == 1) {
96
+                    	continue;
97
+                    }
96 98
                 } elseif ($tokens[$j] instanceof HTMLPurifier_Token_End) {
97 99
                     $depth--;
98 100
                     // skip token assignment on last iteration, this is the
99 101
                     // end token of the token we're currently on
100
-                    if ($depth == 0) break;
102
+                    if ($depth == 0) {
103
+                    	break;
104
+                    }
101 105
                 }
102 106
                 $child_tokens[] = $tokens[$j];
103 107
             }
@@ -199,7 +203,9 @@  discard block
 block discarded – undo
199 203
                 $stack[] = $i;
200 204
 
201 205
                 // register exclusions if there are any
202
-                if (!empty($excludes)) $exclude_stack[] = $excludes;
206
+                if (!empty($excludes)) {
207
+                	$exclude_stack[] = $excludes;
208
+                }
203 209
 
204 210
                 // move cursor to next possible start node
205 211
                 $i++;
@@ -268,7 +274,9 @@  discard block
 block discarded – undo
268 274
                 $stack[] = $i;
269 275
 
270 276
                 // register exclusions if there are any
271
-                if (!empty($excludes)) $exclude_stack[] = $excludes;
277
+                if (!empty($excludes)) {
278
+                	$exclude_stack[] = $excludes;
279
+                }
272 280
 
273 281
                 // move cursor to next possible start node
274 282
                 $i++;
Please login to merge, or discard this patch.
security/htmlpurifier/library/HTMLPurifier/Strategy/MakeWellFormed.php 3 patches
Indentation   +512 added lines, -512 removed lines patch added patch discarded remove patch
@@ -14,518 +14,518 @@
 block discarded – undo
14 14
 class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
15 15
 {
16 16
 
17
-    /**
18
-     * Array stream of tokens being processed.
19
-     */
20
-    protected $tokens;
21
-
22
-    /**
23
-     * Current index in $tokens.
24
-     */
25
-    protected $t;
26
-
27
-    /**
28
-     * Current nesting of elements.
29
-     */
30
-    protected $stack;
31
-
32
-    /**
33
-     * Injectors active in this stream processing.
34
-     */
35
-    protected $injectors;
36
-
37
-    /**
38
-     * Current instance of HTMLPurifier_Config.
39
-     */
40
-    protected $config;
41
-
42
-    /**
43
-     * Current instance of HTMLPurifier_Context.
44
-     */
45
-    protected $context;
46
-
47
-    public function execute($tokens, $config, $context) {
48
-
49
-        $definition = $config->getHTMLDefinition();
50
-
51
-        // local variables
52
-        $generator = new HTMLPurifier_Generator($config, $context);
53
-        $escape_invalid_tags = $config->get('Core.EscapeInvalidTags');
54
-        // used for autoclose early abortion
55
-        $global_parent_allowed_elements = array();
56
-        if (isset($definition->info[$definition->info_parent])) {
57
-            // may be unset under testing circumstances
58
-            $global_parent_allowed_elements = $definition->info[$definition->info_parent]->child->getAllowedElements($config);
59
-        }
60
-        $e = $context->get('ErrorCollector', true);
61
-        $t = false; // token index
62
-        $i = false; // injector index
63
-        $token      = false; // the current token
64
-        $reprocess  = false; // whether or not to reprocess the same token
65
-        $stack = array();
66
-
67
-        // member variables
68
-        $this->stack   =& $stack;
69
-        $this->t       =& $t;
70
-        $this->tokens  =& $tokens;
71
-        $this->config  = $config;
72
-        $this->context = $context;
73
-
74
-        // context variables
75
-        $context->register('CurrentNesting', $stack);
76
-        $context->register('InputIndex',     $t);
77
-        $context->register('InputTokens',    $tokens);
78
-        $context->register('CurrentToken',   $token);
79
-
80
-        // -- begin INJECTOR --
81
-
82
-        $this->injectors = array();
83
-
84
-        $injectors = $config->getBatch('AutoFormat');
85
-        $def_injectors = $definition->info_injector;
86
-        $custom_injectors = $injectors['Custom'];
87
-        unset($injectors['Custom']); // special case
88
-        foreach ($injectors as $injector => $b) {
89
-            // XXX: Fix with a legitimate lookup table of enabled filters
90
-            if (strpos($injector, '.') !== false) continue;
91
-            $injector = "HTMLPurifier_Injector_$injector";
92
-            if (!$b) continue;
93
-            $this->injectors[] = new $injector;
94
-        }
95
-        foreach ($def_injectors as $injector) {
96
-            // assumed to be objects
97
-            $this->injectors[] = $injector;
98
-        }
99
-        foreach ($custom_injectors as $injector) {
100
-            if (!$injector) continue;
101
-            if (is_string($injector)) {
102
-                $injector = "HTMLPurifier_Injector_$injector";
103
-                $injector = new $injector;
104
-            }
105
-            $this->injectors[] = $injector;
106
-        }
107
-
108
-        // give the injectors references to the definition and context
109
-        // variables for performance reasons
110
-        foreach ($this->injectors as $ix => $injector) {
111
-            $error = $injector->prepare($config, $context);
112
-            if (!$error) continue;
113
-            array_splice($this->injectors, $ix, 1); // rm the injector
114
-            trigger_error("Cannot enable {$injector->name} injector because $error is not allowed", E_USER_WARNING);
115
-        }
116
-
117
-        // -- end INJECTOR --
118
-
119
-        // a note on reprocessing:
120
-        //      In order to reduce code duplication, whenever some code needs
121
-        //      to make HTML changes in order to make things "correct", the
122
-        //      new HTML gets sent through the purifier, regardless of its
123
-        //      status. This means that if we add a start token, because it
124
-        //      was totally necessary, we don't have to update nesting; we just
125
-        //      punt ($reprocess = true; continue;) and it does that for us.
126
-
127
-        // isset is in loop because $tokens size changes during loop exec
128
-        for (
129
-            $t = 0;
130
-            $t == 0 || isset($tokens[$t - 1]);
131
-            // only increment if we don't need to reprocess
132
-            $reprocess ? $reprocess = false : $t++
133
-        ) {
134
-
135
-            // check for a rewind
136
-            if (is_int($i) && $i >= 0) {
137
-                // possibility: disable rewinding if the current token has a
138
-                // rewind set on it already. This would offer protection from
139
-                // infinite loop, but might hinder some advanced rewinding.
140
-                $rewind_to = $this->injectors[$i]->getRewind();
141
-                if (is_int($rewind_to) && $rewind_to < $t) {
142
-                    if ($rewind_to < 0) $rewind_to = 0;
143
-                    while ($t > $rewind_to) {
144
-                        $t--;
145
-                        $prev = $tokens[$t];
146
-                        // indicate that other injectors should not process this token,
147
-                        // but we need to reprocess it
148
-                        unset($prev->skip[$i]);
149
-                        $prev->rewind = $i;
150
-                        if ($prev instanceof HTMLPurifier_Token_Start) array_pop($this->stack);
151
-                        elseif ($prev instanceof HTMLPurifier_Token_End) $this->stack[] = $prev->start;
152
-                    }
153
-                }
154
-                $i = false;
155
-            }
156
-
157
-            // handle case of document end
158
-            if (!isset($tokens[$t])) {
159
-                // kill processing if stack is empty
160
-                if (empty($this->stack)) break;
161
-
162
-                // peek
163
-                $top_nesting = array_pop($this->stack);
164
-                $this->stack[] = $top_nesting;
165
-
166
-                // send error [TagClosedSuppress]
167
-                if ($e && !isset($top_nesting->armor['MakeWellFormed_TagClosedError'])) {
168
-                    $e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by document end', $top_nesting);
169
-                }
170
-
171
-                // append, don't splice, since this is the end
172
-                $tokens[] = new HTMLPurifier_Token_End($top_nesting->name);
173
-
174
-                // punt!
175
-                $reprocess = true;
176
-                continue;
177
-            }
178
-
179
-            $token = $tokens[$t];
180
-
181
-            //echo '<br>'; printTokens($tokens, $t); printTokens($this->stack);
182
-            //flush();
183
-
184
-            // quick-check: if it's not a tag, no need to process
185
-            if (empty($token->is_tag)) {
186
-                if ($token instanceof HTMLPurifier_Token_Text) {
187
-                    foreach ($this->injectors as $i => $injector) {
188
-                        if (isset($token->skip[$i])) continue;
189
-                        if ($token->rewind !== null && $token->rewind !== $i) continue;
190
-                        $injector->handleText($token);
191
-                        $this->processToken($token, $i);
192
-                        $reprocess = true;
193
-                        break;
194
-                    }
195
-                }
196
-                // another possibility is a comment
197
-                continue;
198
-            }
199
-
200
-            if (isset($definition->info[$token->name])) {
201
-                $type = $definition->info[$token->name]->child->type;
202
-            } else {
203
-                $type = false; // Type is unknown, treat accordingly
204
-            }
205
-
206
-            // quick tag checks: anything that's *not* an end tag
207
-            $ok = false;
208
-            if ($type === 'empty' && $token instanceof HTMLPurifier_Token_Start) {
209
-                // claims to be a start tag but is empty
210
-                $token = new HTMLPurifier_Token_Empty($token->name, $token->attr, $token->line, $token->col, $token->armor);
211
-                $ok = true;
212
-            } elseif ($type && $type !== 'empty' && $token instanceof HTMLPurifier_Token_Empty) {
213
-                // claims to be empty but really is a start tag
214
-                $this->swap(new HTMLPurifier_Token_End($token->name));
215
-                $this->insertBefore(new HTMLPurifier_Token_Start($token->name, $token->attr, $token->line, $token->col, $token->armor));
216
-                // punt (since we had to modify the input stream in a non-trivial way)
217
-                $reprocess = true;
218
-                continue;
219
-            } elseif ($token instanceof HTMLPurifier_Token_Empty) {
220
-                // real empty token
221
-                $ok = true;
222
-            } elseif ($token instanceof HTMLPurifier_Token_Start) {
223
-                // start tag
224
-
225
-                // ...unless they also have to close their parent
226
-                if (!empty($this->stack)) {
227
-
228
-                    // Performance note: you might think that it's rather
229
-                    // inefficient, recalculating the autoclose information
230
-                    // for every tag that a token closes (since when we
231
-                    // do an autoclose, we push a new token into the
232
-                    // stream and then /process/ that, before
233
-                    // re-processing this token.)  But this is
234
-                    // necessary, because an injector can make an
235
-                    // arbitrary transformations to the autoclosing
236
-                    // tokens we introduce, so things may have changed
237
-                    // in the meantime.  Also, doing the inefficient thing is
238
-                    // "easy" to reason about (for certain perverse definitions
239
-                    // of "easy")
240
-
241
-                    $parent = array_pop($this->stack);
242
-                    $this->stack[] = $parent;
243
-
244
-                    if (isset($definition->info[$parent->name])) {
245
-                        $elements = $definition->info[$parent->name]->child->getAllowedElements($config);
246
-                        $autoclose = !isset($elements[$token->name]);
247
-                    } else {
248
-                        $autoclose = false;
249
-                    }
250
-
251
-                    if ($autoclose && $definition->info[$token->name]->wrap) {
252
-                        // Check if an element can be wrapped by another 
253
-                        // element to make it valid in a context (for 
254
-                        // example, <ul><ul> needs a <li> in between)
255
-                        $wrapname = $definition->info[$token->name]->wrap;
256
-                        $wrapdef = $definition->info[$wrapname];
257
-                        $elements = $wrapdef->child->getAllowedElements($config);
258
-                        $parent_elements = $definition->info[$parent->name]->child->getAllowedElements($config);
259
-                        if (isset($elements[$token->name]) && isset($parent_elements[$wrapname])) {
260
-                            $newtoken = new HTMLPurifier_Token_Start($wrapname);
261
-                            $this->insertBefore($newtoken);
262
-                            $reprocess = true;
263
-                            continue;
264
-                        }
265
-                    }
266
-
267
-                    $carryover = false;
268
-                    if ($autoclose && $definition->info[$parent->name]->formatting) {
269
-                        $carryover = true;
270
-                    }
271
-
272
-                    if ($autoclose) {
273
-                        // check if this autoclose is doomed to fail
274
-                        // (this rechecks $parent, which his harmless)
275
-                        $autoclose_ok = isset($global_parent_allowed_elements[$token->name]);
276
-                        if (!$autoclose_ok) {
277
-                            foreach ($this->stack as $ancestor) {
278
-                                $elements = $definition->info[$ancestor->name]->child->getAllowedElements($config);
279
-                                if (isset($elements[$token->name])) {
280
-                                    $autoclose_ok = true;
281
-                                    break;
282
-                                }
283
-                                if ($definition->info[$token->name]->wrap) {
284
-                                    $wrapname = $definition->info[$token->name]->wrap;
285
-                                    $wrapdef = $definition->info[$wrapname];
286
-                                    $wrap_elements = $wrapdef->child->getAllowedElements($config);
287
-                                    if (isset($wrap_elements[$token->name]) && isset($elements[$wrapname])) {
288
-                                        $autoclose_ok = true;
289
-                                        break;
290
-                                    }
291
-                                }
292
-                            }
293
-                        }
294
-                        if ($autoclose_ok) {
295
-                            // errors need to be updated
296
-                            $new_token = new HTMLPurifier_Token_End($parent->name);
297
-                            $new_token->start = $parent;
298
-                            if ($carryover) {
299
-                                $element = clone $parent;
300
-                                // [TagClosedAuto]
301
-                                $element->armor['MakeWellFormed_TagClosedError'] = true;
302
-                                $element->carryover = true;
303
-                                $this->processToken(array($new_token, $token, $element));
304
-                            } else {
305
-                                $this->insertBefore($new_token);
306
-                            }
307
-                            // [TagClosedSuppress]
308
-                            if ($e && !isset($parent->armor['MakeWellFormed_TagClosedError'])) {
309
-                                if (!$carryover) {
310
-                                    $e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag auto closed', $parent);
311
-                                } else {
312
-                                    $e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag carryover', $parent);
313
-                                }
314
-                            }
315
-                        } else {
316
-                            $this->remove();
317
-                        }
318
-                        $reprocess = true;
319
-                        continue;
320
-                    }
321
-
322
-                }
323
-                $ok = true;
324
-            }
325
-
326
-            if ($ok) {
327
-                foreach ($this->injectors as $i => $injector) {
328
-                    if (isset($token->skip[$i])) continue;
329
-                    if ($token->rewind !== null && $token->rewind !== $i) continue;
330
-                    $injector->handleElement($token);
331
-                    $this->processToken($token, $i);
332
-                    $reprocess = true;
333
-                    break;
334
-                }
335
-                if (!$reprocess) {
336
-                    // ah, nothing interesting happened; do normal processing
337
-                    $this->swap($token);
338
-                    if ($token instanceof HTMLPurifier_Token_Start) {
339
-                        $this->stack[] = $token;
340
-                    } elseif ($token instanceof HTMLPurifier_Token_End) {
341
-                        throw new HTMLPurifier_Exception('Improper handling of end tag in start code; possible error in MakeWellFormed');
342
-                    }
343
-                }
344
-                continue;
345
-            }
346
-
347
-            // sanity check: we should be dealing with a closing tag
348
-            if (!$token instanceof HTMLPurifier_Token_End) {
349
-                throw new HTMLPurifier_Exception('Unaccounted for tag token in input stream, bug in HTML Purifier');
350
-            }
351
-
352
-            // make sure that we have something open
353
-            if (empty($this->stack)) {
354
-                if ($escape_invalid_tags) {
355
-                    if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag to text');
356
-                    $this->swap(new HTMLPurifier_Token_Text(
357
-                        $generator->generateFromToken($token)
358
-                    ));
359
-                } else {
360
-                    $this->remove();
361
-                    if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag removed');
362
-                }
363
-                $reprocess = true;
364
-                continue;
365
-            }
366
-
367
-            // first, check for the simplest case: everything closes neatly.
368
-            // Eventually, everything passes through here; if there are problems
369
-            // we modify the input stream accordingly and then punt, so that
370
-            // the tokens get processed again.
371
-            $current_parent = array_pop($this->stack);
372
-            if ($current_parent->name == $token->name) {
373
-                $token->start = $current_parent;
374
-                foreach ($this->injectors as $i => $injector) {
375
-                    if (isset($token->skip[$i])) continue;
376
-                    if ($token->rewind !== null && $token->rewind !== $i) continue;
377
-                    $injector->handleEnd($token);
378
-                    $this->processToken($token, $i);
379
-                    $this->stack[] = $current_parent;
380
-                    $reprocess = true;
381
-                    break;
382
-                }
383
-                continue;
384
-            }
385
-
386
-            // okay, so we're trying to close the wrong tag
387
-
388
-            // undo the pop previous pop
389
-            $this->stack[] = $current_parent;
390
-
391
-            // scroll back the entire nest, trying to find our tag.
392
-            // (feature could be to specify how far you'd like to go)
393
-            $size = count($this->stack);
394
-            // -2 because -1 is the last element, but we already checked that
395
-            $skipped_tags = false;
396
-            for ($j = $size - 2; $j >= 0; $j--) {
397
-                if ($this->stack[$j]->name == $token->name) {
398
-                    $skipped_tags = array_slice($this->stack, $j);
399
-                    break;
400
-                }
401
-            }
402
-
403
-            // we didn't find the tag, so remove
404
-            if ($skipped_tags === false) {
405
-                if ($escape_invalid_tags) {
406
-                    $this->swap(new HTMLPurifier_Token_Text(
407
-                        $generator->generateFromToken($token)
408
-                    ));
409
-                    if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag to text');
410
-                } else {
411
-                    $this->remove();
412
-                    if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag removed');
413
-                }
414
-                $reprocess = true;
415
-                continue;
416
-            }
417
-
418
-            // do errors, in REVERSE $j order: a,b,c with </a></b></c>
419
-            $c = count($skipped_tags);
420
-            if ($e) {
421
-                for ($j = $c - 1; $j > 0; $j--) {
422
-                    // notice we exclude $j == 0, i.e. the current ending tag, from
423
-                    // the errors... [TagClosedSuppress]
424
-                    if (!isset($skipped_tags[$j]->armor['MakeWellFormed_TagClosedError'])) {
425
-                        $e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by element end', $skipped_tags[$j]);
426
-                    }
427
-                }
428
-            }
429
-
430
-            // insert tags, in FORWARD $j order: c,b,a with </a></b></c>
431
-            $replace = array($token);
432
-            for ($j = 1; $j < $c; $j++) {
433
-                // ...as well as from the insertions
434
-                $new_token = new HTMLPurifier_Token_End($skipped_tags[$j]->name);
435
-                $new_token->start = $skipped_tags[$j];
436
-                array_unshift($replace, $new_token);
437
-                if (isset($definition->info[$new_token->name]) && $definition->info[$new_token->name]->formatting) {
438
-                    // [TagClosedAuto]
439
-                    $element = clone $skipped_tags[$j];
440
-                    $element->carryover = true;
441
-                    $element->armor['MakeWellFormed_TagClosedError'] = true;
442
-                    $replace[] = $element;
443
-                }
444
-            }
445
-            $this->processToken($replace);
446
-            $reprocess = true;
447
-            continue;
448
-        }
449
-
450
-        $context->destroy('CurrentNesting');
451
-        $context->destroy('InputTokens');
452
-        $context->destroy('InputIndex');
453
-        $context->destroy('CurrentToken');
454
-
455
-        unset($this->injectors, $this->stack, $this->tokens, $this->t);
456
-        return $tokens;
457
-    }
458
-
459
-    /**
460
-     * Processes arbitrary token values for complicated substitution patterns.
461
-     * In general:
462
-     *
463
-     * If $token is an array, it is a list of tokens to substitute for the
464
-     * current token. These tokens then get individually processed. If there
465
-     * is a leading integer in the list, that integer determines how many
466
-     * tokens from the stream should be removed.
467
-     *
468
-     * If $token is a regular token, it is swapped with the current token.
469
-     *
470
-     * If $token is false, the current token is deleted.
471
-     *
472
-     * If $token is an integer, that number of tokens (with the first token
473
-     * being the current one) will be deleted.
474
-     *
475
-     * @param $token Token substitution value
476
-     * @param $injector Injector that performed the substitution; default is if
477
-     *        this is not an injector related operation.
478
-     */
479
-    protected function processToken($token, $injector = -1) {
480
-
481
-        // normalize forms of token
482
-        if (is_object($token)) $token = array(1, $token);
483
-        if (is_int($token))    $token = array($token);
484
-        if ($token === false)  $token = array(1);
485
-        if (!is_array($token)) throw new HTMLPurifier_Exception('Invalid token type from injector');
486
-        if (!is_int($token[0])) array_unshift($token, 1);
487
-        if ($token[0] === 0) throw new HTMLPurifier_Exception('Deleting zero tokens is not valid');
488
-
489
-        // $token is now an array with the following form:
490
-        // array(number nodes to delete, new node 1, new node 2, ...)
491
-
492
-        $delete = array_shift($token);
493
-        $old = array_splice($this->tokens, $this->t, $delete, $token);
494
-
495
-        if ($injector > -1) {
496
-            // determine appropriate skips
497
-            $oldskip = isset($old[0]) ? $old[0]->skip : array();
498
-            foreach ($token as $object) {
499
-                $object->skip = $oldskip;
500
-                $object->skip[$injector] = true;
501
-            }
502
-        }
503
-
504
-    }
505
-
506
-    /**
507
-     * Inserts a token before the current token. Cursor now points to
508
-     * this token.  You must reprocess after this.
509
-     */
510
-    private function insertBefore($token) {
511
-        array_splice($this->tokens, $this->t, 0, array($token));
512
-    }
513
-
514
-    /**
515
-     * Removes current token. Cursor now points to new token occupying previously
516
-     * occupied space.  You must reprocess after this.
517
-     */
518
-    private function remove() {
519
-        array_splice($this->tokens, $this->t, 1);
520
-    }
521
-
522
-    /**
523
-     * Swap current token with new token. Cursor points to new token (no
524
-     * change).  You must reprocess after this.
525
-     */
526
-    private function swap($token) {
527
-        $this->tokens[$this->t] = $token;
528
-    }
17
+	/**
18
+	 * Array stream of tokens being processed.
19
+	 */
20
+	protected $tokens;
21
+
22
+	/**
23
+	 * Current index in $tokens.
24
+	 */
25
+	protected $t;
26
+
27
+	/**
28
+	 * Current nesting of elements.
29
+	 */
30
+	protected $stack;
31
+
32
+	/**
33
+	 * Injectors active in this stream processing.
34
+	 */
35
+	protected $injectors;
36
+
37
+	/**
38
+	 * Current instance of HTMLPurifier_Config.
39
+	 */
40
+	protected $config;
41
+
42
+	/**
43
+	 * Current instance of HTMLPurifier_Context.
44
+	 */
45
+	protected $context;
46
+
47
+	public function execute($tokens, $config, $context) {
48
+
49
+		$definition = $config->getHTMLDefinition();
50
+
51
+		// local variables
52
+		$generator = new HTMLPurifier_Generator($config, $context);
53
+		$escape_invalid_tags = $config->get('Core.EscapeInvalidTags');
54
+		// used for autoclose early abortion
55
+		$global_parent_allowed_elements = array();
56
+		if (isset($definition->info[$definition->info_parent])) {
57
+			// may be unset under testing circumstances
58
+			$global_parent_allowed_elements = $definition->info[$definition->info_parent]->child->getAllowedElements($config);
59
+		}
60
+		$e = $context->get('ErrorCollector', true);
61
+		$t = false; // token index
62
+		$i = false; // injector index
63
+		$token      = false; // the current token
64
+		$reprocess  = false; // whether or not to reprocess the same token
65
+		$stack = array();
66
+
67
+		// member variables
68
+		$this->stack   =& $stack;
69
+		$this->t       =& $t;
70
+		$this->tokens  =& $tokens;
71
+		$this->config  = $config;
72
+		$this->context = $context;
73
+
74
+		// context variables
75
+		$context->register('CurrentNesting', $stack);
76
+		$context->register('InputIndex',     $t);
77
+		$context->register('InputTokens',    $tokens);
78
+		$context->register('CurrentToken',   $token);
79
+
80
+		// -- begin INJECTOR --
81
+
82
+		$this->injectors = array();
83
+
84
+		$injectors = $config->getBatch('AutoFormat');
85
+		$def_injectors = $definition->info_injector;
86
+		$custom_injectors = $injectors['Custom'];
87
+		unset($injectors['Custom']); // special case
88
+		foreach ($injectors as $injector => $b) {
89
+			// XXX: Fix with a legitimate lookup table of enabled filters
90
+			if (strpos($injector, '.') !== false) continue;
91
+			$injector = "HTMLPurifier_Injector_$injector";
92
+			if (!$b) continue;
93
+			$this->injectors[] = new $injector;
94
+		}
95
+		foreach ($def_injectors as $injector) {
96
+			// assumed to be objects
97
+			$this->injectors[] = $injector;
98
+		}
99
+		foreach ($custom_injectors as $injector) {
100
+			if (!$injector) continue;
101
+			if (is_string($injector)) {
102
+				$injector = "HTMLPurifier_Injector_$injector";
103
+				$injector = new $injector;
104
+			}
105
+			$this->injectors[] = $injector;
106
+		}
107
+
108
+		// give the injectors references to the definition and context
109
+		// variables for performance reasons
110
+		foreach ($this->injectors as $ix => $injector) {
111
+			$error = $injector->prepare($config, $context);
112
+			if (!$error) continue;
113
+			array_splice($this->injectors, $ix, 1); // rm the injector
114
+			trigger_error("Cannot enable {$injector->name} injector because $error is not allowed", E_USER_WARNING);
115
+		}
116
+
117
+		// -- end INJECTOR --
118
+
119
+		// a note on reprocessing:
120
+		//      In order to reduce code duplication, whenever some code needs
121
+		//      to make HTML changes in order to make things "correct", the
122
+		//      new HTML gets sent through the purifier, regardless of its
123
+		//      status. This means that if we add a start token, because it
124
+		//      was totally necessary, we don't have to update nesting; we just
125
+		//      punt ($reprocess = true; continue;) and it does that for us.
126
+
127
+		// isset is in loop because $tokens size changes during loop exec
128
+		for (
129
+			$t = 0;
130
+			$t == 0 || isset($tokens[$t - 1]);
131
+			// only increment if we don't need to reprocess
132
+			$reprocess ? $reprocess = false : $t++
133
+		) {
134
+
135
+			// check for a rewind
136
+			if (is_int($i) && $i >= 0) {
137
+				// possibility: disable rewinding if the current token has a
138
+				// rewind set on it already. This would offer protection from
139
+				// infinite loop, but might hinder some advanced rewinding.
140
+				$rewind_to = $this->injectors[$i]->getRewind();
141
+				if (is_int($rewind_to) && $rewind_to < $t) {
142
+					if ($rewind_to < 0) $rewind_to = 0;
143
+					while ($t > $rewind_to) {
144
+						$t--;
145
+						$prev = $tokens[$t];
146
+						// indicate that other injectors should not process this token,
147
+						// but we need to reprocess it
148
+						unset($prev->skip[$i]);
149
+						$prev->rewind = $i;
150
+						if ($prev instanceof HTMLPurifier_Token_Start) array_pop($this->stack);
151
+						elseif ($prev instanceof HTMLPurifier_Token_End) $this->stack[] = $prev->start;
152
+					}
153
+				}
154
+				$i = false;
155
+			}
156
+
157
+			// handle case of document end
158
+			if (!isset($tokens[$t])) {
159
+				// kill processing if stack is empty
160
+				if (empty($this->stack)) break;
161
+
162
+				// peek
163
+				$top_nesting = array_pop($this->stack);
164
+				$this->stack[] = $top_nesting;
165
+
166
+				// send error [TagClosedSuppress]
167
+				if ($e && !isset($top_nesting->armor['MakeWellFormed_TagClosedError'])) {
168
+					$e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by document end', $top_nesting);
169
+				}
170
+
171
+				// append, don't splice, since this is the end
172
+				$tokens[] = new HTMLPurifier_Token_End($top_nesting->name);
173
+
174
+				// punt!
175
+				$reprocess = true;
176
+				continue;
177
+			}
178
+
179
+			$token = $tokens[$t];
180
+
181
+			//echo '<br>'; printTokens($tokens, $t); printTokens($this->stack);
182
+			//flush();
183
+
184
+			// quick-check: if it's not a tag, no need to process
185
+			if (empty($token->is_tag)) {
186
+				if ($token instanceof HTMLPurifier_Token_Text) {
187
+					foreach ($this->injectors as $i => $injector) {
188
+						if (isset($token->skip[$i])) continue;
189
+						if ($token->rewind !== null && $token->rewind !== $i) continue;
190
+						$injector->handleText($token);
191
+						$this->processToken($token, $i);
192
+						$reprocess = true;
193
+						break;
194
+					}
195
+				}
196
+				// another possibility is a comment
197
+				continue;
198
+			}
199
+
200
+			if (isset($definition->info[$token->name])) {
201
+				$type = $definition->info[$token->name]->child->type;
202
+			} else {
203
+				$type = false; // Type is unknown, treat accordingly
204
+			}
205
+
206
+			// quick tag checks: anything that's *not* an end tag
207
+			$ok = false;
208
+			if ($type === 'empty' && $token instanceof HTMLPurifier_Token_Start) {
209
+				// claims to be a start tag but is empty
210
+				$token = new HTMLPurifier_Token_Empty($token->name, $token->attr, $token->line, $token->col, $token->armor);
211
+				$ok = true;
212
+			} elseif ($type && $type !== 'empty' && $token instanceof HTMLPurifier_Token_Empty) {
213
+				// claims to be empty but really is a start tag
214
+				$this->swap(new HTMLPurifier_Token_End($token->name));
215
+				$this->insertBefore(new HTMLPurifier_Token_Start($token->name, $token->attr, $token->line, $token->col, $token->armor));
216
+				// punt (since we had to modify the input stream in a non-trivial way)
217
+				$reprocess = true;
218
+				continue;
219
+			} elseif ($token instanceof HTMLPurifier_Token_Empty) {
220
+				// real empty token
221
+				$ok = true;
222
+			} elseif ($token instanceof HTMLPurifier_Token_Start) {
223
+				// start tag
224
+
225
+				// ...unless they also have to close their parent
226
+				if (!empty($this->stack)) {
227
+
228
+					// Performance note: you might think that it's rather
229
+					// inefficient, recalculating the autoclose information
230
+					// for every tag that a token closes (since when we
231
+					// do an autoclose, we push a new token into the
232
+					// stream and then /process/ that, before
233
+					// re-processing this token.)  But this is
234
+					// necessary, because an injector can make an
235
+					// arbitrary transformations to the autoclosing
236
+					// tokens we introduce, so things may have changed
237
+					// in the meantime.  Also, doing the inefficient thing is
238
+					// "easy" to reason about (for certain perverse definitions
239
+					// of "easy")
240
+
241
+					$parent = array_pop($this->stack);
242
+					$this->stack[] = $parent;
243
+
244
+					if (isset($definition->info[$parent->name])) {
245
+						$elements = $definition->info[$parent->name]->child->getAllowedElements($config);
246
+						$autoclose = !isset($elements[$token->name]);
247
+					} else {
248
+						$autoclose = false;
249
+					}
250
+
251
+					if ($autoclose && $definition->info[$token->name]->wrap) {
252
+						// Check if an element can be wrapped by another 
253
+						// element to make it valid in a context (for 
254
+						// example, <ul><ul> needs a <li> in between)
255
+						$wrapname = $definition->info[$token->name]->wrap;
256
+						$wrapdef = $definition->info[$wrapname];
257
+						$elements = $wrapdef->child->getAllowedElements($config);
258
+						$parent_elements = $definition->info[$parent->name]->child->getAllowedElements($config);
259
+						if (isset($elements[$token->name]) && isset($parent_elements[$wrapname])) {
260
+							$newtoken = new HTMLPurifier_Token_Start($wrapname);
261
+							$this->insertBefore($newtoken);
262
+							$reprocess = true;
263
+							continue;
264
+						}
265
+					}
266
+
267
+					$carryover = false;
268
+					if ($autoclose && $definition->info[$parent->name]->formatting) {
269
+						$carryover = true;
270
+					}
271
+
272
+					if ($autoclose) {
273
+						// check if this autoclose is doomed to fail
274
+						// (this rechecks $parent, which his harmless)
275
+						$autoclose_ok = isset($global_parent_allowed_elements[$token->name]);
276
+						if (!$autoclose_ok) {
277
+							foreach ($this->stack as $ancestor) {
278
+								$elements = $definition->info[$ancestor->name]->child->getAllowedElements($config);
279
+								if (isset($elements[$token->name])) {
280
+									$autoclose_ok = true;
281
+									break;
282
+								}
283
+								if ($definition->info[$token->name]->wrap) {
284
+									$wrapname = $definition->info[$token->name]->wrap;
285
+									$wrapdef = $definition->info[$wrapname];
286
+									$wrap_elements = $wrapdef->child->getAllowedElements($config);
287
+									if (isset($wrap_elements[$token->name]) && isset($elements[$wrapname])) {
288
+										$autoclose_ok = true;
289
+										break;
290
+									}
291
+								}
292
+							}
293
+						}
294
+						if ($autoclose_ok) {
295
+							// errors need to be updated
296
+							$new_token = new HTMLPurifier_Token_End($parent->name);
297
+							$new_token->start = $parent;
298
+							if ($carryover) {
299
+								$element = clone $parent;
300
+								// [TagClosedAuto]
301
+								$element->armor['MakeWellFormed_TagClosedError'] = true;
302
+								$element->carryover = true;
303
+								$this->processToken(array($new_token, $token, $element));
304
+							} else {
305
+								$this->insertBefore($new_token);
306
+							}
307
+							// [TagClosedSuppress]
308
+							if ($e && !isset($parent->armor['MakeWellFormed_TagClosedError'])) {
309
+								if (!$carryover) {
310
+									$e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag auto closed', $parent);
311
+								} else {
312
+									$e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag carryover', $parent);
313
+								}
314
+							}
315
+						} else {
316
+							$this->remove();
317
+						}
318
+						$reprocess = true;
319
+						continue;
320
+					}
321
+
322
+				}
323
+				$ok = true;
324
+			}
325
+
326
+			if ($ok) {
327
+				foreach ($this->injectors as $i => $injector) {
328
+					if (isset($token->skip[$i])) continue;
329
+					if ($token->rewind !== null && $token->rewind !== $i) continue;
330
+					$injector->handleElement($token);
331
+					$this->processToken($token, $i);
332
+					$reprocess = true;
333
+					break;
334
+				}
335
+				if (!$reprocess) {
336
+					// ah, nothing interesting happened; do normal processing
337
+					$this->swap($token);
338
+					if ($token instanceof HTMLPurifier_Token_Start) {
339
+						$this->stack[] = $token;
340
+					} elseif ($token instanceof HTMLPurifier_Token_End) {
341
+						throw new HTMLPurifier_Exception('Improper handling of end tag in start code; possible error in MakeWellFormed');
342
+					}
343
+				}
344
+				continue;
345
+			}
346
+
347
+			// sanity check: we should be dealing with a closing tag
348
+			if (!$token instanceof HTMLPurifier_Token_End) {
349
+				throw new HTMLPurifier_Exception('Unaccounted for tag token in input stream, bug in HTML Purifier');
350
+			}
351
+
352
+			// make sure that we have something open
353
+			if (empty($this->stack)) {
354
+				if ($escape_invalid_tags) {
355
+					if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag to text');
356
+					$this->swap(new HTMLPurifier_Token_Text(
357
+						$generator->generateFromToken($token)
358
+					));
359
+				} else {
360
+					$this->remove();
361
+					if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag removed');
362
+				}
363
+				$reprocess = true;
364
+				continue;
365
+			}
366
+
367
+			// first, check for the simplest case: everything closes neatly.
368
+			// Eventually, everything passes through here; if there are problems
369
+			// we modify the input stream accordingly and then punt, so that
370
+			// the tokens get processed again.
371
+			$current_parent = array_pop($this->stack);
372
+			if ($current_parent->name == $token->name) {
373
+				$token->start = $current_parent;
374
+				foreach ($this->injectors as $i => $injector) {
375
+					if (isset($token->skip[$i])) continue;
376
+					if ($token->rewind !== null && $token->rewind !== $i) continue;
377
+					$injector->handleEnd($token);
378
+					$this->processToken($token, $i);
379
+					$this->stack[] = $current_parent;
380
+					$reprocess = true;
381
+					break;
382
+				}
383
+				continue;
384
+			}
385
+
386
+			// okay, so we're trying to close the wrong tag
387
+
388
+			// undo the pop previous pop
389
+			$this->stack[] = $current_parent;
390
+
391
+			// scroll back the entire nest, trying to find our tag.
392
+			// (feature could be to specify how far you'd like to go)
393
+			$size = count($this->stack);
394
+			// -2 because -1 is the last element, but we already checked that
395
+			$skipped_tags = false;
396
+			for ($j = $size - 2; $j >= 0; $j--) {
397
+				if ($this->stack[$j]->name == $token->name) {
398
+					$skipped_tags = array_slice($this->stack, $j);
399
+					break;
400
+				}
401
+			}
402
+
403
+			// we didn't find the tag, so remove
404
+			if ($skipped_tags === false) {
405
+				if ($escape_invalid_tags) {
406
+					$this->swap(new HTMLPurifier_Token_Text(
407
+						$generator->generateFromToken($token)
408
+					));
409
+					if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag to text');
410
+				} else {
411
+					$this->remove();
412
+					if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag removed');
413
+				}
414
+				$reprocess = true;
415
+				continue;
416
+			}
417
+
418
+			// do errors, in REVERSE $j order: a,b,c with </a></b></c>
419
+			$c = count($skipped_tags);
420
+			if ($e) {
421
+				for ($j = $c - 1; $j > 0; $j--) {
422
+					// notice we exclude $j == 0, i.e. the current ending tag, from
423
+					// the errors... [TagClosedSuppress]
424
+					if (!isset($skipped_tags[$j]->armor['MakeWellFormed_TagClosedError'])) {
425
+						$e->send(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by element end', $skipped_tags[$j]);
426
+					}
427
+				}
428
+			}
429
+
430
+			// insert tags, in FORWARD $j order: c,b,a with </a></b></c>
431
+			$replace = array($token);
432
+			for ($j = 1; $j < $c; $j++) {
433
+				// ...as well as from the insertions
434
+				$new_token = new HTMLPurifier_Token_End($skipped_tags[$j]->name);
435
+				$new_token->start = $skipped_tags[$j];
436
+				array_unshift($replace, $new_token);
437
+				if (isset($definition->info[$new_token->name]) && $definition->info[$new_token->name]->formatting) {
438
+					// [TagClosedAuto]
439
+					$element = clone $skipped_tags[$j];
440
+					$element->carryover = true;
441
+					$element->armor['MakeWellFormed_TagClosedError'] = true;
442
+					$replace[] = $element;
443
+				}
444
+			}
445
+			$this->processToken($replace);
446
+			$reprocess = true;
447
+			continue;
448
+		}
449
+
450
+		$context->destroy('CurrentNesting');
451
+		$context->destroy('InputTokens');
452
+		$context->destroy('InputIndex');
453
+		$context->destroy('CurrentToken');
454
+
455
+		unset($this->injectors, $this->stack, $this->tokens, $this->t);
456
+		return $tokens;
457
+	}
458
+
459
+	/**
460
+	 * Processes arbitrary token values for complicated substitution patterns.
461
+	 * In general:
462
+	 *
463
+	 * If $token is an array, it is a list of tokens to substitute for the
464
+	 * current token. These tokens then get individually processed. If there
465
+	 * is a leading integer in the list, that integer determines how many
466
+	 * tokens from the stream should be removed.
467
+	 *
468
+	 * If $token is a regular token, it is swapped with the current token.
469
+	 *
470
+	 * If $token is false, the current token is deleted.
471
+	 *
472
+	 * If $token is an integer, that number of tokens (with the first token
473
+	 * being the current one) will be deleted.
474
+	 *
475
+	 * @param $token Token substitution value
476
+	 * @param $injector Injector that performed the substitution; default is if
477
+	 *        this is not an injector related operation.
478
+	 */
479
+	protected function processToken($token, $injector = -1) {
480
+
481
+		// normalize forms of token
482
+		if (is_object($token)) $token = array(1, $token);
483
+		if (is_int($token))    $token = array($token);
484
+		if ($token === false)  $token = array(1);
485
+		if (!is_array($token)) throw new HTMLPurifier_Exception('Invalid token type from injector');
486
+		if (!is_int($token[0])) array_unshift($token, 1);
487
+		if ($token[0] === 0) throw new HTMLPurifier_Exception('Deleting zero tokens is not valid');
488
+
489
+		// $token is now an array with the following form:
490
+		// array(number nodes to delete, new node 1, new node 2, ...)
491
+
492
+		$delete = array_shift($token);
493
+		$old = array_splice($this->tokens, $this->t, $delete, $token);
494
+
495
+		if ($injector > -1) {
496
+			// determine appropriate skips
497
+			$oldskip = isset($old[0]) ? $old[0]->skip : array();
498
+			foreach ($token as $object) {
499
+				$object->skip = $oldskip;
500
+				$object->skip[$injector] = true;
501
+			}
502
+		}
503
+
504
+	}
505
+
506
+	/**
507
+	 * Inserts a token before the current token. Cursor now points to
508
+	 * this token.  You must reprocess after this.
509
+	 */
510
+	private function insertBefore($token) {
511
+		array_splice($this->tokens, $this->t, 0, array($token));
512
+	}
513
+
514
+	/**
515
+	 * Removes current token. Cursor now points to new token occupying previously
516
+	 * occupied space.  You must reprocess after this.
517
+	 */
518
+	private function remove() {
519
+		array_splice($this->tokens, $this->t, 1);
520
+	}
521
+
522
+	/**
523
+	 * Swap current token with new token. Cursor points to new token (no
524
+	 * change).  You must reprocess after this.
525
+	 */
526
+	private function swap($token) {
527
+		$this->tokens[$this->t] = $token;
528
+	}
529 529
 
530 530
 }
531 531
 
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -65,17 +65,17 @@
 block discarded – undo
65 65
         $stack = array();
66 66
 
67 67
         // member variables
68
-        $this->stack   =& $stack;
69
-        $this->t       =& $t;
70
-        $this->tokens  =& $tokens;
68
+        $this->stack   = & $stack;
69
+        $this->t       = & $t;
70
+        $this->tokens  = & $tokens;
71 71
         $this->config  = $config;
72 72
         $this->context = $context;
73 73
 
74 74
         // context variables
75 75
         $context->register('CurrentNesting', $stack);
76
-        $context->register('InputIndex',     $t);
77
-        $context->register('InputTokens',    $tokens);
78
-        $context->register('CurrentToken',   $token);
76
+        $context->register('InputIndex', $t);
77
+        $context->register('InputTokens', $tokens);
78
+        $context->register('CurrentToken', $token);
79 79
 
80 80
         // -- begin INJECTOR --
81 81
 
Please login to merge, or discard this patch.
Braces   +71 added lines, -24 removed lines patch added patch discarded remove patch
@@ -87,9 +87,13 @@  discard block
 block discarded – undo
87 87
         unset($injectors['Custom']); // special case
88 88
         foreach ($injectors as $injector => $b) {
89 89
             // XXX: Fix with a legitimate lookup table of enabled filters
90
-            if (strpos($injector, '.') !== false) continue;
90
+            if (strpos($injector, '.') !== false) {
91
+            	continue;
92
+            }
91 93
             $injector = "HTMLPurifier_Injector_$injector";
92
-            if (!$b) continue;
94
+            if (!$b) {
95
+            	continue;
96
+            }
93 97
             $this->injectors[] = new $injector;
94 98
         }
95 99
         foreach ($def_injectors as $injector) {
@@ -97,7 +101,9 @@  discard block
 block discarded – undo
97 101
             $this->injectors[] = $injector;
98 102
         }
99 103
         foreach ($custom_injectors as $injector) {
100
-            if (!$injector) continue;
104
+            if (!$injector) {
105
+            	continue;
106
+            }
101 107
             if (is_string($injector)) {
102 108
                 $injector = "HTMLPurifier_Injector_$injector";
103 109
                 $injector = new $injector;
@@ -109,7 +115,9 @@  discard block
 block discarded – undo
109 115
         // variables for performance reasons
110 116
         foreach ($this->injectors as $ix => $injector) {
111 117
             $error = $injector->prepare($config, $context);
112
-            if (!$error) continue;
118
+            if (!$error) {
119
+            	continue;
120
+            }
113 121
             array_splice($this->injectors, $ix, 1); // rm the injector
114 122
             trigger_error("Cannot enable {$injector->name} injector because $error is not allowed", E_USER_WARNING);
115 123
         }
@@ -139,7 +147,9 @@  discard block
 block discarded – undo
139 147
                 // infinite loop, but might hinder some advanced rewinding.
140 148
                 $rewind_to = $this->injectors[$i]->getRewind();
141 149
                 if (is_int($rewind_to) && $rewind_to < $t) {
142
-                    if ($rewind_to < 0) $rewind_to = 0;
150
+                    if ($rewind_to < 0) {
151
+                    	$rewind_to = 0;
152
+                    }
143 153
                     while ($t > $rewind_to) {
144 154
                         $t--;
145 155
                         $prev = $tokens[$t];
@@ -147,8 +157,11 @@  discard block
 block discarded – undo
147 157
                         // but we need to reprocess it
148 158
                         unset($prev->skip[$i]);
149 159
                         $prev->rewind = $i;
150
-                        if ($prev instanceof HTMLPurifier_Token_Start) array_pop($this->stack);
151
-                        elseif ($prev instanceof HTMLPurifier_Token_End) $this->stack[] = $prev->start;
160
+                        if ($prev instanceof HTMLPurifier_Token_Start) {
161
+                        	array_pop($this->stack);
162
+                        } elseif ($prev instanceof HTMLPurifier_Token_End) {
163
+                        	$this->stack[] = $prev->start;
164
+                        }
152 165
                     }
153 166
                 }
154 167
                 $i = false;
@@ -157,7 +170,9 @@  discard block
 block discarded – undo
157 170
             // handle case of document end
158 171
             if (!isset($tokens[$t])) {
159 172
                 // kill processing if stack is empty
160
-                if (empty($this->stack)) break;
173
+                if (empty($this->stack)) {
174
+                	break;
175
+                }
161 176
 
162 177
                 // peek
163 178
                 $top_nesting = array_pop($this->stack);
@@ -185,8 +200,12 @@  discard block
 block discarded – undo
185 200
             if (empty($token->is_tag)) {
186 201
                 if ($token instanceof HTMLPurifier_Token_Text) {
187 202
                     foreach ($this->injectors as $i => $injector) {
188
-                        if (isset($token->skip[$i])) continue;
189
-                        if ($token->rewind !== null && $token->rewind !== $i) continue;
203
+                        if (isset($token->skip[$i])) {
204
+                        	continue;
205
+                        }
206
+                        if ($token->rewind !== null && $token->rewind !== $i) {
207
+                        	continue;
208
+                        }
190 209
                         $injector->handleText($token);
191 210
                         $this->processToken($token, $i);
192 211
                         $reprocess = true;
@@ -325,8 +344,12 @@  discard block
 block discarded – undo
325 344
 
326 345
             if ($ok) {
327 346
                 foreach ($this->injectors as $i => $injector) {
328
-                    if (isset($token->skip[$i])) continue;
329
-                    if ($token->rewind !== null && $token->rewind !== $i) continue;
347
+                    if (isset($token->skip[$i])) {
348
+                    	continue;
349
+                    }
350
+                    if ($token->rewind !== null && $token->rewind !== $i) {
351
+                    	continue;
352
+                    }
330 353
                     $injector->handleElement($token);
331 354
                     $this->processToken($token, $i);
332 355
                     $reprocess = true;
@@ -352,13 +375,17 @@  discard block
 block discarded – undo
352 375
             // make sure that we have something open
353 376
             if (empty($this->stack)) {
354 377
                 if ($escape_invalid_tags) {
355
-                    if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag to text');
378
+                    if ($e) {
379
+                    	$e->send(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag to text');
380
+                    }
356 381
                     $this->swap(new HTMLPurifier_Token_Text(
357 382
                         $generator->generateFromToken($token)
358 383
                     ));
359 384
                 } else {
360 385
                     $this->remove();
361
-                    if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag removed');
386
+                    if ($e) {
387
+                    	$e->send(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag removed');
388
+                    }
362 389
                 }
363 390
                 $reprocess = true;
364 391
                 continue;
@@ -372,8 +399,12 @@  discard block
 block discarded – undo
372 399
             if ($current_parent->name == $token->name) {
373 400
                 $token->start = $current_parent;
374 401
                 foreach ($this->injectors as $i => $injector) {
375
-                    if (isset($token->skip[$i])) continue;
376
-                    if ($token->rewind !== null && $token->rewind !== $i) continue;
402
+                    if (isset($token->skip[$i])) {
403
+                    	continue;
404
+                    }
405
+                    if ($token->rewind !== null && $token->rewind !== $i) {
406
+                    	continue;
407
+                    }
377 408
                     $injector->handleEnd($token);
378 409
                     $this->processToken($token, $i);
379 410
                     $this->stack[] = $current_parent;
@@ -406,10 +437,14 @@  discard block
 block discarded – undo
406 437
                     $this->swap(new HTMLPurifier_Token_Text(
407 438
                         $generator->generateFromToken($token)
408 439
                     ));
409
-                    if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag to text');
440
+                    if ($e) {
441
+                    	$e->send(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag to text');
442
+                    }
410 443
                 } else {
411 444
                     $this->remove();
412
-                    if ($e) $e->send(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag removed');
445
+                    if ($e) {
446
+                    	$e->send(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag removed');
447
+                    }
413 448
                 }
414 449
                 $reprocess = true;
415 450
                 continue;
@@ -479,12 +514,24 @@  discard block
 block discarded – undo
479 514
     protected function processToken($token, $injector = -1) {
480 515
 
481 516
         // normalize forms of token
482
-        if (is_object($token)) $token = array(1, $token);
483
-        if (is_int($token))    $token = array($token);
484
-        if ($token === false)  $token = array(1);
485
-        if (!is_array($token)) throw new HTMLPurifier_Exception('Invalid token type from injector');
486
-        if (!is_int($token[0])) array_unshift($token, 1);
487
-        if ($token[0] === 0) throw new HTMLPurifier_Exception('Deleting zero tokens is not valid');
517
+        if (is_object($token)) {
518
+        	$token = array(1, $token);
519
+        }
520
+        if (is_int($token)) {
521
+        	$token = array($token);
522
+        }
523
+        if ($token === false) {
524
+        	$token = array(1);
525
+        }
526
+        if (!is_array($token)) {
527
+        	throw new HTMLPurifier_Exception('Invalid token type from injector');
528
+        }
529
+        if (!is_int($token[0])) {
530
+        	array_unshift($token, 1);
531
+        }
532
+        if ($token[0] === 0) {
533
+        	throw new HTMLPurifier_Exception('Deleting zero tokens is not valid');
534
+        }
488 535
 
489 536
         // $token is now an array with the following form:
490 537
         // array(number nodes to delete, new node 1, new node 2, ...)
Please login to merge, or discard this patch.