Projet

Général

Profil

Paste
Télécharger (18,6 ko) Statistiques
| Branche: | Révision:

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

1
<?php
2
/*
3
 * Implements hook_preprocess_html().
4
 */
5
function rubik_preprocess_html(&$vars) {
6
  if (module_exists('views')) {
7
    drupal_add_css(drupal_get_path('module', 'views') . '/css/views-admin.seven.css', 'theme');
8
  }
9
  if (theme_get_setting('rubik_inline_field_descriptions')) {
10
    $vars['classes_array'][] = 'rubik-inline-field-descriptions';
11
  }
12
}
13

    
14
/**
15
 * Implements hook_css_alter().
16
 * @TODO: Do this in .info once http://drupal.org/node/575298 is committed.
17
 */
18
function rubik_css_alter(&$css) {
19
  if (isset($css['modules/overlay/overlay-child.css'])) {
20
    $css['modules/overlay/overlay-child.css']['data'] = drupal_get_path('theme', 'rubik') . '/overlay-child.css';
21
  }
22
  if (isset($css['modules/shortcut/shortcut.css'])) {
23
    $css['modules/shortcut/shortcut.css']['data'] = drupal_get_path('theme', 'rubik') . '/shortcut.css';
24
  }
25
}
26

    
27
/**
28
 * Implementation of hook_theme().
29
 */
30
function rubik_theme() {
31
  $items = array();
32

    
33
  // Content theming.
34
  $items['help'] =
35
  $items['node'] =
36
  $items['comment'] =
37
  $items['comment_wrapper'] = array(
38
    'path' => drupal_get_path('theme', 'rubik') .'/templates',
39
    'template' => 'object',
40
  );
41
  $items['node']['template'] = 'node';
42

    
43
  // Help pages really need help. See preprocess_page().
44
  $items['help_page'] = array(
45
    'variables' => array('content' => array()),
46
    'path' => drupal_get_path('theme', 'rubik') .'/templates',
47
    'template' => 'object',
48
    'preprocess functions' => array(
49
      'template_preprocess',
50
      'rubik_preprocess_help_page',
51
    ),
52
    'process functions' => array('template_process'),
53
  );
54

    
55
  // Form layout: default (2 column).
56
  $items['block_add_block_form'] =
57
  $items['block_admin_configure'] =
58
  $items['comment_form'] =
59
  $items['contact_admin_edit'] =
60
  $items['contact_mail_page'] =
61
  $items['contact_mail_user'] =
62
  $items['filter_admin_format_form'] =
63
  $items['forum_form'] =
64
  $items['locale_languages_edit_form'] =
65
  $items['menu_edit_menu'] =
66
  $items['menu_edit_item'] =
67
  $items['node_type_form'] =
68
  $items['path_admin_form'] =
69
  $items['system_settings_form'] =
70
  $items['system_themes_form'] =
71
  $items['system_modules'] =
72
  $items['system_actions_configure'] =
73
  $items['taxonomy_form_term'] =
74
  $items['taxonomy_form_vocabulary'] =
75
  $items['user_profile_form'] =
76
  $items['user_admin_access_add_form'] = array(
77
    'render element' => 'form',
78
    'path' => drupal_get_path('theme', 'rubik') .'/templates',
79
    'template' => 'form-default',
80
    'preprocess functions' => array(
81
      'rubik_preprocess_form_buttons',
82
    ),
83
  );
84

    
85
  // These forms require additional massaging.
86
  $items['confirm_form'] = array(
87
    'render element' => 'form',
88
    'path' => drupal_get_path('theme', 'rubik') .'/templates',
89
    'template' => 'form-simple',
90
    'preprocess functions' => array(
91
      'rubik_preprocess_form_confirm'
92
    ),
93
  );
94
  $items['node_form'] = array(
95
    'render element' => 'form',
96
    'path' => drupal_get_path('theme', 'rubik') .'/templates',
97
    'template' => 'form-default',
98
    'preprocess functions' => array(
99
      'rubik_preprocess_form_buttons',
100
      'rubik_preprocess_form_node',
101
    ),
102
  );
103

    
104
  return $items;
105
}
106

    
107
/**
108
 * Preprocessor for theme('page').
109
 */
