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