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.
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).
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.
When the user clicks on an item like "Links", the subtree under this item is unfolded (Figure 17-4).
A further click on the subcategory "My work" will reveal another level of groups (Figure 17-5).
Finally, a click on a subsubcategory like "Linux" will unfold the "leaves" of the Treemenu (Figure 17-6).
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).
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 |
|
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.