[BUGFIX] Word list when renewing captcha image is in wrong language 39/46439/2
authorStanislas Rolland <typo3@sjbr.ca>
Tue, 2 Feb 2016 04:43:35 +0000 (23:43 -0500)
committerStanislas Rolland <typo3@sjbr.ca>
Tue, 2 Feb 2016 04:46:44 +0000 (05:46 +0100)
Resolves: #73075
Change-Id: I6688e83f9ea90c909117b09e7ae924248ac0784c
Reviewed-on: https://review.typo3.org/46439
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
ChangeLog
Classes/Utility/EidUtility.php
Classes/Utility/LocalizationUtility.php
Classes/ViewHelpers/ImageViewHelper.php

index 735871c..4ef6f91 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2016-02-01  Stanislas Rolland  <typo(arobas)sjbr.ca>
        * Cleanup in ImageViewHelper
        * Correction to composer.json
+       * Resolves #73075: Word list used when renewing captcha image is in wrong language
 
 2015-11-02  Stanislas Rolland  <typo(arobas)sjbr.ca>
 
index abdf356..c011c8b 100644 (file)
@@ -151,9 +151,8 @@ class EidUtility {
                }
                $this->pageUid = htmlspecialchars($this->pageUid);
                $MP = htmlspecialchars(GeneralUtility::_GET('MP'));
-               $GLOBALS['TSFE'] = $this->objectManager->get('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', $GLOBALS['TYPO3_CONF_VARS'], $this->pageUid, '0', TRUE, '', '', $MP, '');
                \TYPO3\CMS\Frontend\Utility\EidUtility::initTCA();
