Merge remote-tracking branch 'origin/main'

This commit is contained in:
Bruno Rybársky 2024-02-29 09:28:13 +01:00
commit 287eb99b98
17 changed files with 123 additions and 44 deletions

@ -70,6 +70,9 @@ async function handlePageResponse(data) {
if (data.Navigation) { if (data.Navigation) {
navbar.innerHTML = data.Navigation; navbar.innerHTML = data.Navigation;
} }
if (data.PageTitle) {
document.title = data.PageTitle;
}
if (data.Page) { if (data.Page) {
pageArea.innerHTML = data.Page; pageArea.innerHTML = data.Page;
@ -181,7 +184,7 @@ async function togglearticlecreate(){
} }
async function renderarticles(){ async function renderarticles(){
let template = document.querySelector('template[data-template-name="article"]').content.toString(); let template = document.querySelector('template[data-template-name="article"]').innerHTML;
let articles = await doAction( let articles = await doAction(
"/newsarticle", "/newsarticle",
{ {
@ -193,7 +196,7 @@ async function renderarticles(){
); );
let articleout = ""; let articleout = "";
for (const article of articles) { for (const article of articles.Articles) {
articleout += template.replace("__TEMPLATE_ARTICLE_TITLE__", article.Title).replace("__TEMPLATE_ARTICLE_AUTHOR__", article.WrittenByName).replace("__TEMPLATE_ARTICLE_DATE__", article.WrittenAt).replace("__TEMPLATE_ARTICLE_BODY__", article.Body) articleout += template.replace("__TEMPLATE_ARTICLE_TITLE__", article.Title).replace("__TEMPLATE_ARTICLE_AUTHOR__", article.WrittenByName).replace("__TEMPLATE_ARTICLE_DATE__", article.WrittenAt).replace("__TEMPLATE_ARTICLE_BODY__", article.Body)
} }
document.getElementById("articleslist").innerHTML = articleout; document.getElementById("articleslist").innerHTML = articleout;
@ -213,17 +216,26 @@ async function submitarticle(){
"Nastala chyba pri pridávaní článku", "Nastala chyba pri pridávaní článku",
false false
); );
togglearticlecreate(); await togglearticlecreate();
} }
async function articleInit(){ async function articleInit(){
let articleContainerElement = document.getElementById("articlecreatecontainer"); let articleContainerElement = document.getElementById("articlecreatecontainer");
let articleCreateOpenElement = document.getElementById("articlecreateopen");
articleContainerElement.addEventListener("keyup", function (ev) { articleContainerElement.addEventListener("keyup", function (ev) {
if(ev.which === 27){ if(ev.key === "Escape"){
togglearticlecreate(); togglearticlecreate();
} }
}) })
PageIntervals.push(setInterval(renderarticles, 300000)); PageIntervals.push(setInterval(renderarticles, 300000));
document.getElementById("articleprivilegeinput").setAttribute("max", UserInfo.Privileges);
if(UserInfo.Privileges < 2){
articleContainerElement.style.display = "none";
articleCreateOpenElement.style.display = "none";
}
else{
articleCreateOpenElement.style.display = "inline-block";
}
} }
async function onPageLoad() { async function onPageLoad() {
@ -247,7 +259,7 @@ async function onPageLoad() {
if (currentSite === "home" && currentPage === "account" && isLoggedIn()) { if (currentSite === "home" && currentPage === "account" && isLoggedIn()) {
await showDashboardGreeting(); await showDashboardGreeting();
} }
if (currentSite === "news" && currentPage === "index" && isLoggedIn()) { if (currentSite === "news" && currentPage === "index") {
await articleInit(); await articleInit();
} }
} }

@ -342,11 +342,22 @@ header a,
input, textarea { input, textarea {
background-color: var(--third-bg); background-color: var(--third-bg);
border: 2px solid var(--primary); border: 2px solid var(--primary);
border-radius: 50px; }
input::placeholder, textarea::placeholder{
color: var(--primary-text);
}
input{
border-radius: 25px;
}
textarea{
border-radius: 10px;
} }
button { button {
border-radius: 50px; border-radius: 25px;
border: 2px solid var(--primary); border: 2px solid var(--primary);
background: var(--third-bg); background: var(--third-bg);
color: var(--primary-text); color: var(--primary-text);
@ -368,14 +379,12 @@ button:hover {
} }
header.ye-span:hover + body{ header.ye-span:hover + body{
background: url('/assets/images/ye.jpg') !important; background: url('/assets/images/ye.jpg') repeat !important;
background-repeat: repeat !important;
background-size: 10% !important; background-size: 10% !important;
} }
body:has(.ye-span:hover) { body:has(.ye-span:hover) {
background: url('/assets/images/ye.jpg') !important; background: url('/assets/images/ye.jpg') repeat !important;
background-repeat: repeat !important;
background-size: 10% !important; background-size: 10% !important;
} }
@ -384,6 +393,17 @@ body:has(.ye-span:hover) {
border: 5px solid var(--primary); border: 5px solid var(--primary);
z-index: 5; z-index: 5;
margin: auto; margin: auto;
padding: 40px;
background-color: var(--primary-bg);
border-radius: 50px;
}
#articlecreate > * {
margin: 10px 0;
}
#articlecreateopen {
display: none;
} }
#articlecreatecontainer{ #articlecreatecontainer{
@ -399,6 +419,30 @@ body:has(.ye-span:hover) {
backdrop-filter: blur(2px); backdrop-filter: blur(2px);
} }
.hidden { .hidden {
display: none !important; display: none !important;
} }
div#articleslist{
width: 80vw;
left: 10vw;
position: relative;
}
div#articleslist > article > div.articleinfo > *{
width: fit-content;
}
div#articleslist > article > div.articleinfo{
display: flex;
flex-direction: row;
}
div#articleslist>article{
border: 4px solid var(--primary);
}
a.navsite_link.active:after{
}

