Projet

Général

Profil

Paste
Télécharger (8,34 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / advanced_forum / includes / template_preprocess_advanced_forum_topic_list_view.inc @ c169e7c4

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
function _template_preprocess_advanced_forum_topic_list_view(&$variables) {
9

    
10
  // Even though this isn't needed for the actual topic list view, the other
11
  // views use this same style and need the AF style files added.
12
  _advanced_forum_add_files();
13
  advanced_forum_add_template_suggestions("topic-list-view", $variables);
14

    
15
  $view = $variables['view'];
16

    
17
  // We need the raw data for this grouping, which is passed in as $variables['rows'].
18
  // However, the template also needs to use for the rendered fields.  We
19
  // therefore swap the raw data out to a new variable and reset $variables['rows']
20
  // so that it can get rebuilt.
21
  $result = $variables['rows'];
22
  $variables['rows'] = array();
23
  $variables['field_classes'] = array();
24

    
25
  $options = $view->style_plugin->options;
26
  $handler = $view->style_plugin;
27

    
28
  $fields = &$view->field;
29
  $columns = $handler->sanitize_columns($options['columns'], $fields);
30

    
31
  $active = !empty($handler->active) ? $handler->active : '';
32
  $order = !empty($handler->order) ? $handler->order : 'asc';
33

    
34
  $query = tablesort_get_query_parameters();
35
  if (isset($view->exposed_raw_input)) {
36
    $query += $view->exposed_raw_input;
37
  }
38

    
39
  $header = array();
40

    
41
  $forum = $view->style_plugin->get_forum_ids();
42

    
43
  // Fields must be rendered in order as of Views 2.3, so we will pre-render
44
  // everything.
45
  $renders = $handler->render_fields($result);
46

    
47
  $keys = array_keys($view->field);
48
  $stickies_done = FALSE;
49
  $sticky_count = 0;
50

    
51
  foreach ($result as $count => $row) {
52
    // Grab the teaser so it can be used on the title of the td as a popup
53
    // preview. By default, the view provides the teaser as a popup on the
54
    // title link.
55
    if (!empty($renders[$count]['teaser'])) {
56
      $teaser = $renders[$count]['teaser'];
57
      $teaser = htmlentities($teaser);
58
      $teasers[$count] = $teaser;
59
    }
60

    
61
    // Determine stickiness.
62
    if (!$stickies_done) {
63
      $sticky[$count] = !empty($row->topic_is_sticky);
64
      if ($sticky[$count]) {
65
        $sticky_count++;
66
        $variables['row_classes'][$count][] = 'sticky';
67
      }
68
      else {
69
        $stickies_done = TRUE;
70
        if ($sticky_count) {
71
          // This ends up appearing only if we have both sticky and non sticky posts.
72
          // Otherwise it will never show up.
73
          $variables['row_classes'][$count - 1][] = 'forum-last-sticky';
74
        }
75
      }
76
    }
77

    
78
    // Shadow (moved) topics.
79
    if ($forum && !in_array($row->topic_actual_forum, $forum)) {
80
      $term = taxonomy_term_load($row->topic_actual_forum);
81
      $variables['shadow'][$count] = theme('advanced_forum_shadow_topic', array(
82
        'title' => $row->node_title,
83
        'nid' => $row->nid,
84
        'new_forum' => empty($term->name) ? "" : $term->name
85
          ));
86
    }
87
    else {
88
      $variables['shadow'][$count] = FALSE;
89
    }
90
  }
91

    
92
  // Make the sticky variable available to the template.
93
  $variables['sticky'] = $sticky;
94
  $variables['teasers'] = empty($teasers) ? NULL : $teasers;
95

    
96
  foreach ($columns as $field => $column) {
97
    // Create a second variable so we can easily find what fields we have and what the
98
    // CSS classes should be.
99
    $variables['fields'][$field] = drupal_clean_css_identifier($field);
100
    if ($active == $field) {
101
      $variables['fields'][$field] .= ' active';
102
    }
103

    
104
    // render the header labels
105
    if ($field == $column && empty($fields[$field]->options['exclude'])) {
106
      $label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : '');
107
      if (empty($options['info'][$field]['sortable']) || !$fields[$field]->click_sortable()) {
108
        $variables['header'][$field] = $label;
109
      }
110
      else {
111
        $initial = !empty($options['info'][$field]['default_sort_order']) ? $options['info'][$field]['default_sort_order'] : 'asc';
112

    
113
        if ($active == $field) {
114
          $initial = ($order == 'asc') ? 'desc' : 'asc';
115
        }
116

    
117
        $title = t('sort by @s', array('@s' => $label));
118
        if ($active == $field) {
119
          $label .= theme('tablesort_indicator', array('style' => $initial));
120
        }
121

    
122
        $query['order'] = $field;
123
        $query['sort'] = $initial;
124
        $link_options = array(
125
          'html' => TRUE,
126
          'attributes' => array('title' => $title),
127
          'query' => $query,
128
        );
129
        $variables['header'][$field] = l($label, $_GET['q'], $link_options);
130
      }
131

    
132
      $variables['header_classes'][$field] = '';
133
      // Set up the header label class.
134
      if ($fields[$field]->options['element_default_classes']) {
135
        $variables['header_classes'][$field] .= "views-field views-field-" . $variables['fields'][$field];
136
      }
137
      $class = $fields[$field]->element_label_classes(0);
138
      if ($class) {
139
        if ($variables['header_classes'][$field]) {
140
          $variables['header_classes'][$field] .= ' ';
141
        }
142
        $variables['header_classes'][$field] .= $class;
143
      }
144

    
145
      // Add a header label wrapper if one was selected.
146
      if ($variables['header'][$field]) {
147
        $element_label_type = $fields[$field]->element_label_type(TRUE, TRUE);
148
        if ($element_label_type) {
149
          $variables['header'][$field] = '<' . $element_label_type . '>' . $variables['header'][$field] . '</' . $element_label_type . '>';
150
        }
151
      }
152
    }
153

    
154
    // Add a CSS align class to each field if one was set
155
    if (!empty($options['info'][$field]['align'])) {
156
      $variables['fields'][$field] .= ' ' . drupal_clean_css_identifier($options['info'][$field]['align']);
157
    }
158

    
159
    // Render each field into its appropriate column.
160
    foreach ($result as $num => $row) {
161
      // Add field classes
162
      $variables['field_classes'][$field][$num] = '';
163
      if ($fields[$field]->options['element_default_classes']) {
164
        $variables['field_classes'][$field][$num] = "views-field views-field-" . $variables['fields'][$field];
165
      }
166
      if ($classes = $fields[$field]->element_classes($num)) {
167
        if ($variables['field_classes'][$field][$num]) {
168
          $variables['field_classes'][$field][$num] .= ' ';
169
        }
170

    
171
        $variables['field_classes'][$field][$num] .= $classes;
172
      }
173
      $variables['field_attributes'][$field][$num] = array();
174

    
175
      if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) {
176
        $field_output = $renders[$num][$field];
177
        $element_type = $fields[$field]->element_type(TRUE, TRUE);
178
        if ($element_type) {
179
          $field_output = '<' . $element_type . '>' . $field_output . '</' . $element_type . '>';
180
        }
181

    
182
        // Don't bother with separators and stuff if the field does not show up.
183
        if (empty($field_output) && !empty($variables['rows'][$num][$column])) {
184
          continue;
185
        }
186

    
187
        // Place the field into the column, along with an optional separator.
188
        if (!empty($variables['rows'][$num][$column])) {
189
          if (!empty($options['info'][$column]['separator'])) {
190
            $variables['rows'][$num][$column] .= filter_xss_admin($options['info'][$column]['separator']);
191
          }
192
        }
193
        else {
194
          $variables['rows'][$num][$column] = '';
195
        }
196

    
197
        $variables['rows'][$num][$column] .= $field_output;
198
      }
199
    }
200
  }
