<commit_before><?php
if (!defined('DOCUMENT_ROOT')) die('Access denied');

require 'vendor/autoload.php';

use Monolog\Logger;
use Monolog\Handler\SyslogHandler;

/**
 * Error Handler...
 */
function systemErrorHandler ( $errno , $errstr , $errfile ,  $errline , $errcontext=null ) 
{
    $log = new Logger('movim');
    $log->pushHandler(new SyslogHandler('movim'));
    $log->addError($errstr);
    return false;
}

/**
 * Manage boot order
 */
class Bootstrap {
    function boot() {
        //define all needed constants
        $this->setContants();

        require_once(SYSTEM_PATH . "Conf.php");
        
        mb_internal_encoding("UTF-8");

        //First thing to do, define error management (in case of error forward)
        $this->setLogs();
        
        //Check if vital system need is OK
        $this->checkSystem();

        $this->setBrowserSupport();
        
        $this->loadSystem();
        $this->loadCommonLibraries();
        $this->loadDispatcher();
        $this->loadHelpers();
        
        $this->setTimezone();
        
        $loadmodlsuccess = $this->loadModl();

        $this->loadMoxl();
        
        if($loadmodlsuccess) {
            $this->startingSession();
        } else {
            throw new Exception('Error loading Modl');
        }
    }
    private function checkSystem() {
        $listWritableFile = array(
            DOCUMENT_ROOT.'/log/logger.log',
            DOCUMENT_ROOT.'/log/php.log',
            DOCUMENT_ROOT.'/cache/test.tmp',
        );
        $errors=array();
        
        if(!is_writable(DOCUMENT_ROOT))
            $errors[] = 'We\'re unable to write to folder '.DOCUMENT_ROOT.': check rights';
        else {
            if(!file_exists(DOCUMENT_ROOT.'/cache') && !@mkdir(DOCUMENT_ROOT.'/cache')) {
                $errors[] = 'Couldn\'t create directory cache';
            }
            if(!file_exists(DOCUMENT_ROOT.'/log') && !@mkdir(DOCUMENT_ROOT.'/log')) {
                $errors[] = 'Couldn\'t create directory log';
            }
            if(!file_exists(DOCUMENT_ROOT.'/config') && !@mkdir(DOCUMENT_ROOT.'/config')) {
                $errors[] = 'Couldn\'t create directory config';
            }
            if(!file_exists(DOCUMENT_ROOT.'/users') && !@mkdir(DOCUMENT_ROOT.'/users')) {
                $errors[] = 'Couldn\'t create directory users';
            } else {
                touch(DOCUMENT_ROOT.'/users/index.html');
            }
        }
        
        foreach($listWritableFile as $fileName) {
            if (!file_exists($fileName)) {
                if (touch($fileName) !== true) {
                    $errors[] = 'We\'re unable to write to '.$fileName.': check rights';
                } 
            }else if (is_writable($fileName) !== true) {
                $errors[] = 'We\'re unable to write to file '.$fileName.': check rights';
            }
        }
        if (!function_exists('json_decode')) {
             $errors[] = 'You need to install php5-json that\'s not seems to be installed';
        }
        if (count($errors)) {
            throw new Exception(implode("\n<br />",$errors));
        }
    }
    private function setContants() {
        define('APP_TITLE',     'Movim');
        define('APP_NAME',      'movim');
        define('APP_VERSION',   $this->getVersion());
        define('BASE_URI',      $this->getBaseUri());
        define('CACHE_URI',     $this->getBaseUri() . 'cache/');
        
        define('THEMES_PATH',   DOCUMENT_ROOT . '/themes/');
        define('USERS_PATH',    DOCUMENT_ROOT . '/users/');
        define('APP_PATH',      DOCUMENT_ROOT . '/app/');
        define('SYSTEM_PATH',   DOCUMENT_ROOT . '/system/');
        define('LIB_PATH',      DOCUMENT_ROOT . '/lib/');
        define('LOCALES_PATH',  DOCUMENT_ROOT . '/locales/');
        define('CACHE_PATH',    DOCUMENT_ROOT . '/cache/');
        define('LOG_PATH',      DOCUMENT_ROOT . '/log/');
        
        define('VIEWS_PATH',    DOCUMENT_ROOT . '/app/views/');
        define('HELPERS_PATH',  DOCUMENT_ROOT . '/app/helpers/');
        
        if (!defined('DOCTYPE')) {
            define('DOCTYPE','text/html');
        }
    }

    private function getVersion() {
        $file = "VERSION";
        if($f = fopen(DOCUMENT_ROOT.'/'.$file, 'r')) {
            return trim(fgets($f));
        }
    }
    
    private function getBaseUri() {
        $dirname = dirname($_SERVER['PHP_SELF']);
        $path = (($dirname == DIRECTORY_SEPARATOR) ? '' : $dirname).'/';
        // Determining the protocol to use.
        $uri = "http://";
        if((
            isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "") 
        || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https")) {
            $uri = 'https://';
        }

        if($path == "") {
            $uri .= $_SERVER['HTTP_HOST'] ;
        } else {
            $uri .= str_replace('//', '/', $_SERVER['HTTP_HOST'] . $path);
        }

        $uri = str_replace('jajax.php', '', $uri);
        
        return $uri;
    }
    