110
function rubik_preprocess_page(&$vars) {
111
  // Show a warning if base theme is not present.
112
  if (!function_exists('tao_theme') && user_access('administer site configuration')) {
113
    drupal_set_message(t('The Rubik theme requires the !tao base theme in order to work properly.', array('!tao' => l('Tao', 'http://drupal.org/project/tao'))), 'warning');
114
  }
115

    
116
  // Set a page icon class.
117
  $vars['page_icon_class'] = ($item = menu_get_item()) ? implode(' ' , _rubik_icon_classes($item['href'])) : '';
118

    
119
  // Help pages. They really do need help.
120
  if (strpos($_GET['q'], 'admin/help/') === 0 && isset($vars['page']['content']['system_main']['main']['#markup'])) {
121
    $vars['page']['content']['system_main']['main']['#markup'] = theme('help_page', array('content' => $vars['page']['content']['system_main']['main']['#markup']));
122
  }
123

    
124
  // Clear out help text if empty.
125
  if (empty($vars['help']) || !(strip_tags($vars['help']))) {
126
    $vars['help'] = '';
127
  }
128

    
129
  // Process local tasks. This will get called for rubik and its subthemes.
130
  _rubik_local_tasks($vars);
131

    
132
  // Overlay is enabled.
133
  $vars['overlay'] = (module_exists('overlay') && overlay_get_mode() === 'child');
134
}
135

    
136
/**
137
 * Preprocessor for theme('fieldset').
138
 */
139
function rubik_preprocess_fieldset(&$vars) {
140
  if (!empty($vars['element']['#collapsible'])) {
141
    $vars['title'] = "<span class='icon'></span>" . $vars['title'];
142
  }
143
}
144

    
145
/**
146
 * Preprocessor for handling form button for most forms.
147
 */
148
function rubik_preprocess_form_buttons(&$vars) {
149
  if (!empty($vars['form']['actions'])) {
150
    $vars['actions'] = $vars['form']['actions'];
151
    unset($vars['form']['actions']);
152
  }
153
}
154

    
155
/**
156
 * Preprocessor for theme('confirm_form').
157
 */
158
function rubik_preprocess_form_confirm(&$vars) {
159
  // Move the title from the page title (usually too big and unwieldy)
160
  $title = filter_xss_admin(drupal_get_title());
161
  $vars['form']['description']['#type'] = 'item';
162
  $vars['form']['description']['#value'] = empty($vars['form']['description']['#value']) ?
163
    "<strong>{$title}</strong>" :
164
    "<strong>{$title}</strong><p>{$vars['form']['description']['#value']}</p>";
165
  drupal_set_title(t('Please confirm'));
166
}
167

    
168
/**
169
 * Preprocessor for theme('node_form').
170
 */
171
function rubik_preprocess_form_node(&$vars) {
172
  $vars['sidebar'] = isset($vars['sidebar']) ? $vars['sidebar'] : array();
173
  // Support nodeformcols if present.
174
  if (module_exists('nodeformcols')) {
175
    $map = array(
176
      'nodeformcols_region_right' => 'sidebar',
177
      'nodeformcols_region_footer' => 'footer',
178
      'nodeformcols_region_main' => NULL,
179
    );
180
    foreach ($map as $region => $target) {
181
      if (isset($vars['form'][$region])) {
182
        if (isset($vars['form'][$region]['#prefix'], $vars['form'][$region]['#suffix'])) {
183
          unset($vars['form'][$region]['#prefix']);
184
          unset($vars['form'][$region]['#suffix']);
185
        }
186
        if (isset($vars['form'][$region]['actions'], $vars['form'][$region]['actions'])) {
187
          $vars['actions'] = $vars['form'][$region]['actions'];
188
          unset($vars['form'][$region]['actions']);
189
        }
190
        if (isset($target)) {
191
          $vars[$target] = $vars['form'][$region];
192
          unset($vars['form'][$region]);
193
        }
194
      }
195
    }
196
  }
197
  // Default to showing taxonomy in sidebar if nodeformcols is not present.
198
  elseif (isset($vars['form']['taxonomy']) && empty($vars['sidebar'])) {
199
    $vars['sidebar']['taxonomy'] = $vars['form']['taxonomy'];
200
    unset($vars['form']['taxonomy']);
201
  }
202
}
203

    
204
/**
205
 * Preprocessor for theme('button').
206
 */
