Use PHP to implement a windows Resource Manager-style tree menu
Last Update:2017-01-13
Source: Internet
Author: User
The following 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
. <B> Demo menu </B> | javascript: alert ('This is the demo menu for TreeMenu 1.0 ');
.. <B> directory 1 </B>
... <B> sub-directory 1.1 </B>
... 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 ');
.. <B> subdirectory 2 </B>
... Item 2.1 | javascript: alert ('item 2.1 ');
... Item 2.2 | javascript: alert ('item 2.2 ');
... <B> sub-directory 2.3 </B>
... Item 2.3.1 | javascript: alert ('item 2.3.1 ');
... Item 2.3.2 | javascript: alert ('item 2.3.2 ');
<? Php
// 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;
// The following figure shows 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];