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