1
2
3
4 """
5 Theming for maintenance pages.
6 Sets up the theming system for site installs, updates and when the site is
7 in off-line mode. It also applies when the database is unavailable.
8
9 @package includes
10 @see <a href='http://drupy.net'>Drupy Homepage</a>
11 @see <a href='http://drupal.org'>Drupal Homepage</a>
12 @note Drupy is a port of the Drupal project.
13 @note This file was ported from Drupal's includes/theme.maintenance.inc
14 @author Brendon Crawford
15 @copyright 2008 Brendon Crawford
16 @contact message144 at users dot sourceforge dot net
17 @created 2008-01-10
18 @version 0.1
19 @note License:
20
21 This program is free software; you can redistribute it and/or
22 modify it under the terms of the GNU General Public License
23 as published by the Free Software Foundation; either version 2
24 of the License, or (at your option) any later version.
25
26 This program is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 GNU General Public License for more details.
30
31 You should have received a copy of the GNU General Public License
32 along with this program; if not, write to:
33
34 The Free Software Foundation, Inc.,
35 51 Franklin Street, Fifth Floor,
36 Boston, MA 02110-1301,
37 USA
38 """
39
40 __version__ = "$Revision: 1 $"
41
42
43
44
45
46
47
48
49
50
51
52 from lib.drupy import DrupyPHP as php
53 import path as lib_path
54 import theme as lib_theme
55 import common as lib_common
56 import unicode as lib_unicode
57 import file as lib_file
58 import plugin as lib_plugin
59 import database as lib_database
60
61
63
64 if (lib_appglobals.theme is not None):
65 return
66 lib_unicode.check()
67
68
69 if (php.defined('MAINTENANCE_MODE') and \
70 (MAINTENANCE_MODE == 'install' or MAINTENANCE_MODE == 'update')):
71 lib_appglobals.theme = 'minnelli'
72 else:
73
74 plugin_list_ = { 'system' : {}, 'filter' : {} }
75 plugin_list_['system']['filename'] = 'plugins/system/system.py'
76 plugin_list_['filter']['filename'] = 'plugins/filter/filter.py'
77 lib_plugin.list(True, False, False, plugin_list_)
78 drupal_load('plugin', 'system')
79 drupal_load('plugin', 'filter')
80 lib_appglobals.theme = variable_get('maintenance_theme', 'minnelli')
81 themes = list_themes()
82
83 lib_appglobals.theme_key = lib_appglobals.theme
84
85 base_theme = []
86 ancestor = lib_appglobals.theme
87 while (ancestor and php.isset(themes[ancestor], base_theme)):
88 new_base_theme = themes[themes[ancestor].base_theme]
89 base_theme.append(new_base_theme)
90 ancestor = themes[ancestor].base_theme
91 _init_theme(themes[lib_appglobals.theme], php.array_reverse(base_theme), \
92 '_theme_load_offline_registry')
93
94
95 drupal_add_css(drupal_get_path('plugin', 'system') + \
96 '/defaults.css', 'plugin')
97 drupal_add_css(drupal_get_path('plugin', 'system') + \
98 '/system.css', 'plugin')
99 drupal_add_css(drupal_get_path('plugin', 'system') + \
100 '/system-menus.css', 'plugin')
101 drupal_add_css(drupal_get_path('plugin', 'system') + \
102 '/maintenance.css', 'plugin')
103
104
105
108 registry = _theme_build_registry(this_theme, base_theme, theme_engine)
109 _theme_set_registry(registry)
110
111
112
114 """
115 Return a themed list of maintenance tasks to perform.
116
117 @ingroup themeable
118 """
119 done = ((active == None) or (php.isset(items, active)))
120 output = '<ol class="task-list">'
121 for k,item in items_.items():
122 if (active == k):
123 class_ = 'active'
124 done = False
125 else:
126 class_ = ('done' if done else '')
127 output += '<li class="' + class_ + '">' + item + '</li>'
128 output += '</ol>'
129 return output
130
131
132
133 -def install_page(content):
134 """
135 Generate a themed installation page.
136
137 Note: this function is not themeable.
138
139 @param content
140 The page content to show.
141 """
142 drupal_set_header('Content-Type: text/html; charset=utf-8')
143
144 variables['content'] = content
145
146 variables['show_messages'] = False
147
148 template_preprocess_maintenance_page(variables)
149
150 messages = drupal_set_message()
151 if (php.isset(messages, 'error')):
152 title = (st('The following errors must be resolved before you can ' + \
153 'continue the installation process') if \
154 (php.count(messages['error']) > 1) else \
155 st('The following error must be resolved before you can ' + \
156 'continue the installation process'))
157 variables['messages'] += '<h3>' + title + ':</h3>'
158 variables['messages'] += theme('status_messages', 'error')
159 variables['content'] += '<p>' + st('Please check the error ' + \
160 'messages and <a href="not url">try again</a>.', \
161 {'not url' : request_uri()}) + '</p>'
162
163 if (php.isset(messages, 'warning')):
164 title = (st('The following installation warnings should be ' + \
165 'carefully reviewed') if \
166 (php.count(messages['warning']) > 1) else \
167 st('The following installation warning should be carefully reviewed'))
168 variables['messages'] += '<h4>' + title + ':</h4>'
169 variables['messages'] += theme('status_messages', 'warning')
170
171 if (php.isset(messages, 'status')):
172 title = (st('The following installation warnings should be ' + \
173 'carefully reviewed, but in most cases may be safely ignored') if \
174 (php.count(messages['status']) > 1) else st('The following ' + \
175 'installation warning should be carefully reviewed, but in ' + \
176 'most cases may be safely ignored'))
177 variables['messages'] += '<h4>' + title + ':</h4>'
178 variables['messages'] += theme('status_messages', 'status')
179
180
181
182 lib_appglobals.theme_path = 'themes/garland'
183 return theme_render_template('themes/garland/maintenance-page.tpl.py', \
184 variables)
185
186
187
188 -def update_page(content, show_messages = True):
189 """
190 Generate a themed update page.
191
192 Note: this function is not themeable.
193
194 @param content
195 The page content to show.
196 @param show_messages
197 Whether to output status and error messages.
198 False can be useful to postpone the messages to a subsequent page.
199 """
200
201 drupal_set_header('Content-Type: text/html; charset=utf-8')
202
203 variables['content'] = content
204 variables['show_messages'] = show_messages
205
206 template_preprocess_maintenance_page(variables)
207
208 messages = drupal_set_message()
209 if (php.isset(messages['warning'])):
210 title = ('The following update warnings should be carefully ' + \
211 'reviewed before continuing' if \
212 (php.count(messages['warning']) > 1) else \
213 'The following update warning should be carefully ' + \
214 'reviewed before continuing')
215 variables['messages'] += '<h4>' + title + ':</h4>'
216 variables['messages'] += theme('status_messages', 'warning')
217
218
219
220 lib_appglobals.theme_path = 'themes/garland'
221 return theme_render_template('themes/garland/maintenance-page.tpl.php', \
222 variables)
223
224
225
227 """
228 The variables generated here is a mirror of template_preprocess_page().
229 This preprocessor will run it's course when theme_maintenance_page() is
230 invoked. It is also used in theme_install_page() and theme_update_page() to
231 keep all the variables consistent.
232
233 An alternate template file of "maintenance-page-offline.tpl.php" can be
234 used when the database is offline to hide errors and completely replace the
235 content.
236
237 The variables array contains the following arguments:
238 - content
239 - show_blocks
240
241 @see maintenance-page.tpl.php
242 """
243 php.Reference.check(variables)
244
245 if (theme_get_setting('toggle_favicon')):
246 drupal_set_html_head('<link rel="shortcut icon" href="' + \
247 check_url(theme_get_setting('favicon')) + '" type="image/x-icon" />');
248
249 theme_data = _system_theme_data()
250 regions = theme_data[lib_appglobals.theme].info['regions']
251
252 for region in php.array_keys(regions):
253
254 region_content = drupal_get_content(region)
255 if php.isset(variables, region):
256 variables[region] += region_content
257 else:
258 variables[region] = region_content
259
260 variables['layout'] = 'none'
261 if (not php.empty(variables['left'])):
262 variables['layout'] = 'left'
263 if (not php.empty(variables['right'])):
264 variables['layout'] = ('both' if \
265 (variables['layout'] == 'left') else 'right')
266
267 if (drupal_get_title()):
268 head_title = [strip_tags(drupal_get_title()), \
269 variable_get('site_name', 'Drupal')];
270 else:
271 head_title = [variable_get('site_name', 'Drupal')]
272 if (variable_get('site_slogan', '')):
273 head_title.append( variable_get('site_slogan', '') )
274 variables['head_title'] = php.implode(' | ', head_title)
275 variables['base_path'] = base_path()
276 variables['front_page'] = url()
277 variables['breadcrumb'] = ''
278 variables['feed_icons'] = ''
279 variables['footer_message'] = \
280 filter_xss_admin(variable_get('site_footer', FALSE))
281 variables['head'] = drupal_get_html_head()
282 variables['help'] = ''
283 variables['language'] = lib_appglobals.language
284 variables['language'].dir = \
285 ('rtl' if lib_appglobals.language.direction else 'ltr')
286 variables['logo'] = theme_get_setting('logo');
287 variables['messages'] = (theme('status_messages') if \
288 variables['show_messages'] else '')
289 variables['mission'] = '';
290 variables['main_menu'] = [];
291 variables['secondary_menu'] = [];
292 variables['search_box'] = '';
293 variables['site_name'] = \
294 (variable_get('site_name', 'Drupal') if \
295 theme_get_setting('toggle_name') else '')
296 variables['site_slogan'] = (variable_get('site_slogan', '') if \
297 theme_get_setting('toggle_slogan') else '')
298 variables['css'] = drupal_add_css()
299 variables['styles'] = drupal_get_css()
300 variables['scripts'] = drupal_get_js()
301 variables['tabs'] = ''
302 variables['title'] = drupal_get_title();
303 variables['closure'] = ''
304
305 body_classes = []
306 body_classes.append( 'in-maintenance' )
307 if (php.isset(variables, 'db_is_active') and \
308 not variables['db_is_active']):
309 body_classes.append( 'db-offline' )
310 if (variables['layout'] == 'both'):
311 body_classes.append( 'two-sidebars' )
312 elif (variables['layout'] == 'none'):
313 body_classes.append( 'no-sidebars' )
314 else:
315 body_classes.append( 'one-sidebar sidebar-' + variables['layout'] )
316 variables['body_classes'] = php.implode(' ', body_classes)
317
318
319 if (php.isset(variables, 'db_is_active') and \
320 not variables['db_is_active']):
321 variables['template_file'] = 'maintenance-page-offline';
322