You are here

function print_ui_node_view in Printer, email and PDF versions 7.2

Implements hook_node_view().

File

print_ui/print_ui.module, line 199
Printer-friendly pages User Interface module.

Code

function print_ui_node_view($node, $view_mode) {
  $corner_markup = '';
  foreach (module_implements('print_link') as $module) {
    $function = $module . '_print_link';
    if (function_exists($function)) {
      $link = call_user_func_array($function, array());
      $link_pos = variable_get('print_' . $link['format'] . '_link_pos', drupal_json_decode(PRINT_UI_LINK_POS_DEFAULT));
      $link_use_alias = variable_get('print_' . $link['format'] . '_link_use_alias', PRINT_UI_LINK_USE_ALIAS_DEFAULT);
      if (!preg_match('!^node/[\\d]*/revisions/[\\d]*/view$!', $_GET['q'])) {

        // Not a revision, use node->nid to build the path.
        $path = $link_use_alias && ($alias = drupal_lookup_path('alias', 'node/' . $node->nid)) ? $alias : $node->nid;
      }
      else {

        // This is a node revision, replace only the node component.
        $path = preg_replace('!^node/!', '', $_GET['q']);
      }
      $path = $link['path'] . '/' . $path;
      foreach (array(
        'node',
        'comment',
      ) as $type) {
        $allowed_type = print_ui_link_allowed($link, array(
          'type' => $type,
          'node' => $node,
          'view_mode' => $view_mode,
        ));
        if ($allowed_type) {
          drupal_add_css(drupal_get_path('module', 'print_ui') . '/css/print_ui.theme.css');
          $links = array();
          $format = theme('print_ui_format_link', array(
            'format' => $link['format'],
            'location' => 'link',
          ));

          // Show book link.
          if ($allowed_type === PRINT_UI_ALLOW_BOOK_LINK) {
            $path = $link['path'] . '/book/export/html/' . $node->nid;
            $links['book_' . $link['format']] = array(
              'href' => $path,
              'title' => $format['text'],
              'attributes' => $format['attributes'],
              'html' => $format['html'],
            );
          }
          elseif ($allowed_type === PRINT_UI_ALLOW_NORMAL_LINK) {
            $links['print_' . $link['format']] = array(
              'href' => $path,
              'title' => $format['text'],
              'attributes' => $format['attributes'],
              'html' => $format['html'],
              'query' => _print_ui_query_string_encode($_GET, array(
                'q',
              )),
            );
          }
          $link_content = array(
            '#theme' => 'links',
            '#links' => $links,
            '#attributes' => array(
              'class' => array(
                'links',
                'inline',
              ),
            ),
          );

          // If it's a node, and configured to show the link, but it's not the
          // html version of a book then show it.
          if ($type == 'node' && !empty($link_pos['link']) && !(isset($node->book) && $link['format'] == 'html')) {
            $node->content['links']['print_' . $link['format']] = $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_' . $link['format']]['query']['comment'] = $cid;
                $node->content['comments']['comments'][$cid]['links']['print_' . $link['format']] = $link_content;
              }
            }
          }
        }
      }
      if (!empty($link_pos['corner'])) {
        $corner_markup .= print_ui_insert_link($link, array(
          'node' => $node,
          'path' => $path,
          'location' => 'corner',
        ));
      }
    }
  }
  if ($view_mode == 'full' && !empty($corner_markup)) {

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