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