FuelPHP Bin
<?php // get the users authenticated state $authenticated = \Auth::check(); // process the linkset nodes, and generate an unordered list $generate = function($nodes, $depth) use (&$generate, $max_depth, $current_uri, $authenticated) { // start the list $output = '<ul id="mainSideMenu" class="nav nav-list nav-side">'.PHP_EOL; foreach ($nodes as $node) { // check permissions if ( ! empty($node->permission)) { if (($node->permission == '.authenticated' and ! $authenticated) or ($node->permission == '.public' and $authenticated) or ($node->permission == '.denied') or ( ! \Auth::has_access($node->permission))) { // no permission, skip this node continue; } } // link uri switch ($node->type) { case 'E': $uri = $node->path; break; case 'P': $uri = Uri::create(\Page::uri_by_page($node->page_id)); break; case 'U': $uri = Uri::create($node->path); break; default: $uri = '#'; } // status of this link $status = strpos($current_uri, $uri) === 0 ? 'active' : ''; // does this node have children? And are we allowed to display them? if ($node->children and $depth < $max_depth) { if ($depth == 1) { $uri = '#acc'.ucfirst(str_replace(' ','_', $node->name)); $output .= '<li class="accordion-group"> <div class="accordion-heading '.$status.'"> <a href="'.$uri.'" data-parent="#mainSideMenu" data-toggle="collapse" class="accordion-toggle"> <span class="item-icon fontello-icon-'.(empty($node->icon) ? 'menu': $node->icon).'"></span> <i class="chevron fontello-icon-right-open-3"></i>'.$node->title.' </a> </div> <ul class="accordion-content nav nav-list '.($status=='active'?'in ':'').'collapse" id="'.substr($uri, 1).'">'. $generate($node->children, $depth+1).' </ul> </li>'.PHP_EOL; } else { $output .= '<li class="'.$status.'"> <a href="'.$uri.'"> <i class="fontello-icon-'.(empty($node->icon) ? 'right-dir': $node->icon).'"></i> <span class="hidden-tablet">'.$node->title.'</span>'.' </a> <ul class="accordion-content nav nav-list '.($status=='active'?'in ':'').'collapse">'. $generate($node->children, $depth+1).' </ul> </li>'.PHP_EOL; } } else { if ($depth == 1) { $output .= '<li class="accordion-group"> <div class="accordion-heading '.$status.'"> <a href="'.$uri.'" data-parent="#mainSideMenu" class="accordion-toggle"> <span class="item-icon fontello-icon-'.(empty($node->icon) ? 'th-list-1': $node->icon).'"></span> '.$node->title.' </a> </div> </li>'.PHP_EOL; } else { $output .= '<li class="'.$status.'"> <a href="'.$uri.'"> <i class="fontello-icon-'.(empty($node->icon) ? 'right-dir': $node->icon).'"></i> <span class="hidden-tablet">'.$node->title.'</span>'.' </a> </li>'.PHP_EOL; } } } // close the list and return it $output .= '</ul>'.PHP_EOL; return $output; }; echo $generate($linkset->children, 1); ?>