You are here

function radioactivity_node_user_node_view in Radioactivity 6

Gives energy to node, if abuse control is passed.

2 calls to radioactivity_node_user_node_view()
radioactivity_node_ajax_callback in plugins/radioactivity_node.module
AJAX Menu Callback.
radioactivity_node_exit in plugins/radioactivity_node.module

File

plugins/radioactivity_node.module, line 99
Node radioactivity

Code

function radioactivity_node_user_node_view($nid) {
  global $user;
  if (_radioactivity_node_get_click_duration() > 0) {
    $nid = (int) $nid;
    $uid = $user->uid;
    $sid = session_id();
    $remote_address = $_SERVER['REMOTE_ADDR'];

    // check if click is found
    if ($user->uid > 0) {

      // not anonymous: use nid/sid
      $result = db_query("SELECT count(*) FROM {radioactivity_node_clicks} WHERE nid=%d AND sid='%s'", $nid, $sid);
    }
    else {

      // anonymous, use nid/sid or nid/hostname
      $result = db_query("SELECT count(*) FROM {radioactivity_node_clicks} WHERE nid=%d AND (sid='%s' OR hostname='%s')", $nid, $sid, $remote_address);
    }
    $passed = 0 == db_result($result);
    if ($passed) {

      // ok, record click
      db_query("INSERT INTO {radioactivity_node_clicks} (nid, sid, hostname, click_timestamp) " . "VALUES (%d, '%s', '%s', %d)", $nid, $sid, $remote_address, time());
    }
    else {

      // don't add energy, because click was found
      return FALSE;
    }
  }

  // ok, abuse control passed
  if (!function_exists('radioactivity_add_energy')) {

    // load radioactivity.inc, because radioactivity_add_energy does not exist
    $radioactivity_inc = substr(drupal_get_filename('module', 'radioactivity'), 0, -6) . 'inc';
    require_once $radioactivity_inc;
  }
  radioactivity_add_energy($nid, 'node', 'view');
  if ($user->uid > 0) {
    radioactivity_add_energy($nid, 'node', 'view_auth');
  }
  return TRUE;
}