cvs: php4 /pear/HTML Menu.php

From: Date: Wed, 08 Aug 2001 10:44:28 +0000
Subject: cvs: php4 /pear/HTML Menu.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-438@lists.php.net to get a copy of this message
sebastian Wed Aug 8 06:44:28 2001 EDT Modified files: /php4/pear/HTML Menu.php Log: Some fixes.

Index: php4/pear/HTML/Menu.php diff -u php4/pear/HTML/Menu.php:1.2 php4/pear/HTML/Menu.php:1.3 --- php4/pear/HTML/Menu.php:1.2 Wed Mar 28 08:08:11 2001 +++ php4/pear/HTML/Menu.php Wed Aug 8 06:44:28 2001 @@ -16,7 +16,7 @@ // | Authors: Ulf Wendel <ulf.wendel@phpdoc.de | // +----------------------------------------------------------------------+ // -// $Id: Menu.php,v 1.2 2001/03/28 13:08:11 uw Exp $ +// $Id: Menu.php,v 1.3 2001/08/08 10:44:28 sebastian Exp $ // /** @@ -24,14 +24,13 @@ * * Special thanks to the original author: Alex Vorobiev <sasha@mathforum.com>. * -* @version $Id: Menu.php,v 1.2 2001/03/28 13:08:11 uw Exp $ +* @version $Id: Menu.php,v 1.3 2001/08/08 10:44:28 sebastian Exp $ * @author Ulf Wendel <ulf.wendel@phpdoc.de> * @access public * @package HTML */ -class menu { - +class menu { /** * Menu structure as a multidimensional hash. * @@ -56,7 +55,7 @@ * @var array * @see setMenuType() */ - var $menu_type = "tree"; + var $menu_type = 'tree'; /** @@ -76,7 +75,7 @@ * @var string * @see get() */ - var $html = ""; + var $html = ''; /** @@ -89,7 +88,7 @@ * * @see getCurrentURL(), getPath() */ - var $current_url = ""; + var $current_url = ''; /** @@ -99,7 +98,7 @@ * @param string * @see setMenuType(), setMenu() */ - function menu($menu = "", $type = "tree") { + function menu($menu = '', $type = 'tree') { if (is_array($menu)) $this->setMenu($menu); @@ -125,20 +124,20 @@ * * $menu = array( * 1 => array( - * "title" => "Projects", - * "url" => "/projects/index.php", - * "sub" => array( + * 'title' => 'Projects', + * 'url' => '/projects/index.php', + * 'sub' => array( * 11 => array( - * "title" => "PHPDoc", + * 'title' => 'PHPDoc', * ... * ), * 12 => array( ... ), * ) * ), - * 2 => array( "title" => "Stuff", "url" => "/stuff/index.php" ) + * 2 => array( 'title' => 'Stuff', 'url' => '/stuff/index.php' ) * ) * - * Note the index "sub" and the nesting. Note also that 1, 11, 12, 2 + * 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 @@ -173,30 +172,30 @@ * @return string HTML of the menu * @access public */ - function get($menu_type = "") { - if ("" != $menu_type) + function get($menu_type = '') { + if ('' != $menu_type) $this->setMenuType($menu_type); - $this->html = ""; + $this->html = ''; // buildMenu for rows cares on this itself - if ("rows" != $this->menu_type) + 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) { + if ('sitemap' == $this->menu_type) { - $this->setMenuType("tree"); + $this->setMenuType('tree'); $this->buildSitemap($this->menu); - $this->setMenuType("sitemap"); + $this->setMenuType('sitemap'); } else { $this->buildMenu($this->menu); } - if ("rows" != $this->menu_type) + if ('rows' != $this->menu_type) $this->html .= $this->getEnd(); return $this->html; @@ -209,7 +208,7 @@ * @brother get() * @return void */ - function show($menu_type = "") { + function show($menu_type = '') { print $this->get($menu_type); } // end func show @@ -222,16 +221,16 @@ */ function getStart() { - $html = ""; + $html = ''; switch ($this->menu_type) { - case "rows": - case "prevnext": + case 'rows': + case 'prevnext': $html .= '<table border><tr>'; break; - case "tree": - case "urhere": - case "sitemap": + case 'tree': + case 'urhere': + case 'sitemap': $html .= '<table border>'; break; } @@ -248,16 +247,16 @@ */ function getEnd() { - $html = ""; + $html = ''; switch ($this->menu_type) { - case "rows": - case "prevnext": + case 'rows': + case 'prevnext': $html .= '</tr></table>'; break; - case "tree": - case "urhere": - case "sitemap": + case 'tree': + case 'urhere': + case 'sitemap': $html .= '</table>'; break; } @@ -279,13 +278,13 @@ // the recursion goes slightly different for every menu type switch ($this->menu_type) { - case "tree": + case 'tree': // loop through the (sub)menu foreach ($menu as $node_id => $node) { - if ($this->current_url == $node["url"]) { - // menu item that fits to this url - "active" menu item + 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) { // processed menu item is part of the path to the active menu item @@ -298,12 +297,12 @@ $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); + if ($type && isset($node['sub'])) + $this->buildMenu($node['sub'], $level + 1); } break; - case "rows": + case 'rows': // every (sub)menu has it's own table $this->html .= $this->getStart(); @@ -313,8 +312,8 @@ // loop through the (sub)menu foreach ($menu as $node_id => $node) { - if ($this->current_url == $node["url"]) { - // menu item that fits to this url - "active" menu item + 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) { // processed menu item is part of the path to the active menu item @@ -327,8 +326,8 @@ $this->html .= $this->getEntry($node, $level, $type); // remember the subtree - if ($type && isset($node["sub"])) - $submenu = $node["sub"]; + if ($type && isset($node['sub'])) + $submenu = $node['sub']; } @@ -341,13 +340,13 @@ break; - case "urhere": + case 'urhere': // loop through the (sub)menu foreach ($menu as $node_id => $node) { - if ($this->current_url == $node["url"]) { - // menu item that fits to this url - "active" menu item + 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) { // processed menu item is part of the path to the active menu item @@ -360,8 +359,8 @@ // follow the subtree if the active menu item is in it if ($type) { $this->html .= $this->getEntry($node, $level, $type); - if (isset($node["sub"])) { - $this->buildMenu($node["sub"], $level + 1); + if (isset($node['sub'])) { + $this->buildMenu($node['sub'], $level + 1); continue; } } @@ -369,7 +368,7 @@ } break; - case "prevnext": + case 'prevnext': // loop through the (sub)menu foreach ($menu as $node_id => $node) { @@ -385,8 +384,8 @@ break; - } else if ($this->current_url == $node["url"]) { - // menu item that fits to this url - "active" menu item + } else if ($this->current_url == $node['url']) { + // menu item that fits to this url - 'active' menu item $type = 1; $flag_stop_level = $level; @@ -431,9 +430,9 @@ $last_node = $node; // follow the subtree if the active menu item is in it - if ($type && isset($node["sub"])) { + 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; @@ -456,8 +455,8 @@ // loop through the (sub)menu foreach ($menu as $node_id => $node) { - if ($this->current_url == $node["url"]) { - // menu item that fits to this url - "active" menu item + 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) { // processed menu item is part of the path to the active menu item @@ -470,8 +469,8 @@ $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); + if (isset($node['sub'])) + $this->buildSitemap($node['sub'], $level + 1); } } // end func buildSitemap @@ -491,12 +490,12 @@ */ function getEntry(&$node, $level, $item_type) { - $html = ""; + $html = ''; - if ("tree" == $this->menu_type) { + if ('tree' == $this->menu_type) { // tree menu $html .= '<tr>'; - $indent = ""; + $indent = ''; if ($level) for ($i = 0; $i < $level; $i++) $indent .= '&nbsp;&nbsp;&nbsp;'; @@ -508,8 +507,8 @@ // plain menu item $html .= sprintf('<td>%s<a href="%s">%s</a></td>', $indent, - $node["url"], - $node["title"] + $node['url'], + $node['title'] ); break; @@ -517,7 +516,7 @@ // selected (active) menu item $html .= sprintf('<td>%s<b>%s</b></td>', $indent, - $node["title"] + $node['title'] ); break; @@ -525,9 +524,9 @@ // part of the path to the selected (active) menu item $html .= sprintf('<td>%s<b><a href="%s">%s</a></b>%s</td>', $indent, - $node["url"], - $node["title"], - ("urhere" == $this->menu_type) ? " &gt;&gt; " : "" + $node['url'], + $node['title'], + ('urhere' == $this->menu_type) ? ' &gt;&gt; ' : '' ); break; @@ -535,8 +534,8 @@ // << previous url $html .= sprintf('<td>%s<a href="%s">&lt;&lt; %s</a></td>', $indent, - $node["url"], - $node["title"] + $node['url'], + $node['title'] ); break; @@ -544,8 +543,8 @@ // next url >> $html .= sprintf('<td>%s<a href="%s">%s &gt;&gt;</a></td>', $indent, - $node["url"], - $node["title"] + $node['url'], + $node['title'] ); break; @@ -553,14 +552,14 @@ // up url ^^ $html .= sprintf('<td>%s<a href="%s">^ %s ^</a></td>', $indent, - $node["url"], - $node["title"] + $node['url'], + $node['title'] ); break; } - if ("tree" == $this->menu_type) + if ('tree' == $this->menu_type) $html .= '</tr>'; return $html; @@ -568,7 +567,7 @@ /* - * Returns the path of the current page in the menu "tree". + * Returns the path of the current page in the menu 'tree'. * * @return array path to the selected menu item * @see buildPath(), $urlmap @@ -586,7 +585,7 @@ /** - * Computes the path of the current page in the menu "tree". + * 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 @@ -601,17 +600,17 @@ foreach ($menu as $node_id => $node) { // save the path of the current node in the urlmap - $this->urlmap[$node["url"]] = $path; + $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) + if ($node['url'] == $this->current_url) return true; // current node has a submenu - if ($node["sub"]) { + if (isset($node['sub'])) { // submenu path = current path + current node $subpath = $path; @@ -619,7 +618,7 @@ // continue search recursivly - return is the inner loop finds the // node that belongs to the current url - if ($this->buildPath($node["sub"], $subpath)) + if ($this->buildPath($node['sub'], $subpath)) return true; } @@ -639,7 +638,7 @@ * @return string */ function getCurrentURL() { - return $GLOBALS["PHP_SELF"]; + return $GLOBALS['PHP_SELF']; } // end func getCurrentURL } // end class menu
« previous php.pear.cvs (#438) next »