Projet

Général

Profil

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

root / drupal7 / sites / all / themes / mayo / template.php @ e4215af7

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains theme override functions and preprocess functions
6
 */
7

    
8
/**
9
 * Includes for MAYO css creation form settings.
10
 */
11
global $theme_key, $path_to_mayo;
12
$theme_key = $GLOBALS['theme_key'];
13
$path_to_mayo = drupal_get_path('theme', 'mayo');
14
include_once($path_to_mayo . '/inc/load.inc');       // drupal_add_css() wrappers
15
include_once($path_to_mayo . '/inc/get.inc');        // get theme info, settings, css etc
16

    
17
/**
18
 * Construct HTML code for the top/bottom block columns
19
 */
20
function mayo_build_columns($columns) {
21
  $styles = array();
22
  $num_columns = 0;
23
  $first = -1;
24

    
25
  for ($i = 0 ; $i < 4 ; $i++) {
26
    if ($columns[$i]) {
27
      if ($first == -1) $first = $i;
28
      $last = $i;
29
      $num_columns++;
30
    }
31
  }
32
  if (!$num_columns) return '';
33

    
34
  $out = '';
35
  $out .= '<div class="column-blocks clearfix">';
36

    
37
  $column_width = round(100 / $num_columns, 2) . '%';  // calculate percent width of a column
38

    
39
  for ($i = 0 ; $i < 4 ; $i++) {
40
    if ($columns[$i]) {
41
      if ($i == $first) {
42
        $margin_left_style = 'margin-left: 0px;';
43
      }
44
      else {
45
        $margin_left_style = 'margin-left: 5px;';
46
      }
47
      if ($i == $last) {
48
        $margin_right_style = 'margin-right: 0px;';
49
      }
50
      else {
51
        $margin_right_style = 'margin-right: 5px;';
52
      }
53
      $style = $margin_left_style . $margin_right_style;
54

    
55
      $out .= '<div class="column-block-wrapper" style="width: ' . $column_width . ';">';
56
      $out .= '<div class="column-block" style="' . $style . '">';
57
      $out .= render($columns[$i]);
58
      $out .= '</div></div> <!--/.column-block --><!--/.column-block-wrapper-->';
59
    }
60
  }
61
  $out .= '</div> <!--/.column-blocks-->';
62
  $out .= '<div class="spacer clearfix cfie"></div>';
63
  return $out;
64
}
65

    
66
/**
67
 * Implements theme_breadcrumb().
68
 *
69
 * Return themed breadcrumb links.
70
 *
71
 * @param array $variables
72
 *   An array containing the breadcrumb links.
73
 *
74
 * @return string
75
 *   A string containing the breadcrumb output.
76
  */
77
function mayo_breadcrumb($variables) {
78
  $breadcrumb = $variables['breadcrumb'];
79

    
80
  // Remove 'Home' and add trailing seperator.
81
  if (theme_get_setting('homeless_breadcrumb') == 1) {
82
    if (is_array($breadcrumb)) {
83
      array_shift($breadcrumb);
84
    }
85
    if (!empty($breadcrumb)) {
86
      $breadcrumb_separator = ' > ';
87
      $breadcrumb_str = implode($breadcrumb_separator, $breadcrumb);
88
      $breadcrumb_str .= $breadcrumb_separator;
89
      $out = '<div class="breadcrumb">' . $breadcrumb_str . '</div>';
90
      return $out;
91
    }
92
  }
93
  // Bartik style breadcrumb.
94
  else {
95
    if (!empty($breadcrumb)) {
96
      $breadcrumb_separator = ' » ';
97
      $breadcrumb_str = implode($breadcrumb_separator, $breadcrumb);
98
      $out = '<div class="breadcrumb">' . $breadcrumb_str . '</div>';
99
      return $out;
100
    }
101
  }
102
}
103

    
104
/**
105
 * Custom search block form
106
 *  Magnifying glass icon used instead of 'submit button'.
107
 *  Use javascript to show/hide the 'search this site' prompt inside of the text field
108
 */
109
function mayo_preprocess_search_block_form(&$variables) {
110
  $prompt = t('search this site');
111
  $variables['search'] = array();
112
  $hidden = array();
113

    
114
  unset($variables['form']['actions']['submit']);
115
  unset($variables['form']['actions']['#children']);
116

    
117
  $variables['form']['search_block_form']['#value'] = $prompt;
118
  $variables['form']['search_block_form']['#size'] = theme_get_setting('searchbox_size');
119
  $variables['form']['search_block_form']['#attributes'] = array(
120
    'onblur'  => "if (this.value == '') { this.value = '$prompt'; }",
121
    'onfocus' => "if (this.value == '$prompt') { this.value = ''; }" );
122

    
123
  // we should use 'render' instead of 'drupal_render' since the form is already rendered once.
124
  foreach (element_children($variables['form']) as $key) {
125
    $type = $variables['form'][$key]['#type'];
126
    if ($type == 'hidden' || $type == 'token') {
127
      $hidden[] = render($variables['form'][$key]);
128
    }
129
    else {
130
      $variables['search'][$key] = render($variables['form'][$key]);
131
    }
132
  }
133
  $variables['search']['hidden'] = implode($hidden);
134
  $variables['search_form'] = implode($variables['search']);
135
}
136

    
137
/**
138
 * Implements hook_process_page().
139
 */
