Projet

Général

Profil

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

root / drupal7 / sites / all / themes / adminimal_theme / template.php @ f8e16685

1
<?php
2

    
3
/**
4
 * @file
5
 * This file contains the main theme functions hooks and overrides.
6
 */
7

    
8
/**
9
 * Override or insert variables into the maintenance page template.
10
 */
11
function adminimal_preprocess_maintenance_page(&$vars) {
12
  // While markup for normal pages is split into page.tpl.php and html.tpl.php,
13
  // the markup for the maintenance page is all in the single
14
  // maintenance-page.tpl.php template. So, to have what's done in
15
  // adminimal_preprocess_html() also happen on the maintenance page, it has to be
16
  // called here.
17
  adminimal_preprocess_html($vars);
18
}
19

    
20
/**
21
 * Override or insert variables into the html template.
22
 */
23
function adminimal_preprocess_html(&$vars) {
24

    
25
  // Get adminimal folder path.
26
  $adminimal_path = drupal_get_path('theme', 'adminimal');
27

    
28
  // Add default styles.
29
  drupal_add_css($adminimal_path . '/css/reset.css', array('group' => CSS_THEME, 'media' => 'all', 'weight' => -999));
30
  drupal_add_css($adminimal_path . '/css/style.css', array('group' => CSS_THEME, 'media' => 'all', 'weight' => 1));
31

    
32
  // Add conditional CSS for IE8 and below.
33
  drupal_add_css($adminimal_path . '/css/ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE), 'weight' => 999, 'preprocess' => TRUE));
34

    
35
  // Add conditional CSS for IE7 and below.
36
  drupal_add_css($adminimal_path . '/css/ie7.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 7', '!IE' => FALSE), 'weight' => 999, 'preprocess' => TRUE));
37

    
38
  // Add conditional CSS for IE6.
39
  drupal_add_css($adminimal_path . '/css/ie6.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 6', '!IE' => FALSE), 'weight' => 999, 'preprocess' => TRUE));
40

    
41
  //Add Homebox module support
42
  if (module_exists('homebox')) {
43
    drupal_add_css($adminimal_path . '/css/homebox_custom.css', array('group' => CSS_THEME, 'media' => 'all', 'weight' => 1));
44
  }
45

    
46
  // Add theme name to body class.
47
  $vars['classes_array'][] = 'adminimal-theme';
48

    
49
  // Style checkbox and radio buttons in Webkit Browsers.
50
  if (theme_get_setting('style_checkboxes')) {
51
    $vars['classes_array'][] = 'style-checkboxes';
52
  }
53

    
54
  // Disable rounded buttons setting.
55
  if (!theme_get_setting('rounded_buttons')) {
56
    $vars['classes_array'][] = 'no-rounded-buttons';
57
  }
58

    
59
  // Enable sticky action buttons.
60
  if (theme_get_setting('sticky_actions')) {
61
    $vars['classes_array'][] = 'sticky-actions';
62
  }
63

    
64
  // Add icons to the admin configuration page.
65
  if (theme_get_setting('display_icons_config')) {
66
    drupal_add_css($adminimal_path . '/css/icons-config.css', array('group' => CSS_THEME, 'weight' => 10, 'preprocess' => TRUE));
67
  }
68

    
69
  // Add icons to the admin configuration page.
70
  if (theme_get_setting('avoid_custom_font')) {
71
    drupal_add_css($adminimal_path . '/css/avoid_custom_font.css', array('group' => CSS_THEME, 'weight' => 9000, 'preprocess' => TRUE));
72
  }
73

    
74
  // Load CKEditor styles if enabled in settings.
75
  if (theme_get_setting('adminimal_ckeditor') and theme_get_setting('adminimal_theme_skin') != 'dark') {
76
    drupal_add_css($adminimal_path . '/css/ckeditor-adminimal.css', array('group' => CSS_THEME, 'media' => 'all', 'weight' => 2));
77
  }
78

    
79
  // Define Default media queries.
80
  $media_query_mobile = 'only screen and (max-width: 480px)';
81
  $media_query_tablet = 'only screen and (min-width : 481px) and (max-width : 1024px)';
82

    
83
  // Get custom media queries if set.
84
  if (theme_get_setting('use_custom_media_queries')) {
85
    $media_query_mobile = theme_get_setting('media_query_mobile');
86
    $media_query_tablet = theme_get_setting('media_query_tablet');
87
  }
