added feature #7161: create a shortcut manager to delegate calls to create a new...
[Packages/TYPO3.CMS.git] / typo3 / alt_main.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
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 * Main frameset of the TYPO3 backend
29 * Sending the GET var "alt_main.php?edit=[page id]" will load the page id in the editing module configured.
30 *
31 * $Id$
32 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
33 * XHTML Compliant (almost)
34 *
35 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
36 */
37 /**
38 * [CLASS/FUNCTION INDEX of SCRIPT]
39 *
40 *
41 *
42 * 72: class SC_alt_main
43 * 91: function init()
44 * 113: function generateJScode()
45 * 386: function editPageHandling()
46 * 437: function startModule()
47 * 459: function main()
48 * 533: function printContent()
49 *
50 * TOTAL FUNCTIONS: 6
51 * (This index is automatically created/updated by the extension "extdeveval")
52 *
53 */
54
55 require ('init.php');
56 require ('template.php');
57 require_once (PATH_t3lib.'class.t3lib_loadmodules.php');
58 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
59 require_once ('class.alt_menu_functions.inc');
60 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
61
62
63
64
65 /**
66 * Script Class for rendering of the main frameset for the TYPO3 backend.
67 *
68 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
69 * @package TYPO3
70 * @subpackage core
71 */
72 class SC_alt_main {
73
74 // Internal, dynamic:
75 var $content;
76 var $mainJScode;
77
78 /**
79 * Object for backend modules, load modules-object
80 *
81 * @var t3lib_loadModules
82 */
83 var $loadModules; // Load modules-object
84
85 /**
86 * Menu functions object
87 *
88 * @var alt_menu_functions
89 */
90 var $alt_menuObj; // Menu functions object.
91
92 // Internal, static:
93 var $leftMenuFrameW = 130;
94 var $selMenuFrame = 130;
95 var $topFrameH = 32;
96 var $shortcutFrameH = 30;
97
98 /**
99 * Initialization of the script class
100 *
101 * @return void
102 */
103 function init() {
104 global $TBE_MODULES,$TBE_STYLES;
105
106 // Initializes the backend modules structure for use later.
107 $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
108 $this->loadModules->load($TBE_MODULES);
109
110 // Instantiates the menu object which will generate some JavaScript for the goToModule() JS function in this frameset.
111 $this->alt_menuObj = t3lib_div::makeInstance('alt_menu_functions');
112
113 // Check for distances defined in the styles array:
114 if ($TBE_STYLES['dims']['leftMenuFrameW']) $this->leftMenuFrameW = $TBE_STYLES['dims']['leftMenuFrameW'];
115 if ($TBE_STYLES['dims']['topFrameH']) $this->topFrameH = $TBE_STYLES['dims']['topFrameH'];
116 if ($TBE_STYLES['dims']['shortcutFrameH']) $this->shortcutFrameH = $TBE_STYLES['dims']['shortcutFrameH'];
117 if ($TBE_STYLES['dims']['selMenuFrame']) $this->selMenuFrame = $TBE_STYLES['dims']['selMenuFrame'];
118 }
119
120 /**
121 * Generates the JavaScript code for the frameset.
122 *
123 * @return void
124 */
125 function generateJScode() {
126 global $BE_USER,$LANG;
127
128 $pt3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
129 $goToModule_switch = $this->alt_menuObj->topMenu($this->loadModules->modules,0,"",4);
130 $fsMod = implode(chr(10),$this->alt_menuObj->fsMod);
131
132 // If another page module was specified, replace the default Page module with the new one
133 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
134 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
135
136 $menuFrameName = 'menu';
137 if ($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
138 $menuFrameName = 'topmenuFrame';
139 }
140
141 $this->mainJScode='
142 /**
143 * Function similar to PHPs rawurlencode();
144 */
145 function rawurlencode(str) { //
146 var output = escape(str);
147 output = str_replace("*","%2A", output);
148 output = str_replace("+","%2B", output);
149 output = str_replace("/","%2F", output);
150 output = str_replace("@","%40", output);
151 return output;
152 }
153
154 /**
155 * String-replace function
156 */
157 function str_replace(match,replace,string) { //
158 var input = ""+string;
159 var matchStr = ""+match;
160 if (!matchStr) {return string;}
161 var output = "";
162 var pointer=0;
163 var pos = input.indexOf(matchStr);
164 while (pos!=-1) {
165 output+=""+input.substr(pointer, pos-pointer)+replace;
166 pointer=pos+matchStr.length;
167 pos = input.indexOf(match,pos+1);
168 }
169 output+=""+input.substr(pointer);
170 return output;
171 }
172
173 /**
174 * TypoSetup object.
175 */
176 function typoSetup() { //
177 this.PATH_typo3 = "'.$pt3.'";
178 this.PATH_typo3_enc = "'.rawurlencode($pt3).'";
179 this.username = "'.$BE_USER->user['username'].'";
180 this.uniqueID = "'.t3lib_div::shortMD5(uniqid('')).'";
181 this.navFrameWidth = 0;
182 }
183 var TS = new typoSetup();
184
185 /**
186 * Functions for session-expiry detection:
187 */
188 function busy() { //
189 this.loginRefreshed = busy_loginRefreshed;
190 this.checkLoginTimeout = busy_checkLoginTimeout;
191 this.openRefreshWindow = busy_OpenRefreshWindow;
192 this.busyloadTime=0;
193 this.openRefreshW=0;
194 this.reloginCancelled=0;
195 }
196 function busy_loginRefreshed() { //
197 var date = new Date();
198 this.busyloadTime = Math.floor(date.getTime()/1000);
199 this.openRefreshW=0;
200 }
201 function busy_checkLoginTimeout() { //
202 var date = new Date();
203 var theTime = Math.floor(date.getTime()/1000);
204 if (theTime > this.busyloadTime+'.intval($BE_USER->auth_timeout_field).'-30) {
205 return true;
206 }
207 }
208 function busy_OpenRefreshWindow() { //
209 vHWin=window.open("login_frameset.php","relogin_"+TS.uniqueID,"height=350,width=700,status=0,menubar=0,location=1");
210 vHWin.focus();
211 this.openRefreshW=1;
212 }
213 function busy_checkLoginTimeout_timer() { //
214 if (busy.checkLoginTimeout() && !busy.reloginCancelled && !busy.openRefreshW) {
215 if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login')).')) {
216 busy.openRefreshWindow();
217 } else {
218 busy.reloginCancelled = 1;
219 }
220 }
221 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())
222
223 // 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!)
224 if (top && top.content && top.content.nav_frame && top.content.nav_frame.document && top.content.nav_frame.document.body) {
225 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;
226 }
227 }
228
229 /**
230 * Launcing information window for records/files (fileref as "table" argument)
231 */
232 function launchView(table,uid,bP) { //
233 var backPath= bP ? bP : "";
234 var thePreviewWindow="";
235 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");
236 if (thePreviewWindow && thePreviewWindow.focus) {
237 thePreviewWindow.focus();
238 }
239 }
240
241 /**
242 * Opens plain window with url
243 */
244 function openUrlInWindow(url,windowName) { //
245 regularWindow = window.open(url,windowName,"status=1,menubar=1,resizable=1,location=1,directories=0,scrollbars=1,toolbar=1");
246 regularWindow.focus();
247 return false;
248 }
249
250 /**
251 * Loads a URL in the topmenuFrame
252 */
253 function loadTopMenu(url) { //
254 top.topmenuFrame.location = url;
255 }
256
257 /**
258 * Loads a page id for editing in the page edit module:
259 */
260 function loadEditId(id,addGetVars) { //
261 top.fsMod.recentIds["web"]=id;
262 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_0"; // For highlighting
263
264 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
265 top.content.nav_frame.refresh_nav();
266 }
267
268 top.goToModule("'.$pageModule.'", 0, addGetVars?addGetVars:"");
269 }
270
271 /**
272 * Returns incoming URL (to a module) unless nextLoadModuleUrl is set. If that is the case nextLoadModuleUrl is returned (and cleared)
273 * Used by the shortcut frame to set a "intermediate URL"
274 */
275 var nextLoadModuleUrl="";
276 function getModuleUrl(inUrl) { //
277 var nMU;
278 if (top.nextLoadModuleUrl) {
279 nMU=top.nextLoadModuleUrl;
280 top.nextLoadModuleUrl="";
281 return nMU;
282 } else {
283 return inUrl;
284 }
285 }
286
287 /**
288 * Print properties of an object
289 */
290 function debugObj(obj,name) { //
291 var acc;
292 for (i in obj) {
293 if (obj[i]) {
294 acc+=i+": "+obj[i]+"\n";
295 }
296 }
297 alert("Object: "+name+"\n\n"+acc);
298 }
299
300 /**
301 * Initialize login expiration warning object
302 */
303 var busy = new busy();
304 busy.loginRefreshed();
305 busy_checkLoginTimeout_timer();
306
307
308 /**
309 * Highlight module:
310 */
311 var currentlyHighLightedId = "";
312 var currentlyHighLighted_restoreValue = "";
313 var currentlyHighLightedMain = "";
314 function highlightModuleMenuItem(trId, mainModule) { //
315 currentlyHighLightedMain = mainModule;
316 // Get document object:
317 if (top.menu && top.menu.document) {
318 var docObj = top.menu.document;
319 var HLclass = mainModule ? "c-mainitem-HL" : "c-subitem-row-HL";
320 } else if (top.topmenuFrame && top.topmenuFrame.document) {
321 var docObj = top.topmenuFrame.document;
322 var HLclass = mainModule ? "c-mainitem-HL" : "c-subitem-HL";
323 }
324
325 if (docObj) {
326 // Reset old:
327 if (currentlyHighLightedId && docObj.getElementById(currentlyHighLightedId)) {
328 docObj.getElementById(currentlyHighLightedId).attributes.getNamedItem("class").nodeValue = currentlyHighLighted_restoreValue;
329 }
330 // Set new:
331 currentlyHighLightedId = trId;
332 if (currentlyHighLightedId && docObj.getElementById(currentlyHighLightedId)) {
333 var classAttribObject = docObj.getElementById(currentlyHighLightedId).attributes.getNamedItem("class");
334 currentlyHighLighted_restoreValue = classAttribObject.nodeValue;
335 classAttribObject.nodeValue = HLclass;
336 }
337 }
338 }
339
340 /**
341 * Function restoring previous selection in left menu after clearing cache
342 */
343 function restoreHighlightedModuleMenuItem() { //
344 if (currentlyHighLightedId) {
345 highlightModuleMenuItem(currentlyHighLightedId,currentlyHighLightedMain);
346 }
347 }
348
349 /**
350 * Wrapper for the actual goToModule function in the menu frame
351 */
352 var currentModuleLoaded = "";
353 function goToModule(modName, cMR_flag, addGetVars) { //
354 if (top.'.$menuFrameName.' && top.'.$menuFrameName.'.goToModule) {
355 currentModuleLoaded = modName;
356 top.'.$menuFrameName.'.goToModule(modName, cMR_flag, addGetVars);
357 } else {
358 window.setTimeout(function() { top.goToModule(modName, cMR_flag, addGetVars); }, 500);
359 }
360 }
361
362 /**
363 * reloads the menu frame
364 */
365 function refreshMenu() {
366 top.'.$menuFrameName.'.location.href = top.'.$menuFrameName.'.document.URL
367 }
368
369 /**
370 * Frameset Module object
371 *
372 * Used in main modules with a frameset for submodules to keep the ID between modules
373 * Typically that is set by something like this in a Web>* sub module:
374 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
375 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
376 */
377 function fsModules() { //
378 this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame.
379 this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time
380 this.currentMainLoaded="";
381 this.currentBank="0";
382 }
383 var fsMod = new fsModules();
384 '.$fsMod.'
385
386 // Used by Frameset Modules
387 var condensedMode = '.($BE_USER->uc['condensedMode']?1:0).';
388 var currentSubScript = "";
389 var currentSubNavScript = "";
390
391 // Used for tab-panels:
392 var DTM_currentTabs = new Array();
393 ';
394
395 // Check editing of page:
396 $this->editPageHandling();
397 $this->startModule();
398 }
399
400 /**
401 * Checking if the "&edit" variable was sent so we can open for editing the page.
402 * Code based on code from "alt_shortcut.php"
403 *
404 * @return void
405 */
406 function editPageHandling() {
407 global $BE_USER;
408
409 if (!t3lib_extMgm::isLoaded('cms')) return;
410
411 // EDIT page:
412 $editId = preg_replace('/[^[:alnum:]_]/','',t3lib_div::_GET('edit'));
413 $theEditRec = '';
414
415 if ($editId) {
416
417 // Looking up the page to edit, checking permissions:
418 $where = ' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
419 if (t3lib_div::testInt($editId)) {
420 $theEditRec = t3lib_BEfunc::getRecordWSOL('pages',$editId,'*',$where);
421 } else {
422 $records = t3lib_BEfunc::getRecordsByField('pages','alias',$editId,$where);
423 if (is_array($records)) {
424 reset($records);
425 $theEditRec = current($records);
426 t3lib_BEfunc::workspaceOL('pages', $theEditRec);
427 }
428 }
429
430 // If the page was accessible, then let the user edit it.
431 if (is_array($theEditRec) && $BE_USER->isInWebMount($theEditRec['uid'])) {
432 // Setting JS code to open editing:
433 $this->mainJScode.='
434 // Load page to edit:
435 window.setTimeout("top.loadEditId('.intval($theEditRec['uid']).');",500);
436 ';
437 // Checking page edit parameter:
438 if(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
439
440 // Expanding page tree:
441 t3lib_BEfunc::openPageTree(intval($theEditRec['pid']),!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
442 }
443 } else {
444 $this->mainJScode.='
445 // Warning about page editing:
446 alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'),$editId)).');
447 ';
448 }
449 }
450 }
451
452 /**
453 * Sets the startup module from either GETvars module and mpdParams or user configuration.
454 *
455 * @return void
456 */
457 function startModule() {
458 global $BE_USER;
459 $module = preg_replace('/[^[:alnum:]_]/','',t3lib_div::_GET('module'));
460
461 if (!$module) {
462 if ($BE_USER->uc['startModule']) {
463 $module = $BE_USER->uc['startModule'];
464 } elseif ($BE_USER->uc['startInTaskCenter']) {
465 $module = 'user_task';
466 }
467 }
468
469 $params = t3lib_div::_GET('modParams');
470 if ($module) {
471 $this->mainJScode.='
472 // open in module:
473 top.goToModule(\''.$module.'\',false,\''.$params.'\');
474 ';
475 }
476 }
477
478
479 /**
480 * Creates the header and frameset of the backend interface
481 *
482 * @return void
483 */
484 function main() {
485 global $BE_USER,$TYPO3_CONF_VARS;
486
487 // Set doktype:
488 $GLOBALS['TBE_TEMPLATE']->docType='xhtml_frames';
489
490 // Make JS:
491 $this->generateJScode();
492 $GLOBALS['TBE_TEMPLATE']->JScode= '
493 <script type="text/javascript" src="md5.js"></script>
494 <script type="text/javascript" src="../t3lib/jsfunc.evalfield.js"></script>
495 <script type="text/javascript" src="js/backend.js"></script>
496 ';
497 $GLOBALS['TBE_TEMPLATE']->JScode.=$GLOBALS['TBE_TEMPLATE']->wrapScriptTags($this->mainJScode);
498
499 // Title:
500 $title = $TYPO3_CONF_VARS['SYS']['sitename'] ? $TYPO3_CONF_VARS['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']' : 'TYPO3 '.TYPO3_version;
501
502 // Start page header:
503 $this->content.=$GLOBALS['TBE_TEMPLATE']->startPage($title);
504
505 // Creates frameset
506 $fr_content = '<frame name="content" src="alt_intro.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" noresize="noresize" />';
507 $fr_toplogo = '<frame name="toplogo" src="alt_toplogo.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
508 $fr_topmenu = '<frame name="topmenuFrame" src="alt_topmenu_dummy.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
509
510 $shortcutFrame=array();
511 if ($BE_USER->getTSConfigVal('options.shortcutFrame')) {
512 $shortcutFrame['rowH']=','.$this->shortcutFrameH;
513 $shortcutFrame['frameDef']='<frame name="shortcutFrame" src="alt_shortcut.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
514 }
515
516 // XHTML notice: ' framespacing="0" frameborder="0" border="0"' in FRAMESET elements breaks compatibility with XHTML-frames, but HOW ELSE can I control the visual appearance?
517 if ($GLOBALS['BE_USER']->uc['noMenuMode']) {
518 $this->content.= '
519 <frameset rows="'.$this->topFrameH.',*'.$shortcutFrame['rowH'].'" framespacing="0" frameborder="0" border="0">
520 '.(!strcmp($BE_USER->uc['noMenuMode'],'icons') ? '
521 <frameset cols="'.$this->leftMenuFrameW.',*" framespacing="0" frameborder="0" border="0">
522 '.$fr_toplogo.'
523 '.$fr_topmenu.'
524 </frameset>' : '
525 <frameset cols="'.$this->leftMenuFrameW.','.$this->selMenuFrame.',*" framespacing="0" frameborder="0" border="0">
526 '.$fr_toplogo.'
527 <frame name="menu" src="alt_menu_sel.php" scrolling="no" noresize="noresize" />
528 '.$fr_topmenu.'
529 </frameset>').'
530 '.$fr_content.'
531 '.$shortcutFrame['frameDef'].'
532 </frameset>
533 ';
534 } else {
535 $this->content.='
536 <frameset rows="'.$this->topFrameH.',*'.$shortcutFrame['rowH'].'" framespacing="0" frameborder="0" border="0">
537 <frameset cols="'.$this->leftMenuFrameW.',*" framespacing="0" frameborder="0" border="0">
538 '.$fr_toplogo.'
539 '.$fr_topmenu.'
540 </frameset>
541 <frameset cols="'.$this->leftMenuFrameW.',*" framespacing="0" frameborder="0" border="0">
542 <frame name="menu" src="alt_menu.php" marginwidth="0" marginheight="0" scrolling="auto" noresize="noresize" />
543 '.$fr_content.'
544 </frameset>
545 '.$shortcutFrame['frameDef'].'
546 </frameset>
547 ';
548 }
549 $this->content.='
550
551 </html>';
552 }
553
554 /**
555 * Outputting the accumulated content to screen
556 *
557 * @return void
558 */
559 function printContent() {
560 echo $this->content;
561 }
562 }
563
564 // Include extension?
565 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_main.php']) {
566 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_main.php']);
567 }
568
569
570
571
572
573
574
575 // ******************************
576 // Starting document output
577 // ******************************
578
579 // Make instance:
580 $SOBE = t3lib_div::makeInstance('SC_alt_main');
581 $SOBE->init();
582 $SOBE->main();
583 $SOBE->printContent();
584
585 ?>