Projet

Général

Profil

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

root / drupal7 / sites / all / themes / adminimal_theme / template.php @ 4b706e38

1 87dbc3bf Benjamin Luce
<?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 9d13637e Assos Assos
  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 87dbc3bf Benjamin Luce
32
  // Add conditional CSS for IE8 and below.
33 c6d34680 Assos Assos
  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 87dbc3bf Benjamin Luce
35
  // Add conditional CSS for IE7 and below.
36 c6d34680 Assos Assos
  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 87dbc3bf Benjamin Luce
38
  // Add conditional CSS for IE6.
39 c6d34680 Assos Assos
  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 87dbc3bf Benjamin Luce
41 3b63f8c7 Assos Assos
  //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 87dbc3bf Benjamin Luce
  // Add theme name to body class.
47
  $vars['classes_array'][] = 'adminimal-theme';
48
49 c6d34680 Assos Assos
  // Style checkbox and radio buttons in Webkit Browsers.
50
  if (theme_get_setting('style_checkboxes')) {
51
    $vars['classes_array'][] = 'style-checkboxes';
52
  }
53
54 3b63f8c7 Assos Assos
  // 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 87dbc3bf Benjamin Luce
  // Add icons to the admin configuration page.
65
  if (theme_get_setting('display_icons_config')) {
66 c6d34680 Assos Assos
    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 87dbc3bf Benjamin Luce
  }
73
74
  // Define Default media queries.
75
  $media_query_mobile = 'only screen and (max-width: 480px)';
76
  $media_query_tablet = 'only screen and (min-width : 481px) and (max-width : 1024px)';
77
78
  // Get custom media queries if set.
79
  if (theme_get_setting('use_custom_media_queries')) {
80
    $media_query_mobile = theme_get_setting('media_query_mobile');
81
    $media_query_tablet = theme_get_setting('media_query_tablet');
82
  }
83
84 c6d34680 Assos Assos
  // Load custom Adminimal skin.
85
  $adminimal_skin = theme_get_setting('adminimal_theme_skin');
86
  if ((!is_null($adminimal_skin))) {
87
    drupal_add_css($adminimal_path . '/skins/' . $adminimal_skin . '/' . $adminimal_skin . '.css', array('group' => CSS_THEME, 'weight' => 900, 'preprocess' => TRUE));
88
    // Add conditional CSS for Mac OS X.
89
    drupal_add_css($adminimal_path . '/skins/' . $adminimal_skin . '/mac_os_x.css', array('group' => CSS_THEME, 'weight' => 950, 'preprocess' => TRUE));
90
    drupal_add_js($adminimal_path . '/skins/' . $adminimal_skin . '/' . $adminimal_skin . '.js');
91
    $vars['classes_array'][] = 'adminimal-skin-' . $adminimal_skin ;
92
  }
93
  else {
94
    drupal_add_css($adminimal_path . '/skins/default/default.css', array('group' => CSS_THEME, 'weight' => 900, 'preprocess' => TRUE));
95
    // Add conditional CSS for Mac OS X.
96
    drupal_add_css($adminimal_path . '/skins/default/mac_os_x.css', array('group' => CSS_THEME, 'weight' => 950, 'preprocess' => TRUE));
97
    drupal_add_js($adminimal_path . '/skins/default/default.js');
98
    $vars['classes_array'][] = 'adminimal-skin-default' ;
99
  }
100
101 87dbc3bf Benjamin Luce
  // Add responsive styles.
102 9d13637e Assos Assos
  drupal_add_css($adminimal_path . '/css/mobile.css', array('group' => CSS_THEME, 'media' => $media_query_mobile, 'weight' => 1000));
103
  drupal_add_css($adminimal_path . '/css/tablet.css', array('group' => CSS_THEME, 'media' => $media_query_tablet, 'weight' => 1000));
104 87dbc3bf Benjamin Luce
105
  // Add custom CSS.
106 e4c061ad Assos Assos
  $custom_css_path = 'public://adminimal-custom.css';
107 87dbc3bf Benjamin Luce
  if (theme_get_setting('custom_css') && file_exists($custom_css_path)) {
108 c6d34680 Assos Assos
    drupal_add_css($custom_css_path, array('group' => CSS_THEME, 'weight' => 9999, 'preprocess' => TRUE));
109 87dbc3bf Benjamin Luce
  }
