' . t('The contact module facilitates communication via e-mail, by allowing your site\'s visitors to contact one another (personal contact forms), and by providing a simple way to direct messages to a set of administrator-defined recipients (the contact page). With either form, users specify a subject, write their message, and (optionally) have a copy of their message sent to their own e-mail address.', array('@contact' => url('contact'))) . '
'; $output .= '' . t("Personal contact forms allow users to be contacted via e-mail, while keeping recipient e-mail addresses private. Users may enable or disable their personal contact forms by editing their My account page. If enabled, a Contact tab leading to their personal contact form is available on their user profile. Site administrators have access to all personal contact forms (even if they have been disabled). The Contact tab is only visible when viewing another user's profile (users do not see their own Contact tab).") . '
'; $output .= '' . t('The contact page provides a simple form for visitors to leave comments, feedback, or other requests. Messages are routed by selecting a category from a list of administrator-defined options; each category has its own set of e-mail recipients. Common categories for a business site include, for example, "Website feedback" (messages are forwarded to web site administrators) and "Product information" (messages are forwarded to members of the sales department). The actual e-mail addresses defined within a category are not displayed. Only users in roles with the access site-wide contact form permission may access the contact page.', array('@contact' => url('contact'))) . '
'; $output .= '' . t('A link to your site\'s contact page from the main Navigation menu is created, but is disabled by default. Create a similar link on another menu by adding a menu item pointing to the path "contact"', array('@contact' => url('contact'))) . '
'; $output .= '' . t('Customize the contact page with additional information (like physical location, mailing address, and telephone number) using the contact form settings page. The settings page also provides configuration options for the maximum number of contact form submissions a user may perform per hour, and the default status of users\' personal contact forms.', array('@contact-settings' => url('admin/structure/contact/settings'), '@contact' => url('contact'))) . '
'; $output .= '' . t('For more information, see the online handbook entry for Contact module.', array('@contact' => url('http://drupal.org/handbook/modules/contact/', array('absolute' => TRUE)))) . '
'; return $output; case 'admin/structure/contact': $output = '' . t('This page lets you set up your site-wide contact form. To do so, add one or more categories. You can associate different recipients with each category to route e-mails to different people. For example, you can route website feedback to the webmaster and direct product information requests to the sales department. On the settings page, you can customize the information shown above the contact form. This can be useful to provide additional contact information such as your postal address and telephone number.', array('@settings' => url('admin/structure/contact/settings'), '@form' => url('contact'))) . '
'; if (!module_exists('menu')) { $menu_note = t('The menu item can be customized and configured only once the menu module has been enabled.', array('@modules-page' => url('admin/config/modules'))); } else { $menu_note = ''; } $output .= '' . t('The contact module also adds a menu item (disabled by default) to the navigation block.', array('@menu-settings' => url('admin/structure/menu'))) . ' ' . $menu_note . '
'; return $output; } } /** * Implement hook_permission(). */ function contact_permission() { return array( 'administer contact forms' => array( 'title' => t('Administer contact forms'), 'description' => t('Manage contact forms and configure contact form administrative settings.'), ), 'access site-wide contact form' => array( 'title' => t('Access site-wide contact form'), 'description' => t('Send e-mails to administrator-defined recipients using the site-wide contact form.'), ), 'access user contact forms' => array( 'title' => t('Access user contact forms'), 'description' => t('Send e-mails to users using their contact forms.'), ), ); } /** * Implement hook_menu(). */ function contact_menu() { $items['admin/structure/contact'] = array( 'title' => 'Contact form', 'description' => 'Create a system contact form and set up categories for the form to use.', 'page callback' => 'contact_category_list', 'access arguments' => array('administer contact forms'), 'file' => 'contact.admin.inc', ); $items['admin/structure/contact/add'] = array( 'title' => 'Add category', 'page callback' => 'drupal_get_form', 'page arguments' => array('contact_category_edit_form'), 'access arguments' => array('administer contact forms'), 'type' => MENU_LOCAL_ACTION, 'weight' => 1, 'file' => 'contact.admin.inc', ); $items['admin/structure/contact/edit/%contact'] = array( 'title' => 'Edit contact category', 'page callback' => 'drupal_get_form', 'page arguments' => array('contact_category_edit_form', 4), 'access arguments' => array('administer contact forms'), 'type' => MENU_CALLBACK, 'file' => 'contact.admin.inc', ); $items['admin/structure/contact/delete/%contact'] = array( 'title' => 'Delete contact', 'page callback' => 'drupal_get_form', 'page arguments' => array('contact_category_delete_form', 4), 'access arguments' => array('administer contact forms'), 'type' => MENU_CALLBACK, 'file' => 'contact.admin.inc', ); $items['contact'] = array( 'title' => 'Contact', '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' => 'drupal_get_form', 'page arguments' => array('contact_personal_form', 1), 'type' => MENU_LOCAL_TASK, 'access callback' => '_contact_personal_tab_access', 'access arguments' => array(1), 'weight' => 2, 'file' => 'contact.pages.inc', ); return $items; } /** * Menu access callback for a user's personal contact form. * * @param $account * A user account object. * @return * TRUE if the current user has access to the requested user's contact form, * or FALSE otherwise. */ function _contact_personal_tab_access(stdClass $account) { global $user; // Anonymous users cannot have contact forms. if (!$account->uid) { return FALSE; } // User administrators should always have access to personal contact forms. if (user_access('administer users')) { return TRUE; } // Users may not contact themselves. if ($user->uid == $account->uid) { return FALSE; } // If the requested user has disabled their contact form, or this preference // has not yet been saved, do not allow users to contact them. if (empty($account->contact)) { return FALSE; } return user_access('access user contact forms'); } /** * Load a contact category. * * @param $cid * The contact category ID. * @return * An array with the contact category's data. */ function contact_load($cid) { return db_query("SELECT * FROM {contact} WHERE cid = :cid", array(':cid' => $cid))->fetchAssoc(); } /** * Implement hook_user_insert(). */ function contact_user_insert(&$edit, $account, $category) { $edit['contact'] = variable_get('contact_default_status', 1); } /** * Implement hook_mail(). */ function contact_mail($key, &$message, $params) { $language = $message['language']; $variables = array( '!site-name' => variable_get('site_name', 'Drupal'), '!subject' => $params['subject'], '!category' => isset($params['category']['category']) ? $params['category']['category'] : '', '!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)), '!sender-name' => format_username($params['sender']), '!sender-url' => $params['sender']->uid ? url('user/' . $params['sender']->uid, array('absolute' => TRUE, 'language' => $language)) : $params['sender']->mail, ); switch ($key) { case 'page_mail': case 'page_copy': $message['subject'] .= t('[!category] !subject', $variables, array('langcode' => $language->language)); $message['body'][] = t("!sender-name (!sender-url) sent a message using the contact form at !form-url.", $variables, array('langcode' => $language->language)); $message['body'][] = $params['message']; break; case 'page_autoreply': $message['subject'] .= t('[!category] !subject', $variables, array('langcode' => $language->language)); $message['body'][] = $params['category']['reply']; break; case 'user_mail': case 'user_copy': $variables += array( '!recipient-name' => format_username($params['recipient']), '!recipient-edit-url' => url('user/' . $params['recipient']->uid . '/edit', array('absolute' => TRUE, 'language' => $language)), ); $message['subject'] .= t('[!site-name] !subject', $variables, array('langcode' => $language->language)); $message['body'][] = t('!recipient-name,', $variables, array('langcode' => $language->language)); $message['body'][] = t("!sender-name (!sender-url) has sent you a message via your contact form (!form-url) at !site-name.", $variables, array('langcode' => $language->language)); $message['body'][] = t("If you don't want to receive such e-mails, you can change your settings at !recipient-edit-url.", $variables, array('langcode' => $language->language)); $message['body'][] = t('Message:', array(), array('langcode' => $language->language)); $message['body'][] = $params['message']; break; } } /** * Implement hook_form_FORM_ID_alter(). * * Add the enable personal contact form to an individual user's account page. */ function contact_form_user_profile_form_alter(&$form, &$form_state) { if ($form['#user_category'] == 'account') { $account = $form['#user']; $form['contact'] = array( '#type' => 'fieldset', '#title' => t('Contact settings'), '#weight' => 5, '#collapsible' => TRUE, ); $form['contact']['contact'] = array( '#type' => 'checkbox', '#title' => t('Personal contact form'), '#default_value' => !empty($account->contact) ? $account->contact : FALSE, '#description' => t('Allow other users to contact you via a personal contact form which keeps your e-mail address hidden. Note that some privileged users such as site administrators are still able to contact you even if you choose to disable this feature.', array('@url' => url("user/$account->uid/contact"))), ); } } /** * Implement of hook_form_FORM_ID_alter(). * * Add the default personal contact setting on the user settings page. */ function contact_form_user_admin_settings_alter(&$form, &$form_state) { $form['contact'] = array( '#type' => 'fieldset', '#title' => t('Contact settings'), '#weight' => 0, ); $form['contact']['contact_default_status'] = array( '#type' => 'checkbox', '#title' => t('Enable the personal contact form by default for new users.'), '#description' => t('Changing this setting will not affect existing users.'), '#default_value' => 1, ); }