3. What is Treemenu

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:

$tree = new TreeMenu("a", "blocks/treemenu/sitemap.txt");


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:
$tree = new TreeMenu("a", "blocks/treemenu/sitemap.txt");
$output = ob_get_contents();
$content = $output;

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.

3.1. Input file method

The structure of the input file (sitemap.txt in the example) is simple:

The text file used for the Treemenu shown in Figure 2-Figure 5 is the following:

..<b>My work</b>
....Web Radio...|http://www.karakas-online.de/phpnuke/block-Web_Radio.tar|_top|;
....Linux Tips...|http://www.karakas-online.de/myLinuxTips/book1.html|_top|;
...Comp. Graphics|http://www.karakas-online.de/myWork/computer_graphics.html|_top|;
..<b>My hobbies</b>
..<b>My online services</b>
...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|;
...User Friendly|http://www.karakas-online.de/myServices/userfriendly.php|_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

Figure 6. Fully expanded Treemenu

 Fully expanded Treemenu

Fully expanded Treemenu

3.2. Alternative method

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:

  include "treemenu.inc";
  $tree = new treemenu("a");
  $tree->addNode(1, "grandpa"); 
  $tree->addNode(2, "pa"); 
  $tree->addNode(3, "son"); 
  $tree->addNode(2, "uncle"); 

the result will be as in Figure 7

Figure 7. Treemenu - alternative method

Treemenu - alternative method

Treemenu - alternative method