You are here

function adsense_get_client_id in Google AdSense integration 5

Same name and namespace in other branches
  1. 5.2 adsense.module \adsense_get_client_id()
4 calls to adsense_get_client_id()
adsense_nodeapi in ./adsense.module
Implemenation of hook_nodeapi().
_adsense_check_if_enabled in ./adsense.module
_adsense_format in ./adsense.module
_adsense_get_searchbox in ./adsense.module

File

./adsense.module, line 1509

Code

function adsense_get_client_id() {
  static $client = false;
  if ($client) {

    // Use the cached client id
    return $client;
  }

  // Get the site wide client ID
  $site_client = _adsense_get_site_owner_client_id();

  // Check if revenue sharing is enabled
  $revenue = variable_get(ADSENSE_REVENUE_ENABLE, 0);
  if (!$revenue) {

    // If not enabled, cache the site wide client ID
    return $site_client;
  }

  // Revenue sharing is enabled, need to now the node
  $path = explode('/', drupal_get_normal_path($_GET['q']));
  if (is_array($path) && $path[0] == 'node' && is_numeric($path[1])) {
    $node = node_load($path[1]);
  }
  else {
    return $site_client;
  }

  // Check the content type we are displaying
  $content = variable_get(ADSENSE_NODE_TYPE . $node->type, 0);
  if (!$content) {

    // Revenue sharing is disabled for this content, use the site wide client id
    $client = $site_client;
    return $client;
  }

  // Check the percentage and choose one
  $client = _adsense_choose_client($node->uid);
  return $client;
}