You are here

function diff_diffs_show in Diff 7.3

Same name and namespace in other branches
  1. 5.2 diff.module \diff_diffs_show()
  2. 5 diff.module \diff_diffs_show()
  3. 6.2 diff.pages.inc \diff_diffs_show()
  4. 6 diff.module \diff_diffs_show()
  5. 7.2 diff.pages.inc \diff_diffs_show()

Create a comparison for the node between versions 'old_vid' and 'new_vid'.

Parameters

object $node: Node on which to perform comparison.

int $old_vid: Version ID of the old revision.

int $new_vid: Version ID of the new revision.

1 call to diff_diffs_show()
diff_tokens in ./diff.tokens.inc
Implements hook_tokens().
1 string reference to 'diff_diffs_show'
diff_menu in ./diff.module
Implements hook_menu().

File

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

Code

function diff_diffs_show($node, $old_vid, $new_vid, $state = NULL) {

  // Attaches the CSS.
  $build['#attached'] = diff_build_attachments();
  $default_state = variable_get('diff_default_state_node', '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.
  if (node_is_page($node)) {
    drupal_set_title(t('Revisions for %title', array(
      '%title' => $node->title,
    )), PASS_THROUGH);
  }
  $node_revisions = node_revision_list($node);
  $old_node = node_load($node->nid, $old_vid);
  $new_node = node_load($node->nid, $new_vid);

  // Generate table header (date, username, log message).
  $old_header = t('!date by !username', array(
    '!date' => l(format_date($old_node->revision_timestamp), "node/{$node->nid}/revisions/{$old_node->vid}/view", array(
      'absolute' => 1,
    )),
    '!username' => theme('username', array(
      'account' => $node_revisions[$old_vid],
    )),
  ));
  $new_header = t('!date by !username', array(
    '!date' => l(format_date($new_node->revision_timestamp), "node/{$node->nid}/revisions/{$new_node->vid}/view", array(
      'absolute' => 1,
    )),
    '!username' => theme('username', array(
      'account' => $node_revisions[$new_vid],
    )),
  ));
  $old_log = $old_node->log != '' ? '<p class="revision-log">' . filter_xss($old_node->log) . '</p>' : '';
  $new_log = $new_node->log != '' ? '<p class="revision-log">' . filter_xss($new_node->log) . '</p>' : '';

  // Generate previous diff/next diff links.
  $nav_suffix = $default_state != $state ? '/' . str_replace('_', '-', $state) : '';
  $next_vid = _diff_get_next_vid($node_revisions, $new_vid);
  if ($next_vid) {
    $next_link = l(t('Next difference >'), 'node/' . $node->nid . '/revisions/view/' . $new_vid . '/' . $next_vid . $nav_suffix, array(
      'absolute' => 1,
    ));
  }
  else {
    $next_link = '';
  }
  $prev_vid = _diff_get_previous_vid($node_revisions, $old_vid);
  if ($prev_vid) {
    $prev_link = l(t('< Previous difference'), 'node/' . $node->nid . '/revisions/view/' . $prev_vid . '/' . $old_vid . $nav_suffix, array(
      'absolute' => 1,
    ));
  }
  else {
    $prev_link = '';
  }
  $header = _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('node') as $alternative_state => $label) {
    if ($alternative_state == $state) {

      // @todo: Should we show both or just alternatives?
    }
    $links[$alternative_state] = array(
      'title' => $label,
      'href' => "node/{$node->nid}/revisions/view/{$old_vid}/{$new_vid}" . ($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, _diff_body_rows($old_node, $new_node, $state));
  $build['diff_table'] = array(
    '#theme' => 'table__diff__standard',
    '#header' => $header,
    '#rows' => $rows,
    '#attributes' => array(
      'class' => array(
        'diff',
      ),
    ),
    '#colgroups' => _diff_default_cols(),
    '#sticky' => FALSE,
  );

  // Allow users to hide or set the display mode of the preview.
  if (node_is_page($node) && ($view_mode = variable_get('diff_view_mode_preview_node_' . $new_node->type, 'full'))) {
    $header = '';
    if ($node->vid == $new_vid) {
      $header .= '<div class="diff-section-title">' . t('Current revision:') . '</div>';
    }
    else {
      $header .= '<div class="diff-section-title">' . t('Revision of @new_date:', array(
        '@new_date' => format_date($new_node->revision_timestamp),
      )) . '</div>';
    }
    $build['diff_preview']['header']['#markup'] = $header;

    // Don't include node links or comments when viewing the diff.
    $build['diff_preview']['content'] = function_exists('entity_view') ? entity_view('node', array(
      $new_node,
    ), $view_mode) : node_view($new_node, $view_mode);
    if (isset($build['diff_preview']['content']['links'])) {
      unset($build['diff_preview']['content']['links']);
    }
    if (isset($build['diff_preview']['content']['comments'])) {
      unset($build['diff_preview']['content']['comments']);
    }
  }
  return $build;
}