You are here

function user_rev_diff_tokens in User Revision 7.2

Implements hook_tokens().

File

diff/user_rev_diff.tokens.inc, line 29
Builds placeholder replacement tokens for diff-related data.

Code

function user_rev_diff_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $sanitize = !empty($options['sanitize']);
  $replacements = array();
  if ($type == 'user' && !empty($data['user'])) {
    $user = $data['user'];
    foreach ($tokens as $name => $original) {
      switch ($name) {

        // Basic diff standard comparison information.
        case 'diff':
        case 'diff-markdown':
          $revisions = user_revision_list($user);
          if (count($revisions) == 1) {
            $replacements[$original] = t('(No previous revision available.)');
          }
          else {
            module_load_include('inc', 'diff', 'diff.pages');
            module_load_include('inc', 'user_rev_diff', 'user_rev_diff.pages');
            $old_vid = _diff_get_previous_vid($revisions, $user->vid);
            $state = $name == 'diff' ? 'raw' : 'raw_plain';
            $output = user_rev_diff_diffs_show($user, $old_vid, $user->vid, $state);
            $replacements[$original] = $sanitize ? check_plain($output) : $output;
          }
          break;
      }
    }
  }
  return $replacements;
}