From 35e67f9a248e7f7884b445c7ecffcd375b96d97a Mon Sep 17 00:00:00 2001
From: amontero <amontero@166637.no-reply.drupal.org>
Date: Fri, 23 Aug 2013 03:20:29 +0200
Subject: [PATCH] Initial support for system-wide tokens.

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

diff --git a/locationmap.module b/locationmap.module
index 5ae0a42..851a94b 100644
--- a/locationmap.module
+++ b/locationmap.module
@@ -501,6 +501,57 @@ 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'),
+  );
+  $tokens['longitude'] = array(
+    'name' => 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

