PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_Menu » Manual

With the HTML_Menu class one can easily create and maintain a navigation structure for websites, configuring it via a multidimensional hash structure. Different modes for the HTML output are supported.

Introduction

Introduction – Menu structure and supported output modes

Menu hash structure

The menu structure is defined by a multidimensional hash. This makes it quite easy to generate and traverse:

Menu multidimensional hash

<?php
array(
    1 => array(
        'title' => 'Menu item 1', 
        'url' => '/item1.php',
        'sub' => array(
            11 => array('title' => 'Menu item 1.1', 'url' => '/item1.1.php'),
            12 => array(
                'title' => 'Menu item 1.2', 
                'url' => '/item1.2.php',
                'sub' => array(
                    121 => array('title' => 'Menu item 1.2.1', 'url' => '/item1.2.1.php'),
                    122 => array('title' => 'Menu item 1.2.2', 'url' => '/item1.2.2.php')
                )
            )
        )
    ),
    2 => array(
        'title' => 'Menu item 2', 
        'url' => '/item2.php',
        'sub' => array(
            21 => array('title' => 'Menu item 2.1', 'url' => '/item2.1.php'),
            22 => array('title' => 'Menu item 2.2', 'url' => '/item2.2.php')
        )
    )
);
?>

Each entry should have at least 'url' and 'title' keys and may also have 'sub' key containing the children of this entry. Note that keys in the entry arrays serve as node identifiers and should be unique.

The menu entries can also contain custom keys. If such keys are present, then they will be used by renderers in creating the output (this usually means that the content of such a key will be assigned to the template placeholder with the same name).

Supported output modes

HTML_Menu supports five output modes: 'tree' (default), 'rows', 'urhere', 'prevnext' and 'sitemap'. Lets use the array defined above as menu structure assuming that element 'Menu item 1.2' is currently active and try each menu type.

'tree'

This type of the menu mostly follows the internal structure of the menu hash. Different levels of the menu are marked by indentation, only the elements leading to the active item or immediately following it are shown.

Output for menu type 'tree'

Menu item 1
    Menu item 1.1   
    Menu item 1.2
        Menu item 1.2.1
        Menu item 1.2.2
Menu item 2
      
'rows'

This is quite similar to 'tree' type, only different levels are not marked by indentation, but are shown on different rows of the menu.

Output for menu type 'rows'

Menu item 1  Menu item 2
Menu item 1.1  Menu item 1.2
Menu item 1.2.1  Menu item 1.2.2
      
'urhere'

This is so-called 'breadcrumb' navigation, allowing to easily understand your position within site hierarchy.

Output for menu type 'urhere'

Menu item 1 >> Menu item 1.2
      
'prevnext'

This is the menu often used in documentation (including the PEAR manual), the links lead to previous, next and parent entries of the current entry.

Output for menu type 'prevnext'

<< Menu item 1.1  ^ Menu item 1 ^  Menu item 1.2.1 >>
      
'sitemap'

This is 'tree' type menu, but with all entries shown.

Output for menu type 'sitemap'

Menu item 1
    Menu item 1.1
    Menu item 1.2
        Menu item 1.2.1
        Menu item 1.2.2
Menu item 2
    Menu item 2.1
    Menu item 2.2
      

Usage example

Very basic usage example

<?php
// Load the class
require_once 'HTML/Menu.php';

// Instantiate the menu object, we presume that $data contains menu structure
$menu =& new HTML_Menu($data, 'tree');

// Output the menu
$menu->show();
?>

constructor HTML_Menu::HTML_Menu()

constructor HTML_Menu::HTML_Menu() – Initializes the menu, sets the type and menu structure.

Synopsis

require_once 'HTML/Menu.php';

void constructor HTML_Menu::HTML_Menu ( array $menu = null , string $type = 'tree' , string $urlEnvVar = 'PHP_SELF' )

Description

Initializes the menu, sets the menu structure, type and variable to use for determining the current URL. All parameters are optional and can be set later by corresponding methods.

Parameter

array $menu

Menu structure

string $type

Menu type: 'tree', 'rows', 'urhere', 'prevnext', 'sitemap'

string $urlEnvVar

Environment variable to use for determining the current URL.

Throws

throws no exceptions thrown

See

see HTML_Menu::setMenuType(), HTML_Menu::setMenu(), HTML_Menu::setURLEnvVar().

Note

This function can not be called statically.

HTML_Menu::forceCurrentUrl()

HTML_Menu::forceCurrentUrl() – Forces the given URL to be "current"

Synopsis

require_once 'HTML/Menu.php';

