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