diff.tokens.inc 1.9 KB

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