mirror of
https://github.com/mrclay/minify.git
synced 2025-09-01 09:53:36 +02:00
cleaning trunk
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (isset($_FILES['subject']['name'])) {
|
||||
|
||||
require '../config.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>
|
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (isset($_FILES['subject']['name'])
|
||||
&& preg_match('/\\.(js|css|x?html?)$/', $_FILES['subject']['name'], $m)
|
||||
) {
|
||||
require '../config.php';
|
||||
|
||||
$arg2 = null;
|
||||
switch ($m[1]) {
|
||||
case 'js':
|
||||
$type = 'Javascript';
|
||||
break;
|
||||
case 'css':
|
||||
$type = 'CSS';
|
||||
break;
|
||||
case 'html': // fallthrough
|
||||
case 'htm': // fallthrough
|
||||
case 'xhtml':
|
||||
$type = 'HTML';
|
||||
$arg2 = array(
|
||||
'cssMinifier' => array('Minify_CSS', 'minify')
|
||||
,'jsMinifier' => array('JSMin', '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'])
|
||||
. '"');
|
||||
|
||||
//@unlink($_FILES['subject']['tmp_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>
|
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
function getPost($key) {
|
||||
return get_magic_quotes_gpc()
|
||||
? stripslashes($_POST[$key])
|
||||
: $_POST[$key];
|
||||
}
|
||||
|
||||
if (isset($_POST['textIn'])) {
|
||||
require '../config.php';
|
||||
$textIn = str_replace("\r\n", "\n", getPost('textIn'));
|
||||
}
|
||||
|
||||
if (isset($_POST['method']) && $_POST['method'] === 'Minify and serve') {
|
||||
|
||||
$base = trim(getPost('base'));
|
||||
if ($base) {
|
||||
$textIn = preg_replace(
|
||||
'@(<head\\b[^>]*>)@i'
|
||||
,'$1<base href="' . htmlentities($base) . '" />'
|
||||
,$textIn
|
||||
);
|
||||
}
|
||||
|
||||
$sourceSpec['content'] = $textIn;
|
||||
$sourceSpec['id'] = 'foo';
|
||||
if (isset($_POST['minJs'])) {
|
||||
$sourceSpec['minifyOptions']['jsMinifier'] = array('JSMin', 'minify');
|
||||
}
|
||||
if (isset($_POST['minCss'])) {
|
||||
$sourceSpec['minifyOptions']['cssMinifier'] = array('Minify_CSS', 'minify');
|
||||
}
|
||||
$source = new Minify_Source($sourceSpec);
|
||||
Minify_Logger::setLogger(FirePHP::getInstance(true));
|
||||
Minify::serve('Files', array(
|
||||
'files' => $source
|
||||
,'contentType' => Minify::TYPE_HTML
|
||||
));
|
||||
exit();
|
||||
}
|
||||
|
||||
$classes = array('Minify_HTML', 'Minify_CSS', 'JSMin', 'JSMinPlus');
|
||||
|
||||
if (isset($_POST['method']) && in_array($_POST['method'], $classes)) {
|
||||
|
||||
$arg2 = null;
|
||||
if ($_POST['method'] === 'Minify_HTML') {
|
||||
$arg2 = array(
|
||||
'cssMinifier' => array('Minify_CSS', 'minify')
|
||||
,'jsMinifier' => array('JSMin', 'minify')
|
||||
);
|
||||
}
|
||||
$func = array($_POST['method'], 'minify');
|
||||
$inOutBytes[0] = strlen($textIn);
|
||||
$textOut = call_user_func($func, $textIn, $arg2);
|
||||
$inOutBytes[1] = strlen($textOut);
|
||||
}
|
||||
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
?>
|
||||
<!DOCTYPE html><head><title>minifyTextarea</title></head>
|
||||
<?php
|
||||
if (isset($inOutBytes)) {
|
||||
echo "
|
||||
<table>
|
||||
<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]} (" . round(100 * $inOutBytes[1] / $inOutBytes[0]) . "%)</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($textOut)) {
|
||||
echo htmlspecialchars($textOut);
|
||||
}
|
||||
?></textarea></label></p>
|
||||
<p>Minify with:
|
||||
<?php foreach ($classes as $minClass): ?>
|
||||
<input type="submit" name="method" value="<?php echo $minClass; ?>">
|
||||
<?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> :
|
||||
<label>JS <input type="checkbox" name="minJs" checked></label>.
|
||||
<label>Insert BASE element w/ href: <input type="text" name="base" size="20"></label>
|
||||
</p>
|
||||
</form>
|
@@ -1,159 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Fetch and minify a URL (auto-detect HTML/JS/CSS)
|
||||
*/
|
||||
|
||||
function getPost($key) {
|
||||
if (! isset($_POST[$key])) {
|
||||
return null;
|
||||
}
|
||||
return get_magic_quotes_gpc()
|
||||
? stripslashes($_POST[$key])
|
||||
: $_POST[$key];
|
||||
}
|
||||
|
||||
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)) {
|
||||
$sentType = $m[1];
|
||||
if (isset($m[3])) {
|
||||
$charset = $m[3];
|
||||
}
|
||||
if (preg_match('@^(?:text|application)/(?:x-)?(?:java|ecma)script$@i', $sentType)) {
|
||||
$type = 'application/x-javascript';
|
||||
} elseif (preg_match('@^(?:text|application)/(?:html|xml|xhtml+xml)$@i', $sentType, $m)) {
|
||||
$type = 'text/html';
|
||||
} elseif ($sentType === 'text/css') {
|
||||
$type = $sentType;
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'minify' => $type
|
||||
,'sent' => $sentType
|
||||
,'charset' => $charset
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($_POST['url'])) {
|
||||
|
||||
require '../config.php';
|
||||
|
||||
$url = trim(getPost('url'));
|
||||
$ua = trim(getPost('ua'));
|
||||
$cook = trim(getPost('cook'));
|
||||
|
||||
if (! preg_match('@^https?://@', $url)) {
|
||||
die('HTTP(s) only.');
|
||||
}
|
||||
|
||||
$httpOpts = array(
|
||||
'max_redirects' => 0
|
||||
,'timeout' => 3
|
||||
);
|
||||
if ($ua !== '') {
|
||||
$httpOpts['user_agent'] = $ua;
|
||||
}
|
||||
if ($cook !== '') {
|
||||
$httpOpts['header'] = "Cookie: {$cook}\r\n";
|
||||
}
|
||||
$ctx = stream_context_create(array(
|
||||
'http' => $httpOpts
|
||||
));
|
||||
|
||||
// fetch
|
||||
if (! ($fp = @fopen($url, 'r', false, $ctx))) {
|
||||
die('Couldn\'t open URL.');
|
||||
}
|
||||
$meta = stream_get_meta_data($fp);
|
||||
$content = stream_get_contents($fp);
|
||||
fclose($fp);
|
||||
|
||||
// get type info
|
||||
$type = sniffType($meta['wrapper_data']);
|
||||
if (! $type['minify']) {
|
||||
die('Unrecognized Content-Type: ' . $type['sent']);
|
||||
}
|
||||
|
||||
if ($type['minify'] === 'text/html'
|
||||
&& isset($_POST['addBase'])
|
||||
&& ! preg_match('@<base\\b@i', $content)) {
|
||||
$content = preg_replace(
|
||||
'@(<head\\b[^>]*>)@i'
|
||||
,'$1<base href="' . htmlentities($url) . '" />'
|
||||
,$content
|
||||
);
|
||||
}
|
||||
|
||||
$sourceSpec['content'] = $content;
|
||||
$sourceSpec['id'] = 'foo';
|
||||
|
||||
if ($type['minify'] === 'text/html') {
|
||||
if (isset($_POST['minJs'])) {
|
||||
$sourceSpec['minifyOptions']['jsMinifier'] = array('JSMin', 'minify');
|
||||
}
|
||||
if (isset($_POST['minCss'])) {
|
||||
$sourceSpec['minifyOptions']['cssMinifier'] = array('Minify_CSS', 'minify');
|
||||
}
|
||||
}
|
||||
|
||||
$source = new Minify_Source($sourceSpec);
|
||||
|
||||
$sendType = 'text/plain';
|
||||
if ($type['minify'] === 'text/html' && ! isset($_POST['asText'])) {
|
||||
$sendType = $type['sent'];
|
||||
}
|
||||
if ($type['charset']) {
|
||||
$sendType .= ';charset=' . $type['charset'];
|
||||
}
|
||||
header('Content-Type: ' . $sendType);
|
||||
// using combine instead of serve because it allows us to specify a
|
||||
// Content-Type like application/xhtml+xml IF we need to
|
||||
echo Minify::combine(array($source), array(
|
||||
'contentType' => $type['minify']
|
||||
));
|
||||
exit();
|
||||
}
|
||||
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
|
||||
$ua = get_magic_quotes_gpc()
|
||||
? stripslashes($_SERVER['HTTP_USER_AGENT'])
|
||||
: $_SERVER['HTTP_USER_AGENT'];
|
||||
|
||||
?>
|
||||
<!DOCTYPE html><head><title>Minify URL</title></head>
|
||||
|
||||
<p><strong>Warning! Please do not place this application on a public site.</strong> This should be used
|
||||
only for testing.</p>
|
||||
|
||||
<h1>Fetch and Minify a URL</h1>
|
||||
<p>This tool will retrieve the contents of a URL and minify it.
|
||||
The fetched resource Content-Type will determine the minifier used.</p>
|
||||
|
||||
<form action="?2" method="post">
|
||||
<p><label>URL: <input type="text" name="url" size="60"></label></p>
|
||||
<p><input type="submit" value="Fetch and minify"></p>
|
||||
|
||||
<fieldset><legend>HTML options</legend>
|
||||
<p>If the resource above is sent with an (x)HTML Content-Type, the following options will apply:</p>
|
||||
<ul>
|
||||
<li><label><input type="checkbox" name="asText" checked> Return plain text (o/w send the original content type)</label>
|
||||
<li><label><input type="checkbox" name="minCss" checked> Minify CSS</label>
|
||||
<li><label><input type="checkbox" name="minJs" checked> Minify JS</label>
|
||||
<li><label><input type="checkbox" name="addBase" checked> Add BASE element (if not present)</label>
|
||||
</ul>
|
||||
</fieldset>
|
||||
|
||||
<fieldset><legend>Retreival options</legend>
|
||||
<ul>
|
||||
<li><label>User-Agent: <input type="text" name="ua" size="60" value="<?php echo htmlspecialchars($ua); ?>"></label>
|
||||
<li><label>Cookie: <input type="text" name="cook" size="60"></label>
|
||||
</ul>
|
||||
</fieldset>
|
||||
|
||||
</form>
|
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
header('Content-Type: text/html;charset=utf-8');
|
||||
|
||||
function h($str) { return htmlspecialchars($str, ENT_QUOTES); }
|
||||
|
||||
function getPost($name, $default = '') { return isset($_POST[$name]) ? $_POST[$name] : $default; }
|
||||
|
||||
function getInput($name, $default = '', $size = 50) {
|
||||
$val = h(isset($_POST[$name]) ? $_POST[$name] : $default);
|
||||
return "<input type='text' name='{$name}' value='{$val}' size='{$size}' />";
|
||||
}
|
||||
|
||||
// validate user POST (no arrays and fix slashes)
|
||||
if (! empty($_POST)) {
|
||||
foreach ($_POST as $name => $val) {
|
||||
if (! is_string($val)) {
|
||||
unset($_POST[$name]);
|
||||
continue;
|
||||
}
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$_POST[$name] = stripslashes($val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$defaultCurrentDir = dirname(__FILE__);
|
||||
$defaultDocRoot = realpath($_SERVER['DOCUMENT_ROOT']);
|
||||
$defaultSymLink = '//symlinkPath';
|
||||
$defaultSymTarget = ($defaultCurrentDir[0] === '/') ? '/tmp' : 'C:\\WINDOWS\\Temp';
|
||||
$defaultCss = "url(hello.gif)\nurl(../hello.gif)\nurl(../../hello.gif)\nurl(up/hello.gif)";
|
||||
|
||||
$out = '';
|
||||
|
||||
if (isset($_POST['css'])) {
|
||||
require '../config.php';
|
||||
$symlinks = array();
|
||||
if ('' !== ($target = getPost('symTarget'))) {
|
||||
$symlinks[getPost('symLink')] = $target;
|
||||
}
|
||||
$css = Minify_CSS_UriRewriter::rewrite(
|
||||
getPost('css')
|
||||
, getPost('currentDir')
|
||||
, getPost('docRoot')
|
||||
, $symlinks
|
||||
);
|
||||
$out = "<hr /><pre><code>" . h($css) . '</code></pre>';
|
||||
}
|
||||
|
||||
?>
|
||||
<h1>Test <code>Minify_CSS_UriRewriter::rewrite()</code></h1>
|
||||
<form action="" method="post">
|
||||
<div><label>document root: <?php echo getInput('docRoot', $defaultDocRoot); ?></label></div>
|
||||
<div><label>symlink: <?php echo getInput('symLink', $defaultSymLink); ?> => <?php echo getInput('symTarget', $defaultSymTarget); ?></label></div>
|
||||
<div><label>current directory: <?php echo getInput('currentDir', $defaultCurrentDir); ?></label></div>
|
||||
<p><label>input CSS: <textarea name="css" cols="80" rows="5"><?php echo h(getPost('css', $defaultCss)); ?></textarea></label></p>
|
||||
<p><input type="submit" value="rewrite()" /></p>
|
||||
</form>
|
||||
<?php echo $out; ?>
|
Reference in New Issue
Block a user