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