book_print

Versions
4.6
book_print($nid = 0, $depth = 1)

Menu callback; generates printer-friendly book page with all descendants.

Code

modules/book.module, line 604

<?php
function book_print($nid = 0, $depth = 1) {
  global $base_url;
  $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 n.status = 1 AND n.nid = %d AND n.moderate = 0 ORDER BY b.weight, n.title'), $nid);

  while ($page = db_fetch_object($result)) {
    // load the node:
    $node = node_load(array('nid' => $page->nid));

    if ($node) {
      // output the content:
      if (node_hook($node, 'content')) {
        $node = node_invoke($node, 'content');
      }
      // Allow modules to change $node->body before viewing.
      node_invoke_nodeapi($node, 'view', $node->body, false);

      $output .= '<h1 id="'. $node->nid .'" name="'. $node->nid .'" class="book-h'. $depth .'">'. check_plain($node->title) .'</h1>';

      if ($node->body) {
        $output .= $node->body;
      }
    }
  }

  $output .= book_print_recurse($nid, $depth + 1);

  $html = '<html><head><title>'. check_plain($node->title) .'</title>';
  $html .= '<base href="'. $base_url .'/" />';
  $html .= theme_stylesheet_import('misc/print.css', 'print');
  $html .= '</head><body>'. $output .'</body></html>';

  print $html;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.