@@ -21,186 +21,51 @@ API sends a comment's text and several previous approved comments to the servers
2121 * PHP 5.6 and above
2222 * CURL support
2323
24+ You can unpack the archive with the plugin to the root of the site or install it using the composer
2425
25- ## Sample SPAM test for user signup
26+ ``` php
27+ composer require cleantalk/php-antispam
28+ ```
29+
30+ ### Sample SPAM test for text comment and user signup
2631
2732``` php
2833<?php
29-
3034session_start();
3135
32- //require_once "vendor/autoload.php"; -- Composer
33-
34- require_once "lib/Cleantalk.php";
35- require_once "lib/CleantalkHelper.php";
36- require_once "lib/CleantalkRequest.php";
37-
38- use Cleantalk\Cleantalk;
39- use Cleantalk\CleantalkRequest;
40-
41- // Take params from config
42- $config_url = 'http://moderate.cleantalk.org/api2.0/';
43- $auth_key = 'enter key'; // Set Cleantalk auth key
44-
45- if (count($_POST)) {
46- $sender_nickname = 'John Dow';
47- if (isset($_POST['login']) && $_POST['login'] != '')
48- $sender_nickname = $_POST['login'];
49-
50- $sender_email = '
[email protected] ';
51- if (isset($_POST['email']) && $_POST['email'] != '')
52- $sender_email = $_POST['email'];
53-
54- $sender_ip = null;
55- if (isset($_SERVER['REMOTE_ADDR']))
56- $sender_ip = $_SERVER['REMOTE_ADDR'];
57-
58- $js_on = 0;
59- if (isset($_POST['js_on']) && $_POST['js_on'] == date("Y"))
60- $js_on = 1;
61-
62- // The facility in which to store the query parameters
63- $ct_request = new CleantalkRequest();
64-
65- $ct_request->auth_key = $auth_key;
66- $ct_request->agent = 'php-api';
67- $ct_request->sender_email = $sender_email;
68- $ct_request->sender_ip = $sender_ip;
69- $ct_request->sender_nickname = $sender_nickname;
70- $ct_request->js_on = $js_on;
71- $ct_request->submit_time = time() - (int) $_SESSION['ct_submit_time'];
72-
73- $ct = new Cleantalk();
74- $ct->server_url = $config_url;
75-
76- // Check
77- $ct_result = $ct->isAllowUser($ct_request);
78-
79- if ($ct_result->allow == 1) {
80- echo 'User allowed. Reason ' . $ct_result->comment;
81- } else {
82- echo 'User forbidden. Reason ' . $ct_result->comment;
83- }
84- echo '<br /><br />';
85- }
86- else
87- {
88- $_SESSION['ct_submit_time'] = time();
89- }
90- ?>
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
9141
92- <form method =" post" >
93- <label for =" login" >Login:<label >
94- <input type =" text" name =" login" id =" login" />
95- <br />
96- <label for =" email" >Email:<label >
97- <input type =" text" name =" email" id =" email" value =" " />
98- <br />
99- <input type =" hidden" name =" js_on" id =" js_on" value =" 0" />
100- <input type =" submit" />
101- </form >
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;
10246
103- <script type =" text/javascript" >
104- var date = new Date ();
47+ //require_once "lib/cleantalk-php-patch.php"; -- PHP-FPM
10548
106- document .getElementById (" js_on" ).value = date .getFullYear ();
107- </script >
108- ```
109-
110- ## Sample SPAM test for text comment
111-
112- ``` php
113- <?php
114-
115- session_start();
116-
117- //require_once "vendor/autoload.php"; -- Composer
118-
119- require_once "lib/Cleantalk.php";
120- require_once "lib/CleantalkHelper.php";
121- require_once "lib/CleantalkRequest.php";
122-
123- use Cleantalk\Cleantalk;
124- use Cleantalk\CleantalkRequest;
125-
126- // Take params from config
127- $config_url = 'http://moderate.cleantalk.org/api2.0/';
128- $auth_key = 'enter key'; // Set Cleantalk auth key
129-
130- if (count($_POST)) {
131- $sender_nickname = 'John Dow';
132- if (isset($_POST['login']) && $_POST['login'] != '')
133- $sender_nickname = $_POST['login'];
134-
135- $sender_email = '
[email protected] ';
136- if (isset($_POST['email']) && $_POST['email'] != '')
137- $sender_email = $_POST['email'];
138-
139- $sender_ip = null;
140- if (isset($_SERVER['REMOTE_ADDR']))
141- $sender_ip = $_SERVER['REMOTE_ADDR'];
142-
143- $js_on = 0;
144- if (isset($_POST['js_on']) && $_POST['js_on'] == date("Y"))
145- $js_on = 1;
146-
147- $message = null;
148- if (isset($_POST['message']) && $_POST['message'] != '')
149- $message = $_POST['message'];
150-
151- // The facility in which to store the query parameters
152- $ct_request = new CleantalkRequest();
153-
154- $ct_request->auth_key = $auth_key;
155- $ct_request->agent = 'php-api';
156- $ct_request->sender_email = $sender_email;
157- $ct_request->sender_ip = $sender_ip;
158- $ct_request->sender_nickname = $sender_nickname;
159- $ct_request->js_on = $js_on;
160- $ct_request->message = $message;
161- $ct_request->submit_time = time() - (int) $_SESSION['ct_submit_time'];
162-
163- $ct = new Cleantalk();
164- $ct->server_url = $config_url;
165-
166- // Check
167- $ct_result = $ct->isAllowMessage($ct_request);
168-
169- if ($ct_result->allow == 1) {
170- echo 'Message allowed. Reason ' . $ct_result->comment;
171- } else {
172- echo 'Message forbidden. Reason ' . $ct_result->comment;
173- }
174- echo '<br /><br />';
175- }
176- else
177- {
178- $_SESSION['ct_submit_time'] = time();
179- }
49+ $cleantalk_antispam = new CleantalkAntispam($apikey, $email_field, $user_name_field, $message_field, $type_form);
50+ $cleantalk_antispam->handle();
18051?>
18152
18253<form method =" post" >
183- <label for =" login" >Login:<label >
184- <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" />
18556 <br />
186- <label for =" email" >Email:<label >
187- <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 =" " />
18859 <br />
189- <label for =" message" >Message:<label >
190- <textarea name =" message " id =" message" ></textarea >
60+ <label for =" message" >Message:</ label >
61+ <textarea name =" name_message_form_field " id =" message" ></textarea >
19162 <br />
192- <input type =" hidden" name =" js_on" id =" js_on" value =" 0" />
19363 <input type =" submit" />
19464</form >
19565
196- <script type =" text/javascript" >
197- var date = new Date ();
198-
199- document .getElementById (" js_on" ).value = date .getFullYear ();
200- </script >
66+ <?php $cleantalk_antispam->frontendScript(); ?>
20167```
20268
203-
20469## API Response description
20570API returns PHP object:
20671 * allow (0|1) - allow to publish or not, in other words spam or ham
0 commit comments