getLanguageService()->sL( 'LLL:EXT:adminpanel/Resources/Private/Language/locallang_preview.xlf:module.label' ); } /** * @inheritdoc */ public function initializeModule(ServerRequestInterface $request): void { // Backend preview params (ADMCMD_) take precedence over configured admin panel values $simulateGroupByRequest = (int)($request->getQueryParams()['ADMCMD_simUser'] ?? 0); $simulateTimeByRequest = (int)($request->getQueryParams()['ADMCMD_simTime'] ?? 0); $this->config = [ 'showHiddenPages' => (bool)$this->getConfigOptionForModule('showHiddenPages'), 'simulateDate' => $simulateTimeByRequest ?: (int)$this->getConfigOptionForModule('simulateDate'), 'showHiddenRecords' => (bool)$this->getConfigOptionForModule('showHiddenRecords'), 'simulateUserGroup' => $simulateGroupByRequest ?: (int)$this->getConfigOptionForModule('simulateUserGroup'), 'showFluidDebug' => (bool)$this->getConfigOptionForModule('showFluidDebug'), ]; if ($this->config['showFluidDebug']) { // forcibly unset fluid caching as it does not care about the tsfe based caching settings unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template']['frontend']); $GLOBALS['TSFE']->set_no_cache('Cache is disabled if fluid debugging is enabled', true); } $this->initializeFrontendPreview( $this->config['showHiddenPages'], $this->config['showHiddenRecords'], $this->config['simulateDate'], $this->config['simulateUserGroup'] ); } /** * @inheritdoc */ public function getPageSettings(): string { $view = GeneralUtility::makeInstance(StandaloneView::class); $templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Settings/Preview.html'; $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath)); $view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']); $frontendGroupsRepository = GeneralUtility::makeInstance(FrontendGroupsRepository::class); $view->assignMultiple( [ 'show' => [ 'pageId' => (int)$this->getTypoScriptFrontendController()->id, 'hiddenPages' => $this->config['showHiddenPages'], 'hiddenRecords' => $this->config['showHiddenRecords'], 'fluidDebug' => $this->config['showFluidDebug'], ], 'simulateDate' => $this->config['simulateDate'], 'frontendUserGroups' => [ 'availableGroups' => $frontendGroupsRepository->getAvailableFrontendUserGroups(), 'selected' => (int)$this->config['simulateUserGroup'], ], ] ); return $view->render(); } /** * @param string $option * @return string */ protected function getConfigOptionForModule(string $option): string { return $this->configurationService->getConfigurationOption( 'preview', $option ); } /** * @return TypoScriptFrontendController */ protected function getTypoScriptFrontendController(): TypoScriptFrontendController { return $GLOBALS['TSFE']; } /** * Initialize frontend preview functionality incl. * simulation of users or time * * @param bool $showHiddenPages * @param bool $showHiddenRecords * @param int $simulateDate * @param int $simulateUserGroup UID of the fe_group to simulate * @throws \Exception */ protected function initializeFrontendPreview( bool $showHiddenPages, bool $showHiddenRecords, int $simulateDate, int $simulateUserGroup ): void { $context = GeneralUtility::makeInstance(Context::class); $typoScriptFrontendController = $this->getTypoScriptFrontendController(); $typoScriptFrontendController->clear_preview(); $typoScriptFrontendController->fePreview = 1; // Modify visibility settings (hidden pages + hidden content) $context->setAspect( 'visibility', GeneralUtility::makeInstance(VisibilityAspect::class, $showHiddenPages, $showHiddenRecords) ); // Simulate date $simTime = null; if ($simulateDate) { $simTime = $this->parseDate($simulateDate); if ($simTime) { $GLOBALS['SIM_EXEC_TIME'] = $simTime; $GLOBALS['SIM_ACCESS_TIME'] = $simTime - $simTime % 60; $context->setAspect( 'date', GeneralUtility::makeInstance( DateTimeAspect::class, new \DateTimeImmutable('@' . $GLOBALS['SIM_EXEC_TIME']) ) ); } } // simulate usergroup if ($simulateUserGroup) { $typoScriptFrontendController->simUserGroup = $simulateUserGroup; if (!$typoScriptFrontendController->fe_user instanceof FrontendUserAuthentication) { $typoScriptFrontendController->fe_user = GeneralUtility::makeInstance( FrontendUserAuthentication::class ); } if (!is_array($typoScriptFrontendController->fe_user->user)) { // This can be removed once #90989 is fixed $typoScriptFrontendController->fe_user->user = ['uid' => PHP_INT_MAX]; } $typoScriptFrontendController->fe_user->user[$typoScriptFrontendController->fe_user->usergroup_column] = $simulateUserGroup; $context->setAspect( 'frontend.user', GeneralUtility::makeInstance( UserAspect::class, $typoScriptFrontendController->fe_user ?: null, [$simulateUserGroup] ) ); } if (!$simulateUserGroup && !$simTime && !$showHiddenPages && !$showHiddenRecords) { $typoScriptFrontendController->fePreview = 0; } } /** * @return array */ public function getJavaScriptFiles(): array { return ['EXT:adminpanel/Resources/Public/JavaScript/Modules/Preview.js']; } /** * The simulated date needs to be a timestring (UTC) * * Simulation date is either set via configuration of AdminPanel (Date and Time Fields) or via ADMCMD_ $_GET * parameter from backend previews * * @param int $simulateDate * @return int */ protected function parseDate(int $simulateDate): ?int { try { $simTime = (new \DateTime('@' . $simulateDate))->getTimestamp(); $simTime = max($simTime, 60); } catch (\Exception $e) { $simTime = null; } return $simTime; } /** * Returns a string array with css files that will be rendered after the module * * @return array */ public function getCssFiles(): array { return []; } }