Skip to content

Commit 0ef8160

Browse files
committed
Merge branch '17' of github.com:nenes25/eicaptcha into 17
2 parents d97ac3d + 1d7a1c0 commit 0ef8160

5 files changed

+23
-10
lines changed

changelog.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@
77
*/
88

99
- V 2.4.0 - 2022- #202 V2.3.1: les modes sombre et clair sont inversés
10-
#205 Captcha box is not visible (Clarify behavior of V3 keys )
10+
#205 Captcha box is not visible (Clarify behavior of V3 keys)
1111
#184 Don't require recaptcha for logged in clients
1212
#217 Allow to validate custom forms
1313
#169 Problème lors de la validation de mon formulaire
1414
#165 Rename Hook hookActionContactFormSubmitCaptcha
15-
- V 2.3.1 - 2021-09-29 : #201 Added displayNewsletterRegistration hook to installation method ( thanks to gdebrion )
15+
#162 V2.0.4 not detect PS language switching (thanks to metacreo)
16+
- V 2.3.1 - 2021-09-29 : #201 Added displayNewsletterRegistration hook to installation method (thanks to gdebrion)
1617
- V 2.3.0 - 2021-09-06 : #94 Recaptcha v3
1718
#188 Compatible with reCaptcha V3 (V2 is not available anymore on Google reCaptcha Entreprise)
1819
#113 not compatible with recaptcha V3
1920
#195 Improve debug information
2021
#196 Improve Code quality : introduce phpcsfixer and phpstan
2122
- V 2.2.0 - 2021-08-10 : Code refactoring
2223
- V 2.1.1 - 2021-04-16 : #186 Wrong ps_emailsubscription version comparison
23-
- V 2.1.0 - 2021-03-15 : Add support for newsletter registration ( in certain conditions )
24+
- V 2.1.0 - 2021-03-15 : Add support for newsletter registration (in certain conditions)
2425
#164 eicaptcha newsletter filtering
2526
#179 Better display debug mode in back office
2627
#180 Display link to github issues in debug module

eicaptcha.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class EiCaptcha extends Module
3535

3636
/** @var array */
3737
protected $themes = [];
38+
3839
/**
3940
* @var Debugger
4041
*/
@@ -45,6 +46,11 @@ class EiCaptcha extends Module
4546
*/
4647
protected $installer;
4748

49+
/**
50+
* @var string (2 or 3 digits Language ISO code) Captcha language (default: en)
51+
*/
52+
protected $captchaLang = 'en';
53+
4854
public function __construct()
4955
{
5056
$this->author = 'hhennes';
@@ -70,6 +76,12 @@ public function __construct()
7076
$this->ps_versions_compliancy = ['min' => '1.7.0.0', 'max' => _PS_VERSION_];
7177

7278
$this->debugger = new Debugger($this);
79+
80+
$this->captchaLang = $this->context->language->iso_code;
81+
$forceLang = Configuration::get('CAPTCHA_FORCE_LANG');
82+
if (!empty($forceLang) && Validate::isLanguageIsoCode($forceLang)) {
83+
$this->captchaLang = $forceLang;
84+
}
7385
}
7486

7587
/**
@@ -213,7 +225,7 @@ protected function renderHeaderV2()
213225
</script>';
214226

215227
if (($this->context->controller instanceof ContactController && Configuration::get('CAPTCHA_ENABLE_CONTACT') == 1)) {
216-
$js .= '<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit&hl=' . Configuration::get('CAPTCHA_FORCE_LANG') . '" async defer></script>';
228+
$js .= '<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit&hl=' . $this->captchaLang . '" async defer></script>';
217229
}
218230

219231
return $js;
@@ -260,7 +272,7 @@ public function hookDisplayCustomerAccountForm($params)
260272
$this->context->smarty->assign([
261273
'captchaVersion' => Configuration::get('CAPTCHA_VERSION'),
262274
'publicKey' => Configuration::get('CAPTCHA_PUBLIC_KEY'),
263-
'captchaforcelang' => Configuration::get('CAPTCHA_FORCE_LANG'),
275+
'captchalang' => $this->captchaLang,
264276
'captchatheme' => $this->themes[Configuration::get('CAPTCHA_THEME')],
265277
]);
266278

@@ -357,7 +369,7 @@ public function hookDisplayNewsletterRegistration($params)
357369
$this->context->smarty->assign([
358370
'captchaVersion' => Configuration::get('CAPTCHA_VERSION'),
359371
'publicKey' => Configuration::get('CAPTCHA_PUBLIC_KEY'),
360-
'captchaforcelang' => Configuration::get('CAPTCHA_FORCE_LANG'),
372+
'captchalang' => $this->captchaLang,
361373
'captchatheme' => $this->themes[Configuration::get('CAPTCHA_THEME')],
362374
]);
363375

@@ -457,7 +469,7 @@ public function hookDisplayEicaptchaVerification($params)
457469
'displayCaptcha' => $this->shouldDisplayToCustomer(),
458470
'captchaVersion' => Configuration::get('CAPTCHA_VERSION'),
459471
'publicKey' => Configuration::get('CAPTCHA_PUBLIC_KEY'),
460-
'captchaforcelang' => Configuration::get('CAPTCHA_FORCE_LANG'),
472+
'captchalang' => $this->captchaLang,
461473
'captchatheme' => $this->themes[Configuration::get('CAPTCHA_THEME')],
462474
]);
463475

views/templates/hook/hookDisplayCustomerAccountForm.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*}
3434
<div class="g-recaptcha" data-sitekey="{$publicKey|escape:'html'}" id="captcha-box"
3535
data-theme="{$captchatheme}"></div>
36-
<script src="https://www.google.com/recaptcha/api.js{if isset($captchaforcelang)}?hl={$captchaforcelang}{/if}"
36+
<script src="https://www.google.com/recaptcha/api.js?hl={$captchalang}"
3737
async defer></script>
3838
</div>
3939
{else}

views/templates/hook/hookDisplayEicaptchaVerification.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
{if $captchaVersion == 2}
2929
<div class="g-recaptcha" data-sitekey="{$publicKey|escape:'html'}" id="captcha-box-custom"
3030
data-theme="{$captchatheme}"></div>
31-
<script src="https://www.google.com/recaptcha/api.js{if isset($captchaforcelang)}?hl={$captchaforcelang}{/if}"
31+
<script src="https://www.google.com/recaptcha/api.js?hl={$captchalang}"
3232
async defer></script>
3333
{else}
3434
<input type="hidden" id="captcha-box-custom" name="g-recaptcha-response"/>

views/templates/hook/hookDisplayNewsletterRegistration.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<div class="col-xs-12 pull-right">
2727
{if $captchaVersion == 2}
2828
<div class="g-recaptcha" data-sitekey="{$publicKey|escape:'html'}" id="captcha-box-newsletter" data-theme="{$captchatheme}"></div>
29-
<script src="https://www.google.com/recaptcha/api.js{if isset($captchaforcelang)}?hl={$captchaforcelang}{/if}" async defer></script>
29+
<script src="https://www.google.com/recaptcha/api.js?hl={$captchalang}" async defer></script>
3030
{else}
3131
<input type="hidden" id="captcha-box-newsletter" name="g-recaptcha-response"/>
3232
<script src="https://www.google.com/recaptcha/api.js?render={$publicKey|escape:'html'}"></script>

0 commit comments

Comments
 (0)