Index: gmaplocation.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmaplocation/gmaplocation.module,v
retrieving revision 1.1.6.20
diff -u -p -r1.1.6.20 gmaplocation.module
--- gmaplocation.module 19 Sep 2010 08:13:50 -0000 1.1.6.20
+++ gmaplocation.module 5 Oct 2010 19:44:52 -0000
@@ -146,6 +146,7 @@ function gmaplocation_admin_settings() {
'#title' => t('Google Maps API key'),
'#collapsible' => TRUE,
'#collapsed' => variable_get('gmaplocation_key', FALSE));
+ if (!module_exists('keys_api') && !module_exists('keys')) {
$form['keys']['gmaplocation_key'] = array(
'#type' => 'textfield',
'#title' => t('API key'),
@@ -154,6 +155,17 @@ function gmaplocation_admin_settings() {
'#description' => t('Google Maps key for your domain.') . " " .
t('Obtain key on !url', array('!url' => l('http://code.google.com/apis/maps/signup.html', 'http://code.google.com/apis/maps/signup.html')))
);
+ } else {
+ $form['keys']['gmaplocation_key_show'] = array(
+ '#type' => 'item',
+ '#title' => t('Google Maps API Key'),
+ '#value' => t('Managed by Keys.', array('@url' => url('admin/settings/keys'))),
+ );
+ $form['keys']['gmaplocation_key'] = array(
+ '#type' => 'value',
+ '#default_value' => gmaplocation_get_key(),
+ );
+ }
$form['#validate'][] = 'gmaplocation_admin_settings_validate';
return system_settings_form($form);
@@ -200,7 +212,7 @@ function gmaplocation_page() {
$gmaplocation_body = variable_get('gmaplocation_body', '');
$gmaplocation_footer = variable_get('gmaplocation_footer', '');
$path = drupal_get_path('module', 'gmaplocation');
- $gmap_key = variable_get('gmaplocation_key', NULL);
+ $gmap_key = gmaplocation_get_key();
drupal_set_html_head('');
drupal_add_js($path . '/gmaplocation.js');
$gmaplocation_settings = array(
@@ -334,7 +346,7 @@ function gmaplocation_static_image_url($
$image_url = 'http://maps.google.com/staticmap?zoom=' . variable_get('gmaplocation_zoom', 5);
$image_url .= "&size={$w}x{$h}";
$image_url .= '&markers=' . variable_get('gmaplocation_lat', 0) . ','. variable_get('gmaplocation_lng', 0);
- $image_url .= '&key=' . variable_get('gmaplocation_key', NULL);
+ $image_url .= '&key=' . gmaplocation_get_key();
return($image_url);
}
@@ -374,4 +386,55 @@ function gmaplocation_theme() {
'gmaplocation_map' => array(),
);
}
-
+
+
+/**
+ * Implementation of hook_keys_service(). (from the keys api)
+ */
+function gmaplocation_keys_service() {
+ // @@@ Remove after everyone has upgraded.
+ if (module_exists('keys_api')) {
+ return array(
+ 'gmap' => array(
+ 'name' => t('Gmap'),
+ 'description' => t('Google Maps API Key'),
+ ),
+ );
+ }
+ elseif (module_exists('keys')) {
+ // @greenSkin:
+ // What is your reasoning behind predefining this?
+ // I'll avoid overriding you for now, but this seems rather arbitrary.
+ // Reference: http://drupal.org/cvs?commit=310498
+
+ // Probe keys to determine if it is defining our key for us.
+ $test = array();
+ if (function_exists('keys_keys_service')) {
+ $test = keys_keys_service();
+ }
+ if (!isset($test['google_maps'])) {
+ // Be forward compatible with future versions of keys api
+ // that no longer define it.
+ return array(
+ 'google_maps' => array(
+ 'name' => t('Google Maps'),
+ 'description' => t('Google Maps API Key'),
+ ),
+ );
+ }
+ }
+}
+
+/**
+ * Retrieve the Google Maps key that is in use for the site.
+ */
+function gmaplocation_get_key() {
+ $key = variable_get('gmaplocation_key', '');
+ if (module_exists('keys_api')) {
+ $key = keys_api_get_key('gmap', $_SERVER['HTTP_HOST']);
+ }
+ elseif (module_exists('keys')) {
+ $key = keys_get_key('google_maps');
+ }
+ return $key;
+}