remove junk

This commit is contained in:
Tomáš Měšťan 2024-03-21 09:49:02 +01:00
parent 154fc4103f
commit 70bee41bb1
16 changed files with 5 additions and 600 deletions

@ -1,16 +0,0 @@
<?php
require_once "lib/newsarticle.php";
function endpoint($endpoint_data): array
{
return match ($endpoint_data["action"]) {
"getNewsArticles" => getNewsArticles(),
"addNewsArticle" => addNewsArticle(
$endpoint_data["title"],
$endpoint_data["body"]
),
default => ["Status" => "Fail", "message" => "Invalid action"],
};
}

@ -1,14 +0,0 @@
<?php
require_once "lib/upload.php";
function endpoint($endpoint_data): array
{
return match ($endpoint_data["action"]) {
"getMyFiles" => listFiles(),
"getAllFiles" => listFiles(false),
"UploadFiles" => parseIncomingFiles(),
default => ["Status" => "Fail", "message" => "Invalid action"],
};
}

@ -4,7 +4,7 @@
return [ return [
'inlining' => false, 'inlining' => false,
'domain' => 'adlerka', 'domain' => 'stylehub.adlerka',
'tld' => 'top', 'tld' => 'top',
'default_page' => 'index', 'default_page' => 'index',
'default_site' => 'home', 'default_site' => 'home',
@ -12,7 +12,7 @@
'endpoint_dir' => 'endpoints/', 'endpoint_dir' => 'endpoints/',
'page_dir' => 'pages/', 'page_dir' => 'pages/',
'protocol' => 'https://', 'protocol' => 'https://',
'site_prefix' => 'Adlerka', 'site_prefix' => 'StyleHub',
'permissions' => [ 'permissions' => [
'logged_out' => 1, 'logged_out' => 1,
'logged_in_default' => 2, 'logged_in_default' => 2,
@ -31,9 +31,9 @@
'default_permissions' => 255, 'default_permissions' => 255,
], ],
'seo' => [ 'seo' => [
'author' => 'Tím AdlerkaTop', 'author' => 'Guvernér',
'description' => 'Toto je neoficiánla študentská stránka pre Adlerku, kde môžete nájsť plno zaujímavostí.', 'description' => 'Toto je stránka Malackého guvernéra.',
'keywords' => 'adlerka, alderka, studenti, studentska stranka, web, dev, webdev, web dev, skola, zabava', 'keywords' => 'moda, oblecenie, mesto, guverner',
'generator' => 'TurboRoute', 'generator' => 'TurboRoute',
'robots' => 'follow, index, max-snippet:-1, max-video-preview:-1, max-image-preview:large' 'robots' => 'follow, index, max-snippet:-1, max-video-preview:-1, max-image-preview:large'
] ]

@ -1,64 +0,0 @@
<?php
function getNewsArticles() :array
{
global $mysqli;
$output = ["Status" => "Fail"]; // Default Status is "Fail"
$articles = [];
$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;
$title = "";
$body = "";
$filelist = 0;
$writtenByName = "";
$stmt->bind_param("i", $_SESSION["privilege_level"]);
$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 $output;
}
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() && $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();
}
return $output;
}