140
function mayo_process_page(&$variables) {
141
  // Hook into color.module
142
  if (module_exists('color')) {
143
    _color_page_alter($variables);
144
  }
145
}
146

    
147
/**
148
 * Implements hook_preprocess_maintenance_page().
149
 */
150
function mayo_preprocess_maintenance_page(&$variables) {
151
  drupal_add_css(drupal_get_path('theme', 'mayo') . '/css/maintenance-page.css');
152
}
153

    
154
/**
155
 * Implements hook_preprocess_html().
156
 */
157
function mayo_preprocess_html(&$variables) {
158
  global $theme_key;
159
  // Adds classes to <body class="">
160
  $settings_array = array(
161
    'round_corners',
162
    'dark_messages',
163
  );
164
  foreach ($settings_array as $setting) {
165
    if (theme_get_setting($setting) !== 0) {
166
      $variables['classes_array'][] = theme_get_setting($setting);
167
    }
168
  }
169

    
170
  // Add conditional stylesheet for IE
171
  drupal_add_css(path_to_theme() . '/css/ie8.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'IE 8', '!IE' => FALSE), 'preprocess' => FALSE));
172
  drupal_add_css(path_to_theme() . '/css/ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => ' IE 7', '!IE' => FALSE), 'preprocess' => FALSE));
173
  drupal_add_css(path_to_theme() . '/css/ie6.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'IE 6', '!IE' => FALSE), 'preprocess' => FALSE));
174

    
175
  $options = array(
176
    'type' => 'file',
177
    'group' => CSS_THEME,
178
    'weight' => 10,
179
  );
180

    
181
  if (theme_get_setting('menubar_style') == 2) {
182
    drupal_add_css(drupal_get_path('theme', 'mayo') . '/css/black-menu.css', $options);
183
  }
184

    
185
  // Add old legacy MAYO styles for Superfish.
186
  if (theme_get_setting('legacy_superfish_styles') == 1) {
187
    drupal_add_css(drupal_get_path('theme', 'mayo') . '/css/mayo-superfish.css', $options);
188
  }
189

    
190
  $options = array(
191
    'type' => 'inline',
192
    'group' => CSS_THEME,
193
    'weight' => 10,
194
  );
195

    
196
  $font_family = array(
197
    // Added Japanese font support
198
    0 => "font-family: Georgia, 'Palatino Linotype', 'Book Antiqua', 'URW Palladio L', Baskerville, Meiryo, 'Hiragino Mincho Pro', 'MS PMincho', serif; ",
199
    1 => "font-family: Verdana, Geneva, Arial, 'Bitstream Vera Sans', 'DejaVu Sans', Meiryo, 'Hiragino Kaku Gothic Pro', 'MS PGothic', Osaka, sans-serif; ",
200
  );
201

    
202
  // Add font related stylesheets
203
  $base_font_size = theme_get_setting('base_font_size');
204
  $style = 'font-size: ' . $base_font_size . '; ';
205
  $base_font_family = theme_get_setting('base_font_family');
206
  if ($base_font_family == 2) { // Custom
207
    $style .= 'font-family: ' . str_replace(array("&quot;", '\\', '/', '&#039;', '(', ')', ':', ';'), array('"', ''), check_plain(theme_get_setting('base_custom_font_family'))) . ';';
208
  }
209
  else {
210
    $style .= $font_family[$base_font_family];
211
  }
212
  drupal_add_css("body {" . $style . "}", $options);
213

    
214
  $heading_font_family = theme_get_setting('heading_font_family');
215
  if ($heading_font_family == 2) { // Custom
216
    $style .= 'font-family: ' . str_replace(array("&quot;", '\\', '/', '&#039;', '(', ')', ':', ';'), array('"', ''), check_plain(theme_get_setting('heading_custom_font_family'))) . ';';
217
  }
218
  else {
219
    $style = $font_family[$heading_font_family];
220
  }
221
  drupal_add_css("h1,h2,h3,h4,h5 {" . $style . "}", $options);
222

    
223
  if ($heading_font_family == 1) {
224
    // in case of san-serif fonts, make heading font sizes slightly smaller
225
    drupal_add_css(".sidebar h2 { font-size: 1.2em; }", $options);
226
    drupal_add_css("#content .node h2 { font-size: 1.4em; }", $options);
227
  }
228
    // Get the path to the directory where our CSS files are saved
229
  $theme_name = $theme_key;
230
  $path = variable_get('theme_' . $theme_name . '_files_directory');
231
    // Load Layout
232
  mayo_load_layout_css($path, $theme_name);
233
}
234

    
235
/**
236
 * Implements hook_process_html().
237
 */
238
function mayo_process_html(&$variables) {
239
  // Hook into color.module
240
  if (module_exists('color')) {
241
    _color_html_alter($variables);
242
  }
243
}
244

    
245
/**
246
 * Implements hook_page_alter().
247
 */
248
function mayo_page_alter($page) {
249
  // Add meta tag for viewport, for easier responsive theme design.
250
  $viewport = array(
251
    '#type' => 'html_tag',
252
    '#tag' => 'meta',
253
    '#attributes' => array(
254
      'name' => 'viewport',
255
      'content' => 'width=device-width, initial-scale=1',
256
    ),
257
  );
258
  drupal_add_html_head($viewport, "viewport");
259
}