Autoptimize - Version 1.6.0

Version Description

  • You can now specify scripts that should not be Autoptimized in the admin page. Just add the names (or part of the path) of the scripts in a comma-seperated list and that JavaScript-file will remain untouched by Autoptimize.
  • Added support for ETag and LastModified (essentially for a better pagespeed score, as the files are explicitely cacheable for 1 year)
  • Autoptimizing for logged in users is enabled again
  • Autoptimize now creates an index.html in wp-content/cache/autoptimize to prevent snooping (as proposed by Chris)
  • bugfix: removed all deprecated functions (reported by Hypolythe and diff by Heiko Adams, thanks guys!)
  • bugfix for HTTPS-problem as reported by dbs121
  • bugfix for breakage with unusual WordPress directory layout as reported by Josef from blog-it-solutions.de.
Download this release

Release Info

Developer futtta
Plugin Icon 128x128 Autoptimize
Version 1.6.0
Comparing to
See all releases

Code changes from version 1.5.1 to 1.6.0

autoptimize.php CHANGED
@@ -3,45 +3,46 @@
3
  Plugin Name: Autoptimize
4
  Plugin URI: http://blog.futtta.be/category/autoptimize/
5
  Description: Optimizes your website, concatenating the CSS and JavaScript code, and compressing it.
6
- Version: 1.5.1
7
  Author: Frank Goossens (futtta)
8
  Author URI: http://blog.futtta.be/
9
  Released under the GNU General Public License (GPL)
10
  http://www.gnu.org/licenses/gpl.txt
11
  */
12
 
13
- //Load config and cache class
14
  include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeConfig.php');
15
  include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeCache.php');
16
 
17
- //Plugin constants
18
  define('AUTOPTIMIZE_CACHE_DIR',WP_CONTENT_DIR.'/cache/autoptimize/');
19
- define('AUTOPTIMIZE_CACHE_URL',WP_CONTENT_URL.'/cache/autoptimize/');
20
  define('AUTOPTIMIZE_CACHE_DELAY',true);
 
 
21
 
22
- //Initialize the cache at least once
23
  $conf = autoptimizeConfig::instance();
24
 
25
- //Do we gzip when caching?
26
  define('AUTOPTIMIZE_CACHE_NOGZIP',(bool) $conf->get('autoptimize_cache_nogzip'));
27
 
28
- //Load translations
29
  $plugin_dir = basename(dirname(__FILE__));
30
  load_plugin_textdomain('autoptimize','wp-content/plugins/'.$plugin_dir.'/localization',$plugin_dir.'/localization');
31
 
32
- //Set up the buffering
33
  function autoptimize_start_buffering()
34
  {
35
- // fgo: not for logged in users, to prevent new admin bar issue in wp3.5
36
- if (!is_user_logged_in()) {
37
 
38
- //Config element
39
  $conf = autoptimizeConfig::instance();
40
 
41
- //Load our base class
42
  include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeBase.php');
43
 
44
- //Load extra classes and set some vars
45
  if($conf->get('autoptimize_html'))
46
  {
47
  include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeHTML.php');
@@ -73,19 +74,19 @@ function autoptimize_start_buffering()
73
  include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeCDN.php');
74
  }
75
 
76
- //Now, start the real thing!
77
  ob_start('autoptimize_end_buffering');
78
 
79
- }
80
  }
81
 
82
  //Action on end -
83
  function autoptimize_end_buffering($content)
