diff options
author | polo <ordipolo@gmx.fr> | 2022-02-17 18:13:00 +0100 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2022-02-17 18:13:00 +0100 |
commit | 787d03e48471ba62cd830379428f04d996f0b74b (patch) | |
tree | e9f98c7b9288c4530b50985688dd82622106ba2d /lib/htmlawed/htmLawed.php | |
parent | 29df6f1362745eabf4fbcaedf309eb63795152fa (diff) | |
download | melaine-787d03e48471ba62cd830379428f04d996f0b74b.zip |
model update
Diffstat (limited to 'lib/htmlawed/htmLawed.php')
-rwxr-xr-x | lib/htmlawed/htmLawed.php | 1458 |
1 files changed, 729 insertions, 729 deletions
diff --git a/lib/htmlawed/htmLawed.php b/lib/htmlawed/htmLawed.php index b384d98..a370d76 100755 --- a/lib/htmlawed/htmLawed.php +++ b/lib/htmlawed/htmLawed.php | |||
@@ -1,729 +1,729 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | /* | 3 | /* |
4 | htmLawed 1.2.5, 24 September 2019 | 4 | htmLawed 1.2.5, 24 September 2019 |
5 | Copyright Santosh Patnaik | 5 | Copyright Santosh Patnaik |
6 | Dual licensed with LGPL 3 and GPL 2+ | 6 | Dual licensed with LGPL 3 and GPL 2+ |
7 | A PHP Labware internal utility - www.bioinformatics.org/phplabware/internal_utilities/htmLawed | 7 | A PHP Labware internal utility - www.bioinformatics.org/phplabware/internal_utilities/htmLawed |
8 | 8 | ||
9 | See htmLawed_README.txt/htm | 9 | See htmLawed_README.txt/htm |
10 | */ | 10 | */ |
11 | 11 | ||
12 | function htmLawed($t, $C=1, $S=array()){ | 12 | function htmLawed($t, $C=1, $S=array()){ |
13 | $C = is_array($C) ? $C : array(); | 13 | $C = is_array($C) ? $C : array(); |
14 | if(!empty($C['valid_xhtml'])){ | 14 | if(!empty($C['valid_xhtml'])){ |
15 | $C['elements'] = empty($C['elements']) ? '*-acronym-big-center-dir-font-isindex-s-strike-tt' : $C['elements']; | 15 | $C['elements'] = empty($C['elements']) ? '*-acronym-big-center-dir-font-isindex-s-strike-tt' : $C['elements']; |
16 | $C['make_tag_strict'] = isset($C['make_tag_strict']) ? $C['make_tag_strict'] : 2; | 16 | $C['make_tag_strict'] = isset($C['make_tag_strict']) ? $C['make_tag_strict'] : 2; |
17 | $C['xml:lang'] = isset($C['xml:lang']) ? $C['xml:lang'] : 2; | 17 | $C['xml:lang'] = isset($C['xml:lang']) ? $C['xml:lang'] : 2; |
18 | } | 18 | } |
19 | // config eles | 19 | // config eles |
20 | $e = array('a'=>1, 'abbr'=>1, 'acronym'=>1, 'address'=>1, 'applet'=>1, 'area'=>1, 'article'=>1, 'aside'=>1, 'audio'=>1, 'b'=>1, 'bdi'=>1, 'bdo'=>1, 'big'=>1, 'blockquote'=>1, 'br'=>1, 'button'=>1, 'canvas'=>1, 'caption'=>1, 'center'=>1, 'cite'=>1, 'code'=>1, 'col'=>1, 'colgroup'=>1, 'command'=>1, 'data'=>1, 'datalist'=>1, 'dd'=>1, 'del'=>1, 'details'=>1, 'dfn'=>1, 'dir'=>1, 'div'=>1, 'dl'=>1, 'dt'=>1, 'em'=>1, 'embed'=>1, 'fieldset'=>1, 'figcaption'=>1, 'figure'=>1, 'font'=>1, 'footer'=>1, 'form'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'header'=>1, 'hgroup'=>1, 'hr'=>1, 'i'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'ins'=>1, 'isindex'=>1, 'kbd'=>1, 'keygen'=>1, 'label'=>1, 'legend'=>1, 'li'=>1, 'link'=>1, 'main'=>1, 'map'=>1, 'mark'=>1, 'menu'=>1, 'meta'=>1, 'meter'=>1, 'nav'=>1, 'noscript'=>1, 'object'=>1, 'ol'=>1, 'optgroup'=>1, 'option'=>1, 'output'=>1, 'p'=>1, 'param'=>1, 'pre'=>1, 'progress'=>1, 'q'=>1, 'rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1, 'ruby'=>1, 's'=>1, 'samp'=>1, 'script'=>1, 'section'=>1, 'select'=>1, 'small'=>1, 'source'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'style'=>1, 'sub'=>1, 'summary'=>1, 'sup'=>1, 'table'=>1, 'tbody'=>1, 'td'=>1, 'textarea'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'time'=>1, 'tr'=>1, 'track'=>1, 'tt'=>1, 'u'=>1, 'ul'=>1, 'var'=>1, 'video'=>1, 'wbr'=>1); // 118 incl. deprecated & some Ruby | 20 | $e = array('a'=>1, 'abbr'=>1, 'acronym'=>1, 'address'=>1, 'applet'=>1, 'area'=>1, 'article'=>1, 'aside'=>1, 'audio'=>1, 'b'=>1, 'bdi'=>1, 'bdo'=>1, 'big'=>1, 'blockquote'=>1, 'br'=>1, 'button'=>1, 'canvas'=>1, 'caption'=>1, 'center'=>1, 'cite'=>1, 'code'=>1, 'col'=>1, 'colgroup'=>1, 'command'=>1, 'data'=>1, 'datalist'=>1, 'dd'=>1, 'del'=>1, 'details'=>1, 'dfn'=>1, 'dir'=>1, 'div'=>1, 'dl'=>1, 'dt'=>1, 'em'=>1, 'embed'=>1, 'fieldset'=>1, 'figcaption'=>1, 'figure'=>1, 'font'=>1, 'footer'=>1, 'form'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'header'=>1, 'hgroup'=>1, 'hr'=>1, 'i'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'ins'=>1, 'isindex'=>1, 'kbd'=>1, 'keygen'=>1, 'label'=>1, 'legend'=>1, 'li'=>1, 'link'=>1, 'main'=>1, 'map'=>1, 'mark'=>1, 'menu'=>1, 'meta'=>1, 'meter'=>1, 'nav'=>1, 'noscript'=>1, 'object'=>1, 'ol'=>1, 'optgroup'=>1, 'option'=>1, 'output'=>1, 'p'=>1, 'param'=>1, 'pre'=>1, 'progress'=>1, 'q'=>1, 'rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1, 'ruby'=>1, 's'=>1, 'samp'=>1, 'script'=>1, 'section'=>1, 'select'=>1, 'small'=>1, 'source'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'style'=>1, 'sub'=>1, 'summary'=>1, 'sup'=>1, 'table'=>1, 'tbody'=>1, 'td'=>1, 'textarea'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'time'=>1, 'tr'=>1, 'track'=>1, 'tt'=>1, 'u'=>1, 'ul'=>1, 'var'=>1, 'video'=>1, 'wbr'=>1); // 118 incl. deprecated & some Ruby |
21 | 21 | ||
22 | if(!empty($C['safe'])){ | 22 | if(!empty($C['safe'])){ |
23 | unset($e['applet'], $e['audio'], $e['canvas'], $e['embed'], $e['iframe'], $e['object'], $e['script'], $e['video']); | 23 | unset($e['applet'], $e['audio'], $e['canvas'], $e['embed'], $e['iframe'], $e['object'], $e['script'], $e['video']); |
24 | } | 24 | } |
25 | $x = !empty($C['elements']) ? str_replace(array("\n", "\r", "\t", ' '), '', $C['elements']) : '*'; | 25 | $x = !empty($C['elements']) ? str_replace(array("\n", "\r", "\t", ' '), '', $C['elements']) : '*'; |
26 | if($x == '-*'){$e = array();} | 26 | if($x == '-*'){$e = array();} |
27 | elseif(strpos($x, '*') === false){$e = array_flip(explode(',', $x));} | 27 | elseif(strpos($x, '*') === false){$e = array_flip(explode(',', $x));} |
28 | else{ | 28 | else{ |
29 | if(isset($x[1])){ | 29 | if(isset($x[1])){ |
30 | preg_match_all('`(?:^|-|\+)[^\-+]+?(?=-|\+|$)`', $x, $m, PREG_SET_ORDER); | 30 | preg_match_all('`(?:^|-|\+)[^\-+]+?(?=-|\+|$)`', $x, $m, PREG_SET_ORDER); |
31 | for($i=count($m); --$i>=0;){$m[$i] = $m[$i][0];} | 31 | for($i=count($m); --$i>=0;){$m[$i] = $m[$i][0];} |
32 | foreach($m as $v){ | 32 | foreach($m as $v){ |
33 | if($v[0] == '+'){$e[substr($v, 1)] = 1;} | 33 | if($v[0] == '+'){$e[substr($v, 1)] = 1;} |
34 | if($v[0] == '-' && isset($e[($v = substr($v, 1))]) && !in_array('+'. $v, $m)){unset($e[$v]);} | 34 | if($v[0] == '-' && isset($e[($v = substr($v, 1))]) && !in_array('+'. $v, $m)){unset($e[$v]);} |
35 | } | 35 | } |
36 | } | 36 | } |
37 | } | 37 | } |
38 | $C['elements'] =& $e; | 38 | $C['elements'] =& $e; |
39 | // config attrs | 39 | // config attrs |
40 | $x = !empty($C['deny_attribute']) ? strtolower(str_replace(array("\n", "\r", "\t", ' '), '', $C['deny_attribute'])) : ''; | 40 | $x = !empty($C['deny_attribute']) ? strtolower(str_replace(array("\n", "\r", "\t", ' '), '', $C['deny_attribute'])) : ''; |
41 | $x = array_flip((isset($x[0]) && $x[0] == '*') ? str_replace('/', 'data-', explode('-', str_replace('data-', '/', $x))) : explode(',', $x. (!empty($C['safe']) ? ',on*' : ''))); | 41 | $x = array_flip((isset($x[0]) && $x[0] == '*') ? str_replace('/', 'data-', explode('-', str_replace('data-', '/', $x))) : explode(',', $x. (!empty($C['safe']) ? ',on*' : ''))); |
42 | $C['deny_attribute'] = $x; | 42 | $C['deny_attribute'] = $x; |
43 | // config URLs | 43 | // config URLs |
44 | $x = (isset($C['schemes'][2]) && strpos($C['schemes'], ':')) ? strtolower($C['schemes']) : 'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, tel, telnet'. (empty($C['safe']) ? ', app, javascript; *: data, javascript, ' : '; *:'). 'file, http, https'; | 44 | $x = (isset($C['schemes'][2]) && strpos($C['schemes'], ':')) ? strtolower($C['schemes']) : 'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, tel, telnet'. (empty($C['safe']) ? ', app, javascript; *: data, javascript, ' : '; *:'). 'file, http, https'; |
45 | $C['schemes'] = array(); | 45 | $C['schemes'] = array(); |
46 | foreach(explode(';', trim(str_replace(array(' ', "\t", "\r", "\n"), '', $x), ';')) as $v){ | 46 | foreach(explode(';', trim(str_replace(array(' ', "\t", "\r", "\n"), '', $x), ';')) as $v){ |
47 | $x = $x2 = null; list($x, $x2) = explode(':', $v, 2); | 47 | $x = $x2 = null; list($x, $x2) = explode(':', $v, 2); |
48 | if($x2){$C['schemes'][$x] = array_flip(explode(',', $x2));} | 48 | if($x2){$C['schemes'][$x] = array_flip(explode(',', $x2));} |
49 | } | 49 | } |
50 | if(!isset($C['schemes']['*'])){ | 50 | if(!isset($C['schemes']['*'])){ |
51 | $C['schemes']['*'] = array('file'=>1, 'http'=>1, 'https'=>1); | 51 | $C['schemes']['*'] = array('file'=>1, 'http'=>1, 'https'=>1); |
52 | if(empty($C['safe'])){$C['schemes']['*'] += array('data'=>1, 'javascript'=>1);} | 52 | if(empty($C['safe'])){$C['schemes']['*'] += array('data'=>1, 'javascript'=>1);} |
53 | } | 53 | } |
54 | if(!empty($C['safe']) && empty($C['schemes']['style'])){$C['schemes']['style'] = array('!'=>1);} | 54 | if(!empty($C['safe']) && empty($C['schemes']['style'])){$C['schemes']['style'] = array('!'=>1);} |
55 | $C['abs_url'] = isset($C['abs_url']) ? $C['abs_url'] : 0; | 55 | $C['abs_url'] = isset($C['abs_url']) ? $C['abs_url'] : 0; |
56 | if(!isset($C['base_url']) or !preg_match('`^[a-zA-Z\d.+\-]+://[^/]+/(.+?/)?$`', $C['base_url'])){ | 56 | if(!isset($C['base_url']) or !preg_match('`^[a-zA-Z\d.+\-]+://[^/]+/(.+?/)?$`', $C['base_url'])){ |
57 | $C['base_url'] = $C['abs_url'] = 0; | 57 | $C['base_url'] = $C['abs_url'] = 0; |
58 | } | 58 | } |
59 | // config rest | 59 | // config rest |
60 | $C['and_mark'] = empty($C['and_mark']) ? 0 : 1; | 60 | $C['and_mark'] = empty($C['and_mark']) ? 0 : 1; |
61 | $C['anti_link_spam'] = (isset($C['anti_link_spam']) && is_array($C['anti_link_spam']) && count($C['anti_link_spam']) == 2 && (empty($C['anti_link_spam'][0]) or hl_regex($C['anti_link_spam'][0])) && (empty($C['anti_link_spam'][1]) or hl_regex($C['anti_link_spam'][1]))) ? $C['anti_link_spam'] : 0; | 61 | $C['anti_link_spam'] = (isset($C['anti_link_spam']) && is_array($C['anti_link_spam']) && count($C['anti_link_spam']) == 2 && (empty($C['anti_link_spam'][0]) or hl_regex($C['anti_link_spam'][0])) && (empty($C['anti_link_spam'][1]) or hl_regex($C['anti_link_spam'][1]))) ? $C['anti_link_spam'] : 0; |
62 | $C['anti_mail_spam'] = isset($C['anti_mail_spam']) ? $C['anti_mail_spam'] : 0; | 62 | $C['anti_mail_spam'] = isset($C['anti_mail_spam']) ? $C['anti_mail_spam'] : 0; |
63 | $C['balance'] = isset($C['balance']) ? (bool)$C['balance'] : 1; | 63 | $C['balance'] = isset($C['balance']) ? (bool)$C['balance'] : 1; |
64 | $C['cdata'] = isset($C['cdata']) ? $C['cdata'] : (empty($C['safe']) ? 3 : 0); | 64 | $C['cdata'] = isset($C['cdata']) ? $C['cdata'] : (empty($C['safe']) ? 3 : 0); |
65 | $C['clean_ms_char'] = empty($C['clean_ms_char']) ? 0 : $C['clean_ms_char']; | 65 | $C['clean_ms_char'] = empty($C['clean_ms_char']) ? 0 : $C['clean_ms_char']; |
66 | $C['comment'] = isset($C['comment']) ? $C['comment'] : (empty($C['safe']) ? 3 : 0); | 66 | $C['comment'] = isset($C['comment']) ? $C['comment'] : (empty($C['safe']) ? 3 : 0); |
67 | $C['css_expression'] = empty($C['css_expression']) ? 0 : 1; | 67 | $C['css_expression'] = empty($C['css_expression']) ? 0 : 1; |
68 | $C['direct_list_nest'] = empty($C['direct_list_nest']) ? 0 : 1; | 68 | $C['direct_list_nest'] = empty($C['direct_list_nest']) ? 0 : 1; |
69 | $C['hexdec_entity'] = isset($C['hexdec_entity']) ? $C['hexdec_entity'] : 1; | 69 | $C['hexdec_entity'] = isset($C['hexdec_entity']) ? $C['hexdec_entity'] : 1; |
70 | $C['hook'] = (!empty($C['hook']) && function_exists($C['hook'])) ? $C['hook'] : 0; | 70 | $C['hook'] = (!empty($C['hook']) && function_exists($C['hook'])) ? $C['hook'] : 0; |
71 | $C['hook_tag'] = (!empty($C['hook_tag']) && function_exists($C['hook_tag'])) ? $C['hook_tag'] : 0; | 71 | $C['hook_tag'] = (!empty($C['hook_tag']) && function_exists($C['hook_tag'])) ? $C['hook_tag'] : 0; |
72 | $C['keep_bad'] = isset($C['keep_bad']) ? $C['keep_bad'] : 6; | 72 | $C['keep_bad'] = isset($C['keep_bad']) ? $C['keep_bad'] : 6; |
73 | $C['lc_std_val'] = isset($C['lc_std_val']) ? (bool)$C['lc_std_val'] : 1; | 73 | $C['lc_std_val'] = isset($C['lc_std_val']) ? (bool)$C['lc_std_val'] : 1; |
74 | $C['make_tag_strict'] = isset($C['make_tag_strict']) ? $C['make_tag_strict'] : 1; | 74 | $C['make_tag_strict'] = isset($C['make_tag_strict']) ? $C['make_tag_strict'] : 1; |
75 | $C['named_entity'] = isset($C['named_entity']) ? (bool)$C['named_entity'] : 1; | 75 | $C['named_entity'] = isset($C['named_entity']) ? (bool)$C['named_entity'] : 1; |
76 | $C['no_deprecated_attr'] = isset($C['no_deprecated_attr']) ? $C['no_deprecated_attr'] : 1; | 76 | $C['no_deprecated_attr'] = isset($C['no_deprecated_attr']) ? $C['no_deprecated_attr'] : 1; |
77 | $C['parent'] = isset($C['parent'][0]) ? strtolower($C['parent']) : 'body'; | 77 | $C['parent'] = isset($C['parent'][0]) ? strtolower($C['parent']) : 'body'; |
78 | $C['show_setting'] = !empty($C['show_setting']) ? $C['show_setting'] : 0; | 78 | $C['show_setting'] = !empty($C['show_setting']) ? $C['show_setting'] : 0; |
79 | $C['style_pass'] = empty($C['style_pass']) ? 0 : 1; | 79 | $C['style_pass'] = empty($C['style_pass']) ? 0 : 1; |
80 | $C['tidy'] = empty($C['tidy']) ? 0 : $C['tidy']; | 80 | $C['tidy'] = empty($C['tidy']) ? 0 : $C['tidy']; |
81 | $C['unique_ids'] = isset($C['unique_ids']) && (!preg_match('`\W`', $C['unique_ids'])) ? $C['unique_ids'] : 1; | 81 | $C['unique_ids'] = isset($C['unique_ids']) && (!preg_match('`\W`', $C['unique_ids'])) ? $C['unique_ids'] : 1; |
82 | $C['xml:lang'] = isset($C['xml:lang']) ? $C['xml:lang'] : 0; | 82 | $C['xml:lang'] = isset($C['xml:lang']) ? $C['xml:lang'] : 0; |
83 | 83 | ||
84 | if(isset($GLOBALS['C'])){$reC = $GLOBALS['C'];} | 84 | if(isset($GLOBALS['C'])){$reC = $GLOBALS['C'];} |
85 | $GLOBALS['C'] = $C; | 85 | $GLOBALS['C'] = $C; |
86 | $S = is_array($S) ? $S : hl_spec($S); | 86 | $S = is_array($S) ? $S : hl_spec($S); |
87 | if(isset($GLOBALS['S'])){$reS = $GLOBALS['S'];} | 87 | if(isset($GLOBALS['S'])){$reS = $GLOBALS['S'];} |
88 | $GLOBALS['S'] = $S; | 88 | $GLOBALS['S'] = $S; |
89 | 89 | ||
90 | $t = preg_replace('`[\x00-\x08\x0b-\x0c\x0e-\x1f]`', '', $t); | 90 | $t = preg_replace('`[\x00-\x08\x0b-\x0c\x0e-\x1f]`', '', $t); |
91 | if($C['clean_ms_char']){ | 91 | if($C['clean_ms_char']){ |
92 | $x = array("\x7f"=>'', "\x80"=>'€', "\x81"=>'', "\x83"=>'ƒ', "\x85"=>'…', "\x86"=>'†', "\x87"=>'‡', "\x88"=>'ˆ', "\x89"=>'‰', "\x8a"=>'Š', "\x8b"=>'‹', "\x8c"=>'Œ', "\x8d"=>'', "\x8e"=>'Ž', "\x8f"=>'', "\x90"=>'', "\x95"=>'•', "\x96"=>'–', "\x97"=>'—', "\x98"=>'˜', "\x99"=>'™', "\x9a"=>'š', "\x9b"=>'›', "\x9c"=>'œ', "\x9d"=>'', "\x9e"=>'ž', "\x9f"=>'Ÿ'); | 92 | $x = array("\x7f"=>'', "\x80"=>'€', "\x81"=>'', "\x83"=>'ƒ', "\x85"=>'…', "\x86"=>'†', "\x87"=>'‡', "\x88"=>'ˆ', "\x89"=>'‰', "\x8a"=>'Š', "\x8b"=>'‹', "\x8c"=>'Œ', "\x8d"=>'', "\x8e"=>'Ž', "\x8f"=>'', "\x90"=>'', "\x95"=>'•', "\x96"=>'–', "\x97"=>'—', "\x98"=>'˜', "\x99"=>'™', "\x9a"=>'š', "\x9b"=>'›', "\x9c"=>'œ', "\x9d"=>'', "\x9e"=>'ž', "\x9f"=>'Ÿ'); |
93 | $x = $x + ($C['clean_ms_char'] == 1 ? array("\x82"=>'‚', "\x84"=>'„', "\x91"=>'‘', "\x92"=>'’', "\x93"=>'“', "\x94"=>'”') : array("\x82"=>'\'', "\x84"=>'"', "\x91"=>'\'', "\x92"=>'\'', "\x93"=>'"', "\x94"=>'"')); | 93 | $x = $x + ($C['clean_ms_char'] == 1 ? array("\x82"=>'‚', "\x84"=>'„', "\x91"=>'‘', "\x92"=>'’', "\x93"=>'“', "\x94"=>'”') : array("\x82"=>'\'', "\x84"=>'"', "\x91"=>'\'', "\x92"=>'\'', "\x93"=>'"', "\x94"=>'"')); |
94 | $t = strtr($t, $x); | 94 | $t = strtr($t, $x); |
95 | } | 95 | } |
96 | if($C['cdata'] or $C['comment']){$t = preg_replace_callback('`<!(?:(?:--.*?--)|(?:\[CDATA\[.*?\]\]))>`sm', 'hl_cmtcd', $t);} | 96 | if($C['cdata'] or $C['comment']){$t = preg_replace_callback('`<!(?:(?:--.*?--)|(?:\[CDATA\[.*?\]\]))>`sm', 'hl_cmtcd', $t);} |
97 | $t = preg_replace_callback('`&([a-zA-Z][a-zA-Z0-9]{1,30}|#(?:[0-9]{1,8}|[Xx][0-9A-Fa-f]{1,7}));`', 'hl_ent', str_replace('&', '&', $t)); | 97 | $t = preg_replace_callback('`&([a-zA-Z][a-zA-Z0-9]{1,30}|#(?:[0-9]{1,8}|[Xx][0-9A-Fa-f]{1,7}));`', 'hl_ent', str_replace('&', '&', $t)); |
98 | if($C['unique_ids'] && !isset($GLOBALS['hl_Ids'])){$GLOBALS['hl_Ids'] = array();} | 98 | if($C['unique_ids'] && !isset($GLOBALS['hl_Ids'])){$GLOBALS['hl_Ids'] = array();} |
99 | if($C['hook']){$t = $C['hook']($t, $C, $S);} | 99 | if($C['hook']){$t = $C['hook']($t, $C, $S);} |
100 | if($C['show_setting'] && preg_match('`^[a-z][a-z0-9_]*$`i', $C['show_setting'])){ | 100 | if($C['show_setting'] && preg_match('`^[a-z][a-z0-9_]*$`i', $C['show_setting'])){ |
101 | $GLOBALS[$C['show_setting']] = array('config'=>$C, 'spec'=>$S, 'time'=>microtime()); | 101 | $GLOBALS[$C['show_setting']] = array('config'=>$C, 'spec'=>$S, 'time'=>microtime()); |
102 | } | 102 | } |
103 | // main | 103 | // main |
104 | $t = preg_replace_callback('`<(?:(?:\s|$)|(?:[^>]*(?:>|$)))|>`m', 'hl_tag', $t); | 104 | $t = preg_replace_callback('`<(?:(?:\s|$)|(?:[^>]*(?:>|$)))|>`m', 'hl_tag', $t); |
105 | $t = $C['balance'] ? hl_bal($t, $C['keep_bad'], $C['parent']) : $t; | 105 | $t = $C['balance'] ? hl_bal($t, $C['keep_bad'], $C['parent']) : $t; |
106 | $t = (($C['cdata'] or $C['comment']) && strpos($t, "\x01") !== false) ? str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05"), array('', '', '&', '<', '>'), $t) : $t; | 106 | $t = (($C['cdata'] or $C['comment']) && strpos($t, "\x01") !== false) ? str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05"), array('', '', '&', '<', '>'), $t) : $t; |
107 | $t = $C['tidy'] ? hl_tidy($t, $C['tidy'], $C['parent']) : $t; | 107 | $t = $C['tidy'] ? hl_tidy($t, $C['tidy'], $C['parent']) : $t; |
108 | unset($C, $e); | 108 | unset($C, $e); |
109 | if(isset($reC)){$GLOBALS['C'] = $reC;} | 109 | if(isset($reC)){$GLOBALS['C'] = $reC;} |
110 | if(isset($reS)){$GLOBALS['S'] = $reS;} | 110 | if(isset($reS)){$GLOBALS['S'] = $reS;} |
111 | return $t; | 111 | return $t; |
112 | } | 112 | } |
113 | 113 | ||
114 | function hl_attrval($a, $t, $p){ | 114 | function hl_attrval($a, $t, $p){ |
115 | // check attr val against $S | 115 | // check attr val against $S |
116 | static $ma = array('accesskey', 'class', 'itemtype', 'rel'); | 116 | static $ma = array('accesskey', 'class', 'itemtype', 'rel'); |
117 | $s = in_array($a, $ma) ? ' ' : ($a == 'srcset' ? ',': ''); | 117 | $s = in_array($a, $ma) ? ' ' : ($a == 'srcset' ? ',': ''); |
118 | $r = array(); | 118 | $r = array(); |
119 | $t = !empty($s) ? explode($s, $t) : array($t); | 119 | $t = !empty($s) ? explode($s, $t) : array($t); |
120 | foreach($t as $tk=>$tv){ | 120 | foreach($t as $tk=>$tv){ |
121 | $o = 1; $tv = trim($tv); $l = strlen($tv); | 121 | $o = 1; $tv = trim($tv); $l = strlen($tv); |
122 | foreach($p as $k=>$v){ | 122 | foreach($p as $k=>$v){ |
123 | if(!$l){continue;} | 123 | if(!$l){continue;} |
124 | switch($k){ | 124 | switch($k){ |
125 | case 'maxlen': if($l > $v){$o = 0;} | 125 | case 'maxlen': if($l > $v){$o = 0;} |
126 | break; case 'minlen': if($l < $v){$o = 0;} | 126 | break; case 'minlen': if($l < $v){$o = 0;} |
127 | break; case 'maxval': if((float)($tv) > $v){$o = 0;} | 127 | break; case 'maxval': if((float)($tv) > $v){$o = 0;} |
128 | break; case 'minval': if((float)($tv) < $v){$o = 0;} | 128 | break; case 'minval': if((float)($tv) < $v){$o = 0;} |
129 | break; case 'match': if(!preg_match($v, $tv)){$o = 0;} | 129 | break; case 'match': if(!preg_match($v, $tv)){$o = 0;} |
130 | break; case 'nomatch': if(preg_match($v, $tv)){$o = 0;} | 130 | break; case 'nomatch': if(preg_match($v, $tv)){$o = 0;} |
131 | break; case 'oneof': | 131 | break; case 'oneof': |
132 | $m = 0; | 132 | $m = 0; |
133 | foreach(explode('|', $v) as $n){if($tv == $n){$m = 1; break;}} | 133 | foreach(explode('|', $v) as $n){if($tv == $n){$m = 1; break;}} |
134 | $o = $m; | 134 | $o = $m; |
135 | break; case 'noneof': | 135 | break; case 'noneof': |
136 | $m = 1; | 136 | $m = 1; |
137 | foreach(explode('|', $v) as $n){if($tv == $n){$m = 0; break;}} | 137 | foreach(explode('|', $v) as $n){if($tv == $n){$m = 0; break;}} |
138 | $o = $m; | 138 | $o = $m; |
139 | break; default: | 139 | break; default: |
140 | break; | 140 | break; |
141 | } | 141 | } |
142 | if(!$o){break;} | 142 | if(!$o){break;} |
143 | } | 143 | } |
144 | if($o){$r[] = $tv;} | 144 | if($o){$r[] = $tv;} |
145 | } | 145 | } |
146 | if($s == ','){$s = ', ';} | 146 | if($s == ','){$s = ', ';} |
147 | $r = implode($s, $r); | 147 | $r = implode($s, $r); |
148 | return (isset($r[0]) ? $r : (isset($p['default']) ? $p['default'] : 0)); | 148 | return (isset($r[0]) ? $r : (isset($p['default']) ? $p['default'] : 0)); |
149 | } | 149 | } |
150 | 150 | ||
151 | function hl_bal($t, $do=1, $in='div'){ | 151 | function hl_bal($t, $do=1, $in='div'){ |
152 | // balance tags | 152 | // balance tags |
153 | // by content | 153 | // by content |
154 | $cB = array('blockquote'=>1, 'form'=>1, 'map'=>1, 'noscript'=>1); // Block | 154 | $cB = array('blockquote'=>1, 'form'=>1, 'map'=>1, 'noscript'=>1); // Block |
155 | $cE = array('area'=>1, 'br'=>1, 'col'=>1, 'command'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'keygen'=>1, 'link'=>1, 'meta'=>1, 'param'=>1, 'source'=>1, 'track'=>1, 'wbr'=>1); // Empty | 155 | $cE = array('area'=>1, 'br'=>1, 'col'=>1, 'command'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'keygen'=>1, 'link'=>1, 'meta'=>1, 'param'=>1, 'source'=>1, 'track'=>1, 'wbr'=>1); // Empty |
156 | $cF = array('a'=>1, 'article'=>1, 'aside'=>1, 'audio'=>1, 'button'=>1, 'canvas'=>1, 'del'=>1, 'details'=>1, 'div'=>1, 'dd'=>1, 'fieldset'=>1, 'figure'=>1, 'footer'=>1, 'header'=>1, 'iframe'=>1, 'ins'=>1, 'li'=>1, 'main'=>1, 'menu'=>1, 'nav'=>1, 'noscript'=>1, 'object'=>1, 'section'=>1, 'style'=>1, 'td'=>1, 'th'=>1, 'video'=>1); // Flow; later context-wise dynamic move of ins & del to $cI | 156 | $cF = array('a'=>1, 'article'=>1, 'aside'=>1, 'audio'=>1, 'button'=>1, 'canvas'=>1, 'del'=>1, 'details'=>1, 'div'=>1, 'dd'=>1, 'fieldset'=>1, 'figure'=>1, 'footer'=>1, 'header'=>1, 'iframe'=>1, 'ins'=>1, 'li'=>1, 'main'=>1, 'menu'=>1, 'nav'=>1, 'noscript'=>1, 'object'=>1, 'section'=>1, 'style'=>1, 'td'=>1, 'th'=>1, 'video'=>1); // Flow; later context-wise dynamic move of ins & del to $cI |
157 | $cI = array('abbr'=>1, 'acronym'=>1, 'address'=>1, 'b'=>1, 'bdi'=>1, 'bdo'=>1, 'big'=>1, 'caption'=>1, 'cite'=>1, 'code'=>1, 'data'=>1, 'datalist'=>1, 'dfn'=>1, 'dt'=>1, 'em'=>1, 'figcaption'=>1, 'font'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hgroup'=>1, 'i'=>1, 'kbd'=>1, 'label'=>1, 'legend'=>1, 'mark'=>1, 'meter'=>1, 'output'=>1, 'p'=>1, 'pre'=>1, 'progress'=>1, 'q'=>1, 'rb'=>1, 'rt'=>1, 's'=>1, 'samp'=>1, 'small'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'sub'=>1, 'summary'=>1, 'sup'=>1, 'time'=>1, 'tt'=>1, 'u'=>1, 'var'=>1); // Inline | 157 | $cI = array('abbr'=>1, 'acronym'=>1, 'address'=>1, 'b'=>1, 'bdi'=>1, 'bdo'=>1, 'big'=>1, 'caption'=>1, 'cite'=>1, 'code'=>1, 'data'=>1, 'datalist'=>1, 'dfn'=>1, 'dt'=>1, 'em'=>1, 'figcaption'=>1, 'font'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hgroup'=>1, 'i'=>1, 'kbd'=>1, 'label'=>1, 'legend'=>1, 'mark'=>1, 'meter'=>1, 'output'=>1, 'p'=>1, 'pre'=>1, 'progress'=>1, 'q'=>1, 'rb'=>1, 'rt'=>1, 's'=>1, 'samp'=>1, 'small'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'sub'=>1, 'summary'=>1, 'sup'=>1, 'time'=>1, 'tt'=>1, 'u'=>1, 'var'=>1); // Inline |
158 | $cN = array('a'=>array('a'=>1, 'address'=>1, 'button'=>1, 'details'=>1, 'embed'=>1, 'keygen'=>1, 'label'=>1, 'select'=>1, 'textarea'=>1), 'address'=>array('address'=>1, 'article'=>1, 'aside'=>1, 'header'=>1, 'keygen'=>1, 'footer'=>1, 'nav'=>1, 'section'=>1), 'button'=>array('a'=>1, 'address'=>1, 'button'=>1, 'details'=>1, 'embed'=>1, 'fieldset'=>1, 'form'=>1, 'iframe'=>1, 'input'=>1, 'keygen'=>1, 'label'=>1, 'select'=>1, 'textarea'=>1), 'fieldset'=>array('fieldset'=>1), 'footer'=>array('header'=>1, 'footer'=>1), 'form'=>array('form'=>1), 'header'=>array('header'=>1, 'footer'=>1), 'label'=>array('label'=>1), 'main'=>array('main'=>1), 'meter'=>array('meter'=>1), 'noscript'=>array('script'=>1), 'pre'=>array('big'=>1, 'font'=>1, 'img'=>1, 'object'=>1, 'script'=>1, 'small'=>1, 'sub'=>1, 'sup'=>1), 'progress'=>array('progress'=>1), 'rb'=>array('ruby'=>1), 'rt'=>array('ruby'=>1), 'time'=>array('time'=>1), ); // Illegal | 158 | $cN = array('a'=>array('a'=>1, 'address'=>1, 'button'=>1, 'details'=>1, 'embed'=>1, 'keygen'=>1, 'label'=>1, 'select'=>1, 'textarea'=>1), 'address'=>array('address'=>1, 'article'=>1, 'aside'=>1, 'header'=>1, 'keygen'=>1, 'footer'=>1, 'nav'=>1, 'section'=>1), 'button'=>array('a'=>1, 'address'=>1, 'button'=>1, 'details'=>1, 'embed'=>1, 'fieldset'=>1, 'form'=>1, 'iframe'=>1, 'input'=>1, 'keygen'=>1, 'label'=>1, 'select'=>1, 'textarea'=>1), 'fieldset'=>array('fieldset'=>1), 'footer'=>array('header'=>1, 'footer'=>1), 'form'=>array('form'=>1), 'header'=>array('header'=>1, 'footer'=>1), 'label'=>array('label'=>1), 'main'=>array('main'=>1), 'meter'=>array('meter'=>1), 'noscript'=>array('script'=>1), 'pre'=>array('big'=>1, 'font'=>1, 'img'=>1, 'object'=>1, 'script'=>1, 'small'=>1, 'sub'=>1, 'sup'=>1), 'progress'=>array('progress'=>1), 'rb'=>array('ruby'=>1), 'rt'=>array('ruby'=>1), 'time'=>array('time'=>1), ); // Illegal |
159 | $cN2 = array_keys($cN); | 159 | $cN2 = array_keys($cN); |
160 | $cS = array('colgroup'=>array('col'=>1), 'datalist'=>array('option'=>1), 'dir'=>array('li'=>1), 'dl'=>array('dd'=>1, 'dt'=>1), 'hgroup'=>array('h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1), 'menu'=>array('li'=>1), 'ol'=>array('li'=>1), 'optgroup'=>array('option'=>1), 'option'=>array('#pcdata'=>1), 'rbc'=>array('rb'=>1), 'rp'=>array('#pcdata'=>1), 'rtc'=>array('rt'=>1), 'ruby'=>array('rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1), 'select'=>array('optgroup'=>1, 'option'=>1), 'script'=>array('#pcdata'=>1), 'table'=>array('caption'=>1, 'col'=>1, 'colgroup'=>1, 'tfoot'=>1, 'tbody'=>1, 'tr'=>1, 'thead'=>1), 'tbody'=>array('tr'=>1), 'tfoot'=>array('tr'=>1), 'textarea'=>array('#pcdata'=>1), 'thead'=>array('tr'=>1), 'tr'=>array('td'=>1, 'th'=>1), 'ul'=>array('li'=>1)); // Specific - immediate parent-child | 160 | $cS = array('colgroup'=>array('col'=>1), 'datalist'=>array('option'=>1), 'dir'=>array('li'=>1), 'dl'=>array('dd'=>1, 'dt'=>1), 'hgroup'=>array('h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1), 'menu'=>array('li'=>1), 'ol'=>array('li'=>1), 'optgroup'=>array('option'=>1), 'option'=>array('#pcdata'=>1), 'rbc'=>array('rb'=>1), 'rp'=>array('#pcdata'=>1), 'rtc'=>array('rt'=>1), 'ruby'=>array('rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1), 'select'=>array('optgroup'=>1, 'option'=>1), 'script'=>array('#pcdata'=>1), 'table'=>array('caption'=>1, 'col'=>1, 'colgroup'=>1, 'tfoot'=>1, 'tbody'=>1, 'tr'=>1, 'thead'=>1), 'tbody'=>array('tr'=>1), 'tfoot'=>array('tr'=>1), 'textarea'=>array('#pcdata'=>1), 'thead'=>array('tr'=>1), 'tr'=>array('td'=>1, 'th'=>1), 'ul'=>array('li'=>1)); // Specific - immediate parent-child |
161 | if($GLOBALS['C']['direct_list_nest']){$cS['ol'] = $cS['ul'] = $cS['menu'] += array('menu'=>1, 'ol'=>1, 'ul'=>1);} | 161 | if($GLOBALS['C']['direct_list_nest']){$cS['ol'] = $cS['ul'] = $cS['menu'] += array('menu'=>1, 'ol'=>1, 'ul'=>1);} |
162 | $cO = array('address'=>array('p'=>1), 'applet'=>array('param'=>1), 'audio'=>array('source'=>1, 'track'=>1), 'blockquote'=>array('script'=>1), 'details'=>array('summary'=>1), 'fieldset'=>array('legend'=>1, '#pcdata'=>1), 'figure'=>array('figcaption'=>1),'form'=>array('script'=>1), 'map'=>array('area'=>1), 'object'=>array('param'=>1, 'embed'=>1), 'video'=>array('source'=>1, 'track'=>1)); // Other | 162 | $cO = array('address'=>array('p'=>1), 'applet'=>array('param'=>1), 'audio'=>array('source'=>1, 'track'=>1), 'blockquote'=>array('script'=>1), 'details'=>array('summary'=>1), 'fieldset'=>array('legend'=>1, '#pcdata'=>1), 'figure'=>array('figcaption'=>1),'form'=>array('script'=>1), 'map'=>array('area'=>1), 'object'=>array('param'=>1, 'embed'=>1), 'video'=>array('source'=>1, 'track'=>1)); // Other |
163 | $cT = array('colgroup'=>1, 'dd'=>1, 'dt'=>1, 'li'=>1, 'option'=>1, 'p'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1); // Omitable closing | 163 | $cT = array('colgroup'=>1, 'dd'=>1, 'dt'=>1, 'li'=>1, 'option'=>1, 'p'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1); // Omitable closing |
164 | // block/inline type; a/ins/del both type; #pcdata: text | 164 | // block/inline type; a/ins/del both type; #pcdata: text |
165 | $eB = array('a'=>1, 'address'=>1, 'article'=>1, 'aside'=>1, 'blockquote'=>1, 'center'=>1, 'del'=>1, 'details'=>1, 'dir'=>1, 'dl'=>1, 'div'=>1, 'fieldset'=>1, 'figure'=>1, 'footer'=>1, 'form'=>1, 'ins'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'header'=>1, 'hr'=>1, 'isindex'=>1, 'main'=>1, 'menu'=>1, 'nav'=>1, 'noscript'=>1, 'ol'=>1, 'p'=>1, 'pre'=>1, 'section'=>1, 'style'=>1, 'table'=>1, 'ul'=>1); | 165 | $eB = array('a'=>1, 'address'=>1, 'article'=>1, 'aside'=>1, 'blockquote'=>1, 'center'=>1, 'del'=>1, 'details'=>1, 'dir'=>1, 'dl'=>1, 'div'=>1, 'fieldset'=>1, 'figure'=>1, 'footer'=>1, 'form'=>1, 'ins'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'header'=>1, 'hr'=>1, 'isindex'=>1, 'main'=>1, 'menu'=>1, 'nav'=>1, 'noscript'=>1, 'ol'=>1, 'p'=>1, 'pre'=>1, 'section'=>1, 'style'=>1, 'table'=>1, 'ul'=>1); |
166 | $eI = array('#pcdata'=>1, 'a'=>1, 'abbr'=>1, 'acronym'=>1, 'applet'=>1, 'audio'=>1, 'b'=>1, 'bdi'=>1, 'bdo'=>1, 'big'=>1, 'br'=>1, 'button'=>1, 'canvas'=>1, 'cite'=>1, 'code'=>1, 'command'=>1, 'data'=>1, 'datalist'=>1, 'del'=>1, 'dfn'=>1, 'em'=>1, 'embed'=>1, 'figcaption'=>1, 'font'=>1, 'i'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'ins'=>1, 'kbd'=>1, 'label'=>1, 'link'=>1, 'map'=>1, 'mark'=>1, 'meta'=>1, 'meter'=>1, 'object'=>1, 'output'=>1, 'progress'=>1, 'q'=>1, 'ruby'=>1, 's'=>1, 'samp'=>1, 'select'=>1, 'script'=>1, 'small'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'sub'=>1, 'summary'=>1, 'sup'=>1, 'textarea'=>1, 'time'=>1, 'tt'=>1, 'u'=>1, 'var'=>1, 'video'=>1, 'wbr'=>1); | 166 | $eI = array('#pcdata'=>1, 'a'=>1, 'abbr'=>1, 'acronym'=>1, 'applet'=>1, 'audio'=>1, 'b'=>1, 'bdi'=>1, 'bdo'=>1, 'big'=>1, 'br'=>1, 'button'=>1, 'canvas'=>1, 'cite'=>1, 'code'=>1, 'command'=>1, 'data'=>1, 'datalist'=>1, 'del'=>1, 'dfn'=>1, 'em'=>1, 'embed'=>1, 'figcaption'=>1, 'font'=>1, 'i'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'ins'=>1, 'kbd'=>1, 'label'=>1, 'link'=>1, 'map'=>1, 'mark'=>1, 'meta'=>1, 'meter'=>1, 'object'=>1, 'output'=>1, 'progress'=>1, 'q'=>1, 'ruby'=>1, 's'=>1, 'samp'=>1, 'select'=>1, 'script'=>1, 'small'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'sub'=>1, 'summary'=>1, 'sup'=>1, 'textarea'=>1, 'time'=>1, 'tt'=>1, 'u'=>1, 'var'=>1, 'video'=>1, 'wbr'=>1); |
167 | $eN = array('a'=>1, 'address'=>1, 'article'=>1, 'aside'=>1, 'big'=>1, 'button'=>1, 'details'=>1, 'embed'=>1, 'fieldset'=>1, 'font'=>1, 'footer'=>1, 'form'=>1, 'header'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'keygen'=>1, 'label'=>1, 'meter'=>1, 'nav'=>1, 'object'=>1, 'progress'=>1, 'ruby'=>1, 'script'=>1, 'select'=>1, 'small'=>1, 'sub'=>1, 'sup'=>1, 'textarea'=>1, 'time'=>1); // Exclude from specific ele; $cN values | 167 | $eN = array('a'=>1, 'address'=>1, 'article'=>1, 'aside'=>1, 'big'=>1, 'button'=>1, 'details'=>1, 'embed'=>1, 'fieldset'=>1, 'font'=>1, 'footer'=>1, 'form'=>1, 'header'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'keygen'=>1, 'label'=>1, 'meter'=>1, 'nav'=>1, 'object'=>1, 'progress'=>1, 'ruby'=>1, 'script'=>1, 'select'=>1, 'small'=>1, 'sub'=>1, 'sup'=>1, 'textarea'=>1, 'time'=>1); // Exclude from specific ele; $cN values |
168 | $eO = array('area'=>1, 'caption'=>1, 'col'=>1, 'colgroup'=>1, 'command'=>1, 'dd'=>1, 'dt'=>1, 'hgroup'=>1, 'keygen'=>1, 'legend'=>1, 'li'=>1, 'optgroup'=>1, 'option'=>1, 'param'=>1, 'rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1, 'script'=>1, 'source'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'thead'=>1, 'th'=>1, 'tr'=>1, 'track'=>1); // Missing in $eB & $eI | 168 | $eO = array('area'=>1, 'caption'=>1, 'col'=>1, 'colgroup'=>1, 'command'=>1, 'dd'=>1, 'dt'=>1, 'hgroup'=>1, 'keygen'=>1, 'legend'=>1, 'li'=>1, 'optgroup'=>1, 'option'=>1, 'param'=>1, 'rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1, 'script'=>1, 'source'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'thead'=>1, 'th'=>1, 'tr'=>1, 'track'=>1); // Missing in $eB & $eI |
169 | $eF = $eB + $eI; | 169 | $eF = $eB + $eI; |
170 | 170 | ||
171 | // $in sets allowed child | 171 | // $in sets allowed child |
172 | $in = ((isset($eF[$in]) && $in != '#pcdata') or isset($eO[$in])) ? $in : 'div'; | 172 | $in = ((isset($eF[$in]) && $in != '#pcdata') or isset($eO[$in])) ? $in : 'div'; |
173 | if(isset($cE[$in])){ | 173 | if(isset($cE[$in])){ |
174 | return (!$do ? '' : str_replace(array('<', '>'), array('<', '>'), $t)); | 174 | return (!$do ? '' : str_replace(array('<', '>'), array('<', '>'), $t)); |
175 | } | 175 | } |
176 | if(isset($cS[$in])){$inOk = $cS[$in];} | 176 | if(isset($cS[$in])){$inOk = $cS[$in];} |
177 | elseif(isset($cI[$in])){$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1;} | 177 | elseif(isset($cI[$in])){$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1;} |
178 | elseif(isset($cF[$in])){$inOk = $eF; unset($cI['del'], $cI['ins']);} | 178 | elseif(isset($cF[$in])){$inOk = $eF; unset($cI['del'], $cI['ins']);} |
179 | elseif(isset($cB[$in])){$inOk = $eB; unset($cI['del'], $cI['ins']);} | 179 | elseif(isset($cB[$in])){$inOk = $eB; unset($cI['del'], $cI['ins']);} |
180 | if(isset($cO[$in])){$inOk = $inOk + $cO[$in];} | 180 | if(isset($cO[$in])){$inOk = $inOk + $cO[$in];} |
181 | if(isset($cN[$in])){$inOk = array_diff_assoc($inOk, $cN[$in]);} | 181 | if(isset($cN[$in])){$inOk = array_diff_assoc($inOk, $cN[$in]);} |
182 | 182 | ||
183 | $t = explode('<', $t); | 183 | $t = explode('<', $t); |
184 | $ok = $q = array(); // $q seq list of open non-empty ele | 184 | $ok = $q = array(); // $q seq list of open non-empty ele |
185 | ob_start(); | 185 | ob_start(); |
186 | 186 | ||
187 | for($i=-1, $ci=count($t); ++$i<$ci;){ | 187 | for($i=-1, $ci=count($t); ++$i<$ci;){ |
188 | // allowed $ok in parent $p | 188 | // allowed $ok in parent $p |
189 | if($ql = count($q)){ | 189 | if($ql = count($q)){ |
190 | $p = array_pop($q); | 190 | $p = array_pop($q); |
191 | $q[] = $p; | 191 | $q[] = $p; |
192 | if(isset($cS[$p])){$ok = $cS[$p];} | 192 | if(isset($cS[$p])){$ok = $cS[$p];} |
193 | elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;} | 193 | elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;} |
194 | elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);} | 194 | elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);} |
195 | elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);} | 195 | elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);} |
196 | if(isset($cO[$p])){$ok = $ok + $cO[$p];} | 196 | if(isset($cO[$p])){$ok = $ok + $cO[$p];} |
197 | if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);} | 197 | if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);} |
198 | }else{$ok = $inOk; unset($cI['del'], $cI['ins']);} | 198 | }else{$ok = $inOk; unset($cI['del'], $cI['ins']);} |
199 | // bad tags, & ele content | 199 | // bad tags, & ele content |
200 | if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){ | 200 | if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){ |
201 | echo '<', $s, $e, $a, '>'; | 201 | echo '<', $s, $e, $a, '>'; |
202 | } | 202 | } |
203 | if(isset($x[0])){ | 203 | if(isset($x[0])){ |
204 | if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){ | 204 | if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){ |
205 | echo '<div>', $x, '</div>'; | 205 | echo '<div>', $x, '</div>'; |
206 | } | 206 | } |
207 | elseif($do < 3 or isset($ok['#pcdata'])){echo $x;} | 207 | elseif($do < 3 or isset($ok['#pcdata'])){echo $x;} |
208 | elseif(strpos($x, "\x02\x04")){ | 208 | elseif(strpos($x, "\x02\x04")){ |
209 | foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){ | 209 | foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){ |
210 | echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : '')); | 210 | echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : '')); |
211 | } | 211 | } |
212 | }elseif($do > 4){echo preg_replace('`\S`', '', $x);} | 212 | }elseif($do > 4){echo preg_replace('`\S`', '', $x);} |
213 | } | 213 | } |
214 | // get markup | 214 | // get markup |
215 | if(!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r)){$x = $t[$i]; continue;} | 215 | if(!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r)){$x = $t[$i]; continue;} |
216 | $s = null; $e = null; $a = null; $x = null; list($all, $s, $e, $a, $x) = $r; | 216 | $s = null; $e = null; $a = null; $x = null; list($all, $s, $e, $a, $x) = $r; |
217 | // close tag | 217 | // close tag |
218 | if($s){ | 218 | if($s){ |
219 | if(isset($cE[$e]) or !in_array($e, $q)){continue;} // Empty/unopen | 219 | if(isset($cE[$e]) or !in_array($e, $q)){continue;} // Empty/unopen |
220 | if($p == $e){array_pop($q); echo '</', $e, '>'; unset($e); continue;} // Last open | 220 | if($p == $e){array_pop($q); echo '</', $e, '>'; unset($e); continue;} // Last open |
221 | $add = ''; // Nesting - close open tags that need to be | 221 | $add = ''; // Nesting - close open tags that need to be |
222 | for($j=-1, $cj=count($q); ++$j<$cj;){ | 222 | for($j=-1, $cj=count($q); ++$j<$cj;){ |
223 | if(($d = array_pop($q)) == $e){break;} | 223 | if(($d = array_pop($q)) == $e){break;} |
224 | else{$add .= "</{$d}>";} | 224 | else{$add .= "</{$d}>";} |
225 | } | 225 | } |
226 | echo $add, '</', $e, '>'; unset($e); continue; | 226 | echo $add, '</', $e, '>'; unset($e); continue; |
227 | } | 227 | } |
228 | // open tag | 228 | // open tag |
229 | // $cB ele needs $eB ele as child | 229 | // $cB ele needs $eB ele as child |
230 | if(isset($cB[$e]) && strlen(trim($x))){ | 230 | if(isset($cB[$e]) && strlen(trim($x))){ |
231 | $t[$i] = "{$e}{$a}>"; | 231 | $t[$i] = "{$e}{$a}>"; |
232 | array_splice($t, $i+1, 0, 'div>'. $x); unset($e, $x); ++$ci; --$i; continue; | 232 | array_splice($t, $i+1, 0, 'div>'. $x); unset($e, $x); ++$ci; --$i; continue; |
233 | } | 233 | } |
234 | if((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e])){ | 234 | if((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e])){ |
235 | array_splice($t, $i, 0, 'div>'); unset($e, $x); ++$ci; --$i; continue; | 235 | array_splice($t, $i, 0, 'div>'); unset($e, $x); ++$ci; --$i; continue; |
236 | } | 236 | } |
237 | // if no open ele, $in = parent; mostly immediate parent-child relation should hold | 237 | // if no open ele, $in = parent; mostly immediate parent-child relation should hold |
238 | if(!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2)){ | 238 | if(!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2)){ |
239 | if(!isset($ok[$e])){ | 239 | if(!isset($ok[$e])){ |
240 | if($ql && isset($cT[$p])){echo '</', array_pop($q), '>'; unset($e, $x); --$i;} | 240 | if($ql && isset($cT[$p])){echo '</', array_pop($q), '>'; unset($e, $x); --$i;} |
241 | continue; | 241 | continue; |
242 | } | 242 | } |
243 | if(!isset($cE[$e])){$q[] = $e;} | 243 | if(!isset($cE[$e])){$q[] = $e;} |
244 | echo '<', $e, $a, '>'; unset($e); continue; | 244 | echo '<', $e, $a, '>'; unset($e); continue; |
245 | } | 245 | } |
246 | // specific parent-child | 246 | // specific parent-child |
247 | if(isset($cS[$p][$e])){ | 247 | if(isset($cS[$p][$e])){ |
248 | if(!isset($cE[$e])){$q[] = $e;} | 248 | if(!isset($cE[$e])){$q[] = $e;} |
249 | echo '<', $e, $a, '>'; unset($e); continue; | 249 | echo '<', $e, $a, '>'; unset($e); continue; |
250 | } | 250 | } |
251 | // nesting | 251 | // nesting |
252 | $add = ''; | 252 | $add = ''; |
253 | $q2 = array(); | 253 | $q2 = array(); |
254 | for($k=-1, $kc=count($q); ++$k<$kc;){ | 254 | for($k=-1, $kc=count($q); ++$k<$kc;){ |
255 | $d = $q[$k]; | 255 | $d = $q[$k]; |
256 | $ok2 = array(); | 256 | $ok2 = array(); |
257 | if(isset($cS[$d])){$q2[] = $d; continue;} | 257 | if(isset($cS[$d])){$q2[] = $d; continue;} |
258 | $ok2 = isset($cI[$d]) ? $eI : $eF; | 258 | $ok2 = isset($cI[$d]) ? $eI : $eF; |
259 | if(isset($cO[$d])){$ok2 = $ok2 + $cO[$d];} | 259 | if(isset($cO[$d])){$ok2 = $ok2 + $cO[$d];} |
260 | if(isset($cN[$d])){$ok2 = array_diff_assoc($ok2, $cN[$d]);} | 260 | if(isset($cN[$d])){$ok2 = array_diff_assoc($ok2, $cN[$d]);} |
261 | if(!isset($ok2[$e])){ | 261 | if(!isset($ok2[$e])){ |
262 | if(!$k && !isset($inOk[$e])){continue 2;} | 262 | if(!$k && !isset($inOk[$e])){continue 2;} |
263 | $add = "</{$d}>"; | 263 | $add = "</{$d}>"; |
264 | for(;++$k<$kc;){$add = "</{$q[$k]}>{$add}";} | 264 | for(;++$k<$kc;){$add = "</{$q[$k]}>{$add}";} |
265 | break; | 265 | break; |
266 | } | 266 | } |
267 | else{$q2[] = $d;} | 267 | else{$q2[] = $d;} |
268 | } | 268 | } |
269 | $q = $q2; | 269 | $q = $q2; |
270 | if(!isset($cE[$e])){$q[] = $e;} | 270 | if(!isset($cE[$e])){$q[] = $e;} |
271 | echo $add, '<', $e, $a, '>'; unset($e); continue; | 271 | echo $add, '<', $e, $a, '>'; unset($e); continue; |
272 | } | 272 | } |
273 | 273 | ||
274 | // end | 274 | // end |
275 | if($ql = count($q)){ | 275 | if($ql = count($q)){ |
276 | $p = array_pop($q); | 276 | $p = array_pop($q); |
277 | $q[] = $p; | 277 | $q[] = $p; |
278 | if(isset($cS[$p])){$ok = $cS[$p];} | 278 | if(isset($cS[$p])){$ok = $cS[$p];} |
279 | elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;} | 279 | elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;} |
280 | elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);} | 280 | elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);} |
281 | elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);} | 281 | elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);} |
282 | if(isset($cO[$p])){$ok = $ok + $cO[$p];} | 282 | if(isset($cO[$p])){$ok = $ok + $cO[$p];} |
283 | if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);} | 283 | if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);} |
284 | }else{$ok = $inOk; unset($cI['del'], $cI['ins']);} | 284 | }else{$ok = $inOk; unset($cI['del'], $cI['ins']);} |
285 | if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){ | 285 | if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){ |
286 | echo '<', $s, $e, $a, '>'; | 286 | echo '<', $s, $e, $a, '>'; |
287 | } | 287 | } |
288 | if(isset($x[0])){ | 288 | if(isset($x[0])){ |
289 | if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){ | 289 | if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){ |
290 | echo '<div>', $x, '</div>'; | 290 | echo '<div>', $x, '</div>'; |
291 | } | 291 | } |
292 | elseif($do < 3 or isset($ok['#pcdata'])){echo $x;} | 292 | elseif($do < 3 or isset($ok['#pcdata'])){echo $x;} |
293 | elseif(strpos($x, "\x02\x04")){ | 293 | elseif(strpos($x, "\x02\x04")){ |
294 | foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){ | 294 | foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){ |
295 | echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : '')); | 295 | echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : '')); |
296 | } | 296 | } |
297 | }elseif($do > 4){echo preg_replace('`\S`', '', $x);} | 297 | }elseif($do > 4){echo preg_replace('`\S`', '', $x);} |
298 | } | 298 | } |
299 | while(!empty($q) && ($e = array_pop($q))){echo '</', $e, '>';} | 299 | while(!empty($q) && ($e = array_pop($q))){echo '</', $e, '>';} |
300 | $o = ob_get_contents(); | 300 | $o = ob_get_contents(); |
301 | ob_end_clean(); | 301 | ob_end_clean(); |
302 | return $o; | 302 | return $o; |
303 | } | 303 | } |
304 | 304 | ||
305 | function hl_cmtcd($t){ | 305 | function hl_cmtcd($t){ |
306 | // comment/CDATA sec handler | 306 | // comment/CDATA sec handler |
307 | $t = $t[0]; | 307 | $t = $t[0]; |
308 | global $C; | 308 | global $C; |
309 | if(!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata'])){return $t;} | 309 | if(!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata'])){return $t;} |
310 | if($v == 1){return '';} | 310 | if($v == 1){return '';} |
311 | if($n == 'comment' && $v < 4){ | 311 | if($n == 'comment' && $v < 4){ |
312 | if(substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' '){$t .= ' ';} | 312 | if(substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' '){$t .= ' ';} |
313 | } | 313 | } |
314 | else{$t = substr($t, 1, -1);} | 314 | else{$t = substr($t, 1, -1);} |
315 | $t = $v == 2 ? str_replace(array('&', '<', '>'), array('&', '<', '>'), $t) : $t; | 315 | $t = $v == 2 ? str_replace(array('&', '<', '>'), array('&', '<', '>'), $t) : $t; |
316 | return str_replace(array('&', '<', '>'), array("\x03", "\x04", "\x05"), ($n == 'comment' ? "\x01\x02\x04!--$t--\x05\x02\x01" : "\x01\x01\x04$t\x05\x01\x01")); | 316 | return str_replace(array('&', '<', '>'), array("\x03", "\x04", "\x05"), ($n == 'comment' ? "\x01\x02\x04!--$t--\x05\x02\x01" : "\x01\x01\x04$t\x05\x01\x01")); |
317 | } | 317 | } |
318 | 318 | ||
319 | function hl_ent($t){ | 319 | function hl_ent($t){ |
320 | // entitity handler | 320 | // entitity handler |
321 | global $C; | 321 | global $C; |
322 | $t = $t[1]; | 322 | $t = $t[1]; |
323 | static $U = array('quot'=>1,'amp'=>1,'lt'=>1,'gt'=>1); | 323 | static $U = array('quot'=>1,'amp'=>1,'lt'=>1,'gt'=>1); |
324 | static $N = array('fnof'=>'402', 'Alpha'=>'913', 'Beta'=>'914', 'Gamma'=>'915', 'Delta'=>'916', 'Epsilon'=>'917', 'Zeta'=>'918', 'Eta'=>'919', 'Theta'=>'920', 'Iota'=>'921', 'Kappa'=>'922', 'Lambda'=>'923', 'Mu'=>'924', 'Nu'=>'925', 'Xi'=>'926', 'Omicron'=>'927', 'Pi'=>'928', 'Rho'=>'929', 'Sigma'=>'931', 'Tau'=>'932', 'Upsilon'=>'933', 'Phi'=>'934', 'Chi'=>'935', 'Psi'=>'936', 'Omega'=>'937', 'alpha'=>'945', 'beta'=>'946', 'gamma'=>'947', 'delta'=>'948', 'epsilon'=>'949', 'zeta'=>'950', 'eta'=>'951', 'theta'=>'952', 'iota'=>'953', 'kappa'=>'954', 'lambda'=>'955', 'mu'=>'956', 'nu'=>'957', 'xi'=>'958', 'omicron'=>'959', 'pi'=>'960', 'rho'=>'961', 'sigmaf'=>'962', 'sigma'=>'963', 'tau'=>'964', 'upsilon'=>'965', 'phi'=>'966', 'chi'=>'967', 'psi'=>'968', 'omega'=>'969', 'thetasym'=>'977', 'upsih'=>'978', 'piv'=>'982', 'bull'=>'8226', 'hellip'=>'8230', 'prime'=>'8242', 'Prime'=>'8243', 'oline'=>'8254', 'frasl'=>'8260', 'weierp'=>'8472', 'image'=>'8465', 'real'=>'8476', 'trade'=>'8482', 'alefsym'=>'8501', 'larr'=>'8592', 'uarr'=>'8593', 'rarr'=>'8594', 'darr'=>'8595', 'harr'=>'8596', 'crarr'=>'8629', 'lArr'=>'8656', 'uArr'=>'8657', 'rArr'=>'8658', 'dArr'=>'8659', 'hArr'=>'8660', 'forall'=>'8704', 'part'=>'8706', 'exist'=>'8707', 'empty'=>'8709', 'nabla'=>'8711', 'isin'=>'8712', 'notin'=>'8713', 'ni'=>'8715', 'prod'=>'8719', 'sum'=>'8721', 'minus'=>'8722', 'lowast'=>'8727', 'radic'=>'8730', 'prop'=>'8733', 'infin'=>'8734', 'ang'=>'8736', 'and'=>'8743', 'or'=>'8744', 'cap'=>'8745', 'cup'=>'8746', 'int'=>'8747', 'there4'=>'8756', 'sim'=>'8764', 'cong'=>'8773', 'asymp'=>'8776', 'ne'=>'8800', 'equiv'=>'8801', 'le'=>'8804', 'ge'=>'8805', 'sub'=>'8834', 'sup'=>'8835', 'nsub'=>'8836', 'sube'=>'8838', 'supe'=>'8839', 'oplus'=>'8853', 'otimes'=>'8855', 'perp'=>'8869', 'sdot'=>'8901', 'lceil'=>'8968', 'rceil'=>'8969', 'lfloor'=>'8970', 'rfloor'=>'8971', 'lang'=>'9001', 'rang'=>'9002', 'loz'=>'9674', 'spades'=>'9824', 'clubs'=>'9827', 'hearts'=>'9829', 'diams'=>'9830', 'apos'=>'39', 'OElig'=>'338', 'oelig'=>'339', 'Scaron'=>'352', 'scaron'=>'353', 'Yuml'=>'376', 'circ'=>'710', 'tilde'=>'732', 'ensp'=>'8194', 'emsp'=>'8195', 'thinsp'=>'8201', 'zwnj'=>'8204', 'zwj'=>'8205', 'lrm'=>'8206', 'rlm'=>'8207', 'ndash'=>'8211', 'mdash'=>'8212', 'lsquo'=>'8216', 'rsquo'=>'8217', 'sbquo'=>'8218', 'ldquo'=>'8220', 'rdquo'=>'8221', 'bdquo'=>'8222', 'dagger'=>'8224', 'Dagger'=>'8225', 'permil'=>'8240', 'lsaquo'=>'8249', 'rsaquo'=>'8250', 'euro'=>'8364', 'nbsp'=>'160', 'iexcl'=>'161', 'cent'=>'162', 'pound'=>'163', 'curren'=>'164', 'yen'=>'165', 'brvbar'=>'166', 'sect'=>'167', 'uml'=>'168', 'copy'=>'169', 'ordf'=>'170', 'laquo'=>'171', 'not'=>'172', 'shy'=>'173', 'reg'=>'174', 'macr'=>'175', 'deg'=>'176', 'plusmn'=>'177', 'sup2'=>'178', 'sup3'=>'179', 'acute'=>'180', 'micro'=>'181', 'para'=>'182', 'middot'=>'183', 'cedil'=>'184', 'sup1'=>'185', 'ordm'=>'186', 'raquo'=>'187', 'frac14'=>'188', 'frac12'=>'189', 'frac34'=>'190', 'iquest'=>'191', 'Agrave'=>'192', 'Aacute'=>'193', 'Acirc'=>'194', 'Atilde'=>'195', 'Auml'=>'196', 'Aring'=>'197', 'AElig'=>'198', 'Ccedil'=>'199', 'Egrave'=>'200', 'Eacute'=>'201', 'Ecirc'=>'202', 'Euml'=>'203', 'Igrave'=>'204', 'Iacute'=>'205', 'Icirc'=>'206', 'Iuml'=>'207', 'ETH'=>'208', 'Ntilde'=>'209', 'Ograve'=>'210', 'Oacute'=>'211', 'Ocirc'=>'212', 'Otilde'=>'213', 'Ouml'=>'214', 'times'=>'215', 'Oslash'=>'216', 'Ugrave'=>'217', 'Uacute'=>'218', 'Ucirc'=>'219', 'Uuml'=>'220', 'Yacute'=>'221', 'THORN'=>'222', 'szlig'=>'223', 'agrave'=>'224', 'aacute'=>'225', 'acirc'=>'226', 'atilde'=>'227', 'auml'=>'228', 'aring'=>'229', 'aelig'=>'230', 'ccedil'=>'231', 'egrave'=>'232', 'eacute'=>'233', 'ecirc'=>'234', 'euml'=>'235', 'igrave'=>'236', 'iacute'=>'237', 'icirc'=>'238', 'iuml'=>'239', 'eth'=>'240', 'ntilde'=>'241', 'ograve'=>'242', 'oacute'=>'243', 'ocirc'=>'244', 'otilde'=>'245', 'ouml'=>'246', 'divide'=>'247', 'oslash'=>'248', 'ugrave'=>'249', 'uacute'=>'250', 'ucirc'=>'251', 'uuml'=>'252', 'yacute'=>'253', 'thorn'=>'254', 'yuml'=>'255'); | 324 | static $N = array('fnof'=>'402', 'Alpha'=>'913', 'Beta'=>'914', 'Gamma'=>'915', 'Delta'=>'916', 'Epsilon'=>'917', 'Zeta'=>'918', 'Eta'=>'919', 'Theta'=>'920', 'Iota'=>'921', 'Kappa'=>'922', 'Lambda'=>'923', 'Mu'=>'924', 'Nu'=>'925', 'Xi'=>'926', 'Omicron'=>'927', 'Pi'=>'928', 'Rho'=>'929', 'Sigma'=>'931', 'Tau'=>'932', 'Upsilon'=>'933', 'Phi'=>'934', 'Chi'=>'935', 'Psi'=>'936', 'Omega'=>'937', 'alpha'=>'945', 'beta'=>'946', 'gamma'=>'947', 'delta'=>'948', 'epsilon'=>'949', 'zeta'=>'950', 'eta'=>'951', 'theta'=>'952', 'iota'=>'953', 'kappa'=>'954', 'lambda'=>'955', 'mu'=>'956', 'nu'=>'957', 'xi'=>'958', 'omicron'=>'959', 'pi'=>'960', 'rho'=>'961', 'sigmaf'=>'962', 'sigma'=>'963', 'tau'=>'964', 'upsilon'=>'965', 'phi'=>'966', 'chi'=>'967', 'psi'=>'968', 'omega'=>'969', 'thetasym'=>'977', 'upsih'=>'978', 'piv'=>'982', 'bull'=>'8226', 'hellip'=>'8230', 'prime'=>'8242', 'Prime'=>'8243', 'oline'=>'8254', 'frasl'=>'8260', 'weierp'=>'8472', 'image'=>'8465', 'real'=>'8476', 'trade'=>'8482', 'alefsym'=>'8501', 'larr'=>'8592', 'uarr'=>'8593', 'rarr'=>'8594', 'darr'=>'8595', 'harr'=>'8596', 'crarr'=>'8629', 'lArr'=>'8656', 'uArr'=>'8657', 'rArr'=>'8658', 'dArr'=>'8659', 'hArr'=>'8660', 'forall'=>'8704', 'part'=>'8706', 'exist'=>'8707', 'empty'=>'8709', 'nabla'=>'8711', 'isin'=>'8712', 'notin'=>'8713', 'ni'=>'8715', 'prod'=>'8719', 'sum'=>'8721', 'minus'=>'8722', 'lowast'=>'8727', 'radic'=>'8730', 'prop'=>'8733', 'infin'=>'8734', 'ang'=>'8736', 'and'=>'8743', 'or'=>'8744', 'cap'=>'8745', 'cup'=>'8746', 'int'=>'8747', 'there4'=>'8756', 'sim'=>'8764', 'cong'=>'8773', 'asymp'=>'8776', 'ne'=>'8800', 'equiv'=>'8801', 'le'=>'8804', 'ge'=>'8805', 'sub'=>'8834', 'sup'=>'8835', 'nsub'=>'8836', 'sube'=>'8838', 'supe'=>'8839', 'oplus'=>'8853', 'otimes'=>'8855', 'perp'=>'8869', 'sdot'=>'8901', 'lceil'=>'8968', 'rceil'=>'8969', 'lfloor'=>'8970', 'rfloor'=>'8971', 'lang'=>'9001', 'rang'=>'9002', 'loz'=>'9674', 'spades'=>'9824', 'clubs'=>'9827', 'hearts'=>'9829', 'diams'=>'9830', 'apos'=>'39', 'OElig'=>'338', 'oelig'=>'339', 'Scaron'=>'352', 'scaron'=>'353', 'Yuml'=>'376', 'circ'=>'710', 'tilde'=>'732', 'ensp'=>'8194', 'emsp'=>'8195', 'thinsp'=>'8201', 'zwnj'=>'8204', 'zwj'=>'8205', 'lrm'=>'8206', 'rlm'=>'8207', 'ndash'=>'8211', 'mdash'=>'8212', 'lsquo'=>'8216', 'rsquo'=>'8217', 'sbquo'=>'8218', 'ldquo'=>'8220', 'rdquo'=>'8221', 'bdquo'=>'8222', 'dagger'=>'8224', 'Dagger'=>'8225', 'permil'=>'8240', 'lsaquo'=>'8249', 'rsaquo'=>'8250', 'euro'=>'8364', 'nbsp'=>'160', 'iexcl'=>'161', 'cent'=>'162', 'pound'=>'163', 'curren'=>'164', 'yen'=>'165', 'brvbar'=>'166', 'sect'=>'167', 'uml'=>'168', 'copy'=>'169', 'ordf'=>'170', 'laquo'=>'171', 'not'=>'172', 'shy'=>'173', 'reg'=>'174', 'macr'=>'175', 'deg'=>'176', 'plusmn'=>'177', 'sup2'=>'178', 'sup3'=>'179', 'acute'=>'180', 'micro'=>'181', 'para'=>'182', 'middot'=>'183', 'cedil'=>'184', 'sup1'=>'185', 'ordm'=>'186', 'raquo'=>'187', 'frac14'=>'188', 'frac12'=>'189', 'frac34'=>'190', 'iquest'=>'191', 'Agrave'=>'192', 'Aacute'=>'193', 'Acirc'=>'194', 'Atilde'=>'195', 'Auml'=>'196', 'Aring'=>'197', 'AElig'=>'198', 'Ccedil'=>'199', 'Egrave'=>'200', 'Eacute'=>'201', 'Ecirc'=>'202', 'Euml'=>'203', 'Igrave'=>'204', 'Iacute'=>'205', 'Icirc'=>'206', 'Iuml'=>'207', 'ETH'=>'208', 'Ntilde'=>'209', 'Ograve'=>'210', 'Oacute'=>'211', 'Ocirc'=>'212', 'Otilde'=>'213', 'Ouml'=>'214', 'times'=>'215', 'Oslash'=>'216', 'Ugrave'=>'217', 'Uacute'=>'218', 'Ucirc'=>'219', 'Uuml'=>'220', 'Yacute'=>'221', 'THORN'=>'222', 'szlig'=>'223', 'agrave'=>'224', 'aacute'=>'225', 'acirc'=>'226', 'atilde'=>'227', 'auml'=>'228', 'aring'=>'229', 'aelig'=>'230', 'ccedil'=>'231', 'egrave'=>'232', 'eacute'=>'233', 'ecirc'=>'234', 'euml'=>'235', 'igrave'=>'236', 'iacute'=>'237', 'icirc'=>'238', 'iuml'=>'239', 'eth'=>'240', 'ntilde'=>'241', 'ograve'=>'242', 'oacute'=>'243', 'ocirc'=>'244', 'otilde'=>'245', 'ouml'=>'246', 'divide'=>'247', 'oslash'=>'248', 'ugrave'=>'249', 'uacute'=>'250', 'ucirc'=>'251', 'uuml'=>'252', 'yacute'=>'253', 'thorn'=>'254', 'yuml'=>'255'); |
325 | if($t[0] != '#'){ | 325 | if($t[0] != '#'){ |
326 | return ($C['and_mark'] ? "\x06" : '&'). (isset($U[$t]) ? $t : (isset($N[$t]) ? (!$C['named_entity'] ? '#'. ($C['hexdec_entity'] > 1 ? 'x'. dechex($N[$t]) : $N[$t]) : $t) : 'amp;'. $t)). ';'; | 326 | return ($C['and_mark'] ? "\x06" : '&'). (isset($U[$t]) ? $t : (isset($N[$t]) ? (!$C['named_entity'] ? '#'. ($C['hexdec_entity'] > 1 ? 'x'. dechex($N[$t]) : $N[$t]) : $t) : 'amp;'. $t)). ';'; |
327 | } | 327 | } |
328 | if(($n = ctype_digit($t = substr($t, 1)) ? intval($t) : hexdec(substr($t, 1))) < 9 or ($n > 13 && $n < 32) or $n == 11 or $n == 12 or ($n > 126 && $n < 160 && $n != 133) or ($n > 55295 && ($n < 57344 or ($n > 64975 && $n < 64992) or $n == 65534 or $n == 65535 or $n > 1114111))){ | 328 | if(($n = ctype_digit($t = substr($t, 1)) ? intval($t) : hexdec(substr($t, 1))) < 9 or ($n > 13 && $n < 32) or $n == 11 or $n == 12 or ($n > 126 && $n < 160 && $n != 133) or ($n > 55295 && ($n < 57344 or ($n > 64975 && $n < 64992) or $n == 65534 or $n == 65535 or $n > 1114111))){ |
329 | return ($C['and_mark'] ? "\x06" : '&'). "amp;#{$t};"; | 329 | return ($C['and_mark'] ? "\x06" : '&'). "amp;#{$t};"; |
330 | } | 330 | } |
331 | return ($C['and_mark'] ? "\x06" : '&'). '#'. (((ctype_digit($t) && $C['hexdec_entity'] < 2) or !$C['hexdec_entity']) ? $n : 'x'. dechex($n)). ';'; | 331 | return ($C['and_mark'] ? "\x06" : '&'). '#'. (((ctype_digit($t) && $C['hexdec_entity'] < 2) or !$C['hexdec_entity']) ? $n : 'x'. dechex($n)). ';'; |
332 | } | 332 | } |
333 | 333 | ||
334 | function hl_prot($p, $c=null){ | 334 | function hl_prot($p, $c=null){ |
335 | // check URL scheme | 335 | // check URL scheme |
336 | global $C; | 336 | global $C; |
337 | $b = $a = ''; | 337 | $b = $a = ''; |
338 | if($c == null){$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]);} | 338 | if($c == null){$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]);} |
339 | $c = isset($C['schemes'][$c]) ? $C['schemes'][$c] : $C['schemes']['*']; | 339 | $c = isset($C['schemes'][$c]) ? $C['schemes'][$c] : $C['schemes']['*']; |
340 | static $d = 'denied:'; | 340 | static $d = 'denied:'; |
341 | if(isset($c['!']) && substr($p, 0, 7) != $d){$p = "$d$p";} | 341 | if(isset($c['!']) && substr($p, 0, 7) != $d){$p = "$d$p";} |
342 | if(isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d)){return "{$b}{$p}{$a}";} // All ok, frag, query, param | 342 | if(isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d)){return "{$b}{$p}{$a}";} // All ok, frag, query, param |
343 | if(preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])])){ // Denied prot | 343 | if(preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])])){ // Denied prot |
344 | return "{$b}{$d}{$p}{$a}"; | 344 | return "{$b}{$d}{$p}{$a}"; |
345 | } | 345 | } |
346 | if($C['abs_url']){ | 346 | if($C['abs_url']){ |
347 | if($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0){ // Make url rel | 347 | if($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0){ // Make url rel |
348 | $p = substr($p, strlen($C['base_url'])); | 348 | $p = substr($p, strlen($C['base_url'])); |
349 | }elseif(empty($m[1])){ // Make URL abs | 349 | }elseif(empty($m[1])){ // Make URL abs |
350 | if(substr($p, 0, 2) == '//'){$p = substr($C['base_url'], 0, strpos($C['base_url'], ':')+1). $p;} | 350 | if(substr($p, 0, 2) == '//'){$p = substr($C['base_url'], 0, strpos($C['base_url'], ':')+1). $p;} |
351 | elseif($p[0] == '/'){$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']). $p;} | 351 | elseif($p[0] == '/'){$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']). $p;} |
352 | elseif(strcspn($p, './')){$p = $C['base_url']. $p;} | 352 | elseif(strcspn($p, './')){$p = $C['base_url']. $p;} |
353 | else{ | 353 | else{ |
354 | preg_match('`^([a-zA-Z\d\-+.]+://[^/]+)(.*)`', $C['base_url'], $m); | 354 | preg_match('`^([a-zA-Z\d\-+.]+://[^/]+)(.*)`', $C['base_url'], $m); |
355 | $p = preg_replace('`(?<=/)\./`', '', $m[2]. $p); | 355 | $p = preg_replace('`(?<=/)\./`', '', $m[2]. $p); |
356 | while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)){ | 356 | while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)){ |
357 | $p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p); | 357 | $p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p); |
358 | } | 358 | } |
359 | $p = $m[1]. $p; | 359 | $p = $m[1]. $p; |
360 | } | 360 | } |
361 | } | 361 | } |
362 | } | 362 | } |
363 | return "{$b}{$p}{$a}"; | 363 | return "{$b}{$p}{$a}"; |
364 | } | 364 | } |
365 | 365 | ||
366 | function hl_regex($p){ | 366 | function hl_regex($p){ |
367 | // check regex | 367 | // check regex |
368 | if(empty($p)){return 0;} | 368 | if(empty($p)){return 0;} |
369 | if($v = function_exists('error_clear_last') && function_exists('error_get_last')){error_clear_last();} | 369 | if($v = function_exists('error_clear_last') && function_exists('error_get_last')){error_clear_last();} |
370 | else{ | 370 | else{ |
371 | if($t = ini_get('track_errors')){$o = isset($php_errormsg) ? $php_errormsg : null;} | 371 | if($t = ini_get('track_errors')){$o = isset($php_errormsg) ? $php_errormsg : null;} |
372 | else{ini_set('track_errors', 1);} | 372 | else{ini_set('track_errors', 1);} |
373 | unset($php_errormsg); | 373 | unset($php_errormsg); |
374 | } | 374 | } |
375 | if(($d = ini_get('display_errors'))){ini_set('display_errors', 0);} | 375 | if(($d = ini_get('display_errors'))){ini_set('display_errors', 0);} |
376 | preg_match($p, ''); | 376 | preg_match($p, ''); |
377 | if($v){$r = error_get_last() == null ? 1 : 0; } | 377 | if($v){$r = error_get_last() == null ? 1 : 0; } |
378 | else{ | 378 | else{ |
379 | $r = isset($php_errormsg) ? 0 : 1; | 379 | $r = isset($php_errormsg) ? 0 : 1; |
380 | if($t){$php_errormsg = isset($o) ? $o : null;} | 380 | if($t){$php_errormsg = isset($o) ? $o : null;} |
381 | else{ini_set('track_errors', 0);} | 381 | else{ini_set('track_errors', 0);} |
382 | } | 382 | } |
383 | if($d){ini_set('display_errors', 1);} | 383 | if($d){ini_set('display_errors', 1);} |
384 | return $r; | 384 | return $r; |
385 | } | 385 | } |
386 | 386 | ||
387 | function hl_spec($t){ | 387 | function hl_spec($t){ |
388 | // final $spec | 388 | // final $spec |
389 | $s = array(); | 389 | $s = array(); |
390 | if(!function_exists('hl_aux1')){function hl_aux1($m){ | 390 | if(!function_exists('hl_aux1')){function hl_aux1($m){ |
391 | return substr(str_replace(array(";", "|", "~", " ", ",", "/", "(", ")", '`"'), array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", '"'), $m[0]), 1, -1); | 391 | return substr(str_replace(array(";", "|", "~", " ", ",", "/", "(", ")", '`"'), array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", '"'), $m[0]), 1, -1); |
392 | }} | 392 | }} |
393 | $t = str_replace(array("\t", "\r", "\n", ' '), '', preg_replace_callback('/"(?>(`.|[^"])*)"/sm', 'hl_aux1', trim($t))); | 393 | $t = str_replace(array("\t", "\r", "\n", ' '), '', preg_replace_callback('/"(?>(`.|[^"])*)"/sm', 'hl_aux1', trim($t))); |
394 | for($i = count(($t = explode(';', $t))); --$i>=0;){ | 394 | for($i = count(($t = explode(';', $t))); --$i>=0;){ |
395 | $w = $t[$i]; | 395 | $w = $t[$i]; |
396 | if(empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a = substr($w, $e+1)))){continue;} | 396 | if(empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a = substr($w, $e+1)))){continue;} |
397 | $y = $n = array(); | 397 | $y = $n = array(); |
398 | foreach(explode(',', $a) as $v){ | 398 | foreach(explode(',', $a) as $v){ |
399 | if(!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m)){continue;} | 399 | if(!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m)){continue;} |
400 | if(($x = strtolower($m[1])) == '-*'){$n['*'] = 1; continue;} | 400 | if(($x = strtolower($m[1])) == '-*'){$n['*'] = 1; continue;} |
401 | if($x[0] == '-'){$n[substr($x, 1)] = 1; continue;} | 401 | if($x[0] == '-'){$n[substr($x, 1)] = 1; continue;} |
402 | if(!isset($m[2])){$y[$x] = 1; continue;} | 402 | if(!isset($m[2])){$y[$x] = 1; continue;} |
403 | foreach(explode('/', $m[2]) as $m){ | 403 | foreach(explode('/', $m[2]) as $m){ |
404 | if(empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5){$y[$x] = 1; continue;} | 404 | if(empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5){$y[$x] = 1; continue;} |
405 | $y[$x][strtolower(substr($m, 0, $p))] = str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08"), array(";", "|", "~", " ", ",", "/", "(", ")"), substr($m, $p+1)); | 405 | $y[$x][strtolower(substr($m, 0, $p))] = str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08"), array(";", "|", "~", " ", ",", "/", "(", ")"), substr($m, $p+1)); |
406 | } | 406 | } |
407 | if(isset($y[$x]['match']) && !hl_regex($y[$x]['match'])){unset($y[$x]['match']);} | 407 | if(isset($y[$x]['match']) && !hl_regex($y[$x]['match'])){unset($y[$x]['match']);} |
408 | if(isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch'])){unset($y[$x]['nomatch']);} | 408 | if(isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch'])){unset($y[$x]['nomatch']);} |
409 | } | 409 | } |
410 | if(!count($y) && !count($n)){continue;} | 410 | if(!count($y) && !count($n)){continue;} |
411 | foreach(explode(',', substr($w, 0, $e)) as $v){ | 411 | foreach(explode(',', substr($w, 0, $e)) as $v){ |
412 | if(!strlen(($v = strtolower($v)))){continue;} | 412 | if(!strlen(($v = strtolower($v)))){continue;} |
413 | if(count($y)){if(!isset($s[$v])){$s[$v] = $y;} else{$s[$v] = array_merge($s[$v], $y);}} | 413 | if(count($y)){if(!isset($s[$v])){$s[$v] = $y;} else{$s[$v] = array_merge($s[$v], $y);}} |
414 | if(count($n)){if(!isset($s[$v]['n'])){$s[$v]['n'] = $n;} else{$s[$v]['n'] = array_merge($s[$v]['n'], $n);}} | 414 | if(count($n)){if(!isset($s[$v]['n'])){$s[$v]['n'] = $n;} else{$s[$v]['n'] = array_merge($s[$v]['n'], $n);}} |
415 | } | 415 | } |
416 | } | 416 | } |
417 | return $s; | 417 | return $s; |
418 | } | 418 | } |
419 | 419 | ||
420 | function hl_tag($t){ | 420 | function hl_tag($t){ |
421 | // tag/attribute handler | 421 | // tag/attribute handler |
422 | global $C; | 422 | global $C; |
423 | $t = $t[0]; | 423 | $t = $t[0]; |
424 | // invalid < > | 424 | // invalid < > |
425 | if($t == '< '){return '< ';} | 425 | if($t == '< '){return '< ';} |
426 | if($t == '>'){return '>';} | 426 | if($t == '>'){return '>';} |
427 | if(!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m)){ | 427 | if(!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m)){ |
428 | return str_replace(array('<', '>'), array('<', '>'), $t); | 428 | return str_replace(array('<', '>'), array('<', '>'), $t); |
429 | }elseif(!isset($C['elements'][($e = strtolower($m[2]))])){ | 429 | }elseif(!isset($C['elements'][($e = strtolower($m[2]))])){ |
430 | return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('<', '>'), $t) : ''); | 430 | return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('<', '>'), $t) : ''); |
431 | } | 431 | } |
432 | // attr string | 432 | // attr string |
433 | $a = str_replace(array("\n", "\r", "\t"), ' ', trim($m[3])); | 433 | $a = str_replace(array("\n", "\r", "\t"), ' ', trim($m[3])); |
434 | // tag transform | 434 | // tag transform |
435 | static $eD = array('acronym'=>1, 'applet'=>1, 'big'=>1, 'center'=>1, 'dir'=>1, 'font'=>1, 'isindex'=>1, 's'=>1, 'strike'=>1, 'tt'=>1); // Deprecated | 435 | static $eD = array('acronym'=>1, 'applet'=>1, 'big'=>1, 'center'=>1, 'dir'=>1, 'font'=>1, 'isindex'=>1, 's'=>1, 'strike'=>1, 'tt'=>1); // Deprecated |
436 | if($C['make_tag_strict'] && isset($eD[$e])){ | 436 | if($C['make_tag_strict'] && isset($eD[$e])){ |
437 | $trt = hl_tag2($e, $a, $C['make_tag_strict']); | 437 | $trt = hl_tag2($e, $a, $C['make_tag_strict']); |
438 | if(!$e){return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('<', '>'), $t) : '');} | 438 | if(!$e){return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('<', '>'), $t) : '');} |
439 | } | 439 | } |
440 | // close tag | 440 | // close tag |
441 | static $eE = array('area'=>1, 'br'=>1, 'col'=>1, 'command'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'keygen'=>1, 'link'=>1, 'meta'=>1, 'param'=>1, 'source'=>1, 'track'=>1, 'wbr'=>1); // Empty ele | 441 | static $eE = array('area'=>1, 'br'=>1, 'col'=>1, 'command'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'keygen'=>1, 'link'=>1, 'meta'=>1, 'param'=>1, 'source'=>1, 'track'=>1, 'wbr'=>1); // Empty ele |
442 | if(!empty($m[1])){ | 442 | if(!empty($m[1])){ |
443 | return (!isset($eE[$e]) ? (empty($C['hook_tag']) ? "</$e>" : $C['hook_tag']($e)) : (($C['keep_bad'])%2 ? str_replace(array('<', '>'), array('<', '>'), $t) : '')); | 443 | return (!isset($eE[$e]) ? (empty($C['hook_tag']) ? "</$e>" : $C['hook_tag']($e)) : (($C['keep_bad'])%2 ? str_replace(array('<', '>'), array('<', '>'), $t) : '')); |
444 | } | 444 | } |
445 | 445 | ||
446 | // open tag & attr | 446 | // open tag & attr |
447 | static $aN = array('abbr'=>array('td'=>1, 'th'=>1), 'accept'=>array('form'=>1, 'input'=>1), 'accept-charset'=>array('form'=>1), 'action'=>array('form'=>1), 'align'=>array('applet'=>1, 'caption'=>1, 'col'=>1, 'colgroup'=>1, 'div'=>1, 'embed'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'object'=>1, 'p'=>1, 'table'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'allowfullscreen'=>array('iframe'=>1), 'alt'=>array('applet'=>1, 'area'=>1, 'img'=>1, 'input'=>1), 'archive'=>array('applet'=>1, 'object'=>1), 'async'=>array('script'=>1), 'autocomplete'=>array('form'=>1, 'input'=>1), 'autofocus'=>array('button'=>1, 'input'=>1, 'keygen'=>1, 'select'=>1, 'textarea'=>1), 'autoplay'=>array('audio'=>1, 'video'=>1), 'axis'=>array('td'=>1, 'th'=>1), 'bgcolor'=>array('embed'=>1, 'table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1), 'border'=>array('img'=>1, 'object'=>1, 'table'=>1), 'bordercolor'=>array('table'=>1, 'td'=>1, 'tr'=>1), 'cellpadding'=>array('table'=>1), 'cellspacing'=>array('table'=>1), 'challenge'=>array('keygen'=>1), 'char'=>array('col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'charoff'=>array('col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'charset'=>array('a'=>1, 'script'=>1), 'checked'=>array('command'=>1, 'input'=>1), 'cite'=>array('blockquote'=>1, 'del'=>1, 'ins'=>1, 'q'=>1), 'classid'=>array('object'=>1), 'clear'=>array('br'=>1), 'code'=>array('applet'=>1), 'codebase'=>array('applet'=>1, 'object'=>1), 'codetype'=>array('object'=>1), 'color'=>array('font'=>1), 'cols'=>array('textarea'=>1), 'colspan'=>array('td'=>1, 'th'=>1), 'compact'=>array('dir'=>1, 'dl'=>1, 'menu'=>1, 'ol'=>1, 'ul'=>1), 'content'=>array('meta'=>1), 'controls'=>array('audio'=>1, 'video'=>1), 'coords'=>array('a'=>1, 'area'=>1), 'crossorigin'=>array('img'=>1), 'data'=>array('object'=>1), 'datetime'=>array('del'=>1, 'ins'=>1, 'time'=>1), 'declare'=>array('object'=>1), 'default'=>array('track'=>1), 'defer'=>array('script'=>1), 'dirname'=>array('input'=>1, 'textarea'=>1), 'disabled'=>array('button'=>1, 'command'=>1, 'fieldset'=>1, 'input'=>1, 'keygen'=>1, 'optgroup'=>1, 'option'=>1, 'select'=>1, 'textarea'=>1), 'download'=>array('a'=>1), 'enctype'=>array('form'=>1), 'face'=>array('font'=>1), 'flashvars'=>array('embed'=>1), 'for'=>array('label'=>1, 'output'=>1), 'form'=>array('button'=>1, 'fieldset'=>1, 'input'=>1, 'keygen'=>1, 'label'=>1, 'object'=>1, 'output'=>1, 'select'=>1, 'textarea'=>1), 'formaction'=>array('button'=>1, 'input'=>1), 'formenctype'=>array('button'=>1, 'input'=>1), 'formmethod'=>array('button'=>1, 'input'=>1), 'formnovalidate'=>array('button'=>1, 'input'=>1), 'formtarget'=>array('button'=>1, 'input'=>1), 'frame'=>array('table'=>1), 'frameborder'=>array('iframe'=>1), 'headers'=>array('td'=>1, 'th'=>1), 'height'=>array('applet'=>1, 'canvas'=>1, 'embed'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'object'=>1, 'td'=>1, 'th'=>1, 'video'=>1), 'high'=>array('meter'=>1), 'href'=>array('a'=>1, 'area'=>1, 'link'=>1), 'hreflang'=>array('a'=>1, 'area'=>1, 'link'=>1), 'hspace'=>array('applet'=>1, 'embed'=>1, 'img'=>1, 'object'=>1), 'icon'=>array('command'=>1), 'ismap'=>array('img'=>1, 'input'=>1), 'keyparams'=>array('keygen'=>1), 'keytype'=>array('keygen'=>1), 'kind'=>array('track'=>1), 'label'=>array('command'=>1, 'menu'=>1, 'option'=>1, 'optgroup'=>1, 'track'=>1), 'language'=>array('script'=>1), 'list'=>array('input'=>1), 'longdesc'=>array('img'=>1, 'iframe'=>1), 'loop'=>array('audio'=>1, 'video'=>1), 'low'=>array('meter'=>1), 'marginheight'=>array('iframe'=>1), 'marginwidth'=>array('iframe'=>1), 'max'=>array('input'=>1, 'meter'=>1, 'progress'=>1), 'maxlength'=>array('input'=>1, 'textarea'=>1), 'media'=>array('a'=>1, 'area'=>1, 'link'=>1, 'source'=>1, 'style'=>1), 'mediagroup'=>array('audio'=>1, 'video'=>1), 'method'=>array('form'=>1), 'min'=>array('input'=>1, 'meter'=>1), 'model'=>array('embed'=>1), 'multiple'=>array('input'=>1, 'select'=>1), 'muted'=>array('audio'=>1, 'video'=>1), 'name'=>array('a'=>1, 'applet'=>1, 'button'=>1, 'embed'=>1, 'fieldset'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'keygen'=>1, 'map'=>1, 'object'=>1, 'output'=>1, 'param'=>1, 'select'=>1, 'textarea'=>1), 'nohref'=>array('area'=>1), 'noshade'=>array('hr'=>1), 'novalidate'=>array('form'=>1), 'nowrap'=>array('td'=>1, 'th'=>1), 'object'=>array('applet'=>1), 'open'=>array('details'=>1), 'optimum'=>array('meter'=>1), 'pattern'=>array('input'=>1), 'ping'=>array('a'=>1, 'area'=>1), 'placeholder'=>array('input'=>1, 'textarea'=>1), 'pluginspage'=>array('embed'=>1), 'pluginurl'=>array('embed'=>1), 'poster'=>array('video'=>1), 'pqg'=>array('keygen'=>1), 'preload'=>array('audio'=>1, 'video'=>1), 'prompt'=>array('isindex'=>1), 'pubdate'=>array('time'=>1), 'radiogroup'=>array('command'=>1), 'readonly'=>array('input'=>1, 'textarea'=>1), 'rel'=>array('a'=>1, 'area'=>1, 'link'=>1), 'required'=>array('input'=>1, 'select'=>1, 'textarea'=>1), 'rev'=>array('a'=>1), 'reversed'=>array('ol'=>1), 'rows'=>array('textarea'=>1), 'rowspan'=>array('td'=>1, 'th'=>1), 'rules'=>array('table'=>1), 'sandbox'=>array('iframe'=>1), 'scope'=>array('td'=>1, 'th'=>1), 'scoped'=>array('style'=>1), 'scrolling'=>array('iframe'=>1), 'seamless'=>array('iframe'=>1), 'selected'=>array('option'=>1), 'shape'=>array('a'=>1, 'area'=>1), 'size'=>array('font'=>1, 'hr'=>1, 'input'=>1, 'select'=>1), 'sizes'=>array('link'=>1), 'span'=>array('col'=>1, 'colgroup'=>1), 'src'=>array('audio'=>1, 'embed'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'script'=>1, 'source'=>1, 'track'=>1, 'video'=>1), 'srcdoc'=>array('iframe'=>1), 'srclang'=>array('track'=>1), 'srcset'=>array('img'=>1), 'standby'=>array('object'=>1), 'start'=>array('ol'=>1), 'step'=>array('input'=>1), 'summary'=>array('table'=>1), 'target'=>array('a'=>1, 'area'=>1, 'form'=>1), 'type'=>array('a'=>1, 'area'=>1, 'button'=>1, 'command'=>1, 'embed'=>1, 'input'=>1, 'li'=>1, 'link'=>1, 'menu'=>1, 'object'=>1, 'ol'=>1, 'param'=>1, 'script'=>1, 'source'=>1, 'style'=>1, 'ul'=>1), 'typemustmatch'=>array('object'=>1), 'usemap'=>array('img'=>1, 'input'=>1, 'object'=>1), 'valign'=>array('col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'value'=>array('button'=>1, 'data'=>1, 'input'=>1, 'li'=>1, 'meter'=>1, 'option'=>1, 'param'=>1, 'progress'=>1), 'valuetype'=>array('param'=>1), 'vspace'=>array('applet'=>1, 'embed'=>1, 'img'=>1, 'object'=>1), 'width'=>array('applet'=>1, 'canvas'=>1, 'col'=>1, 'colgroup'=>1, 'embed'=>1, 'hr'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'object'=>1, 'pre'=>1, 'table'=>1, 'td'=>1, 'th'=>1, 'video'=>1), 'wmode'=>array('embed'=>1), 'wrap'=>array('textarea'=>1)); // Ele-specific | 447 | static $aN = array('abbr'=>array('td'=>1, 'th'=>1), 'accept'=>array('form'=>1, 'input'=>1), 'accept-charset'=>array('form'=>1), 'action'=>array('form'=>1), 'align'=>array('applet'=>1, 'caption'=>1, 'col'=>1, 'colgroup'=>1, 'div'=>1, 'embed'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'object'=>1, 'p'=>1, 'table'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'allowfullscreen'=>array('iframe'=>1), 'alt'=>array('applet'=>1, 'area'=>1, 'img'=>1, 'input'=>1), 'archive'=>array('applet'=>1, 'object'=>1), 'async'=>array('script'=>1), 'autocomplete'=>array('form'=>1, 'input'=>1), 'autofocus'=>array('button'=>1, 'input'=>1, 'keygen'=>1, 'select'=>1, 'textarea'=>1), 'autoplay'=>array('audio'=>1, 'video'=>1), 'axis'=>array('td'=>1, 'th'=>1), 'bgcolor'=>array('embed'=>1, 'table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1), 'border'=>array('img'=>1, 'object'=>1, 'table'=>1), 'bordercolor'=>array('table'=>1, 'td'=>1, 'tr'=>1), 'cellpadding'=>array('table'=>1), 'cellspacing'=>array('table'=>1), 'challenge'=>array('keygen'=>1), 'char'=>array('col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'charoff'=>array('col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'charset'=>array('a'=>1, 'script'=>1), 'checked'=>array('command'=>1, 'input'=>1), 'cite'=>array('blockquote'=>1, 'del'=>1, 'ins'=>1, 'q'=>1), 'classid'=>array('object'=>1), 'clear'=>array('br'=>1), 'code'=>array('applet'=>1), 'codebase'=>array('applet'=>1, 'object'=>1), 'codetype'=>array('object'=>1), 'color'=>array('font'=>1), 'cols'=>array('textarea'=>1), 'colspan'=>array('td'=>1, 'th'=>1), 'compact'=>array('dir'=>1, 'dl'=>1, 'menu'=>1, 'ol'=>1, 'ul'=>1), 'content'=>array('meta'=>1), 'controls'=>array('audio'=>1, 'video'=>1), 'coords'=>array('a'=>1, 'area'=>1), 'crossorigin'=>array('img'=>1), 'data'=>array('object'=>1), 'datetime'=>array('del'=>1, 'ins'=>1, 'time'=>1), 'declare'=>array('object'=>1), 'default'=>array('track'=>1), 'defer'=>array('script'=>1), 'dirname'=>array('input'=>1, 'textarea'=>1), 'disabled'=>array('button'=>1, 'command'=>1, 'fieldset'=>1, 'input'=>1, 'keygen'=>1, 'optgroup'=>1, 'option'=>1, 'select'=>1, 'textarea'=>1), 'download'=>array('a'=>1), 'enctype'=>array('form'=>1), 'face'=>array('font'=>1), 'flashvars'=>array('embed'=>1), 'for'=>array('label'=>1, 'output'=>1), 'form'=>array('button'=>1, 'fieldset'=>1, 'input'=>1, 'keygen'=>1, 'label'=>1, 'object'=>1, 'output'=>1, 'select'=>1, 'textarea'=>1), 'formaction'=>array('button'=>1, 'input'=>1), 'formenctype'=>array('button'=>1, 'input'=>1), 'formmethod'=>array('button'=>1, 'input'=>1), 'formnovalidate'=>array('button'=>1, 'input'=>1), 'formtarget'=>array('button'=>1, 'input'=>1), 'frame'=>array('table'=>1), 'frameborder'=>array('iframe'=>1), 'headers'=>array('td'=>1, 'th'=>1), 'height'=>array('applet'=>1, 'canvas'=>1, 'embed'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'object'=>1, 'td'=>1, 'th'=>1, 'video'=>1), 'high'=>array('meter'=>1), 'href'=>array('a'=>1, 'area'=>1, 'link'=>1), 'hreflang'=>array('a'=>1, 'area'=>1, 'link'=>1), 'hspace'=>array('applet'=>1, 'embed'=>1, 'img'=>1, 'object'=>1), 'icon'=>array('command'=>1), 'ismap'=>array('img'=>1, 'input'=>1), 'keyparams'=>array('keygen'=>1), 'keytype'=>array('keygen'=>1), 'kind'=>array('track'=>1), 'label'=>array('command'=>1, 'menu'=>1, 'option'=>1, 'optgroup'=>1, 'track'=>1), 'language'=>array('script'=>1), 'list'=>array('input'=>1), 'longdesc'=>array('img'=>1, 'iframe'=>1), 'loop'=>array('audio'=>1, 'video'=>1), 'low'=>array('meter'=>1), 'marginheight'=>array('iframe'=>1), 'marginwidth'=>array('iframe'=>1), 'max'=>array('input'=>1, 'meter'=>1, 'progress'=>1), 'maxlength'=>array('input'=>1, 'textarea'=>1), 'media'=>array('a'=>1, 'area'=>1, 'link'=>1, 'source'=>1, 'style'=>1), 'mediagroup'=>array('audio'=>1, 'video'=>1), 'method'=>array('form'=>1), 'min'=>array('input'=>1, 'meter'=>1), 'model'=>array('embed'=>1), 'multiple'=>array('input'=>1, 'select'=>1), 'muted'=>array('audio'=>1, 'video'=>1), 'name'=>array('a'=>1, 'applet'=>1, 'button'=>1, 'embed'=>1, 'fieldset'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'keygen'=>1, 'map'=>1, 'object'=>1, 'output'=>1, 'param'=>1, 'select'=>1, 'textarea'=>1), 'nohref'=>array('area'=>1), 'noshade'=>array('hr'=>1), 'novalidate'=>array('form'=>1), 'nowrap'=>array('td'=>1, 'th'=>1), 'object'=>array('applet'=>1), 'open'=>array('details'=>1), 'optimum'=>array('meter'=>1), 'pattern'=>array('input'=>1), 'ping'=>array('a'=>1, 'area'=>1), 'placeholder'=>array('input'=>1, 'textarea'=>1), 'pluginspage'=>array('embed'=>1), 'pluginurl'=>array('embed'=>1), 'poster'=>array('video'=>1), 'pqg'=>array('keygen'=>1), 'preload'=>array('audio'=>1, 'video'=>1), 'prompt'=>array('isindex'=>1), 'pubdate'=>array('time'=>1), 'radiogroup'=>array('command'=>1), 'readonly'=>array('input'=>1, 'textarea'=>1), 'rel'=>array('a'=>1, 'area'=>1, 'link'=>1), 'required'=>array('input'=>1, 'select'=>1, 'textarea'=>1), 'rev'=>array('a'=>1), 'reversed'=>array('ol'=>1), 'rows'=>array('textarea'=>1), 'rowspan'=>array('td'=>1, 'th'=>1), 'rules'=>array('table'=>1), 'sandbox'=>array('iframe'=>1), 'scope'=>array('td'=>1, 'th'=>1), 'scoped'=>array('style'=>1), 'scrolling'=>array('iframe'=>1), 'seamless'=>array('iframe'=>1), 'selected'=>array('option'=>1), 'shape'=>array('a'=>1, 'area'=>1), 'size'=>array('font'=>1, 'hr'=>1, 'input'=>1, 'select'=>1), 'sizes'=>array('link'=>1), 'span'=>array('col'=>1, 'colgroup'=>1), 'src'=>array('audio'=>1, 'embed'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'script'=>1, 'source'=>1, 'track'=>1, 'video'=>1), 'srcdoc'=>array('iframe'=>1), 'srclang'=>array('track'=>1), 'srcset'=>array('img'=>1), 'standby'=>array('object'=>1), 'start'=>array('ol'=>1), 'step'=>array('input'=>1), 'summary'=>array('table'=>1), 'target'=>array('a'=>1, 'area'=>1, 'form'=>1), 'type'=>array('a'=>1, 'area'=>1, 'button'=>1, 'command'=>1, 'embed'=>1, 'input'=>1, 'li'=>1, 'link'=>1, 'menu'=>1, 'object'=>1, 'ol'=>1, 'param'=>1, 'script'=>1, 'source'=>1, 'style'=>1, 'ul'=>1), 'typemustmatch'=>array('object'=>1), 'usemap'=>array('img'=>1, 'input'=>1, 'object'=>1), 'valign'=>array('col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'value'=>array('button'=>1, 'data'=>1, 'input'=>1, 'li'=>1, 'meter'=>1, 'option'=>1, 'param'=>1, 'progress'=>1), 'valuetype'=>array('param'=>1), 'vspace'=>array('applet'=>1, 'embed'=>1, 'img'=>1, 'object'=>1), 'width'=>array('applet'=>1, 'canvas'=>1, 'col'=>1, 'colgroup'=>1, 'embed'=>1, 'hr'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'object'=>1, 'pre'=>1, 'table'=>1, 'td'=>1, 'th'=>1, 'video'=>1), 'wmode'=>array('embed'=>1), 'wrap'=>array('textarea'=>1)); // Ele-specific |
448 | static $aNA = array('aria-activedescendant'=>1, 'aria-atomic'=>1, 'aria-autocomplete'=>1, 'aria-busy'=>1, 'aria-checked'=>1, 'aria-controls'=>1, 'aria-describedby'=>1, 'aria-disabled'=>1, 'aria-dropeffect'=>1, 'aria-expanded'=>1, 'aria-flowto'=>1, 'aria-grabbed'=>1, 'aria-haspopup'=>1, 'aria-hidden'=>1, 'aria-invalid'=>1, 'aria-label'=>1, 'aria-labelledby'=>1, 'aria-level'=>1, 'aria-live'=>1, 'aria-multiline'=>1, 'aria-multiselectable'=>1, 'aria-orientation'=>1, 'aria-owns'=>1, 'aria-posinset'=>1, 'aria-pressed'=>1, 'aria-readonly'=>1, 'aria-relevant'=>1, 'aria-required'=>1, 'aria-selected'=>1, 'aria-setsize'=>1, 'aria-sort'=>1, 'aria-valuemax'=>1, 'aria-valuemin'=>1, 'aria-valuenow'=>1, 'aria-valuetext'=>1); // ARIA | 448 | static $aNA = array('aria-activedescendant'=>1, 'aria-atomic'=>1, 'aria-autocomplete'=>1, 'aria-busy'=>1, 'aria-checked'=>1, 'aria-controls'=>1, 'aria-describedby'=>1, 'aria-disabled'=>1, 'aria-dropeffect'=>1, 'aria-expanded'=>1, 'aria-flowto'=>1, 'aria-grabbed'=>1, 'aria-haspopup'=>1, 'aria-hidden'=>1, 'aria-invalid'=>1, 'aria-label'=>1, 'aria-labelledby'=>1, 'aria-level'=>1, 'aria-live'=>1, 'aria-multiline'=>1, 'aria-multiselectable'=>1, 'aria-orientation'=>1, 'aria-owns'=>1, 'aria-posinset'=>1, 'aria-pressed'=>1, 'aria-readonly'=>1, 'aria-relevant'=>1, 'aria-required'=>1, 'aria-selected'=>1, 'aria-setsize'=>1, 'aria-sort'=>1, 'aria-valuemax'=>1, 'aria-valuemin'=>1, 'aria-valuenow'=>1, 'aria-valuetext'=>1); // ARIA |
449 | static $aNE = array('allowfullscreen'=>1, 'checkbox'=>1, 'checked'=>1, 'command'=>1, 'compact'=>1, 'declare'=>1, 'defer'=>1, 'default'=>1, 'disabled'=>1, 'hidden'=>1, 'inert'=>1, 'ismap'=>1, 'itemscope'=>1, 'multiple'=>1, 'nohref'=>1, 'noresize'=>1, 'noshade'=>1, 'nowrap'=>1, 'open'=>1, 'radio'=>1, 'readonly'=>1, 'required'=>1, 'reversed'=>1, 'selected'=>1); // Empty | 449 | static $aNE = array('allowfullscreen'=>1, 'checkbox'=>1, 'checked'=>1, 'command'=>1, 'compact'=>1, 'declare'=>1, 'defer'=>1, 'default'=>1, 'disabled'=>1, 'hidden'=>1, 'inert'=>1, 'ismap'=>1, 'itemscope'=>1, 'multiple'=>1, 'nohref'=>1, 'noresize'=>1, 'noshade'=>1, 'nowrap'=>1, 'open'=>1, 'radio'=>1, 'readonly'=>1, 'required'=>1, 'reversed'=>1, 'selected'=>1); // Empty |
450 | static $aNO = array('onabort'=>1, 'onblur'=>1, 'oncanplay'=>1, 'oncanplaythrough'=>1, 'onchange'=>1, 'onclick'=>1, 'oncontextmenu'=>1, 'oncopy'=>1, 'oncuechange'=>1, 'oncut'=>1, 'ondblclick'=>1, 'ondrag'=>1, 'ondragend'=>1, 'ondragenter'=>1, 'ondragleave'=>1, 'ondragover'=>1, 'ondragstart'=>1, 'ondrop'=>1, 'ondurationchange'=>1, 'onemptied'=>1, 'onended'=>1, 'onerror'=>1, 'onfocus'=>1, 'onformchange'=>1, 'onforminput'=>1, 'oninput'=>1, 'oninvalid'=>1, 'onkeydown'=>1, 'onkeypress'=>1, 'onkeyup'=>1, 'onload'=>1, 'onloadeddata'=>1, 'onloadedmetadata'=>1, 'onloadstart'=>1, 'onlostpointercapture'=>1, 'onmousedown'=>1, 'onmousemove'=>1, 'onmouseout'=>1, 'onmouseover'=>1, 'onmouseup'=>1, 'onmousewheel'=>1, 'onpaste'=>1, 'onpause'=>1, 'onplay'=>1, 'onplaying'=>1, 'onpointercancel'=>1, 'ongotpointercapture'=>1, 'onpointerdown'=>1, 'onpointerenter'=>1, 'onpointerleave'=>1, 'onpointermove'=>1, 'onpointerout'=>1, 'onpointerover'=>1, 'onpointerup'=>1, 'onprogress'=>1, 'onratechange'=>1, 'onreadystatechange'=>1, 'onreset'=>1, 'onsearch'=>1, 'onscroll'=>1, 'onseeked'=>1, 'onseeking'=>1, 'onselect'=>1, 'onshow'=>1, 'onstalled'=>1, 'onsubmit'=>1, 'onsuspend'=>1, 'ontimeupdate'=>1, 'ontoggle'=>1, 'ontouchcancel'=>1, 'ontouchend'=>1, 'ontouchmove'=>1, 'ontouchstart'=>1, 'onvolumechange'=>1, 'onwaiting'=>1, 'onwheel'=>1); // Event | 450 | static $aNO = array('onabort'=>1, 'onblur'=>1, 'oncanplay'=>1, 'oncanplaythrough'=>1, 'onchange'=>1, 'onclick'=>1, 'oncontextmenu'=>1, 'oncopy'=>1, 'oncuechange'=>1, 'oncut'=>1, 'ondblclick'=>1, 'ondrag'=>1, 'ondragend'=>1, 'ondragenter'=>1, 'ondragleave'=>1, 'ondragover'=>1, 'ondragstart'=>1, 'ondrop'=>1, 'ondurationchange'=>1, 'onemptied'=>1, 'onended'=>1, 'onerror'=>1, 'onfocus'=>1, 'onformchange'=>1, 'onforminput'=>1, 'oninput'=>1, 'oninvalid'=>1, 'onkeydown'=>1, 'onkeypress'=>1, 'onkeyup'=>1, 'onload'=>1, 'onloadeddata'=>1, 'onloadedmetadata'=>1, 'onloadstart'=>1, 'onlostpointercapture'=>1, 'onmousedown'=>1, 'onmousemove'=>1, 'onmouseout'=>1, 'onmouseover'=>1, 'onmouseup'=>1, 'onmousewheel'=>1, 'onpaste'=>1, 'onpause'=>1, 'onplay'=>1, 'onplaying'=>1, 'onpointercancel'=>1, 'ongotpointercapture'=>1, 'onpointerdown'=>1, 'onpointerenter'=>1, 'onpointerleave'=>1, 'onpointermove'=>1, 'onpointerout'=>1, 'onpointerover'=>1, 'onpointerup'=>1, 'onprogress'=>1, 'onratechange'=>1, 'onreadystatechange'=>1, 'onreset'=>1, 'onsearch'=>1, 'onscroll'=>1, 'onseeked'=>1, 'onseeking'=>1, 'onselect'=>1, 'onshow'=>1, 'onstalled'=>1, 'onsubmit'=>1, 'onsuspend'=>1, 'ontimeupdate'=>1, 'ontoggle'=>1, 'ontouchcancel'=>1, 'ontouchend'=>1, 'ontouchmove'=>1, 'ontouchstart'=>1, 'onvolumechange'=>1, 'onwaiting'=>1, 'onwheel'=>1); // Event |
451 | static $aNP = array('action'=>1, 'cite'=>1, 'classid'=>1, 'codebase'=>1, 'data'=>1, 'href'=>1, 'itemtype'=>1, 'longdesc'=>1, 'model'=>1, 'pluginspage'=>1, 'pluginurl'=>1, 'src'=>1, 'srcset'=>1, 'usemap'=>1); // Need scheme check; excludes style, on* | 451 | static $aNP = array('action'=>1, 'cite'=>1, 'classid'=>1, 'codebase'=>1, 'data'=>1, 'href'=>1, 'itemtype'=>1, 'longdesc'=>1, 'model'=>1, 'pluginspage'=>1, 'pluginurl'=>1, 'src'=>1, 'srcset'=>1, 'usemap'=>1); // Need scheme check; excludes style, on* |
452 | static $aNU = array('accesskey'=>1, 'class'=>1, 'contenteditable'=>1, 'contextmenu'=>1, 'dir'=>1, 'draggable'=>1, 'dropzone'=>1, 'hidden'=>1, 'id'=>1, 'inert'=>1, 'itemid'=>1, 'itemprop'=>1, 'itemref'=>1, 'itemscope'=>1, 'itemtype'=>1, 'lang'=>1, 'role'=>1, 'spellcheck'=>1, 'style'=>1, 'tabindex'=>1, 'title'=>1, 'translate'=>1, 'xmlns'=>1, 'xml:base'=>1, 'xml:lang'=>1, 'xml:space'=>1); // Univ; excludes on*, aria* | 452 | static $aNU = array('accesskey'=>1, 'class'=>1, 'contenteditable'=>1, 'contextmenu'=>1, 'dir'=>1, 'draggable'=>1, 'dropzone'=>1, 'hidden'=>1, 'id'=>1, 'inert'=>1, 'itemid'=>1, 'itemprop'=>1, 'itemref'=>1, 'itemscope'=>1, 'itemtype'=>1, 'lang'=>1, 'role'=>1, 'spellcheck'=>1, 'style'=>1, 'tabindex'=>1, 'title'=>1, 'translate'=>1, 'xmlns'=>1, 'xml:base'=>1, 'xml:lang'=>1, 'xml:space'=>1); // Univ; excludes on*, aria* |
453 | 453 | ||
454 | if($C['lc_std_val']){ | 454 | if($C['lc_std_val']){ |
455 | // predef attr vals for $eAL & $aNE ele | 455 | // predef attr vals for $eAL & $aNE ele |
456 | static $aNL = array('all'=>1, 'auto'=>1, 'baseline'=>1, 'bottom'=>1, 'button'=>1, 'captions'=>1, 'center'=>1, 'chapters'=>1, 'char'=>1, 'checkbox'=>1, 'circle'=>1, 'col'=>1, 'colgroup'=>1, 'color'=>1, 'cols'=>1, 'data'=>1, 'date'=>1, 'datetime'=>1, 'datetime-local'=>1, 'default'=>1, 'descriptions'=>1, 'email'=>1, 'file'=>1, 'get'=>1, 'groups'=>1, 'hidden'=>1, 'image'=>1, 'justify'=>1, 'left'=>1, 'ltr'=>1, 'metadata'=>1, 'middle'=>1, 'month'=>1, 'none'=>1, 'number'=>1, 'object'=>1, 'password'=>1, 'poly'=>1, 'post'=>1, 'preserve'=>1, 'radio'=>1, 'range'=>1, 'rect'=>1, 'ref'=>1, 'reset'=>1, 'right'=>1, 'row'=>1, 'rowgroup'=>1, 'rows'=>1, 'rtl'=>1, 'search'=>1, 'submit'=>1, 'subtitles'=>1, 'tel'=>1, 'text'=>1, 'time'=>1, 'top'=>1, 'url'=>1, 'week'=>1); | 456 | static $aNL = array('all'=>1, 'auto'=>1, 'baseline'=>1, 'bottom'=>1, 'button'=>1, 'captions'=>1, 'center'=>1, 'chapters'=>1, 'char'=>1, 'checkbox'=>1, 'circle'=>1, 'col'=>1, 'colgroup'=>1, 'color'=>1, 'cols'=>1, 'data'=>1, 'date'=>1, 'datetime'=>1, 'datetime-local'=>1, 'default'=>1, 'descriptions'=>1, 'email'=>1, 'file'=>1, 'get'=>1, 'groups'=>1, 'hidden'=>1, 'image'=>1, 'justify'=>1, 'left'=>1, 'ltr'=>1, 'metadata'=>1, 'middle'=>1, 'month'=>1, 'none'=>1, 'number'=>1, 'object'=>1, 'password'=>1, 'poly'=>1, 'post'=>1, 'preserve'=>1, 'radio'=>1, 'range'=>1, 'rect'=>1, 'ref'=>1, 'reset'=>1, 'right'=>1, 'row'=>1, 'rowgroup'=>1, 'rows'=>1, 'rtl'=>1, 'search'=>1, 'submit'=>1, 'subtitles'=>1, 'tel'=>1, 'text'=>1, 'time'=>1, 'top'=>1, 'url'=>1, 'week'=>1); |
457 | static $eAL = array('a'=>1, 'area'=>1, 'bdo'=>1, 'button'=>1, 'col'=>1, 'fieldset'=>1, 'form'=>1, 'img'=>1, 'input'=>1, 'object'=>1, 'ol'=>1, 'optgroup'=>1, 'option'=>1, 'param'=>1, 'script'=>1, 'select'=>1, 'table'=>1, 'td'=>1, 'textarea'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1, 'track'=>1, 'xml:space'=>1); | 457 | static $eAL = array('a'=>1, 'area'=>1, 'bdo'=>1, 'button'=>1, 'col'=>1, 'fieldset'=>1, 'form'=>1, 'img'=>1, 'input'=>1, 'object'=>1, 'ol'=>1, 'optgroup'=>1, 'option'=>1, 'param'=>1, 'script'=>1, 'select'=>1, 'table'=>1, 'td'=>1, 'textarea'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1, 'track'=>1, 'xml:space'=>1); |
458 | $lcase = isset($eAL[$e]) ? 1 : 0; | 458 | $lcase = isset($eAL[$e]) ? 1 : 0; |
459 | } | 459 | } |
460 | 460 | ||
461 | $depTr = 0; | 461 | $depTr = 0; |
462 | if($C['no_deprecated_attr']){ | 462 | if($C['no_deprecated_attr']){ |
463 | // depr attr:applicable ele | 463 | // depr attr:applicable ele |
464 | static $aND = array('align'=>array('caption'=>1, 'div'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'object'=>1, 'p'=>1, 'table'=>1), 'bgcolor'=>array('table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1), 'border'=>array('object'=>1), 'bordercolor'=>array('table'=>1, 'td'=>1, 'tr'=>1), 'cellspacing'=>array('table'=>1), 'clear'=>array('br'=>1), 'compact'=>array('dl'=>1, 'ol'=>1, 'ul'=>1), 'height'=>array('td'=>1, 'th'=>1), 'hspace'=>array('img'=>1, 'object'=>1), 'language'=>array('script'=>1), 'name'=>array('a'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'map'=>1), 'noshade'=>array('hr'=>1), 'nowrap'=>array('td'=>1, 'th'=>1), 'size'=>array('hr'=>1), 'vspace'=>array('img'=>1, 'object'=>1), 'width'=>array('hr'=>1, 'pre'=>1, 'table'=>1, 'td'=>1, 'th'=>1)); | 464 | static $aND = array('align'=>array('caption'=>1, 'div'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'object'=>1, 'p'=>1, 'table'=>1), 'bgcolor'=>array('table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1), 'border'=>array('object'=>1), 'bordercolor'=>array('table'=>1, 'td'=>1, 'tr'=>1), 'cellspacing'=>array('table'=>1), 'clear'=>array('br'=>1), 'compact'=>array('dl'=>1, 'ol'=>1, 'ul'=>1), 'height'=>array('td'=>1, 'th'=>1), 'hspace'=>array('img'=>1, 'object'=>1), 'language'=>array('script'=>1), 'name'=>array('a'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'map'=>1), 'noshade'=>array('hr'=>1), 'nowrap'=>array('td'=>1, 'th'=>1), 'size'=>array('hr'=>1), 'vspace'=>array('img'=>1, 'object'=>1), 'width'=>array('hr'=>1, 'pre'=>1, 'table'=>1, 'td'=>1, 'th'=>1)); |
465 | static $eAD = array('a'=>1, 'br'=>1, 'caption'=>1, 'div'=>1, 'dl'=>1, 'form'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'map'=>1, 'object'=>1, 'ol'=>1, 'p'=>1, 'pre'=>1, 'script'=>1, 'table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1, 'ul'=>1); | 465 | static $eAD = array('a'=>1, 'br'=>1, 'caption'=>1, 'div'=>1, 'dl'=>1, 'form'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'map'=>1, 'object'=>1, 'ol'=>1, 'p'=>1, 'pre'=>1, 'script'=>1, 'table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1, 'ul'=>1); |
466 | $depTr = isset($eAD[$e]) ? 1 : 0; | 466 | $depTr = isset($eAD[$e]) ? 1 : 0; |
467 | } | 467 | } |
468 | 468 | ||
469 | // attr name-vals | 469 | // attr name-vals |
470 | if(strpos($a, "\x01") !== false){$a = preg_replace('`\x01[^\x01]*\x01`', '', $a);} // No comment/CDATA sec | 470 | if(strpos($a, "\x01") !== false){$a = preg_replace('`\x01[^\x01]*\x01`', '', $a);} // No comment/CDATA sec |
471 | $mode = 0; $a = trim($a, ' /'); $aA = array(); | 471 | $mode = 0; $a = trim($a, ' /'); $aA = array(); |
472 | while(strlen($a)){ | 472 | while(strlen($a)){ |
473 | $w = 0; | 473 | $w = 0; |
474 | switch($mode){ | 474 | switch($mode){ |
475 | case 0: // Name | 475 | case 0: // Name |
476 | if(preg_match('`^[a-zA-Z][^\s=/]+`', $a, $m)){ | 476 | if(preg_match('`^[a-zA-Z][^\s=/]+`', $a, $m)){ |
477 | $nm = strtolower($m[0]); | 477 | $nm = strtolower($m[0]); |
478 | $w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0]))); | 478 | $w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0]))); |
479 | } | 479 | } |
480 | break; case 1: | 480 | break; case 1: |
481 | if($a[0] == '='){ // = | 481 | if($a[0] == '='){ // = |
482 | $w = 1; $mode = 2; $a = ltrim($a, '= '); | 482 | $w = 1; $mode = 2; $a = ltrim($a, '= '); |
483 | }else{ // No val | 483 | }else{ // No val |
484 | $w = 1; $mode = 0; $a = ltrim($a); | 484 | $w = 1; $mode = 0; $a = ltrim($a); |
485 | $aA[$nm] = ''; | 485 | $aA[$nm] = ''; |
486 | } | 486 | } |
487 | break; case 2: // Val | 487 | break; case 2: // Val |
488 | if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)){ | 488 | if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)){ |
489 | $a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0; | 489 | $a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0; |
490 | $aA[$nm] = trim(str_replace('<', '<', ($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m)); | 490 | $aA[$nm] = trim(str_replace('<', '<', ($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m)); |
491 | } | 491 | } |
492 | break; | 492 | break; |
493 | } | 493 | } |
494 | if($w == 0){ // Parse errs, deal with space, " & ' | 494 | if($w == 0){ // Parse errs, deal with space, " & ' |
495 | $a = preg_replace('`^(?:"[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*`', '', $a); | 495 | $a = preg_replace('`^(?:"[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*`', '', $a); |
496 | $mode = 0; | 496 | $mode = 0; |
497 | } | 497 | } |
498 | } | 498 | } |
499 | if($mode == 1){$aA[$nm] = '';} | 499 | if($mode == 1){$aA[$nm] = '';} |
500 | 500 | ||
501 | // clean attrs | 501 | // clean attrs |
502 | global $S; | 502 | global $S; |
503 | $rl = isset($S[$e]) ? $S[$e] : array(); | 503 | $rl = isset($S[$e]) ? $S[$e] : array(); |
504 | $a = array(); $nfr = 0; $d = $C['deny_attribute']; | 504 | $a = array(); $nfr = 0; $d = $C['deny_attribute']; |
505 | foreach($aA as $k=>$v){ | 505 | foreach($aA as $k=>$v){ |
506 | if(((isset($d['*']) ? isset($d[$k]) : !isset($d[$k])) && (isset($aN[$k][$e]) or isset($aNU[$k]) or (isset($aNO[$k]) && !isset($d['on*'])) or (isset($aNA[$k]) && !isset($d['aria*'])) or (!isset($d['data*']) && preg_match('`data-((?!xml)[^:]+$)`', $k))) && !isset($rl['n'][$k]) && !isset($rl['n']['*'])) or isset($rl[$k])){ | 506 | if(((isset($d['*']) ? isset($d[$k]) : !isset($d[$k])) && (isset($aN[$k][$e]) or isset($aNU[$k]) or (isset($aNO[$k]) && !isset($d['on*'])) or (isset($aNA[$k]) && !isset($d['aria*'])) or (!isset($d['data*']) && preg_match('`data-((?!xml)[^:]+$)`', $k))) && !isset($rl['n'][$k]) && !isset($rl['n']['*'])) or isset($rl[$k])){ |
507 | if(isset($aNE[$k])){$v = $k;} | 507 | if(isset($aNE[$k])){$v = $k;} |
508 | elseif(!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type')){ // Rather loose but ?not cause issues | 508 | elseif(!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type')){ // Rather loose but ?not cause issues |
509 | $v = (isset($aNL[($v2 = strtolower($v))])) ? $v2 : $v; | 509 | $v = (isset($aNL[($v2 = strtolower($v))])) ? $v2 : $v; |
510 | } | 510 | } |
511 | if($k == 'style' && !$C['style_pass']){ | 511 | if($k == 'style' && !$C['style_pass']){ |
512 | if(false !== strpos($v, '&#')){ | 512 | if(false !== strpos($v, '&#')){ |
513 | static $sC = array(' '=>' ', ' '=>' ', 'E'=>'e', 'E'=>'e', 'e'=>'e', 'e'=>'e', 'X'=>'x', 'X'=>'x', 'x'=>'x', 'x'=>'x', 'P'=>'p', 'P'=>'p', 'p'=>'p', 'p'=>'p', 'S'=>'s', 'S'=>'s', 's'=>'s', 's'=>'s', 'I'=>'i', 'I'=>'i', 'i'=>'i', 'i'=>'i', 'O'=>'o', 'O'=>'o', 'o'=>'o', 'o'=>'o', 'N'=>'n', 'N'=>'n', 'n'=>'n', 'n'=>'n', 'U'=>'u', 'U'=>'u', 'u'=>'u', 'u'=>'u', 'R'=>'r', 'R'=>'r', 'r'=>'r', 'r'=>'r', 'L'=>'l', 'L'=>'l', 'l'=>'l', 'l'=>'l', '('=>'(', '('=>'(', ')'=>')', ')'=>')', ' '=>':', ' '=>':', '"'=>'"', '"'=>'"', '''=>"'", '''=>"'", '/'=>'/', '/'=>'/', '*'=>'*', '*'=>'*', '\'=>'\\', '\'=>'\\'); | 513 | static $sC = array(' '=>' ', ' '=>' ', 'E'=>'e', 'E'=>'e', 'e'=>'e', 'e'=>'e', 'X'=>'x', 'X'=>'x', 'x'=>'x', 'x'=>'x', 'P'=>'p', 'P'=>'p', 'p'=>'p', 'p'=>'p', 'S'=>'s', 'S'=>'s', 's'=>'s', 's'=>'s', 'I'=>'i', 'I'=>'i', 'i'=>'i', 'i'=>'i', 'O'=>'o', 'O'=>'o', 'o'=>'o', 'o'=>'o', 'N'=>'n', 'N'=>'n', 'n'=>'n', 'n'=>'n', 'U'=>'u', 'U'=>'u', 'u'=>'u', 'u'=>'u', 'R'=>'r', 'R'=>'r', 'r'=>'r', 'r'=>'r', 'L'=>'l', 'L'=>'l', 'l'=>'l', 'l'=>'l', '('=>'(', '('=>'(', ')'=>')', ')'=>')', ' '=>':', ' '=>':', '"'=>'"', '"'=>'"', '''=>"'", '''=>"'", '/'=>'/', '/'=>'/', '*'=>'*', '*'=>'*', '\'=>'\\', '\'=>'\\'); |
514 | $v = strtr($v, $sC); | 514 | $v = strtr($v, $sC); |
515 | } | 515 | } |
516 | $v = preg_replace_callback('`(url(?:\()(?: )*(?:\'|"|&(?:quot|apos);)?)(.+?)((?:\'|"|&(?:quot|apos);)?(?: )*(?:\)))`iS', 'hl_prot', $v); | 516 | $v = preg_replace_callback('`(url(?:\()(?: )*(?:\'|"|&(?:quot|apos);)?)(.+?)((?:\'|"|&(?:quot|apos);)?(?: )*(?:\)))`iS', 'hl_prot', $v); |
517 | $v = !$C['css_expression'] ? preg_replace('`expression`i', ' ', preg_replace('`\\\\\S|(/|(%2f))(\*|(%2a))`i', ' ', $v)) : $v; | 517 | $v = !$C['css_expression'] ? preg_replace('`expression`i', ' ', preg_replace('`\\\\\S|(/|(%2f))(\*|(%2a))`i', ' ', $v)) : $v; |
518 | }elseif(isset($aNP[$k]) or isset($aNO[$k])){ | 518 | }elseif(isset($aNP[$k]) or isset($aNO[$k])){ |
519 | $v = str_replace("Â", ' ', (strpos($v, '&') !== false ? str_replace(array('­', '­', '­'), ' ', $v) : $v)); # double-quoted char: soft-hyphen; appears here as "Â" or hyphen or something else depending on viewing software | 519 | $v = str_replace("Â", ' ', (strpos($v, '&') !== false ? str_replace(array('­', '­', '­'), ' ', $v) : $v)); # double-quoted char: soft-hyphen; appears here as "Â" or hyphen or something else depending on viewing software |
520 | if($k == 'srcset'){ | 520 | if($k == 'srcset'){ |
521 | $v2 = ''; | 521 | $v2 = ''; |
522 | foreach(explode(',', $v) as $k1=>$v1){ | 522 | foreach(explode(',', $v) as $k1=>$v1){ |
523 | $v1 = explode(' ', ltrim($v1), 2); | 523 | $v1 = explode(' ', ltrim($v1), 2); |
524 | $k1 = isset($v1[1]) ? trim($v1[1]) : ''; | 524 | $k1 = isset($v1[1]) ? trim($v1[1]) : ''; |
525 | $v1 = trim($v1[0]); | 525 | $v1 = trim($v1[0]); |
526 | if(isset($v1[0])){$v2 .= hl_prot($v1, $k). (empty($k1) ? '' : ' '. $k1). ', ';} | 526 | if(isset($v1[0])){$v2 .= hl_prot($v1, $k). (empty($k1) ? '' : ' '. $k1). ', ';} |
527 | } | 527 | } |
528 | $v = trim($v2, ', '); | 528 | $v = trim($v2, ', '); |
529 | } | 529 | } |
530 | if($k == 'itemtype'){ | 530 | if($k == 'itemtype'){ |
531 | $v2 = ''; | 531 | $v2 = ''; |
532 | foreach(explode(' ', $v) as $v1){ | 532 | foreach(explode(' ', $v) as $v1){ |
533 | if(isset($v1[0])){$v2 .= hl_prot($v1, $k). ' ';} | 533 | if(isset($v1[0])){$v2 .= hl_prot($v1, $k). ' ';} |
534 | } | 534 | } |
535 | $v = trim($v2, ' '); | 535 | $v = trim($v2, ' '); |
536 | } | 536 | } |
537 | else{$v = hl_prot($v, $k);} | 537 | else{$v = hl_prot($v, $k);} |
538 | if($k == 'href'){ // X-spam | 538 | if($k == 'href'){ // X-spam |
539 | if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){ | 539 | if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){ |
540 | $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v); | 540 | $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v); |
541 | }elseif($C['anti_link_spam']){ | 541 | }elseif($C['anti_link_spam']){ |
542 | $r1 = $C['anti_link_spam'][1]; | 542 | $r1 = $C['anti_link_spam'][1]; |
543 | if(!empty($r1) && preg_match($r1, $v)){continue;} | 543 | if(!empty($r1) && preg_match($r1, $v)){continue;} |
544 | $r0 = $C['anti_link_spam'][0]; | 544 | $r0 = $C['anti_link_spam'][0]; |
545 | if(!empty($r0) && preg_match($r0, $v)){ | 545 | if(!empty($r0) && preg_match($r0, $v)){ |
546 | if(isset($a['rel'])){ | 546 | if(isset($a['rel'])){ |
547 | if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';} | 547 | if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';} |
548 | }elseif(isset($aA['rel'])){ | 548 | }elseif(isset($aA['rel'])){ |
549 | if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;} | 549 | if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;} |
550 | }else{$a['rel'] = 'nofollow';} | 550 | }else{$a['rel'] = 'nofollow';} |
551 | } | 551 | } |
552 | } | 552 | } |
553 | } | 553 | } |
554 | } | 554 | } |
555 | if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($k, $v, $rl[$k])) === 0){continue;} | 555 | if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($k, $v, $rl[$k])) === 0){continue;} |
556 | $a[$k] = str_replace('"', '"', $v); | 556 | $a[$k] = str_replace('"', '"', $v); |
557 | } | 557 | } |
558 | } | 558 | } |
559 | if($nfr){$a['rel'] = isset($a['rel']) ? $a['rel']. ' nofollow' : 'nofollow';} | 559 | if($nfr){$a['rel'] = isset($a['rel']) ? $a['rel']. ' nofollow' : 'nofollow';} |
560 | 560 | ||
561 | // rqd attr | 561 | // rqd attr |
562 | static $eAR = array('area'=>array('alt'=>'area'), 'bdo'=>array('dir'=>'ltr'), 'command'=>array('label'=>''), 'form'=>array('action'=>''), 'img'=>array('src'=>'', 'alt'=>'image'), 'map'=>array('name'=>''), 'optgroup'=>array('label'=>''), 'param'=>array('name'=>''), 'style'=>array('scoped'=>''), 'textarea'=>array('rows'=>'10', 'cols'=>'50')); | 562 | static $eAR = array('area'=>array('alt'=>'area'), 'bdo'=>array('dir'=>'ltr'), 'command'=>array('label'=>''), 'form'=>array('action'=>''), 'img'=>array('src'=>'', 'alt'=>'image'), 'map'=>array('name'=>''), 'optgroup'=>array('label'=>''), 'param'=>array('name'=>''), 'style'=>array('scoped'=>''), 'textarea'=>array('rows'=>'10', 'cols'=>'50')); |
563 | if(isset($eAR[$e])){ | 563 | if(isset($eAR[$e])){ |
564 | foreach($eAR[$e] as $k=>$v){ | 564 | foreach($eAR[$e] as $k=>$v){ |
565 | if(!isset($a[$k])){$a[$k] = isset($v[0]) ? $v : $k;} | 565 | if(!isset($a[$k])){$a[$k] = isset($v[0]) ? $v : $k;} |
566 | } | 566 | } |
567 | } | 567 | } |
568 | 568 | ||
569 | // depr attr | 569 | // depr attr |
570 | if($depTr){ | 570 | if($depTr){ |
571 | $c = array(); | 571 | $c = array(); |
572 | foreach($a as $k=>$v){ | 572 | foreach($a as $k=>$v){ |
573 | if($k == 'style' or !isset($aND[$k][$e])){continue;} | 573 | if($k == 'style' or !isset($aND[$k][$e])){continue;} |
574 | $v = str_replace(array('\\', ':', ';', '&#'), '', $v); | 574 | $v = str_replace(array('\\', ':', ';', '&#'), '', $v); |
575 | if($k == 'align'){ | 575 | if($k == 'align'){ |
576 | unset($a['align']); | 576 | unset($a['align']); |
577 | if($e == 'img' && ($v == 'left' or $v == 'right')){$c[] = 'float: '. $v;} | 577 | if($e == 'img' && ($v == 'left' or $v == 'right')){$c[] = 'float: '. $v;} |
578 | elseif(($e == 'div' or $e == 'table') && $v == 'center'){$c[] = 'margin: auto';} | 578 | elseif(($e == 'div' or $e == 'table') && $v == 'center'){$c[] = 'margin: auto';} |
579 | else{$c[] = 'text-align: '. $v;} | 579 | else{$c[] = 'text-align: '. $v;} |
580 | }elseif($k == 'bgcolor'){ | 580 | }elseif($k == 'bgcolor'){ |
581 | unset($a['bgcolor']); | 581 | unset($a['bgcolor']); |
582 | $c[] = 'background-color: '. $v; | 582 | $c[] = 'background-color: '. $v; |
583 | }elseif($k == 'border'){ | 583 | }elseif($k == 'border'){ |
584 | unset($a['border']); $c[] = "border: {$v}px"; | 584 | unset($a['border']); $c[] = "border: {$v}px"; |
585 | }elseif($k == 'bordercolor'){ | 585 | }elseif($k == 'bordercolor'){ |
586 | unset($a['bordercolor']); $c[] = 'border-color: '. $v; | 586 | unset($a['bordercolor']); $c[] = 'border-color: '. $v; |
587 | }elseif($k == 'cellspacing'){ | 587 | }elseif($k == 'cellspacing'){ |
588 | unset($a['cellspacing']); $c[] = "border-spacing: {$v}px"; | 588 | unset($a['cellspacing']); $c[] = "border-spacing: {$v}px"; |
589 | }elseif($k == 'clear'){ | 589 | }elseif($k == 'clear'){ |
590 | unset($a['clear']); $c[] = 'clear: '. ($v != 'all' ? $v : 'both'); | 590 | unset($a['clear']); $c[] = 'clear: '. ($v != 'all' ? $v : 'both'); |
591 | }elseif($k == 'compact'){ | 591 | }elseif($k == 'compact'){ |
592 | unset($a['compact']); $c[] = 'font-size: 85%'; | 592 | unset($a['compact']); $c[] = 'font-size: 85%'; |
593 | }elseif($k == 'height' or $k == 'width'){ | 593 | }elseif($k == 'height' or $k == 'width'){ |
594 | unset($a[$k]); $c[] = $k. ': '. ($v[0] != '*' ? $v. (ctype_digit($v) ? 'px' : '') : 'auto'); | 594 | unset($a[$k]); $c[] = $k. ': '. ($v[0] != '*' ? $v. (ctype_digit($v) ? 'px' : '') : 'auto'); |
595 | }elseif($k == 'hspace'){ | 595 | }elseif($k == 'hspace'){ |
596 | unset($a['hspace']); $c[] = "margin-left: {$v}px; margin-right: {$v}px"; | 596 | unset($a['hspace']); $c[] = "margin-left: {$v}px; margin-right: {$v}px"; |
597 | }elseif($k == 'language' && !isset($a['type'])){ | 597 | }elseif($k == 'language' && !isset($a['type'])){ |
598 | unset($a['language']); | 598 | unset($a['language']); |
599 | $a['type'] = 'text/'. strtolower($v); | 599 | $a['type'] = 'text/'. strtolower($v); |
600 | }elseif($k == 'name'){ | 600 | }elseif($k == 'name'){ |
601 | if($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map')){unset($a['name']);} | 601 | if($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map')){unset($a['name']);} |
602 | if(!isset($a['id']) && !preg_match('`\W`', $v)){$a['id'] = $v;} | 602 | if(!isset($a['id']) && !preg_match('`\W`', $v)){$a['id'] = $v;} |
603 | }elseif($k == 'noshade'){ | 603 | }elseif($k == 'noshade'){ |
604 | unset($a['noshade']); $c[] = 'border-style: none; border: 0; background-color: gray; color: gray'; | 604 | unset($a['noshade']); $c[] = 'border-style: none; border: 0; background-color: gray; color: gray'; |
605 | }elseif($k == 'nowrap'){ | 605 | }elseif($k == 'nowrap'){ |
606 | unset($a['nowrap']); $c[] = 'white-space: nowrap'; | 606 | unset($a['nowrap']); $c[] = 'white-space: nowrap'; |
607 | }elseif($k == 'size'){ | 607 | }elseif($k == 'size'){ |
608 | unset($a['size']); $c[] = 'size: '. $v. 'px'; | 608 | unset($a['size']); $c[] = 'size: '. $v. 'px'; |
609 | }elseif($k == 'vspace'){ | 609 | }elseif($k == 'vspace'){ |
610 | unset($a['vspace']); $c[] = "margin-top: {$v}px; margin-bottom: {$v}px"; | 610 | unset($a['vspace']); $c[] = "margin-top: {$v}px; margin-bottom: {$v}px"; |
611 | } | 611 | } |
612 | } | 612 | } |
613 | if(count($c)){ | 613 | if(count($c)){ |
614 | $c = implode('; ', $c); | 614 | $c = implode('; ', $c); |
615 | $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $c. ';': $c. ';'; | 615 | $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $c. ';': $c. ';'; |
616 | } | 616 | } |
617 | } | 617 | } |
618 | // unique ID | 618 | // unique ID |
619 | if($C['unique_ids'] && isset($a['id'])){ | 619 | if($C['unique_ids'] && isset($a['id'])){ |
620 | if(preg_match('`\s`', ($id = $a['id'])) or (isset($GLOBALS['hl_Ids'][$id]) && $C['unique_ids'] == 1)){unset($a['id']); | 620 | if(preg_match('`\s`', ($id = $a['id'])) or (isset($GLOBALS['hl_Ids'][$id]) && $C['unique_ids'] == 1)){unset($a['id']); |
621 | }else{ | 621 | }else{ |
622 | while(isset($GLOBALS['hl_Ids'][$id])){$id = $C['unique_ids']. $id;} | 622 | while(isset($GLOBALS['hl_Ids'][$id])){$id = $C['unique_ids']. $id;} |
623 | $GLOBALS['hl_Ids'][($a['id'] = $id)] = 1; | 623 | $GLOBALS['hl_Ids'][($a['id'] = $id)] = 1; |
624 | } | 624 | } |
625 | } | 625 | } |
626 | // xml:lang | 626 | // xml:lang |
627 | if($C['xml:lang'] && isset($a['lang'])){ | 627 | if($C['xml:lang'] && isset($a['lang'])){ |
628 | $a['xml:lang'] = isset($a['xml:lang']) ? $a['xml:lang'] : $a['lang']; | 628 | $a['xml:lang'] = isset($a['xml:lang']) ? $a['xml:lang'] : $a['lang']; |
629 | if($C['xml:lang'] == 2){unset($a['lang']);} | 629 | if($C['xml:lang'] == 2){unset($a['lang']);} |
630 | } | 630 | } |
631 | // for transformed tag | 631 | // for transformed tag |
632 | if(!empty($trt)){ | 632 | if(!empty($trt)){ |
633 | $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $trt : $trt; | 633 | $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $trt : $trt; |
634 | } | 634 | } |
635 | // return with empty ele / | 635 | // return with empty ele / |
636 | if(empty($C['hook_tag'])){ | 636 | if(empty($C['hook_tag'])){ |
637 | $aA = ''; | 637 | $aA = ''; |
638 | foreach($a as $k=>$v){$aA .= " {$k}=\"{$v}\"";} | 638 | foreach($a as $k=>$v){$aA .= " {$k}=\"{$v}\"";} |
639 | return "<{$e}{$aA}". (isset($eE[$e]) ? ' /' : ''). '>'; | 639 | return "<{$e}{$aA}". (isset($eE[$e]) ? ' /' : ''). '>'; |
640 | } | 640 | } |
641 | else{return $C['hook_tag']($e, $a);} | 641 | else{return $C['hook_tag']($e, $a);} |
642 | } | 642 | } |
643 | 643 | ||
644 | function hl_tag2(&$e, &$a, $t=1){ | 644 | function hl_tag2(&$e, &$a, $t=1){ |
645 | // transform tag | 645 | // transform tag |
646 | if($e == 'big'){$e = 'span'; return 'font-size: larger;';} | 646 | if($e == 'big'){$e = 'span'; return 'font-size: larger;';} |
647 | if($e == 's' or $e == 'strike'){$e = 'span'; return 'text-decoration: line-through;';} | 647 | if($e == 's' or $e == 'strike'){$e = 'span'; return 'text-decoration: line-through;';} |
648 | if($e == 'tt'){$e = 'code'; return '';} | 648 | if($e == 'tt'){$e = 'code'; return '';} |
649 | if($e == 'center'){$e = 'div'; return 'text-align: center;';} | 649 | if($e == 'center'){$e = 'div'; return 'text-align: center;';} |
650 | static $fs = array('0'=>'xx-small', '1'=>'xx-small', '2'=>'small', '3'=>'medium', '4'=>'large', '5'=>'x-large', '6'=>'xx-large', '7'=>'300%', '-1'=>'smaller', '-2'=>'60%', '+1'=>'larger', '+2'=>'150%', '+3'=>'200%', '+4'=>'300%'); | 650 | static $fs = array('0'=>'xx-small', '1'=>'xx-small', '2'=>'small', '3'=>'medium', '4'=>'large', '5'=>'x-large', '6'=>'xx-large', '7'=>'300%', '-1'=>'smaller', '-2'=>'60%', '+1'=>'larger', '+2'=>'150%', '+3'=>'200%', '+4'=>'300%'); |
651 | if($e == 'font'){ | 651 | if($e == 'font'){ |
652 | $a2 = ''; | 652 | $a2 = ''; |
653 | while(preg_match('`(^|\s)(color|size)\s*=\s*(\'|")?(.+?)(\\3|\s|$)`i', $a, $m)){ | 653 | while(preg_match('`(^|\s)(color|size)\s*=\s*(\'|")?(.+?)(\\3|\s|$)`i', $a, $m)){ |
654 | $a = str_replace($m[0], ' ', $a); | 654 | $a = str_replace($m[0], ' ', $a); |
655 | $a2 .= strtolower($m[2]) == 'color' ? (' color: '. str_replace(array('"', ';', ':'), '\'', trim($m[4])). ';') : (isset($fs[($m = trim($m[4]))]) ? (' font-size: '. $fs[$m]. ';') : ''); | 655 | $a2 .= strtolower($m[2]) == 'color' ? (' color: '. str_replace(array('"', ';', ':'), '\'', trim($m[4])). ';') : (isset($fs[($m = trim($m[4]))]) ? (' font-size: '. $fs[$m]. ';') : ''); |
656 | } | 656 | } |
657 | while(preg_match('`(^|\s)face\s*=\s*(\'|")?([^=]+?)\\2`i', $a, $m) or preg_match('`(^|\s)face\s*=(\s*)(\S+)`i', $a, $m)){ | 657 | while(preg_match('`(^|\s)face\s*=\s*(\'|")?([^=]+?)\\2`i', $a, $m) or preg_match('`(^|\s)face\s*=(\s*)(\S+)`i', $a, $m)){ |
658 | $a = str_replace($m[0], ' ', $a); | 658 | $a = str_replace($m[0], ' ', $a); |
659 | $a2 .= ' font-family: '. str_replace(array('"', ';', ':'), '\'', trim($m[3])). ';'; | 659 | $a2 .= ' font-family: '. str_replace(array('"', ';', ':'), '\'', trim($m[3])). ';'; |
660 | } | 660 | } |
661 | $e = 'span'; return ltrim(str_replace('<', '', $a2)); | 661 | $e = 'span'; return ltrim(str_replace('<', '', $a2)); |
662 | } | 662 | } |
663 | if($e == 'acronym'){$e = 'abbr'; return '';} | 663 | if($e == 'acronym'){$e = 'abbr'; return '';} |
664 | if($e == 'dir'){$e = 'ul'; return '';} | 664 | if($e == 'dir'){$e = 'ul'; return '';} |
665 | if($t == 2){$e = 0; return 0;} | 665 | if($t == 2){$e = 0; return 0;} |
666 | return ''; | 666 | return ''; |
667 | } | 667 | } |
668 | 668 | ||
669 | function hl_tidy($t, $w, $p){ | 669 | function hl_tidy($t, $w, $p){ |
670 | // tidy/compact HTM | 670 | // tidy/compact HTM |
671 | if(strpos(' pre,script,textarea', "$p,")){return $t;} | 671 | if(strpos(' pre,script,textarea', "$p,")){return $t;} |
672 | if(!function_exists('hl_aux2')){function hl_aux2($m){ | 672 | if(!function_exists('hl_aux2')){function hl_aux2($m){ |
673 | return $m[1]. str_replace(array("<", ">", "\n", "\r", "\t", ' '), array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), $m[3]). $m[4]; | 673 | return $m[1]. str_replace(array("<", ">", "\n", "\r", "\t", ' '), array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), $m[3]). $m[4]; |
674 | }} | 674 | }} |
675 | $t = preg_replace(array('`(<\w[^>]*(?<!/)>)\s+`', '`\s+`', '`(<\w[^>]*(?<!/)>) `'), array(' $1', ' ', '$1'), preg_replace_callback(array('`(<(!\[CDATA\[))(.+?)(\]\]>)`sm', '`(<(!--))(.+?)(-->)`sm', '`(<(pre|script|textarea)[^>]*?>)(.+?)(</\2>)`sm'), 'hl_aux2', $t)); | 675 | $t = preg_replace(array('`(<\w[^>]*(?<!/)>)\s+`', '`\s+`', '`(<\w[^>]*(?<!/)>) `'), array(' $1', ' ', '$1'), preg_replace_callback(array('`(<(!\[CDATA\[))(.+?)(\]\]>)`sm', '`(<(!--))(.+?)(-->)`sm', '`(<(pre|script|textarea)[^>]*?>)(.+?)(</\2>)`sm'), 'hl_aux2', $t)); |
676 | if(($w = strtolower($w)) == -1){ | 676 | if(($w = strtolower($w)) == -1){ |
677 | return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t); | 677 | return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t); |
678 | } | 678 | } |
679 | $s = strpos(" $w", 't') ? "\t" : ' '; | 679 | $s = strpos(" $w", 't') ? "\t" : ' '; |
680 | $s = preg_match('`\d`', $w, $m) ? str_repeat($s, $m[0]) : str_repeat($s, ($s == "\t" ? 1 : 2)); | 680 | $s = preg_match('`\d`', $w, $m) ? str_repeat($s, $m[0]) : str_repeat($s, ($s == "\t" ? 1 : 2)); |
681 | $N = preg_match('`[ts]([1-9])`', $w, $m) ? $m[1] : 0; | 681 | $N = preg_match('`[ts]([1-9])`', $w, $m) ? $m[1] : 0; |
682 | $a = array('br'=>1); | 682 | $a = array('br'=>1); |
683 | $b = array('button'=>1, 'command'=>1, 'input'=>1, 'option'=>1, 'param'=>1, 'track'=>1); | 683 | $b = array('button'=>1, 'command'=>1, 'input'=>1, 'option'=>1, 'param'=>1, 'track'=>1); |
684 | $c = array('audio'=>1, 'canvas'=>1, 'caption'=>1, 'dd'=>1, 'dt'=>1, 'figcaption'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'isindex'=>1, 'label'=>1, 'legend'=>1, 'li'=>1, 'object'=>1, 'p'=>1, 'pre'=>1, 'style'=>1, 'summary'=>1, 'td'=>1, 'textarea'=>1, 'th'=>1, 'video'=>1); | 684 | $c = array('audio'=>1, 'canvas'=>1, 'caption'=>1, 'dd'=>1, 'dt'=>1, 'figcaption'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'isindex'=>1, 'label'=>1, 'legend'=>1, 'li'=>1, 'object'=>1, 'p'=>1, 'pre'=>1, 'style'=>1, 'summary'=>1, 'td'=>1, 'textarea'=>1, 'th'=>1, 'video'=>1); |
685 | $d = array('address'=>1, 'article'=>1, 'aside'=>1, 'blockquote'=>1, 'center'=>1, 'colgroup'=>1, 'datalist'=>1, 'details'=>1, 'dir'=>1, 'div'=>1, 'dl'=>1, 'fieldset'=>1, 'figure'=>1, 'footer'=>1, 'form'=>1, 'header'=>1, 'hgroup'=>1, 'hr'=>1, 'iframe'=>1, 'main'=>1, 'map'=>1, 'menu'=>1, 'nav'=>1, 'noscript'=>1, 'ol'=>1, 'optgroup'=>1, 'rbc'=>1, 'rtc'=>1, 'ruby'=>1, 'script'=>1, 'section'=>1, 'select'=>1, 'table'=>1, 'tbody'=>1, 'tfoot'=>1, 'thead'=>1, 'tr'=>1, 'ul'=>1); | 685 | $d = array('address'=>1, 'article'=>1, 'aside'=>1, 'blockquote'=>1, 'center'=>1, 'colgroup'=>1, 'datalist'=>1, 'details'=>1, 'dir'=>1, 'div'=>1, 'dl'=>1, 'fieldset'=>1, 'figure'=>1, 'footer'=>1, 'form'=>1, 'header'=>1, 'hgroup'=>1, 'hr'=>1, 'iframe'=>1, 'main'=>1, 'map'=>1, 'menu'=>1, 'nav'=>1, 'noscript'=>1, 'ol'=>1, 'optgroup'=>1, 'rbc'=>1, 'rtc'=>1, 'ruby'=>1, 'script'=>1, 'section'=>1, 'select'=>1, 'table'=>1, 'tbody'=>1, 'tfoot'=>1, 'thead'=>1, 'tr'=>1, 'ul'=>1); |
686 | $T = explode('<', $t); | 686 | $T = explode('<', $t); |
687 | $X = 1; | 687 | $X = 1; |
688 | while($X){ | 688 | while($X){ |
689 | $n = $N; | 689 | $n = $N; |
690 | $t = $T; | 690 | $t = $T; |
691 | ob_start(); | 691 | ob_start(); |
692 | if(isset($d[$p])){echo str_repeat($s, ++$n);} | 692 | if(isset($d[$p])){echo str_repeat($s, ++$n);} |
693 | echo ltrim(array_shift($t)); | 693 | echo ltrim(array_shift($t)); |
694 | for($i=-1, $j=count($t); ++$i<$j;){ | 694 | for($i=-1, $j=count($t); ++$i<$j;){ |
695 | $r = ''; list($e, $r) = explode('>', $t[$i]); | 695 | $r = ''; list($e, $r) = explode('>', $t[$i]); |
696 | $x = $e[0] == '/' ? 0 : (substr($e, -1) == '/' ? 1 : ($e[0] != '!' ? 2 : -1)); | 696 | $x = $e[0] == '/' ? 0 : (substr($e, -1) == '/' ? 1 : ($e[0] != '!' ? 2 : -1)); |
697 | $y = !$x ? ltrim($e, '/') : ($x > 0 ? substr($e, 0, strcspn($e, ' ')) : 0); | 697 | $y = !$x ? ltrim($e, '/') : ($x > 0 ? substr($e, 0, strcspn($e, ' ')) : 0); |
698 | $e = "<$e>"; | 698 | $e = "<$e>"; |
699 | if(isset($d[$y])){ | 699 | if(isset($d[$y])){ |
700 | if(!$x){ | 700 | if(!$x){ |
701 | if($n){echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n);} | 701 | if($n){echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n);} |
702 | else{++$N; ob_end_clean(); continue 2;} | 702 | else{++$N; ob_end_clean(); continue 2;} |
703 | } | 703 | } |
704 | else{echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n));} | 704 | else{echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n));} |
705 | echo $r; continue; | 705 | echo $r; continue; |
706 | } | 706 | } |
707 | $f = "\n". str_repeat($s, $n); | 707 | $f = "\n". str_repeat($s, $n); |
708 | if(isset($c[$y])){ | 708 | if(isset($c[$y])){ |
709 | if(!$x){echo $e, $f, $r;} | 709 | if(!$x){echo $e, $f, $r;} |
710 | else{echo $f, $e, $r;} | 710 | else{echo $f, $e, $r;} |
711 | }elseif(isset($b[$y])){echo $f, $e, $r; | 711 | }elseif(isset($b[$y])){echo $f, $e, $r; |
712 | }elseif(isset($a[$y])){echo $e, $f, $r; | 712 | }elseif(isset($a[$y])){echo $e, $f, $r; |
713 | }elseif(!$y){echo $f, $e, $f, $r; | 713 | }elseif(!$y){echo $f, $e, $f, $r; |
714 | }else{echo $e, $r;} | 714 | }else{echo $e, $r;} |
715 | } | 715 | } |
716 | $X = 0; | 716 | $X = 0; |
717 | } | 717 | } |
718 | $t = str_replace(array("\n ", " \n"), "\n", preg_replace('`[\n]\s*?[\n]+`', "\n", ob_get_contents())); | 718 | $t = str_replace(array("\n ", " \n"), "\n", preg_replace('`[\n]\s*?[\n]+`', "\n", ob_get_contents())); |
719 | ob_end_clean(); | 719 | ob_end_clean(); |
720 | if(($l = strpos(" $w", 'r') ? (strpos(" $w", 'n') ? "\r\n" : "\r") : 0)){ | 720 | if(($l = strpos(" $w", 'r') ? (strpos(" $w", 'n') ? "\r\n" : "\r") : 0)){ |
721 | $t = str_replace("\n", $l, $t); | 721 | $t = str_replace("\n", $l, $t); |
722 | } | 722 | } |
723 | return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t); | 723 | return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t); |
724 | } | 724 | } |
725 | 725 | ||
726 | function hl_version(){ | 726 | function hl_version(){ |
727 | // version | 727 | // version |
728 | return '1.2.5'; | 728 | return '1.2.5'; |
729 | } | 729 | } |