Breeze – WordPress Cache Plugin - Version 1.1.0

Version Description

  • Add: Optional separate cache settings for subsites.
Download this release

Release Info

Developer adeelkhan
Plugin Icon 128x128 Breeze – WordPress Cache Plugin
Version 1.1.0
Comparing to
See all releases

Code changes from version 1.0.13 to 1.1.0

assets/css/style.css CHANGED
@@ -25,6 +25,85 @@
25
  color: #000;
26
  }
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  #breeze-tabs {
29
  border-bottom: none;
30
  }
@@ -69,6 +148,20 @@
69
  display: block;
70
  }
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  /*Table*/
73
  #breeze-tabs-content table tr td:first-child {
74
  width: 20%;
@@ -231,4 +324,4 @@
231
  #breeze-and-cloudways .rs-content button a {
232
  color: #fff;
233
  text-decoration: none;
234
- }
25
  color: #000;
26
  }
27
 
28
+ #breeze-inherit-settings-toggle .radio-field {
29
+ margin-bottom: 20px;
30
+ }
31
+ #breeze-inherit-settings-toggle .radio-field input,
32
+ #breeze-inherit-settings-toggle .radio-field strong {
33
+ vertical-align: bottom;
34
+ }
35
+ #breeze-inherit-settings-toggle.loading .radio-field {
36
+ opacity: 0.4;
37
+ pointer-events: none;
38
+ }
39
+ #breeze-inherit-settings-toggle label {
40
+ display: block;
41
+ margin-bottom: 5px;
42
+ }
43
+ #breeze-inherit-settings-toggle .radio-field strong {
44
+ font-weight: 500;
45
+ }
46
+ #breeze-inherit-settings-toggle .radio-field.active strong:after {
47
+ content: ' [ACTIVE]';
48
+ font-weight: bold;
49
+ }
50
+ #breeze-inherit-settings-toggle small {
51
+ display: block;
52
+ font-size: inherit;
53
+ margin-left: 24px;
54
+ max-width: 804px;
55
+ }
56
+ #breeze-inherit-settings-toggle p.disclaimer {
57
+ display: none;
58
+ color: #ff0000;
59
+ }
60
+
61
+ #breeze-tabs.tabs-hidden .nav-tab.inactive,
62
+ #breeze-tabs.tabs-hidden .nav-tab.inactive:not(.active):hover {
63
+ color: #888;
64
+ background: #f4f4f4;
65
+ }
66
+
67
+ #breeze-tabs-content.tabs-hidden .tab-pane.inactive,
68
+ #breeze-tabs-content.tabs-hidden .tab-pane.inactive .tab-child {
69
+ min-height: 180px;
70
+ position: relative;
71
+ }
72
+ #breeze-tabs-content.tabs-hidden .tab-pane.inactive .tab-child:after {
73
+ content: '';
74
+ position: absolute;
75
+ top: 0;
76
+ left: 0;
77
+ right: 0;
78
+ bottom: 0;
79
+ background-color: #fff;
80
+ background-color: rgba( 255, 255, 255, 0.95 );
81
+ }
82
+ #breeze-tabs-content .tab-pane .hidden-text {
83
+ display: none;
84
+ }
85
+ #breeze-tabs-content.tabs-hidden .tab-pane.inactive .hidden-text {
86
+ position: absolute;
87
+ top: 100px;
88
+ left: 0;
89
+ right: 0;
90
+ text-align: center;
91
+ color: #ff0000;
92
+ display: block;
93
+ }
94
+ #tab-content-database .tab-child {
95
+ padding-bottom: 0;
96
+ }
97
+ #breeze-database-optimize {
98
+ margin-top: 5px;
99
+ }
100
+ #breeze-database-optimize[disabled] {
101
+ color: #fff !important;
102
+ border-color: #ddd !important;
103
+ background-color: #e0e0e0 !important;
104
+ text-shadow: none !important;
105
+ }
106
+
107
  #breeze-tabs {
108
  border-bottom: none;
109
  }
148
  display: block;
149
  }
150
 
151
+ .breeze-form .multisite-inherit-disclaimer {
152
+ margin-top: 35px;
153
+ margin-bottom: 0;
154
+ color: #ff0000;
155
+ }
156
+
157
+ .breeze-form .multisite-inherit-disclaimer + .submit {
158
+ margin-top: 0;
159
+ }
160
+
161
+ .breeze-form .submit {
162
+ margin-top: 35px;
163
+ }
164
+
165
  /*Table*/
166
  #breeze-tabs-content table tr td:first-child {
167
  width: 20%;
324
  #breeze-and-cloudways .rs-content button a {
325
  color: #fff;
326
  text-decoration: none;