201

    
202
  $count = 0;
203
  foreach ($variables['rows'] as $num => $row) {
204
    $variables['row_classes'][$num][] = ($count++ % 2 == 0) ? 'odd' : 'even';
205
    if ($row_class = $handler->get_row_class($num)) {
206
      $variables['row_classes'][$num][] = $row_class;
207
    }
208
  }
209

    
210
  $variables['row_classes'][0][] = 'views-row-first';
211
  $variables['row_classes'][count($variables['row_classes']) - 1][] = 'views-row-last';
212

    
213
  $variables['classes_array'] = array('forum-table', 'forum-table-topics');
214
  if (empty($variables['rows']) && !empty($options['empty_table'])) {
215
    $variables['rows'][0][0] = $view->display_handler->render_area('empty');
216
    // Calculate the amounts of rows with output.
217
    $variables['field_attributes'][0][0]['colspan'] = count($variables['header']);
218
    $variables['field_classes'][0][0] = 'views-empty';
219
  }
220

    
221

    
222
  if (!empty($options['sticky'])) {
223
    drupal_add_js('misc/tableheader.js');
224
    $variables['classes_array'][] = "sticky-enabled";
225
  }
226
  $variables['classes_array'][] = 'cols-' . count($variables['header']);
227

    
228
  if (!empty($handler->options['summary'])) {
229
    $variables['attributes_array'] = array('summary' => $handler->options['summary']);
230
  }
231
}