Fixed issue: #10916 workspace preview module raises error in conjunction with the...
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Controller / PreviewController.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 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->pageRenderer->loadExtJS();
46 $this->pageRenderer->enableExtJSQuickTips();
47 $this->pageRenderer->enableExtJsDebug();
48
49 // Load JavaScript:
50 $this->pageRenderer->addExtDirectCode();
51 $this->pageRenderer->addJsFile(
52 $this->backPath . 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Workspaces',
53 NULL,
54 FALSE
55 );
56
57 $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/ux/flashmessages.js');
58 $this->pageRenderer->addJsFile($this->backPath . 'js/extjs/iframepanel.js');
59
60 $resourcePath = t3lib_extMgm::extRelPath('workspaces') . 'Resources/Public/JavaScript/';
61 $this->pageRenderer->addJsFile($resourcePath . 'preview.js');
62
63 // todo this part should be done with inlineLocallanglabels
64 $this->pageRenderer->addJsInlineCode('workspace-inline-code', $this->generateJavascript());
65 }
66
67 /**
68 * Basically makes sure that the workspace preview is rendered.
69 * The preview itself consists of three frames, so there are
70 * only the frames-urls we've to generate here
71 *
72 * @return void
73 */
74 public function indexAction() {
75 // @todo Evaluate how the intval() call can be used with Extbase validators/filters
76 $language = intval(t3lib_div::_GP('L'));
77
78 $controller = t3lib_div::makeInstance('Tx_Workspaces_Controller_ReviewController', TRUE);
79 $uriBuilder = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Routing_UriBuilder');
80
81 $wsSettingsPath = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . 'typo3/';
82 $wsSettingsUri = $uriBuilder->uriFor('singleIndex', array(), $controller, 'workspaces', 'web_workspacesworkspaces');
83 $wsSettingsParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Review';
84 $wsSettingsUrl = $wsSettingsPath . $wsSettingsUri . $wsSettingsParams;
85
86 $wsHelpUri = $uriBuilder->uriFor('help', array(), $this, 'workspaces', 'web_workspacesworkspaces');
87 $wsHelpParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Preview';
88 $wsHelpUrl = $wsSettingsPath . $wsHelpUri . $wsHelpParams;
89
90 $viewDomain = t3lib_BEfunc::getViewDomain($this->pageId);
91 $wsBaseUrl = $viewDomain . '/index.php?id=' . $this->pageId . '&L=' . $language;
92
93 // @todo - handle new pages here
94 // branchpoints are not handled anymore because this feature is not supposed anymore
95 $this->view->assign('liveUrl', $wsBaseUrl . '&ADMCMD_noBeUser=1');
96 $this->view->assign('wsUrl', $wsBaseUrl . '&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS=' . $GLOBALS['BE_USER']->workspace);
97 $this->view->assign('wsSettingsUrl', $wsSettingsUrl);
98 $this->view->assign('wsHelpUrl', $wsHelpUrl);
99 }
100
101 /**
102 * @return void
103 */
104 public function helpAction() {
105 // @todo Implement this action
106 }
107
108 /**
109 * Generates the JavaScript code for the backend,
110 * and since we're loading a backend module outside of the actual backend
111 * this copies parts of the backend.php
112 *
113 * @return void
114 */
115 protected function generateJavascript() {
116 $pathTYPO3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')) . '/';
117
118 // If another page module was specified, replace the default Page module with the new one
119 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
120 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
121 if (!$GLOBALS['BE_USER']->check('modules', $pageModule)) {
122 $pageModule = '';
123 }
124
125 $menuFrameName = 'menu';
126 if ($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
127 $menuFrameName = 'topmenuFrame';
128 }
129
130 // determine security level from conf vars and default to super challenged
131 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
132 $loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
133 } else {
134 $loginSecurityLevel = 'superchallenged';
135 }
136
137 $t3Configuration = array(
138 'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
139 'PATH_typo3' => $pathTYPO3,
140 'PATH_typo3_enc' => rawurlencode($pathTYPO3),
141 'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
142 'uniqueID' => t3lib_div::shortMD5(uniqid('')),
143 'securityLevel' => $this->loginSecurityLevel,
144 'TYPO3_mainDir' => TYPO3_mainDir,
145 'pageModule' => $pageModule,
146 'condensedMode' => $GLOBALS['BE_USER']->uc['condensedMode'] ? 1 : 0 ,
147 'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 0,
148 'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
149 'veriCode' => $GLOBALS['BE_USER']->veriCode(),
150 'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
151 'moduleMenuWidth' => $this->menuWidth - 1,
152 'topBarHeight' => (isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? intval($GLOBALS['TBE_STYLES']['dims']['topFrameH']) : 30),
153 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? intval($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) : FALSE,
154 'listModulePath' => t3lib_extMgm::isLoaded('list') ? t3lib_extMgm::extRelPath('list') . 'mod1/' : '',
155 'debugInWindow' => $GLOBALS['BE_USER']->uc['debugInWindow'] ? 1 : 0,
156 'ContextHelpWindows' => array(
157 'width' => 600,
158 'height' => 400
159 )
160 );
161
162 $t3LLLcore = array(
163 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in') ,
164 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'),
165 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'),
166 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
167 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'),
168 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'),
169 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'),
170 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'),
171 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'),
172 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'),
173 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'),
174 'loadingIndicator' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:loadingIndicator'),
175 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'),
176 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'),
177 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'),
178 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'),
179 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'),
180 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'),
181 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'),
182 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeAll'),
183 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeOther'),
184 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.close'),
185 'tabs_openInBrowserWindow' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.openInBrowserWindow'),
186 'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.title'),
187 'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.message'),
188 'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_donate'),
189 'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_disable'),
190 'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_postpone'),
191 );
192
193 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
194 if ($GLOBALS['LANG']->charSet !== 'utf-8') {
195 $t3Configuration['username'] = $GLOBALS['LANG']->csConvObj->conv($t3Configuration['username'], $GLOBALS['LANG']->charSet, 'utf-8');
196 $GLOBALS['LANG']->csConvObj->convArray($t3LLLcore, $GLOBALS['LANG']->charSet, 'utf-8');
197 $GLOBALS['LANG']->csConvObj->convArray($t3LLLfileUpload, $GLOBALS['LANG']->charSet, 'utf-8');
198 }
199
200 $js .= '
201 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
202 TYPO3.LLL = {
203 core : ' . json_encode($t3LLLcore) . '
204 };
205
206 /**
207 * TypoSetup object.
208 */
209 function typoSetup() { //
210 this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
211 this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
212 this.username = TYPO3.configuration.username;
213 this.uniqueID = TYPO3.configuration.uniqueID;
214 this.navFrameWidth = 0;
215 this.securityLevel = TYPO3.configuration.securityLevel;
216 this.veriCode = TYPO3.configuration.veriCode;
217 this.denyFileTypes = TYPO3.configuration.denyFileTypes;
218 }
219 var TS = new typoSetup();
220 //backwards compatibility
221 ';
222 return $js;
223 }
224 }
225
226
227 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Controller/PreviewController.php']) {
228 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Controller/PreviewController.php']);
229 }
230 ?>