<?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;
}
}