Index: modules/contact/contact.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.admin.inc,v retrieving revision 1.15 diff -u -p -r1.15 contact.admin.inc --- modules/contact/contact.admin.inc 18 Sep 2009 00:12:46 -0000 1.15 +++ modules/contact/contact.admin.inc 24 Sep 2009 14:06:57 -0000 @@ -162,18 +162,3 @@ function contact_admin_delete_submit($fo $form_state['redirect'] = 'admin/structure/contact'; return; } - -function contact_admin_settings() { - $form['contact_hourly_threshold'] = array('#type' => 'select', - '#title' => t('Hourly threshold'), - '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50)), - '#default_value' => 3, - '#description' => t('The maximum number of contact form submissions a user can perform per hour.'), - ); - $form['contact_default_status'] = array( - '#type' => 'checkbox', - '#title' => t('Enable the personal contact form by default for new users'), - '#default_value' => 1, - ); - return system_settings_form($form, TRUE); -} Index: modules/contact/contact.install =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.install,v retrieving revision 1.14 diff -u -p -r1.14 contact.install --- modules/contact/contact.install 10 Sep 2009 06:38:17 -0000 1.14 +++ modules/contact/contact.install 24 Sep 2009 14:06:58 -0000 @@ -11,8 +11,8 @@ */ function contact_uninstall() { variable_del('contact_default_status'); - variable_del('contact_form_information'); - variable_del('contact_hourly_threshold'); + variable_del('contact_threshold_limit'); + variable_del('contact_threshold_window'); } /** @@ -73,3 +73,22 @@ function contact_schema() { return $schema; } + +/** + * @defgroup updates-6.x-to-7.x Contact updates from 6.x to 7.x + * @{ + */ + +/** + * Rename the threshold limit variable. + */ +function contact_update_7000() { + variable_set('contact_threshold_limit', variable_get('contact_hourly_threshold', 5)); + variable_del('contact_hourly_threshold'); + return array(); +} + +/** + * @} End of "defgroup updates-6.x-to-7.x" + * The next series of updates should start at 8000. + */ Index: modules/contact/contact.module =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.module,v retrieving revision 1.127 diff -u -p -r1.127 contact.module --- modules/contact/contact.module 22 Sep 2009 07:50:15 -0000 1.127 +++ modules/contact/contact.module 24 Sep 2009 14:06:58 -0000 @@ -59,12 +59,6 @@ function contact_menu() { 'access arguments' => array('administer site-wide contact form'), 'file' => 'contact.admin.inc', ); - $items['admin/structure/contact/list'] = array( - 'title' => 'List', - 'page callback' => 'contact_admin_categories', - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'file' => 'contact.admin.inc', - ); $items['admin/structure/contact/add'] = array( 'title' => 'Add category', 'page callback' => 'drupal_get_form', @@ -90,15 +84,6 @@ function contact_menu() { 'type' => MENU_CALLBACK, 'file' => 'contact.admin.inc', ); - $items['admin/structure/contact/settings'] = array( - 'title' => 'Settings', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('contact_admin_settings'), - 'access arguments' => array('administer site-wide contact form'), - 'file' => 'contact.admin.inc', - 'type' => MENU_LOCAL_TASK, - 'weight' => 1, - ); $items['contact'] = array( 'title' => 'Contact', 'page callback' => 'contact_site_page', @@ -201,3 +186,19 @@ function contact_mail($key, &$message, $ break; } } + +/** + * Implement of hook_form_FORM_ID_alter(). + */ +function contact_form_user_admin_settings_alter(&$form, $form_state) { + $form['contact'] = array( + '#type' => 'fieldset', + '#title' => t('Contact forms'), + '#weight' => 0, + ); + $form['contact']['contact_default_status'] = array( + '#type' => 'checkbox', + '#title' => t('Enable the personal contact form by default for new users.'), + '#default_value' => 1, + ); +} Index: modules/contact/contact.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.pages.inc,v retrieving revision 1.24 diff -u -p -r1.24 contact.pages.inc --- modules/contact/contact.pages.inc 18 Sep 2009 00:12:46 -0000 1.24 +++ modules/contact/contact.pages.inc 24 Sep 2009 14:06:58 -0000 @@ -11,8 +11,8 @@ * Site-wide contact page. */ function contact_site_page() { - if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3)) && !user_access('administer site-wide contact form')) { - $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3))); + if (!flood_is_allowed('contact', variable_get('contact_threshold_limit', 5), variable_get('contact_threshold_window', 3600)) && !user_access('administer site-wide contact form')) { + $output = t("You cannot send more than %number messages in @interval. Please try again later.", array('%number' => variable_get('contact_threshold_limit', 3), '@interval' => format_interval(variable_get('contact_threshold_window', 3600)))); } elseif (!db_query("SELECT COUNT(cid) FROM {contact}")->fetchField()) { if (user_access('administer site-wide contact form')) { @@ -157,8 +157,8 @@ function contact_personal_page($account) if (!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())))); } - elseif (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3)) && !user_access('administer site-wide contact form')) { - $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3))); + elseif (!flood_is_allowed('contact', variable_get('contact_threshold_limit', 5), variable_get('contact_threshold_window', 3600)) && !user_access('administer site-wide contact form')) { + $output = t("You cannot send more than %number messages in @interval. Please try again later.", array('%number' => variable_get('contact_threshold_limit', 3), '@interval' => format_interval(variable_get('contact_threshold_window', 3600)))); } else { drupal_set_title($account->name); Index: modules/contact/contact.test =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.test,v retrieving revision 1.30 diff -u -p -r1.30 contact.test --- modules/contact/contact.test 31 Aug 2009 18:40:00 -0000 1.30 +++ modules/contact/contact.test 24 Sep 2009 14:06:58 -0000 @@ -22,14 +22,17 @@ class ContactSitewideTestCase extends Dr */ function testSiteWideContact() { // Create and login administrative user. - $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer site-wide contact form', 'administer permissions')); + $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer site-wide contact form', 'administer permissions', 'administer users')); $this->drupalLogin($admin_user); + + $flood_limit = 3; + variable_set('contact_threshold_limit', $flood_limit); + variable_set('contact_threshold_window', 600); // Set settings. $edit = array(); - $edit['contact_hourly_threshold'] = 3; $edit['contact_default_status'] = TRUE; - $this->drupalPost('admin/structure/contact/settings', $edit, t('Save configuration')); + $this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration')); $this->assertText(t('The configuration options have been saved.'), t('Setting successfully saved.')); // Delete old categories to ensure that new categories are used. @@ -139,13 +142,13 @@ class ContactSitewideTestCase extends Dr $this->assertText(t('You must select a valid category.'), t('Valid category required.')); // Submit contact form with correct values and check flood interval. - for ($i = 0; $i < $edit['contact_hourly_threshold']; $i++) { + for ($i = 0; $i < $flood_limit; $i++) { $this->submitContact($this->randomName(16), $recipients[0], $this->randomName(16), $categories[0], $this->randomName(64)); $this->assertText(t('Your message has been sent.'), t('Message sent.')); } // Submit contact form one over limit. $this->drupalGet('contact'); - $this->assertRaw(t('You cannot send more than %number messages per hour. Please try again later.', array('%number' => $edit['contact_hourly_threshold'])), t('Message threshold reached.')); + $this->assertRaw(t('You cannot send more than %number messages in @interval. Please try again later.', array('%number' => variable_get('contact_threshold_limit', 3), '@interval' => format_interval(600))), t('Message threshold reached.')); // Delete created categories. $this->drupalLogin($admin_user); @@ -157,7 +160,7 @@ class ContactSitewideTestCase extends Dr */ function testAutoReply() { // Create and login administrative user. - $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer site-wide contact form', 'administer permissions')); + $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer site-wide contact form', 'administer permissions', 'administer users')); $this->drupalLogin($admin_user); // Set up three categories, 2 with an auto-reply and one without. @@ -314,15 +317,16 @@ class ContactPersonalTestCase extends Dr * Test personal contact form. */ function testPersonalContact() { - $admin_user = $this->drupalCreateUser(array('administer site-wide contact form')); + $admin_user = $this->drupalCreateUser(array('administer site-wide contact form', 'administer users')); $this->drupalLogin($admin_user); + + $flood_limit = 3; + variable_set('contact_threshold_limit', $flood_limit); // Enable the personal contact form. - $flood_control = 3; $edit = array(); $edit['contact_default_status'] = TRUE; - $edit['contact_hourly_threshold'] = $flood_control; - $this->drupalPost('admin/structure/contact/settings', $edit, t('Save configuration')); + $this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration')); $this->assertText(t('The configuration options have been saved.'), t('Setting successfully saved.')); // Reload variables. @@ -349,7 +353,7 @@ class ContactPersonalTestCase extends Dr $this->assertIdentical($num_records_flood, '0', t('Flood table emptied.')); // Submit contact form with correct values and check flood interval. - for ($i = 0; $i < $flood_control; $i++) { + for ($i = 0; $i < $flood_limit; $i++) { $this->drupalGet('user/' . $web_user2->uid . '/contact'); $this->drupalPost(NULL, $edit, t('Send message')); $this->assertText(t('Your message has been sent.'), t('Message sent.')); @@ -357,7 +361,7 @@ class ContactPersonalTestCase extends Dr // Submit contact form one over limit. $this->drupalGet('user/' . $web_user2->uid . '/contact'); - $this->assertRaw(t('You cannot send more than %number messages per hour. Please try again later.', array('%number' => $flood_control)), t('Message threshold reached.')); + $this->assertRaw(t('You cannot send more than %number messages in @interval. Please try again later.', array('%number' => $flood_limit, '@interval' => format_interval(variable_get('contact_threshold_window', 3600)))), t('Message threshold reached.')); $this->drupalLogout(); @@ -366,7 +370,7 @@ class ContactPersonalTestCase extends Dr // Disable the personal contact form. $edit = array(); $edit['contact_default_status'] = FALSE; - $this->drupalPost('admin/structure/contact/settings', $edit, t('Save configuration')); + $this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration')); $this->assertText(t('The configuration options have been saved.'), t('Setting successfully saved.')); // Reload variables.