108 lines
2.4 KiB
PHP
108 lines
2.4 KiB
PHP
<?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;
|
|
}
|
|
|
|
?>
|