You are here

function oa_diff_tokens in Open Atrium Core 7.2

Implements hook_tokens().

File

modules/oa_diff/oa_diff.module, line 30
Builds placeholder replacement tokens for diff-related data.

Code

function oa_diff_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $sanitize = !empty($options['sanitize']);

  // similar to regular diff module, but we do not sanitize results because results
  // are always an HTML table
  $replacements = array();
  if ($type == 'node' && !empty($data['node'])) {
    $node = $data['node'];
    foreach ($tokens as $name => $original) {
      $values = explode(':', $name);
      if (!empty($values[0]) && $values[0] == 'oa-diff') {
        $revisions = node_revision_list($node);
        if (count($revisions) == 1) {
          $replacements[$original] = '';
        }
        else {
          module_load_include('inc', 'diff', 'diff.pages');
          if (isset($values[1]) && is_numeric($values[1])) {
            $vid = $values[1];
            if (isset($values[2]) && is_numeric($values[2])) {
              $next_vid = $values[2];
            }
            else {
              $next_vid = _diff_get_next_vid($revisions, $vid);
            }
          }
          else {
            $next_vid = $node->vid;
            $vid = _diff_get_previous_vid($revisions, $next_vid);
          }
          if ($next_vid) {
            $state = 'raw_plain';
            $build = diff_diffs_show($node, $vid, $next_vid, $state);
            unset($build['diff_table']['#rows']['logs']);
            unset($build['diff_table']['#rows']['states']);
            unset($build['diff_table']['#rows']['navigation']);
            unset($build['diff_table']['#header']);
            unset($build['diff_preview']);
            $output = drupal_render_children($build);

            // prevent overflow of messages
            if (strlen($output) > variable_get('oa_diff_limit', 4096)) {
              $output = t('Too many differences to list.  See Revisions for details.');
            }
            $replacements[$original] = $output;
          }
          else {
            $replacements[$original] = '';
          }
        }
      }
    }
  }
  return $replacements;
}