diff --git a/modules/contact/contact.module b/modules/contact/contact.module index 4557029961d9fe895ff419ce10c4bfd356df42fa..ab369ef0da5d82c1ff6735d705ff39b9359287d3 100644 --- a/modules/contact/contact.module +++ b/modules/contact/contact.module @@ -110,19 +110,39 @@ function contact_menu() { } /** - * Determine if a user can access to the contact tab. + * Menu access callback for a user's personal contact form. + * + * @param $account + * A user account object. + * @return + * TRUE if the current user has access to the requested user's contact form, + * or FALSE otherwise. */ function _contact_user_tab_access($account) { global $user; - if (!isset($account->contact)) { - $account->contact = FALSE; + + // Anonymous users cannot use or have contact forms. + if (!$user->uid || !$account->uid) { + return FALSE; } - return - $account && $user->uid && - ( - ($user->uid != $account->uid && $account->contact) || - user_access('administer users') - ); + + // User administrators should always have access to personal contact forms. + if (user_access('administer users')) { + return TRUE; + } + + // Users may not contact themselves. + if ($user->uid == $account->uid) { + return FALSE; + } + + // If the requested user has disabled their contact form, or this preference + // has not yet been saved, do not allow users to contact them. + if (empty($account->contact)) { + return FALSE; + } + + return TRUE; } /** diff --git a/modules/user/user.module b/modules/user/user.module index 3e31a7e3299a45838aadc6edf38b4b27477176ce..9f59cf9fdd3ad53e119df9bf762bd849165f7403 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1117,12 +1117,30 @@ function user_menu() { return $items; } +/** + * Implementation of hook_init(). + */ function user_init() { drupal_add_css(drupal_get_path('module', 'user') .'/user.css', 'module'); } -function user_uid_optional_load($arg) { - return user_load(isset($arg) ? $arg : $GLOBALS['user']->uid); +/** + * Load either a specified or the current user account. + * + * @param $uid + * An optional user ID of the user to load. If not provided, the current + * user's ID will be used. + * @return + * A fully-loaded $user object upon successful user load, FALSE if user + * cannot be loaded. + * + * @see user_load() + */ +function user_uid_optional_load($uid = NULL) { + if (!isset($uid)) { + $uid = $GLOBALS['user']->uid; + } + return user_load($uid); } /**