@@ -46,112 +46,112 @@ class CleantalkAntispam {
46
46
const KEYS_NUM = 12 ; // 12 last JS keys are valid
47
47
48
48
const APBCT_REMOTE_CALL_SLEEP = 10 ;
49
-
50
- /**
51
- * Wrapper for Bitrix agent to prevent database block ofr 10 minutes
52
- *
53
- * @return string
54
- */
55
- static public function sfw_update__agent (){
56
-
57
- self ::sfw_update ();
58
-
59
- return 'CleantalkAntispam::sfw_update__agent(); ' ;
60
- }
61
-
62
- /**
63
- * Updates SFW local database
64
- *
65
- * @param string $key
66
- *
67
- * @return string
68
- */
69
- static public function sfw_update ( $ key = '' ){
70
-
71
- $ is_sfw = COption::GetOptionInt ( 'cleantalk.antispam ' , 'form_sfw ' , 0 );
72
- $ key = $ key ? $ key : COption::GetOptionString ( 'cleantalk.antispam ' , 'key ' , '' );
73
- $ key_is_ok = COption::GetOptionInt ( 'cleantalk.antispam ' , 'key_is_ok ' , 0 );
74
- $ host_url = COption::GetOptionString ( 'cleantalk.antispam ' , 'host_url ' , 0 );
75
-
76
- COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_update_result ' , 'OK ' );
77
-
78
- if ( ! empty ( $ key ) && ! empty ( $ key_is_ok ) ){
79
-
80
- if ( $ is_sfw ){
81
-
82
- $ sfw = new CleantalkSFW ( $ key );
83
-
84
- $ file_url_hash = isset ($ _GET ['file_url_hash ' ]) ? urldecode ($ _GET ['file_url_hash ' ]) : null ;
85
-
86
- $ file_url_nums = isset ($ _GET ['file_url_nums ' ]) ? urldecode ($ _GET ['file_url_nums ' ]) : null ;
87
- $ file_url_nums = isset ($ file_url_nums ) ? explode (', ' , $ file_url_nums ) : null ;
88
-
89
- if ( ! isset ( $ file_url_hash , $ file_url_nums ) ){
90
-
91
- $ sfw ->sfw_update ( $ host_url );
92
-
93
- }elseif ( $ file_url_hash && is_array ( $ file_url_nums ) && count ( $ file_url_nums ) ){
94
-
95
- $ result = $ sfw ->sfw_update ( $ host_url , $ file_url_hash , $ file_url_nums [0 ] );
96
-
97
- if ( empty ( $ result ['error ' ] ) ){
98
-
99
- array_shift ( $ file_url_nums );
100
-
101
- if ( count ( $ file_url_nums ) ){
102
-
103
- CleantalkHelper::http__request (
104
- $ host_url ,
105
- array (
106
- 'spbc_remote_call_token ' => md5 ( $ key ),
107
- 'spbc_remote_call_action ' => 'sfw_update ' ,
108
- 'plugin_name ' => 'apbct ' ,
109
- 'file_url_hash ' => $ file_url_hash ,
110
- 'file_url_nums ' => implode (', ' , $ file_url_nums ),
111
- ),
112
- array ( 'get ' , 'async ' )
113
- );
114
-
115
- // Success. Update completed.
116
- }else
117
- COption::SetOptionInt ('cleantalk.antispam ' , 'sfw_last_update ' , time ());
118
- } else
119
- COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_update_result ' , json_encode ( $ result ) );
120
- }else
121
- COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_update_result ' , json_encode ( array ( 'error ' => 'SFW_UPDATE WRONG_FILE_URLS ' , 'file_url_hash ' => $ file_url_hash , '$file_url_nums ' => $ file_url_nums ) ) );
122
- }else
123
- COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_update_result ' , json_encode ( array ( 'error ' => 'SFW_IS_DISABLED ' ) ) );
49
+
50
+ /**
51
+ * Wrapper for Bitrix agent to prevent database block ofr 10 minutes
52
+ *
53
+ * @return string
54
+ */
55
+ static public function sfw_update__agent (){
56
+
57
+ self ::sfw_update ();
58
+
59
+ return 'CleantalkAntispam::sfw_update__agent(); ' ;
60
+ }
61
+
62
+ /**
63
+ * Updates SFW local database
64
+ *
65
+ * @param string $key
66
+ *
67
+ * @return string
68
+ */
69
+ static public function sfw_update ( $ key = '' ){
70
+
71
+ $ is_sfw = COption::GetOptionInt ( 'cleantalk.antispam ' , 'form_sfw ' , 0 );
72
+ $ key = $ key ? $ key : COption::GetOptionString ( 'cleantalk.antispam ' , 'key ' , '' );
73
+ $ key_is_ok = COption::GetOptionInt ( 'cleantalk.antispam ' , 'key_is_ok ' , 0 );
74
+ $ host_url = COption::GetOptionString ( 'cleantalk.antispam ' , 'host_url ' , 0 );
75
+
76
+ COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_update_result ' , 'OK ' );
77
+
78
+ if ( ! empty ( $ key ) && ! empty ( $ key_is_ok ) ){
79
+
80
+ if ( $ is_sfw ){
81
+
82
+ $ sfw = new CleantalkSFW ( $ key );
83
+
84
+ $ file_url_hash = isset ($ _GET ['file_url_hash ' ]) ? urldecode ($ _GET ['file_url_hash ' ]) : null ;
85
+
86
+ $ file_url_nums = isset ($ _GET ['file_url_nums ' ]) ? urldecode ($ _GET ['file_url_nums ' ]) : null ;
87
+ $ file_url_nums = isset ($ file_url_nums ) ? explode (', ' , $ file_url_nums ) : null ;
88
+
89
+ if ( ! isset ( $ file_url_hash , $ file_url_nums ) ){
90
+
91
+ $ sfw ->sfw_update ( $ host_url );
92
+
93
+ }elseif ( $ file_url_hash && is_array ( $ file_url_nums ) && count ( $ file_url_nums ) ){
94
+
95
+ $ result = $ sfw ->sfw_update ( $ host_url , $ file_url_hash , $ file_url_nums [0 ] );
96
+
97
+ if ( empty ( $ result ['error ' ] ) ){
98
+
99
+ array_shift ( $ file_url_nums );
100
+
101
+ if ( count ( $ file_url_nums ) ){
102
+
103
+ CleantalkHelper::http__request (
104
+ $ host_url ,
105
+ array (
106
+ 'spbc_remote_call_token ' => md5 ( $ key ),
107
+ 'spbc_remote_call_action ' => 'sfw_update ' ,
108
+ 'plugin_name ' => 'apbct ' ,
109
+ 'file_url_hash ' => $ file_url_hash ,
110
+ 'file_url_nums ' => implode (', ' , $ file_url_nums ),
111
+ ),
112
+ array ( 'get ' , 'async ' )
113
+ );
114
+
115
+ // Success. Update completed.
116
+ }else
117
+ COption::SetOptionInt ('cleantalk.antispam ' , 'sfw_last_update ' , time ());
118
+ } else
119
+ COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_update_result ' , json_encode ( $ result ) );
120
+ }else
121
+ COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_update_result ' , json_encode ( array ( 'error ' => 'SFW_UPDATE WRONG_FILE_URLS ' , 'file_url_hash ' => $ file_url_hash , '$file_url_nums ' => $ file_url_nums ) ) );
122
+ }else
123
+ COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_update_result ' , json_encode ( array ( 'error ' => 'SFW_IS_DISABLED ' ) ) );
124
124
}else
125
- COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_update_result ' , json_encode ( array ( 'error ' => 'NO_VALID_APIKEY_PROVIDED_OR_SFW_DISABLED ' ) ) );
126
-
127
- return 'CleantalkAntispam::sfw_update(); ' ;
125
+ COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_update_result ' , json_encode ( array ( 'error ' => 'NO_VALID_APIKEY_PROVIDED_OR_SFW_DISABLED ' ) ) );
126
+
127
+ return 'CleantalkAntispam::sfw_update(); ' ;
128
128
}
129
129
130
130
/*
131
131
* Sends and clean local logs storage
132
132
*/
133
133
static public function sfw_send_logs ( $ key = '' ){
134
-
135
- $ is_sfw = COption::GetOptionInt ( 'cleantalk.antispam ' , 'form_sfw ' , 0 );
136
- $ key = $ key ? $ key : COption::GetOptionString ( 'cleantalk.antispam ' , 'key ' , '' );
137
- $ key_is_ok = COption::GetOptionInt ( 'cleantalk.antispam ' , 'key_is_ok ' , 0 );
138
-
139
- if ( ! empty ( $ key ) && ! empty ( $ key_is_ok ) ){
140
-
141
- if ( ! empty ( $ is_sfw ) ){
142
-
143
- $ sfw = new CleantalkSFW ($ key );
144
- $ result = $ sfw ->send_logs ();
145
-
146
- if ( ! empty ( $ result ['error ' ] ) )
147
- COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_send_log_result ' , json_encode ( $ result ) );
148
- else
149
- COption::SetOptionInt ( 'cleantalk.antispam ' , 'sfw_last_send_log ' , time ());
150
-
151
- }else
152
- COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_send_log_result ' , json_encode ( array ( 'error ' => 'SFW_IS_DISABLED ' ) ) );
153
- }else
154
- COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_send_log_result ' , json_encode ( array ( 'error ' => 'NO_VALID_APIKEY_PROVIDED ' ) ) );
134
+
135
+ $ is_sfw = COption::GetOptionInt ( 'cleantalk.antispam ' , 'form_sfw ' , 0 );
136
+ $ key = $ key ? $ key : COption::GetOptionString ( 'cleantalk.antispam ' , 'key ' , '' );
137
+ $ key_is_ok = COption::GetOptionInt ( 'cleantalk.antispam ' , 'key_is_ok ' , 0 );
138
+
139
+ if ( ! empty ( $ key ) && ! empty ( $ key_is_ok ) ){
140
+
141
+ if ( ! empty ( $ is_sfw ) ){
142
+
143
+ $ sfw = new CleantalkSFW ($ key );
144
+ $ result = $ sfw ->send_logs ();
145
+
146
+ if ( ! empty ( $ result ['error ' ] ) )
147
+ COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_send_log_result ' , json_encode ( $ result ) );
148
+ else
149
+ COption::SetOptionInt ( 'cleantalk.antispam ' , 'sfw_last_send_log ' , time ());
150
+
151
+ }else
152
+ COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_send_log_result ' , json_encode ( array ( 'error ' => 'SFW_IS_DISABLED ' ) ) );
153
+ }else
154
+ COption::SetOptionString ( 'cleantalk.antispam ' , 'sfw_send_log_result ' , json_encode ( array ( 'error ' => 'NO_VALID_APIKEY_PROVIDED ' ) ) );
155
155
156
156
return 'CleantalkAntispam::sfw_send_logs(); ' ;
157
157
}
@@ -215,18 +215,18 @@ public function OnPageStartHandler()
215
215
$ sfw_last_update = COption::GetOptionInt ( 'cleantalk.antispam ' , 'sfw_last_update ' , 0 );
216
216
$ sfw_last_send_log = COption::GetOptionInt ( 'cleantalk.antispam ' , 'sfw_last_send_log ' , 0 );
217
217
$ new_checked = time ();
218
-
218
+
219
219
// Don't take any actions if module is disabled
220
- if ( ! $ ct_status )
221
- return ;
222
-
220
+ if ( ! $ ct_status )
221
+ return ;
222
+
223
223
// Remote calls
224
224
if (isset ( $ _GET ['spbc_remote_call_token ' ], $ _GET ['spbc_remote_call_action ' ], $ _GET ['plugin_name ' ]) && in_array ($ _GET ['plugin_name ' ], array ('antispam ' ,'anti-spam ' , 'apbct ' ))){
225
225
self ::apbct_remote_call__perform ();
226
226
}
227
227
228
- if ( ! $ USER ->IsAdmin () ){
229
-
228
+ if ( ! $ USER ->IsAdmin () ){
229
+
230
230
// Set cookies
231
231
if ( ! headers_sent () )
232
232
self ::ct_cookie ();
@@ -236,8 +236,8 @@ public function OnPageStartHandler()
236
236
$ sfw = new CleantalkSFW ($ ct_key );
237
237
$ sfw ->check_ip ();
238
238
}
239
-
240
- // Global check
239
+
240
+ // Global check
241
241
if ($ ct_status == 1 && $ ct_global == 1 ) {
242
242
// Exclusions
243
243
if ( empty ($ _POST ) ||
@@ -633,6 +633,7 @@ function OnBeforePrmediaCommentAddHandler(&$arFields) {
633
633
*/
634
634
function OnBeforeCommentAddHandler (&$ arFields ) {
635
635
global $ APPLICATION , $ USER ;
636
+
636
637
$ ct_status = COption::GetOptionInt ('cleantalk.antispam ' , 'status ' , 0 );
637
638
$ ct_comment_blog = COption::GetOptionInt ('cleantalk.antispam ' , 'form_comment_blog ' , 0 );
638
639
if ($ ct_status == 1 && $ ct_comment_blog == 1 ) {
@@ -651,7 +652,13 @@ function OnBeforeCommentAddHandler(&$arFields) {
651
652
}
652
653
$ aComment ['sender_email ' ] = $ USER ->GetEmail ();
653
654
} else {
654
- $ aComment ['sender_email ' ] = isset ($ arFields ['EMAIL ' ]) ? $ arFields ['EMAIL ' ] : '' ;
655
+ if (isset ($ arFields ['EMAIL ' ])) {
656
+ $ aComment ['sender_email ' ] = $ arFields ['EMAIL ' ];
657
+ } elseif (isset ($ arFields ['AUTHOR_EMAIL ' ])) {
658
+ $ aComment ['sender_email ' ] = $ arFields ['AUTHOR_EMAIL ' ];
659
+ } else {
660
+ $ aComment ['sender_email ' ] = '' ;
661
+ }
655
662
}
656
663
657
664
@@ -660,24 +667,24 @@ function OnBeforeCommentAddHandler(&$arFields) {
660
667
$ aComment ['subject ' ] = '' ;
661
668
$ aComment ['message ' ] = isset ($ arFields ['POST_TEXT ' ]) ? array ($ arFields ['POST_TEXT ' ]) : array ();
662
669
$ aComment ['example ' ] = array ();
663
-
664
- if (COption::GetOptionInt ('cleantalk.antispam ' , 'form_send_example ' , 0 ) == 1 ){
665
- $ arPost = CBlogPost::GetByID ($ arFields ['POST_ID ' ]);
666
- if (is_array ($ arPost )){
667
- $ aComment ['example ' ]['title ' ] = $ arPost ['TITLE ' ];
668
- $ aComment ['example ' ]['body ' ] = $ arPost ['DETAIL_TEXT ' ];
669
- // Find last 10 approved comments
670
- $ db_res = CBlogComment::GetList (
671
- array ('DATE_CREATE ' => 'DESC ' ),
672
- array ('POST_ID ' => $ arFields ['POST_ID ' ], 'PUBLISH_STATUS ' => BLOG_PUBLISH_STATUS_PUBLISH ),
673
- false ,
674
- array ('nTopCount ' => 10 ),
675
- array ('POST_TEXT ' )
676
- );
677
- while ($ ar_res = $ db_res ->Fetch ())
678
- $ aComment ['example ' ]['comments ' ] .= $ ar_res ['TITLE ' ] . "\n\n" . $ ar_res ['POST_TEXT ' ] . "\n\n" ;
679
- $ aComment ['example ' ]['comments ' ] = json_encode ($ aComment ['example ' ]['comments ' ]);
680
- }
670
+
671
+ if (COption::GetOptionInt ('cleantalk.antispam ' , 'form_send_example ' , 0 ) == 1 ){
672
+ $ arPost = CBlogPost::GetByID ($ arFields ['POST_ID ' ]);
673
+ if (is_array ($ arPost )){
674
+ $ aComment ['example ' ]['title ' ] = $ arPost ['TITLE ' ];
675
+ $ aComment ['example ' ]['body ' ] = $ arPost ['DETAIL_TEXT ' ];
676
+ // Find last 10 approved comments
677
+ $ db_res = CBlogComment::GetList (
678
+ array ('DATE_CREATE ' => 'DESC ' ),
679
+ array ('POST_ID ' => $ arFields ['POST_ID ' ], 'PUBLISH_STATUS ' => BLOG_PUBLISH_STATUS_PUBLISH ),
680
+ false ,
681
+ array ('nTopCount ' => 10 ),
682
+ array ('POST_TEXT ' )
683
+ );
684
+ while ($ ar_res = $ db_res ->Fetch ())
685
+ $ aComment ['example ' ]['comments ' ] .= $ ar_res ['TITLE ' ] . "\n\n" . $ ar_res ['POST_TEXT ' ] . "\n\n" ;
686
+ $ aComment ['example ' ]['comments ' ] = json_encode ($ aComment ['example ' ]['comments ' ]);
687
+ }
681
688
}
682
689
683
690
$ aResult = self ::CheckAllBefore ($ aComment , TRUE );
@@ -1370,8 +1377,10 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE, $form_errors = n
1370
1377
$ request_params ['message ' ] = $ arEntity ['message ' ];
1371
1378
$ request_params ['example ' ] = $ arEntity ['example ' ];
1372
1379
$ request_params ['post_info ' ]['comment_type ' ] = 'comment ' ;
1380
+
1373
1381
$ ct_request = new CleantalkRequest ($ request_params );
1374
1382
$ ct_result = $ ct ->isAllowMessage ($ ct_request );
1383
+
1375
1384
break ;
1376
1385
1377
1386
case 'order ' :
@@ -1436,6 +1445,7 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE, $form_errors = n
1436
1445
$ ct_request = new CleantalkRequest ($ request_params );
1437
1446
$ ct_result = $ ct ->isAllowMessage ($ ct_request );
1438
1447
}
1448
+
1439
1449
$ ret_val = array ();
1440
1450
$ ret_val ['ct_request_id ' ] = $ ct_result ->id ;
1441
1451
@@ -1860,7 +1870,7 @@ private static function ct_cookies_test()
1860
1870
private static function apbct_remote_call__perform ()
1861
1871
{
1862
1872
$ remote_calls_config = json_decode (COption::GetOptionString ('cleantalk.antispam ' ,'remote_calls ' , '' ),true );
1863
-
1873
+
1864
1874
$ remote_action = $ _GET ['spbc_remote_call_action ' ];
1865
1875
$ auth_key = trim (COption::GetOptionString ('cleantalk.antispam ' , 'key ' , '' ));
1866
1876
0 commit comments