88

    
89
  // Use Bootstrap Gids.
90
  if (theme_get_setting('use_bootstrap_grids')) {
91
    drupal_add_css($adminimal_path . '/css/bootstrap-grids.css', array('group' => CSS_THEME, 'weight' => 1000, 'preprocess' => TRUE));
92
  }
93

    
94
  // Load custom Adminimal skin.
95
  $adminimal_skin = theme_get_setting('adminimal_theme_skin');
96
  if ((!is_null($adminimal_skin))) {
97
    drupal_add_css($adminimal_path . '/skins/' . $adminimal_skin . '/' . $adminimal_skin . '.css', array('group' => CSS_THEME, 'weight' => 900, 'preprocess' => TRUE));
98
    // Add conditional CSS for Mac OS X.
99
    drupal_add_css($adminimal_path . '/skins/' . $adminimal_skin . '/mac_os_x.css', array('group' => CSS_THEME, 'weight' => 950, 'preprocess' => TRUE));
100
    drupal_add_js($adminimal_path . '/skins/' . $adminimal_skin . '/' . $adminimal_skin . '.js');
101
    $vars['classes_array'][] = 'adminimal-skin-' . $adminimal_skin ;
102
  }
103
  else {
104
    drupal_add_css($adminimal_path . '/skins/default/default.css', array('group' => CSS_THEME, 'weight' => 900, 'preprocess' => TRUE));
105
    // Add conditional CSS for Mac OS X.
106
    drupal_add_css($adminimal_path . '/skins/default/mac_os_x.css', array('group' => CSS_THEME, 'weight' => 950, 'preprocess' => TRUE));
107
    drupal_add_js($adminimal_path . '/skins/default/default.js');
108
    $vars['classes_array'][] = 'adminimal-skin-default' ;
109
  }
110

    
111
  // Add responsive styles.
112
  drupal_add_css($adminimal_path . '/css/mobile.css', array('group' => CSS_THEME, 'media' => $media_query_mobile, 'weight' => 1000));
113
  drupal_add_css($adminimal_path . '/css/tablet.css', array('group' => CSS_THEME, 'media' => $media_query_tablet, 'weight' => 1000));
114

    
115
  // Add custom CSS.
116
  if (theme_get_setting('custom_css')) {
117
    $custom_css_path = theme_get_setting('custom_css_path');
118
    if (empty($custom_css_path)) {
119
      $custom_css_path = 'public://adminimal-custom.css';
120
    }
121
    if (file_exists($custom_css_path)) {
122
      drupal_add_css($custom_css_path, array(
123
        'group' => CSS_THEME,
124
        'weight' => 9999,
125
        'preprocess' => TRUE,
126
      ));
127
    }
128
  }
129

    
130
  // Fix the viewport and zooming in mobile devices.
131
  $viewport = array(
132
   '#tag' => 'meta',
133
   '#attributes' => array(
134
     'name' => 'viewport',
135
     'content' => 'width=device-width, maximum-scale=1, minimum-scale=1, user-scalable=no, initial-scale=1',
136
   ),
137
  );
138
  drupal_add_html_head($viewport, 'viewport');
139

    
140
  // Remove the no-sidebars class which is always added by core. Core assumes
141
  // the sidebar regions are called sidebar_first and sidebar_second, which
142
  // is not the case in this theme.
143
  $key = array_search('no-sidebars', $vars['classes_array']);
144
  if ($key !== FALSE) {
145
    unset($vars['classes_array'][$key]);
146
  }
147
  // Add information about the number of sidebars.
148
  if (!empty($vars['page']['sidebar_left']) && !empty($vars['page']['sidebar_right'])) {
149
    $vars['classes_array'][] = 'two-sidebars';
150
  }
151
  elseif (!empty($vars['page']['sidebar_left'])) {
152
    $vars['classes_array'][] = 'one-sidebar sidebar-left';
153
  }
154
  elseif (!empty($vars['page']['sidebar_right'])) {
155
    $vars['classes_array'][] = 'one-sidebar sidebar-right';
156
  }
157
  else {
158
    $vars['classes_array'][] = 'no-sidebars';
159
  }
160

    
161
  // Display warning message on certain pages if theme is disabled.
