You are here

function _print_generate_node in Printer, email and PDF versions 7.2

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 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

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

string $format: Format of the page being generated.

int $vid: (Optional) revision ID of the node to use.

int $cid: (Optional) comment ID of the individual comment to be rendered.

string $view_mode: (Optional) view mode to be used when rendering the content.

Return value

object|bool filled node-like object to be used in the print 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 611

Code

function _print_generate_node($nid, $format, $vid = NULL, $cid = NULL, $view_mode = PRINT_VIEW_MODE) {
  global $_print_urls;
  if (!isset($langcode)) {
    $langcode = $GLOBALS['language_content']->language;
  }

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

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

    // Access is denied.
    drupal_access_denied();
    drupal_exit();
  }
  drupal_set_title($node->title);
  $build = array();
  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']);
    $build = $node->content;
    unset($node->content);
  }
  if (function_exists('comment_node_page_additions') && ($cid != NULL || variable_get('print_comments', PRINT_COMMENTS_DEFAULT))) {

    // 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);
  $node->content = $content;
  return $node;
}