summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-05-05 09:36:51 +0000
committerDries Buytaert <dries@buytaert.net>2005-05-05 09:36:51 +0000
commitdf9f93f98a1b6b4df1b4f394cde32e9e4320d299 (patch)
tree6054ae6f6e7201d9629939db49b0e5bced844600
parent77f6f233f8868d0706249621dcd931878c5de6b3 (diff)
downloadbrdo-df9f93f98a1b6b4df1b4f394cde32e9e4320d299.tar.gz
brdo-df9f93f98a1b6b4df1b4f394cde32e9e4320d299.tar.bz2
- Modified patch #21441 from puregin + RobinMonks: fixed some bugs surrounding the book administration and beautified some code making it more consistent with the rest of Drupal. :-)
-rw-r--r--modules/book.module83
-rw-r--r--modules/book/book.module83
2 files changed, 70 insertions, 96 deletions
diff --git a/modules/book.module b/modules/book.module
index 6e5048cbc..9f6030ff9 100644
--- a/modules/book.module
+++ b/modules/book.module
@@ -107,15 +107,6 @@ function book_menu($may_cache) {
'type' => MENU_LOCAL_TASK, 'weight' => 2);
}
}
-
- // We don't want to cache these menu items because they could change whenever
- // a book page or outline node is edited.
- if (arg(0) == 'admin' && arg(1) == 'node' && arg(2) == 'book') {
- $result = db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title'));
- while ($book = db_fetch_object($result)) {
- $items[] = array('path' => 'admin/node/book/'. $book->nid, 'title' => t('"%title" book', array('%title' => $book->title)));
- }
- }
}
return $items;
@@ -593,24 +584,8 @@ function book_tree($parent = 0, $depth = 3, $unfold = array()) {
* Menu callback; prints a listing of all books.
*/
function book_render() {
- $result = db_query(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 AND n.moderate = 0 ORDER BY b.weight, n.title'));
-
- while ($page = db_fetch_object($result)) {
- // Load the node:
- $node = node_load(array('nid' => $page->nid));
+ $result = db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 AND n.moderate = 0 ORDER BY b.weight, n.title'));
- if ($node) {
- // Take the most recent approved revision, extract the page and check output:
- $node = book_content($node, TRUE);
- // Output the content:
- $output .= '<div class="book">';
- $output .= '<div class="title">'. l($node->title, 'node/'. $node->nid) .'</div>';
- $output .= '<div class="body">'. $node->teaser .'</div>';
- $output .= '</div>';
- }
- }
-
- drupal_set_title(t('Books'));
return $output;
}
@@ -684,19 +659,19 @@ function book_print_recurse($parent = '', $depth = 1) {
return $output;
}
-function book_admin_view_line($node, $depth = 0) {
+function book_admin_edit_line($node, $depth = 0) {
return array('<div style="padding-left: '. (25 * $depth) .'px;">'. form_textfield(NULL, $node->nid .'][title', $node->title, 64, 255) .'</div>', form_weight(NULL, $node->nid .'][weight', $node->weight, 15), l(t('view'), 'node/'. $node->nid), l(t('edit'), 'node/'. $node->nid .'/edit'), l(t('delete'), 'node/'.$node->nid.'/delete'));
}
-function book_admin_view_book($nid, $depth = 1) {
+function book_admin_edit_book($nid, $depth = 1) {
$result = db_query(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d ORDER BY b.weight, n.title'), $nid);
$rows = array();
while ($node = db_fetch_object($result)) {
$node = node_load(array('nid' => $node->nid));
- $rows[] = book_admin_view_line($node, $depth);
- $rows = array_merge($rows, book_admin_view_book($node->nid, $depth + 1));
+ $rows[] = book_admin_edit_line($node, $depth);
+ $rows = array_merge($rows, book_admin_edit_book($node->nid, $depth + 1));
}
return $rows;
@@ -705,21 +680,22 @@ function book_admin_view_book($nid, $depth = 1) {
/**
* Display an administrative view of the hierarchy of a book.
*/
-function book_admin_view($nid, $depth = 0) {
- if ($nid) {
- $node = node_load(array('nid' => $nid));
-
- $output .= '<h3>'. check_plain($node->title) .'</h3>';
-
+function book_admin_edit($nid, $depth = 0) {
+ $node = node_load(array('nid' => $nid));
+ if ($node->nid) {
$header = array(t('Title'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3'));
- $rows[] = book_admin_view_line($node);
- $rows = array_merge($rows, book_admin_view_book($nid));
+ $rows[] = book_admin_edit_line($node);
+ $rows = array_merge($rows, book_admin_edit_book($nid));
$output .= theme('table', $header, $rows);
$output .= form_submit(t('Save book pages'));
+ drupal_set_title(check_plain($node->title));
return form($output);
}
+ else {
+ drupal_not_found();
+ }
}
function book_admin_save($nid, $edit = array()) {
@@ -762,8 +738,8 @@ function book_admin_orphan() {
$header = array(t('Title'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3'));
foreach ($pages as $nid => $node) {
if ($node->parent && empty($pages[$node->parent])) {
- $rows[] = book_admin_view_line($node, $depth);
- $rows = array_merge($rows, book_admin_view_book($node->nid, $depth + 1));
+ $rows[] = book_admin_edit_line($node, $depth);
+ $rows = array_merge($rows, book_admin_edit_book($node->nid, $depth + 1));
}
}
$output .= theme('table', $header, $rows);
@@ -779,15 +755,26 @@ function book_admin($nid = 0) {
$op = $_POST['op'];
$edit = $_POST['edit'];
- switch ($op) {
- case t('Save book pages'):
- drupal_set_message(book_admin_save($nid, $edit));
- // fall through:
- default:
- $output .= book_admin_view($nid);
- break;
+ if ($op == t('Save book pages')) {
+ drupal_set_message(book_admin_save($nid, $edit));
}
- return $output;
+
+ if ($nid) {
+ return book_admin_edit($nid);
+ }
+ else {
+ return book_admin_overview();
+ }
+}
+
+function book_admin_overview() {
+ $result = db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title'));
+ while ($book = db_fetch_object($result)) {
+ $rows[] = array(l($book->title, "node/$book->nid"), l(t('outline'), "admin/node/book/$book->nid"));
+ }
+ $headers = array(t('Book'), t('Operations'));
+
+ return theme('table', $headers, $rows);
}
/**
diff --git a/modules/book/book.module b/modules/book/book.module
index 6e5048cbc..9f6030ff9 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -107,15 +107,6 @@ function book_menu($may_cache) {
'type' => MENU_LOCAL_TASK, 'weight' => 2);
}
}
-
- // We don't want to cache these menu items because they could change whenever
- // a book page or outline node is edited.
- if (arg(0) == 'admin' && arg(1) == 'node' && arg(2) == 'book') {
- $result = db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title'));
- while ($book = db_fetch_object($result)) {
- $items[] = array('path' => 'admin/node/book/'. $book->nid, 'title' => t('"%title" book', array('%title' => $book->title)));
- }
- }
}
return $items;
@@ -593,24 +584,8 @@ function book_tree($parent = 0, $depth = 3, $unfold = array()) {
* Menu callback; prints a listing of all books.
*/
function book_render() {
- $result = db_query(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 AND n.moderate = 0 ORDER BY b.weight, n.title'));
-
- while ($page = db_fetch_object($result)) {
- // Load the node:
- $node = node_load(array('nid' => $page->nid));
+ $result = db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 AND n.moderate = 0 ORDER BY b.weight, n.title'));
- if ($node) {
- // Take the most recent approved revision, extract the page and check output:
- $node = book_content($node, TRUE);
- // Output the content:
- $output .= '<div class="book">';
- $output .= '<div class="title">'. l($node->title, 'node/'. $node->nid) .'</div>';
- $output .= '<div class="body">'. $node->teaser .'</div>';
- $output .= '</div>';
- }
- }
-
- drupal_set_title(t('Books'));
return $output;
}
@@ -684,19 +659,19 @@ function book_print_recurse($parent = '', $depth = 1) {
return $output;
}
-function book_admin_view_line($node, $depth = 0) {
+function book_admin_edit_line($node, $depth = 0) {
return array('<div style="padding-left: '. (25 * $depth) .'px;">'. form_textfield(NULL, $node->nid .'][title', $node->title, 64, 255) .'</div>', form_weight(NULL, $node->nid .'][weight', $node->weight, 15), l(t('view'), 'node/'. $node->nid), l(t('edit'), 'node/'. $node->nid .'/edit'), l(t('delete'), 'node/'.$node->nid.'/delete'));
}
-function book_admin_view_book($nid, $depth = 1) {
+function book_admin_edit_book($nid, $depth = 1) {
$result = db_query(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d ORDER BY b.weight, n.title'), $nid);
$rows = array();
while ($node = db_fetch_object($result)) {
$node = node_load(array('nid' => $node->nid));
- $rows[] = book_admin_view_line($node, $depth);
- $rows = array_merge($rows, book_admin_view_book($node->nid, $depth + 1));
+ $rows[] = book_admin_edit_line($node, $depth);
+ $rows = array_merge($rows, book_admin_edit_book($node->nid, $depth + 1));
}
return $rows;
@@ -705,21 +680,22 @@ function book_admin_view_book($nid, $depth = 1) {
/**
* Display an administrative view of the hierarchy of a book.
*/
-function book_admin_view($nid, $depth = 0) {
- if ($nid) {
- $node = node_load(array('nid' => $nid));
-
- $output .= '<h3>'. check_plain($node->title) .'</h3>';
-
+function book_admin_edit($nid, $depth = 0) {
+ $node = node_load(array('nid' => $nid));
+ if ($node->nid) {
$header = array(t('Title'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3'));
- $rows[] = book_admin_view_line($node);
- $rows = array_merge($rows, book_admin_view_book($nid));
+ $rows[] = book_admin_edit_line($node);
+ $rows = array_merge($rows, book_admin_edit_book($nid));
$output .= theme('table', $header, $rows);
$output .= form_submit(t('Save book pages'));
+ drupal_set_title(check_plain($node->title));
return form($output);
}
+ else {
+ drupal_not_found();
+ }
}
function book_admin_save($nid, $edit = array()) {
@@ -762,8 +738,8 @@ function book_admin_orphan() {
$header = array(t('Title'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3'));
foreach ($pages as $nid => $node) {
if ($node->parent && empty($pages[$node->parent])) {
- $rows[] = book_admin_view_line($node, $depth);
- $rows = array_merge($rows, book_admin_view_book($node->nid, $depth + 1));
+ $rows[] = book_admin_edit_line($node, $depth);
+ $rows = array_merge($rows, book_admin_edit_book($node->nid, $depth + 1));
}
}
$output .= theme('table', $header, $rows);
@@ -779,15 +755,26 @@ function book_admin($nid = 0) {
$op = $_POST['op'];
$edit = $_POST['edit'];
- switch ($op) {
- case t('Save book pages'):
- drupal_set_message(book_admin_save($nid, $edit));
- // fall through:
- default:
- $output .= book_admin_view($nid);
- break;
+ if ($op == t('Save book pages')) {
+ drupal_set_message(book_admin_save($nid, $edit));
}
- return $output;
+
+ if ($nid) {
+ return book_admin_edit($nid);
+ }
+ else {
+ return book_admin_overview();
+ }
+}
+
+function book_admin_overview() {
+ $result = db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title'));
+ while ($book = db_fetch_object($result)) {
+ $rows[] = array(l($book->title, "node/$book->nid"), l(t('outline'), "admin/node/book/$book->nid"));
+ }
+ $headers = array(t('Book'), t('Operations'));
+
+ return theme('table', $headers, $rows);
}
/**