PluginProbe
Autoptimize / 1.9.3
Autoptimize v1.9.3
2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 All 107 releases
autoptimize / classes / autoptimizeConfig.php

autoptimizeConfig.php in Autoptimize 1.9.3, at classes/autoptimizeConfig.php

419 lines 19.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4 class autoptimizeConfig {
5 private $config = null;
6 static private $instance = null;
7
8 //Singleton: private construct
9 private function __construct() {
10 if( is_admin() ) {
11 //Add the admin page and settings
12 add_action('admin_menu',array($this,'addmenu'));
13 add_action('admin_init',array($this,'registersettings'));
14
15 //Set meta info
16 if(function_exists('plugin_row_meta')) {
17 //2.8+
18 add_filter('plugin_row_meta',array($this,'setmeta'),10,2);
19 } elseif(function_exists('post_class')) {
20 //2.7
21 $plugin = plugin_basename(WP_PLUGIN_DIR.'/autoptimize/autoptimize.php');
22 add_filter('plugin_action_links_'.$plugin,array($this,'setmeta'));
23 }
24
25 //Clean cache?
26 if(get_option('autoptimize_cache_clean')) {
27 autoptimizeCache::clearall();
28 update_option('autoptimize_cache_clean',0);
29 }
30 }
31 }
32
33 static public function instance() {
34 //Only one instance
35 if (self::$instance == null) {
36 self::$instance = new autoptimizeConfig();
37 }
38
39 return self::$instance;
40 }
41
42 public function show() {
43 ?>
44 <style>input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:100;}</style>
45
46 <div class="wrap">
47
48 <h2><?php _e('Autoptimize Settings','autoptimize'); ?></h2>
49
50 <div style="float:left;width:70%;">
51 <?php
52 if (get_option('autoptimize_show_adv','0')=='1') {
53 ?>
54 <a href="javascript:void(0);" id="ao_show_adv" class="button" style="display:none;"><?php _e("Show advanced settings","autoptimize") ?></a>
55 <a href="javascript:void(0);" id="ao_hide_adv" class="button"><?php _e("Hide advanced settings","autoptimize") ?></a>
56 <style>.ao_adv {display:table-row};</style>
57 <?php
58 } else {
59 ?>
60 <a href="javascript:void(0);" id="ao_show_adv" class="button"><?php _e("Show advanced settings","autoptimize") ?></a>
61 <a href="javascript:void(0);" id="ao_hide_adv" class="button" style="display:none;"><?php _e("Hide advanced settings","autoptimize") ?></a>
62 <?php
63 }
64 ?>
65
66 <form method="post" action="options.php">
67 <?php settings_fields('autoptimize'); ?>
68
69 <h3><?php _e('HTML Options','autoptimize'); ?></h3>
70 <table class="form-table">
71 <tr valign="top">
72 <th scope="row"><?php _e('Optimize HTML Code?','autoptimize'); ?></th>
73 <td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo get_option('autoptimize_html')?'checked="checked" ':''; ?>/></td>
74 </tr>
75 <tr class="html_sub" valign="top">
76 <th scope="row"><?php _e('Keep HTML comments?','autoptimize'); ?></th>
77 <td><label for="autoptimize_html_keepcomments"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo get_option('autoptimize_html_keepcomments')?'checked="checked" ':''; ?>/>
78 <?php _e('Enable this if you want HTML comments to remain in the page, needed for e.g. AdSense to function properly.','autoptimize'); ?></label></td>
79 </tr>
80 </table>
81
82 <h3><?php _e('JavaScript Options','autoptimize'); ?></h3>
83 <table class="form-table">
84 <tr valign="top">
85 <th scope="row"><?php _e('Optimize JavaScript Code?','autoptimize'); ?></th>
86 <td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo get_option('autoptimize_js')?'checked="checked" ':''; ?>/></td>
87 </tr>
88 <tr valign="top" class="hidden js_sub ao_adv">
89 <th scope="row"><?php _e('Force JavaScript in &lt;head&gt;?','autoptimize'); ?></th>
90 <td><label for="autoptimize_js_forcehead"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo get_option('autoptimize_js_forcehead')?'checked="checked" ':''; ?>/>
91 <?php _e('For performance reasons it is better to include JavaScript at the bottom of HTML, but this sometimes breaks things. Especially useful for jQuery-based themes.','autoptimize'); ?></label></td>
92 </tr>
93 <tr valign="top" class="hidden js_sub ao_adv">
94 <th scope="row"><?php _e('Look for scripts only in &lt;head&gt;?','autoptimize'); _e(' <i>(deprecated)</i>','autoptimize');?></th>
95 <td><label for="autoptimize_js_justhead"><input type="checkbox" name="autoptimize_js_justhead" <?php echo get_option('autoptimize_js_justhead')?'checked="checked" ':''; ?>/>
96 <?php _e('Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.','autoptimize'); ?></label></td>
97 </tr>
98 <tr valign="top" class="hidden js_sub ao_adv">
99 <th scope="row"><?php _e('Exclude scripts from Autoptimize:','autoptimize'); ?></th>
100 <td><label for="autoptimize_js_exclude"><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo get_option('autoptimize_js_exclude',"s_sid,smowtion_size,sc_project,WAU_,wau_add,comment-form-quicktags,edToolbar,ch_client,seal.js"); ?>"/><br />
101 <?php _e('A comma-seperated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated and minimized by Autoptimize.','autoptimize'); ?></label></td>
102 </tr>
103 <tr valign="top" class="hidden js_sub ao_adv">
104 <th scope="row"><?php _e('Add try-catch wrapping?','autoptimize'); ?></th>
105 <td><label for="autoptimize_js_trycatch"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo get_option('autoptimize_js_trycatch')?'checked="checked" ':''; ?>/>
106 <?php _e('If your scripts break because of an script error, you might want to try this.','autoptimize'); ?></label></td>
107 </tr>
108 </table>
109
110 <h3><?php _e('CSS Options','autoptimize'); ?></h3>
111 <table class="form-table">
112 <tr valign="top">
113 <th scope="row"><?php _e('Optimize CSS Code?','autoptimize'); ?></th>
114 <td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo get_option('autoptimize_css')?'checked="checked" ':''; ?>/></td>
115 </tr>
116 <tr class="css_sub" valign="top">
117 <th scope="row"><?php _e('Generate data: URIs for images?','autoptimize'); ?></th>
118 <td><label for="autoptimize_css_datauris"><input type="checkbox" name="autoptimize_css_datauris" <?php echo get_option('autoptimize_css_datauris')?'checked="checked" ':''; ?>/>
119 <?php _e('Enable this to include small background-images in the CSS itself instead of as seperate downloads.','autoptimize'); ?></label></td>
120 </tr>
121 <tr valign="top" class="hidden css_sub ao_adv">
122 <th scope="row"><?php _e('Look for styles only in &lt;head&gt;?','autoptimize'); _e(' <i>(deprecated)</i>','autoptimize'); ?></th>
123 <td><label for="autoptimize_css_justhead"><input type="checkbox" name="autoptimize_css_justhead" <?php echo get_option('autoptimize_css_justhead')?'checked="checked" ':''; ?>/>
124 <?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.','autoptimize'); ?></label></td>
125 </tr>
126 <tr valign="top" class="hidden css_sub ao_adv">
127 <th scope="row"><?php _e('Inline and Defer CSS?','autoptimize'); ?></th>
128 <td><label for="autoptimize_css_defer"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo get_option('autoptimize_css_defer')?'checked="checked" ':''; ?>/>
129 <?php _e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="http://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> before activating this option!','autoptimize'); ?></label></td>
130 </tr>
131 <tr valign="top" class="hidden css_sub ao_adv" id="autoptimize_css_defer_inline">
132 <th scope="row"></th>
133 <td><label for="autoptimize_css_defer_inline"><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e('Paste the above the fold CSS here.','autoptimize'); ?>" name="autoptimize_css_defer_inline"><?php echo get_option('autoptimize_css_defer_inline'); ?></textarea></label></td>
134 </tr>
135 <tr valign="top" class="hidden ao_adv css_sub">
136 <th scope="row"><?php _e('Inline all CSS?','autoptimize'); ?></th>
137 <td><label for="autoptimize_css_inline"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo get_option('autoptimize_css_inline')?'checked="checked" ':''; ?>/>
138 <?php _e('Inlining all CSS can improve performance for sites with a low pageviews/ visitor-rate, but may slow down performance otherwise.','autoptimize'); ?></label></td>
139 </tr>
140 <tr valign="top" class="hidden ao_adv css_sub">
141 <th scope="row"><?php _e('Exclude CSS from Autoptimize:','autoptimize'); ?></th>
142 <td><label for="autoptimize_css_exclude"><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo get_option('autoptimize_css_exclude','admin-bar.min.css, dashicons.min.css'); ?>"/><br />
143 <?php _e('A comma-seperated list of CSS you want to exclude from being optimized.','autoptimize'); ?></label></td>
144 </tr>
145 </table>
146
147 <h3><?php _e('CDN Options','autoptimize'); ?></h3>
148 <table class="form-table">
149 <tr valign="top">
150 <th scope="row"><?php _e('CDN Base URL','autoptimize'); ?></th>
151 <td><label for="autoptimize_url"><input id="cdn_url" type="url" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*\/?$" style="width:100%" value="<?php $it = get_option('autoptimize_cdn_url','');echo htmlentities($it); ?>" /><br />
152 <?php _e('Enter your CDN blog root directory URL if you want to enable CDN for images referenced in the CSS.','autoptimize'); ?></label></td>
153 </tr>
154 </table>
155
156 <h3 class="hidden ao_adv"><?php _e('Cache Info','autoptimize'); ?></h3>
157 <table class="form-table" >
158 <tr valign="top" class="hidden ao_adv">
159 <th scope="row"><?php _e('Cache folder','autoptimize'); ?></th>
160 <td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td>
161 </tr>
162 <tr valign="top" class="hidden ao_adv">
163 <th scope="row"><?php _e('Can we write?','autoptimize'); ?></th>
164 <td><?php echo (autoptimizeCache::cacheavail() ? __('Yes','autoptimize') : __('No','autoptimize')); ?></td>
165 </tr>
166 <tr valign="top" class="hidden ao_adv">
167 <th scope="row"><?php _e('Cached styles and scripts','autoptimize'); ?></th>
168 <td><?php echo autoptimizeCache::stats(); ?></td>
169 </tr>
170 <tr valign="top" class="hidden ao_adv">
171 <th scope="row"><?php _e('Save aggregated script/css as static files?','autoptimize'); ?></th>
172 <td><label for="autoptimize_cache_nogzip"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo get_option('autoptimize_cache_nogzip','1')?'checked="checked" ':''; ?>/>
173 <?php _e('By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.','autoptimize'); ?></label></td>
174 </tr>
175 </table>
176 <input type="hidden" id="autoptimize_show_adv" name="autoptimize_show_adv" value="<?php echo get_option('autoptimize_show_adv','0'); ?>">
177
178 <p class="submit">
179 <input type="submit" class="button-secondary" value="<?php _e('Save Changes','autoptimize') ?>" />
180 <input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache','autoptimize') ?>" />
181 </p>
182
183 </form>
184 </div>
185 <div style="float:right;width:30%" id="autoptimize_admin_feed">
186 <div style="margin:0px 15px 15px 15px;font-size:larger;"><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=futtta"><?php _e("Happy with Autoptimize? Try my other plugins!"); ?></a></div>
187 <div style="margin-left:10px;margin-top:-5px;">
188 <h3>
189 <?php _e("futtta about","autoptimize") ?>
190 <select id="feed_dropdown" >
191 <option value="1"><?php _e("Autoptimize","autoptimize") ?></option>
192 <option value="2"><?php _e("WordPress","autoptimize") ?></option>
193 <option value="3"><?php _e("Web Technology","autoptimize") ?></option>
194 </select>
195 </h3>
196 <div id="futtta_feed"></div>
197 </div>
198 <div style="float:right;margin:50px 15px;"><a href="http://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo content_url(); ?>/plugins/autoptimize/classes/external/do_not_donate_smallest.png" title="<?php _e("Do not donate for this plugin!"); ?>"></a></div>
199 </div>
200
201 <script type="text/javascript">
202 var feed = new Array;
203 feed[1]="http://feeds.feedburner.com/futtta_autoptimize";
204 feed[2]="http://feeds.feedburner.com/futtta_wordpress";
205 feed[3]="http://feeds.feedburner.com/futtta_webtech";
206 cookiename="autoptimize_feed";
207
208 jQuery(document).ready(function() {
209 check_ini_state();
210 jQuery( "#ao_show_adv" ).click(function() {
211 jQuery( "#ao_show_adv" ).hide();
212 jQuery( "#ao_hide_adv" ).show();
213 jQuery( ".ao_adv" ).show("slow");
214 if (jQuery("#autoptimize_css").attr('checked')) {
215 jQuery(".css_sub:visible").fadeTo("fast",1);
216 if (!jQuery("#autoptimize_css_defer").attr('checked')) {
217 jQuery("#autoptimize_css_defer_inline").hide();
218 }
219 }
220 if (jQuery("#autoptimize_js").attr('checked')) {
221 jQuery(".js_sub:visible").fadeTo("fast",1);
222 }
223 check_ini_state()
224 jQuery( "input#autoptimize_show_adv" ).val("1");
225 });
226
227 jQuery( "#ao_hide_adv" ).click(function() {
228 jQuery( "#ao_hide_adv" ).hide();
229 jQuery( "#ao_show_adv" ).show();
230 jQuery( ".ao_adv" ).hide("slow");
231 if (!jQuery("#autoptimize_css").attr('checked')) {
232 jQuery(".css_sub:visible").fadeTo("fast",.33);
233 }
234 if (!jQuery("#autoptimize_js").attr('checked')) {
235 jQuery(".js_sub:visible").fadeTo("fast",.33);
236 }
237 check_ini_state()
238 jQuery( "input#autoptimize_show_adv" ).val("0");
239 });
240
241 jQuery( "#autoptimize_html" ).change(function() {
242 if (this.checked) {
243 jQuery(".html_sub:visible").fadeTo("fast",1);
244 } else {
245 jQuery(".html_sub:visible").fadeTo("fast",.33);
246 }
247 });
248
249 jQuery( "#autoptimize_js" ).change(function() {
250 if (this.checked) {
251 jQuery(".js_sub:visible").fadeTo("fast",1);
252 } else {
253 jQuery(".js_sub:visible").fadeTo("fast",.33);
254 }
255 });
256
257 jQuery( "#autoptimize_css" ).change(function() {
258 if (this.checked) {
259 jQuery(".css_sub:visible").fadeTo("fast",1);
260 } else {
261 jQuery(".css_sub:visible").fadeTo("fast",.33);
262 }
263 });
264
265 jQuery( "#autoptimize_css_inline" ).change(function() {
266 if (this.checked) {
267 jQuery("#autoptimize_css_defer").prop("checked",false);
268 jQuery("#autoptimize_css_defer_inline").hide("slow");
269 }
270 });
271
272 jQuery( "#autoptimize_css_defer" ).change(function() {
273 if (this.checked) {
274 jQuery("#autoptimize_css_inline").prop("checked",false);
275 jQuery("#autoptimize_css_defer_inline").show("slow");
276 } else {
277 jQuery("#autoptimize_css_defer_inline").hide("slow");
278 }
279 });
280
281 jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });
282 feedid=jQuery.cookie(cookiename);
283 if(typeof(feedid) !== "string") feedid=1;
284 show_feed(feedid);
285 })
286
287 function check_ini_state() {
288 if (!jQuery("#autoptimize_css_defer").attr('checked')) {
289 jQuery("#autoptimize_css_defer_inline").hide();
290 }
291 if (!jQuery("#autoptimize_html").attr('checked')) {
292 jQuery(".html_sub:visible").fadeTo('fast',.33);
293 }
294 if (!jQuery("#autoptimize_css").attr('checked')) {
295 jQuery(".css_sub:visible").fadeTo('fast',.33);
296 }
297 if (!jQuery("#autoptimize_js").attr('checked')) {
298 jQuery(".js_sub:visible").fadeTo('fast',.33);
299 }
300 }
301
302 function show_feed(id) {
303 jQuery('#futtta_feed').rssfeed(feed[id], {
304 <?php if ( is_ssl() ) echo "ssl: true,"; ?>
305 limit: 4,
306 date: true,
307 header: false
308 });
309 jQuery("#feed_dropdown").val(id);
310 jQuery.cookie(cookiename,id,{ expires: 365 });
311 }
312 </script>
313 </div>
314
315 <?php
316 }
317
318 public function addmenu() {
319 $hook=add_options_page(__('Autoptimize Options','autoptimize'),'Autoptimize','manage_options','autoptimize',array($this,'show'));
320 add_action( 'admin_print_scripts-'.$hook,array($this,'autoptimize_admin_scripts'));
321 add_action( 'admin_print_styles-'.$hook,array($this,'autoptimize_admin_styles'));
322 }
323
324 public function autoptimize_admin_scripts() {
325 wp_enqueue_script('jqzrssfeed', plugins_url('/external/js/jquery.zrssfeed.min.js', __FILE__), array('jquery'),null,true);
326 wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'),null,true);
327 }
328
329 public function autoptimize_admin_styles() {
330 wp_enqueue_style('zrssfeed', plugins_url('/external/js/jquery.zrssfeed.css', __FILE__));
331 }
332
333
334 public function registersettings() {
335 register_setting('autoptimize','autoptimize_html');
336 register_setting('autoptimize','autoptimize_html_keepcomments');
337 register_setting('autoptimize','autoptimize_js');
338 register_setting('autoptimize','autoptimize_js_exclude');
339 register_setting('autoptimize','autoptimize_js_trycatch');
340 register_setting('autoptimize','autoptimize_js_justhead');
341 register_setting('autoptimize','autoptimize_js_forcehead');
342 register_setting('autoptimize','autoptimize_css');
343 register_setting('autoptimize','autoptimize_css_exclude');
344 register_setting('autoptimize','autoptimize_css_justhead');
345 register_setting('autoptimize','autoptimize_css_datauris');
346 register_setting('autoptimize','autoptimize_css_defer');
347 register_setting('autoptimize','autoptimize_css_defer_inline');
348 register_setting('autoptimize','autoptimize_css_inline');
349 register_setting('autoptimize','autoptimize_cdn_url');
350 register_setting('autoptimize','autoptimize_cache_clean');
351 register_setting('autoptimize','autoptimize_cache_nogzip');
352 register_setting('autoptimize','autoptimize_show_adv');
353 }
354
355 public function setmeta($links,$file=null) {
356 //Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/
357 //Do it only once - saves time
358 static $plugin;
359 if(empty($plugin))
360 $plugin = plugin_basename(WP_PLUGIN_DIR.'/autoptimize/autoptimize.php');
361
362 if($file===null) {
363 //2.7
364 $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'));
365 array_unshift($links,$settings_link);
366 } else {
367 //2.8
368 //If it's us, add the link
369 if($file === $plugin) {
370 $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>',__('Settings')));
371 $links = array_merge($links,$newlink);
372 }
373 }
374
375 return $links;
376 }
377
378 public function get($key) {
379 if(!is_array($this->config)) {
380 //Default config
381 $config = array('autoptimize_html' => 0,
382 'autoptimize_html_keepcomments' => 0,
383 'autoptimize_js' => 0,
384 'autoptimize_js_exclude' => "s_sid, smowtion_size, sc_project, WAU_, wau_add, comment-form-quicktags, edToolbar, ch_client, seal.js",
385 'autoptimize_js_trycatch' => 0,
386 'autoptimize_js_justhead' => 0,
387 'autoptimize_js_forcehead' => 0,
388 'autoptimize_css' => 0,
389 'autoptimize_css_exclude' => "admin-bar.min.css, dashicons.min.css",
390 'autoptimize_css_justhead' => 0,
391 'autoptimize_css_defer' => 0,
392 'autoptimize_css_defer_inline' => "",
393 'autoptimize_css_inline' => 0,
394 'autoptimize_css_datauris' => 0,
395 'autoptimize_cdn_url' => "",
396 'autoptimize_cache_nogzip' => 1,
397 'autoptimize_show_adv' => 0
398 );
399
400 //Override with user settings
401 foreach(array_keys($config) as $name) {
402 $conf = get_option($name);
403 if($conf!==false) {
404 //It was set before!
405 $config[$name] = $conf;
406 }
407 }
408
409 //Save for next question
410 $this->config = $config;
411 }
412
413 if(isset($this->config[$key]))
414 return $this->config[$key];
415
416 return false;
417 }
418 }
419