book_recurse
modules/book/book.module, строка 733
- Версии
- 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()
.
Параметры
nid
- the node id (nid) of the root node of the book hierarchy.
- the depth of the given node in the book hierarchy.
- a function callback to be called upon visiting a node in the tree
- a function callback to be called after visiting a node in the tree, but before recursively visiting children.
Возвращаемое значение
- the output generated in visiting each node
Код
<?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;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии