PluginProbe
Autoptimize / 1.6.5
Autoptimize v1.6.5
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.6.5, at classes/autoptimizeConfig.php

352 lines 15.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class autoptimizeConfig
4 {
5 private $config = null;
6 static private $instance = null;
7
8 //Singleton: private construct
9 private function __construct()
10 {
11 if( is_admin() )
12 {
13 //Add the admin page and settings
14 add_action('admin_menu',array($this,'addmenu'));
15 add_action('admin_init',array($this,'registersettings'));
16
17 //Set meta info
18 if(function_exists('plugin_row_meta'))
19 {
20 //2.8+
21 add_filter('plugin_row_meta',array($this,'setmeta'),10,2);
22 } elseif(function_exists('post_class')) {
23 //2.7
24 $plugin = plugin_basename(WP_PLUGIN_DIR.'/autoptimize/autoptimize.php');
25 add_filter('plugin_action_links_'.$plugin,array($this,'setmeta'));
26 }
27
28 //Clean cache?
29 if(get_option('autoptimize_cache_clean'))
30 {
31 autoptimizeCache::clearall();
32 update_option('autoptimize_cache_clean',0);
33 }
34 }
35 }
36
37 static public function instance()
38 {
39 //Only one instance
40 if (self::$instance == null)
41 {
42 self::$instance = new autoptimizeConfig();
43 }
44
45 return self::$instance;
46 }
47
48 public function show()
49 {
50 ?>
51 <div class="wrap">
52 <h2><?php _e('Autoptimize Settings','autoptimize'); ?></h2>
53
54 <div style="float:left;width:70%;">
55 <form method="post" action="options.php">
56 <?php settings_fields('autoptimize'); ?>
57
58 <h3><?php _e('HTML Options','autoptimize'); ?></h3>
59 <table class="form-table">
60 <tr valign="top">
61 <th scope="row"><?php _e('Optimize HTML Code?','autoptimize'); ?></th>
62 <td><input type="checkbox" name="autoptimize_html" <?php echo get_option('autoptimize_html')?'checked="checked" ':''; ?>/></td>
63 </tr>
64 <tr valign="top">
65 <th scope="row"><?php _e('Keep HTML comments?','autoptimize'); ?></th>
66 <td><label for="autoptimize_html_keepcomments"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo get_option('autoptimize_html_keepcomments')?'checked="checked" ':''; ?>/>
67 <?php _e('Disabled by default. Enable this if you want HTML comments to remain in the page.','autoptimize'); ?></label></td>
68 </tr>
69 </table>
70
71 <h3><?php _e('JavaScript Options','autoptimize'); ?></h3>
72 <table class="form-table">
73 <tr valign="top">
74 <th scope="row"><?php _e('Optimize JavaScript Code?','autoptimize'); ?></th>
75 <td><input type="checkbox" name="autoptimize_js" <?php echo get_option('autoptimize_js')?'checked="checked" ':''; ?>/></td>
76 </tr>
77 <tr valign="top">
78 <th scope="row"><?php _e('Exclude scripts from autoptimize:','autoptimize'); ?></th>
79 <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"); ?>"/><br />
80 <?php _e('A comma-seperated list of scripts you want to exclude from being Autoptimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated and minimized by Autoptimize.','autoptimize'); ?></label></td>
81 </tr>
82 <tr valign="top">
83 <th scope="row"><?php _e('Look for scripts only in &lt;head&gt;?','autoptimize'); ?></th>
84 <td><label for="autoptimize_js_justhead"><input type="checkbox" name="autoptimize_js_justhead" <?php echo get_option('autoptimize_js_justhead')?'checked="checked" ':''; ?>/>
85 <?php _e('Disabled by default. If the cache gets big, you might want to enable this.','autoptimize'); ?></label></td>
86 </tr>
87 <tr valign="top">
88 <th scope="row"><?php _e('Force JavaScript in &lt;head&gt;?','autoptimize'); ?></th>
89 <td><label for="autoptimize_js_forcehead"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo get_option('autoptimize_js_forcehead')?'checked="checked" ':''; ?>/>
90 <?php _e('Disabled by default. For performance reasons JavaScript is best put at the end of the HTML, but in some circumstances this breaks things. You can in that case check this option to add JavaScript to the &lt;head&gt; section.','autoptimize'); ?></label></td>
91 </tr>
92 <tr valign="top">
93 <th scope="row"><?php _e('Add try-catch wrapping?','autoptimize'); ?></th>
94 <td><label for="autoptimize_js_trycatch"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo get_option('autoptimize_js_trycatch')?'checked="checked" ':''; ?>/>
95 <?php _e('Disabled by default. If your scripts break because of an script error, you might want to try this.','autoptimize'); ?></label></td>
96 </tr>
97 <tr valign="top">
98 <th scope="row"><?php _e('Use YUI compression?','autoptimize'); ?></th>
99 <td><label for="autoptimize_js_yui"><input type="checkbox" name="autoptimize_js_yui" <?php echo get_option('autoptimize_js_yui')?'checked="checked" ':''; ?>/>
100 <?php _e('<b>Deprecated!</b> Disabled by default. Read [autoptimize]/yui/README.txt for more information.','autoptimize'); ?></label></td>
101 </tr>
102 </table>
103
104 <h3><?php _e('CSS Options','autoptimize'); ?></h3>
105 <table class="form-table">
106 <tr valign="top">
107 <th scope="row"><?php _e('Optimize CSS Code?','autoptimize'); ?></th>
108 <td><input type="checkbox" name="autoptimize_css" <?php echo get_option('autoptimize_css')?'checked="checked" ':''; ?>/></td>
109 </tr>
110 <tr valign="top">
111 <th scope="row"><?php _e('Look for styles on just &lt;head&gt;?','autoptimize'); ?></th>
112 <td><label for="autoptimize_css_justhead"><input type="checkbox" name="autoptimize_css_justhead" <?php echo get_option('autoptimize_css_justhead')?'checked="checked" ':''; ?>/>
113 <?php _e('Disabled by default. If the cache gets big, you might want to enable this.','autoptimize'); ?></label></td>
114 </tr>
115 <tr valign="top">
116 <th scope="row"><?php _e('Generate data: URIs for images?','autoptimize'); ?></th>
117 <td><label for="autoptimize_css_datauris"><input type="checkbox" name="autoptimize_css_datauris" <?php echo get_option('autoptimize_css_datauris')?'checked="checked" ':''; ?>/>
118 <?php _e('Disabled by default. Enable this to include images on the CSS itself.','autoptimize'); ?></label></td>
119 </tr>
120 <tr valign="top">
121 <th scope="row"><?php _e('Use YUI compression?','autoptimize'); ?></th>
122 <td><label for="autoptimize_css_yui"><input type="checkbox" name="autoptimize_css_yui" <?php echo get_option('autoptimize_css_yui')?'checked="checked" ':''; ?>/>
123 <?php _e('<b>Deprecated!</b> Disabled by default. Read [autoptimize]/yui/README.txt for more information.','autoptimize'); ?></label></td>
124 </tr>
125 </table>
126
127 <h3><?php _e('CDN Options','autoptimize'); ?> (Deprecated!)</h3>
128 <table class="form-table">
129 <tr valign="top">
130 <th scope="row"><?php _e('Rewrite JavaScript URLs?','autoptimize'); ?></th>
131 <td><label for="autoptimize_cdn_js"><input type="checkbox" name="autoptimize_cdn_js" <?php echo get_option('autoptimize_cdn_js')?'checked="checked" ':''; ?>/>
132 <?php _e('Disabled by default. Do not enable this unless you know what you are doing.','autoptimize'); ?></label></td>
133 </tr>
134 <tr valign="top">
135 <th scope="row"><?php _e('JavaScript Base URL','autoptimize'); ?></th>
136 <td><label for="autoptimize_cdn_js_url"><input type="text" name="autoptimize_cdn_js_url" value="<?php $it = get_option('autoptimize_cdn_js_url');echo htmlentities($it?$it:site_url()); ?>" />
137 <?php _e('This is the new base URL that will be used when rewriting. It should point to the blog root directory.','autoptimize'); ?></label></td>
138 </tr>
139 <tr valign="top">
140 <th scope="row"><?php _e('Rewrite CSS URLs?','autoptimize'); ?></th>
141 <td><label for="autoptimize_cdn_css"><input type="checkbox" name="autoptimize_cdn_css" <?php echo get_option('autoptimize_cdn_css')?'checked="checked" ':''; ?>/>
142 <?php _e('Disabled by default. Do not enable this unless you know what you are doing.','autoptimize'); ?></label></td>
143 </tr>
144 <tr valign="top">
145 <th scope="row"><?php _e('CSS Base URL','autoptimize'); ?></th>
146 <td><label for="autoptimize_cdn_css_url"><input type="text" name="autoptimize_cdn_css_url" value="<?php $it = get_option('autoptimize_cdn_css_url');echo htmlentities($it?$it:site_url()); ?>" />
147 <?php _e('This is the new base URL that will be used when rewriting. It should point to the blog root directory.','autoptimize'); ?></label></td>
148 </tr>
149 <tr valign="top">
150 <th scope="row"><?php _e('Rewrite Image URLs?','autoptimize'); ?></th>
151 <td><label for="autoptimize_cdn_img"><input type="checkbox" name="autoptimize_cdn_img" <?php echo get_option('autoptimize_cdn_img')?'checked="checked" ':''; ?>/>
152 <?php _e('Disabled by default. Do not enable this unless you know what you are doing.','autoptimize'); ?></label></td>
153 </tr>
154 <tr valign="top">
155 <th scope="row"><?php _e('Image Base URL','autoptimize'); ?></th>
156 <td><label for="autoptimize_cdn_img_url"><input type="text" name="autoptimize_cdn_img_url" value="<?php $it = get_option('autoptimize_cdn_img_url');echo htmlentities($it?$it:site_url()); ?>" />
157 <?php _e('This is the new base URL that will be used when rewriting. It should point to the blog root directory.','autoptimize'); ?></label></td>
158 </tr>
159 </table>
160
161 <h3><?php _e('Cache Info','autoptimize'); ?></h3>
162 <table class="form-table">
163 <tr valign="top">
164 <th scope="row"><?php _e('Cache folder','autoptimize'); ?></th>
165 <td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td>
166 </tr>
167 <tr valign="top">
168 <th scope="row"><?php _e('Can we write?','autoptimize'); ?></th>
169 <td><?php echo (autoptimizeCache::cacheavail() ? __('Yes','autoptimize') : __('No','autoptimize')); ?></td>
170 </tr>
171 <tr valign="top">
172 <th scope="row"><?php _e('Cached styles and scripts','autoptimize'); ?></th>
173 <td><?php echo autoptimizeCache::stats(); ?></td>
174 </tr>
175 <tr valign="top">
176 <th scope="row"><?php _e('Do not compress cache files','autoptimize'); ?></th>
177 <td><label for="autoptimize_cache_nogzip"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo get_option('autoptimize_cache_nogzip')?'checked="checked" ':''; ?>/>
178 <?php _e('Disabled by default. Enable this if you want to compress the served files using your webserver.','autoptimize'); ?></label></td>
179 </tr>
180 </table>
181
182 </table>
183
184 <p class="submit">
185 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
186 <input type="submit" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache') ?>" />
187 </p>
188
189 </form>
190 </div>
191 <div style="float:right;width:30%" id="autoptimize_admin_feed">
192 <div style="margin-left:10px;margin-top:-5px;">
193 <h3>
194 <?php _e("futtta about","autoptimize") ?>
195 <select id="feed_dropdown" >
196 <option value="1"><?php _e("Autoptimize","autoptimize") ?></option>
197 <option value="2"><?php _e("WordPress","autoptimize") ?></option>
198 <option value="3"><?php _e("Web Technology","autoptimize") ?></option>
199 </select>
200 </h3>
201 <div id="futtta_feed"></div>
202 </div>
203 </div>
204
205 <script type="text/javascript">
206 var feed = new Array;
207 feed[1]="http://feeds.feedburner.com/futtta_autoptimize";
208 feed[2]="http://feeds.feedburner.com/futtta_wordpress";
209 feed[3]="http://feeds.feedburner.com/futtta_webtech";
210 cookiename="autoptimize_feed";
211
212 jQuery(document).ready(function() {
213 jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });
214
215 feedid=jQuery.cookie(cookiename);
216 if(typeof(feedid) !== "string") feedid=1;
217
218 show_feed(feedid);
219 })
220
221 function show_feed(id) {
222 jQuery('#futtta_feed').rssfeed(feed[id], {
223 <?php if ( is_ssl() ) echo "ssl: true,"; ?>
224 limit: 4,
225 date: true,
226 header: false
227 });
228 jQuery("#feed_dropdown").val(id);
229 jQuery.cookie(cookiename,id,{ expires: 365 });
230 }
231 </script>
232
233 </div>
234 <?php
235 }
236
237 public function addmenu()
238 {
239 $hook=add_options_page(__('Autoptimize Options','autoptimize'),'Autoptimize','manage_options','autoptimize',array($this,'show'));
240 add_action( 'admin_print_scripts-'.$hook,array($this,'autoptimize_admin_scripts'));
241 add_action( 'admin_print_styles-'.$hook,array($this,'autoptimize_admin_styles'));
242 }
243
244 public function autoptimize_admin_scripts() {
245 wp_enqueue_script('jqzrssfeed', plugins_url('/external/jquery.zrssfeed.min.js', __FILE__), array('jquery'),null,true);
246 wp_enqueue_script('jqcookie', plugins_url('/external/jquery.cookie.min.js', __FILE__), array('jquery'),null,true);
247 }
248
249 public function autoptimize_admin_styles() {
250 wp_enqueue_style('zrssfeed', plugins_url('/external/jquery.zrssfeed.css', __FILE__));
251 }
252
253
254 public function registersettings()
255 {
256 register_setting('autoptimize','autoptimize_html');
257 register_setting('autoptimize','autoptimize_html_keepcomments');
258 register_setting('autoptimize','autoptimize_js');
259 register_setting('autoptimize','autoptimize_js_exclude');
260 register_setting('autoptimize','autoptimize_js_trycatch');
261 register_setting('autoptimize','autoptimize_js_justhead');
262 register_setting('autoptimize','autoptimize_js_forcehead');
263 register_setting('autoptimize','autoptimize_js_yui');
264 register_setting('autoptimize','autoptimize_css');
265 register_setting('autoptimize','autoptimize_css_justhead');
266 register_setting('autoptimize','autoptimize_css_datauris');
267 register_setting('autoptimize','autoptimize_css_yui');
268 register_setting('autoptimize','autoptimize_cdn_js');
269 register_setting('autoptimize','autoptimize_cdn_js_url');
270 register_setting('autoptimize','autoptimize_cdn_css');
271 register_setting('autoptimize','autoptimize_cdn_css_url');
272 register_setting('autoptimize','autoptimize_cdn_img');
273 register_setting('autoptimize','autoptimize_cdn_img_url');
274 register_setting('autoptimize','autoptimize_cache_clean');
275 register_setting('autoptimize','autoptimize_cache_nogzip');
276 }
277
278 public function setmeta($links,$file=null)
279 {
280 //Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/
281
282 //Do it only once - saves time
283 static $plugin;
284 if(empty($plugin))
285 $plugin = plugin_basename(WP_PLUGIN_DIR.'/autoptimize/autoptimize.php');
286
287 if($file===null)
288 {
289 //2.7
290 $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'));
291 array_unshift($links,$settings_link);
292 }else{
293 //2.8
294 //If it's us, add the link
295 if($file === $plugin)
296 {
297 $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>',__('Settings')));
298 $links = array_merge($links,$newlink);
299 }
300 }
301
302 return $links;
303 }
304
305 public function get($key)
306 {
307 if(!is_array($this->config))
308 {
309 //Default config
310 $config = array('autoptimize_html' => 0,
311 'autoptimize_html_keepcomments' => 0,
312 'autoptimize_js' => 0,
313 'autoptimize_js_exclude' => "s_sid, smowtion_size, sc_project, WAU_, wau_add, comment-form-quicktags, edToolbar, ch_client",
314 'autoptimize_js_trycatch' => 0,
315 'autoptimize_js_justhead' => 0,
316 'autoptimize_js_forcehead' => 0,
317 'autoptimize_js_yui' => 0,
318 'autoptimize_css' => 0,
319 'autoptimize_css_justhead' => 0,
320 'autoptimize_css_datauris' => 0,
321 'autoptimize_css_yui' => 0,
322 'autoptimize_cdn_js' => 0,
323 'autoptimize_cdn_js_url' => site_url(),
324 'autoptimize_cdn_css' => 0,
325 'autoptimize_cdn_css_url' => site_url(),
326 'autoptimize_cdn_img' => 0,
327 'autoptimize_cdn_img_url' => site_url(),
328 'autoptimize_cache_nogzip' => 0,
329 );
330
331 //Override with user settings
332 foreach(array_keys($config) as $name)
333 {
334 $conf = get_option($name);
335 if($conf!==false)
336 {
337 //It was set before!
338 $config[$name] = $conf;
339 }
340 }
341
342 //Save for next question
343 $this->config = $config;
344 }
345
346 if(isset($this->config[$key]))
347 return $this->config[$key];
348
349 return false;
350 }
351 }
352