/src/typo3_src-4.2.0alpha1/typo3/alt_main.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00055 require ('init.php');
00056 require ('template.php');
00057 require_once (PATH_t3lib.'class.t3lib_loadmodules.php');
00058 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
00059 require_once ('class.alt_menu_functions.inc');
00060 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
00061 
00062 
00063 
00064 
00072 class SC_alt_main {
00073 
00074                 // Internal, dynamic:
00075         var $content;
00076         var $mainJScode;
00077 
00083         var $loadModules;               // Load modules-object
00084 
00090         var $alt_menuObj;               // Menu functions object.
00091 
00092                 // Internal, static:
00093         var $leftMenuFrameW = 130;
00094         var $selMenuFrame = 130;
00095         var $topFrameH = 32;
00096         var $shortcutFrameH = 30;
00097 
00103         function init() {
00104                 global $TBE_MODULES,$TBE_STYLES;
00105 
00106                         // Initializes the backend modules structure for use later.
00107                 $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
00108                 $this->loadModules->load($TBE_MODULES);
00109 
00110                         // Instantiates the menu object which will generate some JavaScript for the goToModule() JS function in this frameset.
00111                 $this->alt_menuObj = t3lib_div::makeInstance('alt_menu_functions');
00112 
00113                         // Check for distances defined in the styles array:
00114                 if ($TBE_STYLES['dims']['leftMenuFrameW'])              $this->leftMenuFrameW = $TBE_STYLES['dims']['leftMenuFrameW'];
00115                 if ($TBE_STYLES['dims']['topFrameH'])                   $this->topFrameH = $TBE_STYLES['dims']['topFrameH'];
00116                 if ($TBE_STYLES['dims']['shortcutFrameH'])              $this->shortcutFrameH = $TBE_STYLES['dims']['shortcutFrameH'];
00117                 if ($TBE_STYLES['dims']['selMenuFrame'])                $this->selMenuFrame = $TBE_STYLES['dims']['selMenuFrame'];
00118         }
00119 
00125         function generateJScode()       {
00126                 global $BE_USER,$LANG;
00127 
00128                 $pt3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
00129                 $goToModule_switch = $this->alt_menuObj->topMenu($this->loadModules->modules,0,"",4);
00130                 $fsMod = implode(chr(10),$this->alt_menuObj->fsMod);
00131 
00132                         // If another page module was specified, replace the default Page module with the new one
00133                 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
00134                 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
00135 
00136                 $menuFrameName = 'menu';
00137                 if ($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
00138                         $menuFrameName = 'topmenuFrame';
00139                 }
00140 
00141                 $this->mainJScode='
00145         function rawurlencode(str)      {       //
00146                 var output = escape(str);
00147                 output = str_replace("*","%2A", output);
00148                 output = str_replace("+","%2B", output);
00149                 output = str_replace("/","%2F", output);
00150                 output = str_replace("@","%40", output);
00151                 return output;
00152         }
00153 
00157         function str_replace(match,replace,string)      {       //
00158                 var input = ""+string;
00159                 var matchStr = ""+match;
00160                 if (!matchStr)  {return string;}
00161                 var output = "";
00162                 var pointer=0;
00163                 var pos = input.indexOf(matchStr);
00164                 while (pos!=-1) {
00165                         output+=""+input.substr(pointer, pos-pointer)+replace;
00166                         pointer=pos+matchStr.length;
00167                         pos = input.indexOf(match,pos+1);
00168                 }
00169                 output+=""+input.substr(pointer);
00170                 return output;
00171         }
00172 
00176         function typoSetup()    {       //
00177                 this.PATH_typo3 = "'.$pt3.'";
00178                 this.PATH_typo3_enc = "'.rawurlencode($pt3).'";
00179                 this.username = "'.$BE_USER->user['username'].'";
00180                 this.uniqueID = "'.t3lib_div::shortMD5(uniqid('')).'";
00181                 this.navFrameWidth = 0;
00182         }
00183         var TS = new typoSetup();
00184 
00188         function busy() {       //
00189                 this.loginRefreshed = busy_loginRefreshed;
00190                 this.checkLoginTimeout = busy_checkLoginTimeout;
00191                 this.openRefreshWindow = busy_OpenRefreshWindow;
00192                 this.busyloadTime=0;
00193                 this.openRefreshW=0;
00194                 this.reloginCancelled=0;
00195         }
00196         function busy_loginRefreshed()  {       //
00197                 var date = new Date();
00198                 this.busyloadTime = Math.floor(date.getTime()/1000);
00199                 this.openRefreshW=0;
00200         }
00201         function busy_checkLoginTimeout()       {       //
00202                 var date = new Date();
00203                 var theTime = Math.floor(date.getTime()/1000);
00204                 if (theTime > this.busyloadTime+'.intval($BE_USER->auth_timeout_field).'-30)    {
00205                         return true;
00206                 }
00207         }
00208         function busy_OpenRefreshWindow()       {       //
00209                 vHWin=window.open("login_frameset.php","relogin_"+TS.uniqueID,"height=350,width=700,status=0,menubar=0,location=1");
00210                 vHWin.focus();
00211                 this.openRefreshW=1;
00212         }
00213         function busy_checkLoginTimeout_timer() {       //
00214                 if (busy.checkLoginTimeout() && !busy.reloginCancelled && !busy.openRefreshW)   {
00215                         if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login')).')) {
00216                                 busy.openRefreshWindow();
00217                         } else  {
00218                                 busy.reloginCancelled = 1;
00219                         }
00220                 }
00221                 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())
00222 
00223                         // 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!)
00224                 if (top && top.content && top.content.nav_frame && top.content.nav_frame.document && top.content.nav_frame.document.body)       {
00225                         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;
00226                 }
00227         }
00228 
00232         function launchView(table,uid,bP)       {       //
00233                 var backPath= bP ? bP : "";
00234                 var thePreviewWindow="";
00235                 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");
00236                 if (thePreviewWindow && thePreviewWindow.focus) {
00237                         thePreviewWindow.focus();
00238                 }
00239         }
00240 
00244         function openUrlInWindow(url,windowName)        {       //
00245                 regularWindow = window.open(url,windowName,"status=1,menubar=1,resizable=1,location=1,directories=0,scrollbars=1,toolbar=1");
00246                 regularWindow.focus();
00247                 return false;
00248         }
00249 
00253         function loadTopMenu(url)       {       //
00254                 top.topmenuFrame.location = url;
00255         }
00256 
00260         function loadEditId(id,addGetVars)      {       //
00261                 top.fsMod.recentIds["web"]=id;
00262                 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_0";         // For highlighting
00263 
00264                 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav)  {
00265                         top.content.nav_frame.refresh_nav();
00266                 }
00267 
00268                 top.goToModule("'.$pageModule.'", 0, addGetVars?addGetVars:"");
00269         }
00270 
00275         var nextLoadModuleUrl="";
00276         function getModuleUrl(inUrl)    {       //
00277                 var nMU;
00278                 if (top.nextLoadModuleUrl)      {
00279                         nMU=top.nextLoadModuleUrl;
00280                         top.nextLoadModuleUrl="";
00281                         return nMU;
00282                 } else {
00283                         return inUrl;
00284                 }
00285         }
00286 
00290         function debugObj(obj,name)     {       //
00291                 var acc;
00292                 for (i in obj) {
00293                         if (obj[i])     {
00294                                 acc+=i+":  "+obj[i]+"\n";
00295                         }
00296                 }
00297                 alert("Object: "+name+"\n\n"+acc);
00298         }
00299 
00303         var busy = new busy();
00304         busy.loginRefreshed();
00305         busy_checkLoginTimeout_timer();
00306 
00307 
00311         var currentlyHighLightedId = "";
00312         var currentlyHighLighted_restoreValue = "";
00313         var currentlyHighLightedMain = "";
00314         function highlightModuleMenuItem(trId, mainModule)      {       //
00315                 currentlyHighLightedMain = mainModule;
00316                         // Get document object:
00317                 if (top.menu && top.menu.document)      {
00318                         var docObj = top.menu.document;
00319                         var HLclass = mainModule ? "c-mainitem-HL" : "c-subitem-row-HL";
00320                 } else if (top.topmenuFrame && top.topmenuFrame.document)       {
00321                         var docObj = top.topmenuFrame.document;
00322                         var HLclass = mainModule ? "c-mainitem-HL" : "c-subitem-HL";
00323                 }
00324 
00325                 if (docObj)     {
00326                                 // Reset old:
00327                         if (currentlyHighLightedId && docObj.getElementById(currentlyHighLightedId))    {
00328                                 docObj.getElementById(currentlyHighLightedId).attributes.getNamedItem("class").nodeValue = currentlyHighLighted_restoreValue;
00329                         }
00330                                 // Set new:
00331                         currentlyHighLightedId = trId;
00332                         if (currentlyHighLightedId && docObj.getElementById(currentlyHighLightedId))    {
00333                                 var classAttribObject = docObj.getElementById(currentlyHighLightedId).attributes.getNamedItem("class");
00334                                 currentlyHighLighted_restoreValue = classAttribObject.nodeValue;
00335                                 classAttribObject.nodeValue = HLclass;
00336                         }
00337                 }
00338         }
00339 
00343         function restoreHighlightedModuleMenuItem() {   //
00344                 if (currentlyHighLightedId) {
00345                         highlightModuleMenuItem(currentlyHighLightedId,currentlyHighLightedMain);
00346                 }
00347         }
00348 
00352         var currentModuleLoaded = "";
00353         function goToModule(modName, cMR_flag, addGetVars)      {       //
00354                 if (top.'.$menuFrameName.' && top.'.$menuFrameName.'.goToModule) {
00355                         currentModuleLoaded = modName;
00356                         top.'.$menuFrameName.'.goToModule(modName, cMR_flag, addGetVars);
00357                 } else {
00358                         window.setTimeout(function() { top.goToModule(modName, cMR_flag, addGetVars); }, 500);
00359                 }
00360         }
00361 
00365         function refreshMenu() {
00366                 top.'.$menuFrameName.'.location.href = top.'.$menuFrameName.'.document.URL
00367         }
00368 
00377         function fsModules()    {       //
00378                 this.recentIds=new Array();                                     // used by frameset modules to track the most recent used id for list frame.
00379                 this.navFrameHighlightedID=new Array();         // used by navigation frames to track which row id was highlighted last time
00380                 this.currentMainLoaded="";
00381                 this.currentBank="0";
00382         }
00383         var fsMod = new fsModules();
00384         '.$fsMod.'
00385 
00386                 // Used by Frameset Modules
00387         var condensedMode = '.($BE_USER->uc['condensedMode']?1:0).';
00388         var currentSubScript = "";
00389         var currentSubNavScript = "";
00390 
00391                 // Used for tab-panels:
00392         var DTM_currentTabs = new Array();
00393                 ';
00394 
00395                         // Check editing of page:
00396                 $this->editPageHandling();
00397                 $this->startModule();
00398         }
00399 
00406         function editPageHandling()     {
00407                 global $BE_USER;
00408 
00409                 if (!t3lib_extMgm::isLoaded('cms'))     return;
00410 
00411                         // EDIT page:
00412                 $editId = preg_replace('/[^[:alnum:]_]/','',t3lib_div::_GET('edit'));
00413                 $theEditRec = '';
00414 
00415                 if ($editId)    {
00416 
00417                                 // Looking up the page to edit, checking permissions:
00418                         $where = ' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
00419                         if (t3lib_div::testInt($editId))        {
00420                                 $theEditRec = t3lib_BEfunc::getRecordWSOL('pages',$editId,'*',$where);
00421                         } else {
00422                                 $records = t3lib_BEfunc::getRecordsByField('pages','alias',$editId,$where);
00423                                 if (is_array($records)) {
00424                                         reset($records);
00425                                         $theEditRec = current($records);
00426                                         t3lib_BEfunc::workspaceOL('pages', $theEditRec);
00427                                 }
00428                         }
00429 
00430                                 // If the page was accessible, then let the user edit it.
00431                         if (is_array($theEditRec) && $BE_USER->isInWebMount($theEditRec['uid']))        {
00432                                         // Setting JS code to open editing:
00433                                 $this->mainJScode.='
00434                 // Load page to edit:
00435         window.setTimeout("top.loadEditId('.intval($theEditRec['uid']).');",500);
00436                         ';
00437                                         // Checking page edit parameter:
00438                                 if(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
00439 
00440                                                 // Expanding page tree:
00441                                         t3lib_BEfunc::openPageTree(intval($theEditRec['pid']),!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
00442                                 }
00443                         } else {
00444                                 $this->mainJScode.='
00445                 // Warning about page editing:
00446         alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'),$editId)).');
00447                         ';
00448                         }
00449                 }
00450         }
00451 
00457         function startModule() {
00458                 global $BE_USER;
00459                 $module = preg_replace('/[^[:alnum:]_]/','',t3lib_div::_GET('module'));
00460                 
00461                 if (!$module)   {
00462                         if ($BE_USER->uc['startModule'])        {
00463                                 $module = $BE_USER->uc['startModule'];
00464                         } elseif ($BE_USER->uc['startInTaskCenter'])    {
00465                                 $module = 'user_task';
00466                         }
00467                 }
00468 
00469                 $params = t3lib_div::_GET('modParams');
00470                 if ($module) {
00471                         $this->mainJScode.='
00472                 // open in module:
00473         top.goToModule(\''.$module.'\',false,\''.$params.'\');
00474                         ';
00475                 }
00476         }
00477 
00478 
00484         function main() {
00485                 global $BE_USER,$TYPO3_CONF_VARS;
00486 
00487                         // Set doktype:
00488                 $GLOBALS['TBE_TEMPLATE']->docType='xhtml_frames';
00489 
00490                         // Make JS:
00491                 $this->generateJScode();
00492                 $GLOBALS['TBE_TEMPLATE']->JScode= '
00493                         <script type="text/javascript" src="md5.js"></script>
00494                         <script type="text/javascript" src="../t3lib/jsfunc.evalfield.js"></script>
00495                         ';
00496                 $GLOBALS['TBE_TEMPLATE']->JScode.=$GLOBALS['TBE_TEMPLATE']->wrapScriptTags($this->mainJScode);
00497 
00498                         // Title:
00499                 $title = $TYPO3_CONF_VARS['SYS']['sitename'] ? $TYPO3_CONF_VARS['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']' : 'TYPO3 '.TYPO3_version;
00500 
00501                         // Start page header:
00502                 $this->content.=$GLOBALS['TBE_TEMPLATE']->startPage($title);
00503 
00504                         // Creates frameset
00505                 $fr_content = '<frame name="content" src="alt_intro.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" noresize="noresize" />';
00506                 $fr_toplogo = '<frame name="toplogo" src="alt_toplogo.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
00507                 $fr_topmenu = '<frame name="topmenuFrame" src="alt_topmenu_dummy.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
00508 
00509                 $shortcutFrame=array();
00510                 if ($BE_USER->getTSConfigVal('options.shortcutFrame'))  {
00511                         $shortcutFrame['rowH']=','.$this->shortcutFrameH;
00512                         $shortcutFrame['frameDef']='<frame name="shortcutFrame" src="alt_shortcut.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
00513                 }
00514 
00515                         // 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?
00516                 if ($GLOBALS['BE_USER']->uc['noMenuMode'])      {
00517                         $this->content.= '
00518                         <frameset rows="'.$this->topFrameH.',*'.$shortcutFrame['rowH'].'" framespacing="0" frameborder="0" border="0">
00519                                 '.(!strcmp($BE_USER->uc['noMenuMode'],'icons') ? '
00520                                 <frameset cols="'.$this->leftMenuFrameW.',*" framespacing="0" frameborder="0" border="0">
00521                                         '.$fr_toplogo.'
00522                                         '.$fr_topmenu.'
00523                                 </frameset>' : '
00524                                 <frameset cols="'.$this->leftMenuFrameW.','.$this->selMenuFrame.',*" framespacing="0" frameborder="0" border="0">
00525                                         '.$fr_toplogo.'
00526                                         <frame name="menu" src="alt_menu_sel.php" scrolling="no" noresize="noresize" />
00527                                         '.$fr_topmenu.'
00528                                 </frameset>').'
00529                                 '.$fr_content.'
00530                                 '.$shortcutFrame['frameDef'].'
00531                         </frameset>
00532                         ';
00533                 } else {
00534                         $this->content.='
00535                         <frameset rows="'.$this->topFrameH.',*'.$shortcutFrame['rowH'].'" framespacing="0" frameborder="0" border="0">
00536                                 <frameset cols="'.$this->leftMenuFrameW.',*" framespacing="0" frameborder="0" border="0">
00537                                         '.$fr_toplogo.'
00538                                         '.$fr_topmenu.'
00539                                 </frameset>
00540                                 <frameset cols="'.$this->leftMenuFrameW.',*" framespacing="0" frameborder="0" border="0">
00541                                         <frame name="menu" src="alt_menu.php" marginwidth="0" marginheight="0" scrolling="auto" noresize="noresize" />
00542                                         '.$fr_content.'
00543                                 </frameset>
00544                                 '.$shortcutFrame['frameDef'].'
00545                         </frameset>
00546                         ';
00547                 }
00548                 $this->content.='
00549 
00550 </html>';
00551         }
00552 
00558         function printContent() {
00559                 echo $this->content;
00560         }
00561 }
00562 
00563 // Include extension?
00564 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_main.php'])      {
00565         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_main.php']);
00566 }
00567 
00568 
00569 
00570 
00571 
00572 
00573 
00574 // ******************************
00575 // Starting document output
00576 // ******************************
00577 
00578 // Make instance:
00579 $SOBE = t3lib_div::makeInstance('SC_alt_main');
00580 $SOBE->init();
00581 $SOBE->main();
00582 $SOBE->printContent();
00583 
00584 ?>

This documentation has been generated automatically from TYPO3 source code using Doxygen and is provided as is by Cast Iron Coding as a courtesy to other TYPO3 developers and users. Please consider Cast Iron Coding — a full-service web development agency in Portland, Oregon specializing in TYPO3 extension development — for all of your TYPO3 development and consulting needs!