Projet

Général

Profil

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

root / drupal7 / sites / all / themes / tao / template.php @ 1c42f191

1
<?php
2

    
3
/**
4
 * Implements hook_css_alter().
5
 * @TODO: Once http://drupal.org/node/901062 is resolved, determine whether
6
 * this can be implemented in the .info file instead.
7
 *
8
 * Omitted:
9
 * - color.css
10
 * - contextual.css
11
 * - dashboard.css
12
 * - field_ui.css
13
 * - image.css
14
 * - locale.css
15
 * - shortcut.css
16
 * - simpletest.css
17
 * - toolbar.css
18
 */
19
function tao_css_alter(&$css) {
20
  $exclude = array(
21
    'misc/vertical-tabs.css' => FALSE,
22
    'modules/aggregator/aggregator.css' => FALSE,
23
    'modules/block/block.css' => FALSE,
24
    'modules/book/book.css' => FALSE,
25
    'modules/comment/comment.css' => FALSE,
26
    'modules/dblog/dblog.css' => FALSE,
27
    'modules/file/file.css' => FALSE,
28
    'modules/filter/filter.css' => FALSE,
29
    'modules/forum/forum.css' => FALSE,
30
    'modules/help/help.css' => FALSE,
31
    'modules/menu/menu.css' => FALSE,
32
    'modules/node/node.css' => FALSE,
33
    'modules/openid/openid.css' => FALSE,
34
    'modules/poll/poll.css' => FALSE,
35
    'modules/profile/profile.css' => FALSE,
36
    'modules/search/search.css' => FALSE,
37
    'modules/statistics/statistics.css' => FALSE,
38
    'modules/syslog/syslog.css' => FALSE,
39
    'modules/system/admin.css' => FALSE,
40
    'modules/system/maintenance.css' => FALSE,
41
    'modules/system/system.css' => FALSE,
42
    'modules/system/system.admin.css' => FALSE,
43
    'modules/system/system.base.css' => FALSE,
44
    'modules/system/system.maintenance.css' => FALSE,
45
    'modules/system/system.menus.css' => FALSE,
46
    'modules/system/system.theme.css' => FALSE,
47
    'modules/taxonomy/taxonomy.css' => FALSE,
48
    'modules/tracker/tracker.css' => FALSE,
49
    'modules/update/update.css' => FALSE,
50
    'modules/user/user.css' => FALSE,
51
  );
52
  $css = array_diff_key($css, $exclude);
53
}
54

    
55
/**
56
 * Implementation of hook_theme().
57
 */
58
function tao_theme() {
59
  $items = array();
60

    
61
  // Consolidate a variety of theme functions under a single template type.
62
  $items['block'] = array(
63
    'arguments' => array('block' => NULL),
64
    'template' => 'object',
65
    'path' => drupal_get_path('theme', 'tao') .'/templates',
66
  );
67
  $items['comment'] = array(
68
    'arguments' => array('comment' => NULL, 'node' => NULL, 'links' => array()),
69
    'template' => 'object',
70
    'path' => drupal_get_path('theme', 'tao') .'/templates',
71
  );
72
  $items['node'] = array(
73
    'arguments' => array('node' => NULL, 'teaser' => FALSE, 'page' => FALSE),
74
    'template' => 'node',
75
    'path' => drupal_get_path('theme', 'tao') .'/templates',
76
  );
77
  $items['fieldset'] = array(
78
    'arguments' => array('element' => array()),
79
    'template' => 'fieldset',
80
    'path' => drupal_get_path('theme', 'tao') .'/templates',
81
  );
82

    
83
  // Split out pager list into separate theme function.
84
  $items['pager_list'] = array('arguments' => array(
85
    'tags' => array(),
86
    'limit' => 10,
87
    'element' => 0,
88
    'parameters' => array(),
89
    'quantity' => 9,
90
  ));
91

    
92
  return $items;
93
}
94

    
95
/**
96
 * Preprocess functions ===============================================
97
 */
