summaryrefslogtreecommitdiff
path: root/modules/contact
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-09-26 00:13:19 +0000
committerDries Buytaert <dries@buytaert.net>2009-09-26 00:13:19 +0000
commitdba2ebb118a25ff6ed9bcc6a59cc42c20d55ad66 (patch)
tree3190a36dc331b3f1cf6f465fccc01527387dc6cd /modules/contact
parente1d4b4145945d6097c9b9a5206b5283560f03476 (diff)
downloadbrdo-dba2ebb118a25ff6ed9bcc6a59cc42c20d55ad66.tar.gz
brdo-dba2ebb118a25ff6ed9bcc6a59cc42c20d55ad66.tar.bz2
- Patch #570142 by Dave Reid | Dries: get rid of the admin/structure/contact/settings page.
Diffstat (limited to 'modules/contact')
-rw-r--r--modules/contact/contact.admin.inc15
-rw-r--r--modules/contact/contact.install23
-rw-r--r--modules/contact/contact.module31
-rw-r--r--modules/contact/contact.pages.inc8
-rw-r--r--modules/contact/contact.test30
5 files changed, 58 insertions, 49 deletions
diff --git a/modules/contact/contact.admin.inc b/modules/contact/contact.admin.inc
index dd05b866c..3331b1a1a 100644
--- a/modules/contact/contact.admin.inc
+++ b/modules/contact/contact.admin.inc
@@ -162,18 +162,3 @@ function contact_admin_delete_submit($form, &$form_state) {
$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);
-}
diff --git a/modules/contact/contact.install b/modules/contact/contact.install
index 3e22f41bb..7b3e57b71 100644
--- a/modules/contact/contact.install
+++ b/modules/contact/contact.install
@@ -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.
+ */
diff --git a/modules/contact/contact.module b/modules/contact/contact.module
index 2cdb73077..37a47dc79 100644
--- a/modules/contact/contact.module
+++ b/modules/contact/contact.module
@@ -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, $params) {
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,
+ );
+}
diff --git a/modules/contact/contact.pages.inc b/modules/contact/contact.pages.inc
index 4c9210576..319a34eb6 100644
--- a/modules/contact/contact.pages.inc
+++ b/modules/contact/contact.pages.inc
@@ -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 <a href="@url">user information</a> 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);
diff --git a/modules/contact/contact.test b/modules/contact/contact.test
index aaf8e99bc..381dbffb5 100644
--- a/modules/contact/contact.test
+++ b/modules/contact/contact.test
@@ -22,14 +22,17 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
*/
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 DrupalWebTestCase {
$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 DrupalWebTestCase {
*/
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 DrupalWebTestCase {
* 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 DrupalWebTestCase {
$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 DrupalWebTestCase {
// 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 DrupalWebTestCase {
// 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.