Răsfoiți Sursa

Ticket #3675 - Toxicity Filters for Antispam module.

Alexander 4 ani în urmă
părinte
comite
f3b9ad4e2a

+ 5 - 1
inc/classes/BxDolForm.php

@@ -934,6 +934,10 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
             }
             }
         }
         }
 
 
+        //if this is a comments form then we support it since V13.A3 as a special case
+        if (isset($this->aParams['module']) && $this->aParams['module'] == 'system' && isset($this->aParams['object']) && $this->aParams['object'] == 'sys_comment')
+            return true;
+
         return false;
         return false;
     }
     }
 
 
@@ -942,7 +946,7 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
             $oModule = BxDolModule::getInstance($this->aParams['module']);
             $oModule = BxDolModule::getInstance($this->aParams['module']);
             $CNF = &$oModule->_oConfig->CNF;
             $CNF = &$oModule->_oConfig->CNF;
 
 
-            if (isset($oModule->_oConfig->CNF) && isset($CNF['FIELD_STATUS_ADMIN'])) $aValsToAdd[$CNF['FIELD_STATUS_ADMIN']] = BX_BASE_MOD_TEXT_STATUS_HIDDEN;
+            if (isset($oModule->_oConfig->CNF) && isset($CNF['FIELD_STATUS_ADMIN'])) $aValsToAdd[$CNF['FIELD_STATUS_ADMIN']] = 'pending';
         }
         }
     }
     }
 
 

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

@@ -42,6 +42,8 @@ class BxAntispamAlertsResponse extends BxDolAlertsResponse
                     BxDolService::call('bx_antispam', 'on_form_submitted', array($oAlert->aExtras['module'], $oAlert->aExtras['entry_id']));
                     BxDolService::call('bx_antispam', 'on_form_submitted', array($oAlert->aExtras['module'], $oAlert->aExtras['entry_id']));
                     break;
                     break;
             }
             }
+        } elseif ('comment' == $oAlert->sUnit && BxDolService::call('bx_antispam', 'is_last_form_submitted_toxic', array())) {
+            BxDolService::call('bx_antispam', 'set_comment_as_pending', array($oAlert->iObject));
         }
         }
     }
     }
 }
 }

+ 5 - 0
modules/boonex/antispam/classes/BxAntispamDb.php

@@ -15,6 +15,11 @@ class BxAntispamDb extends BxDolModuleDb
     {
     {
         parent::__construct($oConfig);
         parent::__construct($oConfig);
     }
     }
+
+    function setCommentStatus($iCmtId, $sStatus) {
+        $sTableName = BxDolCmts::$sTableIds;
+        $this->query("UPDATE `{$sTableName}` SET `status_admin` = :status WHERE `id` = :id", ['id' => $iCmtId, 'status' => $sStatus]);
+    }
 }
 }
 
 
 /** @} */
 /** @} */

+ 21 - 6
modules/boonex/antispam/classes/BxAntispamModule.php

@@ -16,6 +16,7 @@ class BxAntispamModule extends BxDolModule
     public function __construct(&$aModule)
     public function __construct(&$aModule)
     {
     {
         parent::__construct($aModule);
         parent::__construct($aModule);
+        $this->_bLastSubmittedFormWasToxic = false;
     }
     }
 
 
     public function serviceUpdateDisposableDomainsLists ()
     public function serviceUpdateDisposableDomainsLists ()
@@ -145,9 +146,9 @@ class BxAntispamModule extends BxDolModule
      * @param $isStripSlashes slashes parameter:
      * @param $isStripSlashes slashes parameter:
      *          BX_SLASHES_AUTO - automatically detect magic_quotes_gpc setting
      *          BX_SLASHES_AUTO - automatically detect magic_quotes_gpc setting
      *          BX_SLASHES_NO_ACTION - do not perform any action with slashes
      *          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.
+     * @return true if toxic content detected and content shouln't be recorded, false if content should be processed as usual.
      */
      */
-    public function serviceIsToxic ($sContent, $sIp = '', $isStripSlashes = BX_SLASHES_AUTO)
+    public function serviceIsToxic ($sContent, $sIp = '', $isStripSlashes = BX_SLASHES_AUTO, $bSupressNotification = false)
     {
     {
         if (defined('BX_DOL_CRON_EXECUTE') || isAdmin())
         if (defined('BX_DOL_CRON_EXECUTE') || isAdmin())
             return false;
             return false;
@@ -168,6 +169,8 @@ class BxAntispamModule extends BxDolModule
                 if ($oPerspectiveAPI->isToxic($sContent)) {
                 if ($oPerspectiveAPI->isToxic($sContent)) {
                     $oPerspectiveAPI->onPositiveDetection($sContent);
                     $oPerspectiveAPI->onPositiveDetection($sContent);
                     $aQuickCache[$key] = true;
                     $aQuickCache[$key] = true;
+
+                    if (!$bSupressNotification) $this->serviceOnToxicContentFound($sContent);
                 }
                 }
             }
             }
         }
         }