98
function tao_preprocess_html(&$vars) {
99
  $vars['classes_array'][] = 'tao';
100

    
101
  // Add IE from theme file.
102
  $tao_path = drupal_get_path('theme', 'tao');
103
  $info = drupal_parse_info_file($tao_path.'/tao.info');
104
  $ie = $info['stylesheets']['ie'];
105
  foreach ($ie as $key => $value) {
106
    drupal_add_css(
107
      $tao_path.'/'.$value,
108
      array(
109
        'browsers' => array(
110
          'IE' => $key,
111
          '!IE' => FALSE
112
        )
113
      )
114
    );
115
  }
116

    
117
}
118

    
119
/**
120
 * Implementation of preprocess_page().
121
 */
122
function tao_preprocess_page(&$vars) {
123
  // Split primary and secondary local tasks
124
  $vars['primary_local_tasks'] = menu_primary_local_tasks();
125
  $vars['secondary_local_tasks'] = menu_secondary_local_tasks();
126

    
127
  // Link site name to frontpage
128
  $vars['site_name'] = l($vars['site_name'], '<front>');
129
}
130

    
131
/**
132
 * Implementation of preprocess_block().
133
 */
134
function tao_preprocess_block(&$vars) {
135
  $vars['hook'] = 'block';
136

    
137
  $vars['attributes_array']['id'] = $vars['block_html_id'];
138
  $vars['attributes_array']['class'] = $vars['classes_array'];
139

    
140
  $vars['title_attributes_array']['class'][] = $vars['hook'] . '-title';
141
  $vars['title_attributes_array']['class'][] = 'clearfix';
142

    
143
  $vars['content_attributes_array']['class'][] = $vars['hook'] . '-content';
144
  $vars['content_attributes_array']['class'][] = 'clearfix';
145
  if ($vars['block']->module == 'block') {
146
    $vars['content_attributes_array']['class'][] = 'prose';
147
  }
148

    
149
  $vars['title'] = !empty($vars['block']->subject) ? $vars['block']->subject : '';
150

    
151
  // In D7 the page content may be served as a block. Replace the generic
152
  // 'block' class from the page content with a more specific class that can
153
  // be used to distinguish this block from others.
154
  // Subthemes can easily override this behavior in an implementation of
155
  // preprocess_block().
156
  if ($vars['block']->module === 'system' && $vars['block']->delta === 'main') {
157
    $vars['classes_array'] = array_diff($vars['classes_array'], array('block'));
158
    $vars['classes_array'][] = 'block-page-content';
159
  }
160
}
161

    
162
/**
163
 * Implementation of preprocess_node().
164
 */
165
function tao_preprocess_node(&$vars) {
166
  $vars['hook'] = 'node';
167

    
168
  $vars['classes_array'][] = 'clearfix';
169

    
170
  $vars['attributes_array']['id'] = "node-{$vars['node']->nid}";
171

    
172
  $vars['title_attributes_array']['class'][] = $vars['hook'] . '-title';
173
  $vars['title_attributes_array']['class'][] = 'clearfix';
174

    
175
  $vars['content_attributes_array']['class'][] = $vars['hook'] . '-content';
176
  $vars['content_attributes_array']['class'][] = 'clearfix';
177
  $vars['content_attributes_array']['class'][] = 'prose';
178

    
179
  if (isset($vars['content']['links'])) {
180
    $vars['links'] = $vars['content']['links'];
181
    unset($vars['content']['links']);
182
  }
183

    
184
  if (isset($vars['content']['comments'])) {
185
    $vars['post_object']['comments'] = $vars['content']['comments'];
186
    unset($vars['content']['comments']);
187
  }
188

    
189
  if ($vars['display_submitted']) {
190
    $vars['submitted'] = t('Submitted by !username on !datetime', array(
191
      '!username' => $vars['name'],
192
      '!datetime' => $vars['date'],
193
    ));
194
  }
195
}
196

    
197
/**
198
 * Implementation of preprocess_comment().
199
 */
