e9a5bc6653ffe541534c3d955d4fda98429b2b01
[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\Utility\ExtensionManagementUtility;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
22
23 /**
24 * Implements the preview controller of the workspace module.
25 */
26 class PreviewController extends AbstractController
27 {
28 /**
29 * @var \TYPO3\CMS\Workspaces\Service\StagesService
30 */
31 protected $stageService;
32
33 /**
34 * @var \TYPO3\CMS\Workspaces\Service\WorkspaceService
35 */
36 protected $workspaceService;
37
38 /**
39 * Set up the doc header properly here
40 *
41 * @param ViewInterface $view
42 */
43 protected function initializeView(ViewInterface $view)
44 {
45 if ($view instanceof BackendTemplateView) {
46 /** @var BackendTemplateView $view */
47 parent::initializeView($view);
48 $view->getModuleTemplate()->getDocHeaderComponent()->disable();
49 $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
50 }
51 }
52
53 /**
54 * Initializes the controller before invoking an action method.
55 *
56 * @return void
57 */
58 protected function initializeAction()
59 {
60 parent::initializeAction();
61 $backendRelPath = ExtensionManagementUtility::extRelPath('backend');
62 $workspacesRelPath = ExtensionManagementUtility::extRelPath('workspaces');
63 $this->stageService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\StagesService::class);
64 $this->workspaceService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
65 $this->pageRenderer->addJsFile($backendRelPath . 'Resources/Public/JavaScript/ExtDirect.StateProvider.js');
66 $resourcePath = $workspacesRelPath . 'Resources/Public/Css/preview.css';
67 $GLOBALS['TBE_STYLES']['extJS']['theme'] = $resourcePath;
68 $this->pageRenderer->loadExtJS();
69 // Load JavaScript:
70 $this->pageRenderer->addExtDirectCode(array(
71 'TYPO3.Workspaces',
72 'TYPO3.ExtDirectStateProvider'
73 ));
74 $states = $GLOBALS['BE_USER']->uc['moduleData']['Workspaces']['States'];
75 $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
76 $this->pageRenderer->addJsFile($backendRelPath . 'Resources/Public/JavaScript/notifications.js');
77 $this->pageRenderer->addJsFile($backendRelPath . 'Resources/Public/JavaScript/iframepanel.js');
78 $resourcePathJavaScript = $workspacesRelPath . 'Resources/Public/JavaScript/';
79 $jsFiles = array(
80 'Ext.ux.plugins.TabStripContainer.js',
81 'Store/mainstore.js',
82 'helpers.js',
83 'actions.js'
84 );
85 foreach ($jsFiles as $jsFile) {
86 $this->pageRenderer->addJsFile($resourcePathJavaScript . $jsFile);
87 }
88 $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', BackendUtility::getModuleUrl('record_edit'));
89 $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', BackendUtility::getModuleUrl('record_history'));
90 // @todo this part should be done with inlineLocallanglabels
91 $this->pageRenderer->addJsInlineCode('workspace-inline-code', $this->generateJavascript());
92 }
93
94 /**
95 * Basically makes sure that the workspace preview is rendered.
96 * The preview itself consists of three frames, so there are
97 * only the frames-urls we've to generate here
98 *
99 * @param int $previewWS
100 * @return void
101 */
102 public function indexAction($previewWS = null)
103 {
104 // Get all the GET parameters to pass them on to the frames
105 $queryParameters = GeneralUtility::_GET();
106 // Remove the GET parameters related to the workspaces module and the page id
107 unset($queryParameters['tx_workspaces_web_workspacesworkspaces']);
108 unset($queryParameters['M']);
109 unset($queryParameters['id']);
110 // Assemble a query string from the retrieved parameters
111 $queryString = GeneralUtility::implodeArrayForUrl('', $queryParameters);
112
113 // fetch the next and previous stage
114 $workspaceItemsArray = $this->workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), ($filter = 1), ($stage = -99), $this->pageId, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
115 list(, $nextStage) = $this->stageService->getNextStageForElementCollection($workspaceItemsArray);
116 list(, $previousStage) = $this->stageService->getPreviousStageForElementCollection($workspaceItemsArray);
117 /** @var $wsService \TYPO3\CMS\Workspaces\Service\WorkspaceService */
118 $wsService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
119 $wsList = $wsService->getAvailableWorkspaces();
120 $activeWorkspace = $GLOBALS['BE_USER']->workspace;
121 if (!is_null($previewWS)) {
122 if (in_array($previewWS, array_keys($wsList)) && $activeWorkspace != $previewWS) {
123 $activeWorkspace = $previewWS;
124 $GLOBALS['BE_USER']->setWorkspace($activeWorkspace);
125 BackendUtility::setUpdateSignal('updatePageTree');
126 }
127 }
128 /** @var $uriBuilder \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder */
129 $uriBuilder = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::class);
130 $wsSettingsPath = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
131 $wsSettingsUri = $uriBuilder->uriFor('singleIndex', array(), \TYPO3\CMS\Workspaces\Controller\ReviewController::class, 'workspaces', 'web_workspacesworkspaces');
132 $wsSettingsParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Review';
133 $wsSettingsUrl = $wsSettingsPath . $wsSettingsUri . $wsSettingsParams;
134 $viewDomain = BackendUtility::getViewDomain($this->pageId);
135 $wsBaseUrl = $viewDomain . '/index.php?id=' . $this->pageId . $queryString;
136 // @todo - handle new pages here
137 // branchpoints are not handled anymore because this feature is not supposed anymore
138 if (\TYPO3\CMS\Workspaces\Service\WorkspaceService::isNewPage($this->pageId)) {
139 $wsNewPageUri = $uriBuilder->uriFor('newPage', array(), \TYPO3\CMS\Workspaces\Controller\PreviewController::class, 'workspaces', 'web_workspacesworkspaces');
140 $wsNewPageParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Preview';
141 $this->view->assign('liveUrl', $wsSettingsPath . $wsNewPageUri . $wsNewPageParams);
142 } else {
143 $this->view->assign('liveUrl', $wsBaseUrl . '&ADMCMD_noBeUser=1');
144 }
145 $this->view->assign('wsUrl', $wsBaseUrl . '&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS=' . $GLOBALS['BE_USER']->workspace);
146 $this->view->assign('wsSettingsUrl', $wsSettingsUrl);
147 $this->view->assign('backendDomain', GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
148 $splitPreviewTsConfig = BackendUtility::getModTSconfig($this->pageId, 'workspaces.splitPreviewModes');
149 $splitPreviewModes = GeneralUtility::trimExplode(',', $splitPreviewTsConfig['value']);
150 $allPreviewModes = array('slider', 'vbox', 'hbox');
151 if (!array_intersect($splitPreviewModes, $allPreviewModes)) {
152 $splitPreviewModes = $allPreviewModes;
153 }
154 $this->pageRenderer->addInlineSetting('Workspaces', 'SplitPreviewModes', $splitPreviewModes);
155 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaces.backend_domain', GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
156 $this->pageRenderer->addInlineSetting('Workspaces', 'disableNextStageButton', $this->isInvalidStage($nextStage));
157 $this->pageRenderer->addInlineSetting('Workspaces', 'disablePreviousStageButton', $this->isInvalidStage($previousStage));
158 $this->pageRenderer->addInlineSetting('Workspaces', 'disableDiscardStageButton', $this->isInvalidStage($nextStage) && $this->isInvalidStage($previousStage));
159 $resourcePath = ExtensionManagementUtility::extRelPath('lang') . 'Resources/Public/JavaScript/';
160 $this->pageRenderer->addJsFile($resourcePath . 'Typo3Lang.js');
161 $this->pageRenderer->addJsInlineCode('workspaces.preview.lll', '
162 TYPO3.lang = {
163 visualPreview: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.visualPreview', true)) . ',
164 listView: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.listView', true)) . ',
165 livePreview: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.livePreview', true)) . ',
166 livePreviewDetail: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.livePreviewDetail', true)) . ',
167 workspacePreview: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.workspacePreview', true)) . ',
168 workspacePreviewDetail: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.workspacePreviewDetail', true)) . ',
169 modeSlider: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.modeSlider', true)) . ',
170 modeVbox: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.modeVbox', true)) . ',
171 modeHbox: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.modeHbox', true)) . ',
172 discard: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:label_doaction_discard', true)) . ',
173 nextStage: ' . GeneralUtility::quoteJSvalue($nextStage['title']) . ',
174 previousStage: ' . GeneralUtility::quoteJSvalue($previousStage['title']) . '
175 };TYPO3.l10n.initialize();
176 ');
177 $resourcePath = ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/';
178 $this->pageRenderer->addJsFile($resourcePath . 'JavaScript/preview.js');
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 $flashMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:info.newpage.detail'), $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:info.newpage'), \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
198 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
199 $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
200 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
201 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
202 $defaultFlashMessageQueue->enqueue($flashMessage);
203 }
204
205 /**
206 * Generates the JavaScript code for the backend,
207 * and since we're loading a backend module outside of the actual backend
208 * this copies parts of the index.php?M=main module
209 *
210 * @return string
211 */
212 protected function generateJavascript()
213 {
214 $pathTYPO3 = GeneralUtility::dirname(GeneralUtility::getIndpEnv('SCRIPT_NAME')) . '/';
215 // If another page module was specified, replace the default Page module with the new one
216 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
217 $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
218 if (!$GLOBALS['BE_USER']->check('modules', $pageModule)) {
219 $pageModule = '';
220 }
221 $t3Configuration = array(
222 'siteUrl' => GeneralUtility::getIndpEnv('TYPO3_SITE_URL'),
223 'PATH_typo3' => $pathTYPO3,
224 'PATH_typo3_enc' => rawurlencode($pathTYPO3),
225 'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
226 'uniqueID' => GeneralUtility::shortMD5(uniqid('', true)),
227 'securityLevel' => trim($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) ?: 'normal',
228 'TYPO3_mainDir' => TYPO3_mainDir,
229 'pageModule' => $pageModule,
230 'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0,
231 'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
232 'veriCode' => $GLOBALS['BE_USER']->veriCode(),
233 'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
234 'moduleMenuWidth' => $this->menuWidth - 1,
235 'topBarHeight' => isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? (int)$GLOBALS['TBE_STYLES']['dims']['topFrameH'] : 30,
236 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] : false,
237 'debugInWindow' => $GLOBALS['BE_USER']->uc['debugInWindow'] ? 1 : 0,
238 'ContextHelpWindows' => array(
239 'width' => 600,
240 'height' => 400
241 )
242 );
243 $t3LLLcore = array(
244 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_logging_in'),
245 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_failed'),
246 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_failed_message'),
247 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
248 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.login_expired'),
249 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_username'),
250 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_password'),
251 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_emptyPassword'),
252 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_button'),
253 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_logout_button'),
254 'refresh_exit_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_exit_button'),
255 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.please_wait'),
256 'loadingIndicator' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:loadingIndicator'),
257 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.be_locked'),
258 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_countdown_singular'),
259 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_countdown'),
260 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.login_about_to_expire'),
261 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.login_about_to_expire_title'),
262 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_refresh_button'),
263 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_direct_logout_button'),
264 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tabs.closeAll'),
265 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tabs.closeOther'),
266 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tabs.close'),
267 'tabs_openInBrowserWindow' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tabs.openInBrowserWindow'),
268 'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.title'),
269 'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.message'),
270 'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.button_donate'),
271 'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.button_disable'),
272 'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.button_postpone')
273 );
274 return '
275 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
276 TYPO3.LLL = {
277 core : ' . json_encode($t3LLLcore) . '
278 };
279
280 /**
281 * TypoSetup object.
282 */
283 function typoSetup() { //
284 this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
285 this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
286 this.username = TYPO3.configuration.username;
287 this.uniqueID = TYPO3.configuration.uniqueID;
288 this.securityLevel = TYPO3.configuration.securityLevel;
289 this.veriCode = TYPO3.configuration.veriCode;
290 this.denyFileTypes = TYPO3.configuration.denyFileTypes;
291 }
292 var TS = new typoSetup();
293 //backwards compatibility
294 ';
295 }
296 }