/**
 *  recursive iterate and create map thought multidimensional menu array
 *
 * @param 	array $array;  Pass multidimensional array for menu;  name and/or url
 * @return  array of processed elements via  wrapElement()
 *
 */
function drawMenu($array, $level = 0)
{
    $menu = "";
    foreach ($array as $key => $value) {
        $addClass = '';
        // check the level to decide the main items for class 'ismain'
        if ($level == 0) {
            $addClass = ' ismain';
        }
        !empty($value['url']) ? $url = $value['url'] : ($url = NULL);
        // inside the loop items that has no subs
        if (!isset($value['subpages'])) {
            $class = 'inside';
            $menu .= wrapElement(array('element' => 'li', 'class' => $class . $addClass, 'content' => $value['name'], 'url' => $url));
        } else {
            // outside the loop items that do has subs
            $class = 'outside';
            $menu .= wrapElement(array('element' => 'li', 'class' => $class . $addClass, 'content' => $value['name'], 'url' => $value['url'], 'openTag' => TRUE));
            $menuItemContent = drawMenu($value['subpages'], $level + 1);
            $menu .= wrapElement(array('element' => 'ul', 'content' => $menuItemContent));
            $menu .= wrapElement('li');
        }
    }
    return $menu;
}
Ejemplo n.º 2
0
<?php 
require_once 'function.php';
require_once 'resource.php';
// @@ wrap the menu element with Ul and class 'nagivate'
if (!empty($aMenu)) {
    print $aMenu = wrapElement(array('element' => 'ul', 'class' => 'navigate', 'content' => drawMenu($aMenu)));
}