Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a33f3b27fb |
@@ -18,40 +18,11 @@ session_start();
|
||||
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-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>
|
||||
<input type="text" id="title" name="title" placeholder="Titel hier eingeben" required>
|
||||
<textarea id="content" name="content" placeholder="Schreibe deinen Beitrag..."></textarea>
|
||||
</main>
|
||||
|
||||
<!-- Seitenleiste -->
|
||||
@@ -108,9 +79,7 @@ session_start();
|
||||
|
||||
<div class="sidebar-block">
|
||||
<label for="tags">Schlagwörter</label>
|
||||
<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)">
|
||||
<input type="text" id="tags" name="tags" placeholder="z.B. Technik, IT (mit Komma trennen)">
|
||||
</div>
|
||||
|
||||
</aside>
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<?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"): ?>
|
||||
|
||||
@@ -23,52 +23,12 @@ include_once 'php/controller/showArticle-controller.php';
|
||||
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>
|
||||
<input type="text" id="title" name="title" value="<?php if (isset($title) && !empty($title)){echo htmlspecialchars($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']);
|
||||
}
|
||||
?>
|
||||
<?php if (isset($content) && !empty($content)){echo htmlspecialchars($content);} ?>
|
||||
</textarea>
|
||||
</main>
|
||||
|
||||
@@ -126,15 +86,7 @@ include_once 'php/controller/showArticle-controller.php';
|
||||
|
||||
<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)">
|
||||
<input type="text" id="tags" name="tags" value="<?php if (isset($tags) && !empty($tags)){echo htmlspecialchars($tags);} ?>" placeholder="z.B. Technik, IT (mit Komma trennen)">
|
||||
</div>
|
||||
|
||||
</aside>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
<?php
|
||||
// mit $_SERVER['DOCUMENT_ROOT'] später umbauen?
|
||||
$abs_path = __DIR__;
|
||||
?>
|
||||
|
||||
@@ -2,84 +2,30 @@
|
||||
session_start();
|
||||
require_once '../model/LocalArticleManager.php';
|
||||
require_once '../model/ArticleManager.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($_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 = "max.mustermann"; // TODO: später aus Session den angemeldeten Nutzer beziehen.
|
||||
$category = $_POST["category"];
|
||||
$tags = $_POST['tags'] ?? '';
|
||||
$author = "max.mustermann"; // TODO: später aus Session den angemeldeten Nutzer beziehen.
|
||||
$tags = $_POST["tags"];
|
||||
|
||||
// -------------------------------- 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"]);
|
||||
|
||||
$articleManager->addArticle($title, $content, $author, $category, $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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ session_start();
|
||||
require_once 'php/model/Article.php';
|
||||
require_once 'php/model/ArticleManager.php';
|
||||
|
||||
if (isset($_GET["id"]) && !empty($_GET["id"])){
|
||||
if (isset($_GET["id"])){
|
||||
try {
|
||||
$id = $_GET["id"];
|
||||
$articleManager = ArticleManager::getInstance();
|
||||
@@ -15,15 +15,12 @@ if (isset($_GET["id"]) && !empty($_GET["id"])){
|
||||
$author = $article->getAuthor();
|
||||
$tags = $article->getTags();
|
||||
}else{
|
||||
//header("location: index.php?pfad=404");
|
||||
include_once "content/404.php";
|
||||
exit();
|
||||
$_SESSION["message"] = "article_not_found";
|
||||
}
|
||||
} catch (Exception $e){
|
||||
$_SESSION["message"] = "internal_error";
|
||||
exit();
|
||||
}
|
||||
}else{
|
||||
$_SESSION["message"] = "missing_id";
|
||||
$_SESSION["message"] = "article_not_found";
|
||||
}
|
||||
?>
|
||||
@@ -3,93 +3,44 @@ 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"])) {
|
||||
try {
|
||||
$id = $_GET["id"];
|
||||
} else {
|
||||
} catch (Exception $e){
|
||||
$_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();
|
||||
} elseif(!isset($id)) {
|
||||
$_SESSION["message"] = "missing_id";
|
||||
//header("location: ../../index.php?pfad=updateArticle");
|
||||
}else{
|
||||
$title = $_POST["title"];
|
||||
$content = $_POST["content"];
|
||||
|
||||
$newTitle = $_POST["title"];
|
||||
$newContent = $_POST["content"];
|
||||
$newCategory = $_POST["category"];
|
||||
$author = "max.mustermann"; // TODO: später aus Session den angemeldeten Nutzer beziehen.
|
||||
$category = $_POST["category"];
|
||||
$tags = $_POST['tags'] ?? '';
|
||||
$newTags = $_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();
|
||||
$articleManager = ArticleManager::getInstance(); // TODO: Später aus Session den Nutzer auslesen und Autorenrechte prüfen!
|
||||
$article = $articleManager->getArticle($id);
|
||||
$article->setTitle($title);
|
||||
$article->setContent($content);
|
||||
$article->setCategory($category);
|
||||
$article->setTags($cleanedTags);
|
||||
$article->setTitle($newTitle);
|
||||
$article->setContent($newContent);
|
||||
$article->setCategory($newCategory);
|
||||
$article->setTags($newTags);
|
||||
$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");
|
||||
|
||||
}
|
||||
exit();
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,107 +0,0 @@
|
||||
<?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