Projet

Général

Profil

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

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

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

    
106
  // Add responsive styles.
107
  drupal_add_css($adminimal_path . '/css/mobile.css', array('group' => CSS_THEME, 'media' => $media_query_mobile, 'weight' => 1000));
108
  drupal_add_css($adminimal_path . '/css/tablet.css', array('group' => CSS_THEME, 'media' => $media_query_tablet, 'weight' => 1000));
109

    
110
  // Add custom CSS.
111
  $custom_css_path = 'public://adminimal-custom.css';
112
  if (theme_get_setting('custom_css') && file_exists($custom_css_path)) {
113
    drupal_add_css($custom_css_path, array('group' => CSS_THEME, 'weight' => 9999, 'preprocess' => TRUE));
114
  }
115

    
116
  // Fix the viewport and zooming in mobile devices.
117
  $viewport = array(
118
   '#tag' => 'meta',
119
   '#attributes' => array(
120
     'name' => 'viewport',
121
     'content' => 'width=device-width, maximum-scale=1, minimum-scale=1, user-scalable=no, initial-scale=1',
122
   ),
123
  );
124
  drupal_add_html_head($viewport, 'viewport');
125

    
126
  // Remove the no-sidebars class which is always added by core. Core assumes
127
  // the sidebar regions are called sidebar_first and sidebar_second, which
128
  // is not the case in this theme.
129
  $key = array_search('no-sidebars', $vars['classes_array']);
130
  if ($key !== FALSE) {
131
    unset($vars['classes_array'][$key]);
132
  }
133
  // Add information about the number of sidebars.
134
  if (!empty($vars['page']['sidebar_left']) && !empty($vars['page']['sidebar_right'])) {
135
    $vars['classes_array'][] = 'two-sidebars';
136
  }
137
  elseif (!empty($vars['page']['sidebar_left'])) {
138
    $vars['classes_array'][] = 'one-sidebar sidebar-left';
139
  }
140
  elseif (!empty($vars['page']['sidebar_right'])) {
141
    $vars['classes_array'][] = 'one-sidebar sidebar-right';
142
  }
143
  else {
144
    $vars['classes_array'][] = 'no-sidebars';
145
  }
146
}
147

    
148
/**
149
 * Override or insert variables into the page template.
150
 */
151
function adminimal_preprocess_page(&$vars) {
152
  $vars['primary_local_tasks'] = $vars['tabs'];
153
  unset($vars['primary_local_tasks']['#secondary']);
154
  $vars['secondary_local_tasks'] = array(
155
    '#theme' => 'menu_local_tasks',
156
    '#secondary' => $vars['tabs']['#secondary'],
157
  );
158
  unset($vars['page']['hidden']);
159
}
160

    
161
/**
162
 * Display the list of available node types for node creation.
163
 */
164
function adminimal_node_add_list($variables) {
165
  $content = $variables['content'];
166
  $output = '';
167
  if ($content) {
168
    $output = '<ul class="admin-list">';
169
    foreach ($content as $item) {
170
      $output .= '<li class="clearfix">';
171
      $output .= '<span class="label">' . l($item['title'], $item['href'], $item['localized_options']) . '</span>';
172
      $output .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
173
      $output .= '</li>';
174
    }
175
    $output .= '</ul>';
176
  }
177
  else {
178
    $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>';
179
  }
180
  return $output;
181
}
182

    
183
/**
184
 * Implements theme_adminimal_block_content().
185
 *
186
 * Use unordered list markup in both compact and extended mode.
187
 */
188
function adminimal_adminimal_block_content($variables) {
189
  $content = $variables['content'];
190
  $output = '';
191
  if (!empty($content)) {
192
    $output = system_adminimal_compact_mode() ? '<ul class="admin-list compact">' : '<ul class="admin-list">';
193
    foreach ($content as $item) {
194
      $output .= '<li class="leaf">';
195
      $output .= l($item['title'], $item['href'], $item['localized_options']);
196
      if (isset($item['description']) && !system_adminimal_compact_mode()) {
197
        $output .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
198
      }
199
      $output .= '</li>';
200
    }
201
    $output .= '</ul>';
202
  }
203
  return $output;
204
}
205

    
206
/**
207
 * Implements theme_tablesort_indicator().
208
 *
209
 * Use our own image versions, so they show up as black and not gray on gray.
210
 */
