You are here

function _print_mail_access in Printer, email and PDF versions 5.4

Same name and namespace in other branches
  1. 6 print_mail/print_mail.module \_print_mail_access()
  2. 7.2 print_mail/print_mail.module \_print_mail_access()
  3. 7 print_mail/print_mail.module \_print_mail_access()
  4. 5.x print_mail/print_mail.module \_print_mail_access()

Access callback to check a combination of user_acess() and page access

Parameters

$permission: permission required to view the page

Return value

TRUE if the user has permission to view the page, FALSE otherwise

1 call to _print_mail_access()
print_mail_menu in print_mail/print_mail.module
Implementation of hook_menu().

File

print_mail/print_mail.module, line 307

Code

function _print_mail_access($permission) {
  $page_access = TRUE;
  $parts = explode('/', $_GET['q']);
  if ($parts[0] == PRINTMAIL_PATH && count($parts) > 1) {
    unset($parts[0]);
    $path = implode('/', $parts);
    if (is_numeric($parts[1])) {
      $path = 'node/' . $path;
    }
    else {
      $path = drupal_get_normal_path($path);
    }
    if (preg_match('!^node/(\\d+)$!', $path, $matches) == 1) {
      $page_access = node_access('view', node_load($matches[1]));
    }
    elseif (preg_match('!^book/export/html/(\\d+)$!', $path, $matches) == 1) {
      $page_access = user_access('see printer-friendly version') && node_access('view', node_load($matches[1]));
    }
    else {
      if (!($router_item = menu_get_item(NULL, $path)) || !$router_item['access']) {
        $page_access = FALSE;
      }
    }
  }
  return user_access($permission) && $page_access;
}