### Eclipse Workspace Patch 1.0 #P drupal Index: modules/locale/locale.module =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v retrieving revision 1.171 diff -u -r1.171 locale.module --- modules/locale/locale.module 3 May 2007 09:51:08 -0000 1.171 +++ modules/locale/locale.module 15 May 2007 12:19:14 -0000 @@ -186,10 +186,11 @@ * Implementation of hook_user(). */ function locale_user($type, $edit, &$user, $category = NULL) { - if ($type == 'form' && $category == 'account' && variable_get('language_count', 1) > 1 && variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) == LANGUAGE_NEGOTIATION_PATH) { + // Show language field when user is editing own account and administrator is creating account + if (variable_get('language_count', 1) > 1 && ($type == 'register' && user_access('administer users') || $type == 'form' && $category == 'account' )) { $languages = language_list('enabled'); $languages = $languages['1']; - if ($user->language == '') { + if (!$user || $user->language == '') { $default = language_default(); $user->language = $default->language; } @@ -203,12 +204,16 @@ ); $form['locale']['language'] = array('#type' => 'radios', '#title' => t('Language'), - '#default_value' => $user->language, + '#default_value' => $user ? $user->language : $default->language, '#options' => $names, - '#description' => t('Selecting a different locale will change the interface language of the site.'), + '#description' => t('Selecting a different locale will change the interface and mail language and of the site.'), ); return $form; } + elseif ($type == 'context') { + // Switches to default language if user doesn't have one + locale_switch_language($user ? ($user->language ? $user->language : language_default()) : NULL); + } } /** Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.780 diff -u -r1.780 user.module --- modules/user/user.module 14 May 2007 13:43:38 -0000 1.780 +++ modules/user/user.module 15 May 2007 12:19:17 -0000 @@ -1188,16 +1188,13 @@ } function user_pass_submit($form_values, $form, &$form_state) { - global $base_url; $account = $form_values['account']; - $from = variable_get('site_mail', ini_get('sendmail_from')); // Mail one time login URL and instructions. - $variables = array('!username' => $account->name, '!site' => variable_get('site_name', 'Drupal'), '!login_url' => user_pass_reset_url($account), '!uri' => $base_url, '!uri_brief' => substr($base_url, strlen('http://')), '!mailto' => $account->mail, '!date' => format_date(time()), '!login_uri' => url('user', array('absolute' => TRUE)), '!edit_uri' => url('user/'. $account->uid .'/edit', array('absolute' => TRUE))); - $subject = _user_mail_text('pass_subject', $variables); - $body = _user_mail_text('pass_body', $variables); - $mail_success = drupal_mail('user-pass', $account->mail, $subject, $body, $from); + $variables = array('!login_url' => user_pass_reset_url($account)); + + $mail_success = user_mail('pass', $account, $variables); if ($mail_success) { watchdog('user', 'Password reset instructions mailed to %name at %email.', array('%name' => $account->name, '%email' => $account->mail)); @@ -1212,6 +1209,45 @@ } /** + * Send an e-mail message to a user, using Drupal variables and default settings. + * This function automatically provides subject and body for known user e-mails + * + * @param $key + * A key to identify the mail sent. The mailkey for altering will be 'user-' + $key + * @param $account + * User account to which the e-mail will be sent. + * @param $subject + * Subject of the e-mail to be sent. This must not contain any newline + * characters, or the mail may not be sent properly. + * @param $body + * Message to be sent. Drupal will format the correct line endings for you. + * @param $from + * Sets From, Reply-To, Return-Path and Error-To to this value, if given. + * @param $headers + * Associative array containing the headers to add. This is typically + * used to add extra headers (From, Cc, and Bcc). + * When sending mail, the mail must contain a From header. + * @return Returns TRUE if the mail was successfully accepted for delivery, + * FALSE otherwise. + */ +function user_mail($key, $account, $variables = array(), $subject = '', $body = '', $from = NULL, $headers = array()) { + global $base_url; + + // Add standard variables + $variables += array('!username' => $account->name, '!site' => variable_get('site_name', 'Drupal'), '!uri' => $base_url, '!uri_brief' => substr($base_url, strlen('http://')), '!mailto' => $account->mail, '!date' => format_date(time()), '!login_uri' => url('user', array('absolute' => TRUE)), '!edit_uri' => url('user/'. $account->uid .'/edit', array('absolute' => TRUE))); + + // Get the language code for this user account + $default = language_default(); + $langcode = (isset($account->language) && $account->language) ? $account->language : $default->language; + + // Build the e-mail if no subject and body has been passed + $subject = $subject ? $subject : _user_mail_text($key.'_subject', $variables, $langcode); + $body = $body ? $body : _user_mail_text($key.'_body', $variables, $langcode); + $from = $from ? $from : variable_get('site_mail', ini_get('sendmail_from')); + + return drupal_mail('user-'.$key, $account->mail, $subject, $body, $from, $headers); +} +/** * Menu callback; process one time login link and redirects to the user page on success. */ function user_pass_reset($uid, $timestamp, $hashed_pass, $action = NULL) { @@ -1337,7 +1373,6 @@ } function user_register_submit($form_values, $form, &$form_state) { - global $base_url; $admin = user_access('administer users'); $mail = $form_values['mail']; @@ -1349,7 +1384,7 @@ $pass = user_password(); }; $notify = isset($form_values['notify']) ? $form_values['notify'] : NULL; - $from = variable_get('site_mail', ini_get('sendmail_from')); + if (isset($form_values['roles'])) { $roles = array_filter($form_values['roles']); // Remove unset roles } @@ -1375,7 +1410,7 @@ watchdog('user', 'New user: %name (%email).', array('%name' => $name, '%email' => $mail), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $account->uid .'/edit')); - $variables = array('!username' => $name, '!site' => variable_get('site_name', 'Drupal'), '!password' => $pass, '!uri' => $base_url, '!uri_brief' => substr($base_url, strlen('http://')), '!mailto' => $mail, '!date' => format_date(time()), '!login_uri' => url('user', array('absolute' => TRUE)), '!edit_uri' => url('user/'. $account->uid .'/edit', array('absolute' => TRUE)), '!login_url' => user_pass_reset_url($account)); + $variables = array('!password' => $pass, '!mailto' => $mail, '!login_url' => user_pass_reset_url($account)); // The first user may login immediately, and receives a customized welcome e-mail. if ($account->uid == 1) { @@ -1395,19 +1430,14 @@ } else if (!variable_get('user_email_verification', TRUE) && $account->status && !$admin) { // No e-mail verification is required, create new user account, and login user immediately. - $subject = _user_mail_text('welcome_subject', $variables); - $body = _user_mail_text('welcome_body', $variables); - drupal_mail('user-register-welcome', $mail, $subject, $body, $from); + user_mail('welcome', $account); user_authenticate($account->name, trim($pass)); $form_state['redirect'] = ''; return; } else if ($account->status || $notify) { // Create new user account, no administrator approval required. - $subject = $notify ? _user_mail_text('admin_subject', $variables) : _user_mail_text('welcome_subject', $variables); - $body = $notify ? _user_mail_text('admin_body', $variables) : _user_mail_text('welcome_body', $variables); - - drupal_mail(($notify ? 'user-register-notify' : 'user-register-welcome'), $mail, $subject, $body, $from); + user_mail(($notify ? 'admin' : 'welcome'), $account); if ($notify) { drupal_set_message(t('Password and further instructions have been e-mailed to the new user %user.', array('%user' => $name))); @@ -1420,11 +1450,8 @@ } else { // Create new user account, administrator approval required. - $subject = _user_mail_text('approval_subject', $variables); - $body = _user_mail_text('approval_body', $variables); - - drupal_mail('user-register-approval-user', $mail, $subject, $body, $from); - drupal_mail('user-register-approval-admin', $from, $subject, t("!username has applied for an account.\n\n!edit_uri", $variables), $from); + user_mail('approval', $account, $variables); + user_mail('approval-admin', user_load(1), $variables); drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.
In the meantime, your password and further instructions have been sent to your e-mail address.')); } @@ -1675,7 +1702,7 @@ /*** Administrative features ***********************************************/ -function _user_mail_text($messageid, $variables = array()) { +function _user_mail_text($messageid, $variables = array(), $langcode = '') { // Check if an admin setting overrides the default string. if ($admin_setting = variable_get('user_mail_'. $messageid, FALSE)) { @@ -1685,21 +1712,23 @@ else { switch ($messageid) { case 'welcome_subject': - return t('Account details for !username at !site', $variables); + return t('Account details for !username at !site', $variables, $langcode); case 'welcome_body': - return t("!username,\n\nThank you for registering at !site. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $variables); + return t("!username,\n\nThank you for registering at !site. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $variables, $langcode); case 'admin_subject': - return t('An administrator created an account for you at !site', $variables); + return t('An administrator created an account for you at !site', $variables, $langcode); case 'admin_body': - return t("!username,\n\nA site administrator at !site has created an account for you. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $variables); + return t("!username,\n\nA site administrator at !site has created an account for you. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $variables, $langcode); case 'approval_subject': - return t('Account details for !username at !site (pending admin approval)', $variables); + return t('Account details for !username at !site (pending admin approval)', $variables, $langcode); case 'approval_body': - return t("!username,\n\nThank you for registering at !site. Your application for an account is currently pending approval. Once it has been granted, you may log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you may wish to change your password at !edit_uri\n\n\n-- !site team", $variables); + return t("!username,\n\nThank you for registering at !site. Your application for an account is currently pending approval. Once it has been granted, you may log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you may wish to change your password at !edit_uri\n\n\n-- !site team", $variables, $langcode); case 'pass_subject': - return t('Replacement login information for !username at !site', $variables); + return t('Replacement login information for !username at !site', $variables, $langcode); case 'pass_body': - return t("!username,\n\nA request to reset the password for your account has been made at !site.\n\nYou may now log in to !uri_brief clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once. It expires after one day and nothing will happen if it's not used.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.", $variables); + return t("!username,\n\nA request to reset the password for your account has been made at !site.\n\nYou may now log in to !uri_brief clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once. It expires after one day and nothing will happen if it's not used.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.", $variables, $langcode); + case 'approval-admin_subject': + return t("!username has applied for an account.\n\n!edit_uri", $variables, $langcode); } } }