function user_stats_nodeapi in User Stats 6
Same name and namespace in other branches
- 5 user_stats.module \user_stats_nodeapi()
Implementation of hook_nodeapi().
Increments post count on insert or publish. Decrements post count on delete or unpublish. Checks and updates users without post counts on view.
Parameters
&$node: The node the action is being performed on.
$op: The operation being performed. We are interested in insert, delete, update and view.
File
- ./
user_stats.module, line 288 - User Stats provides commonly requested user statistics for themers. These are:
Code
function user_stats_nodeapi(&$node, $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;
}
$post_count_content_types = variable_get('user_stats_included_content_types', array());
if ((empty($post_count_content_types) || in_array($node->type, $post_count_content_types)) && variable_get('user_stats_count_posts', TRUE)) {
switch ($op) {
case 'insert':
if ($node->status) {
user_stats_post_count_update('increment', $node->uid);
}
break;
case 'delete':
// Node must be published as unpublished nodes would have already been
// removed from user's post count.
if ($node->status) {
user_stats_post_count_update('decrement', $node->uid);
}
break;
case 'update':
// Can't think of any other way of doing this than resetting the user.
user_stats_post_count_update('reset', $node->uid);
break;
}
}
// Do IP Address update.
switch ($op) {
case 'insert':
case 'update':
global $user;
// User IP addresses are only interesting if they are posting the content.
if ($node->uid == $user->uid) {
user_stats_ip_address_update($user->uid, ip_address());
}
}
}