200
function tao_preprocess_comment(&$vars) {
201
  $vars['hook'] = 'comment';
202

    
203
  $vars['classes_array'][] = 'clearfix';
204

    
205
  $vars['title_attributes_array']['class'][] = $vars['hook'] . '-title';
206
  $vars['title_attributes_array']['class'][] = 'clearfix';
207

    
208
  $vars['content_attributes_array']['class'][] = $vars['hook'] . '-content';
209
  $vars['content_attributes_array']['class'][] = 'clearfix';
210

    
211
  $vars['submitted'] = t('Submitted by !username on !datetime', array(
212
    '!username' => $vars['author'],
213
    '!datetime' => $vars['created'],
214
  ));
215

    
216
  if (isset($vars['content']['links'])) {
217
    $vars['links'] = $vars['content']['links'];
218
    unset($vars['content']['links']);
219
  }
220
}
221

    
222
/**
223
 * Implementation of preprocess_fieldset().
224
 */
225
function tao_preprocess_fieldset(&$vars) {
226
  $element = $vars['element'];
227
  _form_set_class($element, array('form-wrapper'));
228
  $vars['attributes'] = isset($element['#attributes']) ? $element['#attributes'] : array();
229
  $vars['attributes']['class'][] = 'fieldset';
230
  if (!empty($element['#title'])) {
231
    $vars['attributes']['class'][] = 'titled';
232
  }
233
  if (!empty($element['#id'])) {
234
    if (!empty($element["#attributes"]["id"])) {
235
      $vars['attributes']['id'] = $element["#attributes"]["id"];
236
    } else {
237
      $vars['attributes']['id'] = $element['#id'];
238
    }
239
  }
240

    
241
  $description = !empty($element['#description']) ? "<div class='description'>{$element['#description']}</div>" : '';
242
  $children = !empty($element['#children']) ? $element['#children'] : '';
243
  $value = !empty($element['#value']) ? $element['#value'] : '';
244
  $vars['content'] = $description . $children . $value;
245
  $vars['title'] = !empty($element['#title']) ? $element['#title'] : '';
246
  $vars['hook'] = 'fieldset';
247
}
248

    
249
/**
250
 * Implementation of preprocess_field().
251
 */
252
function tao_preprocess_field(&$vars) {
253
  // Add prose class to long text fields.
254
  if ($vars['element']['#field_type'] === 'text_with_summary') {
255
    $vars['classes_array'][] = 'prose';
256
  }
257
}
258

    
259
/**
260
 * Function overrides =================================================
261
 */
262

    
263
/**
264
 * Override of theme('textarea').
265
 * Deprecate misc/textarea.js in favor of using the 'resize' CSS3 property.
266
 */
267
function tao_textarea($vars) {
268
  $element = $vars['element'];
269
  $element['#attributes']['name'] = $element['#name'];
270
  $element['#attributes']['id'] = $element['#id'];
271
  $element['#attributes']['cols'] = $element['#cols'];
272
  $element['#attributes']['rows'] = $element['#rows'];
273
  _form_set_class($element, array('form-textarea'));
274

    
275
  $wrapper_attributes = array(
276
    'class' => array('form-textarea-wrapper'),
277
  );
278

    
279
  // Add resizable behavior.
280
  if (!empty($element['#resizable'])) {
281
    $wrapper_attributes['class'][] = 'resizable';
282
  }
283

    
284
  $output = '<div' . drupal_attributes($wrapper_attributes) . '>';
285
  $output .= '<textarea' . drupal_attributes($element['#attributes']) . '>' . check_plain($element['#value']) . '</textarea>';
286
  $output .= '</div>';
287
  return $output;
288
}
289

    
290
/**
291
 * Override of theme_pager().
292
 * Easily one of the most obnoxious theming jobs in Drupal core.
293
 * Goals: consolidate functionality into less than 5 functions and
294
 * ensure the markup will not conflict with major other styles
295
 * (theme_item_list() in particular).
296
 */
