You are here

function _print_generate_node in Printer, email and PDF versions 7

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

Prepare a Printer-friendly-ready node body for content nodes

Parameters

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

array $query: (optional) array of key/value pairs as used in the url() function for the query

$cid: comment ID of the individual comment to be rendered

$format: format of the page being generated

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

$message: optional sender's message (used by the send email module)

Return value

filled array ready to be used in the template

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

File

./print.pages.inc, line 516

Code

function _print_generate_node($nid, $query = NULL, $cid = NULL, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
  global $_print_urls;
  if (!isset($langcode)) {
    $langcode = $GLOBALS['language_content']->language;
  }

  // We can take a node id
  $node = node_load($nid);
  if (!$node) {

    // Node not found
    drupal_not_found();
    return FALSE;
  }
  elseif (!node_access('view', $node)) {

    // Access is denied
    drupal_access_denied();
    return FALSE;
  }
  drupal_set_title($node->title);
  $view_mode = $teaser ? 'teaser' : 'print';

  // Turn off Pagination by the Paging module
  unset($node->pages);
  unset($node->page_count);

  // Make this page a member of the original page's organic group
  if (function_exists('og_set_group_context') && isset($node->og_groups)) {
    og_set_group_context($node->og_groups);
  }
  if ($cid === NULL) {

    // Adapted (simplified) version of node_view
    // Render the node content
    node_build_content($node, $view_mode);

    // Disable the links area
    unset($node->content['links']);

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

    // Disable service links module output
    unset($node->content['service_links']);
    $build = $node->content;
    unset($node->content);
  }
  $print_comments = variable_get('print_comments', PRINT_COMMENTS_DEFAULT);
  if (function_exists('comment_node_page_additions') && ($cid != NULL || $print_comments)) {

    // Print only the requested comment (or if $cid is NULL, all of them)
    $comments = comment_node_page_additions($node);
    if (!empty($comments)) {
      unset($comments['comment_form']);
      foreach ($comments['comments'] as $key => &$comment) {
        if (is_numeric($key)) {
          if ($cid != NULL && $key != $cid) {
            unset($comments['comments'][$key]);
          }
          else {
            unset($comment['links']);
          }
        }
      }
      $build['comments'] = $comments;
    }
  }
  $build += array(
    '#theme' => 'node',
    '#node' => $node,
    '#view_mode' => $view_mode,
    '#language' => $langcode,
    '#print_format' => $format,
  );
  $type = 'node';
  drupal_alter(array(
    'node_view',
    'entity_view',
  ), $build, $type);
  $content = render($build);

  // Get rid of any links before the content
  $parts = explode('<div class="content', $content, 2);
  if (count($parts) == 2) {
    $pattern = '!(.*?)<a [^>]*?>(.*?)</a>(.*?)!mis';
    $parts[0] = preg_replace($pattern, '$1$2$3', $parts[0]);
    $content = implode('<div class="content', $parts);
  }

  // Check URL list settings
  $_print_urls = _print_url_list_enabled($node, $format);

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