<?php
/**
 * HappyFenceNG Total Enterprise Security Plugin
 * HAPPYWPRISS 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       HappyWPRIss
 * @uri         https://happywPRIss.com
 * @set all
 */

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

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

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

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

			$params = array(
				'texts'  => array(
					'title'                             => esc_html__( 'UploadGuard Settings', 'happyfenceng-total-enterprise-security' ),
					'description_1'                     => esc_html__( 'In this page you can select which suspicious query filters activate to improve your WP security. If unsure, we strongly suggest to select all.', 'happyfenceng-total-enterprise-security' ),
					'description_2'                     => esc_html__( 'UploadGuard intercepts file uploads in real time and blocks potentially dangerous files before they are saved.', 'happyfenceng-total-enterprise-security' ),
					'description_3'                     => esc_html__( 'It uses advanced heuristics to detect malicious payloads, reverse shells, disguised PHP files, and suspicious Base64-encoded content.', 'happyfenceng-total-enterprise-security' ),
					'description_4'                     => esc_html__( 'You can define a custom allowlist of file extensions, and UploadGuard will automatically block all others, including executables and scripts.', 'happyfenceng-total-enterprise-security' ),
					'enable_guard_title'                => esc_html__( 'Enable Upload Guard', 'happyfenceng-total-enterprise-security' ),
					'enable_guard_description'          => esc_html__( 'Enable Upload Guard protection on uploaded files.', 'happyfenceng-total-enterprise-security' ),
					'enable_guard_tooltip'              => esc_html__( 'By enabling this guard all the uploads will be intercepted and filtered.', 'happyfenceng-total-enterprise-security' ),
					'allowed_upload_extensions_title'   => esc_html__( 'Allowed File Extensions', 'happyfenceng-total-enterprise-security' ),
					'allowed_upload_extensions_description' => esc_html__( 'Comma-separated list of allowed file extensions (e.g., png,jpg,gif). Files with other extensions will be blocked.', 'happyfenceng-total-enterprise-security' ),
					'allowed_upload_extensions_tooltip' => esc_html__( 'The extensions that you specify here will be granted during the control.', 'happyfenceng-total-enterprise-security' ),

					'feature_requires'                  => esc_html__( 'THIS FEATURE REQUIRES ENTERPRISE', '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_guard'              => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->UG->enable_guard, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'allowed_upload_extensions' => esc_attr( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->UG->allowed_upload_extensions, HappyFenceNGMulti::_ALLOWED_UPLOAD_EXTENSIONS ) ),

					'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, 'upg' );
			// phpcs:ignore WordPress.Security.EscapeOutput
			echo ob_get_clean();

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