<?php
/**
 * HappyFenceNG Total Enterprise Security Plugin
 * HAPPYWPRESS is a RazorVue Trademark.
 *
 * @package     HappyFenceNG
 * @developer   Simonluca Scillitani
 * @copyright   2025 RazorVue di Scillitani Simonluca
 * @link        https://razorvue.it
 * @author      RazorVue di Scillitani Simonluca
 * @brand       HappyWPress
 * @uri         https://happywpress.com
 * @set all
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**PHPCS -> code compliance: we put useful comments where needed.. */
class HappyFenceNGVRPF extends HappyFenceNGAVRoute {

	/**PHPCS -> code compliance: we put useful comments where needed.. */
	public function doRoute() {
		try {

			$nonce_save_settings = wp_create_nonce( 'happyfenceng_PF_save_settings' );
			$burn                = HappyFenceNGFailFast::setup();

			$params = array(
				'texts'  => array(
					'title'                            => esc_html__( 'Deep Filtering Settings', 'happyfenceng-total-enterprise-security' ),
					'description'                      => esc_html__( 'This module monitors the integrity of your content inputs by inspecting posts, options, and REST API requests in real time.', 'happyfenceng-total-enterprise-security' ),
					'description_1'                    => esc_html__( 'It actively blocks the injection of suspicious code — such as PHP tags, inline scripts, iframe exploits, and obfuscated payloads — at the moment they are saved.', 'happyfenceng-total-enterprise-security' ),
					'description_2'                    => esc_html__( 'Unlike traditional file scanners, this filter focuses on content-level threats injected via legitimate admin channels or REST interfaces.', 'happyfenceng-total-enterprise-security' ),
					'description_3'                    => esc_html__( 'WARNING!!! This set of filters are really aggressive and can break your site.', 'happyfenceng-total-enterprise-security' ),
					'description_4'                    => esc_html__( 'If you experience problem try selectively disable them to see what does not fit your configuration.', 'happyfenceng-total-enterprise-security' ),
					'filter_post_content'              => esc_html__( 'Filter post content (save_post)', 'happyfenceng-total-enterprise-security' ),
					'filter_post_content_description'  => esc_html__( 'Enable post content filtering to block dangerous PHP/JS code.', 'happyfenceng-total-enterprise-security' ),
					'filter_post_content_tooltip'      => esc_html__( 'Prevents attackers from hiding harmful code inside posts or pages when you save them.', 'happyfenceng-total-enterprise-security' ),
					'filter_option_update'             => esc_html__( 'Filter options update (update_option)', 'happyfenceng-total-enterprise-security' ),
					'filter_option_update_description' => esc_html__( 'Enable scanning of option values to block malicious code.', 'happyfenceng-total-enterprise-security' ),
					'filter_option_update_tooltip'     => esc_html__( 'If disabled, malicious code hidden in settings may go unnoticed.', 'happyfenceng-total-enterprise-security' ),
					'enable_rest_pre_dispatch_filter'  => esc_html__( 'Filter REST API input (rest_pre_dispatch)', 'happyfenceng-total-enterprise-security' ),
					'enable_rest_pre_dispatch_filter_description' => esc_html__( 'Enable REST API input filtering to block XSS and code injection.', 'happyfenceng-total-enterprise-security' ),
					'enable_rest_pre_dispatch_filter_tooltip' => esc_html__( 'If disabled, attackers may inject malicious code via REST API requests.', 'happyfenceng-total-enterprise-security' ),
					'feature_requires'                 => esc_html__( 'THIS FEATURE REQUIRES PRO OR BETTER', 'happyfenceng-total-enterprise-security' ),
					'save_settings'                    => esc_html__( 'Save Settings', 'happyfenceng-total-enterprise-security' ),
					'settings_saved'                   => esc_html__( 'Settings Saved', 'happyfenceng-total-enterprise-security' ),
					'error_saving_settings'            => esc_html__( 'Error saving settings', 'happyfenceng-total-enterprise-security' ),
				),
				'links'  => array(
					'happyfenceng_logo_url' => esc_url( HAPPYFENCENG_PLUGIN_URL . 'assets/images/happyfenceng-small.png' ),

				),
				'values' => array(
					'enable_post_filter'              => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PF->enable_post_filter, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'enable_update_option_filter'     => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PF->enable_update_option_filter, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'enable_rest_pre_dispatch_filter' => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PF->enable_rest_pre_dispatch_filter, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'checkbox_on'                     => HappyFenceNGPlaceholder::CHECKBOX_ON,
					'checkbox_off'                    => HappyFenceNGPlaceholder::CHECKBOX_OFF,
					'nonce'                           => $nonce_save_settings,
					'burnNonce'                       => $burn,
					'feature_enabled'                 => ( function_exists( 'htes_fs' ) && HappyFenceNGTR::is_in( static::class, array( HappyFenceNGTR::PREAMBLE ) ) ),

				),
			);

			ob_start();
			HappyFenceNGVControl::renderView( $params, 'pf' );
			// phpcs:ignore WordPress.Security.EscapeOutput
			echo ob_get_clean();

		} catch ( Throwable $e ) {
			HappyFenceNGLOGCORE::logcore(
				'HappyFenceNGVRPF - cannot render UI ' . $e->getMessage(),
				HappyFenceNGSyslogFacility::UI,
				HappyFenceNGSyslogSeverity::ERROR
			);
			ob_end_clean();
			HappyFenceNGCleaner::cleaner_oops();
		}
	}
}
