cvs: php4 /pear/HTML Menu.php

From: Date: Mon, 03 Sep 2001 19:14:56 +0000
Subject: cvs: php4 /pear/HTML Menu.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-775@lists.php.net to get a copy of this message
cox Mon Sep 3 15:14:56 2001 EDT Modified files: /php4/pear/HTML Menu.php Log: trailing ws

Index: php4/pear/HTML/Menu.php diff -u php4/pear/HTML/Menu.php:1.5 php4/pear/HTML/Menu.php:1.6 --- php4/pear/HTML/Menu.php:1.5 Sat Aug 11 04:08:06 2001 +++ php4/pear/HTML/Menu.php Mon Sep 3 15:14:56 2001 @@ -17,15 +17,15 @@ // | Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // -// $Id: Menu.php,v 1.5 2001/08/11 08:08:06 sebastian Exp $ -// +// $Id: Menu.php,v 1.6 2001/09/03 19:14:56 cox Exp $ +// /** * Generates a HTML menu from a multidimensional hash. -* -* Special thanks to the original author: Alex Vorobiev <sasha@mathforum.com>. * -* @version $Id: Menu.php,v 1.5 2001/08/11 08:08:06 sebastian Exp $ +* Special thanks to the original author: Alex Vorobiev <sasha@mathforum.com>. +* +* @version $Id: Menu.php,v 1.6 2001/09/03 19:14:56 cox Exp $ * @author Ulf Wendel <ulf.wendel@phpdoc.de> * @access public * @package HTML @@ -34,17 +34,17 @@ class HTML_Menu { /** * URL Environment Variable - * + * * @var array - */ + */ var $url_env_var = 'PHP_SELF'; /** * Menu structure as a multidimensional hash. - * + * * @var array * @see setMenu(), Menu() - */ + */ var $menu = array(); /** @@ -57,7 +57,7 @@ /** * Menu type: tree, rows, you-are-here. - * + * * @var array * @see setMenuType() */ @@ -65,8 +65,8 @@ /** * Path to a certain menu item. - * - * Internal class variable introduced to save some recursion overhead. + * + * Internal class variable introduced to save some recursion overhead. * * @var array * @see get(), getPath() @@ -75,7 +75,7 @@ /** * Generated HTML menu. - * + * * @var string * @see get() */ @@ -84,23 +84,23 @@ /** * URL of the current page. * - * This can be the URL of the current page but it must not be exactly the + * This can be the URL of the current page but it must not be exactly the * return value of getCurrentURL(). If there's no entry for the return value * in the menu hash getPath() tries to find the menu item that fits best * by shortening the URL sign by sign until it finds an entry that fits. - * + * * @see getCurrentURL(), getPath() */ var $current_url = ''; /** * Initializes the menu, sets the type and menu structure. - * + * * @param array * @param string * @see setMenuType(), setMenu() */ - function HTML_Menu($menu = '', $type = 'tree', $url_env_var = 'PHP_SELF') { + function HTML_Menu($menu = '', $type = 'tree', $url_env_var = 'PHP_SELF') { if (is_array($menu)) $this->setMenu($menu); @@ -111,20 +111,20 @@ /** * Sets the menu structure. * - * The menu structure is defined by a multidimensional hash. This is - * quite "dirty" but simple and easy to traverse. An example + * The menu structure is defined by a multidimensional hash. This is + * quite "dirty" but simple and easy to traverse. An example * show the structure. To get the following menu: - * + * * 1 - Projects * 11 - Projects => PHPDoc * 12 - Projects => Forms * 2 - Stuff * * you need the array: - * - * $menu = array( - * 1 => array( - * 'title' => 'Projects', + * + * $menu = array( + * 1 => array( + * 'title' => 'Projects', * 'url' => '/projects/index.php', * 'sub' => array( * 11 => array( @@ -137,9 +137,9 @@ * 2 => array( 'title' => 'Stuff', 'url' => '/stuff/index.php' ) * ) * - * Note the index 'sub' and the nesting. Note also that 1, 11, 12, 2 - * must be unique. The class uses them as ID's. - * + * Note the index 'sub' and the nesting. Note also that 1, 11, 12, 2 + * must be unique. The class uses them as ID's. + * * @param array * @access public * @see append(), update() @@ -171,7 +171,7 @@ /** * Returns the HTML menu. - * + * * @param string Menu type: tree, urhere, rows, prevnext, sitemap * @return string HTML of the menu * @access public @@ -180,34 +180,34 @@ if ('' != $menu_type) $this->setMenuType($menu_type); - $this->html = ''; - + $this->html = ''; + // buildMenu for rows cares on this itself if ('rows' != $this->menu_type) $this->html .= $this->getStart(); - + // storing to a class variable saves some recursion overhead $this->path = $this->getPath(); - + if ('sitemap' == $this->menu_type) { - + $this->setMenuType('tree'); $this->buildSitemap($this->menu); $this->setMenuType('sitemap'); - + } else { $this->buildMenu($this->menu); - } + } if ('rows' != $this->menu_type) $this->html .= $this->getEnd(); - + return $this->html; } /** * Prints the HTML menu. - * + * * @brother get() * @return void */ @@ -217,7 +217,7 @@ /** * Returns the prefix of the HTML menu items. - * + * * @return string HTML menu prefix * @see getEnd(), get() */ @@ -228,7 +228,7 @@ case 'prevnext': $html .= '<table border><tr>'; break; - + case 'tree': case 'urhere': case 'sitemap': @@ -252,14 +252,14 @@ case 'prevnext': $html .= '</tr></table>'; break; - + case 'tree': case 'urhere': case 'sitemap': $html .= '</table>'; break; } - + return $html; } @@ -272,7 +272,7 @@ */ function buildMenu($menu, $level = 0, $flag_stop_level = -1) { static $last_node = array(), $up_node = array(); - + // the recursion goes slightly different for every menu type switch ($this->menu_type) { case 'tree': @@ -290,7 +290,7 @@ } $this->html .= $this->getEntry($node, $level, $type); - + // follow the subtree if the active menu item is in it if ($type && isset($node['sub'])) $this->buildMenu($node['sub'], $level + 1); @@ -300,7 +300,7 @@ case 'rows': // every (sub)menu has it's own table $this->html .= $this->getStart(); - + $submenu = false; // loop through the (sub)menu @@ -325,7 +325,7 @@ // close the table for this level $this->html .= $this->getEnd(); - + // go deeper if neccessary if ($submenu) $this->buildMenu($submenu, $level + 1); @@ -372,7 +372,7 @@ // menu item that fits to this url - 'active' menu item $type = 1; $flag_stop_level = $level; - + if (0 != count($last_node)) { $this->html .= $this->getEntry($last_node, $level, 3); } else { @@ -403,7 +403,7 @@ // follow the subtree if the active menu item is in it if ($type && isset($node['sub'])) { $up_node = $node; - $flag_stop_level = $this->buildMenu($node['sub'], $level + 1, (-1 != $flag_stop_level) ? $flag_stop_level + 1 : -1); + $flag_stop_level = $this->buildMenu($node['sub'], $level + 1, (-1 != $flag_stop_level) ? $flag_stop_level + 1 : -1); } } break; @@ -433,7 +433,7 @@ } $this->html .= $this->getEntry($node, $level, $type); - + // follow the subtree if the active menu item is in it if (isset($node['sub'])) $this->buildSitemap($node['sub'], $level + 1); @@ -442,11 +442,11 @@ /** * Returns the HTML of one menu item. - * + * * @param array menu item data (node data) * @param integer level in the menu tree * @param integer menu item type: 0, 1, 2. 0 => plain menu item, - * 1 => selected (active) menu item, 2 => item + * 1 => selected (active) menu item, 2 => item * is a member of the path to the selected (active) menu item * 3 => previous entry, 4 => next entry * @return string HTML @@ -459,7 +459,7 @@ // tree menu $html .= '<tr>'; $indent = ''; - if ($level) + if ($level) for ($i = 0; $i < $level; $i++) $indent .= '&nbsp;&nbsp;&nbsp;'; } @@ -477,7 +477,7 @@ case 1: // selected (active) menu item - $html .= sprintf('<td>%s<b>%s</b></td>', + $html .= sprintf('<td>%s<b>%s</b></td>', $indent, $node['title'] ); @@ -493,7 +493,7 @@ ); break; - case 3: + case 3: // << previous url $html .= sprintf('<td>%s<a href="%s">&lt;&lt; %s</a></td>', $indent, @@ -535,22 +535,22 @@ */ function getPath() { $this->current_url = $this->getCurrentURL(); - $this->buildPath($this->menu, array()); + $this->buildPath($this->menu, array()); while ($this->current_url && !isset($this->urlmap[$this->current_url])) $this->current_url = substr($this->current_url, 0, -1); - + return $this->urlmap[$this->current_url]; } /** * Computes the path of the current page in the menu 'tree'. - * + * * @param array first call: menu hash / recursion: submenu hash * @param array first call: array() / recursion: path - * @return boolean true if the path to the current page was found, + * @return boolean true if the path to the current page was found, * otherwise false. Only meaningful for the recursion. - * @global $PHP_SELF + * @global $PHP_SELF * @see getPath(), $urlmap */ function buildPath($menu, $path) { @@ -558,30 +558,30 @@ foreach ($menu as $node_id => $node) { // save the path of the current node in the urlmap $this->urlmap[$node['url']] = $path; - + // we got'em - stop the search by returning true // KLUDGE: getPath() works with the best alternative for a URL if there's // no entry for a URL in the menu hash, buildPath() does not perform this test // and might do some unneccessary recursive runs. if ($node['url'] == $this->current_url) return true; - - // current node has a submenu + + // current node has a submenu if (isset($node['sub'])) { - + // submenu path = current path + current node $subpath = $path; $subpath[] = $node_id; - - // continue search recursivly - return is the inner loop finds the + + // continue search recursivly - return is the inner loop finds the // node that belongs to the current url if ($this->buildPath($node['sub'], $subpath)) return true; } - } + } // not found - return false; + return false; } /**
« previous php.pear.cvs (#775) next »