<commit_before><?php
namespace pirrs;
use \PDO;

/** Functions and definitions that will be included for every page **/
require 'config.php';

$path = dirname(__FILE__) . PATH_INCLUDE; 
set_include_path(get_include_path() . PATH_SEPARATOR . $path); //Adds the './include' folder to the include path
// That doesn't explain much, but basically, if I say "include 'file.php';", 
// it now searches './include' for file.php, as well as the default include locations.

/*
 * Includes all of the necessary helper classes and files.
 */
function init(){
	$classPath = dirname(__FILE__) . PATH_CLASS; //Get the path to our .class.php files 
	set_include_path(get_include_path() . PATH_SEPARATOR . $classPath); //Add that path to the include path
	
	spl_autoload_extensions('.class.php,.php'); //Auto-load any of our .class.php classes
	spl_autoload_register();
	require_once 'password.php'; 
	//require_once 'vendor/HTMLPurifier/HTMLPurifier.auto.php';

	//Initialize the logging object
	$logOverrides = array();
	if(defined('SERVER_LOG_PATH_ERRORS')){
		$logOverrides['error'] = SERVER_LOG_PATH_ERRORS; 
	}
	if(defined('SERVER_LOG_PATH_WARNINGS')){
		$logOverrides['warning'] = SERVER_LOG_PATH_WARNINGS;
	}
	Log::construct(SERVER_LOG_PATH,$logOverrides);
}

/*
 * Here's a happy little log function.
 * Use it for errors.
 * $description is for a written description of the problem.
 * $error is for the output of error functions.
 * $debugIndex is the number of levels on the backtrace to use as the calling information. 
 *      ex: When $debugIndex = 0, the file path that gets logged is the file in which "logError()" appears. 
 *          While, when $debugIndex = 1, the file path that is logged is the file which called the function that contains logError() 
 *          Note, if the value is higher than the level returned by debug_backtrace, then it will decrement this value until a valid level is found.
 */
function logError($description, $error, $debugIndex = 1){
	Log::warning('logError() is depreciated! Please use Log::error().');
	Log::error($description, $error, $debugIndex);
}

/*
 * Nice little log function for warnings.
 * $description is for a written description of the problem.
 * $debugIndex is the number of levels on the backtrace to use as the calling information. 
 *      ex: When $debugIndex = 0, the file path that gets logged is the file in which "logError()" appears. 
 *          While, when $debugIndex = 1, the file path that is logged is the file which called the function that contains logError() 
 *          Note, if the value is higher than the level returned by debug_backtrace, then it will decrement this value until a valid level is found.
 */
function logWarning($description, $debugIndex = 1){
	Log::warning('logWarning() is depreciated! Please use Log::warning().');
	Log::warning($description, $debugIndex);
}

/*
 * Echo safe
 * Hopefully echos information in a way that is safe to echo
 */
function es($message){
	echo htmlspecialchars($message);
}
function debug($message){
	if(is_bool($message)){
		echo (($message === true)?'TRUE':'FALSE').' <br />';
	}
	else{
		echo $message . '<br />';
	}
}

