<?php
/*
 * @file
 * Provide libraries for the google ajax APIs
 * @see googleapilibs.info
 */

/**
 * Implements hook_menu().
 */
function googleapilibs_menu() {
  $menu['admin/config/googleapilibs'] = array(
    'title' => 'Google API Libs',
    'description' => 'Configuration page for the google api libs module.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('googleapilibs_settings_form'),
    'access arguments' => array('administer modules'),
  );
  return $menu;
}

/**
 * Adming settings form for google api libs module
 */
function googleapilibs_settings_form() {
  $form['googlapilbs_api_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Google AJAX API Key'),
    '#default_value' => variable_get('googlapilbs_api_key', ''),
    '#required' => TRUE,
    '#description' => t('To use the Google AJAX API, you need to sign up for a key <a href="http://code.google.com/apis/ajaxsearch/signup.html">here</a>'),
  );
  return system_settings_form($form);
}

/**
 * Define the libraries.
 */

function googleapilibs_library() {
  // Only return libraries if the API key has been set.
  $api_key = variable_get('googlapilbs_api_key', '');
  $libraries = array();
  if ( strlen($api_key) > 0) {
    $path_with_key = 'http://www.google.com/jsapi?key=' . $api_key;
    // Google AJAX loader.
    $libraries['google_ajax'] = array(
      'title' => t('Google AJAX API'),
      'website' => 'http://code.google.com/apis/ajax/',
      'version' => '1',
      'js' => array(
        $path_with_key => array('type' => 'external', 'cache' => TRUE),
      ),
    );

    //Google Maps.
    $libraries['google_maps'] = array(
      'title' => t('Google Maps API'),
      'website' => 'http://code.google.com/apis/maps/documentation/javascript/',
      'version' => '2',
      'js' => array(
        'google.load("maps", "2");' =>  array('type' => 'inline', 'cache' => FALSE),
      ),
      'dependencies' => array(
        array('googleapilibs', 'google_ajax'),
      ),
    );

    // Google Search.
    $libraries['google_search'] = array(
      'title' => t('Google AJAX Search API'),
      'website' => 'http://code.google.com/apis/ajaxsearch/',
      'version' => '1',
      'js' => array(
        'google.load("search", "1");' =>  array('type' => 'inline', 'cache' => FALSE),
      ),
      'dependencies' => array(
        array('googleapilibs', 'google_ajax'),
      ),
    );

    // RSS.
    $libraries['google_feeds'] = array(
      'title' => t('Google AJAX Feeds API'),
      'website' => 'http://code.google.com/apis/ajaxsearch/',
      'version' => '1',
      'js' => array(
        'google.load("feeds", "1");' =>  array('type' => 'inline', 'cache' => FALSE),
      ),
      'dependencies' => array(
        array('googleapilibs', 'google_ajax'),
      ),
    );

    // Language.
    $libraries['google_language'] = array(
      'title' => t('Google AJAX Language API'),
      'website' => 'http://code.google.com/apis/ajaxlanguage/',
      'version' => '1',
      'js' => array(
        'google.load("language", "1");' =>  array('type' => 'inline', 'cache' => FALSE),
      ),
      'dependencies' => array(
        array('googleapilibs', 'google_ajax'),
      ),
    );

    // Data.
    $libraries['google_data'] = array(
      'title' => t('Google Data APIs'),
      'website' => 'http://code.google.com/apis/gdata/client-js.html',
      'version' => '1',
      'js' => array(
        'google.load("gdata", "1");' =>  array('type' => 'inline', 'cache' => FALSE),
      ),
      'dependencies' => array(
        array('googleapilibs', 'google_ajax'),
      ),
    );

    // Google Earth.
    $libraries['google_earth'] = array(
      'title' => t('Google Earth API'),
      'website' => 'http://code.google.com/apis/earth/documentation/',
      'version' => '1',
      'js' => array(
        'google.load("earth", "1");' =>  array('type' => 'inline', 'cache' => FALSE),
      ),
      'dependencies' => array(
        array('googleapilibs', 'google_ajax'),
      ),
    );

    // Visualization.
    $libraries['google_visualization'] = array(
      'title' => t('Google Visualization API'),
      'website' => 'http://code.google.com/apis/visualization/documentation/dev/index.html',
      'version' => '1',
      'js' => array(
        'google.load("visualization", "1", {"packages":["corechart"]});' =>  array('type' => 'inline', 'cache' => FALSE),
      ),
      'dependencies' => array(
        array('googleapilibs', 'google_ajax'),
      ),
    );

    // Friend Connect.
    $libraries['google_friendconnect'] = array(
      'title' => t('Google Friend Connect API'),
      'website' => 'http://code.google.com/apis/friendconnect/',
      'version' => '1',
      'js' => array(
        'google.load("friendconnect", "1");' =>  array('type' => 'inline', 'cache' => FALSE),
      ),
      'dependencies' => array(
        array('googleapilibs', 'google_ajax'),
      ),
    );

    // Orkut.
    $libraries['google_orkut'] = array(
      'title' => t('Orkut API'),
      'website' => 'http://code.google.com/apis/orkut/',
      'version' => '1',
      'js' => array(
        'google.load("orkut", "1");' =>  array('type' => 'inline', 'cache' => FALSE),
      ),
      'dependencies' => array(
        array('googleapilibs', 'google_ajax'),
      ),
    );
  }
  return $libraries;
}
