components as $component)
{
require("components/component.{$component}.php");
}
/* lighttpd (and perhaps some other HTTPds) won't pass on GET parameters
* when using the server.error-handler-404 directive that is required to
* use the CPHP router. This patch will try to detect such problems, and
* manually extract the GET data from the request URI. I admit, it's a
* bit of a hack, but there doesn't really seem to be a different way of
* solving this issue. */
/* Detect whether the request URI and the $_GET array disagree on the
* existence of GET parameters. */
if(strpos($_SERVER['REQUEST_URI'], "?") !== false && empty($_GET))
{
/* Separate the protocol/host/path component from the query string. */
list($uri, $query) = explode("?", $_SERVER['REQUEST_URI'], 2);
/* Store the entire query string in the relevant $_SERVER variable -
* lighttpds strange behaviour breaks this variable as well. */
$_SERVER['QUERY_STRING'] = $query;
/* Finally, run the query string through PHPs own internal GET data
* parser, and have it store the result in the $_GET variable. This
* should yield an identical result to a well-functioning HTTPd. */
parse_str($query, $_GET);
}
if(get_magic_quotes_gpc())
{
/* By default, get rid of all quoted variables. Magic quotes are evil. */
foreach($_POST as &$var)
{
$var = stripslashes($var);
}
foreach($_GET as &$var)
{
$var = stripslashes($var);
}
}
if(!empty($cphp_config->autoloader))
{
function cphp_autoload_class($class_name)
{
global $_APP;
$class_name = str_replace("\\", "/", strtolower($class_name));
if(file_exists("classes/{$class_name}.php"))
{
require_once("classes/{$class_name}.php");
}
}
spl_autoload_register('cphp_autoload_class');
}
/* https://stackoverflow.com/a/1159235/1332715 */
set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext) {
if(!(error_reporting() & $errno))
return;
switch($errno) {
case E_WARNING :
case E_USER_WARNING :
case E_STRICT :
case E_NOTICE :
case E_USER_NOTICE :
$type = 'warning';
$fatal = false;
break;
default :
$type = 'fatal error';
$fatal = true;
break;
}
$trace = array_reverse(debug_backtrace());
array_pop($trace);
if(php_sapi_name() == 'cli') {
echo 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
foreach($trace as $item)
echo ' ' . (isset($item['file']) ? $item['file'] : ' ' . "\n";
echo ' Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
echo ' ' . "\n";
foreach($trace as $item)
echo '
' . "\n";
echo '
{$inner_e[1]}"; } $error_body = "
An uncaught {$exception_class} was thrown, in {$exception_file} on line {$exception_line}.
{$exception_trace}{$inner_traces}
Important: These errors should never be displayed on a production server! Make sure that display_errors is turned off in your PHP configuration, if you want to hide these tracebacks.
"; break; default: $error_body = "Something went wrong while creating this page, but we're not yet quite sure what it was.
If the issue persists, please contact the administrator for this application or website.
"; break; } http_status_code(500); echo("