Autoptimize - Version 1.6.3

Version Description

  • fix for IE-hacks with javascript inside, causing javascript breakage (as seen in Sampression theme) as reported by Takahiro of hiskip.com
  • fix for escaping problem of imported css causing css breakage (as seen in Sampression theme) as reported by Takahiro as well
  • fix to parse imports with syntax @import 'custom.css' not being parsed (as seen in Arras theme), again as reported by Takahiro
  • fix for complex media types in media-attribute as reported by jvwisssen
  • fix for disappearing background-images that were already datauri's as reported by will.blaschko
  • fix not to strip out comments in HTML needed by WP Super Cache or W3 Total Cache (e.g. mfunc)
  • added check to clean cache on upgrade
  • updated FAQ in readme with information on troubleshooting and support
  • tested with WordPress 3.6 beta
Download this release

Release Info

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

Code changes from version 1.6.2 to 1.6.3

autoptimize.php CHANGED
@@ -3,7 +3,7 @@
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.2
7
  Author: Frank Goossens (futtta)
8
  Author URI: http://blog.futtta.be/
9
  Released under the GNU General Public License (GPL)
@@ -19,11 +19,24 @@ 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
 
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.3
7
  Author: Frank Goossens (futtta)
8
  Author URI: http://blog.futtta.be/
9
  Released under the GNU General Public License (GPL)
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_DIR',str_replace('/wp-content','',WP_CONTENT_DIR));
23
 
24
  // Initialize the cache at least once
25
  $conf = autoptimizeConfig::instance();
26
 
27
+ /* Check if we're updating, in which case we need to flush the cache
28
+ to avoid old versions of aggregated files lingering around */
29
+ // update_option('autoptimize_version','none');
30
+
31
+ $autoptimize_version="1.6.3";
32
+ $autoptimize_db_version=get_option('autoptimize_version','none');
33
+
34
+ if ($autoptimize_db_version !== $autoptimize_version) {
35
+ autoptimizeCache::clearall();
36
+ update_option('autoptimize_version',$autoptimize_version);
37
+ $autoptimize_db_version=$autoptimize_version;
38
+ }
39
+
40
  // Do we gzip when caching?
41
  define('AUTOPTIMIZE_CACHE_NOGZIP',(bool) $conf->get('autoptimize_cache_nogzip'));
42
 
classes/autoptimizeBase.php CHANGED
@@ -35,7 +35,7 @@ abstract class autoptimizeBase
35
  /** External script/css (adsense, etc) */
36
  return false;
37
  }
38
- $path = str_replace('//','/',WP_ROOT_PATH.$path);
39
  return $path;
40
  }
41
 
35
  /** External script/css (adsense, etc) */
36
  return false;
37
  }
38
+ $path = str_replace('//','/',WP_ROOT_DIR.$path);
39
  return $path;
40
  }
41
 
