PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.3.2
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.3.2
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / mrclay / minify / builder / index.php

index.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.3.2, at vendor/mrclay/minify/builder/index.php

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