Projet

Général

Profil

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

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

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( 'media' => 'all', 'weight' => -999));
30
  drupal_add_css($adminimal_path . '/css/style.css', array( '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' => FALSE));
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' => FALSE));
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' => FALSE));
40

    
41
  // Add theme name to body class.
42
  $vars['classes_array'][] = 'adminimal-theme';
43

    
44
  // Add icons to the admin configuration page.
45
  if (theme_get_setting('display_icons_config')) {
46
    drupal_add_css($adminimal_path . '/css/icons-config.css', array('group' => CSS_THEME, 'weight' => 10, 'preprocess' => FALSE));
47
  }
48

    
49
  // Define Default media queries.
50
  $media_query_mobile = 'only screen and (max-width: 480px)';
51
  $media_query_tablet = 'only screen and (min-width : 481px) and (max-width : 1024px)';
52

    
53
  // Get custom media queries if set.
54
  if (theme_get_setting('use_custom_media_queries')) {
55
    $media_query_mobile = theme_get_setting('media_query_mobile');
56
    $media_query_tablet = theme_get_setting('media_query_tablet');
57
  }
58

    
59
  // Add responsive styles.
60
  drupal_add_css($adminimal_path . '/css/mobile.css', array( 'media' => $media_query_mobile, 'weight' => 1000));
61
  drupal_add_css($adminimal_path . '/css/tablet.css', array( 'media' => $media_query_tablet, 'weight' => 1000));
62

    
63
  // Add custom CSS.
64
  $custom_css_path = $adminimal_path . '/css/custom.css'; 
65
  if (theme_get_setting('custom_css') && file_exists($custom_css_path)) {
66
    drupal_add_css($custom_css_path, array('group' => CSS_THEME, 'weight' => 9999, 'preprocess' => FALSE));
67
  }
68

    
69
  // Fix the viewport and zooming in mobile devices.
70
  $viewport = array(
71
   '#tag' => 'meta',
72
   '#attributes' => array(
73
     'name' => 'viewport',
74
     'content' => 'width=device-width, maximum-scale=1, minimum-scale=1, user-scalable=no, initial-scale=1',
75
   ),
76
  );
77
  drupal_add_html_head($viewport, 'viewport');
78

    
79
}
80

    
81
/**
82
 * Override or insert variables into the page template.
83
 */
84
function adminimal_preprocess_page(&$vars) {
85
  $vars['primary_local_tasks'] = $vars['tabs'];
86
  unset($vars['primary_local_tasks']['#secondary']);
87
  $vars['secondary_local_tasks'] = array(
88
    '#theme' => 'menu_local_tasks',
89
    '#secondary' => $vars['tabs']['#secondary'],
90
  );
91

    
92
}
93

    
94
/**
95
 * Display the list of available node types for node creation.
96
 */
97
function adminimal_node_add_list($variables) {
98
  $content = $variables['content'];
99
  $output = '';
100
  if ($content) {
101
    $output = '<ul class="admin-list">';
102
    foreach ($content as $item) {
103
      $output .= '<li class="clearfix">';
104
      $output .= '<span class="label">' . l($item['title'], $item['href'], $item['localized_options']) . '</span>';
105
      $output .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
106
      $output .= '</li>';
107
    }
108
    $output .= '</ul>';
109
  }
110
  else {
111
    $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>';
112
  }
113
  return $output;
114
}
115

    
116
/**
117
 * Implements theme_adminimal_block_content().
118
 *
119
 * Use unordered list markup in both compact and extended mode.
120
 */
121
function adminimal_adminimal_block_content($variables) {
122
  $content = $variables['content'];
123
  $output = '';
124
  if (!empty($content)) {
125
    $output = system_adminimal_compact_mode() ? '<ul class="admin-list compact">' : '<ul class="admin-list">';
126
    foreach ($content as $item) {
127
      $output .= '<li class="leaf">';
128
      $output .= l($item['title'], $item['href'], $item['localized_options']);
129
      if (isset($item['description']) && !system_adminimal_compact_mode()) {
130
        $output .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
131
      }
132
      $output .= '</li>';
133
    }
134
    $output .= '</ul>';
135
  }
136
  return $output;
137
}
138

    
139
/**
140
 * Implements theme_tablesort_indicator().
141
 * 
142
 * Use our own image versions, so they show up as black and not gray on gray.
143
 */
