content_profile_tokens.module

Tracking 6.x-1.x branch
  1. drupal
    1. 6 contributions/content_profile/modules/content_profile_tokens.module

Implementations of token module hooks for the content profile module.

Functions & methods

NameDescription
content_profile_tokens_token_listImplementation of hook_token_list().
content_profile_tokens_token_valuesImplementation of hook_token_values().

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Implementations of token module hooks for the content profile module.
  5. *
  6. * @ingroup token
  7. */
  8. /**
  9. * Implementation of hook_token_values().
  10. */
  11. function content_profile_tokens_token_values($type, $object = NULL, $options = array()) {
  12. $values = array();
  13. $types = content_profile_get_types('types');
  14. switch ($type) {
  15. case 'user':
  16. foreach($types as $type_name => $type) {
  17. if (isset($object)) {
  18. $profile = content_profile_load($type_name, $object->uid);
  19. }
  20. else {
  21. global $user;
  22. $profile = content_profile_load($type_name, $user->uid);
  23. }
  24. $fields = content_types($type_name);
  25. foreach ($fields['fields'] as $field_name => $field) {
  26. if (!$field['multiple'] && ($field['widget']['type'] == 'text_textfield' || $field['widget']['type'] == 'number')) {
  27. $values['content-profile-'. $type_name .'-'. substr($field_name, 6)] = check_plain($profile->{$field_name}[0]['value']);
  28. $values['content-profile-'. $type_name .'-'. substr($field_name, 6) .'-raw'] = $profile->{$field_name}[0]['value'];
  29. }
  30. }
  31. }
  32. break;
  33. case 'flag_friend':
  34. if(!empty($object)) {
  35. foreach($types as $type_name => $type) {
  36. $profile_requestor = content_profile_load($type_name, $object->friend->uid);
  37. $profile_requestee = content_profile_load($type_name, $object->uid);
  38. $fields = content_types($type_name);
  39. foreach ($fields['fields'] as $field_name => $field) {
  40. if (!$field['multiple'] && ($field['widget']['type'] == 'text_textfield' || $field['widget']['type'] == 'number')) {
  41. $values['requestor-'. $type_name .'-'. substr($field_name, 6)] = check_plain($profile_requestor->{$field_name}[0]['value']);
  42. $values['requestor-'. $type_name .'-'. substr($field_name, 6) .'-raw'] = $profile_requestor->{$field_name}[0]['value'];
  43. $values['requestee-'. $type_name .'-'. substr($field_name, 6)] = check_plain($profile_requestee->{$field_name}[0]['value']);
  44. $values['requestee-'. $type_name .'-'. substr($field_name, 6) .'-raw'] = $profile_requestee->{$field_name}[0]['value'];
  45. }
  46. }
  47. }
  48. }
  49. break;
  50. }
  51. return $values;
  52. }
  53. /**
  54. * Implementation of hook_token_list().
  55. */
  56. function content_profile_tokens_token_list($type = 'all') {
  57. $tokens = array();
  58. if ($type == 'user' || $type == 'all') {
  59. $types = content_profile_get_types('types');
  60. foreach ($types as $type_name => $type) {
  61. $fields = content_types($type_name);
  62. foreach ($fields['fields'] as $field_name => $field) {
  63. if (!$field['multiple'] && ($field['widget']['type'] == 'text_textfield' || $field['widget']['type'] == 'number')) {
  64. $tokens['user']['content-profile-'. $type_name .'-'. substr($field_name, 6)] = t($fields['description']) .'-'. t($field['widget']['label']);
  65. $tokens['user']['content-profile-'. $type_name .'-'. substr($field_name, 6) .'-raw'] = t($fields['description']) .'-'. t($field['widget']['label']) .' '. t('WARNING - raw user input');
  66. }
  67. }
  68. }
  69. }
  70. if ($type == 'flag_friend' && module_exists('flag_friend')) {
  71. foreach($types as $type_name => $type) {
  72. $fields = content_types($type_name);
  73. foreach ($fields['fields'] as $field_name => $field) {
  74. if (!$field['multiple'] && ($field['widget']['type'] == 'text_textfield' || $field['widget']['type'] == 'number')) {
  75. $tokens['content_profile_flag_friend']['requestor-'. $type_name .'-'. substr($field_name, 6)] = t('Requestor:') . t($fields['description']) .'-'. t($field['widget']['label']);
  76. $tokens['content_profile_flag_friend']['requestor-'. $type_name .'-'. substr($field_name, 6) .'-raw'] = t('Requestor:') . t($fields['description']) .'-'. t($field['widget']['label']) .' '. t('WARNING - raw user input');
  77. $tokens['content_profile_flag_friend']['requestee-'. $type_name .'-'. substr($field_name, 6)] = t('Requestee:') . t($fields['description']) .'-'. t($field['widget']['label']);
  78. $tokens['content_profile_flag_friend']['requestee-'. $type_name .'-'. substr($field_name, 6) .'-raw'] = t('Requestee:') .t($fields['description']) .'-'. t($field['widget']['label']) .' '. t('WARNING - raw user input');
  79. }
  80. }
  81. }
  82. }
  83. return $tokens;
  84. }