* Added 3 hooks for each hardcoded function in css_styled_content so extensions can...
[Packages/TYPO3.CMS.git] / typo3 / alt_main.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 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","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 function highlightModuleMenuItem(trId, mainModule) { //
294 // Get document object:
295 if (top.menu && top.menu.document) {
296 var docObj = top.menu.document;
297 var HLclass = mainModule ? "c-mainitem-HL" : "c-subitem-row-HL";
298 } else if (top.topmenuFrame && top.topmenuFrame.document) {
299 var docObj = top.topmenuFrame.document;
300 var HLclass = mainModule ? "c-mainitem-HL" : "c-subitem-HL";
301 }
302
303 if (docObj) {
304 // Reset old:
305 if (currentlyHighLightedId && docObj.getElementById(currentlyHighLightedId)) {
306 docObj.getElementById(currentlyHighLightedId).attributes.getNamedItem("class").nodeValue = currentlyHighLighted_restoreValue;
307 }
308 // Set new:
309 currentlyHighLightedId = trId;
310 if (currentlyHighLightedId && docObj.getElementById(currentlyHighLightedId)) {
311 var classAttribObject = docObj.getElementById(currentlyHighLightedId).attributes.getNamedItem("class");
312 currentlyHighLighted_restoreValue = classAttribObject.nodeValue;
313 classAttribObject.nodeValue = HLclass;
314 }
315 }
316 }
317
318 /**
319 * Function used to switch switch module.
320 */
321 var currentModuleLoaded = "";
322 function goToModule(modName,cMR_flag,addGetVars) { //
323 var additionalGetVariables = "";
324 if (addGetVars) additionalGetVariables = addGetVars;
325
326 var cMR = 0;
327 if (cMR_flag) cMR = 1;
328
329 currentModuleLoaded = modName;
330
331 switch(modName) {'.$goToModule_switch.'
332 }
333 }
334
335 /**
336 * Frameset Module object
337 *
338 * Used in main modules with a frameset for submodules to keep the ID between modules
339 * Typically that is set by something like this in a Web>* sub module:
340 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
341 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
342 */
343 function fsModules() { //
344 this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame.
345 this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time
346 this.currentMainLoaded="";
347 }
348 var fsMod = new fsModules();
349 '.$fsMod.'
350
351 // Used by Frameset Modules
352 var condensedMode = '.($BE_USER->uc['condensedMode']?1:0).';
353 var currentSubScript = "";
354 var currentSubNavScript = "";
355
356 // Used for tab-panels:
357 var DTM_currentTabs = new Array();
358 ';
359
360 // Check editing of page:
361 $this->editPageHandling();
362 }
363
364 /**
365 * Checking if the "&edit" variable was sent so we can open for editing the page.
366 * Code based on code from "alt_shortcut.php"
367 *
368 * @return void
369 */
370 function editPageHandling() {
371 global $BE_USER;
372
373 if (!t3lib_extMgm::isLoaded('cms')) return;
374
375 // EDIT page:
376 $editId = ereg_replace('[^[:alnum:]_]','',t3lib_div::_GET('edit'));
377 $theEditRec = '';
378
379 if ($editId) {
380
381 // Looking up the page to edit, checking permissions:
382 $where = ' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
383 if (t3lib_div::testInt($editId)) {
384 $theEditRec = t3lib_BEfunc::getRecord('pages',$editId,'*',$where);
385 } else {
386 $records = t3lib_BEfunc::getRecordsByField('pages','alias',$editId,$where);
387 if (is_array($records)) {
388 reset($records);
389 $theEditRec = current($records);
390 }
391 }
392
393 // If the page was accessible, then let the user edit it.
394 if (is_array($theEditRec) && $BE_USER->isInWebMount($theEditRec['uid'])) {
395 // Setting JS code to open editing:
396 $this->mainJScode.='
397 // Load page to edit:
398 window.setTimeout("top.loadEditId('.intval($theEditRec['uid']).');",500);
399 ';
400 // Checking page edit parameter:
401 if(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
402
403 // Expanding page tree:
404 t3lib_BEfunc::openPageTree(intval($theEditRec['pid']),!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
405 }
406 } else {
407 $this->mainJScode.='
408 // Warning about page editing:
409 alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'),$editId)).');
410 ';
411 }
412 }
413 }
414
415 /**
416 * Creates the header and frameset of the backend interface
417 *
418 * @return void
419 */
420 function main() {
421 global $BE_USER,$TYPO3_CONF_VARS;
422
423 // Set doktype:
424 $GLOBALS['TBE_TEMPLATE']->docType='xhtml_frames';
425
426 // Make JS:
427 $this->generateJScode();
428 $GLOBALS['TBE_TEMPLATE']->JScode= '
429 <script type="text/javascript" src="md5.js"></script>
430 <script type="text/javascript" src="t3lib/jsfunc.evalfield.js"></script>
431 ';
432 $GLOBALS['TBE_TEMPLATE']->JScode.=$GLOBALS['TBE_TEMPLATE']->wrapScriptTags($this->mainJScode);
433
434 // Title:
435 $title = $TYPO3_CONF_VARS['SYS']['sitename'] ? $TYPO3_CONF_VARS['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']' : 'TYPO3 '.TYPO3_version;
436
437 // Start page header:
438 $this->content.=$GLOBALS['TBE_TEMPLATE']->startPage($title);
439
440 // Creates frameset
441 $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" />';
442 $fr_toplogo = '<frame name="toplogo" src="alt_toplogo.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
443 $fr_topmenu = '<frame name="topmenuFrame" src="alt_topmenu_dummy.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
444
445 $shortcutFrame=array();
446 if ($BE_USER->getTSConfigVal('options.shortcutFrame')) {
447 $shortcutFrame['rowH']=','.$this->shortcutFrameH;
448 $shortcutFrame['frameDef']='<frame name="shortcutFrame" src="alt_shortcut.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
449 }
450
451 // 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?
452 if ($GLOBALS['BE_USER']->uc['noMenuMode']) {
453 $this->content.= '
454 <frameset rows="'.$this->topFrameH.',*'.$shortcutFrame['rowH'].'" framespacing="0" frameborder="0" border="0">
455 '.(!strcmp($BE_USER->uc['noMenuMode'],'icons') ? '
456 <frameset cols="'.$this->leftMenuFrameW.',*" framespacing="0" frameborder="0" border="0">
457 '.$fr_toplogo.'
458 '.$fr_topmenu.'
459 </frameset>' : '
460 <frameset cols="'.$this->leftMenuFrameW.','.$this->selMenuFrame.',*" framespacing="0" frameborder="0" border="0">
461 '.$fr_toplogo.'
462 <frame name="menu" src="alt_menu_sel.php" scrolling="no" noresize="noresize" />
463 '.$fr_topmenu.'
464 </frameset>').'
465 '.$fr_content.'
466 '.$shortcutFrame['frameDef'].'
467 </frameset>
468 ';
469 } else {
470 $this->content.='
471 <frameset rows="'.$this->topFrameH.',*'.$shortcutFrame['rowH'].'" framespacing="0" frameborder="0" border="0">
472 <frameset cols="'.$this->leftMenuFrameW.',*" framespacing="0" frameborder="0" border="0">
473 '.$fr_toplogo.'
474 '.$fr_topmenu.'
475 </frameset>
476 <frameset cols="'.$this->leftMenuFrameW.',*" framespacing="0" frameborder="0" border="0">
477 <frame name="menu" src="alt_menu.php" marginwidth="0" marginheight="0" scrolling="auto" noresize="noresize" />
478 '.$fr_content.'
479 </frameset>
480 '.$shortcutFrame['frameDef'].'
481 </frameset>
482 ';
483 }
484 $this->content.='
485
486 </html>';
487 }
488
489 /**
490 * Outputting the accumulated content to screen
491 *
492 * @return void
493 */
494 function printContent() {
495 echo $this->content;
496 }
497 }
498
499 // Include extension?
500 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_main.php']) {
501 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_main.php']);
502 }
503
504
505
506
507
508
509
510
511 // ******************************
512 // Starting document output
513 // ******************************
514
515 // Make instance:
516 $SOBE = t3lib_div::makeInstance('SC_alt_main');
517 $SOBE->init();
518 $SOBE->main();
519 $SOBE->printContent();
520 ?>