function _diff_body_rows in Diff 6
Same name and namespace in other branches
- 5.2 diff.module \_diff_body_rows()
- 6.2 diff.pages.inc \_diff_body_rows()
- 7.3 diff.pages.inc \_diff_body_rows()
- 7.2 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.
2 calls to _diff_body_rows()
- diff_diffs_show in ./
diff.module - 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 'Preview changes' is pressed.
File
- ./
diff.module, line 328 - Provides functionality to show a diff between two node revisions.
Code
function _diff_body_rows(&$old_node, &$new_node) {
drupal_add_css(drupal_get_path('module', 'diff') . '/diff.css', 'module', 'all', FALSE);
include_once 'DiffEngine.php';
include_once 'node.inc';
if (module_exists('taxonomy')) {
include_once 'taxonomy.inc';
}
if (module_exists('upload')) {
include_once 'upload.inc';
}
if (module_exists('content')) {
include_once 'cck.inc';
}
$rows = array();
$any_visible_change = false;
$node_diffs = module_invoke_all('diff', $old_node, $new_node);
// 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");
}
foreach ($node_diffs as $node_diff) {
$diff = new Diff($node_diff['#old'], $node_diff['#new']);
$formatter = new DrupalDiffFormatter();
if (isset($node_diff['#format'])) {
$formatter->show_header = $node_diff['#format']['show_header'];
}
$diff_rows = $formatter
->format($diff);
if (count($diff_rows)) {
$rows[] = array(
array(
'data' => t('Changes to %name', array(
'%name' => $node_diff['#name'],
)),
'class' => 'diff-section-title',
'colspan' => 4,
),
);
$rows = array_merge($rows, $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;
}