You are here

function book_nodeapi in Drupal 5

Same name and namespace in other branches
  1. 4 modules/book.module \book_nodeapi()
  2. 6 modules/book/book.module \book_nodeapi()

Implementation of hook_nodeapi().

Appends book navigation to all nodes in the book.

File

modules/book/book.module, line 427
Allows users to collaboratively author a book.

Code

function book_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'load':
      return db_fetch_array(db_query('SELECT parent, weight FROM {book} WHERE vid = %d', $node->vid));
      break;
    case 'view':
      if (!$teaser) {
        if (isset($node->parent)) {
          $path = book_location($node);

          // Construct the breadcrumb:
          $node->breadcrumb = array();

          // Overwrite the trail with a book trail.
          foreach ($path as $level) {
            $node->breadcrumb[] = array(
              'path' => 'node/' . $level->nid,
              'title' => $level->title,
            );
          }
          $node->breadcrumb[] = array(
            'path' => 'node/' . $node->nid,
          );
          $node->content['book_navigation'] = array(
            '#value' => theme('book_navigation', $node),
            '#weight' => 100,
          );
          if ($page) {
            menu_set_location($node->breadcrumb);
          }
        }
      }
      break;
    case 'update':
      if (isset($node->parent)) {
        if ($node->revision) {
          db_query("INSERT INTO {book} (nid, vid, parent, weight) VALUES (%d, %d, %d, %d)", $node->nid, $node->vid, $node->parent, $node->weight);
        }
        else {
          db_query("UPDATE {book} SET parent = %d, weight = %d WHERE vid = %d", $node->parent, $node->weight, $node->vid);
        }
      }
      break;
    case 'delete revision':
      db_query('DELETE FROM {book} WHERE vid = %d', $node->vid);
      break;
    case 'delete':
      db_query('DELETE FROM {book} WHERE nid = %d', $node->nid);
      break;
  }
}