Skip to content

Commit b7547f1

Browse files
committed
Merge remote-tracking branch 'origin/dev' into master
# Conflicts: # README.md
2 parents 9fc8abc + 7e2f151 commit b7547f1

File tree

7 files changed

+203
-270
lines changed

7 files changed

+203
-270
lines changed

README.md

Lines changed: 25 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
11934
session_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
21170
API returns PHP object:
21271
* allow (0|1) - allow to publish or not, in other words spam or ham

cleantalk-antispam.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
require_once "lib/Cleantalk.php";
4+
require_once "lib/CleantalkHelper.php";
5+
require_once "lib/CleantalkRequest.php";
6+
require_once "lib/CleantalkResponse.php";
7+
require_once "lib/CleantalkAntispam.php";

example.php

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
1-
<?php
2-
//require_once "vendor/autoload.php"; -- Composer
3-
4-
require_once "lib/Cleantalk.php";
5-
require_once "lib/CleantalkRequest.php";
6-
require_once "lib/CleantalkResponse.php";
7-
require_once "lib/CleantalkHelper.php";
8-
require_once "lib/CleantalkAPI.php";
9-
10-
/**
11-
* Cleantalk example
12-
*
13-
* @package Cleantalk Example
14-
* @copyright (C) 2011 - 2012 Сleantalk team (http://cleantalk.ru)
15-
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
16-
* @see http://cleantalk.ru/wiki/doku.php/api
17-
*
18-
*/
19-
20-
use Cleantalk\CleantalkRequest;
21-
use Cleantalk\Cleantalk;
22-
use Cleantalk\CleantalkAPI;
23-
24-
// Take params from config
25-
$config_url = 'http://moderate.cleantalk.ru';
26-
$auth_key = null; // Set Cleantalk auth key
27-
28-
29-
// The facility in which to store the query parameters
30-
$ct_request = new CleantalkRequest();
31-
32-
$ct_request->auth_key = $auth_key;
33-
$ct_request->message = 'stop_word';
34-
$ct_request->sender_email = '[email protected]';
35-
$ct_request->sender_nickname = 'John Dow';
36-
$ct_request->example = str_repeat('Just text ', 10);
37-
$ct_request->agent = 'php-api';
38-
$ct_request->sender_ip = '178.32.183.43';
39-
$ct_request->js_on = 1; # Site visitor has JavaScript
40-
$ct_request->submit_time = 12; # Seconds from start form filling till the form POST
41-
42-
$ct = new Cleantalk();
43-
$ct->server_url = $config_url;
44-
45-
// Check
46-
$ct_result = $ct->isAllowMessage($ct_request);
47-
48-
if ($ct_result->allow == 1) {
49-
echo 'Comment allowed. Reason ' . $ct_result->comment;
50-
} else {
51-
echo 'Comment blocked. Reason ' . $ct_result->comment;
52-
}
53-
echo "<br/>CleantalkAPI call example:<br/>";
54-
var_dump(CleantalkAPI::method__notice_validate_key('',''));
55-
?>
1+
<?php
2+
//require_once "vendor/autoload.php"; -- Composer
3+
4+
require_once "lib/Cleantalk.php";
5+
require_once "lib/CleantalkRequest.php";
6+
require_once "lib/CleantalkResponse.php";
7+
require_once "lib/CleantalkHelper.php";
8+
require_once "lib/CleantalkAPI.php";
9+
require_once "lib/cleantalk-php-patch.php";
10+
11+
/**
12+
* Cleantalk example
13+
*
14+
* @package Cleantalk Example
15+
* @copyright (C) 2011 - 2012 Сleantalk team (http://cleantalk.ru)
16+
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
17+
* @see http://cleantalk.ru/wiki/doku.php/api
18+
*
19+
*/
20+
21+
use Cleantalk\CleantalkRequest;
22+
use Cleantalk\Cleantalk;
23+
use Cleantalk\CleantalkAPI;
24+
25+
// Take params from config
26+
$config_url = 'https://moderate.cleantalk.org';
27+
$auth_key = null; // Set Cleantalk auth key
28+
29+
30+
// The facility in which to store the query parameters
31+
$ct_request = new CleantalkRequest();
32+
33+
$ct_request->auth_key = $auth_key;
34+
$ct_request->message = 'stop_word';
35+
$ct_request->sender_email = '[email protected]';
36+
$ct_request->sender_nickname = 'John Dow';
37+
$ct_request->example = str_repeat('Just text ', 10);
38+
$ct_request->agent = 'php-api';
39+
$ct_request->sender_ip = '178.32.183.43';
40+
$ct_request->js_on = 1; # Site visitor has JavaScript
41+
$ct_request->submit_time = 12; # Seconds from start form filling till the form POST
42+
43+
$ct = new Cleantalk();
44+
$ct->server_url = $config_url;
45+
46+
// Check
47+
$ct_result = $ct->isAllowMessage($ct_request);
48+
49+
if ($ct_result->allow == 1) {
50+
echo 'Comment allowed. Reason ' . $ct_result->comment;
51+
} else {
52+
echo 'Comment blocked. Reason ' . $ct_result->comment;
53+
}
54+
echo "<br/>CleantalkAPI call example:<br/>";
55+
var_dump(CleantalkAPI::method__notice_validate_key('',''));
56+
?>

0 commit comments

Comments
 (0)