diff --git a/www/data/css/styles.css b/www/data/css/styles.css index 4a06e09..10726a5 100644 --- a/www/data/css/styles.css +++ b/www/data/css/styles.css @@ -25,6 +25,9 @@ body { @media (min-width: 1200px) { .content-responsive { width: 1170px; } } +.content-fullheight { + flex-grow: 1; } + .contentheader { width: 100%; color: #333; @@ -134,6 +137,8 @@ html, body { height: 100%; } #mastercontainer { + display: flex; + flex-direction: column; min-height: 100%; position: relative; } @@ -448,6 +453,27 @@ html, body { .bce_pag05 { 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 { display: inline-flex; flex-direction: column; diff --git a/www/data/css/styles.scss b/www/data/css/styles.scss index d5c6b05..3ddb832 100644 --- a/www/data/css/styles.scss +++ b/www/data/css/styles.scss @@ -6,6 +6,7 @@ @import 'styles_bloglist'; @import 'styles_blogview'; @import 'styles_blogview_befunge'; +@import 'styles_errorview'; @import 'styles_eulerpanel'; @import 'styles_bfjoustrunner'; diff --git a/www/data/css/styles_errorview.scss b/www/data/css/styles_errorview.scss new file mode 100644 index 0000000..e5eb586 --- /dev/null +++ b/www/data/css/styles_errorview.scss @@ -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; } + } + +} \ No newline at end of file diff --git a/www/data/css/styles_footer.scss b/www/data/css/styles_footer.scss index b76d6b6..a1e0b37 100644 --- a/www/data/css/styles_footer.scss +++ b/www/data/css/styles_footer.scss @@ -9,6 +9,8 @@ html, body { // https://stackoverflow.com/a/19723677/1761622 #mastercontainer { + display:flex; + flex-direction: column; min-height:100%; position:relative; } @@ -18,6 +20,7 @@ html, body { #content { padding-bottom:60px; /* Height of the footer */ } + #footerdiv { position:absolute; bottom:0; diff --git a/www/data/css/styles_global.scss b/www/data/css/styles_global.scss index 989764c..ca3f7b8 100644 --- a/www/data/css/styles_global.scss +++ b/www/data/css/styles_global.scss @@ -24,6 +24,8 @@ body { @media(min-width:992px) { .content-responsive { width: 724px; } } @media(min-width:1200px){ .content-responsive { width: 1170px; } } +.content-fullheight { flex-grow: 1;} + .contentheader { width: 100%; color: $COL_TEXT_DARK; diff --git a/www/fragments/blogview_euler_single.php b/www/fragments/blogview_euler_single.php index 2cafa19..0b30eed 100644 --- a/www/fragments/blogview_euler_single.php +++ b/www/fragments/blogview_euler_single.php @@ -9,7 +9,7 @@ $subview = $OPTIONS['subview']; $euler = Euler::listAll(); $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(); diff --git a/www/index.php b/www/index.php index 54b40e5..2b8be96 100644 --- a/www/index.php +++ b/www/index.php @@ -70,73 +70,89 @@ $URL_RULES = //############################################################################# -$path = strtolower(parse_url($_SERVER['REQUEST_URI'])['path']); -$pathparts = preg_split('@/@', $path, NULL, PREG_SPLIT_NO_EMPTY); -$partcount = count($pathparts); +try { + InitPHP(); -global $OPTIONS; -global $HEADER_ACTIVE; + $path = strtolower(parse_url($_SERVER['REQUEST_URI'])['path']); + $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) -{ - if ($partcount !== count($rule['url'])) continue; - - $urlparams = []; - - $match = true; - for($i = 0; $i < $partcount; $i++) + $HEADER_ACTIVE = 'none'; + + foreach ($URL_RULES as $rule) { - $comp = $rule['url'][$i]; - if (startsWith($comp, '?{') && endsWith($comp, '}')) - { - $ident = substr($comp, 2, strlen($comp)-3); - $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; - -} + if ($partcount !== count($rule['url'])) continue; + + $urlparams = []; + + $match = true; + for($i = 0; $i < $partcount; $i++) + { + $comp = $rule['url'][$i]; + if (startsWith($comp, '?{') && endsWith($comp, '}')) + { + $ident = substr($comp, 2, strlen($comp)-3); + $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; + + } + + { + // [404] - Page Not Found + $OPTIONS = []; + httpError('404', 'Page not found'); + return; + } + +} catch (Exception $e) { + + if (isProd()) + { + httpError('500 ', 'Internal server error'); + } + else + { + echo ''.$e->xdebug_message.'
'; + } -{ - // [404] - Page Not Found - $OPTIONS = []; - include 'pages/error_404.php'; - return; } diff --git a/www/internals/base.php b/www/internals/base.php index 9199ad7..c68f6b3 100644 --- a/www/internals/base.php +++ b/www/internals/base.php @@ -3,11 +3,28 @@ global $CONFIG; $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; $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) { $length = strlen($needle); @@ -22,7 +39,12 @@ function endsWith($haystack, $needle) 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) { @@ -81,4 +103,14 @@ function includeScriptOnce($script, $echo = true) $REGISTERED_SCRIPTS []= $script; return ""; } +} + +function printCSS() { + global $CSS_BASE; + echo ''; +} + +function isProd() { + global $CONFIG; + return $CONFIG['prod']; } \ No newline at end of file diff --git a/www/pages/blog_list.php b/www/pages/blog_list.php index 32dbd77..4ceada8 100644 --- a/www/pages/blog_list.php +++ b/www/pages/blog_list.php @@ -12,7 +12,7 @@ $allposts = Blog::listAllOrderedDescending(); Mikescher.com - Blog - +
diff --git a/www/pages/blog_view.php b/www/pages/blog_view.php index 52b60b2..946b69d 100644 --- a/www/pages/blog_view.php +++ b/www/pages/blog_view.php @@ -10,7 +10,7 @@ $subview = $OPTIONS['subview']; $post = Blog::getBlogpost($id); -if ($post === NULL) httpError(404, 'blogpost not found'); +if ($post === NULL) httpError(404, 'Blogpost not found'); ?> @@ -18,7 +18,7 @@ if ($post === NULL) httpError(404, 'blogpost not found'); Mikescher.com - Blog - + + + + + + Mikescher.com - <?php echo $errormsg; ?> + + + + +
+ + + +
+ +
+
+
+
+ +
+ +
+ + \ No newline at end of file diff --git a/www/pages/main.php b/www/pages/main.php index 88b26df..6e29333 100644 --- a/www/pages/main.php +++ b/www/pages/main.php @@ -6,7 +6,7 @@ Mikescher.com - +