[TASK] Cleanup phpDoc to match CGL
[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 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
25 */
26 class PreviewController extends AbstractController {
27
28 /**
29 * @var \TYPO3\CMS\Workspaces\Service\StagesService
30 */
31 protected $stageService;
32
33 /**
34 * @var \TYPO3\CMS\Workspaces\Service\WorkspaceService
35 */
36 protected $workspaceService;
37
38 /**
39 * Initializes the controller before invoking an action method.
40 *
41 * @return void
42 */
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 = 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 = 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
77 /**
78 * Basically makes sure that the workspace preview is rendered.
79 * The preview itself consists of three frames, so there are
80 * only the frames-urls we've to generate here
81 *
82 * @param int $previewWS
83 * @return void
84 */
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);
99 /** @var $wsService \TYPO3\CMS\Workspaces\Service\WorkspaceService */
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 }
110 /** @var $uriBuilder \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder */
111 $uriBuilder = $this->objectManager->create('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);
124 } else {
125 $this->view->assign('liveUrl', $wsBaseUrl . '&ADMCMD_noBeUser=1');
126 }
127 $this->view->assign('wsUrl', $wsBaseUrl . '&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 = 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: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.visualPreview', TRUE)) . ',
146 listView: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.listView', TRUE)) . ',
147 livePreview: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.livePreview', TRUE)) . ',
148 livePreviewDetail: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.livePreviewDetail', TRUE)) . ',
149 workspacePreview: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.workspacePreview', TRUE)) . ',
150 workspacePreviewDetail: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.workspacePreviewDetail', TRUE)) . ',
151 modeSlider: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.modeSlider', TRUE)) . ',
152 modeVbox: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.modeVbox', TRUE)) . ',
153 modeHbox: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.modeHbox', TRUE)) . ',
154 discard: ' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:label_doaction_discard', TRUE)) . ',
155 nextStage: ' . GeneralUtility::quoteJSvalue($nextStage['title']) . ',
156 previousStage: ' . GeneralUtility::quoteJSvalue($previousStage['title']) . '
157 };TYPO3.l10n.initialize();
158 ');
159 $resourcePath = ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/';
160 $this->pageRenderer->addJsFile($resourcePath . 'JavaScript/preview.js');
161 }
162
163 /**
164 * Evaluate the activate state based on given $stageArray.
165 *
166 * @param array $stageArray
167 * @return bool
168 */
169 protected function isInvalidStage($stageArray) {
170 return !(is_array($stageArray) && count($stageArray) > 0);
171 }
172
173 /**
174 * @return void
175 */
176 public function newPageAction() {
177 $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);
178 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
179 $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
180 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
181 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
182 $defaultFlashMessageQueue->enqueue($flashMessage);
183 }
184
185 /**
186 * Generates the JavaScript code for the backend,
187 * and since we're loading a backend module outside of the actual backend
188 * this copies parts of the backend.php
189 *
190 * @return string
191 */
192 protected function generateJavascript() {
193 $pathTYPO3 = GeneralUtility::dirname(GeneralUtility::getIndpEnv('SCRIPT_NAME')) . '/';
194 // If another page module was specified, replace the default Page module with the new one
195 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
196 $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
197 if (!$GLOBALS['BE_USER']->check('modules', $pageModule)) {
198 $pageModule = '';
199 }
200 // Determine security level from conf vars and default to super challenged
201 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
202 $loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
203 } else {
204 $loginSecurityLevel = 'superchallenged';
205 }
206 $t3Configuration = array(
207 'siteUrl' => GeneralUtility::getIndpEnv('TYPO3_SITE_URL'),
208 'PATH_typo3' => $pathTYPO3,
209 'PATH_typo3_enc' => rawurlencode($pathTYPO3),
210 'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
211 'uniqueID' => GeneralUtility::shortMD5(uniqid('', TRUE)),
212 'securityLevel' => $loginSecurityLevel,
213 'TYPO3_mainDir' => TYPO3_mainDir,
214 'pageModule' => $pageModule,
215 'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 0,
216 'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
217 'veriCode' => $GLOBALS['BE_USER']->veriCode(),
218 'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
219 'moduleMenuWidth' => $this->menuWidth - 1,
220 'topBarHeight' => isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? (int)$GLOBALS['TBE_STYLES']['dims']['topFrameH'] : 30,
221 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] : FALSE,
222 'listModulePath' => ExtensionManagementUtility::extRelPath('recordlist') . 'mod1/',
223 'debugInWindow' => $GLOBALS['BE_USER']->uc['debugInWindow'] ? 1 : 0,
224 'ContextHelpWindows' => array(
225 'width' => 600,
226 'height' => 400
227 )
228 );
229 $t3LLLcore = array(
230 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_logging_in'),
231 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_failed'),
232 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_failed_message'),
233 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
234 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.login_expired'),
235 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_username'),
236 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_password'),
237 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_emptyPassword'),
238 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_button'),
239 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_logout_button'),
240 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.please_wait'),
241 'loadingIndicator' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:loadingIndicator'),
242 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.be_locked'),
243 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_countdown_singular'),
244 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_countdown'),
245 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.login_about_to_expire'),
246 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.login_about_to_expire_title'),
247 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_refresh_button'),
248 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_direct_logout_button'),
249 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tabs.closeAll'),
250 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tabs.closeOther'),
251 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tabs.close'),
252 'tabs_openInBrowserWindow' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tabs.openInBrowserWindow'),
253 'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.title'),
254 'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.message'),
255 'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.button_donate'),
256 'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.button_disable'),
257 'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.button_postpone')
258 );
259 return '
260 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
261 TYPO3.LLL = {
262 core : ' . json_encode($t3LLLcore) . '
263 };
264
265 /**
266 * TypoSetup object.
267 */
268 function typoSetup() { //
269 this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
270 this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
271 this.username = TYPO3.configuration.username;
272 this.uniqueID = TYPO3.configuration.uniqueID;
273 this.navFrameWidth = 0;
274 this.securityLevel = TYPO3.configuration.securityLevel;
275 this.veriCode = TYPO3.configuration.veriCode;
276 this.denyFileTypes = TYPO3.configuration.denyFileTypes;
277 }
278 var TS = new typoSetup();
279 //backwards compatibility
280 ';
281 }
282
283 }