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