Use PHP to implement a tree menu of windows Resource Manager style

Source: Internet
Author: User
The following is a tree menu similar to windows Resource Manager that includes the following script to your page. In addition, you need to take some GIF images from the resource manager, in the script, the structure of the comment menu structure file is: treelevel | itemtext, which is a tree menu similar to the 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 menu structure file format 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;

// A screenshot of the corresponding position in the windows Resource Manager

$ Img_expand = 'tree_expand.gif '; // you can expand a node in the resource manager.
$ Img_collapse = 'tree_collapse.gif '; // expanded nodes 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 '; // vacancy chart

// 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 ))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.