Projet

Général

Profil

Paste
Télécharger (10,5 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / busy / template.php @ 87dbc3bf

1
<?php
2

    
3

    
4
/**
5
 * Override or insert variables into the html template.
6
 */
7
function busy_process_html(&$vars) {
8
  // Hook into color.module
9
  if (module_exists('color')) {
10
    _color_html_alter($vars);
11
  }
12
}
13
/**
14
 * Add conditional stylesheets.
15
 */
16
function busy_preprocess_html(&$variables) {
17
  // Add conditional stylesheets for IE
18
  drupal_add_css(path_to_theme() . '/css/ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE), 'preprocess' => FALSE));
19
}
20

    
21
/**
22
 * Override or insert variables into the page template.
23
 */
24
function busy_process_page(&$vars) {
25
  // Hook into color.module
26
  if (module_exists('color')) {
27
    _color_page_alter($vars);
28
  }
29
}
30

    
31
/**
32
 * Override or insert variables into the page template.
33
 */
34
function busy_preprocess_page(&$vars) {
35
  // Prepare header.
36
  $site_fields = array();
37
  if (!empty($vars['site_name'])) {
38
    $site_fields[] = check_plain($vars['site_name']);
39
  }
40
  if (!empty($vars['site_slogan'])) {
41
    $site_fields[] = check_plain($vars['site_slogan']);
42
  }
43
  $vars['site_title'] = implode(' ', $site_fields);
44
  if (!empty($site_fields)) {
45
    $site_fields[0] = '<span>' . $site_fields[0] . '</span>';
46
  }
47
  $vars['site_html'] = implode(' ', $site_fields);
48

    
49
  // Set a variable for the site name title and logo alt attributes text.
50
  $slogan_text = filter_xss_admin(variable_get('site_slogan', ''));
51
  $site_name_text = filter_xss_admin(variable_get('site_name', 'Drupal'));
52
  $vars['site_name_and_slogan'] = $site_name_text . ' ' . $slogan_text;
53
}
54

    
55
/**
56
 * Override or insert variables into the node template.
57
 */
58
function busy_preprocess_node(&$vars) {
59
  if ($vars['page'] && isset($vars['content']['links']['comment']) && ($vars['comment_count'] > 0)) {
60
    if (isset($vars['content']['links']['comment']['#links']['comment_add'])) {
61
      $vars['content']['links']['comment']['#links']['comments_count'] = $vars['content']['links']['comment']['#links']['comment_add'];
62
    }
63
    $vars['content']['links']['comment']['#links']['comments_count']['title'] = t('@num_comments', array('@num_comments' => format_plural($vars['comment_count'], '1 comment', '@count comments')));
64
    $vars['content']['links']['comment']['#links']['comments_count']['attributes'] = array();
65
  }
66
  if (theme_get_setting('toggle_node_user_picture', 'busy') && $vars['picture']) {
67
    $vars['classes_array'][] = 'has-author-picture';
68
  }
69
}
70

    
71
/**
72
 * Process variables for comment.tpl.php.
73
 *
74
 * @see comment.tpl.php
75
 */
76
function busy_preprocess_comment(&$vars) {
77
  if (theme_get_setting('toggle_comment_user_picture', 'busy') && $vars['picture']) {
78
    $vars['classes_array'][] = 'has-author-picture';
79
  }
80
}
81

    
82
/**
83
 * Override html output of a menu tab.
84
 */
85
function busy_menu_local_task($variables) {
86
  $link = $variables['element']['#link'];
87
  $link_text = $link['title'];
88

    
89
  if (!empty($variables['element']['#active'])) {
90
    // Add text to indicate active tab for non-visual users.
91
    $active = '<span class="element-invisible">' . t('(active tab)') . '</span>';
92

    
93
    // If the link does not contain HTML already, check_plain() it now.
94
    // After we set 'html'=TRUE the link will not be sanitized by l().
95
    if (empty($link['localized_options']['html'])) {
96
      $link['title'] = check_plain($link['title']);
97
    }
98
    $link['localized_options']['html'] = TRUE;
99
    $link_text = t('!local-task-title !active', array('!local-task-title' => $link['title'], '!active' => $active));
100
  }
101

    
102
  $link_classes = array();
103
  if (!empty($variables['element']['#active'])) {
104
    $link_classes[] = 'active';
105
  }
106
  if (!empty($variables['element']['#last'])) {
107
    $link_classes[] = 'last';
108
  }
109
  return '<li' . ($link_classes ? ' class="' . implode(' ', $link_classes) . '"' : '') . '>' . l($link_text, $link['href'], $link['localized_options']) . "</li>\n";
110
}
111

    
112
/**
113
 * Format a query pager.
114
 *
115
 * Menu callbacks that display paged query results should call theme('pager') to
116
 * retrieve a pager control so that users can view other results.
117
 * Format a list of nearby pages with additional query results.
118
 *
119
 * @param $variables
120
 *   An associative array containing:
121
 *   - tags: An array of labels for the controls in the pager.
122
 *   - element: An optional integer to distinguish between multiple pagers on
123
 *     one page.
124
 *   - parameters: An associative array of query string parameters to append to
125
 *     the pager links.
126
 *   - quantity: The number of pages in the list.
127
 *
128
 * @return
129
 *   An HTML string that generates the query pager.
130
 *
131
 * @ingroup themeable
132
 */
133
function busy_pager($variables) {
134
  $tags = $variables['tags'];
135
  $element = $variables['element'];
136
  $parameters = array();
137
  if (isset($variables['parameters']) && !is_array($variables['parameters'])) {
138
    $parameters = array($variables['parameters']);
139
  }
140
  $quantity = $variables['quantity'];
141
  global $pager_page_array, $pager_total;
142

    
143
  // Calculate various markers within this pager piece:
144
  // Middle is used to "center" pages around the current page.
145
  $pager_middle = ceil($quantity / 2);
146
  // current is the page we are currently paged to
147
  $pager_current = $pager_page_array[$element] + 1;
148
  // first is the first page listed by this pager piece (re quantity)
149
  $pager_first = $pager_current - $pager_middle + 1;
150
  // last is the last page listed by this pager piece (re quantity)
151
  $pager_last = $pager_current + $quantity - $pager_middle;
152
  // max is the maximum page number
153
  $pager_max = $pager_total[$element];
154
  // End of marker calculations.
155

    
156
  // Prepare for generation loop.
157
  $i = $pager_first;
158
  if ($pager_last > $pager_max) {
159
    // Adjust "center" if at end of query.
160
    $i = $i + ($pager_max - $pager_last);
161
    $pager_last = $pager_max;
162
  }
163
  if ($i <= 0) {
164
    // Adjust "center" if at start of query.
165
    $pager_last = $pager_last + (1 - $i);
166
    $i = 1;
167
  }
168
  // End of generation loop preparation.
169

    
170
  $parameters_wrap = array_merge($parameters, array('wrap' => TRUE));
171
  $li_first = theme('pager_first', array('text' => (isset($tags[0]) ? $tags[0] : t('« first')), 'element' => $element, 'parameters' => $parameters_wrap));
172
  $li_previous = theme('pager_previous', array('text' => (isset($tags[1]) ? $tags[1] : t('previous')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters_wrap));
173
  $li_next = theme('pager_next', array('text' => (isset($tags[3]) ? $tags[3] : t('next')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters_wrap));
174
  $li_last = theme('pager_last', array('text' => (isset($tags[4]) ? $tags[4] : t('last »')), 'element' => $element, 'parameters' => $parameters_wrap));
175

    
176
  if ($pager_total[$element] > 1) {
177
    // When there is more than one page, create the pager list.
178
    if ($i != $pager_max) {
179
      // Now generate the actual pager piece.
180
      for (; $i <= $pager_last && $i <= $pager_max; $i++) {
181
        if ($i < $pager_current) {
182
          $items[] = array(
183
            'class' => array('pager-item'),
184
            'data' => theme('pager_previous', array('text' => $i, 'element' => $element, 'interval' => ($pager_current - $i), 'parameters' => $parameters)),
185
          );
186
        }
187
        if ($i == $pager_current) {
188
          $items[] = array(
189
            'class' => array('pager-current'),
190
            'data' => $i,
191
          );
192
        }
193
        if ($i > $pager_current) {
194
          $items[] = array(
195
            'class' => array('pager-item'),
196
            'data' => theme('pager_next', array('text' => $i, 'element' => $element, 'interval' => ($i - $pager_current), 'parameters' => $parameters)),
197
          );
198
        }
199
      }
200
    }
201
    if ($li_first) {
202
      $items[] = array(
203
        'class' => array('pager-first'),
204
        'data' => $li_first,
205
      );
206
    }
207
    if ($li_previous) {
208
      $items[] = array(
209
        'class' => array('pager-previous'),
210
        'data' => $li_previous,
211
      );
212
    }
213
    // End generation.
214
    if ($li_next) {
215
      $items[] = array(
216
        'class' => array('pager-next'),
217
        'data' => $li_next,
218
      );
219
    }
220
    if ($li_last) {
221
      $items[] = array(
222
        'class' => array('pager-last'),
223
        'data' => $li_last,
224
      );
225
    }
226
    return '<h2 class="element-invisible">' . t('Pages') . '</h2>' . theme('item_list', array('items' => $items, 'title' => NULL, 'type' => 'ul', 'attributes' => array('class' => array('pager', 'clearfix'))));
227
  }
228
}
229

    
230
/**
231
 * Format pager link.
232
 */
233
function busy_pager_link($variables) {
234
  $text = $variables['text'];
235
  $page_new = $variables['page_new'];
236
  $element = $variables['element'];
237
  $parameters = $variables['parameters'];
238
  $wrap_title = isset($parameters['wrap']) ? $parameters['wrap'] : FALSE;
239
  $attributes = $variables['attributes'];
240
  unset($parameters['wrap']);
241

    
242
  $page = isset($_GET['page']) ? $_GET['page'] : '';
243
  if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
244
    $parameters['page'] = $new_page;
245
  }
246

    
247
  $query = array();
248
  if (count($parameters)) {
249
    $query = drupal_get_query_parameters($parameters, array());
250
  }
251
  if ($query_pager = pager_get_query_parameters()) {
252
    $query = array_merge($query, $query_pager);
253
  }
254

    
255
  // Set each pager link title
256
  if (!isset($attributes['title'])) {
257
    static $titles = NULL;
258
    if (!isset($titles)) {
259
      $titles = array(
260
        t('« first') => t('Go to first page'),
261
        t('‹ previous') => t('Go to previous page'),
262
        t('next ›') => t('Go to next page'),
263
        t('last »') => t('Go to last page'),
264
      );
265
    }
266
    if (isset($titles[$text])) {
267
      $attributes['title'] = $titles[$text];
268
    }
269
    elseif (is_numeric($text)) {
270
      $attributes['title'] = t('Go to page @number', array('@number' => $text));
271
    }
272
  }
273
  if ($wrap_title) {
274
    $text = '<span>' . $text . '</span>';
275
  }
276

    
277
  return l($text, $_GET['q'], array('attributes' => $attributes, 'query' => $query, 'html' => $wrap_title));
278
}
279

    
280
/**
281
 * Override html output of fieldsets and add a wrapper element for fieldset
282
 * content.
283
 *
284
 */
285
function busy_fieldset($variables) {
286
  $element = $variables['element'];
287
  element_set_attributes($element, array('id'));
288
  _form_set_class($element, array('form-wrapper'));
289

    
290
  $output = '<fieldset' . drupal_attributes($element['#attributes']) . '>';
291
  if (!empty($element['#title'])) {
292
    // Always wrap fieldset legends in a SPAN for CSS positioning.
293
    $output .= '<legend><span class="fieldset-legend">' . $element['#title'] . '</span></legend>';
294
  }
295
  $output .= '<div class="fieldset-wrapper clearfix">';
296
  if (!empty($element['#description'])) {
297
    $output .= '<div class="fieldset-description">' . $element['#description'] . '</div>';
298
  }
299
  $output .= $element['#children'];
300
  if (isset($element['#value'])) {
301
    $output .= $element['#value'];
302
  }
303
  $output .= '</div>';
304
  $output .= "</fieldset>\n";
305
  return $output;
306
}