@@ -209,14 +212,14 @@ class BxAntispamModule extends BxDolModule
             $sFormText .= " ".$val; // collect all text fields into a single text
             $sFormText .= " ".$val; // collect all text fields into a single text
         }
         }
 
 
-        if ($this->serviceIsToxic($sFormText)) {
+        if ($this->serviceIsToxic($sFormText, '', BX_SLASHES_AUTO, true)) {
             $this->_bLastSubmittedFormWasToxic = true;
             $this->_bLastSubmittedFormWasToxic = true;
 
 
             $sActionrequired = $this->_oConfig->getAntispamOption('toxicity_action');
             $sActionrequired = $this->_oConfig->getAntispamOption('toxicity_action');
 
 
             if ($sActionrequired == 'block' || $sActionrequired == 'disapprove' && !$oForm->isStatusFieldSupported()) {
             if ($sActionrequired == 'block' || $sActionrequired == 'disapprove' && !$oForm->isStatusFieldSupported()) {
                 $oForm->setValid(false);
                 $oForm->setValid(false);
-                $this->serviceOnToxicContentBlocked($sFormText);
+                $this->serviceOnToxicContentFound($sFormText);
 
 
                 if ($sSubmitName)
                 if ($sSubmitName)
                     $oForm->aInputs[$sSubmitName]['error'] = _t('_bx_antispam_form_submission_error');
                     $oForm->aInputs[$sSubmitName]['error'] = _t('_bx_antispam_form_submission_error');
@@ -227,13 +230,21 @@ class BxAntispamModule extends BxDolModule
         }
         }
     }
     }
 
 
+    public function serviceIsLastFormSubmittedToxic() {
+        return $this->_bLastSubmittedFormWasToxic;
+    }
+
+    public function serviceSetCommentAsPending($iCmtId) {
+        return $this->_oDb->setCommentStatus($iCmtId, BX_CMT_STATUS_PENDING);
+    }
+
     public function serviceOnFormSubmitted($sModule, $iEntry) {
     public function serviceOnFormSubmitted($sModule, $iEntry) {
         if ($this->_bLastSubmittedFormWasToxic) {
         if ($this->_bLastSubmittedFormWasToxic) {
             $this->serviceOnToxicContentPosted($sModule, $iEntry);
             $this->serviceOnToxicContentPosted($sModule, $iEntry);
         }
         }
     }
     }
 
 
-    public function serviceOnToxicContentBlocked(&$sText) {
+    public function serviceOnToxicContentFound(&$sText) {
         if ('on' == $this->_oConfig->getAntispamOption('toxicity_report')) {
         if ('on' == $this->_oConfig->getAntispamOption('toxicity_report')) {
             $oProfile = BxDolProfile::getInstance();
             $oProfile = BxDolProfile::getInstance();
             if (!$oProfile) return;
             if (!$oProfile) return;
@@ -249,6 +260,10 @@ class BxAntispamModule extends BxDolModule
                 trigger_error('Email template or translation missing: bx_antispam_toxicity_blocked_report', E_USER_ERROR);
                 trigger_error('Email template or translation missing: bx_antispam_toxicity_blocked_report', E_USER_ERROR);
 
 
             sendMail(getParam('site_email'), $aTemplate['Subject'], $aTemplate['Body']);
             sendMail(getParam('site_email'), $aTemplate['Subject'], $aTemplate['Body']);
+
+            bx_alert('bx_antispam', 'toxic_content_found', 0, bx_get_logged_profile_id(), array(
+                'text' => $sText,
+            ));
         }
         }
     }
     }
 
 
@@ -285,7 +300,7 @@ class BxAntispamModule extends BxDolModule
             bx_alert('bx_antispam', 'toxic_content_posted', $iContentId, bx_get_logged_profile_id(), array(
             bx_alert('bx_antispam', 'toxic_content_posted', $iContentId, bx_get_logged_profile_id(), array(
                 'module' => $sModule,
                 'module' => $sModule,
                 'entry_id' => $iContentId,
                 'entry_id' => $iContentId,
-                'etrny_url' => $sContentUrl,
+                'entry_url' => $sContentUrl,
             ));
             ));
         }
         }
     }
     }

+ 3 - 1
modules/boonex/antispam/install/sql/enable.sql

@@ -225,7 +225,9 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('account', 'check_join', @iHandler),
 ('account', 'check_join', @iHandler),
 ('system', 'check_spam', @iHandler),
 ('system', 'check_spam', @iHandler),
 ('system', 'form_check', @iHandler),
 ('system', 'form_check', @iHandler),
-('system', 'form_submitted', @iHandler);
+('system', 'form_submitted', @iHandler),
+('comment', 'added', @iHandler),
+('comment', 'edited', @iHandler);
 
 
 -- email templates
 -- email templates