TYPO3 CMS  TYPO3_8-7
PreviewController.php
Go to the documentation of this file.
1 <?php
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 
27 
32 {
36  protected $stageService;
37 
41  protected $workspaceService;
42 
48  protected function initializeView(ViewInterface $view)
49  {
50  if ($view instanceof BackendTemplateView) {
52  parent::initializeView($view);
53  $view->getModuleTemplate()->getDocHeaderComponent()->disable();
54  $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
55  }
56  }
57 
61  protected function initializeAction()
62  {
63  parent::initializeAction();
64  $this->stageService = GeneralUtility::makeInstance(StagesService::class);
65  $this->workspaceService = GeneralUtility::makeInstance(WorkspaceService::class);
66  $states = $this->getBackendUser()->uc['moduleData']['Workspaces']['States'];
67  $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
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 
81  public function indexAction($previewWS = null)
82  {
83  $backendUser = $this->getBackendUser();
84 
85  // Get all the GET parameters to pass them on to the frames
86  $queryParameters = GeneralUtility::_GET();
87 
88  // Remove the GET parameters related to the workspaces module and the page id
89  unset($queryParameters['tx_workspaces_web_workspacesworkspaces']);
90  unset($queryParameters['M']);
91  unset($queryParameters['id']);
92 
93  // Assemble a query string from the retrieved parameters
94  $queryString = GeneralUtility::implodeArrayForUrl('', $queryParameters);
95 
96  // fetch the next and previous stage
97  $workspaceItemsArray = $this->workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), ($filter = 1), ($stage = -99), $this->pageId, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
98  list(, $nextStage) = $this->stageService->getNextStageForElementCollection($workspaceItemsArray);
99  list(, $previousStage) = $this->stageService->getPreviousStageForElementCollection($workspaceItemsArray);
101  $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
102  $wsList = $wsService->getAvailableWorkspaces();
103  $activeWorkspace = $backendUser->workspace;
104  if (!is_null($previewWS)) {
105  if (in_array($previewWS, array_keys($wsList)) && $activeWorkspace != $previewWS) {
106  $activeWorkspace = $previewWS;
107  $backendUser->setWorkspace($activeWorkspace);
108  BackendUtility::setUpdateSignal('updatePageTree');
109  }
110  }
112  $uriBuilder = $this->objectManager->get(UriBuilder::class);
113  $wsSettingsPath = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
114  $wsSettingsUri = $uriBuilder->uriFor('singleIndex', [], ReviewController::class, 'workspaces', 'web_workspacesworkspaces');
115  $wsSettingsParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Review';
116  $wsSettingsUrl = $wsSettingsPath . $wsSettingsUri . $wsSettingsParams;
117  $viewDomain = BackendUtility::getViewDomain($this->pageId);
118  $wsBaseUrl = $viewDomain . '/index.php?id=' . $this->pageId . $queryString;
119  // @todo - handle new pages here
120  // branchpoints are not handled anymore because this feature is not supposed anymore
121  if (WorkspaceService::isNewPage($this->pageId)) {
122  $wsNewPageUri = $uriBuilder->uriFor('newPage', [], self::class, 'workspaces', 'web_workspacesworkspaces');
123  $wsNewPageParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Preview';
124  $liveUrl = $wsSettingsPath . $wsNewPageUri . $wsNewPageParams . '&ADMCMD_prev=IGNORE';
125  } else {
126  $liveUrl = $wsBaseUrl . '&ADMCMD_noBeUser=1&ADMCMD_prev=IGNORE';
127  }
128  $wsUrl = $wsBaseUrl . '&ADMCMD_prev=IGNORE&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS=' . $backendUser->workspace;
129  $splitPreviewTsConfig = BackendUtility::getModTSconfig($this->pageId, 'workspaces.splitPreviewModes');
130  $splitPreviewModes = GeneralUtility::trimExplode(',', $splitPreviewTsConfig['value']);
131  $allPreviewModes = ['slider', 'vbox', 'hbox'];
132  if (!array_intersect($splitPreviewModes, $allPreviewModes)) {
133  $splitPreviewModes = $allPreviewModes;
134  }
135 
136  $wsList = $wsService->getAvailableWorkspaces();
137  $activeWorkspace = $backendUser->workspace;
138 
139  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Workspaces/Preview');
140  $this->pageRenderer->addInlineSetting('Workspaces', 'SplitPreviewModes', $splitPreviewModes);
141 
142  $cssFile = 'EXT:workspaces/Resources/Public/Css/preview.css';
143  $cssFile = GeneralUtility::getFileAbsFileName($cssFile);
144  $this->pageRenderer->addCssFile(PathUtility::getAbsoluteWebPath($cssFile));
145 
146  $logoPath = GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Public/Images/typo3_logo_orange.svg');
147  $logoWidth = 22;
148  $logoHeight = 22;
149 
150  $this->view->assignMultiple([
151  'logoUrl' => PathUtility::getAbsoluteWebPath($logoPath),
152  'logoLink' => TYPO3_URL_GENERAL,
153  'logoWidth' => $logoWidth,
154  'logoHeight' => $logoHeight,
155  'liveUrl' => $liveUrl,
156  'wsUrl' => $wsUrl,
157  'wsSettingsUrl' => $wsSettingsUrl,
158  'activeWorkspace' => $wsList[$activeWorkspace],
159  'splitPreviewModes' => $splitPreviewModes,
160  'firstPreviewMode' => current($splitPreviewModes),
161  'enablePreviousStageButton' => !$this->isInvalidStage($previousStage),
162  'enableNextStageButton' => !$this->isInvalidStage($nextStage),
163  'enableDiscardStageButton' => !$this->isInvalidStage($nextStage) || !$this->isInvalidStage($previousStage),
164  'nextStage' => $nextStage['title'],
165  'nextStageId' => $nextStage['uid'],
166  'prevStage' => $previousStage['title'],
167  'prevStageId' => $previousStage['uid'],
168  ]);
169  foreach ($this->getAdditionalResourceService()->getLocalizationResources() as $localizationResource) {
170  $this->pageRenderer->addInlineLanguageLabelFile($localizationResource);
171  }
172  }
173 
180  protected function isInvalidStage($stageArray)
181  {
182  return !(is_array($stageArray) && !empty($stageArray));
183  }
184 
187  public function newPageAction()
188  {
190  $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:info.newpage.detail'), $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:info.newpage'), FlashMessage::INFO);
192  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
194  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
195  $defaultFlashMessageQueue->enqueue($flashMessage);
196  }
197 
205  protected function generateJavascript()
206  {
207  $backendUser = $this->getBackendUser();
208  // If another page module was specified, replace the default Page module with the new one
209  $newPageModule = trim($backendUser->getTSConfigVal('options.overridePageModule'));
210  $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
211  if (!$backendUser->check('modules', $pageModule)) {
212  $pageModule = '';
213  }
214  $t3Configuration = [
215  'username' => htmlspecialchars($backendUser->user['username']),
216  'uniqueID' => GeneralUtility::shortMD5(uniqid('', true)),
217  'pageModule' => $pageModule,
218  'inWorkspace' => $backendUser->workspace !== 0,
219  'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] : false
220  ];
221 
222  return '
223  TYPO3.configuration = ' . json_encode($t3Configuration) . ';
224 
228  function typoSetup() { //
229  this.username = TYPO3.configuration.username;
230  this.uniqueID = TYPO3.configuration.uniqueID;
231  }
232  var TS = new typoSetup();
233  //backwards compatibility
234  ';
235  }
236 
240  protected function getLanguageService()
241  {
242  return $GLOBALS['LANG'];
243  }
244 
248  protected function getBackendUser()
249  {
250  return $GLOBALS['BE_USER'];
251  }
252 }
static getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:40
static getFileAbsFileName($filename, $_=null, $_2=null)
static getViewDomain($pageId, $rootLine=null)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)
static implodeArrayForUrl($name, array $theArray, $str='', $skipBlank=false, $rawurlencodeParamName=false)
static setUpdateSignal($set='', $params='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']