207
function rubik_preprocess_button(&$vars) {
208
  if (isset($vars['element']['#value'])) {
209
    $classes = array(
210
      t('Save') => 'yes',
211
      t('Submit') => 'yes',
212
      t('Add') => 'yes',
213
      t('Delete') => 'no',
214
      t('Cancel') => 'no',
215
    );
216
    foreach ($classes as $search => $class) {
217
      if (strpos($vars['element']['#value'], $search) !== FALSE) {
218
        $vars['element']['#attributes']['class'][] = 'button-' . $class;
219
        break;
220
      }
221
    }
222
  }
223
}
224

    
225
/**
226
 * Preprocessor for theme('help').
227
 */
228
function rubik_preprocess_help(&$vars) {
229
  $vars['hook'] = 'help';
230
  $vars['attr']['id'] = 'help-text';
231
  $class = 'path-admin-help clear-block toggleable';
232
  $vars['attr']['class'] = isset($vars['attr']['class']) ? "{$vars['attr']['class']} $class" : $class;
233
  $help = menu_get_active_help();
234
  if (($test = strip_tags($help)) && !empty($help)) {
235
    // Thankfully this is static cached.
236
    $vars['attr']['class'] .= menu_secondary_local_tasks() ? ' with-tabs' : '';
237

    
238
    $vars['is_prose'] = TRUE;
239
    $vars['layout'] = TRUE;
240
    $vars['content'] = "<span class='icon'></span>" . $help;
241

    
242
    // Link to help section.
243
    $item = menu_get_item('admin/help');
244
    if ($item && $item['path'] === 'admin/help' && $item['access']) {
245
      $vars['links'] = l(t('More help topics'), 'admin/help');
246
    }
247
  }
248
}
249

    
250
/**
251
 * Preprocessor for theme('help_page').
252
 */
253
function rubik_preprocess_help_page(&$vars) {
254
  $vars['hook'] = 'help-page';
255

    
256
  $vars['title_attributes_array']['class'][] = 'help-page-title';
257
  $vars['title_attributes_array']['class'][] = 'clearfix';
258

    
259
  $vars['content_attributes_array']['class'][] = 'help-page-content';
260
  $vars['content_attributes_array']['class'][] = 'clearfix';
261
  $vars['content_attributes_array']['class'][] = 'prose';
262

    
263
  $vars['layout'] = TRUE;
264

    
265
  // Truly hackish way to navigate help pages.
266
  $module_info = system_rebuild_module_data();
267
  $empty_arg = drupal_help_arg();
268
  $modules = array();
269
  foreach (module_implements('help', TRUE) as $module) {
270
    if (module_invoke($module, 'help', "admin/help#$module", $empty_arg)) {
271
      $modules[$module] = $module_info[$module]->info['name'];
272
    }
273
  }
274
  asort($modules);
275

    
276
  $links = array();
277
  foreach ($modules as $module => $name) {
278
    $links[] = array('title' => $name, 'href' => "admin/help/{$module}");
279
  }
280
  $vars['links'] = theme('links', array('links' => $links));
281
}
282

    
283
/**
284
 * Preprocessor for theme('node').
285
 */
