function user_stats_comment in User Stats 6
Same name and namespace in other branches
- 5 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 344 - 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;
// Bug [#479394] - Anonymous User Comment causes 'UID is not a number'
// errors. User Stats always expects UIDs to be numeric.
if ($comment->uid == NULL) {
$comment->uid = 0;
}
$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)) {
switch ($op) {
case 'insert':
if ($comment->status == COMMENT_PUBLISHED) {
user_stats_post_count_update('increment', $comment->uid);
}
break;
case 'delete':
if ($comment->status == COMMENT_PUBLISHED) {
user_stats_post_count_update('decrement', $comment->uid);
}
break;
case 'update':
user_stats_post_count_update('reset', $comment->uid);
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->uid, ip_address());
}
}