Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions cleantalk.antispam/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,11 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE, $form_errors = n
'event_token' => isset($_POST['ct_bot_detector_event_token']) ? $_POST['ct_bot_detector_event_token'] : null,
);

// Fix encoding recursively for message
if (is_array($arEntity['message'])) {
$arEntity['message'] = self::fix_encoding_recursive($arEntity['message']);
}

switch ($type) {
case 'topic_add':
case 'comment':
Expand Down Expand Up @@ -1735,6 +1740,30 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE, $form_errors = n
return false;
}

/**
* Fix encoding recursively in array
* @param array $array
* @param string $from
* @param string $to
*/
private static function fix_encoding_recursive($array, $from = 'CP1251', $to = 'UTF-8') {
foreach ($array as $key => $value) {
if (is_array($value)) {
$array[$key] = self::fix_encoding_recursive($value, $from, $to);
} else {
if (is_string($value) && !mb_check_encoding($value, $to)) {
$converted = iconv($from, $to . '//IGNORE', $value);
if (mb_check_encoding($converted, $to)) {
$array[$key] = $converted;
} else {
unset($array[$key]);
}
}
}
}
return $array;
}

/**
* Addon to CheckAllBefore method after comments/messages checking
* It fills special CleanTalk tables according to CleanTalk result
Expand Down