327
+ }
assets/js/breeze-backend.js CHANGED
@@ -1,8 +1,5 @@
1
  jQuery(document).ready(function ($) {
2
  // Topbar action
3
- $('#wp-admin-bar-breeze-purge-all').click(function () {
4
- window.location.href = breeze_token_name.purge_all_href;
5
- });
6
  $('#wp-admin-bar-breeze-purge-varnish-group').click(function(){
7
  breeze_purgeVarnish_callAjax();
8
  });
@@ -22,6 +19,7 @@ jQuery(document).ready(function ($) {
22
  method:'POST',
23
  data:{
24
  action:'breeze_purge_varnish',
 
25
  security : breeze_token_name.breeze_purge_varnish
26
  },
27
  success : function(res){
@@ -103,4 +101,4 @@ jQuery(document).ready(function ($) {
103
  $('#breeze-hide-install-msg').unbind('click').click(function () {
104
  $(this).closest('div.notice').fadeOut();
105
  })
106
- });
1
  jQuery(document).ready(function ($) {
2
  // Topbar action
 
 
 
3
  $('#wp-admin-bar-breeze-purge-varnish-group').click(function(){
4
  breeze_purgeVarnish_callAjax();
5
  });
19
  method:'POST',
20
  data:{
21
  action:'breeze_purge_varnish',
22
+ is_network: $('body').hasClass( 'network-admin' ),
23
  security : breeze_token_name.breeze_purge_varnish
24
  },
25
  success : function(res){
101
  $('#breeze-hide-install-msg').unbind('click').click(function () {
102
  $(this).closest('div.notice').fadeOut();
103
  })
104
+ });
assets/js/breeze-configuration.js CHANGED
@@ -166,5 +166,98 @@ jQuery(document).ready(function($){
166
  return "";
167
  }
168
 
169
- setTabFromCookie();
170
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  return "";
167
  }
168
 
169
+ setTabFromCookie();
170
+
171
+ // Sub-site settings toggle.
172
+ var global_tabs = [
173
+ 'faq'
174
+ ];
175
+ var save_settings_inherit_form_on_submit = true;
176
+ var settings_inherit_form_did_change = false;
177
+ var $settings_inherit_form = $( '#breeze-inherit-settings-toggle' );
178
+ if ( $settings_inherit_form.length ) {
179
+ $( 'input', $settings_inherit_form ).on( 'change', function() {
180
+ var inherit = $( this ).val() == '1';
181
+
182
+ $( '#breeze-tabs' ).toggleClass( 'tabs-hidden', inherit );
183
+ $( '#breeze-tabs-content' ).toggleClass( 'tabs-hidden', inherit );
184
+
185
+ $( '#breeze-tabs .nav-tab' ).each( function() {
186
+ var tab_id = $( this ).data( 'tab-id' );
187
+
188
+ if ( $.inArray( tab_id, global_tabs ) === -1 ) {
189
+ $( this ).toggleClass( 'inactive', inherit );
190
+ $( '#breeze-tabs-content #tab-content-' + tab_id ).toggleClass( 'inactive', inherit );
191
+ }
192
+ } );
193
+
194
+ settings_inherit_form_did_change = ! $( this ).parents( '.radio-field' ).hasClass( 'active' );
195
+
196
+ $( 'p.disclaimer', $settings_inherit_form ).toggle( settings_inherit_form_did_change );
197
+ } );
198
+
199
+ $( '#breeze-tabs-content form' ).on( 'submit', function( event ) {
200
+ var $form = $( this );
201
+
202
+ if ( save_settings_inherit_form_on_submit && settings_inherit_form_did_change ) {
203
+ event.preventDefault();
204
+
205
+ $.ajax( {
206
+ url: window.location,
207
+ method: 'post',
208
+ data: $settings_inherit_form.serializeArray(),
209
+
210
+ beforeSend: function() {
211
+ $settings_inherit_form.addClass( 'loading' );
212
+ },
213
+
214
+ complete: function() {
215
+ $settings_inherit_form.removeClass( 'loading' );
216
+
217
+ // Continue form submit.
218
+ settings_inherit_form_did_change = false;
219
+ $form.submit();
220
+ },
221
+
222
+ success: function() {
223
+ $( 'input:checked', $settings_inherit_form ).parents( '.radio-field' ).addClass( 'active' ).siblings().removeClass( 'active' );
224
+ }
225
+ } );
226
+ } else {
227
+ return;
228
+ }
229
+ } );
230
+ }
231
+
232
+ // Database optimization.
233
+ $( '#breeze-database-optimize' ).on( 'click', function( event ) {
234
+ save_settings_inherit_form_on_submit = false;
235
+ } );
236
+ $( '#tab-content-database .submit input' ).on( 'click', function( event ) {
237
+ $( '#tab-content-database input[type=checkbox]' ).attr( 'checked', false );
238
+ } );
239
+
240
+ function remove_query_arg( url, arg ) {
241
+ var urlparts = url.split( '?' );
242
+ if ( urlparts.length >= 2 ) {
243
+ var prefix = encodeURIComponent( arg ) + '=';
244
+ var pars = urlparts[1].split( /[&;]/g );
245
+
246
+ for ( var i = pars.length; i-- > 0; ) {
247
+ if ( pars[i].lastIndexOf( prefix, 0 ) !== -1 ) {
248
+ pars.splice( i, 1 );
249
+ }
250
+ }
251
+
252
+ return urlparts[0] + ( pars.length > 0 ? '?' + pars.join( '&' ) : '' );
253
+ }
254
+ return url;
255
+ }
256
+
257
+ // Remove notice query args from URL.
258
+ if ( window.history && typeof window.history.pushState === 'function' ) {
259
+ var clean_url = remove_query_arg( window.location.href, 'save-settings' );
260
+ clean_url = remove_query_arg( clean_url, 'database-cleanup' );
261
+ window.history.pushState( null, null, clean_url );
262
+ }
263
+ });
breeze.php CHANGED
@@ -2,12 +2,13 @@
2
  /**
3
  * Plugin Name: Breeze
4
  * Description: Breeze is a WordPress cache plugin with extensive options to speed up your website. All the options including Varnish Cache are compatible with Cloudways hosting.
5
- * Version: 1.0.13
6
  * Text Domain: breeze
7
  * Domain Path: /languages
8
  * Author: Cloudways
9
  * Author URI: https://www.cloudways.com
10
  * License: GPL2
 
11
  */
12
 
13
  /**
@@ -52,6 +53,11 @@ if (!defined('BREEZE_BASENAME'))
52
  define('BREEZE_CACHE_DELAY', true);
53
  define('BREEZE_CACHE_NOGZIP', true);
54
  define('BREEZE_ROOT_DIR', str_replace(BREEZE_WP_CONTENT_NAME, '', WP_CONTENT_DIR));
 
 
 
 
 
55
  //action to purge cache
56
  require_once(BREEZE_PLUGIN_DIR . 'inc/cache/purge-varnish.php');
57
  require_once(BREEZE_PLUGIN_DIR . 'inc/cache/purge-cache.php');
@@ -73,8 +79,8 @@ if(is_admin()){
73
  require_once( BREEZE_PLUGIN_DIR . 'inc/cache/ecommerce-cache.php');
74
  new Breeze_Ecommerce_Cache();
75
  }else{
76
- $cdn_conf = get_option('breeze_cdn_integration');
77
- $basic_conf = get_option('breeze_basic_settings');
78
 
79
  if(!empty($cdn_conf['cdn-active']) || !empty($basic_conf['breeze-minify-js']) || !empty($basic_conf['breeze-minify-css']) || !empty($basic_conf['breeze-minify-html'])) {
80
  // Call back ob start
@@ -84,7 +90,7 @@ if(is_admin()){
84
 
85
  // Call back ob start - stack
86
  function breeze_ob_start_callback($buffer){
87
- $conf = get_option('breeze_cdn_integration');
88
  // Get buffer from minify
89
  $buffer = apply_filters('breeze_minify_content_return',$buffer);
90
 
@@ -105,4 +111,39 @@ if( !class_exists('Breeze_CDN_Integration')){
105
  require_once ( BREEZE_PLUGIN_DIR. 'inc/cdn-integration/breeze-cdn-integration.php');
106
  require_once ( BREEZE_PLUGIN_DIR. 'inc/cdn-integration/breeze-cdn-rewrite.php');
107
  new Breeze_CDN_Integration();
108
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  /**
3
  * Plugin Name: Breeze
4
  * Description: Breeze is a WordPress cache plugin with extensive options to speed up your website. All the options including Varnish Cache are compatible with Cloudways hosting.
5
+ * Version: 1.1.0
6
  * Text Domain: breeze
7
  * Domain Path: /languages
8
  * Author: Cloudways
9
  * Author URI: https://www.cloudways.com
10
  * License: GPL2
11
+ * Network: true
12
  */
13
 
14
  /**
53
  define('BREEZE_CACHE_DELAY', true);
54
  define('BREEZE_CACHE_NOGZIP', true);
55
  define('BREEZE_ROOT_DIR', str_replace(BREEZE_WP_CONTENT_NAME, '', WP_CONTENT_DIR));
56
+
57
+ // Helper functions.
58
+ require_once BREEZE_PLUGIN_DIR . 'inc/helpers.php';
59
+ require_once BREEZE_PLUGIN_DIR . 'inc/functions.php';
60
+
61
  //action to purge cache
62
  require_once(BREEZE_PLUGIN_DIR . 'inc/cache/purge-varnish.php');
63
  require_once(BREEZE_PLUGIN_DIR . 'inc/cache/purge-cache.php');
79
  require_once( BREEZE_PLUGIN_DIR . 'inc/cache/ecommerce-cache.php');
80
  new Breeze_Ecommerce_Cache();
81
  }else{
82
+ $cdn_conf = breeze_get_option( 'cdn_integration' );
83
+ $basic_conf = breeze_get_option( 'basic_settings' );
84
 
85
  if(!empty($cdn_conf['cdn-active']) || !empty($basic_conf['breeze-minify-js']) || !empty($basic_conf['breeze-minify-css']) || !empty($basic_conf['breeze-minify-html'])) {
86
  // Call back ob start
90
 
91
  // Call back ob start - stack
92
  function breeze_ob_start_callback($buffer){
93
+ $conf = breeze_get_option( 'cdn_integration' );
94
  // Get buffer from minify
95
  $buffer = apply_filters('breeze_minify_content_return',$buffer);
96
 
111
  require_once ( BREEZE_PLUGIN_DIR. 'inc/cdn-integration/breeze-cdn-integration.php');
112
  require_once ( BREEZE_PLUGIN_DIR. 'inc/cdn-integration/breeze-cdn-rewrite.php');
113
  new Breeze_CDN_Integration();
114
+ }
115
+
116
+ // @TODO: remove debug code.
117
+ if ( isset( $_GET['settings_debug'] ) ) {
118
+ $settings = array(
119
+ 'basic_settings',
120
+ 'advanced_settings',
121
+ 'cdn_integration',
122
+ 'varnish_cache',
123
+ );
124
+
125
+ echo '<h1>Is multisite: ' . ( is_multisite() ? 'YES' : 'NO' ) . '</h1>';
126
+
127
+ if ( is_multisite() ) {
128
+ $inherit_option = get_option( 'breeze_inherit_settings' );
129
+ $inherit = true;
130
+
131
+ if ( ! is_network_admin() && '0' === $inherit_option ) {
132
+ $inherit = false;
133
+ }
134
+
135
+ echo '<h1>Using global settings: ' . ( $inherit ? 'YES' : 'NO' ) . '</h1>';
136
+ }
137
+
138
+ foreach ( $settings as $setting ) {
139
+ echo '<h2>' . $setting . '</h2>';
140
+ echo '<pre>';
141
+ print_r( breeze_get_option( $setting ) );
142
+ echo '</pre>';
143
+ }
144
+
145
+ echo '<h2>Gzip enabled: ' . ( getenv( 'BREEZE_GZIP_ON' ) ? 'YES' : 'NO' ) . '</h2>';
146
+ echo '<h2>Browser cache enabled: ' . ( getenv( 'BREEZE_BROWSER_CACHE_ON' ) ? 'YES' : 'NO' ) . '</h2>';
147
+
148
+ exit;
149
+ }
inc/breeze-admin.php CHANGED
@@ -44,7 +44,7 @@ class Breeze_Admin {
44
  add_action('admin_notices', array($this, 'installing_notices'));
45
  }
46
 
47
- $config = get_option('breeze_basic_settings');
48
 
49
  if(isset($config['breeze-display-clean']) && $config['breeze-display-clean']){
50
  //register top bar menu
@@ -115,7 +115,6 @@ class Breeze_Admin {
115
  'breeze_purge_varnish' => wp_create_nonce("_breeze_purge_varnish"),
116
  'breeze_purge_database' => wp_create_nonce("_breeze_purge_database"),
117
  'breeze_purge_cache' => wp_create_nonce("_breeze_purge_cache"),
118
- 'purge_all_href' => wp_nonce_url(add_query_arg('breeze_purge', 1), 'breeze_purge_cache'),
119
  );
120
 
121
  wp_localize_script('breeze-backend','breeze_token_name',$token_name);
@@ -138,92 +137,92 @@ class Breeze_Admin {
138
  }
139
 
140
 
141
- /**
142
- * Register bar menu
143
- *
144
- */
145
- function register_admin_bar_menu(WP_Admin_Bar $wp_admin_bar)
146
- {
147
- if (current_user_can('manage_options') || current_user_can('editor')) {
148
- // add a parent item
149
- $args = array(
150
- 'id' => 'breeze-topbar',
151
- 'title' => esc_html(__('Breeze', 'breeze')),
152
- 'meta' => array(
153
- 'classname' => 'breeze',
154
- ),
155
- );
156
- $wp_admin_bar->add_node( $args );
157
-
158
- // add purge all item
159
- $args = array(
160
- 'id' => 'breeze-purge-all',
161
- 'title' => esc_html(__('Purge All Cache', 'breeze')),
162
- 'parent' => 'breeze-topbar',
163
- 'meta' => array( 'class' => 'breeze-toolbar-group' ),
164
- );
165
- $wp_admin_bar->add_node( $args );
166
-
167
- // Editor role can only use Purge all cache option
168
- if (current_user_can('editor')) return $wp_admin_bar;
169
-
170
- // add purge modules group
171
- $args = array(
172
- 'id' => 'breeze-purge-modules',
173
- 'title' => esc_html(__('Purge Modules', 'breeze')),
174
- 'parent' => 'breeze-topbar',
175
- 'meta' => array( 'class' => 'breeze-toolbar-group' ),
176
- );
177
- $wp_admin_bar->add_node( $args );
178
-
179
-
180
- // add child item (Purge Modules)
181
- $args = array(
182
- 'id' => 'breeze-purge-varnish-group',
183
- 'title' => esc_html(__('Purge Varnish Cache', 'breeze')),
184
- 'parent' => 'breeze-purge-modules',
185
- );
186
- $wp_admin_bar->add_node( $args );
187
-
188
- // add child item (Purge Modules)
189
- $args = array(
190
- 'id' => 'breeze-purge-file-group',
191
- 'title' => esc_html(__('Purge Internal Cache', 'breeze')),
192
- 'parent' => 'breeze-purge-modules',
193
- );
194
- $wp_admin_bar->add_node( $args );
195
-
196
- // add settings item
197
- $args = array(
198
- 'id' => 'breeze-settings',
199
- 'title' => esc_html(__('Settings', 'breeze')),
200
- 'parent' => 'breeze-topbar',
201
- 'href' => 'options-general.php?page=breeze',
202
- 'meta' => array( 'class' => 'breeze-toolbar-group' ),
203
- );
204
- $network_settings_url = network_admin_url('settings.php?page=breeze');
205
- if (is_multisite())
206
- $args = array(
207
- 'id' => 'breeze-settings',
208
- 'title' => esc_html(__('Settings', 'breeze')),
209
- 'parent' => 'breeze-topbar',
210
- 'href' => $network_settings_url,
211
- 'meta' => array( 'class' => 'breeze-toolbar-group' ),
212
- );
213
- $wp_admin_bar->add_node( $args );
214
-
215
- // add support item
216
- $args = array(
217
- 'id' => 'breeze-support',
218
- 'title' => esc_html(__('Support', 'breeze')),
219
- 'href' => 'https://support.cloudways.com/breeze-wordpress-cache-configuration',
220
- 'parent' => 'breeze-topbar',
221
- 'meta' => array( 'class' => 'breeze-toolbar-group',
222
- 'target' => '_blank'),
223
- );
224
- $wp_admin_bar->add_node( $args );
225
- }
226
- }
227
 
228
  function breeze_load_page()
229
  {
@@ -248,7 +247,7 @@ class Breeze_Admin {
248
  public static function plugin_active_hook(){
249
  WP_Filesystem();
250
  // Default basic
251
- $basic = get_option('breeze_basic_settings');
252
  if(empty($basic)) $basic = array();
253
  $default_basic = array(
254
  'breeze-active' => '1',
@@ -268,7 +267,7 @@ class Breeze_Admin {
268
  $basic= array_merge($default_basic,$basic);
269
 
270
  // Default Advanced
271
- $advanced = get_option('breeze_advanced_settings');
272
  if(empty($advanced)) $advanced = array();
273
  $default_advanced = array(
274
  'breeze-exclude-urls' => array(),
@@ -282,7 +281,7 @@ class Breeze_Admin {
282
  $advanced= array_merge($default_advanced,$advanced);
283
 
284
  //CDN default
285
- $cdn = get_option('breeze_cdn_integration');
286
  if(empty($cdn)) $cdn = array();
287
  $wp_content = substr(WP_CONTENT_DIR,strlen(ABSPATH));
288
  $default_cdn = array(
@@ -295,7 +294,7 @@ class Breeze_Admin {
295
  $cdn= array_merge($default_cdn,$cdn);
296
 
297
  // Varnish default
298
- $varnish = get_option('breeze_varnish_cache');
299
  if(empty($varnish)) $varnish = array();
300
  $default_varnish = array(
301
  'auto-purge-varnish' => '1',
@@ -318,12 +317,7 @@ class Breeze_Admin {
318
  }
319
 
320
  //add header to htaccess if setting is enabled or by default if first installed
321
- if ($basic['breeze-browser-cache'] == 1) {
322
- Breeze_Configuration::add_expires_header( true );
323
- }
324
- if ($basic['breeze-gzip-compression'] == 1) {
325
- Breeze_Configuration::add_gzip_htacess( true );
326
- }
327
  //automatic config start cache
328
  Breeze_ConfigCache::factory()->write();
329
  Breeze_ConfigCache::factory()->write_config_cache();
@@ -341,8 +335,7 @@ class Breeze_Admin {
341
  Breeze_ConfigCache::factory()->clean_up();
342
  Breeze_ConfigCache::factory()->clean_config();
343
  Breeze_ConfigCache::factory()->toggle_caching(false);
344
- Breeze_Configuration::add_expires_header(false);
345
- Breeze_Configuration::add_gzip_htacess(false);
346
  }
347
 
348
  /*
@@ -392,14 +385,16 @@ class Breeze_Admin {
392
  public function breeze_clear_varnish() {
393
  $main = new Breeze_PurgeVarnish();
394
 
395
- if (is_multisite()) {
 
 
396
  $sites = get_sites();
397
  foreach ($sites as $site) {
398
  switch_to_blog($site->blog_id);
399
  $homepage = home_url().'/?breeze';
400
  $main->purge_cache($homepage);
 
401
  }
402
- restore_current_blog();
403
  } else {
404
  $homepage = home_url() . '/?breeze';
405
  $main->purge_cache( $homepage );
44
  add_action('admin_notices', array($this, 'installing_notices'));
45
  }
46
 
47
+ $config = breeze_get_option( 'basic_settings' );
48
 
49
  if(isset($config['breeze-display-clean']) && $config['breeze-display-clean']){
50
  //register top bar menu
115
  'breeze_purge_varnish' => wp_create_nonce("_breeze_purge_varnish"),
116
  'breeze_purge_database' => wp_create_nonce("_breeze_purge_database"),
117
  'breeze_purge_cache' => wp_create_nonce("_breeze_purge_cache"),
 
118
  );
119
 
120
  wp_localize_script('breeze-backend','breeze_token_name',$token_name);
137
  }
138
 
139
 
140
+ /**
141
+ * Register bar menu
142
+ *
143
+ * @param WP_Admin_Bar $wp_admin_bar
144
+ */
145
+ function register_admin_bar_menu( WP_Admin_Bar $wp_admin_bar ) {
146
+ if ( ! current_user_can( 'manage_options' ) && ! current_user_can( 'editor' ) ) {
147
+ return;
148
+ }
149
+
150
+ $is_network = is_multisite() && is_network_admin();
151
+
152
+ // add parent item
153
+ $args = array(
154
+ 'id' => 'breeze-topbar',
155
+ 'title' => esc_html__( 'Breeze', 'breeze' ),
156
+ 'meta' => array(
157
+ 'classname' => 'breeze',
158
+ ),
159
+ );
160
+ $wp_admin_bar->add_node( $args );
161
+
162
+ // add purge all item
163
+ $args = array(
164
+ 'id' => 'breeze-purge-all',
165
+ 'title' => ( ! is_multisite() || $is_network ) ? esc_html__( 'Purge All Cache', 'breeze' ) : esc_html__( 'Purge Site Cache', 'breeze' ),
166
+ 'parent' => 'breeze-topbar',
167
+ 'href' => wp_nonce_url( add_query_arg( 'breeze_purge', 1, $is_network ? network_admin_url() : admin_url() ), 'breeze_purge_cache' ),
168
+ 'meta' => array( 'class' => 'breeze-toolbar-group' ),
169
+ );
170
+ $wp_admin_bar->add_node( $args );
171
+
172
+ // Editor role can only use Purge all cache option
173
+ if ( ! current_user_can( 'manage_options' ) ) {
174
+ return;
175
+ }
176
+
177
+ // add purge modules group
178
+ $args = array(
179
+ 'id' => 'breeze-purge-modules',
180
+ 'title' => esc_html__( 'Purge Modules', 'breeze' ),
181
+ 'parent' => 'breeze-topbar',
182
+ 'meta' => array( 'class' => 'breeze-toolbar-group' ),
183
+ );
184
+ $wp_admin_bar->add_node( $args );
185
+
186
+
187
+ // add child item (Purge Modules)
188
+ $args = array(
189
+ 'id' => 'breeze-purge-varnish-group',
190
+ 'title' => esc_html__( 'Purge Varnish Cache', 'breeze' ),
191
+ 'parent' => 'breeze-purge-modules',
192
+ );
193
+ $wp_admin_bar->add_node( $args );
194
+
195
+ // add child item (Purge Modules)
196
+ $args = array(
197
+ 'id' => 'breeze-purge-file-group',
198
+ 'title' => esc_html__( 'Purge Internal Cache', 'breeze' ),
199
+ 'parent' => 'breeze-purge-modules',
200
+ );
201
+ $wp_admin_bar->add_node( $args );
202
+
203
+ // add settings item
204
+ $args = array(
205
+ 'id' => 'breeze-settings',
206
+ 'title' => esc_html__( 'Settings', 'breeze' ),
207
+ 'parent' => 'breeze-topbar',
208
+ 'href' => $is_network ? network_admin_url( 'settings.php?page=breeze' ) : admin_url( 'options-general.php?page=breeze' ),
209
+ 'meta' => array( 'class' => 'breeze-toolbar-group' ),
210
+ );
211
+ $wp_admin_bar->add_node( $args );
212
+
213
+ // add support item
214
+ $args = array(
215
+ 'id' => 'breeze-support',
216
+ 'title' => esc_html__( 'Support', 'breeze' ),
217
+ 'href' => 'https://support.cloudways.com/breeze-wordpress-cache-configuration',
218
+ 'parent' => 'breeze-topbar',
219
+ 'meta' => array(
220
+ 'class' => 'breeze-toolbar-group',
221
+ 'target' => '_blank',
222
+ ),
223
+ );
224
+ $wp_admin_bar->add_node( $args );
225
+ }
226
 
227
  function breeze_load_page()
228
  {
247
  public static function plugin_active_hook(){
248
  WP_Filesystem();
249
  // Default basic
250
+ $basic = breeze_get_option( 'basic_settings' );
251
  if(empty($basic)) $basic = array();
252
  $default_basic = array(
253
  'breeze-active' => '1',
267
  $basic= array_merge($default_basic,$basic);
268
 
269
  // Default Advanced
270
+ $advanced = breeze_get_option( 'advanced_settings' );
271
  if(empty($advanced)) $advanced = array();
272
  $default_advanced = array(
273
  'breeze-exclude-urls' => array(),
281
  $advanced= array_merge($default_advanced,$advanced);
282
 
283
  //CDN default
284
+ $cdn = breeze_get_option( 'cdn_integration' );
285
  if(empty($cdn)) $cdn = array();
286
  $wp_content = substr(WP_CONTENT_DIR,strlen(ABSPATH));
287
  $default_cdn = array(
294
  $cdn= array_merge($default_cdn,$cdn);
295
 
296
  // Varnish default
297
+ $varnish = breeze_get_option( 'varnish_cache' );
298
  if(empty($varnish)) $varnish = array();
299
  $default_varnish = array(
300
  'auto-purge-varnish' => '1',
317
  }
318
 
319
  //add header to htaccess if setting is enabled or by default if first installed
320
+ Breeze_Configuration::update_htaccess();
 
 
 
 
 
321
  //automatic config start cache
322
  Breeze_ConfigCache::factory()->write();
323
  Breeze_ConfigCache::factory()->write_config_cache();
335
  Breeze_ConfigCache::factory()->clean_up();
336
  Breeze_ConfigCache::factory()->clean_config();
337
  Breeze_ConfigCache::factory()->toggle_caching(false);
338
+ Breeze_Configuration::update_htaccess( true );
 
339
  }
340
 
341
  /*
385
  public function breeze_clear_varnish() {
386
  $main = new Breeze_PurgeVarnish();
387
 
388
+ $is_network = ( is_network_admin() || ( ! empty( $_POST['is_network'] ) && 'true' === $_POST['is_network'] ) );
389
+
390
+ if ( is_multisite() && $is_network ) {
391
  $sites = get_sites();
392
  foreach ($sites as $site) {
393
  switch_to_blog($site->blog_id);
394
  $homepage = home_url().'/?breeze';
395
  $main->purge_cache($homepage);
396
+ restore_current_blog();
397
  }
 
398
  } else {
399
  $homepage = home_url() . '/?breeze';
400
  $main->purge_cache( $homepage );
inc/breeze-configuration.php CHANGED
@@ -23,16 +23,32 @@ defined('ABSPATH') || die('No direct script access allowed!');
23
  class Breeze_Configuration{
24
  public function __construct()
25
  {
26
- add_action( 'load-settings_page_breeze', array($this,'afterLoadConfigPage') );
 
 
27
  }
28
 
29
 
30
  /*
31
  * function to save settings
32
  */
33
- public function afterLoadConfigPage()
34
- {
35
- $sites = is_multisite() ? get_sites() : array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  // Basic options tab
37
  if (isset($_REQUEST['breeze_basic_action']) && $_REQUEST['breeze_basic_action'] == 'breeze_basic_settings') {
38
  if (isset($_POST['breeze_settings_basic_nonce']) && wp_verify_nonce($_POST['breeze_settings_basic_nonce'], 'breeze_settings_basic')) {
@@ -53,16 +69,8 @@ class Breeze_Configuration{
53
  'breeze-include-inline-js' => (isset($_POST['include-inline-js']) ? '1' : '0'),
54
  'breeze-include-inline-css' => (isset($_POST['include-inline-css']) ? '1' : '0'),
55
  );
56
- update_option('breeze_basic_settings',$basic);
57
-
58
- // Update settings for network sites
59
- if (is_multisite()) {
60
- foreach ($sites as $site) {
61
- switch_to_blog($site->blog_id);
62
- update_option('breeze_basic_settings',$basic);
63
- }
64
- restore_current_blog();
65
- }
66
 
67
  // Storage infomation to cache pages
68
  Breeze_ConfigCache::factory()->write();
@@ -81,17 +89,7 @@ class Breeze_Configuration{
81
  Breeze_PurgeCacheTime::factory()->schedule_events();
82
  }
83
  // Add expires header
84
- if(isset($_POST['gzip-compression'])){
85
- self::add_gzip_htacess(true);
86
- }else{
87
- self::add_gzip_htacess(false);
88
- }
89
- // Add expires header
90
- if(isset($_POST['browser-cache'])){
91
- self::add_expires_header(true);
92
- }else{
93
- self::add_expires_header(false);
94
- }
95
 
96
  //delete cache after settings
97
  do_action('breeze_clear_all_cache');
@@ -129,16 +127,9 @@ class Breeze_Configuration{
129
  'breeze-exclude-js' => $exclude_js,
130
  'breeze-move-to-footer-js' => $move_to_footer_js,
131
  'breeze-defer-js' => $defer_js
132
- );
133
- update_option('breeze_advanced_settings',$advanced);
134
- // Update settings for network sites
135
- if (is_multisite()) {
136
- foreach ($sites as $site) {
137
- switch_to_blog($site->blog_id);
138
- update_option('breeze_advanced_settings',$advanced);
139
- }
140
- restore_current_blog();
141
- }
142
 
143
  WP_Filesystem();
144
  // Storage infomation to cache pages
@@ -150,31 +141,22 @@ class Breeze_Configuration{
150
  }
151
 
152
  // Database option tab
153
- if (isset($_REQUEST['breeze_database_action']) && $_REQUEST['breeze_database_action'] == 'breeze_database_settings') {
154
- if (isset($_POST['breeze_settings_database_nonce']) && wp_verify_nonce($_POST['breeze_settings_database_nonce'], 'breeze_settings_database')) {
155
- if(isset($_POST['clean'])){
156
- if (is_multisite()) {
157
- foreach ($sites as $site) {
158
- switch_to_blog($site->blog_id);
159
- foreach ($_POST['clean'] as $item){
160
- $this->cleanSystem($item);
161
- }
162
- }
163
- restore_current_blog();
164
- } else {
165
- foreach ($_POST['clean'] as $item){
166
- $this->cleanSystem($item);
167
- }
168
- }
169
-
170
- //return current page
171
- if (!empty($_REQUEST['_wp_http_referer'])) {
172
- wp_safe_redirect($_REQUEST['_wp_http_referer'].'&database-cleanup=success');
173
- exit;
174
- }
175
- }
176
- }
177
- }
178
 
179
  // Cdn option tab
180
  if (isset($_REQUEST['breeze_cdn_action']) && $_REQUEST['breeze_cdn_action'] == 'breeze_cdn_settings') {
@@ -198,15 +180,7 @@ class Breeze_Configuration{
198
  'cdn-relative-path' =>(isset($_POST['cdn-relative-path']) ? '1' : '0'),
199
  );
200
 
201
- update_option('breeze_cdn_integration', $cdn);
202
- // Update settings for network sites
203
- if (is_multisite()) {
204
- foreach ($sites as $site) {
205
- switch_to_blog($site->blog_id);
206
- update_option('breeze_cdn_integration',$cdn);
207
- }
208
- restore_current_blog();
209
- }
210
 
211
  //delete cache after settings
212
  do_action('breeze_clear_all_cache');
@@ -219,16 +193,9 @@ class Breeze_Configuration{
219
  $varnish = array(
220
  'auto-purge-varnish' => (isset($_POST['auto-purge-varnish']) ? '1' : '0'),
221
  'breeze-varnish-server-ip' => preg_replace('/[^a-zA-Z0-9\-\_\.]*/','',$_POST['varnish-server-ip'])
222
- );
223
- update_option('breeze_varnish_cache',$varnish);
224
- // Update settings for network sites
225
- if (is_multisite()) {
226
- foreach ($sites as $site) {
227
- switch_to_blog($site->blog_id);
228
- update_option('breeze_varnish_cache',$varnish);
229
- }
230
- restore_current_blog();
231
- }
232
 
233
  // Clear varnish cache after settings
234
  do_action('breeze_clear_varnish');
@@ -237,128 +204,306 @@ class Breeze_Configuration{
237
 
238
 
239
  //return current page
240
- if (!empty($_REQUEST['_wp_http_referer'])) {
241
- wp_safe_redirect($_REQUEST['_wp_http_referer'].'&save-settings=success');
 
242
  exit;
243
  }
244
 
245
  return true;
246
  }
247
 
248
- /*
249
- * function add expires header to .htaccess
250
- */
251
- public static function add_expires_header($check) {
252
- $expires = "#Expires headers configuration added by BREEZE WP CACHE plugin" . PHP_EOL .
253
- "<IfModule mod_expires.c>" . PHP_EOL .
254
- " ExpiresActive On" . PHP_EOL .
255
- " ExpiresDefault A2592000" . PHP_EOL .
256
- " ExpiresByType application/javascript \"access plus 7 days\"" . PHP_EOL .
257
- " ExpiresByType text/javascript \"access plus 7 days\"" . PHP_EOL .
258
- " ExpiresByType text/css \"access plus 7 days\"" . PHP_EOL .
259
- " ExpiresByType image/jpeg \"access plus 7 days\"" . PHP_EOL .
260
- " ExpiresByType image/png \"access plus 7 days\"" . PHP_EOL .
261
- " ExpiresByType image/gif \"access plus 7 days\"" . PHP_EOL .
262
- " ExpiresByType image/ico \"access plus 7 days\"" . PHP_EOL .
263
- " ExpiresByType image/x-icon \"access plus 7 days\"" . PHP_EOL .
264
- " ExpiresByType image/svg+xml \"access plus 7 days\"" . PHP_EOL .
265
- " ExpiresByType image/bmp \"access plus 7 days\"" . PHP_EOL .
266
- "</IfModule>" . PHP_EOL .
267
- "#End of expires headers configuration" . PHP_EOL ;
268
-
269
- if ($check) {
270
- if (!is_super_admin()) {
271
- return FALSE;
272
- }
273
- //open htaccess file
274
- $htaccessContent = file_get_contents(ABSPATH . DIRECTORY_SEPARATOR . '.htaccess');
275
- if (empty($htaccessContent)) {
276
- return FALSE;
277
- }
278
- //if isset expires header in htacces
279
- if (strpos($htaccessContent, 'mod_expires') !== false || strpos($htaccessContent, 'ExpiresActive') !== false || strpos($htaccessContent, 'ExpiresDefault') !== false || strpos($htaccessContent, 'ExpiresByType') !== false) {
280
- return FALSE;
281
- }
282
-
283
- $htaccessContent = $expires.$htaccessContent;
284
- file_put_contents(ABSPATH . DIRECTORY_SEPARATOR . '.htaccess', $htaccessContent);
285
- return TRUE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
 
287
- } else {
288
- if (!is_super_admin()) {
289
- return FALSE;
290
- }
291
- //open htaccess file
292
- $htaccessContent = file_get_contents(ABSPATH . DIRECTORY_SEPARATOR . '.htaccess');
293
- if (empty($htaccessContent)) {
294
- return FALSE;
295
- }
296
-
297
- $pattern = '/#Expires headers configuration added by BREEZE WP CACHE plugin[\s\S]*#End of expires headers configuration/im';
298
-
299
- $htaccessContent = preg_replace($pattern,'',$htaccessContent);
300
- file_put_contents(ABSPATH . DIRECTORY_SEPARATOR . '.htaccess', $htaccessContent);
301
- return TRUE;
302
- }
303
- }
304
- /*
305
- * function add gzip header to .htaccess
306
- */
307
- public static function add_gzip_htacess($check){
308
- $data = "# Begin GzipofBreezeWPCache".PHP_EOL.
309
- "<IfModule mod_deflate.c>".PHP_EOL.
310
- "AddType x-font/woff .woff".PHP_EOL.
311
- "AddOutputFilterByType DEFLATE image/svg+xml".PHP_EOL.
312
- "AddOutputFilterByType DEFLATE text/plain".PHP_EOL.
313
- "AddOutputFilterByType DEFLATE text/html".PHP_EOL.
314
- "AddOutputFilterByType DEFLATE text/xml".PHP_EOL.
315
- "AddOutputFilterByType DEFLATE text/css".PHP_EOL.
316
- "AddOutputFilterByType DEFLATE text/javascript".PHP_EOL.
317
- "AddOutputFilterByType DEFLATE application/xml".PHP_EOL.
318
- "AddOutputFilterByType DEFLATE application/xhtml+xml".PHP_EOL.
319
- "AddOutputFilterByType DEFLATE application/rss+xml".PHP_EOL.
320
- "AddOutputFilterByType DEFLATE application/javascript".PHP_EOL.
321
- "AddOutputFilterByType DEFLATE application/x-javascript".PHP_EOL.
322
- "AddOutputFilterByType DEFLATE application/x-font-ttf".PHP_EOL.
323
- "AddOutputFilterByType DEFLATE application/vnd.ms-fontobject".PHP_EOL.
324
- "AddOutputFilterByType DEFLATE font/opentype font/ttf font/eot font/otf".PHP_EOL.
325
- "</IfModule>".PHP_EOL.
326
- "# End GzipofBreezeWPCache" . PHP_EOL ;
327
- if ($check) {
328
- if (!is_super_admin()) {
329
- return FALSE;
330
- }
331
- //open htaccess file
332
- $htaccessContent = file_get_contents(ABSPATH . DIRECTORY_SEPARATOR . '.htaccess');
333
- if (empty($htaccessContent)) {
334
- return FALSE;
335
- }
336
- //if isset Gzip access
337
- if (strpos($htaccessContent, 'mod_deflate') !== false || strpos($htaccessContent, 'AddOutputFilterByType') !== false || strpos($htaccessContent, 'AddType') !== false || strpos($htaccessContent,'GzipofBreezeWPCache') !== false) {
338
- return FALSE;
339
- }
340
-
341
- $htaccessContent = $data.$htaccessContent;
342
- file_put_contents(ABSPATH . DIRECTORY_SEPARATOR . '.htaccess', $htaccessContent);
343
- return TRUE;
344
-
345
- } else {
346
- if (!is_super_admin()) {
347
- return FALSE;
348
- }
349
- //open htaccess file
350
- $htaccessContent = file_get_contents(ABSPATH . DIRECTORY_SEPARATOR . '.htaccess');
351
- if (empty($htaccessContent)) {
352
- return FALSE;
353
- }
354
-
355
- $pattern = '/# Begin GzipofBreezeWPCache[\s\S]*# End GzipofBreezeWPCache/im';
356
-
357
- $htaccessContent = preg_replace($pattern,'',$htaccessContent);
358
- file_put_contents(ABSPATH . DIRECTORY_SEPARATOR . '.htaccess', $htaccessContent);
359
- return TRUE;
360
- }
361
- }
362
  /*
363
  * Database clean tab
364
  * funtion to clean in database
@@ -409,11 +554,13 @@ class Breeze_Configuration{
409
  return true;
410
  }
411
 
412
- /*
413
  * Database clean tab
414
  * funtion to get number of element to clean in database
 
 
415
  */
416
- public static function getElementToClean($type){
417
  global $wpdb;
418
  $return = 0;
419
  switch ($type){
@@ -438,7 +585,7 @@ class Breeze_Configuration{
438
  $return = $wpdb->query( $element );
439
  break;
440
  case "transient":
441
- $element = "SELECT option_id FROM `$wpdb->options` WHERE option_name LIKE '%\_transient\_%' ;";
442
  $return = $wpdb->query( $element );
443
  break;
444
  }
@@ -462,77 +609,26 @@ class Breeze_Configuration{
462
  }
463
  //ajax clean cache
464
  public static function breeze_clean_cache() {
465
- $size_cache = 0;
466
- $size_css_cache = 0;
467
- $size_js_cache = 0;
468
- $result = 0;
469
- // analysis size cache
470
- $cachepath = rtrim(WP_CONTENT_DIR, '/') . '/cache/breeze';
471
-
472
- if (is_dir($cachepath))
473
- $cachedirs = scandir($cachepath);
474
- if (!empty($cachedirs)) {
475
- foreach ($cachedirs as $cachedir) {
476
- if ($cachedir != '.' && $cachedir != '..') {
477
- $filepath = $cachepath . '/' . $cachedir;
478
- if(is_dir($filepath))
479
- $filedirs = scandir($filepath);
480
- foreach($filedirs as $filedir){
481
- if ($filedir != '.' && $filedir != '..') {
482
- if (@file_exists($filepath)) {
483
- $dir_path = $filepath.'/'.$filedir;
484
- $size_cache += filesize($dir_path);
485
- }
486
- }
487
- }
488
 
489
- }
490
- }
491
- }
492
-
493
- // analysis size css cache
494
- if(is_multisite()){
495
- $blog_id = get_current_blog_id();
496
- $css_path = rtrim(WP_CONTENT_DIR, '/') . '/cache/breeze-minification/'.$blog_id.'/css';
497
- }else{
498
- $css_path = rtrim(WP_CONTENT_DIR, '/') . '/cache/breeze-minification/css';
499
- }
500
- if (is_dir($css_path))
501
- $file_in_css = scandir($css_path);
502
- if (!empty($file_in_css)) {
503
- foreach ($file_in_css as $v) {
504
- if ($v != '.' && $v != '..' && $v != 'index.html') {
505
- $path = $css_path . '/' . $v;
506
- $size_css_cache += filesize($path);
507
- }
508
- }
509
- }
510
 
511
- // analysis size js cache
512
- if(is_multisite()){
513
- $blog_id = get_current_blog_id();
514
- $js_path = rtrim(WP_CONTENT_DIR, '/') . '/cache/breeze-minification/'.$blog_id.'/js';
515
- }else{
516
- $js_path = rtrim(WP_CONTENT_DIR, '/') . '/cache/breeze-minification/js';
517
- }
518
- if (is_dir($js_path))
519
- ;
520
- $file_in_js = scandir($js_path);
521
- if (!empty($file_in_js)) {
522
- foreach ($file_in_js as $v) {
523
- if ($v != '.' && $v != '..' && $v != 'index.html') {
524
- $path = $js_path . '/' . $v;
525
- $size_js_cache += filesize($path);
526
- }
527
- }
528
- }
529
 
530
- $total_size_cache = $size_cache + $size_css_cache + $size_js_cache;
 
 
 
 
 
 
531
 
532
- $result = self::formatBytes($total_size_cache);
533
 
534
- //delete minify file
535
- Breeze_MinificationCache::clear_minification();
536
  //delete all cache
537
  Breeze_PurgeCache::breeze_cache_flush();
538
 
@@ -571,9 +667,7 @@ class Breeze_Configuration{
571
  check_ajax_referer( '_breeze_purge_database', 'security' );
572
 
573
  $type = array('revisions','drafted','trash','comments','trackbacks','transient');
574
- foreach ($type as $item){
575
- self::cleanSystem($item);
576
- }
577
 
578
  echo json_encode(array('clear' => true));
579
  exit;
@@ -594,7 +688,34 @@ class Breeze_Configuration{
594
  }
595
 
596
  return $bytes;
597
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
598
 
599
  }
600
 
23
  class Breeze_Configuration{
24
  public function __construct()
25
  {
26
+ global $breeze_network_subsite_settings;
27
+ $breeze_network_subsite_settings = false;
28
+ add_action( 'load-settings_page_breeze', array($this,'afterLoadConfigPage') );
29
  }
30
 
31
 
32
  /*
33
  * function to save settings
34
  */
35
+ public function afterLoadConfigPage() {
36
+ // Per-site settings (multisite inheriting)
37
+ if (
38
+ is_multisite() &&
39
+ isset( $_REQUEST['inherit-settings'] ) &&
40
+ isset( $_POST['breeze_inherit_settings_nonce'] ) &&
41
+ wp_verify_nonce( $_POST['breeze_inherit_settings_nonce'], 'breeze_inherit_settings' )
42
+ ) {
43
+ $inherit_settings = ( 1 == $_REQUEST['inherit-settings'] ? '1' : '0' );
44
+ update_option( 'breeze_inherit_settings', $inherit_settings );
45
+
46
+ if ( ! isset( $_REQUEST['breeze_basic_action'], $_REQUEST['breeze_advanced_action'] ) ) {
47
+ WP_Filesystem();
48
+ Breeze_ConfigCache::factory()->write_config_cache();
49
+ }
50
+ }
51
+
52
  // Basic options tab
53
  if (isset($_REQUEST['breeze_basic_action']) && $_REQUEST['breeze_basic_action'] == 'breeze_basic_settings') {
54
  if (isset($_POST['breeze_settings_basic_nonce']) && wp_verify_nonce($_POST['breeze_settings_basic_nonce'], 'breeze_settings_basic')) {
69
  'breeze-include-inline-js' => (isset($_POST['include-inline-js']) ? '1' : '0'),
70
  'breeze-include-inline-css' => (isset($_POST['include-inline-css']) ? '1' : '0'),
71
  );
72
+
73
+ breeze_update_option( 'basic_settings', $basic, true );
 
 
 
 
 
 
 
 
74
 
75
  // Storage infomation to cache pages
76
  Breeze_ConfigCache::factory()->write();
89
  Breeze_PurgeCacheTime::factory()->schedule_events();
90
  }
91
  // Add expires header
92
+ self::update_htaccess();
 
 
 
 
 
 
 
 
 
 
93
 
94
  //delete cache after settings
95
  do_action('breeze_clear_all_cache');
127
  'breeze-exclude-js' => $exclude_js,
128
  'breeze-move-to-footer-js' => $move_to_footer_js,
129
  'breeze-defer-js' => $defer_js
130
+ );
131
+
132
+ breeze_update_option( 'advanced_settings', $advanced, true );
 
 
 
 
 
 
 
133
 
134
  WP_Filesystem();
135
  // Storage infomation to cache pages
141
  }
142
 
143
  // Database option tab
144
+ if (
145
+ isset( $_REQUEST['breeze_database_action'] ) &&
146
+ 'breeze_database_settings' === $_REQUEST['breeze_database_action'] &&
147
+ isset( $_POST['breeze_settings_database_nonce'] ) &&
148
+ wp_verify_nonce( $_POST['breeze_settings_database_nonce'], 'breeze_settings_database' ) &&
149
+ ! empty( $_POST['clean'] ) && is_array( $_POST['clean'] )
150
+ ) {
151
+ self::optimize_database( $_POST['clean'] );
152
+
153
+ //return current page
154
+ if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
155
+ $url = remove_query_arg( 'save-settings', $_REQUEST['_wp_http_referer'] );
156
+ wp_safe_redirect( add_query_arg( 'database-cleanup', 'success', $url ) );
157
+ exit;
158
+ }
159
+ }
 
 
 
 
 
 
 
 
 
160
 
161
  // Cdn option tab
162
  if (isset($_REQUEST['breeze_cdn_action']) && $_REQUEST['breeze_cdn_action'] == 'breeze_cdn_settings') {
180
  'cdn-relative-path' =>(isset($_POST['cdn-relative-path']) ? '1' : '0'),
181
  );
182
 
183
+ breeze_update_option( 'cdn_integration', $cdn, true );
 
 
 
 
 
 
 
 
184
 
185
  //delete cache after settings
186
  do_action('breeze_clear_all_cache');
193
  $varnish = array(
194
  'auto-purge-varnish' => (isset($_POST['auto-purge-varnish']) ? '1' : '0'),
195
  'breeze-varnish-server-ip' => preg_replace('/[^a-zA-Z0-9\-\_\.]*/','',$_POST['varnish-server-ip'])
196
+ );
197
+
198
+ breeze_update_option( 'varnish_cache', $varnish, true );
 
 
 
 
 
 
 
199
 
200
  // Clear varnish cache after settings
201
  do_action('breeze_clear_varnish');
204
 
205
 
206
  //return current page
207
+ if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
208
+ $url = remove_query_arg( 'database-cleanup', $_REQUEST['_wp_http_referer'] );
209
+ wp_safe_redirect( add_query_arg( 'save-settings', 'success', $url ) );
210
  exit;
211
  }
212
 
213
  return true;
214
  }
215
 
216
+ /*
217
+ * function add expires header to .htaccess
218
+ */
219
+ public static function add_expires_header( $clean = false, $conditional_regex = '' ) {
220
+ $args = array(
221
+ 'before' => '#Expires headers configuration added by BREEZE WP CACHE plugin',
222
+ 'after' => '#End of expires headers configuration',
223
+ );
224
+
225
+ if ( $clean ) {
226
+ $args['clean'] = true;
227
+ } else {
228
+ $args['content'] = 'SetEnv BREEZE_BROWSER_CACHE_ON 1' . PHP_EOL .
229
+ '<IfModule mod_expires.c>' . PHP_EOL .
230
+ ' ExpiresActive On' . PHP_EOL .
231
+ ' ExpiresDefault A2592000' . PHP_EOL .
232
+ ' ExpiresByType application/javascript "access plus 7 days"' . PHP_EOL .
233
+ ' ExpiresByType text/javascript "access plus 7 days"' . PHP_EOL .
234
+ ' ExpiresByType text/css "access plus 7 days"' . PHP_EOL .
235
+ ' ExpiresByType image/jpeg "access plus 7 days"' . PHP_EOL .
236
+ ' ExpiresByType image/png "access plus 7 days"' . PHP_EOL .
237
+ ' ExpiresByType image/gif "access plus 7 days"' . PHP_EOL .
238
+ ' ExpiresByType image/ico "access plus 7 days"' . PHP_EOL .
239
+ ' ExpiresByType image/x-icon "access plus 7 days"' . PHP_EOL .
240
+ ' ExpiresByType image/svg+xml "access plus 7 days"' . PHP_EOL .
241
+ ' ExpiresByType image/bmp "access plus 7 days"' . PHP_EOL .
242
+ '</IfModule>' . PHP_EOL;
243
+
244
+ $args['conditions'] = array(
245
+ 'mod_expires',
246
+ 'ExpiresActive',
247
+ 'ExpiresDefault',
248
+ 'ExpiresByType',
249
+ );
250
+
251
+ if ( ! empty( $conditional_regex ) ) {
252
+ $args['content'] = '<If "' . $conditional_regex . '">' . PHP_EOL . $args['content'] . '</If>' . PHP_EOL;
253
+ };
254
+ }
255
+
256
+ return self::write_htaccess( $args );
257
+ }
258
+
259
+ /*
260
+ * function add gzip header to .htaccess
261
+ */
262
+ public static function add_gzip_htacess( $clean = false, $conditional_regex = '' ) {
263
+ $args = array(
264
+ 'before' => '# Begin GzipofBreezeWPCache',
265
+ 'after' => '# End GzipofBreezeWPCache',
266
+ );
267
+
268
+ if ( $clean ) {
269
+ $args['clean'] = true;
270
+ } else {
271
+ $args['content'] = 'SetEnv BREEZE_GZIP_ON 1' . PHP_EOL .
272
+ '<IfModule mod_deflate.c>' . PHP_EOL .
273
+ ' AddType x-font/woff .woff' . PHP_EOL .
274
+ ' AddOutputFilterByType DEFLATE image/svg+xml' . PHP_EOL .
275
+ ' AddOutputFilterByType DEFLATE text/plain' . PHP_EOL .
276
+ ' AddOutputFilterByType DEFLATE text/html' . PHP_EOL .
277
+ ' AddOutputFilterByType DEFLATE text/xml' . PHP_EOL .
278
+ ' AddOutputFilterByType DEFLATE text/css' . PHP_EOL .
279
+ ' AddOutputFilterByType DEFLATE text/javascript' . PHP_EOL .
280
+ ' AddOutputFilterByType DEFLATE application/xml' . PHP_EOL .
281
+ ' AddOutputFilterByType DEFLATE application/xhtml+xml' . PHP_EOL .
282
+ ' AddOutputFilterByType DEFLATE application/rss+xml' . PHP_EOL .
283
+ ' AddOutputFilterByType DEFLATE application/javascript' . PHP_EOL .
284
+ ' AddOutputFilterByType DEFLATE application/x-javascript' . PHP_EOL .
285
+ ' AddOutputFilterByType DEFLATE application/x-font-ttf' . PHP_EOL .
286
+ ' AddOutputFilterByType DEFLATE application/vnd.ms-fontobject' . PHP_EOL .
287
+ ' AddOutputFilterByType DEFLATE font/opentype font/ttf font/eot font/otf' . PHP_EOL .
288
+ '</IfModule>' . PHP_EOL;
289
+
290
+ $args['conditions'] = array(
291
+ 'mod_deflate',
292
+ 'AddOutputFilterByType',
293
+ 'AddType',
294
+ 'GzipofBreezeWPCache',
295
+ );
296
+
297
+ if ( ! empty( $conditional_regex ) ) {
298
+ $args['content'] = '<If "' . $conditional_regex . '">' . PHP_EOL . $args['content'] . '</If>' . PHP_EOL;
299
+ };
300
+ }
301
+
302
+ return self::write_htaccess( $args );
303
+ }
304
+
305
+ /**
306
+ * Trigger update to htaccess file.
307
+ *
308
+ * @param bool $clean If true, will clear custom .htaccess rules.
309
+ * @return bool
310
+ */
311
+ public static function update_htaccess( $clean = false ) {
312
+ if ( $clean ) {
313
+ self::add_expires_header( $clean );
314
+ self::add_gzip_htacess( $clean );
315
+ return true;
316
+ }
317
+
318
+ if ( is_multisite() ) {
319
+ // Multisite setup.
320
+ $supports_conditionals = breeze_is_supported( 'conditional_htaccess' );
321
+
322
+ if ( ! $supports_conditionals ) {
323
+ // If Apache htaccess conditional directives not available, inherit network-level settings.
324
+ $config = get_site_option( 'breeze_basic_settings', array() );
325
+
326
+ if ( isset( $config['breeze-active'] ) && '1' === $config['breeze-active'] ) {
327
+ self::add_expires_header( ! isset( $config['breeze-browser-cache'] ) || '1' !== $config['breeze-browser-cache'] );
328
+ self::add_gzip_htacess( ! isset( $config['breeze-gzip-compression'] ) || '1' !== $config['breeze-gzip-compression'] );
329
+ } else {
330
+ self::add_expires_header( true );
331
+ self::add_gzip_htacess( true );
332
+ }
333
+
334
+ return true;
335
+ }
336
+
337
+ $has_browser_cache = false;
338
+ $browser_cache_sites = array();
339
+ $no_browser_cache_sites = array();
340
+ $browser_cache_regex = '';
341
+ $has_gzip_compress = false;
342
+ $gzip_compress_sites = array();
343
+ $no_gzip_compress_sites = array();
344
+ $gzip_compress_regex = '';
345
+
346
+ $blogs = get_sites(
347
+ array(
348
+ 'fields' => 'ids',
349
+ )
350
+ );
351
+
352
+ global $breeze_network_subsite_settings;
353
+ $breeze_network_subsite_settings = true;
354
+
355
+ foreach ( $blogs as $blog_id ) {
356
+ switch_to_blog( $blog_id );
357
+ $site_url = preg_quote( preg_replace( '(^https?://)', '', site_url() ) );
358
+ $config = breeze_get_option( 'basic_settings' );
359
+ if ( '1' === $config['breeze-active'] ) {
360
+ if ( '1' === $config['breeze-browser-cache'] ) {
361
+ $has_browser_cache = true;
362
+ $browser_cache_sites[] = $site_url;
363
+ } else {
364
+ $no_browser_cache_sites[] = $site_url;
365
+ }
366
+ if ( '1' === $config['breeze-gzip-compression'] ) {
367
+ $has_gzip_compress = true;
368
+ $gzip_compress_sites[] = $site_url;
369
+ } else {
370
+ $no_gzip_compress_sites[] = $site_url;
371
+ }
372
+ } else {
373
+ $no_browser_cache_sites[] = $site_url;
374
+ $no_gzip_compress_sites[] = $site_url;
375
+ }
376
+ restore_current_blog();
377
+ }
378
+
379
+ $breeze_network_subsite_settings = false;
380
+
381
+ $rules = array(
382
+ 'browser_cache' => 'add_expires_header',
383
+ 'gzip_compress' => 'add_gzip_htacess',
384
+ );
385
+ // Loop through caching type rules.
386
+ foreach ( $rules as $var_name => $method_name ) {
387
+ $has_cache_var = 'has_' . $var_name;
388
+ if ( ! $$has_cache_var ) {
389
+ // No sites using rules, clean up.
390
+ self::$method_name( true );
391
+ } else {
392
+ $enabled_sites = $var_name . '_sites';
393
+ $disabled_sites = 'no_' . $var_name . '_sites';
394
+ $regex_string = '';
395
+
396
+ if ( empty( $$disabled_sites ) ) {
397
+ // Rule is active across sites, do not include conditional directives.
398
+ self::$method_name( $clean );
399
+ continue;
400
+ }
401
+
402
+ if ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) {
403
+ // Subdomain sites are matched using host alone.
404
+ $regex_string = '%{HTTP_HOST} =~ m#^(' . implode( '|', $$enabled_sites ) . ')#';
405
+ } else {
406
+ // Subdirectory sites are matched using "THE_REQUEST".
407
+ $network_site_url = preg_quote( preg_replace( '(^https?://)', '', untrailingslashit( network_site_url() ) ) );
408
+
409
+ // Remove host part from URLs.
410
+ $$enabled_sites = array_filter(
411
+ array_map(
412
+ function( $url ) use ( $network_site_url ) {
413
+ $modified = str_replace( $network_site_url, '', $url );
414
+ return empty( $modified ) ? '/' : $modified;
415
+ },
416
+ $$enabled_sites
417
+ )
418
+ );
419
+
420
+ if ( ! empty( $$enabled_sites ) ) {
421
+ $regex_string = '%{THE_REQUEST} =~ m#^GET (' . implode( '|', $$enabled_sites ) . ')#';
422
+ }
423
+
424
+ // Remove main site URL from disabled sites array.
425
+ $network_site_url_index = array_search( $network_site_url, $$disabled_sites );
426
+ if ( false !== $network_site_url_index ) {
427
+ unset( $$disabled_sites[ $network_site_url_index ] );
428
+ }
429
+ // Remove host part from URLs.
430
+ $$disabled_sites = array_filter(
431
+ array_map(
432
+ function( $url ) use ( $network_site_url ) {
433
+ $modified = str_replace( $network_site_url, '', $url );
434
+ return empty( $modified ) ? '/' : $modified;
435
+ },
436
+ $$disabled_sites
437
+ )
438
+ );
439
+ if ( ! empty( $$disabled_sites ) ) {
440
+ if ( ! empty( $$enabled_sites ) ) {
441
+ $regex_string .= ' && ';
442
+ }
443
+ $regex_string .= '%{THE_REQUEST} !~ m#^GET (' . implode( '|', $$disabled_sites ) . ')#';
444
+ }
445
+ }
446
+
447
+ // Add conditional rule.
448
+ self::$method_name( empty( $regex_string ), $regex_string );
449
+ }
450
+ }
451
+ } else {
452
+ // Single-site setup.
453
+ $config = breeze_get_option( 'basic_settings' );
454
+ if ( '1' === $config['breeze-active'] ) {
455
+ self::add_expires_header( '1' !== $config['breeze-browser-cache'] );
456
+ self::add_gzip_htacess( '1' !== $config['breeze-gzip-compression'] );
457
+ } else {
458
+ // Caching not activated, clean up.
459
+ self::add_expires_header( true );
460
+ self::add_gzip_htacess( true );
461
+ return true;
462
+ }
463
+ }
464
+
465
+ return true;
466
+ }
467
+
468
+ /**
469
+ * Add and remove custom blocks from .htaccess.
470
+ *
471
+ * @param array $args
472
+ * @return bool
473
+ */
474
+ public static function write_htaccess( $args ) {
475
+ $htaccess_path = trailingslashit( ABSPATH ) . '.htaccess';
476
+
477
+ if ( ! is_super_admin() ) {
478
+ return false;
479
+ }
480
+ // open htaccess file
481
+ if ( file_exists( $htaccess_path ) ) {
482
+ $htaccess_content = file_get_contents( $htaccess_path );
483
+ }
484
+ if ( empty( $htaccess_content ) ) {
485
+ return false;
486
+ }
487
+
488
+ // Remove old rules.
489
+ $htaccess_content = preg_replace( "/{$args['before']}[\s\S]*{$args['after']}" . PHP_EOL . '/im', '', $htaccess_content );
490
+
491
+ if ( ! isset( $args['clean'] ) ) {
492
+ if ( isset( $args['conditions'] ) ) {
493
+ foreach ( $args['conditions'] as $condition ) {
494
+ if ( strpos( $htaccess_content, $condition ) !== false ) {
495
+ return false;
496
+ }
497
+ }
498
+ }
499
+
500
+ $htaccess_content = $args['before'] . PHP_EOL . $args['content'] . $args['after'] . PHP_EOL . $htaccess_content;
501
+ }
502
+
503
+ file_put_contents( $htaccess_path, $htaccess_content );
504
+ return true;
505
+ }
506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
507
  /*
508
  * Database clean tab
509
  * funtion to clean in database
554
  return true;
555
  }
556
 
557
+ /**
558
  * Database clean tab
559
  * funtion to get number of element to clean in database
560
+ *
561
+ * @param string $type
562
  */
563
+ public static function getElementToClean( $type ) {
564
  global $wpdb;
565
  $return = 0;
566
  switch ($type){
585
  $return = $wpdb->query( $element );
586
  break;
587
  case "transient":
588
+ $element = "SELECT option_id FROM `$wpdb->options` WHERE option_name LIKE '%\_transient\_%' AND option_name != '_transient_doing_cron' ;";
589
  $return = $wpdb->query( $element );
590
  break;
591
  }
609
  }
610
  //ajax clean cache
611
  public static function breeze_clean_cache() {
612
+ // Check whether we're clearing the cache for one subsite on the network.
613
+ $is_subsite = is_multisite() && ! is_network_admin();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614
 
615
+ // analysis size cache
616
+ $cachepath = untrailingslashit( breeze_get_cache_base_path( is_network_admin() ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
617
 
618
+ $size_cache = breeze_get_directory_size( $cachepath );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
619
 
620
+ // Analyze minification directory sizes.
621
+ $files_path = rtrim( WP_CONTENT_DIR, '/' ) . '/cache/breeze-minification';
622
+ if ( $is_subsite ) {
623
+ $blog_id = get_current_blog_id();
624
+ $files_path .= DIRECTORY_SEPARATOR . $blog_id;
625
+ }
626
+ $size_cache += breeze_get_directory_size( $files_path, array( 'index.html' ) );
627
 
628
+ $result = self::formatBytes( $size_cache );
629
 
630
+ //delete minify file
631
+ Breeze_MinificationCache::clear_minification();
632
  //delete all cache
633
  Breeze_PurgeCache::breeze_cache_flush();
634
 
667
  check_ajax_referer( '_breeze_purge_database', 'security' );
668
 
669
  $type = array('revisions','drafted','trash','comments','trackbacks','transient');
670
+ self::optimize_database( $type );
 
 
671
 
672
  echo json_encode(array('clear' => true));
673
  exit;
688
  }
689
 
690
  return $bytes;
691
+ }
692
+
693
+ /**
694
+ * Perform database optimization.
695
+ *
696
+ * @param array $items
697
+ */
698
+ public static function optimize_database( $items ) {
699
+ if ( is_multisite() && is_network_admin() ) {
700
+ $sites = get_sites(
701
+ array(
702
+ 'fields' => 'ids',
703
+ )
704
+ );
705
+
706
+ foreach ( $sites as $blog_id ) {
707
+ switch_to_blog( $blog_id );
708
+ foreach ( $items as $item ) {
709
+ self::cleanSystem( $item );
710
+ }
711
+ restore_current_blog();
712
+ }
713
+ } else {
714
+ foreach ( $items as $item ) {
715
+ self::cleanSystem( $item );
716
+ }
717
+ }
718
+ }
719
 
720
  }
721
 
inc/cache/config-cache.php CHANGED
@@ -23,46 +23,121 @@ if ( ! defined( 'ABSPATH' ) ) exit;
23
 
24
  class Breeze_ConfigCache {
25
 
26
- /*
27
- * Create advanced-cache file
28
- */
29
- public function write(){
30
- global $wp_filesystem;
31
-
32
- $file = untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php';
33
-
34
- $config = get_option('breeze_basic_settings');
35
-
36
- $file_string = '';
37
-
38
- if (!empty($config) && !empty( $config['breeze-active'] ) ) {
39
-
40
- $file_string = '<?php ' .
41
- "\n\r" . "defined( 'ABSPATH' ) || exit;" .
42
- "\n\r" . "define( 'BREEZE_ADVANCED_CACHE', true );" .
43
- "\n\r" . 'if ( is_admin() ) { return; }' .
44
- "\n\r" . "if ( ! @file_exists( '" . BREEZE_PLUGIN_DIR . "breeze.php' ) ) { return; }" .
45
- "\n\r" . "if ( ! @file_exists( '". WP_CONTENT_DIR . "/breeze-config/breeze-config.php' ) ) { return; }" .
46
- "\n\r" . "\$GLOBALS['breeze_config'] = include('". WP_CONTENT_DIR . "/breeze-config/breeze-config.php' );" .
47
- "\n\r" . "if ( empty( \$GLOBALS['breeze_config'] ) || empty( \$GLOBALS['breeze_config']['cache_options']['breeze-active'] ) ) { return; }" .
48
- "\n\r" . "if ( @file_exists( '". BREEZE_PLUGIN_DIR . "inc/cache/execute-cache.php' ) ) { include_once( '". BREEZE_PLUGIN_DIR . "inc/cache/execute-cache.php' ); }" . "\n\r";
49
-
50
- }
51
-
52
- if ( ! $wp_filesystem->put_contents( $file, $file_string ) ) {
53
- return false;
54
- }
55
-
56
- return true;
57
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  /**
60
  * Function write parameter to breeze-config
61
  * @return breeze_Cache
62
  */
63
  public static function write_config_cache(){
64
- $settings = get_option('breeze_basic_settings');
65
- $config = get_option('breeze_advanced_settings');
66
  $ecommerce_exclude_urls = array();
67
 
68
  $storage = array(
@@ -79,35 +154,41 @@ class Breeze_ConfigCache {
79
  $storage['disable_per_adminuser'] = $settings['breeze-disable-admin'];
80
  }
81
 
82
- $storage['exclude_url'] = array_merge($ecommerce_exclude_urls, $config['breeze-exclude-urls']);
 
 
 
83
 
84
- if(! self::write_config($storage)){
85
- return false;
86
- }
87
- return true;
88
  }
89
 
90
  /*
91
  * create file config storage parameter used for cache
92
  */
93
  public static function write_config( $config ) {
 
94
 
95
- global $wp_filesystem;
96
-
97
- $config_dir = WP_CONTENT_DIR . '/breeze-config';
 
 
98
 
99
- $site_url_parts = parse_url( site_url() );
100
 
101
- $config_file = $config_dir . '/breeze-config.php';
 
 
 
 
 
 
102
 
103
- $wp_filesystem->mkdir( $config_dir );
104
 
105
- $config_file_string = '<?php ' . "\n\r" . "defined( 'ABSPATH' ) || exit;" . "\n\r" . 'return ' . var_export( $config, true ) . '; ' . "\n\r";
106
- if ( ! $wp_filesystem->put_contents( $config_file, $config_file_string ) ) {
107
- return false;
108
- }
109
 
110
- return true;
111
  }
112
  //turn on / off wp cache
113
  public function toggle_caching( $status ) {
@@ -193,7 +274,7 @@ class Breeze_ConfigCache {
193
  $ret = false;
194
  }
195
 
196
- $folder = untrailingslashit( WP_CONTENT_DIR ) . '/cache/breeze';
197
 
198
  if ( ! $wp_filesystem->delete( $folder, true ) ) {
199
  $ret = false;
@@ -213,10 +294,8 @@ class Breeze_ConfigCache {
213
 
214
  global $wp_filesystem;
215
 
216
- $folder = untrailingslashit( WP_CONTENT_DIR ) . '/breeze-config';
217
- if ( ! $wp_filesystem->delete( $folder, true ) ) {
218
- return false;
219
- }
220
 
221
  return true;
222
  }
@@ -232,4 +311,4 @@ class Breeze_ConfigCache {
232
 
233
  return $instance;
234
  }
235
- }
23
 
24
  class Breeze_ConfigCache {
25
 
26
+ /**
27
+ * Create advanced-cache file
28
+ */
29
+ public function write() {
30
+ global $wp_filesystem;
31
+
32
+ $file = trailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php';
33
+
34
+ // Create array of configuration files and their corresponding sites' URLs.
35
+ $cache_configs = array(
36
+ 'breeze-config' => array(),
37
+ );
38
+ if ( is_multisite() ) {
39
+ // This is a multisite install, loop through all subsites.
40
+ $blogs = get_sites(
41
+ array(
42
+ 'fields' => 'ids',
43
+ )
44
+ );
45
+
46
+ foreach ( $blogs as $blog_id ) {
47
+ switch_to_blog( $blog_id );
48
+ $config = breeze_get_option( 'basic_settings' );
49
+ if ( ! empty( $config['breeze-active'] ) ) {
50
+ $inherit_option = get_option( 'breeze_inherit_settings' );
51
+
52
+ if ( '0' === $inherit_option ) {
53
+ // Site uses own (custom) configuration.
54
+ $cache_configs[ "breeze-config-{$blog_id}" ] = preg_replace( '(^https?://)', '', site_url() );
55
+ } else {
56
+ // Site uses global configuration.
57
+ $cache_configs['breeze-config'][] = preg_replace( '(^https?://)', '', site_url() );
58
+ }
59
+ }
60
+ restore_current_blog();
61
+ }
62
+ } else {
63
+ $config = breeze_get_option( 'basic_settings' );
64
+
65
+ if ( ! empty( $config['breeze-active'] ) ) {
66
+ $cache_configs['breeze-config'][] = preg_replace( '(^https?://)', '', site_url() );
67
+ }
68
+ }
69
+
70
+ if ( empty( $cache_configs ) || ( 1 === count( $cache_configs ) && empty( $cache_configs['breeze-config'] ) ) ) {
71
+ // No sites with caching enabled.
72
+ $this->clean_config();
73
+ return;
74
+ } else {
75
+ $file_string = '<?php ' .
76
+ "\n\r" . 'defined( \'ABSPATH\' ) || exit;' .
77
+ "\n\r" . 'define( \'BREEZE_ADVANCED_CACHE\', true );' .
78
+ "\n\r" . 'if ( is_admin() ) { return; }' .
79
+ "\n\r" . 'if ( ! @file_exists( \'' . BREEZE_PLUGIN_DIR . 'breeze.php\' ) ) { return; }';
80
+ }
81
+
82
+ if ( 1 === count( $cache_configs ) ) {
83
+ // Only 1 config file available.
84
+ $blog_file = trailingslashit( WP_CONTENT_DIR ) . 'breeze-config/breeze-config.php';
85
+ $file_string .= "\n\$config = '$blog_file';";
86
+ } else {
87
+ // Multiple configuration files, load appropriate one by comparing URLs.
88
+ $file_string .= "\n\r" . '$domain = strtolower( stripslashes( $_SERVER[\'HTTP_HOST\'] ) );' .
89
+ "\n" . 'if ( substr( $domain, -3 ) == \':80\' ) {' .
90
+ "\n" . ' $domain = substr( $domain, 0, -3 );' .
91
+ "\n" . '} elseif ( substr( $domain, -4 ) == \':443\' ) {' .
92
+ "\n" . ' $domain = substr( $domain, 0, -4 );' .
93
+ "\n" . '}';
94
+ if ( is_subdomain_install() ) {
95
+ $file_string .= "\n" . '$site_url = $domain;';
96
+ } else {
97
+ $file_string .= "\n" . 'list( $path ) = explode( \'?\', stripslashes( $_SERVER[\'REQUEST_URI\'] ) );' .
98
+ "\n" . '$path_parts = explode( \'/\', rtrim( $path, \'/\' ) );' .
99
+ "\n" . '$site_url = $domain . ( ! empty( $path_parts[1] ) ? \'/\' . $path_parts[1] : \'\' );';
100
+ }
101
+
102
+ // Create conditional blocks for each site.
103
+ $file_string .= "\n" . 'switch ( $site_url ) {';
104
+ foreach ( array_reverse( $cache_configs ) as $filename => $urls ) {
105
+ $blog_file = trailingslashit( WP_CONTENT_DIR ) . 'breeze-config/' . $filename . '.php';
106
+
107
+ if ( ! is_array( $urls ) ) {
108
+ $urls = array( $urls );
109
+ }
110
+
111
+ if ( empty( $urls ) || empty( $urls[0] ) ) {
112
+ continue;
113
+ }
114
+
115
+ foreach ( $urls as $site_url ) {
116
+ $file_string .= "\n\tcase '$site_url':";
117
+ }
118
+ $file_string .= "\n\t\t\$config = '$blog_file';" .
119
+ "\n\t\tbreak;";
120
+ }
121
+ $file_string .= "\n}";
122
+ }
123
+
124
+ $file_string .= "\nif ( empty( \$config ) || ! @file_exists( \$config ) ) { return; }" .
125
+ "\n\$GLOBALS['breeze_config'] = include \$config;" .
126
+ "\n" . 'if ( empty( $GLOBALS[\'breeze_config\'] ) || empty( $GLOBALS[\'breeze_config\'][\'cache_options\'][\'breeze-active\'] ) ) { return; }' .
127
+ "\n" . 'if ( @file_exists( \'' . BREEZE_PLUGIN_DIR . 'inc/cache/execute-cache.php\' ) ) {' .
128
+ "\n" . ' include_once \'' . BREEZE_PLUGIN_DIR . 'inc/cache/execute-cache.php\';' .
129
+ "\n" . '}' . "\n";
130
+
131
+ return $wp_filesystem->put_contents( $file, $file_string );
132
+ }
133
 
134
  /**
135
  * Function write parameter to breeze-config
136
  * @return breeze_Cache
137
  */
138
  public static function write_config_cache(){
139
+ $settings = breeze_get_option( 'basic_settings' );
140
+ $config = breeze_get_option( 'advanced_settings' );
141
  $ecommerce_exclude_urls = array();
142
 
143
  $storage = array(
154
  $storage['disable_per_adminuser'] = $settings['breeze-disable-admin'];
155
  }
156
 
157
+ $storage['exclude_url'] = array_merge(
158
+ $ecommerce_exclude_urls,
159
+ ! empty( $config['breeze-exclude-urls'] ) ? $config['breeze-exclude-urls'] : array()
160
+ );
161
 
162
+ return self::write_config( $storage );
 
 
 
163
  }
164
 
165
  /*
166
  * create file config storage parameter used for cache
167
  */
168
  public static function write_config( $config ) {
169
+ global $wp_filesystem;
170
 
171
+ $config_dir = trailingslashit( WP_CONTENT_DIR ) . 'breeze-config';
172
+ $filename = 'breeze-config';
173
+ if ( is_multisite() && ! is_network_admin() ) {
174
+ $filename .= '-' . get_current_blog_id();
175
+ }
176
 
177
+ $config_file = $config_dir . DIRECTORY_SEPARATOR . $filename . '.php';
178
 
179
+ if ( is_multisite() && ! is_network_admin() && breeze_does_inherit_settings() ) {
180
+ // Site inherits network-level setting, do not create separate configuration file and remove existing configuration file.
181
+ if ( $wp_filesystem->exists( $config_file ) ) {
182
+ $wp_filesystem->delete( $config_file, true );
183
+ }
184
+ return;
185
+ }
186
 
187
+ $wp_filesystem->mkdir( $config_dir );
188
 
189
+ $config_file_string = '<?php ' . "\n\r" . "defined( 'ABSPATH' ) || exit;" . "\n\r" . 'return ' . var_export( $config, true ) . '; ' . "\n\r";
 
 
 
190
 
191
+ return $wp_filesystem->put_contents( $config_file, $config_file_string );
192
  }
193
  //turn on / off wp cache
194
  public function toggle_caching( $status ) {
274
  $ret = false;
275
  }
276
 
277
+ $folder = untrailingslashit( breeze_get_cache_base_path() );
278
 
279
  if ( ! $wp_filesystem->delete( $folder, true ) ) {
280
  $ret = false;
294
 
295
  global $wp_filesystem;
296
 
297
+ $folder = untrailingslashit( WP_CONTENT_DIR ) . '/breeze-config';
298
+ return $wp_filesystem->delete( $folder, true );
 
 
299
 
300
  return true;
301
  }
311
 
312
  return $instance;
313
  }
314
+ }
inc/cache/execute-cache.php CHANGED
@@ -1,10 +1,13 @@
1
  <?php
2
- /*
3
  * Based on some work of https://github.com/tlovett1/simple-cache/blob/master/inc/dropins/file-based-page-cache.php
4
  */
5
  defined('ABSPATH') || exit;
6
- // Include and instantiate the class.
7
 
 
 
 
 
8
  require_once 'Mobile-Detect-2.8.25/Mobile_Detect.php';
9
  $detect = new \Cloudways\Breeze\Mobile_Detect\Mobile_Detect;
10
 
@@ -27,10 +30,16 @@ if (!preg_match('#index\.php$#i', $_SERVER['REQUEST_URI']) && in_array($file_ext
27
  return;
28
  }
29
 
 
 
 
 
 
 
30
  $url_path = breeze_get_url_path();
31
  $user_logged = false;
32
  $filename = $url_path . 'guest';
33
- // Don't cache
34
  if (!empty($_COOKIE)) {
35
  $wp_cookies = array('wordpressuser_', 'wordpresspass_', 'wordpress_sec_', 'wordpress_logged_in_');
36
 
@@ -136,31 +145,18 @@ function breeze_cache($buffer, $flags)
136
  require_once(ABSPATH . '/wp-admin/includes/file.php');
137
  WP_Filesystem();
138
  }
139
- $url_path = breeze_get_url_path();
140
 
141
- // Make sure we can read/write files and that proper folders exist
142
- if (!$wp_filesystem->exists(untrailingslashit(WP_CONTENT_DIR) . '/cache')) {
143
- if (!$wp_filesystem->mkdir(untrailingslashit(WP_CONTENT_DIR) . '/cache')) {
144
- // Can not cache!
145
- return $buffer;
146
- }
147
- }
148
 
149
- if (!$wp_filesystem->exists(untrailingslashit(WP_CONTENT_DIR) . '/cache/breeze')) {
150
- if (!$wp_filesystem->mkdir(untrailingslashit(WP_CONTENT_DIR) . '/cache/breeze')) {
151
- // Can not cache!
152
- return $buffer;
153
- }
154
- }
155
-
156
- if (!$wp_filesystem->exists(untrailingslashit(WP_CONTENT_DIR) . '/cache/breeze/' . md5($url_path))) {
157
- if (!$wp_filesystem->mkdir(untrailingslashit(WP_CONTENT_DIR) . '/cache/breeze/' . md5($url_path))) {
158
- // Can not cache!
159
- return $buffer;
160
- }
161
- }
162
 
163
- $path = untrailingslashit(WP_CONTENT_DIR) . '/cache/breeze/' . md5($url_path) . '/';
 
 
 
 
 
164
 
165
  $modified_time = time(); // Make sure modified time is consistent
166
 
@@ -294,7 +290,7 @@ function breeze_serve_cache($filename, $url_path, $X1,$opts)
294
  }
295
 
296
 
297
- $path = rtrim(WP_CONTENT_DIR, '/') . '/cache/breeze/' . md5($url_path) . '/' . $file_name;
298
 
299
  $modified_time = (int)@filemtime($path);
300
 
@@ -378,4 +374,4 @@ function check_exclude_page($opts_config,$current_url){
378
  }
379
 
380
  return false;
381
- }
1
  <?php
2
+ /*
3
  * Based on some work of https://github.com/tlovett1/simple-cache/blob/master/inc/dropins/file-based-page-cache.php
4
  */
5
  defined('ABSPATH') || exit;
 
6
 
7
+ // Load helper functions.
8
+ require_once dirname( __DIR__ ) . '/functions.php';
9
+
10
+ // Include and instantiate the class.
11
  require_once 'Mobile-Detect-2.8.25/Mobile_Detect.php';
12
  $detect = new \Cloudways\Breeze\Mobile_Detect\Mobile_Detect;
13
 
30
  return;
31
  }
32
 
33
+ // @TODO: Remove debugging code.
34
+ if ( isset( $_GET['debug_config'] ) ) {
35
+ var_dump( $GLOBALS['breeze_config'] );
36
+ exit;
37
+ }
38
+
39
  $url_path = breeze_get_url_path();
40
  $user_logged = false;
41
  $filename = $url_path . 'guest';
42
+ // Don't cache
43
  if (!empty($_COOKIE)) {
44
  $wp_cookies = array('wordpressuser_', 'wordpresspass_', 'wordpress_sec_', 'wordpress_logged_in_');
45
 
145
  require_once(ABSPATH . '/wp-admin/includes/file.php');
146
  WP_Filesystem();
147
  }
148
+ $url_path = breeze_get_url_path();
149
 
150
+ $cache_base_path = breeze_get_cache_base_path();
 
 
 
 
 
 
151
 
152
+ $path = $cache_base_path . md5( $url_path );
 
 
 
 
 
 
 
 
 
 
 
 
153
 
154
+ // Make sure we can read/write files and that proper folders exist
155
+ if ( ! wp_mkdir_p( $path ) ) {
156
+ // Can not cache!
157
+ return $buffer;
158
+ }
159
+ $path .= '/';
160
 
161
  $modified_time = time(); // Make sure modified time is consistent
162
 
290
  }
291
 
292
 
293
+ $path = breeze_get_cache_base_path() . md5($url_path) . '/' . $file_name;
294
 
295
  $modified_time = (int)@filemtime($path);
296
 
374
  }
375
 
376
  return false;
377
+ }
inc/cache/purge-cache.php CHANGED
@@ -38,7 +38,7 @@ class Breeze_PurgeCache {
38
  * @since 1.3
39
  */
40
  public function set_comment_cookie_exceptions($comment, $user) {
41
- $config = get_option('breeze_basic_settings');
42
  // File based caching only
43
  if (!empty($config['breeze-active'])) {
44
 
@@ -57,7 +57,7 @@ class Breeze_PurgeCache {
57
  return;
58
  }
59
 
60
- $config = get_option('breeze_basic_settings');
61
 
62
  // File based caching only
63
  if (!empty($config['breeze-active'])) {
@@ -69,7 +69,7 @@ class Breeze_PurgeCache {
69
  if (empty($approved)) {
70
  return;
71
  }
72
- $config = get_option('breeze_basic_settings');
73
  // File based caching only
74
  if (!empty($config['breeze-active'])) {
75
  $post_id = $commentdata['comment_post_ID'];
@@ -82,15 +82,15 @@ class Breeze_PurgeCache {
82
  }
83
 
84
  $url_path = get_permalink($post_id);
85
- if ( $wp_filesystem->exists( untrailingslashit( WP_CONTENT_DIR ) . '/cache/breeze/' . md5($url_path) ) ) {
86
- $wp_filesystem->rmdir( untrailingslashit( WP_CONTENT_DIR ) . '/cache/breeze/' . md5($url_path), true );
87
  }
88
  }
89
  }
90
 
91
  // if a comments status changes, purge it's parent posts cache
92
  public function purge_post_on_comment_status_change($comment_ID, $comment_status) {
93
- $config = get_option('breeze_basic_settings');
94
 
95
  // File based caching only
96
  if (!empty($config['breeze-active'])) {
@@ -104,8 +104,8 @@ class Breeze_PurgeCache {
104
 
105
  $url_path = get_permalink($post_id);
106
 
107
- if ( $wp_filesystem->exists( untrailingslashit( WP_CONTENT_DIR ) . '/cache/breeze/' . md5($url_path) ) ) {
108
- $wp_filesystem->rmdir( untrailingslashit( WP_CONTENT_DIR ) . '/cache/breeze/' . md5($url_path), true );
109
  }
110
  }
111
  }
@@ -117,9 +117,10 @@ class Breeze_PurgeCache {
117
 
118
  require_once( ABSPATH . 'wp-admin/includes/file.php');
119
 
120
- WP_Filesystem();
121
 
122
- $wp_filesystem->rmdir( untrailingslashit( WP_CONTENT_DIR ) . '/cache/breeze', true );
 
123
 
124
  if ( function_exists( 'wp_cache_flush' ) ) {
125
  wp_cache_flush();
@@ -139,7 +140,7 @@ class Breeze_PurgeCache {
139
  $ret = false;
140
  }
141
 
142
- $folder = untrailingslashit( WP_CONTENT_DIR ) . '/cache/breeze';
143
 
144
  if ( ! $wp_filesystem->delete( $folder, true ) ) {
145
  $ret = false;
@@ -166,7 +167,7 @@ class Breeze_PurgeCache {
166
  }
167
 
168
  }
169
- $settings = get_option('breeze_basic_settings');
170
- if($settings['breeze-active']){
171
- Breeze_PurgeCache::factory();
172
  }
38
  * @since 1.3
39
  */
40
  public function set_comment_cookie_exceptions($comment, $user) {
41
+ $config = breeze_get_option( 'basic_settings' );
42
  // File based caching only
43
  if (!empty($config['breeze-active'])) {
44
 
57
  return;
58
  }
59
 
60
+ $config = breeze_get_option( 'basic_settings' );
61
 
62
  // File based caching only
63
  if (!empty($config['breeze-active'])) {
69
  if (empty($approved)) {
70
  return;
71
  }
72
+ $config = breeze_get_option( 'basic_settings' );
73
  // File based caching only
74
  if (!empty($config['breeze-active'])) {
75
  $post_id = $commentdata['comment_post_ID'];
82
  }
83
 
84
  $url_path = get_permalink($post_id);
85
+ if ( $wp_filesystem->exists( breeze_get_cache_base_path() . md5( $url_path ) ) ) {
86
+ $wp_filesystem->rmdir( breeze_get_cache_base_path() . md5( $url_path ), true );
87
  }
88
  }
89
  }
90
 
91
  // if a comments status changes, purge it's parent posts cache
92
  public function purge_post_on_comment_status_change($comment_ID, $comment_status) {
93
+ $config = breeze_get_option( 'basic_settings' );
94
 
95
  // File based caching only
96
  if (!empty($config['breeze-active'])) {
104
 
105
  $url_path = get_permalink($post_id);
106
 
107
+ if ( $wp_filesystem->exists( breeze_get_cache_base_path() . md5( $url_path ) ) ) {
108
+ $wp_filesystem->rmdir( breeze_get_cache_base_path() . md5( $url_path ), true );
109
  }
110
  }
111
  }
117
 
118
  require_once( ABSPATH . 'wp-admin/includes/file.php');
119
 
120
+ WP_Filesystem();
121
 
122
+ $cache_path = breeze_get_cache_base_path( is_network_admin() );
123
+ $wp_filesystem->rmdir( untrailingslashit( $cache_path ), true );
124
 
125
  if ( function_exists( 'wp_cache_flush' ) ) {
126
  wp_cache_flush();
140
  $ret = false;
141
  }
142
 
143
+ $folder = untrailingslashit( breeze_get_cache_base_path() );
144
 
145
  if ( ! $wp_filesystem->delete( $folder, true ) ) {
146
  $ret = false;
167
  }
168
 
169
  }
170
+ $settings = breeze_get_option( 'basic_settings' );
171
+ if ( isset( $settings['breeze-active'] ) && $settings['breeze-active'] ) {
172
+ Breeze_PurgeCache::factory();
173
  }
inc/cache/purge-per-time.php CHANGED
@@ -101,8 +101,8 @@ class Breeze_PurgeCacheTime {
101
  }
102
  }
103
 
104
- $basic = get_option('breeze_basic_settings');
105
- $varnish = get_option('breeze_varnish_cache');
106
  //Enabled auto purge the varnish caching by time life
107
  $params = array(
108
  'breeze-active' => (isset($basic['breeze-active'])?(int)$basic['breeze-active']:0),
@@ -113,4 +113,3 @@ $params = array(
113
  if($params['breeze-active'] || $params['breeze-varnish-purge']){
114
  $purgeTime = new Breeze_PurgeCacheTime($params);
115
  }
116
-
101
  }
102
  }
103
 
104
+ $basic = breeze_get_option( 'basic_settings' );
105
+ $varnish = breeze_get_option( 'varnish_cache' );
106
  //Enabled auto purge the varnish caching by time life
107
  $params = array(
108
  'breeze-active' => (isset($basic['breeze-active'])?(int)$basic['breeze-active']:0),
113
  if($params['breeze-active'] || $params['breeze-varnish-purge']){
114
  $purgeTime = new Breeze_PurgeCacheTime($params);
115
  }
 
inc/cache/purge-varnish.php CHANGED
@@ -19,33 +19,25 @@
19
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
  */
21
  defined('ABSPATH') || die('No direct script access allowed!');
22
-
23
  class Breeze_PurgeVarnish {
24
  protected $blogId;
25
-
26
  protected $urlsPurge = array();
27
-
28
  protected $autoPurge = false;
29
-
30
  protected $actions = array(
31
  'switch_theme', // After a theme is changed
32
  'save_post', // Save a post
33
  'deleted_post', // Delete a post
34
  'edit_post', // Edit a post - includes leaving comments
35
  );
36
-
37
  protected $actionsNoId = array('switch_theme');
38
-
39
  public function __construct(){
40
  global $blog_id;
41
  $this->blogId = $blog_id;
42
- $settings = get_option('breeze_varnish_cache');
43
  //storage config
44
  if(!empty($settings['auto-purge-varnish'])) $this->autoPurge = (int)$settings['auto-purge-varnish'];
45
-
46
  add_action('init', array($this, 'init'));
47
  }
48
-
49
  public function init()
50
  {
51
  //Push urlsPurge
@@ -62,17 +54,13 @@ class Breeze_PurgeVarnish {
62
  }
63
  }
64
  }
65
-
66
  //Pust urlsPurge after comment
67
  add_action('comment_post',array($this,'purge_post_on_comment'),10,3);
68
  add_action('wp_set_comment_status', array($this, 'purge_post_on_comment_status'), 10, 2);
69
  }
70
-
71
  //Execute Purge
72
  add_action('shutdown', array($this, 'breeze_execute_purge'));
73
-
74
  }
75
-
76
  /**
77
  * Execute Purge
78
  *
@@ -80,7 +68,6 @@ class Breeze_PurgeVarnish {
80
  public function breeze_execute_purge()
81
  {
82
  $urlsPurge = array_unique($this->urlsPurge);
83
-
84
  if (!empty($urlsPurge)) {
85
  foreach ($urlsPurge as $url) {
86
  $this->purge_cache($url);
@@ -94,10 +81,10 @@ class Breeze_PurgeVarnish {
94
  }
95
  if(isset($_GET['breeze_purge']) && check_admin_referer('breeze_purge_cache')){
96
  //clear varnish cache
97
- $this->purge_cache($homepage);
 
98
  //clear static cache
99
  $size_cache = Breeze_Configuration::breeze_clean_cache();
100
-
101
  if((int)$size_cache > 0){
102
  echo '<div id="message-clear-cache-top" style="margin: 10px 0px 10px 0;padding: 10px;" class="notice notice-success" ><strong>'.__('Cache data has been purged: ','breeze') .$size_cache.__(' Kb static cache cleaned','breeze').'</strong></div>';
103
  }else{
@@ -106,7 +93,6 @@ class Breeze_PurgeVarnish {
106
  }
107
  }
108
  }
109
-
110
  /**
111
  * Purge varnish cache
112
  *
@@ -115,41 +101,32 @@ class Breeze_PurgeVarnish {
115
  {
116
  $parseUrl = parse_url($url);
117
  $pregex = '';
118
-
119
  // Default method is URLPURGE to purge only one object, this method is specific to cloudways configuration
120
  $purge_method = 'URLPURGE';
121
-
122
  // Use PURGE method when purging all site
123
  if (isset($parseUrl['query']) && ($parseUrl['query'] == 'breeze')) {
124
  // The regex is not needed as cloudways configuration purge all the cache of the domain when a PURGE is done
125
  $pregex = '.*';
126
  $purge_method = 'PURGE';
127
  }
128
-
129
  // Determine the path
130
  $path = '';
131
  if (isset($parseUrl['path'])) {
132
  $path = $parseUrl['path'];
133
  }
134
-
135
  // Determine the schema
136
  $schema = 'http://';
137
  if (isset($parseUrl['scheme'])) {
138
  $schema = $parseUrl['scheme'] . '://';
139
  }
140
-
141
  // Determine the host
142
  $host = $parseUrl['host'];
143
-
144
- $config = get_option('breeze_varnish_cache');
145
  $varnish_host = isset($config['breeze-varnish-server-ip'])?$config['breeze-varnish-server-ip']:'127.0.0.1';
146
-
147
  $purgeme = $varnish_host . $path . $pregex;
148
-
149
  if (!empty($parseUrl['query']) && $parseUrl['query'] != 'breeze') {
150
  $purgeme .= '?' . $parseUrl['query'];
151
  }
152
-
153
  $request_args = array('method' => $purge_method, 'headers' => array('Host' => $host, 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'), 'sslverify' => false);
154
  $response = wp_remote_request($schema . $purgeme, $request_args);
155
  if(is_wp_error($response) || $response['response']['code']!='200') {
@@ -161,7 +138,6 @@ class Breeze_PurgeVarnish {
161
  $response = wp_remote_request($schema . $purgeme, $request_args);
162
  }
163
  }
164
-
165
  //check permission
166
  public function check_permission()
167
  {
@@ -172,11 +148,10 @@ class Breeze_PurgeVarnish {
172
  */
173
  public function purge_post($postId)
174
  {
175
- if ( 'save_post' === current_action() && did_action( 'edit_post' ) ) {
176
  // Prevent triggering this method twice when posts are updated.
177
- return;
178
  }
179
-
180
  $this->pushUrl($postId);
181
  }
182
  /*
@@ -207,24 +182,19 @@ class Breeze_PurgeVarnish {
207
  // the home page and any associated tags and categories
208
  $valid_post_status = array('publish', 'private', 'trash');
209
  $this_post_status = get_post_status($postId);
210
-
211
  // Not all post types are created equal
212
  $invalid_post_type = array('nav_menu_item', 'revision');
213
  $noarchive_post_type = array('post', 'page');
214
  $this_post_type = get_post_type($postId);
215
-
216
  // Determine the route for the rest API
217
  // This will need to be revisted if WP updates the version.
218
  $rest_api_route = 'wp/v2';
219
-
220
  // array to collect all our URLs
221
  $listofurls = array();
222
-
223
  // Verify we have a permalink and that we're a valid post status and a not an invalid post type
224
  if (get_permalink($postId) == true && in_array($this_post_status, $valid_post_status) && !in_array($this_post_type, $invalid_post_type)) {
225
  // Post URL
226
  array_push($listofurls, get_permalink($postId));
227
-
228
  // JSON API Permalink for the post based on type
229
  // We only want to do this if the rest_base exists
230
  $post_type_object = get_post_type_object($this_post_type);
@@ -237,22 +207,18 @@ class Breeze_PurgeVarnish {
237
  }
238
  if(isset($rest_permalink))
239
  array_push($listofurls, $rest_permalink);
240
-
241
  // Add in AMP permalink if Automattic's AMP is installed
242
  if (function_exists('amp_get_permalink')) {
243
  array_push($listofurls, amp_get_permalink($postId));
244
  }
245
-
246
  // Regular AMP url for posts
247
  array_push($listofurls, get_permalink($postId) . 'amp/');
248
-
249
  // Also clean URL for trashed post.
250
  if ($this_post_status == 'trash') {
251
  $trashpost = get_permalink($postId);
252
  $trashpost = str_replace('__trashed', '', $trashpost);
253
  array_push($listofurls, $trashpost, $trashpost . 'feed/');
254
  }
255
-
256
  // Category purge based on Donnacha's work in WP Super Cache
257
  $categories = get_the_category($postId);
258
  if ($categories) {
@@ -273,7 +239,6 @@ class Breeze_PurgeVarnish {
273
  );
274
  }
275
  }
276
-
277
  // Author URL
278
  $author_id = get_post_field('post_author', $postId);
279
  array_push($listofurls,
@@ -281,8 +246,6 @@ class Breeze_PurgeVarnish {
281
  get_author_feed_link($author_id),
282
  get_rest_url() . $rest_api_route . '/users/' . $author_id . '/'
283
  );
284
-
285
-
286
  // Archives and their feeds
287
  if ($this_post_type && !in_array($this_post_type, $noarchive_post_type)) {
288
  array_push($listofurls,
@@ -291,8 +254,6 @@ class Breeze_PurgeVarnish {
291
  // Need to add in JSON?
292
  );
293
  }
294
-
295
-
296
  // Feeds
297
  array_push($listofurls,
298
  get_bloginfo_rss('rdf_url'),
@@ -302,39 +263,33 @@ class Breeze_PurgeVarnish {
302
  get_bloginfo_rss('comments_rss2_url'),
303
  get_post_comments_feed_link($postId)
304
  );
305
-
306
  // Home Pages and (if used) posts page
307
  array_push($listofurls,
308
  get_rest_url(),
309
  home_url() . '/'
310
  );
311
-
312
  if (get_option('show_on_front') == 'page') {
313
  // Ensure we have a page_for_posts setting to avoid empty URL
314
  if (get_option('page_for_posts')) {
315
  array_push($listofurls, get_permalink(get_option('page_for_posts')));
316
  }
317
  }
318
-
319
  } else {
320
  // Nothing
321
  return;
322
  }
323
-
324
  // Now flush all the URLs we've collected provided the array isn't empty
325
- if (!empty($listofurls)) {
326
- $this->urlsPurge = array_filter(
327
- array_unique(
328
- array_merge(
329
- $this->urlsPurge,
330
- $listofurls
331
- ),
332
  SORT_REGULAR
333
- )
334
  );
335
  }
336
-
337
  }
338
  }
339
-
340
  new Breeze_PurgeVarnish();
19
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
  */
21
  defined('ABSPATH') || die('No direct script access allowed!');
 
22
  class Breeze_PurgeVarnish {
23
  protected $blogId;
 
24
  protected $urlsPurge = array();
 
25
  protected $autoPurge = false;
 
26
  protected $actions = array(
27
  'switch_theme', // After a theme is changed
28
  'save_post', // Save a post
29
  'deleted_post', // Delete a post
30
  'edit_post', // Edit a post - includes leaving comments
31
  );
 
32
  protected $actionsNoId = array('switch_theme');
 
33
  public function __construct(){
34
  global $blog_id;
35
  $this->blogId = $blog_id;
36
+ $settings = breeze_get_option( 'varnish_cache' );
37
  //storage config
38
  if(!empty($settings['auto-purge-varnish'])) $this->autoPurge = (int)$settings['auto-purge-varnish'];
 
39
  add_action('init', array($this, 'init'));
40
  }
 
41
  public function init()
42
  {
43
  //Push urlsPurge
54
  }
55
  }
56
  }
 
57
  //Pust urlsPurge after comment
58
  add_action('comment_post',array($this,'purge_post_on_comment'),10,3);
59
  add_action('wp_set_comment_status', array($this, 'purge_post_on_comment_status'), 10, 2);
60
  }
 
61
  //Execute Purge
62
  add_action('shutdown', array($this, 'breeze_execute_purge'));
 
63
  }
 
64
  /**
65
  * Execute Purge
66
  *
68
  public function breeze_execute_purge()
69
  {
70
  $urlsPurge = array_unique($this->urlsPurge);
 
71
  if (!empty($urlsPurge)) {
72
  foreach ($urlsPurge as $url) {
73
  $this->purge_cache($url);
81
  }
82
  if(isset($_GET['breeze_purge']) && check_admin_referer('breeze_purge_cache')){
83
  //clear varnish cache
84
+ $admin = new Breeze_Admin();
85
+ $admin->breeze_clear_varnish();
86
  //clear static cache
87
  $size_cache = Breeze_Configuration::breeze_clean_cache();
 
88
  if((int)$size_cache > 0){
89
  echo '<div id="message-clear-cache-top" style="margin: 10px 0px 10px 0;padding: 10px;" class="notice notice-success" ><strong>'.__('Cache data has been purged: ','breeze') .$size_cache.__(' Kb static cache cleaned','breeze').'</strong></div>';
90
  }else{
93
  }
94
  }
95
  }
 
96
  /**
97
  * Purge varnish cache
98
  *
101
  {
102
  $parseUrl = parse_url($url);
103
  $pregex = '';
 
104
  // Default method is URLPURGE to purge only one object, this method is specific to cloudways configuration
105
  $purge_method = 'URLPURGE';
 
106
  // Use PURGE method when purging all site
107
  if (isset($parseUrl['query']) && ($parseUrl['query'] == 'breeze')) {
108
  // The regex is not needed as cloudways configuration purge all the cache of the domain when a PURGE is done
109
  $pregex = '.*';
110
  $purge_method = 'PURGE';
111
  }
 
112
  // Determine the path
113
  $path = '';
114
  if (isset($parseUrl['path'])) {
115
  $path = $parseUrl['path'];
116
  }
 
117
  // Determine the schema
118
  $schema = 'http://';
119
  if (isset($parseUrl['scheme'])) {
120
  $schema = $parseUrl['scheme'] . '://';
121
  }
 
122
  // Determine the host
123
  $host = $parseUrl['host'];
124
+ $config = breeze_get_option( 'varnish_cache' );
 
125
  $varnish_host = isset($config['breeze-varnish-server-ip'])?$config['breeze-varnish-server-ip']:'127.0.0.1';
 
126
  $purgeme = $varnish_host . $path . $pregex;
 
127
  if (!empty($parseUrl['query']) && $parseUrl['query'] != 'breeze') {
128
  $purgeme .= '?' . $parseUrl['query'];
129
  }
 
130
  $request_args = array('method' => $purge_method, 'headers' => array('Host' => $host, 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'), 'sslverify' => false);
131
  $response = wp_remote_request($schema . $purgeme, $request_args);
132
  if(is_wp_error($response) || $response['response']['code']!='200') {
138
  $response = wp_remote_request($schema . $purgeme, $request_args);
139
  }
140
  }
 
141
  //check permission
142
  public function check_permission()
143
  {
148
  */
149
  public function purge_post($postId)
150
  {
151
+ if ( 'save_post' === current_action() && did_action( 'edit_post' ) ) {
152
  // Prevent triggering this method twice when posts are updated.
153
+ return;
154
  }
 
155
  $this->pushUrl($postId);
156
  }
157
  /*
182
  // the home page and any associated tags and categories
183
  $valid_post_status = array('publish', 'private', 'trash');
184
  $this_post_status = get_post_status($postId);
 
185
  // Not all post types are created equal
186
  $invalid_post_type = array('nav_menu_item', 'revision');
187
  $noarchive_post_type = array('post', 'page');
188
  $this_post_type = get_post_type($postId);
 
189
  // Determine the route for the rest API
190
  // This will need to be revisted if WP updates the version.
191
  $rest_api_route = 'wp/v2';
 
192
  // array to collect all our URLs
193
  $listofurls = array();
 
194
  // Verify we have a permalink and that we're a valid post status and a not an invalid post type
195
  if (get_permalink($postId) == true && in_array($this_post_status, $valid_post_status) && !in_array($this_post_type, $invalid_post_type)) {
196
  // Post URL
197
  array_push($listofurls, get_permalink($postId));
 
198
  // JSON API Permalink for the post based on type
199
  // We only want to do this if the rest_base exists
200
  $post_type_object = get_post_type_object($this_post_type);
207
  }
208
  if(isset($rest_permalink))
209
  array_push($listofurls, $rest_permalink);
 
210
  // Add in AMP permalink if Automattic's AMP is installed
211
  if (function_exists('amp_get_permalink')) {
212
  array_push($listofurls, amp_get_permalink($postId));
213
  }
 
214
  // Regular AMP url for posts
215
  array_push($listofurls, get_permalink($postId) . 'amp/');
 
216
  // Also clean URL for trashed post.
217
  if ($this_post_status == 'trash') {
218
  $trashpost = get_permalink($postId);
219
  $trashpost = str_replace('__trashed', '', $trashpost);
220
  array_push($listofurls, $trashpost, $trashpost . 'feed/');
221
  }
 
222
  // Category purge based on Donnacha's work in WP Super Cache
223
  $categories = get_the_category($postId);
224
  if ($categories) {
239
  );
240
  }
241
  }
 
242
  // Author URL
243
  $author_id = get_post_field('post_author', $postId);
244
  array_push($listofurls,
246
  get_author_feed_link($author_id),
247
  get_rest_url() . $rest_api_route . '/users/' . $author_id . '/'
248
  );
 
 
249
  // Archives and their feeds
250
  if ($this_post_type && !in_array($this_post_type, $noarchive_post_type)) {
251
  array_push($listofurls,
254
  // Need to add in JSON?
255
  );
256
  }
 
 
257
  // Feeds
258
  array_push($listofurls,
259
  get_bloginfo_rss('rdf_url'),
263
  get_bloginfo_rss('comments_rss2_url'),
264
  get_post_comments_feed_link($postId)
265
  );
 
266
  // Home Pages and (if used) posts page
267
  array_push($listofurls,
268
  get_rest_url(),
269
  home_url() . '/'
270
  );
 
271
  if (get_option('show_on_front') == 'page') {
272
  // Ensure we have a page_for_posts setting to avoid empty URL
273
  if (get_option('page_for_posts')) {
274
  array_push($listofurls, get_permalink(get_option('page_for_posts')));
275
  }
276
  }
 
277
  } else {
278
  // Nothing
279
  return;
280
  }
 
281
  // Now flush all the URLs we've collected provided the array isn't empty
282
+ if (!empty($listofurls)) {
283
+ $this->urlsPurge = array_filter(
284
+ array_unique(
285
+ array_merge(
286
+ $this->urlsPurge,
287
+ $listofurls
288
+ ),
289
  SORT_REGULAR
290
+ )
291
  );
292
  }
 
293
  }
294
  }
 
295
  new Breeze_PurgeVarnish();
inc/cdn-integration/breeze-cdn-integration.php CHANGED
@@ -30,7 +30,7 @@ class Breeze_CDN_Integration{
30
  * Execute rewrite cdn
31
  */
32
  public function handle_rewrite_cdn(){
33
- $cdn_integration = get_option('breeze_cdn_integration');
34
 
35
  if(empty($cdn_integration) || empty($cdn_integration['cdn-active'])){
36
  return;
@@ -55,4 +55,4 @@ class Breeze_CDN_Integration{
55
  public static function instance(){
56
  new self();
57
  }
58
- }
30
  * Execute rewrite cdn
31
  */
32
  public function handle_rewrite_cdn(){
33
+ $cdn_integration = breeze_get_option( 'cdn_integration' );
34
 
35
  if(empty($cdn_integration) || empty($cdn_integration['cdn-active'])){
36
  return;
55
  public static function instance(){
56
  new self();
57
  }
58
+ }
inc/functions.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @copyright 2017 Cloudways https://www.cloudways.com
4
+ *
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation; either version 2 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+ defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
20
+
21
+ /**
22
+ * Get base path for the page cache directory.
23
+ *
24
+ * @param bool $is_network Whether to include the blog ID in the path on multisite.
25
+ * @return string
26
+ */
27
+ function breeze_get_cache_base_path( $is_network = false ) {
28
+ $path = rtrim( WP_CONTENT_DIR, '/\\' ) . '/cache/breeze/';
29
+
30
+ if ( ! $is_network && is_multisite() ) {
31
+ global $blog_id;
32
+
33
+ if ( ! empty( $blog_id ) ) {
34
+ $path .= abs( intval( $blog_id ) ) . DIRECTORY_SEPARATOR;
35
+ }
36
+ }
37
+
38
+ return $path;
39
+ }
40
+
41
+ /**
42
+ * Get the total size of a directory (including subdirectories).
43
+ *
44
+ * @param string $dir
45
+ * @param array $exclude
46
+ * @return int
47
+ */
48
+ function breeze_get_directory_size( $dir, $exclude = array() ) {
49
+ $size = 0;
50
+
51
+ foreach ( glob( rtrim( $dir, '/' ) . '/*', GLOB_NOSORT ) as $path ) {
52
+ if ( is_file( $path ) ) {
53
+ if ( in_array( basename( $path ), $exclude ) ) {
54
+ continue;
55
+ }
56
+
57
+ $size += filesize( $path );
58
+ } else {
59
+ $size += breeze_get_directory_size( $path, $exclude );
60
+ }
61
+ }
62
+
63
+ return $size;
64
+ }
inc/helpers.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @copyright 2017 Cloudways https://www.cloudways.com
4
+ *
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation; either version 2 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+ defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
20
+
21
+ /**
22
+ * Retrieve site options accounting for settings inheritance.
23
+ *
24
+ * @param string $option_name
25
+ * @param bool $is_local
26
+ * @return array
27
+ */
28
+ function breeze_get_option( $option_name, $is_local = false ) {
29
+ $inherit = true;
30
+
31
+ global $breeze_network_subsite_settings;
32
+
33
+ if ( is_network_admin() && ! $breeze_network_subsite_settings ) {
34
+ $is_local = false;
35
+ } elseif ( ! breeze_does_inherit_settings() ) {
36
+ $inherit = false;
37
+ }
38
+
39
+ if ( ! is_multisite() || $is_local || ! $inherit ) {
40
+ $option = get_option( 'breeze_' . $option_name );
41
+ } else {
42
+ $option = get_site_option( 'breeze_' . $option_name );
43
+ }
44
+
45
+ if ( empty( $option ) || ! is_array( $option ) ) {
46
+ $option = array();
47
+ }
48
+
49
+ return $option;
50
+ }
51
+
52
+ /**
53
+ * Update site options accounting for multisite.
54
+ *
55
+ * @param string $option_name
56
+ * @param mixed $value
57
+ * @param bool $is_local
58
+ */
59
+ function breeze_update_option( $option_name, $value, $is_local = false ) {
60
+ if ( is_network_admin() ) {
61
+ $is_local = false;
62
+ }
63
+
64
+ if ( ! is_multisite() || $is_local ) {
65
+ update_option( 'breeze_' . $option_name, $value );
66
+ } else {
67
+ update_site_option( 'breeze_' . $option_name, $value );
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Check whether current site should inherit network-level settings.
73
+ *
74
+ * @return bool
75
+ */
76
+ function breeze_does_inherit_settings() {
77
+ global $breeze_network_subsite_settings;
78
+
79
+ if ( ! is_multisite() || ( ! $breeze_network_subsite_settings && is_network_admin() ) ) {
80
+ return false;
81
+ }
82
+
83
+ $inherit_option = get_option( 'breeze_inherit_settings' );
84
+
85
+ return '0' !== $inherit_option;
86
+ }
87
+
88
+ /**
89
+ * Check if plugin is activated network-wide in a multisite environment.
90
+ *
91
+ * @return bool
92
+ */
93
+ function breeze_is_active_for_network() {
94
+ return is_multisite() && is_plugin_active_for_network( 'breeze/breeze.php' );
95
+ }
96
+
97
+ function breeze_is_supported( $check ) {
98
+ switch ( $check ) {
99
+ case 'conditional_htaccess':
100
+ $return = isset( $_SERVER['SERVER_SOFTWARE'] ) && stripos( $_SERVER['SERVER_SOFTWARE'], 'Apache/2.4' ) !== false;
101
+ break;
102
+ }
103
+
104
+ return $return;
105
+ }
inc/minification/breeze-minification-cache.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
- /*
4
- * Based on some work of autoptimize plugin
5
  */
6
  class Breeze_MinificationCache {
7
  private $filename;
8
  private $mime;
9
  private $cachedir;
10
  private $delayed;
11
-
12
  public function __construct($md5,$ext='php') {
13
  $this->cachedir = BREEZE_MINIFICATION_CACHE;
14
  if(is_multisite()){
@@ -29,7 +29,7 @@ class Breeze_MinificationCache {
29
 
30
 
31
  }
32
-
33
  public function check() {
34
  if(!file_exists($this->cachedir.$this->filename)) {
35
  // No cached file, sorry
@@ -68,7 +68,7 @@ class Breeze_MinificationCache {
68
  public function getname() {
69
  apply_filters('breeze_filter_cache_getname',breeze_CACHE_URL.$this->filename);
70
  return $this->filename;
71
- }
72
  //create folder cache
73
  public static function create_cache_minification_folder(){
74
  if(!defined('BREEZE_MINIFICATION_CACHE')) {
@@ -108,13 +108,13 @@ class Breeze_MinificationCache {
108
  }
109
 
110
  if(!is_file($htAccess)) {
111
- /**
112
- * create wp-content/AO_htaccess_tmpl with
113
  * whatever htaccess rules you might need
114
  * if you want to override default AO htaccess
115
  */
116
  $htaccess_tmpl=WP_CONTENT_DIR."/AO_htaccess_tmpl";
117
- if (is_file($htaccess_tmpl)) {
118
  $htAccessContent=file_get_contents($htaccess_tmpl);
119
  } else if (is_multisite()) {
120
  $htAccessContent='<IfModule mod_headers.c>
@@ -176,7 +176,7 @@ class Breeze_MinificationCache {
176
  }
177
  // All OK
178
  return true;
179
-
180
  }
181
  // check dir cache
182
  static function checkCacheDir($dir) {
@@ -198,13 +198,32 @@ class Breeze_MinificationCache {
198
  if(!is_file($indexFile)) {
199
  @file_put_contents($indexFile,'<html><head><meta name="robots" content="noindex, nofollow"></head><body></body></html>');
200
  }
201
-
202
  return true;
203
  }
204
- public static function clear_minification() {
205
- if(!Breeze_MinificationCache::create_cache_minification_folder()) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  return false;
207
  }
 
208
  if(is_multisite()){
209
  $blog_id = get_current_blog_id();
210
  // scan the cachedirs
@@ -240,7 +259,7 @@ class Breeze_MinificationCache {
240
  }
241
  return true;
242
  }
243
-
244
  public static function factory() {
245
 
246
  static $instance;
@@ -253,4 +272,3 @@ class Breeze_MinificationCache {
253
  return $instance;
254
  }
255
  }
256
-
1
  <?php
2
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+ /*
4
+ * Based on some work of autoptimize plugin
5
  */
6
  class Breeze_MinificationCache {
7
  private $filename;
8
  private $mime;
9
  private $cachedir;
10
  private $delayed;
11
+
12
  public function __construct($md5,$ext='php') {
13
  $this->cachedir = BREEZE_MINIFICATION_CACHE;
14
  if(is_multisite()){
29
 
30
 
31
  }
32
+
33
  public function check() {
34
  if(!file_exists($this->cachedir.$this->filename)) {
35
  // No cached file, sorry
68
  public function getname() {
69
  apply_filters('breeze_filter_cache_getname',breeze_CACHE_URL.$this->filename);
70
  return $this->filename;
71
+ }
72
  //create folder cache
73
  public static function create_cache_minification_folder(){
74
  if(!defined('BREEZE_MINIFICATION_CACHE')) {
108
  }
109
 
110
  if(!is_file($htAccess)) {
111
+ /**
112
+ * create wp-content/AO_htaccess_tmpl with
113
  * whatever htaccess rules you might need
114
  * if you want to override default AO htaccess
115
  */
116
  $htaccess_tmpl=WP_CONTENT_DIR."/AO_htaccess_tmpl";
117
+ if (is_file($htaccess_tmpl)) {
118
  $htAccessContent=file_get_contents($htaccess_tmpl);
119
  } else if (is_multisite()) {
120
  $htAccessContent='<IfModule mod_headers.c>
176
  }
177
  // All OK
178
  return true;
179
+
180
  }
181
  // check dir cache
182
  static function checkCacheDir($dir) {
198
  if(!is_file($indexFile)) {
199
  @file_put_contents($indexFile,'<html><head><meta name="robots" content="noindex, nofollow"></head><body></body></html>');
200
  }
201
+
202
  return true;
203
  }
204
+
205
+ public static function clear_minification() {
206
+ if ( is_multisite() && is_network_admin() ) {
207
+ $sites = get_sites(
208
+ array(
209
+ 'fields' => 'ids',
210
+ )
211
+ );
212
+ foreach ( $sites as $blog_id ) {
213
+ switch_to_blog( $blog_id );
214
+ self::clear_site_minification();
215
+ }
216
+ restore_current_blog();
217
+ } else {
218
+ self::clear_site_minification();
219
+ }
220
+ }
221
+
222
+ public static function clear_site_minification() {
223
+ if ( ! isset( $_GET['breeze_purge'] ) && ! Breeze_MinificationCache::create_cache_minification_folder() ) {
224
  return false;
225
  }
226
+
227
  if(is_multisite()){
228
  $blog_id = get_current_blog_id();
229
  // scan the cachedirs
259
  }
260
  return true;
261
  }
262
+
263
  public static function factory() {
264
 
265
  static $instance;
272
  return $instance;
273
  }
274
  }
 
inc/minification/breeze-minify-main.php CHANGED
@@ -31,11 +31,11 @@ class Breeze_Minify {
31
  $check_url = $this->check_exclude_url($current_url);
32
 
33
  //load config file when redirect template
34
- if (!$check_url) {
35
  //cache html
36
  //cache minification
37
  if (Breeze_MinificationCache::create_cache_minification_folder()) {
38
- $conf = get_option('breeze_basic_settings');
39
  if ( !empty($conf['breeze-minify-html']) || !empty($conf['breeze-minify-css']) || !empty($conf['breeze-minify-js']) ) {
40
  if (defined('breeze_INIT_EARLIER')) {
41
  add_action('init', array($this,'breeze_start_buffering'), -1);
@@ -46,7 +46,20 @@ class Breeze_Minify {
46
  }
47
  }
48
 
49
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  /*
51
  * Start buffer
52
  */
@@ -61,7 +74,7 @@ class Breeze_Minify {
61
  $ao_noptimize = (bool) apply_filters('breeze_filter_noptimize', $ao_noptimize);
62
  if (!is_feed() && !$ao_noptimize && !is_admin()) {
63
  // Config element
64
- $conf = get_option('breeze_basic_settings');
65
  // Load our base class
66
  include_once(BREEZE_PLUGIN_DIR . 'inc/minification/breeze-minification-base.php');
67
 
@@ -136,8 +149,8 @@ class Breeze_Minify {
136
 
137
  define('breeze_HASH',wp_hash(breeze_CACHE_URL));
138
  // Config element
139
- $conf = get_option('breeze_basic_settings');
140
- $minify = get_option('breeze_advanced_settings');
141
 
142
  // Choose the classes
143
  $classes = array();
@@ -217,7 +230,7 @@ class Breeze_Minify {
217
  * check url from Never cache the following pages area
218
  */
219
  public function check_exclude_url($current_url){
220
- $opts_config = get_option('breeze_advanced_settings');
221
  //check disable cache for page
222
  if (!empty($opts_config['breeze-exclude-urls'])) {
223
  foreach ($opts_config['breeze-exclude-urls'] as $v) {
@@ -250,4 +263,4 @@ class Breeze_Minify {
250
  return false;
251
 
252
  }
253
- }
31
  $check_url = $this->check_exclude_url($current_url);
32
 
33
  //load config file when redirect template
34
+ if ( ! $check_url && self::should_cache() ) {
35
  //cache html
36
  //cache minification
37
  if (Breeze_MinificationCache::create_cache_minification_folder()) {
38
+ $conf = breeze_get_option( 'basic_settings' );
39
  if ( !empty($conf['breeze-minify-html']) || !empty($conf['breeze-minify-css']) || !empty($conf['breeze-minify-js']) ) {
40
  if (defined('breeze_INIT_EARLIER')) {
41
  add_action('init', array($this,'breeze_start_buffering'), -1);
46
  }
47
  }
48
 
49
+ }
50
+
51
+ /**
52
+ * Check whether to execute caching functions or not.
53
+ * Will not execute for purge cache or heartbeat actions.
54
+ */
55
+ public static function should_cache() {
56
+ if ( isset( $_GET['breeze_purge'] ) || ( isset( $_POST['action'] ) && 'heartbeat' === $_POST['action'] ) ) {
57
+ return false;
58
+ }
59
+
60
+ return true;
61
+ }
62
+
63
  /*
64
  * Start buffer
65
  */
74
  $ao_noptimize = (bool) apply_filters('breeze_filter_noptimize', $ao_noptimize);
75
  if (!is_feed() && !$ao_noptimize && !is_admin()) {
76
  // Config element
77
+ $conf = breeze_get_option( 'basic_settings' );
78
  // Load our base class
79
  include_once(BREEZE_PLUGIN_DIR . 'inc/minification/breeze-minification-base.php');
80
 
149
 
150
  define('breeze_HASH',wp_hash(breeze_CACHE_URL));
151
  // Config element
152
+ $conf = breeze_get_option( 'basic_settings' );
153
+ $minify = breeze_get_option( 'advanced_settings' );
154
 
155
  // Choose the classes
156
  $classes = array();
230
  * check url from Never cache the following pages area
231
  */
232
  public function check_exclude_url($current_url){
233
+ $opts_config = breeze_get_option( 'advanced_settings' );
234
  //check disable cache for page
235
  if (!empty($opts_config['breeze-exclude-urls'])) {
236
  foreach ($opts_config['breeze-exclude-urls'] as $v) {
263
  return false;
264
 
265
  }
266
+ }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: Cloudways
3
  Tags: cache,caching, performance, wp-cache, cdn, combine, compress, speed plugin, database cache,gzip, http compression, js cache, minify, optimize, page cache, performance, speed, expire headers
4
  Requires at least: 4.5
5
  Tested up to: 5.2.1
6
- Stable tag: 1.0.13
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -145,6 +145,9 @@ Using Gzip, Breeze compresses the request files, further reducing the size of th
145
 
146
  == Changelog ==
147
 
 
 
 
148
  = 1.0.13 =
149
  * Fix: Validation of nonce.
150
  * Fix: Remove duplication of calls in Varnish purge requests.
3
  Tags: cache,caching, performance, wp-cache, cdn, combine, compress, speed plugin, database cache,gzip, http compression, js cache, minify, optimize, page cache, performance, speed, expire headers
4
  Requires at least: 4.5
5
  Tested up to: 5.2.1
6
+ Stable tag: 1.1.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
145
 
146
  == Changelog ==
147
 
148
+ = 1.1.0 =
149
+ * Add: Optional separate cache settings for subsites.
150
+
151
  = 1.0.13 =
152
  * Fix: Validation of nonce.
153
  * Fix: Remove duplication of calls in Varnish purge requests.
views/breeze-setting-views.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  defined('ABSPATH') or die;
3
 
4
  $tabs = array(
@@ -10,20 +11,18 @@ $tabs = array(
10
  'faq' => __('FAQs', 'breeze'),
11
  );
12
 
13
- if (is_multisite() && get_current_screen()->base !== 'settings_page_breeze-network') {
14
- $tabs = array(
15
- 'faq' => __('FAQs', 'breeze')
16
- );
17
- }
18
 
19
  wp_enqueue_script('jquery-ui', '//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js');
20
  ?>
21
  <?php if (isset($_REQUEST['database-cleanup']) && $_REQUEST['database-cleanup'] == 'success'): ?>
22
- <div id="message-save-settings" class="notice notice-success" style="margin: 10px 0px 10px 0;padding: 10px;"><strong><?php _e('Database cleanup successful', 'breeze'); ?></strong></div>
23
  <?php endif; ?>
24
  <!--save settings successfull message-->
25
  <?php if (isset($_REQUEST['save-settings']) && $_REQUEST['save-settings'] == 'success'): ?>
26
- <div id="message-save-settings" class="notice notice-success" style="margin: 10px 0px 10px 0;padding: 10px;"><strong><?php _e('Configuration settings saved', 'breeze'); ?></strong></div>
27
  <?php endif; ?>
28
  <div class="wrap breeze-main">
29
  <div class="breeze-header">
@@ -32,37 +31,82 @@ wp_enqueue_script('jquery-ui', '//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/
32
  </a>
33
  </div>
34
 
35
- <h1 style="clear: both"></h1>
36
 
37
- <ul id="breeze-tabs" class="nav-tab-wrapper">
38
- <?php
39
- foreach ($tabs as $key => $name) {
40
- echo '<a id="tab-' . $key . '" class="nav-tab" href="#tab-' . $key . '" data-tab-id="' . $key . '"> ' . $name . ' </a> ';
41
- }
42
- ?>
43
- </ul>
44
 
45
- <div id="breeze-tabs-content" class="tab-content">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  <?php
47
- foreach ($tabs as $key => $name) {
48
- echo '<div id="tab-content-' . $key . '" class="tab-pane">';
 
49
  echo '<form class="breeze-form" method="post" action="">';
50
  echo '<div class="tab-child">';
51
  echo '<input type="hidden" name="breeze_'.$key.'_action" value="breeze_'.$key.'_settings">';
52
  wp_nonce_field('breeze_settings_' . $key, 'breeze_settings_' . $key . '_nonce');
53
  Breeze_Admin::render($key);
54
  echo '</div>';
55
- if ($key == 'database'){
56
- echo '<p class="submit">
57
- <input type="submit" class="button button-primary" value="'. __('Optimize', 'breeze') .'"/>
58
- </p>';
59
- }else{
60
- if ($key != 'faq') {
61
- echo '<p class="submit">
62
- <input type="submit" class="button button-primary" value="'. __('Save Changes', 'breeze') .'"/>
63
- </p>';
64
- }
65
- }
 
 
 
 
66
  echo '</form>';
67
  echo '</div>';
68
  }
1
  <?php
2
+
3
  defined('ABSPATH') or die;
4
 
5
  $tabs = array(
11
  'faq' => __('FAQs', 'breeze'),
12
  );
13
 
14
+ $global_tabs = array(
15
+ 'faq',
16
+ );
 
 
17
 
18
  wp_enqueue_script('jquery-ui', '//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js');
19
  ?>
20
  <?php if (isset($_REQUEST['database-cleanup']) && $_REQUEST['database-cleanup'] == 'success'): ?>
21
+ <div id="message-save-settings" class="notice notice-success is-dismissible" style="margin: 10px 0px 10px 0;padding: 10px;"><strong><?php _e('Database cleanup successful', 'breeze'); ?></strong></div>
22
  <?php endif; ?>
23
  <!--save settings successfull message-->
24
  <?php if (isset($_REQUEST['save-settings']) && $_REQUEST['save-settings'] == 'success'): ?>
25
+ <div id="message-save-settings" class="notice notice-success is-dismissible" style="margin: 10px 0px 10px 0;padding: 10px;"><strong><?php _e('Configuration settings saved', 'breeze'); ?></strong></div>
26
  <?php endif; ?>
27
  <div class="wrap breeze-main">
28
  <div class="breeze-header">
31
  </a>
32
  </div>
33
 
34
+ <h1 style="clear: both"></h1>
35
 
36
+ <?php
37
+
38
+ $show_tabs = true;
39
+ $is_subsite = is_multisite() && get_current_screen()->base !== 'settings_page_breeze-network';
 
 
 
40
 
41
+ if ( $is_subsite ) {
42
+ // Show settings inherit option.
43
+ $inherit_settings = get_option( 'breeze_inherit_settings', 1 );
44
+ if ( 0 != $inherit_settings ) {
45
+ $inherit_settings = 1;
46
+ $show_tabs = false;
47
+ }
48
+ ?>
49
+ <form id="breeze-inherit-settings-toggle" class="breeze-form" method="post" action="">
50
+ <div class="radio-field<?php echo $inherit_settings == 1 ? ' active' : ''; ?>">
51
+ <label>
52
+ <input type="radio" id="inherit-settings" name="inherit-settings" value="1" <?php checked( $inherit_settings, 1 ); ?>>
53
+ <strong><?php esc_html_e( 'Use Network Level Settings for this site', 'breeze' ); ?>:</strong>
54
+ </label>
55
+ <small><?php esc_html_e( 'This option allows the subsite to inherit all the cache settings from network. To modify/update the settings please go to network site.', 'breeze' ); ?></small>
56
+ </div>
57
+ <div class="radio-field<?php echo $inherit_settings == 0 ? ' active' : ''; ?>">
58
+ <label>
59
+ <input type="radio" id="inherit-settings" name="inherit-settings" value="0" <?php checked( $inherit_settings, 0 ); ?>>
60
+ <strong><?php esc_html_e( 'Use Custom Settings for this site', 'breeze' ); ?>:</strong>
61
+ </label>
62
+ <small><?php esc_html_e( 'This option allows subsite to have different settings/configuration from the network level. Use this option only if you wish to have separate settings for this subsite.', 'breeze' ); ?></small>
63
+ </div>
64
+
65
+ <p class="disclaimer"><?php esc_html_e( 'To apply your changes, please click on the Save Changes button.', 'breeze' ); ?></p>
66
+
67
+ <?php wp_nonce_field( 'breeze_inherit_settings', 'breeze_inherit_settings_nonce' ); ?>
68
+ </form>
69
+
70
+ <h1 style="clear: both"></h1>
71
+ <?php
72
+ }
73
+ ?>
74
+
75
+ <ul id="breeze-tabs" class="nav-tab-wrapper <?php echo ! $show_tabs ? 'tabs-hidden' : ''; ?>">
76
+ <?php
77
+ foreach ( $tabs as $key => $name ) {
78
+ $is_inactive = ! $show_tabs && ! in_array( $key, $global_tabs );
79
+ echo '<a id="tab-' . $key . '" class="nav-tab' . ( $is_inactive ? ' inactive' : '' ) . '" href="#tab-' . $key . '" data-tab-id="' . $key . '"> ' . $name . ' </a> ';
80
+ }
81
+ ?>
82
+ </ul>
83
+
84
+ <div id="breeze-tabs-content" class="tab-content <?php echo ! $show_tabs ? 'tabs-hidden' : ''; ?>">
85
  <?php
86
+ foreach ( $tabs as $key => $name ) {
87
+ $is_inactive = ! $show_tabs && ! in_array( $key, $global_tabs );
88
+ echo '<div id="tab-content-' . $key . '" class="tab-pane' . ( $is_inactive ? ' inactive' : '' ) . '">';
89
  echo '<form class="breeze-form" method="post" action="">';
90
  echo '<div class="tab-child">';
91
  echo '<input type="hidden" name="breeze_'.$key.'_action" value="breeze_'.$key.'_settings">';
92
  wp_nonce_field('breeze_settings_' . $key, 'breeze_settings_' . $key . '_nonce');
93
  Breeze_Admin::render($key);
94
  echo '</div>';
95
+
96
+ if (
97
+ $key != 'faq' &&
98
+ ( $key != 'database' || ( is_multisite() && ! is_network_admin() ) )
99
+ ) {
100
+ if ( is_multisite() && is_network_admin() ) {
101
+ echo '<p class="multisite-inherit-disclaimer">' . __( '* Any change here will also be applied to all the sub-sites that are using Network level settings.', 'wpr' ) . '</p>';
102
+ }
103
+ echo '<p class="submit">' . PHP_EOL .
104
+ '<input type="submit" class="button button-primary" value="'. __('Save Changes', 'breeze') .'"/>' . PHP_EOL .
105
+ '</p>';
106
+ }
107
+ if ( ! in_array( $key, $global_tabs ) ) {
108
+ echo '<span class="hidden-text">' . esc_attr__( 'When Network Level Settings is selected, modifications/updates can only be done from the main Network site.', 'breeze' ) . '</span>';
109
+ }
110
  echo '</form>';
111
  echo '</div>';
112
  }
views/tabs/advanced.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  defined('ABSPATH') or die;
3
 
4
- $advanced = get_option('breeze_advanced_settings');
5
  ?>
6
  <table cellspacing="15">
7
  <tr>
1
  <?php
2
  defined('ABSPATH') or die;
3
 
4
+ $advanced = breeze_get_option( 'advanced_settings', true );
5
  ?>
6
  <table cellspacing="15">
7
  <tr>
views/tabs/basic.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  defined('ABSPATH') or die;
3
 
4
- $basic = get_option('breeze_basic_settings');
5
  ?>
6
  <table cellspacing="15">
7
  <tr>
@@ -72,7 +72,8 @@ $basic = get_option('breeze_basic_settings');
72
  <li>
73
  <span><?php _e('Check the above boxes to minify HTML, CSS, or JS files.', 'breeze') ?></span>
74
  <br>
75
- <span><b>Note:&nbsp;</b>
 
76
  <span style="color: #ff0000"><?php _e('We recommend testing minification on a staging website before deploying it on a live website. Minification is known to cause issues on the frontend.', 'breeze') ?></span>
77
  </span>
78
  </li>
@@ -80,26 +81,48 @@ $basic = get_option('breeze_basic_settings');
80
 
81
  </td>
82
  </tr>
83
- <tr>
84
- <td>
85
- <label for="gzip-compression"><?php _e('Gzip Compression', 'breeze') ?></label>
86
- </td>
87
- <td>
88
- <input type="checkbox" id="gzip-compression" name="gzip-compression"
89
- value='1' <?php checked($basic['breeze-gzip-compression'], '1') ?>/>
90
- <span class="breeze_tool_tip"><?php _e('Enable this to compress your files making HTTP requests fewer and faster.', 'breeze') ?></span>
91
- </td>
92
- </tr>
93
- <tr>
94
- <td style="vertical-align: middle">
95
- <label for="browser-cache"><?php _e('Browser Cache', 'breeze') ?></label>
96
- </td>
97
- <td>
98
- <input type="checkbox" id="browser-cache" name="browser-cache"
99
- value='1' <?php checked($basic['breeze-browser-cache'], '1') ?>/>
100
- <span class="breeze_tool_tip"><?php _e('Enable this to add expires headers to static files. This will ask browsers to either request a file from server or fetch from the browser’s cache.', 'breeze') ?></span>
101
- </td>
102
- </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
  <tr style="display: none;">
105
  <td style="vertical-align: middle">
1
  <?php
2
  defined('ABSPATH') or die;
3
 
4
+ $basic = breeze_get_option( 'basic_settings', true );
5
  ?>
6
  <table cellspacing="15">
7
  <tr>
72
  <li>
73
  <span><?php _e('Check the above boxes to minify HTML, CSS, or JS files.', 'breeze') ?></span>
74
  <br>
75
+ <span>
76
+ <b><?php esc_html_e( 'Note', 'breeze' ); ?>:&nbsp;</b>
77
  <span style="color: #ff0000"><?php _e('We recommend testing minification on a staging website before deploying it on a live website. Minification is known to cause issues on the frontend.', 'breeze') ?></span>
78
  </span>
79
  </li>
81
 
82
  </td>
83
  </tr>
84
+
85
+ <?php
86
+
87
+ $htaccess_options = array(
88
+ 'gzip-compression' => array(
89
+ 'label' => __( 'Gzip Compression', 'breeze' ),
90
+ 'desc' => __( 'Enable this to compress your files making HTTP requests fewer and faster.', 'breeze' ),
91
+ ),
92
+ 'browser-cache' => array(
93
+ 'label' => __( 'Browser Cache', 'breeze' ),
94
+ 'desc' => __( 'Enable this to add expires headers to static files. This will ask browsers to either request a file from server or fetch from the browser’s cache.', 'breeze' ),
95
+ ),
96
+ );
97
+
98
+ $supports_conditionals = breeze_is_supported( 'conditional_htaccess' );
99
+
100
+ foreach ( $htaccess_options as $fid => $field ) {
101
+ $is_disabled = is_multisite() && ! is_network_admin() && ! $supports_conditionals;
102
+ $is_checked = isset( $basic[ 'breeze-' . $fid ] ) && '1' === $basic[ 'breeze-' . $fid ] && ! $is_disabled;
103
+
104
+ ?>
105
+ <tr>
106
+ <td>
107
+ <label for="<?php echo esc_attr( $fid ); ?>"><?php echo esc_html( $field['label'] ); ?></label>
108
+ </td>
109
+ <td>
110
+ <input type="checkbox" id="<?php echo esc_attr( $fid ); ?>" name="<?php echo esc_attr( $fid ); ?>"
111
+ value='1' <?php checked( $is_checked, true ); ?> <?php echo $is_disabled ? 'disabled="disabled"' : ''; ?>/>
112
+ <span class="breeze_tool_tip"><?php echo esc_html( $field['desc'] ); ?></span>
113
+ <?php if ( $is_disabled ) { ?>
114
+ <br>
115
+ <span>
116
+ <b><?php esc_html_e( 'Note', 'breeze' ); ?>:&nbsp;</b>
117
+ <span style="color: #ff0000"><?php printf( esc_html__( 'Enabling/disabling %s for subsites is only available for Apache 2.4 and above. For lower versions, the Network-level settings will apply.', 'breeze' ), $field['label'] ); ?></span>
118
+ </span>
119
+ <?php } ?>
120
+ </td>
121
+ </tr>
122
+ <?php
123
+ }
124
+
125
+ ?>
126
 
127
  <tr style="display: none;">
128
  <td style="vertical-align: middle">
views/tabs/cdn.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  defined('ABSPATH') or die;
3
 
4
- $cdn_integration = get_option('breeze_cdn_integration');
5
 
6
  $cdn_content_value = '';
7
  $cdn_exclude_content_value = '';
@@ -62,4 +62,4 @@
62
  <span class="breeze_tool_tip"><?php _e('Keep this option enabled. Use this option to enable relative path for your CDN on your WordPress site.', 'breeze')?></span>
63
  </td>
64
  </tr>
65
- </table>
1
  <?php
2
  defined('ABSPATH') or die;
3
 
4
+ $cdn_integration = breeze_get_option( 'cdn_integration', true );
5
 
6
  $cdn_content_value = '';
7
  $cdn_exclude_content_value = '';
62
  <span class="breeze_tool_tip"><?php _e('Keep this option enabled. Use this option to enable relative path for your CDN on your WordPress site.', 'breeze')?></span>
63
  </td>
64
  </tr>
65
+ </table>
views/tabs/database.php CHANGED
@@ -1,26 +1,39 @@
1
  <?php
 
2
  defined('ABSPATH') or die;
 
3
  $post_revisions = 0; $drafted = 0; $trashed = 0; $comments = 0; $trackbacks = 0; $transients = 0;
4
- if (is_multisite()) {
5
- $sites = get_sites();
6
- foreach ($sites as $site) {
7
- switch_to_blog($site->blog_id);
8
- $post_revisions += (int)Breeze_Configuration::getElementToClean('revisions');
9
- $drafted += (int)Breeze_Configuration::getElementToClean('drafted');
10
- $trashed += (int)Breeze_Configuration::getElementToClean('trash');
11
- $comments += (int)Breeze_Configuration::getElementToClean('comments');
12
- $trackbacks += (int)Breeze_Configuration::getElementToClean('trackbacks');
13
- $transients += (int)Breeze_Configuration::getElementToClean('transient');
14
- }
15
- restore_current_blog();
 
 
 
 
 
 
 
16
  } else {
17
- $post_revisions = (int)Breeze_Configuration::getElementToClean('revisions');
18
- $drafted = (int)Breeze_Configuration::getElementToClean('drafted');
19
- $trashed = (int)Breeze_Configuration::getElementToClean('trash');
20
- $comments = (int)Breeze_Configuration::getElementToClean('comments');
21
- $trackbacks = (int)Breeze_Configuration::getElementToClean('trackbacks');
22
- $transients = (int)Breeze_Configuration::getElementToClean('transient');
 
23
  }
 
 
 
24
  ?>
25
  <div class="breeze-top-notice">
26
  <p class="breeze_tool_tip"><?php _e('Important: Backup your databases before using the following options!','breeze')?></p>
@@ -89,5 +102,11 @@ if (is_multisite()) {
89
  <input type="checkbox" id="data6" name="clean[]" class="clean-data" value="transient"/>
90
  <span class="breeze_tool_tip"><?php _e('Delete expired and active transients from the WordPress database.','breeze')?></span>
91
  </td>
92
- </tr>
 
 
 
 
 
 
93
  </table>
1
  <?php
2
+
3
  defined('ABSPATH') or die;
4
+
5
  $post_revisions = 0; $drafted = 0; $trashed = 0; $comments = 0; $trackbacks = 0; $transients = 0;
6
+
7
+ if ( is_multisite() && is_network_admin() ) {
8
+ // Count items from all network sites.
9
+ $sites = get_sites(
10
+ array(
11
+ 'fields' => 'ids',
12
+ )
13
+ );
14
+
15
+ foreach ( $sites as $blog_id ) {
16
+ switch_to_blog( $blog_id );
17
+ $post_revisions += (int) Breeze_Configuration::getElementToClean( 'revisions' );
18
+ $drafted += (int) Breeze_Configuration::getElementToClean( 'drafted' );
19
+ $trashed += (int) Breeze_Configuration::getElementToClean( 'trash' );
20
+ $comments += (int) Breeze_Configuration::getElementToClean( 'comments' );
21
+ $trackbacks += (int) Breeze_Configuration::getElementToClean( 'trackbacks' );
22
+ $transients += (int) Breeze_Configuration::getElementToClean( 'transient' );
23
+ restore_current_blog();
24
+ }
25
  } else {
26
+ // Count items from the current site.
27
+ $post_revisions = (int) Breeze_Configuration::getElementToClean( 'revisions' );
28
+ $drafted = (int) Breeze_Configuration::getElementToClean( 'drafted' );
29
+ $trashed = (int) Breeze_Configuration::getElementToClean( 'trash' );
30
+ $comments = (int) Breeze_Configuration::getElementToClean( 'comments' );
31
+ $trackbacks = (int) Breeze_Configuration::getElementToClean( 'trackbacks' );
32
+ $transients = (int) Breeze_Configuration::getElementToClean( 'transient' );
33
  }
34
+
35
+ $is_optimize_disabled = is_multisite() && ! is_network_admin() && '0' !== get_option( 'breeze_inherit_settings' );
36
+
37
  ?>
38
  <div class="breeze-top-notice">
39
  <p class="breeze_tool_tip"><?php _e('Important: Backup your databases before using the following options!','breeze')?></p>
102
  <input type="checkbox" id="data6" name="clean[]" class="clean-data" value="transient"/>
103
  <span class="breeze_tool_tip"><?php _e('Delete expired and active transients from the WordPress database.','breeze')?></span>
104
  </td>
105
+ </tr>
106
+ <tr>
107
+ <td></td>
108
+ <td>
109
+ <input type="submit" id="breeze-database-optimize" class="button button-primary" <?php echo $is_optimize_disabled ? ' disabled="disabled"' : ''; ?> value="<?php esc_attr_e( 'Optimize' ); ?>">
110
+ </td>
111
+ </tr>
112
  </table>
views/tabs/varnish.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  defined('ABSPATH') or die;
3
 
4
- $varnish = get_option('breeze_varnish_cache');
5
  $check_varnish = Breeze_Admin::check_varnish();
6
  ?>
7
  <div class="breeze-top-notice">
@@ -43,4 +43,4 @@ $check_varnish = Breeze_Admin::check_varnish();
43
  <span style="vertical-align: bottom; margin-left: 5px"><?php _e('Use this option to instantly Purge Varnish Cache on entire website. ', 'breeze') ?></span>
44
  </td>
45
  </tr>
46
- </table>
1
  <?php
2
  defined('ABSPATH') or die;
3
 
4
+ $varnish = breeze_get_option( 'varnish_cache', true );
5
  $check_varnish = Breeze_Admin::check_varnish();
6
  ?>
7
  <div class="breeze-top-notice">
43
  <span style="vertical-align: bottom; margin-left: 5px"><?php _e('Use this option to instantly Purge Varnish Cache on entire website. ', 'breeze') ?></span>
44
  </td>
45
  </tr>
46
+ </table>