function userpoints_nodeapi in User points Nodes and Comments 6
File
- ./userpoints_nc.module, line 130
Code
function userpoints_nodeapi(&$node, $op, $teaser, $page) {
static $up_orig_uid;
$points = variable_get(USERPOINTS_POST . $node->type, 0);
$tid = variable_get(USERPOINTS_POST . $node->type . '_category', 0);
switch ($op) {
case 'insert':
$params = array(
'points' => $points,
'tid' => $tid,
'uid' => $node->uid,
'operation' => 'insert',
'entity_id' => $node->nid,
'entity_type' => 'node',
);
userpoints_userpointsapi($params);
break;
case 'delete':
if (variable_get(USERPOINTS_POST . '_undo_points_on_delete', true)) {
$points = -$points;
$params = array(
'points' => $points,
'tid' => $tid,
'uid' => $node->uid,
'operation' => 'delete',
'entity_id' => $node->nid,
'entity_type' => 'node',
);
userpoints_userpointsapi($params);
}
break;
case 'prepare':
$up_orig_uid = $node->uid;
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 ";
$last_owner = db_fetch_object(db_query($sql, $node->nid, 'node', 'insert', 'Ownership gain'));
if ($node->uid != $last_owner->uid && is_numeric($last_owner->uid)) {
$params = array(
'points' => $points,
'tid' => $tid,
'uid' => $node->uid,
'operation' => 'Ownership gain',
'entity_id' => $node->nid,
'entity_type' => 'node',
);
userpoints_userpointsapi($params);
$params = array(
'points' => -$points,
'tid' => $tid,
'uid' => $last_owner->uid,
'operation' => 'Ownership loss',
'entity_id' => $node->nid,
'entity_type' => 'node',
);
userpoints_userpointsapi($params);
}
else {
if (variable_get(USERPOINTS_USE_V2BUG, false)) {
if ($node->uid != $up_orig_uid) {
$params = array(
'points' => $points,
'tid' => $tid,
'uid' => $node->uid,
'operation' => 'Ownership gain',
'entity_id' => $node->nid,
'entity_type' => 'node',
);
userpoints_userpointsapi($params);
$params = array(
'points' => -$points,
'tid' => $tid,
'uid' => $up_orig_uid,
'operation' => 'Ownership loss',
'entity_id' => $node->nid,
'entity_type' => 'node',
);
userpoints_userpointsapi($params);
}
}
}
break;
}
}