<commit_before><?php
// Security constant
define('BLUDIT', true);

// Directory separator
define('DS', DIRECTORY_SEPARATOR);

// PATHs
define('PATH_ROOT',					__DIR__.DS);
define('PATH_CONTENT',				PATH_ROOT.'content'.DS);
define('PATH_POSTS',                PATH_CONTENT.'posts'.DS);
define('PATH_UPLOADS',              PATH_CONTENT.'uploads'.DS);
define('PATH_PAGES',				PATH_CONTENT.'pages'.DS);
define('PATH_DATABASES',			PATH_CONTENT.'databases'.DS);
define('PATH_PLUGINS_DATABASES',	PATH_CONTENT.'databases'.DS.'plugins'.DS);
define('DOMAIN',                    getenv('HTTP_HOST'));

// HTML PATHs
$base = (dirname(getenv('SCRIPT_NAME'))==DS)?'/':dirname(getenv('SCRIPT_NAME')).'/';
define('HTML_PATH_ROOT', $base);

if(!defined('JSON_PRETTY_PRINT')) {
	define('JSON_PRETTY_PRINT', 128);
}

// ============================================================================
// FUNCTIONS
// ============================================================================

// Generate a random string
// Thanks, http://stackoverflow.com/questions/4356289/php-random-string-generator
function getRandomString($length = 10) {
    return substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
}

function alreadyInstalled()
{
    return file_exists(PATH_DATABASES.'site.php');
}

function checkSystem()
{
    $stdOut = array();
    $dirpermissions = 0755;
    $phpModules = array();

    if(function_exists('get_loaded_extensions'))
    {
        $phpModules = get_loaded_extensions();
    }

    if(!file_exists(PATH_ROOT.'.htaccess'))
    {
        $errorText = 'Missing file, upload the file .htaccess (ERR_201)';
        error_log($errorText, 0);
        array_push($stdOut, $errorText);
    }

    if(!version_compare(phpversion(), '5.2', '>'))
    {
        $errorText = 'Current PHP version '.phpversion().', you need > 5.3. (ERR_202)';
        error_log($errorText, 0);
        array_push($stdOut, $errorText);
    }

    if(!in_array('dom', $phpModules))
    {
        $errorText = 'PHP module DOM does not exist. (ERR_203)';
        error_log($errorText, 0);
        array_push($stdOut, $errorText);
    }

    if(!in_array('json', $phpModules))
    {
        $errorText = 'PHP module JSON does not exist. (ERR_204)';
        error_log($errorText, 0);
        array_push($stdOut, $errorText);
    }

    if(!is_writable(PATH_CONTENT))
    {
        $errorText = 'Writing test failure, check directory content permissions. (ERR_205)';<commit_msg>Bug fixes<commit_after><?php
// Security constant
define('BLUDIT', true);

// Directory separator
define('DS', DIRECTORY_SEPARATOR);

// PATHs
define('PATH_ROOT',					__DIR__.DS);
define('PATH_CONTENT',				PATH_ROOT.'content'.DS);
define('PATH_POSTS',                PATH_CONTENT.'posts'.DS);
define('PATH_UPLOADS',              PATH_CONTENT.'uploads'.DS);
define('PATH_PAGES',				PATH_CONTENT.'pages'.DS);
define('PATH_DATABASES',			PATH_CONTENT.'databases'.DS);
define('PATH_PLUGINS_DATABASES',	PATH_CONTENT.'databases'.DS.'plugins'.DS);
define('DOMAIN',                    getenv('HTTP_HOST'));

// HTML PATHs
$base = (dirname(getenv('SCRIPT_NAME'))==DS)?'/':dirname(getenv('SCRIPT_NAME')).'/';
define('HTML_PATH_ROOT', $base);

if(!defined('JSON_PRETTY_PRINT')) {
	define('JSON_PRETTY_PRINT', 128);
}

// ============================================================================
// FUNCTIONS
// ============================================================================

// Generate a random string
// Thanks, http://stackoverflow.com/questions/4356289/php-random-string-generator
function getRandomString($length = 10) {
    return substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
}

function alreadyInstalled()
{
    return file_exists(PATH_DATABASES.'site.php');
}

function checkSystem()
{
    $stdOut = array();
    $dirpermissions = 0755;
    $phpModules = array();

    if(function_exists('get_loaded_extensions'))
    {
        $phpModules = get_loaded_extensions();
    }

    if(!file_exists(PATH_ROOT.'.htaccess'))
    {
        $errorText = 'Missing file, upload the file .htaccess (ERR_201)';
        error_log($errorText, 0);
        array_push($stdOut, $errorText);
    }

    if(!version_compare(phpversion(), '5.3', '>='))
    {
        $errorText = 'Current PHP version '.phpversion().', you need > 5.3. (ERR_202)';
        error_log($errorText, 0);
        array_push($stdOut, $errorText);
    }

    if(!in_array('dom', $phpModules))
    {
        $errorText = 'PHP module DOM does not exist. (ERR_203)';
        error_log($errorText, 0);
        array_push($stdOut, $errorText);
    }

    if(!in_array('json', $phpModules))
    {
        $errorText = 'PHP module JSON does not exist. (ERR_204)';
        error_log($errorText, 0);
        array_push($stdOut, $errorText);
    }

    if(!is_writable(PATH_CONTENT))
    {
        $errorText = 'Writing test failure, check directory content permissions. (ERR_205)';
{'fraction_non_alphanumeric': 0.21515941447764186, 'fraction_numerical': 0.020052135552436335, 'mean_word_length': 3.9484126984126986, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '1939632', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1592, 'n_words': 260}