@ -1,189 +0,0 @@
<?php
function makePathSafe($userInput): string
{
// Keep only alphanumeric characters, underscores, and hyphens
$safeString = preg_replace('/[^\w\-]/', '', $userInput);
// Ensure no path traversal
$safeString = str_replace('..', '_', $safeString);
// Trim leading/trailing underscores
$safeString = trim($safeString, '_');
// Replace directory separator characters with underscores
$safeString = str_replace(['/', '\\'], '_', $safeString);
// Limit length for safety
return substr($safeString, 0, 255);
}
function getIncomingFiles(): array
{
$files = $_FILES;
$files2 = [];
foreach ($files as $infoArr) {
$filesByInput = [];
foreach ($infoArr as $key => $valueArr) {
if (is_array($valueArr)) { // file input "multiple"
foreach ($valueArr as $i => $value) {
$filesByInput[$i][$key] = $value;
}
} else { // -> string, normal file input
$filesByInput[] = $infoArr;
break;
}
}
$files2 = array_merge($files2, $filesByInput);
}
$files3 = [];
foreach ($files2 as $file) { // let's filter empty & errors
if (!$file['error']) $files3[] = $file;
}
return $files3;
}
function saveUploadedFileInDatabase($filePath, $fileType):bool
{
global $mysqli;
$stmt = $mysqli->prepare("INSERT INTO Files (Path, Type, UploadedBy, UploadedAt) VALUES (?, ?, ?, NOW())");
$stmt->bind_param("ssi", $filePath, $fileType, $_SESSION["ID"]);
$stmt->execute();
$stat = $stmt->affected_rows > 0;
$stmt->close();
return $stat;
}
function doImageUpload($inFile, $outFile): bool
{
// Create Imagick object
try {
$imagick = new Imagick($inFile);
} catch (ImagickException $e) {
}
// Set the desired format for reencoding (WebP)
try {
$imagick->setImageFormat('webp');
} catch (ImagickException $e) {
}
// Remove non-essential metadata
try {
$imagick->stripImage();
} catch (ImagickException $e) {
}
// Write the reencoded image to the output file
try {
$imagick->writeImage($outFile);
} catch (ImagickException $e) {
}
// Destroy the Imagick object to free up resources
$imagick->destroy();
// Check if the reencoding was successful
if (file_exists($outFile)) {
return saveUploadedFileInDatabase($outFile, 'image/webp');
} else {
return false;
}
}
function listFiles($onlyMine = true):array
{
$output = ["Status" => "Fail"];
require_once "lib/account.php";
if(($onlyMine && isLoggedIn()) || (!$onlyMine && isModerator())) {
global $mysqli;
$query = "SELECT ID, Path, Type, UploadedAt, UploadedBy FROM Files";
if($onlyMine){
$query .= " WHERE UploadedBy = ?";
}
$stmt = $mysqli->prepare($query);
if($onlyMine) {
$stmt->bind_param("i", $_SESSION["ID"]);
}
$id = 0;
$path = "";
$type = "";
$uploadedAt = "";
$uploadedBy = 0;
$stmt->bind_result($id, $path, $type, $uploadedAt, $uploadedBy);
$stmt->execute();
// Fetch the results into the bound variables
while ($stmt->fetch()) {
$files[] = [
'ID' => $id,
'Path' => $path,
'Type' => $type,
'UploadedAt' => $uploadedAt,
'UploadedBy' => $uploadedBy,
];
}
// Check if any results were fetched
if (!empty($files)) {
$output["Status"] = "Success";
$output["Files"] = $files;
}
$stmt->close();
}
return $output;
}
function parseIncomingFiles(): array
{
$incomingFiles = getIncomingFiles();
$success = true;
foreach ($incomingFiles as $incomingFile) {
if ($incomingFile["error"] == 0 && is_file($incomingFile["tmp_name"])) {
$type = explode("/", $incomingFile["type"]);
if ($type == "image") {
$imgFname = pathinfo($incomingFile["name"], PATHINFO_FILENAME);
$uploadPath = getUploadPath("image", $imgFname);
if (!empty($uploadPath)) {
if (!doImageUpload($incomingFile["tmp_name"], $uploadPath)) {
$success = false;
}
} else {
$success = false;
}
}
}
}
$output = ["Status" => "Fail"];
if($success){
$output["Status"] = "Success";
}
return $output;
}
function getUploadPath($type = "unknown", $filename = "hehe"): string
{
$type = makePathSafe($type);
$id = makePathSafe($_SESSION["ID"]);
$date = makePathSafe(date("Y/m/d"));
$filename = makePathSafe($filename);
$extension = match ($type) {
'image' => 'webp',
default => 'dummy',
};
if($extension != "dummy") {
return "uploads/$type/$id/$date/$filename.$extension";
}
else {
return "";
}
}