void HTML_Menu::forceCurrentUrl ( string $url )

Description

Use this if you do not want to extract current URL from some environment variable (e.g. $_SERVER['PHP_SELF']) but rather use some custom logic to determine it.

Parameter

string $url

Url to use

Throws

throws no exceptions thrown

See

see HTML_Menu::setURLEnvVar(), HTML_Menu::getCurrentUrl()

Note

This function can not be called statically.

HTML_Menu::get()

HTML_Menu::get() – Returns the HTML menu.

Synopsis

require_once 'HTML/Menu.php';

string HTML_Menu::get ( string $menuType = '' )

Description

This method uses HTML_Menu_DirectRenderer for its work. The renderer is used with default templates, you should use the render() method if you want to customize the output.

Parameter

string $menuType

Menu type: 'tree', 'rows', 'urhere', 'prevnext', 'sitemap'

Return value

returns HTML of the menu

Throws

throws no exceptions thrown

See

see HTML_Menu::show(), HTML_Menu::render().

Note

This function can not be called statically.

HTML_Menu::getCurrentURL()

HTML_Menu::getCurrentURL() – Returns the URL of the currently selected page.

Synopsis

require_once 'HTML/Menu.php';

string HTML_Menu::getCurrentURL ( )

Description

The returned string is used for all test against the URL's in the menu structure hash.

Throws

throws no exceptions thrown

See

see HTML_Menu::setURLEnvVar(), HTML_Menu::forceCurrentUrl().

Note

This function can not be called statically.

HTML_Menu::getPath()

HTML_Menu::getPath() – Returns the path of the current page in the menu 'tree'.

Synopsis

require_once 'HTML/Menu.php';

array HTML_Menu::getPath ( )

Description

'Path' here means the sequence of entry IDs leading to the current menu entry.

Return value

returns path to the selected menu item

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTML_Menu::render()

HTML_Menu::render() – Renders the menu.

Synopsis

require_once 'HTML/Menu.php';

void HTML_Menu::render ( object HTML_Menu_Renderer &$renderer , string $menuType = '' )

Description

All logic to actually create the output is contained in the renderer. render() just calls the appropriate method to traverse the menu structure.

Parameter

object HTML_Menu_Renderer &$renderer

Renderer to use

string $menuType

type of the menu

Throws

throws PEAR_Error. If the renderer is not designed to handle this type of menu, it will throw an error.

Note

This function can not be called statically.

HTML_Menu::setMenu()

HTML_Menu::setMenu() – Sets the menu structure.

Synopsis

require_once 'HTML/Menu.php';

void HTML_Menu::setMenu ( array $menu )

Description

The menu structure is defined by a multidimensional hash.

Parameter

array $menu

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTML_Menu::setMenuType()

HTML_Menu::setMenuType() – Sets the type of the menu.

Synopsis

require_once 'HTML/Menu.php';

void HTML_Menu::setMenuType ( string $menuType )

Description

Available types are: 'tree', 'rows', 'urhere', 'prevnext', 'sitemap'.

Parameter

string $menuType

type name

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTML_Menu::setURLEnvVar()

HTML_Menu::setURLEnvVar() – Sets the environment variable to use to get the current URL.

Synopsis

require_once 'HTML/Menu.php';

void HTML_Menu::setURLEnvVar ( string $urlEnvVar )

Description

The default variable name is 'PHP_SELF', which means 'current script name'.

Parameter

string $urlEnvVar

environment variable for current URL

Throws

throws no exceptions thrown

See

see HTML_Menu::getCurrentURL(), HTML_Menu::forceCurrentURL().

Note

This function can not be called statically.

HTML_Menu::setURLPrefix()

HTML_Menu::setURLPrefix() – Sets the prefix for the URLs in the menu

Synopsis

require_once 'HTML/Menu.php';

void HTML_Menu::setURLPrefix ( string $prefix )

Description

This is useful if you have relative URLs in the menu description structure. This prefix will be appended to the URLs from this structure and the result will be compared to "current" URL.

Parameter

string $prefix

menu URL prefix

Throws

throws no exceptions thrown

See

see HTML_Menu::getCurrentURL(), HTML_Menu::forceCurrentURL(), HTML_Menu::setMenu().

Note

This function can not be called statically.

HTML_Menu::show()

HTML_Menu::show() – Prints the HTML menu.

Synopsis

require_once 'HTML/Menu.php';

void HTML_Menu::show ( string $menuType = '' )

Description

This method uses HTML_Menu_DirectRenderer for its work. The renderer is used with default templates, you should use the render() method if you want to customize the output.

