<?php

// Send headers only when the output hasn't started yet
// Only output up to now should be debug dumps
if (headers_sent() === false) {
    header('X-Frame-Options: SAMEORIGIN');
    header('X-XSS-Protection: 1; mode=block');
    header('X-Content-Type-Options: nosniff');
    header('Strict-Transport-Security: max-age=31536000; includeSubdomains');
    header_remove('X-Powered-By');
}

if (!isset($seoadmin) && !defined('CMS_FALLBACK')) {
    $seoadmin = new Seo();
    $seoadmin->getSeoData();
    $page_meta['title'] = $seoadmin->data['title'];
    $page_meta['description'] = $seoadmin->data['description'];
}

// Handle errors
error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
ini_set('display_errors', (int)config('app.debug'));

if (config('app.debug') === true && class_exists(\Whoops\Run::class)) {
    $whoops = new \Whoops\Run;
    $whoops->pushHandler(php_sapi_name() === 'cli' ? new \Whoops\Handler\PlainTextHandler : new \Whoops\Handler\PrettyPageHandler);
    $whoops->register();
}

// define $_REQUEST indices for legacy admin checks
if (!isset($_REQUEST['edit'])) {
    $_REQUEST['edit'] = null;
}

if (!isset($_REQUEST['delete'])) {
    $_REQUEST['delete'] = null;
}

if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = null;
}

if (!isset($_REQUEST['message'])) {
    $_REQUEST['message'] = null;
}



if (interface_exists(\Mtc\Members\Contracts\MemberModel::class)) {
    $member_id = $_SESSION[\Mtc\Members\Member::SESSION_KEY] ?? null;
    $member = \Illuminate\Support\Facades\App::make(\Mtc\Members\Contracts\MemberModel::class)->find($member_id);
    app('twig')->addGlobal('member', $member);
}

(new \Mtc\AdminGoogle2fa\Support\LegacyHelper())->check2FAAuthenticated();