theme.maintenance.inc

Theming for maintenance pages.

Archivo

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

Functions

Nombreorden descendente Descripción
template_preprocess_maintenance_page The variables generated here is a mirror of template_preprocess_page(). This preprocessor will run it's course when theme_maintenance_page() is invoked. It is also used in theme_install_page() and theme_update_page() to keep all the variables…
theme_install_page Generate a themed installation page.
theme_task_list Return a themed list of maintenance tasks to perform.
theme_update_page Generate a themed update page.
_drupal_maintenance_theme Sets up the theming system for site installs, updates and when the site is in off-line mode. It also applies when the database is unavailable.
_theme_load_offline_registry This builds the registry when the site needs to bypass any database calls.