Parameter

string $menuType

Menu type: 'tree', 'rows', 'urhere', 'prevnext', 'sitemap'

Throws

throws no exceptions thrown

See

see HTML_Menu::get(), HTML_Menu::render().

Note

This function can not be called statically.

Class Summary HTML_Menu_Renderer

Class Summary HTML_Menu_Renderer – An abstract base class for HTML_Menu renderers (package developer related)

Description

This class defines methods that should be implemented by child classes to provide necessary output logic. You only need to read its description if you intend to write your own renderer.

Class Trees for HTML_Menu_Renderer

Classes that extend HTML_Menu_Renderer
Class Summary
HTML_Menu_ArrayRenderer The renderer that creates an array of visible menu entries.
HTML_Menu_DirectRenderer The renderer that generates HTML for the menu all by itself.
HTML_Menu_DirectTreeRenderer The "direct" renderer for 'tree' and 'sitemap' menu types where level is represented by tags nesting.
HTML_Menu_SigmaRenderer The renderer that uses HTML_Template_Sigma instance for menu output.
HTML_Menu_SigmaTreeRenderer HTML_Template_Sigma-based renderer for 'tree' and 'sitemap' type menus, where menu level is represented by tag nesting.

HTML_Menu_Renderer::finishLevel()

HTML_Menu_Renderer::finishLevel() – Finish the tree level (for types 'tree' and 'sitemap') (package developer related)

Synopsis

require_once 'HTML/Menu/Renderer.php';

void HTML_Menu_Renderer::finishLevel ( int $level )

Description

This package is not documented yet.

Parameter

integer $level

current depth in the tree structure

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTML_Menu_Renderer::finishMenu()

HTML_Menu_Renderer::finishMenu() – Finish the menu (package developer related)

Synopsis

require_once 'HTML/Menu/Renderer.php';

void HTML_Menu_Renderer::finishMenu ( int $level )

Description

This package is not documented yet.

Parameter

integer $level

current depth in the tree structure

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTML_Menu_Renderer::finishRow()

HTML_Menu_Renderer::finishRow() – Finish the row in the menu (package developer related)

Synopsis

require_once 'HTML/Menu/Renderer.php';

void HTML_Menu_Renderer::finishRow ( int $level )

Description

This package is not documented yet.

Parameter

integer $level

current depth in the tree structure

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTML_Menu_Renderer::renderEntry()

HTML_Menu_Renderer::renderEntry() – Renders the element of the menu (package developer related)

Synopsis

require_once 'HTML/Menu/Renderer.php';

void HTML_Menu_Renderer::renderEntry ( array $node , int $level , int $type )

Description

This package is not documented yet.

Parameter

array $node

Element being rendered

integer $level

Current depth in the tree structure

integer $type

Type of the element (one of HTML_MENU_ENTRY_* constants)

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTML_Menu_Renderer::setMenuType()

HTML_Menu_Renderer::setMenuType() – Sets the type of the menu being rendered

Synopsis

require_once 'HTML/Menu/Renderer.php';

void HTML_Menu_Renderer::setMenuType ( string $menuType )

Description

This package is not documented yet.

Parameter

string $menuType

menu type

Throws

throws no exceptions thrown

Note

This function can not be called statically.

Class Summary HTML_Menu_DirectRenderer

Class Summary HTML_Menu_DirectRenderer – The renderer that generates HTML for the menu all by itself.

Description

This renderer directly generates the menu HTML, thus the name. It is loosely based on HTML_Menu 1.0 code, but while it was needed to subclass HTML_Menu to customize its output, HTML_Menu_DirectRenderer has built-in methods for changing menu appearance.

Class Trees for HTML_Menu_DirectRenderer

HTML_Menu_DirectRenderer Inherited Methods

Inherited from HTML_Menu_Renderer
Method Name Summary
HTML_Menu_Renderer::finishLevel() Finish the tree level (for types 'tree' and 'sitemap')
HTML_Menu_Renderer::finishMenu() Finish the menu
HTML_Menu_Renderer::finishRow() Finish the row in the menu
HTML_Menu_Renderer::renderEntry() Renders the element of the menu
HTML_Menu_Renderer::setMenuType() Sets the type of the menu being rendered.

DirectRenderer::setEntryTemplate()

DirectRenderer::setEntryTemplate() – Sets the template for menu entry.

Synopsis

require_once 'HTML/Menu/DirectRenderer.php';

void HTML_Menu_DirectRenderer::setEntryTemplate ( mixed $type , string $template = null )

Description

