Skip to content

Commit

Permalink
update version
Browse files Browse the repository at this point in the history
  • Loading branch information
davydovct committed Aug 22, 2017
1 parent 570cb73 commit 8f1cdb0
Show file tree
Hide file tree
Showing 16 changed files with 802 additions and 1,287 deletions.
391 changes: 369 additions & 22 deletions CleanTalk/Base/CleanTalk.php
100644 → 100755

Large diffs are not rendered by default.

806 changes: 0 additions & 806 deletions CleanTalk/Base/JSON.php

This file was deleted.

122 changes: 84 additions & 38 deletions CleanTalk/Base/cleantalk.class.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cleantalk base class
*
* @version 2.1.2
* @version 2.1.3
* @package Cleantalk
* @subpackage Base
* @author Cleantalk team (welcome@cleantalk.org)
Expand All @@ -11,33 +11,43 @@
* @see https://github.com/CleanTalk/php-antispam
*
*/

/**
* Load JSON functions if they are not exists
/**
* Creating apache_request_headers() if not exists
*/
if(!function_exists('json_encode')) {
require_once 'JSON.php';

function json_encode($data) {
$json = new Services_JSON();
return( $json->encode($data) );
}

}
if(!function_exists('json_decode')) {
require_once 'JSON.php';

function json_decode($data) {
$json = new Services_JSON();
return( $json->decode($data) );
}
if( !function_exists('apache_request_headers') ) {
function apache_request_headers() {
$arh = array();
$rx_http = '/\AHTTP_/';
foreach($_SERVER as $key => $val) {
if( preg_match($rx_http, $key) ) {
$arh_key = preg_replace($rx_http, '', $key);
$rx_matches = array();
// do some nasty string manipulations to restore the original letter case
// this should work in most cases
$rx_matches = explode('_', $arh_key);
if( count($rx_matches) > 0 and strlen($arh_key) > 2 ) {
foreach($rx_matches as $ak_key => $ak_val) $rx_matches[$ak_key] = ucfirst($ak_val);
$arh_key = implode('-', $rx_matches);
}
$arh[$arh_key] = $val;
}
}
return( $arh );
}
}

/**
* Response class
*/
class CleantalkResponse {

/**
* Received feedback nubmer
* @var int
*/
public $received = null;

/**
* Is stop words
* @var int
Expand Down Expand Up @@ -172,6 +182,7 @@ function __construct($response = null, $obj = null) {
$this->stop_queue = (isset($obj->stop_queue)) ? $obj->stop_queue : 0;
$this->inactive = (isset($obj->inactive)) ? $obj->inactive : 0;
$this->account_status = (isset($obj->account_status)) ? $obj->account_status : -1;
$this->received = (isset($obj->received)) ? $obj->received : -1;

if ($this->errno !== 0 && $this->errstr !== null && $this->comment === null)
$this->comment = '*** ' . $this->errstr . ' Antispam service cleantalk.org ***';
Expand Down Expand Up @@ -376,7 +387,7 @@ class Cleantalk {
* Server connection timeout in seconds
* @var int
*/
private $server_timeout = 6;
private $server_timeout = 15;

/**
* Cleantalk server url
Expand Down Expand Up @@ -450,7 +461,7 @@ class Cleantalk {
* @return type
*/
public function isAllowMessage(CleantalkRequest $request) {
$this->filterRequest($request);
$request = $this->filterRequest($request);
$msg = $this->createMsg('check_message', $request);
return $this->httpRequest($msg);
}
Expand All @@ -461,7 +472,7 @@ public function isAllowMessage(CleantalkRequest $request) {
* @return type
*/
public function isAllowUser(CleantalkRequest $request) {
$this->filterRequest($request);
$request = $this->filterRequest($request);
$msg = $this->createMsg('check_newuser', $request);
return $this->httpRequest($msg);
}
Expand All @@ -473,7 +484,7 @@ public function isAllowUser(CleantalkRequest $request) {
* @return type
*/
public function sendFeedback(CleantalkRequest $request) {
$this->filterRequest($request);
$request = $this->filterRequest($request);
$msg = $this->createMsg('send_feedback', $request);
return $this->httpRequest($msg);
}
Expand All @@ -483,7 +494,7 @@ public function sendFeedback(CleantalkRequest $request) {
* @param CleantalkRequest $request
* @return type
*/
private function filterRequest(CleantalkRequest &$request) {
private function filterRequest(CleantalkRequest $request) {
// general and optional
foreach ($request as $param => $value) {
if (in_array($param, array('message', 'example', 'agent',
Expand Down Expand Up @@ -523,6 +534,7 @@ private function filterRequest(CleantalkRequest &$request) {
}
}
}
return $request;
}

/**
Expand Down Expand Up @@ -604,7 +616,16 @@ private function createMsg($method, CleantalkRequest $request) {
private function sendRequest($data = null, $url, $server_timeout = 3) {
// Convert to array
$data = (array)json_decode(json_encode($data), true);


//Cleaning from 'null' values
$tmp_data = array();
foreach($data as $key => $value){
if($value !== null)
$tmp_data[$key] = $value;
}
$data = $tmp_data;
unset($key, $value, $tmp_data);

// Convert to JSON
$data = json_encode($data);

Expand Down Expand Up @@ -708,7 +729,26 @@ private function sendRequest($data = null, $url, $server_timeout = 3) {
*/
private function httpRequest($msg) {
$result = false;
$msg->all_headers=json_encode(apache_request_headers());

if($msg->method_name != 'send_feedback'){
$ct_tmp = apache_request_headers();

if(isset($ct_tmp['Cookie']))
$cookie_name = 'Cookie';
elseif(isset($ct_tmp['cookie']))
$cookie_name = 'cookie';
else
$cookie_name = 'COOKIE';

$ct_tmp[$cookie_name] = preg_replace(array(
'/\s{0,1}ct_checkjs=[a-z0-9]*[;|$]{0,1}/',
'/\s{0,1}ct_timezone=.{0,1}\d{1,2}[;|$]/',
'/\s{0,1}ct_pointer_data=.*5D[;|$]{0,1}/',
'/;{0,1}\s{0,3}$/'
), '', $ct_tmp[$cookie_name]);
$msg->all_headers=json_encode($ct_tmp);
}

//$msg->remote_addr=$_SERVER['REMOTE_ADDR'];
//$msg->sender_info['remote_addr']=$_SERVER['REMOTE_ADDR'];
$si=(array)json_decode($msg->sender_info,true);
Expand Down Expand Up @@ -1050,16 +1090,19 @@ public function get_2s_blacklists_db ($api_key) {
* @return type
*/

function getAutoKey($email, $host, $platform)
if(!function_exists('getAutoKey'))
{
$request=Array();
$request['method_name'] = 'get_api_key';
$request['email'] = $email;
$request['website'] = $host;
$request['platform'] = $platform;
$url='https://api.cleantalk.org';
$result=sendRawRequest($url,$request);
return $result;
function getAutoKey($email, $host, $platform)
{
$request=Array();
$request['method_name'] = 'get_api_key';
$request['email'] = $email;
$request['website'] = $host;
$request['platform'] = $platform;
$url='https://api.cleantalk.org';
$result=sendRawRequest($url,$request);
return $result;
}
}

/**
Expand Down Expand Up @@ -1095,6 +1138,7 @@ function sendRawRequest($url,$data,$isJSON=false,$timeout=3)
if(!$isJSON)
{
$data=http_build_query($data);
$data=str_replace("&", "&", $data);
}
else
{
Expand Down Expand Up @@ -1129,8 +1173,10 @@ function sendRawRequest($url,$data,$isJSON=false,$timeout=3)
{
$opts = array(
'http'=>array(
'method'=>"POST",
'content'=>$data)
'method' => "POST",
'timeout'=> $timeout,
'content' => $data
)
);
$context = stream_context_create($opts);
$result = @file_get_contents($url, 0, $context);
Expand Down
Empty file modified CleanTalk/ControllerPublic/CleanTalkForum.php
100644 → 100755
Empty file.
Empty file modified CleanTalk/ControllerPublic/CleanTalkPost.php
100644 → 100755
Empty file.
Empty file modified CleanTalk/ControllerPublic/CleanTalkRegister.php
100644 → 100755
Empty file.
Empty file modified CleanTalk/ControllerPublic/CleanTalkThread.php
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions CleanTalk/Listener/LoadClassController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ public static function loadClassListenerThread($class, &$extend) {
$extend[] = 'CleanTalk_ControllerPublic_CleanTalkThread';
}
}

public static function loadClassListenerMisc($class, &$extend) {
if ($class == 'XenForo_ControllerPublic_Misc') {
$extend[] = 'CleanTalk_ControllerPublic_CleanTalkMisc';
}
}

}
Empty file modified CleanTalk/Listener/LoadClassModel.php
100644 → 100755
Empty file.
Loading

0 comments on commit 8f1cdb0

Please sign in to comment.