Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions plugins/Signatures/class.signatures.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @package Addons
*/

use \Vanilla\Formatting\FormatService;

class SignaturesPlugin extends Gdn_Plugin {

const Unlimited = 'Unlimited';
Expand All @@ -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
Expand Down Expand Up @@ -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'),
Expand Down