1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Helper functions for token_insert.module.
|
5
|
*/
|
6
|
|
7
|
function token_insert_get_tokens() {
|
8
|
global $user;
|
9
|
$roles['global'] = 'global';
|
10
|
if (variable_get('token_insert_use_tokens_per_role', 0)) {
|
11
|
$roles += $user->roles;
|
12
|
}
|
13
|
$all_tokens = token_get_info();
|
14
|
foreach ($roles as $rid => $role) {
|
15
|
foreach ($all_tokens['tokens'] as $category => $tokens) {
|
16
|
// Check to see if all tokens are enabled for this category.
|
17
|
$allow_all = variable_get('token_insert_' . $rid . '_all_tokens_' . $category, FALSE);
|
18
|
if (!$allow_all) {
|
19
|
$allowed_options = variable_get('token_insert_' . $rid . '_used_tokens_' . $category, array());
|
20
|
}
|
21
|
foreach ($tokens as $token => $description) {
|
22
|
$full_token = '[' . $category . ':' . $token . ']';
|
23
|
if ($allow_all) {
|
24
|
$options[$full_token] = $category . ' : [' . $token . '] : ' . truncate_utf8($description['description'], 60, TRUE, TRUE);
|
25
|
}
|
26
|
else {
|
27
|
if (!empty ($allowed_options)) {
|
28
|
if (isset($allowed_options[$full_token]) && $allowed_options[$full_token]) {
|
29
|
$options[$full_token] = $category . ' : [' . $token . '] : ' . truncate_utf8($description['description'], 60, TRUE, TRUE);
|
30
|
}
|
31
|
else {
|
32
|
$all_options[$full_token] = $category . ' : [' . $token . '] : ' . truncate_utf8($description['description'], 60, TRUE, TRUE);
|
33
|
}
|
34
|
}
|
35
|
else {
|
36
|
$all_options[$full_token] = $category . ' : [' . $token . '] : ' . truncate_utf8($description['description'], 60, TRUE, TRUE);
|
37
|
}
|
38
|
}
|
39
|
}
|
40
|
}
|
41
|
}
|
42
|
if (empty($options)) {
|
43
|
$options = $all_options;
|
44
|
}
|
45
|
return $options;
|
46
|
}
|
47
|
|
48
|
function token_insert_get_allowed_token_types() {
|
49
|
global $user;
|
50
|
$roles['global'] = 'global';
|
51
|
if (variable_get('token_insert_use_tokens_per_role', 0)) {
|
52
|
$roles += $user->roles;
|
53
|
}
|
54
|
$all_tokens = token_get_info();
|
55
|
foreach ($roles as $rid => $role) {
|
56
|
foreach ($all_tokens['tokens'] as $category => $tokens) {
|
57
|
// Check to see if all tokens are enabled for this category.
|
58
|
$allow_all = variable_get('token_insert_' . $rid . '_all_tokens_' . $category, FALSE);
|
59
|
if (!$allow_all) {
|
60
|
$allowed_options = variable_get('token_insert_' . $rid . '_used_tokens_' . $category, array());
|
61
|
}
|
62
|
foreach ($tokens as $token => $description) {
|
63
|
$full_token = '[' . $category . ':' . $token . ']';
|
64
|
if ($allow_all) {
|
65
|
$options[$category] = $category;
|
66
|
break;
|
67
|
}
|
68
|
else {
|
69
|
if (!empty ($allowed_options)) {
|
70
|
if (isset($allowed_options[$full_token]) && $allowed_options[$full_token]) {
|
71
|
$options[$category] = $category;
|
72
|
break;
|
73
|
}
|
74
|
else {
|
75
|
$all_options[$category] = $category;
|
76
|
break;
|
77
|
}
|
78
|
}
|
79
|
else {
|
80
|
$all_options[$category] = $category;
|
81
|
break;
|
82
|
}
|
83
|
}
|
84
|
}
|
85
|
}
|
86
|
}
|
87
|
if (empty($options)) {
|
88
|
$options = $all_options;
|
89
|
}
|
90
|
return $options;
|
91
|
}
|