-               $GLOBALS['TSFE']->sys_page = $this->objectManager->get('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
+               $GLOBALS['TSFE'] = $this->objectManager->get('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', $GLOBALS['TYPO3_CONF_VARS'], $this->pageUid, 0, true, '', '', $MP, '');
                $GLOBALS['TSFE']->initFeUser();
                $GLOBALS['TSFE']->determineId();
                return $this;
index 88174ed..6a729f4 100644 (file)
@@ -1,10 +1,11 @@
 <?php
 namespace SJBR\SrFreecap\Utility;
+
 /***************************************************************
  *  Copyright notice
  *
  *  (c) 2009 Sebastian Kurf├╝rst <sebastian@typo3.org>
- *  (c) 2013 Stanislas Rolland <typo3@sjbr.ca>
+ *  (c) 2013-2016 Stanislas Rolland <typo3@sjbr.ca>
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -23,6 +24,11 @@ namespace SJBR\SrFreecap\Utility;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
+use TYPO3\CMS\Core\Localization\Locales;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Localization helper which should be used to fetch appropriate words list or voice rendering language
  *
@@ -56,13 +62,14 @@ class LocalizationUtility {
         * @param string $defaultWordsList: location of the default words list
         * @return string the location of the words list to be used
         */
-       public static function getWordsListLocation($defaultWordsList = '') {
+       public static function getWordsListLocation($defaultWordsList = '')
+       {
                self::setLanguageKeys();
                $initialWordsList = $defaultWordsList;
                if (!trim($initialWordsList)) {
                        $initialWordsList = 'EXT:' . self::$extensionKey . '/Resources/Private/Captcha/Words/default_freecap_words';
                }
-               $path = dirname(\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($initialWordsList)) . '/';
+               $path = dirname(GeneralUtility::getFileAbsFileName($initialWordsList)) . '/';
                $wordsListLocation = $path . self::$languageKey . '_freecap_words';
                if (!is_file($wordsListLocation)) {
                        foreach (self::$alternativeLanguageKeys as $language) {
@@ -77,7 +84,6 @@ class LocalizationUtility {
                        if (!is_file($wordsListLocation)) {
                                $wordsListLocation = '';
                        }
-                       
                }
                return $wordsListLocation;
        }
@@ -87,9 +93,10 @@ class LocalizationUtility {
         *
         * @return string name of the directory containing the wav files to be used
         */
-       public static function getVoicesDirectory() {
+       public static function getVoicesDirectory()
+       {
                self::setLanguageKeys();
-               $path = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(self::$extensionKey) . 'Resources/Private/Captcha/Voices/';
+               $path = ExtensionManagementUtility::extPath(self::$extensionKey) . 'Resources/Private/Captcha/Voices/';
                $voicesDirectory = $path . self::$languageKey . '/';
                if (!is_dir($voicesDirectory)) {
                        foreach (self::$alternativeLanguageKeys as $language) {
@@ -111,7 +118,8 @@ class LocalizationUtility {
         *
         * @return void
         */
-       protected static function setLanguageKeys() {
+       protected static function setLanguageKeys()
+       {
                self::$languageKey = 'default';
                self::$alternativeLanguageKeys = array();
                if (TYPO3_MODE === 'FE') {
@@ -120,8 +128,8 @@ class LocalizationUtility {
                                if (isset($GLOBALS['TSFE']->config['config']['language_alt'])) {
                                        self::$alternativeLanguageKeys[] = $GLOBALS['TSFE']->config['config']['language_alt'];
                                } else {
-                                       /** @var $locales \TYPO3\CMS\Core\Localization\Locales */
-                                       $locales = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\Locales');
+                                       /** @var $locales Locales */
+                                       $locales = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\Locales');
                                        if (in_array(self::$languageKey, $locales->getLocales())) {
                                                foreach ($locales->getLocaleDependencies(self::$languageKey) as $language) {
                                                        self::$alternativeLanguageKeys[] = $language;
@@ -129,11 +137,11 @@ class LocalizationUtility {
                                        }
                                }
                        }
-               } elseif (strlen($GLOBALS['BE_USER']->uc['lang']) > 0) {
+               } else if (strlen($GLOBALS['BE_USER']->uc['lang']) > 0) {
                        self::$languageKey = $GLOBALS['BE_USER']->uc['lang'];
                        // Get standard locale dependencies for the backend
-                       /** @var $locales \TYPO3\CMS\Core\Localization\Locales */
-                       $locales = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\Locales');
+                       /** @var $locales Locales */
+                       $locales = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\Locales');
                        if (in_array(self::$languageKey, $locales->getLocales())) {
                                foreach ($locales->getLocaleDependencies(self::$languageKey) as $language) {
                                        self::$alternativeLanguageKeys[] = $language;
@@ -141,5 +149,4 @@ class LocalizationUtility {
                        }
                }
        }
-}
-?>
\ No newline at end of file
+}
\ No newline at end of file
index ec49769..46bb14f 100644 (file)
@@ -89,6 +89,7 @@ class ImageViewHelper extends AbstractViewHelper
                // Generate the image url
                $fakeId = GeneralUtility::shortMD5(uniqid (rand()),5);
                $siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
+               $L = GeneralUtility::_GP('L');
                $urlParams = array(
                        'eID' => 'sr_freecap_EidDispatcher',
                        'id' => $GLOBALS['TSFE']->id,
@@ -98,14 +99,12 @@ class ImageViewHelper extends AbstractViewHelper
                        'controllerName' => 'ImageGenerator',
                        'actionName' => 'show',
                        'formatName' => 'png',
-                       'set' => $fakeId
+                       'L' => $GLOBALS['TSFE']->sys_language_uid
                );
-               if (isset($L)) {
-                       $urlParams['L'] = htmlspecialchars($L);
-               }
                if ($GLOBALS['TSFE']->MP) {
                        $urlParams['MP'] = $GLOBALS['TSFE']->MP;
                }
+               $urlParams['set'] = $fakeId;
                $imageUrl = $siteURL . 'index.php?' . ltrim(GeneralUtility::implodeArrayForUrl('', $urlParams), '&');
 
                // Generate the html text