11<?php
22
33/*
4- htmLawedTest.php, 11 February 2017
4+ htmLawedTest.php, 17 May 2017
55To test htmLawed
66Copyright Santosh Patnaik
77Dual licensed with LGPL 3 and GPL 2+
6767
6868// HTM for unprocessed
6969if (isset ($ _POST ['inputH ' ])){
70- echo '<html><head><title>htmLawed test: HTML view of unprocessed input</title></head><body style="margin:0; padding: 0;"><p style="background-color: black; color: white; padding: 2px;"> Rendering of unprocessed input without an HTML doctype or charset declaration <small><a style="color: white; text-decoration: none;" href="1" onclick="javascript:window.close(this); return false;">close window</a> | <a style="color: white; text-decoration: none;" href="htmLawedTest.php" onclick="javascript: window.open( \'htmLawedTest.php \', \'hlmain \'); window.close(this); return false;">htmLawed test page</a></small></p><div> ' , $ _POST ['inputH ' ], '</div></body></html> ' ;
70+ echo '<html><head><title>htmLawed test: HTML view of unprocessed input</title></head><body style="margin:0; padding: 0;"><p style="background-color: black; color: white; padding: 2px;"> Rendering of raw/unprocessed input without an HTML doctype or charset declaration <small><a style="color: white; text-decoration: none;" href="1" onclick="javascript:window.close(this); return false;">close window</a> | <a style="color: white; text-decoration: none;" href="htmLawedTest.php" onclick="javascript: window.open( \'htmLawedTest.php \', \'hlmain \'); window.close(this); return false;">htmLawed test page</a></small></p><div> ' , $ _POST ['inputH ' ], '</div></body></html> ' ;
71+ exit ;
72+ }
73+
74+ // HTM for processed
75+ if (isset ($ _POST ['outputH ' ])){
76+ echo '<html><head><title>htmLawed test: HTML view of unprocessed input</title></head><body style="margin:0; padding: 0;"><p style="background-color: black; color: white; padding: 2px;"> Rendering of filtered/processed input without an HTML doctype or charset declaration <small><a style="color: white; text-decoration: none;" href="1" onclick="javascript:window.close(this); return false;">close window</a> | <a style="color: white; text-decoration: none;" href="htmLawedTest.php" onclick="javascript: window.open( \'htmLawedTest.php \', \'hlmain \'); window.close(this); return false;">htmLawed test page</a></small></p><div> ' , $ _POST ['outputH ' ], '</div></body></html> ' ;
7177 exit ;
7278}
7379
@@ -142,7 +148,7 @@ function hexdump($d){
142148body, button, div, html, input, p{font-size:13px; font-family:'Lucida grande', Verdana, Arial, Helvetica, sans-serif;}
143149button, input{font-size: 85%;}
144150div.help{border-top: 1px dotted gray; margin-top: 15px; padding-top: 15px; color:#999999;}
145- #inputC, #inputD, #inputF, #inputR, #outputD, #outputF, #outputH, # outputR, #settingF, #diff{display:block;}
151+ #inputC, #inputD, #inputF, #inputR, #outputD, #outputF, #outputR, #settingF, #diff{display:block;}
146152#inputC, #settingF{background-color:white; border:1px gray solid; padding:3px;}
147153#inputC li{margin: 0; padding: 0;}
148154#inputC ul{margin: 0; padding: 0; margin-left: 14px;}
@@ -152,7 +158,6 @@ function hexdump($d){
152158#inputC, #settingF, #inputD, #inputR, #outputD, #outputR, #diff, textarea{font-size:100%; font-family:'Bitstream vera sans mono', 'courier new', 'courier', monospace;}
153159#outputD{overflow:auto; background-color: #99ffcc; border:1px #66cc99 solid; padding:3px;}
154160#diff{overflow:auto; background-color: white; border:1px #dcdcdc solid; padding:3px;}
155- #outputH{overflow:auto; background-color:white; padding:3px; border:1px #dcdcdc solid;}
156161#outputR{overflow:auto; background-color: #ccffcc; border:1px #99cc99 solid; padding:3px;}
157162span.cmtcdata{color: orange;}
158163span.ctag{color:red;}
@@ -256,6 +261,30 @@ function toggle(i){
256261 if(a == 'hidden'){e.visibility = 'show'; return;}
257262 if(a == 'show'){e.visibility = 'hidden';}
258263}
264+ function sndProc2(){
265+ var i = document.getElementById('text2');
266+ if(!i){return;}
267+ i = i.value;
268+ var w = window.open('htmLawedTest.php?pre=1', 'hlposthtm');
269+ var f = document.createElement('form');
270+ f.enctype = 'application/x-www-form-urlencoded';
271+ f.method = 'post';
272+ f.acceptCharset = '<?php echo htmlspecialchars ($ _POST ['enc ' ]); ?> ';
273+ if(f.style){f.style.display = 'none';}
274+ else{f.visibility = 'hidden';}
275+ f.innerHTML = '<p style="display:none;"><input style="display:none;" type="hidden" name="token" id="token" value="<?php echo $ token ; ?> " /><input style="display:none;" type="hidden" name="<?php echo htmlspecialchars ($ _sid ); ?> " id="<?php echo htmlspecialchars ($ _sid ); ?> " value="' + readCookie('<?php echo htmlspecialchars ($ _sid ); ?> ') + '" /></p>';
276+ f.action = 'htmLawedTest.php?pre=1';
277+ f.target = 'hlposthtm';
278+ f.method = 'post';
279+ var t = document.createElement('textarea');
280+ t.name = 'outputH';
281+ t.value = i;
282+ f.appendChild(t);
283+ var b = document.getElementsByTagName('body')[0];
284+ b.appendChild(f);
285+ f.submit();
286+ w.focus;
287+ }
259288function sndUnproc(){
260289 var i = document.getElementById('text');
261290 if(!i){return;}
@@ -455,7 +484,7 @@ function sndValidn(id, type){
455484 }
456485?>
457486
458- <button type="button" title="rendered as web-page without a doctype or charset declaration" style="float: right;" onclick="javascript: sndUnproc(); return false;" onkeypress="javascript: sndUnproc(); return false;">View unprocessed </button>
487+ <button type="button" title="Raw input rendered as web-page without a doctype or charset declaration" style="float: right;" onclick="javascript: sndUnproc(); return false;" onkeypress="javascript: sndUnproc(); return false;">Render in webpage </button>
459488<button type="button" onclick="javascript:document.getElementById('text').focus();document.getElementById('text').select()" title="select all to copy" style="float:right;">Select all</button>
460489
461490<?php
@@ -598,7 +627,7 @@ function sndValidn(id, type){
598627 $ st = microtime ();
599628 $ out = htmLawed ($ _POST ['text ' ], $ cfg , $ _POST ['spec ' ]);
600629 $ et = microtime ();
601- echo '<br /><a href="htmLawedTest.php" title="[toggle visibility] syntax-highlighted" onclick="javascript:toggle( \'inputR \'); return false;"><span class="notice">Input code »</span></a> <span class="help" title="tags estimated as half of total > and < chars; values may be inaccurate for non-ASCII text"><small><big> ' , strlen ($ _POST ['text ' ]), '</big> chars, ~<big> ' , ($ tag = round ((substr_count ($ _POST ['text ' ], '> ' ) + substr_count ($ _POST ['text ' ], '< ' ))/2 )), '</big> tag ' , ($ tag > 1 ? 's ' : '' ), '</small> </span><div id="inputR" style="display: none;"> ' , format ($ _POST ['text ' ]), '</div><script type="text/javascript">hl( \'inputR \');</script> ' , (!isset ($ _POST ['text ' ][$ _hlimit ]) ? ' <a href="htmLawedTest.php" title="[toggle visibility] hexdump; non-viewable characters like line-returns are shown as dots" onclick="javascript:toggle( \'inputD \'); return false;"><span class="notice">Input binary » </span></a><div id="inputD" style="display: none;"> ' . hexdump ($ _POST ['text ' ]). '</div> ' : '' ), ' <a href="htmLawedTest.php" title="[toggle visibility] finalized internal settings as interpreted by htmLawed; for developers" onclick="javascript:toggle( \'settingF \'); return false;"><span class="notice">Finalized internal settings » </span></a> <div id="settingF" style="display: none;">$config: ' , str_replace (array (' ' , "\t" , ' ' ), array (' ' , ' ' , ' ' ), nl2br (htmlspecialchars (print_r ($ GLOBALS ['hlcfg ' ]['config ' ], true )))), '<br />$spec: ' , str_replace (array (' ' , "\t" , ' ' ), array (' ' , ' ' , ' ' ), nl2br (htmlspecialchars (print_r ($ GLOBALS ['hlcfg ' ]['spec ' ], true )))), '</div><script type="text/javascript">hl( \'settingF \');</script> ' , '<br /><a href="htmLawedTest.php" title="[toggle visibility] suitable for copy-paste" onclick="javascript:toggle( \'outputF \'); return false;"><span class="notice">Output »</span></a> <span class="help" title="approx., server-specific value excluding the \'include() \' call"><small>htmLawed processing time <big> ' , number_format (((substr ($ et ,0 ,9 )) + (substr ($ et ,-10 )) - (substr ($ st ,0 ,9 )) - (substr ($ st ,-10 ))),4 ), '</big> s</small></span> ' , (($ mem = memory_get_peak_usage ()) !== false ? '<span class="help"><small>, peak memory usage <big> ' . round (($ mem -$ pre_mem )/1048576 , 2 ). '</big> <small>MB</small> ' : '' ), '</small></span><div id="outputF" style="display: block;"><div><textarea id="text2" class="textarea" name="text2" rows="5" cols="100" style="width: 100%;"> ' , htmlspecialchars ($ out ), '</textarea></div><button type="button" onclick="javascript:document.getElementById( \'text2 \').focus();document.getElementById( \'text2 \').select()" title="select all to copy" style="float:right;">Select all</button> ' ;
630+ echo '<br /><a href="htmLawedTest.php" title="[toggle visibility] syntax-highlighted" onclick="javascript:toggle( \'inputR \'); return false;"><span class="notice">Input code »</span></a> <span class="help" title="tags estimated as half of total > and < chars; values may be inaccurate for non-ASCII text"><small><big> ' , strlen ($ _POST ['text ' ]), '</big> chars, ~<big> ' , ($ tag = round ((substr_count ($ _POST ['text ' ], '> ' ) + substr_count ($ _POST ['text ' ], '< ' ))/2 )), '</big> tag ' , ($ tag > 1 ? 's ' : '' ), '</small> </span><div id="inputR" style="display: none;"> ' , format ($ _POST ['text ' ]), '</div><script type="text/javascript">hl( \'inputR \');</script> ' , (!isset ($ _POST ['text ' ][$ _hlimit ]) ? ' <a href="htmLawedTest.php" title="[toggle visibility] hexdump; non-viewable characters like line-returns are shown as dots" onclick="javascript:toggle( \'inputD \'); return false;"><span class="notice">Input binary » </span></a><div id="inputD" style="display: none;"> ' . hexdump ($ _POST ['text ' ]). '</div> ' : '' ), ' <a href="htmLawedTest.php" title="[toggle visibility] finalized internal settings as interpreted by htmLawed; for developers" onclick="javascript:toggle( \'settingF \'); return false;"><span class="notice">Finalized internal settings » </span></a> <div id="settingF" style="display: none;">$config: ' , str_replace (array (' ' , "\t" , ' ' ), array (' ' , ' ' , ' ' ), nl2br (htmlspecialchars (print_r ($ GLOBALS ['hlcfg ' ]['config ' ], true )))), '<br />$spec: ' , str_replace (array (' ' , "\t" , ' ' ), array (' ' , ' ' , ' ' ), nl2br (htmlspecialchars (print_r ($ GLOBALS ['hlcfg ' ]['spec ' ], true )))), '</div><script type="text/javascript">hl( \'settingF \');</script> ' , '<br /><a href="htmLawedTest.php" title="[toggle visibility] suitable for copy-paste" onclick="javascript:toggle( \'outputF \'); return false;"><span class="notice">Output »</span></a> <span class="help" title="approx., server-specific value excluding the \'include() \' call"><small>htmLawed processing time <big> ' , number_format (((substr ($ et ,0 ,9 )) + (substr ($ et ,-10 )) - (substr ($ st ,0 ,9 )) - (substr ($ st ,-10 ))),4 ), '</big> s</small></span> ' , (($ mem = memory_get_peak_usage ()) !== false ? '<span class="help"><small>, peak memory usage <big> ' . round (($ mem -$ pre_mem )/1048576 , 2 ). '</big> <small>MB</small> ' : '' ), '</small></span><div id="outputF" style="display: block;"><div><textarea id="text2" class="textarea" name="text2" rows="5" cols="100" style="width: 100%;"> ' , htmlspecialchars ($ out ), '</textarea></div><button type="button" title="Filtered input rendered as web-page without a doctype or charset declaration" style="float: right;" onclick="javascript: sndProc2(); return false;" onkeypress="javascript: sndProc2(); return false;">Render in webpage</button><button type="button" onclick="javascript:document.getElementById( \'text2 \').focus();document.getElementById( \'text2 \').select()" title="select all to copy" style="float:right;">Select all</button> ' ;
602631 if ($ _w3c_validate && $ validation )
603632 {
604633?>
@@ -608,14 +637,14 @@ function sndValidn(id, type){
608637
609638<?php
610639 }
611- echo '</div><br /><a href="htmLawedTest.php" title="[toggle visibility] syntax-highlighted" onclick="javascript:toggle( \'outputR \'); return false;"><span class="notice">Output code »</span></a><div id="outputR" style="display: block;"> ' , format ($ out ), '</div><script type="text/javascript">hl( \'outputR \');</script> ' , (!isset ($ _POST ['text ' ][$ _hlimit ]) ? ' <a href="htmLawedTest.php" title="[toggle visibility] hexdump; non-viewable characters like line-returns are shown as dots" onclick="javascript:toggle( \'outputD \'); return false;"><span class="notice">Output binary »</span></a><div id="outputD" style="display: none;"> ' . hexdump ($ out ). '</div> ' : '' ), ' <a href="htmLawedTest.php" title="[toggle visibility] inline output-input diff; might not be perfectly accurate, semantically or otherwise " onclick="javascript:toggle( \'diff \'); diffLaunch(); return false;"><span class="notice">Diff »</span></a> <div id="diff" style="display: none;"></div><br /><a href="htmLawedTest.php" title="[toggle visibility] XHTML 1 Transitional doctype" onclick="javascript:toggle( \'outputH \'); return false;"><span class="notice">Output rendered »</span></a><div id="outputH" style="display: block;"> ' , $ out , '</div> ' ;
640+ echo '</div><br /><a href="htmLawedTest.php" title="[toggle visibility] syntax-highlighted" onclick="javascript:toggle( \'outputR \'); return false;"><span class="notice">Output code »</span></a><div id="outputR" style="display: block;"> ' , format ($ out ), '</div><script type="text/javascript">hl( \'outputR \');</script> ' , (!isset ($ _POST ['text ' ][$ _hlimit ]) ? ' <a href="htmLawedTest.php" title="[toggle visibility] hexdump; non-viewable characters like line-returns are shown as dots" onclick="javascript:toggle( \'outputD \'); return false;"><span class="notice">Output binary »</span></a><div id="outputD" style="display: none;"> ' . hexdump ($ out ). '</div> ' : '' ), ' <a href="htmLawedTest.php" title="[toggle visibility] inline output-input diff; might not be perfectly accurate, semantically or otherwise " onclick="javascript:toggle( \'diff \'); diffLaunch(); return false;"><span class="notice">Diff »</span></a> <div id="diff" style="display: none;"></div><br /><a href="htmLawedTest.php" title="[toggle visibility] XHTML 1 Transitional doctype" onclick="javascript:toggle( \'outputH \'); return false;"> ' ;
612641}
613642else {
614643?>
615644
616645<br />
617646
618- <div class="help">Use with a Javascript- and cookie-enabled, relatively new version of a common browser. <em>Submitted input will also be HTML-rendered (XHTML 1) after htmLawed-filtering.</em>
647+ <div class="help">Use with a Javascript- and cookie-enabled, relatively new version of a common browser.
619648
620649<?php echo (file_exists ('./htmLawed_TESTCASE.txt ' ) ? '<br /><br />You can use text from <a href="htmLawed_TESTCASE.txt"><span class="notice">this collection of test-cases</span></a> in the input. Set the character encoding of the browser to Unicode/utf-8 before copying. ' : '' ); ?>
621650
0 commit comments