| 1 | | <?php |
| 2 | | // $Id: contact.module,v 1.111 2008/10/09 15:15:51 webchick Exp $ |
| 3 | | |
| 4 | | /** |
| 5 | | * @file |
| 6 | | * Enables the use of personal and site-wide contact forms. |
| 7 | | */ |
| 8 | | |
| 9 | | /** |
| 10 | | * Implementation of hook_help(). |
| 11 | | */ |
| 12 | 149 | function contact_help($path, $arg) { |
| 13 | | switch ($path) { |
| 14 | 104 | case 'admin/help#contact': |
| 15 | 34 | $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>'; |
| 16 | 34 | $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>'; |
| 17 | 34 | $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>'; |
| 18 | 34 | $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>'; |
| 19 | 34 | $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>'; |
| 20 | 34 | $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>'; |
| 21 | 34 | return $output; |
| 22 | 104 | case 'admin/build/contact': |
| 23 | 7 | $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>'; |
| 24 | 7 | if (!module_exists('menu')) { |
| 25 | 0 | $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'))); |
| 26 | 0 | } |
| 27 | | else { |
| 28 | 7 | $menu_note = ''; |
| 29 | | } |
| 30 | 7 | $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>'; |
| 31 | 7 | return $output; |
| 32 | 0 | } |
| 33 | 97 | } |
| 34 | | |
| 35 | | /** |
| 36 | | * Implementation of hook_perm(). |
| 37 | | */ |
| 38 | 149 | function contact_perm() { |
| 39 | | return array( |
| 40 | | 'administer site-wide contact form' => array( |
| 41 | 14 | 'title' => t('Administer site-wide contact form'), |
| 42 | 14 | 'description' => t('Configure site-wide contact form administration
settings.'), |
| 43 | 14 | ), |
| 44 | | 'access site-wide contact form' => array( |
| 45 | 14 | 'title' => t('Access site-wide contact form'), |
| 46 | 14 | 'description' => t('Send feedback to administrators via e-mail using
the site-wide contact form.'), |
| 47 | 14 | ), |
| 48 | 14 | ); |
| 49 | 0 | } |
| 50 | | |
| 51 | | /** |
| 52 | | * Implementation of hook_menu(). |
| 53 | | */ |
| 54 | 149 | function contact_menu() { |
| 55 | 2 | $items['admin/build/contact'] = array( |
| 56 | 2 | 'title' => 'Contact form', |
| 57 | 2 | 'description' => 'Create a system contact form and set up categories
for the form to use.', |
| 58 | 2 | 'page callback' => 'contact_admin_categories', |
| 59 | 2 | 'access arguments' => array('administer site-wide contact form'), |
| 60 | | ); |
| 61 | 2 | $items['admin/build/contact/list'] = array( |
| 62 | 2 | 'title' => 'List', |
| 63 | 2 | 'page callback' => 'contact_admin_categories', |
| 64 | 2 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 65 | | ); |
| 66 | 2 | $items['admin/build/contact/add'] = array( |
| 67 | 2 | 'title' => 'Add category', |
| 68 | 2 | 'page callback' => 'drupal_get_form', |
| 69 | 2 | 'page arguments' => array('contact_admin_edit', 3), |
| 70 | 2 | 'access arguments' => array('administer site-wide contact form'), |
| 71 | 2 | 'type' => MENU_LOCAL_TASK, |
| 72 | 2 | 'weight' => 1, |
| 73 | | ); |
| 74 | 2 | $items['admin/build/contact/edit/%contact'] = array( |
| 75 | 2 | 'title' => 'Edit contact category', |
| 76 | 2 | 'page callback' => 'drupal_get_form', |
| 77 | 2 | 'page arguments' => array('contact_admin_edit', 3, 4), |
| 78 | 2 | 'access arguments' => array('administer site-wide contact form'), |
| 79 | 2 | 'type' => MENU_CALLBACK, |
| 80 | | ); |
| 81 | 2 | $items['admin/build/contact/delete/%contact'] = array( |
| 82 | 2 | 'title' => 'Delete contact', |
| 83 | 2 | 'page callback' => 'drupal_get_form', |
| 84 | 2 | 'page arguments' => array('contact_admin_delete', 4), |
| 85 | 2 | 'access arguments' => array('administer site-wide contact form'), |
| 86 | 2 | 'type' => MENU_CALLBACK, |
| 87 | | ); |
| 88 | 2 | $items['admin/build/contact/settings'] = array( |
| 89 | 2 | 'title' => 'Settings', |
| 90 | 2 | 'page callback' => 'drupal_get_form', |
| 91 | 2 | 'page arguments' => array('contact_admin_settings'), |
| 92 | 2 | 'access arguments' => array('administer site-wide contact form'), |
| 93 | 2 | 'type' => MENU_LOCAL_TASK, |
| 94 | 2 | 'weight' => 2, |
| 95 | | ); |
| 96 | 2 | $items['contact'] = array( |
| 97 | 2 | 'title' => 'Contact', |
| 98 | 2 | 'page callback' => 'contact_site_page', |
| 99 | 2 | 'access arguments' => array('access site-wide contact form'), |
| 100 | 2 | 'type' => MENU_SUGGESTED_ITEM, |
| 101 | | ); |
| 102 | 2 | $items['user/%user/contact'] = array( |
| 103 | 2 | 'title' => 'Contact', |
| 104 | 2 | 'page callback' => 'contact_user_page', |
| 105 | 2 | 'page arguments' => array(1), |
| 106 | 2 | 'type' => MENU_LOCAL_TASK, |
| 107 | 2 | 'access callback' => '_contact_user_tab_access', |
| 108 | 2 | 'access arguments' => array(1), |
| 109 | 2 | 'weight' => 2, |
| 110 | | ); |
| 111 | 2 | return $items; |
| 112 | 0 | } |
| 113 | | |
| 114 | | /** |
| 115 | | * Determine if a user can access to the contact tab. |
| 116 | | */ |
| 117 | 149 | function _contact_user_tab_access($account) { |
| 118 | 19 | global $user; |
| 119 | 19 | if (!isset($account->contact)) { |
| 120 | 0 | $account->contact = FALSE; |
| 121 | 0 | } |
| 122 | | return |
| 123 | 19 | $account && $user->uid && |
| 124 | | ( |
| 125 | 19 | ($user->uid != $account->uid && $account->contact) || |
| 126 | 10 | user_access('administer users') |
| 127 | 19 | ); |
| 128 | 0 | } |
| 129 | | |
| 130 | | /** |
| 131 | | * Load the data for a single contact category. |
| 132 | | */ |
| 133 | 149 | function contact_load($cid) { |
| 134 | 11 | $contact = db_fetch_array(db_query("SELECT * FROM {contact} WHERE cid =
%d", $cid)); |
| 135 | 11 | return empty($contact) ? FALSE : $contact; |
| 136 | 0 | } |
| 137 | | |
| 138 | | /** |
| 139 | | * Implementation of hook_user_form(). |
| 140 | | */ |
| 141 | 149 | function contact_user_form(&$edit, &$user, $category = NULL) { |
| 142 | 0 | if ($category == 'account') { |
| 143 | 0 | $form['contact'] = array('#type' => 'fieldset', |
| 144 | 0 | '#title' => t('Contact settings'), |
| 145 | 0 | '#weight' => 5, |
| 146 | 0 | '#collapsible' => TRUE, |
| 147 | | ); |
| 148 | 0 | $form['contact']['contact'] = array('#type' => 'checkbox', |
| 149 | 0 | '#title' => t('Personal contact form'), |
| 150 | 0 | '#default_value' => !empty($edit['contact']) ? $edit['contact'] :
FALSE, |
| 151 | 0 | '#description' => t('Allow other users to contact you by e-mail via
<a href="@url">your personal contact form</a>. Note that while your e-mail
address is not made public to other members of the community, privileged
users such as site administrators are able to contact you even if you
choose not to enable this feature.', array('@url' =>
url("user/$user->uid/contact"))), |
| 152 | | ); |
| 153 | 0 | return $form; |
| 154 | 0 | } |
| 155 | 0 | } |
| 156 | | |
| 157 | | /** |
| 158 | | * Implementation of hook_user_insert(). |
| 159 | | */ |
| 160 | 149 | function contact_user_insert(&$edit, &$user, $category = NULL) { |
| 161 | 2 | $edit['contact'] = variable_get('contact_default_status', 1); |
| 162 | 2 | } |
| 163 | | |
| 164 | | /** |
| 165 | | * Implementation of hook_user_validate(). |
| 166 | | */ |
| 167 | 149 | function contact_user_validate(&$edit, &$user, $category = NULL) { |
| 168 | 0 | return array('contact' => isset($edit['contact']) ? $edit['contact'] :
FALSE); |
| 169 | 0 | } |
| 170 | | |
| 171 | | /** |
| 172 | | * Implementation of hook_mail(). |
| 173 | | */ |
| 174 | 149 | function contact_mail($key, &$message, $params) { |
| 175 | 7 | $language = $message['language']; |
| 176 | | switch ($key) { |
| 177 | 7 | case 'page_mail': |
| 178 | 7 | case 'page_copy': |
| 179 | 3 | $contact = $params['contact']; |
| 180 | 3 | $message['subject'] .= t('[!category] !subject', array('!category' =>
$contact['category'], '!subject' => $params['subject']),
$language->language); |
| 181 | 3 | $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))), $language->language); |
| 182 | 3 | $message['body'][] = $params['message']; |
| 183 | 3 | break; |
| 184 | 7 | case 'page_autoreply': |
| 185 | 3 | $contact = $params['contact']; |
| 186 | 3 | $message['subject'] .= t('[!category] !subject', array('!category' =>
$contact['category'], '!subject' => $params['subject']),
$language->language); |
| 187 | 3 | $message['body'][] = $contact['reply']; |
| 188 | 3 | break; |
| 189 | 4 | case 'user_mail': |
| 190 | 4 | case 'user_copy': |
| 191 | 4 | $user = $params['user']; |
| 192 | 4 | $account = $params['account']; |
| 193 | 4 | $message['subject'] .= '[' . variable_get('site_name', 'Drupal') . ']
' . $params['subject']; |
| 194 | 4 | $message['body'][] = "$account->name,"; |
| 195 | 4 | $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')),
$language->language); |
| 196 | 4 | $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))), $language->language); |
| 197 | 4 | $message['body'][] = t('Message:', NULL, $language->language); |
| 198 | 4 | $message['body'][] = $params['message']; |
| 199 | 4 | break; |
| 200 | 0 | } |
| 201 | 7 | } |
| 202 | 149 | |