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

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

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

			$params = array(
				'texts'  => array(
					'title'                                => esc_html__( 'API & Frontend Security Features', 'happyfenceng-total-enterprise-security' ),
					'block_rest_guests_title'              => esc_html__( 'REST API Protection', 'happyfenceng-total-enterprise-security' ),
					'block_rest_guests_description'        => esc_html__( 'Block REST API (guests)', 'happyfenceng-total-enterprise-security' ),
					'block_rest_guests_tooltip'            => esc_html__( 'THIS OPTION IS DISABLED IF PRIVACY MANAGEMENT IS ENABLED. Restricts access to the WordPress REST API for unauthenticated users (guests), helping to reduce exposure of public data and potential abuse.', 'happyfenceng-total-enterprise-security' ),
					'block_rest_users_title'               => esc_html__( 'Block REST /users', 'happyfenceng-total-enterprise-security' ),
					'block_rest_users_description'         => esc_html__( 'Remove user endpoint', 'happyfenceng-total-enterprise-security' ),
					'block_rest_users_tooltip'             => esc_html__( 'Removes the /wp-json/wp/v2/users REST API endpoint to prevent user enumeration and reduce the risk of targeted attacks on user accounts.', 'happyfenceng-total-enterprise-security' ),
					'remove_rest_links_title'              => esc_html__( 'Remove REST API links from HTML', 'happyfenceng-total-enterprise-security' ),
					'remove_rest_links_description'        => esc_html__( 'Clean HTML output', 'happyfenceng-total-enterprise-security' ),
					'remove_rest_links_tooltip'            => esc_html__( 'Removes REST API link tags from the HTML <head> to reduce metadata exposure and slightly improve page cleanliness and privacy.', 'happyfenceng-total-enterprise-security' ),
					'advanced_protection'                  => esc_html__( 'Advanced Frontend Protections', 'happyfenceng-total-enterprise-security' ),
					'login_obfuscation_title'              => esc_html__( 'Hide login error messages', 'happyfenceng-total-enterprise-security' ),
					'login_obfuscation_description'        => esc_html__( 'Always show generic login failure message', 'happyfenceng-total-enterprise-security' ),
					'login_obfuscation_tooltip'            => esc_html__( 'Replaces detailed login error messages with a generic one to prevent attackers from determining whether a username or password is incorrect.', 'happyfenceng-total-enterprise-security' ),
					'block_author_title'                   => esc_html__( 'Block ?author=1', 'happyfenceng-total-enterprise-security' ),
					'block_author_description'             => esc_html__( 'Redirect to homepage if not logged in', 'happyfenceng-total-enterprise-security' ),
					'block_author_tooltip'                 => esc_html__( 'Prevents user enumeration via the ?author=ID query by redirecting unauthenticated requests to the homepage, protecting author usernames from exposure.', 'happyfenceng-total-enterprise-security' ),
					'remove_x_pingback_title'              => esc_html__( 'Remove X-Pingback header', 'happyfenceng-total-enterprise-security' ),
					'remove_x_pingback_description'        => esc_html__( 'Remove header that reveals XML-RPC availability', 'happyfenceng-total-enterprise-security' ),
					'remove_x_pingback_tooltip'            => esc_html__( 'Removes the X-Pingback HTTP header to hide the availability of the XML-RPC service, reducing exposure to pingback-based attacks.', 'happyfenceng-total-enterprise-security' ),
					'disable_oembed_discovery_title'       => esc_html__( 'Disable oEmbed discovery', 'happyfenceng-total-enterprise-security' ),
					'disable_oembed_discovery_description' => esc_html__( 'Remove oEmbed discovery links from &lt;head&gt;', 'happyfenceng-total-enterprise-security' ),
					'disable_oembed_discovery_tooltip'     => esc_html__( 'Removes oEmbed discovery links and related headers from the HTML <head>, preventing external sites from embedding your content via the oEmbed protocol.', 'happyfenceng-total-enterprise-security' ),
					'block_xmlrpc_pingback_title'          => esc_html__( 'Block only pingback XML-RPC', 'happyfenceng-total-enterprise-security' ),
					'block_xmlrpc_pingback_description'    => esc_html__( 'Disable only the pingback.ping method (keep XML-RPC enabled)', 'happyfenceng-total-enterprise-security' ),
					'block_xmlrpc_pingback_tooltip'        => esc_html__( 'Block only ping-back.', '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(
					'block_rest_guests'        => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->REST->block_rest_guests, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'block_rest_users'         => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->REST->block_rest_users, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'remove_rest_links'        => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->REST->remove_rest_links, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'login_obfuscation'        => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->LOGIN->login_obfuscation, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'block_author'             => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->META->block_author, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'remove_x_pingback'        => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PINGBACK->remove_x_pingback, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'disable_oembed_discovery' => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->EMBED->disable_oembed_discovery, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
					'block_xmlrpc_pingback'    => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PINGBACK->block_xmlrpc_pingback, 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, 'pre' );
			// phpcs:ignore WordPress.Security.EscapeOutput
			echo ob_get_clean();

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