forked from Adleraci/adlerka.top
		
	Add article page
This commit is contained in:
		
							
								
								
									
										20
									
								
								lib/newsarticle.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								lib/newsarticle.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
function getNewsArticles() :array
 | 
			
		||||
    {
 | 
			
		||||
        global $mysqli;
 | 
			
		||||
 | 
			
		||||
        $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; ");
 | 
			
		||||
 | 
			
		||||
            // Check if the query executed Successfully
 | 
			
		||||
            if ($result) {
 | 
			
		||||
                while ($row = $result->fetch_assoc()) {
 | 
			
		||||
                    $articles[] = $row;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $articles;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,8 +0,0 @@
 | 
			
		||||
<page minimal_permission_level="2" secret="no" page_title="Novinky"></page>
 | 
			
		||||
<header>
 | 
			
		||||
    <h1 class="title"></h1>
 | 
			
		||||
    <p>Adlerka študentské news</p>
 | 
			
		||||
    <hr>
 | 
			
		||||
    <p>Rohová časť stola v a A103 spáchala samovraždu po dotyku Richarda Mikloša!!!</p>
 | 
			
		||||
</header>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										43
									
								
								pages/news/index.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								pages/news/index.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
<?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 = getNewsArticles();
 | 
			
		||||
 | 
			
		||||
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"]);
 | 
			
		||||
 | 
			
		||||
    $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>";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$output = str_replace("__TEMPLATE__ARTICLES_HERE__", $articles_out, $output);
 | 
			
		||||
 | 
			
		||||
return [
 | 
			
		||||
    "output" => $output,
 | 
			
		||||
    "parameters" =>
 | 
			
		||||
        [
 | 
			
		||||
            "minimal_permission_level" => 2,
 | 
			
		||||
            "secret" => "no",
 | 
			
		||||
            "page_title" => "Novinky"
 | 
			
		||||
        ]
 | 
			
		||||
];
 | 
			
		||||
							
								
								
									
										6
									
								
								templates/newsArticles.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								templates/newsArticles.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
<header>
 | 
			
		||||
  <h1 class="title"></h1>
 | 
			
		||||
  <p>Adlerka študentské news</p>
 | 
			
		||||
  <hr>
 | 
			
		||||
  __TEMPLATE__ARTICLES_HERE__
 | 
			
		||||
</header>
 | 
			
		||||
		Reference in New Issue
	
	Block a user