View source
<?php
function context_layouts_help($path, $arg) {
switch ($path) {
case 'admin/help#context_layouts':
$output = file_get_contents(drupal_get_path('module', 'context_layouts') . '/README.txt');
return module_exists('markdown') ? filter_xss_admin(module_invoke('markdown', 'filter', 'process', 0, -1, $output)) : '<pre>' . check_plain($output) . '</pre>';
}
}
function context_layouts_context_plugins() {
return array(
'context_layouts_reaction_block' => array(
'handler' => array(
'path' => drupal_get_path('module', 'context_layouts') . '/plugins',
'file' => 'context_layouts_reaction_block.inc',
'class' => 'context_layouts_reaction_block',
'parent' => 'context_reaction_block',
),
),
);
}
function context_layouts_context_registry_alter(&$registry) {
if (isset($registry['reactions']['block'])) {
$registry['reactions']['block']['plugin'] = 'context_layouts_reaction_block';
}
}
function context_layouts_theme() {
$info = array();
foreach (list_themes() as $theme) {
if (!empty($theme->status) && ($layouts = context_layouts_get_layouts($theme->name))) {
foreach ($layouts as $layout) {
if (!empty($layout['template'])) {
$info["page__context_layouts_{$theme->name}_{$layout['layout']}"] = array(
'template' => $layout['template'],
'path' => $layout['path'],
);
}
}
}
}
return $info;
}
function context_layouts_context_page_reaction() {
$plugin = context_get_plugin('reaction', 'block');
if ($plugin && method_exists($plugin, 'add_layout_stylesheet')) {
$plugin
->add_layout_stylesheet();
}
}
function context_layouts_preprocess_page(&$vars) {
$plugin = context_get_plugin('reaction', 'block');
if ($plugin && method_exists($plugin, 'add_layout_template')) {
$plugin
->add_layout_template($vars);
}
}
function context_layouts_get_layouts($theme = NULL, $reset = FALSE) {
static $layouts = array();
$layouts = $reset ? array() : $layouts;
global $theme_key;
$theme = isset($theme) ? $theme : $theme_key;
if (!isset($layouts[$theme])) {
$info = system_get_info('theme', $theme);
$themes = array();
if (isset($info['base theme'])) {
while (!empty($info['base theme'])) {
$base_theme = $info['base theme'];
$info = system_get_info('theme', $base_theme);
$themes[$base_theme] = $info;
}
}
$themes = array_reverse($themes);
$themes[$theme] = system_get_info('theme', $theme);
foreach ($themes as $key => $info) {
$path = drupal_get_path('theme', $key);
if (!empty($info['layouts'])) {
foreach ($info['layouts'] as $layout => $layout_info) {
$layout_info['layout'] = str_replace('-', '_', $layout);
$layout_info['theme'] = $key;
$layout_info['path'] = $path;
$layouts[$theme][$layout] = $layout_info;
}
}
}
}
return isset($layouts[$theme]) ? $layouts[$theme] : FALSE;
}
function context_layouts_get_active_layout($info = TRUE) {
$plugin = context_get_plugin('reaction', 'block');
if ($plugin && method_exists($plugin, 'get_active_layout')) {
return $plugin
->get_active_layout($info);
}
}