Simpletest Coverage - modules/contact/contact.module

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

Legend

Missed
lines code that were not excersized during program execution.
Covered
lines code were excersized during program execution.
Comment/non executable
Comment or non-executable line of code.
Dead
lines of code that according to xdebug could not be executed. This is counted as coverage code because in almost all cases it is code that runnable.