1
0

errorview

This commit is contained in:
Mike Schwörer 2018-01-03 17:28:08 +01:00
parent 9bc4267c6a
commit 04a798bfa1
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
12 changed files with 209 additions and 69 deletions

View File

@ -25,6 +25,9 @@ body {
@media (min-width: 1200px) { @media (min-width: 1200px) {
.content-responsive { .content-responsive {
width: 1170px; } } width: 1170px; } }
.content-fullheight {
flex-grow: 1; }
.contentheader { .contentheader {
width: 100%; width: 100%;
color: #333; color: #333;
@ -134,6 +137,8 @@ html, body {
height: 100%; } height: 100%; }
#mastercontainer { #mastercontainer {
display: flex;
flex-direction: column;
min-height: 100%; min-height: 100%;
position: relative; } position: relative; }
@ -448,6 +453,27 @@ html, body {
.bce_pag05 { .bce_pag05 {
flex-direction: row; } } flex-direction: row; } }
.ev_master {
align-self: center; }
@media (min-width: 850px) {
.ev_master {
padding-bottom: 80px; } }
.ev_master .ev_code {
color: #000;
text-align: center;
font-size: 150pt;
font-weight: 500;
font-family: Consolas, Monaco, "Courier New", Menlo, monospace; }
.ev_master .ev_msg {
color: #888;
text-align: center;
font-size: 25pt; }
@media (max-width: 767px) {
.ev_master .ev_code {
font-size: 75pt; }
.ev_master .ev_msg {
font-size: 15pt; } }
.euler_pnl_base { .euler_pnl_base {
display: inline-flex; display: inline-flex;
flex-direction: column; flex-direction: column;

View File

@ -6,6 +6,7 @@
@import 'styles_bloglist'; @import 'styles_bloglist';
@import 'styles_blogview'; @import 'styles_blogview';
@import 'styles_blogview_befunge'; @import 'styles_blogview_befunge';
@import 'styles_errorview';
@import 'styles_eulerpanel'; @import 'styles_eulerpanel';
@import 'styles_bfjoustrunner'; @import 'styles_bfjoustrunner';

View File

@ -0,0 +1,28 @@
@import 'styles_config';
.ev_master {
align-self: center;
@media(min-width:850px) {padding-bottom: 80px;}
.ev_code {
color: #000;
text-align: center;
font-size: 150pt;
font-weight: 500;
font-family: $FONT_CODE;
}
.ev_msg {
color: #888;
text-align: center;
font-size: 25pt;
}
@media(max-width:767px) {
.ev_code { font-size: 75pt; }
.ev_msg { font-size: 15pt; }
}
}

View File

@ -9,6 +9,8 @@ html, body {
// https://stackoverflow.com/a/19723677/1761622 // https://stackoverflow.com/a/19723677/1761622
#mastercontainer { #mastercontainer {
display:flex;
flex-direction: column;
min-height:100%; min-height:100%;
position:relative; position:relative;
} }
@ -18,6 +20,7 @@ html, body {
#content { #content {
padding-bottom:60px; /* Height of the footer */ padding-bottom:60px; /* Height of the footer */
} }
#footerdiv { #footerdiv {
position:absolute; position:absolute;
bottom:0; bottom:0;

View File

