array( 'insert' => t('Register'), 'update' => t('Update'), 'login' => t('Login'), 'logout' => t('Logout'), 'view' => t('View'), ), 'types' => array('user' => t('User')), 'roles' => array( 'author' => array( '#name' => t('Author'), '#description' => t('The person creating user activity.'), '#default' => array( 'login' => '[author] logged in to [site-name]', 'logout' => '[author] logged off of [site-name]', 'insert' => '[author] created a new account on [site-name]', 'update' => '[author] updated [possessive] profile', 'view' => '[author] viewed [target-profile]\'s profile', ), ), 'all' => array( '#name' => t('All'), '#description' => t('The general public.'), '#default' => array( 'login' => '[author-all] logged in to [site-name]', 'logout' => '[author-all] logged off of [site-name]', 'insert' => '[author-all] created a new account on [site-name]', 'update' => '[author-all] updated their profile', 'view' => '[author-all] viewed [target-profile]\'s profile', ), ), ), ); } /** * Token module integration. Defines available default tokens. */ function useractivity_token_list($type = 'all') { if ($type == 'useractivity') { $tokens['useractivity'] = array( 'possessive' => t('Possessive pronoun indicating whose user profile page ("your" or "their")'), 'target-uid' => t('User Id of the user profile viewed if viewing a profile'), 'target-profile' => t('Person whose user profile was viewed'), 'target-profile-name' => t('The username of the person whose profile was viewed'), ); return $tokens; } } /** * Token module integration. Defines available default token values. */ function useractivity_token_values($type, $data = NULL, $options = array()) { global $user; static $authors; if ($type == 'useractivity' && !empty($data)) { if (!isset($authors[$data['target-uid']])) { $authors[$data['target-uid']] = activity_user_load($data['target-uid']); } $target = $authors[$data['target-uid']]; $data['possessive'] = ($user->uid == $data['uid']) ? t('your') : t('their'); $data['target-profile'] = theme('activity_username', $target); $data['target-profile-name'] = $target->name; return $data; } } /** * Implementation of hook_user(). */ 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; } }