From a7e20c46efb6a1535e8bee5e68b9e5a13d40bbdd Mon Sep 17 00:00:00 2001 From: "a.vasiliev" Date: Mon, 3 Aug 2026 12:22:41 +0100 Subject: [PATCH] Fix. Verdict. Normalize allow to integer. --- examples/api_response_description.md | 2 +- lib/CleantalkAntispam.php | 7 ++++--- lib/CleantalkVerdict.php | 7 ++++++- lib/HTTP/CleantalkResponse.php | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/api_response_description.md b/examples/api_response_description.md index f599f0c..e3d0741 100644 --- a/examples/api_response_description.md +++ b/examples/api_response_description.md @@ -1,6 +1,6 @@ ## API Response description API returns (`$api_result`) PHP object: - * allow (`bool/0|1`) – allow result to be published or not, in other words, spam(`0`) or ham(`1`). + * allow (`int: 0|1`) – allow result to be published or not, in other words, spam(`0`) or ham(`1`). * comment (`string`) – server comment for requests. * id (`MD5 hash hex string`) – unique MD5 hash used as request identifier. * errno (`int`) - error number or `0` if the request is successful. diff --git a/lib/CleantalkAntispam.php b/lib/CleantalkAntispam.php index f9568e8..e79a8c9 100644 --- a/lib/CleantalkAntispam.php +++ b/lib/CleantalkAntispam.php @@ -276,7 +276,7 @@ private function verifyData() $this->checkAccessKey(); } catch (\Exception $e) { $this->verdict->error = $e->getMessage(); - $this->verdict->allow = true; + $this->verdict->allow = 1; } try { @@ -284,10 +284,10 @@ private function verifyData() } catch (\Exception $e) { if ($this->block_no_js_visitor) { $this->verdict->error = $e->getMessage(); - $this->verdict->allow = false; + $this->verdict->allow = 0; $this->verdict->comment = 'Please, enable JavaScript to process the form.'; } else { - $this->verdict->allow = true; + $this->verdict->allow = 1; } } } @@ -335,6 +335,7 @@ private function checkEventToken() */ private function beforeReturnVerdict() { + $this->verdict->allow = (int) (bool) $this->verdict->allow; $this->setImprovementSuggestions(); return $this->verdict; } diff --git a/lib/CleantalkVerdict.php b/lib/CleantalkVerdict.php index 53195d0..a5cb656 100644 --- a/lib/CleantalkVerdict.php +++ b/lib/CleantalkVerdict.php @@ -4,7 +4,12 @@ class CleantalkVerdict { - public $allow = true; + /** + * Whether the request is allowed, 1|0. + * + * @var int + */ + public $allow = 1; public $comment = ''; public $error = ''; public $request_link = null; diff --git a/lib/HTTP/CleantalkResponse.php b/lib/HTTP/CleantalkResponse.php index bd772a4..2a48356 100644 --- a/lib/HTTP/CleantalkResponse.php +++ b/lib/HTTP/CleantalkResponse.php @@ -146,7 +146,7 @@ public function __construct($obj = null, $failed_urls = null) $this->stop_words = isset($obj->stop_words) ? Helper::fromUTF8($obj->stop_words, 'ISO-8859-1') : null; $this->comment = isset($obj->comment) ? strip_tags(Helper::fromUTF8($obj->comment, 'ISO-8859-1'), '


') : null; $this->blacklisted = isset($obj->blacklisted) ? $obj->blacklisted : null; - $this->allow = isset($obj->allow) ? $obj->allow : 1; + $this->allow = isset($obj->allow) ? (int) (bool) $obj->allow : 1; $this->id = isset($obj->id) ? $obj->id : null; $this->fast_submit = isset($obj->fast_submit) ? $obj->fast_submit : 0; $this->spam = isset($obj->spam) ? $obj->spam : 0;