NoURL.php 1004 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\Validators;
  10. use ForkBB\Core\RulesValidator;
  11. use ForkBB\Core\Validator;
  12. class NoURL extends RulesValidator
  13. {
  14. /**
  15. * Проверяет значение на отсутствие ссылки,
  16. * если пользователю запрещено использовать ссылки или включен флаг принудительной проверки
  17. */
  18. public function noURL(Validator $v, string $value, string $flag): string
  19. {
  20. if (
  21. (
  22. ! empty($flag)
  23. || 1 !== $this->c->user->g_post_links
  24. )
  25. && \preg_match('%\b://|\bwww\.%i', $value)
  26. ) {
  27. $v->addError('The :alias contains a link');
  28. }
  29. return $value;
  30. }
  31. }