[TASK] Add javascript to footer 41/37741/2
authorSebastian Fischer <typo3@evoweb.de>
Wed, 11 Mar 2015 14:03:21 +0000 (15:03 +0100)
committerSebastian Fischer <typo3@evoweb.de>
Wed, 11 Mar 2015 15:53:01 +0000 (16:53 +0100)
Change-Id: Ia98fa37ee5312b2053029eb84d274e042ba36c59
Reviewed-on: http://review.typo3.org/37741
Reviewed-by: Sebastian Fischer <typo3@evoweb.de>
Tested-by: Sebastian Fischer <typo3@evoweb.de>
Classes/Adapter/SfRegisterAdapter.php [new file with mode: 0644]
Classes/Adapter/TypoScriptAdapter.php [new file with mode: 0644]
Classes/Services/Captcha/RecaptchaAdapter.php [deleted file]
Configuration/TypoScript/constants.txt
Configuration/TypoScript/setup.txt

diff --git a/Classes/Adapter/SfRegisterAdapter.php b/Classes/Adapter/SfRegisterAdapter.php
new file mode 100644 (file)
index 0000000..3afc1e1
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+namespace Evoweb\Recaptcha\Adapter;
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2015 Sebastian Fischer <typo3@evoweb.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Class RecaptchaAdapter
+ */
+class SfRegisterAdapter extends \Evoweb\SfRegister\Services\Captcha\AbstractAdapter {
+       /**
+        * Object manager
+        *
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
+        * @inject
+        */
+       protected $objectManager;
+
+       /**
+        * Captcha object
+        *
+        * @var \Evoweb\Recaptcha\Services\CaptchaService
+        */
+       protected $captcha = NULL;
+
+       /**
+        * Constructor
+        */
+       public function __construct() {
+               $this->captcha = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Evoweb\\Recaptcha\\Services\\CaptchaService');
+       }
+
+       /**
+        * Rendering the output of the captcha
+        *
+        * @return string
+        */
+       public function render() {
+               $this->objectManager->get('Evoweb\\SfRegister\\Services\\Session')->remove('captchaWasValidPreviously');
+
+               if ($this->captcha !== NULL) {
+                       $output = $this->captcha->getReCaptcha();
+               } else {
+                       $output = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               'error_captcha.notinstalled', 'Recaptcha', array('recaptcha')
+                       );
+               }
+
+               return $output;
+       }
+
+       /**
+        * Validate the captcha value from the request and output an error if not valid
+        *
+        * @param string $value
+        * @return bool
+        */
+       public function isValid($value) {
+               $validCaptcha = TRUE;
+
+               $session = $this->objectManager->get('Evoweb\\SfRegister\\Services\\Session');
+               $captchaWasValidPreviously = $session->get('captchaWasValidPreviously');
+               if ($this->captcha !== NULL && $captchaWasValidPreviously !== TRUE) {
+                       $status = $this->captcha->validateReCaptcha();
+
+                       if ($status == FALSE || $status['error'] !== '') {
+                               $validCaptcha = FALSE;
+                               $this->addError(
+                                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('error_recaptcha_' . $status['error'], 'Recaptcha'),
+                                       1307421960
+                               );
+                       }
+               }
+
+               $session->set('captchaWasValidPreviously', $validCaptcha);
+
+               return $validCaptcha;
+       }
+}
diff --git a/Classes/Adapter/TypoScriptAdapter.php b/Classes/Adapter/TypoScriptAdapter.php
new file mode 100644 (file)
index 0000000..149c505
--- /dev/null
@@ -0,0 +1,118 @@
+<?php
+namespace Evoweb\Recaptcha\Adapter;
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2015 Sebastian Fischer <typo3@evoweb.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Class RecaptchaAdapter
+ */
+class TypoScriptAdapter {
+       /**
+        * Captcha object
+        *
+        * @var \Evoweb\Recaptcha\Services\CaptchaService
+        */
+       protected $captcha = NULL;
+
+       /**
+        * Constructor
+        */
+       public function __construct() {
+               $this->captcha = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Evoweb\\Recaptcha\\Services\\CaptchaService');
+       }
+
+       /**
+        * Rendering the output of the captcha
+        *
+        * @return string
+        */
+       public function render() {
+               if ($this->captcha !== NULL) {
+                       $output = $this->captcha->getReCaptcha();
+               } else {
+                       $output = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               'error_captcha.notinstalled', 'Recaptcha', array('recaptcha')
+                       );
+               }
+
+               return $output;
+       }
+
+       /**
+        * Validate the captcha value from the request and output an error if not valid
+        *
+        * @return bool
+        */
+       public function validate() {
+               $validCaptcha = TRUE;
+
+               if ($this->captcha !== NULL) {
+                       $status = $this->captcha->validateReCaptcha();
+
+                       if ($status == FALSE || $status['error'] !== '') {
+                               $validCaptcha = FALSE;
+                               $this->renderFlashMessage(
+                                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('error_recaptcha_' . $status['error'], 'Recaptcha'),
+                                       1307421960
+                               );
+                       }
+               }
+
+               return $validCaptcha;
+       }
+
+       /**
+        * @param string $message
+        * @param int $type
+        * @throws \TYPO3\CMS\Core\Exception
+        */
+       protected function renderFlashMessage($message, $type = \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING) {
+               $code  = '
+               .typo3-message .message-header{padding: 10px 10px 0 30px;font-size:0.9em;}
+               .typo3-message .message-body{padding: 10px;font-size:0.9em;}
+               ';
+
+               /**
+                * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $frontend
+                */
+               $frontend = $GLOBALS['TSFE'];
+               $frontend->getPageRenderer()->addCssFile(
+                       \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('t3skin') . 'stylesheets/standalone/errorpage-message.css'
+               );
+               $frontend->getPageRenderer()->addCssInlineBlock('flashmessage', $code);
+
+               /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
+               $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                       'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
+                       $message,
+                       '',
+                       $type
+               );
+
+               /** @var \TYPO3\CMS\Core\Messaging\FlashMessageQueue $flashMessageQueue */
+               $flashMessageQueue = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                       'TYPO3\\CMS\\Core\\Messaging\\FlashMessageQueue'
+               );
+               $flashMessageQueue->enqueue($flashMessage);
+       }
+}
diff --git a/Classes/Services/Captcha/RecaptchaAdapter.php b/Classes/Services/Captcha/RecaptchaAdapter.php
deleted file mode 100644 (file)
index 27750ea..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-namespace Evoweb\Recaptcha\Services\Captcha;
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2015 Sebastian Fischer <typo3@evoweb.de>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-
-/**
- * Class RecaptchaAdapter
- */
-class RecaptchaAdapter extends \Evoweb\SfRegister\Services\Captcha\AbstractAdapter {
-       /**
-        * Object manager
-        *
-        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
-        * @inject
-        */
-       protected $objectManager;
-
-       /**
-        * Captcha object
-        *
-        * @var \Evoweb\Recaptcha\Services\CaptchaService
-        */
-       protected $captcha = NULL;
-
-       /**
-        * Constructor
-        */
-       public function __construct() {
-               $this->captcha = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Evoweb\\Recaptcha\\Services\\CaptchaService');
-       }
-
-       /**
-        * Rendering the output of the captcha
-        *
-        * @return string
-        */
-       public function render() {
-               $this->objectManager->get('Evoweb\\SfRegister\\Services\\Session')->remove('captchaWasValidPreviously');
-
-               if ($this->captcha !== NULL) {
-                       $output = $this->captcha->getReCaptcha();
-               } else {
-                       $output = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
-                               'error_captcha.notinstalled', 'Recaptcha', array('recaptcha')
-                       );
-               }
-
-               return $output;
-       }
-
-       /**
-        * Validate the captcha value from the request and output an error if not valid
-        *
-        * @param string $value
-        * @return bool
-        */
-       public function isValid($value) {
-               $validCaptcha = TRUE;
-
-               $session = $this->objectManager->get('Evoweb\\SfRegister\\Services\\Session');
-               $captchaWasValidPreviously = $session->get('captchaWasValidPreviously');
-               if ($this->captcha !== NULL && $captchaWasValidPreviously !== TRUE) {
-                       $status = $this->captcha->validateReCaptcha();
-
-                       if ($status == FALSE || $status['error'] !== '') {
-                               $validCaptcha = FALSE;
-                               $this->addError(
-                                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('error_recaptcha_' . $status['error'], 'Recaptcha'),
-                                       1307421960
-                               );
-                       }
-               }
-
-               $session->set('captchaWasValidPreviously', $validCaptcha);
-
-               return $validCaptcha;
-       }
-}
index 3dd478d..af84fee 100644 (file)
@@ -1,22 +1,22 @@
 plugin.tx_recaptcha {
-       # cat=plugin.recaptcha//01; type=string; label= reCAPTCHA public key: Public key of your reCAPTCHA-account
-       public_key = 6LdcuP4SAAAAAMPd3ETvHbvRG45odEPc_DkCRaTt
-
-       # cat=plugin.recaptcha//02; type=string; label= reCAPTCHA private key: Private key of your reCAPTCHA-account
-       private_key = 6LdcuP4SAAAAAMDK27S56123NMJKwc8KWeMnaTjj
-
-       # cat=plugin.recaptcha//03; type=string; label= reCAPTCHA API-server address
+       # cat=plugin.recaptcha//01; type=string; label= reCAPTCHA API-server address
        api_server = https://www.google.com/recaptcha/api.js
 
-       # cat=plugin.recaptcha//05; type=string; label= reCAPTCHA VERIFY-server address
+       # cat=plugin.recaptcha//02; type=string; label= reCAPTCHA VERIFY-server address
        verify_server = https://www.google.com/recaptcha/api/siteverify
 
-       # cat=plugin.recaptcha//08; type=int+; label= reCAPTCHA TabIndex: TabIndex of reCAPTCHA field
+       # look at https://www.google.com/recaptcha/admin to register a key for your server
+       # cat=plugin.recaptcha//03; type=string; label= reCAPTCHA public key: Public key of your reCAPTCHA-account
+       public_key = 6LfWWQMTAAAAAAtyIhXtt0E2t5F77l0wXCkRFv2O
+
+       # look at https://www.google.com/recaptcha/admin to register a key for your server
+       # cat=plugin.recaptcha//04; type=string; label= reCAPTCHA private key: Private key of your reCAPTCHA-account
+       private_key = 6LfWWQMTAAAAAAR_UGDnQ4ZqanjGJU64mjGcf_Jq
+
+
+       # cat=plugin.recaptcha//05; type=int+; label= reCAPTCHA TabIndex: TabIndex of reCAPTCHA field
        tabindex = 0
 
-       # cat=plugin.recaptcha//09; type=string; label= reCAPTCHA language: Language of reCAPTCHA frontend (autodetected if empty)
+       # cat=plugin.recaptcha//06; type=string; label= reCAPTCHA language: Language of reCAPTCHA frontend (autodetected if empty)
        lang =
 }
