<commit_before><?php
namespace Slimpd;


$debug = isset($_REQUEST['debug']) ? true : false;
//$debug = true;
if($debug){
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
}

define('DS', DIRECTORY_SEPARATOR);
define('APP_ROOT', __DIR__ . DS);
define('APP_DEFAULT_CHARSET', 'UTF-8');
require_once APP_ROOT . 'vendor-dist' . DS . 'autoload.php';
require_once APP_ROOT . 'php' . DS . 'autoload.php';
date_default_timezone_set('Europe/Vienna');


session_start();

$app = new \Slim\Slim(array(
    'debug' => $debug,
    'view' => new \Slim\Views\Twig(),
    'templates.path' => 'templates'
));

require_once APP_ROOT . 'php' . DS . 'libs' . DS . 'shims' . DS . 'GeneralUtility.php';
require_once APP_ROOT . 'php' . DS . 'libs' . DS . 'shims' . DS . 'StringUtility.php';
require_once APP_ROOT . 'php' . DS . 'libs' . DS . 'shims' . DS . 'FilesystemUtility.php';
require_once APP_ROOT . 'php' . DS . 'libs' . DS . 'shims' . DS . 'CompareImages.php';
require_once APP_ROOT . 'php' . DS . 'libs' . DS . 'twig'  . DS . 'SlimpdTwigExtension.php';

$view = $app->view();
$view->parserExtensions = array(new \Twig_Extension_Debug());
$view->parserOptions = array('debug' => $debug);

$twig = $app->view->getInstance();
$twig->addExtension(new \Slimpd_Twig_Extension());


// LOAD MODULES
call_user_func(function() use ($app) {
    $path = APP_ROOT . 'php' . DS . 'Modules' . DS;
    foreach (scandir($path) as $dir) {
    	// suppress warning with "@" and avoid tons of is_file()-checks 
		@include_once($path . $dir . DS . 'class.php');
    }
});



$config = $app->configLoaderINI->loadConfig('master.ini');
switch($config['config']['langkey']) {
	case 'de':
		setlocale(LC_ALL, array('de_DE.UTF-8','de_DE@euro','de_DE','german'));
		break;
	default:
		// TODO: what is the correct locale-setting for en?
		// make sure this works correctly:
		//   var_dump(basename('musicfiles/testdirectory/Ænima-bla')); die();
		// for now force DE...
		// setlocale(LC_ALL, array('en_EN.UTF-8','en_EN','en_EN'))
		setlocale(LC_ALL, array('de_DE.UTF-8','de_DE@euro','de_DE','german'));
		break;
}

if($config['mpd']['alternative_musicdir'] === '') {
	define('ALTDIR', FALSE);
} else {
	define('ALTDIR', TRUE);
}


$config['current_url']  = rtrim($app->request->getResourceUri(), '/');
# TODO: its not possible to use 2 browsertabs in different playermodes simultaneously!?
$config['playerMode'] = ($app->getCookie('playerMode') === 'mpd') ? 'mpd' : 'local';
$config['nosurrounding'] = ($app->request->get('nosurrounding') == 1) ? TRUE : FALSE;
$config['root'] = $config['config']['absRefPrefix'];
$config['fileroot'] = $config['config']['absFilePrefix'];
$app->config = $config;
$vars = $config;

$app->view->getEnvironment()->addGlobal('flash', @$_SESSION['slim.flash']);

$app->error(function(\Exception $e) use ($app, $vars){
	$vars['action'] = 'error';
	$vars['errormessage'] = $e->getMessage();
	$vars['tracestring'] = str_replace(array('#', "\n"), array('<div>#', '</div>'), htmlspecialchars($e->getTraceAsString()));
	$vars['url'] = $app->request->getResourceUri();
	$vars['file'] = $e->getFile();
	$vars['line'] = $e->getLine();
    $app->render('appless.htm', $vars);
});

// LOAD CONTROLLERS
call_user_func(function() use ($app, $vars) {
    $path = APP_ROOT . 'php' . DS . 'Modules' . DS;
    foreach (scandir($path) as $dir) {
    	// suppress warning with "@" and avoid tons of is_file()-checks 
		@include_once($path . $dir . DS . 'controller.php');
    }
});

// DEFINE GET/POST routes (also check for .gitignored local-routes)
foreach(array('get', 'post') as $method) {
	foreach(array('', '_local') as $local) {
		if(file_exists(APP_ROOT . 'php' . DS . 'routes' . DS . $method . $local . '.php')) {
			include_once APP_ROOT . 'php' . DS . 'routes' . DS . $method . $local . '.php';
		}
	}
}