    private function loadSystem() {
        // Loads up all system libraries.
        require_once(SYSTEM_PATH . "/i18n/i18n.php");

        require_once(SYSTEM_PATH . "Session.php");
        require_once(SYSTEM_PATH . "Sessionx.php");
        require_once(SYSTEM_PATH . "Utils.php");
        require_once(SYSTEM_PATH . "UtilsPicture.php");
        require_once(SYSTEM_PATH . "Cache.php");
        require_once(SYSTEM_PATH . "Event.php");
        require_once(SYSTEM_PATH . "MovimException.php");
        require_once(SYSTEM_PATH . "RPC.php");
        require_once(SYSTEM_PATH . "User.php");
        require_once(SYSTEM_PATH . "Picture.php");
    }
    
    private function loadCommonLibraries() {
        // XMPPtoForm lib
        require_once(LIB_PATH . "XMPPtoForm.php");
        
        // SDPtoJingle and JingletoSDP lib :)
        require_once(LIB_PATH . "SDPtoJingle.php");
        require_once(LIB_PATH . "JingletoSDP.php");

        // Markdown lib
        require_once(LIB_PATH . "Markdown.php");
        
        // The template lib
        //require_once(LIB_PATH . 'RainTPL.php');
    }

    private function loadHelpers() {
        foreach(glob(HELPERS_PATH."*Helper.php") as $file) {
            require $file;
        }
    }
    
    private function loadDispatcher() {
        require_once(SYSTEM_PATH . "template/TplPageBuilder.php");
        require_once(SYSTEM_PATH . "controllers/BaseController.php");
        require_once(SYSTEM_PATH . "controllers/AjaxController.php");

        require_once(SYSTEM_PATH . "Route.php");

        require_once(SYSTEM_PATH . "controllers/FrontController.php");

        require_once(SYSTEM_PATH . "widget/WidgetBase.php");
        require_once(SYSTEM_PATH . "widget/WidgetWrapper.php");

        require_once(APP_PATH . "widgets/WidgetCommon/WidgetCommon.php");
        require_once(APP_PATH . "widgets/Notification/Notification.php");
    }<commit_msg>- Fix a require fatal_error<commit_after><?php
if (!defined('DOCUMENT_ROOT')) die('Access denied');

require 'vendor/autoload.php';

use Monolog\Logger;
use Monolog\Handler\SyslogHandler;

/**
 * Error Handler...
 */
function systemErrorHandler ( $errno , $errstr , $errfile ,  $errline , $errcontext=null ) 
{
    $log = new Logger('movim');
    $log->pushHandler(new SyslogHandler('movim'));
    $log->addError($errstr);
    return false;
}

/**
 * Manage boot order
 */
class Bootstrap {
    function boot() {
        //define all needed constants
        $this->setContants();

        require_once(SYSTEM_PATH . "Conf.php");
        
        mb_internal_encoding("UTF-8");

        //First thing to do, define error management (in case of error forward)
        $this->setLogs();
        
        //Check if vital system need is OK
        $this->checkSystem();

        $this->setBrowserSupport();
        
        $this->loadSystem();
        $this->loadCommonLibraries();
        $this->loadDispatcher();
        $this->loadHelpers();
        
        $this->setTimezone();
        
        $loadmodlsuccess = $this->loadModl();

        $this->loadMoxl();
        
        if($loadmodlsuccess) {
            $this->startingSession();
        } else {
            throw new Exception('Error loading Modl');
        }
    }
    private function checkSystem() {
        $listWritableFile = array(
            DOCUMENT_ROOT.'/log/logger.log',
            DOCUMENT_ROOT.'/log/php.log',
            DOCUMENT_ROOT.'/cache/test.tmp',
        );
        $errors=array();
        
        if(!is_writable(DOCUMENT_ROOT))
            $errors[] = 'We\'re unable to write to folder '.DOCUMENT_ROOT.': check rights';
        else {
            if(!file_exists(DOCUMENT_ROOT.'/cache') && !@mkdir(DOCUMENT_ROOT.'/cache')) {
                $errors[] = 'Couldn\'t create directory cache';
            }
            if(!file_exists(DOCUMENT_ROOT.'/log') && !@mkdir(DOCUMENT_ROOT.'/log')) {
                $errors[] = 'Couldn\'t create directory log';
            }
            if(!file_exists(DOCUMENT_ROOT.'/config') && !@mkdir(DOCUMENT_ROOT.'/config')) {
                $errors[] = 'Couldn\'t create directory config';
            }
            if(!file_exists(DOCUMENT_ROOT.'/users') && !@mkdir(DOCUMENT_ROOT.'/users')) {
                $errors[] = 'Couldn\'t create directory users';
            } else {
                touch(DOCUMENT_ROOT.'/users/index.html');
            }
        }
        
        foreach($listWritableFile as $fileName) {
            if (!file_exists($fileName)) {
                if (touch($fileName) !== true) {
                    $errors[] = 'We\'re unable to write to '.$fileName.': check rights';
                } 
            }else if (is_writable($fileName) !== true) {
                $errors[] = 'We\'re unable to write to file '.$fileName.': check rights';
            }
        }
        if (!function_exists('json_decode')) {
             $errors[] = 'You need to install php5-json that\'s not seems to be installed';
        }
        if (count($errors)) {
            throw new Exception(implode("\n<br />",$errors));
        }
    }
    private function setContants() {
        define('APP_TITLE',     'Movim');
        define('APP_NAME',      'movim');
        define('APP_VERSION',   $this->getVersion());
        define('BASE_URI',      $this->getBaseUri());
        define('CACHE_URI',     $this->getBaseUri() . 'cache/');
        
        define('THEMES_PATH',   DOCUMENT_ROOT . '/themes/');
        define('USERS_PATH',    DOCUMENT_ROOT . '/users/');
        define('APP_PATH',      DOCUMENT_ROOT . '/app/');
        define('SYSTEM_PATH',   DOCUMENT_ROOT . '/system/');
        define('LIB_PATH',      DOCUMENT_ROOT . '/lib/');
        define('LOCALES_PATH',  DOCUMENT_ROOT . '/locales/');
        define('CACHE_PATH',    DOCUMENT_ROOT . '/cache/');
        define('LOG_PATH',      DOCUMENT_ROOT . '/log/');
        
        define('VIEWS_PATH',    DOCUMENT_ROOT . '/app/views/');
        define('HELPERS_PATH',  DOCUMENT_ROOT . '/app/helpers/');
        
        if (!defined('DOCTYPE')) {
            define('DOCTYPE','text/html');
        }
    }

