WIP Suche implementiert, sowie Sortieren der Ergebnisse #19
Generated
+1
-3
@@ -10,9 +10,7 @@
|
||||
<option name="highlightLevel" value="WARNING" />
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.0">
|
||||
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="8.5" />
|
||||
<component name="PhpStanOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
session_start();
|
||||
$user = $user ?? null;
|
||||
if (!isset($_SESSION["user"])) {
|
||||
header("Location: index.php?pfad=login");
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
<!--
|
||||
Seite: Beitrag erstellen
|
||||
@@ -10,7 +14,7 @@ session_start();
|
||||
<main class="editor-main">
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "internal_error"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Es ist ein Fehler beim Speichern aufgetreten. Bitte versuche es erneut.
|
||||
Es ist ein interner Fehler beim Speichern aufgetreten. Bitte versuche es erneut.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "missing_parameters"): ?>
|
||||
@@ -18,8 +22,40 @@ session_start();
|
||||
Jeder Beitrag muss einen Titel, Kategorie und Inhalt besitzen.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<input type="text" id="title" name="title" placeholder="Titel hier eingeben" required>
|
||||
<textarea id="content" name="content" placeholder="Schreibe deinen Beitrag..."></textarea>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_title"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Der Titel enthält ungültige Zeichen oder erfüllt die Länge von 5-120 Zeichen nicht.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_content"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Der Text erlaubt eine Länge von 10 bis maximal 7.000 Zeichen (ca. 1.000 Wörter).
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_category"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Die ausgewählte Kategorie ist ungültig.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_tags"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Ungültige Schlagworte gefunden. Erlaubt sind nur Buchstaben, Zahlen, Leerzeichen und Bindestriche (2-50 Zeichen).
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "validation_missing"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Bei der Validierung deiner Daten ist ein Fehler aufgetreten. Bitte versuche es erneut.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
unset($_SESSION["message"]);
|
||||
?>
|
||||
<input type="text" id="title" name="title"
|
||||
value="<?php echo htmlspecialchars($_SESSION['old_title'] ?? ''); unset($_SESSION['old_title']); ?>"
|
||||
placeholder="Titel hier eingeben" required>
|
||||
<textarea id="content" name="content" placeholder="Schreibe deinen Beitrag...">
|
||||
<?php echo htmlspecialchars($_SESSION['old_content'] ?? ''); unset($_SESSION['old_content']); ?>
|
||||
</textarea>
|
||||
</main>
|
||||
|
||||
<!-- Seitenleiste -->
|
||||
@@ -76,7 +112,9 @@ session_start();
|
||||
|
||||
<div class="sidebar-block">
|
||||
<label for="tags">Schlagwörter</label>
|
||||
<input type="text" id="tags" name="tags" placeholder="z.B. Technik, IT (mit Komma trennen)">
|
||||
<input type="text" id="tags" name="tags"
|
||||
value="<?php echo htmlspecialchars($_SESSION['old_tags'] ?? ''); unset($_SESSION['old_tags']); ?>"
|
||||
placeholder="z.B. Technik, IT (mit Komma trennen)">
|
||||
</div>
|
||||
|
||||
</aside>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
require_once "php/model/LocalUserDAO.php";
|
||||
|
||||
$dao = new LocalUserDAO();
|
||||
|
||||
/*
|
||||
Deregistrierung
|
||||
Funktion: Entfernt User aus Dummy-Daten und beendet Session
|
||||
*/
|
||||
|
||||
if (isset($_SESSION["user_email"])) {
|
||||
$dao->deleteUser($_SESSION["user_email"]);
|
||||
}
|
||||
|
||||
$_SESSION = [];
|
||||
session_destroy();
|
||||
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
+34
-13
@@ -1,32 +1,53 @@
|
||||
<?php
|
||||
$error = $error ?? null;
|
||||
?>
|
||||
|
||||
<!--
|
||||
Form: Login-Bereich
|
||||
Funktion: Benutzerauthentifizierung und Zugang zum eigenen Profil, Erstellen von Beiträgen, etc.
|
||||
-->
|
||||
<main class="login-page">
|
||||
<div class="login-container">
|
||||
|
||||
|
||||
<h1>Bitte anmelden</h1>
|
||||
|
||||
<form>
|
||||
<label id ="inputEmail" class="screenreader-only">E-Mail Adresse / </label>
|
||||
<?php if ($error): ?>
|
||||
<p style="color:red;">
|
||||
<?php echo htmlspecialchars($error); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="index.php?pfad=login">
|
||||
|
||||
<p class="input-label">Benutzername/E-Mail-Adresse:</p>
|
||||
<input type="email" name="email" class="login-input" placeholder="E-Mail-Adresse" required autofocus>
|
||||
<input type="email"
|
||||
name="email"
|
||||
class="login-input"
|
||||
placeholder="E-Mail-Adresse"
|
||||
required
|
||||
autofocus>
|
||||
|
||||
<p class="input-label">Passwort:</p>
|
||||
<input type="password" name="password" class="login-input" placeholder="Passwort" required>
|
||||
<input type="password"
|
||||
name="password"
|
||||
class="login-input"
|
||||
placeholder="Passwort"
|
||||
required>
|
||||
|
||||
<div class="checkbox-wrapper">
|
||||
<label>
|
||||
<input type="checkbox" name="remember-me" value="1"> angemeldet bleiben
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button type="submit" value="anmelden" name="loginSubmit" class="login-button">anmelden</button>
|
||||
<button type="submit"
|
||||
value="anmelden"
|
||||
name="loginSubmit"
|
||||
class="login-button">
|
||||
anmelden
|
||||
</button>
|
||||
|
||||
<div class="register-link">
|
||||
<a href="register.php">Noch keinen Account? Jetzt hier registrieren!</a>
|
||||
<a href="index.php?pfad=register">
|
||||
Noch keinen Account? Jetzt hier registrieren!
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$_SESSION = [];
|
||||
session_destroy();
|
||||
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
+83
-29
@@ -1,46 +1,100 @@
|
||||
<?php
|
||||
include_once 'php/controller/profile-controller.php';
|
||||
$user = $user ?? null;
|
||||
?>
|
||||
|
||||
<!--
|
||||
Content: Profil
|
||||
Inhalt: Das eigene Profil, wenn man angemeldet ist. Dort hat man die Möglichkeit seine Angaben zu ändern.
|
||||
-->
|
||||
|
||||
<main class="form-page">
|
||||
<div class="flexbox">
|
||||
<!-- Linke Spalte: Profildaten -->
|
||||
<div class="container">
|
||||
<form>
|
||||
<label class="input-label">Name</label>
|
||||
<input type="text"
|
||||
class="login-input"
|
||||
readonly
|
||||
value="<?php echo htmlspecialchars($user["username"] ?? ""); ?>">
|
||||
|
||||
<div class="form-container">
|
||||
<form>
|
||||
|
||||
<label class="input-label">Vorname</label>
|
||||
|
||||
<input type="text" name="Vorname" class="login-input" required
|
||||
placeholder="Vorname"
|
||||
value="<?php //DB-Daten ?>">
|
||||
|
||||
<label class="input-label">Nachname</label>
|
||||
<input type="text" name="Nachname" class="login-input" required
|
||||
placeholder="Nachname"
|
||||
value="<?php //DB-Daten ?>">
|
||||
|
||||
<label class="input-label">Email-Adresse</label>
|
||||
<input type="email" name="Email" class="login-input" required
|
||||
placeholder="mustermann@web.de"
|
||||
value="<?php //DB-Daten ?>">
|
||||
|
||||
<label class="input-label">Passwort</label>
|
||||
<input type="password" name="Passwort" class="login-input"
|
||||
required placeholder="Passwort">
|
||||
<label class="input-label">Email-Adresse</label>
|
||||
<input type="email"
|
||||
class="login-input"
|
||||
readonly
|
||||
value="<?php echo htmlspecialchars($user["email"] ?? ""); ?>">
|
||||
|
||||
<label class="input-label">Passwort</label>
|
||||
<input type="password"
|
||||
class="login-input"
|
||||
readonly
|
||||
value="********">
|
||||
</form>
|
||||
<br>
|
||||
|
||||
<button type="submit" class="login-button">
|
||||
Speichern
|
||||
</button>
|
||||
<a href="index.php?pfad=deleteAccount" class="login-button">
|
||||
Account löschen
|
||||
</a>
|
||||
|
||||
<br><br>
|
||||
|
||||
<button type="button" class="login-button">
|
||||
Account löschen
|
||||
</button>
|
||||
<a href="index.php?pfad=logout" class="login-button">
|
||||
Abmelden
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
<!-- Rechte Spalte: Eigene Beiträge -->
|
||||
<div class="container">
|
||||
<h2 class="section-title">Meine Beiträge</h2>
|
||||
<div class="articles-list">
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "internal_error"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Es ist ein interner Fehler aufgetreten. Bitte versuche es erneut.
|
||||
</p>
|
||||
<?php elseif (isset($userArticles) && count($userArticles) > 0): ?>
|
||||
<?php foreach ($userArticles as $userArticle): ?>
|
||||
<!-- Ein einzelner Artikel-Eintrag -->
|
||||
<div class="article-item">
|
||||
<div class="article-meta">
|
||||
<span class="article-date"><?php echo htmlspecialchars($userArticle->getCreationDate()); ?></span>
|
||||
<span class="article-category"><?php echo htmlspecialchars($userArticle->getCategory()); ?></span>
|
||||
</div>
|
||||
<h3 class="article-title"><?php echo htmlspecialchars($userArticle->getTitle()); ?></h3>
|
||||
<?php
|
||||
$tags = $userArticle->getTags();
|
||||
if (isset($tags) && !empty($tags)): ?>
|
||||
<div class="article-view-bottom-section">
|
||||
<div class="article-view-tags-label">Tags:</div>
|
||||
<div class="article-view-tags-list">
|
||||
<?php
|
||||
$tagArray = is_array($tags) ? $tags : explode(',', $tags);
|
||||
foreach ($tagArray as $tag):
|
||||
$trimmedTag = trim($tag);
|
||||
if (!empty($trimmedTag)):
|
||||
?>
|
||||
<span class="article-view-tag-item"><?php echo htmlspecialchars($trimmedTag); ?></span>
|
||||
<?php
|
||||
endif;
|
||||
endforeach;
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<a href="index.php?pfad=updateArticle&id=<?php echo $userArticle->getID(); ?>" class="edit-link-button">Bearbeiten</a>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<p>Du hast noch keine Beiträge erstellt.</p>
|
||||
<button type="button" class="login-button" onclick="window.location.href='index.php?pfad=createArticle';">
|
||||
Beitrag erstellen!
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
unset($_SESSION["message"]);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
+41
-11
@@ -1,3 +1,9 @@
|
||||
<?php
|
||||
include_once 'php/controller/register-controller.php';
|
||||
|
||||
$error = $error ?? null;
|
||||
?>
|
||||
|
||||
<!--
|
||||
Form: Registrierung
|
||||
Funktion: Erstellung neuer Benutzerkonten
|
||||
@@ -7,26 +13,50 @@
|
||||
|
||||
<h1>Jetzt Registrieren!</h1>
|
||||
|
||||
<form>
|
||||
<?php if ($error): ?>
|
||||
<p style="color:red;">
|
||||
<?php echo htmlspecialchars($error); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="index.php?pfad=register">
|
||||
|
||||
<p class="input-label">Email:</p>
|
||||
<input type="email" name="email" class="login-input" placeholder="mustermann@web.de" required>
|
||||
<input type="email"
|
||||
name="email"
|
||||
class="login-input"
|
||||
placeholder="mustermann@web.de"
|
||||
required>
|
||||
|
||||
<p class="input-label">Vorname:</p>
|
||||
<input type="text" name="vorname" class="login-input" placeholder="Max" required>
|
||||
<input type="text"
|
||||
name="vorname"
|
||||
class="login-input"
|
||||
placeholder="Max"
|
||||
required>
|
||||
|
||||
<p class="input-label">Nachname:</p>
|
||||
<input type="text" name="nachname" class="login-input" placeholder="Mustermann" required>
|
||||
<input type="text"
|
||||
name="nachname"
|
||||
class="login-input"
|
||||
placeholder="Mustermann"
|
||||
required>
|
||||
|
||||
<p class="input-label">Passwort:</p>
|
||||
<input type="password" name="password" class="login-input" placeholder="Passwort" required>
|
||||
<input type="password"
|
||||
name="password"
|
||||
class="login-input"
|
||||
placeholder="Passwort"
|
||||
required>
|
||||
|
||||
<div class="checkbox-wrapper">
|
||||
<label>
|
||||
<input type="checkbox" value="remember-me"> angemeldet bleiben
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit"
|
||||
value="register"
|
||||
name="registerSubmit"
|
||||
class="login-button">
|
||||
kostenlos registrieren
|
||||
</button>
|
||||
|
||||
<button type="submit" value="anmelden" name="loginSubmit" class="login-button">kostenlos registrieren</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
+30
-7
@@ -1,21 +1,44 @@
|
||||
<?php
|
||||
include_once 'php/controller/showArticle-controller.php';
|
||||
?>
|
||||
<!--
|
||||
Seite: Anzeige für Beiträge
|
||||
Funktion: Stellt einen übergebenen Beitrag dar.
|
||||
-->
|
||||
|
||||
<?php
|
||||
include_once 'php/controller/showArticle-controller.php';
|
||||
?>
|
||||
|
||||
<!-- Hauptcontainer für die Beitragsansicht (Ausschließlich der Content-Bereich) -->
|
||||
<main class="article-view-container">
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "internal_error"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Es ist ein interner Fehler aufgetreten. Bitte versuche es erneut.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "missing_id"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Es ist ein Fehler aufgetreten. Die ID konnte nicht ausgelesen werden. Bitte versuche es erneut.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "missing_parameters"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Jeder Beitrag muss einen Titel, Kategorie und Inhalt besitzen.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "article_updated"): ?>
|
||||
<p class="alert-message is-success">
|
||||
Dein Beitrag wurde erfolgreich bearbeitet!
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
unset($_SESSION["message"]);
|
||||
?>
|
||||
|
||||
<!-- Metadaten & Titel -->
|
||||
<div class="article-view-top-section">
|
||||
|
||||
<?php if (isset($category) && !empty($category)): ?>
|
||||
<span class="article-view-category"><?php echo htmlspecialchars($category); ?></span>
|
||||
<?php endif; ?>
|
||||
|
||||
<h1 class="article-view-title">
|
||||
<?php if (isset($title)) { echo htmlspecialchars($title); } ?>
|
||||
</h1>
|
||||
@@ -28,7 +51,7 @@ include_once 'php/controller/showArticle-controller.php';
|
||||
|
||||
</div>
|
||||
|
||||
<!-- articleikel-Inhalt -->
|
||||
<!-- Beitrags-Inhalt -->
|
||||
<div class="article-view-content">
|
||||
<?php if (isset($content)): ?>
|
||||
<!-- nl2br für Zeilenumbrüche -->
|
||||
@@ -36,7 +59,7 @@ include_once 'php/controller/showArticle-controller.php';
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- articleikel-Endbereich (Tags) -->
|
||||
<!-- Beitrags-Endbereich (Tags) -->
|
||||
<?php if (isset($tags) && !empty($tags)): ?>
|
||||
<div class="article-view-bottom-section">
|
||||
<div class="article-view-tags-label">Tags:</div>
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
$user = $user ?? null;
|
||||
if (!isset($_SESSION["user"])) {
|
||||
header("Location: index.php?pfad=login");
|
||||
exit();
|
||||
}
|
||||
include_once 'php/controller/showArticle-controller.php';
|
||||
?>
|
||||
<!--
|
||||
Seite: Beitrag erstellen
|
||||
Inhalt: Formular für die Erstellung eines neuen Beitrags
|
||||
-->
|
||||
<form method="post" action="php/controller/updateArticle-controller.php?id=<?php if(isset($id) && !empty($id)){echo htmlspecialchars($id);}else{$_SESSION["message"] = "missing_id";} ?>" id="editor-form" class="article-editor-scope.editor-container article-editor-scope editor-container">
|
||||
|
||||
<main class="editor-main">
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "internal_error"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Es ist ein interner Fehler beim Speichern aufgetreten. Bitte versuche es erneut.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "missing_id"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Es ist ein Fehler aufgetreten. Die ID konnte nicht ausgelesen werden. Bitte versuche es erneut.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "missing_parameters"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Jeder Beitrag muss einen Titel, Kategorie und Inhalt besitzen.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_title"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Der Titel enthält ungültige Zeichen oder erfüllt die Länge von 5-120 Zeichen nicht.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_content"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Der Text erlaubt eine Länge von 10 bis maximal 7.000 Zeichen (ca. 1.000 Wörter).
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_category"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Die ausgewählte Kategorie ist ungültig.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_tags"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Ungültige Schlagworte gefunden. Erlaubt sind nur Buchstaben, Zahlen, Leerzeichen und Bindestriche (2-20 Zeichen).
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "validation_missing"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Bei der Validierung deiner Daten ist ein Fehler aufgetreten. Bitte versuche es erneut.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
unset($_SESSION["message"]);
|
||||
?>
|
||||
<input type="text" id="title" name="title"
|
||||
value="<?php
|
||||
if (isset($title) && !empty($title)){echo htmlspecialchars($title);
|
||||
}elseif (isset($_SESSION['old_title']) && !empty($_SESSION['old_title'])){
|
||||
echo htmlspecialchars($_SESSION['old_title']);
|
||||
unset($_SESSION['old_title']);
|
||||
}
|
||||
|
||||
?>"
|
||||
placeholder="Titel hier eingeben" required>
|
||||
<textarea id="content" name="content" placeholder="Schreibe deinen Beitrag...">
|
||||
<?php
|
||||
if (isset($content) && !empty($content)){echo htmlspecialchars($content);
|
||||
}elseif (isset($_SESSION['old_content']) && !empty($_SESSION['old_content'])){
|
||||
echo htmlspecialchars($_SESSION['old_content']);
|
||||
unset($_SESSION['old_content']);
|
||||
}
|
||||
?>
|
||||
</textarea>
|
||||
</main>
|
||||
|
||||
<!-- Seitenleiste -->
|
||||
<aside class="editor-sidebar">
|
||||
|
||||
<div class="sidebar-block">
|
||||
<button type="submit" class="btn-publish">Änderungen speichern</button>
|
||||
</div>
|
||||
|
||||
<div class="sidebar-block">
|
||||
<label for="category">Kategorie <span class="required">*</span></label>
|
||||
<select id="category" name="category" required>
|
||||
<option disabled selected>Kategorie wählen...</option>
|
||||
|
||||
<optgroup label="Sprachen">
|
||||
<option value="deutsch">Deutsch</option>
|
||||
<option value="englisch">Englisch</option>
|
||||
<option value="franzoesisch">Französisch</option>
|
||||
<option value="latein">Latein</option>
|
||||
<option value="literatur">Literatur</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="MINT">
|
||||
<option value="mathe">Mathematik</option>
|
||||
<option value="biologie">Biologie</option>
|
||||
<option value="chemie">Chemie</option>
|
||||
<option value="physik">Physik</option>
|
||||
<option value="informatik">Informatik</option>
|
||||
<option value="astronomie">Astronomie</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="Gesellschaft & Werte">
|
||||
<option value="geschichte">Geschichte</option>
|
||||
<option value="erdkunde">Erdkunde</option>
|
||||
<option value="sozialkunde">Sozialkunde</option>
|
||||
<option value="wirtschaft">Wirtschaftskunde</option>
|
||||
<option value="religion">Religion</option>
|
||||
<option value="ethik">Ethikunterricht</option>
|
||||
<option value="philosophie">Philosophie</option>
|
||||
<option value="psychologie">Psychologie</option>
|
||||
<option value="kunst">Kunst</option>
|
||||
<option value="musik">Musik</option>
|
||||
<option value="theater">Theater</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="Technik & Praxis">
|
||||
<option value="technik">Technik</option>
|
||||
<option value="werken">Werken</option>
|
||||
<option value="hauswirtschaft">Hauswirtschaft</option>
|
||||
<option value="sport">Sport</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="sidebar-block">
|
||||
<label for="tags">Schlagwörter</label>
|
||||
<input type="text" id="tags" name="tags"
|
||||
value="<?php
|
||||
if (isset($tags) && !empty($tags)){echo htmlspecialchars($tags);
|
||||
} elseif (isset($_SESSION['old_tags']) && !empty($_SESSION['old_tags'])){
|
||||
echo htmlspecialchars($_SESSION['old_tags']);
|
||||
unset($_SESSION['old_tags']);
|
||||
}
|
||||
?>"
|
||||
placeholder="z.B. Technik, IT (mit Komma trennen)">
|
||||
</div>
|
||||
|
||||
</aside>
|
||||
|
||||
</form>
|
||||
@@ -212,3 +212,13 @@ a, button, input, select, textarea, label, main{
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 6px 20px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.form-container {
|
||||
flex: 1 1 450px;
|
||||
padding: 30px;
|
||||
background-color: white;
|
||||
border: 1px solid #dbe3ec;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 6px 20px rgba(0,0,0,0.1);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
+1
-1
@@ -152,7 +152,7 @@ CSS für die navbar
|
||||
}
|
||||
|
||||
/* Responsive Anpassungen unter 760px (für z.B. Smartphones) */
|
||||
@media (max-width: 760px) {
|
||||
@media (max-width: 800px) {
|
||||
.nav {
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
CSS für die Profilseite
|
||||
*/
|
||||
|
||||
/* Roter Button für Account löschen */
|
||||
.delete-account-button {
|
||||
background-color: #dc2626;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.delete-account-button:hover {
|
||||
background-color: #b91c1c;
|
||||
}
|
||||
|
||||
/* Beitragsliste Styling */
|
||||
.section-title {
|
||||
margin-top: 0;
|
||||
margin-bottom: 25px;
|
||||
font-size: 1.5rem;
|
||||
color: #1f2937;
|
||||
border-bottom: 2px solid #eef2f7;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.articles-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.article-item {
|
||||
padding: 15px;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 8px;
|
||||
background-color: #f9fafb;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.article-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 0.85rem;
|
||||
color: #6b7280;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.article-category {
|
||||
font-weight: bold;
|
||||
color: #2563eb;
|
||||
}
|
||||
|
||||
.article-title {
|
||||
margin: 0 0 10px 0;
|
||||
font-size: 1.2rem;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.article-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.tag {
|
||||
font-size: 0.75rem;
|
||||
background-color: #e5e7eb;
|
||||
color: #374151;
|
||||
padding: 3px 8px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* Bearbeiten-Button als Link deklariert */
|
||||
.edit-link-button {
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
font-size: 0.9rem;
|
||||
font-weight: bold;
|
||||
color: #2563eb;
|
||||
border: 1px solid #2563eb;
|
||||
padding: 6px 12px;
|
||||
border-radius: 6px;
|
||||
transition: background-color 0.2s, color 0.2s;
|
||||
}
|
||||
|
||||
.edit-link-button:hover {
|
||||
background-color: #2563eb;
|
||||
color: white;
|
||||
}
|
||||
@@ -69,12 +69,12 @@ CSS für die Suchergebnis-Seite
|
||||
|
||||
.s-res-filter-option input[type="radio"] {
|
||||
margin: 0;
|
||||
accent-color: #3182ce; /* Moderne Färbung des Radio-Buttons */
|
||||
accent-color: #3182ce;
|
||||
}
|
||||
|
||||
/* --- HAUPTINHALT (ERGEBNISSE) --- */
|
||||
.s-res-main-content {
|
||||
min-width: 0; /* Verhindert das Ausbrechen von Flex-Elementen */
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.s-res-header {
|
||||
@@ -164,7 +164,7 @@ CSS für die Suchergebnis-Seite
|
||||
transform: translateX(3px);
|
||||
}
|
||||
|
||||
/* --- ERGEBNISSE PRO SEITE & PAGINIERUNG --- */
|
||||
/* ERGEBNISSE PRO SEITE & PAGINIERUNG */
|
||||
.s-res-pagination-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
@@ -247,7 +247,7 @@ CSS für die Suchergebnis-Seite
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* --- RESPONSIVE DESIGN (MOBILGERÄTE) --- */
|
||||
/* Responsive Anpassungen unter 760px (für z.B. Smartphones) */
|
||||
@media (max-width: 768px) {
|
||||
.s-res-layout-grid {
|
||||
grid-template-columns: 1fr; /* Stapelt Seitenleiste und Inhalt untereinander */
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
+60
-17
@@ -1,27 +1,41 @@
|
||||
<?php
|
||||
session_start();
|
||||
?>
|
||||
|
||||
<!--
|
||||
Globales Menü, wird via PHP später in alle Seiten eingebunden
|
||||
-->
|
||||
<nav class="nav">
|
||||
<div class="nav__left">
|
||||
<a href="index.php" class="nav__logo">
|
||||
<img src="images/logos/logo_full.png" alt="Logo">
|
||||
</a>
|
||||
<img src="images/logos/logo_full.png" alt="Logo">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Mobile navbar mit Burger-Symbol -->
|
||||
<input type="checkbox" id="nav-toggle" class="nav__checkbox">
|
||||
<label for="nav-toggle" id="mobile-nav">
|
||||
<span>☰</span> <!-- Burger Icon Symbol -->
|
||||
<span>☰</span>
|
||||
</label>
|
||||
|
||||
<ul id="mobile-nav" class="nav__mobile-menu">
|
||||
<li>
|
||||
<label for="nav-toggle" class="nav__close-btn">×</label>
|
||||
</li>
|
||||
<li><a href="index.php?pfad=profile">Profil</a></li>
|
||||
<li><a href="index.php?pfad=login">Anmelden</a></li>
|
||||
<li><a href="index.php?pfad=register">Registrieren</a></li>
|
||||
<li><a href="index.php?pfad=createArticle">Beitrag erstellen</a></li>
|
||||
|
||||
<?php if (isset($_SESSION['user'])): ?>
|
||||
|
||||
<li><a href="index.php?pfad=profile">Profil</a></li>
|
||||
<li><a href="index.php?pfad=logout">Abmelden</a></li>
|
||||
<li><a href="index.php?pfad=createArticle">Beitrag erstellen</a></li>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<li><a href="index.php?pfad=login">Anmelden</a></li>
|
||||
<li><a href="index.php?pfad=register">Registrieren</a></li>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<li>
|
||||
<label class="nav__mobile-label">Sprachen</label>
|
||||
<ul class="nav__mobile-submenu">
|
||||
@@ -39,7 +53,7 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
|
||||
<li><a href="index.php?pfad=mathe">Mathematik</a></li>
|
||||
<li><a href="index.php?pfad=biologie">Biologie</a></li>
|
||||
<li><a href="index.php?pfad=chemie">Chemie</a></li>
|
||||
<li><a href="index.php?pfad=englisch">Physik</a></li>
|
||||
<li><a href="index.php?pfad=physik">Physik</a></li>
|
||||
<li><a href="index.php?pfad=informatik">Informatik</a></li>
|
||||
<li><a href="index.php?pfad=astronomie">Astronomie</a></li>
|
||||
</ul>
|
||||
@@ -85,6 +99,7 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
|
||||
<a href="index.php?pfad=literatur">Literatur</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="nav__item nav__dropdown">
|
||||
<button class="nav__dropdown-toggle">MINT</button>
|
||||
<div class="nav__dropdown-menu">
|
||||
@@ -96,6 +111,7 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
|
||||
<a href="index.php?pfad=astronomie">Astronomie</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="nav__item nav__dropdown">
|
||||
<button class="nav__dropdown-toggle">Gesellschaft & Werte</button>
|
||||
<div class="nav__dropdown-menu">
|
||||
@@ -112,6 +128,7 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
|
||||
<a href="index.php?pfad=theater">Theater</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="nav__item nav__dropdown">
|
||||
<button class="nav__dropdown-toggle">Technik & Praxis</button>
|
||||
<div class="nav__dropdown-menu">
|
||||
@@ -124,14 +141,40 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
|
||||
</div>
|
||||
|
||||
<div class="nav__right">
|
||||
<a href="index.php?pfad=profile" class="nav_item nav__link">Profil</a>
|
||||
<div class="nav__search">
|
||||
<?php
|
||||
include_once 'search.php';
|
||||
?>
|
||||
</div>
|
||||
<a href="index.php?pfad=login" class="nav__item nav__button">Anmelden</a>
|
||||
<a href="index.php?pfad=register" class="nav__item nav__button">Registrieren</a>
|
||||
<a href="index.php?pfad=createArticle" class="nav__item nav__button">Beitrag erstellen</a>
|
||||
|
||||
<?php if (isset($_SESSION['user'])): ?>
|
||||
|
||||
<a href="index.php?pfad=profile" class="nav__item nav__link">
|
||||
Profil
|
||||
</a>
|
||||
|
||||
<div class="nav__search">
|
||||
<?php include_once 'search.php'; ?>
|
||||
</div>
|
||||
|
||||
<a href="index.php?pfad=createArticle" class="nav__item nav__button">
|
||||
Beitrag erstellen
|
||||
</a>
|
||||
|
||||
<a href="index.php?pfad=logout" class="nav__item nav__button">
|
||||
Abmelden
|
||||
</a>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<div class="nav__search">
|
||||
<?php include_once 'search.php'; ?>
|
||||
</div>
|
||||
|
||||
<a href="index.php?pfad=login" class="nav__item nav__button">
|
||||
Anmelden
|
||||
</a>
|
||||
|
||||
<a href="index.php?pfad=register" class="nav__item nav__button">
|
||||
Registrieren
|
||||
</a>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
@@ -1,53 +1,83 @@
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($abs_path)) {
|
||||
require_once "path.php";
|
||||
}
|
||||
require_once $abs_path . "/php/controller/index-controller.php";
|
||||
ob_start();
|
||||
|
||||
$pfad = $_GET["pfad"] ?? "home";
|
||||
|
||||
/*
|
||||
Controller für Aktionen werden vor der HTML-Ausgabe geladen,
|
||||
damit Weiterleitungen mit header() funktionieren.
|
||||
*/
|
||||
if ($pfad === "login") {
|
||||
include_once "php/controller/login-controller.php";
|
||||
}
|
||||
|
||||
if ($pfad === "register") {
|
||||
include_once "php/controller/register-controller.php";
|
||||
}
|
||||
|
||||
if ($pfad === "logout") {
|
||||
include_once "content/logout.php";
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($pfad === "deleteAccount") {
|
||||
include_once "content/deleteAccount.php";
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
|
||||
<!--
|
||||
Seite: Index der Lernplattform
|
||||
Funktion: Webseitengerüst, Anzeigen von Content
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<!--
|
||||
Seite: Index der Lernplattform
|
||||
Funktion: Webseitengerüst, Anzeigen von Content
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="description" content="EduForge">
|
||||
<meta name="author" content="Niklas Ortmann">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="icon" type="image/x-icon" href="images/logos/logo_icon.ico">
|
||||
<link rel="stylesheet" href="css/main.css">
|
||||
<link rel="stylesheet" href="css/navbar.css">
|
||||
<link rel="stylesheet" href="css/footer.css">
|
||||
<link rel="stylesheet" href="css/search-results.css">
|
||||
<link rel="stylesheet" href="css/createArticle.css">
|
||||
<link rel="stylesheet" href="css/showArticle.css">
|
||||
<link rel="stylesheet" href="css/message.css">
|
||||
<title>EduForge</title>
|
||||
</head>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="description" content="EduForge">
|
||||
<meta name="author" content="Niklas Ortmann">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="icon" type="image/x-icon" href="images/logos/logo_icon.ico">
|
||||
<link rel="stylesheet" href="css/main.css">
|
||||
<link rel="stylesheet" href="css/navbar.css">
|
||||
<link rel="stylesheet" href="css/footer.css">
|
||||
<link rel="stylesheet" href="css/search-results.css">
|
||||
<link rel="stylesheet" href="css/createArticle.css">
|
||||
<link rel="stylesheet" href="css/profile.css">
|
||||
<link rel="stylesheet" href="css/showArticle.css">
|
||||
<link rel="stylesheet" href="css/message.css">
|
||||
<title>EduForge</title>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<?php
|
||||
include_once 'includes/navbar.php';
|
||||
//Dynamischer Inhalt:
|
||||
if (isset($_GET["pfad"])) {
|
||||
|
||||
if (file_exists($abs_path . '/content/' . $_GET["pfad"] . '.php')) {
|
||||
include_once $abs_path . '/content/' . $_GET["pfad"] . '.php';
|
||||
/*
|
||||
Dynamischer Inhalt:
|
||||
Je nach pfad-Parameter wird die passende Datei aus content geladen.
|
||||
*/
|
||||
if (isset($_GET["pfad"])) {
|
||||
if (file_exists('content/' . $_GET["pfad"] . '.php')) {
|
||||
include_once 'content/' . $_GET["pfad"] . '.php';
|
||||
} else {
|
||||
include_once $abs_path . '/content/404.php';
|
||||
include_once 'content/404.php';
|
||||
}
|
||||
} else {
|
||||
include_once $abs_path . '/content/home.php';
|
||||
include_once 'content/home.php';
|
||||
}
|
||||
include_once $abs_path . '/includes/footer.php';
|
||||
?>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
include_once 'includes/footer.php';
|
||||
?>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php
|
||||
ob_end_flush();
|
||||
?>
|
||||
@@ -1,3 +1,4 @@
|
||||
<?php
|
||||
// mit $_SERVER['DOCUMENT_ROOT'] später umbauen?
|
||||
$abs_path = __DIR__;
|
||||
?>
|
||||
|
||||
@@ -1,32 +1,89 @@
|
||||
<?php
|
||||
session_start();
|
||||
SESSION_START();
|
||||
require_once '../model/LocalArticleManager.php';
|
||||
require_once '../model/ArticleManager.php';
|
||||
require_once '../validator/article-validator.php';
|
||||
require_once "../model/LocalUserDAO.php";
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
if(!isset($_POST["title"]) ||!isset($_POST["content"]) || !isset($_POST["category"])){
|
||||
$_SESSION["message"] = "missing_parameters";
|
||||
header("location: ../../index.php?pfad=createArticle");
|
||||
} else {
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$_SESSION["old_title"] = $_POST["title"] ?? '';
|
||||
$_SESSION["old_content"] = $_POST["content"] ?? '';
|
||||
$_SESSION["old_category"] = $_POST["category"] ?? '';
|
||||
$_SESSION["old_tags"] = $_POST["tags"] ?? '';
|
||||
|
||||
$title = $_POST["title"];
|
||||
$content = $_POST["content"];
|
||||
$category = $_POST["category"];
|
||||
$author = "max.mustermann"; // TODO: später aus Session den angemeldeten Nutzer beziehen.
|
||||
$tags = $_POST["tags"];
|
||||
if(!isset($_POST["title"]) ||!isset($_POST["content"]) || !isset($_POST["category"])){
|
||||
$_SESSION["message"] = "missing_parameters";
|
||||
header("location: ../../index.php?pfad=createArticle");
|
||||
exit();
|
||||
} else {
|
||||
$title = $_POST["title"];
|
||||
$content = $_POST["content"];
|
||||
$author = $_SESSION["user_email"];
|
||||
$category = $_POST["category"];
|
||||
$tags = $_POST['tags'] ?? '';
|
||||
|
||||
try {
|
||||
$articleManager = ArticleManager::getInstance();
|
||||
$articleManager->addArticle($title, $content, $author, $category, $tags);
|
||||
} catch (Exception $e){
|
||||
$_SESSION["message"] = "internal_error";
|
||||
// -------------------------------- Validierung der Daten: -------------------------
|
||||
if (!articleAuthorValidator($author)) {
|
||||
$_SESSION["message"] = "author_not_valid";
|
||||
header("location: ../../index.php?pfad=createArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleTitleValidator($title)) {
|
||||
$_SESSION["message"] = "invalid_title";
|
||||
header("location: ../../index.php?pfad=createArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleContentValidator($content)) {
|
||||
$_SESSION["message"] = "invalid_content";
|
||||
header("location: ../../index.php?pfad=createArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleCategoryValidator($category)) {
|
||||
$_SESSION["message"] = "invalid_category";
|
||||
header("location: ../../index.php?pfad=createArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleTagValidator($tags)) {
|
||||
$_SESSION["message"] = "invalid_tags";
|
||||
header("location: ../../index.php?pfad=createArticle");
|
||||
exit();
|
||||
} else {
|
||||
$cleanedTags = [];
|
||||
$rawTags = explode(',', $tags);
|
||||
foreach ($rawTags as $rawTag) {
|
||||
// Leerzeichen am Anfang/Ende des einzelnen Tags entfernen:
|
||||
$tag = trim($rawTag);
|
||||
$cleanedTags[] = $tag;
|
||||
}
|
||||
// Duplikate entfernen:
|
||||
$cleanedTags = array_unique($cleanedTags);
|
||||
$cleanedTags = implode(',', $cleanedTags);
|
||||
}
|
||||
// ----------------- Übertragung der validierten Daten in ArticleManager: ---------------------------
|
||||
try {
|
||||
$articleManager = ArticleManager::getInstance();
|
||||
$articleManager->addArticle($title, $content, $author, $category, $cleanedTags);
|
||||
|
||||
// Formulardaten nach erfolgreichem Erstellen aus der Session löschen
|
||||
unset($_SESSION["old_title"], $_SESSION["old_content"], $_SESSION["old_category"], $_SESSION["old_tags"]);
|
||||
|
||||
} catch (Exception $e){
|
||||
$_SESSION["message"] = "internal_error";
|
||||
header("location: ../../index.php?pfad=createArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
$_SESSION["message"] = "new_article";
|
||||
// Weiterleitung zur Homepage
|
||||
header("location: ../../index.php");
|
||||
exit();
|
||||
}
|
||||
$_SESSION["message"] = "new_article";
|
||||
// Weiterleitung zur Homepage
|
||||
header("location: ../../index.php");
|
||||
exit();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
require_once "php/model/LocalUserDAO.php";
|
||||
|
||||
$dao = new LocalUserDAO();
|
||||
$error = null;
|
||||
|
||||
/*
|
||||
Verarbeitung des Login-Formulars
|
||||
Funktion: Prüft Benutzerdaten und erstellt Session für eingeloggten Nutzer
|
||||
*/
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
$email = $_POST["email"] ?? "";
|
||||
$password = $_POST["password"] ?? "";
|
||||
|
||||
$user = $dao->findUser($email);
|
||||
|
||||
if ($user && password_verify($password, $user["password"])) {
|
||||
|
||||
$_SESSION["user"] = $user["username"];
|
||||
$_SESSION["user_email"] = $user["email"];
|
||||
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
|
||||
} else {
|
||||
$error = "Login fehlgeschlagen. Bitte überprüfe deine Eingaben.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
require_once "php/model/LocalUserDAO.php";
|
||||
require_once 'php/model/Article.php';
|
||||
require_once 'php/model/ArticleManager.php';
|
||||
|
||||
if (!isset($_SESSION["user"])) {
|
||||
header("Location: index.php?pfad=login");
|
||||
exit();
|
||||
}
|
||||
|
||||
try {
|
||||
$dao = new LocalUserDAO();
|
||||
$user = $dao->findUser($_SESSION["user_email"] ?? "");
|
||||
$articleManager = ArticleManager::getInstance();
|
||||
$userArticles = $articleManager->getArticlesByAuthor($_SESSION["user_email"]);
|
||||
if(!isset($userArticles)) {
|
||||
$_SESSION["message"] = "user_has_no_articles";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$_SESSION["message"] = "internal_error";
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
$_SESSION = [];
|
||||
session_destroy();
|
||||
|
||||
header("Location: index.php?pfad=login");
|
||||
exit();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/*
|
||||
* Controller für die Liste der eigenen Beiträge eines Nutzers auf der eigenen Profilseite
|
||||
*/
|
||||
|
||||
require_once 'php/model/Article.php';
|
||||
require_once 'php/model/ArticleManager.php';
|
||||
require_once "../model/LocalUserDAO.php";
|
||||
|
||||
try {
|
||||
$dao = new LocalUserDAO();
|
||||
$user = $dao->findUser($_SESSION["user_email"] ?? "");
|
||||
|
||||
$author = $user["email"];
|
||||
$articleManager = ArticleManager::getInstance();
|
||||
$userArticles = $articleManager->getArticlesByAuthor($author);
|
||||
if(!isset($userArticles)) {
|
||||
$_SESSION["message"] = "user_has_no_articles";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$_SESSION["message"] = "internal_error";
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
require_once "php/model/LocalUserDAO.php";
|
||||
|
||||
$dao = new LocalUserDAO();
|
||||
$error = null;
|
||||
|
||||
/*
|
||||
Verarbeitung des Registrierungs-Formulars
|
||||
Funktion: Erstellt neuen Benutzer und speichert ihn im DAO + Session
|
||||
*/
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
$email = $_POST["email"] ?? "";
|
||||
$vorname = $_POST["vorname"] ?? "";
|
||||
$nachname = $_POST["nachname"] ?? "";
|
||||
$password = password_hash(
|
||||
$_POST["password"] ?? "",
|
||||
PASSWORD_DEFAULT
|
||||
);
|
||||
|
||||
if ($dao->findUser($email)) {
|
||||
|
||||
$error = "Diese E-Mail-Adresse ist bereits registriert.";
|
||||
|
||||
} else {
|
||||
|
||||
$dao->addUser(
|
||||
$email,
|
||||
$vorname . " " . $nachname,
|
||||
$password
|
||||
);
|
||||
|
||||
$_SESSION["user"] = $vorname . " " . $nachname;
|
||||
$_SESSION["user_email"] = $email;
|
||||
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,11 @@ session_start();
|
||||
require_once 'php/model/Article.php';
|
||||
require_once 'php/model/ArticleManager.php';
|
||||
|
||||
if (isset($_GET["id"])){
|
||||
if (isset($_GET["id"]) && !empty($_GET["id"])){
|
||||
try {
|
||||
$id = $_GET["id"];
|
||||
$articleManager = ArticleManager::getInstance();
|
||||
$article = $articleManager->getArticle($_GET["id"]);
|
||||
$article = $articleManager->getArticle($id);
|
||||
if($article != null){
|
||||
$title = $article->getTitle();
|
||||
$content = $article->getContent();
|
||||
@@ -14,15 +15,15 @@ if (isset($_GET["id"])){
|
||||
$author = $article->getAuthor();
|
||||
$tags = $article->getTags();
|
||||
}else{
|
||||
$_SESSION["message"] = "article_not_found";
|
||||
echo "article_not_found";
|
||||
//header("location: index.php?pfad=404");
|
||||
include_once "content/404.php";
|
||||
exit();
|
||||
}
|
||||
} catch (Exception $e){
|
||||
$_SESSION["message"] = "internal_error";
|
||||
echo "Fehler aufgetreten: " . $e->getMessage();
|
||||
exit();
|
||||
}
|
||||
}else{
|
||||
$_SESSION["message"] = "article_not_found";
|
||||
echo "article_not_found";
|
||||
$_SESSION["message"] = "missing_id";
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once '../model/LocalArticleManager.php';
|
||||
require_once '../model/ArticleManager.php';
|
||||
require_once '../model/Article.php';
|
||||
require_once '../validator/article-validator.php';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$_SESSION["old_title"] = $_POST["title"] ?? '';
|
||||
$_SESSION["old_content"] = $_POST["content"] ?? '';
|
||||
$_SESSION["old_category"] = $_POST["category"] ?? '';
|
||||
$_SESSION["old_tags"] = $_POST["tags"] ?? '';
|
||||
|
||||
if (isset($_GET["id"]) && !empty($_GET["id"])) {
|
||||
$id = $_GET["id"];
|
||||
} else {
|
||||
$_SESSION["message"] = "missing_id";
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!isset($_POST["title"]) ||!isset($_POST["content"]) || !isset($_POST["category"])){
|
||||
$_SESSION["message"] = "missing_parameters";
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
}else{
|
||||
$title = $_POST["title"];
|
||||
$content = $_POST["content"];
|
||||
$author = "max.mustermann"; // TODO: später aus Session den angemeldeten Nutzer beziehen.
|
||||
$category = $_POST["category"];
|
||||
$tags = $_POST['tags'] ?? '';
|
||||
|
||||
// -------------------------------- Validierung der Daten: -------------------------
|
||||
if (!articleAuthorValidator($author)) {
|
||||
$_SESSION["message"] = "author_not_valid";
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleTitleValidator($title)) {
|
||||
$_SESSION["message"] = "invalid_title";
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleContentValidator($content)) {
|
||||
$_SESSION["message"] = "invalid_content";
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleCategoryValidator($category)) {
|
||||
$_SESSION["message"] = "invalid_category";
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleTagValidator($tags)) {
|
||||
$_SESSION["message"] = "invalid_tags";
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
} else {
|
||||
$cleanedTags = [];
|
||||
$rawTags = explode(',', $tags);
|
||||
foreach ($rawTags as $rawTag) {
|
||||
// Leerzeichen am Anfang/Ende des einzelnen Tags entfernen:
|
||||
$tag = trim($rawTag);
|
||||
$cleanedTags[] = $tag;
|
||||
}
|
||||
// Duplikate entfernen:
|
||||
$cleanedTags = array_unique($cleanedTags);
|
||||
$cleanedTags = implode(',', $cleanedTags);
|
||||
}
|
||||
|
||||
// ----------------- Übertragung der validierten Daten in ArticleManager: ---------------------------
|
||||
try {
|
||||
$articleManager = ArticleManager::getInstance();
|
||||
$article = $articleManager->getArticle($id);
|
||||
$article->setTitle($title);
|
||||
$article->setContent($content);
|
||||
$article->setCategory($category);
|
||||
$article->setTags($cleanedTags);
|
||||
$articleManager->updateArticle($id ,$article, $author);
|
||||
} catch (Exception $e){
|
||||
$_SESSION["message"] = "internal_error";
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
}
|
||||
$_SESSION["message"] = "article_updated";
|
||||
// Weiterleitung zur Homepage
|
||||
header("location: ../../index.php?pfad=showArticle&id=$id");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
+21
-11
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Klasse: Artikel
|
||||
* Diese Klasse stellt alle Daten eines Artikels (Beitrag) bereit
|
||||
* Diese Klasse stellt alle Daten eines Beitrags (Beitrag) bereit
|
||||
*
|
||||
* @author Niklas Ortmann
|
||||
*/
|
||||
@@ -38,7 +38,7 @@ class Article
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die ID eines Artikels zurück.
|
||||
* Gibt die ID eines Beitrags zurück.
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
@@ -47,7 +47,7 @@ class Article
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Titel eines Artikels zurück.
|
||||
* Gibt den Titel eines Beitrags zurück.
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle(): string
|
||||
@@ -56,7 +56,7 @@ class Article
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt den Titel eines Artikels
|
||||
* Setzt den Titel eines Beitrags
|
||||
* @param $title
|
||||
* @return void
|
||||
*/
|
||||
@@ -66,7 +66,7 @@ class Article
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Content eines Artikels zurück.
|
||||
* Gibt den Content eines Beitrags zurück.
|
||||
* TODO: Content muss noch definiert werden.
|
||||
* @return string
|
||||
*/
|
||||
@@ -76,7 +76,7 @@ class Article
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt den Content eines Artikels.
|
||||
* Setzt den Content eines Beitrags.
|
||||
* TODO: Content muss noch definiert werden.
|
||||
* @param $content
|
||||
* @return void
|
||||
@@ -87,7 +87,7 @@ class Article
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Autor eines Artikels zurück.
|
||||
* Gibt den Autor eines Beitrags zurück.
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthor(): string
|
||||
@@ -96,7 +96,7 @@ class Article
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt das Veröffentlichungsdatum des Artikels zurück.
|
||||
* Gibt das Veröffentlichungsdatum des Beitrags zurück.
|
||||
* @return string
|
||||
*/
|
||||
public function getCreationDate(): string
|
||||
@@ -105,7 +105,7 @@ class Article
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die Kategorie eines Artikels zurück.
|
||||
* Gibt die Kategorie eines Beitrags zurück.
|
||||
* @return string
|
||||
*/
|
||||
public function getCategory(): string
|
||||
@@ -114,7 +114,17 @@ class Article
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die Schlagworte eines Artikels zurück.
|
||||
* Setzt die Kategorie eines Beitrags.
|
||||
* @param string $category
|
||||
* @return void
|
||||
*/
|
||||
public function setCategory(string $category)
|
||||
{
|
||||
$this->category = $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die Schlagworte eines Beitrags zurück.
|
||||
* @return string
|
||||
*/
|
||||
public function getTags(): string
|
||||
@@ -123,7 +133,7 @@ class Article
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt die Schlagworte eines Artikels.
|
||||
* Setzt die Schlagworte eines Beitrags.
|
||||
* @param string $tags
|
||||
*/
|
||||
public function setTags(string $tags)
|
||||
|
||||
@@ -21,26 +21,24 @@ interface ArticleManagerDAO
|
||||
public function addArticle($title, $content, $author, $category, $tags);
|
||||
|
||||
/**
|
||||
* Ein angemeldeter Nutzer bearbeitet einen Beitrag.
|
||||
* $id ID des Beitrags
|
||||
* $title Titel des Beitrags
|
||||
* $content Der Inhalt des Beitrags
|
||||
* $author dem Author des des Beitrags (NID oder email)
|
||||
* Ändert den gespeicherten Beitrag eines übergebenen Beitrags und eines Autors.
|
||||
* Es wird geprüft, ob der zu änderne Beitrag existiert und ob der übergebene Autor der Autor des originalen
|
||||
* Beitrages ist.
|
||||
* @param $id
|
||||
* @param $article
|
||||
* @param $author
|
||||
* @return void
|
||||
*
|
||||
* Mögliche Exceptions:
|
||||
* TODO Fehlerbeschreibung hinzufügen
|
||||
* TODO: Fehlerbeschreibung hinzufügen
|
||||
*/
|
||||
public function updateArticle($id, $title, $content, $author);
|
||||
public function updateArticle($id, $article, $author);
|
||||
|
||||
/*
|
||||
* Ein angemeldeter Nutzer löscht einen seiner Beiträge.
|
||||
* $id ID des Beitrags
|
||||
* $title Titel des Beitrags
|
||||
* $content Der Inhalt des Beitrags
|
||||
* $author dem Author des des Beitrags (NID oder email)
|
||||
/**
|
||||
* Löscht einen Beitrag aus übergebener ID.
|
||||
* @param $id
|
||||
* @return void
|
||||
*
|
||||
* Mögliche Exceptions:
|
||||
* TODO Fehlerbeschreibung hinzufügen
|
||||
* TODO: Fehlerbeschreibung hinzufügen
|
||||
*/
|
||||
public function deleteArticle($id);
|
||||
|
||||
@@ -62,9 +60,16 @@ interface ArticleManagerDAO
|
||||
*/
|
||||
public function getAllArticles();
|
||||
|
||||
/**
|
||||
* Gibt alle Beiträge eines Nutzer mit einer gegebenen ID aus.
|
||||
* @param $author
|
||||
* @return Article[]
|
||||
*/
|
||||
public function getArticlesByAuthor($author);
|
||||
|
||||
/**
|
||||
* Such-Funktion
|
||||
*
|
||||
*
|
||||
* $keyword Wort, nach dem gesucht wird als string
|
||||
*/
|
||||
public function search(string $keyword): array;
|
||||
|
||||
@@ -62,14 +62,65 @@ class LocalArticleManager implements ArticleManagerDAO {
|
||||
$this->saveArticle($articles);
|
||||
}
|
||||
|
||||
public function updateArticle($id, $title, $content, $author)
|
||||
public function updateArticle($id, $article, $author)
|
||||
{
|
||||
// TODO: Implement updateArticle() method.
|
||||
if (empty($article)) {
|
||||
// TODO: Implement Exception.
|
||||
return;
|
||||
}
|
||||
|
||||
// Berechtigungsprüfung:
|
||||
if ($article->getAuthor() !== $author) {
|
||||
// TODO: Implement Exception.
|
||||
return;
|
||||
}
|
||||
|
||||
// Beitrag aktualisieren:
|
||||
$articles = $this->getAllArticles();
|
||||
$updated = false;
|
||||
|
||||
foreach ($articles as $index => $storedArticle) {
|
||||
if (isset($storedArticle['id']) && $storedArticle['id'] == $id) {
|
||||
$articles[$index] = [
|
||||
"id" => $id,
|
||||
"title" => $article->getTitle(),
|
||||
"content" => $article->getContent(),
|
||||
"author" => $author,
|
||||
"category" => $article->getCategory(),
|
||||
"tags" => $article->getTags(),
|
||||
"creationDate" => $article->getCreationDate()
|
||||
];
|
||||
$updated = true;
|
||||
break;
|
||||
}else{
|
||||
// TODO: Implement Exception.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Nur speichern, wenn Beitrag geändert wurde:
|
||||
if ($updated) {
|
||||
$this->saveArticle($articles);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteArticle($id)
|
||||
{
|
||||
// TODO: Implement deleteArticle() method.
|
||||
$articles = $this->getAllArticles();
|
||||
$articleFound = false;
|
||||
|
||||
foreach ($articles as $index => $article) {
|
||||
if (isset($article['id']) && $article['id'] == $id) {
|
||||
unset($articles[$index]);
|
||||
$articleFound = true;
|
||||
break; // Schleife abbrechen, da die ID eindeutig ist
|
||||
}
|
||||
}
|
||||
|
||||
if ($articleFound) {
|
||||
// array_values stellt sicher, dass die Array-Keys wieder fortlaufend bei 0 beginnen
|
||||
$this->saveArticle(array_values($articles));
|
||||
}
|
||||
}
|
||||
|
||||
public function getArticle($id)
|
||||
@@ -97,7 +148,28 @@ class LocalArticleManager implements ArticleManagerDAO {
|
||||
return is_array($articles) ? $articles : [];
|
||||
}
|
||||
|
||||
public function search(string $keyword): array
|
||||
public function getArticlesByAuthor($author)
|
||||
{
|
||||
$articles = $this->getAllArticles();
|
||||
$filteredArticles = [];
|
||||
|
||||
foreach ($articles as $article) {
|
||||
if (isset($article['author']) && $article['author'] == $author) {
|
||||
$filteredArticles[] = new Article(
|
||||
intval($article['id']),
|
||||
$article['title'],
|
||||
$article['content'],
|
||||
$article['author'],
|
||||
$article['category'],
|
||||
$article['tags'],
|
||||
$article['creationDate']
|
||||
);
|
||||
}
|
||||
}
|
||||
return $filteredArticles;
|
||||
}
|
||||
|
||||
public function search(string $keyword): array
|
||||
{
|
||||
$results = [];
|
||||
$contentFolder = __DIR__ . '/../content/';
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
require_once "UserDAOInterface.php";
|
||||
|
||||
class LocalUserDAO implements UserDAOInterface {
|
||||
|
||||
private string $file = "data/users.json";
|
||||
|
||||
private function loadUsers() {
|
||||
if (!file_exists($this->file)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$json = file_get_contents($this->file);
|
||||
$users = json_decode($json, true);
|
||||
|
||||
return is_array($users) ? $users : [];
|
||||
}
|
||||
|
||||
private function saveUsers($users) {
|
||||
file_put_contents(
|
||||
$this->file,
|
||||
json_encode($users, JSON_PRETTY_PRINT)
|
||||
);
|
||||
}
|
||||
|
||||
public function findUser($email) {
|
||||
$users = $this->loadUsers();
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($user["email"] === $email) {
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function addUser($email, $username, $password) {
|
||||
$users = $this->loadUsers();
|
||||
|
||||
$users[] = [
|
||||
"email" => $email,
|
||||
"username" => $username,
|
||||
"password" => $password
|
||||
];
|
||||
|
||||
$this->saveUsers($users);
|
||||
}
|
||||
|
||||
public function deleteUser($email) {
|
||||
$users = $this->loadUsers();
|
||||
|
||||
foreach ($users as $i => $user) {
|
||||
if ($user["email"] === $email) {
|
||||
unset($users[$i]);
|
||||
$users = array_values($users);
|
||||
$this->saveUsers($users);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Interface für den Zugriff auf Benutzerdaten.
|
||||
*
|
||||
* Definiert die Methoden, die jede UserDAO-Implementierung
|
||||
* bereitstellen muss.
|
||||
*/
|
||||
interface UserDAOInterface {
|
||||
|
||||
/**
|
||||
* Sucht einen Benutzer anhand seiner E-Mail-Adresse.
|
||||
*
|
||||
* @param string $email E-Mail-Adresse des gesuchten Benutzers
|
||||
* @return array|null Benutzerdaten als Array oder null
|
||||
*/
|
||||
public function findUser($email);
|
||||
|
||||
/**
|
||||
* Fügt einen neuen Benutzer hinzu.
|
||||
*
|
||||
* @param string $email E-Mail-Adresse des Benutzers
|
||||
* @param string $username Benutzername des Benutzers
|
||||
* @param string $password Passwort des Benutzers
|
||||
* @return void
|
||||
*/
|
||||
public function addUser($email, $username, $password);
|
||||
|
||||
/**
|
||||
* Löscht einen Benutzer anhand seiner E-Mail-Adresse.
|
||||
*
|
||||
* @param string $email E-Mail-Adresse des zu löschenden Benutzers
|
||||
* @return bool true, wenn der Benutzer gelöscht wurde, sonst false
|
||||
*/
|
||||
public function deleteUser($email);
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Prüft, ob der Autor auch der Eigentümer des Beitrags ist.
|
||||
* @param $author
|
||||
* @return true
|
||||
* TODO: Implement this.
|
||||
*/
|
||||
function articleAuthorValidator($author)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob der Titel die folgenden Bedingungen erfüllt:
|
||||
* Buchstaben von a-z; A-Z
|
||||
* Zahlen von 0-9
|
||||
* Umlaute äöüÄÖÜß
|
||||
* Satzeichen .,!?:;()"„“«»_+-
|
||||
* 5-120 Zeichen
|
||||
* @param $title
|
||||
* @return bool
|
||||
*/
|
||||
function articleTitleValidator($title)
|
||||
{
|
||||
$title = trim($title);
|
||||
$titlePattern = '/^[a-zA-Z0-9äöüÄÖÜß\s.,!?:;()\'"„“«»_+-]{5,120}$/u';
|
||||
if (preg_match($titlePattern, $title)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob der Contenttext 10-7000 Zeichen enthält.
|
||||
* @param $content
|
||||
* @return bool
|
||||
*/
|
||||
function articleContentValidator($content)
|
||||
{
|
||||
$content = trim($content);
|
||||
$zeichenAnzahl = mb_strlen($content);
|
||||
if ($zeichenAnzahl <= 7000 && $zeichenAnzahl >= 10) {
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob die Kategorie eine erlaubt Kategorie ist.
|
||||
* @param $category
|
||||
* @return bool
|
||||
*/
|
||||
function articleCategoryValidator($category)
|
||||
{
|
||||
$allowedCategories = [
|
||||
'deutsch', 'englisch', 'franzoesisch', 'latein', 'literatur',
|
||||
'mathe', 'biologie', 'chemie', 'physik', 'informatik', 'astronomie',
|
||||
'geschichte', 'erdkunde', 'sozialkunde', 'wirtschaft', 'religion',
|
||||
'ethik', 'philosophie', 'psychologie', 'kunst', 'musik', 'theater',
|
||||
'technik', 'werken', 'hauswirtschaft', 'sport'
|
||||
];
|
||||
if (in_array($category, $allowedCategories, true)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob die Tags die folgenden Bedingungen erfüllen:
|
||||
* Buchstaben von a-z; A-Z
|
||||
* Zahlen von 0-9
|
||||
* Umlaute äöüÄÖÜß
|
||||
* Satzeichen -
|
||||
* 2-50 Zeichen
|
||||
* @param $tags
|
||||
* @return bool
|
||||
*/
|
||||
function articleTagValidator($tags)
|
||||
{
|
||||
if (!isset($tags)) {
|
||||
$tags = '';
|
||||
}
|
||||
|
||||
$rawTags = explode(',', $tags);
|
||||
|
||||
foreach ($rawTags as $rawTag) {
|
||||
// Leerzeichen am Anfang/Ende des einzelnen Tags entfernen:
|
||||
$tag = trim($rawTag);
|
||||
|
||||
// leere Elemente überspringen:
|
||||
if ($tag === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Tag mit Regex prüfen:
|
||||
$tagPattern = '/^[a-zA-Z0-9äöüÄÖÜß\s-]{2,50}$/u';
|
||||
if (!preg_match($tagPattern, $tag)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user