diff --git a/plugins/Signatures/class.signatures.plugin.php b/plugins/Signatures/class.signatures.plugin.php index bf1ebd7bf..5006e795e 100644 --- a/plugins/Signatures/class.signatures.plugin.php +++ b/plugins/Signatures/class.signatures.plugin.php @@ -22,6 +22,8 @@ * @package Addons */ +use \Vanilla\Formatting\FormatService; + class SignaturesPlugin extends Gdn_Plugin { const Unlimited = 'Unlimited'; @@ -31,9 +33,20 @@ class SignaturesPlugin extends Gdn_Plugin { /** @var bool */ public $Disabled = false; + /** @var FormatService */ + private $formatService; + /** @var array List of config settings can be overridden by sessions in other plugins */ private $overriddenConfigSettings = ['MaxNumberImages', 'MaxLength']; + /** + * SignaturesPlugin constructor. + * @param FormatService $formatService + */ + public function __construct(FormatService $formatService) { + parent::__construct(); + $this->formatService = $formatService; + } /** * Add mapper methods @@ -246,14 +259,12 @@ public function checkSignatureLength($fields, &$sender) { $maxLength = self::getMaximumTextLength(); if ($maxLength !== null && $maxLength > 0) { $maxLength = intval($maxLength); - $format = config('Plugin.Signatures.Format', Gdn_Format::defaultFormat()); + $format = isset($fields['Format']) ? $fields['Format'] : Gdn_Format::defaultFormat(); $body = val('Plugin.Signatures.Sig', $fields, ''); - $formatted = Gdn_Format::to($body, $format); - $plainText = trim(Gdn_format::text($formatted)); + $plainTextLength = $this->formatService->getPlainTextLength($body, $format); - // Validate the amount of text. - $length = strlen($plainText); - $difference = $length - $maxLength; + // Validate the amount of text + $difference = $plainTextLength - $maxLength; if ($difference > 0) { $sender->Form->addError(sprintf( t('ValidateLength'),