You are here

function taxonomy_revision_diffs_show in Taxonomy revision 7

Create a comparison for the term between versions 'old_revision_id' and 'new_revision_id'.

Parameters

object $term: Term on which to perform comparison

integer $old_revision_id: Version ID of the old revision.

integer $new_revision_id: Version ID of the new revision.

1 string reference to 'taxonomy_revision_diffs_show'
taxonomy_revision_menu in ./taxonomy_revision.module
Implements hook_menu().

File

./taxonomy_revision.pages.inc, line 86
UI pages for revisions, similar with pages from node.pages.inc.

Code

function taxonomy_revision_diffs_show($term, $old_revision_id, $new_revision_id, $state = NULL) {

  // Attaches the CSS.
  $build['#attached'] = diff_build_attachments();

  // The default state is the raw state.
  $default_state = 'raw';
  if (empty($state)) {
    $state = $default_state;
  }
  $state = str_replace('-', '_', $state);
  if (!array_key_exists($state, diff_available_states())) {
    $state = $default_state;
  }

  // Same title as the 'Revisions' tab. Blocked by non-page requests.
  drupal_set_title(t('Revisions for %title', array(
    '%title' => $term->name,
  )), PASS_THROUGH);
  $term_revisions = taxonomy_revision_list($term);
  $old_term = taxonomy_revision_term_load($term->tid, $old_revision_id);
  $new_term = taxonomy_revision_term_load($term->tid, $new_revision_id);

  // Generate table header (date, username, log message).
  $old_header = t('!date by !username', array(
    '!date' => l(format_date($old_term->timestamp), "taxonomy/term/{$term->tid}/revisions/{$old_term->revision_id}/view", array(
      'absolute' => 1,
    )),
    '!username' => theme('username', array(
      'account' => $term_revisions[$old_revision_id],
    )),
  ));
  $new_header = t('!date by !username', array(
    '!date' => l(format_date($new_term->timestamp), "taxonomy_term/{$term->tid}/revisions/{$new_term->revision_id}/view", array(
      'absolute' => 1,
    )),
    '!username' => theme('username', array(
      'account' => $term_revisions[$new_revision_id],
    )),
  ));
  $old_log = $old_term->log != '' ? '<p class="revision-log">' . filter_xss($old_term->log) . '</p>' : '';
  $new_log = $new_term->log != '' ? '<p class="revision-log">' . filter_xss($new_term->log) . '</p>' : '';

  // Generate previous diff/next diff links.
  $nav_suffix = $default_state != $state ? '/' . str_replace('_', '-', $state) : '';
  $next_revision_id = _taxonomy_revision_diff_get_next_revision_id($term_revisions, $new_revision_id);
  if ($next_revision_id) {
    $next_link = l(t('Next difference >'), 'taxonomy/term/' . $term->tid . '/revisions/view/' . $new_revision_id . '/' . $next_revision_id . $nav_suffix, array(
      'absolute' => 1,
    ));
  }
  else {
    $next_link = '';
  }
  $prev_revision_id = _taxonomy_revision_diff_get_previous_revision_id($term_revisions, $old_revision_id);
  if ($prev_revision_id) {
    $prev_link = l(t('< Previous difference'), 'taxonomy/term/' . $term->tid . '/revisions/view/' . $prev_revision_id . '/' . $old_revision_id . $nav_suffix, array(
      'absolute' => 1,
    ));
  }
  else {
    $prev_link = '';
  }
  $header = _taxonomy_revision_diff_default_header($old_header, $new_header);
  $rows = array();
  if ($old_log || $new_log) {
    $rows['logs'] = array(
      array(
        'data' => $old_log,
        'colspan' => 2,
      ),
      array(
        'data' => $new_log,
        'colspan' => 2,
      ),
    );
  }
  $rows['navigation'] = array(
    array(
      'data' => $prev_link,
      'class' => array(
        'diff-prevlink',
      ),
      'colspan' => 2,
    ),
    array(
      'data' => $next_link,
      'class' => array(
        'diff-nextlink',
      ),
      'colspan' => 2,
    ),
  );
  $links = array();
  foreach (diff_available_states('taxonomy_term') as $alternative_state => $label) {
    if ($alternative_state == $state) {

      // @todo: from the diff module: Should we show both or just alternatives?
    }
    $links[$alternative_state] = array(
      'title' => $label,
      'href' => "taxonomy/term/{$term->tid}/revisions/view/{$old_revision_id}/{$new_revision_id}" . ($alternative_state == $default_state ? '' : '/' . str_replace('_', '-', $alternative_state)),
    );
  }
  if (count($links) > 1) {
    $state_links = theme('links', array(
      'links' => $links,
      'attributes' => array(
        'class' => array(
          'links',
          'inline',
        ),
      ),
    ));
    $rows['states'] = array(
      array(
        'data' => $state_links,
        'class' => 'diff-links',
        'colspan' => 4,
      ),
    );
  }
  $rows = array_merge($rows, _taxonomy_revision_diff_body_rows($old_term, $new_term, $state));
  $build['diff_table'] = array(
    '#theme' => 'table__diff__standard',
    '#header' => $header,
    '#rows' => $rows,
    '#attributes' => array(
      'class' => array(
        'diff',
      ),
    ),
    '#colgroups' => _diff_default_cols(),
    '#sticky' => FALSE,
  );
  return $build;
}