@ -24,6 +24,8 @@ body {
@media(min-width:992px) { .content-responsive { width: 724px; } } @media(min-width:992px) { .content-responsive { width: 724px; } }
@media(min-width:1200px){ .content-responsive { width: 1170px; } } @media(min-width:1200px){ .content-responsive { width: 1170px; } }
.content-fullheight { flex-grow: 1;}
.contentheader { .contentheader {
width: 100%; width: 100%;
color: $COL_TEXT_DARK; color: $COL_TEXT_DARK;

View File

@ -9,7 +9,7 @@ $subview = $OPTIONS['subview'];
$euler = Euler::listAll(); $euler = Euler::listAll();
$problem = Euler::getEulerProblemFromStrIdent($subview); $problem = Euler::getEulerProblemFromStrIdent($subview);
if ($post === NULL) httpError(404, 'problem not found'); if ($problem === NULL) httpError(404, 'Project Euler entry not found');
$pd = new ParsedownCustom(); $pd = new ParsedownCustom();

View File

@ -70,73 +70,89 @@ $URL_RULES =
//############################################################################# //#############################################################################
$path = strtolower(parse_url($_SERVER['REQUEST_URI'])['path']); try {
$pathparts = preg_split('@/@', $path, NULL, PREG_SPLIT_NO_EMPTY); InitPHP();
$partcount = count($pathparts);
global $OPTIONS; $path = strtolower(parse_url($_SERVER['REQUEST_URI'])['path']);
global $HEADER_ACTIVE; $pathparts = preg_split('@/@', $path, NULL, PREG_SPLIT_NO_EMPTY);
$partcount = count($pathparts);
$HEADER_ACTIVE = 'none'; global $OPTIONS;
global $HEADER_ACTIVE;
foreach ($URL_RULES as $rule) $HEADER_ACTIVE = 'none';
{
if ($partcount !== count($rule['url'])) continue;
$urlparams = []; foreach ($URL_RULES as $rule)
$match = true;
for($i = 0; $i < $partcount; $i++)
{ {
$comp = $rule['url'][$i]; if ($partcount !== count($rule['url'])) continue;
if (startsWith($comp, '?{') && endsWith($comp, '}'))
{ $urlparams = [];
$ident = substr($comp, 2, strlen($comp)-3);
$urlparams[$ident] = $pathparts[$i]; $match = true;
} for($i = 0; $i < $partcount; $i++)
else {
{ $comp = $rule['url'][$i];
if (strtolower($comp) !== strtolower($pathparts[$i])) { $match = false; break; } if (startsWith($comp, '?{') && endsWith($comp, '}'))
} {
} $ident = substr($comp, 2, strlen($comp)-3);
if (!$match) continue; $urlparams[$ident] = $pathparts[$i];
}
else
{
if (strtolower($comp) !== strtolower($pathparts[$i])) { $match = false; break; }
}
}
if (!$match) continue;
$opt = [];
foreach($rule['options'] as $optname => $optvalue)
{
$value = $optvalue;
if ($value === '%GET%')
{
if (!isset($_GET[$optname])) { $match = false; break; }
$value = $_GET[$optname];
}
else if ($value === '%POST%')
{
if (!isset($_POST[$optname])) { $match = false; break; }
$value = $_POST[$optname];
}
else if ($value === '%URL%')
{
if (!isset($urlparams[$optname])) { $match = false; break; }
$value = $urlparams[$optname];
}
$opt[strtolower($optname)] = $value;
}
if (!$match) continue;
$OPTIONS = $opt;
include $rule['target'];
return;
}
$opt = [];
foreach($rule['options'] as $optname => $optvalue)
{ {
$value = $optvalue; // [404] - Page Not Found
$OPTIONS = [];
if ($value === '%GET%') httpError('404', 'Page not found');
{ return;
if (!isset($_GET[$optname])) { $match = false; break; }
$value = $_GET[$optname];
}
else if ($value === '%POST%')
{
if (!isset($_POST[$optname])) { $match = false; break; }
$value = $_POST[$optname];
}
else if ($value === '%URL%')
{
if (!isset($urlparams[$optname])) { $match = false; break; }
$value = $urlparams[$optname];
}
$opt[strtolower($optname)] = $value;
} }
if (!$match) continue;
$OPTIONS = $opt; } catch (Exception $e) {
include $rule['target'];
return;
} if (isProd())
{
httpError('500 ', 'Internal server error');
}
else
{
echo '<table class="xdebug-error xe-uncaught-exception" dir="ltr" border="1" cellspacing="0" cellpadding="1">'.$e->xdebug_message.'</table>';
}
{
// [404] - Page Not Found
$OPTIONS = [];
include 'pages/error_404.php';
return;
} }

View File

@ -3,11 +3,28 @@
global $CONFIG; global $CONFIG;
$CONFIG = require 'config.php'; $CONFIG = require 'config.php';
$CSS_BASE = ($CONFIG['prod']) ? ('styles.min.css') : ('styles.css'); global $CSS_BASE;
$CSS_BASE = ($CONFIG['prod']) ? ('/data/css/styles.min.css') : ('/data/css/styles.css');
global $REGISTERED_SCRIPTS; global $REGISTERED_SCRIPTS;
$REGISTERED_SCRIPTS = []; $REGISTERED_SCRIPTS = [];
function InitPHP() {
set_error_handler("exception_error_handler"); // errors as exceptions for global catch
ob_start(); // buffer outpt so it can be discarded in httpError
}
function exception_error_handler($severity, $message, $file, $line) {
if (!(error_reporting() & $severity)) {
// This error code is not included in error_reporting
return;
}
throw new ErrorException($message, 0, $severity, $file, $line);
}
function startsWith($haystack, $needle) function startsWith($haystack, $needle)
{ {
$length = strlen($needle); $length = strlen($needle);
@ -22,7 +39,12 @@ function endsWith($haystack, $needle)
function httpError($errorcode, $message) function httpError($errorcode, $message)
{ {
die($message);//TODO errorcode ob_clean();
global $OPTIONS;
$OPTIONS = [ 'code' => $errorcode, 'message' => $message ];
require (__DIR__ . '/../pages/errorview.php');
die();
} }
function destructiveUrlEncode($str) { function destructiveUrlEncode($str) {
@ -82,3 +104,13 @@ function includeScriptOnce($script, $echo = true)
return "<script src=\"$script\" type=\"text/javascript\"></script>"; return "<script src=\"$script\" type=\"text/javascript\"></script>";
} }
} }
function printCSS() {
global $CSS_BASE;
echo '<link rel="stylesheet" href="' . $CSS_BASE . '"/>';
}
function isProd() {
global $CONFIG;
return $CONFIG['prod'];
}

View File

@ -12,7 +12,7 @@ $allposts = Blog::listAllOrderedDescending();
<title>Mikescher.com - Blog</title> <title>Mikescher.com - Blog</title>
<meta name="google-site-verification" content="pZOhmjeJcQbRMNa8xRLam4dwJ2oYwMwISY1lRKreSSs"/> <meta name="google-site-verification" content="pZOhmjeJcQbRMNa8xRLam4dwJ2oYwMwISY1lRKreSSs"/>
<link rel="icon" type="image/png" href="/data/images/favicon.png"/> <link rel="icon" type="image/png" href="/data/images/favicon.png"/>
<link rel="stylesheet" href="/data/css/styles.css"/> <link rel="stylesheet" href="<?php printCSS(); ?>"/>
</head> </head>
<body> <body>
<div id="mastercontainer"> <div id="mastercontainer">

View File

@ -10,7 +10,7 @@ $subview = $OPTIONS['subview'];
$post = Blog::getBlogpost($id); $post = Blog::getBlogpost($id);
if ($post === NULL) httpError(404, 'blogpost not found'); if ($post === NULL) httpError(404, 'Blogpost not found');
?> ?>
<head> <head>
@ -18,7 +18,7 @@ if ($post === NULL) httpError(404, 'blogpost not found');
<title>Mikescher.com - Blog</title> <title>Mikescher.com - Blog</title>
<meta name="google-site-verification" content="pZOhmjeJcQbRMNa8xRLam4dwJ2oYwMwISY1lRKreSSs"/> <meta name="google-site-verification" content="pZOhmjeJcQbRMNa8xRLam4dwJ2oYwMwISY1lRKreSSs"/>
<link rel="icon" type="image/png" href="/data/images/favicon.png"/> <link rel="icon" type="image/png" href="/data/images/favicon.png"/>
<link rel="stylesheet" href="/data/css/styles.css"/> <?php printCSS(); ?>
<?php <?php
if ($post['type'] === 'euler' && $subview !== '') if ($post['type'] === 'euler' && $subview !== '')
{ {

32
www/pages/errorview.php Normal file
View File

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<?php
require_once (__DIR__ . '/../internals/base.php');
global $OPTIONS;
$errorcode = $OPTIONS['code'];
$errormsg = $OPTIONS['message'];
?>
<head>
<meta charset="utf-8">
<title>Mikescher.com - <?php echo $errormsg; ?></title>
<link rel="icon" type="image/png" href="/data/images/favicon.png"/>
<?php printCSS(); ?>
</head>
<body>
<div id="mastercontainer">
<?php $HEADER_ACTIVE='none'; include (__DIR__ . '/../fragments/header.php'); ?>
<div id="content" class="content-responsive content-fullheight">
<div class="ev_master">
<div class="ev_code"><?php echo $errorcode; ?></div>
<div class="ev_msg"><?php echo $errormsg; ?></div>
</div>
</div>
</div>
</body>
</html>

View File

@ -6,7 +6,7 @@
<title>Mikescher.com</title> <title>Mikescher.com</title>
<meta name="google-site-verification" content="pZOhmjeJcQbRMNa8xRLam4dwJ2oYwMwISY1lRKreSSs"/> <meta name="google-site-verification" content="pZOhmjeJcQbRMNa8xRLam4dwJ2oYwMwISY1lRKreSSs"/>
<link rel="icon" type="image/png" href="/data/images/favicon.png"/> <link rel="icon" type="image/png" href="/data/images/favicon.png"/>
<link rel="stylesheet" href="/data/css/styles.css"/> <?php printCSS(); ?>
</head> </head>
<body> <body>
<div id="mastercontainer"> <div id="mastercontainer">