You are here

function user_stats_comment in User Stats 5

Same name and namespace in other branches
  1. 6 user_stats.module \user_stats_comment()

Implementation of hook_comment().

Increments post count on insert or publish. Decrements post count on delete or unpublish. Updates users with no post count on view.

Parameters

$a1: Either the form values being submitted, the module form to be displayed, or the comment object.

$op: What kind of action is being performed.

File

./user_stats.module, line 384
User Stats provides commonly requested user statistics for themers. These are:

Code

function user_stats_comment(&$a1, $op) {

  // We stop before any work is done if the $op isn't one of the ones we need.
  if (!in_array($op, array(
    'insert',
    'delete',
    'update',
  ))) {
    return;
  }

  // check to see if comments should be counted at all.
  if (variable_get('user_stats_count_comments', TRUE)) {
    $comment = (object) $a1;
    $post_count_content_types = variable_get('user_stats_included_content_types', array());
    $node = node_load(array(
      'nid' => $comment->nid,
    ));
    if ((empty($post_count_content_types) || in_array($node->type, $post_count_content_types)) && variable_get('user_login_count', TRUE)) {
      switch ($op) {
        case 'insert':
          $user = user_stats_user_load($comment->uid);
          user_stats_post_count_update($user, 'increment');
          break;
        case 'delete':
          $user = user_stats_user_load($comment->uid);
          user_stats_post_count_update($user, 'decrement');
          break;
        case 'update':
          $user_comment = user_stats_user_load($comment->uid);
          user_stats_post_count_update($user_comment, 'reset');
          break;
      }
    }
  }

  // Do IP address update.
  global $user;
  if ($op == 'insert' && $comment->uid == $user->uid) {

    // User IP addresses are only interesting if they are posting the content.
    user_stats_ip_address_update($user, $_SERVER['REMOTE_ADDR']);
  }
}