@ -1,7 +0,0 @@
<!--suppress HtmlUnknownTag, HtmlUnknownTag -->
<page minimal_permission_level="1" secret="no" page_title="Memes"></page>
<header>
<h1 class="title">Adlerka Memes</h1>
<p>Skoro ako <a href="https://reddit.com/r/adlerka" target="_blank">r/adlerka</a> - ale lepšie.</p>
<hr>
</header>

@ -1,45 +0,0 @@
<?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");
$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["WrittenByName"]);
$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__ARTICLES_HERE__", $articles_out, $output);
return [
"output" => $output,
"parameters" =>
[
"minimal_permission_level" => 1,
"secret" => "no",
"page_title" => "Novinky"
]
];

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

@ -1,4 +0,0 @@
<page minimal_permission_level="2" secret="no" page_title="INFO"></page>
<h1>Toto sú rozvrhy niektorých Adlerákov</h1>
<h2>Zatiaľ hardcoded, potom dorobíme funkcionalitu zbierania dát z Edupage</h2>

@ -1,59 +0,0 @@
<page minimal_permission_level="2" secret="no" page_title="1.C 2.skupina"></page>
<h1>Rozvrh 1.C 2.Skupina</h1>
<table>
<tbody>
<tr>
<th>0 (7:10 - 7:55)</th>
<th>1 (8:00 - 8:45)</th>
<th>2 (8:50 - 9:35)</th>
<th>3 (9:45 - 10:30)</th>
<th>4 (10:50 - 11:35)</th>
<th>5 (11:45 - 12:30)</th>
<th>6 (12:40 - 13:25)</th>
<th>7 (13:30 - 14:15)</th>
</tr>
<tr>
<td></td>
<td>MAT</td>
<td>ELK</td>
<td>SJL</td>
<td colspan="2">ZER</td>
<td>ANJ</td>
<td>MAT</td>
</tr>
<tr>
<td colspan="3">PRX</td>
<td>SJL</td>
<td colspan="2">INF</td>
<td>ELK</td>
</tr>
<tr>
<td></td>
<td>PRO</td>
<td>SJL</td>
<td>FYZ</td>
<td>ANJ</td>
<td>MAT</td>
<td>ELK</td>
<td>TSV</td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">PRO</td>
<td>ANJ</td>
<td>TDK</td>
<td>MAT</td>
<td>ETV</td>
</tr>
<tr>
<td></td>
<td>TDK</td>
<td>OBN</td>
<td>TSV</td>
<td>FYZ</td>
<td>PRO</td>
<td>DEJ</td>
</tr>
</tbody>
</table>

@ -1,59 +0,0 @@
<page minimal_permission_level="2" secret="no" page_title="1.C 1.skupina"></page>
<h1>Rozvrh 1.C 1.Skupina</h1>
<table>
<tbody>
<tr>
<th>0 (7:10 - 7:55)</th>
<th>1 (8:00 - 8:45)</th>
<th>2 (8:50 - 9:35)</th>
<th>3 (9:45 - 10:30)</th>
<th>4 (10:50 - 11:35)</th>
<th>5 (11:45 - 12:30)</th>
<th>6 (12:40 - 13:25)</th>
<th>7 (13:30 - 14:15)</th>
</tr>
<tr>
<td></td>
<td>MAT</td>
<td>ELK</td>
<td>SJL</td>
<td colspan="2">ZER</td>
<td>MAT</td>
<td>ANJ</td>
</tr>
<tr>
<td colspan="3">PRX</td>
<td>SJL</td>
<td colspan="2">INF</td>
<td>ELK</td>
</tr>
<tr>
<td></td>
<td>PRO</td>
<td>SJL</td>
<td>TSV</td>
<td>FYZ</td>
<td>ANJ</td>
<td>MAT</td>
<td>ELK</td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">PRO</td>
<td>TDK</td>
<td>TSV</td>
<td>MAT</td>
<td>ETV</td>
</tr>
<tr>
<td></td>
<td>ANJ</td>
<td>OBN</td>
<td>TDK</td>
<td>FYZ</td>
<td>PRO</td>
<td>DEJ</td>
</tr>
</tbody>
</table>

