// remove child items deeper than end level
if (($args['end']) && ($node->attributes('level') >= $args['end'])) {
$children = $node->children();
foreach ($node->children() as $child) {
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
if ($node->name() == 'ul') {
// remove inaccessable items according to user rights
foreach ($node->children() as $child) {
if ($child->attributes('access') > $user->get('aid', 0)) {
$node->removeChild($child);
}
}
// set order/first/last for li
$count = count($node->children());
foreach ($node->children() as $i => $child) {
if ($i == 0) $child->addAttribute('first', 1);
if ($i == $count - 1) $child->addAttribute('last', 1);
$child->addAttribute('order', $i + 1);
}