<commit_before><?php
/**
 * init.inc.php
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 * @see https://www.elabftw.net Official website
 * @license AGPL-3.0
 */
namespace Elabftw\Elabftw;

use Exception;

/**
 * This must be included on top of every page.
 * It loads the config file, connects to the database,
 * includes functions and locale, tries to update the db schema and redirects anonymous visitors.
 */
try {
    if (!isset($_SESSION)) {
        session_start();
    }

    // add check for php version here also
    if (!function_exists('version_compare') || version_compare(PHP_VERSION, '5.6', '<')) {
        $message = "Your version of PHP isn't recent enough. Please update your php version to at least 5.6";
        throw new Exception($message);
    }

    // load the config file with info to connect to DB
    $configFilePath = dirname(dirname(__FILE__)) . '/config.php';
    // redirect to install page if the config file is not here
    if (!is_readable($configFilePath)) {
        header('Location: install');
        throw new Exception('Redirecting to install folder');
    }

    require_once $configFilePath;

    require_once ELAB_ROOT . 'vendor/autoload.php';

    $Update = new Update(new Config);

    // i18n (gettext)
    if (isset($_SESSION['auth'])) {
        $Users = new Users($_SESSION['userid']);
        $locale = $Users->userData['lang'] . '.utf8';
    } else {
        // this will throw an exception if the SQL structure is not imported yet
        // so we redirect to the install folder
        try {
            $locale = $Update->Config->configArr['lang'] . '.utf8';
        } catch (Exception $e) {
            header('Location: install');
            throw new Exception('Redirecting to install folder');
        }
    }
    $domain = 'messages';
    putenv("LC_ALL=$locale");
    $res = setlocale(LC_ALL, $locale);
    bindtextdomain($domain, ELAB_ROOT . "app/locale");
    textdomain($domain);
    // END i18n

    // TWIG
    $loader = new \Twig_Loader_Filesystem(ELAB_ROOT . 'app/tpl');
    $twig = new \Twig_Environment($loader);
    $cache = ELAB_ROOT . 'uploads/tmp';
    $options = array();

    // enable cache if not in debug (dev) mode
    if (!$Update->Config->configArr['debug']) {
        $options = array('cache' => $cache);
    }
    $twig = new \Twig_Environment($loader, $options);

    // custom twig filters |msg and |kdate
    $filterOptions = array('is_safe' => array('html'));
    $msgFilter = new \Twig_SimpleFilter('msg', '\Elabftw\Elabftw\Tools::displayMessage', $filterOptions);
    $dateFilter = new \Twig_SimpleFilter('kdate', '\Elabftw\Elabftw\Tools::formatDate', $filterOptions);
    $twig->addFilter($msgFilter);
    $twig->addFilter($dateFilter);<commit_msg>fix redirection to install folder upon installation (thx Yohann-Simon)<commit_after><?php
/**
 * init.inc.php
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 * @see https://www.elabftw.net Official website
 * @license AGPL-3.0
 */
namespace Elabftw\Elabftw;

use Exception;

/**
 * This must be included on top of every page.
 * It loads the config file, connects to the database,
 * includes functions and locale, tries to update the db schema and redirects anonymous visitors.
 */
try {
    if (!isset($_SESSION)) {
        session_start();
    }

    // add check for php version here also
    if (!function_exists('version_compare') || version_compare(PHP_VERSION, '5.6', '<')) {
        $message = "Your version of PHP isn't recent enough. Please update your php version to at least 5.6";
        throw new Exception($message);
    }

    // load the config file with info to connect to DB
    $configFilePath = dirname(dirname(__FILE__)) . '/config.php';
    // redirect to install page if the config file is not here
    if (!is_readable($configFilePath)) {
        header('Location: install');
        throw new Exception('Redirecting to install folder');
    }

    require_once $configFilePath;

    require_once ELAB_ROOT . 'vendor/autoload.php';

    // this will throw an exception if the SQL structure is not imported yet
    // so we redirect to the install folder
    try {
        $Update = new Update(new Config);
    } catch (Exception $e) {
        header('Location: install');
        throw new Exception('Redirecting to install folder');
    }

    // i18n (gettext)
    if (isset($_SESSION['auth'])) {
        $Users = new Users($_SESSION['userid']);
        $locale = $Users->userData['lang'] . '.utf8';
    } else {
        $locale = $Update->Config->configArr['lang'] . '.utf8';
    }
    $domain = 'messages';
    putenv("LC_ALL=$locale");
    $res = setlocale(LC_ALL, $locale);
    bindtextdomain($domain, ELAB_ROOT . "app/locale");
    textdomain($domain);
    // END i18n

    // TWIG
    $loader = new \Twig_Loader_Filesystem(ELAB_ROOT . 'app/tpl');
    $twig = new \Twig_Environment($loader);
    $cache = ELAB_ROOT . 'uploads/tmp';
    $options = array();

    // enable cache if not in debug (dev) mode
    if (!$Update->Config->configArr['debug']) {
        $options = array('cache' => $cache);
    }
    $twig = new \Twig_Environment($loader, $options);

    // custom twig filters |msg and |kdate
    $filterOptions = array('is_safe' => array('html'));
    $msgFilter = new \Twig_SimpleFilter('msg', '\Elabftw\Elabftw\Tools::displayMessage', $filterOptions);
    $dateFilter = new \Twig_SimpleFilter('kdate', '\Elabftw\Elabftw\Tools::formatDate', $filterOptions);
    $twig->addFilter($msgFilter);
    $twig->addFilter($dateFilter);
{'fraction_non_alphanumeric': 0.14378730330982095, 'fraction_numerical': 0.0057876650388858746, 'mean_word_length': 3.0602055800293684, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '59800', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1653, 'n_words': 481}