| 1 |
<?php
|
| 2 |
// $Id: blocks404.active.inc,v 1.4 2009/06/29 19:01:49 johnalbin Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Helper function that performs the actual inclusion of the left and right regions.
|
| 6 |
*/
|
| 7 |
function _blocks404_preprocess_page(&$vars) {
|
| 8 |
// Render the left and right regions.
|
| 9 |
$vars['left'] = theme('blocks', 'left') . $vars['left'];
|
| 10 |
$vars['right'] = theme('blocks', 'right') . $vars['right'];
|
| 11 |
|
| 12 |
// Add JS/CSS added by blocks.
|
| 13 |
$vars['scripts'] = drupal_get_js();
|
| 14 |
$vars['styles'] = drupal_get_css();
|
| 15 |
|
| 16 |
// Some themes (like Acquia Marina) are checking the show_blocks variable to
|
| 17 |
// hide regions that aren't named left or right.
|
| 18 |
$vars['show_blocks'] = TRUE;
|
| 19 |
|
| 20 |
blocks404_reset_body_classes($vars);
|
| 21 |
}
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Resets the body classes if called from within a preprocess_page function.
|
| 25 |
*/
|
| 26 |
function blocks404_reset_body_classes(&$vars) {
|
| 27 |
// Determine the new layout variable.
|
| 28 |
$layout = 'none';
|
| 29 |
if (!empty($vars['left'])) {
|
| 30 |
$layout = 'left';
|
| 31 |
}
|
| 32 |
if (!empty($vars['right'])) {
|
| 33 |
$layout = ($layout == 'left') ? 'both' : 'right';
|
| 34 |
}
|
| 35 |
|
| 36 |
// If the new layout is different than the old layout, reset the body classes.
|
| 37 |
if ($layout != $vars['layout']) {
|
| 38 |
// Some themes (like Zen) store body classes in an array.
|
| 39 |
if (!empty($vars['body_classes_array'])) {
|
| 40 |
$classes = $vars['body_classes_array'];
|
| 41 |
}
|
| 42 |
elseif (!empty($vars['classes_array'])) {
|
| 43 |
$classes = $vars['classes_array'];
|
| 44 |
}
|
| 45 |
else {
|
| 46 |
// Otherwise, we just act on core's $body_classes.
|
| 47 |
$classes = explode(' ', $vars['body_classes']);
|
| 48 |
}
|
| 49 |
|
| 50 |
// Undo the old body classes. $pos will never be 0 because the first body
|
| 51 |
// class is always front/not-front; see template_preprocess_page().
|
| 52 |
if ($vars['layout'] == 'both' && $pos = array_search('two-sidebars', $classes)) {
|
| 53 |
unset($classes[$pos]);
|
| 54 |
}
|
| 55 |
else if ($vars['layout'] == 'none' && $pos = array_search('no-sidebars', $classes)) {
|
| 56 |
unset($classes[$pos]);
|
| 57 |
}
|
| 58 |
else {
|
| 59 |
if ($pos = array_search('one-sidebar', $classes)) {
|
| 60 |
unset($classes[$pos]);
|
| 61 |
}
|
| 62 |
if ($pos = array_search('sidebar-' . $vars['layout'], $classes)) {
|
| 63 |
unset($classes[$pos]);
|
| 64 |
}
|
| 65 |
}
|
| 66 |
|
| 67 |
// Save the new layout variable.
|
| 68 |
$vars['layout'] = $layout;
|
| 69 |
|
| 70 |
// Add information about the number of sidebars.
|
| 71 |
if ($layout == 'both') {
|
| 72 |
$classes[] = 'two-sidebars';
|
| 73 |
}
|
| 74 |
elseif ($layout == 'none') {
|
| 75 |
$classes[] = 'no-sidebars';
|
| 76 |
}
|
| 77 |
else {
|
| 78 |
$classes[] = 'one-sidebar';
|
| 79 |
$classes[] = 'sidebar-' . $layout;
|
| 80 |
}
|
| 81 |
|
| 82 |
// Save the new body classes variables.
|
| 83 |
if (!empty($vars['body_classes_array'])) {
|
| 84 |
$vars['body_classes_array'] = $classes;
|
| 85 |
}
|
| 86 |
elseif (!empty($vars['classes_array'])) {
|
| 87 |
$vars['classes_array'] = $classes;
|
| 88 |
}
|
| 89 |
$vars['body_classes'] = implode(' ', $classes);
|
| 90 |
}
|
| 91 |
}
|
| 92 |
|
| 93 |
/**
|
| 94 |
* Implements hook_form_alter().
|
| 95 |
*
|
| 96 |
* We need this to be able to submit any forms from the error pages, otherwise
|
| 97 |
* the form POSTs to the error page and the form is not processed.
|
| 98 |
*/
|
| 99 |
function _blocks404_form_alter(&$form, $form_state, $form_id) {
|
| 100 |
if ($_GET['q'] == BLOCKS404_PAGE) {
|
| 101 |
// Form actions that POST to the 404 page won't work properly.
|
| 102 |
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))) {
|
| 103 |
$form['#action'] = url('<front>');
|
| 104 |
}
|
| 105 |
// Form actions that redirect back to the 404 page aren't good either.
|
| 106 |
elseif (strpos($form['#action'], 'destination=' . urlencode(BLOCKS404_ORIGINAL_QUERY)) !== FALSE) {
|
| 107 |
// Deconstruct the URL.
|
| 108 |
list(, $path) = explode($GLOBALS['base_path'], $form['#action']);
|
| 109 |
list($path, $query) = explode('?', $path);
|
| 110 |
$query = explode('&', $query);
|
| 111 |
if (($pos = array_search('destination=' . urlencode(BLOCKS404_ORIGINAL_QUERY), $query)) !== FALSE) {
|
| 112 |
// Remove the broken redirection.
|
| 113 |
unset($query[$pos]);
|
| 114 |
// Reconstruct the URL.
|
| 115 |
$form['#action'] = url($path, array('query' => $query));
|
| 116 |
}
|
| 117 |
}
|
| 118 |
}
|
| 119 |
}
|