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