1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Implements hook_filter_info().
|
5 |
|
|
*
|
6 |
|
|
* Adds the Token filter to the textx format options.
|
7 |
|
|
*/
|
8 |
|
|
function token_filter_filter_info() {
|
9 |
|
|
$filters['filter_tokens'] = array(
|
10 |
|
|
'title' => t('Replace tokens'),
|
11 |
|
|
'description' => t('The usage of this filter should be restricted to trusted users only as tokens with sensitive data could be exposed.'),
|
12 |
|
|
'process callback' => '_token_filter_filter_tokens',
|
13 |
|
|
'tips callback' => '_token_filter_filter_tips',
|
14 |
|
|
'cache' => FALSE,
|
15 |
|
|
);
|
16 |
|
|
return $filters;
|
17 |
|
|
}
|
18 |
|
|
|
19 |
|
|
/**
|
20 |
|
|
* Filter process callback for the token input filter.
|
21 |
|
|
*/
|
22 |
|
|
function _token_filter_filter_tokens($text, $filter, $format, $langcode, $cache, $cache_id) {
|
23 |
|
|
$data = array();
|
24 |
|
|
$options = array();
|
25 |
|
|
|
26 |
|
|
// Attempt to fetch the entity that is being viewed via a backtrace to the
|
27 |
|
|
// field_attach_view($entity_type, $entity) function and parameters ?if found.
|
28 |
|
|
$backtrace = debug_backtrace();
|
29 |
|
|
foreach ($backtrace as $caller) {
|
30 |
|
|
if ($caller['function'] == 'field_attach_view') {
|
31 |
|
|
$entity_type = $caller['args'][0];
|
32 |
|
|
$entity = $caller['args'][1];
|
33 |
|
|
$token_type = token_get_entity_mapping('entity', $entity_type);
|
34 |
|
|
$data[$token_type] = $entity;
|
35 |
|
|
// Use the proper language code that field_attach_view was called with.
|
36 |
|
|
if ($langcode = $caller['args'][3]) {
|
37 |
|
|
$language_list = language_list();
|
38 |
|
|
if (!empty($language_list[$langcode])) {
|
39 |
|
|
$options['language'] = $language_list[$langcode];
|
40 |
|
|
}
|
41 |
|
|
}
|
42 |
|
|
break;
|
43 |
|
|
}
|
44 |
|
|
elseif ($caller['function'] == '_drupal_bootstrap_full' || $caller == 'menu_execute_active_handler') {
|
45 |
|
|
// There is no point in going back this far, so just stop.
|
46 |
|
|
break;
|
47 |
|
|
}
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
return token_replace($text, $data, $options);
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
/**
|
54 |
|
|
* Filter tip callback for the token input filter.
|
55 |
|
|
*/
|
56 |
|
|
function _token_filter_filter_tips($filter, $format, $long = FALSE) {
|
57 |
|
|
if ($long) {
|
58 |
|
|
$output = t('Global tokens will be replaced with their respective token values (e.g. [site:name] or [current-page:title]). The following is a list of the tokens that are available:');
|
59 |
|
|
$output .= theme('token_tree', array('click_insert' => FALSE));
|
60 |
|
|
return $output;
|
61 |
|
|
}
|
62 |
|
|
else {
|
63 |
|
|
return t('Global tokens will be replaced with their respective token values (e.g. [site:name] or [current-page:title]).');
|
64 |
|
|
}
|
65 |
|
|
} |