[Phplib-commit] CVS: php-lib/php/html menu.inc,1.2,1.3
Brought to you by:
nhruby,
richardarcher
From: Richard A. <ric...@us...> - 2001-08-20 06:38:13
|
Update of /cvsroot/phplib/php-lib/php/html In directory usw-pr-cvs1:/tmp/cvs-serv5619 Modified Files: menu.inc Log Message: Major overhaul of menu.inc: sync with -stable tree fix unset variable access warnings fix unquoted array subscript warnings add { and } around all one-line conditionals allow for new behaviour of dirname() in PHP4 normalise whitespace and comments change "pseudo" operation slightly and add documentation fix the example in the docs. Index: menu.inc =================================================================== RCS file: /cvsroot/phplib/php-lib/php/html/menu.inc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** menu.inc 2000/07/12 11:05:15 1.2 --- menu.inc 2001/08/20 06:38:10 1.3 *************** *** 36,41 **** var $title_delim = " : "; ! /***************************************************************************/ ! /* public: constructor */ function Menu() { --- 36,41 ---- var $title_delim = " : "; ! /*************************************************************************** ! * public: constructor */ function Menu() { *************** *** 43,53 **** } ! /* public: show current menu */ - function show() { print $this->get(); } function get() { global $PHP_SELF; --- 43,56 ---- } ! /* ! * public: show menu of items visible from the current page */ function show() { print $this->get(); } + /* + * public: build menu of items visible from the current page + */ function get() { global $PHP_SELF; *************** *** 72,79 **** $level = count(explode("/", $this->visible[$i])); ! if ($level > $oldlevel) $str .= $this->shift_in($oldlevel, $level); ! if ($level < $oldlevel) $str .= $this->shift_out($oldlevel, $level); $oldlevel = $level; --- 75,84 ---- $level = count(explode("/", $this->visible[$i])); ! if ($level > $oldlevel) { $str .= $this->shift_in($oldlevel, $level); ! } ! if ($level < $oldlevel) { $str .= $this->shift_out($oldlevel, $level); + } $oldlevel = $level; *************** *** 86,96 **** /* ! * public: show a sitemap */ - function show_sitemap() { print $this->get_sitemap(); } function get_sitemap() { $this->visible = array(); --- 91,103 ---- /* ! * public: show a menu of all items (sitemap) */ function show_sitemap() { print $this->get_sitemap(); } + /* + * public: build a menu of all items (sitemap) + */ function get_sitemap() { $this->visible = array(); *************** *** 113,120 **** $level = count(explode("/", $this->visible[$i])); ! if ($level > $oldlevel) $str .= $this->shift_in($oldlevel, $level); ! if ($level < $oldlevel) $str .= $this->shift_out($oldlevel, $level); $oldlevel = $level; --- 120,129 ---- $level = count(explode("/", $this->visible[$i])); ! if ($level > $oldlevel) { $str .= $this->shift_in($oldlevel, $level); ! } ! if ($level < $oldlevel) { $str .= $this->shift_out($oldlevel, $level); + } $oldlevel = $level; *************** *** 127,138 **** ! /* public: show a single menu cell */ function get_cell($n, $level, $class = "") { $bold = ($this->visible[$n] == $this->map); ! for ($i=1; $i<$level; $i++) $dent .= " "; ! if ($this->item[$this->visible[$n]]["pseudo"]) { $str=sprintf("%s%s<br>\n", $dent, --- 136,150 ---- ! /* ! * public: show a single menu cell */ function get_cell($n, $level, $class = "") { + $dent = ""; $bold = ($this->visible[$n] == $this->map); ! for ($i=1; $i<$level; $i++) { $dent .= " "; + } ! if (isset($this->item[$this->visible[$n]]["pseudo"])) { $str=sprintf("%s%s<br>\n", $dent, *************** *** 152,160 **** } ! /* public: build the title of the page based on ! its location in the menu hierarchy. */ function get_title() { global $PHP_SELF; ! unset($this->title); # Determine normalized current position in tree --- 164,174 ---- } ! /* ! * public: build the title of the current page based on its location ! * in the menu hierarchy. ! */ function get_title() { global $PHP_SELF; ! $this->title = ""; # Determine normalized current position in tree *************** *** 165,170 **** while(list($a, $b) = each($r)) { ! if ($this->title) $this->title .= $this->title_delim; $this->title .= $this->item[$b]["title"]; } --- 179,185 ---- while(list($a, $b) = each($r)) { ! if (isset($this->title) && $this->title != "") { $this->title .= $this->title_delim; + } $this->title .= $this->item[$b]["title"]; } *************** *** 173,176 **** --- 188,196 ---- } + /* + * public: These four functions can be used to customise layout. + * They are called when certain events happen during menu display. + * They should be overridden in your subclass. + */ function shift_in($oldlevel, $level) { ; } *************** *** 181,209 **** function end_menu() { ; } ! /***************************************************************************/ ! /* private: normalize current menu position */ function normalize_pos($pos) { ! if ( $m = $this->urlmap[basename($pos)] ) ! return($m); $m = $pos; ! while(substr($m, 0, 1)) { ! if ($this->urlmap[$m]) break; $m = dirname($m); } ! return $this->urlmap[$m]; } ! /* private: split a path /2/2 into components "", /2, /2/2 */ function split_path($p) { $path = ""; ! $r = explode("/", $p); reset($r); while(list($k, $v) = each($r)) { ! if ($v) $path .= "/$v"; $res[] = $path; } --- 201,236 ---- function end_menu() { ; } ! /* ! * private: normalize current menu position */ function normalize_pos($pos) { ! if ( isset($this->urlmap[basename($pos)]) ) { ! return $this->urlmap[basename($pos)]; ! } $m = $pos; ! while(strlen($m)) { ! if (isset($this->urlmap[$m])) { break; + } $m = dirname($m); + if ($m == "/") { + $m = ""; + } } ! return $this->urlmap[$m]; } ! /* ! * private: split a path /2/2 into components "", /2, /2/2 */ function split_path($p) { $path = ""; ! $r = explode("/", $p); reset($r); while(list($k, $v) = each($r)) { ! if ($v) { $path .= "/$v"; + } $res[] = $path; } *************** *** 212,234 **** } ! /* private: set up the visible array. */ function find_visible($r) { # at each level, add current children to visible ! $len = count($r); ! $this->visible= array(); ! for ($i=0; $i<$len; $i++) { # if current level has children, add them... ! if (is_array($this->children[$r[$i]]) ) { reset($this->children[$r[$i]]); while(list($k, $v) = each($this->children[$r[$i]])) { $this->visible[] = $v; ! if (isset($this->item[$v][pseudo]) && ! !ereg("^$v",$this->map)) ! while (list(,$w) = each($this->item[$v][pseudo])) { ! $this->visible[]=$w; } } } --- 239,283 ---- } ! /* ! * private: set up the visible array. */ function find_visible($r) { # at each level, add current children to visible ! $len = count($r); ! $this->visible = array(); for ($i=0; $i<$len; $i++) { # if current level has children, add them... ! if (isset($this->children[$r[$i]])) { reset($this->children[$r[$i]]); while(list($k, $v) = each($this->children[$r[$i]])) { $this->visible[] = $v; ! ! # The "pseudo" feature has not been documented in previous ! # releases. As such, it should not matter greatly that the ! # behaviour may have changed somewhat in this release. ! # Nevertheless, the changes and current behaviour are documented ! # here. ! # ! # Previously the array item $this->item[$v]["pseudo"] should have ! # contained an array of $this->item keys. The items referenced in ! # the "pseudo" array were made visible if the "pseudo" item was ! # visible. ! # ! # This has been changed somewhat. Now, if a "pseudo" array element ! # exists, the $this->children array is scanned and all children of ! # $this->item[$v] are made visible. The menu item $this->item[$v] ! # is displayed as text only, not as a hyperlink. The item acts as a ! # heading. ! ! # show children if this is a "pseudo" item ! if (isset($this->item[$v]["pseudo"]) && !ereg("^$v",$this->map)) { ! if (isset($this->children[$v]) && is_array($this->children[$v]) ) { ! reset($this->children[$v]); ! while (list($w, $ww) = each($this->children[$v])) { ! $this->visible[] = $ww; ! } } + } } } *************** *** 239,243 **** } ! /* private: find children of each menu item */ function setup() { --- 288,293 ---- } ! /* ! * private: find children of each menu item */ function setup() { *************** *** 245,248 **** --- 295,301 ---- while(list($k, $v) = each($this->urlmap)) { $base = dirname($v); + if ($base == "/") { + $base = ""; + } $this->children[$base][] = $v; $this->item[$v]["url"] = $k; |