The template should contain at least the {title} placeholder, can also contain {url} and {indent} placeholders, depending on entry type. Default templates are:

<?php
array(
    HTML_MENU_ENTRY_INACTIVE    => '<td>{indent}<a href="{url}">{title}</a></td>',
    HTML_MENU_ENTRY_ACTIVE      => '<td>{indent}<b>{title}</b></td>',
    HTML_MENU_ENTRY_ACTIVEPATH  => '<td>{indent}<b><a href="{url}">{title}</a></b></td>',
    HTML_MENU_ENTRY_PREVIOUS    => '<td><a href="{url}">&lt;&lt; {title}</a></td>',
    HTML_MENU_ENTRY_NEXT        => '<td><a href="{url}">{title} &gt;&gt;</a></td>',
    HTML_MENU_ENTRY_UPPER       => '<td><a href="{url}">^ {title} ^</a></td>',
    HTML_MENU_ENTRY_BREADCRUMB  => '<td><a href="{url}">{title}</a> &gt;&gt; </td>'
);
?>

Parameter

mixed $type

either type (one of HTML_MENU_ENTRY_* constants) or an array 'type' => 'template'

string $template

template for this entry type if $type is not an array

Throws

throws no exceptions thrown

Note

This function can not be called statically.

DirectRenderer::setMenuTemplate()

DirectRenderer::setMenuTemplate() – Sets the menu template (HTML that wraps around rows)

Synopsis

require_once 'HTML/Menu/DirectRenderer.php';

void HTML_Menu_DirectRenderer::setMenuTemplate ( string $prepend , string $append )

Description

These are the strings that will be prepended and appended to HTML generated for menu rows on each call to finishMenu(). Defaults are


'<table border="1">'

and


'</table>'

Parameter

string $prepend

this will be prepended to the rows HTML

string $append

this will be appended to the rows HTML

Throws

throws no exceptions thrown

Note

This function can not be called statically.

DirectRenderer::setRowTemplate()

DirectRenderer::setRowTemplate() – Sets the row template (HTML that wraps around entries)

Synopsis

require_once 'HTML/Menu/DirectRenderer.php';

void HTML_Menu_DirectRenderer::setRowTemplate ( string $prepend , string $append )

Description

These are the strings that will be prepended and appended to HTML generated for menu entries on each call to finishRow(). Defaults are


'<tr>'

and


'</tr>'

Parameter

string $prepend

this will be prepended to the entries HTML

string $append

this will be appended to the entries HTML

Throws

throws no exceptions thrown

Note

This function can not be called statically.

DirectRenderer::toHtml()

DirectRenderer::toHtml() – returns the HTML generated for the menu

Synopsis

require_once 'HTML/Menu/DirectRenderer.php';

string HTML_Menu_DirectRenderer::toHtml ( )

Description

This package is not documented yet.

Throws

throws no exceptions thrown

Note

This function can not be called statically.

Class Summary HTML_Menu_DirectTreeRenderer

Class Summary HTML_Menu_DirectTreeRenderer – The "direct" renderer for 'tree' and 'sitemap' menu types where level is represented by tags nesting.

Description

The renderer is designed to output only the menus of type 'tree' and 'sitemap'. It shows the level of the menu by tags nesting, not by outputting some indentation and is able to output e.g. nested HTML lists:

<ul>
    <li>Menu item 1
        <ul>
            <li>Menu item 1.1</li>
            <li>Menu item 1.2</li>
        </ul>
    </li>  
    <li>Menu item 2</li>
</ul>

Idea and initial code contributed by Uwe Mindrup.

Class Trees for HTML_Menu_DirectTreeRenderer

HTML_Menu_DirectTreeRenderer Inherited Methods

Inherited from HTML_Menu_Renderer
Method Name Summary
HTML_Menu_Renderer::finishLevel() Finish the tree level (for types 'tree' and 'sitemap')
HTML_Menu_Renderer::finishMenu() Finish the menu
HTML_Menu_Renderer::finishRow() Finish the row in the menu
HTML_Menu_Renderer::renderEntry() Renders the element of the menu
HTML_Menu_Renderer::setMenuType() Sets the type of the menu being rendered.

DirectTreeRenderer::setEntryTemplate()

DirectTreeRenderer::setEntryTemplate() – Sets the template for menu entry.

Synopsis

require_once 'HTML/Menu/DirectTreeRenderer.php';

void HTML_Menu_DirectTreeRenderer::setEntryTemplate ( mixed $type , string $template = null )

Description

The template should contain at least the {title} placeholder, can also contain {url} placeholder. Default templates are:

