function modr8_usermail in modr8 7
Same name and namespace in other branches
- 5 modr8_admin.inc \modr8_usermail()
- 6 modr8_admin.inc \modr8_usermail()
Sending notification to users.
3 calls to modr8_usermail()
- modr8_approve_content in ./
modr8.module - Public API function to approve the given node.
- modr8_delete_content in ./
modr8.module - Public API function to delete the given node.
- modr8_form_submit in ./
modr8_admin.inc - Form submit handler, which approves or deletes the node.
File
- ./
modr8_admin.inc, line 487 - Admin pages for moderation
Code
function modr8_usermail($op, $nid, $values) {
$node = node_load($nid);
if (is_object($node)) {
switch ($op) {
case 'approve':
$subject = variable_get('modr8_accepted_subject', '[%site] %title has been approved');
$message = variable_get('modr8_accepted_text', modr8_accept_default());
$optype = t('approval');
break;
case 'deny':
$subject = variable_get('modr8_denial_subject', '[%site] %title has been denied');
$message = variable_get('modr8_denial_text', modr8_denial_default());
$optype = t('denial');
break;
case 'nada':
$subject = variable_get('modr8_noact_subject', "[%site] note to author about %title");
$message = variable_get('modr8_noact_text', modr8_noact_default());
$optype = t('note (no action)');
break;
}
// get the user info for author
$account = user_load($node->uid);
$note = theme('modr8_note', array(
'0' => $values['note'],
));
$sendmail_from = '';
$site_mail = variable_get('modr8_email_from', '');
if (!$site_mail) {
$sendmail_from = ini_get('sendmail_from');
$site_mail = variable_get('site_mail', $sendmail_from);
}
if (empty($site_mail) || $site_mail == $sendmail_from) {
drupal_set_message(t('You should create an administrator mail address for your site! <a href="@url">Do it here</a>.', array(
'@url' => url('admin/config/site-information'),
)), 'error');
}
// send the email
$language = user_preferred_language($account);
$params = array(
'account' => $account,
'node' => $node,
'subject' => $subject,
'message' => $message,
'note' => $note,
);
if ($account->uid == 0) {
$message = t('Anonymous user; no %type message was sent.', array(
'%type' => $optype,
));
}
else {
$sent = drupal_mail('modr8', 'notify', $account->mail, user_preferred_language($account), $params);
if (!empty($sent['result'])) {
drupal_set_message(t('%type message was sent to %username', array(
'%type' => $optype,
'%username' => $account->name,
)));
$message = filter_xss(nl2br($sent['body']), array(
'br',
'a',
));
// Return sanitized e-mail with HTML breaks added.
}
else {
$message = t('There was a problem sending the %type message to %username', array(
'%type' => $optype,
'%username' => $account->name,
));
drupal_set_message($message, 'error');
}
}
}
else {
$message = t('An error occurred when trying to load this content.');
drupal_set_message($message);
// this probably won't ever get called
}
return $message;
}