Autoptimize - Version 1.4

Version Description

  • Add support for inline style tags with CSS media
  • Fix Wordpress top bar
Download this release

Release Info

Developer turl
Plugin Icon 128x128 Autoptimize
Version 1.4
Comparing to
See all releases

Code changes from version 1.3 to 1.4

autoptimize.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Autoptimize
4
  Plugin URI: http://www.turleando.com.ar/autoptimize/
5
  Description: Optimizes your website, concatenating the CSS and JavaScript code, and compressing it.
6
- Version: 1.3
7
  Author: Emilio López
8
  Author URI: http://www.turleando.com.ar/
9
  Released under the GNU General Public License (GPL)
3
  Plugin Name: Autoptimize
4
  Plugin URI: http://www.turleando.com.ar/autoptimize/
5
  Description: Optimizes your website, concatenating the CSS and JavaScript code, and compressing it.
6
+ Version: 1.4
7
  Author: Emilio López
8
  Author URI: http://www.turleando.com.ar/
9
  Released under the GNU General Public License (GPL)
classes/autoptimizeScripts.php CHANGED
@@ -3,7 +3,7 @@
3
  class autoptimizeScripts extends autoptimizeBase
4
  {
5
  private $scripts = array();
6
- private $dontmove = array('document.write','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');
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;
3
  class autoptimizeScripts extends autoptimizeBase
4
  {
5
  private $scripts = array();
6
+ private $dontmove = array('document.write','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/');
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;
classes/autoptimizeStyles.php CHANGED
@@ -36,31 +36,30 @@ class autoptimizeStyles extends autoptimizeBase
36
  {
37
  foreach($matches[0] as $tag)
38
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  if(preg_match('#<link.*href=("|\')(.*)("|\')#Usmi',$tag,$source))
40
  {
41
  //<link>
42
  $url = current(explode('?',$source[2],2));
43
  $path = $this->getpath($url);
44
- $media = array('all');
45
 
46
  if($path !==false && preg_match('#\.css$#',$path))
47
  {
48
  //Good link
49
- //Get the media
50
- if(strpos($tag,'media=')!==false)
51
- {
52
- $medias = preg_replace('#^.*media=(?:"|\')(.*)(?:"|\').*$#U','$1',$tag);
53
- $medias = explode(',',$medias);
54
- $media = array();
55
- foreach($medias as $elem)
56
- {
57
- $media[] = current(explode(' ',trim($elem),2));
58
- }
59
- }else{
60
- //No media specified - applies to all
61
- $media = array('all');
62
- }
63
-
64
  $this->css[] = array($media,$path);
65
  }else{
66
  //Link is dynamic (.php etc)
@@ -70,7 +69,7 @@ class autoptimizeStyles extends autoptimizeBase
70
  //<style>
71
  preg_match('#<style.*>(.*)</style>#Usmi',$tag,$code);
72
  $code = preg_replace('#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm','$1',$code[1]);
73
- $this->css[] = array('all','INLINE;'.$code);
74
  }
75
 
76
  //Remove the original style tag
@@ -95,23 +94,22 @@ class autoptimizeStyles extends autoptimizeBase
95
  //<style>
96
  $css = preg_replace('#^INLINE;#','',$css);
97
  $css = $this->fixurls(ABSPATH.'/index.php',$css);
98
- if(!isset($this->csscode['all']))
99
- $this->csscode['all'] = '';
100
- $this->csscode['all'] .= "\n/*FILESTART*/".$css;
101
  }else{
102
  //<link>
103
  if($css !== false && file_exists($css) && is_readable($css))
104
  {
105
  $css = $this->fixurls($css,file_get_contents($css));
106
- foreach($media as $elem)
107
- {
108
- if(!isset($this->csscode[$elem]))
109
- $this->csscode[$elem] = '';
110
- $this->csscode[$elem] .= "\n/*FILESTART*/".$css;
111
- }
112
- }/*else{
113
  //Couldn't read CSS. Maybe getpath isn't working?
114
- }*/
 
 
 
 
 
 
 
 
115
  }
116
  }
117
 
36
  {
37
  foreach($matches[0] as $tag)
38
  {
39
+ //Get the media
40
+ if(strpos($tag,'media=')!==false)
41
+ {
42
+ preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui',$tag,$medias);
43
+ $medias = explode(',',$medias[1]);
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
51
+ $media = array('all');
52
+ }
53
+
54
  if(preg_match('#<link.*href=("|\')(.*)("|\')#Usmi',$tag,$source))
55
  {
56
  //<link>
57
  $url = current(explode('?',$source[2],2));
58
  $path = $this->getpath($url);
 
59
 
60
  if($path !==false && preg_match('#\.css$#',$path))
61
  {
62
  //Good link
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  $this->css[] = array($media,$path);
64
  }else{
65
  //Link is dynamic (.php etc)
69
  //<style>
70
  preg_match('#<style.*>(.*)</style>#Usmi',$tag,$code);
71
  $code = preg_replace('#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm','$1',$code[1]);
72
+ $this->css[] = array($media,'INLINE;'.$code);
73
  }
74
 
75
  //Remove the original style tag
94
  //<style>
95
  $css = preg_replace('#^INLINE;#','',$css);
96
  $css = $this->fixurls(ABSPATH.'/index.php',$css);
 
 
 
97
  }else{
98
  //<link>
99
  if($css !== false && file_exists($css) && is_readable($css))
100
  {
101
  $css = $this->fixurls($css,file_get_contents($css));
102
+ }else{
 
 
 
 
 
 
103
  //Couldn't read CSS. Maybe getpath isn't working?
104
+ $css = '';
105
+ }
106
+ }
107
+
108
+ foreach($media as $elem)
109
+ {
110
+ if(!isset($this->csscode[$elem]))
111
+ $this->csscode[$elem] = '';
112
+ $this->csscode[$elem] .= "\n/*FILESTART*/".$css;
113
  }
114
  }
115
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: turl
3
  Donate link: http://www.turleando.com.ar/autoptimize/
4
  Tags: css, html, javascript, js, optimize, speed, cache
5
  Requires at least: 2.7
6
- Tested up to: 3.0
7
- Stable tag: 1.3
8
 
9
  Autoptimize is a Wordpress plugin that speeds up your website, and helps you save bandwidth.
10
 
@@ -38,6 +38,10 @@ Sure, you can help with translations in the [Launchpad translation page](https:/
38
 
39
  == Changelog ==
40
 
 
 
 
 
41
  = 1.3 =
42
  * Add workaround for TinyMCEComments
43
  * Add workaround for asynchronous Google Analytics
3
  Donate link: http://www.turleando.com.ar/autoptimize/
4
  Tags: css, html, javascript, js, optimize, speed, cache
5
  Requires at least: 2.7
6
+ Tested up to: 3.3.1
7
+ Stable tag: 1.4
8
 
9
  Autoptimize is a Wordpress plugin that speeds up your website, and helps you save bandwidth.
10
 
38
 
39
  == Changelog ==
40
 
41
+ = 1.4 =
42
+ * Add support for inline style tags with CSS media
43
+ * Fix Wordpress top bar
44
+
45
  = 1.3 =
46
  * Add workaround for TinyMCEComments
47
  * Add workaround for asynchronous Google Analytics