@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | |
4 | 4 | $DIR=__DIR__.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR; |
5 | -foreach (array('DOMNodeRecursiveIterator','beforeStrip','prepareStrip','htmlStripHelper','htmlStrip') as $file) { |
|
5 | +foreach (array('DOMNodeRecursiveIterator', 'beforeStrip', 'prepareStrip', 'htmlStripHelper', 'htmlStrip') as $file) { |
|
6 | 6 | require_once($DIR.$file.'.php'); |
7 | 7 | } |
8 | 8 | |
@@ -11,18 +11,18 @@ discard block |
||
11 | 11 | $x='<script type="text/javascript" async="" src="./Transitioning%20from%20Data%20Developer%20to%20Data%20Scientist%20-%20Statistics%20for%20Data%20Science_files/f.txt"></script>'; |
12 | 12 | $data='aaaaa<?php echo here ; ?><!doctype><html><head>'.$x.'</head><!-- a comment --> <body> <?php echo here ; ?> <h2 onmousedown="alert(\'keke\');">u</h2><p></p><h2>a</h2></body></html>b2b2 '; |
13 | 13 | |
14 | -$hstrip=new htmlStrip($data, 'replace', array('<h2>',false)); |
|
15 | -var_dump($hstrip->go()===strip_tags($data, '<h2>'));//true |
|
14 | +$hstrip=new htmlStrip($data, 'replace', array('<h2>', false)); |
|
15 | +var_dump($hstrip->go()===strip_tags($data, '<h2>')); //true |
|
16 | 16 | |
17 | 17 | |
18 | 18 | $hstrip=new htmlStrip($data); |
19 | -var_dump($hstrip->go()===strip_tags($data));//true |
|
19 | +var_dump($hstrip->go()===strip_tags($data)); //true |
|
20 | 20 | |
21 | -$hstrip=new htmlStrip($data, 'replace', array('',true), array('src',true)); |
|
22 | -var_dump((bool)stripos($hstrip->go(htmlStrip::ATTRIBUTES), 'src'));//false |
|
21 | +$hstrip=new htmlStrip($data, 'replace', array('', true), array('src', true)); |
|
22 | +var_dump((bool)stripos($hstrip->go(htmlStrip::ATTRIBUTES), 'src')); //false |
|
23 | 23 | |
24 | -$hstrip=new htmlStrip($data, 'replace', array('',true), array('src',false)); |
|
25 | -var_dump((bool)stripos($hstrip->go(htmlStrip::ATTRIBUTES), 'type'));//false |
|
26 | -var_dump((bool)stripos($hstrip->go(htmlStrip::ATTRIBUTES), 'src'),htmlspecialchars($hstrip->go(htmlStrip::ATTRIBUTES)));//true; |
|
24 | +$hstrip=new htmlStrip($data, 'replace', array('', true), array('src', false)); |
|
25 | +var_dump((bool)stripos($hstrip->go(htmlStrip::ATTRIBUTES), 'type')); //false |
|
26 | +var_dump((bool)stripos($hstrip->go(htmlStrip::ATTRIBUTES), 'src'), htmlspecialchars($hstrip->go(htmlStrip::ATTRIBUTES))); //true; |
|
27 | 27 | |
28 | 28 |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | ); |
377 | 377 | protected function loadHTML($html) |
378 | 378 | { |
379 | - $xml = new \DOMDocument(); |
|
379 | + $xml=new \DOMDocument(); |
|
380 | 380 | //Suppress warnings: proper error handling is beyond scope of example |
381 | 381 | libxml_use_internal_errors(true); |
382 | 382 | if (!strlen($html)) { |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | if (!is_array($notAllowedTags)) { |
393 | 393 | return false; |
394 | 394 | } |
395 | - if (count($notAllowedTags) !== 2) { |
|
395 | + if (count($notAllowedTags)!==2) { |
|
396 | 396 | return false; |
397 | 397 | } |
398 | 398 | $notAllowedTags=array_values($notAllowedTags); |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | } |
404 | 404 | if (is_array($notAllowedTags)) { |
405 | 405 | $notAllowedTags=array_filter(array_map($callback, $notAllowedTags), $callback1); |
406 | - $this->allowedTags=!$keep?array_fill_keys($notAllowedTags, 1):array_diff_key(self::$tags, array_flip($notAllowedTags)); |
|
406 | + $this->allowedTags=!$keep ?array_fill_keys($notAllowedTags, 1) : array_diff_key(self::$tags, array_flip($notAllowedTags)); |
|
407 | 407 | } else { |
408 | 408 | return false; |
409 | 409 | } |
@@ -415,17 +415,17 @@ discard block |
||
415 | 415 | if (!is_array($notAllowedAttributes)) { |
416 | 416 | return false; |
417 | 417 | } |
418 | - if (count($notAllowedAttributes) !== 2) { |
|
418 | + if (count($notAllowedAttributes)!==2) { |
|
419 | 419 | return false; |
420 | 420 | } |
421 | 421 | $keep=(bool)$notAllowedAttributes[1]; |
422 | 422 | $notAllowedAttributes=$notAllowedAttributes[0]; |
423 | 423 | if (is_string($notAllowedAttributes)) { |
424 | - $notAllowedAttributes= explode(',', $notAllowedAttributes); |
|
424 | + $notAllowedAttributes=explode(',', $notAllowedAttributes); |
|
425 | 425 | } |
426 | 426 | if (is_array($notAllowedAttributes)) { |
427 | 427 | $notAllowedAttributes=array_filter(array_map($callback, $notAllowedAttributes), $callback2); |
428 | - $this->allowedAttributes=!$keep?array_fill_keys($notAllowedAttributes, 1):array_diff_key(self::$attributes, array_flip($notAllowedAttributes)); |
|
428 | + $this->allowedAttributes=!$keep ?array_fill_keys($notAllowedAttributes, 1) : array_diff_key(self::$attributes, array_flip($notAllowedAttributes)); |
|
429 | 429 | } else { |
430 | 430 | return false; |
431 | 431 | } |
@@ -436,16 +436,15 @@ discard block |
||
436 | 436 | { |
437 | 437 | $result=$domDoc->saveHTML(); |
438 | 438 | self::handleMainHtmlTags($result, $allowed_tags); |
439 | - return substr(($is_php&&isset($allowed_tags['<php>']))? |
|
440 | - str_replace(array('<php>','</php>'), array('<?php ',' ?>'), $result): |
|
441 | - $result, stripos($result, '<div>')+5, -7); |
|
439 | + return substr(($is_php&&isset($allowed_tags['<php>'])) ? |
|
440 | + str_replace(array('<php>', '</php>'), array('<?php ', ' ?>'), $result) : $result, stripos($result, '<div>')+5, -7); |
|
442 | 441 | } |
443 | 442 | |
444 | 443 | protected static function handleMainHtmlTags(&$result, &$allowed_tags) |
445 | 444 | { |
446 | 445 | $result=str_replace( |
447 | - array('<doctypetag','</doctypetag>','<headtag' ,'</headtag','<htmltag','</htmltag','<bodytag','</bodytag'), |
|
448 | - array('<!doctype','','<head','</head','<html','</html','<body','</body'), |
|
446 | + array('<doctypetag', '</doctypetag>', '<headtag', '</headtag', '<htmltag', '</htmltag', '<bodytag', '</bodytag'), |
|
447 | + array('<!doctype', '', '<head', '</head', '<html', '</html', '<body', '</body'), |
|
449 | 448 | $result |
450 | 449 | ); |
451 | 450 | if (!isset($allowed_tags['<doctypetag>'])) { |
@@ -456,7 +455,7 @@ discard block |
||
456 | 455 | protected static function handleComments($domDoc, &$allowed_tags) |
457 | 456 | { |
458 | 457 | if (!isset($allowed_tags['<!-- -->'])) { |
459 | - $xpath = new \DOMXPath($domDoc); |
|
458 | + $xpath=new \DOMXPath($domDoc); |
|
460 | 459 | $DomComments=$xpath->query("//comment()"); |
461 | 460 | foreach ($DomComments as $DomComment) { |
462 | 461 | $DomComment->parentNode->removeChild($DomComment); |
@@ -26,13 +26,13 @@ |
||
26 | 26 | |
27 | 27 | public function prepareHtml() |
28 | 28 | { |
29 | - return array_map(function ($v) { |
|
29 | + return array_map(function($v) { |
|
30 | 30 | return is_array($v) ? $v[1] : $v; |
31 | 31 | }, $this->prepocessed->getHTML()); |
32 | 32 | } |
33 | 33 | public function preparePhp() |
34 | 34 | { |
35 | - return array_map(function ($v) { |
|
35 | + return array_map(function($v) { |
|
36 | 36 | return is_array($v)&&($v[0]===T_OPEN_TAG||$v[0]===T_CLOSE_TAG) ? ($v[0]===T_OPEN_TAG ? '<php>' : '</php>') : (is_array($v) ? $v[1] : $v); |
37 | 37 | }, $this->prepocessed->getPHP()); |
38 | 38 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | array($this->doctype, $this->html_tag, '</html>', $this->head, '</head>', $this->body, '</body>'), |
25 | 25 | array('<doctypetag'.substr($this->doctype, 9), '<htmltag '.substr($this->html_tag, 5), '</htmltag>', '<headtag '.substr($this->head, 5), '</headtag>', '<bodytag '.substr($this->body, 5), '</bodytag>'), |
26 | 26 | $html |
27 | - ).'</doctypetag></div>'; |
|
27 | + ).'</doctypetag></div>'; |
|
28 | 28 | |
29 | 29 | $preprocessed=token_get_all($html); |
30 | 30 |
@@ -28,7 +28,7 @@ |
||
28 | 28 | |
29 | 29 | $preprocessed=token_get_all($html); |
30 | 30 | |
31 | - $HTML=array_filter($preprocessed, function ($v) { |
|
31 | + $HTML=array_filter($preprocessed, function($v) { |
|
32 | 32 | return is_array($v)&&$v[0]===T_INLINE_HTML; |
33 | 33 | }); |
34 | 34 | $PHP=array_diff_key($preprocessed, $HTML); |