* @copyright 2004 by http://wombat.exit0.net * @package wombatModule * @subpackage TreeMenu */ /** * Displays html tree menues * * @version 1.1.0 * @package wombatSite * @subpackage module */ class wbModule_TreeMenu extends wbModule { /** * some parameter * * @access private * @public array $_params */ public $_params = array( 'tmpldir' => 'module/TreeMenu', 'tmpl' => 'menu' ); /** * some request defaults * * @access private * @public array $_requestDefaults */ public $_requestDefaults = array( 'path' => NULL, ); /** * path as array * * @access private * @public array $_path */ public $_path = array(); /** * recieve content * * @return string $html */ function getHtml() { wbFactory::includeClass( 'wbMenuTools' ); $menu = wbMenuTools::getMenu(); if( patErrorManager::isError( $menu ) ) { return $menu; } // select path $depth = 0; if( !empty( $this->_request['path'] ) ) { $this->_path = explode( '/', $this->_request['path'] ); } $this->_loadTemplates( $this->_params['tmpl'] ); $html = $this->_path2Html( $menu, $depth ); $this->_tmpl->addVar( 'wbModule_TreeMenu', 'menu', $html ); return $this->_tmpl->getParsedTemplate( 'wbModule_TreeMenu' ); } /** * build html from path and menu items * * Walk through menu and select items by path. * This function is recursive * * @access private * @param array $menu * @param int $depth * @return string $html */ function _path2Html( $menu, $depth ) { $items = array(); $page = null; if( !empty( $this->_path ) && isset( $this->_path[$depth] ) ) { $page = $this->_path[$depth]; } for( $i = 0; $i < count( $menu ); ++$i ) { $level = array(); $level['depth'] = $depth; $level['page'] = $menu[$i]['page']; $level['state'] = 'item'; if( $page == $level['page'] ) { $level['state'] = 'selected'; } $level['path'] = $level['page']; if( $depth && isset( $this->_path[$depth - 1 ] ) ) { $level['path'] = array_slice( $this->_path, 0, $depth ); array_push( $level['path'], $level['page'] ); $level['path'] = implode( '/', $level['path'] ); } $level['title'] = _( $menu[$i]['title'] ); $level['brief'] = _( $menu[$i]['brief'] ); array_push( $items, $level ); // add submenu if( $page == $level['page'] && isset( $menu[$i]['menu'] ) ) { $level = array(); $level['state'] = 'submenu'; $level['depth'] = $depth; $level['submenu'] = $this->_path2Html( $menu[$i]['menu'], ( $depth + 1 ) ); array_push( $items, $level ); } } $this-> _tmpl->addRows( 'wbModule_TreeMenu_level_' . $depth, $items ); $html = $this->_tmpl->getParsedTemplate( 'wbModule_TreeMenu_level_' . $depth ); return $html; } } ?>