* Added visual response to backend module selection in the menus; The class attribute...
[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                         $moduleCSSId = 'ID_'.t3lib_div::md5int($moduleName);
151
152                                 // Creating image icon
153                         $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath));
154                         $imageCode='';
155                         $descr3_title = $LANG->moduleLabels['tabs'][$moduleKey].' ';
156                         if ($image)     {
157                                 $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath);
158                                 $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' alt="" />';
159                                 $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($descr3_title).'" alt="" />';
160                         } else {
161                                 $descr3_imageCode = '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/dummy_module.gif','width="14" height="12"').' title="'.htmlspecialchars($descr3_title).'" alt="" />';
162                         }
163
164                                 // Creating the various links:
165                         $label = $LANG->moduleLabels['tabs'][$moduleKey];
166                         if ($link && $prefix)   $link=$prefix.rawurlencode($link);
167                         if ($link && !$dontLink)        {
168                                 $label = '<a href="#" onclick="top.goToModule(\''.$moduleName.'\');'.$onBlur.'return false;">'.$label.'</a>';   //  && !$link_sub
169
170                                 $mIcons[] = '<a href="#" onclick="top.goToModule(\''.$moduleName.'\');'.$onBlur.'return false;" class="c-mainitem" id="'.$moduleCSSId.'">'.$descr3_imageCode.'</a>';
171
172                                 $JScmd = '
173                                                 top.content.location=top.getModuleUrl(top.TS.PATH_typo3+\''.$this->wrapLinkWithAB($link).'\');
174                                                 top.highlightModuleMenuItem("'.$moduleCSSId.'",1);';
175                                 $mJScmds[] = "case '".$moduleName."': \n ".$JScmd." \n break;";
176                         }
177
178                         $selectItems[] = '<option value="top.goToModule(\''.$moduleName.'\');">'.htmlspecialchars($LANG->moduleLabels['tabs'][$moduleKey]).'</option>';
179                         $label='&nbsp;<b>'.$label.'</b>&nbsp;';
180
181                                 // Creating a main item for the vertical menu (descr=0)
182                         $menuCode.='
183                                                 <tr class="c-mainitem" id="'.$moduleCSSId.'">
184                                                         <td colspan="3">'.$imageCode.'<span class="c-label">'.$label.'</span></td>
185                                                 </tr>';
186
187                                 // Code for "About modules"
188                         $descrCode.='
189                                                 <tr class="c-mainitem bgColor4">
190                                                         <td colspan="3">'.$imageCode.$label.'</td>
191                                                 </tr>';
192
193
194
195
196                                 // Travesing submodules
197                         $subCode='';
198                         if (is_array($moduleInfo['sub']))       {
199                                 reset($moduleInfo['sub']);
200                                 $c=0;
201                                 while(list($subName,$subInfo)=each($moduleInfo['sub'])) {
202                                         if ($c==0)              {
203                                                 $subCode.='
204                                                                 <tr class="c-first">
205                                                                         <td colspan="3"></td>
206                                                                 </tr>';
207                                                 $descrCode.='
208                                                                 <tr class="c-first">
209                                                                         <td colspan="3"></td>
210                                                                 </tr>';
211                                         }
212
213                                         $link = $subInfo['script'];
214                                         $subKey = $moduleName.'_'.$subName.'_tab';
215                                         $moduleCSSId = 'ID_'.t3lib_div::md5int($moduleName.'_'.$subName);
216
217                                                 // Creating image icon
218                                         $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$subKey],$backPath));
219                                         $imageCode='';
220                                         $descr3_title = $LANG->moduleLabels['tabs'][$subKey].': '.$LANG->moduleLabels['labels'][$subKey.'label'];
221                                         if ($image)     {
222                                                 $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$subKey],$backPath);
223                                                 $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'" alt="" />';
224                                                 $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($descr3_title).'" alt="" />';
225                                         } else {
226                                                 $descr3_imageCode = '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/dummy_module.gif','width="14" height="12"').' title="'.htmlspecialchars($descr3_title).'" alt="" />';
227                                         }
228
229                                                 // Label for submodule:
230                                         $label = $LANG->moduleLabels['tabs'][$subKey];
231                                         $label_descr = ' title="'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'"';
232                                         $flabel = htmlspecialchars($label);
233                                         $origLink = $link;
234                                         if ($link && $prefix)   $link=$prefix.rawurlencode($link);
235
236                                                 // Setting additional JavaScript if frameset script:
237                                         $addJS = '';
238                                         if ($moduleInfo['navFrameScript'])      {$addJS="+'&id='+top.rawurlencode(top.fsMod.recentIds['".$moduleName."'])";}
239
240                                                 // If there is a script to link to (and linking is not disabled.
241                                         if ($link && !$dontLink)        {
242                                                         // For condensed mode, send &cMR parameter to frameset script.
243                                                 if ($addJS && $BE_USER->uc['condensedMode'])    {$addJS.=  "+(cMR?'&cMR=1':'')";}
244
245                                                         // Command for the selector box:
246                                                 $JScmd = "
247                                                                 top.content.location=top.getModuleUrl(top.TS.PATH_typo3+'".$this->wrapLinkWithAB($link)."'".$addJS.');
248                                                                 top.fsMod.currentMainLoaded="'.$moduleName.'";
249                                                                 ';
250
251                                                         // If there is a frameset script in place:
252                                                 if (!$BE_USER->uc['condensedMode'] && $moduleInfo['navFrameScript'])    {
253
254                                                                 // use special nav script from sub module, otherwise from the main module
255                                                         $subNavFrameScript = $subInfo['navFrameScript'] ? $subInfo['navFrameScript'] : $moduleInfo['navFrameScript'] ;
256
257                                                                 // should we add GET params for sub module to the nav script?
258                                                         if ($subInfo['navFrameScriptParam']) {
259                                                                 $subNavFrameScript = $this->wrapLinkWithAB($subNavFrameScript).$subInfo['navFrameScriptParam'];
260                                                         }
261
262                                                         $JScmd = '
263                                                                 if (top.content.list_frame && top.fsMod.currentMainLoaded=="'.$moduleName.'") {
264                                                                         top.currentSubScript="'.$origLink.'";
265                                                                         top.content.list_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->wrapLinkWithAB($origLink).'"'.$addJS.');
266                                                                         if(top.currentSubNavScript!="'.$subNavFrameScript.'") {
267                                                                                 top.currentSubNavScript="'.$subNavFrameScript.'";
268                                                                                 top.content.nav_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->wrapLinkWithAB($subNavFrameScript).'");
269                                                                         }
270                                                                 } else {
271                                                                         top.content.location=top.TS.PATH_typo3+(
272                                                                                 top.nextLoadModuleUrl?
273                                                                                 "'.($prefix?$this->wrapLinkWithAB($link).'&exScript=':'').'listframe_loader.php":
274                                                                                 "'.$this->wrapLinkWithAB($link).'"'.$addJS.'
275                                                                         );
276                                                                         top.fsMod.currentMainLoaded="'.$moduleName.'";
277                                                                 }
278                                                                 ';
279                                                 }
280                                                 $selectItems[] = '<option value="top.goToModule(\''.$moduleName.'_'.$subName.'\');">'.htmlspecialchars('- '.$label).'</option>';
281                                                 $onClickString = htmlspecialchars('top.goToModule(\''.$moduleName.'_'.$subName.'\');'.$onBlur.'return false;');
282
283                                                 $flabel = '<a href="#" onclick="'.$onClickString.'"'.$label_descr.'>'.htmlspecialchars($label).'</a>';
284
285                                                 $mIcons[] = '<a href="#" onclick="'.$onClickString.'"'.$label_descr.' class="c-subitem" id="'.$moduleCSSId.'">'.$descr3_imageCode.'</a>';
286
287                                                 $JScmd.= '
288                                                                 top.highlightModuleMenuItem("'.$moduleCSSId.'");';
289                                                 $mJScmds[] = "case '".$moduleName.'_'.$subName."': \n ".$JScmd." \n break;";
290                                         }
291
292                                         $subCode.='
293                                                         <tr class="c-subitem-row" id="'.$moduleCSSId.'">
294                                                                 <td></td>
295                                                                 <td align="center">'.(!$BE_USER->uc['hideSubmoduleIcons']?$imageCode:'').'</td>
296                                                                 <td class="c-subitem-label">'.$flabel.'</td>
297                                                         </tr>';
298
299                                                 // For "About modules":
300                                         $descrCode.='
301                                                         <tr class="c-subitem-row">
302                                                                 <td align="center">'.$imageCode.'</td>
303                                                                 <td>'.$flabel.'&nbsp;&nbsp;</td>
304                                                                 <td><strong>'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'</strong><br />'.$LANG->moduleLabels['labels'][$subKey.'descr'].'</td>
305                                                         </tr>';
306
307                                                 // Possibly adding a divider line
308                                         $c++;
309                                         if ($c<count($moduleInfo['sub']))       {
310                                                         // Divider
311                                                 $subCode.='
312                                                         <tr class="c-divrow">
313                                                                 <td colspan="3"><img'.t3lib_iconWorks::skinImg($backPath,'gfx/altmenuline.gif','width="105" height="3"').' alt="" /></td>
314                                                         </tr>';
315                                         }
316                                 }
317                                         // Spacer gif for top menu:
318                                 if (count($theModules)>$mC)     {
319                                         $mIcons[]='<img src="'.$backPath.'gfx/acm_spacer2.gif" width="8" height="12" hspace="3" alt="" />';
320                                 }
321                         }
322
323                                 // Add spacers after each main section:
324                         $subCode.='
325                                         <tr class="c-endrow">
326                                                 <td colspan="3"></td>
327                                         </tr>';
328                         $descrCode.='
329                                         <tr class="c-endrow">
330                                                 <td colspan="3"></td>
331                                         </tr>';
332
333                                 // Add sub-code:
334                         $menuCode.=$subCode;
335                 }
336
337                         // $descr==0:   Ordinary vertical menu
338                 if ($menuCode)  {
339                         $final = '
340
341
342                                 <!--
343                                         Vertical module menu, shown in left frame of backend.
344                                 -->
345                                 <table border="0" cellpadding="0" cellspacing="0" id="typo3-vmenu">
346                                         '.$menuCode.'
347                                 </table>';
348                 }
349
350                         // Output for the "About modules" module
351                 if ($descr==1)  {
352                         $descrCode = '
353
354
355                                 <!--
356                                         Listing of modules, for Help > About modules
357                                 -->
358                                 <table border="0" cellpadding="0" cellspacing="0" id="typo3-about-modules">
359                                         '.$descrCode.'
360                                 </table>';
361                         $final = $descrCode;
362                 }
363
364                         // selector-box menu
365                 if ($descr==2)  {
366
367                                 // Add admin-functions for clearing caches:
368                         if ($BE_USER->isAdmin())        {
369                                 $functionArray = $this->adminFunctions($backPath);
370                                 if (count($functionArray))      {
371                                         $selectItems[] = '<option value=""></option>';
372                                         foreach($functionArray as $fAoptions)   {
373                                                 $selectItems[] = '<option value="'.htmlspecialchars("document.location='".$fAoptions['href']."';").'">[ '.htmlspecialchars($fAoptions['title']).' ]</option>';
374                                         }
375                                 }
376                         }
377
378                                 // Logout item:
379                         $selectItems[] = '<option value=""></option>';
380                         $selectItems[] = '<option value="'.htmlspecialchars("top.location='logout.php';").'">[ '.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.logout',1).' ]</option>';
381                         $final = '
382                                 <select name="menuselector" onchange="eval(this.options[this.selectedIndex].value);">
383                                         '.implode('
384                                         ',$selectItems).'
385                                 </select>';
386                 }
387                         // topmenu - horizontal line of icons!
388                 if ($descr==3)  {
389                         $final = ''.implode('',$mIcons).'';
390                 }
391
392                         // Output for the goToModules() function in main frameset.
393                 if ($descr==4)  {
394                         $final = chr(10).implode(chr(10),$mJScmds).chr(10);
395                 }
396
397                         // Return result:
398                 return $final;
399         }
400
401         /**
402          * Returns $Ifilename readable for script in PATH_typo3.
403          * That means absolute names are just returned while relative names are prepended with $backPath (pointing back to typo3/ dir)
404          *
405          * @param       string          Icon filename
406          * @param       string          Back path
407          * @return      string          Result
408          * @see mIconFilename()
409          */
410         function mIconFile($Ifilename,$backPath)        {
411                 if (t3lib_div::isAbsPath($Ifilename))   {
412                         return $Ifilename;
413                 }
414                 return $backPath.$Ifilename;
415         }
416
417         /**
418          * Returns relative filename to the $Ifilename (for use in img-tags)
419          *
420          * @param       string          Icon filename
421          * @param       string          Back path
422          * @return      string          Result
423          * @see mIconFile()
424          */
425         function mIconFilename($Ifilename,$backPath)    {
426                 if (t3lib_div::isAbsPath($Ifilename))   {
427                         $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
428                 }
429                 return $backPath.$Ifilename;
430         }
431
432         /**
433          * Returns logout button.
434          *
435          * @return      string
436          */
437         function topButtons()   {
438                 global $LANG;
439
440                 $out.= '<form action="logout.php" target="_top"><input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.logout',1).'" /></form>';
441                 return $out;
442         }
443
444         /**
445          * Returns logout button.
446          *
447          * @return      string
448          */
449         function adminButtons() {
450                 global $LANG;
451
452                 $functionArray = $this->adminFunctions('');
453
454                 $icons=array();
455                 foreach($functionArray as $fAoptions)   {
456                         $icons[]= '<a href="'.htmlspecialchars($fAoptions['href']).'">'.$fAoptions['icon'].'</a>';
457                 }
458
459                 return implode('',$icons);
460         }
461
462         /**
463          * Returns array with parts from which the admin functions can be constructed.
464          *
465          * @param       string          Backpath.
466          * @return      array
467          */
468         function adminFunctions($backPath)      {
469                 global $LANG,$BE_USER,$TYPO3_CONF_VARS;
470
471                 $functions=array();
472
473                         // Clearing of cache-files in typo3conf/ + menu
474                 if ($TYPO3_CONF_VARS['EXT']['extCache'])        {
475                         $title = $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_allTypo3Conf');
476                         $functions[]=array(
477                                 'title' => $title,
478                                 'href' => $backPath.'tce_db.php?vC='.$BE_USER->veriCode().'&redirect='.rawurlencode(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT')).'&cacheCmd=temp_CACHED',
479                                 'icon' => '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/clear_cache_files_in_typo3c.gif','width="21" height="18"').' title="'.htmlspecialchars($title).'" alt="" />'
480                         );
481                 }
482
483                         // Clear all page cache
484                 $title = $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_all');
485                 $functions[]=array(
486                         'title' => $title,
487                         'href' => $backPath.'tce_db.php?vC='.$BE_USER->veriCode().'&redirect='.rawurlencode(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT')).'&cacheCmd=all',
488                         'icon' => '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/clear_all_cache.gif','width="21" height="18"').' title="'.htmlspecialchars($title).'" alt="" />'
489                 );
490
491                         // Return functions
492                 return $functions;
493         }
494
495         /**
496          * Appends a '?' if there is none in the string already
497          *
498          * @param       string          Link URL
499          * @return      string
500          */
501         function wrapLinkWithAB($link)  {
502                 if (!strstr($link,'?')) {
503                         return $link.'?';
504                 } else return $link;
505         }
506 }
507
508
509 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.alt_menu_functions.inc'])      {
510         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.alt_menu_functions.inc']);
511 }
512 ?>