286
function rubik_preprocess_node(&$vars) {
287
  $vars['layout'] = TRUE;
288
  if ($vars['display_submitted']) {
289
    $vars['submitted'] = _rubik_submitted($vars['node']);
290
  }
291
}
292

    
293
/**
294
 * Preprocessor for theme('comment').
295
 */
296
function rubik_preprocess_comment(&$vars) {
297
  $vars['layout'] = TRUE;
298
  $vars['submitted'] = _rubik_submitted($vars['comment']);
299
}
300

    
301
/**
302
 * Preprocessor for theme('comment_wrapper').
303
 */
304
function rubik_preprocess_comment_wrapper(&$vars) {
305
  $vars['hook'] = 'box';
306
  $vars['layout'] = FALSE;
307
  $vars['title'] = t('Comments');
308

    
309
  $vars['attributes_array']['id'] = 'comments';
310

    
311
  $vars['title_attributes_array']['class'][] = 'box-title';
312
  $vars['title_attributes_array']['class'][] = 'clearfix';
313

    
314
  $vars['content_attributes_array']['class'][] = 'box-content';
315
  $vars['content_attributes_array']['class'][] = 'clearfix';
316
  $vars['content_attributes_array']['class'][] = 'prose';
317

    
318
  $vars['content'] = drupal_render_children($vars['content']);
319
}
320

    
321
/**
322
 * Preprocessor for theme('admin_block').
323
 */
324
function rubik_preprocess_admin_block(&$vars) {
325
  // Add icon and classes to admin block titles.
326
  if (isset($vars['block']['href'])) {
327
    $vars['block']['localized_options']['attributes']['class'] =  _rubik_icon_classes($vars['block']['href']);
328
  }
329
  $vars['block']['localized_options']['html'] = TRUE;
330
  if (isset($vars['block']['link_title'])) {
331
    $vars['block']['title'] = l("<span class='icon'></span>" . filter_xss_admin($vars['block']['title']), $vars['block']['href'], $vars['block']['localized_options']);
332
  }
333

    
334
  if (empty($vars['block']['content'])) {
335
    $vars['block']['content'] = "<div class='admin-block-description description'>{$vars['block']['description']}</div>";
336
  }
337
}
338

    
339
/**
340
 * Override of theme('breadcrumb').
341
 */
342
function rubik_breadcrumb($vars) {
343
  $output = '';
344

    
345
  // Add current page onto the end.
346
  if (!drupal_is_front_page()) {
347
    $item = menu_get_item();
348
    $end = end($vars['breadcrumb']);
349
    if ($end && strip_tags($end) !== $item['title']) {
350
      $vars['breadcrumb'][] = check_plain($item['title']);
351
    }
352
  }
353

    
354
  // Optional: Add the site name to the front of the stack.
355
  if (!empty($vars['prepend'])) {
356
    $site_name = empty($vars['breadcrumb']) ? "<strong>". check_plain(variable_get('site_name', '')) ."</strong>" : l(variable_get('site_name', ''), '<front>', array('purl' => array('disabled' => TRUE)));
357
    array_unshift($vars['breadcrumb'], $site_name);
358
  }
359

    
360
  $depth = 0;
361
  foreach ($vars['breadcrumb'] as $link) {
362

    
363
    // If the item isn't a link, surround it with a strong tag to format it like
364
    // one.
365
    if (!preg_match('/^<a/', $link) && !preg_match('/^<strong/', $link)) {
366
      $link = '<strong>' . $link . '</strong>';
367
    }
368

    
369
    $output .= "<span class='breadcrumb-link breadcrumb-depth-{$depth}'>{$link}</span>";
370
    $depth++;
371
  }
372
  return $output;
373
}
374

    
375
/**
376
 * Override of theme('filter_guidelines').
377
 */
378
function rubik_filter_guidelines($variables) {
379
  return '';
380
}
381

    
382
/**
383
 * Override of theme('node_add_list').
384
 */