function parsePath($withQueryArgs = true){
	//http://stackoverflow.com/questions/16388959/url-rewriting-with-php
	$uri = rtrim( dirname($_SERVER['SCRIPT_NAME']), '/' );
	$uri = '/' . trim( str_replace( $uri, '', $_SERVER['REQUEST_URI'] ), '/' );
	$uri = urldecode( $uri );
	if(!$withQueryArgs){
		$matchVal = preg_match('#^(?\'path\'[^\?]*)(?:\?.*)?$#i',$uri,$matches);
		if($matchVal !== 0 && $matchVal !== false){<commit_msg>fixed issue with parsing url path when in subdirectory of web root<commit_after><?php
namespace pirrs;
use \PDO;

/** Functions and definitions that will be included for every page **/
require 'config.php';

$path = dirname(__FILE__) . PATH_INCLUDE; 
set_include_path(get_include_path() . PATH_SEPARATOR . $path); //Adds the './include' folder to the include path
// That doesn't explain much, but basically, if I say "include 'file.php';", 
// it now searches './include' for file.php, as well as the default include locations.

/*
 * Includes all of the necessary helper classes and files.
 */
function init(){
	$classPath = dirname(__FILE__) . PATH_CLASS; //Get the path to our .class.php files 
	set_include_path(get_include_path() . PATH_SEPARATOR . $classPath); //Add that path to the include path
	
	spl_autoload_extensions('.class.php,.php'); //Auto-load any of our .class.php classes
	spl_autoload_register();
	require_once 'password.php'; 
	//require_once 'vendor/HTMLPurifier/HTMLPurifier.auto.php';

	//Initialize the logging object
	$logOverrides = array();
	if(defined('SERVER_LOG_PATH_ERRORS')){
		$logOverrides['error'] = SERVER_LOG_PATH_ERRORS; 
	}
	if(defined('SERVER_LOG_PATH_WARNINGS')){
		$logOverrides['warning'] = SERVER_LOG_PATH_WARNINGS;
	}
	Log::construct(SERVER_LOG_PATH,$logOverrides);
}

/*
 * Here's a happy little log function.
 * Use it for errors.
 * $description is for a written description of the problem.
 * $error is for the output of error functions.
 * $debugIndex is the number of levels on the backtrace to use as the calling information. 
 *      ex: When $debugIndex = 0, the file path that gets logged is the file in which "logError()" appears. 
 *          While, when $debugIndex = 1, the file path that is logged is the file which called the function that contains logError() 
 *          Note, if the value is higher than the level returned by debug_backtrace, then it will decrement this value until a valid level is found.
 */
function logError($description, $error, $debugIndex = 1){
	Log::warning('logError() is depreciated! Please use Log::error().');
	Log::error($description, $error, $debugIndex);
}

/*
 * Nice little log function for warnings.
 * $description is for a written description of the problem.
 * $debugIndex is the number of levels on the backtrace to use as the calling information. 
 *      ex: When $debugIndex = 0, the file path that gets logged is the file in which "logError()" appears. 
 *          While, when $debugIndex = 1, the file path that is logged is the file which called the function that contains logError() 
 *          Note, if the value is higher than the level returned by debug_backtrace, then it will decrement this value until a valid level is found.
 */
function logWarning($description, $debugIndex = 1){
	Log::warning('logWarning() is depreciated! Please use Log::warning().');
	Log::warning($description, $debugIndex);
}

/*
 * Echo safe
 * Hopefully echos information in a way that is safe to echo
 */
function es($message){
	echo htmlspecialchars($message);
}
function debug($message){
	if(is_bool($message)){
		echo (($message === true)?'TRUE':'FALSE').' <br />';
	}
	else{
		echo $message . '<br />';
	}
}

function parsePath($withQueryArgs = true){
	//http://stackoverflow.com/questions/16388959/url-rewriting-with-php
	$uri = rtrim( dirname($_SERVER['SCRIPT_NAME']), '/' );
    
    $dirPos = strpos($_SERVER['REQUEST_URI'], $uri); //Get the position of the current file directory name in the url
    if($dirPos !== false){
        $uri = '/' . trim( substr_replace($_SERVER['REQUEST_URI'], '', $dirPos, strlen($uri)), '/' ); //Remove only the first occurrence of the current directory
        //http://stackoverflow.com/a/1252710/451726
    }
    
	$uri = urldecode( $uri );
    
	if(!$withQueryArgs){
		$matchVal = preg_match('#^(?\'path\'[^\?]*)(?:\?.*)?$#i',$uri,$matches);
		if($matchVal !== 0 && $matchVal !== false){
{'fraction_non_alphanumeric': 0.13236470274593443, 'fraction_numerical': 0.005731804852039456, 'mean_word_length': 4.185210780926054, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2706765', 'n_tokens_mistral': 2327, 'n_tokens_neox': 2221, 'n_words': 799}