Updated copyright notices to show "2004"
[Packages/TYPO3.CMS.git] / typo3 / class.alt_menu_functions.inc
1 <?php
2 /***************************************************************
3 *  Copyright notice
4 *  
5 *  (c) 1999-2004 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  *  368:     function mIconFile($Ifilename,$backPath)   
46  *  383:     function mIconFilename($Ifilename,$backPath)       
47  *  395:     function topButtons()      
48  *  408:     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                                                 'fW="+top.TS.navFrameWidth+"'.
124                                                 '&nav='.rawurlencode($moduleInfo['navFrameScript']).
125                                                 '&script=';
126                                 }
127                                 $this->fsMod[]='fsMod.recentIds["'.$moduleName.'"]="";';
128                         }
129
130                                 // If there are submodules:
131                         if (is_array($moduleInfo['sub']))       {
132                                         // Finding the default module to display
133                                 if ($moduleInfo['defaultMod'])  {
134                                         $link=$moduleInfo['sub'][$moduleInfo['defaultMod']]['script'];
135                                 } else {
136                                         reset($moduleInfo['sub']);
137                                         $subTemp = current($moduleInfo['sub']);
138                                         $link=$subTemp['script'];
139                                 }
140                                 $link_sub=1;    // Tells that the main modules links to a submodule
141                                 $link='';       // Does not link to submodules...
142                         } else {
143                                 $link=$moduleInfo['script'];
144                                 $link_sub=0;
145                         }
146                         
147                         $moduleKey = $moduleName.'_tab';
148
149                                 // Creating image icon
150                         $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath));
151                         $imageCode='';
152                         $descr3_title = $LANG->moduleLabels['tabs'][$moduleKey].' ';
153                         if ($image)     {
154                                 $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath);
155                                 $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' alt="" />';
156                                 $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($descr3_title).'" alt="" />';
157                         } else {
158                                 $descr3_imageCode = '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/dummy_module.gif','width="14" height="12"').' title="'.htmlspecialchars($descr3_title).'" alt="" />';
159                         }
160                         
161                                 // Creating the various links:
162                         $label = $LANG->moduleLabels['tabs'][$moduleKey];
163                         $JScmd='this.selectedIndex=0;';
164                         if ($link && $prefix)   $link=$prefix.rawurlencode($link);
165                         if ($link && !$dontLink)        {
166                                 $JScmd='top.content.location=top.getModuleUrl(top.TS.PATH_typo3+\''.$this->wrapLinkWithAB($link).'\');';
167                                 $label='<a href="#" onclick="top.goToModule(\''.$moduleName.'\');'.$onBlur.'return false;">'.$label.'</a>';     //  && !$link_sub
168                                 $mIcons[]='<a href="#" onclick="top.goToModule(\''.$moduleName.'\');'.$onBlur.'return false;">'.$descr3_imageCode.'</a>';
169                                 $mJScmds[]="case '".$moduleName."': \n ".$JScmd." \n break;";
170                         }
171                          
172 #                       $selectItems[] = '<option value="'.htmlspecialchars($JScmd).'">'.htmlspecialchars($LANG->moduleLabels['tabs'][$moduleKey]).'</option>';
173                         $selectItems[] = '<option value="top.goToModule(\''.$moduleName.'\');">'.htmlspecialchars($LANG->moduleLabels['tabs'][$moduleKey]).'</option>';
174                         $label='&nbsp;<b>'.$label.'</b>&nbsp;';
175                         
176                                 // Creating a main item for the vertical menu (descr=0)
177                         $menuCode.='
178                                                 <tr class="c-mainitem">
179                                                         <td colspan="3">'.$imageCode.'<span class="c-label">'.$label.'</span></td>
180                                                 </tr>';
181
182                                 // Code for "About modules"
183                         $descrCode.='
184                                                 <tr class="c-mainitem bgColor4">
185                                                         <td colspan="3">'.$imageCode.$label.'</td>
186                                                 </tr>';
187
188
189
190                                 
191                                 // Travesing submodules
192                         $subCode='';
193                         if (is_array($moduleInfo['sub']))       {
194                                 reset($moduleInfo['sub']);
195                                 $c=0;
196                                 while(list($subName,$subInfo)=each($moduleInfo['sub'])) {
197                                         if ($c==0)              {
198                                                 $subCode.='
199                                                                 <tr class="c-first">
200                                                                         <td colspan="3"></td>
201                                                                 </tr>';
202                                                 $descrCode.='
203                                                                 <tr class="c-first">
204                                                                         <td colspan="3"></td>
205                                                                 </tr>';
206                                         }
207
208                                         $link = $subInfo['script'];
209                                         $subKey = $moduleName.'_'.$subName.'_tab';
210
211                                                 // Creating image icon
212                                         $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$subKey],$backPath));
213                                         $imageCode='';
214                                         $descr3_title = $LANG->moduleLabels['tabs'][$subKey].': '.$LANG->moduleLabels['labels'][$subKey.'label'];
215                                         if ($image)     {
216                                                 $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$subKey],$backPath);
217                                                 $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'" alt="" />';
218                                                 $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($descr3_title).'" alt="" />';
219                                         } else {
220                                                 $descr3_imageCode = '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/dummy_module.gif','width="14" height="12"').' title="'.htmlspecialchars($descr3_title).'" alt="" />';
221                                         }
222                                         
223                                                 // Label for submodule:
224                                         $label = $LANG->moduleLabels['tabs'][$subKey];
225                                         $label_descr = ' title="'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'"';
226                                         $flabel = htmlspecialchars($label);
227                                         $origLink = $link;
228                                         if ($link && $prefix)   $link=$prefix.rawurlencode($link);
229                                         
230                                                 // Setting additional JavaScript if frameset script:
231                                         $addJS = '';
232                                         if ($moduleInfo['navFrameScript'])      {$addJS="+'&id='+top.rawurlencode(top.fsMod.recentIds['".$moduleName."'])";}
233                                         
234                                                 // If there is a script to link to (and linking is not disabled.
235                                         if ($link && !$dontLink)        {
236                                                         // For condensed mode, send &cMR parameter to frameset script.
237                                                 if ($addJS && $GLOBALS['BE_USER']->uc['condensedMode']) {$addJS.=  "+(cMR?'&cMR=1':'')";}
238
239                                                         // Command for the selector box:
240                                                 $JScmd = "
241                                                                 top.content.location=top.getModuleUrl(top.TS.PATH_typo3+'".$this->wrapLinkWithAB($link)."'".$addJS.');
242                                                                 top.fsMod.currentMainLoaded="'.$moduleName.'";';
243
244                                                         // If there is a frameset script in place:
245                                                 if (!$GLOBALS['BE_USER']->uc['condensedMode'] && $moduleInfo['navFrameScript']) {
246                                                         $JScmd = '
247                                                                 if (top.content.list_frame && top.fsMod.currentMainLoaded=="'.$moduleName.'") {
248                                                                         top.currentSubScript="'.$origLink.'";
249                                                                         top.content.list_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->wrapLinkWithAB($origLink).'"'.$addJS.');
250                                                                 } else {
251                                                                         top.content.location=top.TS.PATH_typo3+(
252                                                                                 top.nextLoadModuleUrl?
253                                                                                 "'.($prefix?$this->wrapLinkWithAB($link).'&exScript=':'').'listframe_loader.php":
254                                                                                 "'.$this->wrapLinkWithAB($link).'"'.$addJS.'
255                                                                         );
256                                                                         top.fsMod.currentMainLoaded="'.$moduleName.'";
257                                                                 }';
258                                                 }
259                                                 $selectItems[] = '<option value="top.goToModule(\''.$moduleName.'_'.$subName.'\');">'.htmlspecialchars('- '.$label).'</option>';
260                                                 $onClickString = htmlspecialchars('top.goToModule(\''.$moduleName.'_'.$subName.'\');'.$onBlur.'return false;');
261                                                 $flabel='<a href="#" onclick="'.$onClickString.'"'.$label_descr.'>'.htmlspecialchars($label).'</a>';
262                                                 $mIcons[]='<a href="#" onclick="'.$onClickString.'"'.$label_descr.'>'.$descr3_imageCode.'</a>';
263                                                 $mJScmds[]="case '".$moduleName.'_'.$subName."': \n ".$JScmd." \n break;";
264                                         } 
265                                         
266                                         $subCode.='
267                                                         <tr class="c-subitem-row">
268                                                                 <td></td>
269                                                                 <td align="center">'.(!$GLOBALS['BE_USER']->uc['hideSubmoduleIcons']?$imageCode:'').'</td>
270                                                                 <td class="c-subitem-label">'.$flabel.'</td>
271                                                         </tr>';
272
273                                                 // For "About modules":
274                                         $descrCode.='
275                                                         <tr class="c-subitem-row">
276                                                                 <td align="center">'.$imageCode.'</td>
277                                                                 <td>'.$flabel.'&nbsp;&nbsp;</td>
278                                                                 <td><strong>'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'</strong><br />'.$LANG->moduleLabels['labels'][$subKey.'descr'].'</td>
279                                                         </tr>';
280
281                                                 // Possibly adding a divider line
282                                         $c++;
283                                         if ($c<count($moduleInfo['sub']))       {
284                                                         // Divider
285                                                 $subCode.='
286                                                         <tr class="c-divrow">
287                                                                 <td colspan="3"><img'.t3lib_iconWorks::skinImg($backPath,'gfx/altmenuline.gif','width="105" height="3"').' alt="" /></td>
288                                                         </tr>';
289                                         }
290                                 }
291                                         // Spacer gif for top menu:
292                                 if (count($theModules)>$mC)     {
293                                         $mIcons[]='<img src="'.$backPath.'gfx/acm_spacer2.gif" width="8" height="12" hspace="3" alt="" />';
294                                 }
295                         }
296                         
297                                 // Add spacers after each main section:
298                         $subCode.='
299                                         <tr class="c-endrow">
300                                                 <td colspan="3"></td>
301                                         </tr>';
302                         $descrCode.='
303                                         <tr class="c-endrow">
304                                                 <td colspan="3"></td>
305                                         </tr>';
306                                         
307                                 // Add sub-code:
308                         $menuCode.=$subCode;
309                 }
310                 
311                         // $descr==0:   Ordinary vertical menu
312                 if ($menuCode)  {
313                         $final = '
314                         
315                         
316                                 <!-- 
317                                         Vertical module menu, shown in left frame of backend.
318                                 -->
319                                 <table border="0" cellpadding="0" cellspacing="0" id="typo3-vmenu">
320                                         '.$menuCode.'
321                                 </table>';
322                 }
323
324                         // Output for the "About modules" module
325                 if ($descr==1)  {
326                         $descrCode = '
327                         
328                         
329                                 <!-- 
330                                         Listing of modules, for Help > About modules
331                                 -->
332                                 <table border="0" cellpadding="0" cellspacing="0" id="typo3-about-modules">
333                                         '.$descrCode.'
334                                 </table>';
335                         $final = $descrCode;
336                 }
337
338                         // selector-box menu
339                 if ($descr==2)  {
340                         $selectItems[] = '<option value=""></option>';
341                         $selectItems[] = '<option value="'.htmlspecialchars("top.location='logout.php';").'">[ '.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.logout',1).' ]</option>';
342                         $final = '
343                                 <select name="menuselector" onchange="eval(this.options[this.selectedIndex].value);">
344                                         '.implode('
345                                         ',$selectItems).'
346                                 </select>';
347                 }
348                         // topmenu - horizontal line of icons!
349                 if ($descr==3)  {
350                         $final = ''.implode('',$mIcons).'';
351                 }
352
353                         // Output for the goToModules() function in main frameset.
354                 if ($descr==4)  {
355                         $final = chr(10).implode(chr(10),$mJScmds).chr(10);
356                 }
357
358                         // Return result:
359                 return $final;
360         }
361
362         /**
363          * Returns $Ifilename readable for script in PATH_typo3. 
364          * That means absolute names are just returned while relative names are prepended with $backPath (pointing back to typo3/ dir)
365          * 
366          * @param       string          Icon filename
367          * @param       string          Back path
368          * @return      string          Result
369          * @see mIconFilename()
370          */
371         function mIconFile($Ifilename,$backPath)        {
372                 if (t3lib_div::isAbsPath($Ifilename))   {
373                         return $Ifilename;
374                 }
375                 return $backPath.$Ifilename;
376         }
377
378         /**
379          * Returns relative filename to the $Ifilename (for use in img-tags)
380          * 
381          * @param       string          Icon filename
382          * @param       string          Back path
383          * @return      string          Result
384          * @see mIconFile()
385          */
386         function mIconFilename($Ifilename,$backPath)    {
387                 if (t3lib_div::isAbsPath($Ifilename))   {
388                         $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
389                 }
390                 return $backPath.$Ifilename;
391         }
392
393         /**
394          * Returns logout button.
395          * 
396          * @return      string          
397          */
398         function topButtons()   {
399                 global $LANG;
400                         
401                 $out.= '<form action="logout.php" target="_top"><input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.logout',1).'" /></form>';
402                 return $out;
403         }
404
405         /**
406          * Appends a '?' if there is none in the string already
407          * 
408          * @param       string          Link URL
409          * @return      string          
410          */
411         function wrapLinkWithAB($link)  {
412                 if (!strstr($link,'?')) {
413                         return $link.'?';
414                 } else return $link;
415         }
416 }
417
418
419 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.alt_menu_functions.inc'])      {
420         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.alt_menu_functions.inc']);
421 }
422 ?>