You are here

function print_node_view in Printer, email and PDF versions 7

Implements hook_node_view().

File

./print.module, line 379
Displays Printer-friendly versions of Drupal pages.

Code

function print_node_view($node, $view_mode) {
  $print_html_link_pos = variable_get('print_html_link_pos', drupal_json_decode(PRINT_HTML_LINK_POS_DEFAULT));
  $print_html_link_use_alias = variable_get('print_html_link_use_alias', PRINT_HTML_LINK_USE_ALIAS_DEFAULT);
  foreach (array(
    'node',
    'comment',
  ) as $type) {
    $allowed_type = print_link_allowed(array(
      'type' => $type,
      'node' => $node,
      'view_mode' => $view_mode,
    ));
    if ($allowed_type === PRINT_ALLOW_NORMAL_LINK && !isset($node->book) && !empty($print_html_link_pos['link'])) {
      drupal_add_css(drupal_get_path('module', 'print') . '/css/printlinks.css');
      $links = array();
      $format = theme('print_format_link');
      $path = $print_html_link_use_alias && ($alias = drupal_lookup_path('alias', 'node/' . $node->nid)) ? $alias : $node->nid;
      $links['print_html'] = array(
        'href' => PRINT_PATH . '/' . $path,
        'title' => $format['text'],
        'attributes' => $format['attributes'],
        'html' => $format['html'],
        'query' => print_query_string_encode($_GET, array(
          'q',
        )),
      );
      $link_content = array(
        '#theme' => 'links',
        '#links' => $links,
        '#attributes' => array(
          'class' => array(
            'links',
            'inline',
          ),
        ),
      );
      if ($type == 'node') {
        $node->content['links']['print_html'] = $link_content;
      }
      elseif ($type == 'comment' && isset($node->content['comments']['comments'])) {
        foreach ($node->content['comments']['comments'] as $cid => $comment) {
          if (is_numeric($cid)) {
            $link_content['#links']['print_html']['query']['comment'] = $cid;
            $node->content['comments']['comments'][$cid]['links']['print_html'] = $link_content;
          }
        }
      }
    }
  }
  if ($view_mode == 'full') {

    // Insert content corner links
    $node->content['print_links'] = array(
      '#prefix' => '<span class="print-link">',
      '#markup' => '',
      '#suffix' => '</span>',
      '#weight' => -101,
    );
    if (!empty($print_html_link_pos['corner'])) {
      $node->content['print_links']['#markup'] .= print_insert_link(NULL, $node);
    }
  }
}