Merge "[FEATURE] Add possibility for improved detail view"
[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 * Initializes the controller before invoking an action method.
39 *
40 * @return void
41 */
42 protected function initializeAction() {
43 parent::initializeAction();
44
45 $this->template->setExtDirectStateProvider();
46
47 $resourcePath = t3lib_extMgm::extRelPath('workspaces') . 'Resources/Public/';
48 $GLOBALS['TBE_STYLES']['extJS']['theme'] = $resourcePath . 'StyleSheet/preview.css';
49 $this->pageRenderer->loadExtJS();
50 $this->pageRenderer->enableExtJSQuickTips();
51
52
53 // Load JavaScript:
54 $this->pageRenderer->addExtDirectCode(array(
55 'TYPO3.Workspaces',
56 'TYPO3.ExtDirectStateProvider'
57 ));
58
59 $states = $GLOBALS['BE_USER']->uc['moduleData']['Workspaces']['States'];
60 $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
61
62 $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/notifications.js');
63
64 $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/ux/flashmessages.js');
65 $this->pageRenderer->addJsFile($this->backPath . 'js/extjs/iframepanel.js');
66
67 $this->pageRenderer->addJsFile($resourcePath . 'JavaScript/Ext.ux.plugins.TabStripContainer.js');
68
69 // todo this part should be done with inlineLocallanglabels
70 $this->pageRenderer->addJsInlineCode('workspace-inline-code', $this->generateJavascript());
71 }
72
73 /**
74 * Basically makes sure that the workspace preview is rendered.
75 * The preview itself consists of three frames, so there are
76 * only the frames-urls we've to generate here
77 *
78 * @param integer $previewWS
79 *
80 * @return void
81 */
82 public function indexAction($previewWS = null) {
83 // @todo language doesn't always come throught the L parameter
84 // @todo Evaluate how the intval() call can be used with Extbase validators/filters
85 $language = intval(t3lib_div::_GP('L'));
86
87 /** @var $wsService tx_Workspaces_Service_Workspaces */
88 $wsService = t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
89 $wsList = $wsService->getAvailableWorkspaces();
90 $activeWorkspace = $GLOBALS['BE_USER']->workspace;
91
92 if (!is_null($previewWS)) {
93 if (in_array($previewWS, array_keys($wsList)) && $activeWorkspace != $previewWS) {
94 $activeWorkspace = $previewWS;
95 $GLOBALS['BE_USER']->setWorkspace($activeWorkspace);
96 t3lib_BEfunc::setUpdateSignal('updatePageTree');
97 }
98 }
99
100 $controller = t3lib_div::makeInstance('Tx_Workspaces_Controller_ReviewController', TRUE);
101 /** @var $uriBuilder Tx_Extbase_MVC_Web_Routing_UriBuilder */
102 $uriBuilder = $this->objectManager->create('Tx_Extbase_MVC_Web_Routing_UriBuilder');
103
104 $wsSettingsPath = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . 'typo3/';
105 $wsSettingsUri = $uriBuilder->uriFor('singleIndex', array(), 'Tx_Workspaces_Controller_ReviewController', 'workspaces', 'web_workspacesworkspaces');
106 $wsSettingsParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Review';
107 $wsSettingsUrl = $wsSettingsPath . $wsSettingsUri . $wsSettingsParams;
108
109 $viewDomain = t3lib_BEfunc::getViewDomain($this->pageId);
110 $wsBaseUrl = $viewDomain . '/index.php?id=' . $this->pageId . '&L=' . $language;
111
112 // @todo - handle new pages here
113 // branchpoints are not handled anymore because this feature is not supposed anymore
114 if (tx_Workspaces_Service_Workspaces::isNewPage($this->pageId)) {
115 $wsNewPageUri = $uriBuilder->uriFor('newPage', array(), 'Tx_Workspaces_Controller_PreviewController', 'workspaces', 'web_workspacesworkspaces');
116 $wsNewPageParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Preview';
117 $this->view->assign('liveUrl', $wsSettingsPath . $wsNewPageUri . $wsNewPageParams);
118 } else {
119 $this->view->assign('liveUrl', $wsBaseUrl . '&ADMCMD_noBeUser=1');
120 }
121 $this->view->assign('wsUrl', $wsBaseUrl . '&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS=' . $GLOBALS['BE_USER']->workspace);
122 $this->view->assign('wsSettingsUrl', $wsSettingsUrl);
123 $this->view->assign('backendDomain', t3lib_div::getIndpEnv('TYPO3_HOST_ONLY'));
124
125 $splitPreviewTsConfig = t3lib_BEfunc::getModTSconfig($this->pageId, 'workspaces.splitPreviewModes');
126 $splitPreviewModes = t3lib_div::trimExplode(',', $splitPreviewTsConfig['value']);
127 $allPreviewModes = array('slider', 'vbox', 'hbox');
128 if (!array_intersect($splitPreviewModes, $allPreviewModes)) {
129 $splitPreviewModes = $allPreviewModes;
130 }
131 $this->pageRenderer->addInlineSetting('Workspaces', 'SplitPreviewModes', $splitPreviewModes);
132
133 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaces.backend_domain', t3lib_div::getIndpEnv('TYPO3_HOST_ONLY'));
134 $this->pageRenderer->addJsInlineCode("workspaces.preview.lll" , "TYPO3.LLL.Workspaces = {
135 visualPreview: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.visualPreview', TRUE) . "',
136 listView: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.listView', TRUE) . "',
137 livePreview: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.livePreview', TRUE) . "',
138 livePreviewDetail: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.livePreviewDetail', TRUE) . "',
139 workspacePreview: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.workspacePreview', TRUE) . "',
140 workspacePreviewDetail: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.workspacePreviewDetail', TRUE) . "',
141 modeSlider: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeSlider', TRUE) . "',
142 modeVbox: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeVbox', TRUE) . "',
143 modeHbox: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeHbox', TRUE) . "'
144 };\n");
145
146 $resourcePath = t3lib_extMgm::extRelPath('workspaces') . 'Resources/Public/';
147 $this->pageRenderer->addJsFile($resourcePath . 'JavaScript/preview.js');
148 }
149
150 /**
151 * @return void
152 */
153 public function newPageAction() {
154 $message = t3lib_div::makeInstance(
155 't3lib_FlashMessage',
156 $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:info.newpage.detail'),
157 $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:info.newpage'),
158 t3lib_FlashMessage::INFO
159 );
160 t3lib_FlashMessageQueue::addMessage($message);
161 }
162
163 /**
164 * Generates the JavaScript code for the backend,
165 * and since we're loading a backend module outside of the actual backend
166 * this copies parts of the backend.php
167 *
168 * @return void
169 */
170 protected function generateJavascript() {
171 $pathTYPO3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')) . '/';
172
173 // If another page module was specified, replace the default Page module with the new one
174 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
175 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
176 if (!$GLOBALS['BE_USER']->check('modules', $pageModule)) {
177 $pageModule = '';
178 }
179
180 $menuFrameName = 'menu';
181 if ($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
182 $menuFrameName = 'topmenuFrame';
183 }
184
185 // determine security level from conf vars and default to super challenged
186 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
187 $loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
188 } else {
189 $loginSecurityLevel = 'superchallenged';
190 }
191
192 $t3Configuration = array(
193 'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
194 'PATH_typo3' => $pathTYPO3,
195 'PATH_typo3_enc' => rawurlencode($pathTYPO3),
196 'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
197 'uniqueID' => t3lib_div::shortMD5(uniqid('')),
198 'securityLevel' => $this->loginSecurityLevel,
199 'TYPO3_mainDir' => TYPO3_mainDir,
200 'pageModule' => $pageModule,
201 'condensedMode' => $GLOBALS['BE_USER']->uc['condensedMode'] ? 1 : 0 ,
202 'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 0,
203 'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
204 'veriCode' => $GLOBALS['BE_USER']->veriCode(),
205 'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
206 'moduleMenuWidth' => $this->menuWidth - 1,
207 'topBarHeight' => (isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? intval($GLOBALS['TBE_STYLES']['dims']['topFrameH']) : 30),
208 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? intval($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) : FALSE,
209 'listModulePath' => t3lib_extMgm::isLoaded('recordlist') ? t3lib_extMgm::extRelPath('recordlist') . 'mod1/' : '',
210 'debugInWindow' => $GLOBALS['BE_USER']->uc['debugInWindow'] ? 1 : 0,
211 'ContextHelpWindows' => array(
212 'width' => 600,
213 'height' => 400
214 ),
215 );
216
217 $t3LLLcore = array(
218 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in') ,
219 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'),
220 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'),
221 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
222 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'),
223 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'),
224 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'),
225 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'),
226 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'),
227 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'),
228 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'),
229 'loadingIndicator' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:loadingIndicator'),
230 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'),
231 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'),
232 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'),
233 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'),
234 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'),
235 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'),
236 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'),
237 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeAll'),
238 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeOther'),
239 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.close'),
240 'tabs_openInBrowserWindow' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.openInBrowserWindow'),
241 'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.title'),
242 'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.message'),
243 'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_donate'),
244 'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_disable'),
245 'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_postpone'),
246 );
247
248 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
249 if ($GLOBALS['LANG']->charSet !== 'utf-8') {
250 $t3Configuration['username'] = $GLOBALS['LANG']->csConvObj->conv($t3Configuration['username'], $GLOBALS['LANG']->charSet, 'utf-8');
251 $GLOBALS['LANG']->csConvObj->convArray($t3LLLcore, $GLOBALS['LANG']->charSet, 'utf-8');
252 }
253
254 $js = '
255 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
256 TYPO3.LLL = {
257 core : ' . json_encode($t3LLLcore) . '
258 };
259
260 /**
261 * TypoSetup object.
262 */
263 function typoSetup() { //
264 this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
265 this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
266 this.username = TYPO3.configuration.username;
267 this.uniqueID = TYPO3.configuration.uniqueID;
268 this.navFrameWidth = 0;
269 this.securityLevel = TYPO3.configuration.securityLevel;
270 this.veriCode = TYPO3.configuration.veriCode;
271 this.denyFileTypes = TYPO3.configuration.denyFileTypes;
272 }
273 var TS = new typoSetup();
274 //backwards compatibility
275 ';
276 return $js;
277 }
278 }
279
280
281 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Controller/PreviewController.php'])) {
282 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Controller/PreviewController.php']);
283 }
284 ?>