<?php
session_write_close();
if (!defined('BASE_DIR')) {
    session_write_close();
    exit('Access denied!');
}
include BASE_DIR . 'includes/themes.php';

$urlParser = parse_url(BASE_URL);
header("Access-Control-Allow-Origin: {$urlParser['scheme']}://{$urlParser['host']}");
header('Access-Control-Allow-Credentials: true');

ob_start();
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <base href="<?php echo BASE_URL; ?>">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="noindex">

    <meta name="msapplication-TileColor" content="<?php echo $themeColor; ?>">
    <meta name="theme-color" content="<?php echo $themeColor; ?>">
    <meta name="apple-mobile-web-app-capable" content="yes">

    <link rel="manifest" href="manifest.webmanifest">
    <link rel="mask-icon" href="assets/img/maskable_icon.png" color="#ffffff">

    <link rel="shortcut icon" href="favicon.ico" type="image/ico">
    <link rel="apple-touch-icon" href="assets/img/apple-touch-icon.png">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="assets/img/apple-touch-icon-152x152.png">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="assets/img/apple-touch-icon-152x152-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="120x120" href="assets/img/apple-touch-icon-120x120.png">
    <link rel="apple-touch-icon-precomposed" sizes="120x120" href="assets/img/apple-touch-icon-120x120-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/img/apple-touch-icon-114x114.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/img/apple-touch-icon-72x72.png">
    <link rel="apple-touch-icon-precomposed" sizes="57x57" href="assets/img/apple-touch-icon-57x57.png">
    <link rel="apple-touch-icon-precomposed" href="assets/img/apple-touch-icon.png">
    <link rel="apple-touch-icon-precomposed" href="assets/img/apple-touch-icon-precomposed.png">

    <title><?php echo get_env('title') . ' - ' . sitename(); ?></title>

    <link rel="preconnect" href="//<?php echo $urlParser['host']; ?>">
    <link rel="preconnect" href="//cdn.jsdelivr.net">
    <link rel="preconnect" href="//cdnjs.cloudflare.com">
    <link rel="preconnect" href="//cdn.datatables.net">
    <link rel="preconnect" href="//www.gstatic.com">
    <link rel="preconnect" href="//fonts.gstatic.com">
    <link rel="preconnect" href="//www.googleapis.com">
    <link rel="preconnect" href="//www.googletagmanager.com">
    <link rel="preconnect" href="//www.google.com">
    <link rel="preconnect" href="//www.google-analytics.com">
    <link rel="preconnect" href="//googleusercontent.com">
    <link rel="preconnect" href="//lh3.googleusercontent.com">
    <link rel="preconnect" href="//drive-thirdparty.googleusercontent.com">
    <link rel="preconnect" href="//static.addtoany.com">

    <link rel="dns-prefetch" href="//<?php echo $urlParser['host']; ?>">
    <link rel="dns-prefetch" href="//cdn.jsdelivr.net">
    <link rel="dns-prefetch" href="//cdnjs.cloudflare.com">
    <link rel="dns-prefetch" href="//cdn.datatables.net">
    <link rel="dns-prefetch" href="//www.gstatic.com">
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link rel="dns-prefetch" href="//www.googleapis.com">
    <link rel="dns-prefetch" href="//www.googletagmanager.com">
    <link rel="dns-prefetch" href="//www.google.com">
    <link rel="dns-prefetch" href="//www.google-analytics.com">
    <link rel="dns-prefetch" href="//googleusercontent.com">
    <link rel="dns-prefetch" href="//lh3.googleusercontent.com">
    <link rel="dns-prefetch" href="//drive-thirdparty.googleusercontent.com">
    <link rel="dns-prefetch" href="//static.addtoany.com">

    <?php
    $cssLinks = $plugins->getBackendCSS(true);
    if ($cssLinks) {
        session_write_close();
        echo $cssLinks;
    }
    include BACKEND_THEME_PATH . DIRECTORY_SEPARATOR . 'styles.php';

    echo loadJsDelivrScript('jquery@latest', false);
    ?>
    <script src="assets/vendor/FormData.js"></script>
    <script>
        var $ = jQuery.noConflict(),
            baseURL = '<?php echo BASE_URL; ?>',
            imgCDNURL = '<?php echo $urlParser['host'] !== 'localhost' ? '//i1.wp.com/' . $urlParser['host'] . '/' : BASE_URL; ?>',
            adminURL = '<?php echo ADMIN_URL; ?>/',
            pluginsURL = '<?php echo BASE_URL; ?>plugins/',
            uRole = <?php echo isset($userLogin['role']) ? sanitize_int($userLogin['role']) : 1; ?>,
            vidHosts = <?php echo json_encode($hosting->supportedSites(), true); ?>,
            languages = <?php echo json_encode(array_values(language_list())); ?>,
            oldDBVersion = <?php echo intval(get_option('updated')); ?>,
            newDBVersion = <?php echo DB_VERSION; ?>;
    </script>
    <?php
    echo $widget->google_alaytics();
    echo $widget->GTM_head();
    ?>
</head>

<body class="bg-light mb-5">
    <?php echo $widget->GTM_body(); ?>
    <a class="sr-only sr-only-focusable" href="#main">Skip to main content</a>
    <div class="container-xl bg-white shadow rounded-bottom">
        <?php include BACKEND_THEME_PATH . DIRECTORY_SEPARATOR . 'nav.php'; ?>
        <main id="main" class="py-4" style="margin-top:56px">
