[XenMax] - Minimum Message Length

[XenMax] - Minimum Message Length 2.0.0

No permission to download
Thanks a lot for the greate add-on you post her for free :love:

I have noted one thing in this add-on, when the input is zero "0" the add-on dosen't catch the count and the min-limit is baypassed. In other word if I set titles min lenght to 5 and I create a new thread and the title input set to "0" and click post it doesn't give an error to tell you need 5 chars fot title.


Thanks ;)
 
Thanks a lot for the greate add-on you post her for free :love:

I have noted one thing in this add-on, when the input is zero "0" the add-on dosen't catch the count and the min-limit is baypassed. In other word if I set titles min lenght to 5 and I create a new thread and the title input set to "0" and click post it doesn't give an error to tell you need 5 chars fot title.


Thanks ;)
thank you. i will update it soon
 
One more thing, in Service/Thread/Editor.php Why the $thread = null, you should remove the null otherwise when editing the 1st post the title chars lengh will not be pass trough the cheking code.
 
Users can easily bypass this by quoting replies, could you please add the ability to disable this from happening?
 
@Paul R Heya Paul, took a look at this add-on. The checkboxes for turning the options on/off don't actually appear to work.

There's also a number of typos and weird grammar I'd be happy to help fix.
 
Users can easily bypass this by quoting replies, could you please add the ability to disable this from happening?
Do you have any update? Also add option disable Quoted only reply and smile only reply. As well exclude smileys to count towards minimum characters.
Credit to original author of this add on.

Modification :
  • ignore quote.
  • ignore some bb codes.
  • ignore multiple adjacent spaces.
  • ignore new lines / spaces at start / end of message.
You can replace this file /src/addons/XenMax/MessageLength/Repository/MessageLength.php
with this code :
PHP:
<?php

/*************************************************************************
 * @Filename:MessageLength.php
 * @Author: XenMax
 * @HomePage: http://XenfoMax.com
 * @Email: service@xenfomax.com
 * @Date:   2017-12-16 17:24:20
 * @Last Modified by:   XenMax
 * @Last Modified time: 2017-12-16 18:45:33
 * XenMax All Rights Reserved.
 **************************************************************************
 * This file is subject to the terms and conditions defined in the Licence
 * Agreement available at Try it like it buy it :)
 *************************************************************************/
namespace XenMax\MessageLength\Repository;
use XF\Mvc\Entity\Finder;
use XF\Mvc\Entity\Repository;
use XF\PrintableException;

class MessageLength extends Repository
{

