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