@ -89,11 +89,10 @@ function verifyPassword($userID, $password): bool
function UpdateSession(): void function UpdateSession(): void
{ {
global $mysqli; global $mysqli;
$stmt = $mysqli->prepare("SELECT ID, FirstName, LastName, Nickname, Email, MinecraftNick, PrivilegeLevel, LastLoginAt, LoginCount, ClassID, FavoriteColor FROM Users WHERE ID = ? AND isActivated = 1"); $stmt = $mysqli->prepare("SELECT FirstName, LastName, Nickname, Email, MinecraftNick, PrivilegeLevel, LastLoginAt, LoginCount, ClassID, FavoriteColor FROM Users WHERE ID = ? AND isActivated = 1");
$stmt->bind_param("i", $_SESSION["ID"]); $stmt->bind_param("i", $_SESSION["ID"]);
$stmt->execute(); $stmt->execute();
$id = 0;
$first_name = ""; $first_name = "";
$last_name = ""; $last_name = "";
$nickname = ""; $nickname = "";
@ -104,11 +103,9 @@ function UpdateSession(): void
$favorite_color = 0; $favorite_color = 0;
$lastLoginAt = null; $lastLoginAt = null;
$loginCount = 0; $loginCount = 0;
$stmt->bind_result($id, $first_name, $last_name, $nickname, $email, $minecraft_nickname, $privilege_level, $lastLoginAt, $loginCount, $class_id, $favorite_color); $stmt->bind_result($first_name, $last_name, $nickname, $email, $minecraft_nickname, $privilege_level, $lastLoginAt, $loginCount, $class_id, $favorite_color);
$stmt->fetch(); $stmt->fetch();
$stmt->close(); $stmt->close();
$_SESSION["id"] = $id;
$_SESSION["first_name"] = $first_name; $_SESSION["first_name"] = $first_name;
$_SESSION["last_name"] = $last_name; $_SESSION["last_name"] = $last_name;
$_SESSION["nickname"] = $nickname; $_SESSION["nickname"] = $nickname;

@ -12,6 +12,7 @@
'endpoint_dir' => 'endpoints/', 'endpoint_dir' => 'endpoints/',
'page_dir' => 'pages/', 'page_dir' => 'pages/',
'protocol' => 'https://', 'protocol' => 'https://',
'site_prefix' => 'Adlerka',
'permissions' => [ 'permissions' => [
'logged_out' => 1, 'logged_out' => 1,
'logged_in_default' => 2, 'logged_in_default' => 2,
@ -26,6 +27,9 @@
'default_permissions' => 255, 'default_permissions' => 255,
], ],
'newsarticle' => [
'default_permissions' => 255,
],
'seo' => [ 'seo' => [
'author' => 'Tím AdlerkaTop', 'author' => 'Tím AdlerkaTop',
'description' => 'Toto je neoficiánla študentská stránka pre Adlerku, kde môžete nájsť plno zaujímavostí.', 'description' => 'Toto je neoficiánla študentská stránka pre Adlerku, kde môžete nájsť plno zaujímavostí.',

@ -27,7 +27,7 @@ function inlineLocalStylesFromHref($inputString): string
// Minify the CSS content // Minify the CSS content
$cssContent = minifyCss($cssContent); $cssContent = minifyCss($cssContent);
return "<style>{$cssContent}</style>"; return "<style>$cssContent</style>";
}, $inputString); }, $inputString);
} }
@ -41,7 +41,7 @@ function inlineScriptFromSrc($inputString): string
// Minify the JavaScript content // Minify the JavaScript content
$jsContent = minifyJs($jsContent); $jsContent = minifyJs($jsContent);
return "<script>{$jsContent}</script>"; return "<script>$jsContent</script>";
}, $inputString); }, $inputString);
} }

