added support for different navFrameScripts for each submodule
[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  *   72: class alt_menu_functions
44  *   93:     function topMenu($theModules,$dontLink=0,$backPath='',$descr=0)
45  *  386:     function mIconFile($Ifilename,$backPath)
46  *  401:     function mIconFilename($Ifilename,$backPath)
47  *  413:     function topButtons()
48  *  425:     function adminButtons()
49  *  444:     function adminFunctions($backPath)
50  *  477:     function wrapLinkWithAB($link)
51  *
52  * TOTAL FUNCTIONS: 7
53  * (This index is automatically created/updated by the extension "extdeveval")
54  *
55  */
56
57  
58
59
60
61
62
63
64
65 /**
66  * Class with menu functions
67  * 
68  * @author      Kasper Skaarhoj <kasper@typo3.com>
69  * @package TYPO3
70  * @subpackage core
71  */
72 class alt_menu_functions {
73
74                 // Internal
75         var $fsMod = array();
76
77         /**
78          * Creates the menu of modules.
79          * 
80          * $descr determines the type of menu made:
81          *              0 = Ordinary vertical menu
82          *              1 = Descriptions for 'About modules' display
83          *              2 = selector-box menu
84          *              3 = topmenu - horizontal line of icons!
85          *              4 = part of JavaScript switch contruct for alt_main.php frameset.
86          * 
87          * @param       array           $theModules is the output from load_modules class ($this->loadModules->modules)
88          * @param       boolean         $dontLink == true will prevent the output from being linked with A-tags (used in the 'beuser' extension)
89          * @param       string          $backPath must be the 'backPath' to PATH_typo3 from where the the menu is displayed.
90          * @param       integer         $descr determines the type of menu made (see above)
91          * @return      string          The menu HTML
92          */
93         function topMenu($theModules,$dontLink=0,$backPath='',$descr=0) {
94                 global $LANG, $TBE_TEMPLATE, $BE_USER;
95         
96                         // Initialize vars:
97                 $final='';
98                 $menuCode='';
99                 $descrCode='';
100                 $menuCode_sub='';
101                 $selectItems=array();
102                 $mIcons=array();
103                 $mJScmds=array();
104                 $onBlur=$GLOBALS['CLIENT']['FORMSTYLE'] ? 'this.blur();' : '';
105         
106                 $selectItems[] = '<option value="">[ '.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.selMenu_modules',1).' ]</option>';
107                 $mC=0;
108         
109                         // Remove the 'doc' module?
110                 if ($BE_USER->getTSConfigVal('options.disableDocModuleInAB'))   {
111                         unset($theModules['doc']);
112                 }
113         
114                         // Traverse array with modules
115                 reset($theModules);
116                 while(list($moduleName,$moduleInfo)=each($theModules))  {
117                         $mC++;
118
119                         $prefix='';
120                         if ($moduleInfo['navFrameScript'])      {
121                                 if ($BE_USER->uc['condensedMode'])      {
122                                         $prefix=$moduleInfo['navFrameScript'].'?currentSubScript=';
123                                 } else {
124                                         $prefix='alt_mod_frameset.php?'.
125                                                 'fW="+top.TS.navFrameWidth+"'.
126                                                 '&nav='.rawurlencode($moduleInfo['navFrameScript']).
127                                                 '&script=';
128                                 }
129                                 $this->fsMod[]='fsMod.recentIds["'.$moduleName.'"]="";';
130                         }
131
132                                 // If there are submodules:
133                         if (is_array($moduleInfo['sub']))       {
134                                         // Finding the default module to display
135                                 if ($moduleInfo['defaultMod'])  {
136                                         $link=$moduleInfo['sub'][$moduleInfo['defaultMod']]['script'];
137                                 } else {
138                                         reset($moduleInfo['sub']);
139                                         $subTemp = current($moduleInfo['sub']);
140                                         $link=$subTemp['script'];
141                                 }
142                                 $link_sub=1;    // Tells that the main modules links to a submodule
143                                 $link='';       // Does not link to submodules...
144                         } else {
145                                 $link=$moduleInfo['script'];
146                                 $link_sub=0;
147                         }
148                         
149                         $moduleKey = $moduleName.'_tab';
150
151                                 // Creating image icon
152                         $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath));
153                         $imageCode='';
154                         $descr3_title = $LANG->moduleLabels['tabs'][$moduleKey].' ';
155                         if ($image)     {
156                                 $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath);
157                                 $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' alt="" />';
158                                 $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($descr3_title).'" alt="" />';
159                         } else {
160                                 $descr3_imageCode = '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/dummy_module.gif','width="14" height="12"').' title="'.htmlspecialchars($descr3_title).'" alt="" />';
161                         }
162                         
163                                 // Creating the various links:
164                         $label = $LANG->moduleLabels['tabs'][$moduleKey];
165                         $JScmd='this.selectedIndex=0;';
166                         if ($link && $prefix)   $link=$prefix.rawurlencode($link);
167                         if ($link && !$dontLink)        {
168                                 $JScmd='top.content.location=top.getModuleUrl(top.TS.PATH_typo3+\''.$this->wrapLinkWithAB($link).'\');';
169                                 $label='<a href="#" onclick="top.goToModule(\''.$moduleName.'\');'.$onBlur.'return false;">'.$label.'</a>';     //  && !$link_sub
170                                 $mIcons[]='<a href="#" onclick="top.goToModule(\''.$moduleName.'\');'.$onBlur.'return false;">'.$descr3_imageCode.'</a>';
171                                 $mJScmds[]="case '".$moduleName."': \n ".$JScmd." \n break;";
172                         }
173                          
174 #                       $selectItems[] = '<option value="'.htmlspecialchars($JScmd).'">'.htmlspecialchars($LANG->moduleLabels['tabs'][$moduleKey]).'</option>';
175                         $selectItems[] = '<option value="top.goToModule(\''.$moduleName.'\');">'.htmlspecialchars($LANG->moduleLabels['tabs'][$moduleKey]).'</option>';
176                         $label='&nbsp;<b>'.$label.'</b>&nbsp;';
177                         
178                                 // Creating a main item for the vertical menu (descr=0)
179                         $menuCode.='
180                                                 <tr class="c-mainitem">
181                                                         <td colspan="3">'.$imageCode.'<span class="c-label">'.$label.'</span></td>
182                                                 </tr>';
183
184                                 // Code for "About modules"
185                         $descrCode.='
186                                                 <tr class="c-mainitem bgColor4">
187                                                         <td colspan="3">'.$imageCode.$label.'</td>
188                                                 </tr>';
189
190
191
192                                 
193                                 // Travesing submodules
194                         $subCode='';
195                         if (is_array($moduleInfo['sub']))       {
196                                 reset($moduleInfo['sub']);
197                                 $c=0;
198                                 while(list($subName,$subInfo)=each($moduleInfo['sub'])) {
199                                         if ($c==0)              {
200                                                 $subCode.='
201                                                                 <tr class="c-first">
202                                                                         <td colspan="3"></td>
203                                                                 </tr>';
204                                                 $descrCode.='
205                                                                 <tr class="c-first">
206                                                                         <td colspan="3"></td>
207                                                                 </tr>';
208                                         }
209
210                                         $link = $subInfo['script'];
211                                         $subKey = $moduleName.'_'.$subName.'_tab';
212
213                                                 // Creating image icon
214                                         $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$subKey],$backPath));
215                                         $imageCode='';
216                                         $descr3_title = $LANG->moduleLabels['tabs'][$subKey].': '.$LANG->moduleLabels['labels'][$subKey.'label'];
217                                         if ($image)     {
218                                                 $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$subKey],$backPath);
219                                                 $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'" alt="" />';
220                                                 $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($descr3_title).'" alt="" />';
221                                         } else {
222                                                 $descr3_imageCode = '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/dummy_module.gif','width="14" height="12"').' title="'.htmlspecialchars($descr3_title).'" alt="" />';
223                                         }
224                                         
225                                                 // Label for submodule:
226                                         $label = $LANG->moduleLabels['tabs'][$subKey];
227                                         $label_descr = ' title="'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'"';
228                                         $flabel = htmlspecialchars($label);
229                                         $origLink = $link;
230                                         if ($link && $prefix)   $link=$prefix.rawurlencode($link);
231                                         
232                                                 // Setting additional JavaScript if frameset script:
233                                         $addJS = '';
234                                         if ($moduleInfo['navFrameScript'])      {$addJS="+'&id='+top.rawurlencode(top.fsMod.recentIds['".$moduleName."'])";}
235                                         
236                                                 // If there is a script to link to (and linking is not disabled.
237                                         if ($link && !$dontLink)        {
238                                                         // For condensed mode, send &cMR parameter to frameset script.
239                                                 if ($addJS && $BE_USER->uc['condensedMode'])    {$addJS.=  "+(cMR?'&cMR=1':'')";}
240
241                                                         // Command for the selector box:
242                                                 $JScmd = "
243                                                                 top.content.location=top.getModuleUrl(top.TS.PATH_typo3+'".$this->wrapLinkWithAB($link)."'".$addJS.');
244                                                                 top.fsMod.currentMainLoaded="'.$moduleName.'";';
245
246                                                         // If there is a frameset script in place:
247                                                 if (!$BE_USER->uc['condensedMode'] && $moduleInfo['navFrameScript'])    {
248                                                         
249                                                                 // use special nav script from sub module, otherwise from the main module
250                                                         $subNavFrameScript = $subInfo['navFrameScript'] ? $subInfo['navFrameScript'] : $moduleInfo['navFrameScript'] ;
251                                                         
252                                                                 // should we add GET params for sub module to the nav script?
253                                                         if ($subInfo['navFrameScriptParam']) {
254                                                                 $subNavFrameScript = $this->wrapLinkWithAB($subNavFrameScript).$subInfo['navFrameScriptParam'];
255                                                         }
256                                                         
257                                                         $JScmd = '
258                                                                 if (top.content.list_frame && top.fsMod.currentMainLoaded=="'.$moduleName.'") {
259                                                                         top.currentSubScript="'.$origLink.'";
260                                                                         top.content.list_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->wrapLinkWithAB($origLink).'"'.$addJS.');
261                                                                         if(top.currentSubNavScript!="'.$subNavFrameScript.'") {
262                                                                                 top.currentSubNavScript="'.$subNavFrameScript.'";
263                                                                                 top.content.nav_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->wrapLinkWithAB($subNavFrameScript).'");
264                                                                         }
265                                                                 } else {
266                                                                         top.content.location=top.TS.PATH_typo3+(
267                                                                                 top.nextLoadModuleUrl?
268                                                                                 "'.($prefix?$this->wrapLinkWithAB($link).'&exScript=':'').'listframe_loader.php":
269                                                                                 "'.$this->wrapLinkWithAB($link).'"'.$addJS.'
270                                                                         );
271                                                                         top.fsMod.currentMainLoaded="'.$moduleName.'";
272                                                                 }';
273                                                 }
274                                                 $selectItems[] = '<option value="top.goToModule(\''.$moduleName.'_'.$subName.'\');">'.htmlspecialchars('- '.$label).'</option>';
275                                                 $onClickString = htmlspecialchars('top.goToModule(\''.$moduleName.'_'.$subName.'\');'.$onBlur.'return false;');
276                                                 $flabel='<a href="#" onclick="'.$onClickString.'"'.$label_descr.'>'.htmlspecialchars($label).'</a>';
277                                                 $mIcons[]='<a href="#" onclick="'.$onClickString.'"'.$label_descr.'>'.$descr3_imageCode.'</a>';
278                                                 $mJScmds[]="case '".$moduleName.'_'.$subName."': \n ".$JScmd." \n break;";
279                                         } 
280                                         
281                                         $subCode.='
282                                                         <tr class="c-subitem-row">
283                                                                 <td></td>
284                                                                 <td align="center">'.(!$BE_USER->uc['hideSubmoduleIcons']?$imageCode:'').'</td>
285                                                                 <td class="c-subitem-label">'.$flabel.'</td>
286                                                         </tr>';
287
288                                                 // For "About modules":
289                                         $descrCode.='
290                                                         <tr class="c-subitem-row">
291                                                                 <td align="center">'.$imageCode.'</td>
292                                                                 <td>'.$flabel.'&nbsp;&nbsp;</td>
293                                                                 <td><strong>'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'</strong><br />'.$LANG->moduleLabels['labels'][$subKey.'descr'].'</td>
294                                                         </tr>';
295
296                                                 // Possibly adding a divider line
297                                         $c++;
298                                         if ($c<count($moduleInfo['sub']))       {
299                                                         // Divider
300                                                 $subCode.='
301                                                         <tr class="c-divrow">
302                                                                 <td colspan="3"><img'.t3lib_iconWorks::skinImg($backPath,'gfx/altmenuline.gif','width="105" height="3"').' alt="" /></td>
303                                                         </tr>';
304                                         }
305                                 }
306                                         // Spacer gif for top menu:
307                                 if (count($theModules)>$mC)     {
308                                         $mIcons[]='<img src="'.$backPath.'gfx/acm_spacer2.gif" width="8" height="12" hspace="3" alt="" />';
309                                 }
310                         }
311                         
312                                 // Add spacers after each main section:
313                         $subCode.='
314                                         <tr class="c-endrow">
315                                                 <td colspan="3"></td>
316                                         </tr>';
317                         $descrCode.='
318                                         <tr class="c-endrow">
319                                                 <td colspan="3"></td>
320                                         </tr>';
321                                         
322                                 // Add sub-code:
323                         $menuCode.=$subCode;
324                 }
325                 
326                         // $descr==0:   Ordinary vertical menu
327                 if ($menuCode)  {
328                         $final = '
329                         
330                         
331                                 <!-- 
332                                         Vertical module menu, shown in left frame of backend.
333                                 -->
334                                 <table border="0" cellpadding="0" cellspacing="0" id="typo3-vmenu">
335                                         '.$menuCode.'
336                                 </table>';
337                 }
338
339                         // Output for the "About modules" module
340                 if ($descr==1)  {
341                         $descrCode = '
342                         
343                         
344                                 <!-- 
345                                         Listing of modules, for Help > About modules
346                                 -->
347                                 <table border="0" cellpadding="0" cellspacing="0" id="typo3-about-modules">
348                                         '.$descrCode.'
349                                 </table>';
350                         $final = $descrCode;
351                 }
352
353                         // selector-box menu
354                 if ($descr==2)  {
355
356                                 // Add admin-functions for clearing caches:
357                         if ($BE_USER->isAdmin())        {
358                                 $functionArray = $this->adminFunctions($backPath);
359                                 if (count($functionArray))      {
360                                         $selectItems[] = '<option value=""></option>';
361                                         foreach($functionArray as $fAoptions)   {
362                                                 $selectItems[] = '<option value="'.htmlspecialchars("document.location='".$fAoptions['href']."';").'">[ '.htmlspecialchars($fAoptions['title']).' ]</option>';
363                                         }
364                                 }
365                         }
366
367                                 // Logout item:
368                         $selectItems[] = '<option value=""></option>';
369                         $selectItems[] = '<option value="'.htmlspecialchars("top.location='logout.php';").'">[ '.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.logout',1).' ]</option>';
370                         $final = '
371                                 <select name="menuselector" onchange="eval(this.options[this.selectedIndex].value);">
372                                         '.implode('
373                                         ',$selectItems).'
374                                 </select>';
375                 }
376                         // topmenu - horizontal line of icons!
377                 if ($descr==3)  {
378                         $final = ''.implode('',$mIcons).'';
379                 }
380
381                         // Output for the goToModules() function in main frameset.
382                 if ($descr==4)  {
383                         $final = chr(10).implode(chr(10),$mJScmds).chr(10);
384                 }
385
386                         // Return result:
387                 return $final;
388         }
389
390         /**
391          * Returns $Ifilename readable for script in PATH_typo3. 
392          * That means absolute names are just returned while relative names are prepended with $backPath (pointing back to typo3/ dir)
393          * 
394          * @param       string          Icon filename
395          * @param       string          Back path
396          * @return      string          Result
397          * @see mIconFilename()
398          */
399         function mIconFile($Ifilename,$backPath)        {
400                 if (t3lib_div::isAbsPath($Ifilename))   {
401                         return $Ifilename;
402                 }
403                 return $backPath.$Ifilename;
404         }
405
406         /**
407          * Returns relative filename to the $Ifilename (for use in img-tags)
408          * 
409          * @param       string          Icon filename
410          * @param       string          Back path
411          * @return      string          Result
412          * @see mIconFile()
413          */
414         function mIconFilename($Ifilename,$backPath)    {
415                 if (t3lib_div::isAbsPath($Ifilename))   {
416                         $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
417                 }
418                 return $backPath.$Ifilename;
419         }
420
421         /**
422          * Returns logout button.
423          * 
424          * @return      string          
425          */
426         function topButtons()   {
427                 global $LANG;
428                         
429                 $out.= '<form action="logout.php" target="_top"><input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.logout',1).'" /></form>';
430                 return $out;
431         }
432
433         /**
434          * Returns logout button.
435          * 
436          * @return      string          
437          */
438         function adminButtons() {
439                 global $LANG;
440                 
441                 $functionArray = $this->adminFunctions('');
442
443                 $icons=array();         
444                 foreach($functionArray as $fAoptions)   {
445                         $icons[]= '<a href="'.htmlspecialchars($fAoptions['href']).'">'.$fAoptions['icon'].'</a>';
446                 }
447                 
448                 return implode('',$icons);
449         }
450
451         /**
452          * Returns array with parts from which the admin functions can be constructed.
453          * 
454          * @param       string          Backpath.
455          * @return      array   
456          */
457         function adminFunctions($backPath)      {
458                 global $LANG,$BE_USER,$TYPO3_CONF_VARS;
459
460                 $functions=array();
461                 
462                         // Clearing of cache-files in typo3conf/ + menu
463                 if ($TYPO3_CONF_VARS['EXT']['extCache'])        {
464                         $title = $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_allTypo3Conf');
465                         $functions[]=array(
466                                 'title' => $title,
467                                 'href' => $backPath.'tce_db.php?vC='.$BE_USER->veriCode().'&redirect='.rawurlencode(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT')).'&cacheCmd=temp_CACHED',
468                                 'icon' => '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/clear_cache_files_in_typo3c.gif','width="21" height="18"').' title="'.htmlspecialchars($title).'" alt="" />'
469                         );
470                 }
471
472                         // Clear all page cache
473                 $title = $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_all');
474                 $functions[]=array(
475                         'title' => $title,
476                         'href' => $backPath.'tce_db.php?vC='.$BE_USER->veriCode().'&redirect='.rawurlencode(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT')).'&cacheCmd=all',
477                         'icon' => '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/clear_all_cache.gif','width="21" height="18"').' title="'.htmlspecialchars($title).'" alt="" />'
478                 );
479
480                         // Return functions
481                 return $functions;
482         }
483
484         /**
485          * Appends a '?' if there is none in the string already
486          * 
487          * @param       string          Link URL
488          * @return      string          
489          */
490         function wrapLinkWithAB($link)  {
491                 if (!strstr($link,'?')) {
492                         return $link.'?';
493                 } else return $link;
494         }
495 }
496
497
498 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.alt_menu_functions.inc'])      {
499         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.alt_menu_functions.inc']);
500 }
501 ?>