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