Changeset 3727663 for echo-knowledge-base/trunk/includes/admin/editor/class-epkb-frontend-editor.php
- Timestamp:
- 10/04/2026 05:47:01 PM (3 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
echo-knowledge-base/trunk/includes/admin/editor/class-epkb-frontend-editor.php
r3627828 r3727663 515 515 516 516 // do not use the self::update_module_position() here because on preview the rows numbers in HTML remain original 517 $config = self::merge_new_and_old_kb_config( false );517 $config = self::merge_new_and_old_kb_config( false, false, true ); 518 518 $orig_config = $config['orig_config']; 519 519 $new_config = $config['new_config']; … … 726 726 if ( $article_id > 0 ) { 727 727 $demo_article = get_post( $article_id ); 728 if ( $demo_article && ! EPKB_KB_Handler::is_kb_post_type( $demo_article->post_type ) ) { 729 $demo_article = null; 730 } 728 731 } 729 732 if ( empty( $demo_article ) ) { … … 859 862 } 860 863 864 // the preview form is posted by the Frontend Editor itself; the nonce stops a crafted link from injecting config into a logged-in user's page 865 $nonce = EPKB_Utilities::post( '_wpnonce_epkb_ajax_action' ); 866 if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, '_wpnonce_epkb_ajax_action' ) ) { 867 return $kb_config; 868 } 869 861 870 // use cache 862 871 static $cached_kb_config = null; … … 865 874 } 866 875 867 $config = self::merge_new_and_old_kb_config( true, true );876 $config = self::merge_new_and_old_kb_config( true, true, true ); 868 877 $new_config = $config['new_config']; 869 878 … … 1056 1065 } 1057 1066 1058 private static function merge_new_and_old_kb_config( $merge_module_position=true, $page_reload=false ) {1067 private static function merge_new_and_old_kb_config( $merge_module_position=true, $page_reload=false, $is_preview=false ) { 1059 1068 1060 1069 // use cache … … 1075 1084 $new_config['general_typography']['font-family'] = $new_config['general_typography_font_family'] == 'Inherit' ? '' : $new_config['general_typography_font_family']; 1076 1085 unset( $new_config['general_typography_font_family'] ); 1086 } 1087 1088 // saves are validated by update_kb_configuration() which reports errors to the user; previews render unsaved values and must filter them here 1089 if ( $is_preview ) { 1090 $new_config = self::sanitize_preview_config( $kb_id, $new_config ); 1077 1091 } 1078 1092 … … 1121 1135 1122 1136 return $cached_kb_config; 1137 } 1138 1139 /** 1140 * Preview config arrives unsanitized from the browser and is rendered into inline CSS and templates; filter it with the same specs used on save. 1141 * Fields unknown to the specs are UI-only helpers (e.g. nav_sidebar_left, toc_content) and are reduced to plain text. 1142 * @param int $kb_id 1143 * @param array $new_config 1144 * @return array 1145 */ 1146 private static function sanitize_preview_config( $kb_id, $new_config ) { 1147 1148 $field_specs = EPKB_Core_Utilities::retrieve_all_kb_specs( $kb_id ); 1149 if ( empty( $field_specs ) ) { 1150 return []; 1151 } 1152 1153 $spec_fields = array_intersect_key( $new_config, $field_specs ); 1154 $sanitized_config = empty( $spec_fields ) ? [] : ( new EPKB_Input_Filter() )->validate_and_sanitize_specs( $spec_fields, $field_specs ); 1155 if ( is_wp_error( $sanitized_config ) ) { 1156 EPKB_Logging::add_log( 'Invalid Frontend Editor preview config', $kb_id, $sanitized_config ); 1157 $sanitized_config = []; 1158 } 1159 1160 foreach ( array_diff_key( $new_config, $field_specs ) as $key => $value ) { 1161 $sanitized_config[ sanitize_key( $key ) ] = is_array( $value ) ? array_map( 'sanitize_text_field', $value ) : sanitize_text_field( $value ); 1162 } 1163 1164 return $sanitized_config; 1123 1165 } 1124 1166 … … 1299 1341 return array( 1300 1342 'inline_styles' => EPKB_Utilities::minify_css( $inline_styles ), 1301 'custom_inline_styles' => $kb_page_type != 'main-page' || empty( $new_config['epkb_ml_custom_css'] ) ? '' : EPKB_Utilities::minify_css( $new_config['epkb_ml_custom_css']),1343 'custom_inline_styles' => $kb_page_type != 'main-page' || empty( $new_config['epkb_ml_custom_css'] ) ? '' : EPKB_Utilities::minify_css( strip_tags( $new_config['epkb_ml_custom_css'] ) ), 1302 1344 'link_css' => $link_css, 1303 1345 'link_css_rtl' => $link_css_rtl,
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)