[TASK] Namespacing: Use-statement for common classes like GeneralUtility
[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 use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33 /**
34 * Implements the preview controller of the workspace module.
35 *
36 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
37 */
38 class PreviewController extends \TYPO3\CMS\Workspaces\Controller\AbstractController {
39
40 /**
41 * @var \TYPO3\CMS\Workspaces\Service\StagesService
42 */
43 protected $stageService;
44
45 /**
46 * @var \TYPO3\CMS\Workspaces\Service\WorkspaceService
47 */
48 protected $workspaceService;
49
50 /**
51 * Initializes the controller before invoking an action method.
52 *
53 * @return void
54 */
55 protected function initializeAction() {
56 parent::initializeAction();
57 $this->stageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService');
58 $this->workspaceService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
59 $this->template->setExtDirectStateProvider();
60 $resourcePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/StyleSheet/preview.css';
61 $GLOBALS['TBE_STYLES']['extJS']['theme'] = $resourcePath;
62 $this->pageRenderer->loadExtJS();
63 $this->pageRenderer->enableExtJSQuickTips();
64 // Load JavaScript:
65 $this->pageRenderer->addExtDirectCode(array(
66 'TYPO3.Workspaces',
67 'TYPO3.ExtDirectStateProvider'
68 ));
69 $states = $GLOBALS['BE_USER']->uc['moduleData']['Workspaces']['States'];
70 $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
71 $this->pageRenderer->addJsFile($this->backPath . 'sysext/backend/Resources/Public/JavaScript/notifications.js');
72 $this->pageRenderer->addJsFile($this->backPath . 'sysext/backend/Resources/Public/JavaScript/flashmessages.js');
73 $this->pageRenderer->addJsFile($this->backPath . 'sysext/backend/Resources/Public/JavaScript/iframepanel.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(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 = 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 = 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', GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
135 $splitPreviewTsConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig($this->pageId, 'workspaces.splitPreviewModes');
136 $splitPreviewModes = 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', 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') . 'Resources/Public/JavaScript/';
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 $flashMessage = 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 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
185 $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
186 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
187 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
188 $defaultFlashMessageQueue->enqueue($flashMessage);
189 }
190
191 /**
192 * Generates the JavaScript code for the backend,
193 * and since we're loading a backend module outside of the actual backend
194 * this copies parts of the backend.php
195 *
196 * @return string
197 */
198 protected function generateJavascript() {
199 $pathTYPO3 = GeneralUtility::dirname(GeneralUtility::getIndpEnv('SCRIPT_NAME')) . '/';
200 // If another page module was specified, replace the default Page module with the new one
201 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
202 $pageModule = \TYPO3\CMS\Backend\Utility\BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
203 if (!$GLOBALS['BE_USER']->check('modules', $pageModule)) {
204 $pageModule = '';
205 }
206 $menuFrameName = 'menu';
207 if ($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
208 $menuFrameName = 'topmenuFrame';
209 }
210 // determine security level from conf vars and default to super challenged
211 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
212 $loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
213 } else {
214 $loginSecurityLevel = 'superchallenged';
215 }
216 $t3Configuration = array(
217 'siteUrl' => GeneralUtility::getIndpEnv('TYPO3_SITE_URL'),
218 'PATH_typo3' => $pathTYPO3,
219 'PATH_typo3_enc' => rawurlencode($pathTYPO3),
220 'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
221 'uniqueID' => GeneralUtility::shortMD5(uniqid('')),
222 'securityLevel' => $this->loginSecurityLevel,
223 'TYPO3_mainDir' => TYPO3_mainDir,
224 'pageModule' => $pageModule,
225 'condensedMode' => $GLOBALS['BE_USER']->uc['condensedMode'] ? 1 : 0,
226 'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 0,
227 'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
228 'veriCode' => $GLOBALS['BE_USER']->veriCode(),
229 'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
230 'moduleMenuWidth' => $this->menuWidth - 1,
231 'topBarHeight' => isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? intval($GLOBALS['TBE_STYLES']['dims']['topFrameH']) : 30,
232 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? intval($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) : FALSE,
233 'listModulePath' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('recordlist') ? \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('recordlist') . 'mod1/' : '',
234 'debugInWindow' => $GLOBALS['BE_USER']->uc['debugInWindow'] ? 1 : 0,
235 'ContextHelpWindows' => array(
236 'width' => 600,
237 'height' => 400
238 )
239 );
240 $t3LLLcore = array(
241 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in'),
242 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'),
243 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'),
244 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
245 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'),
246 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'),
247 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'),
248 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'),
249 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'),
250 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'),
251 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'),
252 'loadingIndicator' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:loadingIndicator'),
253 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'),
254 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'),
255 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'),
256 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'),
257 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'),
258 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'),
259 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'),
260 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeAll'),
261 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeOther'),
262 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.close'),
263 'tabs_openInBrowserWindow' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.openInBrowserWindow'),
264 'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.title'),
265 'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.message'),
266 'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_donate'),
267 'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_disable'),
268 'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_postpone')
269 );
270 $js = '
271 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
272 TYPO3.LLL = {
273 core : ' . json_encode($t3LLLcore) . '
274 };
275
276 /**
277 * TypoSetup object.
278 */
279 function typoSetup() { //
280 this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
281 this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
282 this.username = TYPO3.configuration.username;
283 this.uniqueID = TYPO3.configuration.uniqueID;
284 this.navFrameWidth = 0;
285 this.securityLevel = TYPO3.configuration.securityLevel;
286 this.veriCode = TYPO3.configuration.veriCode;
287 this.denyFileTypes = TYPO3.configuration.denyFileTypes;
288 }
289 var TS = new typoSetup();
290 //backwards compatibility
291 ';
292 return $js;
293 }
294
295 }
296
297
298 ?>