You are here

function book_export in Drupal 7

Same name and namespace in other branches
  1. 4 modules/book.module \book_export()
  2. 5 modules/book/book.module \book_export()
  3. 6 modules/book/book.pages.inc \book_export()

Menu callback; Generates representations of a book page and its children.

The function delegates the generation of output to helper functions. The function name is derived by prepending 'book_export_' to the given output type. So, e.g., a type of 'html' results in a call to the function book_export_html().

Parameters

$type: A string encoding the type of output requested. The following types are currently supported in book module:

  • html: Printer-friendly HTML.

Other types may be supported in contributed modules.

$nid: An integer representing the node id (nid) of the node to export

Return value

A string representing the node and its children in the book hierarchy in a format determined by the $type parameter.

See also

book_menu()

1 string reference to 'book_export'
book_menu in modules/book/book.module
Implements hook_menu().

File

modules/book/book.pages.inc, line 47
User page callbacks for the book module.

Code

function book_export($type, $nid) {

  // Check that the node exists and that the current user has access to it.
  $node = node_load($nid);
  if (!$node) {
    return MENU_NOT_FOUND;
  }
  if (!node_access('view', $node)) {
    return MENU_ACCESS_DENIED;
  }
  $type = drupal_strtolower($type);
  $export_function = 'book_export_' . $type;
  if (function_exists($export_function)) {
    print call_user_func($export_function, $nid);
  }
  else {
    drupal_set_message(t('Unknown export format.'));
    drupal_not_found();
  }
}