<?php
array(
    HTML_MENU_ENTRY_INACTIVE    => '<a href="{url}">{title}</a>',
    HTML_MENU_ENTRY_ACTIVE      => '<strong>{title}</strong>',
    HTML_MENU_ENTRY_ACTIVEPATH  => '<a href="{url}"><em>{title}</em></a>'
);
?>

If custom keys are present in the original menu structure, they will be assigned to the corresponding placeholders.

Parameter

mixed $type

either type (one of HTML_MENU_ENTRY_* constants) or an array 'type' => 'template'

string $template

template for this entry type if $type is not an array

Throws

throws no exceptions thrown

Note

This function can not be called statically.

DirectTreeRenderer::setItemTemplate()

DirectTreeRenderer::setItemTemplate() – Sets the item template (HTML that wraps around entries)

Synopsis

require_once 'HTML/Menu/DirectTreeRenderer.php';

void HTML_Menu_DirectTreeRenderer::setRowTemplate ( string $prepend , string $append )

Description

These are the strings that will be prepended and appended to HTML generated for menu entries. Defaults are


'<li>'

and


'</li>'

Parameter

string $prepend

this will be prepended to the entries HTML

string $append

this will be appended to the entries HTML

Throws

throws no exceptions thrown

Note

This function can not be called statically.

DirectTreeRenderer::setLevelTemplate()

DirectTreeRenderer::setLevelTemplate() – Sets the level template (HTML that wraps around the submenu)

Synopsis

require_once 'HTML/Menu/DirectTreeRenderer.php';

void HTML_Menu_DirectTreeRenderer::setLevelTemplate ( string $prepend , string $append )

Description

These are the strings that will be prepended and appended to HTML generated for menu level. Defaults are


'<ul>'

and


'</ul>'

Parameter

string $prepend

this will be prepended to the rows HTML

string $append

this will be appended to the rows HTML

Throws

throws no exceptions thrown

Note

This function can not be called statically.

DirectTreeRenderer::toHtml()

DirectTreeRenderer::toHtml() – returns the HTML generated for the menu

Synopsis

require_once 'HTML/Menu/DirectTreeRenderer.php';

string HTML_Menu_DirectTreeRenderer::toHtml ( )

Description

This package is not documented yet.

Throws

throws no exceptions thrown

Note

This function can not be called statically.

Class Summary HTML_Menu_ArrayRenderer

Class Summary HTML_Menu_ArrayRenderer – The renderer that creates an array of visible menu entries.

Output array

The resultant array can be used with e.g. a template engine to produce a completely custom menu look.

All menu types except 'rows' are "rendered" into a one-dimensional array of entries:

<?php
array(
    'entry1',
    ...
    'entryN'
)
?>

while 'rows' produce a two-dimensional array:

<?php
array(
    array('entry 1 for row 1', ..., 'entry M_1 for row 1'),
    ...
    array('entry 1 for row N', ..., 'entry M_N for row 1')
 )
?>

Here entry is

<?php
array(
    'url'    => url element of menu entry
    'title'  => title element of menu entry
    'level'  => entry's depth in the tree structure
    'type'   => type of entry, one of HTML_MENU_ENTRY_* constants
 )
?>

A list of the above mentioned HTML_MENU_ENTRY_* constants can be found here.

Class Trees for HTML_Menu_ArrayRenderer

HTML_Menu_ArrayRenderer Inherited Methods

Inherited from HTML_Menu_Renderer
Method Name Summary
HTML_Menu_Renderer::finishLevel() Finish the tree level (for types 'tree' and 'sitemap')
HTML_Menu_Renderer::finishMenu() Finish the menu
HTML_Menu_Renderer::finishRow() Finish the row in the menu
HTML_Menu_Renderer::renderEntry() Renders the element of the menu
HTML_Menu_Renderer::setMenuType() Sets the type of the menu being rendered.

ArrayRenderer::toArray()

ArrayRenderer::toArray() – returns the resultant array

Synopsis

require_once 'HTML/Menu/ArrayRenderer.php';

array HTML_Menu_ArrayRenderer::toArray ( )

Description

This package is not documented yet.

Throws

throws no exceptions thrown

Note

This function can not be called statically.

Class Summary HTML_Menu_SigmaRenderer

Class Summary HTML_Menu_SigmaRenderer – The renderer that uses HTML_Template_Sigma instance for menu output.

Description

This renderer uses HTML_Template_Sigma for actual HTML generation. This will allow you to easily plug HTML_Menu into your site's structure if you are using this template engine.

The renderer offers more possibilites for output customization than HTML_Menu_DirectRenderer.

