You are here

function user_rev_diff_diffs_show in User Revision 7.2

Create output string for a comparison of 'user' between versions 'old_vid' and 'new_vid'.

Parameters

$user: User on which to perform comparison

$old_vid: Version ID of the old revision.

$new_vid: Version ID of the new revision.

1 call to user_rev_diff_diffs_show()
user_rev_diff_tokens in diff/user_rev_diff.tokens.inc
Implements hook_tokens().
1 string reference to 'user_rev_diff_diffs_show'
user_rev_diff_menu in diff/user_rev_diff.module
Implementation of hook_menu().

File

diff/user_rev_diff.pages.inc, line 116
Menu callbacks for hook_menu().

Code

function user_rev_diff_diffs_show($user, $old_vid, $new_vid) {
  module_load_include('inc', 'diff', 'diff.pages');

  // Set same title as on the 'Revisions' tab for consistency
  drupal_set_title(t('Revisions for @name', array(
    '@name' => $user->name,
  )));
  $user_revisions = user_revision_list($user);
  $old_user = user_revision_load($user->uid, $old_vid);
  $new_user = user_revision_load($user->uid, $new_vid);
  $link_base = _user_revision_base_path($user);

  // Generate table header (date, username, logmessage).
  $old_header = t('!date by !username', array(
    '!date' => l(format_date($old_user->revision_timestamp), "{$link_base}/view/{$old_user->vid}"),
    '!username' => theme('username', array(
      'account' => $user_revisions[$old_vid],
    )),
  ));
  $new_header = t('!date by !username', array(
    '!date' => l(format_date($new_user->revision_timestamp), "{$link_base}/view/{$new_user->vid}"),
    '!username' => theme('username', array(
      'account' => $user_revisions[$new_vid],
    )),
  ));
  $old_log = $old_user->log != '' ? '<p class="revision-log">' . filter_xss($old_user->log) . '</p>' : '';
  $new_log = $new_user->log != '' ? '<p class="revision-log">' . filter_xss($new_user->log) . '</p>' : '';

  // Generate previous diff/next diff links.
  $next_vid = _diff_get_next_vid($user_revisions, $new_vid);
  if ($next_vid) {
    $next_link = l(t('next diff >'), "{$link_base}/diff/{$new_vid}/{$next_vid}");
  }
  else {
    $next_link = '';
  }
  $prev_vid = _diff_get_previous_vid($user_revisions, $old_vid);
  if ($prev_vid) {
    $prev_link = l(t('< previous diff'), "{$link_base}/diff/{$prev_vid}/{$old_vid}");
  }
  else {
    $prev_link = '';
  }
  $cols = _diff_default_cols();
  $header = _diff_default_header($old_header, $new_header);
  $rows = array();
  if ($old_log || $new_log) {
    $rows[] = array(
      array(
        'data' => $old_log,
        'colspan' => 2,
      ),
      array(
        'data' => $new_log,
        'colspan' => 2,
      ),
    );
  }
  $rows[] = array(
    array(
      'data' => $prev_link,
      'class' => array(
        'diff-prevlink',
      ),
      'colspan' => 2,
    ),
    array(
      'data' => $next_link,
      'class' => array(
        'diff-nextlink',
      ),
      'colspan' => 2,
    ),
  );
  $rows = array_merge($rows, _user_rev_diff_body_rows($old_user, $new_user));
  $output = theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'class' => array(
        'diff',
      ),
    ),
    'cols' => $cols,
  ));
  $user_view = user_view($new_user, 'diff_standard');
  $user_output = drupal_render($user_view);

  // Omit header for account display if no rendered output.
  if (!empty(trim(strip_tags($user_output)))) {
    if ($user->vid == $new_vid) {
      $output .= '<div class="diff-section-title">' . t('Current revision:') . '</div>';
    }
    else {
      $output .= '<div class="diff-section-title">' . t('Revision of !new_date:', array(
        '!new_date' => format_date($new_user->revision_timestamp),
      )) . '</div>';
    }
    $output .= $user_output;
  }
  return $output;
}