--- /c/projects/drupal/cvs-47/drupal/modules/contact.module 2006-08-25 19:08:04.656250000 -0400 +++ modules/contact.module 2006-08-25 19:03:25.468750000 -0400 @@ -38,6 +38,15 @@ function contact_help($section) { } /** + * Valid permissions for this module + * @return An array of valid permissions for the contact module + */ +function contact_perm() { + return array('contact other users'); +} + + +/** * Implementation of hook_menu(). */ function contact_menu($may_cache) { @@ -307,10 +316,10 @@ function contact_mail_user() { else if (!$account->contact && !$admin_access) { $output = t('%name is not accepting e-mails.', array('%name' => $account->name)); } - else if (!$user->uid) { + else if (!$user->uid && !user_access('contact other users')) { $output = t('Please login or register to send %name a message.', array('%login' => url('user/login'), '%register' => url('user/register'), '%name' => $account->name)); } - else if (!valid_email_address($user->mail)) { + else 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"))); } else if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) { @@ -320,10 +329,27 @@ function contact_mail_user() { drupal_set_title($account->name); $form['#token'] = $user->name . $user->mail; - $form['from'] = array('#type' => 'item', - '#title' => t('From'), - '#value' => $user->name .' <'. $user->mail .'>', - ); + if ($user->uid) { + // User is logged in so we'll use the account e-mail address + $form['from'] = array('#type' => 'item', + '#title' => t('From'), + '#value' => $user->name .' <'. $user->mail .'>', + ); + } + else { + // User is not logged in so we must ask his e-mail address and validate it + $form['from_name'] = array('#type' => 'textfield', + '#title' => t('Your full name'), + '#required' => TRUE, + '#maxlength' => 60, + ); + $form['from'] = array('#type' => 'textfield', + '#title' => t('Your e-mail'), + '#required' => TRUE, + '#maxlength' => 64, + '#validate' => array('contact_email_validate' => array()), + ); + } $form['to'] = array('#type' => 'item', '#title' => t('To'), '#value' => $account->name, @@ -354,6 +380,13 @@ function contact_mail_user() { } } +function contact_email_validate($form) { + $address = $form['#value']; + if (!valid_email_address($address)) { + form_error($form, t('%address is an invalid e-mail address.', array('%address' => $address))); + } +} + /** * Process the personal contact page form submission. */ @@ -363,7 +396,7 @@ function contact_mail_user_submit($form_ $account = user_load(array('uid' => arg(1), 'status' => 1)); // Compose the body: $message[] = "$account->name,"; - $message[] = 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", NULL, NULL, TRUE), '%form-url' => url($_GET['q'], NULL, NULL, TRUE), '%site' => variable_get('site_name', 'drupal'))); + $message[] = t("%name (%name-url) has sent you a message via your contact form (%form-url) at %site.", array('%name' => $user->uid ? $user->name : $edit['from_name'], '%name-url' => $user->uid ? url("user/$user->uid", NULL, NULL, TRUE) : t('Not verified'), '%form-url' => url($_GET['q'], NULL, NULL, TRUE), '%site' => variable_get('site_name', 'drupal'))); $message[] = t("If you don't want to receive such e-mails, you can change your settings at %url.", array('%url' => url("user/$account->uid", NULL, NULL, TRUE))); $message[] = t('Message:'); $message[] = $edit['message']; @@ -375,7 +408,7 @@ function contact_mail_user_submit($form_ // Prepare all fields: $to = $account->mail; - $from = $user->mail; + $from = $edit['from']; // Format the subject: $subject = '['. variable_get('site_name', 'drupal') .'] '. $edit['subject'];