diff --git a/assets/script.js b/assets/script.js index aa6df08..2d5e6d3 100644 --- a/assets/script.js +++ b/assets/script.js @@ -70,6 +70,9 @@ async function handlePageResponse(data) { if (data.Navigation) { navbar.innerHTML = data.Navigation; } + if (data.PageTitle) { + document.title = data.PageTitle; + } if (data.Page) { pageArea.innerHTML = data.Page; @@ -181,7 +184,7 @@ async function togglearticlecreate(){ } 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( "/newsarticle", { @@ -193,7 +196,7 @@ async function renderarticles(){ ); 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) } document.getElementById("articleslist").innerHTML = articleout; @@ -213,17 +216,26 @@ async function submitarticle(){ "Nastala chyba pri pridávaní článku", false ); - togglearticlecreate(); + await togglearticlecreate(); } async function articleInit(){ let articleContainerElement = document.getElementById("articlecreatecontainer"); + let articleCreateOpenElement = document.getElementById("articlecreateopen"); articleContainerElement.addEventListener("keyup", function (ev) { - if(ev.which === 27){ + if(ev.key === "Escape"){ togglearticlecreate(); } }) 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() { @@ -247,7 +259,7 @@ async function onPageLoad() { if (currentSite === "home" && currentPage === "account" && isLoggedIn()) { await showDashboardGreeting(); } - if (currentSite === "news" && currentPage === "index" && isLoggedIn()) { + if (currentSite === "news" && currentPage === "index") { await articleInit(); } } diff --git a/assets/style.css b/assets/style.css index a897989..3b7c5eb 100644 --- a/assets/style.css +++ b/assets/style.css @@ -342,11 +342,22 @@ header a, input, textarea { background-color: var(--third-bg); 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 { - border-radius: 50px; + border-radius: 25px; border: 2px solid var(--primary); background: var(--third-bg); color: var(--primary-text); @@ -368,14 +379,12 @@ button:hover { } header.ye-span:hover + body{ - background: url('/assets/images/ye.jpg') !important; - background-repeat: repeat !important; + background: url('/assets/images/ye.jpg') repeat !important; background-size: 10% !important; } body:has(.ye-span:hover) { - background: url('/assets/images/ye.jpg') !important; - background-repeat: repeat !important; + background: url('/assets/images/ye.jpg') repeat !important; background-size: 10% !important; } @@ -384,6 +393,17 @@ body:has(.ye-span:hover) { border: 5px solid var(--primary); z-index: 5; margin: auto; + padding: 40px; + background-color: var(--primary-bg); + border-radius: 50px; +} + +#articlecreate > * { + margin: 10px 0; +} + +#articlecreateopen { + display: none; } #articlecreatecontainer{ @@ -399,6 +419,30 @@ body:has(.ye-span:hover) { backdrop-filter: blur(2px); } + .hidden { 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{ + } \ No newline at end of file diff --git a/lib/account.php b/lib/account.php index 8a3ee77..ddfd5e3 100644 --- a/lib/account.php +++ b/lib/account.php @@ -89,11 +89,10 @@ function verifyPassword($userID, $password): bool function UpdateSession(): void { 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->execute(); - $id = 0; $first_name = ""; $last_name = ""; $nickname = ""; @@ -104,11 +103,9 @@ function UpdateSession(): void $favorite_color = 0; $lastLoginAt = null; $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->close(); - - $_SESSION["id"] = $id; $_SESSION["first_name"] = $first_name; $_SESSION["last_name"] = $last_name; $_SESSION["nickname"] = $nickname; diff --git a/lib/config.php b/lib/config.php index e180cc2..0f49b25 100644 --- a/lib/config.php +++ b/lib/config.php @@ -12,6 +12,7 @@ 'endpoint_dir' => 'endpoints/', 'page_dir' => 'pages/', 'protocol' => 'https://', + 'site_prefix' => 'Adlerka', 'permissions' => [ 'logged_out' => 1, 'logged_in_default' => 2, @@ -26,6 +27,9 @@ 'default_permissions' => 255, ], + 'newsarticle' => [ + 'default_permissions' => 255, + ], 'seo' => [ 'author' => 'Tím AdlerkaTop', 'description' => 'Toto je neoficiánla študentská stránka pre Adlerku, kde môžete nájsť plno zaujímavostí.', diff --git a/lib/inliner.php b/lib/inliner.php index 4761191..04fc11a 100644 --- a/lib/inliner.php +++ b/lib/inliner.php @@ -27,7 +27,7 @@ function inlineLocalStylesFromHref($inputString): string // Minify the CSS content $cssContent = minifyCss($cssContent); - return ""; + return ""; }, $inputString); } @@ -41,7 +41,7 @@ function inlineScriptFromSrc($inputString): string // Minify the JavaScript content $jsContent = minifyJs($jsContent); - return ""; + return ""; }, $inputString); } diff --git a/lib/newsarticle.php b/lib/newsarticle.php index 08d02c5..0f80108 100644 --- a/lib/newsarticle.php +++ b/lib/newsarticle.php @@ -1,5 +1,4 @@ "Fail"]; // Default Status is "Fail" $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; "); - + $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 <= ?;"); $id = 0; $writtenAt = ""; $writtenBy = 0; @@ -18,6 +15,7 @@ function getNewsArticles() :array $filelist = 0; $writtenByName = ""; + $stmt->bind_param("i", $_SESSION["privilege_level"]); $stmt->bind_result($id, $writtenAt, $writtenBy, $title, $body, $filelist, $writtenByName); $stmt->execute(); @@ -38,24 +36,29 @@ function getNewsArticles() :array $output["Articles"] = $articles; } - } - return $output; } -function addNewsArticle($title="Nazov", $body="Obsah") :array +function addNewsArticle($title="Nazov", $body="Obsah", $privilegeLevel=0) :array { global $mysqli; + global $routerConfig; + + + if ($privilegeLevel == 0){ + $privilegeLevel = $routerConfig['newsarticle']['default_permissions']; + } $output = ["Status" => "Fail"]; // Default Status is "Fail" - if (isLoggedIn()) { - $query = $mysqli->prepare("INSERT INTO NewsArticles (WrittenBy, Title, Body, FileList) VALUES (?, ?, ?, 0);"); - $query->bind_param("iss", $_SESSION["id"], htmlspecialchars($title), htmlspecialchars($body)); + if (isLoggedIn() && $privilegeLevel <= $_SESSION["privilege_level"]) { + $query = $mysqli->prepare("INSERT INTO NewsArticles (WrittenBy, Title, Body, FileList, PrivilegeLevel) VALUES (?, ?, ?, 0, ?);"); + $minpriv = intval($privilegeLevel); + $query->bind_param("issi", $_SESSION["ID"], htmlspecialchars($title), htmlspecialchars($body), $minpriv); $query->execute(); if ($query->affected_rows > 0) { $output["Status"] = "Success"; } + $query->close(); } - $query->close(); return $output; } \ No newline at end of file diff --git a/lib/page.php b/lib/page.php index a9eaa3b..db2c600 100644 --- a/lib/page.php +++ b/lib/page.php @@ -40,6 +40,10 @@ function renderPage($page_name = null, $site_name = null): array $site_name = $routerRequest["site_name"]; } + $site_title = str_replace("_", " ", $site_name); + + $site_title = ucfirst($site_title); + if(!$page_name){ $page_name = $routerRequest["page_name"]; } @@ -109,10 +113,20 @@ function renderPage($page_name = null, $site_name = null): array $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 [ "PageContent" => $page, "PageName" => $page_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"); - if(!empty($pageMetadata["parameters"]["page_title"])){ - $page_title = $pageMetadata["parameters"]["page_title"]; - } - else{ - $page_title = $page_name; - } + $page_title = $page_tmp["PageTitle"]; $dynamic_style = doDynamicStyling(); $dynamic_script_data = [ "currentPage" => $page_name, @@ -143,6 +152,7 @@ function getPage($site_name_in = null, $page_name_in = null): string "currentTitle" => $page_title, "defaultPage" => $routerConfig["default_page"], "defaultSite" => $routerConfig["default_site"], + "UserInfo_Privileges" => $_SESSION["privilege_level"], ]; if(isLoggedIn()){ $dynamic_script_data += [ @@ -214,5 +224,6 @@ function getPageEndpoint($page_name, $site_name) :array "Status" => "Success", "Page" => $page_tmp["PageContent"], "PageLocation" => $page_location, + "PageTitle" => $page_tmp["PageTitle"], ]; } \ No newline at end of file diff --git a/lib/sitemap.php b/lib/sitemap.php index 7523edb..967be22 100644 --- a/lib/sitemap.php +++ b/lib/sitemap.php @@ -35,7 +35,8 @@ function generateSitemap(): void{ $page_required_permission = $routerConfig["page"]["default_permissions"]; } } elseif ($page_file_tmp[1] == "php") { - $page_required_permission = getDynamicPermission($page_file_path); + $pageMetadata = getDynamicMetadata($page_file_path); + $page_required_permission = getDynamicPermission($pageMetadata); } else { $page_required_permission = $routerConfig["page"]["default_permissions"]; } diff --git a/pages/home/index.html b/pages/home/index.html index e5fb4fd..24dd0d9 100644 --- a/pages/home/index.html +++ b/pages/home/index.html @@ -1,3 +1,4 @@ +

Vitaj, na tejto úžasnej stránke

diff --git a/pages/memes/index.html b/pages/memes/index.html index 61637f3..7e7387b 100644 --- a/pages/memes/index.html +++ b/pages/memes/index.html @@ -1,3 +1,4 @@ +

Adlerka Memes

diff --git a/pages/news/index.php b/pages/news/index.php index 164b122..1874828 100644 --- a/pages/news/index.php +++ b/pages/news/index.php @@ -15,13 +15,14 @@ if($articles_tmp['Status'] == "Success"){ } $articleTemplate = file_get_contents($routerConfig["template_dir"] . "newsArticle.html"); +$output = str_replace("__TEMPLATE_FOR_ARTICLE_CONTENT__", $articleTemplate, $output); 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"]); + $articleWrittenByName = htmlspecialchars($article["WrittenByName"]); $articleTemplate = str_replace("__TEMPLATE_ARTICLE_TITLE__", $articleTitle, $articleTemplate); $articleTemplate = str_replace("__TEMPLATE_ARTICLE_AUTHOR__", $articleWrittenByName, $articleTemplate); @@ -31,14 +32,13 @@ foreach ($articles as $article){ $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, + "minimal_permission_level" => 1, "secret" => "no", "page_title" => "Novinky" ] diff --git a/pages/notes/index.html b/pages/notes/index.html index 9e63fb2..536def0 100644 --- a/pages/notes/index.html +++ b/pages/notes/index.html @@ -1,3 +1,4 @@ +

Adlerka Zošit

diff --git a/pages/smp/index.html b/pages/smp/index.html index 030f031..b2382d4 100644 --- a/pages/smp/index.html +++ b/pages/smp/index.html @@ -1,3 +1,4 @@ +

Vitaj na oficiálnej AdlerkaSMP stránke

diff --git a/pages/smp/info.html b/pages/smp/info.html index 11686e8..70bee00 100644 --- a/pages/smp/info.html +++ b/pages/smp/info.html @@ -1,2 +1,3 @@ - + +

Vitaj na oficiálnej stránke Informácii o AdlerkaSMP

\ No newline at end of file diff --git a/templates/newsArticle.html b/templates/newsArticle.html index c6b009b..4aae648 100644 --- a/templates/newsArticle.html +++ b/templates/newsArticle.html @@ -1,8 +1,9 @@

__TEMPLATE_ARTICLE_TITLE__

-
-

__TEMPLATE_ARTICLE_AUTHOR__

-

__TEMPLATE_ARTICLE_DATE__

+
__TEMPLATE_ARTICLE_BODY__ diff --git a/templates/newsArticles.html b/templates/newsArticles.html index ea74d38..e300c85 100644 --- a/templates/newsArticles.html +++ b/templates/newsArticles.html @@ -17,6 +17,7 @@


+
diff --git a/templates/skeleton.html b/templates/skeleton.html index 1d8037b..cbac06b 100644 --- a/templates/skeleton.html +++ b/templates/skeleton.html @@ -10,7 +10,7 @@ __TEMPLATE__DYNAMIC__STYLE__ - Adlerka __TEMPLATE_PAGE_TITLE__ + __TEMPLATE_PAGE_TITLE__ __TEMPLATE_SEO_STUFF__