The renderer may also work with HTML_Template_IT instance, but as menu templates tend to have lots of blocks, HTML_Template_Sigma's cache feature will give a significant performance improvement.

Template structure

This minimal template will allow output of any available menu type:

<!-- BEGIN mu_menu_loop -->
<table cellpadding="2" cellspacing="0" border="1">
    <!-- BEGIN mu_row_loop -->
    <tr>
        <!-- BEGIN mu_entry_loop -->
        <!-- BEGIN mu_inactive -->
        <td><!-- BEGIN mu_inactive_indent -->&nbsp;&nbsp;<!-- END mu_inactive_indent --><a href="{mu_url}">{mu_title}</a></td>
        <!-- END mu_inactive -->
        <!-- BEGIN mu_active -->
        <td><!-- BEGIN mu_active_indent -->&nbsp;&nbsp;<!-- END mu_active_indent --><strong>{mu_title}</strong></td>
        <!-- END mu_active -->
        <!-- BEGIN mu_activepath -->
        <td><!-- BEGIN mu_activepath_indent -->&nbsp;&nbsp;<!-- END mu_activepath_indent --><a href="{mu_url}"><strong>{mu_title}</strong></a></td>
        <!-- END mu_activepath -->
        <!-- BEGIN mu_previous -->
        <td><a href="{mu_url}">&lt;&lt;&lt; {mu_title}</a></td>
        <!-- END mu_previous -->
        <!-- BEGIN mu_next -->
        <td><a href="{mu_url}">{mu_title} &gt;&gt;&gt;</a></td>
        <!-- END mu_next -->
        <!-- BEGIN mu_upper -->
        <td><a href="{mu_url}">^ {mu_title} ^</a></td>
        <!-- END mu_upper -->
        <!-- BEGIN mu_breadcrumb -->
        <td><a href="{mu_url}">{mu_title}</a> &gt;&gt;&gt;</td>
        <!-- END mu_breadcrumb -->
        <!-- END mu_entry_loop -->
    </tr>
    <!-- END mu_row_loop -->
</table>
<!-- END mu_menu_loop -->

A more complete example showing possible customizations can be found in the package archive.

Note that blocks and placeholders in the template have mu_ prefix. This is done to prevent name conflicts with existing blocks and placeholders, mu_ is the default prefix, another prefix can be passed to class constructor.

menu_loop

If present, this block will be parse()'d after outputting the current menu or (in case of 'rows' type) current menu level. If menu type is 'rows' and %level%_menu_loop block is present, it will be parse()'d instead.

row_loop

If present, this block will be parse()'d after outputting the current menu row. If menu type is 'rows' and %level%_row_loop block is present, it will be parse()'d instead.

entry_loop

This block should always be present and should be a parent for all menu entries' blocks. It is used to implement "flow", to render entries one after another.

If menu type is 'rows' and %level%_entry_loop block is present, it will be used instead.

inactive, active, activepath, previous, next, upper, breadcrumb

These blocks are used to output menu entries, they correspond to possible entry types. Each block should contain a {title} placeholder and may also contain {url} placeholder and indent block

If menu type is either of 'tree', 'sitemap' or 'rows' and %level%_%entry type% block exists, it will be used instead.

inactive_indent, active_indent, activepath_indent

If present, these blocks are used to indent the entries inside tree-type menus ('tree' and 'sitemap').

Class Trees for HTML_Menu_SigmaRenderer

HTML_Menu_SigmaRenderer Inherited Methods

Inherited from HTML_Menu_Renderer
Method Name Summary
HTML_Menu_Renderer::finishLevel() Finish the tree level (for types 'tree' and 'sitemap')
HTML_Menu_Renderer::finishMenu() Finish the menu
HTML_Menu_Renderer::finishRow() Finish the row in the menu
HTML_Menu_Renderer::renderEntry() Renders the element of the menu
HTML_Menu_Renderer::setMenuType() Sets the type of the menu being rendered.

constructor HTML_Menu_SigmaRenderer()

constructor HTML_Menu_SigmaRenderer() – Class constructor.

Synopsis

require_once 'HTML/Menu/SigmaRenderer.php';

void constructor HTML_Menu_SigmaRenderer::HTML_Menu_SigmaRenderer ( object HTML_Template_Sigma &$tpl , string $prefix = 'mu_' )

Description

Sets the template object to use and sets prefix for template blocks and placeholders. We use prefix to avoid name collisions with existing template blocks and it is customisable to allow output of several menus into one template.

Parameter

object HTML_Template_Sigma &$tpl

template object to use for output

