TYPO3 API  SVNRelease
PreviewController.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010-2011 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *  A copy is found in the textfile GPL.txt and important notices to the license
00017  *  from the author is found in LICENSE.txt distributed with these scripts.
00018  *
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 
00028 /**
00029  * Implements the preview controller of the workspace module.
00030  *
00031  * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
00032  * @package Workspaces
00033  * @subpackage Controller
00034  */
00035 class Tx_Workspaces_Controller_PreviewController extends Tx_Workspaces_Controller_AbstractController {
00036 
00037     /**
00038      * Initializes the controller before invoking an action method.
00039      *
00040      * @return void
00041      */
00042     protected function initializeAction() {
00043         parent::initializeAction();
00044 
00045         $resourcePath = t3lib_extMgm::extRelPath('workspaces') . 'Resources/Public/';
00046         $GLOBALS['TBE_STYLES']['extJS']['theme'] = $resourcePath . 'StyleSheet/preview.css';
00047         $this->pageRenderer->loadExtJS();
00048         $this->pageRenderer->enableExtJSQuickTips();
00049         $this->pageRenderer->enableExtJsDebug();
00050 
00051             // Load  JavaScript:
00052         $this->pageRenderer->addExtDirectCode();
00053         $this->pageRenderer->addJsFile(
00054             $this->backPath . 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Workspaces&' . TYPO3_version,
00055             NULL,
00056             FALSE
00057         );
00058 
00059         $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/ux/flashmessages.js');
00060         $this->pageRenderer->addJsFile($this->backPath . 'js/extjs/iframepanel.js');
00061 
00062         $this->pageRenderer->addJsFile($resourcePath . 'JavaScript/Ext.ux.plugins.TabStripContainer.js');
00063         $this->pageRenderer->addJsFile($resourcePath . 'JavaScript/preview.js');
00064 
00065             // todo this part should be done with inlineLocallanglabels
00066         $this->pageRenderer->addJsInlineCode('workspace-inline-code', $this->generateJavascript());
00067     }
00068 
00069     /**
00070      * Basically makes sure that the workspace preview is rendered.
00071      * The preview itself consists of three frames, so there are
00072      * only the frames-urls we've to generate here
00073      *
00074      * @return void
00075      */
00076     public function indexAction() {
00077         // @todo language doesn't always come throught the L parameter
00078         // @todo Evaluate how the intval() call can be used with Extbase validators/filters
00079         $language = intval(t3lib_div::_GP('L'));
00080 
00081         $controller = t3lib_div::makeInstance('Tx_Workspaces_Controller_ReviewController', TRUE);
00082         /** @var $uriBuilder Tx_Extbase_MVC_Web_Routing_UriBuilder */
00083         $uriBuilder = $this->objectManager->create('Tx_Extbase_MVC_Web_Routing_UriBuilder');
00084 
00085         $wsSettingsPath = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . 'typo3/';
00086         $wsSettingsUri = $uriBuilder->uriFor('singleIndex', array(), 'Tx_Workspaces_Controller_ReviewController', 'workspaces', 'web_workspacesworkspaces');
00087         $wsSettingsParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Review';
00088         $wsSettingsUrl = $wsSettingsPath . $wsSettingsUri . $wsSettingsParams;
00089 
00090         $viewDomain = t3lib_BEfunc::getViewDomain($this->pageId);
00091         $wsBaseUrl =  $viewDomain . '/index.php?id=' . $this->pageId . '&L=' . $language;
00092 
00093         // @todo - handle new pages here
00094         // branchpoints are not handled anymore because this feature is not supposed anymore
00095         if (tx_Workspaces_Service_Workspaces::isNewPage($this->pageId)) {
00096             $wsNewPageUri = $uriBuilder->uriFor('newPage', array(), 'Tx_Workspaces_Controller_PreviewController', 'workspaces', 'web_workspacesworkspaces');
00097             $wsNewPageParams = '&tx_workspaces_web_workspacesworkspaces[controller]=Preview';
00098             $this->view->assign('liveUrl', $wsSettingsPath . $wsNewPageUri . $wsNewPageParams);
00099         } else {
00100             $this->view->assign('liveUrl', $wsBaseUrl . '&ADMCMD_noBeUser=1');
00101         }
00102         $this->view->assign('wsUrl', $wsBaseUrl . '&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS=' . $GLOBALS['BE_USER']->workspace);
00103         $this->view->assign('wsSettingsUrl', $wsSettingsUrl);
00104         $this->view->assign('backendDomain', t3lib_div::getIndpEnv('TYPO3_HOST_ONLY'));
00105         $GLOBALS['BE_USER']->setAndSaveSessionData('workspaces.backend_domain', t3lib_div::getIndpEnv('TYPO3_HOST_ONLY'));
00106         $this->pageRenderer->addJsInlineCode("workspaces.preview.lll" , "TYPO3.LLL.Workspaces = {
00107             visualPreview: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.visualPreview', true) . "',
00108             listView: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.listView', true) . "',
00109             livePreview: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.livePreview', true) . "',
00110             livePreviewDetail: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.livePreviewDetail', true) . "',
00111             workspacePreview: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.workspacePreview', true) . "',
00112             workspacePreviewDetail: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.workspacePreviewDetail', true) . "',
00113             modeSlider: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeSlider', true) . "',
00114             modeVbox: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeVbox', true) . "',
00115             modeHbox: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeHbox', true) . "'
00116         };\n");
00117     }
00118 
00119     /**
00120      * @return void
00121      */
00122     public function newPageAction() {
00123         $message = t3lib_div::makeInstance(
00124             't3lib_FlashMessage',
00125             $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:info.newpage.detail'),
00126             $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:info.newpage'),
00127             t3lib_FlashMessage::INFO
00128         );
00129         t3lib_FlashMessageQueue::addMessage($message);
00130     }
00131 
00132     /**
00133      * Generates the JavaScript code for the backend,
00134      * and since we're loading a backend module outside of the actual backend
00135      * this copies parts of the backend.php
00136      *
00137      * @return  void
00138      */
00139     protected function generateJavascript() {
00140         $pathTYPO3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')) . '/';
00141 
00142             // If another page module was specified, replace the default Page module with the new one
00143         $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
00144         $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
00145         if (!$GLOBALS['BE_USER']->check('modules', $pageModule)) {
00146             $pageModule = '';
00147         }
00148 
00149         $menuFrameName = 'menu';
00150         if ($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
00151             $menuFrameName = 'topmenuFrame';
00152         }
00153 
00154             // determine security level from conf vars and default to super challenged
00155         if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
00156             $loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
00157         } else {
00158             $loginSecurityLevel = 'superchallenged';
00159         }
00160 
00161         $t3Configuration = array(
00162             'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
00163             'PATH_typo3' => $pathTYPO3,
00164             'PATH_typo3_enc' => rawurlencode($pathTYPO3),
00165             'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
00166             'uniqueID' => t3lib_div::shortMD5(uniqid('')),
00167             'securityLevel' => $this->loginSecurityLevel,
00168             'TYPO3_mainDir' => TYPO3_mainDir,
00169             'pageModule' => $pageModule,
00170             'condensedMode' => $GLOBALS['BE_USER']->uc['condensedMode'] ? 1 : 0 ,
00171             'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 0,
00172             'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
00173             'veriCode' => $GLOBALS['BE_USER']->veriCode(),
00174             'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
00175             'moduleMenuWidth' => $this->menuWidth - 1,
00176             'topBarHeight' => (isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? intval($GLOBALS['TBE_STYLES']['dims']['topFrameH']) : 30),
00177             'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? intval($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) : FALSE,
00178             'listModulePath' => t3lib_extMgm::isLoaded('recordlist') ? t3lib_extMgm::extRelPath('recordlist') . 'mod1/' : '',
00179             'debugInWindow' => $GLOBALS['BE_USER']->uc['debugInWindow'] ? 1 : 0,
00180             'ContextHelpWindows' => array(
00181                 'width' => 600,
00182                 'height' => 400
00183             )
00184         );
00185 
00186         $t3LLLcore = array(
00187             'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in') ,
00188             'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'),
00189             'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'),
00190             'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
00191             'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'),
00192             'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'),
00193             'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'),
00194             'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'),
00195             'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'),
00196             'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'),
00197             'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'),
00198             'loadingIndicator' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:loadingIndicator'),
00199             'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'),
00200             'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'),
00201             'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'),
00202             'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'),
00203             'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'),
00204             'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'),
00205             'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'),
00206             'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeAll'),
00207             'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeOther'),
00208             'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.close'),
00209             'tabs_openInBrowserWindow' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.openInBrowserWindow'),
00210             'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.title'),
00211             'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.message'),
00212             'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_donate'),
00213             'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_disable'),
00214             'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_postpone'),
00215         );
00216 
00217             // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
00218         if ($GLOBALS['LANG']->charSet !== 'utf-8') {
00219             $t3Configuration['username'] = $GLOBALS['LANG']->csConvObj->conv($t3Configuration['username'], $GLOBALS['LANG']->charSet, 'utf-8');
00220             $GLOBALS['LANG']->csConvObj->convArray($t3LLLcore, $GLOBALS['LANG']->charSet, 'utf-8');
00221         }
00222 
00223         $js .= '
00224         TYPO3.configuration = ' . json_encode($t3Configuration) . ';
00225         TYPO3.LLL = {
00226             core : ' . json_encode($t3LLLcore) . '
00227         };
00228 
00229         /**
00230          * TypoSetup object.
00231          */
00232         function typoSetup()    {   //
00233             this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
00234             this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
00235             this.username = TYPO3.configuration.username;
00236             this.uniqueID = TYPO3.configuration.uniqueID;
00237             this.navFrameWidth = 0;
00238             this.securityLevel = TYPO3.configuration.securityLevel;
00239             this.veriCode = TYPO3.configuration.veriCode;
00240             this.denyFileTypes = TYPO3.configuration.denyFileTypes;
00241         }
00242         var TS = new typoSetup();
00243             //backwards compatibility
00244         ';
00245         return $js;
00246     }
00247 }
00248 
00249 
00250 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Controller/PreviewController.php'])) {
00251     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Controller/PreviewController.php']);
00252 }
00253 ?>