You are here

function antispam_content_publish_operation in AntiSpam 6

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

Execute content publish/unpublish operations.

Parameters

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

object Content object.:

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

boolean TRUE to log action (default); FALSE otherwise (ie. 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_nodeapi in ./antispam.module
Implementation of hook_nodeapi().
_antispam_comment_form_submit in ./antispam.module
Comment form submit callback; check for spam.

File

./antispam.module, line 1830

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_query('UPDATE {node} SET status = %d WHERE nid = %d', $op == 'publish' ? 1 : 0, $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 {

    // comment
    // This code snippet is based on comment.module::comment_admin_overview_submit()
    // Cache operations in case we need to come here more than once per request.
    static $comment_operations = FALSE;
    if (!$comment_operations) {
      $comment_operations = comment_operations();
    }

    // extract the appropriate database query operation.
    $query = $comment_operations[$op][1];

    // perform the update action, then refresh node statistics.
    db_query($query, $content->cid);

    // Update comment statistics.
    _comment_update_node_statistics($content->nid);

    // Allow modules to respond to the updating of a comment.
    comment_invoke_comment($content, $op);
    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();
}