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