You are here

function antispam_content_publish_operation in AntiSpam 7

Same name and namespace in other branches
  1. 6 antispam.module \antispam_content_publish_operation()

Execute content publish/unpublish operations.

Parameters

string $content_type: Content type; it can be 'node' or 'comment' .

object $content: Content object.

string $op: Operation; it can be 'publish' or 'unpublish' .

boolean $log_action: TRUE to log action (default), otherwise the caller logs the action.

5 calls to antispam_content_publish_operation()
antispam_callback_set_published_status in ./antispam.module
Menu callback; publish/unpublish content.
antispam_callback_set_spam_status in ./antispam.module
Menu callback; mark/unmark content as spam.
antispam_confirm_multiple_operation_submit in ./antispam.admin.inc
confirm_form callback; perform the actual operation against selected content.
_antispam_comment_save in ./antispam.module
Called from hook_comment_insert() and hook_comment_update().
_antispam_node_save in ./antispam.module
Called from hook_node_insert() and hook_node_update()

File

./antispam.module, line 1958
Primary hook implementations for the Antispam module.

Code

function antispam_content_publish_operation($content_type, $content, $op, $log_action = TRUE) {
  module_load_include('inc', 'comment', 'comment.admin');
  if ($content_type == 'node') {

    // This code snippet is based on node.module::node_admin_nodes_submit().
    // Only the node record is updated, no other hooks are invoked.
    // Perform the update action.
    db_update('node')
      ->fields(array(
      'status' => $op == 'publish' ? 1 : 0,
    ))
      ->condition('nid', $content->nid)
      ->execute();

    // Perform the update action of the revision.
    db_update('node_revision')
      ->fields(array(
      'status' => $op == 'publish' ? 1 : 0,
    ))
      ->condition('nid', $content->nid)
      ->condition('vid', $content->vid)
      ->execute();

    // Reset the cache for the updated node in order to update the dmin views.
    entity_get_controller('node')
      ->resetCache(array(
      $content->nid,
    ));
    if ($log_action) {
      $action = $op == 'publish' ? t('Content published') : t('Content unpublished');
      watchdog('content', '@action: @title', array(
        '@action' => $action,
        '@title' => $content->title,
      ), WATCHDOG_NOTICE, l(t('view'), 'node/' . $content->nid));
    }
  }
  else {
    if ($op == 'publish') {
      comment_publish_action($content, array(
        'cid' => $content->cid,
      ));
      db_update('comment')
        ->fields(array(
        'status' => COMMENT_PUBLISHED,
      ))
        ->condition('cid', $content->cid)
        ->execute();
      module_invoke_all('comment_published', $content);
    }
    elseif ($op == 'unpublish') {
      comment_unpublish_action($content, array(
        'cid' => $content->cid,
      ));
      db_update('comment')
        ->fields(array(
        'status' => COMMENT_NOT_PUBLISHED,
      ))
        ->condition('cid', $content->cid)
        ->execute();

      // Allow modules to respond to the updating of a comment.
      module_invoke_all('comment_unpublished', $content);
    }

    // Update comment statistics.
    _comment_update_node_statistics($content->nid);
    if ($log_action) {
      $action = $op == 'publish' ? t('Comment published') : t('Comment unpublished');
      watchdog('content', '@action: %subject', array(
        '@action' => $action,
        '%subject' => $content->subject,
      ), WATCHDOG_NOTICE, l(t('view'), 'node/' . $content->nid, array(
        'fragment' => 'comment-' . $content->cid,
      )));
    }
  }
  antispam_clear_cache();
}