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