Skip to content

Commit ce75fdb

Browse files
v7.4-b9: Admin show filter value (#885)
Add admin overwrite to use filter value Add admin overwrite to use SERVER value Change display for text area settings
1 parent 887fc2b commit ce75fdb

6 files changed

Lines changed: 212 additions & 33 deletions

File tree

assets/css/litespeed.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,11 @@ button.litespeed-form-action:hover {
550550
max-width: 960px;
551551
}
552552

553+
.litespeed-desc-wrapper{
554+
display: inline-block;
555+
margin-left: 10px;
556+
}
557+
553558
/* inside stripped table */
554559
.litespeed-desc {
555560
font-size: 12px;
@@ -3193,6 +3198,11 @@ a.litespeed-redetect {
31933198
color: #a5caf2;
31943199
}
31953200

3201+
.litespeed-overwrite{
3202+
display: inline-block;
3203+
margin-left: 10px;
3204+
}
3205+
31963206
@media screen and (min-width: 1401px) {
31973207
.litespeed-postbox--quiccloud.litespeed-postbox .inside .litespeed-title {
31983208
padding-left: 20px;

src/admin-display.cls.php

Lines changed: 147 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,65 @@ class Admin_Display extends Base {
4646

4747
private $_btn_i = 0;
4848

49+
/*
50+
* List of settings with filters and return type.
51+
*
52+
* @since 7.4
53+
*/
54+
protected static $settings_filters = array(
55+
// Crawler - Blocklist
56+
'crawler-blocklist' => [
57+
'filter' => 'litespeed_crawler_disable_blocklist',
58+
'type' => 'boolean'
59+
],
60+
// Crawler - Settings
61+
self::O_CRAWLER_LOAD_LIMIT => [
62+
'filter' => [ Base::ENV_CRAWLER_LOAD_LIMIT_ENFORCE, Base::ENV_CRAWLER_LOAD_LIMIT ],
63+
'type' => 'input'
64+
],
65+
// Cache - ESI
66+
self::O_ESI_NONCE => [
67+
'filter' => 'litespeed_esi_nonces'
68+
],
69+
// Page Optimization - CSS
70+
'optm-ucss_per_pagetype' => [
71+
'filter' => 'litespeed_ucss_per_pagetype',
72+
'type' => 'boolean'
73+
],
74+
// Page Optimization - Media
75+
self::O_MEDIA_ADD_MISSING_SIZES => [
76+
'filter' => 'litespeed_media_ignore_remote_missing_sizes',
77+
'type' => 'boolean'
78+
],
79+
// Page Optimization - Media Exclude
80+
self::O_MEDIA_LAZY_EXC => [
81+
'filter' => 'litespeed_media_lazy_img_excludes'
82+
],
83+
// Page Optimization - Tunning
84+
self::O_OPTM_JS_DELAY_INC => [
85+
'filter' => 'litespeed_optm_js_delay_inc'
86+
],
87+
self::O_OPTM_JS_EXC => [
88+
'filter' => 'litespeed_optimize_js_excludes'
89+
],
90+
self::O_OPTM_JS_DEFER_EXC => [
91+
'filter' => 'litespeed_optm_js_defer_exc'
92+
],
93+
self::O_OPTM_GM_JS_EXC => [
94+
'filter' => 'litespeed_optm_gm_js_exc'
95+
],
96+
self::O_OPTM_EXC => [
97+
'filter' => 'litespeed_optm_uri_exc'
98+
],
99+
// Page Optimization - Tunning CSS
100+
self::O_OPTM_CSS_EXC => [
101+
'filter' => 'litespeed_optimize_css_excludes'
102+
],
103+
self::O_OPTM_UCSS_EXC => [
104+
'filter' => 'litespeed_ucss_exc'
105+
],
106+
);
107+
49108
/**
50109
* Initialize the class and set its properties.
51110
*
@@ -847,6 +906,22 @@ public function build_textarea( $id, $cols = false, $val = null ) {
847906
$cols = 80;
848907
}
849908

909+
$rows = $this->get_textarea_rows($val);
910+
911+
$this->enroll($id);
912+
913+
echo "<textarea name='$id' rows='$rows' cols='$cols'>" . esc_textarea($val) . '</textarea>';
914+
915+
$this->_check_overwritten($id);
916+
}
917+
918+
/**
919+
* Clalculate textarea rows
920+
*
921+
* @since 7.4
922+
* @access public
923+
*/
924+
function get_textarea_rows( $val ){
850925
$rows = 5;
851926
$lines = substr_count($val, "\n") + 2;
852927
if ($lines > $rows) {
@@ -856,11 +931,7 @@ public function build_textarea( $id, $cols = false, $val = null ) {
856931
$rows = 40;
857932
}
858933

859-
$this->enroll($id);
860-
861-
echo "<textarea name='$id' rows='$rows' cols='$cols'>" . esc_textarea($val) . '</textarea>';
862-
863-
$this->_check_overwritten($id);
934+
return $rows;
864935
}
865936

866937
/**
@@ -998,39 +1069,96 @@ private function _build_radio( $id, $val, $txt ) {
9981069
/**
9991070
* Show overwritten msg if there is a const defined
10001071
*
1001-
* @since 3.0
1072+
* @since 3.0
1073+
* @since 7.4 show value from filters. Added type parameter.
10021074
*/
10031075
protected function _check_overwritten( $id ) {
10041076
$const_val = $this->const_overwritten($id);
10051077
$primary_val = $this->primary_overwritten($id);
1006-
if ($const_val === null && $primary_val === null) {
1078+
$filter_val = $this->filter_overwritten($id);
1079+
$server_val = $this->server_overwritten($id);
1080+
1081+
if ($const_val === null && $primary_val === null && $filter_val === null && $server_val === null) {
10071082
return;
10081083
}
10091084

1085+
// Get value to display.
10101086
$val = $const_val !== null ? $const_val : $primary_val;
1087+
// If we have filter_val will set as new val
1088+
if( null !== $filter_val ){
1089+
$val = $filter_val;
1090+
}
1091+
// If we have server_val will set as new val
1092+
if( null !== $server_val ){
1093+
$val = $server_val;
1094+
}
10111095

1012-
$default = isset(self::$_default_options[$id]) ? self::$_default_options[$id] : self::$_default_site_options[$id];
1096+
// Get type(used for display purpose).
1097+
$type = isset(self::$settings_filters[$id]) && isset(self::$settings_filters[$id]['type']) ? self::$settings_filters[$id]['type'] : 'textarea';
1098+
if( ( null !== $const_val || null !== $primary_val ) && null === $filter_val){
1099+
$type = 'setting';
1100+
}
10131101

1014-
if (is_bool($default)) {
1102+
// Get default setting: if settings exist, use default setting, otherwise use filter/server value.
1103+
$default = '';
1104+
if( isset(self::$_default_options[$id]) || isset(self::$_default_site_options[$id]) ){
1105+
$default = isset(self::$_default_options[$id]) ? self::$_default_options[$id] : self::$_default_site_options[$id];
1106+
}
1107+
if( null !== $filter_val || null !== $server_val ){
1108+
$default = null !== $filter_val ? $filter_val : $server_val;
1109+
}
1110+
1111+
// Set value to display, will be a string.
1112+
if ( is_bool($default) ) {
10151113
$val = $val ? __('ON', 'litespeed-cache') : __('OFF', 'litespeed-cache');
10161114
} else {
1017-
if (is_array($default)) {
1115+
if ( (is_array($default) && is_array($val)) || is_array($val) ) {
10181116
$val = implode("\n", $val);
10191117
}
10201118
$val = esc_textarea($val);
10211119
}
1120+
1121+
// Show warning for all types except textarea.
1122+
if( 'textarea' !== $type ){
1123+
echo '<div class="litespeed-desc litespeed-warning litespeed-overwrite">⚠️ ';
10221124

1023-
echo '<div class="litespeed-desc litespeed-warning">⚠️ ';
1125+
if ($server_val !== null) {
1126+
// Show $_SERVER value.
1127+
echo __('This setting is overwritten by value from $_SERVER variable', 'litespeed-cache');
1128+
$val = '$_SERVER["'.$server_val[0].'"] = ' . $server_val[1];
1129+
}
1130+
else if ($filter_val !== null) {
1131+
// Show filter value.
1132+
echo __('This setting is overwritten by filter', 'litespeed-cache');
1133+
}
1134+
else if ($const_val !== null) {
1135+
// Show CONSTANT value.
1136+
printf(__('This setting is overwritten by the PHP constant %s', 'litespeed-cache'), '<code>' . Base::conf_const($id) . '</code>');
1137+
} elseif (is_multisite() ){
1138+
// Show multisite overwrite.
1139+
if( get_current_blog_id() != BLOG_ID_CURRENT_SITE && $this->conf(self::NETWORK_O_USE_PRIMARY)) {
1140+
echo __('This setting is overwritten by the primary site setting', 'litespeed-cache');
1141+
} else {
1142+
echo __('This setting is overwritten by the Network setting', 'litespeed-cache');
1143+
}
1144+
}
10241145

1025-
if ($const_val !== null) {
1026-
printf(__('This setting is overwritten by the PHP constant %s', 'litespeed-cache'), '<code>' . Base::conf_const($id) . '</code>');
1027-
} elseif (get_current_blog_id() != BLOG_ID_CURRENT_SITE && $this->conf(self::NETWORK_O_USE_PRIMARY)) {
1028-
echo __('This setting is overwritten by the primary site setting', 'litespeed-cache');
1029-
} else {
1030-
echo __('This setting is overwritten by the Network setting', 'litespeed-cache');
1146+
echo ', ' . sprintf(__('currently set to %s', 'litespeed-cache'), "<code>$val</code>") . '</div>';
1147+
} else if( 'textarea' === $type && null !== $filter_val ){
1148+
// Show warning for textarea.
1149+
// Textarea sizes.
1150+
$cols = 30;
1151+
$rows = $this->get_textarea_rows($val);
1152+
$rows_current_val = $this->get_textarea_rows( implode("\n", $this->conf($id, true)) );
1153+
// If filter rows is bigger than textarea size, equalize them.
1154+
if($rows > $rows_current_val) $rows = $rows_current_val;
1155+
?>
1156+
<div class="litespeed-desc-wrapper">
1157+
<div class="litespeed-desc"><?php echo __('Value from filter applied', 'litespeed-cache') ?>:</div>
1158+
<textarea readonly rows="<?php echo $rows; ?>" cols="<?php echo $cols; ?>"><?php echo $val; ?></textarea>
1159+
</div>
1160+
<?php
10311161
}
1032-
1033-
echo ', ' . sprintf(__('currently set to %s', 'litespeed-cache'), "<code>$val</code>") . '</div>';
10341162
}
10351163

10361164
/**

src/root.cls.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,46 @@ public function primary_overwritten( $id ) {
302302
return self::$_primary_options[$id];
303303
}
304304

305+
/**
306+
* Check if is overwritten by code filter
307+
*
308+
* @since 7.4
309+
*/
310+
public function filter_overwritten( $id ) {
311+
$cls_admin_display = Admin_Display::$settings_filters;
312+
// Check if filter name is set.
313+
if(!isset($cls_admin_display[$id]) || !isset($cls_admin_display[$id]['filter']) || is_array($cls_admin_display[$id]['filter']) ){ return null; }
314+
315+
$val_setting = $this->conf($id, true);
316+
// if setting not found
317+
if( null === $val_setting ){
318+
$val_setting = '';
319+
}
320+
321+
$val_filter = apply_filters($cls_admin_display[$id]['filter'], $val_setting );
322+
323+
// Return null if value is the same.
324+
return $val_setting === $val_filter ? null : $val_filter;
325+
}
326+
327+
/**
328+
* Check if is overwritten by SERVER variable
329+
*
330+
* @since 7.4
331+
*/
332+
public function server_overwritten( $id ) {
333+
$cls_admin_display = Admin_Display::$settings_filters;
334+
if(!isset($cls_admin_display[$id]['filter'])){ return null; }
335+
336+
if(!is_array($cls_admin_display[$id]['filter'])) $cls_admin_display[$id]['filter'] = array( $cls_admin_display[$id]['filter'] );
337+
338+
foreach( $cls_admin_display[$id]['filter'] as $variable ){
339+
if(isset($_SERVER[$variable])) return [ $variable , $_SERVER[$variable] ] ;
340+
}
341+
342+
return null;
343+
}
344+
305345
/**
306346
* Get the list of configured options for the blog.
307347
*

tpl/cache/settings-esi.tpl.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,17 @@
9393
<?php $this->title( $option_id ); ?>
9494
</th>
9595
<td>
96-
<div class="litespeed-row-flex">
97-
<div>
98-
<?php $this->build_textarea( $option_id ); ?>
99-
</div>
100-
<div class="litespeed-width-3-10">
101-
<p class="litespeed-desc">
102-
<?php echo esc_html__( 'The list will be merged with the predefined nonces in your local data file.', 'litespeed-cache' ); ?>
103-
<?php echo esc_html__( 'The latest data file is', 'litespeed-cache' ); ?>: <a href="https://github.com/litespeedtech/lscache_wp/blob/master/data/esi.nonces.txt" target="_blank">https://github.com/litespeedtech/lscache_wp/blob/master/data/esi.nonces.txt</a>
104-
<br><span class="litespeed-success">
105-
<?php echo esc_html__( 'API', 'litespeed-cache' ); ?>:
106-
<?php printf( esc_html__( 'Filter %s is supported.', 'litespeed-cache' ), '<code>litespeed_esi_nonces</code>' ); ?>
107-
</span>
108-
</p>
109-
</div>
96+
<div>
97+
<?php $this->build_textarea( $option_id ); ?>
11098
</div>
99+
<p class="litespeed-desc">
100+
<?php echo esc_html__( 'The list will be merged with the predefined nonces in your local data file.', 'litespeed-cache' ); ?>
101+
<?php echo esc_html__( 'The latest data file is', 'litespeed-cache' ); ?>: <a href="https://github.com/litespeedtech/lscache_wp/blob/master/data/esi.nonces.txt" target="_blank">https://github.com/litespeedtech/lscache_wp/blob/master/data/esi.nonces.txt</a>
102+
<br><span class="litespeed-success">
103+
<?php echo esc_html__( 'API', 'litespeed-cache' ); ?>:
104+
<?php printf( esc_html__( 'Filter %s is supported.', 'litespeed-cache' ), '<code>litespeed_esi_nonces</code>' ); ?>
105+
</span>
106+
</p>
111107
<div class="litespeed-desc">
112108
<?php echo esc_html__( 'The above nonces will be converted to ESI automatically.', 'litespeed-cache' ); ?>
113109
<?php Doc::one_per_line(); ?>

tpl/crawler/blacklist.tpl.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
$crawler_summary = Crawler::get_summary();
1414
$__map = Crawler_Map::cls();
15+
$__admin_display = Admin_Display::cls();
1516
$list = $__map->list_blacklist( 30 );
1617
$count = $__map->count_blacklist();
1718
$pagination = Utility::pagination( $count, 30 );
@@ -81,6 +82,7 @@
8182
?>
8283
</span>
8384
</p>
85+
<?php echo wp_kses_post( $__admin_display->_check_overwritten( 'crawler-blocklist' ) ); ?>
8486
<p>
8587
<i class="litespeed-dot litespeed-bg-default"></i> = <?php esc_html_e( 'Not blocklisted', 'litespeed-cache' ); ?><br>
8688
<i class="litespeed-dot litespeed-bg-warning"></i> = <?php esc_html_e( 'Blocklisted due to not cacheable', 'litespeed-cache' ); ?><br>

tpl/page_optm/settings_css.tpl.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
defined( 'WPINC' ) || exit;
1414

15+
$__admin_display = Admin_Display::cls();
1516
$css_summary = CSS::get_summary();
1617
$ucss_summary = UCSS::get_summary();
1718
$closest_server_ucss = Cloud::get_summary( 'server.' . Cloud::SVC_UCSS );
@@ -85,6 +86,8 @@
8586
<br />
8687
<font class="litespeed-success"><?php esc_html_e( 'API', 'litespeed-cache' ); ?>: <?php printf( esc_html__( 'Filter %s available for UCSS per page type generation.', 'litespeed-cache' ), '<code>add_filter( "litespeed_ucss_per_pagetype", "__return_true" );</code>' ); ?></font>
8788

89+
<?php echo wp_kses_post( $__admin_display->_check_overwritten( 'optm-ucss_per_pagetype' ) ); ?>
90+
8891
<?php if ( $this->conf( Base::O_OPTM_UCSS ) && ! $this->conf( Base::O_OPTM_CSS_COMB ) ) : ?>
8992
<br />
9093
<font class="litespeed-warning">

0 commit comments

Comments
 (0)