From 1bfe0df4602df63acce3ef5c2e64dec2d968af69 Mon Sep 17 00:00:00 2001 From: sk8rdude461 Date: Thu, 28 May 2015 14:02:20 -0600 Subject: [PATCH] Removes BBCode from being calculated in signatures. Stops bbcode from being calculated into the total for signatures. Also adjusts the character limit in the text area from N, to N + BBC length. Tested on my website. --- Sources/Profile-Modify.php | 2 +- Themes/default/Profile.template.php | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Sources/Profile-Modify.php b/Sources/Profile-Modify.php index 565d230..c43ceb9 100644 --- a/Sources/Profile-Modify.php +++ b/Sources/Profile-Modify.php @@ -2892,7 +2892,7 @@ function profileValidateSignature(&$value) $unparsed_signature = strtr(un_htmlspecialchars($value), array("\r" => '', ''' => '\'')); // Too long? - if (!empty($sig_limits[1]) && $smcFunc['strlen']($unparsed_signature) > $sig_limits[1]) + if (!empty($sig_limits[1]) && (!empty($sig_bbc) ? ($smcFunc['strlen']($unparsed_signature) - $smcFunc['strlen']($sig_bbc)) : $smcFunc['strlen']($unparsed_signature)) > $sig_limits[1]) { $_POST['signature'] = trim(htmlspecialchars($smcFunc['substr']($unparsed_signature, 0, $sig_limits[1]), ENT_QUOTES)); $txt['profile_error_signature_max_length'] = sprintf($txt['profile_error_signature_max_length'], $sig_limits[1]); diff --git a/Themes/default/Profile.template.php b/Themes/default/Profile.template.php index a0fe876..1263911 100644 --- a/Themes/default/Profile.template.php +++ b/Themes/default/Profile.template.php @@ -2549,6 +2549,11 @@ function template_profile_signature_modify() setTimeout("tick()", 800); } + function parseBaby(text) { + var babyless = new RegExp(/\[(\w+)[^w]*?](.*?)\[\/\1]/g); + return text.replace(babyless, "$2"); + } + function calcCharLeft() { var maxLength = ', $context['signature_limits']['max_length'], '; @@ -2561,12 +2566,15 @@ function template_profile_signature_modify() { oldSignature = currentSignature; - if (currentSignature.replace(/\r/, "").length > maxLength) - document.forms.creator.signature.value = currentSignature.replace(/\r/, "").substring(0, maxLength); + if (parseBaby(currentSignature.replace(/\r/, "")).length > maxLength) { + var diff = currentSignature.replace(/\r/, "").length - parseBaby(currentSignature.replace(/\r/, "")).length; + document.forms.creator.signature.value = currentSignature.replace(/\r/, "").substring(0, maxLength+diff); + } currentSignature = document.forms.creator.signature.value.replace(/\r/, ""); } - - setInnerHTML(document.getElementById("signatureLeft"), maxLength - currentSignature.length); + var size = parseBaby(currentSignature).length; + console.log(size); + setInnerHTML(document.getElementById("signatureLeft"), maxLength - size); } addLoadEvent(tick);