blocks404.active.inc in 404 Blocks 5
File
blocks404.active.inc
View source
<?php
function _blocks404_preprocess_page(&$vars) {
$vars['left'] = theme('blocks', 'left') . $vars['left'];
$vars['right'] = theme('blocks', 'right') . $vars['right'];
blocks404_reset_body_classes($vars);
}
function blocks404_reset_body_classes(&$vars) {
$layout = 'none';
if (!empty($vars['left'])) {
$layout = 'left';
}
if (!empty($vars['right'])) {
$layout = $layout == 'left' ? 'both' : 'right';
}
if ($layout != $vars['layout']) {
if (!empty($vars['body_classes_array'])) {
$classes = $vars['body_classes_array'];
}
elseif (!empty($vars['classes_array'])) {
$classes = $vars['classes_array'];
}
else {
$classes = explode(' ', $vars['body_classes']);
}
if ($vars['layout'] == 'both' && ($pos = array_search('two-sidebars', $classes))) {
unset($classes[$pos]);
}
else {
if ($vars['layout'] == 'none' && ($pos = array_search('no-sidebars', $classes))) {
unset($classes[$pos]);
}
else {
if ($pos = array_search('one-sidebar', $classes)) {
unset($classes[$pos]);
}
if ($pos = array_search('sidebar-' . $vars['layout'], $classes)) {
unset($classes[$pos]);
}
}
}
$vars['layout'] = $layout;
if ($layout == 'both') {
$classes[] = 'two-sidebars';
}
elseif ($layout == 'none') {
$classes[] = 'no-sidebars';
}
else {
$classes[] = 'one-sidebar';
$classes[] = 'sidebar-' . $layout;
}
if (!empty($vars['body_classes_array'])) {
$vars['body_classes_array'] = $classes;
}
elseif (!empty($vars['classes_array'])) {
$vars['classes_array'] = $classes;
}
$vars['body_classes'] = implode(' ', $classes);
}
}
function _blocks404_form_alter($form_id, &$form) {
if ($_GET['q'] == BLOCKS404_PAGE) {
if ($form['#action'] == url(BLOCKS404_PAGE) || $form['#action'] == url(BLOCKS404_ORIGINAL_QUERY) || $form_id == 'user_login_block' || $form['#action'] == url(BLOCKS404_PAGE, array(
'query' => 'destination=' . BLOCKS404_ORIGINAL_QUERY,
))) {
$form['#action'] = url('<front>');
}
elseif (strpos($form['#action'], 'destination=' . urlencode(BLOCKS404_ORIGINAL_QUERY)) !== FALSE) {
list(, $path) = explode($GLOBALS['base_path'], $form['#action']);
list($path, $query) = explode('?', $path);
$query = explode('&', $query);
if (($pos = array_search('destination=' . urlencode(BLOCKS404_ORIGINAL_QUERY), $query)) !== FALSE) {
unset($query[$pos]);
$form['#action'] = url($path, array(
'query' => $query,
));
}
}
}
}