mirror of
https://github.com/mrclay/minify.git
synced 2025-08-30 09:09:54 +02:00
Apply php-cs-fixer fixers
- braces - function_declaration - lowercase_keywords - method_argument_space - no_spaces_inside_parenthesis - no_trailing_whitespace - no_trailing_whitespace_in_comment - single_blank_line_at_eof
This commit is contained in:
@@ -13,7 +13,8 @@ $app->cache = new Minify_Cache_Null();
|
||||
|
||||
$env = $app->env;
|
||||
|
||||
function h($txt) {
|
||||
function h($txt)
|
||||
{
|
||||
return htmlspecialchars($txt, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
@@ -22,13 +23,12 @@ if ($env->post('textIn')) {
|
||||
}
|
||||
|
||||
if ($env->post('method') === 'Minify and serve') {
|
||||
|
||||
$base = trim($env->post('base'));
|
||||
if ($base) {
|
||||
$textIn = preg_replace(
|
||||
'@(<head\\b[^>]*>)@i'
|
||||
,'$1<base href="' . h($base) . '" />'
|
||||
,$textIn
|
||||
'@(<head\\b[^>]*>)@i',
|
||||
'$1<base href="' . h($base) . '" />',
|
||||
$textIn
|
||||
);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ $tpl = array();
|
||||
$tpl['classes'] = array('Minify_HTML', 'JSMin\\JSMin', 'Minify_CSS', 'Minify_Lines');
|
||||
|
||||
if (in_array($env->post('method'), $tpl['classes'])) {
|
||||
|
||||
$args = array($textIn);
|
||||
if ($env->post('method') === 'Minify_HTML') {
|
||||
$args[] = array(
|
||||
@@ -88,7 +87,8 @@ sendPage($tpl);
|
||||
* @param string $input
|
||||
* @return string HTML
|
||||
*/
|
||||
function getExceptionMsg(Exception $e, $input) {
|
||||
function getExceptionMsg(Exception $e, $input)
|
||||
{
|
||||
$msg = "<p>" . h($e->getMessage()) . "</p>";
|
||||
if (0 === strpos(get_class($e), 'JSMin_Unterminated')
|
||||
&& preg_match('~byte (\d+)~', $e->getMessage(), $m)) {
|
||||
@@ -113,37 +113,35 @@ function getExceptionMsg(Exception $e, $input) {
|
||||
*
|
||||
* @param array $vars
|
||||
*/
|
||||
function sendPage($vars) {
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
?>
|
||||
function sendPage($vars)
|
||||
{
|
||||
header('Content-Type: text/html; charset=utf-8'); ?>
|
||||
<!DOCTYPE html><head><title>minifyTextarea</title></head>
|
||||
|
||||
<p><strong>Warning! Please do not place this application on a public site.</strong> This should be used only for testing.</p>
|
||||
|
||||
<?php
|
||||
if (isset($vars['exceptionMsg'])) {
|
||||
echo $vars['exceptionMsg'];
|
||||
}
|
||||
if (isset($vars['time'])) {
|
||||
echo "
|
||||
echo $vars['exceptionMsg'];
|
||||
}
|
||||
if (isset($vars['time'])) {
|
||||
echo "
|
||||
<table>
|
||||
<tr><th>Bytes in</th><td>{$vars['inBytes']} (after line endings normalized to <code>\\n</code>)</td></tr>
|
||||
<tr><th>Bytes out</th><td>{$vars['outBytes']} (reduced " . round(100 - (100 * $vars['outBytes'] / $vars['inBytes'])) . "%)</td></tr>
|
||||
<tr><th>Time (s)</th><td>" . round($vars['time'], 5) . "</td></tr>
|
||||
</table>
|
||||
";
|
||||
}
|
||||
?>
|
||||
} ?>
|
||||
<form action="?2" method="post">
|
||||
<p><label>Content<br><textarea name="textIn" cols="80" rows="35" style="width:99%"><?php
|
||||
if (isset($vars['output'])) {
|
||||
echo h($vars['output']);
|
||||
}
|
||||
?></textarea></label></p>
|
||||
echo h($vars['output']);
|
||||
} ?></textarea></label></p>
|
||||
<p>Minify with:
|
||||
<?php foreach ($vars['classes'] as $minClass): ?>
|
||||
<input type="submit" name="method" value="<?php echo $minClass; ?>">
|
||||
<?php endForEach; ?>
|
||||
<?php endforeach; ?>
|
||||
</p>
|
||||
<p>...or <input type="submit" name="method" value="Minify and serve"> this HTML to the browser. Also minify:
|
||||
<label>CSS <input type="checkbox" name="minCss" checked></label> :
|
||||
|
@@ -12,7 +12,8 @@ $app->cache = new Minify_Cache_Null();
|
||||
|
||||
$env = $app->env;
|
||||
|
||||
function getPost($key) {
|
||||
function getPost($key)
|
||||
{
|
||||
if (! isset($_POST[$key])) {
|
||||
return null;
|
||||
}
|
||||
@@ -21,14 +22,16 @@ function getPost($key) {
|
||||
: $_POST[$key];
|
||||
}
|
||||
|
||||
function sniffType($headers) {
|
||||
function sniffType($headers)
|
||||
{
|
||||
$charset = 'utf-8';
|
||||
$type = null;
|
||||
$headers = "\n\n" . implode("\n\n", $headers) . "\n\n";
|
||||
if (preg_match(
|
||||
'@\\n\\nContent-Type: *([\\w/\\+-]+)( *; *charset *= *([\\w-]+))? *\\n\\n@i'
|
||||
,$headers
|
||||
,$m)) {
|
||||
'@\\n\\nContent-Type: *([\\w/\\+-]+)( *; *charset *= *([\\w-]+))? *\\n\\n@i',
|
||||
$headers,
|
||||
$m
|
||||
)) {
|
||||
$sentType = $m[1];
|
||||
if (isset($m[3])) {
|
||||
$charset = $m[3];
|
||||
@@ -49,7 +52,6 @@ function sniffType($headers) {
|
||||
}
|
||||
|
||||
if (isset($_POST['url'])) {
|
||||
|
||||
require '../config.php';
|
||||
|
||||
$url = trim($env->post('url'));
|
||||
@@ -88,13 +90,13 @@ if (isset($_POST['url'])) {
|
||||
die('Unrecognized Content-Type: ' . $type['sent']);
|
||||
}
|
||||
|
||||
if ($type['minify'] === 'text/html'
|
||||
if ($type['minify'] === 'text/html'
|
||||
&& isset($_POST['addBase'])
|
||||
&& ! preg_match('@<base\\b@i', $content)) {
|
||||
$content = preg_replace(
|
||||
'@(<head\\b[^>]*>)@i'
|
||||
,'$1<base href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '" />'
|
||||
,$content
|
||||
'@(<head\\b[^>]*>)@i',
|
||||
'$1<base href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '" />',
|
||||
$content
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -8,9 +8,13 @@ $env = $app->env;
|
||||
|
||||
header('Content-Type: text/html;charset=utf-8');
|
||||
|
||||
function h($str) { return htmlspecialchars($str, ENT_QUOTES); }
|
||||
function h($str)
|
||||
{
|
||||
return htmlspecialchars($str, ENT_QUOTES);
|
||||
}
|
||||
|
||||
function getInput($name, $default = '', $size = 50) {
|
||||
function getInput($name, $default = '', $size = 50)
|
||||
{
|
||||
global $env;
|
||||
$val = $env->post($name, $default);
|
||||
return "<input type='text' name='{$name}' value='" . h($val) . "' size='{$size}' />";
|
||||
|
Reference in New Issue
Block a user