classes/autoptimizeHTML.php CHANGED
@@ -19,9 +19,23 @@ class autoptimizeHTML extends autoptimizeBase
19
  {
20
  if(class_exists('Minify_HTML'))
21
  {
22
- //Minify html
 
 
 
 
 
 
 
 
23
  $options = array('keepComments' => $this->keepcomments);
24
  $this->content = Minify_HTML::minify($this->content,$options);
 
 
 
 
 
 
25
  return true;
26
  }
27
 
19
  {
20
  if(class_exists('Minify_HTML'))
21
  {
22
+ // Minify html
23
+ // but don't remove comment-blocks needed by WP Super Cache (& W3 Total Cache)
24
+ if ( ($this->keepcomments===false) && (preg_match( '/<!--mclude|<!--mfunc|<!--dynamic-cached-content-->/', $this->content ))) {
25
+ $this->content = preg_replace('#(<!--mclude .*<!--/mclude-->)#ise','\'%%MFUNC%%\'.base64_encode("$0").\'%%MFUNC%%\'', $this->content);
26
+ $this->content = preg_replace('#(<!--mfunc.*<!--/mfunc-->)#ise','\'%%MFUNC%%\'.base64_encode("$1").\'%%MFUNC%%\'', $this->content);
27
+ $this->content = preg_replace('#(<!--dynamic-cached-content-->.*<!--/dynamic-cached-content-->)#ise','\'%%MFUNC%%\'.base64_encode("$0").\'%%MFUNC%%\'', $this->content);
28
+ $restore_mfuncs=true;
29
+ }
30
+
31
  $options = array('keepComments' => $this->keepcomments);
32
  $this->content = Minify_HTML::minify($this->content,$options);
33
+
34
+
35
+ if ($restore_mfuncs) {
36
+ $this->content = preg_replace('#%%MFUNC%%(.*)%%MFUNC%%#sie','stripslashes(base64_decode("$1"))',$this->content);
37
+ }
38
+
39
  return true;
40
  }
41
 
classes/autoptimizeScripts.php CHANGED
@@ -3,7 +3,7 @@
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;
@@ -38,6 +38,9 @@ class autoptimizeScripts extends autoptimizeBase
38
  //Do we use yui?
39
  $this->yui = $options['yui'];
40
 
 
 
 
41
  //Get script files
42
  if(preg_match_all('#<script.*</script>#Usmi',$this->content,$matches))
43
  {
@@ -201,6 +204,9 @@ class autoptimizeScripts extends autoptimizeBase
201
  $bodyreplacement .= '<script type="text/javascript" src="'.$this->url.'"></script>';
202
  $bodyreplacement .= implode('',$this->move['last']).'</body>';
203
  $this->content = str_replace('</body>',$bodyreplacement,$this->content);
 
 
 
204
 
205
  //Return the modified HTML
206
  return $this->content;
3
  class autoptimizeScripts extends autoptimizeBase
4
  {
5
  private $scripts = array();
6
+ private $dontmove = array('document.write','html5.js','show_ads.js','google_ad','blogcatalog.com/w','tweetmeme.com/i','mybloglog.com/','histats.com/js','ads.smowtion.com/ad.js','statcounter.com/counter/counter.js','widgets.amung.us','ws.amazon.com/widgets','media.fastclick.net','/ads/','comment-form-quicktags/quicktags.php','edToolbar','intensedebate.com','scripts.chitika.net/','_gaq.push','jotform.com/');
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;
38
  //Do we use yui?
39
  $this->yui = $options['yui'];
40
 
41
+ //Save IE hacks
42
+ $this->content = preg_replace('#(<\!--\[if.*\]>.*<\!\[endif\]-->)#Usie','\'%%IEHACK%%\'.base64_encode("$1").\'%%IEHACK%%\'',$this->content);
43
+
44
  //Get script files
45
  if(preg_match_all('#<script.*</script>#Usmi',$this->content,$matches))
46
  {
204
  $bodyreplacement .= '<script type="text/javascript" src="'.$this->url.'"></script>';
205
  $bodyreplacement .= implode('',$this->move['last']).'</body>';
206
  $this->content = str_replace('</body>',$bodyreplacement,$this->content);
207
+
208
+ //Restore IE hacks
209
+ $this->content = preg_replace('#%%IEHACK%%(.*)%%IEHACK%%#Usie','stripslashes(base64_decode("$1"))',$this->content);
210
 
211
  //Return the modified HTML
212
  return $this->content;
classes/autoptimizeStyles.php CHANGED
@@ -44,7 +44,8 @@ class autoptimizeStyles extends autoptimizeBase
44
  $media = array();
45
  foreach($medias as $elem)
46
  {
47
- $media[] = current(explode(' ',trim($elem),2));
 
48
  }
49
  }else{
50
  //No media specified - applies to all
@@ -151,16 +152,7 @@ class autoptimizeStyles extends autoptimizeBase
151
  $path = $this->getpath($url);
152
  if(file_exists($path) && is_readable($path))
153
  {
154
- $code = $this->fixurls($path,file_get_contents($path));
155
- /*$media = preg_replace('#^.*(?:\)|"|\')(.*)(?:\s|;).*$#','$1',$import);
156
- $media = array_map('trim',explode(' ',$media));
157
- if(empty($media))
158
- {
159
- $thiscss = [...] (Line under)
160
- }else{
161
- //media in @import - how should I handle these?
162
- //TODO: Infinite recursion!
163
- }*/
164
  $thiscss = preg_replace('#(/\*FILESTART\*/.*)'.preg_quote($import,'#').'#Us','/*FILESTART2*/'.$code.'$1',$thiscss);
165
  }else{
166
  //getpath is not working?
@@ -198,7 +190,7 @@ class autoptimizeStyles extends autoptimizeBase
198
 
199
  $imgreplace = array();
200
  //Do the imaging!
201
- if($this->datauris == true && function_exists('base64_encode') && preg_match_all('#(background[^;}]*url\((.*)\)[^;}]*)(?:;|$|})#Usm',$code,$matches))
202
  {
203
  foreach($matches[2] as $count => $quotedurl)
204
  {
@@ -332,10 +324,13 @@ class autoptimizeStyles extends autoptimizeBase
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))
 
 
 
339
  {
340
  $replace = array();
341
  foreach($matches[1] as $k => $url)
@@ -349,7 +344,7 @@ class autoptimizeStyles extends autoptimizeBase
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.')';
44
  $media = array();
45
  foreach($medias as $elem)
46
  {
47
+ // $media[] = current(explode(' ',trim($elem),2));
48
+ $media[] = $elem;
49
  }
50
  }else{
51
  //No media specified - applies to all
152
  $path = $this->getpath($url);
153
  if(file_exists($path) && is_readable($path))
154
  {
155
+ $code = addcslashes($this->fixurls($path,file_get_contents($path)),"\\");
 
 
 
 
 
 
 
 
 
156
  $thiscss = preg_replace('#(/\*FILESTART\*/.*)'.preg_quote($import,'#').'#Us','/*FILESTART2*/'.$code.'$1',$thiscss);
157
  }else{
158
  //getpath is not working?
190
 
191
  $imgreplace = array();
192
  //Do the imaging!
193
+ if($this->datauris == true && function_exists('base64_encode') && preg_match_all('#(background[^;}]*url\((?!data)(.*)\)[^;}]*)(?:;|$|})#Usm',$code,$matches))
194
  {
195
  foreach($matches[2] as $count => $quotedurl)
196
  {
324
  private function fixurls($file,$code)
325
  {
326
  // $file = str_replace(ABSPATH,'/',$file); //Sth like /wp-content/file.css
327
+ $file = str_replace(WP_ROOT_DIR,'/',$file);
328
  $dir = dirname($file); //Like /wp-content
329
+
330
+ // quick fix for import-troubles in e.g. arras theme
331
+ $code=preg_replace('#@import ("|\')(.+?)\.css("|\')#','@import url("${2}.css")',$code);
332
+
333
+ if(preg_match_all('#url?\((?!data)(.*)\)#Usi',$code,$matches))
334
  {
335
  $replace = array();
336
  foreach($matches[1] as $k => $url)
344
  }else{
345
  //relative URL. Let's fix it!
346
  // $newurl = get_settings('home').str_replace('//','/',$dir.'/'.$url); //http://yourblog.com/wp-content/../image.png
347
+ $newurl = WP_ROOT_URL.str_replace('//','/',$dir.'/'.$url);
348
  $hash = md5($url);
349
  $code = str_replace($matches[0][$k],$hash,$code);
350
  $replace[$hash] = 'url('.$newurl.')';
readme.txt CHANGED
@@ -1,17 +1,18 @@
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.2
7
 
8
- Autoptimize is a WordPress plugin that speeds up your website, and helps you save bandwidth.
9
 
10
  == Description ==
11
 
12
  Autoptimize makes optimizing your site really easy. 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.
13
 
14
- I also recommend using WP Super Cache in conjuction with Autoptimize to speed up your blog.
 
15
 
16
  == Installation ==
17
 
@@ -25,13 +26,49 @@ I also recommend using WP Super Cache in conjuction with Autoptimize to speed up
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.
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  = Where can I report an error? =
29
 
30
- You can report problems on the [wordpress.org support forum](http://wordpress.org/support/plugin/autoptimize), or [contact the author using this contact form](http://blog.futtta.be/contact/).
31
 
 
 
 
 
 
 
 
32
 
33
  == Changelog ==
34
 
 
 
 
 
 
 
 
 
 
 
 
35
  = 1.6.2 =
36
  * Yet another emergency bugfix I'm afraid: apache_request_headers (again in config/delayed.php) is only available on ... Apache (duh), breaking non-Apache systems such as ngnix, Lighttpd and MS IIS badly. Reported by multiple users, thanks all!
37
 
1
  === Autoptimize ===
2
  Contributors: futtta, turl
3
+ Tags: css, html, javascript, js, optimize, speed, cache, data-uri, aggregate, minimize, performance, pagespeed, booster, multisite
4
  Requires at least: 2.7
5
+ Tested up to: 3.6
6
+ Stable tag: 1.6.3
7
 
8
+ Autoptimize speeds up your website and helps you save bandwidth by aggregating and minimizing JS and CSS.
9
 
10
  == Description ==
11
 
12
  Autoptimize makes optimizing your site really easy. 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.
13
 
14
+ If you consider performance important, we recommend the use of a caching-plugin such as e.g. [WP Super Cache](http://wordpress.org/extend/plugins/wp-super-cache/) or
15
+ [HyperCache](http://wordpress.org/extend/plugins/hyper-cache/) as well.
16
 
17
  == Installation ==
18
 
26
 
27
  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.
28
 
29
+ = Will this work with for my blog? =
30
+
31
+ Yes, most of the time, but there will always be exceptions. Although Autoptimize goes through great lengths to work with as many themes and plugins possible, there undoubtably are circumstances in which Autoptimize will not work to the full extent (full HTML, JS and CSS optimization). See "Troubleshooting" below for info on how to proceed if you encounter issues.
32
+
33
+ = Compatibility with WP SlimSat =
34
+
35
+ There have been reports of sightings of javascript errors when using Autoptimize together with WP SlimStat. Both [Camu (WP SlimStat developer)](http://profiles.wordpress.org/coolmann/) and I have installed both plugins on test-environments and [found no proof of such incompatibility](http://wordpress.org/support/topic/dropdown-menus-dont-work-when-slimstat-is-enabled?replies=14#post-4086894). Our common conclusion is that there are rare cases in which yet another theme or plugin's JavaScript are triggering these errors. If you do encounter JavaScript-errors when you have both WP SlimStat and Autoptimize installed, add "SlimStatParams, wp-slimstat.js" in the "Exclude scripts from autoptimize:" option on the admin-page and all should be well.
36
+
37
+ = Configuring & Troubleshooting Autoptimize =
38
+
39
+ After having installed and activated the plugin, you'll have access to an admin page where you can to enable HTML, CSS and JavaScript optimization. According to your liking, you can start of just enabling all of them, or if you're more cautious one at a time.
40
+
41
+ If your blog doens't function normally after having turned on Autoptimize, here are some pointers to identify & solve such issues:
42
+ * In case your blog looks weird, i.e. when the layout gets messed up, there is problem with CSS optimization. In this case you can turn on the option "Look for styles on just head?" and see if that solves the problem.
43
+ * In case some functionality on your site stops working (a carroussel, a menu, the search input, ...) you're likely hitting JavaScript optimization trouble. Enable the option "Look for scripts only in head?" and try again. Alternatively -for the technically savvy- you can exclude specific scripts from being treated (moved and/ or aggregated) by Autoptimize by adding a string that will match the offending Javascript. Identifying the offending JavaScript and choosing the correct exclusion-string can be trial and error, but in the majority of cases JavaScript optimization issues can be solved this way.
44
+ * If you can't get either CSS or JS optimization working, you can off course always continue using the other two optimization-techniques.
45
+ * If you tried the troubleshooting tips above and you still can't get CSS and JS working at all, you can ask for support on the [WordPress Autoptimize support forum](http://wordpress.org/support/plugin/autoptimize). See below for a description of what information you should provide in your "trouble ticket"
46
+
47
  = Where can I report an error? =
48
 
49
+ You can report problems on the [wordpress.org support forum](http://wordpress.org/support/plugin/autoptimize), or [contact the maintainer using this contact form](http://blog.futtta.be/contact/).
50
 
51
+ = What information should I include when requesting support =
52
+
53
+ * A description of the problem, including screenshots and information from your browser's Error/ debug console
54
+ * URL of your blog (you can turn Autoptimize off, but should be willing to turn it briefly on to have the error visible)
55
+ * your Autoptimize settings (including a description of changes you made to the configuration to try to troubleshoot yourself)
56
+ * the Theme used (including the Theme's download link)
57
+ * optionally plugins used (if you suspect one or more plugins are raising havoc)
58
 
59
  == Changelog ==
60
 
61
+ = 1.6.3 =
62
+ * fix for IE-hacks with javascript inside, causing javascript breakage (as seen in Sampression theme) as reported by [Takahiro of hiskip.com](http://www.hiskip.com/wp/)
63
+ * fix for escaping problem of imported css causing css breakage (as seen in Sampression theme) as reported by Takahiro as well
64
+ * fix to parse imports with syntax @import 'custom.css' not being parsed (as seen in Arras theme), again as reported by Takahiro
65
+ * fix for complex media types in media-attribute [as reported by jvwisssen](http://wordpress.org/support/topic/autoptimize-and-media-queries)
66
+ * fix for disappearing background-images that were already datauri's [as reported by will.blaschko](http://wordpress.org/support/topic/data-uris)
67
+ * fix not to strip out comments in HTML needed by WP Super Cache or W3 Total Cache (e.g. mfunc)
68
+ * added check to clean cache on upgrade
69
+ * updated FAQ in readme with information on troubleshooting and support
70
+ * tested with WordPress 3.6 beta
71
+
72
  = 1.6.2 =
73
  * Yet another emergency bugfix I'm afraid: apache_request_headers (again in config/delayed.php) is only available on ... Apache (duh), breaking non-Apache systems such as ngnix, Lighttpd and MS IIS badly. Reported by multiple users, thanks all!
74