Projet

Général

Profil

Paste
Télécharger (4,61 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / diff / diff.theme.inc @ 661d64c9

1
<?php
2

    
3
/**
4
 * @file
5
 * Themeable function callbacks for diff.module.
6
 */
7

    
8
/**
9
 * Theme function to display the revisions formular.
10
 */
11
function theme_diff_node_revisions($vars) {
12
  $form = $vars['form'];
13
  $output = '';
14

    
15
  // Overview table:
16
  $header = array(
17
    t('Revision'),
18
    array('data' => drupal_render($form['submit']), 'colspan' => 2),
19
    array('data' => t('Operations'), 'colspan' => 2),
20
  );
21
  if (isset($form['info']) && is_array($form['info'])) {
22
    foreach (element_children($form['info']) as $key) {
23
      $row = array();
24
      if (isset($form['operations'][$key][0])) {
25
        // Note: even if the commands for revert and delete are not permitted,
26
        // the array is not empty since we set a dummy in this case.
27
        $row[] = drupal_render($form['info'][$key]);
28
        $row[] = drupal_render($form['diff']['old'][$key]);
29
        $row[] = drupal_render($form['diff']['new'][$key]);
30
        $row[] = drupal_render($form['operations'][$key][0]);
31
        $row[] = drupal_render($form['operations'][$key][1]);
32
        $rows[] = array(
33
          'data' => $row,
34
          'class' => array('diff-revision'),
35
        );
36
      }
37
      else {
38
        // The current revision (no commands to revert or delete).
39
        $row[] = array(
40
          'data' => drupal_render($form['info'][$key]),
41
          'class' => array('revision-current'),
42
        );
43
        $row[] = array(
44
          'data' => drupal_render($form['diff']['old'][$key]),
45
          'class' => array('revision-current'),
46
        );
47
        $row[] = array(
48
          'data' => drupal_render($form['diff']['new'][$key]),
49
          'class' => array('revision-current'),
50
        );
51
        $revision = $form['info'][$key]['#revision'];
52
        if ($revision && !empty($revision->status)) {
53
          $message = t('This is the published revision.');
54
        }
55
        else {
56
          $message = t('This is the current revision.');
57
        }
58
        $row[] = array(
59
          'data' => '<strong>' . $message . '</strong>',
60
          'class' => array('revision-current'),
61
          'colspan' => '2',
62
        );
63
        $rows[] = array(
64
          'data' => $row,
65
          'class' => array('revision-published diff-revision'),
66
        );
67
      }
68
    }
69
  }
70
  $output .= theme('table__diff__revisions', array(
71
    'header' => $header,
72
    'rows' => $rows,
73
    'sticky' => FALSE,
74
    'attributes' => array('class' => array('diff-revisions')),
75
  ));
76

    
77
  $output .= drupal_render_children($form);
78
  return $output;
79
}
80

    
81
/**
82
 * Theme function for a header line in the diff.
83
 */
84
function theme_diff_header_line($vars) {
85
  return '<strong>' . t('Line @lineno', array('@lineno' => $vars['lineno'])) . '</strong>';
86
}
87

    
88
/**
89
 * Theme function for a content line in the diff.
90
 */
91
function theme_diff_content_line($vars) {
92
  return '<div>' . $vars['line'] . '</div>';
93
}
94

    
95
/**
96
 * Theme function for an empty line in the diff.
97
 */
98
function theme_diff_empty_line($vars) {
99
  return $vars['line'];
100
}
101

    
102
/**
103
 * Theme function for inline diff form.
104
 */
105
function theme_diff_inline_form($vars) {
106
  if ($theme = variable_get('diff_theme', 'default')) {
107
    drupal_add_css(drupal_get_path('module', 'diff') . "/css/diff.{$theme}.css");
108
  }
109
  return drupal_render_children($vars['form']);
110
}
111

    
112
/**
113
 * Display inline diff metadata.
114
 */
115
function theme_diff_inline_metadata($vars) {
116
  if ($theme = variable_get('diff_theme', 'default')) {
117
    drupal_add_css(drupal_get_path('module', 'diff') . "/css/diff.{$theme}.css");
118
  }
119
  $node = $vars['node'];
120

    
121
  $output = "<div class='diff-inline-metadata clear-block'>";
122
  $output .= "<div class='diff-inline-byline'>";
123
  $output .= t('Updated by !name on @date', array(
124
    '!name' => theme('username', array('account' => user_load($node->revision_uid))),
125
    '@date' => format_date($node->revision_timestamp, 'small'),
126
  ));
127
  $output .= "</div>";
128
  $output .= "<div class='diff-inline-legend clear-block'>";
129
  $output .= "<label>" . t('Legend') . "</label>";
130
  $output .= theme('diff_inline_chunk', array('text' => t('Added'), 'type' => 'add'));
131
  $output .= theme('diff_inline_chunk', array('text' => t('Changed'), 'type' => 'change'));
132
  $output .= theme('diff_inline_chunk', array('text' => t('Deleted'), 'type' => 'delete'));
133
  $output .= "</div>";
134
  $output .= "</div>";
135
  return $output;
136
}
137

    
138
/**
139
 * Theme a span of changed text in an inline diff display.
140
 */
141
function theme_diff_inline_chunk($vars) {
142
  switch ($vars['type']) {
143
    case 'add':
144
      return "<span class='diff-added'>{$vars['text']}</span>";
145

    
146
    case 'change':
147
      return "<span class='diff-changed'>{$vars['text']}</span>";
148

    
149
    case 'delete':
150
      return "<span class='diff-deleted'>{$vars['text']}</span>";
151

    
152
    default:
153
      return $vars['text'];
154

    
155
  }
156
}