You are here

function anonymous_publishing_cl_activate in Anonymous Publishing 7

Activate a node or comment published anonymously.

Parameters

int $apid: The apid to activate.

1 call to anonymous_publishing_cl_activate()
anonymous_publishing_cl_admin_unverified_submit in modules/cl/anonymous_publishing_cl.admin.inc
Submit for the notify_admin_unverified form.

File

modules/cl/anonymous_publishing_cl.module, line 367

Code

function anonymous_publishing_cl_activate($apid) {
  $result1 = db_query("SELECT nid, cid, alias, email FROM {anonymous_publishing} WHERE apid = :apid", array(
    ':apid' => $apid,
  ))
    ->fetchAssoc();
  $nid = $result1['nid'];
  $cid = $result1['cid'];
  $wish = $result1['alias'];
  $email = $result1['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();

  // Insert it.
  $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('apid', $apid, '=')
    ->execute();
  $fields = array();
  if (!empty($alias)) {
    $fields['alias'] = $alias;
  }
  $fields['ipaddress'] = ip_address();
  db_update('anonymous_publishing_emails')
    ->fields($fields)
    ->condition('email', $email, '=')
    ->execute();

  // Activate.
  drupal_set_message(t('The anonymously published posting(s) has been activated.'));
  if ($cid) {
    $comm_obj = comment_load($cid, TRUE);
    comment_publish_action($comm_obj);
    comment_save($comm_obj);
  }
  else {
    $node_obj = node_load($nid, NULL, TRUE);
    node_publish_action($node_obj);
    node_save($node_obj);
  }
}