You are here

function print_link in Printer, email and PDF versions 5.3

Same name and namespace in other branches
  1. 5.4 print.module \print_link()
  2. 5 print.module \print_link()
  3. 5.2 print.module \print_link()
  4. 6 print.module \print_link()
  5. 5.x print.module \print_link()

Implementation of hook_link().

File

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

Code

function print_link($type, $node = NULL, $teaser = FALSE) {
  $print_html_link_pos = variable_get('print_html_link_pos', array(
    PRINT_HTML_LINK_POS_DEFAULT => PRINT_HTML_LINK_POS_DEFAULT,
  ));
  $print_html_link_use_alias = variable_get('print_html_link_use_alias', PRINT_HTML_LINK_USE_ALIAS_DEFAULT);
  $allowed_type = print_link_allowed(array(
    'type' => $type,
    'node' => $node,
    'teaser' => $teaser,
  ));
  if ($allowed_type === PRINT_ALLOW_NORMAL_LINK && !empty($print_html_link_pos['link'])) {
    drupal_add_css(drupal_get_path('module', 'print') . '/css/printlinks.css');
    $links = array();
    $format = theme('print_format_link');
    $query_arr = $_GET;
    if ($type == 'comment') {
      $query_arr['comment'] = $node->cid;
    }
    $query = print_query_string_encode($query_arr, array(
      'q',
    ));
    if (empty($query)) {
      $query = NULL;
    }
    if ($print_html_link_use_alias) {
      $path = drupal_get_path_alias('node/' . $node->nid);
    }
    else {
      $path = $node->nid;
    }
    $links['print'] = array(
      'href' => PRINT_PATH . '/' . $path,
      'title' => $format['text'],
      'attributes' => $format['attributes'],
      'html' => $format['html'],
      'query' => $query,
    );
    return $links;
  }
  else {
    return;
  }
}