<?php
 
 /**
 * =============================================================================
 * @package         Blue Raven (Free Version)
 * @Plugin URI      https://enterrahost.com/plugins/blue-raven
 * 
 * @Author          EnterraHost
 * @Author URI      https://enterrahost.com
 * @License         GPL-2.0-or-later
 *  
 * @Copyright       (c) 2025 EnterraHost
 * @Contents        Plugin Tools > Verification
 *
 * =============================================================================
 * 
 * || INDEX:
 * ||   - BLUE RAVEN ADMIN TOOL VERIFICATIONS
 * || 
 * =============================================================================
 */

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

/*
============================================================
    BLUE RAVEN ADMIN TOOL VERIFICATIONS
============================================================
*/

/**
 * Class Blue_Raven_Admin_Tools_Verification
 *
 * This class is responsible for handling site verification within the Blue Raven
 * Admin Tools section of the WordPress administration area. It manages the display
 * and submission of verification tags for services like Google, Bing, and Pinterest.
 */
class Blue_Raven_Admin_Tools_Verification {

    /**
     * Renders the site verification settings page.
     */
    public function render() {
        self::load_tools_verification_template();
    }
    
    /**
     * Loads the template for the site verification settings.
     *
     * This private static method fetches existing verification codes and
     * their enabled states from the database, then outputs the HTML form
     * for managing Google, Bing, Facebook, and Ahrefs site verifications.
     *
     * @access private
     */
    private static function load_tools_verification_template() {
        
    ## =========== Load from the Database =========== ##

        global $wpdb;
        $verifications = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}BlueRavenValues WHERE setting LIKE %s",'%-site-verification%'), ARRAY_A);
        $verifications_by_setting = [];
        if (!empty($verifications)) foreach ($verifications as $row) { $verifications_by_setting[$row['setting']] = $row; }

    ## =========== HTML =========== ##
    
        ?>
            <div class='flex-sb'>
                <h3><?php esc_html_e('Site Verification', 'blue-raven'); ?></h3>
                <h4>
                    <?php esc_html_e('Need Help', 'blue-raven'); ?>
                    <a href="https://portal.enterrahost.com/knowledgebase/3/" target="_noopeing" style="margin-left: 8px;" title="<?php esc_attr_e('Learn more', 'blue-raven'); ?>">
                        <i class="fas fa-question-circle"></i>
                    </a>
                </h4>
            </div>
    
            <p class='enterra-highlight indent-one'>
                <?php esc_html_e('This meta tag is used for site ownership verification by search engines, allowing access to webmaster tools and indexing features.', 'blue-raven'); ?>
            </p>
    
