function print_mail_link_allowed in Printer, email and PDF versions 7
Same name and namespace in other branches
- 5.4 print_mail/print_mail.module \print_mail_link_allowed()
- 5.3 print_mail/print_mail.module \print_mail_link_allowed()
- 6 print_mail/print_mail.module \print_mail_link_allowed()
- 7.2 print_mail/print_mail.module \print_mail_link_allowed()
- 5.x print_mail/print_mail.module \print_mail_link_allowed()
Check if the link to send by email is allowed depending on the 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_mail_link_allowed()
- print_mail_insert_link in print_mail/
print_mail.module - Auxiliary function to display a formatted send by email link
- print_mail_node_view in print_mail/
print_mail.module - Implements hook_node_view().
File
- print_mail/
print_mail.module, line 582 - Displays Printer-friendly versions of Drupal pages.
Code
function print_mail_link_allowed($args) {
$view_mode = isset($args['view_mode']) ? $args['view_mode'] : '';
if ($view_mode == 'teaser' && !variable_get('print_mail_link_teaser', PRINT_MAIL_LINK_TEASER_DEFAULT) || !in_array($view_mode, array(
'full',
'teaser',
'',
)) || !user_access('access send by email')) {
// If the teaser link is disabled or the user is not allowed
return FALSE;
}
if (!empty($args['path'])) {
$nid = preg_replace('!^node/!', '', drupal_get_normal_path($args['path']));
if (ctype_digit($nid)) {
$args['node'] = node_load($nid);
}
}
if (!empty($args['node'])) {
static $node_type = FALSE;
$node = $args['node'];
if (isset($node->type)) {
$node_type = $node->type;
}
// Node
$print_mail_node_link_visibility = variable_get('print_mail_node_link_visibility', PRINT_MAIL_NODE_LINK_VISIBILITY_DEFAULT);
$print_mail_node_link_pages = variable_get('print_mail_node_link_pages', PRINT_MAIL_NODE_LINK_PAGES_DEFAULT);
if (!_print_page_match($print_mail_node_link_visibility, "node/" . $node->nid, $print_mail_node_link_pages)) {
// Page not in visibility list
return FALSE;
}
elseif (isset($args['type']) && $args['type'] == 'comment' && isset($node_type)) {
// Link is for a comment, return the configured setting
// Cache this statically to avoid duplicate queries for every comment.
static $res = array();
if (!isset($res[$node->nid])) {
$res[$node->nid] = db_query("SELECT comments FROM {print_mail_node_conf} WHERE nid = :nid", array(
':nid' => $node->nid,
))
->fetchField();
}
$print_display_comment = $res && $res[$node->nid] !== FALSE ? $res[$node->nid] : variable_get('print_mail_display_comment_' . $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
if ($print_display_comment) {
return PRINT_ALLOW_NORMAL_LINK;
}
}
else {
// Node link
if (isset($node->print_mail_display) && !$node->print_mail_display) {
// Link for this node is disabled
return FALSE;
}
elseif (isset($node->book)) {
// Node is a book;
$print_mail_book_link = variable_get('print_mail_book_link', PRINT_MAIL_BOOK_LINK_DEFAULT);
switch ($print_mail_book_link) {
case 1:
if (user_access('access printer-friendly version')) {
return PRINT_ALLOW_BOOK_LINK;
}
break;
case 2:
return PRINT_ALLOW_NORMAL_LINK;
}
}
else {
return PRINT_ALLOW_NORMAL_LINK;
}
}
}
else {
// 'System' page
$print_mail_sys_link_visibility = variable_get('print_mail_sys_link_visibility', PRINT_MAIL_SYS_LINK_VISIBILITY_DEFAULT);
$print_mail_sys_link_pages = variable_get('print_mail_sys_link_pages', PRINT_MAIL_SYS_LINK_PAGES_DEFAULT);
return _print_page_match($print_mail_sys_link_visibility, $_GET['q'], $print_mail_sys_link_pages);
}
return FALSE;
}