function _anonymous_publishing_node_insert in Anonymous Publishing 5
Node API insert helper.
Parameters
$node: The node object.
1 call to _anonymous_publishing_node_insert()
- anonymous_publishing_nodeapi in ./
anonymous_publishing.module - Implementation of hook_node_api().
File
- ./
anonymous_publishing.module, line 263 - Installation file for the anonymous_publishing module.
Code
function _anonymous_publishing_node_insert(&$node) {
global $user;
if ($user->uid) {
db_query("INSERT INTO {anonymous_publishing} (nid, uid, anonymous) VALUES (%d, %d, %d)", $node->nid, $user->uid, $node->anonymous_publishing['options']);
}
else {
$akey = uniqid(md5(uniqid(mt_rand(), TRUE)), TRUE);
db_query("INSERT INTO {anonymous_publishing} (nid, uid, akey, email, anonymous) VALUES (%d, %d, '%s', '%s', 1)", $node->nid, $user->uid, $akey, $node->anonymous_publishing['email']);
$variables = array(
'!site' => variable_get('site_name', 'Drupal'),
'!title' => check_plain($node->title),
'!nid' => $node->nid,
'!activation_uri' => url('node/' . $node->nid . '/activate', "akey={$akey}", NULL, TRUE),
'!view_uri' => url('node/' . $node->nid . '/view', NULL, NULL, TRUE),
'!edit_uri' => url('node/' . $node->nid . '/edit/' . $akey, NULL, NULL, TRUE),
'!delete_uri' => url('node/' . $node->nid . '/delete/' . $akey, NULL, NULL, TRUE),
);
$to = $node->anonymous_publishing['email'];
$subject = _anonymous_publishing_email_text('subject', $variables);
$body = _anonymous_publishing_email_text('body', $variables);
$from = variable_get('site_mail', ini_get('sendmail_from'));
$mail_success = drupal_mail('anonymous_publishing_verification', $to, $subject, $body, $from);
if ($mail_success) {
drupal_set_message(t('Activation link and further instructions have been sent to your e-mail address.'));
}
else {
watchdog('anonymous_publishing', t('Error mailing activation link.'), WATCHDOG_ERROR);
drupal_set_message(t('Unable to send mail. Please contact the site admin.'));
}
}
}