84
  {
85
- //Config element
86
  $conf = autoptimizeConfig::instance();
87
 
88
- //Choose the classes
89
  $classes = array();
90
  if($conf->get('autoptimize_js'))
91
  $classes[] = 'autoptimizeScripts';
@@ -96,12 +97,13 @@ function autoptimize_end_buffering($content)
96
  if($conf->get('autoptimize_html'))
97
  $classes[] = 'autoptimizeHTML';
98
 
99
- //Set some options
100
  $classoptions = array(
101
  'autoptimizeScripts' => array(
102
  'justhead' => $conf->get('autoptimize_js_justhead'),
103
  'trycatch' => $conf->get('autoptimize_js_trycatch'),
104
  'yui' => $conf->get('autoptimize_js_yui'),
 
105
  ),
106
  'autoptimizeStyles' => array(
107
  'justhead' => $conf->get('autoptimize_css_justhead'),
@@ -122,7 +124,7 @@ function autoptimize_end_buffering($content)
122
  );
123
 
124
 
125
- //Run the classes
126
  foreach($classes as $name)
127
  {
128
  $instance = new $name($content);
@@ -142,10 +144,10 @@ if(autoptimizeCache::cacheavail())
142
  $conf = autoptimizeConfig::instance();
143
  if( $conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') || $conf->get('autoptimize_cdn_js') || $conf->get('autoptimize_cdn_css'))
144
  {
145
- //Hook to wordpress
146
  add_action('template_redirect','autoptimize_start_buffering',2);
147
  }
148
  }
149
 
150
- //Do not pollute other plugins
151
  unset($conf);
3
  Plugin Name: Autoptimize
4
  Plugin URI: http://blog.futtta.be/category/autoptimize/
5
  Description: Optimizes your website, concatenating the CSS and JavaScript code, and compressing it.
6
+ Version: 1.6.0
7
  Author: Frank Goossens (futtta)
8
  Author URI: http://blog.futtta.be/
9
  Released under the GNU General Public License (GPL)
10
  http://www.gnu.org/licenses/gpl.txt
11
  */
12
 
13
+ // Load config and cache class
14
  include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeConfig.php');
15
  include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeCache.php');
16
 
17
+ // Plugin constants
18
  define('AUTOPTIMIZE_CACHE_DIR',WP_CONTENT_DIR.'/cache/autoptimize/');
19
+ define('AUTOPTIMIZE_CACHE_URL',content_url().'/cache/autoptimize/');
20
  define('AUTOPTIMIZE_CACHE_DELAY',true);
21
+ define('WP_ROOT_URL',str_replace('/wp-content','',content_url()));
22
+ define('WP_ROOT_PATH',str_replace('/wp-content','',WP_CONTENT_DIR));
23
 
24
+ // Initialize the cache at least once
25
  $conf = autoptimizeConfig::instance();
26
 
27
+ // Do we gzip when caching?
28
  define('AUTOPTIMIZE_CACHE_NOGZIP',(bool) $conf->get('autoptimize_cache_nogzip'));
29
 
30
+ // Load translations
31
  $plugin_dir = basename(dirname(__FILE__));
32
  load_plugin_textdomain('autoptimize','wp-content/plugins/'.$plugin_dir.'/localization',$plugin_dir.'/localization');
33
 
34
+ // Set up the buffering
35
  function autoptimize_start_buffering()
36
  {
37
+ // if (!is_user_logged_in()) {
 
38
 
39
+ // Config element
40
  $conf = autoptimizeConfig::instance();
41
 
42
+ // Load our base class
43
  include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeBase.php');
44
 
45
+ // Load extra classes and set some vars
46
  if($conf->get('autoptimize_html'))
47
  {
48
  include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeHTML.php');
74
  include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeCDN.php');
75
  }
76
 
77
+ // Now, start the real thing!
78
  ob_start('autoptimize_end_buffering');
79
 
80
+ // }
81
  }
82
 
83
  //Action on end -
84
  function autoptimize_end_buffering($content)
85
  {
86
+ // Config element
87
  $conf = autoptimizeConfig::instance();
88
 
89
+ // Choose the classes
90
  $classes = array();
91
  if($conf->get('autoptimize_js'))
92
  $classes[] = 'autoptimizeScripts';
97
  if($conf->get('autoptimize_html'))
98
  $classes[] = 'autoptimizeHTML';
99
 
100
+ // Set some options
101
  $classoptions = array(
102
  'autoptimizeScripts' => array(
103
  'justhead' => $conf->get('autoptimize_js_justhead'),
104
  'trycatch' => $conf->get('autoptimize_js_trycatch'),
105
  'yui' => $conf->get('autoptimize_js_yui'),
106
+ 'exclude' => $conf->get('autoptimize_js_exclude')
107
  ),
108
  'autoptimizeStyles' => array(
109
  'justhead' => $conf->get('autoptimize_css_justhead'),
124
  );
125
 
126
 
127
+ // Run the classes
128
  foreach($classes as $name)
129
  {
130
  $instance = new $name($content);
144
  $conf = autoptimizeConfig::instance();
145
  if( $conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') || $conf->get('autoptimize_cdn_js') || $conf->get('autoptimize_cdn_css'))
146
  {
147
+ // Hook to wordpress
148
  add_action('template_redirect','autoptimize_start_buffering',2);
149
  }
150
  }
151
 
152
+ // Do not pollute other plugins
153
  unset($conf);
classes/autoptimizeBase.php CHANGED
@@ -25,13 +25,24 @@ abstract class autoptimizeBase
25
  //Converts an URL to a full path
26
  protected function getpath($url)
27
  {
28
- $path = str_replace(get_settings('home'),'',$url);
29
- if(preg_match('#^(https?|ftp)://#i',$path))
30
- {
31
- //External script (adsense, etc)
32
- return false;
33
  }
34
- $path = str_replace('//','/',ABSPATH.$path);
35
- return $path;
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  }
37
  }
25
  //Converts an URL to a full path
26
  protected function getpath($url)
27
  {
28
+ $siteurl = site_url();
29
+ if ((strpos($url,'//')===false) && (strpos($url,parse_url($siteurl,PHP_URL_HOST))===false)) {
30
+ $url = $siteurl.$url;
 
 
31
  }
32
+ $path = str_replace(WP_ROOT_URL,'',$url);
33
+ if(preg_match('#^(https?|ftp)://#i',$path))
34
+ {
35
+ /** External script/css (adsense, etc) */
36
+ return false;
37
+ }
38
+ $path = str_replace('//','/',WP_ROOT_PATH.$path);
39
+ return $path;
40
+ }
41
+
42
+ // coz I'm a crappy developer and I need easy access to whatever I want to log
43
+ protected function ao_logger($logmsg) {
44
+ $logfile=WP_CONTENT_DIR.'/ao_log.txt';
45
+ $logmsg.="\n";
46
+ file_put_contents($logfile,$logmsg,FILE_APPEND);
47
  }
48
  }
classes/autoptimizeCDN.php CHANGED
@@ -18,7 +18,7 @@ class autoptimizeCDN extends autoptimizeBase
18
  $this->cssurl = $options['cssurl'];
19
  $this->img = (bool) $options['img'];
20
  $this->imgurl = $options['imgurl'];
21
- $siteurl = get_bloginfo('siteurl');
22
 
23
  if($this->js)
24
  {
18
  $this->cssurl = $options['cssurl'];
19
  $this->img = (bool) $options['img'];
20
  $this->imgurl = $options['imgurl'];
21
+ $siteurl = site_url();
22
 
23
  if($this->js)
24
  {
classes/autoptimizeCache.php CHANGED
@@ -154,7 +154,13 @@ class autoptimizeCache
154
  //How are we supposed to write?
155
  return false;
156
  }
157
-
 
 
 
 
 
 
158
  //All OK
159
  return true;
160
  }
154
  //How are we supposed to write?
155
  return false;
156
  }
157
+
158
+ /** write index.html here to avoid prying eyes */
159
+ $indexFile=AUTOPTIMIZE_CACHE_DIR.'/index.html';
160
+ if(!is_file($indexFile)) {
161
+ @file_put_contents($indexFile,'<html><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/">Autoptimize</a></body></html>');
162
+ }
163
+
164
  //All OK
165
  return true;
166
  }
classes/autoptimizeConfig.php CHANGED
@@ -8,7 +8,7 @@ class autoptimizeConfig
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'));
@@ -19,11 +19,12 @@ class autoptimizeConfig
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
  //Clean cache?
28
  if(get_option('autoptimize_cache_clean'))
29
  {
@@ -74,6 +75,11 @@ class autoptimizeConfig
74
  <td><input type="checkbox" name="autoptimize_js" <?php echo get_option('autoptimize_js')?'checked="checked" ':''; ?>/></td>
75
  </tr>
76
  <tr valign="top">
 
 
 
 
 
77
  <th scope="row"><?php _e('Look for scripts only in &lt;head&gt;?','autoptimize'); ?></th>
78
  <td><label for="autoptimize_js_justhead"><input type="checkbox" name="autoptimize_js_justhead" <?php echo get_option('autoptimize_js_justhead')?'checked="checked" ':''; ?>/>
79
  <?php _e('Disabled by default. If the cache gets big, you might want to enable this.','autoptimize'); ?></label></td>
@@ -122,7 +128,7 @@ class autoptimizeConfig
122
  </tr>
123
  <tr valign="top">
124
  <th scope="row"><?php _e('JavaScript Base URL','autoptimize'); ?></th>
125
- <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:get_bloginfo('siteurl')); ?>" />
126
  <?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>
127
  </tr>
128
  <tr valign="top">
@@ -132,7 +138,7 @@ class autoptimizeConfig
132
  </tr>
133
  <tr valign="top">
134
  <th scope="row"><?php _e('CSS Base URL','autoptimize'); ?></th>
135
- <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:get_bloginfo('siteurl')); ?>" />
136
  <?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>
137
  </tr>
138
  <tr valign="top">
@@ -142,7 +148,7 @@ class autoptimizeConfig
142
  </tr>
143
  <tr valign="top">
144
  <th scope="row"><?php _e('Image Base URL','autoptimize'); ?></th>
145
- <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:get_bloginfo('siteurl')); ?>" />
146
  <?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>
