diff --git a/www/internals/blog.php b/www/internals/blog.php index 6ffb112..12310b4 100644 --- a/www/internals/blog.php +++ b/www/internals/blog.php @@ -40,6 +40,45 @@ class Blog return null; } + public static function getFullBlogpost($id, $subview, &$error) + { + $post = self::getBlogpost($id); + if ($post === null) { $error="Blogpost not found"; return null; } + + $post['issubview'] = false; + + $isSubEuler = ($post['type'] === 'euler' && $subview !== ''); + $eulerproblem = null; + if ($isSubEuler) + { + require_once(__DIR__ . '/../internals/euler.php'); + $eulerproblem = Euler::getEulerProblemFromStrIdent($subview); + if ($eulerproblem === null) { $error="Project Euler entry not found"; return null; } + $post['submodel'] = $eulerproblem; + $post['issubview'] = true; + } + + $isSubAdventOfCode = ($post['type'] === 'aoc' && $subview !== ''); + $adventofcodeday = null; + if ($isSubAdventOfCode) + { + require_once(__DIR__ . '/../internals/adventofcode.php'); + $adventofcodeday = AdventOfCode::getDayFromStrIdent($post['extras']['aoc:year'], $subview); + if ($adventofcodeday === null) { $error="AdventOfCode entry not found"; return null; } + $post['submodel'] = $adventofcodeday; + $post['issubview'] = true; + } + + if ($isSubEuler) $post['title'] = $eulerproblem['title']; + if ($isSubAdventOfCode) $post['title'] = $adventofcodeday['title']; + + if ($isSubEuler) $post['canonical'] = $eulerproblem['canonical']; + if ($isSubAdventOfCode) $post['canonical'] = $adventofcodeday['canonical']; + + return $post; + + } + public static function getPostFragment($post) { return file_get_contents($post['file_fragment']); diff --git a/www/pages/blog_view.php b/www/pages/blog_view.php index c44f49e..72e9a7b 100644 --- a/www/pages/blog_view.php +++ b/www/pages/blog_view.php @@ -8,49 +8,27 @@ require_once (__DIR__ . '/../internals/blog.php'); $id = $OPTIONS['id']; $subview = $OPTIONS['subview']; -$post = Blog::getBlogpost($id); -if ($post === NULL) httpError(404, 'Blogpost not found'); - -$isSubEuler = ($post['type'] === 'euler' && $subview !== ''); -$isBaseEuler = ($post['type'] === 'euler'); -$eulerproblem = null; -if ($isSubEuler) -{ - require_once(__DIR__ . '/../internals/euler.php'); - $eulerproblem = Euler::getEulerProblemFromStrIdent($subview); -} -if ($eulerproblem === null) $isSubEuler = false; - -$isSubAdventOfCode = ($post['type'] === 'aoc' && $subview !== ''); -$isAdventOfCode = ($post['type'] === 'aoc'); -$adventofcodeday = null; -if ($isSubAdventOfCode) -{ - require_once(__DIR__ . '/../internals/adventofcode.php'); - $adventofcodeday = AdventOfCode::getDayFromStrIdent($post['extras']['aoc:year'], $subview); -} -if ($adventofcodeday === null) $isSubAdventOfCode = false; - -$htmltitle = $post['title']; -if ($isSubEuler) $htmltitle = $eulerproblem['title']; -if ($isSubAdventOfCode) $htmltitle = $adventofcodeday['title']; - -$canonical = $post['canonical']; -if ($isSubEuler) $canonical = $eulerproblem['canonical']; -if ($isSubAdventOfCode) $canonical = $adventofcodeday['canonical']; +$post = Blog::getFullBlogpost($id, $subview, $err); +if ($post === null) httpError(404, $err); ?>
-