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