book_recurse

  1. drupal
    1. 4.7
    2. 5 book.module
Versions
4.7 – 5 book_recurse($nid = 0, $depth = 1, $visit_pre, $visit_post)

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

▾ 2 functions call book_recurse()

book_export_html in modules/book.module
This function is called by book_export() to generate HTML for export.
book_recurse in modules/book.module
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…

Code

modules/book.module, line 755

<?php
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;
}
?>