[FEATURE] Add freeCap.js via pageRenderer 84/51184/3
authorStanislas Rolland <typo3@sjbr.ca>
Sun, 8 Jan 2017 04:09:19 +0000 (23:09 -0500)
committerStanislas Rolland <typo3@sjbr.ca>
Sun, 8 Jan 2017 04:15:27 +0000 (05:15 +0100)
In order to enable compression.

Resolves: #76062
Change-Id: Ic7e9f5f9f5f092d30eb80663f5c65c2b0e9b6e7d
Reviewed-on: https://review.typo3.org/51184
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
ChangeLog
Classes/ViewHelpers/AudioViewHelper.php
Classes/ViewHelpers/ImageViewHelper.php

index 2ae0e5c..bc5d509 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,8 @@
 
        * Change composer name to sjbr/sr-freecap
        * Require TYPO3 CMS 7.6 LTS
-       * Resolves #79195: Require zend.multibyte
+       * Resolves #79195: Require zend.multibyte for backend module
+       * Resolves #76062: add freeCap.js via includeJSlibs for compression
 
 2016-02-13  Stanislas Rolland  <typo(arobas)sjbr.ca>
 
index 74c5ccd..781bbc7 100644 (file)
@@ -1,32 +1,39 @@
 <?php
 namespace SJBR\SrFreecap\ViewHelpers;
+
 /***************************************************************
-*  Copyright notice
-*
-*  (c) 2013-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!
-***************************************************************/
-class AudioViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+ *  Copyright notice
+ *
+ *  (c) 2013-2017 Stanislas Rolland <typo3(arobas)sjbr.ca>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  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 SJBR\SrFreecap\ViewHelpers\TranslateViewHelper;
+use TYPO3\CMS\Core\Utility\ClientUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
 
+class AudioViewHelper extends AbstractTagBasedViewHelper
+{
        /**
         * @var string Name of the extension this view helper belongs to
         */
@@ -43,10 +50,10 @@ class AudioViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelpe
        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;
        }
 
@@ -59,18 +66,17 @@ class AudioViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelpe
        public function render ($suffix = '') {
                $value = '';
                // Get the plugin configuration
-               $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);
                // Get the translation view helper
-               $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
-               $translator = $objectManager->get('SJBR\\SrFreecap\\ViewHelpers\\TranslateViewHelper');
+               $translator = GeneralUtility::makeInstance(TranslateViewHelper::class);
                $translator->injectConfigurationManager($this->configurationManager);
                // Get browser info: in IE 8, we will use a simple link, as dynamic insertion of object element gives unpredictable results
-                $browserInfo = \TYPO3\CMS\Core\Utility\ClientUtility::getBrowserInfo(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_USER_AGENT'));
+                $browserInfo = ClientUtility::getBrowserInfo(GeneralUtility::getIndpEnv('HTTP_USER_AGENT'));
                 $browerIsIE8 = $browserInfo['browser'] == 'msie' && $browserInfo['version'] == '8';
                // Generate the icon
                if ($settings['accessibleOutput'] && in_array('mcrypt', get_loaded_extensions()) && intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem'])) {
-                       $fakeId = \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5(uniqid (rand()),5);
-                       $siteURL = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
+                       $fakeId = GeneralUtility::shortMD5(uniqid (rand()),5);
+                       $siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
                        $urlParams = array(
                                'eID' => 'sr_freecap_EidDispatcher',
                                'id' => $GLOBALS['TSFE']->id,
@@ -88,19 +94,19 @@ class AudioViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelpe
                        if ($GLOBALS['TSFE']->MP) {
                                $urlParams['MP'] = $GLOBALS['TSFE']->MP;
                        }
-                       $audioURL = $siteURL . 'index.php?' . ltrim(\TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', $urlParams), '&');
+                       $audioURL = $siteURL . 'index.php?' . ltrim(GeneralUtility::implodeArrayForUrl('', $urlParams), '&');
                        if ($settings['accessibleOutputImage']) {
                                if ($browerIsIE8) {
-                                       $value = '<a href="' . $audioURL . '&set=' . rand() 
+                                       $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, '', \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($settings['accessibleOutputImage'])) . '"'
+                                               . ' src="' . $siteURL . str_replace(PATH_site, '', 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, '', \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($settings['accessibleOutputImage'])) . '"'
+                                               . ' src="' . $siteURL . str_replace(PATH_site, '', GeneralUtility::getFileAbsFileName($settings['accessibleOutputImage'])) . '"'
                                                . ' onclick="' . $this->extensionName . '.playCaptcha(\'' . $fakeId . '\', \'' . $audioURL . '\', \'' . $translator->render('noPlayMessage') . '\');return false;" style="cursor: pointer;"'
                                                . $this->getClassAttribute('image-accessible', $suffix) . ' />';
                                }
@@ -137,4 +143,4 @@ class AudioViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelpe
        protected function getClassAttribute ($class, $suffix = '') {
                return ' class="' . trim(str_replace('_', '-', $this->pluginName) . ($suffix ? '-' . $suffix . '-' : '-') . $class) . '"';
        }
-}
+}
\ No newline at end of file
index 46bb14f..dc50a6a 100644 (file)
@@ -4,7 +4,7 @@ namespace SJBR\SrFreecap\ViewHelpers;
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2013-2016 Stanislas Rolland <typo3(arobas)sjbr.ca>
+ *  (c) 2013-2017 Stanislas Rolland <typo3(arobas)sjbr.ca>
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -26,12 +26,14 @@ namespace SJBR\SrFreecap\ViewHelpers;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
+use SJBR\SrFreecap\ViewHelpers\TranslateViewHelper;
+use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
-use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
 
-class ImageViewHelper extends AbstractViewHelper
+class ImageViewHelper extends AbstractTagBasedViewHelper
 {
        /**
         * @var string Name of the extension this view helper belongs to
@@ -73,7 +75,8 @@ class ImageViewHelper extends AbstractViewHelper
                $value = '';
 
                // Include the required JavaScript
-               $GLOBALS['TSFE']->additionalHeaderData[$this->extensionKey . '_freeCap'] = '<script type="text/javascript" src="' . GeneralUtility::createVersionNumberedFilename(ExtensionManagementUtility::siteRelPath($this->extensionKey) . 'Resources/Public/JavaScript/freeCap.js') . '"></script>';
+               $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
+               $pageRenderer->addJsFooterFile(ExtensionManagementUtility::siteRelPath($this->extensionKey) . 'Resources/Public/JavaScript/freeCap.js');
 
                // Disable caching
                $GLOBALS['TSFE']->no_cache = 1;
@@ -82,8 +85,7 @@ class ImageViewHelper extends AbstractViewHelper
                $settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, $this->extensionName);
 
                // Get the translation view helper
-               $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
-               $translator = $objectManager->get('SJBR\\SrFreecap\\ViewHelpers\\TranslateViewHelper');
+               $translator = GeneralUtility::makeInstance(TranslateViewHelper::class);
                $translator->injectConfigurationManager($this->configurationManager);
 
                // Generate the image url