Newer
Older
Sebastian Siemssen
committed
/**
* @file
* Helper functions for the Alpha base theme.
*/
Sebastian Siemssen
committed
* A wrapper function for theme_get_settings().
*
* @param $name
Sebastian Siemssen
committed
*
* @param $default (optional)
* The name (key) of the theme that you want to fetch the
Sebastian Siemssen
committed
* setting for. Defaults to NULL.
*
* The key (machin-readable name) of a theme. Defaults to the key of the
* current theme if not defined.
*
Sebastian Siemssen
committed
* @see
function alpha_theme_get_setting($name, $default = NULL, $theme = NULL) {
$setting = theme_get_setting($name, $theme);
return isset($setting) ? $setting : $default;
}
/**
* A helper function for retrieving zone settings.
*
* @param $name
*
* @param $default (optional)
* The name (key) of the theme that you want to fetch the
* setting for. Defaults to NULL.
*
* @param $theme (optional)
* The key (machin-readable name) of a theme. Defaults to the key of the
* current theme if not defined.
*
* @see
*/
function alpha_zone_get_setting($name, $zone, $default = NULL, $theme = NULL) {
Sebastian Siemssen
committed
$setting = theme_get_setting('alpha_zone_' . $zone . '_' . $name, $theme);
return isset($setting) ? $setting : $default;
}
/**
* A helper function for retrieving region settings.
*
* @param $name
*
* @param $default (optional)
* The name (key) of the theme that you want to fetch the
* setting for. Defaults to NULL.
*
* @param $theme (optional)
* The key (machin-readable name) of a theme. Defaults to the key of the
* current theme if not defined.
*
* @see
*/
function alpha_region_get_setting($name, $region, $default = NULL, $theme = NULL) {
Sebastian Siemssen
committed
$setting = theme_get_setting('alpha_region_' . $region . '_' . $name, $theme);
Sebastian Siemssen
committed
return isset($setting) ? $setting : $default;
Sebastian Siemssen
committed
/**
Sebastian Siemssen
committed
* Invokes a preprocess or process hook in all base themes aswell
* as the subtheme (in that order) by including the corresponding
* .inc file and calling the associated function.
Sebastian Siemssen
committed
*
Sebastian Siemssen
committed
* @param $type
* The type of the hook. Can be preprocess or process.
Sebastian Siemssen
committed
*
Sebastian Siemssen
committed
* @param $hook
* The name of the hook.
Sebastian Siemssen
committed
*
Sebastian Siemssen
committed
* @param &$vars
* An array of variables belonging to the (pre)process hook.
* Handed by reference.
Sebastian Siemssen
committed
*/
Sebastian Siemssen
committed
function alpha_invoke($type, $hook, &$vars) {
$theme = alpha_get_theme();
Sebastian Siemssen
committed
// If one of the themes in the theme trail implements this hook
// include the corresponding .inc file and call the associated function.
foreach (array_keys(alpha_theme_trail($theme->theme)) as $key) {
$file = drupal_get_path('theme', $key) . '/' . $type . '/' . $type . '-' . str_replace('_', '-', $hook) . '.inc';
$function = $key . '_alpha_' . $type . '_' . $hook;
Sebastian Siemssen
committed
if (is_file($file)) {
if (!function_exists($function)) {
include $file;
}
Sebastian Siemssen
committed
Sebastian Siemssen
committed
if (function_exists($function)) {
$function($vars);
}
Sebastian Siemssen
committed
}
}
}
Sebastian Siemssen
committed
/**
Sebastian Siemssen
committed
* This function "fixes" drupal_alter so it also works in the theme-settings and anywhere else
* where you want to be 100% certain that drupal_alter uses the proper global $theme.
Sebastian Siemssen
committed
*
Sebastian Siemssen
committed
* The problem with drupal_alter is, that it always relies on the global $theme while
* the theme-settings page relies (and "overrides") the global $theme_key variable while
* building its form.
Sebastian Siemssen
committed
* @param $type
Sebastian Siemssen
committed
* @param $data
Sebastian Siemssen
committed
*
Sebastian Siemssen
committed
* @param $context1
Sebastian Siemssen
committed
*
Sebastian Siemssen
committed
* @param $context2
Sebastian Siemssen
committed
* @see
* See drupal_alter() for more information about how this works.
Sebastian Siemssen
committed
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
function alpha_alter($type, &$data, &$context1 = NULL, &$context2 = NULL) {
global $theme, $base_theme_info;
if ($theme != $context1) {
$themes = list_themes();
if (!empty($themes[$context1])) {
$theme_original = $theme;
$base_theme_info_original = $base_theme_info;
foreach (alpha_theme_trail($context1) as $key => $title) {
if (isset($themes[$key])) {
$base_theme_info[$key] = $themes[$key];
}
}
$functions = &drupal_static('drupal_alter');
if (!empty($base_theme_info)) {
foreach ($base_theme_info as $item) {
if (is_file(drupal_get_path('theme', $item->name) . '/template.php')) {
include_once drupal_get_path('theme', $item->name) . '/template.php';
}
}
}
array_pop($base_theme_info);
$theme = $context1;
drupal_alter($type, $data, $context1, $context2);
$theme = $theme_original;
$base_theme_info = $base_theme_info_original;
unset($functions[$type]);
Sebastian Siemssen
committed
}
Sebastian Siemssen
committed
else {
drupal_alter($type, $data, $context1, $context2);
}
Sebastian Siemssen
committed
/**
Sebastian Siemssen
committed
* Builds the full theme trail (deepest base theme first, subtheme last)
* for a theme.
Sebastian Siemssen
committed
*
* The key (machin-readable name) of a theme. Defaults to the key of the
* current theme if not defined.
Sebastian Siemssen
committed
*
* @param $hook
* The name of the hook.
*
Sebastian Siemssen
committed
* @return
Sebastian Siemssen
committed
* An array of all themes in the trail, keyed by theme key.
*/
Sebastian Siemssen
committed
function alpha_theme_trail($theme) {
$static = &drupal_static(__FUNCTION__);
if (!isset($static)) {
$themes = list_themes();
if (isset($themes[$theme]->info['base theme'])) {
foreach (system_find_base_themes($themes, $theme) as $base => $name) {
if ($name && isset($themes[$base])) {
$static[$theme][$base] = $themes[$base]->info['name'];
}
}
}
Sebastian Siemssen
committed
// Add our current subtheme ($key) to that array.
if (isset($themes[$theme])) {
$static[$theme][$theme] = $themes[$theme]->info['name'];
Sebastian Siemssen
committed
}
}
Sebastian Siemssen
committed
if (isset($static[$theme])) {
return $static[$theme];
Sebastian Siemssen
committed
/**
Sebastian Siemssen
committed
* @todo
Sebastian Siemssen
committed
function alpha_get_theme() {
$container = &drupal_static(__FUNCTION__);
$theme = $GLOBALS['theme_key'];
$delta = isset($GLOBALS['delta']) ? $GLOBALS['delta']->machine_name : NULL;
$key = $theme . (isset($delta) ? ':' . $delta : '');
Sebastian Siemssen
committed
if (!isset($container[$key])) {
Sebastian Siemssen
committed
foreach (array_keys(alpha_theme_trail($theme)) as $item) {
if (class_exists($item . '_theme_container')) {
$class = $item . '_theme_container';
}
}
if (isset($class)) {
$container[$key] = new $class($theme, $delta);
Sebastian Siemssen
committed
}
Sebastian Siemssen
committed
}
return $container[$key];
Sebastian Siemssen
committed
}
/**
Sebastian Siemssen
committed
* @todo
Sebastian Siemssen
committed
*/
Sebastian Siemssen
committed
function alpha_libraries_include() {
$theme = alpha_get_theme();
Sebastian Siemssen
committed
Sebastian Siemssen
committed
foreach (array_filter($theme->settings['libraries']) as $item => $status) {
if (alpha_library_active($item)) {
if (!empty($theme->libraries[$item]['js'])) {
foreach ($theme->libraries[$item]['js'] as $include) {
drupal_add_js($include['path'], $include['options']);
}
}
Sebastian Siemssen
committed
Sebastian Siemssen
committed
if (!empty($theme->libraries[$item]['css'])) {
foreach ($theme->libraries[$item]['css'] as $include) {
drupal_add_css($include['path'], $include['options']);
}
}
}
Sebastian Siemssen
committed
}
}
/**
Sebastian Siemssen
committed
* @todo
Sebastian Siemssen
committed
*/
Sebastian Siemssen
committed
function alpha_css_include() {
$theme = alpha_get_theme();
foreach (array_filter($theme->settings['css']) as $item => $status) {
if (alpha_css_active($item)) {
drupal_add_css($theme->css[$item]['path'], $theme->css[$item]['options']);
Sebastian Siemssen
committed
}
}
/**
* @todo
*/
Sebastian Siemssen
committed
function alpha_library_active($library) {
$theme = alpha_get_theme();
Sebastian Siemssen
committed
if (isset($theme->libraries[$library], $theme->settings['libraries'][$library]) && $theme->settings['libraries'][$library] === $library) {
return TRUE;
}
return FALSE;
}
Sebastian Siemssen
committed
/**
Sebastian Siemssen
committed
* @todo
Sebastian Siemssen
committed
function alpha_css_active($css) {
$theme = alpha_get_theme();
if (isset($theme->css[$css], $theme->settings['css'][$css]) && $theme->settings['css'][$css] === $css) {
return TRUE;
Sebastian Siemssen
committed
return FALSE;
* @deprecated
Sebastian Siemssen
committed
function alpha_regions() {
return alpha_get_theme()->regions();
* @deprecated
Sebastian Siemssen
committed
function alpha_zones() {
return alpha_get_theme()->zones();
}
Sebastian Siemssen
committed
Sebastian Siemssen
committed
/**
* @todo
* @deprecated
Sebastian Siemssen
committed
*/
function alpha_sections() {
return alpha_get_theme()->sections();
}
Sebastian Siemssen
committed
Sebastian Siemssen
committed
/**
* @todo
* @deprecated
Sebastian Siemssen
committed
*/
function alpha_settings() {
return alpha_get_theme()->settings();
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
/**
* @todo
*/
function alpha_grid_include($columns) {
$processed = &drupal_static(__FUNCTION__);
if (empty($processed[$columns])) {
$processed[$columns] = TRUE;
$theme = alpha_get_theme();
if (!empty($theme->grid)) {
foreach ($theme->grid as &$item) {
if (empty($item['processed']) && (empty($item['columns']) || $item['columns'] == $columns)) {
$item['processed'] = TRUE;
drupal_add_css($item['item'], $item['options']);
}
}
}
if ($theme->settings['debug']['access'] && $theme->settings['debug']['grid']) {
if (isset($theme->grids[$theme->settings['grid']])) {
alpha_grid_debug($theme->grids[$theme->settings['grid']], $theme->settings['responsive'], $columns);
}
}
}
}
/**
* @todo
*/
function alpha_grid_debug($grid, $responsive, $columns) {
if (isset($grid['columns'][$columns])) {
if ($responsive) {
$browsers = array('IE' => 'gte IE 9', '!IE' => TRUE);
$layouts = array_keys($grid['layouts']);
}
else {
$browsers = array('IE' => TRUE, '!IE' => TRUE);
$layouts = isset($grid['layouts'][$grid['primary']]) ? array($grid['primary']) : array();
}
foreach ($layouts as $layout) {
if ($grid['layouts'][$layout]['enabled'] || !$responsive) {
$media = $responsive ? $grid['layouts'][$layout]['media'] : 'all';
$weight = $grid['layouts'][$layout]['weight'];
$sanitized = $grid['layouts'][$layout]['sanitized'];
$file = $grid['path'] . '/' . $sanitized . '/' . $grid['sanitized'] . '-' . $sanitized . '-' . $columns . '.png';
$overlay = '.alpha-grid-debug .container-' . $columns . ' { background-image: ' . (is_file($file) ? 'url(' . file_create_url($file) . ')' : 'none') . '; }';
if ($responsive && $layout == $grid['primary']) {
drupal_add_css($overlay, array(
'type' => 'inline',
'media' => 'all',
'browsers' => array('IE' => '(lt IE 9)&(!IEMobile)', '!IE' => FALSE),
'group' => -2000,
'weight' => $weight,
));
}
drupal_add_css($overlay, array(
'type' => 'inline',
'browsers' => $browsers,
'group' => -1000,
'weight' => $weight,
'media' => $media,
));
}
}
}
}
/**
* @todo
*/
function alpha_grid_css($theme, $grid, $responsive) {
$columns = array_keys($grid['columns']);
if ($responsive) {
$browsers = array('IE' => 'gte IE 9', '!IE' => TRUE);
$layouts = array_keys($grid['layouts']);
}
else {
$browsers = array('IE' => TRUE, '!IE' => TRUE);
$layouts = isset($grid['layouts'][$grid['primary']]) ? array($grid['primary']) : array();
}
$output = array();
if (!empty($layouts)) {
$trail = array_keys(alpha_theme_trail($theme));
foreach ($layouts as $layout) {
$enabled = $grid['layouts'][$layout]['enabled'];
if (!$responsive || $enabled) {
$media = $responsive ? $grid['layouts'][$layout]['media'] : 'all';
$weight = $grid['layouts'][$layout]['weight'];
$sanitized = $grid['layouts'][$layout]['sanitized'];
$attached = array();
foreach ($trail as $item) {
$path = drupal_get_path('theme', $item) . '/css';
$file = str_replace('_', '-', $item) . '-' . $grid['sanitized'];
if ($item = alpha_find_stylesheet($path, $file)) {
$attached[] = $item;
}
if ($item = alpha_find_stylesheet($path, $file . '-' . $sanitized)) {
$attached[] = $item;
}
}
foreach ($attached as $item) {
$basename = $layout . '::' . $item;
$output[$basename]['processed'] = FALSE;
$output[$basename]['item'] = $basename;
$output[$basename]['options'] = array(
'group' => 2000,
'weight' => $weight,
'data' => $item,
'basename' => $basename,
'media' => $media,
'browsers' => $browsers,
'aggregate' => TRUE,
);
if ($responsive && $grid['primary'] == $layout) {
$basename = 'ie::' . $basename;
$output[$basename]['processed'] = FALSE;
$output[$basename]['item'] = $basename;
$output[$basename]['options'] = array(
'group' => 1000,
'weight' => $weight,
'data' => $item,
'basename' => $basename,
'browsers' => array('IE' => '(lt IE 9)&(!IEMobile)', '!IE' => FALSE),
);
}
}
$path = $grid['path'] . '/' . $layout . '/' . $grid['sanitized'] . '-' . $sanitized;
foreach ($columns as $count) {
$file = $path . '-' . $count . '.css';
$output[$file]['processed'] = FALSE;
$output[$file]['columns'] = $count;
$output[$file]['item'] = $file;
$output[$file]['options'] = array(
'group' => 2000,
'weight' => $weight,
'media' => $media,
'browsers' => $browsers,
'aggregate' => TRUE,
);
if ($responsive && $grid['primary'] == $layout) {
$basename = 'ie::' . $layout . '::' . $path . '-' . $count . '.css';
$output[$basename]['processed'] = FALSE;
$output[$basename]['columns'] = $count;
$output[$basename]['item'] = $basename;
$output[$basename]['options'] = array(
'group' => 1000,
'weight' => $weight,
'data' => $file,
'basename' => $basename,
'browsers' => array('IE' => '(lt IE 9)&(!IEMobile)', '!IE' => FALSE),
);
}
}
}
}
}
return $output;
}
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
/**
* @todo
*/
function alpha_grid_css_group($items) {
$output = array();
$group = $media = NULL;
$i = $j = -1;
foreach ($items as $item) {
ksort($item['browsers']);
if (array($item['group'], $item['every_page'], $item['browsers']) !== $group) {
$group = array($item['group'], $item['every_page'], $item['browsers']);
$output[++$i] = array(
'subgroups' => array(),
'browsers' => $item['browsers'],
'group' => $item['group'],
'every_page' => $item['every_page'],
);
}
if ($item['media'] !== $media) {
$media = $item['media'];
$subkey = hash('sha256', serialize($media));
$output[$i]['subgroups'][++$j] = array(
'media' => $media,
'items' => array(),
);
}
$output[$i]['subgroups'][$j]['items'][] = $item;
}
return $output;
}
Sebastian Siemssen
committed
/**
* @todo
*/
function alpha_grid_css_aggregate($elements) {
Sebastian Siemssen
committed
if ($theme->settings['responsive']) {
if ($chunks = alpha_grid_css_chunks($elements['#items'])) {
foreach ($chunks as $items) {
Sebastian Siemssen
committed
$haystack = array_keys($elements['#items']);
$needle = key($items);
$offset = FALSE;
Sebastian Siemssen
committed
Sebastian Siemssen
committed
for ($i = 0; $i < count($haystack); $i++) {
if ($needle === $haystack[$i]) {
$offset = $i;
break;
}
}
Sebastian Siemssen
committed
if ($offset !== FALSE) {
$aggregated = array();
foreach (alpha_grid_css_group($items) as $key => $info) {
$info['data'] = alpha_grid_css_cache($info);
$info['media'] = 'all';
$info['preprocess'] = TRUE;
$info['type'] = 'file';
$aggregated[$key] = $info;
}
Sebastian Siemssen
committed
array_splice($elements['#items'], $offset, count($items), $aggregated);
}
Sebastian Siemssen
committed
}
Sebastian Siemssen
committed
}
}
Sebastian Siemssen
committed
return $elements;
}
/**
* @todo
*/
function alpha_grid_css_chunks($items) {
$output = array();
$i = 0;
foreach ($items as $key => $item) {
if (!empty($item['aggregate']) && $item['type'] == 'file' && $item['preprocess']) {
$output[$i][$key] = $item;
}
else if (!empty($output[$i])) {
$i++;
Sebastian Siemssen
committed
}
}
Sebastian Siemssen
committed
return $output;
Sebastian Siemssen
committed
}
/**
* @todo
*/
function alpha_grid_css_cache($group) {
Sebastian Siemssen
committed
$map = variable_get('drupal_css_cache_files', array());
Sebastian Siemssen
committed
$key = hash('sha256', serialize($group));
$uri = isset($map[$key]) ? $map[$key] : NULL;
Sebastian Siemssen
committed
Sebastian Siemssen
committed
if (empty($uri) || !file_exists($uri)) {
Sebastian Siemssen
committed
$data = alpha_grid_css_merge($group['subgroups']);
Sebastian Siemssen
committed
// Create the css/ within the files folder.
$directory = 'public://css';
$uri = $directory . '/css_' . drupal_hash_base64($data) . '.css';
Sebastian Siemssen
committed
// Create the CSS file.
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
Sebastian Siemssen
committed
if (!file_exists($uri) && !file_unmanaged_save_data($data, $uri, FILE_EXISTS_REPLACE)) {
return FALSE;
}
Sebastian Siemssen
committed
// If CSS gzip compression is enabled, clean URLs are enabled (which means
// that rewrite rules are working) and the zlib extension is available then
// create a gzipped version of this file. This file is served conditionally
// to browsers that accept gzip using .htaccess rules.
if (variable_get('css_gzip_compression', TRUE) && variable_get('clean_url', 0) && extension_loaded('zlib')) {
if (!file_exists($uri . '.gz') && !file_unmanaged_save_data(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) {
return FALSE;
}
}
Sebastian Siemssen
committed
// Save the updated map.
$map[$key] = $uri;
Sebastian Siemssen
committed
Sebastian Siemssen
committed
variable_set('drupal_css_cache_files', $map);
Sebastian Siemssen
committed
}
Sebastian Siemssen
committed
return $uri;
Sebastian Siemssen
committed
}
Sebastian Siemssen
committed
/**
* @todo
*/
Sebastian Siemssen
committed
function alpha_grid_css_merge($group) {
$data = '';
foreach ($group as $info) {
$contents = '';
foreach ($info['items'] as $stylesheet) {
// Build the base URL of this CSS file: start with the full URL.
$base = file_create_url($stylesheet['data']);
$base = substr($base, 0, strrpos($base, '/'));
Sebastian Siemssen
committed
if (substr($base, 0, strlen($GLOBALS['base_root'])) == $GLOBALS['base_root']) {
$base = substr($base, strlen($GLOBALS['base_root']));
Sebastian Siemssen
committed
_drupal_build_css_path(NULL, $base . '/');
// Anchor all paths in the CSS with its base URL, ignoring external and absolute paths.
$contents .= preg_replace_callback('/url\(\s*[\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\s*\)/i', '_drupal_build_css_path', drupal_load_stylesheet($stylesheet['data'], TRUE));
Sebastian Siemssen
committed
}
Sebastian Siemssen
committed
$data .= $info['media'] != 'all' ? '@media ' . $info['media'] . '{' . $contents . '}' : $contents;
Sebastian Siemssen
committed
}
Sebastian Siemssen
committed
return $data;
Sebastian Siemssen
committed
}
/**
* @todo
*/
Sebastian Siemssen
committed
function alpha_cache_clear($theme, $delta = NULL) {
if (!isset($delta)) {
cache_clear_all('alpha:' . $theme, 'cache');
}
else {
cache_clear_all('alpha:' . $theme . ':' . $delta, 'cache');
Sebastian Siemssen
committed
}
}
Sebastian Siemssen
committed
/**
Sebastian Siemssen
committed
* @todo
Sebastian Siemssen
committed
function alpha_cache_set($theme) {
$cache = new stdClass();
Sebastian Siemssen
committed
foreach (array_keys($theme->cacheable()) as $item) {
Sebastian Siemssen
committed
if (isset($theme->$item)) {
$cache->$item = $theme->$item;
Sebastian Siemssen
committed
if (isset($theme->delta)) {
return cache_set('alpha:' . $theme->theme . ':' . $theme->delta, $cache);
}
else {
return cache_set('alpha:' . $theme->theme, $cache);
Sebastian Siemssen
committed
}
Sebastian Siemssen
committed
/**
* @todo
*/
Sebastian Siemssen
committed
function alpha_cache_get($theme, $delta = NULL) {
if (isset($delta)) {
return cache_get('alpha:' . $theme . ':' . $delta);
}
else {
return cache_get('alpha:' . $theme);
Sebastian Siemssen
committed
}
Sebastian Siemssen
committed
}
Sebastian Siemssen
committed
/**
Sebastian Siemssen
committed
* @todo
function alpha_retrieve_excludes($theme) {
$themes = list_themes();
$styles = array();
foreach (system_rebuild_module_data() as $module => $data) {
if ($data->status && !empty($data->info['stylesheets'])) {
foreach ($data->info['stylesheets'] as $media => $content) {
foreach ($content as $file) {
$styles[$file] = array(
'type' => 'module',
'source' => $module,
'name' => $data->info['name'],
'file' => $file,
'media' => $media,
'description' => NULL,
);
}
Sebastian Siemssen
committed
}
}
}
Sebastian Siemssen
committed
foreach (alpha_info_trail('stylesheets', $theme) as $item => $data) {
Sebastian Siemssen
committed
foreach ($data as $media => $content) {
foreach ($content as $file) {
$styles[$file] = array(
'type' => 'theme',
'source' => $item,
'name' => $themes[$item]->info['name'],
Sebastian Siemssen
committed
'file' => $file,
'media' => $media,
'description' => NULL,
);
}
}
}
Sebastian Siemssen
committed
foreach (alpha_info_trail('exclude', $theme) as $item => $data) {
Sebastian Siemssen
committed
foreach ($data as $file => $description) {
$styles[$file] = array(
'type' => 'exclude',
'source' => $item,
'name' => $themes[$item]->info['name'],
Sebastian Siemssen
committed
'file' => $file,
'media' => NULL,
'description' => $description,
);
}
}
return $styles;
Sebastian Siemssen
committed
}
Sebastian Siemssen
committed
/**
* @todo
*/
function alpha_retrieve_grids($theme) {
$output = array();
Sebastian Siemssen
committed
foreach (alpha_info_trail('grids', $theme) as $key => $data) {
foreach ($data as $grid => $info) {
$output[$grid] = array(
'theme' => $key,
'grid' => $grid,
'name' => $info['name'],
'sanitized' => str_replace('_', '-', $grid),
Sebastian Siemssen
committed
'layouts' => $info['layouts'],
'columns' => $info['columns'],
'path' => drupal_get_path('theme', $key) . '/css/grid/' . $grid,
);
$output[$grid]['primary'] = alpha_theme_get_setting('alpha_primary_' . $grid, key($info['layouts']), $theme);
foreach ($output[$grid]['layouts'] as $layout => $title) {
$output[$grid]['layouts'][$layout] = array(
'layout' => $layout,
'name' => $title,
'sanitized' => str_replace('_', '-', $layout),
Sebastian Siemssen
committed
'enabled' => alpha_theme_get_setting('alpha_layouts_' . $grid . '_' . $layout . '_responsive', FALSE, $theme),
'media' => alpha_theme_get_setting('alpha_layouts_' . $grid . '_' . $layout . '_media', 'all', $theme),
'weight' => alpha_theme_get_setting('alpha_layouts_' . $grid . '_' . $layout . '_weight', 0, $theme),
Sebastian Siemssen
committed
);
}
Sebastian Siemssen
committed
uasort($output[$grid]['layouts'], 'alpha_sort_layouts');
Sebastian Siemssen
committed
}
}
Sebastian Siemssen
committed
alpha_alter('alpha_grids', $output, $theme);
Sebastian Siemssen
committed
Sebastian Siemssen
committed
return $output;
Sebastian Siemssen
committed
}
/**
* @todo
*/
function alpha_retrieve_css($theme) {
$output = array();
foreach (alpha_info_trail('css', $theme) as $key => $data) {
foreach ($data as $name => $info) {
$output[$name] = array(
'theme' => $key,
'file' => $name,
'path' => drupal_get_path('theme', $key) . '/' . (isset($info['path']) ? $info['path'] : 'css') . '/' . $name,
'options' => (isset($info['options']) ? $info['options'] : array()) + array('group' => CSS_THEME),
'name' => $info['name'],
'description' => isset($info['description']) ? $info['description'] : '',
);
}
}
Sebastian Siemssen
committed
alpha_alter('alpha_css', $output, $theme);
Sebastian Siemssen
committed
return $output;
}
/**
* @todo
*/
function alpha_retrieve_libraries($theme) {
$output = array();
Sebastian Siemssen
committed
Sebastian Siemssen
committed
foreach (alpha_info_trail('libraries', $theme) as $key => $data) {
foreach ($data as $name => $info) {
$output[$name] = array(
'name' => $info['name'],
'description' => isset($info['info']['description']) ? $info['info']['description'] : '',
);
foreach (array('css', 'js') as $type) {
if (!empty($info[$type])) {
foreach ($info[$type] as $index => $item) {
$output[$name][$type][$index] = array(
'file' => $item['file'],
'path' => drupal_get_path('theme', $key) . '/' . (isset($item['path']) ? $item['path'] : $type) . '/' . $item['file'],
'options' => (isset($item['options']) ? $item['options'] : array()) + array('group' => ($type == 'css' ? CSS_THEME : JS_THEME)),
);
}
}
}
}
}
Sebastian Siemssen
committed
alpha_alter('alpha_libraries', $output, $theme);
return $output;
}
/**
* @todo
*/
function alpha_calculate_primary(&$items, $primary, $container) {
if (!empty($items)) {
$items[$primary]['#grid']['columns'] = $container - $items[$primary]['#grid']['prefix'] - $items[$primary]['#grid']['suffix'];
Sebastian Siemssen
committed
foreach (element_children($items) as $item) {
if ($item != $primary) {
$items[$primary]['#grid']['columns'] -= $items[$item]['#grid']['columns'] + $items[$item]['#grid']['prefix'] + $items[$item]['#grid']['suffix'];
}
}
}
}
Sebastian Siemssen
committed
/**
* @todo
*/
function alpha_calculate_position(&$items) {
if (!empty($items)) {
$children = element_children($items, TRUE);
foreach ($children as $a => $item) {
foreach ($children as $b => $inner) {
if ($item != $inner) {
if ($a >= $b && $items[$item]['#position'] < $items[$inner]['#position']) {
$items[$item]['#grid']['pull'] += $items[$inner]['#grid']['columns'] + $items[$inner]['#grid']['prefix'] + $items[$inner]['#grid']['suffix'];
Sebastian Siemssen
committed
}
else if ($a <= $b && $items[$item]['#position'] > $items[$inner]['#position']) {
$items[$item]['#grid']['push'] += $items[$inner]['#grid']['columns'] + $items[$inner]['#grid']['prefix'] + $items[$inner]['#grid']['suffix'];
Sebastian Siemssen
committed
}
}
Sebastian Siemssen
committed
if ($items[$item]['#grid']['pull'] > $items[$item]['#grid']['push']) {
$items[$item]['#grid']['pull'] -= $items[$item]['#grid']['push'];
$items[$item]['#grid']['push'] = 0;
}
else if ($items[$item]['#grid']['pull'] > $items[$item]['#grid']['push']) {
$items[$item]['#grid']['push'] -= $items[$item]['#grid']['pull'];
$items[$item]['#grid']['pull'] = 0;
}
else if ($items[$item]['#grid']['pull'] == $items[$item]['#grid']['push']) {
$items[$item]['#grid']['pull'] = 0;
$items[$item]['#grid']['push'] = 0;
}
}
}
}
Sebastian Siemssen
committed
/**
* A helper function for retrieving the content of theme .info files
* in the theme trail of $key.
*
* @param $item
* The name of the variable that you want to fetch.
*
* @param $theme
* The key (machin-readable name) of a theme.
*
* @return
* The $item content of all themes .info files in the theme trail.
*/
function alpha_info($item, $theme) {
$themes = list_themes();
if (!empty($themes[$theme]->info[$item])) {
return $themes[$theme]->info[$item];
}
}
Sebastian Siemssen
committed
/**
* @todo
*/
function alpha_info_trail($item, $theme) {
$output = array();
if ($trail = alpha_theme_trail($theme)) {
$themes = list_themes();
Sebastian Siemssen
committed
foreach ($trail as $key => $name) {
if (!empty($themes[$key]->info[$item])) {
$output[$key] = $themes[$key]->info[$item];
Sebastian Siemssen
committed
}
}
}
Sebastian Siemssen
committed
return $output;
}
/**
* @todo
*/
function alpha_find_stylesheet($path, $name) {
foreach (array('css', 'css.less', 'sass', 'scss') as $extension) {
$file = $path . '/' . $name . '.' . $extension;
if (is_file($file)) {
return $file;
}
}
return FALSE;
}
/**
* A helper function to check wether the user defined by $user
* matches one of the roles defined by $roles.
*
* @param $user
* A Drupal user as returned by user_load().