You are here

function book_recurse in Drupal 4

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

Traverses the book tree. Applies the $visit_pre() callback to each node, is called recursively for each child of the node (in weight, title order). Finally appends the output of the $visit_post() callback to the output before returning the generated output.

Parameters

nid:

  • the node id (nid) of the root node of the book hierarchy.

depth:

  • the depth of the given node in the book hierarchy.

visit_pre:

  • a function callback to be called upon visiting a node in the tree

visit_post:

  • a function callback to be called after visiting a node in the tree, but before recursively visiting children.

Return value

  • the output generated in visiting each node
1 call to book_recurse()
book_export_html in modules/book.module
This function is called by book_export() to generate HTML for export.

File

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

Code

function book_recurse($nid = 0, $depth = 1, $visit_pre, $visit_post) {
  $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid = %d AND n.moderate = 0 ORDER BY b.weight, n.title'), $nid);
  while ($page = db_fetch_object($result)) {

    // Load the node:
    $node = node_load($page->nid);
    if ($node) {
      if (function_exists($visit_pre)) {
        $output .= call_user_func($visit_pre, $node, $depth, $nid);
      }
      else {
        $output .= book_node_visitor_html_pre($node, $depth, $nid);
      }
      $children = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND b.parent = %d AND n.moderate = 0 ORDER BY b.weight, n.title'), $node->nid);
      while ($childpage = db_fetch_object($children)) {
        $childnode = node_load($childpage->nid);
        if ($childnode->nid != $node->nid) {
          $output .= book_recurse($childnode->nid, $depth + 1, $visit_pre, $visit_post);
        }
      }
      if (function_exists($visit_post)) {
        $output .= call_user_func($visit_post, $node, $depth);
      }
      else {

        # default
        $output .= book_node_visitor_html_post($node, $depth);
      }
    }
  }
  return $output;
}