From 6f90fb912b406025e3d7c0adb05228dbb82abc49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Mon, 20 Jan 2020 21:13:26 +0100 Subject: [PATCH] more dynamic header --- www/fragments/blogview_aoc_list.php | 2 ++ www/fragments/blogview_aoc_single.php | 2 ++ www/frames/default_frame.php | 30 +++++++++++++++++++++--- www/index.php | 4 ++++ www/internals/modules/adventofcode.php | 3 ++- www/internals/modules/selftest.php | 12 ++++++---- www/internals/pageframeoptions.php | 3 +++ www/internals/utils.php | 4 ++++ www/internals/website.php | 2 +- www/pages/adventofcode_day.php | 21 +++++++++++++++++ www/pages/adventofcode_year.php | 32 ++++++++++++++++++++++++++ www/pages/blog_view.php | 2 +- www/pages/books_view.php | 2 +- 13 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 www/pages/adventofcode_day.php create mode 100644 www/pages/adventofcode_year.php diff --git a/www/fragments/blogview_aoc_list.php b/www/fragments/blogview_aoc_list.php index b5a0eb9..673202d 100644 --- a/www/fragments/blogview_aoc_list.php +++ b/www/fragments/blogview_aoc_list.php @@ -15,6 +15,8 @@ $post = $parameter['blogpost']; $year = $post['extras']['aoc:year']; +$FRAME_OPTIONS->alternative_url = "/adventofcode/$year"; + ?>
diff --git a/www/fragments/blogview_aoc_single.php b/www/fragments/blogview_aoc_single.php index 12a37be..ed677b2 100644 --- a/www/fragments/blogview_aoc_single.php +++ b/www/fragments/blogview_aoc_single.php @@ -17,6 +17,8 @@ $year = $post['extras']['aoc:year']; $day = $SITE->modules->AdventOfCode()->getDayFromStrIdent($year, $subview); if ($day === NULL) { $FRAME_OPTIONS->forceResult(404, 'AdventOfCode entry not found'); return; } + +$FRAME_OPTIONS->alternative_url = $day['url-alternative']; ?>
diff --git a/www/frames/default_frame.php b/www/frames/default_frame.php index 9b16bbe..e1989c7 100644 --- a/www/frames/default_frame.php +++ b/www/frames/default_frame.php @@ -23,7 +23,9 @@ require_once (__DIR__ . '/../internals/website.php'); canonical_url !== null) echo '' . "\n"; + if ($FRAME_OPTIONS->canonical_url !== null) echo '' . "\n"; + if ($FRAME_OPTIONS->alternative_url !== null) echo '' . "\n"; + foreach ($FRAME_OPTIONS->stylesheets as $cssfile) echo '' . "\n"; foreach ($FRAME_OPTIONS->scripts as $scriptfile) { @@ -41,15 +43,37 @@ require_once (__DIR__ . '/../internals/website.php');
+ Home + Project Euler + Blog + Programs + + activeHeader === 'aoc' || intval(date('m')) === 12): ?> + Advent of Code + + + activeHeader === 'books'): ?> + Books + + Tools - isLoggedInByCookie()): ?>Admin + + isLoggedInByCookie()): ?> + Admin + + About +
- isLoggedInByCookie()): ?> + + isLoggedInByCookie()): ?> + + + Github
diff --git a/www/index.php b/www/index.php index f82a573..8029657 100644 --- a/www/index.php +++ b/www/index.php @@ -60,6 +60,10 @@ $URL_RULES = [ 'url' => ['log', '?{id}', '?{name}', '?{subview}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ], [ 'url' => ['blogpost', 'view'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%GET%', 'subview' => '' ], ], + [ 'url' => ['adventofcode'], 'target' => 'adventofcode_year.php', 'options' => [ ], 'parameter' => [ 'year' => '' ], ], + [ 'url' => ['adventofcode', '?{year}'], 'target' => 'adventofcode_year.php', 'options' => [ ], 'parameter' => [ 'year' => '%URL%' ], ], + [ 'url' => ['adventofcode', '?{year}', '?{day}'], 'target' => 'adventofcode_day.php', 'options' => [ ], 'parameter' => [ 'year' => '%URL%', 'day' => '%URL%' ], ], + [ 'url' => ['webapps'], 'target' => 'webapps_list.php', 'options' => [ ], 'parameter' => [ ], ], [ 'url' => ['highscores', 'list.php'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], diff --git a/www/internals/modules/adventofcode.php b/www/internals/modules/adventofcode.php index 0e3a0e1..9a3503e 100644 --- a/www/internals/modules/adventofcode.php +++ b/www/internals/modules/adventofcode.php @@ -83,7 +83,8 @@ class AdventOfCode implements IWebsiteModule $n2p = str_pad($a['day'], 2, '0', STR_PAD_LEFT); $a['day-padded'] = $n2p; - $a['url'] = '/blog/' . $yeardata['blog-id'] . '/Advent_of_Code_' . $year . '/day-' . $n2p; + $a['url'] = '/blog/' . $yeardata['blog-id'] . '/Advent_of_Code_' . $year . '/day-' . $n2p; + $a['url-alternative'] = '/adventofcode/' . $year . '/' . $n2p; $a['canonical'] = "https://www.mikescher.com" . $a['url']; $a['url_aoc'] = $yeardata['url-aoc'] . $a['day']; // adventofcode.com/{year}/day/{day} diff --git a/www/internals/modules/selftest.php b/www/internals/modules/selftest.php index 2af2bda..f8b8656 100644 --- a/www/internals/modules/selftest.php +++ b/www/internals/modules/selftest.php @@ -97,11 +97,13 @@ class SelfTest implements IWebsiteModule $this->addMethodPathStatus( "web::euler::euler-404-2", 404, '/blog/1/Project_Euler_with_Befunge/problem-99999'); $this->addMethodPathStatus( "web::euler::euler-404-3", 404, '/blog/1/Project_Euler_with_Befunge/asdf'); - $this->addMethodMultiPathStatus("web::aoc::aoc-list-1", 200, '{0}', function(){ return array_map(function($x){return Website::inst()->modules->AdventOfCode()->getURLForYear($x);},Website::inst()->modules->AdventOfCode()->listYears()); }); - $this->addMethodMultiPathStatus("web::aoc::aoc-show-1", 200, '{0}', function(){ return array_key_map(Website::inst()->modules->AdventOfCode()->listAllDays(), 'url'); }); - $this->addMethodPathStatus( "web::aoc::aoc-404-1", 404, '/blog/25/Advent_of_Code_2017/day-26'); - $this->addMethodPathStatus( "web::aoc::aoc-404-2", 404, '/blog/23/Advent_of_Code_2018/day-27'); - $this->addMethodPathStatus( "web::aoc::aoc-404-3", 404, '/blog/24/Advent_of_Code_2019/day-28'); + $this->addMethodMultiPathStatus("web::aoc::aoc-list-1", 200, '{0}', function(){ return array_map(function($x){return Website::inst()->modules->AdventOfCode()->getURLForYear($x);},Website::inst()->modules->AdventOfCode()->listYears()); }); + $this->addMethodMultiPathStatus("web::aoc::aoc-show-1", 200, '{0}', function(){ return array_key_map(Website::inst()->modules->AdventOfCode()->listAllDays(), 'url'); }); + $this->addMethodPathStatus( "web::aoc::aoc-404-1", 404, '/blog/25/Advent_of_Code_2017/day-26'); + $this->addMethodPathStatus( "web::aoc::aoc-404-2", 404, '/blog/23/Advent_of_Code_2018/day-27'); + $this->addMethodPathStatus( "web::aoc::aoc-404-3", 404, '/blog/24/Advent_of_Code_2019/day-28'); + $this->addMethodMultiPathStatus("web::aoc::aoc-redirect-1", 302, '{0}', function(){ return array_key_map(Website::inst()->modules->AdventOfCode()->listAllDays(), 'url-alternative'); }); + $this->addMethodMultiPathStatus("web::aoc::aoc-redirect-1", 302, '/adventofcode/{0}', function(){ return Website::inst()->modules->AdventOfCode()->listYears(); }); $this->addCheckConsistency("modules::database::database-check-consistency", function(){ return Website::inst()->modules->Database(); }); $this->addCheckConsistency("modules::blog::blog-check-consistency", function(){ return Website::inst()->modules->Blog(); }); diff --git a/www/internals/pageframeoptions.php b/www/internals/pageframeoptions.php index c9cc72b..7260f7a 100644 --- a/www/internals/pageframeoptions.php +++ b/www/internals/pageframeoptions.php @@ -36,6 +36,9 @@ class PageFrameOptions /** @var string */ public $canonical_url = null; + /** @var string */ + public $alternative_url = null; + /** @var string[] */ public $contentCSSClasses = [ 'content-responsive' ]; diff --git a/www/internals/utils.php b/www/internals/utils.php index 6debb91..cb966c6 100644 --- a/www/internals/utils.php +++ b/www/internals/utils.php @@ -283,4 +283,8 @@ function curl_http_request($url) return [ 'output'=>$output, 'statuscode'=>$httpcode, 'redirect'=>$redirect, 'errnum'=>$errnum, 'errstr'=>$errmsg ]; } +function array_last(array $arr) +{ + return $arr[count($arr)-1]; +} diff --git a/www/internals/website.php b/www/internals/website.php index ffe41da..20b3a42 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -68,7 +68,7 @@ class Website if ($result->force_redirect) { - header('Location: ' . $result->force_redirect_url); + header('Location: ' . $result->force_redirect_url); // http 302: Found exit(); } diff --git a/www/pages/adventofcode_day.php b/www/pages/adventofcode_day.php new file mode 100644 index 0000000..c24a812 --- /dev/null +++ b/www/pages/adventofcode_day.php @@ -0,0 +1,21 @@ + + +parameter['year']); +$day = intval($ROUTE->parameter['day']); + +if ($SITE->modules->AdventOfCode()->getSingleDay($year, $day) === null) +{ + $FRAME_OPTIONS->setForced404('Advent of Code not found'); + return; +} + +$FRAME_OPTIONS->setForcedRedirect($SITE->modules->AdventOfCode()->getSingleDay($year, $day)['url']); +?> diff --git a/www/pages/adventofcode_year.php b/www/pages/adventofcode_year.php new file mode 100644 index 0000000..57437b6 --- /dev/null +++ b/www/pages/adventofcode_year.php @@ -0,0 +1,32 @@ + + +parameter['year'] === '') +{ + $year = array_last($SITE->modules->AdventOfCode()->listYears()); + $FRAME_OPTIONS->setForcedRedirect($SITE->modules->AdventOfCode()->getURLForYear($year)); + return; +} +else +{ + $year = intval($ROUTE->parameter['year']); + + if (in_array($year, $SITE->modules->AdventOfCode()->listYears())) + { + $FRAME_OPTIONS->setForcedRedirect($SITE->modules->AdventOfCode()->getURLForYear($year)); + return; + } + else + { + $FRAME_OPTIONS->setForced404('Advent of Code not found'); + return; + } +} +?> diff --git a/www/pages/blog_view.php b/www/pages/blog_view.php index 595c105..814fafc 100644 --- a/www/pages/blog_view.php +++ b/www/pages/blog_view.php @@ -18,7 +18,7 @@ $FRAME_OPTIONS->canonical_url = $post['canonical']; if ($post['type'] == 'euler') $FRAME_OPTIONS->activeHeader = 'euler'; -else if ($post['type'] == 'euler' && $post['issubview']) +else if ($post['type'] == 'aoc') $FRAME_OPTIONS->activeHeader = 'aoc'; else $FRAME_OPTIONS->activeHeader = 'blog'; diff --git a/www/pages/books_view.php b/www/pages/books_view.php index 59de11a..422bbf7 100644 --- a/www/pages/books_view.php +++ b/www/pages/books_view.php @@ -14,7 +14,7 @@ if ($book === null) { $FRAME_OPTIONS->setForced404("Books not found"); return; } $FRAME_OPTIONS->title = $book['title']; $FRAME_OPTIONS->canonical_url = $book['url']; -$FRAME_OPTIONS->activeHeader = 'book'; +$FRAME_OPTIONS->activeHeader = 'books'; $FRAME_OPTIONS->addScript('/data/javascript/ms_basic.js', true); ?>