diff -r 07239de796bb -r e756a8c72c3d cms/drupal/modules/contact/contact.module --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/drupal/modules/contact/contact.module Fri Sep 08 12:04:06 2017 +0200 @@ -0,0 +1,266 @@ +' . t('About') . ''; + $output .= '
' . t('The Contact module allows visitors to contact site administrators and other users. Users specify a subject, write their message, and can have a copy of their message sent to their own e-mail address. For more information, see the online handbook entry for Contact module.', array('@contact' => 'http://drupal.org/documentation/modules/contact/')) . '
'; + $output .= '' . t('Add one or more categories on this page to set up your site-wide contact form.', array('@form' => url('contact'))) . '
'; + $output .= '' . t('A Contact menu item (disabled by default) is added to the Navigation menu, which you can modify on the Menus administration page.', array('@menu-settings' => url('admin/structure/menu'))) . '
'; + $output .= '' . t('If you would like additional text to appear on the site-wide contact page, use a block. You can create and edit blocks on the Blocks administration page.', array('@blocks' => url('admin/structure/block'))) . '
'; + return $output; + } +} + +/** + * Implements hook_permission(). + */ +function contact_permission() { + return array( + 'administer contact forms' => array( + 'title' => t('Administer contact forms and contact form settings'), + ), + 'access site-wide contact form' => array( + 'title' => t('Use the site-wide contact form'), + ), + 'access user contact forms' => array( + 'title' => t("Use users' personal contact forms"), + ), + ); +} + +/** + * Implements 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'), + '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'), + '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 + * The user object of the user whose contact form is being requested. + */ +function _contact_personal_tab_access($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->data['contact'])) { + return FALSE; + } + + // If requested user has been blocked, do not allow users to contact them. + if (empty($account->status)) { + return FALSE; + } + + return user_access('access user contact forms'); +} + +/** + * Loads a contact category. + * + * @param $cid + * The contact category ID. + * + * @return + * An array with the contact category's data. + */ +function contact_load($cid) { + return db_select('contact', 'c') + ->addTag('translatable') + ->fields('c') + ->condition('cid', $cid) + ->execute() + ->fetchAssoc(); +} + +/** + * Implements 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('Hello !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; + } +} + +/** + * Implements hook_form_FORM_ID_alter(). + * + * Add the enable personal contact form to an individual user's account page. + * + * @see user_profile_form() + */ +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->data['contact']) ? $account->data['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"))), + ); + } +} + +/** + * Implements hook_user_presave(). + */ +function contact_user_presave(&$edit, $account, $category) { + if (isset($edit['contact'])) { + // Set new value. + $edit['data']['contact'] = $edit['contact']; + } + elseif (!isset($account->data['contact'])) { + // Use default if none has been set. + $edit['data']['contact'] = variable_get('contact_default_status', 1); + } +} + +/** + * Implements hook_form_FORM_ID_alter(). + * + * Add the default personal contact setting on the user settings page. + * + * @see user_admin_settings() + */ +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' => variable_get('contact_default_status', 1), + ); +}