SG Optimizer - Version 5.7.7

Version Description

Download this release

Release Info

Developer sstoqnov
Plugin Icon 128x128 SG Optimizer
Version 5.7.7
Comparing to
See all releases

Code changes from version 5.7.6 to 5.7.7

core/Cli/Cli_Purge.php CHANGED
@@ -46,6 +46,7 @@ class Cli_Purge {
46
  */
47
  public function purge_everything() {
48
  $response = $this->supercacher->purge_everything();
 
49
  $this->supercacher->delete_assets();
50
 
51
  if ( true == $response ) {
46
  */
47
  public function purge_everything() {
48
  $response = $this->supercacher->purge_everything();
49
+
50
  $this->supercacher->delete_assets();
51
 
52
  if ( true == $response ) {
core/Minifier/Minifier.php CHANGED
@@ -313,21 +313,25 @@ class Minifier {
313
  return $html;
314
  }
315
 
316
- return self::minify_html( $html );
317
- }
 
 
318
 
319
- /**
320
- * Minify the html output.
321
- *
322
- * @since 5.0.0
323
- *
324
- * @param string $buffer The page content.
325
- *
326
- * @return string Minified content.
327
- */
328
- public function minify_html( $buffer ) {
329
- $content = Minify_Html::minify( $buffer );
330
- return $content;
 
 
331
  }
332
 
333
  /**
313
  return $html;
314
  }
315
 
316
+ $descriptorspec = array(
317
+ 0 => array( 'pipe', 'r' ), // stdin is a pipe that the child will read from.
318
+ 1 => array( 'pipe', 'w' ), // stdout is a pipe that the child will write to.
319
+ );
320
 
321
+ $process = proc_open( '/usr/local/bin/minify --type=html', $descriptorspec, $pipes );
322
+
323
+ if ( is_resource( $process ) ) {
324
+ fwrite( $pipes[0], $html );
325
+ fclose( $pipes[0] );
326
+
327
+ $output = stream_get_contents( $pipes[1] );
328
+ fclose( $pipes[1] );
329
+
330
+ // Close any pipes before calling proc_close in order to avoid a deadlock.
331
+ $return_value = proc_close( $process );
332
+ }
333
+
334
+ return $output;
335
  }
336
 
337
  /**
core/Minifier/Minify_Html.php DELETED
@@ -1,256 +0,0 @@
1
- <?php
2
-
3
- namespace SiteGround_Optimizer\Minifier;
4
-
5
- /**
6
- * Compress HTML
7
- *
8
- * This is a heavy regex-based removal of whitespace, unnecessary comments and
9
- * tokens. IE conditional comments are preserved. There are also options to have
10
- * STYLE and SCRIPT blocks compressed by callback functions.
11
- *
12
- * A test suite is available.
13
- *
14
- * @package Minify
15
- * @author Stephen Clay <steve@mrclay.org>
16
- */
17
- class Minify_Html {
18
-
19
- /**
20
- * "Minify" an HTML page
21
- *
22
- * @param string $html
23
- *
24
- * @param array $options
25
- *
26
- * 'cssMinifier' : (optional) callback function to process content of STYLE
27
- * elements.
28
- *
29
- * 'jsMinifier' : (optional) callback function to process content of SCRIPT
30
- * elements. Note: the type attribute is ignored.
31
- *
32
- * 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
33
- * unset, minify will sniff for an XHTML doctype.
34
- *
35
- * 'keepComments' : (optional boolean) should the HTML comments be kept
36
- * in the HTML Code?
37
- *
38
- * @return string
39
- */
40
- public static function minify($html, $options = array()) {
41
- $min = new Minify_Html($html, $options);
42
- return $min->process();
43
- }
44
-
45
-
46
- /**
47
- * Create a minifier object
48
- *
49
- * @param string $html
50
- *
51
- * @param array $options
52
- *
53
- * 'cssMinifier' : (optional) callback function to process content of STYLE
54
- * elements.
55
- *
56
- * 'jsMinifier' : (optional) callback function to process content of SCRIPT
57
- * elements. Note: the type attribute is ignored.
58
- *
59
- * 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
60
- * unset, minify will sniff for an XHTML doctype.
61
- *
62
- * 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
63
- * unset, minify will sniff for an XHTML doctype.
64
- *
65
- * @return null
66
- */
67
- public function __construct($html, $options = array())
68
- {
69
- $this->_html = str_replace("\r\n", "\n", trim($html));
70
- if (isset($options['xhtml'])) {
71
- $this->_isXhtml = (bool)$options['xhtml'];
72
- }
73
- if (isset($options['cssMinifier'])) {
74
- $this->_cssMinifier = $options['cssMinifier'];
75
- }
76
- if (isset($options['jsMinifier'])) {
77
- $this->_jsMinifier = $options['jsMinifier'];
78
- }
79
- if (isset($options['keepComments'])) {
80
- $this->_keepComments = $options['keepComments'];
81
- }
82
- }
83
-
84
-
85
- /**
86
- * Minify the markeup given in the constructor
87
- *
88
- * @return string
89
- */
90
- public function process()
91
- {
92
- if ($this->_isXhtml === null) {
93
- $this->_isXhtml = (false !== @strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
94
- }
95
-
96
- $this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
97
- $this->_placeholders = array();
98
-
99
- // remove HTML comments (not containing IE conditional comments).
100
- if ($this->_keepComments == false) {
101
- $this->_html = preg_replace_callback(
102
- '/<!--([\\s\\S]*?)-->/'
103
- ,array($this, '_commentCB')
104
- ,$this->_html);
105
- }
106
-
107
- // replace PREs with placeholders
108
- $this->_html = preg_replace_callback('/\\s*(<pre\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i'
109
- ,array($this, '_removePreCB')
110
- ,$this->_html);
111
-
112
- // replace TEXTAREAs with placeholders
113
- $this->_html = preg_replace_callback(
114
- '/\\s*(<textarea\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i'
115
- ,array($this, '_removeTextareaCB')
116
- ,$this->_html);
117
-
118
- // replace data: URIs with placeholders
119
- $this->_html = preg_replace_callback(
120
- '/(=("|\')data:.*\\2)/Ui'
121
- ,array($this, '_removeDataURICB')
122
- ,$this->_html);
123
-
124
- // trim each line.
125
- // replace by space instead of '' to avoid newline after opening tag getting zapped
126
- $this->_html = preg_replace('/^\s+|\s+$/m', ' ', $this->_html);
127
-
128
- // remove ws around block/undisplayed elements
129
- $this->_html = preg_replace('/\\s+(<\\/?(?:area|article|aside|base(?:font)?|blockquote|body'
130
- .'|canvas|caption|center|col(?:group)?|dd|dir|div|dl|dt|fieldset|figcaption|figure|footer|form'
131
- .'|frame(?:set)?|h[1-6]|head|header|hgroup|hr|html|legend|li|link|main|map|menu|meta|nav'
132
- .'|ol|opt(?:group|ion)|output|p|param|section|t(?:able|body|head|d|h||r|foot|itle)'
133
- .'|ul|video)\\b[^>]*>)/i', '$1', $this->_html);
134
-
135
- // remove ws outside of all elements
136
- $this->_html = preg_replace_callback(
137
- '/>([^<]+)</'
138
- ,array($this, '_outsideTagCB')
139
- ,$this->_html);
140
-
141
- // use newlines before 1st attribute in open tags (to limit line lengths)
142
- //$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html);
143
-
144
- // fill placeholders
145
- $this->_html = str_replace(
146
- array_keys($this->_placeholders)
147
- ,array_values($this->_placeholders)
148
- ,$this->_html
149
- );
150
- return $this->_html;
151
- }
152
-
153
- protected function _commentCB($m)
154
- {
155
- return (0 === @strpos($m[1], '[') || false !== @strpos($m[1], '<!['))
156
- ? $m[0]
157
- : '';
158
- }
159
-
160
- protected function _reservePlace($content)
161
- {
162
- $placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%';
163
- $this->_placeholders[$placeholder] = $content;
164
- return $placeholder;
165
- }
166
-
167
- protected $_isXhtml = null;
168
- protected $_replacementHash = null;
169
- protected $_placeholders = array();
170
- protected $_cssMinifier = null;
171
- protected $_jsMinifier = null;
172
- protected $_keepComments = true;
173
-
174
- protected function _outsideTagCB($m)
175
- {
176
- return '>' . preg_replace('/^\\s+|\\s+$/', ' ', $m[1]) . '<';
177
- }
178
-
179
- protected function _removePreCB($m)
180
- {
181
- return $this->_reservePlace($m[1]);
182
- }
183
-
184
- protected function _removeTextareaCB($m)
185
- {
186
- return $this->_reservePlace($m[1]);
187
- }
188
-
189
- protected function _removeDataURICB($m)
190
- {
191
- return $this->_reservePlace($m[1]);
192
- }
193
-
194
- protected function _removeStyleCB($m)
195
- {
196
- $openStyle = $m[1];
197
- $css = $m[2];
198
- // remove HTML comments
199
- $css = preg_replace('/(?:^\\s*<!--|-->\\s*$)/', '', $css);
200
-
201
- // remove CDATA section markers
202
- $css = $this->_removeCdata($css);
203
-
204
- // minify
205
- $minifier = $this->_cssMinifier
206
- ? $this->_cssMinifier
207
- : 'trim';
208
- $css = call_user_func($minifier, $css);
209
-
210
- return $this->_reservePlace($this->_needsCdata($css)
211
- ? "{$openStyle}/*<![CDATA[*/{$css}/*]]>*/</style>"
212
- : "{$openStyle}{$css}</style>"
213
- );
214
- }
215
-
216
- protected function _removeScriptCB($m)
217
- {
218
- $openScript = $m[2];
219
- $js = $m[3];
220
-
221
- // whitespace surrounding? preserve at least one space
222
- $ws1 = ($m[1] === '') ? '' : ' ';
223
- $ws2 = ($m[4] === '') ? '' : ' ';
224
-
225
- if ($this->_keepComments == false) {
226
- // remove HTML comments (and ending "//" if present)
227
- $js = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $js);
228
-
229
- // remove CDATA section markers
230
- $js = $this->_removeCdata($js);
231
- }
232
-
233
- // minify
234
- $minifier = $this->_jsMinifier
235
- ? $this->_jsMinifier
236
- : 'trim';
237
- $js = call_user_func($minifier, $js);
238
-
239
- return $this->_reservePlace($this->_needsCdata($js)
240
- ? "{$ws1}{$openScript}/*<![CDATA[*/{$js}/*]]>*/</script>{$ws2}"
241
- : "{$ws1}{$openScript}{$js}</script>{$ws2}"
242
- );
243
- }
244
-
245
- protected function _removeCdata($str)
246
- {
247
- return (false !== @strpos($str, '<![CDATA['))
248
- ? str_replace(array('/* <![CDATA[ */','/* ]]> */','/*<![CDATA[*/','/*]]>*/','<![CDATA[', ']]>'), '', $str)
249
- : $str;
250
- }
251
-
252
- protected function _needsCdata($str)
253
- {
254
- return ($this->_isXhtml && preg_match('/(?:[<&]|\\-\\-|\\]\\]>)/', $str));
255
- }
256
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
core/Supercacher/Supercacher_Helper.php CHANGED
@@ -146,6 +146,13 @@ class Supercacher_Helper {
146
  * @return boolean True if the url matches an excluded type, false otherwise.
147
  */
148
  public static function is_post_type_excluded( $url ) {
 
 
 
 
 
 
 
149
 
150
  // We don't want to cache page builder edit page.
151
  if ( Front_End_Optimization::get_instance()->check_for_builders() ) {
@@ -165,14 +172,6 @@ class Supercacher_Helper {
165
  return false;
166
  }
167
 
168
- // Get excluded post_types.
169
- $post_types = \get_option( 'siteground_optimizer_post_types_exclude', array() );
170
-
171
- // Bail if there are no excluded post types.
172
- if ( empty( $post_types ) ) {
173
- return false;
174
- }
175
-
176
  // Get the post type.
177
  $post_type = get_post_type( $post_id );
178
 
146
  * @return boolean True if the url matches an excluded type, false otherwise.
147
  */
148
  public static function is_post_type_excluded( $url ) {
149
+ // Get excluded post_types.
150
+ $post_types = \get_option( 'siteground_optimizer_post_types_exclude', array() );
151
+
152
+ // Bail if there are no excluded post types.
153
+ if ( empty( $post_types ) ) {
154
+ return false;
155
+ }
156
 
157
  // We don't want to cache page builder edit page.
158
  if ( Front_End_Optimization::get_instance()->check_for_builders() ) {
172
  return false;
173
  }
174
 
 
 
 
 
 
 
 
 
175
  // Get the post type.
176
  $post_type = get_post_type( $post_id );
177
 
readme.txt CHANGED
@@ -212,6 +212,9 @@ Our plugin uses a cookie in order to function properly. It does not store person
212
 
213
  == Changelog ==
214
 
 
 
 
215
  = Version 5.7.6 =
216
  * Improved cache flush, on automatic assets deletion
217
 
212
 
213
  == Changelog ==
214
 
215
+ = Version 5.7.7 =
216
+ * HTML Minification Refactoring
217
+
218
  = Version 5.7.6 =
219
  * Improved cache flush, on automatic assets deletion
220
 
sg-cachepress.php CHANGED
@@ -10,7 +10,7 @@
10
  * Plugin Name: SG Optimizer
11
  * Plugin URI: https://siteground.com
12
  * Description: This plugin will link your WordPress application with all the performance optimizations provided by SiteGround
13
- * Version: 5.7.6
14
  * Author: SiteGround
15
  * Author URI: https://www.siteground.com
16
  * Text Domain: sg-cachepress
@@ -31,7 +31,7 @@ if ( ! defined( 'WPINC' ) ) {
31
 
32
  // Define version constant.
33
  if ( ! defined( __NAMESPACE__ . '\VERSION' ) ) {
34
- define( __NAMESPACE__ . '\VERSION', '5.7.6' );
35
  }
36
 
37
  // Define slug constant.
10
  * Plugin Name: SG Optimizer
11
  * Plugin URI: https://siteground.com
12
  * Description: This plugin will link your WordPress application with all the performance optimizations provided by SiteGround
13
+ * Version: 5.7.7
14
  * Author: SiteGround
15
  * Author URI: https://www.siteground.com
16
  * Text Domain: sg-cachepress
31
 
32
  // Define version constant.
33
  if ( ! defined( __NAMESPACE__ . '\VERSION' ) ) {
34
+ define( __NAMESPACE__ . '\VERSION', '5.7.7' );
35
  }
36
 
37
  // Define slug constant.