Прикрутил к сайту форум Kunena, но не могу найти к нему толковый антимат. Нашел плагин, но в нем фильтрация по списку слов, а это не кошерно. Нарыл еще класс на основе регулярных выражений, но вставить его в плагин у меня знаний не хватает. Может кто поможет?
Вот код плагина:
Свернутый текст
<?php
defined( '_JEXEC') or ( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
$mainframe->registerEvent( 'onAfterRoute', 'plgSystemForumProtectionLight' );
$mainframe->registerEvent( 'onAfterDispatch', 'onAfterDispatch' );
function plgSystemForumProtectionLight()
{
global $mainframe;
// get plugin info
$plugin =& JPluginHelper::getPlugin('system', 'forum_protection_light');
$params = new JParameter($plugin->params);
$usecontact = intval($params->get('usecontact', 0));
$texterror = $params->get('errortxt1');
$texterror .= '<br />';
$texterror .= $params->get('errortxt2');
$debug = intval($params->get('debug'));
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
$itemid = JRequest::getCmd('Itemid');
$task = JRequest::getCmd('task');
$fact = & JFactory::getApplication();
if ($option == 'com_kunena')
{
$action = JRequest::getVar('action', '', 'POST');
$catid = JRequest::getCmd('catid');
$excats = explode(',', str_replace(' ', '', $params->get('excat')));
if ($action == 'post' || $action == 'edit')
{
if (count($excats) > 0)
{
if (in_array($catid , $excats))
return;
}
$message = stripslashes($_POST['message']);
$subject = stripslashes($_POST['subject']);
$src = array('<', '>');
$rep = array('<', '>');
$message = str_replace($src, $rep, $message);
//$catid = JRequest::getCmd('catid');
$id = JRequest::getCmd('id');
if ($id > 0)
{
$func = 'post';
$do = 'reply';
}
else
{
$func = 'post';
$do = 'new';
}
$spam = checkspam($message, $subject, $params);
if ($spam['spam'])
{
if ($debug == 1)
$texterror .= '<br />'.$spam['error'];
JRequest::setVar('action','xx');
unset($_POST['acion'], $_GET['acion']);
JRequest::setVar('func',$func);
JRequest::setVar('do',$do);
JRequest::setVar('catid',$catid);
JRequest::setVar('id',$id);
$mainframe->enqueueMessage($texterror, 'error');
}
}
}
}
function checkspam($message, $subject, $params)
{
//vars
$spam['spam'] = false;
$spam['error'] = '';
$bcount = 0;
$hcount = 0;
$message = repspaces($message);
$subject = repspaces($subject);
$message_r = $_POST['message'];
$subject_r = $_POST['subject'];
//params
$usebadword = intval($params->get('usebadword', 1));
$maxbadword = intval($params->get('maxbadword', 0));
$badwords = explode(',', $params->get('badwords', 'sex,porn,bdsm,fuck,ass,casino,viagra,xxx'));
$bdaction = $params->get('bdaction', 0);
$bdreplace = $params->get('bdreplace', '-_-');
if ($usebadword == 1)
{
foreach ($badwords as $badword)
{
if (stripos($message, $badword) !== false )
{
if($bdaction)
{
$bcount++;
$bword .= $badword.',';
}
else
$message_r = str_ireplace($badword, $bdreplace , $message_r);
}
if (stripos($subject, $badword) !== false )
{
if($bdaction)
{
$bcount++;
$bword .= $badword.',';
}
else
$subject_r = str_ireplace($badword, $bdreplace , $subject_r);
}
}
if ($bcount > $maxbadword)
{
$spam['spam'] = true;
$spam['error'] .= 'Too many Bad Words. Detected: '.$bcount.', MaxAllowed: '.$maxbadword.' Found Words: '.$bword.'<br />';
}
if(!$bdaction)
{
$_POST['message'] = $message_r;
$_POST['subject'] = $subject_r;
}
}
return $spam;
}
function repspaces($string)
{
$string = str_ireplace(' ', ' ', $string);
$string = str_ireplace(' ', ' ', $string);
$pattern = "!\s+!";
$string = preg_replace($pattern, ' ', $string);
return $string;
}
function onAfterDispatch()
{
global $subject;
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
$do = JRequest::getCmd('do');
$id = JRequest::getCmd('id');
$pid = JRequest::getCmd('parentid');
$plugin =& JPluginHelper::getPlugin('system', 'forum_protection_light');
$params = new JParameter($plugin->params);
$keepfailnew = intval($params->get('keepfailnew', 0));
$bdaction = $params->get('bdaction', 0);
if( $option != 'com_kunena' )
return;
else if (($do == 'new' || $do == 'reply') && $keepfailnew == 1 && $bdaction)
{
$db =& JFactory::getDBO();
$query = 'SELECT * FROM #__kunena_config';
$db->setQuery($query);
$rows = $db->loadObject();
$maxsubj = $rows->maxsubject;
if( $id > 0)
{
$query = 'SELECT * FROM #__kunena_messages WHERE id = '.$id;
$db->setQuery($query);
$rows = $db->loadObject();
$subject = 'Re: '.str_ireplace('Re: ', '', $rows->subject);
}
if( $pid > 0)
{
$query = 'SELECT * FROM #__kunena_messages WHERE id = '.$pid;
$db->setQuery($query);
$rows = $db->loadObject();
$subject = 'Re: '.str_ireplace('Re: ', '', $rows->subject);
}
$document =& JFactory::getDocument();
$buffer = $document->getBuffer('component');
$str1 = '<input type="text" class="kinputbox postinput required" name="subject" id="subject" size="35"';
$str2 = 'maxlength="'.$maxsubj.'" value="'.$subject.'" />';
$strrrr = '<input type="text" class="kinputbox postinput required" name="subject" id="subject" size="35" maxlength="'.$maxsubj.'" value="'.$subject.'" />';
$buffer = str_replace($str2, '', $buffer);
$buffer = str_replace($str1, $strrrr, $buffer);
// seting values...
$inputsRe = "/<input(.*name=(['\"])(.+?)\\2.*)?>/i";
$inputsReLnk = "/<input(.*name=['\"].*.['\"].*)?>/i";
$textareaRe = "/<textarea(.*name=(['\"])(.+?)\\2.*)?>(.*)?<\/textarea>/i";
$buffer = preg_replace_callback($inputsRe, 'addInputValues', $buffer);
$buffer = preg_replace_callback($textareaRe, 'addTextareaValue', $buffer);
$document->setBuffer($buffer,'component');
}
else
{
return;
}
}
function addInputValues($matches)
{
global $replacementValue;
switch($matches[3]){
case 'subject':
$re = "/value=(['\"])(.*?)\\1/i";
$replacementValue = JRequest::getVar($matches[3]);
$matches[0] = preg_replace_callback($re, 'replaceValue', $matches[0]);
break;
}
return $matches[0];
}
function addTextareaValue($matches)
{
$attrs = $matches[1];
$val = JRequest::getVar('message');
return "<textarea$attrs>$val</textarea>";
}
function replaceValue($matches)
{
global $replacementValue, $subject;
if (strlen($replacementValue) < 1) $replacementValue = $subject;
$val = addslashes($replacementValue);
return "value=\"$val\"";
}
?>[/code]
а вот класс:
[code]<?
setlocale (LC_ALL, "ru_RU.CP1251");
/*<=====================Describing anti_mate class==============================>*/
class anti_mate {
//latin equivalents for russian letters
var $let_matches = array (
"a" => "а",
"c" => "с",
"e" => "е",
"k" => "к",
"m" => "м",
"o" => "о",
"x" => "х",
"y" => "у",
"ё" => "е"
);
//bad words array. Regexp's symbols are readable !
var $bad_words = array (".*ху(й|и|я|е|л(и|е)).*", ".*пи(з|с)д.*", "бля.*", ".*бля(д|т|ц).*", "(с|сц)ук(а|о|и).*", "еб.*", ".*уеб.*", "заеб.*", ".*еб(а|и)(н|с|щ|ц).*", ".*ебу(ч|щ).*", ".*пид(о|е)р.*", ".*хер.*", "г(а|о)ндон", ".*залуп.*");
function rand_replace (){
$output = " <font color=red>[censored]</font> ";
return $output;
}
function filter ($string){
$counter = 0;
$elems = explode (" ", $string); //here we explode string to words
$count_elems = count($elems);
for ($i=0; $i<$count_elems; $i++)
{
$blocked = 0;
/*formating word...*/
$str_rep = eregi_replace ("[^a-zA-Zа-яА-Яё]", "", strtolower($elems[$i]));
for ($j=0; $j<strlen($str_rep); $j++)
{
foreach ($this->let_matches as $key => $value)
{
if ($str_rep[$j] == $key)
$str_rep[$j] = $value;
}
}
/*done*/
/*here we are trying to find bad word*/
/*match in the special array*/
for ($k=0; $k<count($this->bad_words); $k++)
{
if (ereg("\*$", $this->bad_words[$k]))
{
if (ereg("^".$this->bad_words[$k], $str_rep))
{
$elems[$i] = $this->rand_replace();
$blocked = 1;
$counter++;
break;
}
}
if ($str_rep == $this->bad_words[$k]){
$elems[$i] = $this->rand_replace();
$blocked = 1;
$counter++;
break;
}
}
}
if ($counter != 0)
$string = implode (" ", $elems); //here we implode words in the whole string
return $string;
}
}
?>
Спустя 1 минута, 9 секунд (21.06.2012 - 14:54) vital написал(а):
Цитата |
Может кто поможет? |
50$
Спустя 18 минут, 25 секунд (21.06.2012 - 15:13) radeugen написал(а):
Цитата (vital @ 21.06.2012 - 11:54) |
50$ |
Ну и расценки у вас, товарищ.
По-моему, у вас завышена самооценка.
Спустя 40 минут, 23 секунды (21.06.2012 - 15:53) vital написал(а):
Цитата (radeugen @ 21.06.2012 - 14:13) | ||
Ну и расценки у вас, товарищ. По-моему, у вас завышена самооценка. |
По-моему у вас сильно раскатана губа.
Вы хотите что бы вам на халяву сделали кастомный модуль, еще и для не самого популярного форума.
Спустя 32 минуты, 28 секунд (21.06.2012 - 16:26) Kuliev написал(а):
По поводу антимата вроде была тема. Так вот если захотят написать матом ТО НАПИШУТ дабы вариантов в русском языке ВАГОН...
ИМХО Так что данный модуль не спасет форум от быдло посетителей!!!
ИМХО Так что данный модуль не спасет форум от быдло посетителей!!!
Спустя 10 минут, 11 секунд (21.06.2012 - 16:36) medvedeva написал(а):
Цитата (Kuliev @ 21.06.2012 - 13:26) |
если захотят написать матом ТО НАПИШУТ |
Это точно, накрайняк напишут в IMG
![unsure.gif](http://phpforum.su/html/emoticons/unsure.gif)
Спустя 7 минут, 59 секунд (21.06.2012 - 16:44) vagrand написал(а):
Kuliev
100% - модерация и только модерация
100% - модерация и только модерация
Спустя 16 часов, 1 минута, 54 секунды (22.06.2012 - 08:46) radeugen написал(а):
Спасибо всем.