function print_pdf_insert_link in Printer, email and PDF versions 7
Same name and namespace in other branches
- 5.4 print_pdf/print_pdf.module \print_pdf_insert_link()
- 5.3 print_pdf/print_pdf.module \print_pdf_insert_link()
- 6 print_pdf/print_pdf.module \print_pdf_insert_link()
- 7.2 print_pdf/print_pdf.module \print_pdf_insert_link()
- 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 - Implements hook_help().
- print_pdf_node_view in print_pdf/
print_pdf.module - Implements hook_node_view().
File
- print_pdf/
print_pdf.module, line 543 - 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',
));
}
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;
}
}