2007-11-30 12:19:10 +00:00
< ? php
// $Id$
/**
* @ file
* Theming for maintenance pages .
*/
/**
* Sets up the theming system for site installs , updates and when the site is
2009-04-19 19:10:08 +00:00
* in maintenance mode . It also applies when the database is unavailable .
2007-11-30 12:19:10 +00:00
*
* Minnelli is always used for the initial install and update operations . In
* other cases , " settings.php " must have a " maintenance_theme " key set for the
* $conf variable in order to change the maintenance theme .
*/
function _drupal_maintenance_theme () {
global $theme , $theme_key ;
// If $theme is already set, assume the others are set too, and do nothing.
if ( isset ( $theme )) {
return ;
}
2008-09-20 20:22:25 +00:00
require_once DRUPAL_ROOT . '/includes/path.inc' ;
require_once DRUPAL_ROOT . '/includes/theme.inc' ;
require_once DRUPAL_ROOT . '/includes/common.inc' ;
require_once DRUPAL_ROOT . '/includes/unicode.inc' ;
require_once DRUPAL_ROOT . '/includes/file.inc' ;
require_once DRUPAL_ROOT . '/includes/module.inc' ;
require_once DRUPAL_ROOT . '/includes/database/database.inc' ;
2007-11-30 12:19:10 +00:00
unicode_check ();
// Install and update pages are treated differently to prevent theming overrides.
if ( defined ( 'MAINTENANCE_MODE' ) && ( MAINTENANCE_MODE == 'install' || MAINTENANCE_MODE == 'update' )) {
2009-10-27 19:29:12 +00:00
$custom_theme = 'minnelli' ;
2007-11-30 12:19:10 +00:00
}
else {
2009-07-10 05:06:55 +00:00
if ( ! db_is_active ()) {
// Because we are operating in a crippled environment, we need to
// bootstrap just enough to allow hook invocations to work.
$module_list [ 'system' ][ 'filename' ] = 'modules/system/system.module' ;
$module_list [ 'filter' ][ 'filename' ] = 'modules/filter/filter.module' ;
2009-08-24 00:14:23 +00:00
module_list ( TRUE , FALSE , FALSE , $module_list );
2009-07-10 05:06:55 +00:00
drupal_load ( 'module' , 'system' );
drupal_load ( 'module' , 'filter' );
}
2007-11-30 23:09:14 +00:00
2009-10-27 19:29:12 +00:00
$custom_theme = variable_get ( 'maintenance_theme' , 'minnelli' );
2007-11-30 12:19:10 +00:00
}
2007-11-30 23:09:14 +00:00
$themes = list_themes ();
2009-10-27 19:29:12 +00:00
// list_themes() triggers a drupal_alter() in maintenance mode, but we can't
// let themes alter the .info data until we know a theme's base themes. So
// don't set global $theme until after list_themes() builds its cache.
$theme = $custom_theme ;
2007-11-30 12:19:10 +00:00
// Store the identifier for retrieving theme settings with.
$theme_key = $theme ;
// Find all our ancestor themes and put them in an array.
$base_theme = array ();
$ancestor = $theme ;
while ( $ancestor && isset ( $themes [ $ancestor ] -> base_theme )) {
$base_theme [] = $new_base_theme = $themes [ $themes [ $ancestor ] -> base_theme ];
$ancestor = $themes [ $ancestor ] -> base_theme ;
}
2009-07-14 10:22:17 +00:00
_drupal_theme_initialize ( $themes [ $theme ], array_reverse ( $base_theme ), '_theme_load_offline_registry' );
2007-11-30 12:19:10 +00:00
// These are usually added from system_init() -except maintenance.css.
// When the database is inactive it's not called so we add it here.
2008-10-26 18:06:39 +00:00
drupal_add_css ( drupal_get_path ( 'module' , 'system' ) . '/defaults.css' );
drupal_add_css ( drupal_get_path ( 'module' , 'system' ) . '/system.css' );
drupal_add_css ( drupal_get_path ( 'module' , 'system' ) . '/system-menus.css' );
drupal_add_css ( drupal_get_path ( 'module' , 'system' ) . '/maintenance.css' );
drupal_add_css ( drupal_get_path ( 'module' , 'system' ) . '/admin.css' );
2007-11-30 12:19:10 +00:00
}
/**
* This builds the registry when the site needs to bypass any database calls .
*/
function _theme_load_offline_registry ( $theme , $base_theme = NULL , $theme_engine = NULL ) {
$registry = _theme_build_registry ( $theme , $base_theme , $theme_engine );
_theme_set_registry ( $registry );
}
/**
* Return a themed list of maintenance tasks to perform .
2007-12-08 14:06:23 +00:00
*
2007-12-06 09:58:34 +00:00
* @ ingroup themeable
2007-11-30 12:19:10 +00:00
*/
2009-10-09 01:00:08 +00:00
function theme_task_list ( $variables ) {
$items = $variables [ 'items' ];
$active = $variables [ 'active' ];
2007-11-30 12:19:10 +00:00
$done = isset ( $items [ $active ]) || $active == NULL ;
2009-09-11 13:56:56 +00:00
$output = '<h2 class="element-invisible">Installation tasks</h2>' ;
$output .= '<ol class="task-list">' ;
2007-11-30 12:19:10 +00:00
foreach ( $items as $k => $item ) {
if ( $active == $k ) {
$class = 'active' ;
2009-09-11 13:56:56 +00:00
$status = '(' . t ( 'active' ) . ')' ;
2008-09-19 07:53:59 +00:00
$done = FALSE ;
2007-11-30 12:19:10 +00:00
}
else {
$class = $done ? 'done' : '' ;
2009-09-11 13:56:56 +00:00
$status = $done ? '(' . t ( 'done' ) . ')' : '' ;
2007-11-30 12:19:10 +00:00
}
2009-09-11 13:56:56 +00:00
$output .= '<li' ;
$output .= ( $class ? ' class="' . $class . '"' : '' ) . '>' ;
$output .= $item ;
$output .= ( $status ? '<span class="element-invisible">' . $status . '</span>' : '' );
$output .= '</li>' ;
2007-11-30 12:19:10 +00:00
}
$output .= '</ol>' ;
return $output ;
}
/**
* Generate a themed installation page .
*
* Note : this function is not themeable .
*
2009-10-09 01:00:08 +00:00
* @ param $variables
* An associative array containing :
* - content : The page content to show .
2007-11-30 12:19:10 +00:00
*/
2009-10-09 01:00:08 +00:00
function theme_install_page ( $variables ) {
2009-09-30 18:36:02 +00:00
drupal_add_http_header ( 'Content-Type' , 'text/html; charset=utf-8' );
2007-11-30 12:19:10 +00:00
// Delay setting the message variable so it can be processed below.
$variables [ 'show_messages' ] = FALSE ;
2009-05-28 16:44:07 +00:00
// Variable processors invoked manually since this function and theme_update_page()
// are exceptions in how it works within the theme system.
template_preprocess ( $variables , 'install_page' );
2007-11-30 12:19:10 +00:00
template_preprocess_maintenance_page ( $variables );
2009-05-28 16:44:07 +00:00
template_process ( $variables , 'install_page' );
2007-11-30 12:19:10 +00:00
// Special handling of error messages
$messages = drupal_set_message ();
if ( isset ( $messages [ 'error' ])) {
$title = count ( $messages [ 'error' ]) > 1 ? st ( 'The following errors must be resolved before you can continue the installation process' ) : st ( 'The following error must be resolved before you can continue the installation process' );
2008-04-14 17:48:46 +00:00
$variables [ 'messages' ] .= '<h3>' . $title . ':</h3>' ;
2009-10-09 01:00:08 +00:00
$variables [ 'messages' ] .= theme ( 'status_messages' , array ( 'display' => 'error' ));
2008-04-14 17:48:46 +00:00
$variables [ 'content' ] .= '<p>' . st ( 'Please check the error messages and <a href="!url">try again</a>.' , array ( '!url' => request_uri ())) . '</p>' ;
2007-11-30 12:19:10 +00:00
}
2008-02-06 19:38:28 +00:00
2008-01-04 17:19:04 +00:00
// Special handling of warning messages
if ( isset ( $messages [ 'warning' ])) {
2008-01-07 15:31:50 +00:00
$title = count ( $messages [ 'warning' ]) > 1 ? st ( 'The following installation warnings should be carefully reviewed' ) : st ( 'The following installation warning should be carefully reviewed' );
2008-04-14 17:48:46 +00:00
$variables [ 'messages' ] .= '<h4>' . $title . ':</h4>' ;
2009-10-09 01:00:08 +00:00
$variables [ 'messages' ] .= theme ( 'status_messages' , array ( 'display' => 'warning' ));
2008-01-04 17:19:04 +00:00
}
2007-11-30 12:19:10 +00:00
// Special handling of status messages
if ( isset ( $messages [ 'status' ])) {
2007-12-08 15:15:25 +00:00
$title = count ( $messages [ 'status' ]) > 1 ? st ( 'The following installation warnings should be carefully reviewed, but in most cases may be safely ignored' ) : st ( 'The following installation warning should be carefully reviewed, but in most cases may be safely ignored' );
2008-04-14 17:48:46 +00:00
$variables [ 'messages' ] .= '<h4>' . $title . ':</h4>' ;
2009-10-09 01:00:08 +00:00
$variables [ 'messages' ] .= theme ( 'status_messages' , array ( 'display' => 'status' ));
2007-11-30 12:19:10 +00:00
}
2008-01-16 10:47:17 +00:00
// This was called as a theme hook (not template), so we need to
// fix path_to_theme() for the template, to point at the actual
// theme rather than system module as owner of the hook.
global $theme_path ;
$theme_path = 'themes/garland' ;
2007-11-30 12:19:10 +00:00
return theme_render_template ( 'themes/garland/maintenance-page.tpl.php' , $variables );
}
/**
* Generate a themed update page .
*
* Note : this function is not themeable .
*
2009-10-09 01:00:08 +00:00
* @ param $variables
* An associative array containing :
* - content : The page content to show .
* - show_messages : Whether to output status and error messages .
* FALSE can be useful to postpone the messages to a subsequent page .
2007-11-30 12:19:10 +00:00
*/
2009-10-09 01:00:08 +00:00
function theme_update_page ( $variables ) {
2007-11-30 12:19:10 +00:00
// Set required headers.
2009-09-30 18:36:02 +00:00
drupal_add_http_header ( 'Content-Type' , 'text/html; charset=utf-8' );
2007-11-30 12:19:10 +00:00
2009-05-28 16:44:07 +00:00
// Variable processors invoked manually since this function and theme_install_page()
// are exceptions in how it works within the theme system.
template_preprocess ( $variables , 'update_page' );
2007-11-30 12:19:10 +00:00
template_preprocess_maintenance_page ( $variables );
2009-05-28 16:44:07 +00:00
template_process ( $variables , 'update_page' );
2007-11-30 12:19:10 +00:00
2008-01-16 10:37:43 +00:00
// Special handling of warning messages.
$messages = drupal_set_message ();
if ( isset ( $messages [ 'warning' ])) {
$title = count ( $messages [ 'warning' ]) > 1 ? 'The following update warnings should be carefully reviewed before continuing' : 'The following update warning should be carefully reviewed before continuing' ;
2008-04-14 17:48:46 +00:00
$variables [ 'messages' ] .= '<h4>' . $title . ':</h4>' ;
2009-10-09 01:00:08 +00:00
$variables [ 'messages' ] .= theme ( 'status_messages' , array ( 'display' => 'warning' ));
2008-01-16 10:37:43 +00:00
}
2008-01-16 10:47:17 +00:00
// This was called as a theme hook (not template), so we need to
// fix path_to_theme() for the template, to point at the actual
// theme rather than system module as owner of the hook.
global $theme_path ;
$theme_path = 'themes/garland' ;
2007-11-30 12:19:10 +00:00
return theme_render_template ( 'themes/garland/maintenance-page.tpl.php' , $variables );
}
2009-10-15 21:19:31 +00:00
/**
* Generate a report of the results from an operation run via authorize . php .
*
* @ param array $variables
* - messages : An array of result messages .
*/
function theme_authorize_report ( $variables ) {
$messages = $variables [ 'messages' ];
$output = '' ;
if ( ! empty ( $messages )) {
$output .= '<div id="authorize-results">' ;
foreach ( $messages as $heading => $logs ) {
$output .= '<h3>' . check_plain ( $heading ) . '</h3>' ;
foreach ( $logs as $number => $log_message ) {
if ( $number === '#abort' ) {
continue ;
}
$output .= theme ( 'authorize_message' , array ( 'message' => $log_message [ 'message' ], 'success' => $log_message [ 'success' ]));
}
}
$output .= '</div>' ;
}
return $output ;
}
/**
* Render a single log message from the authorize . php batch operation .
*
* @ param $variables
* - message : The log message .
* - success : A boolean indicating failure or success .
*/
function theme_authorize_message ( $variables ) {
$output = '' ;
$message = $variables [ 'message' ];
$success = $variables [ 'success' ];
if ( $success ) {
$output .= '<li class="success">' . $message . '</li>' ;
}
else {
$output .= '<li class="failure"><strong>' . t ( 'Failed' ) . ':</strong> ' . $message . '</li>' ;
}
return $output ;
}