2 /***************************************************************
5 * (c) 1999-2004 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 * 402: function getNavFramePrefix ($moduleInfo, $subModuleInfo=array())
46 * 429: function mIconFile($Ifilename,$backPath)
47 * 444: function mIconFilename($Ifilename,$backPath)
48 * 456: function topButtons()
49 * 468: function adminButtons()
50 * 487: function adminFunctions($backPath)
51 * 520: function wrapLinkWithAB($link)
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);
107 $selectItems=array();
110 $onBlur=$GLOBALS['CLIENT']['FORMSTYLE'] ? 'this.blur();' : '';
112 $selectItems[] = '<option value="">[ '.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.selMenu_modules',1).' ]</option>';
115 // Remove the 'doc' module?
116 if ($BE_USER->getTSConfigVal('options.disableDocModuleInAB')) {
117 unset($theModules['doc']);
120 // Get collapsed configuration
121 if ($collapsable == 1) {
122 $config = is_array ($BE_USER->uc['moduleData']['alt_menu.php']) ? $BE_USER->uc['moduleData']['alt_menu.php'] : array();
123 $collapsedOverride = t3lib_div::_GP('collapsedOverride');
124 if (is_array ($collapsedOverride)) {
125 $config = array_merge ($config, $collapsedOverride);
128 if (t3lib_div::_GP('collapsableExpandAll') == 1) {
129 $config['expandAll'] = t3lib_div::_GP('expandAll');
132 if ($config['expandAll'] && is_array($collapsedOverride)) {
133 $config = $collapsedOverride;
136 $BE_USER->uc['moduleData']['alt_menu.php'] = $config;
137 $BE_USER->writeUC($BE_USER->uc);
139 // all items have to be expanded when expandAll is set
140 if($config['expandAll'] == 1) {
141 foreach($config as $key => $value) {
142 if($key != 'expandAll')
148 // Traverse array with modules
150 while(list($moduleName,$moduleInfo)=each($theModules)) {
153 $prefix=$this->getNavFramePrefix ($moduleInfo);
155 $this->fsMod[]='fsMod.recentIds["'.$moduleName.'"]="";';
158 // If there are submodules:
159 if (is_array($moduleInfo['sub'])) {
160 // Finding the default module to display
161 if ($moduleInfo['defaultMod']) {
162 $link = $moduleInfo['sub'][$moduleInfo['defaultMod']]['script'];
164 reset($moduleInfo['sub']);
165 $subTemp = current($moduleInfo['sub']);
166 $link = $subTemp['script'];
168 $link_sub = 1; // Tells that the main modules links to a submodule
169 $link = ''; // Does not link to submodules...
171 $link = $moduleInfo['script'];
175 $link = t3lib_div::resolveBackPath($link);
177 $moduleKey = $moduleName.'_tab';
178 $moduleCSSId = 'ID_'.t3lib_div::md5int($moduleName);
180 // Creating image icon
181 $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath));
183 $descr3_title = $LANG->moduleLabels['tabs'][$moduleKey].' ';
185 $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$moduleKey],$backPath);
186 $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' alt="" />';
187 $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($descr3_title).'" alt="" />';
189 $descr3_imageCode = '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/dummy_module.gif','width="14" height="12"').' title="'.htmlspecialchars($descr3_title).'" alt="" />';
192 // Creating the various links:
193 $label = $LANG->moduleLabels['tabs'][$moduleKey];
194 if ($link && $prefix) $link=$prefix.rawurlencode($link);
195 if ($link && !$dontLink) {
196 $label = '<a href="#" onclick="top.goToModule(\''.$moduleName.'\');'.$onBlur.'return false;">'.$label.'</a>'; // && !$link_sub
198 $mIcons[] = '<a href="#" onclick="top.goToModule(\''.$moduleName.'\');'.$onBlur.'return false;" class="c-mainitem" id="'.$moduleCSSId.'">'.$descr3_imageCode.'</a>';
201 top.content.location=top.getModuleUrl(top.TS.PATH_typo3+\''.$this->wrapLinkWithAB($link).'\'+additionalGetVariables);
202 top.highlightModuleMenuItem("'.$moduleCSSId.'",1);';
203 $mJScmds[] = "case '".$moduleName."': \n ".$JScmd." \n break;";
206 $selectItems[] = '<option value="top.goToModule(\''.$moduleName.'\');">'.htmlspecialchars($LANG->moduleLabels['tabs'][$moduleKey]).'</option>';
207 $label=' <b>'.$label.'</b> ';
210 // make menu collapsable
211 if($collapsable == 1 && is_array($moduleInfo['sub'])) {
212 $collapseJS = 'onclick="window.location.href=\'alt_menu.php?collapsedOverride['.$moduleName.']='.($config[$moduleName] ? '0' : '1').'\'"';
213 $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>';
215 $collapseJS = $collapseIcon = '';
218 // Creating a main item for the vertical menu (descr=0)
220 <tr class="c-mainitem" id="'.$moduleCSSId.'">
221 <td colspan="3" '.$collapseJS.' >'.$imageCode.'<span class="c-label">'.$label.'</span>'.$collapseIcon.'</td>
224 // Code for "About modules"
226 <tr class="c-mainitem bgColor4">
227 <td colspan="3">'.$imageCode.$label.'</td>
231 // Hide submodules when collapsed:
232 if($collapsable == 1 && $config[$moduleName] == 1 && $descr == 0 && $config['expandAll'] != 1) {
233 unset($moduleInfo['sub']);
236 // Traversing submodules
238 if (is_array($moduleInfo['sub'])) {
239 reset($moduleInfo['sub']);
241 while(list($subName,$subInfo)=each($moduleInfo['sub'])) {
245 <td colspan="3"></td>
249 <td colspan="3"></td>
253 $link = t3lib_div::resolveBackPath($subInfo['script']);
254 $prefix=$this->getNavFramePrefix ($moduleInfo, $subInfo);
256 $subKey = $moduleName.'_'.$subName.'_tab';
257 $moduleCSSId = 'ID_'.t3lib_div::md5int($moduleName.'_'.$subName);
259 // Creating image icon
260 $image = @getimagesize($this->mIconFile($LANG->moduleLabels['tabs_images'][$subKey],$backPath));
262 $descr3_title = $LANG->moduleLabels['tabs'][$subKey].': '.$LANG->moduleLabels['labels'][$subKey.'label'];
264 $Ifilename = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$subKey],$backPath);
265 $imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'" alt="" />';
266 $descr3_imageCode = '<img src="'.$Ifilename.'" '.$image[3].' title="'.htmlspecialchars($descr3_title).'" alt="" />';
268 $descr3_imageCode = '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/dummy_module.gif','width="14" height="12"').' title="'.htmlspecialchars($descr3_title).'" alt="" />';
271 // Label for submodule:
272 $label = $LANG->moduleLabels['tabs'][$subKey];
273 $label_descr = ' title="'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'"';
274 $flabel = htmlspecialchars($label);
276 if ($link && $prefix) $link=$prefix.rawurlencode($link);
278 // Setting additional JavaScript if frameset script:
280 if ($moduleInfo['navFrameScript']) {$addJS="+'&id='+top.rawurlencode(top.fsMod.recentIds['".$moduleName."'])";}
282 // If there is a script to link to (and linking is not disabled.
283 if ($link && !$dontLink) {
284 // For condensed mode, send &cMR parameter to frameset script.
285 if ($addJS && $BE_USER->uc['condensedMode']) {$addJS.= "+(cMR?'&cMR=1':'')";}
287 // Command for the selector box:
289 top.content.location=top.getModuleUrl(top.TS.PATH_typo3+'".$this->wrapLinkWithAB($link)."'".$addJS.'+additionalGetVariables);
290 top.fsMod.currentMainLoaded="'.$moduleName.'";
293 // If there is a frameset script in place:
294 if (!$BE_USER->uc['condensedMode'] && $moduleInfo['navFrameScript']) {
296 // use special nav script from sub module, otherwise from the main module
297 $subNavFrameScript = $subInfo['navFrameScript'] ? $subInfo['navFrameScript'] : $moduleInfo['navFrameScript'];
298 $subNavFrameScript = t3lib_div::resolveBackPath($subNavFrameScript);
300 // add GET params for sub module to the nav script
301 $subNavFrameScript = $this->wrapLinkWithAB($subNavFrameScript).$subInfo['navFrameScriptParam'];
304 if (top.content.list_frame && top.fsMod.currentMainLoaded=="'.$moduleName.'") {
305 top.currentSubScript="'.$origLink.'";
306 top.content.list_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->wrapLinkWithAB($origLink).'"'.$addJS.'+additionalGetVariables);
307 if(top.currentSubNavScript!="'.$subNavFrameScript.'") {
308 top.currentSubNavScript="'.$subNavFrameScript.'";
309 top.content.nav_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$subNavFrameScript.'");
312 top.content.location=top.TS.PATH_typo3+(
313 top.nextLoadModuleUrl?
314 "'.($prefix?$this->wrapLinkWithAB($link).'&exScript=':'').'listframe_loader.php":
315 "'.$this->wrapLinkWithAB($link).'"'.$addJS.'+additionalGetVariables
317 top.fsMod.currentMainLoaded="'.$moduleName.'";
318 top.currentSubScript="'.$origLink.'";
322 $selectItems[] = '<option value="top.goToModule(\''.$moduleName.'_'.$subName.'\');">'.htmlspecialchars('- '.$label).'</option>';
323 $onClickString = htmlspecialchars('top.goToModule(\''.$moduleName.'_'.$subName.'\');'.$onBlur.'return false;');
325 $flabel = '<a href="#" onclick="'.$onClickString.'"'.$label_descr.'>'.htmlspecialchars($label).'</a>';
327 $mIcons[] = '<a href="#" onclick="'.$onClickString.'"'.$label_descr.' class="c-subitem" id="'.$moduleCSSId.'">'.$descr3_imageCode.'</a>';
330 top.highlightModuleMenuItem("'.$moduleCSSId.'");';
331 $mJScmds[] = "case '".$moduleName.'_'.$subName."': \n ".$JScmd." \n break;";
335 <tr class="c-subitem-row" id="'.$moduleCSSId.'">
337 <td align="center">'.(!$BE_USER->uc['hideSubmoduleIcons']?$imageCode:'').'</td>
338 <td class="c-subitem-label">'.$flabel.'</td>
341 // For "About modules":
343 <tr class="c-subitem-row">
344 <td align="center">'.$imageCode.'</td>
345 <td>'.$flabel.' </td>
346 <td><strong>'.htmlspecialchars($LANG->moduleLabels['labels'][$subKey.'label']).'</strong><br />'.$LANG->moduleLabels['labels'][$subKey.'descr'].'</td>
349 // Possibly adding a divider line
351 if ($c<count($moduleInfo['sub'])) {
354 <tr class="c-divrow">
355 <td colspan="3"><img'.t3lib_iconWorks::skinImg($backPath,'gfx/altmenuline.gif','width="105" height="3"').' alt="" /></td>
359 // Spacer gif for top menu:
360 if (count($theModules)>$mC) {
361 $mIcons[]='<img src="'.$backPath.'gfx/acm_spacer2.gif" width="8" height="12" hspace="3" alt="" />';
365 // Add spacers after each main section:
367 <tr class="c-endrow">
368 <td colspan="3"></td>
371 <tr class="c-endrow">
372 <td colspan="3"></td>
379 // $descr==0: Ordinary vertical menu
381 if($collapsable == 1 || $config['expandAll'] == 1) {
382 $collapseAllHTML = '<tr class="c-endrow">
385 <form action="alt_menu.php" method="get">
386 <input type="hidden" name="collapsableExpandAll" value="1" />
387 <input type="checkbox" name="expandAll" value="1" onclick="this.form.submit();" '.($config['expandAll']?'checked="checked"':'').' />
390 <td class="c-subitem-label">'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.expandAll',1).'</td>
393 $collapseAllHTML = '';
400 Vertical module menu, shown in left frame of backend.
402 <table border="0" cellpadding="0" cellspacing="0" id="typo3-vmenu">
404 <tr class="c-endrow">
405 <td colspan="3">'.t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'menu_modules', $GLOBALS['BACK_PATH']).'</td></tr>
410 // Output for the "About modules" module
416 Listing of modules, for Help > About modules
418 <table border="0" cellpadding="0" cellspacing="0" id="typo3-about-modules">
427 // Add admin-functions for clearing caches:
428 if ($BE_USER->isAdmin()) {
429 $functionArray = $this->adminFunctions($backPath);
430 if (count($functionArray)) {
431 $selectItems[] = '<option value=""></option>';
432 foreach($functionArray as $fAoptions) {
433 $selectItems[] = '<option value="'.htmlspecialchars("document.location='".$fAoptions['href']."';").'">[ '.htmlspecialchars($fAoptions['title']).' ]</option>';
439 $selectItems[] = '<option value=""></option>';
440 $selectItems[] = '<option value="'.htmlspecialchars("top.location='logout.php';").'">[ '.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.logout',1).' ]</option>';
442 <select name="menuselector" onchange="eval(this.options[this.selectedIndex].value);">
447 // topmenu - horizontal line of icons!
449 $final = ''.implode('',$mIcons).'';
452 // Output for the goToModules() function in main frameset.
454 $final = chr(10).implode(chr(10),$mJScmds).chr(10);
462 * Returns a prefix used to call the navframe with parameters to call the scripts defined in the modules info array.
464 * @param string Module info array
465 * @param string Submodule info array
466 * @return string Result url string
468 function getNavFramePrefix ($moduleInfo, $subModuleInfo=array()) {
472 $navFrameScriptParam = $subModuleInfo['navFrameScriptParam'] ? $subModuleInfo['navFrameScriptParam'] : $moduleInfo['navFrameScriptParam'];
473 if ($moduleInfo['navFrameScript']) {
474 $navFrameScript = t3lib_div::resolveBackPath($moduleInfo['navFrameScript']);
475 $navFrameScript = $this->wrapLinkWithAB($navFrameScript);
477 if ($BE_USER->uc['condensedMode']) {
478 $prefix=$navFrameScript.$navFrameScriptParam.'¤tSubScript=';
480 $prefix='alt_mod_frameset.php?'.
481 'fW="+top.TS.navFrameWidth+"'.
482 '&nav="+top.TS.PATH_typo3+"'.rawurlencode($navFrameScript.$navFrameScriptParam).
490 * Returns $Ifilename readable for script in PATH_typo3.
491 * That means absolute names are just returned while relative names are prepended with $backPath (pointing back to typo3/ dir)
493 * @param string Icon filename
494 * @param string Back path
495 * @return string Result
496 * @see mIconFilename()
498 function mIconFile($Ifilename,$backPath) {
499 if (t3lib_div::isAbsPath($Ifilename)) {
502 return $backPath.$Ifilename;
506 * Returns relative filename to the $Ifilename (for use in img-tags)
508 * @param string Icon filename
509 * @param string Back path
510 * @return string Result
513 function mIconFilename($Ifilename,$backPath) {
514 if (t3lib_div::isAbsPath($Ifilename)) {
515 $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
517 return $backPath.$Ifilename;
521 * Returns logout button.
525 function topButtons() {
528 $out.= '<form action="logout.php" target="_top"><input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.logout',1).'" /></form>';
533 * Returns logout button.
537 function adminButtons() {
540 $functionArray = $this->adminFunctions('');
543 foreach($functionArray as $fAoptions) {
544 $icons[]= '<a href="'.htmlspecialchars($fAoptions['href']).'">'.$fAoptions['icon'].'</a>';
547 return implode('',$icons);
551 * Returns array with parts from which the admin functions can be constructed.
553 * @param string Backpath.
556 function adminFunctions($backPath) {
557 global $LANG,$BE_USER,$TYPO3_CONF_VARS;
561 // Clearing of cache-files in typo3conf/ + menu
562 if ($TYPO3_CONF_VARS['EXT']['extCache']) {
563 $title = $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_allTypo3Conf');
566 'href' => $backPath.'tce_db.php?vC='.$BE_USER->veriCode().'&redirect='.rawurlencode(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT')).'&cacheCmd=temp_CACHED',
567 'icon' => '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/clear_cache_files_in_typo3c.gif','width="21" height="18"').' title="'.htmlspecialchars($title).'" alt="" />'
571 // Clear all page cache
572 $title = $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_all');
575 'href' => $backPath.'tce_db.php?vC='.$BE_USER->veriCode().'&redirect='.rawurlencode(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT')).'&cacheCmd=all',
576 'icon' => '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/clear_all_cache.gif','width="21" height="18"').' title="'.htmlspecialchars($title).'" alt="" />'
584 * Appends a '?' if there is none in the string already
586 * @param string Link URL
589 function wrapLinkWithAB($link) {
590 if (!strstr($link,'?')) {
597 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.alt_menu_functions.inc']) {
598 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.alt_menu_functions.inc']);