1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-09 07:36:56 +02:00

Add elapsed time to minifyTextarea, better escaping

This commit is contained in:
Steve Clay
2012-11-25 16:34:55 -05:00
parent 7e08cff1f0
commit f680ac83e7
2 changed files with 10 additions and 7 deletions

View File

@@ -17,7 +17,7 @@ if (isset($_POST['method']) && $_POST['method'] === 'Minify and serve') {
if ($base) { if ($base) {
$textIn = preg_replace( $textIn = preg_replace(
'@(<head\\b[^>]*>)@i' '@(<head\\b[^>]*>)@i'
,'$1<base href="' . htmlentities($base) . '" />' ,'$1<base href="' . htmlspecialchars($base, ENT_QUOTES, 'UTF-8') . '" />'
,$textIn ,$textIn
); );
} }
@@ -38,7 +38,7 @@ if (isset($_POST['method']) && $_POST['method'] === 'Minify and serve') {
,'contentType' => Minify::TYPE_HTML ,'contentType' => Minify::TYPE_HTML
)); ));
} catch (Exception $e) { } catch (Exception $e) {
echo htmlspecialchars($e->getMessage()); echo htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
} }
exit(); exit();
} }
@@ -56,12 +56,14 @@ if (isset($_POST['method']) && in_array($_POST['method'], $classes)) {
} }
$func = array($_POST['method'], 'minify'); $func = array($_POST['method'], 'minify');
$inOutBytes[0] = strlen($textIn); $inOutBytes[0] = strlen($textIn);
$startTime = microtime(true);
try { try {
$textOut = call_user_func_array($func, $args); $textOut = call_user_func_array($func, $args);
} catch (Exception $e) { } catch (Exception $e) {
echo htmlspecialchars($e->getMessage()); echo htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
exit; exit;
} }
$elapsedTime = microtime(true) - $startTime;
$inOutBytes[1] = strlen($textOut); $inOutBytes[1] = strlen($textOut);
} }
@@ -74,6 +76,7 @@ if (isset($inOutBytes)) {
<table> <table>
<tr><th>Bytes in</th><td>{$inOutBytes[0]} (after line endings normalized to <code>\\n</code>)</td></tr> <tr><th>Bytes in</th><td>{$inOutBytes[0]} (after line endings normalized to <code>\\n</code>)</td></tr>
<tr><th>Bytes out</th><td>{$inOutBytes[1]} (reduced " . round(100 - (100 * $inOutBytes[1] / $inOutBytes[0])) . "%)</td></tr> <tr><th>Bytes out</th><td>{$inOutBytes[1]} (reduced " . round(100 - (100 * $inOutBytes[1] / $inOutBytes[0])) . "%)</td></tr>
<tr><th>Time (s)</th><td>" . round($elapsedTime, 5) . "</td></tr>
</table> </table>
"; ";
} }
@@ -81,7 +84,7 @@ if (isset($inOutBytes)) {
<form action="?2" method="post"> <form action="?2" method="post">
<p><label>Content<br><textarea name="textIn" cols="80" rows="35" style="width:99%"><?php <p><label>Content<br><textarea name="textIn" cols="80" rows="35" style="width:99%"><?php
if (isset($textOut)) { if (isset($textOut)) {
echo htmlspecialchars($textOut); echo htmlspecialchars($textOut, ENT_QUOTES, 'UTF-8');
} }
?></textarea></label></p> ?></textarea></label></p>
<p>Minify with: <p>Minify with:

View File

@@ -84,7 +84,7 @@ if (isset($_POST['url'])) {
&& ! preg_match('@<base\\b@i', $content)) { && ! preg_match('@<base\\b@i', $content)) {
$content = preg_replace( $content = preg_replace(
'@(<head\\b[^>]*>)@i' '@(<head\\b[^>]*>)@i'
,'$1<base href="' . htmlentities($url) . '" />' ,'$1<base href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '" />'
,$content ,$content
); );
} }
@@ -119,7 +119,7 @@ if (isset($_POST['url'])) {
)); ));
} catch (Exception $e) { } catch (Exception $e) {
header('Content-Type: text/html;charset=utf-8'); header('Content-Type: text/html;charset=utf-8');
echo htmlspecialchars($e->getMessage()); echo htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
} }
exit(); exit();
} }
@@ -156,7 +156,7 @@ The fetched resource Content-Type will determine the minifier used.</p>
<fieldset><legend>Retreival options</legend> <fieldset><legend>Retreival options</legend>
<ul> <ul>
<li><label>User-Agent: <input type="text" name="ua" size="60" value="<?php echo htmlspecialchars($ua); ?>"></label> <li><label>User-Agent: <input type="text" name="ua" size="60" value="<?php echo htmlspecialchars($ua, ENT_QUOTES, 'UTF-8'); ?>"></label>
<li><label>Cookie: <input type="text" name="cook" size="60"></label> <li><label>Cookie: <input type="text" name="cook" size="60"></label>
</ul> </ul>
</fieldset> </fieldset>