162
  if (in_array('page-admin-appearance', $vars['classes_array']) || in_array('page-admin-modules', $vars['classes_array']) || in_array('page-admin-reports-status', $vars['classes_array'])) {
163
    $active_themes = list_themes();
164
    if ($active_themes['adminimal']->status == 0) {
165
      global $base_url;
166
      drupal_set_message(t('Adminimal Theme must be enabled to work properly. Please enable it from the <a href="@link">Appearance page</a>.', array('@link' => $base_url . '/admin/appearance')), 'warning');
167
    }
168
  }
169
}
170

    
171
/**
172
 * Override or insert variables into the page template.
173
 */
174
function adminimal_preprocess_page(&$vars) {
175
  $vars['primary_local_tasks'] = $vars['tabs'];
176
  unset($vars['primary_local_tasks']['#secondary']);
177
  $vars['secondary_local_tasks'] = array(
178
    '#theme' => 'menu_local_tasks',
179
    '#secondary' => $vars['tabs']['#secondary'],
180
  );
181
  unset($vars['page']['hidden']);
182
}
183

    
184
/**
185
 * Display the list of available node types for node creation.
186
 */
187
function adminimal_node_add_list($variables) {
188
  $content = $variables['content'];
189
  $output = '';
190
  if ($content) {
191
    $output = '<ul class="admin-list">';
192
    foreach ($content as $item) {
193
      $output .= '<li class="clearfix">';
194
      $output .= '<span class="label">' . l($item['title'], $item['href'], $item['localized_options']) . '</span>';
195
      $output .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
196
      $output .= '</li>';
197
    }
198
    $output .= '</ul>';
199
  }
200
  else {
201
    $output = '<p>' . t('You have not created any content types yet. Go to the <a href="@create-content">content type creation page</a> to add a new content type.', array('@create-content' => url('admin/structure/types/add'))) . '</p>';
202
  }
203
  return $output;
204
}
205

    
206
/**
207
 * Implements theme_adminimal_block_content().
208
 *
209
 * Use unordered list markup in both compact and extended mode.
210
 */
211
function adminimal_adminimal_block_content($variables) {
212
  $content = $variables['content'];
213
  $output = '';
214
  if (!empty($content)) {
215
    $output = system_adminimal_compact_mode() ? '<ul class="admin-list compact">' : '<ul class="admin-list">';
216
    foreach ($content as $item) {
217
      $output .= '<li class="leaf">';
218
      $output .= l($item['title'], $item['href'], $item['localized_options']);
219
      if (isset($item['description']) && !system_adminimal_compact_mode()) {
220
        $output .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
221
      }
222
      $output .= '</li>';
223
    }
224
    $output .= '</ul>';
225
  }
226
  return $output;
227
}
228

    
229
/**
230
 * Implements theme_tablesort_indicator().
231
 *
232
 * Use our own image versions, so they show up as black and not gray on gray.
233
 */
234
function adminimal_tablesort_indicator($variables) {
235
  $style = $variables['style'];
236
  $theme_path = drupal_get_path('theme', 'adminimal');
237
  if ($style == 'asc') {
238
    return theme('image', array('path' => $theme_path . '/images/arrow-asc.png', 'alt' => t('sort ascending'), 'width' => 13, 'height' => 13, 'title' => t('sort ascending')));
239
  }
240
  else {
241
    return theme('image', array('path' => $theme_path . '/images/arrow-desc.png', 'alt' => t('sort descending'), 'width' => 13, 'height' => 13, 'title' => t('sort descending')));
242
  }
243
}
244

    
245
/**
246
 * Implements hook_css_alter().
247
 */
