-
Notifications
You must be signed in to change notification settings - Fork 5
/
diff.tokens.inc
63 lines (55 loc) · 1.93 KB
/
diff.tokens.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* @file
* Builds placeholder replacement tokens for diff-related data.
*/
/**
* Implements hook_token_info().
*/
function diff_token_info() {
$node['diff'] = array(
'name' => t('Latest differences'),
'description' => t('The differences between the current revision and the previous revision of this node.'),
);
$node['diff-markdown'] = array(
'name' => t('Latest differences (marked down)'),
'description' => t('The differences between the current revision and the previous revision of this node, but with a marked-down form of each revision used for comparison.'),
);
return array(
'tokens' => array('node' => $node),
);
}
/**
* Implements hook_tokens().
*/
function diff_tokens($type, $tokens, array $data = array(), array $options = array()) {
$sanitize = !empty($options['sanitize']);
$replacements = array();
if ($type == 'node' && !empty($data['node'])) {
$node = $data['node'];
foreach ($tokens as $name => $original) {
switch ($name) {
// Basic diff standard comparison information.
case 'diff':
case 'diff-markdown':
$revisions = node_revision_list($node);
if (count($revisions) == 1) {
$replacements[$original] = t('(No previous revision available.)');
}
else {
module_load_include('inc', 'diff', 'diff.pages');
$old_vid = _diff_get_previous_vid($revisions, $node->vid);
$state = $name == 'diff' ? 'raw' : 'raw_plain';
$build = diff_diffs_show($node, $old_vid, $node->vid, $state);
unset($build['diff_table']['#rows']['states']);
unset($build['diff_table']['#rows']['navigation']);
unset($build['diff_preview']);
$output = backdrop_render_children($build);
$replacements[$original] = $sanitize ? check_plain($output) : $output;
}
break;
}
}
}
return $replacements;
}