Plugin Directory


Ignore:
Timestamp:
10/04/2026 05:47:01 PM (3 weeks ago)
Author:
echoplugins
Message:

version 17.311.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • echo-knowledge-base/trunk/includes/admin/editor/class-epkb-frontend-editor.php

    r3627828 r3727663  
    515515
    516516                // 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 );
    518518                $orig_config = $config['orig_config'];
    519519                $new_config = $config['new_config'];
    … …  
    726726                                        if ( $article_id > 0 ) {
    727727                                                $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                                                }
    728731                                        }
    729732                                        if ( empty( $demo_article ) ) {
    … …  
    859862                }
    860863
     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
    861870                // use cache
    862871                static $cached_kb_config = null;
    … …  
    865874                }
    866875
    867                 $config = self::merge_new_and_old_kb_config( true, true );
     876                $config = self::merge_new_and_old_kb_config( true, true, true );
    868877                $new_config = $config['new_config'];
    869878
    … …  
    10561065        }
    10571066
    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 ) {
    10591068
    10601069                // use cache
    … …  
    10751084                        $new_config['general_typography']['font-family'] = $new_config['general_typography_font_family'] == 'Inherit' ? '' : $new_config['general_typography_font_family'];
    10761085                        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 );
    10771091                }
    10781092
    … …  
    11211135
    11221136                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;
    11231165        }
    11241166
    … …  
    12991341                return array(
    13001342                        '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'] ) ),
    13021344                        'link_css'                              => $link_css,
    13031345                        'link_css_rtl'                  => $link_css_rtl,
Note: See TracChangeset for help on using the changeset viewer.