110
111
  // Fix the viewport and zooming in mobile devices.
112
  $viewport = array(
113
   '#tag' => 'meta',
114
   '#attributes' => array(
115
     'name' => 'viewport',
116
     'content' => 'width=device-width, maximum-scale=1, minimum-scale=1, user-scalable=no, initial-scale=1',
117
   ),
118
  );
119
  drupal_add_html_head($viewport, 'viewport');
120
121 3b63f8c7 Assos Assos
  // Remove the no-sidebars class which is always added by core. Core assumes
122
  // the sidebar regions are called sidebar_first and sidebar_second, which
123
  // is not the case in this theme.
124
  $key = array_search('no-sidebars', $vars['classes_array']);
125
  if ($key !== FALSE) {
126
    unset($vars['classes_array'][$key]);
127
  }
128
  // Add information about the number of sidebars.
129
  if (!empty($vars['page']['sidebar_left']) && !empty($vars['page']['sidebar_right'])) {
130
    $vars['classes_array'][] = 'two-sidebars';
131
  }
132
  elseif (!empty($vars['page']['sidebar_left'])) {
133
    $vars['classes_array'][] = 'one-sidebar sidebar-left';
134
  }
135
  elseif (!empty($vars['page']['sidebar_right'])) {
136
    $vars['classes_array'][] = 'one-sidebar sidebar-right';
137
  }
138
  else {
139
    $vars['classes_array'][] = 'no-sidebars';
140
  }
141 87dbc3bf Benjamin Luce
}
142
143
/**
144
 * Override or insert variables into the page template.
145
 */
146
function adminimal_preprocess_page(&$vars) {
147
  $vars['primary_local_tasks'] = $vars['tabs'];
148
  unset($vars['primary_local_tasks']['#secondary']);
149
  $vars['secondary_local_tasks'] = array(
150
    '#theme' => 'menu_local_tasks',
151
    '#secondary' => $vars['tabs']['#secondary'],
152
  );
153 3b63f8c7 Assos Assos
  unset($vars['page']['hidden']);
154 87dbc3bf Benjamin Luce
}
155
156
/**
157
 * Display the list of available node types for node creation.
158
 */
159
function adminimal_node_add_list($variables) {
160
  $content = $variables['content'];
161
  $output = '';
162
  if ($content) {
163
    $output = '<ul class="admin-list">';
164
    foreach ($content as $item) {
165
      $output .= '<li class="clearfix">';
166
      $output .= '<span class="label">' . l($item['title'], $item['href'], $item['localized_options']) . '</span>';
167
      $output .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
168
      $output .= '</li>';
169
    }
170
    $output .= '</ul>';
171
  }
172
  else {
173
    $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>';
174
  }
175
  return $output;
176
}
177
178
/**
179
 * Implements theme_adminimal_block_content().
180
 *
181
 * Use unordered list markup in both compact and extended mode.
182
 */
183
function adminimal_adminimal_block_content($variables) {
184
  $content = $variables['content'];
185
  $output = '';
186
  if (!empty($content)) {
187
    $output = system_adminimal_compact_mode() ? '<ul class="admin-list compact">' : '<ul class="admin-list">';
188
    foreach ($content as $item) {
189
      $output .= '<li class="leaf">';
190
      $output .= l($item['title'], $item['href'], $item['localized_options']);
191
      if (isset($item['description']) && !system_adminimal_compact_mode()) {
192
        $output .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
193
      }
194
      $output .= '</li>';
195
    }
196
    $output .= '</ul>';
197
  }
198
  return $output;
199
}
200
201
/**
202
 * Implements theme_tablesort_indicator().
203 c6d34680 Assos Assos
 *
204 87dbc3bf Benjamin Luce
 * Use our own image versions, so they show up as black and not gray on gray.
205
 */
206
function adminimal_tablesort_indicator($variables) {
207
  $style = $variables['style'];
208
  $theme_path = drupal_get_path('theme', 'adminimal');
209
  if ($style == 'asc') {
210
    return theme('image', array('path' => $theme_path . '/images/arrow-asc.png', 'alt' => t('sort ascending'), 'width' => 13, 'height' => 13, 'title' => t('sort ascending')));
211
  }
212
  else {
213
    return theme('image', array('path' => $theme_path . '/images/arrow-desc.png', 'alt' => t('sort descending'), 'width' => 13, 'height' => 13, 'title' => t('sort descending')));
214
  }
215
}
216
217
/**
218
 * Implements hook_css_alter().
219
 */
