-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into master
# Conflicts: # README.md
- Loading branch information
Showing
7 changed files
with
203 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,194 +19,53 @@ API sends a comment's text and several previous approved comments to the servers | |
## Requirements | ||
|
||
* PHP 5.6 and above | ||
* CURL support | ||
* CleanTalk account https://cleantalk.org/register?product=anti-spam | ||
* CURL support | ||
|
||
|
||
|
||
## Sample SPAM test for user signup | ||
You can unpack the archive with the plugin to the root of the site or install it using the composer | ||
|
||
```php | ||
<?php | ||
|
||
session_start(); | ||
|
||
//require_once "vendor/autoload.php"; -- Composer | ||
//require_once "lib/cleantalk-php-patch.php"; -- PHP-FPM | ||
|
||
require_once "lib/Cleantalk.php"; | ||
require_once "lib/CleantalkHelper.php"; | ||
require_once "lib/CleantalkRequest.php"; | ||
require_once "lib/CleantalkResponse.php"; | ||
|
||
use Cleantalk\Cleantalk; | ||
use Cleantalk\CleantalkRequest; | ||
|
||
// Take params from config | ||
$config_url = 'http://moderate.cleantalk.org/api2.0/'; | ||
$auth_key = 'enter key'; // Set Cleantalk auth key | ||
|
||
if (count($_POST)) { | ||
$sender_nickname = 'John Dow'; | ||
if (isset($_POST['login']) && $_POST['login'] != '') | ||
$sender_nickname = $_POST['login']; | ||
|
||
$sender_email = '[email protected]'; | ||
if (isset($_POST['email']) && $_POST['email'] != '') | ||
$sender_email = $_POST['email']; | ||
|
||
$sender_ip = null; | ||
if (isset($_SERVER['REMOTE_ADDR'])) | ||
$sender_ip = $_SERVER['REMOTE_ADDR']; | ||
|
||
$js_on = 0; | ||
if (isset($_POST['js_on']) && $_POST['js_on'] == date("Y")) | ||
$js_on = 1; | ||
|
||
// The facility in which to store the query parameters | ||
$ct_request = new CleantalkRequest(); | ||
|
||
$ct_request->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 '<br /><br />'; | ||
} | ||
else | ||
{ | ||
$_SESSION['ct_submit_time'] = time(); | ||
} | ||
?> | ||
|
||
<form method="post"> | ||
<label for="login">Login:<label> | ||
<input type="text" name="login" id="login" /> | ||
<br /> | ||
<label for="email">Email:<label> | ||
<input type="text" name="email" id="email" value="" /> | ||
<br /> | ||
<input type="hidden" name="js_on" id="js_on" value="0" /> | ||
<input type="submit" /> | ||
</form> | ||
|
||
<script type="text/javascript"> | ||
var date = new Date(); | ||
document.getElementById("js_on").value = date.getFullYear(); | ||
</script> | ||
composer require cleantalk/php-antispam | ||
``` | ||
|
||
## Sample SPAM test for text comment | ||
### Sample SPAM test for text comment and user signup | ||
|
||
```php | ||
<?php | ||
|
||
session_start(); | ||
|
||
//require_once "vendor/autoload.php"; -- Composer | ||
$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; | ||
|
||
//require_once "lib/cleantalk-php-patch.php"; -- PHP-FPM | ||
|
||
require_once "lib/Cleantalk.php"; | ||
require_once "lib/CleantalkHelper.php"; | ||
require_once "lib/CleantalkRequest.php"; | ||
require_once "lib/CleantalkResponse.php"; | ||
|
||
use Cleantalk\Cleantalk; | ||
use Cleantalk\CleantalkRequest; | ||
|
||
// Take params from config | ||
$config_url = 'http://moderate.cleantalk.org/api2.0/'; | ||
$auth_key = 'enter key'; // Set Cleantalk auth key | ||
|
||
if (count($_POST)) { | ||
$sender_nickname = 'John Dow'; | ||
if (isset($_POST['login']) && $_POST['login'] != '') | ||
$sender_nickname = $_POST['login']; | ||
|
||
$sender_email = '[email protected]'; | ||
if (isset($_POST['email']) && $_POST['email'] != '') | ||
$sender_email = $_POST['email']; | ||
|
||
$sender_ip = null; | ||
if (isset($_SERVER['REMOTE_ADDR'])) | ||
$sender_ip = $_SERVER['REMOTE_ADDR']; | ||
|
||
$js_on = 0; | ||
if (isset($_POST['js_on']) && $_POST['js_on'] == date("Y")) | ||
$js_on = 1; | ||
|
||
$message = null; | ||
if (isset($_POST['message']) && $_POST['message'] != '') | ||
$message = $_POST['message']; | ||
|
||
// The facility in which to store the query parameters | ||
$ct_request = new CleantalkRequest(); | ||
|
||
$ct_request->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 '<br /><br />'; | ||
} | ||
else | ||
{ | ||
$_SESSION['ct_submit_time'] = time(); | ||
} | ||
$cleantalk_antispam = new CleantalkAntispam($apikey, $email_field, $user_name_field, $message_field, $type_form); | ||
$cleantalk_antispam->handle(); | ||
?> | ||
|
||
<form method="post"> | ||
<label for="login">Login:<label> | ||
<input type="text" name="login" id="login" /> | ||
<label for="login">Login:</label> | ||
<input type="text" name="name_user_name_form_field" id="login" /> | ||
<br /> | ||
<label for="email">Email:<label> | ||
<input type="text" name="email" id="email" value="" /> | ||
<label for="email">Email:</label> | ||
<input type="text" name="name_email_form_field" id="email" value="" /> | ||
<br /> | ||
<label for="message">Message:<label> | ||
<textarea name="message" id="message"></textarea> | ||
<label for="message">Message:</label> | ||
<textarea name="name_message_form_field" id="message"></textarea> | ||
<br /> | ||
<input type="hidden" name="js_on" id="js_on" value="0" /> | ||
<input type="submit" /> | ||
</form> | ||
|
||
<script type="text/javascript"> | ||
var date = new Date(); | ||
document.getElementById("js_on").value = date.getFullYear(); | ||
</script> | ||
<?php $cleantalk_antispam->frontendScript(); ?> | ||
``` | ||
|
||
|
||
## API Response description | ||
API returns PHP object: | ||
* allow (0|1) - allow to publish or not, in other words spam or ham | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
require_once "lib/Cleantalk.php"; | ||
require_once "lib/CleantalkHelper.php"; | ||
require_once "lib/CleantalkRequest.php"; | ||
require_once "lib/CleantalkResponse.php"; | ||
require_once "lib/CleantalkAntispam.php"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,56 @@ | ||
<?php | ||
//require_once "vendor/autoload.php"; -- Composer | ||
|
||
require_once "lib/Cleantalk.php"; | ||
require_once "lib/CleantalkRequest.php"; | ||
require_once "lib/CleantalkResponse.php"; | ||
require_once "lib/CleantalkHelper.php"; | ||
require_once "lib/CleantalkAPI.php"; | ||
|
||
/** | ||
* Cleantalk example | ||
* | ||
* @package Cleantalk Example | ||
* @copyright (C) 2011 - 2012 Сleantalk team (http://cleantalk.ru) | ||
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html | ||
* @see http://cleantalk.ru/wiki/doku.php/api | ||
* | ||
*/ | ||
|
||
use Cleantalk\CleantalkRequest; | ||
use Cleantalk\Cleantalk; | ||
use Cleantalk\CleantalkAPI; | ||
|
||
// Take params from config | ||
$config_url = 'http://moderate.cleantalk.ru'; | ||
$auth_key = null; // Set Cleantalk auth key | ||
|
||
|
||
// The facility in which to store the query parameters | ||
$ct_request = new CleantalkRequest(); | ||
|
||
$ct_request->auth_key = $auth_key; | ||
$ct_request->message = 'stop_word'; | ||
$ct_request->sender_email = '[email protected]'; | ||
$ct_request->sender_nickname = 'John Dow'; | ||
$ct_request->example = str_repeat('Just text ', 10); | ||
$ct_request->agent = 'php-api'; | ||
$ct_request->sender_ip = '178.32.183.43'; | ||
$ct_request->js_on = 1; # Site visitor has JavaScript | ||
$ct_request->submit_time = 12; # Seconds from start form filling till the form POST | ||
|
||
$ct = new Cleantalk(); | ||
$ct->server_url = $config_url; | ||
|
||
// Check | ||
$ct_result = $ct->isAllowMessage($ct_request); | ||
|
||
if ($ct_result->allow == 1) { | ||
echo 'Comment allowed. Reason ' . $ct_result->comment; | ||
} else { | ||
echo 'Comment blocked. Reason ' . $ct_result->comment; | ||
} | ||
echo "<br/>CleantalkAPI call example:<br/>"; | ||
var_dump(CleantalkAPI::method__notice_validate_key('','')); | ||
?> | ||
<?php | ||
//require_once "vendor/autoload.php"; -- Composer | ||
|
||
require_once "lib/Cleantalk.php"; | ||
require_once "lib/CleantalkRequest.php"; | ||
require_once "lib/CleantalkResponse.php"; | ||
require_once "lib/CleantalkHelper.php"; | ||
require_once "lib/CleantalkAPI.php"; | ||
require_once "lib/cleantalk-php-patch.php"; | ||
|
||
/** | ||
* Cleantalk example | ||
* | ||
* @package Cleantalk Example | ||
* @copyright (C) 2011 - 2012 Сleantalk team (http://cleantalk.ru) | ||
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html | ||
* @see http://cleantalk.ru/wiki/doku.php/api | ||
* | ||
*/ | ||
|
||
use Cleantalk\CleantalkRequest; | ||
use Cleantalk\Cleantalk; | ||
use Cleantalk\CleantalkAPI; | ||
|
||
// Take params from config | ||
$config_url = 'https://moderate.cleantalk.org'; | ||
$auth_key = null; // Set Cleantalk auth key | ||
|
||
|
||
// The facility in which to store the query parameters | ||
$ct_request = new CleantalkRequest(); | ||
|
||
$ct_request->auth_key = $auth_key; | ||
$ct_request->message = 'stop_word'; | ||
$ct_request->sender_email = '[email protected]'; | ||
$ct_request->sender_nickname = 'John Dow'; | ||
$ct_request->example = str_repeat('Just text ', 10); | ||
$ct_request->agent = 'php-api'; | ||
$ct_request->sender_ip = '178.32.183.43'; | ||
$ct_request->js_on = 1; # Site visitor has JavaScript | ||
$ct_request->submit_time = 12; # Seconds from start form filling till the form POST | ||
|
||
$ct = new Cleantalk(); | ||
$ct->server_url = $config_url; | ||
|
||
// Check | ||
$ct_result = $ct->isAllowMessage($ct_request); | ||
|
||
if ($ct_result->allow == 1) { | ||
echo 'Comment allowed. Reason ' . $ct_result->comment; | ||
} else { | ||
echo 'Comment blocked. Reason ' . $ct_result->comment; | ||
} | ||
echo "<br/>CleantalkAPI call example:<br/>"; | ||
var_dump(CleantalkAPI::method__notice_validate_key('','')); | ||
?> |
Oops, something went wrong.