The following is a tree menu similar to windows Resource Manager that contains the following script to your page. In addition, you need to take some GIF images from the resource manager, the format of the comment menu structure file in the script is treelevel | itemtext | itemlink | linktarget | lastiteminsubtree, for example. bDemomenub | javascript: below al is a tree menu style similar to windows Resource Manager
Include the following script to your page
In addition, you need to extract some GIF images from the resource manager. For more information, see the notes in the script.
The format of the menu structure file is:
Tree level | item text | item link | link target | last item in subtree
For example
.
Demo menu| Javascript: alert ('This is the demo menu for TreeMenu 100 ');
..
Directory 1
...
Sub-directory 1.1
... Item 1.1.1 | javascript: alert ('item 1.1.1 ');
... Item 1.1.2 | javascript: alert ('item 1.1.1 ');
... Item 1.2 | javascript: alert ('item 1.2 ');
... Item 1.3 | javascript: alert ('item 1.3 ');
..
Subdirectory 2
... Item 2.1 | javascript: alert ('item 2.1 ');
... Item 2.2 | javascript: alert ('item 2.2 ');
...
Sub-directory 2.3
... Item 2.3.1 | javascript: alert ('item 2.3.1 ');
... Item 2.3.2 | javascript: alert ('item 2.3.2 ');
// File: tremenu. inc
// PHP TreeMenu
/////////////////
// Initialization //
/////////////////
$ Treefile = "demomenu.txt"; // sets a file with a menu structure.
If (isset ($ PATH_INFO ))
$ Script = $ PATH_INFO;
Else
$ Script = $ SCRIPT_NAME;
// Take a screenshot of the corresponding position in windows resource manager.
$ Img_expand = "tree_expand.gif"; // scalable node in the resource manager +
$ Img_collapse = "tree_collapse.gif"; // extended node in the resource manager-
$ Img_line = "tree_vertline.gif"; // Image |
$ Img_split = "tree_split.gif"; // Image |-
$ Img_end = "tree_end.gif"; // L-shaped
$ Img_leaf = "tree_leaf.gif"; // o-shaped
$ Img_spc = "tree_space.gif"; // blank figure
// The following is the menu processing script.
$ Maxlevel = 0;
$ Cnt = 0;
$ Fd = fopen ($ treefile, "r ");
If ($ fd = 0) die ("treemenu. inc: Unable to open file". $ treefile );
While ($ buffer = fgets ($ fd, 4096 ))
{
$ Tree [$ cnt] [0] = strspns ($ buffer ,".");
$ Tmp = rtrim (substr ($ buffer, $ tree [$ cnt] [0]);
$ Node = explode ("|", $ tmp );
$ Tree [$ cnt] [1] = $ node [0];
$ Tree [$ cnt] [2] = $ node [1];
$ Tree [$ cnt] [3] = $ node [2];
$ Tree [$ cnt] [4] = 0;
If ($ tree [$ cnt] [0]> $ maxlevel) $ maxlevel = $ tree [$ cnt] [0];
$ Cnt ++;
}
Fclose ($ fd );
For ($ I = 0; $ I {
$ Expand [$ I] = 0;
$ Visible [$ I] = 0;
$ Levels [$ I] = 0;
}
If ($ p! = "")
$ Explevels = explode ("|", $ p );
$ I = 0;
While ($ I {
$ Expand [$ explevels [$ I] = 1;
$ I ++;
}
$ Lastlevel = $ maxlevel;
For ($ I = count ($ tree)-1; $ I> = 0; $ I --)
{
If ($ tree [$ I] [0] <$ lastlevel)
For ($ j = $ tree [$ I] [0] + 1; $ j <= $ maxlevel; $ j ++)
$ Levels [$ j] = 0;
If ($ levels [$ tree [$ I] [0] = 0)
{
$ Levels [$ tree [$ I] [0] = 1;
$ Tree [$ I] [4] = 1;
}
Else
$ Tree [$ I] [4] = 0;
$ Lastlevel = $ tree [$ I] [0];
}
For ($ I = 0; $ I <count ($ tree); $ I ++)
If ($ tree [$ I] [0] = 1)
$ Visible [$ I] = 1;
For ($ I = 0; $ I <count ($ explevels); $ I ++)
{
$ N = $ explevels [$ I];
If ($ visible [$ n] = 1) & ($ expand [$ n] = 1 ))
{
$ J = $ n + 1;
While ($ tree [$ j] [0]> $ tree [$ n] [0])
{
If ($ tree [$ j] [0] = $ tree [$ n] [0] + 1) $ visible [$ j] = 1;
$ J ++;
}
}
}
For ($ I = 0; $ I <$ maxlevel; $ I ++)
$ Levels [$ I] = 1;
$ Maxlevel ++;
Echo"
\ N ";Echo"
";For ($ I = 0; $ I <$ maxlevel; $ I ++)Echo"
| ";Echo"
|
\ N ";$ Cnt = 0;While ($ cnt{If ($ visible [$ cnt]){Echo"
";$ I = 0;While ($ I <$ tree [$ cnt] [0]-1){If ($ levels [$ I] = 1)Echo"
| ";ElseEcho"
| ";$ I ++;}If ($ tree [$ cnt] [4] = 1){Echo"
| ";$ Levels [$ tree [$ cnt] [0]-1] = 0;}Else{Echo"
| ";$ Levels [$ tree [$ cnt] [0]-1] = 1;}If ($ tree [$ cnt + 1] [0]> $ tree [$ cnt] [0]){$ I = 0; $ params = "? P = ";While ($ I{If ($ expand [$ I] = 1) & ($ cnt! = $ I) | ($ expand [$ I] = 0 & $ cnt = $ I )){$ Params = $ params. $ I;$ Params = $ params. "| ";}$ I ++;}If ($ expand [$ cnt] = 0)Echo"
| ";ElseEcho"
| ";}ElseEcho"
| ";If ($ tree [$ cnt] [2] = "")Echo"
". $ Tree [$ cnt] [1]." | ";ElseEcho"
". $ Tree [$ cnt] [1]." | ";Echo"
\ N ";}$ Cnt ++;}Echo"
\ N ";
?>
From: Programmers