@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | public function getSupportedAlgorithms() |
20 | 20 | { |
21 | 21 | $retval = array(); |
22 | - if(function_exists('hash_hmac') && in_array('sha256', hash_algos())) |
|
22 | + if (function_exists('hash_hmac') && in_array('sha256', hash_algos())) |
|
23 | 23 | { |
24 | 24 | $retval['pbkdf2'] = 'pbkdf2'; |
25 | 25 | } |
26 | - if(version_compare(PHP_VERSION, '5.3.7', '>=') && defined('CRYPT_BLOWFISH')) |
|
26 | + if (version_compare(PHP_VERSION, '5.3.7', '>=') && defined('CRYPT_BLOWFISH')) |
|
27 | 27 | { |
28 | 28 | $retval['bcrypt'] = 'bcrypt'; |
29 | 29 | } |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function getCurrentlySelectedAlgorithm() |
49 | 49 | { |
50 | - if(function_exists('getModel')) |
|
50 | + if (function_exists('getModel')) |
|
51 | 51 | { |
52 | 52 | $config = getModel('member')->getMemberConfig(); |
53 | 53 | $algorithm = $config->password_hashing_algorithm; |
54 | - if(strval($algorithm) === '') |
|
54 | + if (strval($algorithm) === '') |
|
55 | 55 | { |
56 | - $algorithm = 'md5'; // Historical default for XE |
|
56 | + $algorithm = 'md5'; // Historical default for XE |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | else |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function getWorkFactor() |
71 | 71 | { |
72 | - if(function_exists('getModel')) |
|
72 | + if (function_exists('getModel')) |
|
73 | 73 | { |
74 | 74 | $config = getModel('member')->getMemberConfig(); |
75 | 75 | $work_factor = $config->password_hashing_work_factor; |
76 | - if(!$work_factor || $work_factor < 4 || $work_factor > 31) |
|
76 | + if (!$work_factor || $work_factor < 4 || $work_factor > 31) |
|
77 | 77 | { |
78 | - $work_factor = 8; // Reasonable default |
|
78 | + $work_factor = 8; // Reasonable default |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | else |
@@ -93,18 +93,18 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function createHash($password, $algorithm = null) |
95 | 95 | { |
96 | - if($algorithm === null) |
|
96 | + if ($algorithm === null) |
|
97 | 97 | { |
98 | 98 | $algorithm = $this->getCurrentlySelectedAlgorithm(); |
99 | 99 | } |
100 | - if(!array_key_exists($algorithm, $this->getSupportedAlgorithms())) |
|
100 | + if (!array_key_exists($algorithm, $this->getSupportedAlgorithms())) |
|
101 | 101 | { |
102 | 102 | return false; |
103 | 103 | } |
104 | 104 | |
105 | 105 | $password = trim($password); |
106 | 106 | |
107 | - switch($algorithm) |
|
107 | + switch ($algorithm) |
|
108 | 108 | { |
109 | 109 | case 'md5': |
110 | 110 | return md5($password); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $iterations = pow(2, $this->getWorkFactor() + 5); |
114 | 114 | $salt = $this->createSecureSalt(12, 'alnum'); |
115 | 115 | $hash = base64_encode($this->pbkdf2($password, $salt, 'sha256', $iterations, 24)); |
116 | - return 'sha256:'.sprintf('%07d', $iterations).':'.$salt.':'.$hash; |
|
116 | + return 'sha256:' . sprintf('%07d', $iterations) . ':' . $salt . ':' . $hash; |
|
117 | 117 | |
118 | 118 | case 'bcrypt': |
119 | 119 | return $this->bcrypt($password); |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function checkPassword($password, $hash, $algorithm = null) |
134 | 134 | { |
135 | - if($algorithm === null) |
|
135 | + if ($algorithm === null) |
|
136 | 136 | { |
137 | 137 | $algorithm = $this->checkAlgorithm($hash); |
138 | 138 | } |
139 | 139 | |
140 | 140 | $password = trim($password); |
141 | 141 | |
142 | - switch($algorithm) |
|
142 | + switch ($algorithm) |
|
143 | 143 | { |
144 | 144 | case 'md5': |
145 | 145 | return md5($password) === $hash || md5(sha1(md5($password))) === $hash; |
@@ -173,23 +173,23 @@ discard block |
||
173 | 173 | */ |
174 | 174 | function checkAlgorithm($hash) |
175 | 175 | { |
176 | - if(preg_match('/^\$2[axy]\$([0-9]{2})\$/', $hash, $matches)) |
|
176 | + if (preg_match('/^\$2[axy]\$([0-9]{2})\$/', $hash, $matches)) |
|
177 | 177 | { |
178 | 178 | return 'bcrypt'; |
179 | 179 | } |
180 | - elseif(preg_match('/^sha[0-9]+:([0-9]+):/', $hash, $matches)) |
|
180 | + elseif (preg_match('/^sha[0-9]+:([0-9]+):/', $hash, $matches)) |
|
181 | 181 | { |
182 | 182 | return 'pbkdf2'; |
183 | 183 | } |
184 | - elseif(strlen($hash) === 32 && ctype_xdigit($hash)) |
|
184 | + elseif (strlen($hash) === 32 && ctype_xdigit($hash)) |
|
185 | 185 | { |
186 | 186 | return 'md5'; |
187 | 187 | } |
188 | - elseif(strlen($hash) === 16 && ctype_xdigit($hash)) |
|
188 | + elseif (strlen($hash) === 16 && ctype_xdigit($hash)) |
|
189 | 189 | { |
190 | 190 | return 'mysql_old_password'; |
191 | 191 | } |
192 | - elseif(strlen($hash) === 41 && $hash[0] === '*') |
|
192 | + elseif (strlen($hash) === 41 && $hash[0] === '*') |
|
193 | 193 | { |
194 | 194 | return 'mysql_password'; |
195 | 195 | } |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | */ |
207 | 207 | function checkWorkFactor($hash) |
208 | 208 | { |
209 | - if(preg_match('/^\$2[axy]\$([0-9]{2})\$/', $hash, $matches)) |
|
209 | + if (preg_match('/^\$2[axy]\$([0-9]{2})\$/', $hash, $matches)) |
|
210 | 210 | { |
211 | 211 | return intval($matches[1], 10); |
212 | 212 | } |
213 | - elseif(preg_match('/^sha[0-9]+:([0-9]+):/', $hash, $matches)) |
|
213 | + elseif (preg_match('/^sha[0-9]+:([0-9]+):/', $hash, $matches)) |
|
214 | 214 | { |
215 | 215 | return max(0, round(log($matches[1], 2)) - 5); |
216 | 216 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | public function createSecureSalt($length, $format = 'hex') |
230 | 230 | { |
231 | 231 | // Find out how many bytes of entropy we really need |
232 | - switch($format) |
|
232 | + switch ($format) |
|
233 | 233 | { |
234 | 234 | case 'hex': |
235 | 235 | $entropy_required_bytes = ceil($length / 2); |
@@ -247,19 +247,19 @@ discard block |
||
247 | 247 | |
248 | 248 | // Find and use the most secure way to generate a random string |
249 | 249 | $is_windows = (defined('PHP_OS') && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'); |
250 | - if(function_exists('openssl_random_pseudo_bytes') && (!$is_windows || version_compare(PHP_VERSION, '5.4', '>='))) |
|
250 | + if (function_exists('openssl_random_pseudo_bytes') && (!$is_windows || version_compare(PHP_VERSION, '5.4', '>='))) |
|
251 | 251 | { |
252 | 252 | $entropy = openssl_random_pseudo_bytes($entropy_capped_bytes); |
253 | 253 | } |
254 | - elseif(function_exists('mcrypt_create_iv') && (!$is_windows || version_compare(PHP_VERSION, '5.3.7', '>='))) |
|
254 | + elseif (function_exists('mcrypt_create_iv') && (!$is_windows || version_compare(PHP_VERSION, '5.3.7', '>='))) |
|
255 | 255 | { |
256 | 256 | $entropy = mcrypt_create_iv($entropy_capped_bytes, MCRYPT_DEV_URANDOM); |
257 | 257 | } |
258 | - elseif(function_exists('mcrypt_create_iv') && $is_windows) |
|
258 | + elseif (function_exists('mcrypt_create_iv') && $is_windows) |
|
259 | 259 | { |
260 | 260 | $entropy = mcrypt_create_iv($entropy_capped_bytes, MCRYPT_RAND); |
261 | 261 | } |
262 | - elseif(!$is_windows && @is_readable('/dev/urandom')) |
|
262 | + elseif (!$is_windows && @is_readable('/dev/urandom')) |
|
263 | 263 | { |
264 | 264 | $fp = fopen('/dev/urandom', 'rb'); |
265 | 265 | $entropy = fread($fp, $entropy_capped_bytes); |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | else |
269 | 269 | { |
270 | 270 | $entropy = ''; |
271 | - for($i = 0; $i < $entropy_capped_bytes; $i += 2) |
|
271 | + for ($i = 0; $i < $entropy_capped_bytes; $i += 2) |
|
272 | 272 | { |
273 | 273 | $entropy .= pack('S', rand(0, 65536) ^ mt_rand(0, 65535)); |
274 | 274 | } |
@@ -276,13 +276,13 @@ discard block |
||
276 | 276 | |
277 | 277 | // Mixing (see RFC 4086 section 5) |
278 | 278 | $output = ''; |
279 | - for($i = 0; $i < $entropy_required_bytes; $i += 32) |
|
279 | + for ($i = 0; $i < $entropy_required_bytes; $i += 32) |
|
280 | 280 | { |
281 | 281 | $output .= hash('sha256', $entropy . $i . rand(), true); |
282 | 282 | } |
283 | 283 | |
284 | 284 | // Encode and return the random string |
285 | - switch($format) |
|
285 | + switch ($format) |
|
286 | 286 | { |
287 | 287 | case 'hex': |
288 | 288 | return substr(bin2hex($output), 0, $length); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | return substr($output, 0, $length); |
291 | 291 | case 'printable': |
292 | 292 | $salt = ''; |
293 | - for($i = 0; $i < $length; $i++) |
|
293 | + for ($i = 0; $i < $length; $i++) |
|
294 | 294 | { |
295 | 295 | $salt .= chr(33 + (crc32(sha1($i . $output)) % 94)); |
296 | 296 | } |
@@ -310,15 +310,15 @@ discard block |
||
310 | 310 | */ |
311 | 311 | public function createTemporaryPassword($length = 16) |
312 | 312 | { |
313 | - while(true) |
|
313 | + while (true) |
|
314 | 314 | { |
315 | 315 | $source = base64_encode($this->createSecureSalt(64, 'binary')); |
316 | 316 | $source = strtr($source, 'iIoOjl10/', '@#$%&*-!?'); |
317 | 317 | $source_length = strlen($source); |
318 | - for($i = 0; $i < $source_length - $length; $i++) |
|
318 | + for ($i = 0; $i < $source_length - $length; $i++) |
|
319 | 319 | { |
320 | 320 | $candidate = substr($source, $i, $length); |
321 | - if(preg_match('/[a-z]/', $candidate) && preg_match('/[A-Z]/', $candidate) && |
|
321 | + if (preg_match('/[a-z]/', $candidate) && preg_match('/[A-Z]/', $candidate) && |
|
322 | 322 | preg_match('/[0-9]/', $candidate) && preg_match('/[^a-zA-Z0-9]/', $candidate)) |
323 | 323 | { |
324 | 324 | return $candidate; |
@@ -338,19 +338,19 @@ discard block |
||
338 | 338 | */ |
339 | 339 | public function pbkdf2($password, $salt, $algorithm = 'sha256', $iterations = 8192, $length = 24) |
340 | 340 | { |
341 | - if(function_exists('hash_pbkdf2')) |
|
341 | + if (function_exists('hash_pbkdf2')) |
|
342 | 342 | { |
343 | 343 | return hash_pbkdf2($algorithm, $password, $salt, $iterations, $length, true); |
344 | 344 | } |
345 | 345 | else |
346 | 346 | { |
347 | 347 | $output = ''; |
348 | - $block_count = ceil($length / strlen(hash($algorithm, '', true))); // key length divided by the length of one hash |
|
349 | - for($i = 1; $i <= $block_count; $i++) |
|
348 | + $block_count = ceil($length / strlen(hash($algorithm, '', true))); // key length divided by the length of one hash |
|
349 | + for ($i = 1; $i <= $block_count; $i++) |
|
350 | 350 | { |
351 | - $last = $salt . pack('N', $i); // $i encoded as 4 bytes, big endian |
|
352 | - $last = $xorsum = hash_hmac($algorithm, $last, $password, true); // first iteration |
|
353 | - for($j = 1; $j < $iterations; $j++) // The other $count - 1 iterations |
|
351 | + $last = $salt . pack('N', $i); // $i encoded as 4 bytes, big endian |
|
352 | + $last = $xorsum = hash_hmac($algorithm, $last, $password, true); // first iteration |
|
353 | + for ($j = 1; $j < $iterations; $j++) // The other $count - 1 iterations |
|
354 | 354 | { |
355 | 355 | $xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true)); |
356 | 356 | } |
@@ -368,9 +368,9 @@ discard block |
||
368 | 368 | */ |
369 | 369 | public function bcrypt($password, $salt = null) |
370 | 370 | { |
371 | - if($salt === null) |
|
371 | + if ($salt === null) |
|
372 | 372 | { |
373 | - $salt = '$2y$'.sprintf('%02d', $this->getWorkFactor()).'$'.$this->createSecureSalt(22, 'alnum'); |
|
373 | + $salt = '$2y$' . sprintf('%02d', $this->getWorkFactor()) . '$' . $this->createSecureSalt(22, 'alnum'); |
|
374 | 374 | } |
375 | 375 | return crypt($password, $salt); |
376 | 376 | } |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | { |
386 | 386 | $diff = strlen($a) ^ strlen($b); |
387 | 387 | $maxlen = min(strlen($a), strlen($b)); |
388 | - for($i = 0; $i < $maxlen; $i++) |
|
388 | + for ($i = 0; $i < $maxlen; $i++) |
|
389 | 389 | { |
390 | 390 | $diff |= ord($a[$i]) ^ ord($b[$i]); |
391 | 391 | } |
@@ -55,8 +55,7 @@ discard block |
||
55 | 55 | { |
56 | 56 | $algorithm = 'md5'; // Historical default for XE |
57 | 57 | } |
58 | - } |
|
59 | - else |
|
58 | + } else |
|
60 | 59 | { |
61 | 60 | $algorithm = 'md5'; |
62 | 61 | } |
@@ -77,8 +76,7 @@ discard block |
||
77 | 76 | { |
78 | 77 | $work_factor = 8; // Reasonable default |
79 | 78 | } |
80 | - } |
|
81 | - else |
|
79 | + } else |
|
82 | 80 | { |
83 | 81 | $work_factor = 8; |
84 | 82 | } |
@@ -176,24 +174,19 @@ discard block |
||
176 | 174 | if(preg_match('/^\$2[axy]\$([0-9]{2})\$/', $hash, $matches)) |
177 | 175 | { |
178 | 176 | return 'bcrypt'; |
179 | - } |
|
180 | - elseif(preg_match('/^sha[0-9]+:([0-9]+):/', $hash, $matches)) |
|
177 | + } elseif(preg_match('/^sha[0-9]+:([0-9]+):/', $hash, $matches)) |
|
181 | 178 | { |
182 | 179 | return 'pbkdf2'; |
183 | - } |
|
184 | - elseif(strlen($hash) === 32 && ctype_xdigit($hash)) |
|
180 | + } elseif(strlen($hash) === 32 && ctype_xdigit($hash)) |
|
185 | 181 | { |
186 | 182 | return 'md5'; |
187 | - } |
|
188 | - elseif(strlen($hash) === 16 && ctype_xdigit($hash)) |
|
183 | + } elseif(strlen($hash) === 16 && ctype_xdigit($hash)) |
|
189 | 184 | { |
190 | 185 | return 'mysql_old_password'; |
191 | - } |
|
192 | - elseif(strlen($hash) === 41 && $hash[0] === '*') |
|
186 | + } elseif(strlen($hash) === 41 && $hash[0] === '*') |
|
193 | 187 | { |
194 | 188 | return 'mysql_password'; |
195 | - } |
|
196 | - else |
|
189 | + } else |
|
197 | 190 | { |
198 | 191 | return false; |
199 | 192 | } |
@@ -209,12 +202,10 @@ discard block |
||
209 | 202 | if(preg_match('/^\$2[axy]\$([0-9]{2})\$/', $hash, $matches)) |
210 | 203 | { |
211 | 204 | return intval($matches[1], 10); |
212 | - } |
|
213 | - elseif(preg_match('/^sha[0-9]+:([0-9]+):/', $hash, $matches)) |
|
205 | + } elseif(preg_match('/^sha[0-9]+:([0-9]+):/', $hash, $matches)) |
|
214 | 206 | { |
215 | 207 | return max(0, round(log($matches[1], 2)) - 5); |
216 | - } |
|
217 | - else |
|
208 | + } else |
|
218 | 209 | { |
219 | 210 | return false; |
220 | 211 | } |
@@ -250,22 +241,18 @@ discard block |
||
250 | 241 | if(function_exists('openssl_random_pseudo_bytes') && (!$is_windows || version_compare(PHP_VERSION, '5.4', '>='))) |
251 | 242 | { |
252 | 243 | $entropy = openssl_random_pseudo_bytes($entropy_capped_bytes); |
253 | - } |
|
254 | - elseif(function_exists('mcrypt_create_iv') && (!$is_windows || version_compare(PHP_VERSION, '5.3.7', '>='))) |
|
244 | + } elseif(function_exists('mcrypt_create_iv') && (!$is_windows || version_compare(PHP_VERSION, '5.3.7', '>='))) |
|
255 | 245 | { |
256 | 246 | $entropy = mcrypt_create_iv($entropy_capped_bytes, MCRYPT_DEV_URANDOM); |
257 | - } |
|
258 | - elseif(function_exists('mcrypt_create_iv') && $is_windows) |
|
247 | + } elseif(function_exists('mcrypt_create_iv') && $is_windows) |
|
259 | 248 | { |
260 | 249 | $entropy = mcrypt_create_iv($entropy_capped_bytes, MCRYPT_RAND); |
261 | - } |
|
262 | - elseif(!$is_windows && @is_readable('/dev/urandom')) |
|
250 | + } elseif(!$is_windows && @is_readable('/dev/urandom')) |
|
263 | 251 | { |
264 | 252 | $fp = fopen('/dev/urandom', 'rb'); |
265 | 253 | $entropy = fread($fp, $entropy_capped_bytes); |
266 | 254 | fclose($fp); |
267 | - } |
|
268 | - else |
|
255 | + } else |
|
269 | 256 | { |
270 | 257 | $entropy = ''; |
271 | 258 | for($i = 0; $i < $entropy_capped_bytes; $i += 2) |
@@ -341,8 +328,7 @@ discard block |
||
341 | 328 | if(function_exists('hash_pbkdf2')) |
342 | 329 | { |
343 | 330 | return hash_pbkdf2($algorithm, $password, $salt, $iterations, $length, true); |
344 | - } |
|
345 | - else |
|
331 | + } else |
|
346 | 332 | { |
347 | 333 | $output = ''; |
348 | 334 | $block_count = ceil($length / strlen(hash($algorithm, '', true))); // key length divided by the length of one hash |
@@ -350,10 +336,12 @@ discard block |
||
350 | 336 | { |
351 | 337 | $last = $salt . pack('N', $i); // $i encoded as 4 bytes, big endian |
352 | 338 | $last = $xorsum = hash_hmac($algorithm, $last, $password, true); // first iteration |
353 | - for($j = 1; $j < $iterations; $j++) // The other $count - 1 iterations |
|
339 | + for($j = 1; $j < $iterations; $j++) { |
|
340 | + // The other $count - 1 iterations |
|
354 | 341 | { |
355 | 342 | $xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true)); |
356 | 343 | } |
344 | + } |
|
357 | 345 | $output .= $xorsum; |
358 | 346 | } |
359 | 347 | return substr($output, 0, $length); |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | public function getInstance() |
24 | 24 | { |
25 | - if(!isset($GLOBALS['__PURIFIER_INSTANCE__'])) |
|
25 | + if (!isset($GLOBALS['__PURIFIER_INSTANCE__'])) |
|
26 | 26 | { |
27 | 27 | $GLOBALS['__PURIFIER_INSTANCE__'] = new Purifier(); |
28 | 28 | } |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | { |
53 | 53 | // add attribute for edit component |
54 | 54 | $editComponentAttrs = $this->_searchEditComponent($content); |
55 | - if(is_array($editComponentAttrs)) |
|
55 | + if (is_array($editComponentAttrs)) |
|
56 | 56 | { |
57 | - foreach($editComponentAttrs AS $k => $v) |
|
57 | + foreach ($editComponentAttrs AS $k => $v) |
|
58 | 58 | { |
59 | 59 | $this->_def->addAttribute('img', $v, 'CDATA'); |
60 | 60 | $this->_def->addAttribute('div', $v, 'CDATA'); |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | |
64 | 64 | // add attribute for widget component |
65 | 65 | $widgetAttrs = $this->_searchWidget($content); |
66 | - if(is_array($widgetAttrs)) |
|
66 | + if (is_array($widgetAttrs)) |
|
67 | 67 | { |
68 | - foreach($widgetAttrs AS $k => $v) |
|
68 | + foreach ($widgetAttrs AS $k => $v) |
|
69 | 69 | { |
70 | 70 | $this->_def->addAttribute('img', $v, 'CDATA'); |
71 | 71 | } |
@@ -82,19 +82,19 @@ discard block |
||
82 | 82 | preg_match_all('!<(?:(div)|img)([^>]*)editor_component=([^>]*)>(?(1)(.*?)</div>)!is', $content, $m); |
83 | 83 | |
84 | 84 | $attributeList = array(); |
85 | - if(is_array($m[2])) |
|
85 | + if (is_array($m[2])) |
|
86 | 86 | { |
87 | - foreach($m[2] as $key => $value) |
|
87 | + foreach ($m[2] as $key => $value) |
|
88 | 88 | { |
89 | 89 | unset($script, $m2); |
90 | 90 | $script = " {$m[2][$key]} editor_component={$m[3][$key]}"; |
91 | 91 | |
92 | - if(preg_match_all('/([a-z0-9_-]+)="([^"]+)"/is', $script, $m2)) |
|
92 | + if (preg_match_all('/([a-z0-9_-]+)="([^"]+)"/is', $script, $m2)) |
|
93 | 93 | { |
94 | - foreach($m2[1] as $value2) |
|
94 | + foreach ($m2[1] as $value2) |
|
95 | 95 | { |
96 | 96 | //SECISSUE check style attr |
97 | - if($value2 == 'style') |
|
97 | + if ($value2 == 'style') |
|
98 | 98 | { |
99 | 99 | continue; |
100 | 100 | } |
@@ -117,18 +117,18 @@ discard block |
||
117 | 117 | preg_match_all('!<(?:(div)|img)([^>]*)class="zbxe_widget_output"([^>]*)>(?(1)(.*?)</div>)!is', $content, $m); |
118 | 118 | |
119 | 119 | $attributeList = array(); |
120 | - if(is_array($m[3])) |
|
120 | + if (is_array($m[3])) |
|
121 | 121 | { |
122 | 122 | $content = str_replace('<img class="zbxe_widget_output"', '<img src="" class="zbxe_widget_output"', $content); |
123 | 123 | |
124 | - foreach($m[3] as $key => $value) |
|
124 | + foreach ($m[3] as $key => $value) |
|
125 | 125 | { |
126 | 126 | if (preg_match_all('/([a-z0-9_-]+)="([^"]+)"/is', $m[3][$key], $m2)) |
127 | 127 | { |
128 | - foreach($m2[1] as $value2) |
|
128 | + foreach ($m2[1] as $value2) |
|
129 | 129 | { |
130 | 130 | //SECISSUE check style attr |
131 | - if($value2 == 'style') |
|
131 | + if ($value2 == 'style') |
|
132 | 132 | { |
133 | 133 | continue; |
134 | 134 | } |
@@ -149,14 +149,14 @@ discard block |
||
149 | 149 | $whiteDomainRegex = '%^('; |
150 | 150 | $whiteDomainCount = count($whiteIframeUrlList); |
151 | 151 | |
152 | - $i=1; |
|
153 | - if(is_array($whiteIframeUrlList)) |
|
152 | + $i = 1; |
|
153 | + if (is_array($whiteIframeUrlList)) |
|
154 | 154 | { |
155 | - foreach($whiteIframeUrlList as $value) |
|
155 | + foreach ($whiteIframeUrlList as $value) |
|
156 | 156 | { |
157 | 157 | $whiteDomainRegex .= $value; |
158 | 158 | |
159 | - if($i < $whiteDomainCount) |
|
159 | + if ($i < $whiteDomainCount) |
|
160 | 160 | { |
161 | 161 | $whiteDomainRegex .= '|'; |
162 | 162 | } |
@@ -7,20 +7,20 @@ |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if (function_exists('spl_autoload_register') && function_exists('spl_autoload_unregister')) { |
10 | - // We need unregister for our pre-registering functionality |
|
11 | - HTMLPurifier_Bootstrap::registerAutoload(); |
|
12 | - if (function_exists('__autoload')) { |
|
13 | - // Be polite and ensure that userland autoload gets retained |
|
14 | - spl_autoload_register('__autoload'); |
|
15 | - } |
|
10 | + // We need unregister for our pre-registering functionality |
|
11 | + HTMLPurifier_Bootstrap::registerAutoload(); |
|
12 | + if (function_exists('__autoload')) { |
|
13 | + // Be polite and ensure that userland autoload gets retained |
|
14 | + spl_autoload_register('__autoload'); |
|
15 | + } |
|
16 | 16 | } elseif (!function_exists('__autoload')) { |
17 | - function __autoload($class) { |
|
18 | - return HTMLPurifier_Bootstrap::autoload($class); |
|
19 | - } |
|
17 | + function __autoload($class) { |
|
18 | + return HTMLPurifier_Bootstrap::autoload($class); |
|
19 | + } |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | if (ini_get('zend.ze1_compatibility_mode')) { |
23 | - trigger_error("HTML Purifier is not compatible with zend.ze1_compatibility_mode; please turn it off", E_USER_ERROR); |
|
23 | + trigger_error("HTML Purifier is not compatible with zend.ze1_compatibility_mode; please turn it off", E_USER_ERROR); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | // vim: et sw=4 sts=4 |
@@ -13,11 +13,11 @@ |
||
13 | 13 | * HTMLPurifier_Config::create() |
14 | 14 | */ |
15 | 15 | function HTMLPurifier($html, $config = null) { |
16 | - static $purifier = false; |
|
17 | - if (!$purifier) { |
|
18 | - $purifier = new HTMLPurifier(); |
|
19 | - } |
|
20 | - return $purifier->purify($html, $config); |
|
16 | + static $purifier = false; |
|
17 | + if (!$purifier) { |
|
18 | + $purifier = new HTMLPurifier(); |
|
19 | + } |
|
20 | + return $purifier->purify($html, $config); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | // vim: et sw=4 sts=4 |
@@ -8,23 +8,23 @@ |
||
8 | 8 | require_once dirname(__FILE__) . '/HTMLPurifier.auto.php'; |
9 | 9 | |
10 | 10 | function kses($string, $allowed_html, $allowed_protocols = null) { |
11 | - $config = HTMLPurifier_Config::createDefault(); |
|
12 | - $allowed_elements = array(); |
|
13 | - $allowed_attributes = array(); |
|
14 | - foreach ($allowed_html as $element => $attributes) { |
|
15 | - $allowed_elements[$element] = true; |
|
16 | - foreach ($attributes as $attribute => $x) { |
|
17 | - $allowed_attributes["$element.$attribute"] = true; |
|
18 | - } |
|
19 | - } |
|
20 | - $config->set('HTML.AllowedElements', $allowed_elements); |
|
21 | - $config->set('HTML.AllowedAttributes', $allowed_attributes); |
|
22 | - $allowed_schemes = array(); |
|
23 | - if ($allowed_protocols !== null) { |
|
24 | - $config->set('URI.AllowedSchemes', $allowed_protocols); |
|
25 | - } |
|
26 | - $purifier = new HTMLPurifier($config); |
|
27 | - return $purifier->purify($string); |
|
11 | + $config = HTMLPurifier_Config::createDefault(); |
|
12 | + $allowed_elements = array(); |
|
13 | + $allowed_attributes = array(); |
|
14 | + foreach ($allowed_html as $element => $attributes) { |
|
15 | + $allowed_elements[$element] = true; |
|
16 | + foreach ($attributes as $attribute => $x) { |
|
17 | + $allowed_attributes["$element.$attribute"] = true; |
|
18 | + } |
|
19 | + } |
|
20 | + $config->set('HTML.AllowedElements', $allowed_elements); |
|
21 | + $config->set('HTML.AllowedAttributes', $allowed_attributes); |
|
22 | + $allowed_schemes = array(); |
|
23 | + if ($allowed_protocols !== null) { |
|
24 | + $config->set('URI.AllowedSchemes', $allowed_protocols); |
|
25 | + } |
|
26 | + $purifier = new HTMLPurifier($config); |
|
27 | + return $purifier->purify($string); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | // vim: et sw=4 sts=4 |
@@ -6,6 +6,6 @@ |
||
6 | 6 | * without any other side-effects. |
7 | 7 | */ |
8 | 8 | |
9 | -set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path() ); |
|
9 | +set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path()); |
|
10 | 10 | |
11 | 11 | // vim: et sw=4 sts=4 |
@@ -54,183 +54,183 @@ |
||
54 | 54 | class HTMLPurifier |
55 | 55 | { |
56 | 56 | |
57 | - /** Version of HTML Purifier */ |
|
58 | - public $version = '4.4.0'; |
|
59 | - |
|
60 | - /** Constant with version of HTML Purifier */ |
|
61 | - const VERSION = '4.4.0'; |
|
62 | - |
|
63 | - /** Global configuration object */ |
|
64 | - public $config; |
|
65 | - |
|
66 | - /** Array of extra HTMLPurifier_Filter objects to run on HTML, for backwards compatibility */ |
|
67 | - private $filters = array(); |
|
68 | - |
|
69 | - /** Single instance of HTML Purifier */ |
|
70 | - private static $instance; |
|
71 | - |
|
72 | - protected $strategy, $generator; |
|
73 | - |
|
74 | - /** |
|
75 | - * Resultant HTMLPurifier_Context of last run purification. Is an array |
|
76 | - * of contexts if the last called method was purifyArray(). |
|
77 | - */ |
|
78 | - public $context; |
|
79 | - |
|
80 | - /** |
|
81 | - * Initializes the purifier. |
|
82 | - * @param $config Optional HTMLPurifier_Config object for all instances of |
|
83 | - * the purifier, if omitted, a default configuration is |
|
84 | - * supplied (which can be overridden on a per-use basis). |
|
85 | - * The parameter can also be any type that |
|
86 | - * HTMLPurifier_Config::create() supports. |
|
87 | - */ |
|
88 | - public function __construct($config = null) { |
|
89 | - |
|
90 | - $this->config = HTMLPurifier_Config::create($config); |
|
91 | - |
|
92 | - $this->strategy = new HTMLPurifier_Strategy_Core(); |
|
93 | - |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Adds a filter to process the output. First come first serve |
|
98 | - * @param $filter HTMLPurifier_Filter object |
|
99 | - */ |
|
100 | - public function addFilter($filter) { |
|
101 | - trigger_error('HTMLPurifier->addFilter() is deprecated, use configuration directives in the Filter namespace or Filter.Custom', E_USER_WARNING); |
|
102 | - $this->filters[] = $filter; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Filters an HTML snippet/document to be XSS-free and standards-compliant. |
|
107 | - * |
|
108 | - * @param $html String of HTML to purify |
|
109 | - * @param $config HTMLPurifier_Config object for this operation, if omitted, |
|
110 | - * defaults to the config object specified during this |
|
111 | - * object's construction. The parameter can also be any type |
|
112 | - * that HTMLPurifier_Config::create() supports. |
|
113 | - * @return Purified HTML |
|
114 | - */ |
|
115 | - public function purify($html, $config = null) { |
|
116 | - |
|
117 | - // :TODO: make the config merge in, instead of replace |
|
118 | - $config = $config ? HTMLPurifier_Config::create($config) : $this->config; |
|
119 | - |
|
120 | - // implementation is partially environment dependant, partially |
|
121 | - // configuration dependant |
|
122 | - $lexer = HTMLPurifier_Lexer::create($config); |
|
123 | - |
|
124 | - $context = new HTMLPurifier_Context(); |
|
125 | - |
|
126 | - // setup HTML generator |
|
127 | - $this->generator = new HTMLPurifier_Generator($config, $context); |
|
128 | - $context->register('Generator', $this->generator); |
|
129 | - |
|
130 | - // set up global context variables |
|
131 | - if ($config->get('Core.CollectErrors')) { |
|
132 | - // may get moved out if other facilities use it |
|
133 | - $language_factory = HTMLPurifier_LanguageFactory::instance(); |
|
134 | - $language = $language_factory->create($config, $context); |
|
135 | - $context->register('Locale', $language); |
|
136 | - |
|
137 | - $error_collector = new HTMLPurifier_ErrorCollector($context); |
|
138 | - $context->register('ErrorCollector', $error_collector); |
|
139 | - } |
|
140 | - |
|
141 | - // setup id_accumulator context, necessary due to the fact that |
|
142 | - // AttrValidator can be called from many places |
|
143 | - $id_accumulator = HTMLPurifier_IDAccumulator::build($config, $context); |
|
144 | - $context->register('IDAccumulator', $id_accumulator); |
|
145 | - |
|
146 | - $html = HTMLPurifier_Encoder::convertToUTF8($html, $config, $context); |
|
147 | - |
|
148 | - // setup filters |
|
149 | - $filter_flags = $config->getBatch('Filter'); |
|
150 | - $custom_filters = $filter_flags['Custom']; |
|
151 | - unset($filter_flags['Custom']); |
|
152 | - $filters = array(); |
|
153 | - foreach ($filter_flags as $filter => $flag) { |
|
154 | - if (!$flag) continue; |
|
155 | - if (strpos($filter, '.') !== false) continue; |
|
156 | - $class = "HTMLPurifier_Filter_$filter"; |
|
157 | - $filters[] = new $class; |
|
158 | - } |
|
159 | - foreach ($custom_filters as $filter) { |
|
160 | - // maybe "HTMLPurifier_Filter_$filter", but be consistent with AutoFormat |
|
161 | - $filters[] = $filter; |
|
162 | - } |
|
163 | - $filters = array_merge($filters, $this->filters); |
|
164 | - // maybe prepare(), but later |
|
165 | - |
|
166 | - for ($i = 0, $filter_size = count($filters); $i < $filter_size; $i++) { |
|
167 | - $html = $filters[$i]->preFilter($html, $config, $context); |
|
168 | - } |
|
169 | - |
|
170 | - // purified HTML |
|
171 | - $html = |
|
172 | - $this->generator->generateFromTokens( |
|
173 | - // list of tokens |
|
174 | - $this->strategy->execute( |
|
175 | - // list of un-purified tokens |
|
176 | - $lexer->tokenizeHTML( |
|
177 | - // un-purified HTML |
|
178 | - $html, $config, $context |
|
179 | - ), |
|
180 | - $config, $context |
|
181 | - ) |
|
182 | - ); |
|
183 | - |
|
184 | - for ($i = $filter_size - 1; $i >= 0; $i--) { |
|
185 | - $html = $filters[$i]->postFilter($html, $config, $context); |
|
186 | - } |
|
187 | - |
|
188 | - $html = HTMLPurifier_Encoder::convertFromUTF8($html, $config, $context); |
|
189 | - $this->context =& $context; |
|
190 | - return $html; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Filters an array of HTML snippets |
|
195 | - * @param $config Optional HTMLPurifier_Config object for this operation. |
|
196 | - * See HTMLPurifier::purify() for more details. |
|
197 | - * @return Array of purified HTML |
|
198 | - */ |
|
199 | - public function purifyArray($array_of_html, $config = null) { |
|
200 | - $context_array = array(); |
|
201 | - foreach ($array_of_html as $key => $html) { |
|
202 | - $array_of_html[$key] = $this->purify($html, $config); |
|
203 | - $context_array[$key] = $this->context; |
|
204 | - } |
|
205 | - $this->context = $context_array; |
|
206 | - return $array_of_html; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Singleton for enforcing just one HTML Purifier in your system |
|
211 | - * @param $prototype Optional prototype HTMLPurifier instance to |
|
212 | - * overload singleton with, or HTMLPurifier_Config |
|
213 | - * instance to configure the generated version with. |
|
214 | - */ |
|
215 | - public static function instance($prototype = null) { |
|
216 | - if (!self::$instance || $prototype) { |
|
217 | - if ($prototype instanceof HTMLPurifier) { |
|
218 | - self::$instance = $prototype; |
|
219 | - } elseif ($prototype) { |
|
220 | - self::$instance = new HTMLPurifier($prototype); |
|
221 | - } else { |
|
222 | - self::$instance = new HTMLPurifier(); |
|
223 | - } |
|
224 | - } |
|
225 | - return self::$instance; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @note Backwards compatibility, see instance() |
|
230 | - */ |
|
231 | - public static function getInstance($prototype = null) { |
|
232 | - return HTMLPurifier::instance($prototype); |
|
233 | - } |
|
57 | + /** Version of HTML Purifier */ |
|
58 | + public $version = '4.4.0'; |
|
59 | + |
|
60 | + /** Constant with version of HTML Purifier */ |
|
61 | + const VERSION = '4.4.0'; |
|
62 | + |
|
63 | + /** Global configuration object */ |
|
64 | + public $config; |
|
65 | + |
|
66 | + /** Array of extra HTMLPurifier_Filter objects to run on HTML, for backwards compatibility */ |
|
67 | + private $filters = array(); |
|
68 | + |
|
69 | + /** Single instance of HTML Purifier */ |
|
70 | + private static $instance; |
|
71 | + |
|
72 | + protected $strategy, $generator; |
|
73 | + |
|
74 | + /** |
|
75 | + * Resultant HTMLPurifier_Context of last run purification. Is an array |
|
76 | + * of contexts if the last called method was purifyArray(). |
|
77 | + */ |
|
78 | + public $context; |
|
79 | + |
|
80 | + /** |
|
81 | + * Initializes the purifier. |
|
82 | + * @param $config Optional HTMLPurifier_Config object for all instances of |
|
83 | + * the purifier, if omitted, a default configuration is |
|
84 | + * supplied (which can be overridden on a per-use basis). |
|
85 | + * The parameter can also be any type that |
|
86 | + * HTMLPurifier_Config::create() supports. |
|
87 | + */ |
|
88 | + public function __construct($config = null) { |
|
89 | + |
|
90 | + $this->config = HTMLPurifier_Config::create($config); |
|
91 | + |
|
92 | + $this->strategy = new HTMLPurifier_Strategy_Core(); |
|
93 | + |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Adds a filter to process the output. First come first serve |
|
98 | + * @param $filter HTMLPurifier_Filter object |
|
99 | + */ |
|
100 | + public function addFilter($filter) { |
|
101 | + trigger_error('HTMLPurifier->addFilter() is deprecated, use configuration directives in the Filter namespace or Filter.Custom', E_USER_WARNING); |
|
102 | + $this->filters[] = $filter; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Filters an HTML snippet/document to be XSS-free and standards-compliant. |
|
107 | + * |
|
108 | + * @param $html String of HTML to purify |
|
109 | + * @param $config HTMLPurifier_Config object for this operation, if omitted, |
|
110 | + * defaults to the config object specified during this |
|
111 | + * object's construction. The parameter can also be any type |
|
112 | + * that HTMLPurifier_Config::create() supports. |
|
113 | + * @return Purified HTML |
|
114 | + */ |
|
115 | + public function purify($html, $config = null) { |
|
116 | + |
|
117 | + // :TODO: make the config merge in, instead of replace |
|
118 | + $config = $config ? HTMLPurifier_Config::create($config) : $this->config; |
|
119 | + |
|
120 | + // implementation is partially environment dependant, partially |
|
121 | + // configuration dependant |
|
122 | + $lexer = HTMLPurifier_Lexer::create($config); |
|
123 | + |
|
124 | + $context = new HTMLPurifier_Context(); |
|
125 | + |
|
126 | + // setup HTML generator |
|
127 | + $this->generator = new HTMLPurifier_Generator($config, $context); |
|
128 | + $context->register('Generator', $this->generator); |
|
129 | + |
|
130 | + // set up global context variables |
|
131 | + if ($config->get('Core.CollectErrors')) { |
|
132 | + // may get moved out if other facilities use it |
|
133 | + $language_factory = HTMLPurifier_LanguageFactory::instance(); |
|
134 | + $language = $language_factory->create($config, $context); |
|
135 | + $context->register('Locale', $language); |
|
136 | + |
|
137 | + $error_collector = new HTMLPurifier_ErrorCollector($context); |
|
138 | + $context->register('ErrorCollector', $error_collector); |
|
139 | + } |
|
140 | + |
|
141 | + // setup id_accumulator context, necessary due to the fact that |
|
142 | + // AttrValidator can be called from many places |
|
143 | + $id_accumulator = HTMLPurifier_IDAccumulator::build($config, $context); |
|
144 | + $context->register('IDAccumulator', $id_accumulator); |
|
145 | + |
|
146 | + $html = HTMLPurifier_Encoder::convertToUTF8($html, $config, $context); |
|
147 | + |
|
148 | + // setup filters |
|
149 | + $filter_flags = $config->getBatch('Filter'); |
|
150 | + $custom_filters = $filter_flags['Custom']; |
|
151 | + unset($filter_flags['Custom']); |
|
152 | + $filters = array(); |
|
153 | + foreach ($filter_flags as $filter => $flag) { |
|
154 | + if (!$flag) continue; |
|
155 | + if (strpos($filter, '.') !== false) continue; |
|
156 | + $class = "HTMLPurifier_Filter_$filter"; |
|
157 | + $filters[] = new $class; |
|
158 | + } |
|
159 | + foreach ($custom_filters as $filter) { |
|
160 | + // maybe "HTMLPurifier_Filter_$filter", but be consistent with AutoFormat |
|
161 | + $filters[] = $filter; |
|
162 | + } |
|
163 | + $filters = array_merge($filters, $this->filters); |
|
164 | + // maybe prepare(), but later |
|
165 | + |
|
166 | + for ($i = 0, $filter_size = count($filters); $i < $filter_size; $i++) { |
|
167 | + $html = $filters[$i]->preFilter($html, $config, $context); |
|
168 | + } |
|
169 | + |
|
170 | + // purified HTML |
|
171 | + $html = |
|
172 | + $this->generator->generateFromTokens( |
|
173 | + // list of tokens |
|
174 | + $this->strategy->execute( |
|
175 | + // list of un-purified tokens |
|
176 | + $lexer->tokenizeHTML( |
|
177 | + // un-purified HTML |
|
178 | + $html, $config, $context |
|
179 | + ), |
|
180 | + $config, $context |
|
181 | + ) |
|
182 | + ); |
|
183 | + |
|
184 | + for ($i = $filter_size - 1; $i >= 0; $i--) { |
|
185 | + $html = $filters[$i]->postFilter($html, $config, $context); |
|
186 | + } |
|
187 | + |
|
188 | + $html = HTMLPurifier_Encoder::convertFromUTF8($html, $config, $context); |
|
189 | + $this->context =& $context; |
|
190 | + return $html; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Filters an array of HTML snippets |
|
195 | + * @param $config Optional HTMLPurifier_Config object for this operation. |
|
196 | + * See HTMLPurifier::purify() for more details. |
|
197 | + * @return Array of purified HTML |
|
198 | + */ |
|
199 | + public function purifyArray($array_of_html, $config = null) { |
|
200 | + $context_array = array(); |
|
201 | + foreach ($array_of_html as $key => $html) { |
|
202 | + $array_of_html[$key] = $this->purify($html, $config); |
|
203 | + $context_array[$key] = $this->context; |
|
204 | + } |
|
205 | + $this->context = $context_array; |
|
206 | + return $array_of_html; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Singleton for enforcing just one HTML Purifier in your system |
|
211 | + * @param $prototype Optional prototype HTMLPurifier instance to |
|
212 | + * overload singleton with, or HTMLPurifier_Config |
|
213 | + * instance to configure the generated version with. |
|
214 | + */ |
|
215 | + public static function instance($prototype = null) { |
|
216 | + if (!self::$instance || $prototype) { |
|
217 | + if ($prototype instanceof HTMLPurifier) { |
|
218 | + self::$instance = $prototype; |
|
219 | + } elseif ($prototype) { |
|
220 | + self::$instance = new HTMLPurifier($prototype); |
|
221 | + } else { |
|
222 | + self::$instance = new HTMLPurifier(); |
|
223 | + } |
|
224 | + } |
|
225 | + return self::$instance; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @note Backwards compatibility, see instance() |
|
230 | + */ |
|
231 | + public static function getInstance($prototype = null) { |
|
232 | + return HTMLPurifier::instance($prototype); |
|
233 | + } |
|
234 | 234 | |
235 | 235 | } |
236 | 236 |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | |
90 | 90 | $this->config = HTMLPurifier_Config::create($config); |
91 | 91 | |
92 | - $this->strategy = new HTMLPurifier_Strategy_Core(); |
|
92 | + $this->strategy = new HTMLPurifier_Strategy_Core(); |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | } |
187 | 187 | |
188 | 188 | $html = HTMLPurifier_Encoder::convertFromUTF8($html, $config, $context); |
189 | - $this->context =& $context; |
|
189 | + $this->context = & $context; |
|
190 | 190 | return $html; |
191 | 191 | } |
192 | 192 |
@@ -151,8 +151,12 @@ |
||
151 | 151 | unset($filter_flags['Custom']); |
152 | 152 | $filters = array(); |
153 | 153 | foreach ($filter_flags as $filter => $flag) { |
154 | - if (!$flag) continue; |
|
155 | - if (strpos($filter, '.') !== false) continue; |
|
154 | + if (!$flag) { |
|
155 | + continue; |
|
156 | + } |
|
157 | + if (strpos($filter, '.') !== false) { |
|
158 | + continue; |
|
159 | + } |
|
156 | 160 | $class = "HTMLPurifier_Filter_$filter"; |
157 | 161 | $filters[] = new $class; |
158 | 162 | } |
@@ -7,121 +7,121 @@ |
||
7 | 7 | class HTMLPurifier_AttrCollections |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * Associative array of attribute collections, indexed by name |
|
12 | - */ |
|
13 | - public $info = array(); |
|
14 | - |
|
15 | - /** |
|
16 | - * Performs all expansions on internal data for use by other inclusions |
|
17 | - * It also collects all attribute collection extensions from |
|
18 | - * modules |
|
19 | - * @param $attr_types HTMLPurifier_AttrTypes instance |
|
20 | - * @param $modules Hash array of HTMLPurifier_HTMLModule members |
|
21 | - */ |
|
22 | - public function __construct($attr_types, $modules) { |
|
23 | - // load extensions from the modules |
|
24 | - foreach ($modules as $module) { |
|
25 | - foreach ($module->attr_collections as $coll_i => $coll) { |
|
26 | - if (!isset($this->info[$coll_i])) { |
|
27 | - $this->info[$coll_i] = array(); |
|
28 | - } |
|
29 | - foreach ($coll as $attr_i => $attr) { |
|
30 | - if ($attr_i === 0 && isset($this->info[$coll_i][$attr_i])) { |
|
31 | - // merge in includes |
|
32 | - $this->info[$coll_i][$attr_i] = array_merge( |
|
33 | - $this->info[$coll_i][$attr_i], $attr); |
|
34 | - continue; |
|
35 | - } |
|
36 | - $this->info[$coll_i][$attr_i] = $attr; |
|
37 | - } |
|
38 | - } |
|
39 | - } |
|
40 | - // perform internal expansions and inclusions |
|
41 | - foreach ($this->info as $name => $attr) { |
|
42 | - // merge attribute collections that include others |
|
43 | - $this->performInclusions($this->info[$name]); |
|
44 | - // replace string identifiers with actual attribute objects |
|
45 | - $this->expandIdentifiers($this->info[$name], $attr_types); |
|
46 | - } |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Takes a reference to an attribute associative array and performs |
|
51 | - * all inclusions specified by the zero index. |
|
52 | - * @param &$attr Reference to attribute array |
|
53 | - */ |
|
54 | - public function performInclusions(&$attr) { |
|
55 | - if (!isset($attr[0])) return; |
|
56 | - $merge = $attr[0]; |
|
57 | - $seen = array(); // recursion guard |
|
58 | - // loop through all the inclusions |
|
59 | - for ($i = 0; isset($merge[$i]); $i++) { |
|
60 | - if (isset($seen[$merge[$i]])) continue; |
|
61 | - $seen[$merge[$i]] = true; |
|
62 | - // foreach attribute of the inclusion, copy it over |
|
63 | - if (!isset($this->info[$merge[$i]])) continue; |
|
64 | - foreach ($this->info[$merge[$i]] as $key => $value) { |
|
65 | - if (isset($attr[$key])) continue; // also catches more inclusions |
|
66 | - $attr[$key] = $value; |
|
67 | - } |
|
68 | - if (isset($this->info[$merge[$i]][0])) { |
|
69 | - // recursion |
|
70 | - $merge = array_merge($merge, $this->info[$merge[$i]][0]); |
|
71 | - } |
|
72 | - } |
|
73 | - unset($attr[0]); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Expands all string identifiers in an attribute array by replacing |
|
78 | - * them with the appropriate values inside HTMLPurifier_AttrTypes |
|
79 | - * @param &$attr Reference to attribute array |
|
80 | - * @param $attr_types HTMLPurifier_AttrTypes instance |
|
81 | - */ |
|
82 | - public function expandIdentifiers(&$attr, $attr_types) { |
|
83 | - |
|
84 | - // because foreach will process new elements we add, make sure we |
|
85 | - // skip duplicates |
|
86 | - $processed = array(); |
|
87 | - |
|
88 | - foreach ($attr as $def_i => $def) { |
|
89 | - // skip inclusions |
|
90 | - if ($def_i === 0) continue; |
|
91 | - |
|
92 | - if (isset($processed[$def_i])) continue; |
|
93 | - |
|
94 | - // determine whether or not attribute is required |
|
95 | - if ($required = (strpos($def_i, '*') !== false)) { |
|
96 | - // rename the definition |
|
97 | - unset($attr[$def_i]); |
|
98 | - $def_i = trim($def_i, '*'); |
|
99 | - $attr[$def_i] = $def; |
|
100 | - } |
|
101 | - |
|
102 | - $processed[$def_i] = true; |
|
103 | - |
|
104 | - // if we've already got a literal object, move on |
|
105 | - if (is_object($def)) { |
|
106 | - // preserve previous required |
|
107 | - $attr[$def_i]->required = ($required || $attr[$def_i]->required); |
|
108 | - continue; |
|
109 | - } |
|
110 | - |
|
111 | - if ($def === false) { |
|
112 | - unset($attr[$def_i]); |
|
113 | - continue; |
|
114 | - } |
|
115 | - |
|
116 | - if ($t = $attr_types->get($def)) { |
|
117 | - $attr[$def_i] = $t; |
|
118 | - $attr[$def_i]->required = $required; |
|
119 | - } else { |
|
120 | - unset($attr[$def_i]); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - } |
|
10 | + /** |
|
11 | + * Associative array of attribute collections, indexed by name |
|
12 | + */ |
|
13 | + public $info = array(); |
|
14 | + |
|
15 | + /** |
|
16 | + * Performs all expansions on internal data for use by other inclusions |
|
17 | + * It also collects all attribute collection extensions from |
|
18 | + * modules |
|
19 | + * @param $attr_types HTMLPurifier_AttrTypes instance |
|
20 | + * @param $modules Hash array of HTMLPurifier_HTMLModule members |
|
21 | + */ |
|
22 | + public function __construct($attr_types, $modules) { |
|
23 | + // load extensions from the modules |
|
24 | + foreach ($modules as $module) { |
|
25 | + foreach ($module->attr_collections as $coll_i => $coll) { |
|
26 | + if (!isset($this->info[$coll_i])) { |
|
27 | + $this->info[$coll_i] = array(); |
|
28 | + } |
|
29 | + foreach ($coll as $attr_i => $attr) { |
|
30 | + if ($attr_i === 0 && isset($this->info[$coll_i][$attr_i])) { |
|
31 | + // merge in includes |
|
32 | + $this->info[$coll_i][$attr_i] = array_merge( |
|
33 | + $this->info[$coll_i][$attr_i], $attr); |
|
34 | + continue; |
|
35 | + } |
|
36 | + $this->info[$coll_i][$attr_i] = $attr; |
|
37 | + } |
|
38 | + } |
|
39 | + } |
|
40 | + // perform internal expansions and inclusions |
|
41 | + foreach ($this->info as $name => $attr) { |
|
42 | + // merge attribute collections that include others |
|
43 | + $this->performInclusions($this->info[$name]); |
|
44 | + // replace string identifiers with actual attribute objects |
|
45 | + $this->expandIdentifiers($this->info[$name], $attr_types); |
|
46 | + } |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Takes a reference to an attribute associative array and performs |
|
51 | + * all inclusions specified by the zero index. |
|
52 | + * @param &$attr Reference to attribute array |
|
53 | + */ |
|
54 | + public function performInclusions(&$attr) { |
|
55 | + if (!isset($attr[0])) return; |
|
56 | + $merge = $attr[0]; |
|
57 | + $seen = array(); // recursion guard |
|
58 | + // loop through all the inclusions |
|
59 | + for ($i = 0; isset($merge[$i]); $i++) { |
|
60 | + if (isset($seen[$merge[$i]])) continue; |
|
61 | + $seen[$merge[$i]] = true; |
|
62 | + // foreach attribute of the inclusion, copy it over |
|
63 | + if (!isset($this->info[$merge[$i]])) continue; |
|
64 | + foreach ($this->info[$merge[$i]] as $key => $value) { |
|
65 | + if (isset($attr[$key])) continue; // also catches more inclusions |
|
66 | + $attr[$key] = $value; |
|
67 | + } |
|
68 | + if (isset($this->info[$merge[$i]][0])) { |
|
69 | + // recursion |
|
70 | + $merge = array_merge($merge, $this->info[$merge[$i]][0]); |
|
71 | + } |
|
72 | + } |
|
73 | + unset($attr[0]); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Expands all string identifiers in an attribute array by replacing |
|
78 | + * them with the appropriate values inside HTMLPurifier_AttrTypes |
|
79 | + * @param &$attr Reference to attribute array |
|
80 | + * @param $attr_types HTMLPurifier_AttrTypes instance |
|
81 | + */ |
|
82 | + public function expandIdentifiers(&$attr, $attr_types) { |
|
83 | + |
|
84 | + // because foreach will process new elements we add, make sure we |
|
85 | + // skip duplicates |
|
86 | + $processed = array(); |
|
87 | + |
|
88 | + foreach ($attr as $def_i => $def) { |
|
89 | + // skip inclusions |
|
90 | + if ($def_i === 0) continue; |
|
91 | + |
|
92 | + if (isset($processed[$def_i])) continue; |
|
93 | + |
|
94 | + // determine whether or not attribute is required |
|
95 | + if ($required = (strpos($def_i, '*') !== false)) { |
|
96 | + // rename the definition |
|
97 | + unset($attr[$def_i]); |
|
98 | + $def_i = trim($def_i, '*'); |
|
99 | + $attr[$def_i] = $def; |
|
100 | + } |
|
101 | + |
|
102 | + $processed[$def_i] = true; |
|
103 | + |
|
104 | + // if we've already got a literal object, move on |
|
105 | + if (is_object($def)) { |
|
106 | + // preserve previous required |
|
107 | + $attr[$def_i]->required = ($required || $attr[$def_i]->required); |
|
108 | + continue; |
|
109 | + } |
|
110 | + |
|
111 | + if ($def === false) { |
|
112 | + unset($attr[$def_i]); |
|
113 | + continue; |
|
114 | + } |
|
115 | + |
|
116 | + if ($t = $attr_types->get($def)) { |
|
117 | + $attr[$def_i] = $t; |
|
118 | + $attr[$def_i]->required = $required; |
|
119 | + } else { |
|
120 | + unset($attr[$def_i]); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + } |
|
125 | 125 | |
126 | 126 | } |
127 | 127 |
@@ -52,17 +52,26 @@ discard block |
||
52 | 52 | * @param &$attr Reference to attribute array |
53 | 53 | */ |
54 | 54 | public function performInclusions(&$attr) { |
55 | - if (!isset($attr[0])) return; |
|
55 | + if (!isset($attr[0])) { |
|
56 | + return; |
|
57 | + } |
|
56 | 58 | $merge = $attr[0]; |
57 | 59 | $seen = array(); // recursion guard |
58 | 60 | // loop through all the inclusions |
59 | 61 | for ($i = 0; isset($merge[$i]); $i++) { |
60 | - if (isset($seen[$merge[$i]])) continue; |
|
62 | + if (isset($seen[$merge[$i]])) { |
|
63 | + continue; |
|
64 | + } |
|
61 | 65 | $seen[$merge[$i]] = true; |
62 | 66 | // foreach attribute of the inclusion, copy it over |
63 | - if (!isset($this->info[$merge[$i]])) continue; |
|
67 | + if (!isset($this->info[$merge[$i]])) { |
|
68 | + continue; |
|
69 | + } |
|
64 | 70 | foreach ($this->info[$merge[$i]] as $key => $value) { |
65 | - if (isset($attr[$key])) continue; // also catches more inclusions |
|
71 | + if (isset($attr[$key])) { |
|
72 | + continue; |
|
73 | + } |
|
74 | + // also catches more inclusions |
|
66 | 75 | $attr[$key] = $value; |
67 | 76 | } |
68 | 77 | if (isset($this->info[$merge[$i]][0])) { |
@@ -87,9 +96,13 @@ discard block |
||
87 | 96 | |
88 | 97 | foreach ($attr as $def_i => $def) { |
89 | 98 | // skip inclusions |
90 | - if ($def_i === 0) continue; |
|
99 | + if ($def_i === 0) { |
|
100 | + continue; |
|
101 | + } |
|
91 | 102 | |
92 | - if (isset($processed[$def_i])) continue; |
|
103 | + if (isset($processed[$def_i])) { |
|
104 | + continue; |
|
105 | + } |
|
93 | 106 | |
94 | 107 | // determine whether or not attribute is required |
95 | 108 | if ($required = (strpos($def_i, '*') !== false)) { |
@@ -13,110 +13,110 @@ |
||
13 | 13 | abstract class HTMLPurifier_AttrDef |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Tells us whether or not an HTML attribute is minimized. Has no |
|
18 | - * meaning in other contexts. |
|
19 | - */ |
|
20 | - public $minimized = false; |
|
16 | + /** |
|
17 | + * Tells us whether or not an HTML attribute is minimized. Has no |
|
18 | + * meaning in other contexts. |
|
19 | + */ |
|
20 | + public $minimized = false; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Tells us whether or not an HTML attribute is required. Has no |
|
24 | - * meaning in other contexts |
|
25 | - */ |
|
26 | - public $required = false; |
|
22 | + /** |
|
23 | + * Tells us whether or not an HTML attribute is required. Has no |
|
24 | + * meaning in other contexts |
|
25 | + */ |
|
26 | + public $required = false; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Validates and cleans passed string according to a definition. |
|
30 | - * |
|
31 | - * @param $string String to be validated and cleaned. |
|
32 | - * @param $config Mandatory HTMLPurifier_Config object. |
|
33 | - * @param $context Mandatory HTMLPurifier_AttrContext object. |
|
34 | - */ |
|
35 | - abstract public function validate($string, $config, $context); |
|
28 | + /** |
|
29 | + * Validates and cleans passed string according to a definition. |
|
30 | + * |
|
31 | + * @param $string String to be validated and cleaned. |
|
32 | + * @param $config Mandatory HTMLPurifier_Config object. |
|
33 | + * @param $context Mandatory HTMLPurifier_AttrContext object. |
|
34 | + */ |
|
35 | + abstract public function validate($string, $config, $context); |
|
36 | 36 | |
37 | - /** |
|
38 | - * Convenience method that parses a string as if it were CDATA. |
|
39 | - * |
|
40 | - * This method process a string in the manner specified at |
|
41 | - * <http://www.w3.org/TR/html4/types.html#h-6.2> by removing |
|
42 | - * leading and trailing whitespace, ignoring line feeds, and replacing |
|
43 | - * carriage returns and tabs with spaces. While most useful for HTML |
|
44 | - * attributes specified as CDATA, it can also be applied to most CSS |
|
45 | - * values. |
|
46 | - * |
|
47 | - * @note This method is not entirely standards compliant, as trim() removes |
|
48 | - * more types of whitespace than specified in the spec. In practice, |
|
49 | - * this is rarely a problem, as those extra characters usually have |
|
50 | - * already been removed by HTMLPurifier_Encoder. |
|
51 | - * |
|
52 | - * @warning This processing is inconsistent with XML's whitespace handling |
|
53 | - * as specified by section 3.3.3 and referenced XHTML 1.0 section |
|
54 | - * 4.7. However, note that we are NOT necessarily |
|
55 | - * parsing XML, thus, this behavior may still be correct. We |
|
56 | - * assume that newlines have been normalized. |
|
57 | - */ |
|
58 | - public function parseCDATA($string) { |
|
59 | - $string = trim($string); |
|
60 | - $string = str_replace(array("\n", "\t", "\r"), ' ', $string); |
|
61 | - return $string; |
|
62 | - } |
|
37 | + /** |
|
38 | + * Convenience method that parses a string as if it were CDATA. |
|
39 | + * |
|
40 | + * This method process a string in the manner specified at |
|
41 | + * <http://www.w3.org/TR/html4/types.html#h-6.2> by removing |
|
42 | + * leading and trailing whitespace, ignoring line feeds, and replacing |
|
43 | + * carriage returns and tabs with spaces. While most useful for HTML |
|
44 | + * attributes specified as CDATA, it can also be applied to most CSS |
|
45 | + * values. |
|
46 | + * |
|
47 | + * @note This method is not entirely standards compliant, as trim() removes |
|
48 | + * more types of whitespace than specified in the spec. In practice, |
|
49 | + * this is rarely a problem, as those extra characters usually have |
|
50 | + * already been removed by HTMLPurifier_Encoder. |
|
51 | + * |
|
52 | + * @warning This processing is inconsistent with XML's whitespace handling |
|
53 | + * as specified by section 3.3.3 and referenced XHTML 1.0 section |
|
54 | + * 4.7. However, note that we are NOT necessarily |
|
55 | + * parsing XML, thus, this behavior may still be correct. We |
|
56 | + * assume that newlines have been normalized. |
|
57 | + */ |
|
58 | + public function parseCDATA($string) { |
|
59 | + $string = trim($string); |
|
60 | + $string = str_replace(array("\n", "\t", "\r"), ' ', $string); |
|
61 | + return $string; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Factory method for creating this class from a string. |
|
66 | - * @param $string String construction info |
|
67 | - * @return Created AttrDef object corresponding to $string |
|
68 | - */ |
|
69 | - public function make($string) { |
|
70 | - // default implementation, return a flyweight of this object. |
|
71 | - // If $string has an effect on the returned object (i.e. you |
|
72 | - // need to overload this method), it is best |
|
73 | - // to clone or instantiate new copies. (Instantiation is safer.) |
|
74 | - return $this; |
|
75 | - } |
|
64 | + /** |
|
65 | + * Factory method for creating this class from a string. |
|
66 | + * @param $string String construction info |
|
67 | + * @return Created AttrDef object corresponding to $string |
|
68 | + */ |
|
69 | + public function make($string) { |
|
70 | + // default implementation, return a flyweight of this object. |
|
71 | + // If $string has an effect on the returned object (i.e. you |
|
72 | + // need to overload this method), it is best |
|
73 | + // to clone or instantiate new copies. (Instantiation is safer.) |
|
74 | + return $this; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work |
|
79 | - * properly. THIS IS A HACK! |
|
80 | - */ |
|
81 | - protected function mungeRgb($string) { |
|
82 | - return preg_replace('/rgb\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\)/', 'rgb(\1,\2,\3)', $string); |
|
83 | - } |
|
77 | + /** |
|
78 | + * Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work |
|
79 | + * properly. THIS IS A HACK! |
|
80 | + */ |
|
81 | + protected function mungeRgb($string) { |
|
82 | + return preg_replace('/rgb\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\)/', 'rgb(\1,\2,\3)', $string); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Parses a possibly escaped CSS string and returns the "pure" |
|
87 | - * version of it. |
|
88 | - */ |
|
89 | - protected function expandCSSEscape($string) { |
|
90 | - // flexibly parse it |
|
91 | - $ret = ''; |
|
92 | - for ($i = 0, $c = strlen($string); $i < $c; $i++) { |
|
93 | - if ($string[$i] === '\\') { |
|
94 | - $i++; |
|
95 | - if ($i >= $c) { |
|
96 | - $ret .= '\\'; |
|
97 | - break; |
|
98 | - } |
|
99 | - if (ctype_xdigit($string[$i])) { |
|
100 | - $code = $string[$i]; |
|
101 | - for ($a = 1, $i++; $i < $c && $a < 6; $i++, $a++) { |
|
102 | - if (!ctype_xdigit($string[$i])) break; |
|
103 | - $code .= $string[$i]; |
|
104 | - } |
|
105 | - // We have to be extremely careful when adding |
|
106 | - // new characters, to make sure we're not breaking |
|
107 | - // the encoding. |
|
108 | - $char = HTMLPurifier_Encoder::unichr(hexdec($code)); |
|
109 | - if (HTMLPurifier_Encoder::cleanUTF8($char) === '') continue; |
|
110 | - $ret .= $char; |
|
111 | - if ($i < $c && trim($string[$i]) !== '') $i--; |
|
112 | - continue; |
|
113 | - } |
|
114 | - if ($string[$i] === "\n") continue; |
|
115 | - } |
|
116 | - $ret .= $string[$i]; |
|
117 | - } |
|
118 | - return $ret; |
|
119 | - } |
|
85 | + /** |
|
86 | + * Parses a possibly escaped CSS string and returns the "pure" |
|
87 | + * version of it. |
|
88 | + */ |
|
89 | + protected function expandCSSEscape($string) { |
|
90 | + // flexibly parse it |
|
91 | + $ret = ''; |
|
92 | + for ($i = 0, $c = strlen($string); $i < $c; $i++) { |
|
93 | + if ($string[$i] === '\\') { |
|
94 | + $i++; |
|
95 | + if ($i >= $c) { |
|
96 | + $ret .= '\\'; |
|
97 | + break; |
|
98 | + } |
|
99 | + if (ctype_xdigit($string[$i])) { |
|
100 | + $code = $string[$i]; |
|
101 | + for ($a = 1, $i++; $i < $c && $a < 6; $i++, $a++) { |
|
102 | + if (!ctype_xdigit($string[$i])) break; |
|
103 | + $code .= $string[$i]; |
|
104 | + } |
|
105 | + // We have to be extremely careful when adding |
|
106 | + // new characters, to make sure we're not breaking |
|
107 | + // the encoding. |
|
108 | + $char = HTMLPurifier_Encoder::unichr(hexdec($code)); |
|
109 | + if (HTMLPurifier_Encoder::cleanUTF8($char) === '') continue; |
|
110 | + $ret .= $char; |
|
111 | + if ($i < $c && trim($string[$i]) !== '') $i--; |
|
112 | + continue; |
|
113 | + } |
|
114 | + if ($string[$i] === "\n") continue; |
|
115 | + } |
|
116 | + $ret .= $string[$i]; |
|
117 | + } |
|
118 | + return $ret; |
|
119 | + } |
|
120 | 120 | |
121 | 121 | } |
122 | 122 |
@@ -99,19 +99,27 @@ |
||
99 | 99 | if (ctype_xdigit($string[$i])) { |
100 | 100 | $code = $string[$i]; |
101 | 101 | for ($a = 1, $i++; $i < $c && $a < 6; $i++, $a++) { |
102 | - if (!ctype_xdigit($string[$i])) break; |
|
102 | + if (!ctype_xdigit($string[$i])) { |
|
103 | + break; |
|
104 | + } |
|
103 | 105 | $code .= $string[$i]; |
104 | 106 | } |
105 | 107 | // We have to be extremely careful when adding |
106 | 108 | // new characters, to make sure we're not breaking |
107 | 109 | // the encoding. |
108 | 110 | $char = HTMLPurifier_Encoder::unichr(hexdec($code)); |
109 | - if (HTMLPurifier_Encoder::cleanUTF8($char) === '') continue; |
|
111 | + if (HTMLPurifier_Encoder::cleanUTF8($char) === '') { |
|
112 | + continue; |
|
113 | + } |
|
110 | 114 | $ret .= $char; |
111 | - if ($i < $c && trim($string[$i]) !== '') $i--; |
|
115 | + if ($i < $c && trim($string[$i]) !== '') { |
|
116 | + $i--; |
|
117 | + } |
|
112 | 118 | continue; |
113 | 119 | } |
114 | - if ($string[$i] === "\n") continue; |
|
120 | + if ($string[$i] === "\n") { |
|
121 | + continue; |
|
122 | + } |
|
115 | 123 | } |
116 | 124 | $ret .= $string[$i]; |
117 | 125 | } |