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