23
23
use Cleantalk \ApbctBitrix \SFW ;
24
24
25
25
if ( ! defined ( 'CLEANTALK_USER_AGENT ' ) )
26
- define ( 'CLEANTALK_USER_AGENT ' , 'bitrix-3.12 .0 ' );
26
+ define ( 'CLEANTALK_USER_AGENT ' , 'bitrix-3.14 .0 ' );
27
27
28
28
define ('APBCT_TBL_FIREWALL_DATA ' , 'cleantalk_sfw ' ); // Table with firewall data.
29
29
define ('APBCT_TBL_FIREWALL_LOG ' , 'cleantalk_sfw_logs ' ); // Table with firewall logs.
@@ -182,7 +182,14 @@ public static function OnPageStartHandler()
182
182
if ( ! $ USER ->IsAdmin () ){
183
183
184
184
if ( $ bot_detector ) {
185
- Asset::getInstance ()->addJs ('https://moderate.cleantalk.org/ct-bot-detector-wrapper.js ' );
185
+ if (class_exists ('COption ' )) {
186
+ $ use_custom_server = \COption::GetOptionString ( 'cleantalk.antispam ' , 'use_custom_server ' , '' );
187
+ if ($ use_custom_server !== '' ) {
188
+ Asset::getInstance ()->addJs ('https://moderate. ' . $ use_custom_server . '/ct-bot-detector-wrapper.js ' );
189
+ } else {
190
+ Asset::getInstance ()->addJs ('https://moderate.cleantalk.org/ct-bot-detector-wrapper.js ' );
191
+ }
192
+ }
186
193
}
187
194
188
195
// Set cookies
@@ -771,19 +778,27 @@ static function OnBeforeMessageAddHandler(&$arFields) {
771
778
array ('AUTHOR_ID ' =>$ arFields ['AUTHOR_ID ' ], 'APPROVED ' =>'Y ' ),
772
779
TRUE
773
780
);
774
- if (intval ($ approved_messages ) > 5 ) {
781
+ if (intval ($ approved_messages ) > 5 && ! defined ( ' CLEANTALK__IGNORE_APPROVED_COMMENTS_COUNT_RULE ' ) ) {
775
782
return ;
776
783
}
777
784
$ aComment ['sender_email ' ] = $ USER ->GetEmail ();
778
785
} else {
779
786
$ aComment ['sender_email ' ] = isset ($ arFields ['EMAIL ' ]) ? $ arFields ['EMAIL ' ] : '' ;
780
787
}
781
788
782
- $ aComment ['type ' ] = 'comment ' ;
783
- $ aComment ['sender_nickname ' ] = isset ($ arFields ['AUTHOR_NAME ' ]) ? $ arFields ['AUTHOR_NAME ' ] : '' ;
784
- $ aComment ['subject ' ] = '' ;
785
- $ aComment ['message ' ] = isset ($ arFields ['POST_MESSAGE ' ]) ? array ($ arFields ['POST_MESSAGE ' ]) : array ();
786
- $ aComment ['example ' ] = array ();
789
+ if (isset ($ arFields ['TITLE ' ]) && isset ($ arFields ['DESCRIPTION ' ])) {
790
+ $ aComment ['type ' ] = 'topic_add ' ;
791
+ $ aComment ['sender_nickname ' ] = isset ($ arFields ['LAST_POSTER_NAME ' ]) ? $ arFields ['LAST_POSTER_NAME ' ] : '' ;
792
+ $ aComment ['subject ' ] = isset ($ arFields ['TITLE ' ]) ? array ($ arFields ['TITLE ' ]) : '' ;
793
+ $ aComment ['message ' ] = isset ($ arFields ['DESCRIPTION ' ]) ? array ($ arFields ['DESCRIPTION ' ]) : array ();
794
+ $ aComment ['example ' ] = array ();
795
+ } else {
796
+ $ aComment ['type ' ] = 'comment ' ;
797
+ $ aComment ['sender_nickname ' ] = isset ($ arFields ['AUTHOR_NAME ' ]) ? $ arFields ['AUTHOR_NAME ' ] : '' ;
798
+ $ aComment ['subject ' ] = '' ;
799
+ $ aComment ['message ' ] = isset ($ arFields ['POST_MESSAGE ' ]) ? array ($ arFields ['POST_MESSAGE ' ]) : array ();
800
+ $ aComment ['example ' ] = array ();
801
+ }
787
802
788
803
if (COption::GetOptionInt ('cleantalk.antispam ' , 'form_send_example ' , 0 ) == 1 ){
789
804
$ arTopic = CForumTopic::GetByID ($ arFields ['TOPIC_ID ' ]);
@@ -1263,7 +1278,17 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE, $form_errors = n
1263
1278
}
1264
1279
1265
1280
$ type = $ arEntity ['type ' ];
1266
- if ($ type != 'comment ' && $ type != 'webform ' && $ type != 'register ' && $ type != 'order ' && $ type != 'feedback_general_contact_form ' && $ type != 'private_message ' && strpos ($ type , 'contact_form_bitrix ' ) === false ){
1281
+ $ allowed_types = array (
1282
+ 'topic_add ' ,
1283
+ 'comment ' ,
1284
+ 'webform ' ,
1285
+ 'register ' ,
1286
+ 'order ' ,
1287
+ 'feedback_general_contact_form ' ,
1288
+ 'private_message ' ,
1289
+ );
1290
+
1291
+ if (!in_array ($ type , $ allowed_types ) && strpos ($ type , 'contact_form_bitrix ' ) === false ){
1267
1292
CEventLog::Add (array (
1268
1293
'SEVERITY ' => 'SECURITY ' ,
1269
1294
'AUDIT_TYPE_ID ' => 'CLEANTALK_E_INTERNAL ' ,
@@ -1372,6 +1397,7 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE, $form_errors = n
1372
1397
);
1373
1398
1374
1399
switch ($ type ) {
1400
+ case 'topic_add ' :
1375
1401
case 'comment ' :
1376
1402
$ timelabels_key = 'mail_error_comment ' ;
1377
1403
if (is_array ($ arEntity ['message ' ])) {
@@ -1382,11 +1408,10 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE, $form_errors = n
1382
1408
}
1383
1409
$ request_params ['message ' ] = $ arEntity ['message ' ];
1384
1410
$ request_params ['example ' ] = $ arEntity ['example ' ];
1385
- $ request_params ['post_info ' ]['comment_type ' ] = ' comment ' ;
1411
+ $ request_params ['post_info ' ]['comment_type ' ] = $ type ;
1386
1412
1387
1413
$ ct_request = new CleantalkRequest ($ request_params );
1388
1414
$ ct_result = $ ct ->isAllowMessage ($ ct_request );
1389
-
1390
1415
break ;
1391
1416
1392
1417
case 'order ' :
@@ -1710,6 +1735,19 @@ static function GetCleanTalkResume($module, $id) {
1710
1735
*/
1711
1736
private static function GetWorkServer () {
1712
1737
global $ DB ;
1738
+
1739
+ if (class_exists ('COption ' )) {
1740
+ $ use_custom_server = \COption::GetOptionString ( 'cleantalk.antispam ' , 'use_custom_server ' , '' );
1741
+ if ($ use_custom_server !== '' ) {
1742
+ return array (
1743
+ 'work_url ' => 'http://moderate. ' . $ use_custom_server ,
1744
+ 'server_url ' => 'http://moderate. ' . $ use_custom_server ,
1745
+ 'server_ttl ' => 0 ,
1746
+ 'server_changed ' => 0 ,
1747
+ );
1748
+ }
1749
+ }
1750
+
1713
1751
$ result = $ DB ->Query ('SELECT work_url,server_url,server_ttl,server_changed FROM cleantalk_server LIMIT 1 ' )->Fetch ();
1714
1752
if ($ result !== FALSE )
1715
1753
return array (
@@ -1750,7 +1788,17 @@ private static function ExceptionList($value = null)
1750
1788
*/
1751
1789
private static function SetWorkServer ($ work_url = 'https://moderate.cleantalk.org ' , $ server_url = 'https://moderate.cleantalk.org ' , $ server_ttl = 0 , $ server_changed = 0 ) {
1752
1790
global $ DB ;
1791
+
1753
1792
$ result = $ DB ->Query ('SELECT count(*) AS count FROM cleantalk_server ' )->Fetch ();
1793
+
1794
+ if (class_exists ('COption ' )) {
1795
+ $ use_custom_server = \COption::GetOptionString ( 'cleantalk.antispam ' , 'use_custom_server ' , '' );
1796
+ if ($ use_custom_server !== '' ) {
1797
+ $ work_url = 'http://moderate. ' . $ use_custom_server ;
1798
+ $ server_url = 'http://moderate. ' . $ use_custom_server ;
1799
+ }
1800
+ }
1801
+
1754
1802
if ($ result ['count ' ] == 0 ){
1755
1803
$ arInsert = $ DB ->PrepareInsert (
1756
1804
'cleantalk_server ' ,
0 commit comments