Projet

Général

Profil

Paste
Télécharger (7,55 ko) Statistiques
| Branche: | Révision:

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

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
 * Return a themed breadcrumb links
68
 *
69
 * @param $breadcrumb
70
 *  An array containing the breadcrumb links.
71
 * @return
72
 *  A string containing the breadcrumb output.
73
 */
74
function mayo_breadcrumb($variables) {
75
  $breadcrumb = $variables['breadcrumb'];
76

    
77
  // remove 'Home'
78
  if (is_array($breadcrumb)) {
79
    array_shift($breadcrumb);
80
  }
81
  if (!empty($breadcrumb)) {
82
    $breadcrumb_separator = ' > ';
83
    $breadcrumb_str = implode($breadcrumb_separator, $breadcrumb);
84
    $breadcrumb_str .= $breadcrumb_separator;
85
    $out = '<div class="breadcrumb">' . $breadcrumb_str . '</div>';
86
    return $out;
87
  }
88
  return '';
89
}
90

    
91
/**
92
 * Custom search block form
93
 *  Magnifying glass icon used instead of 'submit button'.
94
 *  Use javascript to show/hide the 'search this site' prompt inside of the text field
95
 */
96
function mayo_preprocess_search_block_form(&$variables) {
97
  $prompt = t('search this site');
98
  $variables['search'] = array();
99
  $hidden = array();
100

    
101
  unset($variables['form']['actions']['submit']);
102
  unset($variables['form']['actions']['#children']);
103

    
104
  $variables['form']['search_block_form']['#value'] = $prompt;
105
  $variables['form']['search_block_form']['#size'] = theme_get_setting('searchbox_size');
106
  $variables['form']['search_block_form']['#attributes'] = array(
107
    'onblur'  => "if (this.value == '') { this.value = '$prompt'; }",
108
    'onfocus' => "if (this.value == '$prompt') { this.value = ''; }" );
109

    
110
  // we should use 'render' instead of 'drupal_render' since the form is already rendered once.
111
  foreach (element_children($variables['form']) as $key) {
112
    $type = $variables['form'][$key]['#type'];
113
    if ($type == 'hidden' || $type == 'token') {
114
      $hidden[] = render($variables['form'][$key]);
115
    }
116
    else {
117
      $variables['search'][$key] = render($variables['form'][$key]);
118
    }
119
  }
120
  $variables['search']['hidden'] = implode($hidden);
121
  $variables['search_form'] = implode($variables['search']);
122
}
123

    
124
/**
125
 * Implements hook_process_page().
126
 */
127
function mayo_process_page(&$variables) {
128
  // Hook into color.module
129
  if (module_exists('color')) {
130
    _color_page_alter($variables);
131
  }
132
}
133

    
134
/**
135
 * Implements hook_preprocess_maintenance_page().
136
 */
137
function mayo_preprocess_maintenance_page(&$variables) {
138
  drupal_add_css(drupal_get_path('theme', 'mayo') . '/css/maintenance-page.css');
139
}
140

    
141
/**
142
 * Implements hook_preprocess_html().
143
 */
144
function mayo_preprocess_html(&$variables) {
145
  global $theme_key;
146
  // Adds classes to <body class="">
147
  $settings_array = array(
148
    'round_corners',
149
    'dark_messages',
150
  );
151
  foreach ($settings_array as $setting) {
152
    if (theme_get_setting($setting) !== 0) {
153
      $variables['classes_array'][] = theme_get_setting($setting);
154
    }
155
  }
156

    
157
  // Add conditional stylesheet for IE
158
  drupal_add_css(path_to_theme() . '/css/ie8.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'IE 8', '!IE' => FALSE), 'preprocess' => FALSE));
159
  drupal_add_css(path_to_theme() . '/css/ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => ' IE 7', '!IE' => FALSE), 'preprocess' => FALSE));
160
  drupal_add_css(path_to_theme() . '/css/ie6.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'IE 6', '!IE' => FALSE), 'preprocess' => FALSE));
161

    
162
  $options = array(
163
    'type' => 'file',
164
    'group' => CSS_THEME,
165
    'weight' => 10,
166
  );
167

    
168
  if (theme_get_setting('menubar_style') == 2) {
169
    drupal_add_css(drupal_get_path('theme', 'mayo') . '/css/black-menu.css', $options);
170
  }
171

    
172
  // Add old legacy MAYO styles for Superfish.
173
  if (theme_get_setting('legacy_superfish_styles') == 1) {
174
    drupal_add_css(drupal_get_path('theme', 'mayo') . '/css/mayo-superfish.css', $options);
175
  }
176

    
177
  $options = array(
178
    'type' => 'inline',
179
    'group' => CSS_THEME,
180
    'weight' => 10,
181
  );
182

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

    
189
  // Add font related stylesheets
190
  $base_font_size = theme_get_setting('base_font_size');
191
  $style = 'font-size: ' . $base_font_size . '; ';
192
  $base_font_family = theme_get_setting('base_font_family');
193
  if ($base_font_family == 2) { // Custom
194
    $style .= 'font-family: ' . theme_get_setting('base_custom_font_family') . ';';
195
  }
196
  else {
197
    $style .= $font_family[$base_font_family];
198
  }
199
  drupal_add_css("body {" . $style . "}", $options);
200

    
201
  $heading_font_family = theme_get_setting('heading_font_family');
202
  if ($heading_font_family == 2) { // Custom
203
    $style .= 'font-family: ' . theme_get_setting('heading_custom_font_family') . ';';
204
  }
205
  else {
206
    $style = $font_family[$heading_font_family];
207
  }
208
  drupal_add_css("h1,h2,h3,h4,h5 {" . $style . "}", $options);
209

    
210
  if ($heading_font_family == 1) {
211
    // in case of san-serif fonts, make heading font sizes slightly smaller
212
    drupal_add_css(".sidebar h2 { font-size: 1.2em; }", $options);
213
    drupal_add_css("#content .node h2 { font-size: 1.4em; }", $options);
214
  }
215
    // Get the path to the directory where our CSS files are saved
216
  $theme_name = $theme_key;
217
  $path = variable_get('theme_' . $theme_name . '_files_directory');
218
    // Load Layout
219
  mayo_load_layout_css($path, $theme_name);
220
}
221

    
222
/**
223
 * Implements hook_process_html().
224
 */
225
function mayo_process_html(&$variables) {
226
  // Hook into color.module
227
  if (module_exists('color')) {
228
    _color_html_alter($variables);
229
  }
230
}
231

    
232
/**
233
 * Implements hook_page_alter().
234
 */
235
function mayo_page_alter($page) {
236
  // Add meta tag for viewport, for easier responsive theme design.
237
  $viewport = array(
238
    '#type' => 'html_tag',
239
    '#tag' => 'meta',
240
    '#attributes' => array(
241
      'name' => 'viewport',
242
      'content' => 'width=device-width, initial-scale=1',
243
    ),
244
  );
245
  drupal_add_html_head($viewport, "viewport");
246
}