147
  </tr>
148
  </table>
@@ -225,14 +231,14 @@ class autoptimizeConfig
225
 
226
  public function addmenu()
227
  {
228
- $hook=add_options_page(__('Autoptimize Options','autoptimize'),'Autoptimize',8,'autoptimize',array($this,'show'));
229
  add_action( 'admin_print_scripts-'.$hook,array($this,'autoptimize_admin_scripts'));
230
  add_action( 'admin_print_styles-'.$hook,array($this,'autoptimize_admin_styles'));
231
  }
232
 
233
  public function autoptimize_admin_scripts() {
234
- wp_enqueue_script('jqzrssfeed', plugins_url('/external/jquery.zrssfeed.min.js', __FILE__), array(jquery),null,true);
235
- wp_enqueue_script('jqcookie', plugins_url('/external/jquery.cookie.min.js', __FILE__), array(jquery),null,true);
236
  }
237
 
238
  public function autoptimize_admin_styles() {
@@ -245,6 +251,7 @@ class autoptimizeConfig
245
  register_setting('autoptimize','autoptimize_html');
246
  register_setting('autoptimize','autoptimize_html_keepcomments');
247
  register_setting('autoptimize','autoptimize_js');
 
248
  register_setting('autoptimize','autoptimize_js_trycatch');
249
  register_setting('autoptimize','autoptimize_js_justhead');
250
  register_setting('autoptimize','autoptimize_js_yui');
@@ -297,6 +304,7 @@ class autoptimizeConfig
297
  $config = array('autoptimize_html' => 0,
298
  'autoptimize_html_keepcomments' => 0,
299
  'autoptimize_js' => 0,
 
300
  'autoptimize_js_trycatch' => 0,
301
  'autoptimize_js_justhead' => 0,
302
  'autoptimize_js_yui' => 0,
@@ -305,11 +313,11 @@ class autoptimizeConfig
305
  'autoptimize_css_datauris' => 0,
306
  'autoptimize_css_yui' => 0,
307
  'autoptimize_cdn_js' => 0,
308
- 'autoptimize_cdn_js_url' => get_bloginfo('siteurl'),
309
  'autoptimize_cdn_css' => 0,
310
- 'autoptimize_cdn_css_url' => get_bloginfo('siteurl'),
311
  'autoptimize_cdn_img' => 0,
312
- 'autoptimize_cdn_img_url' => get_bloginfo('siteurl'),
313
  'autoptimize_cache_nogzip' => 0,
314
  );
315
 
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'));
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
  {
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>
128
  </tr>
129
  <tr valign="top">
130
  <th scope="row"><?php _e('JavaScript Base URL','autoptimize'); ?></th>
131
+ <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()); ?>" />
132
  <?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>
133
  </tr>
134
  <tr valign="top">
138
  </tr>
139
  <tr valign="top">
140
  <th scope="row"><?php _e('CSS Base URL','autoptimize'); ?></th>
141
+ <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()); ?>" />
142
  <?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>
