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