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