diff --git a/min/builder/_index.html b/min/builder/_index.html new file mode 100644 index 0000000..7bfcb6b --- /dev/null +++ b/min/builder/_index.html @@ -0,0 +1,39 @@ + + + Minify URI Builder + + +

Minify URI Builder

+ +

Create a list of Javascript or CSS files and click [Update] to generate +a URI to serve them as one file through Minify.

+ +
+
+ +

+ + + + +
URI/min (opens in new window)
HTML
+ + + + + + \ No newline at end of file diff --git a/min/builder/index.html b/min/builder/index.html deleted file mode 100644 index 486b124..0000000 --- a/min/builder/index.html +++ /dev/null @@ -1,24 +0,0 @@ - - - Minify URI Builder - - -

Minify URI Builder

- -
    -
    Add file +
    - -

    - - - - -
    URI/min (opens in new window)
    HTML
    - - - \ No newline at end of file diff --git a/min/builder/index.js b/min/builder/index.js index 7e7e5da..5c3de08 100644 --- a/min/builder/index.js +++ b/min/builder/index.js @@ -2,16 +2,17 @@ var MUB = { _uid : 0 ,newLi : function () { - return '
  1. http://' + location.host + '/' + return '
  2. http://' + location.host + '/' + ' ' - + ' test link
  3. '; + + ' '; } ,addLi : function () { $('#sources').append(MUB.newLi()); var li = $('#li' + MUB._uid)[0]; $('button[title=Remove]', li).click(function () { + var hadValue = !!$('input', li)[0].value; $(li).remove(); + hadValue && MUB.update(); }); $('button[title$=Earlier]', li).click(function () { $(li).prev('li').find('input').each(function () { @@ -19,6 +20,8 @@ var MUB = { var tmp = this.value; this.value = $('input', li).val(); $('input', li).val(tmp); + MUB.updateAllTestLinks(); + MUB.update(); }); }); $('button[title$=Later]', li).click(function () { @@ -27,18 +30,83 @@ var MUB = { var tmp = this.value; this.value = $('input', li).val(); $('input', li).val(tmp); + MUB.updateAllTestLinks(); + MUB.update(); }); }); - $('input', li).keyup(function () { - $('a', li)[0].href = '/' + this.value; - }); ++MUB._uid; } + ,liUpdateTestLink : function () { // call in context of li element + if (! $('input', this)[0].value) + return; + var li = this; + $('span', this).html(''); + var url = 'http://' + location.host + '/' + + $('input', this)[0].value.replace(/^\//, ''); + $.ajax({ + url : url + ,complete : function (xhr, stat) { + $('span', li).html( + 'success' == stat + ? '✓' + : 'file not found!' + ); + } + ,dataType : 'text' + }); + } + ,updateAllTestLinks : function () { + $('#sources li').each(MUB.liUpdateTestLink); + } + ,getCommonCharAtPos : function (arr, pos) { + var i + ,l = arr.length + ,c = arr[0].charAt(pos); + if (c === '' || l === 1) + return c; + for (i = 1; i < l; ++i) + if (arr[i].charAt(pos) !== c) + return ''; + return c; + } + ,getBestUri : function (sources) { + var pos = 0 + ,base = '' + ,c; + while (true) { + c = MUB.getCommonCharAtPos(sources, pos); + if (c === '') + break; + else + base += c; + ++pos; + } + base = base.replace(/[^\/]+$/, ''); + var uri = '/min/?f=' + sources.join(','); + if (base.charAt(base.length - 1) === '/') { + // we have a base dir! + var basedSources = sources + ,i + ,l = sources.length; + for (i = 0; i < l; ++i) { + basedSources[i] = sources[i].substr(base.length); + } + base = base.substr(0, base.length - 1); + var bUri = '/min/?b=' + base + '&f=' + basedSources.join(','); + //window.console && console.log([uri, bUri]); + uri = uri.length < bUri.length + ? uri + : bUri; + } + return uri; + } ,update : function () { + MUB.updateAllTestLinks(); var sources = [] ,ext = false ,fail = false; $('#sources input').each(function () { + var m, val; if (! fail && this.value && (m = this.value.match(/\.(css|js)$/))) { var thisExt = m[1]; if (ext === false) @@ -47,6 +115,7 @@ var MUB = { fail = true; return alert('extensions must match!'); } + this.value = this.value.replace(/^\//, ''); if (-1 != $.inArray(this.value, sources)) { fail = true; return alert('duplicate file!'); @@ -56,24 +125,28 @@ var MUB = { }); if (fail || ! sources.length) return; - var uri = '/min/?f=' + sources.join(',') - ,uriH = uri.replace(//, '>').replace(/&/, '&'); + var uri = MUB.getBestUri(sources) + ,uriH = uri.replace(//, '>').replace(/&/, '&'); $('#uriA').html(uriH)[0].href = uri; $('#uriHtml').val( ext === 'js' ? '' : '' ); - $('table').show(); + $('#uriTable').show(); } ,init : function () { - $('#add a').click(MUB.addLi); + $('#sources').html(''); + $('#add button').click(function () { + MUB.addLi(); + MUB.updateAllTestLinks(); + $('#update').show().click(MUB.update); + }); $('#uriHtml').click(function () { this.select(); }).focus(function () { this.select(); }); - $('#update').click(MUB.update); } }; window.onload = MUB.init; \ No newline at end of file diff --git a/min/builder/index.php b/min/builder/index.php new file mode 100644 index 0000000..53e463e --- /dev/null +++ b/min/builder/index.php @@ -0,0 +1,12 @@ + dirname(__FILE__) . '/_index.html' + ,'minifyAll' => true +)); diff --git a/min/index.php b/min/index.php index 4eb4525..3adf3ca 100644 --- a/min/index.php +++ b/min/index.php @@ -27,6 +27,10 @@ if (! (include 'Minify.php')) { ); } +if (0 === stripos(PHP_OS, 'win')) { + Minify::setDocRoot(); // we may be on IIS +} + Minify::$uploaderHoursBehind = $min_uploaderHoursBehind; if (isset($_GET['g'])) { diff --git a/min/lib/Minify.php b/min/lib/Minify.php index 3ba5d9d..a085bb7 100644 --- a/min/lib/Minify.php +++ b/min/lib/Minify.php @@ -323,6 +323,30 @@ class Minify { } } + /** + * On IIS, create $_SERVER['DOCUMENT_ROOT'] + * + * @param bool $unsetPathInfo (default false) if true, $_SERVER['PATH_INFO'] + * will be unset (it is inconsistent with Apache's setting) + * + * @return null + */ + public static function setDocRoot($unsetPathInfo = false) + { + if (isset($_SERVER['SERVER_SOFTWARE']) + && 0 === strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/') + ) { + $_SERVER['DOCUMENT_ROOT'] = substr( + $_SERVER['PATH_TRANSLATED'] + ,0 + ,strlen($_SERVER['PATH_TRANSLATED']) - strlen($_SERVER['SCRIPT_NAME']) + ); + if ($unsetPathInfo) { + unset($_SERVER['PATH_INFO']); + } + } + } + /** * @var Minify_Controller active controller for current request */ diff --git a/min/lib/Minify/Controller/Page.php b/min/lib/Minify/Controller/Page.php index b8c090b..b1ff9fd 100644 --- a/min/lib/Minify/Controller/Page.php +++ b/min/lib/Minify/Controller/Page.php @@ -36,13 +36,18 @@ class Minify_Controller_Page extends Minify_Controller_Base { * @todo Add 'file' option to read HTML file. */ public function setupSources($options) { - // strip controller options - $sourceSpec = array( - 'content' => $options['content'] - ,'id' => $options['id'] - ); - unset($options['content'], $options['id']); - + if (isset($options['file'])) { + $sourceSpec = array( + 'filepath' => $options['file'] + ); + } else { + // strip controller options + $sourceSpec = array( + 'content' => $options['content'] + ,'id' => $options['id'] + ); + unset($options['content'], $options['id']); + } if (isset($options['minifyAll'])) { // this will be the 2nd argument passed to Minify_HTML::minify() $sourceSpec['minifyOptions'] = array(