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