first commit
This commit is contained in:
330
modules/eicaptcha/src/ConfigForm.php
Normal file
330
modules/eicaptcha/src/ConfigForm.php
Normal file
@@ -0,0 +1,330 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2021 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author Hennes Hervé <contact@h-hennes.fr>
|
||||
* @copyright 2013-2021 Hennes Hervé
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* http://www.h-hennes.fr/blog/
|
||||
*/
|
||||
|
||||
namespace Eicaptcha\Module;
|
||||
|
||||
use Configuration;
|
||||
use Context;
|
||||
use EiCaptcha;
|
||||
use HelperForm;
|
||||
use Language;
|
||||
use Tools;
|
||||
|
||||
class ConfigForm
|
||||
{
|
||||
/**
|
||||
* @var EiCaptcha
|
||||
*/
|
||||
private $module;
|
||||
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
private $context;
|
||||
|
||||
/**
|
||||
* Installer constructor.
|
||||
*
|
||||
* @param EiCaptcha $module
|
||||
*/
|
||||
public function __construct(EiCaptcha $module)
|
||||
{
|
||||
$this->module = $module;
|
||||
$this->context = $this->module->getContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Form for module Configuration
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \PrestaShopDatabaseException
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
public function renderForm()
|
||||
{
|
||||
$fields_form = [
|
||||
'form' => [
|
||||
'legend' => [
|
||||
'title' => $this->l('Eicaptcha Configuration'),
|
||||
'icon' => 'icon-cogs',
|
||||
],
|
||||
'tabs' => [
|
||||
'general' => $this->l('General configuration'),
|
||||
'advanced' => $this->l('Advanded parameters'),
|
||||
],
|
||||
'description' => $this->l('To get your own public and private keys please click on the folowing link')
|
||||
. '<br /><a href="https://www.google.com/recaptcha/intro/index.html" target="_blank">https://www.google.com/recaptcha/intro/index.html</a>',
|
||||
'input' => [
|
||||
[
|
||||
'type' => 'radio',
|
||||
'label' => $this->l('Recaptcha Version'),
|
||||
'name' => 'CAPTCHA_VERSION',
|
||||
'required' => true,
|
||||
'class' => 't',
|
||||
'values' => [
|
||||
[
|
||||
'id' => 'v2',
|
||||
'value' => 2,
|
||||
'label' => $this->l('V2'),
|
||||
],
|
||||
[
|
||||
'id' => 'v3',
|
||||
'value' => 3,
|
||||
'label' => $this->l('V3'),
|
||||
],
|
||||
],
|
||||
'tab' => 'general',
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Captcha public key (Site key)'),
|
||||
'name' => 'CAPTCHA_PUBLIC_KEY',
|
||||
'required' => true,
|
||||
'empty_message' => $this->l('Please fill the captcha public key'),
|
||||
'tab' => 'general',
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Captcha private key (Secret key)'),
|
||||
'name' => 'CAPTCHA_PRIVATE_KEY',
|
||||
'required' => true,
|
||||
'empty_message' => $this->l('Please fill the captcha private key'),
|
||||
'tab' => 'general',
|
||||
],
|
||||
[
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Enable Captcha for contact form'),
|
||||
'name' => 'CAPTCHA_ENABLE_CONTACT',
|
||||
'required' => true,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'values' => [
|
||||
[
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled'),
|
||||
],
|
||||
[
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled'),
|
||||
],
|
||||
],
|
||||
'tab' => 'general',
|
||||
],
|
||||
[
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Enable Captcha for account creation'),
|
||||
'name' => 'CAPTCHA_ENABLE_ACCOUNT',
|
||||
'required' => true,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'values' => [
|
||||
[
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled'),
|
||||
],
|
||||
[
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled'),
|
||||
],
|
||||
],
|
||||
'tab' => 'general',
|
||||
],
|
||||
[
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Enable Captcha for newsletter registration'),
|
||||
'hint' => $this->l('Only availaibles in certain conditions*'),
|
||||
'name' => 'CAPTCHA_ENABLE_NEWSLETTER',
|
||||
'required' => true,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'values' => [
|
||||
[
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled'),
|
||||
],
|
||||
[
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled'),
|
||||
],
|
||||
],
|
||||
'tab' => 'general',
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Force Captcha language'),
|
||||
'hint' => $this->l('Language code ( en-GB | fr | de | de-AT | ... ) - Leave empty for autodetect'),
|
||||
'desc' => $this->l('For available language codes see: https://developers.google.com/recaptcha/docs/language'),
|
||||
'name' => 'CAPTCHA_FORCE_LANG',
|
||||
'required' => false,
|
||||
'tab' => 'general',
|
||||
],
|
||||
[
|
||||
'type' => 'radio',
|
||||
'label' => $this->l('Theme'),
|
||||
'name' => 'CAPTCHA_THEME',
|
||||
'required' => true,
|
||||
'is_bool' => true,
|
||||
'values' => [
|
||||
[
|
||||
'id' => 'clight',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Light'),
|
||||
],
|
||||
[
|
||||
'id' => 'cdark',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Dark'),
|
||||
],
|
||||
],
|
||||
'tab' => 'general',
|
||||
],
|
||||
[
|
||||
'type' => 'switch',
|
||||
'name' => 'CAPTCHA_DEBUG',
|
||||
'label' => $this->l('Enable Debug'),
|
||||
'hint' => $this->l('Use only for debug'),
|
||||
'desc' => sprintf(
|
||||
$this->l('Enable loging for debuging module, see file %s'),
|
||||
dirname(__FILE__) . '/logs/debug.log'
|
||||
),
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'values' => [
|
||||
[
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled'),
|
||||
],
|
||||
[
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled'),
|
||||
],
|
||||
],
|
||||
'tab' => 'advanced',
|
||||
],
|
||||
[
|
||||
'type' => 'html',
|
||||
'label' => $this->l('Check module installation'),
|
||||
'name' => 'enable_debug_html',
|
||||
'html_content' => '<a href="' . $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->module->name . '&tab_module=' . $this->module->tab . '&module_name=' . $this->module->name . '&display_debug=1&token=' . Tools::getAdminTokenLite('AdminModules') . '">' . $this->l('Check if module is well installed') . '</a>',
|
||||
'desc' => $this->l('click on this link will reload the page, please go again in tab "advanced parameters" to see the results'),
|
||||
'tab' => 'advanced',
|
||||
],
|
||||
],
|
||||
'submit' => [
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'button btn btn-default pull-right',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
//Display debug data to help detect issues
|
||||
if (Tools::getValue('display_debug')) {
|
||||
$fields_form['form']['input'][] = [
|
||||
'type' => 'html',
|
||||
'name' => 'debug_html',
|
||||
'html_content' => $this->module->getDebugger()->debugModuleInstall(),
|
||||
'tab' => 'advanced',
|
||||
];
|
||||
}
|
||||
|
||||
$helper = new HelperForm();
|
||||
$helper->show_toolbar = false;
|
||||
$lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
|
||||
$helper->default_form_language = $lang->id;
|
||||
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ?
|
||||
Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
||||
$helper->id = 'eicaptcha';
|
||||
$helper->submit_action = 'SubmitCaptchaConfiguration';
|
||||
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
|
||||
. '&configure=' . $this->module->name . '&tab_module=' . $this->module->tab . '&module_name=' . $this->module->name;
|
||||
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
||||
$helper->tpl_vars = [
|
||||
'fields_value' => $this->getConfigFieldsValues(),
|
||||
'languages' => $this->context->controller->getLanguages(),
|
||||
'id_language' => $this->context->language->id,
|
||||
];
|
||||
|
||||
return $helper->generateForm([$fields_form]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post Process in back office
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::isSubmit('SubmitCaptchaConfiguration')) {
|
||||
Configuration::updateValue('CAPTCHA_VERSION', Tools::getValue('CAPTCHA_VERSION'));
|
||||
Configuration::updateValue('CAPTCHA_PUBLIC_KEY', Tools::getValue('CAPTCHA_PUBLIC_KEY'));
|
||||
Configuration::updateValue('CAPTCHA_PRIVATE_KEY', Tools::getValue('CAPTCHA_PRIVATE_KEY'));
|
||||
Configuration::updateValue('CAPTCHA_ENABLE_ACCOUNT', (int) Tools::getValue('CAPTCHA_ENABLE_ACCOUNT'));
|
||||
Configuration::updateValue('CAPTCHA_ENABLE_CONTACT', (int) Tools::getValue('CAPTCHA_ENABLE_CONTACT'));
|
||||
Configuration::updateValue('CAPTCHA_ENABLE_NEWSLETTER', (int) Tools::getValue('CAPTCHA_ENABLE_NEWSLETTER'));
|
||||
Configuration::updateValue('CAPTCHA_FORCE_LANG', Tools::getValue('CAPTCHA_FORCE_LANG'));
|
||||
Configuration::updateValue('CAPTCHA_THEME', (int) Tools::getValue('CAPTCHA_THEME'));
|
||||
Configuration::updateValue('CAPTCHA_DEBUG', (int) Tools::getValue('CAPTCHA_DEBUG'));
|
||||
|
||||
return $this->module->displayConfirmation($this->l('Settings updated'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config values to hydrate the helperForm
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getConfigFieldsValues()
|
||||
{
|
||||
return [
|
||||
'CAPTCHA_VERSION' => Tools::getValue('CAPTCHA_VERSION', Configuration::get('CAPTCHA_VERSION')),
|
||||
'CAPTCHA_PRIVATE_KEY' => Tools::getValue('CAPTCHA_PRIVATE_KEY', Configuration::get('CAPTCHA_PRIVATE_KEY')),
|
||||
'CAPTCHA_PUBLIC_KEY' => Tools::getValue('CAPTCHA_PUBLIC_KEY', Configuration::get('CAPTCHA_PUBLIC_KEY')),
|
||||
'CAPTCHA_ENABLE_ACCOUNT' => Tools::getValue('CAPTCHA_ENABLE_ACCOUNT', Configuration::get('CAPTCHA_ENABLE_ACCOUNT')),
|
||||
'CAPTCHA_ENABLE_CONTACT' => Tools::getValue('CAPTCHA_ENABLE_CONTACT', Configuration::get('CAPTCHA_ENABLE_CONTACT')),
|
||||
'CAPTCHA_ENABLE_NEWSLETTER' => Tools::getValue('CAPTCHA_ENABLE_NEWSLETTER', Configuration::get('CAPTCHA_ENABLE_NEWSLETTER')),
|
||||
'CAPTCHA_FORCE_LANG' => Tools::getValue('CAPTCHA_FORCE_LANG', Configuration::get('CAPTCHA_FORCE_LANG')),
|
||||
'CAPTCHA_THEME' => Tools::getValue('CAPTCHA_THEME', Configuration::get('CAPTCHA_THEME')),
|
||||
'CAPTCHA_DEBUG' => Tools::getValue('CAPTCHA_DEBUG', Configuration::get('CAPTCHA_DEBUG')),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of l function with specific context
|
||||
*
|
||||
* @param string $trans
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function l($trans)
|
||||
{
|
||||
return $this->module->l($trans, 'configform');
|
||||
}
|
||||
}
|
||||
299
modules/eicaptcha/src/Debugger.php
Normal file
299
modules/eicaptcha/src/Debugger.php
Normal file
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2021 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author Hennes Hervé <contact@h-hennes.fr>
|
||||
* @copyright 2013-2021 Hennes Hervé
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* http://www.h-hennes.fr/blog/
|
||||
*/
|
||||
|
||||
namespace Eicaptcha\Module;
|
||||
|
||||
use Configuration;
|
||||
use EiCaptcha;
|
||||
use Module;
|
||||
|
||||
class Debugger
|
||||
{
|
||||
/**
|
||||
* @var EiCaptcha
|
||||
*/
|
||||
private $module;
|
||||
|
||||
/**
|
||||
* Installer constructor.
|
||||
*
|
||||
* @param EiCaptcha $module
|
||||
*/
|
||||
public function __construct(EiCaptcha $module)
|
||||
{
|
||||
$this->module = $module;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if needed composer directory is present
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function checkComposer()
|
||||
{
|
||||
if (!is_dir(_PS_MODULE_DIR_ . $this->module->name . '/vendor')) {
|
||||
$errorMessage = $this->l('This module need composer to work, please go into module directory %s and run composer install or dowload and install latest release from %s');
|
||||
|
||||
return $this->module->displayError(
|
||||
sprintf(
|
||||
$errorMessage,
|
||||
_PS_MODULE_DIR_ . $this->module->name,
|
||||
'https://github.com/nenes25/eicaptcha/releases'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if debug mode is enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDebugEnabled()
|
||||
{
|
||||
return (bool) Configuration::get('CAPTCHA_DEBUG');
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug module installation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function debugModuleInstall()
|
||||
{
|
||||
$errors = [];
|
||||
$success = [];
|
||||
|
||||
$modulesChecks = $this->checkModules();
|
||||
$hookChecks = $this->checkModuleHooks();
|
||||
$overridesChecks = $this->checkOverrides();
|
||||
$newsletterChecks = $this->checkNewsletter();
|
||||
|
||||
$errors = array_merge(
|
||||
$errors,
|
||||
$modulesChecks['errors'],
|
||||
$hookChecks['errors'],
|
||||
$overridesChecks['errors'],
|
||||
$newsletterChecks['errors']
|
||||
);
|
||||
|
||||
$success = array_merge(
|
||||
$success,
|
||||
$modulesChecks['success'],
|
||||
$hookChecks['success'],
|
||||
$overridesChecks['success'],
|
||||
$newsletterChecks['success']
|
||||
);
|
||||
|
||||
$this->module->getContext()->smarty->assign([
|
||||
'errors' => $errors,
|
||||
'success' => $success,
|
||||
'recaptchaVersion' => Configuration::get('CAPTCHA_VERSION'),
|
||||
'prestashopVersion' => _PS_VERSION_,
|
||||
'themeName' => _THEME_NAME_,
|
||||
'phpVersion' => phpversion(),
|
||||
]);
|
||||
|
||||
return $this->module->fetch('module:eicaptcha/views/templates/admin/debug.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check modules necessary for the module to work
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function checkModules()
|
||||
{
|
||||
$errors = $success = [];
|
||||
//Check if module version is compatible with current PS version
|
||||
if (!$this->module->checkCompliancy()) {
|
||||
$errors[] = $this->l('the module is not compatible with your version');
|
||||
} else {
|
||||
$success[] = $this->l('the module is compatible with your version');
|
||||
}
|
||||
|
||||
//Check if module contactform is installed
|
||||
if (!Module::isInstalled('contactform')) {
|
||||
$errors[] = $this->l('the module contatcform is not installed');
|
||||
} else {
|
||||
$success[] = $this->l('the module contactform is installed');
|
||||
}
|
||||
|
||||
return [
|
||||
'errors' => $errors,
|
||||
'success' => $success,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if module is well hooked on all necessary hooks
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function checkModuleHooks()
|
||||
{
|
||||
$errors = $success = [];
|
||||
$modulesHooks = [
|
||||
'header',
|
||||
'displayCustomerAccountForm',
|
||||
'actionContactFormSubmitCaptcha',
|
||||
'actionContactFormSubmitBefore',
|
||||
];
|
||||
foreach ($modulesHooks as $hook) {
|
||||
if (!$this->module->isRegisteredInHook($hook)) {
|
||||
$errors[] = sprintf(
|
||||
$this->l('the module is not registered in hook %s'),
|
||||
'<strong>' . $hook . '</strong>'
|
||||
);
|
||||
} else {
|
||||
$success[] = sprintf(
|
||||
$this->l('the module well registered in hook %s'),
|
||||
'<strong>' . $hook . '</strong>'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'errors' => $errors,
|
||||
'success' => $success,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that all overrides behaviors are good
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function checkOverrides()
|
||||
{
|
||||
$errors = $success = [];
|
||||
|
||||
//Check if override are disabled in configuration
|
||||
if (Configuration::get('PS_DISABLE_OVERRIDES') == 1) {
|
||||
$errors[] = $this->l('Overrides are disabled on your website');
|
||||
} else {
|
||||
$success[] = $this->l('Overrides are enabled on your website');
|
||||
}
|
||||
|
||||
//Check if file overrides exists
|
||||
if (!file_exists(_PS_OVERRIDE_DIR_ . 'controllers/front/AuthController.php')) {
|
||||
$errors[] = $this->l('AuthController.php override does not exists');
|
||||
} else {
|
||||
$success[] = $this->l('AuthController.php override exists');
|
||||
}
|
||||
|
||||
if (!file_exists(_PS_OVERRIDE_DIR_ . 'modules/contactform/contactform.php')) {
|
||||
$errors[] = $this->l('contactform.php override does not exists');
|
||||
} else {
|
||||
$success[] = $this->l('contactform.php override exists');
|
||||
}
|
||||
|
||||
//Check if file override is written in class_index.php files
|
||||
if (file_exists(_PS_CACHE_DIR_ . '/class_index.php')) {
|
||||
$classesArray = (include _PS_CACHE_DIR_ . '/class_index.php');
|
||||
if ($classesArray['AuthController']['path'] != 'override/controllers/front/AuthController.php') {
|
||||
$errors[] = $this->l('Authcontroller override is not present in class_index.php');
|
||||
} else {
|
||||
$success[] = $this->l('Authcontroller override is present in class_index.php');
|
||||
}
|
||||
} else {
|
||||
$errors[] = $this->l('no class_index.php found');
|
||||
}
|
||||
|
||||
return [
|
||||
'errors' => $errors,
|
||||
'success' => $success,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the newsletter configuration
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function checkNewsletter()
|
||||
{
|
||||
$errors = $success = [];
|
||||
|
||||
//Check if we can display the captcha in the newsletter
|
||||
if (!Module::isInstalled('ps_emailsubscription')) {
|
||||
$errors[] = $this->l('the module ps_emailsubscription is not installed you will not be able to use captcha on newslettter');
|
||||
} else {
|
||||
if ($this->module->canUseCaptchaOnNewsletter()) {
|
||||
$success[] = $this->l('Module ps_emailsubscription version allow to use captcha on newsletter');
|
||||
$newsletterTemplateFile = _PS_THEME_DIR_ . 'modules/ps_emailsubscription/views/templates/hook/ps_emailsubscription.tpl';
|
||||
if (is_file($newsletterTemplateFile)) {
|
||||
$newsletterTemplateContent = file_get_contents($newsletterTemplateFile);
|
||||
if (!preg_match('#displayNewsletterRegistration#', $newsletterTemplateContent)) {
|
||||
$moduleDefaultFile = _PS_MODULE_DIR_ . 'ps_emailsubscription/views/templates/hook/ps_emailsubscription.tpl';
|
||||
$errors[] = sprintf(
|
||||
$this->l(
|
||||
'Missing hook %s in template %s , Please check in original module file to adapt : %s'
|
||||
),
|
||||
'<strong>displayNewsletterRegistration</strong>',
|
||||
'<i>' . $newsletterTemplateFile . '</i>',
|
||||
'<i>' . $moduleDefaultFile . '</i>'
|
||||
);
|
||||
}
|
||||
//@Todo manage multi-shop configuration
|
||||
} else {
|
||||
$errors[] = $this->l('Module ps_emailsubscription version do not allow to use captcha on newsletter');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'errors' => $errors,
|
||||
'success' => $success,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Log debug messages
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function log($message)
|
||||
{
|
||||
if ($this->isDebugEnabled()) {
|
||||
file_put_contents(
|
||||
dirname(__FILE__) . '/logs/debug.log',
|
||||
date('Y-m-d H:i:s') . ': ' . $message . "\n",
|
||||
FILE_APPEND
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of l function with specific context
|
||||
*
|
||||
* @param string $trans
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function l($trans)
|
||||
{
|
||||
return $this->module->l($trans, 'debugger');
|
||||
}
|
||||
}
|
||||
112
modules/eicaptcha/src/Installer.php
Normal file
112
modules/eicaptcha/src/Installer.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2021 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author Hennes Hervé <contact@h-hennes.fr>
|
||||
* @copyright 2013-2021 Hennes Hervé
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* http://www.h-hennes.fr/blog/
|
||||
*/
|
||||
|
||||
namespace Eicaptcha\Module;
|
||||
|
||||
use Configuration;
|
||||
use EiCaptcha;
|
||||
|
||||
class Installer
|
||||
{
|
||||
/**
|
||||
* @var EiCaptcha
|
||||
*/
|
||||
private $module;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_hooks = [
|
||||
'displayHeader',
|
||||
'displayCustomerAccountForm',
|
||||
'displayNewsletterRegistration',
|
||||
'actionContactFormSubmitCaptcha',
|
||||
'actionContactFormSubmitBefore',
|
||||
'actionNewsletterRegistrationBefore',
|
||||
'actionAdminControllerSetMedia',
|
||||
];
|
||||
|
||||
/**
|
||||
* Installer constructor.
|
||||
*
|
||||
* @param EiCaptcha $module
|
||||
*/
|
||||
public function __construct(EiCaptcha $module)
|
||||
{
|
||||
$this->module = $module;
|
||||
}
|
||||
|
||||
/**
|
||||
* Eicaptcha Installer
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
return $this->installHooks() && $this->installConfigurations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Eicaptcha Uninstaller
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
return $this->uninstallConfigurations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Install Hooks
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function installHooks()
|
||||
{
|
||||
return $this->module->registerHook($this->_hooks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Install Configurations
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function installConfigurations()
|
||||
{
|
||||
return Configuration::updateGlobalValue('CAPTCHA_ENABLE_ACCOUNT', 0)
|
||||
&& Configuration::updateValue('CAPTCHA_ENABLE_CONTACT', 0)
|
||||
&& Configuration::updateValue('CAPTCHA_ENABLE_NEWSLETTER', 0)
|
||||
&& Configuration::updateValue('CAPTCHA_THEME', 0)
|
||||
&& Configuration::updateValue('CAPTCHA_DEBUG', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function uninstallConfigurations()
|
||||
{
|
||||
return Configuration::deleteByName('CAPTCHA_ENABLE_ACCOUNT')
|
||||
&& Configuration::deleteByName('CAPTCHA_ENABLE_CONTACT')
|
||||
&& Configuration::deleteByName('CAPTCHA_ENABLE_NEWSLETTER')
|
||||
&& Configuration::deleteByName('CAPTCHA_THEME')
|
||||
&& Configuration::deleteByName('CAPTCHA_DEBUG')
|
||||
&& Configuration::deleteByName('CAPTCHA_VERSION');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user