1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Provide a global context to allow for token support.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
$plugin = array(
|
9 |
|
|
'title' => t('Token'),
|
10 |
|
|
'description' => t('A context that contains token replacements from token.module.'),
|
11 |
|
|
'context' => 'ctools_context_create_token', // func to create context
|
12 |
|
|
'context name' => 'token',
|
13 |
|
|
'keyword' => 'token',
|
14 |
|
|
'convert list' => 'ctools_context_token_convert_list',
|
15 |
|
|
'convert' => 'ctools_context_token_convert',
|
16 |
|
|
);
|
17 |
|
|
|
18 |
|
|
/**
|
19 |
|
|
* Create a context from manual configuration.
|
20 |
|
|
*/
|
21 |
|
|
function ctools_context_create_token($empty, $data = NULL, $conf = FALSE) {
|
22 |
|
|
$context = new ctools_context('token');
|
23 |
|
|
$context->plugin = 'token';
|
24 |
|
|
|
25 |
|
|
return $context;
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
/**
|
29 |
|
|
* Implementation of hook_ctools_context_convert_list().
|
30 |
|
|
*/
|
31 |
|
|
function ctools_context_token_convert_list() {
|
32 |
|
|
$tokens = token_info();
|
33 |
|
|
foreach ($tokens['types'] as $type => $type_info) {
|
34 |
|
|
if (empty($type_info['needs-data'])) {
|
35 |
|
|
$real_type = isset($type_info['type']) ? $type_info['type'] : $type;
|
36 |
|
|
foreach ($tokens['tokens'][$real_type] as $id => $info) {
|
37 |
|
|
$key = "$type:$id";
|
38 |
|
|
if (!isset($list[$key])) {
|
39 |
|
|
$list[$key] = $type_info['name'] . ': ' . $info['name'];
|
40 |
|
|
}
|
41 |
|
|
}
|
42 |
|
|
}
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
return $list;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
/**
|
49 |
|
|
* Implementation of hook_ctools_context_converter_alter().
|
50 |
|
|
*/
|
51 |
|
|
function ctools_context_token_convert($context, $token) {
|
52 |
|
|
$tokens = token_info();
|
53 |
|
|
list($type, $token) = explode(':', $token, 2);
|
54 |
3753f249
|
Assos Assos
|
$parts = explode(':', $token, 2);
|
55 |
85ad3d82
|
Assos Assos
|
$real_type = isset($tokens['types'][$type]['type']) ? $tokens['types'][$type]['type'] : $type;
|
56 |
3753f249
|
Assos Assos
|
if (isset($tokens['tokens'][$real_type][$parts[0]])) {
|
57 |
85ad3d82
|
Assos Assos
|
$values = token_generate($type, array($token => $token));
|
58 |
|
|
if (isset($values[$token])) {
|
59 |
|
|
return $values[$token];
|
60 |
|
|
}
|
61 |
|
|
}
|
62 |
|
|
} |