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