You are here

function revenue_sharing_basic_get_profile_client_id in Google AdSense integration 7

Same name and namespace in other branches
  1. 5.3 old/revenue_sharing_basic/revenue_sharing_basic.module \revenue_sharing_basic_get_profile_client_id()
  2. 5.2 revenue_sharing_basic.module \revenue_sharing_basic_get_profile_client_id()
  3. 6 old/revenue_sharing_basic/revenue_sharing_basic.module \revenue_sharing_basic_get_profile_client_id()

Provide the Publisher ID of the the specified user.

Parameters

int $uid: User ID.

Return value

mixed Publisher ID of the specified user in case it applies, otherwise NULL

2 calls to revenue_sharing_basic_get_profile_client_id()
revenue_sharing_basic_choose_client in old/revenue_sharing_basic/revenue_sharing_basic.module
Provide the applicable Publisher ID, based on the configured probabilities.
revenue_sharing_basic_get_referral_client_id in old/revenue_sharing_basic/revenue_sharing_basic.module
Provide the Publisher ID of the user of referred the specified user.

File

old/revenue_sharing_basic/revenue_sharing_basic.module, line 157
Main file of the revenue_sharing_basic module.

Code

function revenue_sharing_basic_get_profile_client_id($uid) {
  $client_id = NULL;

  // Get the profile field for a certain user.
  $profile_field = explode(':', variable_get('revenue_sharing_basic_client_id_profile_field', REVENUE_SHARING_BASIC_CLIENT_ID_PROFILE_FIELD_DEFAULT));
  if ($uid && count($profile_field) > 1 && module_exists($profile_field[0])) {
    $user = user_load($uid);
    switch ($profile_field[0]) {
      case 'field':
        $fields = field_get_items('user', $user, $profile_field[1]);
        $value = field_view_value('user', $user, $profile_field[1], $fields[0]);
        $client_id = render($value);
        break;
      case 'profile':
        $client_id = isset($user->{$profile_field[1]}) ? $user->{$profile_field[1]} : NULL;
        break;
      case 'profile2':
        $profile = profile2_load_by_user($user);
        $items = field_get_items('profile2', $profile[$profile_field[1]], $profile_field[2]);
        $client_id = drupal_render(field_view_value('profile2', $profile[$profile_field[1]], $profile_field[2], $items[0]));
        break;
    }
  }
  return $client_id;
}