[FEATURE] Migrate to TYPO3 9 LTS 54/58654/3 v2.5.0
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 18 Oct 2018 23:53:55 +0000 (19:53 -0400)
committerStanislas Rolland <typo3@sjbr.ca>
Fri, 19 Oct 2018 00:17:53 +0000 (02:17 +0200)
Use custom middleware for eid requests, use language context aspect,
adapt to changed API, etc.

Resolves: #86688
Change-Id: I842bef42106127518163dbf6d35d50d0fa2d9ca7
Reviewed-on: https://review.typo3.org/58654
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
24 files changed:
ChangeLog
Classes/Configuration/ConfigurationHelper.php
Classes/Controller/AudioPlayerController.php
Classes/Controller/ImageGeneratorController.php
Classes/Domain/Model/Font.php
Classes/Domain/Repository/FontRepository.php
Classes/Http/EidDispatcher.php [new file with mode: 0644]
Classes/Middleware/EidHandler.php [new file with mode: 0644]
Classes/PiBaseApi.php
Classes/Utility/EidUtility.php [deleted file]
Classes/Utility/FontMakingUtility.php
Classes/Utility/GifBuilderUtility.php
Classes/Utility/ImageContentUtility.php
Classes/Utility/LocalizationUtility.php
Classes/View/AudioPlayer/AbstractPlayFormat.php
Classes/View/AudioPlayer/PlayMp3.php
Classes/View/ImageGenerator/ShowPng.php
Classes/ViewHelpers/AudioViewHelper.php
Classes/ViewHelpers/ImageViewHelper.php
Classes/ViewHelpers/TranslateViewHelper.php
composer.json
doc/manual.sxw
ext_emconf.php
ext_localconf.php

index bf886c6..390453d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
 2018-10-18  Stanislas Rolland  <typo(arobas)sjbr.ca>
+       * Resolves #86688: Migrate to TYPO3 9 LTS
+       * Update version to 2.5.0
+
+2018-10-18  Stanislas Rolland  <typo(arobas)sjbr.ca>
        * Resolves #86691: Incorrect keywords for composer
        * Update version to 2.4.4
 
index dd7835f..c250bee 100644 (file)
@@ -27,7 +27,7 @@ namespace SJBR\SrFreecap\Configuration;
  *  This copyright notice MUST APPEAR in all copies of the script!
  */
 
-use TYPO3\CMS\Extensionmanager\ViewHelpers\Form\TypoScriptConstantsViewHelper;
+use TYPO3\CMS\Install\ViewHelpers\Form\TypoScriptConstantsViewHelper;
 
 /**
  * Class providing configuration help for extension SrFreecap
@@ -41,7 +41,7 @@ class ConfigurationHelper
         * @param TypoScriptConstantsViewHelper $pObj: The calling parent object.
         * @return string The HTML select field
         */