    public function check_count($message, $thread, $forumId, &$errorString)
    {
        //Get options config
        $options = $this->app()->options();
        //get curent visitor
        $visitor = \XF::visitor();

        // Message stripping START
        $stripped_message = trim($message);// trim the message
        $stripped_message = str_replace(array("\n", "\r", "\t"), '', $stripped_message);// remove new lines
        $stripped_message = preg_replace('/([ ]+)/', ' ', $stripped_message);// remove duplicate spaces
        $stripped_message = trim($stripped_message);// trim it once more
        if (stripos($message, '[quote') !== false) {// if contains quote
            $stripped_message = preg_replace('/\[quote(.*)\[\/quote\]/iU', '', $stripped_message);// remove quotes
            $stripped_message = trim($stripped_message);// trim it once more
        }
        if (stripos($message, '[spoiler') !== false) {// if contains spoiler
            $stripped_message = preg_replace('/\[spoiler(.*)\]/iU', '', $stripped_message);// remove spoiler
            $stripped_message = trim($stripped_message);// trim it once more
        }
        if (stripos($message, '[size') !== false) {// if contains size
            $stripped_message = preg_replace('/\[size(.*)\]/iU', '', $stripped_message);// remove size
            $stripped_message = trim($stripped_message);// trim it once more
        }
        if (stripos($message, '[color') !== false) {// if contains color
            $stripped_message = preg_replace('/\[color(.*)\]/iU', '', $stripped_message);// remove color
            $stripped_message = trim($stripped_message);// trim it once more
        }
        if (stripos($message, '[font') !== false) {// if contains font
            $stripped_message = preg_replace('/\[font(.*)\]/iU', '', $stripped_message);// remove font
            $stripped_message = trim($stripped_message);// trim it once more
        }
        $stripped_message = str_ireplace(array(
            '[ispoiler]',
            '[/ispoiler]',
            '[b]',
            '[/b]',
            '[i]',
            '[/i]',
            '[u]',
            '[/u]',
            '[s]',
            '[/s]',
            '[right]',
            '[/right]',
            '[center]',
            '[/center]',
            '[/quote]',
            '[/spoiler]',
            '[/size]',
            '[/color]',
            '[/font]',
        ), '', $stripped_message);// remove useless bb code
        $stripped_message = trim($stripped_message);// trim it once more
        // Message stripping END

        $CharCount = mb_strlen($stripped_message);// Message stripping modification
        $WordCount = str_word_count($stripped_message);// Message stripping modification

        if($thread){
            $TitleCount = mb_strlen($thread->title);
        }
        $minimumchar = $options->XenMax_mincharl;
        $minimumwords = $options->XenMax_minwordl;
        $minititle = $options->XenMax_mintitle;
        $maxtitle = $options->XenMax_maxtitle;

        if($thread){
            //Enable the mod and set up the min title limit in posts
            if(!empty($minititle))
            {
               if($TitleCount < $minititle AND !$visitor->hasPermission('forum', 'XenMax_bypass_char_words'))
               {
                    $errorString = \XF::phrase('xenmax_min_title_x_x', [
                        'min' => $minititle,
                        'max' => $maxtitle,
                        'curent' => $TitleCount,
                        'username' => $visitor['username'],
                    ]);
                    return false;
               }
            }
            //Enable the mod and set up the minword limit in posts
            if(!empty($maxtitle))
            {
               if($TitleCount > $maxtitle AND !$visitor->hasPermission('forum', 'XenMax_bypass_char_words'))
               {
                    $errorString = \XF::phrase('xenmax_max_title_x_x', [
                        'max' => $maxtitle,
                        'min' => $minititle,
                        'curent' => $TitleCount,
                        'username' => $visitor['username'],
                    ]);
                    return false;
               }
            }
        }

        if(!empty($minimumchar))
        {
           if($CharCount < $minimumchar AND !$visitor->hasPermission('forum', 'XenMax_bypass_char_words'))
           {
                   $errorString = \XF::phrase('xenmax_min_char_x_x', [
                    'min' => $minimumchar,
                    'curent' => $CharCount,
                    'username' => $visitor['username'],
                ]);
                return false;
           }
        }

        //Enable the mod and set up the minword limit in posts
        if(!empty($minimumwords))
        {
           if($WordCount < $minimumwords AND !$visitor->hasPermission('forum', 'XenMax_bypass_char_words'))
           {
                   $errorString = \XF::phrase('xenmax_min_word_x_x', [
                    'min' => $minimumwords,
                    'curent' => $WordCount,
                    'username' => $visitor['username'],
                ]);
                 return false;
           }
        }
        return true;
    }


}
 
Last edited:
Credit to original author of this add on.

Modification :
  • ignore quote.
  • ignore some bb codes.
  • ignore multiple adjacent spaces.
  • ignore new lines / spaces at start / end of message.
You can replace this file /src/addons/XenMax/MessageLength/Repository/MessageLength.php
with this code :
PHP:
<?php

/*************************************************************************
* @Filename:MessageLength.php
* @Author: XenMax
* @HomePage: http://XenfoMax.com
* @Email: service@xenfomax.com
* @Date:   2017-12-16 17:24:20
* @Last Modified by:   XenMax
* @Last Modified time: 2017-12-16 18:45:33
* XenMax All Rights Reserved.
**************************************************************************
* This file is subject to the terms and conditions defined in the Licence
* Agreement available at Try it like it buy it :)
*************************************************************************/
namespace XenMax\MessageLength\Repository;
use XF\Mvc\Entity\Finder;
use XF\Mvc\Entity\Repository;
use XF\PrintableException;

class MessageLength extends Repository
{

