You are here

function google_analytics_counter_auth_admin_submit in Google Analytics Counter 7.2

Same name and namespace in other branches
  1. 7.3 google_analytics_counter_auth.inc \google_analytics_counter_auth_admin_submit()

Submit handler. Steps through the OAuth process, revokes tokens, saves profiles.

File

./google_analytics_counter_auth.inc, line 143
Provides the GAFeed object type and associated methods.

Code

function google_analytics_counter_auth_admin_submit($form, &$form_state) {
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
  cache_clear_all('GAFeed', 'cache', '*');
  switch ($op) {
    case t('Start setup and authorize account'):
      variable_set('google_analytics_counter_hd', $form_state['values']['google_analytics_counter_hd']);

      /* Anonymous keys are a Google default */
      $key = variable_get('google_analytics_counter_consumer_key', 'anonymous');
      $secret = variable_get('google_analytics_counter_consumer_secret', 'anonymous');
      module_load_include('inc', 'google_analytics_counter', 'GAFeed.lib');
      $GAFeed = new GAFeed($key, $secret);

      /* Step #1 of OAuth */
      $token = $GAFeed
        ->getRequestToken();
      $_SESSION['google_analytics_counter_oauth']['token'] = $token;
      $_SESSION['google_analytics_counter_oauth']['destination'] = $_GET['q'];

      /* Step #2 of OAuth */
      $GAFeed
        ->obtainAuthorization($token);

      //dpm($GAFeed);
      break;
    case t('Save settings'):
      variable_set('google_analytics_counter_profile_id', $form_state['values']['google_analytics_counter_profile_id']);
      drupal_set_message(t('Settings have been saved successfully.'));
      break;
    case t('Revoke access token'):
      google_analytics_counter_revoke();
      drupal_set_message(t('Access token has been successfully revoked.'));
      break;
  }
}