[TASK] Use (int) instead of intval() or (integer)
[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 // todo this part should be done with inlineLocallanglabels
86 $this->pageRenderer->addJsInlineCode('workspace-inline-code', $this->generateJavascript());
87 }
88
89 /**
90 * Basically makes sure that the workspace preview is rendered.
91 * The preview itself consists of three frames, so there are
92 * only the frames-urls we've to generate here
93 *
94 * @param integer $previewWS
95 * @return void
96 */
97 public function indexAction($previewWS = NULL) {
98 // Get all the GET parameters to pass them on to the frames
99 $queryParameters = GeneralUtility::_GET();
100 // Remove the GET parameters related to the workspaces module and the page id
101 unset($queryParameters['tx_workspaces_web_workspacesworkspaces']);
102 unset($queryParameters['M']);
103 unset($queryParameters['id']);
104 // Assemble a query string from the retrieved parameters
105 $queryString = GeneralUtility::implodeArrayForUrl('', $queryParameters);
106
107 // fetch the next and previous stage
108 $workspaceItemsArray = $this->workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), ($filter = 1), ($stage = -99), $this->pageId, ($recursionLevel = 0), ($selectionType = 'tables_modify'));
109 list(, $nextStage) = $this->stageService->getNextStageForElementCollection($workspaceItemsArray);
110 list(, $previousStage) = $this->stageService->getPreviousStageForElementCollection($workspaceItemsArray);
111 /** @var $wsService \TYPO3\CMS\Workspaces\Service\WorkspaceService */
112 $wsService = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
113 $wsList = $wsService->getAvailableWorkspaces();
114 $activeWorkspace = $GLOBALS['BE_USER']->workspace;
115 if (!is_null($previewWS)) {
116 if (in_array($previewWS, array_keys($wsList)) && $activeWorkspace != $previewWS) {
117 $activeWorkspace = $previewWS;
118 $GLOBALS['BE_USER']->setWorkspace($activeWorkspace);
119 BackendUtility::setUpdateSignal('updatePageTree');
120 }
121 }
122 /** @var $uriBuilder \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder */
123 $uriBuilder = $this->objectManager->create('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder');
124 $wsSettingsPath = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'typo3/';
125 $wsSettingsUri = $uriBuilder->uriFor('singleIndex', array(), 'TYPO3\\CMS\\Workspaces\\Controller\\ReviewController', 'workspaces', 'web_workspacesworkspaces');
126 $wsSettingsParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Review';
127 $wsSettingsUrl = $wsSettingsPath . $wsSettingsUri . $wsSettingsParams;
128 $viewDomain = BackendUtility::getViewDomain($this->pageId);
129 $wsBaseUrl = $viewDomain . '/index.php?id=' . $this->pageId . $queryString;
130 // @todo - handle new pages here
131 // branchpoints are not handled anymore because this feature is not supposed anymore
132 if (\TYPO3\CMS\Workspaces\Service\WorkspaceService::isNewPage($this->pageId)) {
133 $wsNewPageUri = $uriBuilder->uriFor('newPage', array(), 'TYPO3\\CMS\\Workspaces\\Controller\\PreviewController', 'workspaces', 'web_workspacesworkspaces');
134 $wsNewPageParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Preview';
135 $this->view->assign('liveUrl', $wsSettingsPath . $wsNewPageUri . $wsNewPageParams);
136 } else {
137 $this->view->assign('liveUrl', $wsBaseUrl . '&ADMCMD_noBeUser=1');
138 }
139 $this->view->assign('wsUrl', $wsBaseUrl . '&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS=' . $GLOBALS['BE_USER']->workspace);
140 $this->view->assign('wsSettingsUrl', $wsSettingsUrl);
141 $this->view->assign('backendDomain', GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
142 $splitPreviewTsConfig = BackendUtility::getModTSconfig($this->pageId, 'workspaces.splitPreviewModes');
143 $splitPreviewModes = GeneralUtility::trimExplode(',', $splitPreviewTsConfig['value']);
144 $allPreviewModes = array('slider', 'vbox', 'hbox');
145 if (!array_intersect($splitPreviewModes, $allPreviewModes)) {
146 $splitPreviewModes = $allPreviewModes;
147 }
148 $this->pageRenderer->addInlineSetting('Workspaces', 'SplitPreviewModes', $splitPreviewModes);
149 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaces.backend_domain', GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
150 $this->pageRenderer->addInlineSetting('Workspaces', 'disableNextStageButton', $this->isInvalidStage($nextStage));
151 $this->pageRenderer->addInlineSetting('Workspaces', 'disablePreviousStageButton', $this->isInvalidStage($previousStage));
152 $this->pageRenderer->addInlineSetting('Workspaces', 'disableDiscardStageButton', $this->isInvalidStage($nextStage) && $this->isInvalidStage($previousStage));
153 $resourcePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('lang') . 'Resources/Public/JavaScript/';
154 $this->pageRenderer->addJsFile($resourcePath . 'Typo3Lang.js');
155 $this->pageRenderer->addJsInlineCode('workspaces.preview.lll', '
156 TYPO3.lang = {
157 visualPreview: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.visualPreview', TRUE)) . ',
158 listView: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.listView', TRUE)) . ',
159 livePreview: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.livePreview', TRUE)) . ',
160 livePreviewDetail: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.livePreviewDetail', TRUE)) . ',
161 workspacePreview: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.workspacePreview', TRUE)) . ',
162 workspacePreviewDetail: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.workspacePreviewDetail', TRUE)) . ',
163 modeSlider: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.modeSlider', TRUE)) . ',
164 modeVbox: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.modeVbox', TRUE)) . ',
165 modeHbox: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:preview.modeHbox', TRUE)) . ',
166 discard: ' . Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:label_doaction_discard', TRUE)) . ',
167 nextStage: ' . Utility\GeneralUtility::quoteJSvalue($nextStage['title']) . ',
168 previousStage: ' . Utility\GeneralUtility::quoteJSvalue($previousStage['title']) . '
169 };TYPO3.l10n.initialize();
170 ');
171 $resourcePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/';
172 $this->pageRenderer->addJsFile($resourcePath . 'JavaScript/preview.js');
173 }
174
175 /**
176 * Evaluate the activate state based on given $stageArray.
177 *
178 * @param array $stageArray
179 * @return boolean
180 * @author Michael Klapper <development@morphodo.com>
181 */
182 protected function isInvalidStage($stageArray) {
183 return !(is_array($stageArray) && count($stageArray) > 0);
184 }
185
186 /**
187 * @return void
188 */
189 public function newPageAction() {
190 $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);
191 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
192 $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
193 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
194 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
195 $defaultFlashMessageQueue->enqueue($flashMessage);
196 }
197
198 /**
199 * Generates the JavaScript code for the backend,
200 * and since we're loading a backend module outside of the actual backend
201 * this copies parts of the backend.php
202 *
203 * @return string
204 */
205 protected function generateJavascript() {
206 $pathTYPO3 = GeneralUtility::dirname(GeneralUtility::getIndpEnv('SCRIPT_NAME')) . '/';
207 // If another page module was specified, replace the default Page module with the new one
208 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
209 $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
210 if (!$GLOBALS['BE_USER']->check('modules', $pageModule)) {
211 $pageModule = '';
212 }
213 $menuFrameName = 'menu';
214 if ($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
215 $menuFrameName = 'topmenuFrame';
216 }
217 // determine security level from conf vars and default to super challenged
218 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
219 $loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
220 } else {
221 $loginSecurityLevel = 'superchallenged';
222 }
223 $t3Configuration = array(
224 'siteUrl' => GeneralUtility::getIndpEnv('TYPO3_SITE_URL'),
225 'PATH_typo3' => $pathTYPO3,
226 'PATH_typo3_enc' => rawurlencode($pathTYPO3),
227 'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
228 'uniqueID' => GeneralUtility::shortMD5(uniqid('')),
229 'securityLevel' => $this->loginSecurityLevel,
230 'TYPO3_mainDir' => TYPO3_mainDir,
231 'pageModule' => $pageModule,
232 'condensedMode' => $GLOBALS['BE_USER']->uc['condensedMode'] ? 1 : 0,
233 'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 0,
234 'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
235 'veriCode' => $GLOBALS['BE_USER']->veriCode(),
236 'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
237 'moduleMenuWidth' => $this->menuWidth - 1,
238 'topBarHeight' => isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? (int)$GLOBALS['TBE_STYLES']['dims']['topFrameH'] : 30,
239 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] : FALSE,
240 'listModulePath' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('recordlist') ? \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('recordlist') . 'mod1/' : '',
241 'debugInWindow' => $GLOBALS['BE_USER']->uc['debugInWindow'] ? 1 : 0,
242 'ContextHelpWindows' => array(
243 'width' => 600,
244 'height' => 400
245 )
246 );
247 $t3LLLcore = array(
248 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_logging_in'),
249 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_failed'),
250 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_failed_message'),
251 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
252 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.login_expired'),
253 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_username'),
254 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_password'),
255 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_emptyPassword'),
256 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_button'),
257 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_logout_button'),
258 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.please_wait'),
259 'loadingIndicator' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:loadingIndicator'),
260 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.be_locked'),
261 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_countdown_singular'),
262 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_countdown'),
263 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.login_about_to_expire'),
264 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.login_about_to_expire_title'),
265 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login_refresh_button'),
266 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_direct_logout_button'),
267 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tabs.closeAll'),
268 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tabs.closeOther'),
269 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tabs.close'),
270 'tabs_openInBrowserWindow' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tabs.openInBrowserWindow'),
271 'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.title'),
272 'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.message'),
273 'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.button_donate'),
274 'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.button_disable'),
275 'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:donateWindow.button_postpone')
276 );
277 $js = '
278 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
279 TYPO3.LLL = {
280 core : ' . json_encode($t3LLLcore) . '
281 };
282
283 /**
284 * TypoSetup object.
285 */
286 function typoSetup() { //
287 this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
288 this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
289 this.username = TYPO3.configuration.username;
290 this.uniqueID = TYPO3.configuration.uniqueID;
291 this.navFrameWidth = 0;
292 this.securityLevel = TYPO3.configuration.securityLevel;
293 this.veriCode = TYPO3.configuration.veriCode;
294 this.denyFileTypes = TYPO3.configuration.denyFileTypes;
295 }
296 var TS = new typoSetup();
297 //backwards compatibility
298 ';
299 return $js;
300 }
301
302 }