Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 17345345b5 | |||
| 3df526d5b5 |
@@ -10,15 +10,19 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
$_SESSION["old_content"] = $_POST["content"] ?? '';
|
$_SESSION["old_content"] = $_POST["content"] ?? '';
|
||||||
$_SESSION["old_category"] = $_POST["category"] ?? '';
|
$_SESSION["old_category"] = $_POST["category"] ?? '';
|
||||||
$_SESSION["old_tags"] = $_POST["tags"] ?? '';
|
$_SESSION["old_tags"] = $_POST["tags"] ?? '';
|
||||||
try {
|
|
||||||
|
if (isset($_GET["id"]) && !empty($_GET["id"])) {
|
||||||
$id = $_GET["id"];
|
$id = $_GET["id"];
|
||||||
} catch (Exception $e){
|
} else {
|
||||||
$_SESSION["message"] = "missing_id";
|
$_SESSION["message"] = "missing_id";
|
||||||
|
header("location: ../../index.php?pfad=updateArticle");
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($_POST["title"]) ||!isset($_POST["content"]) || !isset($_POST["category"])){
|
if (!isset($_POST["title"]) ||!isset($_POST["content"]) || !isset($_POST["category"])){
|
||||||
$_SESSION["message"] = "missing_parameters";
|
$_SESSION["message"] = "missing_parameters";
|
||||||
} elseif(!isset($id)) {
|
header("location: ../../index.php?pfad=updateArticle");
|
||||||
$_SESSION["message"] = "missing_id";
|
exit();
|
||||||
}else{
|
}else{
|
||||||
$title = $_POST["title"];
|
$title = $_POST["title"];
|
||||||
$content = $_POST["content"];
|
$content = $_POST["content"];
|
||||||
@@ -33,31 +37,31 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
// -------------------------------- Validierung der Daten: -------------------------
|
// -------------------------------- Validierung der Daten: -------------------------
|
||||||
if (!articleAuthorValidator($author)) {
|
if (!articleAuthorValidator($author)) {
|
||||||
$_SESSION["message"] = "author_not_valid";
|
$_SESSION["message"] = "author_not_valid";
|
||||||
header("location: ../../index.php?pfad=createArticle");
|
header("location: ../../index.php?pfad=updateArticle");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!articleTitleValidator($title)) {
|
if (!articleTitleValidator($title)) {
|
||||||
$_SESSION["message"] = "invalid_title";
|
$_SESSION["message"] = "invalid_title";
|
||||||
header("location: ../../index.php?pfad=createArticle");
|
header("location: ../../index.php?pfad=updateArticle");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!articleContentValidator($content)) {
|
if (!articleContentValidator($content)) {
|
||||||
$_SESSION["message"] = "invalid_content";
|
$_SESSION["message"] = "invalid_content";
|
||||||
header("location: ../../index.php?pfad=createArticle");
|
header("location: ../../index.php?pfad=updateArticle");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!articleCategoryValidator($category)) {
|
if (!articleCategoryValidator($category)) {
|
||||||
$_SESSION["message"] = "invalid_category";
|
$_SESSION["message"] = "invalid_category";
|
||||||
header("location: ../../index.php?pfad=createArticle");
|
header("location: ../../index.php?pfad=updateArticle");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!articleTagValidator($_POST["tags"])) {
|
if (!articleTagValidator($tags)) {
|
||||||
$_SESSION["message"] = "invalid_tags";
|
$_SESSION["message"] = "invalid_tags";
|
||||||
header("location: ../../index.php?pfad=createArticle");
|
header("location: ../../index.php?pfad=updateArticle");
|
||||||
exit();
|
exit();
|
||||||
} else {
|
} else {
|
||||||
$cleanedTags = [];
|
$cleanedTags = [];
|
||||||
@@ -65,10 +69,11 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
foreach ($rawTags as $rawTag) {
|
foreach ($rawTags as $rawTag) {
|
||||||
// Leerzeichen am Anfang/Ende des einzelnen Tags entfernen:
|
// Leerzeichen am Anfang/Ende des einzelnen Tags entfernen:
|
||||||
$tag = trim($rawTag);
|
$tag = trim($rawTag);
|
||||||
// Duplikate entfernen:
|
$cleanedTags[] = $tag;
|
||||||
$cleanedTags = array_unique($cleanedTags);
|
|
||||||
$cleanedTags = implode(',', $cleanedTags);
|
|
||||||
}
|
}
|
||||||
|
// Duplikate entfernen:
|
||||||
|
$cleanedTags = array_unique($cleanedTags);
|
||||||
|
$cleanedTags = implode(',', $cleanedTags);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------- Übertragung der validierten Daten in ArticleManager: ---------------------------
|
// ----------------- Übertragung der validierten Daten in ArticleManager: ---------------------------
|
||||||
@@ -82,7 +87,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
$articleManager->updateArticle($id ,$article, $author);
|
$articleManager->updateArticle($id ,$article, $author);
|
||||||
} catch (Exception $e){
|
} catch (Exception $e){
|
||||||
$_SESSION["message"] = "internal_error";
|
$_SESSION["message"] = "internal_error";
|
||||||
header("location: ../../index.php?pfad=createArticle");
|
header("location: ../../index.php?pfad=updateArticle");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
$_SESSION["message"] = "article_updated";
|
$_SESSION["message"] = "article_updated";
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
* Prüft, ob der Autor auch der Eigentümer des Beitrags ist.
|
* Prüft, ob der Autor auch der Eigentümer des Beitrags ist.
|
||||||
* @param $author
|
* @param $author
|
||||||
* @return true
|
* @return true
|
||||||
|
* TODO: Implement this.
|
||||||
*/
|
*/
|
||||||
function articleAuthorValidator($author)
|
function articleAuthorValidator($author)
|
||||||
{
|
{
|
||||||
@@ -21,6 +22,7 @@ function articleAuthorValidator($author)
|
|||||||
*/
|
*/
|
||||||
function articleTitleValidator($title)
|
function articleTitleValidator($title)
|
||||||
{
|
{
|
||||||
|
$title = trim($title);
|
||||||
$titlePattern = '/^[a-zA-Z0-9äöüÄÖÜß\s.,!?:;()\'"„“«»_+-]{5,120}$/u';
|
$titlePattern = '/^[a-zA-Z0-9äöüÄÖÜß\s.,!?:;()\'"„“«»_+-]{5,120}$/u';
|
||||||
if (preg_match($titlePattern, $title)) {
|
if (preg_match($titlePattern, $title)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -36,8 +38,9 @@ function articleTitleValidator($title)
|
|||||||
*/
|
*/
|
||||||
function articleContentValidator($content)
|
function articleContentValidator($content)
|
||||||
{
|
{
|
||||||
|
$content = trim($content);
|
||||||
$zeichenAnzahl = mb_strlen($content);
|
$zeichenAnzahl = mb_strlen($content);
|
||||||
if ($zeichenAnzahl <= 7000 && $zeichenAnzahl > 10) {
|
if ($zeichenAnzahl <= 7000 && $zeichenAnzahl >= 10) {
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user