* Added a checkbox for be-users to disable IP locking. This is useful if you have...
[Packages/TYPO3.CMS.git] / typo3 / class.alt_menu_functions.inc
index 7079d3a..7478d77 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *  
-*  (c) 1999-2003 Kasper Skaarhoj (kasper@typo3.com)
+*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is 
  *
  *
  *
- *   70: class alt_menu_functions 
- *   91:     function topMenu($theModules,$dontLink=0,$backPath='',$descr=0)   
- *  340:     function mIconFile($Ifilename,$backPath)  
- *  355:     function mIconFilename($Ifilename,$backPath)      
- *  367:     function topButtons()     
- *  380:     function wrapLinkWithAB($link)    
+ *   72: class alt_menu_functions 
+ *   93:     function topMenu($theModules,$dontLink=0,$backPath='',$descr=0)   
+ *  386:     function mIconFile($Ifilename,$backPath)  
+ *  401:     function mIconFilename($Ifilename,$backPath)      
+ *  413:     function topButtons()     
+ *  425:     function adminButtons()   
+ *  444:     function adminFunctions($backPath)        
+ *  477:     function wrapLinkWithAB($link)    
  *
- * TOTAL FUNCTIONS: 5
+ * TOTAL FUNCTIONS: 7
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
@@ -62,7 +64,7 @@
 
 /**
  * Class with menu functions
- * 
+ *
  * @author     Kasper Skaarhoj <kasper@typo3.com>
  * @package TYPO3
  * @subpackage core
@@ -74,14 +76,14 @@ class alt_menu_functions {
 
        /**
         * Creates the menu of modules.
-        * 
+        *
         * $descr determines the type of menu made:
         *              0 = Ordinary vertical menu
         *              1 = Descriptions for 'About modules' display
         *              2 = selector-box menu
         *              3 = topmenu - horizontal line of icons!
         *              4 = part of JavaScript switch contruct for alt_main.php frameset.
-        * 
+        *
         * @param       array           $theModules is the output from load_modules class ($this->loadModules->modules)
         * @param       boolean         $dontLink == true will prevent the output from being linked with A-tags (used in the 'beuser' extension)
         * @param       string          $backPath must be the 'backPath' to PATH_typo3 from where the the menu is displayed.
@@ -89,7 +91,7 @@ class alt_menu_functions {
         * @return      string          The menu HTML
         */
        function topMenu($theModules,$dontLink=0,$backPath='',$descr=0) {
-               global $LANG, $TBE_TEMPLATE;
+               global $LANG, $TBE_TEMPLATE, $BE_USER;
        
                        // Initialize vars:
                $final='';
@@ -101,11 +103,11 @@ class alt_menu_functions {
                $mJScmds=array();
                $onBlur=$GLOBALS['CLIENT']['FORMSTYLE'] ? 'this.blur();' : '';
        
-               $selectItems[] = '<option value="">[ MODULES ]</option>';
+               $selectItems[] = '<option value="">[ '.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.selMenu_modules',1).' ]</option>';
                $mC=0;
        
                        // Remove the 'doc' module?
-               if ($GLOBALS['BE_USER']->getTSConfigVal('options.disableDocModuleInAB'))        {
+               if ($BE_USER->getTSConfigVal('options.disableDocModuleInAB'))   {
                        unset($theModules['doc']);
                }
        
@@ -115,12 +117,13 @@ class alt_menu_functions {
                        $mC++;
 
                        $prefix='';
-                       if ($moduleInfo["navFrameScript"])      {
-                               if ($GLOBALS['BE_USER']->uc['condensedMode'])   {
-                                       $prefix=$moduleInfo["navFrameScript"].'?currentSubScript=';
+                       if ($moduleInfo['navFrameScript'])      {
+                               if ($BE_USER->uc['condensedMode'])      {
+                                       $prefix=$moduleInfo['navFrameScript'].'?currentSubScript=';
                                } else {
                                        $prefix='alt_mod_frameset.php?'.
-                                               '&nav='.$moduleInfo["navFrameScript"].
+                                               'fW="+top.TS.navFrameWidth+"'.
+                                               '&nav='.rawurlencode($moduleInfo['navFrameScript']).
                                                '&script=';
                                }
                                $this->fsMod[]='fsMod.recentIds["'.$moduleName.'"]="";';
@@ -148,13 +151,13 @@ class alt_menu_functions {
                                // Creating image icon
                        $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath));
                        $imageCode='';
-                       $descr3_title = t3lib_BEfunc::titleAttrib($LANG->moduleLabels['tabs'][$moduleKey].' ');
+                       $descr3_title = $LANG->moduleLabels['tabs'][$moduleKey].' ';
                        if ($image)     {
                                $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath);
-                               $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' align="top" alt="" />';
-                               $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' align="top" border="0"'.$descr3_title.' alt="" />';
+                               $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' alt="" />';
+                               $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($descr3_title).'" alt="" />';
                        } else {
-                               $descr3_imageCode = '<img src="'.$backPath.'gfx/dummy_module.gif" width="14" height="12" align="top" border="0"'.$descr3_title.' alt="" />';
+                               $descr3_imageCode = '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/dummy_module.gif','width="14" height="12"').' title="'.htmlspecialchars($descr3_title).'" alt="" />';
                        }
                        
                                // Creating the various links:
@@ -173,20 +176,16 @@ class alt_menu_functions {
                        $label='&nbsp;<b>'.$label.'</b>&nbsp;';
                        
                                // Creating a main item for the vertical menu (descr=0)
-                       $modItemCode=$imageCode.$label;
-                       $modItemCode='<div class="typo3-mainmenu-inner">'.$modItemCode.'</div>';
-                       $modItemCode='<tr>
-                               <td colspan="3" class="typo3-mainmenu-outer">'.$modItemCode.'</td>
-                               </tr>';
-                       $menuCode.=$modItemCode;
+                       $menuCode.='
+                                               <tr class="c-mainitem">
+                                                       <td colspan="3">'.$imageCode.'<span class="c-label">'.$label.'</span></td>
+                                               </tr>';
 
                                // Code for "About modules"
-                       $descrCode.='<tr>
-                               <td colspan="3"><img src="clear.gif" width="1" height="10" alt="" /></td>
-                               </tr>';
-                       $descrCode.='<tr>
-                               <td colspan="3" class="typo3-aboutmod-outer" bgcolor="'.$TBE_TEMPLATE->bgColor4.'" nowrap="nowrap">'.$imageCode.$label.'</td>
-                               </tr>';
+                       $descrCode.='
+                                               <tr class="c-mainitem bgColor4">
+                                                       <td colspan="3">'.$imageCode.$label.'</td>
+                                               </tr>';
 
 
 
@@ -197,7 +196,16 @@ class alt_menu_functions {
                                reset($moduleInfo['sub']);
                                $c=0;
                                while(list($subName,$subInfo)=each($moduleInfo['sub'])) {
-                                       if ($c==0)              $subCode.='<tr><td colspan="3"><img src="clear.gif" width="1" height="2" alt="" /></td></tr>';
+                                       if ($c==0)              {
+                                               $subCode.='
+                                                               <tr class="c-first">
+                                                                       <td colspan="3"></td>
+                                                               </tr>';
+                                               $descrCode.='
+                                                               <tr class="c-first">
+                                                                       <td colspan="3"></td>
+                                                               </tr>';
+                                       }
 
                                        $link = $subInfo['script'];
                                        $subKey = $moduleName.'_'.$subName.'_tab';
@@ -205,36 +213,38 @@ class alt_menu_functions {
                                                // Creating image icon
                                        $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$subKey],$backPath));
                                        $imageCode='';
-                                       $descr3_title = t3lib_BEfunc::titleAttrib($LANG->moduleLabels['tabs'][$subKey].': '.$LANG->moduleLabels['labels'][$subKey.'label']);
+                                       $descr3_title = $LANG->moduleLabels['tabs'][$subKey].': '.$LANG->moduleLabels['labels'][$subKey.'label'];
                                        if ($image)     {
                                                $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$subKey],$backPath);
-                                               $imageCode = '<img src="'.$Ifilename.'" '.$image[3].t3lib_BEfunc::titleAttrib($LANG->moduleLabels['labels'][$subKey.'label'].' ').' alt="" />';
-                                               $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' align="top" border="0"'.$descr3_title.' alt="" />';
+                                               $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'" alt="" />';
+                                               $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($descr3_title).'" alt="" />';
                                        } else {
-                                               $descr3_imageCode = '<img src="'.$backPath.'gfx/dummy_module.gif" width="14" height="12" align="top" border="0"'.$descr3_title.' alt="" />';
+                                               $descr3_imageCode = '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/dummy_module.gif','width="14" height="12"').' title="'.htmlspecialchars($descr3_title).'" alt="" />';
                                        }
                                        
                                                // Label for submodule:
                                        $label = $LANG->moduleLabels['tabs'][$subKey];
                                        $label_descr = ' title="'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'"';
-                                       $flabel = $label;
+                                       $flabel = htmlspecialchars($label);
                                        $origLink = $link;
                                        if ($link && $prefix)   $link=$prefix.rawurlencode($link);
                                        
                                                // Setting additional JavaScript if frameset script:
                                        $addJS = '';
-                                       if ($moduleInfo["navFrameScript"])      {$addJS="+'&id='+top.rawurlencode(top.fsMod.recentIds['".$moduleName."'])";}
+                                       if ($moduleInfo['navFrameScript'])      {$addJS="+'&id='+top.rawurlencode(top.fsMod.recentIds['".$moduleName."'])";}
                                        
                                                // If there is a script to link to (and linking is not disabled.
                                        if ($link && !$dontLink)        {
                                                        // For condensed mode, send &cMR parameter to frameset script.
-                                               if ($addJS && $GLOBALS['BE_USER']->uc['condensedMode']) {$addJS.=  "+(cMR?'&cMR=1':'')";}
+                                               if ($addJS && $BE_USER->uc['condensedMode'])    {$addJS.=  "+(cMR?'&cMR=1':'')";}
 
                                                        // Command for the selector box:
-                                               $JScmd = "top.content.location=top.getModuleUrl(top.TS.PATH_typo3+'".$this->wrapLinkWithAB($link)."'".$addJS.");";
+                                               $JScmd = "
+                                                               top.content.location=top.getModuleUrl(top.TS.PATH_typo3+'".$this->wrapLinkWithAB($link)."'".$addJS.');
+                                                               top.fsMod.currentMainLoaded="'.$moduleName.'";';
 
                                                        // If there is a frameset script in place:
-                                               if (!$GLOBALS['BE_USER']->uc['condensedMode'] && $moduleInfo["navFrameScript"]) {
+                                               if (!$BE_USER->uc['condensedMode'] && $moduleInfo['navFrameScript'])    {
                                                        $JScmd = '
                                                                if (top.content.list_frame && top.fsMod.currentMainLoaded=="'.$moduleName.'") {
                                                                        top.currentSubScript="'.$origLink.'";
@@ -248,71 +258,107 @@ class alt_menu_functions {
                                                                        top.fsMod.currentMainLoaded="'.$moduleName.'";
                                                                }';
                                                }
-#                                              $selectItems[] = '<option value="'.htmlspecialchars($JScmd).'">'.htmlspecialchars("- ".$label).'</option>';
-                                               $selectItems[] = '<option value="top.goToModule(\''.$moduleName."_".$subName.'\');">'.htmlspecialchars("- ".$label).'</option>';
-                                               $onClickString = htmlspecialchars('top.goToModule(\''.$moduleName."_".$subName.'\');'.$onBlur.'return false;');
-                                               $flabel='<a href="#" onclick="'.$onClickString.'"'.$label_descr.'>'.$label.'</a>';
+                                               $selectItems[] = '<option value="top.goToModule(\''.$moduleName.'_'.$subName.'\');">'.htmlspecialchars('- '.$label).'</option>';
+                                               $onClickString = htmlspecialchars('top.goToModule(\''.$moduleName.'_'.$subName.'\');'.$onBlur.'return false;');
+                                               $flabel='<a href="#" onclick="'.$onClickString.'"'.$label_descr.'>'.htmlspecialchars($label).'</a>';
                                                $mIcons[]='<a href="#" onclick="'.$onClickString.'"'.$label_descr.'>'.$descr3_imageCode.'</a>';
-                                               $mJScmds[]="case '".$moduleName."_".$subName."': \n ".$JScmd." \n break;";
+                                               $mJScmds[]="case '".$moduleName.'_'.$subName."': \n ".$JScmd." \n break;";
                                        } 
                                        
-                                       $subCode.='<tr class="typo3-submenu">
-                                               <td></td>
-                                               <td valign="top" align="center">'.(!$GLOBALS['BE_USER']->uc['hideSubmoduleIcons']?$imageCode:"").'</td>
-                                               <td class="typo3-submenu-label">'.$flabel.'</td>
-                                       </tr>';
+                                       $subCode.='
+                                                       <tr class="c-subitem-row">
+                                                               <td></td>
+                                                               <td align="center">'.(!$BE_USER->uc['hideSubmoduleIcons']?$imageCode:'').'</td>
+                                                               <td class="c-subitem-label">'.$flabel.'</td>
+                                                       </tr>';
 
                                                // For "About modules":
                                        $descrCode.='
-                                       <tr>
-                                               <td colspan="3"><img src="clear.gif" width="1" height="5" alt="" /></td>
-                                       </tr>';
-                                       $descrCode.='
-                                       <tr>
-                                               <td valign="top" align="center">'.$imageCode.'</td>
-                                               <td valign="top" nowrap="nowrap">'.$flabel.'&nbsp;&nbsp;</td>
-                                               <td valign="top"><strong>'.$LANG->moduleLabels['labels'][$subKey.'label'].'</strong><br />'.$LANG->moduleLabels['labels'][$subKey.'descr'].'</td>
-                                       </tr>';
+                                                       <tr class="c-subitem-row">
+                                                               <td align="center">'.$imageCode.'</td>
+                                                               <td>'.$flabel.'&nbsp;&nbsp;</td>
+                                                               <td><strong>'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'</strong><br />'.$LANG->moduleLabels['labels'][$subKey.'descr'].'</td>
+                                                       </tr>';
 
                                                // Possibly adding a divider line
                                        $c++;
                                        if ($c<count($moduleInfo['sub']))       {
                                                        // Divider
-                                               $subCode.='<tr class="typo3-submenu-divrow">
-                                                       <td><img src="clear.gif" width="5" height="1" alt="" /></td>
-                                                       <td colspan="2"><img src="gfx/altmenuline.gif" width="105" height="3" alt="" /></td>
-                                               </tr>';
-                                       } else {
-                                                       // Space:
-                                               $subCode.='<tr class="typo3-submenu-endrow">
-                                                       <td colspan="3"><img src="clear.gif" width="1" height="4" alt="" /></td>
-                                               </tr>';
+                                               $subCode.='
+                                                       <tr class="c-divrow">
+                                                               <td colspan="3"><img'.t3lib_iconWorks::skinImg($backPath,'gfx/altmenuline.gif','width="105" height="3"').' alt="" /></td>
+                                                       </tr>';
                                        }
                                }
-                               if (count($theModules)>$mC)     $mIcons[]='<img src="'.$backPath.'gfx/acm_spacer2.gif" width="8" height="12" hspace="3" align="top" alt="" />';
-                       } else {
-                               $subCode.='<tr><td colspan="3"><img src="clear.gif" width="1" height="2" alt="" /></td></tr>';
+                                       // Spacer gif for top menu:
+                               if (count($theModules)>$mC)     {
+                                       $mIcons[]='<img src="'.$backPath.'gfx/acm_spacer2.gif" width="8" height="12" hspace="3" alt="" />';
+                               }
                        }
-
+                       
+                               // Add spacers after each main section:
+                       $subCode.='
+                                       <tr class="c-endrow">
+                                               <td colspan="3"></td>
+                                       </tr>';
+                       $descrCode.='
+                                       <tr class="c-endrow">
+                                               <td colspan="3"></td>
+                                       </tr>';
+                                       
+                               // Add sub-code:
                        $menuCode.=$subCode;
                }
                
                        // $descr==0:   Ordinary vertical menu
                if ($menuCode)  {
-                       $final = '<table border="0" cellpadding="0" cellspacing="0" width="1">'.$menuCode.'</table>';
+                       $final = '
+                       
+                       
+                               <!-- 
+                                       Vertical module menu, shown in left frame of backend.
+                               -->
+                               <table border="0" cellpadding="0" cellspacing="0" id="typo3-vmenu">
+                                       '.$menuCode.'
+                               </table>';
                }
 
                        // Output for the "About modules" module
                if ($descr==1)  {
-                       $descrCode = '<table border="0" cellpadding="0" cellspacing="0">'.$descrCode.'</table>';
+                       $descrCode = '
+                       
+                       
+                               <!-- 
+                                       Listing of modules, for Help > About modules
+                               -->
+                               <table border="0" cellpadding="0" cellspacing="0" id="typo3-about-modules">
+                                       '.$descrCode.'
+                               </table>';
                        $final = $descrCode;
                }
 
                        // selector-box menu
                if ($descr==2)  {
+
+                               // Add admin-functions for clearing caches:
+                       if ($BE_USER->isAdmin())        {
+                               $functionArray = $this->adminFunctions($backPath);
+                               if (count($functionArray))      {
+                                       $selectItems[] = '<option value=""></option>';
+                                       foreach($functionArray as $fAoptions)   {
+                                               $selectItems[] = '<option value="'.htmlspecialchars("document.location='".$fAoptions['href']."';").'">[ '.htmlspecialchars($fAoptions['title']).' ]</option>';
+                                       }
+                               }
+                       }
+
+                               // Logout item:
                        $selectItems[] = '<option value=""></option>';
-                       $selectItems[] = '<option value="'.htmlspecialchars("top.location='logout.php';").'">[ LOGOUT ]</option>';
-                       $final = '<select name="menuselector" onchange="eval(this.options[this.selectedIndex].value);">'.implode('',$selectItems).'</select>';
+                       $selectItems[] = '<option value="'.htmlspecialchars("top.location='logout.php';").'">[ '.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.logout',1).' ]</option>';
+                       $final = '
+                               <select name="menuselector" onchange="eval(this.options[this.selectedIndex].value);">
+                                       '.implode('
+                                       ',$selectItems).'
+                               </select>';
                }
                        // topmenu - horizontal line of icons!
                if ($descr==3)  {
@@ -329,9 +375,9 @@ class alt_menu_functions {
        }
 
        /**
-        * Returns $Ifilename readable for script in PATH_typo3. 
+        * Returns $Ifilename readable for script in PATH_typo3.
         * That means absolute names are just returned while relative names are prepended with $backPath (pointing back to typo3/ dir)
-        * 
+        *
         * @param       string          Icon filename
         * @param       string          Back path
         * @return      string          Result
@@ -346,7 +392,7 @@ class alt_menu_functions {
 
        /**
         * Returns relative filename to the $Ifilename (for use in img-tags)
-        * 
+        *
         * @param       string          Icon filename
         * @param       string          Back path
         * @return      string          Result
@@ -361,21 +407,72 @@ class alt_menu_functions {
 
        /**
         * Returns logout button.
-        * 
-        * @return      string          
+        *
+        * @return      string
         */
        function topButtons()   {
                global $LANG;
                        
-               $out.= '<form action="logout.php" target="_top" style="margin: 0 0 0 0;"><input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.logout',1).'" /></form>';
+               $out.= '<form action="logout.php" target="_top"><input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.logout',1).'" /></form>';
                return $out;
        }
 
        /**
+        * Returns logout button.
+        *
+        * @return      string
+        */
+       function adminButtons() {
+               global $LANG;
+               
+               $functionArray = $this->adminFunctions('');
+
+               $icons=array();         
+               foreach($functionArray as $fAoptions)   {
+                       $icons[]= '<a href="'.htmlspecialchars($fAoptions['href']).'">'.$fAoptions['icon'].'</a>';
+               }
+               
+               return implode('',$icons);
+       }
+
+       /**
+        * Returns array with parts from which the admin functions can be constructed.
+        *
+        * @param       string          Backpath.
+        * @return      array
+        */
+       function adminFunctions($backPath)      {
+               global $LANG,$BE_USER,$TYPO3_CONF_VARS;
+
+               $functions=array();
+               
+                       // Clearing of cache-files in typo3conf/ + menu
+               if ($TYPO3_CONF_VARS['EXT']['extCache'])        {
+                       $title = $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_allTypo3Conf');
+                       $functions[]=array(
+                               'title' => $title,
+                               'href' => $backPath.'tce_db.php?vC='.$BE_USER->veriCode().'&redirect='.rawurlencode(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT')).'&cacheCmd=temp_CACHED',
+                               'icon' => '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/clear_cache_files_in_typo3c.gif','width="21" height="18"').' title="'.htmlspecialchars($title).'" alt="" />'
+                       );
+               }
+
+                       // Clear all page cache
+               $title = $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_all');
+               $functions[]=array(
+                       'title' => $title,
+                       'href' => $backPath.'tce_db.php?vC='.$BE_USER->veriCode().'&redirect='.rawurlencode(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT')).'&cacheCmd=all',
+                       'icon' => '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/clear_all_cache.gif','width="21" height="18"').' title="'.htmlspecialchars($title).'" alt="" />'
+               );
+
+                       // Return functions
+               return $functions;
+       }
+
+       /**
         * Appends a '?' if there is none in the string already
-        * 
+        *
         * @param       string          Link URL
-        * @return      string          
+        * @return      string
         */
        function wrapLinkWithAB($link)  {
                if (!strstr($link,'?')) {