The method described here makes use of a Treemenu in a PHPNuke Block. Treemenu is a PHP class created by Bjorge Dijkstra (original script to be found here) and adapted by Denny Shimkoski (his version to be found here). I have fixed some bugs in the latter one and incorporated it in a PHPNuke Block.
There are two ways you can use the Treemenu class - I use the one that takes as input a simple text file and creates a tree menu, in a style that most users are familiar with from a graphical file manager (see Figure 2). Navigation through such a tree is done intuitively by expanding and collapsing the various tree levels by clicking on the node icons (the icons are discussed in ).
To create a Treemenu, once you have written the input text file with your favorite text editor (see Section 3.1), or used the alternative method (see Section 3.2) to fill the nodes and leaves of the tree, you just have to write this 3-liner to get it up and running:
include("blocks/treemenu/treemenu.inc");
$tree = new TreeMenu("a", "blocks/treemenu/sitemap.txt");
$tree->show(); |
![]() | Note | |
|---|---|---|
In order to be able to display the output of the above code in a PHPNuke Block, we have to capture it in an output buffer with the ob_start(), ob_get_contents() and ob_end_clean() mechanism:
|
The file treemenu.inc contains the class definition, the file sitemap.txt the text description of the tree and the show() method echoes a dynamically created table that contains the tree.
The structure of the input file (sitemap.txt in the example) is simple:
Each node of the tree is described by a line of the file.
Each line consists of 4 parts separated by a “|”. It ends with a “;”. The four parts are:
Level of this node. This is denoted by one or more points “.”. One point “.” means 1st (top) level, two point “..” denote 2nd level (one level below top level), three points “...” mean 3rd level etc.
Textual description of the link (like the text in an anchor link). HTML code like <b>, <i> etc. is also allowed.
Address of the link (like the address in the href=”...” part of an anchor link).
Name of the window where the linked page has to appear (like the target name in the target=”...” part of an anchor link). It may take any values that the target attribute of an anchor may take (_top, _self, _new etc., or any self-defined name). This is optional, so it may be left empty.
The text file used for the Treemenu shown in Figure 2-Figure 5 is the following:
.Start|http://www.karakas-online.de|_top|; .<b>Links</b> ..<b>My work</b> ...Overview|http://www.karakas-online.de/myWork/t1.html|_top|; ...SAP|http://www.karakas-online.de/myWork/sap.html|_top|; ....Projects...|http://www.karakas-online.de/myProfile/book1.html|_top|; ...Linux|http://www.karakas-online.de/myWork/linux.html|_top|; ....AMANDA...|http://www.karakas-online.de/myAMANDA/t1.html|_top|; ....PHPNuke...|http://www.karakas-online.de/EN-Book/book1.html|_top|; ....UserFriendly...|http://www.karakas-online.de/phpnuke/block-User_Friendly.tar|_top|; ....Meteosat...|http://www.karakas-online.de/phpnuke/block-Meteosat.tar|_top|; ....Web Radio...|http://www.karakas-online.de/phpnuke/block-Web_Radio.tar|_top|; ....Linux Tips...|http://www.karakas-online.de/myLinuxTips/book1.html|_top|; ...Mathematics|http://www.karakas-online.de/myWork/mathematics.html|_top|; ...Comp. Graphics|http://www.karakas-online.de/myWork/computer_graphics.html|_top|; ..<b>My hobbies</b> ...Overview|http://www.karakas-online.de/myHobbies/t1.html|_top|; ..<b>My online services</b> ...Overview|http://www.karakas-online.de/myServices/index.html|_top|; ...Postcard service|http://www.karakas-online.de/cards/card.html|_top|; ...Hot links|http://www.karakas-online.de/link-o-matik.html|_blank|; ...HTML Validator|http://www.karakas-online.de/myServices/validator.html|_top|; ...Mortgage Calculator|http://www.karakas-online.de/myServices/mortgage_calculator.php|_top|; ...Web Radio|http://www.karakas-online.de/myServices/webradio.php|_top|; ...Meteosat|http://www.karakas-online.de/myServices/meteosat.php|_top|; ...User Friendly|http://www.karakas-online.de/myServices/userfriendly.php|_top|; .<b>Forum</b>|http://www.karakas-online.de/cgi3/index.html|_top|; .<b>Guestbook</b>|http://www.karakas-online.de/cgi1/index.html|_top|; .<b>My wishlist</b>|http://www.amazon.de/exec/obidos/wishlist/7IEDDLYYBJ3X/ref=wl_em_to|_top|; .<i><b>Email me</b></i>|mailto:chris@karakas-online.de?subject=Homepage%20Comments |
The fully expanded Treemenu for the above file is shown in Figure 6
The second method to fill the tree with nodes and leaves does not make use of an input file but uses the AddNode function to insert each element directly in the program code. So if you write:
<?php
include "treemenu.inc";
$tree = new treemenu("a");
$tree->addNode(1, "grandpa");
$tree->addNode(2, "pa");
$tree->addNode(3, "son");
$tree->addNode(2, "uncle");
$tree->show();
?> |
the result will be as in Figure 7