index.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. // recommend $min_symlinks setting for Apache UserDir
  9. $symlinkOption = '';
  10. if (0 === strpos($_SERVER["SERVER_SOFTWARE"], 'Apache/')
  11. && preg_match('@^/\\~(\\w+)/@', $_SERVER['REQUEST_URI'], $m)
  12. ) {
  13. $userDir = DIRECTORY_SEPARATOR . $m[1] . DIRECTORY_SEPARATOR;
  14. if (false !== strpos(__FILE__, $userDir)) {
  15. $sm = array();
  16. $sm["//~{$m[1]}"] = dirname(dirname(__FILE__));
  17. $array = str_replace('array (', 'array(', var_export($sm, 1));
  18. $symlinkOption = "\$min_symlinks = $array;";
  19. }
  20. }
  21. require dirname(__FILE__) . '/../config.php';
  22. require "$min_libPath/Minify/Loader.php";
  23. Minify_Loader::register();
  24. if (! $min_enableBuilder) {
  25. header('Content-Type: text/plain');
  26. die('This application is not enabled. See http://code.google.com/p/minify/wiki/BuilderApp');
  27. }
  28. if (isset($min_builderPassword)
  29. && is_string($min_builderPassword)
  30. && $min_builderPassword !== '') {
  31. DooDigestAuth::http_auth('Minify Builder', array('admin' => $min_builderPassword));
  32. }
  33. $cachePathCode = '';
  34. if (! isset($min_cachePath) && ! function_exists('sys_get_temp_dir')) {
  35. $detectedTmp = Minify_Cache_File::tmp();
  36. $cachePathCode = "\$min_cachePath = " . var_export($detectedTmp, 1) . ';';
  37. }
  38. ob_start();
  39. ?>
  40. <!DOCTYPE html>
  41. <title>Minify URI Builder</title>
  42. <meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
  43. <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
  44. <style>
  45. body {margin:1em 60px;}
  46. h1, h2, h3 {margin-left:-25px; position:relative;}
  47. h1 {margin-top:0;}
  48. #sources {margin:0; padding:0;}
  49. #sources li {margin:0 0 0 40px}
  50. #sources li input {margin-left:2px}
  51. #add {margin:5px 0 1em 40px}
  52. .hide {display:none}
  53. #uriTable {border-collapse:collapse;}
  54. #uriTable td, #uriTable th {padding-top:10px;}
  55. #uriTable th {padding-right:10px;}
  56. #groupConfig {font-family:monospace;}
  57. b {color:#c00}
  58. .topNote {background: #ff9; display:inline-block; padding:.5em .6em; margin:0 0 1em;}
  59. .topWarning {background:#c00; color:#fff; padding:.5em .6em; margin:0 0 1em;}
  60. .topWarning a {color:#fff;}
  61. #jsDidntLoad {display:none;}
  62. </style>
  63. <body>
  64. <?php if ($symlinkOption): ?>
  65. <div class=topNote><strong>Note:</strong> It looks like you're running Minify in a user
  66. directory. You may need the following option in /min/config.php to have URIs
  67. correctly rewritten in CSS output:
  68. <br><textarea id=symlinkOpt rows=3 cols=80 readonly><?php echo htmlspecialchars($symlinkOption); ?></textarea>
  69. </div>
  70. <?php endif; ?>
  71. <p class=topWarning id=jsDidntLoad><strong>Uh Oh.</strong> Minify was unable to
  72. serve Javascript for this app. To troubleshoot this,
  73. <a href="http://code.google.com/p/minify/wiki/Debugging">enable FirePHP debugging</a>
  74. and request the <a id=builderScriptSrc href=#>Minify URL</a> directly. Hopefully the
  75. FirePHP console will report the cause of the error.
  76. </p>
  77. <?php if ($cachePathCode): ?>
  78. <p class=topNote><strong>Note:</strong> <code><?php echo
  79. htmlspecialchars($detectedTmp); ?></code> was discovered as a usable temp directory.<br>To
  80. slightly improve performance you can hardcode this in /min/config.php:
  81. <code><?php echo htmlspecialchars($cachePathCode); ?></code></p>
  82. <?php endIf; ?>
  83. <p id=minRewriteFailed class="hide"><strong>Note:</strong> Your webserver does not seem to
  84. support mod_rewrite (used in /min/.htaccess). Your Minify URIs will contain "?", which
  85. <a href="http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/"
  86. >may reduce the benefit of proxy cache servers</a>.</p>
  87. <h1>Minify URI Builder</h1>
  88. <noscript><p class="topNote">Javascript and a browser supported by jQuery 1.2.6 is required
  89. for this application.</p></noscript>
  90. <div id=app class=hide>
  91. <p>Create a list of Javascript or CSS files (or 1 is fine) you'd like to combine
  92. and click [Update].</p>
  93. <ol id=sources><li></li></ol>
  94. <div id=add><button>Add file +</button></div>
  95. <div id=bmUris></div>
  96. <p><button class="btn btn-primary" id=update class=hide>Update</button></p>
  97. <div id=results class=hide>
  98. <h2>Minify URI</h2>
  99. <p>Place this URI in your HTML to serve the files above combined, minified, compressed and
  100. with cache headers.</p>
  101. <table id=uriTable>
  102. <tr><th>URI</th><td><a id=uriA class=ext>/min</a> <small>(opens in new window)</small></td></tr>
  103. <tr><th>HTML</th><td><input id=uriHtml type=text size=100 readonly></td></tr>
  104. </table>
  105. <h2>How to serve these files as a group</h2>
  106. <p>For the best performance you can serve these files as a pre-defined group with a URI
  107. like: <code><span class=minRoot>/min/?</span>g=keyName</code></p>
  108. <p>To do this, add a line like this to /min/groupsConfig.php:</p>
  109. <pre><code>return array(
  110. <span style="color:#666">... your existing groups here ...</span>
  111. <input id=groupConfig size=100 type=text readonly>
  112. );</code></pre>
  113. <p><em>Make sure to replace <code>keyName</code> with a unique key for this group.</em></p>
  114. </div>
  115. <div id=getBm>
  116. <h3>Find URIs on a Page</h3>
  117. <p>You can use the bookmarklet below to fetch all CSS &amp; Javascript URIs from a page
  118. on your site. When you active it, this page will open in a new window with a list of
  119. available URIs to add.</p>
  120. <p><a id=bm>Create Minify URIs</a> <small>(right-click, add to bookmarks)</small></p>
  121. </div>
  122. <h3>Combining CSS files that contain <code>@import</code></h3>
  123. <p>If your CSS files contain <code>@import</code> declarations, Minify will not
  124. remove them. Therefore, you will want to remove those that point to files already
  125. in your list, and move any others to the top of the first file in your list
  126. (imports below any styles will be ignored by browsers as invalid).</p>
  127. <p>If you desire, you can use Minify URIs in imports and they will not be touched
  128. by Minify. E.g. <code>@import "<span class=minRoot>/min/?</span>g=css2";</code></p>
  129. <h3>Debug Mode</h3>
  130. <p>When /min/config.php has <code>$min_allowDebugFlag = <strong>true</strong>;</code>
  131. you can get debug output by appending <code>&amp;debug</code> to a Minify URL, or
  132. by sending the cookie <code>minDebug=&lt;match&gt;</code>, where <code>&lt;match&gt;</code>
  133. should be a string in the Minify URIs you'd like to debug. This bookmarklet will allow you to
  134. set this cookie.</p>
  135. <p><a id=bm2>Minify Debug</a> <small>(right-click, add to bookmarks)</small></p>
  136. </div><!-- #app -->
  137. <hr>
  138. <p>Need help? Check the <a href="http://code.google.com/p/minify/w/list?can=3">wiki</a>,
  139. or post to the <a class=ext href="http://groups.google.com/group/minify">discussion
  140. list</a>.</p>
  141. <p><small>Powered by Minify <?php echo Minify::VERSION; ?></small></p>
  142. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
  143. <script>window.jQuery || document.write('<script src="jquery-1.6.3.min.js"><\/script>')</script>
  144. <script>
  145. (function () {
  146. // workaround required to test when /min isn't child of web root
  147. var src = "../?f=" + location.pathname.replace(/\/[^\/]*$/, '/_index.js').substr(1);
  148. // load script immediately
  149. document.write('<\script src="' + src + '"><\/script>');
  150. $(function () {
  151. $('#builderScriptSrc')[0].href = src;
  152. // give Minify a few seconds to serve _index.js before showing scary red warning
  153. setTimeout(function () {
  154. if (! window.MUB) {
  155. // Minify didn't load
  156. $('#jsDidntLoad').css({display:'block'});
  157. }
  158. }, 3000);
  159. // detection of double output encoding
  160. var msg = '<\p class=topWarning><\strong>Warning:<\/strong> ';
  161. var url = 'ocCheck.php?' + (new Date()).getTime();
  162. $.get(url, function (ocStatus) {
  163. $.get(url + '&hello=1', function (ocHello) {
  164. if (ocHello != 'World!') {
  165. msg += 'It appears output is being automatically compressed, interfering '
  166. + ' with Minify\'s own compression. ';
  167. if (ocStatus == '1')
  168. msg += 'The option "zlib.output_compression" is enabled in your PHP configuration. '
  169. + 'Minify set this to "0", but it had no effect. This option must be disabled '
  170. + 'in php.ini or .htaccess.';
  171. else
  172. msg += 'The option "zlib.output_compression" is disabled in your PHP configuration '
  173. + 'so this behavior is likely due to a server option.';
  174. $(document.body).prepend(msg + '<\/p>');
  175. } else
  176. if (ocStatus == '1')
  177. $(document.body).prepend('<\p class=topNote><\strong>Note:</\strong> The option '
  178. + '"zlib.output_compression" is enabled in your PHP configuration, but has been '
  179. + 'successfully disabled via ini_set(). If you experience mangled output you '
  180. + 'may want to consider disabling this option in your PHP configuration.<\/p>'
  181. );
  182. });
  183. });
  184. });
  185. })();
  186. </script>
  187. </body>
  188. <?php
  189. $content = ob_get_clean();
  190. // setup Minify
  191. Minify::setCache(
  192. isset($min_cachePath) ? $min_cachePath : ''
  193. ,$min_cacheFileLocking
  194. );
  195. Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
  196. Minify::serve('Page', array(
  197. 'content' => $content
  198. ,'id' => __FILE__
  199. ,'lastModifiedTime' => max(
  200. // regenerate cache if any of these change
  201. filemtime(__FILE__)
  202. ,filemtime(dirname(__FILE__) . '/../config.php')
  203. ,filemtime(dirname(__FILE__) . '/../lib/Minify.php')
  204. )
  205. ,'minifyAll' => true
  206. ,'encodeOutput' => $encodeOutput
  207. ));