You are here

function print_pdf_insert_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_insert_link()
  2. 5.3 print_pdf/print_pdf.module \print_pdf_insert_link()
  3. 7.2 print_pdf/print_pdf.module \print_pdf_insert_link()
  4. 7 print_pdf/print_pdf.module \print_pdf_insert_link()
  5. 5.x print_pdf/print_pdf.module \print_pdf_insert_link()

Auxiliary function to display a formatted PDF version link

Function made available so that developers may call this function from their defined pages/blocks.

Parameters

$path: path of the original page (optional). If not specified, the current URL is used

$node: an optional node object, to be used in defining the path, if used, the path argument is irrelevant

Return value

string with the HTML link to the printer-friendly page

2 calls to print_pdf_insert_link()
print_pdf_help in print_pdf/print_pdf.module
Implementation of hook_help().
print_pdf_nodeapi in print_pdf/print_pdf.module
Implementation of hook_nodeapi().

File

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

Code

function print_pdf_insert_link($path = NULL, $node = NULL) {
  if ($node !== NULL) {
    $nid = $node->nid;
    $path = 'node/' . $nid;
    $allowed_type = print_pdf_link_allowed(array(
      'node' => $node,
    ));
  }
  else {
    if ($path === NULL) {
      $nid = preg_replace('!^node/([\\d]+)!', '$1', $_GET['q']);
      $path = $_GET['q'];
    }
    else {
      $nid = NULL;
    }
    $allowed_type = print_pdf_link_allowed(array(
      'path' => $path,
    ));
  }
  if ($allowed_type) {
    if ($nid !== NULL) {
      if ($allowed_type === PRINT_ALLOW_BOOK_LINK) {
        $path = 'book/export/html/' . $nid;
      }
      else {
        if (variable_get('print_pdf_link_use_alias', PRINT_PDF_LINK_USE_ALIAS_DEFAULT) && ($alias = drupal_lookup_path('alias', $path))) {
          $path = $alias;
        }
        else {
          $path = $nid;
        }
      }
      $path = PRINTPDF_PATH . '/' . $path;
      $query = print_query_string_encode($_GET, array(
        'q',
      ));
      if (empty($query)) {
        $query = NULL;
      }
    }
    else {
      $query = NULL;
    }
    drupal_add_css(drupal_get_path('module', 'print') . '/css/printlinks.css');
    $format = theme('print_pdf_format_link');
    return '<span class="print_pdf">' . l($format['text'], $path, array(
      'attributes' => $format['attributes'],
      'query' => $query,
      'absolute' => TRUE,
      'html' => $format['html'],
    )) . '</span>';
  }
  else {
    return FALSE;
  }
}