385
function rubik_node_add_list($vars) {
386
  $content = $vars['content'];
387

    
388
  $output = "<ul class='admin-list'>";
389
  if ($content) {
390
    foreach ($content as $item) {
391
      $item['title'] = "<span class='icon'></span>" . filter_xss_admin($item['title']);
392
      if (isset($item['localized_options']['attributes']['class'])) {
393
        $item['localized_options']['attributes']['class'] += _rubik_icon_classes($item['href']);
394
      }
395
      else {
396
        $item['localized_options']['attributes']['class'] = _rubik_icon_classes($item['href']);
397
      }
398
      $item['localized_options']['html'] = TRUE;
399
      $output .= "<li>";
400
      $output .= l($item['title'], $item['href'], $item['localized_options']);
401
      $output .= '<div class="description">'. filter_xss_admin($item['description']) .'</div>';
402
      $output .= "</li>";
403
    }
404
  }
405
  $output .= "</ul>";
406
  return $output;
407
}
408

    
409
/**
410
 * Override of theme_admin_block_content().
411
 */
412
function rubik_admin_block_content($vars) {
413
  $content = $vars['content'];
414

    
415
  $output = '';
416
  if (!empty($content)) {
417

    
418
    foreach ($content as $k => $item) {
419

    
420
      //-- Safety check for invalid clients of the function
421
      if (empty($content[$k]['localized_options']['attributes']['class'])) {
422
        $content[$k]['localized_options']['attributes']['class'] = array();
423
      }
424
      if (!is_array($content[$k]['localized_options']['attributes']['class'])) {
425
        $content[$k]['localized_options']['attributes']['class'] = array($content[$k]['localized_options']['attributes']['class']);
426
      }
427

    
428
      $content[$k]['title'] = "<span class='icon'></span>" . filter_xss_admin($item['title']);
429
      $content[$k]['localized_options']['html'] = TRUE;
430
      if (!empty($content[$k]['localized_options']['attributes']['class'])) {
431
        $content[$k]['localized_options']['attributes']['class'] += _rubik_icon_classes($item['href']);
432
      }
433
      else {
434
        $content[$k]['localized_options']['attributes']['class'] = _rubik_icon_classes($item['href']);
435
      }
436
    }
437
    $output = system_admin_compact_mode() ? '<ul class="admin-list admin-list-compact">' : '<ul class="admin-list">';
438
    foreach ($content as $item) {
439
      $output .= '<li class="leaf">';
440
      $output .= l($item['title'], $item['href'], $item['localized_options']);
441
      if (isset($item['description']) && !system_admin_compact_mode()) {
442
        $output .= "<div class='description'>{$item['description']}</div>";
443
      }
444
      $output .= '</li>';
445
    }
446
    $output .= '</ul>';
447
  }
448
  return $output;
449
}
450

    
451
/**
452
 * Override of theme('admin_drilldown_menu_item_link').
453
 */
454
function rubik_admin_drilldown_menu_item_link($link) {
455
  $link['localized_options'] = empty($link['localized_options']) ? array() : $link['localized_options'];
456
  $link['localized_options']['html'] = TRUE;
457
  if (!isset($link['localized_options']['attributes']['class'])) {
458
    $link['localized_options']['attributes']['class'] = _rubik_icon_classes($link['href']);
459
  }
460
  else {
461
    $link['localized_options']['attributes']['class'] += _rubik_icon_classes($link['href']);
462
  }
463
  $link['description'] = check_plain(truncate_utf8(strip_tags($link['description']), 150, TRUE, TRUE));
464
  $link['description'] = "<span class='icon'></span>" . $link['description'];
465
  $link['title'] .= !empty($link['description']) ? "<span class='menu-description'>{$link['description']}</span>" : '';
466
  $link['title'] = filter_xss_admin($link['title']);
467
  return l($link['title'], $link['href'], $link['localized_options']);
468
}
469

    
470
/**
471
 * Preprocessor for theme('textfield').
472
 */
