'. t('The private messaging module allows users to send messages to each other without having to share email addresses. An inbox link will appear in the navigation menu. The "write to author" links are included in posts, allowing users to write a private message instead of commenting openly. Allowing users to communicate directly is an important part of building the strength of the community.') .'
';
$output .= '
'. t('Users can also select whether to receive email notices of new messages by editing their user profile. The contacts list contains only users that you have previously messaged. To contact users not in your list, you need to know their local user name. Administrators can set messaging options such as frequency of emails, message status display, and number of messages to display per page. They can also configure \'Write to Author\' options.') .'
'. t('For more information please read the configuration and customization handbook Privatemsg page.', array('!privatemsg' => 'http://drupal.org/handbook/modules/privatemsg/')) .'
';
return $output;
}
}
/**
* Implementation of hook_link().
*/
function privatemsg_link($type, $node = NULL, $teaser = FALSE) {
global $user;
static $access = array();
$links = array();
$uid = $node->uid;
if ($type == 'comment' && $node->nid) {
$node = node_load($node->nid);
}
if (user_access('access private messages') && in_array($teaser ? 'teaser' : $type, variable_get('privatemsg_link_'. $node->type, array())) && $uid != $user->uid && $user->privatemsg_allow) {
if (!isset($access[$uid])) {
$author = user_load(array('uid' => $uid));
$access[$uid] = user_access('access private messages', $author) && $author->uid && $author->privatemsg_allow;
}
if ($access[$uid]) {
$links['privatemsg_write_to_author'] = array(
'title' => t('Write to author'),
'href' => 'privatemsg/new/'. $uid,
);
}
}
return $links;
}
/**
* Implementation of hook_user().
*/
function privatemsg_user($type, &$edit, &$account, $category = NULL) {
switch ($type) {
case 'load':
_privatemsg_user_add_defaults($account);
break;
case 'view':
if (user_access('access private messages') && $account->privatemsg_allow) {
return array(t('Private messages') => array(array(
'value' => l(t('Write private message'), 'privatemsg/new/'. $account->uid, array(
'title' => t('Send private message to @name', array('@name' => $account->name)))),
'class' => 'send-message')));
}
else if ($GLOBALS['user']->uid) {
return;
}
else if ($account->privatemsg_allow) {
if (variable_get('user_register', 1)) {
return array(t('Private messages') => array(array(
'value' => t('login or register to send private messages to this user', array('!login' => url('user/login'), '!register' => url('user/register'))),
'class' => 'need-login')));
}
else {
return array(t('Private messages') => array(array(
'value' => t('login to send private messages to this user', array('!login' => url('user/login'))),
'class' => 'need-login')));
}
}
break;
case 'form':
if (user_access('access private messages') && $category == 'account') {
$form = array();
$form['privatemsg_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Private message settings'),
'#weight' => 4,
'#collapsible' => TRUE
);
$form['privatemsg_settings']['privatemsg_allow'] = array(
'#type' => 'checkbox',
'#title' => t('Allow private messages'),
'#default_value' => isset($edit['privatemsg_allow']) ? $edit['privatemsg_allow'] : 1,
'#description' => t('Check this box to allow users to send you private messages.')
);
$form['privatemsg_settings']['privatemsg_setmessage_notify'] = array(
'#type' => 'checkbox',
'#title' => t('Aggressive notification of new messages'),
'#default_value' => isset($edit['privatemsg_setmessage_notify']) ? $edit['privatemsg_setmessage_notify'] : 1,
'#description' => t('Show status message on every page until new messages are read.')
);
$form['privatemsg_settings']['privatemsg_mailalert'] = array(
'#type' => 'radios',
'#title' => t('Receive e-mail for unread messages'),
'#options' => array(PRIVATEMSG_MAIL_NONE => t('Never'), PRIVATEMSG_MAIL_DIGEST => t('Daily'), PRIVATEMSG_MAIL_INDIVIDUAL => t('Every message')),
'#default_value' => isset($edit['privatemsg_mailalert']) ? $edit['privatemsg_mailalert'] : PRIVATEMSG_MAIL_NONE,
'#description' => t('Select when to receive e-mail notification for unread messages.')
);
return $form;
}
break;
case 'insert':
if ($welcome_message = trim(variable_get('privatemsg_welcome_message', ''))) {
$subject = variable_get('privatemsg_welcome_subject', t('Welcome'));
$format = variable_get('privatemsg_welcome_format', FILTER_FORMAT_DEFAULT);
$sender = user_load(array('uid' => variable_get('privatemsg_welcome_sender', 1)));
if ($sender->uid) {
_privatemsg_send($sender, $account, $subject, $welcome_message, $format);
}
}
break;
case 'delete':
db_query('DELETE FROM {privatemsg} WHERE recipient = %d', $account->uid);
db_query('DELETE FROM {privatemsg_archive} WHERE recipient = %d', $account->uid);
db_query('DELETE FROM {privatemsg_folder} WHERE uid = %d', $account->uid);
db_query('UPDATE {privatemsg} SET author = 0 WHERE author = %d', $account->uid);
db_query('UPDATE {privatemsg_archive} SET author = 0 WHERE author = %d', $account->uid);
break;
}
}
function _privatemsg_user_add_defaults(&$account) {
if (!isset($account->privatemsg_mailalert)) {
$account->privatemsg_mailalert = variable_get('privatemsg_default_mailalert', PRIVATEMSG_MAIL_NONE);
$account->privatemsg_allow = variable_get('privatemsg_default_allow', 1);
$account->privatemsg_setmessage_notify = variable_get('privatemsg_default_setmessage_notify', 1);
}
}
/**
* Implementation of hook_form_alter().
*/
function privatemsg_form_alter($form_id, &$form) {
if ($form_id == 'node_type_form') {
$link = variable_get('privatemsg_link_'. $form['#node_type']->type, array());
$form['workflow']['privatemsg_link'] = array(
'#type' => 'checkboxes',
'#title' => t('Private message "Write to author" links'),
'#weight' => 30,
'node' => array(
'#type' => 'checkbox',
'#title' => t('Link on node'),
'#default_value' => in_array('node', $link),
),
'teaser' => array(
'#type' => 'checkbox',
'#title' => t('Link on teaser'),
'#default_value' => in_array('teaser', $link),
),
'comment' => array(
'#type' => module_exists('comment') ? 'checkbox' : 'hidden',
'#title' => t('Link on comments'),
'#default_value' => in_array('comment', $link),
),
);
}
}
/**
* Implementation of hook_block().
*/
function privatemsg_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$blocks[0]['info'] = t('Private messages');
return $blocks;
}
else if ($op == 'view') {
switch ($delta) {
case 0:
return _privatemsg_block_inbox();
}
}
}
/**
* Implementation of hook_mail_alter().
*/
function privatemsg_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers) {
$message_types = variable_get('privatemsg_mail_types', array());
if (isset($message_types[$mailkey])) {
}
}
function _privatemsg_block_inbox() {
global $user;
if ($user->uid && user_access('access private messages') && $user->privatemsg_allow) {
$new = _privatemsg_get_new_messages();
$items = array(
l(t('Inbox') . ($new ? " ($new)" : ''), 'privatemsg'),
l(t('Write message'), 'privatemsg/new'),
);
$block['subject'] = t('Private messages');
$block['content'] = theme('item_list', $items);
return $block;
}
}
function privatemsg_configure() {
$form['privatemsg_max_rate'] = array(
'#type' => 'select',
'#title' => t('Private messaging max rate'),
'#default_value' => variable_get('privatemsg_max_rate', 15),
'#options' => drupal_map_assoc(array(5, 10, 15, 20, 30, 60), 'format_interval'),
'#description' => t('Max submit rate for private messaging. To prevent abuse.'),
);
$form['privatemsg_sent_status'] = array(
'#type' => 'select',
'#title' => t('Sent message status'),
'#default_value' => variable_get('privatemsg_sent_status', 1),
'#options' => array(t('Disabled'), t('Enabled')),
'#description' => t('If enabled users can see whether a message has been read or not.'),
);
$form['privatemsg_per_page'] = array(
'#type' => 'select',
'#title' => t('Messages per page'),
'#default_value' => variable_get('privatemsg_per_page', 10),
'#options' => drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100)),
'#description' => t('The maximum number of messages displayed per page; links to browse messages automatically appear.'),
);
$form['privatemsg_menu_link'] = array(
'#type' => 'textfield',
'#title' => t('Menu link'),
'#default_value' => variable_get('privatemsg_menu_link', t('My inbox')),
'#description' => t("Text shown in link to user's inbox."),
);
$options = array(
'1' => t('Above the message'),
'2' => t('Below the message'),
'3' => t('Above and below the message'),
'4' => t('Neither (show the old links)'),
);
$form['privatemsg_view_actions'] = array(
'#type' => 'radios',
'#title' => t('Display action form on view screens'),
'#description' => t('Choose where to display the actions form on the view message screen.'),
'#options' => $options,
'#default_value' => variable_get('privatemsg_view_actions', '3'),
);
$options = array(
'1' => t('Before other buttons'),
'2' => t('After other buttons'),
);
$form['privatemsg_delete_loc'] = array(
'#type' => 'radios',
'#title' => t('Display delete button'),
'#description' => t('Choose where to display the delete button on the actions form.'),
'#options' => $options,
'#default_value' => variable_get('privatemsg_delete_loc', '1'),
);
$form['privatemsg_threaded_view'] = array(
'#type' => 'radios',
'#title' => t('How messages are displayed on the detail screen'),
'#description' => t('You can choose between displaying a thread of messages (like for example on facebook) or just a single message.'),
'#options' => array(t('Single message'), t('Full thread')),
'#default_value' => variable_get('privatemsg_threaded_view', 0),
);
$form['links'] = array(
'#type' => 'fieldset',
'#title' => t('"Write to author" links'),
'#description' => t('Edit content types to select where these links are displayed.', array('!settings-url' => url('admin/content/types'))),
);
$form['welcome'] = array(
'#type' => 'fieldset',
'#title' => t('Welcome message for new users'),
);
$form['welcome']['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#default_value' => variable_get('privatemsg_welcome_subject', t('Welcome')),
'#size' => 50,
'#maxlength' => 64,
);
$form['welcome']['privatemsg_welcome_message'] = array(
'#type' => 'textarea',
'#title' => t('Message'),
'#default_value' => variable_get('privatemsg_welcome_message', ''),
'#cols' => 80,
'#rows' => 5,
'#description' => t('Leave blank to disable this feature.'),
);
$form['welcome'][] = filter_form(variable_get('privatemsg_welcome_format', FILTER_FORMAT_DEFAULT));
$sender = user_load(array('uid' => variable_get('privatemsg_welcome_sender', 1)));
$form['welcome']['privatemsg_welcome_sender'] = array(
'#type' => 'textfield',
'#title' => t('Sender'),
'#default_value' => $sender->name,
'#autocomplete_path' => 'privatemsg/autocomplete',
'#size' => 50,
'#maxlength' => 64,
'#required' => TRUE,
);
$form['admin_default'] = array(
'#type' => 'fieldset',
'#title' => t('Default user settings'),
'#description' => 'Set the default values for user settings. These can be changed by each user.',
'#collapsible' => TRUE,
);
$form['admin_default']['privatemsg_default_allow'] = array(
'#type' => 'checkbox',
'#title' => t("'Allow private messages' default"),
'#default_value' => variable_get('privatemsg_default_allow', 1),
'#description' => t("Check this box to set the default value of the 'Allow private messages' user setting."),
);
$form['admin_default']['privatemsg_default_setmessage_notify'] = array(
'#type' => 'checkbox',
'#title' => t("'Aggressive notification of new messages' default"),
'#default_value' => variable_get('privatemsg_default_setmessage_notify', 1),
'#description' => t("Check this box to set the default value of the 'Aggressive notification of new messages' user setting."),
);
$form['admin_default']['privatemsg_default_mailalert'] = array(
'#type' => 'radios',
'#title' => t("'Receive e-mail for unread messages' default"),
'#options' => array(PRIVATEMSG_MAIL_NONE => t('Never'), PRIVATEMSG_MAIL_DIGEST => t('Daily'), PRIVATEMSG_MAIL_INDIVIDUAL => t('Every message')),
'#default_value' => variable_get('privatemsg_default_mailalert', PRIVATEMSG_MAIL_NONE),
'#description' => t("Check this box to set the default value of the 'Receive e-mail for unread messages' user setting.")
);
return system_settings_form($form);
}
function privatemsg_configure_validate($form_id, $form_values, $form) {
if (!empty($form_values['privatemsg_welcome_sender'])) {
$sender = user_load(array('name' => $form_values['privatemsg_welcome_sender']));
if ($sender->uid) {
form_set_value($form['welcome']['privatemsg_welcome_sender'], $sender->uid);
}
else {
form_set_error('privatemsg_welcome_sender', t('The Sender does not exist.'));
}
}
}
function privatemsg_list($uid = NULL) {
if (!empty($uid) && is_numeric($uid) && user_access('administer private messages')) {
$account = user_load(array('uid' => $uid));
}
else {
$account = $GLOBALS['user'];
}
// Notification emails link here, but the user may not be logged in yet.
if (!$account->uid) {
drupal_goto('user/login', 'destination=privatemsg');
}
if (!user_access('access private messages') || !$account->privatemsg_allow) {
return drupal_access_denied();
}
$current_folder = intval(arg(2));
if ($current_folder != 1) {
$result = pager_query('SELECT id, subject, p.timestamp, u.uid, u.name, newmsg FROM {privatemsg} p, {users} u WHERE p.author = u.uid AND p.recipient = %d AND folder = %d AND p.recipient_del = 0 ORDER BY p.timestamp DESC', variable_get('privatemsg_per_page', 10), 0, NULL, $account->uid, $current_folder);
if ($current_folder > 0) {
$folder_name = db_result(db_query('SELECT name FROM {privatemsg_folder} WHERE fid = %d AND uid = %d', $current_folder, $account->uid));
}
else {
$folder_name = t('Inbox');
}
}
else {
// sent messages
$result = pager_query('SELECT id, subject, p.timestamp, u.uid, u.name, newmsg FROM {privatemsg} p, {users} u WHERE p.recipient = u.uid AND p.author = %d AND p.author_del = 0 ORDER BY p.timestamp DESC', variable_get('privatemsg_per_page', 10), 0, NULL, $account->uid);
$folder_name = t('Sent messages');
}
$messages = array();
while ($message = db_fetch_object($result)) {
$messages[] = $message;
}
$folders = privatemsg_load_folders($account->uid);
$output = drupal_get_form('privatemsg_cur_folder_form', $folders, $current_folder);
$output .= drupal_get_form('privatemsg_list_form', $messages, $folders, $current_folder);
return $output;
}
function privatemsg_cur_folder_form($folders, $current_folder) {
foreach ($folders as $folder) {
$options[$folder['fid']] = $folder['name'];
}
$form['folder_select'] = array(
'#type' => 'select',
'#title' => t('Current folder'),
'#options' => $options,
'#default_value' => $current_folder,
'#attributes' => array('class' => 'pm-add-folder-select'),
'#prefix' => '',
);
return $form;
}
function privatemsg_cur_folder_form_submit($form_id, $form_values) {
$redirect = 'privatemsg';
if ($form_values['folder_select'] || is_numeric(arg(1))) {
$redirect .= '/'. (is_numeric(arg(1)) ? arg(1) : 'list');
if ($form_values['folder_select']) {
$redirect .= '/'. $form_values['folder_select'];
}
}
return $redirect;
}
function privatemsg_list_form($messages, $folders, $current_folder) {
global $user;
$extra_folders = array();
foreach ($folders as $folder) {
if ($folder['fid'] != 1 && $folder['fid'] != $current_folder) {
$extra_folders[$folder['fid']] = $folder['name'];
}
}
$extra_folders['new'] = t('New folder...');
$form['messages'] = array(
'#theme' => 'privatemsg_message_table',
'#tree' => TRUE
);
$form['messages']['current_folder'] = array(
'#type' => 'value',
'#value' => $current_folder
);
foreach ($messages as $message) {
if ($current_folder != 1) {
$new = $message->newmsg;
$new_text = theme('mark');
}
else {
$new = variable_get('privatemsg_sent_status', 1) ? $message->newmsg : 0;
$new_text = ' '. t('unread') .'';
}
$form['messages'][$message->id]['selected'] = array(
'#type' => 'checkbox',
);
$form['messages'][$message->id]['user'] = array(
'#type' => 'value',
'#value' => theme('username', $message),
);
$form['messages'][$message->id]['subject'] = array(
'#type' => 'value',
'#value' => l($message->subject, 'privatemsg/view/'. $message->id) . ($new ? (' '. $new_text) : ''),
);
$form['messages'][$message->id]['date'] = array(
'#type' => 'value',
'#value' => format_date($message->timestamp, 'small'),
);
}
$form[] = array(
'#value' => theme('pager', array(), variable_get('privatemsg_per_page', 10)),
);
if (count($messages) > 0) {
$form['selected'] = array(
'#type' => 'fieldset',
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#prefix' => '