2 /***************************************************************
5 * (c) 2007 Ingo Renner <ingo@typo3.org>
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 ***************************************************************/
30 * class to render the TYPO3 backend menu for the modules
32 * @author Ingo Renner <ingo@typo3.org>
39 * module loading object
41 * @var t3lib_loadModules
43 protected $moduleLoader;
47 private $loadedModules;
48 private $fsMod; //TODO find a more descriptive name, left over from alt_menu_functions
51 * constructor, initializes several variables
55 public function __construct() {
58 $this->fsMod
= array();
59 $this->linkModules
= true;
61 // Loads the backend modules available for the logged in user.
62 $this->moduleLoader
= t3lib_div
::makeInstance('t3lib_loadModules');
63 $this->moduleLoader
->observeWorkspaces
= true;
64 $this->moduleLoader
->load($GLOBALS['TBE_MODULES']);
65 $this->loadedModules
= $this->moduleLoader
->modules
;
70 * sets the path back to /typo3/
72 * @param string path back to /typo3/
75 public function setBackPath($backPath) {
76 if(!is_string($backPath)) {
77 throw new InvalidArgumentException('parameter $backPath must be of type string', 1193315266);
80 $this->backPath
= $backPath;
84 * loads the collapse states for the main modules from user's configuration (uc)
86 * @return array collapse states
88 private function getCollapsedStates() {
90 $collapsedStates = array();
91 if($GLOBALS['BE_USER']->uc
['moduleData']['moduleMenu']) {
92 $collapsedStates = $GLOBALS['BE_USER']->uc
['moduleData']['moduleMenu'];
95 return $collapsedStates;
99 * returns the loaded modules
101 * @return array array of loaded modules
103 public function getLoadedModules() {
104 return $this->loadedModules
;
108 * renders the backend menu as unordered list
110 * @return string menu html code to use in the backend
112 public function render() {
114 $onBlur = $GLOBALS['CLIENT']['FORMSTYLE'] ?
'this.blur();' : '';
116 $rawModuleData = $this->getRawModuleData();
118 foreach($rawModuleData as $moduleKey => $moduleData) {
120 $moduleLabel = $moduleData['title'];
121 if($moduleData['link'] && $this->linkModules
) {
122 $moduleLabel = '<a href="#" onclick="top.goToModule(\''.$moduleData['name'].'\');'.$onBlur.'return false;">'.$moduleLabel.'</a>';
125 //TODO make icon a background image using css
126 $menu .= '<li><div>'.$moduleData['icon']['html'].' '.$moduleLabel.'</div>';
128 // traverse submodules
129 if(is_array($moduleData['subitems'])) {
130 $menu .= $this->renderSubModules($moduleData['subitems']);
133 $menu .= '</li>'."\n";
136 return '<ul id="typo3-menu">'."\n".$menu.'</ul>'."\n";
142 * @param array array of (sub)module data
143 * @return string (sub)module html code
145 public function renderSubModules($modules) {
147 $onBlur = $GLOBALS['CLIENT']['FORMSTYLE'] ?
'this.blur();' : '';
149 foreach($modules as $moduleKey => $moduleData) {
150 // Setting additional JavaScript
151 $additionalJavascript = '';
152 if($moduleData['parentNavigationFrameScript']) {
153 $parentModuleName = substr($moduleData['name'], 0, strpos($moduleData['name'], '_'));
154 $additionalJavascript = "+'&id='+top.rawurlencode(top.fsMod.recentIds['".$parentModuleName."'])";
157 if($moduleData['link'] && $this->linkModules
) {
159 $onClickString = htmlspecialchars('top.goToModule(\''.$moduleData['name'].'\');'.$onBlur.'return false;');
160 $submoduleLink = '<a href="#" onclick="'.$onClickString.'" title="'.$moduleData['description'].'">'
161 //TODO make icon a background image using css
162 .$moduleData['icon']['html'].' '
163 .'<span>'.htmlspecialchars($moduleData['title']).'</span>'
167 $moduleMenu .= '<li>'.$submoduleLink.'</li>'."\n";
170 return '<ul>'."\n".$moduleMenu.'</ul>'."\n";
174 * gets the raw module data
176 * @return array multi dimension array with module data
178 public function getRawModuleData() {
181 // Remove the 'doc' module?
182 if($GLOBALS['BE_USER']->getTSConfigVal('options.disableDocModuleInAB')) {
183 unset($this->loadedModules
['doc']);
186 foreach($this->loadedModules
as $moduleName => $moduleData) {
187 $moduleNavigationFramePrefix = $this->getNavigationFramePrefix($moduleData);
189 if($moduleNavigationFramePrefix) {
190 $this->fsMod
[$moduleName] = 'fsMod.recentIds["'.$moduleName.'"]="";';
194 if(!is_array($moduleData['sub'])) {
195 $moduleLink = $moduleData['script'];
197 $moduleLink = t3lib_div
::resolveBackPath($moduleLink);
199 $moduleKey = $moduleName.'_tab';
200 $moduleCssId = 'ID_'.t3lib_div
::md5int($moduleName);
201 $moduleIcon = $this->getModuleIcon($moduleKey);
203 if($moduleLink && $moduleNavigationFramePrefix) {
204 $moduleLink = $moduleNavigationFramePrefix.rawurlencode($moduleLink);
207 $modules[$moduleKey] = array(
208 'name' => $moduleName,
209 'title' => $GLOBALS['LANG']->moduleLabels
['tabs'][$moduleKey],
210 'onclick' => 'top.goToModule(\''.$moduleName.'\');',
211 'cssId' => $moduleCssId,
212 'icon' => $moduleIcon,
213 'link' => $moduleLink,
214 'prefix' => $moduleNavigationFramePrefix
217 if(is_array($moduleData['sub'])) {
219 foreach($moduleData['sub'] as $submoduleName => $submoduleData) {
220 $submoduleLink = t3lib_div
::resolveBackPath($submoduleData['script']);
221 $submoduleNavigationFramePrefix = $this->getNavigationFramePrefix($moduleData, $submoduleData);
223 $submoduleKey = $moduleName.'_'.$submoduleName.'_tab';
224 $submoduleCssId = 'ID_'.t3lib_div
::md5int($moduleName.'_'.$submoduleName);
225 $submoduleIcon = $this->getModuleIcon($submoduleKey);
226 $submoduleDescription = $GLOBALS['LANG']->moduleLabels
['labels'][$submoduleKey.'label'];
228 $originalLink = $submoduleLink;
229 if($submoduleLink && $submoduleNavigationFramePrefix) {
230 $submoduleLink = $submoduleNavigationFramePrefix.rawurlencode($submoduleLink);
233 $modules[$moduleKey]['subitems'][$submoduleKey] = array(
234 'name' => $moduleName.'_'.$submoduleName,
235 'title' => $GLOBALS['LANG']->moduleLabels
['tabs'][$submoduleKey],
236 'onclick' => 'top.goToModule(\''.$moduleName.'_'.$submoduleName.'\');',
237 'cssId' => $submoduleCssId,
238 'icon' => $submoduleIcon,
239 'link' => $submoduleLink,
240 'originalLink' => $originalLink,
241 'prefix' => $submoduleNavigationFramePrefix,
242 'description' => $submoduleDescription
245 if($moduleData['navFrameScript']) {
246 $modules[$moduleKey]['subitems'][$submoduleKey]['parentNavigationFrameScript'] = $moduleData['navFrameScript'];
256 * gets the module icon and its size
258 * @param string module key
259 * @return array icon data array with 'filename', 'size', and 'html'
261 private function getModuleIcon($moduleKey) {
263 $iconFileRelative = $this->getModuleIconRelative($GLOBALS['LANG']->moduleLabels
['tabs_images'][$moduleKey]);
264 $iconFileAbsolute = $this->getModuleIconAbsolute($GLOBALS['LANG']->moduleLabels
['tabs_images'][$moduleKey]);
265 $iconSizes = @getimagesize
($iconFileAbsolute);
266 $iconTitle = $GLOBALS['LANG']->moduleLabels
['tabs'][$moduleKey];
268 $icon['filename'] = $iconFileRelative;
269 $icon['size'] = $iconSizes[3];
270 $icon['title'] = htmlspecialchars($iconTitle);
271 $icon['html'] = '<img src="'.$iconFileRelative.'" '.$iconSizes[3].' title="'.htmlspecialchars($iconTitle).'" alt="'.htmlspecialchars($iconTitle).'" />';
277 * Returns the filename readable for the script from PATH_typo3.
278 * That means absolute names are just returned while relative names are
279 * prepended with the path pointing back to typo3/ dir
281 * @param string icon filename
282 * @return string icon filename with absolute path
283 * @see getModuleIconRelative()
285 private function getModuleIconAbsolute($iconFilename) {
287 if(!t3lib_div
::isAbsPath($iconFilename)) {
288 $iconFilename = $this->backPath
.$iconFilename;
291 return $iconFilename;
295 * Returns relative path to the icon filename for use in img-tags
297 * @param string icon filename
298 * @return string icon filename with relative path
299 * @see getModuleIconAbsolute()
301 private function getModuleIconRelative($iconFilename) {
302 if(t3lib_div
::isAbsPath($iconFilename)) {
303 $iconFilename = '../'.substr($iconFilename, strlen(PATH_site
));
306 return $this->backPath
.$iconFilename;
310 * Returns a prefix used to call the navigation frame with parameters which then will call the scripts defined in the modules info array.
312 * @param array module data array
313 * @param array submodule data array
314 * @return string result URL string
316 private function getNavigationFramePrefix($moduleData, $subModuleData = array()) {
319 $navigationFrameScript = $moduleData['navFrameScript'];
320 if($subModuleData['navFrameScript']) {
321 $navigationFrameScript = $subModuleData['navFrameScript'];
324 $navigationFrameParameter = $moduleData['navFrameScriptParam'];
325 if($subModuleData['navFrameScriptParam']) {
326 $navigationFrameParameter = $subModuleData['navFrameScriptParam'];
329 if($navigationFrameScript) {
330 $navigationFrameScript = t3lib_div
::resolveBackPath($navigationFrameScript);
331 $navigationFrameScript = $this->appendQuestionmarkToLink($navigationFrameScript);
333 if($GLOBALS['BE_USER']->uc
['condensedMode']) {
334 $prefix = $navigationFrameScript.$navigationFrameParameter.'¤tSubScript=';
336 $prefix = 'alt_mod_frameset.php?'
337 .'fW="+top.TS.navFrameWidth+"'
338 .'&nav="+top.TS.PATH_typo3+"'
339 .rawurlencode($navigationFrameScript.$navigationFrameParameter)
348 * generates javascript code to switch between modules
350 * @return string javascript code snippet to switch modules
352 public function getGotoModuleJavascript() {
354 $moduleJavascriptCommands = array();
355 $rawModuleData = $this->getRawModuleData();
357 foreach($rawModuleData as $mainModuleKey => $mainModuleData) {
358 if($mainModuleData['subitems']) {
359 foreach($mainModuleData['subitems'] as $subModuleKey => $subModuleData) {
361 $parentModuleName = substr($subModuleData['name'], 0, strpos($subModuleData['name'], '_'));
362 $javascriptCommand = '';
364 // Setting additional JavaScript if frameset script:
365 $additionalJavascript = '';
366 if($subModuleData['parentNavigationFrameScript']) {
367 $additionalJavascript = "+'&id='+top.rawurlencode(top.fsMod.recentIds['".$parentModuleName."'])";
370 if($subModuleData['link'] && $this->linkModules
) {
371 // For condensed mode, send &cMR parameter to frameset script.
372 if($additionalJavascript && $GLOBALS['BE_USER']->uc
['condensedMode']) {
373 $additionalJavascript .= "+(cMR?'&cMR=1':'')";
376 $javascriptCommand = '
377 top.content.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->appendQuestionmarkToLink($subModuleData['link']).'"'.$additionalJavascript.'+additionalGetVariables);
378 top.fsMod.currentMainLoaded="'.$parentModuleName.'";
381 if($subModuleData['navFrameScript']) {
382 $javascriptCommand .= '
383 top.currentSubScript="'.$subModuleData['originalLink'].'";';
386 if(!$GLOBALS['BE_USER']->uc
['condensedMode'] && $subModuleData['parentNavigationFrameScript']) {
387 $additionalJavascript = "+'&id='+top.rawurlencode(top.fsMod.recentIds['".$parentModuleName."'])";
389 $submoduleNavigationFrameScript = $subModuleData['navigationFrameScript'] ?
$subModuleData['navigationFrameScript'] : $subModuleData['parentNavigationFrameScript'];
390 $submoduleNavigationFrameScript = t3lib_div
::resolveBackPath($submoduleNavigationFrameScript);
392 // add GET parameters for sub module to the navigation script
393 $submoduleNavigationFrameScript = $this->appendQuestionmarkToLink($submoduleNavigationFrameScript).$subModuleData['navigationFrameScript'];
395 $javascriptCommand = '
396 if (top.content.list_frame && top.fsMod.currentMainLoaded=="'.$parentModuleName.'") {
397 top.currentSubScript="'.$subModuleData['originalLink'].'";
398 top.content.list_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->appendQuestionmarkToLink($subModuleData['originalLink']).'"'.$additionalJavascript.'+additionalGetVariables);
399 if(top.currentSubNavScript!="'.$submoduleNavigationFrameScript.'") {
400 top.currentSubNavScript="'.$submoduleNavigationFrameScript.'";
401 top.content.nav_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$submoduleNavigationFrameScript.'");
404 top.content.location=top.TS.PATH_typo3+(
405 top.nextLoadModuleUrl?
406 "'.($subModuleData['prefix'] ?
$this->appendQuestionmarkToLink($subModuleData['link']).'&exScript=' : '').'listframe_loader.php":
407 "'.$this->appendQuestionmarkToLink($subModuleData['link']).'"'.$additionalJavascript.'+additionalGetVariables
409 top.fsMod.currentMainLoaded="'.$parentModuleName.'";
410 top.currentSubScript="'.$subModuleData['originalLink'].'";
415 $javascriptCommand .= '
416 top.highlightModuleMenuItem("'.$subModuleData['cssId'].'");
418 $moduleJavascriptCommands[] = "case '".$subModuleData['name']."': \n ".$javascriptCommand." \n break;";
421 } elseif(!$mainModuleData['subitems'] && !empty($mainModuleData['link'])) {
422 // main module has no sub modules but instead is linked itself (doc module)
423 $javascriptCommand = '
424 top.content.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->appendQuestionmarkToLink($mainModuleData['link']).'"+additionalGetVariables);
425 top.highlightModuleMenuItem("'.$mainModuleData['cssId'].'", 1);
427 $moduleJavascriptCommands[] = "case '".$mainModuleData['name']."': \n ".$javascriptCommand." \n break;";
433 * Function used to switch switch module.
435 var currentModuleLoaded = "";
436 function goToModule(modName,cMR_flag,addGetVars) { //
437 var additionalGetVariables = "";
438 if (addGetVars) additionalGetVariables = addGetVars;
441 if (cMR_flag) cMR = 1;
443 currentModuleLoaded = modName;
446 ."\n".implode("\n", $moduleJavascriptCommands)."\n".'
450 return $javascriptCode;
454 * Appends a '?' if there is none in the string already
456 * @param string Link URL
457 * @return string link URl appended with ? if there wasn't one
459 private function appendQuestionmarkToLink($link) {
460 if(!strstr($link, '?')) {
468 * renders the logout button form
470 * @return string html code snippet displaying the logout button
472 public function renderLogoutButton() {
473 $buttonLabel = $GLOBALS['BE_USER']->user
['ses_backuserid'] ?
'LLL:EXT:lang/locallang_core.php:buttons.exit' : 'LLL:EXT:lang/locallang_core.php:buttons.logout';
476 <form action="logout.php" target="_top">
477 <input type="submit" value="'.$GLOBALS['LANG']->sL($buttonLabel, 1).'" />
484 * turns linking of modules on or off
486 * @param boolean status for linking modules with a-tags, set to false to turn lining off
488 public function setLinkModules($linkModules) {
489 if(!is_bool($linkModules)) {
490 throw new InvalidArgumentException('parameter $linkModules must be of type bool', 1193326558);
493 $this->linkModules
= $linkModules;
497 * gets the frameset (leftover) helper
499 * @return array array of javascript snippets
501 public function getFsMod() {
507 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/classes/class.modulemenu.php']) {
508 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/classes/class.modulemenu.php']);