    private function getVersion() {
        $file = "VERSION";
        if($f = fopen(DOCUMENT_ROOT.'/'.$file, 'r')) {
            return trim(fgets($f));
        }
    }
    
    private function getBaseUri() {
        $dirname = dirname($_SERVER['PHP_SELF']);
        $path = (($dirname == DIRECTORY_SEPARATOR) ? '' : $dirname).'/';
        // Determining the protocol to use.
        $uri = "http://";
        if((
            isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "") 
        || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https")) {
            $uri = 'https://';
        }

        if($path == "") {
            $uri .= $_SERVER['HTTP_HOST'] ;
        } else {
            $uri .= str_replace('//', '/', $_SERVER['HTTP_HOST'] . $path);
        }

        $uri = str_replace('jajax.php', '', $uri);
        
        return $uri;
    }
    
    private function loadSystem() {
        // Loads up all system libraries.
        require_once(SYSTEM_PATH . "/i18n/i18n.php");

        require_once(SYSTEM_PATH . "Session.php");
        require_once(SYSTEM_PATH . "Sessionx.php");
        require_once(SYSTEM_PATH . "Utils.php");
        require_once(SYSTEM_PATH . "UtilsPicture.php");
        require_once(SYSTEM_PATH . "Cache.php");
        require_once(SYSTEM_PATH . "Event.php");
        require_once(SYSTEM_PATH . "MovimException.php");
        require_once(SYSTEM_PATH . "RPC.php");
        require_once(SYSTEM_PATH . "User.php");
        require_once(SYSTEM_PATH . "Picture.php");
    }
    
    private function loadCommonLibraries() {
        // XMPPtoForm lib
        require_once(LIB_PATH . "XMPPtoForm.php");
        
        // SDPtoJingle and JingletoSDP lib :)
        require_once(LIB_PATH . "SDPtoJingle.php");
        require_once(LIB_PATH . "JingletoSDP.php");
    }

    private function loadHelpers() {
        foreach(glob(HELPERS_PATH."*Helper.php") as $file) {
            require $file;
        }
    }
    
    private function loadDispatcher() {
        require_once(SYSTEM_PATH . "template/TplPageBuilder.php");
        require_once(SYSTEM_PATH . "controllers/BaseController.php");
        require_once(SYSTEM_PATH . "controllers/AjaxController.php");

        require_once(SYSTEM_PATH . "Route.php");

        require_once(SYSTEM_PATH . "controllers/FrontController.php");

        require_once(SYSTEM_PATH . "widget/WidgetBase.php");
        require_once(SYSTEM_PATH . "widget/WidgetWrapper.php");

        require_once(APP_PATH . "widgets/WidgetCommon/WidgetCommon.php");
        require_once(APP_PATH . "widgets/Notification/Notification.php");
    }
{'fraction_non_alphanumeric': 0.15651481132758746, 'fraction_numerical': 0.0008691243572101109, 'mean_word_length': 2.0691264725494554, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '3043184', 'n_tokens_mistral': 4217, 'n_tokens_neox': 4074, 'n_words': 715}