[TASK] Remove hardcoded ContextHelpWindows settings
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Controller / PreviewController.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\Controller;
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 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Backend\View\BackendTemplateView;
19 use TYPO3\CMS\Core\Messaging\FlashMessage;
20 use TYPO3\CMS\Core\Messaging\FlashMessageService;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Core\Utility\PathUtility;
23 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
24 use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
25 use TYPO3\CMS\Workspaces\Service\StagesService;
26 use TYPO3\CMS\Workspaces\Service\WorkspaceService;
27
28 /**
29 * Implements the preview controller of the workspace module.
30 */
31 class PreviewController extends AbstractController
32 {
33 /**
34 * @var StagesService
35 */
36 protected $stageService;
37
38 /**
39 * @var WorkspaceService
40 */
41 protected $workspaceService;
42
43 /**
44 * Set up the doc header properly here
45 *
46 * @param ViewInterface $view
47 */
48 protected function initializeView(ViewInterface $view)
49 {
50 if ($view instanceof BackendTemplateView) {
51 /** @var BackendTemplateView $view */
52 parent::initializeView($view);
53 $view->getModuleTemplate()->getDocHeaderComponent()->disable();
54 $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
55 }
56 }
57
58 /**
59 * Initializes the controller before invoking an action method.
60 *
61 * @return void
62 */
63 protected function initializeAction()
64 {
65 parent::initializeAction();
66 $this->stageService = GeneralUtility::makeInstance(StagesService::class);
67 $this->workspaceService = GeneralUtility::makeInstance(WorkspaceService::class);
68 $states = $this->getBackendUser()->uc['moduleData']['Workspaces']['States'];
69 $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
70 $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', BackendUtility::getModuleUrl('record_edit'));
71 $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', BackendUtility::getModuleUrl('record_history'));
72 // @todo this part should be done with inlineLocallanglabels
73 $this->pageRenderer->addJsInlineCode('workspace-inline-code', $this->generateJavascript());
74 }
75
76 /**
77 * Basically makes sure that the workspace preview is rendered.
78 * The preview itself consists of three frames, so there are
79 * only the frames-urls we've to generate here
80 *
81 * @param int $previewWS
82 * @return void
83 */
84 public function indexAction($previewWS = null)
85 {
86 $backendUser = $this->getBackendUser();
87
88 // Get all the GET parameters to pass them on to the frames
89 $queryParameters = GeneralUtility::_GET();
90
91 // Remove the GET parameters related to the workspaces module and the page id
92 unset($queryParameters['tx_workspaces_web_workspacesworkspaces']);
93 unset($queryParameters['M']);
94 unset($queryParameters['id']);
95
96 // Assemble a query string from the retrieved parameters
97 $queryString = GeneralUtility::implodeArrayForUrl('', $queryParameters);
98
99 // fetch the next and previous stage
100 $workspaceItemsArray = $this->workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), ($filter = 1), ($stage = -99), $this->pageId, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
101 list(, $nextStage) = $this->stageService->getNextStageForElementCollection($workspaceItemsArray);
102 list(, $previousStage) = $this->stageService->getPreviousStageForElementCollection($workspaceItemsArray);
103 /** @var $wsService WorkspaceService */
104 $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
105 $wsList = $wsService->getAvailableWorkspaces();
106 $activeWorkspace = $backendUser->workspace;
107 if (!is_null($previewWS)) {
108 if (in_array($previewWS, array_keys($wsList)) && $activeWorkspace != $previewWS) {
109 $activeWorkspace = $previewWS;
110 $backendUser->setWorkspace($activeWorkspace);
111 BackendUtility::setUpdateSignal('updatePageTree');
112 }
113 }
114 /** @var $uriBuilder UriBuilder */
115 $uriBuilder = $this->objectManager->get(UriBuilder::class);
116 $wsSettingsPath = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
117 $wsSettingsUri = $uriBuilder->uriFor('singleIndex', [], ReviewController::class, 'workspaces', 'web_workspacesworkspaces');
118 $wsSettingsParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Review';
119 $wsSettingsUrl = $wsSettingsPath . $wsSettingsUri . $wsSettingsParams;
120 $viewDomain = BackendUtility::getViewDomain($this->pageId);
121 $wsBaseUrl = $viewDomain . '/index.php?id=' . $this->pageId . $queryString;
122 // @todo - handle new pages here
123 // branchpoints are not handled anymore because this feature is not supposed anymore
124 if (WorkspaceService::isNewPage($this->pageId)) {
125 $wsNewPageUri = $uriBuilder->uriFor('newPage', [], self::class, 'workspaces', 'web_workspacesworkspaces');
126 $wsNewPageParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Preview';
127 $liveUrl = $wsSettingsPath . $wsNewPageUri . $wsNewPageParams . '&ADMCMD_prev=IGNORE';
128 } else {
129 $liveUrl = $wsBaseUrl . '&ADMCMD_noBeUser=1&ADMCMD_prev=IGNORE';
130 }
131 $wsUrl = $wsBaseUrl . '&ADMCMD_prev=IGNORE&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS=' . $backendUser->workspace;
132 $backendDomain = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
133 $splitPreviewTsConfig = BackendUtility::getModTSconfig($this->pageId, 'workspaces.splitPreviewModes');
134 $splitPreviewModes = GeneralUtility::trimExplode(',', $splitPreviewTsConfig['value']);
135 $allPreviewModes = ['slider', 'vbox', 'hbox'];
136 if (!array_intersect($splitPreviewModes, $allPreviewModes)) {
137 $splitPreviewModes = $allPreviewModes;
138 }
139
140 $wsList = $wsService->getAvailableWorkspaces();
141 $activeWorkspace = $backendUser->workspace;
142
143 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Workspaces/Preview');
144 $this->pageRenderer->addInlineSetting('Workspaces', 'SplitPreviewModes', $splitPreviewModes);
145
146 $cssFile = 'EXT:workspaces/Resources/Public/Css/preview.css';
147 $cssFile = GeneralUtility::getFileAbsFileName($cssFile);
148 $this->pageRenderer->addCssFile(PathUtility::getAbsoluteWebPath($cssFile));
149
150 $backendUser->setAndSaveSessionData('workspaces.backend_domain', GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
151
152 $logoPath = GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Public/Images/typo3_logo_orange.svg');
153 $logoWidth = 22;
154 $logoHeight = 22;
155
156 $this->view->assignMultiple([
157 'logoUrl' => PathUtility::getAbsoluteWebPath($logoPath),
158 'logoLink' => TYPO3_URL_GENERAL,
159 'logoWidth' => $logoWidth,
160 'logoHeight' => $logoHeight,
161 'liveUrl' => $liveUrl,
162 'wsUrl' => $wsUrl,
163 'wsSettingsUrl' => $wsSettingsUrl,
164 'backendDomain' => $backendDomain,
165 'activeWorkspace' => $wsList[$activeWorkspace],
166 'splitPreviewModes' => $splitPreviewModes,
167 'firstPreviewMode' => current($splitPreviewModes),
168 'enablePreviousStageButton' => !$this->isInvalidStage($previousStage),
169 'enableNextStageButton' => !$this->isInvalidStage($nextStage),
170 'enableDiscardStageButton' => !$this->isInvalidStage($nextStage) || !$this->isInvalidStage($previousStage),
171 'nextStage' => $nextStage['title'],
172 'nextStageId' => $nextStage['uid'],
173 'prevStage' => $previousStage['title'],
174 'prevStageId' => $previousStage['uid'],
175 ]);
176 foreach ($this->getAdditionalResourceService()->getLocalizationResources() as $localizationResource) {
177 $this->pageRenderer->addInlineLanguageLabelFile($localizationResource);
178 }
179 }
180
181 /**
182 * Evaluate the activate state based on given $stageArray.
183 *
184 * @param array $stageArray
185 * @return bool
186 */
187 protected function isInvalidStage($stageArray)
188 {
189 return !(is_array($stageArray) && !empty($stageArray));
190 }
191
192 /**
193 * @return void
194 */
195 public function newPageAction()
196 {
197 /** @var FlashMessage $flashMessage */
198 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:info.newpage.detail'), $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:info.newpage'), FlashMessage::INFO);
199 /** @var $flashMessageService FlashMessageService */
200 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
201 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
202 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
203 $defaultFlashMessageQueue->enqueue($flashMessage);
204 }
205
206 /**
207 * Generates the JavaScript code for the backend,
208 * and since we're loading a backend module outside of the actual backend
209 * this copies parts of the index.php?M=main module
210 *
211 * @return string
212 */
213 protected function generateJavascript()
214 {
215 $backendUser = $this->getBackendUser();
216 // If another page module was specified, replace the default Page module with the new one
217 $newPageModule = trim($backendUser->getTSConfigVal('options.overridePageModule'));
218 $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
219 if (!$backendUser->check('modules', $pageModule)) {
220 $pageModule = '';
221 }
222 $t3Configuration = [
223 'siteUrl' => GeneralUtility::getIndpEnv('TYPO3_SITE_URL'),
224 'username' => htmlspecialchars($backendUser->user['username']),
225 'uniqueID' => GeneralUtility::shortMD5(uniqid('', true)),
226 'pageModule' => $pageModule,
227 'inWorkspace' => $backendUser->workspace !== 0,
228 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] : false
229 ];
230
231 return '
232 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
233
234 /**
235 * TypoSetup object.
236 */
237 function typoSetup() { //
238 this.username = TYPO3.configuration.username;
239 this.uniqueID = TYPO3.configuration.uniqueID;
240 }
241 var TS = new typoSetup();
242 //backwards compatibility
243 ';
244 }
245
246 /**
247 * @return \TYPO3\CMS\Lang\LanguageService
248 */
249 protected function getLanguageService()
250 {
251 return $GLOBALS['LANG'];
252 }
253
254 /**
255 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
256 */
257 protected function getBackendUser()
258 {
259 return $GLOBALS['BE_USER'];
260 }
261 }