LiteSpeed Cache - Version 1.3.1.1

Version Description

  • October 6 2017 =
  • [BUGFIX] Improved optimizer table creating process in certain database charset to avoid css/js minify/combination failure.
Download this release

Release Info

Developer LiteSpeedTech
Plugin Icon 128x128 LiteSpeed Cache
Version 1.3.1.1
Comparing to
See all releases

Code changes from version 1.2.3.1 to 1.3.1.1

Files changed (85) hide show
  1. admin/img/icons/purge-front.svg +0 -32
  2. admin/litespeed-cache-admin-display.class.php +8 -59
  3. admin/litespeed-cache-admin-optimize.class.php +1 -1
  4. admin/litespeed-cache-admin-rules.class.php +162 -185
  5. admin/litespeed-cache-admin-settings.class.php +538 -579
  6. admin/litespeed-cache-admin.class.php +2 -2
  7. admin/tpl/crawler.php +5 -5
  8. admin/tpl/edit_htaccess.php +1 -1
  9. admin/tpl/info_faqs.php +1 -1
  10. admin/tpl/manage.php +1 -1
  11. admin/tpl/manage_purge.php +1 -1
  12. admin/tpl/network_settings.php +1 -1
  13. admin/tpl/network_settings_cache.php +1 -0
  14. admin/tpl/network_settings_excludes.php +8 -4
  15. admin/tpl/settings.php +2 -3
  16. admin/tpl/settings_advanced.php +1 -1
  17. admin/tpl/settings_cache.php +22 -0
  18. admin/tpl/settings_debug.php +1 -12
  19. admin/tpl/settings_excludes.php +107 -102
  20. admin/tpl/settings_inc.cache_browser.php +19 -0
  21. admin/tpl/settings_inc.cache_favicon.php +4 -0
  22. admin/tpl/settings_inc.cache_mobile.php +22 -30
  23. admin/tpl/settings_inc.cache_resources.php +4 -0
  24. admin/tpl/settings_inc.exclude_cookies.php +23 -19
  25. admin/tpl/settings_inc.exclude_useragent.php +20 -20
  26. admin/tpl/settings_inc.purge_on_upgrade.php +1 -1
  27. admin/tpl/settings_optimize.php +64 -0
  28. cli/litespeed-cache-cli-admin.class.php +12 -2
  29. cli/litespeed-cache-cli-purge.class.php +1 -2
  30. {admin/css → css}/fonts/litespeedfont.eot +0 -0
  31. {admin/css → css}/fonts/litespeedfont.svg +0 -0
  32. {admin/css → css}/fonts/litespeedfont.ttf +0 -0
  33. {admin/css → css}/fonts/litespeedfont.woff +0 -0
  34. {admin/css → css}/litespeed.css +13 -2
  35. {admin/img → img}/Litespeed.icon.svg +0 -0
  36. {admin/img → img}/icons/all.svg +0 -0
  37. {admin/img → img}/icons/all_transients.svg +0 -0
  38. {admin/img → img}/icons/auto_draft.svg +0 -0
  39. {admin/img → img}/icons/cross_icon.svg +0 -0
  40. {admin/img → img}/icons/db.svg +0 -0
  41. {admin/img → img}/icons/empty-cache.svg +0 -0
  42. {admin/img → img}/icons/expired_transient.svg +0 -0
  43. {admin/img → img}/icons/optimize_tables.svg +0 -0
  44. {admin/img → img}/icons/purge-403.svg +0 -0
  45. {admin/img → img}/icons/purge-404.svg +0 -0
  46. {admin/img → img}/icons/purge-500.svg +0 -0
  47. {admin/img → img}/icons/purge-all.svg +0 -0
  48. {admin/img → img}/icons/purge-cssjs.svg +0 -0
  49. img/icons/purge-front.svg +31 -0
  50. {admin/img → img}/icons/purge-pages.svg +0 -0
  51. {admin/img → img}/icons/revision.svg +0 -0
  52. {admin/img → img}/icons/spam_comment.svg +0 -0
  53. {admin/img → img}/icons/success_icon.svg +0 -0
  54. {admin/img → img}/icons/trackback-pingback.svg +0 -0
  55. {admin/img → img}/icons/trash_comment.svg +0 -0
  56. {admin/img → img}/icons/trash_post.svg +0 -0
  57. inc/data.class.php +177 -0
  58. includes/litespeed-cache-activation.class.php +47 -57
  59. includes/litespeed-cache-api.class.php +43 -2
  60. includes/litespeed-cache-cdn.class.php +15 -3
  61. includes/litespeed-cache-config.class.php +156 -125
  62. includes/litespeed-cache-control.class.php +64 -65
  63. includes/litespeed-cache-crawler-sitemap.class.php +6 -7
  64. includes/litespeed-cache-crawler.class.php +7 -7
  65. includes/litespeed-cache-esi.class.php +24 -15
  66. includes/litespeed-cache-gui.class.php +116 -0
  67. includes/litespeed-cache-log.class.php +7 -7
  68. includes/litespeed-cache-optimize.class.php +383 -58
  69. includes/litespeed-cache-purge.class.php +20 -1
  70. includes/litespeed-cache-router.class.php +9 -73
  71. includes/litespeed-cache-task.class.php +20 -20
  72. includes/litespeed-cache-utility.class.php +193 -9
  73. includes/litespeed-cache-vary.class.php +8 -4
  74. includes/litespeed-cache.class.php +84 -34
  75. includes/litespeed.autoload.php +3 -0
  76. js/css_async.js +4 -0
  77. {admin/js → js}/litespeed-cache-admin.js +5 -0
  78. languages/litespeed-cache.pot +235 -151
  79. lib/litespeed-php-compatibility.func.php +11 -11
  80. lib/litespeed/litespeed-string.class.php +70 -0
  81. litespeed-cache.php +19 -10
  82. readme.txt +68 -11
  83. thirdparty/lscwp-3rd-nextgengallery.cls.php +1 -1
  84. thirdparty/lscwp-3rd-woocommerce.cls.php +2 -2
  85. thirdparty/lscwp-3rd-yith-wishlist.cls.php +1 -1
