diff.theme.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * @file
  4. * Themeable function callbacks for diff.module.
  5. */
  6. /**
  7. * Theme function to display the revisions formular.
  8. */
  9. function theme_diff_node_revisions($vars) {
  10. $form = $vars['form'];
  11. $output = '';
  12. // Overview table:
  13. $header = array(
  14. t('Revision'),
  15. array('data' => drupal_render($form['submit']), 'colspan' => 2),
  16. array('data' => t('Operations'), 'colspan' => 2),
  17. );
  18. if (isset($form['info']) && is_array($form['info'])) {
  19. foreach (element_children($form['info']) as $key) {
  20. $row = array();
  21. if (isset($form['operations'][$key][0])) {
  22. // Note: even if the commands for revert and delete are not permitted,
  23. // the array is not empty since we set a dummy in this case.
  24. $row[] = drupal_render($form['info'][$key]);
  25. $row[] = drupal_render($form['diff']['old'][$key]);
  26. $row[] = drupal_render($form['diff']['new'][$key]);
  27. $row[] = drupal_render($form['operations'][$key][0]);
  28. $row[] = drupal_render($form['operations'][$key][1]);
  29. $rows[] = array(
  30. 'data' => $row,
  31. 'class' => array('diff-revision'),
  32. );
  33. }
  34. else {
  35. // The current revision (no commands to revert or delete).
  36. $row[] = array(
  37. 'data' => drupal_render($form['info'][$key]),
  38. 'class' => array('revision-current'),
  39. );
  40. $row[] = array(
  41. 'data' => drupal_render($form['diff']['old'][$key]),
  42. 'class' => array('revision-current'),
  43. );
  44. $row[] = array(
  45. 'data' => drupal_render($form['diff']['new'][$key]),
  46. 'class' => array('revision-current'),
  47. );
  48. $revision = $form['info'][$key]['#revision'];
  49. if ($revision && !empty($revision->status)) {
  50. $message = t('This is the published revision.');
  51. }
  52. else {
  53. $message = t('This is the current revision.');
  54. }
  55. $row[] = array(
  56. 'data' => '<strong>' . $message . '</strong>',
  57. 'class' => array('revision-current'),
  58. 'colspan' => '2',
  59. );
  60. $rows[] = array(
  61. 'data' => $row,
  62. 'class' => array('revision-published diff-revision'),
  63. );
  64. }
  65. }
  66. }
  67. $output .= theme('table__diff__revisions', array(
  68. 'header' => $header,
  69. 'rows' => $rows,
  70. 'sticky' => FALSE,
  71. 'attributes' => array('class' => array('diff-revisions')),
  72. ));
  73. $output .= drupal_render_children($form);
  74. return $output;
  75. }
  76. /**
  77. * Theme function for a header line in the diff.
  78. */
  79. function theme_diff_header_line($vars) {
  80. return '<strong>' . t('Line @lineno', array('@lineno' => $vars['lineno'])) . '</strong>';
  81. }
  82. /**
  83. * Theme function for a content line in the diff.
  84. */
  85. function theme_diff_content_line($vars) {
  86. return '<div>' . $vars['line'] . '</div>';
  87. }
  88. /**
  89. * Theme function for an empty line in the diff.
  90. */
  91. function theme_diff_empty_line($vars) {
  92. return $vars['line'];
  93. }
  94. /**
  95. * Theme function for inline diff form.
  96. */
  97. function theme_diff_inline_form($vars) {
  98. if ($theme = variable_get('diff_theme', 'default')) {
  99. drupal_add_css(drupal_get_path('module', 'diff') . "/css/diff.{$theme}.css");
  100. }
  101. return drupal_render_children($vars['form']);
  102. }
  103. /**
  104. * Display inline diff metadata.
  105. */
  106. function theme_diff_inline_metadata($vars) {
  107. if ($theme = variable_get('diff_theme', 'default')) {
  108. drupal_add_css(drupal_get_path('module', 'diff') . "/css/diff.{$theme}.css");
  109. }
  110. $node = $vars['node'];
  111. $output = "<div class='diff-inline-metadata clear-block'>";
  112. $output .= "<div class='diff-inline-byline'>";
  113. $output .= t('Updated by !name on @date', array(
  114. '!name' => theme('username', array('account' => user_load($node->revision_uid))),
  115. '@date' => format_date($node->revision_timestamp, 'small'),
  116. ));
  117. $output .= "</div>";
  118. $output .= "<div class='diff-inline-legend clear-block'>";
  119. $output .= "<label>" . t('Legend') . "</label>";
  120. $output .= theme('diff_inline_chunk', array('text' => t('Added'), 'type' => 'add'));
  121. $output .= theme('diff_inline_chunk', array('text' => t('Changed'), 'type' => 'change'));
  122. $output .= theme('diff_inline_chunk', array('text' => t('Deleted'), 'type' => 'delete'));
  123. $output .= "</div>";
  124. $output .= "</div>";
  125. return $output;
  126. }
  127. /**
  128. * Theme a span of changed text in an inline diff display.
  129. */
  130. function theme_diff_inline_chunk($vars) {
  131. switch ($vars['type']) {
  132. case 'add':
  133. return "<span class='diff-added'>{$vars['text']}</span>";
  134. case 'change':
  135. return "<span class='diff-changed'>{$vars['text']}</span>";
  136. case 'delete':
  137. return "<span class='diff-deleted'>{$vars['text']}</span>";
  138. default:
  139. return $vars['text'];
  140. }
  141. }