You are here

function anonymous_publishing_cl_verify in Anonymous Publishing 7

Page callback: Activate a node or comment published anonymously.

This is the page callback for the link sent to the user by email to activate the node.

Parameters

object $node: Node.

1 string reference to 'anonymous_publishing_cl_verify'
anonymous_publishing_cl_menu in modules/cl/anonymous_publishing_cl.admin.inc
Implements hook_menu().

File

modules/cl/anonymous_publishing_cl.module, line 438

Code

function anonymous_publishing_cl_verify(stdClass $node) {
  if (isset($_GET['akey'])) {
    $akey = $_GET['akey'];
  }
  else {
    drupal_set_message(t('No activation key present.'));
    drupal_goto();
  }

  // Do the key exist?
  $result1 = db_query("SELECT nid, cid, akey, alias, verified, email FROM {anonymous_publishing} WHERE akey = :akey", array(
    ':akey' => $akey,
  ))
    ->fetchAssoc();
  $nid = $result1['nid'];
  $cid = $result1['cid'];
  $rkey = $result1['akey'];
  $wish = $result1['alias'];
  $vfied = $result1['verified'];
  $email = $result1['email'];
  $at = $akey[0];
  if ($akey != $rkey) {
    drupal_set_message(t('Invalid activation key.'), 'error');
    drupal_goto();
  }
  if ($vfied) {
    drupal_set_message(t('Stale activation key.'), 'error');
    drupal_goto();
  }
  $found = FALSE;
  $result = db_query("SELECT email, blocked FROM {anonymous_publishing_emails} WHERE email = :email", array(
    ':email' => $email,
  ));
  $aliasopt = variable_get('anonymous_publishing_cl_alias', 0);
  if (1 == $aliasopt) {
    $auid = db_next_id(db_query('SELECT MAX(auid) FROM {anonymous_publishing_emails}')
      ->fetchField());
    $alias = 'user' . $auid;
  }
  elseif (2 == $aliasopt || 3 == $aliasopt) {
    $alias = $wish;
  }
  else {
    $alias = '';
  }
  $ip = ip_address();
  if ($result) {
    $row = $result
      ->fetchAssoc();
    $found = $row['email'];
  }

  // Insert it (unless blocked).
  if ($found) {
    if ($row['blocked']) {

      // Hand-moderate if already blocked.
      $at = 'V';
    }
  }
  else {
    $now = date('Y-m-d');
    $auid = db_insert('anonymous_publishing_emails')
      ->fields(array(
      'email' => $email,
      'alias' => $alias,
      'ipaddress' => $ip,
      'firstseen' => $now,
      'lastseen' => $now,
    ))
      ->execute();
  }
  db_update('anonymous_publishing')
    ->fields(array(
    'verified' => 1,
  ))
    ->condition('akey', $akey, '=')
    ->execute();
  $fields = array();
  if (!empty($alias)) {
    $fields['alias'] = $alias;
  }
  $fields['ipaddress'] = ip_address();
  db_update('anonymous_publishing_emails')
    ->fields($fields)
    ->condition('email', $email, '=')
    ->execute();
  $vfymsg = t('Thanks for verifying your e-mail,');
  if ('V' == $at) {
    drupal_set_message($vfymsg . ' ' . t('your content will be published when it has been approved by an administrator.'));
    drupal_goto();
  }
  else {

    // Activate (unless comment moderation).
    if ($cid && user_access('skip comment approval')) {
      $comm_obj = comment_load($cid, TRUE);
      comment_publish_action($comm_obj);
      comment_save($comm_obj);
      drupal_set_message($vfymsg . ' ' . t('your comment has been published and will appear on the site soon.'));
      drupal_goto('comment/' . $cid, array(
        'fragment' => 'comment-' . $cid,
      ));
    }
    elseif ($cid) {
      drupal_set_message($vfymsg . ' ' . t('your comment will be published when it has been approved by an administrator.'));
      drupal_goto();
    }
    else {
      $node_obj = node_load($nid, NULL, TRUE);
      node_publish_action($node_obj);
      node_save($node_obj);
      drupal_set_message($vfymsg . ' ' . t('your content has been published and will appear on the site soon.'));
      if (node_access('view', $node_obj)) {
        drupal_goto('node/' . $nid . '/view');
      }
    }
  }
}