    public function check_count($message, $thread, $forumId, &$errorString)
    {
        //Get options config
        $options = $this->app()->options();
        //get curent visitor
        $visitor = \XF::visitor();

        // Message stripping START
        $stripped_message = trim($message);// trim the message
        $stripped_message = str_replace(array("\n", "\r", "\t"), '', $stripped_message);// remove new lines
        $stripped_message = preg_replace('/([ ]+)/', ' ', $stripped_message);// remove duplicate spaces
        $stripped_message = trim($stripped_message);// trim it once more
        if (stripos($message, '[quote') !== false) {// if contains quote
            $stripped_message = preg_replace('/\[quote(.*)\[\/quote\]/iU', '', $stripped_message);// remove quotes
            $stripped_message = trim($stripped_message);// trim it once more
        }
        if (stripos($message, '[spoiler') !== false) {// if contains spoiler
            $stripped_message = preg_replace('/\[spoiler(.*)\]/iU', '', $stripped_message);// remove spoiler
            $stripped_message = trim($stripped_message);// trim it once more
        }
        if (stripos($message, '[size') !== false) {// if contains size
            $stripped_message = preg_replace('/\[size(.*)\]/iU', '', $stripped_message);// remove size
            $stripped_message = trim($stripped_message);// trim it once more
        }
        if (stripos($message, '[color') !== false) {// if contains color
            $stripped_message = preg_replace('/\[color(.*)\]/iU', '', $stripped_message);// remove color
            $stripped_message = trim($stripped_message);// trim it once more
        }
        if (stripos($message, '[font') !== false) {// if contains font
            $stripped_message = preg_replace('/\[font(.*)\]/iU', '', $stripped_message);// remove font
            $stripped_message = trim($stripped_message);// trim it once more
        }
        $stripped_message = str_ireplace(array(
            '[ispoiler]',
            '[/ispoiler]',
            '[b]',
            '[/b]',
            '[i]',
            '[/i]',
            '[u]',
            '[/u]',
            '[s]',
            '[/s]',
            '[right]',
            '[/right]',
            '[center]',
            '[/center]',
            '[/quote]',
            '[/spoiler]',
            '[/size]',
            '[/color]',
            '[/font]',
        ), '', $stripped_message);// remove useless bb code
        $stripped_message = trim($stripped_message);// trim it once more
        // Message stripping END

        $CharCount = mb_strlen($stripped_message);// Message stripping modification
        $WordCount = str_word_count($stripped_message);// Message stripping modification

        if($thread){
            $TitleCount = mb_strlen($thread->title);
        }
        $minimumchar = $options->XenMax_mincharl;
        $minimumwords = $options->XenMax_minwordl;
        $minititle = $options->XenMax_mintitle;
        $maxtitle = $options->XenMax_maxtitle;

        if($thread){
            //Enable the mod and set up the min title limit in posts
            if(!empty($minititle))
            {
               if($TitleCount < $minititle AND !$visitor->hasPermission('forum', 'XenMax_bypass_char_words'))
               {
                    $errorString = \XF::phrase('xenmax_min_title_x_x', [
                        'min' => $minititle,
                        'max' => $maxtitle,
                        'curent' => $TitleCount,
                        'username' => $visitor['username'],
                    ]);
                    return false;
               }
            }
            //Enable the mod and set up the minword limit in posts
            if(!empty($maxtitle))
            {
               if($TitleCount > $maxtitle AND !$visitor->hasPermission('forum', 'XenMax_bypass_char_words'))
               {
                    $errorString = \XF::phrase('xenmax_max_title_x_x', [
                        'max' => $maxtitle,
                        'min' => $minititle,
                        'curent' => $TitleCount,
                        'username' => $visitor['username'],
                    ]);
                    return false;
               }
            }
        }

        if(!empty($minimumchar))
        {
           if($CharCount < $minimumchar AND !$visitor->hasPermission('forum', 'XenMax_bypass_char_words'))
           {
                   $errorString = \XF::phrase('xenmax_min_char_x_x', [
                    'min' => $minimumchar,
                    'curent' => $CharCount,
                    'username' => $visitor['username'],
                ]);
                return false;
           }
        }

        //Enable the mod and set up the minword limit in posts
        if(!empty($minimumwords))
        {
           if($WordCount < $minimumwords AND !$visitor->hasPermission('forum', 'XenMax_bypass_char_words'))
           {
                   $errorString = \XF::phrase('xenmax_min_word_x_x', [
                    'min' => $minimumwords,
                    'curent' => $WordCount,
                    'username' => $visitor['username'],
                ]);
                 return false;
           }
        }
        return true;
    }


}
Anyone got any idea why this plugin incorrectly flags up a short message sometimes when a mod trys to close a thread?
 
Top Bottom