2 /***************************************************************
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
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.
33 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
34 * XHTML compliant content
36 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
39 * [CLASS/FUNCTION INDEX of SCRIPT]
43 * 73: class alt_menu_functions
44 * 94: function topMenu($theModules,$dontLink=0,$backPath='',$descr=0)
45 * 473: function getNavFramePrefix($moduleInfo, $subModuleInfo=array())
46 * 504: function mIconFile($Ifilename,$backPath)
47 * 519: function mIconFilename($Ifilename,$backPath)
48 * 531: function topButtons()
49 * 544: function adminButtons()
50 * 563: function adminFunctions($backPath)
51 * 596: function wrapLinkWithAB($link)
54 * (This index is automatically created/updated by the extension "extdeveval")
67 * Class with menu functions
69 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
73 class alt_menu_functions {
79 * Creates the menu of modules.
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.
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
94 function topMenu($theModules,$dontLink=0,$backPath='',$descr=0) {
95 global $LANG, $TBE_TEMPLATE, $BE_USER;
97 // By default module sections are collapsable, only if they are explicitly turned off via TSconfig, they are not:
98 $tmpArr = $BE_USER->getTSConfig('options.moduleMenuCollapsable');
99 $collapsable = ($tmpArr['value'] ? 0 : 1);
108 $selectItems=array();
111 $onBlur=$GLOBALS['CLIENT']['FORMSTYLE'] ? 'this.blur();' : '';
113 $selectItems[] = '<option value="">[ '.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.selMenu_modules',1).' ]</option>';
116 // Remove the 'doc' module?
117 if ($BE_USER->getTSConfigVal('options.disableDocModuleInAB')) {
118 unset($theModules['doc']);
121 // Get collapsed configuration
122 if ($collapsable == 1) {
123 $config = is_array ($BE_USER->uc['moduleData']['alt_menu.php']) ? $BE_USER->uc['moduleData']['alt_menu.php'] : array();
124 $collapsedOverride = t3lib_div::_GP('collapsedOverride');
125 if (is_array ($collapsedOverride)) {
126 $config = array_merge ($config, $collapsedOverride);
129 if (t3lib_div::_GP('collapsableExpandAll') == 1) {
130 $config['expandAll'] = t3lib_div::_GP('expandAll');
133 if ($config['expandAll'] && is_array($collapsedOverride)) {
134 $config = $collapsedOverride;
137 $BE_USER->uc['moduleData']['alt_menu.php'] = $config;
138 $BE_USER->writeUC($BE_USER->uc);
140 // all items have to be expanded when expandAll is set
141 if($config['expandAll'] == 1) {
142 foreach($config as $key => $value) {
143 if($key != 'expandAll')
149 // Traverse array with modules
151 while(list($moduleName,$moduleInfo)=each($theModules)) {
154 $prefix = $this->getNavFramePrefix($moduleInfo);
156 $this->fsMod[]='fsMod.recentIds["'.$moduleName.'"]="";';
159 // If there are submodules:
160 if (is_array($moduleInfo['sub'])) {
161 // Finding the default module to display
162 if ($moduleInfo['defaultMod']) {
163 $link = $moduleInfo['sub'][$moduleInfo['defaultMod']]['script'];
165 reset($moduleInfo['sub']);
166 $subTemp = current($moduleInfo['sub']);
167 $link = $subTemp['script'];
169 $link_sub = 1; // Tells that the main modules links to a submodule
170 $link = ''; // Does not link to submodules...
172 $link = $moduleInfo['script'];
176 $link = t3lib_div::resolveBackPath($link);
178 $moduleKey = $moduleName.'_tab';
179 $moduleCSSId = 'ID_'.t3lib_div::md5int($moduleName);
181 $collection[$moduleKey] = array(
182 'moduleName' => $moduleName,
183 'title' => $LANG->moduleLabels['tabs'][$moduleKey],
184 'onclick' => 'top.goToModule(\''.$moduleName.'\');',
187 // Creating image icon
188 $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath));
190 $descr3_title = $LANG->moduleLabels['tabs'][$moduleKey].' ';
192 $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath);
193 $collection[$moduleKey]['icon'] = array($Ifilename, $image[3]);
194 $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' alt="" />';
195 $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($descr3_title).'" alt="" />';
197 $descr3_imageCode = '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/dummy_module.gif','width="14" height="12"').' title="'.htmlspecialchars($descr3_title).'" alt="" />';
200 // Creating the various links:
201 $label = $LANG->moduleLabels['tabs'][$moduleKey];
202 if ($link && $prefix) $link=$prefix.rawurlencode($link);
203 if ($link && !$dontLink) {
204 $label = '<a href="#" onclick="top.goToModule(\''.$moduleName.'\');'.$onBlur.'return false;">'.$label.'</a>'; // && !$link_sub
206 $mIcons[] = '<a href="#" onclick="top.goToModule(\''.$moduleName.'\');'.$onBlur.'return false;" class="c-mainitem" id="'.$moduleCSSId.'">'.$descr3_imageCode.'</a>';
209 top.content.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->wrapLinkWithAB($link).'"+additionalGetVariables);
210 top.highlightModuleMenuItem("'.$moduleCSSId.'",1);';
211 $mJScmds[] = "case '".$moduleName."': \n ".$JScmd." \n break;";
214 $selectItems[] = '<option value="top.goToModule(\''.$moduleName.'\');">'.htmlspecialchars($LANG->moduleLabels['tabs'][$moduleKey]).'</option>';
215 $label=' <b>'.$label.'</b> ';
218 // make menu collapsable
219 if($collapsable == 1 && is_array($moduleInfo['sub'])) {
220 $collapseJS = 'onclick="window.location.href=\'alt_menu.php?collapsedOverride['.$moduleName.']='.($config[$moduleName] ? '0' : '1').'\'"';
221 $collapseIcon = '<span class="c-iconCollapse"><img'.t3lib_iconWorks::skinImg($backPath,'gfx/ol/'.($config[$moduleName] ? 'plusbullet.gif':'minusbullet.gif'),'width="18" height="16"').' title="" alt="" /></span>';
223 $collapseJS = $collapseIcon = '';
226 // Creating a main item for the vertical menu (descr=0)
228 <tr class="c-mainitem" id="'.$moduleCSSId.'">
229 <td colspan="3" '.$collapseJS.' >'.$imageCode.'<span class="c-label">'.$label.'</span>'.$collapseIcon.'</td>
232 // Code for "About modules"
234 <tr class="c-mainitem bgColor4">
235 <td colspan="3">'.$imageCode.$label.'</td>
239 // Hide submodules when collapsed:
240 if($collapsable == 1 && $config[$moduleName] == 1 && $descr == 0 && $config['expandAll'] != 1) {
241 unset($moduleInfo['sub']);
244 // Traversing submodules
246 if (is_array($moduleInfo['sub'])) {
247 reset($moduleInfo['sub']);
248 $collection[$moduleKey]['subitems'] = array();
250 while(list($subName,$subInfo)=each($moduleInfo['sub'])) {
254 <td colspan="3"></td>
258 <td colspan="3"></td>
262 $link = t3lib_div::resolveBackPath($subInfo['script']);
263 $prefix = $this->getNavFramePrefix($moduleInfo, $subInfo);
265 $subKey = $moduleName.'_'.$subName.'_tab';
266 $moduleCSSId = 'ID_'.t3lib_div::md5int($moduleName.'_'.$subName);
268 $collection[$moduleKey]['subitems'][$subKey] = array(
269 'moduleName' => $moduleName.'_'.$subName,
270 'title' => $LANG->moduleLabels['tabs'][$subKey],
271 'onclick' => 'top.goToModule(\''.$moduleName.'_'.$subName.'\');',
274 // Creating image icon
275 $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$subKey],$backPath));
277 $descr3_title = $LANG->moduleLabels['tabs'][$subKey].': '.$LANG->moduleLabels['labels'][$subKey.'label'];
279 $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$subKey],$backPath);
280 $collection[$moduleKey]['subitems'][$subKey]['icon'] = array($Ifilename, $image[3]);
281 $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'" alt="" />';
282 $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($descr3_title).'" alt="" />';
284 $descr3_imageCode = '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/dummy_module.gif','width="14" height="12"').' title="'.htmlspecialchars($descr3_title).'" alt="" />';
287 // Label for submodule:
288 $label = $LANG->moduleLabels['tabs'][$subKey];
289 $label_descr = ' title="'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'"';
290 $flabel = htmlspecialchars($label);
292 if ($link && $prefix) $link=$prefix.rawurlencode($link);
294 // Setting additional JavaScript if frameset script:
296 if ($moduleInfo['navFrameScript']) {$addJS="+'&id='+top.rawurlencode(top.fsMod.recentIds['".$moduleName."'])";}
298 // If there is a script to link to (and linking is not disabled.
299 if ($link && !$dontLink) {
300 // For condensed mode, send &cMR parameter to frameset script.
301 if ($addJS && $BE_USER->uc['condensedMode']) {$addJS.= "+(cMR?'&cMR=1':'')";}
303 // Command for the selector box:
305 top.content.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->wrapLinkWithAB($link).'"'.$addJS.'+additionalGetVariables);
306 top.fsMod.currentMainLoaded="'.$moduleName.'";
309 if ($subInfo['navFrameScript']) {
311 top.currentSubScript="'.$origLink.'";';
314 // If there is a frameset script in place:
315 if (!$BE_USER->uc['condensedMode'] && $moduleInfo['navFrameScript']) {
317 // use special nav script from sub module, otherwise from the main module
318 $subNavFrameScript = $subInfo['navFrameScript'] ? $subInfo['navFrameScript'] : $moduleInfo['navFrameScript'];
319 $subNavFrameScript = t3lib_div::resolveBackPath($subNavFrameScript);
321 // add GET params for sub module to the nav script
322 $subNavFrameScript = $this->wrapLinkWithAB($subNavFrameScript).$subInfo['navFrameScriptParam'];
325 if (top.content.list_frame && top.fsMod.currentMainLoaded=="'.$moduleName.'") {
326 top.currentSubScript="'.$origLink.'";
327 top.content.list_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->wrapLinkWithAB($origLink).'"'.$addJS.'+additionalGetVariables);
328 if(top.currentSubNavScript!="'.$subNavFrameScript.'") {
329 top.currentSubNavScript="'.$subNavFrameScript.'";
330 top.content.nav_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$subNavFrameScript.'");
333 top.content.location=top.TS.PATH_typo3+(
334 top.nextLoadModuleUrl?
335 "'.($prefix?$this->wrapLinkWithAB($link).'&exScript=':'').'listframe_loader.php":
336 "'.$this->wrapLinkWithAB($link).'"'.$addJS.'+additionalGetVariables
338 top.fsMod.currentMainLoaded="'.$moduleName.'";
339 top.currentSubScript="'.$origLink.'";
343 $selectItems[] = '<option value="top.goToModule(\''.$moduleName.'_'.$subName.'\');">'.htmlspecialchars('- '.$label).'</option>';
344 $onClickString = htmlspecialchars('top.goToModule(\''.$moduleName.'_'.$subName.'\');'.$onBlur.'return false;');
346 $flabel = '<a href="#" onclick="'.$onClickString.'"'.$label_descr.'>'.htmlspecialchars($label).'</a>';
348 $mIcons[] = '<a href="#" onclick="'.$onClickString.'"'.$label_descr.' class="c-subitem" id="'.$moduleCSSId.'">'.$descr3_imageCode.'</a>';
351 top.highlightModuleMenuItem("'.$moduleCSSId.'");';
352 $mJScmds[] = "case '".$moduleName.'_'.$subName."': \n ".$JScmd." \n break;";
356 <tr class="c-subitem-row" id="'.$moduleCSSId.'">
358 <td align="center">'.(!$BE_USER->uc['hideSubmoduleIcons']?$imageCode:'').'</td>
359 <td class="c-subitem-label">'.$flabel.'</td>
362 // For "About modules":
364 <tr class="c-subitem-row">
365 <td align="center">'.$imageCode.'</td>
366 <td>'.$flabel.' </td>
367 <td><strong>'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'</strong><br />'.$LANG->moduleLabels['labels'][$subKey.'descr'].'</td>
370 // Possibly adding a divider line
372 if ($c<count($moduleInfo['sub'])) {
375 <tr class="c-divrow">
376 <td colspan="3"><img'.t3lib_iconWorks::skinImg($backPath,'gfx/altmenuline.gif','width="105" height="3"').' alt="" /></td>
380 // Spacer gif for top menu:
381 if (count($theModules)>$mC) {
382 $mIcons[]='<img src="'.$backPath.'gfx/acm_spacer2.gif" width="8" height="12" hspace="3" alt="" />';
386 // Add spacers after each main section:
388 <tr class="c-endrow">
389 <td colspan="3"></td>
392 <tr class="c-endrow">
393 <td colspan="3"></td>
400 // $descr==0: Ordinary vertical menu
402 if($collapsable == 1 || $config['expandAll'] == 1) {
403 $collapseAllHTML = '<tr class="c-endrow">
406 <form action="alt_menu.php" method="get">
407 <input type="hidden" name="collapsableExpandAll" value="1" />
408 <input type="checkbox" name="expandAll" id="expandall" value="1" onclick="this.form.submit();" '.($config['expandAll']?'checked="checked"':'').' />
411 <td class="c-subitem-label"><label for="expandall">'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.expandAll',1).'</label></td>
414 $collapseAllHTML = '';
421 Vertical module menu, shown in left frame of backend.
423 <table border="0" cellpadding="0" cellspacing="0" id="typo3-vmenu">
425 <tr class="c-endrow">
426 <td colspan="3">'.t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'menu_modules', $GLOBALS['BACK_PATH']).'</td></tr>
431 // Output for the "About modules" module
437 Listing of modules, for Help > About modules
439 <table border="0" cellpadding="0" cellspacing="0" id="typo3-about-modules">
448 // Add admin-functions for clearing caches:
449 if ($BE_USER->isAdmin()) {
450 $functionArray = $this->adminFunctions($backPath);
451 if (count($functionArray)) {
452 $selectItems[] = '<option value=""></option>';
453 foreach($functionArray as $fAoptions) {
454 $selectItems[] = '<option value="'.htmlspecialchars("window.location.href='".$fAoptions['href']."';").'">[ '.htmlspecialchars($fAoptions['title']).' ]</option>';
460 $selectItems[] = '<option value=""></option>';
461 $selectItems[] = '<option value="'.htmlspecialchars("top.location='logout.php';").'">[ '.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.logout',1).' ]</option>';
463 <select name="menuselector" onchange="eval(this.options[this.selectedIndex].value);">
468 // topmenu - horizontal line of icons!
470 $final = ''.implode('',$mIcons).'';
473 // Output for the goToModules() function in main frameset.
475 $final = chr(10).implode(chr(10),$mJScmds).chr(10);
478 // Output for TOPMENU BAR drop downs (but basically this is an array with which you can do many interesting things...)
480 $final = $collection;
488 * Returns a prefix used to call the navframe with parameters to call the scripts defined in the modules info array.
490 * @param string Module info array
491 * @param string Submodule info array
492 * @return string Result url string
494 function getNavFramePrefix($moduleInfo, $subModuleInfo=array()) {
498 $navFrameScript = $subModuleInfo['navFrameScript'] ? $subModuleInfo['navFrameScript'] : $moduleInfo['navFrameScript'];
499 $navFrameScriptParam = isset($subModuleInfo['navFrameScriptParam']) ? $subModuleInfo['navFrameScriptParam'] : $moduleInfo['navFrameScriptParam'];
500 if ($navFrameScript) {
501 $navFrameScript = t3lib_div::resolveBackPath($navFrameScript);
502 $navFrameScript = $this->wrapLinkWithAB($navFrameScript);
504 if ($BE_USER->uc['condensedMode']) {
505 $prefix=$navFrameScript.$navFrameScriptParam.'¤tSubScript=';
507 $prefix='alt_mod_frameset.php?'.
508 'fW="+top.TS.navFrameWidth+"'.
509 '&nav="+top.TS.PATH_typo3+"'.rawurlencode($navFrameScript.$navFrameScriptParam).
517 * Returns $Ifilename readable for script in PATH_typo3.
518 * That means absolute names are just returned while relative names are prepended with $backPath (pointing back to typo3/ dir)
520 * @param string Icon filename
521 * @param string Back path
522 * @return string Result
523 * @see mIconFilename()
525 function mIconFile($Ifilename,$backPath) {
526 if (t3lib_div::isAbsPath($Ifilename)) {
529 return $backPath.$Ifilename;
533 * Returns relative filename to the $Ifilename (for use in img-tags)
535 * @param string Icon filename
536 * @param string Back path
537 * @return string Result
540 function mIconFilename($Ifilename,$backPath) {
541 if (t3lib_div::isAbsPath($Ifilename)) {
542 $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
544 return $backPath.$Ifilename;
548 * Returns logout button.
552 function topButtons() {
555 $label = $GLOBALS['BE_USER']->user['ses_backuserid'] ? 'LLL:EXT:lang/locallang_core.php:buttons.exit' : 'LLL:EXT:lang/locallang_core.php:buttons.logout';
556 $out.= '<form action="logout.php" target="_top"><input type="submit" value="'.$LANG->sL($label,1).'" /></form>';
561 * Returns logout button.
565 function adminButtons() {
568 $functionArray = $this->adminFunctions('');
571 foreach($functionArray as $fAoptions) {
572 $icons[]= '<a href="'.htmlspecialchars($fAoptions['href']).'">'.$fAoptions['icon'].'</a>';
575 return implode('',$icons);
579 * Returns array with parts from which the admin functions can be constructed.
581 * @param string Backpath.
584 function adminFunctions($backPath) {
585 global $LANG,$BE_USER,$TYPO3_CONF_VARS;
589 // Clearing of cache-files in typo3conf/ + menu
590 if ($TYPO3_CONF_VARS['EXT']['extCache']) {
591 $title = $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_allTypo3Conf');
593 'id' => 'temp_CACHED',
595 'href' => $backPath.'tce_db.php?vC='.$BE_USER->veriCode().'&redirect='.rawurlencode(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT')).'&cacheCmd=temp_CACHED',
596 'icon' => '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/clear_cache_files_in_typo3c.gif','width="21" height="18"').' title="'.htmlspecialchars($title).'" alt="" />'
600 // Clear all page cache
601 $title = $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_all');
605 'href' => $backPath.'tce_db.php?vC='.$BE_USER->veriCode().'&redirect='.rawurlencode(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT')).'&cacheCmd=all',
606 'icon' => '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/clear_all_cache.gif','width="21" height="18"').' title="'.htmlspecialchars($title).'" alt="" />'
614 * Appends a '?' if there is none in the string already
616 * @param string Link URL
619 function wrapLinkWithAB($link) {
620 if (!strstr($link,'?')) {
627 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.alt_menu_functions.inc']) {
628 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.alt_menu_functions.inc']);