@ -1,5 +1,4 @@
<?php <?php
function getNewsArticles() :array function getNewsArticles() :array
{ {
global $mysqli; global $mysqli;
@ -7,9 +6,7 @@ function getNewsArticles() :array
$output = ["Status" => "Fail"]; // Default Status is "Fail" $output = ["Status" => "Fail"]; // Default Status is "Fail"
$articles = []; $articles = [];
if (isLoggedIn()) { $stmt = $mysqli->prepare("SELECT NewsArticles.ID, NewsArticles.WrittenAt, NewsArticles.WrittenBy, NewsArticles.Title, NewsArticles.Body, NewsArticles.FileList, Users.Nickname FROM NewsArticles INNER JOIN Users ON NewsArticles.WrittenBy = Users.ID WHERE NewsArticles.PrivilegeLevel <= ?;");
$stmt = $mysqli->prepare("SELECT NewsArticles.ID, NewsArticles.WrittenAt, NewsArticles.WrittenBy, NewsArticles.Title, NewsArticles.Body, NewsArticles.FileList, Users.Nickname FROM NewsArticles INNER JOIN Users ON NewsArticles.WrittenBy = Users.ID; ");
$id = 0; $id = 0;
$writtenAt = ""; $writtenAt = "";
$writtenBy = 0; $writtenBy = 0;
@ -18,6 +15,7 @@ function getNewsArticles() :array
$filelist = 0; $filelist = 0;
$writtenByName = ""; $writtenByName = "";
$stmt->bind_param("i", $_SESSION["privilege_level"]);
$stmt->bind_result($id, $writtenAt, $writtenBy, $title, $body, $filelist, $writtenByName); $stmt->bind_result($id, $writtenAt, $writtenBy, $title, $body, $filelist, $writtenByName);
$stmt->execute(); $stmt->execute();
@ -38,24 +36,29 @@ function getNewsArticles() :array
$output["Articles"] = $articles; $output["Articles"] = $articles;
} }
}
return $output; return $output;
} }
function addNewsArticle($title="Nazov", $body="Obsah") :array function addNewsArticle($title="Nazov", $body="Obsah", $privilegeLevel=0) :array
{ {
global $mysqli; global $mysqli;
global $routerConfig;
if ($privilegeLevel == 0){
$privilegeLevel = $routerConfig['newsarticle']['default_permissions'];
}
$output = ["Status" => "Fail"]; // Default Status is "Fail" $output = ["Status" => "Fail"]; // Default Status is "Fail"
if (isLoggedIn()) { if (isLoggedIn() && $privilegeLevel <= $_SESSION["privilege_level"]) {
$query = $mysqli->prepare("INSERT INTO NewsArticles (WrittenBy, Title, Body, FileList) VALUES (?, ?, ?, 0);"); $query = $mysqli->prepare("INSERT INTO NewsArticles (WrittenBy, Title, Body, FileList, PrivilegeLevel) VALUES (?, ?, ?, 0, ?);");
$query->bind_param("iss", $_SESSION["id"], htmlspecialchars($title), htmlspecialchars($body)); $minpriv = intval($privilegeLevel);
$query->bind_param("issi", $_SESSION["ID"], htmlspecialchars($title), htmlspecialchars($body), $minpriv);
$query->execute(); $query->execute();
if ($query->affected_rows > 0) { if ($query->affected_rows > 0) {
$output["Status"] = "Success"; $output["Status"] = "Success";
} }
}
$query->close(); $query->close();
}
return $output; return $output;
} }

