[TASK] Merge submodule workspaces into core
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Controller / PreviewController.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\Controller;
3 use TYPO3\CMS\Core\Utility;
4
5 /***************************************************************
6 * Copyright notice
7 *
8 * (c) 2010-2013 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Implements the preview controller of the workspace module.
32 *
33 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
34 */
35 class PreviewController extends \TYPO3\CMS\Workspaces\Controller\AbstractController {
36
37 /**
38 * @var \TYPO3\CMS\Workspaces\Service\StagesService
39 */
40 protected $stageService;
41
42 /**
43 * @var \TYPO3\CMS\Workspaces\Service\WorkspaceService
44 */
45 protected $workspaceService;
46
47 /**
48 * Initializes the controller before invoking an action method.
49 *
50 * @return void
51 */
52 protected function initializeAction() {
53 parent::initializeAction();
54 $this->stageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService');
55 $this->workspaceService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
56 $this->template->setExtDirectStateProvider();
57 $resourcePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/StyleSheet/preview.css';
58 $GLOBALS['TBE_STYLES']['extJS']['theme'] = $resourcePath;
59 $this->pageRenderer->loadExtJS();
60 $this->pageRenderer->enableExtJSQuickTips();
61 // Load JavaScript:
62 $this->pageRenderer->addExtDirectCode(array(
63 'TYPO3.Workspaces',
64 'TYPO3.ExtDirectStateProvider'
65 ));
66 $states = $GLOBALS['BE_USER']->uc['moduleData']['Workspaces']['States'];
67 $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
68 $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/notifications.js');
69 $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/ux/flashmessages.js');
70 $this->pageRenderer->addJsFile($this->backPath . 'js/extjs/iframepanel.js');
71 $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/notifications.js');
72 $resourcePathJavaScript = \TYPO3\CMS\Core\Utility\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 // todo this part should be done with inlineLocallanglabels
83 $this->pageRenderer->addJsInlineCode('workspace-inline-code', $this->generateJavascript());
84 }
85
86 /**
87 * Basically makes sure that the workspace preview is rendered.
88 * The preview itself consists of three frames, so there are
89 * only the frames-urls we've to generate here
90 *
91 * @param integer $previewWS
92 * @return void
93 */
94 public function indexAction($previewWS = NULL) {
95 // @todo language doesn't always come throught the L parameter
96 // @todo Evaluate how the intval() call can be used with Extbase validators/filters
97 $language = intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('L'));
98 // fetch the next and previous stage
99 $workspaceItemsArray = $this->workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), ($filter = 1), ($stage = -99), $this->pageId, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
100 list(, $nextStage) = $this->stageService->getNextStageForElementCollection($workspaceItemsArray);
101 list(, $previousStage) = $this->stageService->getPreviousStageForElementCollection($workspaceItemsArray);
102 /** @var $wsService \TYPO3\CMS\Workspaces\Service\WorkspaceService */
103 $wsService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
104 $wsList = $wsService->getAvailableWorkspaces();
105 $activeWorkspace = $GLOBALS['BE_USER']->workspace;
106 if (!is_null($previewWS)) {
107 if (in_array($previewWS, array_keys($wsList)) && $activeWorkspace != $previewWS) {
108 $activeWorkspace = $previewWS;
109 $GLOBALS['BE_USER']->setWorkspace($activeWorkspace);
110 \TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('updatePageTree');
111 }
112 }
113 /** @var $uriBuilder \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder */
114 $uriBuilder = $this->objectManager->create('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder');
115 $wsSettingsPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'typo3/';
116 $wsSettingsUri = $uriBuilder->uriFor('singleIndex', array(), 'TYPO3\\CMS\\Workspaces\\Controller\\ReviewController', 'workspaces', 'web_workspacesworkspaces');
117 $wsSettingsParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Review';
118 $wsSettingsUrl = $wsSettingsPath . $wsSettingsUri . $wsSettingsParams;
119 $viewDomain = \TYPO3\CMS\Backend\Utility\BackendUtility::getViewDomain($this->pageId);
120 $wsBaseUrl = $viewDomain . '/index.php?id=' . $this->pageId . '&L=' . $language;
121 // @todo - handle new pages here
122 // branchpoints are not handled anymore because this feature is not supposed anymore
123 if (\TYPO3\CMS\Workspaces\Service\WorkspaceService::isNewPage($this->pageId)) {
124 $wsNewPageUri = $uriBuilder->uriFor('newPage', array(), 'TYPO3\\CMS\\Workspaces\\Controller\\PreviewController', 'workspaces', 'web_workspacesworkspaces');
125 $wsNewPageParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Preview';
126 $this->view->assign('liveUrl', $wsSettingsPath . $wsNewPageUri . $wsNewPageParams);
127 } else {
128 $this->view->assign('liveUrl', $wsBaseUrl . '&ADMCMD_noBeUser=1');
129 }
130 $this->view->assign('wsUrl', $wsBaseUrl . '&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS=' . $GLOBALS['BE_USER']->workspace);
131 $this->view->assign('wsSettingsUrl', $wsSettingsUrl);
132 $this->view->assign('backendDomain', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
133 $splitPreviewTsConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig($this->pageId, 'workspaces.splitPreviewModes');
134 $splitPreviewModes = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $splitPreviewTsConfig['value']);
135 $allPreviewModes = array('slider', 'vbox', 'hbox');
136 if (!array_intersect($splitPreviewModes, $allPreviewModes)) {
137 $splitPreviewModes = $allPreviewModes;
138 }
139 $this->pageRenderer->addInlineSetting('Workspaces', 'SplitPreviewModes', $splitPreviewModes);
140 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaces.backend_domain', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
141 $this->pageRenderer->addInlineSetting('Workspaces', 'disableNextStageButton', $this->isInvalidStage($nextStage));
142 $this->pageRenderer->addInlineSetting('Workspaces', 'disablePreviousStageButton', $this->isInvalidStage($previousStage));
143 $this->pageRenderer->addInlineSetting('Workspaces', 'disableDiscardStageButton', $this->isInvalidStage($nextStage) && $this->isInvalidStage($previousStage));
144 $resourcePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('lang') . 'res/js/be/';
145 $this->pageRenderer->addJsFile($resourcePath . 'typo3lang.js');
146 $this->pageRenderer->addJsInlineCode('workspaces.preview.lll', '
147 TYPO3.lang = {
148 visualPreview: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.visualPreview', TRUE)) . ',
149 listView: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.listView', TRUE)) . ',
150 livePreview: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.livePreview', TRUE)) . ',
151 livePreviewDetail: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.livePreviewDetail', TRUE)) . ',
152 workspacePreview: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.workspacePreview', TRUE)) . ',
153 workspacePreviewDetail: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.workspacePreviewDetail', TRUE)) . ',
154 modeSlider: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeSlider', TRUE)) . ',
155 modeVbox: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeVbox', TRUE)) . ',
156 modeHbox: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeHbox', TRUE)) . ',
157 discard: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:label_doaction_discard', TRUE)) . ',
158 nextStage: ' . Utility\GeneralUtility::quoteJSvalue($nextStage['title']) . ',
159 previousStage: ' . Utility\GeneralUtility::quoteJSvalue($previousStage['title']) . '
160 };TYPO3.l10n.initialize();
161 ');
162 $resourcePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/';
163 $this->pageRenderer->addJsFile($resourcePath . 'JavaScript/preview.js');
164 }
165
166 /**
167 * Evaluate the activate state based on given $stageArray.
168 *
169 * @param array $stageArray
170 * @return boolean
171 * @author Michael Klapper <development@morphodo.com>
172 */
173 protected function isInvalidStage($stageArray) {
174 return !(is_array($stageArray) && count($stageArray) > 0);
175 }
176
177 /**
178 * @return void
179 */
180 public function newPageAction() {
181 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:info.newpage.detail'), $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:info.newpage'), \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
182 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
183 $flashMessageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
184 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
185 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
186 $defaultFlashMessageQueue->enqueue($flashMessage);
187 }
188
189 /**
190 * Generates the JavaScript code for the backend,
191 * and since we're loading a backend module outside of the actual backend
192 * this copies parts of the backend.php
193 *
194 * @return string
195 */
196 protected function generateJavascript() {
197 $pathTYPO3 = \TYPO3\CMS\Core\Utility\GeneralUtility::dirname(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('SCRIPT_NAME')) . '/';
198 // If another page module was specified, replace the default Page module with the new one
199 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
200 $pageModule = \TYPO3\CMS\Backend\Utility\BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
201 if (!$GLOBALS['BE_USER']->check('modules', $pageModule)) {
202 $pageModule = '';
203 }
204 $menuFrameName = 'menu';
205 if ($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
206 $menuFrameName = 'topmenuFrame';
207 }
208 // determine security level from conf vars and default to super challenged
209 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
210 $loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
211 } else {
212 $loginSecurityLevel = 'superchallenged';
213 }
214 $t3Configuration = array(
215 'siteUrl' => \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL'),
216 'PATH_typo3' => $pathTYPO3,
217 'PATH_typo3_enc' => rawurlencode($pathTYPO3),
218 'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
219 'uniqueID' => \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5(uniqid('')),
220 'securityLevel' => $this->loginSecurityLevel,
221 'TYPO3_mainDir' => TYPO3_mainDir,
222 'pageModule' => $pageModule,
223 'condensedMode' => $GLOBALS['BE_USER']->uc['condensedMode'] ? 1 : 0,
224 'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 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']) ? intval($GLOBALS['TBE_STYLES']['dims']['topFrameH']) : 30,
230 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? intval($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) : FALSE,
231 'listModulePath' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('recordlist') ? \TYPO3\CMS\Core\Utility\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.xml:mess.refresh_login_logging_in'),
240 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'),
241 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'),
242 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
243 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'),
244 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'),
245 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'),
246 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'),
247 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'),
248 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'),
249 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'),
250 'loadingIndicator' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:loadingIndicator'),
251 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'),
252 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'),
253 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'),
254 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'),
255 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'),
256 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'),
257 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'),
258 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeAll'),
259 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeOther'),
260 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.close'),
261 'tabs_openInBrowserWindow' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.openInBrowserWindow'),
262 'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.title'),
263 'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.message'),
264 'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_donate'),
265 'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_disable'),
266 'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_postpone')
267 );
268 $js = '
269 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
270 TYPO3.LLL = {
271 core : ' . json_encode($t3LLLcore) . '
272 };
273
274 /**
275 * TypoSetup object.
276 */
277 function typoSetup() { //
278 this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
279 this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
280 this.username = TYPO3.configuration.username;
281 this.uniqueID = TYPO3.configuration.uniqueID;
282 this.navFrameWidth = 0;
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 return $js;
291 }
292
293 }
294
295
296 ?>