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