@ -40,6 +40,10 @@ function renderPage($page_name = null, $site_name = null): array
$site_name = $routerRequest["site_name"]; $site_name = $routerRequest["site_name"];
} }
$site_title = str_replace("_", " ", $site_name);
$site_title = ucfirst($site_title);
if(!$page_name){ if(!$page_name){
$page_name = $routerRequest["page_name"]; $page_name = $routerRequest["page_name"];
} }
@ -109,10 +113,20 @@ function renderPage($page_name = null, $site_name = null): array
$page = ""; $page = "";
} }
if(!empty($pageMetadata["parameters"]["page_title"])){
$page_title = $pageMetadata["parameters"]["page_title"];
}
else{
$page_title = $page_name;
}
$page_title = $routerConfig['site_prefix'] . " " . $site_title . " " . $page_title;
return [ return [
"PageContent" => $page, "PageContent" => $page,
"PageName" => $page_name, "PageName" => $page_name,
"SiteName" => $site_name, "SiteName" => $site_name,
"PageTitle" => $page_title,
]; ];
} }
@ -130,12 +144,7 @@ function getPage($site_name_in = null, $page_name_in = null): string
$footer = file_get_contents($routerConfig["template_dir"] . "footer.html"); $footer = file_get_contents($routerConfig["template_dir"] . "footer.html");
if(!empty($pageMetadata["parameters"]["page_title"])){ $page_title = $page_tmp["PageTitle"];
$page_title = $pageMetadata["parameters"]["page_title"];
}
else{
$page_title = $page_name;
}
$dynamic_style = doDynamicStyling(); $dynamic_style = doDynamicStyling();
$dynamic_script_data = [ $dynamic_script_data = [
"currentPage" => $page_name, "currentPage" => $page_name,
@ -143,6 +152,7 @@ function getPage($site_name_in = null, $page_name_in = null): string
"currentTitle" => $page_title, "currentTitle" => $page_title,
"defaultPage" => $routerConfig["default_page"], "defaultPage" => $routerConfig["default_page"],
"defaultSite" => $routerConfig["default_site"], "defaultSite" => $routerConfig["default_site"],
"UserInfo_Privileges" => $_SESSION["privilege_level"],
]; ];
if(isLoggedIn()){ if(isLoggedIn()){
$dynamic_script_data += [ $dynamic_script_data += [
@ -214,5 +224,6 @@ function getPageEndpoint($page_name, $site_name) :array
"Status" => "Success", "Status" => "Success",
"Page" => $page_tmp["PageContent"], "Page" => $page_tmp["PageContent"],
"PageLocation" => $page_location, "PageLocation" => $page_location,
"PageTitle" => $page_tmp["PageTitle"],
]; ];
} }