@ -1,60 +0,0 @@
<page minimal_permission_level="2" secret="no" page_title="1.D 1.skupina"></page>
<h1>Rozvrh 1.D 1.Skupina</h1>
<table>
<tbody>
<tr>
<th>0 (7:10 - 7:55)</th>
<th>1 (8:00 - 8:45)</th>
<th>2 (8:50 - 9:35)</th>
<th>3 (9:45 - 10:30)</th>
<th>4 (10:50 - 11:35)</th>
<th>5 (11:45 - 12:30)</th>
<th>6 (12:40 - 13:25)</th>
<th>7 (13:30 - 14:15)</th>
</tr>
<tr>
<td></td>
<td>TSV</td>
<td colspan="2">PRO</td>
<td>MAT</td>
<td>TDK</td>
<td>PRO</td>
<td>SJL</td>
</tr>
<tr>
<td></td>
<td>FYZ</td>
<td>TDK</td>
<td>MAT</td>
<td>ELK</td>
<td>OBN</td>
<td>ANJ</td>
<td>ETV</td>
</tr>
<tr>
<td></td>
<td>ELK</td>
<td>MAT</td>
<td>SJL</td>
<td>ANJ</td>
<td>ELK</td>
<td colspan="2">INF</td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">ZER</td>
<td>MAT</td>
<td>FYZ</td>
<td>DEJ</td>
<td>TSV</td>
</tr>
<tr>
<td></td>
<td>SJL</td>
<td>ANJ</td>
<td>PRO</td>
<td colspan="3">PRX</td>
</tr>
</tbody>
</table>

@ -1,36 +0,0 @@
<!--suppress HtmlUnknownTag, HtmlUnknownTag -->
<page minimal_permission_level="1" secret="no" page_title="Domov"></page>
<header>
<h1 class="title">Vitaj na oficiálnej AdlerkaSMP stránke</h1>
<p>Najlepší <a href="https://minecraft.net" style="text-decoration: underline; color: #fff;" target="_blank">Minecraft®™</a> server na Adlerke</p>
<hr>
<div class="wrapper feature-list">
<h2>Čo môžeš očakávať od AdlerkaSMP:</h2>
<ul class="feature-list-ul">
<li>
<strong>Vlastné pluginy:</strong>
<ul>
<li>Plugin 1</li>
<li>Plugin 2</li>
</ul>
</li>
<li>
<strong>Kvalitné pluginy:</strong>
<ul>
<li>Oraxen</li>
<li>ModelManager</li>
</ul>
</li>
<li>
<strong>Super admini:</strong>
<ul>
<li>Robíme celý server.</li>
<li>Vďaka nám je AdlerkaSMP<br>bezpečné miesto.</li>
</ul>
</li>
</ul>
</div>
</header>

@ -1,3 +0,0 @@
<!--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>

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

@ -1,22 +0,0 @@
<header>
<h1 class="title"></h1>
<p>Adlerka študentské news</p>
<button id="articlecreateopen" onclick="togglearticlecreate()"><i class="ri-add-circle-line"></i></button>
</header>
<template data-template-name="article">
__TEMPLATE_FOR_ARTICLE_CONTENT__
</template>
<div id="articleslist">
__TEMPLATE__ARTICLES_HERE__
</div>
<div id="articlecreatecontainer" class="hidden">
<div id="articlecreate">
<input type="text" placeholder="Article Title" id="articletitleinput"><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>
</div>
</div>