function privatemsg_user in Privatemsg 5
Same name and namespace in other branches
- 5.3 privatemsg.module \privatemsg_user()
- 6.2 privatemsg.module \privatemsg_user()
- 6 privatemsg.module \privatemsg_user()
Implementation of hook_user().
File
- ./
privatemsg.module, line 305
Code
function privatemsg_user($type, &$edit, &$account, $category = NULL) {
global $user;
switch ($type) {
case 'load':
_privatemsg_user_add_defaults($account);
break;
case 'view':
if (user_access('access private messages')) {
if (privatemsg_message_allowed($account->uid)) {
$return[t('Private messages')][] = 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',
);
}
if ($account->uid != $user->uid) {
if (!privatemsg_user_blocked($account->uid)) {
$return[t('Private messages')][] = array(
'value' => l(t('Block messages'), 'privatemsg/block/' . $account->uid, array(
'title' => t('Block private messages from @name', array(
'@name' => $account->name,
)),
)),
'class' => 'block-message',
);
}
else {
$return[t('Private messages')][] = array(
'value' => l(t('Unblock messages'), 'privatemsg/block/' . $account->uid, array(
'title' => t('Unblock private messages from @name', array(
'@name' => $account->name,
)),
)),
'class' => 'unblock-message',
);
}
}
return $return;
}
elseif ($user->uid) {
return;
}
elseif ($account->privatemsg_allow) {
if (variable_get('user_register', 1)) {
return array(
t('Private messages') => array(
array(
'value' => t('<a href="!login">login</a> or <a href="!register">register</a> 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('<a href="!login">login</a> 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.'),
);
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;
}
}