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