Newer
Older
Jake Strawn
committed
<?php
//$Id$
// Report all PHP errors (see changelog)
//ini_set('error_reporting', E_ALL);
/**
* Implementation of hook_preprocess()
*
* This function checks to see if a hook has a preprocess file associated with
* it, and if so, loads it.
*
* This makes it easier to keep sorted the preprocess functions that can be present in the
* template.php file. You may still use hook_preprocess_page in template.php
* or create a file preprocess-page.inc in the preprocess folder to include the appropriate
* logic to your preprocess functionality
*
* @param $vars
* @param $hook
* @return Array
*/
function omega_preprocess(&$vars, $hook) {
// Collect all information for the active theme.
$themes_active = array();
global $theme_info;
// If there is a base theme, collect the names of all themes that may have
// preprocess files to load.
if($theme_info->base_theme) {
global $base_theme_info;
foreach($base_theme_info as $base){
$themes_active[] = $base->name;
}
}
// Add the active theme to the list of themes that may have preprocess files.
$themes_active[] = $theme_info->name;
// Check all active themes for preprocess files that will need to be loaded.
foreach($themes_active as $name) {
if(is_file(drupal_get_path('theme', $name) . '/preprocess/preprocess-' . str_replace('_', '-', $hook) . '.inc')) {
include(drupal_get_path('theme', $name) . '/preprocess/preprocess-' . str_replace('_', '-', $hook) . '.inc');
}
Jake Strawn
committed
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
}
}
/**
* Preprocessor for page.tpl.php template file.
* The default functionality can be found in preprocess/preprocess-page.inc
*/
function omega_preprocess_page(&$vars, $hook) {
} // end preprocess_page
function omega_preprocess_node(&$vars, $hook) {
} // end preprocess_node
/**
* NINESIXTY - Contextually adds 960 Grid System classes.
*
* The first parameter passed is the *default class*. All other parameters must
* be set in pairs like so: "$variable, 3". The variable can be anything available
* within a template file and the integer is the width set for the adjacent box
* containing that variable.
*
* class="<?php print ns('grid-16', $var_a, 6); ?>"
*
* If $var_a contains data, the next parameter (integer) will be subtracted from
* the default class. See the README.txt file.
*/
function 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;
}
/**
* NINESIXTY - This rearranges how the style sheets are included so the framework styles
* are included first.
*
* Sub-themes can override the framework styles when it contains css files with
* the same name as a framework style. This can be removed once Drupal supports
* weighted styles.
*/
function omega_css_reorder($css) {
global $theme_info, $base_theme_info;
// Dig into the framework .info data.
$framework = !empty($base_theme_info) ? $base_theme_info[0]->info : $theme_info->info;
// Pull framework styles from the themes .info file and place them above all stylesheets.
if (isset($framework['stylesheets'])) {
foreach ($framework['stylesheets'] as $media => $styles_from_960) {
// Setup framework group.
if (isset($css[$media])) {
$css[$media] = array_merge(array('framework' => array()), $css[$media]);
}
else {
$css[$media]['framework'] = array();
}
foreach ($styles_from_960 as $style_from_960) {
// Force framework styles to come first.
if (strpos($style_from_960, 'framework') !== FALSE) {
$framework_shift = $style_from_960;
$remove_styles = array($style_from_960);
// Handle styles that may be overridden from sub-themes.
foreach ($css[$media]['theme'] as $style_from_var => $preprocess) {
if ($style_from_960 != $style_from_var && basename($style_from_960) == basename($style_from_var)) {
$framework_shift = $style_from_var;
$remove_styles[] = $style_from_var;
break;
}
}
$css[$media]['framework'][$framework_shift] = TRUE;
foreach ($remove_styles as $remove_style) {
unset($css[$media]['theme'][$remove_style]);
}
}
}
}
}
return $css;
}
Jake Strawn
committed
/**
* The region_builder function will create the variables needed to create
Jake Strawn
committed
* a dynamic group of regions. This function is simply a quick pass-thru
* that will create either inline or stacked regions. This function will
* not do any advanced functionality, but simply assing the appropriate
* classes based on the settings for the theme.
Jake Strawn
committed
*
Jake Strawn
committed
* For a more advanced set of regions, dynamic_region_builder() will be used.
Jake Strawn
committed
*/
function static_region_builder($region_data, $container_width, $vars) {
Jake Strawn
committed
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
// let's cycle the region data, and determine what we have
foreach ($region_data AS $region => $info) {
// if we do have content for this region, let's create it.
if ($info['data']) {
$vars[$region .'_classes'] = ns('grid-'. $info['width']);
}
if (is_array($info['spacing'])) {
foreach ($info['spacing'] AS $attribute => $value) {
if ($value) {
$vars[$region .'_classes'] .= ' '. $attribute .'-'. $value;
}
}
}
}
return $vars;
}
function _omega_dynamic_zones($width, $conditions, $vars) {
foreach($conditions AS $variable => $reaction) {
if(($reaction['type'] && $vars[$variable]) || (!$reaction['type'] && !$vars[$variable])) {
$width = $width - $reaction['value'];
}
}
return $width;
}
function _omega_dynamic_widths($width, $conditions, $vars) {
foreach($conditions AS $variable => $zone) {
if(($vars[$variable])) {
$width = $width - $zone['width'];
}
}
return $width;
}
/**
* The dynamic_region_builder function will be used to pass important zones
* like the content regions where the regions sent to the function MUST appear
* inline, and advanced calculations need to be done in order to display the as such
*
* Stacked regions are not possible using this function, and should be passed through
* static_region_builder() instead.
*/
function dynamic_region_builder($region_data, $container_width, $vars) {
// let's cycle the region data, and determine what we have
foreach ($region_data AS $region => $info) {
// if we do have content for this region, let's create it.
if ($info['data']) {
$width = $info['primary'] ? $container_width : $info['width'];
$vars[$region .'_classes'] = $info['primary'] ? ns('grid-'. _omega_dynamic_widths($width, $info['related'], $vars)) : ns('grid-'. $info['width']);
// we know we have stuff to put here, so we can check for push & pull options
if($info['pull']) {
// looks like we do wanna pull, or this value would have been false, so let's boogie
$vars[$region .'_classes'] .= ' '. ns('pull-'. _omega_dynamic_zones($info['pull']['width'], $info['pull']['conditions'], $vars));
//krumo('Pulling '. $region .' '. $vars[$region .'_classes']);
}
if($info['push']) {
// looks like a push
$vars[$region .'_classes'] .= ' '. ns('push-'. _omega_dynamic_zones($info['push']['width'], $info['push']['conditions'], $vars));
//krumo('Pushing '. $region .' '. $vars[$region .'_classes']);
//krumo('Should be pushing '. $info['push']['width'] .' grids.');
//krumo($info['push']['conditions']);
}
}
// currently ignored becuase we have not given prefix/suffix class options
// to the primary content zones... this will become active again later
if (is_array($info['spacing'])) {
foreach ($info['spacing'] AS $attribute => $value) {
if ($value) {
Jake Strawn
committed
$vars[$region .'_classes'] .= ' '. $attribute .'-'. $value;
Jake Strawn
committed
}
}
}
// \unused prefix/suffix stuffs
}
return $vars;
Jake Strawn
committed
}
/**
* The rfilter function takes one argument, an array of values for the regions
* for a "group" of regions like preface or postscript
* @param $vars
*/
function rfilter($vars) {
return count(array_filter($vars));
}
Jake Strawn
committed
/**
* OMEGA - A function to return the alpha and or omega classes based on context
Jake Strawn
committed
* This function is not currently being used.
Jake Strawn
committed
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
* @param $vars
* @param $elements
* @param $current
* @param $alpha
* @param $omega
* @return classes
*/
function ao($vars, $elements, $current, $alpha = FALSE, $omega = FALSE){
$classes = array();
$regions = array();
// let's get rid of empty elements first
foreach($elements AS $k => $r) {
if($vars[$r]) {
$regions[$k] = $r;
}
}
// now we do another fast loop since we emptied out any blank zones to determine what
// regions are alpha & omega
foreach($regions AS $k => $r) {
$classes[$r] = '';
if(!$alpha){
$alpha = TRUE;
$classes[$r] .= ' alpha';
}
if(!$omega && ($k == count($regions) - 1 || count($regions) == 1 )) {
$omega = TRUE;
$classes[$r] .= ' omega';
}
}
return $classes[$current];
}
/**
* Converts a string to a suitable html ID attribute.
*
* http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
* valid ID attribute in HTML. This function:
*
* - Ensure an ID starts with an alpha character by optionally adding an 'id'.
* - Replaces any character except alphanumeric characters with dashes.
* - Converts entire string to lowercase.
*
* @param $string
* The string
* @return
* The converted string
*/
function omega_id_safe($string) {
// Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
$string = strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
// If the first character is not a-z, add 'id' in front.
if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
$string = 'id' . $string;
}
return $string;
}
/**
* ZEN - Return a themed breadcrumb trail.
*
* @param $breadcrumb
* An array containing the breadcrumb links.
* @return
* A string containing the breadcrumb output.
*/
function omega_breadcrumb($breadcrumb) {
// Determine if we are to display the breadcrumb.
$show_breadcrumb = theme_get_setting('omega_breadcrumb');
if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
// Optionally get rid of the homepage link.
$show_breadcrumb_home = theme_get_setting('omega_breadcrumb_home');
if (!$show_breadcrumb_home) {
array_shift($breadcrumb);
}
// Return the breadcrumb with separators.
if (!empty($breadcrumb)) {
$breadcrumb_separator = theme_get_setting('omega_breadcrumb_separator');
$trailing_separator = $title = '';
if (theme_get_setting('omega_breadcrumb_title')) {
$trailing_separator = $breadcrumb_separator;
$title = menu_get_active_title();
}
elseif (theme_get_setting('omega_breadcrumb_trailing')) {
$trailing_separator = $breadcrumb_separator;
}
return '<div class="breadcrumb">' . implode($breadcrumb_separator, $breadcrumb) . "$trailing_separator$title</div>";
}
}
// Otherwise, return an empty string.
return '';
}
/**
* Create a string of attributes form a provided array.
*
* @param $attributes
* @return string
*/
function omega_render_attributes($attributes) {
Jake Strawn
committed
if ($attributes) {
Jake Strawn
committed
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
$items = array();
foreach($attributes as $attribute => $data) {
if(is_array($data)) {
$data = implode(' ', $data);
}
$items[] = $attribute . '="' . $data . '"';
}
$output = ' ' . implode(' ', $items);
}
return $output;
}
/**
* Implementation of hook_theme().
*
* @return
*/
function omega_theme(&$existing, $type, $theme, $path) {
if (!db_is_active()) {
return array();
}
include_once './' . drupal_get_path('theme', 'omega') . '/theme-functions.inc';
// Since we are rebuilding the theme registry and the theme settings' default
// values may have changed, make sure they are saved in the database properly.
omega_theme_get_default_settings($theme);
return array(
'id_safe' => array(
'arguments' => array('string'),
),
'render_attributes' => array(
'arguments' => array('attributes'),
),
);