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