<?php
/**
 *
 * @package FENSE_BPVT
 */

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

class FENSE_BPVT_RUN extends FENSE_BPVT_RUN_BASE
{
	
	/**
	 * Applies the configured protection mode for a confirmed proxy IP.
	 *
	 * BUG 4 FIX: __PM_show_content previously checked (proxy == 'yes') → return null
	 * then added the header. This added the header only for CLEAN visitors.
	 * Correct logic: add header code only when the visitor IS a proxy.
	 */
	public function applyProtectionMode( $ignoreProxyState = false, $exclude = false ): void
	{
		if ( $exclude ) return;
		
		if ( !$this->isProxy() && !$ignoreProxyState ) {
			return;
		}
		
		FENSE_BPVT_FUN::cleanUP();
		
		switch ( $this->settings->protection_mode ) {
			case 'redirect':
				nocache_headers();
				wp_redirect( $this->settings->url ?: 'https://google.com' );
				exit;
			
			case 'show_content':
				// BUG 4 FIX: inject obfuscation code for PROXY visitors (was inverted).
				add_action( 'wp_head', 'FENSE_BPVT_header_code' );
				break;
			
			default: // 'message'
				$this->fun->get_main_template( ...$this->template );
		}
	}
	
	/** Applies referrer-domain block, calling wp_die() if matched. */
	public function applyReferrerBlock(): bool
	{
		if ( !$this->isReferrerBlocked() ) {
			return false;
		}
//		$this->fun->get_main_template( ...$this->template );
		$this->applyProtectionMode( true );
		return true; // unreachable after wp_die(), but satisfies static analysis
	}
}
