Simpletest Coverage - includes/theme.maintenance.inc

1 <?php
2 // $Id: theme.maintenance.inc,v 1.34 2009/08/04 07:04:21 webchick 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 maintenance 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 DRUPAL_ROOT . '/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 require_once DRUPAL_ROOT . '/includes/database/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, $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 _drupal_theme_initialize($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');
69 drupal_add_css(drupal_get_path('module', 'system') . '/system.css');
70 drupal_add_css(drupal_get_path('module', 'system') . '/system-menus.css');
71 drupal_add_css(drupal_get_path('module', 'system') . '/maintenance.css');
72 drupal_add_css(drupal_get_path('module', 'system') . '/admin.css');
73 }
74
75 /**
76 * This builds the registry when the site needs to bypass any database calls.
77 */
78 function _theme_load_offline_registry($theme, $base_theme = NULL, $theme_engine = NULL) {
79 $registry = _theme_build_registry($theme, $base_theme, $theme_engine);
80 _theme_set_registry($registry);
81 }
82
83 /**
84 * Return a themed list of maintenance tasks to perform.
85 *
86 * @ingroup themeable
87 */
88 function theme_task_list($items, $active = NULL) {
89 $done = isset($items[$active]) || $active == NULL;
90 $output = '<ol class="task-list">';
91 foreach ($items as $k => $item) {
92 if ($active == $k) {
93 $class = 'active';
94 $done = FALSE;
95 }
96 else {
97 $class = $done ? 'done' : '';
98 }
99 $output .= '<li class="' . $class . '">' . $item . '</li>';
100 }
101 $output .= '</ol>';
102 return $output;
103 }
104
105 /**
106 * Generate a themed installation page.
107 *
108 * Note: this function is not themeable.
109 *
110 * @param $content
111 * The page content to show.
112 */
113 function theme_install_page($content) {
114 drupal_set_header('Content-Type', 'text/html; charset=utf-8');
115
116 // Assign content.
117 $variables['content'] = $content;
118 // Delay setting the message variable so it can be processed below.
119 $variables['show_messages'] = FALSE;
120 // Variable processors invoked manually since this function and theme_update_page()
121 // are exceptions in how it works within the theme system.
122 template_preprocess($variables, 'install_page');
123 template_preprocess_maintenance_page($variables);
124 template_process($variables, 'install_page');
125
126 // Special handling of error messages
127 $messages = drupal_set_message();
128 if (isset($messages['error'])) {
129 $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');
130 $variables['messages'] .= '<h3>' . $title . ':</h3>';
131 $variables['messages'] .= theme('status_messages', 'error');
132 $variables['content'] .= '<p>' . st('Please check the error messages and <a href="!url">try again</a>.', array('!url' => request_uri())) . '</p>';
133 }
134
135 // Special handling of warning messages
136 if (isset($messages['warning'])) {
137 $title = count($messages['warning']) > 1 ? st('The following installation warnings should be carefully reviewed') : st('The following installation warning should be carefully reviewed');
138 $variables['messages'] .= '<h4>' . $title . ':</h4>';
139 $variables['messages'] .= theme('status_messages', 'warning');
140 }
141
142 // Special handling of status messages
143 if (isset($messages['status'])) {
144 $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');
145 $variables['messages'] .= '<h4>' . $title . ':</h4>';
146 $variables['messages'] .= theme('status_messages', 'status');
147 }
148
149 // This was called as a theme hook (not template), so we need to
150 // fix path_to_theme() for the template, to point at the actual
151 // theme rather than system module as owner of the hook.
152 global $theme_path;
153 $theme_path = 'themes/garland';
154
155 return theme_render_template('themes/garland/maintenance-page.tpl.php', $variables);
156 }
157
158 /**
159 * Generate a themed update page.
160 *
161 * Note: this function is not themeable.
162 *
163 * @param $content
164 * The page content to show.
165 * @param $show_messages
166 * Whether to output status and error messages.
167 * FALSE can be useful to postpone the messages to a subsequent page.
168 */
169 function theme_update_page($content, $show_messages = TRUE) {
170 // Set required headers.
171 drupal_set_header('Content-Type', 'text/html; charset=utf-8');
172
173 // Assign content and show message flag.
174 $variables['content'] = $content;
175 $variables['show_messages'] = $show_messages;
176 // Variable processors invoked manually since this function and theme_install_page()
177 // are exceptions in how it works within the theme system.
178 template_preprocess($variables, 'update_page');
179 template_preprocess_maintenance_page($variables);
180 template_process($variables, 'update_page');
181
182 // Special handling of warning messages.
183 $messages = drupal_set_message();
184 if (isset($messages['warning'])) {
185 $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';
186 $variables['messages'] .= '<h4>' . $title . ':</h4>';
187 $variables['messages'] .= theme('status_messages', 'warning');
188 }
189
190 // This was called as a theme hook (not template), so we need to
191 // fix path_to_theme() for the template, to point at the actual
192 // theme rather than system module as owner of the hook.
193 global $theme_path;
194 $theme_path = 'themes/garland';
195
196 return theme_render_template('themes/garland/maintenance-page.tpl.php', $variables);
197 }
198
199 /**
200 * The variables generated here is a mirror of template_preprocess_page().
201 * This preprocessor will run it's course when theme_maintenance_page() is
202 * invoked. It is also used in theme_install_page() and theme_update_page() to
203 * keep all the variables consistent.
204 *
205 * An alternate template file of "maintenance-page-offline.tpl.php" can be
206 * used when the database is offline to hide errors and completely replace the
207 * content.
208 *
209 * The $variables array contains the following arguments:
210 * - $content
211 * - $show_blocks
212 *
213 * @see maintenance-page.tpl.php
214 */
215 function template_preprocess_maintenance_page(&$variables) {
216 // Add favicon
217 if (theme_get_setting('toggle_favicon')) {
218 $favicon = theme_get_setting('favicon');
219 $type = theme_get_setting('favicon_mimetype');
220 drupal_add_html_head('<link rel="shortcut icon" href="' . check_url($favicon) . '" type="' . check_plain($type) . '" />');
221 }
222
223 global $theme;
224 // Retrieve the theme data to list all available regions.
225 $theme_data = _system_get_theme_data();
226 $regions = $theme_data[$theme]->info['regions'];
227
228 // Get all region content set with drupal_add_region_content().
229 foreach (array_keys($regions) as $region) {
230 // Assign region to a region variable.
231 $region_content = drupal_get_region_content($region);
232 isset($variables[$region]) ? $variables[$region] .= $region_content : $variables[$region] = $region_content;
233 }
234
235 // Setup layout variable.
236 $variables['layout'] = 'none';
237 if (!empty($variables['sidebar_first'])) {
238 $variables['layout'] = 'first';
239 }
240 if (!empty($variables['sidebar_second'])) {
241 $variables['layout'] = ($variables['layout'] == 'first') ? 'both' : 'second';
242 }
243
244 // Construct page title
245 if (drupal_get_title()) {
246 $head_title = array(strip_tags(drupal_get_title()), variable_get('site_name', 'Drupal'));
247 }
248 else {
249 $head_title = array(variable_get('site_name', 'Drupal'));
250 if (variable_get('site_slogan', '')) {
251 $head_title[] = variable_get('site_slogan', '');
252 }
253 }
254 $variables['head_title'] = implode(' | ', $head_title);
255 $variables['base_path'] = base_path();
256 $variables['front_page'] = url();
257 $variables['breadcrumb'] = '';
258 $variables['feed_icons'] = '';
259 $variables['head'] = drupal_get_html_head();
260 $variables['help'] = '';
261 $variables['language'] = $GLOBALS['language'];
262 $variables['language']->dir = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
263 $variables['logo'] = theme_get_setting('logo');
264 $variables['messages'] = $variables['show_messages'] ? theme('status_messages') : '';
265 $variables['main_menu'] = array();
266 $variables['secondary_menu'] = array();
267 $variables['search_box'] = '';
268 $variables['site_name'] = (theme_get_setting('toggle_name') ? variable_get('site_name', 'Drupal') : '');
269 $variables['site_slogan'] = (theme_get_setting('toggle_slogan') ? variable_get('site_slogan', '') : '');
270 $variables['css'] = drupal_add_css();
271 $variables['styles'] = drupal_get_css();
272 $variables['scripts'] = drupal_get_js();
273 $variables['tabs'] = '';
274 $variables['title'] = drupal_get_title();
275 $variables['closure'] = '';
276
277 // Compile a list of classes that are going to be applied to the body element.
278 $variables['classes_array'][] = 'in-maintenance';
279 if (isset($variables['db_is_active']) && !$variables['db_is_active']) {
280 $variables['classes_array'][] = 'db-offline';
281 }
282 if ($variables['layout'] == 'both') {
283 $variables['classes_array'][] = 'two-sidebars';
284 }
285 elseif ($variables['layout'] == 'none') {
286 $variables['classes_array'][] = 'no-sidebars';
287 }
288 else {
289 $variables['classes_array'][] = 'one-sidebar sidebar-' . $variables['layout'];
290 }
291
292 // Dead databases will show error messages so supplying this template will
293 // allow themers to override the page and the content completely.
294 if (isset($variables['db_is_active']) && !$variables['db_is_active']) {
295 $variables['template_file'] = 'maintenance-page-offline';
296 }
297 }
298

Legend

Missed
lines code that were not excersized during program execution.
Covered
lines code were excersized during program execution.
Comment/non executable
Comment or non-executable line of code.
Dead
lines of code that according to xdebug could not be executed. This is counted as coverage code because in almost all cases it is code that runnable.