⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 05-menu.sgml

📁 PHPLOB注释详细版 使用模板技术的好帮手 PHP最有用的东东了
💻 SGML
字号:
<!-- $Id: 05-menu.sgml,v 1.2 1999/12/12 16:29:52 padraic Exp $ --><sect1>Menu<p>Menu will generate a hierarchical menu of clickable itemssuitable as a navigation bar. Menu takes a tree definition ofitems as the basis for this navigation bar and knows whichsubtrees to fold, depending on the current position in the menutree. Menu uses the current URL as presented in<tt/PHP&lowbar;SELF/ to determine the current position in themenu tree automatically.Menu does not depend on a hierarchical organisation of files inURL-space to generate a menu hierarchy. The organisation of menuitems and the organisation of files in URL-space are in factcompletely independent and Menu uses a mapping hash to derive amenu position from an URL. In the following class documentationwe'll say URL when we mean files the latter and menustring whenwe mean the former. In the context of the Menu class, URLs arealways relative URLs starting at the root of the local serversURL space, as we'll see them in PHP&lowbar;SELF. They may looklike <tt>/menu/index.php3</tt>. A menustring is usually numericand all components have the same length, if necessary withleading zeroes. It may look like <tt>/001/007</tt>, denoting anitem in main menu 1, submenu 7.<sect2>Instance variables<p><table><tabular ca="">$urlmap<colsep>Hash. Maps a relative URL as seenin PHP&lowbar;SELF to a menustring.<rowsep>$map<colsep>Menustring. Current position in menu.<rowsep>$item<colsep>Hash of Hashes. The <tt/item/ hash is indexed bymenustring. For each menustring, an arbitrary number of itemattributes is stored. Menu does not use the <tt/item/ array,only <tt/Menu::get&lowbar;cell()/ does, which you implement. Eachmenu item will automatically get an attribute <tt/url/ through<tt/urlmap/ inversion from the class constructor and the name ofthe menu item should be stored as the <tt/title/ attribute. Youmay add other attributes such as <tt/textcolor/ and <tt/bgcolor/and use them in your <tt/Menu::get&lowbar;cell()/implementation.<rowsep>$nomain<colsep>Boolean. If set, the first menu item will neverbe shown. This menu item is always the menu root, adding anextra level of indentation.<rowsep>$title<colsep>String. After calling <tt/get&lowbar;title()/, this variable contains the title of the page based on it's location in the menu hierarchy.<rowsep>$title&lowbar;delim<colsep>String. Used to delimit (i.e., separate) components in the page title built by <tt/get&lowbar;title()/. Default is <tt>" : "</tt><rowsep></tabular><caption>Accessible instance variables.</caption></table><table><tabular ca="">$children<colsep>Hash of arrays. The <tt/children/ is indexed bymenustring. For each menustring, an array of childrenmenustrings is stored. This array is generated from <tt/urlmap/in the class constructor and is used to determine which submenusare visible from the current <tt/map/ position.<rowsep>$visible<colsep>Array of menustrings. The <tt/visible/ arraycontains the menustrings visible from the current <tt/map/position. It is calculated by the <tt/Menu::get()/ and<tt/Menu::show()/ functions.<rowsep></tabular><caption>Internal instance variables.</caption></table><sect2>Instance methods<p><sect3>Accessible instance methods<p><descrip><tag>Menu()</tag><p>Constructor. Calls <tt/Menu::setup()/ internally.<tag>show()</tag><p>A shorthand notation for <tt/print $this->get()/.<tag>get()</tag><p>This function will calculate the menu items visible from thecurrent <tt/map/ position. The menu will be constructed bycalling <tt/Menu::start&lowbar;menu()/ first. For each visiblemenu item, Menu will check the current indentation level and theindentation level of the current menu cell. If the indentationlevel increases, <tt/Menu::shift&lowbar;in($oldlevel, $level)/ is called once, if it decreases,<tt/Menu:shift&lowbar;out($oldlevel, $level)/ is called once.After that, <tt/Menu::get&lowbar;cell($number, $level)/ iscalled once. The number is an index into the <tt/visible/ array.After all menu cells have been drawn,<tt/Menu::end&lowbar;menu()/ will be called once.<tag>get&lowbar;cell($n, $level)</tag><p>You are expected to implement this function yourself. It shouldrender a single menu item. You may use the <tt/visible/ and<tt/item/ arrays for that purpose: <tt/$m = $this->visible[$n]/will return a menu string and <tt/$attr = $this->item[$m]/ is ahash of attributes for that menu string. <tt/$hilite =($this->visible[$n] == $this->map)/ is true for the currentmenu item, which should be rendered in way to stand out from therest of the menu items.<tag>get&lowbar;title()</tag><p>This function will calculate the title of the current page basedon the position of the current page in the menu hierarchy. Thisfunction uses <tt/$this->title&lowbar;delim/ to separate the componentsof the title. This function sets <tt/$this>title/ to the calculatedtitle and returns the title as a string.<tag>setup()</tag> <p> This function initializes the internal arrays of Menu and shouldbe called once from the constructor. It actually is theconstructor, but language stupidity has it that PHP3 constructornames vary with class names, which means that you have to writea new constructor for each subclass and call this functionmanually.</descrip><sect3>Internal instance methods<p><descrip><tag>normalize&lowbar;pos($pos)</tag><p>This function looks at the current URL in <tt/$PHP&lowbar;SELF/and tried to translate this into a menustring. If the URLmatches a menustring directly, this is easy.If not, the current URL will be sequentially shortened byapplying the <tt/dirname/ PHP function to it until it matches.This allows you to create a single menu item for all files in adirectory.<tag>split&lowbar;path($p)</tag><p>This function is used in the construction of the set of visiblemenu items. Given a menustring or a pathname, it constructsa series of pathnames which converge elementwise against thegiven pathname. That is, given the menustring <tt>/3/2</tt>,this function will return an array with the elements <tt>""</tt>(the empty string), <tt>/3</tt> and <tt>/3/2</tt>.<tag>find&lowbar;visible($r)</tag><p>This function calculates the actual set of visible URLs given aseries of converging pathnames. It will include the set ofchildren of each of these pathnames in the visible set, thensort this set numerically.</descrip><sect2>Example<p>To use <tt/Menu/, you must enable the require statement for<tt/menu.inc/ in <tt/prepend.php3/. To use<tt/Menu&lowbar;Button/, you must enable the require statementfor <tt/menu.inc/ and <tt/menu_button.inc/ in <tt/prepend.php3/.Use a subclass of either <tt/Menu/ or <tt/Menu&lowbar;Button/ tocreate a menu. Define a class <tt/Example&lowbar;Menu/ in your<tt/local.inc/ file with a number of menu items in it. Do notforget to build a constructor.<tscreen><code>class Example_Menu extends Menu {  # Map of PHP_SELF URL strings to menu positions  var $urlmap = array(    "/menu/index.php3"   =&gt; "",    "/menu/item1.php3"   =&gt; "/1",    "/menu/item11.php3"  =&gt; "/1/1",    "/menu/item12.php3"  =&gt; "/1/2",    "/menu/item13.php3"  =&gt; "/1/3",    "/menu/item2.php3"   =&gt; "/2",    "/menu/item21.php3"  =&gt; "/2/1",    "/menu/item22.php3"  =&gt; "/2/2",    "/menu/item221.php3" =&gt; "/2/2/1",    "/menu/item222.php3" =&gt; "/2/2/2",    "/menu/item23.php3"  =&gt; "/2/3",    "/menu/item24.php3"  =&gt; "/2/4"  );  # Information about each menu item  var $item = array(    ""      =&gt; array("title" =&gt; "Main"),    "/1"    =&gt; array("title" =&gt; "Text 1"),    "/1/1"  =&gt; array("title" =&gt; "Text 1.1"),    "/1/2"  =&gt; array("title" =&gt; "Text 1.2"),    "/1/3"  =&gt; array("title" =&gt; "Text 1.3"),    "/2"    =&gt; array("title" =&gt; "Text 2"),    "/2/1"  =&gt; array("title" =&gt; "Text 2.1"),    "/2/2"  =&gt; array("title" =&gt; "Text 2.2"),    "/2/2/1"=&gt; array("title" =&gt; "Text 2.2.1"),    "/2/2/2"=&gt; array("title" =&gt; "Text 2.2.2"),    "/2/3"  =&gt; array("title" =&gt; "Text 2.3"),    "/2/4"  =&gt; array("title" =&gt; "Text 2.4")  );  function Example_Menu() {    $this-&gt;setup();  }}</code></tscreen>In each of your files mentioned in the above <tt/urlmap/, createan instance of <tt/Example&lowbar;Menu/ and call the <tt/show()/method of that instance.<tscreen><code>&lt;?php  $m = new Example_Menu; ?&gt;&lt;html&gt;&lt;head&gt; &lt;title&gt;&lt;?php $m-&gt;get&lowbar;menu() ?&gt;&lt;/title&gt;&lt;/head&gt;&lt;body bgcolor="#ffffff"&gt;&lt;table border=1 bgcolor="#eeeeee" cellspacing=0 cellpadding=4&gt;  &lt;tr&gt;   &lt;td colspan=2 valign=top align=center&gt;    &lt;h1&gt;&lt;?php print $m-&gt;title ?&gt;&lt;/h1&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td align=left valign=top&gt;&lt;?php $m-&gt;show() ?&gt;&lt;/td&gt;   &lt;td align=left valign=top&gt;Content&lt;/td&gt;  &lt;/tr&gt; &lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</code></tscreen>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -