<?php

if (!defined('PARENT') || !isset($SETTINGS->id)) {
  include(PATH . 'control/system/headers/403.php');
  exit;
}

use Detection\MobileDetect;

/* LOAD INCLUDE FILES
---------------------------------------*/

mswFLCTR();
include(PATH . 'control/system/core/mm.php');
include(PATH . 'control/timezones.php');
include(PATH . 'control/currencies.php');
include(PATH . 'control/classes/class.accounts.php');
include(PATH . 'control/classes/system/class.page.php');
include(PATH . 'control/classes/system/class.datetime.php');
include(PATH . 'control/classes/system/class.parser.php');
include(PATH . 'control/classes/system/class.tags.php');
include(PATH . 'control/classes/system/class.mail.php');
include(PATH . 'control/classes/class.html.php');
include(PATH . 'control/classes/class.social.php');
include(PATH . 'control/classes/system/class.captcha.php');
include(PATH . 'control/classes/system/class.json.php');
include(PATH . 'control/classes/class.system.php');
include(PATH . 'control/classes/class.api.php');

/*
  INITIALISE CLASSES - PRE THEME
---------------------------------------*/

$DT              = new dt();
$SYS             = new mswsys();
$SCL             = new social();
$CPHA            = new captcha();
$SANTAGS         = new tags();
$DETECT          = new MobileDetect();
$SYS->settings   = $SETTINGS;
$SYS->dt         = $DT;
$SYS->social     = $SCL;
$SCL->settings   = $SETTINGS;
$DT->settings    = $SETTINGS;


/* THEME SWITCHER
---------------------------------------*/

include(PATH . 'control/theme-switcher.php');

/* CAPTCHA
   If all we want is the captcha, create it.
------------------------------------------------*/

if (property_exists($SETTINGS, 'captcha') && $SETTINGS->captcha == 'yes' && isset($_GET['load_c']) && CSRF_GET_VAL == 'yes') {
  $CPHA->c_var = (in_array($_GET['load_c'], array(
    'cpt_create','cpt_login')
  ) ? $_GET['load_c'] : 'cpt_create');
  $code = $CPHA->code();
  $CPHA->show($code);
}

/*
  INITIALISE CLASSES
---------------------------------------*/

$JSON            = new json();
$ACC             = new accounts();
$PRSR            = new parser();
$MAILR           = new mailr();
$HTML            = new html();
$API             = new api();
$MAILR->parser   = $PRSR;
$HTML->settings  = $SETTINGS;
$HTML->dt        = $DT;
$HTML->sys       = $SYS;
$HTML->ssn       = $SSN;
$ACC->settings   = $SETTINGS;
$ACC->dt         = $DT;
$ACC->sys        = $SYS;
$ACC->ssn        = $SSN;
$API->settings   = $SETTINGS;
$API->dt         = $DT;
$API->sys        = $SYS;
$API->loglang    = $apilog;
$API->json       = $JSON;

/* API DETECTION
---------------------------------------*/

if ($API->stream()) {
  // Destroy all sessions..
  $SSN->kill();
  define('AFF_API', 1);
  include(PATH . 'control/aff-api.php');
  exit;
}

/* LATTE CFG
---------------------------------------*/

$latte->setTempDirectory(PATH . THEME_FOLDER . '/cache/');
$latte->setLoader(new \Latte\Loaders\FileLoader(PATH . THEME_FOLDER));

?>