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

+ web/tools

This commit is contained in:
Steve Clay
2008-06-04 05:12:03 +00:00
parent c314cbecd6
commit 6cf3d1d792
2 changed files with 82 additions and 0 deletions

32
web/tools/encodeFile.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
if (isset($_FILES['subject']['name'])) {
require '../../lib/HTTP/Encoder.php';
$he = new HTTP_Encoder(array(
'content' => file_get_contents($_FILES['subject']['tmp_name'])
,'method' => $_POST['method']
));
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header("Content-Disposition: attachment; filename=\"{$_FILES['subject']['name']}."
. ($_POST['method'] == 'deflate'
? 'zd'
: ($_POST['method'] == 'gzip'
? 'zg'
: 'zc'
)
) . '"');
$he->encode(9);
echo $he->getContent();
exit();
}
?>
<form enctype="multipart/form-data" action="" method="post">
<p>Encode <input type="file" name="subject" /><br />
as <input type="submit" name="method" value="deflate" />
<input type="submit" name="method" value="gzip" />
<input type="submit" name="method" value="compress" />
</p>
</form>

50
web/tools/minifyFile.php Normal file
View File

@@ -0,0 +1,50 @@
<?php
if (isset($_FILES['subject']['name'])
&& preg_match('/\\.(js|css|html)$/', $_FILES['subject']['name'], $m)
) {
ini_set('include_path',
dirname(__FILE__) . '/../../lib'
. PATH_SEPARATOR . ini_get('include_path')
);
// eh why not
require 'Minify/HTML.php';
require 'Minify/CSS.php';
require 'Minify/Javascript.php';
$arg2 = null;
switch ($m[1]) {
case 'js':
$type = 'Javascript';
break;
case 'css':
$type = 'CSS';
break;
case 'html':
$type = 'HTML';
$arg2 = array(
'cssMinifier' => array('Minify_CSS', 'minify')
,'jsMinifier' => array('Minify_Javascript', 'minify')
);
}
$func = array('Minify_' . $type, 'minify');
$out = call_user_func($func, file_get_contents($_FILES['subject']['tmp_name']), $arg2);
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="'
. preg_replace('/\\.(\w+)$/', '.min.$1', $_FILES['subject']['name'])
. '"');
echo $out;
exit();
}
?>
<form enctype="multipart/form-data" action="" method="post">
<p>Minify <input type="file" name="subject" /><br />
<input type="submit" name="method" value="Go!" />
</p>
</form>