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