function print_pdf_node_view in Printer, email and PDF versions 7
Implements hook_node_view().
File
- print_pdf/
print_pdf.module, line 300 - Displays Printer-friendly versions of Drupal pages.
Code
function print_pdf_node_view($node, $view_mode) {
$print_pdf_link_pos = variable_get('print_pdf_link_pos', drupal_json_decode(PRINT_PDF_LINK_POS_DEFAULT));
$print_pdf_link_use_alias = variable_get('print_pdf_link_use_alias', PRINT_PDF_LINK_USE_ALIAS_DEFAULT);
foreach (array(
'node',
'comment',
) as $type) {
$allowed_type = print_pdf_link_allowed(array(
'type' => $type,
'node' => $node,
'view_mode' => $view_mode,
));
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'],
);
}
elseif ($allowed_type === PRINT_ALLOW_NORMAL_LINK) {
$path = $print_pdf_link_use_alias && ($alias = drupal_lookup_path('alias', 'node/' . $node->nid)) ? $alias : $node->nid;
$links['print_pdf'] = array(
'href' => PRINTPDF_PATH . '/' . $path,
'title' => $format['text'],
'attributes' => $format['attributes'],
'html' => $format['html'],
'query' => print_query_string_encode($_GET, array(
'q',
)),
);
}
$link_content = array(
'#theme' => 'links',
'#links' => $links,
'#attributes' => array(
'class' => array(
'links',
'inline',
),
),
);
if ($type == 'node') {
$node->content['links']['print_pdf'] = $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_pdf']['query']['comment'] = $cid;
$node->content['comments']['comments'][$cid]['links']['print_pdf'] = $link_content;
}
}
}
}
}
// Insert content corner links
if (!empty($print_pdf_link_pos['corner']) && $view_mode == 'full') {
$node->content['print_links']['#markup'] .= print_pdf_insert_link(NULL, $node);
}
}