aboutsummaryrefslogtreecommitdiff
path: root/template.php
blob: 1d36d79891d41fc68f54a3243304368b98fbaa76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
// $Id$

/**
 * @file
 * template.php!
 */

/**
 * Override or insert variables into the html template.
 */
function sky_preprocess_html(&$vars) {
  global $theme_path;

  // Add conditional CSS for IE7 and below.
  drupal_add_css($theme_path . '/css/ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 7', '!IE' => FALSE), 'preprocess' => FALSE));
}

/**
 * Implements template_preprocess_page().
 */
function sky_preprocess_page(&$vars) {
  // Shorten the sidebar variable names.
  $sidebar_1 = $vars['page']['sidebar_first'];
  $sidebar_2 = $vars['page']['sidebar_second'];
  // Grid size for sidebars for 2-column layout.
  $width = 4;
  // Grid size for sidebars for 3-column layout.
  if (!empty($sidebar_1) && !empty($sidebar_2)) {
    $width = 3;
  }
  // Define grid classes for page.tpl.php
  $vars['content_grid_classes'] = sky_ns('grid-16', $sidebar_1, $width, $sidebar_2, $width) . ' ' . sky_ns('push-' . $width, !$sidebar_1,  $width);
  $vars['sidebar_first_grid_classes'] = 'grid-' . $width . ' ' . sky_ns('pull-' . (16 - $width), $sidebar_2, $width);
  $vars['sidebar_second_grid_classes'] = 'grid-' . $width;

  // Add text for unpublished nodes.
  if (isset($vars['node']) && $vars['node']->status == 0) {
    $vars['title'] =  drupal_get_title() . ' <span class="marker">(' . t('Unpublished') . ')</span>';
  }
}

/**
 * Implements template_process_html().
 */
function sky_process_html(&$vars) {
  // Apply color module scheme.
  if (module_exists('color')) {
    _color_html_alter($vars);
  }
}

/**
 * Implements template_preprocess_region().
 */
function sky_preprocess_region(&$vars) {
  // Grid classes.
  if ($vars['region'] == 'header') {
    $vars['classes_array'][] = 'grid-6';
  }
  if ($vars['region'] == 'copyright' || $vars['region'] == 'navigation') {
    $vars['classes_array'][] = 'grid-16';
    $vars['classes_array'][] = 'alpha';
    $vars['classes_array'][] = 'omega';
  }
  if ($vars['region'] == 'collapsible') {
    $vars['classes_array'][] = 'container-16';
  }
}

/**
 * Implements template_preprocess_node().
 */
function sky_preprocess_node(&$vars) {
  // Add decent classes for node titles.
  $vars['title_attributes_array']['class'][] = 'title';
  $vars['title_attributes_array']['class'][] = 'node-title';

  // Add the article ARIA role.
  $vars['attributes_array']['role'] = 'article';
}

/**
 * Implements template_preprocess_block().
 */
function sky_preprocess_block(&$vars) {
  // Add decent classes for block titles.
  $vars['title_attributes_array']['class'][] = 'title';
  $vars['title_attributes_array']['class'][] = 'block-title';

  // Flag the first block in each region.
  if ($vars['block_id'] == 1) {
    $vars['classes_array'][] = 'first';
  }

  // Hide the block titles in the header by default.
  if ($vars['block']->region == 'navigation') {
    $vars['title_attributes_array']['class'][] = 'element-invisible';
  }
}

/**
 * Implements hook_html_head_alter().
 * Overwrite the default meta character type tag with HTML5 version.
 */
function sky_html_head_alter(&$head_elements) {
  // Modify the meta tag for HTML5.
  $head_elements['system_meta_content_type']['#attributes'] = array(
    'charset' => 'utf-8',
  );
  // Force IE to always run the latest rendering engine.
  $head_elements['sky_edge_chrome'] = array(
    '#type' => 'html_tag',
    '#tag' => 'meta',
    '#attributes' => array('http-equiv' => 'X-UA-Compatible', 'content' => 'IE=edge,chrome=1'),
  );
}

/**
 * Implements hook_css_alter().
 */
function sky_css_alter(&$css) {
  $path = drupal_get_path('theme', 'sky');

  // Remove some core default stylesheets.
  unset($css[drupal_get_path('module', 'system') . '/system.menus.css']);
  unset($css[drupal_get_path('module', 'system') . '/system.messages.css']);
  unset($css[drupal_get_path('module', 'system') . '/system.theme.css']);
  unset($css[drupal_get_path('module', 'node') . '/node.css']);
  unset($css[drupal_get_path('module', 'aggregator') . '/aggregator.css']);

  // Use the theme's version of user.css.
  $user_css = drupal_get_path('module', 'user') . '/user.css';
  if (isset($css[$user_css])) {
    $css[$user_css]['data'] = $path . '/css/user.css';
  }
  // Use the theme's version of book.css.
  $book_css = drupal_get_path('module', 'book') . '/book.css';
  if (isset($css[$book_css])) {
    $css[$book_css]['data'] = $path . '/css/book.css';
  }
  // Use the theme's version of search.css.
  $search_css = drupal_get_path('module', 'search') . '/search.css';
  if (isset($css[$search_css])) {
    $css[$search_css]['data'] = $path . '/css/search.css';
  }
  // Use the theme's version of jquery.ui.theme.css.
  if (isset($css['misc/ui/jquery.ui.theme.css'])) {
    $css['misc/ui/jquery.ui.theme.css']['data'] = $path . '/css/jquery.ui.theme.css';
  }
}

