You are here

function _print_generate_path in Printer, email and PDF versions 5.3

Same name and namespace in other branches
  1. 5.4 print.pages.inc \_print_generate_path()
  2. 6 print.pages.inc \_print_generate_path()
  3. 7.2 print.pages.inc \_print_generate_path()
  4. 7 print.pages.inc \_print_generate_path()
  5. 5.x print.pages.inc \_print_generate_path()

Prepare a Printer-friendly-ready node body for non-content pages

Parameters

$path: path of the node to be rendered into a printer-friendly page

$teaser: if set to TRUE, outputs only the node's teaser

$message: optional sender's message (used by the send e-mail module)

Return value

filled array ready to be used in the template

1 call to _print_generate_path()
print_controller in ./print.pages.inc
Select the print generator function based on the page type

File

./print.pages.inc, line 579
Contains the functions to generate Printer-friendly pages.

Code

function _print_generate_path($path, $teaser = FALSE, $message = NULL) {
  $path = drupal_get_normal_path($path);
  $_GET['q'] = $path;
  _menu_append_contextual_items();
  menu_set_active_item($path);

  // Adapted from index.php.
  $node = new stdClass();
  $node->body = menu_execute_active_handler();
  $node->title = drupal_get_title();
  $node->path = $path;

  // It may happen that a drupal_not_found is called in the above call
  if (preg_match('/404 Not Found/', drupal_get_headers()) == 1) {
    return FALSE;
  }
  if (is_int($node->body)) {
    switch ($node->body) {
      case MENU_NOT_FOUND:
        drupal_not_found();
        return FALSE;
        break;
      case MENU_ACCESS_DENIED:
        drupal_access_denied();
        return FALSE;
        break;
    }
  }

  // Delete any links area
  $node->body = preg_replace('!\\s*<div class="links">.*?</div>!sim', '', $node->body);

  // Convert the a href elements
  $pattern = '!<(a\\s[^>]*?)>(.*?)(</a>)!is';
  $node->body = preg_replace_callback($pattern, '_print_rewrite_urls', $node->body);
  init_theme();
  $print = _print_var_generator($node, $message);
  return $print;
}