initial commit
[namibia] / public / min / builder / index.php
1 <?php 
2
3 if (phpversion() < 5) {
4     exit('Minify requires PHP5 or greater.');
5 }
6
7 // check for auto-encoding
8 $encodeOutput = (function_exists('gzdeflate')
9                  && !ini_get('zlib.output_compression'));
10
11 // recommend $min_symlinks setting for Apache UserDir
12 $symlinkOption = '';
13 if (0 === strpos($_SERVER["SERVER_SOFTWARE"], 'Apache/')
14     && preg_match('@^/\\~(\\w+)/@', $_SERVER['REQUEST_URI'], $m)
15 ) {
16     $userDir = DIRECTORY_SEPARATOR . $m[1] . DIRECTORY_SEPARATOR;
17     if (false !== strpos(__FILE__, $userDir)) {
18         $sm = array();
19         $sm["//~{$m[1]}"] = dirname(dirname(__FILE__));
20         $array = str_replace('array (', 'array(', var_export($sm, 1));
21         $symlinkOption = "\$min_symlinks = $array;";
22     }
23 }
24
25 require dirname(__FILE__) . '/../config.php';
26
27 require "$min_libPath/Minify/Loader.php";
28 Minify_Loader::register();
29
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');
33 }
34
35 if (isset($min_builderPassword)
36         && is_string($min_builderPassword)
37         && $min_builderPassword !== '') {
38     DooDigestAuth::http_auth('Minify Builder', array('admin' => $min_builderPassword));
39 }
40
41 $cachePathCode = '';
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) . ';';
45 }
46
47 ob_start();
48 ?>
49 <!DOCTYPE html>
50 <title>Minify URI Builder</title>
51 <meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
52 <style>
53 body {margin:1em 60px;}
54 h1, h2, h3 {margin-left:-25px; position:relative;}
55 h1 {margin-top:0;}
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}
60 .hide {display:none}
61 #uriTable {border-collapse:collapse;}
62 #uriTable td, #uriTable th {padding-top:10px;}
63 #uriTable th {padding-right:10px;}
64 #groupConfig {font-family:monospace;}
65 b {color:#c00}
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;}
70 </style>
71 <body>
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>
77 </div>
78 <?php endif; ?>
79
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.
85 </p>
86
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>
92 <?php endIf; ?>
93
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>
98
99 <h1>Minify URI Builder</h1>
100
101 <noscript><p class="topNote">Javascript and a browser supported by jQuery 1.2.6 is required
102 for this application.</p></noscript>
103
104 <div id=app class=hide>
105
106 <p>Create a list of Javascript or CSS files (or 1 is fine) you'd like to combine
107 and click [Update].</p>
108
109 <ol id=sources><li></li></ol>
110 <div id=add><button>Add file +</button></div>
111
112 <div id=bmUris></div>
113
114 <p><button id=update class=hide>Update</button></p>
115
116 <div id=results class=hide>
117
118 <h2>Minify URI</h2>
119 <p>Place this URI in your HTML to serve the files above combined, minified, compressed and
120 with cache headers.</p>
121 <table id=uriTable>
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>
124 </table>
125
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>
130
131 <pre><code>return array(
132     <span style="color:#666">... your existing groups here ...</span>
133 <input id=groupConfig size=100 type=text readonly>
134 );</code></pre>
135
136 <p><em>Make sure to replace <code>keyName</code> with a unique key for this group.</em></p>
137 </div>
138
139 <div id=getBm>
140 <h3>Find URIs on a Page</h3>
141 <p>You can use the bookmarklet below to fetch all CSS &amp; 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>
144
145 <p><a id=bm>Create Minify URIs</a> <small>(right-click, add to bookmarks)</small></p>
146 </div>
147
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>
155
156 <h3>Debug Mode</h3>
157 <p>When /min/config.php has <code>$min_allowDebugFlag = <strong>true</strong>;</code>
158  you can get debug output by appending <code>&amp;debug</code> to a Minify URL, or
159  by sending the cookie <code>minDebug=&lt;match&gt;</code>, where <code>&lt;match&gt;</code>
160  should be a string in the Minify URIs you'd like to debug. This bookmarklet will allow you to
161  set this cookie.</p>
162 <p><a id=bm2>Minify Debug</a> <small>(right-click, add to bookmarks)</small></p>
163
164 </div><!-- #app -->
165
166 <hr>
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
169  list</a>.</p>
170  <p><small>Powered by Minify <?php echo Minify::VERSION; ?></small></p>
171
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>
174 <script>
175 (function () {
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>');
180     $(function () {
181         $('#builderScriptSrc')[0].href = src;
182         // give Minify a few seconds to serve _index.js before showing scary red warning
183         setTimeout(function () {
184             if (! window.MUB) {
185                 // Minify didn't load
186                 $('#jsDidntLoad').css({display:'block'});
187             }
188         }, 3000);
189
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. ';
198                     if (ocStatus == '1')
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.';
202                     else
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>');
206                 } else
207                     if (ocStatus == '1')
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>'
212                         );
213             });
214         });
215     });
216 })();
217 </script>
218 </body>
219 <?php
220 $content = ob_get_clean();
221
222 // setup Minify
223 Minify::setCache(
224     isset($min_cachePath) ? $min_cachePath : ''
225     ,$min_cacheFileLocking
226 );
227 Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
228
229 Minify::serve('Page', array(
230     'content' => $content
231     ,'id' => __FILE__
232     ,'lastModifiedTime' => max(
233         // regenerate cache if any of these change
234         filemtime(__FILE__)
235         ,filemtime(dirname(__FILE__) . '/../config.php')
236         ,filemtime(dirname(__FILE__) . '/../lib/Minify.php')
237     )
238     ,'minifyAll' => true
239     ,'encodeOutput' => $encodeOutput
240 ));