You are here

function print_pdf_link in Printer, email and PDF versions 6

Same name and namespace in other branches
  1. 5.4 print_pdf/print_pdf.module \print_pdf_link()
  2. 5.3 print_pdf/print_pdf.module \print_pdf_link()
  3. 5.x print_pdf/print_pdf.module \print_pdf_link()

Implementation of hook_link().

File

print_pdf/print_pdf.module, line 302
Displays Printer-friendly versions of Drupal pages.

Code

function print_pdf_link($type, $node = NULL, $teaser = FALSE) {
  $print_pdf_link_pos = variable_get('print_pdf_link_pos', unserialize(PRINT_PDF_LINK_POS_DEFAULT));
  $print_pdf_link_use_alias = variable_get('print_pdf_link_use_alias', PRINT_PDF_LINK_USE_ALIAS_DEFAULT);
  $allowed_type = print_pdf_link_allowed(array(
    'type' => $type,
    'node' => $node,
    'teaser' => $teaser,
  ));
  if ($allowed_type && !empty($print_pdf_link_pos['link'])) {
    drupal_add_css(drupal_get_path('module', 'print') . '/css/printlinks.css');
    $links = array();
    $format = theme('print_pdf_format_link');

    // Show book link
    if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
      $links['book_pdf'] = array(
        'href' => PRINTPDF_PATH . '/book/export/html/' . $node->nid,
        'title' => $format['text'],
        'attributes' => $format['attributes'],
        'html' => $format['html'],
      );
      return $links;
    }
    elseif ($allowed_type === PRINT_ALLOW_NORMAL_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_pdf_link_use_alias && ($alias = drupal_lookup_path('alias', 'node/' . $node->nid))) {
        $path = $alias;
      }
      else {
        $path = $node->nid;
      }
      $links['print_pdf'] = array(
        'href' => PRINTPDF_PATH . '/' . $path,
        'title' => $format['text'],
        'attributes' => $format['attributes'],
        'html' => $format['html'],
        'query' => $query,
      );
      return $links;
    }
  }
  else {
    return;
  }
}