RomanL 7 лет назад
Родитель
Сommit
9f9a0e3040

+ 6 - 4
inc/classes/BxDolForm.php

@@ -1269,9 +1269,11 @@ class BxDolFormChecker
                 if (!$val)
                     continue;
 
-                if (!$oChecker->checkIsSpam($val))
+                if (!$oChecker->checkIsSpam($val)){
+					BxDolForm::setSubmittedValue($a['name'], $val, $this->_sFormMethod, $this->_aSpecificValues);
                     continue;
-
+				}
+                
                 ++$iErrors;
 
                 $sErr = _t('_sys_spam_detected');
@@ -1481,10 +1483,10 @@ class BxDolFormCheckerHelper
             return true;
         return $oCaptcha->check ();
     }
-    static public function checkIsSpam($val)
+    static public function checkIsSpam(&$val)
     {
         $bSpam = false;
-        bx_alert('system', 'check_spam', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => $val, 'where' => 'form'));
+        bx_alert('system', 'check_spam', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => &$val, 'where' => 'form'));
         return $bSpam;
     }
 

+ 2 - 2
modules/boonex/antispam/classes/BxAntispamAlertsResponse.php

@@ -31,10 +31,10 @@ class BxAntispamAlertsResponse extends BxDolAlertsResponse
 
             switch ($oAlert->sAction) {
                 case 'check_spam':
-                    $oAlert->aExtras['is_spam'] = BxDolService::call('bx_antispam', 'is_spam', array($oAlert->aExtras['content']));
+                    $oAlert->aExtras['is_spam'] = BxDolService::call('bx_antispam', 'is_spam', array(&$oAlert->aExtras['content']));
                     break;
             }
-
+            
         }
     }
 }

+ 2 - 0
modules/boonex/antispam/classes/BxAntispamConfig.php

@@ -24,6 +24,7 @@ class BxAntispamConfig extends BxDolModuleConfig
         'akismet_enable' => 'bx_antispam_akismet_enable',
         'disposable_email_domains_mode' => 'bx_antispam_disposable_email_domains_mode',
         'disposable_email_domains_behaviour_join' => 'bx_antispam_disposable_email_domains_behaviour_join',
+        'profanity_enable' => 'bx_antispam_profanity_filter_enable',
     );
     /**
      * default local options, it is filled in with real system options in class contructor, @see restoreAntispamOptions
@@ -36,6 +37,7 @@ class BxAntispamConfig extends BxDolModuleConfig
         'dnsbl_behaviour_login' => 'block',
         'dnsbl_behaviour_join' => 'approval',
         'akismet_enable' => '',
+        'profanity_enable' => '',
     );
 
     public function __construct($aModule)

+ 8 - 3
modules/boonex/antispam/classes/BxAntispamModule.php

@@ -65,17 +65,22 @@ class BxAntispamModule extends BxDolModule
      *          BX_SLASHES_NO_ACTION - do not perform any action with slashes
      * @return true if spam detected and content shouln't be recorded, false if content should be processed as usual.
      */