/**
 * Implements hook_page_alter().
 */
function sky_page_alter(&$page) {
  // Remove the block template wrapper from the main content block.
  if (!empty($page['content']['system_main'])) {
    $page['content']['system_main']['#theme_wrappers'] = array_diff($page['content']['system_main']['#theme_wrappers'], array('block'));
  }
  // Remove sidebars on administrative pages.
  if (arg(0) == 'admin') {
    unset($page['sidebar_first']);
    unset($page['sidebar_second']);
  }
}

/**
 * Overrides theme_status_messages().
 * Shows the message headers instead of hiding them.
 */
function sky_status_messages($variables) {
  $display = $variables['display'];
  $output = '';

  foreach (drupal_get_messages($display) as $type => $messages) {
    $output .= "<div class=\"messages $type\">\n";
    $output .= '<h2 class="message-title">' . t(drupal_ucfirst($type)) . "</h2>\n";
    $output .= '<div class="content">';
    if (count($messages) > 1) {
      $output .= "<ul>\n";
      foreach ($messages as $message) {
        $output .= '  <li>' . $message . "</li>\n";
      }
      $output .= " </ul>\n";
    }
    else {
      $output .= $messages[0];
    }
    $output .= "</div>\n";
    $output .= "</div>\n";
  }
  return $output;
}

/**
 * Overrides theme_field().
 */
function sky_field($variables) {
  $output = '';

  // Render the label, if it's not hidden.
  if (!$variables['label_hidden']) {
    $output .= '<h3 class="field-label"' . $variables['title_attributes'] . '>' . $variables['label'] . '&nbsp;</h3>';
  }

  // Render the items.
  $output .= '<div class="field-items"' . $variables['content_attributes'] . '>';
  foreach ($variables['items'] as $delta => $item) {
    $classes = 'field-item ' . ($delta % 2 ? 'odd' : 'even');
    $output .= '<div class="' . $classes . '"' . $variables['item_attributes'][$delta] . '>' . drupal_render($item) . '</div>';
  }
  $output .= '</div>';

  // Render the top-level DIV.
  $output = '<div class="' . $variables['classes'] . '"' . $variables['attributes'] . '>' . $output . '</div>';

  return $output;
}


/**
 * Implements hook_theme().
 */
function sky_theme() {
  return array(
    'color_scheme_form' => array(
      'render element' => 'form',
      'path' =>  drupal_get_path('theme', 'sky') . '/templates',
      'template' => 'color-scheme-form',
    ),
  );
}

/**
 * Implements template_preprocess_color_scheme_form().
 */
function sky_preprocess_color_scheme_form(&$variables) {
  $form = $variables['form'];
  $info = $form['info']['#value'];
  $path = drupal_get_path('theme', 'sky') . '/';

  // Add the preview.css file.
  drupal_add_css($path . $info['preview_css'], array('group' => CSS_THEME, 'preprocess' => FALSE));

  // Add the preview.js file.
  $preview_js_path = isset($info['preview_js']) ? $path . $info['preview_js'] : drupal_get_path('module', 'color') . '/' . 'preview.js';
  drupal_add_js($preview_js_path, array('group' => JS_THEME));

  // Create a variable for the preview.html file contents.
  $preview_html_path = DRUPAL_ROOT . '/' . (isset($info['preview_html']) ? $path . '/' . $info['preview_html'] : drupal_get_path('module', 'color') . '/preview.html');
  $variables['preview'] = file_get_contents($preview_html_path);
}

/**
 * Taken from the Ninesixty project to help generate grid classes.
 * @see http://drupal.org/project/ninesixty
 */
function sky_ns() {
  $args = func_get_args();
  $default = array_shift($args);
  // Get the type of class, i.e., 'grid', 'pull', 'push', etc.
  // Also get the default unit for the type to be procesed and returned.
  list($type, $return_unit) = explode('-', $default);

  // Process the conditions.
  $flip_states = array('var' => 'int', 'int' => 'var');
  $state = 'var';
  foreach ($args as $arg) {
    if ($state == 'var') {
      $var_state = !empty($arg);
    }
    elseif ($var_state) {
      $return_unit = $return_unit - $arg;
    }
    $state = $flip_states[$state];
  }
  $output = '';
  // Anything below a value of 1 is not needed.
  if ($return_unit > 0) {
    $output = $type . '-' . $return_unit;
  }
  return $output;
}