248
function adminimal_css_alter(&$css) {
249
  // Use Seven's vertical tabs style instead of the default one.
250
  if (isset($css['misc/vertical-tabs.css'])) {
251
    $css['misc/vertical-tabs.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/vertical-tabs.css';
252
  }
253
  if (isset($css['misc/vertical-tabs-rtl.css'])) {
254
    $css['misc/vertical-tabs-rtl.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/vertical-tabs-rtl.css';
255
  }
256
  // Use Seven's jQuery UI theme style instead of the default one.
257
  if (isset($css['misc/ui/jquery.ui.theme.css'])) {
258
    $css['misc/ui/jquery.ui.theme.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/jquery.ui.theme.css';
259
  }
260
}
261

    
262
/**
263
 * Implements hook_js_alter().
264
 */
265
function adminimal_js_alter(&$javascript) {
266
  // Fix module filter available updates page.
267
  if (module_exists('module_filter') && isset($javascript[drupal_get_path('module', 'module_filter') . '/js/update_status.js'])) {
268
    $javascript[drupal_get_path('module','module_filter').'/js/update_status.js']['data'] = drupal_get_path('theme', 'adminimal') . '/js/update_status.js';
269
  }
270
}
271

    
272
/**
273
 * Implements theme_admin_block().
274
 * Adding classes to the administration blocks see issue #1869690.
275
 */
276
function adminimal_admin_block($variables) {
277
  $block = $variables['block'];
278
  $output = '';
279

    
280
  // Don't display the block if it has no content to display.
281
  if (empty($block['show'])) {
282
    return $output;
283
  }
284

    
285
  if (!empty($block['path'])) {
286
    $output .= '<div class="admin-panel ' . check_plain(str_replace("/", " ", $block['path'])) . ' ">';
287
  }
288
  elseif (!empty($block['title'])) {
289
    $output .= '<div class="admin-panel ' . check_plain(strtolower($block['title'])) . '">';
290
  }
291
  else {
292
    $output .= '<div class="admin-panel">';
293
  }
294

    
295
  if (!empty($block['title'])) {
296
    $output .= '<h3 class="title">' . $block['title'] . '</h3>';
297
  }
298

    
299
  if (!empty($block['content'])) {
300
    $output .= '<div class="body">' . $block['content'] . '</div>';
301
  }
302
  else {
303
    $output .= '<div class="description">' . $block['description'] . '</div>';
304
  }
305

    
306
  $output .= '</div>';
307

    
308
  return $output;
309
}
310

    
311
/**
312
 * Implements theme_admin_block_content().
313
 * Adding classes to the administration blocks see issue #1869690.
314
 */
315
function adminimal_admin_block_content($variables) {
316
  $content = $variables['content'];
317
  $output = '';
318

    
319
  if (!empty($content)) {
320
    $class = 'admin-list';
321
    if ($compact = system_admin_compact_mode()) {
322
      $class .= ' compact';
323
    }
324
    $output .= '<dl class="' . $class . '">';
325
    foreach ($content as $item) {
326
      if (!isset($item['path'])) {
327
          $item['path']='';
328
      }
329
      $output .= '<div class="admin-block-item ' . check_plain(str_replace("/", "-", $item['path'])) . '"><dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
330
      if (!$compact && isset($item['description'])) {
331
        $output .= '<dd class="description">' . filter_xss_admin($item['description']) . '</dd>';
332
      }
333
      $output .= '</div>';
334
    }
335
    $output .= '</dl>';
336
  }
337
  return $output;
338
}
339

    
340
/**
341
 * Implements theme_table().
342
 */
343
function adminimal_table($variables) {
344
  $header = $variables['header'];
345
  $rows = $variables['rows'];
346
  $attributes = $variables['attributes'];
347
  $caption = $variables['caption'];
348
  $colgroups = $variables['colgroups'];
349
  $sticky = $variables['sticky'];
350
  $empty = $variables['empty'];
351

    
352
  // Add sticky headers, if applicable.
353
  if (!empty($header) && $sticky) {
354
    drupal_add_js('misc/tableheader.js');
355
    // Add 'sticky-enabled' class to the table to identify it for JS.
356
    // This is needed to target tables constructed by this function.
357
    $attributes['class'][] = 'sticky-enabled';
358
  }
359

    
360
  $output = '<div class="overflow-fix">';
361
  $output .= '<table' . drupal_attributes($attributes) . ">\n";
362

    
363
  if (isset($caption)) {
364
    $output .= '<caption>' . $caption . "</caption>\n";
365
  }
366

    
367
  // Format the table columns:
368
  if (!empty($colgroups)) {
369
    foreach ($colgroups as $number => $colgroup) {
370
      $attributes = array();
371

    
372
      // Check if we're dealing with a simple or complex column
373
      if (isset($colgroup['data'])) {
374
        foreach ($colgroup as $key => $value) {
375
          if ($key == 'data') {
376
            $cols = $value;
377
          }
378
          else {
379
            $attributes[$key] = $value;
380
          }
381
        }
382
      }
383
      else {
384
        $cols = $colgroup;
385
      }
386

    
387
      // Build colgroup
388
      if (is_array($cols) && count($cols)) {
389
        $output .= ' <colgroup' . drupal_attributes($attributes) . '>';
390
        $i = 0;
391
        foreach ($cols as $col) {
392
          $output .= ' <col' . drupal_attributes($col) . ' />';
393
        }
394
        $output .= " </colgroup>\n";
395
      }
396
      else {
397
        $output .= ' <colgroup' . drupal_attributes($attributes) . " />\n";
398
      }
399
    }
400
  }
401

    
402
  // Add the 'empty' row message if available.
403
  if (empty($rows) && $empty) {
404
    $header_count = 0;
405
    if (!empty($header)) {
406
      foreach ($header as $header_cell) {
407
        if (is_array($header_cell)) {
408
          $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1;
409
        }
410
        else {
411
          ++$header_count;
412
        }
413
      }
414
    }
415
    $rows[] = array(array(
416
      'data' => $empty,
417
      'colspan' => $header_count,
418
      'class' => array('empty', 'message'),
419
    ));
420
  }
421

    
422
  // Format the table header:
423
  if (!empty($header)) {
424
    $ts = tablesort_init($header);
425
    // HTML requires that the thead tag has tr tags in it followed by tbody
426
    // tags. Using ternary operator to check and see if we have any rows.
427
    $output .= (!empty($rows) ? ' <thead><tr>' : ' <tr>');
428
    foreach ($header as $cell) {
429
      $cell = tablesort_header($cell, $header, $ts);
430
      $output .= _theme_table_cell($cell, TRUE);
431
    }
432
    // Using ternary operator to close the tags based on whether or not there are rows
433
    $output .= (!empty($rows) ? " </tr></thead>\n" : "</tr>\n");
434
  }
435
  else {
436
    $ts = array();
437
  }
438

    
439
  // Format the table rows:
440
  if (!empty($rows)) {
441
    $output .= "<tbody>\n";
442
    $flip = array(
443
      'even' => 'odd',
444
      'odd' => 'even',
445
    );
446
    $class = 'even';
447
    foreach ($rows as $number => $row) {
448
      // Check if we're dealing with a simple or complex row
449
      if (isset($row['data'])) {
450
        $cells = $row['data'];
451
        $no_striping = isset($row['no_striping']) ? $row['no_striping'] : FALSE;
452

    
453
        // Set the attributes array and exclude 'data' and 'no_striping'.
454
        $attributes = $row;
455
        unset($attributes['data']);
456
        unset($attributes['no_striping']);
457
      }
458
      else {
459
        $cells = $row;
460
        $attributes = array();
461
        $no_striping = FALSE;
462
      }
463
      if (!empty($cells)) {
464
        // Add odd/even class
465
        if (!$no_striping) {
466
          $class = $flip[$class];
467
          $attributes['class'][] = $class;
468
        }
469

    
470
        // Build row
471
        $output .= ' <tr' . drupal_attributes($attributes) . '>';
472
        $i = 0;
473
        foreach ($cells as $cell) {
474
          $cell = tablesort_cell($cell, $header, $ts, $i++);
475
          $output .= _theme_table_cell($cell);
476
        }
477
        $output .= " </tr>\n";
478
      }
479
    }
480
    $output .= "</tbody>\n";
481
  }
482

    
483
  $output .= "</table>\n";
484
  $output .= "</div>\n";
485
  return $output;
486
}
487

    
488
/**
489
 * Set dark skin for CKEditor.
490
 * Implements hook_ckeditor_settings_alter().
491
 */
492
function adminimal_ckeditor_settings_alter(&$settings) {
493

    
494
  // Check if selected adminimal skin is dark.
495
  if (theme_get_setting('adminimal_theme_skin') == 'dark') {
496
    $adminimal_path = drupal_get_path('theme', 'adminimal');
497
    global $base_url;
498
    $settings['skin'] = 'adminimal-dark, '. $base_url .'/'. $adminimal_path . '/skins/dark/ckeditor/';
499
    array_push($settings['contentsCss'], $base_url .'/'. $adminimal_path . '/skins/dark/ckeditor/contents.css');
500
  }
501
}