function anonymous_publishing_cl_node_presave in Anonymous Publishing 7
Same name and namespace in other branches
- 8 modules/anonymous_publishing_cl/anonymous_publishing_cl.module \anonymous_publishing_cl_node_presave()
Implements hook_node_presave().
File
- modules/
cl/ anonymous_publishing_cl.module, line 823
Code
function anonymous_publishing_cl_node_presave($node) {
if (!anonymous_publishing_cl_content_type_allowed($node->type)) {
return;
}
if (isset($node->anonymous_publishing['email'])) {
$vrfypers = variable_get('anonymous_publishing_cl_vrfypers', 0);
$mustconfirm = TRUE;
if (2 > $vrfypers) {
$result = db_query("SELECT email, ipaddress, blocked FROM {anonymous_publishing_emails} WHERE email = :email", array(
':email' => $node->anonymous_publishing['email'],
))
->fetchAssoc();
if ($result['email']) {
$ip = ip_address();
if (0 == $vrfypers || 1 == $vrfypers && $ip == $result['ipaddress']) {
// Blocked s. handled by_anonymous_publishing_cl_content_validate().
$node->status = NODE_PUBLISHED;
drupal_set_message(t('Your email has been activated previously.'));
$mustconfirm = FALSE;
}
}
}
if ($mustconfirm) {
$node->status = NODE_NOT_PUBLISHED;
drupal_set_message(t('Thank you for posting here. You must also confirm that @email belongs to you.', array(
'@email' => $node->anonymous_publishing['email'],
)));
}
}
elseif ($node->status) {
// IN AP queue?
$result = db_query("SELECT apid, nid, alias, email, ip FROM {anonymous_publishing} WHERE nid = :nid", array(
':nid' => $node->nid,
))
->fetchAssoc();
if (!$result) {
return;
}
// Do we need to enter an alias?
$usealias = variable_get('anonymous_publishing_cl_alias', 0);
if ($usealias) {
$email = $result['email'] ? $result['email'] : '';
$alias = $result['alias'] ? $result['alias'] : '';
$exists = db_query("SELECT email FROM {anonymous_publishing_emails} WHERE email = :email", array(
':email' => $email,
))
->fetchAssoc();
if (!$exists) {
// Insert the email and alias.
$now = date('Y-m-d');
db_insert('anonymous_publishing_emails')
->fields(array(
'email' => $email,
'alias' => $alias,
'ipaddress' => $result['ip'],
'firstseen' => $now,
'lastseen' => $now,
))
->execute();
}
}
db_update('anonymous_publishing')
->fields(array(
'verified' => 1,
))
->condition('apid', $result['apid'], '=')
->execute();
}
}