function userpoints_comment in User points Nodes and Comments 6
File
- ./userpoints_nc.module, line 232
Code
function userpoints_comment($comment, $op) {
global $user;
static $up_orig_com_uid;
$points = variable_get(USERPOINTS_POST_COMMENT, 0);
$tid = variable_get(USERPOINTS_POST_COMMENT . '_category', 0);
switch ($op) {
case 'insert':
$params = array(
'points' => $points,
'tid' => $tid,
'uid' => $user->uid,
'operation' => 'insert',
'entity_id' => $comment['cid'],
'entity_type' => 'comment',
);
userpoints_userpointsapi($params);
break;
case 'delete':
$points = -$points;
$params = array(
'points' => $points,
'tid' => $tid,
'uid' => $comment->uid,
'operation' => 'delete',
'entity_id' => $comment->cid,
'entity_type' => 'comment',
);
userpoints_userpointsapi($params);
break;
case 'moderate':
$points = variable_get(USERPOINTS_MODERATE_COMMENT, 0);
$tid = variable_get(USERPOINTS_MODERATE_COMMENT . '_category', 0);
$params = array(
'points' => $points,
'tid' => $tid,
'uid' => $comment->uid,
'operation' => 'moderate',
'entity_id' => $comment->cid,
'entity_type' => 'comment',
);
userpoints_userpointsapi($params);
break;
case 'form':
$up_orig_com_uid = $comment['uid']['#value'];
break;
case 'update':
$sql = "SELECT points, uid \n FROM {userpoints_txn} \n WHERE entity_id = %d AND entity_type = '%s' \n AND (operation = '%s' OR operation ='%s')\n ORDER BY time_stamp DESC\n LIMIT 1\n ";
$cid = $comment['cid'];
$new_uid = $comment['uid'];
$last_owner = db_fetch_object(db_query($sql, $cid, 'comment', 'insert', 'Ownership gain'));
if ($new_uid != $last_owner->uid && is_numeric($last_owner->uid)) {
$points = $last_owner->points;
$params = array(
'points' => $points,
'tid' => $tid,
'uid' => $new_uid,
'operation' => 'Ownership gain',
'entity_id' => $cid,
'entity_type' => 'comment',
);
userpoints_userpointsapi($params);
$params = array(
'points' => -$points,
'tid' => $tid,
'uid' => $last_owner->uid,
'operation' => 'Ownership loss',
'entity_id' => $cid,
'entity_type' => 'comment',
);
userpoints_userpointsapi($params);
}
else {
if (variable_get(USERPOINTS_USE_V2BUG, false)) {
if ($orig_uid != $comment['uid']) {
$params = array(
'points' => $points,
'tid' => $tid,
'uid' => $new_uid,
'operation' => 'Ownership gain',
'entity_id' => $cid,
'entity_type' => 'comment',
);
userpoints_userpointsapi($params);
$params = array(
'points' => -$points,
'tid' => $tid,
'uid' => $comment['uid'],
'operation' => 'Ownership loss',
'entity_id' => $new_uid,
'entity_type' => 'comment',
);
userpoints_userpointsapi($params);
}
}
}
break;
}
}