203 lines
11 KiB
Plaintext
203 lines
11 KiB
Plaintext
<?php
|
|
// $Id$
|
|
|
|
/**
|
|
* @file
|
|
* Enables the use of personal and site-wide contact forms.
|
|
*/
|
|
|
|
/**
|
|
* Implement hook_help().
|
|
*/
|
|
function contact_help($path, $arg) {
|
|
switch ($path) {
|
|
case 'admin/help#contact':
|
|
$output = '<p>' . 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 <a href="@contact">contact page</a>). 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'))) . '</p>';
|
|
$output .= '<p>' . 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 <em>My account</em> page. If enabled, a <em>Contact</em> 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 <em>Contact</em> tab is only visible when viewing another user's profile (users do not see their own <em>Contact</em> tab).") . '</p>';
|
|
$output .= '<p>' . t('The <a href="@contact">contact page</a> 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 <em>access site-wide contact form</em> permission may access the <a href="@contact">contact page</a>.', array('@contact' => url('contact'))) . '</p>';
|
|
$output .= '<p>' . t('A link to your site\'s <a href="@contact">contact page</a> from the main <em>Navigation</em> 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'))) . '</p>';
|
|
$output .= '<p>' . t('Customize the <a href="@contact">contact page</a> with additional information (like physical location, mailing address, and telephone number) using the <a href="@contact-settings">contact form settings page</a>. The <a href="@contact-settings">settings page</a> 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/build/contact/settings'), '@contact' => url('contact'))) . '</p>';
|
|
$output .= '<p>' . t('For more information, see the online handbook entry for <a href="@contact">Contact module</a>.', array('@contact' => url('http://drupal.org/handbook/modules/contact/', array('absolute' => TRUE)))) . '</p>';
|
|
return $output;
|
|
case 'admin/build/contact':
|
|
$output = '<p>' . t('This page lets you set up <a href="@form">your site-wide contact form</a>. 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 <a href="@settings">settings page</a>, 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/build/contact/settings'), '@form' => url('contact'))) . '</p>';
|
|
if (!module_exists('menu')) {
|
|
$menu_note = t('The menu item can be customized and configured only once the menu module has been <a href="@modules-page">enabled</a>.', array('@modules-page' => url('admin/settings/modules')));
|
|
}
|
|
else {
|
|
$menu_note = '';
|
|
}
|
|
$output .= '<p>' . t('The contact module also adds a <a href="@menu-settings">menu item</a> (disabled by default) to the navigation block.', array('@menu-settings' => url('admin/build/menu'))) . ' ' . $menu_note . '</p>';
|
|
return $output;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implement hook_perm().
|
|
*/
|
|
function contact_perm() {
|
|
return array(
|
|
'administer site-wide contact form' => array(
|
|
'title' => t('Administer site-wide contact form'),
|
|
'description' => t('Configure site-wide contact form administration settings.'),
|
|
),
|
|
'access site-wide contact form' => array(
|
|
'title' => t('Access site-wide contact form'),
|
|
'description' => t('Send feedback to administrators via e-mail using the site-wide contact form.'),
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implement hook_menu().
|
|
*/
|
|
function contact_menu() {
|
|
$items['admin/build/contact'] = array(
|
|
'title' => 'Contact form',
|
|
'description' => 'Create a system contact form and set up categories for the form to use.',
|
|
'page callback' => 'contact_admin_categories',
|
|
'access arguments' => array('administer site-wide contact form'),
|
|
);
|
|
$items['admin/build/contact/list'] = array(
|
|
'title' => 'List',
|
|
'page callback' => 'contact_admin_categories',
|
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
|
);
|
|
$items['admin/build/contact/add'] = array(
|
|
'title' => 'Add category',
|
|
'page callback' => 'drupal_get_form',
|
|
'page arguments' => array('contact_admin_edit', 3),
|
|
'access arguments' => array('administer site-wide contact form'),
|
|
'type' => MENU_LOCAL_TASK,
|
|
'weight' => 1,
|
|
);
|
|
$items['admin/build/contact/edit/%contact'] = array(
|
|
'title' => 'Edit contact category',
|
|
'page callback' => 'drupal_get_form',
|
|
'page arguments' => array('contact_admin_edit', 3, 4),
|
|
'access arguments' => array('administer site-wide contact form'),
|
|
'type' => MENU_CALLBACK,
|
|
);
|
|
$items['admin/build/contact/delete/%contact'] = array(
|
|
'title' => 'Delete contact',
|
|
'page callback' => 'drupal_get_form',
|
|
'page arguments' => array('contact_admin_delete', 4),
|
|
'access arguments' => array('administer site-wide contact form'),
|
|
'type' => MENU_CALLBACK,
|
|
);
|
|
$items['admin/build/contact/settings'] = array(
|
|
'title' => 'Settings',
|
|
'page callback' => 'drupal_get_form',
|
|
'page arguments' => array('contact_admin_settings'),
|
|
'access arguments' => array('administer site-wide contact form'),
|
|
'type' => MENU_LOCAL_TASK,
|
|
'weight' => 2,
|
|
);
|
|
$items['contact'] = array(
|
|
'title' => 'Contact',
|
|
'page callback' => 'contact_site_page',
|
|
'access arguments' => array('access site-wide contact form'),
|
|
'type' => MENU_SUGGESTED_ITEM,
|
|
);
|
|
$items['user/%user/contact'] = array(
|
|
'title' => 'Contact',
|
|
'page callback' => 'contact_personal_page',
|
|
'page arguments' => array(1),
|
|
'type' => MENU_LOCAL_TASK,
|
|
'access callback' => '_contact_personal_tab_access',
|
|
'access arguments' => array(1),
|
|
'weight' => 2,
|
|
);
|
|
return $items;
|
|
}
|
|
|
|
/**
|
|
* Determine permission to a user's personal contact form.
|
|
*/
|
|
function _contact_personal_tab_access($account) {
|
|
global $user;
|
|
if (!isset($account->contact)) {
|
|
$account->contact = FALSE;
|
|
}
|
|
return
|
|
$account && $user->uid &&
|
|
(
|
|
($user->uid != $account->uid && $account->contact) ||
|
|
user_access('administer users')
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Load the data for a single contact category.
|
|
*/
|
|
function contact_load($cid) {
|
|
$contact = db_query("SELECT cid, category, recipients, reply, weight, selected FROM {contact} WHERE cid = :cid", array(':cid' => $cid))
|
|
->fetchAssoc();
|
|
return empty($contact) ? FALSE : $contact;
|
|
}
|
|
|
|
/**
|
|
* Implement hook_user_form().
|
|
*/
|
|
function contact_user_form(&$edit, &$user, $category = NULL) {
|
|
if ($category == 'account') {
|
|
$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($edit['contact']) ? $edit['contact'] : FALSE,
|
|
'#description' => t('Allow other users to contact you via a <a href="@url">personal contact form</a> 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/$user->uid/contact"))),
|
|
);
|
|
return $form;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implement hook_user_insert().
|
|
*/
|
|
function contact_user_insert(&$edit, &$user, $category = NULL) {
|
|
$edit['contact'] = variable_get('contact_default_status', 1);
|
|
}
|
|
|
|
/**
|
|
* Implement hook_user_validate().
|
|
*/
|
|
function contact_user_validate(&$edit, &$user, $category = NULL) {
|
|
return array('contact' => isset($edit['contact']) ? $edit['contact'] : FALSE);
|
|
}
|
|
|
|
/**
|
|
* Implement hook_mail().
|
|
*/
|
|
function contact_mail($key, &$message, $params) {
|
|
$language = $message['language'];
|
|
switch ($key) {
|
|
case 'page_mail':
|
|
case 'page_copy':
|
|
$contact = $params['contact'];
|
|
$message['subject'] .= t('[!category] !subject', array('!category' => $contact['category'], '!subject' => $params['subject']), array('langcode' => $language->language));
|
|
$message['body'][] = t("!name sent a message using the contact form at !form.", array('!name' => $params['name'], '!form' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language))), array('langcode' => $language->language));
|
|
$message['body'][] = $params['message'];
|
|
break;
|
|
case 'page_autoreply':
|
|
$contact = $params['contact'];
|
|
$message['subject'] .= t('[!category] !subject', array('!category' => $contact['category'], '!subject' => $params['subject']), array('langcode' => $language->language));
|
|
$message['body'][] = $contact['reply'];
|
|
break;
|
|
case 'user_mail':
|
|
case 'user_copy':
|
|
$user = $params['user'];
|
|
$account = $params['account'];
|
|
$message['subject'] .= '[' . variable_get('site_name', 'Drupal') . '] ' . $params['subject'];
|
|
$message['body'][] = "$account->name,";
|
|
$message['body'][] = t("!name (!name-url) has sent you a message via your contact form (!form-url) at !site.", array('!name' => $user->name, '!name-url' => url("user/$user->uid", array('absolute' => TRUE, 'language' => $language)), '!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)), '!site' => variable_get('site_name', 'Drupal')), array('langcode' => $language->language));
|
|
$message['body'][] = t("If you don't want to receive such e-mails, you can change your settings at !url.", array('!url' => url("user/$account->uid", array('absolute' => TRUE, 'language' => $language))), array('langcode' => $language->language));
|
|
$message['body'][] = t('Message:', array(), array('langcode' => $language->language));
|
|
$message['body'][] = $params['message'];
|
|
break;
|
|
}
|
|
}
|