// This file is an extension to HTML_TreeMenu, by Richard Heyes.
// Much of the code is based on Heyes' client-side JavaScript code.
include_once('TreeMenu.php');
include_once('ccBrowserInfo.php');
// Browser detection determines whether we generate DHTML menus
static $tmsDoesMenus = 'maybe';
class HTML_TreeMenuSafe extends HTML_TreeMenu
{
// Constructor
function HTML_TreeMenuSafe($layer=null, $images=null, $linkTarget = '_self', $usePersistence = true)
{
if ($GLOBALS['tmsDoesMenus'] == 'maybe') {
$tmb = new ccBrowserInfo();
$GLOBALS['tmsDoesMenus'] = ($tmb->is_ie5up() || $tmb->is_moz5up);
}
HTML_TreeMenu::HTML_TreeMenu($layer, $images, $linkTarget, $usePersistence);
} // HTML_TreeMenuSafe
function printMenu($images=null, $rigidmenu=false, $layer=null)
{
if (!$rigidmenu && $GLOBALS['tmsDoesMenus']) HTML_TreeMenu::printMenu($images, $layer);
elseif (!empty($this->items)) {
// Static menu
// $images could have been set in the constructor,
// so don't assign to it unless a value has been supplied here.
// $layer is not used for static menus.
if (!empty($images)) $this->images = $images;
for ($i=0; $i < count($this->items); $i++) {
$this->_printStaticMenu($this, $i);
}
} // static menu
} // printMenu
//
// Helper Functions
//
// Print HTML for a single menu node
// This code is based on the JavaScript function drawMenu().
function _printNode($thisnode, $currentlevel, $prepend='', $modifier='')
{
if (empty($this->images)) {
// No images in output
$iconimg = '';
$imgTag = '';
}
else {
$gifname = 'branch';
$iconimg = $thisnode->icon ? sprintf('',
$this->images, $thisnode->icon) : '';
$imgTag = sprintf('',
$this->images, $gifname, $modifier);
}
$linkStart = $thisnode->link ? sprintf('',
$thisnode->link, $this->linkTarget) : '';
$linkEnd = $thisnode->link ? '' : '';
$titleString = $thisnode->text;
$styleStart = '';
$styleEnd = '';
if ($thisnode->style == 'auto') {
$styleInx = min($currentlevel, count($GLOBALS['_autostyles'])-1);
$styleStart = '';
$styleEnd = '';
}
echo ''. $styleStart . $prepend .
(parentLayerID == null && nodes.length == 1 ? '' : $imgTag) .
$iconimg .
$linkStart . $titleString . $linkEnd .
$styleEnd . "
\n";
} // _printNode
// Static menu.
// Print current node and all subnodes
function _printStaticMenu($nodeParent, $nodeinx, $currentlevel=0, $prepend='')
{
$thisnode = $nodeParent->items[$nodeinx];
$cntSubnodes = empty($thisnode->items) ? 0 : count($thisnode->items);
$cntSiblings = empty($nodeParent->items) ? 0 : count($nodeParent->items);
// Gif modifier
if ($nodeinx == 0 && $currentlevel == 0) $modifier = $cntSubnodes > 1 ? 'top' : 'single';
elseif ($nodeinx == ($cntSiblings - 1)) $modifier = 'bottom';
else $modifier = '';
$this->_printNode($thisnode, $currentlevel, $prepend, $modifier);
// Print any subnodes
for ($i=0; $i<$cntSubnodes; $i++) {
// Determine what to prepend to child subnode entries.
$newPrepend = $prepend;
if (empty($this->images)) {
// No images. Use spaces instead
$newPrepend .= ' ';
}
else {
// Prepend images to each menu entry
//if ($currentlevel == 0 && $cntSiblings == 1) $nppimg = '';
//^^^ This special case does not apply to static menus.
// Why? Bwaaa Ha Ha Ha Haaaaaaa!! Try it and see. Happy Halloween...
if ($nodeinx < ($cntSiblings - 1)) $nppimg = 'line.gif';
else $nppimg = 'linebottom.gif';
$newPrepend .= sprintf('', $nodeinx, $cntSubnodes, $this->images, $nppimg);
}
// Now print the menu entry for this node
$this->_printStaticMenu($thisnode, $i, $currentlevel+1, $newPrepend);
}
} // _printStaticMenu
} // class HTML_TreeMenuSafe
?>