theme.maintenance.inc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /**
  3. * @file
  4. * Theming for maintenance pages.
  5. */
  6. /**
  7. * Sets up the theming system for maintenance page.
  8. *
  9. * Used for site installs, updates and when the site is in maintenance mode.
  10. * It also applies when the database is unavailable or bootstrap was not
  11. * complete. Seven is always used for the initial install and update operations.
  12. * In other cases, Bartik is used, but this can be overridden by setting a
  13. * "maintenance_theme" key in the $conf variable in settings.php.
  14. */
  15. function _drupal_maintenance_theme() {
  16. global $theme, $theme_key, $conf;
  17. // If $theme is already set, assume the others are set too, and do nothing.
  18. if (isset($theme)) {
  19. return;
  20. }
  21. require_once DRUPAL_ROOT . '/' . variable_get('path_inc', 'includes/path.inc');
  22. require_once DRUPAL_ROOT . '/includes/theme.inc';
  23. require_once DRUPAL_ROOT . '/includes/common.inc';
  24. require_once DRUPAL_ROOT . '/includes/unicode.inc';
  25. require_once DRUPAL_ROOT . '/includes/file.inc';
  26. require_once DRUPAL_ROOT . '/includes/module.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. $custom_theme = (isset($conf['maintenance_theme']) ? $conf['maintenance_theme'] : 'seven');
  31. }
  32. else {
  33. // The bootstrap was not complete. So we are operating in a crippled
  34. // environment, we need to bootstrap just enough to allow hook invocations
  35. // to work. See _drupal_log_error().
  36. if (!class_exists('Database', FALSE)) {
  37. require_once DRUPAL_ROOT . '/includes/database/database.inc';
  38. }
  39. // We use the default theme as the maintenance theme. If a default theme
  40. // isn't specified in the database or in settings.php, we use Bartik.
  41. $custom_theme = variable_get('maintenance_theme', variable_get('theme_default', 'bartik'));
  42. }
  43. // Ensure that system.module is loaded.
  44. if (!function_exists('_system_rebuild_theme_data')) {
  45. $module_list['system']['filename'] = 'modules/system/system.module';
  46. module_list(TRUE, FALSE, FALSE, $module_list);
  47. drupal_load('module', 'system');
  48. }
  49. $themes = list_themes();
  50. // list_themes() triggers a drupal_alter() in maintenance mode, but we can't
  51. // let themes alter the .info data until we know a theme's base themes. So
  52. // don't set global $theme until after list_themes() builds its cache.
  53. $theme = $custom_theme;
  54. // Store the identifier for retrieving theme settings with.
  55. $theme_key = $theme;
  56. // Find all our ancestor themes and put them in an array.
  57. $base_theme = array();
  58. $ancestor = $theme;
  59. while ($ancestor && isset($themes[$ancestor]->base_theme)) {
  60. $base_theme[] = $new_base_theme = $themes[$themes[$ancestor]->base_theme];
  61. $ancestor = $themes[$ancestor]->base_theme;
  62. }
  63. _drupal_theme_initialize($themes[$theme], array_reverse($base_theme), '_theme_load_offline_registry');
  64. // These are usually added from system_init() -except maintenance.css.
  65. // When the database is inactive it's not called so we add it here.
  66. $path = drupal_get_path('module', 'system');
  67. drupal_add_css($path . '/system.base.css');
  68. drupal_add_css($path . '/system.admin.css');
  69. drupal_add_css($path . '/system.menus.css');
  70. drupal_add_css($path . '/system.messages.css');
  71. drupal_add_css($path . '/system.theme.css');
  72. drupal_add_css($path . '/system.maintenance.css');
  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. return _theme_build_registry($theme, $base_theme, $theme_engine);
  79. }
  80. /**
  81. * Returns HTML for a list of maintenance tasks to perform.
  82. *
  83. * @param $variables
  84. * An associative array containing:
  85. * - items: An associative array of maintenance tasks.
  86. * - active: The key for the currently active maintenance task.
  87. *
  88. * @ingroup themeable
  89. */
  90. function theme_task_list($variables) {
  91. $items = $variables['items'];
  92. $active = $variables['active'];
  93. $done = isset($items[$active]) || $active == NULL;
  94. $output = '<h2 class="element-invisible">Installation tasks</h2>';
  95. $output .= '<ol class="task-list">';
  96. foreach ($items as $k => $item) {
  97. if ($active == $k) {
  98. $class = 'active';
  99. $status = '(' . t('active') . ')';
  100. $done = FALSE;
  101. }
  102. else {
  103. $class = $done ? 'done' : '';
  104. $status = $done ? '(' . t('done') . ')' : '';
  105. }
  106. $output .= '<li';
  107. $output .= ($class ? ' class="' . $class . '"' : '') . '>';
  108. $output .= $item;
  109. $output .= ($status ? '<span class="element-invisible">' . $status . '</span>' : '');
  110. $output .= '</li>';
  111. }
  112. $output .= '</ol>';
  113. return $output;
  114. }
  115. /**
  116. * Returns HTML for the installation page.
  117. *
  118. * Note: this function is not themeable.
  119. *
  120. * @param $variables
  121. * An associative array containing:
  122. * - content: The page content to show.
  123. */
  124. function theme_install_page($variables) {
  125. drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
  126. return theme('maintenance_page', $variables);
  127. }
  128. /**
  129. * Returns HTML for the update page.
  130. *
  131. * Note: this function is not themeable.
  132. *
  133. * @param $variables
  134. * An associative array containing:
  135. * - content: The page content to show.
  136. * - show_messages: Whether to output status and error messages.
  137. * FALSE can be useful to postpone the messages to a subsequent page.
  138. */
  139. function theme_update_page($variables) {
  140. drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
  141. return theme('maintenance_page', $variables);
  142. }
  143. /**
  144. * Returns HTML for a report of the results from an operation run via authorize.php.
  145. *
  146. * @param $variables
  147. * An associative array containing:
  148. * - messages: An array of result messages.
  149. *
  150. * @ingroup themeable
  151. */
  152. function theme_authorize_report($variables) {
  153. $messages = $variables['messages'];
  154. $output = '';
  155. if (!empty($messages)) {
  156. $output .= '<div id="authorize-results">';
  157. foreach ($messages as $heading => $logs) {
  158. $items = array();
  159. foreach ($logs as $number => $log_message) {
  160. if ($number === '#abort') {
  161. continue;
  162. }
  163. $items[] = theme('authorize_message', array('message' => $log_message['message'], 'success' => $log_message['success']));
  164. }
  165. $output .= theme('item_list', array('items' => $items, 'title' => $heading));
  166. }
  167. $output .= '</div>';
  168. }
  169. return $output;
  170. }
  171. /**
  172. * Returns HTML for a single log message from the authorize.php batch operation.
  173. *
  174. * @param $variables
  175. * An associative array containing:
  176. * - message: The log message.
  177. * - success: A boolean indicating failure or success.
  178. *
  179. * @ingroup themeable
  180. */
  181. function theme_authorize_message($variables) {
  182. $message = $variables['message'];
  183. $success = $variables['success'];
  184. if ($success) {
  185. $item = array('data' => $message, 'class' => array('success'));
  186. }
  187. else {
  188. $item = array('data' => '<strong>' . $message . '</strong>', 'class' => array('failure'));
  189. }
  190. return $item;
  191. }