@@ -19,194 +19,53 @@ API sends a comment's text and several previous approved comments to the servers
1919## Requirements
2020
2121 * PHP 5.6 and above
22- * CURL support
23- * CleanTalk account https://cleantalk.org/register?product=anti-spam
22+ * CURL support
2423
25-
26-
27- ## Sample SPAM test for user signup
24+ You can unpack the archive with the plugin to the root of the site or install it using the composer
2825
2926``` php
30- <?php
31-
32- session_start();
33-
34- //require_once "vendor/autoload.php"; -- Composer
35- //require_once "lib/cleantalk-php-patch.php"; -- PHP-FPM
36-
37- require_once "lib/Cleantalk.php";
38- require_once "lib/CleantalkHelper.php";
39- require_once "lib/CleantalkRequest.php";
40- require_once "lib/CleantalkResponse.php";
41-
42- use Cleantalk\Cleantalk;
43- use Cleantalk\CleantalkRequest;
44-
45- // Take params from config
46- $config_url = 'http://moderate.cleantalk.org/api2.0/';
47- $auth_key = 'enter key'; // Set Cleantalk auth key
48-
49- if (count($_POST)) {
50- $sender_nickname = 'John Dow';
51- if (isset($_POST['login']) && $_POST['login'] != '')
52- $sender_nickname = $_POST['login'];
53-
54- $sender_email = '
[email protected] ';
55- if (isset($_POST['email']) && $_POST['email'] != '')
56- $sender_email = $_POST['email'];
57-
58- $sender_ip = null;
59- if (isset($_SERVER['REMOTE_ADDR']))
60- $sender_ip = $_SERVER['REMOTE_ADDR'];
61-
62- $js_on = 0;
63- if (isset($_POST['js_on']) && $_POST['js_on'] == date("Y"))
64- $js_on = 1;
65-
66- // The facility in which to store the query parameters
67- $ct_request = new CleantalkRequest();
68-
69- $ct_request->auth_key = $auth_key;
70- $ct_request->agent = 'php-api';
71- $ct_request->sender_email = $sender_email;
72- $ct_request->sender_ip = $sender_ip;
73- $ct_request->sender_nickname = $sender_nickname;
74- $ct_request->js_on = $js_on;
75- $ct_request->submit_time = time() - (int) $_SESSION['ct_submit_time'];
76-
77- $ct = new Cleantalk();
78- $ct->server_url = $config_url;
79-
80- // Check
81- $ct_result = $ct->isAllowUser($ct_request);
82-
83- if ($ct_result->allow == 1) {
84- echo 'User allowed. Reason ' . $ct_result->comment;
85- } else {
86- echo 'User forbidden. Reason ' . $ct_result->comment;
87- }
88- echo '<br /><br />';
89- }
90- else
91- {
92- $_SESSION['ct_submit_time'] = time();
93- }
94- ?>
95-
96- <form method =" post" >
97- <label for =" login" >Login:<label >
98- <input type =" text" name =" login" id =" login" />
99- <br />
100- <label for =" email" >Email:<label >
101- <input type =" text" name =" email" id =" email" value =" " />
102- <br />
103- <input type =" hidden" name =" js_on" id =" js_on" value =" 0" />
104- <input type =" submit" />
105- </form >
106-
107- <script type =" text/javascript" >
108- var date = new Date ();
109-
110- document .getElementById (" js_on" ).value = date .getFullYear ();
111- </script >
27+ composer require cleantalk/php-antispam
11228```
113-
114- ## Sample SPAM test for text comment
29+
30+ ### Sample SPAM test for text comment and user signup
11531
11632``` php
11733<?php
118-
11934session_start();
12035
121- //require_once "vendor/autoload.php"; -- Composer
36+ $apikey = 'your_cleantalk_api_key';
37+ $email_field = 'name_email_form_field';
38+ $user_name_field = 'name_user_name_form_field';
39+ $message_field = 'name_message_form_field';
40+ $type_form = 'contact'; // use 'signup' for user signup form
41+
42+ // if downloaded, unzip and include the app:
43+ require_once 'php-antispam/cleantalk-antispam.php';
44+ // if install the app by composer package:
45+ use Cleantalk\CleantalkAntispam;
46+
12247//require_once "lib/cleantalk-php-patch.php"; -- PHP-FPM
12348
124- require_once "lib/Cleantalk.php";
125- require_once "lib/CleantalkHelper.php";
126- require_once "lib/CleantalkRequest.php";
127- require_once "lib/CleantalkResponse.php";
128-
129- use Cleantalk\Cleantalk;
130- use Cleantalk\CleantalkRequest;
131-
132- // Take params from config
133- $config_url = 'http://moderate.cleantalk.org/api2.0/';
134- $auth_key = 'enter key'; // Set Cleantalk auth key
135-
136- if (count($_POST)) {
137- $sender_nickname = 'John Dow';
138- if (isset($_POST['login']) && $_POST['login'] != '')
139- $sender_nickname = $_POST['login'];
140-
141- $sender_email = '
[email protected] ';
142- if (isset($_POST['email']) && $_POST['email'] != '')
143- $sender_email = $_POST['email'];
144-
145- $sender_ip = null;
146- if (isset($_SERVER['REMOTE_ADDR']))
147- $sender_ip = $_SERVER['REMOTE_ADDR'];
148-
149- $js_on = 0;
150- if (isset($_POST['js_on']) && $_POST['js_on'] == date("Y"))
151- $js_on = 1;
152-
153- $message = null;
154- if (isset($_POST['message']) && $_POST['message'] != '')
155- $message = $_POST['message'];
156-
157- // The facility in which to store the query parameters
158- $ct_request = new CleantalkRequest();
159-
160- $ct_request->auth_key = $auth_key;
161- $ct_request->agent = 'php-api';
162- $ct_request->sender_email = $sender_email;
163- $ct_request->sender_ip = $sender_ip;
164- $ct_request->sender_nickname = $sender_nickname;
165- $ct_request->js_on = $js_on;
166- $ct_request->message = $message;
167- $ct_request->submit_time = time() - (int) $_SESSION['ct_submit_time'];
168-
169- $ct = new Cleantalk();
170- $ct->server_url = $config_url;
171-
172- // Check
173- $ct_result = $ct->isAllowMessage($ct_request);
174-
175- if ($ct_result->allow == 1) {
176- echo 'Message allowed. Reason ' . $ct_result->comment;
177- } else {
178- echo 'Message forbidden. Reason ' . $ct_result->comment;
179- }
180- echo '<br /><br />';
181- }
182- else
183- {
184- $_SESSION['ct_submit_time'] = time();
185- }
49+ $cleantalk_antispam = new CleantalkAntispam($apikey, $email_field, $user_name_field, $message_field, $type_form);
50+ $cleantalk_antispam->handle();
18651?>
18752
18853<form method =" post" >
189- <label for =" login" >Login:<label >
190- <input type =" text" name =" login " id =" login" />
54+ <label for =" login" >Login:</ label >
55+ <input type =" text" name =" name_user_name_form_field " id =" login" />
19156 <br />
192- <label for =" email" >Email:<label >
193- <input type =" text" name =" email " id =" email" value =" " />
57+ <label for =" email" >Email:</ label >
58+ <input type =" text" name =" name_email_form_field " id =" email" value =" " />
19459 <br />
195- <label for =" message" >Message:<label >
196- <textarea name =" message " id =" message" ></textarea >
60+ <label for =" message" >Message:</ label >
61+ <textarea name =" name_message_form_field " id =" message" ></textarea >
19762 <br />
198- <input type =" hidden" name =" js_on" id =" js_on" value =" 0" />
19963 <input type =" submit" />
20064</form >
20165
202- <script type =" text/javascript" >
203- var date = new Date ();
204-
205- document .getElementById (" js_on" ).value = date .getFullYear ();
206- </script >
66+ <?php $cleantalk_antispam->frontendScript(); ?>
20767```
20868
209-
21069## API Response description
21170API returns PHP object:
21271 * allow (0|1) - allow to publish or not, in other words spam or ham
0 commit comments