function anonymous_publishing_cl_comment_presave in Anonymous Publishing 7
Same name and namespace in other branches
- 8 modules/anonymous_publishing_cl/anonymous_publishing_cl.module \anonymous_publishing_cl_comment_presave()
Implements hook_comment_presave().
File
- modules/
cl/ anonymous_publishing_cl.module, line 766
Code
function anonymous_publishing_cl_comment_presave($comment) {
if (isset($comment->anonymous_publishing['email'])) {
$mustconfirm = TRUE;
$vrfypers = variable_get('anonymous_publishing_cl_vrfypers', 0);
if (2 > $vrfypers) {
$result = db_query("SELECT email, ipaddress, blocked FROM {anonymous_publishing_emails} WHERE email = :email", array(
':email' => $comment->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().
$comment->status = COMMENT_PUBLISHED;
drupal_set_message(t('Your email has been activated previously.'));
$mustconfirm = FALSE;
}
}
}
if ($mustconfirm) {
$comment->status = COMMENT_NOT_PUBLISHED;
drupal_set_message(t('Thank you for posting here. You must also confirm that @email belongs to you.', array(
'@email' => $comment->anonymous_publishing['email'],
)));
}
}
elseif ($comment->status) {
// Do not insert here if it is not in {anonymous_publishing} yet.
$result = db_query("SELECT apid, nid, cid, alias, email, ip FROM {anonymous_publishing} WHERE cid = :cid", array(
':cid' => $comment->cid,
))
->fetchAssoc();
if ($result) {
$alias = $result['alias'] ? $result['alias'] : '';
$usealias = variable_get('anonymous_publishing_cl_alias', 0);
if ($usealias) {
$email = $result['email'];
$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();
}
}