You are here

function revenue_sharing_basic_choose_client in Google AdSense integration 5.3

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

Provide the applicable Publisher ID, based on the configured probabilities

Parameters

$format: Format of the ad

Return value

If format is set, returns NULL. Otherwise, based on the configured percentage, returns either the Publisher ID of the current page's author or of the owner of the site. When configured, it may also return the Publisher ID of the user who referred the page author.

1 call to revenue_sharing_basic_choose_client()
revenue_sharing_basic_adsense in old/revenue_sharing_basic/revenue_sharing_basic.module
Interface of the Publisher ID modules

File

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

Code

function revenue_sharing_basic_choose_client($format) {
  global $user;
  if (isset($format)) {

    // This module can't handle the selection of an appropriate Slot ID
    // Give up!
    return NULL;
  }
  $site_client = variable_get('adsense_basic_id', ADSENSE_BASIC_ID_DEFAULT);
  $info = revenue_sharing_basic_get_node_info();
  if (empty($info) || !variable_get('revenue_sharing_basic_node_type_' . $info['type'], REVENUE_SHARING_BASIC_NODE_TYPE_DEFAULT)) {
    return $site_client;
  }
  $percents[0] = variable_get('revenue_sharing_basic_percentage_author', REVENUE_SHARING_BASIC_PERCENTAGE_AUTHOR_DEFAULT);
  $author_user = user_load(array(
    'uid' => $info['uid'],
  ));
  foreach ($author_user->roles as $role => $role_desc) {
    $percents[$role] = variable_get('revenue_sharing_basic_percentage_role_' . $role, REVENUE_SHARING_BASIC_PERCENTAGE_ROLE_DEFAULT);
  }
  arsort($percents);
  $percent_author = array_shift($percents);
  $percent_referral = variable_get('revenue_sharing_basic_percentage_refer', REVENUE_SHARING_BASIC_PERCENTAGE_REFER_DEFAULT);

  // Toss the dice and see who gets their ad displayed
  $random = mt_rand(1, 100);
  if ($random <= $percent_author) {
    $client = revenue_sharing_basic_get_profile_client_id($info['uid']);
  }
  elseif ($random <= $percent_author + $percent_referral) {
    $client = revenue_sharing_basic_get_referral_client_id($info['uid']);
  }
  else {
    $client = $site_client;
  }

  // Last check to see that we have a valid client
  // Check that the current user doesn't view ads with it's own Publisher ID
  if (!$client || $client == revenue_sharing_basic_get_profile_client_id($user->uid)) {
    $client = $site_client;
  }
  return $client;
}