Révision 661d64c9
Ajouté par Assos Assos il y a plus de 7 ans
drupal7/sites/all/modules/diff/diff.pages.inc | ||
---|---|---|
10 | 10 |
*/ |
11 | 11 |
function diff_latest($node) { |
12 | 12 |
$revisions = node_revision_list($node); |
13 |
if (count($revisions) < 2 || !diff_node_revision_access($node, 'view')) { |
|
14 |
drupal_goto('node/' . $node->nid); |
|
15 |
} |
|
13 | 16 |
$new = array_shift($revisions); |
14 | 17 |
$old = array_shift($revisions); |
15 | 18 |
drupal_goto("node/{$node->nid}/revisions/view/{$old->vid}/{$new->vid}"); |
... | ... | |
35 | 38 |
'#value' => $node->nid, |
36 | 39 |
); |
37 | 40 |
|
38 |
$revision_list = node_revision_list($node); |
|
41 |
$revision_list = diff_node_revision_list($node); |
|
42 |
$revision_count = count($revision_list); |
|
39 | 43 |
|
40 |
if (count($revision_list) > REVISION_LIST_SIZE) {
|
|
44 |
if ($revision_count > REVISION_LIST_SIZE) {
|
|
41 | 45 |
// If the list of revisions is longer than the number shown on one page |
42 | 46 |
// split the array. |
43 | 47 |
$page = isset($_GET['page']) ? $_GET['page'] : '0'; |
44 |
$revision_chunks = array_chunk(node_revision_list($node), REVISION_LIST_SIZE);
|
|
48 |
$revision_chunks = array_chunk($revision_list, REVISION_LIST_SIZE);
|
|
45 | 49 |
$revisions = $revision_chunks[$page]; |
46 | 50 |
// Set up global pager variables as would 'pager_query' do. |
47 | 51 |
// These variables are then used in the theme('pager') call later. |
48 | 52 |
global $pager_page_array, $pager_total, $pager_total_items; |
49 |
$pager_total_items[0] = count($revision_list);
|
|
50 |
$pager_total[0] = ceil(count($revision_list) / REVISION_LIST_SIZE);
|
|
53 |
$pager_total_items[0] = $revision_count;
|
|
54 |
$pager_total[0] = ceil($revision_count / REVISION_LIST_SIZE);
|
|
51 | 55 |
$pager_page_array[0] = max(0, min($page, ((int) $pager_total[0]) - 1)); |
52 | 56 |
} |
53 | 57 |
else { |
... | ... | |
73 | 77 |
'#markup' => t('!date by !username', array( |
74 | 78 |
'!date' => l(format_date($revision->timestamp, 'small'), "node/$node->nid"), |
75 | 79 |
'!username' => theme('username', array('account' => $revision)))) . $revision_log, |
80 |
'#revision' => $revision, |
|
76 | 81 |
); |
77 | 82 |
} |
78 | 83 |
else { |
... | ... | |
82 | 87 |
'!date' => $diff_date, |
83 | 88 |
'!username' => theme('username', array('account' => $revision))) |
84 | 89 |
) . $revision_log, |
90 |
'#revision' => $revision, |
|
85 | 91 |
); |
86 | 92 |
if ($revert_permission) { |
87 | 93 |
$operations[] = array( |
... | ... | |
117 | 123 |
|
118 | 124 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Compare')); |
119 | 125 |
|
120 |
if (count($revision_list) > REVISION_LIST_SIZE) {
|
|
126 |
if ($revision_count > REVISION_LIST_SIZE) {
|
|
121 | 127 |
$form['#suffix'] = theme('pager'); |
122 | 128 |
} |
123 | 129 |
$form['#attached'] = diff_build_attachments(TRUE); |
124 | 130 |
return $form; |
125 | 131 |
} |
126 | 132 |
|
127 |
/** |
|
128 |
* Submit code for input form to select two revisions. |
|
129 |
*/ |
|
130 |
function diff_node_revisions_submit($form, &$form_state) { |
|
131 |
// The ids are ordered so the old revision is always on the left. |
|
132 |
$old_vid = min($form_state['values']['old'], $form_state['values']['new']); |
|
133 |
$new_vid = max($form_state['values']['old'], $form_state['values']['new']); |
|
134 |
$form_state['redirect'] = 'node/' . $form_state['values']['nid'] . '/revisions/view/' . $old_vid . '/' . $new_vid; |
|
135 |
} |
|
136 |
|
|
137 | 133 |
/** |
138 | 134 |
* Validation for input form to select two revisions. |
139 | 135 |
*/ |
... | ... | |
145 | 141 |
} |
146 | 142 |
} |
147 | 143 |
|
144 |
/** |
|
145 |
* Submit code for input form to select two revisions. |
|
146 |
*/ |
|
147 |
function diff_node_revisions_submit($form, &$form_state) { |
|
148 |
// The ids are ordered so the old revision is always on the left. |
|
149 |
$old_vid = min($form_state['values']['old'], $form_state['values']['new']); |
|
150 |
$new_vid = max($form_state['values']['old'], $form_state['values']['new']); |
|
151 |
if (isset($_GET['destination'])) { |
|
152 |
unset($_GET['destination']); |
|
153 |
} |
|
154 |
$form_state['redirect'] = 'node/' . $form_state['values']['nid'] . '/revisions/view/' . $old_vid . '/' . $new_vid; |
|
155 |
} |
|
156 |
|
|
148 | 157 |
/** |
149 | 158 |
* Create a comparison for the node between versions 'old_vid' and 'new_vid'. |
150 | 159 |
* |
151 | 160 |
* @param object $node |
152 |
* Node on which to perform comparison |
|
153 |
* @param integer $old_vid
|
|
161 |
* Node on which to perform comparison.
|
|
162 |
* @param int $old_vid |
|
154 | 163 |
* Version ID of the old revision. |
155 |
* @param integer $new_vid
|
|
164 |
* @param int $new_vid |
|
156 | 165 |
* Version ID of the new revision. |
157 | 166 |
*/ |
158 | 167 |
function diff_diffs_show($node, $old_vid, $new_vid, $state = NULL) { |
... | ... | |
161 | 170 |
|
162 | 171 |
$default_state = variable_get('diff_default_state_node', 'raw'); |
163 | 172 |
if (empty($state)) { |
164 |
$state = $default_state;
|
|
173 |
$state = $default_state;
|
|
165 | 174 |
} |
166 | 175 |
$state = str_replace('-', '_', $state); |
167 | 176 |
if (!array_key_exists($state, diff_available_states())) { |
... | ... | |
279 | 288 |
} |
280 | 289 |
$build['diff_preview']['header']['#markup'] = $header; |
281 | 290 |
// Don't include node links or comments when viewing the diff. |
282 |
$build['diff_preview']['content'] = node_view($new_node, $view_mode); |
|
291 |
$build['diff_preview']['content'] = function_exists('entity_view') ? entity_view('node', array($new_node), $view_mode) : node_view($new_node, $view_mode);
|
|
283 | 292 |
if (isset($build['diff_preview']['content']['links'])) { |
284 | 293 |
unset($build['diff_preview']['content']['links']); |
285 | 294 |
} |
... | ... | |
291 | 300 |
} |
292 | 301 |
|
293 | 302 |
/** |
294 |
* Creates an array of rows which represent the difference between nodes.
|
|
303 |
* Creates an array of rows which represent the difference between two entities.
|
|
295 | 304 |
* |
296 |
* @param object $old_node
|
|
297 |
* Node for comparison which will be displayed on the left side.
|
|
298 |
* @param object $new_node
|
|
299 |
* Node for comparison which will be displayed on the right side.
|
|
300 |
* @param boolean $state
|
|
301 |
* The state to render for the diff.
|
|
305 |
* @param object $left_entity
|
|
306 |
* Entity for comparison which will be displayed on the left side.
|
|
307 |
* @param object $right_entity
|
|
308 |
* Entity for comparison which will be displayed on the right side.
|
|
309 |
* @param array $context
|
|
310 |
* The context used to render the diff.
|
|
302 | 311 |
*/ |
303 |
function _diff_body_rows($old_node, $new_node, $state = 'raw') {
|
|
312 |
function diff_entity_body_rows($entity_type, $left_entity, $right_entity, $context = array()) {
|
|
304 | 313 |
// This is an unique index only, so no need for drupal_static(). |
305 | 314 |
static $table_row_counter = 0; |
306 | 315 |
|
307 | 316 |
if ($theme = variable_get('diff_theme', 'default')) { |
308 | 317 |
drupal_add_css(drupal_get_path('module', 'diff') . "/css/diff.{$theme}.css"); |
309 | 318 |
} |
310 |
module_load_include('inc', 'diff', 'includes/node'); |
|
311 | 319 |
|
312 | 320 |
$rows = array(); |
313 | 321 |
$any_visible_change = FALSE; |
314 |
$context = array( |
|
315 |
'entity_type' => 'node',
|
|
316 |
'states' => array($state),
|
|
322 |
$context += array(
|
|
323 |
'entity_type' => $entity_type,
|
|
324 |
'states' => array('raw'),
|
|
317 | 325 |
'view_mode' => 'diff_standard', |
318 | 326 |
); |
327 |
$state = current($context['states']); |
|
319 | 328 |
|
320 |
$node_diffs = diff_compare_entities($old_node, $new_node, $context);
|
|
329 |
$entity_diffs = diff_compare_entities($left_entity, $right_entity, $context);
|
|
321 | 330 |
|
322 | 331 |
// Track line numbers between multiple diffs. |
323 | 332 |
$line_stats = array( |
... | ... | |
326 | 335 |
); |
327 | 336 |
|
328 | 337 |
// Render diffs for each. |
329 |
foreach ($node_diffs as $node_diff) {
|
|
330 |
$show_header = !empty($node_diff['#name']);
|
|
338 |
foreach ($entity_diffs as $entity_diff) {
|
|
339 |
$show_header = !empty($entity_diff['#name']);
|
|
331 | 340 |
// These are field level settings. |
332 |
if ($show_header && isset($node_diff['#settings']['show_header'])) {
|
|
333 |
$show_header = $show_header && $node_diff['#settings']['show_header'];
|
|
341 |
if ($show_header && isset($entity_diff['#settings']['show_header'])) {
|
|
342 |
$show_header = $show_header && $entity_diff['#settings']['show_header'];
|
|
334 | 343 |
} |
335 | 344 |
|
336 | 345 |
// Line counting and line header options. |
337 |
if (empty($node_diff['#settings']['line_counter'])) {
|
|
346 |
if (empty($entity_diff['#settings']['line_counter'])) {
|
|
338 | 347 |
$line_counter = FALSE; |
339 | 348 |
} |
340 | 349 |
else { |
341 |
$line_counter = $node_diff['#settings']['line_counter'];
|
|
350 |
$line_counter = $entity_diff['#settings']['line_counter'];
|
|
342 | 351 |
} |
343 | 352 |
// Every call to 'line' resets the counters. |
344 | 353 |
if ($line_counter) { |
... | ... | |
354 | 363 |
$line_stats_ref = NULL; |
355 | 364 |
} |
356 | 365 |
|
357 |
list($old, $new) = diff_extract_state($node_diff, $state);
|
|
358 |
if ($node_diff_rows = diff_get_rows($old, $new, $line_counter && $line_counter != 'hidden', $line_stats_ref)) {
|
|
366 |
list($left, $right) = diff_extract_state($entity_diff, $state);
|
|
367 |
if ($entity_diff_rows = diff_get_rows($left, $right, $line_counter && $line_counter != 'hidden', $line_stats_ref)) {
|
|
359 | 368 |
if ($line_counter && $line_counter != 'line') { |
360 | 369 |
$line_stats['offset']['x'] += $line_stats_ref['counter']['x']; |
361 | 370 |
$line_stats['offset']['y'] += $line_stats_ref['counter']['y']; |
... | ... | |
363 | 372 |
if ($show_header) { |
364 | 373 |
$rows['diff-header-' . $table_row_counter++] = array( |
365 | 374 |
array( |
366 |
'data' => t('Changes to %name', array('%name' => $node_diff['#name'])),
|
|
375 |
'data' => t('Changes to %name', array('%name' => $entity_diff['#name'])),
|
|
367 | 376 |
'class' => 'diff-section-title', |
368 | 377 |
'colspan' => 4, |
369 | 378 |
), |
... | ... | |
371 | 380 |
} |
372 | 381 |
// To avoid passing counter to the Diff engine, index rows manually here |
373 | 382 |
// to allow modules to interact with the table. i.e. no array_merge(). |
374 |
foreach ($node_diff_rows as $row) {
|
|
383 |
foreach ($entity_diff_rows as $row) {
|
|
375 | 384 |
$rows['diff-row-' . $table_row_counter++] = $row; |
376 | 385 |
} |
377 | 386 |
$any_visible_change = TRUE; |
... | ... | |
385 | 394 |
'colspan' => 4, |
386 | 395 |
), |
387 | 396 |
); |
388 |
// @todo: revise this. |
|
389 |
// Needed to keep safari happy. |
|
390 |
$rows['diff-empty-' . $table_row_counter++] = array( |
|
391 |
array('data' => ''), |
|
392 |
array('data' => ''), |
|
393 |
array('data' => ''), |
|
394 |
array('data' => ''), |
|
395 |
); |
|
396 | 397 |
} |
397 |
|
|
398 | 398 |
return $rows; |
399 | 399 |
} |
400 | 400 |
|
401 |
/** |
|
402 |
* Creates an array of rows which represent the difference between nodes. |
|
403 |
* |
|
404 |
* @param object $old_node |
|
405 |
* Node for comparison which will be displayed on the left side. |
|
406 |
* @param object $new_node |
|
407 |
* Node for comparison which will be displayed on the right side. |
|
408 |
* @param bool $state |
|
409 |
* The state to render for the diff. |
|
410 |
*/ |
|
411 |
function _diff_body_rows($old_node, $new_node, $state = 'raw') { |
|
412 |
$context = array( |
|
413 |
'states' => array($state), |
|
414 |
'view_mode' => 'diff_standard', |
|
415 |
); |
|
416 |
return diff_entity_body_rows('node', $old_node, $new_node, $context); |
|
417 |
} |
|
418 |
|
|
401 | 419 |
/** |
402 | 420 |
* Generic callback to compare two entities. |
403 | 421 |
*/ |
... | ... | |
460 | 478 |
if (!isset($diff['#sorted'])) { |
461 | 479 |
uasort($diff, 'element_sort'); |
462 | 480 |
} |
481 |
else { |
|
482 |
unset($diff['#sorted']); |
|
483 |
} |
|
463 | 484 |
|
464 | 485 |
// Process the array and get line counts per field. |
465 | 486 |
array_walk($diff, 'diff_process_state_lines'); |
... | ... | |
467 | 488 |
return $diff; |
468 | 489 |
} |
469 | 490 |
|
491 |
/** |
|
492 |
* Helper function to get line counts per field. |
|
493 |
*/ |
|
470 | 494 |
function diff_process_state_lines(&$diff, $key) { |
471 | 495 |
foreach ($diff['#states'] as $state => $data) { |
472 | 496 |
if (isset($data['#old'])) { |
... | ... | |
509 | 533 |
} |
510 | 534 |
|
511 | 535 |
if (!isset($plain_old) && isset($old)) { |
512 |
if (is_array($old)) { |
|
513 |
$diff['#states'][$state . '_plain']['#old'] = $markdown ? array_map($markdown, $old) : $old; |
|
514 |
} |
|
515 |
else { |
|
516 |
$diff['#states'][$state . '_plain']['#old'] = $markdown ? $markdown($old) : $old; |
|
517 |
} |
|
536 |
$diff['#states'][$state . '_plain']['#old'] = _diff_apply_markdown($markdown, $old); |
|
518 | 537 |
} |
519 | 538 |
if (!isset($plain_new) && isset($new)) { |
520 |
if (is_array($new)) { |
|
521 |
$diff['#states'][$state . '_plain']['#new'] = $markdown ? array_map($markdown, $new) : $new; |
|
522 |
} |
|
523 |
else { |
|
524 |
$diff['#states'][$state . '_plain']['#new'] = $markdown ? $markdown($new) : $new; |
|
539 |
$diff['#states'][$state . '_plain']['#new'] = _diff_apply_markdown($markdown, $new); |
|
540 |
} |
|
541 |
} |
|
542 |
|
|
543 |
/** |
|
544 |
* Helper function to clear newlines from the content. |
|
545 |
*/ |
|
546 |
function _diff_apply_markdown($markdown, $items) { |
|
547 |
if (!$markdown) { |
|
548 |
return $items; |
|
549 |
} |
|
550 |
if (is_array($items)) { |
|
551 |
$items = array_map($markdown, $items); |
|
552 |
foreach ($items as &$item) { |
|
553 |
$item = trim($item, "\n"); |
|
525 | 554 |
} |
555 |
return $items; |
|
556 |
} |
|
557 |
else { |
|
558 |
return trim($markdown($items), "\n"); |
|
526 | 559 |
} |
527 | 560 |
} |
528 | 561 |
|
... | ... | |
534 | 567 |
* @param int $vid |
535 | 568 |
* Version ID to look for. |
536 | 569 |
* |
537 |
* @return boolean|integer
|
|
570 |
* @return bool|int
|
|
538 | 571 |
* Returns FALSE if $vid is the last entry. |
539 | 572 |
*/ |
540 | 573 |
function _diff_get_next_vid($node_revisions, $vid) { |
... | ... | |
553 | 586 |
* |
554 | 587 |
* @param array $node_revisions |
555 | 588 |
* Array of node revision IDs in descending order. |
556 |
* @param integer $vid
|
|
589 |
* @param int $vid |
|
557 | 590 |
* Version ID to look for. |
558 | 591 |
* |
559 |
* @return boolean|integer
|
|
592 |
* @return bool|int
|
|
560 | 593 |
* Returns FALSE if $vid is the first entry. |
561 | 594 |
*/ |
562 | 595 |
function _diff_get_previous_vid($node_revisions, $vid) { |
... | ... | |
615 | 648 |
* normally rendered content of the specified revision. |
616 | 649 |
*/ |
617 | 650 |
function diff_inline_show($node, $vid = 0, $metadata = TRUE) { |
618 |
$new_node = $vid ? node_load($node->nid, $vid, TRUE) : clone $node;
|
|
651 |
$new_node = $vid ? node_load($node->nid, $vid) : clone $node; |
|
619 | 652 |
node_build_content($new_node); |
620 | 653 |
$new = drupal_render($new_node->content); |
621 | 654 |
|
622 | 655 |
$old = $vid ? _diff_get_previous_vid(node_revision_list($node), $vid) : 0; |
623 | 656 |
if ($old) { |
624 |
$old_node = node_load($node->nid, $old, TRUE);
|
|
657 |
$old_node = node_load($node->nid, $old); |
|
625 | 658 |
node_build_content($old_node); |
626 | 659 |
$old = drupal_render($old_node->content); |
627 | 660 |
$output = $metadata ? theme('diff_inline_metadata', array('node' => $new_node)) : ''; |
Formats disponibles : Unified diff
Weekly update of contrib modules