string $prefix

prefix for template blocks and placeholders

Throws

throws no exceptions thrown

Note

This function can not be called statically.

Class Summary HTML_Menu_SigmaTreeRenderer

Class Summary HTML_Menu_SigmaTreeRenderer – HTML_Template_Sigma-based renderer for 'tree' and 'sitemap' type menus, where menu level is represented by tag nesting.

Description

The renderer generates outpu similar to that of HTML_Menu_DirectTreeRenderer but offers more possibilites for output customization.

The renderer may also work with HTML_Template_IT instance, but as menu templates tend to have lots of blocks, HTML_Template_Sigma's cache feature will give a significant performance improvement.

Template structure

This is the minimal template for HTML_Menu_SigmaTreeRenderer, containing all the required blocks:

<!-- BEGIN mu_tree_loop -->
    <!-- BEGIN mu_level_open -->
<ul>
    <!-- END mu_level_open -->
        <!-- BEGIN mu_entry_open -->
    <li>
        <!-- END mu_entry_open -->
        <!-- BEGIN mu_active -->
    <strong>{mu_title}</strong>
        <!-- END mu_active -->
        <!-- BEGIN mu_inactive -->
    <a href="{mu_url}">{mu_title}</a>
        <!-- END mu_inactive -->
        <!-- BEGIN mu_activepath -->
    <a href="{mu_url}"><em>{mu_title}</em></a>
        <!-- END mu_activepath -->
        <!-- BEGIN mu_entry_close -->
    </li>
        <!-- END mu_entry_close -->
    <!-- BEGIN mu_level_close -->
</ul>
    <!-- END mu_level_close -->
<!-- END mu_tree_loop -->

A more complete example showing possible customizations can be found in the package archive.

Note that blocks and placeholders in the template have mu_ prefix. This is done to prevent name conflicts with existing blocks and placeholders, mu_ is the default prefix, another prefix can be passed to class constructor.

tree_loop

This block should always be present and should be a parent for all other blocks. It is used to implement "flow", to render entries one after another.

level_open, level_close

These blocks will be used on start and end of each menu level. If level-specific blocks %level%_level_open and %level%_level_close are present, they will be used instead.

entry_open, entry_close

These blocks will be used on start and end of each menu entry. If level-specific blocks %level%_entry_open and %level%_entry_close are present, they will be used instead.

inactive, active, activepath

These blocks are used to output menu entries, they correspond to possible entry types. Each block should contain a {title} placeholder and may also contain {url} placeholder. As usual, if other keys are present in original menu array they will be assigned to corresponding placeholders in the template.

If level-specific block %level%_%entry type% exists, it will be used instead.

Class Trees for HTML_Menu_SigmaTreeRenderer

HTML_Menu_SigmaTreeRenderer Inherited Methods

Inherited from HTML_Menu_Renderer
Method Name Summary
HTML_Menu_Renderer::finishLevel() Finish the tree level (for types 'tree' and 'sitemap')
HTML_Menu_Renderer::finishMenu() Finish the menu
HTML_Menu_Renderer::finishRow() Finish the row in the menu
HTML_Menu_Renderer::renderEntry() Renders the element of the menu
HTML_Menu_Renderer::setMenuType() Sets the type of the menu being rendered.

constructor HTML_Menu_SigmaTreeRenderer()

constructor HTML_Menu_SigmaTreeRenderer() – Class constructor.

Synopsis

require_once 'HTML/Menu/SigmaTreeRenderer.php';

void constructor HTML_Menu_SigmaTreeRenderer::HTML_Menu_SigmaTreeRenderer ( object HTML_Template_Sigma &$tpl , string $prefix = 'mu_' )

Description

Sets the template object to use and sets prefix for template blocks and placeholders. We use prefix to avoid name collisions with existing template blocks and it is customisable to allow output of several menus into one template.

Parameter

object HTML_Template_Sigma &$tpl

template object to use for output

string $prefix

prefix for template blocks and placeholders

Throws

throws no exceptions thrown

Note

This function can not be called statically.

Class Summary HTML_MenuBrowser

Class Summary HTML_MenuBrowser – Simple filesystem browser that can be used to generated menu (3) hashes based on the directory structure.

Simple filesystem browser that can be used to generated menu (3) hashes based on the directory structure.

Together with menu (3) and the (userland) cache you can use this browser to generate simple fusebox like applications / content systems.

Let the menubrowser scan your document root and generate a menu (3) structure hash which maps the directory structure, pass it to menu's setMethod() and optionally wrap the cache around all this to save script runs. If you do so, it looks like this:

