@@ -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 /**
0 commit comments