Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
Glomberg committed Oct 14, 2020
2 parents d29c25a + d91dc0f commit c76298f
Show file tree
Hide file tree
Showing 19 changed files with 285 additions and 106 deletions.
7 changes: 4 additions & 3 deletions 2.3.x/install.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Antispam by Cleantalk</name>
<version>2.0</version>
<version>2.1</version>
<author>Cleantalk Inc.</author>
<link>https://cleantalk.org/</link>
<code>antispambycleantalk</code>
Expand All @@ -11,6 +11,7 @@
<search><![CDATA[$this->registry->set('openbay', new Openbay($this->registry));]]></search>
<add position="after"><![CDATA[
// AntiSpam By Cleantalk
require_once(DIR_SYSTEM . 'library/antispambycleantalk/Core.php');
$this->registry->set( 'apbct', AntispamByCleantalk\Core::get_instance( $this->registry ) );
$this->apbct->init( $this->config );
]]></add>
Expand All @@ -22,7 +23,7 @@
<operation>
<search><![CDATA[$data['scripts'] = $this->document->getScripts();]]></search>
<add position="before"><![CDATA[
$ver = '?v=' . $this->apbct::VERSION;
$ver = '?v=' . $this->apbct->get_version();
$this->document->addScript( 'catalog/view/javascript/antispambycleantalk.js' . $ver );
$this->apbct->setCookie();
]]></add>
Expand All @@ -35,7 +36,7 @@
{
if ( $this->request->server['REQUEST_METHOD'] == 'GET' && $this->config->get('module_antispambycleantalk_status') && $this->config->get('module_antispambycleantalk_enable_sfw') )
{
if( $this->apbct->rc::check($this->config->get('module_antispambycleantalk_access_key')) ) {
if( $this->apbct->rc->check($this->config->get('module_antispambycleantalk_access_key')) ) {
$this->apbct->rc->perform($this->config->get('module_antispambycleantalk_access_key'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public function index()
{
$this->install();

require_once(DIR_SYSTEM . 'library/antispambycleantalk/Core.php');
$this->registry->set( 'apbct', AntispamByCleantalk\Core::get_instance( $this->registry ) );

$data = $this->load->language('extension/module/antispambycleantalk');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct( $db_object, $db_prefix )
$this->table_prefix = $db_prefix;
}

public static function check()
public function check()
{
return isset($_GET['spbc_remote_call_token'], $_GET['spbc_remote_call_action'], $_GET['plugin_name']) && in_array(Get::get('plugin_name'), array('antispam','anti-spam', 'apbct'))
? true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cleantalk\Antispam;

use Cleantalk\Common\Get;
use Cleantalk\Common\Server;

/**
Expand Down Expand Up @@ -70,7 +71,7 @@ public function __construct( $db_object, $db_prefix )

$this->debug = isset($_GET['debug']) && intval($_GET['debug']) === 1 ? true : false;

$this->ip_array = $this->ip__get();
$this->ip_array = $this->ip__get( array('real'), true );
}

/**
Expand Down Expand Up @@ -294,33 +295,37 @@ public function sfw_update( $api_key, $immediate = false )
{
if( ! empty( $api_key ) ) {

$file_urls = isset( $_GET['file_urls'] ) ? urldecode( $_GET['file_urls'] ) : null;
$file_urls = isset( $file_urls ) ? explode( ',', $file_urls ) : null;
$api_server = !empty( Get::get( 'api_server' ) ) ? urldecode( Get::get( 'api_server' ) ) : null;
$data_id = !empty( Get::get( 'data_id' ) ) ? urldecode( Get::get( 'data_id' ) ) : null;
$file_url_nums = !empty( Get::get( 'file_url_nums' ) ) ? urldecode( Get::get( 'file_url_nums' ) ) : null;
$file_url_nums = isset($file_url_nums) ? explode(',', $file_url_nums) : null;

if( ! $file_urls ){
if( ! isset( $api_server, $data_id, $file_url_nums ) ){

$result = $this->get_sfw_file( $api_key, $immediate );

return ! empty( $result['error'] )
? $result
: true;

}elseif( is_array( $file_urls ) && count( $file_urls ) ){
}elseif( $api_server && $data_id && is_array( $file_url_nums ) && count( $file_url_nums ) ){

$result = $this->sfw_update_db( $file_urls[0] );
$result = $this->sfw_update_db( $api_server, $data_id, $file_url_nums[0] );

if( empty( $result['error'] ) ){

array_shift($file_urls);
array_shift( $file_url_nums );

if (count($file_urls)) {
if ( count( $file_url_nums ) ) {
Helper::http__request(
Server::get('HTTP_HOST'),
array(
'spbc_remote_call_token' => md5($api_key),
'spbc_remote_call_action' => 'sfw_update',
'plugin_name' => 'apbct',
'file_urls' => implode(',', $file_urls),
'api_server' => $api_server,
'data_id' => $data_id,
'file_url_nums' => implode(',', $file_url_nums),
),
array('get', 'async')
);
Expand Down Expand Up @@ -364,29 +369,40 @@ private function get_sfw_file( $api_key, $immediate )
}
}

$gf = \gzopen($result['file_url'], 'rb');
if (preg_match('/multifiles/', $result['file_url'])) {

if ($gf) {
$api_server = preg_replace( '@https://(api.*?)\.cleantalk\.org/.*?(bl_list_[0-9a-z]*?)\.multifiles\.csv\.gz@', '$1', $result['file_url'] );
$data_id = preg_replace( '@https://(api.*?)\.cleantalk\.org/.*?(bl_list_[0-9a-z]*?)\.multifiles\.csv\.gz@', '$2', $result['file_url'] );

$file_urls = array();
$gf = \gzopen($result['file_url'], 'rb');

while( ! \gzeof($gf) )
$file_urls[] = trim( \gzgets($gf, 1024) );
if ($gf) {

\gzclose($gf);
$file_url_nums = array();

return Helper::http__request(
Server::get('HTTP_HOST'),
array(
'spbc_remote_call_token' => md5( $api_key ),
'spbc_remote_call_action' => 'sfw_update',
'plugin_name' => 'apbct',
'file_urls' => implode( ',', $file_urls ),
),
$pattenrs
);
}else
return array('error' => 'COULD_NOT_OPEN_REMOTE_FILE_SFW');
while( ! \gzeof($gf) ) {
$file_url = trim( \gzgets($gf, 1024) );
$file_url_nums[] = preg_replace( '@(https://.*)\.(\d*)(\.csv\.gz)@', '$2', $file_url );
}

\gzclose($gf);

return Helper::http__request(
Server::get('HTTP_HOST'),
array(
'spbc_remote_call_token' => md5( $api_key ),
'spbc_remote_call_action' => 'sfw_update',
'plugin_name' => 'apbct',
'api_server' => $api_server,
'data_id' => $data_id,
'file_url_nums' => implode(',', $file_url_nums),
),
$pattenrs
);
}else
return array('error' => 'COULD_NOT_OPEN_REMOTE_FILE_SFW');
} else
return array('error' => 'COULD_NOT_GET_MULTIFILE');
}else
return array('error' => 'ERROR_ALLOW_URL_FOPEN_DISABLED');
}else
Expand All @@ -397,9 +413,11 @@ private function get_sfw_file( $api_key, $immediate )
return $result;
}

private function sfw_update_db( $file_url )
private function sfw_update_db( $api_server = null, $data_id = null, $file_url_num = null )
{
if(Helper::http__request($file_url, array(), 'get_code') === 200){ // Check if it's there
$file_url = 'https://' . $api_server . '.cleantalk.org/store/' . $data_id . '.' . $file_url_num . '.csv.gz';

if( Helper::http__request( $file_url, array(), 'get_code') === 200 ){ // Check if it's there

$gf = \gzopen($file_url, 'rb');

Expand Down
14 changes: 12 additions & 2 deletions 2.3.x/upload/system/library/antispambycleantalk/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Core
{
const VERSION = '2.0';
const VERSION = '2.1';

private $agent;

Expand Down Expand Up @@ -39,10 +39,20 @@ public static function get_instance( \Registry $registry )
return static::$instance;
}

/**
* Getting version number
*
* @return string
*/
public function get_version() {
return self::VERSION;
}

private function __construct( \Registry $registry )
{
$this->autoloader();
$this->agent = 'opencart-' . str_replace( '.', '', self::VERSION );
require_once 'php_fix.php';
$this->agent = 'opencart-' . str_replace( '.', '', $this->get_version() );
$this->rc = new RemoteCalls( $registry->get('db'), DB_PREFIX );
$this->sfw = new SFW( $registry->get('db'), DB_PREFIX );
}
Expand Down
27 changes: 27 additions & 0 deletions 2.3.x/upload/system/library/antispambycleantalk/php_fix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* Patch for apache_request_headers()
* If Apache web server is missing then making
*/
if( !function_exists('apache_request_headers') ){
function apache_request_headers(){

$headers = array();
foreach($_SERVER as $key => $val){
if(preg_match('/\AHTTP_/', $key)){
$server_key = preg_replace('/\AHTTP_/', '', $key);
$key_parts = explode('_', $server_key);
if(count($key_parts) > 0 and strlen($server_key) > 2){
foreach($key_parts as $part_index => $part){
$key_parts[$part_index] = function_exists('mb_strtolower') ? mb_strtolower($part) : strtolower($part);
$key_parts[$part_index][0] = strtoupper($key_parts[$part_index][0]);
}
$server_key = implode('-', $key_parts);
}
$headers[$server_key] = $val;
}
}
return $headers;
}
}
14 changes: 11 additions & 3 deletions 2.x - 2.2.x/install.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Antispam by Cleantalk</name>
<version>2.0</version>
<version>2.1</version>
<author>Cleantalk Inc.</author>
<link>https://cleantalk.org/</link>
<code>antispambycleantalk</code>
Expand All @@ -12,6 +12,7 @@
<search><![CDATA[$data['title'] = $this->document->getTitle();]]></search>
<add position="after"><![CDATA[
// AntiSpam By Cleantalk
require_once(DIR_SYSTEM . 'library/antispambycleantalk/Core.php');
$this->registry->set( 'apbct', AntispamByCleantalk\Core::get_instance( $this->registry ) );
$this->apbct->init( $this->config );
]]></add>
Expand All @@ -20,7 +21,7 @@
<operation>
<search><![CDATA[$data['scripts'] = $this->document->getScripts();]]></search>
<add position="before"><![CDATA[
$ver = '?v=' . $this->apbct::VERSION;
$ver = '?v=' . $this->apbct->get_version();
$this->document->addScript( 'catalog/view/javascript/antispambycleantalk.js' . $ver );
$this->apbct->setCookie();
]]></add>
Expand All @@ -33,7 +34,7 @@
{
if ( $this->request->server['REQUEST_METHOD'] == 'GET' && $this->config->get('module_antispambycleantalk_status') && $this->config->get('module_antispambycleantalk_enable_sfw') )
{
if( $this->apbct->rc::check($this->config->get('module_antispambycleantalk_access_key')) ) {
if( $this->apbct->rc->check($this->config->get('module_antispambycleantalk_access_key')) ) {
$this->apbct->rc->perform($this->config->get('module_antispambycleantalk_access_key'));
}
Expand Down Expand Up @@ -72,6 +73,7 @@
{
if ($this->config->get('module_antispambycleantalk_status') && $this->config->get('module_antispambycleantalk_check_registrations'))
{
require_once(DIR_SYSTEM . 'library/antispambycleantalk/Core.php');
$this->registry->set( 'apbct', AntispamByCleantalk\Core::get_instance( $this->registry ) );
$this->apbct->init( $this->config );
if( $this->apbct->is_spam( $this ) )
Expand Down Expand Up @@ -103,6 +105,7 @@
{
if ($this->config->get('module_antispambycleantalk_status') && $this->config->get('module_antispambycleantalk_check_registrations'))
{
require_once(DIR_SYSTEM . 'library/antispambycleantalk/Core.php');
$this->registry->set( 'apbct', AntispamByCleantalk\Core::get_instance( $this->registry ) );
$this->apbct->init( $this->config );
if( $this->apbct->is_spam( $this ) )
Expand Down Expand Up @@ -134,6 +137,7 @@
{
if ($this->config->get('module_antispambycleantalk_status') && $this->config->get('module_antispambycleantalk_check_orders'))
{
require_once(DIR_SYSTEM . 'library/antispambycleantalk/Core.php');
$this->registry->set( 'apbct', AntispamByCleantalk\Core::get_instance( $this->registry ) );
$this->apbct->init( $this->config );
if( $this->apbct->is_spam( $this ) )
Expand All @@ -154,6 +158,7 @@
if ($this->config->get('module_antispambycleantalk_status') && $this->config->get('module_antispambycleantalk_check_return'))
{
require_once(DIR_SYSTEM . 'library/antispambycleantalk/Core.php');
$this->registry->set( 'apbct', AntispamByCleantalk\Core::get_instance( $this->registry ) );
$this->apbct->init( $this->config );
if( $this->apbct->is_spam( $this ) )
Expand All @@ -172,6 +177,7 @@
{
if ($this->config->get('module_antispambycleantalk_status') && $this->config->get('module_antispambycleantalk_check_orders'))
{
require_once(DIR_SYSTEM . 'library/antispambycleantalk/Core.php');
$this->registry->set( 'apbct', AntispamByCleantalk\Core::get_instance( $this->registry ) );
$this->apbct->init( $this->config );
if( $this->apbct->is_spam( $this ) )
Expand All @@ -190,6 +196,7 @@
{
if ($this->config->get('module_antispambycleantalk_status') && $this->config->get('module_antispambycleantalk_check_reviews'))
{
require_once(DIR_SYSTEM . 'library/antispambycleantalk/Core.php');
$this->registry->set( 'apbct', AntispamByCleantalk\Core::get_instance( $this->registry ) );
$this->apbct->init( $this->config );
if( $this->apbct->is_spam( $this ) )
Expand All @@ -208,6 +215,7 @@
{
if ($this->config->get('module_antispambycleantalk_status') && $this->config->get('module_antispambycleantalk_check_registrations'))
{
require_once(DIR_SYSTEM . 'library/antispambycleantalk/Core.php');
$this->registry->set( 'apbct', AntispamByCleantalk\Core::get_instance( $this->registry ) );
$this->apbct->init( $this->config );
if( $this->apbct->is_spam( $this ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ControllerModuleAntispamByCleantalk extends Controller {
public function index() {
$this->install();

require_once(DIR_SYSTEM . 'library/antispambycleantalk/Core.php');
$this->registry->set( 'apbct', AntispamByCleantalk\Core::get_instance( $this->registry ) );

$data = $this->load->language('module/antispambycleantalk');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct( $db_object, $db_prefix )
$this->table_prefix = $db_prefix;
}

public static function check()
public function check()
{
return isset($_GET['spbc_remote_call_token'], $_GET['spbc_remote_call_action'], $_GET['plugin_name']) && in_array(Get::get('plugin_name'), array('antispam','anti-spam', 'apbct'))
? true
Expand Down
Loading

0 comments on commit c76298f

Please sign in to comment.