cvs: php4 /pear/Experimental/HTML Menu.php

From: Date: Mon, 12 Mar 2001 22:03:51 +0000
Subject: cvs: php4 /pear/Experimental/HTML Menu.php
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-4518@lists.php.net to get a copy of this message
uw Mon Mar 12 14:03:51 2001 EDT Modified files: /php4/pear/Experimental/HTML Menu.php Log: - removed a typo - added the Isomenu feature "use which fits best" for the search of the selected item Index: php4/pear/Experimental/HTML/Menu.php diff -u php4/pear/Experimental/HTML/Menu.php:1.3 php4/pear/Experimental/HTML/Menu.php:1.4 --- php4/pear/Experimental/HTML/Menu.php:1.3 Mon Mar 12 12:30:44 2001 +++ php4/pear/Experimental/HTML/Menu.php Mon Mar 12 14:03:51 2001 @@ -57,6 +57,19 @@ * @see get() */ var $html = ""; + + + /** + * URL of the current page. + * + * 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 find an entry that fits. + * + * @see getCurrentURL(), getPath() + */ + var $current_url = ""; /** @@ -123,7 +136,7 @@ /** * Sets the type / format of the menu: tree, rows or urhere. * - * @param string "tree", "rows", "urhere" + * @param string "tree", "rows", "urhere", "prevnext" * @access public */ function setMenuType($menu_type) { @@ -132,6 +145,7 @@ } // end func setMenuType + /** * Returns the HTML menu. * @@ -156,7 +170,7 @@ if ("rows" != $this->menu_typ) $this->html .= $this->getEnd(); - return $this->html . $this->getEnd(); + return $this->html; } // end func get @@ -252,8 +266,6 @@ function buildMenu($menu, $level = 0, $flag_stop_level = -1) { static $last_node = array(); - $current_url = $this->getCurrentURL(); - // the recursion goes slightly different for every menu type switch ($this->menu_type) { @@ -262,7 +274,7 @@ // loop through the (sub)menu foreach ($menu as $node_id => $node) { - if ($current_url == $node["url"]) { + if ($this->current_url == $node["url"]) { // menu item that fits to this url - "active" menu item $type = 1; } else if (isset($this->path[$level]) && $this->path[$level] == $node_id) { @@ -290,7 +302,7 @@ // loop through the (sub)menu foreach ($menu as $node_id => $node) { - if ($current_url == $node["url"]) { + if ($this->current_url == $node["url"]) { // menu item that fits to this url - "active" menu item $type = 1; } else if (isset($this->path[$level]) && $this->path[$level] == $node_id) { @@ -323,7 +335,7 @@ // loop through the (sub)menu foreach ($menu as $node_id => $node) { - if ($current_url == $node["url"]) { + if ($this->current_url == $node["url"]) { // menu item that fits to this url - "active" menu item $type = 1; } else if (isset($this->path[$level]) && $this->path[$level] == $node_id) { @@ -362,7 +374,7 @@ break; - } else if ($current_url == $node["url"]) { + } else if ($this->current_url == $node["url"]) { // menu item that fits to this url - "active" menu item $type = 1; @@ -416,12 +428,10 @@ */ function buildSitemap($menu, $level = 0) { - $current_url = $this->getCurrentURL(); - // loop through the (sub)menu foreach ($menu as $node_id => $node) { - if ($current_url == $node["url"]) { + if ($this->current_url == $node["url"]) { // menu item that fits to this url - "active" menu item $type = 1; } else if (isset($this->path[$level]) && $this->path[$level] == $node_id) { @@ -488,7 +498,7 @@ case 2: // part of the path to the selected (active) menu item - $html .= sprintf('<td>%s<a href="%s">%s</a>%s</td>', + $html .= sprintf('<td>%s<b><a href="%s">%s</a></b>%s</td>', $indent, $node["url"], $node["title"], @@ -522,7 +532,7 @@ return $html; } // end func getEnty - + /* * Returns the path of the current page in the menu "tree". * @@ -530,10 +540,14 @@ * @see buildPath(), $urlmap */ function getPath() { - + + $this->current_url = $this->getCurrentURL(); $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->currentURL()]; + return $this->urlmap[$this->current_url]; } // end func getPath @@ -549,8 +563,6 @@ */ function buildPath($menu, $path) { - $current_url = $this->getCurrentURL(); - // loop through the (sub)menu foreach ($menu as $node_id => $node) { @@ -558,7 +570,10 @@ $this->urlmap[$node["url"]] = $path; // we got'em - stop the search by returning true - if ($node["url"] == $current_url) + // 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

« previous php.cvs (#4518) next »