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