1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Holds the contents of a preprocess function moved into its own file
|
6
|
* to ease memory requirements and having too much code in one file.
|
7
|
*/
|
8
|
|
9
|
/**
|
10
|
* Preprocess advanced forum topic list.
|
11
|
*/
|
12
|
function _template_preprocess_advanced_forum_topic_list_view(&$variables) {
|
13
|
|
14
|
// Even though this isn't needed for the actual topic list view, the other
|
15
|
// views use this same style and need the AF style files added.
|
16
|
_advanced_forum_add_files();
|
17
|
advanced_forum_add_template_suggestions("topic-list-view", $variables);
|
18
|
|
19
|
$view = $variables['view'];
|
20
|
|
21
|
// We need the raw data for this grouping, which is passed in as $variables['rows'].
|
22
|
// However, the template also needs to use for the rendered fields. We
|
23
|
// therefore swap the raw data out to a new variable and reset $variables['rows']
|
24
|
// so that it can get rebuilt.
|
25
|
$result = $variables['rows'];
|
26
|
$variables['rows'] = array();
|
27
|
$variables['field_classes'] = array();
|
28
|
|
29
|
$options = $view->style_plugin->options;
|
30
|
$handler = $view->style_plugin;
|
31
|
|
32
|
$fields = &$view->field;
|
33
|
$columns = $handler->sanitize_columns($options['columns'], $fields);
|
34
|
|
35
|
$active = !empty($handler->active) ? $handler->active : '';
|
36
|
$order = !empty($handler->order) ? $handler->order : 'asc';
|
37
|
|
38
|
$query = tablesort_get_query_parameters();
|
39
|
if (isset($view->exposed_raw_input)) {
|
40
|
$query += $view->exposed_raw_input;
|
41
|
}
|
42
|
|
43
|
$header = array();
|
44
|
|
45
|
$forum = $view->style_plugin->get_forum_ids();
|
46
|
|
47
|
// Fields must be rendered in order as of Views 2.3, so we will pre-render
|
48
|
// everything.
|
49
|
$renders = $handler->render_fields($result);
|
50
|
|
51
|
$keys = array_keys($view->field);
|
52
|
$stickies_done = FALSE;
|
53
|
$sticky_count = 0;
|
54
|
|
55
|
foreach ($result as $count => $row) {
|
56
|
// Grab the teaser so it can be used on the title of the td as a popup
|
57
|
// preview. By default, the view provides the teaser as a popup on the
|
58
|
// title link.
|
59
|
if (!empty($renders[$count]['teaser'])) {
|
60
|
$teaser = $renders[$count]['teaser'];
|
61
|
$teaser = htmlentities($teaser);
|
62
|
$teasers[$count] = $teaser;
|
63
|
}
|
64
|
|
65
|
// Determine stickiness.
|
66
|
if (!$stickies_done) {
|
67
|
$sticky[$count] = !empty($row->topic_is_sticky);
|
68
|
if ($sticky[$count]) {
|
69
|
$sticky_count++;
|
70
|
$variables['row_classes'][$count][] = 'sticky';
|
71
|
}
|
72
|
else {
|
73
|
$stickies_done = TRUE;
|
74
|
if ($sticky_count) {
|
75
|
// This ends up appearing only if we have both sticky and non sticky posts.
|
76
|
// Otherwise it will never show up.
|
77
|
$variables['row_classes'][$count - 1][] = 'forum-last-sticky';
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
|
82
|
// Shadow (moved) topics.
|
83
|
if ($forum && !in_array($row->topic_actual_forum, $forum)) {
|
84
|
$term = taxonomy_term_load($row->topic_actual_forum);
|
85
|
$variables['shadow'][$count] = theme('advanced_forum_shadow_topic', array(
|
86
|
'title' => $row->node_title,
|
87
|
'nid' => $row->nid,
|
88
|
'new_forum' => empty($term->name) ? "" : $term->name,
|
89
|
));
|
90
|
}
|
91
|
else {
|
92
|
$variables['shadow'][$count] = FALSE;
|
93
|
}
|
94
|
}
|
95
|
|
96
|
// Make the sticky variable available to the template.
|
97
|
$variables['sticky'] = $sticky;
|
98
|
$variables['teasers'] = empty($teasers) ? NULL : $teasers;
|
99
|
|
100
|
foreach ($columns as $field => $column) {
|
101
|
// Create a second variable so we can easily find what fields we have and what the
|
102
|
// CSS classes should be.
|
103
|
$variables['fields'][$field] = drupal_clean_css_identifier($field);
|
104
|
if ($active == $field) {
|
105
|
$variables['fields'][$field] .= ' active';
|
106
|
}
|
107
|
|
108
|
// Render the header labels.
|
109
|
if ($field == $column && empty($fields[$field]->options['exclude'])) {
|
110
|
$label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : '');
|
111
|
if (empty($options['info'][$field]['sortable']) || !$fields[$field]->click_sortable()) {
|
112
|
$variables['header'][$field] = $label;
|
113
|
}
|
114
|
else {
|
115
|
$initial = !empty($options['info'][$field]['default_sort_order']) ? $options['info'][$field]['default_sort_order'] : 'asc';
|
116
|
|
117
|
if ($active == $field) {
|
118
|
$initial = ($order == 'asc') ? 'desc' : 'asc';
|
119
|
}
|
120
|
|
121
|
$title = t('sort by @s', array('@s' => $label));
|
122
|
if ($active == $field) {
|
123
|
$label .= theme('tablesort_indicator', array('style' => $initial));
|
124
|
}
|
125
|
|
126
|
$query['order'] = $field;
|
127
|
$query['sort'] = $initial;
|
128
|
$link_options = array(
|
129
|
'html' => TRUE,
|
130
|
'attributes' => array('title' => $title),
|
131
|
'query' => $query,
|
132
|
);
|
133
|
$variables['header'][$field] = l($label, $_GET['q'], $link_options);
|
134
|
}
|
135
|
|
136
|
$variables['header_classes'][$field] = '';
|
137
|
// Set up the header label class.
|
138
|
if ($fields[$field]->options['element_default_classes']) {
|
139
|
$variables['header_classes'][$field] .= "views-field views-field-" . $variables['fields'][$field];
|
140
|
}
|
141
|
$class = $fields[$field]->element_label_classes(0);
|
142
|
if ($class) {
|
143
|
if ($variables['header_classes'][$field]) {
|
144
|
$variables['header_classes'][$field] .= ' ';
|
145
|
}
|
146
|
$variables['header_classes'][$field] .= $class;
|
147
|
}
|
148
|
|
149
|
// Add a header label wrapper if one was selected.
|
150
|
if ($variables['header'][$field]) {
|
151
|
$element_label_type = $fields[$field]->element_label_type(TRUE, TRUE);
|
152
|
if ($element_label_type) {
|
153
|
$variables['header'][$field] = '<' . $element_label_type . '>' . $variables['header'][$field] . '</' . $element_label_type . '>';
|
154
|
}
|
155
|
}
|
156
|
}
|
157
|
|
158
|
// Add a CSS align class to each field if one was set.
|
159
|
if (!empty($options['info'][$field]['align'])) {
|
160
|
$variables['fields'][$field] .= ' ' . drupal_clean_css_identifier($options['info'][$field]['align']);
|
161
|
}
|
162
|
|
163
|
// Render each field into its appropriate column.
|
164
|
foreach ($result as $num => $row) {
|
165
|
// Add field classes.
|
166
|
$variables['field_classes'][$field][$num] = '';
|
167
|
if ($fields[$field]->options['element_default_classes']) {
|
168
|
$variables['field_classes'][$field][$num] = "views-field views-field-" . $variables['fields'][$field];
|
169
|
}
|
170
|
if ($classes = $fields[$field]->element_classes($num)) {
|
171
|
if ($variables['field_classes'][$field][$num]) {
|
172
|
$variables['field_classes'][$field][$num] .= ' ';
|
173
|
}
|
174
|
|
175
|
$variables['field_classes'][$field][$num] .= $classes;
|
176
|
}
|
177
|
$variables['field_attributes'][$field][$num] = array();
|
178
|
|
179
|
if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) {
|
180
|
$field_output = $renders[$num][$field];
|
181
|
$element_type = $fields[$field]->element_type(TRUE, TRUE);
|
182
|
if ($element_type) {
|
183
|
$field_output = '<' . $element_type . '>' . $field_output . '</' . $element_type . '>';
|
184
|
}
|
185
|
|
186
|
// Don't bother with separators and stuff if the field does not show up.
|
187
|
if (empty($field_output) && !empty($variables['rows'][$num][$column])) {
|
188
|
continue;
|
189
|
}
|
190
|
|
191
|
// Place the field into the column, along with an optional separator.
|
192
|
if (!empty($variables['rows'][$num][$column])) {
|
193
|
if (!empty($options['info'][$column]['separator'])) {
|
194
|
$variables['rows'][$num][$column] .= filter_xss_admin($options['info'][$column]['separator']);
|
195
|
}
|
196
|
}
|
197
|
else {
|
198
|
$variables['rows'][$num][$column] = '';
|
199
|
}
|
200
|
|
201
|
$variables['rows'][$num][$column] .= $field_output;
|
202
|
}
|
203
|
}
|
204
|
}
|
205
|
|
206
|
$count = 0;
|
207
|
foreach ($variables['rows'] as $num => $row) {
|
208
|
$variables['row_classes'][$num][] = ($count++ % 2 == 0) ? 'odd' : 'even';
|
209
|
if ($row_class = $handler->get_row_class($num)) {
|
210
|
$variables['row_classes'][$num][] = $row_class;
|
211
|
}
|
212
|
}
|
213
|
|
214
|
$variables['row_classes'][0][] = 'views-row-first';
|
215
|
$variables['row_classes'][count($variables['row_classes']) - 1][] = 'views-row-last';
|
216
|
|
217
|
if (!variable_get('advanced_forum_keep_classes', FALSE) || !is_array($variables['classes_array'])) {
|
218
|
// Add in our classes overwriting existing.
|
219
|
$variables['classes_array'] = array();
|
220
|
}
|
221
|
|
222
|
$variables['classes_array'][] = 'forum-table forum-table-topics';
|
223
|
if (empty($variables['rows']) && !empty($options['empty_table'])) {
|
224
|
$variables['rows'][0][0] = $view->display_handler->render_area('empty');
|
225
|
// Calculate the amounts of rows with output.
|
226
|
$variables['field_attributes'][0][0]['colspan'] = count($variables['header']);
|
227
|
$variables['field_classes'][0][0] = 'views-empty';
|
228
|
}
|
229
|
|
230
|
if (!empty($options['sticky'])) {
|
231
|
drupal_add_js('misc/tableheader.js');
|
232
|
$variables['classes_array'][] = "sticky-enabled";
|
233
|
}
|
234
|
$variables['classes_array'][] = 'cols-' . count($variables['header']);
|
235
|
|
236
|
if (!empty($handler->options['summary'])) {
|
237
|
$variables['attributes_array'] = array('summary' => $handler->options['summary']);
|
238
|
}
|
239
|
}
|