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