[TASK] Localize preview boxes 08/55108/14
authorStephan Großberndt <stephan@grossberndt.de>
Sat, 16 Dec 2017 10:45:18 +0000 (11:45 +0100)
committerBenni Mack <benni@typo3.org>
Mon, 5 Mar 2018 06:43:30 +0000 (07:43 +0100)
* 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>
typo3/sysext/frontend/Classes/Hooks/FrontendHooks.php
typo3/sysext/workspaces/Classes/Middleware/WorkspacePreview.php
typo3/sysext/workspaces/Resources/Private/Language/locallang_mod.xlf

index 09dd582..bc77eb7 100644 (file)
@@ -14,8 +14,11 @@ namespace TYPO3\CMS\Frontend\Hooks;
  * 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
 {
@@ -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)
@@ -35,6 +38,7 @@ class FrontendHooks
         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';
@@ -48,11 +52,19 @@ class FrontendHooks
             $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'];
+    }
 }
index dc436ed..8999aaa 100644 (file)
@@ -23,8 +23,8 @@ use TYPO3\CMS\Core\Database\ConnectionPool;
 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;
 
@@ -121,20 +121,22 @@ class WorkspacePreview implements MiddlewareInterface
      */
     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));
     }
 
@@ -154,7 +156,7 @@ class WorkspacePreview implements MiddlewareInterface
      * @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)) {
@@ -285,16 +287,15 @@ class WorkspacePreview implements MiddlewareInterface
                     $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';
@@ -352,4 +353,12 @@ class WorkspacePreview implements MiddlewareInterface
     {
         return (string)preg_replace('/\\&?' . $this->previewKey . '=[[:alnum:]]+/', '', $url);
     }
+
+    /**
+     * @return LanguageService
+     */
+    protected function getLanguageService(): LanguageService
+    {
+        return $GLOBALS['LANG'] ?: GeneralUtility::makeInstance(LanguageService::class);
+    }
 }
index da322ec..a2fcfac 100644 (file)
                        <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>