admin/img/icons/purge-front.svg DELETED
@@ -1,32 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <!-- Generator: Adobe Illustrator 16.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
- <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5
- width="75px" height="75px" viewBox="0 0 75 75" enable-background="new 0 0 75 75" xml:space="preserve">
6
- <g>
7
- <path fill="#6699CC" d="M63.657,12.237c-0.046-0.116-0.109-0.227-0.205-0.318L52.954,1.835c-0.028-0.027-0.065-0.039-0.097-0.062
8
- c-0.06-0.043-0.115-0.089-0.186-0.117c-0.068-0.027-0.143-0.034-0.215-0.043c-0.037-0.005-0.07-0.022-0.109-0.022H52.33h-0.001
9
- H14.114c-1.577,0-2.86,1.283-2.86,2.859v66.923c0,1.577,1.283,2.859,2.86,2.859h46.773c1.575,0,2.858-1.282,2.858-2.859V12.608
10
- C63.746,12.474,63.711,12.351,63.657,12.237z M53.223,4.52l7.51,7.213h-7.395c-0.064,0-0.115-0.052-0.115-0.118V4.52z
11
- M61.996,71.373c0,0.611-0.498,1.109-1.109,1.109H14.114c-0.612,0-1.11-0.498-1.11-1.109V4.45c0-0.612,0.498-1.109,1.11-1.109
12
- h37.359v8.274c0,1.03,0.836,1.868,1.864,1.868h8.658L61.996,71.373L61.996,71.373z"/>
13
- <path fill="#6699CC" d="M45.43,44.486c-6.656,0-12.072,5.416-12.072,12.072S38.773,68.63,45.43,68.63
14
- c6.655,0,12.071-5.415,12.071-12.071S52.085,44.486,45.43,44.486z M45.43,66.881c-5.691,0-10.322-4.63-10.322-10.32
15
- c0-5.691,4.63-10.322,10.322-10.322c5.69,0,10.321,4.631,10.321,10.322C55.751,62.251,51.12,66.881,45.43,66.881z"/>
16
- <path fill="#6699CC" d="M51.299,50.689c-0.342-0.342-0.896-0.342-1.238,0L45.43,55.32l-4.631-4.631
17
- c-0.342-0.342-0.896-0.342-1.238,0c-0.34,0.342-0.34,0.896,0,1.237l4.631,4.632l-4.631,4.631c-0.34,0.342-0.34,0.896,0,1.237
18
- c0.172,0.171,0.396,0.257,0.619,0.257s0.448-0.086,0.619-0.257l4.631-4.631l4.631,4.631c0.172,0.171,0.396,0.257,0.619,0.257
19
- s0.448-0.086,0.619-0.257c0.342-0.342,0.342-0.896,0-1.237l-4.631-4.631l4.631-4.632C51.641,51.586,51.641,51.031,51.299,50.689z"
20
- />
21
- <path fill="#6699CC" d="M19.826,18.879c0,0.483,0.392,0.875,0.875,0.875h33.598c0.483,0,0.875-0.392,0.875-0.875
22
- s-0.392-0.875-0.875-0.875H20.701C20.218,18.004,19.826,18.396,19.826,18.879z"/>
23
- <path fill="#6699CC" d="M20.701,29.511h33.598c0.483,0,0.875-0.392,0.875-0.875c0-0.483-0.392-0.875-0.875-0.875H20.701
24
- c-0.483,0-0.875,0.392-0.875,0.875C19.826,29.119,20.218,29.511,20.701,29.511z"/>
25
- <path fill="#6699CC" d="M20.701,39.27h33.598c0.483,0,0.875-0.393,0.875-0.875c0-0.483-0.392-0.875-0.875-0.875H20.701
26
- c-0.483,0-0.875,0.392-0.875,0.875C19.826,38.877,20.218,39.27,20.701,39.27z"/>
27
- <path fill="#6699CC" d="M30.125,47.275h-9.423c-0.483,0-0.875,0.393-0.875,0.875c0,0.483,0.392,0.875,0.875,0.875h9.423
28
- c0.483,0,0.875-0.392,0.875-0.875C31,47.668,30.608,47.275,30.125,47.275z"/>
29
- <path fill="#6699CC" d="M27.75,57.034h-7.049c-0.483,0-0.875,0.392-0.875,0.875s0.392,0.875,0.875,0.875h7.049
30
- c0.483,0,0.875-0.392,0.875-0.875S28.233,57.034,27.75,57.034z"/>
31
- </g>
32
- </svg>
admin/litespeed-cache-admin-display.class.php CHANGED
@@ -65,7 +65,7 @@ class LiteSpeed_Cache_Admin_Display
65
$manage = 'manage_options' ;
66
}
67
if ( current_user_can($manage) ) {
68
- if ( LiteSpeed_Cache_Router::cache_enabled() ) {
69
add_action('wp_before_admin_bar_render', array($this, 'add_quick_purge')) ;
70
}
71
add_action('admin_enqueue_scripts', array($this, 'check_messages')) ;// We can do this cos admin_notices hook is after admin_enqueue_scripts hook in wp-admin/admin-header.php
@@ -97,7 +97,7 @@ class LiteSpeed_Cache_Admin_Display
97
// Admin footer
98
add_filter('admin_footer_text', array($this, 'admin_footer_text'), 1) ;
99
100
- if( LiteSpeed_Cache_Router::cache_enabled() ) {
101
// Help tab
102
$this->add_help_tabs() ;
103
@@ -185,7 +185,7 @@ class LiteSpeed_Cache_Admin_Display
185
*/
186
public function enqueue_style()
187
{
188
- wp_enqueue_style(LiteSpeed_Cache::PLUGIN_NAME, plugin_dir_url(__FILE__) . 'css/litespeed.css', array(), LiteSpeed_Cache::PLUGIN_VERSION, 'all') ;
189
}
190
191
/**
@@ -196,15 +196,15 @@ class LiteSpeed_Cache_Admin_Display
196
*/
197
public function enqueue_scripts()
198
{
199
- wp_register_script(LiteSpeed_Cache::PLUGIN_NAME, plugin_dir_url(__FILE__) . 'js/litespeed-cache-admin.js', array(), LiteSpeed_Cache::PLUGIN_VERSION, false) ;
200
201
if ( LiteSpeed_Cache_Router::has_whm_msg() ) {
202
- $ajax_url_dismiss_whm = self::build_url(LiteSpeed_Cache::ACTION_DISMISS_WHM, LiteSpeed_Cache::ACTION_DISMISS_WHM) ;
203
wp_localize_script(LiteSpeed_Cache::PLUGIN_NAME, 'litespeed_data', array('ajax_url_dismiss_whm' => $ajax_url_dismiss_whm)) ;
204
}
205
206
if ( LiteSpeed_Cache_Router::has_msg_ruleconflict() ) {
207
- $ajax_url = self::build_url(LiteSpeed_Cache::ACTION_DISMISS_EXPIRESDEFAULT, LiteSpeed_Cache::ACTION_DISMISS_EXPIRESDEFAULT) ;
208
wp_localize_script(LiteSpeed_Cache::PLUGIN_NAME, 'litespeed_data', array('ajax_url_dismiss_ruleconflict' => $ajax_url)) ;
209
}
210
@@ -278,7 +278,7 @@ class LiteSpeed_Cache_Admin_Display
278
public function add_quick_purge()
279
{
280
global $wp_admin_bar ;
281
- $url = self::build_url(LiteSpeed_Cache::ACTION_PURGE_ALL) ;
282
283
$wp_admin_bar->add_node(array(
284
'id' => 'lscache-quick-purge',
@@ -288,57 +288,6 @@ class LiteSpeed_Cache_Admin_Display
288
)) ;
289
}
290
291
- /**
292
- * Builds an admin url with an action and a nonce.
293
- *
294
- * Assumes user capabilities are already checked.
295
- *
296
- * @access public
297
- * @param string $action The LSCWP_CTRL action to do in the url.
298
- * @param string $ajax_action AJAX call's action
299
- * @param string $append_str The appending string to url
300
- * @return string The built url.
301
- */
302
- public static function build_url($action, $ajax_action = false, $append_str = false)
303
- {
304
- global $pagenow ;
305
- $prefix = '?' ;
306
-
307
- if ( $ajax_action === false ) {
308
- $params = $_GET ;
309
-
310
- if ( ! empty($params) ) {
311
- if ( isset($params['LSCWP_CTRL']) ) {
312
- unset($params['LSCWP_CTRL']) ;
313
- }
314
- if ( isset($params['_wpnonce']) ) {
315
- unset($params['_wpnonce']) ;
316
- }
317
- if ( ! empty($params) ) {
318
- $prefix .= http_build_query($params) . '&' ;
319
- }
320
- }
321
- $combined = $pagenow . $prefix . LiteSpeed_Cache::ACTION_KEY . '=' . $action ;
322
- }
323
- else {
324
- $combined = 'admin-ajax.php?action=' . $ajax_action . '&' . LiteSpeed_Cache::ACTION_KEY . '=' . $action ;
325
- }
326
-
327
- if ( is_network_admin() ) {
328
- $prenonce = network_admin_url($combined) ;
329
- }
330
- else {
331
- $prenonce = admin_url($combined) ;
332
- }
333
- $url = wp_nonce_url($prenonce, $action, LiteSpeed_Cache::NONCE_NAME) ;
334
-
335
- if ( $append_str ) {
336
- $url .= '&' . $append_str ;
337
- }
338
-
339
- return $url ;
340
- }
341
-
342
/**
343
* Change the admin footer text on LiteSpeed Cache admin pages.
344
*
@@ -408,7 +357,7 @@ class LiteSpeed_Cache_Admin_Display
408
*/
409
public function check_license()
410
{
411
- if ( ! LiteSpeed_Cache_Config::get_instance()->is_caching_allowed() ) {
412
self::add_error(LiteSpeed_Cache_Admin_Error::E_SERVER) ;
413
self::display_messages() ;
414
}
65
$manage = 'manage_options' ;
66
}
67
if ( current_user_can($manage) ) {
68
+ if ( defined( 'LITESPEED_ON' ) ) {
69
add_action('wp_before_admin_bar_render', array($this, 'add_quick_purge')) ;
70
}
71
add_action('admin_enqueue_scripts', array($this, 'check_messages')) ;// We can do this cos admin_notices hook is after admin_enqueue_scripts hook in wp-admin/admin-header.php
97
// Admin footer
98
add_filter('admin_footer_text', array($this, 'admin_footer_text'), 1) ;
99
100
+ if( defined( 'LITESPEED_ON' ) ) {
101
// Help tab
102
$this->add_help_tabs() ;
103
185
*/
186
public function enqueue_style()
187
{
188
+ wp_enqueue_style(LiteSpeed_Cache::PLUGIN_NAME, LSWCP_PLUGIN_URL . 'css/litespeed.css', array(), LiteSpeed_Cache::PLUGIN_VERSION, 'all') ;
189
}
190
191
/**
196
*/
197
public function enqueue_scripts()
198
{
199
+ wp_register_script(LiteSpeed_Cache::PLUGIN_NAME, LSWCP_PLUGIN_URL . 'js/litespeed-cache-admin.js', array(), LiteSpeed_Cache::PLUGIN_VERSION, false) ;
200
201
if ( LiteSpeed_Cache_Router::has_whm_msg() ) {
202
+ $ajax_url_dismiss_whm = LiteSpeed_Cache_Utility::build_url(LiteSpeed_Cache::ACTION_DISMISS_WHM, LiteSpeed_Cache::ACTION_DISMISS_WHM) ;
203
wp_localize_script(LiteSpeed_Cache::PLUGIN_NAME, 'litespeed_data', array('ajax_url_dismiss_whm' => $ajax_url_dismiss_whm)) ;
204
}
205
206
if ( LiteSpeed_Cache_Router::has_msg_ruleconflict() ) {
207
+ $ajax_url = LiteSpeed_Cache_Utility::build_url(LiteSpeed_Cache::ACTION_DISMISS_EXPIRESDEFAULT, LiteSpeed_Cache::ACTION_DISMISS_EXPIRESDEFAULT) ;
208
wp_localize_script(LiteSpeed_Cache::PLUGIN_NAME, 'litespeed_data', array('ajax_url_dismiss_ruleconflict' => $ajax_url)) ;
209
}
210
278
public function add_quick_purge()
279
{
280
global $wp_admin_bar ;
281
+ $url = LiteSpeed_Cache_Utility::build_url(LiteSpeed_Cache::ACTION_PURGE_ALL) ;
282
283
$wp_admin_bar->add_node(array(
284
'id' => 'lscache-quick-purge',
288
)) ;
289
}
290
291
/**
292
* Change the admin footer text on LiteSpeed Cache admin pages.
293
*
357
*/
358
public function check_license()
359
{
360
+ if ( ! defined( 'LITESPEED_ALLOWED' ) ) {
361
self::add_error(LiteSpeed_Cache_Admin_Error::E_SERVER) ;
362
self::display_messages() ;
363
}
admin/litespeed-cache-admin-optimize.class.php CHANGED
@@ -25,7 +25,7 @@ class LiteSpeed_Cache_Admin_Optimize
25
*/
26
public static function generate_url( $type )
27
{
28
- $url = LiteSpeed_Cache_Admin_Display::build_url( LiteSpeed_Cache::ACTION_DB_OPTIMIZE, false, self::TYPE . '=' . $type ) ;
29
return $url ;
30
}
31
25
*/
26
public static function generate_url( $type )
27
{
28
+ $url = LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_DB_OPTIMIZE, false, self::TYPE . '=' . $type ) ;
29
return $url ;
30
}
31
admin/litespeed-cache-admin-rules.class.php CHANGED
@@ -24,8 +24,6 @@ class LiteSpeed_Cache_Admin_Rules
24
private $theme_htaccess_readable = false ;
25
private $theme_htaccess_writable = false ;
26
27
- private static $RW_LOOKUP ;
28
- const RW_LOOKUP_PUBLIC = "CacheLookup Public on" ;
29
const RW_LOOKUP_BOTH = "CacheLookup on" ;
30
const RW_PRIV_BYPASS_POST_PURGE = "RewriteRule .* - [E=Cache-Control:no-autoflush]" ;
31
const RW_OPTM_NO_VARY = "RewriteRule min/\w+\.(css|js) - [E=cache-control:no-vary]" ;
@@ -42,6 +40,7 @@ class LiteSpeed_Cache_Admin_Rules
42
const MARKER_NOCACHE_USER_AGENTS = '### marker NOCACHE USER AGENTS' ;
43
const MARKER_CACHE_RESOURCE = '### marker CACHE RESOURCE' ;
44
const MARKER_FAVICON = '### marker FAVICON' ;
45
const MARKER_MINIFY = '### marker MINIFY' ;
46
const MARKER_START = ' start ###' ;
47
const MARKER_END = ' end ###' ;
@@ -67,13 +66,13 @@ class LiteSpeed_Cache_Admin_Rules
67
if ( is_writable($test_permissions) ) {
68
$this->frontend_htaccess_writable = true ;
69
}
70
- if ( LITESPEED_SERVER_TYPE == 'LITESPEED_SERVER_OLS' ) {
71
- self::$RW_LOOKUP = self::RW_LOOKUP_PUBLIC ;
72
- }
73
- else {
74
- self::$RW_LOOKUP = self::RW_LOOKUP_BOTH ;
75
- }
76
- self::$LS_MODULE_REWRITE_ON = "RewriteEngine on\n" . self::$RW_LOOKUP . "\n" . self::RW_PRIV_BYPASS_POST_PURGE . "\n" . self::RW_OPTM_NO_VARY ;
77
78
// backend .htaccess privilege
79
if ( $this->frontend_htaccess === $this->backend_htaccess ) {
@@ -399,7 +398,7 @@ class LiteSpeed_Cache_Admin_Rules
399
*/
400
public function get_rewrite_rule_mobile_agents()
401
{
402
- $rules = $this->get_rewrite_rule(self::MARKER_MOBILE) ;
403
if( ! isset($rules[0]) ) {
404
LiteSpeed_Cache_Admin_Display::add_error(LiteSpeed_Cache_Admin_Error::E_HTA_DNF, self::MARKER_MOBILE) ;
405
return false ;
@@ -426,7 +425,7 @@ class LiteSpeed_Cache_Admin_Rules
426
*/
427
public function get_rewrite_rule_login_cookie($kind = 'frontend')
428
{
429
- $rule = $this->get_rewrite_rule(self::MARKER_LOGIN_COOKIE, $kind) ;
430
if( substr($rule, 0, strlen('RewriteRule .? - [E=')) !== 'RewriteRule .? - [E=' ) {//todo: use regex
431
return false ;
432
}
@@ -440,7 +439,7 @@ class LiteSpeed_Cache_Admin_Rules
440
* @param string $kind Frontend or backend .htaccess file
441
* @return mixed Rules
442
*/
443
- private function get_rewrite_rule($cond, $kind = 'frontend')
444
{
445
clearstatcache() ;
446
$path = $this->htaccess_path($kind) ;
@@ -470,164 +469,68 @@ class LiteSpeed_Cache_Admin_Rules
470
}
471
472
/**
473
- * Parses the input to see if there is a need to edit the .htaccess file.
474
*
475
- * @since 1.0.8
476
- * @access public
477
- * @param array $options The current options
478
- * @param array $input The input
479
- * @param array $errors Errors array to add error messages to.
480
- * @return mixed False if there is an error, diff array otherwise.
481
*/
482
- public function check_input_for_rewrite($options, $input, &$errors)
483
{
484
- $diff = array() ;
485
- $opts = array(
486
- LiteSpeed_Cache_Config::OPID_CACHE_MOBILE,
487
- LiteSpeed_Cache_Config::OPID_CACHE_FAVICON,
488
- LiteSpeed_Cache_Config::OPID_CACHE_RES,
489
) ;
490
- $has_error = false ;
491
-
492
- foreach ($opts as $opt) {
493
- $input[$opt] = LiteSpeed_Cache_Admin_Settings::parse_onoff( $input, $opt ) ;
494
- if ( $input[$opt] || $options[$opt] != $input[$opt] ) {
495
- $diff[$opt] = $input[$opt] ;
496
- }
497
- }
498
-
499
- // check mobile agents
500
- $id = LiteSpeed_Cache_Config::ID_MOBILEVIEW_LIST ;
501
- if ( $input[LiteSpeed_Cache_Config::OPID_CACHE_MOBILE] ) {
502
- $list = $input[$id] ;
503
- if ( empty($list) || $this->check_rewrite($list) === false ) {
504
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_SETTING_REWRITE, array($id, empty($list) ? 'EMPTY' : esc_html($list))
505
- ) ;
506
- $has_error = true ;
507
- }
508
- $diff[$id] = $list ;
509
- }
510
- elseif ( isset($diff[LiteSpeed_Cache_Config::OPID_CACHE_MOBILE]) ) {
511
- $diff[$id] = false ;
512
- }
513
-
514
- $id = LiteSpeed_Cache_Config::ID_NOCACHE_COOKIES ;
515
- if ( isset($input[$id]) && $input[$id] ) {
516
- $cookie_list = preg_replace("/[\r\n]+/", '|', $input[$id]) ;
517
- }
518
- else {
519
- $cookie_list = '' ;
520
- }
521
-
522
- if ( empty($cookie_list) || $this->check_rewrite($cookie_list) ) {
523
- $diff[$id] = $cookie_list ;
524
- }
525
- else {
526
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_SETTING_REWRITE, array($id, esc_html($cookie_list))) ;
527
- $has_error = true ;
528
- }
529
-
530
- $id = LiteSpeed_Cache_Config::ID_NOCACHE_USERAGENTS ;
531
- if ( isset($input[$id]) && $this->check_rewrite($input[$id]) ) {
532
- $diff[$id] = $input[$id] ;
533
- }
534
- else {
535
- $err_args = array($id) ;
536
- if ( ! isset($input[$id]) || empty($input[$id]) ) {
537
- $err_args[] = 'EMPTY' ;
538
- }
539
- else {
540
- $err_args[] = esc_html($input[$id]) ;
541
- }
542
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_SETTING_REWRITE, $err_args) ;
543
- $has_error = true ;
544
- }
545
-
546
- $id = LiteSpeed_Cache_Config::OPID_LOGIN_COOKIE ;
547
- $aExceptions = array('-', '_') ;
548
- if ( isset($input[$id]) ) {
549
- if ( $input[$id] === '' || (ctype_alnum(str_replace($aExceptions, '', $input[$id])) && $this->check_rewrite($input[$id])) ) {
550
- $diff[$id] = $input[$id] ;
551
- }
552
- else {
553
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_SETTING_LC, esc_html($input[$id])) ;
554
- $has_error = true ;
555
- }
556
- }
557
-
558
- if ( $has_error ) {
559
- return false ;
560
- }
561
- return $diff ;
562
}
563
564
/**
565
- * Parse rewrite input to check for possible issues (e.g. unescaped spaces).
566
*
567
- * Issues tracked:
568
- * Starts with |
569
- * Ends with |
570
- * Double |
571
- * Unescaped space
572
- * Invalid character (NOT \w, -, \, |, \s, /, ., +, *, (, ))
573
- *
574
- * @since 1.0.9
575
* @access private
576
- * @param String $rule Input rewrite rule.
577
- * @return boolean True for valid rules, false otherwise.
578
*/
579
- private function check_rewrite($rule)
580
{
581
- $escaped = str_replace('@', '\@', $rule) ;
582
- return @preg_match('@' . $escaped . '@', null) !== false ;//todo: improve to try catch
583
- }
584
-
585
- /**
586
- * Validate common rewrite rules configured by the admin.
587
- *
588
- * @since 1.0.4
589
- * @access public
590
- * @param array $diff The rules that need to be set.
591
- * @param array $errors Returns error messages added if failed.
592
- * @return mixed Returns updated options array on success, false otherwise.
593
- */
594
- public function validate_common_rewrites($diff, &$errors)
595
- {
596
- if ( ! self::readable() ) {
597
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_HTA_R) ;
598
- return false ;
599
- }
600
-
601
- if ( $this->frontend_htaccess !== $this->backend_htaccess ) {
602
- if ( ! self::readable('backend') ) {
603
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_HTA_R) ;
604
- return false ;
605
- }
606
- }
607
-
608
- // check login cookie
609
- if ( LITESPEED_SERVER_TYPE === 'LITESPEED_SERVER_OLS' ) {
610
- $id = LiteSpeed_Cache_Config::OPID_LOGIN_COOKIE ;
611
- if ( $diff[$id] ) {
612
- $diff[$id] .= ',wp-postpass_' . COOKIEHASH ;
613
- }
614
- else {
615
- $diff[$id] = 'wp-postpass_' . COOKIEHASH ;
616
- }
617
-
618
- $tp_cookies = apply_filters('litespeed_cache_api_vary', array()) ;
619
- if ( ! empty($tp_cookies) && is_array($tp_cookies) ) {
620
- $diff[$id] .= ',' . implode(',', $tp_cookies) ;
621
- }
622
- }
623
-
624
$new_rules = array() ;
625
$new_rules_backend = array() ;
626
// mobile agents
627
$id = LiteSpeed_Cache_Config::ID_MOBILEVIEW_LIST ;
628
- if ( isset($diff[$id]) && $diff[$id] ) {
629
$new_rules[] = self::MARKER_MOBILE . self::MARKER_START ;
630
- $new_rules[] = 'RewriteCond %{HTTP_USER_AGENT} ' . $diff[$id] . ' [NC]' ;
631
$new_rules[] = 'RewriteRule .* - [E=Cache-Control:vary=ismobile]' ;
632
$new_rules[] = self::MARKER_MOBILE . self::MARKER_END ;
633
$new_rules[] = '' ;
@@ -635,9 +538,9 @@ class LiteSpeed_Cache_Admin_Rules
635
636
// nocache cookie
637
$id = LiteSpeed_Cache_Config::ID_NOCACHE_COOKIES ;
638
- if ( isset($diff[$id]) && $diff[$id] ) {
639
$new_rules[] = self::MARKER_NOCACHE_COOKIES . self::MARKER_START ;
640
- $new_rules[] = 'RewriteCond %{HTTP_COOKIE} ' . $diff[$id] ;
641
$new_rules[] = 'RewriteRule .* - [E=Cache-Control:no-cache]' ;
642
$new_rules[] = self::MARKER_NOCACHE_COOKIES . self::MARKER_END ;
643
$new_rules[] = '' ;
@@ -645,9 +548,9 @@ class LiteSpeed_Cache_Admin_Rules
645
646
// nocache user agents
647
$id = LiteSpeed_Cache_Config::ID_NOCACHE_USERAGENTS ;
648
- if ( isset($diff[$id]) && $diff[$id] ) {
649
$new_rules[] = self::MARKER_NOCACHE_USER_AGENTS . self::MARKER_START ;
650
- $new_rules[] = 'RewriteCond %{HTTP_USER_AGENT} ' . $diff[$id] ;
651
$new_rules[] = 'RewriteRule .* - [E=Cache-Control:no-cache]' ;
652
$new_rules[] = self::MARKER_NOCACHE_USER_AGENTS . self::MARKER_END ;
653
$new_rules[] = '' ;
@@ -655,18 +558,31 @@ class LiteSpeed_Cache_Admin_Rules
655
656
// caching php resource
657
$id = LiteSpeed_Cache_Config::OPID_CACHE_RES ;
658
- if ( isset($diff[$id]) && $diff[$id] ) {
659
$new_rules[] = $new_rules_backend[] = self::MARKER_CACHE_RESOURCE . self::MARKER_START ;
660
$new_rules[] = $new_rules_backend[] = 'RewriteRule ' . LSWCP_CONTENT_FOLDER . self::RW_PATTERN_RES . ' - [E=cache-control:max-age=3600]' ;
661
$new_rules[] = $new_rules_backend[] = self::MARKER_CACHE_RESOURCE . self::MARKER_END ;
662
$new_rules[] = $new_rules_backend[] = '' ;
663
}
664
665
- // login cookie
666
- // frontend and backend
667
$id = LiteSpeed_Cache_Config::OPID_LOGIN_COOKIE ;
668
- if ( isset($diff[$id]) && $diff[$id] ) {
669
- $env = 'Cache-Vary:' . $diff[$id] ;
670
if ( LITESPEED_SERVER_TYPE === 'LITESPEED_SERVER_OLS' ) {
671
$env = '"' . $env . '"' ;
672
}
@@ -679,27 +595,25 @@ class LiteSpeed_Cache_Admin_Rules
679
// favicon
680
// frontend and backend
681
$id = LiteSpeed_Cache_Config::OPID_CACHE_FAVICON ;
682
- if ( isset($diff[$id]) && $diff[$id] ) {
683
$new_rules[] = $new_rules_backend[] = self::MARKER_FAVICON . self::MARKER_START ;
684
$new_rules[] = $new_rules_backend[] = 'RewriteRule favicon\.ico$ - [E=cache-control:max-age=86400]' ;
685
$new_rules[] = $new_rules_backend[] = self::MARKER_FAVICON . self::MARKER_END ;
686
$new_rules[] = '' ;
687
}
688
689
- $this->deprecated_clear_rules() ;
690
- if ( ! $this->insert_wrapper($new_rules) ) {
691
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_HTA_W) ;
692
- $errors[] = $this->rewrite_codes_msg( $this->frontend_htaccess, $new_rules ) ;
693
- return false ;
694
- }
695
- if ( $this->frontend_htaccess !== $this->backend_htaccess ) {
696
- if ( ! $this->insert_wrapper($new_rules_backend, 'backend') ) {
697
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_HTA_W) ;
698
- $errors[] = $this->rewrite_codes_msg( $this->backend_htaccess, $new_rules ) ;
699
- return false ;
700
- }
701
}
702
- return $diff ;
703
}
704
705
/**
@@ -714,7 +628,7 @@ class LiteSpeed_Cache_Admin_Rules
714
{
715
return sprintf( __( '<p>Please add/replace the following codes into the beginning of %1$s:</p> %2$s' , 'litespeed-cache' ),
716
$file,
717
- '<textarea style="width:100%;" rows="10" readonly>' . htmlspecialchars( $this->wrap_rules_with_marker( $rules ) ) . '</textarea>'
718
) ;
719
}
720
@@ -725,14 +639,14 @@ class LiteSpeed_Cache_Admin_Rules
725
* @param array $rules
726
* @return array final rules data for htaccess
727
*/
728
- private function wrap_rules_with_marker( $rules )
729
{
730
$marker = self::MARKER ;
731
$start_marker = "# BEGIN {$marker}" ;
732
$end_marker = "# END {$marker}" ;
733
$new_file_data = implode( "\n", array_merge(
734
array( $start_marker ),
735
- $this->wrap_rules($rules),
736
array( $end_marker )
737
) ) ;
738
@@ -746,13 +660,13 @@ class LiteSpeed_Cache_Admin_Rules
746
* @param array $rules
747
* @return array wrapped rules with module info
748
*/
749
- private function wrap_rules( $rules )
750
{
751
if ( $rules !== false ) {
752
$rules = array_merge(
753
array(self::LS_MODULE_DONOTEDIT),
754
array(self::LS_MODULE_START),
755
- array(self::$LS_MODULE_REWRITE_ON),
756
array(''),
757
$rules,
758
array(self::LS_MODULE_END),
@@ -776,7 +690,71 @@ class LiteSpeed_Cache_Admin_Rules
776
return false ;
777
}
778
779
- return Litespeed_File::insert_with_markers( $this->htaccess_path($kind), $this->wrap_rules( $rules ), self::MARKER, true ) ;
780
}
781
782
/**
@@ -788,7 +766,6 @@ class LiteSpeed_Cache_Admin_Rules
788
public function clear_rules( $clear_all = false )
789
{
790
$keep_wrapper = $clear_all === true ? false : array() ;
791
- $this->deprecated_clear_rules() ;
792
$this->insert_wrapper( $keep_wrapper ) ;
793
if ( $this->frontend_htaccess !== $this->backend_htaccess ) {
794
$this->insert_wrapper( $keep_wrapper, 'backend' ) ;
@@ -867,7 +844,7 @@ class LiteSpeed_Cache_Admin_Rules
867
*/
868
public static function get_instance()
869
{
870
- if ( ! isset(self::$_instance) ) {
871
self::$_instance = new self() ;
872
}
873
24
private $theme_htaccess_readable = false ;
25
private $theme_htaccess_writable = false ;
26
27
const RW_LOOKUP_BOTH = "CacheLookup on" ;
28
const RW_PRIV_BYPASS_POST_PURGE = "RewriteRule .* - [E=Cache-Control:no-autoflush]" ;
29
const RW_OPTM_NO_VARY = "RewriteRule min/\w+\.(css|js) - [E=cache-control:no-vary]" ;
40
const MARKER_NOCACHE_USER_AGENTS = '### marker NOCACHE USER AGENTS' ;
41
const MARKER_CACHE_RESOURCE = '### marker CACHE RESOURCE' ;
42
const MARKER_FAVICON = '### marker FAVICON' ;
43
+ const MARKER_BROWSER_CACHE = '### marker BROWSER CACHE' ;
44
const MARKER_MINIFY = '### marker MINIFY' ;
45
const MARKER_START = ' start ###' ;
46
const MARKER_END = ' end ###' ;
66
if ( is_writable($test_permissions) ) {
67
$this->frontend_htaccess_writable = true ;
68
}
69
+
70
+ self::$LS_MODULE_REWRITE_ON = array(
71
+ 'RewriteEngine on',
72
+ self::RW_LOOKUP_BOTH,
73
+ self::RW_PRIV_BYPASS_POST_PURGE,
74
+ self::RW_OPTM_NO_VARY,
75
+ ) ;
76
77
// backend .htaccess privilege
78
if ( $this->frontend_htaccess === $this->backend_htaccess ) {
398
*/
399
public function get_rewrite_rule_mobile_agents()
400
{
401
+ $rules = $this->_get_rule_by(self::MARKER_MOBILE) ;
402
if( ! isset($rules[0]) ) {
403
LiteSpeed_Cache_Admin_Display::add_error(LiteSpeed_Cache_Admin_Error::E_HTA_DNF, self::MARKER_MOBILE) ;
404
return false ;
425
*/
426
public function get_rewrite_rule_login_cookie($kind = 'frontend')
427
{
428
+ $rule = $this->_get_rule_by(self::MARKER_LOGIN_COOKIE, $kind) ;
429
if( substr($rule, 0, strlen('RewriteRule .? - [E=')) !== 'RewriteRule .? - [E=' ) {//todo: use regex
430
return false ;
431
}
439
* @param string $kind Frontend or backend .htaccess file
440
* @return mixed Rules
441
*/
442
+ private function _get_rule_by($cond, $kind = 'frontend')
443
{
444
clearstatcache() ;
445
$path = $this->htaccess_path($kind) ;
469
}
470
471
/**
472
+ * Generate browser cache rules
473
*
474
+ * @since 1.3
475
+ * @access private
476
+ * @return array Rules set
477
*/
478
+ private function _browser_cache_rules()
479
{
480
+ $rules = array(
481
+ '<FilesMatch "\.(pdf|ico|svg|xml|jpg|jpeg|png|gif|webp|ogg|mp4|webm|js|css|woff|woff2|ttf|eot)(\.gz)?quot;>',
482
+ '<IfModule mod_expires.c>',
483
+ 'ExpiresActive on',
484
+ 'ExpiresByType application/pdf A2592000',
485
+ 'ExpiresByType image/x-icon A2592000',
486
+ 'ExpiresByType image/vnd.microsoft.icon A2592000',
487
+ 'ExpiresByType image/svg+xml A2592000',
488
+ '',
489
+ 'ExpiresByType image/jpg A2592000',
490
+ 'ExpiresByType image/jpeg A2592000',
491
+ 'ExpiresByType image/png A2592000',
492
+ 'ExpiresByType image/gif A2592000',
493
+ 'ExpiresByType image/webp A2592000',
494
+ '',
495
+ 'ExpiresByType video/ogg A2592000',
496
+ 'ExpiresByType audio/ogg A2592000',
497
+ 'ExpiresByType video/mp4 A2592000',
498
+ 'ExpiresByType video/webm A2592000',
499
+ '',
500
+ 'ExpiresByType text/css A2592000',
501
+ 'ExpiresByType text/javascript A2592000',
502
+ 'ExpiresByType application/javascript A2592000',
503
+ 'ExpiresByType application/x-javascript A2592000',
504
+ '',
505
+ 'ExpiresByType application/x-font-ttf A2592000',
506
+ 'ExpiresByType application/font-woff A2592000',
507
+ 'ExpiresByType application/font-woff2 A2592000',
508
+ 'ExpiresByType application/vnd.ms-fontobject A2592000',
509
+ '',
510
+ '</IfModule>',
511
+ '</FilesMatch>',
512
) ;
513
+ return $rules ;
514
}
515
516
/**
517
+ * Generate rewrite rules based on settings
518
*
519
+ * @since 1.3
520
* @access private
521
+ * @param array $cfg The settings to be used for rewrite rule
522
+ * @return array Rules array
523
*/
524
+ private function _generate_rules( $cfg )
525
{
526
$new_rules = array() ;
527
$new_rules_backend = array() ;
528
+
529
// mobile agents
530
$id = LiteSpeed_Cache_Config::ID_MOBILEVIEW_LIST ;
531
+ if ( ! empty( $cfg[ LiteSpeed_Cache_Config::OPID_CACHE_MOBILE ] ) && ! empty( $cfg[ $id ] ) ) {
532
$new_rules[] = self::MARKER_MOBILE . self::MARKER_START ;
533
+ $new_rules[] = 'RewriteCond %{HTTP_USER_AGENT} ' . $cfg[ $id ] . ' [NC]' ;
534
$new_rules[] = 'RewriteRule .* - [E=Cache-Control:vary=ismobile]' ;
535
$new_rules[] = self::MARKER_MOBILE . self::MARKER_END ;
536
$new_rules[] = '' ;
538
539
// nocache cookie
540
$id = LiteSpeed_Cache_Config::ID_NOCACHE_COOKIES ;
541
+ if ( ! empty( $cfg[ $id ] ) ) {
542
$new_rules[] = self::MARKER_NOCACHE_COOKIES . self::MARKER_START ;
543
+ $new_rules[] = 'RewriteCond %{HTTP_COOKIE} ' . $cfg[ $id ] ;
544
$new_rules[] = 'RewriteRule .* - [E=Cache-Control:no-cache]' ;
545
$new_rules[] = self::MARKER_NOCACHE_COOKIES . self::MARKER_END ;
546
$new_rules[] = '' ;
548
549
// nocache user agents
550
$id = LiteSpeed_Cache_Config::ID_NOCACHE_USERAGENTS ;
551
+ if ( ! empty( $cfg[ $id ] ) ) {
552
$new_rules[] = self::MARKER_NOCACHE_USER_AGENTS . self::MARKER_START ;
553
+ $new_rules[] = 'RewriteCond %{HTTP_USER_AGENT} ' . $cfg[ $id ] ;
554
$new_rules[] = 'RewriteRule .* - [E=Cache-Control:no-cache]' ;
555
$new_rules[] = self::MARKER_NOCACHE_USER_AGENTS . self::MARKER_END ;
556
$new_rules[] = '' ;
558
559
// caching php resource
560
$id = LiteSpeed_Cache_Config::OPID_CACHE_RES ;
561
+ if ( ! empty( $cfg[ $id ] ) ) {
562
$new_rules[] = $new_rules_backend[] = self::MARKER_CACHE_RESOURCE . self::MARKER_START ;
563
$new_rules[] = $new_rules_backend[] = 'RewriteRule ' . LSWCP_CONTENT_FOLDER . self::RW_PATTERN_RES . ' - [E=cache-control:max-age=3600]' ;
564
$new_rules[] = $new_rules_backend[] = self::MARKER_CACHE_RESOURCE . self::MARKER_END ;
565
$new_rules[] = $new_rules_backend[] = '' ;
566
}
567
568
+ // check login cookie
569
$id = LiteSpeed_Cache_Config::OPID_LOGIN_COOKIE ;
570
+ if ( LITESPEED_SERVER_TYPE === 'LITESPEED_SERVER_OLS' ) {
571
+ if ( ! empty( $cfg[ $id ] ) ) {
572
+ $cfg[ $id ] .= ',wp-postpass_' . COOKIEHASH ;
573
+ }
574
+ else {
575
+ $cfg[ $id ] = 'wp-postpass_' . COOKIEHASH ;
576
+ }
577
+
578
+ $tp_cookies = apply_filters( 'litespeed_cache_api_vary', array() ) ;
579
+ if ( ! empty( $tp_cookies ) && is_array( $tp_cookies ) ) {
580
+ $cfg[ $id ] .= ',' . implode( ',', $tp_cookies ) ;
581
+ }
582
+ }
583
+ // frontend and backend
584
+ if ( ! empty( $cfg[ $id ] ) ) {
585
+ $env = 'Cache-Vary:' . $cfg[ $id ] ;
586
if ( LITESPEED_SERVER_TYPE === 'LITESPEED_SERVER_OLS' ) {
587
$env = '"' . $env . '"' ;
588
}
595
// favicon
596
// frontend and backend
597
$id = LiteSpeed_Cache_Config::OPID_CACHE_FAVICON ;
598
+ if ( ! empty( $cfg[ $id ] ) ) {
599
$new_rules[] = $new_rules_backend[] = self::MARKER_FAVICON . self::MARKER_START ;
600
$new_rules[] = $new_rules_backend[] = 'RewriteRule favicon\.ico$ - [E=cache-control:max-age=86400]' ;
601
$new_rules[] = $new_rules_backend[] = self::MARKER_FAVICON . self::MARKER_END ;
602
$new_rules[] = '' ;
603
}
604
605
+ // Browser cache
606
+ $id = LiteSpeed_Cache_Config::OPID_CACHE_BROWSER ;
607
+ if ( ! empty( $cfg[ $id ] ) ) {
608
+ $new_rules[] = $new_rules_backend[] = self::MARKER_BROWSER_CACHE . self::MARKER_START ;
609
+ $new_rules = array_merge( $new_rules, $this->_browser_cache_rules() ) ;
610
+ $new_rules_backend = array_merge( $new_rules_backend, $this->_browser_cache_rules() ) ;
611
+ $new_rules[] = $new_rules_backend[] = self::MARKER_BROWSER_CACHE . self::MARKER_END ;
612
+ $new_rules[] = '' ;
613
}
614
+
615
+ return array( $new_rules, $new_rules_backend ) ;
616
+
617
}
618
619
/**
628
{
629
return sprintf( __( '<p>Please add/replace the following codes into the beginning of %1$s:</p> %2$s' , 'litespeed-cache' ),
630
$file,
631
+ '<textarea style="width:100%;" rows="10" readonly>' . htmlspecialchars( $this->_wrap_rules_with_marker( $rules ) ) . '</textarea>'
632
) ;
633
}
634
639
* @param array $rules
640
* @return array final rules data for htaccess
641
*/
642
+ private function _wrap_rules_with_marker( $rules )
643
{
644
$marker = self::MARKER ;
645
$start_marker = "# BEGIN {$marker}" ;
646
$end_marker = "# END {$marker}" ;
647
$new_file_data = implode( "\n", array_merge(
648
array( $start_marker ),
649
+ $this->_wrap_rules($rules),
650
array( $end_marker )
651
) ) ;
652
660
* @param array $rules
661
* @return array wrapped rules with module info
662
*/
663
+ private function _wrap_rules( $rules )
664
{
665
if ( $rules !== false ) {
666
$rules = array_merge(
667
array(self::LS_MODULE_DONOTEDIT),
668
array(self::LS_MODULE_START),
669
+ self::$LS_MODULE_REWRITE_ON,
670
array(''),
671
$rules,
672
array(self::LS_MODULE_END),
690
return false ;
691
}
692
693
+ return Litespeed_File::insert_with_markers( $this->htaccess_path($kind), $this->_wrap_rules( $rules ), self::MARKER, true ) ;
694
+ }
695
+
696
+ /**
697
+ * Update rewrite rules based on setting
698
+ *
699
+ * @since 1.3
700
+ * @access public
701
+ * @param array $cfg The rules that need to be set.
702
+ */
703
+ public function update( $cfg )
704
+ {
705
+ if ( ! LiteSpeed_Cache_Admin_Rules::readable() ) {
706
+ return LiteSpeed_Cache_Admin_Display::get_error( LiteSpeed_Cache_Admin_Error::E_HTA_R ) ;
707
+ }
708
+
709
+ if ( $this->frontend_htaccess !== $this->backend_htaccess ) {
710
+ if ( ! LiteSpeed_Cache_Admin_Rules::readable( 'backend' ) ) {
711
+ return LiteSpeed_Cache_Admin_Display::get_error( LiteSpeed_Cache_Admin_Error::E_HTA_R ) ;
712
+ }
713
+ }
714
+
715
+ list( $frontend_rules, $backend_rules ) = $this->_generate_rules( $cfg ) ;
716
+ // Check frontend content
717
+ if ( $this->_wrap_rules( $frontend_rules ) != $this->extract_rules() ) {
718
+ // Need to update frontend htaccess
719
+ if ( ! $this->insert_wrapper( $frontend_rules ) ) {
720
+ $manual_guide_codes = $this->rewrite_codes_msg( $this->frontend_htaccess, $frontend_rules ) ;
721
+ return array( LiteSpeed_Cache_Admin_Display::get_error( LiteSpeed_Cache_Admin_Error::E_HTA_W ), $manual_guide_codes ) ;
722
+ }
723
+ }
724
+
725
+ if ( $this->frontend_htaccess !== $this->backend_htaccess ) {
726
+ // Check backend content
727
+ if ( $this->_wrap_rules( $backend_rules ) != $this->extract_rules( 'backend' ) ) {
728
+ // Need to update backend htaccess
729
+ if ( ! $this->insert_wrapper( $backend_rules, 'backend' ) ) {
730
+ $manual_guide_codes = $this->rewrite_codes_msg( $this->backend_htaccess, $backend_rules ) ;
731
+ return array( LiteSpeed_Cache_Admin_Display::get_error( LiteSpeed_Cache_Admin_Error::E_HTA_W ), $manual_guide_codes ) ;
732
+ }
733
+ }
734
+ }
735
+
736
+ return true ;
737
+ }
738
+
739
+ /**
740
+ * Get existing rewrite rules
741
+ *
742
+ * @since 1.3
743
+ * @access public
744
+ * @param string $kind Frontend or backend .htaccess file
745
+ * @return bool|array False if failed to read, rules array otherwise
746
+ */
747
+ public function extract_rules( $kind = 'frontend' )
748
+ {
749
+ clearstatcache() ;
750
+ $path = $this->htaccess_path( $kind ) ;
751
+ if ( ! self::readable( $kind ) ) {
752
+ return false ;
753
+ }
754
+
755
+ $rules = Litespeed_File::extract_from_markers( $path, self::MARKER ) ;
756
+
757
+ return $rules ;
758
}
759
760
/**
766
public function clear_rules( $clear_all = false )
767
{
768
$keep_wrapper = $clear_all === true ? false : array() ;
769
$this->insert_wrapper( $keep_wrapper ) ;
770
if ( $this->frontend_htaccess !== $this->backend_htaccess ) {
771
$this->insert_wrapper( $keep_wrapper, 'backend' ) ;
844
*/
845
public static function get_instance()
846
{
847
+ if ( ! isset( self::$_instance ) ) {
848
self::$_instance = new self() ;
849
}
850
admin/litespeed-cache-admin-settings.class.php CHANGED
@@ -12,223 +12,268 @@ class LiteSpeed_Cache_Admin_Settings
12
{
13
private static $_instance ;
14
15
- /**
16
- * Helper function to validate TTL settings. Will check if it's set,
17
- * is an integer, and is greater than 0 and less than INT_MAX.
18
- *
19
- * @since 1.0.12
20
- * @access public
21
- * @param array $input Input array
22
- * @param string $id Option ID
23
- * @param number $min Minimum number
24
- * @param number $max Maximum number
25
- * @return bool True if valid, false otherwise.
26
- */
27
- public function validate_ttl( $input, $id, $min = false, $max = 2147483647)
28
- {
29
- if ( ! isset( $input[ $id ]) ) {
30
- return false ;
31
- }
32
33
- $val = $input[ $id ] ;
34
35
- $ival = intval( $val) ;
36
- $sval = strval( $val) ;
37
-
38
- if( $min && $ival < $min ) {
39
- return false ;
40
- }
41
-
42
- return ctype_digit( $sval) && $ival >= 0 && $ival < $max ;
43
- }
44
45
/**
46
- * Hooked to the wp_redirect filter.
47
- * This will only hook if there was a problem when saving the widget.
48
*
49
- * @since 1.1.3
50
- * @access public
51
- * @param string $location The location string.
52
- * @return string the updated location string.
53
*/
54
- public static function widget_save_err( $location)
55
{
56
- return str_replace('?message=0', '?error=0', $location) ;
57
}
58
59
/**
60
- * Hooked to the widget_update_callback filter.
61
- * Validate the LiteSpeed Cache settings on edit widget save.
62
*
63
- * @since 1.1.3
64
* @access public
65
- * @param array $instance The new settings.
66
- * @param array $new_instance
67
- * @param array $old_instance The original settings.
68
- * @param WP_Widget $widget The widget
69
- * @return mixed Updated settings on success, false on error.
70
*/
71
- public static function validate_widget_save( $instance, $new_instance, $old_instance, $widget)
72
{
73
- if ( empty( $_POST[ LiteSpeed_Cache_Config::OPTION_NAME ] ) ) {
74
- return $instance ;
75
}
76
- $current = ! empty( $old_instance[ LiteSpeed_Cache_Config::OPTION_NAME ] ) ? $old_instance[ LiteSpeed_Cache_Config::OPTION_NAME ] : false ;
77
- $input = $_POST[ LiteSpeed_Cache_Config::OPTION_NAME ] ;
78
- $esistr = $input[ LiteSpeed_Cache_ESI::WIDGET_OPID_ESIENABLE ] ;
79
- $ttlstr = $input[ LiteSpeed_Cache_ESI::WIDGET_OPID_TTL ] ;
80
81
- if ( ! is_numeric( $ttlstr ) || ! is_numeric( $esistr ) ) {
82
- add_filter( 'wp_redirect', 'LiteSpeed_Cache_Admin_Settings::widget_save_err' ) ;
83
- return false ;
84
}
85
86
- $esi = self::is_checked_radio( $esistr) ;
87
- $ttl = intval( $ttlstr) ;
88
89
- if ( $ttl != 0 && $ttl < 30 ) {
90
- add_filter('wp_redirect', 'LiteSpeed_Cache_Admin_Settings::widget_save_err') ;
91
- return false ; // invalid ttl.
92
}
93
94
- if ( empty( $instance[ LiteSpeed_Cache_Config::OPTION_NAME ] ) ) {
95
- $instance[ LiteSpeed_Cache_Config::OPTION_NAME ] = array() ;
96
}
97
- $instance[ LiteSpeed_Cache_Config::OPTION_NAME ][ LiteSpeed_Cache_ESI::WIDGET_OPID_ESIENABLE ] = $esi ;
98
- $instance[ LiteSpeed_Cache_Config::OPTION_NAME ][ LiteSpeed_Cache_ESI::WIDGET_OPID_TTL ] = $ttl ;
99
100
- if ( ! $current || $esi != $current[ LiteSpeed_Cache_ESI::WIDGET_OPID_ESIENABLE ] ) {
101
- LiteSpeed_Cache_Purge::purge_all() ;
102
}
103
- elseif ( $ttl != 0 && $ttl != $current[ LiteSpeed_Cache_ESI::WIDGET_OPID_TTL ] ) {
104
- LiteSpeed_Cache_Purge::add( LiteSpeed_Cache_Tag::TYPE_WIDGET . $widget->id ) ;
105
}
106
107
- LiteSpeed_Cache_Purge::purge_all() ;
108
- return $instance ;
109
}
110
111
/**
112
- * Validates the general settings.
113
*
114
* @since 1.0.12
115
* @access private
116
- * @param array $input The input options.
117
- * @param array $options The current options.
118
- * @param array $errors The errors list.
119
*/
120
- private function validate_general( &$input, &$options, &$errors )
121
{
122
- $num_err = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_SETTING_NUMERIC) ;
123
- $max_ttl = 2147483647 ;
124
-
125
- // enabled setting
126
- $id = LiteSpeed_Cache_Config::OPID_ENABLED_RADIO ;
127
- if( ! isset( $input[ $id ]) ) {
128
- $enabled = 0 ;
129
- }
130
- else {
131
- $options[ $id ] = self::is_checked_radio( $input[ $id ]) ;
132
-
133
- if( $options[ $id ] !== LiteSpeed_Cache_Config::VAL_ON2 ){
134
- $enabled = $options[ $id ] ;
135
- }
136
- else{
137
- if ( is_multisite() ) {
138
- $enabled = $options[LiteSpeed_Cache_Config::NETWORK_OPID_ENABLED] ;
139
}
140
- else{
141
- $enabled = LiteSpeed_Cache_Config::VAL_ON ;
142
}
143
}
144
}
145
146
- // $enabled temporary variable
147
- $id = LiteSpeed_Cache_Config::OPID_ENABLED ;
148
- if ( $enabled !== $options[ $id ] ) {
149
- $options[ $id ] = $enabled ;
150
- $ret = LiteSpeed_Cache_Config::wp_cache_var_setter( $enabled) ;
151
- if ( $ret !== true ) {
152
- $errors[] = $ret ;
153
}
154
- if ( ! $enabled ) {
155
LiteSpeed_Cache_Purge::purge_all() ;
156
}
157
- elseif ( $options[LiteSpeed_Cache_Config::OPID_CACHE_FAVICON] ) {
158
- $options[LiteSpeed_Cache_Config::OPID_CACHE_FAVICON] = false ;
159
- }
160
- $input[ $id ] = 'changed' ;
161
- }
162
- else {
163
- $input[ $id ] = $enabled ;
164
}
165
166
- $id = LiteSpeed_Cache_Config::OPID_PUBLIC_TTL ;
167
- if ( ! $this->validate_ttl( $input, $id, 30 ) ) {
168
- $errors[] = sprintf( $num_err, __( 'Default Public Cache', 'litespeed-cache' ), 30, $max_ttl ) ;
169
- }
170
- else {
171
- $options[ $id ] = $input[ $id ] ;
172
}
173
174
- $id = LiteSpeed_Cache_Config::OPID_PRIVATE_TTL ;
175
- if ( ! $this->validate_ttl( $input, $id, 60, 3600 ) ) {
176
- $errors[] = sprintf( $num_err, __( 'Default Private Cache', 'litespeed-cache' ), 60, 3600 ) ;
177
- }
178
- else {
179
- $options[ $id ] = $input[ $id ] ;
180
- }
181
182
- $id = LiteSpeed_Cache_Config::OPID_FRONT_PAGE_TTL ;
183
- if ( ! $this->validate_ttl( $input, $id, 30) ) {
184
- $errors[] = sprintf( $num_err, __('Default Front Page', 'litespeed-cache'), 30, $max_ttl) ;
185
}
186
else {
187
- $options[ $id ] = $input[ $id ] ;
188
}
189
190
- $id = LiteSpeed_Cache_Config::OPID_FEED_TTL ;
191
- if ( ! $this->validate_ttl( $input, $id) ) {
192
- $errors[] = sprintf( $num_err, __('Feed', 'litespeed-cache'), 0, $max_ttl) ;
193
- }
194
- elseif ( $input[ $id ] < 30 ) {
195
- $options[ $id ] = 0 ;
196
- }
197
- else {
198
- $options[ $id ] = intval( $input[ $id ]) ;
199
}
200
201
- $id = LiteSpeed_Cache_Config::OPID_404_TTL ;
202
- if ( ! $this->validate_ttl( $input, $id) ) {
203
- $errors[] = sprintf( $num_err, __('404', 'litespeed-cache'), 0, $max_ttl) ;
204
- }
205
- elseif ( $input[ $id ] < 30 ) {
206
- $options[ $id ] = 0 ;
207
- }
208
- else {
209
- $options[ $id ] = intval( $input[ $id ]) ;
210
- }
211
212
- $id = LiteSpeed_Cache_Config::OPID_403_TTL ;
213
- if ( ! $this->validate_ttl( $input, $id) ) {
214
- $errors[] = sprintf( $num_err, __('403', 'litespeed-cache'), 0, $max_ttl) ;
215
}
216
- elseif ( $input[ $id ] < 30 ) {
217
- $options[ $id ] = 0 ;
218
}
219
else {
220
- $options[ $id ] = intval( $input[ $id ]) ;
221
}
222
223
- $id = LiteSpeed_Cache_Config::OPID_500_TTL ;
224
- if ( ! $this->validate_ttl( $input, $id) ) {
225
- $errors[] = sprintf( $num_err, __('500', 'litespeed-cache'), 0, $max_ttl) ;
226
- }
227
- elseif ( $input[ $id ] < 30 ) {
228
- $options[ $id ] = 0 ;
229
}
230
- else {
231
- $options[ $id ] = intval( $input[ $id ]) ;
232
}
233
234
}
@@ -238,25 +283,27 @@ class LiteSpeed_Cache_Admin_Settings
238
*
239
* @since 1.1.6
240
* @access private
241
- * @param array $input The input options.
242
- * @param array $options The current options.
243
- * @param array $errors The errors list.
244
*/
245
- private function validate_cache( &$input, &$options, &$errors )
246
{
247
- $id = LiteSpeed_Cache_Config::OPID_CACHE_PRIV ;
248
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
249
-
250
- $id = LiteSpeed_Cache_Config::OPID_CACHE_COMMENTER ;
251
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
252
-
253
- $id = LiteSpeed_Cache_Config::OPID_CACHE_REST ;
254
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
255
256
$id = LiteSpeed_Cache_Config::OPID_CACHE_PAGE_LOGIN ;
257
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
258
- if( ! $options[ $id ] ) {
259
- LiteSpeed_Cache_Purge::add(LiteSpeed_Cache_Tag::TYPE_LOGIN) ;
260
}
261
}
262
@@ -265,14 +312,11 @@ class LiteSpeed_Cache_Admin_Settings
265
*
266
* @since 1.0.12
267
* @access private
268
- * @param array $input The input options.
269
- * @param array $options The current options.
270
- * @param array $errors The errors list.
271
*/
272
- private function validate_purge( $input, &$options, &$errors )
273
{
274
$id = LiteSpeed_Cache_Config::OPID_PURGE_ON_UPGRADE ;
275
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
276
277
// get auto purge rules options
278
$pvals = array(
@@ -289,39 +333,27 @@ class LiteSpeed_Cache_Admin_Settings
289
LiteSpeed_Cache_Config::PURGE_POST_TYPE,
290
) ;
291
$input_purge_options = array() ;
292
- foreach ( $pvals as $pval) {
293
- $input_name = 'purge_' . $pval ;
294
- if ( self::parse_onoff( $input, $input_name ) ) {
295
- $input_purge_options[] = $pval ;
296
}
297
}
298
sort( $input_purge_options ) ;
299
$purge_by_post = implode( '.', $input_purge_options ) ;
300
- if ( $purge_by_post !== $options[ LiteSpeed_Cache_Config::OPID_PURGE_BY_POST ] ) {
301
- $options[ LiteSpeed_Cache_Config::OPID_PURGE_BY_POST ] = $purge_by_post ;
302
}
303
304
// Filter scheduled purge URLs
305
$id = LiteSpeed_Cache_Config::OPID_TIMED_URLS ;
306
- $options[ $id ] = '' ;
307
- if ( isset( $input[ $id ] ) ) {
308
- if ( ! empty( $input[ $id ] ) ) {
309
- $list = array() ;
310
- foreach ( explode( "\n", $input[ $id ] ) as $val ) {
311
- $val = LiteSpeed_Cache_Utility::make_relative( $val ) ;
312
- if ( $val ) {
313
- $list[] = $val ;
314
- }
315
- }
316
- if ( $list ) {
317
- $options[ $id ] = implode( "\n", $list ) ;
318
- }
319
- }
320
}
321
322
// Schduled Purge Time
323
$id = LiteSpeed_Cache_Config::OPID_TIMED_URLS_TIME ;
324
- $options[ $id ] = $input[ $id ] ;
325
}
326
327
/**
@@ -329,61 +361,62 @@ class LiteSpeed_Cache_Admin_Settings
329
*
330
* @since 1.0.12
331
* @access private
332
- * @param array $input The input options.
333
- * @param array $options The current options.
334
- * @param array $errors The errors list.
335
*/
336
- private function validate_exclude( $input, &$options, &$errors)
337
{
338
$id = LiteSpeed_Cache_Config::OPID_EXCLUDES_URI ;
339
- if ( isset( $input[ $id ]) ) {
340
- $uri_arr = array_map('trim', explode("\n", $input[ $id ])) ;
341
- $options[ $id ] = implode("\n", array_filter( $uri_arr)) ;
342
}
343
344
$id = LiteSpeed_Cache_Config::OPID_EXCLUDES_CAT ;
345
- $options[ $id ] = '' ;
346
- if ( isset( $input[ $id ]) ) {
347
$cat_ids = array() ;
348
- $cats = explode("\n", $input[ $id ]) ;
349
- foreach ( $cats as $cat) {
350
- $cat_name = trim( $cat) ;
351
if ( $cat_name == '' ) {
352
continue ;
353
}
354
- $cat_id = get_cat_ID( $cat_name) ;
355
if ( $cat_id == 0 ) {
356
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_SETTING_CAT, $cat_name) ;
357
}
358
else {
359
$cat_ids[] = $cat_id ;
360
}
361
}
362
- if ( ! empty( $cat_ids) ) {
363
- $options[ $id ] = implode(',', $cat_ids) ;
364
}
365
}
366
367
$id = LiteSpeed_Cache_Config::OPID_EXCLUDES_TAG ;
368
- $options[ $id ] = '' ;
369
- if ( isset( $input[ $id ]) ) {
370
$tag_ids = array() ;
371
- $tags = explode("\n", $input[ $id ]) ;
372
- foreach ( $tags as $tag) {
373
- $tag_name = trim( $tag) ;
374
if ( $tag_name == '' ) {
375
continue ;
376
}
377
- $term = get_term_by('name', $tag_name, 'post_tag') ;
378
if ( $term == 0 ) {
379
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_SETTING_TAG, $tag_name) ;
380
}
381
else {
382
$tag_ids[] = $term->term_id ;
383
}
384
}
385
- if ( ! empty( $tag_ids) ) {
386
- $options[ $id ] = implode(',', $tag_ids) ;
387
}
388
}
389
}
@@ -394,51 +427,46 @@ class LiteSpeed_Cache_Admin_Settings
394
* @since 1.2.2
395
* @access private
396
*/
397
- private function validate_cdn( $input, &$options, &$errors)
398
{
399
$ids = array(
400
LiteSpeed_Cache_Config::OPID_CDN,
401
LiteSpeed_Cache_Config::OPID_CDN_INC_IMG,
402
LiteSpeed_Cache_Config::OPID_CDN_INC_CSS,
403
LiteSpeed_Cache_Config::OPID_CDN_INC_JS,
404
- );
405
foreach ( $ids as $id ) {
406
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
407
}
408
409
$id = LiteSpeed_Cache_Config::OPID_CDN_ORI ;
410
- $options[ $id ] = $input[ $id ] ;
411
- if ( $options[ $id ] ) {
412
- $tmp = parse_url( $options[ $id ] ) ;
413
if ( ! empty( $tmp[ 'scheme' ] ) ) {
414
- $options[ $id ] = str_replace( $tmp[ 'scheme' ] . ':', '', $options[ $id ] ) ;
415
}
416
}
417
418
$id = LiteSpeed_Cache_Config::OPID_CDN_URL ;
419
- $options[ $id ] = $input[ $id ] ;
420
421
$ids = array(
422
LiteSpeed_Cache_Config::OPID_CDN_FILETYPE,
423
LiteSpeed_Cache_Config::OPID_CDN_EXCLUDE,
424
) ;
425
foreach ( $ids as $id ) {
426
- $options[ $id ] = explode( "\n", $input[ $id ] ) ;
427
- $options[ $id ] = array_map( 'trim', $options[ $id ] ) ;
428
- $options[ $id ] = array_unique( $options[ $id ] ) ;
429
- $options[ $id ] = array_filter( $options[ $id ] ) ;
430
- $options[ $id ] = implode( "\n", $options[ $id ] ) ;
431
}
432
}
433
434
-
435
/**
436
* Validates the optimize settings.
437
*
438
* @since 1.2.2
439
* @access private
440
*/
441
- private function validate_optimize( $input, &$options, &$errors)
442
{
443
$ids = array(
444
LiteSpeed_Cache_Config::OPID_CSS_MINIFY,
@@ -448,9 +476,14 @@ class LiteSpeed_Cache_Admin_Settings
448
LiteSpeed_Cache_Config::OPID_JS_COMBINE,
449
LiteSpeed_Cache_Config::OPID_JS_HTTP2,
450
LiteSpeed_Cache_Config::OPID_HTML_MINIFY,
451
) ;
452
foreach ( $ids as $id ) {
453
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
454
}
455
456
$ids = array(
@@ -458,55 +491,17 @@ class LiteSpeed_Cache_Admin_Settings
458
LiteSpeed_Cache_Config::OPID_JS_EXCLUDES,
459
) ;
460
foreach ( $ids as $id ) {
461
- $options[ $id ] = explode( "\n", $input[ $id ] ) ;
462
- $options[ $id ] = array_map( 'LiteSpeed_Cache_Utility::url2uri', $options[ $id ] ) ;
463
- $options[ $id ] = array_unique( $options[ $id ] ) ;
464
- $options[ $id ] = array_filter( $options[ $id ] ) ;
465
- $options[ $id ] = implode( "\n", $options[ $id ] ) ;
466
}
467
468
$id = LiteSpeed_Cache_Config::OPID_OPTIMIZE_TTL ;
469
- if ( ! $this->validate_ttl( $input, $id, 3600 ) ) {
470
- $input[ $id ] = 3600 ;
471
- }
472
- $options[ $id ] = $input[ $id ] ;
473
-
474
- }
475
-
476
- /**
477
- * Validates the single site specific settings.
478
- *
479
- * @since 1.0.12
480
- * @access private
481
- * @param array $input The input options.
482
- * @param array $options The current options.
483
- * @param array $errors The errors list.
484
- */
485
- private function validate_singlesite( $input, &$options, &$errors)
486
- {
487
- $rules = LiteSpeed_Cache_Admin_Rules::get_instance() ;
488
-
489
- $id = LiteSpeed_Cache_Config::OPID_ENABLED ;
490
- if ( $input[ $id ] !== 'changed' ) {
491
- $diff = $rules->check_input_for_rewrite( $options, $input, $errors) ;
492
- }
493
- elseif ( $options[ $id ] ) {
494
- $reset = LiteSpeed_Cache_Config::get_rule_reset_options() ;
495
- $added_and_changed = $rules->check_input_for_rewrite( $reset, $input, $errors) ;
496
- // Merge to include the newly disabled options
497
- $diff = array_merge( $reset, $added_and_changed) ;
498
- }
499
- else {
500
- $rules->clear_rules() ;
501
- $diff = $rules->check_input_for_rewrite( $options, $input, $errors) ;
502
}
503
504
- if ( ! empty( $diff) && ( $options[ $id ] == false || $rules->validate_common_rewrites( $diff, $errors) !== false) ) {//todo: check if need to use ===
505
- $options = array_merge( $options, $diff) ;
506
- }
507
-
508
- $id = LiteSpeed_Cache_Config::OPID_CHECK_ADVANCEDCACHE ;
509
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
510
}
511
512
/**
@@ -514,104 +509,62 @@ class LiteSpeed_Cache_Admin_Settings
514
*
515
* @since 1.0.12
516
* @access private
517
- * @param array $input The input options.
518
- * @param array $options The current options.
519
- * @param array $errors The errors list.
520
*/
521
- private function validate_debug( $input, &$options, &$errors)
522
{
523
- $num_err = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_SETTING_NUMERIC) ;
524
-
525
$id = LiteSpeed_Cache_Config::OPID_ADMIN_IPS ;
526
- if ( isset( $input[ $id ]) ) {
527
- $admin_ips = array_map('trim', explode("\n", trim( $input[ $id ]))) ;
528
- $admin_ips = array_filter( $admin_ips) ;
529
$has_err = false ;
530
if ( $admin_ips ) {
531
- foreach ( $admin_ips as $ip) {
532
- if ( ! WP_Http::is_ip_address( $ip) ) {
533
- $has_err = true ;
534
- break ;
535
- }
536
- }
537
- }
538
- $admin_ips = implode("\n", $admin_ips) ;
539
-
540
- if ( $has_err ) {
541
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_SETTING_ADMIN_IP_INV) ;
542
- }
543
- elseif ( $admin_ips != $options[ $id ] ) {
544
- $options[ $id ] = $admin_ips ;
545
- }
546
- }
547
-
548
- $id = LiteSpeed_Cache_Config::OPID_TEST_IPS ;
549
- if ( isset( $input[ $id ]) ) {
550
- // this feature has not implemented yet
551
- $test_ips = array_map('trim', explode("\n", trim( $input[ $id ]))) ;
552
- $test_ips = array_filter( $test_ips) ;
553
- $has_err = false ;
554
- if ( $test_ips ) {
555
- foreach ( $test_ips as $ip) {
556
- if ( ! WP_Http::is_ip_address( $ip) ) {
557
$has_err = true ;
558
break ;
559
}
560
}
561
}
562
- $test_ips = implode("\n", $test_ips) ;
563
564
if ( $has_err ) {
565
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_SETTING_TEST_IP_INV) ;
566
}
567
- elseif ( $test_ips != $options[ $id ] ) {
568
- $options[ $id ] = $test_ips ;
569
}
570
}
571
572
$id = LiteSpeed_Cache_Config::OPID_DEBUG ;
573
- $debug_level = self::is_checked_radio( $input[ $id ]) ;
574
- if ( $debug_level != $options[ $id ] ){
575
- $options[ $id ] = $debug_level ;
576
- }
577
-
578
- $id = LiteSpeed_Cache_Config::OPID_DEBUG_LEVEL ;
579
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
580
581
$id = LiteSpeed_Cache_Config::OPID_LOG_FILE_SIZE ;
582
- if ( ! $this->validate_ttl( $input, $id, 3, 3000 ) ) {
583
- $errors[] = sprintf( $num_err, __( 'Log File Size Limit', 'litespeed-cache' ), 3, 3000 ) ;
584
}
585
else {
586
- $options[ $id ] = $input[ $id ] ;
587
}
588
589
- $id = LiteSpeed_Cache_Config::OPID_HEARTBEAT ;
590
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
591
-
592
- $id = LiteSpeed_Cache_Config::OPID_DEBUG_COOKIE ;
593
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
594
-
595
- $id = LiteSpeed_Cache_Config::OPID_COLLAPS_QS ;
596
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
597
-
598
- $id = LiteSpeed_Cache_Config::OPID_LOG_FILTERS ;
599
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
600
-
601
- $id = LiteSpeed_Cache_Config::OPID_LOG_IGNORE_FILTERS ;
602
- if ( isset( $input[ $id ] ) ) {
603
- $items = array_map( 'trim', explode( "\n", trim( $input[ $id ] ) ) ) ;
604
- $items = implode( "\n", array_filter( $items ) ) ;
605
- $options[ $id ] = $items ;
606
}
607
608
- $id = LiteSpeed_Cache_Config::OPID_LOG_IGNORE_PART_FILTERS ;
609
- if ( isset( $input[ $id ] ) ) {
610
- $items = array_map( 'trim', explode( "\n", trim( $input[ $id ] ) ) ) ;
611
- $items = implode( "\n", array_filter( $items ) ) ;
612
- $options[ $id ] = $items ;
613
}
614
-
615
}
616
617
/**
@@ -619,116 +572,152 @@ class LiteSpeed_Cache_Admin_Settings
619
*
620
* @since 1.0.12
621
* @access private
622
- * @param array $input The input options.
623
- * @param array $options The current options.
624
- * @param array $errors The errors list.
625
*/
626
- private function validate_crawler( $input, &$options, &$errors)
627
{
628
- $num_err = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_SETTING_NUMERIC) ;
629
-
630
- $id = LiteSpeed_Cache_Config::CRWL_POSTS ;
631
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
632
-
633
- $id = LiteSpeed_Cache_Config::CRWL_PAGES ;
634
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
635
-
636
- $id = LiteSpeed_Cache_Config::CRWL_CATS ;
637
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
638
-
639
- $id = LiteSpeed_Cache_Config::CRWL_TAGS ;
640
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
641
642
$id = LiteSpeed_Cache_Config::CRWL_EXCLUDES_CPT ;
643
- if ( isset( $input[ $id ]) ) {
644
- $arr = array_map('trim', explode("\n", $input[ $id ])) ;
645
- $arr = array_filter( $arr) ;
646
- $ori = array_diff(get_post_types( '', 'names' ), array('post', 'page')) ;
647
- $options[ $id ] = implode("\n", array_intersect( $arr, $ori)) ;
648
}
649
650
$id = LiteSpeed_Cache_Config::CRWL_ORDER_LINKS ;
651
- if( ! isset( $input[ $id ]) || ! in_array( $input[ $id ], array(
652
LiteSpeed_Cache_Config::CRWL_DATE_DESC,
653
LiteSpeed_Cache_Config::CRWL_DATE_ASC,
654
LiteSpeed_Cache_Config::CRWL_ALPHA_DESC,
655
LiteSpeed_Cache_Config::CRWL_ALPHA_ASC,
656
- )) ) {
657
- $input[ $id ] = LiteSpeed_Cache_Config::CRWL_DATE_DESC ;
658
}
659
- $options[ $id ] = $input[ $id ] ;
660
661
- $id = LiteSpeed_Cache_Config::CRWL_USLEEP ;
662
- if ( ! $this->validate_ttl( $input, $id, 0, 30000) ) {
663
- $errors[] = sprintf( $num_err, __('Delay', 'litespeed-cache'), 0, 30000) ;
664
- }
665
- else {
666
- $options[ $id ] = $input[ $id ] ;
667
}
668
669
- $id = LiteSpeed_Cache_Config::CRWL_RUN_DURATION ;
670
- if ( ! $this->validate_ttl( $input, $id) ) {
671
- $errors[] = sprintf( $num_err, __('Run Duration', 'litespeed-cache'), 0, 2147483647) ;
672
}
673
else {
674
- $options[ $id ] = $input[ $id ] ;
675
}
676
677
- $id = LiteSpeed_Cache_Config::CRWL_RUN_INTERVAL ;
678
- if ( ! $this->validate_ttl( $input, $id, 60) ) {
679
- $errors[] = sprintf( $num_err, __('Cron Interval', 'litespeed-cache'), 60, 2147483647) ;
680
}
681
else {
682
- $options[ $id ] = $input[ $id ] ;
683
}
684
685
- $id = LiteSpeed_Cache_Config::CRWL_CRAWL_INTERVAL ;
686
- if ( ! $this->validate_ttl( $input, $id) ) {
687
- $errors[] = sprintf( $num_err, __('Whole Interval', 'litespeed-cache'), 0, 2147483647) ;
688
}
689
else {
690
- $options[ $id ] = $input[ $id ] ;
691
}
692
693
- $id = LiteSpeed_Cache_Config::CRWL_THREADS ;
694
- if ( ! $this->validate_ttl( $input, $id, 1) ) {
695
- $errors[] = sprintf( $num_err, __('Threads', 'litespeed-cache'), 1, 16) ;
696
}
697
else {
698
- $options[ $id ] = $input[ $id ] ;
699
}
700
701
- $id = LiteSpeed_Cache_Config::CRWL_LOAD_LIMIT ;
702
- $options[ $id ] = $input[ $id ] ;
703
-
704
- $id = LiteSpeed_Cache_Config::CRWL_DOMAIN_IP ;
705
- if ( ! empty( $input[ $id ]) && ! WP_Http::is_ip_address( $input[ $id ]) ) {
706
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error(LiteSpeed_Cache_Admin_Error::E_SETTING_SITE_IP, $input[ $id ]) ;
707
}
708
else {
709
- $options[ $id ] = $input[ $id ] ;
710
}
711
712
- $id = LiteSpeed_Cache_Config::CRWL_CUSTOM_SITEMAP ;
713
- if ( ! empty( $input[ $id ]) && ( $err = $this->validate_custom_sitemap( $input[ $id ])) !== true ) {
714
- $errors[] = LiteSpeed_Cache_Admin_Display::get_error( $err, $input[ $id ]) ;
715
}
716
else {
717
- $options[ $id ] = $input[ $id ] ;
718
}
719
720
- }
721
-
722
- /**
723
- * Validates the custom sitemap settings.
724
- *
725
- * @since 1.1.1
726
- * @access private
727
- * @param string $url The sitemap url
728
- */
729
- private function validate_custom_sitemap( $url)
730
- {
731
- return LiteSpeed_Cache_Crawler::get_instance()->parse_custom_sitemap( $url, false) ;
732
}
733
734
/**
@@ -736,24 +725,23 @@ class LiteSpeed_Cache_Admin_Settings
736
*
737
* @since 1.0.12
738
* @access private
739
- * @param array $input The input options.
740
- * @param array $options The current options.
741
*/
742
- private function validate_thirdparty( $input, $options)
743
{
744
$tp_default_options = LiteSpeed_Cache_Config::get_instance()->get_thirdparty_options() ;
745
- if ( empty( $tp_default_options) ) {
746
- return $options ;
747
}
748
- $tp_input = array_intersect_key( $input, $tp_default_options) ;
749
- if ( empty( $tp_input) ) {
750
- return $options ;
751
}
752
- $tp_options = apply_filters('litespeed_cache_save_options', array_intersect_key( $options, $tp_default_options), $tp_input) ;
753
- if ( ! empty( $tp_options) && is_array( $tp_options) ) {
754
- $options = array_merge( $options, $tp_options) ;
755
}
756
- return $options ;
757
}
758
759
/**
@@ -761,185 +749,156 @@ class LiteSpeed_Cache_Admin_Settings
761
*
762
* @since 1.1.3
763
* @access private
764
- * @param array $input The input options.
765
- * @param array $options The current options.
766
- * @param array $errors The errors list.
767
*/
768
- private function validate_esi( $input, &$options, &$errors)
769
{
770
- $id = LiteSpeed_Cache_Config::OPID_ESI_ENABLE ;
771
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
772
-
773
- $id = LiteSpeed_Cache_Config::OPID_ESI_CACHE_ADMBAR ;
774
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
775
-
776
- $id = LiteSpeed_Cache_Config::OPID_ESI_CACHE_COMMFORM ;
777
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
778
779
// Save vary group settings
780
$vary_groups = $_POST[ LiteSpeed_Cache_Config::VARY_GROUP ] ;
781
$vary_groups = array_map( 'trim', $vary_groups ) ;
782
$vary_groups = array_filter( $vary_groups ) ;
783
update_option( LiteSpeed_Cache_Config::VARY_GROUP, $vary_groups ) ;
784
-
785
}
786
787
/**
788
- * Callback function that will validate any changes made in the settings
789
- * page.
790
- *
791
- * NOTE: Anytime that validate_plugin_settings is called, `convert_options_to_input` must be done first if not from option page
792
*
793
- * @since 1.0.0
794
* @access public
795
- * @param array $input The configuration selected by the admin when
796
- * clicking save.
797
- * @return array The updated configuration options.
798
*/
799
- public function validate_plugin_settings( $input)
800
{
801
- LiteSpeed_Cache_Log::debug('settings->validate_plugin_settings called') ;
802
- $options = LiteSpeed_Cache_Config::get_instance()->get_options() ;
803
- $errors = array() ;
804
-
805
- if ( LiteSpeed_Cache_Admin_Display::get_instance()->get_disable_all() ) {
806
- add_settings_error(LiteSpeed_Cache_Config::OPTION_NAME, LiteSpeed_Cache_Config::OPTION_NAME, __('\'Use primary site settings\' set by Network Administrator.', 'litespeed-cache')) ;
807
808
- return $options ;
809
}
810
811
- $this->validate_general( $input, $options, $errors) ;
812
-
813
- $this->validate_cache( $input, $options, $errors) ;
814
-
815
- $this->validate_purge( $input, $options, $errors) ;
816
-
817
- $this->validate_exclude( $input, $options, $errors) ;
818
-
819
- $this->validate_optimize( $input, $options, $errors) ;
820
-
821
- $this->validate_cdn( $input, $options, $errors) ;
822
823
- $this->validate_debug( $input, $options, $errors) ;
824
825
- if ( ! is_multisite() ) {
826
- $this->validate_singlesite( $input, $options, $errors) ;
827
}
828
829
- if ( ! is_network_admin() ) {
830
- $this->validate_crawler( $input, $options, $errors) ;
831
}
832
833
- if ( LSWCP_ESI_SUPPORT ) {
834
- $orig_enabled = $options[LiteSpeed_Cache_Config::OPID_ENABLED] ;
835
- $orig_esi_enabled = $options[LiteSpeed_Cache_Config::OPID_ESI_ENABLE] ;
836
-
837
- $this->validate_esi( $input, $options, $errors) ;
838
-
839
- $new_enabled = $options[LiteSpeed_Cache_Config::OPID_ENABLED] ;
840
- $new_esi_enabled = $options[LiteSpeed_Cache_Config::OPID_ESI_ENABLE] ;
841
-
842
- if ( $orig_enabled !== $new_enabled || $orig_esi_enabled !== $new_esi_enabled ) {
843
- LiteSpeed_Cache_Purge::purge_all() ;
844
- }
845
}
846
847
- if ( ! empty( $errors) ) {
848
- add_settings_error(LiteSpeed_Cache_Config::OPTION_NAME, LiteSpeed_Cache_Config::OPTION_NAME, implode('<br />', $errors)) ;
849
850
- return $options ;
851
- }
852
853
- $cron_changed = false ;
854
- if ( LiteSpeed_Cache_Router::is_cli() ) {
855
- $id = LiteSpeed_Cache_Config::CRWL_CRON_ACTIVE ;
856
- $cron_val = $options[ $id ] ;
857
- // assign crawler_cron_active to $options if exists in $input separately for CLI
858
- // This has to be specified cos crawler cron activation is not set in admin setting page
859
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
860
- if ( $cron_val != $options[ $id ] ) {
861
- $cron_changed = true ;
862
- }
863
- }
864
865
- // check if need to enable crawler cron
866
- if ( $input[LiteSpeed_Cache_Config::OPID_ENABLED] === 'changed' || $cron_changed ) {
867
- LiteSpeed_Cache_Task::update( $options) ;
868
}
869
870
- $options = $this->validate_thirdparty( $input, $options) ;
871
872
- return $options ;
873
}
874
875
/**
876
- * Parses any changes made by the network admin on the network settings.
877
*
878
- * @since 1.0.4
879
- * @access public
880
*/
881
- public function validate_network_settings()
882
{
883
- $input = array_map("LiteSpeed_Cache_Admin::cleanup_text", $_POST[LiteSpeed_Cache_Config::OPTION_NAME]) ;
884
- $options = LiteSpeed_Cache_Config::get_instance()->get_site_options() ;
885
- $errors = array() ;
886
-
887
- $id = LiteSpeed_Cache_Config::NETWORK_OPID_ENABLED ;
888
- $network_enabled = self::parse_onoff( $input, $id ) ;
889
- if ( $options[ $id ] != $network_enabled ) {
890
- $options[ $id ] = $network_enabled ;
891
- if ( $network_enabled ) {
892
- $ret = LiteSpeed_Cache_Config::wp_cache_var_setter(true) ;
893
- if ( $ret !== true ) {
894
- $errors[] = $ret ;
895
- }
896
- }
897
- else {
898
- LiteSpeed_Cache_Purge::purge_all() ;
899
- }
900
- $input[ $id ] = 'changed' ;
901
- $reset = LiteSpeed_Cache_Config::get_rule_reset_options() ;
902
- }
903
-
904
- $id = LiteSpeed_Cache_Config::NETWORK_OPID_USE_PRIMARY ;
905
- $orig_primary = $options[ $id ] ;
906
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
907
- if ( $orig_primary != $options[ $id ] ) {
908
- LiteSpeed_Cache_Purge::purge_all() ;
909
}
910
911
- $id = LiteSpeed_Cache_Config::OPID_PURGE_ON_UPGRADE ;
912
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
913
-
914
- $id = LiteSpeed_Cache_Config::OPID_CHECK_ADVANCEDCACHE ;
915
- $options[ $id ] = self::parse_onoff( $input, $id ) ;
916
917
- $rules = LiteSpeed_Cache_Admin_Rules::get_instance() ;
918
919
- if ( $input[LiteSpeed_Cache_Config::NETWORK_OPID_ENABLED] !== 'changed' ) {
920
- $diff = $rules->check_input_for_rewrite( $options, $input, $errors) ;
921
- }
922
- elseif ( $network_enabled ) {
923
- $added_and_changed = $rules->check_input_for_rewrite( $reset, $input, $errors) ;
924
- // Merge to include the newly disabled options
925
- $diff = array_merge( $reset, $added_and_changed) ;
926
- }
927
- else {
928
- $rules->validate_common_rewrites( $reset, $errors) ;
929
- $diff = $rules->check_input_for_rewrite( $options, $input, $errors) ;
930
}
931
932
- if ( ! empty( $diff) && ( $network_enabled === false || $rules->validate_common_rewrites( $diff, $errors) !== false) ) {
933
- $options = array_merge( $options, $diff) ;
934
}
935
936
- if ( ! empty( $errors) ) {
937
- LiteSpeed_Cache_Admin_Display::add_notice(LiteSpeed_Cache_Admin_Display::NOTICE_RED, $errors) ;
938
- return ;
939
- }
940
- LiteSpeed_Cache_Admin_Display::add_notice(LiteSpeed_Cache_Admin_Display::NOTICE_GREEN, __('File saved.', 'litespeed-cache')) ;
941
- update_site_option(LiteSpeed_Cache_Config::OPTION_NAME, $options) ;
942
- return $options ;
943
}
944
945
/**
@@ -964,11 +923,11 @@ class LiteSpeed_Cache_Admin_Settings
964
* @param int $val The checkbox value
965
* @return bool Filtered value
966
*/
967
- public static function is_checked( $val)
968
{
969
- $val = intval( $val) ;
970
971
- if( $val === LiteSpeed_Cache_Config::VAL_ON ){
972
return true ;
973
}
974
@@ -983,15 +942,15 @@ class LiteSpeed_Cache_Admin_Settings
983
* @param int $val The radio value
984
* @return int Filtered value
985
*/
986
- public static function is_checked_radio( $val)
987
{
988
- $val = intval( $val) ;
989
990
- if( $val === LiteSpeed_Cache_Config::VAL_ON ){
991
return LiteSpeed_Cache_Config::VAL_ON ;
992
}
993
994
- if( $val === LiteSpeed_Cache_Config::VAL_ON2 ){
995
return LiteSpeed_Cache_Config::VAL_ON2 ;
996
}
997
@@ -1007,7 +966,7 @@ class LiteSpeed_Cache_Admin_Settings
1007
*/
1008
public static function get_instance()
1009
{
1010
- if ( ! isset(self::$_instance) ) {
1011
self::$_instance = new self() ;
1012
}
1013
12
{
13
private static $_instance ;
14
15
+ private $_input ;
16
+ private $_options ;
17
+ private $_err ;
18
19
+ private $_err_msg_numeric ;
20
21
+ private $_max_int = 2147483647 ;
22
23
/**
24
+ * Init
25
*
26
+ * @since 1.3
27
+ * @access private
28
*/
29
+ private function __construct()
30
{
31
+ $this->_err_msg_numeric = LiteSpeed_Cache_Admin_Display::get_error( LiteSpeed_Cache_Admin_Error::E_SETTING_NUMERIC ) ;
32
}
33
34
/**
35
+ * Callback function that will validate any changes made in the settings page.
36
*
37
+ * NOTE: Anytime that validate_plugin_settings is called, `convert_options_to_input` must be done first if not from option page
38
+ *
39
+ * @since 1.0.0
40
* @access public
41
+ * @param array $input The configuration selected by the admin when clicking save.
42
+ * @return array The updated configuration options.
43
*/
44
+ public function validate_plugin_settings( $input )
45
{
46
+ LiteSpeed_Cache_Log::debug( 'Settings: validate_plugin_settings called' ) ;
47
+ $this->_options = LiteSpeed_Cache_Config::get_instance()->get_options() ;
48
+
49
+ if ( LiteSpeed_Cache_Admin_Display::get_instance()->get_disable_all() ) {
50
+ add_settings_error( LiteSpeed_Cache_Config::OPTION_NAME, LiteSpeed_Cache_Config::OPTION_NAME, __( '\'Use primary site settings\' set by Network Administrator.', 'litespeed-cache' ) ) ;
51
+
52
+ return $this->_options ;
53
}
54
55
+ $this->_input = $input ;
56
+
57
+ $this->_validate_general() ;
58
+
59
+ $this->_validate_cache() ;
60
+
61
+ $this->_validate_purge() ;
62
+
63
+ $this->_validate_exclude() ;
64
+
65
+ $this->_validate_optimize() ;
66
+
67
+ $this->_validate_cdn() ;
68
+
69
+ $this->_validate_debug() ;
70
+
71
+ $this->_validate_crawler() ; // Network setup doesn't run validate_plugin_settings
72
+
73
+ if ( ! is_multisite() ) {
74
+ $this->_validate_singlesite() ;
75
}
76
77
+ if ( LSWCP_ESI_SUPPORT ) {
78
+ $orig_esi_enabled = $this->_options[ LiteSpeed_Cache_Config::OPID_ESI_ENABLE ] ;
79
80
+ $this->_validate_esi() ;
81
+
82
+ $new_esi_enabled = $this->_options[ LiteSpeed_Cache_Config::OPID_ESI_ENABLE ] ;
83
+
84
+ if ( $orig_esi_enabled !== $new_esi_enabled ) {
85
+ LiteSpeed_Cache_Purge::purge_all() ;
86
+ }
87
}
88
89
+ if ( ! empty( $this->_err ) ) {
90
+ add_settings_error( LiteSpeed_Cache_Config::OPTION_NAME, LiteSpeed_Cache_Config::OPTION_NAME, implode( '<br />', $this->_err ) ) ;
91
+
92
+ return $this->_options ;
93
}
94
95
+ $cron_changed = false ;
96
+ if ( defined( 'LITESPEED_CLI' ) ) {
97
+ $id = LiteSpeed_Cache_Config::CRWL_CRON_ACTIVE ;
98
+ $cron_val = $this->_options[ $id ] ;
99
+ // assign crawler_cron_active to $this->_options if exists in $this->_input separately for CLI
100
+ // This has to be specified cos crawler cron activation is not set in admin setting page
101
+ $this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
102
+ if ( $cron_val != $this->_options[ $id ] ) {
103
+ $cron_changed = true ;
104
+ }
105
}
106
+
107
+ // check if need to enable crawler cron
108
+ if ( defined( 'LITESPEED_ON_CHANGED' ) || $cron_changed ) {
109
+ LiteSpeed_Cache_Task::update( $this->_options ) ;
110
}
111
112
+ $this->_validate_thirdparty( ) ;
113
+
114
+ return $this->_options ;
115
}
116
117
/**
118
+ * Validates the single site specific settings.
119
*
120
* @since 1.0.12
121
* @access private
122
*/
123
+ private function _validate_singlesite()
124
{
125
+ $id = LiteSpeed_Cache_Config::OPID_CHECK_ADVANCEDCACHE ;
126
+ $this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
127
+
128
+ // Parse rewrite rule settings
129
+ $new_options = $this->_validate_rewrite_settings() ;
130
+ $this->_options = array_merge( $this->_options, $new_options ) ;
131
+
132
+ // Try to update rewrite rules
133
+ if ( ! defined( 'LITESPEED_NEW_OFF' ) ) {
134
+ // Only update needs to get error, for clear rules, can ignore for now
135
+ $res = LiteSpeed_Cache_Admin_Rules::get_instance()->update( $this->_options ) ;
136
+ if ( $res !== true ) {
137
+ if ( ! is_array( $res ) ) {
138
+ $this->_err[] = $res ;
139
}
140
+ else {
141
+ $this->_err = array_merge( $this->_err, $res ) ;
142
}
143
}
144
}
145
+ else {
146
+ LiteSpeed_Cache_Admin_Rules::get_instance()->clear_rules() ;
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Parses any changes made by the network admin on the network settings.
152
+ *
153
+ * @since 1.0.4
154
+ * @access public
155
+ */
156
+ public function validate_network_settings()
157
+ {
158
+ $input = array_map( 'LiteSpeed_Cache_Admin::cleanup_text', $_POST[ LiteSpeed_Cache_Config::OPTION_NAME ] ) ;
159
+ $this->_input = $input ;
160
161
+ $options = LiteSpeed_Cache_Config::get_instance()->get_site_options() ;
162
+
163
+ $id = LiteSpeed_Cache_Config::NETWORK_OPID_ENABLED ;
164
+ $network_enabled = self::parse_onoff( $this->_input, $id ) ;
165
+ if ( $options[ $id ] != $network_enabled ) {
166
+ $options[ $id ] = $network_enabled ;
167
+ if ( $network_enabled ) {
168
+ $ret = LiteSpeed_Cache_Config::wp_cache_var_setter( true ) ;
169
+ if ( $ret !== true ) {
170
+ $this->_err[] = $ret ;
171
+ }
172
}
173
+ else {
174
LiteSpeed_Cache_Purge::purge_all() ;
175
}
176
}
177
178
+ $id = LiteSpeed_Cache_Config::NETWORK_OPID_USE_PRIMARY ;
179
+ $orig_primary = $options[ $id ] ;
180
+ $options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
181
+ if ( $orig_primary != $options[ $id ] ) {
182
+ LiteSpeed_Cache_Purge::purge_all() ;
183
}
184
185
+ $id = LiteSpeed_Cache_Config::OPID_PURGE_ON_UPGRADE ;
186
+ $options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
187
188
+ $id = LiteSpeed_Cache_Config::OPID_CHECK_ADVANCEDCACHE ;
189
+ $options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
190
+
191
+ // Parse rewrite settings from input
192
+ $new_options = $this->_validate_rewrite_settings() ;
193
+ $options = array_merge( $options, $new_options ) ;
194
+
195
+ // Update htaccess
196
+ if ( $network_enabled ) {
197
+ $res = LiteSpeed_Cache_Admin_Rules::get_instance()->update( $options ) ;
198
+ if ( $res !== true ) {
199
+ if ( ! is_array( $res ) ) {
200
+ $this->_err[] = $res ;
201
+ }
202
+ else {
203
+ $this->_err = array_merge( $this->_err, $res ) ;
204
+ }
205
+ }
206
}
207
else {
208
+ // Need to set cachePublicOn in case subblogs turn on cache manually
209
+ LiteSpeed_Cache_Admin_Rules::get_instance()->insert_wrapper() ;
210
}
211
212
+ if ( ! empty( $this->_err ) ) {
213
+ LiteSpeed_Cache_Admin_Display::add_notice( LiteSpeed_Cache_Admin_Display::NOTICE_RED, $this->_err ) ;
214
+ return ;
215
}
216
217
+ LiteSpeed_Cache_Admin_Display::add_notice( LiteSpeed_Cache_Admin_Display::NOTICE_GREEN, __( 'Site options saved.', 'litespeed-cache' ) ) ;
218
+ update_site_option( LiteSpeed_Cache_Config::OPTION_NAME, $options ) ;
219
+ return $options ;
220
+ }
221
222
+ /**
223
+ * Validates the general settings.
224
+ *
225
+ * @since 1.0.12
226
+ * @access private
227
+ */
228
+ private function _validate_general()
229
+ {
230
+ // Cache enabled setting
231
+ $id = LiteSpeed_Cache_Config::OPID_ENABLED_RADIO ;
232
+ $this->_options[ $id ] = self::is_checked_radio( $this->_input[ $id ] ) ;
233
+
234
+ $enabled = $this->_options[ $id ] ;
235
+ // Use network setting
236
+ if( $enabled === LiteSpeed_Cache_Config::VAL_ON2 ) {
237
+ $enabled = is_multisite() ? defined( 'LITESPEED_NETWORK_ON' ) : true ; // Default to true
238
}
239
+
240
+ // Purge when disabled
241
+ if ( ! $enabled ) {
242
+ LiteSpeed_Cache_Purge::purge_all() ;
243
+ ! defined( 'LITESPEED_NEW_OFF' ) && define( 'LITESPEED_NEW_OFF', true ) ; // Latest status is off
244
}
245
else {
246
+ ! defined( 'LITESPEED_NEW_ON' ) && define( 'LITESPEED_NEW_ON', true ) ; // Latest status is on
247
}
248
249
+ // Status changed
250
+ if ( defined( 'LITESPEED_ON' ) xor $enabled ) {
251
+ define( 'LITESPEED_ON_CHANGED', true ) ;
252
}
253
+
254
+ // TTL check
255
+ $ids = array(
256
+ LiteSpeed_Cache_Config::OPID_PUBLIC_TTL => array( __( 'Default Public Cache', 'litespeed-cache' ), 30, $this->_max_int ),
257
+ LiteSpeed_Cache_Config::OPID_PRIVATE_TTL => array( __( 'Default Private Cache', 'litespeed-cache' ), 60, 3600 ),
258
+ LiteSpeed_Cache_Config::OPID_FRONT_PAGE_TTL => array( __( 'Default Front Page', 'litespeed-cache' ), 30, $this->_max_int ),
259
+ LiteSpeed_Cache_Config::OPID_FEED_TTL => array( __( 'Feed', 'litespeed-cache' ), 0, $this->_max_int, 30 ),
260
+ LiteSpeed_Cache_Config::OPID_404_TTL => array( __( '404', 'litespeed-cache' ), 0, $this->_max_int, 30 ),
261
+ LiteSpeed_Cache_Config::OPID_403_TTL => array( __( '403', 'litespeed-cache' ), 0, $this->_max_int, 30 ),
262
+ LiteSpeed_Cache_Config::OPID_500_TTL => array( __( '500', 'litespeed-cache' ), 0, $this->_max_int, 30 ),
263
+ ) ;
264
+ foreach ( $ids as $id => $v ) {
265
+ list( $desc, $min, $max ) = $v ;
266
+ if ( ! $this->_check_ttl( $this->_input, $id, $min, $max ) ) {
267
+ $this->_err[] = sprintf( $this->_err_msg_numeric, $desc, $min, $max ) ;
268
+ }
269
+ else {
270
+ if ( ! empty( $v[ 3 ] ) && $this->_input[ $id ] < $v[ 3 ] ) {
271
+ $this->_options[ $id ] = 0 ;
272
+ }
273
+ else {
274
+ $this->_options[ $id ] = $this->_input[ $id ] ;
275
+ }
276
+ }
277
}
278
279
}
283
*
284
* @since 1.1.6
285
* @access private
286
*/
287
+ private function _validate_cache()
288
{
289
+ $ids = array(
290
+ LiteSpeed_Cache_Config::OPID_CACHE_PRIV,
291
+ LiteSpeed_Cache_Config::OPID_CACHE_COMMENTER,
292
+ LiteSpeed_Cache_Config::OPID_CACHE_REST,
293
+ );
294
+ foreach ( $ids as $id ) {
295
+ $this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
296
+ }
297
298
$id = LiteSpeed_Cache_Config::OPID_CACHE_PAGE_LOGIN ;
299
+ $this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
300
+ if( ! $this->_options[ $id ] ) {
301
+ LiteSpeed_Cache_Purge::add( LiteSpeed_Cache_Tag::TYPE_LOGIN ) ;
302
+ }
303
+
304
+ $id = LiteSpeed_Cache_Config::OPID_CACHE_URI_PRIV ;
305
+ if ( isset( $this->_input[ $id ]) ) {
306
+ $this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ], 'relative' ) ;
307
}
308
}
309
312
*
313
* @since 1.0.12
314
* @access private
315
*/
316
+ private function _validate_purge()
317
{
318
$id = LiteSpeed_Cache_Config::OPID_PURGE_ON_UPGRADE ;
319
+ $this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
320
321
// get auto purge rules options
322
$pvals = array(
333
LiteSpeed_Cache_Config::PURGE_POST_TYPE,
334
) ;
335
$input_purge_options = array() ;
336
+ foreach ( $pvals as $v) {
337
+ $input_name = 'purge_' . $v ;
338
+ if ( self::parse_onoff( $this->_input, $input_name ) ) {
339
+ $input_purge_options[] = $v ;
340
}
341
}
342
sort( $input_purge_options ) ;
343
$purge_by_post = implode( '.', $input_purge_options ) ;
344
+ if ( $purge_by_post !== $this->_options[ LiteSpeed_Cache_Config::OPID_PURGE_BY_POST ] ) {
345
+ $this->_options[ LiteSpeed_Cache_Config::OPID_PURGE_BY_POST ] = $purge_by_post ;
346
}
347
348
// Filter scheduled purge URLs
349
$id = LiteSpeed_Cache_Config::OPID_TIMED_URLS ;
350
+ if ( isset( $this->_input[ $id ] ) ) {
351
+ $this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ], 'relative' ) ;
352
}
353
354
// Schduled Purge Time
355
$id = LiteSpeed_Cache_Config::OPID_TIMED_URLS_TIME ;
356
+ $this->_options[ $id ] = $this->_input[ $id ] ;
357
}
358
359
/**
361
*
362
* @since 1.0.12
363
* @access private
364
*/
365
+ private function _validate_exclude()
366
{
367
$id = LiteSpeed_Cache_Config::OPID_EXCLUDES_URI ;
368
+ if ( isset( $this->_input[ $id ] ) ) {
369
+ $this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ], 'relative' ) ;
370
+ }
371
+
372
+ $id = LiteSpeed_Cache_Config::OPID_EXCLUDES_QS ;
373
+ if ( isset( $this->_input[ $id ] ) ) {
374
+ $this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ] ) ;
375
}
376
377
$id = LiteSpeed_Cache_Config::OPID_EXCLUDES_CAT ;
378
+ $this->_options[ $id ] = '' ;
379
+ if ( isset( $this->_input[ $id ] ) ) {
380
$cat_ids = array() ;
381
+ $cats = explode( "\n", $this->_input[ $id ] ) ;
382
+ foreach ( $cats as $cat ) {
383
+ $cat_name = trim( $cat ) ;
384
if ( $cat_name == '' ) {
385
continue ;
386
}
387
+ $cat_id = get_cat_ID( $cat_name ) ;
388
if ( $cat_id == 0 ) {
389
+ $this->_err[] = LiteSpeed_Cache_Admin_Display::get_error( LiteSpeed_Cache_Admin_Error::E_SETTING_CAT, $cat_name ) ;
390
}
391
else {
392
$cat_ids[] = $cat_id ;
393
}
394
}
395
+ if ( ! empty( $cat_ids ) ) {
396
+ $this->_options[ $id ] = implode( ',', $cat_ids ) ;
397
}
398
}
399
400
$id = LiteSpeed_Cache_Config::OPID_EXCLUDES_TAG ;
401
+ $this->_options[ $id ] = '' ;
402
+ if ( isset( $this->_input[ $id ] ) ) {
403
$tag_ids = array() ;
404
+ $tags = explode( "\n", $this->_input[ $id ] ) ;
405
+ foreach ( $tags as $tag ) {
406
+ $tag_name = trim( $tag ) ;
407
if ( $tag_name == '' ) {
408
continue ;
409
}
410
+ $term = get_term_by( 'name', $tag_name, 'post_tag' ) ;
411
if ( $term == 0 ) {
412
+ $this->_err[] = LiteSpeed_Cache_Admin_Display::get_error( LiteSpeed_Cache_Admin_Error::E_SETTING_TAG, $tag_name ) ;
413
}
414
else {
415
$tag_ids[] = $term->term_id ;
416
}
417
}
418
+ if ( ! empty( $tag_ids ) ) {
419
+ $this->_options[ $id ] = implode( ',', $tag_ids ) ;
420
}
421
}
422
}
427
* @since 1.2.2
428
* @access private
429
*/
430
+ private function _validate_cdn()
431
{
432
$ids = array(
433
LiteSpeed_Cache_Config::OPID_CDN,
434
LiteSpeed_Cache_Config::OPID_CDN_INC_IMG,
435
LiteSpeed_Cache_Config::OPID_CDN_INC_CSS,
436
LiteSpeed_Cache_Config::OPID_CDN_INC_JS,
437
+ ) ;
438
foreach ( $ids as $id ) {
439
+ $this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
440
}
441
442
$id = LiteSpeed_Cache_Config::OPID_CDN_ORI ;
443
+ $this->_options[ $id ] = $this->_input[ $id ] ;
444
+ if ( $this->_options[ $id ] ) {
445
+ $tmp = parse_url( $this->_options[ $id ] ) ;
446
if ( ! empty( $tmp[ 'scheme' ] ) ) {
447
+ $this->_options[ $id ] = str_replace( $tmp[ 'scheme' ] . ':', '', $this->_options[ $id ] ) ;
448
}
449
}
450
451
$id = LiteSpeed_Cache_Config::OPID_CDN_URL ;
452
+ $this->_options[ $id ] = $this->_input[ $id ] ;
453
454
$ids = array(
455
LiteSpeed_Cache_Config::OPID_CDN_FILETYPE,
456
LiteSpeed_Cache_Config::OPID_CDN_EXCLUDE,
457
) ;
458
foreach ( $ids as $id ) {
459
+ $this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ] ) ;
460
}
461
}
462
463
/**
464
* Validates the optimize settings.
465
*
466
* @since 1.2.2
467
* @access private
468
*/
469
+ private function _validate_optimize()
470
{
471
$ids = array(
472
LiteSpeed_Cache_Config::OPID_CSS_MINIFY,
476
LiteSpeed_Cache_Config::OPID_JS_COMBINE,
477
LiteSpeed_Cache_Config::OPID_JS_HTTP2,
478
LiteSpeed_Cache_Config::OPID_HTML_MINIFY,
479
+ LiteSpeed_Cache_Config::OPID_OPTM_QS_RM,
480
+ LiteSpeed_Cache_Config::OPID_OPTM_GGFONTS_RM,
481
+ LiteSpeed_Cache_Config::OPID_OPTM_CSS_ASYNC,
482
+ LiteSpeed_Cache_Config::OPID_OPTM_JS_DEFER,
483
+ LiteSpeed_Cache_Config::OPID_OPTM_EMOJI_RM,
484
) ;
485
foreach ( $ids as $id ) {
486
+ $this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
487
}
488
489
$ids = array(
491
LiteSpeed_Cache_Config::OPID_JS_EXCLUDES,
492
) ;
493
foreach ( $ids as $id ) {
494
+ $this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ], 'uri' ) ;
495
}
496
497
$id = LiteSpeed_Cache_Config::OPID_OPTIMIZE_TTL ;
498
+ if ( ! $this->_check_ttl( $this->_input, $id, 3600 ) ) {
499
+ $this->_input[ $id ] = 3600 ;
500
}
501
+ $this->_options[ $id ] = $this->_input[ $id ] ;
502
503
+ // Update critical css
504
+ update_option( LiteSpeed_Cache_Config::ITEM_OPTM_CSS, $this->_input[ LiteSpeed_Cache_Config::ITEM_OPTM_CSS ] ) ;
505
}
506
507
/**
509
*
510
* @since 1.0.12
511
* @access private
512
*/
513
+ private function _validate_debug()
514
{
515
$id = LiteSpeed_Cache_Config::OPID_ADMIN_IPS ;
516
+ if ( isset( $this->_input[ $id ] ) ) {
517
+ $admin_ips = array_map( 'trim', explode( "\n", trim( $this->_input[ $id ] ) ) ) ;
518
+ $admin_ips = array_filter( $admin_ips ) ;
519
$has_err = false ;
520
if ( $admin_ips ) {
521
+ foreach ( $admin_ips as $ip ) {
522
+ if ( ! WP_Http::is_ip_address( $ip ) ) {
523
$has_err = true ;
524
break ;
525
}
526
}
527
}
528
+ $admin_ips = implode( "\n", $admin_ips ) ;
529
530
if ( $has_err ) {
531
+ $this->_err[] = LiteSpeed_Cache_Admin_Display::get_error( LiteSpeed_Cache_Admin_Error::E_SETTING_ADMIN_IP_INV ) ;
532
}
533
+ else {
534
+ $this->_options[ $id ] = $admin_ips ;
535
}
536
}
537
538
$id = LiteSpeed_Cache_Config::OPID_DEBUG ;
539
+ $this->_options[ $id ] = self::is_checked_radio( $this->_input[ $id ] ) ;
540
541
$id = LiteSpeed_Cache_Config::OPID_LOG_FILE_SIZE ;
542
+ if ( ! $this->_check_ttl( $this->_input, $id, 3, 3000 ) ) {
543
+ $this->_err[] = sprintf( $this->_err_msg_numeric, __( 'Log File Size Limit', 'litespeed-cache' ), 3, 3000 ) ;
544
}
545
else {
546
+ $this->_options[ $id ] = $this->_input[ $id ] ;
547
}
548
549
+ $ids = array(
550
+ LiteSpeed_Cache_Config::OPID_DEBUG_LEVEL,
551
+ LiteSpeed_Cache_Config::OPID_HEARTBEAT,
552
+ LiteSpeed_Cache_Config::OPID_DEBUG_COOKIE,
553
+ LiteSpeed_Cache_Config::OPID_COLLAPS_QS,
554
+ LiteSpeed_Cache_Config::OPID_LOG_FILTERS,
555
+ ) ;
556
+ foreach ( $ids as $id ) {
557
+ $this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
558
}
559
560
+ // Filters ignored
561
+ $ids = array(
562
+ LiteSpeed_Cache_Config::OPID_LOG_IGNORE_FILTERS,
563
+ LiteSpeed_Cache_Config::OPID_LOG_IGNORE_PART_FILTERS,
564
+ ) ;
565
+ foreach ( $ids as $id ) {
566
+ $this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ] ) ;
567
}
568
}
569
570
/**
572
*
573
* @since 1.0.12
574
* @access private
575
*/
576
+ private function _validate_crawler()
577
{
578
+ $ids = array(
579
+ LiteSpeed_Cache_Config::CRWL_POSTS,
580
+ LiteSpeed_Cache_Config::CRWL_PAGES,
581
+ LiteSpeed_Cache_Config::CRWL_CATS,
582
+ LiteSpeed_Cache_Config::CRWL_TAGS,
583
+ ) ;
584
+ foreach ( $ids as $id ) {
585
+ $this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
586
+ }
587
588
$id = LiteSpeed_Cache_Config::CRWL_EXCLUDES_CPT ;
589
+ if ( isset( $this->_input[ $id ] ) ) {
590
+ $arr = array_map( 'trim', explode( "\n", $this->_input[ $id ] ) ) ;
591
+ $arr = array_filter( $arr ) ;
592
+ $ori = array_diff( get_post_types( '', 'names' ), array( 'post', 'page' ) ) ;
593
+ $this->_options[ $id ] = implode( "\n", array_intersect( $arr, $ori ) ) ;
594
}
595
596
$id = LiteSpeed_Cache_Config::CRWL_ORDER_LINKS ;
597
+ if( ! isset( $this->_input[ $id ] ) || ! in_array( $this->_input[ $id ], array(
598
LiteSpeed_Cache_Config::CRWL_DATE_DESC,
599
LiteSpeed_Cache_Config::CRWL_DATE_ASC,
600
LiteSpeed_Cache_Config::CRWL_ALPHA_DESC,
601
LiteSpeed_Cache_Config::CRWL_ALPHA_ASC,
602
+ ) )
603
+ ) {
604
+ $this->_input[ $id ] = LiteSpeed_Cache_Config::CRWL_DATE_DESC ;
605
}
606
+ $this->_options[ $id ] = $this->_input[ $id ] ;
607
608
+ $ids = array(
609
+ LiteSpeed_Cache_Config::CRWL_USLEEP => array( __( 'Delay', 'litespeed-cache' ), 0, 30000 ),
610
+ LiteSpeed_Cache_Config::CRWL_RUN_DURATION => array( __( 'Run Duration', 'litespeed-cache' ), 0, $this->_max_int ),
611
+ LiteSpeed_Cache_Config::CRWL_RUN_INTERVAL => array( __( 'Cron Interval', 'litespeed-cache' ), 60, $this->_max_int ),
612
+ LiteSpeed_Cache_Config::CRWL_CRAWL_INTERVAL => array( __( 'Whole Interval', 'litespeed-cache' ), 0, $this->_max_int ),
613
+ LiteSpeed_Cache_Config::CRWL_THREADS => array( __( 'Threads', 'litespeed-cache' ), 1, 16 ),
614
+ ) ;
615
+ foreach ( $ids as $id => $v ) {
616
+ list( $desc, $min, $max ) = $v ;
617
+ if ( ! $this->_check_ttl( $this->_input, $id, $min, $max ) ) {
618
+ $this->_err[] = sprintf( $this->_err_msg_numeric, $desc, $min, $max ) ;
619
+ }
620
+ else {
621
+ $this->_options[ $id ] = $this->_input[ $id ] ;
622
+ }
623
}
624
625
+
626
+ $id = LiteSpeed_Cache_Config::CRWL_LOAD_LIMIT ;
627
+ $this->_options[ $id ] = $this->_input[ $id ] ;
628
+
629
+ $id = LiteSpeed_Cache_Config::CRWL_DOMAIN_IP ;
630
+ if ( ! empty( $this->_input[ $id ] ) && ! WP_Http::is_ip_address( $this->_input[ $id ] ) ) {
631
+ $this->_err[] = LiteSpeed_Cache_Admin_Display::get_error( LiteSpeed_Cache_Admin_Error::E_SETTING_SITE_IP, $this->_input[ $id ] ) ;
632
}
633
else {
634
+ $this->_options[ $id ] = $this->_input[ $id ] ;
635
}
636
637
+ $id = LiteSpeed_Cache_Config::CRWL_CUSTOM_SITEMAP ;
638
+ if ( ! empty( $this->_input[ $id ] ) && ( $err = $this->_validate_custom_sitemap( $this->_input[ $id ] ) ) !== true ) {
639
+ $this->_err[] = LiteSpeed_Cache_Admin_Display::get_error( $err, $this->_input[ $id ] ) ;
640
}
641
else {
642
+ $this->_options[ $id ] = $this->_input[ $id ] ;
643
}
644
645
+ }
646
+
647
+ /**
648
+ * Validates the custom sitemap settings.
649
+ *
650
+ * @since 1.1.1
651
+ * @access private
652
+ * @param string $url The sitemap url
653
+ */
654
+ private function _validate_custom_sitemap( $url )
655
+ {
656
+ return LiteSpeed_Cache_Crawler::get_instance()->parse_custom_sitemap( $url, false ) ;
657
+ }
658
+
659
+ /**
660
+ * Validates settings related to rewrite rules
661
+ *
662
+ * @since 1.3
663
+ * @access private
664
+ * @return array New options relate