From d049d9b9e16ad02a7e9537ecf061efdce619f7cf Mon Sep 17 00:00:00 2001
From: amontero <amontero@166637.no-reply.drupal.org>
Date: Mon, 26 Aug 2013 20:06:19 +0200
Subject: [PATCH] Add Token module support for latitude and longitude.

---
 locationmap.module | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/locationmap.module b/locationmap.module
index 5ae0a42..ae1ebc6 100644
--- a/locationmap.module
+++ b/locationmap.module
@@ -501,6 +501,59 @@ function locationmap_block_image() {
 }
 
 /**
+ * Implements hook_token_info().
+ */
+function locationmap_token_info() {
+  $types = array(
+    'locationmap' => array(
+      'name' =>  t('Location Map tokens'),
+      'description' => t('Tokens provided by the Location Map module.'),
+    ),
+  );
+
+  $tokens['latitude'] = array(
+    'name' => t('Latitude'),
+    'description' => t('Latitude'),
+  );
+  $tokens['longitude'] = array(
+    'name' => t('Longitude'),
+    'description' => t('Longitude'),
+  );
+
+  return array(
+    'types' => $types,
+    'tokens' => array(
+      'locationmap' => $tokens,
+    ),
+  );
+}
+
+/**
+ * Implements hook_tokens().
+ */
+function locationmap_tokens($type, $tokens, array $data = array(), array $options = array()){
+  $replacements = array();
+  $sanitize = !empty($options['sanitize']);
+
+  if ($type == 'locationmap') {
+    foreach ($tokens as $name => $original) {
+      switch ($name) {
+        case 'latitude':
+          $lat = variable_get('locationmap_lat');
+          $replacements[$original] = $sanitize ? check_plain($lat) : $lat;
+          break;
+        case 'longitude':
+          $lat = variable_get('locationmap_lng');
+          $replacements[$original] = $sanitize ? check_plain($lat) : $lat;
+          break;
+      }
+    }
+  }
+
+  return $replacements;
+}
+
+/**
  * Format static image for display in the block.
  * @ingroup themeable
  */
-- 
1.8.3.4

