Skip to content

Commit

Permalink
[TASK] Localize preview boxes
Browse files Browse the repository at this point in the history
* Make the box shown when previewing in Frontend either a hidden page or
  an unpublished version in a workspace use translated labels
* Add missing htmlspecialchars() calls
* Restore the link to stop the preview
* Use translation of LanguageService to use the language of the current
  backend user

Resolves: #83352
Releases: master
Change-Id: I4a00965d02e549f4953d0a9b891e2469a7ff9a64
Reviewed-on: https://review.typo3.org/55108
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
  • Loading branch information
sgrossberndt authored and bmack committed Mar 5, 2018
1 parent 9b5ce1b commit b998ae4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
20 changes: 16 additions & 4 deletions typo3/sysext/frontend/Classes/Hooks/FrontendHooks.php
Expand Up @@ -14,8 +14,11 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
* Uses frontend hooks to show preview informations
* Uses frontend hooks to show preview information
*/
class FrontendHooks
{
Expand All @@ -24,7 +27,7 @@ class FrontendHooks
* in the LIVE workspace
*
* @param array $params
* @param \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $pObj
* @param TypoScriptFrontendController $pObj
* @return string
*/
public function hook_previewInfo($params, $pObj)
Expand All @@ -35,6 +38,7 @@ public function hook_previewInfo($params, $pObj)
if ($pObj->config['config']['message_preview']) {
$message = $pObj->config['config']['message_preview'];
} else {
$label = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_tsfe.xlf:preview');
$styles = [];
$styles[] = 'position: fixed';
$styles[] = 'top: 15px';
Expand All @@ -48,11 +52,19 @@ public function hook_previewInfo($params, $pObj)
$styles[] = 'color: #856404';
$styles[] = 'z-index: 20000';
$styles[] = 'user-select: none';
$styles[] = 'pointer-events:none';
$styles[] = 'pointer-events: none';
$styles[] = 'text-align: center';
$styles[] = 'border-radius: 2px';
$message = '<div id="typo3-preview-info" style="' . implode(';', $styles) . '">PREVIEW</div>';
$message = '<div id="typo3-preview-info" style="' . implode(';', $styles) . '">' . htmlspecialchars($label) . '</div>';
}
return $message;
}

/**
* @return LanguageService
*/
protected function getLanguageService()
{
return $GLOBALS['LANG'];
}
}
37 changes: 23 additions & 14 deletions typo3/sysext/workspaces/Classes/Middleware/WorkspacePreview.php
Expand Up @@ -23,8 +23,8 @@
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Http\NormalizedParams;
use TYPO3\CMS\Core\Http\Stream;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Workspaces\Authentication\PreviewUserAuthentication;

Expand Down Expand Up @@ -121,20 +121,22 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
*/
protected function getLogoutTemplateMessage(string $returnUrl = ''): string
{
$returnUrl = GeneralUtility::sanitizeLocalUrl($returnUrl);
$returnUrl = $this->removePreviewParameterFromUrl($returnUrl);
if ($GLOBALS['TYPO3_CONF_VARS']['FE']['workspacePreviewLogoutTemplate']) {
$templateFile = GeneralUtility::getFileAbsFileName($GLOBALS['TYPO3_CONF_VARS']['FE']['workspacePreviewLogoutTemplate']);
if (@is_file($templateFile)) {
$message = file_get_contents($templateFile);
} else {
$message = '<strong>ERROR!</strong><br>Template File "'
. $GLOBALS['TYPO3_CONF_VARS']['FE']['workspacePreviewLogoutTemplate']
. '" configured with $TYPO3_CONF_VARS["FE"]["workspacePreviewLogoutTemplate"] not found. Please contact webmaster about this problem.';
$message = $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:previewLogoutError');
$message = htmlspecialchars($message);
$message = sprintf($message, '<strong>', '</strong><br>', $templateFile);
}
} else {
$message = 'You logged out from Workspace preview mode. Click this link to <a href="%1$s">go back to the website</a>';
$message = $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:previewLogoutSuccess');
$message = htmlspecialchars($message);
$message = sprintf($message, '<a href="' . htmlspecialchars($returnUrl) . '">', '</a>');
}
$returnUrl = GeneralUtility::sanitizeLocalUrl($returnUrl);
$returnUrl = $this->removePreviewParameterFromUrl($returnUrl);
return sprintf($message, htmlspecialchars($returnUrl));
}

Expand All @@ -154,7 +156,7 @@ protected function getLogoutTemplateMessage(string $returnUrl = ''): string
* @return array Preview configuration array from sys_preview record.
* @throws \Exception
*/
protected function getPreviewConfigurationFromRequest(ServerRequestInterface $request, string $inputCode)
protected function getPreviewConfigurationFromRequest(ServerRequestInterface $request, string $inputCode): array
{
$previewData = $this->getPreviewData($inputCode);
if (!is_array($previewData)) {
Expand Down Expand Up @@ -285,16 +287,15 @@ protected function renderPreviewInfo(TypoScriptFrontendController $tsfe, Normali
$currentWorkspaceId ?? -99
);
} else {
$text = LocalizationUtility::translate(
'LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:previewText',
'workspaces',
[$currentWorkspaceTitle, $currentWorkspaceId ?? -99]
);
$text = $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:previewText');
$text = htmlspecialchars($text);
$text = sprintf($text, $currentWorkspaceTitle, $currentWorkspaceId ?? -99);
$stopPreviewText = $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:stopPreview');
$stopPreviewText = htmlspecialchars($stopPreviewText);
if ($GLOBALS['BE_USER'] instanceof PreviewUserAuthentication) {
$url = $this->removePreviewParameterFromUrl($normalizedParams->getRequestUri());
$urlForStoppingPreview = $normalizedParams->getSiteUrl() . 'index.php?returnUrl=' . rawurlencode($url) . '&ADMCMD_prev=LOGOUT';
$text .= '<br><a style="color: #000; pointer-events: visible;" href="' . htmlspecialchars($urlForStoppingPreview) . '">Stop preview</a>';
$text .= '<br><a style="color: #000; pointer-events: visible;" href="' . htmlspecialchars($urlForStoppingPreview) . '">' . $stopPreviewText . '</a>';
}
$styles = [];
$styles[] = 'position: fixed';
Expand Down Expand Up @@ -352,4 +353,12 @@ protected function removePreviewParameterFromUrl(string $url): string
{
return (string)preg_replace('/\\&?' . $this->previewKey . '=[[:alnum:]]+/', '', $url);
}

/**
* @return LanguageService
*/
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'] ?: GeneralUtility::makeInstance(LanguageService::class);
}
}
Expand Up @@ -30,6 +30,15 @@
<trans-unit id="previewText">
<source>Preview of workspace %s (%s)</source>
</trans-unit>
<trans-unit id="stopPreview">
<source>Stop preview</source>
</trans-unit>
<trans-unit id="previewLogoutSuccess">
<source>You logged out from Workspace preview mode. Click this link to %1$s go back to the website%2$s</source>
</trans-unit>
<trans-unit id="previewLogoutError">
<source>%1$sERROR!%2$sTemplate File "%3$s" configured with $TYPO3_CONF_VARS["FE"]["workspacePreviewLogoutTemplate"] not found. Please contact webmaster about this problem.</source>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit b998ae4

Please sign in to comment.