Version Description
- Apr 27 2018 =
- [NEW FEATURE] WebP For Extra srcset setting in Media tab. (@vengen)
- [REFACTOR] Removed redundant LS consts.
- [REFACTOR] Refactored adv_cache generation flow.
- [BUGFIX] Fixed issue where inline JS minify exception caused a blank page. (@oomskaap @kenb1978)
- [UPDATE] Changed HTTP/2 Crawl default value to OFF.
- [UPDATE] Added img.data-src to default WebP replacement value for WooCommerce WebP support.
- [UPDATE] Detached crawler from LSCache LITESPEED_ON status.
- [API] Improved ESI API to honor the cache control in ESI wrapper.
- [API] Added LITESPEED_PURGE_SILENT const to bypass the notification when purging
- [INTEGRATION] Fixed issue with nonce expiration when using ESI API. (@Dan #923505)
- [INTEGRATION] Improved compatibility with Ninja Forms by bypassing non-javascript JS from inline JS minify.
- [INTEGRATION] Added a hook for plugins that change the CSS/JS path e.g. Hide My WordPress.
Download this release
Release Info
Developer | LiteSpeedTech |
Plugin | LiteSpeed Cache |
Version | 2.2.3 |
Comparing to | |
See all releases |
Code changes from version 2.2.2 to 2.2.3
- admin/litespeed-cache-admin-settings.class.php +3 -15
- admin/litespeed-cache-admin.class.php +24 -19
- admin/tpl/setting/settings_media.php +11 -0
- cli/litespeed-cache-cli-admin.class.php +2 -0
- inc/activation.class.php +7 -1
- inc/config.class.php +19 -13
- inc/control.class.php +3 -0
- inc/esi.class.php +22 -1
- inc/litespeed-cache.class.php +10 -40
- inc/media.class.php +23 -9
- inc/optimize.class.php +1 -15
- inc/optimizer.class.php +90 -23
- inc/purge.class.php +38 -13
- inc/router.class.php +3 -7
- inc/tag.class.php +22 -10
- inc/task.class.php +0 -10
- inc/utility.class.php +57 -2
- includes/litespeed-cache-activation.class.php +7 -1
- includes/litespeed-cache-config.class.php +19 -13
- includes/litespeed-cache-control.class.php +3 -0
- includes/litespeed-cache-esi.class.php +22 -1
- includes/litespeed-cache-optimize.class.php +1 -15
- includes/litespeed-cache-purge.class.php +38 -13
- includes/litespeed-cache-router.class.php +3 -7
- includes/litespeed-cache-tag.class.php +22 -10
- includes/litespeed-cache-task.class.php +0 -10
- includes/litespeed-cache-utility.class.php +57 -2
- includes/litespeed-cache.class.php +10 -40
- languages/litespeed-cache.pot +57 -46
- lib/html_min.class.php +244 -237
- lib/js_min.class.php +394 -396
- litespeed-cache.php +1 -1
- readme.txt +20 -3
admin/litespeed-cache-admin-settings.class.php
CHANGED
@@ -108,7 +108,6 @@ class LiteSpeed_Cache_Admin_Settings
|
|
108 |
return $this->_options ;
|
109 |
}
|
110 |
|
111 |
-
$cron_changed = false ;
|
112 |
if ( defined( 'LITESPEED_CLI' ) ) {
|
113 |
$id = LiteSpeed_Cache_Config::CRWL_CRON_ACTIVE ;
|
114 |
$cron_val = $this->_options[ $id ] ;
|
@@ -116,15 +115,11 @@ class LiteSpeed_Cache_Admin_Settings
|
|
116 |
// This has to be specified cos crawler cron activation is not set in admin setting page
|
117 |
$this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
|
118 |
if ( $cron_val != $this->_options[ $id ] ) {
|
119 |
-
|
|
|
120 |
}
|
121 |
}
|
122 |
|
123 |
-
// check if need to enable crawler cron
|
124 |
-
if ( defined( 'LITESPEED_ON_CHANGED' ) || $cron_changed ) {
|
125 |
-
LiteSpeed_Cache_Task::update( $this->_options ) ;
|
126 |
-
}
|
127 |
-
|
128 |
$this->_validate_thirdparty( ) ;
|
129 |
|
130 |
return $this->_options ;
|
@@ -341,14 +336,6 @@ class LiteSpeed_Cache_Admin_Settings
|
|
341 |
LiteSpeed_Cache_Purge::purge_all( 'Not enabled' ) ;
|
342 |
! defined( 'LITESPEED_NEW_OFF' ) && define( 'LITESPEED_NEW_OFF', true ) ; // Latest status is off
|
343 |
}
|
344 |
-
else {
|
345 |
-
! defined( 'LITESPEED_NEW_ON' ) && define( 'LITESPEED_NEW_ON', true ) ; // Latest status is on
|
346 |
-
}
|
347 |
-
|
348 |
-
// Status changed
|
349 |
-
if ( defined( 'LITESPEED_ON' ) xor $enabled ) {
|
350 |
-
define( 'LITESPEED_ON_CHANGED', true ) ;
|
351 |
-
}
|
352 |
|
353 |
// TTL check
|
354 |
$ids = array(
|
@@ -691,6 +678,7 @@ class LiteSpeed_Cache_Admin_Settings
|
|
691 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_LAZY,
|
692 |
LiteSpeed_Cache_Config::OPID_MEDIA_IFRAME_LAZY,
|
693 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_OPTM_CRON_OFF,
|
|
|
694 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_ONLY,
|
695 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_EXIF,
|
696 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_LOSSLESS,
|
108 |
return $this->_options ;
|
109 |
}
|
110 |
|
|
|
111 |
if ( defined( 'LITESPEED_CLI' ) ) {
|
112 |
$id = LiteSpeed_Cache_Config::CRWL_CRON_ACTIVE ;
|
113 |
$cron_val = $this->_options[ $id ] ;
|
115 |
// This has to be specified cos crawler cron activation is not set in admin setting page
|
116 |
$this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
|
117 |
if ( $cron_val != $this->_options[ $id ] ) {
|
118 |
+
// check if need to enable crawler cron
|
119 |
+
LiteSpeed_Cache_Task::update( $this->_options ) ;
|
120 |
}
|
121 |
}
|
122 |
|
|
|
|
|
|
|
|
|
|
|
123 |
$this->_validate_thirdparty( ) ;
|
124 |
|
125 |
return $this->_options ;
|
336 |
LiteSpeed_Cache_Purge::purge_all( 'Not enabled' ) ;
|
337 |
! defined( 'LITESPEED_NEW_OFF' ) && define( 'LITESPEED_NEW_OFF', true ) ; // Latest status is off
|
338 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
339 |
|
340 |
// TTL check
|
341 |
$ids = array(
|
678 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_LAZY,
|
679 |
LiteSpeed_Cache_Config::OPID_MEDIA_IFRAME_LAZY,
|
680 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_OPTM_CRON_OFF,
|
681 |
+
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_REPLACE_SRCSET,
|
682 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_ONLY,
|
683 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_EXIF,
|
684 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_LOSSLESS,
|
admin/litespeed-cache-admin.class.php
CHANGED
@@ -98,11 +98,29 @@ class LiteSpeed_Cache_Admin
|
|
98 |
|
99 |
do_action( 'litspeed_after_admin_init' ) ;
|
100 |
|
101 |
-
//
|
102 |
-
if (
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
|
|
|
106 |
LiteSpeed_Cache_Control::set_nocache( 'Admin page' ) ;
|
107 |
|
108 |
if ( LiteSpeed_Cache_Router::esi_enabled() ) {
|
@@ -110,19 +128,6 @@ class LiteSpeed_Cache_Admin
|
|
110 |
add_filter( 'widget_update_callback', 'LiteSpeed_Cache_Admin_Settings::validate_widget_save', 10, 4 ) ;
|
111 |
}
|
112 |
|
113 |
-
// check if WP_CACHE is defined and true in the wp-config.php file.
|
114 |
-
if ( ! defined('WP_CACHE') || ! WP_CACHE ) {
|
115 |
-
$add_var = LiteSpeed_Cache_Config::wp_cache_var_setter(true) ;
|
116 |
-
if ( $add_var !== true ) {
|
117 |
-
LiteSpeed_Cache_Admin_Display::add_error($add_var) ;
|
118 |
-
}
|
119 |
-
}
|
120 |
-
|
121 |
-
// check management action
|
122 |
-
if ( defined('WP_CACHE') && WP_CACHE ) {
|
123 |
-
$this->check_advanced_cache() ;
|
124 |
-
}
|
125 |
-
|
126 |
if ( ! is_multisite() ) {
|
127 |
if( ! current_user_can('manage_options') ){
|
128 |
return ;
|
@@ -189,11 +194,11 @@ class LiteSpeed_Cache_Admin
|
|
189 |
private function check_advanced_cache()
|
190 |
{
|
191 |
$capability = is_network_admin() ? 'manage_network_options' : 'manage_options' ;
|
192 |
-
if (
|
193 |
-
if ( ! LiteSpeed_Cache::config(LiteSpeed_Cache_Config::OPID_CHECK_ADVANCEDCACHE) ) {
|
194 |
// If it exists because I added it at runtime, try to create the file anyway.
|
195 |
// Result does not matter.
|
196 |
-
LiteSpeed_Cache_Activation::try_copy_advanced_cache()
|
197 |
}
|
198 |
return ;
|
199 |
}
|
98 |
|
99 |
do_action( 'litspeed_after_admin_init' ) ;
|
100 |
|
101 |
+
// If setting is set to on, try to activate cache func
|
102 |
+
if ( defined( 'LITESPEED_ON_IN_SETTING' ) ) {
|
103 |
+
// check if WP_CACHE is defined and true in the wp-config.php file.
|
104 |
+
if ( ! defined('WP_CACHE') || ! WP_CACHE ) {
|
105 |
+
$add_var = LiteSpeed_Cache_Config::wp_cache_var_setter(true) ;
|
106 |
+
if ( $add_var !== true ) {
|
107 |
+
LiteSpeed_Cache_Admin_Display::add_error($add_var) ;
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
// check management action
|
112 |
+
if ( defined('WP_CACHE') && WP_CACHE ) {
|
113 |
+
$this->check_advanced_cache() ;
|
114 |
+
}
|
115 |
+
|
116 |
+
// step out if adv_cache can't write
|
117 |
+
if ( ! defined( 'LITESPEED_ON' ) ) {
|
118 |
+
return ;
|
119 |
+
}
|
120 |
+
|
121 |
}
|
122 |
|
123 |
+
|
124 |
LiteSpeed_Cache_Control::set_nocache( 'Admin page' ) ;
|
125 |
|
126 |
if ( LiteSpeed_Cache_Router::esi_enabled() ) {
|
128 |
add_filter( 'widget_update_callback', 'LiteSpeed_Cache_Admin_Settings::validate_widget_save', 10, 4 ) ;
|
129 |
}
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
if ( ! is_multisite() ) {
|
132 |
if( ! current_user_can('manage_options') ){
|
133 |
return ;
|
194 |
private function check_advanced_cache()
|
195 |
{
|
196 |
$capability = is_network_admin() ? 'manage_network_options' : 'manage_options' ;
|
197 |
+
if ( defined( 'LSCACHE_ADV_CACHE' ) || ! current_user_can( $capability ) ) {
|
198 |
+
if ( ! LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CHECK_ADVANCEDCACHE ) ) {
|
199 |
// If it exists because I added it at runtime, try to create the file anyway.
|
200 |
// Result does not matter.
|
201 |
+
LiteSpeed_Cache_Activation::try_copy_advanced_cache() ;// not sure why do this but doesn't matter
|
202 |
}
|
203 |
return ;
|
204 |
}
|
admin/tpl/setting/settings_media.php
CHANGED
@@ -98,6 +98,17 @@ if ( ! defined( 'WPINC' ) ) die ;
|
|
98 |
</td>
|
99 |
</tr>
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
<tr>
|
102 |
<th><?php echo __( 'Only Request WebP', 'litespeed-cache' ) ; ?></th>
|
103 |
<td>
|
98 |
</td>
|
99 |
</tr>
|
100 |
|
101 |
+
<tr>
|
102 |
+
<th><?php echo __( 'WebP For Extra srcset', 'litespeed-cache' ) ; ?></th>
|
103 |
+
<td>
|
104 |
+
<?php $this->build_switch( LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_REPLACE_SRCSET ) ; ?>
|
105 |
+
<div class="litespeed-desc">
|
106 |
+
<?php echo sprintf( __( 'Enable replacement of WebP in %s elements that were generated outside of WordPress logic.', 'litespeed-cache' ), '<code>srcset</code>' ) ; ?>
|
107 |
+
<a href="https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:configuration:media#webp_for_extra_srcset" target="_blank"><?php echo __('Learn More', 'litespeed-cache') ; ?></a>
|
108 |
+
</div>
|
109 |
+
</td>
|
110 |
+
</tr>
|
111 |
+
|
112 |
<tr>
|
113 |
<th><?php echo __( 'Only Request WebP', 'litespeed-cache' ) ; ?></th>
|
114 |
<td>
|
cli/litespeed-cache-cli-admin.class.php
CHANGED
@@ -68,6 +68,7 @@ class LiteSpeed_Cache_Cli_Admin
|
|
68 |
LiteSpeed_Cache_Config::OPID_MEDIA_IFRAME_LAZY,
|
69 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_OPTM_CRON_OFF,
|
70 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP,
|
|
|
71 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_ONLY,
|
72 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_EXIF,
|
73 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_LOSSLESS,
|
@@ -178,6 +179,7 @@ class LiteSpeed_Cache_Cli_Admin
|
|
178 |
case LiteSpeed_Cache_Config::OPID_MEDIA_IFRAME_LAZY:
|
179 |
case LiteSpeed_Cache_Config::OPID_MEDIA_IMG_OPTM_CRON_OFF:
|
180 |
case LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP:
|
|
|
181 |
case LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_ONLY:
|
182 |
case LiteSpeed_Cache_Config::OPID_MEDIA_IMG_EXIF:
|
183 |
case LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_LOSSLESS:
|
68 |
LiteSpeed_Cache_Config::OPID_MEDIA_IFRAME_LAZY,
|
69 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_OPTM_CRON_OFF,
|
70 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP,
|
71 |
+
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_REPLACE_SRCSET,
|
72 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_ONLY,
|
73 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_EXIF,
|
74 |
LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_LOSSLESS,
|
179 |
case LiteSpeed_Cache_Config::OPID_MEDIA_IFRAME_LAZY:
|
180 |
case LiteSpeed_Cache_Config::OPID_MEDIA_IMG_OPTM_CRON_OFF:
|
181 |
case LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP:
|
182 |
+
case LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_REPLACE_SRCSET:
|
183 |
case LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_ONLY:
|
184 |
case LiteSpeed_Cache_Config::OPID_MEDIA_IMG_EXIF:
|
185 |
case LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_LOSSLESS:
|
inc/activation.class.php
CHANGED
@@ -234,8 +234,14 @@ class LiteSpeed_Cache_Activation
|
|
234 |
defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Activation] Copying advanced_cache file' ) ;
|
235 |
|
236 |
copy( LSCWP_DIR . 'includes/advanced-cache.php', $adv_cache_path ) ;
|
237 |
-
|
|
|
|
|
238 |
$ret = defined( 'LSCACHE_ADV_CACHE' ) ;
|
|
|
|
|
|
|
|
|
239 |
return $ret ;
|
240 |
}
|
241 |
|
234 |
defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Activation] Copying advanced_cache file' ) ;
|
235 |
|
236 |
copy( LSCWP_DIR . 'includes/advanced-cache.php', $adv_cache_path ) ;
|
237 |
+
|
238 |
+
include $adv_cache_path ;
|
239 |
+
|
240 |
$ret = defined( 'LSCACHE_ADV_CACHE' ) ;
|
241 |
+
|
242 |
+
// Try to enable `LITESPEED_ON`
|
243 |
+
LiteSpeed_Cache_Config::get_instance()->define_cache_on() ;
|
244 |
+
|
245 |
return $ret ;
|
246 |
}
|
247 |
|
inc/config.class.php
CHANGED
@@ -183,6 +183,7 @@ class LiteSpeed_Cache_Config
|
|
183 |
const OPID_MEDIA_IFRAME_LAZY = 'media_iframe_lazy' ;
|
184 |
const OPID_MEDIA_IMG_OPTM_CRON_OFF = 'media_img_optm_cron_off' ;
|
185 |
const OPID_MEDIA_IMG_WEBP = 'media_img_webp' ;
|
|
|
186 |
const OPID_MEDIA_IMG_WEBP_ONLY = 'media_img_webp_only' ;
|
187 |
const OPID_MEDIA_IMG_EXIF = 'media_img_exif' ;
|
188 |
const OPID_MEDIA_IMG_WEBP_LOSSLESS = 'media_img_webp_lossless' ;
|
@@ -236,7 +237,7 @@ class LiteSpeed_Cache_Config
|
|
236 |
$options = get_option( self::OPTION_NAME, $this->get_default_options() ) ;
|
237 |
|
238 |
// Check advanced_cache set
|
239 |
-
$this->
|
240 |
}
|
241 |
|
242 |
$this->options = $options ;
|
@@ -246,7 +247,7 @@ class LiteSpeed_Cache_Config
|
|
246 |
if ( $this->options[ self::OPID_ENABLED_RADIO ] === self::VAL_ON
|
247 |
// || ( is_multisite() && is_network_admin() && current_user_can( 'manage_network_options' ) && $this->options[ LiteSpeed_Cache_Config::NETWORK_OPID_ENABLED ] ) todo: need to check when primary is off and network is on, if can manage
|
248 |
) {
|
249 |
-
$this->
|
250 |
}
|
251 |
|
252 |
// Vary group settings
|
@@ -304,10 +305,10 @@ class LiteSpeed_Cache_Config
|
|
304 |
* @since 2.1
|
305 |
* @access private
|
306 |
*/
|
307 |
-
private function
|
308 |
{
|
309 |
-
if ( isset( $options[ self::OPID_CHECK_ADVANCEDCACHE ] ) && $options[ self::OPID_CHECK_ADVANCEDCACHE ]
|
310 |
-
define( 'LSCACHE_ADV_CACHE', true ) ;
|
311 |
}
|
312 |
}
|
313 |
|
@@ -315,11 +316,11 @@ class LiteSpeed_Cache_Config
|
|
315 |
* Define `LITESPEED_ON`
|
316 |
*
|
317 |
* @since 2.1
|
318 |
-
* @access
|
319 |
*/
|
320 |
-
|
321 |
{
|
322 |
-
defined( 'LITESPEED_ALLOWED' ) && ! defined( 'LITESPEED_ON' ) && define( 'LITESPEED_ON', true ) ;
|
323 |
|
324 |
// Use this for cache enabled setting check
|
325 |
! defined( 'LITESPEED_ON_IN_SETTING' ) && define( 'LITESPEED_ON_IN_SETTING', true ) ;
|
@@ -336,7 +337,7 @@ class LiteSpeed_Cache_Config
|
|
336 |
{
|
337 |
$site_options = get_site_option( self::OPTION_NAME ) ;
|
338 |
|
339 |
-
$this->
|
340 |
|
341 |
$options = get_option( self::OPTION_NAME, $this->get_default_options() ) ;
|
342 |
|
@@ -352,7 +353,7 @@ class LiteSpeed_Cache_Config
|
|
352 |
// If don't have site options
|
353 |
if ( ! $site_options || ! is_array( $site_options ) || ! is_plugin_active_for_network( 'litespeed-cache/litespeed-cache.php' ) ) {
|
354 |
if ( $options[ self::OPID_ENABLED_RADIO ] === self::VAL_ON2 ) { // Default to cache on
|
355 |
-
$this->
|
356 |
}
|
357 |
return $options ;
|
358 |
}
|
@@ -372,7 +373,7 @@ class LiteSpeed_Cache_Config
|
|
372 |
|
373 |
// If use network setting
|
374 |
if ( $options[ self::OPID_ENABLED_RADIO ] === self::VAL_ON2 && $site_options[ self::NETWORK_OPID_ENABLED ] ) {
|
375 |
-
$this->
|
376 |
}
|
377 |
// Set network eanble to on
|
378 |
if ( $site_options[ self::NETWORK_OPID_ENABLED ] ) {
|
@@ -715,6 +716,7 @@ class LiteSpeed_Cache_Config
|
|
715 |
self::OPID_MEDIA_IFRAME_LAZY => false,
|
716 |
self::OPID_MEDIA_IMG_OPTM_CRON_OFF => false,
|
717 |
self::OPID_MEDIA_IMG_WEBP => false,
|
|
|
718 |
self::OPID_MEDIA_IMG_WEBP_ONLY => false,
|
719 |
self::OPID_MEDIA_IMG_EXIF => false,
|
720 |
self::OPID_MEDIA_IMG_WEBP_LOSSLESS => false,
|
@@ -738,7 +740,7 @@ class LiteSpeed_Cache_Config
|
|
738 |
self::CRWL_DOMAIN_IP => '',
|
739 |
self::CRWL_CUSTOM_SITEMAP => '',
|
740 |
self::CRWL_CRON_ACTIVE => false,
|
741 |
-
self::CRWL_HTTP2 =>
|
742 |
) ;
|
743 |
|
744 |
if ( LSWCP_ESI_SUPPORT ) {
|
@@ -840,7 +842,11 @@ class LiteSpeed_Cache_Config
|
|
840 |
return LSCWP_CONTENT_FOLDER . "\nwp-includes\n/min/" ;
|
841 |
|
842 |
case self::ITEM_MEDIA_WEBP_ATTRIBUTE :
|
843 |
-
return "img.src\
|
|
|
|
|
|
|
|
|
844 |
|
845 |
default :
|
846 |
break ;
|
183 |
const OPID_MEDIA_IFRAME_LAZY = 'media_iframe_lazy' ;
|
184 |
const OPID_MEDIA_IMG_OPTM_CRON_OFF = 'media_img_optm_cron_off' ;
|
185 |
const OPID_MEDIA_IMG_WEBP = 'media_img_webp' ;
|
186 |
+
const OPID_MEDIA_IMG_WEBP_REPLACE_SRCSET = 'media_img_webp_replace_srcset' ;
|
187 |
const OPID_MEDIA_IMG_WEBP_ONLY = 'media_img_webp_only' ;
|
188 |
const OPID_MEDIA_IMG_EXIF = 'media_img_exif' ;
|
189 |
const OPID_MEDIA_IMG_WEBP_LOSSLESS = 'media_img_webp_lossless' ;
|
237 |
$options = get_option( self::OPTION_NAME, $this->get_default_options() ) ;
|
238 |
|
239 |
// Check advanced_cache set
|
240 |
+
$this->_define_adv_cache( $options ) ;
|
241 |
}
|
242 |
|
243 |
$this->options = $options ;
|
247 |
if ( $this->options[ self::OPID_ENABLED_RADIO ] === self::VAL_ON
|
248 |
// || ( is_multisite() && is_network_admin() && current_user_can( 'manage_network_options' ) && $this->options[ LiteSpeed_Cache_Config::NETWORK_OPID_ENABLED ] ) todo: need to check when primary is off and network is on, if can manage
|
249 |
) {
|
250 |
+
$this->define_cache_on() ;
|
251 |
}
|
252 |
|
253 |
// Vary group settings
|
305 |
* @since 2.1
|
306 |
* @access private
|
307 |
*/
|
308 |
+
private function _define_adv_cache( $options )
|
309 |
{
|
310 |
+
if ( isset( $options[ self::OPID_CHECK_ADVANCEDCACHE ] ) && ! $options[ self::OPID_CHECK_ADVANCEDCACHE ] ) {
|
311 |
+
! defined( 'LSCACHE_ADV_CACHE' ) && define( 'LSCACHE_ADV_CACHE', true ) ;
|
312 |
}
|
313 |
}
|
314 |
|
316 |
* Define `LITESPEED_ON`
|
317 |
*
|
318 |
* @since 2.1
|
319 |
+
* @access public
|
320 |
*/
|
321 |
+
public function define_cache_on()
|
322 |
{
|
323 |
+
defined( 'LITESPEED_ALLOWED' ) && defined( 'LSCACHE_ADV_CACHE' ) && ! defined( 'LITESPEED_ON' ) && define( 'LITESPEED_ON', true ) ;
|
324 |
|
325 |
// Use this for cache enabled setting check
|
326 |
! defined( 'LITESPEED_ON_IN_SETTING' ) && define( 'LITESPEED_ON_IN_SETTING', true ) ;
|
337 |
{
|
338 |
$site_options = get_site_option( self::OPTION_NAME ) ;
|
339 |
|
340 |
+
$this->_define_adv_cache( $site_options ) ;
|
341 |
|
342 |
$options = get_option( self::OPTION_NAME, $this->get_default_options() ) ;
|
343 |
|
353 |
// If don't have site options
|
354 |
if ( ! $site_options || ! is_array( $site_options ) || ! is_plugin_active_for_network( 'litespeed-cache/litespeed-cache.php' ) ) {
|
355 |
if ( $options[ self::OPID_ENABLED_RADIO ] === self::VAL_ON2 ) { // Default to cache on
|
356 |
+
$this->define_cache_on() ;
|
357 |
}
|
358 |
return $options ;
|
359 |
}
|
373 |
|
374 |
// If use network setting
|
375 |
if ( $options[ self::OPID_ENABLED_RADIO ] === self::VAL_ON2 && $site_options[ self::NETWORK_OPID_ENABLED ] ) {
|
376 |
+
$this->define_cache_on() ;
|
377 |
}
|
378 |
// Set network eanble to on
|
379 |
if ( $site_options[ self::NETWORK_OPID_ENABLED ] ) {
|
716 |
self::OPID_MEDIA_IFRAME_LAZY => false,
|
717 |
self::OPID_MEDIA_IMG_OPTM_CRON_OFF => false,
|
718 |
self::OPID_MEDIA_IMG_WEBP => false,
|
719 |
+
self::OPID_MEDIA_IMG_WEBP_REPLACE_SRCSET => false,
|
720 |
self::OPID_MEDIA_IMG_WEBP_ONLY => false,
|
721 |
self::OPID_MEDIA_IMG_EXIF => false,
|
722 |
self::OPID_MEDIA_IMG_WEBP_LOSSLESS => false,
|
740 |
self::CRWL_DOMAIN_IP => '',
|
741 |
self::CRWL_CUSTOM_SITEMAP => '',
|
742 |
self::CRWL_CRON_ACTIVE => false,
|
743 |
+
self::CRWL_HTTP2 => false,
|
744 |
) ;
|
745 |
|
746 |
if ( LSWCP_ESI_SUPPORT ) {
|
842 |
return LSCWP_CONTENT_FOLDER . "\nwp-includes\n/min/" ;
|
843 |
|
844 |
case self::ITEM_MEDIA_WEBP_ATTRIBUTE :
|
845 |
+
return "img.src\n" .
|
846 |
+
"div.data-thumb\n" .
|
847 |
+
"img.data-src\n" .
|
848 |
+
"div.data-large_image\n" .
|
849 |
+
"img.retina_logo_url" ;
|
850 |
|
851 |
default :
|
852 |
break ;
|
inc/control.class.php
CHANGED
@@ -40,6 +40,9 @@ class LiteSpeed_Cache_Control
|
|
40 |
* @since 1.6.2
|
41 |
*/
|
42 |
add_filter( 'litespeed_vary', array( $this, 'vary_add_role_exclude' ) ) ;
|
|
|
|
|
|
|
43 |
}
|
44 |
|
45 |
/**
|
40 |
* @since 1.6.2
|
41 |
*/
|
42 |
add_filter( 'litespeed_vary', array( $this, 'vary_add_role_exclude' ) ) ;
|
43 |
+
|
44 |
+
// 301 redirect hook
|
45 |
+
add_filter( 'wp_redirect', 'LiteSpeed_Cache_Control::check_redirect', 10, 2 ) ;
|
46 |
}
|
47 |
|
48 |
/**
|
inc/esi.class.php
CHANGED
@@ -180,7 +180,12 @@ class LiteSpeed_Cache_ESI
|
|
180 |
return false ;
|
181 |
}
|
182 |
|
183 |
-
$url = trailingslashit( wp_make_link_relative( home_url() ) ) . '?' . self::QS_ACTION . '=' . self::POSTTYPE
|
|
|
|
|
|
|
|
|
|
|
184 |
$output = "<esi:include src='$url'" ;
|
185 |
if ( ! empty( $control ) ) {
|
186 |
$output .= " cache-control='$control'" ;
|
@@ -253,6 +258,22 @@ class LiteSpeed_Cache_ESI
|
|
253 |
|
254 |
// LiteSpeed_Cache_Log::debug(var_export($params, true ));
|
255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
do_action('litespeed_cache_load_esi_block-' . $esi_id, $params) ;
|
257 |
}
|
258 |
|
180 |
return false ;
|
181 |
}
|
182 |
|
183 |
+
$url = trailingslashit( wp_make_link_relative( home_url() ) ) . '?' . self::QS_ACTION . '=' . self::POSTTYPE ;
|
184 |
+
if ( ! empty( $control ) ) {
|
185 |
+
$url .= '&_control=' . $control ;
|
186 |
+
}
|
187 |
+
$url .= '&' . self::QS_PARAMS . '=' . urlencode(base64_encode(serialize($params))) ;
|
188 |
+
|
189 |
$output = "<esi:include src='$url'" ;
|
190 |
if ( ! empty( $control ) ) {
|
191 |
$output .= " cache-control='$control'" ;
|
258 |
|
259 |
// LiteSpeed_Cache_Log::debug(var_export($params, true ));
|
260 |
|
261 |
+
/**
|
262 |
+
* Handle default cache control 'private,no-vary' for sub_esi_block() @ticket #923505
|
263 |
+
*
|
264 |
+
* @since 2.2.3
|
265 |
+
*/
|
266 |
+
if ( ! empty( $_GET[ '_control' ] ) ) {
|
267 |
+
$control = explode( ',', $_GET[ '_control' ] ) ;
|
268 |
+
if ( in_array( 'private', $control ) ) {
|
269 |
+
LiteSpeed_Cache_Control::set_private() ;
|
270 |
+
}
|
271 |
+
|
272 |
+
if ( in_array( 'no-vary', $control ) ) {
|
273 |
+
LiteSpeed_Cache_Control::set_no_vary() ;
|
274 |
+
}
|
275 |
+
}
|
276 |
+
|
277 |
do_action('litespeed_cache_load_esi_block-' . $esi_id, $params) ;
|
278 |
}
|
279 |
|
inc/litespeed-cache.class.php
CHANGED
@@ -19,7 +19,7 @@ class LiteSpeed_Cache
|
|
19 |
private static $_instance ;
|
20 |
|
21 |
const PLUGIN_NAME = 'litespeed-cache' ;
|
22 |
-
const PLUGIN_VERSION = '2.2.
|
23 |
|
24 |
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
|
25 |
|
@@ -158,7 +158,7 @@ class LiteSpeed_Cache
|
|
158 |
|
159 |
LiteSpeed_Cache_Router::get_instance()->is_crawler_role_simulation() ;
|
160 |
|
161 |
-
// if ( ! defined( 'LITESPEED_ON' ) || ! defined( 'LSCACHE_ADV_CACHE' )
|
162 |
// return ;
|
163 |
// }
|
164 |
|
@@ -194,8 +194,10 @@ class LiteSpeed_Cache
|
|
194 |
// Hook cdn for attachements
|
195 |
LiteSpeed_Cache_CDN::get_instance() ;
|
196 |
|
197 |
-
//
|
198 |
-
|
|
|
|
|
199 |
|
200 |
// load cron tasks
|
201 |
LiteSpeed_Cache_Task::get_instance() ;
|
@@ -360,38 +362,6 @@ class LiteSpeed_Cache
|
|
360 |
do_action( 'litespeed_cache_api_load_thirdparty' ) ;
|
361 |
}
|
362 |
|
363 |
-
/**
|
364 |
-
* Register all of the hooks related to the all users
|
365 |
-
* of the plugin.
|
366 |
-
*
|
367 |
-
* @since 1.0.0
|
368 |
-
* @access private
|
369 |
-
*/
|
370 |
-
private function load_public_actions()
|
371 |
-
{
|
372 |
-
//register purge actions
|
373 |
-
$purge_post_events = array(
|
374 |
-
'edit_post',
|
375 |
-
'save_post',
|
376 |
-
'deleted_post',
|
377 |
-
'trashed_post',
|
378 |
-
'delete_attachment',
|
379 |
-
// 'clean_post_cache', // This will disable wc's not purge product when stock status not change setting
|
380 |
-
) ;
|
381 |
-
foreach ( $purge_post_events as $event ) {
|
382 |
-
// this will purge all related tags
|
383 |
-
add_action( $event, 'LiteSpeed_Cache_Purge::purge_post', 10, 2 ) ;
|
384 |
-
}
|
385 |
-
|
386 |
-
add_action( 'wp_update_comment_count', 'LiteSpeed_Cache_Purge::purge_feeds' ) ;
|
387 |
-
|
388 |
-
// register recent posts widget tag before theme renders it to make it work
|
389 |
-
add_filter( 'widget_posts_args', 'LiteSpeed_Cache_Tag::add_widget_recent_posts' ) ;
|
390 |
-
|
391 |
-
// 301 redirect hook
|
392 |
-
add_filter( 'wp_redirect', 'LiteSpeed_Cache_Control::check_redirect', 10, 2 ) ;
|
393 |
-
}
|
394 |
-
|
395 |
/**
|
396 |
* A shortcut to get the LiteSpeed_Cache_Config config value
|
397 |
*
|
@@ -578,7 +548,7 @@ class LiteSpeed_Cache
|
|
578 |
}
|
579 |
|
580 |
// send Control header
|
581 |
-
if ( defined( '
|
582 |
@header( $control_header ) ;
|
583 |
if ( defined( 'LSCWP_LOG' ) ) {
|
584 |
LiteSpeed_Cache_Log::debug( $control_header ) ;
|
@@ -588,7 +558,7 @@ class LiteSpeed_Cache
|
|
588 |
}
|
589 |
}
|
590 |
// send PURGE header (Always send regardless of cache setting disabled/enabled)
|
591 |
-
if ( $purge_header ) {
|
592 |
@header( $purge_header ) ;
|
593 |
if ( defined( 'LSCWP_LOG' ) ) {
|
594 |
LiteSpeed_Cache_Log::debug( $purge_header ) ;
|
@@ -598,7 +568,7 @@ class LiteSpeed_Cache
|
|
598 |
}
|
599 |
}
|
600 |
// send Vary header
|
601 |
-
if ( defined( '
|
602 |
@header( $vary_header ) ;
|
603 |
if ( defined( 'LSCWP_LOG' ) ) {
|
604 |
LiteSpeed_Cache_Log::debug( $vary_header ) ;
|
@@ -628,7 +598,7 @@ class LiteSpeed_Cache
|
|
628 |
}
|
629 |
else {
|
630 |
// Control header
|
631 |
-
if ( defined( '
|
632 |
@header( $tag_header ) ;
|
633 |
if ( defined( 'LSCWP_LOG' ) ) {
|
634 |
LiteSpeed_Cache_Log::debug( $tag_header ) ;
|
19 |
private static $_instance ;
|
20 |
|
21 |
const PLUGIN_NAME = 'litespeed-cache' ;
|
22 |
+
const PLUGIN_VERSION = '2.2.3' ;
|
23 |
|
24 |
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
|
25 |
|
158 |
|
159 |
LiteSpeed_Cache_Router::get_instance()->is_crawler_role_simulation() ;
|
160 |
|
161 |
+
// if ( ! defined( 'LITESPEED_ON' ) || ! defined( 'LSCACHE_ADV_CACHE' ) ) {
|
162 |
// return ;
|
163 |
// }
|
164 |
|
194 |
// Hook cdn for attachements
|
195 |
LiteSpeed_Cache_CDN::get_instance() ;
|
196 |
|
197 |
+
// Init Purge hooks
|
198 |
+
LiteSpeed_Cache_Purge::get_instance() ;
|
199 |
+
|
200 |
+
LiteSpeed_Cache_Tag::get_instance() ;
|
201 |
|
202 |
// load cron tasks
|
203 |
LiteSpeed_Cache_Task::get_instance() ;
|
362 |
do_action( 'litespeed_cache_api_load_thirdparty' ) ;
|
363 |
}
|
364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
/**
|
366 |
* A shortcut to get the LiteSpeed_Cache_Config config value
|
367 |
*
|
548 |
}
|
549 |
|
550 |
// send Control header
|
551 |
+
if ( defined( 'LITESPEED_ON' ) && $control_header ) {
|
552 |
@header( $control_header ) ;
|
553 |
if ( defined( 'LSCWP_LOG' ) ) {
|
554 |
LiteSpeed_Cache_Log::debug( $control_header ) ;
|
558 |
}
|
559 |
}
|
560 |
// send PURGE header (Always send regardless of cache setting disabled/enabled)
|
561 |
+
if ( defined( 'LITESPEED_ON' ) && $purge_header ) {
|
562 |
@header( $purge_header ) ;
|
563 |
if ( defined( 'LSCWP_LOG' ) ) {
|
564 |
LiteSpeed_Cache_Log::debug( $purge_header ) ;
|
568 |
}
|
569 |
}
|
570 |
// send Vary header
|
571 |
+
if ( defined( 'LITESPEED_ON' ) && $vary_header ) {
|
572 |
@header( $vary_header ) ;
|
573 |
if ( defined( 'LSCWP_LOG' ) ) {
|
574 |
LiteSpeed_Cache_Log::debug( $vary_header ) ;
|
598 |
}
|
599 |
else {
|
600 |
// Control header
|
601 |
+
if ( defined( 'LITESPEED_ON' ) && LiteSpeed_Cache_Control::is_cacheable() && $tag_header ) {
|
602 |
@header( $tag_header ) ;
|
603 |
if ( defined( 'LSCWP_LOG' ) ) {
|
604 |
LiteSpeed_Cache_Log::debug( $tag_header ) ;
|
inc/media.class.php
CHANGED
@@ -421,11 +421,11 @@ class LiteSpeed_Cache_Media
|
|
421 |
* @since 1.6
|
422 |
*/
|
423 |
if ( strpos( $attrs[ 'src' ], 'base64' ) !== false || substr( $attrs[ 'src' ], 0, 5 ) === 'data:' ) {
|
424 |
-
LiteSpeed_Cache_Log::debug2( '[Media] bypassed base64 img' ) ;
|
425 |
continue ;
|
426 |
}
|
427 |
|
428 |
-
LiteSpeed_Cache_Log::debug2( '[Media] found: ' . $attrs[ 'src' ] ) ;
|
429 |
|
430 |
if ( ! empty( $attrs[ 'data-no-lazy' ] ) || ! empty( $attrs[ 'data-lazyloaded' ] ) || ! empty( $attrs[ 'data-src' ] ) || ! empty( $attrs[ 'data-srcset' ] ) ) {
|
431 |
LiteSpeed_Cache_Log::debug2( '[Media] bypassed' ) ;
|
@@ -531,7 +531,7 @@ class LiteSpeed_Cache_Media
|
|
531 |
continue ;
|
532 |
}
|
533 |
|
534 |
-
if ( ! $url2 = $this->
|
535 |
continue ;
|
536 |
}
|
537 |
|
@@ -554,6 +554,12 @@ class LiteSpeed_Cache_Media
|
|
554 |
}
|
555 |
}
|
556 |
|
|
|
|
|
|
|
|
|
|
|
|
|
557 |
// Replace background-image
|
558 |
preg_match_all( '#background\-image:(\s*)url\((.*)\)#iU', $this->content, $matches ) ;
|
559 |
foreach ( $matches[ 2 ] as $k => $url ) {
|
@@ -562,7 +568,7 @@ class LiteSpeed_Cache_Media
|
|
562 |
continue ;
|
563 |
}
|
564 |
|
565 |
-
if ( ! $url2 = $this->
|
566 |
continue ;
|
567 |
}
|
568 |
|
@@ -582,7 +588,7 @@ class LiteSpeed_Cache_Media
|
|
582 |
public function webp_attach_img_src( $img )
|
583 |
{
|
584 |
LiteSpeed_Cache_Log::debug2( '[Media] changing attach src: ' . $img[0] ) ;
|
585 |
-
if ( $img && $url = $this->
|
586 |
$img[ 0 ] = $url ;
|
587 |
}
|
588 |
return $img ;
|
@@ -598,7 +604,7 @@ class LiteSpeed_Cache_Media
|
|
598 |
*/
|
599 |
public function webp_url( $url )
|
600 |
{
|
601 |
-
if ( $url && $url2 = $this->
|
602 |
$url = $url2 ;
|
603 |
}
|
604 |
return $url ;
|
@@ -616,7 +622,7 @@ class LiteSpeed_Cache_Media
|
|
616 |
{
|
617 |
if ( $srcs ) {
|
618 |
foreach ( $srcs as $w => $data ) {
|
619 |
-
if( ! $url = $this->
|
620 |
continue ;
|
621 |
}
|
622 |
$srcs[ $w ][ 'url' ] = $url ;
|
@@ -629,11 +635,17 @@ class LiteSpeed_Cache_Media
|
|
629 |
* Replace internal image src to webp
|
630 |
*
|
631 |
* @since 1.6.2
|
632 |
-
* @access
|
633 |
*/
|
634 |
-
|
635 |
{
|
636 |
LiteSpeed_Cache_Log::debug2( '[Media] webp replacing: ' . $url, 4 ) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
637 |
if ( LiteSpeed_Cache_Utility::is_internal_file( $url ) ) {
|
638 |
// check if has webp file
|
639 |
if ( LiteSpeed_Cache_Utility::is_internal_file( $url . '.webp' ) ) {
|
@@ -649,6 +661,8 @@ class LiteSpeed_Cache_Media
|
|
649 |
return false ;
|
650 |
}
|
651 |
|
|
|
|
|
652 |
return $url ;
|
653 |
}
|
654 |
|
421 |
* @since 1.6
|
422 |
*/
|
423 |
if ( strpos( $attrs[ 'src' ], 'base64' ) !== false || substr( $attrs[ 'src' ], 0, 5 ) === 'data:' ) {
|
424 |
+
LiteSpeed_Cache_Log::debug2( '[Media] lazyload bypassed base64 img' ) ;
|
425 |
continue ;
|
426 |
}
|
427 |
|
428 |
+
LiteSpeed_Cache_Log::debug2( '[Media] lazyload found: ' . $attrs[ 'src' ] ) ;
|
429 |
|
430 |
if ( ! empty( $attrs[ 'data-no-lazy' ] ) || ! empty( $attrs[ 'data-lazyloaded' ] ) || ! empty( $attrs[ 'data-src' ] ) || ! empty( $attrs[ 'data-srcset' ] ) ) {
|
431 |
LiteSpeed_Cache_Log::debug2( '[Media] bypassed' ) ;
|
531 |
continue ;
|
532 |
}
|
533 |
|
534 |
+
if ( ! $url2 = $this->replace_webp( $url ) ) {
|
535 |
continue ;
|
536 |
}
|
537 |
|
554 |
}
|
555 |
}
|
556 |
|
557 |
+
// parse srcset
|
558 |
+
// todo: should apply this to cdn too
|
559 |
+
if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_MEDIA_IMG_WEBP_REPLACE_SRCSET ) ) {
|
560 |
+
$this->content = LiteSpeed_Cache_Utility::srcset_replace( $this->content, array( $this, 'replace_webp' ) ) ;
|
561 |
+
}
|
562 |
+
|
563 |
// Replace background-image
|
564 |
preg_match_all( '#background\-image:(\s*)url\((.*)\)#iU', $this->content, $matches ) ;
|
565 |
foreach ( $matches[ 2 ] as $k => $url ) {
|
568 |
continue ;
|
569 |
}
|
570 |
|
571 |
+
if ( ! $url2 = $this->replace_webp( $url ) ) {
|
572 |
continue ;
|
573 |
}
|
574 |
|
588 |
public function webp_attach_img_src( $img )
|
589 |
{
|
590 |
LiteSpeed_Cache_Log::debug2( '[Media] changing attach src: ' . $img[0] ) ;
|
591 |
+
if ( $img && $url = $this->replace_webp( $img[ 0 ] ) ) {
|
592 |
$img[ 0 ] = $url ;
|
593 |
}
|
594 |
return $img ;
|
604 |
*/
|
605 |
public function webp_url( $url )
|
606 |
{
|
607 |
+
if ( $url && $url2 = $this->replace_webp( $url ) ) {
|
608 |
$url = $url2 ;
|
609 |
}
|
610 |
return $url ;
|
622 |
{
|
623 |
if ( $srcs ) {
|
624 |
foreach ( $srcs as $w => $data ) {
|
625 |
+
if( ! $url = $this->replace_webp( $data[ 'url' ] ) ) {
|
626 |
continue ;
|
627 |
}
|
628 |
$srcs[ $w ][ 'url' ] = $url ;
|
635 |
* Replace internal image src to webp
|
636 |
*
|
637 |
* @since 1.6.2
|
638 |
+
* @access public
|
639 |
*/
|
640 |
+
public function replace_webp( $url )
|
641 |
{
|
642 |
LiteSpeed_Cache_Log::debug2( '[Media] webp replacing: ' . $url, 4 ) ;
|
643 |
+
|
644 |
+
if ( substr( $url, -5 ) == '.webp' ) {
|
645 |
+
LiteSpeed_Cache_Log::debug2( '[Media] already webp' ) ;
|
646 |
+
return false ;
|
647 |
+
}
|
648 |
+
|
649 |
if ( LiteSpeed_Cache_Utility::is_internal_file( $url ) ) {
|
650 |
// check if has webp file
|
651 |
if ( LiteSpeed_Cache_Utility::is_internal_file( $url . '.webp' ) ) {
|
661 |
return false ;
|
662 |
}
|
663 |
|
664 |
+
LiteSpeed_Cache_Log::debug2( '[Media] - replaced to: ' . $url ) ;
|
665 |
+
|
666 |
return $url ;
|
667 |
}
|
668 |
|
inc/optimize.class.php
CHANGED
@@ -665,21 +665,7 @@ class LiteSpeed_Cache_Optimize
|
|
665 |
|
666 |
// HTML minify
|
667 |
if ( $this->cfg_html_minify ) {
|
668 |
-
$
|
669 |
-
|
670 |
-
set_error_handler( 'litespeed_exception_handler' ) ;
|
671 |
-
try {
|
672 |
-
$this->content = LiteSpeed_Cache_Optimizer::get_instance()->html_min( $this->content ) ;
|
673 |
-
$this->content .= "\n" . '<!-- Page optimized by LiteSpeed Cache on '.date('Y-m-d H:i:s').' -->' ;
|
674 |
-
|
675 |
-
} catch ( ErrorException $e ) {
|
676 |
-
LiteSpeed_Cache_Log::debug( '[Optm] Error when optimizing HTML: ' . $e->getMessage() ) ;
|
677 |
-
error_log( 'LiteSpeed Optimizer optimizing HTML Error: ' . $e->getMessage() ) ;
|
678 |
-
// If failed to minify HTML, restore original content
|
679 |
-
$this->content = $ori ;
|
680 |
-
}
|
681 |
-
restore_error_handler() ;
|
682 |
-
|
683 |
}
|
684 |
|
685 |
if ( $this->http2_headers ) {
|
665 |
|
666 |
// HTML minify
|
667 |
if ( $this->cfg_html_minify ) {
|
668 |
+
$this->content = LiteSpeed_Cache_Optimizer::get_instance()->html_min( $this->content ) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
669 |
}
|
670 |
|
671 |
if ( $this->http2_headers ) {
|
inc/optimizer.class.php
CHANGED
@@ -45,15 +45,28 @@ class LiteSpeed_Cache_Optimizer
|
|
45 |
{
|
46 |
$options = array() ;
|
47 |
if ( $this->cfg_css_inline_minify ) {
|
48 |
-
$options[ 'cssMinifier' ] =
|
49 |
}
|
50 |
|
51 |
if ( $this->cfg_js_inline_minify ) {
|
52 |
-
$options[ 'jsMinifier' ] = '
|
53 |
}
|
54 |
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
}
|
58 |
|
59 |
/**
|
@@ -92,27 +105,29 @@ class LiteSpeed_Cache_Optimizer
|
|
92 |
|
93 |
LiteSpeed_Cache_Log::debug2( '[Optmer] urls : ', $urls ) ;
|
94 |
|
95 |
-
set_error_handler( 'litespeed_exception_handler' ) ;
|
96 |
|
97 |
$content = '' ;
|
98 |
$tmp = parse_url( $urls[ 0 ], PHP_URL_PATH ) ;
|
99 |
$file_type = substr( $tmp, strrpos( $tmp, '.' ) + 1 ) ;
|
100 |
-
try {
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
}
|
109 |
-
|
110 |
-
} catch ( ErrorException $e ) {
|
111 |
-
LiteSpeed_Cache_Log::debug( '[Optmer] Error when serving from optimizer: ' . $e->getMessage() ) ;
|
112 |
-
error_log( 'LiteSpeed Optimizer serving Error: ' . $e->getMessage() ) ;
|
113 |
-
return false ;
|
114 |
}
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
/**
|
118 |
* Clean comment when minify
|
@@ -143,8 +158,7 @@ class LiteSpeed_Cache_Optimizer
|
|
143 |
$data = preg_replace( '/@charset[^;]+;\\s*/', '', $data ) ;
|
144 |
|
145 |
if ( ! $concat_only && ! $this->_is_min( $real_path ) ) {
|
146 |
-
$
|
147 |
-
$data = $obj->run( $data ) ;
|
148 |
}
|
149 |
|
150 |
$data = Minify_CSS_UriRewriter::rewrite( $data, dirname( $real_path ) ) ;
|
@@ -168,7 +182,7 @@ class LiteSpeed_Cache_Optimizer
|
|
168 |
$data = Litespeed_File::read( $real_path ) ;
|
169 |
|
170 |
if ( ! $concat_only && ! $this->_is_min( $real_path ) ) {
|
171 |
-
$data =
|
172 |
}
|
173 |
else {
|
174 |
$data = $this->_null_minifier( $data ) ;
|
@@ -180,6 +194,59 @@ class LiteSpeed_Cache_Optimizer
|
|
180 |
return implode( "\n;", $con ) ;
|
181 |
}
|
182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
private function _null_minifier( $content )
|
184 |
{
|
185 |
$content = str_replace( "\r\n", "\n", $content ) ;
|
45 |
{
|
46 |
$options = array() ;
|
47 |
if ( $this->cfg_css_inline_minify ) {
|
48 |
+
$options[ 'cssMinifier' ] = 'LiteSpeed_Cache_Optimizer::minify_css' ;
|
49 |
}
|
50 |
|
51 |
if ( $this->cfg_js_inline_minify ) {
|
52 |
+
$options[ 'jsMinifier' ] = 'LiteSpeed_Cache_Optimizer::minify_js' ;
|
53 |
}
|
54 |
|
55 |
+
/**
|
56 |
+
* Added exception capture when minify
|
57 |
+
* @since 2.2.3
|
58 |
+
*/
|
59 |
+
try {
|
60 |
+
$obj = new Minify_HTML( $content, $options ) ;
|
61 |
+
$content_final = $obj->process() ;
|
62 |
+
$content_final .= "\n" . '<!-- Page optimized by LiteSpeed Cache @' . date('Y-m-d H:i:s') . ' -->' ;
|
63 |
+
return $content_final ;
|
64 |
+
|
65 |
+
} catch ( Exception $e ) {
|
66 |
+
LiteSpeed_Cache_Log::debug( '******[Optmer] html_min failed: ' . $e->getMessage() ) ;
|
67 |
+
error_log( '****** LiteSpeed Optimizer html_min failed: ' . $e->getMessage() ) ;
|
68 |
+
return $content ;
|
69 |
+
}
|
70 |
}
|
71 |
|
72 |
/**
|
105 |
|
106 |
LiteSpeed_Cache_Log::debug2( '[Optmer] urls : ', $urls ) ;
|
107 |
|
108 |
+
// set_error_handler( 'litespeed_exception_handler' ) ;
|
109 |
|
110 |
$content = '' ;
|
111 |
$tmp = parse_url( $urls[ 0 ], PHP_URL_PATH ) ;
|
112 |
$file_type = substr( $tmp, strrpos( $tmp, '.' ) + 1 ) ;
|
113 |
+
// try {
|
114 |
+
// Handle CSS
|
115 |
+
if ( $file_type === 'css' ) {
|
116 |
+
$content = $this->_serve_css( $real_files, $concat_only ) ;
|
117 |
+
}
|
118 |
+
// Handle JS
|
119 |
+
else {
|
120 |
+
$content = $this->_serve_js( $real_files, $concat_only ) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
}
|
122 |
+
|
123 |
+
// } catch ( Exception $e ) {
|
124 |
+
// $tmp = '[url] ' . implode( ', ', $urls ) . ' [err] ' . $e->getMessage() ;
|
125 |
+
|
126 |
+
// LiteSpeed_Cache_Log::debug( '******[Optmer] serve err ' . $tmp ) ;
|
127 |
+
// error_log( '****** LiteSpeed Optimizer serve err ' . $tmp ) ;
|
128 |
+
// return false ;//todo: return ori data
|
129 |
+
// }
|
130 |
+
// restore_error_handler() ;
|
131 |
|
132 |
/**
|
133 |
* Clean comment when minify
|
158 |
$data = preg_replace( '/@charset[^;]+;\\s*/', '', $data ) ;
|
159 |
|
160 |
if ( ! $concat_only && ! $this->_is_min( $real_path ) ) {
|
161 |
+
$data = self::minify_css( $data ) ;
|
|
|
162 |
}
|
163 |
|
164 |
$data = Minify_CSS_UriRewriter::rewrite( $data, dirname( $real_path ) ) ;
|
182 |
$data = Litespeed_File::read( $real_path ) ;
|
183 |
|
184 |
if ( ! $concat_only && ! $this->_is_min( $real_path ) ) {
|
185 |
+
$data = self::minify_js( $data ) ;
|
186 |
}
|
187 |
else {
|
188 |
$data = $this->_null_minifier( $data ) ;
|
194 |
return implode( "\n;", $con ) ;
|
195 |
}
|
196 |
|
197 |
+
/**
|
198 |
+
* Minify CSS
|
199 |
+
*
|
200 |
+
* @since 2.2.3
|
201 |
+
* @access private
|
202 |
+
*/
|
203 |
+
public static function minify_css( $data )
|
204 |
+
{
|
205 |
+
try {
|
206 |
+
$obj = new CSSmin() ;
|
207 |
+
return $obj->run( $data ) ;
|
208 |
+
|
209 |
+
} catch ( Exception $e ) {
|
210 |
+
LiteSpeed_Cache_Log::debug( '******[Optmer] minify_css failed: ' . $e->getMessage() ) ;
|
211 |
+
error_log( '****** LiteSpeed Optimizer minify_css failed: ' . $e->getMessage() ) ;
|
212 |
+
return $data ;
|
213 |
+
}
|
214 |
+
}
|
215 |
+
|
216 |
+
/**
|
217 |
+
* Minify JS
|
218 |
+
*
|
219 |
+
* Added exception capture when minify
|
220 |
+
*
|
221 |
+
* @since 2.2.3
|
222 |
+
* @access private
|
223 |
+
*/
|
224 |
+
public static function minify_js( $data, $js_type = '' )
|
225 |
+
{
|
226 |
+
// For inline JS optimize, need to check if it's js type
|
227 |
+
if ( $js_type ) {
|
228 |
+
preg_match( '#type=([\'"])(.+)\g{1}#isU', $js_type, $matches ) ;
|
229 |
+
if ( $matches && $matches[ 2 ] != 'text/javascript' ) {
|
230 |
+
LiteSpeed_Cache_Log::debug( '******[Optmer] minify_js bypass due to type: ' . $matches[ 2 ] ) ;
|
231 |
+
return $data ;
|
232 |
+
}
|
233 |
+
}
|
234 |
+
|
235 |
+
try {
|
236 |
+
$data = JSMin::minify( $data ) ;
|
237 |
+
return $data ;
|
238 |
+
} catch ( Exception $e ) {
|
239 |
+
LiteSpeed_Cache_Log::debug( '******[Optmer] minify_js failed: ' . $e->getMessage() ) ;
|
240 |
+
error_log( '****** LiteSpeed Optimizer minify_js failed: ' . $e->getMessage() ) ;
|
241 |
+
return $data ;
|
242 |
+
}
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Basic minifier
|
247 |
+
*
|
248 |
+
* @access private
|
249 |
+
*/
|
250 |
private function _null_minifier( $content )
|
251 |
{
|
252 |
$content = str_replace( "\r\n", "\n", $content ) ;
|
inc/purge.class.php
CHANGED
@@ -31,6 +31,31 @@ class LiteSpeed_Cache_Purge
|
|
31 |
const TYPE_PURGE_PAGES = 'purge_pages' ;
|
32 |
const TYPE_PURGE_ERROR = 'purge_error' ;
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
/**
|
35 |
* Handle all request actions from main cls
|
36 |
*
|
@@ -121,8 +146,8 @@ class LiteSpeed_Cache_Purge
|
|
121 |
|
122 |
LiteSpeed_Cache_Log::debug( '[Purge] Purge all ' . $reason, 3 ) ;
|
123 |
|
124 |
-
$msg = __( '
|
125 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
126 |
}
|
127 |
|
128 |
/**
|
@@ -145,7 +170,7 @@ class LiteSpeed_Cache_Purge
|
|
145 |
|
146 |
if ( ! $silence ) {
|
147 |
$msg = __( 'Notified LiteSpeed Web Server to purge all LSCache entries.', 'litespeed-cache' ) ;
|
148 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
149 |
}
|
150 |
}
|
151 |
|
@@ -164,7 +189,7 @@ class LiteSpeed_Cache_Purge
|
|
164 |
|
165 |
if ( ! $silence ) {
|
166 |
$msg = __( 'Notified LiteSpeed Web Server to purge CSS/JS entries.', 'litespeed-cache' ) ;
|
167 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
168 |
}
|
169 |
}
|
170 |
|
@@ -193,7 +218,7 @@ class LiteSpeed_Cache_Purge
|
|
193 |
|
194 |
if ( ! $silence ) {
|
195 |
$msg = __( 'Reset the entire opcode cache successfully.', 'litespeed-cache' ) ;
|
196 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
197 |
}
|
198 |
|
199 |
return true ;
|
@@ -222,7 +247,7 @@ class LiteSpeed_Cache_Purge
|
|
222 |
|
223 |
if ( ! $silence ) {
|
224 |
$msg = __( 'Purge all object caches successfully.', 'litespeed-cache' ) ;
|
225 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
226 |
}
|
227 |
|
228 |
return true ;
|
@@ -374,7 +399,7 @@ class LiteSpeed_Cache_Purge
|
|
374 |
}
|
375 |
|
376 |
$msg = __( 'Notified LiteSpeed Web Server to purge the front page.', 'litespeed-cache' ) ;
|
377 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
378 |
}
|
379 |
|
380 |
/**
|
@@ -388,7 +413,7 @@ class LiteSpeed_Cache_Purge
|
|
388 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_PAGES ) ;
|
389 |
|
390 |
$msg = __( 'Notified LiteSpeed Web Server to purge pages.', 'litespeed-cache' ) ;
|
391 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
392 |
}
|
393 |
|
394 |
/**
|
@@ -408,7 +433,7 @@ class LiteSpeed_Cache_Purge
|
|
408 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_ERROR . $type ) ;
|
409 |
|
410 |
$msg = __( 'Notified LiteSpeed Web Server to purge error pages.', 'litespeed-cache' ) ;
|
411 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
412 |
}
|
413 |
|
414 |
/**
|
@@ -435,7 +460,7 @@ class LiteSpeed_Cache_Purge
|
|
435 |
return ;
|
436 |
}
|
437 |
|
438 |
-
LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge category %s', 'litespeed-cache' ), $val ) ) ;
|
439 |
|
440 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_ARCHIVE_TERM . $cat->term_id ) ;
|
441 |
}
|
@@ -462,7 +487,7 @@ class LiteSpeed_Cache_Purge
|
|
462 |
LiteSpeed_Cache_Admin_Display::add_error( LiteSpeed_Cache_Admin_Error::E_PURGEBY_PID_DNE, $val ) ;
|
463 |
return ;
|
464 |
}
|
465 |
-
LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge Post ID %s', 'litespeed-cache' ), $val ) ) ;
|
466 |
|
467 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_POST . $val ) ;
|
468 |
}
|
@@ -491,7 +516,7 @@ class LiteSpeed_Cache_Purge
|
|
491 |
return ;
|
492 |
}
|
493 |
|
494 |
-
LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge tag %s', 'litespeed-cache' ), $val ) ) ;
|
495 |
|
496 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_ARCHIVE_TERM . $term->term_id ) ;
|
497 |
}
|
@@ -525,7 +550,7 @@ class LiteSpeed_Cache_Purge
|
|
525 |
return ;
|
526 |
}
|
527 |
|
528 |
-
LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge url %s', 'litespeed-cache' ), $val ) ) ;
|
529 |
|
530 |
$this->_add( $hash ) ;
|
531 |
return ;
|
31 |
const TYPE_PURGE_PAGES = 'purge_pages' ;
|
32 |
const TYPE_PURGE_ERROR = 'purge_error' ;
|
33 |
|
34 |
+
/**
|
35 |
+
* Initialize
|
36 |
+
*
|
37 |
+
* @since 2.2.3
|
38 |
+
*/
|
39 |
+
private function __construct()
|
40 |
+
{
|
41 |
+
//register purge actions
|
42 |
+
$purge_post_events = array(
|
43 |
+
'edit_post',
|
44 |
+
'save_post',
|
45 |
+
'deleted_post',
|
46 |
+
'trashed_post',
|
47 |
+
'delete_attachment',
|
48 |
+
// 'clean_post_cache', // This will disable wc's not purge product when stock status not change setting
|
49 |
+
) ;
|
50 |
+
foreach ( $purge_post_events as $event ) {
|
51 |
+
// this will purge all related tags
|
52 |
+
add_action( $event, 'LiteSpeed_Cache_Purge::purge_post', 10, 2 ) ;
|
53 |
+
}
|
54 |
+
|
55 |
+
add_action( 'wp_update_comment_count', 'LiteSpeed_Cache_Purge::purge_feeds' ) ;
|
56 |
+
|
57 |
+
}
|
58 |
+
|
59 |
/**
|
60 |
* Handle all request actions from main cls
|
61 |
*
|
146 |
|
147 |
LiteSpeed_Cache_Log::debug( '[Purge] Purge all ' . $reason, 3 ) ;
|
148 |
|
149 |
+
$msg = __( 'Purged all caches successfully.', 'litespeed-cache' ) ;
|
150 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
151 |
}
|
152 |
|
153 |
/**
|
170 |
|
171 |
if ( ! $silence ) {
|
172 |
$msg = __( 'Notified LiteSpeed Web Server to purge all LSCache entries.', 'litespeed-cache' ) ;
|
173 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
174 |
}
|
175 |
}
|
176 |
|
189 |
|
190 |
if ( ! $silence ) {
|
191 |
$msg = __( 'Notified LiteSpeed Web Server to purge CSS/JS entries.', 'litespeed-cache' ) ;
|
192 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
193 |
}
|
194 |
}
|
195 |
|
218 |
|
219 |
if ( ! $silence ) {
|
220 |
$msg = __( 'Reset the entire opcode cache successfully.', 'litespeed-cache' ) ;
|
221 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
222 |
}
|
223 |
|
224 |
return true ;
|
247 |
|
248 |
if ( ! $silence ) {
|
249 |
$msg = __( 'Purge all object caches successfully.', 'litespeed-cache' ) ;
|
250 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
251 |
}
|
252 |
|
253 |
return true ;
|
399 |
}
|
400 |
|
401 |
$msg = __( 'Notified LiteSpeed Web Server to purge the front page.', 'litespeed-cache' ) ;
|
402 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
403 |
}
|
404 |
|
405 |
/**
|
413 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_PAGES ) ;
|
414 |
|
415 |
$msg = __( 'Notified LiteSpeed Web Server to purge pages.', 'litespeed-cache' ) ;
|
416 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
417 |
}
|
418 |
|
419 |
/**
|
433 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_ERROR . $type ) ;
|
434 |
|
435 |
$msg = __( 'Notified LiteSpeed Web Server to purge error pages.', 'litespeed-cache' ) ;
|
436 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
437 |
}
|
438 |
|
439 |
/**
|
460 |
return ;
|
461 |
}
|
462 |
|
463 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge category %s', 'litespeed-cache' ), $val ) ) ;
|
464 |
|
465 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_ARCHIVE_TERM . $cat->term_id ) ;
|
466 |
}
|
487 |
LiteSpeed_Cache_Admin_Display::add_error( LiteSpeed_Cache_Admin_Error::E_PURGEBY_PID_DNE, $val ) ;
|
488 |
return ;
|
489 |
}
|
490 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge Post ID %s', 'litespeed-cache' ), $val ) ) ;
|
491 |
|
492 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_POST . $val ) ;
|
493 |
}
|
516 |
return ;
|
517 |
}
|
518 |
|
519 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge tag %s', 'litespeed-cache' ), $val ) ) ;
|
520 |
|
521 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_ARCHIVE_TERM . $term->term_id ) ;
|
522 |
}
|
550 |
return ;
|
551 |
}
|
552 |
|
553 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge url %s', 'litespeed-cache' ), $val ) ) ;
|
554 |
|
555 |
$this->_add( $hash ) ;
|
556 |
return ;
|
inc/router.class.php
CHANGED
@@ -166,10 +166,10 @@ class LiteSpeed_Cache_Router
|
|
166 |
public static function can_crawl()
|
167 |
{
|
168 |
if ( ! isset( self::$_can_crawl ) ) {
|
169 |
-
self::$_can_crawl =
|
170 |
|
171 |
-
if ( isset( $_SERVER['X-LSCACHE'] ) && strpos( $_SERVER['X-LSCACHE'], 'crawler' )
|
172 |
-
self::$_can_crawl =
|
173 |
}
|
174 |
|
175 |
// CLI will bypass this check as crawler library can always do the 428 check
|
@@ -177,10 +177,6 @@ class LiteSpeed_Cache_Router
|
|
177 |
self::$_can_crawl = true ;
|
178 |
}
|
179 |
|
180 |
-
// For non-ls users, they can use crawler
|
181 |
-
if ( ! defined( 'LITESPEED_ON' ) ) {
|
182 |
-
self::$_can_crawl = true ;
|
183 |
-
}
|
184 |
}
|
185 |
|
186 |
return self::$_can_crawl ;
|
166 |
public static function can_crawl()
|
167 |
{
|
168 |
if ( ! isset( self::$_can_crawl ) ) {
|
169 |
+
self::$_can_crawl = true ;
|
170 |
|
171 |
+
if ( isset( $_SERVER['X-LSCACHE'] ) && strpos( $_SERVER['X-LSCACHE'], 'crawler' ) === false ) {
|
172 |
+
self::$_can_crawl = false ;
|
173 |
}
|
174 |
|
175 |
// CLI will bypass this check as crawler library can always do the 428 check
|
177 |
self::$_can_crawl = true ;
|
178 |
}
|
179 |
|
|
|
|
|
|
|
|
|
180 |
}
|
181 |
|
182 |
return self::$_can_crawl ;
|
inc/tag.class.php
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
*/
|
11 |
class LiteSpeed_Cache_Tag
|
12 |
{
|
13 |
-
|
14 |
|
15 |
const TYPE_FEED = 'FD' ;
|
16 |
const TYPE_FRONTPAGE = 'F' ;
|
@@ -38,6 +38,18 @@ class LiteSpeed_Cache_Tag
|
|
38 |
private static $_tags_priv = array( 'tag_priv' ) ;
|
39 |
protected static $_error_status = false ;
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
/**
|
42 |
* Check if the login page is cacheable.
|
43 |
* If not, unset the cacheable member variable.
|
@@ -370,17 +382,17 @@ class LiteSpeed_Cache_Tag
|
|
370 |
/**
|
371 |
* Get the current instance object.
|
372 |
*
|
373 |
-
* @since
|
374 |
* @access public
|
375 |
* @return Current class instance.
|
376 |
*/
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
|
386 |
}
|
10 |
*/
|
11 |
class LiteSpeed_Cache_Tag
|
12 |
{
|
13 |
+
private static $_instance ;
|
14 |
|
15 |
const TYPE_FEED = 'FD' ;
|
16 |
const TYPE_FRONTPAGE = 'F' ;
|
38 |
private static $_tags_priv = array( 'tag_priv' ) ;
|
39 |
protected static $_error_status = false ;
|
40 |
|
41 |
+
/**
|
42 |
+
* Initialize
|
43 |
+
*
|
44 |
+
* @since 2.2.3
|
45 |
+
*/
|
46 |
+
private function __construct()
|
47 |
+
{
|
48 |
+
// register recent posts widget tag before theme renders it to make it work
|
49 |
+
add_filter( 'widget_posts_args', 'LiteSpeed_Cache_Tag::add_widget_recent_posts' ) ;
|
50 |
+
|
51 |
+
}
|
52 |
+
|
53 |
/**
|
54 |
* Check if the login page is cacheable.
|
55 |
* If not, unset the cacheable member variable.
|
382 |
/**
|
383 |
* Get the current instance object.
|
384 |
*
|
385 |
+
* @since 2.2.3
|
386 |
* @access public
|
387 |
* @return Current class instance.
|
388 |
*/
|
389 |
+
public static function get_instance()
|
390 |
+
{
|
391 |
+
if ( ! isset( self::$_instance ) ) {
|
392 |
+
self::$_instance = new self() ;
|
393 |
+
}
|
394 |
+
|
395 |
+
return self::$_instance ;
|
396 |
+
}
|
397 |
|
398 |
}
|
inc/task.class.php
CHANGED
@@ -90,16 +90,6 @@ class LiteSpeed_Cache_Task
|
|
90 |
$is_active = LiteSpeed_Cache::config( $id ) ;
|
91 |
}
|
92 |
|
93 |
-
// If cron setting is on, check cache status
|
94 |
-
if ( $is_active ) {
|
95 |
-
if ( defined( 'LITESPEED_NEW_OFF' ) ) {
|
96 |
-
$is_active = false ;
|
97 |
-
}
|
98 |
-
elseif ( ! defined( 'LITESPEED_ON' ) && ! defined( 'LITESPEED_NEW_ON' ) ) {
|
99 |
-
$is_active = false ;
|
100 |
-
}
|
101 |
-
}
|
102 |
-
|
103 |
if ( ! $is_active ) {
|
104 |
self::clear() ;
|
105 |
}
|
90 |
$is_active = LiteSpeed_Cache::config( $id ) ;
|
91 |
}
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
if ( ! $is_active ) {
|
94 |
self::clear() ;
|
95 |
}
|
inc/utility.class.php
CHANGED
@@ -437,7 +437,7 @@ class LiteSpeed_Cache_Utility
|
|
437 |
// Check if is cdn path
|
438 |
// Do this to avoid user hardcoded src in tpl
|
439 |
if ( ! LiteSpeed_Cache_CDN::internal( $url_parsed[ 'host' ] ) ) {
|
440 |
-
LiteSpeed_Cache_Log::debug2( '[
|
441 |
return false ;
|
442 |
}
|
443 |
}
|
@@ -482,16 +482,71 @@ class LiteSpeed_Cache_Utility
|
|
482 |
$file_path_ori = LiteSpeed_Cache_Router::frontend_path() . '/' . $url_parsed[ 'path' ] ;
|
483 |
}
|
484 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
$file_path = realpath( $file_path_ori ) ;
|
486 |
if ( ! is_file( $file_path ) ) {
|
487 |
-
LiteSpeed_Cache_Log::debug2( '[
|
488 |
return false ;
|
489 |
}
|
490 |
|
491 |
return array( $file_path, filesize( $file_path ) ) ;
|
492 |
}
|
493 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
494 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
495 |
|
496 |
|
497 |
|
437 |
// Check if is cdn path
|
438 |
// Do this to avoid user hardcoded src in tpl
|
439 |
if ( ! LiteSpeed_Cache_CDN::internal( $url_parsed[ 'host' ] ) ) {
|
440 |
+
LiteSpeed_Cache_Log::debug2( '[Util] external' ) ;
|
441 |
return false ;
|
442 |
}
|
443 |
}
|
482 |
$file_path_ori = LiteSpeed_Cache_Router::frontend_path() . '/' . $url_parsed[ 'path' ] ;
|
483 |
}
|
484 |
|
485 |
+
/**
|
486 |
+
* Added this filter for those plugins which overwrite the filepath
|
487 |
+
* @see #101091 plugin `Hide My WordPress`
|
488 |
+
* @since 2.2.3
|
489 |
+
*/
|
490 |
+
$file_path_ori = apply_filters( 'litespeed_realpath', $file_path_ori ) ;
|
491 |
+
|
492 |
$file_path = realpath( $file_path_ori ) ;
|
493 |
if ( ! is_file( $file_path ) ) {
|
494 |
+
LiteSpeed_Cache_Log::debug2( '[Util] file not exist: ' . $file_path_ori ) ;
|
495 |
return false ;
|
496 |
}
|
497 |
|
498 |
return array( $file_path, filesize( $file_path ) ) ;
|
499 |
}
|
500 |
|
501 |
+
/**
|
502 |
+
* Replace url in srcset to new value
|
503 |
+
*
|
504 |
+
* @since 2.2.3
|
505 |
+
*/
|
506 |
+
public static function srcset_replace( $content, $callback )
|
507 |
+
{
|
508 |
+
preg_match_all( '# srcset=([\'"])(.+)\g{1}#iU', $content, $matches ) ;
|
509 |
+
$srcset_ori = array() ;
|
510 |
+
$srcset_final = array() ;
|
511 |
+
foreach ( $matches[ 2 ] as $k => $urls_ori ) {
|
512 |
+
|
513 |
+
$urls_final = explode( ',', $urls_ori ) ;
|
514 |
+
|
515 |
+
$changed = false ;
|
516 |
+
|
517 |
+
foreach ( $urls_final as $k2 => $url_info ) {
|
518 |
+
list( $url, $size ) = explode( ' ', trim( $url_info ) ) ;
|
519 |
+
|
520 |
+
if ( ! $url2 = call_user_func( $callback, $url ) ) {
|
521 |
+
continue ;
|
522 |
+
}
|
523 |
+
|
524 |
+
$changed = true ;
|
525 |
+
|
526 |
+
$urls_final[ $k2 ] = str_replace( $url, $url2, $url_info ) ;
|
527 |
|
528 |
+
LiteSpeed_Cache_Log::debug2( '[Util] - srcset replaced to ' . $url2 . ' ' . $size ) ;
|
529 |
+
}
|
530 |
+
|
531 |
+
if ( ! $changed ) {
|
532 |
+
continue ;
|
533 |
+
}
|
534 |
+
|
535 |
+
$urls_final = implode( ',', $urls_final ) ;
|
536 |
+
|
537 |
+
$srcset_ori[] = $matches[ 0 ][ $k ] ;
|
538 |
+
|
539 |
+
$srcset_final[] = str_replace( $urls_ori, $urls_final, $matches[ 0 ][ $k ] ) ;
|
540 |
+
}
|
541 |
+
|
542 |
+
if ( $srcset_ori ) {
|
543 |
+
$content = str_replace( $srcset_ori, $srcset_final, $content ) ;
|
544 |
+
LiteSpeed_Cache_Log::debug2( '[Util] - srcset replaced' ) ;
|
545 |
+
}
|
546 |
+
|
547 |
+
return $content ;
|
548 |
+
|
549 |
+
}
|
550 |
|
551 |
|
552 |
|
includes/litespeed-cache-activation.class.php
CHANGED
@@ -234,8 +234,14 @@ class LiteSpeed_Cache_Activation
|
|
234 |
defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Activation] Copying advanced_cache file' ) ;
|
235 |
|
236 |
copy( LSCWP_DIR . 'includes/advanced-cache.php', $adv_cache_path ) ;
|
237 |
-
|
|
|
|
|
238 |
$ret = defined( 'LSCACHE_ADV_CACHE' ) ;
|
|
|
|
|
|
|
|
|
239 |
return $ret ;
|
240 |
}
|
241 |
|
234 |
defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Activation] Copying advanced_cache file' ) ;
|
235 |
|
236 |
copy( LSCWP_DIR . 'includes/advanced-cache.php', $adv_cache_path ) ;
|
237 |
+
|
238 |
+
include $adv_cache_path ;
|
239 |
+
|
240 |
$ret = defined( 'LSCACHE_ADV_CACHE' ) ;
|
241 |
+
|
242 |
+
// Try to enable `LITESPEED_ON`
|
243 |
+
LiteSpeed_Cache_Config::get_instance()->define_cache_on() ;
|
244 |
+
|
245 |
return $ret ;
|
246 |
}
|
247 |
|
includes/litespeed-cache-config.class.php
CHANGED
@@ -183,6 +183,7 @@ class LiteSpeed_Cache_Config
|
|
183 |
const OPID_MEDIA_IFRAME_LAZY = 'media_iframe_lazy' ;
|
184 |
const OPID_MEDIA_IMG_OPTM_CRON_OFF = 'media_img_optm_cron_off' ;
|
185 |
const OPID_MEDIA_IMG_WEBP = 'media_img_webp' ;
|
|
|
186 |
const OPID_MEDIA_IMG_WEBP_ONLY = 'media_img_webp_only' ;
|
187 |
const OPID_MEDIA_IMG_EXIF = 'media_img_exif' ;
|
188 |
const OPID_MEDIA_IMG_WEBP_LOSSLESS = 'media_img_webp_lossless' ;
|
@@ -236,7 +237,7 @@ class LiteSpeed_Cache_Config
|
|
236 |
$options = get_option( self::OPTION_NAME, $this->get_default_options() ) ;
|
237 |
|
238 |
// Check advanced_cache set
|
239 |
-
$this->
|
240 |
}
|
241 |
|
242 |
$this->options = $options ;
|
@@ -246,7 +247,7 @@ class LiteSpeed_Cache_Config
|
|
246 |
if ( $this->options[ self::OPID_ENABLED_RADIO ] === self::VAL_ON
|
247 |
// || ( is_multisite() && is_network_admin() && current_user_can( 'manage_network_options' ) && $this->options[ LiteSpeed_Cache_Config::NETWORK_OPID_ENABLED ] ) todo: need to check when primary is off and network is on, if can manage
|
248 |
) {
|
249 |
-
$this->
|
250 |
}
|
251 |
|
252 |
// Vary group settings
|
@@ -304,10 +305,10 @@ class LiteSpeed_Cache_Config
|
|
304 |
* @since 2.1
|
305 |
* @access private
|
306 |
*/
|
307 |
-
private function
|
308 |
{
|
309 |
-
if ( isset( $options[ self::OPID_CHECK_ADVANCEDCACHE ] ) && $options[ self::OPID_CHECK_ADVANCEDCACHE ]
|
310 |
-
define( 'LSCACHE_ADV_CACHE', true ) ;
|
311 |
}
|
312 |
}
|
313 |
|
@@ -315,11 +316,11 @@ class LiteSpeed_Cache_Config
|
|
315 |
* Define `LITESPEED_ON`
|
316 |
*
|
317 |
* @since 2.1
|
318 |
-
* @access
|
319 |
*/
|
320 |
-
|
321 |
{
|
322 |
-
defined( 'LITESPEED_ALLOWED' ) && ! defined( 'LITESPEED_ON' ) && define( 'LITESPEED_ON', true ) ;
|
323 |
|
324 |
// Use this for cache enabled setting check
|
325 |
! defined( 'LITESPEED_ON_IN_SETTING' ) && define( 'LITESPEED_ON_IN_SETTING', true ) ;
|
@@ -336,7 +337,7 @@ class LiteSpeed_Cache_Config
|
|
336 |
{
|
337 |
$site_options = get_site_option( self::OPTION_NAME ) ;
|
338 |
|
339 |
-
$this->
|
340 |
|
341 |
$options = get_option( self::OPTION_NAME, $this->get_default_options() ) ;
|
342 |
|
@@ -352,7 +353,7 @@ class LiteSpeed_Cache_Config
|
|
352 |
// If don't have site options
|
353 |
if ( ! $site_options || ! is_array( $site_options ) || ! is_plugin_active_for_network( 'litespeed-cache/litespeed-cache.php' ) ) {
|
354 |
if ( $options[ self::OPID_ENABLED_RADIO ] === self::VAL_ON2 ) { // Default to cache on
|
355 |
-
$this->
|
356 |
}
|
357 |
return $options ;
|
358 |
}
|
@@ -372,7 +373,7 @@ class LiteSpeed_Cache_Config
|
|
372 |
|
373 |
// If use network setting
|
374 |
if ( $options[ self::OPID_ENABLED_RADIO ] === self::VAL_ON2 && $site_options[ self::NETWORK_OPID_ENABLED ] ) {
|
375 |
-
$this->
|
376 |
}
|
377 |
// Set network eanble to on
|
378 |
if ( $site_options[ self::NETWORK_OPID_ENABLED ] ) {
|
@@ -715,6 +716,7 @@ class LiteSpeed_Cache_Config
|
|
715 |
self::OPID_MEDIA_IFRAME_LAZY => false,
|
716 |
self::OPID_MEDIA_IMG_OPTM_CRON_OFF => false,
|
717 |
self::OPID_MEDIA_IMG_WEBP => false,
|
|
|
718 |
self::OPID_MEDIA_IMG_WEBP_ONLY => false,
|
719 |
self::OPID_MEDIA_IMG_EXIF => false,
|
720 |
self::OPID_MEDIA_IMG_WEBP_LOSSLESS => false,
|
@@ -738,7 +740,7 @@ class LiteSpeed_Cache_Config
|
|
738 |
self::CRWL_DOMAIN_IP => '',
|
739 |
self::CRWL_CUSTOM_SITEMAP => '',
|
740 |
self::CRWL_CRON_ACTIVE => false,
|
741 |
-
self::CRWL_HTTP2 =>
|
742 |
) ;
|
743 |
|
744 |
if ( LSWCP_ESI_SUPPORT ) {
|
@@ -840,7 +842,11 @@ class LiteSpeed_Cache_Config
|
|
840 |
return LSCWP_CONTENT_FOLDER . "\nwp-includes\n/min/" ;
|
841 |
|
842 |
case self::ITEM_MEDIA_WEBP_ATTRIBUTE :
|
843 |
-
return "img.src\
|
|
|
|
|
|
|
|
|
844 |
|
845 |
default :
|
846 |
break ;
|
183 |
const OPID_MEDIA_IFRAME_LAZY = 'media_iframe_lazy' ;
|
184 |
const OPID_MEDIA_IMG_OPTM_CRON_OFF = 'media_img_optm_cron_off' ;
|
185 |
const OPID_MEDIA_IMG_WEBP = 'media_img_webp' ;
|
186 |
+
const OPID_MEDIA_IMG_WEBP_REPLACE_SRCSET = 'media_img_webp_replace_srcset' ;
|
187 |
const OPID_MEDIA_IMG_WEBP_ONLY = 'media_img_webp_only' ;
|
188 |
const OPID_MEDIA_IMG_EXIF = 'media_img_exif' ;
|
189 |
const OPID_MEDIA_IMG_WEBP_LOSSLESS = 'media_img_webp_lossless' ;
|
237 |
$options = get_option( self::OPTION_NAME, $this->get_default_options() ) ;
|
238 |
|
239 |
// Check advanced_cache set
|
240 |
+
$this->_define_adv_cache( $options ) ;
|
241 |
}
|
242 |
|
243 |
$this->options = $options ;
|
247 |
if ( $this->options[ self::OPID_ENABLED_RADIO ] === self::VAL_ON
|
248 |
// || ( is_multisite() && is_network_admin() && current_user_can( 'manage_network_options' ) && $this->options[ LiteSpeed_Cache_Config::NETWORK_OPID_ENABLED ] ) todo: need to check when primary is off and network is on, if can manage
|
249 |
) {
|
250 |
+
$this->define_cache_on() ;
|
251 |
}
|
252 |
|
253 |
// Vary group settings
|
305 |
* @since 2.1
|
306 |
* @access private
|
307 |
*/
|
308 |
+
private function _define_adv_cache( $options )
|
309 |
{
|
310 |
+
if ( isset( $options[ self::OPID_CHECK_ADVANCEDCACHE ] ) && ! $options[ self::OPID_CHECK_ADVANCEDCACHE ] ) {
|
311 |
+
! defined( 'LSCACHE_ADV_CACHE' ) && define( 'LSCACHE_ADV_CACHE', true ) ;
|
312 |
}
|
313 |
}
|
314 |
|
316 |
* Define `LITESPEED_ON`
|
317 |
*
|
318 |
* @since 2.1
|
319 |
+
* @access public
|
320 |
*/
|
321 |
+
public function define_cache_on()
|
322 |
{
|
323 |
+
defined( 'LITESPEED_ALLOWED' ) && defined( 'LSCACHE_ADV_CACHE' ) && ! defined( 'LITESPEED_ON' ) && define( 'LITESPEED_ON', true ) ;
|
324 |
|
325 |
// Use this for cache enabled setting check
|
326 |
! defined( 'LITESPEED_ON_IN_SETTING' ) && define( 'LITESPEED_ON_IN_SETTING', true ) ;
|
337 |
{
|
338 |
$site_options = get_site_option( self::OPTION_NAME ) ;
|
339 |
|
340 |
+
$this->_define_adv_cache( $site_options ) ;
|
341 |
|
342 |
$options = get_option( self::OPTION_NAME, $this->get_default_options() ) ;
|
343 |
|
353 |
// If don't have site options
|
354 |
if ( ! $site_options || ! is_array( $site_options ) || ! is_plugin_active_for_network( 'litespeed-cache/litespeed-cache.php' ) ) {
|
355 |
if ( $options[ self::OPID_ENABLED_RADIO ] === self::VAL_ON2 ) { // Default to cache on
|
356 |
+
$this->define_cache_on() ;
|
357 |
}
|
358 |
return $options ;
|
359 |
}
|
373 |
|
374 |
// If use network setting
|
375 |
if ( $options[ self::OPID_ENABLED_RADIO ] === self::VAL_ON2 && $site_options[ self::NETWORK_OPID_ENABLED ] ) {
|
376 |
+
$this->define_cache_on() ;
|
377 |
}
|
378 |
// Set network eanble to on
|
379 |
if ( $site_options[ self::NETWORK_OPID_ENABLED ] ) {
|
716 |
self::OPID_MEDIA_IFRAME_LAZY => false,
|
717 |
self::OPID_MEDIA_IMG_OPTM_CRON_OFF => false,
|
718 |
self::OPID_MEDIA_IMG_WEBP => false,
|
719 |
+
self::OPID_MEDIA_IMG_WEBP_REPLACE_SRCSET => false,
|
720 |
self::OPID_MEDIA_IMG_WEBP_ONLY => false,
|
721 |
self::OPID_MEDIA_IMG_EXIF => false,
|
722 |
self::OPID_MEDIA_IMG_WEBP_LOSSLESS => false,
|
740 |
self::CRWL_DOMAIN_IP => '',
|
741 |
self::CRWL_CUSTOM_SITEMAP => '',
|
742 |
self::CRWL_CRON_ACTIVE => false,
|
743 |
+
self::CRWL_HTTP2 => false,
|
744 |
) ;
|
745 |
|
746 |
if ( LSWCP_ESI_SUPPORT ) {
|
842 |
return LSCWP_CONTENT_FOLDER . "\nwp-includes\n/min/" ;
|
843 |
|
844 |
case self::ITEM_MEDIA_WEBP_ATTRIBUTE :
|
845 |
+
return "img.src\n" .
|
846 |
+
"div.data-thumb\n" .
|
847 |
+
"img.data-src\n" .
|
848 |
+
"div.data-large_image\n" .
|
849 |
+
"img.retina_logo_url" ;
|
850 |
|
851 |
default :
|
852 |
break ;
|
includes/litespeed-cache-control.class.php
CHANGED
@@ -40,6 +40,9 @@ class LiteSpeed_Cache_Control
|
|
40 |
* @since 1.6.2
|
41 |
*/
|
42 |
add_filter( 'litespeed_vary', array( $this, 'vary_add_role_exclude' ) ) ;
|
|
|
|
|
|
|
43 |
}
|
44 |
|
45 |
/**
|
40 |
* @since 1.6.2
|
41 |
*/
|
42 |
add_filter( 'litespeed_vary', array( $this, 'vary_add_role_exclude' ) ) ;
|
43 |
+
|
44 |
+
// 301 redirect hook
|
45 |
+
add_filter( 'wp_redirect', 'LiteSpeed_Cache_Control::check_redirect', 10, 2 ) ;
|
46 |
}
|
47 |
|
48 |
/**
|
includes/litespeed-cache-esi.class.php
CHANGED
@@ -180,7 +180,12 @@ class LiteSpeed_Cache_ESI
|
|
180 |
return false ;
|
181 |
}
|
182 |
|
183 |
-
$url = trailingslashit( wp_make_link_relative( home_url() ) ) . '?' . self::QS_ACTION . '=' . self::POSTTYPE
|
|
|
|
|
|
|
|
|
|
|
184 |
$output = "<esi:include src='$url'" ;
|
185 |
if ( ! empty( $control ) ) {
|
186 |
$output .= " cache-control='$control'" ;
|
@@ -253,6 +258,22 @@ class LiteSpeed_Cache_ESI
|
|
253 |
|
254 |
// LiteSpeed_Cache_Log::debug(var_export($params, true ));
|
255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
do_action('litespeed_cache_load_esi_block-' . $esi_id, $params) ;
|
257 |
}
|
258 |
|
180 |
return false ;
|
181 |
}
|
182 |
|
183 |
+
$url = trailingslashit( wp_make_link_relative( home_url() ) ) . '?' . self::QS_ACTION . '=' . self::POSTTYPE ;
|
184 |
+
if ( ! empty( $control ) ) {
|
185 |
+
$url .= '&_control=' . $control ;
|
186 |
+
}
|
187 |
+
$url .= '&' . self::QS_PARAMS . '=' . urlencode(base64_encode(serialize($params))) ;
|
188 |
+
|
189 |
$output = "<esi:include src='$url'" ;
|
190 |
if ( ! empty( $control ) ) {
|
191 |
$output .= " cache-control='$control'" ;
|
258 |
|
259 |
// LiteSpeed_Cache_Log::debug(var_export($params, true ));
|
260 |
|
261 |
+
/**
|
262 |
+
* Handle default cache control 'private,no-vary' for sub_esi_block() @ticket #923505
|
263 |
+
*
|
264 |
+
* @since 2.2.3
|
265 |
+
*/
|
266 |
+
if ( ! empty( $_GET[ '_control' ] ) ) {
|
267 |
+
$control = explode( ',', $_GET[ '_control' ] ) ;
|
268 |
+
if ( in_array( 'private', $control ) ) {
|
269 |
+
LiteSpeed_Cache_Control::set_private() ;
|
270 |
+
}
|
271 |
+
|
272 |
+
if ( in_array( 'no-vary', $control ) ) {
|
273 |
+
LiteSpeed_Cache_Control::set_no_vary() ;
|
274 |
+
}
|
275 |
+
}
|
276 |
+
|
277 |
do_action('litespeed_cache_load_esi_block-' . $esi_id, $params) ;
|
278 |
}
|
279 |
|
includes/litespeed-cache-optimize.class.php
CHANGED
@@ -665,21 +665,7 @@ class LiteSpeed_Cache_Optimize
|
|
665 |
|
666 |
// HTML minify
|
667 |
if ( $this->cfg_html_minify ) {
|
668 |
-
$
|
669 |
-
|
670 |
-
set_error_handler( 'litespeed_exception_handler' ) ;
|
671 |
-
try {
|
672 |
-
$this->content = LiteSpeed_Cache_Optimizer::get_instance()->html_min( $this->content ) ;
|
673 |
-
$this->content .= "\n" . '<!-- Page optimized by LiteSpeed Cache on '.date('Y-m-d H:i:s').' -->' ;
|
674 |
-
|
675 |
-
} catch ( ErrorException $e ) {
|
676 |
-
LiteSpeed_Cache_Log::debug( '[Optm] Error when optimizing HTML: ' . $e->getMessage() ) ;
|
677 |
-
error_log( 'LiteSpeed Optimizer optimizing HTML Error: ' . $e->getMessage() ) ;
|
678 |
-
// If failed to minify HTML, restore original content
|
679 |
-
$this->content = $ori ;
|
680 |
-
}
|
681 |
-
restore_error_handler() ;
|
682 |
-
|
683 |
}
|
684 |
|
685 |
if ( $this->http2_headers ) {
|
665 |
|
666 |
// HTML minify
|
667 |
if ( $this->cfg_html_minify ) {
|
668 |
+
$this->content = LiteSpeed_Cache_Optimizer::get_instance()->html_min( $this->content ) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
669 |
}
|
670 |
|
671 |
if ( $this->http2_headers ) {
|
includes/litespeed-cache-purge.class.php
CHANGED
@@ -31,6 +31,31 @@ class LiteSpeed_Cache_Purge
|
|
31 |
const TYPE_PURGE_PAGES = 'purge_pages' ;
|
32 |
const TYPE_PURGE_ERROR = 'purge_error' ;
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
/**
|
35 |
* Handle all request actions from main cls
|
36 |
*
|
@@ -121,8 +146,8 @@ class LiteSpeed_Cache_Purge
|
|
121 |
|
122 |
LiteSpeed_Cache_Log::debug( '[Purge] Purge all ' . $reason, 3 ) ;
|
123 |
|
124 |
-
$msg = __( '
|
125 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
126 |
}
|
127 |
|
128 |
/**
|
@@ -145,7 +170,7 @@ class LiteSpeed_Cache_Purge
|
|
145 |
|
146 |
if ( ! $silence ) {
|
147 |
$msg = __( 'Notified LiteSpeed Web Server to purge all LSCache entries.', 'litespeed-cache' ) ;
|
148 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
149 |
}
|
150 |
}
|
151 |
|
@@ -164,7 +189,7 @@ class LiteSpeed_Cache_Purge
|
|
164 |
|
165 |
if ( ! $silence ) {
|
166 |
$msg = __( 'Notified LiteSpeed Web Server to purge CSS/JS entries.', 'litespeed-cache' ) ;
|
167 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
168 |
}
|
169 |
}
|
170 |
|
@@ -193,7 +218,7 @@ class LiteSpeed_Cache_Purge
|
|
193 |
|
194 |
if ( ! $silence ) {
|
195 |
$msg = __( 'Reset the entire opcode cache successfully.', 'litespeed-cache' ) ;
|
196 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
197 |
}
|
198 |
|
199 |
return true ;
|
@@ -222,7 +247,7 @@ class LiteSpeed_Cache_Purge
|
|
222 |
|
223 |
if ( ! $silence ) {
|
224 |
$msg = __( 'Purge all object caches successfully.', 'litespeed-cache' ) ;
|
225 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
226 |
}
|
227 |
|
228 |
return true ;
|
@@ -374,7 +399,7 @@ class LiteSpeed_Cache_Purge
|
|
374 |
}
|
375 |
|
376 |
$msg = __( 'Notified LiteSpeed Web Server to purge the front page.', 'litespeed-cache' ) ;
|
377 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
378 |
}
|
379 |
|
380 |
/**
|
@@ -388,7 +413,7 @@ class LiteSpeed_Cache_Purge
|
|
388 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_PAGES ) ;
|
389 |
|
390 |
$msg = __( 'Notified LiteSpeed Web Server to purge pages.', 'litespeed-cache' ) ;
|
391 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
392 |
}
|
393 |
|
394 |
/**
|
@@ -408,7 +433,7 @@ class LiteSpeed_Cache_Purge
|
|
408 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_ERROR . $type ) ;
|
409 |
|
410 |
$msg = __( 'Notified LiteSpeed Web Server to purge error pages.', 'litespeed-cache' ) ;
|
411 |
-
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
412 |
}
|
413 |
|
414 |
/**
|
@@ -435,7 +460,7 @@ class LiteSpeed_Cache_Purge
|
|
435 |
return ;
|
436 |
}
|
437 |
|
438 |
-
LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge category %s', 'litespeed-cache' ), $val ) ) ;
|
439 |
|
440 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_ARCHIVE_TERM . $cat->term_id ) ;
|
441 |
}
|
@@ -462,7 +487,7 @@ class LiteSpeed_Cache_Purge
|
|
462 |
LiteSpeed_Cache_Admin_Display::add_error( LiteSpeed_Cache_Admin_Error::E_PURGEBY_PID_DNE, $val ) ;
|
463 |
return ;
|
464 |
}
|
465 |
-
LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge Post ID %s', 'litespeed-cache' ), $val ) ) ;
|
466 |
|
467 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_POST . $val ) ;
|
468 |
}
|
@@ -491,7 +516,7 @@ class LiteSpeed_Cache_Purge
|
|
491 |
return ;
|
492 |
}
|
493 |
|
494 |
-
LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge tag %s', 'litespeed-cache' ), $val ) ) ;
|
495 |
|
496 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_ARCHIVE_TERM . $term->term_id ) ;
|
497 |
}
|
@@ -525,7 +550,7 @@ class LiteSpeed_Cache_Purge
|
|
525 |
return ;
|
526 |
}
|
527 |
|
528 |
-
LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge url %s', 'litespeed-cache' ), $val ) ) ;
|
529 |
|
530 |
$this->_add( $hash ) ;
|
531 |
return ;
|
31 |
const TYPE_PURGE_PAGES = 'purge_pages' ;
|
32 |
const TYPE_PURGE_ERROR = 'purge_error' ;
|
33 |
|
34 |
+
/**
|
35 |
+
* Initialize
|
36 |
+
*
|
37 |
+
* @since 2.2.3
|
38 |
+
*/
|
39 |
+
private function __construct()
|
40 |
+
{
|
41 |
+
//register purge actions
|
42 |
+
$purge_post_events = array(
|
43 |
+
'edit_post',
|
44 |
+
'save_post',
|
45 |
+
'deleted_post',
|
46 |
+
'trashed_post',
|
47 |
+
'delete_attachment',
|
48 |
+
// 'clean_post_cache', // This will disable wc's not purge product when stock status not change setting
|
49 |
+
) ;
|
50 |
+
foreach ( $purge_post_events as $event ) {
|
51 |
+
// this will purge all related tags
|
52 |
+
add_action( $event, 'LiteSpeed_Cache_Purge::purge_post', 10, 2 ) ;
|
53 |
+
}
|
54 |
+
|
55 |
+
add_action( 'wp_update_comment_count', 'LiteSpeed_Cache_Purge::purge_feeds' ) ;
|
56 |
+
|
57 |
+
}
|
58 |
+
|
59 |
/**
|
60 |
* Handle all request actions from main cls
|
61 |
*
|
146 |
|
147 |
LiteSpeed_Cache_Log::debug( '[Purge] Purge all ' . $reason, 3 ) ;
|
148 |
|
149 |
+
$msg = __( 'Purged all caches successfully.', 'litespeed-cache' ) ;
|
150 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
151 |
}
|
152 |
|
153 |
/**
|
170 |
|
171 |
if ( ! $silence ) {
|
172 |
$msg = __( 'Notified LiteSpeed Web Server to purge all LSCache entries.', 'litespeed-cache' ) ;
|
173 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
174 |
}
|
175 |
}
|
176 |
|
189 |
|
190 |
if ( ! $silence ) {
|
191 |
$msg = __( 'Notified LiteSpeed Web Server to purge CSS/JS entries.', 'litespeed-cache' ) ;
|
192 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
193 |
}
|
194 |
}
|
195 |
|
218 |
|
219 |
if ( ! $silence ) {
|
220 |
$msg = __( 'Reset the entire opcode cache successfully.', 'litespeed-cache' ) ;
|
221 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
222 |
}
|
223 |
|
224 |
return true ;
|
247 |
|
248 |
if ( ! $silence ) {
|
249 |
$msg = __( 'Purge all object caches successfully.', 'litespeed-cache' ) ;
|
250 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
251 |
}
|
252 |
|
253 |
return true ;
|
399 |
}
|
400 |
|
401 |
$msg = __( 'Notified LiteSpeed Web Server to purge the front page.', 'litespeed-cache' ) ;
|
402 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
403 |
}
|
404 |
|
405 |
/**
|
413 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_PAGES ) ;
|
414 |
|
415 |
$msg = __( 'Notified LiteSpeed Web Server to purge pages.', 'litespeed-cache' ) ;
|
416 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
417 |
}
|
418 |
|
419 |
/**
|
433 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_ERROR . $type ) ;
|
434 |
|
435 |
$msg = __( 'Notified LiteSpeed Web Server to purge error pages.', 'litespeed-cache' ) ;
|
436 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
|
437 |
}
|
438 |
|
439 |
/**
|
460 |
return ;
|
461 |
}
|
462 |
|
463 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge category %s', 'litespeed-cache' ), $val ) ) ;
|
464 |
|
465 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_ARCHIVE_TERM . $cat->term_id ) ;
|
466 |
}
|
487 |
LiteSpeed_Cache_Admin_Display::add_error( LiteSpeed_Cache_Admin_Error::E_PURGEBY_PID_DNE, $val ) ;
|
488 |
return ;
|
489 |
}
|
490 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge Post ID %s', 'litespeed-cache' ), $val ) ) ;
|
491 |
|
492 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_POST . $val ) ;
|
493 |
}
|
516 |
return ;
|
517 |
}
|
518 |
|
519 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge tag %s', 'litespeed-cache' ), $val ) ) ;
|
520 |
|
521 |
$this->_add( LiteSpeed_Cache_Tag::TYPE_ARCHIVE_TERM . $term->term_id ) ;
|
522 |
}
|
550 |
return ;
|
551 |
}
|
552 |
|
553 |
+
! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge url %s', 'litespeed-cache' ), $val ) ) ;
|
554 |
|
555 |
$this->_add( $hash ) ;
|
556 |
return ;
|
includes/litespeed-cache-router.class.php
CHANGED
@@ -166,10 +166,10 @@ class LiteSpeed_Cache_Router
|
|
166 |
public static function can_crawl()
|
167 |
{
|
168 |
if ( ! isset( self::$_can_crawl ) ) {
|
169 |
-
self::$_can_crawl =
|
170 |
|
171 |
-
if ( isset( $_SERVER['X-LSCACHE'] ) && strpos( $_SERVER['X-LSCACHE'], 'crawler' )
|
172 |
-
self::$_can_crawl =
|
173 |
}
|
174 |
|
175 |
// CLI will bypass this check as crawler library can always do the 428 check
|
@@ -177,10 +177,6 @@ class LiteSpeed_Cache_Router
|
|
177 |
self::$_can_crawl = true ;
|
178 |
}
|
179 |
|
180 |
-
// For non-ls users, they can use crawler
|
181 |
-
if ( ! defined( 'LITESPEED_ON' ) ) {
|
182 |
-
self::$_can_crawl = true ;
|
183 |
-
}
|
184 |
}
|
185 |
|
186 |
return self::$_can_crawl ;
|
166 |
public static function can_crawl()
|
167 |
{
|
168 |
if ( ! isset( self::$_can_crawl ) ) {
|
169 |
+
self::$_can_crawl = true ;
|
170 |
|
171 |
+
if ( isset( $_SERVER['X-LSCACHE'] ) && strpos( $_SERVER['X-LSCACHE'], 'crawler' ) === false ) {
|
172 |
+
self::$_can_crawl = false ;
|
173 |
}
|
174 |
|
175 |
// CLI will bypass this check as crawler library can always do the 428 check
|
177 |
self::$_can_crawl = true ;
|
178 |
}
|
179 |
|
|
|
|
|
|
|
|
|
180 |
}
|
181 |
|
182 |
return self::$_can_crawl ;
|
includes/litespeed-cache-tag.class.php
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
*/
|
11 |
class LiteSpeed_Cache_Tag
|
12 |
{
|
13 |
-
|
14 |
|
15 |
const TYPE_FEED = 'FD' ;
|
16 |
const TYPE_FRONTPAGE = 'F' ;
|
@@ -38,6 +38,18 @@ class LiteSpeed_Cache_Tag
|
|
38 |
private static $_tags_priv = array( 'tag_priv' ) ;
|
39 |
protected static $_error_status = false ;
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
/**
|
42 |
* Check if the login page is cacheable.
|
43 |
* If not, unset the cacheable member variable.
|
@@ -370,17 +382,17 @@ class LiteSpeed_Cache_Tag
|
|
370 |
/**
|
371 |
* Get the current instance object.
|
372 |
*
|
373 |
-
* @since
|
374 |
* @access public
|
375 |
* @return Current class instance.
|
376 |
*/
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
|
386 |
}
|
10 |
*/
|
11 |
class LiteSpeed_Cache_Tag
|
12 |
{
|
13 |
+
private static $_instance ;
|
14 |
|
15 |
const TYPE_FEED = 'FD' ;
|
16 |
const TYPE_FRONTPAGE = 'F' ;
|
38 |
private static $_tags_priv = array( 'tag_priv' ) ;
|
39 |
protected static $_error_status = false ;
|
40 |
|
41 |
+
/**
|
42 |
+
* Initialize
|
43 |
+
*
|
44 |
+
* @since 2.2.3
|
45 |
+
*/
|
46 |
+
private function __construct()
|
47 |
+
{
|
48 |
+
// register recent posts widget tag before theme renders it to make it work
|
49 |
+
add_filter( 'widget_posts_args', 'LiteSpeed_Cache_Tag::add_widget_recent_posts' ) ;
|
50 |
+
|
51 |
+
}
|
52 |
+
|
53 |
/**
|
54 |
* Check if the login page is cacheable.
|
55 |
* If not, unset the cacheable member variable.
|
382 |
/**
|
383 |
* Get the current instance object.
|
384 |
*
|
385 |
+
* @since 2.2.3
|
386 |
* @access public
|
387 |
* @return Current class instance.
|
388 |
*/
|
389 |
+
public static function get_instance()
|
390 |
+
{
|
391 |
+
if ( ! isset( self::$_instance ) ) {
|
392 |
+
self::$_instance = new self() ;
|
393 |
+
}
|
394 |
+
|
395 |
+
return self::$_instance ;
|
396 |
+
}
|
397 |
|
398 |
}
|
includes/litespeed-cache-task.class.php
CHANGED
@@ -90,16 +90,6 @@ class LiteSpeed_Cache_Task
|
|
90 |
$is_active = LiteSpeed_Cache::config( $id ) ;
|
91 |
}
|
92 |
|
93 |
-
// If cron setting is on, check cache status
|
94 |
-
if ( $is_active ) {
|
95 |
-
if ( defined( 'LITESPEED_NEW_OFF' ) ) {
|
96 |
-
$is_active = false ;
|
97 |
-
}
|
98 |
-
elseif ( ! defined( 'LITESPEED_ON' ) && ! defined( 'LITESPEED_NEW_ON' ) ) {
|
99 |
-
$is_active = false ;
|
100 |
-
}
|
101 |
-
}
|
102 |
-
|
103 |
if ( ! $is_active ) {
|
104 |
self::clear() ;
|
105 |
}
|
90 |
$is_active = LiteSpeed_Cache::config( $id ) ;
|
91 |
}
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
if ( ! $is_active ) {
|
94 |
self::clear() ;
|
95 |
}
|
includes/litespeed-cache-utility.class.php
CHANGED
@@ -437,7 +437,7 @@ class LiteSpeed_Cache_Utility
|
|
437 |
// Check if is cdn path
|
438 |
// Do this to avoid user hardcoded src in tpl
|
439 |
if ( ! LiteSpeed_Cache_CDN::internal( $url_parsed[ 'host' ] ) ) {
|
440 |
-
LiteSpeed_Cache_Log::debug2( '[
|
441 |
return false ;
|
442 |
}
|
443 |
}
|
@@ -482,16 +482,71 @@ class LiteSpeed_Cache_Utility
|
|
482 |
$file_path_ori = LiteSpeed_Cache_Router::frontend_path() . '/' . $url_parsed[ 'path' ] ;
|
483 |
}
|
484 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
$file_path = realpath( $file_path_ori ) ;
|
486 |
if ( ! is_file( $file_path ) ) {
|
487 |
-
LiteSpeed_Cache_Log::debug2( '[
|
488 |
return false ;
|
489 |
}
|
490 |
|
491 |
return array( $file_path, filesize( $file_path ) ) ;
|
492 |
}
|
493 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
494 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
495 |
|
496 |
|
497 |
|
437 |
// Check if is cdn path
|
438 |
// Do this to avoid user hardcoded src in tpl
|
439 |
if ( ! LiteSpeed_Cache_CDN::internal( $url_parsed[ 'host' ] ) ) {
|
440 |
+
LiteSpeed_Cache_Log::debug2( '[Util] external' ) ;
|
441 |
return false ;
|
442 |
}
|
443 |
}
|
482 |
$file_path_ori = LiteSpeed_Cache_Router::frontend_path() . '/' . $url_parsed[ 'path' ] ;
|
483 |
}
|
484 |
|
485 |
+
/**
|
486 |
+
* Added this filter for those plugins which overwrite the filepath
|
487 |
+
* @see #101091 plugin `Hide My WordPress`
|
488 |
+
* @since 2.2.3
|
489 |
+
*/
|
490 |
+
$file_path_ori = apply_filters( 'litespeed_realpath', $file_path_ori ) ;
|
491 |
+
|
492 |
$file_path = realpath( $file_path_ori ) ;
|
493 |
if ( ! is_file( $file_path ) ) {
|
494 |
+
LiteSpeed_Cache_Log::debug2( '[Util] file not exist: ' . $file_path_ori ) ;
|
495 |
return false ;
|
496 |
}
|
497 |
|
498 |
return array( $file_path, filesize( $file_path ) ) ;
|
499 |
}
|
500 |
|
501 |
+
/**
|
502 |
+
* Replace url in srcset to new value
|
503 |
+
*
|
504 |
+
* @since 2.2.3
|
505 |
+
*/
|
506 |
+
public static function srcset_replace( $content, $callback )
|
507 |
+
{
|
508 |
+
preg_match_all( '# srcset=([\'"])(.+)\g{1}#iU', $content, $matches ) ;
|
509 |
+
$srcset_ori = array() ;
|
510 |
+
$srcset_final = array() ;
|
511 |
+
foreach ( $matches[ 2 ] as $k => $urls_ori ) {
|
512 |
+
|
513 |
+
$urls_final = explode( ',', $urls_ori ) ;
|
514 |
+
|
515 |
+
$changed = false ;
|
516 |
+
|
517 |
+
foreach ( $urls_final as $k2 => $url_info ) {
|
518 |
+
list( $url, $size ) = explode( ' ', trim( $url_info ) ) ;
|
519 |
+
|
520 |
+
if ( ! $url2 = call_user_func( $callback, $url ) ) {
|
521 |
+
continue ;
|
522 |
+
}
|
523 |
+
|
524 |
+
$changed = true ;
|
525 |
+
|
526 |
+
$urls_final[ $k2 ] = str_replace( $url, $url2, $url_info ) ;
|
527 |
|
528 |
+
LiteSpeed_Cache_Log::debug2( '[Util] - srcset replaced to ' . $url2 . ' ' . $size ) ;
|
529 |
+
}
|
530 |
+
|
531 |
+
if ( ! $changed ) {
|
532 |
+
continue ;
|
533 |
+
}
|
534 |
+
|
535 |
+
$urls_final = implode( ',', $urls_final ) ;
|
536 |
+
|
537 |
+
$srcset_ori[] = $matches[ 0 ][ $k ] ;
|
538 |
+
|
539 |
+
$srcset_final[] = str_replace( $urls_ori, $urls_final, $matches[ 0 ][ $k ] ) ;
|
540 |
+
}
|
541 |
+
|
542 |
+
if ( $srcset_ori ) {
|
543 |
+
$content = str_replace( $srcset_ori, $srcset_final, $content ) ;
|
544 |
+
LiteSpeed_Cache_Log::debug2( '[Util] - srcset replaced' ) ;
|
545 |
+
}
|
546 |
+
|
547 |
+
return $content ;
|
548 |
+
|
549 |
+
}
|
550 |
|
551 |
|
552 |
|
includes/litespeed-cache.class.php
CHANGED
@@ -19,7 +19,7 @@ class LiteSpeed_Cache
|
|
19 |
private static $_instance ;
|
20 |
|
21 |
const PLUGIN_NAME = 'litespeed-cache' ;
|
22 |
-
const PLUGIN_VERSION = '2.2.
|
23 |
|
24 |
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
|
25 |
|
@@ -158,7 +158,7 @@ class LiteSpeed_Cache
|
|
158 |
|
159 |
LiteSpeed_Cache_Router::get_instance()->is_crawler_role_simulation() ;
|
160 |
|
161 |
-
// if ( ! defined( 'LITESPEED_ON' ) || ! defined( 'LSCACHE_ADV_CACHE' )
|
162 |
// return ;
|
163 |
// }
|
164 |
|
@@ -194,8 +194,10 @@ class LiteSpeed_Cache
|
|
194 |
// Hook cdn for attachements
|
195 |
LiteSpeed_Cache_CDN::get_instance() ;
|
196 |
|
197 |
-
//
|
198 |
-
|
|
|
|
|
199 |
|
200 |
// load cron tasks
|
201 |
LiteSpeed_Cache_Task::get_instance() ;
|
@@ -360,38 +362,6 @@ class LiteSpeed_Cache
|
|
360 |
do_action( 'litespeed_cache_api_load_thirdparty' ) ;
|
361 |
}
|
362 |
|
363 |
-
/**
|
364 |
-
* Register all of the hooks related to the all users
|
365 |
-
* of the plugin.
|
366 |
-
*
|
367 |
-
* @since 1.0.0
|
368 |
-
* @access private
|
369 |
-
*/
|
370 |
-
private function load_public_actions()
|
371 |
-
{
|
372 |
-
//register purge actions
|
373 |
-
$purge_post_events = array(
|
374 |
-
'edit_post',
|
375 |
-
'save_post',
|
376 |
-
'deleted_post',
|
377 |
-
'trashed_post',
|
378 |
-
'delete_attachment',
|
379 |
-
// 'clean_post_cache', // This will disable wc's not purge product when stock status not change setting
|
380 |
-
) ;
|
381 |
-
foreach ( $purge_post_events as $event ) {
|
382 |
-
// this will purge all related tags
|
383 |
-
add_action( $event, 'LiteSpeed_Cache_Purge::purge_post', 10, 2 ) ;
|
384 |
-
}
|
385 |
-
|
386 |
-
add_action( 'wp_update_comment_count', 'LiteSpeed_Cache_Purge::purge_feeds' ) ;
|
387 |
-
|
388 |
-
// register recent posts widget tag before theme renders it to make it work
|
389 |
-
add_filter( 'widget_posts_args', 'LiteSpeed_Cache_Tag::add_widget_recent_posts' ) ;
|
390 |
-
|
391 |
-
// 301 redirect hook
|
392 |
-
add_filter( 'wp_redirect', 'LiteSpeed_Cache_Control::check_redirect', 10, 2 ) ;
|
393 |
-
}
|
394 |
-
|
395 |
/**
|
396 |
* A shortcut to get the LiteSpeed_Cache_Config config value
|
397 |
*
|
@@ -578,7 +548,7 @@ class LiteSpeed_Cache
|
|
578 |
}
|
579 |
|
580 |
// send Control header
|
581 |
-
if ( defined( '
|
582 |
@header( $control_header ) ;
|
583 |
if ( defined( 'LSCWP_LOG' ) ) {
|
584 |
LiteSpeed_Cache_Log::debug( $control_header ) ;
|
@@ -588,7 +558,7 @@ class LiteSpeed_Cache
|
|
588 |
}
|
589 |
}
|
590 |
// send PURGE header (Always send regardless of cache setting disabled/enabled)
|
591 |
-
if ( $purge_header ) {
|
592 |
@header( $purge_header ) ;
|
593 |
if ( defined( 'LSCWP_LOG' ) ) {
|
594 |
LiteSpeed_Cache_Log::debug( $purge_header ) ;
|
@@ -598,7 +568,7 @@ class LiteSpeed_Cache
|
|
598 |
}
|
599 |
}
|
600 |
// send Vary header
|
601 |
-
if ( defined( '
|
602 |
@header( $vary_header ) ;
|
603 |
if ( defined( 'LSCWP_LOG' ) ) {
|
604 |
LiteSpeed_Cache_Log::debug( $vary_header ) ;
|
@@ -628,7 +598,7 @@ class LiteSpeed_Cache
|
|
628 |
}
|
629 |
else {
|
630 |
// Control header
|
631 |
-
if ( defined( '
|
632 |
@header( $tag_header ) ;
|
633 |
if ( defined( 'LSCWP_LOG' ) ) {
|
634 |
LiteSpeed_Cache_Log::debug( $tag_header ) ;
|
19 |
private static $_instance ;
|
20 |
|
21 |
const PLUGIN_NAME = 'litespeed-cache' ;
|
22 |
+
const PLUGIN_VERSION = '2.2.3' ;
|
23 |
|
24 |
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
|
25 |
|
158 |
|
159 |
LiteSpeed_Cache_Router::get_instance()->is_crawler_role_simulation() ;
|
160 |
|
161 |
+
// if ( ! defined( 'LITESPEED_ON' ) || ! defined( 'LSCACHE_ADV_CACHE' ) ) {
|
162 |
// return ;
|
163 |
// }
|
164 |
|
194 |
// Hook cdn for attachements
|
195 |
LiteSpeed_Cache_CDN::get_instance() ;
|
196 |
|
197 |
+
// Init Purge hooks
|
198 |
+
LiteSpeed_Cache_Purge::get_instance() ;
|
199 |
+
|
200 |
+
LiteSpeed_Cache_Tag::get_instance() ;
|
201 |
|
202 |
// load cron tasks
|
203 |
LiteSpeed_Cache_Task::get_instance() ;
|
362 |
do_action( 'litespeed_cache_api_load_thirdparty' ) ;
|
363 |
}
|
364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
/**
|
366 |
* A shortcut to get the LiteSpeed_Cache_Config config value
|
367 |
*
|
548 |
}
|
549 |
|
550 |
// send Control header
|
551 |
+
if ( defined( 'LITESPEED_ON' ) && $control_header ) {
|
552 |
@header( $control_header ) ;
|
553 |
if ( defined( 'LSCWP_LOG' ) ) {
|
554 |
LiteSpeed_Cache_Log::debug( $control_header ) ;
|
558 |
}
|
559 |
}
|
560 |
// send PURGE header (Always send regardless of cache setting disabled/enabled)
|
561 |
+
if ( defined( 'LITESPEED_ON' ) && $purge_header ) {
|
562 |
@header( $purge_header ) ;
|
563 |
if ( defined( 'LSCWP_LOG' ) ) {
|
564 |
LiteSpeed_Cache_Log::debug( $purge_header ) ;
|
568 |
}
|
569 |
}
|
570 |
// send Vary header
|
571 |
+
if ( defined( 'LITESPEED_ON' ) && $vary_header ) {
|
572 |
@header( $vary_header ) ;
|
573 |
if ( defined( 'LSCWP_LOG' ) ) {
|
574 |
LiteSpeed_Cache_Log::debug( $vary_header ) ;
|
598 |
}
|
599 |
else {
|
600 |
// Control header
|
601 |
+
if ( defined( 'LITESPEED_ON' ) && LiteSpeed_Cache_Control::is_cacheable() && $tag_header ) {
|
602 |
@header( $tag_header ) ;
|
603 |
if ( defined( 'LSCWP_LOG' ) ) {
|
604 |
LiteSpeed_Cache_Log::debug( $tag_header ) ;
|
languages/litespeed-cache.pot
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
# This file is distributed under the same license as the LiteSpeed Cache package.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
-
"Project-Id-Version: LiteSpeed Cache 2.2.
|
6 |
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/litespeed-cache\n"
|
7 |
-
"POT-Creation-Date: 2018-04-
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
@@ -130,6 +130,7 @@ msgstr ""
|
|
130 |
#: admin/tpl/setting/settings_inc.cache_object.php:75
|
131 |
#: admin/tpl/setting/settings_inc.cache_object.php:150
|
132 |
#: admin/tpl/setting/settings_media.php:8
|
|
|
133 |
#: admin/tpl/setting/settings_optimize.php:8
|
134 |
#: admin/tpl/setting/settings_optimize.php:176
|
135 |
#: admin/tpl/setting/settings_purge.php:8
|
@@ -419,74 +420,74 @@ msgstr ""
|
|
419 |
msgid "'Use primary site settings' set by Network Administrator."
|
420 |
msgstr ""
|
421 |
|
422 |
-
#: admin/litespeed-cache-admin-settings.class.php:
|
423 |
msgid "Site options saved."
|
424 |
msgstr ""
|
425 |
|
426 |
-
#: admin/litespeed-cache-admin-settings.class.php:
|
427 |
-
#: admin/litespeed-cache-admin-settings.class.php:
|
428 |
msgid "Default Public Cache"
|
429 |
msgstr ""
|
430 |
|
431 |
-
#: admin/litespeed-cache-admin-settings.class.php:
|
432 |
msgid "Default Private Cache"
|
433 |
msgstr ""
|
434 |
|
435 |
-
#: admin/litespeed-cache-admin-settings.class.php:
|
436 |
msgid "Default Front Page"
|
437 |
msgstr ""
|
438 |
|
439 |
-
#: admin/litespeed-cache-admin-settings.class.php:
|
440 |
msgid "Feed"
|
441 |
msgstr ""
|
442 |
|
443 |
-
#: admin/litespeed-cache-admin-settings.class.php:
|
444 |
#: admin/tpl/setting/settings_debug.php:88
|
445 |
msgid "Log File Size Limit"
|
446 |
msgstr ""
|
447 |
|
448 |
-
#: admin/litespeed-cache-admin-settings.class.php:
|
449 |
#: admin/tpl/setting/settings_crawler.php:13
|
450 |
msgid "Delay"
|
451 |
msgstr ""
|
452 |
|
453 |
-
#: admin/litespeed-cache-admin-settings.class.php:
|
454 |
#: admin/tpl/setting/settings_crawler.php:37
|
455 |
msgid "Run Duration"
|
456 |
msgstr ""
|
457 |
|
458 |
-
#: admin/litespeed-cache-admin-settings.class.php:
|
459 |
msgid "Cron Interval"
|
460 |
msgstr ""
|
461 |
|
462 |
-
#: admin/litespeed-cache-admin-settings.class.php:
|
463 |
msgid "Whole Interval"
|
464 |
msgstr ""
|
465 |
|
466 |
-
#: admin/litespeed-cache-admin-settings.class.php:
|
467 |
#: admin/tpl/setting/settings_crawler.php:73
|
468 |
msgid "Threads"
|
469 |
msgstr ""
|
470 |
|
471 |
-
#: admin/litespeed-cache-admin.class.php:
|
472 |
msgid ""
|
473 |
"For this scenario only, the network admin may uncheck \"Check Advanced Cache"
|
474 |
"\" in LiteSpeed Cache settings."
|
475 |
msgstr ""
|
476 |
|
477 |
-
#: admin/litespeed-cache-admin.class.php:
|
478 |
msgid ""
|
479 |
"For this scenario only, please uncheck \"Check Advanced Cache\" in LiteSpeed "
|
480 |
"Cache settings."
|
481 |
msgstr ""
|
482 |
|
483 |
-
#: admin/litespeed-cache-admin.class.php:
|
484 |
msgid ""
|
485 |
"Please disable/deactivate any other Full Page Cache solutions that are "
|
486 |
"currently being used."
|
487 |
msgstr ""
|
488 |
|
489 |
-
#: admin/litespeed-cache-admin.class.php:
|
490 |
msgid ""
|
491 |
"LiteSpeed Cache does work with other cache solutions, but only their non-"
|
492 |
"page caching offerings—such as minifying css/js files."
|
@@ -1046,7 +1047,7 @@ msgstr ""
|
|
1046 |
msgid "Rate %s on %s"
|
1047 |
msgstr ""
|
1048 |
|
1049 |
-
#. #-#-#-#-# litespeed-cache.pot (LiteSpeed Cache 2.2.
|
1050 |
#. Plugin Name of the plugin/theme
|
1051 |
#: admin/tpl/inc/admin_footer.php:6 inc/gui.class.php:348
|
1052 |
#: includes/litespeed-cache-gui.class.php:348
|
@@ -3132,37 +3133,47 @@ msgid "Use the format %1$s or %2$s (element is optional)."
|
|
3132 |
msgstr ""
|
3133 |
|
3134 |
#: admin/tpl/setting/settings_media.php:102
|
3135 |
-
msgid "
|
3136 |
msgstr ""
|
3137 |
|
3138 |
#: admin/tpl/setting/settings_media.php:106
|
3139 |
msgid ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3140 |
"Prevent images from being replaced with optimized versions when optimizing. "
|
3141 |
"WebP versions will still be generated."
|
3142 |
msgstr ""
|
3143 |
|
3144 |
-
#: admin/tpl/setting/settings_media.php:
|
3145 |
msgid "Preserve EXIF data"
|
3146 |
msgstr ""
|
3147 |
|
3148 |
-
#: admin/tpl/setting/settings_media.php:
|
3149 |
msgid ""
|
3150 |
"Preserve EXIF data (copyright, GPS, comments, keywords, etc) when optimizing."
|
3151 |
msgstr ""
|
3152 |
|
3153 |
-
#: admin/tpl/setting/settings_media.php:
|
3154 |
msgid "This will increase the size of optimized files."
|
3155 |
msgstr ""
|
3156 |
|
3157 |
-
#: admin/tpl/setting/settings_media.php:
|
3158 |
msgid "WebP Lossless Compression"
|
3159 |
msgstr ""
|
3160 |
|
3161 |
-
#: admin/tpl/setting/settings_media.php:
|
3162 |
msgid "Generate WebP images using lossless compression."
|
3163 |
msgstr ""
|
3164 |
|
3165 |
-
#: admin/tpl/setting/settings_media.php:
|
3166 |
msgid "This can improve quality at the cost of larger images."
|
3167 |
msgstr ""
|
3168 |
|
@@ -3820,15 +3831,15 @@ msgstr ""
|
|
3820 |
msgid "Imported setting file %s successfully."
|
3821 |
msgstr ""
|
3822 |
|
3823 |
-
#: inc/litespeed-cache.class.php:
|
3824 |
msgid "Crawler blacklist is saved."
|
3825 |
msgstr ""
|
3826 |
|
3827 |
-
#: inc/litespeed-cache.class.php:
|
3828 |
msgid "Notified LiteSpeed Web Server to purge everything."
|
3829 |
msgstr ""
|
3830 |
|
3831 |
-
#: inc/litespeed-cache.class.php:
|
3832 |
msgid "Notified LiteSpeed Web Server to purge the list."
|
3833 |
msgstr ""
|
3834 |
|
@@ -3860,67 +3871,67 @@ msgstr ""
|
|
3860 |
msgid "Original saved %s"
|
3861 |
msgstr ""
|
3862 |
|
3863 |
-
#: inc/purge.class.php:
|
3864 |
-
msgid "
|
3865 |
msgstr ""
|
3866 |
|
3867 |
-
#: inc/purge.class.php:
|
3868 |
msgid "Notified LiteSpeed Web Server to purge all LSCache entries."
|
3869 |
msgstr ""
|
3870 |
|
3871 |
-
#: inc/purge.class.php:
|
3872 |
msgid "Notified LiteSpeed Web Server to purge CSS/JS entries."
|
3873 |
msgstr ""
|
3874 |
|
3875 |
-
#: inc/purge.class.php:
|
3876 |
msgid "Opcode cache is not enabled."
|
3877 |
msgstr ""
|
3878 |
|
3879 |
-
#: inc/purge.class.php:
|
3880 |
msgid "Reset the entire opcode cache successfully."
|
3881 |
msgstr ""
|
3882 |
|
3883 |
-
#: inc/purge.class.php:
|
3884 |
msgid "Object cache is not enabled."
|
3885 |
msgstr ""
|
3886 |
|
3887 |
-
#: inc/purge.class.php:
|
3888 |
msgid "Purge all object caches successfully."
|
3889 |
msgstr ""
|
3890 |
|
3891 |
-
#: inc/purge.class.php:
|
3892 |
msgid "Notified LiteSpeed Web Server to purge the front page."
|
3893 |
msgstr ""
|
3894 |
|
3895 |
-
#: inc/purge.class.php:
|
3896 |
msgid "Notified LiteSpeed Web Server to purge pages."
|
3897 |
msgstr ""
|
3898 |
|
3899 |
-
#: inc/purge.class.php:
|
3900 |
msgid "Notified LiteSpeed Web Server to purge error pages."
|
3901 |
msgstr ""
|
3902 |
|
3903 |
-
#: inc/purge.class.php:
|
3904 |
msgid "Purge category %s"
|
3905 |
msgstr ""
|
3906 |
|
3907 |
-
#: inc/purge.class.php:
|
3908 |
msgid "Purge Post ID %s"
|
3909 |
msgstr ""
|
3910 |
|
3911 |
-
#: inc/purge.class.php:
|
3912 |
msgid "Purge tag %s"
|
3913 |
msgstr ""
|
3914 |
|
3915 |
-
#: inc/purge.class.php:
|
3916 |
msgid "Purge url %s"
|
3917 |
msgstr ""
|
3918 |
|
3919 |
-
#: inc/task.class.php:
|
3920 |
msgid "LiteSpeed Cache Custom Cron ImgOptm"
|
3921 |
msgstr ""
|
3922 |
|
3923 |
-
#: inc/task.class.php:
|
3924 |
msgid "LiteSpeed Cache Custom Cron Crawler"
|
3925 |
msgstr ""
|
3926 |
|
2 |
# This file is distributed under the same license as the LiteSpeed Cache package.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
+
"Project-Id-Version: LiteSpeed Cache 2.2.3\n"
|
6 |
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/litespeed-cache\n"
|
7 |
+
"POT-Creation-Date: 2018-04-26 19:48:18+00:00\n"
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
130 |
#: admin/tpl/setting/settings_inc.cache_object.php:75
|
131 |
#: admin/tpl/setting/settings_inc.cache_object.php:150
|
132 |
#: admin/tpl/setting/settings_media.php:8
|
133 |
+
#: admin/tpl/setting/settings_media.php:107
|
134 |
#: admin/tpl/setting/settings_optimize.php:8
|
135 |
#: admin/tpl/setting/settings_optimize.php:176
|
136 |
#: admin/tpl/setting/settings_purge.php:8
|
420 |
msgid "'Use primary site settings' set by Network Administrator."
|
421 |
msgstr ""
|
422 |
|
423 |
+
#: admin/litespeed-cache-admin-settings.class.php:242
|
424 |
msgid "Site options saved."
|
425 |
msgstr ""
|
426 |
|
427 |
+
#: admin/litespeed-cache-admin-settings.class.php:342
|
428 |
+
#: admin/litespeed-cache-admin-settings.class.php:1030
|
429 |
msgid "Default Public Cache"
|
430 |
msgstr ""
|
431 |
|
432 |
+
#: admin/litespeed-cache-admin-settings.class.php:343
|
433 |
msgid "Default Private Cache"
|
434 |
msgstr ""
|
435 |
|
436 |
+
#: admin/litespeed-cache-admin-settings.class.php:344
|
437 |
msgid "Default Front Page"
|
438 |
msgstr ""
|
439 |
|
440 |
+
#: admin/litespeed-cache-admin-settings.class.php:345
|
441 |
msgid "Feed"
|
442 |
msgstr ""
|
443 |
|
444 |
+
#: admin/litespeed-cache-admin-settings.class.php:870
|
445 |
#: admin/tpl/setting/settings_debug.php:88
|
446 |
msgid "Log File Size Limit"
|
447 |
msgstr ""
|
448 |
|
449 |
+
#: admin/litespeed-cache-admin-settings.class.php:953
|
450 |
#: admin/tpl/setting/settings_crawler.php:13
|
451 |
msgid "Delay"
|
452 |
msgstr ""
|
453 |
|
454 |
+
#: admin/litespeed-cache-admin-settings.class.php:954
|
455 |
#: admin/tpl/setting/settings_crawler.php:37
|
456 |
msgid "Run Duration"
|
457 |
msgstr ""
|
458 |
|
459 |
+
#: admin/litespeed-cache-admin-settings.class.php:955
|
460 |
msgid "Cron Interval"
|
461 |
msgstr ""
|
462 |
|
463 |
+
#: admin/litespeed-cache-admin-settings.class.php:956
|
464 |
msgid "Whole Interval"
|
465 |
msgstr ""
|
466 |
|
467 |
+
#: admin/litespeed-cache-admin-settings.class.php:957
|
468 |
#: admin/tpl/setting/settings_crawler.php:73
|
469 |
msgid "Threads"
|
470 |
msgstr ""
|
471 |
|
472 |
+
#: admin/litespeed-cache-admin.class.php:211
|
473 |
msgid ""
|
474 |
"For this scenario only, the network admin may uncheck \"Check Advanced Cache"
|
475 |
"\" in LiteSpeed Cache settings."
|
476 |
msgstr ""
|
477 |
|
478 |
+
#: admin/litespeed-cache-admin.class.php:213
|
479 |
msgid ""
|
480 |
"For this scenario only, please uncheck \"Check Advanced Cache\" in LiteSpeed "
|
481 |
"Cache settings."
|
482 |
msgstr ""
|
483 |
|
484 |
+
#: admin/litespeed-cache-admin.class.php:215
|
485 |
msgid ""
|
486 |
"Please disable/deactivate any other Full Page Cache solutions that are "
|
487 |
"currently being used."
|
488 |
msgstr ""
|
489 |
|
490 |
+
#: admin/litespeed-cache-admin.class.php:216
|
491 |
msgid ""
|
492 |
"LiteSpeed Cache does work with other cache solutions, but only their non-"
|
493 |
"page caching offerings—such as minifying css/js files."
|
1047 |
msgid "Rate %s on %s"
|
1048 |
msgstr ""
|
1049 |
|
1050 |
+
#. #-#-#-#-# litespeed-cache.pot (LiteSpeed Cache 2.2.3) #-#-#-#-#
|
1051 |
#. Plugin Name of the plugin/theme
|
1052 |
#: admin/tpl/inc/admin_footer.php:6 inc/gui.class.php:348
|
1053 |
#: includes/litespeed-cache-gui.class.php:348
|
3133 |
msgstr ""
|
3134 |
|
3135 |
#: admin/tpl/setting/settings_media.php:102
|
3136 |
+
msgid "WebP For Extra srcset"
|
3137 |
msgstr ""
|
3138 |
|
3139 |
#: admin/tpl/setting/settings_media.php:106
|
3140 |
msgid ""
|
3141 |
+
"Enable replacement of WebP in %s elements that were generated outside of "
|
3142 |
+
"WordPress logic."
|
3143 |
+
msgstr ""
|
3144 |
+
|
3145 |
+
#: admin/tpl/setting/settings_media.php:113
|
3146 |
+
msgid "Only Request WebP"
|
3147 |
+
msgstr ""
|
3148 |
+
|
3149 |
+
#: admin/tpl/setting/settings_media.php:117
|
3150 |
+
msgid ""
|
3151 |
"Prevent images from being replaced with optimized versions when optimizing. "
|
3152 |
"WebP versions will still be generated."
|
3153 |
msgstr ""
|
3154 |
|
3155 |
+
#: admin/tpl/setting/settings_media.php:123
|
3156 |
msgid "Preserve EXIF data"
|
3157 |
msgstr ""
|
3158 |
|
3159 |
+
#: admin/tpl/setting/settings_media.php:127
|
3160 |
msgid ""
|
3161 |
"Preserve EXIF data (copyright, GPS, comments, keywords, etc) when optimizing."
|
3162 |
msgstr ""
|
3163 |
|
3164 |
+
#: admin/tpl/setting/settings_media.php:128
|
3165 |
msgid "This will increase the size of optimized files."
|
3166 |
msgstr ""
|
3167 |
|
3168 |
+
#: admin/tpl/setting/settings_media.php:134
|
3169 |
msgid "WebP Lossless Compression"
|
3170 |
msgstr ""
|
3171 |
|
3172 |
+
#: admin/tpl/setting/settings_media.php:138
|
3173 |
msgid "Generate WebP images using lossless compression."
|
3174 |
msgstr ""
|
3175 |
|
3176 |
+
#: admin/tpl/setting/settings_media.php:139
|
3177 |
msgid "This can improve quality at the cost of larger images."
|
3178 |
msgstr ""
|
3179 |
|
3831 |
msgid "Imported setting file %s successfully."
|
3832 |
msgstr ""
|
3833 |
|
3834 |
+
#: inc/litespeed-cache.class.php:262 includes/litespeed-cache.class.php:262
|
3835 |
msgid "Crawler blacklist is saved."
|
3836 |
msgstr ""
|
3837 |
|
3838 |
+
#: inc/litespeed-cache.class.php:273 includes/litespeed-cache.class.php:273
|
3839 |
msgid "Notified LiteSpeed Web Server to purge everything."
|
3840 |
msgstr ""
|
3841 |
|
3842 |
+
#: inc/litespeed-cache.class.php:283 includes/litespeed-cache.class.php:283
|
3843 |
msgid "Notified LiteSpeed Web Server to purge the list."
|
3844 |
msgstr ""
|
3845 |
|
3871 |
msgid "Original saved %s"
|
3872 |
msgstr ""
|
3873 |
|
3874 |
+
#: inc/purge.class.php:149 includes/litespeed-cache-purge.class.php:149
|
3875 |
+
msgid "Purged all caches successfully."
|
3876 |
msgstr ""
|
3877 |
|
3878 |
+
#: inc/purge.class.php:172 includes/litespeed-cache-purge.class.php:172
|
3879 |
msgid "Notified LiteSpeed Web Server to purge all LSCache entries."
|
3880 |
msgstr ""
|
3881 |
|
3882 |
+
#: inc/purge.class.php:191 includes/litespeed-cache-purge.class.php:191
|
3883 |
msgid "Notified LiteSpeed Web Server to purge CSS/JS entries."
|
3884 |
msgstr ""
|
3885 |
|
3886 |
+
#: inc/purge.class.php:208 includes/litespeed-cache-purge.class.php:208
|
3887 |
msgid "Opcode cache is not enabled."
|
3888 |
msgstr ""
|
3889 |
|
3890 |
+
#: inc/purge.class.php:220 includes/litespeed-cache-purge.class.php:220
|
3891 |
msgid "Reset the entire opcode cache successfully."
|
3892 |
msgstr ""
|
3893 |
|
3894 |
+
#: inc/purge.class.php:239 includes/litespeed-cache-purge.class.php:239
|
3895 |
msgid "Object cache is not enabled."
|
3896 |
msgstr ""
|
3897 |
|
3898 |
+
#: inc/purge.class.php:249 includes/litespeed-cache-purge.class.php:249
|
3899 |
msgid "Purge all object caches successfully."
|
3900 |
msgstr ""
|
3901 |
|
3902 |
+
#: inc/purge.class.php:401 includes/litespeed-cache-purge.class.php:401
|
3903 |
msgid "Notified LiteSpeed Web Server to purge the front page."
|
3904 |
msgstr ""
|
3905 |
|
3906 |
+
#: inc/purge.class.php:415 includes/litespeed-cache-purge.class.php:415
|
3907 |
msgid "Notified LiteSpeed Web Server to purge pages."
|
3908 |
msgstr ""
|
3909 |
|
3910 |
+
#: inc/purge.class.php:435 includes/litespeed-cache-purge.class.php:435
|
3911 |
msgid "Notified LiteSpeed Web Server to purge error pages."
|
3912 |
msgstr ""
|
3913 |
|
3914 |
+
#: inc/purge.class.php:463 includes/litespeed-cache-purge.class.php:463
|
3915 |
msgid "Purge category %s"
|
3916 |
msgstr ""
|
3917 |
|
3918 |
+
#: inc/purge.class.php:490 includes/litespeed-cache-purge.class.php:490
|
3919 |
msgid "Purge Post ID %s"
|
3920 |
msgstr ""
|
3921 |
|
3922 |
+
#: inc/purge.class.php:519 includes/litespeed-cache-purge.class.php:519
|
3923 |
msgid "Purge tag %s"
|
3924 |
msgstr ""
|
3925 |
|
3926 |
+
#: inc/purge.class.php:553 includes/litespeed-cache-purge.class.php:553
|
3927 |
msgid "Purge url %s"
|
3928 |
msgstr ""
|
3929 |
|
3930 |
+
#: inc/task.class.php:145 includes/litespeed-cache-task.class.php:145
|
3931 |
msgid "LiteSpeed Cache Custom Cron ImgOptm"
|
3932 |
msgstr ""
|
3933 |
|
3934 |
+
#: inc/task.class.php:166 includes/litespeed-cache-task.class.php:166
|
3935 |
msgid "LiteSpeed Cache Custom Cron Crawler"
|
3936 |
msgstr ""
|
3937 |
|
lib/html_min.class.php
CHANGED
@@ -18,241 +18,248 @@
|
|
18 |
*/
|
19 |
class Minify_HTML
|
20 |
{
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
}
|
18 |
*/
|
19 |
class Minify_HTML
|
20 |
{
|
21 |
+
/**
|
22 |
+
* @var boolean
|
23 |
+
*/
|
24 |
+
protected $_jsCleanComments = true;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* "Minify" an HTML page
|
28 |
+
*
|
29 |
+
* @param string $html
|
30 |
+
*
|
31 |
+
* @param array $options
|
32 |
+
*
|
33 |
+
* 'cssMinifier' : (optional) callback function to process content of STYLE
|
34 |
+
* elements.
|
35 |
+
*
|
36 |
+
* 'jsMinifier' : (optional) callback function to process content of SCRIPT
|
37 |
+
* elements. Note: the type attribute is ignored.
|
38 |
+
*
|
39 |
+
* 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
|
40 |
+
* unset, minify will sniff for an XHTML doctype.
|
41 |
+
*
|
42 |
+
* @return string
|
43 |
+
*/
|
44 |
+
public static function minify($html, $options = array())
|
45 |
+
{
|
46 |
+
$min = new self($html, $options);
|
47 |
+
|
48 |
+
return $min->process();
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Create a minifier object
|
53 |
+
*
|
54 |
+
* @param string $html
|
55 |
+
*
|
56 |
+
* @param array $options
|
57 |
+
*
|
58 |
+
* 'cssMinifier' : (optional) callback function to process content of STYLE
|
59 |
+
* elements.
|
60 |
+
*
|
61 |
+
* 'jsMinifier' : (optional) callback function to process content of SCRIPT
|
62 |
+
* elements. Note: the type attribute is ignored.
|
63 |
+
*
|
64 |
+
* 'jsCleanComments' : (optional) whether to remove HTML comments beginning and end of script block
|
65 |
+
*
|
66 |
+
* 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
|
67 |
+
* unset, minify will sniff for an XHTML doctype.
|
68 |
+
*/
|
69 |
+
public function __construct($html, $options = array())
|
70 |
+
{
|
71 |
+
$this->_html = str_replace("\r\n", "\n", trim($html));
|
72 |
+
if (isset($options['xhtml'])) {
|
73 |
+
$this->_isXhtml = (bool)$options['xhtml'];
|
74 |
+
}
|
75 |
+
if (isset($options['cssMinifier'])) {
|
76 |
+
$this->_cssMinifier = $options['cssMinifier'];
|
77 |
+
}
|
78 |
+
if (isset($options['jsMinifier'])) {
|
79 |
+
$this->_jsMinifier = $options['jsMinifier'];
|
80 |
+
}
|
81 |
+
if (isset($options['jsCleanComments'])) {
|
82 |
+
$this->_jsCleanComments = (bool)$options['jsCleanComments'];
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Minify the markeup given in the constructor
|
88 |
+
*
|
89 |
+
* @return string
|
90 |
+
*/
|
91 |
+
public function process()
|
92 |
+
{
|
93 |
+
if ($this->_isXhtml === null) {
|
94 |
+
$this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
|
95 |
+
}
|
96 |
+
|
97 |
+
$this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
|
98 |
+
$this->_placeholders = array();
|
99 |
+
|
100 |
+
// replace SCRIPTs (and minify) with placeholders
|
101 |
+
$this->_html = preg_replace_callback(
|
102 |
+
'/(\\s*)<script(\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/i'
|
103 |
+
,array($this, '_removeScriptCB')
|
104 |
+
,$this->_html);
|
105 |
+
|
106 |
+
// replace STYLEs (and minify) with placeholders
|
107 |
+
$this->_html = preg_replace_callback(
|
108 |
+
'/\\s*<style(\\b[^>]*>)([\\s\\S]*?)<\\/style>\\s*/i'
|
109 |
+
,array($this, '_removeStyleCB')
|
110 |
+
,$this->_html);
|
111 |
+
|
112 |
+
// remove HTML comments (not containing IE conditional comments).
|
113 |
+
$this->_html = preg_replace_callback(
|
114 |
+
'/<!--([\\s\\S]*?)-->/'
|
115 |
+
,array($this, '_commentCB')
|
116 |
+
,$this->_html);
|
117 |
+
|
118 |
+
// replace PREs with placeholders
|
119 |
+
$this->_html = preg_replace_callback('/\\s*<pre(\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i'
|
120 |
+
,array($this, '_removePreCB')
|
121 |
+
,$this->_html);
|
122 |
+
|
123 |
+
// replace TEXTAREAs with placeholders
|
124 |
+
$this->_html = preg_replace_callback(
|
125 |
+
'/\\s*<textarea(\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i'
|
126 |
+
,array($this, '_removeTextareaCB')
|
127 |
+
,$this->_html);
|
128 |
+
|
129 |
+
// trim each line.
|
130 |
+
// @todo take into account attribute values that span multiple lines.
|
131 |
+
$this->_html = preg_replace('/^\\s+|\\s+$/m', '', $this->_html);
|
132 |
+
|
133 |
+
// remove ws around block/undisplayed elements
|
134 |
+
$this->_html = preg_replace('/\\s+(<\\/?(?:area|article|aside|base(?:font)?|blockquote|body'
|
135 |
+
.'|canvas|caption|center|col(?:group)?|dd|dir|div|dl|dt|fieldset|figcaption|figure|footer|form'
|
136 |
+
.'|frame(?:set)?|h[1-6]|head|header|hgroup|hr|html|legend|li|link|main|map|menu|meta|nav'
|
137 |
+
.'|ol|opt(?:group|ion)|output|p|param|section|t(?:able|body|head|d|h||r|foot|itle)'
|
138 |
+
.'|ul|video)\\b[^>]*>)/i', '$1', $this->_html);
|
139 |
+
|
140 |
+
// remove ws outside of all elements
|
141 |
+
$this->_html = preg_replace(
|
142 |
+
'/>(\\s(?:\\s*))?([^<]+)(\\s(?:\s*))?</'
|
143 |
+
,'>$1$2$3<'
|
144 |
+
,$this->_html);
|
145 |
+
|
146 |
+
// use newlines before 1st attribute in open tags (to limit line lengths)
|
147 |
+
// $this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html);
|
148 |
+
|
149 |
+
// fill placeholders
|
150 |
+
$this->_html = str_replace(
|
151 |
+
array_keys($this->_placeholders)
|
152 |
+
,array_values($this->_placeholders)
|
153 |
+
,$this->_html
|
154 |
+
);
|
155 |
+
// issue 229: multi-pass to catch scripts that didn't get replaced in textareas
|
156 |
+
$this->_html = str_replace(
|
157 |
+
array_keys($this->_placeholders)
|
158 |
+
,array_values($this->_placeholders)
|
159 |
+
,$this->_html
|
160 |
+
);
|
161 |
+
|
162 |
+
return $this->_html;
|
163 |
+
}
|
164 |
+
|
165 |
+
protected function _commentCB($m)
|
166 |
+
{
|
167 |
+
return (0 === strpos($m[1], '[') || false !== strpos($m[1], '<!['))
|
168 |
+
? $m[0]
|
169 |
+
: '';
|
170 |
+
}
|
171 |
+
|
172 |
+
protected function _reservePlace($content)
|
173 |
+
{
|
174 |
+
$placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%';
|
175 |
+
$this->_placeholders[$placeholder] = $content;
|
176 |
+
|
177 |
+
return $placeholder;
|
178 |
+
}
|
179 |
+
|
180 |
+
protected $_isXhtml = null;
|
181 |
+
protected $_replacementHash = null;
|
182 |
+
protected $_placeholders = array();
|
183 |
+
protected $_cssMinifier = null;
|
184 |
+
protected $_jsMinifier = null;
|
185 |
+
|
186 |
+
protected function _removePreCB($m)
|
187 |
+
{
|
188 |
+
return $this->_reservePlace("<pre{$m[1]}");
|
189 |
+
}
|
190 |
+
|
191 |
+
protected function _removeTextareaCB($m)
|
192 |
+
{
|
193 |
+
return $this->_reservePlace("<textarea{$m[1]}");
|
194 |
+
}
|
195 |
+
|
196 |
+
protected function _removeStyleCB($m)
|
197 |
+
{
|
198 |
+
$openStyle = "<style{$m[1]}";
|
199 |
+
$css = $m[2];
|
200 |
+
// remove HTML comments
|
201 |
+
$css = preg_replace('/(?:^\\s*<!--|-->\\s*$)/', '', $css);
|
202 |
+
|
203 |
+
// remove CDATA section markers
|
204 |
+
$css = $this->_removeCdata($css);
|
205 |
+
|
206 |
+
// minify
|
207 |
+
$minifier = $this->_cssMinifier
|
208 |
+
? $this->_cssMinifier
|
209 |
+
: 'trim';
|
210 |
+
$css = call_user_func($minifier, $css);
|
211 |
+
|
212 |
+
return $this->_reservePlace($this->_needsCdata($css)
|
213 |
+
? "{$openStyle}/*<![CDATA[*/{$css}/*]]>*/</style>"
|
214 |
+
: "{$openStyle}{$css}</style>"
|
215 |
+
);
|
216 |
+
}
|
217 |
+
|
218 |
+
protected function _removeScriptCB($m)
|
219 |
+
{
|
220 |
+
$openScript = "<script{$m[2]}";
|
221 |
+
$js = $m[3];
|
222 |
+
|
223 |
+
// whitespace surrounding? preserve at least one space
|
224 |
+
$ws1 = ($m[1] === '') ? '' : ' ';
|
225 |
+
$ws2 = ($m[4] === '') ? '' : ' ';
|
226 |
+
|
227 |
+
// remove HTML comments (and ending "//" if present)
|
228 |
+
if ($this->_jsCleanComments) {
|
229 |
+
$js = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $js);
|
230 |
+
}
|
231 |
+
|
232 |
+
// remove CDATA section markers
|
233 |
+
$js = $this->_removeCdata($js);
|
234 |
+
|
235 |
+
// minify
|
236 |
+
/**
|
237 |
+
* Added 2nd param by LiteSpeed
|
238 |
+
*
|
239 |
+
* @since 2.2.3
|
240 |
+
*/
|
241 |
+
if ( $this->_jsMinifier ) {
|
242 |
+
$js = call_user_func( $this->_jsMinifier, $js, trim( $m[ 2 ] ) ) ;
|
243 |
+
}
|
244 |
+
else {
|
245 |
+
$js = trim( $js ) ;
|
246 |
+
}
|
247 |
+
|
248 |
+
return $this->_reservePlace($this->_needsCdata($js)
|
249 |
+
? "{$ws1}{$openScript}/*<![CDATA[*/{$js}/*]]>*/</script>{$ws2}"
|
250 |
+
: "{$ws1}{$openScript}{$js}</script>{$ws2}"
|
251 |
+
);
|
252 |
+
}
|
253 |
+
|
254 |
+
protected function _removeCdata($str)
|
255 |
+
{
|
256 |
+
return (false !== strpos($str, '<![CDATA['))
|
257 |
+
? str_replace(array('<![CDATA[', ']]>'), '', $str)
|
258 |
+
: $str;
|
259 |
+
}
|
260 |
+
|
261 |
+
protected function _needsCdata($str)
|
262 |
+
{
|
263 |
+
return ($this->_isXhtml && preg_match('/(?:[<&]|\\-\\-|\\]\\]>)/', $str));
|
264 |
+
}
|
265 |
}
|
lib/js_min.class.php
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
namespace JSMin;
|
4 |
-
|
5 |
/**
|
6 |
* JSMin.php - modified PHP implementation of Douglas Crockford's JSMin.
|
7 |
*
|
@@ -57,398 +55,398 @@ namespace JSMin;
|
|
57 |
* @link http://code.google.com/p/jsmin-php/
|
58 |
*/
|
59 |
class JSMin {
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
}
|
1 |
<?php
|
2 |
|
|
|
|
|
3 |
/**
|
4 |
* JSMin.php - modified PHP implementation of Douglas Crockford's JSMin.
|
5 |
*
|
55 |
* @link http://code.google.com/p/jsmin-php/
|
56 |
*/
|
57 |
class JSMin {
|
58 |
+
const ORD_LF = 10;
|
59 |
+
const ORD_SPACE = 32;
|
60 |
+
const ACTION_KEEP_A = 1;
|
61 |
+
const ACTION_DELETE_A = 2;
|
62 |
+
const ACTION_DELETE_A_B = 3;
|
63 |
+
|
64 |
+
protected $a = "\n";
|
65 |
+
protected $b = '';
|
66 |
+
protected $input = '';
|
67 |
+
protected $inputIndex = 0;
|
68 |
+
protected $inputLength = 0;
|
69 |
+
protected $lookAhead = null;
|
70 |
+
protected $output = '';
|
71 |
+
protected $lastByteOut = '';
|
72 |
+
protected $keptComment = '';
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Minify Javascript.
|
76 |
+
*
|
77 |
+
* @param string $js Javascript to be minified
|
78 |
+
*
|
79 |
+
* @return string
|
80 |
+
*/
|
81 |
+
public static function minify($js)
|
82 |
+
{
|
83 |
+
$jsmin = new JSMin($js);
|
84 |
+
return $jsmin->min();
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* @param string $input
|
89 |
+
*/
|
90 |
+
public function __construct($input)
|
91 |
+
{
|
92 |
+
$this->input = $input;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Perform minification, return result
|
97 |
+
*
|
98 |
+
* @return string
|
99 |
+
*/
|
100 |
+
public function min()
|
101 |
+
{
|
102 |
+
if ($this->output !== '') { // min already run
|
103 |
+
return $this->output;
|
104 |
+
}
|
105 |
+
|
106 |
+
$mbIntEnc = null;
|
107 |
+
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
108 |
+
$mbIntEnc = mb_internal_encoding();
|
109 |
+
mb_internal_encoding('8bit');
|
110 |
+
}
|
111 |
+
|
112 |
+
if (isset($this->input[0]) && $this->input[0] === "\xef") {
|
113 |
+
$this->input = substr($this->input, 3);
|
114 |
+
}
|
115 |
+
|
116 |
+
$this->input = str_replace("\r\n", "\n", $this->input);
|
117 |
+
$this->inputLength = strlen($this->input);
|
118 |
+
|
119 |
+
$this->action(self::ACTION_DELETE_A_B);
|
120 |
+
|
121 |
+
while ($this->a !== null) {
|
122 |
+
// determine next command
|
123 |
+
$command = self::ACTION_KEEP_A; // default
|
124 |
+
if ($this->a === ' ') {
|
125 |
+
if (($this->lastByteOut === '+' || $this->lastByteOut === '-')
|
126 |
+
&& ($this->b === $this->lastByteOut)) {
|
127 |
+
// Don't delete this space. If we do, the addition/subtraction
|
128 |
+
// could be parsed as a post-increment
|
129 |
+
} elseif (! $this->isAlphaNum($this->b)) {
|
130 |
+
$command = self::ACTION_DELETE_A;
|
131 |
+
}
|
132 |
+
} elseif ($this->a === "\n") {
|
133 |
+
if ($this->b === ' ') {
|
134 |
+
$command = self::ACTION_DELETE_A_B;
|
135 |
+
|
136 |
+
// in case of mbstring.func_overload & 2, must check for null b,
|
137 |
+
// otherwise mb_strpos will give WARNING
|
138 |
+
} elseif ($this->b === null
|
139 |
+
|| (false === strpos('{[(+-!~', $this->b)
|
140 |
+
&& ! $this->isAlphaNum($this->b))) {
|
141 |
+
$command = self::ACTION_DELETE_A;
|
142 |
+
}
|
143 |
+
} elseif (! $this->isAlphaNum($this->a)) {
|
144 |
+
if ($this->b === ' '
|
145 |
+
|| ($this->b === "\n"
|
146 |
+
&& (false === strpos('}])+-"\'', $this->a)))) {
|
147 |
+
$command = self::ACTION_DELETE_A_B;
|
148 |
+
}
|
149 |
+
}
|
150 |
+
$this->action($command);
|
151 |
+
}
|
152 |
+
$this->output = trim($this->output);
|
153 |
+
|
154 |
+
if ($mbIntEnc !== null) {
|
155 |
+
mb_internal_encoding($mbIntEnc);
|
156 |
+
}
|
157 |
+
return $this->output;
|
158 |
+
}
|
159 |
+
|
160 |
+
/**
|
161 |
+
* ACTION_KEEP_A = Output A. Copy B to A. Get the next B.
|
162 |
+
* ACTION_DELETE_A = Copy B to A. Get the next B.
|
163 |
+
* ACTION_DELETE_A_B = Get the next B.
|
164 |
+
*
|
165 |
+
* @param int $command
|
166 |
+
* @throws UnterminatedRegExpException|UnterminatedStringException
|
167 |
+
*/
|
168 |
+
protected function action($command)
|
169 |
+
{
|
170 |
+
// make sure we don't compress "a + ++b" to "a+++b", etc.
|
171 |
+
if ($command === self::ACTION_DELETE_A_B
|
172 |
+
&& $this->b === ' '
|
173 |
+
&& ($this->a === '+' || $this->a === '-')) {
|
174 |
+
// Note: we're at an addition/substraction operator; the inputIndex
|
175 |
+
// will certainly be a valid index
|
176 |
+
if ($this->input[$this->inputIndex] === $this->a) {
|
177 |
+
// This is "+ +" or "- -". Don't delete the space.
|
178 |
+
$command = self::ACTION_KEEP_A;
|
179 |
+
}
|
180 |
+
}
|
181 |
+
|
182 |
+
switch ($command) {
|
183 |
+
case self::ACTION_KEEP_A: // 1
|
184 |
+
$this->output .= $this->a;
|
185 |
+
|
186 |
+
if ($this->keptComment) {
|
187 |
+
$this->output = rtrim($this->output, "\n");
|
188 |
+
$this->output .= $this->keptComment;
|
189 |
+
$this->keptComment = '';
|
190 |
+
}
|
191 |
+
|
192 |
+
$this->lastByteOut = $this->a;
|
193 |
+
|
194 |
+
// fallthrough intentional
|
195 |
+
case self::ACTION_DELETE_A: // 2
|
196 |
+
$this->a = $this->b;
|
197 |
+
if ($this->a === "'" || $this->a === '"') { // string literal
|
198 |
+
$str = $this->a; // in case needed for exception
|
199 |
+
for(;;) {
|
200 |
+
$this->output .= $this->a;
|
201 |
+
$this->lastByteOut = $this->a;
|
202 |
+
|
203 |
+
$this->a = $this->get();
|
204 |
+
if ($this->a === $this->b) { // end quote
|
205 |
+
break;
|
206 |
+
}
|
207 |
+
if ($this->isEOF($this->a)) {
|
208 |
+
$byte = $this->inputIndex - 1;
|
209 |
+
throw new Exception(
|
210 |
+
"JSMin: Unterminated String at byte {$byte}: {$str}");
|
211 |
+
}
|
212 |
+
$str .= $this->a;
|
213 |
+
if ($this->a === '\\') {
|
214 |
+
$this->output .= $this->a;
|
215 |
+
$this->lastByteOut = $this->a;
|
216 |
+
|
217 |
+
$this->a = $this->get();
|
218 |
+
$str .= $this->a;
|
219 |
+
}
|
220 |
+
}
|
221 |
+
}
|
222 |
+
|
223 |
+
// fallthrough intentional
|
224 |
+
case self::ACTION_DELETE_A_B: // 3
|
225 |
+
$this->b = $this->next();
|
226 |
+
if ($this->b === '/' && $this->isRegexpLiteral()) {
|
227 |
+
$this->output .= $this->a . $this->b;
|
228 |
+
$pattern = '/'; // keep entire pattern in case we need to report it in the exception
|
229 |
+
for(;;) {
|
230 |
+
$this->a = $this->get();
|
231 |
+
$pattern .= $this->a;
|
232 |
+
if ($this->a === '[') {
|
233 |
+
for(;;) {
|
234 |
+
$this->output .= $this->a;
|
235 |
+
$this->a = $this->get();
|
236 |
+
$pattern .= $this->a;
|
237 |
+
if ($this->a === ']') {
|
238 |
+
break;
|
239 |
+
}
|
240 |
+
if ($this->a === '\\') {
|
241 |
+
$this->output .= $this->a;
|
242 |
+
$this->a = $this->get();
|
243 |
+
$pattern .= $this->a;
|
244 |
+
}
|
245 |
+
if ($this->isEOF($this->a)) {
|
246 |
+
throw new Exception(
|
247 |
+
"JSMin: Unterminated set in RegExp at byte "
|
248 |
+
. $this->inputIndex .": {$pattern}");
|
249 |
+
}
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
if ($this->a === '/') { // end pattern
|
254 |
+
break; // while (true)
|
255 |
+
} elseif ($this->a === '\\') {
|
256 |
+
$this->output .= $this->a;
|
257 |
+
$this->a = $this->get();
|
258 |
+
$pattern .= $this->a;
|
259 |
+
} elseif ($this->isEOF($this->a)) {
|
260 |
+
$byte = $this->inputIndex - 1;
|
261 |
+
throw new Exception(
|
262 |
+
"JSMin: Unterminated RegExp at byte {$byte}: {$pattern}");
|
263 |
+
}
|
264 |
+
$this->output .= $this->a;
|
265 |
+
$this->lastByteOut = $this->a;
|
266 |
+
}
|
267 |
+
$this->b = $this->next();
|
268 |
+
}
|
269 |
+
// end case ACTION_DELETE_A_B
|
270 |
+
}
|
271 |
+
}
|
272 |
+
|
273 |
+
/**
|
274 |
+
* @return bool
|
275 |
+
*/
|
276 |
+
protected function isRegexpLiteral()
|
277 |
+
{
|
278 |
+
if (false !== strpos("(,=:[!&|?+-~*{;", $this->a)) {
|
279 |
+
// we can't divide after these tokens
|
280 |
+
return true;
|
281 |
+
}
|
282 |
+
|
283 |
+
// check if first non-ws token is "/" (see starts-regex.js)
|
284 |
+
$length = strlen($this->output);
|
285 |
+
if ($this->a === ' ' || $this->a === "\n") {
|
286 |
+
if ($length < 2) { // weird edge case
|
287 |
+
return true;
|
288 |
+
}
|
289 |
+
}
|
290 |
+
|
291 |
+
// if the "/" follows a keyword, it must be a regexp, otherwise it's best to assume division
|
292 |
+
|
293 |
+
$subject = $this->output . trim($this->a);
|
294 |
+
if (!preg_match('/(?:case|else|in|return|typeof)$/', $subject, $m)) {
|
295 |
+
// not a keyword
|
296 |
+
return false;
|
297 |
+
}
|
298 |
+
|
299 |
+
// can't be sure it's a keyword yet (see not-regexp.js)
|
300 |
+
$charBeforeKeyword = substr($subject, 0 - strlen($m[0]) - 1, 1);
|
301 |
+
if ($this->isAlphaNum($charBeforeKeyword)) {
|
302 |
+
// this is really an identifier ending in a keyword, e.g. "xreturn"
|
303 |
+
return false;
|
304 |
+
}
|
305 |
+
|
306 |
+
// it's a regexp. Remove unneeded whitespace after keyword
|
307 |
+
if ($this->a === ' ' || $this->a === "\n") {
|
308 |
+
$this->a = '';
|
309 |
+
}
|
310 |
+
|
311 |
+
return true;
|
312 |
+
}
|
313 |
+
|
314 |
+
/**
|
315 |
+
* Return the next character from stdin. Watch out for lookahead. If the character is a control character,
|
316 |
+
* translate it to a space or linefeed.
|
317 |
+
*
|
318 |
+
* @return string
|
319 |
+
*/
|
320 |
+
protected function get()
|
321 |
+
{
|
322 |
+
$c = $this->lookAhead;
|
323 |
+
$this->lookAhead = null;
|
324 |
+
if ($c === null) {
|
325 |
+
// getc(stdin)
|
326 |
+
if ($this->inputIndex < $this->inputLength) {
|
327 |
+
$c = $this->input[$this->inputIndex];
|
328 |
+
$this->inputIndex += 1;
|
329 |
+
} else {
|
330 |
+
$c = null;
|
331 |
+
}
|
332 |
+
}
|
333 |
+
if (ord($c) >= self::ORD_SPACE || $c === "\n" || $c === null) {
|
334 |
+
return $c;
|
335 |
+
}
|
336 |
+
if ($c === "\r") {
|
337 |
+
return "\n";
|
338 |
+
}
|
339 |
+
return ' ';
|
340 |
+
}
|
341 |
+
|
342 |
+
/**
|
343 |
+
* Does $a indicate end of input?
|
344 |
+
*
|
345 |
+
* @param string $a
|
346 |
+
* @return bool
|
347 |
+
*/
|
348 |
+
protected function isEOF($a)
|
349 |
+
{
|
350 |
+
return ord($a) <= self::ORD_LF;
|
351 |
+
}
|
352 |
+
|
353 |
+
/**
|
354 |
+
* Get next char (without getting it). If is ctrl character, translate to a space or newline.
|
355 |
+
*
|
356 |
+
* @return string
|
357 |
+
*/
|
358 |
+
protected function peek()
|
359 |
+
{
|
360 |
+
$this->lookAhead = $this->get();
|
361 |
+
return $this->lookAhead;
|
362 |
+
}
|
363 |
+
|
364 |
+
/**
|
365 |
+
* Return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character.
|
366 |
+
*
|
367 |
+
* @param string $c
|
368 |
+
*
|
369 |
+
* @return bool
|
370 |
+
*/
|
371 |
+
protected function isAlphaNum($c)
|
372 |
+
{
|
373 |
+
return (preg_match('/^[a-z0-9A-Z_\\$\\\\]$/', $c) || ord($c) > 126);
|
374 |
+
}
|
375 |
+
|
376 |
+
/**
|
377 |
+
* Consume a single line comment from input (possibly retaining it)
|
378 |
+
*/
|
379 |
+
protected function consumeSingleLineComment()
|
380 |
+
{
|
381 |
+
$comment = '';
|
382 |
+
while (true) {
|
383 |
+
$get = $this->get();
|
384 |
+
$comment .= $get;
|
385 |
+
if (ord($get) <= self::ORD_LF) { // end of line reached
|
386 |
+
// if IE conditional comment
|
387 |
+
if (preg_match('/^\\/@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
388 |
+
$this->keptComment .= "/{$comment}";
|
389 |
+
}
|
390 |
+
return;
|
391 |
+
}
|
392 |
+
}
|
393 |
+
}
|
394 |
+
|
395 |
+
/**
|
396 |
+
* Consume a multiple line comment from input (possibly retaining it)
|
397 |
+
*
|
398 |
+
* @throws UnterminatedCommentException
|
399 |
+
*/
|
400 |
+
protected function consumeMultipleLineComment()
|
401 |
+
{
|
402 |
+
$this->get();
|
403 |
+
$comment = '';
|
404 |
+
for(;;) {
|
405 |
+
$get = $this->get();
|
406 |
+
if ($get === '*') {
|
407 |
+
if ($this->peek() === '/') { // end of comment reached
|
408 |
+
$this->get();
|
409 |
+
if (0 === strpos($comment, '!')) {
|
410 |
+
// preserved by YUI Compressor
|
411 |
+
if (!$this->keptComment) {
|
412 |
+
// don't prepend a newline if two comments right after one another
|
413 |
+
$this->keptComment = "\n";
|
414 |
+
}
|
415 |
+
$this->keptComment .= "/*!" . substr($comment, 1) . "*/\n";
|
416 |
+
} else if (preg_match('/^@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
417 |
+
// IE conditional
|
418 |
+
$this->keptComment .= "/*{$comment}*/";
|
419 |
+
}
|
420 |
+
return;
|
421 |
+
}
|
422 |
+
} elseif ($get === null) {
|
423 |
+
throw new Exception(
|
424 |
+
"JSMin: Unterminated comment at byte {$this->inputIndex}: /*{$comment}");
|
425 |
+
}
|
426 |
+
$comment .= $get;
|
427 |
+
}
|
428 |
+
}
|
429 |
+
|
430 |
+
/**
|
431 |
+
* Get the next character, skipping over comments. Some comments may be preserved.
|
432 |
+
*
|
433 |
+
* @return string
|
434 |
+
*/
|
435 |
+
protected function next()
|
436 |
+
{
|
437 |
+
$get = $this->get();
|
438 |
+
if ($get === '/') {
|
439 |
+
switch ($this->peek()) {
|
440 |
+
case '/':
|
441 |
+
$this->consumeSingleLineComment();
|
442 |
+
$get = "\n";
|
443 |
+
break;
|
444 |
+
case '*':
|
445 |
+
$this->consumeMultipleLineComment();
|
446 |
+
$get = ' ';
|
447 |
+
break;
|
448 |
+
}
|
449 |
+
}
|
450 |
+
return $get;
|
451 |
+
}
|
452 |
}
|
litespeed-cache.php
CHANGED
@@ -15,7 +15,7 @@
|
|
15 |
* Plugin Name: LiteSpeed Cache
|
16 |
* Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration
|
17 |
* Description: WordPress plugin to connect to LSCache on LiteSpeed Web Server.
|
18 |
-
* Version: 2.2.
|
19 |
* Author: LiteSpeed Technologies
|
20 |
* Author URI: https://www.litespeedtech.com
|
21 |
* License: GPLv3
|
15 |
* Plugin Name: LiteSpeed Cache
|
16 |
* Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration
|
17 |
* Description: WordPress plugin to connect to LSCache on LiteSpeed Web Server.
|
18 |
+
* Version: 2.2.3
|
19 |
* Author: LiteSpeed Technologies
|
20 |
* Author URI: https://www.litespeedtech.com
|
21 |
* License: GPLv3
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: LiteSpeedTech
|
|
3 |
Tags: cache, wp-cache, litespeed, super cache, http2, total cache, optimize, object cache, redis, memcached, lazy load, database cleaner
|
4 |
Requires at least: 4.0
|
5 |
Tested up to: 4.9.5
|
6 |
-
Stable tag: 2.2.
|
7 |
License: GPLv3
|
8 |
License URI: http://www.gnu.org/licenses/gpl.html
|
9 |
|
@@ -27,7 +27,8 @@ LSCWP supports WordPress Multisite and is compatible with most popular plugins,
|
|
27 |
* Object Cache (Memcached/LSMCD/Redis)
|
28 |
* Image Optimization
|
29 |
* Minify CSS, JavaScript, and HTML
|
30 |
-
*
|
|
|
31 |
* Lazyload images/iframes
|
32 |
* Multiple CDN support
|
33 |
* Load CSS/JS Asynchronously
|
@@ -36,7 +37,7 @@ LSCWP supports WordPress Multisite and is compatible with most popular plugins,
|
|
36 |
* Database Cleaner and Optimizer
|
37 |
* PageSpeed score optimization
|
38 |
* OPcode Cache
|
39 |
-
* HTTP/2 Push for CSS
|
40 |
* DNS Prefetch
|
41 |
* Cloudflare API
|
42 |
* Single Site and Multi Site (Network) support
|
@@ -44,6 +45,7 @@ LSCWP supports WordPress Multisite and is compatible with most popular plugins,
|
|
44 |
* Basic/Advanced setting view
|
45 |
* Attractive, easy-to-understand interface
|
46 |
* WebP image format support
|
|
|
47 |
|
48 |
= LiteSpeed Exclusive Features =
|
49 |
|
@@ -248,12 +250,27 @@ Click on the `Advanced View` link at the top of the page, and several more tabs
|
|
248 |
* [Elegant Themes Divi 3.0.67+](https://www.elegantthemes.com/gallery/divi/)
|
249 |
* [Caldera Forms](https://wordpress.org/plugins/caldera-forms/) 1.5.6.2+
|
250 |
* Login With Ajax
|
|
|
251 |
* [Post Types Order 1.9.3.6+](https://wordpress.org/plugins/post-types-order/)
|
252 |
* [BoomBox — Viral Magazine WordPress Theme](https://themeforest.net/item/boombox-viral-buzz-wordpress-theme/16596434?ref=PX-lab)
|
253 |
|
254 |
|
255 |
== Changelog ==
|
256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
= 2.2.2 - Apr 16 2018 =
|
258 |
* [NEW FEATURE] WebP Attribute To Replace setting in Media tab. (@vengen)
|
259 |
* [IMPROVEMENT] Generate adv_cache file automatically when it is lost.
|
3 |
Tags: cache, wp-cache, litespeed, super cache, http2, total cache, optimize, object cache, redis, memcached, lazy load, database cleaner
|
4 |
Requires at least: 4.0
|
5 |
Tested up to: 4.9.5
|
6 |
+
Stable tag: 2.2.3
|
7 |
License: GPLv3
|
8 |
License URI: http://www.gnu.org/licenses/gpl.html
|
9 |
|
27 |
* Object Cache (Memcached/LSMCD/Redis)
|
28 |
* Image Optimization
|
29 |
* Minify CSS, JavaScript, and HTML
|
30 |
+
* Minify inline CSS/JS
|
31 |
+
* Combine CSS/JS
|
32 |
* Lazyload images/iframes
|
33 |
* Multiple CDN support
|
34 |
* Load CSS/JS Asynchronously
|
37 |
* Database Cleaner and Optimizer
|
38 |
* PageSpeed score optimization
|
39 |
* OPcode Cache
|
40 |
+
* HTTP/2 Push for CSS/JS (on web servers that support it)
|
41 |
* DNS Prefetch
|
42 |
* Cloudflare API
|
43 |
* Single Site and Multi Site (Network) support
|
45 |
* Basic/Advanced setting view
|
46 |
* Attractive, easy-to-understand interface
|
47 |
* WebP image format support
|
48 |
+
* Heartbeat control
|
49 |
|
50 |
= LiteSpeed Exclusive Features =
|
51 |
|
250 |
* [Elegant Themes Divi 3.0.67+](https://www.elegantthemes.com/gallery/divi/)
|
251 |
* [Caldera Forms](https://wordpress.org/plugins/caldera-forms/) 1.5.6.2+
|
252 |
* Login With Ajax
|
253 |
+
* [Ninja Forms](https://wordpress.org/plugins/ninja-forms/)
|
254 |
* [Post Types Order 1.9.3.6+](https://wordpress.org/plugins/post-types-order/)
|
255 |
* [BoomBox — Viral Magazine WordPress Theme](https://themeforest.net/item/boombox-viral-buzz-wordpress-theme/16596434?ref=PX-lab)
|
256 |
|
257 |
|
258 |
== Changelog ==
|
259 |
|
260 |
+
= 2.2.3 - Apr 27 2018 =
|
261 |
+
* [NEW FEATURE] WebP For Extra srcset setting in Media tab. (@vengen)
|
262 |
+
* [REFACTOR] Removed redundant LS consts.
|
263 |
+
* [REFACTOR] Refactored adv_cache generation flow.
|
264 |
+
* [BUGFIX] Fixed issue where inline JS minify exception caused a blank page. (@oomskaap @kenb1978)
|
265 |
+
* [UPDATE] Changed HTTP/2 Crawl default value to OFF.
|
266 |
+
* [UPDATE] Added img.data-src to default WebP replacement value for WooCommerce WebP support.
|
267 |
+
* [UPDATE] Detached crawler from LSCache LITESPEED_ON status.
|
268 |
+
* [API] Improved ESI API to honor the cache control in ESI wrapper.
|
269 |
+
* [API] Added LITESPEED_PURGE_SILENT const to bypass the notification when purging
|
270 |
+
* [INTEGRATION] Fixed issue with nonce expiration when using ESI API. (@Dan #923505)
|
271 |
+
* [INTEGRATION] Improved compatibility with Ninja Forms by bypassing non-javascript JS from inline JS minify.
|
272 |
+
* [INTEGRATION] Added a hook for plugins that change the CSS/JS path e.g. Hide My WordPress.
|
273 |
+
|
274 |
= 2.2.2 - Apr 16 2018 =
|
275 |
* [NEW FEATURE] WebP Attribute To Replace setting in Media tab. (@vengen)
|
276 |
* [IMPROVEMENT] Generate adv_cache file automatically when it is lost.
|