index.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. if (phpversion() < 5) {
  3. exit('Minify requires PHP5 or greater.');
  4. }
  5. // check for auto-encoding
  6. $encodeOutput = (function_exists('gzdeflate')
  7. && !ini_get('zlib.output_compression'));
  8. require dirname(__FILE__) . '/../config.php';
  9. if (! $min_enableBuilder) {
  10. header('Location: /');
  11. exit();
  12. }
  13. ob_start();
  14. ?>
  15. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  16. <head>
  17. <meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
  18. <title>Minify URI Builder</title>
  19. <style type="text/css">
  20. body {margin:1em 60px;}
  21. h1, h2, h3 {margin-left:-25px; position:relative;}
  22. h1 {margin-top:0;}
  23. #sources {margin:0; padding:0;}
  24. #sources li {margin:0 0 0 40px}
  25. #sources li input {margin-left:2px}
  26. #add {margin:5px 0 1em 40px}
  27. .hide {display:none}
  28. #uriTable {border-collapse:collapse;}
  29. #uriTable td, #uriTable th {padding-top:10px;}
  30. #uriTable th {padding-right:10px;}
  31. #groupConfig {font-family:monospace;}
  32. b {color:#c00}
  33. .topNote {background: #ff9; display:inline-block; padding:.5em .6em; margin:0 0 1em;}
  34. .topWarning {background:#c00; color:#fff; padding:.5em .6em; margin:0 0 1em;}
  35. </style>
  36. </head>
  37. <?php if (! isset($min_cachePath)): ?>
  38. <p class=topNote><strong>Note:</strong> Please set <code>$min_cachePath</code>
  39. in /min/config.php to improve performance.</p>
  40. <?php endIf; ?>
  41. <p id=minRewriteFailed class="hide"><strong>Note:</strong> Your webserver does not seem to
  42. support mod_rewrite (used in /min/.htaccess). Your Minify URIs will contain "?", which
  43. <a href="http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/"
  44. >may reduce the benefit of proxy cache servers</a>.</p>
  45. <h1>Minify URI Builder</h1>
  46. <noscript><p class="topNote">Javascript and a browser supported by jQuery 1.2.6 is required
  47. for this application.</p></noscript>
  48. <div id=app class=hide>
  49. <p>Create a list of Javascript or CSS files (or 1 is fine) you'd like to combine
  50. and click [Update].</p>
  51. <ol id=sources><li></li></ol>
  52. <div id=add><button>Add file +</button></div>
  53. <div id=bmUris></div>
  54. <p><button id=update class=hide>Update</button></p>
  55. <div id=results class=hide>
  56. <h2>Minify URI</h2>
  57. <p>Place this URI in your HTML to serve the files above combined, minified, compressed and
  58. with cache headers.</p>
  59. <table id=uriTable>
  60. <tr><th>URI</th><td><a id=uriA class=ext>/min</a> <small>(opens in new window)</small></td></tr>
  61. <tr><th>HTML</th><td><input id=uriHtml type=text size=100 readonly></td></tr>
  62. </table>
  63. <h2>How to serve these files as a group</h2>
  64. <p>For the best performance you can serve these files as a pre-defined group with a URI
  65. like: <code><span class=minRoot>/min/?</span>g=keyName</code></p>
  66. <p>To do this, add a line like this to /min/groupsConfig.php:</p>
  67. <pre><code>return array(
  68. <span style="color:#666">... your existing groups here ...</span>
  69. <input id=groupConfig size=100 type=text readonly>
  70. );</code></pre>
  71. <p><em>Make sure to replace <code>keyName</code> with a unique key for this group.</em></p>
  72. </div>
  73. <div id=getBm>
  74. <h3>Find URIs on a Page</h3>
  75. <p>You can use the bookmarklet below to fetch all CSS &amp; Javascript URIs from a page
  76. on your site. When you active it, this page will open in a new window with a list of
  77. available URIs to add.</p>
  78. <p><a id=bm>Create Minify URIs</a> <small>(right-click, add to bookmarks)</small></p>
  79. </div>
  80. <h3>Combining CSS files that contain <code>@import</code></h3>
  81. <p>If your CSS files contain <code>@import</code> declarations, Minify will not
  82. remove them. Therefore, you will want to remove those that point to files already
  83. in your list, and move any others to the top of the first file in your list
  84. (imports below any styles will be ignored by browsers as invalid).</p>
  85. <p>If you desire, you can use Minify URIs in imports and they will not be touched
  86. by Minify. E.g. <code>@import "<span class=minRoot>/min/?</span>g=css2";</code></p>
  87. </div><!-- #app -->
  88. <hr>
  89. <p>Need help? Search or post to the <a class=ext
  90. href="http://groups.google.com/group/minify">Minify discussion list</a>.</p>
  91. <p><small>This app is minified :) <a class=ext
  92. href="http://code.google.com/p/minify/source/browse/trunk/min/builder/index.php">view
  93. source</a></small></p>
  94. <script type="text/javascript"
  95. src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
  96. <script type="text/javascript">
  97. $(function () {
  98. // detection of double output encoding
  99. var msg = '<\p class=topWarning><\strong>Warning:<\/strong> ';
  100. var url = 'ocCheck.php?' + (new Date()).getTime();
  101. $.get(url, function (ocStatus) {
  102. $.get(url + '&hello=1', function (ocHello) {
  103. if (ocHello != 'World!') {
  104. msg += 'It appears output is being automatically compressed, interfering '
  105. + ' with Minify\'s own compression. ';
  106. if (ocStatus == '1')
  107. msg += 'The option "zlib.output_compression" is enabled in your PHP configuration. '
  108. + 'Minify set this to "0", but it had no effect. This option must be disabled '
  109. + 'in php.ini or .htaccess.';
  110. else
  111. msg += 'The option "zlib.output_compression" is disabled in your PHP configuration '
  112. + 'so this behavior is likely due to a server option.';
  113. $(document.body).prepend(msg + '<\/p>');
  114. } else
  115. if (ocStatus == '1')
  116. $(document.body).prepend('<\p class=topNote><\strong>Note:</\strong> The option '
  117. + '"zlib.output_compression" is enabled in your PHP configuration, but has been '
  118. + 'successfully disabled via ini_set(). If you experience mangled output you '
  119. + 'may want to consider disabling this option in your PHP configuration.<\/p>'
  120. );
  121. });
  122. });
  123. });
  124. </script>
  125. <script type="text/javascript">
  126. // workaround required to test when /min isn't child of web root
  127. var src = location.pathname.replace(/\/[^\/]*$/, '/_index.js').substr(1);
  128. document.write('<\script type="text/javascript" src="../?f=' + src + '"><\/script>');
  129. </script>
  130. <?php
  131. $serveOpts = array(
  132. 'content' => ob_get_contents()
  133. ,'id' => __FILE__
  134. ,'lastModifiedTime' => max(
  135. // regenerate cache if either of these change
  136. filemtime(__FILE__)
  137. ,filemtime(dirname(__FILE__) . '/../config.php')
  138. )
  139. ,'minifyAll' => true
  140. ,'encodeOutput' => $encodeOutput
  141. );
  142. ob_end_clean();
  143. set_include_path(dirname(__FILE__) . '/../lib' . PATH_SEPARATOR . get_include_path());
  144. require 'Minify.php';
  145. if (0 === stripos(PHP_OS, 'win')) {
  146. Minify::setDocRoot(); // we may be on IIS
  147. }
  148. Minify::setCache(isset($min_cachePath) ? $min_cachePath : null);
  149. Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
  150. Minify::serve('Page', $serveOpts);