TYPO3 API  SVNRelease
backend.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2007-2011 Ingo Renner <ingo@typo3.org>
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 require_once('init.php');
00029 require_once('template.php');
00030 require_once('interfaces/interface.backend_toolbaritem.php');
00031 
00032 require('classes/class.typo3logo.php');
00033 require('classes/class.modulemenu.php');
00034 
00035     // core toolbar items
00036 require('classes/class.clearcachemenu.php');
00037 require('classes/class.shortcutmenu.php');
00038 require('classes/class.livesearch.php');
00039 
00040 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xml');
00041 
00042 
00043 /**
00044  * Class for rendering the TYPO3 backend version 4.2+
00045  *
00046  * @author  Ingo Renner <ingo@typo3.org>
00047  * @package TYPO3
00048  * @subpackage core
00049  */
00050 class TYPO3backend {
00051 
00052     protected $content;
00053     protected $css;
00054     protected $cssFiles;
00055     protected $js;
00056     protected $jsFiles;
00057     protected $jsFilesAfterInline;
00058     protected $toolbarItems;
00059     private   $menuWidthDefault = 190; // intentionally private as nobody should modify defaults
00060     protected $menuWidth;
00061     protected $debug;
00062 
00063     /**
00064      * Object for loading backend modules
00065      *
00066      * @var t3lib_loadModules
00067      */
00068     protected $moduleLoader;
00069 
00070     /**
00071      * module menu generating object
00072      *
00073      * @var ModuleMenu
00074      */
00075     protected $moduleMenu;
00076 
00077     /**
00078      * Pagerenderer
00079      *
00080      * @var t3lib_PageRenderer
00081      */
00082     protected $pageRenderer;
00083 
00084     /**
00085      * constructor
00086      *
00087      * @return  void
00088      */
00089     public function __construct() {
00090             // set debug flag for BE development only
00091         $this->debug = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['debug']) === 1;
00092 
00093             // Initializes the backend modules structure for use later.
00094         $this->moduleLoader = t3lib_div::makeInstance('t3lib_loadModules');
00095         $this->moduleLoader->load($GLOBALS['TBE_MODULES']);
00096 
00097         $this->moduleMenu = t3lib_div::makeInstance('ModuleMenu');
00098 
00099         $this->pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
00100         $this->pageRenderer->loadScriptaculous('builder,effects,controls,dragdrop');
00101         $this->pageRenderer->loadExtJS();
00102         $this->pageRenderer->enableExtJSQuickTips();
00103 
00104 
00105         $this->pageRenderer->addJsInlineCode(
00106             'consoleOverrideWithDebugPanel',
00107             '//already done'
00108         );
00109         $this->pageRenderer->addExtDirectCode();
00110 
00111             // add default BE javascript
00112         $this->js      = '';
00113         $this->jsFiles = array(
00114             'common'                => 'js/common.js',
00115             'locallang'             => $this->getLocalLangFileName(),
00116             'modernizr'             => 'contrib/modernizr/modernizr.min.js',
00117             'swfupload'             => 'contrib/swfupload/swfupload.js',
00118             'swfupload.swfobject'   => 'contrib/swfupload/plugins/swfupload.swfobject.js',
00119             'swfupload.cookies'     => 'contrib/swfupload/plugins/swfupload.cookies.js',
00120             'swfupload.queue'       => 'contrib/swfupload/plugins/swfupload.queue.js',
00121             'md5'                   => 'md5.js',
00122             'toolbarmanager'        => 'js/toolbarmanager.js',
00123             'modulemenu'            => 'js/modulemenu.js',
00124             'iecompatibility'       => 'js/iecompatibility.js',
00125             'flashupload'           => 'js/flashupload.js',
00126             'evalfield'             => '../t3lib/jsfunc.evalfield.js',
00127             'flashmessages'         => '../t3lib/js/extjs/ux/flashmessages.js',
00128             'tabclosemenu'          => '../t3lib/js/extjs/ux/ext.ux.tabclosemenu.js',
00129             'notifications'         => '../t3lib/js/extjs/notifications.js',
00130             'backend'               => 'js/backend.js',
00131             'loginrefresh'          => 'js/loginrefresh.js',
00132             'debugPanel'            => 'js/extjs/debugPanel.js',
00133             'viewport'              => 'js/extjs/viewport.js',
00134             'iframepanel'           => 'js/extjs/iframepanel.js',
00135             'viewportConfiguration' => 'js/extjs/viewportConfiguration.js',
00136             'util'                  => '../t3lib/js/extjs/util.js',
00137         );
00138 
00139         if ($this->debug) {
00140             unset($this->jsFiles['loginrefresh']);
00141         }
00142 
00143             // add default BE css
00144         $this->css      = '';
00145         $this->cssFiles = array();
00146 
00147         $this->toolbarItems = array();
00148         $this->initializeCoreToolbarItems();
00149 
00150         $this->menuWidth = $this->menuWidthDefault;
00151         if (isset($GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW']) && (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'] != (int) $this->menuWidth) {
00152             $this->menuWidth = (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'];
00153         }
00154 
00155         $this->executeHook('constructPostProcess');
00156     }
00157 
00158     /**
00159      * initializes the core toolbar items
00160      *
00161      * @return  void
00162      */
00163     protected function initializeCoreToolbarItems() {
00164 
00165         $coreToolbarItems = array(
00166             'shortcuts'         => 'ShortcutMenu',
00167             'clearCacheActions' => 'ClearCacheMenu',
00168             'liveSearch'        => 'LiveSearch'
00169         );
00170 
00171         foreach($coreToolbarItems as $toolbarItemName => $toolbarItemClassName) {
00172             $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
00173 
00174             if(!($toolbarItem instanceof backend_toolbarItem)) {
00175                 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195126772);
00176             }
00177 
00178             if($toolbarItem->checkAccess()) {
00179                 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
00180             } else {
00181                 unset($toolbarItem);
00182             }
00183         }
00184     }
00185 
00186     /**
00187      * main function generating the BE scaffolding
00188      *
00189      * @return  void
00190      */
00191     public function render()    {
00192         $this->executeHook('renderPreProcess');
00193 
00194             // prepare the scaffolding, at this point extension may still add javascript and css
00195         $logo         = t3lib_div::makeInstance('TYPO3Logo');
00196         $logo->setLogo('gfx/typo3logo_mini.png');
00197 
00198 
00199 
00200             // create backend scaffolding
00201         $backendScaffolding = '
00202         <div id="typo3-top-container" class="x-hide-display">
00203             <div id="typo3-logo">'.$logo->render().'</div>
00204             <div id="typo3-top" class="typo3-top-toolbar">' .
00205                 $this->renderToolbar() .
00206             '</div>
00207         </div>
00208 
00209 ';
00210 
00211         /******************************************************
00212          * now put the complete backend document together
00213          ******************************************************/
00214 
00215         foreach($this->cssFiles as $cssFileName => $cssFile) {
00216             $this->pageRenderer->addCssFile($cssFile);
00217 
00218                 // load addditional css files to overwrite existing core styles
00219             if(!empty($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName])) {
00220                 $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName]);
00221             }
00222         }
00223 
00224         if(!empty($this->css)) {
00225             $this->pageRenderer->addCssInlineBlock('BackendInlineCSS', $this->css);
00226         }
00227 
00228         foreach ($this->jsFiles as $jsFile) {
00229             $this->pageRenderer->addJsFile($jsFile);
00230         }
00231 
00232 
00233         $this->generateJavascript();
00234         $this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js);
00235 
00236         $this->loadResourcesForRegisteredNavigationComponents();
00237 
00238             // add state provider
00239         $GLOBALS['TBE_TEMPLATE']->setExtDirectStateProvider();
00240         $states = $GLOBALS['BE_USER']->uc['BackendComponents']['States'];
00241             //save states in BE_USER->uc
00242         $extOnReadyCode = '
00243             Ext.state.Manager.setProvider(new TYPO3.state.ExtDirectProvider({
00244                 key: "BackendComponents.States",
00245                 autoRead: false
00246             }));
00247         ';
00248         if ($states) {
00249             $extOnReadyCode .= 'Ext.state.Manager.getProvider().initState(' . json_encode($states) . ');';
00250         }
00251         $extOnReadyCode .= '
00252             TYPO3.Backend = new TYPO3.Viewport(TYPO3.Viewport.configuration);
00253             if (typeof console === "undefined") {
00254                 console = TYPO3.Backend.DebugConsole;
00255             }
00256             TYPO3.ContextHelpWindow.init();';
00257         $this->pageRenderer->addExtOnReadyCode($extOnReadyCode);
00258 
00259 
00260             // set document title:
00261         $title = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
00262             ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']'
00263             : 'TYPO3 '.TYPO3_version
00264         );
00265 
00266         $this->content = $backendScaffolding;
00267             // Renders the module page
00268         $this->content = $GLOBALS['TBE_TEMPLATE']->render(
00269             $title,
00270             $this->content
00271         );
00272 
00273         $hookConfiguration = array('content' => &$this->content);
00274         $this->executeHook('renderPostProcess', $hookConfiguration);
00275 
00276         echo $this->content;
00277     }
00278 
00279     /**
00280      * Loads the css and javascript files of all registered navigation widgets
00281      *
00282      * @return void
00283      */
00284     protected function loadResourcesForRegisteredNavigationComponents() {
00285         if (!is_array($GLOBALS['TBE_MODULES']['_navigationComponents'])) {
00286             return;
00287         }
00288 
00289         $loadedComponents = array();
00290         foreach ($GLOBALS['TBE_MODULES']['_navigationComponents'] as $module => $info) {
00291             if (in_array($info['componentId'], $loadedComponents)) {
00292                 continue;
00293             }
00294             $loadedComponents[] = $info['componentId'];
00295 
00296             $component = strtolower(substr($info['componentId'], strrpos($info['componentId'], '-') + 1));
00297             $componentDirectory = 'components/' . $component . '/';
00298 
00299             if ($info['isCoreComponent']) {
00300                 $absoluteComponentPath = PATH_t3lib . 'js/extjs/' . $componentDirectory;
00301                 $relativeComponentPath = '../' . str_replace(PATH_site, '', $absoluteComponentPath);
00302             } else {
00303                 $absoluteComponentPath = t3lib_extMgm::extPath($info['extKey']) . $componentDirectory;
00304                 $relativeComponentPath = t3lib_extMgm::extRelPath($info['extKey']) . $componentDirectory;
00305             }
00306 
00307             $cssFiles = t3lib_div::getFilesInDir($absoluteComponentPath . 'css/', 'css');
00308             if (file_exists($absoluteComponentPath . 'css/loadorder.txt')) {
00309                     //don't allow inclusion outside directory
00310                 $loadOrder = str_replace('../', '', t3lib_div::getURL($absoluteComponentPath . 'css/loadorder.txt'));
00311                 $cssFilesOrdered = t3lib_div::trimExplode(LF, $loadOrder, TRUE);
00312                 $cssFiles = array_merge($cssFilesOrdered, $cssFiles);
00313             }
00314             foreach ($cssFiles as $cssFile) {
00315                 $this->pageRenderer->addCssFile($relativeComponentPath . 'css/' . $cssFile);
00316             }
00317 
00318             $jsFiles = t3lib_div::getFilesInDir($absoluteComponentPath . 'javascript/', 'js');
00319             if (file_exists($absoluteComponentPath . 'javascript/loadorder.txt')) {
00320                     //don't allow inclusion outside directory
00321                 $loadOrder = str_replace('../', '', t3lib_div::getURL($absoluteComponentPath . 'javascript/loadorder.txt'));
00322                 $jsFilesOrdered = t3lib_div::trimExplode(LF, $loadOrder, TRUE);
00323                 $jsFiles = array_merge($jsFilesOrdered, $jsFiles);
00324             }
00325 
00326             foreach ($jsFiles as $jsFile) {
00327                 $this->pageRenderer->addJsFile($relativeComponentPath . 'javascript/' . $jsFile);
00328             }
00329         }
00330     }
00331 
00332     /**
00333      * renders the items in the top toolbar
00334      *
00335      * @return  string  top toolbar elements as HTML
00336      */
00337     protected function renderToolbar() {
00338 
00339             // move search to last position
00340         if (array_key_exists('liveSearch', $this->toolbarItems)) {
00341             $search = $this->toolbarItems['liveSearch'];
00342             unset($this->toolbarItems['liveSearch']);
00343             $this->toolbarItems['liveSearch'] = $search;
00344         }
00345 
00346         $toolbar = '<ul id="typo3-toolbar">';
00347         $toolbar.= '<li>'.$this->getLoggedInUserLabel().'</li>
00348                     <li><div id="logout-button" class="toolbar-item no-separator">'.$this->moduleMenu->renderLogoutButton().'</div></li>';
00349 
00350         foreach($this->toolbarItems as $toolbarItem) {
00351             $menu = $toolbarItem->render();
00352             if ($menu) {
00353                 $additionalAttributes = $toolbarItem->getAdditionalAttributes();
00354                 $toolbar .= '<li' . $additionalAttributes . '>' .$menu. '</li>';
00355             }
00356         }
00357 
00358         return $toolbar.'</ul>';
00359     }
00360 
00361     /**
00362      * Gets the label of the BE user currently logged in
00363      *
00364      * @return  string      html code snippet displaying the currently logged in user
00365      */
00366     protected function getLoggedInUserLabel() {
00367         global $BE_USER, $BACK_PATH;
00368 
00369                 $icon = t3lib_iconWorks::getSpriteIcon('status-user-'. ($BE_USER->isAdmin() ? 'admin' : 'backend'));
00370 
00371         $label = $GLOBALS['BE_USER']->user['realName'] ?
00372             $BE_USER->user['realName'] . ' (' . $BE_USER->user['username'] . ')' :
00373             $BE_USER->user['username'];
00374 
00375             // Link to user setup if it's loaded and user has access
00376         $link = '';
00377         if (t3lib_extMgm::isLoaded('setup') && $BE_USER->check('modules','user_setup')) {
00378             $link = '<a href="#" onclick="top.goToModule(\'user_setup\');this.blur();return false;">';
00379         }
00380 
00381         $username = '">'.$link.$icon.'<span>'.htmlspecialchars($label).'</span>'.($link?'</a>':'');
00382 
00383             // superuser mode
00384         if($BE_USER->user['ses_backuserid']) {
00385             $username   = ' su-user">'.$icon.
00386             '<span title="' . $GLOBALS['LANG']->getLL('switchtouser') . '">' .
00387             $GLOBALS['LANG']->getLL('switchtousershort') . ' </span>' .
00388             '<span>' . htmlspecialchars($label) . '</span>';
00389         }
00390 
00391         return '<div id="username" class="toolbar-item no-separator'.$username.'</div>';
00392     }
00393 
00394     /**
00395      * Returns the file name  to the LLL JavaScript, containing the localized labels,
00396      * which can be used in JavaScript code.
00397      *
00398      * @return string File name of the JS file, relative to TYPO3_mainDir
00399      */
00400     protected function getLocalLangFileName() {
00401         $code = $this->generateLocalLang();
00402         $filePath = 'typo3temp/locallang-BE-' . sha1($code) . '.js';
00403         if (!file_exists(PATH_site . $filePath)) {
00404                 // writeFileToTypo3tempDir() returns NULL on success (please double-read!)
00405             if (t3lib_div::writeFileToTypo3tempDir(PATH_site . $filePath, $code) !== NULL) {
00406                 throw new RuntimeException('LocalLangFile could not be written to ' . $filePath, 1295193026);
00407             }
00408         }
00409         return '../' . $filePath;
00410     }
00411 
00412     /**
00413      * Reads labels required in JavaScript code from the localization system and returns them as JSON
00414      * array in TYPO3.LLL.
00415      *
00416      * @return string JavaScript code containing the LLL labels in TYPO3.LLL
00417      */
00418     protected function generateLocalLang() {
00419         $coreLabels = array(
00420             'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in') ,
00421             'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'),
00422             'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'),
00423             'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
00424             'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'),
00425             'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'),
00426             'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'),
00427             'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'),
00428             'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'),
00429             'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'),
00430             'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'),
00431             'loadingIndicator' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:loadingIndicator'),
00432             'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'),
00433             'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'),
00434             'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'),
00435             'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'),
00436             'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'),
00437             'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'),
00438             'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'),
00439             'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeAll'),
00440             'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeOther'),
00441             'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.close'),
00442             'tabs_openInBrowserWindow' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.openInBrowserWindow'),
00443             'csh_tooltip_loading' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:csh_tooltip_loading'),
00444         );
00445 
00446         $labels = array(
00447             'fileUpload' => array(
00448                 'windowTitle',
00449                 'buttonSelectFiles',
00450                 'buttonCancelAll',
00451                 'infoComponentMaxFileSize',
00452                 'infoComponentFileUploadLimit',
00453                 'infoComponentFileTypeLimit',
00454                 'infoComponentOverrideFiles',
00455                 'processRunning',
00456                 'uploadWait',
00457                 'uploadStarting',
00458                 'uploadProgress',
00459                 'uploadSuccess',
00460                 'errorQueueLimitExceeded',
00461                 'errorQueueFileSizeLimit',
00462                 'errorQueueZeroByteFile',
00463                 'errorQueueInvalidFiletype',
00464                 'errorUploadHttp',
00465                 'errorUploadMissingUrl',
00466                 'errorUploadIO',
00467                 'errorUploadSecurityError',
00468                 'errorUploadLimit',
00469                 'errorUploadFailed',
00470                 'errorUploadFileIDNotFound',
00471                 'errorUploadFileValidation',
00472                 'errorUploadFileCancelled',
00473                 'errorUploadStopped',
00474                 'allErrorMessageTitle',
00475                 'allErrorMessageText',
00476                 'allError401',
00477                 'allError2038',
00478             ),
00479             'liveSearch' => array(
00480                 'title',
00481                 'helpTitle',
00482                 'emptyText',
00483                 'loadingText',
00484                 'listEmptyText',
00485                 'showAllResults',
00486                 'helpDescription',
00487                 'helpDescriptionPages',
00488                 'helpDescriptionContent',
00489             ),
00490             'viewPort' => array(
00491                 'tooltipModuleMenuSplit',
00492                 'tooltipNavigationContainerSplitDrag',
00493                 'tooltipDebugPanelSplitDrag',
00494 
00495             ),
00496         );
00497         $generatedLabels = array();
00498         $generatedLabels['core'] = $coreLabels;
00499 
00500             // first loop over all categories (fileUpload, liveSearch, ..)
00501         foreach ($labels as $categoryName => $categoryLabels) {
00502                 // then loop over every single label
00503             foreach ($categoryLabels as $label) {
00504                     // LLL identifier must be called $categoryName_$label, e.g. liveSearch_loadingText
00505                 $generatedLabels[$categoryName][$label] = $GLOBALS['LANG']->getLL($categoryName . '_' . $label);
00506             }
00507         }
00508 
00509             // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
00510         if ($GLOBALS['LANG']->charSet !== 'utf-8') {
00511             $GLOBALS['LANG']->csConvObj->convArray($generatedLabels, $GLOBALS['LANG']->charSet, 'utf-8');
00512         }
00513 
00514         return 'TYPO3.LLL = ' . json_encode($generatedLabels) . ';';
00515     }
00516 
00517     /**
00518      * Generates the JavaScript code for the backend.
00519      *
00520      * @return  void
00521      */
00522     protected function generateJavascript() {
00523 
00524         $pathTYPO3          = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
00525 
00526             // If another page module was specified, replace the default Page module with the new one
00527         $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
00528         $pageModule    = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
00529         if (!$GLOBALS['BE_USER']->check('modules', $pageModule)) {
00530             $pageModule = '';
00531         }
00532 
00533         $menuFrameName = 'menu';
00534         if($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
00535             $menuFrameName = 'topmenuFrame';
00536         }
00537 
00538         // determine security level from conf vars and default to super challenged
00539         if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
00540             $this->loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
00541         } else {
00542             $this->loginSecurityLevel = 'superchallenged';
00543         }
00544 
00545         $t3Configuration = array(
00546             'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
00547             'PATH_typo3' => $pathTYPO3,
00548             'PATH_typo3_enc' => rawurlencode($pathTYPO3),
00549             'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
00550             'uniqueID' => t3lib_div::shortMD5(uniqid('')),
00551             'securityLevel' => $this->loginSecurityLevel,
00552             'TYPO3_mainDir' => TYPO3_mainDir,
00553             'pageModule' => $pageModule,
00554             'condensedMode' => $GLOBALS['BE_USER']->uc['condensedMode'] ? 1 : 0 ,
00555             'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 0,
00556             'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
00557             'veriCode' => $GLOBALS['BE_USER']->veriCode(),
00558             'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
00559             'moduleMenuWidth' => $this->menuWidth - 1,
00560             'topBarHeight' => (isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? intval($GLOBALS['TBE_STYLES']['dims']['topFrameH']) : 30),
00561             'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? intval($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) : FALSE,
00562             'listModulePath' => t3lib_extMgm::isLoaded('recordlist') ? t3lib_extMgm::extRelPath('recordlist') . 'mod1/' : '',
00563             'debugInWindow' => $GLOBALS['BE_USER']->uc['debugInWindow'] ? 1 : 0,
00564             'ContextHelpWindows' => array(
00565                 'width' => 600,
00566                 'height' => 400
00567             ),
00568             'firstWebmountPid' => intval($GLOBALS['WEBMOUNTS'][0]),
00569         );
00570         if ($GLOBALS['LANG']->charSet !== 'utf-8') {
00571             $t3Configuration['username'] = $GLOBALS['LANG']->csConvObj->conv($t3Configuration['username'], $GLOBALS['LANG']->charSet, 'utf-8');
00572         }
00573 
00574         $this->js .= '
00575     TYPO3.configuration = ' . json_encode($t3Configuration) . ';
00576 
00577     /**
00578      * TypoSetup object.
00579      */
00580     function typoSetup()    {   //
00581         this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
00582         this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
00583         this.username = TYPO3.configuration.username;
00584         this.uniqueID = TYPO3.configuration.uniqueID;
00585         this.navFrameWidth = 0;
00586         this.securityLevel = TYPO3.configuration.securityLevel;
00587         this.veriCode = TYPO3.configuration.veriCode;
00588         this.denyFileTypes = TYPO3.configuration.denyFileTypes;
00589     }
00590     var TS = new typoSetup();
00591         //backwards compatibility
00592     /**
00593      * Frameset Module object
00594      *
00595      * Used in main modules with a frameset for submodules to keep the ID between modules
00596      * Typically that is set by something like this in a Web>* sub module:
00597      *      if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
00598      *      if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
00599      */
00600     function fsModules()    {   //
00601         this.recentIds=new Array();                 // used by frameset modules to track the most recent used id for list frame.
00602         this.navFrameHighlightedID=new Array();     // used by navigation frames to track which row id was highlighted last time
00603         this.currentMainLoaded="";
00604         this.currentBank="0";
00605     }
00606     var fsMod = new fsModules();
00607 
00608     top.goToModule = function(modName, cMR_flag, addGetVars) {
00609         TYPO3.ModuleMenu.App.showModule(modName, addGetVars);
00610     }
00611     ' . $this->setStartupModule();
00612 
00613             // Check editing of page:
00614         $this->handlePageEditing();
00615 
00616     }
00617 
00618     /**
00619      * Checking if the "&edit" variable was sent so we can open it for editing the page.
00620      * Code based on code from "alt_shortcut.php"
00621      *
00622      * @return  void
00623      */
00624     protected function handlePageEditing()  {
00625 
00626         if(!t3lib_extMgm::isLoaded('cms'))  {
00627             return;
00628         }
00629 
00630             // EDIT page:
00631         $editId     = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('edit'));
00632         $editRecord = '';
00633 
00634         if($editId) {
00635 
00636                 // Looking up the page to edit, checking permissions:
00637             $where = ' AND ('.$GLOBALS['BE_USER']->getPagePermsClause(2)
00638                     .' OR '.$GLOBALS['BE_USER']->getPagePermsClause(16).')';
00639 
00640             if(t3lib_div::testInt($editId)) {
00641                 $editRecord = t3lib_BEfunc::getRecordWSOL('pages', $editId, '*', $where);
00642             } else {
00643                 $records = t3lib_BEfunc::getRecordsByField('pages', 'alias', $editId, $where);
00644 
00645                 if(is_array($records))  {
00646                     reset($records);
00647                     $editRecord = current($records);
00648                     t3lib_BEfunc::workspaceOL('pages', $editRecord);
00649                 }
00650             }
00651 
00652                 // If the page was accessible, then let the user edit it.
00653             if(is_array($editRecord) && $GLOBALS['BE_USER']->isInWebMount($editRecord['uid']))  {
00654                     // Setting JS code to open editing:
00655                 $this->js .= '
00656         // Load page to edit:
00657     window.setTimeout("top.loadEditId('.intval($editRecord['uid']).');", 500);
00658             ';
00659 
00660                     // "Shortcuts" have been renamed to "Bookmarks"
00661                     // @deprecated remove shortcuts code in TYPO3 4.7
00662                 $shortcutSetPageTree = $GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree');
00663                 $bookmarkSetPageTree = $GLOBALS['BE_USER']->getTSConfigVal('options.bookmark_onEditId_dontSetPageTree');
00664                 if ($shortcutSetPageTree !== '') {
00665                     t3lib_div::deprecationLog('options.shortcut_onEditId_dontSetPageTree - since TYPO3 4.5, will be removed in TYPO3 4.7 - use options.bookmark_onEditId_dontSetPageTree instead');
00666                 }
00667 
00668                     // Checking page edit parameter:
00669                 if (!$shortcutSetPageTree && !$bookmarkSetPageTree) {
00670 
00671                     $shortcutKeepExpanded = $GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded');
00672                     $bookmarkKeepExpanded = $GLOBALS['BE_USER']->getTSConfigVal('options.bookmark_onEditId_keepExistingExpanded');
00673                     $keepExpanded = ($shortcutKeepExpanded || $bookmarkKeepExpanded);
00674 
00675                         // Expanding page tree:
00676                     t3lib_BEfunc::openPageTree(intval($editRecord['pid']), !$keepExpanded);
00677 
00678                     if ($shortcutKeepExpanded) {
00679                         t3lib_div::deprecationLog('options.shortcut_onEditId_keepExistingExpanded - since TYPO3 4.5, will be removed in TYPO3 4.7 - use options.bookmark_onEditId_keepExistingExpanded instead');
00680                     }
00681                 }
00682             } else {
00683                 $this->js .= '
00684         // Warning about page editing:
00685     alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)).');
00686             ';
00687             }
00688         }
00689     }
00690 
00691     /**
00692      * Sets the startup module from either GETvars module and mpdParams or user configuration.
00693      *
00694      * @return  void
00695      */
00696     protected function setStartupModule() {
00697         $startModule = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('module'));
00698 
00699         if(!$startModule)   {
00700             if ($GLOBALS['BE_USER']->uc['startModule']) {
00701                 $startModule = $GLOBALS['BE_USER']->uc['startModule'];
00702             } else if($GLOBALS['BE_USER']->uc['startInTaskCenter']) {
00703                 $startModule = 'user_task';
00704             }
00705         }
00706 
00707         $moduleParameters = t3lib_div::_GET('modParams');
00708         if($startModule) {
00709             return '
00710                     // start in module:
00711                 top.startInModule = [\'' . $startModule . '\', ' . t3lib_div::quoteJSvalue($moduleParameters) . '];
00712             ';
00713         } else {
00714             return '';
00715         }
00716 
00717     }
00718 
00719     /**
00720      * adds a javascript snippet to the backend
00721      *
00722      * @param   string  javascript snippet
00723      * @return  void
00724      */
00725     public function addJavascript($javascript) {
00726             // TODO do we need more checks?
00727         if(!is_string($javascript)) {
00728             throw new InvalidArgumentException('parameter $javascript must be of type string', 1195129553);
00729         }
00730 
00731         $this->js .= $javascript;
00732     }
00733 
00734     /**
00735      * adds a javscript file to the backend after it has been checked that it exists
00736      *
00737      * @param   string  javascript file reference
00738      * @return  boolean true if the javascript file was successfully added, false otherwise
00739      */
00740     public function addJavascriptFile($javascriptFile) {
00741         $jsFileAdded = false;
00742 
00743             //TODO add more checks if neccessary
00744         if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$javascriptFile))) {
00745             $this->jsFiles[] = $javascriptFile;
00746             $jsFileAdded     = true;
00747         }
00748 
00749         return $jsFileAdded;
00750     }
00751 
00752     /**
00753      * adds a css snippet to the backend
00754      *
00755      * @param   string  css snippet
00756      * @return  void
00757      */
00758     public function addCss($css) {
00759         if(!is_string($css)) {
00760             throw new InvalidArgumentException('parameter $css must be of type string', 1195129642);
00761         }
00762 
00763         $this->css .= $css;
00764     }
00765 
00766     /**
00767      * adds a css file to the backend after it has been checked that it exists
00768      *
00769      * @param   string  the css file's name with out the .css ending
00770      * @param   string  css file reference
00771      * @return  boolean true if the css file was added, false otherwise
00772      */
00773     public function addCssFile($cssFileName, $cssFile) {
00774         $cssFileAdded = false;
00775 
00776         if(empty($this->cssFiles[$cssFileName])) {
00777             $this->cssFiles[$cssFileName] = $cssFile;
00778             $cssFileAdded = true;
00779         }
00780 
00781         return $cssFileAdded;
00782     }
00783 
00784     /**
00785      * adds an item to the toolbar, the class file for the toolbar item must be loaded at this point
00786      *
00787      * @param   string  toolbar item name, f.e. tx_toolbarExtension_coolItem
00788      * @param   string  toolbar item class name, f.e. tx_toolbarExtension_coolItem
00789      * @return  void
00790      */
00791     public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
00792         $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
00793 
00794         if(!($toolbarItem instanceof backend_toolbarItem)) {
00795             throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195125501);
00796         }
00797 
00798         if($toolbarItem->checkAccess()) {
00799             $this->toolbarItems[$toolbarItemName] = $toolbarItem;
00800         } else {
00801             unset($toolbarItem);
00802         }
00803     }
00804 
00805     /**
00806      * Executes defined hooks functions for the given identifier.
00807      *
00808      * These hook identifiers are valid:
00809      *  + constructPostProcess
00810      *  + renderPreProcess
00811      *  + renderPostProcess
00812      *
00813      * @param string $identifier Specific hook identifier
00814      * @param array $hookConfiguration Additional configuration passed to hook functions
00815      * @return void
00816      */
00817     protected function executeHook($identifier, array $hookConfiguration = array()) {
00818         $options =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/backend.php'];
00819 
00820         if(isset($options[$identifier]) && is_array($options[$identifier])) {
00821             foreach($options[$identifier] as $hookFunction) {
00822                 t3lib_div::callUserFunction($hookFunction, $hookConfiguration, $this);
00823             }
00824         }
00825     }
00826 }
00827 
00828 
00829     // include XCLASS
00830 if(defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/backend.php']) {
00831     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/backend.php']);
00832 }
00833 
00834 
00835     // document generation
00836 $TYPO3backend = t3lib_div::makeInstance('TYPO3backend');
00837 
00838     // include extensions which may add css, javascript or toolbar items
00839 if(is_array($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'])) {
00840     foreach($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'] as $additionalBackendItem) {
00841         include_once($additionalBackendItem);
00842     }
00843 }
00844 
00845 $TYPO3backend->render();
00846 
00847 ?>