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