            <section>
                <div style="margin: 20px 0;" class='border-bottom-white flex-right'>
                    <h4 class='no-margin-padding spacing-right text-center'><?php esc_html_e('Switch On Site Verification', 'blue-raven'); ?></h4>
                    <label class="switch">
                        <input type="checkbox" id="enable-site-verification"
                            <?php if (!empty($verifications_by_setting['overall-site-verification']) && isset($verifications_by_setting['overall-site-verification']['enabled']) && $verifications_by_setting['overall-site-verification']['enabled']) echo 'checked'; ?>>
                        <span class="slider"></span>
                    </label>
                </div>
            </section>
            <section class='spacing-bottom-large'>
                <h4 class='spacing-right text-center'><?php esc_html_e('Google Site Verification', 'blue-raven'); ?></h4>
                <p class='indent-one'><?php printf(
					// translators: %1$s and %2$s and %3$s are the emphised words in bold
                    esc_html__('To get your Google site verification code, go to Google Search Console and add your website as a new property. Choose the HTML tag verification method, and Google will generate a meta tag. From that tag, copy only the code between the quotation marks after "content=" not the entire tag. For example, if the tag is %1$s, you should copy just %2$s. Paste that code into the field below, enable %3$s. Then return to Search Console to click "Verify".', 'blue-raven'),
                    '<strong>meta name="google-site-verification" content="YourCodeHere"</strong>',
                    '<strong>YourCodeHere</strong>',
                    '<strong>' . esc_html__('Add Google Verification', 'blue-raven') . '</strong>'
                ); ?></p>
                <div class='flex-right row-down-right' style='margin-top: 3rem;'>
                    <div style="margin: 20px 0;" class='flex-left spacing-right'>
                        <label class='text-center' style='text-decoration: underline;'><h4 class='no-margin-padding spacing-right-small text-center'><a href='https://search.google.com/search-console' target="_noopeing"><?php esc_html_e('Google Code', 'blue-raven'); ?></a></h4></label>
                        <input type="text" name="google-key" placeholder="<?php esc_attr_e('KEY', 'blue-raven'); ?>" class="br-input" style="width:20rem;" id='google-key'
                            value="<?php echo !empty($verifications_by_setting['google-site-verification']) && isset($verifications_by_setting['google-site-verification']['value']) ? esc_attr($verifications_by_setting['google-site-verification']['value']) : ''; ?>">
                    </div>
                    <div style="margin: 20px 0;" class='flex-right toggle-text-width' >
                        <h4 class='no-margin-padding spacing-right text-center'><?php esc_html_e('Add Google Verification', 'blue-raven'); ?></h4>
                        <label class="switch">
                            <input type="checkbox" id="enable-google-verification"
                                <?php if (!empty($verifications_by_setting['google-site-verification']) && isset($verifications_by_setting['google-site-verification']['enabled']) && $verifications_by_setting['google-site-verification']['enabled']) echo 'checked'; ?>>
                            <span class="slider"></span>
                        </label>
                    </div>
                </div>
                <div style='height:1.2rem;'>
                    <p class='br-error' id='google-verification-error-message' style='text-align:right;'></p>
                </div>
            </section>
            <section class='spacing-bottom-large'>
                <h4 class='spacing-right text-center'><?php esc_html_e('Bing Site Verification', 'blue-raven'); ?></h4>
                <p class='indent-one'><?php printf(
					// translators: %1$s and %2$s and %3$s are the emphised words in bold
                    esc_html__('To get your Bing site verification code, go to Bing Webmaster Tools and add your website as a new site. Choose the HTML meta tag verification method, and Bing will generate a meta tag. From that tag, copy only the code between the quotation marks after "content=" not the entire tag. For example, if the tag is %1$s, you should copy just %2$s. Paste that code into the field below, enable %3$s. Then return to Bing Webmaster Tools and click "Verify".', 'blue-raven'),
                    '<strong>meta name="msvalidate.01" content="YourCodeHere"</strong>',
                    '<strong>YourCodeHere</strong>',
                    '<strong>' . esc_html__('Add Bing Verification', 'blue-raven') . '</strong>'
                ); ?></p>
                <div class='flex-right row-down-right' style='margin-top: 3rem;'>
                    <div style="margin: 20px 0;" class='flex-left spacing-right'>
                        <label class='text-center' style='text-decoration: underline;'><h4 class='no-margin-padding spacing-right-small text-center'><a href='https://www.bing.com/webmasters' target="_noopeing"><?php esc_html_e('Bing Code', 'blue-raven'); ?></a></h4></label>
                        <input type="text" name="bing-key" placeholder="<?php esc_attr_e('KEY', 'blue-raven'); ?>" class="br-input" style="width:20rem;" id='bing-key'
                            value="<?php echo !empty($verifications_by_setting['bing-site-verification']) && isset($verifications_by_setting['bing-site-verification']['value']) ? esc_attr($verifications_by_setting['bing-site-verification']['value']) : ''; ?>">
                    </div>
                    <div style="margin: 20px 0;" class='flex-right toggle-text-width'>
                        <h4 class='no-margin-padding spacing-right text-center'><?php esc_html_e('Add Bing Verification', 'blue-raven'); ?></h4>
                        <label class="switch">
                            <input type="checkbox" id="enable-bing-verification"
                                <?php if (!empty($verifications_by_setting['bing-site-verification']) && isset($verifications_by_setting['bing-site-verification']['enabled']) && $verifications_by_setting['bing-site-verification']['enabled']) echo 'checked'; ?>>
                            <span class="slider"></span>
                        </label>
                    </div>
                </div>
                <div style='height:1.2rem;'>
                    <p class='br-error' id='bing-verification-error-message' style='text-align:right;'></p>
                </div>
            </section>
            <section class='spacing-bottom-large'>
                <h4 class='spacing-right text-center'><?php esc_html_e('Facebook Site Verification (Meta)', 'blue-raven'); ?></h4>
                <p class='indent-one'><?php printf(
					// translators: %1$s and %2$s and %3$s are the emphised words in bold
                    esc_html__('To get your Facebook domain verification code, go to your Facebook Business Manager, open Brand Safety and select Domains. Add your domain and choose the Meta-tag Verification method. Facebook will provide a meta tag. From that tag, copy only the code between the quotation marks after "content=" not the entire tag. For example, if the tag is %1$s, you should copy just %2$s. Paste that code into the field below, enable %3$s. Then return to Facebook Business Manager and click "Verify".', 'blue-raven'),
                    '<strong>meta name="facebook-domain-verification" content="YourCodeHere"</strong>',
                    '<strong>YourCodeHere</strong>',
                    '<strong>' . esc_html__('Add Facebook Verification', 'blue-raven') . '</strong>'
                ); ?></p>
                <div class='flex-right row-down-right' style='margin-top: 3rem;'>
                    <div style="margin: 20px 0;" class='flex-left spacing-right'>
                        <label class='text-center' style='text-decoration: underline;'><h4 class='no-margin-padding spacing-right-small text-center'><a href='https://business.facebook.com' target="_noopeing"><?php esc_html_e('Facebook Code', 'blue-raven'); ?></a></h4></label>
                        <input type="text" name="facebook-key" placeholder="<?php esc_attr_e('KEY', 'blue-raven'); ?>" class="br-input" style="width:20rem;" id='facebook-key'
                            value="<?php echo !empty($verifications_by_setting['facebook-site-verification']) && isset($verifications_by_setting['facebook-site-verification']['value']) ? esc_attr($verifications_by_setting['facebook-site-verification']['value']) : ''; ?>">
                    </div>
                    <div style="margin: 20px 0;" class='flex-right toggle-text-width'>
                        <h4 class='no-margin-padding spacing-right text-center'><?php esc_html_e('Add Facebook Verification', 'blue-raven'); ?></h4>
                        <label class="switch">
                            <input type="checkbox" id="enable-facebook-verification"
                                <?php if (!empty($verifications_by_setting['facebook-site-verification']) && isset($verifications_by_setting['facebook-site-verification']['enabled']) && $verifications_by_setting['facebook-site-verification']['enabled']) echo 'checked'; ?>>
                            <span class="slider"></span>
                        </label>
                    </div>
                </div>
                <div style='height:1.2rem;'>
                    <p class='br-error' id='facebook-verification-error-message' style='text-align:right;'></p>
                </div>
            </section>
            <section class='spacing-bottom-large'>
                <h4 class='spacing-right text-center'><?php esc_html_e('Ahrefs Site Verification', 'blue-raven'); ?></h4>
                <p class='indent-one'><?php printf(
					// translators: %1$s and %2$s and %3$s are the emphised words in bold
                    esc_html__('To verify your domain with Ahrefs, go to your Ahrefs Dashboard and open Site Verification. Add your domain and choose the HTML tag verification method. Ahrefs will provide a meta tag. From that tag, copy only the code between the quotation marks after "content="—not the entire tag. For example, if the tag is %1$s, you should copy just %2$s. Paste this code into the field below, enable %3$s. Then return to Ahrefs and click "Verify".', 'blue-raven'),
                    '<strong>meta name="ahrefs-site-verification" content="YourVerificationCodeHere"</strong>',
                    '<strong>YourVerificationCodeHere</strong>',
                    '<strong>' . esc_html__('Ahrefs Verification', 'blue-raven') . '</strong>'
                ); ?></p>
                <div class='flex-right row-down-right' style='margin-top: 3rem;'>
                    <div style="margin: 20px 0;" class='flex-left spacing-right'>
                        <label class='text-center' style='text-decoration: underline;'><h4 class='no-margin-padding spacing-right-small text-center'><a href='' target="_noopeing"><?php esc_html_e('Ahrefs Code', 'blue-raven'); ?></a></h4></label>
                        <input type="text" name="ahref-key" placeholder="<?php esc_attr_e('KEY', 'blue-raven'); ?>" class="br-input" style="width:20rem;" id='ahref-key'
                            value="<?php echo !empty($verifications_by_setting['ahref-site-verification']) && isset($verifications_by_setting['ahref-site-verification']['value']) ? esc_attr($verifications_by_setting['ahref-site-verification']['value']) : ''; ?>">
                    </div>
                    <div style="margin: 20px 0;" class='flex-right toggle-text-width'>
                        <h4 class='no-margin-padding spacing-right text-center'><?php esc_html_e('Add AHREF Verification', 'blue-raven'); ?></h4>
                        <label class="switch">
                            <input type="checkbox" id="enable-ahref-verification"
                                <?php if (!empty($verifications_by_setting['ahref-site-verification']) && isset($verifications_by_setting['ahref-site-verification']['enabled']) && $verifications_by_setting['ahref-site-verification']['enabled']) echo 'checked'; ?>>
                            <span class="slider"></span>
                        </label>
                    </div>
                </div>
                <div style='height:1.2rem;'>
                    <p class='br-error' id='ahref-verification-error-message' style='text-align:right;'></p>
                </div>
            </section>
        <?php
    }
}
