index.php 1.66 KB
Newer Older
1 2
<?php

3
require_once("../vendor/autoload.php");
4

5
require_once("../app/config.php");
6 7 8 9 10

// Retrieve instance of the framework
$f3 = Base::instance();

// Initialize CMS
11
$f3->config('../app/config.ini');
12 13 14 15 16 17 18 19 20 21 22

$f3->set('container', new LQDN\Container());

// Deal with sessions
$session = $f3->get('container')['session'];
$session->start();
if (!$session->has('csrf')) {
    $session->set('csrf', md5(rand()));
}
$f3->CSRF = $session->get('csrf');

okhin's avatar
okhin committed
23 24 25 26 27 28 29 30 31 32 33 34
// Initialisation éventuelle des messages
if (!$session->has('message')) {
    $session->set('message', []);
}

if (!$session->has('error')) {
    $session->set('error', []);
}

// Let's register the message tag
\Template::instance()->extend('message', 'MessageHelper::render');

35 36 37 38 39 40 41 42 43 44
// Debug
$f3->set('DEBUG', DEBUG);
$f3->set('ONERROR', function ($f3) {
    $logger = new Log('error.log');
    $logger->write($f3->get('ERROR.code') . ' - ' . $f3->get('ERROR.text'));
    $logger->write($f3->get('ERROR.trace'));

    // If there is any problem, replace the current csrf
    $csrf = md5(rand());
    $f3->CSRF = $csrf;
45 46

    // If neither error or message are set, define them
okhin's avatar
okhin committed
47
    if (!$f3->exists('SESSION.message')) {
48
        $f3->push('SESSION.message', '');
okhin's avatar
okhin committed
49 50
    }
    if (!$f3->exists('SESSION.error')) {
51
        $f3->push('SESSION.error', '');
okhin's avatar
okhin committed
52
    }
53 54 55 56 57 58
    $f3->get('container')['session']->set('csrf', $csrf);

    while (ob_get_level()) {
        ob_end_clean();
    }
    $f3->set('block_content', 'campaign/errors.html');
okhin's avatar
okhin committed
59
    echo \Template::instance()->render('base.html');
60 61 62 63 64 65 66 67
});

// Are we being invoked from CLI ?
if (php_sapi_name() == 'cli') {
    $f3->CLI = true;
}

// Define routes
68
$f3->config('../app/routes.ini');
69 70 71

// Execute application
$f3->run();