/**
* Debug-Mode
* Check if file "_CMSimpleDebug.txt" exists to turn on debug-mode
* with default setting E_ERROR | E_USER_WARNING | E_PARSE.
* Level of debug mode can be adjusted by placing an
* integer-value within the file using following values:
*
* Possible values of $dbglevel:
* 0 - Turn off all error reporting
* 1 - Running errors except warnings
* 2 - Running errors
* 3 - Running errors + notices
* 4 - All errors except notices and warnings
* 5 - All errors except notices
* 6 - All errors
*
* @author Holger
*
* @global array $pth CMSimple's pathes
* @return boolean Returns true/false if error_reporting was enabled or not
*/
function CMSimpleDebugMode()
{
global $pth;
$dbglevel = '';
# possible values of $dbglevel:
# 0 - Turn off all error reporting
# 1 - Running errors except warnings
# 2 - Running errors
# 3 - Running errors + notices
# 4 - All errors except notices and warnings
# 5 - All errors except notices
# 6 - All errors
if (file_exists($pth['folder']['userfiles'] . '_core/_CMSimpleDebug.txt'))
{
ini_set('display_errors', 1);
$dbglevel = rf($pth['folder']['userfiles'] . '_core/_CMSimpleDebug.txt');
if (strlen($dbglevel) == 1)
{
set_error_handler('CMSimpleDebug');
switch ($dbglevel)
{
case 0: error_reporting(0);
break;
case 1: error_reporting(E_ERROR | E_USER_WARNING | E_PARSE);
break;
case 2: error_reporting(E_ERROR | E_WARNING | E_USER_WARNING | E_PARSE);
break;
case 3: error_reporting(E_ERROR | E_WARNING | E_USER_WARNING | E_PARSE | E_NOTICE);
break;
case 4: error_reporting(E_ALL ^ (E_NOTICE | E_WARNING | E_USER_WARNING));
break;
case 5: error_reporting(E_ALL ^ E_NOTICE);
break;
case 6: error_reporting(E_ALL);
break;
default:
error_reporting(E_ERROR | E_USER_WARNING | E_PARSE);
}
}
else
{
error_reporting(E_ERROR | E_USER_WARNING | E_PARSE);
}
}
else
{
ini_set('display_errors', 0);
error_reporting(0);
}
if (error_reporting() > 0)
{
return true;
}
else
{
return false;
}
}
function CMSimpleDebug($errno, $errstr, $errfile, $errline)
{
global $errors;
if (!(error_reporting() & $errno))
{
// This error code is not included in error_reporting
return;
}
switch ($errno)
{
case E_USER_ERROR:
$errors[] = "CMSimple-ERROR: [$errno] $errstr
$errfile:$errline
\n";
break;
case E_USER_WARNING:
echo "CMSimple WARNING: $errstr
$errfile: $errline
\n";
break;
case E_USER_NOTICE:
$errors[] = "CMSimple-NOTICE: [$errno] $errstr
$errfile:$errline
\n";
break;
case E_WARNING:
$errors[] = "WARNING: $errno $errstr
$errfile:$errline
\n";
break;
case E_NOTICE:
$errors[] = "NOTICE: $errstr
$errfile:$errline
\n";
break;
case E_ERROR:
$errors[] = "ERROR: $errstr
$errfile:$errline
\n";
break;
default:
echo "Unknown error type: [$errno] $errstr
$errfile:$errline
\n";
break;
}
return true;
}
csrfProtection
function csrfProtection()
{
global $adm, $cf, $sn, $csrfSession;
if($adm && $cf['use']['csrf_protection'] == 'true')
{
if($_POST['csrf_token'] !== $_SESSION[$csrfSession])die("CSRF protection - logout »");
}
}