summaryrefslogtreecommitdiff
path: root/modules/contact
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-10-11 01:06:27 +0000
committerDries Buytaert <dries@buytaert.net>2009-10-11 01:06:27 +0000
commit704e3ef81219d55950505f1efb7dda33e1fcc431 (patch)
tree910fe1702c889169a2e1ddb2c2f4c7b847d6e6e2 /modules/contact
parent7ed3cf3b133aa980f110ebf6585d69448e2cb6ef (diff)
downloadbrdo-704e3ef81219d55950505f1efb7dda33e1fcc431.tar.gz
brdo-704e3ef81219d55950505f1efb7dda33e1fcc431.tar.bz2
- Patch #601016 by Dave Reid: remove contact_site_page() and contact_personal_page() and use the forms directly.
Diffstat (limited to 'modules/contact')
-rw-r--r--modules/contact/contact.module7
-rw-r--r--modules/contact/contact.pages.inc90
2 files changed, 44 insertions, 53 deletions
diff --git a/modules/contact/contact.module b/modules/contact/contact.module
index f6a8dfa82..6c343882f 100644
--- a/modules/contact/contact.module
+++ b/modules/contact/contact.module
@@ -86,15 +86,16 @@ function contact_menu() {
);
$items['contact'] = array(
'title' => 'Contact',
- 'page callback' => 'contact_site_page',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('contact_site_form'),
'access arguments' => array('access site-wide contact form'),
'type' => MENU_SUGGESTED_ITEM,
'file' => 'contact.pages.inc',
);
$items['user/%user/contact'] = array(
'title' => 'Contact',
- 'page callback' => 'contact_personal_page',
- 'page arguments' => array(1),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('contact_personal_form', 1),
'type' => MENU_LOCAL_TASK,
'access callback' => '_contact_personal_tab_access',
'access arguments' => array(1),
diff --git a/modules/contact/contact.pages.inc b/modules/contact/contact.pages.inc
index 5ad41d6f1..8aa9ec661 100644
--- a/modules/contact/contact.pages.inc
+++ b/modules/contact/contact.pages.inc
@@ -6,40 +6,33 @@
* User page callbacks for the contact module.
*/
-
/**
- * Site-wide contact page.
+ * Form builder; the site-wide contact form.
*/
-function contact_site_page() {
+function contact_site_form($form, &$form_state) {
+ global $user;
+
+ // Check if flood control has been activated for sending e-mails.
$limit = variable_get('contact_threshold_limit', 5);
$window = variable_get('contact_threshold_window', 3600);
-
if (!flood_is_allowed('contact', $limit, $window) && !user_access('administer contact forms')) {
- $output = t("You cannot send more than %limit messages in @interval. Please try again later.", array('%limit' => $limit, '@interval' => format_interval($window)));
+ drupal_set_message(t("You cannot send more than %limit messages in @interval. Please try again later.", array('%limit' => $limit, '@interval' => format_interval($window))), 'error');
+ return drupal_access_denied();
}
- elseif (!db_query("SELECT 1 FROM {contact}")->fetchField()) {
+
+ // Get an array of the categories and the current default category.
+ $categories = db_query("SELECT cid, category FROM {contact} ORDER BY weight, category")->fetchAllKeyed();
+ $default_category = db_query("SELECT cid FROM {contact} WHERE selected = 1")->fetchField();
+
+ // If there are no categories, do not display the form.
+ if (!$categories) {
if (user_access('administer contact forms')) {
- $output = t('The contact form has not been configured. <a href="@add">Add one or more categories</a> to the form.', array('@add' => url('admin/structure/contact/add')));
+ drupal_set_message(t('The contact form has not been configured. <a href="@add">Add one or more categories</a> to the form.', array('@add' => url('admin/structure/contact/add'))), 'error');
}
else {
return drupal_not_found();
}
}
- else {
- $output = drupal_get_form('contact_site_form');
- }
-
- return $output;
-}
-
-/**
- * Form builder; the site-wide contact form.
- */
-function contact_site_form($form, &$form_state) {
- global $user;
-
- $categories = db_query("SELECT cid, category FROM {contact} ORDER BY weight, category")->fetchAllKeyed();
- $default_category = db_query("SELECT cid FROM {contact} WHERE selected = 1")->fetchField();
// If there is more than one category available and no default category has
// been selected, prepend a default placeholder value.
@@ -162,57 +155,54 @@ function contact_site_form_submit($form, &$form_state) {
}
/**
- * Personal contact page.
+ * Form builder; the personal contact form.
*/
-function contact_personal_page(stdClass $recipient) {
+function contact_personal_form($form, &$form_state, stdClass $recipient) {
global $user;
+ // Check if flood control has been activated for sending e-mails.
$limit = variable_get('contact_threshold_limit', 5);
$window = variable_get('contact_threshold_window', 3600);
-
- 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' => drupal_get_destination()))));
- }
- elseif (!flood_is_allowed('contact', $limit, $window) && !user_access('administer contact forms') && !user_access('administer users')) {
- $output = t("You cannot send more than %limit messages in @interval. Please try again later.", array('%limit' => $limit, '@interval' => format_interval($window)));
+ if (!flood_is_allowed('contact', $limit, $window) && !user_access('administer contact forms') && !user_access('administer users')) {
+ drupal_set_message(t("You cannot send more than %limit messages in @interval. Please try again later.", array('%limit' => $limit, '@interval' => format_interval($window))), 'error');
+ return drupal_access_denied();
}
- else {
- drupal_set_title(t('Contact @username', array('@username' => $recipient->name)), PASS_THROUGH);
- $output = drupal_get_form('contact_personal_form', $recipient);
- }
-
- return $output;
-}
-
-/**
- * Form builder; the personal contact form.
- */
-function contact_personal_form($form, &$form_state, stdClass $recipient) {
- global $user;
+
+ drupal_set_title(t('Contact @username', array('@username' => $recipient->name)), PASS_THROUGH);
+
$form['#token'] = $user->name . $user->mail;
- $form['recipient'] = array('#type' => 'value', '#value' => $recipient);
- $form['from'] = array('#type' => 'item',
+ $form['recipient'] = array(
+ '#type' => 'value',
+ '#value' => $recipient,
+ );
+ $form['from'] = array(
+ '#type' => 'item',
'#title' => t('From'),
'#markup' => theme('username', array('account' => $user)) . ' &lt;' . check_plain($user->mail) . '&gt;',
);
- $form['to'] = array('#type' => 'item',
+ $form['to'] = array(
+ '#type' => 'item',
'#title' => t('To'),
'#markup' => theme('username', array('account' => $recipient)),
);
- $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.'),
);
- $form['submit'] = array('#type' => 'submit',
+ $form['submit'] = array(
+ '#type' => 'submit',
'#value' => t('Send message'),
);
return $form;