Changed order of cache and shortcut toolbar items
[Packages/TYPO3.CMS.git] / typo3 / backend.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007 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
35 // core toolbar items
36 require('classes/class.workspaceselector.php');
37 require('classes/class.clearcachemenu.php');
38 require('classes/class.shortcutmenu.php');
39 require('classes/class.backendsearchmenu.php');
40
41 require_once(PATH_t3lib.'class.t3lib_loadmodules.php');
42 require_once(PATH_t3lib.'class.t3lib_basicfilefunc.php');
43 require_once('class.alt_menu_functions.inc');
44 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xml');
45
46
47 /**
48 * Class for rendering the TYPO3 backend version 4.2+
49 *
50 * @author Ingo Renner <ingo@typo3.org>
51 * @package TYPO3
52 * @subpackage core
53 */
54 class TYPO3backend {
55
56 protected $content;
57 protected $css;
58 protected $cssFiles;
59 protected $js;
60 protected $jsFiles;
61 protected $toolbarItems;
62 private $menuWithDefault = 160; // intentionally private as nobody should modify defaults
63 protected $menuWith;
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 * constructor
81 *
82 * @return void
83 */
84 public function __construct() {
85 // Initializes the backend modules structure for use later.
86 $this->moduleLoader = t3lib_div::makeInstance('t3lib_loadModules');
87 $this->moduleLoader->load($GLOBALS['TBE_MODULES']);
88
89 $this->moduleMenu = t3lib_div::makeInstance('ModuleMenu');
90
91 // add default BE javascript
92 $this->js = '';
93 $this->jsFiles = array(
94 'contrib/prototype/prototype.js',
95 'contrib/scriptaculous/scriptaculous.js?load=builder,effects,controls,dragdrop',
96 'md5.js',
97 'js/backend.js',
98 'js/common.js',
99 'js/sizemanager.js',
100 'js/toolbarmanager.js',
101 'js/modulemenu.js',
102 'js/iecompatibility.js',
103 '../t3lib/jsfunc.evalfield.js'
104 );
105
106 // add default BE css
107 $this->css = '';
108 $this->cssFiles = array(
109 'backend-scaffolding' => 'css/backend-scaffolding.css',
110 'backend-style' => 'css/backend-style.css',
111 'modulemenu' => 'css/modulemenu.css'
112 );
113
114 $this->toolbarItems = array();
115 $this->initializeCoreToolbarItems();
116
117 $this->menuWith = $this->menuWithDefault;
118 if (isset($GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW']) && $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'] != (int) $this->menuWith) {
119 $this->menuWith = $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'];
120 }
121 }
122
123 /**
124 * initializes the core toolbar items
125 *
126 * @return void
127 */
128 protected function initializeCoreToolbarItems() {
129
130 $coreToolbarItems = array(
131 'workspaceSelector' => 'WorkspaceSelector',
132 'shortcuts' => 'ShortcutMenu',
133 'clearCacheActions' => 'ClearCacheMenu',
134 'backendSearch' => 'BackendSearchMenu'
135 );
136
137 foreach($coreToolbarItems as $toolbarItemName => $toolbarItemClassName) {
138 // Get name of XCLASS (if any):
139 $toolbarItemClassName = t3lib_div::makeInstanceClassName($toolbarItemClassName);
140 $toolbarItem = new $toolbarItemClassName($this);
141
142 if(!($toolbarItem instanceof backend_toolbarItem)) {
143 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195126772);
144 }
145
146 if($toolbarItem->checkAccess()) {
147 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
148 } else {
149 unset($toolbarItem);
150 }
151 }
152 }
153
154 /**
155 * main function generating the BE scaffolding
156 *
157 * @return void
158 */
159 public function render() {
160
161 // prepare the scaffolding, at this point extension may still add javascript and css
162 $logo = t3lib_div::makeInstance('TYPO3Logo');
163 $logo->setLogo('gfx/typo3logo_mini.png');
164
165 $menu = $this->moduleMenu->render();
166
167 if ($this->menuWith != $this->menuWithDefault) {
168 $this->css .= '
169 #typo3-logo,
170 #typo3-side-menu {
171 width: ' . ($this->menuWith - 1) . 'px;
172 }
173
174 #typo3-top,
175 #typo3-content {
176 margin-left: ' . $this->menuWith . 'px;
177 }
178 ';
179 }
180
181 // create backend scaffolding
182 $backendScaffolding = '
183 <div id="typo3-backend">
184 <div id="typo3-top-container">
185 <div id="typo3-logo">'.$logo->render().'</div>
186 <div id="typo3-top" class="typo3-top-toolbar">'
187 .$this->renderToolbar()
188 .'</div>
189 </div>
190 <div id="typo3-main-container">
191 <div id="typo3-side-menu">
192 '.$menu.'
193 </div>
194 <div id="typo3-content">
195 <iframe src="alt_intro.php" name="content" id="content" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" noresize="noresize"></iframe>
196 </div>
197 </div>
198 </div>
199 ';
200
201 /******************************************************
202 * now put the complete backend document together
203 ******************************************************/
204
205 // set doctype
206 $GLOBALS['TBE_TEMPLATE']->docType = 'xhtml_trans';
207
208 // add javascript
209 foreach($this->jsFiles as $jsFile) {
210 $GLOBALS['TBE_TEMPLATE']->JScode .= '
211 <script type="text/javascript" src="'.$jsFile.'"></script>';
212 }
213 $GLOBALS['TBE_TEMPLATE']->JScode .= chr(10);
214 $this->generateJavascript();
215 $GLOBALS['TBE_TEMPLATE']->JScode .= $GLOBALS['TBE_TEMPLATE']->wrapScriptTags($this->js);
216
217 // FIXME abusing the JS container to add CSS, need to fix template.php
218 foreach($this->cssFiles as $cssFileName => $cssFile) {
219 $GLOBALS['TBE_TEMPLATE']->JScode .= '
220 <link rel="stylesheet" type="text/css" href="'.$cssFile.'" />
221 ';
222
223 // load addditional css files to overwrite existing core styles
224 if(!empty($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName])) {
225 $GLOBALS['TBE_TEMPLATE']->JScode .= '
226 <link rel="stylesheet" type="text/css" href="'.$GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName].'" />
227 ';
228 }
229 }
230
231 if(!empty($this->css)) {
232 $GLOBALS['TBE_TEMPLATE']->JScode .= '
233 <style type="text/css" id="internalStyle">
234 '.$this->css.'
235 </style>';
236 }
237
238 // set document title:
239 $title = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
240 ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']'
241 : 'TYPO3 '.TYPO3_version
242 );
243
244 // start page header:
245 $this->content .= $GLOBALS['TBE_TEMPLATE']->startPage($title);
246 $this->content .= $backendScaffolding;
247 $this->content .= $GLOBALS['TBE_TEMPLATE']->endPage();
248
249 echo $this->content;
250 }
251
252 /**
253 * renders the items in the top toolbar
254 *
255 * @return string top toolbar elements as HTML
256 */
257 protected function renderToolbar() {
258 $toolbar = '<ul id="typo3-toolbar">';
259 $toolbar.= '<li>'.$this->getLoggedInUserLabel().'</li>
260 <li><div id="logout-button" class="toolbar-item no-separator">'.$this->moduleMenu->renderLogoutButton().'</div></li>';
261
262 foreach($this->toolbarItems as $toolbarItem) {
263 $additionalAttributes = $toolbarItem->getAdditionalAttributes();
264
265 $toolbar .= '<li'.$additionalAttributes.'>'.$toolbarItem->render().'</li>';
266 }
267
268 return $toolbar.'</ul>';
269 }
270
271 /**
272 * gets the label of the currently loged in BE user
273 *
274 * @return string html code snippet displaying the currently logged in user
275 */
276 protected function getLoggedInUserLabel() {
277 global $BE_USER, $BACK_PATH;
278
279 $icon = '<img'.t3lib_iconWorks::skinImg(
280 '',
281 $BE_USER->isAdmin() ?
282 'gfx/i/be_users_admin.gif' :
283 'gfx/i/be_users.gif',
284 'width="18" height="16"'
285 )
286 .' title="" alt="" />';
287
288 $label = $GLOBALS['BE_USER']->user['realName'] ?
289 $BE_USER->user['realName'].' ['.$BE_USER->user['username'].']' :
290 $BE_USER->user['username'];
291
292 // Link to user setup if it's loaded and user has access
293 $link = '';
294 if (t3lib_extMgm::isLoaded('setup') && $BE_USER->check('modules','user_setup')) {
295 $link = '<a href="#" onclick="top.goToModule(\'user_setup\');this.blur();return false;">';
296 }
297
298 $username = '">'.$link.$icon.'<span>'.htmlspecialchars($label).'</span>'.($link?'</a>':'');
299
300 // superuser mode
301 if($BE_USER->user['ses_backuserid']) {
302 $username = ' su-user">'.$icon.
303 '<span title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:switchtouser').'">SU: </span>'.
304 '<span>'.htmlspecialchars($label).'</span>';
305 }
306
307 return '<div id="username" class="toolbar-item no-separator'.$username.'</div>';
308 }
309
310 /**
311 * Generates the JavaScript code for the backend.
312 *
313 * @return void
314 */
315 protected function generateJavascript() {
316
317 $pathTYPO3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
318 $goToModuleSwitch = $this->moduleMenu->getGotoModuleJavascript();
319 $moduleFramesHelper = implode(chr(10), $this->moduleMenu->getFsMod());
320
321 // If another page module was specified, replace the default Page module with the new one
322 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
323 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
324
325 $menuFrameName = 'menu';
326 if($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
327 $menuFrameName = 'topmenuFrame';
328 }
329
330 $this->js .= '
331 /**
332 * Function similar to PHPs rawurlencode();
333 */
334 function rawurlencode(str) { //
335 var output = escape(str);
336 output = str_replace("*","%2A", output);
337 output = str_replace("+","%2B", output);
338 output = str_replace("/","%2F", output);
339 output = str_replace("@","%40", output);
340 return output;
341 }
342
343 /**
344 * String-replace function
345 */
346 function str_replace(match,replace,string) { //
347 var input = ""+string;
348 var matchStr = ""+match;
349 if (!matchStr) {return string;}
350 var output = "";
351 var pointer=0;
352 var pos = input.indexOf(matchStr);
353 while (pos!=-1) {
354 output+=""+input.substr(pointer, pos-pointer)+replace;
355 pointer=pos+matchStr.length;
356 pos = input.indexOf(match,pos+1);
357 }
358 output+=""+input.substr(pointer);
359 return output;
360 }
361
362 /**
363 * TypoSetup object.
364 */
365 function typoSetup() { //
366 this.PATH_typo3 = "'.$pathTYPO3.'";
367 this.PATH_typo3_enc = "'.rawurlencode($pathTYPO3).'";
368 this.username = "'.$GLOBALS['BE_USER']->user['username'].'";
369 this.uniqueID = "'.t3lib_div::shortMD5(uniqid('')).'";
370 this.navFrameWidth = 0;
371 }
372 var TS = new typoSetup();
373
374 /**
375 * Functions for session-expiry detection:
376 */
377 function busy() { //
378 this.loginRefreshed = busy_loginRefreshed;
379 this.checkLoginTimeout = busy_checkLoginTimeout;
380 this.openRefreshWindow = busy_OpenRefreshWindow;
381 this.busyloadTime=0;
382 this.openRefreshW=0;
383 this.reloginCancelled=0;
384 }
385 function busy_loginRefreshed() { //
386 var date = new Date();
387 this.busyloadTime = Math.floor(date.getTime()/1000);
388 this.openRefreshW=0;
389 }
390 function busy_checkLoginTimeout() { //
391 var date = new Date();
392 var theTime = Math.floor(date.getTime()/1000);
393 if (theTime > this.busyloadTime+'.intval($GLOBALS['BE_USER']->auth_timeout_field).'-30) {
394 return true;
395 }
396 }
397 function busy_OpenRefreshWindow() { //
398 vHWin=window.open("login_frameset.php","relogin_"+TS.uniqueID,"height=350,width=700,status=0,menubar=0,location=1");
399 vHWin.focus();
400 this.openRefreshW=1;
401 }
402 function busy_checkLoginTimeout_timer() { //
403 if (busy.checkLoginTimeout() && !busy.reloginCancelled && !busy.openRefreshW) {
404 if (confirm('.$GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login')).')) {
405 busy.openRefreshWindow();
406 } else {
407 busy.reloginCancelled = 1;
408 }
409 }
410 window.setTimeout("busy_checkLoginTimeout_timer();",2*1000); // Each 2nd second is enough for checking. The popup will be triggered 10 seconds before the login expires (see above, busy_checkLoginTimeout())
411
412 // Detecting the frameset module navigation frame widths (do this AFTER setting new timeout so that any errors in the code below does not prevent another time to be set!)
413 if (top && top.content && top.content.nav_frame && top.content.nav_frame.document && top.content.nav_frame.document.body) {
414 TS.navFrameWidth = (top.content.nav_frame.document.documentElement && top.content.nav_frame.document.documentElement.clientWidth) ? top.content.nav_frame.document.documentElement.clientWidth : top.content.nav_frame.document.body.clientWidth;
415 }
416 }
417
418 /**
419 * Launcing information window for records/files (fileref as "table" argument)
420 */
421 function launchView(table,uid,bP) { //
422 var backPath= bP ? bP : "";
423 var thePreviewWindow="";
424 thePreviewWindow = window.open(TS.PATH_typo3+"show_item.php?table="+encodeURIComponent(table)+"&uid="+encodeURIComponent(uid),"ShowItem"+TS.uniqueID,"height=400,width=550,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
425 if (thePreviewWindow && thePreviewWindow.focus) {
426 thePreviewWindow.focus();
427 }
428 }
429
430 /**
431 * Opens plain window with url
432 */
433 function openUrlInWindow(url,windowName) { //
434 regularWindow = window.open(url,windowName,"status=1,menubar=1,resizable=1,location=1,directories=0,scrollbars=1,toolbar=1");
435 regularWindow.focus();
436 return false;
437 }
438
439 /**
440 * Loads a page id for editing in the page edit module:
441 */
442 function loadEditId(id,addGetVars) { //
443 top.fsMod.recentIds["web"]=id;
444 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_0"; // For highlighting
445
446 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
447 top.content.nav_frame.refresh_nav();
448 }
449
450 top.goToModule("'.$pageModule.'", 0, addGetVars?addGetVars:"");
451 }
452
453 /**
454 * Returns incoming URL (to a module) unless nextLoadModuleUrl is set. If that is the case nextLoadModuleUrl is returned (and cleared)
455 * Used by the shortcut frame to set a "intermediate URL"
456 */
457 var nextLoadModuleUrl="";
458 function getModuleUrl(inUrl) { //
459 var nMU;
460 if (top.nextLoadModuleUrl) {
461 nMU=top.nextLoadModuleUrl;
462 top.nextLoadModuleUrl="";
463 return nMU;
464 } else {
465 return inUrl;
466 }
467 }
468
469 /**
470 * Print properties of an object
471 */
472 function debugObj(obj,name) { //
473 var acc;
474 for (i in obj) {
475 if (obj[i]) {
476 acc+=i+": "+obj[i]+"\n";
477 }
478 }
479 alert("Object: "+name+"\n\n"+acc);
480 }
481
482 /**
483 * Initialize login expiration warning object
484 */
485 var busy = new busy();
486 busy.loginRefreshed();
487 busy_checkLoginTimeout_timer();
488
489 /**
490 * Function used to switch modules
491 */
492 var currentModuleLoaded = "";
493 var goToModule = '.$goToModuleSwitch.'
494
495 /**
496 * Frameset Module object
497 *
498 * Used in main modules with a frameset for submodules to keep the ID between modules
499 * Typically that is set by something like this in a Web>* sub module:
500 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
501 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
502 */
503 function fsModules() { //
504 this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame.
505 this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time
506 this.currentMainLoaded="";
507 this.currentBank="0";
508 }
509 var fsMod = new fsModules();
510 '.$moduleFramesHelper.'
511
512 // Used by Frameset Modules
513 var condensedMode = '.($GLOBALS['BE_USER']->uc['condensedMode']?1:0).';
514 var currentSubScript = "";
515 var currentSubNavScript = "";
516
517 // Used for tab-panels:
518 var DTM_currentTabs = new Array();
519 ';
520
521 // Check editing of page:
522 $this->handlePageEditing();
523 $this->setStartupModule();
524 }
525
526 /**
527 * Checking if the "&edit" variable was sent so we can open it for editing the page.
528 * Code based on code from "alt_shortcut.php"
529 *
530 * @return void
531 */
532 protected function handlePageEditing() {
533
534 if(!t3lib_extMgm::isLoaded('cms')) {
535 return;
536 }
537
538 // EDIT page:
539 $editId = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('edit'));
540 $editRecord = '';
541
542 if($editId) {
543
544 // Looking up the page to edit, checking permissions:
545 $where = ' AND ('.$GLOBALS['BE_USER']->getPagePermsClause(2)
546 .' OR '.$GLOBALS['BE_USER']->getPagePermsClause(16).')';
547
548 if(t3lib_div::testInt($editId)) {
549 $editRecord = t3lib_BEfunc::getRecordWSOL('pages', $editId, '*', $where);
550 } else {
551 $records = t3lib_BEfunc::getRecordsByField('pages', 'alias', $editId, $where);
552
553 if(is_array($records)) {
554 reset($records);
555 $editRecord = current($records);
556 t3lib_BEfunc::workspaceOL('pages', $editRecord);
557 }
558 }
559
560 // If the page was accessible, then let the user edit it.
561 if(is_array($editRecord) && $GLOBALS['BE_USER']->isInWebMount($editRecord['uid'])) {
562 // Setting JS code to open editing:
563 $this->js .= '
564 // Load page to edit:
565 window.setTimeout("top.loadEditId('.intval($editRecord['uid']).');", 500);
566 ';
567 // Checking page edit parameter:
568 if(!$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
569
570 // Expanding page tree:
571 t3lib_BEfunc::openPageTree(intval($editRecord['pid']), !$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
572 }
573 } else {
574 $this->js .= '
575 // Warning about page editing:
576 alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)).');
577 ';
578 }
579 }
580 }
581
582 /**
583 * Sets the startup module from either GETvars module and mpdParams or user configuration.
584 *
585 * @return void
586 */
587 protected function setStartupModule() {
588 $startModule = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('module'));
589
590 if(!$startModule) {
591 if ($GLOBALS['BE_USER']->uc['startModule']) {
592 $startModule = $GLOBALS['BE_USER']->uc['startModule'];
593 } else if($GLOBALS['BE_USER']->uc['startInTaskCenter']) {
594 $startModule = 'user_task';
595 }
596 }
597
598 $moduleParameters = t3lib_div::_GET('modParams');
599 if($startModule) {
600 $this->js .= '
601 // start in module:
602 function startInModule(modName, cMR_flag, addGetVars) {
603 Event.observe(document, \'dom:loaded\', function() {
604 top.goToModule(modName, cMR_flag, addGetVars);
605 });
606 }
607
608 startInModule(\''.$startModule.'\', false, \''.$moduleParameters.'\');
609 ';
610 }
611 }
612
613 /**
614 * generates the code for the TYPO3 logo, either the default TYPO3 logo or a custom one
615 *
616 * @return string HTML code snippet to display the TYPO3 logo
617 */
618 protected function getLogo() {
619 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
620 '<img'.t3lib_iconWorks::skinImg('','gfx/alt_backend_logo.gif','width="117" height="32"').' title="TYPO3 Content Management Framework" alt="" />'.
621 '</a>';
622
623 // overwrite with custom logo
624 if($GLOBALS['TBE_STYLES']['logo']) {
625 if(substr($GLOBALS['TBE_STYLES']['logo'], 0, 3) == '../') {
626 $imgInfo = @getimagesize(PATH_site.substr($GLOBALS['TBE_STYLES']['logo'], 3));
627 }
628 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
629 '<img src="'.$GLOBALS['TBE_STYLES']['logo'].'" '.$imgInfo[3].' title="TYPO3 Content Management Framework" alt="" />'.
630 '</a>';
631 }
632
633 return $logo;
634 }
635
636 /**
637 * adds a javascript snippet to the backend
638 *
639 * @param string javascript snippet
640 * @return void
641 */
642 public function addJavascript($javascript) {
643 // TODO do we need more checks?
644 if(!is_string($javascript)) {
645 throw new InvalidArgumentException('parameter $javascript must be of type string', 1195129553);
646 }
647
648 $this->js .= $javascript;
649 }
650
651 /**
652 * adds a javscript file to the backend after it has been checked that it exists
653 *
654 * @param string javascript file reference
655 * @return boolean true if the javascript file was successfully added, false otherwise
656 */
657 public function addJavascriptFile($javascriptFile) {
658 $jsFileAdded = false;
659
660 //TODO add more checks if neccessary
661 if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$javascriptFile))) {
662 $this->jsFiles[] = $javascriptFile;
663 $jsFileAdded = true;
664 }
665
666 return $jsFileAdded;
667 }
668
669 /**
670 * adds a css snippet to the backend
671 *
672 * @param string css snippet
673 * @return void
674 */
675 public function addCss($css) {
676 if(!is_string($css)) {
677 throw new InvalidArgumentException('parameter $css must be of type string', 1195129642);
678 }
679
680 $this->css .= $css;
681 }
682
683 /**
684 * adds a css file to the backend after it has been checked that it exists
685 *
686 * @param string the css file's name with out the .css ending
687 * @param string css file reference
688 * @return boolean true if the css file was added, false otherwise
689 */
690 public function addCssFile($cssFileName, $cssFile) {
691 $cssFileAdded = false;
692
693 //TODO add more checks if neccessary
694 if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$cssFile))) {
695 // prevent overwriting existing css files
696 if(empty($this->cssFiles[$cssFileName])) {
697 $this->cssFiles[$cssFileName] = $cssFile;
698 $cssFileAdded = true;
699 }
700 }
701
702 return $cssFileAdded;
703 }
704
705 /**
706 * adds an item to the toolbar, the class file for the toolbar item must be loaded at this point
707 *
708 * @param string toolbar item name, f.e. tx_toolbarExtension_coolItem
709 * @param string toolbar item class name, f.e. tx_toolbarExtension_coolItem
710 * @return void
711 */
712 public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
713 $toolbarItemResolvedClassName = t3lib_div::makeInstanceClassName($toolbarItemClassName);
714 $toolbarItem = new $toolbarItemResolvedClassName($this);
715
716 if(!($toolbarItem instanceof backend_toolbarItem)) {
717 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195125501);
718 }
719
720 if($toolbarItem->checkAccess()) {
721 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
722 } else {
723 unset($toolbarItem);
724 }
725 }
726 }
727
728
729 // include XCLASS
730 if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']) {
731 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']);
732 }
733
734
735 // document generation
736 $TYPO3backend = t3lib_div::makeInstance('TYPO3backend');
737
738 // include extensions which may add css, javascript or toolbar items
739 if(is_array($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'])) {
740 foreach($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'] as $additionalBackendItem) {
741 include_once($additionalBackendItem);
742 }
743 }
744
745 $TYPO3backend->render();
746
747 ?>