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 ( b130b6...8a2f54 )
by gyeong-won
07:36
created
classes/security/htmlpurifier/library/HTMLPurifier/Lexer/PH5P.php 4 patches
Doc Comments   +18 added lines patch added patch discarded remove patch
@@ -124,6 +124,9 @@  discard block
 block discarded – undo
124 124
     const CHARACTR = 4;
125 125
     const EOF      = 5;
126 126
 
127
+    /**
128
+     * @param string $data
129
+     */
127 130
     public function __construct($data) {
128 131
 
129 132
         $this->data = $data;
@@ -143,12 +146,20 @@  discard block
 block discarded – undo
143 146
         return $this->tree->save();
144 147
     }
145 148
 
149
+    /**
150
+     * @return string
151
+     */
146 152
     private function char() {
147 153
         return ($this->char < $this->EOF)
148 154
             ? $this->data[$this->char]
149 155
             : false;
150 156
     }
151 157
 
158
+    /**
159
+     * @param integer $s
160
+     *
161
+     * @return string
162
+     */
152 163
     private function character($s, $l = 0) {
153 164
         if($s + $l < $this->EOF) {
154 165
             if($l === 0) {
@@ -159,6 +170,10 @@  discard block
 block discarded – undo
159 170
         }
160 171
     }
161 172
 
173
+    /**
174
+     * @param string $char_class
175
+     * @param integer $start
176
+     */
162 177
     private function characters($char_class, $start) {
163 178
         return preg_replace('#^(['.$char_class.']+).*#s', '\\1', substr($this->data, $start));
164 179
     }
@@ -3767,6 +3782,9 @@  discard block
 block discarded – undo
3767 3782
             return self::PHRASING;
3768 3783
     }
3769 3784
 
3785
+    /**
3786
+     * @param string[] $elements
3787
+     */
3770 3788
     private function clearStackToTableContext($elements) {
3771 3789
         /* When the steps above require the UA to clear the stack back to a
3772 3790
         table context, it means that the UA must, while the current node is not
Please login to merge, or discard this patch.
Indentation   +2868 added lines, -2868 removed lines patch added patch discarded remove patch
@@ -12,26 +12,26 @@  discard block
 block discarded – undo
12 12
 
13 13
 class HTMLPurifier_Lexer_PH5P extends HTMLPurifier_Lexer_DOMLex {
14 14
     
15
-    public function tokenizeHTML($html, $config, $context) {
16
-        $new_html = $this->normalize($html, $config, $context);
17
-        $new_html = $this->wrapHTML($new_html, $config, $context);
18
-        try {
19
-            $parser = new HTML5($new_html);
20
-            $doc = $parser->save();
21
-        } catch (DOMException $e) {
22
-            // Uh oh, it failed. Punt to DirectLex.
23
-            $lexer = new HTMLPurifier_Lexer_DirectLex();
24
-            $context->register('PH5PError', $e); // save the error, so we can detect it
25
-            return $lexer->tokenizeHTML($html, $config, $context); // use original HTML
26
-        }
27
-        $tokens = array();
28
-        $this->tokenizeDOM(
29
-            $doc->getElementsByTagName('html')->item(0)-> // <html>
30
-                  getElementsByTagName('body')->item(0)-> //   <body>
31
-                  getElementsByTagName('div')->item(0)    //     <div>
32
-            , $tokens);
33
-        return $tokens;
34
-    }
15
+	public function tokenizeHTML($html, $config, $context) {
16
+		$new_html = $this->normalize($html, $config, $context);
17
+		$new_html = $this->wrapHTML($new_html, $config, $context);
18
+		try {
19
+			$parser = new HTML5($new_html);
20
+			$doc = $parser->save();
21
+		} catch (DOMException $e) {
22
+			// Uh oh, it failed. Punt to DirectLex.
23
+			$lexer = new HTMLPurifier_Lexer_DirectLex();
24
+			$context->register('PH5PError', $e); // save the error, so we can detect it
25
+			return $lexer->tokenizeHTML($html, $config, $context); // use original HTML
26
+		}
27
+		$tokens = array();
28
+		$this->tokenizeDOM(
29
+			$doc->getElementsByTagName('html')->item(0)-> // <html>
30
+				  getElementsByTagName('body')->item(0)-> //   <body>
31
+				  getElementsByTagName('div')->item(0)    //     <div>
32
+			, $tokens);
33
+		return $tokens;
34
+	}
35 35
     
36 36
 }
37 37
 
@@ -61,145 +61,145 @@  discard block
 block discarded – undo
61 61
 */
62 62
 
63 63
 class HTML5 {
64
-    private $data;
65
-    private $char;
66
-    private $EOF;
67
-    private $state;
68
-    private $tree;
69
-    private $token;
70
-    private $content_model;
71
-    private $escape = false;
72
-    private $entities = array('AElig;','AElig','AMP;','AMP','Aacute;','Aacute',
73
-    'Acirc;','Acirc','Agrave;','Agrave','Alpha;','Aring;','Aring','Atilde;',
74
-    'Atilde','Auml;','Auml','Beta;','COPY;','COPY','Ccedil;','Ccedil','Chi;',
75
-    'Dagger;','Delta;','ETH;','ETH','Eacute;','Eacute','Ecirc;','Ecirc','Egrave;',
76
-    'Egrave','Epsilon;','Eta;','Euml;','Euml','GT;','GT','Gamma;','Iacute;',
77
-    'Iacute','Icirc;','Icirc','Igrave;','Igrave','Iota;','Iuml;','Iuml','Kappa;',
78
-    'LT;','LT','Lambda;','Mu;','Ntilde;','Ntilde','Nu;','OElig;','Oacute;',
79
-    'Oacute','Ocirc;','Ocirc','Ograve;','Ograve','Omega;','Omicron;','Oslash;',
80
-    'Oslash','Otilde;','Otilde','Ouml;','Ouml','Phi;','Pi;','Prime;','Psi;',
81
-    'QUOT;','QUOT','REG;','REG','Rho;','Scaron;','Sigma;','THORN;','THORN',
82
-    'TRADE;','Tau;','Theta;','Uacute;','Uacute','Ucirc;','Ucirc','Ugrave;',
83
-    'Ugrave','Upsilon;','Uuml;','Uuml','Xi;','Yacute;','Yacute','Yuml;','Zeta;',
84
-    'aacute;','aacute','acirc;','acirc','acute;','acute','aelig;','aelig',
85
-    'agrave;','agrave','alefsym;','alpha;','amp;','amp','and;','ang;','apos;',
86
-    'aring;','aring','asymp;','atilde;','atilde','auml;','auml','bdquo;','beta;',
87
-    'brvbar;','brvbar','bull;','cap;','ccedil;','ccedil','cedil;','cedil',
88
-    'cent;','cent','chi;','circ;','clubs;','cong;','copy;','copy','crarr;',
89
-    'cup;','curren;','curren','dArr;','dagger;','darr;','deg;','deg','delta;',
90
-    'diams;','divide;','divide','eacute;','eacute','ecirc;','ecirc','egrave;',
91
-    'egrave','empty;','emsp;','ensp;','epsilon;','equiv;','eta;','eth;','eth',
92
-    'euml;','euml','euro;','exist;','fnof;','forall;','frac12;','frac12',
93
-    'frac14;','frac14','frac34;','frac34','frasl;','gamma;','ge;','gt;','gt',
94
-    'hArr;','harr;','hearts;','hellip;','iacute;','iacute','icirc;','icirc',
95
-    'iexcl;','iexcl','igrave;','igrave','image;','infin;','int;','iota;',
96
-    'iquest;','iquest','isin;','iuml;','iuml','kappa;','lArr;','lambda;','lang;',
97
-    'laquo;','laquo','larr;','lceil;','ldquo;','le;','lfloor;','lowast;','loz;',
98
-    'lrm;','lsaquo;','lsquo;','lt;','lt','macr;','macr','mdash;','micro;','micro',
99
-    'middot;','middot','minus;','mu;','nabla;','nbsp;','nbsp','ndash;','ne;',
100
-    'ni;','not;','not','notin;','nsub;','ntilde;','ntilde','nu;','oacute;',
101
-    'oacute','ocirc;','ocirc','oelig;','ograve;','ograve','oline;','omega;',
102
-    'omicron;','oplus;','or;','ordf;','ordf','ordm;','ordm','oslash;','oslash',
103
-    'otilde;','otilde','otimes;','ouml;','ouml','para;','para','part;','permil;',
104
-    'perp;','phi;','pi;','piv;','plusmn;','plusmn','pound;','pound','prime;',
105
-    'prod;','prop;','psi;','quot;','quot','rArr;','radic;','rang;','raquo;',
106
-    'raquo','rarr;','rceil;','rdquo;','real;','reg;','reg','rfloor;','rho;',
107
-    'rlm;','rsaquo;','rsquo;','sbquo;','scaron;','sdot;','sect;','sect','shy;',
108
-    'shy','sigma;','sigmaf;','sim;','spades;','sub;','sube;','sum;','sup1;',
109
-    'sup1','sup2;','sup2','sup3;','sup3','sup;','supe;','szlig;','szlig','tau;',
110
-    'there4;','theta;','thetasym;','thinsp;','thorn;','thorn','tilde;','times;',
111
-    'times','trade;','uArr;','uacute;','uacute','uarr;','ucirc;','ucirc',
112
-    'ugrave;','ugrave','uml;','uml','upsih;','upsilon;','uuml;','uuml','weierp;',
113
-    'xi;','yacute;','yacute','yen;','yen','yuml;','yuml','zeta;','zwj;','zwnj;');
114
-
115
-    const PCDATA    = 0;
116
-    const RCDATA    = 1;
117
-    const CDATA     = 2;
118
-    const PLAINTEXT = 3;
119
-
120
-    const DOCTYPE  = 0;
121
-    const STARTTAG = 1;
122
-    const ENDTAG   = 2;
123
-    const COMMENT  = 3;
124
-    const CHARACTR = 4;
125
-    const EOF      = 5;
126
-
127
-    public function __construct($data) {
128
-
129
-        $this->data = $data;
130
-        $this->char = -1;
131
-        $this->EOF  = strlen($data);
132
-        $this->tree = new HTML5TreeConstructer;
133
-        $this->content_model = self::PCDATA;
134
-
135
-        $this->state = 'data';
136
-
137
-        while($this->state !== null) {
138
-            $this->{$this->state.'State'}();
139
-        }
140
-    }
141
-
142
-    public function save() {
143
-        return $this->tree->save();
144
-    }
145
-
146
-    private function char() {
147
-        return ($this->char < $this->EOF)
148
-            ? $this->data[$this->char]
149
-            : false;
150
-    }
151
-
152
-    private function character($s, $l = 0) {
153
-        if($s + $l < $this->EOF) {
154
-            if($l === 0) {
155
-                return $this->data[$s];
156
-            } else {
157
-                return substr($this->data, $s, $l);
158
-            }
159
-        }
160
-    }
161
-
162
-    private function characters($char_class, $start) {
163
-        return preg_replace('#^(['.$char_class.']+).*#s', '\\1', substr($this->data, $start));
164
-    }
165
-
166
-    private function dataState() {
167
-        // Consume the next input character
168
-        $this->char++;
169
-        $char = $this->char();
170
-
171
-        if($char === '&' && ($this->content_model === self::PCDATA || $this->content_model === self::RCDATA)) {
172
-            /* U+0026 AMPERSAND (&)
64
+	private $data;
65
+	private $char;
66
+	private $EOF;
67
+	private $state;
68
+	private $tree;
69
+	private $token;
70
+	private $content_model;
71
+	private $escape = false;
72
+	private $entities = array('AElig;','AElig','AMP;','AMP','Aacute;','Aacute',
73
+	'Acirc;','Acirc','Agrave;','Agrave','Alpha;','Aring;','Aring','Atilde;',
74
+	'Atilde','Auml;','Auml','Beta;','COPY;','COPY','Ccedil;','Ccedil','Chi;',
75
+	'Dagger;','Delta;','ETH;','ETH','Eacute;','Eacute','Ecirc;','Ecirc','Egrave;',
76
+	'Egrave','Epsilon;','Eta;','Euml;','Euml','GT;','GT','Gamma;','Iacute;',
77
+	'Iacute','Icirc;','Icirc','Igrave;','Igrave','Iota;','Iuml;','Iuml','Kappa;',
78
+	'LT;','LT','Lambda;','Mu;','Ntilde;','Ntilde','Nu;','OElig;','Oacute;',
79
+	'Oacute','Ocirc;','Ocirc','Ograve;','Ograve','Omega;','Omicron;','Oslash;',
80
+	'Oslash','Otilde;','Otilde','Ouml;','Ouml','Phi;','Pi;','Prime;','Psi;',
81
+	'QUOT;','QUOT','REG;','REG','Rho;','Scaron;','Sigma;','THORN;','THORN',
82
+	'TRADE;','Tau;','Theta;','Uacute;','Uacute','Ucirc;','Ucirc','Ugrave;',
83
+	'Ugrave','Upsilon;','Uuml;','Uuml','Xi;','Yacute;','Yacute','Yuml;','Zeta;',
84
+	'aacute;','aacute','acirc;','acirc','acute;','acute','aelig;','aelig',
85
+	'agrave;','agrave','alefsym;','alpha;','amp;','amp','and;','ang;','apos;',
86
+	'aring;','aring','asymp;','atilde;','atilde','auml;','auml','bdquo;','beta;',
87
+	'brvbar;','brvbar','bull;','cap;','ccedil;','ccedil','cedil;','cedil',
88
+	'cent;','cent','chi;','circ;','clubs;','cong;','copy;','copy','crarr;',
89
+	'cup;','curren;','curren','dArr;','dagger;','darr;','deg;','deg','delta;',
90
+	'diams;','divide;','divide','eacute;','eacute','ecirc;','ecirc','egrave;',
91
+	'egrave','empty;','emsp;','ensp;','epsilon;','equiv;','eta;','eth;','eth',
92
+	'euml;','euml','euro;','exist;','fnof;','forall;','frac12;','frac12',
93
+	'frac14;','frac14','frac34;','frac34','frasl;','gamma;','ge;','gt;','gt',
94
+	'hArr;','harr;','hearts;','hellip;','iacute;','iacute','icirc;','icirc',
95
+	'iexcl;','iexcl','igrave;','igrave','image;','infin;','int;','iota;',
96
+	'iquest;','iquest','isin;','iuml;','iuml','kappa;','lArr;','lambda;','lang;',
97
+	'laquo;','laquo','larr;','lceil;','ldquo;','le;','lfloor;','lowast;','loz;',
98
+	'lrm;','lsaquo;','lsquo;','lt;','lt','macr;','macr','mdash;','micro;','micro',
99
+	'middot;','middot','minus;','mu;','nabla;','nbsp;','nbsp','ndash;','ne;',
100
+	'ni;','not;','not','notin;','nsub;','ntilde;','ntilde','nu;','oacute;',
101
+	'oacute','ocirc;','ocirc','oelig;','ograve;','ograve','oline;','omega;',
102
+	'omicron;','oplus;','or;','ordf;','ordf','ordm;','ordm','oslash;','oslash',
103
+	'otilde;','otilde','otimes;','ouml;','ouml','para;','para','part;','permil;',
104
+	'perp;','phi;','pi;','piv;','plusmn;','plusmn','pound;','pound','prime;',
105
+	'prod;','prop;','psi;','quot;','quot','rArr;','radic;','rang;','raquo;',
106
+	'raquo','rarr;','rceil;','rdquo;','real;','reg;','reg','rfloor;','rho;',
107
+	'rlm;','rsaquo;','rsquo;','sbquo;','scaron;','sdot;','sect;','sect','shy;',
108
+	'shy','sigma;','sigmaf;','sim;','spades;','sub;','sube;','sum;','sup1;',
109
+	'sup1','sup2;','sup2','sup3;','sup3','sup;','supe;','szlig;','szlig','tau;',
110
+	'there4;','theta;','thetasym;','thinsp;','thorn;','thorn','tilde;','times;',
111
+	'times','trade;','uArr;','uacute;','uacute','uarr;','ucirc;','ucirc',
112
+	'ugrave;','ugrave','uml;','uml','upsih;','upsilon;','uuml;','uuml','weierp;',
113
+	'xi;','yacute;','yacute','yen;','yen','yuml;','yuml','zeta;','zwj;','zwnj;');
114
+
115
+	const PCDATA    = 0;
116
+	const RCDATA    = 1;
117
+	const CDATA     = 2;
118
+	const PLAINTEXT = 3;
119
+
120
+	const DOCTYPE  = 0;
121
+	const STARTTAG = 1;
122
+	const ENDTAG   = 2;
123
+	const COMMENT  = 3;
124
+	const CHARACTR = 4;
125
+	const EOF      = 5;
126
+
127
+	public function __construct($data) {
128
+
129
+		$this->data = $data;
130
+		$this->char = -1;
131
+		$this->EOF  = strlen($data);
132
+		$this->tree = new HTML5TreeConstructer;
133
+		$this->content_model = self::PCDATA;
134
+
135
+		$this->state = 'data';
136
+
137
+		while($this->state !== null) {
138
+			$this->{$this->state.'State'}();
139
+		}
140
+	}
141
+
142
+	public function save() {
143
+		return $this->tree->save();
144
+	}
145
+
146
+	private function char() {
147
+		return ($this->char < $this->EOF)
148
+			? $this->data[$this->char]
149
+			: false;
150
+	}
151
+
152
+	private function character($s, $l = 0) {
153
+		if($s + $l < $this->EOF) {
154
+			if($l === 0) {
155
+				return $this->data[$s];
156
+			} else {
157
+				return substr($this->data, $s, $l);
158
+			}
159
+		}
160
+	}
161
+
162
+	private function characters($char_class, $start) {
163
+		return preg_replace('#^(['.$char_class.']+).*#s', '\\1', substr($this->data, $start));
164
+	}
165
+
166
+	private function dataState() {
167
+		// Consume the next input character
168
+		$this->char++;
169
+		$char = $this->char();
170
+
171
+		if($char === '&' && ($this->content_model === self::PCDATA || $this->content_model === self::RCDATA)) {
172
+			/* U+0026 AMPERSAND (&)
173 173
             When the content model flag is set to one of the PCDATA or RCDATA
174 174
             states: switch to the entity data state. Otherwise: treat it as per
175 175
             the "anything else"    entry below. */
176
-            $this->state = 'entityData';
176
+			$this->state = 'entityData';
177 177
 
178
-        } elseif($char === '-') {
179
-            /* If the content model flag is set to either the RCDATA state or
178
+		} elseif($char === '-') {
179
+			/* If the content model flag is set to either the RCDATA state or
180 180
             the CDATA state, and the escape flag is false, and there are at
181 181
             least three characters before this one in the input stream, and the
182 182
             last four characters in the input stream, including this one, are
183 183
             U+003C LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
184 184
             and U+002D HYPHEN-MINUS ("<!--"), then set the escape flag to true. */
185
-            if(($this->content_model === self::RCDATA || $this->content_model ===
186
-            self::CDATA) && $this->escape === false &&
187
-            $this->char >= 3 && $this->character($this->char - 4, 4) === '<!--') {
188
-                $this->escape = true;
189
-            }
185
+			if(($this->content_model === self::RCDATA || $this->content_model ===
186
+			self::CDATA) && $this->escape === false &&
187
+			$this->char >= 3 && $this->character($this->char - 4, 4) === '<!--') {
188
+				$this->escape = true;
189
+			}
190 190
 
191
-            /* In any case, emit the input character as a character token. Stay
191
+			/* In any case, emit the input character as a character token. Stay
192 192
             in the data state. */
193
-            $this->emitToken(array(
194
-                'type' => self::CHARACTR,
195
-                'data' => $char
196
-            ));
197
-
198
-        /* U+003C LESS-THAN SIGN (<) */
199
-        } elseif($char === '<' && ($this->content_model === self::PCDATA ||
200
-        (($this->content_model === self::RCDATA ||
201
-        $this->content_model === self::CDATA) && $this->escape === false))) {
202
-            /* When the content model flag is set to the PCDATA state: switch
193
+			$this->emitToken(array(
194
+				'type' => self::CHARACTR,
195
+				'data' => $char
196
+			));
197
+
198
+		/* U+003C LESS-THAN SIGN (<) */
199
+		} elseif($char === '<' && ($this->content_model === self::PCDATA ||
200
+		(($this->content_model === self::RCDATA ||
201
+		$this->content_model === self::CDATA) && $this->escape === false))) {
202
+			/* When the content model flag is set to the PCDATA state: switch
203 203
             to the tag open state.
204 204
 
205 205
             When the content model flag is set to either the RCDATA state or
@@ -207,171 +207,171 @@  discard block
 block discarded – undo
207 207
             open state.
208 208
 
209 209
             Otherwise: treat it as per the "anything else" entry below. */
210
-            $this->state = 'tagOpen';
210
+			$this->state = 'tagOpen';
211 211
 
212
-        /* U+003E GREATER-THAN SIGN (>) */
213
-        } elseif($char === '>') {
214
-            /* If the content model flag is set to either the RCDATA state or
212
+		/* U+003E GREATER-THAN SIGN (>) */
213
+		} elseif($char === '>') {
214
+			/* If the content model flag is set to either the RCDATA state or
215 215
             the CDATA state, and the escape flag is true, and the last three
216 216
             characters in the input stream including this one are U+002D
217 217
             HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("-->"),
218 218
             set the escape flag to false. */
219
-            if(($this->content_model === self::RCDATA ||
220
-            $this->content_model === self::CDATA) && $this->escape === true &&
221
-            $this->character($this->char, 3) === '-->') {
222
-                $this->escape = false;
223
-            }
219
+			if(($this->content_model === self::RCDATA ||
220
+			$this->content_model === self::CDATA) && $this->escape === true &&
221
+			$this->character($this->char, 3) === '-->') {
222
+				$this->escape = false;
223
+			}
224 224
 
225
-            /* In any case, emit the input character as a character token.
225
+			/* In any case, emit the input character as a character token.
226 226
             Stay in the data state. */
227
-            $this->emitToken(array(
228
-                'type' => self::CHARACTR,
229
-                'data' => $char
230
-            ));
227
+			$this->emitToken(array(
228
+				'type' => self::CHARACTR,
229
+				'data' => $char
230
+			));
231 231
 
232
-        } elseif($this->char === $this->EOF) {
233
-            /* EOF
232
+		} elseif($this->char === $this->EOF) {
233
+			/* EOF
234 234
             Emit an end-of-file token. */
235
-            $this->EOF();
235
+			$this->EOF();
236 236
 
237
-        } elseif($this->content_model === self::PLAINTEXT) {
238
-            /* When the content model flag is set to the PLAINTEXT state
237
+		} elseif($this->content_model === self::PLAINTEXT) {
238
+			/* When the content model flag is set to the PLAINTEXT state
239 239
             THIS DIFFERS GREATLY FROM THE SPEC: Get the remaining characters of
240 240
             the text and emit it as a character token. */
241
-            $this->emitToken(array(
242
-                'type' => self::CHARACTR,
243
-                'data' => substr($this->data, $this->char)
244
-            ));
241
+			$this->emitToken(array(
242
+				'type' => self::CHARACTR,
243
+				'data' => substr($this->data, $this->char)
244
+			));
245 245
 
246
-            $this->EOF();
246
+			$this->EOF();
247 247
 
248
-        } else {
249
-            /* Anything else
248
+		} else {
249
+			/* Anything else
250 250
             THIS DIFFERS GREATLY FROM THE SPEC: Get as many character that
251 251
             otherwise would also be treated as a character token and emit it
252 252
             as a single character token. Stay in the data state. */
253
-            $len  = strcspn($this->data, '<&', $this->char);
254
-            $char = substr($this->data, $this->char, $len);
255
-            $this->char += $len - 1;
256
-
257
-            $this->emitToken(array(
258
-                'type' => self::CHARACTR,
259
-                'data' => $char
260
-            ));
261
-
262
-            $this->state = 'data';
263
-        }
264
-    }
265
-
266
-    private function entityDataState() {
267
-        // Attempt to consume an entity.
268
-        $entity = $this->entity();
269
-
270
-        // If nothing is returned, emit a U+0026 AMPERSAND character token.
271
-        // Otherwise, emit the character token that was returned.
272
-        $char = (!$entity) ? '&' : $entity;
273
-        $this->emitToken(array(
274
-            'type' => self::CHARACTR,
275
-            'data' => $char
276
-        ));
277
-
278
-        // Finally, switch to the data state.
279
-        $this->state = 'data';
280
-    }
281
-
282
-    private function tagOpenState() {
283
-        switch($this->content_model) {
284
-            case self::RCDATA:
285
-            case self::CDATA:
286
-                /* If the next input character is a U+002F SOLIDUS (/) character,
253
+			$len  = strcspn($this->data, '<&', $this->char);
254
+			$char = substr($this->data, $this->char, $len);
255
+			$this->char += $len - 1;
256
+
257
+			$this->emitToken(array(
258
+				'type' => self::CHARACTR,
259
+				'data' => $char
260
+			));
261
+
262
+			$this->state = 'data';
263
+		}
264
+	}
265
+
266
+	private function entityDataState() {
267
+		// Attempt to consume an entity.
268
+		$entity = $this->entity();
269
+
270
+		// If nothing is returned, emit a U+0026 AMPERSAND character token.
271
+		// Otherwise, emit the character token that was returned.
272
+		$char = (!$entity) ? '&' : $entity;
273
+		$this->emitToken(array(
274
+			'type' => self::CHARACTR,
275
+			'data' => $char
276
+		));
277
+
278
+		// Finally, switch to the data state.
279
+		$this->state = 'data';
280
+	}
281
+
282
+	private function tagOpenState() {
283
+		switch($this->content_model) {
284
+			case self::RCDATA:
285
+			case self::CDATA:
286
+				/* If the next input character is a U+002F SOLIDUS (/) character,
287 287
                 consume it and switch to the close tag open state. If the next
288 288
                 input character is not a U+002F SOLIDUS (/) character, emit a
289 289
                 U+003C LESS-THAN SIGN character token and switch to the data
290 290
                 state to process the next input character. */
291
-                if($this->character($this->char + 1) === '/') {
292
-                    $this->char++;
293
-                    $this->state = 'closeTagOpen';
294
-
295
-                } else {
296
-                    $this->emitToken(array(
297
-                        'type' => self::CHARACTR,
298
-                        'data' => '<'
299
-                    ));
300
-
301
-                    $this->state = 'data';
302
-                }
303
-            break;
304
-
305
-            case self::PCDATA:
306
-                // If the content model flag is set to the PCDATA state
307
-                // Consume the next input character:
308
-                $this->char++;
309
-                $char = $this->char();
310
-
311
-                if($char === '!') {
312
-                    /* U+0021 EXCLAMATION MARK (!)
291
+				if($this->character($this->char + 1) === '/') {
292
+					$this->char++;
293
+					$this->state = 'closeTagOpen';
294
+
295
+				} else {
296
+					$this->emitToken(array(
297
+						'type' => self::CHARACTR,
298
+						'data' => '<'
299
+					));
300
+
301
+					$this->state = 'data';
302
+				}
303
+			break;
304
+
305
+			case self::PCDATA:
306
+				// If the content model flag is set to the PCDATA state
307
+				// Consume the next input character:
308
+				$this->char++;
309
+				$char = $this->char();
310
+
311
+				if($char === '!') {
312
+					/* U+0021 EXCLAMATION MARK (!)
313 313
                     Switch to the markup declaration open state. */
314
-                    $this->state = 'markupDeclarationOpen';
314
+					$this->state = 'markupDeclarationOpen';
315 315
 
316
-                } elseif($char === '/') {
317
-                    /* U+002F SOLIDUS (/)
316
+				} elseif($char === '/') {
317
+					/* U+002F SOLIDUS (/)
318 318
                     Switch to the close tag open state. */
319
-                    $this->state = 'closeTagOpen';
319
+					$this->state = 'closeTagOpen';
320 320
 
321
-                } elseif(preg_match('/^[A-Za-z]$/', $char)) {
322
-                    /* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
321
+				} elseif(preg_match('/^[A-Za-z]$/', $char)) {
322
+					/* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
323 323
                     Create a new start tag token, set its tag name to the lowercase
324 324
                     version of the input character (add 0x0020 to the character's code
325 325
                     point), then switch to the tag name state. (Don't emit the token
326 326
                     yet; further details will be filled in before it is emitted.) */
327
-                    $this->token = array(
328
-                        'name'  => strtolower($char),
329
-                        'type'  => self::STARTTAG,
330
-                        'attr'  => array()
331
-                    );
327
+					$this->token = array(
328
+						'name'  => strtolower($char),
329
+						'type'  => self::STARTTAG,
330
+						'attr'  => array()
331
+					);
332 332
 
333
-                    $this->state = 'tagName';
333
+					$this->state = 'tagName';
334 334
 
335
-                } elseif($char === '>') {
336
-                    /* U+003E GREATER-THAN SIGN (>)
335
+				} elseif($char === '>') {
336
+					/* U+003E GREATER-THAN SIGN (>)
337 337
                     Parse error. Emit a U+003C LESS-THAN SIGN character token and a
338 338
                     U+003E GREATER-THAN SIGN character token. Switch to the data state. */
339
-                    $this->emitToken(array(
340
-                        'type' => self::CHARACTR,
341
-                        'data' => '<>'
342
-                    ));
339
+					$this->emitToken(array(
340
+						'type' => self::CHARACTR,
341
+						'data' => '<>'
342
+					));
343 343
 
344
-                    $this->state = 'data';
344
+					$this->state = 'data';
345 345
 
346
-                } elseif($char === '?') {
347
-                    /* U+003F QUESTION MARK (?)
346
+				} elseif($char === '?') {
347
+					/* U+003F QUESTION MARK (?)
348 348
                     Parse error. Switch to the bogus comment state. */
349
-                    $this->state = 'bogusComment';
349
+					$this->state = 'bogusComment';
350 350
 
351
-                } else {
352
-                    /* Anything else
351
+				} else {
352
+					/* Anything else
353 353
                     Parse error. Emit a U+003C LESS-THAN SIGN character token and
354 354
                     reconsume the current input character in the data state. */
355
-                    $this->emitToken(array(
356
-                        'type' => self::CHARACTR,
357
-                        'data' => '<'
358
-                    ));
359
-
360
-                    $this->char--;
361
-                    $this->state = 'data';
362
-                }
363
-            break;
364
-        }
365
-    }
366
-
367
-    private function closeTagOpenState() {
368
-        $next_node = strtolower($this->characters('A-Za-z', $this->char + 1));
369
-        $the_same = count($this->tree->stack) > 0 && $next_node === end($this->tree->stack)->nodeName;
370
-
371
-        if(($this->content_model === self::RCDATA || $this->content_model === self::CDATA) &&
372
-        (!$the_same || ($the_same && (!preg_match('/[\t\n\x0b\x0c >\/]/',
373
-        $this->character($this->char + 1 + strlen($next_node))) || $this->EOF === $this->char)))) {
374
-            /* If the content model flag is set to the RCDATA or CDATA states then
355
+					$this->emitToken(array(
356
+						'type' => self::CHARACTR,
357
+						'data' => '<'
358
+					));
359
+
360
+					$this->char--;
361
+					$this->state = 'data';
362
+				}
363
+			break;
364
+		}
365
+	}
366
+
367
+	private function closeTagOpenState() {
368
+		$next_node = strtolower($this->characters('A-Za-z', $this->char + 1));
369
+		$the_same = count($this->tree->stack) > 0 && $next_node === end($this->tree->stack)->nodeName;
370
+
371
+		if(($this->content_model === self::RCDATA || $this->content_model === self::CDATA) &&
372
+		(!$the_same || ($the_same && (!preg_match('/[\t\n\x0b\x0c >\/]/',
373
+		$this->character($this->char + 1 + strlen($next_node))) || $this->EOF === $this->char)))) {
374
+			/* If the content model flag is set to the RCDATA or CDATA states then
375 375
             examine the next few characters. If they do not match the tag name of
376 376
             the last start tag token emitted (case insensitively), or if they do but
377 377
             they are not immediately followed by one of the following characters:
@@ -386,426 +386,426 @@  discard block
 block discarded – undo
386 386
             ...then there is a parse error. Emit a U+003C LESS-THAN SIGN character
387 387
             token, a U+002F SOLIDUS character token, and switch to the data state
388 388
             to process the next input character. */
389
-            $this->emitToken(array(
390
-                'type' => self::CHARACTR,
391
-                'data' => '</'
392
-            ));
389
+			$this->emitToken(array(
390
+				'type' => self::CHARACTR,
391
+				'data' => '</'
392
+			));
393 393
 
394
-            $this->state = 'data';
394
+			$this->state = 'data';
395 395
 
396
-        } else {
397
-            /* Otherwise, if the content model flag is set to the PCDATA state,
396
+		} else {
397
+			/* Otherwise, if the content model flag is set to the PCDATA state,
398 398
             or if the next few characters do match that tag name, consume the
399 399
             next input character: */
400
-            $this->char++;
401
-            $char = $this->char();
400
+			$this->char++;
401
+			$char = $this->char();
402 402
 
403
-            if(preg_match('/^[A-Za-z]$/', $char)) {
404
-                /* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
403
+			if(preg_match('/^[A-Za-z]$/', $char)) {
404
+				/* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
405 405
                 Create a new end tag token, set its tag name to the lowercase version
406 406
                 of the input character (add 0x0020 to the character's code point), then
407 407
                 switch to the tag name state. (Don't emit the token yet; further details
408 408
                 will be filled in before it is emitted.) */
409
-                $this->token = array(
410
-                    'name'  => strtolower($char),
411
-                    'type'  => self::ENDTAG
412
-                );
409
+				$this->token = array(
410
+					'name'  => strtolower($char),
411
+					'type'  => self::ENDTAG
412
+				);
413 413
 
414
-                $this->state = 'tagName';
414
+				$this->state = 'tagName';
415 415
 
416
-            } elseif($char === '>') {
417
-                /* U+003E GREATER-THAN SIGN (>)
416
+			} elseif($char === '>') {
417
+				/* U+003E GREATER-THAN SIGN (>)
418 418
                 Parse error. Switch to the data state. */
419
-                $this->state = 'data';
419
+				$this->state = 'data';
420 420
 
421
-            } elseif($this->char === $this->EOF) {
422
-                /* EOF
421
+			} elseif($this->char === $this->EOF) {
422
+				/* EOF
423 423
                 Parse error. Emit a U+003C LESS-THAN SIGN character token and a U+002F
424 424
                 SOLIDUS character token. Reconsume the EOF character in the data state. */
425
-                $this->emitToken(array(
426
-                    'type' => self::CHARACTR,
427
-                    'data' => '</'
428
-                ));
429
-
430
-                $this->char--;
431
-                $this->state = 'data';
432
-
433
-            } else {
434
-                /* Parse error. Switch to the bogus comment state. */
435
-                $this->state = 'bogusComment';
436
-            }
437
-        }
438
-    }
439
-
440
-    private function tagNameState() {
441
-        // Consume the next input character:
442
-        $this->char++;
443
-        $char = $this->character($this->char);
444
-
445
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
446
-            /* U+0009 CHARACTER TABULATION
425
+				$this->emitToken(array(
426
+					'type' => self::CHARACTR,
427
+					'data' => '</'
428
+				));
429
+
430
+				$this->char--;
431
+				$this->state = 'data';
432
+
433
+			} else {
434
+				/* Parse error. Switch to the bogus comment state. */
435
+				$this->state = 'bogusComment';
436
+			}
437
+		}
438
+	}
439
+
440
+	private function tagNameState() {
441
+		// Consume the next input character:
442
+		$this->char++;
443
+		$char = $this->character($this->char);
444
+
445
+		if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
446
+			/* U+0009 CHARACTER TABULATION
447 447
             U+000A LINE FEED (LF)
448 448
             U+000B LINE TABULATION
449 449
             U+000C FORM FEED (FF)
450 450
             U+0020 SPACE
451 451
             Switch to the before attribute name state. */
452
-            $this->state = 'beforeAttributeName';
452
+			$this->state = 'beforeAttributeName';
453 453
 
454
-        } elseif($char === '>') {
455
-            /* U+003E GREATER-THAN SIGN (>)
454
+		} elseif($char === '>') {
455
+			/* U+003E GREATER-THAN SIGN (>)
456 456
             Emit the current tag token. Switch to the data state. */
457
-            $this->emitToken($this->token);
458
-            $this->state = 'data';
457
+			$this->emitToken($this->token);
458
+			$this->state = 'data';
459 459
 
460
-        } elseif($this->char === $this->EOF) {
461
-            /* EOF
460
+		} elseif($this->char === $this->EOF) {
461
+			/* EOF
462 462
             Parse error. Emit the current tag token. Reconsume the EOF
463 463
             character in the data state. */
464
-            $this->emitToken($this->token);
464
+			$this->emitToken($this->token);
465 465
 
466
-            $this->char--;
467
-            $this->state = 'data';
466
+			$this->char--;
467
+			$this->state = 'data';
468 468
 
469
-        } elseif($char === '/') {
470
-            /* U+002F SOLIDUS (/)
469
+		} elseif($char === '/') {
470
+			/* U+002F SOLIDUS (/)
471 471
             Parse error unless this is a permitted slash. Switch to the before
472 472
             attribute name state. */
473
-            $this->state = 'beforeAttributeName';
473
+			$this->state = 'beforeAttributeName';
474 474
 
475
-        } else {
476
-            /* Anything else
475
+		} else {
476
+			/* Anything else
477 477
             Append the current input character to the current tag token's tag name.
478 478
             Stay in the tag name state. */
479
-            $this->token['name'] .= strtolower($char);
480
-            $this->state = 'tagName';
481
-        }
482
-    }
483
-
484
-    private function beforeAttributeNameState() {
485
-        // Consume the next input character:
486
-        $this->char++;
487
-        $char = $this->character($this->char);
488
-
489
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
490
-            /* U+0009 CHARACTER TABULATION
479
+			$this->token['name'] .= strtolower($char);
480
+			$this->state = 'tagName';
481
+		}
482
+	}
483
+
484
+	private function beforeAttributeNameState() {
485
+		// Consume the next input character:
486
+		$this->char++;
487
+		$char = $this->character($this->char);
488
+
489
+		if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
490
+			/* U+0009 CHARACTER TABULATION
491 491
             U+000A LINE FEED (LF)
492 492
             U+000B LINE TABULATION
493 493
             U+000C FORM FEED (FF)
494 494
             U+0020 SPACE
495 495
             Stay in the before attribute name state. */
496
-            $this->state = 'beforeAttributeName';
496
+			$this->state = 'beforeAttributeName';
497 497
 
498
-        } elseif($char === '>') {
499
-            /* U+003E GREATER-THAN SIGN (>)
498
+		} elseif($char === '>') {
499
+			/* U+003E GREATER-THAN SIGN (>)
500 500
             Emit the current tag token. Switch to the data state. */
501
-            $this->emitToken($this->token);
502
-            $this->state = 'data';
501
+			$this->emitToken($this->token);
502
+			$this->state = 'data';
503 503
 
504
-        } elseif($char === '/') {
505
-            /* U+002F SOLIDUS (/)
504
+		} elseif($char === '/') {
505
+			/* U+002F SOLIDUS (/)
506 506
             Parse error unless this is a permitted slash. Stay in the before
507 507
             attribute name state. */
508
-            $this->state = 'beforeAttributeName';
508
+			$this->state = 'beforeAttributeName';
509 509
 
510
-        } elseif($this->char === $this->EOF) {
511
-            /* EOF
510
+		} elseif($this->char === $this->EOF) {
511
+			/* EOF
512 512
             Parse error. Emit the current tag token. Reconsume the EOF
513 513
             character in the data state. */
514
-            $this->emitToken($this->token);
514
+			$this->emitToken($this->token);
515 515
 
516
-            $this->char--;
517
-            $this->state = 'data';
516
+			$this->char--;
517
+			$this->state = 'data';
518 518
 
519
-        } else {
520
-            /* Anything else
519
+		} else {
520
+			/* Anything else
521 521
             Start a new attribute in the current tag token. Set that attribute's
522 522
             name to the current input character, and its value to the empty string.
523 523
             Switch to the attribute name state. */
524
-            $this->token['attr'][] = array(
525
-                'name'  => strtolower($char),
526
-                'value' => null
527
-            );
528
-
529
-            $this->state = 'attributeName';
530
-        }
531
-    }
532
-
533
-    private function attributeNameState() {
534
-        // Consume the next input character:
535
-        $this->char++;
536
-        $char = $this->character($this->char);
537
-
538
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
539
-            /* U+0009 CHARACTER TABULATION
524
+			$this->token['attr'][] = array(
525
+				'name'  => strtolower($char),
526
+				'value' => null
527
+			);
528
+
529
+			$this->state = 'attributeName';
530
+		}
531
+	}
532
+
533
+	private function attributeNameState() {
534
+		// Consume the next input character:
535
+		$this->char++;
536
+		$char = $this->character($this->char);
537
+
538
+		if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
539
+			/* U+0009 CHARACTER TABULATION
540 540
             U+000A LINE FEED (LF)
541 541
             U+000B LINE TABULATION
542 542
             U+000C FORM FEED (FF)
543 543
             U+0020 SPACE
544 544
             Stay in the before attribute name state. */
545
-            $this->state = 'afterAttributeName';
545
+			$this->state = 'afterAttributeName';
546 546
 
547
-        } elseif($char === '=') {
548
-            /* U+003D EQUALS SIGN (=)
547
+		} elseif($char === '=') {
548
+			/* U+003D EQUALS SIGN (=)
549 549
             Switch to the before attribute value state. */
550
-            $this->state = 'beforeAttributeValue';
550
+			$this->state = 'beforeAttributeValue';
551 551
 
552
-        } elseif($char === '>') {
553
-            /* U+003E GREATER-THAN SIGN (>)
552
+		} elseif($char === '>') {
553
+			/* U+003E GREATER-THAN SIGN (>)
554 554
             Emit the current tag token. Switch to the data state. */
555
-            $this->emitToken($this->token);
556
-            $this->state = 'data';
555
+			$this->emitToken($this->token);
556
+			$this->state = 'data';
557 557
 
558
-        } elseif($char === '/' && $this->character($this->char + 1) !== '>') {
559
-            /* U+002F SOLIDUS (/)
558
+		} elseif($char === '/' && $this->character($this->char + 1) !== '>') {
559
+			/* U+002F SOLIDUS (/)
560 560
             Parse error unless this is a permitted slash. Switch to the before
561 561
             attribute name state. */
562
-            $this->state = 'beforeAttributeName';
562
+			$this->state = 'beforeAttributeName';
563 563
 
564
-        } elseif($this->char === $this->EOF) {
565
-            /* EOF
564
+		} elseif($this->char === $this->EOF) {
565
+			/* EOF
566 566
             Parse error. Emit the current tag token. Reconsume the EOF
567 567
             character in the data state. */
568
-            $this->emitToken($this->token);
568
+			$this->emitToken($this->token);
569 569
 
570
-            $this->char--;
571
-            $this->state = 'data';
570
+			$this->char--;
571
+			$this->state = 'data';
572 572
 
573
-        } else {
574
-            /* Anything else
573
+		} else {
574
+			/* Anything else
575 575
             Append the current input character to the current attribute's name.
576 576
             Stay in the attribute name state. */
577
-            $last = count($this->token['attr']) - 1;
578
-            $this->token['attr'][$last]['name'] .= strtolower($char);
577
+			$last = count($this->token['attr']) - 1;
578
+			$this->token['attr'][$last]['name'] .= strtolower($char);
579 579
 
580
-            $this->state = 'attributeName';
581
-        }
582
-    }
580
+			$this->state = 'attributeName';
581
+		}
582
+	}
583 583
 
584
-    private function afterAttributeNameState() {
585
-        // Consume the next input character:
586
-        $this->char++;
587
-        $char = $this->character($this->char);
584
+	private function afterAttributeNameState() {
585
+		// Consume the next input character:
586
+		$this->char++;
587
+		$char = $this->character($this->char);
588 588
 
589
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
590
-            /* U+0009 CHARACTER TABULATION
589
+		if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
590
+			/* U+0009 CHARACTER TABULATION
591 591
             U+000A LINE FEED (LF)
592 592
             U+000B LINE TABULATION
593 593
             U+000C FORM FEED (FF)
594 594
             U+0020 SPACE
595 595
             Stay in the after attribute name state. */
596
-            $this->state = 'afterAttributeName';
596
+			$this->state = 'afterAttributeName';
597 597
 
598
-        } elseif($char === '=') {
599
-            /* U+003D EQUALS SIGN (=)
598
+		} elseif($char === '=') {
599
+			/* U+003D EQUALS SIGN (=)
600 600
             Switch to the before attribute value state. */
601
-            $this->state = 'beforeAttributeValue';
601
+			$this->state = 'beforeAttributeValue';
602 602
 
603
-        } elseif($char === '>') {
604
-            /* U+003E GREATER-THAN SIGN (>)
603
+		} elseif($char === '>') {
604
+			/* U+003E GREATER-THAN SIGN (>)
605 605
             Emit the current tag token. Switch to the data state. */
606
-            $this->emitToken($this->token);
607
-            $this->state = 'data';
606
+			$this->emitToken($this->token);
607
+			$this->state = 'data';
608 608
 
609
-        } elseif($char === '/' && $this->character($this->char + 1) !== '>') {
610
-            /* U+002F SOLIDUS (/)
609
+		} elseif($char === '/' && $this->character($this->char + 1) !== '>') {
610
+			/* U+002F SOLIDUS (/)
611 611
             Parse error unless this is a permitted slash. Switch to the
612 612
             before attribute name state. */
613
-            $this->state = 'beforeAttributeName';
613
+			$this->state = 'beforeAttributeName';
614 614
 
615
-        } elseif($this->char === $this->EOF) {
616
-            /* EOF
615
+		} elseif($this->char === $this->EOF) {
616
+			/* EOF
617 617
             Parse error. Emit the current tag token. Reconsume the EOF
618 618
             character in the data state. */
619
-            $this->emitToken($this->token);
619
+			$this->emitToken($this->token);
620 620
 
621
-            $this->char--;
622
-            $this->state = 'data';
621
+			$this->char--;
622
+			$this->state = 'data';
623 623
 
624
-        } else {
625
-            /* Anything else
624
+		} else {
625
+			/* Anything else
626 626
             Start a new attribute in the current tag token. Set that attribute's
627 627
             name to the current input character, and its value to the empty string.
628 628
             Switch to the attribute name state. */
629
-            $this->token['attr'][] = array(
630
-                'name'  => strtolower($char),
631
-                'value' => null
632
-            );
633
-
634
-            $this->state = 'attributeName';
635
-        }
636
-    }
637
-
638
-    private function beforeAttributeValueState() {
639
-        // Consume the next input character:
640
-        $this->char++;
641
-        $char = $this->character($this->char);
642
-
643
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
644
-            /* U+0009 CHARACTER TABULATION
629
+			$this->token['attr'][] = array(
630
+				'name'  => strtolower($char),
631
+				'value' => null
632
+			);
633
+
634
+			$this->state = 'attributeName';
635
+		}
636
+	}
637
+
638
+	private function beforeAttributeValueState() {
639
+		// Consume the next input character:
640
+		$this->char++;
641
+		$char = $this->character($this->char);
642
+
643
+		if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
644
+			/* U+0009 CHARACTER TABULATION
645 645
             U+000A LINE FEED (LF)
646 646
             U+000B LINE TABULATION
647 647
             U+000C FORM FEED (FF)
648 648
             U+0020 SPACE
649 649
             Stay in the before attribute value state. */
650
-            $this->state = 'beforeAttributeValue';
650
+			$this->state = 'beforeAttributeValue';
651 651
 
652
-        } elseif($char === '"') {
653
-            /* U+0022 QUOTATION MARK (")
652
+		} elseif($char === '"') {
653
+			/* U+0022 QUOTATION MARK (")
654 654
             Switch to the attribute value (double-quoted) state. */
655
-            $this->state = 'attributeValueDoubleQuoted';
655
+			$this->state = 'attributeValueDoubleQuoted';
656 656
 
657
-        } elseif($char === '&') {
658
-            /* U+0026 AMPERSAND (&)
657
+		} elseif($char === '&') {
658
+			/* U+0026 AMPERSAND (&)
659 659
             Switch to the attribute value (unquoted) state and reconsume
660 660
             this input character. */
661
-            $this->char--;
662
-            $this->state = 'attributeValueUnquoted';
661
+			$this->char--;
662
+			$this->state = 'attributeValueUnquoted';
663 663
 
664
-        } elseif($char === '\'') {
665
-            /* U+0027 APOSTROPHE (')
664
+		} elseif($char === '\'') {
665
+			/* U+0027 APOSTROPHE (')
666 666
             Switch to the attribute value (single-quoted) state. */
667
-            $this->state = 'attributeValueSingleQuoted';
667
+			$this->state = 'attributeValueSingleQuoted';
668 668
 
669
-        } elseif($char === '>') {
670
-            /* U+003E GREATER-THAN SIGN (>)
669
+		} elseif($char === '>') {
670
+			/* U+003E GREATER-THAN SIGN (>)
671 671
             Emit the current tag token. Switch to the data state. */
672
-            $this->emitToken($this->token);
673
-            $this->state = 'data';
672
+			$this->emitToken($this->token);
673
+			$this->state = 'data';
674 674
 
675
-        } else {
676
-            /* Anything else
675
+		} else {
676
+			/* Anything else
677 677
             Append the current input character to the current attribute's value.
678 678
             Switch to the attribute value (unquoted) state. */
679
-            $last = count($this->token['attr']) - 1;
680
-            $this->token['attr'][$last]['value'] .= $char;
679
+			$last = count($this->token['attr']) - 1;
680
+			$this->token['attr'][$last]['value'] .= $char;
681 681
 
682
-            $this->state = 'attributeValueUnquoted';
683
-        }
684
-    }
682
+			$this->state = 'attributeValueUnquoted';
683
+		}
684
+	}
685 685
 
686
-    private function attributeValueDoubleQuotedState() {
687
-        // Consume the next input character:
688
-        $this->char++;
689
-        $char = $this->character($this->char);
686
+	private function attributeValueDoubleQuotedState() {
687
+		// Consume the next input character:
688
+		$this->char++;
689
+		$char = $this->character($this->char);
690 690
 
691
-        if($char === '"') {
692
-            /* U+0022 QUOTATION MARK (")
691
+		if($char === '"') {
692
+			/* U+0022 QUOTATION MARK (")
693 693
             Switch to the before attribute name state. */
694
-            $this->state = 'beforeAttributeName';
694
+			$this->state = 'beforeAttributeName';
695 695
 
696
-        } elseif($char === '&') {
697
-            /* U+0026 AMPERSAND (&)
696
+		} elseif($char === '&') {
697
+			/* U+0026 AMPERSAND (&)
698 698
             Switch to the entity in attribute value state. */
699
-            $this->entityInAttributeValueState('double');
699
+			$this->entityInAttributeValueState('double');
700 700
 
701
-        } elseif($this->char === $this->EOF) {
702
-            /* EOF
701
+		} elseif($this->char === $this->EOF) {
702
+			/* EOF
703 703
             Parse error. Emit the current tag token. Reconsume the character
704 704
             in the data state. */
705
-            $this->emitToken($this->token);
705
+			$this->emitToken($this->token);
706 706
 
707
-            $this->char--;
708
-            $this->state = 'data';
707
+			$this->char--;
708
+			$this->state = 'data';
709 709
 
710
-        } else {
711
-            /* Anything else
710
+		} else {
711
+			/* Anything else
712 712
             Append the current input character to the current attribute's value.
713 713
             Stay in the attribute value (double-quoted) state. */
714
-            $last = count($this->token['attr']) - 1;
715
-            $this->token['attr'][$last]['value'] .= $char;
714
+			$last = count($this->token['attr']) - 1;
715
+			$this->token['attr'][$last]['value'] .= $char;
716 716
 
717
-            $this->state = 'attributeValueDoubleQuoted';
718
-        }
719
-    }
717
+			$this->state = 'attributeValueDoubleQuoted';
718
+		}
719
+	}
720 720
 
721
-    private function attributeValueSingleQuotedState() {
722
-        // Consume the next input character:
723
-        $this->char++;
724
-        $char = $this->character($this->char);
721
+	private function attributeValueSingleQuotedState() {
722
+		// Consume the next input character:
723
+		$this->char++;
724
+		$char = $this->character($this->char);
725 725
 
726
-        if($char === '\'') {
727
-            /* U+0022 QUOTATION MARK (')
726
+		if($char === '\'') {
727
+			/* U+0022 QUOTATION MARK (')
728 728
             Switch to the before attribute name state. */
729
-            $this->state = 'beforeAttributeName';
729
+			$this->state = 'beforeAttributeName';
730 730
 
731
-        } elseif($char === '&') {
732
-            /* U+0026 AMPERSAND (&)
731
+		} elseif($char === '&') {
732
+			/* U+0026 AMPERSAND (&)
733 733
             Switch to the entity in attribute value state. */
734
-            $this->entityInAttributeValueState('single');
734
+			$this->entityInAttributeValueState('single');
735 735
 
736
-        } elseif($this->char === $this->EOF) {
737
-            /* EOF
736
+		} elseif($this->char === $this->EOF) {
737
+			/* EOF
738 738
             Parse error. Emit the current tag token. Reconsume the character
739 739
             in the data state. */
740
-            $this->emitToken($this->token);
740
+			$this->emitToken($this->token);
741 741
 
742
-            $this->char--;
743
-            $this->state = 'data';
742
+			$this->char--;
743
+			$this->state = 'data';
744 744
 
745
-        } else {
746
-            /* Anything else
745
+		} else {
746
+			/* Anything else
747 747
             Append the current input character to the current attribute's value.
748 748
             Stay in the attribute value (single-quoted) state. */
749
-            $last = count($this->token['attr']) - 1;
750
-            $this->token['attr'][$last]['value'] .= $char;
749
+			$last = count($this->token['attr']) - 1;
750
+			$this->token['attr'][$last]['value'] .= $char;
751 751
 
752
-            $this->state = 'attributeValueSingleQuoted';
753
-        }
754
-    }
752
+			$this->state = 'attributeValueSingleQuoted';
753
+		}
754
+	}
755 755
 
756
-    private function attributeValueUnquotedState() {
757
-        // Consume the next input character:
758
-        $this->char++;
759
-        $char = $this->character($this->char);
756
+	private function attributeValueUnquotedState() {
757
+		// Consume the next input character:
758
+		$this->char++;
759
+		$char = $this->character($this->char);
760 760
 
761
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
762
-            /* U+0009 CHARACTER TABULATION
761
+		if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
762
+			/* U+0009 CHARACTER TABULATION
763 763
             U+000A LINE FEED (LF)
764 764
             U+000B LINE TABULATION
765 765
             U+000C FORM FEED (FF)
766 766
             U+0020 SPACE
767 767
             Switch to the before attribute name state. */
768
-            $this->state = 'beforeAttributeName';
768
+			$this->state = 'beforeAttributeName';
769 769
 
770
-        } elseif($char === '&') {
771
-            /* U+0026 AMPERSAND (&)
770
+		} elseif($char === '&') {
771
+			/* U+0026 AMPERSAND (&)
772 772
             Switch to the entity in attribute value state. */
773
-            $this->entityInAttributeValueState();
773
+			$this->entityInAttributeValueState();
774 774
 
775
-        } elseif($char === '>') {
776
-            /* U+003E GREATER-THAN SIGN (>)
775
+		} elseif($char === '>') {
776
+			/* U+003E GREATER-THAN SIGN (>)
777 777
             Emit the current tag token. Switch to the data state. */
778
-            $this->emitToken($this->token);
779
-            $this->state = 'data';
778
+			$this->emitToken($this->token);
779
+			$this->state = 'data';
780 780
 
781
-        } else {
782
-            /* Anything else
781
+		} else {
782
+			/* Anything else
783 783
             Append the current input character to the current attribute's value.
784 784
             Stay in the attribute value (unquoted) state. */
785
-            $last = count($this->token['attr']) - 1;
786
-            $this->token['attr'][$last]['value'] .= $char;
787
-
788
-            $this->state = 'attributeValueUnquoted';
789
-        }
790
-    }
791
-
792
-    private function entityInAttributeValueState() {
793
-        // Attempt to consume an entity.
794
-        $entity = $this->entity();
795
-
796
-        // If nothing is returned, append a U+0026 AMPERSAND character to the
797
-        // current attribute's value. Otherwise, emit the character token that
798
-        // was returned.
799
-        $char = (!$entity)
800
-            ? '&'
801
-            : $entity;
802
-
803
-        $last = count($this->token['attr']) - 1;
804
-        $this->token['attr'][$last]['value'] .= $char;
805
-    }
806
-
807
-    private function bogusCommentState() {
808
-        /* Consume every character up to the first U+003E GREATER-THAN SIGN
785
+			$last = count($this->token['attr']) - 1;
786
+			$this->token['attr'][$last]['value'] .= $char;
787
+
788
+			$this->state = 'attributeValueUnquoted';
789
+		}
790
+	}
791
+
792
+	private function entityInAttributeValueState() {
793
+		// Attempt to consume an entity.
794
+		$entity = $this->entity();
795
+
796
+		// If nothing is returned, append a U+0026 AMPERSAND character to the
797
+		// current attribute's value. Otherwise, emit the character token that
798
+		// was returned.
799
+		$char = (!$entity)
800
+			? '&'
801
+			: $entity;
802
+
803
+		$last = count($this->token['attr']) - 1;
804
+		$this->token['attr'][$last]['value'] .= $char;
805
+	}
806
+
807
+	private function bogusCommentState() {
808
+		/* Consume every character up to the first U+003E GREATER-THAN SIGN
809 809
         character (>) or the end of the file (EOF), whichever comes first. Emit
810 810
         a comment token whose data is the concatenation of all the characters
811 811
         starting from and including the character that caused the state machine
@@ -813,446 +813,446 @@  discard block
 block discarded – undo
813 813
         consumed character before the U+003E character, if any, or up to the
814 814
         end of the file otherwise. (If the comment was started by the end of
815 815
         the file (EOF), the token is empty.) */
816
-        $data = $this->characters('^>', $this->char);
817
-        $this->emitToken(array(
818
-            'data' => $data,
819
-            'type' => self::COMMENT
820
-        ));
816
+		$data = $this->characters('^>', $this->char);
817
+		$this->emitToken(array(
818
+			'data' => $data,
819
+			'type' => self::COMMENT
820
+		));
821 821
 
822
-        $this->char += strlen($data);
822
+		$this->char += strlen($data);
823 823
 
824
-        /* Switch to the data state. */
825
-        $this->state = 'data';
824
+		/* Switch to the data state. */
825
+		$this->state = 'data';
826 826
 
827
-        /* If the end of the file was reached, reconsume the EOF character. */
828
-        if($this->char === $this->EOF) {
829
-            $this->char = $this->EOF - 1;
830
-        }
831
-    }
827
+		/* If the end of the file was reached, reconsume the EOF character. */
828
+		if($this->char === $this->EOF) {
829
+			$this->char = $this->EOF - 1;
830
+		}
831
+	}
832 832
 
833
-    private function markupDeclarationOpenState() {
834
-        /* If the next two characters are both U+002D HYPHEN-MINUS (-)
833
+	private function markupDeclarationOpenState() {
834
+		/* If the next two characters are both U+002D HYPHEN-MINUS (-)
835 835
         characters, consume those two characters, create a comment token whose
836 836
         data is the empty string, and switch to the comment state. */
837
-        if($this->character($this->char + 1, 2) === '--') {
838
-            $this->char += 2;
839
-            $this->state = 'comment';
840
-            $this->token = array(
841
-                'data' => null,
842
-                'type' => self::COMMENT
843
-            );
844
-
845
-        /* Otherwise if the next seven chacacters are a case-insensitive match
837
+		if($this->character($this->char + 1, 2) === '--') {
838
+			$this->char += 2;
839
+			$this->state = 'comment';
840
+			$this->token = array(
841
+				'data' => null,
842
+				'type' => self::COMMENT
843
+			);
844
+
845
+		/* Otherwise if the next seven chacacters are a case-insensitive match
846 846
         for the word "DOCTYPE", then consume those characters and switch to the
847 847
         DOCTYPE state. */
848
-        } elseif(strtolower($this->character($this->char + 1, 7)) === 'doctype') {
849
-            $this->char += 7;
850
-            $this->state = 'doctype';
848
+		} elseif(strtolower($this->character($this->char + 1, 7)) === 'doctype') {
849
+			$this->char += 7;
850
+			$this->state = 'doctype';
851 851
 
852
-        /* Otherwise, is is a parse error. Switch to the bogus comment state.
852
+		/* Otherwise, is is a parse error. Switch to the bogus comment state.
853 853
         The next character that is consumed, if any, is the first character
854 854
         that will be in the comment. */
855
-        } else {
856
-            $this->char++;
857
-            $this->state = 'bogusComment';
858
-        }
859
-    }
860
-
861
-    private function commentState() {
862
-        /* Consume the next input character: */
863
-        $this->char++;
864
-        $char = $this->char();
865
-
866
-        /* U+002D HYPHEN-MINUS (-) */
867
-        if($char === '-') {
868
-            /* Switch to the comment dash state  */
869
-            $this->state = 'commentDash';
870
-
871
-        /* EOF */
872
-        } elseif($this->char === $this->EOF) {
873
-            /* Parse error. Emit the comment token. Reconsume the EOF character
855
+		} else {
856
+			$this->char++;
857
+			$this->state = 'bogusComment';
858
+		}
859
+	}
860
+
861
+	private function commentState() {
862
+		/* Consume the next input character: */
863
+		$this->char++;
864
+		$char = $this->char();
865
+
866
+		/* U+002D HYPHEN-MINUS (-) */
867
+		if($char === '-') {
868
+			/* Switch to the comment dash state  */
869
+			$this->state = 'commentDash';
870
+
871
+		/* EOF */
872
+		} elseif($this->char === $this->EOF) {
873
+			/* Parse error. Emit the comment token. Reconsume the EOF character
874 874
             in the data state. */
875
-            $this->emitToken($this->token);
876
-            $this->char--;
877
-            $this->state = 'data';
875
+			$this->emitToken($this->token);
876
+			$this->char--;
877
+			$this->state = 'data';
878 878
 
879
-        /* Anything else */
880
-        } else {
881
-            /* Append the input character to the comment token's data. Stay in
879
+		/* Anything else */
880
+		} else {
881
+			/* Append the input character to the comment token's data. Stay in
882 882
             the comment state. */
883
-            $this->token['data'] .= $char;
884
-        }
885
-    }
886
-
887
-    private function commentDashState() {
888
-        /* Consume the next input character: */
889
-        $this->char++;
890
-        $char = $this->char();
891
-
892
-        /* U+002D HYPHEN-MINUS (-) */
893
-        if($char === '-') {
894
-            /* Switch to the comment end state  */
895
-            $this->state = 'commentEnd';
896
-
897
-        /* EOF */
898
-        } elseif($this->char === $this->EOF) {
899
-            /* Parse error. Emit the comment token. Reconsume the EOF character
883
+			$this->token['data'] .= $char;
884
+		}
885
+	}
886
+
887
+	private function commentDashState() {
888
+		/* Consume the next input character: */
889
+		$this->char++;
890
+		$char = $this->char();
891
+
892
+		/* U+002D HYPHEN-MINUS (-) */
893
+		if($char === '-') {
894
+			/* Switch to the comment end state  */
895
+			$this->state = 'commentEnd';
896
+
897
+		/* EOF */
898
+		} elseif($this->char === $this->EOF) {
899
+			/* Parse error. Emit the comment token. Reconsume the EOF character
900 900
             in the data state. */
901
-            $this->emitToken($this->token);
902
-            $this->char--;
903
-            $this->state = 'data';
901
+			$this->emitToken($this->token);
902
+			$this->char--;
903
+			$this->state = 'data';
904 904
 
905
-        /* Anything else */
906
-        } else {
907
-            /* Append a U+002D HYPHEN-MINUS (-) character and the input
905
+		/* Anything else */
906
+		} else {
907
+			/* Append a U+002D HYPHEN-MINUS (-) character and the input
908 908
             character to the comment token's data. Switch to the comment state. */
909
-            $this->token['data'] .= '-'.$char;
910
-            $this->state = 'comment';
911
-        }
912
-    }
913
-
914
-    private function commentEndState() {
915
-        /* Consume the next input character: */
916
-        $this->char++;
917
-        $char = $this->char();
918
-
919
-        if($char === '>') {
920
-            $this->emitToken($this->token);
921
-            $this->state = 'data';
922
-
923
-        } elseif($char === '-') {
924
-            $this->token['data'] .= '-';
925
-
926
-        } elseif($this->char === $this->EOF) {
927
-            $this->emitToken($this->token);
928
-            $this->char--;
929
-            $this->state = 'data';
930
-
931
-        } else {
932
-            $this->token['data'] .= '--'.$char;
933
-            $this->state = 'comment';
934
-        }
935
-    }
936
-
937
-    private function doctypeState() {
938
-        /* Consume the next input character: */
939
-        $this->char++;
940
-        $char = $this->char();
941
-
942
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
943
-            $this->state = 'beforeDoctypeName';
944
-
945
-        } else {
946
-            $this->char--;
947
-            $this->state = 'beforeDoctypeName';
948
-        }
949
-    }
950
-
951
-    private function beforeDoctypeNameState() {
952
-        /* Consume the next input character: */
953
-        $this->char++;
954
-        $char = $this->char();
955
-
956
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
957
-            // Stay in the before DOCTYPE name state.
958
-
959
-        } elseif(preg_match('/^[a-z]$/', $char)) {
960
-            $this->token = array(
961
-                'name' => strtoupper($char),
962
-                'type' => self::DOCTYPE,
963
-                'error' => true
964
-            );
965
-
966
-            $this->state = 'doctypeName';
967
-
968
-        } elseif($char === '>') {
969
-            $this->emitToken(array(
970
-                'name' => null,
971
-                'type' => self::DOCTYPE,
972
-                'error' => true
973
-            ));
974
-
975
-            $this->state = 'data';
976
-
977
-        } elseif($this->char === $this->EOF) {
978
-            $this->emitToken(array(
979
-                'name' => null,
980
-                'type' => self::DOCTYPE,
981
-                'error' => true
982
-            ));
983
-
984
-            $this->char--;
985
-            $this->state = 'data';
986
-
987
-        } else {
988
-            $this->token = array(
989
-                'name' => $char,
990
-                'type' => self::DOCTYPE,
991
-                'error' => true
992
-            );
993
-
994
-            $this->state = 'doctypeName';
995
-        }
996
-    }
997
-
998
-    private function doctypeNameState() {
999
-        /* Consume the next input character: */
1000
-        $this->char++;
1001
-        $char = $this->char();
1002
-
1003
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
1004
-            $this->state = 'AfterDoctypeName';
1005
-
1006
-        } elseif($char === '>') {
1007
-            $this->emitToken($this->token);
1008
-            $this->state = 'data';
1009
-
1010
-        } elseif(preg_match('/^[a-z]$/', $char)) {
1011
-            $this->token['name'] .= strtoupper($char);
1012
-
1013
-        } elseif($this->char === $this->EOF) {
1014
-            $this->emitToken($this->token);
1015
-            $this->char--;
1016
-            $this->state = 'data';
1017
-
1018
-        } else {
1019
-            $this->token['name'] .= $char;
1020
-        }
1021
-
1022
-        $this->token['error'] = ($this->token['name'] === 'HTML')
1023
-            ? false
1024
-            : true;
1025
-    }
1026
-
1027
-    private function afterDoctypeNameState() {
1028
-        /* Consume the next input character: */
1029
-        $this->char++;
1030
-        $char = $this->char();
1031
-
1032
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
1033
-            // Stay in the DOCTYPE name state.
1034
-
1035
-        } elseif($char === '>') {
1036
-            $this->emitToken($this->token);
1037
-            $this->state = 'data';
1038
-
1039
-        } elseif($this->char === $this->EOF) {
1040
-            $this->emitToken($this->token);
1041
-            $this->char--;
1042
-            $this->state = 'data';
1043
-
1044
-        } else {
1045
-            $this->token['error'] = true;
1046
-            $this->state = 'bogusDoctype';
1047
-        }
1048
-    }
1049
-
1050
-    private function bogusDoctypeState() {
1051
-        /* Consume the next input character: */
1052
-        $this->char++;
1053
-        $char = $this->char();
1054
-
1055
-        if($char === '>') {
1056
-            $this->emitToken($this->token);
1057
-            $this->state = 'data';
1058
-
1059
-        } elseif($this->char === $this->EOF) {
1060
-            $this->emitToken($this->token);
1061
-            $this->char--;
1062
-            $this->state = 'data';
1063
-
1064
-        } else {
1065
-            // Stay in the bogus DOCTYPE state.
1066
-        }
1067
-    }
1068
-
1069
-    private function entity() {
1070
-        $start = $this->char;
1071
-
1072
-        // This section defines how to consume an entity. This definition is
1073
-        // used when parsing entities in text and in attributes.
1074
-
1075
-        // The behaviour depends on the identity of the next character (the
1076
-        // one immediately after the U+0026 AMPERSAND character): 
1077
-
1078
-        switch($this->character($this->char + 1)) {
1079
-            // U+0023 NUMBER SIGN (#)
1080
-            case '#':
1081
-
1082
-                // The behaviour further depends on the character after the
1083
-                // U+0023 NUMBER SIGN:
1084
-                switch($this->character($this->char + 1)) {
1085
-                    // U+0078 LATIN SMALL LETTER X
1086
-                    // U+0058 LATIN CAPITAL LETTER X
1087
-                    case 'x':
1088
-                    case 'X':
1089
-                        // Follow the steps below, but using the range of
1090
-                        // characters U+0030 DIGIT ZERO through to U+0039 DIGIT
1091
-                        // NINE, U+0061 LATIN SMALL LETTER A through to U+0066
1092
-                        // LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL LETTER
1093
-                        // A, through to U+0046 LATIN CAPITAL LETTER F (in other
1094
-                        // words, 0-9, A-F, a-f).
1095
-                        $char = 1;
1096
-                        $char_class = '0-9A-Fa-f';
1097
-                    break;
1098
-
1099
-                    // Anything else
1100
-                    default:
1101
-                        // Follow the steps below, but using the range of
1102
-                        // characters U+0030 DIGIT ZERO through to U+0039 DIGIT
1103
-                        // NINE (i.e. just 0-9).
1104
-                        $char = 0;
1105
-                        $char_class = '0-9';
1106
-                    break;
1107
-                }
1108
-
1109
-                // Consume as many characters as match the range of characters
1110
-                // given above.
1111
-                $this->char++;
1112
-                $e_name = $this->characters($char_class, $this->char + $char + 1);
1113
-                $entity = $this->character($start, $this->char);
1114
-                $cond = strlen($e_name) > 0;
1115
-
1116
-                // The rest of the parsing happens bellow.
1117
-            break;
1118
-
1119
-            // Anything else
1120
-            default:
1121
-                // Consume the maximum number of characters possible, with the
1122
-                // consumed characters case-sensitively matching one of the
1123
-                // identifiers in the first column of the entities table.
1124
-                $e_name = $this->characters('0-9A-Za-z;', $this->char + 1);
1125
-                $len = strlen($e_name);
1126
-
1127
-                for($c = 1; $c <= $len; $c++) {
1128
-                    $id = substr($e_name, 0, $c);
1129
-                    $this->char++;
1130
-
1131
-                    if(in_array($id, $this->entities)) {
1132
-                        if ($e_name[$c-1] !== ';') {
1133
-                            if ($c < $len && $e_name[$c] == ';') {
1134
-                                $this->char++; // consume extra semicolon
1135
-                            }
1136
-                        }
1137
-                        $entity = $id;
1138
-                        break;
1139
-                    }
1140
-                }
1141
-
1142
-                $cond = isset($entity);
1143
-                // The rest of the parsing happens bellow.
1144
-            break;
1145
-        }
1146
-
1147
-        if(!$cond) {
1148
-            // If no match can be made, then this is a parse error. No
1149
-            // characters are consumed, and nothing is returned.
1150
-            $this->char = $start;
1151
-            return false;
1152
-        }
1153
-
1154
-        // Return a character token for the character corresponding to the
1155
-        // entity name (as given by the second column of the entities table).
1156
-        return html_entity_decode('&'.$entity.';', ENT_QUOTES, 'UTF-8');
1157
-    }
1158
-
1159
-    private function emitToken($token) {
1160
-        $emit = $this->tree->emitToken($token);
1161
-
1162
-        if(is_int($emit)) {
1163
-            $this->content_model = $emit;
1164
-
1165
-        } elseif($token['type'] === self::ENDTAG) {
1166
-            $this->content_model = self::PCDATA;
1167
-        }
1168
-    }
1169
-
1170
-    private function EOF() {
1171
-        $this->state = null;
1172
-        $this->tree->emitToken(array(
1173
-            'type' => self::EOF
1174
-        ));
1175
-    }
909
+			$this->token['data'] .= '-'.$char;
910
+			$this->state = 'comment';
911
+		}
912
+	}
913
+
914
+	private function commentEndState() {
915
+		/* Consume the next input character: */
916
+		$this->char++;
917
+		$char = $this->char();
918
+
919
+		if($char === '>') {
920
+			$this->emitToken($this->token);
921
+			$this->state = 'data';
922
+
923
+		} elseif($char === '-') {
924
+			$this->token['data'] .= '-';
925
+
926
+		} elseif($this->char === $this->EOF) {
927
+			$this->emitToken($this->token);
928
+			$this->char--;
929
+			$this->state = 'data';
930
+
931
+		} else {
932
+			$this->token['data'] .= '--'.$char;
933
+			$this->state = 'comment';
934
+		}
935
+	}
936
+
937
+	private function doctypeState() {
938
+		/* Consume the next input character: */
939
+		$this->char++;
940
+		$char = $this->char();
941
+
942
+		if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
943
+			$this->state = 'beforeDoctypeName';
944
+
945
+		} else {
946
+			$this->char--;
947
+			$this->state = 'beforeDoctypeName';
948
+		}
949
+	}
950
+
951
+	private function beforeDoctypeNameState() {
952
+		/* Consume the next input character: */
953
+		$this->char++;
954
+		$char = $this->char();
955
+
956
+		if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
957
+			// Stay in the before DOCTYPE name state.
958
+
959
+		} elseif(preg_match('/^[a-z]$/', $char)) {
960
+			$this->token = array(
961
+				'name' => strtoupper($char),
962
+				'type' => self::DOCTYPE,
963
+				'error' => true
964
+			);
965
+
966
+			$this->state = 'doctypeName';
967
+
968
+		} elseif($char === '>') {
969
+			$this->emitToken(array(
970
+				'name' => null,
971
+				'type' => self::DOCTYPE,
972
+				'error' => true
973
+			));
974
+
975
+			$this->state = 'data';
976
+
977
+		} elseif($this->char === $this->EOF) {
978
+			$this->emitToken(array(
979
+				'name' => null,
980
+				'type' => self::DOCTYPE,
981
+				'error' => true
982
+			));
983
+
984
+			$this->char--;
985
+			$this->state = 'data';
986
+
987
+		} else {
988
+			$this->token = array(
989
+				'name' => $char,
990
+				'type' => self::DOCTYPE,
991
+				'error' => true
992
+			);
993
+
994
+			$this->state = 'doctypeName';
995
+		}
996
+	}
997
+
998
+	private function doctypeNameState() {
999
+		/* Consume the next input character: */
1000
+		$this->char++;
1001
+		$char = $this->char();
1002
+
1003
+		if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
1004
+			$this->state = 'AfterDoctypeName';
1005
+
1006
+		} elseif($char === '>') {
1007
+			$this->emitToken($this->token);
1008
+			$this->state = 'data';
1009
+
1010
+		} elseif(preg_match('/^[a-z]$/', $char)) {
1011
+			$this->token['name'] .= strtoupper($char);
1012
+
1013
+		} elseif($this->char === $this->EOF) {
1014
+			$this->emitToken($this->token);
1015
+			$this->char--;
1016
+			$this->state = 'data';
1017
+
1018
+		} else {
1019
+			$this->token['name'] .= $char;
1020
+		}
1021
+
1022
+		$this->token['error'] = ($this->token['name'] === 'HTML')
1023
+			? false
1024
+			: true;
1025
+	}
1026
+
1027
+	private function afterDoctypeNameState() {
1028
+		/* Consume the next input character: */
1029
+		$this->char++;
1030
+		$char = $this->char();
1031
+
1032
+		if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
1033
+			// Stay in the DOCTYPE name state.
1034
+
1035
+		} elseif($char === '>') {
1036
+			$this->emitToken($this->token);
1037
+			$this->state = 'data';
1038
+
1039
+		} elseif($this->char === $this->EOF) {
1040
+			$this->emitToken($this->token);
1041
+			$this->char--;
1042
+			$this->state = 'data';
1043
+
1044
+		} else {
1045
+			$this->token['error'] = true;
1046
+			$this->state = 'bogusDoctype';
1047
+		}
1048
+	}
1049
+
1050
+	private function bogusDoctypeState() {
1051
+		/* Consume the next input character: */
1052
+		$this->char++;
1053
+		$char = $this->char();
1054
+
1055
+		if($char === '>') {
1056
+			$this->emitToken($this->token);
1057
+			$this->state = 'data';
1058
+
1059
+		} elseif($this->char === $this->EOF) {
1060
+			$this->emitToken($this->token);
1061
+			$this->char--;
1062
+			$this->state = 'data';
1063
+
1064
+		} else {
1065
+			// Stay in the bogus DOCTYPE state.
1066
+		}
1067
+	}
1068
+
1069
+	private function entity() {
1070
+		$start = $this->char;
1071
+
1072
+		// This section defines how to consume an entity. This definition is
1073
+		// used when parsing entities in text and in attributes.
1074
+
1075
+		// The behaviour depends on the identity of the next character (the
1076
+		// one immediately after the U+0026 AMPERSAND character): 
1077
+
1078
+		switch($this->character($this->char + 1)) {
1079
+			// U+0023 NUMBER SIGN (#)
1080
+			case '#':
1081
+
1082
+				// The behaviour further depends on the character after the
1083
+				// U+0023 NUMBER SIGN:
1084
+				switch($this->character($this->char + 1)) {
1085
+					// U+0078 LATIN SMALL LETTER X
1086
+					// U+0058 LATIN CAPITAL LETTER X
1087
+					case 'x':
1088
+					case 'X':
1089
+						// Follow the steps below, but using the range of
1090
+						// characters U+0030 DIGIT ZERO through to U+0039 DIGIT
1091
+						// NINE, U+0061 LATIN SMALL LETTER A through to U+0066
1092
+						// LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL LETTER
1093
+						// A, through to U+0046 LATIN CAPITAL LETTER F (in other
1094
+						// words, 0-9, A-F, a-f).
1095
+						$char = 1;
1096
+						$char_class = '0-9A-Fa-f';
1097
+					break;
1098
+
1099
+					// Anything else
1100
+					default:
1101
+						// Follow the steps below, but using the range of
1102
+						// characters U+0030 DIGIT ZERO through to U+0039 DIGIT
1103
+						// NINE (i.e. just 0-9).
1104
+						$char = 0;
1105
+						$char_class = '0-9';
1106
+					break;
1107
+				}
1108
+
1109
+				// Consume as many characters as match the range of characters
1110
+				// given above.
1111
+				$this->char++;
1112
+				$e_name = $this->characters($char_class, $this->char + $char + 1);
1113
+				$entity = $this->character($start, $this->char);
1114
+				$cond = strlen($e_name) > 0;
1115
+
1116
+				// The rest of the parsing happens bellow.
1117
+			break;
1118
+
1119
+			// Anything else
1120
+			default:
1121
+				// Consume the maximum number of characters possible, with the
1122
+				// consumed characters case-sensitively matching one of the
1123
+				// identifiers in the first column of the entities table.
1124
+				$e_name = $this->characters('0-9A-Za-z;', $this->char + 1);
1125
+				$len = strlen($e_name);
1126
+
1127
+				for($c = 1; $c <= $len; $c++) {
1128
+					$id = substr($e_name, 0, $c);
1129
+					$this->char++;
1130
+
1131
+					if(in_array($id, $this->entities)) {
1132
+						if ($e_name[$c-1] !== ';') {
1133
+							if ($c < $len && $e_name[$c] == ';') {
1134
+								$this->char++; // consume extra semicolon
1135
+							}
1136
+						}
1137
+						$entity = $id;
1138
+						break;
1139
+					}
1140
+				}
1141
+
1142
+				$cond = isset($entity);
1143
+				// The rest of the parsing happens bellow.
1144
+			break;
1145
+		}
1146
+
1147
+		if(!$cond) {
1148
+			// If no match can be made, then this is a parse error. No
1149
+			// characters are consumed, and nothing is returned.
1150
+			$this->char = $start;
1151
+			return false;
1152
+		}
1153
+
1154
+		// Return a character token for the character corresponding to the
1155
+		// entity name (as given by the second column of the entities table).
1156
+		return html_entity_decode('&'.$entity.';', ENT_QUOTES, 'UTF-8');
1157
+	}
1158
+
1159
+	private function emitToken($token) {
1160
+		$emit = $this->tree->emitToken($token);
1161
+
1162
+		if(is_int($emit)) {
1163
+			$this->content_model = $emit;
1164
+
1165
+		} elseif($token['type'] === self::ENDTAG) {
1166
+			$this->content_model = self::PCDATA;
1167
+		}
1168
+	}
1169
+
1170
+	private function EOF() {
1171
+		$this->state = null;
1172
+		$this->tree->emitToken(array(
1173
+			'type' => self::EOF
1174
+		));
1175
+	}
1176 1176
 }
1177 1177
 
1178 1178
 class HTML5TreeConstructer {
1179
-    public $stack = array();
1180
-
1181
-    private $phase;
1182
-    private $mode;
1183
-    private $dom;
1184
-    private $foster_parent = null;
1185
-    private $a_formatting  = array();
1186
-
1187
-    private $head_pointer = null;
1188
-    private $form_pointer = null;
1189
-
1190
-    private $scoping = array('button','caption','html','marquee','object','table','td','th');
1191
-    private $formatting = array('a','b','big','em','font','i','nobr','s','small','strike','strong','tt','u');
1192
-    private $special = array('address','area','base','basefont','bgsound',
1193
-    'blockquote','body','br','center','col','colgroup','dd','dir','div','dl',
1194
-    'dt','embed','fieldset','form','frame','frameset','h1','h2','h3','h4','h5',
1195
-    'h6','head','hr','iframe','image','img','input','isindex','li','link',
1196
-    'listing','menu','meta','noembed','noframes','noscript','ol','optgroup',
1197
-    'option','p','param','plaintext','pre','script','select','spacer','style',
1198
-    'tbody','textarea','tfoot','thead','title','tr','ul','wbr');
1199
-
1200
-    // The different phases.
1201
-    const INIT_PHASE = 0;
1202
-    const ROOT_PHASE = 1;
1203
-    const MAIN_PHASE = 2;
1204
-    const END_PHASE  = 3;
1205
-
1206
-    // The different insertion modes for the main phase.
1207
-    const BEFOR_HEAD = 0;
1208
-    const IN_HEAD    = 1;
1209
-    const AFTER_HEAD = 2;
1210
-    const IN_BODY    = 3;
1211
-    const IN_TABLE   = 4;
1212
-    const IN_CAPTION = 5;
1213
-    const IN_CGROUP  = 6;
1214
-    const IN_TBODY   = 7;
1215
-    const IN_ROW     = 8;
1216
-    const IN_CELL    = 9;
1217
-    const IN_SELECT  = 10;
1218
-    const AFTER_BODY = 11;
1219
-    const IN_FRAME   = 12;
1220
-    const AFTR_FRAME = 13;
1221
-
1222
-    // The different types of elements.
1223
-    const SPECIAL    = 0;
1224
-    const SCOPING    = 1;
1225
-    const FORMATTING = 2;
1226
-    const PHRASING   = 3;
1227
-
1228
-    const MARKER     = 0;
1229
-
1230
-    public function __construct() {
1231
-        $this->phase = self::INIT_PHASE;
1232
-        $this->mode = self::BEFOR_HEAD;
1233
-        $this->dom = new DOMDocument;
1234
-
1235
-        $this->dom->encoding = 'UTF-8';
1236
-        $this->dom->preserveWhiteSpace = true;
1237
-        $this->dom->substituteEntities = true;
1238
-        $this->dom->strictErrorChecking = false;
1239
-    }
1240
-
1241
-    // Process tag tokens
1242
-    public function emitToken($token) {
1243
-        switch($this->phase) {
1244
-            case self::INIT_PHASE: return $this->initPhase($token); break;
1245
-            case self::ROOT_PHASE: return $this->rootElementPhase($token); break;
1246
-            case self::MAIN_PHASE: return $this->mainPhase($token); break;
1247
-            case self::END_PHASE : return $this->trailingEndPhase($token); break;
1248
-        }
1249
-    }
1250
-
1251
-    private function initPhase($token) {
1252
-        /* Initially, the tree construction stage must handle each token
1179
+	public $stack = array();
1180
+
1181
+	private $phase;
1182
+	private $mode;
1183
+	private $dom;
1184
+	private $foster_parent = null;
1185
+	private $a_formatting  = array();
1186
+
1187
+	private $head_pointer = null;
1188
+	private $form_pointer = null;
1189
+
1190
+	private $scoping = array('button','caption','html','marquee','object','table','td','th');
1191
+	private $formatting = array('a','b','big','em','font','i','nobr','s','small','strike','strong','tt','u');
1192
+	private $special = array('address','area','base','basefont','bgsound',
1193
+	'blockquote','body','br','center','col','colgroup','dd','dir','div','dl',
1194
+	'dt','embed','fieldset','form','frame','frameset','h1','h2','h3','h4','h5',
1195
+	'h6','head','hr','iframe','image','img','input','isindex','li','link',
1196
+	'listing','menu','meta','noembed','noframes','noscript','ol','optgroup',
1197
+	'option','p','param','plaintext','pre','script','select','spacer','style',
1198
+	'tbody','textarea','tfoot','thead','title','tr','ul','wbr');
1199
+
1200
+	// The different phases.
1201
+	const INIT_PHASE = 0;
1202
+	const ROOT_PHASE = 1;
1203
+	const MAIN_PHASE = 2;
1204
+	const END_PHASE  = 3;
1205
+
1206
+	// The different insertion modes for the main phase.
1207
+	const BEFOR_HEAD = 0;
1208
+	const IN_HEAD    = 1;
1209
+	const AFTER_HEAD = 2;
1210
+	const IN_BODY    = 3;
1211
+	const IN_TABLE   = 4;
1212
+	const IN_CAPTION = 5;
1213
+	const IN_CGROUP  = 6;
1214
+	const IN_TBODY   = 7;
1215
+	const IN_ROW     = 8;
1216
+	const IN_CELL    = 9;
1217
+	const IN_SELECT  = 10;
1218
+	const AFTER_BODY = 11;
1219
+	const IN_FRAME   = 12;
1220
+	const AFTR_FRAME = 13;
1221
+
1222
+	// The different types of elements.
1223
+	const SPECIAL    = 0;
1224
+	const SCOPING    = 1;
1225
+	const FORMATTING = 2;
1226
+	const PHRASING   = 3;
1227
+
1228
+	const MARKER     = 0;
1229
+
1230
+	public function __construct() {
1231
+		$this->phase = self::INIT_PHASE;
1232
+		$this->mode = self::BEFOR_HEAD;
1233
+		$this->dom = new DOMDocument;
1234
+
1235
+		$this->dom->encoding = 'UTF-8';
1236
+		$this->dom->preserveWhiteSpace = true;
1237
+		$this->dom->substituteEntities = true;
1238
+		$this->dom->strictErrorChecking = false;
1239
+	}
1240
+
1241
+	// Process tag tokens
1242
+	public function emitToken($token) {
1243
+		switch($this->phase) {
1244
+			case self::INIT_PHASE: return $this->initPhase($token); break;
1245
+			case self::ROOT_PHASE: return $this->rootElementPhase($token); break;
1246
+			case self::MAIN_PHASE: return $this->mainPhase($token); break;
1247
+			case self::END_PHASE : return $this->trailingEndPhase($token); break;
1248
+		}
1249
+	}
1250
+
1251
+	private function initPhase($token) {
1252
+		/* Initially, the tree construction stage must handle each token
1253 1253
         emitted from the tokenisation stage as follows: */
1254 1254
 
1255
-        /* A DOCTYPE token that is marked as being in error
1255
+		/* A DOCTYPE token that is marked as being in error
1256 1256
         A comment token
1257 1257
         A start tag token
1258 1258
         An end tag token
@@ -1260,575 +1260,575 @@  discard block
 block discarded – undo
1260 1260
             U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
1261 1261
             or U+0020 SPACE
1262 1262
         An end-of-file token */
1263
-        if((isset($token['error']) && $token['error']) ||
1264
-        $token['type'] === HTML5::COMMENT ||
1265
-        $token['type'] === HTML5::STARTTAG ||
1266
-        $token['type'] === HTML5::ENDTAG ||
1267
-        $token['type'] === HTML5::EOF ||
1268
-        ($token['type'] === HTML5::CHARACTR && isset($token['data']) &&
1269
-        !preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']))) {
1270
-            /* This specification does not define how to handle this case. In
1263
+		if((isset($token['error']) && $token['error']) ||
1264
+		$token['type'] === HTML5::COMMENT ||
1265
+		$token['type'] === HTML5::STARTTAG ||
1266
+		$token['type'] === HTML5::ENDTAG ||
1267
+		$token['type'] === HTML5::EOF ||
1268
+		($token['type'] === HTML5::CHARACTR && isset($token['data']) &&
1269
+		!preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']))) {
1270
+			/* This specification does not define how to handle this case. In
1271 1271
             particular, user agents may ignore the entirety of this specification
1272 1272
             altogether for such documents, and instead invoke special parse modes
1273 1273
             with a greater emphasis on backwards compatibility. */
1274 1274
 
1275
-            $this->phase = self::ROOT_PHASE;
1276
-            return $this->rootElementPhase($token);
1275
+			$this->phase = self::ROOT_PHASE;
1276
+			return $this->rootElementPhase($token);
1277 1277
 
1278
-        /* A DOCTYPE token marked as being correct */
1279
-        } elseif(isset($token['error']) && !$token['error']) {
1280
-            /* Append a DocumentType node to the Document  node, with the name
1278
+		/* A DOCTYPE token marked as being correct */
1279
+		} elseif(isset($token['error']) && !$token['error']) {
1280
+			/* Append a DocumentType node to the Document  node, with the name
1281 1281
             attribute set to the name given in the DOCTYPE token (which will be
1282 1282
             "HTML"), and the other attributes specific to DocumentType objects
1283 1283
             set to null, empty lists, or the empty string as appropriate. */
1284
-            $doctype = new DOMDocumentType(null, null, 'HTML');
1284
+			$doctype = new DOMDocumentType(null, null, 'HTML');
1285 1285
 
1286
-            /* Then, switch to the root element phase of the tree construction
1286
+			/* Then, switch to the root element phase of the tree construction
1287 1287
             stage. */
1288
-            $this->phase = self::ROOT_PHASE;
1288
+			$this->phase = self::ROOT_PHASE;
1289 1289
 
1290
-        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
1290
+		/* A character token that is one of one of U+0009 CHARACTER TABULATION,
1291 1291
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
1292 1292
         or U+0020 SPACE */
1293
-        } elseif(isset($token['data']) && preg_match('/^[\t\n\x0b\x0c ]+$/',
1294
-        $token['data'])) {
1295
-            /* Append that character  to the Document node. */
1296
-            $text = $this->dom->createTextNode($token['data']);
1297
-            $this->dom->appendChild($text);
1298
-        }
1299
-    }
1300
-
1301
-    private function rootElementPhase($token) {
1302
-        /* After the initial phase, as each token is emitted from the tokenisation
1293
+		} elseif(isset($token['data']) && preg_match('/^[\t\n\x0b\x0c ]+$/',
1294
+		$token['data'])) {
1295
+			/* Append that character  to the Document node. */
1296
+			$text = $this->dom->createTextNode($token['data']);
1297
+			$this->dom->appendChild($text);
1298
+		}
1299
+	}
1300
+
1301
+	private function rootElementPhase($token) {
1302
+		/* After the initial phase, as each token is emitted from the tokenisation
1303 1303
         stage, it must be processed as described in this section. */
1304 1304
 
1305
-        /* A DOCTYPE token */
1306
-        if($token['type'] === HTML5::DOCTYPE) {
1307
-            // Parse error. Ignore the token.
1305
+		/* A DOCTYPE token */
1306
+		if($token['type'] === HTML5::DOCTYPE) {
1307
+			// Parse error. Ignore the token.
1308 1308
 
1309
-        /* A comment token */
1310
-        } elseif($token['type'] === HTML5::COMMENT) {
1311
-            /* Append a Comment node to the Document object with the data
1309
+		/* A comment token */
1310
+		} elseif($token['type'] === HTML5::COMMENT) {
1311
+			/* Append a Comment node to the Document object with the data
1312 1312
             attribute set to the data given in the comment token. */
1313
-            $comment = $this->dom->createComment($token['data']);
1314
-            $this->dom->appendChild($comment);
1313
+			$comment = $this->dom->createComment($token['data']);
1314
+			$this->dom->appendChild($comment);
1315 1315
 
1316
-        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
1316
+		/* A character token that is one of one of U+0009 CHARACTER TABULATION,
1317 1317
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
1318 1318
         or U+0020 SPACE */
1319
-        } elseif($token['type'] === HTML5::CHARACTR &&
1320
-        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
1321
-            /* Append that character  to the Document node. */
1322
-            $text = $this->dom->createTextNode($token['data']);
1323
-            $this->dom->appendChild($text);
1319
+		} elseif($token['type'] === HTML5::CHARACTR &&
1320
+		preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
1321
+			/* Append that character  to the Document node. */
1322
+			$text = $this->dom->createTextNode($token['data']);
1323
+			$this->dom->appendChild($text);
1324 1324
 
1325
-        /* A character token that is not one of U+0009 CHARACTER TABULATION,
1325
+		/* A character token that is not one of U+0009 CHARACTER TABULATION,
1326 1326
             U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED
1327 1327
             (FF), or U+0020 SPACE
1328 1328
         A start tag token
1329 1329
         An end tag token
1330 1330
         An end-of-file token */
1331
-        } elseif(($token['type'] === HTML5::CHARACTR &&
1332
-        !preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) ||
1333
-        $token['type'] === HTML5::STARTTAG ||
1334
-        $token['type'] === HTML5::ENDTAG ||
1335
-        $token['type'] === HTML5::EOF) {
1336
-            /* Create an HTMLElement node with the tag name html, in the HTML
1331
+		} elseif(($token['type'] === HTML5::CHARACTR &&
1332
+		!preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) ||
1333
+		$token['type'] === HTML5::STARTTAG ||
1334
+		$token['type'] === HTML5::ENDTAG ||
1335
+		$token['type'] === HTML5::EOF) {
1336
+			/* Create an HTMLElement node with the tag name html, in the HTML
1337 1337
             namespace. Append it to the Document object. Switch to the main
1338 1338
             phase and reprocess the current token. */
1339
-            $html = $this->dom->createElement('html');
1340
-            $this->dom->appendChild($html);
1341
-            $this->stack[] = $html;
1339
+			$html = $this->dom->createElement('html');
1340
+			$this->dom->appendChild($html);
1341
+			$this->stack[] = $html;
1342 1342
 
1343
-            $this->phase = self::MAIN_PHASE;
1344
-            return $this->mainPhase($token);
1345
-        }
1346
-    }
1343
+			$this->phase = self::MAIN_PHASE;
1344
+			return $this->mainPhase($token);
1345
+		}
1346
+	}
1347 1347
 
1348
-    private function mainPhase($token) {
1349
-        /* Tokens in the main phase must be handled as follows: */
1348
+	private function mainPhase($token) {
1349
+		/* Tokens in the main phase must be handled as follows: */
1350 1350
 
1351
-        /* A DOCTYPE token */
1352
-        if($token['type'] === HTML5::DOCTYPE) {
1353
-            // Parse error. Ignore the token.
1351
+		/* A DOCTYPE token */
1352
+		if($token['type'] === HTML5::DOCTYPE) {
1353
+			// Parse error. Ignore the token.
1354 1354
 
1355
-        /* A start tag token with the tag name "html" */
1356
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'html') {
1357
-            /* If this start tag token was not the first start tag token, then
1355
+		/* A start tag token with the tag name "html" */
1356
+		} elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'html') {
1357
+			/* If this start tag token was not the first start tag token, then
1358 1358
             it is a parse error. */
1359 1359
 
1360
-            /* For each attribute on the token, check to see if the attribute
1360
+			/* For each attribute on the token, check to see if the attribute
1361 1361
             is already present on the top element of the stack of open elements.
1362 1362
             If it is not, add the attribute and its corresponding value to that
1363 1363
             element. */
1364
-            foreach($token['attr'] as $attr) {
1365
-                if(!$this->stack[0]->hasAttribute($attr['name'])) {
1366
-                    $this->stack[0]->setAttribute($attr['name'], $attr['value']);
1367
-                }
1368
-            }
1369
-
1370
-        /* An end-of-file token */
1371
-        } elseif($token['type'] === HTML5::EOF) {
1372
-            /* Generate implied end tags. */
1373
-            $this->generateImpliedEndTags();
1374
-
1375
-        /* Anything else. */
1376
-        } else {
1377
-            /* Depends on the insertion mode: */
1378
-            switch($this->mode) {
1379
-                case self::BEFOR_HEAD: return $this->beforeHead($token); break;
1380
-                case self::IN_HEAD:    return $this->inHead($token); break;
1381
-                case self::AFTER_HEAD: return $this->afterHead($token); break;
1382
-                case self::IN_BODY:    return $this->inBody($token); break;
1383
-                case self::IN_TABLE:   return $this->inTable($token); break;
1384
-                case self::IN_CAPTION: return $this->inCaption($token); break;
1385
-                case self::IN_CGROUP:  return $this->inColumnGroup($token); break;
1386
-                case self::IN_TBODY:   return $this->inTableBody($token); break;
1387
-                case self::IN_ROW:     return $this->inRow($token); break;
1388
-                case self::IN_CELL:    return $this->inCell($token); break;
1389
-                case self::IN_SELECT:  return $this->inSelect($token); break;
1390
-                case self::AFTER_BODY: return $this->afterBody($token); break;
1391
-                case self::IN_FRAME:   return $this->inFrameset($token); break;
1392
-                case self::AFTR_FRAME: return $this->afterFrameset($token); break;
1393
-                case self::END_PHASE:  return $this->trailingEndPhase($token); break;
1394
-            }
1395
-        }
1396
-    }
1397
-
1398
-    private function beforeHead($token) {
1399
-        /* Handle the token as follows: */
1400
-
1401
-        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
1364
+			foreach($token['attr'] as $attr) {
1365
+				if(!$this->stack[0]->hasAttribute($attr['name'])) {
1366
+					$this->stack[0]->setAttribute($attr['name'], $attr['value']);
1367
+				}
1368
+			}
1369
+
1370
+		/* An end-of-file token */
1371
+		} elseif($token['type'] === HTML5::EOF) {
1372
+			/* Generate implied end tags. */
1373
+			$this->generateImpliedEndTags();
1374
+
1375
+		/* Anything else. */
1376
+		} else {
1377
+			/* Depends on the insertion mode: */
1378
+			switch($this->mode) {
1379
+				case self::BEFOR_HEAD: return $this->beforeHead($token); break;
1380
+				case self::IN_HEAD:    return $this->inHead($token); break;
1381
+				case self::AFTER_HEAD: return $this->afterHead($token); break;
1382
+				case self::IN_BODY:    return $this->inBody($token); break;
1383
+				case self::IN_TABLE:   return $this->inTable($token); break;
1384
+				case self::IN_CAPTION: return $this->inCaption($token); break;
1385
+				case self::IN_CGROUP:  return $this->inColumnGroup($token); break;
1386
+				case self::IN_TBODY:   return $this->inTableBody($token); break;
1387
+				case self::IN_ROW:     return $this->inRow($token); break;
1388
+				case self::IN_CELL:    return $this->inCell($token); break;
1389
+				case self::IN_SELECT:  return $this->inSelect($token); break;
1390
+				case self::AFTER_BODY: return $this->afterBody($token); break;
1391
+				case self::IN_FRAME:   return $this->inFrameset($token); break;
1392
+				case self::AFTR_FRAME: return $this->afterFrameset($token); break;
1393
+				case self::END_PHASE:  return $this->trailingEndPhase($token); break;
1394
+			}
1395
+		}
1396
+	}
1397
+
1398
+	private function beforeHead($token) {
1399
+		/* Handle the token as follows: */
1400
+
1401
+		/* A character token that is one of one of U+0009 CHARACTER TABULATION,
1402 1402
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
1403 1403
         or U+0020 SPACE */
1404
-        if($token['type'] === HTML5::CHARACTR &&
1405
-        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
1406
-            /* Append the character to the current node. */
1407
-            $this->insertText($token['data']);
1408
-
1409
-        /* A comment token */
1410
-        } elseif($token['type'] === HTML5::COMMENT) {
1411
-            /* Append a Comment node to the current node with the data attribute
1404
+		if($token['type'] === HTML5::CHARACTR &&
1405
+		preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
1406
+			/* Append the character to the current node. */
1407
+			$this->insertText($token['data']);
1408
+
1409
+		/* A comment token */
1410
+		} elseif($token['type'] === HTML5::COMMENT) {
1411
+			/* Append a Comment node to the current node with the data attribute
1412 1412
             set to the data given in the comment token. */
1413
-            $this->insertComment($token['data']);
1413
+			$this->insertComment($token['data']);
1414 1414
 
1415
-        /* A start tag token with the tag name "head" */
1416
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') {
1417
-            /* Create an element for the token, append the new element to the
1415
+		/* A start tag token with the tag name "head" */
1416
+		} elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') {
1417
+			/* Create an element for the token, append the new element to the
1418 1418
             current node and push it onto the stack of open elements. */
1419
-            $element = $this->insertElement($token);
1419
+			$element = $this->insertElement($token);
1420 1420
 
1421
-            /* Set the head element pointer to this new element node. */
1422
-            $this->head_pointer = $element;
1421
+			/* Set the head element pointer to this new element node. */
1422
+			$this->head_pointer = $element;
1423 1423
 
1424
-            /* Change the insertion mode to "in head". */
1425
-            $this->mode = self::IN_HEAD;
1424
+			/* Change the insertion mode to "in head". */
1425
+			$this->mode = self::IN_HEAD;
1426 1426
 
1427
-        /* A start tag token whose tag name is one of: "base", "link", "meta",
1427
+		/* A start tag token whose tag name is one of: "base", "link", "meta",
1428 1428
         "script", "style", "title". Or an end tag with the tag name "html".
1429 1429
         Or a character token that is not one of U+0009 CHARACTER TABULATION,
1430 1430
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
1431 1431
         or U+0020 SPACE. Or any other start tag token */
1432
-        } elseif($token['type'] === HTML5::STARTTAG ||
1433
-        ($token['type'] === HTML5::ENDTAG && $token['name'] === 'html') ||
1434
-        ($token['type'] === HTML5::CHARACTR && !preg_match('/^[\t\n\x0b\x0c ]$/',
1435
-        $token['data']))) {
1436
-            /* Act as if a start tag token with the tag name "head" and no
1432
+		} elseif($token['type'] === HTML5::STARTTAG ||
1433
+		($token['type'] === HTML5::ENDTAG && $token['name'] === 'html') ||
1434
+		($token['type'] === HTML5::CHARACTR && !preg_match('/^[\t\n\x0b\x0c ]$/',
1435
+		$token['data']))) {
1436
+			/* Act as if a start tag token with the tag name "head" and no
1437 1437
             attributes had been seen, then reprocess the current token. */
1438
-            $this->beforeHead(array(
1439
-                'name' => 'head',
1440
-                'type' => HTML5::STARTTAG,
1441
-                'attr' => array()
1442
-            ));
1438
+			$this->beforeHead(array(
1439
+				'name' => 'head',
1440
+				'type' => HTML5::STARTTAG,
1441
+				'attr' => array()
1442
+			));
1443 1443
 
1444
-            return $this->inHead($token);
1444
+			return $this->inHead($token);
1445 1445
 
1446
-        /* Any other end tag */
1447
-        } elseif($token['type'] === HTML5::ENDTAG) {
1448
-            /* Parse error. Ignore the token. */
1449
-        }
1450
-    }
1446
+		/* Any other end tag */
1447
+		} elseif($token['type'] === HTML5::ENDTAG) {
1448
+			/* Parse error. Ignore the token. */
1449
+		}
1450
+	}
1451 1451
 
1452
-    private function inHead($token) {
1453
-        /* Handle the token as follows: */
1452
+	private function inHead($token) {
1453
+		/* Handle the token as follows: */
1454 1454
 
1455
-        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
1455
+		/* A character token that is one of one of U+0009 CHARACTER TABULATION,
1456 1456
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
1457 1457
         or U+0020 SPACE.
1458 1458
 
1459 1459
         THIS DIFFERS FROM THE SPEC: If the current node is either a title, style
1460 1460
         or script element, append the character to the current node regardless
1461 1461
         of its content. */
1462
-        if(($token['type'] === HTML5::CHARACTR &&
1463
-        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) || (
1464
-        $token['type'] === HTML5::CHARACTR && in_array(end($this->stack)->nodeName,
1465
-        array('title', 'style', 'script')))) {
1466
-            /* Append the character to the current node. */
1467
-            $this->insertText($token['data']);
1468
-
1469
-        /* A comment token */
1470
-        } elseif($token['type'] === HTML5::COMMENT) {
1471
-            /* Append a Comment node to the current node with the data attribute
1462
+		if(($token['type'] === HTML5::CHARACTR &&
1463
+		preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) || (
1464
+		$token['type'] === HTML5::CHARACTR && in_array(end($this->stack)->nodeName,
1465
+		array('title', 'style', 'script')))) {
1466
+			/* Append the character to the current node. */
1467
+			$this->insertText($token['data']);
1468
+
1469
+		/* A comment token */
1470
+		} elseif($token['type'] === HTML5::COMMENT) {
1471
+			/* Append a Comment node to the current node with the data attribute
1472 1472
             set to the data given in the comment token. */
1473
-            $this->insertComment($token['data']);
1473
+			$this->insertComment($token['data']);
1474 1474
 
1475
-        } elseif($token['type'] === HTML5::ENDTAG &&
1476
-        in_array($token['name'], array('title', 'style', 'script'))) {
1477
-            array_pop($this->stack);
1478
-            return HTML5::PCDATA;
1475
+		} elseif($token['type'] === HTML5::ENDTAG &&
1476
+		in_array($token['name'], array('title', 'style', 'script'))) {
1477
+			array_pop($this->stack);
1478
+			return HTML5::PCDATA;
1479 1479
 
1480
-        /* A start tag with the tag name "title" */
1481
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'title') {
1482
-            /* Create an element for the token and append the new element to the
1480
+		/* A start tag with the tag name "title" */
1481
+		} elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'title') {
1482
+			/* Create an element for the token and append the new element to the
1483 1483
             node pointed to by the head element pointer, or, if that is null
1484 1484
             (innerHTML case), to the current node. */
1485
-            if($this->head_pointer !== null) {
1486
-                $element = $this->insertElement($token, false);
1487
-                $this->head_pointer->appendChild($element);
1485
+			if($this->head_pointer !== null) {
1486
+				$element = $this->insertElement($token, false);
1487
+				$this->head_pointer->appendChild($element);
1488 1488
 
1489
-            } else {
1490
-                $element = $this->insertElement($token);
1491
-            }
1489
+			} else {
1490
+				$element = $this->insertElement($token);
1491
+			}
1492 1492
 
1493
-            /* Switch the tokeniser's content model flag  to the RCDATA state. */
1494
-            return HTML5::RCDATA;
1493
+			/* Switch the tokeniser's content model flag  to the RCDATA state. */
1494
+			return HTML5::RCDATA;
1495 1495
 
1496
-        /* A start tag with the tag name "style" */
1497
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'style') {
1498
-            /* Create an element for the token and append the new element to the
1496
+		/* A start tag with the tag name "style" */
1497
+		} elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'style') {
1498
+			/* Create an element for the token and append the new element to the
1499 1499
             node pointed to by the head element pointer, or, if that is null
1500 1500
             (innerHTML case), to the current node. */
1501
-            if($this->head_pointer !== null) {
1502
-                $element = $this->insertElement($token, false);
1503
-                $this->head_pointer->appendChild($element);
1504
-
1505
-            } else {
1506
-                $this->insertElement($token);
1507
-            }
1508
-
1509
-            /* Switch the tokeniser's content model flag  to the CDATA state. */
1510
-            return HTML5::CDATA;
1511
-
1512
-        /* A start tag with the tag name "script" */
1513
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'script') {
1514
-            /* Create an element for the token. */
1515
-            $element = $this->insertElement($token, false);
1516
-            $this->head_pointer->appendChild($element);
1517
-
1518
-            /* Switch the tokeniser's content model flag  to the CDATA state. */
1519
-            return HTML5::CDATA;
1520
-
1521
-        /* A start tag with the tag name "base", "link", or "meta" */
1522
-        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
1523
-        array('base', 'link', 'meta'))) {
1524
-            /* Create an element for the token and append the new element to the
1501
+			if($this->head_pointer !== null) {
1502
+				$element = $this->insertElement($token, false);
1503
+				$this->head_pointer->appendChild($element);
1504
+
1505
+			} else {
1506
+				$this->insertElement($token);
1507
+			}
1508
+
1509
+			/* Switch the tokeniser's content model flag  to the CDATA state. */
1510
+			return HTML5::CDATA;
1511
+
1512
+		/* A start tag with the tag name "script" */
1513
+		} elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'script') {
1514
+			/* Create an element for the token. */
1515
+			$element = $this->insertElement($token, false);
1516
+			$this->head_pointer->appendChild($element);
1517
+
1518
+			/* Switch the tokeniser's content model flag  to the CDATA state. */
1519
+			return HTML5::CDATA;
1520
+
1521
+		/* A start tag with the tag name "base", "link", or "meta" */
1522
+		} elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
1523
+		array('base', 'link', 'meta'))) {
1524
+			/* Create an element for the token and append the new element to the
1525 1525
             node pointed to by the head element pointer, or, if that is null
1526 1526
             (innerHTML case), to the current node. */
1527
-            if($this->head_pointer !== null) {
1528
-                $element = $this->insertElement($token, false);
1529
-                $this->head_pointer->appendChild($element);
1530
-                array_pop($this->stack);
1531
-
1532
-            } else {
1533
-                $this->insertElement($token);
1534
-            }
1535
-
1536
-        /* An end tag with the tag name "head" */
1537
-        } elseif($token['type'] === HTML5::ENDTAG && $token['name'] === 'head') {
1538
-            /* If the current node is a head element, pop the current node off
1527
+			if($this->head_pointer !== null) {
1528
+				$element = $this->insertElement($token, false);
1529
+				$this->head_pointer->appendChild($element);
1530
+				array_pop($this->stack);
1531
+
1532
+			} else {
1533
+				$this->insertElement($token);
1534
+			}
1535
+
1536
+		/* An end tag with the tag name "head" */
1537
+		} elseif($token['type'] === HTML5::ENDTAG && $token['name'] === 'head') {
1538
+			/* If the current node is a head element, pop the current node off
1539 1539
             the stack of open elements. */
1540
-            if($this->head_pointer->isSameNode(end($this->stack))) {
1541
-                array_pop($this->stack);
1540
+			if($this->head_pointer->isSameNode(end($this->stack))) {
1541
+				array_pop($this->stack);
1542 1542
 
1543
-            /* Otherwise, this is a parse error. */
1544
-            } else {
1545
-                // k
1546
-            }
1543
+			/* Otherwise, this is a parse error. */
1544
+			} else {
1545
+				// k
1546
+			}
1547 1547
 
1548
-            /* Change the insertion mode to "after head". */
1549
-            $this->mode = self::AFTER_HEAD;
1548
+			/* Change the insertion mode to "after head". */
1549
+			$this->mode = self::AFTER_HEAD;
1550 1550
 
1551
-        /* A start tag with the tag name "head" or an end tag except "html". */
1552
-        } elseif(($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') ||
1553
-        ($token['type'] === HTML5::ENDTAG && $token['name'] !== 'html')) {
1554
-            // Parse error. Ignore the token.
1551
+		/* A start tag with the tag name "head" or an end tag except "html". */
1552
+		} elseif(($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') ||
1553
+		($token['type'] === HTML5::ENDTAG && $token['name'] !== 'html')) {
1554
+			// Parse error. Ignore the token.
1555 1555
 
1556
-        /* Anything else */
1557
-        } else {
1558
-            /* If the current node is a head element, act as if an end tag
1556
+		/* Anything else */
1557
+		} else {
1558
+			/* If the current node is a head element, act as if an end tag
1559 1559
             token with the tag name "head" had been seen. */
1560
-            if($this->head_pointer->isSameNode(end($this->stack))) {
1561
-                $this->inHead(array(
1562
-                    'name' => 'head',
1563
-                    'type' => HTML5::ENDTAG
1564
-                ));
1565
-
1566
-            /* Otherwise, change the insertion mode to "after head". */
1567
-            } else {
1568
-                $this->mode = self::AFTER_HEAD;
1569
-            }
1570
-
1571
-            /* Then, reprocess the current token. */
1572
-            return $this->afterHead($token);
1573
-        }
1574
-    }
1575
-
1576
-    private function afterHead($token) {
1577
-        /* Handle the token as follows: */
1578
-
1579
-        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
1560
+			if($this->head_pointer->isSameNode(end($this->stack))) {
1561
+				$this->inHead(array(
1562
+					'name' => 'head',
1563
+					'type' => HTML5::ENDTAG
1564
+				));
1565
+
1566
+			/* Otherwise, change the insertion mode to "after head". */
1567
+			} else {
1568
+				$this->mode = self::AFTER_HEAD;
1569
+			}
1570
+
1571
+			/* Then, reprocess the current token. */
1572
+			return $this->afterHead($token);
1573
+		}
1574
+	}
1575
+
1576
+	private function afterHead($token) {
1577
+		/* Handle the token as follows: */
1578
+
1579
+		/* A character token that is one of one of U+0009 CHARACTER TABULATION,
1580 1580
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
1581 1581
         or U+0020 SPACE */
1582
-        if($token['type'] === HTML5::CHARACTR &&
1583
-        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
1584
-            /* Append the character to the current node. */
1585
-            $this->insertText($token['data']);
1586
-
1587
-        /* A comment token */
1588
-        } elseif($token['type'] === HTML5::COMMENT) {
1589
-            /* Append a Comment node to the current node with the data attribute
1582
+		if($token['type'] === HTML5::CHARACTR &&
1583
+		preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
1584
+			/* Append the character to the current node. */
1585
+			$this->insertText($token['data']);
1586
+
1587
+		/* A comment token */
1588
+		} elseif($token['type'] === HTML5::COMMENT) {
1589
+			/* Append a Comment node to the current node with the data attribute
1590 1590
             set to the data given in the comment token. */
1591
-            $this->insertComment($token['data']);
1591
+			$this->insertComment($token['data']);
1592 1592
 
1593
-        /* A start tag token with the tag name "body" */
1594
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'body') {
1595
-            /* Insert a body element for the token. */
1596
-            $this->insertElement($token);
1593
+		/* A start tag token with the tag name "body" */
1594
+		} elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'body') {
1595
+			/* Insert a body element for the token. */
1596
+			$this->insertElement($token);
1597 1597
 
1598
-            /* Change the insertion mode to "in body". */
1599
-            $this->mode = self::IN_BODY;
1598
+			/* Change the insertion mode to "in body". */
1599
+			$this->mode = self::IN_BODY;
1600 1600
 
1601
-        /* A start tag token with the tag name "frameset" */
1602
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'frameset') {
1603
-            /* Insert a frameset element for the token. */
1604
-            $this->insertElement($token);
1601
+		/* A start tag token with the tag name "frameset" */
1602
+		} elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'frameset') {
1603
+			/* Insert a frameset element for the token. */
1604
+			$this->insertElement($token);
1605 1605
 
1606
-            /* Change the insertion mode to "in frameset". */
1607
-            $this->mode = self::IN_FRAME;
1606
+			/* Change the insertion mode to "in frameset". */
1607
+			$this->mode = self::IN_FRAME;
1608 1608
 
1609
-        /* A start tag token whose tag name is one of: "base", "link", "meta",
1609
+		/* A start tag token whose tag name is one of: "base", "link", "meta",
1610 1610
         "script", "style", "title" */
1611
-        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
1612
-        array('base', 'link', 'meta', 'script', 'style', 'title'))) {
1613
-            /* Parse error. Switch the insertion mode back to "in head" and
1611
+		} elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
1612
+		array('base', 'link', 'meta', 'script', 'style', 'title'))) {
1613
+			/* Parse error. Switch the insertion mode back to "in head" and
1614 1614
             reprocess the token. */
1615
-            $this->mode = self::IN_HEAD;
1616
-            return $this->inHead($token);
1615
+			$this->mode = self::IN_HEAD;
1616
+			return $this->inHead($token);
1617 1617
 
1618
-        /* Anything else */
1619
-        } else {
1620
-            /* Act as if a start tag token with the tag name "body" and no
1618
+		/* Anything else */
1619
+		} else {
1620
+			/* Act as if a start tag token with the tag name "body" and no
1621 1621
             attributes had been seen, and then reprocess the current token. */
1622
-            $this->afterHead(array(
1623
-                'name' => 'body',
1624
-                'type' => HTML5::STARTTAG,
1625
-                'attr' => array()
1626
-            ));
1627
-
1628
-            return $this->inBody($token);
1629
-        }
1630
-    }
1631
-
1632
-    private function inBody($token) {
1633
-        /* Handle the token as follows: */
1634
-
1635
-        switch($token['type']) {
1636
-            /* A character token */
1637
-            case HTML5::CHARACTR:
1638
-                /* Reconstruct the active formatting elements, if any. */
1639
-                $this->reconstructActiveFormattingElements();
1640
-
1641
-                /* Append the token's character to the current node. */
1642
-                $this->insertText($token['data']);
1643
-            break;
1644
-
1645
-            /* A comment token */
1646
-            case HTML5::COMMENT:
1647
-                /* Append a Comment node to the current node with the data
1622
+			$this->afterHead(array(
1623
+				'name' => 'body',
1624
+				'type' => HTML5::STARTTAG,
1625
+				'attr' => array()
1626
+			));
1627
+
1628
+			return $this->inBody($token);
1629
+		}
1630
+	}
1631
+
1632
+	private function inBody($token) {
1633
+		/* Handle the token as follows: */
1634
+
1635
+		switch($token['type']) {
1636
+			/* A character token */
1637
+			case HTML5::CHARACTR:
1638
+				/* Reconstruct the active formatting elements, if any. */
1639
+				$this->reconstructActiveFormattingElements();
1640
+
1641
+				/* Append the token's character to the current node. */
1642
+				$this->insertText($token['data']);
1643
+			break;
1644
+
1645
+			/* A comment token */
1646
+			case HTML5::COMMENT:
1647
+				/* Append a Comment node to the current node with the data
1648 1648
                 attribute set to the data given in the comment token. */
1649
-                $this->insertComment($token['data']);
1650
-            break;
1649
+				$this->insertComment($token['data']);
1650
+			break;
1651 1651
 
1652
-            case HTML5::STARTTAG:
1653
-            switch($token['name']) {
1654
-                /* A start tag token whose tag name is one of: "script",
1652
+			case HTML5::STARTTAG:
1653
+			switch($token['name']) {
1654
+				/* A start tag token whose tag name is one of: "script",
1655 1655
                 "style" */
1656
-                case 'script': case 'style':
1657
-                    /* Process the token as if the insertion mode had been "in
1656
+				case 'script': case 'style':
1657
+					/* Process the token as if the insertion mode had been "in
1658 1658
                     head". */
1659
-                    return $this->inHead($token);
1660
-                break;
1659
+					return $this->inHead($token);
1660
+				break;
1661 1661
 
1662
-                /* A start tag token whose tag name is one of: "base", "link",
1662
+				/* A start tag token whose tag name is one of: "base", "link",
1663 1663
                 "meta", "title" */
1664
-                case 'base': case 'link': case 'meta': case 'title':
1665
-                    /* Parse error. Process the token as if the insertion mode
1664
+				case 'base': case 'link': case 'meta': case 'title':
1665
+					/* Parse error. Process the token as if the insertion mode
1666 1666
                     had    been "in head". */
1667
-                    return $this->inHead($token);
1668
-                break;
1667
+					return $this->inHead($token);
1668
+				break;
1669 1669
 
1670
-                /* A start tag token with the tag name "body" */
1671
-                case 'body':
1672
-                    /* Parse error. If the second element on the stack of open
1670
+				/* A start tag token with the tag name "body" */
1671
+				case 'body':
1672
+					/* Parse error. If the second element on the stack of open
1673 1673
                     elements is not a body element, or, if the stack of open
1674 1674
                     elements has only one node on it, then ignore the token.
1675 1675
                     (innerHTML case) */
1676
-                    if(count($this->stack) === 1 || $this->stack[1]->nodeName !== 'body') {
1677
-                        // Ignore
1676
+					if(count($this->stack) === 1 || $this->stack[1]->nodeName !== 'body') {
1677
+						// Ignore
1678 1678
 
1679
-                    /* Otherwise, for each attribute on the token, check to see
1679
+					/* Otherwise, for each attribute on the token, check to see
1680 1680
                     if the attribute is already present on the body element (the
1681 1681
                     second element)    on the stack of open elements. If it is not,
1682 1682
                     add the attribute and its corresponding value to that
1683 1683
                     element. */
1684
-                    } else {
1685
-                        foreach($token['attr'] as $attr) {
1686
-                            if(!$this->stack[1]->hasAttribute($attr['name'])) {
1687
-                                $this->stack[1]->setAttribute($attr['name'], $attr['value']);
1688
-                            }
1689
-                        }
1690
-                    }
1691
-                break;
1692
-
1693
-                /* A start tag whose tag name is one of: "address",
1684
+					} else {
1685
+						foreach($token['attr'] as $attr) {
1686
+							if(!$this->stack[1]->hasAttribute($attr['name'])) {
1687
+								$this->stack[1]->setAttribute($attr['name'], $attr['value']);
1688
+							}
1689
+						}
1690
+					}
1691
+				break;
1692
+
1693
+				/* A start tag whose tag name is one of: "address",
1694 1694
                 "blockquote", "center", "dir", "div", "dl", "fieldset",
1695 1695
                 "listing", "menu", "ol", "p", "ul" */
1696
-                case 'address': case 'blockquote': case 'center': case 'dir':
1697
-                case 'div': case 'dl': case 'fieldset': case 'listing':
1698
-                case 'menu': case 'ol': case 'p': case 'ul':
1699
-                    /* If the stack of open elements has a p element in scope,
1696
+				case 'address': case 'blockquote': case 'center': case 'dir':
1697
+				case 'div': case 'dl': case 'fieldset': case 'listing':
1698
+				case 'menu': case 'ol': case 'p': case 'ul':
1699
+					/* If the stack of open elements has a p element in scope,
1700 1700
                     then act as if an end tag with the tag name p had been
1701 1701
                     seen. */
1702
-                    if($this->elementInScope('p')) {
1703
-                        $this->emitToken(array(
1704
-                            'name' => 'p',
1705
-                            'type' => HTML5::ENDTAG
1706
-                        ));
1707
-                    }
1708
-
1709
-                    /* Insert an HTML element for the token. */
1710
-                    $this->insertElement($token);
1711
-                break;
1712
-
1713
-                /* A start tag whose tag name is "form" */
1714
-                case 'form':
1715
-                    /* If the form element pointer is not null, ignore the
1702
+					if($this->elementInScope('p')) {
1703
+						$this->emitToken(array(
1704
+							'name' => 'p',
1705
+							'type' => HTML5::ENDTAG
1706
+						));
1707
+					}
1708
+
1709
+					/* Insert an HTML element for the token. */
1710
+					$this->insertElement($token);
1711
+				break;
1712
+
1713
+				/* A start tag whose tag name is "form" */
1714
+				case 'form':
1715
+					/* If the form element pointer is not null, ignore the
1716 1716
                     token with a parse error. */
1717
-                    if($this->form_pointer !== null) {
1718
-                        // Ignore.
1717
+					if($this->form_pointer !== null) {
1718
+						// Ignore.
1719 1719
 
1720
-                    /* Otherwise: */
1721
-                    } else {
1722
-                        /* If the stack of open elements has a p element in
1720
+					/* Otherwise: */
1721
+					} else {
1722
+						/* If the stack of open elements has a p element in
1723 1723
                         scope, then act as if an end tag with the tag name p
1724 1724
                         had been seen. */
1725
-                        if($this->elementInScope('p')) {
1726
-                            $this->emitToken(array(
1727
-                                'name' => 'p',
1728
-                                'type' => HTML5::ENDTAG
1729
-                            ));
1730
-                        }
1731
-
1732
-                        /* Insert an HTML element for the token, and set the
1725
+						if($this->elementInScope('p')) {
1726
+							$this->emitToken(array(
1727
+								'name' => 'p',
1728
+								'type' => HTML5::ENDTAG
1729
+							));
1730
+						}
1731
+
1732
+						/* Insert an HTML element for the token, and set the
1733 1733
                         form element pointer to point to the element created. */
1734
-                        $element = $this->insertElement($token);
1735
-                        $this->form_pointer = $element;
1736
-                    }
1737
-                break;
1738
-
1739
-                /* A start tag whose tag name is "li", "dd" or "dt" */
1740
-                case 'li': case 'dd': case 'dt':
1741
-                    /* If the stack of open elements has a p  element in scope,
1734
+						$element = $this->insertElement($token);
1735
+						$this->form_pointer = $element;
1736
+					}
1737
+				break;
1738
+
1739
+				/* A start tag whose tag name is "li", "dd" or "dt" */
1740
+				case 'li': case 'dd': case 'dt':
1741
+					/* If the stack of open elements has a p  element in scope,
1742 1742
                     then act as if an end tag with the tag name p had been
1743 1743
                     seen. */
1744
-                    if($this->elementInScope('p')) {
1745
-                        $this->emitToken(array(
1746
-                            'name' => 'p',
1747
-                            'type' => HTML5::ENDTAG
1748
-                        ));
1749
-                    }
1744
+					if($this->elementInScope('p')) {
1745
+						$this->emitToken(array(
1746
+							'name' => 'p',
1747
+							'type' => HTML5::ENDTAG
1748
+						));
1749
+					}
1750 1750
 
1751
-                    $stack_length = count($this->stack) - 1;
1751
+					$stack_length = count($this->stack) - 1;
1752 1752
 
1753
-                    for($n = $stack_length; 0 <= $n; $n--) {
1754
-                        /* 1. Initialise node to be the current node (the
1753
+					for($n = $stack_length; 0 <= $n; $n--) {
1754
+						/* 1. Initialise node to be the current node (the
1755 1755
                         bottommost node of the stack). */
1756
-                        $stop = false;
1757
-                        $node = $this->stack[$n];
1758
-                        $cat  = $this->getElementCategory($node->tagName);
1756
+						$stop = false;
1757
+						$node = $this->stack[$n];
1758
+						$cat  = $this->getElementCategory($node->tagName);
1759 1759
 
1760
-                        /* 2. If node is an li, dd or dt element, then pop all
1760
+						/* 2. If node is an li, dd or dt element, then pop all
1761 1761
                         the    nodes from the current node up to node, including
1762 1762
                         node, then stop this algorithm. */
1763
-                        if($token['name'] === $node->tagName ||    ($token['name'] !== 'li'
1764
-                        && ($node->tagName === 'dd' || $node->tagName === 'dt'))) {
1765
-                            for($x = $stack_length; $x >= $n ; $x--) {
1766
-                                array_pop($this->stack);
1767
-                            }
1763
+						if($token['name'] === $node->tagName ||    ($token['name'] !== 'li'
1764
+						&& ($node->tagName === 'dd' || $node->tagName === 'dt'))) {
1765
+							for($x = $stack_length; $x >= $n ; $x--) {
1766
+								array_pop($this->stack);
1767
+							}
1768 1768
 
1769
-                            break;
1770
-                        }
1769
+							break;
1770
+						}
1771 1771
 
1772
-                        /* 3. If node is not in the formatting category, and is
1772
+						/* 3. If node is not in the formatting category, and is
1773 1773
                         not    in the phrasing category, and is not an address or
1774 1774
                         div element, then stop this algorithm. */
1775
-                        if($cat !== self::FORMATTING && $cat !== self::PHRASING &&
1776
-                        $node->tagName !== 'address' && $node->tagName !== 'div') {
1777
-                            break;
1778
-                        }
1779
-                    }
1775
+						if($cat !== self::FORMATTING && $cat !== self::PHRASING &&
1776
+						$node->tagName !== 'address' && $node->tagName !== 'div') {
1777
+							break;
1778
+						}
1779
+					}
1780 1780
 
1781
-                    /* Finally, insert an HTML element with the same tag
1781
+					/* Finally, insert an HTML element with the same tag
1782 1782
                     name as the    token's. */
1783
-                    $this->insertElement($token);
1784
-                break;
1783
+					$this->insertElement($token);
1784
+				break;
1785 1785
 
1786
-                /* A start tag token whose tag name is "plaintext" */
1787
-                case 'plaintext':
1788
-                    /* If the stack of open elements has a p  element in scope,
1786
+				/* A start tag token whose tag name is "plaintext" */
1787
+				case 'plaintext':
1788
+					/* If the stack of open elements has a p  element in scope,
1789 1789
                     then act as if an end tag with the tag name p had been
1790 1790
                     seen. */
1791
-                    if($this->elementInScope('p')) {
1792
-                        $this->emitToken(array(
1793
-                            'name' => 'p',
1794
-                            'type' => HTML5::ENDTAG
1795
-                        ));
1796
-                    }
1791
+					if($this->elementInScope('p')) {
1792
+						$this->emitToken(array(
1793
+							'name' => 'p',
1794
+							'type' => HTML5::ENDTAG
1795
+						));
1796
+					}
1797 1797
 
1798
-                    /* Insert an HTML element for the token. */
1799
-                    $this->insertElement($token);
1798
+					/* Insert an HTML element for the token. */
1799
+					$this->insertElement($token);
1800 1800
 
1801
-                    return HTML5::PLAINTEXT;
1802
-                break;
1801
+					return HTML5::PLAINTEXT;
1802
+				break;
1803 1803
 
1804
-                /* A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
1804
+				/* A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
1805 1805
                 "h5", "h6" */
1806
-                case 'h1': case 'h2': case 'h3': case 'h4': case 'h5': case 'h6':
1807
-                    /* If the stack of open elements has a p  element in scope,
1806
+				case 'h1': case 'h2': case 'h3': case 'h4': case 'h5': case 'h6':
1807
+					/* If the stack of open elements has a p  element in scope,
1808 1808
                     then act as if an end tag with the tag name p had been seen. */
1809
-                    if($this->elementInScope('p')) {
1810
-                        $this->emitToken(array(
1811
-                            'name' => 'p',
1812
-                            'type' => HTML5::ENDTAG
1813
-                        ));
1814
-                    }
1815
-
1816
-                    /* If the stack of open elements has in scope an element whose
1809
+					if($this->elementInScope('p')) {
1810
+						$this->emitToken(array(
1811
+							'name' => 'p',
1812
+							'type' => HTML5::ENDTAG
1813
+						));
1814
+					}
1815
+
1816
+					/* If the stack of open elements has in scope an element whose
1817 1817
                     tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6", then
1818 1818
                     this is a parse error; pop elements from the stack until an
1819 1819
                     element with one of those tag names has been popped from the
1820 1820
                     stack. */
1821
-                    while($this->elementInScope(array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'))) {
1822
-                        array_pop($this->stack);
1823
-                    }
1821
+					while($this->elementInScope(array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'))) {
1822
+						array_pop($this->stack);
1823
+					}
1824 1824
 
1825
-                    /* Insert an HTML element for the token. */
1826
-                    $this->insertElement($token);
1827
-                break;
1825
+					/* Insert an HTML element for the token. */
1826
+					$this->insertElement($token);
1827
+				break;
1828 1828
 
1829
-                /* A start tag whose tag name is "a" */
1830
-                case 'a':
1831
-                    /* If the list of active formatting elements contains
1829
+				/* A start tag whose tag name is "a" */
1830
+				case 'a':
1831
+					/* If the list of active formatting elements contains
1832 1832
                     an element whose tag name is "a" between the end of the
1833 1833
                     list and the last marker on the list (or the start of
1834 1834
                     the list if there is no marker on the list), then this
@@ -1837,940 +1837,940 @@  discard block
 block discarded – undo
1837 1837
                     of active formatting elements and the stack of open
1838 1838
                     elements if the end tag didn't already remove it (it
1839 1839
                     might not have if the element is not in table scope). */
1840
-                    $leng = count($this->a_formatting);
1840
+					$leng = count($this->a_formatting);
1841 1841
 
1842
-                    for($n = $leng - 1; $n >= 0; $n--) {
1843
-                        if($this->a_formatting[$n] === self::MARKER) {
1844
-                            break;
1842
+					for($n = $leng - 1; $n >= 0; $n--) {
1843
+						if($this->a_formatting[$n] === self::MARKER) {
1844
+							break;
1845 1845
 
1846
-                        } elseif($this->a_formatting[$n]->nodeName === 'a') {
1847
-                            $this->emitToken(array(
1848
-                                'name' => 'a',
1849
-                                'type' => HTML5::ENDTAG
1850
-                            ));
1851
-                            break;
1852
-                        }
1853
-                    }
1846
+						} elseif($this->a_formatting[$n]->nodeName === 'a') {
1847
+							$this->emitToken(array(
1848
+								'name' => 'a',
1849
+								'type' => HTML5::ENDTAG
1850
+							));
1851
+							break;
1852
+						}
1853
+					}
1854 1854
 
1855
-                    /* Reconstruct the active formatting elements, if any. */
1856
-                    $this->reconstructActiveFormattingElements();
1855
+					/* Reconstruct the active formatting elements, if any. */
1856
+					$this->reconstructActiveFormattingElements();
1857 1857
 
1858
-                    /* Insert an HTML element for the token. */
1859
-                    $el = $this->insertElement($token);
1858
+					/* Insert an HTML element for the token. */
1859
+					$el = $this->insertElement($token);
1860 1860
 
1861
-                    /* Add that element to the list of active formatting
1861
+					/* Add that element to the list of active formatting
1862 1862
                     elements. */
1863
-                    $this->a_formatting[] = $el;
1864
-                break;
1863
+					$this->a_formatting[] = $el;
1864
+				break;
1865 1865
 
1866
-                /* A start tag whose tag name is one of: "b", "big", "em", "font",
1866
+				/* A start tag whose tag name is one of: "b", "big", "em", "font",
1867 1867
                 "i", "nobr", "s", "small", "strike", "strong", "tt", "u" */
1868
-                case 'b': case 'big': case 'em': case 'font': case 'i':
1869
-                case 'nobr': case 's': case 'small': case 'strike':
1870
-                case 'strong': case 'tt': case 'u':
1871
-                    /* Reconstruct the active formatting elements, if any. */
1872
-                    $this->reconstructActiveFormattingElements();
1868
+				case 'b': case 'big': case 'em': case 'font': case 'i':
1869
+				case 'nobr': case 's': case 'small': case 'strike':
1870
+				case 'strong': case 'tt': case 'u':
1871
+					/* Reconstruct the active formatting elements, if any. */
1872
+					$this->reconstructActiveFormattingElements();
1873 1873
 
1874
-                    /* Insert an HTML element for the token. */
1875
-                    $el = $this->insertElement($token);
1874
+					/* Insert an HTML element for the token. */
1875
+					$el = $this->insertElement($token);
1876 1876
 
1877
-                    /* Add that element to the list of active formatting
1877
+					/* Add that element to the list of active formatting
1878 1878
                     elements. */
1879
-                    $this->a_formatting[] = $el;
1880
-                break;
1879
+					$this->a_formatting[] = $el;
1880
+				break;
1881 1881
 
1882
-                /* A start tag token whose tag name is "button" */
1883
-                case 'button':
1884
-                    /* If the stack of open elements has a button element in scope,
1882
+				/* A start tag token whose tag name is "button" */
1883
+				case 'button':
1884
+					/* If the stack of open elements has a button element in scope,
1885 1885
                     then this is a parse error; act as if an end tag with the tag
1886 1886
                     name "button" had been seen, then reprocess the token. (We don't
1887 1887
                     do that. Unnecessary.) */
1888
-                    if($this->elementInScope('button')) {
1889
-                        $this->inBody(array(
1890
-                            'name' => 'button',
1891
-                            'type' => HTML5::ENDTAG
1892
-                        ));
1893
-                    }
1888
+					if($this->elementInScope('button')) {
1889
+						$this->inBody(array(
1890
+							'name' => 'button',
1891
+							'type' => HTML5::ENDTAG
1892
+						));
1893
+					}
1894 1894
 
1895
-                    /* Reconstruct the active formatting elements, if any. */
1896
-                    $this->reconstructActiveFormattingElements();
1895
+					/* Reconstruct the active formatting elements, if any. */
1896
+					$this->reconstructActiveFormattingElements();
1897 1897
 
1898
-                    /* Insert an HTML element for the token. */
1899
-                    $this->insertElement($token);
1898
+					/* Insert an HTML element for the token. */
1899
+					$this->insertElement($token);
1900 1900
 
1901
-                    /* Insert a marker at the end of the list of active
1901
+					/* Insert a marker at the end of the list of active
1902 1902
                     formatting elements. */
1903
-                    $this->a_formatting[] = self::MARKER;
1904
-                break;
1903
+					$this->a_formatting[] = self::MARKER;
1904
+				break;
1905 1905
 
1906
-                /* A start tag token whose tag name is one of: "marquee", "object" */
1907
-                case 'marquee': case 'object':
1908
-                    /* Reconstruct the active formatting elements, if any. */
1909
-                    $this->reconstructActiveFormattingElements();
1906
+				/* A start tag token whose tag name is one of: "marquee", "object" */
1907
+				case 'marquee': case 'object':
1908
+					/* Reconstruct the active formatting elements, if any. */
1909
+					$this->reconstructActiveFormattingElements();
1910 1910
 
1911
-                    /* Insert an HTML element for the token. */
1912
-                    $this->insertElement($token);
1911
+					/* Insert an HTML element for the token. */
1912
+					$this->insertElement($token);
1913 1913
 
1914
-                    /* Insert a marker at the end of the list of active
1914
+					/* Insert a marker at the end of the list of active
1915 1915
                     formatting elements. */
1916
-                    $this->a_formatting[] = self::MARKER;
1917
-                break;
1916
+					$this->a_formatting[] = self::MARKER;
1917
+				break;
1918 1918
 
1919
-                /* A start tag token whose tag name is "xmp" */
1920
-                case 'xmp':
1921
-                    /* Reconstruct the active formatting elements, if any. */
1922
-                    $this->reconstructActiveFormattingElements();
1919
+				/* A start tag token whose tag name is "xmp" */
1920
+				case 'xmp':
1921
+					/* Reconstruct the active formatting elements, if any. */
1922
+					$this->reconstructActiveFormattingElements();
1923 1923
 
1924
-                    /* Insert an HTML element for the token. */
1925
-                    $this->insertElement($token);
1924
+					/* Insert an HTML element for the token. */
1925
+					$this->insertElement($token);
1926 1926
 
1927
-                    /* Switch the content model flag to the CDATA state. */
1928
-                    return HTML5::CDATA;
1929
-                break;
1927
+					/* Switch the content model flag to the CDATA state. */
1928
+					return HTML5::CDATA;
1929
+				break;
1930 1930
 
1931
-                /* A start tag whose tag name is "table" */
1932
-                case 'table':
1933
-                    /* If the stack of open elements has a p element in scope,
1931
+				/* A start tag whose tag name is "table" */
1932
+				case 'table':
1933
+					/* If the stack of open elements has a p element in scope,
1934 1934
                     then act as if an end tag with the tag name p had been seen. */
1935
-                    if($this->elementInScope('p')) {
1936
-                        $this->emitToken(array(
1937
-                            'name' => 'p',
1938
-                            'type' => HTML5::ENDTAG
1939
-                        ));
1940
-                    }
1935
+					if($this->elementInScope('p')) {
1936
+						$this->emitToken(array(
1937
+							'name' => 'p',
1938
+							'type' => HTML5::ENDTAG
1939
+						));
1940
+					}
1941 1941
 
1942
-                    /* Insert an HTML element for the token. */
1943
-                    $this->insertElement($token);
1942
+					/* Insert an HTML element for the token. */
1943
+					$this->insertElement($token);
1944 1944
 
1945
-                    /* Change the insertion mode to "in table". */
1946
-                    $this->mode = self::IN_TABLE;
1947
-                break;
1945
+					/* Change the insertion mode to "in table". */
1946
+					$this->mode = self::IN_TABLE;
1947
+				break;
1948 1948
 
1949
-                /* A start tag whose tag name is one of: "area", "basefont",
1949
+				/* A start tag whose tag name is one of: "area", "basefont",
1950 1950
                 "bgsound", "br", "embed", "img", "param", "spacer", "wbr" */
1951
-                case 'area': case 'basefont': case 'bgsound': case 'br':
1952
-                case 'embed': case 'img': case 'param': case 'spacer':
1953
-                case 'wbr':
1954
-                    /* Reconstruct the active formatting elements, if any. */
1955
-                    $this->reconstructActiveFormattingElements();
1956
-
1957
-                    /* Insert an HTML element for the token. */
1958
-                    $this->insertElement($token);
1959
-
1960
-                    /* Immediately pop the current node off the stack of open elements. */
1961
-                    array_pop($this->stack);
1962
-                break;
1963
-
1964
-                /* A start tag whose tag name is "hr" */
1965
-                case 'hr':
1966
-                    /* If the stack of open elements has a p element in scope,
1951
+				case 'area': case 'basefont': case 'bgsound': case 'br':
1952
+				case 'embed': case 'img': case 'param': case 'spacer':
1953
+				case 'wbr':
1954
+					/* Reconstruct the active formatting elements, if any. */
1955
+					$this->reconstructActiveFormattingElements();
1956
+
1957
+					/* Insert an HTML element for the token. */
1958
+					$this->insertElement($token);
1959
+
1960
+					/* Immediately pop the current node off the stack of open elements. */
1961
+					array_pop($this->stack);
1962
+				break;
1963
+
1964
+				/* A start tag whose tag name is "hr" */
1965
+				case 'hr':
1966
+					/* If the stack of open elements has a p element in scope,
1967 1967
                     then act as if an end tag with the tag name p had been seen. */
1968
-                    if($this->elementInScope('p')) {
1969
-                        $this->emitToken(array(
1970
-                            'name' => 'p',
1971
-                            'type' => HTML5::ENDTAG
1972
-                        ));
1973
-                    }
1974
-
1975
-                    /* Insert an HTML element for the token. */
1976
-                    $this->insertElement($token);
1977
-
1978
-                    /* Immediately pop the current node off the stack of open elements. */
1979
-                    array_pop($this->stack);
1980
-                break;
1981
-
1982
-                /* A start tag whose tag name is "image" */
1983
-                case 'image':
1984
-                    /* Parse error. Change the token's tag name to "img" and
1968
+					if($this->elementInScope('p')) {
1969
+						$this->emitToken(array(
1970
+							'name' => 'p',
1971
+							'type' => HTML5::ENDTAG
1972
+						));
1973
+					}
1974
+
1975
+					/* Insert an HTML element for the token. */
1976
+					$this->insertElement($token);
1977
+
1978
+					/* Immediately pop the current node off the stack of open elements. */
1979
+					array_pop($this->stack);
1980
+				break;
1981
+
1982
+				/* A start tag whose tag name is "image" */
1983
+				case 'image':
1984
+					/* Parse error. Change the token's tag name to "img" and
1985 1985
                     reprocess it. (Don't ask.) */
1986
-                    $token['name'] = 'img';
1987
-                    return $this->inBody($token);
1988
-                break;
1986
+					$token['name'] = 'img';
1987
+					return $this->inBody($token);
1988
+				break;
1989 1989
 
1990
-                /* A start tag whose tag name is "input" */
1991
-                case 'input':
1992
-                    /* Reconstruct the active formatting elements, if any. */
1993
-                    $this->reconstructActiveFormattingElements();
1990
+				/* A start tag whose tag name is "input" */
1991
+				case 'input':
1992
+					/* Reconstruct the active formatting elements, if any. */
1993
+					$this->reconstructActiveFormattingElements();
1994 1994
 
1995
-                    /* Insert an input element for the token. */
1996
-                    $element = $this->insertElement($token, false);
1995
+					/* Insert an input element for the token. */
1996
+					$element = $this->insertElement($token, false);
1997 1997
 
1998
-                    /* If the form element pointer is not null, then associate the
1998
+					/* If the form element pointer is not null, then associate the
1999 1999
                     input element with the form element pointed to by the form
2000 2000
                     element pointer. */
2001
-                    $this->form_pointer !== null
2002
-                        ? $this->form_pointer->appendChild($element)
2003
-                        : end($this->stack)->appendChild($element);
2001
+					$this->form_pointer !== null
2002
+						? $this->form_pointer->appendChild($element)
2003
+						: end($this->stack)->appendChild($element);
2004 2004
 
2005
-                    /* Pop that input element off the stack of open elements. */
2006
-                    array_pop($this->stack);
2007
-                break;
2005
+					/* Pop that input element off the stack of open elements. */
2006
+					array_pop($this->stack);
2007
+				break;
2008 2008
 
2009
-                /* A start tag whose tag name is "isindex" */
2010
-                case 'isindex':
2011
-                    /* Parse error. */
2012
-                    // w/e
2009
+				/* A start tag whose tag name is "isindex" */
2010
+				case 'isindex':
2011
+					/* Parse error. */
2012
+					// w/e
2013 2013
 
2014
-                    /* If the form element pointer is not null,
2014
+					/* If the form element pointer is not null,
2015 2015
                     then ignore the token. */
2016
-                    if($this->form_pointer === null) {
2017
-                        /* Act as if a start tag token with the tag name "form" had
2016
+					if($this->form_pointer === null) {
2017
+						/* Act as if a start tag token with the tag name "form" had
2018 2018
                         been seen. */
2019
-                        $this->inBody(array(
2020
-                            'name' => 'body',
2021
-                            'type' => HTML5::STARTTAG,
2022
-                            'attr' => array()
2023
-                        ));
2019
+						$this->inBody(array(
2020
+							'name' => 'body',
2021
+							'type' => HTML5::STARTTAG,
2022
+							'attr' => array()
2023
+						));
2024 2024
 
2025
-                        /* Act as if a start tag token with the tag name "hr" had
2025
+						/* Act as if a start tag token with the tag name "hr" had
2026 2026
                         been seen. */
2027
-                        $this->inBody(array(
2028
-                            'name' => 'hr',
2029
-                            'type' => HTML5::STARTTAG,
2030
-                            'attr' => array()
2031
-                        ));
2027
+						$this->inBody(array(
2028
+							'name' => 'hr',
2029
+							'type' => HTML5::STARTTAG,
2030
+							'attr' => array()
2031
+						));
2032 2032
 
2033
-                        /* Act as if a start tag token with the tag name "p" had
2033
+						/* Act as if a start tag token with the tag name "p" had
2034 2034
                         been seen. */
2035
-                        $this->inBody(array(
2036
-                            'name' => 'p',
2037
-                            'type' => HTML5::STARTTAG,
2038
-                            'attr' => array()
2039
-                        ));
2035
+						$this->inBody(array(
2036
+							'name' => 'p',
2037
+							'type' => HTML5::STARTTAG,
2038
+							'attr' => array()
2039
+						));
2040 2040
 
2041
-                        /* Act as if a start tag token with the tag name "label"
2041
+						/* Act as if a start tag token with the tag name "label"
2042 2042
                         had been seen. */
2043
-                        $this->inBody(array(
2044
-                            'name' => 'label',
2045
-                            'type' => HTML5::STARTTAG,
2046
-                            'attr' => array()
2047
-                        ));
2043
+						$this->inBody(array(
2044
+							'name' => 'label',
2045
+							'type' => HTML5::STARTTAG,
2046
+							'attr' => array()
2047
+						));
2048 2048
 
2049
-                        /* Act as if a stream of character tokens had been seen. */
2050
-                        $this->insertText('This is a searchable index. '.
2051
-                        'Insert your search keywords here: ');
2049
+						/* Act as if a stream of character tokens had been seen. */
2050
+						$this->insertText('This is a searchable index. '.
2051
+						'Insert your search keywords here: ');
2052 2052
 
2053
-                        /* Act as if a start tag token with the tag name "input"
2053
+						/* Act as if a start tag token with the tag name "input"
2054 2054
                         had been seen, with all the attributes from the "isindex"
2055 2055
                         token, except with the "name" attribute set to the value
2056 2056
                         "isindex" (ignoring any explicit "name" attribute). */
2057
-                        $attr = $token['attr'];
2058
-                        $attr[] = array('name' => 'name', 'value' => 'isindex');
2057
+						$attr = $token['attr'];
2058
+						$attr[] = array('name' => 'name', 'value' => 'isindex');
2059 2059
 
2060
-                        $this->inBody(array(
2061
-                            'name' => 'input',
2062
-                            'type' => HTML5::STARTTAG,
2063
-                            'attr' => $attr
2064
-                        ));
2060
+						$this->inBody(array(
2061
+							'name' => 'input',
2062
+							'type' => HTML5::STARTTAG,
2063
+							'attr' => $attr
2064
+						));
2065 2065
 
2066
-                        /* Act as if a stream of character tokens had been seen
2066
+						/* Act as if a stream of character tokens had been seen
2067 2067
                         (see below for what they should say). */
2068
-                        $this->insertText('This is a searchable index. '.
2069
-                        'Insert your search keywords here: ');
2068
+						$this->insertText('This is a searchable index. '.
2069
+						'Insert your search keywords here: ');
2070 2070
 
2071
-                        /* Act as if an end tag token with the tag name "label"
2071
+						/* Act as if an end tag token with the tag name "label"
2072 2072
                         had been seen. */
2073
-                        $this->inBody(array(
2074
-                            'name' => 'label',
2075
-                            'type' => HTML5::ENDTAG
2076
-                        ));
2073
+						$this->inBody(array(
2074
+							'name' => 'label',
2075
+							'type' => HTML5::ENDTAG
2076
+						));
2077 2077
 
2078
-                        /* Act as if an end tag token with the tag name "p" had
2078
+						/* Act as if an end tag token with the tag name "p" had
2079 2079
                         been seen. */
2080
-                        $this->inBody(array(
2081
-                            'name' => 'p',
2082
-                            'type' => HTML5::ENDTAG
2083
-                        ));
2080
+						$this->inBody(array(
2081
+							'name' => 'p',
2082
+							'type' => HTML5::ENDTAG
2083
+						));
2084 2084
 
2085
-                        /* Act as if a start tag token with the tag name "hr" had
2085
+						/* Act as if a start tag token with the tag name "hr" had
2086 2086
                         been seen. */
2087
-                        $this->inBody(array(
2088
-                            'name' => 'hr',
2089
-                            'type' => HTML5::ENDTAG
2090
-                        ));
2087
+						$this->inBody(array(
2088
+							'name' => 'hr',
2089
+							'type' => HTML5::ENDTAG
2090
+						));
2091 2091
 
2092
-                        /* Act as if an end tag token with the tag name "form" had
2092
+						/* Act as if an end tag token with the tag name "form" had
2093 2093
                         been seen. */
2094
-                        $this->inBody(array(
2095
-                            'name' => 'form',
2096
-                            'type' => HTML5::ENDTAG
2097
-                        ));
2098
-                    }
2099
-                break;
2100
-
2101
-                /* A start tag whose tag name is "textarea" */
2102
-                case 'textarea':
2103
-                    $this->insertElement($token);
2104
-
2105
-                    /* Switch the tokeniser's content model flag to the
2094
+						$this->inBody(array(
2095
+							'name' => 'form',
2096
+							'type' => HTML5::ENDTAG
2097
+						));
2098
+					}
2099
+				break;
2100
+
2101
+				/* A start tag whose tag name is "textarea" */
2102
+				case 'textarea':
2103
+					$this->insertElement($token);
2104
+
2105
+					/* Switch the tokeniser's content model flag to the
2106 2106
                     RCDATA state. */
2107
-                    return HTML5::RCDATA;
2108
-                break;
2107
+					return HTML5::RCDATA;
2108
+				break;
2109 2109
 
2110
-                /* A start tag whose tag name is one of: "iframe", "noembed",
2110
+				/* A start tag whose tag name is one of: "iframe", "noembed",
2111 2111
                 "noframes" */
2112
-                case 'iframe': case 'noembed': case 'noframes':
2113
-                    $this->insertElement($token);
2112
+				case 'iframe': case 'noembed': case 'noframes':
2113
+					$this->insertElement($token);
2114 2114
 
2115
-                    /* Switch the tokeniser's content model flag to the CDATA state. */
2116
-                    return HTML5::CDATA;
2117
-                break;
2115
+					/* Switch the tokeniser's content model flag to the CDATA state. */
2116
+					return HTML5::CDATA;
2117
+				break;
2118 2118
 
2119
-                /* A start tag whose tag name is "select" */
2120
-                case 'select':
2121
-                    /* Reconstruct the active formatting elements, if any. */
2122
-                    $this->reconstructActiveFormattingElements();
2119
+				/* A start tag whose tag name is "select" */
2120
+				case 'select':
2121
+					/* Reconstruct the active formatting elements, if any. */
2122
+					$this->reconstructActiveFormattingElements();
2123 2123
 
2124
-                    /* Insert an HTML element for the token. */
2125
-                    $this->insertElement($token);
2124
+					/* Insert an HTML element for the token. */
2125
+					$this->insertElement($token);
2126 2126
 
2127
-                    /* Change the insertion mode to "in select". */
2128
-                    $this->mode = self::IN_SELECT;
2129
-                break;
2127
+					/* Change the insertion mode to "in select". */
2128
+					$this->mode = self::IN_SELECT;
2129
+				break;
2130 2130
 
2131
-                /* A start or end tag whose tag name is one of: "caption", "col",
2131
+				/* A start or end tag whose tag name is one of: "caption", "col",
2132 2132
                 "colgroup", "frame", "frameset", "head", "option", "optgroup",
2133 2133
                 "tbody", "td", "tfoot", "th", "thead", "tr". */
2134
-                case 'caption': case 'col': case 'colgroup': case 'frame':
2135
-                case 'frameset': case 'head': case 'option': case 'optgroup':
2136
-                case 'tbody': case 'td': case 'tfoot': case 'th': case 'thead':
2137
-                case 'tr':
2138
-                    // Parse error. Ignore the token.
2139
-                break;
2140
-
2141
-                /* A start or end tag whose tag name is one of: "event-source",
2134
+				case 'caption': case 'col': case 'colgroup': case 'frame':
2135
+				case 'frameset': case 'head': case 'option': case 'optgroup':
2136
+				case 'tbody': case 'td': case 'tfoot': case 'th': case 'thead':
2137
+				case 'tr':
2138
+					// Parse error. Ignore the token.
2139
+				break;
2140
+
2141
+				/* A start or end tag whose tag name is one of: "event-source",
2142 2142
                 "section", "nav", "article", "aside", "header", "footer",
2143 2143
                 "datagrid", "command" */
2144
-                case 'event-source': case 'section': case 'nav': case 'article':
2145
-                case 'aside': case 'header': case 'footer': case 'datagrid':
2146
-                case 'command':
2147
-                    // Work in progress!
2148
-                break;
2149
-
2150
-                /* A start tag token not covered by the previous entries */
2151
-                default:
2152
-                    /* Reconstruct the active formatting elements, if any. */
2153
-                    $this->reconstructActiveFormattingElements();
2154
-
2155
-                    $this->insertElement($token, true, true);
2156
-                break;
2157
-            }
2158
-            break;
2159
-
2160
-            case HTML5::ENDTAG:
2161
-            switch($token['name']) {
2162
-                /* An end tag with the tag name "body" */
2163
-                case 'body':
2164
-                    /* If the second element in the stack of open elements is
2144
+				case 'event-source': case 'section': case 'nav': case 'article':
2145
+				case 'aside': case 'header': case 'footer': case 'datagrid':
2146
+				case 'command':
2147
+					// Work in progress!
2148
+				break;
2149
+
2150
+				/* A start tag token not covered by the previous entries */
2151
+				default:
2152
+					/* Reconstruct the active formatting elements, if any. */
2153
+					$this->reconstructActiveFormattingElements();
2154
+
2155
+					$this->insertElement($token, true, true);
2156
+				break;
2157
+			}
2158
+			break;
2159
+
2160
+			case HTML5::ENDTAG:
2161
+			switch($token['name']) {
2162
+				/* An end tag with the tag name "body" */
2163
+				case 'body':
2164
+					/* If the second element in the stack of open elements is
2165 2165
                     not a body element, this is a parse error. Ignore the token.
2166 2166
                     (innerHTML case) */
2167
-                    if(count($this->stack) < 2 || $this->stack[1]->nodeName !== 'body') {
2168
-                        // Ignore.
2167
+					if(count($this->stack) < 2 || $this->stack[1]->nodeName !== 'body') {
2168
+						// Ignore.
2169 2169
 
2170
-                    /* If the current node is not the body element, then this
2170
+					/* If the current node is not the body element, then this
2171 2171
                     is a parse error. */
2172
-                    } elseif(end($this->stack)->nodeName !== 'body') {
2173
-                        // Parse error.
2174
-                    }
2172
+					} elseif(end($this->stack)->nodeName !== 'body') {
2173
+						// Parse error.
2174
+					}
2175 2175
 
2176
-                    /* Change the insertion mode to "after body". */
2177
-                    $this->mode = self::AFTER_BODY;
2178
-                break;
2176
+					/* Change the insertion mode to "after body". */
2177
+					$this->mode = self::AFTER_BODY;
2178
+				break;
2179 2179
 
2180
-                /* An end tag with the tag name "html" */
2181
-                case 'html':
2182
-                    /* Act as if an end tag with tag name "body" had been seen,
2180
+				/* An end tag with the tag name "html" */
2181
+				case 'html':
2182
+					/* Act as if an end tag with tag name "body" had been seen,
2183 2183
                     then, if that token wasn't ignored, reprocess the current
2184 2184
                     token. */
2185
-                    $this->inBody(array(
2186
-                        'name' => 'body',
2187
-                        'type' => HTML5::ENDTAG
2188
-                    ));
2185
+					$this->inBody(array(
2186
+						'name' => 'body',
2187
+						'type' => HTML5::ENDTAG
2188
+					));
2189 2189
 
2190
-                    return $this->afterBody($token);
2191
-                break;
2190
+					return $this->afterBody($token);
2191
+				break;
2192 2192
 
2193
-                /* An end tag whose tag name is one of: "address", "blockquote",
2193
+				/* An end tag whose tag name is one of: "address", "blockquote",
2194 2194
                 "center", "dir", "div", "dl", "fieldset", "listing", "menu",
2195 2195
                 "ol", "pre", "ul" */
2196
-                case 'address': case 'blockquote': case 'center': case 'dir':
2197
-                case 'div': case 'dl': case 'fieldset': case 'listing':
2198
-                case 'menu': case 'ol': case 'pre': case 'ul':
2199
-                    /* If the stack of open elements has an element in scope
2196
+				case 'address': case 'blockquote': case 'center': case 'dir':
2197
+				case 'div': case 'dl': case 'fieldset': case 'listing':
2198
+				case 'menu': case 'ol': case 'pre': case 'ul':
2199
+					/* If the stack of open elements has an element in scope
2200 2200
                     with the same tag name as that of the token, then generate
2201 2201
                     implied end tags. */
2202
-                    if($this->elementInScope($token['name'])) {
2203
-                        $this->generateImpliedEndTags();
2202
+					if($this->elementInScope($token['name'])) {
2203
+						$this->generateImpliedEndTags();
2204 2204
 
2205
-                        /* Now, if the current node is not an element with
2205
+						/* Now, if the current node is not an element with
2206 2206
                         the same tag name as that of the token, then this
2207 2207
                         is a parse error. */
2208
-                        // w/e
2208
+						// w/e
2209 2209
 
2210
-                        /* If the stack of open elements has an element in
2210
+						/* If the stack of open elements has an element in
2211 2211
                         scope with the same tag name as that of the token,
2212 2212
                         then pop elements from this stack until an element
2213 2213
                         with that tag name has been popped from the stack. */
2214
-                        for($n = count($this->stack) - 1; $n >= 0; $n--) {
2215
-                            if($this->stack[$n]->nodeName === $token['name']) {
2216
-                                $n = -1;
2217
-                            }
2218
-
2219
-                            array_pop($this->stack);
2220
-                        }
2221
-                    }
2222
-                break;
2223
-
2224
-                /* An end tag whose tag name is "form" */
2225
-                case 'form':
2226
-                    /* If the stack of open elements has an element in scope
2214
+						for($n = count($this->stack) - 1; $n >= 0; $n--) {
2215
+							if($this->stack[$n]->nodeName === $token['name']) {
2216
+								$n = -1;
2217
+							}
2218
+
2219
+							array_pop($this->stack);
2220
+						}
2221
+					}
2222
+				break;
2223
+
2224
+				/* An end tag whose tag name is "form" */
2225
+				case 'form':
2226
+					/* If the stack of open elements has an element in scope
2227 2227
                     with the same tag name as that of the token, then generate
2228 2228
                     implied    end tags. */
2229
-                    if($this->elementInScope($token['name'])) {
2230
-                        $this->generateImpliedEndTags();
2229
+					if($this->elementInScope($token['name'])) {
2230
+						$this->generateImpliedEndTags();
2231 2231
 
2232
-                    } 
2232
+					} 
2233 2233
 
2234
-                    if(end($this->stack)->nodeName !== $token['name']) {
2235
-                        /* Now, if the current node is not an element with the
2234
+					if(end($this->stack)->nodeName !== $token['name']) {
2235
+						/* Now, if the current node is not an element with the
2236 2236
                         same tag name as that of the token, then this is a parse
2237 2237
                         error. */
2238
-                        // w/e
2238
+						// w/e
2239 2239
 
2240
-                    } else {
2241
-                        /* Otherwise, if the current node is an element with
2240
+					} else {
2241
+						/* Otherwise, if the current node is an element with
2242 2242
                         the same tag name as that of the token pop that element
2243 2243
                         from the stack. */
2244
-                        array_pop($this->stack);
2245
-                    }
2244
+						array_pop($this->stack);
2245
+					}
2246 2246
 
2247
-                    /* In any case, set the form element pointer to null. */
2248
-                    $this->form_pointer = null;
2249
-                break;
2247
+					/* In any case, set the form element pointer to null. */
2248
+					$this->form_pointer = null;
2249
+				break;
2250 2250
 
2251
-                /* An end tag whose tag name is "p" */
2252
-                case 'p':
2253
-                    /* If the stack of open elements has a p element in scope,
2251
+				/* An end tag whose tag name is "p" */
2252
+				case 'p':
2253
+					/* If the stack of open elements has a p element in scope,
2254 2254
                     then generate implied end tags, except for p elements. */
2255
-                    if($this->elementInScope('p')) {
2256
-                        $this->generateImpliedEndTags(array('p'));
2255
+					if($this->elementInScope('p')) {
2256
+						$this->generateImpliedEndTags(array('p'));
2257 2257
 
2258
-                        /* If the current node is not a p element, then this is
2258
+						/* If the current node is not a p element, then this is
2259 2259
                         a parse error. */
2260
-                        // k
2260
+						// k
2261 2261
 
2262
-                        /* If the stack of open elements has a p element in
2262
+						/* If the stack of open elements has a p element in
2263 2263
                         scope, then pop elements from this stack until the stack
2264 2264
                         no longer has a p element in scope. */
2265
-                        for($n = count($this->stack) - 1; $n >= 0; $n--) {
2266
-                            if($this->elementInScope('p')) {
2267
-                                array_pop($this->stack);
2268
-
2269
-                            } else {
2270
-                                break;
2271
-                            }
2272
-                        }
2273
-                    }
2274
-                break;
2275
-
2276
-                /* An end tag whose tag name is "dd", "dt", or "li" */
2277
-                case 'dd': case 'dt': case 'li':
2278
-                    /* If the stack of open elements has an element in scope
2265
+						for($n = count($this->stack) - 1; $n >= 0; $n--) {
2266
+							if($this->elementInScope('p')) {
2267
+								array_pop($this->stack);
2268
+
2269
+							} else {
2270
+								break;
2271
+							}
2272
+						}
2273
+					}
2274
+				break;
2275
+
2276
+				/* An end tag whose tag name is "dd", "dt", or "li" */
2277
+				case 'dd': case 'dt': case 'li':
2278
+					/* If the stack of open elements has an element in scope
2279 2279
                     whose tag name matches the tag name of the token, then
2280 2280
                     generate implied end tags, except for elements with the
2281 2281
                     same tag name as the token. */
2282
-                    if($this->elementInScope($token['name'])) {
2283
-                        $this->generateImpliedEndTags(array($token['name']));
2282
+					if($this->elementInScope($token['name'])) {
2283
+						$this->generateImpliedEndTags(array($token['name']));
2284 2284
 
2285
-                        /* If the current node is not an element with the same
2285
+						/* If the current node is not an element with the same
2286 2286
                         tag name as the token, then this is a parse error. */
2287
-                        // w/e
2287
+						// w/e
2288 2288
 
2289
-                        /* If the stack of open elements has an element in scope
2289
+						/* If the stack of open elements has an element in scope
2290 2290
                         whose tag name matches the tag name of the token, then
2291 2291
                         pop elements from this stack until an element with that
2292 2292
                         tag name has been popped from the stack. */
2293
-                        for($n = count($this->stack) - 1; $n >= 0; $n--) {
2294
-                            if($this->stack[$n]->nodeName === $token['name']) {
2295
-                                $n = -1;
2296
-                            }
2293
+						for($n = count($this->stack) - 1; $n >= 0; $n--) {
2294
+							if($this->stack[$n]->nodeName === $token['name']) {
2295
+								$n = -1;
2296
+							}
2297 2297
 
2298
-                            array_pop($this->stack);
2299
-                        }
2300
-                    }
2301
-                break;
2298
+							array_pop($this->stack);
2299
+						}
2300
+					}
2301
+				break;
2302 2302
 
2303
-                /* An end tag whose tag name is one of: "h1", "h2", "h3", "h4",
2303
+				/* An end tag whose tag name is one of: "h1", "h2", "h3", "h4",
2304 2304
                 "h5", "h6" */
2305
-                case 'h1': case 'h2': case 'h3': case 'h4': case 'h5': case 'h6':
2306
-                    $elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6');
2305
+				case 'h1': case 'h2': case 'h3': case 'h4': case 'h5': case 'h6':
2306
+					$elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6');
2307 2307
 
2308
-                    /* If the stack of open elements has in scope an element whose
2308
+					/* If the stack of open elements has in scope an element whose
2309 2309
                     tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6", then
2310 2310
                     generate implied end tags. */
2311
-                    if($this->elementInScope($elements)) {
2312
-                        $this->generateImpliedEndTags();
2311
+					if($this->elementInScope($elements)) {
2312
+						$this->generateImpliedEndTags();
2313 2313
 
2314
-                        /* Now, if the current node is not an element with the same
2314
+						/* Now, if the current node is not an element with the same
2315 2315
                         tag name as that of the token, then this is a parse error. */
2316
-                        // w/e
2316
+						// w/e
2317 2317
 
2318
-                        /* If the stack of open elements has in scope an element
2318
+						/* If the stack of open elements has in scope an element
2319 2319
                         whose tag name is one of "h1", "h2", "h3", "h4", "h5", or
2320 2320
                         "h6", then pop elements from the stack until an element
2321 2321
                         with one of those tag names has been popped from the stack. */
2322
-                        while($this->elementInScope($elements)) {
2323
-                            array_pop($this->stack);
2324
-                        }
2325
-                    }
2326
-                break;
2322
+						while($this->elementInScope($elements)) {
2323
+							array_pop($this->stack);
2324
+						}
2325
+					}
2326
+				break;
2327 2327
 
2328
-                /* An end tag whose tag name is one of: "a", "b", "big", "em",
2328
+				/* An end tag whose tag name is one of: "a", "b", "big", "em",
2329 2329
                 "font", "i", "nobr", "s", "small", "strike", "strong", "tt", "u" */
2330
-                case 'a': case 'b': case 'big': case 'em': case 'font':
2331
-                case 'i': case 'nobr': case 's': case 'small': case 'strike':
2332
-                case 'strong': case 'tt': case 'u':
2333
-                    /* 1. Let the formatting element be the last element in
2330
+				case 'a': case 'b': case 'big': case 'em': case 'font':
2331
+				case 'i': case 'nobr': case 's': case 'small': case 'strike':
2332
+				case 'strong': case 'tt': case 'u':
2333
+					/* 1. Let the formatting element be the last element in
2334 2334
                     the list of active formatting elements that:
2335 2335
                         * is between the end of the list and the last scope
2336 2336
                         marker in the list, if any, or the start of the list
2337 2337
                         otherwise, and
2338 2338
                         * has the same tag name as the token.
2339 2339
                     */
2340
-                    while(true) {
2341
-                        for($a = count($this->a_formatting) - 1; $a >= 0; $a--) {
2342
-                            if($this->a_formatting[$a] === self::MARKER) {
2343
-                                break;
2344
-
2345
-                            } elseif($this->a_formatting[$a]->tagName === $token['name']) {
2346
-                                $formatting_element = $this->a_formatting[$a];
2347
-                                $in_stack = in_array($formatting_element, $this->stack, true);
2348
-                                $fe_af_pos = $a;
2349
-                                break;
2350
-                            }
2351
-                        }
2352
-
2353
-                        /* If there is no such node, or, if that node is
2340
+					while(true) {
2341
+						for($a = count($this->a_formatting) - 1; $a >= 0; $a--) {
2342
+							if($this->a_formatting[$a] === self::MARKER) {
2343
+								break;
2344
+
2345
+							} elseif($this->a_formatting[$a]->tagName === $token['name']) {
2346
+								$formatting_element = $this->a_formatting[$a];
2347
+								$in_stack = in_array($formatting_element, $this->stack, true);
2348
+								$fe_af_pos = $a;
2349
+								break;
2350
+							}
2351
+						}
2352
+
2353
+						/* If there is no such node, or, if that node is
2354 2354
                         also in the stack of open elements but the element
2355 2355
                         is not in scope, then this is a parse error. Abort
2356 2356
                         these steps. The token is ignored. */
2357
-                        if(!isset($formatting_element) || ($in_stack &&
2358
-                        !$this->elementInScope($token['name']))) {
2359
-                            break;
2357
+						if(!isset($formatting_element) || ($in_stack &&
2358
+						!$this->elementInScope($token['name']))) {
2359
+							break;
2360 2360
 
2361
-                        /* Otherwise, if there is such a node, but that node
2361
+						/* Otherwise, if there is such a node, but that node
2362 2362
                         is not in the stack of open elements, then this is a
2363 2363
                         parse error; remove the element from the list, and
2364 2364
                         abort these steps. */
2365
-                        } elseif(isset($formatting_element) && !$in_stack) {
2366
-                            unset($this->a_formatting[$fe_af_pos]);
2367
-                            $this->a_formatting = array_merge($this->a_formatting);
2368
-                            break;
2369
-                        }
2365
+						} elseif(isset($formatting_element) && !$in_stack) {
2366
+							unset($this->a_formatting[$fe_af_pos]);
2367
+							$this->a_formatting = array_merge($this->a_formatting);
2368
+							break;
2369
+						}
2370 2370
 
2371
-                        /* 2. Let the furthest block be the topmost node in the
2371
+						/* 2. Let the furthest block be the topmost node in the
2372 2372
                         stack of open elements that is lower in the stack
2373 2373
                         than the formatting element, and is not an element in
2374 2374
                         the phrasing or formatting categories. There might
2375 2375
                         not be one. */
2376
-                        $fe_s_pos = array_search($formatting_element, $this->stack, true);
2377
-                        $length = count($this->stack);
2376
+						$fe_s_pos = array_search($formatting_element, $this->stack, true);
2377
+						$length = count($this->stack);
2378 2378
 
2379
-                        for($s = $fe_s_pos + 1; $s < $length; $s++) {
2380
-                            $category = $this->getElementCategory($this->stack[$s]->nodeName);
2379
+						for($s = $fe_s_pos + 1; $s < $length; $s++) {
2380
+							$category = $this->getElementCategory($this->stack[$s]->nodeName);
2381 2381
 
2382
-                            if($category !== self::PHRASING && $category !== self::FORMATTING) {
2383
-                                $furthest_block = $this->stack[$s];
2384
-                            }
2385
-                        }
2382
+							if($category !== self::PHRASING && $category !== self::FORMATTING) {
2383
+								$furthest_block = $this->stack[$s];
2384
+							}
2385
+						}
2386 2386
 
2387
-                        /* 3. If there is no furthest block, then the UA must
2387
+						/* 3. If there is no furthest block, then the UA must
2388 2388
                         skip the subsequent steps and instead just pop all
2389 2389
                         the nodes from the bottom of the stack of open
2390 2390
                         elements, from the current node up to the formatting
2391 2391
                         element, and remove the formatting element from the
2392 2392
                         list of active formatting elements. */
2393
-                        if(!isset($furthest_block)) {
2394
-                            for($n = $length - 1; $n >= $fe_s_pos; $n--) {
2395
-                                array_pop($this->stack);
2396
-                            }
2393
+						if(!isset($furthest_block)) {
2394
+							for($n = $length - 1; $n >= $fe_s_pos; $n--) {
2395
+								array_pop($this->stack);
2396
+							}
2397 2397
 
2398
-                            unset($this->a_formatting[$fe_af_pos]);
2399
-                            $this->a_formatting = array_merge($this->a_formatting);
2400
-                            break;
2401
-                        }
2398
+							unset($this->a_formatting[$fe_af_pos]);
2399
+							$this->a_formatting = array_merge($this->a_formatting);
2400
+							break;
2401
+						}
2402 2402
 
2403
-                        /* 4. Let the common ancestor be the element
2403
+						/* 4. Let the common ancestor be the element
2404 2404
                         immediately above the formatting element in the stack
2405 2405
                         of open elements. */
2406
-                        $common_ancestor = $this->stack[$fe_s_pos - 1];
2406
+						$common_ancestor = $this->stack[$fe_s_pos - 1];
2407 2407
 
2408
-                        /* 5. If the furthest block has a parent node, then
2408
+						/* 5. If the furthest block has a parent node, then
2409 2409
                         remove the furthest block from its parent node. */
2410
-                        if($furthest_block->parentNode !== null) {
2411
-                            $furthest_block->parentNode->removeChild($furthest_block);
2412
-                        }
2410
+						if($furthest_block->parentNode !== null) {
2411
+							$furthest_block->parentNode->removeChild($furthest_block);
2412
+						}
2413 2413
 
2414
-                        /* 6. Let a bookmark note the position of the
2414
+						/* 6. Let a bookmark note the position of the
2415 2415
                         formatting element in the list of active formatting
2416 2416
                         elements relative to the elements on either side
2417 2417
                         of it in the list. */
2418
-                        $bookmark = $fe_af_pos;
2418
+						$bookmark = $fe_af_pos;
2419 2419
 
2420
-                        /* 7. Let node and last node  be the furthest block.
2420
+						/* 7. Let node and last node  be the furthest block.
2421 2421
                         Follow these steps: */
2422
-                        $node = $furthest_block;
2423
-                        $last_node = $furthest_block;
2422
+						$node = $furthest_block;
2423
+						$last_node = $furthest_block;
2424 2424
 
2425
-                        while(true) {
2426
-                            for($n = array_search($node, $this->stack, true) - 1; $n >= 0; $n--) {
2427
-                                /* 7.1 Let node be the element immediately
2425
+						while(true) {
2426
+							for($n = array_search($node, $this->stack, true) - 1; $n >= 0; $n--) {
2427
+								/* 7.1 Let node be the element immediately
2428 2428
                                 prior to node in the stack of open elements. */
2429
-                                $node = $this->stack[$n];
2429
+								$node = $this->stack[$n];
2430 2430
 
2431
-                                /* 7.2 If node is not in the list of active
2431
+								/* 7.2 If node is not in the list of active
2432 2432
                                 formatting elements, then remove node from
2433 2433
                                 the stack of open elements and then go back
2434 2434
                                 to step 1. */
2435
-                                if(!in_array($node, $this->a_formatting, true)) {
2436
-                                    unset($this->stack[$n]);
2437
-                                    $this->stack = array_merge($this->stack);
2435
+								if(!in_array($node, $this->a_formatting, true)) {
2436
+									unset($this->stack[$n]);
2437
+									$this->stack = array_merge($this->stack);
2438 2438
 
2439
-                                } else {
2440
-                                    break;
2441
-                                }
2442
-                            }
2439
+								} else {
2440
+									break;
2441
+								}
2442
+							}
2443 2443
 
2444
-                            /* 7.3 Otherwise, if node is the formatting
2444
+							/* 7.3 Otherwise, if node is the formatting
2445 2445
                             element, then go to the next step in the overall
2446 2446
                             algorithm. */
2447
-                            if($node === $formatting_element) {
2448
-                                break;
2447
+							if($node === $formatting_element) {
2448
+								break;
2449 2449
 
2450
-                            /* 7.4 Otherwise, if last node is the furthest
2450
+							/* 7.4 Otherwise, if last node is the furthest
2451 2451
                             block, then move the aforementioned bookmark to
2452 2452
                             be immediately after the node in the list of
2453 2453
                             active formatting elements. */
2454
-                            } elseif($last_node === $furthest_block) {
2455
-                                $bookmark = array_search($node, $this->a_formatting, true) + 1;
2456
-                            }
2454
+							} elseif($last_node === $furthest_block) {
2455
+								$bookmark = array_search($node, $this->a_formatting, true) + 1;
2456
+							}
2457 2457
 
2458
-                            /* 7.5 If node has any children, perform a
2458
+							/* 7.5 If node has any children, perform a
2459 2459
                             shallow clone of node, replace the entry for
2460 2460
                             node in the list of active formatting elements
2461 2461
                             with an entry for the clone, replace the entry
2462 2462
                             for node in the stack of open elements with an
2463 2463
                             entry for the clone, and let node be the clone. */
2464
-                            if($node->hasChildNodes()) {
2465
-                                $clone = $node->cloneNode();
2466
-                                $s_pos = array_search($node, $this->stack, true);
2467
-                                $a_pos = array_search($node, $this->a_formatting, true);
2464
+							if($node->hasChildNodes()) {
2465
+								$clone = $node->cloneNode();
2466
+								$s_pos = array_search($node, $this->stack, true);
2467
+								$a_pos = array_search($node, $this->a_formatting, true);
2468 2468
 
2469
-                                $this->stack[$s_pos] = $clone;
2470
-                                $this->a_formatting[$a_pos] = $clone;
2471
-                                $node = $clone;
2472
-                            }
2469
+								$this->stack[$s_pos] = $clone;
2470
+								$this->a_formatting[$a_pos] = $clone;
2471
+								$node = $clone;
2472
+							}
2473 2473
 
2474
-                            /* 7.6 Insert last node into node, first removing
2474
+							/* 7.6 Insert last node into node, first removing
2475 2475
                             it from its previous parent node if any. */
2476
-                            if($last_node->parentNode !== null) {
2477
-                                $last_node->parentNode->removeChild($last_node);
2478
-                            }
2476
+							if($last_node->parentNode !== null) {
2477
+								$last_node->parentNode->removeChild($last_node);
2478
+							}
2479 2479
 
2480
-                            $node->appendChild($last_node);
2480
+							$node->appendChild($last_node);
2481 2481
 
2482
-                            /* 7.7 Let last node be node. */
2483
-                            $last_node = $node;
2484
-                        }
2482
+							/* 7.7 Let last node be node. */
2483
+							$last_node = $node;
2484
+						}
2485 2485
 
2486
-                        /* 8. Insert whatever last node ended up being in
2486
+						/* 8. Insert whatever last node ended up being in
2487 2487
                         the previous step into the common ancestor node,
2488 2488
                         first removing it from its previous parent node if
2489 2489
                         any. */
2490
-                        if($last_node->parentNode !== null) {
2491
-                            $last_node->parentNode->removeChild($last_node);
2492
-                        }
2490
+						if($last_node->parentNode !== null) {
2491
+							$last_node->parentNode->removeChild($last_node);
2492
+						}
2493 2493
 
2494
-                        $common_ancestor->appendChild($last_node);
2494
+						$common_ancestor->appendChild($last_node);
2495 2495
 
2496
-                        /* 9. Perform a shallow clone of the formatting
2496
+						/* 9. Perform a shallow clone of the formatting
2497 2497
                         element. */
2498
-                        $clone = $formatting_element->cloneNode();
2498
+						$clone = $formatting_element->cloneNode();
2499 2499
 
2500
-                        /* 10. Take all of the child nodes of the furthest
2500
+						/* 10. Take all of the child nodes of the furthest
2501 2501
                         block and append them to the clone created in the
2502 2502
                         last step. */
2503
-                        while($furthest_block->hasChildNodes()) {
2504
-                            $child = $furthest_block->firstChild;
2505
-                            $furthest_block->removeChild($child);
2506
-                            $clone->appendChild($child);
2507
-                        }
2503
+						while($furthest_block->hasChildNodes()) {
2504
+							$child = $furthest_block->firstChild;
2505
+							$furthest_block->removeChild($child);
2506
+							$clone->appendChild($child);
2507
+						}
2508 2508
 
2509
-                        /* 11. Append that clone to the furthest block. */
2510
-                        $furthest_block->appendChild($clone);
2509
+						/* 11. Append that clone to the furthest block. */
2510
+						$furthest_block->appendChild($clone);
2511 2511
 
2512
-                        /* 12. Remove the formatting element from the list
2512
+						/* 12. Remove the formatting element from the list
2513 2513
                         of active formatting elements, and insert the clone
2514 2514
                         into the list of active formatting elements at the
2515 2515
                         position of the aforementioned bookmark. */
2516
-                        $fe_af_pos = array_search($formatting_element, $this->a_formatting, true);
2517
-                        unset($this->a_formatting[$fe_af_pos]);
2518
-                        $this->a_formatting = array_merge($this->a_formatting);
2516
+						$fe_af_pos = array_search($formatting_element, $this->a_formatting, true);
2517
+						unset($this->a_formatting[$fe_af_pos]);
2518
+						$this->a_formatting = array_merge($this->a_formatting);
2519 2519
 
2520
-                        $af_part1 = array_slice($this->a_formatting, 0, $bookmark - 1);
2521
-                        $af_part2 = array_slice($this->a_formatting, $bookmark, count($this->a_formatting));
2522
-                        $this->a_formatting = array_merge($af_part1, array($clone), $af_part2);
2520
+						$af_part1 = array_slice($this->a_formatting, 0, $bookmark - 1);
2521
+						$af_part2 = array_slice($this->a_formatting, $bookmark, count($this->a_formatting));
2522
+						$this->a_formatting = array_merge($af_part1, array($clone), $af_part2);
2523 2523
 
2524
-                        /* 13. Remove the formatting element from the stack
2524
+						/* 13. Remove the formatting element from the stack
2525 2525
                         of open elements, and insert the clone into the stack
2526 2526
                         of open elements immediately after (i.e. in a more
2527 2527
                         deeply nested position than) the position of the
2528 2528
                         furthest block in that stack. */
2529
-                        $fe_s_pos = array_search($formatting_element, $this->stack, true);
2530
-                        $fb_s_pos = array_search($furthest_block, $this->stack, true);
2531
-                        unset($this->stack[$fe_s_pos]);
2529
+						$fe_s_pos = array_search($formatting_element, $this->stack, true);
2530
+						$fb_s_pos = array_search($furthest_block, $this->stack, true);
2531
+						unset($this->stack[$fe_s_pos]);
2532 2532
 
2533
-                        $s_part1 = array_slice($this->stack, 0, $fb_s_pos);
2534
-                        $s_part2 = array_slice($this->stack, $fb_s_pos + 1, count($this->stack));
2535
-                        $this->stack = array_merge($s_part1, array($clone), $s_part2);
2533
+						$s_part1 = array_slice($this->stack, 0, $fb_s_pos);
2534
+						$s_part2 = array_slice($this->stack, $fb_s_pos + 1, count($this->stack));
2535
+						$this->stack = array_merge($s_part1, array($clone), $s_part2);
2536 2536
 
2537
-                        /* 14. Jump back to step 1 in this series of steps. */
2538
-                        unset($formatting_element, $fe_af_pos, $fe_s_pos, $furthest_block);
2539
-                    }
2540
-                break;
2537
+						/* 14. Jump back to step 1 in this series of steps. */
2538
+						unset($formatting_element, $fe_af_pos, $fe_s_pos, $furthest_block);
2539
+					}
2540
+				break;
2541 2541
 
2542
-                /* An end tag token whose tag name is one of: "button",
2542
+				/* An end tag token whose tag name is one of: "button",
2543 2543
                 "marquee", "object" */
2544
-                case 'button': case 'marquee': case 'object':
2545
-                    /* If the stack of open elements has an element in scope whose
2544
+				case 'button': case 'marquee': case 'object':
2545
+					/* If the stack of open elements has an element in scope whose
2546 2546
                     tag name matches the tag name of the token, then generate implied
2547 2547
                     tags. */
2548
-                    if($this->elementInScope($token['name'])) {
2549
-                        $this->generateImpliedEndTags();
2548
+					if($this->elementInScope($token['name'])) {
2549
+						$this->generateImpliedEndTags();
2550 2550
 
2551
-                        /* Now, if the current node is not an element with the same
2551
+						/* Now, if the current node is not an element with the same
2552 2552
                         tag name as the token, then this is a parse error. */
2553
-                        // k
2553
+						// k
2554 2554
 
2555
-                        /* Now, if the stack of open elements has an element in scope
2555
+						/* Now, if the stack of open elements has an element in scope
2556 2556
                         whose tag name matches the tag name of the token, then pop
2557 2557
                         elements from the stack until that element has been popped from
2558 2558
                         the stack, and clear the list of active formatting elements up
2559 2559
                         to the last marker. */
2560
-                        for($n = count($this->stack) - 1; $n >= 0; $n--) {
2561
-                            if($this->stack[$n]->nodeName === $token['name']) {
2562
-                                $n = -1;
2563
-                            }
2560
+						for($n = count($this->stack) - 1; $n >= 0; $n--) {
2561
+							if($this->stack[$n]->nodeName === $token['name']) {
2562
+								$n = -1;
2563
+							}
2564 2564
 
2565
-                            array_pop($this->stack);
2566
-                        }
2565
+							array_pop($this->stack);
2566
+						}
2567 2567
 
2568
-                        $marker = end(array_keys($this->a_formatting, self::MARKER, true));
2568
+						$marker = end(array_keys($this->a_formatting, self::MARKER, true));
2569 2569
 
2570
-                        for($n = count($this->a_formatting) - 1; $n > $marker; $n--) {
2571
-                            array_pop($this->a_formatting);
2572
-                        }
2573
-                    }
2574
-                break;
2570
+						for($n = count($this->a_formatting) - 1; $n > $marker; $n--) {
2571
+							array_pop($this->a_formatting);
2572
+						}
2573
+					}
2574
+				break;
2575 2575
 
2576
-                /* Or an end tag whose tag name is one of: "area", "basefont",
2576
+				/* Or an end tag whose tag name is one of: "area", "basefont",
2577 2577
                 "bgsound", "br", "embed", "hr", "iframe", "image", "img",
2578 2578
                 "input", "isindex", "noembed", "noframes", "param", "select",
2579 2579
                 "spacer", "table", "textarea", "wbr" */
2580
-                case 'area': case 'basefont': case 'bgsound': case 'br':
2581
-                case 'embed': case 'hr': case 'iframe': case 'image':
2582
-                case 'img': case 'input': case 'isindex': case 'noembed':
2583
-                case 'noframes': case 'param': case 'select': case 'spacer':
2584
-                case 'table': case 'textarea': case 'wbr':
2585
-                    // Parse error. Ignore the token.
2586
-                break;
2587
-
2588
-                /* An end tag token not covered by the previous entries */
2589
-                default:
2590
-                    for($n = count($this->stack) - 1; $n >= 0; $n--) {
2591
-                        /* Initialise node to be the current node (the bottommost
2580
+				case 'area': case 'basefont': case 'bgsound': case 'br':
2581
+				case 'embed': case 'hr': case 'iframe': case 'image':
2582
+				case 'img': case 'input': case 'isindex': case 'noembed':
2583
+				case 'noframes': case 'param': case 'select': case 'spacer':
2584
+				case 'table': case 'textarea': case 'wbr':
2585
+					// Parse error. Ignore the token.
2586
+				break;
2587
+
2588
+				/* An end tag token not covered by the previous entries */
2589
+				default:
2590
+					for($n = count($this->stack) - 1; $n >= 0; $n--) {
2591
+						/* Initialise node to be the current node (the bottommost
2592 2592
                         node of the stack). */
2593
-                        $node = end($this->stack);
2593
+						$node = end($this->stack);
2594 2594
 
2595
-                        /* If node has the same tag name as the end tag token,
2595
+						/* If node has the same tag name as the end tag token,
2596 2596
                         then: */
2597
-                        if($token['name'] === $node->nodeName) {
2598
-                            /* Generate implied end tags. */
2599
-                            $this->generateImpliedEndTags();
2597
+						if($token['name'] === $node->nodeName) {
2598
+							/* Generate implied end tags. */
2599
+							$this->generateImpliedEndTags();
2600 2600
 
2601
-                            /* If the tag name of the end tag token does not
2601
+							/* If the tag name of the end tag token does not
2602 2602
                             match the tag name of the current node, this is a
2603 2603
                             parse error. */
2604
-                            // k
2604
+							// k
2605 2605
 
2606
-                            /* Pop all the nodes from the current node up to
2606
+							/* Pop all the nodes from the current node up to
2607 2607
                             node, including node, then stop this algorithm. */
2608
-                            for($x = count($this->stack) - $n; $x >= $n; $x--) {
2609
-                                array_pop($this->stack);
2610
-                            }
2608
+							for($x = count($this->stack) - $n; $x >= $n; $x--) {
2609
+								array_pop($this->stack);
2610
+							}
2611 2611
                                     
2612
-                        } else {
2613
-                            $category = $this->getElementCategory($node);
2612
+						} else {
2613
+							$category = $this->getElementCategory($node);
2614 2614
 
2615
-                            if($category !== self::SPECIAL && $category !== self::SCOPING) {
2616
-                                /* Otherwise, if node is in neither the formatting
2615
+							if($category !== self::SPECIAL && $category !== self::SCOPING) {
2616
+								/* Otherwise, if node is in neither the formatting
2617 2617
                                 category nor the phrasing category, then this is a
2618 2618
                                 parse error. Stop this algorithm. The end tag token
2619 2619
                                 is ignored. */
2620
-                                return false;
2621
-                            }
2622
-                        }
2623
-                    }
2624
-                break;
2625
-            }
2626
-            break;
2627
-        }
2628
-    }
2629
-
2630
-    private function inTable($token) {
2631
-        $clear = array('html', 'table');
2632
-
2633
-        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
2620
+								return false;
2621
+							}
2622
+						}
2623
+					}
2624
+				break;
2625
+			}
2626
+			break;
2627
+		}
2628
+	}
2629
+
2630
+	private function inTable($token) {
2631
+		$clear = array('html', 'table');
2632
+
2633
+		/* A character token that is one of one of U+0009 CHARACTER TABULATION,
2634 2634
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
2635 2635
         or U+0020 SPACE */
2636
-        if($token['type'] === HTML5::CHARACTR &&
2637
-        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
2638
-            /* Append the character to the current node. */
2639
-            $text = $this->dom->createTextNode($token['data']);
2640
-            end($this->stack)->appendChild($text);
2641
-
2642
-        /* A comment token */
2643
-        } elseif($token['type'] === HTML5::COMMENT) {
2644
-            /* Append a Comment node to the current node with the data
2636
+		if($token['type'] === HTML5::CHARACTR &&
2637
+		preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
2638
+			/* Append the character to the current node. */
2639
+			$text = $this->dom->createTextNode($token['data']);
2640
+			end($this->stack)->appendChild($text);
2641
+
2642
+		/* A comment token */
2643
+		} elseif($token['type'] === HTML5::COMMENT) {
2644
+			/* Append a Comment node to the current node with the data
2645 2645
             attribute set to the data given in the comment token. */
2646
-            $comment = $this->dom->createComment($token['data']);
2647
-            end($this->stack)->appendChild($comment);
2646
+			$comment = $this->dom->createComment($token['data']);
2647
+			end($this->stack)->appendChild($comment);
2648 2648
 
2649
-        /* A start tag whose tag name is "caption" */
2650
-        } elseif($token['type'] === HTML5::STARTTAG &&
2651
-        $token['name'] === 'caption') {
2652
-            /* Clear the stack back to a table context. */
2653
-            $this->clearStackToTableContext($clear);
2649
+		/* A start tag whose tag name is "caption" */
2650
+		} elseif($token['type'] === HTML5::STARTTAG &&
2651
+		$token['name'] === 'caption') {
2652
+			/* Clear the stack back to a table context. */
2653
+			$this->clearStackToTableContext($clear);
2654 2654
 
2655
-            /* Insert a marker at the end of the list of active
2655
+			/* Insert a marker at the end of the list of active
2656 2656
             formatting elements. */
2657
-            $this->a_formatting[] = self::MARKER;
2657
+			$this->a_formatting[] = self::MARKER;
2658 2658
 
2659
-            /* Insert an HTML element for the token, then switch the
2659
+			/* Insert an HTML element for the token, then switch the
2660 2660
             insertion mode to "in caption". */
2661
-            $this->insertElement($token);
2662
-            $this->mode = self::IN_CAPTION;
2661
+			$this->insertElement($token);
2662
+			$this->mode = self::IN_CAPTION;
2663 2663
 
2664
-        /* A start tag whose tag name is "colgroup" */
2665
-        } elseif($token['type'] === HTML5::STARTTAG &&
2666
-        $token['name'] === 'colgroup') {
2667
-            /* Clear the stack back to a table context. */
2668
-            $this->clearStackToTableContext($clear);
2664
+		/* A start tag whose tag name is "colgroup" */
2665
+		} elseif($token['type'] === HTML5::STARTTAG &&
2666
+		$token['name'] === 'colgroup') {
2667
+			/* Clear the stack back to a table context. */
2668
+			$this->clearStackToTableContext($clear);
2669 2669
 
2670
-            /* Insert an HTML element for the token, then switch the
2670
+			/* Insert an HTML element for the token, then switch the
2671 2671
             insertion mode to "in column group". */
2672
-            $this->insertElement($token);
2673
-            $this->mode = self::IN_CGROUP;
2674
-
2675
-        /* A start tag whose tag name is "col" */
2676
-        } elseif($token['type'] === HTML5::STARTTAG &&
2677
-        $token['name'] === 'col') {
2678
-            $this->inTable(array(
2679
-                'name' => 'colgroup',
2680
-                'type' => HTML5::STARTTAG,
2681
-                'attr' => array()
2682
-            ));
2683
-
2684
-            $this->inColumnGroup($token);
2685
-
2686
-        /* A start tag whose tag name is one of: "tbody", "tfoot", "thead" */
2687
-        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
2688
-        array('tbody', 'tfoot', 'thead'))) {
2689
-            /* Clear the stack back to a table context. */
2690
-            $this->clearStackToTableContext($clear);
2691
-
2692
-            /* Insert an HTML element for the token, then switch the insertion
2672
+			$this->insertElement($token);
2673
+			$this->mode = self::IN_CGROUP;
2674
+
2675
+		/* A start tag whose tag name is "col" */
2676
+		} elseif($token['type'] === HTML5::STARTTAG &&
2677
+		$token['name'] === 'col') {
2678
+			$this->inTable(array(
2679
+				'name' => 'colgroup',
2680
+				'type' => HTML5::STARTTAG,
2681
+				'attr' => array()
2682
+			));
2683
+
2684
+			$this->inColumnGroup($token);
2685
+
2686
+		/* A start tag whose tag name is one of: "tbody", "tfoot", "thead" */
2687
+		} elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
2688
+		array('tbody', 'tfoot', 'thead'))) {
2689
+			/* Clear the stack back to a table context. */
2690
+			$this->clearStackToTableContext($clear);
2691
+
2692
+			/* Insert an HTML element for the token, then switch the insertion
2693 2693
             mode to "in table body". */
2694
-            $this->insertElement($token);
2695
-            $this->mode = self::IN_TBODY;
2694
+			$this->insertElement($token);
2695
+			$this->mode = self::IN_TBODY;
2696 2696
 
2697
-        /* A start tag whose tag name is one of: "td", "th", "tr" */
2698
-        } elseif($token['type'] === HTML5::STARTTAG &&
2699
-        in_array($token['name'], array('td', 'th', 'tr'))) {
2700
-            /* Act as if a start tag token with the tag name "tbody" had been
2697
+		/* A start tag whose tag name is one of: "td", "th", "tr" */
2698
+		} elseif($token['type'] === HTML5::STARTTAG &&
2699
+		in_array($token['name'], array('td', 'th', 'tr'))) {
2700
+			/* Act as if a start tag token with the tag name "tbody" had been
2701 2701
             seen, then reprocess the current token. */
2702
-            $this->inTable(array(
2703
-                'name' => 'tbody',
2704
-                'type' => HTML5::STARTTAG,
2705
-                'attr' => array()
2706
-            ));
2707
-
2708
-            return $this->inTableBody($token);
2709
-
2710
-        /* A start tag whose tag name is "table" */
2711
-        } elseif($token['type'] === HTML5::STARTTAG &&
2712
-        $token['name'] === 'table') {
2713
-            /* Parse error. Act as if an end tag token with the tag name "table"
2702
+			$this->inTable(array(
2703
+				'name' => 'tbody',
2704
+				'type' => HTML5::STARTTAG,
2705
+				'attr' => array()
2706
+			));
2707
+
2708
+			return $this->inTableBody($token);
2709
+
2710
+		/* A start tag whose tag name is "table" */
2711
+		} elseif($token['type'] === HTML5::STARTTAG &&
2712
+		$token['name'] === 'table') {
2713
+			/* Parse error. Act as if an end tag token with the tag name "table"
2714 2714
             had been seen, then, if that token wasn't ignored, reprocess the
2715 2715
             current token. */
2716
-            $this->inTable(array(
2717
-                'name' => 'table',
2718
-                'type' => HTML5::ENDTAG
2719
-            ));
2716
+			$this->inTable(array(
2717
+				'name' => 'table',
2718
+				'type' => HTML5::ENDTAG
2719
+			));
2720 2720
 
2721
-            return $this->mainPhase($token);
2721
+			return $this->mainPhase($token);
2722 2722
 
2723
-        /* An end tag whose tag name is "table" */
2724
-        } elseif($token['type'] === HTML5::ENDTAG &&
2725
-        $token['name'] === 'table') {
2726
-            /* If the stack of open elements does not have an element in table
2723
+		/* An end tag whose tag name is "table" */
2724
+		} elseif($token['type'] === HTML5::ENDTAG &&
2725
+		$token['name'] === 'table') {
2726
+			/* If the stack of open elements does not have an element in table
2727 2727
             scope with the same tag name as the token, this is a parse error.
2728 2728
             Ignore the token. (innerHTML case) */
2729
-            if(!$this->elementInScope($token['name'], true)) {
2730
-                return false;
2729
+			if(!$this->elementInScope($token['name'], true)) {
2730
+				return false;
2731 2731
 
2732
-            /* Otherwise: */
2733
-            } else {
2734
-                /* Generate implied end tags. */
2735
-                $this->generateImpliedEndTags();
2732
+			/* Otherwise: */
2733
+			} else {
2734
+				/* Generate implied end tags. */
2735
+				$this->generateImpliedEndTags();
2736 2736
 
2737
-                /* Now, if the current node is not a table element, then this
2737
+				/* Now, if the current node is not a table element, then this
2738 2738
                 is a parse error. */
2739
-                // w/e
2739
+				// w/e
2740 2740
 
2741
-                /* Pop elements from this stack until a table element has been
2741
+				/* Pop elements from this stack until a table element has been
2742 2742
                 popped from the stack. */
2743
-                while(true) {
2744
-                    $current = end($this->stack)->nodeName;
2745
-                    array_pop($this->stack);
2743
+				while(true) {
2744
+					$current = end($this->stack)->nodeName;
2745
+					array_pop($this->stack);
2746 2746
 
2747
-                    if($current === 'table') {
2748
-                        break;
2749
-                    }
2750
-                }
2747
+					if($current === 'table') {
2748
+						break;
2749
+					}
2750
+				}
2751 2751
 
2752
-                /* Reset the insertion mode appropriately. */
2753
-                $this->resetInsertionMode();
2754
-            }
2752
+				/* Reset the insertion mode appropriately. */
2753
+				$this->resetInsertionMode();
2754
+			}
2755 2755
 
2756
-        /* An end tag whose tag name is one of: "body", "caption", "col",
2756
+		/* An end tag whose tag name is one of: "body", "caption", "col",
2757 2757
         "colgroup", "html", "tbody", "td", "tfoot", "th", "thead", "tr" */
2758
-        } elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
2759
-        array('body', 'caption', 'col', 'colgroup', 'html', 'tbody', 'td',
2760
-        'tfoot', 'th', 'thead', 'tr'))) {
2761
-            // Parse error. Ignore the token.
2762
-
2763
-        /* Anything else */
2764
-        } else {
2765
-            /* Parse error. Process the token as if the insertion mode was "in
2758
+		} elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
2759
+		array('body', 'caption', 'col', 'colgroup', 'html', 'tbody', 'td',
2760
+		'tfoot', 'th', 'thead', 'tr'))) {
2761
+			// Parse error. Ignore the token.
2762
+
2763
+		/* Anything else */
2764
+		} else {
2765
+			/* Parse error. Process the token as if the insertion mode was "in
2766 2766
             body", with the following exception: */
2767 2767
 
2768
-            /* If the current node is a table, tbody, tfoot, thead, or tr
2768
+			/* If the current node is a table, tbody, tfoot, thead, or tr
2769 2769
             element, then, whenever a node would be inserted into the current
2770 2770
             node, it must instead be inserted into the foster parent element. */
2771
-            if(in_array(end($this->stack)->nodeName,
2772
-            array('table', 'tbody', 'tfoot', 'thead', 'tr'))) {
2773
-                /* The foster parent element is the parent element of the last
2771
+			if(in_array(end($this->stack)->nodeName,
2772
+			array('table', 'tbody', 'tfoot', 'thead', 'tr'))) {
2773
+				/* The foster parent element is the parent element of the last
2774 2774
                 table element in the stack of open elements, if there is a
2775 2775
                 table element and it has such a parent element. If there is no
2776 2776
                 table element in the stack of open elements (innerHTML case),
@@ -2781,1124 +2781,1124 @@  discard block
 block discarded – undo
2781 2781
                 its parent node is not an element, then the foster parent
2782 2782
                 element is the element before the last table element in the
2783 2783
                 stack of open elements. */
2784
-                for($n = count($this->stack) - 1; $n >= 0; $n--) {
2785
-                    if($this->stack[$n]->nodeName === 'table') {
2786
-                        $table = $this->stack[$n];
2787
-                        break;
2788
-                    }
2789
-                }
2790
-
2791
-                if(isset($table) && $table->parentNode !== null) {
2792
-                    $this->foster_parent = $table->parentNode;
2793
-
2794
-                } elseif(!isset($table)) {
2795
-                    $this->foster_parent = $this->stack[0];
2796
-
2797
-                } elseif(isset($table) && ($table->parentNode === null ||
2798
-                $table->parentNode->nodeType !== XML_ELEMENT_NODE)) {
2799
-                    $this->foster_parent = $this->stack[$n - 1];
2800
-                }
2801
-            }
2802
-
2803
-            $this->inBody($token);
2804
-        }
2805
-    }
2806
-
2807
-    private function inCaption($token) {
2808
-        /* An end tag whose tag name is "caption" */
2809
-        if($token['type'] === HTML5::ENDTAG && $token['name'] === 'caption') {
2810
-            /* If the stack of open elements does not have an element in table
2784
+				for($n = count($this->stack) - 1; $n >= 0; $n--) {
2785
+					if($this->stack[$n]->nodeName === 'table') {
2786
+						$table = $this->stack[$n];
2787
+						break;
2788
+					}
2789
+				}
2790
+
2791
+				if(isset($table) && $table->parentNode !== null) {
2792
+					$this->foster_parent = $table->parentNode;
2793
+
2794
+				} elseif(!isset($table)) {
2795
+					$this->foster_parent = $this->stack[0];
2796
+
2797
+				} elseif(isset($table) && ($table->parentNode === null ||
2798
+				$table->parentNode->nodeType !== XML_ELEMENT_NODE)) {
2799
+					$this->foster_parent = $this->stack[$n - 1];
2800
+				}
2801
+			}
2802
+
2803
+			$this->inBody($token);
2804
+		}
2805
+	}
2806
+
2807
+	private function inCaption($token) {
2808
+		/* An end tag whose tag name is "caption" */
2809
+		if($token['type'] === HTML5::ENDTAG && $token['name'] === 'caption') {
2810
+			/* If the stack of open elements does not have an element in table
2811 2811
             scope with the same tag name as the token, this is a parse error.
2812 2812
             Ignore the token. (innerHTML case) */
2813
-            if(!$this->elementInScope($token['name'], true)) {
2814
-                // Ignore
2813
+			if(!$this->elementInScope($token['name'], true)) {
2814
+				// Ignore
2815 2815
 
2816
-            /* Otherwise: */
2817
-            } else {
2818
-                /* Generate implied end tags. */
2819
-                $this->generateImpliedEndTags();
2816
+			/* Otherwise: */
2817
+			} else {
2818
+				/* Generate implied end tags. */
2819
+				$this->generateImpliedEndTags();
2820 2820
 
2821
-                /* Now, if the current node is not a caption element, then this
2821
+				/* Now, if the current node is not a caption element, then this
2822 2822
                 is a parse error. */
2823
-                // w/e
2823
+				// w/e
2824 2824
 
2825
-                /* Pop elements from this stack until a caption element has
2825
+				/* Pop elements from this stack until a caption element has
2826 2826
                 been popped from the stack. */
2827
-                while(true) {
2828
-                    $node = end($this->stack)->nodeName;
2829
-                    array_pop($this->stack);
2827
+				while(true) {
2828
+					$node = end($this->stack)->nodeName;
2829
+					array_pop($this->stack);
2830 2830
 
2831
-                    if($node === 'caption') {
2832
-                        break;
2833
-                    }
2834
-                }
2831
+					if($node === 'caption') {
2832
+						break;
2833
+					}
2834
+				}
2835 2835
 
2836
-                /* Clear the list of active formatting elements up to the last
2836
+				/* Clear the list of active formatting elements up to the last
2837 2837
                 marker. */
2838
-                $this->clearTheActiveFormattingElementsUpToTheLastMarker();
2838
+				$this->clearTheActiveFormattingElementsUpToTheLastMarker();
2839 2839
 
2840
-                /* Switch the insertion mode to "in table". */
2841
-                $this->mode = self::IN_TABLE;
2842
-            }
2840
+				/* Switch the insertion mode to "in table". */
2841
+				$this->mode = self::IN_TABLE;
2842
+			}
2843 2843
 
2844
-        /* A start tag whose tag name is one of: "caption", "col", "colgroup",
2844
+		/* A start tag whose tag name is one of: "caption", "col", "colgroup",
2845 2845
         "tbody", "td", "tfoot", "th", "thead", "tr", or an end tag whose tag
2846 2846
         name is "table" */
2847
-        } elseif(($token['type'] === HTML5::STARTTAG && in_array($token['name'],
2848
-        array('caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
2849
-        'thead', 'tr'))) || ($token['type'] === HTML5::ENDTAG &&
2850
-        $token['name'] === 'table')) {
2851
-            /* Parse error. Act as if an end tag with the tag name "caption"
2847
+		} elseif(($token['type'] === HTML5::STARTTAG && in_array($token['name'],
2848
+		array('caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
2849
+		'thead', 'tr'))) || ($token['type'] === HTML5::ENDTAG &&
2850
+		$token['name'] === 'table')) {
2851
+			/* Parse error. Act as if an end tag with the tag name "caption"
2852 2852
             had been seen, then, if that token wasn't ignored, reprocess the
2853 2853
             current token. */
2854
-            $this->inCaption(array(
2855
-                'name' => 'caption',
2856
-                'type' => HTML5::ENDTAG
2857
-            ));
2854
+			$this->inCaption(array(
2855
+				'name' => 'caption',
2856
+				'type' => HTML5::ENDTAG
2857
+			));
2858 2858
 
2859
-            return $this->inTable($token);
2859
+			return $this->inTable($token);
2860 2860
 
2861
-        /* An end tag whose tag name is one of: "body", "col", "colgroup",
2861
+		/* An end tag whose tag name is one of: "body", "col", "colgroup",
2862 2862
         "html", "tbody", "td", "tfoot", "th", "thead", "tr" */
2863
-        } elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
2864
-        array('body', 'col', 'colgroup', 'html', 'tbody', 'tfoot', 'th',
2865
-        'thead', 'tr'))) {
2866
-            // Parse error. Ignore the token.
2867
-
2868
-        /* Anything else */
2869
-        } else {
2870
-            /* Process the token as if the insertion mode was "in body". */
2871
-            $this->inBody($token);
2872
-        }
2873
-    }
2874
-
2875
-    private function inColumnGroup($token) {
2876
-        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
2863
+		} elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
2864
+		array('body', 'col', 'colgroup', 'html', 'tbody', 'tfoot', 'th',
2865
+		'thead', 'tr'))) {
2866
+			// Parse error. Ignore the token.
2867
+
2868
+		/* Anything else */
2869
+		} else {
2870
+			/* Process the token as if the insertion mode was "in body". */
2871
+			$this->inBody($token);
2872
+		}
2873
+	}
2874
+
2875
+	private function inColumnGroup($token) {
2876
+		/* A character token that is one of one of U+0009 CHARACTER TABULATION,
2877 2877
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
2878 2878
         or U+0020 SPACE */
2879
-        if($token['type'] === HTML5::CHARACTR &&
2880
-        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
2881
-            /* Append the character to the current node. */
2882
-            $text = $this->dom->createTextNode($token['data']);
2883
-            end($this->stack)->appendChild($text);
2884
-
2885
-        /* A comment token */
2886
-        } elseif($token['type'] === HTML5::COMMENT) {
2887
-            /* Append a Comment node to the current node with the data
2879
+		if($token['type'] === HTML5::CHARACTR &&
2880
+		preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
2881
+			/* Append the character to the current node. */
2882
+			$text = $this->dom->createTextNode($token['data']);
2883
+			end($this->stack)->appendChild($text);
2884
+
2885
+		/* A comment token */
2886
+		} elseif($token['type'] === HTML5::COMMENT) {
2887
+			/* Append a Comment node to the current node with the data
2888 2888
             attribute set to the data given in the comment token. */
2889
-            $comment = $this->dom->createComment($token['data']);
2890
-            end($this->stack)->appendChild($comment);
2889
+			$comment = $this->dom->createComment($token['data']);
2890
+			end($this->stack)->appendChild($comment);
2891 2891
 
2892
-        /* A start tag whose tag name is "col" */
2893
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'col') {
2894
-            /* Insert a col element for the token. Immediately pop the current
2892
+		/* A start tag whose tag name is "col" */
2893
+		} elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'col') {
2894
+			/* Insert a col element for the token. Immediately pop the current
2895 2895
             node off the stack of open elements. */
2896
-            $this->insertElement($token);
2897
-            array_pop($this->stack);
2896
+			$this->insertElement($token);
2897
+			array_pop($this->stack);
2898 2898
 
2899
-        /* An end tag whose tag name is "colgroup" */
2900
-        } elseif($token['type'] === HTML5::ENDTAG &&
2901
-        $token['name'] === 'colgroup') {
2902
-            /* If the current node is the root html element, then this is a
2899
+		/* An end tag whose tag name is "colgroup" */
2900
+		} elseif($token['type'] === HTML5::ENDTAG &&
2901
+		$token['name'] === 'colgroup') {
2902
+			/* If the current node is the root html element, then this is a
2903 2903
             parse error, ignore the token. (innerHTML case) */
2904
-            if(end($this->stack)->nodeName === 'html') {
2905
-                // Ignore
2904
+			if(end($this->stack)->nodeName === 'html') {
2905
+				// Ignore
2906 2906
 
2907
-            /* Otherwise, pop the current node (which will be a colgroup
2907
+			/* Otherwise, pop the current node (which will be a colgroup
2908 2908
             element) from the stack of open elements. Switch the insertion
2909 2909
             mode to "in table". */
2910
-            } else {
2911
-                array_pop($this->stack);
2912
-                $this->mode = self::IN_TABLE;
2913
-            }
2914
-
2915
-        /* An end tag whose tag name is "col" */
2916
-        } elseif($token['type'] === HTML5::ENDTAG && $token['name'] === 'col') {
2917
-            /* Parse error. Ignore the token. */
2918
-
2919
-        /* Anything else */
2920
-        } else {
2921
-            /* Act as if an end tag with the tag name "colgroup" had been seen,
2910
+			} else {
2911
+				array_pop($this->stack);
2912
+				$this->mode = self::IN_TABLE;
2913
+			}
2914
+
2915
+		/* An end tag whose tag name is "col" */
2916
+		} elseif($token['type'] === HTML5::ENDTAG && $token['name'] === 'col') {
2917
+			/* Parse error. Ignore the token. */
2918
+
2919
+		/* Anything else */
2920
+		} else {
2921
+			/* Act as if an end tag with the tag name "colgroup" had been seen,
2922 2922
             and then, if that token wasn't ignored, reprocess the current token. */
2923
-            $this->inColumnGroup(array(
2924
-                'name' => 'colgroup',
2925
-                'type' => HTML5::ENDTAG
2926
-            ));
2923
+			$this->inColumnGroup(array(
2924
+				'name' => 'colgroup',
2925
+				'type' => HTML5::ENDTAG
2926
+			));
2927 2927
 
2928
-            return $this->inTable($token);
2929
-        }
2930
-    }
2928
+			return $this->inTable($token);
2929
+		}
2930
+	}
2931 2931
 
2932
-    private function inTableBody($token) {
2933
-        $clear = array('tbody', 'tfoot', 'thead', 'html');
2932
+	private function inTableBody($token) {
2933
+		$clear = array('tbody', 'tfoot', 'thead', 'html');
2934 2934
 
2935
-        /* A start tag whose tag name is "tr" */
2936
-        if($token['type'] === HTML5::STARTTAG && $token['name'] === 'tr') {
2937
-            /* Clear the stack back to a table body context. */
2938
-            $this->clearStackToTableContext($clear);
2935
+		/* A start tag whose tag name is "tr" */
2936
+		if($token['type'] === HTML5::STARTTAG && $token['name'] === 'tr') {
2937
+			/* Clear the stack back to a table body context. */
2938
+			$this->clearStackToTableContext($clear);
2939 2939
 
2940
-            /* Insert a tr element for the token, then switch the insertion
2940
+			/* Insert a tr element for the token, then switch the insertion
2941 2941
             mode to "in row". */
2942
-            $this->insertElement($token);
2943
-            $this->mode = self::IN_ROW;
2942
+			$this->insertElement($token);
2943
+			$this->mode = self::IN_ROW;
2944 2944
 
2945
-        /* A start tag whose tag name is one of: "th", "td" */
2946
-        } elseif($token['type'] === HTML5::STARTTAG &&
2947
-        ($token['name'] === 'th' ||    $token['name'] === 'td')) {
2948
-            /* Parse error. Act as if a start tag with the tag name "tr" had
2945
+		/* A start tag whose tag name is one of: "th", "td" */
2946
+		} elseif($token['type'] === HTML5::STARTTAG &&
2947
+		($token['name'] === 'th' ||    $token['name'] === 'td')) {
2948
+			/* Parse error. Act as if a start tag with the tag name "tr" had
2949 2949
             been seen, then reprocess the current token. */
2950
-            $this->inTableBody(array(
2951
-                'name' => 'tr',
2952
-                'type' => HTML5::STARTTAG,
2953
-                'attr' => array()
2954
-            ));
2955
-
2956
-            return $this->inRow($token);
2957
-
2958
-        /* An end tag whose tag name is one of: "tbody", "tfoot", "thead" */
2959
-        } elseif($token['type'] === HTML5::ENDTAG &&
2960
-        in_array($token['name'], array('tbody', 'tfoot', 'thead'))) {
2961
-            /* If the stack of open elements does not have an element in table
2950
+			$this->inTableBody(array(
2951
+				'name' => 'tr',
2952
+				'type' => HTML5::STARTTAG,
2953
+				'attr' => array()
2954
+			));
2955
+
2956
+			return $this->inRow($token);
2957
+
2958
+		/* An end tag whose tag name is one of: "tbody", "tfoot", "thead" */
2959
+		} elseif($token['type'] === HTML5::ENDTAG &&
2960
+		in_array($token['name'], array('tbody', 'tfoot', 'thead'))) {
2961
+			/* If the stack of open elements does not have an element in table
2962 2962
             scope with the same tag name as the token, this is a parse error.
2963 2963
             Ignore the token. */
2964
-            if(!$this->elementInScope($token['name'], true)) {
2965
-                // Ignore
2964
+			if(!$this->elementInScope($token['name'], true)) {
2965
+				// Ignore
2966 2966
 
2967
-            /* Otherwise: */
2968
-            } else {
2969
-                /* Clear the stack back to a table body context. */
2970
-                $this->clearStackToTableContext($clear);
2967
+			/* Otherwise: */
2968
+			} else {
2969
+				/* Clear the stack back to a table body context. */
2970
+				$this->clearStackToTableContext($clear);
2971 2971
 
2972
-                /* Pop the current node from the stack of open elements. Switch
2972
+				/* Pop the current node from the stack of open elements. Switch
2973 2973
                 the insertion mode to "in table". */
2974
-                array_pop($this->stack);
2975
-                $this->mode = self::IN_TABLE;
2976
-            }
2974
+				array_pop($this->stack);
2975
+				$this->mode = self::IN_TABLE;
2976
+			}
2977 2977
 
2978
-        /* A start tag whose tag name is one of: "caption", "col", "colgroup",
2978
+		/* A start tag whose tag name is one of: "caption", "col", "colgroup",
2979 2979
         "tbody", "tfoot", "thead", or an end tag whose tag name is "table" */
2980
-        } elseif(($token['type'] === HTML5::STARTTAG && in_array($token['name'],
2981
-        array('caption', 'col', 'colgroup', 'tbody', 'tfoor', 'thead'))) ||
2982
-        ($token['type'] === HTML5::STARTTAG && $token['name'] === 'table')) {
2983
-            /* If the stack of open elements does not have a tbody, thead, or
2980
+		} elseif(($token['type'] === HTML5::STARTTAG && in_array($token['name'],
2981
+		array('caption', 'col', 'colgroup', 'tbody', 'tfoor', 'thead'))) ||
2982
+		($token['type'] === HTML5::STARTTAG && $token['name'] === 'table')) {
2983
+			/* If the stack of open elements does not have a tbody, thead, or
2984 2984
             tfoot element in table scope, this is a parse error. Ignore the
2985 2985
             token. (innerHTML case) */
2986
-            if(!$this->elementInScope(array('tbody', 'thead', 'tfoot'), true)) {
2987
-                // Ignore.
2986
+			if(!$this->elementInScope(array('tbody', 'thead', 'tfoot'), true)) {
2987
+				// Ignore.
2988 2988
 
2989
-            /* Otherwise: */
2990
-            } else {
2991
-                /* Clear the stack back to a table body context. */
2992
-                $this->clearStackToTableContext($clear);
2989
+			/* Otherwise: */
2990
+			} else {
2991
+				/* Clear the stack back to a table body context. */
2992
+				$this->clearStackToTableContext($clear);
2993 2993
 
2994
-                /* Act as if an end tag with the same tag name as the current
2994
+				/* Act as if an end tag with the same tag name as the current
2995 2995
                 node ("tbody", "tfoot", or "thead") had been seen, then
2996 2996
                 reprocess the current token. */
2997
-                $this->inTableBody(array(
2998
-                    'name' => end($this->stack)->nodeName,
2999
-                    'type' => HTML5::ENDTAG
3000
-                ));
2997
+				$this->inTableBody(array(
2998
+					'name' => end($this->stack)->nodeName,
2999
+					'type' => HTML5::ENDTAG
3000
+				));
3001 3001
 
3002
-                return $this->mainPhase($token);
3003
-            }
3002
+				return $this->mainPhase($token);
3003
+			}
3004 3004
 
3005
-        /* An end tag whose tag name is one of: "body", "caption", "col",
3005
+		/* An end tag whose tag name is one of: "body", "caption", "col",
3006 3006
         "colgroup", "html", "td", "th", "tr" */
3007
-        } elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3008
-        array('body', 'caption', 'col', 'colgroup', 'html', 'td', 'th', 'tr'))) {
3009
-            /* Parse error. Ignore the token. */
3010
-
3011
-        /* Anything else */
3012
-        } else {
3013
-            /* Process the token as if the insertion mode was "in table". */
3014
-            $this->inTable($token);
3015
-        }
3016
-    }
3017
-
3018
-    private function inRow($token) {
3019
-        $clear = array('tr', 'html');
3020
-
3021
-        /* A start tag whose tag name is one of: "th", "td" */
3022
-        if($token['type'] === HTML5::STARTTAG &&
3023
-        ($token['name'] === 'th' || $token['name'] === 'td')) {
3024
-            /* Clear the stack back to a table row context. */
3025
-            $this->clearStackToTableContext($clear);
3026
-
3027
-            /* Insert an HTML element for the token, then switch the insertion
3007
+		} elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3008
+		array('body', 'caption', 'col', 'colgroup', 'html', 'td', 'th', 'tr'))) {
3009
+			/* Parse error. Ignore the token. */
3010
+
3011
+		/* Anything else */
3012
+		} else {
3013
+			/* Process the token as if the insertion mode was "in table". */
3014
+			$this->inTable($token);
3015
+		}
3016
+	}
3017
+
3018
+	private function inRow($token) {
3019
+		$clear = array('tr', 'html');
3020
+
3021
+		/* A start tag whose tag name is one of: "th", "td" */
3022
+		if($token['type'] === HTML5::STARTTAG &&
3023
+		($token['name'] === 'th' || $token['name'] === 'td')) {
3024
+			/* Clear the stack back to a table row context. */
3025
+			$this->clearStackToTableContext($clear);
3026
+
3027
+			/* Insert an HTML element for the token, then switch the insertion
3028 3028
             mode to "in cell". */
3029
-            $this->insertElement($token);
3030
-            $this->mode = self::IN_CELL;
3029
+			$this->insertElement($token);
3030
+			$this->mode = self::IN_CELL;
3031 3031
 
3032
-            /* Insert a marker at the end of the list of active formatting
3032
+			/* Insert a marker at the end of the list of active formatting
3033 3033
             elements. */
3034
-            $this->a_formatting[] = self::MARKER;
3034
+			$this->a_formatting[] = self::MARKER;
3035 3035
 
3036
-        /* An end tag whose tag name is "tr" */
3037
-        } elseif($token['type'] === HTML5::ENDTAG && $token['name'] === 'tr') {
3038
-            /* If the stack of open elements does not have an element in table
3036
+		/* An end tag whose tag name is "tr" */
3037
+		} elseif($token['type'] === HTML5::ENDTAG && $token['name'] === 'tr') {
3038
+			/* If the stack of open elements does not have an element in table
3039 3039
             scope with the same tag name as the token, this is a parse error.
3040 3040
             Ignore the token. (innerHTML case) */
3041
-            if(!$this->elementInScope($token['name'], true)) {
3042
-                // Ignore.
3041
+			if(!$this->elementInScope($token['name'], true)) {
3042
+				// Ignore.
3043 3043
 
3044
-            /* Otherwise: */
3045
-            } else {
3046
-                /* Clear the stack back to a table row context. */
3047
-                $this->clearStackToTableContext($clear);
3044
+			/* Otherwise: */
3045
+			} else {
3046
+				/* Clear the stack back to a table row context. */
3047
+				$this->clearStackToTableContext($clear);
3048 3048
 
3049
-                /* Pop the current node (which will be a tr element) from the
3049
+				/* Pop the current node (which will be a tr element) from the
3050 3050
                 stack of open elements. Switch the insertion mode to "in table
3051 3051
                 body". */
3052
-                array_pop($this->stack);
3053
-                $this->mode = self::IN_TBODY;
3054
-            }
3052
+				array_pop($this->stack);
3053
+				$this->mode = self::IN_TBODY;
3054
+			}
3055 3055
 
3056
-        /* A start tag whose tag name is one of: "caption", "col", "colgroup",
3056
+		/* A start tag whose tag name is one of: "caption", "col", "colgroup",
3057 3057
         "tbody", "tfoot", "thead", "tr" or an end tag whose tag name is "table" */
3058
-        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
3059
-        array('caption', 'col', 'colgroup', 'tbody', 'tfoot', 'thead', 'tr'))) {
3060
-            /* Act as if an end tag with the tag name "tr" had been seen, then,
3058
+		} elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
3059
+		array('caption', 'col', 'colgroup', 'tbody', 'tfoot', 'thead', 'tr'))) {
3060
+			/* Act as if an end tag with the tag name "tr" had been seen, then,
3061 3061
             if that token wasn't ignored, reprocess the current token. */
3062
-            $this->inRow(array(
3063
-                'name' => 'tr',
3064
-                'type' => HTML5::ENDTAG
3065
-            ));
3062
+			$this->inRow(array(
3063
+				'name' => 'tr',
3064
+				'type' => HTML5::ENDTAG
3065
+			));
3066 3066
 
3067
-            return $this->inCell($token);
3067
+			return $this->inCell($token);
3068 3068
 
3069
-        /* An end tag whose tag name is one of: "tbody", "tfoot", "thead" */
3070
-        } elseif($token['type'] === HTML5::ENDTAG &&
3071
-        in_array($token['name'], array('tbody', 'tfoot', 'thead'))) {
3072
-            /* If the stack of open elements does not have an element in table
3069
+		/* An end tag whose tag name is one of: "tbody", "tfoot", "thead" */
3070
+		} elseif($token['type'] === HTML5::ENDTAG &&
3071
+		in_array($token['name'], array('tbody', 'tfoot', 'thead'))) {
3072
+			/* If the stack of open elements does not have an element in table
3073 3073
             scope with the same tag name as the token, this is a parse error.
3074 3074
             Ignore the token. */
3075
-            if(!$this->elementInScope($token['name'], true)) {
3076
-                // Ignore.
3075
+			if(!$this->elementInScope($token['name'], true)) {
3076
+				// Ignore.
3077 3077
 
3078
-            /* Otherwise: */
3079
-            } else {
3080
-                /* Otherwise, act as if an end tag with the tag name "tr" had
3078
+			/* Otherwise: */
3079
+			} else {
3080
+				/* Otherwise, act as if an end tag with the tag name "tr" had
3081 3081
                 been seen, then reprocess the current token. */
3082
-                $this->inRow(array(
3083
-                    'name' => 'tr',
3084
-                    'type' => HTML5::ENDTAG
3085
-                ));
3082
+				$this->inRow(array(
3083
+					'name' => 'tr',
3084
+					'type' => HTML5::ENDTAG
3085
+				));
3086 3086
 
3087
-                return $this->inCell($token);
3088
-            }
3087
+				return $this->inCell($token);
3088
+			}
3089 3089
 
3090
-        /* An end tag whose tag name is one of: "body", "caption", "col",
3090
+		/* An end tag whose tag name is one of: "body", "caption", "col",
3091 3091
         "colgroup", "html", "td", "th" */
3092
-        } elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3093
-        array('body', 'caption', 'col', 'colgroup', 'html', 'td', 'th', 'tr'))) {
3094
-            /* Parse error. Ignore the token. */
3095
-
3096
-        /* Anything else */
3097
-        } else {
3098
-            /* Process the token as if the insertion mode was "in table". */
3099
-            $this->inTable($token);
3100
-        }
3101
-    }
3102
-
3103
-    private function inCell($token) {
3104
-        /* An end tag whose tag name is one of: "td", "th" */
3105
-        if($token['type'] === HTML5::ENDTAG &&
3106
-        ($token['name'] === 'td' || $token['name'] === 'th')) {
3107
-            /* If the stack of open elements does not have an element in table
3092
+		} elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3093
+		array('body', 'caption', 'col', 'colgroup', 'html', 'td', 'th', 'tr'))) {
3094
+			/* Parse error. Ignore the token. */
3095
+
3096
+		/* Anything else */
3097
+		} else {
3098
+			/* Process the token as if the insertion mode was "in table". */
3099
+			$this->inTable($token);
3100
+		}
3101
+	}
3102
+
3103
+	private function inCell($token) {
3104
+		/* An end tag whose tag name is one of: "td", "th" */
3105
+		if($token['type'] === HTML5::ENDTAG &&
3106
+		($token['name'] === 'td' || $token['name'] === 'th')) {
3107
+			/* If the stack of open elements does not have an element in table
3108 3108
             scope with the same tag name as that of the token, then this is a
3109 3109
             parse error and the token must be ignored. */
3110
-            if(!$this->elementInScope($token['name'], true)) {
3111
-                // Ignore.
3110
+			if(!$this->elementInScope($token['name'], true)) {
3111
+				// Ignore.
3112 3112
 
3113
-            /* Otherwise: */
3114
-            } else {
3115
-                /* Generate implied end tags, except for elements with the same
3113
+			/* Otherwise: */
3114
+			} else {
3115
+				/* Generate implied end tags, except for elements with the same
3116 3116
                 tag name as the token. */
3117
-                $this->generateImpliedEndTags(array($token['name']));
3117
+				$this->generateImpliedEndTags(array($token['name']));
3118 3118
 
3119
-                /* Now, if the current node is not an element with the same tag
3119
+				/* Now, if the current node is not an element with the same tag
3120 3120
                 name as the token, then this is a parse error. */
3121
-                // k
3121
+				// k
3122 3122
 
3123
-                /* Pop elements from this stack until an element with the same
3123
+				/* Pop elements from this stack until an element with the same
3124 3124
                 tag name as the token has been popped from the stack. */
3125
-                while(true) {
3126
-                    $node = end($this->stack)->nodeName;
3127
-                    array_pop($this->stack);
3125
+				while(true) {
3126
+					$node = end($this->stack)->nodeName;
3127
+					array_pop($this->stack);
3128 3128
 
3129
-                    if($node === $token['name']) {
3130
-                        break;
3131
-                    }
3132
-                }
3129
+					if($node === $token['name']) {
3130
+						break;
3131
+					}
3132
+				}
3133 3133
 
3134
-                /* Clear the list of active formatting elements up to the last
3134
+				/* Clear the list of active formatting elements up to the last
3135 3135
                 marker. */
3136
-                $this->clearTheActiveFormattingElementsUpToTheLastMarker();
3136
+				$this->clearTheActiveFormattingElementsUpToTheLastMarker();
3137 3137
 
3138
-                /* Switch the insertion mode to "in row". (The current node
3138
+				/* Switch the insertion mode to "in row". (The current node
3139 3139
                 will be a tr element at this point.) */
3140
-                $this->mode = self::IN_ROW;
3141
-            }
3140
+				$this->mode = self::IN_ROW;
3141
+			}
3142 3142
 
3143
-        /* A start tag whose tag name is one of: "caption", "col", "colgroup",
3143
+		/* A start tag whose tag name is one of: "caption", "col", "colgroup",
3144 3144
         "tbody", "td", "tfoot", "th", "thead", "tr" */
3145
-        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
3146
-        array('caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
3147
-        'thead', 'tr'))) {
3148
-            /* If the stack of open elements does not have a td or th element
3145
+		} elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
3146
+		array('caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
3147
+		'thead', 'tr'))) {
3148
+			/* If the stack of open elements does not have a td or th element
3149 3149
             in table scope, then this is a parse error; ignore the token.
3150 3150
             (innerHTML case) */
3151
-            if(!$this->elementInScope(array('td', 'th'), true)) {
3152
-                // Ignore.
3151
+			if(!$this->elementInScope(array('td', 'th'), true)) {
3152
+				// Ignore.
3153 3153
 
3154
-            /* Otherwise, close the cell (see below) and reprocess the current
3154
+			/* Otherwise, close the cell (see below) and reprocess the current
3155 3155
             token. */
3156
-            } else {
3157
-                $this->closeCell();
3158
-                return $this->inRow($token);
3159
-            }
3156
+			} else {
3157
+				$this->closeCell();
3158
+				return $this->inRow($token);
3159
+			}
3160 3160
 
3161
-        /* A start tag whose tag name is one of: "caption", "col", "colgroup",
3161
+		/* A start tag whose tag name is one of: "caption", "col", "colgroup",
3162 3162
         "tbody", "td", "tfoot", "th", "thead", "tr" */
3163
-        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
3164
-        array('caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
3165
-        'thead', 'tr'))) {
3166
-            /* If the stack of open elements does not have a td or th element
3163
+		} elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
3164
+		array('caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
3165
+		'thead', 'tr'))) {
3166
+			/* If the stack of open elements does not have a td or th element
3167 3167
             in table scope, then this is a parse error; ignore the token.
3168 3168
             (innerHTML case) */
3169
-            if(!$this->elementInScope(array('td', 'th'), true)) {
3170
-                // Ignore.
3169
+			if(!$this->elementInScope(array('td', 'th'), true)) {
3170
+				// Ignore.
3171 3171
 
3172
-            /* Otherwise, close the cell (see below) and reprocess the current
3172
+			/* Otherwise, close the cell (see below) and reprocess the current
3173 3173
             token. */
3174
-            } else {
3175
-                $this->closeCell();
3176
-                return $this->inRow($token);
3177
-            }
3174
+			} else {
3175
+				$this->closeCell();
3176
+				return $this->inRow($token);
3177
+			}
3178 3178
 
3179
-        /* An end tag whose tag name is one of: "body", "caption", "col",
3179
+		/* An end tag whose tag name is one of: "body", "caption", "col",
3180 3180
         "colgroup", "html" */
3181
-        } elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3182
-        array('body', 'caption', 'col', 'colgroup', 'html'))) {
3183
-            /* Parse error. Ignore the token. */
3181
+		} elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3182
+		array('body', 'caption', 'col', 'colgroup', 'html'))) {
3183
+			/* Parse error. Ignore the token. */
3184 3184
 
3185
-        /* An end tag whose tag name is one of: "table", "tbody", "tfoot",
3185
+		/* An end tag whose tag name is one of: "table", "tbody", "tfoot",
3186 3186
         "thead", "tr" */
3187
-        } elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3188
-        array('table', 'tbody', 'tfoot', 'thead', 'tr'))) {
3189
-            /* If the stack of open elements does not have an element in table
3187
+		} elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3188
+		array('table', 'tbody', 'tfoot', 'thead', 'tr'))) {
3189
+			/* If the stack of open elements does not have an element in table
3190 3190
             scope with the same tag name as that of the token (which can only
3191 3191
             happen for "tbody", "tfoot" and "thead", or, in the innerHTML case),
3192 3192
             then this is a parse error and the token must be ignored. */
3193
-            if(!$this->elementInScope($token['name'], true)) {
3194
-                // Ignore.
3193
+			if(!$this->elementInScope($token['name'], true)) {
3194
+				// Ignore.
3195 3195
 
3196
-            /* Otherwise, close the cell (see below) and reprocess the current
3196
+			/* Otherwise, close the cell (see below) and reprocess the current
3197 3197
             token. */
3198
-            } else {
3199
-                $this->closeCell();
3200
-                return $this->inRow($token);
3201
-            }
3202
-
3203
-        /* Anything else */
3204
-        } else {
3205
-            /* Process the token as if the insertion mode was "in body". */
3206
-            $this->inBody($token);
3207
-        }
3208
-    }
3209
-
3210
-    private function inSelect($token) {
3211
-        /* Handle the token as follows: */
3212
-
3213
-        /* A character token */
3214
-        if($token['type'] === HTML5::CHARACTR) {
3215
-            /* Append the token's character to the current node. */
3216
-            $this->insertText($token['data']);
3217
-
3218
-        /* A comment token */
3219
-        } elseif($token['type'] === HTML5::COMMENT) {
3220
-            /* Append a Comment node to the current node with the data
3198
+			} else {
3199
+				$this->closeCell();
3200
+				return $this->inRow($token);
3201
+			}
3202
+
3203
+		/* Anything else */
3204
+		} else {
3205
+			/* Process the token as if the insertion mode was "in body". */
3206
+			$this->inBody($token);
3207
+		}
3208
+	}
3209
+
3210
+	private function inSelect($token) {
3211
+		/* Handle the token as follows: */
3212
+
3213
+		/* A character token */
3214
+		if($token['type'] === HTML5::CHARACTR) {
3215
+			/* Append the token's character to the current node. */
3216
+			$this->insertText($token['data']);
3217
+
3218
+		/* A comment token */
3219
+		} elseif($token['type'] === HTML5::COMMENT) {
3220
+			/* Append a Comment node to the current node with the data
3221 3221
             attribute set to the data given in the comment token. */
3222
-            $this->insertComment($token['data']);
3222
+			$this->insertComment($token['data']);
3223 3223
 
3224
-        /* A start tag token whose tag name is "option" */
3225
-        } elseif($token['type'] === HTML5::STARTTAG &&
3226
-        $token['name'] === 'option') {
3227
-            /* If the current node is an option element, act as if an end tag
3224
+		/* A start tag token whose tag name is "option" */
3225
+		} elseif($token['type'] === HTML5::STARTTAG &&
3226
+		$token['name'] === 'option') {
3227
+			/* If the current node is an option element, act as if an end tag
3228 3228
             with the tag name "option" had been seen. */
3229
-            if(end($this->stack)->nodeName === 'option') {
3230
-                $this->inSelect(array(
3231
-                    'name' => 'option',
3232
-                    'type' => HTML5::ENDTAG
3233
-                ));
3234
-            }
3235
-
3236
-            /* Insert an HTML element for the token. */
3237
-            $this->insertElement($token);
3238
-
3239
-        /* A start tag token whose tag name is "optgroup" */
3240
-        } elseif($token['type'] === HTML5::STARTTAG &&
3241
-        $token['name'] === 'optgroup') {
3242
-            /* If the current node is an option element, act as if an end tag
3229
+			if(end($this->stack)->nodeName === 'option') {
3230
+				$this->inSelect(array(
3231
+					'name' => 'option',
3232
+					'type' => HTML5::ENDTAG
3233
+				));
3234
+			}
3235
+
3236
+			/* Insert an HTML element for the token. */
3237
+			$this->insertElement($token);
3238
+
3239
+		/* A start tag token whose tag name is "optgroup" */
3240
+		} elseif($token['type'] === HTML5::STARTTAG &&
3241
+		$token['name'] === 'optgroup') {
3242
+			/* If the current node is an option element, act as if an end tag
3243 3243
             with the tag name "option" had been seen. */
3244
-            if(end($this->stack)->nodeName === 'option') {
3245
-                $this->inSelect(array(
3246
-                    'name' => 'option',
3247
-                    'type' => HTML5::ENDTAG
3248
-                ));
3249
-            }
3250
-
3251
-            /* If the current node is an optgroup element, act as if an end tag
3244
+			if(end($this->stack)->nodeName === 'option') {
3245
+				$this->inSelect(array(
3246
+					'name' => 'option',
3247
+					'type' => HTML5::ENDTAG
3248
+				));
3249
+			}
3250
+
3251
+			/* If the current node is an optgroup element, act as if an end tag
3252 3252
             with the tag name "optgroup" had been seen. */
3253
-            if(end($this->stack)->nodeName === 'optgroup') {
3254
-                $this->inSelect(array(
3255
-                    'name' => 'optgroup',
3256
-                    'type' => HTML5::ENDTAG
3257
-                ));
3258
-            }
3259
-
3260
-            /* Insert an HTML element for the token. */
3261
-            $this->insertElement($token);
3262
-
3263
-        /* An end tag token whose tag name is "optgroup" */
3264
-        } elseif($token['type'] === HTML5::ENDTAG &&
3265
-        $token['name'] === 'optgroup') {
3266
-            /* First, if the current node is an option element, and the node
3253
+			if(end($this->stack)->nodeName === 'optgroup') {
3254
+				$this->inSelect(array(
3255
+					'name' => 'optgroup',
3256
+					'type' => HTML5::ENDTAG
3257
+				));
3258
+			}
3259
+
3260
+			/* Insert an HTML element for the token. */
3261
+			$this->insertElement($token);
3262
+
3263
+		/* An end tag token whose tag name is "optgroup" */
3264
+		} elseif($token['type'] === HTML5::ENDTAG &&
3265
+		$token['name'] === 'optgroup') {
3266
+			/* First, if the current node is an option element, and the node
3267 3267
             immediately before it in the stack of open elements is an optgroup
3268 3268
             element, then act as if an end tag with the tag name "option" had
3269 3269
             been seen. */
3270
-            $elements_in_stack = count($this->stack);
3270
+			$elements_in_stack = count($this->stack);
3271 3271
 
3272
-            if($this->stack[$elements_in_stack - 1]->nodeName === 'option' &&
3273
-            $this->stack[$elements_in_stack - 2]->nodeName === 'optgroup') {
3274
-                $this->inSelect(array(
3275
-                    'name' => 'option',
3276
-                    'type' => HTML5::ENDTAG
3277
-                ));
3278
-            }
3272
+			if($this->stack[$elements_in_stack - 1]->nodeName === 'option' &&
3273
+			$this->stack[$elements_in_stack - 2]->nodeName === 'optgroup') {
3274
+				$this->inSelect(array(
3275
+					'name' => 'option',
3276
+					'type' => HTML5::ENDTAG
3277
+				));
3278
+			}
3279 3279
 
3280
-            /* If the current node is an optgroup element, then pop that node
3280
+			/* If the current node is an optgroup element, then pop that node
3281 3281
             from the stack of open elements. Otherwise, this is a parse error,
3282 3282
             ignore the token. */
3283
-            if($this->stack[$elements_in_stack - 1] === 'optgroup') {
3284
-                array_pop($this->stack);
3285
-            }
3286
-
3287
-        /* An end tag token whose tag name is "option" */
3288
-        } elseif($token['type'] === HTML5::ENDTAG &&
3289
-        $token['name'] === 'option') {
3290
-            /* If the current node is an option element, then pop that node
3283
+			if($this->stack[$elements_in_stack - 1] === 'optgroup') {
3284
+				array_pop($this->stack);
3285
+			}
3286
+
3287
+		/* An end tag token whose tag name is "option" */
3288
+		} elseif($token['type'] === HTML5::ENDTAG &&
3289
+		$token['name'] === 'option') {
3290
+			/* If the current node is an option element, then pop that node
3291 3291
             from the stack of open elements. Otherwise, this is a parse error,
3292 3292
             ignore the token. */
3293
-            if(end($this->stack)->nodeName === 'option') {
3294
-                array_pop($this->stack);
3295
-            }
3296
-
3297
-        /* An end tag whose tag name is "select" */
3298
-        } elseif($token['type'] === HTML5::ENDTAG &&
3299
-        $token['name'] === 'select') {
3300
-            /* If the stack of open elements does not have an element in table
3293
+			if(end($this->stack)->nodeName === 'option') {
3294
+				array_pop($this->stack);
3295
+			}
3296
+
3297
+		/* An end tag whose tag name is "select" */
3298
+		} elseif($token['type'] === HTML5::ENDTAG &&
3299
+		$token['name'] === 'select') {
3300
+			/* If the stack of open elements does not have an element in table
3301 3301
             scope with the same tag name as the token, this is a parse error.
3302 3302
             Ignore the token. (innerHTML case) */
3303
-            if(!$this->elementInScope($token['name'], true)) {
3304
-                // w/e
3303
+			if(!$this->elementInScope($token['name'], true)) {
3304
+				// w/e
3305 3305
 
3306
-            /* Otherwise: */
3307
-            } else {
3308
-                /* Pop elements from the stack of open elements until a select
3306
+			/* Otherwise: */
3307
+			} else {
3308
+				/* Pop elements from the stack of open elements until a select
3309 3309
                 element has been popped from the stack. */
3310
-                while(true) {
3311
-                    $current = end($this->stack)->nodeName;
3312
-                    array_pop($this->stack);
3313
-
3314
-                    if($current === 'select') {
3315
-                        break;
3316
-                    }
3317
-                }
3318
-
3319
-                /* Reset the insertion mode appropriately. */
3320
-                $this->resetInsertionMode();
3321
-            }
3322
-
3323
-        /* A start tag whose tag name is "select" */
3324
-        } elseif($token['name'] === 'select' &&
3325
-        $token['type'] === HTML5::STARTTAG) {
3326
-            /* Parse error. Act as if the token had been an end tag with the
3310
+				while(true) {
3311
+					$current = end($this->stack)->nodeName;
3312
+					array_pop($this->stack);
3313
+
3314
+					if($current === 'select') {
3315
+						break;
3316
+					}
3317
+				}
3318
+
3319
+				/* Reset the insertion mode appropriately. */
3320
+				$this->resetInsertionMode();
3321
+			}
3322
+
3323
+		/* A start tag whose tag name is "select" */
3324
+		} elseif($token['name'] === 'select' &&
3325
+		$token['type'] === HTML5::STARTTAG) {
3326
+			/* Parse error. Act as if the token had been an end tag with the
3327 3327
             tag name "select" instead. */
3328
-            $this->inSelect(array(
3329
-                'name' => 'select',
3330
-                'type' => HTML5::ENDTAG
3331
-            ));
3328
+			$this->inSelect(array(
3329
+				'name' => 'select',
3330
+				'type' => HTML5::ENDTAG
3331
+			));
3332 3332
 
3333
-        /* An end tag whose tag name is one of: "caption", "table", "tbody",
3333
+		/* An end tag whose tag name is one of: "caption", "table", "tbody",
3334 3334
         "tfoot", "thead", "tr", "td", "th" */
3335
-        } elseif(in_array($token['name'], array('caption', 'table', 'tbody',
3336
-        'tfoot', 'thead', 'tr', 'td', 'th')) && $token['type'] === HTML5::ENDTAG) {
3337
-            /* Parse error. */
3338
-            // w/e
3335
+		} elseif(in_array($token['name'], array('caption', 'table', 'tbody',
3336
+		'tfoot', 'thead', 'tr', 'td', 'th')) && $token['type'] === HTML5::ENDTAG) {
3337
+			/* Parse error. */
3338
+			// w/e
3339 3339
 
3340
-            /* If the stack of open elements has an element in table scope with
3340
+			/* If the stack of open elements has an element in table scope with
3341 3341
             the same tag name as that of the token, then act as if an end tag
3342 3342
             with the tag name "select" had been seen, and reprocess the token.
3343 3343
             Otherwise, ignore the token. */
3344
-            if($this->elementInScope($token['name'], true)) {
3345
-                $this->inSelect(array(
3346
-                    'name' => 'select',
3347
-                    'type' => HTML5::ENDTAG
3348
-                ));
3344
+			if($this->elementInScope($token['name'], true)) {
3345
+				$this->inSelect(array(
3346
+					'name' => 'select',
3347
+					'type' => HTML5::ENDTAG
3348
+				));
3349 3349
 
3350
-                $this->mainPhase($token);
3351
-            }
3350
+				$this->mainPhase($token);
3351
+			}
3352 3352
 
3353
-        /* Anything else */
3354
-        } else {
3355
-            /* Parse error. Ignore the token. */
3356
-        }
3357
-    }
3353
+		/* Anything else */
3354
+		} else {
3355
+			/* Parse error. Ignore the token. */
3356
+		}
3357
+	}
3358 3358
 
3359
-    private function afterBody($token) {
3360
-        /* Handle the token as follows: */
3359
+	private function afterBody($token) {
3360
+		/* Handle the token as follows: */
3361 3361
 
3362
-        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
3362
+		/* A character token that is one of one of U+0009 CHARACTER TABULATION,
3363 3363
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
3364 3364
         or U+0020 SPACE */
3365
-        if($token['type'] === HTML5::CHARACTR &&
3366
-        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
3367
-            /* Process the token as it would be processed if the insertion mode
3365
+		if($token['type'] === HTML5::CHARACTR &&
3366
+		preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
3367
+			/* Process the token as it would be processed if the insertion mode
3368 3368
             was "in body". */
3369
-            $this->inBody($token);
3369
+			$this->inBody($token);
3370 3370
 
3371
-        /* A comment token */
3372
-        } elseif($token['type'] === HTML5::COMMENT) {
3373
-            /* Append a Comment node to the first element in the stack of open
3371
+		/* A comment token */
3372
+		} elseif($token['type'] === HTML5::COMMENT) {
3373
+			/* Append a Comment node to the first element in the stack of open
3374 3374
             elements (the html element), with the data attribute set to the
3375 3375
             data given in the comment token. */
3376
-            $comment = $this->dom->createComment($token['data']);
3377
-            $this->stack[0]->appendChild($comment);
3376
+			$comment = $this->dom->createComment($token['data']);
3377
+			$this->stack[0]->appendChild($comment);
3378 3378
 
3379
-        /* An end tag with the tag name "html" */
3380
-        } elseif($token['type'] === HTML5::ENDTAG && $token['name'] === 'html') {
3381
-            /* If the parser was originally created in order to handle the
3379
+		/* An end tag with the tag name "html" */
3380
+		} elseif($token['type'] === HTML5::ENDTAG && $token['name'] === 'html') {
3381
+			/* If the parser was originally created in order to handle the
3382 3382
             setting of an element's innerHTML attribute, this is a parse error;
3383 3383
             ignore the token. (The element will be an html element in this
3384 3384
             case.) (innerHTML case) */
3385 3385
 
3386
-            /* Otherwise, switch to the trailing end phase. */
3387
-            $this->phase = self::END_PHASE;
3386
+			/* Otherwise, switch to the trailing end phase. */
3387
+			$this->phase = self::END_PHASE;
3388 3388
 
3389
-        /* Anything else */
3390
-        } else {
3391
-            /* Parse error. Set the insertion mode to "in body" and reprocess
3389
+		/* Anything else */
3390
+		} else {
3391
+			/* Parse error. Set the insertion mode to "in body" and reprocess
3392 3392
             the token. */
3393
-            $this->mode = self::IN_BODY;
3394
-            return $this->inBody($token);
3395
-        }
3396
-    }
3393
+			$this->mode = self::IN_BODY;
3394
+			return $this->inBody($token);
3395
+		}
3396
+	}
3397 3397
 
3398
-    private function inFrameset($token) {
3399
-        /* Handle the token as follows: */
3398
+	private function inFrameset($token) {
3399
+		/* Handle the token as follows: */
3400 3400
 
3401
-        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
3401
+		/* A character token that is one of one of U+0009 CHARACTER TABULATION,
3402 3402
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
3403 3403
         U+000D CARRIAGE RETURN (CR), or U+0020 SPACE */
3404
-        if($token['type'] === HTML5::CHARACTR &&
3405
-        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
3406
-            /* Append the character to the current node. */
3407
-            $this->insertText($token['data']);
3408
-
3409
-        /* A comment token */
3410
-        } elseif($token['type'] === HTML5::COMMENT) {
3411
-            /* Append a Comment node to the current node with the data
3404
+		if($token['type'] === HTML5::CHARACTR &&
3405
+		preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
3406
+			/* Append the character to the current node. */
3407
+			$this->insertText($token['data']);
3408
+
3409
+		/* A comment token */
3410
+		} elseif($token['type'] === HTML5::COMMENT) {
3411
+			/* Append a Comment node to the current node with the data
3412 3412
             attribute set to the data given in the comment token. */
3413
-            $this->insertComment($token['data']);
3413
+			$this->insertComment($token['data']);
3414 3414
 
3415
-        /* A start tag with the tag name "frameset" */
3416
-        } elseif($token['name'] === 'frameset' &&
3417
-        $token['type'] === HTML5::STARTTAG) {
3418
-            $this->insertElement($token);
3415
+		/* A start tag with the tag name "frameset" */
3416
+		} elseif($token['name'] === 'frameset' &&
3417
+		$token['type'] === HTML5::STARTTAG) {
3418
+			$this->insertElement($token);
3419 3419
 
3420
-        /* An end tag with the tag name "frameset" */
3421
-        } elseif($token['name'] === 'frameset' &&
3422
-        $token['type'] === HTML5::ENDTAG) {
3423
-            /* If the current node is the root html element, then this is a
3420
+		/* An end tag with the tag name "frameset" */
3421
+		} elseif($token['name'] === 'frameset' &&
3422
+		$token['type'] === HTML5::ENDTAG) {
3423
+			/* If the current node is the root html element, then this is a
3424 3424
             parse error; ignore the token. (innerHTML case) */
3425
-            if(end($this->stack)->nodeName === 'html') {
3426
-                // Ignore
3425
+			if(end($this->stack)->nodeName === 'html') {
3426
+				// Ignore
3427 3427
 
3428
-            } else {
3429
-                /* Otherwise, pop the current node from the stack of open
3428
+			} else {
3429
+				/* Otherwise, pop the current node from the stack of open
3430 3430
                 elements. */
3431
-                array_pop($this->stack);
3431
+				array_pop($this->stack);
3432 3432
 
3433
-                /* If the parser was not originally created in order to handle
3433
+				/* If the parser was not originally created in order to handle
3434 3434
                 the setting of an element's innerHTML attribute (innerHTML case),
3435 3435
                 and the current node is no longer a frameset element, then change
3436 3436
                 the insertion mode to "after frameset". */
3437
-                $this->mode = self::AFTR_FRAME;
3438
-            }
3439
-
3440
-        /* A start tag with the tag name "frame" */
3441
-        } elseif($token['name'] === 'frame' &&
3442
-        $token['type'] === HTML5::STARTTAG) {
3443
-            /* Insert an HTML element for the token. */
3444
-            $this->insertElement($token);
3445
-
3446
-            /* Immediately pop the current node off the stack of open elements. */
3447
-            array_pop($this->stack);
3448
-
3449
-        /* A start tag with the tag name "noframes" */
3450
-        } elseif($token['name'] === 'noframes' &&
3451
-        $token['type'] === HTML5::STARTTAG) {
3452
-            /* Process the token as if the insertion mode had been "in body". */
3453
-            $this->inBody($token);
3454
-
3455
-        /* Anything else */
3456
-        } else {
3457
-            /* Parse error. Ignore the token. */
3458
-        }
3459
-    }
3460
-
3461
-    private function afterFrameset($token) {
3462
-        /* Handle the token as follows: */
3463
-
3464
-        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
3437
+				$this->mode = self::AFTR_FRAME;
3438
+			}
3439
+
3440
+		/* A start tag with the tag name "frame" */
3441
+		} elseif($token['name'] === 'frame' &&
3442
+		$token['type'] === HTML5::STARTTAG) {
3443
+			/* Insert an HTML element for the token. */
3444
+			$this->insertElement($token);
3445
+
3446
+			/* Immediately pop the current node off the stack of open elements. */
3447
+			array_pop($this->stack);
3448
+
3449
+		/* A start tag with the tag name "noframes" */
3450
+		} elseif($token['name'] === 'noframes' &&
3451
+		$token['type'] === HTML5::STARTTAG) {
3452
+			/* Process the token as if the insertion mode had been "in body". */
3453
+			$this->inBody($token);
3454
+
3455
+		/* Anything else */
3456
+		} else {
3457
+			/* Parse error. Ignore the token. */
3458
+		}
3459
+	}
3460
+
3461
+	private function afterFrameset($token) {
3462
+		/* Handle the token as follows: */
3463
+
3464
+		/* A character token that is one of one of U+0009 CHARACTER TABULATION,
3465 3465
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
3466 3466
         U+000D CARRIAGE RETURN (CR), or U+0020 SPACE */
3467
-        if($token['type'] === HTML5::CHARACTR &&
3468
-        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
3469
-            /* Append the character to the current node. */
3470
-            $this->insertText($token['data']);
3471
-
3472
-        /* A comment token */
3473
-        } elseif($token['type'] === HTML5::COMMENT) {
3474
-            /* Append a Comment node to the current node with the data
3467
+		if($token['type'] === HTML5::CHARACTR &&
3468
+		preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
3469
+			/* Append the character to the current node. */
3470
+			$this->insertText($token['data']);
3471
+
3472
+		/* A comment token */
3473
+		} elseif($token['type'] === HTML5::COMMENT) {
3474
+			/* Append a Comment node to the current node with the data
3475 3475
             attribute set to the data given in the comment token. */
3476
-            $this->insertComment($token['data']);
3477
-
3478
-        /* An end tag with the tag name "html" */
3479
-        } elseif($token['name'] === 'html' &&
3480
-        $token['type'] === HTML5::ENDTAG) {
3481
-            /* Switch to the trailing end phase. */
3482
-            $this->phase = self::END_PHASE;
3483
-
3484
-        /* A start tag with the tag name "noframes" */
3485
-        } elseif($token['name'] === 'noframes' &&
3486
-        $token['type'] === HTML5::STARTTAG) {
3487
-            /* Process the token as if the insertion mode had been "in body". */
3488
-            $this->inBody($token);
3489
-
3490
-        /* Anything else */
3491
-        } else {
3492
-            /* Parse error. Ignore the token. */
3493
-        }
3494
-    }
3495
-
3496
-    private function trailingEndPhase($token) {
3497
-        /* After the main phase, as each token is emitted from the tokenisation
3476
+			$this->insertComment($token['data']);
3477
+
3478
+		/* An end tag with the tag name "html" */
3479
+		} elseif($token['name'] === 'html' &&
3480
+		$token['type'] === HTML5::ENDTAG) {
3481
+			/* Switch to the trailing end phase. */
3482
+			$this->phase = self::END_PHASE;
3483
+
3484
+		/* A start tag with the tag name "noframes" */
3485
+		} elseif($token['name'] === 'noframes' &&
3486
+		$token['type'] === HTML5::STARTTAG) {
3487
+			/* Process the token as if the insertion mode had been "in body". */
3488
+			$this->inBody($token);
3489
+
3490
+		/* Anything else */
3491
+		} else {
3492
+			/* Parse error. Ignore the token. */
3493
+		}
3494
+	}
3495
+
3496
+	private function trailingEndPhase($token) {
3497
+		/* After the main phase, as each token is emitted from the tokenisation
3498 3498
         stage, it must be processed as described in this section. */
3499 3499
 
3500
-        /* A DOCTYPE token */
3501
-        if($token['type'] === HTML5::DOCTYPE) {
3502
-            // Parse error. Ignore the token.
3500
+		/* A DOCTYPE token */
3501
+		if($token['type'] === HTML5::DOCTYPE) {
3502
+			// Parse error. Ignore the token.
3503 3503
 
3504
-        /* A comment token */
3505
-        } elseif($token['type'] === HTML5::COMMENT) {
3506
-            /* Append a Comment node to the Document object with the data
3504
+		/* A comment token */
3505
+		} elseif($token['type'] === HTML5::COMMENT) {
3506
+			/* Append a Comment node to the Document object with the data
3507 3507
             attribute set to the data given in the comment token. */
3508
-            $comment = $this->dom->createComment($token['data']);
3509
-            $this->dom->appendChild($comment);
3508
+			$comment = $this->dom->createComment($token['data']);
3509
+			$this->dom->appendChild($comment);
3510 3510
 
3511
-        /* A character token that is one of one of U+0009 CHARACTER TABULATION,
3511
+		/* A character token that is one of one of U+0009 CHARACTER TABULATION,
3512 3512
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
3513 3513
         or U+0020 SPACE */
3514
-        } elseif($token['type'] === HTML5::CHARACTR &&
3515
-        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
3516
-            /* Process the token as it would be processed in the main phase. */
3517
-            $this->mainPhase($token);
3514
+		} elseif($token['type'] === HTML5::CHARACTR &&
3515
+		preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
3516
+			/* Process the token as it would be processed in the main phase. */
3517
+			$this->mainPhase($token);
3518 3518
 
3519
-        /* A character token that is not one of U+0009 CHARACTER TABULATION,
3519
+		/* A character token that is not one of U+0009 CHARACTER TABULATION,
3520 3520
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
3521 3521
         or U+0020 SPACE. Or a start tag token. Or an end tag token. */
3522
-        } elseif(($token['type'] === HTML5::CHARACTR &&
3523
-        preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) ||
3524
-        $token['type'] === HTML5::STARTTAG || $token['type'] === HTML5::ENDTAG) {
3525
-            /* Parse error. Switch back to the main phase and reprocess the
3522
+		} elseif(($token['type'] === HTML5::CHARACTR &&
3523
+		preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) ||
3524
+		$token['type'] === HTML5::STARTTAG || $token['type'] === HTML5::ENDTAG) {
3525
+			/* Parse error. Switch back to the main phase and reprocess the
3526 3526
             token. */
3527
-            $this->phase = self::MAIN_PHASE;
3528
-            return $this->mainPhase($token);
3529
-
3530
-        /* An end-of-file token */
3531
-        } elseif($token['type'] === HTML5::EOF) {
3532
-            /* OMG DONE!! */
3533
-        }
3534
-    }
3535
-
3536
-    private function insertElement($token, $append = true, $check = false) {
3537
-        // Proprietary workaround for libxml2's limitations with tag names
3538
-        if ($check) {
3539
-            // Slightly modified HTML5 tag-name modification,
3540
-            // removing anything that's not an ASCII letter, digit, or hyphen
3541
-            $token['name'] = preg_replace('/[^a-z0-9-]/i', '', $token['name']);
3542
-            // Remove leading hyphens and numbers
3543
-            $token['name'] = ltrim($token['name'], '-0..9');
3544
-            // In theory, this should ever be needed, but just in case
3545
-            if ($token['name'] === '') $token['name'] = 'span'; // arbitrary generic choice
3546
-        }
3527
+			$this->phase = self::MAIN_PHASE;
3528
+			return $this->mainPhase($token);
3529
+
3530
+		/* An end-of-file token */
3531
+		} elseif($token['type'] === HTML5::EOF) {
3532
+			/* OMG DONE!! */
3533
+		}
3534
+	}
3535
+
3536
+	private function insertElement($token, $append = true, $check = false) {
3537
+		// Proprietary workaround for libxml2's limitations with tag names
3538
+		if ($check) {
3539
+			// Slightly modified HTML5 tag-name modification,
3540
+			// removing anything that's not an ASCII letter, digit, or hyphen
3541
+			$token['name'] = preg_replace('/[^a-z0-9-]/i', '', $token['name']);
3542
+			// Remove leading hyphens and numbers
3543
+			$token['name'] = ltrim($token['name'], '-0..9');
3544
+			// In theory, this should ever be needed, but just in case
3545
+			if ($token['name'] === '') $token['name'] = 'span'; // arbitrary generic choice
3546
+		}
3547 3547
         
3548
-        $el = $this->dom->createElement($token['name']);
3548
+		$el = $this->dom->createElement($token['name']);
3549 3549
 
3550
-        foreach($token['attr'] as $attr) {
3551
-            if(!$el->hasAttribute($attr['name'])) {
3552
-                $el->setAttribute($attr['name'], $attr['value']);
3553
-            }
3554
-        }
3550
+		foreach($token['attr'] as $attr) {
3551
+			if(!$el->hasAttribute($attr['name'])) {
3552
+				$el->setAttribute($attr['name'], $attr['value']);
3553
+			}
3554
+		}
3555 3555
 
3556
-        $this->appendToRealParent($el);
3557
-        $this->stack[] = $el;
3556
+		$this->appendToRealParent($el);
3557
+		$this->stack[] = $el;
3558 3558
 
3559
-        return $el;
3560
-    }
3559
+		return $el;
3560
+	}
3561 3561
 
3562
-    private function insertText($data) {
3563
-        $text = $this->dom->createTextNode($data);
3564
-        $this->appendToRealParent($text);
3565
-    }
3562
+	private function insertText($data) {
3563
+		$text = $this->dom->createTextNode($data);
3564
+		$this->appendToRealParent($text);
3565
+	}
3566 3566
 
3567
-    private function insertComment($data) {
3568
-        $comment = $this->dom->createComment($data);
3569
-        $this->appendToRealParent($comment);
3570
-    }
3567
+	private function insertComment($data) {
3568
+		$comment = $this->dom->createComment($data);
3569
+		$this->appendToRealParent($comment);
3570
+	}
3571 3571
 
3572
-    private function appendToRealParent($node) {
3573
-        if($this->foster_parent === null) {
3574
-            end($this->stack)->appendChild($node);
3572
+	private function appendToRealParent($node) {
3573
+		if($this->foster_parent === null) {
3574
+			end($this->stack)->appendChild($node);
3575 3575
 
3576
-        } elseif($this->foster_parent !== null) {
3577
-            /* If the foster parent element is the parent element of the
3576
+		} elseif($this->foster_parent !== null) {
3577
+			/* If the foster parent element is the parent element of the
3578 3578
             last table element in the stack of open elements, then the new
3579 3579
             node must be inserted immediately before the last table element
3580 3580
             in the stack of open elements in the foster parent element;
3581 3581
             otherwise, the new node must be appended to the foster parent
3582 3582
             element. */
3583
-            for($n = count($this->stack) - 1; $n >= 0; $n--) {
3584
-                if($this->stack[$n]->nodeName === 'table' &&
3585
-                $this->stack[$n]->parentNode !== null) {
3586
-                    $table = $this->stack[$n];
3587
-                    break;
3588
-                }
3589
-            }
3590
-
3591
-            if(isset($table) && $this->foster_parent->isSameNode($table->parentNode))
3592
-                $this->foster_parent->insertBefore($node, $table);
3593
-            else
3594
-                $this->foster_parent->appendChild($node);
3595
-
3596
-            $this->foster_parent = null;
3597
-        }
3598
-    }
3599
-
3600
-    private function elementInScope($el, $table = false) {
3601
-        if(is_array($el)) {
3602
-            foreach($el as $element) {
3603
-                if($this->elementInScope($element, $table)) {
3604
-                    return true;
3605
-                }
3606
-            }
3607
-
3608
-            return false;
3609
-        }
3610
-
3611
-        $leng = count($this->stack);
3612
-
3613
-        for($n = 0; $n < $leng; $n++) {
3614
-            /* 1. Initialise node to be the current node (the bottommost node of
3583
+			for($n = count($this->stack) - 1; $n >= 0; $n--) {
3584
+				if($this->stack[$n]->nodeName === 'table' &&
3585
+				$this->stack[$n]->parentNode !== null) {
3586
+					$table = $this->stack[$n];
3587
+					break;
3588
+				}
3589
+			}
3590
+
3591
+			if(isset($table) && $this->foster_parent->isSameNode($table->parentNode))
3592
+				$this->foster_parent->insertBefore($node, $table);
3593
+			else
3594
+				$this->foster_parent->appendChild($node);
3595
+
3596
+			$this->foster_parent = null;
3597
+		}
3598
+	}
3599
+
3600
+	private function elementInScope($el, $table = false) {
3601
+		if(is_array($el)) {
3602
+			foreach($el as $element) {
3603
+				if($this->elementInScope($element, $table)) {
3604
+					return true;
3605
+				}
3606
+			}
3607
+
3608
+			return false;
3609
+		}
3610
+
3611
+		$leng = count($this->stack);
3612
+
3613
+		for($n = 0; $n < $leng; $n++) {
3614
+			/* 1. Initialise node to be the current node (the bottommost node of
3615 3615
             the stack). */
3616
-            $node = $this->stack[$leng - 1 - $n];
3616
+			$node = $this->stack[$leng - 1 - $n];
3617 3617
 
3618
-            if($node->tagName === $el) {
3619
-                /* 2. If node is the target node, terminate in a match state. */
3620
-                return true;
3618
+			if($node->tagName === $el) {
3619
+				/* 2. If node is the target node, terminate in a match state. */
3620
+				return true;
3621 3621
 
3622
-            } elseif($node->tagName === 'table') {
3623
-                /* 3. Otherwise, if node is a table element, terminate in a failure
3622
+			} elseif($node->tagName === 'table') {
3623
+				/* 3. Otherwise, if node is a table element, terminate in a failure
3624 3624
                 state. */
3625
-                return false;
3625
+				return false;
3626 3626
 
3627
-            } elseif($table === true && in_array($node->tagName, array('caption', 'td',
3628
-            'th', 'button', 'marquee', 'object'))) {
3629
-                /* 4. Otherwise, if the algorithm is the "has an element in scope"
3627
+			} elseif($table === true && in_array($node->tagName, array('caption', 'td',
3628
+			'th', 'button', 'marquee', 'object'))) {
3629
+				/* 4. Otherwise, if the algorithm is the "has an element in scope"
3630 3630
                 variant (rather than the "has an element in table scope" variant),
3631 3631
                 and node is one of the following, terminate in a failure state. */
3632
-                return false;
3632
+				return false;
3633 3633
 
3634
-            } elseif($node === $node->ownerDocument->documentElement) {
3635
-                /* 5. Otherwise, if node is an html element (root element), terminate
3634
+			} elseif($node === $node->ownerDocument->documentElement) {
3635
+				/* 5. Otherwise, if node is an html element (root element), terminate
3636 3636
                 in a failure state. (This can only happen if the node is the topmost
3637 3637
                 node of the    stack of open elements, and prevents the next step from
3638 3638
                 being invoked if there are no more elements in the stack.) */
3639
-                return false;
3640
-            }
3639
+				return false;
3640
+			}
3641 3641
 
3642
-            /* Otherwise, set node to the previous entry in the stack of open
3642
+			/* Otherwise, set node to the previous entry in the stack of open
3643 3643
             elements and return to step 2. (This will never fail, since the loop
3644 3644
             will always terminate in the previous step if the top of the stack
3645 3645
             is reached.) */
3646
-        }
3647
-    }
3646
+		}
3647
+	}
3648 3648
 
3649
-    private function reconstructActiveFormattingElements() {
3650
-        /* 1. If there are no entries in the list of active formatting elements,
3649
+	private function reconstructActiveFormattingElements() {
3650
+		/* 1. If there are no entries in the list of active formatting elements,
3651 3651
         then there is nothing to reconstruct; stop this algorithm. */
3652
-        $formatting_elements = count($this->a_formatting);
3652
+		$formatting_elements = count($this->a_formatting);
3653 3653
 
3654
-        if($formatting_elements === 0) {
3655
-            return false;
3656
-        }
3654
+		if($formatting_elements === 0) {
3655
+			return false;
3656
+		}
3657 3657
 
3658
-        /* 3. Let entry be the last (most recently added) element in the list
3658
+		/* 3. Let entry be the last (most recently added) element in the list
3659 3659
         of active formatting elements. */
3660
-        $entry = end($this->a_formatting);
3660
+		$entry = end($this->a_formatting);
3661 3661
 
3662
-        /* 2. If the last (most recently added) entry in the list of active
3662
+		/* 2. If the last (most recently added) entry in the list of active
3663 3663
         formatting elements is a marker, or if it is an element that is in the
3664 3664
         stack of open elements, then there is nothing to reconstruct; stop this
3665 3665
         algorithm. */
3666
-        if($entry === self::MARKER || in_array($entry, $this->stack, true)) {
3667
-            return false;
3668
-        }
3666
+		if($entry === self::MARKER || in_array($entry, $this->stack, true)) {
3667
+			return false;
3668
+		}
3669 3669
 
3670
-        for($a = $formatting_elements - 1; $a >= 0; true) {
3671
-            /* 4. If there are no entries before entry in the list of active
3670
+		for($a = $formatting_elements - 1; $a >= 0; true) {
3671
+			/* 4. If there are no entries before entry in the list of active
3672 3672
             formatting elements, then jump to step 8. */
3673
-            if($a === 0) {
3674
-                $step_seven = false;
3675
-                break;
3676
-            }
3673
+			if($a === 0) {
3674
+				$step_seven = false;
3675
+				break;
3676
+			}
3677 3677
 
3678
-            /* 5. Let entry be the entry one earlier than entry in the list of
3678
+			/* 5. Let entry be the entry one earlier than entry in the list of
3679 3679
             active formatting elements. */
3680
-            $a--;
3681
-            $entry = $this->a_formatting[$a];
3680
+			$a--;
3681
+			$entry = $this->a_formatting[$a];
3682 3682
 
3683
-            /* 6. If entry is neither a marker nor an element that is also in
3683
+			/* 6. If entry is neither a marker nor an element that is also in
3684 3684
             thetack of open elements, go to step 4. */
3685
-            if($entry === self::MARKER || in_array($entry, $this->stack, true)) {
3686
-                break;
3687
-            }
3688
-        }
3685
+			if($entry === self::MARKER || in_array($entry, $this->stack, true)) {
3686
+				break;
3687
+			}
3688
+		}
3689 3689
 
3690
-        while(true) {
3691
-            /* 7. Let entry be the element one later than entry in the list of
3690
+		while(true) {
3691
+			/* 7. Let entry be the element one later than entry in the list of
3692 3692
             active formatting elements. */
3693
-            if(isset($step_seven) && $step_seven === true) {
3694
-                $a++;
3695
-                $entry = $this->a_formatting[$a];
3696
-            }
3693
+			if(isset($step_seven) && $step_seven === true) {
3694
+				$a++;
3695
+				$entry = $this->a_formatting[$a];
3696
+			}
3697 3697
 
3698
-            /* 8. Perform a shallow clone of the element entry to obtain clone. */
3699
-            $clone = $entry->cloneNode();
3698
+			/* 8. Perform a shallow clone of the element entry to obtain clone. */
3699
+			$clone = $entry->cloneNode();
3700 3700
 
3701
-            /* 9. Append clone to the current node and push it onto the stack
3701
+			/* 9. Append clone to the current node and push it onto the stack
3702 3702
             of open elements  so that it is the new current node. */
3703
-            end($this->stack)->appendChild($clone);
3704
-            $this->stack[] = $clone;
3703
+			end($this->stack)->appendChild($clone);
3704
+			$this->stack[] = $clone;
3705 3705
 
3706
-            /* 10. Replace the entry for entry in the list with an entry for
3706
+			/* 10. Replace the entry for entry in the list with an entry for
3707 3707
             clone. */
3708
-            $this->a_formatting[$a] = $clone;
3708
+			$this->a_formatting[$a] = $clone;
3709 3709
 
3710
-            /* 11. If the entry for clone in the list of active formatting
3710
+			/* 11. If the entry for clone in the list of active formatting
3711 3711
             elements is not the last entry in the list, return to step 7. */
3712
-            if(end($this->a_formatting) !== $clone) {
3713
-                $step_seven = true;
3714
-            } else {
3715
-                break;
3716
-            }
3717
-        }
3718
-    }
3719
-
3720
-    private function clearTheActiveFormattingElementsUpToTheLastMarker() {
3721
-        /* When the steps below require the UA to clear the list of active
3712
+			if(end($this->a_formatting) !== $clone) {
3713
+				$step_seven = true;
3714
+			} else {
3715
+				break;
3716
+			}
3717
+		}
3718
+	}
3719
+
3720
+	private function clearTheActiveFormattingElementsUpToTheLastMarker() {
3721
+		/* When the steps below require the UA to clear the list of active
3722 3722
         formatting elements up to the last marker, the UA must perform the
3723 3723
         following steps: */
3724 3724
 
3725
-        while(true) {
3726
-            /* 1. Let entry be the last (most recently added) entry in the list
3725
+		while(true) {
3726
+			/* 1. Let entry be the last (most recently added) entry in the list
3727 3727
             of active formatting elements. */
3728
-            $entry = end($this->a_formatting);
3728
+			$entry = end($this->a_formatting);
3729 3729
 
3730
-            /* 2. Remove entry from the list of active formatting elements. */
3731
-            array_pop($this->a_formatting);
3730
+			/* 2. Remove entry from the list of active formatting elements. */
3731
+			array_pop($this->a_formatting);
3732 3732
 
3733
-            /* 3. If entry was a marker, then stop the algorithm at this point.
3733
+			/* 3. If entry was a marker, then stop the algorithm at this point.
3734 3734
             The list has been cleared up to the last marker. */
3735
-            if($entry === self::MARKER) {
3736
-                break;
3737
-            }
3738
-        }
3739
-    }
3740
-
3741
-    private function generateImpliedEndTags($exclude = array()) {
3742
-        /* When the steps below require the UA to generate implied end tags,
3735
+			if($entry === self::MARKER) {
3736
+				break;
3737
+			}
3738
+		}
3739
+	}
3740
+
3741
+	private function generateImpliedEndTags($exclude = array()) {
3742
+		/* When the steps below require the UA to generate implied end tags,
3743 3743
         then, if the current node is a dd element, a dt element, an li element,
3744 3744
         a p element, a td element, a th  element, or a tr element, the UA must
3745 3745
         act as if an end tag with the respective tag name had been seen and
3746 3746
         then generate implied end tags again. */
3747
-        $node = end($this->stack);
3748
-        $elements = array_diff(array('dd', 'dt', 'li', 'p', 'td', 'th', 'tr'), $exclude);
3747
+		$node = end($this->stack);
3748
+		$elements = array_diff(array('dd', 'dt', 'li', 'p', 'td', 'th', 'tr'), $exclude);
3749 3749
 
3750
-        while(in_array(end($this->stack)->nodeName, $elements)) {
3751
-            array_pop($this->stack);
3752
-        }
3753
-    }
3750
+		while(in_array(end($this->stack)->nodeName, $elements)) {
3751
+			array_pop($this->stack);
3752
+		}
3753
+	}
3754 3754
 
3755
-    private function getElementCategory($node) {
3756
-        $name = $node->tagName;
3757
-        if(in_array($name, $this->special))
3758
-            return self::SPECIAL;
3755
+	private function getElementCategory($node) {
3756
+		$name = $node->tagName;
3757
+		if(in_array($name, $this->special))
3758
+			return self::SPECIAL;
3759 3759
 
3760
-        elseif(in_array($name, $this->scoping))
3761
-            return self::SCOPING;
3760
+		elseif(in_array($name, $this->scoping))
3761
+			return self::SCOPING;
3762 3762
 
3763
-        elseif(in_array($name, $this->formatting))
3764
-            return self::FORMATTING;
3763
+		elseif(in_array($name, $this->formatting))
3764
+			return self::FORMATTING;
3765 3765
 
3766
-        else
3767
-            return self::PHRASING;
3768
-    }
3766
+		else
3767
+			return self::PHRASING;
3768
+	}
3769 3769
 
3770
-    private function clearStackToTableContext($elements) {
3771
-        /* When the steps above require the UA to clear the stack back to a
3770
+	private function clearStackToTableContext($elements) {
3771
+		/* When the steps above require the UA to clear the stack back to a
3772 3772
         table context, it means that the UA must, while the current node is not
3773 3773
         a table element or an html element, pop elements from the stack of open
3774 3774
         elements. If this causes any elements to be popped from the stack, then
3775 3775
         this is a parse error. */
3776
-        while(true) {
3777
-            $node = end($this->stack)->nodeName;
3778
-
3779
-            if(in_array($node, $elements)) {
3780
-                break;
3781
-            } else {
3782
-                array_pop($this->stack);
3783
-            }
3784
-        }
3785
-    }
3786
-
3787
-    private function resetInsertionMode() {
3788
-        /* 1. Let last be false. */
3789
-        $last = false;
3790
-        $leng = count($this->stack);
3791
-
3792
-        for($n = $leng - 1; $n >= 0; $n--) {
3793
-            /* 2. Let node be the last node in the stack of open elements. */
3794
-            $node = $this->stack[$n];
3795
-
3796
-            /* 3. If node is the first node in the stack of open elements, then
3776
+		while(true) {
3777
+			$node = end($this->stack)->nodeName;
3778
+
3779
+			if(in_array($node, $elements)) {
3780
+				break;
3781
+			} else {
3782
+				array_pop($this->stack);
3783
+			}
3784
+		}
3785
+	}
3786
+
3787
+	private function resetInsertionMode() {
3788
+		/* 1. Let last be false. */
3789
+		$last = false;
3790
+		$leng = count($this->stack);
3791
+
3792
+		for($n = $leng - 1; $n >= 0; $n--) {
3793
+			/* 2. Let node be the last node in the stack of open elements. */
3794
+			$node = $this->stack[$n];
3795
+
3796
+			/* 3. If node is the first node in the stack of open elements, then
3797 3797
             set last to true. If the element whose innerHTML  attribute is being
3798 3798
             set is neither a td  element nor a th element, then set node to the
3799 3799
             element whose innerHTML  attribute is being set. (innerHTML  case) */
3800
-            if($this->stack[0]->isSameNode($node)) {
3801
-                $last = true;
3802
-            }
3800
+			if($this->stack[0]->isSameNode($node)) {
3801
+				$last = true;
3802
+			}
3803 3803
 
3804
-            /* 4. If node is a select element, then switch the insertion mode to
3804
+			/* 4. If node is a select element, then switch the insertion mode to
3805 3805
             "in select" and abort these steps. (innerHTML case) */
3806
-            if($node->nodeName === 'select') {
3807
-                $this->mode = self::IN_SELECT;
3808
-                break;
3806
+			if($node->nodeName === 'select') {
3807
+				$this->mode = self::IN_SELECT;
3808
+				break;
3809 3809
 
3810
-            /* 5. If node is a td or th element, then switch the insertion mode
3810
+			/* 5. If node is a td or th element, then switch the insertion mode
3811 3811
             to "in cell" and abort these steps. */
3812
-            } elseif($node->nodeName === 'td' || $node->nodeName === 'th') {
3813
-                $this->mode = self::IN_CELL;
3814
-                break;
3812
+			} elseif($node->nodeName === 'td' || $node->nodeName === 'th') {
3813
+				$this->mode = self::IN_CELL;
3814
+				break;
3815 3815
 
3816
-            /* 6. If node is a tr element, then switch the insertion mode to
3816
+			/* 6. If node is a tr element, then switch the insertion mode to
3817 3817
             "in    row" and abort these steps. */
3818
-            } elseif($node->nodeName === 'tr') {
3819
-                $this->mode = self::IN_ROW;
3820
-                break;
3818
+			} elseif($node->nodeName === 'tr') {
3819
+				$this->mode = self::IN_ROW;
3820
+				break;
3821 3821
 
3822
-            /* 7. If node is a tbody, thead, or tfoot element, then switch the
3822
+			/* 7. If node is a tbody, thead, or tfoot element, then switch the
3823 3823
             insertion mode to "in table body" and abort these steps. */
3824
-            } elseif(in_array($node->nodeName, array('tbody', 'thead', 'tfoot'))) {
3825
-                $this->mode = self::IN_TBODY;
3826
-                break;
3824
+			} elseif(in_array($node->nodeName, array('tbody', 'thead', 'tfoot'))) {
3825
+				$this->mode = self::IN_TBODY;
3826
+				break;
3827 3827
 
3828
-            /* 8. If node is a caption element, then switch the insertion mode
3828
+			/* 8. If node is a caption element, then switch the insertion mode
3829 3829
             to "in caption" and abort these steps. */
3830
-            } elseif($node->nodeName === 'caption') {
3831
-                $this->mode = self::IN_CAPTION;
3832
-                break;
3830
+			} elseif($node->nodeName === 'caption') {
3831
+				$this->mode = self::IN_CAPTION;
3832
+				break;
3833 3833
 
3834
-            /* 9. If node is a colgroup element, then switch the insertion mode
3834
+			/* 9. If node is a colgroup element, then switch the insertion mode
3835 3835
             to "in column group" and abort these steps. (innerHTML case) */
3836
-            } elseif($node->nodeName === 'colgroup') {
3837
-                $this->mode = self::IN_CGROUP;
3838
-                break;
3836
+			} elseif($node->nodeName === 'colgroup') {
3837
+				$this->mode = self::IN_CGROUP;
3838
+				break;
3839 3839
 
3840
-            /* 10. If node is a table element, then switch the insertion mode
3840
+			/* 10. If node is a table element, then switch the insertion mode
3841 3841
             to "in table" and abort these steps. */
3842
-            } elseif($node->nodeName === 'table') {
3843
-                $this->mode = self::IN_TABLE;
3844
-                break;
3842
+			} elseif($node->nodeName === 'table') {
3843
+				$this->mode = self::IN_TABLE;
3844
+				break;
3845 3845
 
3846
-            /* 11. If node is a head element, then switch the insertion mode
3846
+			/* 11. If node is a head element, then switch the insertion mode
3847 3847
             to "in body" ("in body"! not "in head"!) and abort these steps.
3848 3848
             (innerHTML case) */
3849
-            } elseif($node->nodeName === 'head') {
3850
-                $this->mode = self::IN_BODY;
3851
-                break;
3849
+			} elseif($node->nodeName === 'head') {
3850
+				$this->mode = self::IN_BODY;
3851
+				break;
3852 3852
 
3853
-            /* 12. If node is a body element, then switch the insertion mode to
3853
+			/* 12. If node is a body element, then switch the insertion mode to
3854 3854
             "in body" and abort these steps. */
3855
-            } elseif($node->nodeName === 'body') {
3856
-                $this->mode = self::IN_BODY;
3857
-                break;
3855
+			} elseif($node->nodeName === 'body') {
3856
+				$this->mode = self::IN_BODY;
3857
+				break;
3858 3858
 
3859
-            /* 13. If node is a frameset element, then switch the insertion
3859
+			/* 13. If node is a frameset element, then switch the insertion
3860 3860
             mode to "in frameset" and abort these steps. (innerHTML case) */
3861
-            } elseif($node->nodeName === 'frameset') {
3862
-                $this->mode = self::IN_FRAME;
3863
-                break;
3861
+			} elseif($node->nodeName === 'frameset') {
3862
+				$this->mode = self::IN_FRAME;
3863
+				break;
3864 3864
 
3865
-            /* 14. If node is an html element, then: if the head element
3865
+			/* 14. If node is an html element, then: if the head element
3866 3866
             pointer is null, switch the insertion mode to "before head",
3867 3867
             otherwise, switch the insertion mode to "after head". In either
3868 3868
             case, abort these steps. (innerHTML case) */
3869
-            } elseif($node->nodeName === 'html') {
3870
-                $this->mode = ($this->head_pointer === null)
3871
-                    ? self::BEFOR_HEAD
3872
-                    : self::AFTER_HEAD;
3869
+			} elseif($node->nodeName === 'html') {
3870
+				$this->mode = ($this->head_pointer === null)
3871
+					? self::BEFOR_HEAD
3872
+					: self::AFTER_HEAD;
3873 3873
 
3874
-                break;
3874
+				break;
3875 3875
 
3876
-            /* 15. If last is true, then set the insertion mode to "in body"
3876
+			/* 15. If last is true, then set the insertion mode to "in body"
3877 3877
             and    abort these steps. (innerHTML case) */
3878
-            } elseif($last) {
3879
-                $this->mode = self::IN_BODY;
3880
-                break;
3881
-            }
3882
-        }
3883
-    }
3884
-
3885
-    private function closeCell() {
3886
-        /* If the stack of open elements has a td or th element in table scope,
3878
+			} elseif($last) {
3879
+				$this->mode = self::IN_BODY;
3880
+				break;
3881
+			}
3882
+		}
3883
+	}
3884
+
3885
+	private function closeCell() {
3886
+		/* If the stack of open elements has a td or th element in table scope,
3887 3887
         then act as if an end tag token with that tag name had been seen. */
3888
-        foreach(array('td', 'th') as $cell) {
3889
-            if($this->elementInScope($cell, true)) {
3890
-                $this->inCell(array(
3891
-                    'name' => $cell,
3892
-                    'type' => HTML5::ENDTAG
3893
-                ));
3894
-
3895
-                break;
3896
-            }
3897
-        }
3898
-    }
3899
-
3900
-    public function save() {
3901
-        return $this->dom;
3902
-    }
3888
+		foreach(array('td', 'th') as $cell) {
3889
+			if($this->elementInScope($cell, true)) {
3890
+				$this->inCell(array(
3891
+					'name' => $cell,
3892
+					'type' => HTML5::ENDTAG
3893
+				));
3894
+
3895
+				break;
3896
+			}
3897
+		}
3898
+	}
3899
+
3900
+	public function save() {
3901
+		return $this->dom;
3902
+	}
3903 3903
 }
3904 3904
 ?>
Please login to merge, or discard this patch.
Braces   +18 added lines, -16 removed lines patch added patch discarded remove patch
@@ -3542,7 +3542,10 @@  discard block
 block discarded – undo
3542 3542
             // Remove leading hyphens and numbers
3543 3543
             $token['name'] = ltrim($token['name'], '-0..9');
3544 3544
             // In theory, this should ever be needed, but just in case
3545
-            if ($token['name'] === '') $token['name'] = 'span'; // arbitrary generic choice
3545
+            if ($token['name'] === '') {
3546
+            	$token['name'] = 'span';
3547
+            }
3548
+            // arbitrary generic choice
3546 3549
         }
3547 3550
         
3548 3551
         $el = $this->dom->createElement($token['name']);
@@ -3588,10 +3591,11 @@  discard block
 block discarded – undo
3588 3591
                 }
3589 3592
             }
3590 3593
 
3591
-            if(isset($table) && $this->foster_parent->isSameNode($table->parentNode))
3592
-                $this->foster_parent->insertBefore($node, $table);
3593
-            else
3594
-                $this->foster_parent->appendChild($node);
3594
+            if(isset($table) && $this->foster_parent->isSameNode($table->parentNode)) {
3595
+                            $this->foster_parent->insertBefore($node, $table);
3596
+            } else {
3597
+                            $this->foster_parent->appendChild($node);
3598
+            }
3595 3599
 
3596 3600
             $this->foster_parent = null;
3597 3601
         }
@@ -3754,17 +3758,15 @@  discard block
 block discarded – undo
3754 3758
 
3755 3759
     private function getElementCategory($node) {
3756 3760
         $name = $node->tagName;
3757
-        if(in_array($name, $this->special))
3758
-            return self::SPECIAL;
3759
-
3760
-        elseif(in_array($name, $this->scoping))
3761
-            return self::SCOPING;
3762
-
3763
-        elseif(in_array($name, $this->formatting))
3764
-            return self::FORMATTING;
3765
-
3766
-        else
3767
-            return self::PHRASING;
3761
+        if(in_array($name, $this->special)) {
3762
+                    return self::SPECIAL;
3763
+        } elseif(in_array($name, $this->scoping)) {
3764
+                    return self::SCOPING;
3765
+        } elseif(in_array($name, $this->formatting)) {
3766
+                    return self::FORMATTING;
3767
+        } else {
3768
+                    return self::PHRASING;
3769
+        }
3768 3770
     }
3769 3771
 
3770 3772
     private function clearStackToTableContext($elements) {
Please login to merge, or discard this patch.
Spacing   +384 added lines, -384 removed lines patch added patch discarded remove patch
@@ -69,48 +69,48 @@  discard block
 block discarded – undo
69 69
     private $token;
70 70
     private $content_model;
71 71
     private $escape = false;
72
-    private $entities = array('AElig;','AElig','AMP;','AMP','Aacute;','Aacute',
73
-    'Acirc;','Acirc','Agrave;','Agrave','Alpha;','Aring;','Aring','Atilde;',
74
-    'Atilde','Auml;','Auml','Beta;','COPY;','COPY','Ccedil;','Ccedil','Chi;',
75
-    'Dagger;','Delta;','ETH;','ETH','Eacute;','Eacute','Ecirc;','Ecirc','Egrave;',
76
-    'Egrave','Epsilon;','Eta;','Euml;','Euml','GT;','GT','Gamma;','Iacute;',
77
-    'Iacute','Icirc;','Icirc','Igrave;','Igrave','Iota;','Iuml;','Iuml','Kappa;',
78
-    'LT;','LT','Lambda;','Mu;','Ntilde;','Ntilde','Nu;','OElig;','Oacute;',
79
-    'Oacute','Ocirc;','Ocirc','Ograve;','Ograve','Omega;','Omicron;','Oslash;',
80
-    'Oslash','Otilde;','Otilde','Ouml;','Ouml','Phi;','Pi;','Prime;','Psi;',
81
-    'QUOT;','QUOT','REG;','REG','Rho;','Scaron;','Sigma;','THORN;','THORN',
82
-    'TRADE;','Tau;','Theta;','Uacute;','Uacute','Ucirc;','Ucirc','Ugrave;',
83
-    'Ugrave','Upsilon;','Uuml;','Uuml','Xi;','Yacute;','Yacute','Yuml;','Zeta;',
84
-    'aacute;','aacute','acirc;','acirc','acute;','acute','aelig;','aelig',
85
-    'agrave;','agrave','alefsym;','alpha;','amp;','amp','and;','ang;','apos;',
86
-    'aring;','aring','asymp;','atilde;','atilde','auml;','auml','bdquo;','beta;',
87
-    'brvbar;','brvbar','bull;','cap;','ccedil;','ccedil','cedil;','cedil',
88
-    'cent;','cent','chi;','circ;','clubs;','cong;','copy;','copy','crarr;',
89
-    'cup;','curren;','curren','dArr;','dagger;','darr;','deg;','deg','delta;',
90
-    'diams;','divide;','divide','eacute;','eacute','ecirc;','ecirc','egrave;',
91
-    'egrave','empty;','emsp;','ensp;','epsilon;','equiv;','eta;','eth;','eth',
92
-    'euml;','euml','euro;','exist;','fnof;','forall;','frac12;','frac12',
93
-    'frac14;','frac14','frac34;','frac34','frasl;','gamma;','ge;','gt;','gt',
94
-    'hArr;','harr;','hearts;','hellip;','iacute;','iacute','icirc;','icirc',
95
-    'iexcl;','iexcl','igrave;','igrave','image;','infin;','int;','iota;',
96
-    'iquest;','iquest','isin;','iuml;','iuml','kappa;','lArr;','lambda;','lang;',
97
-    'laquo;','laquo','larr;','lceil;','ldquo;','le;','lfloor;','lowast;','loz;',
98
-    'lrm;','lsaquo;','lsquo;','lt;','lt','macr;','macr','mdash;','micro;','micro',
99
-    'middot;','middot','minus;','mu;','nabla;','nbsp;','nbsp','ndash;','ne;',
100
-    'ni;','not;','not','notin;','nsub;','ntilde;','ntilde','nu;','oacute;',
101
-    'oacute','ocirc;','ocirc','oelig;','ograve;','ograve','oline;','omega;',
102
-    'omicron;','oplus;','or;','ordf;','ordf','ordm;','ordm','oslash;','oslash',
103
-    'otilde;','otilde','otimes;','ouml;','ouml','para;','para','part;','permil;',
104
-    'perp;','phi;','pi;','piv;','plusmn;','plusmn','pound;','pound','prime;',
105
-    'prod;','prop;','psi;','quot;','quot','rArr;','radic;','rang;','raquo;',
106
-    'raquo','rarr;','rceil;','rdquo;','real;','reg;','reg','rfloor;','rho;',
107
-    'rlm;','rsaquo;','rsquo;','sbquo;','scaron;','sdot;','sect;','sect','shy;',
108
-    'shy','sigma;','sigmaf;','sim;','spades;','sub;','sube;','sum;','sup1;',
109
-    'sup1','sup2;','sup2','sup3;','sup3','sup;','supe;','szlig;','szlig','tau;',
110
-    'there4;','theta;','thetasym;','thinsp;','thorn;','thorn','tilde;','times;',
111
-    'times','trade;','uArr;','uacute;','uacute','uarr;','ucirc;','ucirc',
112
-    'ugrave;','ugrave','uml;','uml','upsih;','upsilon;','uuml;','uuml','weierp;',
113
-    'xi;','yacute;','yacute','yen;','yen','yuml;','yuml','zeta;','zwj;','zwnj;');
72
+    private $entities = array('AElig;', 'AElig', 'AMP;', 'AMP', 'Aacute;', 'Aacute',
73
+    'Acirc;', 'Acirc', 'Agrave;', 'Agrave', 'Alpha;', 'Aring;', 'Aring', 'Atilde;',
74
+    'Atilde', 'Auml;', 'Auml', 'Beta;', 'COPY;', 'COPY', 'Ccedil;', 'Ccedil', 'Chi;',
75
+    'Dagger;', 'Delta;', 'ETH;', 'ETH', 'Eacute;', 'Eacute', 'Ecirc;', 'Ecirc', 'Egrave;',
76
+    'Egrave', 'Epsilon;', 'Eta;', 'Euml;', 'Euml', 'GT;', 'GT', 'Gamma;', 'Iacute;',
77
+    'Iacute', 'Icirc;', 'Icirc', 'Igrave;', 'Igrave', 'Iota;', 'Iuml;', 'Iuml', 'Kappa;',
78
+    'LT;', 'LT', 'Lambda;', 'Mu;', 'Ntilde;', 'Ntilde', 'Nu;', 'OElig;', 'Oacute;',
79
+    'Oacute', 'Ocirc;', 'Ocirc', 'Ograve;', 'Ograve', 'Omega;', 'Omicron;', 'Oslash;',
80
+    'Oslash', 'Otilde;', 'Otilde', 'Ouml;', 'Ouml', 'Phi;', 'Pi;', 'Prime;', 'Psi;',
81
+    'QUOT;', 'QUOT', 'REG;', 'REG', 'Rho;', 'Scaron;', 'Sigma;', 'THORN;', 'THORN',
82
+    'TRADE;', 'Tau;', 'Theta;', 'Uacute;', 'Uacute', 'Ucirc;', 'Ucirc', 'Ugrave;',
83
+    'Ugrave', 'Upsilon;', 'Uuml;', 'Uuml', 'Xi;', 'Yacute;', 'Yacute', 'Yuml;', 'Zeta;',
84
+    'aacute;', 'aacute', 'acirc;', 'acirc', 'acute;', 'acute', 'aelig;', 'aelig',
85
+    'agrave;', 'agrave', 'alefsym;', 'alpha;', 'amp;', 'amp', 'and;', 'ang;', 'apos;',
86
+    'aring;', 'aring', 'asymp;', 'atilde;', 'atilde', 'auml;', 'auml', 'bdquo;', 'beta;',
87
+    'brvbar;', 'brvbar', 'bull;', 'cap;', 'ccedil;', 'ccedil', 'cedil;', 'cedil',
88
+    'cent;', 'cent', 'chi;', 'circ;', 'clubs;', 'cong;', 'copy;', 'copy', 'crarr;',
89
+    'cup;', 'curren;', 'curren', 'dArr;', 'dagger;', 'darr;', 'deg;', 'deg', 'delta;',
90
+    'diams;', 'divide;', 'divide', 'eacute;', 'eacute', 'ecirc;', 'ecirc', 'egrave;',
91
+    'egrave', 'empty;', 'emsp;', 'ensp;', 'epsilon;', 'equiv;', 'eta;', 'eth;', 'eth',
92
+    'euml;', 'euml', 'euro;', 'exist;', 'fnof;', 'forall;', 'frac12;', 'frac12',
93
+    'frac14;', 'frac14', 'frac34;', 'frac34', 'frasl;', 'gamma;', 'ge;', 'gt;', 'gt',
94
+    'hArr;', 'harr;', 'hearts;', 'hellip;', 'iacute;', 'iacute', 'icirc;', 'icirc',
95
+    'iexcl;', 'iexcl', 'igrave;', 'igrave', 'image;', 'infin;', 'int;', 'iota;',
96
+    'iquest;', 'iquest', 'isin;', 'iuml;', 'iuml', 'kappa;', 'lArr;', 'lambda;', 'lang;',
97
+    'laquo;', 'laquo', 'larr;', 'lceil;', 'ldquo;', 'le;', 'lfloor;', 'lowast;', 'loz;',
98
+    'lrm;', 'lsaquo;', 'lsquo;', 'lt;', 'lt', 'macr;', 'macr', 'mdash;', 'micro;', 'micro',
99
+    'middot;', 'middot', 'minus;', 'mu;', 'nabla;', 'nbsp;', 'nbsp', 'ndash;', 'ne;',
100
+    'ni;', 'not;', 'not', 'notin;', 'nsub;', 'ntilde;', 'ntilde', 'nu;', 'oacute;',
101
+    'oacute', 'ocirc;', 'ocirc', 'oelig;', 'ograve;', 'ograve', 'oline;', 'omega;',
102
+    'omicron;', 'oplus;', 'or;', 'ordf;', 'ordf', 'ordm;', 'ordm', 'oslash;', 'oslash',
103
+    'otilde;', 'otilde', 'otimes;', 'ouml;', 'ouml', 'para;', 'para', 'part;', 'permil;',
104
+    'perp;', 'phi;', 'pi;', 'piv;', 'plusmn;', 'plusmn', 'pound;', 'pound', 'prime;',
105
+    'prod;', 'prop;', 'psi;', 'quot;', 'quot', 'rArr;', 'radic;', 'rang;', 'raquo;',
106
+    'raquo', 'rarr;', 'rceil;', 'rdquo;', 'real;', 'reg;', 'reg', 'rfloor;', 'rho;',
107
+    'rlm;', 'rsaquo;', 'rsquo;', 'sbquo;', 'scaron;', 'sdot;', 'sect;', 'sect', 'shy;',
108
+    'shy', 'sigma;', 'sigmaf;', 'sim;', 'spades;', 'sub;', 'sube;', 'sum;', 'sup1;',
109
+    'sup1', 'sup2;', 'sup2', 'sup3;', 'sup3', 'sup;', 'supe;', 'szlig;', 'szlig', 'tau;',
110
+    'there4;', 'theta;', 'thetasym;', 'thinsp;', 'thorn;', 'thorn', 'tilde;', 'times;',
111
+    'times', 'trade;', 'uArr;', 'uacute;', 'uacute', 'uarr;', 'ucirc;', 'ucirc',
112
+    'ugrave;', 'ugrave', 'uml;', 'uml', 'upsih;', 'upsilon;', 'uuml;', 'uuml', 'weierp;',
113
+    'xi;', 'yacute;', 'yacute', 'yen;', 'yen', 'yuml;', 'yuml', 'zeta;', 'zwj;', 'zwnj;');
114 114
 
115 115
     const PCDATA    = 0;
116 116
     const RCDATA    = 1;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
         $this->state = 'data';
136 136
 
137
-        while($this->state !== null) {
137
+        while ($this->state !== null) {
138 138
             $this->{$this->state.'State'}();
139 139
         }
140 140
     }
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
     }
151 151
 
152 152
     private function character($s, $l = 0) {
153
-        if($s + $l < $this->EOF) {
154
-            if($l === 0) {
153
+        if ($s + $l < $this->EOF) {
154
+            if ($l === 0) {
155 155
                 return $this->data[$s];
156 156
             } else {
157 157
                 return substr($this->data, $s, $l);
@@ -168,21 +168,21 @@  discard block
 block discarded – undo
168 168
         $this->char++;
169 169
         $char = $this->char();
170 170
 
171
-        if($char === '&' && ($this->content_model === self::PCDATA || $this->content_model === self::RCDATA)) {
171
+        if ($char === '&' && ($this->content_model === self::PCDATA || $this->content_model === self::RCDATA)) {
172 172
             /* U+0026 AMPERSAND (&)
173 173
             When the content model flag is set to one of the PCDATA or RCDATA
174 174
             states: switch to the entity data state. Otherwise: treat it as per
175 175
             the "anything else"    entry below. */
176 176
             $this->state = 'entityData';
177 177
 
178
-        } elseif($char === '-') {
178
+        } elseif ($char === '-') {
179 179
             /* If the content model flag is set to either the RCDATA state or
180 180
             the CDATA state, and the escape flag is false, and there are at
181 181
             least three characters before this one in the input stream, and the
182 182
             last four characters in the input stream, including this one, are
183 183
             U+003C LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
184 184
             and U+002D HYPHEN-MINUS ("<!--"), then set the escape flag to true. */
185
-            if(($this->content_model === self::RCDATA || $this->content_model ===
185
+            if (($this->content_model === self::RCDATA || $this->content_model ===
186 186
             self::CDATA) && $this->escape === false &&
187 187
             $this->char >= 3 && $this->character($this->char - 4, 4) === '<!--') {
188 188
                 $this->escape = true;
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
             ));
197 197
 
198 198
         /* U+003C LESS-THAN SIGN (<) */
199
-        } elseif($char === '<' && ($this->content_model === self::PCDATA ||
199
+        } elseif ($char === '<' && ($this->content_model === self::PCDATA ||
200 200
         (($this->content_model === self::RCDATA ||
201 201
         $this->content_model === self::CDATA) && $this->escape === false))) {
202 202
             /* When the content model flag is set to the PCDATA state: switch
@@ -210,13 +210,13 @@  discard block
 block discarded – undo
210 210
             $this->state = 'tagOpen';
211 211
 
212 212
         /* U+003E GREATER-THAN SIGN (>) */
213
-        } elseif($char === '>') {
213
+        } elseif ($char === '>') {
214 214
             /* If the content model flag is set to either the RCDATA state or
215 215
             the CDATA state, and the escape flag is true, and the last three
216 216
             characters in the input stream including this one are U+002D
217 217
             HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("-->"),
218 218
             set the escape flag to false. */
219
-            if(($this->content_model === self::RCDATA ||
219
+            if (($this->content_model === self::RCDATA ||
220 220
             $this->content_model === self::CDATA) && $this->escape === true &&
221 221
             $this->character($this->char, 3) === '-->') {
222 222
                 $this->escape = false;
@@ -229,12 +229,12 @@  discard block
 block discarded – undo
229 229
                 'data' => $char
230 230
             ));
231 231
 
232
-        } elseif($this->char === $this->EOF) {
232
+        } elseif ($this->char === $this->EOF) {
233 233
             /* EOF
234 234
             Emit an end-of-file token. */
235 235
             $this->EOF();
236 236
 
237
-        } elseif($this->content_model === self::PLAINTEXT) {
237
+        } elseif ($this->content_model === self::PLAINTEXT) {
238 238
             /* When the content model flag is set to the PLAINTEXT state
239 239
             THIS DIFFERS GREATLY FROM THE SPEC: Get the remaining characters of
240 240
             the text and emit it as a character token. */
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
     }
281 281
 
282 282
     private function tagOpenState() {
283
-        switch($this->content_model) {
283
+        switch ($this->content_model) {
284 284
             case self::RCDATA:
285 285
             case self::CDATA:
286 286
                 /* If the next input character is a U+002F SOLIDUS (/) character,
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 input character is not a U+002F SOLIDUS (/) character, emit a
289 289
                 U+003C LESS-THAN SIGN character token and switch to the data
290 290
                 state to process the next input character. */
291
-                if($this->character($this->char + 1) === '/') {
291
+                if ($this->character($this->char + 1) === '/') {
292 292
                     $this->char++;
293 293
                     $this->state = 'closeTagOpen';
294 294
 
@@ -308,17 +308,17 @@  discard block
 block discarded – undo
308 308
                 $this->char++;
309 309
                 $char = $this->char();
310 310
 
311
-                if($char === '!') {
311
+                if ($char === '!') {
312 312
                     /* U+0021 EXCLAMATION MARK (!)
313 313
                     Switch to the markup declaration open state. */
314 314
                     $this->state = 'markupDeclarationOpen';
315 315
 
316
-                } elseif($char === '/') {
316
+                } elseif ($char === '/') {
317 317
                     /* U+002F SOLIDUS (/)
318 318
                     Switch to the close tag open state. */
319 319
                     $this->state = 'closeTagOpen';
320 320
 
321
-                } elseif(preg_match('/^[A-Za-z]$/', $char)) {
321
+                } elseif (preg_match('/^[A-Za-z]$/', $char)) {
322 322
                     /* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
323 323
                     Create a new start tag token, set its tag name to the lowercase
324 324
                     version of the input character (add 0x0020 to the character's code
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 
333 333
                     $this->state = 'tagName';
334 334
 
335
-                } elseif($char === '>') {
335
+                } elseif ($char === '>') {
336 336
                     /* U+003E GREATER-THAN SIGN (>)
337 337
                     Parse error. Emit a U+003C LESS-THAN SIGN character token and a
338 338
                     U+003E GREATER-THAN SIGN character token. Switch to the data state. */
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 
344 344
                     $this->state = 'data';
345 345
 
346
-                } elseif($char === '?') {
346
+                } elseif ($char === '?') {
347 347
                     /* U+003F QUESTION MARK (?)
348 348
                     Parse error. Switch to the bogus comment state. */
349 349
                     $this->state = 'bogusComment';
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
         $next_node = strtolower($this->characters('A-Za-z', $this->char + 1));
369 369
         $the_same = count($this->tree->stack) > 0 && $next_node === end($this->tree->stack)->nodeName;
370 370
 
371
-        if(($this->content_model === self::RCDATA || $this->content_model === self::CDATA) &&
371
+        if (($this->content_model === self::RCDATA || $this->content_model === self::CDATA) &&
372 372
         (!$the_same || ($the_same && (!preg_match('/[\t\n\x0b\x0c >\/]/',
373 373
         $this->character($this->char + 1 + strlen($next_node))) || $this->EOF === $this->char)))) {
374 374
             /* If the content model flag is set to the RCDATA or CDATA states then
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
             $this->char++;
401 401
             $char = $this->char();
402 402
 
403
-            if(preg_match('/^[A-Za-z]$/', $char)) {
403
+            if (preg_match('/^[A-Za-z]$/', $char)) {
404 404
                 /* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
405 405
                 Create a new end tag token, set its tag name to the lowercase version
406 406
                 of the input character (add 0x0020 to the character's code point), then
@@ -413,12 +413,12 @@  discard block
 block discarded – undo
413 413
 
414 414
                 $this->state = 'tagName';
415 415
 
416
-            } elseif($char === '>') {
416
+            } elseif ($char === '>') {
417 417
                 /* U+003E GREATER-THAN SIGN (>)
418 418
                 Parse error. Switch to the data state. */
419 419
                 $this->state = 'data';
420 420
 
421
-            } elseif($this->char === $this->EOF) {
421
+            } elseif ($this->char === $this->EOF) {
422 422
                 /* EOF
423 423
                 Parse error. Emit a U+003C LESS-THAN SIGN character token and a U+002F
424 424
                 SOLIDUS character token. Reconsume the EOF character in the data state. */
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
         $this->char++;
443 443
         $char = $this->character($this->char);
444 444
 
445
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
445
+        if (preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
446 446
             /* U+0009 CHARACTER TABULATION
447 447
             U+000A LINE FEED (LF)
448 448
             U+000B LINE TABULATION
@@ -451,13 +451,13 @@  discard block
 block discarded – undo
451 451
             Switch to the before attribute name state. */
452 452
             $this->state = 'beforeAttributeName';
453 453
 
454
-        } elseif($char === '>') {
454
+        } elseif ($char === '>') {
455 455
             /* U+003E GREATER-THAN SIGN (>)
456 456
             Emit the current tag token. Switch to the data state. */
457 457
             $this->emitToken($this->token);
458 458
             $this->state = 'data';
459 459
 
460
-        } elseif($this->char === $this->EOF) {
460
+        } elseif ($this->char === $this->EOF) {
461 461
             /* EOF
462 462
             Parse error. Emit the current tag token. Reconsume the EOF
463 463
             character in the data state. */
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
             $this->char--;
467 467
             $this->state = 'data';
468 468
 
469
-        } elseif($char === '/') {
469
+        } elseif ($char === '/') {
470 470
             /* U+002F SOLIDUS (/)
471 471
             Parse error unless this is a permitted slash. Switch to the before
472 472
             attribute name state. */
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
         $this->char++;
487 487
         $char = $this->character($this->char);
488 488
 
489
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
489
+        if (preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
490 490
             /* U+0009 CHARACTER TABULATION
491 491
             U+000A LINE FEED (LF)
492 492
             U+000B LINE TABULATION
@@ -495,19 +495,19 @@  discard block
 block discarded – undo
495 495
             Stay in the before attribute name state. */
496 496
             $this->state = 'beforeAttributeName';
497 497
 
498
-        } elseif($char === '>') {
498
+        } elseif ($char === '>') {
499 499
             /* U+003E GREATER-THAN SIGN (>)
500 500
             Emit the current tag token. Switch to the data state. */
501 501
             $this->emitToken($this->token);
502 502
             $this->state = 'data';
503 503
 
504
-        } elseif($char === '/') {
504
+        } elseif ($char === '/') {
505 505
             /* U+002F SOLIDUS (/)
506 506
             Parse error unless this is a permitted slash. Stay in the before
507 507
             attribute name state. */
508 508
             $this->state = 'beforeAttributeName';
509 509
 
510
-        } elseif($this->char === $this->EOF) {
510
+        } elseif ($this->char === $this->EOF) {
511 511
             /* EOF
512 512
             Parse error. Emit the current tag token. Reconsume the EOF
513 513
             character in the data state. */
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
         $this->char++;
536 536
         $char = $this->character($this->char);
537 537
 
538
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
538
+        if (preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
539 539
             /* U+0009 CHARACTER TABULATION
540 540
             U+000A LINE FEED (LF)
541 541
             U+000B LINE TABULATION
@@ -544,24 +544,24 @@  discard block
 block discarded – undo
544 544
             Stay in the before attribute name state. */
545 545
             $this->state = 'afterAttributeName';
546 546
 
547
-        } elseif($char === '=') {
547
+        } elseif ($char === '=') {
548 548
             /* U+003D EQUALS SIGN (=)
549 549
             Switch to the before attribute value state. */
550 550
             $this->state = 'beforeAttributeValue';
551 551
 
552
-        } elseif($char === '>') {
552
+        } elseif ($char === '>') {
553 553
             /* U+003E GREATER-THAN SIGN (>)
554 554
             Emit the current tag token. Switch to the data state. */
555 555
             $this->emitToken($this->token);
556 556
             $this->state = 'data';
557 557
 
558
-        } elseif($char === '/' && $this->character($this->char + 1) !== '>') {
558
+        } elseif ($char === '/' && $this->character($this->char + 1) !== '>') {
559 559
             /* U+002F SOLIDUS (/)
560 560
             Parse error unless this is a permitted slash. Switch to the before
561 561
             attribute name state. */
562 562
             $this->state = 'beforeAttributeName';
563 563
 
564
-        } elseif($this->char === $this->EOF) {
564
+        } elseif ($this->char === $this->EOF) {
565 565
             /* EOF
566 566
             Parse error. Emit the current tag token. Reconsume the EOF
567 567
             character in the data state. */
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
         $this->char++;
587 587
         $char = $this->character($this->char);
588 588
 
589
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
589
+        if (preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
590 590
             /* U+0009 CHARACTER TABULATION
591 591
             U+000A LINE FEED (LF)
592 592
             U+000B LINE TABULATION
@@ -595,24 +595,24 @@  discard block
 block discarded – undo
595 595
             Stay in the after attribute name state. */
596 596
             $this->state = 'afterAttributeName';
597 597
 
598
-        } elseif($char === '=') {
598
+        } elseif ($char === '=') {
599 599
             /* U+003D EQUALS SIGN (=)
600 600
             Switch to the before attribute value state. */
601 601
             $this->state = 'beforeAttributeValue';
602 602
 
603
-        } elseif($char === '>') {
603
+        } elseif ($char === '>') {
604 604
             /* U+003E GREATER-THAN SIGN (>)
605 605
             Emit the current tag token. Switch to the data state. */
606 606
             $this->emitToken($this->token);
607 607
             $this->state = 'data';
608 608
 
609
-        } elseif($char === '/' && $this->character($this->char + 1) !== '>') {
609
+        } elseif ($char === '/' && $this->character($this->char + 1) !== '>') {
610 610
             /* U+002F SOLIDUS (/)
611 611
             Parse error unless this is a permitted slash. Switch to the
612 612
             before attribute name state. */
613 613
             $this->state = 'beforeAttributeName';
614 614
 
615
-        } elseif($this->char === $this->EOF) {
615
+        } elseif ($this->char === $this->EOF) {
616 616
             /* EOF
617 617
             Parse error. Emit the current tag token. Reconsume the EOF
618 618
             character in the data state. */
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
         $this->char++;
641 641
         $char = $this->character($this->char);
642 642
 
643
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
643
+        if (preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
644 644
             /* U+0009 CHARACTER TABULATION
645 645
             U+000A LINE FEED (LF)
646 646
             U+000B LINE TABULATION
@@ -649,24 +649,24 @@  discard block
 block discarded – undo
649 649
             Stay in the before attribute value state. */
650 650
             $this->state = 'beforeAttributeValue';
651 651
 
652
-        } elseif($char === '"') {
652
+        } elseif ($char === '"') {
653 653
             /* U+0022 QUOTATION MARK (")
654 654
             Switch to the attribute value (double-quoted) state. */
655 655
             $this->state = 'attributeValueDoubleQuoted';
656 656
 
657
-        } elseif($char === '&') {
657
+        } elseif ($char === '&') {
658 658
             /* U+0026 AMPERSAND (&)
659 659
             Switch to the attribute value (unquoted) state and reconsume
660 660
             this input character. */
661 661
             $this->char--;
662 662
             $this->state = 'attributeValueUnquoted';
663 663
 
664
-        } elseif($char === '\'') {
664
+        } elseif ($char === '\'') {
665 665
             /* U+0027 APOSTROPHE (')
666 666
             Switch to the attribute value (single-quoted) state. */
667 667
             $this->state = 'attributeValueSingleQuoted';
668 668
 
669
-        } elseif($char === '>') {
669
+        } elseif ($char === '>') {
670 670
             /* U+003E GREATER-THAN SIGN (>)
671 671
             Emit the current tag token. Switch to the data state. */
672 672
             $this->emitToken($this->token);
@@ -688,17 +688,17 @@  discard block
 block discarded – undo
688 688
         $this->char++;
689 689
         $char = $this->character($this->char);
690 690
 
691
-        if($char === '"') {
691
+        if ($char === '"') {
692 692
             /* U+0022 QUOTATION MARK (")
693 693
             Switch to the before attribute name state. */
694 694
             $this->state = 'beforeAttributeName';
695 695
 
696
-        } elseif($char === '&') {
696
+        } elseif ($char === '&') {
697 697
             /* U+0026 AMPERSAND (&)
698 698
             Switch to the entity in attribute value state. */
699 699
             $this->entityInAttributeValueState('double');
700 700
 
701
-        } elseif($this->char === $this->EOF) {
701
+        } elseif ($this->char === $this->EOF) {
702 702
             /* EOF
703 703
             Parse error. Emit the current tag token. Reconsume the character
704 704
             in the data state. */
@@ -723,17 +723,17 @@  discard block
 block discarded – undo
723 723
         $this->char++;
724 724
         $char = $this->character($this->char);
725 725
 
726
-        if($char === '\'') {
726
+        if ($char === '\'') {
727 727
             /* U+0022 QUOTATION MARK (')
728 728
             Switch to the before attribute name state. */
729 729
             $this->state = 'beforeAttributeName';
730 730
 
731
-        } elseif($char === '&') {
731
+        } elseif ($char === '&') {
732 732
             /* U+0026 AMPERSAND (&)
733 733
             Switch to the entity in attribute value state. */
734 734
             $this->entityInAttributeValueState('single');
735 735
 
736
-        } elseif($this->char === $this->EOF) {
736
+        } elseif ($this->char === $this->EOF) {
737 737
             /* EOF
738 738
             Parse error. Emit the current tag token. Reconsume the character
739 739
             in the data state. */
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
         $this->char++;
759 759
         $char = $this->character($this->char);
760 760
 
761
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
761
+        if (preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
762 762
             /* U+0009 CHARACTER TABULATION
763 763
             U+000A LINE FEED (LF)
764 764
             U+000B LINE TABULATION
@@ -767,12 +767,12 @@  discard block
 block discarded – undo
767 767
             Switch to the before attribute name state. */
768 768
             $this->state = 'beforeAttributeName';
769 769
 
770
-        } elseif($char === '&') {
770
+        } elseif ($char === '&') {
771 771
             /* U+0026 AMPERSAND (&)
772 772
             Switch to the entity in attribute value state. */
773 773
             $this->entityInAttributeValueState();
774 774
 
775
-        } elseif($char === '>') {
775
+        } elseif ($char === '>') {
776 776
             /* U+003E GREATER-THAN SIGN (>)
777 777
             Emit the current tag token. Switch to the data state. */
778 778
             $this->emitToken($this->token);
@@ -825,7 +825,7 @@  discard block
 block discarded – undo
825 825
         $this->state = 'data';
826 826
 
827 827
         /* If the end of the file was reached, reconsume the EOF character. */
828
-        if($this->char === $this->EOF) {
828
+        if ($this->char === $this->EOF) {
829 829
             $this->char = $this->EOF - 1;
830 830
         }
831 831
     }
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
         /* If the next two characters are both U+002D HYPHEN-MINUS (-)
835 835
         characters, consume those two characters, create a comment token whose
836 836
         data is the empty string, and switch to the comment state. */
837
-        if($this->character($this->char + 1, 2) === '--') {
837
+        if ($this->character($this->char + 1, 2) === '--') {
838 838
             $this->char += 2;
839 839
             $this->state = 'comment';
840 840
             $this->token = array(
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
         /* Otherwise if the next seven chacacters are a case-insensitive match
846 846
         for the word "DOCTYPE", then consume those characters and switch to the
847 847
         DOCTYPE state. */
848
-        } elseif(strtolower($this->character($this->char + 1, 7)) === 'doctype') {
848
+        } elseif (strtolower($this->character($this->char + 1, 7)) === 'doctype') {
849 849
             $this->char += 7;
850 850
             $this->state = 'doctype';
851 851
 
@@ -864,12 +864,12 @@  discard block
 block discarded – undo
864 864
         $char = $this->char();
865 865
 
866 866
         /* U+002D HYPHEN-MINUS (-) */
867
-        if($char === '-') {
867
+        if ($char === '-') {
868 868
             /* Switch to the comment dash state  */
869 869
             $this->state = 'commentDash';
870 870
 
871 871
         /* EOF */
872
-        } elseif($this->char === $this->EOF) {
872
+        } elseif ($this->char === $this->EOF) {
873 873
             /* Parse error. Emit the comment token. Reconsume the EOF character
874 874
             in the data state. */
875 875
             $this->emitToken($this->token);
@@ -890,12 +890,12 @@  discard block
 block discarded – undo
890 890
         $char = $this->char();
891 891
 
892 892
         /* U+002D HYPHEN-MINUS (-) */
893
-        if($char === '-') {
893
+        if ($char === '-') {
894 894
             /* Switch to the comment end state  */
895 895
             $this->state = 'commentEnd';
896 896
 
897 897
         /* EOF */
898
-        } elseif($this->char === $this->EOF) {
898
+        } elseif ($this->char === $this->EOF) {
899 899
             /* Parse error. Emit the comment token. Reconsume the EOF character
900 900
             in the data state. */
901 901
             $this->emitToken($this->token);
@@ -916,14 +916,14 @@  discard block
 block discarded – undo
916 916
         $this->char++;
917 917
         $char = $this->char();
918 918
 
919
-        if($char === '>') {
919
+        if ($char === '>') {
920 920
             $this->emitToken($this->token);
921 921
             $this->state = 'data';
922 922
 
923
-        } elseif($char === '-') {
923
+        } elseif ($char === '-') {
924 924
             $this->token['data'] .= '-';
925 925
 
926
-        } elseif($this->char === $this->EOF) {
926
+        } elseif ($this->char === $this->EOF) {
927 927
             $this->emitToken($this->token);
928 928
             $this->char--;
929 929
             $this->state = 'data';
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
         $this->char++;
940 940
         $char = $this->char();
941 941
 
942
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
942
+        if (preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
943 943
             $this->state = 'beforeDoctypeName';
944 944
 
945 945
         } else {
@@ -953,10 +953,10 @@  discard block
 block discarded – undo
953 953
         $this->char++;
954 954
         $char = $this->char();
955 955
 
956
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
956
+        if (preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
957 957
             // Stay in the before DOCTYPE name state.
958 958
 
959
-        } elseif(preg_match('/^[a-z]$/', $char)) {
959
+        } elseif (preg_match('/^[a-z]$/', $char)) {
960 960
             $this->token = array(
961 961
                 'name' => strtoupper($char),
962 962
                 'type' => self::DOCTYPE,
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
 
966 966
             $this->state = 'doctypeName';
967 967
 
968
-        } elseif($char === '>') {
968
+        } elseif ($char === '>') {
969 969
             $this->emitToken(array(
970 970
                 'name' => null,
971 971
                 'type' => self::DOCTYPE,
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
 
975 975
             $this->state = 'data';
976 976
 
977
-        } elseif($this->char === $this->EOF) {
977
+        } elseif ($this->char === $this->EOF) {
978 978
             $this->emitToken(array(
979 979
                 'name' => null,
980 980
                 'type' => self::DOCTYPE,
@@ -1000,17 +1000,17 @@  discard block
 block discarded – undo
1000 1000
         $this->char++;
1001 1001
         $char = $this->char();
1002 1002
 
1003
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
1003
+        if (preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
1004 1004
             $this->state = 'AfterDoctypeName';
1005 1005
 
1006
-        } elseif($char === '>') {
1006
+        } elseif ($char === '>') {
1007 1007
             $this->emitToken($this->token);
1008 1008
             $this->state = 'data';
1009 1009
 
1010
-        } elseif(preg_match('/^[a-z]$/', $char)) {
1010
+        } elseif (preg_match('/^[a-z]$/', $char)) {
1011 1011
             $this->token['name'] .= strtoupper($char);
1012 1012
 
1013
-        } elseif($this->char === $this->EOF) {
1013
+        } elseif ($this->char === $this->EOF) {
1014 1014
             $this->emitToken($this->token);
1015 1015
             $this->char--;
1016 1016
             $this->state = 'data';
@@ -1029,14 +1029,14 @@  discard block
 block discarded – undo
1029 1029
         $this->char++;
1030 1030
         $char = $this->char();
1031 1031
 
1032
-        if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
1032
+        if (preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
1033 1033
             // Stay in the DOCTYPE name state.
1034 1034
 
1035
-        } elseif($char === '>') {
1035
+        } elseif ($char === '>') {
1036 1036
             $this->emitToken($this->token);
1037 1037
             $this->state = 'data';
1038 1038
 
1039
-        } elseif($this->char === $this->EOF) {
1039
+        } elseif ($this->char === $this->EOF) {
1040 1040
             $this->emitToken($this->token);
1041 1041
             $this->char--;
1042 1042
             $this->state = 'data';
@@ -1052,11 +1052,11 @@  discard block
 block discarded – undo
1052 1052
         $this->char++;
1053 1053
         $char = $this->char();
1054 1054
 
1055
-        if($char === '>') {
1055
+        if ($char === '>') {
1056 1056
             $this->emitToken($this->token);
1057 1057
             $this->state = 'data';
1058 1058
 
1059
-        } elseif($this->char === $this->EOF) {
1059
+        } elseif ($this->char === $this->EOF) {
1060 1060
             $this->emitToken($this->token);
1061 1061
             $this->char--;
1062 1062
             $this->state = 'data';
@@ -1075,13 +1075,13 @@  discard block
 block discarded – undo
1075 1075
         // The behaviour depends on the identity of the next character (the
1076 1076
         // one immediately after the U+0026 AMPERSAND character): 
1077 1077
 
1078
-        switch($this->character($this->char + 1)) {
1078
+        switch ($this->character($this->char + 1)) {
1079 1079
             // U+0023 NUMBER SIGN (#)
1080 1080
             case '#':
1081 1081
 
1082 1082
                 // The behaviour further depends on the character after the
1083 1083
                 // U+0023 NUMBER SIGN:
1084
-                switch($this->character($this->char + 1)) {
1084
+                switch ($this->character($this->char + 1)) {
1085 1085
                     // U+0078 LATIN SMALL LETTER X
1086 1086
                     // U+0058 LATIN CAPITAL LETTER X
1087 1087
                     case 'x':
@@ -1124,12 +1124,12 @@  discard block
 block discarded – undo
1124 1124
                 $e_name = $this->characters('0-9A-Za-z;', $this->char + 1);
1125 1125
                 $len = strlen($e_name);
1126 1126
 
1127
-                for($c = 1; $c <= $len; $c++) {
1127
+                for ($c = 1; $c <= $len; $c++) {
1128 1128
                     $id = substr($e_name, 0, $c);
1129 1129
                     $this->char++;
1130 1130
 
1131
-                    if(in_array($id, $this->entities)) {
1132
-                        if ($e_name[$c-1] !== ';') {
1131
+                    if (in_array($id, $this->entities)) {
1132
+                        if ($e_name[$c - 1] !== ';') {
1133 1133
                             if ($c < $len && $e_name[$c] == ';') {
1134 1134
                                 $this->char++; // consume extra semicolon
1135 1135
                             }
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
             break;
1145 1145
         }
1146 1146
 
1147
-        if(!$cond) {
1147
+        if (!$cond) {
1148 1148
             // If no match can be made, then this is a parse error. No
1149 1149
             // characters are consumed, and nothing is returned.
1150 1150
             $this->char = $start;
@@ -1159,10 +1159,10 @@  discard block
 block discarded – undo
1159 1159
     private function emitToken($token) {
1160 1160
         $emit = $this->tree->emitToken($token);
1161 1161
 
1162
-        if(is_int($emit)) {
1162
+        if (is_int($emit)) {
1163 1163
             $this->content_model = $emit;
1164 1164
 
1165
-        } elseif($token['type'] === self::ENDTAG) {
1165
+        } elseif ($token['type'] === self::ENDTAG) {
1166 1166
             $this->content_model = self::PCDATA;
1167 1167
         }
1168 1168
     }
@@ -1187,15 +1187,15 @@  discard block
 block discarded – undo
1187 1187
     private $head_pointer = null;
1188 1188
     private $form_pointer = null;
1189 1189
 
1190
-    private $scoping = array('button','caption','html','marquee','object','table','td','th');
1191
-    private $formatting = array('a','b','big','em','font','i','nobr','s','small','strike','strong','tt','u');
1192
-    private $special = array('address','area','base','basefont','bgsound',
1193
-    'blockquote','body','br','center','col','colgroup','dd','dir','div','dl',
1194
-    'dt','embed','fieldset','form','frame','frameset','h1','h2','h3','h4','h5',
1195
-    'h6','head','hr','iframe','image','img','input','isindex','li','link',
1196
-    'listing','menu','meta','noembed','noframes','noscript','ol','optgroup',
1197
-    'option','p','param','plaintext','pre','script','select','spacer','style',
1198
-    'tbody','textarea','tfoot','thead','title','tr','ul','wbr');
1190
+    private $scoping = array('button', 'caption', 'html', 'marquee', 'object', 'table', 'td', 'th');
1191
+    private $formatting = array('a', 'b', 'big', 'em', 'font', 'i', 'nobr', 's', 'small', 'strike', 'strong', 'tt', 'u');
1192
+    private $special = array('address', 'area', 'base', 'basefont', 'bgsound',
1193
+    'blockquote', 'body', 'br', 'center', 'col', 'colgroup', 'dd', 'dir', 'div', 'dl',
1194
+    'dt', 'embed', 'fieldset', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5',
1195
+    'h6', 'head', 'hr', 'iframe', 'image', 'img', 'input', 'isindex', 'li', 'link',
1196
+    'listing', 'menu', 'meta', 'noembed', 'noframes', 'noscript', 'ol', 'optgroup',
1197
+    'option', 'p', 'param', 'plaintext', 'pre', 'script', 'select', 'spacer', 'style',
1198
+    'tbody', 'textarea', 'tfoot', 'thead', 'title', 'tr', 'ul', 'wbr');
1199 1199
 
1200 1200
     // The different phases.
1201 1201
     const INIT_PHASE = 0;
@@ -1240,7 +1240,7 @@  discard block
 block discarded – undo
1240 1240
 
1241 1241
     // Process tag tokens
1242 1242
     public function emitToken($token) {
1243
-        switch($this->phase) {
1243
+        switch ($this->phase) {
1244 1244
             case self::INIT_PHASE: return $this->initPhase($token); break;
1245 1245
             case self::ROOT_PHASE: return $this->rootElementPhase($token); break;
1246 1246
             case self::MAIN_PHASE: return $this->mainPhase($token); break;
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
             U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
1261 1261
             or U+0020 SPACE
1262 1262
         An end-of-file token */
1263
-        if((isset($token['error']) && $token['error']) ||
1263
+        if ((isset($token['error']) && $token['error']) ||
1264 1264
         $token['type'] === HTML5::COMMENT ||
1265 1265
         $token['type'] === HTML5::STARTTAG ||
1266 1266
         $token['type'] === HTML5::ENDTAG ||
@@ -1276,7 +1276,7 @@  discard block
 block discarded – undo
1276 1276
             return $this->rootElementPhase($token);
1277 1277
 
1278 1278
         /* A DOCTYPE token marked as being correct */
1279
-        } elseif(isset($token['error']) && !$token['error']) {
1279
+        } elseif (isset($token['error']) && !$token['error']) {
1280 1280
             /* Append a DocumentType node to the Document  node, with the name
1281 1281
             attribute set to the name given in the DOCTYPE token (which will be
1282 1282
             "HTML"), and the other attributes specific to DocumentType objects
@@ -1290,7 +1290,7 @@  discard block
 block discarded – undo
1290 1290
         /* A character token that is one of one of U+0009 CHARACTER TABULATION,
1291 1291
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
1292 1292
         or U+0020 SPACE */
1293
-        } elseif(isset($token['data']) && preg_match('/^[\t\n\x0b\x0c ]+$/',
1293
+        } elseif (isset($token['data']) && preg_match('/^[\t\n\x0b\x0c ]+$/',
1294 1294
         $token['data'])) {
1295 1295
             /* Append that character  to the Document node. */
1296 1296
             $text = $this->dom->createTextNode($token['data']);
@@ -1303,11 +1303,11 @@  discard block
 block discarded – undo
1303 1303
         stage, it must be processed as described in this section. */
1304 1304
 
1305 1305
         /* A DOCTYPE token */
1306
-        if($token['type'] === HTML5::DOCTYPE) {
1306
+        if ($token['type'] === HTML5::DOCTYPE) {
1307 1307
             // Parse error. Ignore the token.
1308 1308
 
1309 1309
         /* A comment token */
1310
-        } elseif($token['type'] === HTML5::COMMENT) {
1310
+        } elseif ($token['type'] === HTML5::COMMENT) {
1311 1311
             /* Append a Comment node to the Document object with the data
1312 1312
             attribute set to the data given in the comment token. */
1313 1313
             $comment = $this->dom->createComment($token['data']);
@@ -1316,7 +1316,7 @@  discard block
 block discarded – undo
1316 1316
         /* A character token that is one of one of U+0009 CHARACTER TABULATION,
1317 1317
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
1318 1318
         or U+0020 SPACE */
1319
-        } elseif($token['type'] === HTML5::CHARACTR &&
1319
+        } elseif ($token['type'] === HTML5::CHARACTR &&
1320 1320
         preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
1321 1321
             /* Append that character  to the Document node. */
1322 1322
             $text = $this->dom->createTextNode($token['data']);
@@ -1328,7 +1328,7 @@  discard block
 block discarded – undo
1328 1328
         A start tag token
1329 1329
         An end tag token
1330 1330
         An end-of-file token */
1331
-        } elseif(($token['type'] === HTML5::CHARACTR &&
1331
+        } elseif (($token['type'] === HTML5::CHARACTR &&
1332 1332
         !preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) ||
1333 1333
         $token['type'] === HTML5::STARTTAG ||
1334 1334
         $token['type'] === HTML5::ENDTAG ||
@@ -1349,11 +1349,11 @@  discard block
 block discarded – undo
1349 1349
         /* Tokens in the main phase must be handled as follows: */
1350 1350
 
1351 1351
         /* A DOCTYPE token */
1352
-        if($token['type'] === HTML5::DOCTYPE) {
1352
+        if ($token['type'] === HTML5::DOCTYPE) {
1353 1353
             // Parse error. Ignore the token.
1354 1354
 
1355 1355
         /* A start tag token with the tag name "html" */
1356
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'html') {
1356
+        } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'html') {
1357 1357
             /* If this start tag token was not the first start tag token, then
1358 1358
             it is a parse error. */
1359 1359
 
@@ -1361,21 +1361,21 @@  discard block
 block discarded – undo
1361 1361
             is already present on the top element of the stack of open elements.
1362 1362
             If it is not, add the attribute and its corresponding value to that
1363 1363
             element. */
1364
-            foreach($token['attr'] as $attr) {
1365
-                if(!$this->stack[0]->hasAttribute($attr['name'])) {
1364
+            foreach ($token['attr'] as $attr) {
1365
+                if (!$this->stack[0]->hasAttribute($attr['name'])) {
1366 1366
                     $this->stack[0]->setAttribute($attr['name'], $attr['value']);
1367 1367
                 }
1368 1368
             }
1369 1369
 
1370 1370
         /* An end-of-file token */
1371
-        } elseif($token['type'] === HTML5::EOF) {
1371
+        } elseif ($token['type'] === HTML5::EOF) {
1372 1372
             /* Generate implied end tags. */
1373 1373
             $this->generateImpliedEndTags();
1374 1374
 
1375 1375
         /* Anything else. */
1376 1376
         } else {
1377 1377
             /* Depends on the insertion mode: */
1378
-            switch($this->mode) {
1378
+            switch ($this->mode) {
1379 1379
                 case self::BEFOR_HEAD: return $this->beforeHead($token); break;
1380 1380
                 case self::IN_HEAD:    return $this->inHead($token); break;
1381 1381
                 case self::AFTER_HEAD: return $this->afterHead($token); break;
@@ -1401,19 +1401,19 @@  discard block
 block discarded – undo
1401 1401
         /* A character token that is one of one of U+0009 CHARACTER TABULATION,
1402 1402
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
1403 1403
         or U+0020 SPACE */
1404
-        if($token['type'] === HTML5::CHARACTR &&
1404
+        if ($token['type'] === HTML5::CHARACTR &&
1405 1405
         preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
1406 1406
             /* Append the character to the current node. */
1407 1407
             $this->insertText($token['data']);
1408 1408
 
1409 1409
         /* A comment token */
1410
-        } elseif($token['type'] === HTML5::COMMENT) {
1410
+        } elseif ($token['type'] === HTML5::COMMENT) {
1411 1411
             /* Append a Comment node to the current node with the data attribute
1412 1412
             set to the data given in the comment token. */
1413 1413
             $this->insertComment($token['data']);
1414 1414
 
1415 1415
         /* A start tag token with the tag name "head" */
1416
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') {
1416
+        } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') {
1417 1417
             /* Create an element for the token, append the new element to the
1418 1418
             current node and push it onto the stack of open elements. */
1419 1419
             $element = $this->insertElement($token);
@@ -1429,7 +1429,7 @@  discard block
 block discarded – undo
1429 1429
         Or a character token that is not one of U+0009 CHARACTER TABULATION,
1430 1430
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
1431 1431
         or U+0020 SPACE. Or any other start tag token */
1432
-        } elseif($token['type'] === HTML5::STARTTAG ||
1432
+        } elseif ($token['type'] === HTML5::STARTTAG ||
1433 1433
         ($token['type'] === HTML5::ENDTAG && $token['name'] === 'html') ||
1434 1434
         ($token['type'] === HTML5::CHARACTR && !preg_match('/^[\t\n\x0b\x0c ]$/',
1435 1435
         $token['data']))) {
@@ -1444,7 +1444,7 @@  discard block
 block discarded – undo
1444 1444
             return $this->inHead($token);
1445 1445
 
1446 1446
         /* Any other end tag */
1447
-        } elseif($token['type'] === HTML5::ENDTAG) {
1447
+        } elseif ($token['type'] === HTML5::ENDTAG) {
1448 1448
             /* Parse error. Ignore the token. */
1449 1449
         }
1450 1450
     }
@@ -1459,7 +1459,7 @@  discard block
 block discarded – undo
1459 1459
         THIS DIFFERS FROM THE SPEC: If the current node is either a title, style
1460 1460
         or script element, append the character to the current node regardless
1461 1461
         of its content. */
1462
-        if(($token['type'] === HTML5::CHARACTR &&
1462
+        if (($token['type'] === HTML5::CHARACTR &&
1463 1463
         preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) || (
1464 1464
         $token['type'] === HTML5::CHARACTR && in_array(end($this->stack)->nodeName,
1465 1465
         array('title', 'style', 'script')))) {
@@ -1467,22 +1467,22 @@  discard block
 block discarded – undo
1467 1467
             $this->insertText($token['data']);
1468 1468
 
1469 1469
         /* A comment token */
1470
-        } elseif($token['type'] === HTML5::COMMENT) {
1470
+        } elseif ($token['type'] === HTML5::COMMENT) {
1471 1471
             /* Append a Comment node to the current node with the data attribute
1472 1472
             set to the data given in the comment token. */
1473 1473
             $this->insertComment($token['data']);
1474 1474
 
1475
-        } elseif($token['type'] === HTML5::ENDTAG &&
1475
+        } elseif ($token['type'] === HTML5::ENDTAG &&
1476 1476
         in_array($token['name'], array('title', 'style', 'script'))) {
1477 1477
             array_pop($this->stack);
1478 1478
             return HTML5::PCDATA;
1479 1479
 
1480 1480
         /* A start tag with the tag name "title" */
1481
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'title') {
1481
+        } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'title') {
1482 1482
             /* Create an element for the token and append the new element to the
1483 1483
             node pointed to by the head element pointer, or, if that is null
1484 1484
             (innerHTML case), to the current node. */
1485
-            if($this->head_pointer !== null) {
1485
+            if ($this->head_pointer !== null) {
1486 1486
                 $element = $this->insertElement($token, false);
1487 1487
                 $this->head_pointer->appendChild($element);
1488 1488
 
@@ -1494,11 +1494,11 @@  discard block
 block discarded – undo
1494 1494
             return HTML5::RCDATA;
1495 1495
 
1496 1496
         /* A start tag with the tag name "style" */
1497
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'style') {
1497
+        } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'style') {
1498 1498
             /* Create an element for the token and append the new element to the
1499 1499
             node pointed to by the head element pointer, or, if that is null
1500 1500
             (innerHTML case), to the current node. */
1501
-            if($this->head_pointer !== null) {
1501
+            if ($this->head_pointer !== null) {
1502 1502
                 $element = $this->insertElement($token, false);
1503 1503
                 $this->head_pointer->appendChild($element);
1504 1504
 
@@ -1510,7 +1510,7 @@  discard block
 block discarded – undo
1510 1510
             return HTML5::CDATA;
1511 1511
 
1512 1512
         /* A start tag with the tag name "script" */
1513
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'script') {
1513
+        } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'script') {
1514 1514
             /* Create an element for the token. */
1515 1515
             $element = $this->insertElement($token, false);
1516 1516
             $this->head_pointer->appendChild($element);
@@ -1519,12 +1519,12 @@  discard block
 block discarded – undo
1519 1519
             return HTML5::CDATA;
1520 1520
 
1521 1521
         /* A start tag with the tag name "base", "link", or "meta" */
1522
-        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
1522
+        } elseif ($token['type'] === HTML5::STARTTAG && in_array($token['name'],
1523 1523
         array('base', 'link', 'meta'))) {
1524 1524
             /* Create an element for the token and append the new element to the
1525 1525
             node pointed to by the head element pointer, or, if that is null
1526 1526
             (innerHTML case), to the current node. */
1527
-            if($this->head_pointer !== null) {
1527
+            if ($this->head_pointer !== null) {
1528 1528
                 $element = $this->insertElement($token, false);
1529 1529
                 $this->head_pointer->appendChild($element);
1530 1530
                 array_pop($this->stack);
@@ -1534,10 +1534,10 @@  discard block
 block discarded – undo
1534 1534
             }
1535 1535
 
1536 1536
         /* An end tag with the tag name "head" */
1537
-        } elseif($token['type'] === HTML5::ENDTAG && $token['name'] === 'head') {
1537
+        } elseif ($token['type'] === HTML5::ENDTAG && $token['name'] === 'head') {
1538 1538
             /* If the current node is a head element, pop the current node off
1539 1539
             the stack of open elements. */
1540
-            if($this->head_pointer->isSameNode(end($this->stack))) {
1540
+            if ($this->head_pointer->isSameNode(end($this->stack))) {
1541 1541
                 array_pop($this->stack);
1542 1542
 
1543 1543
             /* Otherwise, this is a parse error. */
@@ -1549,7 +1549,7 @@  discard block
 block discarded – undo
1549 1549
             $this->mode = self::AFTER_HEAD;
1550 1550
 
1551 1551
         /* A start tag with the tag name "head" or an end tag except "html". */
1552
-        } elseif(($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') ||
1552
+        } elseif (($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') ||
1553 1553
         ($token['type'] === HTML5::ENDTAG && $token['name'] !== 'html')) {
1554 1554
             // Parse error. Ignore the token.
1555 1555
 
@@ -1557,7 +1557,7 @@  discard block
 block discarded – undo
1557 1557
         } else {
1558 1558
             /* If the current node is a head element, act as if an end tag
1559 1559
             token with the tag name "head" had been seen. */
1560
-            if($this->head_pointer->isSameNode(end($this->stack))) {
1560
+            if ($this->head_pointer->isSameNode(end($this->stack))) {
1561 1561
                 $this->inHead(array(
1562 1562
                     'name' => 'head',
1563 1563
                     'type' => HTML5::ENDTAG
@@ -1579,19 +1579,19 @@  discard block
 block discarded – undo
1579 1579
         /* A character token that is one of one of U+0009 CHARACTER TABULATION,
1580 1580
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
1581 1581
         or U+0020 SPACE */
1582
-        if($token['type'] === HTML5::CHARACTR &&
1582
+        if ($token['type'] === HTML5::CHARACTR &&
1583 1583
         preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
1584 1584
             /* Append the character to the current node. */
1585 1585
             $this->insertText($token['data']);
1586 1586
 
1587 1587
         /* A comment token */
1588
-        } elseif($token['type'] === HTML5::COMMENT) {
1588
+        } elseif ($token['type'] === HTML5::COMMENT) {
1589 1589
             /* Append a Comment node to the current node with the data attribute
1590 1590
             set to the data given in the comment token. */
1591 1591
             $this->insertComment($token['data']);
1592 1592
 
1593 1593
         /* A start tag token with the tag name "body" */
1594
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'body') {
1594
+        } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'body') {
1595 1595
             /* Insert a body element for the token. */
1596 1596
             $this->insertElement($token);
1597 1597
 
@@ -1599,7 +1599,7 @@  discard block
 block discarded – undo
1599 1599
             $this->mode = self::IN_BODY;
1600 1600
 
1601 1601
         /* A start tag token with the tag name "frameset" */
1602
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'frameset') {
1602
+        } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'frameset') {
1603 1603
             /* Insert a frameset element for the token. */
1604 1604
             $this->insertElement($token);
1605 1605
 
@@ -1608,7 +1608,7 @@  discard block
 block discarded – undo
1608 1608
 
1609 1609
         /* A start tag token whose tag name is one of: "base", "link", "meta",
1610 1610
         "script", "style", "title" */
1611
-        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
1611
+        } elseif ($token['type'] === HTML5::STARTTAG && in_array($token['name'],
1612 1612
         array('base', 'link', 'meta', 'script', 'style', 'title'))) {
1613 1613
             /* Parse error. Switch the insertion mode back to "in head" and
1614 1614
             reprocess the token. */
@@ -1632,7 +1632,7 @@  discard block
 block discarded – undo
1632 1632
     private function inBody($token) {
1633 1633
         /* Handle the token as follows: */
1634 1634
 
1635
-        switch($token['type']) {
1635
+        switch ($token['type']) {
1636 1636
             /* A character token */
1637 1637
             case HTML5::CHARACTR:
1638 1638
                 /* Reconstruct the active formatting elements, if any. */
@@ -1650,7 +1650,7 @@  discard block
 block discarded – undo
1650 1650
             break;
1651 1651
 
1652 1652
             case HTML5::STARTTAG:
1653
-            switch($token['name']) {
1653
+            switch ($token['name']) {
1654 1654
                 /* A start tag token whose tag name is one of: "script",
1655 1655
                 "style" */
1656 1656
                 case 'script': case 'style':
@@ -1673,7 +1673,7 @@  discard block
 block discarded – undo
1673 1673
                     elements is not a body element, or, if the stack of open
1674 1674
                     elements has only one node on it, then ignore the token.
1675 1675
                     (innerHTML case) */
1676
-                    if(count($this->stack) === 1 || $this->stack[1]->nodeName !== 'body') {
1676
+                    if (count($this->stack) === 1 || $this->stack[1]->nodeName !== 'body') {
1677 1677
                         // Ignore
1678 1678
 
1679 1679
                     /* Otherwise, for each attribute on the token, check to see
@@ -1682,8 +1682,8 @@  discard block
 block discarded – undo
1682 1682
                     add the attribute and its corresponding value to that
1683 1683
                     element. */
1684 1684
                     } else {
1685
-                        foreach($token['attr'] as $attr) {
1686
-                            if(!$this->stack[1]->hasAttribute($attr['name'])) {
1685
+                        foreach ($token['attr'] as $attr) {
1686
+                            if (!$this->stack[1]->hasAttribute($attr['name'])) {
1687 1687
                                 $this->stack[1]->setAttribute($attr['name'], $attr['value']);
1688 1688
                             }
1689 1689
                         }
@@ -1699,7 +1699,7 @@  discard block
 block discarded – undo
1699 1699
                     /* If the stack of open elements has a p element in scope,
1700 1700
                     then act as if an end tag with the tag name p had been
1701 1701
                     seen. */
1702
-                    if($this->elementInScope('p')) {
1702
+                    if ($this->elementInScope('p')) {
1703 1703
                         $this->emitToken(array(
1704 1704
                             'name' => 'p',
1705 1705
                             'type' => HTML5::ENDTAG
@@ -1714,7 +1714,7 @@  discard block
 block discarded – undo
1714 1714
                 case 'form':
1715 1715
                     /* If the form element pointer is not null, ignore the
1716 1716
                     token with a parse error. */
1717
-                    if($this->form_pointer !== null) {
1717
+                    if ($this->form_pointer !== null) {
1718 1718
                         // Ignore.
1719 1719
 
1720 1720
                     /* Otherwise: */
@@ -1722,7 +1722,7 @@  discard block
 block discarded – undo
1722 1722
                         /* If the stack of open elements has a p element in
1723 1723
                         scope, then act as if an end tag with the tag name p
1724 1724
                         had been seen. */
1725
-                        if($this->elementInScope('p')) {
1725
+                        if ($this->elementInScope('p')) {
1726 1726
                             $this->emitToken(array(
1727 1727
                                 'name' => 'p',
1728 1728
                                 'type' => HTML5::ENDTAG
@@ -1741,7 +1741,7 @@  discard block
 block discarded – undo
1741 1741
                     /* If the stack of open elements has a p  element in scope,
1742 1742
                     then act as if an end tag with the tag name p had been
1743 1743
                     seen. */
1744
-                    if($this->elementInScope('p')) {
1744
+                    if ($this->elementInScope('p')) {
1745 1745
                         $this->emitToken(array(
1746 1746
                             'name' => 'p',
1747 1747
                             'type' => HTML5::ENDTAG
@@ -1750,7 +1750,7 @@  discard block
 block discarded – undo
1750 1750
 
1751 1751
                     $stack_length = count($this->stack) - 1;
1752 1752
 
1753
-                    for($n = $stack_length; 0 <= $n; $n--) {
1753
+                    for ($n = $stack_length; 0 <= $n; $n--) {
1754 1754
                         /* 1. Initialise node to be the current node (the
1755 1755
                         bottommost node of the stack). */
1756 1756
                         $stop = false;
@@ -1760,9 +1760,9 @@  discard block
 block discarded – undo
1760 1760
                         /* 2. If node is an li, dd or dt element, then pop all
1761 1761
                         the    nodes from the current node up to node, including
1762 1762
                         node, then stop this algorithm. */
1763
-                        if($token['name'] === $node->tagName ||    ($token['name'] !== 'li'
1763
+                        if ($token['name'] === $node->tagName || ($token['name'] !== 'li'
1764 1764
                         && ($node->tagName === 'dd' || $node->tagName === 'dt'))) {
1765
-                            for($x = $stack_length; $x >= $n ; $x--) {
1765
+                            for ($x = $stack_length; $x >= $n; $x--) {
1766 1766
                                 array_pop($this->stack);
1767 1767
                             }
1768 1768
 
@@ -1772,7 +1772,7 @@  discard block
 block discarded – undo
1772 1772
                         /* 3. If node is not in the formatting category, and is
1773 1773
                         not    in the phrasing category, and is not an address or
1774 1774
                         div element, then stop this algorithm. */
1775
-                        if($cat !== self::FORMATTING && $cat !== self::PHRASING &&
1775
+                        if ($cat !== self::FORMATTING && $cat !== self::PHRASING &&
1776 1776
                         $node->tagName !== 'address' && $node->tagName !== 'div') {
1777 1777
                             break;
1778 1778
                         }
@@ -1788,7 +1788,7 @@  discard block
 block discarded – undo
1788 1788
                     /* If the stack of open elements has a p  element in scope,
1789 1789
                     then act as if an end tag with the tag name p had been
1790 1790
                     seen. */
1791
-                    if($this->elementInScope('p')) {
1791
+                    if ($this->elementInScope('p')) {
1792 1792
                         $this->emitToken(array(
1793 1793
                             'name' => 'p',
1794 1794
                             'type' => HTML5::ENDTAG
@@ -1806,7 +1806,7 @@  discard block
 block discarded – undo
1806 1806
                 case 'h1': case 'h2': case 'h3': case 'h4': case 'h5': case 'h6':
1807 1807
                     /* If the stack of open elements has a p  element in scope,
1808 1808
                     then act as if an end tag with the tag name p had been seen. */
1809
-                    if($this->elementInScope('p')) {
1809
+                    if ($this->elementInScope('p')) {
1810 1810
                         $this->emitToken(array(
1811 1811
                             'name' => 'p',
1812 1812
                             'type' => HTML5::ENDTAG
@@ -1818,7 +1818,7 @@  discard block
 block discarded – undo
1818 1818
                     this is a parse error; pop elements from the stack until an
1819 1819
                     element with one of those tag names has been popped from the
1820 1820
                     stack. */
1821
-                    while($this->elementInScope(array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'))) {
1821
+                    while ($this->elementInScope(array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'))) {
1822 1822
                         array_pop($this->stack);
1823 1823
                     }
1824 1824
 
@@ -1839,11 +1839,11 @@  discard block
 block discarded – undo
1839 1839
                     might not have if the element is not in table scope). */
1840 1840
                     $leng = count($this->a_formatting);
1841 1841
 
1842
-                    for($n = $leng - 1; $n >= 0; $n--) {
1843
-                        if($this->a_formatting[$n] === self::MARKER) {
1842
+                    for ($n = $leng - 1; $n >= 0; $n--) {
1843
+                        if ($this->a_formatting[$n] === self::MARKER) {
1844 1844
                             break;
1845 1845
 
1846
-                        } elseif($this->a_formatting[$n]->nodeName === 'a') {
1846
+                        } elseif ($this->a_formatting[$n]->nodeName === 'a') {
1847 1847
                             $this->emitToken(array(
1848 1848
                                 'name' => 'a',
1849 1849
                                 'type' => HTML5::ENDTAG
@@ -1885,7 +1885,7 @@  discard block
 block discarded – undo
1885 1885
                     then this is a parse error; act as if an end tag with the tag
1886 1886
                     name "button" had been seen, then reprocess the token. (We don't
1887 1887
                     do that. Unnecessary.) */
1888
-                    if($this->elementInScope('button')) {
1888
+                    if ($this->elementInScope('button')) {
1889 1889
                         $this->inBody(array(
1890 1890
                             'name' => 'button',
1891 1891
                             'type' => HTML5::ENDTAG
@@ -1932,7 +1932,7 @@  discard block
 block discarded – undo
1932 1932
                 case 'table':
1933 1933
                     /* If the stack of open elements has a p element in scope,
1934 1934
                     then act as if an end tag with the tag name p had been seen. */
1935
-                    if($this->elementInScope('p')) {
1935
+                    if ($this->elementInScope('p')) {
1936 1936
                         $this->emitToken(array(
1937 1937
                             'name' => 'p',
1938 1938
                             'type' => HTML5::ENDTAG
@@ -1965,7 +1965,7 @@  discard block
 block discarded – undo
1965 1965
                 case 'hr':
1966 1966
                     /* If the stack of open elements has a p element in scope,
1967 1967
                     then act as if an end tag with the tag name p had been seen. */
1968
-                    if($this->elementInScope('p')) {
1968
+                    if ($this->elementInScope('p')) {
1969 1969
                         $this->emitToken(array(
1970 1970
                             'name' => 'p',
1971 1971
                             'type' => HTML5::ENDTAG
@@ -2013,7 +2013,7 @@  discard block
 block discarded – undo
2013 2013
 
2014 2014
                     /* If the form element pointer is not null,
2015 2015
                     then ignore the token. */
2016
-                    if($this->form_pointer === null) {
2016
+                    if ($this->form_pointer === null) {
2017 2017
                         /* Act as if a start tag token with the tag name "form" had
2018 2018
                         been seen. */
2019 2019
                         $this->inBody(array(
@@ -2158,18 +2158,18 @@  discard block
 block discarded – undo
2158 2158
             break;
2159 2159
 
2160 2160
             case HTML5::ENDTAG:
2161
-            switch($token['name']) {
2161
+            switch ($token['name']) {
2162 2162
                 /* An end tag with the tag name "body" */
2163 2163
                 case 'body':
2164 2164
                     /* If the second element in the stack of open elements is
2165 2165
                     not a body element, this is a parse error. Ignore the token.
2166 2166
                     (innerHTML case) */
2167
-                    if(count($this->stack) < 2 || $this->stack[1]->nodeName !== 'body') {
2167
+                    if (count($this->stack) < 2 || $this->stack[1]->nodeName !== 'body') {
2168 2168
                         // Ignore.
2169 2169
 
2170 2170
                     /* If the current node is not the body element, then this
2171 2171
                     is a parse error. */
2172
-                    } elseif(end($this->stack)->nodeName !== 'body') {
2172
+                    } elseif (end($this->stack)->nodeName !== 'body') {
2173 2173
                         // Parse error.
2174 2174
                     }
2175 2175
 
@@ -2199,7 +2199,7 @@  discard block
 block discarded – undo
2199 2199
                     /* If the stack of open elements has an element in scope
2200 2200
                     with the same tag name as that of the token, then generate
2201 2201
                     implied end tags. */
2202
-                    if($this->elementInScope($token['name'])) {
2202
+                    if ($this->elementInScope($token['name'])) {
2203 2203
                         $this->generateImpliedEndTags();
2204 2204
 
2205 2205
                         /* Now, if the current node is not an element with
@@ -2211,8 +2211,8 @@  discard block
 block discarded – undo
2211 2211
                         scope with the same tag name as that of the token,
2212 2212
                         then pop elements from this stack until an element
2213 2213
                         with that tag name has been popped from the stack. */
2214
-                        for($n = count($this->stack) - 1; $n >= 0; $n--) {
2215
-                            if($this->stack[$n]->nodeName === $token['name']) {
2214
+                        for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2215
+                            if ($this->stack[$n]->nodeName === $token['name']) {
2216 2216
                                 $n = -1;
2217 2217
                             }
2218 2218
 
@@ -2226,12 +2226,12 @@  discard block
 block discarded – undo
2226 2226
                     /* If the stack of open elements has an element in scope
2227 2227
                     with the same tag name as that of the token, then generate
2228 2228
                     implied    end tags. */
2229
-                    if($this->elementInScope($token['name'])) {
2229
+                    if ($this->elementInScope($token['name'])) {
2230 2230
                         $this->generateImpliedEndTags();
2231 2231
 
2232 2232
                     } 
2233 2233
 
2234
-                    if(end($this->stack)->nodeName !== $token['name']) {
2234
+                    if (end($this->stack)->nodeName !== $token['name']) {
2235 2235
                         /* Now, if the current node is not an element with the
2236 2236
                         same tag name as that of the token, then this is a parse
2237 2237
                         error. */
@@ -2252,7 +2252,7 @@  discard block
 block discarded – undo
2252 2252
                 case 'p':
2253 2253
                     /* If the stack of open elements has a p element in scope,
2254 2254
                     then generate implied end tags, except for p elements. */
2255
-                    if($this->elementInScope('p')) {
2255
+                    if ($this->elementInScope('p')) {
2256 2256
                         $this->generateImpliedEndTags(array('p'));
2257 2257
 
2258 2258
                         /* If the current node is not a p element, then this is
@@ -2262,8 +2262,8 @@  discard block
 block discarded – undo
2262 2262
                         /* If the stack of open elements has a p element in
2263 2263
                         scope, then pop elements from this stack until the stack
2264 2264
                         no longer has a p element in scope. */
2265
-                        for($n = count($this->stack) - 1; $n >= 0; $n--) {
2266
-                            if($this->elementInScope('p')) {
2265
+                        for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2266
+                            if ($this->elementInScope('p')) {
2267 2267
                                 array_pop($this->stack);
2268 2268
 
2269 2269
                             } else {
@@ -2279,7 +2279,7 @@  discard block
 block discarded – undo
2279 2279
                     whose tag name matches the tag name of the token, then
2280 2280
                     generate implied end tags, except for elements with the
2281 2281
                     same tag name as the token. */
2282
-                    if($this->elementInScope($token['name'])) {
2282
+                    if ($this->elementInScope($token['name'])) {
2283 2283
                         $this->generateImpliedEndTags(array($token['name']));
2284 2284
 
2285 2285
                         /* If the current node is not an element with the same
@@ -2290,8 +2290,8 @@  discard block
 block discarded – undo
2290 2290
                         whose tag name matches the tag name of the token, then
2291 2291
                         pop elements from this stack until an element with that
2292 2292
                         tag name has been popped from the stack. */
2293
-                        for($n = count($this->stack) - 1; $n >= 0; $n--) {
2294
-                            if($this->stack[$n]->nodeName === $token['name']) {
2293
+                        for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2294
+                            if ($this->stack[$n]->nodeName === $token['name']) {
2295 2295
                                 $n = -1;
2296 2296
                             }
2297 2297
 
@@ -2308,7 +2308,7 @@  discard block
 block discarded – undo
2308 2308
                     /* If the stack of open elements has in scope an element whose
2309 2309
                     tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6", then
2310 2310
                     generate implied end tags. */
2311
-                    if($this->elementInScope($elements)) {
2311
+                    if ($this->elementInScope($elements)) {
2312 2312
                         $this->generateImpliedEndTags();
2313 2313
 
2314 2314
                         /* Now, if the current node is not an element with the same
@@ -2319,7 +2319,7 @@  discard block
 block discarded – undo
2319 2319
                         whose tag name is one of "h1", "h2", "h3", "h4", "h5", or
2320 2320
                         "h6", then pop elements from the stack until an element
2321 2321
                         with one of those tag names has been popped from the stack. */
2322
-                        while($this->elementInScope($elements)) {
2322
+                        while ($this->elementInScope($elements)) {
2323 2323
                             array_pop($this->stack);
2324 2324
                         }
2325 2325
                     }
@@ -2337,12 +2337,12 @@  discard block
 block discarded – undo
2337 2337
                         otherwise, and
2338 2338
                         * has the same tag name as the token.
2339 2339
                     */
2340
-                    while(true) {
2341
-                        for($a = count($this->a_formatting) - 1; $a >= 0; $a--) {
2342
-                            if($this->a_formatting[$a] === self::MARKER) {
2340
+                    while (true) {
2341
+                        for ($a = count($this->a_formatting) - 1; $a >= 0; $a--) {
2342
+                            if ($this->a_formatting[$a] === self::MARKER) {
2343 2343
                                 break;
2344 2344
 
2345
-                            } elseif($this->a_formatting[$a]->tagName === $token['name']) {
2345
+                            } elseif ($this->a_formatting[$a]->tagName === $token['name']) {
2346 2346
                                 $formatting_element = $this->a_formatting[$a];
2347 2347
                                 $in_stack = in_array($formatting_element, $this->stack, true);
2348 2348
                                 $fe_af_pos = $a;
@@ -2354,7 +2354,7 @@  discard block
 block discarded – undo
2354 2354
                         also in the stack of open elements but the element
2355 2355
                         is not in scope, then this is a parse error. Abort
2356 2356
                         these steps. The token is ignored. */
2357
-                        if(!isset($formatting_element) || ($in_stack &&
2357
+                        if (!isset($formatting_element) || ($in_stack &&
2358 2358
                         !$this->elementInScope($token['name']))) {
2359 2359
                             break;
2360 2360
 
@@ -2362,7 +2362,7 @@  discard block
 block discarded – undo
2362 2362
                         is not in the stack of open elements, then this is a
2363 2363
                         parse error; remove the element from the list, and
2364 2364
                         abort these steps. */
2365
-                        } elseif(isset($formatting_element) && !$in_stack) {
2365
+                        } elseif (isset($formatting_element) && !$in_stack) {
2366 2366
                             unset($this->a_formatting[$fe_af_pos]);
2367 2367
                             $this->a_formatting = array_merge($this->a_formatting);
2368 2368
                             break;
@@ -2376,10 +2376,10 @@  discard block
 block discarded – undo
2376 2376
                         $fe_s_pos = array_search($formatting_element, $this->stack, true);
2377 2377
                         $length = count($this->stack);
2378 2378
 
2379
-                        for($s = $fe_s_pos + 1; $s < $length; $s++) {
2379
+                        for ($s = $fe_s_pos + 1; $s < $length; $s++) {
2380 2380
                             $category = $this->getElementCategory($this->stack[$s]->nodeName);
2381 2381
 
2382
-                            if($category !== self::PHRASING && $category !== self::FORMATTING) {
2382
+                            if ($category !== self::PHRASING && $category !== self::FORMATTING) {
2383 2383
                                 $furthest_block = $this->stack[$s];
2384 2384
                             }
2385 2385
                         }
@@ -2390,8 +2390,8 @@  discard block
 block discarded – undo
2390 2390
                         elements, from the current node up to the formatting
2391 2391
                         element, and remove the formatting element from the
2392 2392
                         list of active formatting elements. */
2393
-                        if(!isset($furthest_block)) {
2394
-                            for($n = $length - 1; $n >= $fe_s_pos; $n--) {
2393
+                        if (!isset($furthest_block)) {
2394
+                            for ($n = $length - 1; $n >= $fe_s_pos; $n--) {
2395 2395
                                 array_pop($this->stack);
2396 2396
                             }
2397 2397
 
@@ -2407,7 +2407,7 @@  discard block
 block discarded – undo
2407 2407
 
2408 2408
                         /* 5. If the furthest block has a parent node, then
2409 2409
                         remove the furthest block from its parent node. */
2410
-                        if($furthest_block->parentNode !== null) {
2410
+                        if ($furthest_block->parentNode !== null) {
2411 2411
                             $furthest_block->parentNode->removeChild($furthest_block);
2412 2412
                         }
2413 2413
 
@@ -2422,8 +2422,8 @@  discard block
 block discarded – undo
2422 2422
                         $node = $furthest_block;
2423 2423
                         $last_node = $furthest_block;
2424 2424
 
2425
-                        while(true) {
2426
-                            for($n = array_search($node, $this->stack, true) - 1; $n >= 0; $n--) {
2425
+                        while (true) {
2426
+                            for ($n = array_search($node, $this->stack, true) - 1; $n >= 0; $n--) {
2427 2427
                                 /* 7.1 Let node be the element immediately
2428 2428
                                 prior to node in the stack of open elements. */
2429 2429
                                 $node = $this->stack[$n];
@@ -2432,7 +2432,7 @@  discard block
 block discarded – undo
2432 2432
                                 formatting elements, then remove node from
2433 2433
                                 the stack of open elements and then go back
2434 2434
                                 to step 1. */
2435
-                                if(!in_array($node, $this->a_formatting, true)) {
2435
+                                if (!in_array($node, $this->a_formatting, true)) {
2436 2436
                                     unset($this->stack[$n]);
2437 2437
                                     $this->stack = array_merge($this->stack);
2438 2438
 
@@ -2444,14 +2444,14 @@  discard block
 block discarded – undo
2444 2444
                             /* 7.3 Otherwise, if node is the formatting
2445 2445
                             element, then go to the next step in the overall
2446 2446
                             algorithm. */
2447
-                            if($node === $formatting_element) {
2447
+                            if ($node === $formatting_element) {
2448 2448
                                 break;
2449 2449
 
2450 2450
                             /* 7.4 Otherwise, if last node is the furthest
2451 2451
                             block, then move the aforementioned bookmark to
2452 2452
                             be immediately after the node in the list of
2453 2453
                             active formatting elements. */
2454
-                            } elseif($last_node === $furthest_block) {
2454
+                            } elseif ($last_node === $furthest_block) {
2455 2455
                                 $bookmark = array_search($node, $this->a_formatting, true) + 1;
2456 2456
                             }
2457 2457
 
@@ -2461,7 +2461,7 @@  discard block
 block discarded – undo
2461 2461
                             with an entry for the clone, replace the entry
2462 2462
                             for node in the stack of open elements with an
2463 2463
                             entry for the clone, and let node be the clone. */
2464
-                            if($node->hasChildNodes()) {
2464
+                            if ($node->hasChildNodes()) {
2465 2465
                                 $clone = $node->cloneNode();
2466 2466
                                 $s_pos = array_search($node, $this->stack, true);
2467 2467
                                 $a_pos = array_search($node, $this->a_formatting, true);
@@ -2473,7 +2473,7 @@  discard block
 block discarded – undo
2473 2473
 
2474 2474
                             /* 7.6 Insert last node into node, first removing
2475 2475
                             it from its previous parent node if any. */
2476
-                            if($last_node->parentNode !== null) {
2476
+                            if ($last_node->parentNode !== null) {
2477 2477
                                 $last_node->parentNode->removeChild($last_node);
2478 2478
                             }
2479 2479
 
@@ -2487,7 +2487,7 @@  discard block
 block discarded – undo
2487 2487
                         the previous step into the common ancestor node,
2488 2488
                         first removing it from its previous parent node if
2489 2489
                         any. */
2490
-                        if($last_node->parentNode !== null) {
2490
+                        if ($last_node->parentNode !== null) {
2491 2491
                             $last_node->parentNode->removeChild($last_node);
2492 2492
                         }
2493 2493
 
@@ -2500,7 +2500,7 @@  discard block
 block discarded – undo
2500 2500
                         /* 10. Take all of the child nodes of the furthest
2501 2501
                         block and append them to the clone created in the
2502 2502
                         last step. */
2503
-                        while($furthest_block->hasChildNodes()) {
2503
+                        while ($furthest_block->hasChildNodes()) {
2504 2504
                             $child = $furthest_block->firstChild;
2505 2505
                             $furthest_block->removeChild($child);
2506 2506
                             $clone->appendChild($child);
@@ -2545,7 +2545,7 @@  discard block
 block discarded – undo
2545 2545
                     /* If the stack of open elements has an element in scope whose
2546 2546
                     tag name matches the tag name of the token, then generate implied
2547 2547
                     tags. */
2548
-                    if($this->elementInScope($token['name'])) {
2548
+                    if ($this->elementInScope($token['name'])) {
2549 2549
                         $this->generateImpliedEndTags();
2550 2550
 
2551 2551
                         /* Now, if the current node is not an element with the same
@@ -2557,8 +2557,8 @@  discard block
 block discarded – undo
2557 2557
                         elements from the stack until that element has been popped from
2558 2558
                         the stack, and clear the list of active formatting elements up
2559 2559
                         to the last marker. */
2560
-                        for($n = count($this->stack) - 1; $n >= 0; $n--) {
2561
-                            if($this->stack[$n]->nodeName === $token['name']) {
2560
+                        for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2561
+                            if ($this->stack[$n]->nodeName === $token['name']) {
2562 2562
                                 $n = -1;
2563 2563
                             }
2564 2564
 
@@ -2567,7 +2567,7 @@  discard block
 block discarded – undo
2567 2567
 
2568 2568
                         $marker = end(array_keys($this->a_formatting, self::MARKER, true));
2569 2569
 
2570
-                        for($n = count($this->a_formatting) - 1; $n > $marker; $n--) {
2570
+                        for ($n = count($this->a_formatting) - 1; $n > $marker; $n--) {
2571 2571
                             array_pop($this->a_formatting);
2572 2572
                         }
2573 2573
                     }
@@ -2587,14 +2587,14 @@  discard block
 block discarded – undo
2587 2587
 
2588 2588
                 /* An end tag token not covered by the previous entries */
2589 2589
                 default:
2590
-                    for($n = count($this->stack) - 1; $n >= 0; $n--) {
2590
+                    for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2591 2591
                         /* Initialise node to be the current node (the bottommost
2592 2592
                         node of the stack). */
2593 2593
                         $node = end($this->stack);
2594 2594
 
2595 2595
                         /* If node has the same tag name as the end tag token,
2596 2596
                         then: */
2597
-                        if($token['name'] === $node->nodeName) {
2597
+                        if ($token['name'] === $node->nodeName) {
2598 2598
                             /* Generate implied end tags. */
2599 2599
                             $this->generateImpliedEndTags();
2600 2600
 
@@ -2605,14 +2605,14 @@  discard block
 block discarded – undo
2605 2605
 
2606 2606
                             /* Pop all the nodes from the current node up to
2607 2607
                             node, including node, then stop this algorithm. */
2608
-                            for($x = count($this->stack) - $n; $x >= $n; $x--) {
2608
+                            for ($x = count($this->stack) - $n; $x >= $n; $x--) {
2609 2609
                                 array_pop($this->stack);
2610 2610
                             }
2611 2611
                                     
2612 2612
                         } else {
2613 2613
                             $category = $this->getElementCategory($node);
2614 2614
 
2615
-                            if($category !== self::SPECIAL && $category !== self::SCOPING) {
2615
+                            if ($category !== self::SPECIAL && $category !== self::SCOPING) {
2616 2616
                                 /* Otherwise, if node is in neither the formatting
2617 2617
                                 category nor the phrasing category, then this is a
2618 2618
                                 parse error. Stop this algorithm. The end tag token
@@ -2633,21 +2633,21 @@  discard block
 block discarded – undo
2633 2633
         /* A character token that is one of one of U+0009 CHARACTER TABULATION,
2634 2634
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
2635 2635
         or U+0020 SPACE */
2636
-        if($token['type'] === HTML5::CHARACTR &&
2636
+        if ($token['type'] === HTML5::CHARACTR &&
2637 2637
         preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
2638 2638
             /* Append the character to the current node. */
2639 2639
             $text = $this->dom->createTextNode($token['data']);
2640 2640
             end($this->stack)->appendChild($text);
2641 2641
 
2642 2642
         /* A comment token */
2643
-        } elseif($token['type'] === HTML5::COMMENT) {
2643
+        } elseif ($token['type'] === HTML5::COMMENT) {
2644 2644
             /* Append a Comment node to the current node with the data
2645 2645
             attribute set to the data given in the comment token. */
2646 2646
             $comment = $this->dom->createComment($token['data']);
2647 2647
             end($this->stack)->appendChild($comment);
2648 2648
 
2649 2649
         /* A start tag whose tag name is "caption" */
2650
-        } elseif($token['type'] === HTML5::STARTTAG &&
2650
+        } elseif ($token['type'] === HTML5::STARTTAG &&
2651 2651
         $token['name'] === 'caption') {
2652 2652
             /* Clear the stack back to a table context. */
2653 2653
             $this->clearStackToTableContext($clear);
@@ -2662,7 +2662,7 @@  discard block
 block discarded – undo
2662 2662
             $this->mode = self::IN_CAPTION;
2663 2663
 
2664 2664
         /* A start tag whose tag name is "colgroup" */
2665
-        } elseif($token['type'] === HTML5::STARTTAG &&
2665
+        } elseif ($token['type'] === HTML5::STARTTAG &&
2666 2666
         $token['name'] === 'colgroup') {
2667 2667
             /* Clear the stack back to a table context. */
2668 2668
             $this->clearStackToTableContext($clear);
@@ -2673,7 +2673,7 @@  discard block
 block discarded – undo
2673 2673
             $this->mode = self::IN_CGROUP;
2674 2674
 
2675 2675
         /* A start tag whose tag name is "col" */
2676
-        } elseif($token['type'] === HTML5::STARTTAG &&
2676
+        } elseif ($token['type'] === HTML5::STARTTAG &&
2677 2677
         $token['name'] === 'col') {
2678 2678
             $this->inTable(array(
2679 2679
                 'name' => 'colgroup',
@@ -2684,7 +2684,7 @@  discard block
 block discarded – undo
2684 2684
             $this->inColumnGroup($token);
2685 2685
 
2686 2686
         /* A start tag whose tag name is one of: "tbody", "tfoot", "thead" */
2687
-        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
2687
+        } elseif ($token['type'] === HTML5::STARTTAG && in_array($token['name'],
2688 2688
         array('tbody', 'tfoot', 'thead'))) {
2689 2689
             /* Clear the stack back to a table context. */
2690 2690
             $this->clearStackToTableContext($clear);
@@ -2695,7 +2695,7 @@  discard block
 block discarded – undo
2695 2695
             $this->mode = self::IN_TBODY;
2696 2696
 
2697 2697
         /* A start tag whose tag name is one of: "td", "th", "tr" */
2698
-        } elseif($token['type'] === HTML5::STARTTAG &&
2698
+        } elseif ($token['type'] === HTML5::STARTTAG &&
2699 2699
         in_array($token['name'], array('td', 'th', 'tr'))) {
2700 2700
             /* Act as if a start tag token with the tag name "tbody" had been
2701 2701
             seen, then reprocess the current token. */
@@ -2708,7 +2708,7 @@  discard block
 block discarded – undo
2708 2708
             return $this->inTableBody($token);
2709 2709
 
2710 2710
         /* A start tag whose tag name is "table" */
2711
-        } elseif($token['type'] === HTML5::STARTTAG &&
2711
+        } elseif ($token['type'] === HTML5::STARTTAG &&
2712 2712
         $token['name'] === 'table') {
2713 2713
             /* Parse error. Act as if an end tag token with the tag name "table"
2714 2714
             had been seen, then, if that token wasn't ignored, reprocess the
@@ -2721,12 +2721,12 @@  discard block
 block discarded – undo
2721 2721
             return $this->mainPhase($token);
2722 2722
 
2723 2723
         /* An end tag whose tag name is "table" */
2724
-        } elseif($token['type'] === HTML5::ENDTAG &&
2724
+        } elseif ($token['type'] === HTML5::ENDTAG &&
2725 2725
         $token['name'] === 'table') {
2726 2726
             /* If the stack of open elements does not have an element in table
2727 2727
             scope with the same tag name as the token, this is a parse error.
2728 2728
             Ignore the token. (innerHTML case) */
2729
-            if(!$this->elementInScope($token['name'], true)) {
2729
+            if (!$this->elementInScope($token['name'], true)) {
2730 2730
                 return false;
2731 2731
 
2732 2732
             /* Otherwise: */
@@ -2740,11 +2740,11 @@  discard block
 block discarded – undo
2740 2740
 
2741 2741
                 /* Pop elements from this stack until a table element has been
2742 2742
                 popped from the stack. */
2743
-                while(true) {
2743
+                while (true) {
2744 2744
                     $current = end($this->stack)->nodeName;
2745 2745
                     array_pop($this->stack);
2746 2746
 
2747
-                    if($current === 'table') {
2747
+                    if ($current === 'table') {
2748 2748
                         break;
2749 2749
                     }
2750 2750
                 }
@@ -2755,7 +2755,7 @@  discard block
 block discarded – undo
2755 2755
 
2756 2756
         /* An end tag whose tag name is one of: "body", "caption", "col",
2757 2757
         "colgroup", "html", "tbody", "td", "tfoot", "th", "thead", "tr" */
2758
-        } elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
2758
+        } elseif ($token['type'] === HTML5::ENDTAG && in_array($token['name'],
2759 2759
         array('body', 'caption', 'col', 'colgroup', 'html', 'tbody', 'td',
2760 2760
         'tfoot', 'th', 'thead', 'tr'))) {
2761 2761
             // Parse error. Ignore the token.
@@ -2768,7 +2768,7 @@  discard block
 block discarded – undo
2768 2768
             /* If the current node is a table, tbody, tfoot, thead, or tr
2769 2769
             element, then, whenever a node would be inserted into the current
2770 2770
             node, it must instead be inserted into the foster parent element. */
2771
-            if(in_array(end($this->stack)->nodeName,
2771
+            if (in_array(end($this->stack)->nodeName,
2772 2772
             array('table', 'tbody', 'tfoot', 'thead', 'tr'))) {
2773 2773
                 /* The foster parent element is the parent element of the last
2774 2774
                 table element in the stack of open elements, if there is a
@@ -2781,20 +2781,20 @@  discard block
 block discarded – undo
2781 2781
                 its parent node is not an element, then the foster parent
2782 2782
                 element is the element before the last table element in the
2783 2783
                 stack of open elements. */
2784
-                for($n = count($this->stack) - 1; $n >= 0; $n--) {
2785
-                    if($this->stack[$n]->nodeName === 'table') {
2784
+                for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2785
+                    if ($this->stack[$n]->nodeName === 'table') {
2786 2786
                         $table = $this->stack[$n];
2787 2787
                         break;
2788 2788
                     }
2789 2789
                 }
2790 2790
 
2791
-                if(isset($table) && $table->parentNode !== null) {
2791
+                if (isset($table) && $table->parentNode !== null) {
2792 2792
                     $this->foster_parent = $table->parentNode;
2793 2793
 
2794
-                } elseif(!isset($table)) {
2794
+                } elseif (!isset($table)) {
2795 2795
                     $this->foster_parent = $this->stack[0];
2796 2796
 
2797
-                } elseif(isset($table) && ($table->parentNode === null ||
2797
+                } elseif (isset($table) && ($table->parentNode === null ||
2798 2798
                 $table->parentNode->nodeType !== XML_ELEMENT_NODE)) {
2799 2799
                     $this->foster_parent = $this->stack[$n - 1];
2800 2800
                 }
@@ -2806,11 +2806,11 @@  discard block
 block discarded – undo
2806 2806
 
2807 2807
     private function inCaption($token) {
2808 2808
         /* An end tag whose tag name is "caption" */
2809
-        if($token['type'] === HTML5::ENDTAG && $token['name'] === 'caption') {
2809
+        if ($token['type'] === HTML5::ENDTAG && $token['name'] === 'caption') {
2810 2810
             /* If the stack of open elements does not have an element in table
2811 2811
             scope with the same tag name as the token, this is a parse error.
2812 2812
             Ignore the token. (innerHTML case) */
2813
-            if(!$this->elementInScope($token['name'], true)) {
2813
+            if (!$this->elementInScope($token['name'], true)) {
2814 2814
                 // Ignore
2815 2815
 
2816 2816
             /* Otherwise: */
@@ -2824,11 +2824,11 @@  discard block
 block discarded – undo
2824 2824
 
2825 2825
                 /* Pop elements from this stack until a caption element has
2826 2826
                 been popped from the stack. */
2827
-                while(true) {
2827
+                while (true) {
2828 2828
                     $node = end($this->stack)->nodeName;
2829 2829
                     array_pop($this->stack);
2830 2830
 
2831
-                    if($node === 'caption') {
2831
+                    if ($node === 'caption') {
2832 2832
                         break;
2833 2833
                     }
2834 2834
                 }
@@ -2844,7 +2844,7 @@  discard block
 block discarded – undo
2844 2844
         /* A start tag whose tag name is one of: "caption", "col", "colgroup",
2845 2845
         "tbody", "td", "tfoot", "th", "thead", "tr", or an end tag whose tag
2846 2846
         name is "table" */
2847
-        } elseif(($token['type'] === HTML5::STARTTAG && in_array($token['name'],
2847
+        } elseif (($token['type'] === HTML5::STARTTAG && in_array($token['name'],
2848 2848
         array('caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
2849 2849
         'thead', 'tr'))) || ($token['type'] === HTML5::ENDTAG &&
2850 2850
         $token['name'] === 'table')) {
@@ -2860,7 +2860,7 @@  discard block
 block discarded – undo
2860 2860
 
2861 2861
         /* An end tag whose tag name is one of: "body", "col", "colgroup",
2862 2862
         "html", "tbody", "td", "tfoot", "th", "thead", "tr" */
2863
-        } elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
2863
+        } elseif ($token['type'] === HTML5::ENDTAG && in_array($token['name'],
2864 2864
         array('body', 'col', 'colgroup', 'html', 'tbody', 'tfoot', 'th',
2865 2865
         'thead', 'tr'))) {
2866 2866
             // Parse error. Ignore the token.
@@ -2876,32 +2876,32 @@  discard block
 block discarded – undo
2876 2876
         /* A character token that is one of one of U+0009 CHARACTER TABULATION,
2877 2877
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
2878 2878
         or U+0020 SPACE */
2879
-        if($token['type'] === HTML5::CHARACTR &&
2879
+        if ($token['type'] === HTML5::CHARACTR &&
2880 2880
         preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
2881 2881
             /* Append the character to the current node. */
2882 2882
             $text = $this->dom->createTextNode($token['data']);
2883 2883
             end($this->stack)->appendChild($text);
2884 2884
 
2885 2885
         /* A comment token */
2886
-        } elseif($token['type'] === HTML5::COMMENT) {
2886
+        } elseif ($token['type'] === HTML5::COMMENT) {
2887 2887
             /* Append a Comment node to the current node with the data
2888 2888
             attribute set to the data given in the comment token. */
2889 2889
             $comment = $this->dom->createComment($token['data']);
2890 2890
             end($this->stack)->appendChild($comment);
2891 2891
 
2892 2892
         /* A start tag whose tag name is "col" */
2893
-        } elseif($token['type'] === HTML5::STARTTAG && $token['name'] === 'col') {
2893
+        } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'col') {
2894 2894
             /* Insert a col element for the token. Immediately pop the current
2895 2895
             node off the stack of open elements. */
2896 2896
             $this->insertElement($token);
2897 2897
             array_pop($this->stack);
2898 2898
 
2899 2899
         /* An end tag whose tag name is "colgroup" */
2900
-        } elseif($token['type'] === HTML5::ENDTAG &&
2900
+        } elseif ($token['type'] === HTML5::ENDTAG &&
2901 2901
         $token['name'] === 'colgroup') {
2902 2902
             /* If the current node is the root html element, then this is a
2903 2903
             parse error, ignore the token. (innerHTML case) */
2904
-            if(end($this->stack)->nodeName === 'html') {
2904
+            if (end($this->stack)->nodeName === 'html') {
2905 2905
                 // Ignore
2906 2906
 
2907 2907
             /* Otherwise, pop the current node (which will be a colgroup
@@ -2913,7 +2913,7 @@  discard block
 block discarded – undo
2913 2913
             }
2914 2914
 
2915 2915
         /* An end tag whose tag name is "col" */
2916
-        } elseif($token['type'] === HTML5::ENDTAG && $token['name'] === 'col') {
2916
+        } elseif ($token['type'] === HTML5::ENDTAG && $token['name'] === 'col') {
2917 2917
             /* Parse error. Ignore the token. */
2918 2918
 
2919 2919
         /* Anything else */
@@ -2933,7 +2933,7 @@  discard block
 block discarded – undo
2933 2933
         $clear = array('tbody', 'tfoot', 'thead', 'html');
2934 2934
 
2935 2935
         /* A start tag whose tag name is "tr" */
2936
-        if($token['type'] === HTML5::STARTTAG && $token['name'] === 'tr') {
2936
+        if ($token['type'] === HTML5::STARTTAG && $token['name'] === 'tr') {
2937 2937
             /* Clear the stack back to a table body context. */
2938 2938
             $this->clearStackToTableContext($clear);
2939 2939
 
@@ -2943,8 +2943,8 @@  discard block
 block discarded – undo
2943 2943
             $this->mode = self::IN_ROW;
2944 2944
 
2945 2945
         /* A start tag whose tag name is one of: "th", "td" */
2946
-        } elseif($token['type'] === HTML5::STARTTAG &&
2947
-        ($token['name'] === 'th' ||    $token['name'] === 'td')) {
2946
+        } elseif ($token['type'] === HTML5::STARTTAG &&
2947
+        ($token['name'] === 'th' || $token['name'] === 'td')) {
2948 2948
             /* Parse error. Act as if a start tag with the tag name "tr" had
2949 2949
             been seen, then reprocess the current token. */
2950 2950
             $this->inTableBody(array(
@@ -2956,12 +2956,12 @@  discard block
 block discarded – undo
2956 2956
             return $this->inRow($token);
2957 2957
 
2958 2958
         /* An end tag whose tag name is one of: "tbody", "tfoot", "thead" */
2959
-        } elseif($token['type'] === HTML5::ENDTAG &&
2959
+        } elseif ($token['type'] === HTML5::ENDTAG &&
2960 2960
         in_array($token['name'], array('tbody', 'tfoot', 'thead'))) {
2961 2961
             /* If the stack of open elements does not have an element in table
2962 2962
             scope with the same tag name as the token, this is a parse error.
2963 2963
             Ignore the token. */
2964
-            if(!$this->elementInScope($token['name'], true)) {
2964
+            if (!$this->elementInScope($token['name'], true)) {
2965 2965
                 // Ignore
2966 2966
 
2967 2967
             /* Otherwise: */
@@ -2977,13 +2977,13 @@  discard block
 block discarded – undo
2977 2977
 
2978 2978
         /* A start tag whose tag name is one of: "caption", "col", "colgroup",
2979 2979
         "tbody", "tfoot", "thead", or an end tag whose tag name is "table" */
2980
-        } elseif(($token['type'] === HTML5::STARTTAG && in_array($token['name'],
2980
+        } elseif (($token['type'] === HTML5::STARTTAG && in_array($token['name'],
2981 2981
         array('caption', 'col', 'colgroup', 'tbody', 'tfoor', 'thead'))) ||
2982 2982
         ($token['type'] === HTML5::STARTTAG && $token['name'] === 'table')) {
2983 2983
             /* If the stack of open elements does not have a tbody, thead, or
2984 2984
             tfoot element in table scope, this is a parse error. Ignore the
2985 2985
             token. (innerHTML case) */
2986
-            if(!$this->elementInScope(array('tbody', 'thead', 'tfoot'), true)) {
2986
+            if (!$this->elementInScope(array('tbody', 'thead', 'tfoot'), true)) {
2987 2987
                 // Ignore.
2988 2988
 
2989 2989
             /* Otherwise: */
@@ -3004,7 +3004,7 @@  discard block
 block discarded – undo
3004 3004
 
3005 3005
         /* An end tag whose tag name is one of: "body", "caption", "col",
3006 3006
         "colgroup", "html", "td", "th", "tr" */
3007
-        } elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3007
+        } elseif ($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3008 3008
         array('body', 'caption', 'col', 'colgroup', 'html', 'td', 'th', 'tr'))) {
3009 3009
             /* Parse error. Ignore the token. */
3010 3010
 
@@ -3019,7 +3019,7 @@  discard block
 block discarded – undo
3019 3019
         $clear = array('tr', 'html');
3020 3020
 
3021 3021
         /* A start tag whose tag name is one of: "th", "td" */
3022
-        if($token['type'] === HTML5::STARTTAG &&
3022
+        if ($token['type'] === HTML5::STARTTAG &&
3023 3023
         ($token['name'] === 'th' || $token['name'] === 'td')) {
3024 3024
             /* Clear the stack back to a table row context. */
3025 3025
             $this->clearStackToTableContext($clear);
@@ -3034,11 +3034,11 @@  discard block
 block discarded – undo
3034 3034
             $this->a_formatting[] = self::MARKER;
3035 3035
 
3036 3036
         /* An end tag whose tag name is "tr" */
3037
-        } elseif($token['type'] === HTML5::ENDTAG && $token['name'] === 'tr') {
3037
+        } elseif ($token['type'] === HTML5::ENDTAG && $token['name'] === 'tr') {
3038 3038
             /* If the stack of open elements does not have an element in table
3039 3039
             scope with the same tag name as the token, this is a parse error.
3040 3040
             Ignore the token. (innerHTML case) */
3041
-            if(!$this->elementInScope($token['name'], true)) {
3041
+            if (!$this->elementInScope($token['name'], true)) {
3042 3042
                 // Ignore.
3043 3043
 
3044 3044
             /* Otherwise: */
@@ -3055,7 +3055,7 @@  discard block
 block discarded – undo
3055 3055
 
3056 3056
         /* A start tag whose tag name is one of: "caption", "col", "colgroup",
3057 3057
         "tbody", "tfoot", "thead", "tr" or an end tag whose tag name is "table" */
3058
-        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
3058
+        } elseif ($token['type'] === HTML5::STARTTAG && in_array($token['name'],
3059 3059
         array('caption', 'col', 'colgroup', 'tbody', 'tfoot', 'thead', 'tr'))) {
3060 3060
             /* Act as if an end tag with the tag name "tr" had been seen, then,
3061 3061
             if that token wasn't ignored, reprocess the current token. */
@@ -3067,12 +3067,12 @@  discard block
 block discarded – undo
3067 3067
             return $this->inCell($token);
3068 3068
 
3069 3069
         /* An end tag whose tag name is one of: "tbody", "tfoot", "thead" */
3070
-        } elseif($token['type'] === HTML5::ENDTAG &&
3070
+        } elseif ($token['type'] === HTML5::ENDTAG &&
3071 3071
         in_array($token['name'], array('tbody', 'tfoot', 'thead'))) {
3072 3072
             /* If the stack of open elements does not have an element in table
3073 3073
             scope with the same tag name as the token, this is a parse error.
3074 3074
             Ignore the token. */
3075
-            if(!$this->elementInScope($token['name'], true)) {
3075
+            if (!$this->elementInScope($token['name'], true)) {
3076 3076
                 // Ignore.
3077 3077
 
3078 3078
             /* Otherwise: */
@@ -3089,7 +3089,7 @@  discard block
 block discarded – undo
3089 3089
 
3090 3090
         /* An end tag whose tag name is one of: "body", "caption", "col",
3091 3091
         "colgroup", "html", "td", "th" */
3092
-        } elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3092
+        } elseif ($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3093 3093
         array('body', 'caption', 'col', 'colgroup', 'html', 'td', 'th', 'tr'))) {
3094 3094
             /* Parse error. Ignore the token. */
3095 3095
 
@@ -3102,12 +3102,12 @@  discard block
 block discarded – undo
3102 3102
 
3103 3103
     private function inCell($token) {
3104 3104
         /* An end tag whose tag name is one of: "td", "th" */
3105
-        if($token['type'] === HTML5::ENDTAG &&
3105
+        if ($token['type'] === HTML5::ENDTAG &&
3106 3106
         ($token['name'] === 'td' || $token['name'] === 'th')) {
3107 3107
             /* If the stack of open elements does not have an element in table
3108 3108
             scope with the same tag name as that of the token, then this is a
3109 3109
             parse error and the token must be ignored. */
3110
-            if(!$this->elementInScope($token['name'], true)) {
3110
+            if (!$this->elementInScope($token['name'], true)) {
3111 3111
                 // Ignore.
3112 3112
 
3113 3113
             /* Otherwise: */
@@ -3122,11 +3122,11 @@  discard block
 block discarded – undo
3122 3122
 
3123 3123
                 /* Pop elements from this stack until an element with the same
3124 3124
                 tag name as the token has been popped from the stack. */
3125
-                while(true) {
3125
+                while (true) {
3126 3126
                     $node = end($this->stack)->nodeName;
3127 3127
                     array_pop($this->stack);
3128 3128
 
3129
-                    if($node === $token['name']) {
3129
+                    if ($node === $token['name']) {
3130 3130
                         break;
3131 3131
                     }
3132 3132
                 }
@@ -3142,13 +3142,13 @@  discard block
 block discarded – undo
3142 3142
 
3143 3143
         /* A start tag whose tag name is one of: "caption", "col", "colgroup",
3144 3144
         "tbody", "td", "tfoot", "th", "thead", "tr" */
3145
-        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
3145
+        } elseif ($token['type'] === HTML5::STARTTAG && in_array($token['name'],
3146 3146
         array('caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
3147 3147
         'thead', 'tr'))) {
3148 3148
             /* If the stack of open elements does not have a td or th element
3149 3149
             in table scope, then this is a parse error; ignore the token.
3150 3150
             (innerHTML case) */
3151
-            if(!$this->elementInScope(array('td', 'th'), true)) {
3151
+            if (!$this->elementInScope(array('td', 'th'), true)) {
3152 3152
                 // Ignore.
3153 3153
 
3154 3154
             /* Otherwise, close the cell (see below) and reprocess the current
@@ -3160,13 +3160,13 @@  discard block
 block discarded – undo
3160 3160
 
3161 3161
         /* A start tag whose tag name is one of: "caption", "col", "colgroup",
3162 3162
         "tbody", "td", "tfoot", "th", "thead", "tr" */
3163
-        } elseif($token['type'] === HTML5::STARTTAG && in_array($token['name'],
3163
+        } elseif ($token['type'] === HTML5::STARTTAG && in_array($token['name'],
3164 3164
         array('caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
3165 3165
         'thead', 'tr'))) {
3166 3166
             /* If the stack of open elements does not have a td or th element
3167 3167
             in table scope, then this is a parse error; ignore the token.
3168 3168
             (innerHTML case) */
3169
-            if(!$this->elementInScope(array('td', 'th'), true)) {
3169
+            if (!$this->elementInScope(array('td', 'th'), true)) {
3170 3170
                 // Ignore.
3171 3171
 
3172 3172
             /* Otherwise, close the cell (see below) and reprocess the current
@@ -3178,19 +3178,19 @@  discard block
 block discarded – undo
3178 3178
 
3179 3179
         /* An end tag whose tag name is one of: "body", "caption", "col",
3180 3180
         "colgroup", "html" */
3181
-        } elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3181
+        } elseif ($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3182 3182
         array('body', 'caption', 'col', 'colgroup', 'html'))) {
3183 3183
             /* Parse error. Ignore the token. */
3184 3184
 
3185 3185
         /* An end tag whose tag name is one of: "table", "tbody", "tfoot",
3186 3186
         "thead", "tr" */
3187
-        } elseif($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3187
+        } elseif ($token['type'] === HTML5::ENDTAG && in_array($token['name'],
3188 3188
         array('table', 'tbody', 'tfoot', 'thead', 'tr'))) {
3189 3189
             /* If the stack of open elements does not have an element in table
3190 3190
             scope with the same tag name as that of the token (which can only
3191 3191
             happen for "tbody", "tfoot" and "thead", or, in the innerHTML case),
3192 3192
             then this is a parse error and the token must be ignored. */
3193
-            if(!$this->elementInScope($token['name'], true)) {
3193
+            if (!$this->elementInScope($token['name'], true)) {
3194 3194
                 // Ignore.
3195 3195
 
3196 3196
             /* Otherwise, close the cell (see below) and reprocess the current
@@ -3211,22 +3211,22 @@  discard block
 block discarded – undo
3211 3211
         /* Handle the token as follows: */
3212 3212
 
3213 3213
         /* A character token */
3214
-        if($token['type'] === HTML5::CHARACTR) {
3214
+        if ($token['type'] === HTML5::CHARACTR) {
3215 3215
             /* Append the token's character to the current node. */
3216 3216
             $this->insertText($token['data']);
3217 3217
 
3218 3218
         /* A comment token */
3219
-        } elseif($token['type'] === HTML5::COMMENT) {
3219
+        } elseif ($token['type'] === HTML5::COMMENT) {
3220 3220
             /* Append a Comment node to the current node with the data
3221 3221
             attribute set to the data given in the comment token. */
3222 3222
             $this->insertComment($token['data']);
3223 3223
 
3224 3224
         /* A start tag token whose tag name is "option" */
3225
-        } elseif($token['type'] === HTML5::STARTTAG &&
3225
+        } elseif ($token['type'] === HTML5::STARTTAG &&
3226 3226
         $token['name'] === 'option') {
3227 3227
             /* If the current node is an option element, act as if an end tag
3228 3228
             with the tag name "option" had been seen. */
3229
-            if(end($this->stack)->nodeName === 'option') {
3229
+            if (end($this->stack)->nodeName === 'option') {
3230 3230
                 $this->inSelect(array(
3231 3231
                     'name' => 'option',
3232 3232
                     'type' => HTML5::ENDTAG
@@ -3237,11 +3237,11 @@  discard block
 block discarded – undo
3237 3237
             $this->insertElement($token);
3238 3238
 
3239 3239
         /* A start tag token whose tag name is "optgroup" */
3240
-        } elseif($token['type'] === HTML5::STARTTAG &&
3240
+        } elseif ($token['type'] === HTML5::STARTTAG &&
3241 3241
         $token['name'] === 'optgroup') {
3242 3242
             /* If the current node is an option element, act as if an end tag
3243 3243
             with the tag name "option" had been seen. */
3244
-            if(end($this->stack)->nodeName === 'option') {
3244
+            if (end($this->stack)->nodeName === 'option') {
3245 3245
                 $this->inSelect(array(
3246 3246
                     'name' => 'option',
3247 3247
                     'type' => HTML5::ENDTAG
@@ -3250,7 +3250,7 @@  discard block
 block discarded – undo
3250 3250
 
3251 3251
             /* If the current node is an optgroup element, act as if an end tag
3252 3252
             with the tag name "optgroup" had been seen. */
3253
-            if(end($this->stack)->nodeName === 'optgroup') {
3253
+            if (end($this->stack)->nodeName === 'optgroup') {
3254 3254
                 $this->inSelect(array(
3255 3255
                     'name' => 'optgroup',
3256 3256
                     'type' => HTML5::ENDTAG
@@ -3261,7 +3261,7 @@  discard block
 block discarded – undo
3261 3261
             $this->insertElement($token);
3262 3262
 
3263 3263
         /* An end tag token whose tag name is "optgroup" */
3264
-        } elseif($token['type'] === HTML5::ENDTAG &&
3264
+        } elseif ($token['type'] === HTML5::ENDTAG &&
3265 3265
         $token['name'] === 'optgroup') {
3266 3266
             /* First, if the current node is an option element, and the node
3267 3267
             immediately before it in the stack of open elements is an optgroup
@@ -3269,7 +3269,7 @@  discard block
 block discarded – undo
3269 3269
             been seen. */
3270 3270
             $elements_in_stack = count($this->stack);
3271 3271
 
3272
-            if($this->stack[$elements_in_stack - 1]->nodeName === 'option' &&
3272
+            if ($this->stack[$elements_in_stack - 1]->nodeName === 'option' &&
3273 3273
             $this->stack[$elements_in_stack - 2]->nodeName === 'optgroup') {
3274 3274
                 $this->inSelect(array(
3275 3275
                     'name' => 'option',
@@ -3280,38 +3280,38 @@  discard block
 block discarded – undo
3280 3280
             /* If the current node is an optgroup element, then pop that node
3281 3281
             from the stack of open elements. Otherwise, this is a parse error,
3282 3282
             ignore the token. */
3283
-            if($this->stack[$elements_in_stack - 1] === 'optgroup') {
3283
+            if ($this->stack[$elements_in_stack - 1] === 'optgroup') {
3284 3284
                 array_pop($this->stack);
3285 3285
             }
3286 3286
 
3287 3287
         /* An end tag token whose tag name is "option" */
3288
-        } elseif($token['type'] === HTML5::ENDTAG &&
3288
+        } elseif ($token['type'] === HTML5::ENDTAG &&
3289 3289
         $token['name'] === 'option') {
3290 3290
             /* If the current node is an option element, then pop that node
3291 3291
             from the stack of open elements. Otherwise, this is a parse error,
3292 3292
             ignore the token. */
3293
-            if(end($this->stack)->nodeName === 'option') {
3293
+            if (end($this->stack)->nodeName === 'option') {
3294 3294
                 array_pop($this->stack);
3295 3295
             }
3296 3296
 
3297 3297
         /* An end tag whose tag name is "select" */
3298
-        } elseif($token['type'] === HTML5::ENDTAG &&
3298
+        } elseif ($token['type'] === HTML5::ENDTAG &&
3299 3299
         $token['name'] === 'select') {
3300 3300
             /* If the stack of open elements does not have an element in table
3301 3301
             scope with the same tag name as the token, this is a parse error.
3302 3302
             Ignore the token. (innerHTML case) */
3303
-            if(!$this->elementInScope($token['name'], true)) {
3303
+            if (!$this->elementInScope($token['name'], true)) {
3304 3304
                 // w/e
3305 3305
 
3306 3306
             /* Otherwise: */
3307 3307
             } else {
3308 3308
                 /* Pop elements from the stack of open elements until a select
3309 3309
                 element has been popped from the stack. */
3310
-                while(true) {
3310
+                while (true) {
3311 3311
                     $current = end($this->stack)->nodeName;
3312 3312
                     array_pop($this->stack);
3313 3313
 
3314
-                    if($current === 'select') {
3314
+                    if ($current === 'select') {
3315 3315
                         break;
3316 3316
                     }
3317 3317
                 }
@@ -3321,7 +3321,7 @@  discard block
 block discarded – undo
3321 3321
             }
3322 3322
 
3323 3323
         /* A start tag whose tag name is "select" */
3324
-        } elseif($token['name'] === 'select' &&
3324
+        } elseif ($token['name'] === 'select' &&
3325 3325
         $token['type'] === HTML5::STARTTAG) {
3326 3326
             /* Parse error. Act as if the token had been an end tag with the
3327 3327
             tag name "select" instead. */
@@ -3332,7 +3332,7 @@  discard block
 block discarded – undo
3332 3332
 
3333 3333
         /* An end tag whose tag name is one of: "caption", "table", "tbody",
3334 3334
         "tfoot", "thead", "tr", "td", "th" */
3335
-        } elseif(in_array($token['name'], array('caption', 'table', 'tbody',
3335
+        } elseif (in_array($token['name'], array('caption', 'table', 'tbody',
3336 3336
         'tfoot', 'thead', 'tr', 'td', 'th')) && $token['type'] === HTML5::ENDTAG) {
3337 3337
             /* Parse error. */
3338 3338
             // w/e
@@ -3341,7 +3341,7 @@  discard block
 block discarded – undo
3341 3341
             the same tag name as that of the token, then act as if an end tag
3342 3342
             with the tag name "select" had been seen, and reprocess the token.
3343 3343
             Otherwise, ignore the token. */
3344
-            if($this->elementInScope($token['name'], true)) {
3344
+            if ($this->elementInScope($token['name'], true)) {
3345 3345
                 $this->inSelect(array(
3346 3346
                     'name' => 'select',
3347 3347
                     'type' => HTML5::ENDTAG
@@ -3362,14 +3362,14 @@  discard block
 block discarded – undo
3362 3362
         /* A character token that is one of one of U+0009 CHARACTER TABULATION,
3363 3363
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
3364 3364
         or U+0020 SPACE */
3365
-        if($token['type'] === HTML5::CHARACTR &&
3365
+        if ($token['type'] === HTML5::CHARACTR &&
3366 3366
         preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
3367 3367
             /* Process the token as it would be processed if the insertion mode
3368 3368
             was "in body". */
3369 3369
             $this->inBody($token);
3370 3370
 
3371 3371
         /* A comment token */
3372
-        } elseif($token['type'] === HTML5::COMMENT) {
3372
+        } elseif ($token['type'] === HTML5::COMMENT) {
3373 3373
             /* Append a Comment node to the first element in the stack of open
3374 3374
             elements (the html element), with the data attribute set to the
3375 3375
             data given in the comment token. */
@@ -3377,7 +3377,7 @@  discard block
 block discarded – undo
3377 3377
             $this->stack[0]->appendChild($comment);
3378 3378
 
3379 3379
         /* An end tag with the tag name "html" */
3380
-        } elseif($token['type'] === HTML5::ENDTAG && $token['name'] === 'html') {
3380
+        } elseif ($token['type'] === HTML5::ENDTAG && $token['name'] === 'html') {
3381 3381
             /* If the parser was originally created in order to handle the
3382 3382
             setting of an element's innerHTML attribute, this is a parse error;
3383 3383
             ignore the token. (The element will be an html element in this
@@ -3401,28 +3401,28 @@  discard block
 block discarded – undo
3401 3401
         /* A character token that is one of one of U+0009 CHARACTER TABULATION,
3402 3402
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
3403 3403
         U+000D CARRIAGE RETURN (CR), or U+0020 SPACE */
3404
-        if($token['type'] === HTML5::CHARACTR &&
3404
+        if ($token['type'] === HTML5::CHARACTR &&
3405 3405
         preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
3406 3406
             /* Append the character to the current node. */
3407 3407
             $this->insertText($token['data']);
3408 3408
 
3409 3409
         /* A comment token */
3410
-        } elseif($token['type'] === HTML5::COMMENT) {
3410
+        } elseif ($token['type'] === HTML5::COMMENT) {
3411 3411
             /* Append a Comment node to the current node with the data
3412 3412
             attribute set to the data given in the comment token. */
3413 3413
             $this->insertComment($token['data']);
3414 3414
 
3415 3415
         /* A start tag with the tag name "frameset" */
3416
-        } elseif($token['name'] === 'frameset' &&
3416
+        } elseif ($token['name'] === 'frameset' &&
3417 3417
         $token['type'] === HTML5::STARTTAG) {
3418 3418
             $this->insertElement($token);
3419 3419
 
3420 3420
         /* An end tag with the tag name "frameset" */
3421
-        } elseif($token['name'] === 'frameset' &&
3421
+        } elseif ($token['name'] === 'frameset' &&
3422 3422
         $token['type'] === HTML5::ENDTAG) {
3423 3423
             /* If the current node is the root html element, then this is a
3424 3424
             parse error; ignore the token. (innerHTML case) */
3425
-            if(end($this->stack)->nodeName === 'html') {
3425
+            if (end($this->stack)->nodeName === 'html') {
3426 3426
                 // Ignore
3427 3427
 
3428 3428
             } else {
@@ -3438,7 +3438,7 @@  discard block
 block discarded – undo
3438 3438
             }
3439 3439
 
3440 3440
         /* A start tag with the tag name "frame" */
3441
-        } elseif($token['name'] === 'frame' &&
3441
+        } elseif ($token['name'] === 'frame' &&
3442 3442
         $token['type'] === HTML5::STARTTAG) {
3443 3443
             /* Insert an HTML element for the token. */
3444 3444
             $this->insertElement($token);
@@ -3447,7 +3447,7 @@  discard block
 block discarded – undo
3447 3447
             array_pop($this->stack);
3448 3448
 
3449 3449
         /* A start tag with the tag name "noframes" */
3450
-        } elseif($token['name'] === 'noframes' &&
3450
+        } elseif ($token['name'] === 'noframes' &&
3451 3451
         $token['type'] === HTML5::STARTTAG) {
3452 3452
             /* Process the token as if the insertion mode had been "in body". */
3453 3453
             $this->inBody($token);
@@ -3464,25 +3464,25 @@  discard block
 block discarded – undo
3464 3464
         /* A character token that is one of one of U+0009 CHARACTER TABULATION,
3465 3465
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
3466 3466
         U+000D CARRIAGE RETURN (CR), or U+0020 SPACE */
3467
-        if($token['type'] === HTML5::CHARACTR &&
3467
+        if ($token['type'] === HTML5::CHARACTR &&
3468 3468
         preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
3469 3469
             /* Append the character to the current node. */
3470 3470
             $this->insertText($token['data']);
3471 3471
 
3472 3472
         /* A comment token */
3473
-        } elseif($token['type'] === HTML5::COMMENT) {
3473
+        } elseif ($token['type'] === HTML5::COMMENT) {
3474 3474
             /* Append a Comment node to the current node with the data
3475 3475
             attribute set to the data given in the comment token. */
3476 3476
             $this->insertComment($token['data']);
3477 3477
 
3478 3478
         /* An end tag with the tag name "html" */
3479
-        } elseif($token['name'] === 'html' &&
3479
+        } elseif ($token['name'] === 'html' &&
3480 3480
         $token['type'] === HTML5::ENDTAG) {
3481 3481
             /* Switch to the trailing end phase. */
3482 3482
             $this->phase = self::END_PHASE;
3483 3483
 
3484 3484
         /* A start tag with the tag name "noframes" */
3485
-        } elseif($token['name'] === 'noframes' &&
3485
+        } elseif ($token['name'] === 'noframes' &&
3486 3486
         $token['type'] === HTML5::STARTTAG) {
3487 3487
             /* Process the token as if the insertion mode had been "in body". */
3488 3488
             $this->inBody($token);
@@ -3498,11 +3498,11 @@  discard block
 block discarded – undo
3498 3498
         stage, it must be processed as described in this section. */
3499 3499
 
3500 3500
         /* A DOCTYPE token */
3501
-        if($token['type'] === HTML5::DOCTYPE) {
3501
+        if ($token['type'] === HTML5::DOCTYPE) {
3502 3502
             // Parse error. Ignore the token.
3503 3503
 
3504 3504
         /* A comment token */
3505
-        } elseif($token['type'] === HTML5::COMMENT) {
3505
+        } elseif ($token['type'] === HTML5::COMMENT) {
3506 3506
             /* Append a Comment node to the Document object with the data
3507 3507
             attribute set to the data given in the comment token. */
3508 3508
             $comment = $this->dom->createComment($token['data']);
@@ -3511,7 +3511,7 @@  discard block
 block discarded – undo
3511 3511
         /* A character token that is one of one of U+0009 CHARACTER TABULATION,
3512 3512
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
3513 3513
         or U+0020 SPACE */
3514
-        } elseif($token['type'] === HTML5::CHARACTR &&
3514
+        } elseif ($token['type'] === HTML5::CHARACTR &&
3515 3515
         preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
3516 3516
             /* Process the token as it would be processed in the main phase. */
3517 3517
             $this->mainPhase($token);
@@ -3519,7 +3519,7 @@  discard block
 block discarded – undo
3519 3519
         /* A character token that is not one of U+0009 CHARACTER TABULATION,
3520 3520
         U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
3521 3521
         or U+0020 SPACE. Or a start tag token. Or an end tag token. */
3522
-        } elseif(($token['type'] === HTML5::CHARACTR &&
3522
+        } elseif (($token['type'] === HTML5::CHARACTR &&
3523 3523
         preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) ||
3524 3524
         $token['type'] === HTML5::STARTTAG || $token['type'] === HTML5::ENDTAG) {
3525 3525
             /* Parse error. Switch back to the main phase and reprocess the
@@ -3528,7 +3528,7 @@  discard block
 block discarded – undo
3528 3528
             return $this->mainPhase($token);
3529 3529
 
3530 3530
         /* An end-of-file token */
3531
-        } elseif($token['type'] === HTML5::EOF) {
3531
+        } elseif ($token['type'] === HTML5::EOF) {
3532 3532
             /* OMG DONE!! */
3533 3533
         }
3534 3534
     }
@@ -3547,8 +3547,8 @@  discard block
 block discarded – undo
3547 3547
         
3548 3548
         $el = $this->dom->createElement($token['name']);
3549 3549
 
3550
-        foreach($token['attr'] as $attr) {
3551
-            if(!$el->hasAttribute($attr['name'])) {
3550
+        foreach ($token['attr'] as $attr) {
3551
+            if (!$el->hasAttribute($attr['name'])) {
3552 3552
                 $el->setAttribute($attr['name'], $attr['value']);
3553 3553
             }
3554 3554
         }
@@ -3570,25 +3570,25 @@  discard block
 block discarded – undo
3570 3570
     }
3571 3571
 
3572 3572
     private function appendToRealParent($node) {
3573
-        if($this->foster_parent === null) {
3573
+        if ($this->foster_parent === null) {
3574 3574
             end($this->stack)->appendChild($node);
3575 3575
 
3576
-        } elseif($this->foster_parent !== null) {
3576
+        } elseif ($this->foster_parent !== null) {
3577 3577
             /* If the foster parent element is the parent element of the
3578 3578
             last table element in the stack of open elements, then the new
3579 3579
             node must be inserted immediately before the last table element
3580 3580
             in the stack of open elements in the foster parent element;
3581 3581
             otherwise, the new node must be appended to the foster parent
3582 3582
             element. */
3583
-            for($n = count($this->stack) - 1; $n >= 0; $n--) {
3584
-                if($this->stack[$n]->nodeName === 'table' &&
3583
+            for ($n = count($this->stack) - 1; $n >= 0; $n--) {
3584
+                if ($this->stack[$n]->nodeName === 'table' &&
3585 3585
                 $this->stack[$n]->parentNode !== null) {
3586 3586
                     $table = $this->stack[$n];
3587 3587
                     break;
3588 3588
                 }
3589 3589
             }
3590 3590
 
3591
-            if(isset($table) && $this->foster_parent->isSameNode($table->parentNode))
3591
+            if (isset($table) && $this->foster_parent->isSameNode($table->parentNode))
3592 3592
                 $this->foster_parent->insertBefore($node, $table);
3593 3593
             else
3594 3594
                 $this->foster_parent->appendChild($node);
@@ -3598,9 +3598,9 @@  discard block
 block discarded – undo
3598 3598
     }
3599 3599
 
3600 3600
     private function elementInScope($el, $table = false) {
3601
-        if(is_array($el)) {
3602
-            foreach($el as $element) {
3603
-                if($this->elementInScope($element, $table)) {
3601
+        if (is_array($el)) {
3602
+            foreach ($el as $element) {
3603
+                if ($this->elementInScope($element, $table)) {
3604 3604
                     return true;
3605 3605
                 }
3606 3606
             }
@@ -3610,28 +3610,28 @@  discard block
 block discarded – undo
3610 3610
 
3611 3611
         $leng = count($this->stack);
3612 3612
 
3613
-        for($n = 0; $n < $leng; $n++) {
3613
+        for ($n = 0; $n < $leng; $n++) {
3614 3614
             /* 1. Initialise node to be the current node (the bottommost node of
3615 3615
             the stack). */
3616 3616
             $node = $this->stack[$leng - 1 - $n];
3617 3617
 
3618
-            if($node->tagName === $el) {
3618
+            if ($node->tagName === $el) {
3619 3619
                 /* 2. If node is the target node, terminate in a match state. */
3620 3620
                 return true;
3621 3621
 
3622
-            } elseif($node->tagName === 'table') {
3622
+            } elseif ($node->tagName === 'table') {
3623 3623
                 /* 3. Otherwise, if node is a table element, terminate in a failure
3624 3624
                 state. */
3625 3625
                 return false;
3626 3626
 
3627
-            } elseif($table === true && in_array($node->tagName, array('caption', 'td',
3627
+            } elseif ($table === true && in_array($node->tagName, array('caption', 'td',
3628 3628
             'th', 'button', 'marquee', 'object'))) {
3629 3629
                 /* 4. Otherwise, if the algorithm is the "has an element in scope"
3630 3630
                 variant (rather than the "has an element in table scope" variant),
3631 3631
                 and node is one of the following, terminate in a failure state. */
3632 3632
                 return false;
3633 3633
 
3634
-            } elseif($node === $node->ownerDocument->documentElement) {
3634
+            } elseif ($node === $node->ownerDocument->documentElement) {
3635 3635
                 /* 5. Otherwise, if node is an html element (root element), terminate
3636 3636
                 in a failure state. (This can only happen if the node is the topmost
3637 3637
                 node of the    stack of open elements, and prevents the next step from
@@ -3651,7 +3651,7 @@  discard block
 block discarded – undo
3651 3651
         then there is nothing to reconstruct; stop this algorithm. */
3652 3652
         $formatting_elements = count($this->a_formatting);
3653 3653
 
3654
-        if($formatting_elements === 0) {
3654
+        if ($formatting_elements === 0) {
3655 3655
             return false;
3656 3656
         }
3657 3657
 
@@ -3663,14 +3663,14 @@  discard block
 block discarded – undo
3663 3663
         formatting elements is a marker, or if it is an element that is in the
3664 3664
         stack of open elements, then there is nothing to reconstruct; stop this
3665 3665
         algorithm. */
3666
-        if($entry === self::MARKER || in_array($entry, $this->stack, true)) {
3666
+        if ($entry === self::MARKER || in_array($entry, $this->stack, true)) {
3667 3667
             return false;
3668 3668
         }
3669 3669
 
3670
-        for($a = $formatting_elements - 1; $a >= 0; true) {
3670
+        for ($a = $formatting_elements - 1; $a >= 0; true) {
3671 3671
             /* 4. If there are no entries before entry in the list of active
3672 3672
             formatting elements, then jump to step 8. */
3673
-            if($a === 0) {
3673
+            if ($a === 0) {
3674 3674
                 $step_seven = false;
3675 3675
                 break;
3676 3676
             }
@@ -3682,15 +3682,15 @@  discard block
 block discarded – undo
3682 3682
 
3683 3683
             /* 6. If entry is neither a marker nor an element that is also in
3684 3684
             thetack of open elements, go to step 4. */
3685
-            if($entry === self::MARKER || in_array($entry, $this->stack, true)) {
3685
+            if ($entry === self::MARKER || in_array($entry, $this->stack, true)) {
3686 3686
                 break;
3687 3687
             }
3688 3688
         }
3689 3689
 
3690
-        while(true) {
3690
+        while (true) {
3691 3691
             /* 7. Let entry be the element one later than entry in the list of
3692 3692
             active formatting elements. */
3693
-            if(isset($step_seven) && $step_seven === true) {
3693
+            if (isset($step_seven) && $step_seven === true) {
3694 3694
                 $a++;
3695 3695
                 $entry = $this->a_formatting[$a];
3696 3696
             }
@@ -3709,7 +3709,7 @@  discard block
 block discarded – undo
3709 3709
 
3710 3710
             /* 11. If the entry for clone in the list of active formatting
3711 3711
             elements is not the last entry in the list, return to step 7. */
3712
-            if(end($this->a_formatting) !== $clone) {
3712
+            if (end($this->a_formatting) !== $clone) {
3713 3713
                 $step_seven = true;
3714 3714
             } else {
3715 3715
                 break;
@@ -3722,7 +3722,7 @@  discard block
 block discarded – undo
3722 3722
         formatting elements up to the last marker, the UA must perform the
3723 3723
         following steps: */
3724 3724
 
3725
-        while(true) {
3725
+        while (true) {
3726 3726
             /* 1. Let entry be the last (most recently added) entry in the list
3727 3727
             of active formatting elements. */
3728 3728
             $entry = end($this->a_formatting);
@@ -3732,7 +3732,7 @@  discard block
 block discarded – undo
3732 3732
 
3733 3733
             /* 3. If entry was a marker, then stop the algorithm at this point.
3734 3734
             The list has been cleared up to the last marker. */
3735
-            if($entry === self::MARKER) {
3735
+            if ($entry === self::MARKER) {
3736 3736
                 break;
3737 3737
             }
3738 3738
         }
@@ -3747,20 +3747,20 @@  discard block
 block discarded – undo
3747 3747
         $node = end($this->stack);
3748 3748
         $elements = array_diff(array('dd', 'dt', 'li', 'p', 'td', 'th', 'tr'), $exclude);
3749 3749
 
3750
-        while(in_array(end($this->stack)->nodeName, $elements)) {
3750
+        while (in_array(end($this->stack)->nodeName, $elements)) {
3751 3751
             array_pop($this->stack);
3752 3752
         }
3753 3753
     }
3754 3754
 
3755 3755
     private function getElementCategory($node) {
3756 3756
         $name = $node->tagName;
3757
-        if(in_array($name, $this->special))
3757
+        if (in_array($name, $this->special))
3758 3758
             return self::SPECIAL;
3759 3759
 
3760
-        elseif(in_array($name, $this->scoping))
3760
+        elseif (in_array($name, $this->scoping))
3761 3761
             return self::SCOPING;
3762 3762
 
3763
-        elseif(in_array($name, $this->formatting))
3763
+        elseif (in_array($name, $this->formatting))
3764 3764
             return self::FORMATTING;
3765 3765
 
3766 3766
         else
@@ -3773,10 +3773,10 @@  discard block
 block discarded – undo
3773 3773
         a table element or an html element, pop elements from the stack of open
3774 3774
         elements. If this causes any elements to be popped from the stack, then
3775 3775
         this is a parse error. */
3776
-        while(true) {
3776
+        while (true) {
3777 3777
             $node = end($this->stack)->nodeName;
3778 3778
 
3779
-            if(in_array($node, $elements)) {
3779
+            if (in_array($node, $elements)) {
3780 3780
                 break;
3781 3781
             } else {
3782 3782
                 array_pop($this->stack);
@@ -3789,7 +3789,7 @@  discard block
 block discarded – undo
3789 3789
         $last = false;
3790 3790
         $leng = count($this->stack);
3791 3791
 
3792
-        for($n = $leng - 1; $n >= 0; $n--) {
3792
+        for ($n = $leng - 1; $n >= 0; $n--) {
3793 3793
             /* 2. Let node be the last node in the stack of open elements. */
3794 3794
             $node = $this->stack[$n];
3795 3795
 
@@ -3797,68 +3797,68 @@  discard block
 block discarded – undo
3797 3797
             set last to true. If the element whose innerHTML  attribute is being
3798 3798
             set is neither a td  element nor a th element, then set node to the
3799 3799
             element whose innerHTML  attribute is being set. (innerHTML  case) */
3800
-            if($this->stack[0]->isSameNode($node)) {
3800
+            if ($this->stack[0]->isSameNode($node)) {
3801 3801
                 $last = true;
3802 3802
             }
3803 3803
 
3804 3804
             /* 4. If node is a select element, then switch the insertion mode to
3805 3805
             "in select" and abort these steps. (innerHTML case) */
3806
-            if($node->nodeName === 'select') {
3806
+            if ($node->nodeName === 'select') {
3807 3807
                 $this->mode = self::IN_SELECT;
3808 3808
                 break;
3809 3809
 
3810 3810
             /* 5. If node is a td or th element, then switch the insertion mode
3811 3811
             to "in cell" and abort these steps. */
3812
-            } elseif($node->nodeName === 'td' || $node->nodeName === 'th') {
3812
+            } elseif ($node->nodeName === 'td' || $node->nodeName === 'th') {
3813 3813
                 $this->mode = self::IN_CELL;
3814 3814
                 break;
3815 3815
 
3816 3816
             /* 6. If node is a tr element, then switch the insertion mode to
3817 3817
             "in    row" and abort these steps. */
3818
-            } elseif($node->nodeName === 'tr') {
3818
+            } elseif ($node->nodeName === 'tr') {
3819 3819
                 $this->mode = self::IN_ROW;
3820 3820
                 break;
3821 3821
 
3822 3822
             /* 7. If node is a tbody, thead, or tfoot element, then switch the
3823 3823
             insertion mode to "in table body" and abort these steps. */
3824
-            } elseif(in_array($node->nodeName, array('tbody', 'thead', 'tfoot'))) {
3824
+            } elseif (in_array($node->nodeName, array('tbody', 'thead', 'tfoot'))) {
3825 3825
                 $this->mode = self::IN_TBODY;
3826 3826
                 break;
3827 3827
 
3828 3828
             /* 8. If node is a caption element, then switch the insertion mode
3829 3829
             to "in caption" and abort these steps. */
3830
-            } elseif($node->nodeName === 'caption') {
3830
+            } elseif ($node->nodeName === 'caption') {
3831 3831
                 $this->mode = self::IN_CAPTION;
3832 3832
                 break;
3833 3833
 
3834 3834
             /* 9. If node is a colgroup element, then switch the insertion mode
3835 3835
             to "in column group" and abort these steps. (innerHTML case) */
3836
-            } elseif($node->nodeName === 'colgroup') {
3836
+            } elseif ($node->nodeName === 'colgroup') {
3837 3837
                 $this->mode = self::IN_CGROUP;
3838 3838
                 break;
3839 3839
 
3840 3840
             /* 10. If node is a table element, then switch the insertion mode
3841 3841
             to "in table" and abort these steps. */
3842
-            } elseif($node->nodeName === 'table') {
3842
+            } elseif ($node->nodeName === 'table') {
3843 3843
                 $this->mode = self::IN_TABLE;
3844 3844
                 break;
3845 3845
 
3846 3846
             /* 11. If node is a head element, then switch the insertion mode
3847 3847
             to "in body" ("in body"! not "in head"!) and abort these steps.
3848 3848
             (innerHTML case) */
3849
-            } elseif($node->nodeName === 'head') {
3849
+            } elseif ($node->nodeName === 'head') {
3850 3850
                 $this->mode = self::IN_BODY;
3851 3851
                 break;
3852 3852
 
3853 3853
             /* 12. If node is a body element, then switch the insertion mode to
3854 3854
             "in body" and abort these steps. */
3855
-            } elseif($node->nodeName === 'body') {
3855
+            } elseif ($node->nodeName === 'body') {
3856 3856
                 $this->mode = self::IN_BODY;
3857 3857
                 break;
3858 3858
 
3859 3859
             /* 13. If node is a frameset element, then switch the insertion
3860 3860
             mode to "in frameset" and abort these steps. (innerHTML case) */
3861
-            } elseif($node->nodeName === 'frameset') {
3861
+            } elseif ($node->nodeName === 'frameset') {
3862 3862
                 $this->mode = self::IN_FRAME;
3863 3863
                 break;
3864 3864
 
@@ -3866,7 +3866,7 @@  discard block
 block discarded – undo
3866 3866
             pointer is null, switch the insertion mode to "before head",
3867 3867
             otherwise, switch the insertion mode to "after head". In either
3868 3868
             case, abort these steps. (innerHTML case) */
3869
-            } elseif($node->nodeName === 'html') {
3869
+            } elseif ($node->nodeName === 'html') {
3870 3870
                 $this->mode = ($this->head_pointer === null)
3871 3871
                     ? self::BEFOR_HEAD
3872 3872
                     : self::AFTER_HEAD;
@@ -3875,7 +3875,7 @@  discard block
 block discarded – undo
3875 3875
 
3876 3876
             /* 15. If last is true, then set the insertion mode to "in body"
3877 3877
             and    abort these steps. (innerHTML case) */
3878
-            } elseif($last) {
3878
+            } elseif ($last) {
3879 3879
                 $this->mode = self::IN_BODY;
3880 3880
                 break;
3881 3881
             }
@@ -3885,8 +3885,8 @@  discard block
 block discarded – undo
3885 3885
     private function closeCell() {
3886 3886
         /* If the stack of open elements has a td or th element in table scope,
3887 3887
         then act as if an end tag token with that tag name had been seen. */
3888
-        foreach(array('td', 'th') as $cell) {
3889
-            if($this->elementInScope($cell, true)) {
3888
+        foreach (array('td', 'th') as $cell) {
3889
+            if ($this->elementInScope($cell, true)) {
3890 3890
                 $this->inCell(array(
3891 3891
                     'name' => $cell,
3892 3892
                     'type' => HTML5::ENDTAG
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/Printer.php 4 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 
61 61
     /**
62 62
      * Prints a complete element with content inside
63
-     * @param $tag Tag name
63
+     * @param string $tag Tag name
64 64
      * @param $contents Element contents
65 65
      * @param $attr Tag attributes
66 66
      * @param $escape Bool whether or not to escape contents
@@ -71,6 +71,9 @@  discard block
 block discarded – undo
71 71
                $this->end($tag);
72 72
     }
73 73
 
74
+    /**
75
+     * @param string $tag
76
+     */
74 77
     protected function elementEmpty($tag, $attr = array()) {
75 78
         return $this->generator->generateFromToken(
76 79
             new HTMLPurifier_Token_Empty($tag, $attr)
Please login to merge, or discard this patch.
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -6,170 +6,170 @@
 block discarded – undo
6 6
 class HTMLPurifier_Printer
7 7
 {
8 8
 
9
-    /**
10
-     * Instance of HTMLPurifier_Generator for HTML generation convenience funcs
11
-     */
12
-    protected $generator;
13
-
14
-    /**
15
-     * Instance of HTMLPurifier_Config, for easy access
16
-     */
17
-    protected $config;
18
-
19
-    /**
20
-     * Initialize $generator.
21
-     */
22
-    public function __construct() {
23
-    }
24
-
25
-    /**
26
-     * Give generator necessary configuration if possible
27
-     */
28
-    public function prepareGenerator($config) {
29
-        $all = $config->getAll();
30
-        $context = new HTMLPurifier_Context();
31
-        $this->generator = new HTMLPurifier_Generator($config, $context);
32
-    }
33
-
34
-    /**
35
-     * Main function that renders object or aspect of that object
36
-     * @note Parameters vary depending on printer
37
-     */
38
-    // function render() {}
39
-
40
-    /**
41
-     * Returns a start tag
42
-     * @param $tag Tag name
43
-     * @param $attr Attribute array
44
-     */
45
-    protected function start($tag, $attr = array()) {
46
-        return $this->generator->generateFromToken(
47
-                    new HTMLPurifier_Token_Start($tag, $attr ? $attr : array())
48
-               );
49
-    }
50
-
51
-    /**
52
-     * Returns an end teg
53
-     * @param $tag Tag name
54
-     */
55
-    protected function end($tag) {
56
-        return $this->generator->generateFromToken(
57
-                    new HTMLPurifier_Token_End($tag)
58
-               );
59
-    }
60
-
61
-    /**
62
-     * Prints a complete element with content inside
63
-     * @param $tag Tag name
64
-     * @param $contents Element contents
65
-     * @param $attr Tag attributes
66
-     * @param $escape Bool whether or not to escape contents
67
-     */
68
-    protected function element($tag, $contents, $attr = array(), $escape = true) {
69
-        return $this->start($tag, $attr) .
70
-               ($escape ? $this->escape($contents) : $contents) .
71
-               $this->end($tag);
72
-    }
73
-
74
-    protected function elementEmpty($tag, $attr = array()) {
75
-        return $this->generator->generateFromToken(
76
-            new HTMLPurifier_Token_Empty($tag, $attr)
77
-        );
78
-    }
79
-
80
-    protected function text($text) {
81
-        return $this->generator->generateFromToken(
82
-            new HTMLPurifier_Token_Text($text)
83
-        );
84
-    }
85
-
86
-    /**
87
-     * Prints a simple key/value row in a table.
88
-     * @param $name Key
89
-     * @param $value Value
90
-     */
91
-    protected function row($name, $value) {
92
-        if (is_bool($value)) $value = $value ? 'On' : 'Off';
93
-        return
94
-            $this->start('tr') . "\n" .
95
-                $this->element('th', $name) . "\n" .
96
-                $this->element('td', $value) . "\n" .
97
-            $this->end('tr')
98
-        ;
99
-    }
100
-
101
-    /**
102
-     * Escapes a string for HTML output.
103
-     * @param $string String to escape
104
-     */
105
-    protected function escape($string) {
106
-        $string = HTMLPurifier_Encoder::cleanUTF8($string);
107
-        $string = htmlspecialchars($string, ENT_COMPAT, 'UTF-8', false);
108
-        return $string;
109
-    }
110
-
111
-    /**
112
-     * Takes a list of strings and turns them into a single list
113
-     * @param $array List of strings
114
-     * @param $polite Bool whether or not to add an end before the last
115
-     */
116
-    protected function listify($array, $polite = false) {
117
-        if (empty($array)) return 'None';
118
-        $ret = '';
119
-        $i = count($array);
120
-        foreach ($array as $value) {
121
-            $i--;
122
-            $ret .= $value;
123
-            if ($i > 0 && !($polite && $i == 1)) $ret .= ', ';
124
-            if ($polite && $i == 1) $ret .= 'and ';
125
-        }
126
-        return $ret;
127
-    }
128
-
129
-    /**
130
-     * Retrieves the class of an object without prefixes, as well as metadata
131
-     * @param $obj Object to determine class of
132
-     * @param $prefix Further prefix to remove
133
-     */
134
-    protected function getClass($obj, $sec_prefix = '') {
135
-        static $five = null;
136
-        if ($five === null) $five = version_compare(PHP_VERSION, '5', '>=');
137
-        $prefix = 'HTMLPurifier_' . $sec_prefix;
138
-        if (!$five) $prefix = strtolower($prefix);
139
-        $class = str_replace($prefix, '', get_class($obj));
140
-        $lclass = strtolower($class);
141
-        $class .= '(';
142
-        switch ($lclass) {
143
-            case 'enum':
144
-                $values = array();
145
-                foreach ($obj->valid_values as $value => $bool) {
146
-                    $values[] = $value;
147
-                }
148
-                $class .= implode(', ', $values);
149
-                break;
150
-            case 'css_composite':
151
-                $values = array();
152
-                foreach ($obj->defs as $def) {
153
-                    $values[] = $this->getClass($def, $sec_prefix);
154
-                }
155
-                $class .= implode(', ', $values);
156
-                break;
157
-            case 'css_multiple':
158
-                $class .= $this->getClass($obj->single, $sec_prefix) . ', ';
159
-                $class .= $obj->max;
160
-                break;
161
-            case 'css_denyelementdecorator':
162
-                $class .= $this->getClass($obj->def, $sec_prefix) . ', ';
163
-                $class .= $obj->element;
164
-                break;
165
-            case 'css_importantdecorator':
166
-                $class .= $this->getClass($obj->def, $sec_prefix);
167
-                if ($obj->allow) $class .= ', !important';
168
-                break;
169
-        }
170
-        $class .= ')';
171
-        return $class;
172
-    }
9
+	/**
10
+	 * Instance of HTMLPurifier_Generator for HTML generation convenience funcs
11
+	 */
12
+	protected $generator;
13
+
14
+	/**
15
+	 * Instance of HTMLPurifier_Config, for easy access
16
+	 */
17
+	protected $config;
18
+
19
+	/**
20
+	 * Initialize $generator.
21
+	 */
22
+	public function __construct() {
23
+	}
24
+
25
+	/**
26
+	 * Give generator necessary configuration if possible
27
+	 */
28
+	public function prepareGenerator($config) {
29
+		$all = $config->getAll();
30
+		$context = new HTMLPurifier_Context();
31
+		$this->generator = new HTMLPurifier_Generator($config, $context);
32
+	}
33
+
34
+	/**
35
+	 * Main function that renders object or aspect of that object
36
+	 * @note Parameters vary depending on printer
37
+	 */
38
+	// function render() {}
39
+
40
+	/**
41
+	 * Returns a start tag
42
+	 * @param $tag Tag name
43
+	 * @param $attr Attribute array
44
+	 */
45
+	protected function start($tag, $attr = array()) {
46
+		return $this->generator->generateFromToken(
47
+					new HTMLPurifier_Token_Start($tag, $attr ? $attr : array())
48
+			   );
49
+	}
50
+
51
+	/**
52
+	 * Returns an end teg
53
+	 * @param $tag Tag name
54
+	 */
55
+	protected function end($tag) {
56
+		return $this->generator->generateFromToken(
57
+					new HTMLPurifier_Token_End($tag)
58
+			   );
59
+	}
60
+
61
+	/**
62
+	 * Prints a complete element with content inside
63
+	 * @param $tag Tag name
64
+	 * @param $contents Element contents
65
+	 * @param $attr Tag attributes
66
+	 * @param $escape Bool whether or not to escape contents
67
+	 */
68
+	protected function element($tag, $contents, $attr = array(), $escape = true) {
69
+		return $this->start($tag, $attr) .
70
+			   ($escape ? $this->escape($contents) : $contents) .
71
+			   $this->end($tag);
72
+	}
73
+
74
+	protected function elementEmpty($tag, $attr = array()) {
75
+		return $this->generator->generateFromToken(
76
+			new HTMLPurifier_Token_Empty($tag, $attr)
77
+		);
78
+	}
79
+
80
+	protected function text($text) {
81
+		return $this->generator->generateFromToken(
82
+			new HTMLPurifier_Token_Text($text)
83
+		);
84
+	}
85
+
86
+	/**
87
+	 * Prints a simple key/value row in a table.
88
+	 * @param $name Key
89
+	 * @param $value Value
90
+	 */
91
+	protected function row($name, $value) {
92
+		if (is_bool($value)) $value = $value ? 'On' : 'Off';
93
+		return
94
+			$this->start('tr') . "\n" .
95
+				$this->element('th', $name) . "\n" .
96
+				$this->element('td', $value) . "\n" .
97
+			$this->end('tr')
98
+		;
99
+	}
100
+
101
+	/**
102
+	 * Escapes a string for HTML output.
103
+	 * @param $string String to escape
104
+	 */
105
+	protected function escape($string) {
106
+		$string = HTMLPurifier_Encoder::cleanUTF8($string);
107
+		$string = htmlspecialchars($string, ENT_COMPAT, 'UTF-8', false);
108
+		return $string;
109
+	}
110
+
111
+	/**
112
+	 * Takes a list of strings and turns them into a single list
113
+	 * @param $array List of strings
114
+	 * @param $polite Bool whether or not to add an end before the last
115
+	 */
116
+	protected function listify($array, $polite = false) {
117
+		if (empty($array)) return 'None';
118
+		$ret = '';
119
+		$i = count($array);
120
+		foreach ($array as $value) {
121
+			$i--;
122
+			$ret .= $value;
123
+			if ($i > 0 && !($polite && $i == 1)) $ret .= ', ';
124
+			if ($polite && $i == 1) $ret .= 'and ';
125
+		}
126
+		return $ret;
127
+	}
128
+
129
+	/**
130
+	 * Retrieves the class of an object without prefixes, as well as metadata
131
+	 * @param $obj Object to determine class of
132
+	 * @param $prefix Further prefix to remove
133
+	 */
134
+	protected function getClass($obj, $sec_prefix = '') {
135
+		static $five = null;
136
+		if ($five === null) $five = version_compare(PHP_VERSION, '5', '>=');
137
+		$prefix = 'HTMLPurifier_' . $sec_prefix;
138
+		if (!$five) $prefix = strtolower($prefix);
139
+		$class = str_replace($prefix, '', get_class($obj));
140
+		$lclass = strtolower($class);
141
+		$class .= '(';
142
+		switch ($lclass) {
143
+			case 'enum':
144
+				$values = array();
145
+				foreach ($obj->valid_values as $value => $bool) {
146
+					$values[] = $value;
147
+				}
148
+				$class .= implode(', ', $values);
149
+				break;
150
+			case 'css_composite':
151
+				$values = array();
152
+				foreach ($obj->defs as $def) {
153
+					$values[] = $this->getClass($def, $sec_prefix);
154
+				}
155
+				$class .= implode(', ', $values);
156
+				break;
157
+			case 'css_multiple':
158
+				$class .= $this->getClass($obj->single, $sec_prefix) . ', ';
159
+				$class .= $obj->max;
160
+				break;
161
+			case 'css_denyelementdecorator':
162
+				$class .= $this->getClass($obj->def, $sec_prefix) . ', ';
163
+				$class .= $obj->element;
164
+				break;
165
+			case 'css_importantdecorator':
166
+				$class .= $this->getClass($obj->def, $sec_prefix);
167
+				if ($obj->allow) $class .= ', !important';
168
+				break;
169
+		}
170
+		$class .= ')';
171
+		return $class;
172
+	}
173 173
 
174 174
 }
175 175
 
Please login to merge, or discard this patch.
Braces   +21 added lines, -7 removed lines patch added patch discarded remove patch
@@ -89,7 +89,9 @@  discard block
 block discarded – undo
89 89
      * @param $value Value
90 90
      */
91 91
     protected function row($name, $value) {
92
-        if (is_bool($value)) $value = $value ? 'On' : 'Off';
92
+        if (is_bool($value)) {
93
+        	$value = $value ? 'On' : 'Off';
94
+        }
93 95
         return
94 96
             $this->start('tr') . "\n" .
95 97
                 $this->element('th', $name) . "\n" .
@@ -114,14 +116,20 @@  discard block
 block discarded – undo
114 116
      * @param $polite Bool whether or not to add an end before the last
115 117
      */
116 118
     protected function listify($array, $polite = false) {
117
-        if (empty($array)) return 'None';
119
+        if (empty($array)) {
120
+        	return 'None';
121
+        }
118 122
         $ret = '';
119 123
         $i = count($array);
120 124
         foreach ($array as $value) {
121 125
             $i--;
122 126
             $ret .= $value;
123
-            if ($i > 0 && !($polite && $i == 1)) $ret .= ', ';
124
-            if ($polite && $i == 1) $ret .= 'and ';
127
+            if ($i > 0 && !($polite && $i == 1)) {
128
+            	$ret .= ', ';
129
+            }
130
+            if ($polite && $i == 1) {
131
+            	$ret .= 'and ';
132
+            }
125 133
         }
126 134
         return $ret;
127 135
     }
@@ -133,9 +141,13 @@  discard block
 block discarded – undo
133 141
      */
134 142
     protected function getClass($obj, $sec_prefix = '') {
135 143
         static $five = null;
136
-        if ($five === null) $five = version_compare(PHP_VERSION, '5', '>=');
144
+        if ($five === null) {
145
+        	$five = version_compare(PHP_VERSION, '5', '>=');
146
+        }
137 147
         $prefix = 'HTMLPurifier_' . $sec_prefix;
138
-        if (!$five) $prefix = strtolower($prefix);
148
+        if (!$five) {
149
+        	$prefix = strtolower($prefix);
150
+        }
139 151
         $class = str_replace($prefix, '', get_class($obj));
140 152
         $lclass = strtolower($class);
141 153
         $class .= '(';
@@ -164,7 +176,9 @@  discard block
 block discarded – undo
164 176
                 break;
165 177
             case 'css_importantdecorator':
166 178
                 $class .= $this->getClass($obj->def, $sec_prefix);
167
-                if ($obj->allow) $class .= ', !important';
179
+                if ($obj->allow) {
180
+                	$class .= ', !important';
181
+                }
168 182
                 break;
169 183
         }
170 184
         $class .= ')';
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
      * @param $escape Bool whether or not to escape contents
67 67
      */
68 68
     protected function element($tag, $contents, $attr = array(), $escape = true) {
69
-        return $this->start($tag, $attr) .
70
-               ($escape ? $this->escape($contents) : $contents) .
69
+        return $this->start($tag, $attr).
70
+               ($escape ? $this->escape($contents) : $contents).
71 71
                $this->end($tag);
72 72
     }
73 73
 
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
     protected function row($name, $value) {
92 92
         if (is_bool($value)) $value = $value ? 'On' : 'Off';
93 93
         return
94
-            $this->start('tr') . "\n" .
95
-                $this->element('th', $name) . "\n" .
96
-                $this->element('td', $value) . "\n" .
94
+            $this->start('tr')."\n".
95
+                $this->element('th', $name)."\n".
96
+                $this->element('td', $value)."\n".
97 97
             $this->end('tr')
98 98
         ;
99 99
     }
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
     protected function getClass($obj, $sec_prefix = '') {
135 135
         static $five = null;
136 136
         if ($five === null) $five = version_compare(PHP_VERSION, '5', '>=');
137
-        $prefix = 'HTMLPurifier_' . $sec_prefix;
137
+        $prefix = 'HTMLPurifier_'.$sec_prefix;
138 138
         if (!$five) $prefix = strtolower($prefix);
139 139
         $class = str_replace($prefix, '', get_class($obj));
140 140
         $lclass = strtolower($class);
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
                 $class .= implode(', ', $values);
156 156
                 break;
157 157
             case 'css_multiple':
158
-                $class .= $this->getClass($obj->single, $sec_prefix) . ', ';
158
+                $class .= $this->getClass($obj->single, $sec_prefix).', ';
159 159
                 $class .= $obj->max;
160 160
                 break;
161 161
             case 'css_denyelementdecorator':
162
-                $class .= $this->getClass($obj->def, $sec_prefix) . ', ';
162
+                $class .= $this->getClass($obj->def, $sec_prefix).', ';
163 163
                 $class .= $obj->element;
164 164
                 break;
165 165
             case 'css_importantdecorator':
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/UnitConverter.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -192,6 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
     /**
194 194
      * Multiples two numbers, using arbitrary precision when available.
195
+     * @param integer $scale
195 196
      */
196 197
     private function mul($s1, $s2, $scale) {
197 198
         if ($this->bcmath) return bcmul($s1, $s2, $scale);
@@ -200,6 +201,7 @@  discard block
 block discarded – undo
200 201
 
201 202
     /**
202 203
      * Divides two numbers, using arbitrary precision when available.
204
+     * @param integer $scale
203 205
      */
204 206
     private function div($s1, $s2, $scale) {
205 207
         if ($this->bcmath) return bcdiv($s1, $s2, $scale);
@@ -209,6 +211,7 @@  discard block
 block discarded – undo
209 211
     /**
210 212
      * Rounds a number according to the number of sigfigs it should have,
211 213
      * using arbitrary precision when available.
214
+     * @param integer $sigfigs
212 215
      */
213 216
     private function round($n, $sigfigs) {
214 217
         $new_log = (int) floor(log(abs($n), 10)); // Number of digits left of decimal - 1
Please login to merge, or discard this patch.
Indentation   +241 added lines, -241 removed lines patch added patch discarded remove patch
@@ -7,247 +7,247 @@
 block discarded – undo
7 7
 class HTMLPurifier_UnitConverter
8 8
 {
9 9
 
10
-    const ENGLISH = 1;
11
-    const METRIC = 2;
12
-    const DIGITAL = 3;
13
-
14
-    /**
15
-     * Units information array. Units are grouped into measuring systems
16
-     * (English, Metric), and are assigned an integer representing
17
-     * the conversion factor between that unit and the smallest unit in
18
-     * the system. Numeric indexes are actually magical constants that
19
-     * encode conversion data from one system to the next, with a O(n^2)
20
-     * constraint on memory (this is generally not a problem, since
21
-     * the number of measuring systems is small.)
22
-     */
23
-    protected static $units = array(
24
-        self::ENGLISH => array(
25
-            'px' => 3, // This is as per CSS 2.1 and Firefox. Your mileage may vary
26
-            'pt' => 4,
27
-            'pc' => 48,
28
-            'in' => 288,
29
-            self::METRIC => array('pt', '0.352777778', 'mm'),
30
-        ),
31
-        self::METRIC => array(
32
-            'mm' => 1,
33
-            'cm' => 10,
34
-            self::ENGLISH => array('mm', '2.83464567', 'pt'),
35
-        ),
36
-    );
37
-
38
-    /**
39
-     * Minimum bcmath precision for output.
40
-     */
41
-    protected $outputPrecision;
42
-
43
-    /**
44
-     * Bcmath precision for internal calculations.
45
-     */
46
-    protected $internalPrecision;
47
-
48
-    /**
49
-     * Whether or not BCMath is available
50
-     */
51
-    private $bcmath;
52
-
53
-    public function __construct($output_precision = 4, $internal_precision = 10, $force_no_bcmath = false) {
54
-        $this->outputPrecision = $output_precision;
55
-        $this->internalPrecision = $internal_precision;
56
-        $this->bcmath = !$force_no_bcmath && function_exists('bcmul');
57
-    }
58
-
59
-    /**
60
-     * Converts a length object of one unit into another unit.
61
-     * @param HTMLPurifier_Length $length
62
-     *      Instance of HTMLPurifier_Length to convert. You must validate()
63
-     *      it before passing it here!
64
-     * @param string $to_unit
65
-     *      Unit to convert to.
66
-     * @note
67
-     *      About precision: This conversion function pays very special
68
-     *      attention to the incoming precision of values and attempts
69
-     *      to maintain a number of significant figure. Results are
70
-     *      fairly accurate up to nine digits. Some caveats:
71
-     *          - If a number is zero-padded as a result of this significant
72
-     *            figure tracking, the zeroes will be eliminated.
73
-     *          - If a number contains less than four sigfigs ($outputPrecision)
74
-     *            and this causes some decimals to be excluded, those
75
-     *            decimals will be added on.
76
-     */
77
-    public function convert($length, $to_unit) {
78
-
79
-        if (!$length->isValid()) return false;
80
-
81
-        $n    = $length->getN();
82
-        $unit = $length->getUnit();
83
-
84
-        if ($n === '0' || $unit === false) {
85
-            return new HTMLPurifier_Length('0', false);
86
-        }
87
-
88
-        $state = $dest_state = false;
89
-        foreach (self::$units as $k => $x) {
90
-            if (isset($x[$unit])) $state = $k;
91
-            if (isset($x[$to_unit])) $dest_state = $k;
92
-        }
93
-        if (!$state || !$dest_state) return false;
94
-
95
-        // Some calculations about the initial precision of the number;
96
-        // this will be useful when we need to do final rounding.
97
-        $sigfigs = $this->getSigFigs($n);
98
-        if ($sigfigs < $this->outputPrecision) $sigfigs = $this->outputPrecision;
99
-
100
-        // BCMath's internal precision deals only with decimals. Use
101
-        // our default if the initial number has no decimals, or increase
102
-        // it by how ever many decimals, thus, the number of guard digits
103
-        // will always be greater than or equal to internalPrecision.
104
-        $log = (int) floor(log(abs($n), 10));
105
-        $cp = ($log < 0) ? $this->internalPrecision - $log : $this->internalPrecision; // internal precision
106
-
107
-        for ($i = 0; $i < 2; $i++) {
108
-
109
-            // Determine what unit IN THIS SYSTEM we need to convert to
110
-            if ($dest_state === $state) {
111
-                // Simple conversion
112
-                $dest_unit = $to_unit;
113
-            } else {
114
-                // Convert to the smallest unit, pending a system shift
115
-                $dest_unit = self::$units[$state][$dest_state][0];
116
-            }
117
-
118
-            // Do the conversion if necessary
119
-            if ($dest_unit !== $unit) {
120
-                $factor = $this->div(self::$units[$state][$unit], self::$units[$state][$dest_unit], $cp);
121
-                $n = $this->mul($n, $factor, $cp);
122
-                $unit = $dest_unit;
123
-            }
124
-
125
-            // Output was zero, so bail out early. Shouldn't ever happen.
126
-            if ($n === '') {
127
-                $n = '0';
128
-                $unit = $to_unit;
129
-                break;
130
-            }
131
-
132
-            // It was a simple conversion, so bail out
133
-            if ($dest_state === $state) {
134
-                break;
135
-            }
136
-
137
-            if ($i !== 0) {
138
-                // Conversion failed! Apparently, the system we forwarded
139
-                // to didn't have this unit. This should never happen!
140
-                return false;
141
-            }
142
-
143
-            // Pre-condition: $i == 0
144
-
145
-            // Perform conversion to next system of units
146
-            $n = $this->mul($n, self::$units[$state][$dest_state][1], $cp);
147
-            $unit = self::$units[$state][$dest_state][2];
148
-            $state = $dest_state;
149
-
150
-            // One more loop around to convert the unit in the new system.
151
-
152
-        }
153
-
154
-        // Post-condition: $unit == $to_unit
155
-        if ($unit !== $to_unit) return false;
156
-
157
-        // Useful for debugging:
158
-        //echo "<pre>n";
159
-        //echo "$n\nsigfigs = $sigfigs\nnew_log = $new_log\nlog = $log\nrp = $rp\n</pre>\n";
160
-
161
-        $n = $this->round($n, $sigfigs);
162
-        if (strpos($n, '.') !== false) $n = rtrim($n, '0');
163
-        $n = rtrim($n, '.');
164
-
165
-        return new HTMLPurifier_Length($n, $unit);
166
-    }
167
-
168
-    /**
169
-     * Returns the number of significant figures in a string number.
170
-     * @param string $n Decimal number
171
-     * @return int number of sigfigs
172
-     */
173
-    public function getSigFigs($n) {
174
-        $n = ltrim($n, '0+-');
175
-        $dp = strpos($n, '.'); // decimal position
176
-        if ($dp === false) {
177
-            $sigfigs = strlen(rtrim($n, '0'));
178
-        } else {
179
-            $sigfigs = strlen(ltrim($n, '0.')); // eliminate extra decimal character
180
-            if ($dp !== 0) $sigfigs--;
181
-        }
182
-        return $sigfigs;
183
-    }
184
-
185
-    /**
186
-     * Adds two numbers, using arbitrary precision when available.
187
-     */
188
-    private function add($s1, $s2, $scale) {
189
-        if ($this->bcmath) return bcadd($s1, $s2, $scale);
190
-        else return $this->scale($s1 + $s2, $scale);
191
-    }
192
-
193
-    /**
194
-     * Multiples two numbers, using arbitrary precision when available.
195
-     */
196
-    private function mul($s1, $s2, $scale) {
197
-        if ($this->bcmath) return bcmul($s1, $s2, $scale);
198
-        else return $this->scale($s1 * $s2, $scale);
199
-    }
200
-
201
-    /**
202
-     * Divides two numbers, using arbitrary precision when available.
203
-     */
204
-    private function div($s1, $s2, $scale) {
205
-        if ($this->bcmath) return bcdiv($s1, $s2, $scale);
206
-        else return $this->scale($s1 / $s2, $scale);
207
-    }
208
-
209
-    /**
210
-     * Rounds a number according to the number of sigfigs it should have,
211
-     * using arbitrary precision when available.
212
-     */
213
-    private function round($n, $sigfigs) {
214
-        $new_log = (int) floor(log(abs($n), 10)); // Number of digits left of decimal - 1
215
-        $rp = $sigfigs - $new_log - 1; // Number of decimal places needed
216
-        $neg = $n < 0 ? '-' : ''; // Negative sign
217
-        if ($this->bcmath) {
218
-            if ($rp >= 0) {
219
-                $n = bcadd($n, $neg . '0.' .  str_repeat('0', $rp) . '5', $rp + 1);
220
-                $n = bcdiv($n, '1', $rp);
221
-            } else {
222
-                // This algorithm partially depends on the standardized
223
-                // form of numbers that comes out of bcmath.
224
-                $n = bcadd($n, $neg . '5' . str_repeat('0', $new_log - $sigfigs), 0);
225
-                $n = substr($n, 0, $sigfigs + strlen($neg)) . str_repeat('0', $new_log - $sigfigs + 1);
226
-            }
227
-            return $n;
228
-        } else {
229
-            return $this->scale(round($n, $sigfigs - $new_log - 1), $rp + 1);
230
-        }
231
-    }
232
-
233
-    /**
234
-     * Scales a float to $scale digits right of decimal point, like BCMath.
235
-     */
236
-    private function scale($r, $scale) {
237
-        if ($scale < 0) {
238
-            // The f sprintf type doesn't support negative numbers, so we
239
-            // need to cludge things manually. First get the string.
240
-            $r = sprintf('%.0f', (float) $r);
241
-            // Due to floating point precision loss, $r will more than likely
242
-            // look something like 4652999999999.9234. We grab one more digit
243
-            // than we need to precise from $r and then use that to round
244
-            // appropriately.
245
-            $precise = (string) round(substr($r, 0, strlen($r) + $scale), -1);
246
-            // Now we return it, truncating the zero that was rounded off.
247
-            return substr($precise, 0, -1) . str_repeat('0', -$scale + 1);
248
-        }
249
-        return sprintf('%.' . $scale . 'f', (float) $r);
250
-    }
10
+	const ENGLISH = 1;
11
+	const METRIC = 2;
12
+	const DIGITAL = 3;
13
+
14
+	/**
15
+	 * Units information array. Units are grouped into measuring systems
16
+	 * (English, Metric), and are assigned an integer representing
17
+	 * the conversion factor between that unit and the smallest unit in
18
+	 * the system. Numeric indexes are actually magical constants that
19
+	 * encode conversion data from one system to the next, with a O(n^2)
20
+	 * constraint on memory (this is generally not a problem, since
21
+	 * the number of measuring systems is small.)
22
+	 */
23
+	protected static $units = array(
24
+		self::ENGLISH => array(
25
+			'px' => 3, // This is as per CSS 2.1 and Firefox. Your mileage may vary
26
+			'pt' => 4,
27
+			'pc' => 48,
28
+			'in' => 288,
29
+			self::METRIC => array('pt', '0.352777778', 'mm'),
30
+		),
31
+		self::METRIC => array(
32
+			'mm' => 1,
33
+			'cm' => 10,
34
+			self::ENGLISH => array('mm', '2.83464567', 'pt'),
35
+		),
36
+	);
37
+
38
+	/**
39
+	 * Minimum bcmath precision for output.
40
+	 */
41
+	protected $outputPrecision;
42
+
43
+	/**
44
+	 * Bcmath precision for internal calculations.
45
+	 */
46
+	protected $internalPrecision;
47
+
48
+	/**
49
+	 * Whether or not BCMath is available
50
+	 */
51
+	private $bcmath;
52
+
53
+	public function __construct($output_precision = 4, $internal_precision = 10, $force_no_bcmath = false) {
54
+		$this->outputPrecision = $output_precision;
55
+		$this->internalPrecision = $internal_precision;
56
+		$this->bcmath = !$force_no_bcmath && function_exists('bcmul');
57
+	}
58
+
59
+	/**
60
+	 * Converts a length object of one unit into another unit.
61
+	 * @param HTMLPurifier_Length $length
62
+	 *      Instance of HTMLPurifier_Length to convert. You must validate()
63
+	 *      it before passing it here!
64
+	 * @param string $to_unit
65
+	 *      Unit to convert to.
66
+	 * @note
67
+	 *      About precision: This conversion function pays very special
68
+	 *      attention to the incoming precision of values and attempts
69
+	 *      to maintain a number of significant figure. Results are
70
+	 *      fairly accurate up to nine digits. Some caveats:
71
+	 *          - If a number is zero-padded as a result of this significant
72
+	 *            figure tracking, the zeroes will be eliminated.
73
+	 *          - If a number contains less than four sigfigs ($outputPrecision)
74
+	 *            and this causes some decimals to be excluded, those
75
+	 *            decimals will be added on.
76
+	 */
77
+	public function convert($length, $to_unit) {
78
+
79
+		if (!$length->isValid()) return false;
80
+
81
+		$n    = $length->getN();
82
+		$unit = $length->getUnit();
83
+
84
+		if ($n === '0' || $unit === false) {
85
+			return new HTMLPurifier_Length('0', false);
86
+		}
87
+
88
+		$state = $dest_state = false;
89
+		foreach (self::$units as $k => $x) {
90
+			if (isset($x[$unit])) $state = $k;
91
+			if (isset($x[$to_unit])) $dest_state = $k;
92
+		}
93
+		if (!$state || !$dest_state) return false;
94
+
95
+		// Some calculations about the initial precision of the number;
96
+		// this will be useful when we need to do final rounding.
97
+		$sigfigs = $this->getSigFigs($n);
98
+		if ($sigfigs < $this->outputPrecision) $sigfigs = $this->outputPrecision;
99
+
100
+		// BCMath's internal precision deals only with decimals. Use
101
+		// our default if the initial number has no decimals, or increase
102
+		// it by how ever many decimals, thus, the number of guard digits
103
+		// will always be greater than or equal to internalPrecision.
104
+		$log = (int) floor(log(abs($n), 10));
105
+		$cp = ($log < 0) ? $this->internalPrecision - $log : $this->internalPrecision; // internal precision
106
+
107
+		for ($i = 0; $i < 2; $i++) {
108
+
109
+			// Determine what unit IN THIS SYSTEM we need to convert to
110
+			if ($dest_state === $state) {
111
+				// Simple conversion
112
+				$dest_unit = $to_unit;
113
+			} else {
114
+				// Convert to the smallest unit, pending a system shift
115
+				$dest_unit = self::$units[$state][$dest_state][0];
116
+			}
117
+
118
+			// Do the conversion if necessary
119
+			if ($dest_unit !== $unit) {
120
+				$factor = $this->div(self::$units[$state][$unit], self::$units[$state][$dest_unit], $cp);
121
+				$n = $this->mul($n, $factor, $cp);
122
+				$unit = $dest_unit;
123
+			}
124
+
125
+			// Output was zero, so bail out early. Shouldn't ever happen.
126
+			if ($n === '') {
127
+				$n = '0';
128
+				$unit = $to_unit;
129
+				break;
130
+			}
131
+
132
+			// It was a simple conversion, so bail out
133
+			if ($dest_state === $state) {
134
+				break;
135
+			}
136
+
137
+			if ($i !== 0) {
138
+				// Conversion failed! Apparently, the system we forwarded
139
+				// to didn't have this unit. This should never happen!
140
+				return false;
141
+			}
142
+
143
+			// Pre-condition: $i == 0
144
+
145
+			// Perform conversion to next system of units
146
+			$n = $this->mul($n, self::$units[$state][$dest_state][1], $cp);
147
+			$unit = self::$units[$state][$dest_state][2];
148
+			$state = $dest_state;
149
+
150
+			// One more loop around to convert the unit in the new system.
151
+
152
+		}
153
+
154
+		// Post-condition: $unit == $to_unit
155
+		if ($unit !== $to_unit) return false;
156
+
157
+		// Useful for debugging:
158
+		//echo "<pre>n";
159
+		//echo "$n\nsigfigs = $sigfigs\nnew_log = $new_log\nlog = $log\nrp = $rp\n</pre>\n";
160
+
161
+		$n = $this->round($n, $sigfigs);
162
+		if (strpos($n, '.') !== false) $n = rtrim($n, '0');
163
+		$n = rtrim($n, '.');
164
+
165
+		return new HTMLPurifier_Length($n, $unit);
166
+	}
167
+
168
+	/**
169
+	 * Returns the number of significant figures in a string number.
170
+	 * @param string $n Decimal number
171
+	 * @return int number of sigfigs
172
+	 */
173
+	public function getSigFigs($n) {
174
+		$n = ltrim($n, '0+-');
175
+		$dp = strpos($n, '.'); // decimal position
176
+		if ($dp === false) {
177
+			$sigfigs = strlen(rtrim($n, '0'));
178
+		} else {
179
+			$sigfigs = strlen(ltrim($n, '0.')); // eliminate extra decimal character
180
+			if ($dp !== 0) $sigfigs--;
181
+		}
182
+		return $sigfigs;
183
+	}
184
+
185
+	/**
186
+	 * Adds two numbers, using arbitrary precision when available.
187
+	 */
188
+	private function add($s1, $s2, $scale) {
189
+		if ($this->bcmath) return bcadd($s1, $s2, $scale);
190
+		else return $this->scale($s1 + $s2, $scale);
191
+	}
192
+
193
+	/**
194
+	 * Multiples two numbers, using arbitrary precision when available.
195
+	 */
196
+	private function mul($s1, $s2, $scale) {
197
+		if ($this->bcmath) return bcmul($s1, $s2, $scale);
198
+		else return $this->scale($s1 * $s2, $scale);
199
+	}
200
+
201
+	/**
202
+	 * Divides two numbers, using arbitrary precision when available.
203
+	 */
204
+	private function div($s1, $s2, $scale) {
205
+		if ($this->bcmath) return bcdiv($s1, $s2, $scale);
206
+		else return $this->scale($s1 / $s2, $scale);
207
+	}
208
+
209
+	/**
210
+	 * Rounds a number according to the number of sigfigs it should have,
211
+	 * using arbitrary precision when available.
212
+	 */
213
+	private function round($n, $sigfigs) {
214
+		$new_log = (int) floor(log(abs($n), 10)); // Number of digits left of decimal - 1
215
+		$rp = $sigfigs - $new_log - 1; // Number of decimal places needed
216
+		$neg = $n < 0 ? '-' : ''; // Negative sign
217
+		if ($this->bcmath) {
218
+			if ($rp >= 0) {
219
+				$n = bcadd($n, $neg . '0.' .  str_repeat('0', $rp) . '5', $rp + 1);
220
+				$n = bcdiv($n, '1', $rp);
221
+			} else {
222
+				// This algorithm partially depends on the standardized
223
+				// form of numbers that comes out of bcmath.
224
+				$n = bcadd($n, $neg . '5' . str_repeat('0', $new_log - $sigfigs), 0);
225
+				$n = substr($n, 0, $sigfigs + strlen($neg)) . str_repeat('0', $new_log - $sigfigs + 1);
226
+			}
227
+			return $n;
228
+		} else {
229
+			return $this->scale(round($n, $sigfigs - $new_log - 1), $rp + 1);
230
+		}
231
+	}
232
+
233
+	/**
234
+	 * Scales a float to $scale digits right of decimal point, like BCMath.
235
+	 */
236
+	private function scale($r, $scale) {
237
+		if ($scale < 0) {
238
+			// The f sprintf type doesn't support negative numbers, so we
239
+			// need to cludge things manually. First get the string.
240
+			$r = sprintf('%.0f', (float) $r);
241
+			// Due to floating point precision loss, $r will more than likely
242
+			// look something like 4652999999999.9234. We grab one more digit
243
+			// than we need to precise from $r and then use that to round
244
+			// appropriately.
245
+			$precise = (string) round(substr($r, 0, strlen($r) + $scale), -1);
246
+			// Now we return it, truncating the zero that was rounded off.
247
+			return substr($precise, 0, -1) . str_repeat('0', -$scale + 1);
248
+		}
249
+		return sprintf('%.' . $scale . 'f', (float) $r);
250
+	}
251 251
 
252 252
 }
253 253
 
Please login to merge, or discard this patch.
Braces   +39 added lines, -14 removed lines patch added patch discarded remove patch
@@ -76,7 +76,9 @@  discard block
 block discarded – undo
76 76
      */
77 77
     public function convert($length, $to_unit) {
78 78
 
79
-        if (!$length->isValid()) return false;
79
+        if (!$length->isValid()) {
80
+        	return false;
81
+        }
80 82
 
81 83
         $n    = $length->getN();
82 84
         $unit = $length->getUnit();
@@ -87,15 +89,23 @@  discard block
 block discarded – undo
87 89
 
88 90
         $state = $dest_state = false;
89 91
         foreach (self::$units as $k => $x) {
90
-            if (isset($x[$unit])) $state = $k;
91
-            if (isset($x[$to_unit])) $dest_state = $k;
92
+            if (isset($x[$unit])) {
93
+            	$state = $k;
94
+            }
95
+            if (isset($x[$to_unit])) {
96
+            	$dest_state = $k;
97
+            }
98
+        }
99
+        if (!$state || !$dest_state) {
100
+        	return false;
92 101
         }
93
-        if (!$state || !$dest_state) return false;
94 102
 
95 103
         // Some calculations about the initial precision of the number;
96 104
         // this will be useful when we need to do final rounding.
97 105
         $sigfigs = $this->getSigFigs($n);
98
-        if ($sigfigs < $this->outputPrecision) $sigfigs = $this->outputPrecision;
106
+        if ($sigfigs < $this->outputPrecision) {
107
+        	$sigfigs = $this->outputPrecision;
108
+        }
99 109
 
100 110
         // BCMath's internal precision deals only with decimals. Use
101 111
         // our default if the initial number has no decimals, or increase
@@ -152,14 +162,18 @@  discard block
 block discarded – undo
152 162
         }
153 163
 
154 164
         // Post-condition: $unit == $to_unit
155
-        if ($unit !== $to_unit) return false;
165
+        if ($unit !== $to_unit) {
166
+        	return false;
167
+        }
156 168
 
157 169
         // Useful for debugging:
158 170
         //echo "<pre>n";
159 171
         //echo "$n\nsigfigs = $sigfigs\nnew_log = $new_log\nlog = $log\nrp = $rp\n</pre>\n";
160 172
 
161 173
         $n = $this->round($n, $sigfigs);
162
-        if (strpos($n, '.') !== false) $n = rtrim($n, '0');
174
+        if (strpos($n, '.') !== false) {
175
+        	$n = rtrim($n, '0');
176
+        }
163 177
         $n = rtrim($n, '.');
164 178
 
165 179
         return new HTMLPurifier_Length($n, $unit);
@@ -177,7 +191,9 @@  discard block
 block discarded – undo
177 191
             $sigfigs = strlen(rtrim($n, '0'));
178 192
         } else {
179 193
             $sigfigs = strlen(ltrim($n, '0.')); // eliminate extra decimal character
180
-            if ($dp !== 0) $sigfigs--;
194
+            if ($dp !== 0) {
195
+            	$sigfigs--;
196
+            }
181 197
         }
182 198
         return $sigfigs;
183 199
     }
@@ -186,24 +202,33 @@  discard block
 block discarded – undo
186 202
      * Adds two numbers, using arbitrary precision when available.
187 203
      */
188 204
     private function add($s1, $s2, $scale) {
189
-        if ($this->bcmath) return bcadd($s1, $s2, $scale);
190
-        else return $this->scale($s1 + $s2, $scale);
205
+        if ($this->bcmath) {
206
+        	return bcadd($s1, $s2, $scale);
207
+        } else {
208
+        	return $this->scale($s1 + $s2, $scale);
209
+        }
191 210
     }
192 211
 
193 212
     /**
194 213
      * Multiples two numbers, using arbitrary precision when available.
195 214
      */
196 215
     private function mul($s1, $s2, $scale) {
197
-        if ($this->bcmath) return bcmul($s1, $s2, $scale);
198
-        else return $this->scale($s1 * $s2, $scale);
216
+        if ($this->bcmath) {
217
+        	return bcmul($s1, $s2, $scale);
218
+        } else {
219
+        	return $this->scale($s1 * $s2, $scale);
220
+        }
199 221
     }
200 222
 
201 223
     /**
202 224
      * Divides two numbers, using arbitrary precision when available.
203 225
      */
204 226
     private function div($s1, $s2, $scale) {
205
-        if ($this->bcmath) return bcdiv($s1, $s2, $scale);
206
-        else return $this->scale($s1 / $s2, $scale);
227
+        if ($this->bcmath) {
228
+        	return bcdiv($s1, $s2, $scale);
229
+        } else {
230
+        	return $this->scale($s1 / $s2, $scale);
231
+        }
207 232
     }
208 233
 
209 234
     /**
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -216,13 +216,13 @@  discard block
 block discarded – undo
216 216
         $neg = $n < 0 ? '-' : ''; // Negative sign
217 217
         if ($this->bcmath) {
218 218
             if ($rp >= 0) {
219
-                $n = bcadd($n, $neg . '0.' .  str_repeat('0', $rp) . '5', $rp + 1);
219
+                $n = bcadd($n, $neg.'0.'.str_repeat('0', $rp).'5', $rp + 1);
220 220
                 $n = bcdiv($n, '1', $rp);
221 221
             } else {
222 222
                 // This algorithm partially depends on the standardized
223 223
                 // form of numbers that comes out of bcmath.
224
-                $n = bcadd($n, $neg . '5' . str_repeat('0', $new_log - $sigfigs), 0);
225
-                $n = substr($n, 0, $sigfigs + strlen($neg)) . str_repeat('0', $new_log - $sigfigs + 1);
224
+                $n = bcadd($n, $neg.'5'.str_repeat('0', $new_log - $sigfigs), 0);
225
+                $n = substr($n, 0, $sigfigs + strlen($neg)).str_repeat('0', $new_log - $sigfigs + 1);
226 226
             }
227 227
             return $n;
228 228
         } else {
@@ -244,9 +244,9 @@  discard block
 block discarded – undo
244 244
             // appropriately.
245 245
             $precise = (string) round(substr($r, 0, strlen($r) + $scale), -1);
246 246
             // Now we return it, truncating the zero that was rounded off.
247
-            return substr($precise, 0, -1) . str_repeat('0', -$scale + 1);
247
+            return substr($precise, 0, -1).str_repeat('0', -$scale + 1);
248 248
         }
249
-        return sprintf('%.' . $scale . 'f', (float) $r);
249
+        return sprintf('%.'.$scale.'f', (float) $r);
250 250
     }
251 251
 
252 252
 }
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/URI.php 4 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,6 +15,8 @@  discard block
 block discarded – undo
15 15
 
16 16
     /**
17 17
      * @note Automatically normalizes scheme and port
18
+     * @param string|null $host
19
+     * @param integer|null $port
18 20
      */
19 21
     public function __construct($scheme, $userinfo, $host, $port, $path, $query, $fragment) {
20 22
         $this->scheme = is_null($scheme) || ctype_lower($scheme) ? $scheme : strtolower($scheme);
@@ -58,7 +60,7 @@  discard block
 block discarded – undo
58 60
      * this URI in order to get it into a compliant form.
59 61
      * @param $config Instance of HTMLPurifier_Config
60 62
      * @param $context Instance of HTMLPurifier_Context
61
-     * @return True if validation/filtering succeeds, false if failure
63
+     * @return boolean if validation/filtering succeeds, false if failure
62 64
      */
63 65
     public function validate($config, $context) {
64 66
 
Please login to merge, or discard this patch.
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -11,231 +11,231 @@
 block discarded – undo
11 11
 class HTMLPurifier_URI
12 12
 {
13 13
 
14
-    public $scheme, $userinfo, $host, $port, $path, $query, $fragment;
15
-
16
-    /**
17
-     * @note Automatically normalizes scheme and port
18
-     */
19
-    public function __construct($scheme, $userinfo, $host, $port, $path, $query, $fragment) {
20
-        $this->scheme = is_null($scheme) || ctype_lower($scheme) ? $scheme : strtolower($scheme);
21
-        $this->userinfo = $userinfo;
22
-        $this->host = $host;
23
-        $this->port = is_null($port) ? $port : (int) $port;
24
-        $this->path = $path;
25
-        $this->query = $query;
26
-        $this->fragment = $fragment;
27
-    }
28
-
29
-    /**
30
-     * Retrieves a scheme object corresponding to the URI's scheme/default
31
-     * @param $config Instance of HTMLPurifier_Config
32
-     * @param $context Instance of HTMLPurifier_Context
33
-     * @return Scheme object appropriate for validating this URI
34
-     */
35
-    public function getSchemeObj($config, $context) {
36
-        $registry = HTMLPurifier_URISchemeRegistry::instance();
37
-        if ($this->scheme !== null) {
38
-            $scheme_obj = $registry->getScheme($this->scheme, $config, $context);
39
-            if (!$scheme_obj) return false; // invalid scheme, clean it out
40
-        } else {
41
-            // no scheme: retrieve the default one
42
-            $def = $config->getDefinition('URI');
43
-            $scheme_obj = $def->getDefaultScheme($config, $context);
44
-            if (!$scheme_obj) {
45
-                // something funky happened to the default scheme object
46
-                trigger_error(
47
-                    'Default scheme object "' . $def->defaultScheme . '" was not readable',
48
-                    E_USER_WARNING
49
-                );
50
-                return false;
51
-            }
52
-        }
53
-        return $scheme_obj;
54
-    }
55
-
56
-    /**
57
-     * Generic validation method applicable for all schemes. May modify
58
-     * this URI in order to get it into a compliant form.
59
-     * @param $config Instance of HTMLPurifier_Config
60
-     * @param $context Instance of HTMLPurifier_Context
61
-     * @return True if validation/filtering succeeds, false if failure
62
-     */
63
-    public function validate($config, $context) {
64
-
65
-        // ABNF definitions from RFC 3986
66
-        $chars_sub_delims = '!$&\'()*+,;=';
67
-        $chars_gen_delims = ':/?#[]@';
68
-        $chars_pchar = $chars_sub_delims . ':@';
69
-
70
-        // validate host
71
-        if (!is_null($this->host)) {
72
-            $host_def = new HTMLPurifier_AttrDef_URI_Host();
73
-            $this->host = $host_def->validate($this->host, $config, $context);
74
-            if ($this->host === false) $this->host = null;
75
-        }
76
-
77
-        // validate scheme
78
-        // NOTE: It's not appropriate to check whether or not this
79
-        // scheme is in our registry, since a URIFilter may convert a
80
-        // URI that we don't allow into one we do.  So instead, we just
81
-        // check if the scheme can be dropped because there is no host
82
-        // and it is our default scheme.
83
-        if (!is_null($this->scheme) && is_null($this->host) || $this->host === '') {
84
-            // support for relative paths is pretty abysmal when the
85
-            // scheme is present, so axe it when possible
86
-            $def = $config->getDefinition('URI');
87
-            if ($def->defaultScheme === $this->scheme) {
88
-                $this->scheme = null;
89
-            }
90
-        }
91
-
92
-        // validate username
93
-        if (!is_null($this->userinfo)) {
94
-            $encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims . ':');
95
-            $this->userinfo = $encoder->encode($this->userinfo);
96
-        }
97
-
98
-        // validate port
99
-        if (!is_null($this->port)) {
100
-            if ($this->port < 1 || $this->port > 65535) $this->port = null;
101
-        }
102
-
103
-        // validate path
104
-        $path_parts = array();
105
-        $segments_encoder = new HTMLPurifier_PercentEncoder($chars_pchar . '/');
106
-        if (!is_null($this->host)) { // this catches $this->host === ''
107
-            // path-abempty (hier and relative)
108
-            // http://www.example.com/my/path
109
-            // //www.example.com/my/path (looks odd, but works, and
110
-            //                            recognized by most browsers)
111
-            // (this set is valid or invalid on a scheme by scheme
112
-            // basis, so we'll deal with it later)
113
-            // file:///my/path
114
-            // ///my/path
115
-            $this->path = $segments_encoder->encode($this->path);
116
-        } elseif ($this->path !== '') {
117
-            if ($this->path[0] === '/') {
118
-                // path-absolute (hier and relative)
119
-                // http:/my/path
120
-                // /my/path
121
-                if (strlen($this->path) >= 2 && $this->path[1] === '/') {
122
-                    // This could happen if both the host gets stripped
123
-                    // out
124
-                    // http://my/path
125
-                    // //my/path
126
-                    $this->path = '';
127
-                } else {
128
-                    $this->path = $segments_encoder->encode($this->path);
129
-                }
130
-            } elseif (!is_null($this->scheme)) {
131
-                // path-rootless (hier)
132
-                // http:my/path
133
-                // Short circuit evaluation means we don't need to check nz
134
-                $this->path = $segments_encoder->encode($this->path);
135
-            } else {
136
-                // path-noscheme (relative)
137
-                // my/path
138
-                // (once again, not checking nz)
139
-                $segment_nc_encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims . '@');
140
-                $c = strpos($this->path, '/');
141
-                if ($c !== false) {
142
-                    $this->path =
143
-                        $segment_nc_encoder->encode(substr($this->path, 0, $c)) .
144
-                        $segments_encoder->encode(substr($this->path, $c));
145
-                } else {
146
-                    $this->path = $segment_nc_encoder->encode($this->path);
147
-                }
148
-            }
149
-        } else {
150
-            // path-empty (hier and relative)
151
-            $this->path = ''; // just to be safe
152
-        }
153
-
154
-        // qf = query and fragment
155
-        $qf_encoder = new HTMLPurifier_PercentEncoder($chars_pchar . '/?');
156
-
157
-        if (!is_null($this->query)) {
158
-            $this->query = $qf_encoder->encode($this->query);
159
-        }
160
-
161
-        if (!is_null($this->fragment)) {
162
-            $this->fragment = $qf_encoder->encode($this->fragment);
163
-        }
164
-
165
-        return true;
166
-
167
-    }
168
-
169
-    /**
170
-     * Convert URI back to string
171
-     * @return String URI appropriate for output
172
-     */
173
-    public function toString() {
174
-        // reconstruct authority
175
-        $authority = null;
176
-        // there is a rendering difference between a null authority
177
-        // (http:foo-bar) and an empty string authority
178
-        // (http:///foo-bar).
179
-        if (!is_null($this->host)) {
180
-            $authority = '';
181
-            if(!is_null($this->userinfo)) $authority .= $this->userinfo . '@';
182
-            $authority .= $this->host;
183
-            if(!is_null($this->port))     $authority .= ':' . $this->port;
184
-        }
185
-
186
-        // Reconstruct the result
187
-        // One might wonder about parsing quirks from browsers after
188
-        // this reconstruction.  Unfortunately, parsing behavior depends
189
-        // on what *scheme* was employed (file:///foo is handled *very*
190
-        // differently than http:///foo), so unfortunately we have to
191
-        // defer to the schemes to do the right thing.
192
-        $result = '';
193
-        if (!is_null($this->scheme))    $result .= $this->scheme . ':';
194
-        if (!is_null($authority))       $result .=  '//' . $authority;
195
-        $result .= $this->path;
196
-        if (!is_null($this->query))     $result .= '?' . $this->query;
197
-        if (!is_null($this->fragment))  $result .= '#' . $this->fragment;
198
-
199
-        return $result;
200
-    }
201
-
202
-    /**
203
-     * Returns true if this URL might be considered a 'local' URL given
204
-     * the current context.  This is true when the host is null, or
205
-     * when it matches the host supplied to the configuration.
206
-     *
207
-     * Note that this does not do any scheme checking, so it is mostly
208
-     * only appropriate for metadata that doesn't care about protocol
209
-     * security.  isBenign is probably what you actually want.
210
-     */
211
-    public function isLocal($config, $context) {
212
-        if ($this->host === null) return true;
213
-        $uri_def = $config->getDefinition('URI');
214
-        if ($uri_def->host === $this->host) return true;
215
-        return false;
216
-    }
217
-
218
-    /**
219
-     * Returns true if this URL should be considered a 'benign' URL,
220
-     * that is:
221
-     *
222
-     *      - It is a local URL (isLocal), and
223
-     *      - It has a equal or better level of security
224
-     */
225
-    public function isBenign($config, $context) {
226
-        if (!$this->isLocal($config, $context)) return false;
227
-
228
-        $scheme_obj = $this->getSchemeObj($config, $context);
229
-        if (!$scheme_obj) return false; // conservative approach
230
-
231
-        $current_scheme_obj = $config->getDefinition('URI')->getDefaultScheme($config, $context);
232
-        if ($current_scheme_obj->secure) {
233
-            if (!$scheme_obj->secure) {
234
-                return false;
235
-            }
236
-        }
237
-        return true;
238
-    }
14
+	public $scheme, $userinfo, $host, $port, $path, $query, $fragment;
15
+
16
+	/**
17
+	 * @note Automatically normalizes scheme and port
18
+	 */
19
+	public function __construct($scheme, $userinfo, $host, $port, $path, $query, $fragment) {
20
+		$this->scheme = is_null($scheme) || ctype_lower($scheme) ? $scheme : strtolower($scheme);
21
+		$this->userinfo = $userinfo;
22
+		$this->host = $host;
23
+		$this->port = is_null($port) ? $port : (int) $port;
24
+		$this->path = $path;
25
+		$this->query = $query;
26
+		$this->fragment = $fragment;
27
+	}
28
+
29
+	/**
30
+	 * Retrieves a scheme object corresponding to the URI's scheme/default
31
+	 * @param $config Instance of HTMLPurifier_Config
32
+	 * @param $context Instance of HTMLPurifier_Context
33
+	 * @return Scheme object appropriate for validating this URI
34
+	 */
35
+	public function getSchemeObj($config, $context) {
36
+		$registry = HTMLPurifier_URISchemeRegistry::instance();
37
+		if ($this->scheme !== null) {
38
+			$scheme_obj = $registry->getScheme($this->scheme, $config, $context);
39
+			if (!$scheme_obj) return false; // invalid scheme, clean it out
40
+		} else {
41
+			// no scheme: retrieve the default one
42
+			$def = $config->getDefinition('URI');
43
+			$scheme_obj = $def->getDefaultScheme($config, $context);
44
+			if (!$scheme_obj) {
45
+				// something funky happened to the default scheme object
46
+				trigger_error(
47
+					'Default scheme object "' . $def->defaultScheme . '" was not readable',
48
+					E_USER_WARNING
49
+				);
50
+				return false;
51
+			}
52
+		}
53
+		return $scheme_obj;
54
+	}
55
+
56
+	/**
57
+	 * Generic validation method applicable for all schemes. May modify
58
+	 * this URI in order to get it into a compliant form.
59
+	 * @param $config Instance of HTMLPurifier_Config
60
+	 * @param $context Instance of HTMLPurifier_Context
61
+	 * @return True if validation/filtering succeeds, false if failure
62
+	 */
63
+	public function validate($config, $context) {
64
+
65
+		// ABNF definitions from RFC 3986
66
+		$chars_sub_delims = '!$&\'()*+,;=';
67
+		$chars_gen_delims = ':/?#[]@';
68
+		$chars_pchar = $chars_sub_delims . ':@';
69
+
70
+		// validate host
71
+		if (!is_null($this->host)) {
72
+			$host_def = new HTMLPurifier_AttrDef_URI_Host();
73
+			$this->host = $host_def->validate($this->host, $config, $context);
74
+			if ($this->host === false) $this->host = null;
75
+		}
76
+
77
+		// validate scheme
78
+		// NOTE: It's not appropriate to check whether or not this
79
+		// scheme is in our registry, since a URIFilter may convert a
80
+		// URI that we don't allow into one we do.  So instead, we just
81
+		// check if the scheme can be dropped because there is no host
82
+		// and it is our default scheme.
83
+		if (!is_null($this->scheme) && is_null($this->host) || $this->host === '') {
84
+			// support for relative paths is pretty abysmal when the
85
+			// scheme is present, so axe it when possible
86
+			$def = $config->getDefinition('URI');
87
+			if ($def->defaultScheme === $this->scheme) {
88
+				$this->scheme = null;
89
+			}
90
+		}
91
+
92
+		// validate username
93
+		if (!is_null($this->userinfo)) {
94
+			$encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims . ':');
95
+			$this->userinfo = $encoder->encode($this->userinfo);
96
+		}
97
+
98
+		// validate port
99
+		if (!is_null($this->port)) {
100
+			if ($this->port < 1 || $this->port > 65535) $this->port = null;
101
+		}
102
+
103
+		// validate path
104
+		$path_parts = array();
105
+		$segments_encoder = new HTMLPurifier_PercentEncoder($chars_pchar . '/');
106
+		if (!is_null($this->host)) { // this catches $this->host === ''
107
+			// path-abempty (hier and relative)
108
+			// http://www.example.com/my/path
109
+			// //www.example.com/my/path (looks odd, but works, and
110
+			//                            recognized by most browsers)
111
+			// (this set is valid or invalid on a scheme by scheme
112
+			// basis, so we'll deal with it later)
113
+			// file:///my/path
114
+			// ///my/path
115
+			$this->path = $segments_encoder->encode($this->path);
116
+		} elseif ($this->path !== '') {
117
+			if ($this->path[0] === '/') {
118
+				// path-absolute (hier and relative)
119
+				// http:/my/path
120
+				// /my/path
121
+				if (strlen($this->path) >= 2 && $this->path[1] === '/') {
122
+					// This could happen if both the host gets stripped
123
+					// out
124
+					// http://my/path
125
+					// //my/path
126
+					$this->path = '';
127
+				} else {
128
+					$this->path = $segments_encoder->encode($this->path);
129
+				}
130
+			} elseif (!is_null($this->scheme)) {
131
+				// path-rootless (hier)
132
+				// http:my/path
133
+				// Short circuit evaluation means we don't need to check nz
134
+				$this->path = $segments_encoder->encode($this->path);
135
+			} else {
136
+				// path-noscheme (relative)
137
+				// my/path
138
+				// (once again, not checking nz)
139
+				$segment_nc_encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims . '@');
140
+				$c = strpos($this->path, '/');
141
+				if ($c !== false) {
142
+					$this->path =
143
+						$segment_nc_encoder->encode(substr($this->path, 0, $c)) .
144
+						$segments_encoder->encode(substr($this->path, $c));
145
+				} else {
146
+					$this->path = $segment_nc_encoder->encode($this->path);
147
+				}
148
+			}
149
+		} else {
150
+			// path-empty (hier and relative)
151
+			$this->path = ''; // just to be safe
152
+		}
153
+
154
+		// qf = query and fragment
155
+		$qf_encoder = new HTMLPurifier_PercentEncoder($chars_pchar . '/?');
156
+
157
+		if (!is_null($this->query)) {
158
+			$this->query = $qf_encoder->encode($this->query);
159
+		}
160
+
161
+		if (!is_null($this->fragment)) {
162
+			$this->fragment = $qf_encoder->encode($this->fragment);
163
+		}
164
+
165
+		return true;
166
+
167
+	}
168
+
169
+	/**
170
+	 * Convert URI back to string
171
+	 * @return String URI appropriate for output
172
+	 */
173
+	public function toString() {
174
+		// reconstruct authority
175
+		$authority = null;
176
+		// there is a rendering difference between a null authority
177
+		// (http:foo-bar) and an empty string authority
178
+		// (http:///foo-bar).
179
+		if (!is_null($this->host)) {
180
+			$authority = '';
181
+			if(!is_null($this->userinfo)) $authority .= $this->userinfo . '@';
182
+			$authority .= $this->host;
183
+			if(!is_null($this->port))     $authority .= ':' . $this->port;
184
+		}
185
+
186
+		// Reconstruct the result
187
+		// One might wonder about parsing quirks from browsers after
188
+		// this reconstruction.  Unfortunately, parsing behavior depends
189
+		// on what *scheme* was employed (file:///foo is handled *very*
190
+		// differently than http:///foo), so unfortunately we have to
191
+		// defer to the schemes to do the right thing.
192
+		$result = '';
193
+		if (!is_null($this->scheme))    $result .= $this->scheme . ':';
194
+		if (!is_null($authority))       $result .=  '//' . $authority;
195
+		$result .= $this->path;
196
+		if (!is_null($this->query))     $result .= '?' . $this->query;
197
+		if (!is_null($this->fragment))  $result .= '#' . $this->fragment;
198
+
199
+		return $result;
200
+	}
201
+
202
+	/**
203
+	 * Returns true if this URL might be considered a 'local' URL given
204
+	 * the current context.  This is true when the host is null, or
205
+	 * when it matches the host supplied to the configuration.
206
+	 *
207
+	 * Note that this does not do any scheme checking, so it is mostly
208
+	 * only appropriate for metadata that doesn't care about protocol
209
+	 * security.  isBenign is probably what you actually want.
210
+	 */
211
+	public function isLocal($config, $context) {
212
+		if ($this->host === null) return true;
213
+		$uri_def = $config->getDefinition('URI');
214
+		if ($uri_def->host === $this->host) return true;
215
+		return false;
216
+	}
217
+
218
+	/**
219
+	 * Returns true if this URL should be considered a 'benign' URL,
220
+	 * that is:
221
+	 *
222
+	 *      - It is a local URL (isLocal), and
223
+	 *      - It has a equal or better level of security
224
+	 */
225
+	public function isBenign($config, $context) {
226
+		if (!$this->isLocal($config, $context)) return false;
227
+
228
+		$scheme_obj = $this->getSchemeObj($config, $context);
229
+		if (!$scheme_obj) return false; // conservative approach
230
+
231
+		$current_scheme_obj = $config->getDefinition('URI')->getDefaultScheme($config, $context);
232
+		if ($current_scheme_obj->secure) {
233
+			if (!$scheme_obj->secure) {
234
+				return false;
235
+			}
236
+		}
237
+		return true;
238
+	}
239 239
 
240 240
 }
241 241
 
Please login to merge, or discard this patch.
Braces   +41 added lines, -13 removed lines patch added patch discarded remove patch
@@ -36,7 +36,10 @@  discard block
 block discarded – undo
36 36
         $registry = HTMLPurifier_URISchemeRegistry::instance();
37 37
         if ($this->scheme !== null) {
38 38
             $scheme_obj = $registry->getScheme($this->scheme, $config, $context);
39
-            if (!$scheme_obj) return false; // invalid scheme, clean it out
39
+            if (!$scheme_obj) {
40
+            	return false;
41
+            }
42
+            // invalid scheme, clean it out
40 43
         } else {
41 44
             // no scheme: retrieve the default one
42 45
             $def = $config->getDefinition('URI');
@@ -71,7 +74,9 @@  discard block
 block discarded – undo
71 74
         if (!is_null($this->host)) {
72 75
             $host_def = new HTMLPurifier_AttrDef_URI_Host();
73 76
             $this->host = $host_def->validate($this->host, $config, $context);
74
-            if ($this->host === false) $this->host = null;
77
+            if ($this->host === false) {
78
+            	$this->host = null;
79
+            }
75 80
         }
76 81
 
77 82
         // validate scheme
@@ -97,7 +102,9 @@  discard block
 block discarded – undo
97 102
 
98 103
         // validate port
99 104
         if (!is_null($this->port)) {
100
-            if ($this->port < 1 || $this->port > 65535) $this->port = null;
105
+            if ($this->port < 1 || $this->port > 65535) {
106
+            	$this->port = null;
107
+            }
101 108
         }
102 109
 
103 110
         // validate path
@@ -178,9 +185,13 @@  discard block
 block discarded – undo
178 185
         // (http:///foo-bar).
179 186
         if (!is_null($this->host)) {
180 187
             $authority = '';
181
-            if(!is_null($this->userinfo)) $authority .= $this->userinfo . '@';
188
+            if(!is_null($this->userinfo)) {
189
+            	$authority .= $this->userinfo . '@';
190
+            }
182 191
             $authority .= $this->host;
183
-            if(!is_null($this->port))     $authority .= ':' . $this->port;
192
+            if(!is_null($this->port)) {
193
+            	$authority .= ':' . $this->port;
194
+            }
184 195
         }
185 196
 
186 197
         // Reconstruct the result
@@ -190,11 +201,19 @@  discard block
 block discarded – undo
190 201
         // differently than http:///foo), so unfortunately we have to
191 202
         // defer to the schemes to do the right thing.
192 203
         $result = '';
193
-        if (!is_null($this->scheme))    $result .= $this->scheme . ':';
194
-        if (!is_null($authority))       $result .=  '//' . $authority;
204
+        if (!is_null($this->scheme)) {
205
+        	$result .= $this->scheme . ':';
206
+        }
207
+        if (!is_null($authority)) {
208
+        	$result .=  '//' . $authority;
209
+        }
195 210
         $result .= $this->path;
196
-        if (!is_null($this->query))     $result .= '?' . $this->query;
197
-        if (!is_null($this->fragment))  $result .= '#' . $this->fragment;
211
+        if (!is_null($this->query)) {
212
+        	$result .= '?' . $this->query;
213
+        }
214
+        if (!is_null($this->fragment)) {
215
+        	$result .= '#' . $this->fragment;
216
+        }
198 217
 
199 218
         return $result;
200 219
     }
@@ -209,9 +228,13 @@  discard block
 block discarded – undo
209 228
      * security.  isBenign is probably what you actually want.
210 229
      */
211 230
     public function isLocal($config, $context) {
212
-        if ($this->host === null) return true;
231
+        if ($this->host === null) {
232
+        	return true;
233
+        }
213 234
         $uri_def = $config->getDefinition('URI');
214
-        if ($uri_def->host === $this->host) return true;
235
+        if ($uri_def->host === $this->host) {
236
+        	return true;
237
+        }
215 238
         return false;
216 239
     }
217 240
 
@@ -223,10 +246,15 @@  discard block
 block discarded – undo
223 246
      *      - It has a equal or better level of security
224 247
      */
225 248
     public function isBenign($config, $context) {
226
-        if (!$this->isLocal($config, $context)) return false;
249
+        if (!$this->isLocal($config, $context)) {
250
+        	return false;
251
+        }
227 252
 
228 253
         $scheme_obj = $this->getSchemeObj($config, $context);
229
-        if (!$scheme_obj) return false; // conservative approach
254
+        if (!$scheme_obj) {
255
+        	return false;
256
+        }
257
+        // conservative approach
230 258
 
231 259
         $current_scheme_obj = $config->getDefinition('URI')->getDefaultScheme($config, $context);
232 260
         if ($current_scheme_obj->secure) {
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
             if (!$scheme_obj) {
45 45
                 // something funky happened to the default scheme object
46 46
                 trigger_error(
47
-                    'Default scheme object "' . $def->defaultScheme . '" was not readable',
47
+                    'Default scheme object "'.$def->defaultScheme.'" was not readable',
48 48
                     E_USER_WARNING
49 49
                 );
50 50
                 return false;
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         // ABNF definitions from RFC 3986
66 66
         $chars_sub_delims = '!$&\'()*+,;=';
67 67
         $chars_gen_delims = ':/?#[]@';
68
-        $chars_pchar = $chars_sub_delims . ':@';
68
+        $chars_pchar = $chars_sub_delims.':@';
69 69
 
70 70
         // validate host
71 71
         if (!is_null($this->host)) {
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 
92 92
         // validate username
93 93
         if (!is_null($this->userinfo)) {
94
-            $encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims . ':');
94
+            $encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims.':');
95 95
             $this->userinfo = $encoder->encode($this->userinfo);
96 96
         }
97 97
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 
103 103
         // validate path
104 104
         $path_parts = array();
105
-        $segments_encoder = new HTMLPurifier_PercentEncoder($chars_pchar . '/');
105
+        $segments_encoder = new HTMLPurifier_PercentEncoder($chars_pchar.'/');
106 106
         if (!is_null($this->host)) { // this catches $this->host === ''
107 107
             // path-abempty (hier and relative)
108 108
             // http://www.example.com/my/path
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
                 // path-noscheme (relative)
137 137
                 // my/path
138 138
                 // (once again, not checking nz)
139
-                $segment_nc_encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims . '@');
139
+                $segment_nc_encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims.'@');
140 140
                 $c = strpos($this->path, '/');
141 141
                 if ($c !== false) {
142 142
                     $this->path =
143
-                        $segment_nc_encoder->encode(substr($this->path, 0, $c)) .
143
+                        $segment_nc_encoder->encode(substr($this->path, 0, $c)).
144 144
                         $segments_encoder->encode(substr($this->path, $c));
145 145
                 } else {
146 146
                     $this->path = $segment_nc_encoder->encode($this->path);
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
         }
153 153
 
154 154
         // qf = query and fragment
155
-        $qf_encoder = new HTMLPurifier_PercentEncoder($chars_pchar . '/?');
155
+        $qf_encoder = new HTMLPurifier_PercentEncoder($chars_pchar.'/?');
156 156
 
157 157
         if (!is_null($this->query)) {
158 158
             $this->query = $qf_encoder->encode($this->query);
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
         // (http:///foo-bar).
179 179
         if (!is_null($this->host)) {
180 180
             $authority = '';
181
-            if(!is_null($this->userinfo)) $authority .= $this->userinfo . '@';
181
+            if (!is_null($this->userinfo)) $authority .= $this->userinfo.'@';
182 182
             $authority .= $this->host;
183
-            if(!is_null($this->port))     $authority .= ':' . $this->port;
183
+            if (!is_null($this->port))     $authority .= ':'.$this->port;
184 184
         }
185 185
 
186 186
         // Reconstruct the result
@@ -190,11 +190,11 @@  discard block
 block discarded – undo
190 190
         // differently than http:///foo), so unfortunately we have to
191 191
         // defer to the schemes to do the right thing.
192 192
         $result = '';
193
-        if (!is_null($this->scheme))    $result .= $this->scheme . ':';
194
-        if (!is_null($authority))       $result .=  '//' . $authority;
193
+        if (!is_null($this->scheme))    $result .= $this->scheme.':';
194
+        if (!is_null($authority))       $result .= '//'.$authority;
195 195
         $result .= $this->path;
196
-        if (!is_null($this->query))     $result .= '?' . $this->query;
197
-        if (!is_null($this->fragment))  $result .= '#' . $this->fragment;
196
+        if (!is_null($this->query))     $result .= '?'.$this->query;
197
+        if (!is_null($this->fragment))  $result .= '#'.$this->fragment;
198 198
 
199 199
         return $result;
200 200
     }
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/VarParser.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -109,6 +109,7 @@  discard block
 block discarded – undo
109 109
     /**
110 110
      * Actually implements the parsing. Base implementation is to not
111 111
      * do anything to $var. Subclasses should overload this!
112
+     * @param boolean $allow_null
112 113
      */
113 114
     protected function parseImplementation($var, $type, $allow_null) {
114 115
         return $var;
@@ -116,6 +117,7 @@  discard block
 block discarded – undo
116 117
 
117 118
     /**
118 119
      * Throws an exception.
120
+     * @param string $msg
119 121
      */
120 122
     protected function error($msg) {
121 123
         throw new HTMLPurifier_VarParserException($msg);
@@ -126,6 +128,7 @@  discard block
 block discarded – undo
126 128
      * @note This should not ever be called. It would be called if we
127 129
      *       extend the allowed values of HTMLPurifier_VarParser without
128 130
      *       updating subclasses.
131
+     * @param string $class
129 132
      */
130 133
     protected function errorInconsistent($class, $type) {
131 134
         throw new HTMLPurifier_Exception("Inconsistency in $class: ".HTMLPurifier_VarParser::getTypeName($type)." not implemented");
Please login to merge, or discard this patch.
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -7,147 +7,147 @@
 block discarded – undo
7 7
 class HTMLPurifier_VarParser
8 8
 {
9 9
 
10
-    const STRING    = 1;
11
-    const ISTRING   = 2;
12
-    const TEXT      = 3;
13
-    const ITEXT     = 4;
14
-    const INT       = 5;
15
-    const FLOAT     = 6;
16
-    const BOOL      = 7;
17
-    const LOOKUP    = 8;
18
-    const ALIST     = 9;
19
-    const HASH      = 10;
20
-    const MIXED     = 11;
10
+	const STRING    = 1;
11
+	const ISTRING   = 2;
12
+	const TEXT      = 3;
13
+	const ITEXT     = 4;
14
+	const INT       = 5;
15
+	const FLOAT     = 6;
16
+	const BOOL      = 7;
17
+	const LOOKUP    = 8;
18
+	const ALIST     = 9;
19
+	const HASH      = 10;
20
+	const MIXED     = 11;
21 21
 
22
-    /**
23
-     * Lookup table of allowed types. Mainly for backwards compatibility, but
24
-     * also convenient for transforming string type names to the integer constants.
25
-     */
26
-    static public $types = array(
27
-        'string'    => self::STRING,
28
-        'istring'   => self::ISTRING,
29
-        'text'      => self::TEXT,
30
-        'itext'     => self::ITEXT,
31
-        'int'       => self::INT,
32
-        'float'     => self::FLOAT,
33
-        'bool'      => self::BOOL,
34
-        'lookup'    => self::LOOKUP,
35
-        'list'      => self::ALIST,
36
-        'hash'      => self::HASH,
37
-        'mixed'     => self::MIXED
38
-    );
22
+	/**
23
+	 * Lookup table of allowed types. Mainly for backwards compatibility, but
24
+	 * also convenient for transforming string type names to the integer constants.
25
+	 */
26
+	static public $types = array(
27
+		'string'    => self::STRING,
28
+		'istring'   => self::ISTRING,
29
+		'text'      => self::TEXT,
30
+		'itext'     => self::ITEXT,
31
+		'int'       => self::INT,
32
+		'float'     => self::FLOAT,
33
+		'bool'      => self::BOOL,
34
+		'lookup'    => self::LOOKUP,
35
+		'list'      => self::ALIST,
36
+		'hash'      => self::HASH,
37
+		'mixed'     => self::MIXED
38
+	);
39 39
 
40
-    /**
41
-     * Lookup table of types that are string, and can have aliases or
42
-     * allowed value lists.
43
-     */
44
-    static public $stringTypes = array(
45
-        self::STRING    => true,
46
-        self::ISTRING   => true,
47
-        self::TEXT      => true,
48
-        self::ITEXT     => true,
49
-    );
40
+	/**
41
+	 * Lookup table of types that are string, and can have aliases or
42
+	 * allowed value lists.
43
+	 */
44
+	static public $stringTypes = array(
45
+		self::STRING    => true,
46
+		self::ISTRING   => true,
47
+		self::TEXT      => true,
48
+		self::ITEXT     => true,
49
+	);
50 50
 
51
-    /**
52
-     * Validate a variable according to type. Throws
53
-     * HTMLPurifier_VarParserException if invalid.
54
-     * It may return NULL as a valid type if $allow_null is true.
55
-     *
56
-     * @param $var Variable to validate
57
-     * @param $type Type of variable, see HTMLPurifier_VarParser->types
58
-     * @param $allow_null Whether or not to permit null as a value
59
-     * @return Validated and type-coerced variable
60
-     */
61
-    final public function parse($var, $type, $allow_null = false) {
62
-        if (is_string($type)) {
63
-            if (!isset(HTMLPurifier_VarParser::$types[$type])) {
64
-                throw new HTMLPurifier_VarParserException("Invalid type '$type'");
65
-            } else {
66
-                $type = HTMLPurifier_VarParser::$types[$type];
67
-            }
68
-        }
69
-        $var = $this->parseImplementation($var, $type, $allow_null);
70
-        if ($allow_null && $var === null) return null;
71
-        // These are basic checks, to make sure nothing horribly wrong
72
-        // happened in our implementations.
73
-        switch ($type) {
74
-            case (self::STRING):
75
-            case (self::ISTRING):
76
-            case (self::TEXT):
77
-            case (self::ITEXT):
78
-                if (!is_string($var)) break;
79
-                if ($type == self::ISTRING || $type == self::ITEXT) $var = strtolower($var);
80
-                return $var;
81
-            case (self::INT):
82
-                if (!is_int($var)) break;
83
-                return $var;
84
-            case (self::FLOAT):
85
-                if (!is_float($var)) break;
86
-                return $var;
87
-            case (self::BOOL):
88
-                if (!is_bool($var)) break;
89
-                return $var;
90
-            case (self::LOOKUP):
91
-            case (self::ALIST):
92
-            case (self::HASH):
93
-                if (!is_array($var)) break;
94
-                if ($type === self::LOOKUP) {
95
-                    foreach ($var as $k) if ($k !== true) $this->error('Lookup table contains value other than true');
96
-                } elseif ($type === self::ALIST) {
97
-                    $keys = array_keys($var);
98
-                    if (array_keys($keys) !== $keys) $this->error('Indices for list are not uniform');
99
-                }
100
-                return $var;
101
-            case (self::MIXED):
102
-                return $var;
103
-            default:
104
-                $this->errorInconsistent(get_class($this), $type);
105
-        }
106
-        $this->errorGeneric($var, $type);
107
-    }
51
+	/**
52
+	 * Validate a variable according to type. Throws
53
+	 * HTMLPurifier_VarParserException if invalid.
54
+	 * It may return NULL as a valid type if $allow_null is true.
55
+	 *
56
+	 * @param $var Variable to validate
57
+	 * @param $type Type of variable, see HTMLPurifier_VarParser->types
58
+	 * @param $allow_null Whether or not to permit null as a value
59
+	 * @return Validated and type-coerced variable
60
+	 */
61
+	final public function parse($var, $type, $allow_null = false) {
62
+		if (is_string($type)) {
63
+			if (!isset(HTMLPurifier_VarParser::$types[$type])) {
64
+				throw new HTMLPurifier_VarParserException("Invalid type '$type'");
65
+			} else {
66
+				$type = HTMLPurifier_VarParser::$types[$type];
67
+			}
68
+		}
69
+		$var = $this->parseImplementation($var, $type, $allow_null);
70
+		if ($allow_null && $var === null) return null;
71
+		// These are basic checks, to make sure nothing horribly wrong
72
+		// happened in our implementations.
73
+		switch ($type) {
74
+			case (self::STRING):
75
+			case (self::ISTRING):
76
+			case (self::TEXT):
77
+			case (self::ITEXT):
78
+				if (!is_string($var)) break;
79
+				if ($type == self::ISTRING || $type == self::ITEXT) $var = strtolower($var);
80
+				return $var;
81
+			case (self::INT):
82
+				if (!is_int($var)) break;
83
+				return $var;
84
+			case (self::FLOAT):
85
+				if (!is_float($var)) break;
86
+				return $var;
87
+			case (self::BOOL):
88
+				if (!is_bool($var)) break;
89
+				return $var;
90
+			case (self::LOOKUP):
91
+			case (self::ALIST):
92
+			case (self::HASH):
93
+				if (!is_array($var)) break;
94
+				if ($type === self::LOOKUP) {
95
+					foreach ($var as $k) if ($k !== true) $this->error('Lookup table contains value other than true');
96
+				} elseif ($type === self::ALIST) {
97
+					$keys = array_keys($var);
98
+					if (array_keys($keys) !== $keys) $this->error('Indices for list are not uniform');
99
+				}
100
+				return $var;
101
+			case (self::MIXED):
102
+				return $var;
103
+			default:
104
+				$this->errorInconsistent(get_class($this), $type);
105
+		}
106
+		$this->errorGeneric($var, $type);
107
+	}
108 108
 
109
-    /**
110
-     * Actually implements the parsing. Base implementation is to not
111
-     * do anything to $var. Subclasses should overload this!
112
-     */
113
-    protected function parseImplementation($var, $type, $allow_null) {
114
-        return $var;
115
-    }
109
+	/**
110
+	 * Actually implements the parsing. Base implementation is to not
111
+	 * do anything to $var. Subclasses should overload this!
112
+	 */
113
+	protected function parseImplementation($var, $type, $allow_null) {
114
+		return $var;
115
+	}
116 116
 
117
-    /**
118
-     * Throws an exception.
119
-     */
120
-    protected function error($msg) {
121
-        throw new HTMLPurifier_VarParserException($msg);
122
-    }
117
+	/**
118
+	 * Throws an exception.
119
+	 */
120
+	protected function error($msg) {
121
+		throw new HTMLPurifier_VarParserException($msg);
122
+	}
123 123
 
124
-    /**
125
-     * Throws an inconsistency exception.
126
-     * @note This should not ever be called. It would be called if we
127
-     *       extend the allowed values of HTMLPurifier_VarParser without
128
-     *       updating subclasses.
129
-     */
130
-    protected function errorInconsistent($class, $type) {
131
-        throw new HTMLPurifier_Exception("Inconsistency in $class: ".HTMLPurifier_VarParser::getTypeName($type)." not implemented");
132
-    }
124
+	/**
125
+	 * Throws an inconsistency exception.
126
+	 * @note This should not ever be called. It would be called if we
127
+	 *       extend the allowed values of HTMLPurifier_VarParser without
128
+	 *       updating subclasses.
129
+	 */
130
+	protected function errorInconsistent($class, $type) {
131
+		throw new HTMLPurifier_Exception("Inconsistency in $class: ".HTMLPurifier_VarParser::getTypeName($type)." not implemented");
132
+	}
133 133
 
134
-    /**
135
-     * Generic error for if a type didn't work.
136
-     */
137
-    protected function errorGeneric($var, $type) {
138
-        $vtype = gettype($var);
139
-        $this->error("Expected type ".HTMLPurifier_VarParser::getTypeName($type).", got $vtype");
140
-    }
134
+	/**
135
+	 * Generic error for if a type didn't work.
136
+	 */
137
+	protected function errorGeneric($var, $type) {
138
+		$vtype = gettype($var);
139
+		$this->error("Expected type ".HTMLPurifier_VarParser::getTypeName($type).", got $vtype");
140
+	}
141 141
 
142
-    static public function getTypeName($type) {
143
-        static $lookup;
144
-        if (!$lookup) {
145
-            // Lazy load the alternative lookup table
146
-            $lookup = array_flip(HTMLPurifier_VarParser::$types);
147
-        }
148
-        if (!isset($lookup[$type])) return 'unknown';
149
-        return $lookup[$type];
150
-    }
142
+	static public function getTypeName($type) {
143
+		static $lookup;
144
+		if (!$lookup) {
145
+			// Lazy load the alternative lookup table
146
+			$lookup = array_flip(HTMLPurifier_VarParser::$types);
147
+		}
148
+		if (!isset($lookup[$type])) return 'unknown';
149
+		return $lookup[$type];
150
+	}
151 151
 
152 152
 }
153 153
 
Please login to merge, or discard this patch.
Braces   +30 added lines, -10 removed lines patch added patch discarded remove patch
@@ -67,7 +67,9 @@  discard block
 block discarded – undo
67 67
             }
68 68
         }
69 69
         $var = $this->parseImplementation($var, $type, $allow_null);
70
-        if ($allow_null && $var === null) return null;
70
+        if ($allow_null && $var === null) {
71
+        	return null;
72
+        }
71 73
         // These are basic checks, to make sure nothing horribly wrong
72 74
         // happened in our implementations.
73 75
         switch ($type) {
@@ -75,27 +77,43 @@  discard block
 block discarded – undo
75 77
             case (self::ISTRING):
76 78
             case (self::TEXT):
77 79
             case (self::ITEXT):
78
-                if (!is_string($var)) break;
79
-                if ($type == self::ISTRING || $type == self::ITEXT) $var = strtolower($var);
80
+                if (!is_string($var)) {
81
+                	break;
82
+                }
83
+                if ($type == self::ISTRING || $type == self::ITEXT) {
84
+                	$var = strtolower($var);
85
+                }
80 86
                 return $var;
81 87
             case (self::INT):
82
-                if (!is_int($var)) break;
88
+                if (!is_int($var)) {
89
+                	break;
90
+                }
83 91
                 return $var;
84 92
             case (self::FLOAT):
85
-                if (!is_float($var)) break;
93
+                if (!is_float($var)) {
94
+                	break;
95
+                }
86 96
                 return $var;
87 97
             case (self::BOOL):
88
-                if (!is_bool($var)) break;
98
+                if (!is_bool($var)) {
99
+                	break;
100
+                }
89 101
                 return $var;
90 102
             case (self::LOOKUP):
91 103
             case (self::ALIST):
92 104
             case (self::HASH):
93
-                if (!is_array($var)) break;
105
+                if (!is_array($var)) {
106
+                	break;
107
+                }
94 108
                 if ($type === self::LOOKUP) {
95
-                    foreach ($var as $k) if ($k !== true) $this->error('Lookup table contains value other than true');
109
+                    foreach ($var as $k) {
110
+                    	if ($k !== true) $this->error('Lookup table contains value other than true');
111
+                    }
96 112
                 } elseif ($type === self::ALIST) {
97 113
                     $keys = array_keys($var);
98
-                    if (array_keys($keys) !== $keys) $this->error('Indices for list are not uniform');
114
+                    if (array_keys($keys) !== $keys) {
115
+                    	$this->error('Indices for list are not uniform');
116
+                    }
99 117
                 }
100 118
                 return $var;
101 119
             case (self::MIXED):
@@ -145,7 +163,9 @@  discard block
 block discarded – undo
145 163
             // Lazy load the alternative lookup table
146 164
             $lookup = array_flip(HTMLPurifier_VarParser::$types);
147 165
         }
148
-        if (!isset($lookup[$type])) return 'unknown';
166
+        if (!isset($lookup[$type])) {
167
+        	return 'unknown';
168
+        }
149 169
         return $lookup[$type];
150 170
     }
151 171
 
Please login to merge, or discard this patch.
classes/security/UploadFileFilter.class.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -5,6 +5,9 @@
 block discarded – undo
5 5
 {
6 6
 	private static $_block_list = array ('exec', 'system', 'passthru', 'show_source', 'phpinfo', 'fopen', 'file_get_contents', 'file_put_contents', 'fwrite', 'proc_open', 'popen');
7 7
 
8
+	/**
9
+	 * @param string $file
10
+	 */
8 11
 	public function check($file)
9 12
 	{
10 13
 		// TODO: 기능개선후 enable
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -3,38 +3,38 @@
 block discarded – undo
3 3
 
4 4
 class UploadFileFilter
5 5
 {
6
-	private static $_block_list = array ('exec', 'system', 'passthru', 'show_source', 'phpinfo', 'fopen', 'file_get_contents', 'file_put_contents', 'fwrite', 'proc_open', 'popen');
6
+	private static $_block_list = array('exec', 'system', 'passthru', 'show_source', 'phpinfo', 'fopen', 'file_get_contents', 'file_put_contents', 'fwrite', 'proc_open', 'popen');
7 7
 
8 8
 	public function check($file)
9 9
 	{
10 10
 		// TODO: 기능개선후 enable
11 11
 
12 12
 		return TRUE; // disable
13
-		if (! $file || ! FileHandler::exists($file)) return TRUE;
14
-		return self::_check ( $file );
13
+		if (!$file || !FileHandler::exists($file)) return TRUE;
14
+		return self::_check($file);
15 15
 	}
16 16
 
17 17
 	private function _check($file)
18 18
 	{
19
-		if (! ($fp = fopen ( $file, 'r' ))) return FALSE;
19
+		if (!($fp = fopen($file, 'r'))) return FALSE;
20 20
 
21 21
 		$has_php_tag = FALSE;
22 22
 
23
-		while ( ! feof ( $fp ) )
23
+		while (!feof($fp))
24 24
 		{
25
-			$content = fread ( $fp, 8192 );
26
-			if (FALSE === $has_php_tag) $has_php_tag = strpos ( $content, '<?' );
27
-			foreach ( self::$_block_list as $v )
25
+			$content = fread($fp, 8192);
26
+			if (FALSE === $has_php_tag) $has_php_tag = strpos($content, '<?');
27
+			foreach (self::$_block_list as $v)
28 28
 			{
29
-				if (FALSE !== $has_php_tag && FALSE !== strpos ( $content, $v ))
29
+				if (FALSE !== $has_php_tag && FALSE !== strpos($content, $v))
30 30
 				{
31
-					fclose ( $fp );
31
+					fclose($fp);
32 32
 					return FALSE;
33 33
 				}
34 34
 			}
35 35
 		}
36 36
 
37
-		fclose ( $fp );
37
+		fclose($fp);
38 38
 
39 39
 		return TRUE;
40 40
 	}
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,20 +10,26 @@
 block discarded – undo
10 10
 		// TODO: 기능개선후 enable
11 11
 
12 12
 		return TRUE; // disable
13
-		if (! $file || ! FileHandler::exists($file)) return TRUE;
13
+		if (! $file || ! FileHandler::exists($file)) {
14
+			return TRUE;
15
+		}
14 16
 		return self::_check ( $file );
15 17
 	}
16 18
 
17 19
 	private function _check($file)
18 20
 	{
19
-		if (! ($fp = fopen ( $file, 'r' ))) return FALSE;
21
+		if (! ($fp = fopen ( $file, 'r' ))) {
22
+			return FALSE;
23
+		}
20 24
 
21 25
 		$has_php_tag = FALSE;
22 26
 
23 27
 		while ( ! feof ( $fp ) )
24 28
 		{
25 29
 			$content = fread ( $fp, 8192 );
26
-			if (FALSE === $has_php_tag) $has_php_tag = strpos ( $content, '<?' );
30
+			if (FALSE === $has_php_tag) {
31
+				$has_php_tag = strpos ( $content, '<?' );
32
+			}
27 33
 			foreach ( self::$_block_list as $v )
28 34
 			{
29 35
 				if (FALSE !== $has_php_tag && FALSE !== strpos ( $content, $v ))
Please login to merge, or discard this patch.
classes/template/TemplateHandler.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 
26 26
 	/**
27 27
 	 * constructor
28
-	 * @return void
28
+	 * @return string
29 29
 	 */
30 30
 	public function __construct()
31 31
 	{
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 				//parse error
377 377
 				if ($error_info['type'] == 4)
378 378
 				{
379
-				    throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}");
379
+					throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}");
380 380
 				}
381 381
 			}
382 382
 			else
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 			//parse error
393 393
 			if ($error_info['type'] == 4)
394 394
 			{
395
-			    throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}");
395
+				throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}");
396 396
 			}
397 397
 		}
398 398
 
Please login to merge, or discard this patch.
Braces   +20 added lines, -36 removed lines patch added patch discarded remove patch
@@ -46,8 +46,7 @@  discard block
 block discarded – undo
46 46
 			if(!isset($GLOBALS['__TemplateHandlerCalled__']))
47 47
 			{
48 48
 				$GLOBALS['__TemplateHandlerCalled__'] = 1;
49
-			}
50
-			else
49
+			} else
51 50
 			{
52 51
 				$GLOBALS['__TemplateHandlerCalled__']++;
53 52
 			}
@@ -150,8 +149,7 @@  discard block
 block discarded – undo
150 149
 		{
151 150
 			$cache_key = 'template:' . $this->file;
152 151
 			$buff = $oCacheHandler->get($cache_key, $latest_mtime);
153
-		}
154
-		else
152
+		} else
155 153
 		{
156 154
 			if(is_readable($this->compiled_file) && filemtime($this->compiled_file) > $latest_mtime && filesize($this->compiled_file))
157 155
 			{
@@ -165,8 +163,7 @@  discard block
 block discarded – undo
165 163
 			if($oCacheHandler->isSupport())
166 164
 			{
167 165
 				$oCacheHandler->put($cache_key, $buff);
168
-			}
169
-			else
166
+			} else
170 167
 			{
171 168
 				FileHandler::writeFile($this->compiled_file, $buff);
172 169
 			}
@@ -286,8 +283,7 @@  discard block
 block discarded – undo
286 283
 				{
287 284
 					$path = str_replace('@', '', $m[1]);
288 285
 					$path = './files/ruleset/' . $path . '.xml';
289
-				}
290
-				else if(strpos($m[1], '#') !== FALSE)
286
+				} else if(strpos($m[1], '#') !== FALSE)
291 287
 				{
292 288
 					$fileName = str_replace('#', '', $m[1]);
293 289
 					$fileName = str_replace('<?php echo ', '', $fileName);
@@ -299,8 +295,7 @@  discard block
 block discarded – undo
299 295
 					list($rulsetFile) = explode('.', $fileName);
300 296
 					$autoPath = $module_path . '/ruleset/' . $rulsetFile . '.xml';
301 297
 					$m[1] = $rulsetFile;
302
-				}
303
-				else if(preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm))
298
+				} else if(preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm))
304 299
 				{
305 300
 					$module_path = $mm[1];
306 301
 					$path = $module_path . '/ruleset/' . $m[1] . '.xml';
@@ -330,10 +325,10 @@  discard block
 block discarded – undo
330 325
 		if(!preg_match('/no-error-return-url="true"/i', $matches[1]))
331 326
 		{
332 327
 			preg_match('/<input[^>]*name="error_return_url"[^>]*>/is', $matches[2], $m3);
333
-			if(!$m3[0])
334
-				$matches[2] = '<input type="hidden" name="error_return_url" value="<?php echo htmlspecialchars(getRequestUriByServerEnviroment(), ENT_COMPAT | ENT_HTML401, \'UTF-8\', false) ?>" />' . $matches[2];
335
-		}
336
-		else
328
+			if(!$m3[0]) {
329
+							$matches[2] = '<input type="hidden" name="error_return_url" value="<?php echo htmlspecialchars(getRequestUriByServerEnviroment(), ENT_COMPAT | ENT_HTML401, \'UTF-8\', false) ?>" />' . $matches[2];
330
+			}
331
+		} else
337 332
 		{
338 333
 			$matches[1] = preg_replace('/no-error-return-url="true"/i', '', $matches[1]);
339 334
 		}
@@ -378,13 +373,11 @@  discard block
 block discarded – undo
378 373
 				{
379 374
 				    throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}");
380 375
 				}
381
-			}
382
-			else
376
+			} else
383 377
 			{
384 378
 				include(substr($buff, 7));
385 379
 			}
386
-		}
387
-		else
380
+		} else
388 381
 		{
389 382
 			$eval_str = "?>" . $buff;
390 383
 			@eval($eval_str);
@@ -510,12 +503,10 @@  discard block
 block discarded – undo
510 503
 									$expr_m[2] .= '=>' . trim($expr_m[3]);
511 504
 								}
512 505
 								$nodes[$idx - 1] .= "<?php if({$expr_m[1]}&&count({$expr_m[1]}))foreach({$expr_m[1]} as {$expr_m[2]}){ ?>";
513
-							}
514
-							elseif($expr_m[4])
506
+							} elseif($expr_m[4])
515 507
 							{
516 508
 								$nodes[$idx - 1] .= "<?php for({$expr_m[4]}){ ?>";
517
-							}
518
-							elseif($expr_m[5])
509
+							} elseif($expr_m[5])
519 510
 							{
520 511
 								$nodes[$idx - 1] .= "<?php while({$expr_m[5]}={$expr_m[6]}){ ?>";
521 512
 							}
@@ -530,8 +521,7 @@  discard block
 block discarded – undo
530 521
 				if($node{1} == '!' || substr($node, -2, 1) == '/' || isset($self_closing[$tag]))
531 522
 				{
532 523
 					$nodes[$idx + 1] = $close_php . $nodes[$idx + 1];
533
-				}
534
-				else
524
+				} else
535 525
 				{
536 526
 					$depth = 1;
537 527
 					for($i = $idx + 2; $i < $node_len; $i+=2)
@@ -540,8 +530,7 @@  discard block
 block discarded – undo
540 530
 						if(strpos($nd, $tag) === 1)
541 531
 						{
542 532
 							$depth++;
543
-						}
544
-						elseif(strpos($nd, '/' . $tag) === 1)
533
+						} elseif(strpos($nd, '/' . $tag) === 1)
545 534
 						{
546 535
 							$depth--;
547 536
 							if(!$depth)
@@ -610,8 +599,7 @@  discard block
 block discarded – undo
610 599
 					}
611 600
 				}
612 601
 				$attr['target'] = $m[5];
613
-			}
614
-			else
602
+			} else
615 603
 			{
616 604
 				if(!preg_match_all('@ (\w+)="([^"]+)"@', $m[6], $mm))
617 605
 				{
@@ -690,8 +678,7 @@  discard block
 block discarded – undo
690 678
 							if($pathinfo['basename'] == 'lang.xml' || substr($pathinfo['dirname'], -5) == '/lang')
691 679
 							{
692 680
 								$result = "Context::loadLang('{$relativeDir}');";
693
-							}
694
-							else
681
+							} else
695 682
 							{
696 683
 								$result = "require_once('./classes/xml/XmlJsFilter.class.php');\$__xmlFilter=new XmlJsFilter('{$relativeDir}','{$pathinfo['basename']}');\$__xmlFilter->compile();";
697 684
 							}
@@ -700,8 +687,7 @@  discard block
 block discarded – undo
700 687
 							if($doUnload)
701 688
 							{
702 689
 								$result = "Context::unloadFile('{$attr['target']}','{$attr['targetie']}');";
703
-							}
704
-							else
690
+							} else
705 691
 							{
706 692
 								$metafile = $attr['target'];
707 693
 								$result = "\$__tmp=array('{$attr['target']}','{$attr['type']}','{$attr['targetie']}','{$attr['index']}');Context::loadFile(\$__tmp);unset(\$__tmp);";
@@ -711,8 +697,7 @@  discard block
 block discarded – undo
711 697
 							if($doUnload)
712 698
 							{
713 699
 								$result = "Context::unloadFile('{$attr['target']}','{$attr['targetie']}','{$attr['media']}');";
714
-							}
715
-							else
700
+							} else
716 701
 							{
717 702
 								$metafile = $attr['target'];
718 703
 								$result = "\$__tmp=array('{$attr['target']}','{$attr['media']}','{$attr['targetie']}','{$attr['index']}');Context::loadFile(\$__tmp);unset(\$__tmp);";
@@ -753,8 +738,7 @@  discard block
 block discarded – undo
753 738
 				if($mm[1] == 'switch')
754 739
 				{
755 740
 					$m[9] = '';
756
-				}
757
-				elseif($mm[1] == 'foreach')
741
+				} elseif($mm[1] == 'foreach')
758 742
 				{
759 743
 					$var = preg_replace('/^\s*\(\s*(.+?) .*$/', '$1', $m[8]);
760 744
 					$precheck = "if({$var}&&count({$var}))";
Please login to merge, or discard this patch.
Spacing   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 	private $path = NULL; ///< target directory
17 17
 	private $filename = NULL; ///< target filename
18 18
 	private $file = NULL; ///< target file (fullpath)
19
-	private $xe_path = NULL;  ///< XpressEngine base path
19
+	private $xe_path = NULL; ///< XpressEngine base path
20 20
 	private $web_path = NULL; ///< tpl file web path
21 21
 	private $compiled_file = NULL; ///< tpl file web path
22 22
 	private $skipTags = NULL;
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	public function __construct()
31 31
 	{
32 32
 		$this->xe_path = rtrim(getScriptPath(), '/');
33
-		$this->compiled_path = _XE_PATH_ . $this->compiled_path;
33
+		$this->compiled_path = _XE_PATH_.$this->compiled_path;
34 34
 	}
35 35
 
36 36
 	/**
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 	{
42 42
 		static $oTemplate = NULL;
43 43
 
44
-		if(__DEBUG__ == 3)
44
+		if (__DEBUG__ == 3)
45 45
 		{
46
-			if(!isset($GLOBALS['__TemplateHandlerCalled__']))
46
+			if (!isset($GLOBALS['__TemplateHandlerCalled__']))
47 47
 			{
48 48
 				$GLOBALS['__TemplateHandlerCalled__'] = 1;
49 49
 			}
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 			}
54 54
 		}
55 55
 
56
-		if(!$oTemplate)
56
+		if (!$oTemplate)
57 57
 		{
58 58
 			$oTemplate = new TemplateHandler();
59 59
 		}
@@ -71,23 +71,23 @@  discard block
 block discarded – undo
71 71
 	protected function init($tpl_path, $tpl_filename, $tpl_file = '')
72 72
 	{
73 73
 		// verify arguments
74
-		if(substr($tpl_path, -1) != '/')
74
+		if (substr($tpl_path, -1) != '/')
75 75
 		{
76 76
 			$tpl_path .= '/';
77 77
 		}
78
-		if(!is_dir($tpl_path))
78
+		if (!is_dir($tpl_path))
79 79
 		{
80 80
 			return;
81 81
 		}
82
-		if(!file_exists($tpl_path . $tpl_filename) && file_exists($tpl_path . $tpl_filename . '.html'))
82
+		if (!file_exists($tpl_path.$tpl_filename) && file_exists($tpl_path.$tpl_filename.'.html'))
83 83
 		{
84 84
 			$tpl_filename .= '.html';
85 85
 		}
86 86
 
87 87
 		// create tpl_file variable
88
-		if(!$tpl_file)
88
+		if (!$tpl_file)
89 89
 		{
90
-			$tpl_file = $tpl_path . $tpl_filename;
90
+			$tpl_file = $tpl_path.$tpl_filename;
91 91
 		}
92 92
 
93 93
 		// set template file infos.
@@ -95,10 +95,10 @@  discard block
 block discarded – undo
95 95
 		$this->filename = $tpl_filename;
96 96
 		$this->file = $tpl_file;
97 97
 
98
-		$this->web_path = $this->xe_path . '/' . ltrim(preg_replace('@^' . preg_quote(_XE_PATH_, '@') . '|\./@', '', $this->path), '/');
98
+		$this->web_path = $this->xe_path.'/'.ltrim(preg_replace('@^'.preg_quote(_XE_PATH_, '@').'|\./@', '', $this->path), '/');
99 99
 
100 100
 		// get compiled file name
101
-		$hash = md5($this->file . __XE_VERSION__);
101
+		$hash = md5($this->file.__XE_VERSION__);
102 102
 		$this->compiled_file = "{$this->compiled_path}{$hash}.compiled.php";
103 103
 
104 104
 		// compare various file's modified time for check changed
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 		$buff = false;
120 120
 
121 121
 		// store the starting time for debug information
122
-		if(__DEBUG__ == 3)
122
+		if (__DEBUG__ == 3)
123 123
 		{
124 124
 			$start = getMicroTime();
125 125
 		}
@@ -128,13 +128,13 @@  discard block
 block discarded – undo
128 128
 		$this->init($tpl_path, $tpl_filename, $tpl_file);
129 129
 
130 130
 		// if target file does not exist exit
131
-		if(!$this->file || !file_exists($this->file))
131
+		if (!$this->file || !file_exists($this->file))
132 132
 		{
133 133
 			return "Err : '{$this->file}' template file does not exists.";
134 134
 		}
135 135
 
136 136
 		// for backward compatibility
137
-		if(is_null(self::$rootTpl))
137
+		if (is_null(self::$rootTpl))
138 138
 		{
139 139
 			self::$rootTpl = $this->file;
140 140
 		}
@@ -146,23 +146,23 @@  discard block
 block discarded – undo
146 146
 		$oCacheHandler = CacheHandler::getInstance('template');
147 147
 
148 148
 		// get cached buff
149
-		if($oCacheHandler->isSupport())
149
+		if ($oCacheHandler->isSupport())
150 150
 		{
151
-			$cache_key = 'template:' . $this->file;
151
+			$cache_key = 'template:'.$this->file;
152 152
 			$buff = $oCacheHandler->get($cache_key, $latest_mtime);
153 153
 		}
154 154
 		else
155 155
 		{
156
-			if(is_readable($this->compiled_file) && filemtime($this->compiled_file) > $latest_mtime && filesize($this->compiled_file))
156
+			if (is_readable($this->compiled_file) && filemtime($this->compiled_file) > $latest_mtime && filesize($this->compiled_file))
157 157
 			{
158
-				$buff = 'file://' . $this->compiled_file;
158
+				$buff = 'file://'.$this->compiled_file;
159 159
 			}
160 160
 		}
161 161
 
162
-		if($buff === FALSE)
162
+		if ($buff === FALSE)
163 163
 		{
164 164
 			$buff = $this->parse();
165
-			if($oCacheHandler->isSupport())
165
+			if ($oCacheHandler->isSupport())
166 166
 			{
167 167
 				$oCacheHandler->put($cache_key, $buff);
168 168
 			}
@@ -174,13 +174,13 @@  discard block
 block discarded – undo
174 174
 
175 175
 		$output = $this->_fetch($buff);
176 176
 
177
-		if($__templatehandler_root_tpl == $this->file)
177
+		if ($__templatehandler_root_tpl == $this->file)
178 178
 		{
179 179
 			$__templatehandler_root_tpl = null;
180 180
 		}
181 181
 
182 182
 		// store the ending time for debug information
183
-		if(__DEBUG__ == 3)
183
+		if (__DEBUG__ == 3)
184 184
 		{
185 185
 			$GLOBALS['__template_elapsed__'] += getMicroTime() - $start;
186 186
 		}
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 		$this->init($tpl_path, $tpl_filename, null);
200 200
 
201 201
 		// if target file does not exist exit
202
-		if(!$this->file || !file_exists($this->file))
202
+		if (!$this->file || !file_exists($this->file))
203 203
 		{
204 204
 			Context::close();
205 205
 			exit("Cannot find the template file: '{$this->file}'");
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
 	 */
216 216
 	protected function parse($buff = null)
217 217
 	{
218
-		if(is_null($buff))
218
+		if (is_null($buff))
219 219
 		{
220
-			if(!is_readable($this->file))
220
+			if (!is_readable($this->file))
221 221
 			{
222 222
 				return;
223 223
 			}
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 		}
228 228
 
229 229
 		// HTML tags to skip
230
-		if(is_null($this->skipTags))
230
+		if (is_null($this->skipTags))
231 231
 		{
232 232
 			$this->skipTags = array('marquee');
233 233
 		}
@@ -249,13 +249,13 @@  discard block
 block discarded – undo
249 249
 
250 250
 		// form auto generation
251 251
 		$temp = preg_replace_callback('/(<form(?:<\?php.+?\?>|[^<>]+)*?>)(.*?)(<\/form>)/is', array($this, '_compileFormAuthGeneration'), $buff);
252
-		if($temp)
252
+		if ($temp)
253 253
 		{
254 254
 			$buff = $temp;
255 255
 		}
256 256
 
257 257
 		// prevent from calling directly before writing into file
258
-		$buff = '<?php if(!defined("__XE__"))exit;?>' . $buff;
258
+		$buff = '<?php if(!defined("__XE__"))exit;?>'.$buff;
259 259
 
260 260
 		// remove php script reopening
261 261
 		$buff = preg_replace(array('/(\n|\r\n)+/', '/(;)?( )*\?\>\<\?php([\n\t ]+)?/'), array("\n", ";\n"), $buff);
@@ -275,40 +275,40 @@  discard block
 block discarded – undo
275 275
 	private function _compileFormAuthGeneration($matches)
276 276
 	{
277 277
 		// form ruleset attribute move to hidden tag
278
-		if($matches[1])
278
+		if ($matches[1])
279 279
 		{
280 280
 			preg_match('/ruleset="([^"]*?)"/is', $matches[1], $m);
281
-			if($m[0])
281
+			if ($m[0])
282 282
 			{
283
-				$matches[1] = preg_replace('/' . addcslashes($m[0], '?$') . '/i', '', $matches[1]);
283
+				$matches[1] = preg_replace('/'.addcslashes($m[0], '?$').'/i', '', $matches[1]);
284 284
 
285
-				if(strpos($m[1], '@') !== FALSE)
285
+				if (strpos($m[1], '@') !== FALSE)
286 286
 				{
287 287
 					$path = str_replace('@', '', $m[1]);
288
-					$path = './files/ruleset/' . $path . '.xml';
288
+					$path = './files/ruleset/'.$path.'.xml';
289 289
 				}
290
-				else if(strpos($m[1], '#') !== FALSE)
290
+				else if (strpos($m[1], '#') !== FALSE)
291 291
 				{
292 292
 					$fileName = str_replace('#', '', $m[1]);
293 293
 					$fileName = str_replace('<?php echo ', '', $fileName);
294 294
 					$fileName = str_replace(' ?>', '', $fileName);
295
-					$path = '#./files/ruleset/' . $fileName . '.xml';
295
+					$path = '#./files/ruleset/'.$fileName.'.xml';
296 296
 
297 297
 					preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm);
298 298
 					$module_path = $mm[1];
299 299
 					list($rulsetFile) = explode('.', $fileName);
300
-					$autoPath = $module_path . '/ruleset/' . $rulsetFile . '.xml';
300
+					$autoPath = $module_path.'/ruleset/'.$rulsetFile.'.xml';
301 301
 					$m[1] = $rulsetFile;
302 302
 				}
303
-				else if(preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm))
303
+				else if (preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm))
304 304
 				{
305 305
 					$module_path = $mm[1];
306
-					$path = $module_path . '/ruleset/' . $m[1] . '.xml';
306
+					$path = $module_path.'/ruleset/'.$m[1].'.xml';
307 307
 				}
308 308
 
309
-				$matches[2] = '<input type="hidden" name="ruleset" value="' . $m[1] . '" />' . $matches[2];
309
+				$matches[2] = '<input type="hidden" name="ruleset" value="'.$m[1].'" />'.$matches[2];
310 310
 				//assign to addJsFile method for js dynamic recache
311
-				$matches[1] = '<?php Context::addJsFile("' . $path . '", FALSE, "", 0, "body", TRUE, "' . $autoPath . '") ?' . '>' . $matches[1];
311
+				$matches[1] = '<?php Context::addJsFile("'.$path.'", FALSE, "", 0, "body", TRUE, "'.$autoPath.'") ?'.'>'.$matches[1];
312 312
 			}
313 313
 		}
314 314
 
@@ -316,22 +316,22 @@  discard block
 block discarded – undo
316 316
 		preg_match_all('/<input[^>]* name="(act|mid|vid)"/is', $matches[2], $m2);
317 317
 		$checkVar = array('act', 'mid', 'vid');
318 318
 		$resultArray = array_diff($checkVar, $m2[1]);
319
-		if(is_array($resultArray))
319
+		if (is_array($resultArray))
320 320
 		{
321 321
 			$generatedHidden = '';
322
-			foreach($resultArray AS $key => $value)
322
+			foreach ($resultArray AS $key => $value)
323 323
 			{
324
-				$generatedHidden .= '<input type="hidden" name="' . $value . '" value="<?php echo $__Context->' . $value . ' ?>" />';
324
+				$generatedHidden .= '<input type="hidden" name="'.$value.'" value="<?php echo $__Context->'.$value.' ?>" />';
325 325
 			}
326
-			$matches[2] = $generatedHidden . $matches[2];
326
+			$matches[2] = $generatedHidden.$matches[2];
327 327
 		}
328 328
 
329 329
 		// return url generate
330
-		if(!preg_match('/no-error-return-url="true"/i', $matches[1]))
330
+		if (!preg_match('/no-error-return-url="true"/i', $matches[1]))
331 331
 		{
332 332
 			preg_match('/<input[^>]*name="error_return_url"[^>]*>/is', $matches[2], $m3);
333
-			if(!$m3[0])
334
-				$matches[2] = '<input type="hidden" name="error_return_url" value="<?php echo htmlspecialchars(getRequestUriByServerEnviroment(), ENT_COMPAT | ENT_HTML401, \'UTF-8\', false) ?>" />' . $matches[2];
333
+			if (!$m3[0])
334
+				$matches[2] = '<input type="hidden" name="error_return_url" value="<?php echo htmlspecialchars(getRequestUriByServerEnviroment(), ENT_COMPAT | ENT_HTML401, \'UTF-8\', false) ?>" />'.$matches[2];
335 335
 		}
336 336
 		else
337 337
 		{
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 	 */
350 350
 	private function _fetch($buff)
351 351
 	{
352
-		if(!$buff)
352
+		if (!$buff)
353 353
 		{
354 354
 			return;
355 355
 		}
@@ -357,20 +357,20 @@  discard block
 block discarded – undo
357 357
 		$__Context = &$GLOBALS['__Context__'];
358 358
 		$__Context->tpl_path = $this->path;
359 359
 
360
-		if($_SESSION['is_logged'])
360
+		if ($_SESSION['is_logged'])
361 361
 		{
362 362
 			$__Context->logged_info = Context::get('logged_info');
363 363
 		}
364 364
 
365 365
 		$level = ob_get_level();
366 366
 		ob_start();
367
-		if(substr($buff, 0, 7) == 'file://')
367
+		if (substr($buff, 0, 7) == 'file://')
368 368
 		{
369
-			if(__DEBUG__)
369
+			if (__DEBUG__)
370 370
 			{
371 371
 				//load cache file from disk
372 372
 				$eval_str = FileHandler::readFile(substr($buff, 7));
373
-				$eval_str_buffed = "?>" . $eval_str;
373
+				$eval_str_buffed = "?>".$eval_str;
374 374
 				@eval($eval_str_buffed);
375 375
 				$error_info = error_get_last();
376 376
 				//parse error
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 		}
387 387
 		else
388 388
 		{
389
-			$eval_str = "?>" . $buff;
389
+			$eval_str = "?>".$buff;
390 390
 			@eval($eval_str);
391 391
 			$error_info = error_get_last();
392 392
 			//parse error
@@ -415,31 +415,31 @@  discard block
 block discarded – undo
415 415
 	private function _replacePath($match)
416 416
 	{
417 417
 		//return origin conde when src value started '${'.
418
-		if(preg_match('@^\${@', $match[1]))
418
+		if (preg_match('@^\${@', $match[1]))
419 419
 		{
420 420
 			return $match[0];
421 421
 		}
422 422
 
423 423
 		//return origin code when src value include variable.
424
-		if(preg_match('@^[\'|"]\s*\.\s*\$@', $match[1]))
424
+		if (preg_match('@^[\'|"]\s*\.\s*\$@', $match[1]))
425 425
 		{
426 426
 			return $match[0];
427 427
 		}
428 428
 
429 429
 		$src = preg_replace('@^(\./)+@', '', trim($match[1]));
430 430
 
431
-		$src = $this->web_path . $src;
431
+		$src = $this->web_path.$src;
432 432
 		$src = str_replace('/./', '/', $src);
433 433
 
434 434
 		// for backward compatibility
435 435
 		$src = preg_replace('@/((?:[\w-]+/)+)\1@', '/\1', $src);
436 436
 
437
-		while(($tmp = preg_replace('@[^/]+/\.\./@', '', $src, 1)) !== $src)
437
+		while (($tmp = preg_replace('@[^/]+/\.\./@', '', $src, 1)) !== $src)
438 438
 		{
439 439
 			$src = $tmp;
440 440
 		}
441 441
 
442
-		return substr($match[0], 0, -strlen($match[1]) - 6) . "src=\"{$src}\"";
442
+		return substr($match[0], 0, -strlen($match[1]) - 6)."src=\"{$src}\"";
443 443
 	}
444 444
 
445 445
 	/**
@@ -449,19 +449,19 @@  discard block
 block discarded – undo
449 449
 	 */
450 450
 	private function _parseInline($buff)
451 451
 	{
452
-		if(preg_match_all('/<([a-zA-Z]+\d?)(?>(?!<[a-z]+\d?[\s>]).)*?(?:[ \|]cond| loop)="/s', $buff, $match) === false)
452
+		if (preg_match_all('/<([a-zA-Z]+\d?)(?>(?!<[a-z]+\d?[\s>]).)*?(?:[ \|]cond| loop)="/s', $buff, $match) === false)
453 453
 		{
454 454
 			return $buff;
455 455
 		}
456 456
 
457 457
 		$tags = array_diff(array_unique($match[1]), $this->skipTags);
458 458
 
459
-		if(!count($tags))
459
+		if (!count($tags))
460 460
 		{
461 461
 			return $buff;
462 462
 		}
463 463
 
464
-		$tags = '(?:' . implode('|', $tags) . ')';
464
+		$tags = '(?:'.implode('|', $tags).')';
465 465
 		$split_regex = "@(<(?>/?{$tags})(?>[^<>\{\}\"']+|<!--.*?-->|{[^}]+}|\".*?\"|'.*?'|.)*?>)@s";
466 466
 
467 467
 		$nodes = preg_split($split_regex, $buff, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -469,14 +469,14 @@  discard block
 block discarded – undo
469 469
 		// list of self closing tags
470 470
 		$self_closing = array('area' => 1, 'base' => 1, 'basefont' => 1, 'br' => 1, 'hr' => 1, 'input' => 1, 'img' => 1, 'link' => 1, 'meta' => 1, 'param' => 1, 'frame' => 1, 'col' => 1);
471 471
 
472
-		for($idx = 1, $node_len = count($nodes); $idx < $node_len; $idx+=2)
472
+		for ($idx = 1, $node_len = count($nodes); $idx < $node_len; $idx += 2)
473 473
 		{
474
-			if(!($node = $nodes[$idx]))
474
+			if (!($node = $nodes[$idx]))
475 475
 			{
476 476
 				continue;
477 477
 			}
478 478
 
479
-			if(preg_match_all('@\s(loop|cond)="([^"]+)"@', $node, $matches))
479
+			if (preg_match_all('@\s(loop|cond)="([^"]+)"@', $node, $matches))
480 480
 			{
481 481
 				// this tag
482 482
 				$tag = substr($node, 1, strpos($node, ' ') - 1);
@@ -485,37 +485,37 @@  discard block
 block discarded – undo
485 485
 				$closing = 0;
486 486
 
487 487
 				// process opening tag
488
-				foreach($matches[1] as $n => $stmt)
488
+				foreach ($matches[1] as $n => $stmt)
489 489
 				{
490 490
 					$expr = $matches[2][$n];
491 491
 					$expr = $this->_replaceVar($expr);
492 492
 					$closing++;
493 493
 
494
-					switch($stmt)
494
+					switch ($stmt)
495 495
 					{
496 496
 						case 'cond':
497 497
 							$nodes[$idx - 1] .= "<?php if({$expr}){ ?>";
498 498
 							break;
499 499
 						case 'loop':
500
-							if(!preg_match('@^(?:(.+?)=>(.+?)(?:,(.+?))?|(.*?;.*?;.*?)|(.+?)\s*=\s*(.+?))$@', $expr, $expr_m))
500
+							if (!preg_match('@^(?:(.+?)=>(.+?)(?:,(.+?))?|(.*?;.*?;.*?)|(.+?)\s*=\s*(.+?))$@', $expr, $expr_m))
501 501
 							{
502 502
 								break;
503 503
 							}
504
-							if($expr_m[1])
504
+							if ($expr_m[1])
505 505
 							{
506 506
 								$expr_m[1] = trim($expr_m[1]);
507 507
 								$expr_m[2] = trim($expr_m[2]);
508
-								if($expr_m[3])
508
+								if ($expr_m[3])
509 509
 								{
510
-									$expr_m[2] .= '=>' . trim($expr_m[3]);
510
+									$expr_m[2] .= '=>'.trim($expr_m[3]);
511 511
 								}
512 512
 								$nodes[$idx - 1] .= "<?php if({$expr_m[1]}&&count({$expr_m[1]}))foreach({$expr_m[1]} as {$expr_m[2]}){ ?>";
513 513
 							}
514
-							elseif($expr_m[4])
514
+							elseif ($expr_m[4])
515 515
 							{
516 516
 								$nodes[$idx - 1] .= "<?php for({$expr_m[4]}){ ?>";
517 517
 							}
518
-							elseif($expr_m[5])
518
+							elseif ($expr_m[5])
519 519
 							{
520 520
 								$nodes[$idx - 1] .= "<?php while({$expr_m[5]}={$expr_m[6]}){ ?>";
521 521
 							}
@@ -525,28 +525,28 @@  discard block
 block discarded – undo
525 525
 				$node = preg_replace('@\s(loop|cond)="([^"]+)"@', '', $node);
526 526
 
527 527
 				// find closing tag
528
-				$close_php = '<?php ' . str_repeat('}', $closing) . ' ?>';
528
+				$close_php = '<?php '.str_repeat('}', $closing).' ?>';
529 529
 				//  self closing tag
530
-				if($node{1} == '!' || substr($node, -2, 1) == '/' || isset($self_closing[$tag]))
530
+				if ($node{1} == '!' || substr($node, -2, 1) == '/' || isset($self_closing[$tag]))
531 531
 				{
532
-					$nodes[$idx + 1] = $close_php . $nodes[$idx + 1];
532
+					$nodes[$idx + 1] = $close_php.$nodes[$idx + 1];
533 533
 				}
534 534
 				else
535 535
 				{
536 536
 					$depth = 1;
537
-					for($i = $idx + 2; $i < $node_len; $i+=2)
537
+					for ($i = $idx + 2; $i < $node_len; $i += 2)
538 538
 					{
539 539
 						$nd = $nodes[$i];
540
-						if(strpos($nd, $tag) === 1)
540
+						if (strpos($nd, $tag) === 1)
541 541
 						{
542 542
 							$depth++;
543 543
 						}
544
-						elseif(strpos($nd, '/' . $tag) === 1)
544
+						elseif (strpos($nd, '/'.$tag) === 1)
545 545
 						{
546 546
 							$depth--;
547
-							if(!$depth)
547
+							if (!$depth)
548 548
 							{
549
-								$nodes[$i - 1] .= $nodes[$i] . $close_php;
549
+								$nodes[$i - 1] .= $nodes[$i].$close_php;
550 550
 								$nodes[$i] = '';
551 551
 								break;
552 552
 							}
@@ -555,13 +555,13 @@  discard block
 block discarded – undo
555 555
 				}
556 556
 			}
557 557
 
558
-			if(strpos($node, '|cond="') !== false)
558
+			if (strpos($node, '|cond="') !== false)
559 559
 			{
560 560
 				$node = preg_replace('@(\s[-\w:]+(?:="[^"]+?")?)\|cond="(.+?)"@s', '<?php if($2){ ?>$1<?php } ?>', $node);
561 561
 				$node = $this->_replaceVar($node);
562 562
 			}
563 563
 
564
-			if($nodes[$idx] != $node)
564
+			if ($nodes[$idx] != $node)
565 565
 			{
566 566
 				$nodes[$idx] = $node;
567 567
 			}
@@ -581,30 +581,30 @@  discard block
 block discarded – undo
581 581
 	private function _parseResource($m)
582 582
 	{
583 583
 		// {@ ... } or {$var} or {func(...)}
584
-		if($m[1])
584
+		if ($m[1])
585 585
 		{
586
-			if(preg_match('@^(\w+)\(@', $m[1], $mm) && !function_exists($mm[1]))
586
+			if (preg_match('@^(\w+)\(@', $m[1], $mm) && !function_exists($mm[1]))
587 587
 			{
588 588
 				return $m[0];
589 589
 			}
590 590
 
591 591
 			$echo = 'echo ';
592
-			if($m[1]{0} == '@')
592
+			if ($m[1]{0} == '@')
593 593
 			{
594 594
 				$echo = '';
595 595
 				$m[1] = substr($m[1], 1);
596 596
 			}
597
-			return '<?php ' . $echo . $this->_replaceVar($m[1]) . ' ?>';
597
+			return '<?php '.$echo.$this->_replaceVar($m[1]).' ?>';
598 598
 		}
599 599
 
600
-		if($m[3])
600
+		if ($m[3])
601 601
 		{
602 602
 			$attr = array();
603
-			if($m[5])
603
+			if ($m[5])
604 604
 			{
605
-				if(preg_match_all('@,(\w+)="([^"]+)"@', $m[6], $mm))
605
+				if (preg_match_all('@,(\w+)="([^"]+)"@', $m[6], $mm))
606 606
 				{
607
-					foreach($mm[1] as $idx => $name)
607
+					foreach ($mm[1] as $idx => $name)
608 608
 					{
609 609
 						$attr[$name] = $mm[2][$idx];
610 610
 					}
@@ -613,21 +613,21 @@  discard block
 block discarded – undo
613 613
 			}
614 614
 			else
615 615
 			{
616
-				if(!preg_match_all('@ (\w+)="([^"]+)"@', $m[6], $mm))
616
+				if (!preg_match_all('@ (\w+)="([^"]+)"@', $m[6], $mm))
617 617
 				{
618 618
 					return $m[0];
619 619
 				}
620
-				foreach($mm[1] as $idx => $name)
620
+				foreach ($mm[1] as $idx => $name)
621 621
 				{
622 622
 					$attr[$name] = $mm[2][$idx];
623 623
 				}
624 624
 			}
625 625
 
626
-			switch($m[3])
626
+			switch ($m[3])
627 627
 			{
628 628
 				// <!--#include--> or <include ..>
629 629
 				case 'include':
630
-					if(!$this->file || !$attr['target'])
630
+					if (!$this->file || !$attr['target'])
631 631
 					{
632 632
 						return '';
633 633
 					}
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
 					$pathinfo = pathinfo($attr['target']);
636 636
 					$fileDir = $this->_getRelativeDir($pathinfo['dirname']);
637 637
 
638
-					if(!$fileDir)
638
+					if (!$fileDir)
639 639
 					{
640 640
 						return '';
641 641
 					}
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
 				case 'load_js_plugin':
646 646
 					$plugin = $this->_replaceVar($m[5]);
647 647
 					$s = "<!--#JSPLUGIN:{$plugin}-->";
648
-					if(strpos($plugin, '$__Context') === false)
648
+					if (strpos($plugin, '$__Context') === false)
649 649
 					{
650 650
 						$plugin = "'{$plugin}'";
651 651
 					}
@@ -661,13 +661,13 @@  discard block
 block discarded – undo
661 661
 					$doUnload = ($m[3] === 'unload');
662 662
 					$isRemote = !!preg_match('@^(https?:)?//@i', $attr['target']);
663 663
 
664
-					if(!$isRemote)
664
+					if (!$isRemote)
665 665
 					{
666
-						if(!preg_match('@^\.?/@', $attr['target']))
666
+						if (!preg_match('@^\.?/@', $attr['target']))
667 667
 						{
668
-							$attr['target'] = './' . $attr['target'];
668
+							$attr['target'] = './'.$attr['target'];
669 669
 						}
670
-						if(substr($attr['target'], -5) == '/lang')
670
+						if (substr($attr['target'], -5) == '/lang')
671 671
 						{
672 672
 							$pathinfo['dirname'] .= '/lang';
673 673
 							$pathinfo['basename'] = '';
@@ -676,18 +676,18 @@  discard block
 block discarded – undo
676 676
 
677 677
 						$relativeDir = $this->_getRelativeDir($pathinfo['dirname']);
678 678
 
679
-						$attr['target'] = $relativeDir . '/' . $pathinfo['basename'];
679
+						$attr['target'] = $relativeDir.'/'.$pathinfo['basename'];
680 680
 					}
681 681
 
682
-					switch($pathinfo['extension'])
682
+					switch ($pathinfo['extension'])
683 683
 					{
684 684
 						case 'xml':
685
-							if($isRemote || $doUnload)
685
+							if ($isRemote || $doUnload)
686 686
 							{
687 687
 								return '';
688 688
 							}
689 689
 							// language file?
690
-							if($pathinfo['basename'] == 'lang.xml' || substr($pathinfo['dirname'], -5) == '/lang')
690
+							if ($pathinfo['basename'] == 'lang.xml' || substr($pathinfo['dirname'], -5) == '/lang')
691 691
 							{
692 692
 								$result = "Context::loadLang('{$relativeDir}');";
693 693
 							}
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 							}
698 698
 							break;
699 699
 						case 'js':
700
-							if($doUnload)
700
+							if ($doUnload)
701 701
 							{
702 702
 								$result = "Context::unloadFile('{$attr['target']}','{$attr['targetie']}');";
703 703
 							}
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
 							}
709 709
 							break;
710 710
 						case 'css':
711
-							if($doUnload)
711
+							if ($doUnload)
712 712
 							{
713 713
 								$result = "Context::unloadFile('{$attr['target']}','{$attr['targetie']}','{$attr['media']}');";
714 714
 							}
@@ -721,9 +721,9 @@  discard block
 block discarded – undo
721 721
 					}
722 722
 
723 723
 					$result = "<?php {$result} ?>";
724
-					if($metafile)
724
+					if ($metafile)
725 725
 					{
726
-						$result = "<!--#Meta:{$metafile}-->" . $result;
726
+						$result = "<!--#Meta:{$metafile}-->".$result;
727 727
 					}
728 728
 
729 729
 					return $result;
@@ -731,45 +731,45 @@  discard block
 block discarded – undo
731 731
 		}
732 732
 
733 733
 		// <[email protected]> such as <!--@if($cond)-->, <!--@else-->, <!--@end-->
734
-		if($m[7])
734
+		if ($m[7])
735 735
 		{
736 736
 			$m[7] = substr($m[7], 1);
737
-			if(!$m[7])
737
+			if (!$m[7])
738 738
 			{
739
-				return '<?php ' . $this->_replaceVar($m[8]) . '{ ?>' . $m[9];
739
+				return '<?php '.$this->_replaceVar($m[8]).'{ ?>'.$m[9];
740 740
 			}
741
-			if(!preg_match('/^(?:((?:end)?(?:if|switch|for(?:each)?|while)|end)|(else(?:if)?)|(break@)?(case|default)|(break))$/', $m[7], $mm))
741
+			if (!preg_match('/^(?:((?:end)?(?:if|switch|for(?:each)?|while)|end)|(else(?:if)?)|(break@)?(case|default)|(break))$/', $m[7], $mm))
742 742
 			{
743 743
 				return '';
744 744
 			}
745
-			if($mm[1])
745
+			if ($mm[1])
746 746
 			{
747
-				if($mm[1]{0} == 'e')
747
+				if ($mm[1]{0} == 'e')
748 748
 				{
749
-					return '<?php } ?>' . $m[9];
749
+					return '<?php } ?>'.$m[9];
750 750
 				}
751 751
 
752 752
 				$precheck = '';
753
-				if($mm[1] == 'switch')
753
+				if ($mm[1] == 'switch')
754 754
 				{
755 755
 					$m[9] = '';
756 756
 				}
757
-				elseif($mm[1] == 'foreach')
757
+				elseif ($mm[1] == 'foreach')
758 758
 				{
759 759
 					$var = preg_replace('/^\s*\(\s*(.+?) .*$/', '$1', $m[8]);
760 760
 					$precheck = "if({$var}&&count({$var}))";
761 761
 				}
762
-				return '<?php ' . $this->_replaceVar($precheck . $m[7] . $m[8]) . '{ ?>' . $m[9];
762
+				return '<?php '.$this->_replaceVar($precheck.$m[7].$m[8]).'{ ?>'.$m[9];
763 763
 			}
764
-			if($mm[2])
764
+			if ($mm[2])
765 765
 			{
766
-				return "<?php }{$m[7]}" . $this->_replaceVar($m[8]) . "{ ?>" . $m[9];
766
+				return "<?php }{$m[7]}".$this->_replaceVar($m[8])."{ ?>".$m[9];
767 767
 			}
768
-			if($mm[4])
768
+			if ($mm[4])
769 769
 			{
770
-				return "<?php " . ($mm[3] ? 'break;' : '') . "{$m[7]} " . trim($m[8], '()') . ": ?>" . $m[9];
770
+				return "<?php ".($mm[3] ? 'break;' : '')."{$m[7]} ".trim($m[8], '()').": ?>".$m[9];
771 771
 			}
772
-			if($mm[5])
772
+			if ($mm[5])
773 773
 			{
774 774
 				return "<?php break; ?>";
775 775
 			}
@@ -788,30 +788,30 @@  discard block
 block discarded – undo
788 788
 		$_path = $path;
789 789
 
790 790
 		$fileDir = strtr(realpath($this->path), '\\', '/');
791
-		if($path{0} != '/')
791
+		if ($path{0} != '/')
792 792
 		{
793
-			$path = strtr(realpath($fileDir . '/' . $path), '\\', '/');
793
+			$path = strtr(realpath($fileDir.'/'.$path), '\\', '/');
794 794
 		}
795 795
 
796 796
 		// for backward compatibility
797
-		if(!$path)
797
+		if (!$path)
798 798
 		{
799 799
 			$dirs = explode('/', $fileDir);
800 800
 			$paths = explode('/', $_path);
801 801
 			$idx = array_search($paths[0], $dirs);
802 802
 
803
-			if($idx !== false)
803
+			if ($idx !== false)
804 804
 			{
805
-				while($dirs[$idx] && $dirs[$idx] === $paths[0])
805
+				while ($dirs[$idx] && $dirs[$idx] === $paths[0])
806 806
 				{
807 807
 					array_splice($dirs, $idx, 1);
808 808
 					array_shift($paths);
809 809
 				}
810
-				$path = strtr(realpath($fileDir . '/' . implode('/', $paths)), '\\', '/');
810
+				$path = strtr(realpath($fileDir.'/'.implode('/', $paths)), '\\', '/');
811 811
 			}
812 812
 		}
813 813
 
814
-		$path = preg_replace('/^' . preg_quote(_XE_PATH_, '/') . '/', '', $path);
814
+		$path = preg_replace('/^'.preg_quote(_XE_PATH_, '/').'/', '', $path);
815 815
 
816 816
 		return $path;
817 817
 	}
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
 	 */
824 824
 	function _replaceVar($php)
825 825
 	{
826
-		if(!strlen($php))
826
+		if (!strlen($php))
827 827
 		{
828 828
 			return '';
829 829
 		}
Please login to merge, or discard this patch.
classes/validator/Validator.class.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 
240 240
 	/**
241 241
 	 * Validate the fields. If the fields aren't passed, validation will be execute on the Context variables.
242
-	 * @param array $fields Target fields. The keys of the array represents field's name, its values represents field's value.
242
+	 * @param array $fields_ Target fields. The keys of the array represents field's name, its values represents field's value.
243 243
 	 * @return boolean TRUE if it is valid, FALSE otherwise.
244 244
 	 */
245 245
 	function validate($fields_ = null)
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 
457 457
 	/**
458 458
 	 * Log an error
459
-	 * @param $msg error message
459
+	 * @param string $msg error message
460 460
 	 * @return boolean always false
461 461
 	 */
462 462
 	function error($field, $msg)
Please login to merge, or discard this patch.
Braces   +15 added lines, -26 removed lines patch added patch discarded remove patch
@@ -81,8 +81,9 @@  discard block
 block discarded – undo
81 81
 		$this->_filters = array();
82 82
 		$this->_xml_ruleset = NULL;
83 83
 
84
-		if($xml_path)
85
-			$this->load($xml_path);
84
+		if($xml_path) {
85
+					$this->load($xml_path);
86
+		}
86 87
 
87 88
 		// predefined rules
88 89
 		$this->addRule(array(
@@ -247,8 +248,7 @@  discard block
 block discarded – undo
247 248
 		if(is_array($fields_))
248 249
 		{
249 250
 			$fields = $fields_;
250
-		}
251
-		else
251
+		} else
252 252
 		{
253 253
 			$args = array_keys($this->_filters);
254 254
 			$fields = (array) Context::getRequestVars();
@@ -281,13 +281,11 @@  discard block
 block discarded – undo
281 281
 			if($key{0} == '^')
282 282
 			{
283 283
 				$names = preg_grep('/^' . preg_quote(substr($key, 1)) . '/', $field_names);
284
-			}
285
-			elseif(substr($key, -2) == '[]')
284
+			} elseif(substr($key, -2) == '[]')
286 285
 			{
287 286
 				$filters[substr($key, 0, -2)] = $filter;
288 287
 				unset($filters[$key]);
289
-			}
290
-			else
288
+			} else
291 289
 			{
292 290
 				$filters[$key] = $filter;
293 291
 			}
@@ -313,8 +311,7 @@  discard block
 block discarded – undo
313 311
 			{
314 312
 				$exists = array_key_exists($matches[1], $fields);
315 313
 				$value = $exists ? $fields[$matches[1]][$matches[2]] : NULL;
316
-			}
317
-			else
314
+			} else
318 315
 			{
319 316
 				$exists = array_key_exists($key, $fields);
320 317
 				$value = $exists ? $fields[$fname] : NULL;
@@ -325,8 +322,7 @@  discard block
 block discarded – undo
325 322
 				if(!isset($value[tmp_name]))
326 323
 				{
327 324
 					$value = implode('', $value);
328
-				}
329
-				else
325
+				} else
330 326
 				{
331 327
 					$value = $value['name'];
332 328
 				}
@@ -356,8 +352,7 @@  discard block
 block discarded – undo
356 352
 				if(is_null($fields_))
357 353
 				{
358 354
 					Context::set($fname, $value);
359
-				}
360
-				else
355
+				} else
361 356
 				{
362 357
 					$fields_[$fname] = $value;
363 358
 				}
@@ -464,8 +459,7 @@  discard block
 block discarded – undo
464 459
 		if(isset($this->_message[$msg]))
465 460
 		{
466 461
 			$msg = $this->_message[$msg];
467
-		}
468
-		else
462
+		} else
469 463
 		{
470 464
 			$lang_filter = Context::getLang('filter');
471 465
 			$msg = isset($lang_filter->{$msg}) ? $lang_filter->{$msg} : $lang_filter->invalid;
@@ -474,8 +468,7 @@  discard block
 block discarded – undo
474 468
 		if(isset($this->_fieldNames[$field]))
475 469
 		{
476 470
 			$fieldName = $this->_fieldNames[$field];
477
-		}
478
-		else
471
+		} else
479 472
 		{
480 473
 			$fieldName = Context::getLang($field);
481 474
 		}
@@ -507,8 +500,7 @@  discard block
 block discarded – undo
507 500
 		if(is_array($name))
508 501
 		{
509 502
 			$args = $name;
510
-		}
511
-		else
503
+		} else
512 504
 		{
513 505
 			$args = array($name => $rule);
514 506
 		}
@@ -555,8 +547,7 @@  discard block
 block discarded – undo
555 547
 		if(is_array($name))
556 548
 		{
557 549
 			$args = $name;
558
-		}
559
-		else
550
+		} else
560 551
 		{
561 552
 			$args = array($name => $filter);
562 553
 		}
@@ -577,8 +568,7 @@  discard block
 block discarded – undo
577 568
 					{
578 569
 						$filter['if'] = array($filter['if']);
579 570
 					}
580
-				}
581
-				else
571
+				} else
582 572
 				{
583 573
 					unset($filter['if']);
584 574
 				}
@@ -753,8 +743,7 @@  discard block
 block discarded – undo
753 743
 			{
754 744
 				$field_lang = addslashes($filter['title']);
755 745
 				$messages[] = "v.cast('ADD_MESSAGE',['{$name}','{$field_lang}']);";
756
-			}
757
-			elseif(isset($lang->{$name}))
746
+			} elseif(isset($lang->{$name}))
758 747
 			{
759 748
 				$field_lang = addslashes($lang->{$name});
760 749
 				$messages[] = "v.cast('ADD_MESSAGE',['{$name}','{$field_lang}']);";
Please login to merge, or discard this patch.
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 		$this->_filters = array();
82 82
 		$this->_xml_ruleset = NULL;
83 83
 
84
-		if($xml_path)
84
+		if ($xml_path)
85 85
 			$this->load($xml_path);
86 86
 
87 87
 		// predefined rules
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 		));
97 97
 
98 98
 		$this->_has_mb_func = is_callable('mb_strlen');
99
-		$this->setCacheDir(_XE_PATH_ . 'files/cache');
99
+		$this->setCacheDir(_XE_PATH_.'files/cache');
100 100
 	}
101 101
 
102 102
 	/**
@@ -119,32 +119,32 @@  discard block
 block discarded – undo
119 119
 		$this->_xml_ruleset = NULL;
120 120
 
121 121
 		$xml_path = realpath($xml_path);
122
-		if(!is_readable($xml_path))
122
+		if (!is_readable($xml_path))
123 123
 		{
124 124
 			return FALSE;
125 125
 		}
126 126
 
127 127
 		$parser = new XmlParser();
128 128
 		$xml = $parser->loadXmlFile($xml_path);
129
-		if(!isset($xml->ruleset) || !isset($xml->ruleset->fields) || !isset($xml->ruleset->fields->field))
129
+		if (!isset($xml->ruleset) || !isset($xml->ruleset->fields) || !isset($xml->ruleset->fields->field))
130 130
 		{
131 131
 			return FALSE;
132 132
 		}
133 133
 
134 134
 		// custom rules
135
-		if(isset($xml->ruleset->customrules) && isset($xml->ruleset->customrules->rule))
135
+		if (isset($xml->ruleset->customrules) && isset($xml->ruleset->customrules->rule))
136 136
 		{
137 137
 			$customrules = $xml->ruleset->customrules->rule;
138
-			if(!is_array($customrules))
138
+			if (!is_array($customrules))
139 139
 			{
140 140
 				$customrules = array($customrules);
141 141
 			}
142 142
 
143 143
 			$rules = array();
144 144
 			$messages = array();
145
-			foreach($customrules as $rule)
145
+			foreach ($customrules as $rule)
146 146
 			{
147
-				if(!isset($rule->attrs) || !isset($rule->attrs->name))
147
+				if (!isset($rule->attrs) || !isset($rule->attrs->name))
148 148
 				{
149 149
 					continue;
150 150
 				}
@@ -156,12 +156,12 @@  discard block
 block discarded – undo
156 156
 				unset($rule['name']);
157 157
 
158 158
 				$rules[$name] = $rule;
159
-				if(isset($message))
159
+				if (isset($message))
160 160
 				{
161
-					$messages['invalid_' . $name] = $message;
161
+					$messages['invalid_'.$name] = $message;
162 162
 				}
163 163
 			}
164
-			if(count($rules))
164
+			if (count($rules))
165 165
 			{
166 166
 				$this->addRule($rules);
167 167
 			}
@@ -169,19 +169,19 @@  discard block
 block discarded – undo
169 169
 
170 170
 		// filters
171 171
 		$fields = $xml->ruleset->fields->field;
172
-		if(!is_array($fields))
172
+		if (!is_array($fields))
173 173
 		{
174 174
 			$fields = array($fields);
175 175
 		}
176 176
 
177 177
 		$filters = array();
178 178
 		$fieldsNames = array();
179
-		foreach($fields as $field)
179
+		foreach ($fields as $field)
180 180
 		{
181 181
 			$name = '';
182 182
 			$filter = array();
183 183
 
184
-			if(!isset($field->attrs) || !isset($field->attrs->name))
184
+			if (!isset($field->attrs) || !isset($field->attrs->name))
185 185
 			{
186 186
 				continue;
187 187
 			}
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 			$filter['title'] = $title;
192 192
 
193 193
 			$name = $filter['name'];
194
-			if(isset($title))
194
+			if (isset($title))
195 195
 			{
196 196
 				$fieldsNames[$name] = $title;
197 197
 			}
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
 			unset($filter['name']);
200 200
 
201 201
 			// conditional statement
202
-			if(isset($field->if))
202
+			if (isset($field->if))
203 203
 			{
204 204
 				$if = $field->if;
205
-				if(!is_array($if))
205
+				if (!is_array($if))
206 206
 				{
207 207
 					$if = array($if);
208 208
 				}
209
-				foreach($if as $idx => $cond)
209
+				foreach ($if as $idx => $cond)
210 210
 				{
211 211
 					$if[$idx] = (array) $cond->attrs;
212 212
 				}
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 	 */
233 233
 	function setCacheDir($cache_dir)
234 234
 	{
235
-		if(is_dir($cache_dir))
235
+		if (is_dir($cache_dir))
236 236
 		{
237 237
 			$this->_cache_dir = preg_replace('@/$@', '', $cache_dir);
238 238
 		}
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 */
246 246
 	function validate($fields_ = null)
247 247
 	{
248
-		if(is_array($fields_))
248
+		if (is_array($fields_))
249 249
 		{
250 250
 			$fields = $fields_;
251 251
 		}
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 			$fields = (array) Context::getRequestVars();
256 256
 		}
257 257
 
258
-		if(!is_array($fields))
258
+		if (!is_array($fields))
259 259
 		{
260 260
 			return TRUE;
261 261
 		}
@@ -276,14 +276,14 @@  discard block
 block discarded – undo
276 276
 		$filters = array();
277 277
 
278 278
 		// get field names matching patterns
279
-		foreach($this->_filters as $key => $filter)
279
+		foreach ($this->_filters as $key => $filter)
280 280
 		{
281 281
 			$names = array();
282
-			if($key{0} == '^')
282
+			if ($key{0} == '^')
283 283
 			{
284
-				$names = preg_grep('/^' . preg_quote(substr($key, 1)) . '/', $field_names);
284
+				$names = preg_grep('/^'.preg_quote(substr($key, 1)).'/', $field_names);
285 285
 			}
286
-			elseif(substr($key, -2) == '[]')
286
+			elseif (substr($key, -2) == '[]')
287 287
 			{
288 288
 				$filters[substr($key, 0, -2)] = $filter;
289 289
 				unset($filters[$key]);
@@ -293,24 +293,24 @@  discard block
 block discarded – undo
293 293
 				$filters[$key] = $filter;
294 294
 			}
295 295
 
296
-			if(!count($names))
296
+			if (!count($names))
297 297
 			{
298 298
 				continue;
299 299
 			}
300 300
 
301
-			foreach($names as $name)
301
+			foreach ($names as $name)
302 302
 			{
303 303
 				$filters[$name] = $filter;
304 304
 			}
305 305
 			unset($filters[$key]);
306 306
 		}
307 307
 
308
-		foreach($filters as $key => $filter)
308
+		foreach ($filters as $key => $filter)
309 309
 		{
310 310
 			$fname = preg_replace('/\[\]$/', '', $key);
311 311
 			$filter = array_merge($filter_default, $filter);
312 312
 
313
-			if(preg_match("/(^[a-z_]*)[\[](?:\'|\")?([a-z_]*)(?:\'|\")?[\]]$/i", $key, $matches))
313
+			if (preg_match("/(^[a-z_]*)[\[](?:\'|\")?([a-z_]*)(?:\'|\")?[\]]$/i", $key, $matches))
314 314
 			{
315 315
 				$exists = array_key_exists($matches[1], $fields);
316 316
 				$value = $exists ? $fields[$matches[1]][$matches[2]] : NULL;
@@ -321,9 +321,9 @@  discard block
 block discarded – undo
321 321
 				$value = $exists ? $fields[$fname] : NULL;
322 322
 			}
323 323
 
324
-			if(is_array($value))
324
+			if (is_array($value))
325 325
 			{
326
-				if(!isset($value[tmp_name]))
326
+				if (!isset($value[tmp_name]))
327 327
 				{
328 328
 					$value = implode('', $value);
329 329
 				}
@@ -334,9 +334,9 @@  discard block
 block discarded – undo
334 334
 			}
335 335
 
336 336
 			// conditional statement
337
-			foreach($filter['if'] as $cond)
337
+			foreach ($filter['if'] as $cond)
338 338
 			{
339
-				if(!isset($cond['test']) || !isset($cond['attr']))
339
+				if (!isset($cond['test']) || !isset($cond['attr']))
340 340
 				{
341 341
 					continue;
342 342
 				}
@@ -344,17 +344,17 @@  discard block
 block discarded – undo
344 344
 				$func_body = preg_replace('/\\$(\w+)/', '$c[\'$1\']', $cond['test']);
345 345
 				$func = create_function('$c', "return !!({$func_body});");
346 346
 
347
-				if($func($fields))
347
+				if ($func($fields))
348 348
 				{
349 349
 					$filter[$cond['attr']] = $cond['value'];
350 350
 				}
351 351
 			}
352 352
 
353 353
 			// attr : default
354
-			if(!$value && strlen($default = trim($filter['default'])))
354
+			if (!$value && strlen($default = trim($filter['default'])))
355 355
 			{
356 356
 				$value = $default;
357
-				if(is_null($fields_))
357
+				if (is_null($fields_))
358 358
 				{
359 359
 					Context::set($fname, $value);
360 360
 				}
@@ -366,25 +366,25 @@  discard block
 block discarded – undo
366 366
 			$value_len = strlen($value);
367 367
 
368 368
 			// attr : modifier
369
-			if(is_string($modifiers = $filter['modifiers']))
369
+			if (is_string($modifiers = $filter['modifiers']))
370 370
 			{
371 371
 				$modifiers = explode(',', trim($modifiers));
372 372
 			}
373 373
 
374 374
 			// attr : required
375
-			if($filter['required'] === 'true' && !$value_len)
375
+			if ($filter['required'] === 'true' && !$value_len)
376 376
 			{
377 377
 				return $this->error($key, 'isnull');
378 378
 			}
379 379
 
380 380
 			// if the field wasn't passed, ignore this value
381
-			if(!$exists && !$value_len)
381
+			if (!$exists && !$value_len)
382 382
 			{
383 383
 				continue;
384 384
 			}
385 385
 
386 386
 			// attr : length
387
-			if($length = $filter['length'])
387
+			if ($length = $filter['length'])
388 388
 			{
389 389
 				list($min, $max) = explode(':', trim($length));
390 390
 				$is_min_b = (substr($min, -1) === 'b');
@@ -392,41 +392,41 @@  discard block
 block discarded – undo
392 392
 				list($min, $max) = array((int) $min, (int) $max);
393 393
 
394 394
 				$strbytes = strlen($value);
395
-				if(!$is_min_b || !$is_max_b)
395
+				if (!$is_min_b || !$is_max_b)
396 396
 				{
397 397
 					$strlength = $this->_has_mb_func ? mb_strlen($value, 'utf-8') : $this->mbStrLen($value);
398 398
 				}
399 399
 
400
-				if(($min && $min > ($is_min_b ? $strbytes : $strlength)) || ($max && $max < ($is_max_b ? $strbytes : $strlength)))
400
+				if (($min && $min > ($is_min_b ? $strbytes : $strlength)) || ($max && $max < ($is_max_b ? $strbytes : $strlength)))
401 401
 				{
402 402
 					return $this->error($key, 'outofrange');
403 403
 				}
404 404
 			}
405 405
 
406 406
 			// equalto
407
-			if($equalto = $filter['equalto'])
407
+			if ($equalto = $filter['equalto'])
408 408
 			{
409
-				if(!array_key_exists($equalto, $fields) || trim($fields[$equalto]) !== $value)
409
+				if (!array_key_exists($equalto, $fields) || trim($fields[$equalto]) !== $value)
410 410
 				{
411 411
 					return $this->error($key, 'equalto');
412 412
 				}
413 413
 			}
414 414
 
415 415
 			// rules
416
-			if($rules = $filter['rule'])
416
+			if ($rules = $filter['rule'])
417 417
 			{
418 418
 				$rules = explode(',', $rules);
419
-				foreach($rules as $rule)
419
+				foreach ($rules as $rule)
420 420
 				{
421 421
 					$result = $this->applyRule($rule, $value);
422 422
 					// apply the 'not' modifier
423
-					if(in_array('not', $modifiers))
423
+					if (in_array('not', $modifiers))
424 424
 					{
425 425
 						$result = !$result;
426 426
 					}
427
-					if(!$result)
427
+					if (!$result)
428 428
 					{
429
-						return $this->error($key, 'invalid_' . $rule);
429
+						return $this->error($key, 'invalid_'.$rule);
430 430
 					}
431 431
 				}
432 432
 			}
@@ -442,12 +442,12 @@  discard block
 block discarded – undo
442 442
 	 */
443 443
 	function arrayTrim($array)
444 444
 	{
445
-		if(!is_array($array))
445
+		if (!is_array($array))
446 446
 		{
447 447
 			return trim($array);
448 448
 		}
449 449
 
450
-		foreach($array as $key => $value)
450
+		foreach ($array as $key => $value)
451 451
 		{
452 452
 			$array[$key] = $this->arrayTrim($value);
453 453
 		}
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 	 */
463 463
 	function error($field, $msg)
464 464
 	{
465
-		if(isset($this->_message[$msg]))
465
+		if (isset($this->_message[$msg]))
466 466
 		{
467 467
 			$msg = $this->_message[$msg];
468 468
 		}
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
 			$msg = isset($lang_filter->{$msg}) ? $lang_filter->{$msg} : $lang_filter->invalid;
473 473
 		}
474 474
 
475
-		if(isset($this->_fieldNames[$field]))
475
+		if (isset($this->_fieldNames[$field]))
476 476
 		{
477 477
 			$fieldName = $this->_fieldNames[$field];
478 478
 		}
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
 	 */
506 506
 	function addRule($name, $rule = '')
507 507
 	{
508
-		if(is_array($name))
508
+		if (is_array($name))
509 509
 		{
510 510
 			$args = $name;
511 511
 		}
@@ -514,18 +514,18 @@  discard block
 block discarded – undo
514 514
 			$args = array($name => $rule);
515 515
 		}
516 516
 
517
-		foreach($args as $name => $rule)
517
+		foreach ($args as $name => $rule)
518 518
 		{
519
-			if(!$rule)
519
+			if (!$rule)
520 520
 			{
521 521
 				continue;
522 522
 			}
523
-			if(is_string($rule))
523
+			if (is_string($rule))
524 524
 			{
525 525
 				$rule = array('type' => 'regex', 'test' => $rule);
526 526
 			}
527 527
 
528
-			if($rule['type'] == 'enum')
528
+			if ($rule['type'] == 'enum')
529 529
 			{
530 530
 				$delim = isset($rule['delim']) ? $rule['delim'] : ',';
531 531
 				$rule['test'] = explode($delim, $rule['test']);
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
 	 */
554 554
 	function addFilter($name, $filter = '')
555 555
 	{
556
-		if(is_array($name))
556
+		if (is_array($name))
557 557
 		{
558 558
 			$args = $name;
559 559
 		}
@@ -562,19 +562,19 @@  discard block
 block discarded – undo
562 562
 			$args = array($name => $filter);
563 563
 		}
564 564
 
565
-		foreach($args as $name => $filter)
565
+		foreach ($args as $name => $filter)
566 566
 		{
567
-			if(!$filter)
567
+			if (!$filter)
568 568
 			{
569 569
 				continue;
570 570
 			}
571 571
 
572
-			if(isset($filter['if']))
572
+			if (isset($filter['if']))
573 573
 			{
574
-				if(is_array($filter['if']) && count($filter['if']))
574
+				if (is_array($filter['if']) && count($filter['if']))
575 575
 				{
576 576
 					$key = key($filter['if']);
577
-					if(!is_int($key))
577
+					if (!is_int($key))
578 578
 					{
579 579
 						$filter['if'] = array($filter['if']);
580 580
 					}
@@ -609,21 +609,21 @@  discard block
 block discarded – undo
609 609
 	{
610 610
 		$rule = $this->_rules[$name];
611 611
 
612
-		if(is_array($value) && isset($value['tmp_name']))
612
+		if (is_array($value) && isset($value['tmp_name']))
613 613
 		{
614 614
 			$value = $value['name'];
615 615
 		}
616 616
 
617
-		switch($rule['type'])
617
+		switch ($rule['type'])
618 618
 		{
619 619
 			case 'regex':
620 620
 				return (preg_match($rule['test'], $value) > 0);
621 621
 			case 'enum':
622 622
 				return in_array($value, $rule['test']);
623 623
 			case 'expr':
624
-				if(!$rule['func_test'])
624
+				if (!$rule['func_test'])
625 625
 				{
626
-					$rule['func_test'] = create_function('$a', 'return (' . preg_replace('/\$\$/', '$a', html_entity_decode($rule['test'])) . ');');
626
+					$rule['func_test'] = create_function('$a', 'return ('.preg_replace('/\$\$/', '$a', html_entity_decode($rule['test'])).');');
627 627
 				}
628 628
 				return $rule['func_test']($value);
629 629
 		}
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
 	function mbStrLen($str)
640 640
 	{
641 641
 		$arr = count_chars($str);
642
-		for($i = 0x80; $i < 0xc0; $i++)
642
+		for ($i = 0x80; $i < 0xc0; $i++)
643 643
 		{
644 644
 			unset($arr[$i]);
645 645
 		}
@@ -652,17 +652,17 @@  discard block
 block discarded – undo
652 652
 	 */
653 653
 	function getJsPath()
654 654
 	{
655
-		if(!$this->_cache_dir)
655
+		if (!$this->_cache_dir)
656 656
 		{
657 657
 			return FALSE;
658 658
 		}
659 659
 
660
-		$dir = $this->_cache_dir . '/ruleset';
661
-		if(!is_dir($dir) && !mkdir($dir))
660
+		$dir = $this->_cache_dir.'/ruleset';
661
+		if (!is_dir($dir) && !mkdir($dir))
662 662
 		{
663 663
 			return FALSE;
664 664
 		}
665
-		if(!$this->_xml_path)
665
+		if (!$this->_xml_path)
666 666
 		{
667 667
 			return FALSE;
668 668
 		}
@@ -671,14 +671,14 @@  discard block
 block discarded – undo
671 671
 		$lang_type = class_exists('Context', false) ? Context::getLangType() : 'en';
672 672
 
673 673
 		// check the file
674
-		$filepath = $dir . '/' . md5($this->_version . ' ' . $this->_xml_path) . ".{$lang_type}.js";
675
-		if(is_readable($filepath) && filemtime($filepath) > filemtime($this->_xml_path))
674
+		$filepath = $dir.'/'.md5($this->_version.' '.$this->_xml_path).".{$lang_type}.js";
675
+		if (is_readable($filepath) && filemtime($filepath) > filemtime($this->_xml_path))
676 676
 		{
677 677
 			return $filepath;
678 678
 		}
679 679
 
680 680
 		$content = $this->_compile2js();
681
-		if($content === FALSE)
681
+		if ($content === FALSE)
682 682
 		{
683 683
 			return FALSE;
684 684
 		}
@@ -699,9 +699,9 @@  discard block
 block discarded – undo
699 699
 		$ruleset = basename($this->_xml_path, '.xml');
700 700
 		$content = array();
701 701
 
702
-		if(preg_match('@(^|/)files/ruleset/\w+\.xml$@i', $this->_xml_path))
702
+		if (preg_match('@(^|/)files/ruleset/\w+\.xml$@i', $this->_xml_path))
703 703
 		{
704
-			$ruleset = '@' . $ruleset;
704
+			$ruleset = '@'.$ruleset;
705 705
 		}
706 706
 
707 707
 		list($ruleset) = explode('.', $ruleset);
@@ -711,22 +711,22 @@  discard block
 block discarded – undo
711 711
 
712 712
 		// custom rulesets
713 713
 		$addrules = array();
714
-		foreach($this->_rules as $name => $rule)
714
+		foreach ($this->_rules as $name => $rule)
715 715
 		{
716 716
 			$name = strtolower($name);
717 717
 
718
-			if(in_array($name, array('email', 'userid', 'url', 'alpha', 'alpha_number', 'number', 'float')))
718
+			if (in_array($name, array('email', 'userid', 'url', 'alpha', 'alpha_number', 'number', 'float')))
719 719
 			{
720 720
 				continue;
721 721
 			}
722 722
 
723
-			switch($rule['type'])
723
+			switch ($rule['type'])
724 724
 			{
725 725
 				case 'regex':
726 726
 					$addrules[] = "v.cast('ADD_RULE', ['{$name}', {$rule['test']}]);";
727 727
 					break;
728 728
 				case 'enum':
729
-					$enums = '"' . implode('","', $rule['test']) . '"';
729
+					$enums = '"'.implode('","', $rule['test']).'"';
730 730
 					$addrules[] = "v.cast('ADD_RULE', ['{$name}', function($$){ return ($.inArray($$,[{$enums}]) > -1); }]);";
731 731
 					break;
732 732
 				case 'expr':
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
 			}
736 736
 
737 737
 			// if have a message, add message
738
-			if(isset($rule['message']))
738
+			if (isset($rule['message']))
739 739
 			{
740 740
 				$text = preg_replace('@\r?\n@', '\\n', addslashes($rule['message']));
741 741
 				$addrules[] = "v.cast('ADD_MESSAGE',['invalid_{$name}','{$text}']);";
@@ -746,79 +746,79 @@  discard block
 block discarded – undo
746 746
 		// filters
747 747
 		$content = array();
748 748
 		$messages = array();
749
-		foreach($this->_filters as $name => $filter)
749
+		foreach ($this->_filters as $name => $filter)
750 750
 		{
751 751
 			$field = array();
752 752
 
753 753
 			// form filed name
754
-			if(isset($filter['title']))
754
+			if (isset($filter['title']))
755 755
 			{
756 756
 				$field_lang = addslashes($filter['title']);
757 757
 				$messages[] = "v.cast('ADD_MESSAGE',['{$name}','{$field_lang}']);";
758 758
 			}
759
-			elseif(isset($lang->{$name}))
759
+			elseif (isset($lang->{$name}))
760 760
 			{
761 761
 				$field_lang = addslashes($lang->{$name});
762 762
 				$messages[] = "v.cast('ADD_MESSAGE',['{$name}','{$field_lang}']);";
763 763
 			}
764 764
 
765
-			if($filter['required'] == 'true')
765
+			if ($filter['required'] == 'true')
766 766
 			{
767 767
 				$field[] = 'required:true';
768 768
 			}
769
-			if($filter['rule'])
769
+			if ($filter['rule'])
770 770
 			{
771
-				$field[] = "rule:'" . strtolower($filter['rule']) . "'";
771
+				$field[] = "rule:'".strtolower($filter['rule'])."'";
772 772
 			}
773
-			if($filter['default'])
773
+			if ($filter['default'])
774 774
 			{
775 775
 				$field[] = "default:'{$filter['default']}'";
776 776
 			}
777
-			if($filter['modifier'])
777
+			if ($filter['modifier'])
778 778
 			{
779 779
 				$field[] = "modifier:'{$filter['modifier']}'";
780 780
 			}
781
-			if($filter['length'])
781
+			if ($filter['length'])
782 782
 			{
783 783
 				list($min, $max) = explode(':', $filter['length']);
784
-				if($min)
784
+				if ($min)
785 785
 				{
786 786
 					$field[] = "minlength:'{$min}'";
787 787
 				}
788
-				if($max)
788
+				if ($max)
789 789
 				{
790 790
 					$field[] = "maxlength:'{$max}'";
791 791
 				}
792 792
 			}
793
-			if($filter['if'])
793
+			if ($filter['if'])
794 794
 			{
795 795
 				$ifs = array();
796
-				if(!isset($filter['if'][0]))
796
+				if (!isset($filter['if'][0]))
797 797
 				{
798 798
 					$filter['if'] = array($filter['if']);
799 799
 				}
800
-				foreach($filter['if'] as $if)
800
+				foreach ($filter['if'] as $if)
801 801
 				{
802
-					$ifs[] = "{test:'" . addslashes($if['test']) . "', attr:'{$if['attr']}', value:'" . addslashes($if['value']) . "'}";
802
+					$ifs[] = "{test:'".addslashes($if['test'])."', attr:'{$if['attr']}', value:'".addslashes($if['value'])."'}";
803 803
 				}
804
-				$field[] = "'if':[" . implode(',', $ifs) . "]";
804
+				$field[] = "'if':[".implode(',', $ifs)."]";
805 805
 			}
806
-			if(count($field))
806
+			if (count($field))
807 807
 			{
808
-				$field = '{' . implode(',', $field) . '}';
808
+				$field = '{'.implode(',', $field).'}';
809 809
 				$content[] = "'{$name}':{$field}";
810 810
 			}
811 811
 		}
812 812
 
813
-		if(!$content)
813
+		if (!$content)
814 814
 		{
815 815
 			return '/* Error : empty ruleset  */';
816 816
 		}
817 817
 
818 818
 		// error messages
819
-		foreach($lang->filter as $key => $text)
819
+		foreach ($lang->filter as $key => $text)
820 820
 		{
821
-			if($text)
821
+			if ($text)
822 822
 			{
823 823
 				$text = preg_replace('@\r?\n@', '\\n', addslashes($text));
824 824
 				$messages[] = "v.cast('ADD_MESSAGE',['{$key}','{$text}']);";
Please login to merge, or discard this patch.
classes/xml/GeneralXmlParser.class.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	/**
62 62
 	 * Character data handler
63 63
 	 * Variable in the last element of this->output
64
-	 * @param resource $parse an instance of parser
64
+	 * @param resource $parser an instance of parser
65 65
 	 * @param string $body a data to be added
66 66
 	 * @return void
67 67
 	 */
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 
74 74
 	/**
75 75
 	 * End element handler
76
-	 * @param resource $parse an instance of parser
76
+	 * @param resource $parser an instance of parser
77 77
 	 * @param string $node_name name of xml node
78 78
 	 * @return void
79 79
 	 */
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 		xml_parse($oParser, $input);
33 33
 		xml_parser_free($oParser);
34 34
 
35
-		if(count($this->output) < 1)
35
+		if (count($this->output) < 1)
36 36
 		{
37 37
 			return;
38 38
 		}
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
 		$parent_obj = &$this->output[count($this->output) - 1];
85 85
 		$tmp_obj = &$parent_obj->childNodes[$node_name];
86 86
 
87
-		if($tmp_obj)
87
+		if ($tmp_obj)
88 88
 		{
89
-			if(is_array($tmp_obj))
89
+			if (is_array($tmp_obj))
90 90
 			{
91 91
 				$tmp_obj[] = $cur_obj;
92 92
 			}
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -89,13 +89,11 @@
 block discarded – undo
89 89
 			if(is_array($tmp_obj))
90 90
 			{
91 91
 				$tmp_obj[] = $cur_obj;
92
-			}
93
-			else
92
+			} else
94 93
 			{
95 94
 				$tmp_obj = array($tmp_obj, $cur_obj);
96 95
 			}
97
-		}
98
-		else
96
+		} else
99 97
 		{
100 98
 			$tmp_obj = $cur_obj;
101 99
 		}
Please login to merge, or discard this patch.