1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
5721e759
|
Assos Assos
|
* Helper functions for token_insert.module.
|
5 |
85ad3d82
|
Assos Assos
|
*/
|
6 |
|
|
|
7 |
|
|
function token_insert_get_tokens() {
|
8 |
|
|
global $user;
|
9 |
|
|
$roles['global'] = 'global';
|
10 |
5721e759
|
Assos Assos
|
if (variable_get('token_insert_use_tokens_per_role', 0)) {
|
11 |
85ad3d82
|
Assos Assos
|
$roles += $user->roles;
|
12 |
|
|
}
|
13 |
|
|
$all_tokens = token_get_info();
|
14 |
5721e759
|
Assos Assos
|
foreach ($roles as $rid => $role) {
|
15 |
85ad3d82
|
Assos Assos
|
foreach ($all_tokens['tokens'] as $category => $tokens) {
|
16 |
5721e759
|
Assos Assos
|
// 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 |
85ad3d82
|
Assos Assos
|
foreach ($tokens as $token => $description) {
|
22 |
5721e759
|
Assos Assos
|
$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 |
85ad3d82
|
Assos Assos
|
}
|
35 |
|
|
else {
|
36 |
5721e759
|
Assos Assos
|
$all_options[$full_token] = $category . ' : [' . $token . '] : ' . truncate_utf8($description['description'], 60, TRUE, TRUE);
|
37 |
85ad3d82
|
Assos Assos
|
}
|
38 |
|
|
}
|
39 |
|
|
}
|
40 |
|
|
}
|
41 |
|
|
}
|
42 |
|
|
if (empty($options)) {
|
43 |
|
|
$options = $all_options;
|
44 |
|
|
}
|
45 |
|
|
return $options;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
5721e759
|
Assos Assos
|
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 |
|
|
} |