diff --git a/src/app/controller/submit.php b/src/app/controller/submit.php index d72840a..844e49c 100644 --- a/src/app/controller/submit.php +++ b/src/app/controller/submit.php @@ -97,14 +97,12 @@ class AppControllerSubmit [ 'value' => null, 'required' => $this->_validator->getPageKeywordsRequired(), - 'minlength' => $this->_validator->getPageKeywordsLengthMin(), - 'maxlength' => $this->_validator->getPageKeywordsLengthMax(), 'placeholder' => sprintf( _('Page keywords (%s-%s total / %s-%s chars per item)'), number_format($this->_validator->getPageKeywordsQuantityMin()), number_format($this->_validator->getPageKeywordsQuantityMax()), - number_format($this->_validator->getPageKeywordsLengthMin()), - number_format($this->_validator->getPageKeywordsLengthMax()) + number_format($this->_validator->getPageKeywordLengthMin()), + number_format($this->_validator->getPageKeywordLengthMax()) ), ] ], @@ -115,6 +113,7 @@ class AppControllerSubmit [ 'value' => null, 'required' => $this->_validator->getPageTorrentRequired(), + 'accept' => implode(',', $this->_validator->getPageTorrentMimeTypes()), 'placeholder' => sprintf( _('Torrent file (use Ctrl to select multiple files)') ), @@ -134,9 +133,9 @@ class AppControllerSubmit { $error = []; - if ($this->_validator->pageTitle($_POST['title'], $error)) + if (!$this->_validator->pageTitle($_POST['title'], $error)) { - $form->title->error = $error; + $form->title->error[] = $error; } // @TODO check for page duplicates @@ -148,9 +147,9 @@ class AppControllerSubmit { $error = []; - if ($this->_validator->pageDescription($_POST['description'], $error)) + if (!$this->_validator->pageDescription($_POST['description'], $error)) { - $form->description->error = $error; + $form->description->error[] = $error; } $form->description->attribute->value = htmlentities($_POST['description']); @@ -160,14 +159,21 @@ class AppControllerSubmit { $error = []; - if ($this->_validator->pageKeywords($_POST['keywords'], $error)) + if (!$this->_validator->pageKeywords($_POST['keywords'], $error)) { - $form->keywords->error = $error; + $form->keywords->error[] = $error; } $form->keywords->attribute->value = htmlentities($_POST['keywords']); } + if (isset($_FILES['torrent'])) + { + $error = []; + + // @TODO + } + // Request valid if (empty($error)) { diff --git a/src/app/model/validator.php b/src/app/model/validator.php index 8b3da69..5f98697 100644 --- a/src/app/model/validator.php +++ b/src/app/model/validator.php @@ -167,16 +167,6 @@ class AppModelValidator return $this->_config->page->keywords->required; } - public function getPageKeywordsLengthMin() : int - { - return $this->_config->page->keywords->length->min; - } - - public function getPageKeywordsLengthMax() : int - { - return $this->_config->page->keywords->length->max; - } - public function getPageKeywordsQuantityMin() : int { return $this->_config->page->keywords->quantity->min; @@ -187,14 +177,9 @@ class AppModelValidator return $this->_config->page->keywords->quantity->max; } - public function getPageKeywordsRegex() : string - { - return $this->_config->page->keywords->regex; - } - public function pageKeywords(mixed $value, array &$error = []) : bool { - if (!is_array($value)) + if (!is_string($value)) { array_push( $error, @@ -214,67 +199,60 @@ class AppModelValidator return false; } - $total = 0; - - foreach ($value as $keywords) + if ($this->getPageKeywordsRequired()) { - if (!is_string($kt)) + $total = 0; + + foreach (explode(PHP_EOL, str_replace(['#', ',', ' '], PHP_EOL, $value)) as $keyword) { - array_push( - $error, - _('Invalid magnet keyword value data type') - ); + $error = []; - return false; - } + if (!$this->pageKeyword($keyword, $error)) + { + array_push( + $error, + _('Invalid page keyword'), + ); - if (!preg_match(MAGNET_KT_REGEX, $kt)) - { - array_push( - $error, - sprintf( - _('Magnet keyword format does not match condition "%s"'), - MAGNET_KT_REGEX - ) - ); + return false; + } - return false; + $total++; } - if (mb_strlen($kt) < MAGNET_KT_MIN_LENGTH || - mb_strlen($kt) > MAGNET_KT_MAX_LENGTH) + if ($total < $this->getPageKeywordsQuantityMin() || + $total > $this->getPageKeywordsQuantityMax()) { array_push( $error, sprintf( - _('Magnet keyword out of %s-%s chars range'), - MAGNET_KT_MIN_LENGTH, - MAGNET_KT_MAX_LENGTH + _('Page keywords quantity out of %s-%s range'), + $this->getPageKeywordsQuantityMin(), + $this->getPageKeywordsQuantityMax() ) ); return false; } - - $total++; } - if ($total < MAGNET_KT_MIN_QUANTITY || - $total > MAGNET_KT_MAX_QUANTITY) - { - array_push( - $error, - sprintf( - _('Magnet keywords quantity out of %s-%s range'), - MAGNET_KT_MIN_QUANTITY, - MAGNET_KT_MAX_QUANTITY - ) - ); + return true; + } - return false; - } + /// Page keyword + public function getPageKeywordLengthMin() : int + { + return $this->_config->page->keyword->length->min; + } - return true; + public function getPageKeywordLengthMax() : int + { + return $this->_config->page->keyword->length->max; + } + + public function getPageKeywordRegex() : string + { + return $this->_config->page->keyword->regex; } public function pageKeyword(mixed $value, array &$error = []) : bool @@ -289,29 +267,28 @@ class AppModelValidator return false; } - if (!preg_match($this->getPageKeywordsRegex(), $value)) + if (!preg_match($this->getPageKeywordRegex(), $value)) { array_push( $error, sprintf( - _('Page keyword "%s" format does not match condition "%s"'), - $value, - $this->getPageKeywordsRegex() + _('Page keyword format does not match condition "%s"'), + $this->getPageKeywordRegex() ) ); return false; } - if (mb_strlen($value) < $this->getPageDescriptionLengthMin() || - mb_strlen($value) > $this->getPageDescriptionLengthMax()) + if (mb_strlen($value) < $this->getPageKeywordLengthMin() || + mb_strlen($value) > $this->getPageKeywordLengthMax()) { array_push( $error, sprintf( - _('Page description out of %s-%s chars range'), - $this->getPageDescriptionLengthMin(), - $this->getPageDescriptionLengthMax() + _('Page keyword out of %s-%s chars range'), + $this->getPageKeywordLengthMin(), + $this->getPageKeywordLengthMax() ) ); @@ -327,6 +304,11 @@ class AppModelValidator return $this->_config->page->torrent->required; } + public function getPageTorrentMimeTypes() : array + { + return $this->_config->page->torrent->mime; + } + // Common public function host(mixed $value, array &$error = []) : bool { diff --git a/src/app/view/theme/default/submit.phtml b/src/app/view/theme/default/submit.phtml index 6a16a49..69ab176 100644 --- a/src/app/view/theme/default/submit.phtml +++ b/src/app/view/theme/default/submit.phtml @@ -12,7 +12,7 @@

-
+