220
function adminimal_css_alter(&$css) {
221
  // Use Seven's vertical tabs style instead of the default one.
222
  if (isset($css['misc/vertical-tabs.css'])) {
223
    $css['misc/vertical-tabs.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/vertical-tabs.css';
224
  }
225
  if (isset($css['misc/vertical-tabs-rtl.css'])) {
226
    $css['misc/vertical-tabs-rtl.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/vertical-tabs-rtl.css';
227
  }
228
  // Use Seven's jQuery UI theme style instead of the default one.
229
  if (isset($css['misc/ui/jquery.ui.theme.css'])) {
230
    $css['misc/ui/jquery.ui.theme.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/jquery.ui.theme.css';
231
  }
232
}
233
234 c6d34680 Assos Assos
/**
235
 * Implements hook_js_alter().
236
 */
237
function adminimal_js_alter(&$javascript) {
238
  // Fix module filter available updates page.
239
  if (isset($javascript[drupal_get_path('module','module_filter').'/js/update_status.js'])) {
240
    $javascript[drupal_get_path('module','module_filter').'/js/update_status.js']['data'] = drupal_get_path('theme', 'adminimal') . '/js/update_status.js';
241
  }
242
}
243
244 87dbc3bf Benjamin Luce
/**
245
 * Implements theme_admin_block().
246
 * Adding classes to the administration blocks see issue #1869690.
247
 */
248
function adminimal_admin_block($variables) {
249
  $block = $variables['block'];
250
  $output = '';
251
252
  // Don't display the block if it has no content to display.
253
  if (empty($block['show'])) {
254
    return $output;
255
  }
256
257
  if (!empty($block['path'])) {
258
    $output .= '<div class="admin-panel ' . check_plain(str_replace("/", " ", $block['path'])) . ' ">';
259
  }
260
  elseif (!empty($block['title'])) {
261
    $output .= '<div class="admin-panel ' . check_plain(strtolower($block['title'])) . '">';
262
  }
263
  else {
264
    $output .= '<div class="admin-panel">';
265
  }
266
267
  if (!empty($block['title'])) {
268
    $output .= '<h3 class="title">' . $block['title'] . '</h3>';
269
  }
270
271
  if (!empty($block['content'])) {
272
    $output .= '<div class="body">' . $block['content'] . '</div>';
273
  }
274
  else {
275
    $output .= '<div class="description">' . $block['description'] . '</div>';
276
  }
277
278
  $output .= '</div>';
279
280
  return $output;
281
}
282
283
/**
284
 * Implements theme_admin_block_content().
285
 * Adding classes to the administration blocks see issue #1869690.
286
 */
287
function adminimal_admin_block_content($variables) {
288
  $content = $variables['content'];
289
  $output = '';
290
291
  if (!empty($content)) {
292
    $class = 'admin-list';
293
    if ($compact = system_admin_compact_mode()) {
294
      $class .= ' compact';
295
    }
296
    $output .= '<dl class="' . $class . '">';
297
    foreach ($content as $item) {
298
      if (!isset($item['path'])) {
299
          $item['path']='';
300
      }
301
      $output .= '<div class="admin-block-item ' . check_plain(str_replace("/", "-", $item['path'])) . '"><dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
302
      if (!$compact && isset($item['description'])) {
303
        $output .= '<dd class="description">' . filter_xss_admin($item['description']) . '</dd>';
304
      }
305
      $output .= '</div>';
306
    }
307
    $output .= '</dl>';
308
  }
309
  return $output;
310
}
311
312
/**
313
 * Implements theme_table().
314
 */
315
function adminimal_table($variables) {
316
  $header = $variables['header'];
317
  $rows = $variables['rows'];
318
  $attributes = $variables['attributes'];
319
  $caption = $variables['caption'];
320
  $colgroups = $variables['colgroups'];
321
  $sticky = $variables['sticky'];
322
  $empty = $variables['empty'];
323
324
  // Add sticky headers, if applicable.
325
  if (count($header) && $sticky) {
326
    drupal_add_js('misc/tableheader.js');
327
    // Add 'sticky-enabled' class to the table to identify it for JS.
328
    // This is needed to target tables constructed by this function.
329
    $attributes['class'][] = 'sticky-enabled';
330
  }
331
332
  $output = '<div class="overflow-fix">';
333
  $output .= '<table' . drupal_attributes($attributes) . ">\n";
334
335
  if (isset($caption)) {
336
    $output .= '<caption>' . $caption . "</caption>\n";
337
  }
338
339
  // Format the table columns:
340
  if (count($colgroups)) {
341
    foreach ($colgroups as $number => $colgroup) {
342
      $attributes = array();
343
344
      // Check if we're dealing with a simple or complex column
345
      if (isset($colgroup['data'])) {
346
        foreach ($colgroup as $key => $value) {
347
          if ($key == 'data') {
348
            $cols = $value;
349
          }
350
          else {
351
            $attributes[$key] = $value;
352
          }
353
        }
354
      }
355
      else {
356
        $cols = $colgroup;
357
      }
358
359
      // Build colgroup
360
      if (is_array($cols) && count($cols)) {
361
        $output .= ' <colgroup' . drupal_attributes($attributes) . '>';
362
        $i = 0;
363
        foreach ($cols as $col) {
364
          $output .= ' <col' . drupal_attributes($col) . ' />';
365
        }
366
        $output .= " </colgroup>\n";
367
      }
368
      else {
369
        $output .= ' <colgroup' . drupal_attributes($attributes) . " />\n";
370
      }
371
    }
372
  }
373
374
  // Add the 'empty' row message if available.
375
  if (!count($rows) && $empty) {
376
    $header_count = 0;
377
    foreach ($header as $header_cell) {
378
      if (is_array($header_cell)) {
379
        $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1;
380
      }
381
      else {
382
        ++$header_count;
383
      }
384
    }
385
    $rows[] = array(array(
386
      'data' => $empty,
387
      'colspan' => $header_count,
388
      'class' => array('empty', 'message'),
389
    ));
390
  }
391
392
  // Format the table header:
393
  if (count($header)) {
394
    $ts = tablesort_init($header);
395
    // HTML requires that the thead tag has tr tags in it followed by tbody
396
    // tags. Using ternary operator to check and see if we have any rows.
397
    $output .= (count($rows) ? ' <thead><tr>' : ' <tr>');
398
    foreach ($header as $cell) {
399
      $cell = tablesort_header($cell, $header, $ts);
400
      $output .= _theme_table_cell($cell, TRUE);
401
    }
402
    // Using ternary operator to close the tags based on whether or not there are rows
403
    $output .= (count($rows) ? " </tr></thead>\n" : "</tr>\n");
404
  }
405
  else {
406
    $ts = array();
407
  }
408
409
  // Format the table rows:
410
  if (count($rows)) {
411
    $output .= "<tbody>\n";
412
    $flip = array(
413
      'even' => 'odd',
414
      'odd' => 'even',
415
    );
416
    $class = 'even';
417
    foreach ($rows as $number => $row) {
418
      // Check if we're dealing with a simple or complex row
419
      if (isset($row['data'])) {
420
        $cells = $row['data'];
421
        $no_striping = isset($row['no_striping']) ? $row['no_striping'] : FALSE;
422
423
        // Set the attributes array and exclude 'data' and 'no_striping'.
424
        $attributes = $row;
425
        unset($attributes['data']);
426
        unset($attributes['no_striping']);
427
      }
428
      else {
429
        $cells = $row;
430
        $attributes = array();
431
        $no_striping = FALSE;
432
      }
433
      if (count($cells)) {
434
        // Add odd/even class
435
        if (!$no_striping) {
436
          $class = $flip[$class];
437
          $attributes['class'][] = $class;
438
        }
439
440
        // Build row
441
        $output .= ' <tr' . drupal_attributes($attributes) . '>';
442
        $i = 0;
443
        foreach ($cells as $cell) {
444
          $cell = tablesort_cell($cell, $header, $ts, $i++);
445
          $output .= _theme_table_cell($cell);
446
        }
447
        $output .= " </tr>\n";
448
      }
449
    }
450
    $output .= "</tbody>\n";
451
  }
452
453
  $output .= "</table>\n";
454
  $output .= "</div>\n";
455
  return $output;
456
}