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