diff.theme.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. $row[] = array(
  49. 'data' => t('current revision'),
  50. 'class' => array('revision-current'),
  51. 'colspan' => '2',
  52. );
  53. $rows[] = array(
  54. 'data' => $row,
  55. 'class' => array('error diff-revision'),
  56. );
  57. }
  58. }
  59. }
  60. $output .= theme('table__diff__revisions', array(
  61. 'header' => $header,
  62. 'rows' => $rows,
  63. 'sticky' => FALSE,
  64. 'attributes' => array('class' => 'diff-revisions'),
  65. ));
  66. $output .= drupal_render_children($form);
  67. return $output;
  68. }
  69. /**
  70. * Theme functions
  71. */
  72. /**
  73. * Theme function for a header line in the diff.
  74. */
  75. function theme_diff_header_line($vars) {
  76. return '<strong>' . t('Line @lineno', array('@lineno' => $vars['lineno'])) . '</strong>';
  77. }
  78. /**
  79. * Theme function for a content line in the diff.
  80. */
  81. function theme_diff_content_line($vars) {
  82. return '<div>' . $vars['line'] . '</div>';
  83. }
  84. /**
  85. * Theme function for an empty line in the diff.
  86. */
  87. function theme_diff_empty_line($vars) {
  88. return $vars['line'];
  89. }
  90. /**
  91. * Theme function for inline diff form.
  92. */
  93. function theme_diff_inline_form($vars) {
  94. if ($theme = variable_get('diff_theme', 'default')) {
  95. drupal_add_css(drupal_get_path('module', 'diff') . "/css/diff.{$theme}.css");
  96. }
  97. return drupal_render_children($vars['form']);
  98. }
  99. /**
  100. * Display inline diff metadata.
  101. */
  102. function theme_diff_inline_metadata($vars) {
  103. if ($theme = variable_get('diff_theme', 'default')) {
  104. drupal_add_css(drupal_get_path('module', 'diff') . "/css/diff.{$theme}.css");
  105. }
  106. $node = $vars['node'];
  107. $output = "<div class='diff-inline-metadata clear-block'>";
  108. $output .= "<div class='diff-inline-byline'>";
  109. $output .= t('Updated by !name on @date', array(
  110. '!name' => theme('username', array('account' => user_load($node->revision_uid))),
  111. '@date' => format_date($node->revision_timestamp, 'small'),
  112. ));
  113. $output .= "</div>";
  114. $output .= "<div class='diff-inline-legend clear-block'>";
  115. $output .= "<label>" . t('Legend') . "</label>";
  116. $output .= theme('diff_inline_chunk', array('text' => t('Added'), 'type' => 'add'));
  117. $output .= theme('diff_inline_chunk', array('text' => t('Changed'), 'type' => 'change'));
  118. $output .= theme('diff_inline_chunk', array('text' => t('Deleted'), 'type' => 'delete'));
  119. $output .= "</div>";
  120. $output .= "</div>";
  121. return $output;
  122. }
  123. /**
  124. * Theme a span of changed text in an inline diff display.
  125. */
  126. function theme_diff_inline_chunk($vars) {
  127. switch ($vars['type']) {
  128. case 'add':
  129. return "<span class='diff-added'>{$vars['text']}</span>";
  130. case 'change':
  131. return "<span class='diff-changed'>{$vars['text']}</span>";
  132. case 'delete':
  133. return "<span class='diff-deleted'>{$vars['text']}</span>";
  134. default:
  135. return $vars['text'];
  136. }
  137. }