From 24dfee093604672fef36fabfb53dec70232faa13 Mon Sep 17 00:00:00 2001
From: amontero <amontero@166637.no-reply.drupal.org>
Date: Tue, 27 Aug 2013 13:21:10 +0200
Subject: [PATCH] Add Token module support (provide tokens).

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

diff --git a/contactinfo.module b/contactinfo.module
index 2ad0d71..030ab17 100644
--- a/contactinfo.module
+++ b/contactinfo.module
@@ -440,6 +440,57 @@ function contactinfo_coord_convert($decimal, $direction) {
   return $coord_direction . ' ' . $coord_degrees . '° ' . $coord_minutes . '"';
 }
 
+function contactinfo_token_info() {
+  $types = array(
+    'contactinfo' => array(
+      'name' =>  t('Contact Info tokens'),
+      'description' => t('Tokens provided by the Contact Info module.'),
+    ),
+  );
+
+  $tokens['location-latitude'] = array(
+    'name' => t('Latitude'),
+    'description' => t('Latitude'),
+  );
+  $tokens['location-longitude'] = array(
+    'name' => t('Longitude'),
+    'description' => t('Longitude'),
+  );
+
+  return array(
+    'types' => $types,
+    'tokens' => array(
+      'contactinfo' => $tokens,
+    ),
+  );
+}
+
+/**
+ * Implements hook_tokens().
+ */
+function contactinfo_tokens($type, $tokens, array $data = array(), array $options = array()){
+  $replacements = array();
+  $sanitize = !empty($options['sanitize']);
+
+  if ($type == 'contactinfo') {
+    $contactinfo = contactinfo_get_contactinfo();
+    foreach ($tokens as $name => $original) {
+      switch ($name) {
+        case 'location-latitude':
+          $var = $contactinfo['location']['latitude'];
+          $replacements[$original] = $sanitize ? check_plain($var) : $var;
+          break;
+        case 'location-longitude':
+          $var = $contactinfo['location']['longitude'];
+          $replacements[$original] = $sanitize ? check_plain($var) : $var;
+          break;
+      }
+    }
+  }
+
+  return $replacements;
+}
+
 /**
  * Helper function to return saved contact information.
  *
-- 
1.8.3.4

