Autoptimize - Version 0.8

Version Description

  • Add workaround for Vipers Video Quicktags
  • Support tags without media.
  • Take even more precautions so we don't break urls in CSS
  • Support adding try-catch wrappings to JavaScript code
  • Add workaround for Wordpress.com Stats
  • Fix a bug in where the tags wouldn't move
  • Update translation template
  • Update Spanish translation
Download this release

Release Info

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

Code changes from version 0.7 to 0.8

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: 0.7
7
  Author: Emilio López
8
  Author URI: http://www.turleando.com.ar/
9
  Released under the GNU General Public License (GPL)
@@ -77,13 +77,13 @@ function autoptimize_end_buffering($content)
77
  //Set some options
78
  $classoptions = array(
79
  'autoptimizeScripts' => array(
80
- 'justhead' => $conf->get('autoptimize_js_justhead')
 
81
  ),
82
  'autoptimizeStyles' => array(
83
  'justhead' => $conf->get('autoptimize_css_justhead')
84
  ),
85
  'autoptimizeHTML' => array(
86
- 'justhead' => 0
87
  )
88
  );
89
 
@@ -92,7 +92,7 @@ function autoptimize_end_buffering($content)
92
  foreach($classes as $name)
93
  {
94
  $instance = new $name($content);
95
- if($instance->read($classoptions[$name]['justhead']))
96
  {
97
  $instance->minify();
98
  $instance->cache();
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: 0.8
7
  Author: Emilio López
8
  Author URI: http://www.turleando.com.ar/
9
  Released under the GNU General Public License (GPL)
77
  //Set some options
78
  $classoptions = array(
79
  'autoptimizeScripts' => array(
80
+ 'justhead' => $conf->get('autoptimize_js_justhead'),
81
+ 'trycatch' => $conf->get('autoptimize_js_trycatch')
82
  ),
83
  'autoptimizeStyles' => array(
84
  'justhead' => $conf->get('autoptimize_css_justhead')
85
  ),
86
  'autoptimizeHTML' => array(
 
87
  )
88
  );
89
 
92
  foreach($classes as $name)
93
  {
94
  $instance = new $name($content);
95
+ if($instance->read($classoptions[$name]))
96
  {
97
  $instance->minify();
98
  $instance->cache();
classes/autoptimizeConfig.php CHANGED
@@ -65,6 +65,11 @@ class autoptimizeConfig
65
  <td><label for="autoptimize_js_justhead"><input type="checkbox" name="autoptimize_js_justhead" <?php echo get_option('autoptimize_js_justhead')?'checked="checked" ':''; ?>/>
66
  <?php _e('Disabled by default. If the cache gets big, you might want to enable this.','autoptimize'); ?></label></td>
67
  </tr>
 
 
 
 
 
68
  </table>
69
 
70
  <h3><?php _e('CSS Options','autoptimize'); ?></h3>
@@ -100,6 +105,7 @@ class autoptimizeConfig
100
  {
101
  register_setting('autoptimize','autoptimize_html');
102
  register_setting('autoptimize','autoptimize_js');
 
103
  register_setting('autoptimize','autoptimize_js_justhead');
104
  register_setting('autoptimize','autoptimize_css');
105
  register_setting('autoptimize','autoptimize_css_justhead');
@@ -139,6 +145,7 @@ class autoptimizeConfig
139
  //Default config
140
  $config = array('autoptimize_html' => 0,
141
  'autoptimize_js' => 0,
 
142
  'autoptimize_js_justhead' => 0,
143
  'autoptimize_css' => 0,
144
  'autoptimize_css_justhead' => 0);
65
  <td><label for="autoptimize_js_justhead"><input type="checkbox" name="autoptimize_js_justhead" <?php echo get_option('autoptimize_js_justhead')?'checked="checked" ':''; ?>/>
66
  <?php _e('Disabled by default. If the cache gets big, you might want to enable this.','autoptimize'); ?></label></td>
67
  </tr>
68
+ <tr valign="top">
69
+ <th scope="row"><?php _e('Add try-catch wrapping?','autoptimize'); ?></th>
70
+ <td><label for="autoptimize_js_trycatch"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo get_option('autoptimize_js_trycatch')?'checked="checked" ':''; ?>/>
71
+ <?php _e('Disabled by default. If your scripts break because of an script error, you might want to try this.','autoptimize'); ?></label></td>
72
+ </tr>
73
  </table>
74
 
75
  <h3><?php _e('CSS Options','autoptimize'); ?></h3>
105
  {
106
  register_setting('autoptimize','autoptimize_html');
107
  register_setting('autoptimize','autoptimize_js');
108
+ register_setting('autoptimize','autoptimize_js_trycatch');
109
  register_setting('autoptimize','autoptimize_js_justhead');
110
  register_setting('autoptimize','autoptimize_css');
111
  register_setting('autoptimize','autoptimize_css_justhead');
145
  //Default config
146
  $config = array('autoptimize_html' => 0,
147
  'autoptimize_js' => 0,
148
+ 'autoptimize_js_trycatch' => 0,
149
  'autoptimize_js_justhead' => 0,
150
  'autoptimize_css' => 0,
151
  'autoptimize_css_justhead' => 0);
classes/autoptimizeScripts.php CHANGED
@@ -3,25 +3,30 @@
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/');
7
- private $domove = array('gaJsHost');
8
  private $domovelast = array('addthis.com','/afsonline/show_afs_search.js','disqus.js');
 
9
  private $jscode = '';
10
  private $url = '';
11
  private $move = array('first' => array(), 'last' => array());
12
  private $restofcontent = '';
13
 
14
  //Reads the page and collects script tags
15
- public function read($justhead)
16
  {
17
  //Remove everything that's not the header
18
- if($justhead == true)
19
  {
20
  $content = explode('</head>',$this->content,2);
21
  $this->content = $content[0].'</head>';
22
  $this->restofcontent = $content[1];
23
  }
24
 
 
 
 
 
25
  //Get script files
26
  if(preg_match_all('#<script.*</script>#Usmi',$this->content,$matches))
27
  {
@@ -64,7 +69,12 @@ class autoptimizeScripts extends autoptimizeBase
64
  //Can we move this?
65
  if($this->ismovable($tag))
66
  {
67
- $this->move[] = $tag;
 
 
 
 
 
68
  }else{
69
  //We shouldn't touch this
70
  $tag = '';
@@ -92,12 +102,18 @@ class autoptimizeScripts extends autoptimizeBase
92
  {
93
  //Inline script
94
  $script = preg_replace('#^INLINE;#','',$script);
 
 
 
95
  $this->jscode .= "\n".$script;
96
  }else{
97
  //External script
98
  if($script !== false && file_exists($script) && is_readable($script))
99
  {
100
  $script = file_get_contents($script);
 
 
 
101
  $this->jscode .= "\n".$script;
102
  }/*else{
103
  //Couldn't read JS. Maybe getpath isn't working?
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/','swfobject.embedSWF(');
7
+ private $domove = array('gaJsHost','load_cmc');
8
  private $domovelast = array('addthis.com','/afsonline/show_afs_search.js','disqus.js');
9
+ private $trycatch = false;
10
  private $jscode = '';
11
  private $url = '';
12
  private $move = array('first' => array(), 'last' => array());
13
  private $restofcontent = '';
14
 
15
  //Reads the page and collects script tags
16
+ public function read($options)
17
  {
18
  //Remove everything that's not the header
19
+ if($options['justhead'] == true)
20
  {
21
  $content = explode('</head>',$this->content,2);
22
  $this->content = $content[0].'</head>';
23
  $this->restofcontent = $content[1];
24
  }
25
 
26
+ //Should we add try-catch?
27
+ if($options['trycatch'] == true)
28
+ $this->trycatch = true;
29
+
30
  //Get script files
31
  if(preg_match_all('#<script.*</script>#Usmi',$this->content,$matches))
32
  {
69
  //Can we move this?
70
  if($this->ismovable($tag))
71
  {
72
+ if($this->movetolast($tag))
73
+ {
74
+ $this->move['last'][] = $tag;
75
+ }else{
76
+ $this->move['first'][] = $tag;
77
+ }
78
  }else{
79
  //We shouldn't touch this
80
  $tag = '';
102
  {
103
  //Inline script
104
  $script = preg_replace('#^INLINE;#','',$script);
105
+ //Add try-catch?
106
+ if($this->trycatch)
107
+ $script = 'try{'.$script.'}catch(e){}';
108
  $this->jscode .= "\n".$script;
109
  }else{
110
  //External script
111
  if($script !== false && file_exists($script) && is_readable($script))
112
  {
113
  $script = file_get_contents($script);
114
+ //Add try-catch?
115
+ if($this->trycatch)
116
+ $script = 'try{'.$script.'}catch(e){}';
117
  $this->jscode .= "\n".$script;
118
  }/*else{
119
  //Couldn't read JS. Maybe getpath isn't working?
classes/autoptimizeStyles.php CHANGED
@@ -7,10 +7,10 @@ class autoptimizeStyles extends autoptimizeBase
7
  private $restofcontent = '';
8
 
9
  //Reads the page and collects style tags
10
- public function read($justhead)
11
  {
12
  //Remove everything that's not the header
13
- if($justhead == true)
14
  {
15
  $content = explode('</head>',$this->content,2);
16
  $this->content = $content[0].'</head>';
@@ -46,6 +46,9 @@ class autoptimizeStyles extends autoptimizeBase
46
  {
47
  $media[] = current(explode(' ',trim($elem),2));
48
  }
 
 
 
49
  }
50
 
51
  $this->css[] = array($media,$path);
@@ -228,7 +231,7 @@ class autoptimizeStyles extends autoptimizeBase
228
  if(preg_match_all('#url\((.*)\)#Usi',$code,$matches))
229
  {
230
  $replace = array();
231
- foreach($matches[1] as $url)
232
  {
233
  //Remove quotes
234
  $url = trim($url," \t\n\r\0\x0B\"'");
@@ -239,7 +242,9 @@ class autoptimizeStyles extends autoptimizeBase
239
  }else{
240
  //relative URL. Let's fix it!
241
  $newurl = get_settings('home').str_replace('//','/',$dir.'/'.$url); //http://yourblog.com/wp-content/../image.png
242
- $replace[$url] = $newurl;
 
 
243
  }
244
  }
245
 
7
  private $restofcontent = '';
8
 
9
  //Reads the page and collects style tags
10
+ public function read($options)
11
  {
12
  //Remove everything that's not the header
13
+ if($options['justhead'] == true)
14
  {
15
  $content = explode('</head>',$this->content,2);
16
  $this->content = $content[0].'</head>';
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
  $this->css[] = array($media,$path);
231
  if(preg_match_all('#url\((.*)\)#Usi',$code,$matches))
232
  {
233
  $replace = array();
234
+ foreach($matches[1] as $k => $url)
235
  {
236
  //Remove quotes
237
  $url = trim($url," \t\n\r\0\x0B\"'");
242
  }else{
243
  //relative URL. Let's fix it!
244
  $newurl = get_settings('home').str_replace('//','/',$dir.'/'.$url); //http://yourblog.com/wp-content/../image.png
245
+ $hash = md5($url);
246
+ $code = str_replace($matches[0][$k],$hash,$code);
247
+ $replace[$hash] = 'url('.$newurl.')';
248
  }
249
  }
250
 
localization/autoptimize-es_ES.mo CHANGED
Binary file
localization/autoptimize-es_ES.po CHANGED
@@ -7,14 +7,14 @@ msgid ""
7
  msgstr ""
8
  "Project-Id-Version: autoptimize\n"
9
  "Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
10
- "POT-Creation-Date: 2009-07-12 03:12+0000\n"
11
- "PO-Revision-Date: 2009-07-12 18:20+0000\n"
12
  "Last-Translator: Emilio <Unknown>\n"
13
  "Language-Team: Spanish <es@li.org>\n"
14
  "MIME-Version: 1.0\n"
15
  "Content-Type: text/plain; charset=UTF-8\n"
16
  "Content-Transfer-Encoding: 8bit\n"
17
- "X-Launchpad-Export-Date: 2009-07-12 19:28+0000\n"
18
  "X-Generator: Launchpad (build Unknown)\n"
19
 
20
  #: classes/autoptimizeConfig.php:44
@@ -41,34 +41,46 @@ msgstr "¿Optimizar el código JavaScript?"
41
  msgid "Look for scripts only in &lt;head&gt;?"
42
  msgstr "¿Buscar scripts solo en &lt;head&gt;?"
43
 
44
- #: classes/autoptimizeConfig.php:66 classes/autoptimizeConfig.php:79
45
  msgid ""
46
  "Disabled by default. If the cache gets big, you might want to enable this."
47
  msgstr ""
48
- "Deshabilitado por defecto. Si el cache se hace grande, tal vez quieras "
49
  "habilitar esto."
50
 
51
- #: classes/autoptimizeConfig.php:70
 
 
 
 
 
 
 
 
 
 
 
 
52
  msgid "CSS Options"
53
  msgstr "Opciones de CSS"
54
 
55
- #: classes/autoptimizeConfig.php:73
56
  msgid "Optimize CSS Code?"
57
  msgstr "¿Optimizar el código CSS?"
58
 
59
- #: classes/autoptimizeConfig.php:77
60
  msgid "Look for styles on just &lt;head&gt;?"
61
  msgstr "¿Buscar estilos solo en &lt;head&gt;?"
62
 
63
- #: classes/autoptimizeConfig.php:86
64
  msgid "Save Changes"
65
  msgstr "Guardar Cambios"
66
 
67
- #: classes/autoptimizeConfig.php:96
68
  msgid "Autoptimize Options"
69
  msgstr "Configuración de Autoptimize"
70
 
71
- #: classes/autoptimizeConfig.php:120 classes/autoptimizeConfig.php:127
72
  msgid "Settings"
73
  msgstr "Configuración"
74
 
7
  msgstr ""
8
  "Project-Id-Version: autoptimize\n"
9
  "Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
10
+ "POT-Creation-Date: 2009-07-21 03:53+0000\n"
11
+ "PO-Revision-Date: 2009-07-21 18:55+0000\n"
12
  "Last-Translator: Emilio <Unknown>\n"
13
  "Language-Team: Spanish <es@li.org>\n"
14
  "MIME-Version: 1.0\n"
15
  "Content-Type: text/plain; charset=UTF-8\n"
16
  "Content-Transfer-Encoding: 8bit\n"
17
+ "X-Launchpad-Export-Date: 2009-07-21 19:00+0000\n"
18
  "X-Generator: Launchpad (build Unknown)\n"
19
 
20
  #: classes/autoptimizeConfig.php:44
41
  msgid "Look for scripts only in &lt;head&gt;?"
42
  msgstr "¿Buscar scripts solo en &lt;head&gt;?"
43
 
44
+ #: classes/autoptimizeConfig.php:66 classes/autoptimizeConfig.php:84
45
  msgid ""
46
  "Disabled by default. If the cache gets big, you might want to enable this."
47
  msgstr ""
48
+ "Deshabilitado por defecto. Si el cache se hace grande, tal vez quiera "
49
  "habilitar esto."
50
 
51
+ #: classes/autoptimizeConfig.php:69
52
+ msgid "Add try-catch wrapping?"
53
+ msgstr "¿Añadir envolturas try-catch?"
54
+
55
+ #: classes/autoptimizeConfig.php:71
56
+ msgid ""
57
+ "Disabled by default. If your scripts break because of an script error, you "
58
+ "might want to try this."
59
+ msgstr ""
60
+ "Deshabilitado por defecto. Si sus scripts dejan de funcionar por un error de "
61
+ "scripting, tal vez quiera probar esto."
62
+
63
+ #: classes/autoptimizeConfig.php:75
64
  msgid "CSS Options"
65
  msgstr "Opciones de CSS"
66
 
67
+ #: classes/autoptimizeConfig.php:78
68
  msgid "Optimize CSS Code?"
69
  msgstr "¿Optimizar el código CSS?"
70
 
71
+ #: classes/autoptimizeConfig.php:82
72
  msgid "Look for styles on just &lt;head&gt;?"
73
  msgstr "¿Buscar estilos solo en &lt;head&gt;?"
74
 
75
+ #: classes/autoptimizeConfig.php:91
76
  msgid "Save Changes"
77
  msgstr "Guardar Cambios"
78
 
79
+ #: classes/autoptimizeConfig.php:101
80
  msgid "Autoptimize Options"
81
  msgstr "Configuración de Autoptimize"
82
 
83
+ #: classes/autoptimizeConfig.php:126 classes/autoptimizeConfig.php:133
84
  msgid "Settings"
85
  msgstr "Configuración"
86
 
localization/autoptimize.pot CHANGED
@@ -8,7 +8,7 @@ msgid ""
8
  msgstr ""
9
  "Project-Id-Version: PACKAGE VERSION\n"
10
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/autoptimize\n"
11
- "POT-Creation-Date: 2009-07-12 03:12+0000\n"
12
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
  "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -40,32 +40,42 @@ msgstr ""
40
  msgid "Look for scripts only in &lt;head&gt;?"
41
  msgstr ""
42
 
43
- #: classes/autoptimizeConfig.php:66 classes/autoptimizeConfig.php:79
44
  msgid ""
45
  "Disabled by default. If the cache gets big, you might want to enable this."
46
  msgstr ""
47
 
48
- #: classes/autoptimizeConfig.php:70
 
 
 
 
 
 
 
 
 
 
49
  msgid "CSS Options"
50
  msgstr ""
51
 
52
- #: classes/autoptimizeConfig.php:73
53
  msgid "Optimize CSS Code?"
54
  msgstr ""
55
 
56
- #: classes/autoptimizeConfig.php:77
57
  msgid "Look for styles on just &lt;head&gt;?"
58
  msgstr ""
59
 
60
- #: classes/autoptimizeConfig.php:86
61
  msgid "Save Changes"
62
  msgstr ""
63
 
64
- #: classes/autoptimizeConfig.php:96
65
  msgid "Autoptimize Options"
66
  msgstr ""
67
 
68
- #: classes/autoptimizeConfig.php:120 classes/autoptimizeConfig.php:127
69
  msgid "Settings"
70
  msgstr ""
71
 
@@ -78,4 +88,3 @@ msgid ""
78
  "Optimizes your website, concatenating the CSS and JavaScript code, and "
79
  "compressing it."
80
  msgstr ""
81
-
8
  msgstr ""
9
  "Project-Id-Version: PACKAGE VERSION\n"
10
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/autoptimize\n"
11
+ "POT-Creation-Date: 2009-07-21 03:53+0000\n"
12
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
  "Language-Team: LANGUAGE <LL@li.org>\n"
40
  msgid "Look for scripts only in &lt;head&gt;?"
41
  msgstr ""
42
 
43
+ #: classes/autoptimizeConfig.php:66 classes/autoptimizeConfig.php:84
44
  msgid ""
45
  "Disabled by default. If the cache gets big, you might want to enable this."
46
  msgstr ""
47
 
48
+ #: classes/autoptimizeConfig.php:69
49
+ msgid "Add try-catch wrapping?"
50
+ msgstr ""
51
+
52
+ #: classes/autoptimizeConfig.php:71
53
+ msgid ""
54
+ "Disabled by default. If your scripts break because of an script error, you "
55
+ "might want to try this."
56
+ msgstr ""
57
+
58
+ #: classes/autoptimizeConfig.php:75
59
  msgid "CSS Options"
60
  msgstr ""
61
 
62
+ #: classes/autoptimizeConfig.php:78
63
  msgid "Optimize CSS Code?"
64
  msgstr ""
65
 
66
+ #: classes/autoptimizeConfig.php:82
67
  msgid "Look for styles on just &lt;head&gt;?"
68
  msgstr ""
69
 
70
+ #: classes/autoptimizeConfig.php:91
71
  msgid "Save Changes"
72
  msgstr ""
73
 
74
+ #: classes/autoptimizeConfig.php:101
75
  msgid "Autoptimize Options"
76
  msgstr ""
77
 
78
+ #: classes/autoptimizeConfig.php:126 classes/autoptimizeConfig.php:133
79
  msgid "Settings"
80
  msgstr ""
81
 
88
  "Optimizes your website, concatenating the CSS and JavaScript code, and "
89
  "compressing it."
90
  msgstr ""
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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: 2.8.1
7
- Stable tag: 0.7
8
 
9
  Autoptimize is a Wordpress plugin that speeds up your website, and helps you save bandwidth.
10
 
@@ -38,6 +38,16 @@ Sure, you can help with translations in the [Launchpad translation page](https:/
38
 
39
  == Changelog ==
40
 
 
 
 
 
 
 
 
 
 
 
41
  = 0.7 =
42
  * Add fix for DISQUS Comment System.
43
 
4
  Tags: css, html, javascript, js, optimize, speed, cache
5
  Requires at least: 2.7
6
  Tested up to: 2.8.1
7
+ Stable tag: 0.8
8
 
9
  Autoptimize is a Wordpress plugin that speeds up your website, and helps you save bandwidth.
10
 
38
 
39
  == Changelog ==
40
 
41
+ = 0.8 =
42
+ * Add workaround for Vipers Video Quicktags
43
+ * Support <link> tags without media.
44
+ * Take even more precautions so we don't break urls in CSS
45
+ * Support adding try-catch wrappings to JavaScript code
46
+ * Add workaround for Wordpress.com Stats
47
+ * Fix a bug in where the tags wouldn't move
48
+ * Update translation template
49
+ * Update Spanish translation
50
+
51
  = 0.7 =
52
  * Add fix for DISQUS Comment System.
53