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