-
-page.includeJSFooterlibs.recaptcha < plugin.tx_recaptcha.api_server
-page.includeJSFooterlibs.recaptcha.external = 1
\ No newline at end of file
index 866eadb..a7e5f5e 100644 (file)
@@ -1,7 +1,9 @@
 plugin.tx_recaptcha {
+       # look at https://www.google.com/recaptcha/admin to register a key for your server
        public_key = {$plugin.tx_recaptcha.public_key}
        public_key.wrap = <div class="g-recaptcha" data-sitekey="|"></div>
 
+       # look at https://www.google.com/recaptcha/admin to register a key for your server
        private_key = {$plugin.tx_recaptcha.private_key}
 
        api_server = {$plugin.tx_recaptcha.api_server}
@@ -9,9 +11,10 @@ plugin.tx_recaptcha {
 
        tabindex = {$plugin.tx_recaptcha.tabindex}
        lang = {$plugin.tx_recaptcha.lang}
-
 }
 
+page.includeJSFooterlibs.recaptcha = {$plugin.tx_recaptcha.api_server}
+page.includeJSFooterlibs.recaptcha.external = 1
 
 // register recaptcha as captcha for sf_register
-plugin.tx_sfregister.settings.captcha.recaptcha = Evoweb\Recaptcha\Services\Captcha\RecaptchaAdapter
+plugin.tx_sfregister.settings.captcha.recaptcha = Evoweb\Recaptcha\Adapter\SfRegisterAdapter