You are here

adsense_basic.module in Google AdSense integration 5.2

File

adsense_basic.module
View source
<?php

// Copyright 2005-2008 Khalid Baheyeldin http://2bits.com
define('ADSENSE_BASIC_ID', 'adsense_basic_id');
define('ADSENSE_BASIC_ERROR_NOT_CONFIGURED', 1);
function adsense_basic_adsense($op, $args = array()) {
  switch ($op) {
    case 'status':
      $error_flag = FALSE;
      if (!variable_get(ADSENSE_BASIC_ID, '')) {
        adsense_basic_error(ADSENSE_BASIC_ERROR_NOT_CONFIGURED);
        $error_flag = TRUE;
      }
      return $error_flag;
    case 'settings':
      return adsense_basic_settings();
    case 'client_id':
      return adsense_basic_client_id();
  }
}
function adsense_basic_settings() {

  // We only load the help text if we are in settings, to save memory
  $module = 'adsense_basic';
  include_once drupal_get_path('module', $module) . '/' . $module . '_help.inc';
  $function = $module . '_adsense';
  $error_flag = $function('status');
  $form['help'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Help and instructions'),
  );
  $help_function = $module . '_help_text';
  $form['help']['help'] = array(
    '#type' => 'markup',
    '#value' => $help_function(),
  );
  $form[ADSENSE_BASIC_ID] = array(
    '#type' => 'textfield',
    '#title' => t('Google AdSense client ID'),
    '#required' => TRUE,
    '#default_value' => variable_get(ADSENSE_BASIC_ID, ''),
    '#description' => t('This is the Google AdSense Client ID for the site owner. You should get this from your Google Adsense account. It should be similar to <em>pub-9999999999999</em>.'),
  );
  return $form;
}
function adsense_basic_client_id() {
  $client = variable_get(ADSENSE_BASIC_ID, '');
  return $client;
}
function adsense_basic_error($code) {
  switch ($code) {
    case ADSENSE_BASIC_ERROR_NOT_CONFIGURED:
      $text = t('Adsense basic is not correctly configured. Please check your settings.');
      break;
    default:
      $text = t('Unknown Adsense basic error.');
      break;
  }
  drupal_set_message($text, 'error');
}