flash.moe/pages/blog.php

95 lines
3.3 KiB
PHP
Raw Normal View History

2020-07-30 00:55:37 +00:00
<?php
2022-02-04 20:30:52 +00:00
namespace Makai;
2022-02-05 03:35:42 +00:00
$router->get('/blog.php', function() {
header('Location: /old-blog/' . (int)filter_input(INPUT_GET, 'p', FILTER_SANITIZE_NUMBER_INT));
return 302;
});
$router->get('/blog-post.php', function() {
header('Location: /old-blog/' . (int)filter_input(INPUT_GET, 'p', FILTER_SANITIZE_NUMBER_INT));
return 302;
});
$router->get('/blog/:id', function(string $id) {
header('Location: /old-blog/' . intval($id));
return 302;
});
$router->get('/old-blog', function() {
$blogInfo = json_decode(file_get_contents(MKI_DIR_PUB . '/old_blog_posts.json'));
$body = fm_component('header', [
'title' => 'flash.moe / old blog posts',
2020-10-03 16:22:27 +00:00
]);
2022-02-05 03:35:42 +00:00
$body .= <<<HTML
<div style="max-width: 1000px; margin: 0 auto; font-size: 20px; line-height: 1.7em;">
<div style="margin: 5px; background-color: #222; border-radius: 5px; padding: 2px 5px; text-align: center;">List of old blog posts to enjoy while I Eventually make the new script.</div>
</div>
HTML;
$body .= '<div class="ob-wrapper"><div class="ob-blogs">';
foreach($blogInfo as $postInfo) {
$preview = trim(explode("\n", $postInfo->post_text)[0]);
$dateCustom = date('Y-m-d @ H:i:s T', $postInfo->post_published);
$dateISO = date('c', $postInfo->post_published);
$body .= <<<HTML
<div class="ob-blog ob-preview">
<h1><a href="/old-blog/{$postInfo->post_id}">{$postInfo->post_title}</a></h1>
<time datetime="{$dateISO}">{$dateCustom}</time>
<p>{$preview}</p>
<a class="ob-continue" href="/old-blog/{$postInfo->post_id}">Continue reading</a>
</div>\r\n
HTML;
}
$body .= '</div></div>';
$body .= fm_component('footer');
return $body;
});
$router->get('/old-blog/:id', function(string $id) {
if(!is_numeric($id))
return 404;
$postId = intval($id);
$blogInfo = json_decode(file_get_contents(MKI_DIR_PUB . '/old_blog_posts.json'));
foreach($blogInfo as $postInfo) {
if($postInfo->post_id !== $postId)
continue;
$dateCustom = date('Y-m-d @ H:i:s T', $postInfo->post_published);
$dateISO = date('c', $postInfo->post_published);
$preview = trim(explode("\n", $postInfo->post_text)[0]);
$body = fm_component('header', [
'title' => 'flash.moe / ' . $postInfo->post_title,
]);
$body .= '<div class="ob-wrapper"><div class="ob-blog"><div class="ob-blog">';
if(!empty($postInfo->post_new_url))
$body .= "<a href=\"{$postInfo->post_new_url}\" style=\"display: block; text-align: center; color: #fff; text-decoration: none; font-size: 2em; line-height: 1.5em; padding: 20px 10px; margin: 10px 0; font-weight: bold; background-color: #222; border-radius: 5px\">This post has a new url, please go here instead!</a>";
$body .= "<h1>{$postInfo->post_title}</h1>";
$body .= "<time datetime=\"{$dateISO}\">{$dateCustom}</time>";
$splitLines = explode("\n", $postInfo->post_text);
foreach ($splitLines as $paragraph)
if(!empty($paragraph))
$body .= '<p>' . trim($paragraph) . '</p>';
$body .= '</div></div></div>';
$body .= fm_component('footer');
return $body;
}
return 404;
});