source: sipes/cord/includes/theme.maintenance.inc

stableversion-3.0
Last change on this file was b354002, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio del cord

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