You are here

function profile2_diff_diffs_show in Profile 2 7.2

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

Parameters

$profile: profile on which to perform comparison

$old_vid: Version ID of the old revision.

$new_vid: Version ID of the new revision.

1 call to profile2_diff_diffs_show()
profile2_diff_diffs_show_by_user in contrib/profile2_diff.pages.inc
1 string reference to 'profile2_diff_diffs_show'
profile2_diff_menu in contrib/profile2_diff.module
Implements hook_menu().

File

contrib/profile2_diff.pages.inc, line 160
Menu callbacks for hook_menu().

Code

function profile2_diff_diffs_show($profile, $old_vid, $new_vid) {
  module_load_include('inc', 'diff', 'diff.pages');
  $uid = $profile->uid;
  $pid = $profile->pid;
  $profile2_revisions = profile2_revision_list($profile);
  $old_rev = $profile2_revisions[$old_vid];
  $new_rev = $profile2_revisions[$new_vid];

  // mode-dependent base for links
  $link_base = _profile2_revision_base_path($profile, TRUE);

  // Generate table header (date, profile-name, logmessage).
  $old_header = t('!date by !username', array(
    '!date' => l(format_date($old_rev->timestamp), "{$link_base}/view/{$old_vid}"),
    '!username' => theme('username', array(
      'account' => $old_rev,
    )),
  ));
  $new_header = t('!date by !username', array(
    '!date' => l(format_date($new_rev->timestamp), "{$link_base}/view/{$new_vid}"),
    '!username' => theme('username', array(
      'account' => $new_rev,
    )),
  ));
  $old_log = $old_rev->log != '' ? '<p class="revision-log">' . filter_xss($old_rev->log) . '</p>' : '';
  $new_log = $new_rev->log != '' ? '<p class="revision-log">' . filter_xss($new_rev->log) . '</p>' : '';

  // Generate previous diff/next diff links.
  $next_vid = _diff_get_next_vid($profile2_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($profile2_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,
    ),
  );
  $old_profile = profile2_load($pid, $old_vid);
  $new_profile = profile2_load($pid, $new_vid);
  $rows = array_merge($rows, _profile2_diff_body_rows($old_profile, $new_profile));
  $output = theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'class' => array(
        'diff',
      ),
    ),
    'cols' => $cols,
  ));
  $profile_view = profile2_view($new_profile, 'diff_standard');
  $profile_output = drupal_render($profile_view);
  $stripped_output = trim(strip_tags($profile_output));

  // Omit header for profile display if no rendered output, apart from label.
  if (!empty($stripped_output) && $stripped_output != $new_profile
    ->label()) {
    if ($profile->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_profile->revision_timestamp),
      )) . '</div>';
    }
    $output .= $profile_output;
  }
  return $output;
}