Skip to content

Commit a7e20c4

Browse files
committed
Fix. Verdict. Normalize allow to integer.
1 parent 2fae102 commit a7e20c4

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

examples/api_response_description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## API Response description
22
API returns (`$api_result`) PHP object:
3-
* allow (`bool/0|1`) – allow result to be published or not, in other words, spam(`0`) or ham(`1`).
3+
* allow (`int: 0|1`) – allow result to be published or not, in other words, spam(`0`) or ham(`1`).
44
* comment (`string`) – server comment for requests.
55
* id (`MD5 hash hex string`) – unique MD5 hash used as request identifier.
66
* errno (`int`) - error number or `0` if the request is successful.

lib/CleantalkAntispam.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,18 @@ private function verifyData()
276276
$this->checkAccessKey();
277277
} catch (\Exception $e) {
278278
$this->verdict->error = $e->getMessage();
279-
$this->verdict->allow = true;
279+
$this->verdict->allow = 1;
280280
}
281281

282282
try {
283283
$this->checkEventToken();
284284
} catch (\Exception $e) {
285285
if ($this->block_no_js_visitor) {
286286
$this->verdict->error = $e->getMessage();
287-
$this->verdict->allow = false;
287+
$this->verdict->allow = 0;
288288
$this->verdict->comment = 'Please, enable JavaScript to process the form.';
289289
} else {
290-
$this->verdict->allow = true;
290+
$this->verdict->allow = 1;
291291
}
292292
}
293293
}
@@ -335,6 +335,7 @@ private function checkEventToken()
335335
*/
336336
private function beforeReturnVerdict()
337337
{
338+
$this->verdict->allow = (int) (bool) $this->verdict->allow;
338339
$this->setImprovementSuggestions();
339340
return $this->verdict;
340341
}

lib/CleantalkVerdict.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
class CleantalkVerdict
66
{
7-
public $allow = true;
7+
/**
8+
* Whether the request is allowed, 1|0.
9+
*
10+
* @var int
11+
*/
12+
public $allow = 1;
813
public $comment = '';
914
public $error = '';
1015
public $request_link = null;

lib/HTTP/CleantalkResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function __construct($obj = null, $failed_urls = null)
146146
$this->stop_words = isset($obj->stop_words) ? Helper::fromUTF8($obj->stop_words, 'ISO-8859-1') : null;
147147
$this->comment = isset($obj->comment) ? strip_tags(Helper::fromUTF8($obj->comment, 'ISO-8859-1'), '<p><a><br>') : null;
148148
$this->blacklisted = isset($obj->blacklisted) ? $obj->blacklisted : null;
149-
$this->allow = isset($obj->allow) ? $obj->allow : 1;
149+
$this->allow = isset($obj->allow) ? (int) (bool) $obj->allow : 1;
150150
$this->id = isset($obj->id) ? $obj->id : null;
151151
$this->fast_submit = isset($obj->fast_submit) ? $obj->fast_submit : 0;
152152
$this->spam = isset($obj->spam) ? $obj->spam : 0;

0 commit comments

Comments
 (0)