book_recurse

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.

@todo This is duplicitous with node_build_content().

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

<?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 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 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;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.