forked from Adleraci/adlerka.top
		
	Test
This commit is contained in:
		@@ -179,16 +179,24 @@ async function togglearticlecreate(){
 | 
			
		||||
    articleContainerElement.classList.toggle("hidden");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function renderarticle(articledata){
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function submitarticle(){
 | 
			
		||||
    let articleTitleElement = document.getElementById("articletitleinput");
 | 
			
		||||
    let articleBodyElement = document.getElementById("articlebodyinput");
 | 
			
		||||
    await doAction("/newsarticle", {
 | 
			
		||||
       action: "addNewsArticle",
 | 
			
		||||
        title: articleTitleElement.value,
 | 
			
		||||
        body: articleBodyElement.value
 | 
			
		||||
    }, "Článok úspešne pridaný",
 | 
			
		||||
    await doAction(
 | 
			
		||||
        "/newsarticle",
 | 
			
		||||
        {
 | 
			
		||||
            action: "addNewsArticle",
 | 
			
		||||
            title: articleTitleElement.value,
 | 
			
		||||
            body: articleBodyElement.value
 | 
			
		||||
        },
 | 
			
		||||
        "Článok úspešne pridaný",
 | 
			
		||||
        "Nastala chyba pri pridávaní článku",
 | 
			
		||||
        false);
 | 
			
		||||
        false
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function articleInit(){
 | 
			
		||||
 
 | 
			
		||||
@@ -4,19 +4,43 @@ function getNewsArticles() :array
 | 
			
		||||
    {
 | 
			
		||||
        global $mysqli;
 | 
			
		||||
 | 
			
		||||
        $output = ["Status" => "Fail"]; // Default Status is "Fail"
 | 
			
		||||
 | 
			
		||||
        $articles = [];
 | 
			
		||||
        if (isLoggedIn()) {
 | 
			
		||||
            $result = $mysqli->query("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; ");
 | 
			
		||||
 | 
			
		||||
            // Check if the query executed Successfully
 | 
			
		||||
            if ($result) {
 | 
			
		||||
                while ($row = $result->fetch_assoc()) {
 | 
			
		||||
                    $articles[] = $row;
 | 
			
		||||
                }
 | 
			
		||||
            $id = 0;
 | 
			
		||||
            $writtenAt = "";
 | 
			
		||||
            $writtenBy = 0;
 | 
			
		||||
            $title = "";
 | 
			
		||||
            $body = "";
 | 
			
		||||
            $filelist = 0;
 | 
			
		||||
            $writtenByName = "";
 | 
			
		||||
 | 
			
		||||
            $stmt->bind_result($id, $writtenAt, $writtenBy, $title, $body, $filelist, $writtenByName);
 | 
			
		||||
 | 
			
		||||
            $stmt->execute();
 | 
			
		||||
 | 
			
		||||
            while ($stmt->fetch()) {
 | 
			
		||||
                $articles[] = [
 | 
			
		||||
                    'ID' => $id,
 | 
			
		||||
                    'WrittenAt' => $writtenAt,
 | 
			
		||||
                    'Title' => $title,
 | 
			
		||||
                    'Body' => $body,
 | 
			
		||||
                    'WrittenByName' =>$writtenByName
 | 
			
		||||
                ];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Check if any results were fetched
 | 
			
		||||
            if (!empty($articles)) {
 | 
			
		||||
                $output["Status"] = "Success";
 | 
			
		||||
                $output["Articles"] = $articles;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $articles;
 | 
			
		||||
        return $output;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function addNewsArticle($title="Nazov", $body="Obsah") :array
 | 
			
		||||
 
 | 
			
		||||
@@ -8,8 +8,13 @@ global $routerConfig;
 | 
			
		||||
$output =  file_get_contents($routerConfig["template_dir"] . "newsArticles.html");
 | 
			
		||||
 | 
			
		||||
$articles_out = "";
 | 
			
		||||
$articles = getNewsArticles();
 | 
			
		||||
$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"]);
 | 
			
		||||
@@ -18,18 +23,15 @@ foreach ($articles as $article){
 | 
			
		||||
    $articleWrittenAt = htmlspecialchars($article["WrittenAt"]);
 | 
			
		||||
    $articleWrittenByName = htmlspecialchars($article["Nickname"]);
 | 
			
		||||
 | 
			
		||||
    $articles_out .= "<article>
 | 
			
		||||
<h2 class='newstitle'>$articleTitle</h2>
 | 
			
		||||
<br>
 | 
			
		||||
<p class='newsauthor'>$articleWrittenByName</p>
 | 
			
		||||
<p class='newsdate'>$articleWrittenAt</p>
 | 
			
		||||
<hr>
 | 
			
		||||
<div class='newsbody'>
 | 
			
		||||
$articleBody
 | 
			
		||||
</div>
 | 
			
		||||
</article>";
 | 
			
		||||
    $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 [
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								templates/newsArticle.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								templates/newsArticle.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
			
		||||
<article>
 | 
			
		||||
    <h2 class='newstitle'>__TEMPLATE_ARTICLE_TITLE__</h2>
 | 
			
		||||
    <br>
 | 
			
		||||
    <p class='newsauthor'>__TEMPLATE_ARTICLE_AUTHOR__</p>
 | 
			
		||||
    <p class='newsdate'>__TEMPLATE_ARTICLE_DATE__</p>
 | 
			
		||||
    <hr>
 | 
			
		||||
    <div class='newsbody'>
 | 
			
		||||
        __TEMPLATE_ARTICLE_BODY__
 | 
			
		||||
    </div>
 | 
			
		||||
</article>
 | 
			
		||||
@@ -4,6 +4,11 @@
 | 
			
		||||
  <button id="articlecreateopen" onclick="togglearticlecreate()"><i class="ri-add-circle-line"></i></button>
 | 
			
		||||
  <hr>
 | 
			
		||||
</header>
 | 
			
		||||
 | 
			
		||||
<template data-template-name="article">
 | 
			
		||||
  __TEMPLATE_FOR_ARTICLE_CONTENT__
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<div id="articleslist">
 | 
			
		||||
  __TEMPLATE__ARTICLES_HERE__
 | 
			
		||||
</div>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user