<?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 HappyFenceNGVRFUN extends HappyFenceNGAVRoute {

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

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

			$params = array(
				'texts'  => array(
					'title'                             => esc_html__( 'Basic Security Features', 'happyfenceng-total-enterprise-security' ),
					'sub_title_basic'                   => esc_html__( 'Basic Protections', 'happyfenceng-total-enterprise-security' ),
					'block_xml_rpc_title'               => esc_html__( 'Block XML-RPC', 'happyfenceng-total-enterprise-security' ),
					'block_xml_rpc_description'         => esc_html__( 'Disable xmlrpc.php access', 'happyfenceng-total-enterprise-security' ),
					'block_xml_rpc_tooltip'             => esc_html__( 'Disables access to xmlrpc.php to prevent abuse from bots or remote connections.', 'happyfenceng-total-enterprise-security' ),
					'remove_meta_generator_tag_title'   => esc_html__( 'Remove meta generator tag', 'happyfenceng-total-enterprise-security' ),
					'remove_meta_generator_tag_description' => esc_html__( 'Hide WordPress version in HTML', 'happyfenceng-total-enterprise-security' ),
					'remove_meta_generator_tag_tooltip' => esc_html__( 'Removes the meta tag that reveals the WordPress version. This helps reduce the risk of targeted attacks based on known vulnerabilities of specific versions.', 'happyfenceng-total-enterprise-security' ),
					'remove_embed_script_title'         => esc_html__( 'Disable wp-embed.js', 'happyfenceng-total-enterprise-security' ),
					'remove_embed_script_description'   => esc_html__( 'Prevent wp-embed.js from loading', 'happyfenceng-total-enterprise-security' ),
					'remove_embed_script_tooltip'       => esc_html__( 'Prevents WordPress from loading the wp-embed.js script on the frontend. This improves performance slightly and is useful if you don’t use embedded content from other WordPress sites.', 'happyfenceng-total-enterprise-security' ),

					'extended_protection_title'         => esc_html__( 'Extended Protections', 'happyfenceng-total-enterprise-security' ),
					'enable_custom_login_title'         => esc_html__( 'Enable custom login path', 'happyfenceng-total-enterprise-security' ),
					'enable_custom_login_description'   => esc_html__( 'Enable obfuscated custom login path', 'happyfenceng-total-enterprise-security' ),
					'enable_custom_login_tooltip'       => esc_html__( 'Enables a custom login path with an obfuscated URL to protect the WordPress login page from automated login attempts and brute-force attacks.', 'happyfenceng-total-enterprise-security' ),

					'custom_login_slug_title'           => esc_html__( 'Custom login URL slug (only https!)', 'happyfenceng-total-enterprise-security' ),
					'custom_login_slug_description'     => esc_html__( 'Set a custom login path, e.g. /my-secret-login. Leave empty to use default /wp-login.php', 'happyfenceng-total-enterprise-security' ),
					'custom_login_slug_tooltip'         => esc_html__( 'Allows you to define a custom login URL (e.g. /my-secret-login) to hide the default WordPress login page. If left empty, the default /wp-login.php will remain accessible. Remember that this requires https!', 'happyfenceng-total-enterprise-security' ),

					'generate_random_slug_title'        => esc_html__( 'Generate random login slug', 'happyfenceng-total-enterprise-security' ),
					'generate_random_slug_description'  => esc_html__( 'Automatically generate a random login slug', 'happyfenceng-total-enterprise-security' ),
					'generate_random_slug_tooltip'      => esc_html__( 'Generate a 50 character random custom login URL, improving protection against targeted attacks.', 'happyfenceng-total-enterprise-security' ),

					'disable_rss_feed_title'            => esc_html__( 'Disable RSS Feeds', 'happyfenceng-total-enterprise-security' ),
					'disable_rss_feed_description'      => esc_html__( 'Block access to all RSS feeds', 'happyfenceng-total-enterprise-security' ),
					'disable_rss_feed_tooltip'          => esc_html__( 'Disables all RSS and Atom feed endpoints to prevent content scraping, reduce server load, and limit exposure of site updates.', 'happyfenceng-total-enterprise-security' ),

					'disable_app_passwords_title'       => esc_html__( 'Disable Application Passwords', 'happyfenceng-total-enterprise-security' ),
					'disable_app_passwords_description' => esc_html__( 'Prevent the use of Application Passwords API (for REST access)', 'happyfenceng-total-enterprise-security' ),
					'disable_app_passwords_tooltip'     => esc_html__( 'Disables the Application Passwords feature in WordPress to block external apps and services from authenticating via the REST API using generated credentials.', 'happyfenceng-total-enterprise-security' ),

					'feature_requires'                  => esc_html__( 'THIS FEATURE IS FREE', 'happyfenceng-total-enterprise-security' ),
					'enable_filesystem_scan'            => esc_html__( 'Enable Filesystem Scan', '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(
					'block_xmlrpc'          => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->XMLRPC->block_xmlrpc, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'remove_meta_generator' => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->META->remove_meta_generator, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'remove_embed_script'   => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->EMBED->remove_embed_script, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'enable_custom_login'   => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->enable_custom_login, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'custom_login_slug'     => esc_attr( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->custom_login_slug, HappyFenceNGPlaceholder::EMPTY_STRING ) ),
					'generate_random_slug'  => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->generate_random_slug, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'disable_rss_feed'      => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->disable_rss_feed, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'disable_app_passwords' => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->disable_app_passwords, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),

					'checkbox_on'           => HappyFenceNGPlaceholder::CHECKBOX_ON,
					'checkbox_off'          => HappyFenceNGPlaceholder::CHECKBOX_OFF,
					'nonce'                 => $nonce_save_settings,
					'burnNonce'             => $burn,
					'feature_enabled'       => true,

				),
			);

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

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