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