diff --git a/min_extras/README.txt b/min_extras/README.txt
new file mode 100644
index 0000000..1fef8a8
--- /dev/null
+++ b/min_extras/README.txt
@@ -0,0 +1,11 @@
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+DO NOT leave this directory on a site in production. Some scripts within may be
+resource intensive and some allow file uploads.
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+This directory contains testing scripts and a few example applications built
+with the Minify library classes.
+
+tools/
+ Two utility web apps that upload a file, alter it, and send it back to the
+ user. One applies HTTP encoding, the other minifies CSS/JS/HTML.
diff --git a/min_extras/config.php b/min_extras/config.php
new file mode 100644
index 0000000..459fc32
--- /dev/null
+++ b/min_extras/config.php
@@ -0,0 +1,16 @@
+]*>)@i'
+ ,'$1'
+ ,$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));
+ try {
+ Minify::serve('Files', array(
+ 'files' => $source
+ ,'contentType' => Minify::TYPE_HTML
+ ));
+ } catch (Exception $e) {
+ echo htmlspecialchars($e->getMessage());
+ }
+ exit();
+}
+
+$classes = array('Minify_HTML', 'Minify_CSS', 'JSMin', 'JSMinPlus');
+
+if (isset($_POST['method']) && in_array($_POST['method'], $classes)) {
+
+ $args = array($textIn);
+ if ($_POST['method'] === 'Minify_HTML') {
+ $args[] = array(
+ 'cssMinifier' => array('Minify_CSS', 'minify')
+ ,'jsMinifier' => array('JSMin', 'minify')
+ );
+ }
+ $func = array($_POST['method'], 'minify');
+ $inOutBytes[0] = strlen($textIn);
+ try {
+ $textOut = call_user_func_array($func, $args);
+ } catch (Exception $e) {
+ echo htmlspecialchars($e->getMessage());
+ exit;
+ }
+ $inOutBytes[1] = strlen($textOut);
+}
+
+header('Content-Type: text/html; charset=utf-8');
+?>
+
minifyTextarea
+
+ Bytes in | {$inOutBytes[0]} (after line endings normalized to \\n ) |
+ Bytes out | {$inOutBytes[1]} (reduced " . round(100 - (100 * $inOutBytes[1] / $inOutBytes[0])) . "%) |
+
+ ";
+}
+?>
+
diff --git a/min_extras/tools/minifyUrl.php b/min_extras/tools/minifyUrl.php
new file mode 100644
index 0000000..e313bda
--- /dev/null
+++ b/min_extras/tools/minifyUrl.php
@@ -0,0 +1,164 @@
+ $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('@]*>)@i'
+ ,'$1'
+ ,$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
+ try {
+ echo Minify::combine(array($source), array(
+ 'contentType' => $type['minify']
+ ));
+ } catch (Exception $e) {
+ header('Content-Type: text/html;charset=utf-8');
+ echo htmlspecialchars($e->getMessage());
+ }
+ exit();
+}
+
+header('Content-Type: text/html; charset=utf-8');
+
+$ua = get_magic_quotes_gpc()
+ ? stripslashes($_SERVER['HTTP_USER_AGENT'])
+ : $_SERVER['HTTP_USER_AGENT'];
+
+?>
+Minify URL
+
+Warning! Please do not place this application on a public site. This should be used
+only for testing.
+
+Fetch and Minify a URL
+This tool will retrieve the contents of a URL and minify it.
+The fetched resource Content-Type will determine the minifier used.
+
+
diff --git a/min_extras/tools/testRewriteUri.php b/min_extras/tools/testRewriteUri.php
new file mode 100644
index 0000000..b40d9d8
--- /dev/null
+++ b/min_extras/tools/testRewriteUri.php
@@ -0,0 +1,58 @@
+";
+}
+
+// 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 = "
" . h($css) . '
';
+}
+
+?>
+Test Minify_CSS_UriRewriter::rewrite()
+
+
\ No newline at end of file