Skip to content

Commit

Permalink
add excepiton function
Browse files Browse the repository at this point in the history
  • Loading branch information
davydov committed Apr 1, 2019
1 parent 3f085a5 commit a47ab97
Showing 1 changed file with 40 additions and 25 deletions.
65 changes: 40 additions & 25 deletions cleantalk.antispam/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -1025,28 +1025,32 @@ function OnBeforeUserRegisterHandler(&$arFields) {
$aUser['sender_email'] = isset($arFields['EMAIL']) ? $arFields['EMAIL'] : '';
$aUser['sender_nickname'] = isset($arFields['LOGIN']) ? $arFields['LOGIN'] : '';

$aResult = self::CheckAllBefore($aUser, TRUE);
if (!self::ExceptionList($aUser))
{
$aResult = self::CheckAllBefore($aUser, TRUE);

if(isset($aResult) && is_array($aResult)){
if($aResult['errno'] == 0){
if($aResult['allow'] == 1){
// Not spammer - just return;
return;
}else{
// Spammer - return false and throw
// Note: 'stop_queue' is ignored in user checking
if (preg_match('//u', $aResult['ct_result_comment'])){
$err_str = preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/iu', '', $aResult['ct_result_comment']);
$err_str = preg_replace('/<[^<>]*>/iu', '', $err_str);
if(isset($aResult) && is_array($aResult)){
if($aResult['errno'] == 0){
if($aResult['allow'] == 1){
// Not spammer - just return;
return;
}else{
$err_str = preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/i', '', $aResult['ct_result_comment']);
$err_str = preg_replace('/<[^<>]*>/i', '', $err_str);
// Spammer - return false and throw
// Note: 'stop_queue' is ignored in user checking
if (preg_match('//u', $aResult['ct_result_comment'])){
$err_str = preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/iu', '', $aResult['ct_result_comment']);
$err_str = preg_replace('/<[^<>]*>/iu', '', $err_str);
}else{
$err_str = preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/i', '', $aResult['ct_result_comment']);
$err_str = preg_replace('/<[^<>]*>/i', '', $err_str);
}
$APPLICATION->ThrowException($err_str);
return false;
}
$APPLICATION->ThrowException($err_str);
return false;
}
}
}
}

}
}

Expand Down Expand Up @@ -1227,8 +1231,6 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE) {
$ct_key = COption::GetOptionString('cleantalk.antispam', 'key', '0');
$ct_ws = self::GetWorkServer();

$ct_submit_time = self::ct_cookies_test() == 1 ? time() - (int)$_COOKIE['ct_timestamp'] : null;

if (!isset($_COOKIE['ct_checkjs']))
$checkjs = NULL;
elseif (in_array($_COOKIE['ct_checkjs'], self::GetCheckJSValues()))
Expand Down Expand Up @@ -1312,14 +1314,14 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE) {
$ct_request->response_lang = 'ru';
$ct_request->js_on = $checkjs;
$ct_request->sender_info = $sender_info;
$ct_request->submit_time = self::ct_cookies_test() == 1 ? time() - (int)$_COOKIE['ct_timestamp'] : null;
if (isset($arEntity['message_title']) && is_array($arEntity))
$arEntity['message_title'] = implode("\n", $arEntity['message_title']);
if (isset($arEntity['message_body']) && is_array($arEntity['message_body']))
$arEntity['message_body'] = implode("\n", $arEntity['message_body']);
switch ($type) {
case 'comment':
$timelabels_key = 'mail_error_comment';
$ct_request->submit_time = $ct_submit_time;

$ct_request->message = isset($arEntity['message_title']) ? $arEntity['message_title'] : '';
$ct_request->message .= "\n\n";
Expand Down Expand Up @@ -1350,7 +1352,6 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE) {
$ct_request->post_info = $post_info;

$timelabels_key = 'mail_error_comment';
$ct_request->submit_time = $ct_submit_time;

$ct_request->message = isset($arEntity['message_title']) ? $arEntity['message_title'] : '';
$ct_request->message .= "\n\n";
Expand All @@ -1366,7 +1367,6 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE) {
$ct_request->post_info = $post_info;

$timelabels_key = 'mail_error_comment';
$ct_request->submit_time = $ct_submit_time;

$ct_request->message .= isset($arEntity['message_body']) ? $arEntity['message_body'] : '';

Expand All @@ -1380,7 +1380,6 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE) {
$ct_request->post_info = $post_info;

$timelabels_key = 'mail_error_comment';
$ct_request->submit_time = $ct_submit_time;

$ct_request->message .= isset($arEntity['message_body']) ? $arEntity['message_body'] : '';

Expand All @@ -1390,7 +1389,6 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE) {
case 'register':

$timelabels_key = 'mail_error_reg';
$ct_request->submit_time = $ct_submit_time;
$ct_request->tz = isset($arEntity['user_timezone']) ? $arEntity['user_timezone'] : NULL;

$ct_result = $ct->isAllowUser($ct_request);
Expand All @@ -1405,7 +1403,6 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE) {
$ct_request->post_info = $post_info;

$timelabels_key = 'mail_error_comment';
$ct_request->submit_time = $ct_submit_time;
$ct_request->tz = isset($arEntity['user_timezone']) ? $arEntity['user_timezone'] : NULL;

$ct_result = $ct->isAllowMessage($ct_request);
Expand Down Expand Up @@ -1645,6 +1642,24 @@ private static function GetWorkServer() {
);
}

/**
* CleanTalk inner function - check for exceptions.
*/
private static function ExceptionList($value = null)
{
if ($value && is_array($value))
{
if (isset($value['sender_email']))
{
if (preg_match('^user-\d+@shop\.kalyan-hut\.ru^', $value['sender_email']))
return true;
}

}

return false;
}

/**
* CleanTalk inner function - sets working server.
*/
Expand Down

0 comments on commit a47ab97

Please sign in to comment.