summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGerhard Killesreiter <killes_www_drop_org@227.no-reply.drupal.org>2006-03-26 19:35:05 +0000
committerGerhard Killesreiter <killes_www_drop_org@227.no-reply.drupal.org>2006-03-26 19:35:05 +0000
commit3052c49e0924fbe93789dec3760ae8f19685654e (patch)
tree4d9ac06a0ec7b3b6cb216f92e47b777f60574de5 /modules
parent5885925b0d2881277c22c6d70d86f1bc060fb133 (diff)
downloadbrdo-3052c49e0924fbe93789dec3760ae8f19685654e.tar.gz
brdo-3052c49e0924fbe93789dec3760ae8f19685654e.tar.bz2
#53826, Book export: db_rewrite breaks sql query., patch by puregin
Diffstat (limited to 'modules')
-rw-r--r--modules/book.module51
-rw-r--r--modules/book/book.module51
2 files changed, 32 insertions, 70 deletions
diff --git a/modules/book.module b/modules/book.module
index 5ecd04a83..70f0ee90c 100644
--- a/modules/book.module
+++ b/modules/book.module
@@ -370,7 +370,16 @@ function book_outline_submit($form_id, $form_values) {
}
/**
- * Return the path (call stack) to a certain book page.
+ * Given a node, this function returns an array of 'book node' objects
+ * representing the path in the book tree from the root to the
+ * parent of the given node.
+ *
+ * @param node - a book node object for which to compute the path
+ *
+ * @return - an array of book node objects representing the path of
+ * nodes root to parent of the given node. Returns an empty array if
+ * the node does not exist or is not part of a book hierarchy.
+ *
*/
function book_location($node, $nodes = array()) {
$parent = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.nid = %d'), $node->parent));
@@ -505,7 +514,7 @@ function book_nodeapi(&$node, $op, $teaser, $page) {
}
/**
- * Prepares both the custom breadcrumb trail and the forward/backward
+ * Prepares the links to children (TOC) and forward/backward
* navigation for a node presented as a book page.
*
* @ingroup themeable
@@ -669,7 +678,11 @@ function book_render() {
*/
function book_export($type = 'html', $nid = 0) {
$type = drupal_strtolower($type);
- $depth = _book_get_depth($nid);
+ $node_result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.nid = %d'), $nid);
+ if (db_num_rows($node_result) > 0) {
+ $node = db_fetch_object($node_result);
+ }
+ $depth = count(book_location($node)) + 1;
$export_function = 'book_export_' . $type;
if (function_exists($export_function)) {
@@ -744,38 +757,6 @@ function theme_book_export_html($title, $content) {
}
/**
- * Given a node, this function returns the depth of the node in its hierarchy.
- * A root node has depth 1, and children of a node of depth n have depth (n+1).
- *
- * @param nid
- * - the nid of the node whose depth to compute.
- * @return
- * - the depth of the given node in its hierarchy. Returns 0 if the node
- * does not exist or is not part of a book hierarchy.
- */
-function _book_get_depth($nid) {
- $depth = 0;
- if ($nid) {
- while ($nid) {
- $result = db_query(db_rewrite_sql('SELECT b.parent FROM {book} b WHERE b.nid = %d'), $nid);
- $obj = db_fetch_object($result);
- $parent = $obj->parent;
- if ($nid == $parent->parent) {
- $nid = 0;
- }
- else {
- $nid = $parent;
- }
- $depth++;
- }
- return $depth;
- }
- else {
- return 0;
- }
-}
-
-/**
* 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()
diff --git a/modules/book/book.module b/modules/book/book.module
index 5ecd04a83..70f0ee90c 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -370,7 +370,16 @@ function book_outline_submit($form_id, $form_values) {
}
/**
- * Return the path (call stack) to a certain book page.
+ * Given a node, this function returns an array of 'book node' objects
+ * representing the path in the book tree from the root to the
+ * parent of the given node.
+ *
+ * @param node - a book node object for which to compute the path
+ *
+ * @return - an array of book node objects representing the path of
+ * nodes root to parent of the given node. Returns an empty array if
+ * the node does not exist or is not part of a book hierarchy.
+ *
*/
function book_location($node, $nodes = array()) {
$parent = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.nid = %d'), $node->parent));
@@ -505,7 +514,7 @@ function book_nodeapi(&$node, $op, $teaser, $page) {
}
/**
- * Prepares both the custom breadcrumb trail and the forward/backward
+ * Prepares the links to children (TOC) and forward/backward
* navigation for a node presented as a book page.
*
* @ingroup themeable
@@ -669,7 +678,11 @@ function book_render() {
*/
function book_export($type = 'html', $nid = 0) {
$type = drupal_strtolower($type);
- $depth = _book_get_depth($nid);
+ $node_result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.nid = %d'), $nid);
+ if (db_num_rows($node_result) > 0) {
+ $node = db_fetch_object($node_result);
+ }
+ $depth = count(book_location($node)) + 1;
$export_function = 'book_export_' . $type;
if (function_exists($export_function)) {
@@ -744,38 +757,6 @@ function theme_book_export_html($title, $content) {
}
/**
- * Given a node, this function returns the depth of the node in its hierarchy.
- * A root node has depth 1, and children of a node of depth n have depth (n+1).
- *
- * @param nid
- * - the nid of the node whose depth to compute.
- * @return
- * - the depth of the given node in its hierarchy. Returns 0 if the node
- * does not exist or is not part of a book hierarchy.
- */
-function _book_get_depth($nid) {
- $depth = 0;
- if ($nid) {
- while ($nid) {
- $result = db_query(db_rewrite_sql('SELECT b.parent FROM {book} b WHERE b.nid = %d'), $nid);
- $obj = db_fetch_object($result);
- $parent = $obj->parent;
- if ($nid == $parent->parent) {
- $nid = 0;
- }
- else {
- $nid = $parent;
- }
- $depth++;
- }
- return $depth;
- }
- else {
- return 0;
- }
-}
-
-/**
* 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()