label = $label; $this->href = $href; $this->childMenu = $childMenu; $this->style = $style; $this->accesskey = $accesskey; } function getLabel() { return $this->label; } function getHref() { return $this->href; } function getChildMenu() { return $this->childMenu; } function getStyle() { return $this->style; } function getAccess() { return $this->accesskey; } } function treeMenu($array) { $menuItemFormat = '
  • %s%s
  • '; $menuItemSelFormat = '
  • %s%s
  • '; return treeMenuMaker($array, $menuItemFormat, $menuItemSelFormat); } function treeMenuMaker($array, $menuItemFormat, $menuItemSelFormat) { $treeMenu = ""; $uri = $_SERVER['REQUEST_URI']; foreach ($array as $index => $menuItem) { $label = $menuItem->getLabel(); $href = $menuItem->getHref(); $style = $menuItem->getStyle(); $accesskey = $menuItem->getAccess(); $hasChildren = (is_array($menuItem->getChildMenu())); // "$index == 0" is a check for homepage (assumes that is first) - this is a special case that we must always do a full compare $isDirectoryHref = (strrpos($href, "/") === (strlen($href) - 1)); $fullCompare = ($index == 0 || !$isDirectoryHref); if ($fullCompare) $comp = $index."full"; else $comp = $index."part"; $selected = ($fullCompare ? $uri == $href : strpos($uri, $href) === 0); if ($selected) { $menuTpl = $menuItemSelFormat; } else { $menuTpl = $menuItemFormat; } $childMenu = ""; if ($selected && $hasChildren) { $childMenu = sprintf ("\n", treeMenuMaker($menuItem->getChildMenu(), $menuItemFormat, $menuItemSelFormat)); } $treeMenu .= sprintf($menuTpl, $style, $href, $accesskey, $label, $childMenu)."\n"; } return $treeMenu; } ?>