144
function adminimal_tablesort_indicator($variables) {
145
  $style = $variables['style'];
146
  $theme_path = drupal_get_path('theme', 'adminimal');
147
  if ($style == 'asc') {
148
    return theme('image', array('path' => $theme_path . '/images/arrow-asc.png', 'alt' => t('sort ascending'), 'width' => 13, 'height' => 13, 'title' => t('sort ascending')));
149
  }
150
  else {
151
    return theme('image', array('path' => $theme_path . '/images/arrow-desc.png', 'alt' => t('sort descending'), 'width' => 13, 'height' => 13, 'title' => t('sort descending')));
152
  }
153
}
154

    
155
/**
156
 * Implements hook_css_alter().
157
 */
158
function adminimal_css_alter(&$css) {
159
  // Use Seven's vertical tabs style instead of the default one.
160
  if (isset($css['misc/vertical-tabs.css'])) {
161
    $css['misc/vertical-tabs.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/vertical-tabs.css';
162
  }
163
  if (isset($css['misc/vertical-tabs-rtl.css'])) {
164
    $css['misc/vertical-tabs-rtl.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/vertical-tabs-rtl.css';
165
  }
166
  // Use Seven's jQuery UI theme style instead of the default one.
167
  if (isset($css['misc/ui/jquery.ui.theme.css'])) {
168
    $css['misc/ui/jquery.ui.theme.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/jquery.ui.theme.css';
169
  }
170
}
171

    
172
/**
173
 * Implements theme_admin_block().
174
 * Adding classes to the administration blocks see issue #1869690.
175
 */
176
function adminimal_admin_block($variables) {
177
  $block = $variables['block'];
178
  $output = '';
179

    
180
  // Don't display the block if it has no content to display.
181
  if (empty($block['show'])) {
182
    return $output;
183
  }
184

    
185
  if (!empty($block['path'])) {
186
    $output .= '<div class="admin-panel ' . check_plain(str_replace("/", " ", $block['path'])) . ' ">';
187
  }
188
  elseif (!empty($block['title'])) {
189
    $output .= '<div class="admin-panel ' . check_plain(strtolower($block['title'])) . '">';
190
  }
191
  else {
192
    $output .= '<div class="admin-panel">';
193
  }
194

    
195
  if (!empty($block['title'])) {
196
    $output .= '<h3 class="title">' . $block['title'] . '</h3>';
197
  }
198

    
199
  if (!empty($block['content'])) {
200
    $output .= '<div class="body">' . $block['content'] . '</div>';
201
  }
202
  else {
203
    $output .= '<div class="description">' . $block['description'] . '</div>';
204
  }
205

    
206
  $output .= '</div>';
207

    
208
  return $output;
209

    
210
}
211

    
212
/**
213
 * Implements theme_admin_block_content().
214
 * Adding classes to the administration blocks see issue #1869690.
215
 */
216
function adminimal_admin_block_content($variables) {
217
  $content = $variables['content'];
218
  $output = '';
219

    
220
  if (!empty($content)) {
221
    $class = 'admin-list';
222
    if ($compact = system_admin_compact_mode()) {
223
      $class .= ' compact';
224
    }
225
    $output .= '<dl class="' . $class . '">';
226
    foreach ($content as $item) {
227
      if (!isset($item['path'])) {
228
          $item['path']='';
229
      }
230
      $output .= '<div class="admin-block-item ' . check_plain(str_replace("/", "-", $item['path'])) . '"><dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
231
      if (!$compact && isset($item['description'])) {
232
        $output .= '<dd class="description">' . filter_xss_admin($item['description']) . '</dd>';
233
      }
234
      $output .= '</div>';
235
    }
236
    $output .= '</dl>';
237
  }
238
  return $output;
239
}
240

    
241
/**
242
 * Implements theme_table().
243
 */
244
function adminimal_table($variables) {
245
  $header = $variables['header'];
246
  $rows = $variables['rows'];
247
  $attributes = $variables['attributes'];
248
  $caption = $variables['caption'];
249
  $colgroups = $variables['colgroups'];
250
  $sticky = $variables['sticky'];
251
  $empty = $variables['empty'];
252

    
253
  // Add sticky headers, if applicable.
254
  if (count($header) && $sticky) {
255
    drupal_add_js('misc/tableheader.js');
256
    // Add 'sticky-enabled' class to the table to identify it for JS.
257
    // This is needed to target tables constructed by this function.
258
    $attributes['class'][] = 'sticky-enabled';
259
  }
260

    
261
  $output = '<div class="overflow-fix">';
262
  $output .= '<table' . drupal_attributes($attributes) . ">\n";
263

    
264
  if (isset($caption)) {
265
    $output .= '<caption>' . $caption . "</caption>\n";
266
  }
267

    
268
  // Format the table columns:
269
  if (count($colgroups)) {
270
    foreach ($colgroups as $number => $colgroup) {
271
      $attributes = array();
272

    
273
      // Check if we're dealing with a simple or complex column
274
      if (isset($colgroup['data'])) {
275
        foreach ($colgroup as $key => $value) {
276
          if ($key == 'data') {
277
            $cols = $value;
278
          }
279
          else {
280
            $attributes[$key] = $value;
281
          }
282
        }
283
      }
284
      else {
285
        $cols = $colgroup;
286
      }
287

    
288
      // Build colgroup
289
      if (is_array($cols) && count($cols)) {
290
        $output .= ' <colgroup' . drupal_attributes($attributes) . '>';
291
        $i = 0;
292
        foreach ($cols as $col) {
293
          $output .= ' <col' . drupal_attributes($col) . ' />';
294
        }
295
        $output .= " </colgroup>\n";
296
      }
297
      else {
298
        $output .= ' <colgroup' . drupal_attributes($attributes) . " />\n";
299
      }
300
    }
301
  }
302

    
303
  // Add the 'empty' row message if available.
304
  if (!count($rows) && $empty) {
305
    $header_count = 0;
306
    foreach ($header as $header_cell) {
307
      if (is_array($header_cell)) {
308
        $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1;
309
      }
310
      else {
311
        ++$header_count;
312
      }
313
    }
314
    $rows[] = array(array(
315
      'data' => $empty,
316
      'colspan' => $header_count,
317
      'class' => array('empty', 'message'),
318
    ));
319
  }
320

    
321
  // Format the table header:
322
  if (count($header)) {
323
    $ts = tablesort_init($header);
324
    // HTML requires that the thead tag has tr tags in it followed by tbody
325
    // tags. Using ternary operator to check and see if we have any rows.
326
    $output .= (count($rows) ? ' <thead><tr>' : ' <tr>');
327
    foreach ($header as $cell) {
328
      $cell = tablesort_header($cell, $header, $ts);
329
      $output .= _theme_table_cell($cell, TRUE);
330
    }
331
    // Using ternary operator to close the tags based on whether or not there are rows
332
    $output .= (count($rows) ? " </tr></thead>\n" : "</tr>\n");
333
  }
334
  else {
335
    $ts = array();
336
  }
337

    
338
  // Format the table rows:
339
  if (count($rows)) {
340
    $output .= "<tbody>\n";
341
    $flip = array(
342
      'even' => 'odd',
343
      'odd' => 'even',
344
    );
345
    $class = 'even';
346
    foreach ($rows as $number => $row) {
347
      // Check if we're dealing with a simple or complex row
348
      if (isset($row['data'])) {
349
        $cells = $row['data'];
350
        $no_striping = isset($row['no_striping']) ? $row['no_striping'] : FALSE;
351

    
352
        // Set the attributes array and exclude 'data' and 'no_striping'.
353
        $attributes = $row;
354
        unset($attributes['data']);
355
        unset($attributes['no_striping']);
356
      }
357
      else {
358
        $cells = $row;
359
        $attributes = array();
360
        $no_striping = FALSE;
361
      }
362
      if (count($cells)) {
363
        // Add odd/even class
364
        if (!$no_striping) {
365
          $class = $flip[$class];
366
          $attributes['class'][] = $class;
367
        }
368

    
369
        // Build row
370
        $output .= ' <tr' . drupal_attributes($attributes) . '>';
371
        $i = 0;
372
        foreach ($cells as $cell) {
373
          $cell = tablesort_cell($cell, $header, $ts, $i++);
374
          $output .= _theme_table_cell($cell);
375
        }
376
        $output .= " </tr>\n";
377
      }
378
    }
379
    $output .= "</tbody>\n";
380
  }
381

    
382
  $output .= "</table>\n";
383
  $output .= "</div>\n";
384
  return $output;
385
}