function print_pdf_link_allowed in Printer, email and PDF versions 5.3
Same name and namespace in other branches
- 5.4 print_pdf/print_pdf.module \print_pdf_link_allowed()
- 6 print_pdf/print_pdf.module \print_pdf_link_allowed()
- 7.2 print_pdf/print_pdf.module \print_pdf_link_allowed()
- 7 print_pdf/print_pdf.module \print_pdf_link_allowed()
- 5.x print_pdf/print_pdf.module \print_pdf_link_allowed()
Determine a the link to the PDF version is allowed depending on all possible settings
Parameters
$args: array containing the possible parameters: teaser, node, type, path
Return value
FALSE if not allowed PRINT_ALLOW_NORMAL_LINK if a normal link is allowed PRINT_ALLOW_BOOK_LINK if a link is allowed in a book node
2 calls to print_pdf_link_allowed()
- print_pdf_insert_link in print_pdf/
print_pdf.module - Auxiliary function to display a formatted PDF version link
- print_pdf_link in print_pdf/
print_pdf.module - Implementation of hook_link().
File
- print_pdf/
print_pdf.module, line 291
Code
function print_pdf_link_allowed($args) {
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
if (!empty($args['teaser']) || !user_access('access print') || empty($print_pdf_pdf_tool)) {
// If showing only the teaser or the user is not allowed or link is disabled
return FALSE;
}
if (!empty($args['path'])) {
$nid = preg_replace('!^node/!', '', drupal_get_normal_path($args['path']));
if (is_numeric($nid)) {
$args['node'] = node_load(array(
'nid' => $nid,
));
}
}
if (!empty($args['node'])) {
static $node_type = FALSE;
$node = $args['node'];
if ($node_type === FALSE) {
if (isset($node->type)) {
$node_type = $node->type;
}
else {
$node_type = '';
}
}
// Node
$print_pdf_node_link_visibility = variable_get('print_pdf_node_link_visibility', PRINT_PDF_NODE_LINK_VISIBILITY_DEFAULT);
$print_pdf_node_link_pages = variable_get('print_pdf_node_link_pages', PRINT_PDF_NODE_LINK_PAGES_DEFAULT);
if (!empty($node->printing) || !_print_page_match($print_pdf_node_link_visibility, $print_pdf_node_link_pages)) {
// Page not in visibility list or we are working!
return FALSE;
}
elseif (isset($args['type']) && $args['type'] == 'comment' && isset($node_type)) {
// Link is for a comment, return the configured setting
return variable_get('print_pdf_display_comment_' . $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
}
else {
// Node link
if (isset($node_type) && !variable_get('print_pdf_display_' . $node_type, PRINT_TYPE_SHOW_LINK_DEFAULT)) {
// Link for this node type is disabled
return FALSE;
}
elseif (isset($node->parent)) {
// Node is a book;
$print_pdf_book_link = variable_get('print_pdf_book_link', PRINT_PDF_BOOK_LINK_DEFAULT);
if (!$print_pdf_book_link || !user_access('see printer-friendly version')) {
// Book link is disabled
return FALSE;
}
else {
return PRINT_ALLOW_BOOK_LINK;
}
}
else {
return PRINT_ALLOW_NORMAL_LINK;
}
}
}
else {
// 'System' page
$print_pdf_sys_link_visibility = variable_get('print_pdf_sys_link_visibility', PRINT_PDF_SYS_LINK_VISIBILITY_DEFAULT);
$print_pdf_sys_link_pages = variable_get('print_pdf_sys_link_pages', PRINT_PDF_SYS_LINK_PAGES_DEFAULT);
return _print_page_match($print_pdf_sys_link_visibility, $print_pdf_sys_link_pages);
}
}