473
function rubik_preprocess_textfield(&$vars) {
474
  if ($vars['element']['#size'] >= 30 && empty($vars['element']['#field_prefix']) && empty($vars['element']['#field_suffix'])) {
475
    $vars['element']['#size'] = '';
476
    if (!isset($vars['element']['#attributes']['class'])
477
      || !is_array($vars['element']['#attributes']['class'])) {
478
       $vars['element']['#attributes']['class'] = array();
479
    }
480
    $vars['element']['#attributes']['class'][] = 'fluid';
481
  }
482
}
483

    
484
/**
485
 * Override of theme('menu_local_task').
486
 */
487
function rubik_menu_local_task($variables) {
488
  $link = $variables['element']['#link'];
489
  $link_text = $link['title'];
490

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

    
495
    // If the link does not contain HTML already, check_plain() it now.
496
    // After we set 'html'=TRUE the link will not be sanitized by l().
497
    if (empty($link['localized_options']['html'])) {
498
      $link['title'] = check_plain($link['title']);
499
    }
500
    $link['localized_options']['html'] = TRUE;
501
    $link_text = t('!local-task-title!active', array('!local-task-title' => $link['title'], '!active' => $active));
502
  }
503

    
504
  // Render child tasks if available.
505
  $children = '';
506
  if (element_children($variables['element'])) {
507
    $children = drupal_render_children($variables['element']);
508
    $children = "<ul class='secondary-tabs links clearfix'>{$children}</ul>";
509
  }
510

    
511
  return '<li' . (!empty($variables['element']['#active']) ? ' class="active"' : '') . '>' . l($link_text, $link['href'], $link['localized_options']) . $children . "</li>\n";
512
}
513

    
514
/**
515
 * Helper function for cloning and drupal_render()'ing elements.
516
 */
517
function rubik_render_clone($elements) {
518
  static $instance;
519
  if (!isset($instance)) {
520
    $instance = 1;
521
  }
522
  foreach (element_children($elements) as $key) {
523
    if (isset($elements[$key]['#id'])) {
524
      $elements[$key]['#id'] = "{$elements[$key]['#id']}-{$instance}";
525
    }
526
  }
527
  $instance++;
528
  return drupal_render($elements);
529
}
530

    
531
/**
532
 * Helper function to submitted info theming functions.
533
 */
534
function _rubik_submitted($node) {
535
  $byline = t('Posted by !username', array('!username' => theme('username', array('account' => $node))));
536
  $date = format_date($node->created, 'small');
537
  return "<div class='byline'>{$byline}</div><div class='date'>$date</div>";
538
}
539

    
540
/**
541
 * Generate an icon class from a path.
542
 */
543
function _rubik_icon_classes($path) {
544
  $classes = array();
545
  $args = explode('/', $path);
546
  if ($args[0] === 'admin' || (count($args) > 1 && $args[0] === 'node' && $args[1] === 'add')) {
547
    // Add a class specifically for the current path that allows non-cascading
548
    // style targeting.
549
    $classes[] = 'path-'. str_replace('/', '-', implode('/', $args)) . '-';
550
    while (count($args)) {
551
      $classes[] = drupal_html_class('path-'. str_replace('/', '-', implode('/', $args)));
552
      array_pop($args);
553
    }
554
    return $classes;
555
  }
556
  return array();
557
}
558

    
559
function _rubik_local_tasks(&$vars) {
560
  if (!empty($vars['secondary_local_tasks']) && is_array($vars['primary_local_tasks'])) {
561
    foreach ($vars['primary_local_tasks'] as $key => $element) {
562
      if (!empty($element['#active'])) {
563
        $vars['primary_local_tasks'][$key] = $vars['primary_local_tasks'][$key] + $vars['secondary_local_tasks'];
564
        break;
565
      }
566
    }
567
  }
568
}
569