You are here

function book_tree_recurse in Drupal 5

Same name and namespace in other branches
  1. 4 modules/book.module \book_tree_recurse()

This is a helper function for book_tree()

1 call to book_tree_recurse()
book_tree in modules/book/book.module
Returns an HTML nested list (wrapped in a menu-class div) representing the book nodes as a tree.

File

modules/book/book.module, line 558
Allows users to collaboratively author a book.

Code

function book_tree_recurse($nid, $depth, $children, $unfold = array()) {
  $output = '';
  if ($depth > 0) {
    if (isset($children[$nid])) {
      foreach ($children[$nid] as $foo => $node) {
        if (in_array($node->nid, $unfold)) {
          if ($tree = book_tree_recurse($node->nid, $depth - 1, $children, $unfold)) {
            $output .= '<li class="expanded">';
            $output .= l($node->title, 'node/' . $node->nid);
            $output .= '<ul class="menu">' . $tree . '</ul>';
            $output .= '</li>';
          }
          else {
            $output .= '<li class="leaf">' . l($node->title, 'node/' . $node->nid) . '</li>';
          }
        }
        else {
          if ($tree = book_tree_recurse($node->nid, 1, $children)) {
            $output .= '<li class="collapsed">' . l($node->title, 'node/' . $node->nid) . '</li>';
          }
          else {
            $output .= '<li class="leaf">' . l($node->title, 'node/' . $node->nid) . '</li>';
          }
        }
      }
    }
  }
  return $output;
}