You are here

function print_generate_node in Printer, email and PDF versions 5.2

Same name and namespace in other branches
  1. 5 print.module \print_generate_node()

Outputs a printer-friendly page. Used for content types

1 call to print_generate_node()
print_controller in ./print.module
Print module path catcher

File

./print.module, line 651
Display printer-friendly versions of Drupal pages

Code

function print_generate_node($nid, $cid = NULL) {
  global $base_url;

  // We can take a node id
  $node = node_load(array(
    'nid' => $nid,
  ));
  if (!node_access('view', $node)) {

    // Access is denied
    return drupal_access_denied();
  }

  //alert other modules that we are generating a printer-friendly page, so they can choose to show/hide info
  $node->printing = true;

  // Turn off Pagination by the Paging module
  unset($node->pages);
  unset($node->pages_count);
  unset($node->teaser);
  $node = (object) $node;
  if ($cid === NULL) {

    // Adapted (simplified) version of node_view for Drupal 5.x

    //Render the node content
    $node = node_build_content($node, false, true);

    // Disable fivestar widget output
    unset($node->content["fivestar_widget"]);

    // Disable service links module output
    unset($node->content["service_links"]);
    $node->body = drupal_render($node->content);
  }
  $print_settings = variable_get('print_settings', print_settings_default());
  if (function_exists(comment_render) && ($cid != NULL || $print_settings['comments'])) {

    //Print only the requested comment (or if $cid is NULL, all of them)
    $comments = comment_render($node, $cid);

    //Remove the comment title hyperlink
    $comments = preg_replace("/(<h3.*?>)(<a.*?>)(.*?)<\\/a>(<\\/h3>)/", "\$1\$3\$4", $comments);

    //Remove the comment links
    $comments = preg_replace("/\\s*<div class=\"links\">.*?<\\/div>/sim", "", $comments);
    if ($cid != NULL) {

      // Single comment requested, output only the comment
      unset($node->body);
    }
    $node->body .= $comments;
  }
  node_invoke_nodeapi($node, 'alter', false, true);

  // 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, $cid);
  include_once print_get_template($node->type);
}