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