[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/includes/ -> theme.maintenance.inc (source)

   1  <?php
   2  // $Id: theme.maintenance.inc,v 1.10.2.2 2010/03/04 00:15:28 goba Exp $
   3  
   4  /**
   5   * @file
   6   * Theming for maintenance pages.
   7   */
   8  
   9  /**
  10   * Sets up the theming system for site installs, updates and when the site is
  11   * in off-line mode. It also applies when the database is unavailable.
  12   *
  13   * Minnelli is always used for the initial install and update operations. In
  14   * other cases, "settings.php" must have a "maintenance_theme" key set for the
  15   * $conf variable in order to change the maintenance theme.
  16   */
  17  function _drupal_maintenance_theme() {
  18    global $theme, $theme_key;
  19  
  20    // If $theme is already set, assume the others are set too, and do nothing.
  21    if (isset($theme)) {
  22      return;
  23    }
  24  
  25    require_once  './includes/path.inc';
  26    require_once  './includes/theme.inc';
  27    require_once  './includes/common.inc';
  28    require_once  './includes/unicode.inc';
  29    require_once  './includes/file.inc';
  30    require_once  './includes/module.inc';
  31    require_once  './includes/database.inc';
  32    unicode_check();
  33  
  34    // Install and update pages are treated differently to prevent theming overrides.
  35    if (defined('MAINTENANCE_MODE') && (MAINTENANCE_MODE == 'install' || MAINTENANCE_MODE == 'update')) {
  36      $theme = 'minnelli';
  37    }
  38    else {
  39      if (!db_is_active()) {
  40        // Because we are operating in a crippled environment, we need to
  41        // bootstrap just enough to allow hook invocations to work.
  42        $module_list['system']['filename'] = 'modules/system/system.module';
  43        $module_list['filter']['filename'] = 'modules/filter/filter.module';
  44        module_list(TRUE, FALSE, FALSE, $module_list);
  45        drupal_load('module', 'system');
  46        drupal_load('module', 'filter');
  47      }
  48  
  49      $theme = variable_get('maintenance_theme', 'minnelli');
  50    }
  51  
  52    $themes = list_themes();
  53  
  54    // Store the identifier for retrieving theme settings with.
  55    $theme_key = $theme;
  56  
  57    // Find all our ancestor themes and put them in an array.
  58    $base_theme = array();
  59    $ancestor = $theme;
  60    while ($ancestor && isset($themes[$ancestor]->base_theme)) {
  61      $base_theme[] = $new_base_theme = $themes[$themes[$ancestor]->base_theme];
  62      $ancestor = $themes[$ancestor]->base_theme;
  63    }
  64    _init_theme($themes[$theme], array_reverse($base_theme), '_theme_load_offline_registry');
  65  
  66    // These are usually added from system_init() -except maintenance.css.
  67    // When the database is inactive it's not called so we add it here.
  68    drupal_add_css(drupal_get_path('module', 'system') .'/defaults.css', 'module');
  69    drupal_add_css(drupal_get_path('module', 'system') .'/system.css', 'module');
  70    drupal_add_css(drupal_get_path('module', 'system') .'/system-menus.css', 'module');
  71    drupal_add_css(drupal_get_path('module', 'system') .'/maintenance.css', 'module');
  72  }
  73  
  74  /**
  75   * This builds the registry when the site needs to bypass any database calls.
  76   */
  77  function _theme_load_offline_registry($theme, $base_theme = NULL, $theme_engine = NULL) {
  78    $registry = _theme_build_registry($theme, $base_theme, $theme_engine);
  79    _theme_set_registry($registry);
  80  }
  81  
  82  /**
  83   * Return a themed list of maintenance tasks to perform.
  84   *
  85   * @ingroup themeable
  86   */
  87  function theme_task_list($items, $active = NULL) {
  88    $done = isset($items[$active]) || $active == NULL;
  89    $output = '<ol class="task-list">';
  90    foreach ($items as $k => $item) {
  91      if ($active == $k) {
  92        $class = 'active';
  93        $done = false;
  94      }
  95      else {
  96        $class = $done ? 'done' : '';
  97      }
  98      $output .= '<li class="'. $class .'">'. $item .'</li>';
  99    }
 100    $output .= '</ol>';
 101    return $output;
 102  }
 103  
 104  /**
 105   * Generate a themed installation page.
 106   *
 107   * Note: this function is not themeable.
 108   *
 109   * @param $content
 110   *   The page content to show.
 111   */
 112  function theme_install_page($content) {
 113    drupal_set_header('Content-Type: text/html; charset=utf-8');
 114  
 115    // Assign content.
 116    $variables['content'] = $content;
 117    // Delay setting the message variable so it can be processed below.
 118    $variables['show_messages'] = FALSE;
 119    // The maintenance preprocess function is recycled here.
 120    template_preprocess_maintenance_page($variables);
 121  
 122    // Special handling of error messages
 123    $messages = drupal_set_message();
 124    if (isset($messages['error'])) {
 125      $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');
 126      $variables['messages'] .= '<h3>'. $title .':</h3>';
 127      $variables['messages'] .= theme('status_messages', 'error');
 128      $variables['content'] .= '<p>'. st('Please check the error messages and <a href="!url">try again</a>.', array('!url' => check_url(request_uri()))) .'</p>';
 129    }
 130  
 131    // Special handling of warning messages
 132    if (isset($messages['warning'])) {
 133      $title = count($messages['warning']) > 1 ? st('The following installation warnings should be carefully reviewed') : st('The following installation warning should be carefully reviewed');
 134      $variables['messages'] .= '<h4>'. $title .':</h4>';
 135      $variables['messages'] .= theme('status_messages', 'warning');
 136    }
 137  
 138    // Special handling of status messages
 139    if (isset($messages['status'])) {
 140      $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');
 141      $variables['messages'] .= '<h4>'. $title .':</h4>';
 142      $variables['messages'] .= theme('status_messages', 'status');
 143    }
 144  
 145    // This was called as a theme hook (not template), so we need to
 146    // fix path_to_theme() for the template, to point at the actual
 147    // theme rather than system module as owner of the hook.
 148    global $theme_path;
 149    $theme_path = 'themes/garland';
 150  
 151    return theme_render_template('themes/garland/maintenance-page.tpl.php', $variables);
 152  }
 153  
 154  /**
 155   * Generate a themed update page.
 156   *
 157   * Note: this function is not themeable.
 158   *
 159   * @param $content
 160   *   The page content to show.
 161   * @param $show_messages
 162   *   Whether to output status and error messages.
 163   *   FALSE can be useful to postpone the messages to a subsequent page.
 164   */
 165  function theme_update_page($content, $show_messages = TRUE) {
 166    // Set required headers.
 167    drupal_set_header('Content-Type: text/html; charset=utf-8');
 168  
 169    // Assign content and show message flag.
 170    $variables['content'] = $content;
 171    $variables['show_messages'] = $show_messages;
 172    // The maintenance preprocess function is recycled here.
 173    template_preprocess_maintenance_page($variables);
 174  
 175    // Special handling of warning messages.
 176    $messages = drupal_set_message();
 177    if (isset($messages['warning'])) {
 178      $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';
 179      $variables['messages'] .= '<h4>'. $title .':</h4>';
 180      $variables['messages'] .= theme('status_messages', 'warning');
 181    }
 182  
 183    // This was called as a theme hook (not template), so we need to
 184    // fix path_to_theme() for the template, to point at the actual
 185    // theme rather than system module as owner of the hook.
 186    global $theme_path;
 187    $theme_path = 'themes/garland';
 188  
 189    return theme_render_template('themes/garland/maintenance-page.tpl.php', $variables);
 190  }
 191  
 192  /**
 193   * The variables generated here is a mirror of template_preprocess_page().
 194   * This preprocessor will run it's course when theme_maintenance_page() is
 195   * invoked. It is also used in theme_install_page() and theme_update_page() to
 196   * keep all the variables consistent.
 197   *
 198   * An alternate template file of "maintenance-page-offline.tpl.php" can be
 199   * used when the database is offline to hide errors and completely replace the
 200   * content.
 201   *
 202   * The $variables array contains the following arguments:
 203   * - $content
 204   * - $show_blocks
 205   *
 206   * @see maintenance-page.tpl.php
 207   */
 208  function template_preprocess_maintenance_page(&$variables) {
 209    // Add favicon
 210    if (theme_get_setting('toggle_favicon')) {
 211      drupal_set_html_head('<link rel="shortcut icon" href="'. check_url(theme_get_setting('favicon')) .'" type="image/x-icon" />');
 212    }
 213  
 214    global $theme;
 215    // Retrieve the theme data to list all available regions.
 216    $theme_data = _system_theme_data();
 217    $regions = $theme_data[$theme]->info['regions'];
 218  
 219    // Get all region content set with drupal_set_content().
 220    foreach (array_keys($regions) as $region) {
 221      // Assign region to a region variable.
 222      $region_content = drupal_get_content($region);
 223      isset($variables[$region]) ? $variables[$region] .= $region_content : $variables[$region] = $region_content;
 224    }
 225  
 226    // Setup layout variable.
 227    $variables['layout'] = 'none';
 228    if (!empty($variables['left'])) {
 229      $variables['layout'] = 'left';
 230    }
 231    if (!empty($variables['right'])) {
 232      $variables['layout'] = ($variables['layout'] == 'left') ? 'both' : 'right';
 233    }
 234  
 235    // Construct page title
 236    if (drupal_get_title()) {
 237      $head_title = array(strip_tags(drupal_get_title()), variable_get('site_name', 'Drupal'));
 238    }
 239    else {
 240      $head_title = array(variable_get('site_name', 'Drupal'));
 241      if (variable_get('site_slogan', '')) {
 242        $head_title[] = variable_get('site_slogan', '');
 243      }
 244    }
 245    $variables['head_title']        = implode(' | ', $head_title);
 246    $variables['base_path']         = base_path();
 247    $variables['breadcrumb']        = '';
 248    $variables['feed_icons']        = '';
 249    $variables['footer_message']    = filter_xss_admin(variable_get('site_footer', FALSE));
 250    $variables['head']              = drupal_get_html_head();
 251    $variables['help']              = '';
 252    $variables['language']          = $GLOBALS['language'];
 253    $variables['language']->dir     = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
 254    $variables['logo']              = theme_get_setting('logo');
 255    $variables['messages']          = $variables['show_messages'] ? theme('status_messages') : '';
 256    $variables['mission']           = '';
 257    $variables['primary_links']     = array();
 258    $variables['secondary_links']   = array();
 259    $variables['search_box']        = '';
 260    $variables['site_name']         = (theme_get_setting('toggle_name') ? variable_get('site_name', 'Drupal') : '');
 261    $variables['site_slogan']       = (theme_get_setting('toggle_slogan') ? variable_get('site_slogan', '') : '');
 262    $variables['css']               = drupal_add_css();
 263    $variables['styles']            = drupal_get_css();
 264    $variables['scripts']           = drupal_get_js();
 265    $variables['tabs']              = '';
 266    $variables['title']             = drupal_get_title();
 267    $variables['closure']           = '';
 268  
 269    // Compile a list of classes that are going to be applied to the body element.
 270    $body_classes = array();
 271    $body_classes[] = 'in-maintenance';
 272    if (isset($variables['db_is_active']) && !$variables['db_is_active']) {
 273      $body_classes[] = 'db-offline';
 274    }
 275    if ($variables['layout'] == 'both') {
 276      $body_classes[] = 'two-sidebars';
 277    }
 278    elseif ($variables['layout'] == 'none') {
 279      $body_classes[] = 'no-sidebars';
 280    }
 281    else {
 282      $body_classes[] = 'one-sidebar sidebar-'. $variables['layout'];
 283    }
 284    $variables['body_classes'] = implode(' ', $body_classes);
 285  
 286    // Dead databases will show error messages so supplying this template will
 287    // allow themers to override the page and the content completely.
 288    if (isset($variables['db_is_active']) && !$variables['db_is_active']) {
 289      $variables['template_file'] = 'maintenance-page-offline';
 290    }
 291  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7