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