? token-DRUPAL-5.patch
Index: token.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/Attic/token.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 token.inc
--- token.inc	10 Mar 2007 22:17:48 -0000	1.1.2.1
+++ token.inc	12 Mar 2007 18:13:04 -0000
@@ -59,6 +59,9 @@ function token_get_values($type = 'globa
   if (module_exists('content')) {
     include_once(drupal_get_path('module', 'token') . '/token_cck.inc');
   }
+  if (module_exists('profile')) {
+    include_once(drupal_get_path('module', 'token') . '/token_profile.inc');
+  }
 
   if (!isset($tokens)) {
     $tokens = array();
@@ -156,7 +159,8 @@ function _token_get_id($type = 'global',
     case 'comment':
       return $object->cid;
     case 'user':
-      return $user->uid;
+    case 'profile':
+      return $object->uid;
     default:
       return md5(serialize($object));
   }
Index: token.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/token.module,v
retrieving revision 1.5.2.5
diff -u -p -r1.5.2.5 token.module
--- token.module	10 Mar 2007 22:17:48 -0000	1.5.2.5
+++ token.module	12 Mar 2007 17:27:55 -0000
@@ -34,6 +34,9 @@ function theme_token_help($type = 'all',
   if (module_exists('content')) {
     include_once(drupal_get_path('module', 'token') . '/token_cck.inc');
   }
+  if (module_exists('profile')) {
+    include_once(drupal_get_path('module', 'token') . '/token_profile.inc');
+  }
 
   $full_list = token_get_list($type);
   
Index: token_profile.inc
===================================================================
RCS file: token_profile.inc
diff -N token_profile.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ token_profile.inc	12 Mar 2007 17:30:06 -0000
@@ -0,0 +1,71 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_token_values()
+ */
+function profile_token_values($type, $object = NULL) {
+  $values = array();
+  if ($type == 'profile') {
+    if (isset($object)) {
+      $account = $object;
+    }
+    else {
+      global $user;
+      $account = $user;
+    }
+
+    $result = db_query('SELECT f.name, f.title, f.type, v.value FROM {profile_fields} f INNER JOIN {profile_values} v ON f.fid = v.fid WHERE uid = %d', $account->uid);
+    while ($field = db_fetch_object($result)) {
+      if (_profile_field_serialize($field->type)) {
+        $field->value = unserialize($field->value);
+      }
+      $values[$field->name] = _profile_token_format_field($field);
+    }
+  }
+  return $values;
+}
+
+/**
+ * Implementation of hook_token_list()
+ */
+function profile_token_list($type = 'all') {
+  if ($type == 'profile' || $type == 'all') {
+    $result = db_query('SELECT name, title FROM {profile_fields}');
+    while ($field = db_fetch_object($result)) {
+      $tokens['profile'][$field->name] = $field->title;
+    }
+    return $tokens;
+  }
+}
+
+function _profile_token_format_field($field) {
+  switch ($field->type) {
+    case 'checkbox':
+      return check_plain($field->title);
+    case 'date':
+      $format = substr(variable_get('date_format_short', 'm/d/Y - H:i'), 0, 5);
+      // Note: Avoid PHP's date() because it does not handle dates before
+      // 1970 on Windows. This would make the date field useless for e.g.
+      // birthdays.
+      $replace = array('d' => sprintf('%02d', $field->value['day']),
+                       'j' => $field->value['day'],
+                       'm' => sprintf('%02d', $field->value['month']),
+                       'M' => map_month($field->value['month']),
+                       'Y' => $field->value['year'],
+                       'H:i' => NULL,
+                       'g:ia' => NULL);
+      return strtr($format, $replace);
+    case 'list':
+      $values = split("[,\n\r]", $field->value);
+      $fields = array();
+      foreach ($values as $value) {
+        if ($value = trim($value)) {
+          $fields[] = check_plain($value);
+        }
+      }
+      return implode(', ', $fields);
+    default:
+      return check_plain($field->value);
+  }
+}
\ No newline at end of file
