Index: modules/contact/contact.module =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.module,v retrieving revision 1.108 diff -u -p -r1.108 contact.module --- modules/contact/contact.module 24 Jul 2008 16:25:17 -0000 1.108 +++ modules/contact/contact.module 13 Sep 2008 04:06:44 -0000 @@ -38,6 +38,7 @@ function contact_help($path, $arg) { function contact_perm() { return array( 'access site-wide contact form' => t('Send feedback to administrators via e-mail using the site-wide contact form.'), + 'access personal contact form' => t('Contact users via email using their contact form.'), 'administer site-wide contact form' => t('Configure site-wide contact form administration settings.'), ); } @@ -113,12 +114,7 @@ function _contact_user_tab_access($accou if (!isset($account->contact)) { $account->contact = FALSE; } - return - $account && $user->uid && - ( - ($user->uid != $account->uid && $account->contact) || - user_access('administer users') - ); + return ($user->uid != $account->uid && $account->contact && user_access('access personal contact form')) || user_access('administer users'); } /** @@ -177,10 +173,11 @@ function contact_mail($key, &$message, $ case 'user_mail': case 'user_copy': $user = $params['user']; + $user->url = $user->uid ? url("user/$user->uid", array('absolute' => TRUE, 'language' => $language)) : $user->mail; $account = $params['account']; $message['subject'] .= '[' . variable_get('site_name', 'Drupal') . '] ' . $params['subject']; $message['body'][] = "$account->name,"; - $message['body'][] = t("!name (!name-url) has sent you a message via your contact form (!form-url) at !site.", array('!name' => $user->name, '!name-url' => url("user/$user->uid", array('absolute' => TRUE, 'language' => $language)), '!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)), '!site' => variable_get('site_name', 'Drupal')), $language->language); + $message['body'][] = t("!name (!name-url) has sent you a message via your contact form (!form-url) at !site.", array('!name' => $user->name, '!name-url' => $user->url, '!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)), '!site' => variable_get('site_name', 'Drupal')), $language->language); $message['body'][] = t("If you don't want to receive such e-mails, you can change your settings at !url.", array('!url' => url("user/$account->uid", array('absolute' => TRUE, 'language' => $language))), $language->language); $message['body'][] = t('Message:', NULL, $language->language); $message['body'][] = $params['message']; Index: modules/contact/contact.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.pages.inc,v retrieving revision 1.11 diff -u -p -r1.11 contact.pages.inc --- modules/contact/contact.pages.inc 16 Jul 2008 21:59:26 -0000 1.11 +++ modules/contact/contact.pages.inc 13 Sep 2008 04:06:47 -0000 @@ -157,7 +157,7 @@ function contact_mail_page_submit($form, function contact_user_page($account) { global $user; - if (!valid_email_address($user->mail)) { + if ($user->uid && !valid_email_address($user->mail)) { $output = t('You need to provide a valid e-mail address to contact other users. Please update your user information and try again.', array('@url' => url("user/$user->uid/edit", array('query' => 'destination=' . drupal_get_destination())))); } else if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3)) && !user_access('administer site-wide contact form')) { @@ -173,35 +173,85 @@ function contact_user_page($account) { function contact_mail_user(&$form_state, $recipient) { global $user; - $form['#token'] = $user->name . $user->mail; - $form['recipient'] = array('#type' => 'value', '#value' => $recipient); - $form['from'] = array('#type' => 'item', - '#title' => t('From'), - '#markup' => check_plain($user->name) . ' <' . check_plain($user->mail) . '>', - ); - $form['to'] = array('#type' => 'item', + + $form['recipient'] = array( + '#type' => 'value', + '#value' => $recipient + ); + + if ($user->uid) { + $form['#token'] = $user->name . $user->mail; + $form['from'] = array( + '#type' => 'item', + '#title' => t('From'), + '#markup' => check_plain($user->name) . ' <' . check_plain($user->mail) . '>', + ); + $form['mail'] = array( + '#type' => 'value', + '#value' => $user->mail, + ); + } + else { + $form['#token'] = $recipient->name . $recipient->mail; + $form['from'] = array( + '#type' => 'textfield', + '#title' => t('Your name'), + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => isset($_COOKIE['comment_info_name']) ? $_COOKIE['comment_info_name'] : '', + ); + $form['mail'] = array('#type' => 'textfield', + '#title' => t('Your e-mail address'), + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => isset($_COOKIE['comment_info_mail']) ? $_COOKIE['comment_info_mail'] : '', + ); + } + + $form['to'] = array( + '#type' => 'item', '#title' => t('To'), '#markup' => check_plain($recipient->name), ); - $form['subject'] = array('#type' => 'textfield', + $form['subject'] = array( + '#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 50, '#required' => TRUE, ); - $form['message'] = array('#type' => 'textarea', + $form['message'] = array( + '#type' => 'textarea', '#title' => t('Message'), '#rows' => 15, '#required' => TRUE, ); - $form['copy'] = array('#type' => 'checkbox', + $form['copy'] = array( + '#type' => 'checkbox', '#title' => t('Send yourself a copy.'), + '#disabled' => !$user->uid, ); - $form['submit'] = array('#type' => 'submit', + $form['submit'] = array( + '#type' => 'submit', '#value' => t('Send e-mail'), ); return $form; } +function contact_mail_user_validate($form, &$form_state) { + global $user; + if (!$user->uid) { + if (!valid_email_address($form_state['values']['mail'])) { + form_set_error('mail', t('You must enter a valid e-mail address.')); + } + foreach (array('from' => 'name', 'mail' => 'mail') as $form_field => $cookie_field) { + // Set cookie for 365 days. + if (isset($form_state['values'][$form_field])) { + setcookie('comment_info_' . $cookie_field, $form_state['values'][$form_field], $_SERVER['REQUEST_TIME'] + 31536000, '/'); + } + } + } +} + /** * Process the personal contact page form submission. */ @@ -212,11 +262,15 @@ function contact_mail_user_submit($form, // Send from the current user to the requested user. $to = $account->mail; - $from = $user->mail; + $from = $form_state['values']['mail']; // Save both users and all form values for email composition. $values = $form_state['values']; $values['account'] = $account; + if (!$user->uid) { + $user->mail = $form_state['values']['mail']; + $user->name = $form_state['values']['from']; + } $values['user'] = $user; // Send the e-mail in the requested user language.