Skip to content

Commit 6a4659e

Browse files
committed
Merge branch 'refs/heads/master' into dev
2 parents 4777c1f + 520abf5 commit 6a4659e

File tree

5 files changed

+63
-43
lines changed

5 files changed

+63
-43
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use Cleantalk\CleantalkAntispam;
4747
//require_once "lib/cleantalk-php-patch.php"; -- PHP-FPM
4848

4949
$cleantalk_antispam = new CleantalkAntispam($apikey, $email_field, $user_name_field, $message_field, $type_form);
50-
$cleantalk_antispam->handle();
50+
$api_result = $cleantalk_antispam->handle();
5151
?>
5252

5353
<form method="post">
@@ -67,7 +67,7 @@ $cleantalk_antispam->handle();
6767
```
6868

6969
## API Response description
70-
API returns PHP object:
70+
API returns (`$api_result`) PHP object:
7171
* allow (0|1) - allow to publish or not, in other words spam or ham
7272
* comment (string) - server comment for requests.
7373
* id (string MD5 HEX hash) - unique request idenifier.

example.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
$ct_request->example = str_repeat('Just text ', 10);
3838
$ct_request->agent = 'php-api';
3939
$ct_request->sender_ip = '178.32.183.43';
40-
$ct_request->js_on = 1; # Site visitor has JavaScript
41-
$ct_request->submit_time = 12; # Seconds from start form filling till the form POST
40+
$ct_request->event_token = isset($_POST['ct_bot_detector_event_token']) ? $_POST['ct_bot_detector_event_token'] : null;
4241

4342
$ct = new Cleantalk();
4443
$ct->server_url = $config_url;

lib/Cleantalk.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,20 @@ public function sendFeedback( CleantalkRequest $request ){
153153

154154
return $this->httpRequest( $filtered_request );
155155
}
156-
156+
157+
/**
158+
* Function checks if visitor is bot or not based on the Bot-detector event token.
159+
*
160+
* @param CleantalkRequest $request
161+
*
162+
* @return CleantalkResponse
163+
*/
164+
public function checkBot( CleantalkRequest $request ){
165+
$request = $this->filterRequest( $request );
166+
$filtered_request = $this->createMsg( 'check_bot', $request );
167+
return $this->httpRequest( $filtered_request );
168+
}
169+
157170
/**
158171
* Filter request params
159172
*

lib/CleantalkAntispam.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public function handle()
4545
$ct_request->sender_ip = $sender_ip;
4646
$ct_request->sender_nickname = $sender_nickname;
4747
$ct_request->message = $message;
48-
$ct_request->submit_time = time() - (int) $_SESSION['ct_submit_time'];
4948
$ct_request->event_token = isset($_POST['ct_bot_detector_event_token']) ? $_POST['ct_bot_detector_event_token'] : null;
5049

5150
$ct = new Cleantalk();
@@ -59,22 +58,7 @@ public function handle()
5958
$ct_result = $ct->isAllowMessage($ct_request);
6059
}
6160

62-
if ($ct_result->allow == 1) {
63-
if ($this->type_form === 'signup') {
64-
echo 'User allowed. Reason ' . $ct_result->comment;
65-
}
66-
if ($this->type_form === 'contact') {
67-
echo 'Message allowed. Reason ' . $ct_result->comment;
68-
}
69-
} else {
70-
if ($this->type_form === 'signup') {
71-
echo 'User forbidden. Reason ' . $ct_result->comment;
72-
}
73-
if ($this->type_form === 'contact') {
74-
echo 'Message forbidden. Reason ' . $ct_result->comment;
75-
}
76-
}
77-
echo '<br /><br />';
61+
return $ct_result;
7862
}
7963

8064
public function frontendScript()

lib/CleantalkResponse.php

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
* Response class
66
*/
77
class CleantalkResponse {
8-
8+
99
/**
1010
* Checked IP
1111
* @var string
1212
*/
1313
public $sender_ip = null;
14-
14+
1515
/**
1616
* Checked Email
1717
* @var string
1818
*/
1919
public $sender_email = null;
20-
20+
2121
/**
2222
* Received feedback nubmer
2323
* @var int
2424
*/
2525
public $received = null;
26-
26+
2727
/**
2828
* Is stop words
2929
* @var int
3030
*/
3131
public $stop_words = null;
32-
32+
3333
/**
3434
* Cleantalk comment
3535
* @var string
@@ -80,57 +80,75 @@ class CleantalkResponse {
8080

8181
/**
8282
* Is JS
83-
* @var type
83+
* @var type
8484
*/
8585
public $js_disabled = null;
8686

8787
/**
8888
* Sms check
89-
* @var type
89+
* @var type
9090
*/
9191
public $sms_allow = null;
9292

9393
/**
9494
* Sms code result
95-
* @var type
95+
* @var type
9696
*/
9797
public $sms = null;
98-
98+
9999
/**
100100
* Sms error code
101-
* @var type
101+
* @var type
102102
*/
103103
public $sms_error_code = null;
104-
104+
105105
/**
106106
* Sms error code
107-
* @var type
107+
* @var type
108108
*/
109109
public $sms_error_text = null;
110-
110+
111111
/**
112112
* Stop queue message, 1|0
113-
* @var int
113+
* @var int
114114
*/
115115
public $stop_queue = null;
116-
116+
117117
/**
118118
* Account shuld by deactivated after registration, 1|0
119-
* @var int
119+
* @var int
120120
*/
121121
public $inactive = null;
122122

123123
/**
124-
* Account status
125-
* @var int
124+
* Account status
125+
* @var int
126126
*/
127127
public $account_status = -1;
128-
128+
129129
/**
130130
* @var array Contains codes returned from server
131131
*/
132132
public $codes = array();
133-
133+
134+
/**
135+
* @var int Frequency of visitor spotted in 24 hours
136+
*/
137+
public $ip_frequency_24hour = 0;
138+
139+
/**
140+
* @var int Frequency of visitor spotted in 24 hours
141+
*/
142+
public $ip_frequency_10min = 0;
143+
/**
144+
* @var int Frequency of visitor spotted in 24 hours
145+
*/
146+
public $ip_frequency_1hour = 0;
147+
/**
148+
* @var float Bot expectation percentage.
149+
*/
150+
public $bot_expectation = 0.0;
151+
134152
/**
135153
* Create server response
136154
*
@@ -168,8 +186,14 @@ function __construct($response = null, $obj = null) {
168186
$this->received = (isset($obj->received)) ? $obj->received : -1;
169187
$this->codes = (isset($obj->codes)) ? explode(' ', $obj->codes) : array();
170188

189+
$this->bot_expectation = (isset($obj->bot_expectation)) ? $obj->bot_expectation : 0.0;
190+
$this->ip_frequency_24hour = (isset($obj->ip_frequency_24hour)) ? $obj->ip_frequency_24hour : 0;
191+
$this->ip_frequency_1hour = (isset($obj->ip_frequency_1hour)) ? $obj->ip_frequency_1hour : 0;
192+
$this->ip_frequency_10min = (isset($obj->ip_frequency_10min)) ? $obj->ip_frequency_10min : 0;
193+
194+
171195
if ($this->errno !== 0 && $this->errstr !== null && $this->comment === null)
172-
$this->comment = '*** ' . $this->errstr . ' Antispam service cleantalk.org ***';
196+
$this->comment = '*** ' . $this->errstr . ' Antispam service cleantalk.org ***';
173197
}
174198
}
175199
}

0 commit comments

Comments
 (0)