$items = array();
$items[PRINTMAIL_PATH] = array(
- 'title' => 'Send page by e-mail',
+ 'title' => variable_get('print_mail_text_title', 'Send page by e-mail'),
'page callback' => 'drupal_get_form',
'page arguments' => array('print_mail_form'),
'access callback' => '_print_mail_access',
$items[PRINTMAIL_PATH . '/' . PRINTMAIL_PATH] = array(
'access callback' => FALSE,
);
- $items['admin/config/print/email'] = array(
+ $items['admin/config/user-interface/print/email'] = array(
'title' => 'e-mail',
'page callback' => 'drupal_get_form',
'page arguments' => array('print_mail_settings'),
'type' => MENU_LOCAL_TASK,
'file' => 'print_mail.admin.inc',
);
- $items['admin/config/print/email/options'] = array(
+ $items['admin/config/user-interface/print/email/options'] = array(
'title' => 'Options',
'weight' => 1,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
- $items['admin/config/print/email/strings'] = array(
+ $items['admin/config/user-interface/print/email/strings'] = array(
'title' => 'Text strings',
'page callback' => 'drupal_get_form',
'page arguments' => array('print_mail_strings_settings'),
*/
function _print_mail_access($permission) {
$page_access = TRUE;
- $user_access = TRUE;
- $reasons = array();
- global $user;
$parts = explode('/', $_GET['q']);
- if (count($parts) > 1) {
- unset($parts[0]);
- $path = implode('/', $parts);
- // If the destination page is not accessible, don't show the form
- if ($router_item = menu_get_item($path)) {
- if (!$router_item['access']) {
+ if ($parts[0] == PRINTMAIL_PATH) {
+ if (count($parts) > 1) {
+ unset($parts[0]);
+ $path = implode('/', $parts);
+ if (ctype_digit($parts[1])) {
+ if (drupal_lookup_path('source', $path)) {
+ // This is a numeric alias
+ $path = drupal_get_normal_path($path);
+ }
+ else {
+ // normal nid
+ $path = 'node/' . $path;
+ }
+ }
+ // If the destination page is not accessible, don't show the form
+ if (!($router_item = menu_get_item($path)) || (!$router_item['access'])) {
$page_access = FALSE;
- $reasons[] = (empty($router_item['access_callback'])
- ? 'access_callback'
- : $router_item['access_callback']
- ) . ' = FALSE';
}
}
- else {
- $page_access = FALSE;
- $reasons[] = 'no valid menu entry was found.';
- }
- }
- if (!user_access($permission)) {
- $user_access = FALSE;
- $reasons[] = t('User %uid cannot %permission',
- array('%uid' => $user->uid,
- '%permission' => $permission));
- }
- if ($page_access && $user_access) {
- return TRUE;
- }
- else {
- watchdog('Access to %path denied because: %reasons.',
- array('%path' => $path,
- '%reasons' => implode('; ', $reasons)));
- return FALSE;
}
+
+ return (user_access($permission) && $page_access);
}
/**
$path = drupal_get_path_alias($path);
}
else {
- $path = 'node/' . $nid;
+ $path = $nid;
}
}
$path = PRINTMAIL_PATH . '/' . $path;
}
if (!empty($args['path'])) {
$nid = preg_replace('!^node/!', '', drupal_get_normal_path($args['path']));
- if (is_numeric($nid)) {
+ if (ctype_digit($nid)) {
$args['node'] = node_load($nid);
}
}
}
elseif (isset($args['type']) && ($args['type'] == 'comment') && isset($node_type)) {
// Link is for a comment, return the configured setting
- $res = db_query("SELECT comments FROM {print_mail_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))
- ->fetch();
- $print_display_comment = $res ? intval($res->comments) : variable_get('print_mail_display_comment_' . $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
+ // 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))
+ ->fetch();
+ }
+ $print_display_comment = $res ? intval($res[$node->nid]->comments) : variable_get('print_mail_display_comment_' . $node_type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
if ($print_display_comment) {
return PRINT_ALLOW_NORMAL_LINK;
}