// use 404 not found as a search in case we don't have a slash in uri
$app->notFound(function() use ($app, $vars){
	$uri = ltrim(rawurldecode($app->request->getResourceUri()),'/');
	// check if we do have a slash in uri
	if(stripos($uri, '/') !== FALSE) {
		$vars['action'] = '404';
		$app->render('surrounding.htm', $vars);<commit_msg>fixed whitespaces and line breaks<commit_after><?php
namespace Slimpd;
/* Copyright
 *
 */

$debug = isset($_REQUEST['debug']) ? true : false;
if($debug){
	error_reporting(E_ALL);
	ini_set('display_errors', 1);
}

define('DS', DIRECTORY_SEPARATOR);
define('APP_ROOT', __DIR__ . DS);
define('APP_DEFAULT_CHARSET', 'UTF-8');
require_once APP_ROOT . 'vendor-dist' . DS . 'autoload.php';
require_once APP_ROOT . 'php' . DS . 'autoload.php';
date_default_timezone_set('Europe/Vienna');


session_start();

$app = new \Slim\Slim(array(
	'debug' => $debug,
	'view' => new \Slim\Views\Twig(),
	'templates.path' => 'templates'
));

require_once APP_ROOT . 'php' . DS . 'libs' . DS . 'shims' . DS . 'GeneralUtility.php';
require_once APP_ROOT . 'php' . DS . 'libs' . DS . 'shims' . DS . 'StringUtility.php';
require_once APP_ROOT . 'php' . DS . 'libs' . DS . 'shims' . DS . 'FilesystemUtility.php';
require_once APP_ROOT . 'php' . DS . 'libs' . DS . 'shims' . DS . 'CompareImages.php';
require_once APP_ROOT . 'php' . DS . 'libs' . DS . 'twig'  . DS . 'SlimpdTwigExtension.php';

$view = $app->view();
$view->parserExtensions = array(new \Twig_Extension_Debug());
$view->parserOptions = array('debug' => $debug);

$twig = $app->view->getInstance();
$twig->addExtension(new \Slimpd_Twig_Extension());


// LOAD MODULES
call_user_func(function() use ($app) {
	$path = APP_ROOT . 'php' . DS . 'Modules' . DS;
	foreach (scandir($path) as $dir) {
		// suppress warning with "@" and avoid tons of is_file()-checks
		@include_once($path . $dir . DS . 'class.php');
	}
});



$config = $app->configLoaderINI->loadConfig('master.ini');
switch($config['config']['langkey']) {
	case 'de':
		setlocale(LC_ALL, array('de_DE.UTF-8','<EMAIL>@euro','de_DE','german'));
		break;
	default:
		// TODO: what is the correct locale-setting for en?
		// make sure this works correctly:
		//   var_dump(basename('musicfiles/testdirectory/Ænima-bla')); die();
		// for now force DE...
		// setlocale(LC_ALL, array('en_EN.UTF-8','en_EN','en_EN'))
		setlocale(LC_ALL, array('de_DE.UTF-8','de_DE@euro','de_DE','german'));
		break;
}

if($config['mpd']['alternative_musicdir'] === '') {
	define('ALTDIR', FALSE);
} else {
	define('ALTDIR', TRUE);
}


$config['current_url']  = rtrim($app->request->getResourceUri(), '/');
# TODO: its not possible to use 2 browsertabs in different playermodes simultaneously!?
$config['playerMode'] = ($app->getCookie('playerMode') === 'mpd') ? 'mpd' : 'local';
$config['nosurrounding'] = ($app->request->get('nosurrounding') == 1) ? TRUE : FALSE;
$config['root'] = $config['config']['absRefPrefix'];
$config['fileroot'] = $config['config']['absFilePrefix'];
$app->config = $config;
$vars = $config;

$app->view->getEnvironment()->addGlobal('flash', @$_SESSION['slim.flash']);

$app->error(function(\Exception $e) use ($app, $vars){
	$vars['action'] = 'error';
	$vars['errormessage'] = $e->getMessage();
	$vars['tracestring'] = str_replace(array('#', "\n"), array('<div>#', '</div>'), htmlspecialchars($e->getTraceAsString()));
	$vars['url'] = $app->request->getResourceUri();
	$vars['file'] = $e->getFile();
	$vars['line'] = $e->getLine();
	$app->render('appless.htm', $vars);
});

// LOAD CONTROLLERS
call_user_func(function() use ($app, $vars) {
	$path = APP_ROOT . 'php' . DS . 'Modules' . DS;
	foreach (scandir($path) as $dir) {
		// suppress warning with "@" and avoid tons of is_file()-checks
		@include_once($path . $dir . DS . 'controller.php');
	}
});

// DEFINE GET/POST routes (also check for .gitignored local-routes)
foreach(array('get', 'post') as $method) {
	foreach(array('', '_local') as $local) {
		if(file_exists(APP_ROOT . 'php' . DS . 'routes' . DS . $method . $local . '.php')) {
			include_once APP_ROOT . 'php' . DS . 'routes' . DS . $method . $local . '.php';
		}
	}
}

// use 404 not found as a search in case we don't have a slash in uri
$app->notFound(function() use ($app, $vars){
	$uri = ltrim(rawurldecode($app->request->getResourceUri()),'/');
	// check if we do have a slash in uri
	if(stripos($uri, '/') !== FALSE) {
		$vars['action'] = '404';
		$app->render('surrounding.htm', $vars);
{'fraction_non_alphanumeric': 0.22041707080504364, 'fraction_numerical': 0.0031522793404461687, 'mean_word_length': 4.423405654174885, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 74, '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': '5947161', 'n_tokens_mistral': 3110, 'n_tokens_neox': 3014, 'n_words': 642}