-    public function serviceIsSpam ($sContent, $sIp = '', $isStripSlashes = BX_SLASHES_AUTO)
-    {
+    public function serviceIsSpam (&$sContent, $sIp = '', $isStripSlashes = BX_SLASHES_AUTO)
+    {      
         if (defined('BX_DOL_CRON_EXECUTE') || isAdmin())
             return false;
+        
+        if ('on' == $this->_oConfig->getAntispamOption('profanity_enable')) {
+            $oProfanityFilter = bx_instance('BxAntispamProfanityFilter', array(), $this->_aModule);
+            $sContent = $oProfanityFilter->censorString($sContent);
+        }
 
         if ($this->serviceIsIpWhitelisted($sIp))
             return false;
 
         if (get_magic_quotes_gpc() && $isStripSlashes == BX_SLASHES_AUTO)
             $sContent = stripslashes($sContent);
-
+        
         $bRet = false;
         if ('on' == $this->_oConfig->getAntispamOption('uridnsbl_enable')) {
             $oDNSURIBlacklists = bx_instance('BxAntispamDNSURIBlacklists', array(), $this->_aModule);

+ 57 - 0
modules/boonex/antispam/classes/BxAntispamProfanityFilter.php

@@ -0,0 +1,57 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    Antispam Antispam
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+/**
+ * Profanity Filter based on https://github.com/developerdino/ProfanityFilter
+ */
+class BxAntispamProfanityFilter extends BxDol
+{
+    protected $oProfanityFilter = null;
+
+    public function __construct()
+    {
+        parent::__construct();
+        
+        require_once (BX_DIRECTORY_PATH_PLUGINS . 'banbuilder/src/CensorWords.php');
+        $sClassName = 'Snipe\BanBuilder\CensorWords';
+        $this->oProfanityFilter = new $sClassName;
+        $this->oProfanityFilter->addDictionary('en-base');
+        $this->oProfanityFilter->addDictionary('en-uk');
+        
+        $aLng = BxDolLanguages::getInstance()->getLanguages();
+        try{
+            foreach ($aLng as $sKey => $sVal){
+                if ($sKey != 'en')
+                    $this->oProfanityFilter->addDictionary($sKey);
+            }
+        }
+        catch (Exception $oException) {
+        }
+        
+        $this->oProfanityFilter->setReplaceChar(getParam('bx_antispam_profanity_filter_char_replace'));
+        
+        $sBadWords = trim(getParam('bx_antispam_profanity_filter_bad_words_list'));
+        if ($sBadWords != '')
+            $this->oProfanityFilter->addFromArray(explode(',', $sBadWords));
+        
+        $sWhiteWords = getParam('bx_antispam_profanity_filter_white_words_list');
+        if ($sWhiteWords != '')
+            $this->oProfanityFilter->addWhiteList(explode(',', $sWhiteWords));
+    }
+
+    public function censorString ($s)
+    {
+        $aTmp = $this->oProfanityFilter->censorString($s, false);
+        return $aTmp['clean'];
+    } 
+}
+
+/** @} */

+ 10 - 3
modules/boonex/antispam/install/langs/en.xml

@@ -3,13 +3,15 @@
 
 	<string name="_bx_antispam"><![CDATA[Antispam]]></string>
     <string name="_bx_antispam_help"><![CDATA[Help]]></string>
-    <string name="_bx_antispam_help_text"><![CDATA[This module allows to limit spam on the site, there are different build-in tools for this:
+    <string name="_bx_antispam_help_text">
+      <![CDATA[This module allows to limit spam on the site, there are different build-in tools for this:
 <ul>
     <li><b>IP table</b> - manual IP blocking/whitelisting</li>
     <li><b>DNSBL</b> - automatic blocking by IP from different block lists</li>
     <li><b>URI DNSBL</b> - automatic blocking of spam content by spam URLs in the text</li>
     <li><b>Akismet</b> - automatic spam content blocking using <a target="_blank" href="http://akismet.com">Akismet service</a></li>
     <li><b>StopForumSpam</b> - automatic spam content blocking using <a target="_blank" href="http://www.stopforumspam.com">StopForumSpam service</a></li>
+    <li><b>Profanity filter</b> - profanity filter, based on a predefined list of words with the ability to add to words this list</a></li>
 </ul>
 ]]></string>
     <string name="_bx_antispam_help_dnsbl"><![CDATA[
@@ -121,6 +123,7 @@ This antispam method scan submitted content for the URLs and check them if any o
     <string name="_bx_antispam_adm_stg_cpt_category_akismet"><![CDATA[Akismet]]></string>
     <string name="_bx_antispam_adm_stg_cpt_category_stopforumspam"><![CDATA[StopForumSpam]]></string>
     <string name="_bx_antispam_adm_stg_cpt_category_disposable_email_domains"><![CDATA[Disposable email domains]]></string>
+    <string name="_bx_antispam_adm_stg_cpt_category_profanity_filter"><![CDATA[Profanity filter]]></string>
     
 	<string name="_bx_antispam_option_block"><![CDATA[Total block all spam content]]></string>
 	<string name="_bx_antispam_option_report"><![CDATA[Send report to admin if spam content discovered]]></string>
@@ -135,8 +138,12 @@ This antispam method scan submitted content for the URLs and check them if any o
     <string name="_bx_antispam_option_stopforumspam_api_key"><![CDATA["Stop Forum Spam" API Key]]></string> 
 	<string name="_bx_antispam_option_disposable_email_domains_mode"><![CDATA[Mode]]></string>
 	<string name="_bx_antispam_option_disposable_email_domains_behaviour_join"><![CDATA[Join behaviour]]></string>
-    
-    <string name="_bx_antispam_spam_report_name"><![CDATA[Spam report message]]></string>
+  <string name="_bx_antispam_option_profanity_filter_enable"><![CDATA[Enable Profanity filter]]></string>
+  <string name="_bx_antispam_option_profanity_filter_bad_words_list"><![CDATA[Bad words list (comma separated)]]></string>
+  <string name="_bx_antispam_option_profanity_filter_char_replace"><![CDATA[Char to replace]]></string>
+  <string name="_bx_antispam_option_profanity_filter_white_words_list"><![CDATA[White words list (comma separated)]]></string>
+
+  <string name="_bx_antispam_spam_report_name"><![CDATA[Spam report message]]></string>
     <string name="_bx_antispam_spam_report_subject"><![CDATA[Automatic spam report]]></string>
     <string name="_bx_antispam_spam_report_body"><![CDATA[{email_header}
 <b>Profile:</b> <a href="{SpammerUrl}">{SpammerNickName}</a><br />

+ 11 - 0
modules/boonex/antispam/install/sql/enable.sql

@@ -66,6 +66,17 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'bx_antispam_disposable_email_domains_behaviour_join', '_bx_antispam_option_disposable_email_domains_behaviour_join', 'block', 'select', 'a:3:{s:6:"module";s:11:"bx_antispam";s:6:"method";s:13:"config_values";s:6:"params";a:1:{i:0;s:29:"disposable_email_domains_join";}}', '', '', 20);
 
 
+INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `order` )  
+VALUES (@iTypeId, 'bx_antispam_profanity_filter', '_bx_antispam_adm_stg_cpt_category_profanity_filter', 7);
+SET @iCategoryId = LAST_INSERT_ID();
+
+INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
+(@iCategoryId, 'bx_antispam_profanity_filter_enable', '_bx_antispam_option_profanity_filter_enable', '', 'checkbox', '', '', '', 10),
+(@iCategoryId, 'bx_antispam_profanity_filter_bad_words_list', '_bx_antispam_option_profanity_filter_bad_words_list', '', 'text', '', '', '', 20),
+(@iCategoryId, 'bx_antispam_profanity_filter_char_replace', '_bx_antispam_option_profanity_filter_char_replace', '*', 'digit', '', '', '', 30),
+(@iCategoryId, 'bx_antispam_profanity_filter_white_words_list', '_bx_antispam_option_profanity_filter_white_words_list', '', 'text', '', '', '', 40);
+
+
 -- page: DNSBL list
 
 INSERT INTO `sys_objects_page`(`object`, `uri`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES 

+ 5 - 1
modules/boonex/convos/classes/BxCnvFormEntry.php

@@ -82,7 +82,11 @@ class BxCnvFormEntry extends BxBaseModTextFormEntry
 
             // check for spam
             $bSpam = false;
-            bx_alert('system', 'check_spam', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => $this->getCleanValue('text'), 'where' => $this->MODULE));
+			$sVal = $this->getCleanValue('text');
+            bx_alert('system', 'check_spam', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => &$sVal, 'where' => $this->MODULE));
+			if (isset($this->aInputs[$sName]))
+				$this->aInputs[$sName] = $sVal;
+				
             $iFolder = $bSpam ? BX_CNV_FOLDER_SPAM : BX_CNV_FOLDER_INBOX;
 
             $this->_updateParticipants ($iContentId, $iFolder, $bDraft);

+ 9 - 2
modules/boonex/russian/data/langs/bx_antispam/ru.xml

@@ -3,13 +3,15 @@
 
 	<string name="_bx_antispam"><![CDATA[Антиспам]]></string>
     <string name="_bx_antispam_help"><![CDATA[Помощь]]></string>
-    <string name="_bx_antispam_help_text"><![CDATA[Этот модуль помогает ограничить спам на сайте. Для этого существуют различные встроенные инструменты:
+    <string name="_bx_antispam_help_text">
+      <![CDATA[Этот модуль помогает ограничить спам на сайте. Для этого существуют различные встроенные инструменты:
 <ul>
     <li><b>IP table</b> - ручная (раз)блокировка IP</li>
     <li><b>DNSBL</b> - автоматическая блокировка по IP из различных блок-списков</li>
     <li><b>URI DNSBL</b> - автоматическая блокировка спам-контента с помощью спам-URL в тексте</li>
     <li><b>Akismet</b> - автоматическая блокировка спам-контента с использованием <a target="_blank" href="http://akismet.com">Сервиса Akismet</a></li>
     <li><b>StopForumSpam</b> - автоматическая блокировка спам-контента с использованием <a target="_blank" href="http://www.stopforumspam.com">Сервиса StopForumSpam</a></li>
+    <li><b>Profanity filter</b> - фильтр ненормативной лексики, основанный на заранее определенных списках слов с возможностью их расширения</a></li>
 </ul>
 ]]></string>
     <string name="_bx_antispam_help_dnsbl"><![CDATA[
@@ -121,6 +123,7 @@ URI DNSBL - это DNSBL, которые перечисляют доменные
     <string name="_bx_antispam_adm_stg_cpt_category_akismet"><![CDATA[Akismet]]></string>
     <string name="_bx_antispam_adm_stg_cpt_category_stopforumspam"><![CDATA[StopForumSpam]]></string>
     <string name="_bx_antispam_adm_stg_cpt_category_disposable_email_domains"><![CDATA[Временные е-mail домены]]></string>
+    <string name="_bx_antispam_adm_stg_cpt_category_profanity_filter"><![CDATA[Фильтр ненормативной лексики]]></string>
 
 	<string name="_bx_antispam_option_block"><![CDATA[Полностью заблокировать весь спам-контент]]></string>
 	<string name="_bx_antispam_option_report"><![CDATA[Послать отчёт администратору при обнаружении спам-контента]]></string>
@@ -135,7 +138,11 @@ URI DNSBL - это DNSBL, которые перечисляют доменные
 	<string name="_bx_antispam_option_stopforumspam_api_key"><![CDATA[Ключ для "Stop Forum Spam" API]]></string>
 	<string name="_bx_antispam_option_disposable_email_domains_mode"><![CDATA[Режим]]></string>
     <string name="_bx_antispam_option_disposable_email_domains_behaviour_join"><![CDATA[Поведение при регистрации пользователя]]></string>
-    
+  <string name="_bx_antispam_option_profanity_filter_enable"><![CDATA[Включить фильтр ненормативной лексики]]></string>
+  <string name="_bx_antispam_option_profanity_filter_bad_words_list"><![CDATA[Список плохих слов (разделенных запятой)]]></string>
+  <string name="_bx_antispam_option_profanity_filter_char_replace"><![CDATA[Символ замены]]></string>
+  <string name="_bx_antispam_option_profanity_filter_white_words_list"><![CDATA[Список слов исключений (разделенных запятой)]]></string>
+  
     <string name="_bx_antispam_spam_report_name"><![CDATA[Сообщение отчёта о спаме]]></string>
     <string name="_bx_antispam_spam_report_subject"><![CDATA[Автоматический отчёт о спаме]]></string>
     <string name="_bx_antispam_spam_report_body"><![CDATA[{email_header}