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