297
function tao_pager($vars) {
298
  $tags = $vars['tags'];
299
  $element = $vars['element'];
300
  $parameters = $vars['parameters'];
301
  $quantity = $vars['quantity'];
302
  $pager_list = theme('pager_list', $vars);
303

    
304
  $links = array();
305
  $links['pager-first'] = theme('pager_first', array(
306
    'text' => (isset($tags[0]) ? $tags[0] : t('First')),
307
    'element' => $element,
308
    'parameters' => $parameters
309
  ));
310
  $links['pager-previous'] = theme('pager_previous', array(
311
    'text' => (isset($tags[1]) ? $tags[1] : t('Prev')),
312
    'element' => $element,
313
    'interval' => 1,
314
    'parameters' => $parameters
315
  ));
316
  $links['pager-next'] = theme('pager_next', array(
317
    'text' => (isset($tags[3]) ? $tags[3] : t('Next')),
318
    'element' => $element,
319
    'interval' => 1,
320
    'parameters' => $parameters
321
  ));
322
  $links['pager-last'] = theme('pager_last', array(
323
    'text' => (isset($tags[4]) ? $tags[4] : t('Last')),
324
    'element' => $element,
325
    'parameters' => $parameters
326
  ));
327
  $links = array_filter($links);
328
  $pager_links = theme('links', array(
329
    'links' => $links,
330
    'attributes' => array('class' => 'links pager pager-links')
331
  ));
332
  if ($pager_list) {
333
    return '<div class="pager clearfix">' . $pager_list . ' ' . $pager_links . '</div>';
334
  }
335
}
336

    
337
/**
338
 * Split out page list generation into its own function.
339
 */
340
function tao_pager_list($vars) {
341
  $tags = $vars['tags'];
342
  $element = $vars['element'];
343
  $parameters = $vars['parameters'];
344
  $quantity = $vars['quantity'];
345

    
346
  global $pager_page_array, $pager_total;
347
  if ($pager_total[$element] > 1) {
348
    // Calculate various markers within this pager piece:
349
    // Middle is used to "center" pages around the current page.
350
    $pager_middle = ceil($quantity / 2);
351
    // current is the page we are currently paged to
352
    $pager_current = $pager_page_array[$element] + 1;
353
    // first is the first page listed by this pager piece (re quantity)
354
    $pager_first = $pager_current - $pager_middle + 1;
355
    // last is the last page listed by this pager piece (re quantity)
356
    $pager_last = $pager_current + $quantity - $pager_middle;
357
    // max is the maximum page number
358
    $pager_max = $pager_total[$element];
359
    // End of marker calculations.
360

    
361
    // Prepare for generation loop.
362
    $i = $pager_first;
363
    if ($pager_last > $pager_max) {
364
      // Adjust "center" if at end of query.
365
      $i = $i + ($pager_max - $pager_last);
366
      $pager_last = $pager_max;
367
    }
368
    if ($i <= 0) {
369
      // Adjust "center" if at start of query.
370
      $pager_last = $pager_last + (1 - $i);
371
      $i = 1;
372
    }
373
    // End of generation loop preparation.
374

    
375
    $links = array();
376

    
377
    // When there is more than one page, create the pager list.
378
    if ($i != $pager_max) {
379
      // Now generate the actual pager piece.
380
      for ($i; $i <= $pager_last && $i <= $pager_max; $i++) {
381
        if ($i < $pager_current) {
382
          $links["$i pager-item"] = theme('pager_previous', array(
383
            'text' => $i,
384
            'element' => $element,
385
            'interval' => ($pager_current - $i),
386
            'parameters' => $parameters
387
          ));
388
        }
389
        if ($i == $pager_current) {
390
          $links["$i pager-current"] = array('title' => $i);
391
        }
392
        if ($i > $pager_current) {
393
          $links["$i pager-item"] = theme('pager_next', array(
394
            'text' => $i,
395
            'element' => $element,
396
            'interval' => ($i - $pager_current),
397
            'parameters' => $parameters
398
          ));
399
        }
400
      }
401
      return theme('links', array(
402
        'links' => $links,
403
        'attributes' => array('class' => 'links pager pager-list')
404
      ));
405
    }
406
  }
407
  return '';
408
}
409

    
410
/**
411
 * Return an array suitable for theme_links() rather than marked up HTML link.
412
 */
