You are here

function useractivity_user in Activity 5.4

Same name and namespace in other branches
  1. 6 contrib/useractivity/useractivity.module \useractivity_user()

Implementation of hook_user().

File

contrib/useractivity/useractivity.module, line 82

Code

function useractivity_user($op, &$edit, &$account, $category = NULL) {
  global $user;
  switch ($op) {
    case 'insert':
    case 'update':
    case 'login':
    case 'logout':
    case 'view':

      // don't record if new user requires admin approval
      if ($op == 'insert' && variable_get('user_register', 1) != 1) {
        return FALSE;
      }

      // check if action is not done by the $account-uid such
      // as if user is edited by admin
      if ($op == 'update' && $user->uid != $account->uid) {
        return FALSE;
      }

      // Check if both type and operation are
      // enabled for activity. If not then stop here
      if (!in_array('user', variable_get('useractivity_token_types', array(
        'user',
      )), TRUE) || !in_array($op, variable_get('useractivity_op_types', array(
        $op,
      )), TRUE)) {
        return FALSE;
      }

      // Privacy setting check
      if (activity_user_privacy_optout($op == 'view' ? $user : $account)) {
        return FALSE;
      }

      // If $op is view and user is viewing their own profile don't record
      if ($op == 'view' && $user->uid == $account->uid) {
        return FALSE;
      }
      $data = array(
        'operation' => $op,
        'target-uid' => $account->uid,
      );
      $target_users_roles = array(
        ACTIVITY_ALL => 'all',
        $user->uid => 'author',
      );
      activity_insert($user->uid, 'useractivity', 'user', $op, $data, $target_users_roles);
      break;
  }
}