Projet

Général

Profil

Paste
Télécharger (36,2 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / adaptivetheme / at_core / inc / preprocess.inc @ 74f6bef0

1
<?php
2

    
3
/**
4
 * @file
5
 * All Preprocess functions for templates and theme fucntions.
6
 * If you need to add or modify preprocess functions do it in your sub-theme.
7
 */
8

    
9
/**
10
 * Preprocess variables for all templates.
11
 */
12
function adaptivetheme_preprocess(&$vars) {
13
  // Provide variables to all templates to test for a mobile and tablet context, this
14
  // requires the Mobile Detect or Browscap modules.  TRUE/FALSE mean the feature
15
  // was detected; NULL means the feature could not be properly detected.
16
  $browser = at_get_browser();
17
  $vars['is_mobile'] = $browser['is_mobile'];
18
  $vars['is_tablet'] = $browser['is_tablet'];
19
}
20

    
21
/**
22
 * Preprocess variables for html.tpl.php
23
 */
24
function adaptivetheme_preprocess_html(&$vars) {
25
  global $theme_key, $language;
26
  $theme_name = $theme_key;
27

    
28
  // Set variable for the base path
29
  $vars['base_path'] = base_path();
30

    
31
  // Get the info file data
32
  $info = at_get_info($theme_name);
33

    
34
  // DOCTYPE
35
  // AT no longer uses doctype switching or $rdf_profile, these maintain
36
  // backwards compatibility with pre 7.x-2.1 versions of html.tpl.php
37
  $vars['doctype'] = '<!DOCTYPE html>' . "\n";
38
  $vars['rdf_profile'] = '';
39

    
40
  // Use a proper attributes array for the html attributes.
41
  // You can add more attributes to the html elment, for example in a sub-theme you can do this:
42
  // $vars['html_attributes_array']['xmlns:og'][] = 'http://opengraphprotocol.org/schema/';
43
  $vars['html_attributes_array']['lang'][] = $language->language;
44
  $vars['html_attributes_array']['dir'][] = $language->dir;
45

    
46
  // Convert RDF Namespaces into structured data using drupal_attributes.
47
  $vars['rdf_namespaces'] = array();
48
  if (function_exists('rdf_get_namespaces')) {
49
    foreach (rdf_get_namespaces() as $prefix => $uri) {
50
      $prefixes[] = $prefix . ': ' . $uri;
51
    }
52
    $vars['rdf_namespaces_array']['prefix'] = implode(' ', $prefixes);
53
  }
54

    
55
  // Get the path to the directory where our CSS files are saved
56
  $path = variable_get('theme_' . $theme_name . '_files_directory');
57

    
58
  // Load Layout
59
  at_load_layout_css($path, $theme_name);
60

    
61
  // Add layout settings as JS settings, we use this for responsive JS,
62
  // such as the Menu Toggle javascript.
63
  at_load_layout_js_settings($theme_name);
64

    
65
  // Load Responsive Styles.
66
  if (at_get_setting('disable_responsive_styles', $theme_name) === 0) {
67
    at_load_responsive_css($path, $theme_name);
68
  }
69

    
70
  // Load fonts and/or Custom CSS and the menu toggle files
71
  if (at_get_setting('enable_extensions', $theme_name) === 1) {
72
    // Fonts CSS
73
    if (at_get_setting('enable_font_settings', $theme_name) === 1) {
74
      at_load_fonts($path, $theme_name);
75
    }
76
    // Custom CSS
77
    if (at_get_setting('enable_custom_css', $theme_name) === 1) {
78
      at_load_custom_css($path, $theme_name);
79
    }
80
    // Load the menu toggle js and css files
81
    if (at_get_setting('enable_menu_toggle', $theme_name) === 1) {
82
      at_load_menu_toggle($path, $theme_name);
83
    }
84
    // Load Extension Settings CSS
85
    at_load_extensions_css($theme_name);
86
  }
87

    
88
  // Load conditional stylesheets declared in the info file
89
  if (isset($info['ie_stylesheets'])) {
90
    at_load_subtheme_conditional_styles($theme_name);
91
  }
92

    
93
  // Load specific subtheme scripts
94
  if (at_get_setting('load_onmediaqueryjs', $theme_name) === 1) {
95
    at_load_subtheme_script('scripts/media_queries.js', $theme_name, 'footer', '100');
96
  }
97

    
98
  // Load polyfills
99
  $vars['polyfills'] = at_load_polyfills($theme_name, $vars);
100

    
101
  // Set the skip navigation target ID
102
  $vars['skip_link_target'] = '#main-content';
103
  if (at_get_setting('skip_link_target', $theme_name)) {
104
    $skip_link_target = at_get_setting('skip_link_target', $theme_name);
105
    $vars['skip_link_target'] = check_plain($skip_link_target);
106
  }
107

    
108
  // Generate body classes
109
  if ($html_classes = at_generate_html_classes($vars, $theme_name)) {
110
    foreach ($html_classes as $class_name) {
111
      $vars['classes_array'][] = $class_name;
112
    }
113
  }
114

    
115
  // Do some legacy stuff for 7.x-2.x themes that have google webfonts running
116
  // on the old system. Scan for the existence of a "release" key and
117
  // conditionally load google.web.fonts.inc
118
  if (!isset($info['release']) || $info['release'] === '7.x-2.x') {
119
    include_once(drupal_get_path('theme', 'adaptivetheme') . '/inc/google.web.fonts.inc');
120
  }
121

    
122
  // Load debuggers if enabled.
123
  if (at_get_setting('expose_regions', $theme_name) === 1 || at_get_setting('show_window_size', $theme_name) === 1 || at_get_setting('load_all_panels', $theme_name) === 1) {
124
    at_load_debuggers($theme_name);
125
  }
126
}
127

    
128
/**
129
 * Preprocess variables for page.tpl.php
130
 */
131
function adaptivetheme_preprocess_page(&$vars) {
132
  global $theme_key;
133
  $theme_name = $theme_key;
134

    
135
  // Set up logo element
136
  if (at_get_setting('toggle_logo', $theme_name) === 1) {
137
    $vars['site_logo'] = &drupal_static('adaptivetheme_preprocess_page_site_logo');
138
    if (empty($vars['site_logo'])) {
139
      $logo_image_path = check_url($vars['logo']);
140
      $logo_image_alt = check_plain(variable_get('site_name', t('Home page')));
141
      $logo_image_vars = array('path' => $logo_image_path, 'alt' => $logo_image_alt, 'attributes' => array('class' => 'site-logo'));
142
      $vars['logo_img'] = theme('image', $logo_image_vars);
143
      if (at_get_setting('logo_title') == 1) {
144
        $vars['site_logo'] = $vars['logo_img'] ? l($vars['logo_img'], '<front>', array('attributes' => array('title' => $logo_image_alt), 'html' => TRUE)) : '';
145
      }
146
      else {
147
        $vars['site_logo'] = $vars['logo_img'] ? l($vars['logo_img'], '<front>', array('html' => TRUE)) : '';
148
      }
149
    }
150
    // Maintain backwards compatibility with 7.x-2.x sub-themes
151
    $vars['linked_site_logo'] = $vars['site_logo'];
152
  }
153
  else {
154
    $vars['site_logo'] = '';
155
    $vars['logo_img'] = '';
156
    $vars['linked_site_logo'] = '';
157
  }
158

    
159
  // Site name
160
  $vars['site_name'] = &drupal_static('adaptivetheme_preprocess_page_site_name');
161
  if (empty($vars['site_name'])) {
162
    $vars['site_name_title'] = variable_get('site_name', 'Drupal');
163
    $vars['site_name'] = l($vars['site_name_title'], '<front>', array('attributes' => array('title' => t('Home page'))));
164
    $vars['site_name_unlinked'] = $vars['site_name_title'];
165
  }
166

    
167
  // Site name visibility and other classes and variables
168
  $vars['site_name_attributes_array'] = array();
169
  $vars['visibility'] = '';
170
  $vars['hide_site_name'] = FALSE;
171
  if (at_get_setting('toggle_name', $theme_name) === 0) {
172
    // Keep the visibility variable to maintain backwards compatibility
173
    $vars['visibility'] = 'element-invisible';
174
    $vars['site_name_attributes_array']['class'][] = $vars['visibility'];
175
    $vars['hide_site_name'] = TRUE;
176
  }
177

    
178
  // Build a variable for the main menu
179
  if (isset($vars['main_menu'])) {
180
    $main_menu_title = at_get_setting('menu_button_link_text') ? at_get_setting('menu_button_link_text') : t('Main menu');
181
    $vars['primary_navigation'] = theme('links', array(
182
      'links' => $vars['main_menu'],
183
      'attributes' => array(
184
        'class' => array('menu', 'primary-menu', 'clearfix'),
185
       ),
186
      'heading' => array(
187
        'text'  => $main_menu_title,
188
        'level' => 'h2',
189
        'class' => array('element-invisible'),
190
        'id'    => array('primary-menu'),
191
      )
192
    ));
193
  }
194

    
195
  // Build a variable for the secondary menu
196
  if (isset($vars['secondary_menu'])) {
197
    $vars['secondary_navigation'] = theme('links', array(
198
      'links' => $vars['secondary_menu'],
199
      'attributes' => array(
200
        'class' => array('menu', 'secondary-menu', 'clearfix'),
201
      ),
202
      'heading' => array(
203
        'text'  => t('Secondary menu'),
204
        'level' => 'h2',
205
        'class' => array('element-invisible'),
206
        'id'    => 'secondary-menu',
207
      )
208
    ));
209
  }
210

    
211
  // Build variables for Primary and Secondary local tasks
212
  $vars['primary_local_tasks'] = menu_primary_local_tasks();
213
  $vars['secondary_local_tasks'] = menu_secondary_local_tasks();
214

    
215
  // Add back the $search_box var to D7
216
  if (module_exists('search')) {
217
    $search_box = drupal_get_form('search_form');
218
    $vars['search_box'] = '<div id="search-box" role="search">' . drupal_render($search_box) . '</div>';
219
  }
220

    
221
  // Process enabled Extensions
222
  if (at_get_setting('enable_extensions', $theme_name) === 1) {
223
    // Generate page classes, in AT Core these are all Extensions
224
    if ($page_classes = at_generate_page_classes($vars, $theme_name)) {
225
      foreach ($page_classes as $class_name) {
226
        $vars['classes_array'][] = $class_name;
227
      }
228
    }
229
    // Process modify markup settings
230
    if (at_get_setting('enable_markup_overides', $theme_name) === 1) {
231
      // Remove the infernal feed icons
232
      if (at_get_setting('feed_icons_hide', $theme_name) === 1) {
233
        $vars['feed_icons'] = '';
234
      }
235
    }
236
  }
237

    
238
  // Strip stupid contextual-links-region class.
239
  //$vars['classes_array'] = array_values(array_diff($vars['classes_array'], array('contextual-links-region')));
240

    
241
  // page attributes
242
  $vars['page_attributes_array']['id'][] = 'page';
243
  $vars['page_attributes_array']['class'] = $vars['classes_array'];
244

    
245
  // header attributes
246
  $vars['header_attributes_array']['id'][] = 'header';
247
  $vars['header_attributes_array']['class'][] = 'clearfix';
248
  $vars['header_attributes_array']['role'][] = 'banner';
249

    
250
  // branding attributes
251
  $vars['branding_attributes_array']['id'][] = 'branding';
252
  $vars['branding_attributes_array']['class'][] = 'branding-elements';
253
  $vars['branding_attributes_array']['class'][] = 'clearfix';
254

    
255
  // site name and slogan attributes (wrapper div)
256
  // hgroup maintains BC layer for pre 7.x-3.2 themes
257
  $vars['hgroup_attributes_array'] = array();
258
  if (!$vars['site_slogan'] && $vars['hide_site_name']) {
259
    $vars['hgroup_attributes_array']['class'][] = $vars['visibility'];
260
  }
261
  $vars['hgroup_attributes_array']['class'][] = 'h-group';
262
  $vars['hgroup_attributes_array']['id'][] = 'name-and-slogan';
263

    
264
  // site name attributes
265
  $vars['site_name_attributes_array']['id'][] = 'site-name';
266

    
267
  // site slogan attributes
268
  $vars['site_slogan_attributes_array']['id'][] = 'site-slogan';
269

    
270
  // main content header attributes
271
  $vars['content_header_attributes_array']['id'][] = 'main-content-header';
272
  $vars['content_header_attributes_array']['class'][] = 'clearfix';
273

    
274
  // footer attributes
275
  $vars['footer_attributes_array']['id'][] = 'footer';
276
  $vars['footer_attributes_array']['class'][] = 'clearfix';
277
  $vars['footer_attributes_array']['role'][] = 'contentinfo';
278

    
279
  // Attribution variable used in admin theme and some others
280
  $vars['attribution'] = '';
281
  if (at_get_setting('attribution_toggle', $theme_name) === 1) {
282
    $vars['attribution'] = "<small class=\"attribution\">Premium Drupal Theme by <a href=\"http://adaptivethemes.com\">Adaptivethemes.com</a></small>";
283
  }
284

    
285
  // Work around a perculier bug/feature(?) in Drupal 7 which incorrectly sets
286
  // the page title to "User account" for all three of these pages.
287
  $title = drupal_get_title();
288
  if (arg(0) === 'user' && $title == t('User account')) {
289
    if (arg(1) === 'login' || arg(1) == '') {
290
      drupal_set_title(t('User login'));
291
    }
292
    if (arg(1) === 'password') {
293
      drupal_set_title(t('Request new password'));
294
    }
295
    if (arg(1) === 'register') {
296
      drupal_set_title(t('Create new account'));
297
    }
298
  }
299
}
300

    
301
/**
302
 * Preprocess variables for region.tpl.php
303
 */
304
function adaptivetheme_preprocess_region(&$vars) {
305
  global $theme_key;
306
  $theme_name = $theme_key;
307

    
308
  $region = $vars['region'];
309

    
310
  // Add a "sidebar" class to sidebar regions
311
  if (strpos($region, 'sidebar_') === 0) {
312
    $vars['classes_array'][] = 'sidebar';
313
    // Allow a region-specific template to override the region--sidebar suggestion.
314
    array_unshift($vars['theme_hook_suggestions'], 'region__sidebar');
315
  }
316

    
317
  // Float region block classes
318
  if (at_get_setting('enable_extensions', $theme_name) === 1) {
319
    if (at_get_setting('enable_float_region_blocks', $theme_name) === 1) {
320

    
321
      // Make sure there is something set for the region, get the column count
322
      if ($float_blocks_regions_class = at_get_setting('float_block_' . $region)) {
323

    
324
        // Do nothing if its <none>
325
        if ($float_blocks_regions_class !== '<none>') {
326

    
327
          // Set a class for the number of columns selected, default to nothing
328
          $float_blocks_regions_class = isset($float_blocks_regions_class) ? check_plain($float_blocks_regions_class) : '';
329
          $vars['classes_array'][] = 'float-blocks-' . $float_blocks_regions_class;
330

    
331
          // Add the float direction class, default to left if the setting fails
332
          if ($float_block_direction_class = at_get_setting('float_block_direction_' . $region)) {
333
            $float_block_direction_class = isset($float_block_direction_class) ? check_plain($float_block_direction_class) : 'left';
334
            $vars['classes_array'][] = 'float-blocks-' . $float_block_direction_class;
335
          }
336
        }
337
      }
338
    }
339
  }
340

    
341
  // Add classes to conditional stack regions in Gpanel regions, in the Panels
342
  // layout plugins these are hard coded.
343
  $conditional_stack_regions = &drupal_static(__FUNCTION__, array());
344
  if (empty($conditional_stack_regions)) {
345
    $conditional_stack_regions = array(
346
      'three_25_25_50_top',
347
      'three_25_25_50_bottom',
348
      'three_25_50_25_top',
349
      'three_25_50_25_bottom',
350
      'three_50_25_25_top',
351
      'three_50_25_25_bottom',
352
      'three_33_top',
353
      'three_33_bottom',
354
      'two_50_top',
355
      'two_50_bottom',
356
      'two_33_66_top',
357
      'two_33_66_bottom',
358
      'two_66_33_top',
359
      'two_66_33_bottom',
360
      'two_brick_top',
361
      'two_brick_middle',
362
      'two_brick_bottom',
363
      'threecol_inset_left_top',
364
      'threecol_inset_left_bottom',
365
      'threecol_inset_right_top',
366
      'threecol_inset_right_bottom',
367
    );
368
  }
369
  if (in_array($region, $conditional_stack_regions)) {
370
    $vars['classes_array'][] = 'region-conditional-stack';
371
  }
372
}
373

    
374
/**
375
 * Preprocess variables for block.tpl.php
376
 */
377
function adaptivetheme_preprocess_block(&$vars) {
378
  global $theme_key;
379
  global $user;
380
  $theme_name = $theme_key;
381

    
382
  // Block subject, under certain conditions, is not set
383
  $vars['tag'] = 'div';
384
  $vars['title'] = '';
385

    
386
  if (isset($vars['block']->subject)) {
387
    if (!empty($vars['block']->subject)) {
388
      // Generate the wrapper element, if there's a title use section
389
      $vars['tag'] = 'section';
390

    
391
      // Use a $title variable instead of $block->subject
392
      $vars['title'] = $vars['block']->subject;
393
    }
394
    // subject can be set and empty, i.e. using <none>
395
    else {
396
      $vars['classes_array'][] = 'no-title';
397
    }
398
  }
399
  // sometimes subject is not set at all
400
  else {
401
    $vars['classes_array'][] = 'no-title';
402
  }
403

    
404
  // Search is never a section, its just a div
405
  if ($vars['block_html_id'] === 'block-search-form') {
406
    $vars['tag'] = 'div';
407
  }
408

    
409
  // Block inner attributes
410
  $vars['block_inner_attributes_array']['class'][] = 'block-inner';
411
  $vars['block_inner_attributes_array']['class'][] = 'clearfix';
412

    
413
  // Use nav element for menu blocks and provide a suggestion for all of them
414
  $nav_blocks = array('navigation', 'main-menu', 'management', 'user-menu');
415
  if (in_array($vars['block']->delta, $nav_blocks)) {
416
    $vars['tag'] = 'nav';
417
    array_unshift($vars['theme_hook_suggestions'], 'block__menu');
418
  }
419

    
420
  $nav_modules = array('superfish', 'nice_menus', 'menu_block', 'menu');
421
  if (in_array($vars['block']->module, $nav_modules)) {
422
    $vars['tag'] = 'nav';
423
    array_unshift($vars['theme_hook_suggestions'], 'block__menu');
424
  }
425

    
426
  // The menu bar region gets special treatment for the block template
427
  if ($vars['block']->region === 'menu_bar') {
428
    $vars['classes_array'][] = 'menu-wrapper';
429
    $vars['classes_array'][] = 'menu-bar-wrapper';
430
    $vars['classes_array'][] = 'clearfix';
431
    $vars['title_attributes_array']['class'][] = 'element-invisible';
432
  }
433

    
434
  // The menu bar region gets special treatment for the block template
435
  if (at_get_setting('enable_menu_toggle', $theme_name) === 1) {
436
    if (at_get_setting('menu_toggle_menu_bar', $theme_name) === 1) {
437
      if ($vars['block']->region === 'menu_bar') {
438
        $vars['classes_array'][] = 'at-menu-toggle';
439
      }
440
    }
441
    if (at_get_setting('menu_toggle_leaderboard', $theme_name) === 1 && $vars['block']->region === 'leaderboard') {
442
      $vars['classes_array'][] = 'at-menu-toggle';
443
      $vars['classes_array'][] = 'clearfix';
444
    }
445
    if (at_get_setting('menu_toggle_header', $theme_name) === 1 && $vars['block']->region === 'header') {
446
      $vars['classes_array'][] = 'at-menu-toggle';
447
      $vars['classes_array'][] = 'clearfix';
448
    }
449
  }
450

    
451
  // Add extra classes if required
452
  if (at_get_setting('extra_block_classes', $theme_name) === 1) {
453

    
454
    // Zebra
455
    $vars['classes_array'][] = $vars['block_zebra'];
456

    
457
    // Position?
458
    if ($vars['block_id'] === 1) {
459
      $vars['classes_array'][] = 'first';
460
    }
461
    if (isset($vars['block']->last_in_region)) {
462
      $vars['classes_array'][] = 'last';
463
    }
464

    
465
    // Count
466
    $vars['classes_array'][] = 'block-count-' . $vars['id'];
467

    
468
    // Region
469
    $vars['classes_array'][] = drupal_html_class('block-region-' . $vars['block']->region);
470

    
471
    // Delta
472
    $vars['classes_array'][] = drupal_html_class('block-' . $vars['block']->delta);
473
  }
474

    
475
  // Add classes to theme the horizontal block option
476
  if (at_get_setting('enable_extensions', $theme_name) === 1) {
477
    if (at_get_setting('enable_markup_overides', $theme_name) === 1) {
478
      // Change the user menu title to the user name.
479
      if (at_get_setting('user_block_user_name', $theme_name) === 1) {
480
        if ($vars['block']->module == 'system' && $vars['block']->delta == 'user-menu') {
481
          if (user_is_logged_in()) {
482
            $vars['title'] = check_plain($user->name);
483
          }
484
        }
485
      }
486
      // Horizontal block classes.
487
      if (at_get_setting('horizontal_login_block', $theme_name) === 1 && $vars['block']->module === 'user' && $vars['block']->delta === 'login') {
488
        $vars['classes_array'][] = 'lb-h';
489
        $vars['title_attributes_array']['class'][] = 'element-invisible';
490
      }
491
      if (at_get_setting('slider_login_block', $theme_name) === 1 && $vars['block']->module === 'user' && $vars['block']->delta === 'login') {
492
        $vars['classes_array'][] = 'lb-s';
493
      }
494
    }
495
  }
496

    
497
  // Give our block titles and content some additional class
498
  $vars['title_attributes_array']['class'][] = 'block-title';
499
  $vars['content_attributes_array']['class'] = array('block-content', 'content');
500

    
501
  // Support aria-describedby
502
  if ($vars['block']->subject && !empty($vars['attributes_array']['role'])) {
503
    $vars['title_attributes_array']['id'] = drupal_html_id($vars['block']->subject);
504
    $vars['attributes_array']['aria-describedby'] = $vars['title_attributes_array']['id'];
505
  }
506

    
507
  // Add Aria Roles via attributes
508
  switch ($vars['block']->module) {
509
    case 'system':
510
      switch ($vars['block']->delta) {
511
        case 'main':
512
          // Note: the "main" role goes in the page.tpl, not here.
513
          break;
514
        case 'help':
515
        case 'powered-by':
516
          $vars['attributes_array']['role'] = 'complementary';
517
          break;
518
        default:
519
          // Any other "system" block is a menu block.
520
          $vars['attributes_array']['role'] = 'navigation';
521
          break;
522
      }
523
      break;
524
    case 'menu':
525
    case 'menu_block':
526
    case 'blog':
527
    case 'book':
528
    case 'comment':
529
    case 'forum':
530
    case 'shortcut':
531
    case 'statistics':
532
      $vars['attributes_array']['role'] = 'navigation';
533
      break;
534
    case 'search':
535
      $vars['attributes_array']['role'] = 'search';
536
      break;
537
    case 'help':
538
    case 'aggregator':
539
    case 'locale':
540
    case 'poll':
541
    case 'profile':
542
      $vars['attributes_array']['role'] = 'complementary';
543
      break;
544
    case 'node':
545
      switch ($vars['block']->delta) {
546
        case 'syndicate':
547
          $vars['attributes_array']['role'] = 'complementary';
548
          break;
549
        case 'recent':
550
          $vars['attributes_array']['role'] = 'navigation';
551
          break;
552
      }
553
      break;
554
    case 'user':
555
      switch ($vars['block']->delta) {
556
        case 'login':
557
          $vars['attributes_array']['role'] = 'form';
558
          break;
559
        case 'new':
560
        case 'online':
561
          $vars['attributes_array']['role'] = 'complementary';
562
          break;
563
      }
564
      break;
565
  }
566
}
567

    
568
/**
569
 * Preprocess variables for panels_pane.tpl.php
570
 */
571
function adaptivetheme_preprocess_panels_pane(&$vars) {
572
  // Top level wrapper
573
  $vars['tag'] = $vars['title'] ? 'section' : 'div';
574

    
575
  // Add the same classes as blocks
576
  if (empty($vars['title'])) {
577
    $vars['classes_array'][] = 'no-title';
578
  }
579
  $vars['classes_array'][] = 'block';
580

    
581
  // Use the attributes arrays to add classes.
582
  $vars['title_attributes_array']['class'][] = 'block-title';
583
  $vars['attributes_array']['class'] = $vars['classes_array'];
584
  $vars['content_attributes_array']['class'][] = 'block-content';
585
}
586

    
587
/**
588
 * Preprocess variables for field.tpl.php
589
 */
590
function adaptivetheme_preprocess_field(&$vars) {
591
  global $theme_key;
592
  $theme_name = $theme_key;
593

    
594
  $element = $vars['element'];
595

    
596
 // Set the top level element as either <section> (if the field label is showing),
597
 // or <div> if the field label is hidden.
598
  $vars['tag'] = 'section';
599
  if (isset($vars['label_hidden']) && $vars['label_hidden'] == TRUE) {
600
    $vars['tag'] = 'div';
601
  }
602

    
603
  $vars['field_view_mode'] = '';
604
  if (isset($element['#view_mode'])) {
605
    // add a view mode class to fields
606
    $vars['classes_array'][] = 'view-mode-' . $element['#view_mode'];
607
    // Set variable for view mode, appears to be not gettable in a template
608
    $vars['field_view_mode'] = $element['#view_mode'];
609
  }
610

    
611
  // Image fields
612
  if ($element['#field_type'] === 'image') {
613

    
614
    // Set some vars for image captioning, these always need to be initialized
615
    $vars['image_caption_teaser'] = FALSE;
616
    $vars['image_caption_full'] = FALSE;
617

    
618
    // Dont run anything if extensions or image settings are disabled
619
    if (at_get_setting('enable_extensions', $theme_name) === 1) {
620
      if (at_get_setting('enable_image_settings', $theme_name) === 1) {
621

    
622
        // Reduce number of images in teaser view mode to single image
623
        if (at_get_setting('image_teaser', $theme_name) === 1) {
624
          if ($element['#view_mode'] == 'teaser') {
625
            $item = reset($vars['items']);
626
            $vars['items'] = array($item);
627
          }
628
        }
629

    
630
        // Captions
631
        if (at_get_setting('image_caption_teaser', $theme_name) === 1) {
632
          $vars['image_caption_teaser'] = TRUE;
633
        }
634
        if (at_get_setting('image_caption_full', $theme_name) === 1) {
635
          $vars['image_caption_full'] = TRUE;
636
        }
637
      }
638
    }
639
  }
640
}
641

    
642
/**
643
 * Preprocess variables for node.tpl.php
644
 */
645
function adaptivetheme_preprocess_node(&$vars) {
646
  global $theme_key;
647
  $theme_name = $theme_key;
648

    
649
  // article class to attempt backwards compatibility
650
  $vars['classes_array'][] = 'article';
651

    
652
  // Extra classes if required
653
  if (at_get_setting('extra_article_classes', $theme_name) === 1) {
654

    
655
    // Zebra
656
    $vars['classes_array'][] = $vars['zebra'];
657

    
658
    // Langauge
659
    if (module_exists('translation')) {
660
      if ($vars['node']->language) {
661
        $vars['classes_array'][] = 'node-lang-' . $vars['node']->language;
662
      }
663
    }
664

    
665
    // User picture?
666
    // Should we all a check for the global settings here? SEE: https://drupal.org/node/2020687
667
    if (at_get_setting('toggle_node_user_picture', $theme_name) === 1) {
668
      if ($vars['display_submitted'] && !empty($vars['picture'])) {
669
        $vars['classes_array'][] = 'node-with-picture';
670
      }
671
    }
672

    
673
    // Class for each view mode, core assumes we only need to target teasers but neglects custom view modes or full
674
    if ($vars['view_mode'] !== 'teaser') {
675
      $vars['classes_array'][] = drupal_html_class('node-' . $vars['view_mode']);
676
    }
677
  }
678

    
679
  // Image alignment and caption classes
680
  if (at_get_setting('enable_extensions', $theme_name) === 1) {
681
    if (at_get_setting('enable_image_settings', $theme_name) === 1) {
682
      if ($vars['view_mode'] !== 'teaser') {
683
        if ($image_caption_full = at_get_setting('image_caption_full', $theme_name)) {
684
          $vars['classes_array'][] = $image_caption_full;
685
        }
686
        if ($image_alignment = at_get_setting('image_alignment', $theme_name)) {
687
          $vars['classes_array'][] = $image_alignment;
688
        }
689
      }
690
      if ($vars['view_mode'] == 'teaser') {
691
        if ($image_caption_teaser = at_get_setting('image_caption_teaser', $theme_name)) {
692
          $vars['classes_array'][] = $image_caption_teaser;
693
        }
694
        if ($image_alignment_teaser = at_get_setting('image_alignment_teaser', $theme_name)) {
695
          $vars['classes_array'][] = $image_alignment_teaser;
696
        }
697
      }
698
    }
699
  }
700

    
701
  // ARIA Role
702
  $vars['attributes_array']['role'][] = 'article';
703

    
704
  // Classes and attributes
705
  $vars['title_attributes_array']['class'][] = 'node-title';
706
  $vars['content_attributes_array']['class'][] = 'node-content';
707

    
708
  // header, submitted and links wrappers have their own attributes
709
  $vars['header_attributes_array']['class'][] = 'node-header';
710
  $vars['footer_attributes_array']['class'][] = 'submitted';
711
  if ($vars['user_picture']) {
712
    $vars['footer_attributes_array']['class'][] = 'with-user-picture';
713
  }
714
  $vars['links_attributes_array']['class'][] = 'clearfix';
715

    
716
  //
717
  // AT Core builds additional time and date variables for use in templates
718
  //
719
  // datetime stamp formatted correctly to ISO8601
720
  $vars['datetime'] = format_date($vars['created'], 'custom', 'Y-m-d\TH:i:sO'); // PHP 'c' format is not proper ISO8601!
721

    
722
  // Publication date, formatted with time element
723
  $vars['publication_date'] = '<time datetime="' . $vars['datetime'] . '" pubdate="pubdate">' . $vars['date'] . '</time>';
724

    
725
  // Last update variables
726
  $vars['datetime_updated'] = format_date($vars['node']->changed, 'custom', 'Y-m-d\TH:i:sO');
727
  $vars['custom_date_and_time'] = date('jS F, Y - g:ia', $vars['node']->changed);
728

    
729
  // Last updated formatted in time element
730
  $vars['last_update'] = '<time datetime="' . $vars['datetime_updated'] . '" pubdate="pubdate">' . $vars['custom_date_and_time'] . '</time>';
731

    
732
  // Build the submitted variable used by default in node templates
733
  if (variable_get('node_submitted_' . $vars['node']->type, TRUE)) {
734
    $vars['submitted'] = t('Submitted by !username on !datetime',
735
      array(
736
        '!username' => $vars['name'],
737
        '!datetime' => $vars['publication_date'],
738
      )
739
    );
740
  }
741
  else {
742
    $vars['submitted'] = '';
743
  }
744

    
745
  // Unpublished?
746
  $vars['unpublished'] = ''; // Initialize for backwards compatibility
747
  if (!$vars['status']) {
748
    // Use the title prefix to render the unpublished message
749
    $vars['title_prefix']['unpublished']['#markup'] = '<p class="unpublished">' . t('Unpublished') . '</p>';
750
  }
751

    
752
  // Add nofollow to Book module print/export links
753
  if (isset($vars['content']['links']['book']['#links']['book_printer'])) {
754
    $vars['content']['links']['book']['#links']['book_printer']['attributes'] = array('rel' => array('nofollow'));
755
  }
756
}
757

    
758
/**
759
 * Preprocess variables for comment.tpl.php
760
 */
761
function adaptivetheme_preprocess_comment(&$vars) {
762
  global $theme_key;
763
  $theme_name = $theme_key;
764

    
765
  // Extra comment classes if required
766
  if (at_get_setting('extra_comment_classes', $theme_name) === 1) {
767

    
768
    // Zebra
769
    $vars['classes_array'][] = $vars['zebra'];
770

    
771
    // Position?
772
    if ($vars['id'] === 1) {
773
      $vars['classes_array'][] = 'first';
774
    }
775
    if ($vars['id'] === $vars['node']->comment_count) {
776
      $vars['classes_array'][] = 'last';
777
    }
778

    
779
    // Title hidden?
780
    if (at_get_setting('comments_hide_title', $theme_name) === 1) {
781
      $vars['classes_array'][] = 'comment-title-hidden';
782
    }
783

    
784
    // User picture?
785
    // Should we add a check for the global settings here? SEE: https://drupal.org/node/2020687
786
    if (at_get_setting('toggle_comment_user_picture', $theme_name) === 1) {
787
      if (!empty($vars['picture'])) {
788
        $vars['classes_array'][] = 'comment-with-picture';
789
      }
790
    }
791

    
792
    // Signature?
793
    if (!empty($vars['signature'])) {
794
      $vars['classes_array'][] = 'comment-with-signature';
795
    }
796
  }
797

    
798
  // Classes for comment title
799
  $vars['title_attributes_array']['class'][] = 'comment-title';
800

    
801
  // Title hidden?
802
  if (at_get_setting('enable_extensions', $theme_name) === 1) {
803
    if (at_get_setting('enable_markup_overides', $theme_name) === 1) {
804
      if (at_get_setting('comments_hide_title', $theme_name) === 1) {
805
        $vars['title_attributes_array']['class'][] = 'element-invisible';
806
      }
807
    }
808
  }
809

    
810
  // Classes for comment content
811
  $vars['content_attributes_array']['class'][] = 'comment-content';
812

    
813
  // header, submitted and links wrappers have their own attributes
814
  $vars['header_attributes_array']['class'][] = 'comment-header';
815
  $vars['footer_attributes_array']['class'][] = 'submitted';
816
  if ($vars['picture']) {
817
    $vars['footer_attributes_array']['class'][] = 'with-user-picture';
818
  }
819
  $vars['links_attributes_array']['class'][] = 'clearfix';
820

    
821
  // Build the submitted by, permalink, title and time elements
822
  $uri = entity_uri('comment', $vars['comment']);
823
  $uri['options'] += array('attributes' => array('rel' => 'bookmark'));
824
  $vars['title'] = l($vars['comment']->subject, $uri['path'], $uri['options']);
825

    
826
  // Don't rebuild the permalink variable if Advanced Forum is enabled
827
  if (!module_exists('advanced_forum')) {
828
    $vars['permalink'] = l(t('Permalink'), $uri['path'], $uri['options']);
829
  }
830

    
831
  $vars['created'] = '<span class="date-time">' . $vars['created'] . '</span>';
832

    
833
  $vars['datetime'] = format_date($vars['comment']->created, 'custom', 'Y-m-d\TH:i:s\Z'); // Generate the timestamp, PHP "c" format is wrong
834

    
835
  $vars['submitted'] = t('Submitted by !username on !datetime',
836
    array(
837
      '!username' => $vars['author'],
838
      '!datetime' => '<time datetime="' . $vars['datetime'] . '" pubdate="pubdate">' . $vars['created'] . '</time>',
839
    )
840
  );
841

    
842
  // Unpublished?
843
  $vars['unpublished'] = ''; // Initialize for backwards compatibility
844
  if ($vars['status'] === 'comment-unpublished') {
845
    // Use the title prefix to render the unpublished message
846
    $vars['title_prefix']['unpublished']['#markup'] = '<p class="unpublished">' . t('Unpublished') . '</p>';
847
  }
848
}
849

    
850
/**
851
 * Preprocess variables for the search block form.
852
 */
853
function adaptivetheme_preprocess_search_block_form(&$vars) {
854
  // Changes the search form to use the "search" input element attribute (HTML5)
855
  // We have to replace the string because FAPI don't know what type=search is, i.e.
856
  // no way we can do this in a form alter hook.
857
  $vars['search_form'] = str_replace('type="text"', 'type="search"', $vars['search_form']);
858
}
859

    
860
/**
861
 * Preprocess variables for aggregator-item.tpl.php
862
 */
863
function adaptivetheme_preprocess_aggregator_item(&$vars) {
864
  $item = $vars['item'];
865
  // We want the same highly accurate time stamp feature as nodes and comments
866
  $vars['datetime'] = format_date($item->timestamp, 'custom', 'Y-m-d\TH:i:sO');
867
  // Give our aggregator items some class
868
  $vars['classes_array'][] = 'feed-item clearfix';
869
  $vars['title_attributes_array']['class'][] = 'title feed-item-title';
870
  $vars['content_attributes_array']['class'][] = 'content feed-item-content';
871
}
872

    
873
/**
874
 * Preprocess variables for adaptivtheme_menubar()
875
 */
876
function adaptivetheme_preprocess_menubar(&$vars) {
877
  global $theme_key;
878
  $theme_name = $theme_key;
879
  $type = $vars['type'];
880

    
881
  // menu bar id
882
  $vars['menubar_id'] = $type . '-menu-bar';
883
  // Add classes to the main wrapper
884
  $vars['classes_array'] = array('nav', 'clearfix');
885

    
886
  // Classes for toggle menus
887
  if (at_get_setting('enable_menu_toggle', $theme_name) === 1) {
888
    if (at_get_setting('menu_toggle_main_menu', $theme_name) === 1 && $type === 'primary') {
889
      $vars['classes_array'][] = 'at-menu-toggle';
890
    }
891
    if (at_get_setting('menu_toggle_secondary_menu', $theme_name) === 1 && $type === 'secondary') {
892
      $vars['classes_array'][] = 'at-menu-toggle';
893
    }
894
  }
895

    
896
  // Add classes to the inner wrapper
897
  $vars['content_attributes_array']['class'][] = $type . '-menu-wrapper';
898
  $vars['content_attributes_array']['class'][] = 'menu-wrapper';
899
  $vars['content_attributes_array']['class'][] = 'clearfix';
900
  // Aria
901
  $vars['content_attributes_array']['role'][] = 'navigation';
902
  $vars['content_attributes_array']['aria-labelledby'][] = $type . '-menu';
903

    
904
  // Add suggstions per menu type
905
  $vars['theme_hook_suggestions'][] = 'menubar__' . $type;
906
}
907

    
908
/**
909
 * Preprocess variables for the username.
910
 */
911
function adaptivetheme_preprocess_username(&$vars) {
912
  global $theme_key;
913
  $theme_name = $theme_key;
914
  // Add rel=author for SEO and supporting search engines
915
  if (at_get_setting('enable_extensions', $theme_name) === 1) {
916
    if (at_get_setting('enable_markup_overides', $theme_name) === 1) {
917
      if (at_get_setting('rel_author', $theme_name) === 1) {
918
        if (isset($vars['link_path'])) {
919
          $vars['link_attributes']['rel'][] = 'author';
920
        }
921
        else {
922
          $vars['attributes_array']['rel'][] = 'author';
923
        }
924
      }
925
    }
926
  }
927
}
928

    
929
/**
930
 * Preprocess variables for theme_image()
931
 */
932
function adaptivetheme_preprocess_image(&$vars) {
933

    
934
  // Initialize the variable if there isn't one
935
  if (!isset($vars['attributes']['class'])) {
936
    $vars['attributes']['class'] = array();
937
  }
938

    
939
  // Some modules set the style name even when its empty, such as User Badges
940
  // module, so initialize the class name variable with a "none" class
941
  $style_name_class = 'none';
942

    
943
  // If there really is a style name use it for the class
944
  if (isset($vars['style_name']) && !empty($vars['style_name'])) {
945
    $style_name_class = drupal_html_class($vars['style_name']);
946
  }
947

    
948
  // Check if the class attributes is an array. If we don't do this check and
949
  // the class attribute is string it can cause a fatal error.
950
  // See http://drupal.org/node/1722146 for an example
951
  if (is_array($vars['attributes']['class'])) {
952
    $vars['attributes']['class'][] = 'image-style-' . $style_name_class;
953
  }
954
}
955

    
956
/**
957
 * Preprocess variables for maintenance-page.tpl.php
958
 */
959
function adaptivetheme_preprocess_maintenance_page(&$vars) {
960
  global $theme_key;
961
  $theme_name = $theme_key;
962

    
963
  // Get the path to the directory where our CSS files are saved
964
  $path = variable_get('theme_' . $theme_name . '_files_directory');
965

    
966
  // Load Layout
967
  at_load_layout_css($path, $theme_name);
968

    
969
  // Load Responsive Styles.
970
  if (at_get_setting('disable_responsive_styles', $theme_name) === 0) {
971
    at_load_responsive_css($path, $theme_name);
972
  }
973

    
974
  // Load fonts and/or Custom CSS
975
  if (at_get_setting('enable_extensions', $theme_name) === 1) {
976
    // Fonts CSS
977
    if (at_get_setting('enable_font_settings', $theme_name) === 1) {
978
      at_load_fonts($path, $theme_name);
979
    }
980
    // Custom CSS
981
    if (at_get_setting('enable_custom_css', $theme_name) === 1) {
982
      at_load_custom_css($path, $theme_name);
983
    }
984
    // Load Extension Settings CSS
985
    at_load_extensions_css($theme_name);
986
  }
987

    
988
  // Load polyfills
989
  $vars['polyfills'] = at_load_polyfills($theme_name, $vars);
990

    
991
  // Load the colors stylesheet for the active color scheme. This only works
992
  // for maintenance mode, when there is a database error the default color
993
  // scheme will be used.
994
  if (module_exists('color')) {
995
    $color_file = variable_get('color_' . $theme_name . '_stylesheets', NULL);
996
    if (file_exists($color_file[0])) {
997
      drupal_add_css($color_file[0], array(
998
        'group' => CSS_THEME,
999
        'weight' => 99,
1000
        )
1001
      );
1002
    }
1003
  }
1004

    
1005
  // Attribution variable used in admin theme and some others
1006
  $vars['attribution'] = '';
1007
  if (at_get_setting('attribution_toggle', $theme_name) === 1) {
1008
    $vars['attribution'] = "<small class=\"attribution\">Premium Drupal Theme by <a href=\"http://adaptivethemes.com\">Adaptivethemes.com</a></small>";
1009
  }
1010
}
1011

    
1012
/**
1013
 * Preprocess variables for user-profile.tpl.php
1014
 */
1015
function adaptivetheme_preprocess_user_profile(&$vars) {
1016
  $vars['classes_array'][] = 'profile';
1017
}
1018

    
1019
/**
1020
 * Preprocess variables for breadcrumbs
1021
 */
1022
function adaptivetheme_preprocess_breadcrumb(&$vars) {
1023
  // Add Google rich snippets to breadcrumbs using RDFa
1024
  if (module_exists('rdf')) {
1025
    $snippet_url = ' rel="v:url" ';
1026
    $snippet_title = ' property="v:title" ';
1027
    foreach ($vars['breadcrumb'] as $key => $breadcrumb) {
1028
      preg_match_all('/<([\w]+)[^>]*>.*?<\/\\1>/', $breadcrumb, $matches);
1029
      if (count($matches[0]) > 0) {
1030
        $snippet = $snippet_title;
1031
        if ($matches[1][count($matches[1]) - 1] == 'a') {
1032
          $snippet = $snippet_url . $snippet_title;
1033
        }
1034
        $breadcrumb = substr_replace($breadcrumb, $snippet, strlen($matches[1][count($matches[1]) - 1]) + 1, 0);
1035
      }
1036
      else {
1037
        $breadcrumb = '<span ' . $snippet_title . '>' . $breadcrumb . '</span>';
1038
      }
1039
      $vars['breadcrumb'][$key] = '<span typeof="v:Breadcrumb">' . $breadcrumb . '</span>';
1040
    }
1041
  }
1042
}