143
  </tr>
144
  <tr valign="top">
148
  </tr>
149
  <tr valign="top">
150
  <th scope="row"><?php _e('Image Base URL','autoptimize'); ?></th>
151
+ <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()); ?>" />
152
  <?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>
153
  </tr>
154
  </table>
231
 
232
  public function addmenu()
233
  {
234
+ $hook=add_options_page(__('Autoptimize Options','autoptimize'),'Autoptimize','manage_options','autoptimize',array($this,'show'));
235
  add_action( 'admin_print_scripts-'.$hook,array($this,'autoptimize_admin_scripts'));
236
  add_action( 'admin_print_styles-'.$hook,array($this,'autoptimize_admin_styles'));
237
  }
238
 
239
  public function autoptimize_admin_scripts() {
240
+ wp_enqueue_script('jqzrssfeed', plugins_url('/external/jquery.zrssfeed.min.js', __FILE__), array('jquery'),null,true);
241
+ wp_enqueue_script('jqcookie', plugins_url('/external/jquery.cookie.min.js', __FILE__), array('jquery'),null,true);
242
  }
243
 
244
  public function autoptimize_admin_styles() {
251
  register_setting('autoptimize','autoptimize_html');
252
  register_setting('autoptimize','autoptimize_html_keepcomments');
253
  register_setting('autoptimize','autoptimize_js');
254
+ register_setting('autoptimize','autoptimize_js_exclude');
255
  register_setting('autoptimize','autoptimize_js_trycatch');
256
  register_setting('autoptimize','autoptimize_js_justhead');
257
  register_setting('autoptimize','autoptimize_js_yui');
304
  $config = array('autoptimize_html' => 0,
305
  'autoptimize_html_keepcomments' => 0,
306
  'autoptimize_js' => 0,
307
+ 'autoptimize_js_exclude' => "s_sid, smowtion_size, sc_project, WAU_, wau_add, comment-form-quicktags, edToolbar, ch_client",
308
  'autoptimize_js_trycatch' => 0,
309
  'autoptimize_js_justhead' => 0,
310
  'autoptimize_js_yui' => 0,
313
  'autoptimize_css_datauris' => 0,
314
  'autoptimize_css_yui' => 0,
315
  'autoptimize_cdn_js' => 0,
316
+ 'autoptimize_cdn_js_url' => site_url(),
317
  'autoptimize_cdn_css' => 0,
318
+ 'autoptimize_cdn_css_url' => site_url(),
319
  'autoptimize_cdn_img' => 0,
320
+ 'autoptimize_cdn_img_url' => site_url(),
321
  'autoptimize_cache_nogzip' => 0,
322
  );
323
 
classes/autoptimizeScripts.php CHANGED
@@ -3,8 +3,7 @@
3
  class autoptimizeScripts extends autoptimizeBase
4
  {
5
  private $scripts = array();
6
- // fgo: add html5.js to avoid aggregating html5 support for older IE browsers
7
- private $dontmove = array('document.write','html5.js','show_ads.js','google_ad','blogcatalog.com/w','tweetmeme.com/i','mybloglog.com/','var s_sid = ','histats.com/js','smowtion_size','ads.smowtion.com/ad.js','sc_project','statcounter.com/counter/counter.js','widgets.amung.us','WAU_','wau_add','ws.amazon.com/widgets','media.fastclick.net','/ads/','comment-form-quicktags/quicktags.php','edToolbar','intensedebate.com','ch_client','scripts.chitika.net/','_gaq.push','jotform.com/');
8
  private $domove = array('gaJsHost','load_cmc','jd.gallery.transitions.js','swfobject.embedSWF(','tiny_mce.js','tinyMCEPreInit.go');
9
  private $domovelast = array('addthis.com','/afsonline/show_afs_search.js','disqus.js','networkedblogs.com/getnetworkwidget','infolinks.com/js/','jd.gallery.js.php','jd.gallery.transitions.js','swfobject.embedSWF(','linkwithin.com/widget.js','tiny_mce.js','tinyMCEPreInit.go');
10
  private $trycatch = false;
@@ -25,6 +24,12 @@ class autoptimizeScripts extends autoptimizeBase
25
  $this->content = $content[0].'</head>';
26
  $this->restofcontent = $content[1];
27
  }
 
 
 
 
 
 
28
 
29
  //Should we add try-catch?
30
  if($options['trycatch'] == true)
3
  class autoptimizeScripts extends autoptimizeBase
4
  {
5
  private $scripts = array();
6
+ private $dontmove = array('document.write','html5.js','show_ads.js','google_ad','_gaq.push','/ads/');
 
7
  private $domove = array('gaJsHost','load_cmc','jd.gallery.transitions.js','swfobject.embedSWF(','tiny_mce.js','tinyMCEPreInit.go');
8
  private $domovelast = array('addthis.com','/afsonline/show_afs_search.js','disqus.js','networkedblogs.com/getnetworkwidget','infolinks.com/js/','jd.gallery.js.php','jd.gallery.transitions.js','swfobject.embedSWF(','linkwithin.com/widget.js','tiny_mce.js','tinyMCEPreInit.go');
9
  private $trycatch = false;
24
  $this->content = $content[0].'</head>';
25
  $this->restofcontent = $content[1];
26
  }
27
+
28
+ $excludeJS = $options['exclude'];
29
+ if ($excludeJS!=="") {
30
+ $exclJSArr = array_map('trim',explode(",",$excludeJS));
31
+ $this->dontmove = array_merge($exclJSArr,$this->dontmove);
32
+ }
33
 
34
  //Should we add try-catch?
35
  if($options['trycatch'] == true)
classes/autoptimizeStyles.php CHANGED
@@ -35,6 +35,7 @@ class autoptimizeStyles extends autoptimizeBase
35
  {
36
  foreach($matches[0] as $tag)
37
  {
 
38
  //Get the media
39
  if(strpos($tag,'media=')!==false)
40
  {
@@ -73,6 +74,7 @@ class autoptimizeStyles extends autoptimizeBase
73
 
74
  //Remove the original style tag
75
  $this->content = str_replace($tag,'',$this->content);
 
76
  }
77
 
78
  return true;
@@ -329,7 +331,8 @@ class autoptimizeStyles extends autoptimizeBase
329
 
330
  private function fixurls($file,$code)
331
  {
332
- $file = str_replace(ABSPATH,'/',$file); //Sth like /wp-content/file.css
 
333
  $dir = dirname($file); //Like /wp-content
334
 
335
  if(preg_match_all('#url\((.*)\)#Usi',$code,$matches))
@@ -345,7 +348,8 @@ class autoptimizeStyles extends autoptimizeBase
345
  continue;
346
  }else{
347
  //relative URL. Let's fix it!
348
- $newurl = get_settings('home').str_replace('//','/',$dir.'/'.$url); //http://yourblog.com/wp-content/../image.png
 
349
  $hash = md5($url);
350
  $code = str_replace($matches[0][$k],$hash,$code);
351
  $replace[$hash] = 'url('.$newurl.')';
35
  {
36
  foreach($matches[0] as $tag)
37
  {
38
+ if (strpos($tag,"admin-bar.min.css")===false) {
39
  //Get the media
40
  if(strpos($tag,'media=')!==false)
41
  {
74
 
75
  //Remove the original style tag
76
  $this->content = str_replace($tag,'',$this->content);
77
+ }
78
  }
79
 
80
  return true;
331
 
332
  private function fixurls($file,$code)
333
  {
334
+ // $file = str_replace(ABSPATH,'/',$file); //Sth like /wp-content/file.css
335
+ $file = str_replace(WP_CONTENT_DIR,'/',$file);
336
  $dir = dirname($file); //Like /wp-content
337
 
338
  if(preg_match_all('#url\((.*)\)#Usi',$code,$matches))
348
  continue;
349
  }else{
350
  //relative URL. Let's fix it!
351
+ // $newurl = get_settings('home').str_replace('//','/',$dir.'/'.$url); //http://yourblog.com/wp-content/../image.png
352
+ $newurl = WP_CONTENT_URL.str_replace('//','/',$dir.'/'.$url);
353
  $hash = md5($url);
354
  $code = str_replace($matches[0][$k],$hash,$code);
355
  $replace[$hash] = 'url('.$newurl.')';
config/default.php CHANGED
@@ -33,16 +33,33 @@ if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compressi
33
  //Get data
34
  $contents = file_get_contents(__FILE__.'.'.$encoding);
35
 
36
- if(isset($encoding) && $encoding != 'none')
37
- {
38
- // Send compressed contents
39
- header('Content-Encoding: '.$encoding);
40
- }
41
- header('Vary: Accept-Encoding');
42
- header('Content-Length: '.strlen($contents));
43
 
44
- header('Content-type: %%CONTENT%%; charset=utf-8');
45
- header('Cache-Control: max-age=315360000, public, must-revalidate');
46
- header('Expires: '.gmdate('D, d M Y H:i:s', time() + 315360000).' GMT'); //10 years
 
 
 
47
 
48
- echo $contents;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  //Get data
34
  $contents = file_get_contents(__FILE__.'.'.$encoding);
35
 
36
+ // first check if we have to send 304
37
+ $eTag=md5($contents);
38
+ $modTime=filemtime(__FILE__.'.none');
39
+
40
+ $headers = apache_request_headers();
41
+ $eTagMatch = (isset($headers['If-None-Match']) && str_pos($headers['If-None-Match'],$eTag));
42
+ $modTimeMatch = (isset($headers['If-Modified-Since']) && strtotime($headers['If-Modified-Since']) === $modTime);
43
 
44
+ if (($modTimeMatch)||($eTagMatch)) {
45
+ header('HTTP/1.1 304 Not Modified');
46
+ header('Connection: close');
47
+ } else {
48
+ // send all sorts of headers
49
+ $expireTime=60*60*24*356; // 1y max according to RFC
50
 
51
+ if(isset($encoding) && $encoding != 'none')
52
+ {
53
+ header('Content-Encoding: '.$encoding);
54
+ }
55
+ header('Vary: Accept-Encoding');
56
+ header('Content-Length: '.strlen($contents));
57
+ header('Content-type: %%CONTENT%%; charset=utf-8');
58
+ header('Cache-Control: max-age='.$expireTime.', public, must-revalidate');
59
+ header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); //10 years
60
+ header('ETag: ' . $eTag);
61
+ header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT');
62
+
63
+ // send output
64
+ echo $contents;
65
+ }
config/delayed.php CHANGED
@@ -41,29 +41,46 @@ if($encoding != 'none' && $iscompressed == false)
41
  $contents = file_get_contents(__FILE__.'.'.$encoding);
42
  }
43
 
44
- if ($encoding != 'none')
45
- {
46
- // Send compressed contents
47
- header('Content-Encoding: '.$encoding);
48
- }
49
- header('Vary: Accept-Encoding');
50
- header('Content-Length: '.strlen($contents));
51
 
52
- header('Content-type: %%CONTENT%%; charset=utf-8');
53
- header('Cache-Control: max-age=315360000, public, must-revalidate');
54
- header('Expires: '.gmdate('D, d M Y H:i:s', time() + 315360000).' GMT'); //10 years
55
 
56
- echo $contents;
 
 
57
 
58
- //Write it here
59
- if($encoding != 'none' && $iscompressed == false)
60
- {
61
- //Write the content we sent
62
- file_put_contents(__FILE__.'.'.$encoding,$contents);
63
-
64
- //And write the new content
65
- $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP);
66
- $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip');
67
- $contents = gzencode($code,9,$flag);
68
- file_put_contents(__FILE__.'.'.$ext,$contents);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
41
  $contents = file_get_contents(__FILE__.'.'.$encoding);
42
  }
43
 
44
+ // first check if we have to send 304
45
+ // inspired by http://www.jonasjohn.de/snippets/php/caching.htm
 
 
 
 
 
46
 
47
+ $eTag=md5($contents);
48
+ $modTime=filemtime(__FILE__.'.none');
 
49
 
50
+ $headers = apache_request_headers();
51
+ $eTagMatch = (isset($headers['If-None-Match']) && str_pos($headers['If-None-Match'],$eTag));
52
+ $modTimeMatch = (isset($headers['If-Modified-Since']) && strtotime($headers['If-Modified-Since']) === $modTime);
53
 
54
+ if (($modTimeMatch)||($eTagMatch)) {
55
+ header('HTTP/1.1 304 Not Modified');
56
+ header('Connection: close');
57
+ } else {
58
+ // send all sorts of headers
59
+ $expireTime=60*60*24*355; // 1y max according to RFC
60
+ if ($encoding != 'none') {
61
+ header('Content-Encoding: '.$encoding);
62
+ }
63
+ header('Vary: Accept-Encoding');
64
+ header('Content-Length: '.strlen($contents));
65
+ header('Content-type: %%CONTENT%%; charset=utf-8');
66
+ header('Cache-Control: max-age='.$expireTime.', public, must-revalidate');
67
+ header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT');
68
+ header('ETag: ' . $eTag);
69
+ header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT');
70
+
71
+ // send output
72
+ echo $contents;
73
+
74
+ //And write to filesystem cache if not done yet
75
+ if($encoding != 'none' && $iscompressed == false)
76
+ {
77
+ //Write the content we sent
78
+ file_put_contents(__FILE__.'.'.$encoding,$contents);
79
+
80
+ //And write the new content
81
+ $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP);
82
+ $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip');
83
+ $contents = gzencode($code,9,$flag);
84
+ file_put_contents(__FILE__.'.'.$ext,$contents);
85
+ }
86
  }
readme.txt CHANGED
@@ -1,11 +1,11 @@
1
  === Autoptimize ===
2
- Contributors: turl, futtta
3
- Tags: css, html, javascript, js, optimize, speed, cache, data-uri, aggregate, minimize
4
  Requires at least: 2.7
5
  Tested up to: 3.5
6
- Stable tag: 1.5.1
7
 
8
- Autoptimize is a Wordpress plugin that speeds up your website, and helps you save bandwidth.
9
 
10
  == Description ==
11
 
@@ -21,10 +21,6 @@ I also recommend using WP Super Cache in conjuction with Autoptimize to speed up
21
 
22
  == Frequently Asked Questions ==
23
 
24
- = Autoptimize doesn't work when I'm logged on? =
25
-
26
- Correct; given the recurring problems with the WordPress admin bar, Autoptimize only works for anonymous users starting from version 1.5.
27
-
28
  = What does the plugin do to help speed up my site? =
29
 
30
  It concatenates all scripts and styles, minifies and compresses them, adds expires headers, caches them, and moves styles to the page head, and scripts to the footer. It also minifies the HTML code itself, making your page really lightweight.
@@ -36,6 +32,15 @@ You can report problems on the [wordpress.org support forum](http://wordpress.or
36
 
37
  == Changelog ==
38
 
 
 
 
 
 
 
 
 
 
39
  = 1.5.1 =
40
  * bugfix: add CSS before opening title-tag instead of after closing title, to avoid CSS being loaded in wrong order, as reported by [fotofashion](http://fotoandfashion.de/) and [blogitsolutions](www.blog-it-solutions.de) (thanks guys)
41
 
1
  === Autoptimize ===
2
+ Contributors: futtta, turl
3
+ Tags: css, html, javascript, js, optimize, speed, cache, data-uri, aggregate, minimize, performance, pagespeed
4
  Requires at least: 2.7
5
  Tested up to: 3.5
6
+ Stable tag: 1.6.0
7
 
8
+ Autoptimize is a WordPress plugin that speeds up your website, and helps you save bandwidth.
9
 
10
  == Description ==
11
 
21
 
22
  == Frequently Asked Questions ==
23
 
 
 
 
 
24
  = What does the plugin do to help speed up my site? =
25
 
26
  It concatenates all scripts and styles, minifies and compresses them, adds expires headers, caches them, and moves styles to the page head, and scripts to the footer. It also minifies the HTML code itself, making your page really lightweight.
32
 
33
  == Changelog ==
34
 
35
+ = 1.6.0 =
36
+ * You can now specify scripts that should not be Autoptimized in the admin page. Just add the names (or part of the path) of the scripts in a comma-seperated list and that JavaScript-file will remain untouched by Autoptimize.
37
+ * Added support for ETag and LastModified (essentially for a better pagespeed score, as the files are explicitely cacheable for 1 year)
38
+ * Autoptimizing for logged in users is enabled again
39
+ * Autoptimize now creates an index.html in wp-content/cache/autoptimize to prevent snooping (as [proposed by Chris](http://blog.futtta.be/2013/01/07/adopting-an-oss-orphan-autoptimize/#li-comment-36292))
40
+ * bugfix: removed all deprecated functions ([reported by Hypolythe](http://wordpress.org/support/topic/many-deprecated-errors) and diff by Heiko Adams, thanks guys!)
41
+ * bugfix for HTTPS-problem as [reported by dbs121](http://wordpress.org/support/topic/woocommerce-autoptimizer-https-issue)
42
+ * bugfix for breakage with unusual WordPress directory layout as reported by [Josef from blog-it-solutions.de](http://www.blog-it-solutions.de/).
43
+
44
  = 1.5.1 =
45
  * bugfix: add CSS before opening title-tag instead of after closing title, to avoid CSS being loaded in wrong order, as reported by [fotofashion](http://fotoandfashion.de/) and [blogitsolutions](www.blog-it-solutions.de) (thanks guys)
46