You are here

function _diff_body_rows in Diff 7.2

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

Creates an array of rows which represent a diff between $old_node and $new_node. The rows can be used via theme('diff_table') to be displayed.

Parameters

$old_node: Node for comparison which will be displayed on the left side.

$new_node: Node for comparison which will be displayed on the right side.

$remove_markup: Strip markup before doing the diff

2 calls to _diff_body_rows()
diff_diffs_show in ./diff.pages.inc
Create output string for a comparison of 'node' between versions 'old_vid' and 'new_vid'.
diff_node_form_build_preview_changes in ./diff.module
Callback if 'View changes' is pressed.

File

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

Code

function _diff_body_rows($old_node, $new_node, $remove_markup = FALSE) {
  drupal_add_css(drupal_get_path('module', 'diff') . '/diff.css');
  module_load_include('inc', 'diff', 'includes/node');
  $rows = array();
  $any_visible_change = FALSE;

  // @todo quick workaround for PHP >= 5.3.0 date_diff() conflict.
  $node_diffs = _diff_module_invoke_all($old_node, $new_node, $remove_markup);

  // We start off assuming all form elements are in the correct order.
  $node_diffs['#sorted'] = TRUE;

  // Recurse through all child elements.
  $count = 0;
  foreach (element_children($node_diffs) as $key) {

    // Assign a decimal placeholder weight to preserve original array order.
    if (!isset($node_diffs[$key]['#weight'])) {
      $node_diffs[$key]['#weight'] = $count / 1000;
    }
    else {

      // If one of the child elements has a weight then we will need to sort
      // later.
      unset($node_diffs['#sorted']);
    }
    $count++;
  }

  // One of the children has a #weight.
  if (!isset($node_diffs['#sorted'])) {
    uasort($node_diffs, "element_sort");
  }

  // Render diffs for each.
  foreach ($node_diffs as $node_diff) {
    $show_header = isset($node_diff['#format']['show_header']) ? $node_diff['#format']['show_header'] : FALSE;
    if ($node_diff_rows = diff_get_rows($node_diff['#old'], $node_diff['#new'], $show_header)) {
      $rows[] = array(
        array(
          'data' => t('Changes to %name', array(
            '%name' => $node_diff['#name'],
          )),
          'class' => 'diff-section-title',
          'colspan' => 4,
        ),
      );
      $rows = array_merge($rows, $node_diff_rows);
      $any_visible_change = TRUE;
    }
  }
  if (!$any_visible_change) {
    $rows[] = array(
      array(
        'data' => t('No visible changes'),
        'class' => 'diff-section-title',
        'colspan' => 4,
      ),
    );

    // Needed to keep safari happy
    $rows[] = array(
      array(
        'data' => '',
      ),
      array(
        'data' => '',
      ),
      array(
        'data' => '',
      ),
      array(
        'data' => '',
      ),
    );
  }
  return $rows;
}