@ -35,7 +35,8 @@ function generateSitemap(): void{
$page_required_permission = $routerConfig["page"]["default_permissions"]; $page_required_permission = $routerConfig["page"]["default_permissions"];
} }
} elseif ($page_file_tmp[1] == "php") { } elseif ($page_file_tmp[1] == "php") {
$page_required_permission = getDynamicPermission($page_file_path); $pageMetadata = getDynamicMetadata($page_file_path);
$page_required_permission = getDynamicPermission($pageMetadata);
} else { } else {
$page_required_permission = $routerConfig["page"]["default_permissions"]; $page_required_permission = $routerConfig["page"]["default_permissions"];
} }

@ -1,3 +1,4 @@
<!--suppress HtmlUnknownTag, HtmlUnknownTag -->
<page minimal_permission_level="1" secret="no" page_title="Domov"></page> <page minimal_permission_level="1" secret="no" page_title="Domov"></page>
<header> <header>
<h1 class="title">Vitaj, na tejto úžasnej stránke</h1> <h1 class="title">Vitaj, na tejto úžasnej stránke</h1>

@ -1,3 +1,4 @@
<!--suppress HtmlUnknownTag, HtmlUnknownTag -->
<page minimal_permission_level="1" secret="no" page_title="Memes"></page> <page minimal_permission_level="1" secret="no" page_title="Memes"></page>
<header> <header>
<h1 class="title">Adlerka Memes</h1> <h1 class="title">Adlerka Memes</h1>