211
function adminimal_tablesort_indicator($variables) {
212
  $style = $variables['style'];
213
  $theme_path = drupal_get_path('theme', 'adminimal');
214
  if ($style == 'asc') {
215
    return theme('image', array('path' => $theme_path . '/images/arrow-asc.png', 'alt' => t('sort ascending'), 'width' => 13, 'height' => 13, 'title' => t('sort ascending')));
216
  }
217
  else {
218
    return theme('image', array('path' => $theme_path . '/images/arrow-desc.png', 'alt' => t('sort descending'), 'width' => 13, 'height' => 13, 'title' => t('sort descending')));
219
  }
220
}
221

    
222
/**
223
 * Implements hook_css_alter().
224
 */
225
function adminimal_css_alter(&$css) {
226
  // Use Seven's vertical tabs style instead of the default one.
227
  if (isset($css['misc/vertical-tabs.css'])) {
228
    $css['misc/vertical-tabs.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/vertical-tabs.css';
229
  }
230
  if (isset($css['misc/vertical-tabs-rtl.css'])) {
231
    $css['misc/vertical-tabs-rtl.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/vertical-tabs-rtl.css';
232
  }
233
  // Use Seven's jQuery UI theme style instead of the default one.
234
  if (isset($css['misc/ui/jquery.ui.theme.css'])) {
235
    $css['misc/ui/jquery.ui.theme.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/jquery.ui.theme.css';
236
  }
237
}
238

    
239
/**
240
 * Implements hook_js_alter().
241
 */
242
function adminimal_js_alter(&$javascript) {
243
  // Fix module filter available updates page.
244
  if (isset($javascript[drupal_get_path('module','module_filter').'/js/update_status.js'])) {
245
    $javascript[drupal_get_path('module','module_filter').'/js/update_status.js']['data'] = drupal_get_path('theme', 'adminimal') . '/js/update_status.js';
246
  }
247
}
248

    
249
/**
250
 * Implements theme_admin_block().
251
 * Adding classes to the administration blocks see issue #1869690.
252
 */
253
function adminimal_admin_block($variables) {
254
  $block = $variables['block'];
255
  $output = '';
256

    
257
  // Don't display the block if it has no content to display.
258
  if (empty($block['show'])) {
259
    return $output;
260
  }
261

    
262
  if (!empty($block['path'])) {
263
    $output .= '<div class="admin-panel ' . check_plain(str_replace("/", " ", $block['path'])) . ' ">';
264
  }
265
  elseif (!empty($block['title'])) {
266
    $output .= '<div class="admin-panel ' . check_plain(strtolower($block['title'])) . '">';
267
  }
268
  else {
269
    $output .= '<div class="admin-panel">';
270
  }
271

    
272
  if (!empty($block['title'])) {
273
    $output .= '<h3 class="title">' . $block['title'] . '</h3>';
274
  }
275

    
276
  if (!empty($block['content'])) {
277
    $output .= '<div class="body">' . $block['content'] . '</div>';
278
  }
279
  else {
280
    $output .= '<div class="description">' . $block['description'] . '</div>';
281
  }
282

    
283
  $output .= '</div>';
284

    
285
  return $output;
286
}
287

    
288
/**
289
 * Implements theme_admin_block_content().
290
 * Adding classes to the administration blocks see issue #1869690.
291
 */
292
function adminimal_admin_block_content($variables) {
293
  $content = $variables['content'];
294
  $output = '';
295

    
296
  if (!empty($content)) {
297
    $class = 'admin-list';
298
    if ($compact = system_admin_compact_mode()) {
299
      $class .= ' compact';
300
    }
301
    $output .= '<dl class="' . $class . '">';
302
    foreach ($content as $item) {
303
      if (!isset($item['path'])) {
304
          $item['path']='';
305
      }
306
      $output .= '<div class="admin-block-item ' . check_plain(str_replace("/", "-", $item['path'])) . '"><dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
307
      if (!$compact && isset($item['description'])) {
308
        $output .= '<dd class="description">' . filter_xss_admin($item['description']) . '</dd>';
309
      }
310
      $output .= '</div>';
311
    }
312
    $output .= '</dl>';
313
  }
314
  return $output;
315
}
316

    
317
/**
318
 * Implements theme_table().
319
 */
320
function adminimal_table($variables) {
321
  $header = $variables['header'];
322
  $rows = $variables['rows'];
323
  $attributes = $variables['attributes'];
324
  $caption = $variables['caption'];
325
  $colgroups = $variables['colgroups'];
326
  $sticky = $variables['sticky'];
327
  $empty = $variables['empty'];
328

    
329
  // Add sticky headers, if applicable.
330
  if (count($header) && $sticky) {
331
    drupal_add_js('misc/tableheader.js');
332
    // Add 'sticky-enabled' class to the table to identify it for JS.
333
    // This is needed to target tables constructed by this function.
334
    $attributes['class'][] = 'sticky-enabled';
335
  }
336

    
337
  $output = '<div class="overflow-fix">';
338
  $output .= '<table' . drupal_attributes($attributes) . ">\n";
339

    
340
  if (isset($caption)) {
341
    $output .= '<caption>' . $caption . "</caption>\n";
342
  }
343

    
344
  // Format the table columns:
345
  if (count($colgroups)) {
346
    foreach ($colgroups as $number => $colgroup) {
347
      $attributes = array();
348

    
349
      // Check if we're dealing with a simple or complex column
350
      if (isset($colgroup['data'])) {
351
        foreach ($colgroup as $key => $value) {
352
          if ($key == 'data') {
353
            $cols = $value;
354
          }
355
          else {
356
            $attributes[$key] = $value;
357
          }
358
        }
359
      }
360
      else {
361
        $cols = $colgroup;
362
      }
363

    
364
      // Build colgroup
365
      if (is_array($cols) && count($cols)) {
366
        $output .= ' <colgroup' . drupal_attributes($attributes) . '>';
367
        $i = 0;
368
        foreach ($cols as $col) {
369
          $output .= ' <col' . drupal_attributes($col) . ' />';
370
        }
371
        $output .= " </colgroup>\n";
372
      }
373
      else {
374
        $output .= ' <colgroup' . drupal_attributes($attributes) . " />\n";
375
      }
376
    }
377
  }
378

    
379
  // Add the 'empty' row message if available.
380
  if (!count($rows) && $empty) {
381
    $header_count = 0;
382
    foreach ($header as $header_cell) {
383
      if (is_array($header_cell)) {
384
        $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1;
385
      }
386
      else {
387
        ++$header_count;
388
      }
389
    }
390
    $rows[] = array(array(
391
      'data' => $empty,
392
      'colspan' => $header_count,
393
      'class' => array('empty', 'message'),
394
    ));
395
  }
396

    
397
  // Format the table header:
398
  if (count($header)) {
399
    $ts = tablesort_init($header);
400
    // HTML requires that the thead tag has tr tags in it followed by tbody
401
    // tags. Using ternary operator to check and see if we have any rows.
402
    $output .= (count($rows) ? ' <thead><tr>' : ' <tr>');
403
    foreach ($header as $cell) {
404
      $cell = tablesort_header($cell, $header, $ts);
405
      $output .= _theme_table_cell($cell, TRUE);
406
    }
407
    // Using ternary operator to close the tags based on whether or not there are rows
408
    $output .= (count($rows) ? " </tr></thead>\n" : "</tr>\n");
409
  }
410
  else {
411
    $ts = array();
412
  }
413

    
414
  // Format the table rows:
415
  if (count($rows)) {
416
    $output .= "<tbody>\n";
417
    $flip = array(
418
      'even' => 'odd',
419
      'odd' => 'even',
420
    );
421
    $class = 'even';
422
    foreach ($rows as $number => $row) {
423
      // Check if we're dealing with a simple or complex row
424
      if (isset($row['data'])) {
425
        $cells = $row['data'];
426
        $no_striping = isset($row['no_striping']) ? $row['no_striping'] : FALSE;
427

    
428
        // Set the attributes array and exclude 'data' and 'no_striping'.
429
        $attributes = $row;
430
        unset($attributes['data']);
431
        unset($attributes['no_striping']);
432
      }
433
      else {
434
        $cells = $row;
435
        $attributes = array();
436
        $no_striping = FALSE;
437
      }
438
      if (count($cells)) {
439
        // Add odd/even class
440
        if (!$no_striping) {
441
          $class = $flip[$class];
442
          $attributes['class'][] = $class;
443
        }
444

    
445
        // Build row
446
        $output .= ' <tr' . drupal_attributes($attributes) . '>';
447
        $i = 0;
448
        foreach ($cells as $cell) {
449
          $cell = tablesort_cell($cell, $header, $ts, $i++);
450
          $output .= _theme_table_cell($cell);
451
        }
452
        $output .= " </tr>\n";
453
      }
454
    }
455
    $output .= "</tbody>\n";
456
  }
457

    
458
  $output .= "</table>\n";
459
  $output .= "</div>\n";
460
  return $output;
461
}