Spam protection, AntiSpam, FireWall by CleanTalk - Version 2.4.15

Version Description

2013-09-26 = * Fixed: Bug with mass comments deletion * Changed: Russian localization for admin panel * Tested with mulitsite setup (WordPress network or WPMU)

Download this release

Release Info

Developer shagimuratov
Plugin Icon 128x128 Spam protection, AntiSpam, FireWall by CleanTalk
Version 2.4.15
Comparing to
See all releases

Code changes from version 2.4.14 to 2.4.15

Files changed (4) hide show
  1. cleantalk.class.php +897 -857
  2. cleantalk.php +3 -12
  3. i18n/cleantalk-ru_RU.mo +0 -0
  4. readme.txt +26 -5
cleantalk.class.php CHANGED
@@ -1,857 +1,897 @@
1
- <?php
2
- /**
3
- * Cleantalk base class
4
- *
5
- * @version 0.20.2
6
- * @package Cleantalk
7
- * @subpackage Base
8
- * @author Сleantalk team (welcome@cleantalk.ru)
9
- * @copyright (C) 2013 СleanTalk team (http://cleantalk.org)
10
- * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
11
- * @see http://cleantalk.ru/wiki/doku.php/api
12
- *
13
- */
14
-
15
- /**
16
- * @ignore
17
- */
18
- require_once(dirname(__FILE__) . '/cleantalk.xmlrpc.php');
19
-
20
- /**
21
- * Response class
22
- */
23
- class CleantalkResponse {
24
-
25
- /**
26
- * Unique user ID
27
- * @var string
28
- */
29
- public $sender_id = null;
30
-
31
- /**
32
- * Is stop words
33
- * @var int
34
- */
35
- public $stop_words = null;
36
-
37
- /**
38
- * Cleantalk comment
39
- * @var string
40
- */
41
- public $comment = null;
42
-
43
- /**
44
- * Is blacklisted
45
- * @var int
46
- */
47
- public $blacklisted = null;
48
-
49
- /**
50
- * Is allow, 1|0
51
- * @var int
52
- */
53
- public $allow = null;
54
-
55
- /**
56
- * Request ID
57
- * @var int
58
- */
59
- public $id = null;
60
-
61
- /**
62
- * Request errno
63
- * @var int
64
- */
65
- public $errno = null;
66
-
67
- /**
68
- * Error string
69
- * @var string
70
- */
71
- public $errstr = null;
72
-
73
- /**
74
- * Is fast submit, 1|0
75
- * @var string
76
- */
77
- public $fast_submit = null;
78
-
79
- /**
80
- * Is spam comment
81
- * @var string
82
- */
83
- public $spam = null;
84
-
85
- /**
86
- * Is JS
87
- * @var type
88
- */
89
- public $js_disabled = null;
90
-
91
- /**
92
- * Sms check
93
- * @var type
94
- */
95
- public $sms_allow = null;
96
-
97
- /**
98
- * Sms code result
99
- * @var type
100
- */
101
- public $sms = null;
102
-
103
- /**
104
- * Sms error code
105
- * @var type
106
- */
107
- public $sms_error_code = null;
108
-
109
- /**
110
- * Sms error code
111
- * @var type
112
- */
113
- public $sms_error_text = null;
114
-
115
- /**
116
- * Stop queue message, 1|0
117
- * @var int
118
- */
119
- public $stop_queue = null;
120
-
121
- /**
122
- * Account shuld by deactivated after registration, 1|0
123
- * @var int
124
- */
125
- public $inactive = null;
126
-
127
- /**
128
- * Create server response
129
- *
130
- * @param type $response
131
- * @param xmlrpcresp $obj
132
- */
133
- function __construct($response = null, xmlrpcresp $obj = null) {
134
- if ($response && is_array($response) && count($response) > 0) {
135
- foreach ($response as $param => $value) {
136
- $this->{$param} = $value;
137
- }
138
- } else {
139
- $this->errno = $obj->errno;
140
- $this->errstr = $obj->errstr;
141
-
142
- $this->errstr = preg_replace("/.+(\*\*\*.+\*\*\*).+/", "$1", $this->errstr);
143
-
144
- // Разбираем xmlrpcresp ответ с клинтолка
145
- if ($obj->val !== 0) {
146
- $this->sender_id = (isset($obj->val['sender_id'])) ? $obj->val['sender_id'] : null;
147
- $this->stop_words = isset($obj->val['stop_words']) ? $obj->val['stop_words'] : null;
148
- $this->comment = $obj->val['comment'];
149
- $this->blacklisted = (isset($obj->val['blacklisted'])) ? $obj->val['blacklisted'] : null;
150
- $this->allow = (isset($obj->val['allow'])) ? $obj->val['allow'] : null;
151
- $this->id = (isset($obj->val['id'])) ? $obj->val['id'] : null;
152
- $this->fast_submit = (isset($obj->val['fast_submit'])) ? $obj->val['fast_submit'] : 0;
153
- $this->spam = (isset($obj->val['spam'])) ? $obj->val['spam'] : 0;
154
- $this->js_disabled = (isset($obj->val['js_disabled'])) ? $obj->val['js_disabled'] : 0;
155
- $this->sms_allow = (isset($obj->val['sms_allow'])) ? $obj->val['sms_allow'] : null;
156
- $this->sms = (isset($obj->val['sms'])) ? $obj->val['sms'] : null;
157
- $this->sms_error_code = (isset($obj->val['sms_error_code'])) ? $obj->val['sms_error_code'] : null;
158
- $this->sms_error_text = (isset($obj->val['sms_error_text'])) ? $obj->val['sms_error_text'] : null;
159
- $this->stop_queue = (isset($obj->val['stop_queue'])) ? $obj->val['stop_queue'] : 0;
160
- $this->inactive = (isset($obj->val['inactive'])) ? $obj->val['inactive'] : 0;
161
- } else {
162
- $this->comment = $this->errstr . '. Automoderator cleantalk.org';
163
- }
164
- }
165
- }
166
-
167
- }
168
-
169
- /**
170
- * Request class
171
- */
172
- class CleantalkRequest {
173
-
174
- const VERSION = '0.7';
175
-
176
- /**
177
- * User message
178
- * @var string
179
- */
180
- public $message = null;
181
-
182
- /**
183
- * Post example with last comments
184
- * @var string
185
- */
186
- public $example = null;
187
-
188
- /**
189
- * Auth key
190
- * @var string
191
- */
192
- public $auth_key = null;
193
-
194
- /**
195
- * Engine
196
- * @var string
197
- */
198
- public $agent = null;
199
-
200
- /**
201
- * Is check for stoplist,
202
- * valid are 0|1
203
- * @var int
204
- */
205
- public $stoplist_check = null;
206
-
207
- /**
208
- * Language server response,
209
- * valid are 'en' or 'ru'
210
- * @var string
211
- */
212
- public $response_lang = null;
213
-
214
- /**
215
- * User IP
216
- * @var strings
217
- */
218
- public $sender_ip = null;
219
-
220
- /**
221
- * User email
222
- * @var strings
223
- */
224
- public $sender_email = null;
225
-
226
- /**
227
- * User nickname
228
- * @var string
229
- */
230
- public $sender_nickname = null;
231
-
232
- /**
233
- * Sender info JSON string
234
- * @var string
235
- */
236
- public $sender_info = null;
237
-
238
- /**
239
- * Post info JSON string
240
- * @var string
241
- */
242
- public $post_info = null;
243
-
244
- /**
245
- * Is allow links, email and icq,
246
- * valid are 1|0
247
- * @var int
248
- */
249
- public $allow_links = 0;
250
-
251
- /**
252
- * Time form filling
253
- * @var int
254
- */
255
- public $submit_time = null;
256
-
257
- /**
258
- * Is enable Java Script,
259
- * valid are 0|1|2
260
- * Status:
261
- * null - JS html code not inserted into phpBB templates
262
- * 0 - JS disabled at the client browser
263
- * 1 - JS enabled at the client broswer
264
- * @var int
265
- */
266
- public $js_on = null;
267
-
268
- /**
269
- * user time zone
270
- * @var string
271
- */
272
- public $tz = null;
273
-
274
- /**
275
- * Feedback string,
276
- * valid are 'requset_id:(1|0)'
277
- * @var string
278
- */
279
- public $feedback = null;
280
-
281
- /**
282
- * Phone number
283
- * @var type
284
- */
285
- public $phone = null;
286
-
287
- /**
288
- * Fill params with constructor
289
- * @param type $params
290
- */
291
- public function __construct($params = null) {
292
- if (is_array($params) && count($params) > 0) {
293
- foreach ($params as $param => $value) {
294
- $this->{$param} = $value;
295
- }
296
- }
297
- }
298
-
299
- }
300
-
301
- /**
302
- * Cleantalk class create request
303
- */
304
- class Cleantalk {
305
-
306
- /**
307
- * Debug level
308
- * @var int
309
- */
310
- public $debug = 0;
311
-
312
- /**
313
- * Maximum data size in bytes
314
- * @var int
315
- */
316
- private $dataMaxSise = 32768;
317
-
318
- /**
319
- * Data compression rate
320
- * @var int
321
- */
322
- private $compressRate = 6;
323
-
324
- /**
325
- * Server connection timeout in seconds
326
- * @var int
327
- */
328
- private $server_timeout = 2;
329
-
330
- /**
331
- * Cleantalk server url
332
- * @var string
333
- */
334
- public $server_url = null;
335
-
336
- /**
337
- * Last work url
338
- * @var string
339
- */
340
- public $work_url = null;
341
-
342
- /**
343
- * WOrk url ttl
344
- * @var int
345
- */
346
- public $server_ttl = null;
347
-
348
- /**
349
- * Time wotk_url changer
350
- * @var int
351
- */
352
- public $server_changed = null;
353
-
354
- /**
355
- * Flag is change server url
356
- * @var bool
357
- */
358
- public $server_change = false;
359
-
360
- /**
361
- * Use TRUE when need stay on server. Example: send feedback
362
- * @var bool
363
- */
364
- public $stay_on_server = false;
365
-
366
- /**
367
- * Function checks whether it is possible to publish the message
368
- * @param CleantalkRequest $request
369
- * @return type
370
- */
371
- public function isAllowMessage(CleantalkRequest $request) {
372
- $error_params = $this->filterRequest('check_message', $request);
373
-
374
- if (!empty($error_params)) {
375
- $response = new CleantalkResponse(
376
- array(
377
- 'allow' => 0,
378
- 'comment' => 'CleanTalk. Request params error: ' . implode(', ', $error_params)
379
- ), null);
380
-
381
- return $response;
382
- }
383
-
384
- $msg = $this->createMsg('check_message', $request);
385
- return $this->xmlRequest($msg);
386
- }
387
-
388
- /**
389
- * Function checks whether it is possible to publish the message
390
- * @param CleantalkRequest $request
391
- * @return type
392
- */
393
- public function isAllowUser(CleantalkRequest $request) {
394
- $error_params = $this->filterRequest('check_newuser', $request);
395
-
396
- if (!empty($error_params)) {
397
- $response = new CleantalkResponse(
398
- array(
399
- 'allow' => 0,
400
- 'comment' => 'CleanTalk. Request params error: ' . implode(', ', $error_params)
401
- ), null);
402
-
403
- return $response;
404
- }
405
-
406
- $msg = $this->createMsg('check_newuser', $request);
407
- return $this->xmlRequest($msg);
408
- }
409
-
410
- /**
411
- * Function sends the results of manual moderation
412
- *
413
- * @param CleantalkRequest $request
414
- * @return type
415
- */
416
- public function sendFeedback(CleantalkRequest $request) {
417
- $error_params = $this->filterRequest('send_feedback', $request);
418
-
419
- if (!empty($error_params)) {
420
- $response = new CleantalkResponse(
421
- array(
422
- 'allow' => 0,
423
- 'comment' => 'Cleantalk. Spam protect. Request params error: ' . implode(', ', $error_params)
424
- ), null);
425
-
426
- return $response;
427
- }
428
-
429
- $msg = $this->createMsg('send_feedback', $request);
430
- return $this->xmlRequest($msg);
431
- }
432
-
433
- /**
434
- * Filter request params
435
- * @param CleantalkRequest $request
436
- * @return type
437
- */
438
- private function filterRequest($method, CleantalkRequest $request) {
439
- $error_params = array();
440
-
441
- // general and optional
442
- foreach ($request as $param => $value) {
443
- if (in_array($param, array('message', 'example', 'agent',
444
- 'sender_info', 'sender_nickname', 'post_info', 'phone')) && !empty($value)) {
445
- if (!is_string($value) && !is_integer($value)) {
446
- $error_params[] = $param;
447
- }
448
- }
449
-
450
- if (in_array($param, array('stoplist_check', 'allow_links')) && !empty($value)) {
451
- if (!in_array($value, array(1, 2))) {
452
- $error_params[] = $param;
453
- }
454
- }
455
-
456
- if (in_array($param, array('js_on')) && !empty($value)) {
457
- if (!is_integer($value)) {
458
- $error_params[] = $param;
459
- }
460
- }
461
-
462
- if ($param == 'sender_ip' && !empty($value)) {
463
- if (!is_string($value)) {
464
- $error_params[] = $param;
465
- }
466
- }
467
-
468
- if ($param == 'sender_email' && !empty($value)) {
469
- if (!is_string($value)) {
470
- $error_params[] = $param;
471
- }
472
- }
473
-
474
- if ($param == 'submit_time' && !empty($value)) {
475
- if (!is_int($value)) {
476
- $error_params[] = $param;
477
- }
478
- }
479
- }
480
-
481
- // special and must be
482
- switch ($method) {
483
- case 'check_message':
484
-
485
- // Convert strings to UTF8
486
- $this->message = $this->stringToUTF8($request->message);
487
- $this->example = $this->stringToUTF8($request->example);
488
-
489
- $request->message = $this->compressData($request->message);
490
- $request->example = $this->compressData($request->example);
491
- break;
492
-
493
- case 'check_newuser':
494
- if (empty($request->sender_nickname)) {
495
- $error_params[] = 'sender_nickname';
496
- }
497
- if (empty($request->sender_email)) {
498
- $error_params[] = 'sender_email';
499
- }
500
- break;
501
-
502
- case 'send_feedback':
503
- if (empty($request->feedback)) {
504
- $error_params[] = 'feedback';
505
- }
506
- break;
507
- }
508
-
509
- if (isset($request->sender_info)) {
510
- if (function_exists('json_decode')){
511
- $sender_info = json_decode($request->sender_info, true);
512
-
513
- // Save request's creation timestamps
514
- if (function_exists('microtime'))
515
- $sender_info['request_submit_time'] = (float) (time() + (float) microtime());
516
-
517
- if (function_exists('json_encode')){
518
- $request->sender_info = json_encode($sender_info);
519
-
520
- }
521
- }
522
- }
523
-
524
- return $error_params;
525
- }
526
-
527
- /**
528
- * Compress data and encode to base64
529
- * @param type string
530
- * @return string
531
- */
532
- private function compressData($data = null){
533
-
534
- if (strlen($data) > $this->dataMaxSise && function_exists('gzencode') && function_exists('base64_encode')){
535
-
536
- $localData = gzencode($data, $this->compressRate, FORCE_GZIP);
537
-
538
- if ($localData === false)
539
- return $data;
540
-
541
- $localData = base64_encode($localData);
542
-
543
- if ($localData === false)
544
- return $data;
545
-
546
- return $localData;
547
- }
548
-
549
- return $data;
550
- }
551
-
552
- /**
553
- * Create msg for cleantalk server
554
- * @param type $method
555
- * @param CleantalkRequest $request
556
- * @return \xmlrpcmsg
557
- */
558
- private function createMsg($method, CleantalkRequest $request) {
559
- switch ($method) {
560
- case 'check_message':
561
- $params = array(
562
- 'message' => $request->message,
563
- 'base_text' => $request->example,
564
- 'auth_key' => $request->auth_key,
565
- 'agent' => $request->agent,
566
- 'sender_info' => $request->sender_info,
567
- 'ct_stop_words' => $request->stoplist_check,
568
- 'response_lang' => $request->response_lang,
569
- 'session_ip' => $request->sender_ip,
570
- 'user_email' => $request->sender_email,
571
- 'user_name' => $request->sender_nickname,
572
- 'post_info' => $request->post_info,
573
- 'ct_links' => $request->allow_links,
574
- 'submit_time' => $request->submit_time,
575
- 'js_on' => $request->js_on);
576
- break;
577
-
578
- case 'check_newuser':
579
- $params = array(
580
- 'auth_key' => $request->auth_key,
581
- 'agent' => $request->agent,
582
- 'response_lang' => $request->response_lang,
583
- 'session_ip' => $request->sender_ip,
584
- 'user_email' => $request->sender_email,
585
- 'user_name' => $request->sender_nickname,
586
- 'tz' => $request->tz,
587
- 'submit_time' => $request->submit_time,
588
- 'js_on' => $request->js_on,
589
- 'phone' => $request->phone,
590
- 'sender_info' => $request->sender_info);
591
- break;
592
-
593
- case 'send_feedback':
594
- if (is_array($request->feedback)) {
595
- $feedback = implode(';', $request->feedback);
596
- } else {
597
- $feedback = $request->feedback;
598
- }
599
-
600
- $params = array(
601
- 'auth_key' => $request->auth_key, // !
602
- 'feedback' => $feedback);
603
- break;
604
- }
605
-
606
- $xmlvars = array();
607
- foreach ($params as $param) {
608
- $xmlvars[] = new xmlrpcval($param);
609
- }
610
-
611
- $ct_params = new xmlrpcmsg(
612
- $method,
613
- array(new xmlrpcval($xmlvars, "array"))
614
- );
615
-
616
- return $ct_params;
617
- }
618
-
619
- /**
620
- * XM-Request
621
- * @param xmlrpcmsg $msg
622
- * @return boolean|\CleantalkResponse
623
- */
624
- private function xmlRequest(xmlrpcmsg $msg) {
625
- if (((isset($this->work_url) && $this->work_url !== '') && ($this->server_changed + $this->server_ttl > time()))
626
- || $this->stay_on_server == true) {
627
-
628
- $url = (!empty($this->work_url)) ? $this->work_url : $this->server_url;
629
- $ct_request = new xmlrpc_client($url);
630
- $ct_request->request_charset_encoding = 'utf-8';
631
- $ct_request->return_type = 'phpvals';
632
- $ct_request->setDebug($this->debug);
633
-
634
- $result = $ct_request->send($msg, $this->server_timeout);
635
- }
636
-
637
- if ((!isset($result) || $result->errno != 0) && $this->stay_on_server == false) {
638
- $matches = array();
639
- preg_match("#^(http://|https://)([a-z\.\-0-9]+):?(\d*)$#i", $this->server_url, $matches);
640
- $url_prefix = $matches[1];
641
- $pool = $matches[2];
642
- $port = $matches[3];
643
- if (empty($url_prefix))
644
- $url_prefix = 'http://';
645
- if (empty($pool)) {
646
- return false;
647
- } else {
648
- foreach ($this->get_servers_ip($pool) as $server) {
649
- if ($server['host'] === 'localhost' || $server['ip'] === null) {
650
- $work_url = $url_prefix . $server['host'];
651
- } else {
652
- $server_host = gethostbyaddr($server['ip']);
653
- $work_url = $url_prefix . $server_host;
654
- }
655
-
656
- $work_url = ($port !== '') ? $work_url . ':' . $port : $work_url;
657
-
658
- $this->work_url = $work_url;
659
- $this->server_ttl = $server['ttl'];
660
- $ct_request = new xmlrpc_client($this->work_url);
661
- $ct_request->request_charset_encoding = 'utf-8';
662
- $ct_request->return_type = 'phpvals';
663
- $ct_request->setDebug($this->debug);
664
- $result = $ct_request->send($msg, $this->server_timeout);
665
-
666
- if (!$result->faultCode()) {
667
- $this->server_change = true;
668
- break;
669
- }
670
- }
671
- }
672
- }
673
-
674
- $response = new CleantalkResponse(null, $result);
675
-
676
- if (!empty($response->sender_id)) {
677
- $this->setSenderId($response->sender_id);
678
- }
679
- return $response;
680
- }
681
-
682
- /**
683
- * Function DNS request
684
- * @param $host
685
- * @return array
686
- */
687
- public function get_servers_ip($host) {
688
- $response = null;
689
- if (!isset($host))
690
- return $response;
691
-
692
- if (function_exists('dns_get_record')) {
693
- $records = dns_get_record($host, DNS_A);
694
-
695
- if ($records !== FALSE) {
696
- foreach ($records as $server) {
697
- $response[] = $server;
698
- }
699
- }
700
- }
701
-
702
- if (count($response) == 0 && function_exists('gethostbynamel')) {
703
- $records = gethostbynamel($host);
704
-
705
- if ($records !== FALSE) {
706
- foreach ($records as $server) {
707
- $response[] = array("ip" => $server,
708
- "host" => $host,
709
- "ttl" => $this->server_ttl
710
- );
711
- }
712
- }
713
- }
714
-
715
- if (count($response) == 0) {
716
- $response[] = array("ip" => null,
717
- "host" => $host,
718
- "ttl" => $this->server_ttl
719
- );
720
- } else {
721
-
722
- // $i - to resolve collisions with localhost and
723
- $i = 0;
724
- $r_temp = null;
725
- foreach ($response as $server) {
726
- $ping = $this->httpPing($server['ip']);
727
-
728
- // -1 server is down, skips not reachable server
729
- if ($ping != -1)
730
- $r_temp[$ping * 10000 + $i] = $server;
731
-
732
- $i++;
733
- }
734
- if (count($r_temp)){
735
- ksort($r_temp);
736
- $response = $r_temp;
737
- }
738
- }
739
-
740
- return $response;
741
- }
742
-
743
- /**
744
- * Function to get the SenderID
745
- * @return string
746
- */
747
- public function getSenderId() {
748
- return ( isset($_COOKIE['ct_sender_id']) && !empty($_COOKIE['ct_sender_id']) ) ? $_COOKIE['ct_sender_id'] : '';
749
- }
750
-
751
- /**
752
- * Function to change the SenderID
753
- * @param $senderId
754
- * @return bool
755
- */
756
- private function setSenderId($senderId) {
757
- return @setcookie('ct_sender_id', $senderId);
758
- }
759
-
760
- /**
761
- * Function to get the message hash from Cleantalk.ru comment
762
- * @param $message
763
- * @return null
764
- */
765
- public function getCleantalkCommentHash($message) {
766
- $matches = array();
767
- if (preg_match('/\n\n\*\*\*.+([a-z0-9]{32}).+\*\*\*$/', $message, $matches))
768
- return $matches[1];
769
- else if (preg_match('/\<br.*\>[\n]{0,1}\<br.*\>[\n]{0,1}\*\*\*.+([a-z0-9]{32}).+\*\*\*$/', $message, $matches))
770
- return $matches[1];
771
-
772
- return NULL;
773
- }
774
-
775
- /**
776
- * Function adds to the post comment Cleantalk.ru
777
- * @param $message
778
- * @param $comment
779
- * @return string
780
- */
781
- public function addCleantalkComment($message, $comment) {
782
- $comment = preg_match('/\*\*\*(.+)\*\*\*/', $comment, $matches) ? $comment : '*** ' . $comment . ' ***';
783
- return $message . "\n\n" . $comment;
784
- }
785
-
786
- /**
787
- * Function deletes the comment Cleantalk.ru
788
- * @param $message
789
- * @return mixed
790
- */
791
- public function delCleantalkComment($message) {
792
- $message = preg_replace('/\n\n\*\*\*.+\*\*\*$/', '', $message);
793
- $message = preg_replace('/\<br.*\>[\n]{0,1}\<br.*\>[\n]{0,1}\*\*\*.+\*\*\*$/', '', $message);
794
- return $message;
795
- }
796
-
797
- /*
798
- Get user IP
799
- */
800
- public function ct_session_ip( $data_ip )
801
- {
802
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
803
- {
804
- $forwarded_for = (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? htmlentities($_SERVER['HTTP_X_FORWARDED_FOR']) : '';
805
- }
806
-
807
- // 127.0.0.1 usually used at reverse proxy
808
- $session_ip = ($data_ip == '127.0.0.1' && !empty($forwarded_for)) ? $forwarded_for : $data_ip;
809
-
810
- return $session_ip;
811
- }
812
-
813
- /**
814
- * Function to check response time
815
- * param string
816
- * @return int
817
- */
818
- function httpPing($host){
819
-
820
- // Skip localhost ping cause it raise error at fsockopen.
821
- // And return minimun value
822
- if ($host == 'localhost')
823
- return 0.001;
824
-
825
- $starttime = microtime(true);
826
- $file = @fsockopen ($host, 80, $errno, $errstr, $this->server_timeout);
827
- $stoptime = microtime(true);
828
- $status = 0;
829
-
830
- if (!$file) {
831
- $status = -1; // Site is down
832
- } else {
833
- fclose($file);
834
- $status = ($stoptime - $starttime);
835
- $status = round($status, 4);
836
- }
837
-
838
- return $status;
839
- }
840
-
841
- /**
842
- * Function convert string to UTF8 and removes non UTF8 characters
843
- * param string
844
- * @return string
845
- */
846
- function stringToUTF8($str){
847
-
848
- if (!preg_match('//u', $str) && function_exists('mb_detect_encoding') && function_exists('mb_convert_encoding')) {
849
- $encoding = mb_detect_encoding($str);
850
- $srt = mb_convert_encoding($str, 'UTF-8', $encoding);
851
- }
852
-
853
- return $str;
854
- }
855
- }
856
-
857
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Cleantalk base class
4
+ *
5
+ * @version 1.21.9
6
+ * @package Cleantalk
7
+ * @subpackage Base
8
+ * @author Сleantalk team (welcome@cleantalk.ru)
9
+ * @copyright (C) 2013 СleanTalk team (http://cleantalk.org)
10
+ * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
11
+ * @see http://cleantalk.ru/wiki/doku.php/api
12
+ *
13
+ */
14
+
15
+ /**
16
+ * Load JSON functions if they are not exists
17
+ */
18
+ if(!function_exists('json_encode')) {
19
+ require_once 'JSON.php';
20
+
21
+ function json_encode($data) {
22
+ $json = new Services_JSON();
23
+ return( $json->encode($data) );
24
+ }
25
+
26
+ }
27
+ if(!function_exists('json_decode')) {
28
+ require_once 'JSON.php';
29
+
30
+ function json_decode($data) {
31
+ $json = new Services_JSON();
32
+ return( $json->decode($data) );
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Response class
38
+ */
39
+ class CleantalkResponse {
40
+
41
+ /**
42
+ * Is stop words
43
+ * @var int
44
+ */
45
+ public $stop_words = null;
46
+
47
+ /**
48
+ * Cleantalk comment
49
+ * @var string
50
+ */
51
+ public $comment = null;
52
+
53
+ /**
54
+ * Is blacklisted
55
+ * @var int
56
+ */
57
+ public $blacklisted = null;
58
+
59
+ /**
60
+ * Is allow, 1|0
61
+ * @var int
62
+ */
63
+ public $allow = null;
64
+
65
+ /**
66
+ * Request ID
67
+ * @var int
68
+ */
69
+ public $id = null;
70
+
71
+ /**
72
+ * Request errno
73
+ * @var int
74
+ */
75
+ public $errno = null;
76
+
77
+ /**
78
+ * Error string
79
+ * @var string
80
+ */
81
+ public $errstr = null;
82
+
83
+ /**
84
+ * Is fast submit, 1|0
85
+ * @var string
86
+ */
87
+ public $fast_submit = null;
88
+
89
+ /**
90
+ * Is spam comment
91
+ * @var string
92
+ */
93
+ public $spam = null;
94
+
95
+ /**
96
+ * Is JS
97
+ * @var type
98
+ */
99
+ public $js_disabled = null;
100
+
101
+ /**
102
+ * Sms check
103
+ * @var type
104
+ */
105
+ public $sms_allow = null;
106
+
107
+ /**
108
+ * Sms code result
109
+ * @var type
110
+ */
111
+ public $sms = null;
112
+
113
+ /**
114
+ * Sms error code
115
+ * @var type
116
+ */
117
+ public $sms_error_code = null;
118
+
119
+ /**
120
+ * Sms error code
121
+ * @var type
122
+ */
123
+ public $sms_error_text = null;
124
+
125
+ /**
126
+ * Stop queue message, 1|0
127
+ * @var int
128
+ */
129
+ public $stop_queue = null;
130
+
131
+ /**
132
+ * Account shuld by deactivated after registration, 1|0
133
+ * @var int
134
+ */
135
+ public $inactive = null;
136
+
137
+ /**
138
+ * Create server response
139
+ *
140
+ * @param type $response
141
+ * @param type $obj
142
+ */
143
+ function __construct($response = null, $obj = null) {
144
+ if ($response && is_array($response) && count($response) > 0) {
145
+ foreach ($response as $param => $value) {
146
+ $this->{$param} = $value;
147
+ }
148
+ } else {
149
+ $this->errno = $obj->errno;
150
+ $this->errstr = $obj->errstr;
151
+
152
+ $this->errstr = preg_replace("/.+(\*\*\*.+\*\*\*).+/", "$1", $this->errstr);
153
+ // Разбираем ответ с клинтолка
154
+ $this->stop_words = isset($obj->stop_words) ? $obj->stop_words : null;
155
+ $this->comment = isset($obj->comment) ? utf8_decode($obj->comment) : null;
156
+ $this->blacklisted = (isset($obj->blacklisted)) ? $obj->blacklisted : null;
157
+ $this->allow = (isset($obj->allow)) ? $obj->allow : null;
158
+ $this->id = (isset($obj->id)) ? $obj->id : null;
159
+ $this->fast_submit = (isset($obj->fast_submit)) ? $obj->fast_submit : 0;
160
+ $this->spam = (isset($obj->spam)) ? $obj->spam : 0;
161
+ $this->js_disabled = (isset($obj->js_disabled)) ? $obj->js_disabled : 0;
162
+ $this->sms_allow = (isset($obj->sms_allow)) ? $obj->sms_allow : null;
163
+ $this->sms = (isset($obj->sms)) ? $obj->sms : null;
164
+ $this->sms_error_code = (isset($obj->sms_error_code)) ? $obj->sms_error_code : null;
165
+ $this->sms_error_text = (isset($obj->sms_error_text)) ? $obj->sms_error_text : null;
166
+ $this->stop_queue = (isset($obj->stop_queue)) ? $obj->stop_queue : 0;
167
+ $this->inactive = (isset($obj->inactive)) ? $obj->inactive : 0;
168
+
169
+ if ($this->errno !== 0 && $this->errstr !== null && $this->comment === null)
170
+ $this->comment = '*** ' . $this->errstr . ' Automoderator cleantalk.org ***';
171
+ }
172
+ }
173
+
174
+ }
175
+
176
+ /**
177
+ * Request class
178
+ */
179
+ class CleantalkRequest {
180
+
181
+ /**
182
+ * User message
183
+ * @var string
184
+ */
185
+ public $message = null;
186
+
187
+ /**
188
+ * Post example with last comments
189
+ * @var string
190
+ */
191
+ public $example = null;
192
+
193
+ /**
194
+ * Auth key
195
+ * @var string
196
+ */
197
+ public $auth_key = null;
198
+
199
+ /**
200
+ * Engine
201
+ * @var string
202
+ */
203
+ public $agent = null;
204
+
205
+ /**
206
+ * Is check for stoplist,
207
+ * valid are 0|1
208
+ * @var int
209
+ */
210
+ public $stoplist_check = null;
211
+
212
+ /**
213
+ * Language server response,
214
+ * valid are 'en' or 'ru'
215
+ * @var string
216
+ */
217
+ public $response_lang = null;
218
+
219
+ /**
220
+ * User IP
221
+ * @var strings
222
+ */
223
+ public $sender_ip = null;
224
+
225
+ /**
226
+ * User email
227
+ * @var strings
228
+ */
229
+ public $sender_email = null;
230
+
231
+ /**
232
+ * User nickname
233
+ * @var string
234
+ */
235
+ public $sender_nickname = null;
236
+
237
+ /**
238
+ * Sender info JSON string
239
+ * @var string
240
+ */
241
+ public $sender_info = null;
242
+
243
+ /**
244
+ * Post info JSON string
245
+ * @var string
246
+ */
247
+ public $post_info = null;
248
+
249
+ /**
250
+ * Is allow links, email and icq,
251
+ * valid are 1|0
252
+ * @var int
253
+ */
254
+ public $allow_links = null;
255
+
256
+ /**
257
+ * Time form filling
258
+ * @var int
259
+ */
260
+ public $submit_time = null;
261
+
262
+ /**
263
+ * Is enable Java Script,
264
+ * valid are 0|1|2
265
+ * Status:
266
+ * null - JS html code not inserted into phpBB templates
267
+ * 0 - JS disabled at the client browser
268
+ * 1 - JS enabled at the client broswer
269
+ * @var int
270
+ */
271
+ public $js_on = null;
272
+
273
+ /**
274
+ * user time zone
275
+ * @var string
276
+ */
277
+ public $tz = null;
278
+
279
+ /**
280
+ * Feedback string,
281
+ * valid are 'requset_id:(1|0)'
282
+ * @var string
283
+ */
284
+ public $feedback = null;
285
+
286
+ /**
287
+ * Phone number
288
+ * @var type
289
+ */
290
+ public $phone = null;
291
+
292
+ /**
293
+ * Method name
294
+ * @var string
295
+ */
296
+ public $method_name = 'check_message';
297
+
298
+ /**
299
+ * Fill params with constructor
300
+ * @param type $params
301
+ */
302
+ public function __construct($params = null) {
303
+ if (is_array($params) && count($params) > 0) {
304
+ foreach ($params as $param => $value) {
305
+ $this->{$param} = $value;
306
+ }
307
+ }
308
+ }
309
+
310
+ }
311
+
312
+ /**
313
+ * Cleantalk class create request
314
+ */
315
+ class Cleantalk {
316
+
317
+ /**
318
+ * Debug level
319
+ * @var int
320
+ */
321
+ public $debug = 0;
322
+
323
+ /**
324
+ * Maximum data size in bytes
325
+ * @var int
326
+ */
327
+ private $dataMaxSise = 32768;
328
+
329
+ /**
330
+ * Data compression rate
331
+ * @var int
332
+ */
333
+ private $compressRate = 6;
334
+
335
+ /**
336
+ * Server connection timeout in seconds
337
+ * @var int
338
+ */
339
+ private $server_timeout = 5;
340
+
341
+ /**
342
+ * Cleantalk server url
343
+ * @var string
344
+ */
345
+ public $server_url = null;
346
+
347
+ /**
348
+ * Last work url
349
+ * @var string
350
+ */
351
+ public $work_url = null;
352
+
353
+ /**
354
+ * WOrk url ttl
355
+ * @var int
356
+ */
357
+ public $server_ttl = null;
358
+
359
+ /**
360
+ * Time wotk_url changer
361
+ * @var int
362
+ */
363
+ public $server_changed = null;
364
+
365
+ /**
366
+ * Flag is change server url
367
+ * @var bool
368
+ */
369
+ public $server_change = false;
370
+
371
+ /**
372
+ * Use TRUE when need stay on server. Example: send feedback
373
+ * @var bool
374
+ */
375
+ public $stay_on_server = false;
376
+
377
+ /**
378
+ * Codepage of the data
379
+ * @var bool
380
+ */
381
+ public $data_codepage = null;
382
+
383
+ /**
384
+ * API version to use
385
+ * @var string
386
+ */
387
+ public $api_version = '/api2.0';
388
+
389
+ /**
390
+ * Function checks whether it is possible to publish the message
391
+ * @param CleantalkRequest $request
392
+ * @return type
393
+ */
394
+ public function isAllowMessage(CleantalkRequest $request) {
395
+ $error_params = $this->filterRequest('check_message', $request);
396
+
397
+ if (!empty($error_params)) {
398
+ $response = new CleantalkResponse(
399
+ array(
400
+ 'allow' => 0,
401
+ 'comment' => 'CleanTalk. Request params error: ' . implode(', ', $error_params)
402
+ ), null);
403
+
404
+ return $response;
405
+ }
406
+
407
+ $msg = $this->createMsg('check_message', $request);
408
+ return $this->httpRequest($msg);
409
+ }
410
+
411
+ /**
412
+ * Function checks whether it is possible to publish the message
413
+ * @param CleantalkRequest $request
414
+ * @return type
415
+ */
416
+ public function isAllowUser(CleantalkRequest $request) {
417
+ $error_params = $this->filterRequest('check_newuser', $request);
418
+
419
+ if (!empty($error_params)) {
420
+ $response = new CleantalkResponse(
421
+ array(
422
+ 'allow' => 0,
423
+ 'comment' => 'CleanTalk. Request params error: ' . implode(', ', $error_params)
424
+ ), null);
425
+
426
+ return $response;
427
+ }
428
+
429
+ $msg = $this->createMsg('check_newuser', $request);
430
+ return $this->httpRequest($msg);
431
+ }
432
+
433
+ /**
434
+ * Function sends the results of manual moderation
435
+ *
436
+ * @param CleantalkRequest $request
437
+ * @return type
438
+ */
439
+ public function sendFeedback(CleantalkRequest $request) {
440
+ $error_params = $this->filterRequest('send_feedback', $request);
441
+
442
+ if (!empty($error_params)) {
443
+ $response = new CleantalkResponse(
444
+ array(
445
+ 'allow' => 0,
446
+ 'comment' => 'Cleantalk. Spam protect. Request params error: ' . implode(', ', $error_params)
447
+ ), null);
448
+
449
+ return $response;
450
+ }
451
+
452
+ $msg = $this->createMsg('send_feedback', $request);
453
+
454
+ return $this->httpRequest($msg);
455
+ }
456
+
457
+ /**
458
+ * Filter request params
459
+ * @param CleantalkRequest $request
460
+ * @return type
461
+ */
462
+ private function filterRequest($method, CleantalkRequest $request) {
463
+ $error_params = array();
464
+
465
+ // general and optional
466
+ foreach ($request as $param => $value) {
467
+ if (in_array($param, array('message', 'example', 'agent',
468
+ 'sender_info', 'sender_nickname', 'post_info', 'phone')) && !empty($value)) {
469
+ if (!is_string($value) && !is_integer($value)) {
470
+ $error_params[] = $param;
471
+ }
472
+ }
473
+
474
+ if (in_array($param, array('stoplist_check', 'allow_links')) && !empty($value)) {
475
+ if (!in_array($value, array(1, 2))) {
476
+ $error_params[] = $param;
477
+ }
478
+ }
479
+
480
+ if (in_array($param, array('js_on')) && !empty($value)) {
481
+ if (!is_integer($value)) {
482
+ $error_params[] = $param;
483
+ }
484
+ }
485
+
486
+ if ($param == 'sender_ip' && !empty($value)) {
487
+ if (!is_string($value)) {
488
+ $error_params[] = $param;
489
+ }
490
+ }
491
+
492
+ if ($param == 'sender_email' && !empty($value)) {
493
+ if (!is_string($value)) {
494
+ $error_params[] = $param;
495
+ }
496
+ }
497
+
498
+ if ($param == 'submit_time' && !empty($value)) {
499
+ if (!is_int($value)) {
500
+ $error_params[] = $param;
501
+ }
502
+ }
503
+ }
504
+
505
+ // special and must be
506
+ switch ($method) {
507
+ case 'check_message':
508
+ break;
509
+
510
+ case 'check_newuser':
511
+ if (empty($request->sender_nickname)) {
512
+ $error_params[] = 'sender_nickname';
513
+ }
514
+ if (empty($request->sender_email)) {
515
+ $error_params[] = 'sender_email';
516
+ }
517
+ break;
518
+
519
+ case 'send_feedback':
520
+ if (empty($request->feedback)) {
521
+ $error_params[] = 'feedback';
522
+ }
523
+ break;
524
+ }
525
+
526
+ return $error_params;
527
+ }
528
+
529
+ /**
530
+ * Compress data and encode to base64
531
+ * @param type string
532
+ * @return string
533
+ */
534
+ private function compressData($data = null){
535
+
536
+ if (strlen($data) > $this->dataMaxSise && function_exists('gzencode') && function_exists('base64_encode')){
537
+
538
+ $localData = gzencode($data, $this->compressRate, FORCE_GZIP);
539
+
540
+ if ($localData === false)
541
+ return $data;
542
+
543
+ $localData = base64_encode($localData);
544
+
545
+ if ($localData === false)
546
+ return $data;
547
+
548
+ return $localData;
549
+ }
550
+
551
+ return $data;
552
+ }
553
+
554
+ /**
555
+ * Create msg for cleantalk server
556
+ * @param type $method
557
+ * @param CleantalkRequest $request
558
+ * @return \xmlrpcmsg
559
+ */
560
+ private function createMsg($method, CleantalkRequest $request) {
561
+ switch ($method) {
562
+ case 'check_message':
563
+ // Convert strings to UTF8
564
+ $request->message = $this->stringToUTF8($request->message, $this->data_codepage);
565
+ $request->example = $this->stringToUTF8($request->example, $this->data_codepage);
566
+ $request->sender_email = $this->stringToUTF8($request->sender_email, $this->data_codepage);
567
+ $request->sender_nickname = $this->stringToUTF8($request->sender_nickname, $this->data_codepage);
568
+
569
+ $request->message = $this->compressData($request->message);
570
+ $request->example = $this->compressData($request->example);
571
+ break;
572
+
573
+ case 'check_newuser':
574
+ // Convert strings to UTF8
575
+ $request->sender_email = $this->stringToUTF8($request->sender_email, $this->data_codepage);
576
+ $request->sender_nickname = $this->stringToUTF8($request->sender_nickname, $this->data_codepage);
577
+ break;
578
+
579
+ case 'send_feedback':
580
+ if (is_array($request->feedback)) {
581
+ $request->feedback = implode(';', $request->feedback);
582
+ }
583
+ break;
584
+ }
585
+
586
+ $request->method_name = $method;
587
+
588
+ return $request;
589
+ }
590
+
591
+ /**
592
+ * Send JSON request to servers
593
+ * @param $msg
594
+ * @return boolean|\CleantalkResponse
595
+ */
596
+ private function sendRequest($data = null, $url, $server_timeout = 3) {
597
+ // Convert to array
598
+ $data = json_decode(json_encode($data), true);
599
+
600
+ // Convert to JSON
601
+ $data = json_encode($data);
602
+
603
+ if (isset($this->api_version))
604
+ $url = $url . $this->api_version;
605
+
606
+ $result = false;
607
+ if(function_exists('curl_init')) {
608
+ $ch = curl_init();
609
+ curl_setopt($ch, CURLOPT_URL, $url);
610
+ curl_setopt($ch, CURLOPT_TIMEOUT, $server_timeout);
611
+ curl_setopt($ch, CURLOPT_POST, 1);
612
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
613
+ // receive server response ...
614
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
615
+
616
+ $result = curl_exec($ch);
617
+ curl_close($ch);
618
+ } else {
619
+ $allow_url_fopen = ini_get('allow_url_fopen');
620
+ if (function_exists('file_get_contents') && isset($allow_url_fopen) && $allow_url_fopen == '1') {
621
+ $opts = array('http' =>
622
+ array(
623
+ 'method' => 'POST',
624
+ 'header' => "Content-Type: text/html\r\n",
625
+ 'content' => $data,
626
+ 'timeout' => $server_timeout
627
+ )
628
+ );
629
+
630
+ $context = stream_context_create($opts);
631
+ $result = @file_get_contents($url, false, $context);
632
+ } else {
633
+ $response = null;
634
+ $response['errno'] = 1;
635
+ $response['errstr'] = 'No CURL support compiled in. Disabled allow_url_fopen in php.ini.';
636
+ $response = json_decode(json_encode($response));
637
+
638
+ return $response;
639
+ }
640
+ }
641
+
642
+ $errstr = null;
643
+ $response = json_decode($result);
644
+ if ($result !== false && is_object($response)) {
645
+ $response->errno = 0;
646
+ $response->errstr = $errstr;
647
+ } else {
648
+ if ($result === false)
649
+ $errstr = 'Failed connect to ' . $url . '.';
650
+ else
651
+ $errstr = $result;
652
+
653
+ $response = null;
654
+ $response['errno'] = 1;
655
+ $response['errstr'] = $errstr;
656
+ $response = json_decode(json_encode($response));
657
+ }
658
+
659
+ return $response;
660
+ }
661
+
662
+ /**
663
+ * httpRequest
664
+ * @param $msg
665
+ * @return boolean|\CleantalkResponse
666
+ */
667
+ private function httpRequest($msg) {
668
+ $result = false;
669
+ if (((isset($this->work_url) && $this->work_url !== '') && ($this->server_changed + $this->server_ttl > time()))
670
+ || $this->stay_on_server == true) {
671
+
672
+ $url = (!empty($this->work_url)) ? $this->work_url : $this->server_url;
673
+
674
+ $result = $this->sendRequest($msg, $url, $this->server_timeout);
675
+ }
676
+
677
+ if (($result === false || $result->errno != 0) && $this->stay_on_server == false) {
678
+
679
+ // Split server url to parts
680
+ preg_match("@^(https?://)([^/:]+)(.*)@i", $this->server_url, $matches);
681
+ $url_prefix = '';
682
+ if (isset($matches[1]))
683
+ $url_prefix = $matches[1];
684
+
685
+ $pool = null;
686
+ if (isset($matches[2]))
687
+ $pool = $matches[2];
688
+
689
+ $url_suffix = '';
690
+ if (isset($matches[3]))
691
+ $url_suffix = $matches[3];
692
+
693
+ if ($url_prefix === '')
694
+ $url_prefix = 'http://';
695
+
696
+ if (empty($pool)) {
697
+ return false;
698
+ } else {
699
+
700
+ // Loop until find work server
701
+ foreach ($this->get_servers_ip($pool) as $server) {
702
+ if ($server['host'] === 'localhost' || $server['ip'] === null) {
703
+ $work_url = $server['host'];
704
+ } else {
705
+ $server_host = gethostbyaddr($server['ip']);
706
+ $work_url = $server_host;
707
+ }
708
+ $work_url = $url_prefix . $work_url;
709
+ if (isset($url_suffix))
710
+ $work_url = $work_url . $url_suffix;
711
+
712
+ $this->work_url = $work_url;
713
+ $this->server_ttl = $server['ttl'];
714
+
715
+ $result = $this->sendRequest($msg, $this->work_url, $this->server_timeout);
716
+
717
+ if ($result !== false && $result->errno === 0) {
718
+ $this->server_change = true;
719
+ break;
720
+ }
721
+ }
722
+ }
723
+ }
724
+
725
+ $response = new CleantalkResponse(null, $result);
726
+
727
+ return $response;
728
+ }
729
+
730
+ /**
731
+ * Function DNS request
732
+ * @param $host
733
+ * @return array
734
+ */
735
+ public function get_servers_ip($host) {
736
+ $response = null;
737
+ if (!isset($host))
738
+ return $response;
739
+
740
+ if (function_exists('dns_get_record')) {
741
+ $records = dns_get_record($host, DNS_A);
742
+
743
+ if ($records !== FALSE) {
744
+ foreach ($records as $server) {
745
+ $response[] = $server;
746
+ }
747
+ }
748
+ }
749
+
750
+ if (count($response) == 0 && function_exists('gethostbynamel')) {
751
+ $records = gethostbynamel($host);
752
+
753
+ if ($records !== FALSE) {
754
+ foreach ($records as $server) {
755
+ $response[] = array("ip" => $server,
756
+ "host" => $host,
757
+ "ttl" => $this->server_ttl
758
+ );
759
+ }
760
+ }
761
+ }
762
+
763
+ if (count($response) == 0) {
764
+ $response[] = array("ip" => null,
765
+ "host" => $host,
766
+ "ttl" => $this->server_ttl
767
+ );
768
+ } else {
769
+
770
+ // $i - to resolve collisions with localhost and
771
+ $i = 0;
772
+ $r_temp = null;
773
+ foreach ($response as $server) {
774
+ $ping = $this->httpPing($server['ip']);
775
+
776
+ // -1 server is down, skips not reachable server
777
+ if ($ping != -1)
778
+ $r_temp[$ping * 10000 + $i] = $server;
779
+
780
+ $i++;
781
+ }
782
+ if (count($r_temp)){
783
+ ksort($r_temp);
784
+ $response = $r_temp;
785
+ }
786
+ }
787
+
788
+ return $response;
789
+ }
790
+
791
+ /**
792
+ * Function to get the message hash from Cleantalk.ru comment
793
+ * @param $message
794
+ * @return null
795
+ */
796
+ public function getCleantalkCommentHash($message) {
797
+ $matches = array();
798
+ if (preg_match('/\n\n\*\*\*.+([a-z0-9]{32}).+\*\*\*$/', $message, $matches))
799
+ return $matches[1];
800
+ else if (preg_match('/\<br.*\>[\n]{0,1}\<br.*\>[\n]{0,1}\*\*\*.+([a-z0-9]{32}).+\*\*\*$/', $message, $matches))
801
+ return $matches[1];
802
+
803
+ return NULL;
804
+ }
805
+
806
+ /**
807
+ * Function adds to the post comment Cleantalk.ru
808
+ * @param $message
809
+ * @param $comment
810
+ * @return string
811
+ */
812
+ public function addCleantalkComment($message, $comment) {
813
+ $comment = preg_match('/\*\*\*(.+)\*\*\*/', $comment, $matches) ? $comment : '*** ' . $comment . ' ***';
814
+ return $message . "\n\n" . $comment;
815
+ }
816
+
817
+ /**
818
+ * Function deletes the comment Cleantalk.ru
819
+ * @param $message
820
+ * @return mixed
821
+ */
822
+ public function delCleantalkComment($message) {
823
+ $message = preg_replace('/\n\n\*\*\*.+\*\*\*$/', '', $message);
824
+
825
+ // DLE sign cut
826
+ $message = preg_replace('/<br\s?\/><br\s?\/>\*\*\*.+\*\*\*$/', '', $message);
827
+
828
+ $message = preg_replace('/\<br.*\>[\n]{0,1}\<br.*\>[\n]{0,1}\*\*\*.+\*\*\*$/', '', $message);
829
+
830
+ return $message;
831
+ }
832
+
833
+ /*
834
+ Get user IP
835
+ */
836
+ public function ct_session_ip( $data_ip )
837
+ {
838
+ if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
839
+ {
840
+ $forwarded_for = (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? htmlentities($_SERVER['HTTP_X_FORWARDED_FOR']) : '';
841
+ }
842
+
843
+ // 127.0.0.1 usually used at reverse proxy
844
+ $session_ip = ($data_ip == '127.0.0.1' && !empty($forwarded_for)) ? $forwarded_for : $data_ip;
845
+
846
+ return $session_ip;
847
+ }
848
+
849
+ /**
850
+ * Function to check response time
851
+ * param string
852
+ * @return int
853
+ */
854
+ function httpPing($host){
855
+
856
+ // Skip localhost ping cause it raise error at fsockopen.
857
+ // And return minimun value
858
+ if ($host == 'localhost')
859
+ return 0.001;
860
+
861
+ $starttime = microtime(true);
862
+ $file = @fsockopen ($host, 80, $errno, $errstr, $this->server_timeout);
863
+ $stoptime = microtime(true);
864
+ $status = 0;
865
+
866
+ if (!$file) {
867
+ $status = -1; // Site is down
868
+ } else {
869
+ fclose($file);
870
+ $status = ($stoptime - $starttime);
871
+ $status = round($status, 4);
872
+ }
873
+
874
+ return $status;
875
+ }
876
+
877
+ /**
878
+ * Function convert string to UTF8 and removes non UTF8 characters
879
+ * param string
880
+ * param string
881
+ * @return string
882
+ */
883
+ function stringToUTF8($str, $data_codepage = null){
884
+ if (!preg_match('//u', $str) && function_exists('mb_detect_encoding') && function_exists('mb_convert_encoding')) {
885
+
886
+ if ($data_codepage !== null)
887
+ return mb_convert_encoding($str, 'UTF-8', $data_codepage);
888
+
889
+ $encoding = mb_detect_encoding($str);
890
+ return mb_convert_encoding($str, 'UTF-8', $encoding);
891
+ }
892
+
893
+ return $str;
894
+ }
895
+ }
896
+
897
+ ?>
cleantalk.php CHANGED
@@ -1,17 +1,16 @@
1
  <?php
2
  /*
3
- Plugin Name: CleanTalk. Cloud anti-spam
4
  Plugin URI: http://cleantalk.org/wordpress
5
  Description: It's cloud, invisible, smart antispam for your blog. The plugin doesn't use CAPTCHA, Q&A, math to stop spam bots.
6
- Version: 2.4.14
7
  Author: СleanTalk team <welcome@cleantalk.ru>
8
  Author URI: http://cleantalk.org
9
  */
10
 
11
- $ct_agent_version = 'wordpress-2414';
12
 
13
  add_action('init', 'ct_init_locale');
14
- add_action('delete_comment', 'ct_delete_comment_meta'); // param - comment ID
15
  add_action('comment_form', 'ct_add_hidden_fields');
16
  add_action('parse_request', 'ct_set_session');
17
  add_action('admin_notices', 'admin_notice_message');
@@ -160,14 +159,6 @@ function ct_init_locale() {
160
  }
161
  }
162
 
163
- /**
164
- * Public action 'delete_comment' - Deletes comment's meta before deleting comment
165
- * @param int $post_id Post ID, not used
166
- */
167
- function ct_delete_comment_meta($comment_id) {
168
- delete_comment_meta($comment_id, 'ct_hash');
169
- }
170
-
171
  /**
172
  * Public action 'comment_form' - Adds hidden filed to define avaialbility of client's JavaScript
173
  * @param int $post_id Post ID, not used
1
  <?php
2
  /*
3
+ Plugin Name: Anti-spam by CleanTalk
4
  Plugin URI: http://cleantalk.org/wordpress
5
  Description: It's cloud, invisible, smart antispam for your blog. The plugin doesn't use CAPTCHA, Q&A, math to stop spam bots.
6
+ Version: 2.4.15
7
  Author: СleanTalk team <welcome@cleantalk.ru>
8
  Author URI: http://cleantalk.org
9
  */
10
 
11
+ $ct_agent_version = 'wordpress-2415';
12
 
13
  add_action('init', 'ct_init_locale');
 
14
  add_action('comment_form', 'ct_add_hidden_fields');
15
  add_action('parse_request', 'ct_set_session');
16
  add_action('admin_notices', 'admin_notice_message');
159
  }
160
  }
161
 
 
 
 
 
 
 
 
 
162
  /**
163
  * Public action 'comment_form' - Adds hidden filed to define avaialbility of client's JavaScript
164
  * @param int $post_id Post ID, not used
i18n/cleantalk-ru_RU.mo CHANGED
Binary file
readme.txt CHANGED
@@ -1,13 +1,13 @@
1
  === Anti-spam by CleanTalk ===
2
  Contributors: znaeff, default.asp, shagimuratov, aleontiev
3
- Tags: spam, antispam, anti-spam, spambot, spam-bot, stop spam, spammers, spamfree, captcha, capcha, captha, catcha, recaptcha, comment, comments, math, cloud, blacklist, puzzle
4
  Requires at least: 3.0
5
- Tested up to: 3.6
6
- Stable tag: 2.4.14
7
  License: GPLv2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
- No spam in the comments. Cloud, smart, invisible anti-spam without CAPTCHA.
11
 
12
  == Description ==
13
 
@@ -19,7 +19,9 @@ Plugin filters spam bots in the comments, spam moves to trash. The plugin is not
19
 
20
  Also every new comment plugin compares with post and previous comments. If the relevance of the comment is good enough it gets approval at the blog without manual approval. This feature works for English, Russian laguages.
21
 
22
- It's simple and clever antispam for your blog. This plugin is a client application for anti-spam cloud service <a href="http://cleantalk.org" target="_blank">cleantalk.org</a>.
 
 
23
 
24
  = Requirements =
25
  WordPress 3.0 at least. PHP 4, 5 with CURL or file_get_contents() function and enabled 'allow_url_fopen' setting.
@@ -54,12 +56,21 @@ Plugin works with all WordPress themes. With some themes may not works JavaScrip
54
 
55
  Please use test email stop_email@example.com for comments. Also you can see comments proccessed by plugin for last 7 days at <a href="http://cleantalk.org/my/show_requests">Control panel</a> or look at folder "Spam" for banned comments.
56
 
 
 
 
 
 
 
57
  = Why do I need one more anti-spam plugin? =
58
 
59
  1. The plugin is more effective than CAPTCHA because use several methods to stop spammers.
60
  1. This plugin stops spam bots automatically, plugin invisible for blog visitors and admins.
61
  1. CleanTalk automatically approves relevant, not spam comments.
62
 
 
 
 
63
  == Screenshots ==
64
 
65
  1. The comment from spammer (sender blacklisted by IP/Email, comment text not relevant for the post) prohibited to place in the queue WordPress
@@ -68,6 +79,11 @@ Please use test email stop_email@example.com for comments. Also you can see comm
68
 
69
  == Changelog ==
70
 
 
 
 
 
 
71
  = 2.4.14 2013-08-29 =
72
  * Changed: Removed feedback requests to the servers for banned (spam) comments.
73
 
@@ -167,6 +183,11 @@ Please use test email stop_email@example.com for comments. Also you can see comm
167
  * First version
168
 
169
  == Upgrade Notice ==
 
 
 
 
 
170
  = 2.4.14 2013-08-29 =
171
  * Changed: Removed feedback requests to the servers for banned (spam) comments.
172
 
1
  === Anti-spam by CleanTalk ===
2
  Contributors: znaeff, default.asp, shagimuratov, aleontiev
3
+ Tags: spam, antispam, anti-spam, spambot, spam-bot, stop spam, spammers, spamfree, captcha, capcha, captha, catcha, recaptcha, comment, comments, math, cloud, blacklist, puzzle, wpmu, network, multisite, akismet, спам, 垃圾邮件, correo no deseado,
4
  Requires at least: 3.0
5
+ Tested up to: 3.7
6
+ Stable tag: 2.4.15
7
  License: GPLv2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
+ Cloud, smart, invisible anti-spam without CAPTCHA. No spam in the comments.
11
 
12
  == Description ==
13
 
19
 
20
  Also every new comment plugin compares with post and previous comments. If the relevance of the comment is good enough it gets approval at the blog without manual approval. This feature works for English, Russian laguages.
21
 
22
+ The plugin is a client application for anti-spam cloud service <a href="http://cleantalk.org" target="_blank">cleantalk.org</a>. CleanTalk.org daily prevents from spam 3 000 blogs, blocks up to 300 000 spam bots attacks and approves up to 2 000 not spam comments.
23
+
24
+ The plugin is WordPress MultiUser (WPMU or WordPress network) compatible. Each blog in multisite environment has individual anitspam options for spam bots protection.
25
 
26
  = Requirements =
27
  WordPress 3.0 at least. PHP 4, 5 with CURL or file_get_contents() function and enabled 'allow_url_fopen' setting.
56
 
57
  Please use test email stop_email@example.com for comments. Also you can see comments proccessed by plugin for last 7 days at <a href="http://cleantalk.org/my/show_requests">Control panel</a> or look at folder "Spam" for banned comments.
58
 
59
+ = How the plugin is effective against spam bots? =
60
+ Plugin Antispam by CleanTalk stops about 99.99% of spam comments by spam bots. More over, by determining the relevance of the comment text, the plugin stops about 96% spam comments submitted manually via browser.
61
+
62
+ = What about pingback, trackback spam? =
63
+ Plugin by default pass not spam pingbacks/trackbacks (sender host clear at <a href="http://cleantalk.org/blacklists">Blacklists IP</a> database) from third-party sites to the blog. If the pingback has more then 3 records in the Blacklists and not relevant to the blog the pingback will be stopped by CleanTalk.
64
+
65
  = Why do I need one more anti-spam plugin? =
66
 
67
  1. The plugin is more effective than CAPTCHA because use several methods to stop spammers.
68
  1. This plugin stops spam bots automatically, plugin invisible for blog visitors and admins.
69
  1. CleanTalk automatically approves relevant, not spam comments.
70
 
71
+ = Should I use another antispam plugins? =
72
+ Use other antispam plugins not necessarily, because CleanTalk stops 99.99% of spam comments. But if necessary, the plugin can work together with Akismet, Captcha and etc.
73
+
74
  == Screenshots ==
75
 
76
  1. The comment from spammer (sender blacklisted by IP/Email, comment text not relevant for the post) prohibited to place in the queue WordPress
79
 
80
  == Changelog ==
81
 
82
+ = 2.4.15 2013-09-26 =
83
+ * Fixed: Bug with mass comments deletion
84
+ * Changed: Russian localization for admin panel
85
+ * Tested with mulitsite setup (WordPress network or WPMU)
86
+
87
  = 2.4.14 2013-08-29 =
88
  * Changed: Removed feedback requests to the servers for banned (spam) comments.
89
 
183
  * First version
184
 
185
  == Upgrade Notice ==
186
+ = 2.4.15 2013-09-26 =
187
+ * Fixed: Bug with mass comments deletion
188
+ * Changed: Russian localization for admin panel
189
+ * Tested with mulitsite setup (WordPress network or WPMU)
190
+
191
  = 2.4.14 2013-08-29 =
192
  * Changed: Removed feedback requests to the servers for banned (spam) comments.
193