Added $Id$ keywords, cleaned up comment tags
[Packages/TYPO3.CMS.git] / typo3 / class.alt_menu_functions.inc
1 <?php
2 /***************************************************************
3 *  Copyright notice
4 *  
5 *  (c) 1999-2003 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  * Class for generation of the module menu.
29  *
30  * Will make the the vertical, horizontal, selectorbox based menus AND the "about modules" display.
31  * Basically it traverses the module structure and generates output based on that.
32  * 
33  * @author      Kasper Skaarhoj <kasper@typo3.com>
34  * @package TYPO3
35  * @subpackage core
36  *
37  * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
38  * XHTML compliant content
39  */
40
41  
42 class alt_menu_functions {
43
44                 // Internal
45         var $fsMod = array();
46
47         /**
48          * Creates the menu of modules.
49          * 
50          * $theModules is the output from load_modules class ($this->loadModules->modules)
51          * $descr determines the type of menu made:
52          *              0 = Ordinary vertical menu
53          *              1 = Descriptions for 'About modules' display
54          *              2 = selector-box menu
55          *              3 = topmenu - horizontal line of icons!
56          *              4 = part of JavaScript switch contruct for alt_main.php frameset.
57          * $dontLink == true will prevent the output from being linked with A-tags (used in the 'beuser' extension)
58          * $backPath must be the 'backPath' to PATH_typo3 from where the the menu is displayed.
59          */
60         function topMenu($theModules,$dontLink=0,$backPath='',$descr=0) {
61                 global $LANG, $TBE_TEMPLATE;
62         
63                         // Initialize vars:
64                 $final='';
65                 $menuCode='';
66                 $descrCode='';
67                 $menuCode_sub='';
68                 $selectItems=array();
69                 $mIcons=array();
70                 $mJScmds=array();
71                 $onBlur=$GLOBALS['CLIENT']['FORMSTYLE'] ? 'this.blur();' : '';
72         
73                 $selectItems[] = '<option value="">[ MODULES ]</option>';
74                 $mC=0;
75         
76                         // Remove the 'doc' module?
77                 if ($GLOBALS['BE_USER']->getTSConfigVal('options.disableDocModuleInAB'))        {
78                         unset($theModules['doc']);
79                 }
80         
81                         // Traverse array with modules
82                 reset($theModules);
83                 while(list($moduleName,$moduleInfo)=each($theModules))  {
84                         $mC++;
85
86                         $prefix='';
87                         if ($moduleInfo["navFrameScript"])      {
88                                 if ($GLOBALS['BE_USER']->uc['condensedMode'])   {
89                                         $prefix=$moduleInfo["navFrameScript"].'?currentSubScript=';
90                                 } else {
91                                         $prefix='alt_mod_frameset.php?'.
92                                                 '&nav='.$moduleInfo["navFrameScript"].
93                                                 '&script=';
94                                 }
95                                 $this->fsMod[]='fsMod.recentIds["'.$moduleName.'"]="";';
96                         }
97
98                                 // If there are submodules:
99                         if (is_array($moduleInfo['sub']))       {
100                                         // Finding the default module to display
101                                 if ($moduleInfo['defaultMod'])  {
102                                         $link=$moduleInfo['sub'][$moduleInfo['defaultMod']]['script'];
103                                 } else {
104                                         reset($moduleInfo['sub']);
105                                         $subTemp = current($moduleInfo['sub']);
106                                         $link=$subTemp['script'];
107                                 }
108                                 $link_sub=1;    // Tells that the main modules links to a submodule
109                                 $link='';       // Does not link to submodules...
110                         } else {
111                                 $link=$moduleInfo['script'];
112                                 $link_sub=0;
113                         }
114                         
115                         $moduleKey = $moduleName.'_tab';
116
117                                 // Creating image icon
118                         $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath));
119                         $imageCode='';
120                         $descr3_title = t3lib_BEfunc::titleAttrib($LANG->moduleLabels['tabs'][$moduleKey].' ');
121                         if ($image)     {
122                                 $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath);
123                                 $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' align="top" alt="" />';
124                                 $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' align="top" border="0"'.$descr3_title.' alt="" />';
125                         } else {
126                                 $descr3_imageCode = '<img src="'.$backPath.'gfx/dummy_module.gif" width="14" height="12" align="top" border="0"'.$descr3_title.' alt="" />';
127                         }
128                         
129                                 // Creating the various links:
130                         $label = $LANG->moduleLabels['tabs'][$moduleKey];
131                         $JScmd='this.selectedIndex=0;';
132                         if ($link && $prefix)   $link=$prefix.rawurlencode($link);
133                         if ($link && !$dontLink)        {
134                                 $JScmd='top.content.location=top.getModuleUrl(top.TS.PATH_typo3+\''.$this->wrapLinkWithAB($link).'\');';
135                                 $label='<a href="#" onclick="top.goToModule(\''.$moduleName.'\');'.$onBlur.'return false;">'.$label.'</a>';     //  && !$link_sub
136                                 $mIcons[]='<a href="#" onclick="top.goToModule(\''.$moduleName.'\');'.$onBlur.'return false;">'.$descr3_imageCode.'</a>';
137                                 $mJScmds[]="case '".$moduleName."': \n ".$JScmd." \n break;";
138                         }
139                          
140 #                       $selectItems[] = '<option value="'.htmlspecialchars($JScmd).'">'.htmlspecialchars($LANG->moduleLabels['tabs'][$moduleKey]).'</option>';
141                         $selectItems[] = '<option value="top.goToModule(\''.$moduleName.'\');">'.htmlspecialchars($LANG->moduleLabels['tabs'][$moduleKey]).'</option>';
142                         $label='&nbsp;<b>'.$label.'</b>&nbsp;';
143                         
144                                 // Creating a main item for the vertical menu (descr=0)
145                         $modItemCode=$imageCode.$label;
146                         $modItemCode='<div class="typo3-mainmenu-inner">'.$modItemCode.'</div>';
147                         $modItemCode='<tr>
148                                 <td colspan="3" class="typo3-mainmenu-outer">'.$modItemCode.'</td>
149                                 </tr>';
150                         $menuCode.=$modItemCode;
151
152                                 // Code for "About modules"
153                         $descrCode.='<tr>
154                                 <td colspan="3"><img src="clear.gif" width="1" height="10" alt="" /></td>
155                                 </tr>';
156                         $descrCode.='<tr>
157                                 <td colspan="3" class="typo3-aboutmod-outer" bgcolor="'.$TBE_TEMPLATE->bgColor4.'" nowrap="nowrap">'.$imageCode.$label.'</td>
158                                 </tr>';
159
160
161
162                                 
163                                 // Travesing submodules
164                         $subCode='';
165                         if (is_array($moduleInfo['sub']))       {
166                                 reset($moduleInfo['sub']);
167                                 $c=0;
168                                 while(list($subName,$subInfo)=each($moduleInfo['sub'])) {
169                                         if ($c==0)              $subCode.='<tr><td colspan="3"><img src="clear.gif" width="1" height="2" alt="" /></td></tr>';
170
171                                         $link = $subInfo['script'];
172                                         $subKey = $moduleName.'_'.$subName.'_tab';
173
174                                                 // Creating image icon
175                                         $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$subKey],$backPath));
176                                         $imageCode='';
177                                         $descr3_title = t3lib_BEfunc::titleAttrib($LANG->moduleLabels['tabs'][$subKey].': '.$LANG->moduleLabels['labels'][$subKey.'label']);
178                                         if ($image)     {
179                                                 $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$subKey],$backPath);
180                                                 $imageCode = '<img src="'.$Ifilename.'" '.$image[3].t3lib_BEfunc::titleAttrib($LANG->moduleLabels['labels'][$subKey.'label'].' ').' alt="" />';
181                                                 $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' align="top" border="0"'.$descr3_title.' alt="" />';
182                                         } else {
183                                                 $descr3_imageCode = '<img src="'.$backPath.'gfx/dummy_module.gif" width="14" height="12" align="top" border="0"'.$descr3_title.' alt="" />';
184                                         }
185                                         
186                                                 // Label for submodule:
187                                         $label = $LANG->moduleLabels['tabs'][$subKey];
188                                         $label_descr = ' title="'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'"';
189                                         $flabel = $label;
190                                         $origLink = $link;
191                                         if ($link && $prefix)   $link=$prefix.rawurlencode($link);
192                                         
193                                                 // Setting additional JavaScript if frameset script:
194                                         $addJS = '';
195                                         if ($moduleInfo["navFrameScript"])      {$addJS="+'&id='+top.rawurlencode(top.fsMod.recentIds['".$moduleName."'])";}
196                                         
197                                                 // If there is a script to link to (and linking is not disabled.
198                                         if ($link && !$dontLink)        {
199                                                         // For condensed mode, send &cMR parameter to frameset script.
200                                                 if ($addJS && $GLOBALS['BE_USER']->uc['condensedMode']) {$addJS.=  "+(cMR?'&cMR=1':'')";}
201
202                                                         // Command for the selector box:
203                                                 $JScmd = "top.content.location=top.getModuleUrl(top.TS.PATH_typo3+'".$this->wrapLinkWithAB($link)."'".$addJS.");";
204
205                                                         // If there is a frameset script in place:
206                                                 if (!$GLOBALS['BE_USER']->uc['condensedMode'] && $moduleInfo["navFrameScript"]) {
207                                                         $JScmd = '
208                                                                 if (top.content.list_frame && top.fsMod.currentMainLoaded=="'.$moduleName.'") {
209                                                                         top.currentSubScript="'.$origLink.'";
210                                                                         top.content.list_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->wrapLinkWithAB($origLink).'"'.$addJS.');
211                                                                 } else {
212                                                                         top.content.location=top.TS.PATH_typo3+(
213                                                                                 top.nextLoadModuleUrl?
214                                                                                 "'.($prefix?$this->wrapLinkWithAB($link).'&exScript=':'').'listframe_loader.php":
215                                                                                 "'.$this->wrapLinkWithAB($link).'"'.$addJS.'
216                                                                         );
217                                                                         top.fsMod.currentMainLoaded="'.$moduleName.'";
218                                                                 }';
219                                                 }
220 #                                               $selectItems[] = '<option value="'.htmlspecialchars($JScmd).'">'.htmlspecialchars("- ".$label).'</option>';
221                                                 $selectItems[] = '<option value="top.goToModule(\''.$moduleName."_".$subName.'\');">'.htmlspecialchars("- ".$label).'</option>';
222                                                 $onClickString = htmlspecialchars('top.goToModule(\''.$moduleName."_".$subName.'\');'.$onBlur.'return false;');
223                                                 $flabel='<a href="#" onclick="'.$onClickString.'"'.$label_descr.'>'.$label.'</a>';
224                                                 $mIcons[]='<a href="#" onclick="'.$onClickString.'"'.$label_descr.'>'.$descr3_imageCode.'</a>';
225                                                 $mJScmds[]="case '".$moduleName."_".$subName."': \n ".$JScmd." \n break;";
226                                         } 
227                                         
228                                         $subCode.='<tr class="typo3-submenu">
229                                                 <td></td>
230                                                 <td valign="top" align="center">'.(!$GLOBALS['BE_USER']->uc['hideSubmoduleIcons']?$imageCode:"").'</td>
231                                                 <td class="typo3-submenu-label">'.$flabel.'</td>
232                                         </tr>';
233
234                                                 // For "About modules":
235                                         $descrCode.='
236                                         <tr>
237                                                 <td colspan="3"><img src="clear.gif" width="1" height="5" alt="" /></td>
238                                         </tr>';
239                                         $descrCode.='
240                                         <tr>
241                                                 <td valign="top" align="center">'.$imageCode.'</td>
242                                                 <td valign="top" nowrap="nowrap">'.$flabel.'&nbsp;&nbsp;</td>
243                                                 <td valign="top"><strong>'.$LANG->moduleLabels['labels'][$subKey.'label'].'</strong><br />'.$LANG->moduleLabels['labels'][$subKey.'descr'].'</td>
244                                         </tr>';
245
246                                                 // Possibly adding a divider line
247                                         $c++;
248                                         if ($c<count($moduleInfo['sub']))       {
249                                                         // Divider
250                                                 $subCode.='<tr class="typo3-submenu-divrow">
251                                                         <td><img src="clear.gif" width="5" height="1" alt="" /></td>
252                                                         <td colspan="2"><img src="gfx/altmenuline.gif" width="105" height="3" alt="" /></td>
253                                                 </tr>';
254                                         } else {
255                                                         // Space:
256                                                 $subCode.='<tr class="typo3-submenu-endrow">
257                                                         <td colspan="3"><img src="clear.gif" width="1" height="4" alt="" /></td>
258                                                 </tr>';
259                                         }
260                                 }
261                                 if (count($theModules)>$mC)     $mIcons[]='<img src="'.$backPath.'gfx/acm_spacer2.gif" width="8" height="12" hspace="3" align="top" alt="" />';
262                         } else {
263                                 $subCode.='<tr><td colspan="3"><img src="clear.gif" width="1" height="2" alt="" /></td></tr>';
264                         }
265
266                         $menuCode.=$subCode;
267                 }
268                 
269                         // $descr==0:   Ordinary vertical menu
270                 if ($menuCode)  {
271                         $final = '<table border="0" cellpadding="0" cellspacing="0" width="1">'.$menuCode.'</table>';
272                 }
273
274                         // Output for the "About modules" module
275                 if ($descr==1)  {
276                         $descrCode = '<table border="0" cellpadding="0" cellspacing="0">'.$descrCode.'</table>';
277                         $final = $descrCode;
278                 }
279
280                         // selector-box menu
281                 if ($descr==2)  {
282                         $selectItems[] = '<option value=""></option>';
283                         $selectItems[] = '<option value="'.htmlspecialchars("top.location='logout.php';").'">[ LOGOUT ]</option>';
284                         $final = '<select name="menuselector" onchange="eval(this.options[this.selectedIndex].value);">'.implode('',$selectItems).'</select>';
285                 }
286                         // topmenu - horizontal line of icons!
287                 if ($descr==3)  {
288                         $final = ''.implode('',$mIcons).'';
289                 }
290
291                         // Output for the goToModules() function in main frameset.
292                 if ($descr==4)  {
293                         $final = chr(10).implode(chr(10),$mJScmds).chr(10);
294                 }
295
296                         // Return result:
297                 return $final;
298         }
299
300         /**
301          * Returns $Ifilename readable for script in PATH_typo3. 
302          * That means absolute names are just returned while relative names are prepended with $backPath (pointing back to typo3/ dir)
303          */
304         function mIconFile($Ifilename,$backPath)        {
305                 if (t3lib_div::isAbsPath($Ifilename))   {
306                         return $Ifilename;
307                 }
308                 return $backPath.$Ifilename;
309         }
310
311         /**
312          * Returns relative filename to the $Ifilename (for use in img-tags)
313          */
314         function mIconFilename($Ifilename,$backPath)    {
315                 if (t3lib_div::isAbsPath($Ifilename))   {
316                         $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
317                 }
318                 return $backPath.$Ifilename;
319         }
320
321         /**
322          * Returns logout button.
323          */
324         function topButtons()   {
325                 global $LANG;
326                         
327                 $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>';
328                 return $out;
329         }
330
331         /**
332          * Appends a '?' if there is none in the string already
333          */
334         function wrapLinkWithAB($link)  {
335                 if (!strstr($link,'?')) {
336                         return $link.'?';
337                 } else return $link;
338         }
339 }
340
341
342 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.alt_menu_functions.inc'])      {
343         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.alt_menu_functions.inc']);
344 }
345
346 ?>