We wszystkich katalogach w katalogu override mam tylko plik index.php
Wyjątkiem jest katalog ovverride/controllers/admin gdzie jest plik AdminCustomerThreadsController.php:
<?php
/*
* tw
* dodane pola dla recapcha
*
*/
class AdminCustomerThreadsController extends AdminCustomerThreadsControllerCore {
public function __construct() {
parent::__construct();
$this->fields_options['contact']['fields']['PS_CUSTOMER_SERVICE_RECAPTCHA'] = array(
'title' => $this->l('Recaptcha protection'),
'hint' => $this->l('Enable or disable the anti-spam protection recaptcha.'),
'type' => 'bool'
);
$this->fields_options['contact']['fields']['PS_CUSTOMER_SERVICE_RECAPTCHA_SITE_KEY'] = array(
'title' => $this->l('Site key'),
'hint' => $this->l('Site key - recaptcha (https://www.google.com/recaptcha/).'),
'type' => 'text'
);
$this->fields_options['contact']['fields']['PS_CUSTOMER_SERVICE_RECAPTCHA_SECRET_KEY'] = array(
'title' => $this->l('Secret key'),
'hint' => $this->l('Secret key - recaptcha (https://www.google.com/recaptcha/).'),
'type' => 'text'
);
} // ------------------------------------------------------------------------------------------------------ __construct()
}
[b]oraz plik ContactController.php w katalogu ovverride/controllers/admin:[/b]
<?php
/**
* tw
* dodana obsluga recaptcha
*
*/
class ContactController extends ContactControllerCore {
public $recaptcha_on = false;
public $recaptcha_site_key;
public $recaptcha_secret_key;
/**
* tw
* dodana obsluga recaptcha
*
*/
public function __construct() {
parent::__construct();
// --- tw - konfiguracja recaptcha
$this->recaptcha_on = (bool)Configuration::get('PS_CUSTOMER_SERVICE_RECAPTCHA');
$this->recaptcha_site_key = trim(Configuration::get('PS_CUSTOMER_SERVICE_RECAPTCHA_SITE_KEY'));
$this->recaptcha_secret_key = trim(Configuration::get('PS_CUSTOMER_SERVICE_RECAPTCHA_SECRET_KEY'));
$this->context->smarty->assign(array(
'recaptchaON' => $this->recaptcha_on && (bool)$this->recaptcha_site_key && (bool)$this->recaptcha_secret_key,
'recaptchaSiteKey' => $this->recaptcha_site_key,
));
} // -------------------------------------------------------------------------------------------------- __construct()
/**
* tw
* dodana weryfikacja recaptcha
*
*/
public function postProcess() {
if (Tools::isSubmit('submitMessage')) {
if (!$this->recaptchaVerify()) { // weryfikacja recaptcha
$this->errors[] = Tools::displayError('Captcha error');
} else {
parent::postProcess();
}
}
} // -------------------------------------------------------------------------------------------------- postProcess()
/**
* tw
* weryfikacja recaptcha
*
*/
public function recaptchaVerify() {
if (!$this->recaptcha_on) {
return true;
}
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => [
'secret' => $this->recaptcha_secret_key,
'response' => Tools::getValue('g-recaptcha-response'),
'remoteip' => $_SERVER['REMOTE_ADDR']
],
CURLOPT_RETURNTRANSFER => true
]);
$response = curl_exec($curl);
curl_close($curl);
$captcha_success = json_decode($response, true);
return $captcha_success['success'];
} // -------------------------------------------------------------------------------------------------- recaptchaVerify()
}