comparison includes/theme.maintenance.inc @ 1:c1f4ac30525a 6.0

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