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