Initial commit - Typo3 11.5.41
This commit is contained in:
154
typo3conf/ext/sr_freecap/Classes/ViewHelpers/AudioViewHelper.php
Normal file
154
typo3conf/ext/sr_freecap/Classes/ViewHelpers/AudioViewHelper.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
namespace SJBR\SrFreecap\ViewHelpers;
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2013-2022 Stanislas Rolland <typo3AAAA(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\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\Frontend\Controller\TypoScriptFrontendController;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
|
||||
|
||||
class AudioViewHelper extends AbstractTagBasedViewHelper
|
||||
{
|
||||
/**
|
||||
* @var string Name of the extension this view helper belongs to
|
||||
*/
|
||||
protected $extensionName = 'SrFreecap';
|
||||
|
||||
/**
|
||||
* @var string Name of the extension this view helper belongs to
|
||||
*/
|
||||
protected $pluginName = 'tx_srfreecap';
|
||||
|
||||
/**
|
||||
* @var ConfigurationManagerInterface
|
||||
*/
|
||||
protected $configurationManager;
|
||||
|
||||
/**
|
||||
* @param ConfigurationManagerInterface $configurationManager
|
||||
* @return void
|
||||
*/
|
||||
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
|
||||
{
|
||||
$this->configurationManager = $configurationManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
*/
|
||||
public function injectContext(Context $context)
|
||||
{
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
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
|
||||
*
|
||||
* @param string suffix to be appended to the extenstion key when forming css class names
|
||||
* @return string The html used to render the captcha audio rendering request icon
|
||||
*/
|
||||
public function render($suffix = '')
|
||||
{
|
||||
// This viewhelper needs a frontend user session
|
||||
if (!is_object($this->getTypoScriptFrontendController()) || !isset($this->getTypoScriptFrontendController()->fe_user)) {
|
||||
throw new SessionNotFoundException('No frontend user found in session!');
|
||||
}
|
||||
$value = '';
|
||||
// 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);
|
||||
// Generate the icon
|
||||
if (($settings['accessibleOutput'] ?? false) && ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem'] ?? false)) {
|
||||
$languageAspect = $this->context->getAspect('language');
|
||||
$fakeId = substr(md5(uniqid(rand())), 0, 5);
|
||||
$siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
|
||||
$urlParams = [
|
||||
'eIDSR' => 'sr_freecap_EidDispatcher',
|
||||
'id' => $GLOBALS['TSFE']->id,
|
||||
'pluginName' => 'AudioPlayer',
|
||||
'actionName' => 'play',
|
||||
'formatName' => 'wav',
|
||||
'L' => $languageAspect->getId()
|
||||
];
|
||||
if ($this->getTypoScriptFrontendController()->MP) {
|
||||
$urlParams['MP'] = $this->getTypoScriptFrontendController()->MP;
|
||||
}
|
||||
$audioURL = $siteURL . 'index.php?' . ltrim(GeneralUtility::implodeArrayForUrl('', $urlParams), '&');
|
||||
if (isset($settings['accessibleOutputImage']) && $settings['accessibleOutputImage']) {
|
||||
$value = '<input type="image" alt="' . $translator->render('click_here_accessible') . '"'
|
||||
. ' title="' . $translator->render('click_here_accessible') . '"'
|
||||
. ' 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) . ' />';
|
||||
} else {
|
||||
$value = '<span id="tx_srfreecap_captcha_playLink_' . $fakeId . '"'
|
||||
. $this->getClassAttribute('accessible-link', $suffix) . '>' . $translator->render('click_here_accessible_before_link')
|
||||
. '<a href="#" onClick="' . $this->extensionName . '.playCaptcha(\'' . $fakeId.'\', \'' . $audioURL . '\', \'' . $translator->render('noPlayMessage') . '\');return false;" style="cursor: pointer;" title="' . $translator->render('click_here_accessible') . '">'
|
||||
. $translator->render('click_here_accessible_link') . '</a>'
|
||||
. $translator->render('click_here_accessible_after_link') . '</span>';
|
||||
}
|
||||
$value .= '<span' . $this->getClassAttribute('accessible', $suffix) . ' id="tx_srfreecap_captcha_playAudio_' . $fakeId . '"></span>';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a class attribute with a class-name prefixed with $this->pluginName and with all underscores substituted to dashes (-)
|
||||
*
|
||||
* @param string $class The class name (or the END of it since it will be prefixed by $this->pluginName.'-')
|
||||
* @param string suffix to be appended to the extenstion key when forming css class names
|
||||
* @return string the class attribute with the combined class name (with the correct prefix)
|
||||
*/
|
||||
protected function getClassAttribute ($class, $suffix = '')
|
||||
{
|
||||
return ' class="' . trim(str_replace('_', '-', $this->pluginName) . ($suffix ? '-' . $suffix . '-' : '-') . $class) . '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TypoScriptFrontendController
|
||||
*/
|
||||
protected function getTypoScriptFrontendController()
|
||||
{
|
||||
return $GLOBALS['TSFE'];
|
||||
}
|
||||
}
|
||||
174
typo3conf/ext/sr_freecap/Classes/ViewHelpers/ImageViewHelper.php
Normal file
174
typo3conf/ext/sr_freecap/Classes/ViewHelpers/ImageViewHelper.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
namespace SJBR\SrFreecap\ViewHelpers;
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2013-2021 Stanislas Rolland <typo3AAAA(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\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\Frontend\Controller\TypoScriptFrontendController;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
|
||||
|
||||
class ImageViewHelper extends AbstractTagBasedViewHelper
|
||||
{
|
||||
/**
|
||||
* @var string Name of the extension this view helper belongs to
|
||||
*/
|
||||
protected $extensionName = 'SrFreecap';
|
||||
|
||||
/**
|
||||
* @var string Name of the extension this view helper belongs to
|
||||
*/
|
||||
protected $extensionKey = 'sr_freecap';
|
||||
|
||||
/**
|
||||
* @var string Name of the plugin this view helper belongs to
|
||||
*/
|
||||
protected $pluginName = 'tx_srfreecap';
|
||||
|
||||
/**
|
||||
* @var ConfigurationManagerInterface
|
||||
*/
|
||||
protected $configurationManager;
|
||||
|
||||
/**
|
||||
* @param ConfigurationManagerInterface $configurationManager
|
||||
*/
|
||||
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
|
||||
{
|
||||
$this->configurationManager = $configurationManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var PageRenderer
|
||||
*/
|
||||
protected $pageRenderer;
|
||||
|
||||
/**
|
||||
* @param PageRenderer $pageRenderer
|
||||
*/
|
||||
public function injectPageRenderer(PageRenderer $pageRenderer)
|
||||
{
|
||||
$this->pageRenderer = $pageRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
*/
|
||||
public function injectContext(Context $context)
|
||||
{
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
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
|
||||
*
|
||||
* @param string suffix to be appended to the extenstion key when forming css class names
|
||||
* @return string The html used to render the captcha image
|
||||
*/
|
||||
public function render($suffix = '')
|
||||
{
|
||||
// This viewhelper needs a frontend user session
|
||||
if (!is_object($this->getTypoScriptFrontendController()) || !isset($this->getTypoScriptFrontendController()->fe_user)) {
|
||||
throw new SessionNotFoundException('No frontend user found in session!');
|
||||
}
|
||||
|
||||
$value = '';
|
||||
|
||||
// Include the required JavaScript
|
||||
$this->pageRenderer->addJsFooterFile(PathUtility::stripPathSitePrefix(ExtensionManagementUtility::extPath($this->extensionKey)) . 'Resources/Public/JavaScript/freeCap.js');
|
||||
|
||||
// Disable caching
|
||||
$this->getTypoScriptFrontendController()->no_cache = true;
|
||||
|
||||
// Get the translation view helper
|
||||
$translator = GeneralUtility::makeInstance(TranslateViewHelper::class);
|
||||
|
||||
// Generate the image url
|
||||
$fakeId = substr(md5(uniqid(rand())), 0, 5);
|
||||
$siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
|
||||
$languageAspect = $this->context->getAspect('language');
|
||||
$urlParams = [
|
||||
'eIDSR' => 'sr_freecap_EidDispatcher',
|
||||
'id' => $this->getTypoScriptFrontendController()->id,
|
||||
'pluginName' => 'ImageGenerator',
|
||||
'actionName' => 'show',
|
||||
'formatName' => 'png',
|
||||
'L' => $languageAspect->getId()
|
||||
];
|
||||
if ($this->getTypoScriptFrontendController()->MP) {
|
||||
$urlParams['MP'] = $this->getTypoScriptFrontendController()->MP;
|
||||
}
|
||||
$urlParams['set'] = $fakeId;
|
||||
$imageUrl = $siteURL . 'index.php?' . ltrim(GeneralUtility::implodeArrayForUrl('', $urlParams), '&');
|
||||
|
||||
// Generate the html text
|
||||
$value = '<img' . $this->getClassAttribute('image', $suffix) . ' id="tx_srfreecap_captcha_image_' . $fakeId . '"'
|
||||
. ' src="' . htmlspecialchars($imageUrl) . '"'
|
||||
. ' alt="' . $translator->render('altText') . ' "/>'
|
||||
. '<span' . $this->getClassAttribute('cant-read', $suffix) . '>' . $translator->render('cant_read1')
|
||||
. ' <a href="#" onclick="this.blur();' . $this->extensionName . '.newImage(\'' . $fakeId . '\', \'' . $translator->render('noImageMessage').'\');return false;">'
|
||||
. $translator->render('click_here') . '</a>'
|
||||
. $translator->render('cant_read2') . '</span>';
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a class attribute with a class-name prefixed with $this->pluginName and with all underscores substituted to dashes (-)
|
||||
*
|
||||
* @param string $class The class name (or the END of it since it will be prefixed by $this->pluginName.'-')
|
||||
* @param string suffix to be appended to the extenstion key when forming css class names
|
||||
* @return string the class attribute with the combined class name (with the correct prefix)
|
||||
*/
|
||||
protected function getClassAttribute($class, $suffix = '')
|
||||
{
|
||||
return ' class="' . trim(str_replace('_', '-', $this->pluginName) . ($suffix ? '-' . $suffix . '-' : '-') . $class) . '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TypoScriptFrontendController
|
||||
*/
|
||||
protected function getTypoScriptFrontendController()
|
||||
{
|
||||
return $GLOBALS['TSFE'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
namespace SJBR\SrFreecap\ViewHelpers;
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2013-2022 Stanislas Rolland <typo3AAAA@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/".
|
||||
*
|
||||
* Handle salutation suffixes
|
||||
*
|
||||
* == Examples ==
|
||||
*
|
||||
* <code title="Translate key">
|
||||
* <f:translate key="key1" />
|
||||
* </code>
|
||||
* <output>
|
||||
* // value of key "key1" in the current website language
|
||||
* </output>
|
||||
*
|
||||
* <code title="Keep HTML tags">
|
||||
* <f:translate key="htmlKey" htmlEscape="false" />
|
||||
* </code>
|
||||
* <output>
|
||||
* // value of key "htmlKey" in the current website language, no htmlspecialchars applied
|
||||
* </output>
|
||||
*
|
||||
* <code title="Translate key from custom locallang file">
|
||||
* <f:translate key="LLL:EXT:myext/Resources/Private/Language/locallang.xml:key1" />
|
||||
* </code>
|
||||
* <output>
|
||||
* // value of key "key1" in the current website language
|
||||
* </output>
|
||||
*
|
||||
* <code title="Inline notation with arguments and default value">
|
||||
* {f:translate(key: 'argumentsKey', arguments: {0: 'dog', 1: 'fox'}, default: 'default value')}
|
||||
* </code>
|
||||
* <output>
|
||||
* // value of key "argumentsKey" in the current website language
|
||||
* // with "%1" and "%2" are replaced by "dog" and "fox" (printf)
|
||||
* // if the key is not found, the output is "default value"
|
||||
* </output>
|
||||
*/
|
||||
class TranslateViewHelper extends AbstractViewHelper
|
||||
{
|
||||
/**
|
||||
* @var string Name of the extension this view helper belongs to
|
||||
*/
|
||||
protected $extensionName = 'SrFreecap';
|
||||
|
||||
/**
|
||||
* @var string Name of the extension this view helper belongs to
|
||||
*/
|
||||
protected $pluginName = 'tx_srfreecap';
|
||||
|
||||
/**
|
||||
* @var array List of allowed suffixes
|
||||
*/
|
||||
protected $allowedSuffixes = ['formal', 'informal'];
|
||||
|
||||
/**
|
||||
* @var ConfigurationManagerInterface
|
||||
*/
|
||||
protected $configurationManager;
|
||||
|
||||
/**
|
||||
* @param ConfigurationManagerInterface $configurationManager
|
||||
* @return void
|
||||
*/
|
||||
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 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 = null)
|
||||
{
|
||||
if ($this->hasArgument('key')) {
|
||||
$key = $this->arguments['key'];
|
||||
}
|
||||
$value = null;
|
||||
$default = $this->hasArgument('default') ? $this->arguments['default'] : '';
|
||||
$htmlEscape = $this->hasArgument('htmlEscape') ? $this->arguments['htmlEscape'] : false;
|
||||
$arguments = $this->hasArgument('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(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, $this->extensionName, $this->pluginName);
|
||||
if (isset($settings['salutation']) && in_array($settings['salutation'], $this->allowedSuffixes, 1)) {
|
||||
$expandedKey = $key . '_' . $settings['salutation'];
|
||||
$value = LocalizationUtility::translate($expandedKey, $this->extensionName, $arguments);
|
||||
}
|
||||
if ($value === null) {
|
||||
$value = LocalizationUtility::translate($key, $this->extensionName, $arguments);
|
||||
}
|
||||
if ($value === null) {
|
||||
$value = $default !== null ? $default : $this->renderChildren();
|
||||
} elseif ($htmlEscape) {
|
||||
$value = htmlspecialchars($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user