Documentation TYPO3 par Ameos

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 ***************************************************************/
00054 require ('init.php');
00055 require ('template.php');
00056 require_once (PATH_t3lib.'class.t3lib_loadmodules.php');
00057 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
00058 require_once ('class.alt_menu_functions.inc');
00059 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
00060 
00061 
00062 
00063 
00071 class SC_alt_main {
00072 
00073                 // Internal, dynamic:
00074         var $content;
00075         var $mainJScode;
00076         var $loadModules;               // Load modules-object
00077         var $alt_menuObj;               // Menu functions object.
00078 
00079                 // Internal, static:
00080         var $leftMenuFrameW = 130;
00081         var $selMenuFrame = 130;
00082         var $topFrameH = 32;
00083         var $shortcutFrameH = 30;
00084 
00090         function init() {
00091                 global $TBE_MODULES,$TBE_STYLES;
00092 
00093                         // Initializes the backend modules structure for use later.
00094                 $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
00095                 $this->loadModules->load($TBE_MODULES);
00096 
00097                         // Instantiates thee menu object which will generate some JavaScript for the goToModule() JS function in this frameset.
00098                 $this->alt_menuObj = t3lib_div::makeInstance('alt_menu_functions');
00099 
00100                         // Check for distances defined in the styles array:
00101                 if ($TBE_STYLES['dims']['leftMenuFrameW'])              $this->leftMenuFrameW = $TBE_STYLES['dims']['leftMenuFrameW'];
00102                 if ($TBE_STYLES['dims']['topFrameH'])           $this->topFrameH = $TBE_STYLES['dims']['topFrameH'];
00103                 if ($TBE_STYLES['dims']['shortcutFrameH'])              $this->shortcutFrameH = $TBE_STYLES['dims']['shortcutFrameH'];
00104                 if ($TBE_STYLES['dims']['selMenuFrame'])                $this->selMenuFrame = $TBE_STYLES['dims']['selMenuFrame'];
00105         }
00106 
00112         function generateJScode()       {
00113                 global $BE_USER,$LANG;
00114 
00115                 $pt3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
00116                 $goToModule_switch = $this->alt_menuObj->topMenu($this->loadModules->modules,0,"",4);
00117                 $fsMod = implode(chr(10),$this->alt_menuObj->fsMod);
00118 
00119                         // If another page module was specified, replace the default Page module with the new one
00120                 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
00121                 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
00122 
00123                 $this->mainJScode='
00127         function rawurlencode(str)      {       //
00128                 var output = escape(str);
00129                 output = str_replace("*","%2A", output);
00130                 output = str_replace("+","%2B", output);
00131                 output = str_replace("/","%2F", output);
00132                 output = str_replace("@","%40", output);
00133                 return output;
00134         }
00135 
00139         function str_replace(match,replace,string)      {       //
00140                 var input = ""+string;
00141                 var matchStr = ""+match;
00142                 if (!matchStr)  {return string;}
00143                 var output = "";
00144                 var pointer=0;
00145                 var pos = input.indexOf(matchStr);
00146                 while (pos!=-1) {
00147                         output+=""+input.substr(pointer, pos-pointer)+replace;
00148                         pointer=pos+matchStr.length;
00149                         pos = input.indexOf(match,pos+1);
00150                 }
00151                 output+=""+input.substr(pointer);
00152                 return output;
00153         }
00154 
00158         function typoSetup()    {       //
00159                 this.PATH_typo3 = "'.$pt3.'";
00160                 this.PATH_typo3_enc = "'.rawurlencode($pt3).'";
00161                 this.username = "'.$BE_USER->user['username'].'";
00162                 this.uniqueID = "'.t3lib_div::shortMD5(uniqid('')).'";
00163                 this.navFrameWidth = 0;
00164         }
00165         var TS = new typoSetup();
00166 
00170         function busy() {       //
00171                 this.loginRefreshed = busy_loginRefreshed;
00172                 this.checkLoginTimeout = busy_checkLoginTimeout;
00173                 this.openRefreshWindow = busy_OpenRefreshWindow;
00174                 this.busyloadTime=0;
00175                 this.openRefreshW=0;
00176         }
00177         function busy_loginRefreshed()  {       //
00178                 var date = new Date();
00179                 this.busyloadTime = Math.floor(date.getTime()/1000);
00180                 this.openRefreshW=0;
00181         }
00182         function busy_checkLoginTimeout()       {       //
00183                 var date = new Date();
00184                 var theTime = Math.floor(date.getTime()/1000);
00185                 if (theTime > this.busyloadTime+'.intval($BE_USER->auth_timeout_field).'-10)    {
00186                         return true;
00187                 }
00188         }
00189         function busy_OpenRefreshWindow()       {       //
00190                 vHWin=window.open("login_frameset.php","relogin_"+TS.uniqueID,"height=350,width=700,status=0,menubar=0,location=1");
00191                 vHWin.focus();
00192                 this.openRefreshW=1;
00193         }
00194         function busy_checkLoginTimeout_timer() {       //
00195 
00196                 if (busy.checkLoginTimeout())   {
00197                         if (!busy.openRefreshW && confirm('.$GLOBALS['LANG']->JScharCode($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login')).'))   {
00198                                 busy.openRefreshWindow();
00199                         }
00200                 }
00201                 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())
00202 
00203                         // 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!)
00204                 if (top && top.content && top.content.nav_frame && top.content.nav_frame.document && top.content.nav_frame.document.body)       {
00205                         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;
00206                 }
00207         }
00208 
00212         function launchView(table,uid,bP)       {       //
00213                 var backPath= bP ? bP : "";
00214                 var thePreviewWindow="";
00215                 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");
00216                 if (thePreviewWindow && thePreviewWindow.focus) {
00217                         thePreviewWindow.focus();
00218                 }
00219         }
00220 
00224         function openUrlInWindow(url,windowName)        {       //
00225                 regularWindow = window.open(url,windowName,"status=1,menubar=1,resizable=1,location=1,directories=0,scrollbars=1,toolbar=1");
00226                 regularWindow.focus();
00227                 return false;
00228         }
00229 
00233         function loadTopMenu(url)       {       //
00234                 top.topmenuFrame.location = url;
00235         }
00236 
00240         function loadEditId(id,addGetVars)      {       //
00241                 top.fsMod.recentIds["web"]=id;
00242                 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_0";         // For highlighting
00243 
00244                 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav)  {
00245                         top.content.nav_frame.refresh_nav();
00246                 }
00247 
00248                 top.goToModule("'.$pageModule.'", 0, addGetVars?addGetVars:"");
00249         }
00250 
00255         var nextLoadModuleUrl="";
00256         function getModuleUrl(inUrl)    {       //
00257                 var nMU;
00258                 if (top.nextLoadModuleUrl)      {
00259                         nMU=top.nextLoadModuleUrl;
00260                         top.nextLoadModuleUrl="";
00261                         return nMU;
00262                 } else {
00263                         return inUrl;
00264                 }
00265         }
00266 
00270         function debugObj(obj,name)     {       //
00271                 var acc;
00272                 for (i in obj) {
00273                         if (obj[i])     {
00274                                 acc+=i+":  "+obj[i]+"\n";
00275                         }
00276                 }
00277                 alert("Object: "+name+"\n\n"+acc);
00278         }
00279 
00283         var busy = new busy();
00284         busy.loginRefreshed();
00285         busy_checkLoginTimeout_timer();
00286 
00287 
00291         var currentlyHighLightedId = "";
00292         var currentlyHighLighted_restoreValue = "";
00293         var currentlyHighLightedMain = "";
00294         function highlightModuleMenuItem(trId, mainModule)      {       //
00295                 currentlyHighLightedMain = mainModule;
00296                         // Get document object:
00297                 if (top.menu && top.menu.document)      {
00298                         var docObj = top.menu.document;
00299                         var HLclass = mainModule ? "c-mainitem-HL" : "c-subitem-row-HL";
00300                 } else if (top.topmenuFrame && top.topmenuFrame.document)       {
00301                         var docObj = top.topmenuFrame.document;
00302                         var HLclass = mainModule ? "c-mainitem-HL" : "c-subitem-HL";
00303                 }
00304 
00305                 if (docObj)     {
00306                                 // Reset old:
00307                         if (currentlyHighLightedId && docObj.getElementById(currentlyHighLightedId))    {
00308                                 docObj.getElementById(currentlyHighLightedId).attributes.getNamedItem("class").nodeValue = currentlyHighLighted_restoreValue;
00309                         }
00310                                 // Set new:
00311                         currentlyHighLightedId = trId;
00312                         if (currentlyHighLightedId && docObj.getElementById(currentlyHighLightedId))    {
00313                                 var classAttribObject = docObj.getElementById(currentlyHighLightedId).attributes.getNamedItem("class");
00314                                 currentlyHighLighted_restoreValue = classAttribObject.nodeValue;
00315                                 classAttribObject.nodeValue = HLclass;
00316                         }
00317                 }
00318         }
00319 
00323         function restoreHighlightedModuleMenuItem() {
00324                 if (currentlyHighLightedId) {
00325                         highlightModuleMenuItem(currentlyHighLightedId,currentlyHighLightedMain);
00326                 }
00327         }
00328 
00332         var currentModuleLoaded = "";
00333         function goToModule(modName,cMR_flag,addGetVars)        {       //
00334                 var additionalGetVariables = "";
00335                 if (addGetVars) additionalGetVariables = addGetVars;
00336 
00337                 var cMR = 0;
00338                 if (cMR_flag)   cMR = 1;
00339 
00340                 currentModuleLoaded = modName;
00341 
00342                 switch(modName) {'.$goToModule_switch.'
00343                 }
00344         }
00345 
00354         function fsModules()    {       //
00355                 this.recentIds=new Array();                                     // used by frameset modules to track the most recent used id for list frame.
00356                 this.navFrameHighlightedID=new Array();         // used by navigation frames to track which row id was highlighted last time
00357                 this.currentMainLoaded="";
00358         }
00359         var fsMod = new fsModules();
00360         '.$fsMod.'
00361 
00362                 // Used by Frameset Modules
00363         var condensedMode = '.($BE_USER->uc['condensedMode']?1:0).';
00364         var currentSubScript = "";
00365         var currentSubNavScript = "";
00366 
00367                 // Used for tab-panels:
00368         var DTM_currentTabs = new Array();
00369                 ';
00370 
00371                         // Check editing of page:
00372                 $this->editPageHandling();
00373         }
00374 
00381         function editPageHandling()     {
00382                 global $BE_USER;
00383 
00384                 if (!t3lib_extMgm::isLoaded('cms'))     return;
00385 
00386                         // EDIT page:
00387                 $editId = ereg_replace('[^[:alnum:]_]','',t3lib_div::_GET('edit'));
00388                 $theEditRec = '';
00389 
00390                 if ($editId)    {
00391 
00392                                 // Looking up the page to edit, checking permissions:
00393                         $where = ' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
00394                         if (t3lib_div::testInt($editId))        {
00395                                 $theEditRec = t3lib_BEfunc::getRecord('pages',$editId,'*',$where);
00396                         } else {
00397                                 $records = t3lib_BEfunc::getRecordsByField('pages','alias',$editId,$where);
00398                                 if (is_array($records)) {
00399                                         reset($records);
00400                                         $theEditRec = current($records);
00401                                 }
00402                         }
00403 
00404                                 // If the page was accessible, then let the user edit it.
00405                         if (is_array($theEditRec) && $BE_USER->isInWebMount($theEditRec['uid']))        {
00406                                         // Setting JS code to open editing:
00407                                 $this->mainJScode.='
00408                 // Load page to edit:
00409         window.setTimeout("top.loadEditId('.intval($theEditRec['uid']).');",500);
00410                         ';
00411                                         // Checking page edit parameter:
00412                                 if(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
00413 
00414                                                 // Expanding page tree:
00415                                         t3lib_BEfunc::openPageTree(intval($theEditRec['pid']),!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
00416                                 }
00417                         } else {
00418                                 $this->mainJScode.='
00419                 // Warning about page editing:
00420         alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'),$editId)).');
00421                         ';
00422                         }
00423                 }
00424         }
00425 
00431         function main() {
00432                 global $BE_USER,$TYPO3_CONF_VARS;
00433 
00434                         // Set doktype:
00435                 $GLOBALS['TBE_TEMPLATE']->docType='xhtml_frames';
00436 
00437                         // Make JS:
00438                 $this->generateJScode();
00439                 $GLOBALS['TBE_TEMPLATE']->JScode= '
00440                         <script type="text/javascript" src="md5.js"></script>
00441                         <script type="text/javascript" src="t3lib/jsfunc.evalfield.js"></script>
00442                         ';
00443                 $GLOBALS['TBE_TEMPLATE']->JScode.=$GLOBALS['TBE_TEMPLATE']->wrapScriptTags($this->mainJScode);
00444 
00445                         // Title:
00446                 $title = $TYPO3_CONF_VARS['SYS']['sitename'] ? $TYPO3_CONF_VARS['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']' : 'TYPO3 '.TYPO3_version;
00447 
00448                         // Start page header:
00449                 $this->content.=$GLOBALS['TBE_TEMPLATE']->startPage($title);
00450 
00451                         // Creates frameset
00452                 $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" />';
00453                 $fr_toplogo = '<frame name="toplogo" src="alt_toplogo.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
00454                 $fr_topmenu = '<frame name="topmenuFrame" src="alt_topmenu_dummy.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
00455 
00456                 $shortcutFrame=array();
00457                 if ($BE_USER->getTSConfigVal('options.shortcutFrame'))  {
00458                         $shortcutFrame['rowH']=','.$this->shortcutFrameH;
00459                         $shortcutFrame['frameDef']='<frame name="shortcutFrame" src="alt_shortcut.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
00460                 }
00461 
00462                         // 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?
00463                 if ($GLOBALS['BE_USER']->uc['noMenuMode'])      {
00464                         $this->content.= '
00465                         <frameset rows="'.$this->topFrameH.',*'.$shortcutFrame['rowH'].'" framespacing="0" frameborder="0" border="0">
00466                                 '.(!strcmp($BE_USER->uc['noMenuMode'],'icons') ? '
00467                                 <frameset cols="'.$this->leftMenuFrameW.',*" framespacing="0" frameborder="0" border="0">
00468                                         '.$fr_toplogo.'
00469                                         '.$fr_topmenu.'
00470                                 </frameset>' : '
00471                                 <frameset cols="'.$this->leftMenuFrameW.','.$this->selMenuFrame.',*" framespacing="0" frameborder="0" border="0">
00472                                         '.$fr_toplogo.'
00473                                         <frame name="menu" src="alt_menu_sel.php" scrolling="no" noresize="noresize" />
00474                                         '.$fr_topmenu.'
00475                                 </frameset>').'
00476                                 '.$fr_content.'
00477                                 '.$shortcutFrame['frameDef'].'
00478                         </frameset>
00479                         ';
00480                 } else {
00481                         $this->content.='
00482                         <frameset rows="'.$this->topFrameH.',*'.$shortcutFrame['rowH'].'" framespacing="0" frameborder="0" border="0">
00483                                 <frameset cols="'.$this->leftMenuFrameW.',*" framespacing="0" frameborder="0" border="0">
00484                                         '.$fr_toplogo.'
00485                                         '.$fr_topmenu.'
00486                                 </frameset>
00487                                 <frameset cols="'.$this->leftMenuFrameW.',*" framespacing="0" frameborder="0" border="0">
00488                                         <frame name="menu" src="alt_menu.php" marginwidth="0" marginheight="0" scrolling="auto" noresize="noresize" />
00489                                         '.$fr_content.'
00490                                 </frameset>
00491                                 '.$shortcutFrame['frameDef'].'
00492                         </frameset>
00493                         ';
00494                 }
00495                 $this->content.='
00496 
00497 </html>';
00498         }
00499 
00505         function printContent() {
00506                 echo $this->content;
00507         }
00508 }
00509 
00510 // Include extension?
00511 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_main.php'])      {
00512         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_main.php']);
00513 }
00514 
00515 
00516 
00517 
00518 
00519 
00520 
00521 
00522 // ******************************
00523 // Starting document output
00524 // ******************************
00525 
00526 // Make instance:
00527 $SOBE = t3lib_div::makeInstance('SC_alt_main');
00528 $SOBE->init();
00529 $SOBE->main();
00530 $SOBE->printContent();
00531 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6