2023-09-04 21:13:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class Blog
|
|
|
|
{
|
|
|
|
|
|
|
|
private array $links = [];
|
|
|
|
|
2023-09-08 08:19:05 +02:00
|
|
|
public function __construct()
|
2023-09-04 21:13:29 +02:00
|
|
|
{
|
|
|
|
$this->loadConfig();
|
2023-09-08 08:19:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function run()
|
|
|
|
{
|
2023-09-04 21:13:29 +02:00
|
|
|
$this->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function loadConfig()
|
|
|
|
{
|
|
|
|
require_once "config.php";
|
|
|
|
foreach ($links as $title => $url) {
|
|
|
|
$this->links[] = new Link($title, $url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function render()
|
|
|
|
{
|
|
|
|
extract($this->populateViews());
|
|
|
|
include "views/index.phtml";
|
|
|
|
}
|
|
|
|
|
|
|
|
private function populateViews(): array
|
|
|
|
{
|
|
|
|
return array_merge(
|
|
|
|
["lang" => BLOG_LANGUAGE],
|
|
|
|
$this->populateHeader(),
|
|
|
|
$this->populateMainView(),
|
|
|
|
$this->populateBio(),
|
|
|
|
$this->populateNavByTag(),
|
|
|
|
$this->populateNavByLatest(),
|
|
|
|
$this->populateFooter()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function populateHeader(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
"title" => BLOG_TITLE,
|
|
|
|
"has_sub_title" => BLOG_SUB_TITLE !== "",
|
|
|
|
"sub_title" => BLOG_SUB_TITLE
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
private function populateMainView(): array
|
|
|
|
{
|
|
|
|
$variables = [];
|
|
|
|
$view = filter_input(INPUT_GET, "view", FILTER_SANITIZE_STRING) ?: "single";
|
|
|
|
$variables["view"] = $view;
|
|
|
|
switch ($view) {
|
|
|
|
case "single":
|
|
|
|
$date = filter_input(INPUT_GET, "date", FILTER_SANITIZE_STRING);
|
|
|
|
$ref = filter_input(INPUT_GET, "ref", FILTER_SANITIZE_STRING);
|
|
|
|
$variables["article"] = ($date !== null and $ref !== null) ?
|
|
|
|
ArticleManager::get(str_replace("-", "", $date) . $ref) :
|
|
|
|
ArticleManager::getNewest();
|
|
|
|
break;
|
|
|
|
case "tags":
|
|
|
|
$tag = filter_input(INPUT_GET, "tag", FILTER_SANITIZE_STRING) ?: "";
|
|
|
|
$variables["articles"] = ArticleManager::getMultiple(TagManager::getFromTag($tag));
|
|
|
|
break;
|
|
|
|
case "archives":
|
|
|
|
$variables["dates"] = ArticleManager::getAll();;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $variables;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function populateBio(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
"author" => AUTHOR_NICKNAME,
|
|
|
|
"bio" => AUTHOR_BIOGRAPHY,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
private function populateNavByTag(): array
|
|
|
|
{
|
|
|
|
return ["tags" => TagManager::getTags()];
|
|
|
|
}
|
|
|
|
|
|
|
|
private function populateNavByLatest(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
"latest" => ArticleManager::getLatestArticles(ARTICLE_COUNT_IN_NAV)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
private function populateFooter(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
"has_links" => count($this->links) > 0,
|
|
|
|
"links" => $this->links,
|
|
|
|
"footer" => $this->getFooterString()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getFooterString(): string
|
|
|
|
{
|
|
|
|
$currentYear = getdate()["year"];
|
|
|
|
$footerYear = BLOG_CREATION_YEAR .
|
|
|
|
(BLOG_CREATION_YEAR !== $currentYear ? " - $currentYear" : "");
|
|
|
|
$footerAuthor = AUTHOR_NICKNAME .
|
|
|
|
(AUTHOR_REALNAME !== "" ? " (" . AUTHOR_REALNAME . ")" : "");
|
|
|
|
return "$footerYear. $footerAuthor";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|