-       public function buildEncryptionAlgorithmSelector (array $params, TypoScriptConstantsViewHelper $pObj)
+       public function buildEncryptionAlgorithmSelector(array $params, TypoScriptConstantsViewHelper $pObj)
        {
                if (in_array('openssl', get_loaded_extensions())) {
                        $encryptionAlgorithms = openssl_get_cipher_methods(true);
index b8fc470..6fdbd87 100644 (file)
@@ -1,44 +1,47 @@
 <?php
 namespace SJBR\SrFreecap\Controller;
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2012-2015 Stanislas Rolland <typo3(arobas)sjbr.ca>
-*  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.
-*  A copy is found in the textfile GPL.txt and important notices to the license
-*  from the author is found in LICENSE.txt distributed with these scripts.
-*
-*
-*  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!
-***************************************************************/
-/**
- * Renders a wav audio version of the CAPTCHA
+
+/*
+ *  Copyright notice
+ *
+ *  (c) 2012-2018 Stanislas Rolland <typo3(arobas)sjbr.ca>
+ *  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.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
  *
- * @author     Stanislas Rolland       <typo3(arobas)sjbr.ca>
+ *
+ *  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 AudioPlayerController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
 
+use SJBR\SrFreecap\Domain\Repository\WordRepository;
+use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
+
+/**
+ * Renders a wav audio version of the CAPTCHA
+ */
+class AudioPlayerController extends ActionController
+{
        /**
         * @var string Name of the extension this controller belongs to
         */
        protected $extensionName = 'SrFreecap';
 
        /**
-        * @var \SJBR\SrFreecap\Domain\Repository\WordRepository
+        * @var WordRepository
         */
        protected $wordRepository;
 
@@ -47,9 +50,10 @@ class AudioPlayerController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionCont
         *
         * @return void
         */
-       protected function initializeAction() {
+       protected function initializeAction()
+       {
                // Get an instance of the word repository
-               $this->wordRepository = $this->objectManager->get('SJBR\\SrFreecap\\Domain\\Repository\\WordRepository');
+               $this->wordRepository = $this->objectManager->get(WordRepository::class);
        }
 
        /**
@@ -57,7 +61,8 @@ class AudioPlayerController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionCont
         *
         * @return string Audio content to be sent to the client
         */
-       public function playAction() {
+       public function playAction()
+       {
                $word = $this->wordRepository->getWord();
                $this->view->assign('word', $word);
        }
index 80ddfab..5847c78 100644 (file)
@@ -1,38 +1,44 @@
 <?php
 namespace SJBR\SrFreecap\Controller;
 
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2012-2015 Stanislas Rolland <typo3(arobas)sjbr.ca>
-*  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.
-*  A copy is found in the textfile GPL.txt and important notices to the license
-*  from the author is found in LICENSE.txt distributed with these scripts.
-*
-*
-*  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!
-***************************************************************/
-/**
- * Renders the CAPTCHA image
+/*
+ *  Copyright notice
+ *
+ *  (c) 2012-2018 Stanislas Rolland <typo3(arobas)sjbr.ca>
+ *  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.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
  *
- * @author     Stanislas Rolland       <typo3(arobas)sjbr.ca>
+ *  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 ImageGeneratorController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
 
+use SJBR\SrFreecap\Domain\Repository\WordRepository;
+use TYPO3\CMS\Core\Core\Environment;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
+use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
+
+/**
+ * Renders the CAPTCHA image
+ */
+class ImageGeneratorController extends ActionController
+{
        /**
         * @var string Name of the extension this controller belongs to
         */
@@ -44,7 +50,7 @@ class ImageGeneratorController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionC
        protected $extensionKey = 'sr_freecap';
 
        /**
-        * @var \SJBR\SrFreecap\Domain\Repository\WordRepository
+        * @var WordRepository
         */
        protected $wordRepository;
 
@@ -53,9 +59,10 @@ class ImageGeneratorController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionC
         *
         * @return void
         */
-       protected function initializeAction() {
+       protected function initializeAction()
+       {
                // Get an instance of the word repository
-               $this->wordRepository = $this->objectManager->get('SJBR\\SrFreecap\\Domain\\Repository\\WordRepository');
+               $this->wordRepository = $this->objectManager->get(WordRepository::class);
        }
 
        /**
@@ -63,7 +70,8 @@ class ImageGeneratorController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionC
         *
         * @return string empty string (image is sent by view)
         */
-       public function showAction() {
+       public function showAction()
+       {
                // Get session data
                $word = $this->wordRepository->getWord();
                // Which type of hash to use
@@ -85,20 +93,20 @@ class ImageGeneratorController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionC
         * @return void
         * @api
         */
-       protected function processSettings () {
-
+       protected function processSettings()
+       {
                // Image type:
                // possible values: "jpg", "png", "gif"
                // jpg doesn't support transparency (transparent bg option ends up white)
                // png isn't supported by old browsers (see http://www.libpng.org/pub/png/pngstatus.html)
                // gif may not be supported by your GD Lib.
                $this->settings['imageFormat'] = $this->settings['imageFormat'] ? $this->settings['imageFormat'] : 'png';
-               
+
                // true = generate pseudo-random string, false = use dictionary
                // dictionary is easier to recognise
                // - both for humans and computers, so use random string if you're paranoid.
-               $this->settings['useWordsList'] = $this->settings['useWordsList'] ? TRUE : FALSE;
-               
+               $this->settings['useWordsList'] = $this->settings['useWordsList'] ? true : false;
+
                // if your server is NOT set up to deny web access to files beginning ".ht"
                // then you should ensure the dictionary file is kept outside the web directory
                // eg: if www.foo.com/index.html points to c:\website\www\index.html
@@ -107,7 +115,7 @@ class ImageGeneratorController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionC
                // you should NOT be able to view the contents.
                // can leave this blank if not using dictionary
                $this->settings['wordsListLocation'] = \SJBR\SrFreecap\Utility\LocalizationUtility::getWordsListLocation($this->settings['defaultWordsList']);
-               
+
                // Used for non-dictionary word generation and to calculate image width
                $this->settings['maxWordLength'] = $this->settings['maxWordLength'] ? $this->settings['maxWordLength'] : 6;
 
@@ -130,24 +138,24 @@ class ImageGeneratorController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionC
                // so are not suitable for most other uses
                // to increase security, you really should add other fonts
                if ($this->settings['generateNumbers']) {
-                       $this->settings['fontLocations'] = Array('EXT:' . $this->extensionKey . '/Resources/Private/Captcha/Fonts/anonymous.gdf');
+                       $this->settings['fontLocations'] = ['EXT:' . $this->extensionKey . '/Resources/Private/Captcha/Fonts/anonymous.gdf'];
                } else {
-                       $this->settings['fontLocations'] = Array(
+                       $this->settings['fontLocations'] = [
                                'EXT:' . $this->extensionKey . '/Resources/Private/Captcha/Fonts/freecap_font1.gdf',
                                'EXT:' . $this->extensionKey . '/Resources/Private/Captcha/Fonts/freecap_font2.gdf',
                                'EXT:' . $this->extensionKey . '/Resources/Private/Captcha/Fonts/freecap_font3.gdf',
                                'EXT:' . $this->extensionKey . '/Resources/Private/Captcha/Fonts/freecap_font4.gdf',
                                'EXT:' . $this->extensionKey . '/Resources/Private/Captcha/Fonts/freecap_font5.gdf'
-                               );
+                               ];
                }
                if ($this->settings['fontFiles']) {
-                       $this->settings['fontLocations'] = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->settings['fontFiles'], 1);
+                       $this->settings['fontLocations'] = GeneralUtility::trimExplode(',', $this->settings['fontFiles'], 1);
                }
                for ($i = 0; $i < sizeof($this->settings['fontLocations']); $i++) {
                        if (substr($this->settings['fontLocations'][$i],0,4) == 'EXT:') {
-                               $this->settings['fontLocations'][$i] = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($this->settings['fontLocations'][$i]);
+                               $this->settings['fontLocations'][$i] = GeneralUtility::getFileAbsFileName($this->settings['fontLocations'][$i]);
                        } else {
-                               $this->settings['fontLocations'][$i] = PATH_site . 'uploads/' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getCN($this->extensionKey) . '/' . $this->settings['fontLocations'][$i];
+                               $this->settings['fontLocations'][$i] = Environment::getPublicPath() . '/uploads/' . ExtensionManagementUtility::getCN($this->extensionKey) . '/' . $this->settings['fontLocations'][$i];
                        }
                }
 
@@ -161,13 +169,13 @@ class ImageGeneratorController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionC
                }
 
                // Text position
-               $this->settings['textPosition'] = array();
+               $this->settings['textPosition'] = [];
                $this->settings['textPosition']['horizontal'] = $this->settings['textHorizontalPosition'] ? intval($this->settings['textHorizontalPosition']) : 32;
                $this->settings['textPosition']['vertical'] = $this->settings['textVerticalPosition'] ? intval($this->settings['textVerticalPosition']) : 15;
                // Text morphing factor
                $this->settings['morphFactor'] = $this->settings['morphFactor'] ? $this->settings['morphFactor'] : 0;
                // Limits for text color
-               $this->settings['colorMaximum'] = array();
+               $this->settings['colorMaximum'] = [];
                if (isset($this->settings['colorMaximumDarkness'])) {
                        $this->settings['colorMaximum']['darkness'] = intval($this->settings['colorMaximumDarkness']);
                }
@@ -178,29 +186,29 @@ class ImageGeneratorController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionC
                // Background
                // Many thanks to http://ocr-research.org.ua and http://sam.zoy.org/pwntcha/ for testing
                // for jpgs, 'transparent' is white
-               if (!in_array($this->settings['backgroundType'], array('Transparent', 'White with grid', 'White with squiggles', 'Morphed image blocks'))) {
+               if (!in_array($this->settings['backgroundType'], ['Transparent', 'White with grid', 'White with squiggles', 'Morphed image blocks'])) {
                        $this->settings['backgroundType'] = 'White with grid';
                }
                // Should we blur the background? (looks nicer, makes text easier to read, takes longer)
-               $this->settings['backgroundBlur'] = ($this->settings['backgroundBlur'] || !isset($this->settings['backgroundBlur'])) ? TRUE : FALSE;
+               $this->settings['backgroundBlur'] = ($this->settings['backgroundBlur'] || !isset($this->settings['backgroundBlur'])) ? true : false;
                // For background type 'Morphed image blocks', which images should we use?
                // If you add your own, make sure they're fairly 'busy' images (ie a lot of shapes in them)
-               $this->settings['backgroundImages'] = Array(
+               $this->settings['backgroundImages'] = [
                        'EXT:' . $this->extensionKey . '/Resources/Private/Captcha/Images/freecap_im1.jpg',
                        'EXT:' . $this->extensionKey . '/Resources/Private/Captcha/Images/freecap_im2.jpg',
                        'EXT:' . $this->extensionKey . '/Resources/Private/Captcha/Images/freecap_im3.jpg',
                        'EXT:' . $this->extensionKey . '/Resources/Private/Captcha/Images/freecap_im4.jpg',
                        'EXT:' . $this->extensionKey . '/Resources/Private/Captcha/Images/freecap_im5.jpg'
-                       );
+                       ];
                // For non-transparent backgrounds only:
                // if 0, merges CAPTCHA with background
                // if 1, write CAPTCHA over background
                $this->settings['mergeWithBackground'] = $this->settings['mergeWithBackground'] ? 0 : 1;
                // Should we morph the background? (recommend yes, but takes a little longer to compute)
-               $this->settings['backgroundMorph'] = $this->settings['backgroundMorph'] ? TRUE : FALSE;
-               
+               $this->settings['backgroundMorph'] = $this->settings['backgroundMorph'] ? true : false;
+
                // Read each font and get font character widths
-               $this->settings['fontWidths'] = Array();
+               $this->settings['fontWidths'] = [];
                for ($i=0 ; $i < sizeof($this->settings['fontLocations']); $i++)        {
                        $handle = fopen($this->settings['fontLocations'][$i],"r");
                        // Read header of GD font, up to char width
@@ -219,8 +227,8 @@ class ImageGeneratorController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionC
                // or more simply:
                // "for use only on example.org";
                // reword or add lines as you please
-               $this->settings['siteTag'] = $this->settings['siteTag'] ? explode('|', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('site_tag', $this->extensionName, isset($this->settings['siteTagDomain']) ? $this->settings['siteTagDomain'] : 'example.org')) : array();
-               
+               $this->settings['siteTag'] = $this->settings['siteTag'] ? explode('|', LocalizationUtility::translate('site_tag', $this->extensionName, [isset($this->settings['siteTagDomain']) ? $this->settings['siteTagDomain'] : 'example.org'])) : [];
+
                // where to write the above:
                // 0=top
                // 1=bottom
index 08cd691..c61ca88 100644 (file)
@@ -2,7 +2,7 @@
 declare(encoding='ISO-8859-2');
 namespace SJBR\SrFreecap\Domain\Model;
 
-/***************************************************************
+/*
  *  Copyright notice
  *
  *  (c) 2012-2018 Stanislas Rolland <typo3@sjbr.ca>
@@ -26,10 +26,12 @@ namespace SJBR\SrFreecap\Domain\Model;
  *  GNU General Public License for more details.
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ */
 
 use SJBR\SrFreecap\Utility\FontMakingUtility;
 use SJBR\SrFreecap\Validation\Validator\TtfFileValidator;
+use TYPO3\CMS\Core\Core\Environment;
+use TYPO3\CMS\Extbase\Annotation\Validate;
 use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
 
 /**
@@ -47,13 +49,13 @@ class Font extends AbstractEntity
 
        /**
         * @var int
-        * @validate NumberRange(minimum=5, maximum=255)
+        * @Validate("NumberRange", options={"minimum": 5, "maximum": 255})
         */
        protected $characterWidth;
 
        /**
         * @var int
-        * @validate NumberRange(minimum=5, maximum=255)
+        * @Validate("NumberRange", options={"minimum": 5, "maximum": 255})
         */
        protected $characterHeight;
 
@@ -64,9 +66,9 @@ class Font extends AbstractEntity
 
        /**
         * @var string
-        * @validate NotEmpty
-        * @validate StringLength(minimum=1, maximum=255)
-        * @validate \SJBR\SrFreecap\Validation\Validator\TtfFileValidator
+        * @Validate("NotEmpty")
+        * @Validate("StringLength", options={"minimum": 1, "maximum": 255})
+        * @Validate("\SJBR\SrFreecap\Validation\Validator\TtfFileValidator")
         **/
        protected $ttfFontFileName = '';
 
@@ -196,7 +198,7 @@ class Font extends AbstractEntity
                                $startCharacter = 'a';
                                break;
                        case 2:
-                               // Note: This script must be iso-8859-1-encoded
+                               // Note: This script must be iso-8859-2-encoded
                                $characters = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o'
                                        .',p,q,r,s,t,u,v,w,x,y,z,-,-,-,-,-'
                                        .',-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-'
@@ -218,9 +220,9 @@ class Font extends AbstractEntity
                $numberOfCharacters = count(explode(',', $characters));
                $this->setPngImageFileName(FontMakingUtility::makeFontImage($characters, $this->ttfFontFileName, $this->characterWidth, $this->characterHeight));
                if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
-                       $image = @ImageCreateFromPNG(PATH_site . $this->pngImageFileName);
+                       $image = @ImageCreateFromPNG(Environment::getPublicPath() . '/' . $this->pngImageFileName);
                } else {
-                       $image = @ImageCreateFromGIF(PATH_site . $this->pngImageFileName);
+                       $image = @ImageCreateFromGIF(Environment::getPublicPath() . '/' . $this->pngImageFileName);
                }
                if ($image !== false) {
                        $this->setGdFontdata(FontMakingUtility::makeFont($image, $numberOfCharacters, $startCharacter, $this->characterWidth, $this->characterHeight, $this->endianness));
index 81c6b82..3ed5205 100644 (file)
@@ -1,9 +1,10 @@
 <?php
 namespace SJBR\SrFreecap\Domain\Repository;
-/***************************************************************
+
+/*
  *  Copyright notice
  *
- *  (c) 2012 Stanislas Rolland <typo3@sjbr.ca>
+ *  (c) 2012-2018 Stanislas Rolland <typo3@sjbr.ca>
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -24,15 +25,19 @@ namespace SJBR\SrFreecap\Domain\Repository;
  *  GNU General Public License for more details.
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ */
+
+use SJBR\SrFreecap\Domain\Model\Font;
+use TYPO3\CMS\Core\Core\Environment;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Persistence\Repository;
 
 /**
  * Font repository
- *
- * @author Stanislas Rolland <typo3@sjbr.ca>
  */
-class FontRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
-
+class FontRepository extends Repository
+{
        /**
         * @var string Name of the extension this controller belongs to
         */
@@ -41,15 +46,15 @@ class FontRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
        /**
         * Writes the GD font file
         *
-        * @param \SJBR\SrFreecap\Domain\Model\Font the object to be stored
+        * @param Font the object to be stored
         * @return \SJBR\SrFreecap\Domain\Repository\FontRepository $this
         */
-        public function writeFontFile(\SJBR\SrFreecap\Domain\Model\Font $font) {
-               $relativeFileName = 'uploads/' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getCN($this->extensionKey) . '/' . $font->getGdFontFilePrefix() . '_' .  \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5($font->getGdFontData()) . '.gdf';
-               if (\TYPO3\CMS\Core\Utility\GeneralUtility::writeFile(PATH_site . $relativeFileName, $font->getGdFontData())) {
+        public function writeFontFile(Font $font)
+        {
+               $relativeFileName = 'uploads/' . ExtensionManagementUtility::getCN($this->extensionKey) . '/' . $font->getGdFontFilePrefix() . '_' .  GeneralUtility::shortMD5($font->getGdFontData()) . '.gdf';
+               if (GeneralUtility::writeFile(Environment::getPublicPath() . '/' . $relativeFileName, $font->getGdFontData())) {
                        $font->setGdFontFileName($relativeFileName);
                }
                return $this;
        }
-}
-?>
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/Classes/Http/EidDispatcher.php b/Classes/Http/EidDispatcher.php
new file mode 100644 (file)
index 0000000..5d163c1
--- /dev/null
@@ -0,0 +1,326 @@
+<?php
+namespace SJBR\SrFreecap\Http;
+
+/*
+ * Copyright notice
+ *
+ * 2010 Daniel Lienert <daniel@lienert.cc>, Michael Knoll <mimi@kaktusteam.de>
+ * 2012-2018 Stanislas Rolland <typo3(arobas)sjbr.ca>
+ * 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!
+ */
+
+use TYPO3\CMS\Core\Context\Context;
+use TYPO3\CMS\Core\Error\Http\BadRequestException;
+use TYPO3\CMS\Core\Http\NullResponse;
+use TYPO3\CMS\Core\Utility\ArrayUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\RootlineUtility;
+use TYPO3\CMS\Core\Utility\VersionNumberUtility;
+use TYPO3\CMS\Extbase\Core\Bootstrap;
+use TYPO3\CMS\Extbase\Mvc\Dispatcher;
+use TYPO3\CMS\Extbase\Mvc\Web\Request;
+use TYPO3\CMS\Extbase\Mvc\Web\Response;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
+
+/**
+ * Dispatch the eid request
+ */
+class EidDispatcher
+{
+       /**
+        * Array of all request Arguments
+        *
+        * @var array
+        */
+       protected $requestArguments = [];
+
+       /**
+        * Extbase Object Manager
+        * @var ObjectManager
+        */
+       protected $objectManager;
+
+       /**
+        * @var string
+        */
+       protected $vendorName;
+
+       /**
+        * @var string
+        */
+       protected $extensionName;
+
+       /**
+        * @var string
+        */
+       protected $pluginName;
+
+       /**
+        * @var string
+        */
+       protected $controllerName;
+
+       /**
+        * @var string
+        */
+       protected $actionName;
+
+       /**
+        * @var string
+        */
+       protected $formatName;
+
+       /**
+        * @var array
+        */
+       protected $arguments = [];
+
+       /**
+        * @var integer
+        */
+       protected $pageUid;
+
+       /**
+        * Constructor
+        *
+        */
+       public function __construct()
+       {
+               $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
+       }
+
+       /**
+        * Initializes and dispatches actions
+        *
+        * Call this function if you want to use this dispatcher "standalone"
+        */
+       public function initAndDispatch()
+       {
+               return $this->initTypoScriptConfiguration()
+                       ->initLanguage()
+                       ->initCallArguments()
+                       ->dispatch();
+       }
+
+       /**
+        * Builds an extbase context and returns the response
+        *
+        */
+       protected function dispatch()
+       {
+               $bootstrap = $this->objectManager->get(Bootstrap::class);
+               $configuration['vendorName'] = $this->vendorName;
+               $configuration['extensionName'] = $this->extensionName;
+               $configuration['pluginName'] = $this->pluginName;
+               $bootstrap->initialize($configuration);
+               $request = $this->buildRequest();
+               $response = $this->objectManager->get(Response::class);
+               $dispatcher = $this->objectManager->get(Dispatcher::class);
+               try {
+                       $dispatcher->dispatch($request, $response);
+               } catch (\Exception $e) {
+                       throw new BadRequestException('An argument is missing or invalid', 1394587024);
+               }
+               if (isset($this->getTypoScriptFrontendController()->fe_user)) {
+                       $this->getTypoScriptFrontendController()->fe_user->storeSessionData();
+               }
+               // Output was already sent
+               return new NullResponse();
+       }
+
+       /**
+        * Get the TypoScript configuration
+        *
+        * @return \SJBR\SrFreecap\Http\EidDispatcher
+        */
+       protected function initTypoScriptConfiguration()
+       {
+               $this->getTypoScriptFrontendController()->type = 0;
+               $context = GeneralUtility::makeInstance(Context::class);
+               $this->getTypoScriptFrontendController()->rootLine = GeneralUtility::makeInstance(RootlineUtility::class, $this->getTypoScriptFrontendController()->id, $this->getTypoScriptFrontendController()->MP, $context)->get();
+               $this->getTypoScriptFrontendController()->getConfigArray();
+               return $this;
+       }
+
+       /**
+        * Set  language and locale
+        *
+        * @return \SJBR\SrFreecap\Http\EidDispatcher
+        */
+       protected function initLanguage()
+       {
+               $this->getTypoScriptFrontendController()->settingLanguage();
+               $this->getTypoScriptFrontendController()->settingLocale();
+               return $this;
+       }
+
+       /**
+        * Build a request object
+        *
+        * @return \TYPO3\CMS\Extbase\Mvc\Web\Request $request
+        */
+       protected function buildRequest()
+       {
+               $request = $this->objectManager->get(Request::class);
+               $request->setControllerVendorName($this->vendorName);
+               $request->setControllerExtensionName($this->extensionName);
+               $request->setPluginName($this->pluginName);
+               $request->setControllerName($this->controllerName);
+               $request->setControllerActionName($this->actionName);
+               $request->setFormat($this->formatName);
+               $request->setArguments($this->arguments);
+               return $request;
+       }
+
+       /**
+        * Prepare the call arguments
+        *
+        * @return \SJBR\SrFreecap\Http\EidDispatcher
+        */
+       public function initCallArguments() {
+               $request = GeneralUtility::_GP('request');
+               if ($request) {
+                       $this->setRequestArgumentsFromJSON($request);
+               } else {
+                       $this->setRequestArgumentsFromGetPost();
+               }
+               return $this->setVendorName($this->requestArguments['vendorName'])
+                       ->setExtensionName($this->requestArguments['extensionName'])
+                       ->setPluginName($this->requestArguments['pluginName'])
+                       ->setControllerName($this->requestArguments['controllerName'])
+                       ->setActionName($this->requestArguments['actionName'])
+                       ->setFormatName($this->requestArguments['formatName'])
+                       ->setArguments($this->requestArguments['arguments']);
+       }
+
+       /**
+        * Set the request array from JSON
+        *
+        * @param string $request
+        */
+       protected function setRequestArgumentsFromJSON($request)
+       {
+               $requestArray = json_decode($request, true);
+               if (is_array($requestArray)) {
+                       ArrayUtility::mergeRecursiveWithOverrule($this->requestArguments, $requestArray);
+               }
+       }
+
+       /**
+        * Set the request array from the getPost array
+        */
+       protected function setRequestArgumentsFromGetPost()
+       {
+               $validArguments = array('vendorName', 'extensionName', 'pluginName', 'controllerName', 'actionName', 'formatName', 'arguments');
+               foreach ($validArguments as $argument) {
+                       if (GeneralUtility::_GP($argument)) {
+                               $this->requestArguments[$argument] = GeneralUtility::_GP($argument);
+                       } else if (GeneralUtility::_GP('amp;' . $argument)) {
+                               // Something went wrong...
+                               $this->requestArguments[$argument] = GeneralUtility::_GP('amp;' . $argument);
+                       } else if ($argument !== 'arguments') {
+                               throw new BadRequestException('An argument is missing', 1394587023);
+                       }
+               }
+       }
+
+       /**
+        * @param string $vendorName
+        * @return \SJBR\SrFreecap\Http\EidDispatcher
+        */
+       protected function setVendorName($vendorName)
+       {
+               $this->vendorName = htmlspecialchars((string)$vendorName);
+               return $this;
+       }
+
+       /**
+        * @param string $extensionName
+        * @return \SJBR\SrFreecap\Http\EidDispatcher
+        */
+       protected function setExtensionName($extensionName)
+       {
+               $this->extensionName = htmlspecialchars((string)$extensionName);
+               return $this;
+       }
+
+       /**
+        * @param string $pluginName
+        * @return \SJBR\SrFreecap\Http\EidDispatcher
+        */
+       protected function setPluginName($pluginName = '')
+       {
+               $this->pluginName = htmlspecialchars((string)$pluginName);
+               return $this;
+       }
+
+       /**
+        * @param string $controllerName
+        * @return \SJBR\SrFreecap\Http\EidDispatcher
+        */
+       protected function setControllerName($controllerName = '')
+       {
+               $this->controllerName = htmlspecialchars((string)$controllerName);
+               return $this;
+       }
+
+       /**
+        * @param string $actionName
+        * @return \SJBR\SrFreecap\Http\EidDispatcher
+        */
+       protected function setActionName($actionName = 'index')
+       {
+               $this->actionName = htmlspecialchars((string)$actionName);
+               return $this;
+       }
+
+       /**
+        * @param string $formatName
+        * @return \SJBR\SrFreecap\Http\EidDispatcher
+        */
+       protected function setFormatName($formatName = 'txt')
+       {
+               $this->formatName = htmlspecialchars((string)$formatName);
+               return $this;
+       }
+
+       /**
+        * @param array $arguments
+        * @return \SJBR\SrFreecap\Http\EidDispatcher
+        */
+       protected function setArguments($arguments)
+       {
+               if (!is_array($arguments)) {
+                       $this->arguments = array();
+               } else {
+                       $this->arguments = $arguments;
+               }
+               return $this;
+       }
+
+    /**
+     * @return TypoScriptFrontendController
+     */
+    protected function getTypoScriptFrontendController()
+    {
+        return $GLOBALS['TSFE'];
+    }
+}
\ No newline at end of file
diff --git a/Classes/Middleware/EidHandler.php b/Classes/Middleware/EidHandler.php
new file mode 100644 (file)
index 0000000..f1ac1cc
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+declare(strict_types = 1);
+namespace SJBR\SrFreecap\Middleware;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\MiddlewareInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+use TYPO3\CMS\Core\Exception;
+use TYPO3\CMS\Core\Http\Dispatcher;
+use TYPO3\CMS\Core\Http\NullResponse;
+use TYPO3\CMS\Core\Http\Response;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Lightweight alternative to regular frontend requests; used when $_GET[eID] is set.
+ * In the future, logic from the EidUtility will be moved to this class, however in most cases
+ * a custom PSR-15 middleware will be better suited for whatever job the eID functionality does currently.
+ *
+ * @internal
+ */
+class EidHandler implements MiddlewareInterface
+{
+    /**
+     * Dispatches the request to the corresponding eID class or eID script
+     *
+     * @param ServerRequestInterface $request
+     * @param RequestHandlerInterface $handler
+     * @return ResponseInterface
+     * @throws Exception
+     */
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
+    {
+        $eID = $request->getParsedBody()['eIDSR'] ?? $request->getQueryParams()['eIDSR'] ?? null;
+
+        if ($eID === null) {
+            return $handler->handle($request);
+        }
+
+        // Remove any output produced until now
+        ob_clean();
+
+        /** @var Response $response */
+        $response = GeneralUtility::makeInstance(Response::class);
+
+        if (empty($eID) || !isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sr_freecap']['eIDSR_include'][$eID])) {
+            return $response->withStatus(404, 'eIDSR not registered');
+        }
+
+        $configuration = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sr_freecap']['eIDSR_include'][$eID];
+
+        // Simple check to make sure that it's not an absolute file (to use the fallback)
+        if (strpos($configuration, '::') !== false || is_callable($configuration)) {
+            /** @var Dispatcher $dispatcher */
+            $dispatcher = GeneralUtility::makeInstance(Dispatcher::class);
+            $request = $request->withAttribute('target', $configuration);
+            return $dispatcher->dispatch($request) ?? new NullResponse();
+        }
+        return new NullResponse();
+    }
+}
\ No newline at end of file
index de3c9f3..7682be2 100644 (file)
@@ -4,7 +4,7 @@ namespace SJBR\SrFreecap;
 /*
  *  Copyright notice
  *
- *  (c) 2005-2015 Stanislas Rolland <typo3(arobas)sjbr.ca>
+ *  (c) 2005-2018 Stanislas Rolland <typo3(arobas)sjbr.ca>
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -25,76 +25,57 @@ namespace SJBR\SrFreecap;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  */
-/**
- * Integrates freeCap v1.4 into TYPO3 and checks the freeCap CAPTCHA word.
- */
-/************************************************************\
-*
-*              freeCap v1.4 Copyright 2005 Howard Yeend
-*              www.puremango.co.uk
-*
-*    This file is part of freeCap.
-*
-*    freeCap 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.
-*
-*    freeCap 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.
-*
-*    You should have received a copy of the GNU General Public License
-*    along with freeCap; if not, write to the Free Software
-*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*
-*
-\************************************************************/
+
+use SJBR\SrFreecap\Validation\Validator\CaptchaValidator;
+use SJBR\SrFreecap\ViewHelpers\AudioViewHelper;
+use SJBR\SrFreecap\ViewHelpers\ImageViewHelper;
+use SJBR\SrFreecap\ViewHelpers\TranslateViewHelper;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
+
 class PiBaseApi
 {
-
        /**
         * @var string The extension key
         */
        public $extKey = 'sr_freecap';
 
        /**
-        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
+        * @var ObjectManager
         */
-       protected $objectManager = NULL;
+       protected $objectManager = null;
 
        /**
         * This function generates an array of markers used to render the captcha element
         *
         * @return array marker array containing the captcha markers to be sustituted in the html template
-        */     
+        */
        public function makeCaptcha()
        {
-
                // Get the object manager
-               if ($this->objectManager === NULL) {
-                       $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
+               if ($this->objectManager === null) {
+                       $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
                }
-               
+
                // Get the configuration manager
-               $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
-               
+               $configurationManager = $this->objectManager->get(ConfigurationManagerInterface::class);
+
                // Get translation view helper
-               $translator = $this->objectManager->get('SJBR\\SrFreecap\\ViewHelpers\\TranslateViewHelper');
+               $translator = $this->objectManager->get(TranslateViewHelper::class);
                $translator->injectConfigurationManager($configurationManager);
 
-               $markerArray = array();
+               $markerArray = [];
                $markerArray['###'. strtoupper($this->extKey) . '_NOTICE###'] = $translator->render('notice') . ' ' . $translator->render('explain');
 
                // Get the captcha image view helper
-               $imageViewHelper = $this->objectManager->get('SJBR\\SrFreecap\\ViewHelpers\\ImageViewHelper');
+               $imageViewHelper = $this->objectManager->get(ImageViewHelper::class);
                $imageViewHelper->injectConfigurationManager($configurationManager);
                $markerArray['###'. strtoupper($this->extKey) . '_IMAGE###'] = $imageViewHelper->render('pi1');
                $markerArray['###'. strtoupper($this->extKey) . '_CANT_READ###'] = '';
 
                // Get the audio icon view helper
-               $audioViewHelper = $this->objectManager->get('SJBR\\SrFreecap\\ViewHelpers\\AudioViewHelper');
+               $audioViewHelper = $this->objectManager->get(AudioViewHelper::class);
                $audioViewHelper->injectConfigurationManager($configurationManager);
                $markerArray['###'. strtoupper($this->extKey) . '_ACCESSIBLE###'] = $audioViewHelper->render('pi1');
 
@@ -104,17 +85,17 @@ class PiBaseApi
        /**
         * Check the word that was entered against the hashed value
         *
-        * @param       string          $word: hte word that was entered
-        * @return      boolean         true, if the word entered matches the hashes value
+        * @param string $word: hte word that was entered
+        * @return bool true, if the word entered matches the hashes value
         */
        public function checkWord($word)
        {
                // Get the object manager
-               if ($this->objectManager === NULL) {
-                       $this->objectManager = new \TYPO3\CMS\Extbase\Object\ObjectManager();
+               if ($this->objectManager === null) {
+                       $this->objectManager = GeneralUtility::makeInstance(ObjectManager:class);
                }
                // Get the validator
-               $validator = $this->objectManager->get('SJBR\\SrFreecap\\Validation\\Validator\\CaptchaValidator');
+               $validator = $this->objectManager->get(CaptchaValidator::class);
                // Check word
                return !$validator->validate($word)->hasErrors();
        }
diff --git a/Classes/Utility/EidUtility.php b/Classes/Utility/EidUtility.php
deleted file mode 100644 (file)
index c011c8b..0000000
+++ /dev/null
@@ -1,319 +0,0 @@
-<?php
-namespace SJBR\SrFreecap\Utility;
-/***************************************************************
- * Copyright notice
- *
- * 2010 Daniel Lienert <daniel@lienert.cc>, Michael Knoll <mimi@kaktusteam.de>
- * 2012-2015 Stanislas Rolland <typo3(arobas)sjbr.ca>
- * 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!
- ***************************************************************/
-
-use TYPO3\CMS\Core\Error\Http\BadRequestException;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Core\Utility\VersionNumberUtility;
-
-/**
- * Utility to dispatch the eid request
- *
- * @author Daniel Lienert <daniel@lienert.cc>
- * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
-*/
-class EidUtility {
-
-       /**
-        * Array of all request Arguments
-        *
-        * @var array
-        */
-       protected $requestArguments = array();
-
-       /**
-        * Extbase Object Manager
-        * @var \TYPO3\CMS\Extbase\Object\ObjectManager
-        */
-       protected $objectManager;
-
-       /**
-        * @var string
-        */
-       protected $vendorName;
-
-       /**
-        * @var string
-        */
-       protected $extensionName;
-
-       /**
-        * @var string
-        */
-       protected $pluginName;
-
-       /**
-        * @var string
-        */
-       protected $controllerName;
-
-       /**
-        * @var string
-        */
-       protected $actionName;
-
-       /**
-        * @var string
-        */
-       protected $formatName;
-
-       /**
-        * @var array
-        */
-       protected $arguments = array();
-
-       /**
-        * @var integer
-        */
-       protected $pageUid;
-
-       /**
-        * Constructor
-        *
-        */
-       public function __construct() {
-               $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
-       }
-
-       /**
-        * Initializes and dispatches actions
-        *
-        * Call this function if you want to use this dispatcher "standalone"
-        */
-       public function initAndDispatch() {
-               return $this->initTypoScriptFrontendController()
-                       ->initTypoScriptConfiguration()
-                       ->initLanguage()
-                       ->initCallArguments()
-                       ->dispatch();
-       }
-
-       /**
-        * Builds an extbase context and returns the response
-        *
-        */
-       protected function dispatch() {
-               /* @var $bootstrap \TYPO3\CMS\Extbase\Core\Bootstrap */
-               $bootstrap = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Core\\Bootstrap');
-               $configuration['vendorName'] = $this->vendorName;
-               $configuration['extensionName'] = $this->extensionName;
-               $configuration['pluginName'] = $this->pluginName;
-               $bootstrap->initialize($configuration);
-               $request = $this->buildRequest();
-               /* @var $response \TYPO3\CMS\Extbase\Mvc\Web\Response */
-               $response = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response');
-               /* @var $dispatcher \TYPO3\CMS\Extbase\Mvc\Dispatcher */
-               $dispatcher = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Dispatcher');
-               try {
-                       $dispatcher->dispatch($request, $response);
-               } catch (\Exception $e) {
-                       throw new BadRequestException('An argument is missing or invalid', 1394587024);
-               }
-               if ($GLOBALS ['TSFE']->fe_user) {
-                       $GLOBALS ['TSFE']->fe_user->storeSessionData();
-               }
-               return $response->getContent();
-       }
-
-       /**
-        * Create a TypoScript Frontend Controller
-        *
-        * @return \SJBR\SrFreecap\Utility\EidDispatcher
-        */
-       protected function initTypoScriptFrontendController() {
-               // Get page uid and mount point, if any
-               $this->pageUid = GeneralUtility::_GET('id');
-               if (!isset($this->pageUid)) {
-                       $this->pageUid = 0;
-               }
-               $this->pageUid = htmlspecialchars($this->pageUid);
-               $MP = htmlspecialchars(GeneralUtility::_GET('MP'));
-               \TYPO3\CMS\Frontend\Utility\EidUtility::initTCA();
-               $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;
-       }
-
-       /**
-        * Get the TypoScript configuration
-        *
-        * @return \SJBR\SrFreecap\Utility\EidDispatcher
-        */
-       protected function initTypoScriptConfiguration() {
-               $GLOBALS['TSFE']->getPageAndRootline();
-               $GLOBALS['TSFE']->initTemplate();
-               $GLOBALS['TSFE']->tmpl->getFileName_backPath = PATH_site;
-               $GLOBALS['TSFE']->getConfigArray();
-               return $this;
-       }
-
-       /**
-        * Set  language and locale
-        *
-        * @return \SJBR\SrFreecap\Utility\EidDispatcher
-        */
-       protected function initLanguage() {
-               $GLOBALS['TSFE']->settingLanguage();
-               $GLOBALS['TSFE']->settingLocale();
-               return $this;
-       }
-
-       /**
-        * Build a request object
-        *
-        * @return \TYPO3\CMS\Extbase\Mvc\Web\Request $request
-        */
-       protected function buildRequest() {
-               /* @var $request \TYPO3\CMS\Extbase\Mvc\Web\Request */
-               $request = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request');
-               $request->setControllerVendorName($this->vendorName);
-               $request->setControllerExtensionName($this->extensionName);
-               $request->setPluginName($this->pluginName);
-               $request->setControllerName($this->controllerName);
-               $request->setControllerActionName($this->actionName);
-               $request->setFormat($this->formatName);
-               $request->setArguments($this->arguments);
-               return $request;
-       }
-
-       /**
-        * Prepare the call arguments
-        *
-        * @return \SJBR\SrFreecap\Utility\EidDispatcher
-        */
-       public function initCallArguments() {
-               $request = GeneralUtility::_GP('request');
-               if ($request) {
-                       $this->setRequestArgumentsFromJSON($request);
-               } else {
-                       $this->setRequestArgumentsFromGetPost();
-               }
-               return $this->setVendorName($this->requestArguments['vendorName'])
-                       ->setExtensionName($this->requestArguments['extensionName'])
-                       ->setPluginName($this->requestArguments['pluginName'])
-                       ->setControllerName($this->requestArguments['controllerName'])
-                       ->setActionName($this->requestArguments['actionName'])
-                       ->setFormatName($this->requestArguments['formatName'])
-                       ->setArguments($this->requestArguments['arguments']);
-       }
-
-       /**
-        * Set the request array from JSON
-        *
-        * @param string $request
-        */
-       protected function setRequestArgumentsFromJSON($request) {
-               $requestArray = json_decode($request, TRUE);
-               if (is_array($requestArray)) {
-                       \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($this->requestArguments, $requestArray);
-               }
-       }
-
-       /**
-        * Set the request array from the getPost array
-        */
-       protected function setRequestArgumentsFromGetPost() {
-               $validArguments = array('vendorName', 'extensionName', 'pluginName', 'controllerName', 'actionName', 'formatName', 'arguments');
-               foreach ($validArguments as $argument) {
-                       if (GeneralUtility::_GP($argument)) {
-                               $this->requestArguments[$argument] = GeneralUtility::_GP($argument);
-                       } else if (GeneralUtility::_GP('amp;' . $argument)) {
-                               // Something went wrong...
-                               $this->requestArguments[$argument] = GeneralUtility::_GP('amp;' . $argument);
-                       } else if ($argument !== 'arguments') {
-                               throw new BadRequestException('An argument is missing', 1394587023);
-                       }
-               }
-       }
-
-       /**
-        * @param string $vendorName
-        * @return \SJBR\SrFreecap\Utility\EidDispatcher
-        */
-       protected function setVendorName($vendorName) {
-               $this->vendorName = htmlspecialchars((string)$vendorName);
-               return $this;
-       }
-
-       /**
-        * @param string $extensionName
-        * @return \SJBR\SrFreecap\Utility\EidDispatcher
-        */
-       protected function setExtensionName($extensionName) {
-               $this->extensionName = htmlspecialchars((string)$extensionName);
-               return $this;
-       }
-
-       /**
-        * @param string $pluginName
-        * @return \SJBR\SrFreecap\Utility\EidDispatcher
-        */
-       protected function setPluginName($pluginName = '') {
-               $this->pluginName = htmlspecialchars((string)$pluginName);
-               return $this;
-       }
-
-       /**
-        * @param string $controllerName
-        * @return \SJBR\SrFreecap\Utility\EidDispatcher
-        */
-       protected function setControllerName($controllerName = '') {
-               $this->controllerName = htmlspecialchars((string)$controllerName);
-               return $this;
-       }
-
-       /**
-        * @param string $actionName
-        * @return \SJBR\SrFreecap\Utility\EidDispatcher
-        */
-       protected function setActionName($actionName = 'index') {
-               $this->actionName = htmlspecialchars((string)$actionName);
-               return $this;
-       }
-
-       /**
-        * @param string $formatName
-        * @return \SJBR\SrFreecap\Utility\EidDispatcher
-        */
-       protected function setFormatName($formatName = 'txt') {
-               $this->formatName = htmlspecialchars((string)$formatName);
-               return $this;
-       }
-
-       /**
-        * @param array $arguments
-        * @return \SJBR\SrFreecap\Utility\EidDispatcher
-        */
-       protected function setArguments($arguments) {
-               if (!is_array($arguments)) {
-                       $this->arguments = array();
-               } else {
-                       $this->arguments = $arguments;
-               }
-               return $this;
-       }
-}
\ No newline at end of file
index 4c27029..742275f 100644 (file)
@@ -28,7 +28,6 @@ namespace SJBR\SrFreecap\Utility;
  */
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Core\Utility\VersionNumberUtility;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
 
 /**
@@ -81,7 +80,6 @@ class FontMakingUtility
                }
                $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
                $gifCreator = $objectManager->get(GifBuilderUtility::class);
-               $gifCreator->init();
                if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
                        $gifCreator->start($gifObjArray, array());
                        return $gifCreator->gifBuild();
index ba528ed..66575d6 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 namespace SJBR\SrFreecap\Utility;
 
-/***************************************************************
+/*
  *  Copyright notice
  *
  *  (c) 2012-2018 Stanislas Rolland <typo3(arobas)sjbr.ca>
@@ -25,8 +25,9 @@ namespace SJBR\SrFreecap\Utility;
  *  GNU General Public License for more details.
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ */
 
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Frontend\Imaging\GifBuilder;
@@ -44,7 +45,7 @@ class GifBuilderUtility extends GifBuilder
         */
        public function checkFile($file)
        {
-               $file = GeneralUtility::getFileAbsFileName(PATH_site . $file);
+               $file = GeneralUtility::getFileAbsFileName(Environment::getPublicPath() . '/' . $file);
         $file = PathUtility::stripPathSitePrefix($file);
                return $file;
        }
@@ -60,6 +61,6 @@ class GifBuilderUtility extends GifBuilder
         */
        public function ImageWrite($destImg, $theImage, $quality = 0)
        {
-               return parent::ImageWrite($destImg, PATH_site.$theImage, $quality);
+               return parent::ImageWrite($destImg, Environment::getPublicPath() . '/' . $theImage, $quality);
        }
 }
\ No newline at end of file
index 87a1417..d7660ff 100644 (file)
@@ -425,6 +425,8 @@ class ImageContentUtility {
                header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
                header('Pragma: no-cache');
                header('Cache-Control: no-cache, no-store, must-revalidate');
+               // Setting privacy policy header for IE in popup window
+               header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
                switch ($imageType) {
                        case 'jpg':
                                header('Content-Type: image/jpeg');
index 6a729f4..d964e42 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 namespace SJBR\SrFreecap\Utility;
 
-/***************************************************************
+/*
  *  Copyright notice
  *
  *  (c) 2009 Sebastian Kurf├╝rst <sebastian@typo3.org>
- *  (c) 2013-2016 Stanislas Rolland <typo3@sjbr.ca>
+ *  (c) 2013-2018 Stanislas Rolland <typo3@sjbr.ca>
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -23,18 +23,23 @@ namespace SJBR\SrFreecap\Utility;
  *  GNU General Public License for more details.
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ */
 
+use Psr\Http\Message\ServerRequestInterface;
+use TYPO3\CMS\Core\Context\Context;
+use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Localization\Locales;
+use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
 /**
  * Localization helper which should be used to fetch appropriate words list or voice rendering language
  *
  */
-class LocalizationUtility {
-
+class LocalizationUtility
+{
        /**
         * Key of the extension to which this class belongs
         *
@@ -43,20 +48,6 @@ class LocalizationUtility {
        protected static $extensionKey = 'sr_freecap';
 
        /**
-        * Key of the language to use
-        *
-        * @var string
-        */
-       protected static $languageKey = 'default';
-
-       /**
-        * Pointer to alternative fall-back language to use
-        *
-        * @var array
-        */
-       protected static $alternativeLanguageKeys = array();
-
-       /**
         * Gets the location of the words list based on configured language
         *
         * @param string $defaultWordsList: location of the default words list
@@ -64,15 +55,15 @@ class LocalizationUtility {
         */
        public static function getWordsListLocation($defaultWordsList = '')
        {
-               self::setLanguageKeys();
+               $languageKeys = static::getLanguageKeys();
                $initialWordsList = $defaultWordsList;
                if (!trim($initialWordsList)) {
                        $initialWordsList = 'EXT:' . self::$extensionKey . '/Resources/Private/Captcha/Words/default_freecap_words';
                }
                $path = dirname(GeneralUtility::getFileAbsFileName($initialWordsList)) . '/';
-               $wordsListLocation = $path . self::$languageKey . '_freecap_words';
+               $wordsListLocation = $path . $languageKeys['languageKey'] . '_freecap_words';
                if (!is_file($wordsListLocation)) {
-                       foreach (self::$alternativeLanguageKeys as $language) {
+                       foreach ($languageKeys['alternativeLanguageKeys'] as $language) {
                                $wordsListLocation = $path . $language . '_freecap_words';
                                if (is_file($wordsListLocation)) {
                                        break;
@@ -95,11 +86,11 @@ class LocalizationUtility {
         */
        public static function getVoicesDirectory()
        {
-               self::setLanguageKeys();
+               $languageKeys = static::getLanguageKeys();
                $path = ExtensionManagementUtility::extPath(self::$extensionKey) . 'Resources/Private/Captcha/Voices/';
-               $voicesDirectory = $path . self::$languageKey . '/';
+               $voicesDirectory = $path . $languageKeys['languageKey'] . '/';
                if (!is_dir($voicesDirectory)) {
-                       foreach (self::$alternativeLanguageKeys as $language) {
+                       foreach ($languageKeys['alternativeLanguageKeys'] as $language) {
                                $voicesDirectory = $path . $language . '/';
                                if (is_dir($voicesDirectory)) {
                                        break;
@@ -112,41 +103,75 @@ class LocalizationUtility {
                return $voicesDirectory;
        }
 
-       /**
-        * Sets the currently active language/language_alt keys.
-        * Default values are "default" for language key and "" for language_alt key.
-        *
-        * @return void
-        */
-       protected static function setLanguageKeys()
-       {
-               self::$languageKey = 'default';
-               self::$alternativeLanguageKeys = array();
-               if (TYPO3_MODE === 'FE') {
-                       if (isset($GLOBALS['TSFE']->config['config']['language'])) {
-                               self::$languageKey = $GLOBALS['TSFE']->config['config']['language'];
-                               if (isset($GLOBALS['TSFE']->config['config']['language_alt'])) {
-                                       self::$alternativeLanguageKeys[] = $GLOBALS['TSFE']->config['config']['language_alt'];
-                               } else {
-                                       /** @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;
-                                               }
-                                       }
-                               }
-                       }
-               } 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 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;
-                               }
-                       }
-               }
-       }
+    /**
+     * Sets the currently active language/language_alt keys.
+     * Default values are "default" for language key and an empty array for language_alt key.
+     *
+     * @return array
+     */
+    protected static function getLanguageKeys(): array
+    {
+        $languageKeys = [
+            'languageKey' => 'default',
+            'alternativeLanguageKeys' => [],
+        ];
+        if (TYPO3_MODE === 'FE') {
+            $tsfe = static::getTypoScriptFrontendController();
+            $siteLanguage = self::getCurrentSiteLanguage();
+
+            // Get values from site language, which takes precedence over TypoScript settings
+            if ($siteLanguage instanceof SiteLanguage) {
+                $languageKeys['languageKey'] = $siteLanguage->getTypo3Language();
+            } elseif (isset($tsfe->config['config']['language'])) {
+                $languageKeys['languageKey'] = $tsfe->config['config']['language'];
+                if (isset($tsfe->config['config']['language_alt'])) {
+                    $languageKeys['alternativeLanguageKeys'][] = $tsfe->config['config']['language_alt'];
+                }
+            }
+
+            if (empty($languageKeys['alternativeLanguageKeys'])) {
+                $locales = GeneralUtility::makeInstance(Locales::class);
+                if (in_array($languageKeys['languageKey'], $locales->getLocales())) {
+                    foreach ($locales->getLocaleDependencies($languageKeys['languageKey']) as $language) {
+                        $languageKeys['alternativeLanguageKeys'][] = $language;
+                    }
+                }
+            }
+        } elseif (!empty($GLOBALS['BE_USER']->uc['lang'])) {
+            $languageKeys['languageKey'] = $GLOBALS['BE_USER']->uc['lang'];
+        } elseif (!empty(static::getLanguageService()->lang)) {
+            $languageKeys['languageKey'] = static::getLanguageService()->lang;
+        }
+        return $languageKeys;
+    }
+
+    /**
+     * Returns the currently configured "site language" if a site is configured (= resolved)
+     * in the current request.
+     *
+     * @return SiteLanguage|null
+     */
+    protected static function getCurrentSiteLanguage(): ?SiteLanguage
+    {
+        if ($GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface) {
+            return $GLOBALS['TYPO3_REQUEST']->getAttribute('language', null);
+        }
+        return null;
+    }
+
+    /**
+     * @return TypoScriptFrontendController
+     */
+    protected static function getTypoScriptFrontendController()
+    {
+        return $GLOBALS['TSFE'];
+    }
+
+    /**
+     * @return LanguageService
+     */
+    protected static function getLanguageService()
+    {
+        return $GLOBALS['LANG'];
+    }
 }
\ No newline at end of file
index 2a1bbde..58abcea 100644 (file)
@@ -4,7 +4,7 @@ namespace SJBR\SrFreecap\View\AudioPlayer;
 /*
  *  Copyright notice
  *
- *  (c) 2013-2016 Stanislas Rolland <typo3(arobas)sjbr.ca>
+ *  (c) 2013-2018 Stanislas Rolland <typo3(arobas)sjbr.ca>
  *  All rights reserved
  *
  *  free software; you can redistribute it and/or modify
@@ -67,7 +67,8 @@ class AbstractPlayFormat implements ViewInterface
         * @param mixed $value Value of object
         * @return ViewInterface an instance of $this, to enable chaining
         */
-       public function assign($key, $value) {
+       public function assign($key, $value)
+       {
                switch ($key) {
                        case 'word':
                                $this->word = $value;
@@ -111,8 +112,10 @@ class AbstractPlayFormat implements ViewInterface
                $letterRenderingFiles = $this->getLetterRenderingFiles($word);
                // Join the files
                $audioContent = AudioContentUtility::joinAudioFiles($letterRenderingFiles);
-               // Output proper headers
+               // Output proper headers and echo audio content
                $this->sendHeaders($audioContent);
+               // Send audio content
+               $this->sendAudioContent($audioContent);
                // Return the audio content
                return $audioContent;
        }
@@ -146,7 +149,7 @@ class AbstractPlayFormat implements ViewInterface
         */
        protected function getLetterRenderingFiles($word, $extension = 'wav')
        {
-               $letterRenderingFiles = array();
+               $letterRenderingFiles = [];
                // Split the word
                $letters = preg_split('//', $word, -1, PREG_SPLIT_NO_EMPTY);
                // Get the directory containing the wav files
@@ -178,5 +181,19 @@ class AbstractPlayFormat implements ViewInterface
                header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
                header('Pragma: no-cache');
                header('Cache-Control: no-cache, no-store, must-revalidate');
+               // Setting privacy policy header for IE in popup window
+               header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
+               echo $audioContent;
+       }
+
+       /**
+        * Sends headers appropriate for wav content
+        *
+        * @param string $audioContent: the audio content that will be sent
+        * @return      void
+        */
+       protected function sendAudioContent($audioContent)
+       {
+               echo $audioContent;
        }
 }
\ No newline at end of file
index 993b77d..0adb24e 100644 (file)
@@ -1,51 +1,56 @@
 <?php
 namespace SJBR\SrFreecap\View\AudioPlayer;
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
-*  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.
-*  A copy is found in the textfile GPL.txt and important notices to the license
-*  from the author is found in LICENSE.txt distributed with these scripts.
-*
-*
-*  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!
-***************************************************************/
-/**
- * Renders a mp3 audio version of the CAPTCHA
+
+/*
+ *  Copyright notice
+ *
+ *  (c) 2013-2018 Stanislas Rolland <typo3(arobas)sjbr.ca>
+ *  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.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
  *
- * @author     Stanislas Rolland       <typo3(arobas)sjbr.ca>
+ *
+ *  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 PlayMp3 extends AbstractPlayFormat {
 
+use SJBR\SrFreecap\Utility\AudioContentUtility;
+
+/**
+ * Renders a mp3 audio version of the CAPTCHA
+ */
+class PlayMp3 extends AbstractPlayFormat
+{
        /**
         * Renders the audio version of captcha
         *
         * @return string The audio output to play
         */
-        public function render () {
+        public function render()
+        {
                 // Get the catcha word
                $word = $this->getWord();
                // Get the letter rensering files
                $letterRenderingFiles = $this->getLetterRenderingFiles($word, 'mp3');
                // Join the files
-               $audioContent = \SJBR\SrFreecap\Utility\AudioContentUtility::joinAudioFiles($letterRenderingFiles, 'mp3');
+               $audioContent = AudioContentUtility::joinAudioFiles($letterRenderingFiles, 'mp3');
                // Output proper headers
                $this->sendHeaders($audioContent, 'mpeg');
+               // Send audio content
+               $this->sendAudioContent($audioContent);
                // Return the audio content
                return $audioContent;
        }
index 24f5695..8ae28c7 100644 (file)
@@ -1,66 +1,73 @@
 <?php
 namespace SJBR\SrFreecap\View\ImageGenerator;
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2005-2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
-*  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.
-*  A copy is found in the textfile GPL.txt and important notices to the license
-*  from the author is found in LICENSE.txt distributed with these scripts.
-*
-*
-*  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!
-***************************************************************/
-/**
+
+/*
+ *  Copyright notice
+ *
+ *  (c) 2005-2018 Stanislas Rolland <typo3(arobas)sjbr.ca>
+ *  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.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  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!
+ */
+/*
  * Integrates freeCap v1.4.1 into TYPO3 and generates the freeCap CAPTCHA image.
+ */
+/*
+ *
+ *             freeCap v1.4.1 Copyright 2005 Howard Yeend
+ *             www.puremango.co.uk
  *
+ *    This file is part of freeCap.
+ *
+ *    freeCap 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.
+ *
+ *    freeCap 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.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with freeCap; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * @author     Stanislas Rolland       <typo3(arobas)sjbr.ca>
  */
-/************************************************************\
-*
-*              freeCap v1.4.1 Copyright 2005 Howard Yeend
-*              www.puremango.co.uk
-*
-*    This file is part of freeCap.
-*
-*    freeCap 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.
-*
-*    freeCap 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.
-*
-*    You should have received a copy of the GNU General Public License
-*    along with freeCap; if not, write to the Free Software
-*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*
-*
-\************************************************************/
+
+use SJBR\SrFreecap\Domain\Model\Word;
+use SJBR\SrFreecap\Domain\Repository\WordRepository;
+use SJBR\SrFreecap\Utility\EncryptionUtility;
+use SJBR\SrFreecap\Utility\ImageContentUtility;
+use SJBR\SrFreecap\Utility\RandomContentUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
+use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
+use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
+
 /**
  * Renders a png image of the CAPTCHA
- *
- * @author     Stanislas Rolland       <typo3(arobas)sjbr.ca>
  */
-class ShowPng implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface {
-
+class ShowPng implements ViewInterface
+{
        /**
         * @var string Name of the extension this view helper belongs to
         */
@@ -77,7 +84,7 @@ class ShowPng implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface {
        protected $extensionKey = 'sr_freecap';
 
        /**
-        * @var \TYPO3\CMS\Core\Domain\Model\Word
+        * @var Word
         */
        protected $word;
 
@@ -89,11 +96,10 @@ class ShowPng implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface {
        /**
         * Sets the current controller context
         *
-        * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext
+        * @param ControllerContext $controllerContext
         * @return void
         */
-       public function setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext) {
-       }
+       public function setControllerContext(ControllerContext $controllerContext) {}
 
        /**
         * Add a variable to the view data collection.
@@ -104,7 +110,8 @@ class ShowPng implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface {
         * @return SJBR\SrFreecap\View\ImageGenerator\ShowPng an instance of $this, to enable chaining
         * @api
         */
-       public function assign($key, $value) {
+       public function assign($key, $value)
+       {
                switch ($key) {
                        case 'word':
                                $this->word = $value;
@@ -123,19 +130,21 @@ class ShowPng implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface {
         * @return SJBR\SrFreecap\View\ImageGenerator\ShowPng an instance of $this, to enable chaining
         * @api
         */
-       public function assignMultiple(array $values) {
+       public function assignMultiple(array $values)
+       {
                return $this;
        }
 
        /**
         * Tells if the view implementation can render the view for the given context.
         *
-        * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext
-        * @return boolean TRUE if the view has something useful to display, otherwise FALSE
+        * @param ControllerContext $controllerContext
+        * @return boolean true if the view has something useful to display, otherwise false
         * @api
         */
-       public function canRender(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext) {
-                return TRUE;
+       public function canRender(ControllerContext $controllerContext)
+       {
+                return true;
        }
 
        /**
@@ -152,8 +161,8 @@ class ShowPng implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface {
         *
         * @return string empty string (the image is sent here)
         */
-       public function render () {
-
+       public function render()
+       {
                // Avoid Brute Force Attacks:
                if (!$this->word->getAttempts()) {
                        $this->word->setAttempts(1);
@@ -168,14 +177,14 @@ class ShowPng implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface {
                        // accessible via the web or use random string option
                        if ($this->word->getAttempts() > $this->settings['maxAttempts']) {
                                $this->word->setWordHash('');
-                               $this->word->setWordCypher(array());
+                               $this->word->setWordCypher([]);
                                $this->word->setHashFunction('');
                                // Get an instance of the word repository
-                               $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
-                               $wordRepository = $objectManager->get('SJBR\\SrFreecap\\Domain\\Repository\\WordRepository');
+                               $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
+                               $wordRepository = $objectManager->get(WordRepository::class);
                                // Reset the word
                                $wordRepository->setWord($this->word);
-                               $string = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('max_attempts', $this->extensionName);
+                               $string = LocalizationUtility::translate('max_attempts', $this->extensionName);
                                $font = 5;
                                $width  = imagefontwidth($font) * strlen($string);
                                $height = imagefontheight($font);
@@ -184,7 +193,7 @@ class ShowPng implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface {
                                ImageColorTransparent($image, $background);
                                $red = ImageColorAllocate($image, 255, 0, 0);
                                ImageString($image, $font, 1, 10, $string, $red);
-                               \SJBR\SrFreecap\Utility\ImageContentUtility::sendImage($image, $this->settings['imageFormat']);
+                               ImageContentUtility::sendImage($image, $this->settings['imageFormat']);
                                ImageDestroy($image);
                                // Return an empty string
                                return '';
@@ -192,7 +201,7 @@ class ShowPng implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface {
                }
 
                // Get random word
-               $word = \SJBR\SrFreecap\Utility\RandomContentUtility::getRandomWord($this->settings['useWordsList'], $this->settings['wordsListLocation'], $this->settings['generateNumbers'], $this->settings['maxWordLength']);
+               $word = RandomContentUtility::getRandomWord($this->settings['useWordsList'], $this->settings['wordsListLocation'], $this->settings['generateNumbers'], $this->settings['maxWordLength']);
 
                // Save hash of word for comparison
                // using hash so that if there's an insecurity elsewhere (eg on the form processor),
@@ -206,14 +215,14 @@ class ShowPng implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface {
 
                // We use a simple encrypt to prevent the session from being exposed
                if ($this->settings['accessibleOutput']) {
-                       $this->word->setWordCypher(\SJBR\SrFreecap\Utility\EncryptionUtility::encrypt($word));
+                       $this->word->setWordCypher(EncryptionUtility::encrypt($word));
                }
 
                // Build the image
                $image = $this->buildImage($word, $this->settings['imageWidth'], $this->settings['imageHeight'], $this->settings['backgroundType']);
 
                // Send the image
-               \SJBR\SrFreecap\Utility\ImageContentUtility::sendImage($image, $this->settings['imageFormat']);
+               ImageContentUtility::sendImage($image, $this->settings['imageFormat']);
 
                // Cleanup
                ImageDestroy($image);
@@ -227,33 +236,32 @@ class ShowPng implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface {
         *
         * @return string GD image identifier of image
         */
-       protected function buildImage ($word, $width, $height, $backgroundType) {
-               
+       protected function buildImage($word, $width, $height, $backgroundType)
+       {
                $image = ImageCreate($width, $height);
                $background = ImageColorAllocate($image, 254, 254, 254);
-               
+
                // Write word on image
-               $image = \SJBR\SrFreecap\Utility\ImageContentUtility::writeWordOnImage($width, $height, $word, $this->settings['textColor'], $this->settings['textPosition'], $this->settings['colorMaximum'], $backgroundType, $this->settings['fontLocations'], $this->settings['fontWidths'], $this->settings['morphFactor']);
+               $image = ImageContentUtility::writeWordOnImage($width, $height, $word, $this->settings['textColor'], $this->settings['textPosition'], $this->settings['colorMaximum'], $backgroundType, $this->settings['fontLocations'], $this->settings['fontWidths'], $this->settings['morphFactor']);
 
                // Blur edges
                // Doesn't really add any security, but looks a lot nicer, and renders text a little easier to read
                // for humans (hopefully not for OCRs, but if you know better, feel free to disable this function)
                // (and if you do, let me know why)
-               $image = \SJBR\SrFreecap\Utility\ImageContentUtility::blurImage($image);
+               $image = ImageContentUtility::blurImage($image);
 
-               if ($this->settings['imageFormat'] != 'jpg' && $backgroundType == \SJBR\SrFreecap\Utility\ImageContentUtility::BACKGROUND_TYPE_TRANSPARENT) {
+               if ($this->settings['imageFormat'] != 'jpg' && $backgroundType == ImageContentUtility::BACKGROUND_TYPE_TRANSPARENT) {
                        // Make background transparent
                        ImageColorTransparent($image, $background);
                }
 
-               if ($backgroundType != \SJBR\SrFreecap\Utility\ImageContentUtility::BACKGROUND_TYPE_TRANSPARENT) {
+               if ($backgroundType != ImageContentUtility::BACKGROUND_TYPE_TRANSPARENT) {
                        // Get noisy background
-                       $image3 = \SJBR\SrFreecap\Utility\ImageContentUtility::generateNoisyBackground($width, $height, $word, $backgroundType, $this->settings['backgroundImages'], $this->settings['backgroundMorph'], $this->settings['backgroundBlur']);
+                       $image3 = ImageContentUtility::generateNoisyBackground($width, $height, $word, $backgroundType, $this->settings['backgroundImages'], $this->settings['backgroundMorph'], $this->settings['backgroundBlur']);
                        // Merge with obfuscated background
-                       $image = \SJBR\SrFreecap\Utility\ImageContentUtility::mergeCaptchaWithBackground($width, $height, $image, $image3, $backgroundType, $this->settings['mergeWithBackground']);
+                       $image = ImageContentUtility::mergeCaptchaWithBackground($width, $height, $image, $image3, $backgroundType, $this->settings['mergeWithBackground']);
                        ImageDestroy($image3);
                }
-
                return $image;
        }
-}
+}
\ No newline at end of file
index 64ff112..f907820 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 namespace SJBR\SrFreecap\ViewHelpers;
 
-/***************************************************************
+/*
  *  Copyright notice
  *
  *  (c) 2013-2018 Stanislas Rolland <typo3(arobas)sjbr.ca>
@@ -24,13 +24,17 @@ namespace SJBR\SrFreecap\ViewHelpers;
  *  GNU General Public License for more details.
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ */
 
 use SJBR\SrFreecap\ViewHelpers\TranslateViewHelper;
+use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Session\Backend\Exception\SessionNotFoundException;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
-use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
+use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
 
 class AudioViewHelper extends AbstractTagBasedViewHelper
 {
@@ -58,6 +62,12 @@ class AudioViewHelper extends AbstractTagBasedViewHelper
                $this->configurationManager = $configurationManager;
        }
 
+       public function initializeArguments()
+       {
+               parent::initializeArguments();
+               $this->registerArgument('suffix', 'string', 'Suffix to be appended to the extenstion key when forming css class names', false, '');
+       }
+
        /**
         * Render the captcha audio rendering request icon
         *
@@ -67,7 +77,7 @@ class AudioViewHelper extends AbstractTagBasedViewHelper
        public function render($suffix = '')
        {
                // This viewhelper needs a frontend user session
-               if (!is_object($GLOBALS ['TSFE']) || !isset($GLOBALS ['TSFE']->fe_user)) {
+               if (!is_object($this->getTypoScriptFrontendController()) || !isset($this->getTypoScriptFrontendController()->fe_user)) {
                        throw new SessionNotFoundException('No frontend user found in session!');
                }
 
@@ -75,17 +85,19 @@ class AudioViewHelper extends AbstractTagBasedViewHelper
                // Get the plugin configuration
                $settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, $this->extensionName, $this->pluginName);
                // Get the translation view helper
-               $translator = GeneralUtility::makeInstance(TranslateViewHelper::class);
-               $translator->injectConfigurationManager($this->configurationManager);
+               $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
+               $translator = $objectManager->get(TranslateViewHelper::class);
                // Get browser info: in IE 8, we will use a simple link, as dynamic insertion of object element gives unpredictable results
         $browserInfo = GeneralUtility::getIndpEnv('HTTP_USER_AGENT');
         $browerIsIE8 = strpos($browserInfo, 'MSIE 8') !== false;
                // Generate the icon
                if ($settings['accessibleOutput'] && (int)$GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
+                       $context = GeneralUtility::makeInstance(Context::class);
+                       $languageAspect = $context->getAspect('language');
                        $fakeId = GeneralUtility::shortMD5(uniqid (rand()),5);
                        $siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
-                       $urlParams = array(
-                               'eID' => 'sr_freecap_EidDispatcher',
+                       $urlParams = [
+                               'eIDSR' => 'sr_freecap_EidDispatcher',
                                'id' => $GLOBALS['TSFE']->id,
                                'vendorName' => 'SJBR',
                                'extensionName' => $this->extensionName,
@@ -93,13 +105,10 @@ class AudioViewHelper extends AbstractTagBasedViewHelper
                                'controllerName' => 'AudioPlayer',
                                'actionName' => 'play',
                                'formatName' => $browerIsIE8 ? 'mp3' : 'wav',
-                       );
-                       $L = GeneralUtility::_GP('L');
-                       if (isset($L)) {
-                               $urlParams['L'] = htmlspecialchars($L);
-                       }
-                       if ($GLOBALS['TSFE']->MP) {
-                               $urlParams['MP'] = $GLOBALS['TSFE']->MP;
+                               'L' => $languageAspect->getId()
+                       ];
+                       if ($this->getTypoScriptFrontendController()->MP) {
+                               $urlParams['MP'] = $this->getTypoScriptFrontendController()->MP;
                        }
                        $audioURL = $siteURL . 'index.php?' . ltrim(GeneralUtility::implodeArrayForUrl('', $urlParams), '&');
                        if ($settings['accessibleOutputImage']) {
@@ -107,13 +116,13 @@ class AudioViewHelper extends AbstractTagBasedViewHelper
                                        $value = '<a href="' . $audioURL . '&set=' . rand()
                                                . '" title="' . $translator->render('click_here_accessible') . '">'
                                                . '<img alt="' . $translator->render('click_here_accessible') . '"'
-                                               . ' src="' . $siteURL . str_replace(PATH_site, '', GeneralUtility::getFileAbsFileName($settings['accessibleOutputImage'])) . '"'
+                                               . ' src="' . $siteURL . PathUtility::stripPathSitePrefix(GeneralUtility::getFileAbsFileName($settings['accessibleOutputImage'])) . '"'
                                                . $this->getClassAttribute('image-accessible', $suffix) . ' />'
                                                . '</a>';
                                } else {
                                        $value = '<input type="image" alt="' . $translator->render('click_here_accessible') . '"'
                                                . ' title="' . $translator->render('click_here_accessible') . '"'
-                                               . ' src="' . $siteURL . str_replace(PATH_site, '', GeneralUtility::getFileAbsFileName($settings['accessibleOutputImage'])) . '"'
+                                               . ' src="' . $siteURL . PathUtility::stripPathSitePrefix(GeneralUtility::getFileAbsFileName($settings['accessibleOutputImage'])) . '"'
                                                . ' onclick="' . $this->extensionName . '.playCaptcha(\'' . $fakeId . '\', \'' . $audioURL . '\', \'' . $translator->render('noPlayMessage') . '\');return false;" style="cursor: pointer;"'
                                                . $this->getClassAttribute('image-accessible', $suffix) . ' />';
                                }
@@ -151,4 +160,12 @@ class AudioViewHelper extends AbstractTagBasedViewHelper
        {
                return ' class="' . trim(str_replace('_', '-', $this->pluginName) . ($suffix ? '-' . $suffix . '-' : '-') . $class) . '"';
        }
+
+    /**
+     * @return TypoScriptFrontendController
+     */
+    protected function getTypoScriptFrontendController()
+    {
+        return $GLOBALS['TSFE'];
+    }
 }
\ No newline at end of file
index e6be819..287bd9f 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 namespace SJBR\SrFreecap\ViewHelpers;
 
-/***************************************************************
+/*
  *  Copyright notice
  *
- *  (c) 2013-2017 Stanislas Rolland <typo3(arobas)sjbr.ca>
+ *  (c) 2013-2018 Stanislas Rolland <typo3(arobas)sjbr.ca>
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -24,15 +24,19 @@ namespace SJBR\SrFreecap\ViewHelpers;
  *  GNU General Public License for more details.
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ */
 
 use SJBR\SrFreecap\ViewHelpers\TranslateViewHelper;
+use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Session\Backend\Exception\SessionNotFoundException;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
-use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
+use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
 
 class ImageViewHelper extends AbstractTagBasedViewHelper
 {
@@ -65,6 +69,12 @@ class ImageViewHelper extends AbstractTagBasedViewHelper
                $this->configurationManager = $configurationManager;
        }
 
+       public function initializeArguments()
+       {
+               parent::initializeArguments();
+               $this->registerArgument('suffix', 'string', 'Suffix to be appended to the extenstion key when forming css class names', false, '');
+       }
+
        /**
         * Render the captcha image html
         *
@@ -74,7 +84,7 @@ class ImageViewHelper extends AbstractTagBasedViewHelper
        public function render($suffix = '')
        {
                // This viewhelper needs a frontend user session
-               if (!is_object($GLOBALS ['TSFE']) || !isset($GLOBALS ['TSFE']->fe_user)) {
+               if (!is_object($this->getTypoScriptFrontendController()) || !isset($this->getTypoScriptFrontendController()->fe_user)) {
                        throw new SessionNotFoundException('No frontend user found in session!');
                }
 
@@ -82,35 +92,33 @@ class ImageViewHelper extends AbstractTagBasedViewHelper
 
                // Include the required JavaScript
                $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
-               $pageRenderer->addJsFooterFile(ExtensionManagementUtility::siteRelPath($this->extensionKey) . 'Resources/Public/JavaScript/freeCap.js');
+               $pageRenderer->addJsFooterFile(PathUtility::stripPathSitePrefix(ExtensionManagementUtility::extPath($this->extensionKey)) . 'Resources/Public/JavaScript/freeCap.js');
 
                // Disable caching
-               $GLOBALS['TSFE']->no_cache = 1;
-
-               // Get the plugin configuration
-               $settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, $this->extensionName);
+               $this->getTypoScriptFrontendController()->no_cache = 1;
 
                // Get the translation view helper
-               $translator = GeneralUtility::makeInstance(TranslateViewHelper::class);
-               $translator->injectConfigurationManager($this->configurationManager);
+               $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
+               $translator = $objectManager->get(TranslateViewHelper::class);
 
                // 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,
+               $context = GeneralUtility::makeInstance(Context::class);
+               $languageAspect = $context->getAspect('language');
+               $urlParams = [
+                       'eIDSR' => 'sr_freecap_EidDispatcher',
+                       'id' => $this->getTypoScriptFrontendController()->id,
                        'vendorName' => 'SJBR',
                        'extensionName' => 'SrFreecap',
                        'pluginName' => 'ImageGenerator',
                        'controllerName' => 'ImageGenerator',
                        'actionName' => 'show',
                        'formatName' => 'png',
-                       'L' => $GLOBALS['TSFE']->sys_language_uid
-               );
-               if ($GLOBALS['TSFE']->MP) {
-                       $urlParams['MP'] = $GLOBALS['TSFE']->MP;
+                       'L' => $languageAspect->getId()
+               ];
+               if ($this->getTypoScriptFrontendController()->MP) {
+                       $urlParams['MP'] = $this->getTypoScriptFrontendController()->MP;
                }
                $urlParams['set'] = $fakeId;
                $imageUrl = $siteURL . 'index.php?' . ltrim(GeneralUtility::implodeArrayForUrl('', $urlParams), '&');
@@ -137,4 +145,12 @@ class ImageViewHelper extends AbstractTagBasedViewHelper
        {
                return ' class="' . trim(str_replace('_', '-', $this->pluginName) . ($suffix ? '-' . $suffix . '-' : '-') . $class) . '"';
        }
+
+    /**
+     * @return TypoScriptFrontendController
+     */
+    protected function getTypoScriptFrontendController()
+    {
+        return $GLOBALS['TSFE'];
+    }
 }
\ No newline at end of file
index 13caccd..7fd4331 100644 (file)
@@ -1,30 +1,36 @@
 <?php
 namespace SJBR\SrFreecap\ViewHelpers;
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
-*  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.
-*  A copy is found in the textfile GPL.txt and important notices to the license
-*  from the author is found in LICENSE.txt distributed with these scripts.
-*
-*
-*  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!
-***************************************************************/
+
+/*
+ *  Copyright notice
+ *
+ *  (c) 2013-2018 Stanislas Rolland <typo3@sjbr.ca>
+ *  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.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  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!
+ */
+
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
+use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
+use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
+
 /**
  * Translate a key from locallang. The files are loaded from the folder
  * "Resources/Private/Language/".
@@ -63,8 +69,8 @@ namespace SJBR\SrFreecap\ViewHelpers;
  * // if the key is not found, the output is "default value"
  * </output>
  */
-class TranslateViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
-
+class TranslateViewHelper extends AbstractViewHelper
+{
        /**
         * @var string Name of the extension this view helper belongs to
         */
@@ -81,45 +87,66 @@ class TranslateViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewH
        protected $allowedSuffixes = array('formal', 'informal');
 
        /**
-        * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
+        * @var ConfigurationManagerInterface
         */
        protected $configurationManager;
 
        /**
-        * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
+        * @param ConfigurationManagerInterface $configurationManager
         * @return void
         */
-       public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) {
+       public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
+       {
                $this->configurationManager = $configurationManager;
        }
 
+       public function initializeArguments()
+       {
+               $this->registerArgument('key', 'string', 'The language key to translate', true);
+               $this->registerArgument('default', 'string', 'Value to be used when the key is not found');
+               $this->registerArgument('htmlEscape', 'boolean', 'Whether to escape html', false, true);
+               $this->registerArgument('arguments', 'array', 'Arguments to be replaced in the string');
+       }
+
        /**
         * Translate a given key or use the tag body as default.
         *
         * @param string $key The locallang key
         * @param string $default if the given locallang key could not be found, this value is used. . If this argument is not set, child nodes will be used to render the default
-        * @param boolean $htmlEscape TRUE if the result should be htmlescaped. This won't have an effect for the default value
+        * @param boolean $htmlEscape true if the result should be htmlescaped. This won't have an effect for the default value
         * @param array $arguments Arguments to be replaced in the resulting string
         * @return string The translated key or tag body if key doesn't exist
         * @author Christopher Hlubek <hlubek@networkteam.com>
         * @author Bastian Waidelich <bastian@typo3.org>
         */
-       public function render ($key, $default = NULL, $htmlEscape = TRUE, array $arguments = NULL) {
+       public function render($key = null)
+       {
+               if ($this->hasArgument('key')) {
+                       $key = $this->arguments['key'];
+               }
+               if ($this->hasArgument('default')) {
+                       $default = $this->arguments['default'];
+               }
+               if ($this->hasArgument('htmlEscape')) {
+                       $htmlEscape = $this->arguments['htmlEscape'];
+               }
+               if ($this->hasArgument('arguments')) {
+                       $arguments = $this->arguments['arguments'];
+               }
                // If the suffix is allowed and we have a localized string for the desired salutation, we'll take that.
-               $settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $this->extensionName, $this->pluginName);
+               $settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, $this->extensionName, $this->pluginName);
                if (isset($settings['salutation']) && in_array($settings['salutation'], $this->allowedSuffixes, 1)) {
                        $expandedKey = $key . '_' . $settings['salutation'];
-                       $value = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($expandedKey, $this->extensionName, $arguments);
+                       $value = LocalizationUtility::translate($expandedKey, $this->extensionName, $arguments);
                }
-               if ($value === NULL) {
-                       $value = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, $this->extensionName, $arguments);
+               if ($value === null) {
+                       $value = LocalizationUtility::translate($key, $this->extensionName, $arguments);
                }
-               if ($value === NULL) {
-                       $value = $default !== NULL ? $default : $this->renderChildren();
+               if ($value === null) {
+                       $value = $default !== null ? $default : $this->renderChildren();
                } elseif ($htmlEscape) {
                        $value = htmlspecialchars($value);
                }
                return $value;
        }
-}
-?>
+}
\ No newline at end of file
index 8d7324d..37aeb94 100644 (file)
@@ -1,7 +1,7 @@
 {
   "name": "sjbr/sr-freecap",
   "description": "A TYPO3 integration of freeCap CAPTCHA.",
-  "version": "2.4.4",
+  "version": "2.5.0",
   "type": "typo3-cms-extension",
   "license": "GPL-2.0+",
   "keywords": [
@@ -24,7 +24,7 @@
        "typo3-ter/sr-freecap": "self.version"
   },
   "require": {
-         "typo3/cms-core": ">=7.6,<9.0"
+       "typo3/cms-core": ">=9.5,<10.0"
   },
   "autoload": {
     "psr-4": {
index 387d31f..1e8c1b6 100644 (file)
Binary files a/doc/manual.sxw and b/doc/manual.sxw differ
index 86339c2..c846099 100644 (file)
@@ -3,11 +3,11 @@
  * Extension Manager configuration file for ext "sr_freecap".
  *
  */
-$EM_CONF[$_EXTKEY] = array(
+$EM_CONF[$_EXTKEY] = [
        'title' => 'freeCap CAPTCHA',
        'description' => 'A TYPO3 integration of freeCap CAPTCHA.',
        'category' => 'plugin',
-       'version' => '2.4.4',
+       'version' => '2.5.0',
        'state' => 'stable',
        'uploadfolder' => 1,
        'createDirs' => '',
@@ -15,11 +15,11 @@ $EM_CONF[$_EXTKEY] = array(
        'author' => 'Stanislas Rolland',
        'author_email' => 'typo3(arobas)sjbr.ca',
        'author_company' => 'SJBR',
-       'constraints' => array(
-               'depends' => array(
-                       'typo3' => '7.6.0-8.7.99'
-               ),
-               'conflicts' => array(),
-               'suggests' => array()
-       )
-);
\ No newline at end of file
+       'constraints' => [
+               'depends' => [
+                       'typo3' => '9.5.0-9.5.99'
+               ],
+               'conflicts' => [],
+               'suggests' => []
+       ]
+];
\ No newline at end of file
index 15a9c30..92d3c33 100644 (file)
@@ -2,14 +2,15 @@
 defined('TYPO3_MODE') or die();
 
 call_user_func(
-    function($extKey, $extConf)
+    function($extKey)
     {
+       $extConf = (bool)\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)->get($extKey);
                // Setting the encryption algorithm
                $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sr_freecap']['encryptionAlgorithm'] = isset($extConf['encryptionAlgorithm']) ? $extConf['encryptionAlgorithm'] : 'AES-256-CBC';
                $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sr_freecap']['salt'] = isset($extConf['salt']) ? $extConf['salt'] : 'cH!swe!retReGu7W6bEDRup7usuDUh9THeD2CHeGE*ewr4n39=E@rAsp7c-Ph@pH';
 
                // Dispatching requests to image generator and audio player
-               $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['sr_freecap_EidDispatcher'] = 'EXT:sr_freecap/Resources/Private/Eid/EidDispatcher.php';
+               $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sr_freecap']['eIDSR_include']['sr_freecap_EidDispatcher'] = \SJBR\SrFreecap\Http\EidDispatcher::class . '::initAndDispatch';
 
                // Configuring the captcha image generator
                \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
@@ -45,6 +46,5 @@ call_user_func(
                        ]
                );
        },
-       'sr_freecap',
-       unserialize($_EXTCONF)
+       'sr_freecap'
 );
\ No newline at end of file