misuzu/src/Forum/validate.php

34 lines
717 B
PHP
Raw Normal View History

2018-05-23 03:41:57 +02:00
<?php
define('MSZ_TOPIC_TITLE_LENGTH_MIN', 3);
2018-05-23 03:41:57 +02:00
define('MSZ_TOPIC_TITLE_LENGTH_MAX', 100);
define('MSZ_POST_TEXT_LENGTH_MIN', 1);
2018-05-23 03:41:57 +02:00
define('MSZ_POST_TEXT_LENGTH_MAX', 60000);
2019-06-10 19:04:53 +02:00
function forum_validate_title(string $title): string {
$length = mb_strlen(trim($title));
2018-05-23 03:41:57 +02:00
2019-06-10 19:04:53 +02:00
if($length < MSZ_TOPIC_TITLE_LENGTH_MIN) {
2018-05-23 03:41:57 +02:00
return 'too-short';
}
2019-06-10 19:04:53 +02:00
if($length > MSZ_TOPIC_TITLE_LENGTH_MAX) {
2018-05-23 03:41:57 +02:00
return 'too-long';
}
return '';
}
2019-06-10 19:04:53 +02:00
function forum_validate_post(string $text): string {
$length = mb_strlen(trim($text));
2018-05-23 03:41:57 +02:00
2019-06-10 19:04:53 +02:00
if($length < MSZ_POST_TEXT_LENGTH_MIN) {
2018-05-23 03:41:57 +02:00
return 'too-short';
}
2019-06-10 19:04:53 +02:00
if($length > MSZ_POST_TEXT_LENGTH_MAX) {
2018-05-23 03:41:57 +02:00
return 'too-long';
}
return '';
}