@ -15,13 +15,14 @@ if($articles_tmp['Status'] == "Success"){
} }
$articleTemplate = file_get_contents($routerConfig["template_dir"] . "newsArticle.html"); $articleTemplate = file_get_contents($routerConfig["template_dir"] . "newsArticle.html");
$output = str_replace("__TEMPLATE_FOR_ARTICLE_CONTENT__", $articleTemplate, $output);
foreach ($articles as $article){ foreach ($articles as $article){
$articleTitle = htmlspecialchars($article["Title"]); $articleTitle = htmlspecialchars($article["Title"]);
$articleBody = htmlspecialchars($article["Body"]); $articleBody = htmlspecialchars($article["Body"]);
$articleFileList = $article["FileList"]; $articleFileList = $article["FileList"];
$articleWrittenBy = $article["WrittenBy"]; $articleWrittenBy = $article["WrittenBy"];
$articleWrittenAt = htmlspecialchars($article["WrittenAt"]); $articleWrittenAt = htmlspecialchars($article["WrittenAt"]);
$articleWrittenByName = htmlspecialchars($article["Nickname"]); $articleWrittenByName = htmlspecialchars($article["WrittenByName"]);
$articleTemplate = str_replace("__TEMPLATE_ARTICLE_TITLE__", $articleTitle, $articleTemplate); $articleTemplate = str_replace("__TEMPLATE_ARTICLE_TITLE__", $articleTitle, $articleTemplate);
$articleTemplate = str_replace("__TEMPLATE_ARTICLE_AUTHOR__", $articleWrittenByName, $articleTemplate); $articleTemplate = str_replace("__TEMPLATE_ARTICLE_AUTHOR__", $articleWrittenByName, $articleTemplate);
@ -31,14 +32,13 @@ foreach ($articles as $article){
$articles_out .= $articleTemplate; $articles_out .= $articleTemplate;
} }
$output = str_replace("__TEMPLATE_FOR_ARTICLE_CONTENT__", $articleTemplate, $output);
$output = str_replace("__TEMPLATE__ARTICLES_HERE__", $articles_out, $output); $output = str_replace("__TEMPLATE__ARTICLES_HERE__", $articles_out, $output);
return [ return [
"output" => $output, "output" => $output,
"parameters" => "parameters" =>
[ [
"minimal_permission_level" => 2, "minimal_permission_level" => 1,
"secret" => "no", "secret" => "no",
"page_title" => "Novinky" "page_title" => "Novinky"
] ]

@ -1,3 +1,4 @@
<!--suppress HtmlUnknownTag, HtmlUnknownTag -->
<page minimal_permission_level="2" secret="no" page_title="Zošit"></page> <page minimal_permission_level="2" secret="no" page_title="Zošit"></page>
<header> <header>
<h1 class="title">Adlerka Zošit</h1> <h1 class="title">Adlerka Zošit</h1>

@ -1,3 +1,4 @@
<!--suppress HtmlUnknownTag, HtmlUnknownTag -->
<page minimal_permission_level="1" secret="no" page_title="Domov"></page> <page minimal_permission_level="1" secret="no" page_title="Domov"></page>
<header> <header>
<h1 class="title">Vitaj na oficiálnej AdlerkaSMP stránke</h1> <h1 class="title">Vitaj na oficiálnej AdlerkaSMP stránke</h1>

@ -1,2 +1,3 @@
<page minimal_permission_level="1" secret="no" page_title="AdlerkaSMP info"></page> <!--suppress HtmlUnknownTag, HtmlUnknownTag -->
<page minimal_permission_level="1" secret="no" page_title="Info"></page>
<h1>Vitaj na oficiálnej stránke Informácii o AdlerkaSMP</h1> <h1>Vitaj na oficiálnej stránke Informácii o AdlerkaSMP</h1>

@ -1,8 +1,9 @@
<article> <article>
<h2 class='newstitle'>__TEMPLATE_ARTICLE_TITLE__</h2> <h2 class='newstitle'>__TEMPLATE_ARTICLE_TITLE__</h2>
<br> <div class="articleinfo">
<p class='newsauthor'>__TEMPLATE_ARTICLE_AUTHOR__</p> <p class='newsauthor'><i class="ri-user-line"></i>__TEMPLATE_ARTICLE_AUTHOR__</p>
<p class='newsdate'>__TEMPLATE_ARTICLE_DATE__</p> <p class='newsdate'><i class="ri-calendar-line"></i>__TEMPLATE_ARTICLE_DATE__</p>
</div>
<hr> <hr>
<div class='newsbody'> <div class='newsbody'>
__TEMPLATE_ARTICLE_BODY__ __TEMPLATE_ARTICLE_BODY__

@ -17,6 +17,7 @@
<div id="articlecreate"> <div id="articlecreate">
<input type="text" placeholder="Article Title" id="articletitleinput"><br> <input type="text" placeholder="Article Title" id="articletitleinput"><br>
<textarea id="articlebodyinput" placeholder="Article Body" rows="20" cols="80"></textarea><br> <textarea id="articlebodyinput" placeholder="Article Body" rows="20" cols="80"></textarea><br>
<input type="number" id="articleprivilegeinput" min="1" value="1" step="1"><br>
<button id="articlesubmit" onclick="submitarticle()">Add</button> <button id="articlesubmit" onclick="submitarticle()">Add</button>
</div> </div>
</div> </div>

@ -10,7 +10,7 @@
__TEMPLATE__DYNAMIC__STYLE__ __TEMPLATE__DYNAMIC__STYLE__
<script async src="https://umami.brn.systems/script.js" data-website-id="95e93885-5c19-4cab-ba9b-2f746a316a2a"></script> <script async src="https://umami.brn.systems/script.js" data-website-id="95e93885-5c19-4cab-ba9b-2f746a316a2a"></script>
<script async src="/assets/script.js"></script> <script async src="/assets/script.js"></script>
<title>Adlerka __TEMPLATE_PAGE_TITLE__</title> <title>__TEMPLATE_PAGE_TITLE__</title>
__TEMPLATE_SEO_STUFF__ __TEMPLATE_SEO_STUFF__
</head> </head>
<body> <body>