// document root directory define('DOC_ROOT', '/home/server/www.example.com/');

// instantiate the menubrowser $browser = new menubrowser(DOC_ROOT);

// instantiate menu (3) $menu = new menu($browser->getMenu());

// output the sitemap $menu->show('sitemap');

Now, use e.g. simple XML files to store your content and additional menu informations (title!). Subclass exploreFile() depending on your file format.

Class Trees for HTML_MenuBrowser

constructor HTML_MenuBrowser::HTML_MenuBrowser()

constructor HTML_MenuBrowser::HTML_MenuBrowser() – Creates the object and optionally sets the directory to scan.

Synopsis

require_once 'HTML/MenuBrowser.php';

void constructor HTML_MenuBrowser::HTML_MenuBrowser ( string $dir = '' , string $index = '' , string $file_suffix = '' )

Description

This package is not documented yet.

Parameter

string $dir

Directory to scan

string $index

Filename of index pages

string $file_suffix

Suffix for files containing the additional data

Throws

throws no exceptions thrown

See

see HTML_MenuBrowser::$dir

Note

This function can not be called statically.

HTML_MenuBrowser::addFileInfo()

HTML_MenuBrowser::addFileInfo() – Adds further informations to the menu hash gathered from the files in it

Synopsis

require_once 'HTML/MenuBrowser.php';

array HTML_MenuBrowser::addFileInfo ( mixed $menu )

Description

This package is not documented yet.

Parameter

mixed $menu

Return value

returns Modified menu hash with the new informations

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTML_MenuBrowser::browse()

HTML_MenuBrowser::browse() – Recursive function that does the scan and builds the menu (3) hash.

Synopsis

require_once 'HTML/MenuBrowser.php';

array HTML_MenuBrowser::browse ( string $dir , integer $id = 0 , boolean $noindex = false )

Description

This package is not documented yet.

Parameter

string $dir

directory to scan

integer $id

entry id - used only for recursion

boolean $noindex

??? - used only for recursion

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTML_MenuBrowser::exploreFile()

HTML_MenuBrowser::exploreFile() – Returns additional menu informations decoded in the file that appears in the menu.

Synopsis

require_once 'HTML/MenuBrowser.php';

void HTML_MenuBrowser::exploreFile ( string $file )

Description

You should subclass this method to make it work with your own file formats. I used a simple XML format to store the content.

Parameter

string $file

filename

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTML_MenuBrowser::getMenu()

HTML_MenuBrowser::getMenu() – Returns a hash to be used with menu(3)'s setMenu().

Synopsis

require_once 'HTML/MenuBrowser.php';

void HTML_MenuBrowser::getMenu ( string $dir = '' , string $prefix = '' )

Description

This package is not documented yet.

Parameter

string $dir

directory to scan

string $prefix

id prefix

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTML_MenuBrowser::setDirectory()

HTML_MenuBrowser::setDirectory() – Sets the directory to scan.

Synopsis

require_once 'HTML/MenuBrowser.php';

void HTML_MenuBrowser::setDirectory ( string $dir )

Description

This package is not documented yet.

Parameter

string $dir

directory to scan

Throws

throws no exceptions thrown

Note

This function can not be called statically.

HTML_MenuBrowser::setIDPrefix()

HTML_MenuBrowser::setIDPrefix() – Sets the prefix for every id in the menu hash.

Synopsis

require_once 'HTML/MenuBrowser.php';

void HTML_MenuBrowser::setIDPrefix ( string $prefix )

Description

This package is not documented yet.

Parameter

string $prefix

Throws

throws no exceptions thrown

Note

This function can not be called statically.

Package HTML_Menu Constants

Package HTML_Menu Constants – Constants defined in and used by HTML_Menu

All Constants

Constants defined in Menu.php

Name Value Line Number Meaning
HTML_MENU_ENTRY_ACTIVE 1 26 Active menu entry, the one having the current URL as 'url' attribute
HTML_MENU_ENTRY_ACTIVEPATH 2 27 Ancestor of the active menu entry
HTML_MENU_ENTRY_BREADCRUMB 6 31 Ancestor of the active menu entry, for menu type 'urhere'
HTML_MENU_ENTRY_INACTIVE 0 25 Default menu entry
HTML_MENU_ENTRY_NEXT 4 29 "Next" menu entry (for menu type 'prevnext')
HTML_MENU_ENTRY_PREVIOUS 3 28 "Previous" menu entry (for menu type 'prevnext')
HTML_MENU_ENTRY_UPPER 5 30 "Up" menu entry (for menu type 'prevnext')