local/modules/ReCaptcha/Hook/HookManager.php line 24

  1. <?php
  2. namespace ReCaptcha\Hook;
  3. use ReCaptcha\ReCaptcha;
  4. use Thelia\Core\Event\Hook\HookRenderEvent;
  5. use Thelia\Core\Hook\BaseHook;
  6. class HookManager extends BaseHook
  7. {
  8.     public function onModuleConfigure(HookRenderEvent $event)
  9.     {
  10.         $event->add(
  11.             $this->render(
  12.                 'recaptcha/configuration.html',
  13.                 [
  14.                     'with_contact_form' => defined('\Thelia\Core\Event\TheliaEvents::CONTACT_SUBMIT')
  15.                 ]
  16.             )
  17.         );
  18.     }
  19.     public function addRecaptchaCheckContact(HookRenderEvent $event)
  20.     {
  21.         // Ensure comptatibility with pre-2.4 versions
  22.         if (defined('\Thelia\Core\Event\TheliaEvents::CONTACT_SUBMIT')
  23.             &&
  24.             (bool) ReCaptcha::getConfigValue('add_to_contact_form')
  25.         ) {
  26.             $this->addRecaptchaCheck($event);
  27.         }
  28.     }
  29.     public function addRecaptchaCheck(HookRenderEvent $event)
  30.     {
  31.         $siteKey ReCaptcha::getConfigValue('site_key');
  32.         $captchaStyle ReCaptcha::getConfigValue('captcha_style');
  33.         $captchaId"recaptcha";
  34.         $captchaCallback "";
  35.         $type "";
  36.         if ($captchaStyle === 'invisible') {
  37.             $captchaCallback "data-callback='onCompleted'";
  38.             $type "g-invisible";
  39.             $captchaId .= '-invisible';
  40.         }
  41.         if (null !== $event->getArgument('id')) {
  42.             $captchaId $event->getArgument('id');
  43.         }
  44.         $event->add("<div id='$captchaId' class='g-recaptcha $type' data-sitekey='$siteKey$captchaCallback data-size='$captchaStyle'></div>");
  45.     }
  46.     public function loadRecaptcha(HookRenderEvent $event)
  47.     {
  48.         $siteKey ReCaptcha::getConfigValue('site_key');
  49.         $captchaStyle ReCaptcha::getConfigValue('captcha_style');
  50.         if ($captchaStyle !== 'invisible') {
  51.             $event->add($this->render(
  52.                 'recaptcha-js.html',
  53.                 [
  54.                     "siteKey" => $siteKey,
  55.                     "captchaStyle" => $captchaStyle,
  56.                 ]
  57.             ));
  58.             return;
  59.         }
  60.         $event->add($this->render(
  61.             'recaptcha-js-invisible.html',
  62.             [
  63.                 "siteKey" => $siteKey,
  64.                 "captchaStyle" => $captchaStyle,
  65.             ]
  66.         ));
  67.     }
  68. }