You are here

function _referral_user_save in User Referral 7

Same name and namespace in other branches
  1. 5 referral.module \_referral_user_save()
  2. 6 referral.module \_referral_user_save()
1 call to _referral_user_save()
referral_user_insert in ./referral.module
Implements hook_user_insert().

File

./referral.module, line 223
The referral module.

Code

function _referral_user_save($uid) {
  $cookie_name = variable_get('referral_cookie_name', REFERRAL_COOKIE_DEFAULT);
  if (!isset($_COOKIE[$cookie_name])) {
    return;
  }

  // Retrieve referral info from the cookie
  $cookie = unserialize($_COOKIE[$cookie_name]);
  if (empty($cookie)) {

    // Nothing to do ...
    return;
  }
  try {
    $query = db_insert('referral')
      ->fields(array(
      'uid' => $uid,
      'referral_uid' => $cookie['uid'],
      'created' => $cookie['timestamp'],
      'host' => $cookie['ip'],
      'http_referer' => $cookie['referer'],
    ))
      ->execute();
  } catch (Exception $e) {
    watchdog_exception('referral', $e);
    return;
  }

  // Invoke other modules hooks ...
  module_invoke_all('referral', $uid, $cookie['uid']);
  if (module_exists('rules')) {
    rules_invoke_event('referral_recorded', user_load($cookie['uid']), user_load($uid));
  }
}