Projet

Général

Profil

Paste
Télécharger (1,92 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / diff / diff.tokens.inc @ a5572547

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