adlerka.top/pages/news/index.php
2024-02-22 13:57:05 +01:00

46 lines
1.6 KiB
PHP

<?php
require_once "lib/router.php";
require_once "lib/newsarticle.php";
global $routerConfig;
$output = file_get_contents($routerConfig["template_dir"] . "newsArticles.html");
$articles_out = "";
$articles = [];
$articles_tmp = getNewsArticles();
if($articles_tmp['Status'] == "Success"){
$articles = $articles_tmp["Articles"];
}
$articleTemplate = file_get_contents($routerConfig["template_dir"] . "newsArticle.html");
foreach ($articles as $article){
$articleTitle = htmlspecialchars($article["Title"]);
$articleBody = htmlspecialchars($article["Body"]);
$articleFileList = $article["FileList"];
$articleWrittenBy = $article["WrittenBy"];
$articleWrittenAt = htmlspecialchars($article["WrittenAt"]);
$articleWrittenByName = htmlspecialchars($article["Nickname"]);
$articleTemplate = str_replace("__TEMPLATE_ARTICLE_TITLE__", $articleTitle, $articleTemplate);
$articleTemplate = str_replace("__TEMPLATE_ARTICLE_AUTHOR__", $articleWrittenByName, $articleTemplate);
$articleTemplate = str_replace("__TEMPLATE_ARTICLE_DATE__", $articleWrittenAt, $articleTemplate);
$articleTemplate = str_replace("__TEMPLATE_ARTICLE_BODY__", $articleBody, $articleTemplate);
$articles_out .= $articleTemplate;
}
$output = str_replace("__TEMPLATE_FOR_ARTICLE_CONTENT__", $articleTemplate, $output);
$output = str_replace("__TEMPLATE__ARTICLES_HERE__", $articles_out, $output);
return [
"output" => $output,
"parameters" =>
[
"minimal_permission_level" => 2,
"secret" => "no",
"page_title" => "Novinky"
]
];