0d103983b58ffddc8b2c5b51a3a0d53aed1e81bc
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Hook / TypoScriptFrontendControllerHook.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\Hook;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Frontend hooks
19 */
20 class TypoScriptFrontendControllerHook
21 {
22 /**
23 * @param array $params
24 * @param \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $pObj
25 */
26 public function hook_eofe($params, $pObj)
27 {
28 // 2 means preview of a non-live workspace
29 if ($pObj->fePreview !== 2) {
30 return;
31 }
32
33 if (empty($this->getBackendUserAuthentication()->getSessionData('workspaces.backend_domain'))) {
34 $backendDomain = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
35 } else {
36 $backendDomain = $this->getBackendUserAuthentication()->getSessionData('workspaces.backend_domain');
37 }
38
39 $previewParts = $this->getTypoScriptFrontendController()->cObj->cObjGetSingle('FLUIDTEMPLATE', [
40 'file' => 'EXT:workspaces/Resources/Private/Templates/Preview/Preview.html',
41 'variables.' => [
42 'backendDomain' => 'TEXT',
43 'backendDomain.' => ['value' => $backendDomain]
44 ]
45 ]);
46 $this->getTypoScriptFrontendController()->content = str_ireplace('</body>', $previewParts . '</body>', $this->getTypoScriptFrontendController()->content);
47 }
48
49 /**
50 * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
51 */
52 protected function getTypoScriptFrontendController()
53 {
54 return $GLOBALS['TSFE'];
55 }
56
57 /**
58 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
59 */
60 protected function getBackendUserAuthentication()
61 {
62 return $GLOBALS['BE_USER'];
63 }
64 }