Same name and namespace in other branches
  1. 4.7.x modules/book.module \book_menu()
  2. 5.x modules/book/book.module \book_menu()
  3. 6.x modules/book/book.module \book_menu()
  4. 7.x modules/book/book.module \book_menu()

Implementation of hook_menu().

File

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

Code

function book_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'book',
      'title' => t('books'),
      'access' => user_access('access content'),
      'type' => MENU_NORMAL_ITEM,
      'weight' => 5,
    );
    $items[] = array(
      'path' => 'node/add/book',
      'title' => t('book page'),
      'access' => user_access('create book pages'),
    );
    $items[] = array(
      'path' => 'admin/node/book',
      'title' => t('books'),
      'callback' => 'book_admin',
      'access' => user_access('administer nodes'),
      'weight' => 4,
    );
    $items[] = array(
      'path' => 'admin/node/book/orphan',
      'title' => t('orphan pages'),
      'callback' => 'book_admin_orphan',
      'access' => user_access('administer nodes'),
      'weight' => 8,
    );
    $items[] = array(
      'path' => 'book',
      'title' => t('books'),
      'callback' => 'book_render',
      'access' => user_access('access content'),
      'type' => MENU_SUGGESTED_ITEM,
    );
    $items[] = array(
      'path' => 'book/print',
      'title' => t('printer-friendly version'),
      'callback' => 'book_print',
      'access' => user_access('access content'),
      'type' => MENU_CALLBACK,
    );
  }
  else {

    // To avoid SQL overhead, check whether we are on a node page and whether the
    // user is allowed to maintain books.
    if (arg(0) == 'node' && is_numeric(arg(1)) && user_access('maintain books')) {

      // Only add the outline-tab for non-book pages:
      $result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.nid = %d AND n.type != 'book'"), arg(1));
      if (db_num_rows($result) > 0) {
        $items[] = array(
          'path' => 'node/' . arg(1) . '/outline',
          'title' => t('outline'),
          'callback' => 'book_outline',
          'access' => user_access('maintain books'),
          '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, b.weight 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;
}