diff --git a/README.md b/README.md
index 1d55a2d..6dc2a86 100644
--- a/README.md
+++ b/README.md
@@ -21,186 +21,51 @@ API sends a comment's text and several previous approved comments to the servers
* PHP 5.6 and above
* CURL support
+You can unpack the archive with the plugin to the root of the site or install it using the composer
-## Sample SPAM test for user signup
+```php
+composer require cleantalk/php-antispam
+```
+
+### Sample SPAM test for text comment and user signup
```php
auth_key = $auth_key;
- $ct_request->agent = 'php-api';
- $ct_request->sender_email = $sender_email;
- $ct_request->sender_ip = $sender_ip;
- $ct_request->sender_nickname = $sender_nickname;
- $ct_request->js_on = $js_on;
- $ct_request->submit_time = time() - (int) $_SESSION['ct_submit_time'];
-
- $ct = new Cleantalk();
- $ct->server_url = $config_url;
-
- // Check
- $ct_result = $ct->isAllowUser($ct_request);
-
- if ($ct_result->allow == 1) {
- echo 'User allowed. Reason ' . $ct_result->comment;
- } else {
- echo 'User forbidden. Reason ' . $ct_result->comment;
- }
- echo '
';
-}
-else
-{
- $_SESSION['ct_submit_time'] = time();
-}
-?>
+$apikey = 'your_cleantalk_api_key';
+$email_field = 'name_email_form_field';
+$user_name_field = 'name_user_name_form_field';
+$message_field = 'name_message_form_field';
+$type_form = 'contact'; // use 'signup' for user signup form
-
+// if downloaded, unzip and include the app:
+require_once 'php-antispam/cleantalk-antispam.php';
+// if install the app by composer package:
+use Cleantalk\CleantalkAntispam;
-
-```
-
-## Sample SPAM test for text comment
-
-```php
-auth_key = $auth_key;
- $ct_request->agent = 'php-api';
- $ct_request->sender_email = $sender_email;
- $ct_request->sender_ip = $sender_ip;
- $ct_request->sender_nickname = $sender_nickname;
- $ct_request->js_on = $js_on;
- $ct_request->message = $message;
- $ct_request->submit_time = time() - (int) $_SESSION['ct_submit_time'];
-
- $ct = new Cleantalk();
- $ct->server_url = $config_url;
-
- // Check
- $ct_result = $ct->isAllowMessage($ct_request);
-
- if ($ct_result->allow == 1) {
- echo 'Message allowed. Reason ' . $ct_result->comment;
- } else {
- echo 'Message forbidden. Reason ' . $ct_result->comment;
- }
- echo '
';
-}
-else
-{
- $_SESSION['ct_submit_time'] = time();
-}
+$cleantalk_antispam = new CleantalkAntispam($apikey, $email_field, $user_name_field, $message_field, $type_form);
+$cleantalk_antispam->handle();
?>
-
+frontendScript(); ?>
```
-
## API Response description
API returns PHP object:
* allow (0|1) - allow to publish or not, in other words spam or ham
diff --git a/cleantalk-antispam.php b/cleantalk-antispam.php
new file mode 100644
index 0000000..6ae97a4
--- /dev/null
+++ b/cleantalk-antispam.php
@@ -0,0 +1,7 @@
+apikey = $apikey;
+ $this->email_field = $email_field;
+ $this->user_name_field = $user_name_field;
+ $this->message_field = $message_field;
+ $this->type_form = $type_form;
+ }
+
+ public function handle()
+ {
+ if (count($_POST) === 0) {
+ $_SESSION['ct_submit_time'] = time();
+ return;
+ }
+
+ $sender_email = isset($_POST[$this->email_field]) ? $_POST[$this->email_field] : '';
+ $sender_nickname = isset($_POST[$this->user_name_field]) ? $_POST[$this->user_name_field] : '';
+ $message = isset($_POST[$this->message_field]) ? $_POST[$this->message_field] : '';
+ $sender_ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
+
+ $ct_request = new CleantalkRequest();
+
+ $ct_request->auth_key = $this->apikey;
+ $ct_request->agent = 'php-api';
+ $ct_request->sender_email = $sender_email;
+ $ct_request->sender_ip = $sender_ip;
+ $ct_request->sender_nickname = $sender_nickname;
+ $ct_request->message = $message;
+ $ct_request->submit_time = time() - (int) $_SESSION['ct_submit_time'];
+ $ct_request->event_token = isset($_POST['ct_bot_detector_event_token']) ? $_POST['ct_bot_detector_event_token'] : null;
+
+ $ct = new Cleantalk();
+ $ct->server_url = $ct_request::CLEANTALK_API_URL;
+
+ // Check
+ if ($this->type_form === 'signup') {
+ $ct_result = $ct->isAllowUser($ct_request);
+ }
+ if ($this->type_form === 'contact') {
+ $ct_result = $ct->isAllowMessage($ct_request);
+ }
+
+ if ($ct_result->allow == 1) {
+ if ($this->type_form === 'signup') {
+ echo 'User allowed. Reason ' . $ct_result->comment;
+ }
+ if ($this->type_form === 'contact') {
+ echo 'Message allowed. Reason ' . $ct_result->comment;
+ }
+ } else {
+ if ($this->type_form === 'signup') {
+ echo 'User forbidden. Reason ' . $ct_result->comment;
+ }
+ if ($this->type_form === 'contact') {
+ echo 'Message forbidden. Reason ' . $ct_result->comment;
+ }
+ }
+ echo '
';
+ }
+
+ public function frontendScript()
+ {
+ echo '';
+ }
+}
\ No newline at end of file
diff --git a/lib/CleantalkRequest.php b/lib/CleantalkRequest.php
index 2da2f48..b2ab971 100644
--- a/lib/CleantalkRequest.php
+++ b/lib/CleantalkRequest.php
@@ -4,7 +4,9 @@
/**
* Request class
*/
-class CleantalkRequest {
+class CleantalkRequest
+{
+ const CLEANTALK_API_URL = 'https://moderate.cleantalk.org/api2.0/';
/**
* All http request headers
@@ -120,17 +122,6 @@ class CleantalkRequest {
public $x_forwarded_for = '';
public $x_real_ip = '';
- /**
- * Is enable Java Script,
- * valid are 0|1|2
- * Status:
- * null - JS html code not inserted into phpBB templates
- * 0 - JS disabled at the client browser
- * 1 - JS enabled at the client broswer
- * @var int
- */
- public $js_on = null;
-
/**
* user time zone
* @var string
@@ -154,7 +145,12 @@ class CleantalkRequest {
* Method name
* @var string
*/
- public $method_name = 'check_message';
+ public $method_name = 'check_message';
+
+ /**
+ * @var string|null
+ */
+ public $event_token;
/**
* Fill params with constructor