LD SoftwareBespoke Software, Web Design, Security Consultants and Host Services.

Menu

Sentinel
You have been warned!
We have caught 5883 shameful hackers.

NukeSentinel(tm)

Paypal Referral
Sign up for PayPal and start accepting credit card payments instantly.

Link Exchange
Join our free link exchange

Click Here
 
Treemenu block

17.2.2. Treemenu block

A commonly asked question in PHPNuke forums (see for example Menu Hack Needed (show different menu or block depending on the category)), is if there exists some Module block out there that displays a dynamic view of the available modules. The webmaster needs a functionality that will allow for the display of only certain module links, depending on, say, the interests, access level, or preferences of the viewer.

A typical Module block, as shipped with the standard PHPNuke package, looks as in Figure 17-2.

Figure 17-2. The standard Modules block.

The standard Modules block.



What we need instead is a module block that displays some links (to modules, or generally, to pages) when a certain condition is met (say, when Category A was previously chosen) and some other ones when a different condition is true (e.g. when Category B was chosen).

17.2.2.1. The general idea

To met the above requirements, the Treemenu block for PHP-Nuke adapts the well-known Treemenu concept to a PHPNuke Block and creates a PHPNuke block containing a Treemenu which looks as in Figure 17-3.

Figure 17-3. Treemenu Block.

Treemenu Block.



When the user clicks on an item like "Links", the subtree under this item is unfolded (Figure 17-4).

Figure 17-4. Treemenu Block with "Links" expanded.

Treemenu Block with "Links" expanded.



A further click on the subcategory "My work" will reveal another level of groups (Figure 17-5).

Figure 17-5. Treemenu Block with "My work" expanded.

Treemenu Block with "My work" expanded.



Finally, a click on a subsubcategory like "Linux" will unfold the "leaves" of the Treemenu (Figure 17-6).

Figure 17-6. Treemenu Block with "Linux" expanded.

Treemenu Block with "Linux" expanded.



Of course, the naming and nesting of categories and/or items is fully arbitrary. The above functionality can easily be adapted to suit more advanced needs too (see refinements of the PHP-Nuke Treemenu).

17.2.2.2. What is Treemenu

The Treemenu block makes use of a Treemenu in a PHPNuke Block. Treemenu is a PHP class created by Bjorge Dijkstra (original script to be found Treemenu Class from Bjorge) and adapted by Denny Shimkoski (his version to be found in Treemenu from Denny). Chris have fixed some bugs in the latter one and integrated it into a Treemenu block for PHP-Nuke.

There are two ways you can use the Treemenu class - Chris uses 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 17-3). 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 custom node icons for the PHP-Nuke Treemenu).

To create a Treemenu, once you have written the input text file with your favorite text editor (see input file method for the Treemenu) or used the alternative method to fill the nodes and leaves of the Treemenu, 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 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:

ob_start();
include("blocks/treemenu/treemenu.inc");
$tree = new TreeMenu("a", "blocks/treemenu/sitemap.txt");
$tree->show();
$output = ob_get_contents();
ob_end_clean();
$content = $output;


See Treemenu block for PHP-Nuke for more information of how to use the Treemenu block as a module block for PHP-Nuke.


Help us make a better PHP-Nuke HOWTO!

Want to contribute to this HOWTO? Have a suggestion or a solution to a problem that was not treated here? Post your comments on my PHP-Nuke Forum!

Chris Karakas, Maintainer PHP-Nuke HOWTO

 
You can syndicate our News with backend.php And our Forums with rss.php
You can also access our feeds via Feedburner Site News and LD Software Forums
© 2009 ld-software.co.uk All Rights Reserved.
PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.47 Seconds