PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/typo3/backend.php

https://github.com/foxsoft/typo3v4core
PHP | 747 lines | 471 code | 103 blank | 173 comment | 52 complexity | ac5e9b6b7e9a9e723e4903c89086f848 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 2007-2010 Ingo Renner <ingo@typo3.org>
  6. * All rights reserved
  7. *
  8. * This script is part of the TYPO3 project. The TYPO3 project is
  9. * free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * The GNU General Public License can be found at
  15. * http://www.gnu.org/copyleft/gpl.html.
  16. * A copy is found in the textfile GPL.txt and important notices to the license
  17. * from the author is found in LICENSE.txt distributed with these scripts.
  18. *
  19. *
  20. * This script is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * This copyright notice MUST APPEAR in all copies of the script!
  26. ***************************************************************/
  27. require_once('init.php');
  28. require_once('template.php');
  29. require_once('interfaces/interface.backend_toolbaritem.php');
  30. require('classes/class.typo3logo.php');
  31. require('classes/class.modulemenu.php');
  32. require_once('classes/class.donatewindow.php');
  33. // core toolbar items
  34. require('classes/class.workspaceselector.php');
  35. require('classes/class.clearcachemenu.php');
  36. require('classes/class.shortcutmenu.php');
  37. require('classes/class.backendsearchmenu.php');
  38. require_once('class.alt_menu_functions.inc');
  39. $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xml');
  40. /**
  41. * Class for rendering the TYPO3 backend version 4.2+
  42. *
  43. * @author Ingo Renner <ingo@typo3.org>
  44. * @package TYPO3
  45. * @subpackage core
  46. */
  47. class TYPO3backend {
  48. protected $content;
  49. protected $css;
  50. protected $cssFiles;
  51. protected $js;
  52. protected $jsFiles;
  53. protected $jsFilesAfterInline;
  54. protected $toolbarItems;
  55. private $menuWidthDefault = 190; // intentionally private as nobody should modify defaults
  56. protected $menuWidth;
  57. /**
  58. * Object for loading backend modules
  59. *
  60. * @var t3lib_loadModules
  61. */
  62. protected $moduleLoader;
  63. /**
  64. * module menu generating object
  65. *
  66. * @var ModuleMenu
  67. */
  68. protected $moduleMenu;
  69. /**
  70. * Pagerenderer
  71. *
  72. * @var t3lib_PageRenderer
  73. */
  74. protected $pageRenderer;
  75. /**
  76. * constructor
  77. *
  78. * @return void
  79. */
  80. public function __construct() {
  81. // Initializes the backend modules structure for use later.
  82. $this->moduleLoader = t3lib_div::makeInstance('t3lib_loadModules');
  83. $this->moduleLoader->load($GLOBALS['TBE_MODULES']);
  84. $this->moduleMenu = t3lib_div::makeInstance('ModuleMenu');
  85. $this->pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
  86. $this->pageRenderer->loadScriptaculous('builder,effects,controls,dragdrop');
  87. $this->pageRenderer->loadExtJS();
  88. // register the extDirect API providers
  89. // Note: we need to iterate thru the object, because the addProvider method
  90. // does this only with multiple arguments
  91. $this->pageRenderer->addExtOnReadyCode(
  92. 'for (var api in Ext.app.ExtDirectAPI) {
  93. Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
  94. }
  95. TYPO3.Backend = new TYPO3.Viewport(TYPO3.Viewport.configuration);
  96. ',
  97. TRUE
  98. );
  99. // add default BE javascript
  100. $this->js = '';
  101. $this->jsFiles = array(
  102. 'contrib/swfupload/swfupload.js',
  103. 'contrib/swfupload/plugins/swfupload.swfobject.js',
  104. 'contrib/swfupload/plugins/swfupload.cookies.js',
  105. 'contrib/swfupload/plugins/swfupload.queue.js',
  106. 'md5.js',
  107. 'js/common.js',
  108. 'js/extjs/backendsizemanager.js',
  109. 'js/toolbarmanager.js',
  110. 'js/modulemenu.js',
  111. 'js/iecompatibility.js',
  112. 'js/flashupload.js',
  113. '../t3lib/jsfunc.evalfield.js',
  114. '../t3lib/js/extjs/ux/flashmessages.js',
  115. '../t3lib/js/extjs/ux/ext.ux.tabclosemenu.js',
  116. 'js/backend.js',
  117. 'js/loginrefresh.js',
  118. 'js/extjs/debugPanel.js',
  119. 'js/extjs/viewport.js',
  120. 'js/extjs/viewportConfiguration.js',
  121. );
  122. // add default BE css
  123. $this->css = '';
  124. $this->cssFiles = array();
  125. $this->toolbarItems = array();
  126. $this->initializeCoreToolbarItems();
  127. $this->menuWidth = $this->menuWidthDefault;
  128. if (isset($GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW']) && (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'] != (int) $this->menuWidth) {
  129. $this->menuWidth = (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'];
  130. }
  131. $this->executeHook('constructPostProcess');
  132. }
  133. /**
  134. * initializes the core toolbar items
  135. *
  136. * @return void
  137. */
  138. protected function initializeCoreToolbarItems() {
  139. $coreToolbarItems = array(
  140. 'workspaceSelector' => 'WorkspaceSelector',
  141. 'shortcuts' => 'ShortcutMenu',
  142. 'clearCacheActions' => 'ClearCacheMenu',
  143. 'backendSearch' => 'BackendSearchMenu'
  144. );
  145. foreach($coreToolbarItems as $toolbarItemName => $toolbarItemClassName) {
  146. $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
  147. if(!($toolbarItem instanceof backend_toolbarItem)) {
  148. throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195126772);
  149. }
  150. if($toolbarItem->checkAccess()) {
  151. $this->toolbarItems[$toolbarItemName] = $toolbarItem;
  152. } else {
  153. unset($toolbarItem);
  154. }
  155. }
  156. }
  157. /**
  158. * main function generating the BE scaffolding
  159. *
  160. * @return void
  161. */
  162. public function render() {
  163. $this->executeHook('renderPreProcess');
  164. if (t3lib_div::makeInstance('DonateWindow')->isDonateWindowAllowed()) {
  165. $this->pageRenderer->addJsFile('js/donate.js');
  166. }
  167. // prepare the scaffolding, at this point extension may still add javascript and css
  168. $logo = t3lib_div::makeInstance('TYPO3Logo');
  169. $logo->setLogo('gfx/typo3logo_mini.png');
  170. $menu = $this->moduleMenu->render();
  171. if ($this->menuWidth != $this->menuWidthDefault) {
  172. $this->css .= '
  173. #typo3-top {
  174. margin-left: ' . $this->menuWidth . 'px;
  175. }
  176. ';
  177. }
  178. // create backend scaffolding
  179. $backendScaffolding = '
  180. <div id="typo3-backend">
  181. <div id="typo3-top-container" class="x-hide-display">
  182. <div id="typo3-logo">'.$logo->render().'</div>
  183. <div id="typo3-top" class="typo3-top-toolbar">' .
  184. $this->renderToolbar() .
  185. '</div>
  186. </div>
  187. <div id="typo3-main-container">
  188. <div id="typo3-side-menu" class="x-hide-display">' .
  189. $menu .
  190. '</div>
  191. <div id="typo3-content" class="x-hide-display">
  192. <iframe src="alt_intro.php" name="content" id="content" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto"></iframe>
  193. </div>
  194. </div>
  195. </div>
  196. ';
  197. /******************************************************
  198. * now put the complete backend document together
  199. ******************************************************/
  200. foreach($this->cssFiles as $cssFileName => $cssFile) {
  201. $this->pageRenderer->addCssFile($cssFile);
  202. // load addditional css files to overwrite existing core styles
  203. if(!empty($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName])) {
  204. $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName]);
  205. }
  206. }
  207. if(!empty($this->css)) {
  208. $this->pageRenderer->addCssInlineBlock('BackendInlineCSS', $this->css);
  209. }
  210. foreach ($this->jsFiles as $jsFile) {
  211. $this->pageRenderer->addJsFile($jsFile);
  212. }
  213. // Those lines can be removed once we have at least one official ExtDirect router within the backend.
  214. $hasExtDirectRouter = FALSE;
  215. if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'])) {
  216. foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'] as $key => $value) {
  217. if (strpos($key, 'TYPO3.Ajax.ExtDirect') !== FALSE) {
  218. $hasExtDirectRouter = TRUE;
  219. break;
  220. }
  221. }
  222. }
  223. if ($hasExtDirectRouter) {
  224. $this->pageRenderer->addJsFile('ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Ajax.ExtDirect', NULL, FALSE);
  225. }
  226. $this->generateJavascript();
  227. $this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js);
  228. // set document title:
  229. $title = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
  230. ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']'
  231. : 'TYPO3 '.TYPO3_version
  232. );
  233. // start page header:
  234. $this->content .= $GLOBALS['TBE_TEMPLATE']->startPage($title);
  235. $this->content .= $backendScaffolding;
  236. $this->content .= $GLOBALS['TBE_TEMPLATE']->endPage();
  237. $hookConfiguration = array('content' => &$this->content);
  238. $this->executeHook('renderPostProcess', $hookConfiguration);
  239. echo $this->content;
  240. }
  241. /**
  242. * renders the items in the top toolbar
  243. *
  244. * @return string top toolbar elements as HTML
  245. */
  246. protected function renderToolbar() {
  247. // move search to last position
  248. $search = $this->toolbarItems['backendSearch'];
  249. unset($this->toolbarItems['backendSearch']);
  250. $this->toolbarItems['backendSearch'] = $search;
  251. $toolbar = '<ul id="typo3-toolbar">';
  252. $toolbar.= '<li>'.$this->getLoggedInUserLabel().'</li>
  253. <li><div id="logout-button" class="toolbar-item no-separator">'.$this->moduleMenu->renderLogoutButton().'</div></li>';
  254. foreach($this->toolbarItems as $toolbarItem) {
  255. $menu = $toolbarItem->render();
  256. if ($menu) {
  257. $additionalAttributes = $toolbarItem->getAdditionalAttributes();
  258. $toolbar .= '<li' . $additionalAttributes . '>' .$menu. '</li>';
  259. }
  260. }
  261. return $toolbar.'</ul>';
  262. }
  263. /**
  264. * Gets the label of the BE user currently logged in
  265. *
  266. * @return string html code snippet displaying the currently logged in user
  267. */
  268. protected function getLoggedInUserLabel() {
  269. global $BE_USER, $BACK_PATH;
  270. $icon = t3lib_iconWorks::getSpriteIcon('status-user-'. ($BE_USER->isAdmin() ? 'admin' : 'backend'));
  271. $label = $GLOBALS['BE_USER']->user['realName'] ?
  272. $BE_USER->user['realName'] . ' (' . $BE_USER->user['username'] . ')' :
  273. $BE_USER->user['username'];
  274. // Link to user setup if it's loaded and user has access
  275. $link = '';
  276. if (t3lib_extMgm::isLoaded('setup') && $BE_USER->check('modules','user_setup')) {
  277. $link = '<a href="#" onclick="top.goToModule(\'user_setup\');this.blur();return false;">';
  278. }
  279. $username = '">'.$link.$icon.'<span>'.htmlspecialchars($label).'</span>'.($link?'</a>':'');
  280. // superuser mode
  281. if($BE_USER->user['ses_backuserid']) {
  282. $username = ' su-user">'.$icon.
  283. '<span title="' . $GLOBALS['LANG']->getLL('switchtouser') . '">' .
  284. $GLOBALS['LANG']->getLL('switchtousershort') . ' </span>' .
  285. '<span>' . htmlspecialchars($label) . '</span>';
  286. }
  287. return '<div id="username" class="toolbar-item no-separator'.$username.'</div>';
  288. }
  289. /**
  290. * Generates the JavaScript code for the backend.
  291. *
  292. * @return void
  293. */
  294. protected function generateJavascript() {
  295. $pathTYPO3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
  296. $goToModuleSwitch = $this->moduleMenu->getGotoModuleJavascript();
  297. $moduleFramesHelper = implode(LF, $this->moduleMenu->getFsMod());
  298. // If another page module was specified, replace the default Page module with the new one
  299. $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
  300. $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
  301. $menuFrameName = 'menu';
  302. if($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
  303. $menuFrameName = 'topmenuFrame';
  304. }
  305. // determine security level from conf vars and default to super challenged
  306. if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
  307. $this->loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
  308. } else {
  309. $this->loginSecurityLevel = 'superchallenged';
  310. }
  311. $t3Configuration = array(
  312. 'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
  313. 'PATH_typo3' => $pathTYPO3,
  314. 'PATH_typo3_enc' => rawurlencode($pathTYPO3),
  315. 'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
  316. 'uniqueID' => t3lib_div::shortMD5(uniqid('')),
  317. 'securityLevel' => $this->loginSecurityLevel,
  318. 'TYPO3_mainDir' => TYPO3_mainDir,
  319. 'pageModule' => $pageModule,
  320. 'condensedMode' => $GLOBALS['BE_USER']->uc['condensedMode'] ? 1 : 0 ,
  321. 'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 0,
  322. 'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
  323. 'veriCode' => $GLOBALS['BE_USER']->veriCode(),
  324. 'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
  325. 'moduleMenuWidth' => $this->menuWidth - 1,
  326. 'topBarHeight' => (isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? intval($GLOBALS['TBE_STYLES']['dims']['topFrameH']) : 30),
  327. 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? intval($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) : FALSE,
  328. );
  329. $t3LLLcore = array(
  330. 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in') ,
  331. 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'),
  332. 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'),
  333. 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
  334. 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'),
  335. 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'),
  336. 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'),
  337. 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'),
  338. 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'),
  339. 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'),
  340. 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'),
  341. 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'),
  342. 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'),
  343. 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'),
  344. 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'),
  345. 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'),
  346. 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'),
  347. 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'),
  348. 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeAll'),
  349. 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeOther'),
  350. 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.close'),
  351. 'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.title'),
  352. 'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.message'),
  353. 'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_donate'),
  354. 'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_disable'),
  355. 'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_postpone'),
  356. );
  357. $t3LLLfileUpload = array(
  358. 'windowTitle' => $GLOBALS['LANG']->getLL('fileUpload_windowTitle'),
  359. 'buttonSelectFiles' => $GLOBALS['LANG']->getLL('fileUpload_buttonSelectFiles'),
  360. 'buttonCancelAll' => $GLOBALS['LANG']->getLL('fileUpload_buttonCancelAll'),
  361. 'infoComponentMaxFileSize' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentMaxFileSize'),
  362. 'infoComponentFileUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileUploadLimit'),
  363. 'infoComponentFileTypeLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileTypeLimit'),
  364. 'infoComponentOverrideFiles' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentOverrideFiles'),
  365. 'processRunning' => $GLOBALS['LANG']->getLL('fileUpload_processRunning'),
  366. 'uploadWait' => $GLOBALS['LANG']->getLL('fileUpload_uploadWait'),
  367. 'uploadStarting' => $GLOBALS['LANG']->getLL('fileUpload_uploadStarting'),
  368. 'uploadProgress' => $GLOBALS['LANG']->getLL('fileUpload_uploadProgress'),
  369. 'uploadSuccess' => $GLOBALS['LANG']->getLL('fileUpload_uploadSuccess'),
  370. 'errorQueueLimitExceeded' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueLimitExceeded'),
  371. 'errorQueueFileSizeLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueFileSizeLimit'),
  372. 'errorQueueZeroByteFile' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueZeroByteFile'),
  373. 'errorQueueInvalidFiletype' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueInvalidFiletype'),
  374. 'errorUploadHttp' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadHttpError'),
  375. 'errorUploadMissingUrl' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadMissingUrl'),
  376. 'errorUploadIO' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadIO'),
  377. 'errorUploadSecurityError' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadSecurityError'),
  378. 'errorUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadLimit'),
  379. 'errorUploadFailed' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFailed'),
  380. 'errorUploadFileIDNotFound' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileIDNotFound'),
  381. 'errorUploadFileValidation' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileValidation'),
  382. 'errorUploadFileCancelled' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileCancelled'),
  383. 'errorUploadStopped' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadStopped'),
  384. 'allErrorMessageTitle' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageTitle'),
  385. 'allErrorMessageText' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageText'),
  386. 'allError401' => $GLOBALS['LANG']->getLL('fileUpload_allError401'),
  387. 'allError2038' => $GLOBALS['LANG']->getLL('fileUpload_allError2038'),
  388. );
  389. // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
  390. if ($GLOBALS['LANG']->charSet !== 'utf-8') {
  391. $t3Configuration['username'] = $GLOBALS['LANG']->csConvObj->conv($t3Configuration['username'], $GLOBALS['LANG']->charSet, 'utf-8');
  392. $GLOBALS['LANG']->csConvObj->convArray($t3LLLcore, $GLOBALS['LANG']->charSet, 'utf-8');
  393. $GLOBALS['LANG']->csConvObj->convArray($t3LLLfileUpload, $GLOBALS['LANG']->charSet, 'utf-8');
  394. }
  395. $this->js .= '
  396. TYPO3.configuration = ' . json_encode($t3Configuration) . ';
  397. TYPO3.LLL = {
  398. core : ' . json_encode($t3LLLcore) . ',
  399. fileUpload: ' . json_encode($t3LLLfileUpload) . '
  400. };
  401. /**
  402. * TypoSetup object.
  403. */
  404. function typoSetup() { //
  405. this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
  406. this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
  407. this.username = TYPO3.configuration.username;
  408. this.uniqueID = TYPO3.configuration.uniqueID;
  409. this.navFrameWidth = 0;
  410. this.securityLevel = TYPO3.configuration.securityLevel;
  411. this.veriCode = TYPO3.configuration.veriCode;
  412. this.denyFileTypes = TYPO3.configuration.denyFileTypes;
  413. }
  414. var TS = new typoSetup();
  415. var currentModuleLoaded = "";
  416. /**
  417. * Frameset Module object
  418. *
  419. * Used in main modules with a frameset for submodules to keep the ID between modules
  420. * Typically that is set by something like this in a Web>* sub module:
  421. * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
  422. * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
  423. */
  424. function fsModules() { //
  425. this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame.
  426. this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time
  427. this.currentMainLoaded="";
  428. this.currentBank="0";
  429. }
  430. var fsMod = new fsModules();' . $moduleFramesHelper . ';';
  431. // add goToModule code
  432. $this->pageRenderer->addExtOnReadyCode('
  433. top.goToModule = ' . $goToModuleSwitch . ';
  434. ');
  435. // Check editing of page:
  436. $this->handlePageEditing();
  437. $this->setStartupModule();
  438. }
  439. /**
  440. * Checking if the "&edit" variable was sent so we can open it for editing the page.
  441. * Code based on code from "alt_shortcut.php"
  442. *
  443. * @return void
  444. */
  445. protected function handlePageEditing() {
  446. if(!t3lib_extMgm::isLoaded('cms')) {
  447. return;
  448. }
  449. // EDIT page:
  450. $editId = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('edit'));
  451. $editRecord = '';
  452. if($editId) {
  453. // Looking up the page to edit, checking permissions:
  454. $where = ' AND ('.$GLOBALS['BE_USER']->getPagePermsClause(2)
  455. .' OR '.$GLOBALS['BE_USER']->getPagePermsClause(16).')';
  456. if(t3lib_div::testInt($editId)) {
  457. $editRecord = t3lib_BEfunc::getRecordWSOL('pages', $editId, '*', $where);
  458. } else {
  459. $records = t3lib_BEfunc::getRecordsByField('pages', 'alias', $editId, $where);
  460. if(is_array($records)) {
  461. reset($records);
  462. $editRecord = current($records);
  463. t3lib_BEfunc::workspaceOL('pages', $editRecord);
  464. }
  465. }
  466. // If the page was accessible, then let the user edit it.
  467. if(is_array($editRecord) && $GLOBALS['BE_USER']->isInWebMount($editRecord['uid'])) {
  468. // Setting JS code to open editing:
  469. $this->js .= '
  470. // Load page to edit:
  471. window.setTimeout("top.loadEditId('.intval($editRecord['uid']).');", 500);
  472. ';
  473. // Checking page edit parameter:
  474. if(!$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
  475. // Expanding page tree:
  476. t3lib_BEfunc::openPageTree(intval($editRecord['pid']), !$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
  477. }
  478. } else {
  479. $this->js .= '
  480. // Warning about page editing:
  481. alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)).');
  482. ';
  483. }
  484. }
  485. }
  486. /**
  487. * Sets the startup module from either GETvars module and mpdParams or user configuration.
  488. *
  489. * @return void
  490. */
  491. protected function setStartupModule() {
  492. $startModule = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('module'));
  493. if(!$startModule) {
  494. if ($GLOBALS['BE_USER']->uc['startModule']) {
  495. $startModule = $GLOBALS['BE_USER']->uc['startModule'];
  496. } else if($GLOBALS['BE_USER']->uc['startInTaskCenter']) {
  497. $startModule = 'user_task';
  498. }
  499. }
  500. $moduleParameters = t3lib_div::_GET('modParams');
  501. if($startModule) {
  502. $this->pageRenderer->addExtOnReadyCode('
  503. // start in module:
  504. function startInModule(modName, cMR_flag, addGetVars) {
  505. Ext.onReady(function() {
  506. top.goToModule(modName, cMR_flag, addGetVars);
  507. });
  508. }
  509. startInModule(\''.$startModule.'\', false, '.t3lib_div::quoteJSvalue($moduleParameters).');
  510. ');
  511. }
  512. }
  513. /**
  514. * generates the code for the TYPO3 logo, either the default TYPO3 logo or a custom one
  515. *
  516. * @return string HTML code snippet to display the TYPO3 logo
  517. */
  518. protected function getLogo() {
  519. $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
  520. '<img'.t3lib_iconWorks::skinImg('','gfx/alt_backend_logo.gif','width="117" height="32"').' title="TYPO3 Content Management Framework" alt="" />'.
  521. '</a>';
  522. // overwrite with custom logo
  523. if($GLOBALS['TBE_STYLES']['logo']) {
  524. if(substr($GLOBALS['TBE_STYLES']['logo'], 0, 3) == '../') {
  525. $imgInfo = @getimagesize(PATH_site.substr($GLOBALS['TBE_STYLES']['logo'], 3));
  526. }
  527. $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
  528. '<img src="'.$GLOBALS['TBE_STYLES']['logo'].'" '.$imgInfo[3].' title="TYPO3 Content Management Framework" alt="" />'.
  529. '</a>';
  530. }
  531. return $logo;
  532. }
  533. /**
  534. * adds a javascript snippet to the backend
  535. *
  536. * @param string javascript snippet
  537. * @return void
  538. */
  539. public function addJavascript($javascript) {
  540. // TODO do we need more checks?
  541. if(!is_string($javascript)) {
  542. throw new InvalidArgumentException('parameter $javascript must be of type string', 1195129553);
  543. }
  544. $this->js .= $javascript;
  545. }
  546. /**
  547. * adds a javscript file to the backend after it has been checked that it exists
  548. *
  549. * @param string javascript file reference
  550. * @return boolean true if the javascript file was successfully added, false otherwise
  551. */
  552. public function addJavascriptFile($javascriptFile) {
  553. $jsFileAdded = false;
  554. //TODO add more checks if neccessary
  555. if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$javascriptFile))) {
  556. $this->jsFiles[] = $javascriptFile;
  557. $jsFileAdded = true;
  558. }
  559. return $jsFileAdded;
  560. }
  561. /**
  562. * adds a css snippet to the backend
  563. *
  564. * @param string css snippet
  565. * @return void
  566. */
  567. public function addCss($css) {
  568. if(!is_string($css)) {
  569. throw new InvalidArgumentException('parameter $css must be of type string', 1195129642);
  570. }
  571. $this->css .= $css;
  572. }
  573. /**
  574. * adds a css file to the backend after it has been checked that it exists
  575. *
  576. * @param string the css file's name with out the .css ending
  577. * @param string css file reference
  578. * @return boolean true if the css file was added, false otherwise
  579. */
  580. public function addCssFile($cssFileName, $cssFile) {
  581. $cssFileAdded = false;
  582. if(empty($this->cssFiles[$cssFileName])) {
  583. $this->cssFiles[$cssFileName] = $cssFile;
  584. $cssFileAdded = true;
  585. }
  586. return $cssFileAdded;
  587. }
  588. /**
  589. * adds an item to the toolbar, the class file for the toolbar item must be loaded at this point
  590. *
  591. * @param string toolbar item name, f.e. tx_toolbarExtension_coolItem
  592. * @param string toolbar item class name, f.e. tx_toolbarExtension_coolItem
  593. * @return void
  594. */
  595. public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
  596. $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
  597. if(!($toolbarItem instanceof backend_toolbarItem)) {
  598. throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195125501);
  599. }
  600. if($toolbarItem->checkAccess()) {
  601. $this->toolbarItems[$toolbarItemName] = $toolbarItem;
  602. } else {
  603. unset($toolbarItem);
  604. }
  605. }
  606. /**
  607. * Executes defined hooks functions for the given identifier.
  608. *
  609. * These hook identifiers are valid:
  610. * + constructPostProcess
  611. * + renderPreProcess
  612. * + renderPostProcess
  613. *
  614. * @param string $identifier Specific hook identifier
  615. * @param array $hookConfiguration Additional configuration passed to hook functions
  616. * @return void
  617. */
  618. protected function executeHook($identifier, array $hookConfiguration = array()) {
  619. $options =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/backend.php'];
  620. if(isset($options[$identifier]) && is_array($options[$identifier])) {
  621. foreach($options[$identifier] as $hookFunction) {
  622. t3lib_div::callUserFunction($hookFunction, $hookConfiguration, $this);
  623. }
  624. }
  625. }
  626. }
  627. // include XCLASS
  628. if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']) {
  629. include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']);
  630. }
  631. // document generation
  632. $TYPO3backend = t3lib_div::makeInstance('TYPO3backend');
  633. // include extensions which may add css, javascript or toolbar items
  634. if(is_array($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'])) {
  635. foreach($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'] as $additionalBackendItem) {
  636. include_once($additionalBackendItem);
  637. }
  638. }
  639. $TYPO3backend->render();
  640. ?>