413
function tao_pager_link($vars) {
414
  $text = $vars['text'];
415
  $page_new = $vars['page_new'];
416
  $element = $vars['element'];
417
  $parameters = $vars['parameters'];
418
  $attributes = $vars['attributes'];
419

    
420
  $page = isset($_GET['page']) ? $_GET['page'] : '';
421
  if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
422
    $parameters['page'] = $new_page;
423
  }
424

    
425
  $query = array();
426
  if (count($parameters)) {
427
    $query = drupal_get_query_parameters($parameters, array());
428
  }
429
  if ($query_pager = pager_get_query_parameters()) {
430
    $query = array_merge($query, $query_pager);
431
  }
432

    
433
  // Set each pager link title
434
  if (!isset($attributes['title'])) {
435
    static $titles = NULL;
436
    if (!isset($titles)) {
437
      $titles = array(
438
        t('« first') => t('Go to first page'),
439
        t('‹ previous') => t('Go to previous page'),
440
        t('next ›') => t('Go to next page'),
441
        t('last »') => t('Go to last page'),
442
      );
443
    }
444
    if (isset($titles[$text])) {
445
      $attributes['title'] = $titles[$text];
446
    }
447
    else if (is_numeric($text)) {
448
      $attributes['title'] = t('Go to page @number', array('@number' => $text));
449
    }
450
  }
451

    
452
  return array(
453
    'title' => $text,
454
    'href' => $_GET['q'],
455
    'attributes' => $attributes,
456
    'query' => count($query) ? $query : NULL,
457
  );
458
}
459

    
460
/**
461
 * Override of theme_views_mini_pager().
462
 */
463
function tao_views_mini_pager($vars) {
464
  $tags = $vars['tags'];
465
  $quantity = $vars['quantity'];
466
  $element = $vars['element'];
467
  $parameters = $vars['parameters'];
468

    
469
  global $pager_page_array, $pager_total;
470

    
471
  // Calculate various markers within this pager piece:
472
  // Middle is used to "center" pages around the current page.
473
  $pager_middle = ceil($quantity / 2);
474
  // current is the page we are currently paged to
475
  $pager_current = $pager_page_array[$element] + 1;
476
  // max is the maximum page number
477
  $pager_max = $pager_total[$element];
478
  // End of marker calculations.
479

    
480
  $links = array();
481
  if ($pager_total[$element] > 1) {
482
    $links['pager-previous'] = theme('pager_previous', array(
483
      'text' => (isset($tags[1]) ? $tags[1] : t('Prev')),
484
      'element' => $element,
485
      'interval' => 1,
486
      'parameters' => $parameters
487
    ));
488
    $links['pager-current'] = array(
489
      'title' => t('@current of @max', array(
490
        '@current' => $pager_current,
491
        '@max' => $pager_max)
492
      )
493
    );
494
    $links['pager-next'] = theme('pager_next', array(
495
      'text' => (isset($tags[3]) ? $tags[3] : t('Next')),
496
      'element' => $element,
497
      'interval' => 1,
498
      'parameters' => $parameters
499
    ));
500
    return theme('links', array('links' => $links, 'attributes' => array('class' => array('links', 'pager', 'views-mini-pager'))));
501
  }
502
}