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