mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-04-01 01:25:39 +00:00
add required fields configuration, draft post request processing #14
This commit is contained in:
parent
762d72e913
commit
d8f6b6d27e
4 changed files with 319 additions and 1 deletions
|
|
@ -14,6 +14,11 @@ class AppModelValidator
|
|||
// Page
|
||||
|
||||
/// Page title
|
||||
public function getPageTitleRequired() : bool
|
||||
{
|
||||
return $this->_config->page->title->required;
|
||||
}
|
||||
|
||||
public function getPageTitleLengthMin() : int
|
||||
{
|
||||
return $this->_config->page->title->length->min;
|
||||
|
|
@ -29,7 +34,65 @@ class AppModelValidator
|
|||
return $this->_config->page->title->regex;
|
||||
}
|
||||
|
||||
public function pageTitle(mixed $value, array &$error = []) : bool
|
||||
{
|
||||
if (!is_string($value))
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
_('Invalid page title data type')
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($value) && $this->getPageTitleRequired())
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
_('Page title required')
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!preg_match($this->getPageTitleRegex(), $value))
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
sprintf(
|
||||
_('Page title format does not match condition "%s"'),
|
||||
$this->getPageTitleRegex()
|
||||
)
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mb_strlen($value) < $this->getPageTitleLengthMin() ||
|
||||
mb_strlen($value) > $this->getPageTitleLengthMax())
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
sprintf(
|
||||
_('Page title out of %s-%s chars range'),
|
||||
$this->getPageTitleLengthMin(),
|
||||
$this->getPageTitleLengthMax()
|
||||
)
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Page description
|
||||
public function getPageDescriptionRequired() : bool
|
||||
{
|
||||
return $this->_config->page->description->required;
|
||||
}
|
||||
|
||||
public function getPageDescriptionLengthMin() : int
|
||||
{
|
||||
return $this->_config->page->description->length->min;
|
||||
|
|
@ -45,7 +108,65 @@ class AppModelValidator
|
|||
return $this->_config->page->description->regex;
|
||||
}
|
||||
|
||||
public function pageDescription(mixed $value, array &$error = []) : bool
|
||||
{
|
||||
if (!is_string($value))
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
_('Invalid page description data type')
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($value) && $this->getPageDescriptionRequired())
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
_('Page description required')
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!preg_match($this->getPageDescriptionRegex(), $value))
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
sprintf(
|
||||
_('Page description format does not match condition "%s"'),
|
||||
$this->getPageDescriptionRegex()
|
||||
)
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mb_strlen($value) < $this->getPageDescriptionLengthMin() ||
|
||||
mb_strlen($value) > $this->getPageDescriptionLengthMax())
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
sprintf(
|
||||
_('Page description out of %s-%s chars range'),
|
||||
$this->getPageDescriptionLengthMin(),
|
||||
$this->getPageDescriptionLengthMax()
|
||||
)
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Page keywords
|
||||
public function getPageKeywordsRequired() : bool
|
||||
{
|
||||
return $this->_config->page->keywords->required;
|
||||
}
|
||||
|
||||
public function getPageKeywordsLengthMin() : int
|
||||
{
|
||||
return $this->_config->page->keywords->length->min;
|
||||
|
|
@ -71,6 +192,141 @@ class AppModelValidator
|
|||
return $this->_config->page->keywords->regex;
|
||||
}
|
||||
|
||||
public function pageKeywords(mixed $value, array &$error = []) : bool
|
||||
{
|
||||
if (!is_array($value))
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
_('Invalid page keywords data type')
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($value) && $this->getPageKeywordsRequired())
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
_('Page keywords required')
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
|
||||
foreach ($value as $keywords)
|
||||
{
|
||||
if (!is_string($kt))
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
_('Invalid magnet keyword value data type')
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!preg_match(MAGNET_KT_REGEX, $kt))
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
sprintf(
|
||||
_('Magnet keyword format does not match condition "%s"'),
|
||||
MAGNET_KT_REGEX
|
||||
)
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mb_strlen($kt) < MAGNET_KT_MIN_LENGTH ||
|
||||
mb_strlen($kt) > MAGNET_KT_MAX_LENGTH)
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
sprintf(
|
||||
_('Magnet keyword out of %s-%s chars range'),
|
||||
MAGNET_KT_MIN_LENGTH,
|
||||
MAGNET_KT_MAX_LENGTH
|
||||
)
|
||||
);
|
||||
|
||||
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 false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function pageKeyword(mixed $value, array &$error = []) : bool
|
||||
{
|
||||
if (!is_string($value))
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
_('Invalid page keyword data type')
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!preg_match($this->getPageKeywordsRegex(), $value))
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
sprintf(
|
||||
_('Page keyword "%s" format does not match condition "%s"'),
|
||||
$value,
|
||||
$this->getPageKeywordsRegex()
|
||||
)
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mb_strlen($value) < $this->getPageDescriptionLengthMin() ||
|
||||
mb_strlen($value) > $this->getPageDescriptionLengthMax())
|
||||
{
|
||||
array_push(
|
||||
$error,
|
||||
sprintf(
|
||||
_('Page description out of %s-%s chars range'),
|
||||
$this->getPageDescriptionLengthMin(),
|
||||
$this->getPageDescriptionLengthMax()
|
||||
)
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Page torrent
|
||||
public function getPageTorrentRequired() : bool
|
||||
{
|
||||
return $this->_config->page->torrent->required;
|
||||
}
|
||||
|
||||
// Common
|
||||
public function host(mixed $value, array &$error = []) : bool
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue