Mercurial > defr > drupal > core
comparison modules/system/system.admin.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 | 2427550111ae |
comparison
equal
deleted
inserted
replaced
0:5a113a1c4740 | 1:c1f4ac30525a |
---|---|
1 <?php | |
2 // $Id: system.admin.inc,v 1.63 2008/02/04 12:35:48 goba Exp $ | |
3 | |
4 /** | |
5 * @file | |
6 * Admin page callbacks for the system module. | |
7 */ | |
8 | |
9 /** | |
10 * Menu callback; Provide the administration overview page. | |
11 */ | |
12 function system_main_admin_page($arg = NULL) { | |
13 // If we received an argument, they probably meant some other page. | |
14 // Let's 404 them since the menu system cannot be told we do not | |
15 // accept arguments. | |
16 if (isset($arg) && substr($arg, 0, 3) != 'by-') { | |
17 return drupal_not_found(); | |
18 } | |
19 | |
20 // Check for status report errors. | |
21 if (system_status(TRUE) && user_access('administer site configuration')) { | |
22 drupal_set_message(t('One or more problems were detected with your Drupal installation. Check the <a href="@status">status report</a> for more information.', array('@status' => url('admin/reports/status'))), 'error'); | |
23 } | |
24 $blocks = array(); | |
25 if ($admin = db_fetch_array(db_query("SELECT menu_name, mlid FROM {menu_links} WHERE link_path = 'admin' AND module = 'system'"))) { | |
26 $result = db_query(" | |
27 SELECT m.*, ml.* | |
28 FROM {menu_links} ml | |
29 INNER JOIN {menu_router} m ON ml.router_path = m.path | |
30 WHERE ml.link_path != 'admin/help' AND menu_name = '%s' AND ml.plid = %d AND hidden = 0", $admin); | |
31 while ($item = db_fetch_array($result)) { | |
32 _menu_link_translate($item); | |
33 if (!$item['access']) { | |
34 continue; | |
35 } | |
36 // The link 'description' either derived from the hook_menu 'description' | |
37 // or entered by the user via menu module is saved as the title attribute. | |
38 if (!empty($item['localized_options']['attributes']['title'])) { | |
39 $item['description'] = $item['localized_options']['attributes']['title']; | |
40 } | |
41 $block = $item; | |
42 $block['content'] = ''; | |
43 if ($item['block_callback'] && function_exists($item['block_callback'])) { | |
44 $function = $item['block_callback']; | |
45 $block['content'] .= $function(); | |
46 } | |
47 $block['content'] .= theme('admin_block_content', system_admin_menu_block($item)); | |
48 // Prepare for sorting as in function _menu_tree_check_access(). | |
49 // The weight is offset so it is always positive, with a uniform 5-digits. | |
50 $blocks[(50000 + $item['weight']) .' '. $item['title'] .' '. $item['mlid']] = $block; | |
51 } | |
52 } | |
53 if ($blocks) { | |
54 ksort($blocks); | |
55 return theme('admin_page', $blocks); | |
56 } | |
57 else { | |
58 return t('You do not have any administrative items.'); | |
59 } | |
60 } | |
61 | |
62 | |
63 /** | |
64 * Provide a single block from the administration menu as a page. | |
65 * This function is often a destination for these blocks. | |
66 * For example, 'admin/content/types' needs to have a destination to be valid | |
67 * in the Drupal menu system, but too much information there might be | |
68 * hidden, so we supply the contents of the block. | |
69 * | |
70 * @return | |
71 * The output HTML. | |
72 */ | |
73 function system_admin_menu_block_page() { | |
74 $item = menu_get_item(); | |
75 if ($content = system_admin_menu_block($item)) { | |
76 $output = theme('admin_block_content', $content); | |
77 } | |
78 else { | |
79 $output = t('You do not have any administrative items.'); | |
80 } | |
81 return $output; | |
82 } | |
83 | |
84 /** | |
85 * Menu callback; Sets whether the admin menu is in compact mode or not. | |
86 * | |
87 * @param $mode | |
88 * Valid values are 'on' and 'off'. | |
89 */ | |
90 function system_admin_compact_page($mode = 'off') { | |
91 global $user; | |
92 user_save($user, array('admin_compact_mode' => ($mode == 'on'))); | |
93 drupal_goto('admin'); | |
94 } | |
95 | |
96 /** | |
97 * Menu callback; prints a listing of admin tasks for each installed module. | |
98 */ | |
99 function system_admin_by_module() { | |
100 | |
101 $modules = module_rebuild_cache(); | |
102 $menu_items = array(); | |
103 $help_arg = module_exists('help') ? drupal_help_arg() : FALSE; | |
104 | |
105 foreach ($modules as $file) { | |
106 $module = $file->name; | |
107 if ($module == 'help') { | |
108 continue; | |
109 } | |
110 | |
111 $admin_tasks = system_get_module_admin_tasks($module); | |
112 | |
113 // Only display a section if there are any available tasks. | |
114 if (count($admin_tasks)) { | |
115 | |
116 // Check for help links. | |
117 if ($help_arg && module_invoke($module, 'help', "admin/help#$module", $help_arg)) { | |
118 $admin_tasks[100] = l(t('Get help'), "admin/help/$module"); | |
119 } | |
120 | |
121 // Sort. | |
122 ksort($admin_tasks); | |
123 | |
124 $menu_items[$file->info['name']] = array($file->info['description'], $admin_tasks); | |
125 } | |
126 } | |
127 return theme('system_admin_by_module', $menu_items); | |
128 } | |
129 | |
130 /** | |
131 * Menu callback; displays a module's settings page. | |
132 */ | |
133 function system_settings_overview() { | |
134 // Check database setup if necessary | |
135 if (function_exists('db_check_setup') && empty($_POST)) { | |
136 db_check_setup(); | |
137 } | |
138 | |
139 $item = menu_get_item('admin/settings'); | |
140 $content = system_admin_menu_block($item); | |
141 | |
142 $output = theme('admin_block_content', $content); | |
143 | |
144 return $output; | |
145 } | |
146 | |
147 /** | |
148 * Form builder; This function allows selection of the theme to show in administration sections. | |
149 * | |
150 * @ingroup forms | |
151 * @see system_settings_form() | |
152 */ | |
153 function system_admin_theme_settings() { | |
154 $themes = system_theme_data(); | |
155 | |
156 uasort($themes, 'system_sort_modules_by_info_name'); | |
157 | |
158 $options[0] = '<'. t('System default') .'>'; | |
159 foreach ($themes as $theme) { | |
160 $options[$theme->name] = $theme->info['name']; | |
161 } | |
162 | |
163 $form['admin_theme'] = array( | |
164 '#type' => 'select', | |
165 '#options' => $options, | |
166 '#title' => t('Administration theme'), | |
167 '#description' => t('Choose which theme the administration pages should display in. If you choose "System default" the administration pages will use the same theme as the rest of the site.'), | |
168 '#default_value' => variable_get('admin_theme', '0'), | |
169 ); | |
170 | |
171 $form['node_admin_theme'] = array( | |
172 '#type' => 'checkbox', | |
173 '#title' => t('Use administration theme for content editing'), | |
174 '#description' => t('Use the administration theme when editing existing posts or creating new ones.'), | |
175 '#default_value' => variable_get('node_admin_theme', '0'), | |
176 ); | |
177 | |
178 $form['#submit'][] = 'system_admin_theme_submit'; | |
179 return system_settings_form($form); | |
180 } | |
181 | |
182 /** | |
183 * Menu callback; displays a listing of all themes. | |
184 * | |
185 * @ingroup forms | |
186 * @see system_themes_form_submit() | |
187 */ | |
188 function system_themes_form() { | |
189 | |
190 drupal_clear_css_cache(); | |
191 $themes = system_theme_data(); | |
192 | |
193 uasort($themes, 'system_sort_modules_by_info_name'); | |
194 | |
195 $status = array(); | |
196 $incompatible_core = array(); | |
197 $incompatible_php = array(); | |
198 | |
199 foreach ($themes as $theme) { | |
200 $screenshot = NULL; | |
201 $theme_key = $theme->name; | |
202 while ($theme_key) { | |
203 if (file_exists($themes[$theme_key]->info['screenshot'])) { | |
204 $screenshot = $themes[$theme_key]->info['screenshot']; | |
205 break; | |
206 } | |
207 $theme_key = isset($themes[$theme_key]->info['base theme']) ? $themes[$theme_key]->info['base theme'] : NULL; | |
208 } | |
209 $screenshot = $screenshot ? theme('image', $screenshot, t('Screenshot for %theme theme', array('%theme' => $theme->info['name'])), '', array('class' => 'screenshot'), FALSE) : t('no screenshot'); | |
210 | |
211 $form[$theme->name]['screenshot'] = array('#value' => $screenshot); | |
212 $form[$theme->name]['info'] = array( | |
213 '#type' => 'value', | |
214 '#value' => $theme->info, | |
215 ); | |
216 $options[$theme->name] = ''; | |
217 | |
218 if (!empty($theme->status) || $theme->name == variable_get('admin_theme', '0')) { | |
219 $form[$theme->name]['operations'] = array('#value' => l(t('configure'), 'admin/build/themes/settings/'. $theme->name) ); | |
220 } | |
221 else { | |
222 // Dummy element for drupal_render. Cleaner than adding a check in the theme function. | |
223 $form[$theme->name]['operations'] = array(); | |
224 } | |
225 if (!empty($theme->status)) { | |
226 $status[] = $theme->name; | |
227 } | |
228 else { | |
229 // Ensure this theme is compatible with this version of core. | |
230 if (!isset($theme->info['core']) || $theme->info['core'] != DRUPAL_CORE_COMPATIBILITY) { | |
231 $incompatible_core[] = $theme->name; | |
232 } | |
233 if (version_compare(phpversion(), $theme->info['php']) < 0) { | |
234 $incompatible_php[$theme->name] = $theme->info['php']; | |
235 } | |
236 } | |
237 } | |
238 | |
239 $form['status'] = array( | |
240 '#type' => 'checkboxes', | |
241 '#options' => $options, | |
242 '#default_value' => $status, | |
243 '#incompatible_themes_core' => drupal_map_assoc($incompatible_core), | |
244 '#incompatible_themes_php' => $incompatible_php, | |
245 ); | |
246 $form['theme_default'] = array( | |
247 '#type' => 'radios', | |
248 '#options' => $options, | |
249 '#default_value' => variable_get('theme_default', 'garland'), | |
250 ); | |
251 $form['buttons']['submit'] = array( | |
252 '#type' => 'submit', | |
253 '#value' => t('Save configuration'), | |
254 ); | |
255 $form['buttons']['reset'] = array( | |
256 '#type' => 'submit', | |
257 '#value' => t('Reset to defaults'), | |
258 ); | |
259 return $form; | |
260 } | |
261 | |
262 /** | |
263 * Process system_themes_form form submissions. | |
264 */ | |
265 function system_themes_form_submit($form, &$form_state) { | |
266 | |
267 // Store list of previously enabled themes and disable all themes | |
268 $old_theme_list = $new_theme_list = array(); | |
269 foreach (list_themes() as $theme) { | |
270 if ($theme->status) { | |
271 $old_theme_list[] = $theme->name; | |
272 } | |
273 } | |
274 db_query("UPDATE {system} SET status = 0 WHERE type = 'theme'"); | |
275 | |
276 if ($form_state['values']['op'] == t('Save configuration')) { | |
277 if (is_array($form_state['values']['status'])) { | |
278 foreach ($form_state['values']['status'] as $key => $choice) { | |
279 // Always enable the default theme, despite its status checkbox being checked: | |
280 if ($choice || $form_state['values']['theme_default'] == $key) { | |
281 system_initialize_theme_blocks($key); | |
282 $new_theme_list[] = $key; | |
283 db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' and name = '%s'", $key); | |
284 } | |
285 } | |
286 } | |
287 if (($admin_theme = variable_get('admin_theme', '0')) != '0' && $admin_theme != $form_state['values']['theme_default']) { | |
288 drupal_set_message(t('Please note that the <a href="!admin_theme_page">administration theme</a> is still set to the %admin_theme theme; consequently, the theme on this page remains unchanged. All non-administrative sections of the site, however, will show the selected %selected_theme theme by default.', array( | |
289 '!admin_theme_page' => url('admin/settings/admin'), | |
290 '%admin_theme' => $admin_theme, | |
291 '%selected_theme' => $form_state['values']['theme_default'], | |
292 ))); | |
293 } | |
294 variable_set('theme_default', $form_state['values']['theme_default']); | |
295 } | |
296 else { | |
297 // Revert to defaults: only Garland is enabled. | |
298 variable_del('theme_default'); | |
299 db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' AND name = 'garland'"); | |
300 $new_theme_list = array('garland'); | |
301 } | |
302 | |
303 list_themes(TRUE); | |
304 menu_rebuild(); | |
305 drupal_rebuild_theme_registry(); | |
306 drupal_set_message(t('The configuration options have been saved.')); | |
307 $form_state['redirect'] = 'admin/build/themes'; | |
308 | |
309 // Notify locale module about new themes being enabled, so translations can | |
310 // be imported. This might start a batch, and only return to the redirect | |
311 // path after that. | |
312 module_invoke('locale', 'system_update', array_diff($new_theme_list, $old_theme_list)); | |
313 | |
314 return; | |
315 } | |
316 | |
317 /** | |
318 * Form builder; display theme configuration for entire site and individual themes. | |
319 * | |
320 * @param $key | |
321 * A theme name. | |
322 * @return | |
323 * The form structure. | |
324 * @ingroup forms | |
325 * @see system_theme_settings_submit() | |
326 */ | |
327 function system_theme_settings(&$form_state, $key = '') { | |
328 $directory_path = file_directory_path(); | |
329 file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path'); | |
330 | |
331 // Default settings are defined in theme_get_settings() in includes/theme.inc | |
332 if ($key) { | |
333 $settings = theme_get_settings($key); | |
334 $var = str_replace('/', '_', 'theme_'. $key .'_settings'); | |
335 $themes = system_theme_data(); | |
336 $features = $themes[$key]->info['features']; | |
337 } | |
338 else { | |
339 $settings = theme_get_settings(''); | |
340 $var = 'theme_settings'; | |
341 } | |
342 | |
343 $form['var'] = array('#type' => 'hidden', '#value' => $var); | |
344 | |
345 // Check for a new uploaded logo, and use that instead. | |
346 if ($file = file_save_upload('logo_upload', array('file_validate_is_image' => array()))) { | |
347 $parts = pathinfo($file->filename); | |
348 $filename = ($key) ? str_replace('/', '_', $key) .'_logo.'. $parts['extension'] : 'logo.'. $parts['extension']; | |
349 | |
350 // The image was saved using file_save_upload() and was added to the | |
351 // files table as a temporary file. We'll make a copy and let the garbage | |
352 // collector delete the original upload. | |
353 if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) { | |
354 $_POST['default_logo'] = 0; | |
355 $_POST['logo_path'] = $file->filepath; | |
356 $_POST['toggle_logo'] = 1; | |
357 } | |
358 } | |
359 | |
360 // Check for a new uploaded favicon, and use that instead. | |
361 if ($file = file_save_upload('favicon_upload')) { | |
362 $parts = pathinfo($file->filename); | |
363 $filename = ($key) ? str_replace('/', '_', $key) .'_favicon.'. $parts['extension'] : 'favicon.'. $parts['extension']; | |
364 | |
365 // The image was saved using file_save_upload() and was added to the | |
366 // files table as a temporary file. We'll make a copy and let the garbage | |
367 // collector delete the original upload. | |
368 if (file_copy($file, $filename)) { | |
369 $_POST['default_favicon'] = 0; | |
370 $_POST['favicon_path'] = $file->filepath; | |
371 $_POST['toggle_favicon'] = 1; | |
372 } | |
373 } | |
374 | |
375 // Toggle settings | |
376 $toggles = array( | |
377 'logo' => t('Logo'), | |
378 'name' => t('Site name'), | |
379 'slogan' => t('Site slogan'), | |
380 'mission' => t('Mission statement'), | |
381 'node_user_picture' => t('User pictures in posts'), | |
382 'comment_user_picture' => t('User pictures in comments'), | |
383 'search' => t('Search box'), | |
384 'favicon' => t('Shortcut icon'), | |
385 'primary_links' => t('Primary links'), | |
386 'secondary_links' => t('Secondary links'), | |
387 ); | |
388 | |
389 // Some features are not always available | |
390 $disabled = array(); | |
391 if (!variable_get('user_pictures', 0)) { | |
392 $disabled['toggle_node_user_picture'] = TRUE; | |
393 $disabled['toggle_comment_user_picture'] = TRUE; | |
394 } | |
395 if (!module_exists('search')) { | |
396 $disabled['toggle_search'] = TRUE; | |
397 } | |
398 | |
399 $form['theme_settings'] = array( | |
400 '#type' => 'fieldset', | |
401 '#title' => t('Toggle display'), | |
402 '#description' => t('Enable or disable the display of certain page elements.'), | |
403 ); | |
404 foreach ($toggles as $name => $title) { | |
405 if ((!$key) || in_array($name, $features)) { | |
406 $form['theme_settings']['toggle_'. $name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $settings['toggle_'. $name]); | |
407 // Disable checkboxes for features not supported in the current configuration. | |
408 if (isset($disabled['toggle_'. $name])) { | |
409 $form['theme_settings']['toggle_'. $name]['#disabled'] = TRUE; | |
410 } | |
411 } | |
412 } | |
413 | |
414 // System wide only settings. | |
415 if (!$key) { | |
416 // Create neat 2-column layout for the toggles | |
417 $form['theme_settings'] += array( | |
418 '#prefix' => '<div class="theme-settings-left">', | |
419 '#suffix' => '</div>', | |
420 ); | |
421 | |
422 // Toggle node display. | |
423 $node_types = node_get_types('names'); | |
424 if ($node_types) { | |
425 $form['node_info'] = array( | |
426 '#type' => 'fieldset', | |
427 '#title' => t('Display post information on'), | |
428 '#description' => t('Enable or disable the <em>submitted by Username on date</em> text when displaying posts of the following type.'), | |
429 '#prefix' => '<div class="theme-settings-right">', | |
430 '#suffix' => '</div>', | |
431 ); | |
432 foreach ($node_types as $type => $name) { | |
433 $form['node_info']["toggle_node_info_$type"] = array('#type' => 'checkbox', '#title' => check_plain($name), '#default_value' => $settings["toggle_node_info_$type"]); | |
434 } | |
435 } | |
436 } | |
437 elseif (!element_children($form['theme_settings'])) { | |
438 // If there is no element in the theme settings fieldset then do not show | |
439 // it -- but keep it in the form if another module wants to alter. | |
440 $form['theme_settings']['#access'] = FALSE; | |
441 } | |
442 | |
443 // Logo settings | |
444 if ((!$key) || in_array('logo', $features)) { | |
445 $form['logo'] = array( | |
446 '#type' => 'fieldset', | |
447 '#title' => t('Logo image settings'), | |
448 '#description' => t('If toggled on, the following logo will be displayed.'), | |
449 '#attributes' => array('class' => 'theme-settings-bottom'), | |
450 ); | |
451 $form['logo']["default_logo"] = array( | |
452 '#type' => 'checkbox', | |
453 '#title' => t('Use the default logo'), | |
454 '#default_value' => $settings['default_logo'], | |
455 '#tree' => FALSE, | |
456 '#description' => t('Check here if you want the theme to use the logo supplied with it.') | |
457 ); | |
458 $form['logo']['logo_path'] = array( | |
459 '#type' => 'textfield', | |
460 '#title' => t('Path to custom logo'), | |
461 '#default_value' => $settings['logo_path'], | |
462 '#description' => t('The path to the file you would like to use as your logo file instead of the default logo.')); | |
463 | |
464 $form['logo']['logo_upload'] = array( | |
465 '#type' => 'file', | |
466 '#title' => t('Upload logo image'), | |
467 '#maxlength' => 40, | |
468 '#description' => t("If you don't have direct file access to the server, use this field to upload your logo.") | |
469 ); | |
470 } | |
471 | |
472 if ((!$key) || in_array('favicon', $features)) { | |
473 $form['favicon'] = array( | |
474 '#type' => 'fieldset', | |
475 '#title' => t('Shortcut icon settings'), | |
476 '#description' => t("Your shortcut icon, or 'favicon', is displayed in the address bar and bookmarks of most browsers.") | |
477 ); | |
478 $form['favicon']['default_favicon'] = array( | |
479 '#type' => 'checkbox', | |
480 '#title' => t('Use the default shortcut icon.'), | |
481 '#default_value' => $settings['default_favicon'], | |
482 '#description' => t('Check here if you want the theme to use the default shortcut icon.') | |
483 ); | |
484 $form['favicon']['favicon_path'] = array( | |
485 '#type' => 'textfield', | |
486 '#title' => t('Path to custom icon'), | |
487 '#default_value' => $settings['favicon_path'], | |
488 '#description' => t('The path to the image file you would like to use as your custom shortcut icon.') | |
489 ); | |
490 | |
491 $form['favicon']['favicon_upload'] = array( | |
492 '#type' => 'file', | |
493 '#title' => t('Upload icon image'), | |
494 '#description' => t("If you don't have direct file access to the server, use this field to upload your shortcut icon.") | |
495 ); | |
496 } | |
497 | |
498 if ($key) { | |
499 // Include the theme's theme-settings.php file | |
500 $filename = './'. str_replace("/$key.info", '', $themes[$key]->filename) .'/theme-settings.php'; | |
501 if (!file_exists($filename) and !empty($themes[$key]->info['base theme'])) { | |
502 // If the theme doesn't have a theme-settings.php file, use the base theme's. | |
503 $base = $themes[$key]->info['base theme']; | |
504 $filename = './'. str_replace("/$base.info", '', $themes[$base]->filename) .'/theme-settings.php'; | |
505 } | |
506 if (file_exists($filename)) { | |
507 require_once $filename; | |
508 } | |
509 | |
510 // Call engine-specific settings. | |
511 $function = $themes[$key]->prefix .'_engine_settings'; | |
512 if (function_exists($function)) { | |
513 $group = $function($settings); | |
514 if (!empty($group)) { | |
515 $form['engine_specific'] = array('#type' => 'fieldset', '#title' => t('Theme-engine-specific settings'), '#description' => t('These settings only exist for all the templates and styles based on the %engine theme engine.', array('%engine' => $themes[$key]->prefix))); | |
516 $form['engine_specific'] = array_merge($form['engine_specific'], $group); | |
517 } | |
518 } | |
519 // Call theme-specific settings. | |
520 $function = $key .'_settings'; | |
521 if (!function_exists($function)) { | |
522 $function = $themes[$key]->prefix .'_settings'; | |
523 } | |
524 if (function_exists($function)) { | |
525 $group = $function($settings); | |
526 if (!empty($group)) { | |
527 $form['theme_specific'] = array('#type' => 'fieldset', '#title' => t('Theme-specific settings'), '#description' => t('These settings only exist for the %theme theme and all the styles based on it.', array('%theme' => $themes[$key]->info['name']))); | |
528 $form['theme_specific'] = array_merge($form['theme_specific'], $group); | |
529 } | |
530 } | |
531 } | |
532 $form['#attributes'] = array('enctype' => 'multipart/form-data'); | |
533 | |
534 $form = system_settings_form($form); | |
535 // We don't want to call system_settings_form_submit(), so change #submit. | |
536 $form['#submit'] = array('system_theme_settings_submit'); | |
537 return $form; | |
538 } | |
539 | |
540 /** | |
541 * Process system_theme_settings form submissions. | |
542 */ | |
543 function system_theme_settings_submit($form, &$form_state) { | |
544 $values = $form_state['values']; | |
545 $key = $values['var']; | |
546 | |
547 if ($values['op'] == t('Reset to defaults')) { | |
548 variable_del($key); | |
549 drupal_set_message(t('The configuration options have been reset to their default values.')); | |
550 } | |
551 else { | |
552 // Exclude unnecessary elements before saving. | |
553 unset($values['var'], $values['submit'], $values['reset'], $values['form_id'], $values['op'], $values['form_build_id'], $values['form_token']); | |
554 variable_set($key, $values); | |
555 drupal_set_message(t('The configuration options have been saved.')); | |
556 } | |
557 | |
558 cache_clear_all(); | |
559 } | |
560 | |
561 /** | |
562 * Recursively check compatibility. | |
563 * | |
564 * @param $incompatible | |
565 * An associative array which at the end of the check contains all incompatible files as the keys, their values being TRUE. | |
566 * @param $files | |
567 * The set of files that will be tested. | |
568 * @param $file | |
569 * The file at which the check starts. | |
570 * @return | |
571 * Returns TRUE if an incompatible file is found, NULL (no return value) otherwise. | |
572 */ | |
573 function _system_is_incompatible(&$incompatible, $files, $file) { | |
574 static $seen; | |
575 // We need to protect ourselves in case of a circular dependency. | |
576 if (isset($seen[$file->name])) { | |
577 return isset($incompatible[$file->name]); | |
578 } | |
579 $seen[$file->name] = TRUE; | |
580 if (isset($incompatible[$file->name])) { | |
581 return TRUE; | |
582 } | |
583 // The 'dependencies' key in .info files was a string in Drupal 5, but changed | |
584 // to an array in Drupal 6. If it is not an array, the module is not | |
585 // compatible and we can skip the check below which requires an array. | |
586 if (!is_array($file->info['dependencies'])) { | |
587 $file->info['dependencies'] = array(); | |
588 $incompatible[$file->name] = TRUE; | |
589 return TRUE; | |
590 } | |
591 // Recursively traverse the dependencies, looking for incompatible modules | |
592 foreach ($file->info['dependencies'] as $dependency) { | |
593 if (isset($files[$dependency]) && _system_is_incompatible($incompatible, $files, $files[$dependency])) { | |
594 $incompatible[$file->name] = TRUE; | |
595 return TRUE; | |
596 } | |
597 } | |
598 } | |
599 | |
600 /** | |
601 * Menu callback; provides module enable/disable interface. | |
602 * | |
603 * Modules can be enabled or disabled and set for throttling if the throttle module is enabled. | |
604 * The list of modules gets populated by module.info files, which contain each module's name, | |
605 * description and dependencies. | |
606 * @see drupal_parse_info_file for information on module.info descriptors. | |
607 * | |
608 * Dependency checking is performed to ensure that a module cannot be enabled if the module has | |
609 * disabled dependencies and also to ensure that the module cannot be disabled if the module has | |
610 * enabled dependents. | |
611 * | |
612 * @param $form_state | |
613 * An associative array containing the current state of the form. | |
614 * @ingroup forms | |
615 * @see theme_system_modules() | |
616 * @see system_modules_submit() | |
617 * @return | |
618 * The form array. | |
619 */ | |
620 function system_modules($form_state = array()) { | |
621 drupal_rebuild_theme_registry(); | |
622 node_types_rebuild(); | |
623 menu_rebuild(); | |
624 cache_clear_all('schema', 'cache'); | |
625 // Get current list of modules. | |
626 $files = module_rebuild_cache(); | |
627 | |
628 uasort($files, 'system_sort_modules_by_info_name'); | |
629 | |
630 if (!empty($form_state['storage'])) { | |
631 return system_modules_confirm_form($files, $form_state['storage']); | |
632 } | |
633 $dependencies = array(); | |
634 | |
635 // Store module list for validation callback. | |
636 $form['validation_modules'] = array('#type' => 'value', '#value' => $files); | |
637 | |
638 // Create storage for disabled modules as browser will disable checkboxes. | |
639 $form['disabled_modules'] = array('#type' => 'value', '#value' => array()); | |
640 | |
641 // Traverse the files, checking for compatibility | |
642 $incompatible_core = array(); | |
643 $incompatible_php = array(); | |
644 foreach ($files as $filename => $file) { | |
645 // Ensure this module is compatible with this version of core. | |
646 if (!isset($file->info['core']) || $file->info['core'] != DRUPAL_CORE_COMPATIBILITY) { | |
647 $incompatible_core[$file->name] = $file->name; | |
648 } | |
649 // Ensure this module is compatible with the currently installed version of PHP. | |
650 if (version_compare(phpversion(), $file->info['php']) < 0) { | |
651 $incompatible_php[$file->name] = $file->info['php']; | |
652 } | |
653 } | |
654 | |
655 // Array for disabling checkboxes in callback system_module_disable. | |
656 $disabled = array(); | |
657 $throttle = array(); | |
658 // Traverse the files retrieved and build the form. | |
659 foreach ($files as $filename => $file) { | |
660 $form['name'][$filename] = array('#value' => $file->info['name']); | |
661 $form['version'][$filename] = array('#value' => $file->info['version']); | |
662 $form['description'][$filename] = array('#value' => t($file->info['description'])); | |
663 $options[$filename] = ''; | |
664 // Ensure this module is compatible with this version of core and php. | |
665 if (_system_is_incompatible($incompatible_core, $files, $file) || _system_is_incompatible($incompatible_php, $files, $file)) { | |
666 $disabled[] = $file->name; | |
667 // Nothing else in this loop matters, so move to the next module. | |
668 continue; | |
669 } | |
670 if ($file->status) { | |
671 $status[] = $file->name; | |
672 } | |
673 if ($file->throttle) { | |
674 $throttle[] = $file->name; | |
675 } | |
676 | |
677 $dependencies = array(); | |
678 // Check for missing dependencies. | |
679 if (is_array($file->info['dependencies'])) { | |
680 foreach ($file->info['dependencies'] as $dependency) { | |
681 if (!isset($files[$dependency]) || !$files[$dependency]->status) { | |
682 if (isset($files[$dependency])) { | |
683 $dependencies[] = $files[$dependency]->info['name'] . t(' (<span class="admin-disabled">disabled</span>)'); | |
684 } | |
685 else { | |
686 $dependencies[] = drupal_ucfirst($dependency) . t(' (<span class="admin-missing">missing</span>)'); | |
687 $disabled[] = $filename; | |
688 $form['disabled_modules']['#value'][$filename] = FALSE; | |
689 } | |
690 } | |
691 else { | |
692 $dependencies[] = $files[$dependency]->info['name'] . t(' (<span class="admin-enabled">enabled</span>)'); | |
693 } | |
694 } | |
695 | |
696 // Add text for dependencies. | |
697 if (!empty($dependencies)) { | |
698 $form['description'][$filename]['dependencies'] = array( | |
699 '#value' => t('Depends on: !dependencies', array('!dependencies' => implode(', ', $dependencies))), | |
700 '#prefix' => '<div class="admin-dependencies">', | |
701 '#suffix' => '</div>', | |
702 ); | |
703 } | |
704 } | |
705 | |
706 // Mark dependents disabled so user can not remove modules being depended on. | |
707 $dependents = array(); | |
708 foreach ($file->info['dependents'] as $dependent) { | |
709 if ($files[$dependent]->status == 1) { | |
710 $dependents[] = $files[$dependent]->info['name'] . t(' (<span class="admin-enabled">enabled</span>)'); | |
711 $disabled[] = $filename; | |
712 $form['disabled_modules']['#value'][$filename] = TRUE; | |
713 } | |
714 else { | |
715 $dependents[] = $files[$dependent]->info['name'] . t(' (<span class="admin-disabled">disabled</span>)'); | |
716 } | |
717 } | |
718 | |
719 // Add text for enabled dependents. | |
720 if (!empty($dependents)) { | |
721 $form['description'][$filename]['required'] = array( | |
722 '#value' => t('Required by: !required', array('!required' => implode(', ', $dependents))), | |
723 '#prefix' => '<div class="admin-required">', | |
724 '#suffix' => '</div>', | |
725 ); | |
726 } | |
727 } | |
728 | |
729 $modules_required = drupal_required_modules(); | |
730 // Merge in required modules. | |
731 foreach ($modules_required as $required) { | |
732 $disabled[] = $required; | |
733 $form['disabled_modules']['#value'][$required] = TRUE; | |
734 } | |
735 | |
736 // Handle status checkboxes, including overriding | |
737 // the generated checkboxes for required modules. | |
738 $form['status'] = array( | |
739 '#type' => 'checkboxes', | |
740 '#default_value' => $status, | |
741 '#options' => $options, | |
742 '#process' => array( | |
743 'expand_checkboxes', | |
744 'system_modules_disable', | |
745 ), | |
746 '#disabled_modules' => $disabled, | |
747 '#incompatible_modules_core' => $incompatible_core, | |
748 '#incompatible_modules_php' => $incompatible_php, | |
749 ); | |
750 | |
751 // Handle throttle checkboxes, including overriding the | |
752 // generated checkboxes for required modules. | |
753 if (module_exists('throttle')) { | |
754 $form['throttle'] = array( | |
755 '#type' => 'checkboxes', | |
756 '#default_value' => $throttle, | |
757 '#options' => $options, | |
758 '#process' => array( | |
759 'expand_checkboxes', | |
760 'system_modules_disable', | |
761 ), | |
762 '#disabled_modules' => array_merge($modules_required, array('throttle')), | |
763 ); | |
764 } | |
765 | |
766 $form['buttons']['submit'] = array( | |
767 '#type' => 'submit', | |
768 '#value' => t('Save configuration'), | |
769 ); | |
770 $form['#action'] = url('admin/build/modules/list/confirm'); | |
771 | |
772 return $form; | |
773 } | |
774 | |
775 /** | |
776 * Array sorting callback; sorts modules or themes by their name. | |
777 */ | |
778 function system_sort_modules_by_info_name($a, $b) { | |
779 return strcasecmp($a->info['name'], $b->info['name']); | |
780 } | |
781 | |
782 /** | |
783 * Form process callback function to disable check boxes. | |
784 * | |
785 * @param $form | |
786 * The form structure. | |
787 * @param $edit | |
788 * Not used. | |
789 * @ingroup forms | |
790 * @return | |
791 * The form structure. | |
792 */ | |
793 function system_modules_disable($form, $edit) { | |
794 foreach ($form['#disabled_modules'] as $key) { | |
795 $form[$key]['#attributes']['disabled'] = 'disabled'; | |
796 } | |
797 return $form; | |
798 } | |
799 | |
800 /** | |
801 * Display confirmation form for dependencies. | |
802 * | |
803 * @param $modules | |
804 * Array of module file objects as returned from module_rebuild_cache(). | |
805 * @param $storage | |
806 * The contents of $form_state['storage']; an array with two | |
807 * elements: the list of dependencies and the list of status | |
808 * form field values from the previous screen. | |
809 * @ingroup forms | |
810 */ | |
811 function system_modules_confirm_form($modules, $storage) { | |
812 $form = array(); | |
813 $items = array(); | |
814 | |
815 list($dependencies, $status) = $storage; | |
816 $form['validation_modules'] = array('#type' => 'value', '#value' => $modules); | |
817 $form['status']['#tree'] = TRUE; | |
818 // Remember list of modules selected on the module listing page already. | |
819 foreach ($status as $key => $choice) { | |
820 $form['status'][$key] = array('#type' => 'value', '#value' => $choice); | |
821 } | |
822 foreach ($dependencies as $name => $missing_dependencies) { | |
823 $form['status'][$name] = array('#type' => 'hidden', '#value' => 1); | |
824 foreach ($missing_dependencies as $k => $dependency) { | |
825 $form['status'][$dependency] = array('#type' => 'hidden', '#value' => 1); | |
826 $info = $modules[$dependency]->info; | |
827 $missing_dependencies[$k] = $info['name'] ? $info['name'] : drupal_ucfirst($dependency); | |
828 } | |
829 $t_argument = array( | |
830 '@module' => $modules[$name]->info['name'], | |
831 '@dependencies' => implode(', ', $missing_dependencies), | |
832 ); | |
833 $items[] = format_plural(count($missing_dependencies), 'You must enable the @dependencies module to install @module.', 'You must enable the @dependencies modules to install @module.', $t_argument); | |
834 } | |
835 $form['text'] = array('#value' => theme('item_list', $items)); | |
836 | |
837 if ($form) { | |
838 // Set some default form values | |
839 $form = confirm_form( | |
840 $form, | |
841 t('Some required modules must be enabled'), | |
842 'admin/build/modules', | |
843 t('Would you like to continue with enabling the above?'), | |
844 t('Continue'), | |
845 t('Cancel')); | |
846 return $form; | |
847 } | |
848 } | |
849 | |
850 /** | |
851 * Submit callback; handles modules form submission. | |
852 */ | |
853 function system_modules_submit($form, &$form_state) { | |
854 include_once './includes/install.inc'; | |
855 $new_modules = array(); | |
856 | |
857 // If we are coming from the confirm form... | |
858 if (!isset($form_state['storage'])) { | |
859 // Merge in disabled active modules since they should be enabled. | |
860 // They don't appear because disabled checkboxes are not submitted | |
861 // by browsers. | |
862 $form_state['values']['status'] = array_merge($form_state['values']['status'], $form_state['values']['disabled_modules']); | |
863 | |
864 // Check values for dependency that we can't install. | |
865 if ($dependencies = system_module_build_dependencies($form_state['values']['validation_modules'], $form_state['values'])) { | |
866 // These are the modules that depend on existing modules. | |
867 foreach (array_keys($dependencies) as $name) { | |
868 $form_state['values']['status'][$name] = 0; | |
869 } | |
870 } | |
871 } | |
872 else { | |
873 $dependencies = NULL; | |
874 } | |
875 | |
876 // Update throttle settings, if present | |
877 if (isset($form_state['values']['throttle'])) { | |
878 foreach ($form_state['values']['throttle'] as $key => $choice) { | |
879 db_query("UPDATE {system} SET throttle = %d WHERE type = 'module' and name = '%s'", $choice ? 1 : 0, $key); | |
880 } | |
881 } | |
882 | |
883 // If there where unmet dependencies and they haven't confirmed don't process | |
884 // the submission yet. Store the form submission data needed later. | |
885 if ($dependencies) { | |
886 if (!isset($form_state['values']['confirm'])) { | |
887 $form_state['storage'] = array($dependencies, $form_state['values']['status']); | |
888 return; | |
889 } | |
890 else { | |
891 $form_state['values']['status'] = array_merge($form_state['values']['status'], $form_storage[1]); | |
892 } | |
893 } | |
894 // If we have no dependencies, or the dependencies are confirmed | |
895 // to be installed, we don't need the temporary storage anymore. | |
896 unset($form_state['storage']); | |
897 | |
898 $enable_modules = array(); | |
899 $disable_modules = array(); | |
900 foreach ($form_state['values']['status'] as $key => $choice) { | |
901 if ($choice) { | |
902 if (drupal_get_installed_schema_version($key) == SCHEMA_UNINSTALLED) { | |
903 $new_modules[] = $key; | |
904 } | |
905 else { | |
906 $enable_modules[] = $key; | |
907 } | |
908 } | |
909 else { | |
910 $disable_modules[] = $key; | |
911 } | |
912 } | |
913 | |
914 $old_module_list = module_list(); | |
915 | |
916 if (!empty($enable_modules)) { | |
917 module_enable($enable_modules); | |
918 } | |
919 if (!empty($disable_modules)) { | |
920 module_disable($disable_modules); | |
921 } | |
922 | |
923 // Install new modules. | |
924 foreach ($new_modules as $key => $module) { | |
925 if (!drupal_check_module($module)) { | |
926 unset($new_modules[$key]); | |
927 } | |
928 } | |
929 drupal_install_modules($new_modules); | |
930 | |
931 $current_module_list = module_list(TRUE, FALSE); | |
932 if ($old_module_list != $current_module_list) { | |
933 drupal_set_message(t('The configuration options have been saved.')); | |
934 } | |
935 | |
936 drupal_clear_css_cache(); | |
937 drupal_clear_js_cache(); | |
938 | |
939 $form_state['redirect'] = 'admin/build/modules'; | |
940 | |
941 // Notify locale module about module changes, so translations can be | |
942 // imported. This might start a batch, and only return to the redirect | |
943 // path after that. | |
944 module_invoke('locale', 'system_update', $new_modules); | |
945 | |
946 // Synchronize to catch any actions that were added or removed. | |
947 actions_synchronize(); | |
948 | |
949 return; | |
950 } | |
951 | |
952 | |
953 /** | |
954 * Generate a list of dependencies for modules that are going to be switched on. | |
955 * | |
956 * @param $modules | |
957 * The list of modules to check. | |
958 * @param $form_values | |
959 * Submitted form values used to determine what modules have been enabled. | |
960 * @return | |
961 * An array of dependencies. | |
962 */ | |
963 function system_module_build_dependencies($modules, $form_values) { | |
964 static $dependencies; | |
965 | |
966 if (!isset($dependencies) && isset($form_values)) { | |
967 $dependencies = array(); | |
968 foreach ($modules as $name => $module) { | |
969 // If the module is disabled, will be switched on and it has dependencies. | |
970 if (!$module->status && $form_values['status'][$name] && isset($module->info['dependencies'])) { | |
971 foreach ($module->info['dependencies'] as $dependency) { | |
972 if (!$form_values['status'][$dependency] && isset($modules[$dependency])) { | |
973 if (!isset($dependencies[$name])) { | |
974 $dependencies[$name] = array(); | |
975 } | |
976 $dependencies[$name][] = $dependency; | |
977 } | |
978 } | |
979 } | |
980 } | |
981 } | |
982 return $dependencies; | |
983 } | |
984 | |
985 /** | |
986 * Uninstall functions | |
987 */ | |
988 | |
989 /** | |
990 * Builds a form of currently disabled modules. | |
991 * | |
992 * @ingroup forms | |
993 * @see system_modules_uninstall_validate() | |
994 * @see system_modules_uninstall_submit() | |
995 * @param $form_state['values'] | |
996 * Submitted form values. | |
997 * @return | |
998 * A form array representing the currently disabled modules. | |
999 */ | |
1000 function system_modules_uninstall($form_state = NULL) { | |
1001 // Make sure the install API is available. | |
1002 include_once './includes/install.inc'; | |
1003 | |
1004 // Display the confirm form if any modules have been submitted. | |
1005 if (isset($form_state) && $confirm_form = system_modules_uninstall_confirm_form($form_state['storage'])) { | |
1006 return $confirm_form; | |
1007 } | |
1008 | |
1009 $form = array(); | |
1010 | |
1011 // Pull all disabled modules from the system table. | |
1012 $disabled_modules = db_query("SELECT name, filename, info FROM {system} WHERE type = 'module' AND status = 0 AND schema_version > %d ORDER BY name", SCHEMA_UNINSTALLED); | |
1013 while ($module = db_fetch_object($disabled_modules)) { | |
1014 | |
1015 // Grab the module info | |
1016 $info = unserialize($module->info); | |
1017 | |
1018 // Load the .install file, and check for an uninstall hook. | |
1019 // If the hook exists, the module can be uninstalled. | |
1020 module_load_install($module->name); | |
1021 if (module_hook($module->name, 'uninstall')) { | |
1022 $form['modules'][$module->name]['name'] = array('#value' => $info['name'] ? $info['name'] : $module->name); | |
1023 $form['modules'][$module->name]['description'] = array('#value' => t($info['description'])); | |
1024 $options[$module->name] = ''; | |
1025 } | |
1026 } | |
1027 | |
1028 // Only build the rest of the form if there are any modules available to uninstall. | |
1029 if (!empty($options)) { | |
1030 $form['uninstall'] = array( | |
1031 '#type' => 'checkboxes', | |
1032 '#options' => $options, | |
1033 ); | |
1034 $form['buttons']['submit'] = array( | |
1035 '#type' => 'submit', | |
1036 '#value' => t('Uninstall'), | |
1037 ); | |
1038 $form['#action'] = url('admin/build/modules/uninstall/confirm'); | |
1039 } | |
1040 else { | |
1041 $form['modules'] = array(); | |
1042 } | |
1043 | |
1044 return $form; | |
1045 } | |
1046 | |
1047 /** | |
1048 * Confirm uninstall of selected modules. | |
1049 * | |
1050 * @ingroup forms | |
1051 * @param $storage | |
1052 * An associative array of modules selected to be uninstalled. | |
1053 * @return | |
1054 * A form array representing modules to confirm. | |
1055 */ | |
1056 function system_modules_uninstall_confirm_form($storage) { | |
1057 // Nothing to build. | |
1058 if (!isset($storage)) { | |
1059 return; | |
1060 } | |
1061 | |
1062 // Construct the hidden form elements and list items. | |
1063 foreach (array_filter($storage['uninstall']) as $module => $value) { | |
1064 $info = drupal_parse_info_file(dirname(drupal_get_filename('module', $module)) .'/'. $module .'.info'); | |
1065 $uninstall[] = $info['name']; | |
1066 $form['uninstall'][$module] = array('#type' => 'hidden', | |
1067 '#value' => 1, | |
1068 ); | |
1069 } | |
1070 | |
1071 // Display a confirm form if modules have been selected. | |
1072 if (isset($uninstall)) { | |
1073 $form['#confirmed'] = TRUE; | |
1074 $form['uninstall']['#tree'] = TRUE; | |
1075 $form['modules'] = array('#value' => '<p>'. t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') .'</p>'. theme('item_list', $uninstall)); | |
1076 $form = confirm_form( | |
1077 $form, | |
1078 t('Confirm uninstall'), | |
1079 'admin/build/modules/uninstall', | |
1080 t('Would you like to continue with uninstalling the above?'), | |
1081 t('Uninstall'), | |
1082 t('Cancel')); | |
1083 return $form; | |
1084 } | |
1085 } | |
1086 | |
1087 /** | |
1088 * Validates the submitted uninstall form. | |
1089 */ | |
1090 function system_modules_uninstall_validate($form, &$form_state) { | |
1091 // Form submitted, but no modules selected. | |
1092 if (!count(array_filter($form_state['values']['uninstall']))) { | |
1093 drupal_set_message(t('No modules selected.'), 'error'); | |
1094 drupal_goto('admin/build/modules/uninstall'); | |
1095 } | |
1096 } | |
1097 | |
1098 /** | |
1099 * Processes the submitted uninstall form. | |
1100 */ | |
1101 function system_modules_uninstall_submit($form, &$form_state) { | |
1102 // Make sure the install API is available. | |
1103 include_once './includes/install.inc'; | |
1104 | |
1105 if (!empty($form['#confirmed'])) { | |
1106 // Call the uninstall routine for each selected module. | |
1107 foreach (array_filter($form_state['values']['uninstall']) as $module => $value) { | |
1108 drupal_uninstall_module($module); | |
1109 } | |
1110 drupal_set_message(t('The selected modules have been uninstalled.')); | |
1111 | |
1112 unset($form_state['storage']); | |
1113 $form_state['redirect'] = 'admin/build/modules/uninstall'; | |
1114 } | |
1115 else { | |
1116 $form_state['storage'] = $form_state['values']; | |
1117 } | |
1118 } | |
1119 | |
1120 /** | |
1121 * Form builder; The general site information form. | |
1122 * | |
1123 * @ingroup forms | |
1124 * @see system_settings_form() | |
1125 */ | |
1126 function system_site_information_settings() { | |
1127 $form['site_name'] = array( | |
1128 '#type' => 'textfield', | |
1129 '#title' => t('Name'), | |
1130 '#default_value' => variable_get('site_name', 'Drupal'), | |
1131 '#description' => t('The name of this website.'), | |
1132 '#required' => TRUE | |
1133 ); | |
1134 $form['site_mail'] = array( | |
1135 '#type' => 'textfield', | |
1136 '#title' => t('E-mail address'), | |
1137 '#default_value' => variable_get('site_mail', ini_get('sendmail_from')), | |
1138 '#description' => t("The <em>From</em> address in automated e-mails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this e-mail being flagged as spam.)"), | |
1139 '#required' => TRUE, | |
1140 ); | |
1141 $form['site_slogan'] = array( | |
1142 '#type' => 'textfield', | |
1143 '#title' => t('Slogan'), | |
1144 '#default_value' => variable_get('site_slogan', ''), | |
1145 '#description' => t("Your site's motto, tag line, or catchphrase (often displayed alongside the title of the site).") | |
1146 ); | |
1147 $form['site_mission'] = array( | |
1148 '#type' => 'textarea', | |
1149 '#title' => t('Mission'), | |
1150 '#default_value' => variable_get('site_mission', ''), | |
1151 '#description' => t("Your site's mission or focus statement (often prominently displayed on the front page).") | |
1152 ); | |
1153 $form['site_footer'] = array( | |
1154 '#type' => 'textarea', | |
1155 '#title' => t('Footer message'), | |
1156 '#default_value' => variable_get('site_footer', ''), | |
1157 '#description' => t('This text will be displayed at the bottom of each page. Useful for adding a copyright notice to your pages.') | |
1158 ); | |
1159 $form['anonymous'] = array( | |
1160 '#type' => 'textfield', | |
1161 '#title' => t('Anonymous user'), | |
1162 '#default_value' => variable_get('anonymous', t('Anonymous')), | |
1163 '#description' => t('The name used to indicate anonymous users.'), | |
1164 '#required' => TRUE, | |
1165 ); | |
1166 $form['site_frontpage'] = array( | |
1167 '#type' => 'textfield', | |
1168 '#title' => t('Default front page'), | |
1169 '#default_value' => variable_get('site_frontpage', 'node'), | |
1170 '#size' => 40, | |
1171 '#description' => t('The home page displays content from this relative URL. If unsure, specify "node".'), | |
1172 '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), | |
1173 '#required' => TRUE, | |
1174 ); | |
1175 $form['#validate'][] = 'system_site_information_settings_validate'; | |
1176 | |
1177 return system_settings_form($form); | |
1178 } | |
1179 | |
1180 /** | |
1181 * Validate the submitted site-information form. | |
1182 */ | |
1183 function system_site_information_settings_validate($form, &$form_state) { | |
1184 // Validate the e-mail address. | |
1185 if ($error = user_validate_mail($form_state['values']['site_mail'])) { | |
1186 form_set_error('site_mail', $error); | |
1187 } | |
1188 // Validate front page path. | |
1189 $item = array('link_path' => $form_state['values']['site_frontpage']); | |
1190 $normal_path = drupal_get_normal_path($item['link_path']); | |
1191 if ($item['link_path'] != $normal_path) { | |
1192 drupal_set_message(t('The menu system stores system paths only, but will use the URL alias for display. %link_path has been stored as %normal_path', array('%link_path' => $item['link_path'], '%normal_path' => $normal_path))); | |
1193 $item['link_path'] = $normal_path; | |
1194 } | |
1195 if (!empty($item) && !menu_valid_path($item)) { | |
1196 form_set_error('site_frontpage', t("The path '@path' is either invalid or you do not have access to it.", array('@path' => $item['link_path']))); | |
1197 } | |
1198 } | |
1199 | |
1200 /** | |
1201 * Form builder; Configure error reporting settings. | |
1202 * | |
1203 * @ingroup forms | |
1204 * @see system_settings_form() | |
1205 */ | |
1206 function system_error_reporting_settings() { | |
1207 | |
1208 $form['site_403'] = array( | |
1209 '#type' => 'textfield', | |
1210 '#title' => t('Default 403 (access denied) page'), | |
1211 '#default_value' => variable_get('site_403', ''), | |
1212 '#size' => 40, | |
1213 '#description' => t('This page is displayed when the requested document is denied to the current user. If unsure, specify nothing.'), | |
1214 '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=') | |
1215 ); | |
1216 | |
1217 $form['site_404'] = array( | |
1218 '#type' => 'textfield', | |
1219 '#title' => t('Default 404 (not found) page'), | |
1220 '#default_value' => variable_get('site_404', ''), | |
1221 '#size' => 40, | |
1222 '#description' => t('This page is displayed when no other content matches the requested document. If unsure, specify nothing.'), | |
1223 '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=') | |
1224 ); | |
1225 | |
1226 $form['error_level'] = array( | |
1227 '#type' => 'select', '#title' => t('Error reporting'), '#default_value' => variable_get('error_level', 1), | |
1228 '#options' => array(t('Write errors to the log'), t('Write errors to the log and to the screen')), | |
1229 '#description' => t('Specify where Drupal, PHP and SQL errors are logged. While it is recommended that a site running in a production environment write errors to the log only, in a development or testing environment it may be helpful to write errors both to the log and to the screen.') | |
1230 ); | |
1231 | |
1232 return system_settings_form($form); | |
1233 } | |
1234 | |
1235 /** | |
1236 * Menu callback; Menu page for the various logging options. | |
1237 */ | |
1238 function system_logging_overview() { | |
1239 $item = menu_get_item('admin/settings/logging'); | |
1240 $content = system_admin_menu_block($item); | |
1241 | |
1242 $output = theme('admin_block_content', $content); | |
1243 | |
1244 return $output; | |
1245 } | |
1246 | |
1247 /** | |
1248 * Form builder; Configure site performance settings. | |
1249 * | |
1250 * @ingroup forms | |
1251 * @see system_settings_form() | |
1252 */ | |
1253 function system_performance_settings() { | |
1254 | |
1255 $description = '<p>'. t("The normal cache mode is suitable for most sites and does not cause any side effects. The aggressive cache mode causes Drupal to skip the loading (boot) and unloading (exit) of enabled modules when serving a cached page. This results in an additional performance boost but can cause unwanted side effects.") .'</p>'; | |
1256 | |
1257 $problem_modules = array_unique(array_merge(module_implements('boot'), module_implements('exit'))); | |
1258 sort($problem_modules); | |
1259 | |
1260 if (count($problem_modules) > 0) { | |
1261 $description .= '<p>'. t('<strong class="error">The following enabled modules are incompatible with aggressive mode caching and will not function properly: %modules</strong>', array('%modules' => implode(', ', $problem_modules))) .'.</p>'; | |
1262 } | |
1263 else { | |
1264 $description .= '<p>'. t('<strong class="ok">Currently, all enabled modules are compatible with the aggressive caching policy.</strong> Please note, if you use aggressive caching and enable new modules, you will need to check this page again to ensure compatibility.') .'</p>'; | |
1265 } | |
1266 $form['page_cache'] = array( | |
1267 '#type' => 'fieldset', | |
1268 '#title' => t('Page cache'), | |
1269 '#description' => t('Enabling the page cache will offer a significant performance boost. Drupal can store and send compressed cached pages requested by <em>anonymous</em> users. By caching a web page, Drupal does not have to construct the page each time it is viewed.'), | |
1270 ); | |
1271 | |
1272 $form['page_cache']['cache'] = array( | |
1273 '#type' => 'radios', | |
1274 '#title' => t('Caching mode'), | |
1275 '#default_value' => variable_get('cache', CACHE_DISABLED), | |
1276 '#options' => array(CACHE_DISABLED => t('Disabled'), CACHE_NORMAL => t('Normal (recommended for production sites, no side effects)'), CACHE_AGGRESSIVE => t('Aggressive (experts only, possible side effects)')), | |
1277 '#description' => $description | |
1278 ); | |
1279 | |
1280 $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval'); | |
1281 $period[0] = '<'. t('none') .'>'; | |
1282 $form['page_cache']['cache_lifetime'] = array( | |
1283 '#type' => 'select', | |
1284 '#title' => t('Minimum cache lifetime'), | |
1285 '#default_value' => variable_get('cache_lifetime', 0), | |
1286 '#options' => $period, | |
1287 '#description' => t('On high-traffic sites, it may be necessary to enforce a minimum cache lifetime. The minimum cache lifetime is the minimum amount of time that will elapse before the cache is emptied and recreated, and is applied to both page and block caches. A larger minimum cache lifetime offers better performance, but users will not see new content for a longer period of time.') | |
1288 ); | |
1289 $form['page_cache']['page_compression'] = array( | |
1290 '#type' => 'radios', | |
1291 '#title' => t('Page compression'), | |
1292 '#default_value' => variable_get('page_compression', TRUE), | |
1293 '#options' => array(t('Disabled'), t('Enabled')), | |
1294 '#description' => t("By default, Drupal compresses the pages it caches in order to save bandwidth and improve download times. This option should be disabled when using a webserver that performs compression."), | |
1295 ); | |
1296 | |
1297 $form['block_cache'] = array( | |
1298 '#type' => 'fieldset', | |
1299 '#title' => t('Block cache'), | |
1300 '#description' => t('Enabling the block cache can offer a performance increase for all users by preventing blocks from being reconstructed on each page load. If the page cache is also enabled, performance increases from enabling the block cache will mainly benefit authenticated users.'), | |
1301 ); | |
1302 | |
1303 $form['block_cache']['block_cache'] = array( | |
1304 '#type' => 'radios', | |
1305 '#title' => t('Block cache'), | |
1306 '#default_value' => variable_get('block_cache', CACHE_DISABLED), | |
1307 '#options' => array(CACHE_DISABLED => t('Disabled'), CACHE_NORMAL => t('Enabled (recommended)')), | |
1308 '#disabled' => count(module_implements('node_grants')), | |
1309 '#description' => t('Note that block caching is inactive when modules defining content access restrictions are enabled.'), | |
1310 ); | |
1311 | |
1312 $form['bandwidth_optimizations'] = array( | |
1313 '#type' => 'fieldset', | |
1314 '#title' => t('Bandwidth optimizations'), | |
1315 '#description' => t('<p>Drupal can automatically optimize external resources like CSS and JavaScript, which can reduce both the size and number of requests made to your website. CSS files can be aggregated and compressed into a single file, while JavaScript files are aggregated (but not compressed). These optional optimizations may reduce server load, bandwidth requirements, and page loading times.</p><p>These options are disabled if you have not set up your files directory, or if your download method is set to private.</p>') | |
1316 ); | |
1317 | |
1318 $directory = file_directory_path(); | |
1319 $is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC); | |
1320 $form['bandwidth_optimizations']['preprocess_css'] = array( | |
1321 '#type' => 'radios', | |
1322 '#title' => t('Optimize CSS files'), | |
1323 '#default_value' => intval(variable_get('preprocess_css', 0) && $is_writable), | |
1324 '#disabled' => !$is_writable, | |
1325 '#options' => array(t('Disabled'), t('Enabled')), | |
1326 '#description' => t('This option can interfere with theme development and should only be enabled in a production environment.'), | |
1327 ); | |
1328 $form['bandwidth_optimizations']['preprocess_js'] = array( | |
1329 '#type' => 'radios', | |
1330 '#title' => t('Optimize JavaScript files'), | |
1331 '#default_value' => intval(variable_get('preprocess_js', 0) && $is_writable), | |
1332 '#disabled' => !$is_writable, | |
1333 '#options' => array(t('Disabled'), t('Enabled')), | |
1334 '#description' => t('This option can interfere with module development and should only be enabled in a production environment.'), | |
1335 ); | |
1336 | |
1337 $form['clear_cache'] = array( | |
1338 '#type' => 'fieldset', | |
1339 '#title' => t('Clear cached data'), | |
1340 '#description' => t('Caching data improves performance, but may cause problems while troubleshooting new modules, themes, or translations, if outdated information has been cached. To refresh all cached data on your site, click the button below. <em>Warning: high-traffic sites will experience performance slowdowns while cached data is rebuilt.</em>'), | |
1341 ); | |
1342 | |
1343 $form['clear_cache']['clear'] = array( | |
1344 '#type' => 'submit', | |
1345 '#value' => t('Clear cached data'), | |
1346 '#submit' => array('system_clear_cache_submit'), | |
1347 ); | |
1348 | |
1349 $form['#submit'][] = 'drupal_clear_css_cache'; | |
1350 $form['#submit'][] = 'drupal_clear_js_cache'; | |
1351 | |
1352 return system_settings_form($form); | |
1353 } | |
1354 | |
1355 /** | |
1356 * Submit callback; clear system caches. | |
1357 * | |
1358 * @ingroup forms | |
1359 */ | |
1360 function system_clear_cache_submit(&$form_state, $form) { | |
1361 drupal_flush_all_caches(); | |
1362 drupal_set_message('Caches cleared.'); | |
1363 } | |
1364 | |
1365 /** | |
1366 * Form builder; Configure the site file handling. | |
1367 * | |
1368 * @ingroup forms | |
1369 * @see system_settings_form() | |
1370 */ | |
1371 function system_file_system_settings() { | |
1372 | |
1373 $form['file_directory_path'] = array( | |
1374 '#type' => 'textfield', | |
1375 '#title' => t('File system path'), | |
1376 '#default_value' => file_directory_path(), | |
1377 '#maxlength' => 255, | |
1378 '#description' => t('A file system path where the files will be stored. This directory must exist and be writable by Drupal. If the download method is set to public, this directory must be relative to the Drupal installation directory and be accessible over the web. If the download method is set to private, this directory should not be accessible over the web. Changing this location will modify all download paths and may cause unexpected problems on an existing site.'), | |
1379 '#after_build' => array('system_check_directory'), | |
1380 ); | |
1381 | |
1382 $form['file_directory_temp'] = array( | |
1383 '#type' => 'textfield', | |
1384 '#title' => t('Temporary directory'), | |
1385 '#default_value' => file_directory_temp(), | |
1386 '#maxlength' => 255, | |
1387 '#description' => t('A file system path where uploaded files will be stored during previews.'), | |
1388 '#after_build' => array('system_check_directory'), | |
1389 ); | |
1390 | |
1391 $form['file_downloads'] = array( | |
1392 '#type' => 'radios', | |
1393 '#title' => t('Download method'), | |
1394 '#default_value' => variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC), | |
1395 '#options' => array(FILE_DOWNLOADS_PUBLIC => t('Public - files are available using HTTP directly.'), FILE_DOWNLOADS_PRIVATE => t('Private - files are transferred by Drupal.')), | |
1396 '#description' => t('Choose the <em>Public download</em> method unless you wish to enforce fine-grained access controls over file downloads. Changing the download method will modify all download paths and may cause unexpected problems on an existing site.') | |
1397 ); | |
1398 | |
1399 return system_settings_form($form); | |
1400 } | |
1401 | |
1402 /** | |
1403 * Form builder; Configure site image toolkit usage. | |
1404 * | |
1405 * @ingroup forms | |
1406 * @see system_settings_form() | |
1407 */ | |
1408 function system_image_toolkit_settings() { | |
1409 $toolkits_available = image_get_available_toolkits(); | |
1410 if (count($toolkits_available) > 1) { | |
1411 $form['image_toolkit'] = array( | |
1412 '#type' => 'radios', | |
1413 '#title' => t('Select an image processing toolkit'), | |
1414 '#default_value' => variable_get('image_toolkit', image_get_toolkit()), | |
1415 '#options' => $toolkits_available | |
1416 ); | |
1417 } | |
1418 elseif (count($toolkits_available) == 1) { | |
1419 variable_set('image_toolkit', key($toolkits_available)); | |
1420 } | |
1421 | |
1422 $form['image_toolkit_settings'] = image_toolkit_invoke('settings'); | |
1423 | |
1424 return system_settings_form($form); | |
1425 } | |
1426 | |
1427 /** | |
1428 * Form builder; Configure how the site handles RSS feeds. | |
1429 * | |
1430 * @ingroup forms | |
1431 * @see system_settings_form() | |
1432 */ | |
1433 function system_rss_feeds_settings() { | |
1434 | |
1435 $form['feed_default_items'] = array( | |
1436 '#type' => 'select', | |
1437 '#title' => t('Number of items in each feed'), | |
1438 '#default_value' => variable_get('feed_default_items', 10), | |
1439 '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), | |
1440 '#description' => t('Default number of items to include in each feed.') | |
1441 ); | |
1442 $form['feed_item_length'] = array( | |
1443 '#type' => 'select', | |
1444 '#title' => t('Feed content'), | |
1445 '#default_value' => variable_get('feed_item_length', 'teaser'), | |
1446 '#options' => array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')), | |
1447 '#description' => t('Global setting for the default display of content items in each feed.') | |
1448 ); | |
1449 | |
1450 return system_settings_form($form); | |
1451 } | |
1452 | |
1453 /** | |
1454 * Form builder; Configure the site date and time settings. | |
1455 * | |
1456 * @ingroup forms | |
1457 * @see system_settings_form() | |
1458 * @see system_date_time_settings_submit() | |
1459 */ | |
1460 function system_date_time_settings() { | |
1461 drupal_add_js(drupal_get_path('module', 'system') .'/system.js', 'module'); | |
1462 drupal_add_js(array('dateTime' => array('lookup' => url('admin/settings/date-time/lookup'))), 'setting'); | |
1463 | |
1464 // Date settings: | |
1465 $zones = _system_zonelist(); | |
1466 | |
1467 // Date settings: possible date formats | |
1468 $date_short = array('Y-m-d H:i', 'm/d/Y - H:i', 'd/m/Y - H:i', 'Y/m/d - H:i', | |
1469 'd.m.Y - H:i', 'm/d/Y - g:ia', 'd/m/Y - g:ia', 'Y/m/d - g:ia', | |
1470 'M j Y - H:i', 'j M Y - H:i', 'Y M j - H:i', | |
1471 'M j Y - g:ia', 'j M Y - g:ia', 'Y M j - g:ia'); | |
1472 $date_medium = array('D, Y-m-d H:i', 'D, m/d/Y - H:i', 'D, d/m/Y - H:i', | |
1473 'D, Y/m/d - H:i', 'F j, Y - H:i', 'j F, Y - H:i', 'Y, F j - H:i', | |
1474 'D, m/d/Y - g:ia', 'D, d/m/Y - g:ia', 'D, Y/m/d - g:ia', | |
1475 'F j, Y - g:ia', 'j F Y - g:ia', 'Y, F j - g:ia', 'j. F Y - G:i'); | |
1476 $date_long = array('l, F j, Y - H:i', 'l, j F, Y - H:i', 'l, Y, F j - H:i', | |
1477 'l, F j, Y - g:ia', 'l, j F Y - g:ia', 'l, Y, F j - g:ia', 'l, j. F Y - G:i'); | |
1478 | |
1479 // Date settings: construct choices for user | |
1480 foreach ($date_short as $f) { | |
1481 $date_short_choices[$f] = format_date(time(), 'custom', $f); | |
1482 } | |
1483 foreach ($date_medium as $f) { | |
1484 $date_medium_choices[$f] = format_date(time(), 'custom', $f); | |
1485 } | |
1486 foreach ($date_long as $f) { | |
1487 $date_long_choices[$f] = format_date(time(), 'custom', $f); | |
1488 } | |
1489 | |
1490 $date_long_choices['custom'] = $date_medium_choices['custom'] = $date_short_choices['custom'] = t('Custom format'); | |
1491 | |
1492 $form['locale'] = array( | |
1493 '#type' => 'fieldset', | |
1494 '#title' => t('Locale settings'), | |
1495 ); | |
1496 | |
1497 $form['locale']['date_default_timezone'] = array( | |
1498 '#type' => 'select', | |
1499 '#title' => t('Default time zone'), | |
1500 '#default_value' => variable_get('date_default_timezone', 0), | |
1501 '#options' => $zones, | |
1502 '#description' => t('Select the default site time zone.') | |
1503 ); | |
1504 | |
1505 $form['locale']['configurable_timezones'] = array( | |
1506 '#type' => 'radios', | |
1507 '#title' => t('User-configurable time zones'), | |
1508 '#default_value' => variable_get('configurable_timezones', 1), | |
1509 '#options' => array(t('Disabled'), t('Enabled')), | |
1510 '#description' => t('When enabled, users can set their own time zone and dates will be displayed accordingly.') | |
1511 ); | |
1512 | |
1513 $form['locale']['date_first_day'] = array( | |
1514 '#type' => 'select', | |
1515 '#title' => t('First day of week'), | |
1516 '#default_value' => variable_get('date_first_day', 0), | |
1517 '#options' => array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')), | |
1518 '#description' => t('The first day of the week for calendar views.') | |
1519 ); | |
1520 | |
1521 $form['date_formats'] = array( | |
1522 '#type' => 'fieldset', | |
1523 '#title' => t('Formatting'), | |
1524 ); | |
1525 | |
1526 $date_format_short = variable_get('date_format_short', $date_short[1]); | |
1527 $form['date_formats']['date_format_short'] = array( | |
1528 '#prefix' => '<div class="date-container"><div class="select-container">', | |
1529 '#suffix' => '</div>', | |
1530 '#type' => 'select', | |
1531 '#title' => t('Short date format'), | |
1532 '#attributes' => array('class' => 'date-format'), | |
1533 '#default_value' => (isset($date_short_choices[$date_format_short]) ? $date_format_short : 'custom'), | |
1534 '#options' => $date_short_choices, | |
1535 '#description' => t('The short format of date display.'), | |
1536 ); | |
1537 | |
1538 $default_short_custom = variable_get('date_format_short_custom', (isset($date_short_choices[$date_format_short]) ? $date_format_short : '')); | |
1539 $form['date_formats']['date_format_short_custom'] = array( | |
1540 '#prefix' => '<div class="custom-container">', | |
1541 '#suffix' => '</div></div>', | |
1542 '#type' => 'textfield', | |
1543 '#title' => t('Custom short date format'), | |
1544 '#attributes' => array('class' => 'custom-format'), | |
1545 '#default_value' => $default_short_custom, | |
1546 '#description' => t('A user-defined short date format. See the <a href="@url">PHP manual</a> for available options. This format is currently set to display as <span>%date</span>.', array('@url' => 'http://php.net/manual/function.date.php', '%date' => format_date(time(), 'custom', $default_short_custom))), | |
1547 ); | |
1548 | |
1549 $date_format_medium = variable_get('date_format_medium', $date_medium[1]); | |
1550 $form['date_formats']['date_format_medium'] = array( | |
1551 '#prefix' => '<div class="date-container"><div class="select-container">', | |
1552 '#suffix' => '</div>', | |
1553 '#type' => 'select', | |
1554 '#title' => t('Medium date format'), | |
1555 '#attributes' => array('class' => 'date-format'), | |
1556 '#default_value' => (isset($date_medium_choices[$date_format_medium]) ? $date_format_medium : 'custom'), | |
1557 '#options' => $date_medium_choices, | |
1558 '#description' => t('The medium sized date display.'), | |
1559 ); | |
1560 | |
1561 $default_medium_custom = variable_get('date_format_medium_custom', (isset($date_medium_choices[$date_format_medium]) ? $date_format_medium : '')); | |
1562 $form['date_formats']['date_format_medium_custom'] = array( | |
1563 '#prefix' => '<div class="custom-container">', | |
1564 '#suffix' => '</div></div>', | |
1565 '#type' => 'textfield', | |
1566 '#title' => t('Custom medium date format'), | |
1567 '#attributes' => array('class' => 'custom-format'), | |
1568 '#default_value' => $default_medium_custom, | |
1569 '#description' => t('A user-defined medium date format. See the <a href="@url">PHP manual</a> for available options. This format is currently set to display as <span>%date</span>.', array('@url' => 'http://php.net/manual/function.date.php', '%date' => format_date(time(), 'custom', $default_medium_custom))), | |
1570 ); | |
1571 | |
1572 $date_format_long = variable_get('date_format_long', $date_long[0]); | |
1573 $form['date_formats']['date_format_long'] = array( | |
1574 '#prefix' => '<div class="date-container"><div class="select-container">', | |
1575 '#suffix' => '</div>', | |
1576 '#type' => 'select', | |
1577 '#title' => t('Long date format'), | |
1578 '#attributes' => array('class' => 'date-format'), | |
1579 '#default_value' => (isset($date_long_choices[$date_format_long]) ? $date_format_long : 'custom'), | |
1580 '#options' => $date_long_choices, | |
1581 '#description' => t('Longer date format used for detailed display.') | |
1582 ); | |
1583 | |
1584 $default_long_custom = variable_get('date_format_long_custom', (isset($date_long_choices[$date_format_long]) ? $date_format_long : '')); | |
1585 $form['date_formats']['date_format_long_custom'] = array( | |
1586 '#prefix' => '<div class="custom-container">', | |
1587 '#suffix' => '</div></div>', | |
1588 '#type' => 'textfield', | |
1589 '#title' => t('Custom long date format'), | |
1590 '#attributes' => array('class' => 'custom-format'), | |
1591 '#default_value' => $default_long_custom, | |
1592 '#description' => t('A user-defined long date format. See the <a href="@url">PHP manual</a> for available options. This format is currently set to display as <span>%date</span>.', array('@url' => 'http://php.net/manual/function.date.php', '%date' => format_date(time(), 'custom', $default_long_custom))), | |
1593 ); | |
1594 | |
1595 $form = system_settings_form($form); | |
1596 // We will call system_settings_form_submit() manually, so remove it for now. | |
1597 unset($form['#submit']); | |
1598 return $form; | |
1599 } | |
1600 | |
1601 /** | |
1602 * Process system_date_time_settings form submissions. | |
1603 */ | |
1604 function system_date_time_settings_submit($form, &$form_state) { | |
1605 if ($form_state['values']['date_format_short'] == 'custom') { | |
1606 $form_state['values']['date_format_short'] = $form_state['values']['date_format_short_custom']; | |
1607 } | |
1608 if ($form_state['values']['date_format_medium'] == 'custom') { | |
1609 $form_state['values']['date_format_medium'] = $form_state['values']['date_format_medium_custom']; | |
1610 } | |
1611 if ($form_state['values']['date_format_long'] == 'custom') { | |
1612 $form_state['values']['date_format_long'] = $form_state['values']['date_format_long_custom']; | |
1613 } | |
1614 return system_settings_form_submit($form, $form_state); | |
1615 } | |
1616 | |
1617 /** | |
1618 * Return the date for a given format string via Ajax. | |
1619 */ | |
1620 function system_date_time_lookup() { | |
1621 $result = format_date(time(), 'custom', $_GET['format']); | |
1622 echo drupal_to_js($result); | |
1623 exit; | |
1624 } | |
1625 | |
1626 /** | |
1627 * Form builder; Configure the site's maintenance status. | |
1628 * | |
1629 * @ingroup forms | |
1630 * @see system_settings_form() | |
1631 */ | |
1632 function system_site_maintenance_settings() { | |
1633 | |
1634 $form['site_offline'] = array( | |
1635 '#type' => 'radios', | |
1636 '#title' => t('Site status'), | |
1637 '#default_value' => variable_get('site_offline', 0), | |
1638 '#options' => array(t('Online'), t('Off-line')), | |
1639 '#description' => t('When set to "Online", all visitors will be able to browse your site normally. When set to "Off-line", only users with the "administer site configuration" permission will be able to access your site to perform maintenance; all other visitors will see the site off-line message configured below. Authorized users can log in during "Off-line" mode directly via the <a href="@user-login">user login</a> page.', array('@user-login' => url('user'))), | |
1640 ); | |
1641 | |
1642 $form['site_offline_message'] = array( | |
1643 '#type' => 'textarea', | |
1644 '#title' => t('Site off-line message'), | |
1645 '#default_value' => variable_get('site_offline_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')))), | |
1646 '#description' => t('Message to show visitors when the site is in off-line mode.') | |
1647 ); | |
1648 | |
1649 return system_settings_form($form); | |
1650 } | |
1651 | |
1652 /** | |
1653 * Form builder; Configure Clean URL settings. | |
1654 * | |
1655 * @ingroup forms | |
1656 * @see system_settings_form() | |
1657 */ | |
1658 function system_clean_url_settings() { | |
1659 $form['clean_url'] = array( | |
1660 '#type' => 'radios', | |
1661 '#title' => t('Clean URLs'), | |
1662 '#default_value' => variable_get('clean_url', 0), | |
1663 '#options' => array(t('Disabled'), t('Enabled')), | |
1664 '#description' => t('This option makes Drupal emit "clean" URLs (i.e. without <code>?q=</code> in the URL).'), | |
1665 ); | |
1666 | |
1667 if (!variable_get('clean_url', 0)) { | |
1668 if (strpos(request_uri(), '?q=') !== FALSE) { | |
1669 drupal_add_js(drupal_get_path('module', 'system') .'/system.js', 'module'); | |
1670 | |
1671 $form['clean_url']['#description'] .= ' <span>'. t('Before enabling clean URLs, you must perform a test to determine if your server is properly configured. If you are able to see this page again after clicking the "Run the clean URL test" link, the test has succeeded and the radio buttons above will be available. If instead you are directed to a "Page not found" error, you will need to change the configuration of your server. The <a href="@handbook">handbook page on Clean URLs</a> has additional troubleshooting information.', array('@handbook' => 'http://drupal.org/node/15365')) .'</span>'; | |
1672 | |
1673 $form['clean_url']['#disabled'] = TRUE; | |
1674 $form['clean_url']['#prefix'] = '<div id="clean-url">'; | |
1675 $form['clean_url']['#suffix'] = '<p>'. t('<a href="@clean_url">Run the clean url test</a>.', array('@clean_url' => base_path() .'admin/settings/clean-urls')) .'</p></div>'; | |
1676 } | |
1677 else { | |
1678 $form['clean_url']['#description'] .= ' <div class="ok">'. t('Your server has been successfully tested to support this feature.') .'</div>'; | |
1679 } | |
1680 } | |
1681 | |
1682 return system_settings_form($form); | |
1683 } | |
1684 | |
1685 /** | |
1686 * Menu callback: displays the site status report. Can also be used as a pure check. | |
1687 * | |
1688 * @param $check | |
1689 * If true, only returns a boolean whether there are system status errors. | |
1690 */ | |
1691 function system_status($check = FALSE) { | |
1692 // Load .install files | |
1693 include_once './includes/install.inc'; | |
1694 drupal_load_updates(); | |
1695 | |
1696 // Check run-time requirements and status information. | |
1697 $requirements = module_invoke_all('requirements', 'runtime'); | |
1698 usort($requirements, '_system_sort_requirements'); | |
1699 | |
1700 if ($check) { | |
1701 return drupal_requirements_severity($requirements) == REQUIREMENT_ERROR; | |
1702 } | |
1703 // MySQL import might have set the uid of the anonymous user to autoincrement | |
1704 // value. Let's try fixing it. See http://drupal.org/node/204411 | |
1705 db_query("UPDATE {users} SET uid = uid - uid WHERE name = '' AND pass = '' AND status = 0"); | |
1706 | |
1707 return theme('status_report', $requirements); | |
1708 } | |
1709 | |
1710 /** | |
1711 * Menu callback: run cron manually. | |
1712 */ | |
1713 function system_run_cron() { | |
1714 // Run cron manually | |
1715 if (drupal_cron_run()) { | |
1716 drupal_set_message(t('Cron ran successfully.')); | |
1717 } | |
1718 else { | |
1719 drupal_set_message(t('Cron run failed.'), 'error'); | |
1720 } | |
1721 | |
1722 drupal_goto('admin/reports/status'); | |
1723 } | |
1724 | |
1725 /** | |
1726 * Menu callback: return information about PHP. | |
1727 */ | |
1728 function system_php() { | |
1729 phpinfo(INFO_GENERAL | INFO_CONFIGURATION); | |
1730 exit(); | |
1731 } | |
1732 | |
1733 /** | |
1734 * Theme a SQL result table. | |
1735 * | |
1736 * @param $data | |
1737 * The actual table data. | |
1738 * @param $keys | |
1739 * Data keys and descriptions. | |
1740 * @return | |
1741 * The output HTML. | |
1742 */ | |
1743 function _system_sql($data, $keys) { | |
1744 $rows = array(); | |
1745 foreach ($keys as $key => $explanation) { | |
1746 if (isset($data[$key])) { | |
1747 $rows[] = array(check_plain($key), check_plain($data[$key]), $explanation); | |
1748 } | |
1749 } | |
1750 | |
1751 return theme('table', array(t('Variable'), t('Value'), t('Description')), $rows); | |
1752 } | |
1753 | |
1754 /** | |
1755 * Menu callback: return information about the database. | |
1756 */ | |
1757 function system_sql() { | |
1758 | |
1759 $result = db_query("SHOW STATUS"); | |
1760 while ($entry = db_fetch_object($result)) { | |
1761 // 'SHOW STATUS' returns fields named 'Variable_name' and 'Value', | |
1762 // case is important. | |
1763 $data[$entry->Variable_name] = $entry->Value; | |
1764 } | |
1765 | |
1766 $output = '<h2>'. t('Command counters') .'</h2>'; | |
1767 $output .= _system_sql($data, array( | |
1768 'Com_select' => t('The number of <code>SELECT</code>-statements.'), | |
1769 'Com_insert' => t('The number of <code>INSERT</code>-statements.'), | |
1770 'Com_update' => t('The number of <code>UPDATE</code>-statements.'), | |
1771 'Com_delete' => t('The number of <code>DELETE</code>-statements.'), | |
1772 'Com_lock_tables' => t('The number of table locks.'), | |
1773 'Com_unlock_tables' => t('The number of table unlocks.') | |
1774 )); | |
1775 | |
1776 $output .= '<h2>'. t('Query performance') .'</h2>'; | |
1777 $output .= _system_sql($data, array( | |
1778 'Select_full_join' => t('The number of joins without an index; should be zero.'), | |
1779 'Select_range_check' => t('The number of joins without keys that check for key usage after each row; should be zero.'), | |
1780 'Sort_scan' => t('The number of sorts done without using an index; should be zero.'), | |
1781 'Table_locks_immediate' => t('The number of times a lock could be acquired immediately.'), | |
1782 'Table_locks_waited' => t('The number of times the server had to wait for a lock.') | |
1783 )); | |
1784 | |
1785 $output .= '<h2>'. t('Query cache information') .'</h2>'; | |
1786 $output .= '<p>'. t('The MySQL query cache can improve performance of your site by storing the result of queries. Then, if an identical query is received later, the MySQL server retrieves the result from the query cache rather than parsing and executing the statement again.') .'</p>'; | |
1787 $output .= _system_sql($data, array( | |
1788 'Qcache_queries_in_cache' => t('The number of queries in the query cache.'), | |
1789 'Qcache_hits' => t('The number of times MySQL found previous results in the cache.'), | |
1790 'Qcache_inserts' => t('The number of times MySQL added a query to the cache (misses).'), | |
1791 'Qcache_lowmem_prunes' => t('The number of times MySQL had to remove queries from the cache because it ran out of memory. Ideally should be zero.') | |
1792 )); | |
1793 | |
1794 return $output; | |
1795 } | |
1796 | |
1797 /** | |
1798 * Default page callback for batches. | |
1799 */ | |
1800 function system_batch_page() { | |
1801 require_once './includes/batch.inc'; | |
1802 $output = _batch_page(); | |
1803 if ($output === FALSE) { | |
1804 drupal_access_denied(); | |
1805 } | |
1806 elseif (isset($output)) { | |
1807 // Force a page without blocks or messages to | |
1808 // display a list of collected messages later. | |
1809 print theme('page', $output, FALSE, FALSE); | |
1810 } | |
1811 } | |
1812 | |
1813 /** | |
1814 * This function formats an administrative block for display. | |
1815 * | |
1816 * @param $block | |
1817 * An array containing information about the block. It should | |
1818 * include a 'title', a 'description' and a formatted 'content'. | |
1819 * @ingroup themeable | |
1820 */ | |
1821 function theme_admin_block($block) { | |
1822 // Don't display the block if it has no content to display. | |
1823 if (empty($block['content'])) { | |
1824 return ''; | |
1825 } | |
1826 | |
1827 $output = <<< EOT | |
1828 <div class="admin-panel"> | |
1829 <h3> | |
1830 $block[title] | |
1831 </h3> | |
1832 <div class="body"> | |
1833 <p class="description"> | |
1834 $block[description] | |
1835 </p> | |
1836 $block[content] | |
1837 </div> | |
1838 </div> | |
1839 EOT; | |
1840 return $output; | |
1841 } | |
1842 | |
1843 /** | |
1844 * This function formats the content of an administrative block. | |
1845 * | |
1846 * @param $block | |
1847 * An array containing information about the block. It should | |
1848 * include a 'title', a 'description' and a formatted 'content'. | |
1849 * @ingroup themeable | |
1850 */ | |
1851 function theme_admin_block_content($content) { | |
1852 if (!$content) { | |
1853 return ''; | |
1854 } | |
1855 | |
1856 if (system_admin_compact_mode()) { | |
1857 $output = '<ul class="menu">'; | |
1858 foreach ($content as $item) { | |
1859 $output .= '<li class="leaf">'. l($item['title'], $item['href'], $item['localized_options']) .'</li>'; | |
1860 } | |
1861 $output .= '</ul>'; | |
1862 } | |
1863 else { | |
1864 $output = '<dl class="admin-list">'; | |
1865 foreach ($content as $item) { | |
1866 $output .= '<dt>'. l($item['title'], $item['href'], $item['localized_options']) .'</dt>'; | |
1867 $output .= '<dd>'. $item['description'] .'</dd>'; | |
1868 } | |
1869 $output .= '</dl>'; | |
1870 } | |
1871 return $output; | |
1872 } | |
1873 | |
1874 /** | |
1875 * This function formats an administrative page for viewing. | |
1876 * | |
1877 * @param $blocks | |
1878 * An array of blocks to display. Each array should include a | |
1879 * 'title', a 'description', a formatted 'content' and a | |
1880 * 'position' which will control which container it will be | |
1881 * in. This is usually 'left' or 'right'. | |
1882 * @ingroup themeable | |
1883 */ | |
1884 function theme_admin_page($blocks) { | |
1885 $stripe = 0; | |
1886 $container = array(); | |
1887 | |
1888 foreach ($blocks as $block) { | |
1889 if ($block_output = theme('admin_block', $block)) { | |
1890 if (empty($block['position'])) { | |
1891 // perform automatic striping. | |
1892 $block['position'] = ++$stripe % 2 ? 'left' : 'right'; | |
1893 } | |
1894 if (!isset($container[$block['position']])) { | |
1895 $container[$block['position']] = ''; | |
1896 } | |
1897 $container[$block['position']] .= $block_output; | |
1898 } | |
1899 } | |
1900 | |
1901 $output = '<div class="admin clear-block">'; | |
1902 $output .= '<div class="compact-link">'; | |
1903 if (system_admin_compact_mode()) { | |
1904 $output .= l(t('Show descriptions'), 'admin/compact/off', array('title' => t('Expand layout to include descriptions.'))); | |
1905 } | |
1906 else { | |
1907 $output .= l(t('Hide descriptions'), 'admin/compact/on', array('title' => t('Compress layout by hiding descriptions.'))); | |
1908 } | |
1909 $output .= '</div>'; | |
1910 | |
1911 foreach ($container as $id => $data) { | |
1912 $output .= '<div class="'. $id .' clear-block">'; | |
1913 $output .= $data; | |
1914 $output .= '</div>'; | |
1915 } | |
1916 $output .= '</div>'; | |
1917 return $output; | |
1918 } | |
1919 | |
1920 /** | |
1921 * Theme output of the dashboard page. | |
1922 * | |
1923 * @param $menu_items | |
1924 * An array of modules to be displayed. | |
1925 * @ingroup themeable | |
1926 */ | |
1927 function theme_system_admin_by_module($menu_items) { | |
1928 $stripe = 0; | |
1929 $output = ''; | |
1930 $container = array('left' => '', 'right' => ''); | |
1931 $flip = array('left' => 'right', 'right' => 'left'); | |
1932 $position = 'left'; | |
1933 | |
1934 // Iterate over all modules | |
1935 foreach ($menu_items as $module => $block) { | |
1936 list($description, $items) = $block; | |
1937 | |
1938 // Output links | |
1939 if (count($items)) { | |
1940 $block = array(); | |
1941 $block['title'] = $module; | |
1942 $block['content'] = theme('item_list', $items); | |
1943 $block['description'] = t($description); | |
1944 | |
1945 if ($block_output = theme('admin_block', $block)) { | |
1946 if (!isset($block['position'])) { | |
1947 // Perform automatic striping. | |
1948 $block['position'] = $position; | |
1949 $position = $flip[$position]; | |
1950 } | |
1951 $container[$block['position']] .= $block_output; | |
1952 } | |
1953 } | |
1954 } | |
1955 | |
1956 $output = '<div class="admin clear-block">'; | |
1957 foreach ($container as $id => $data) { | |
1958 $output .= '<div class="'. $id .' clear-block">'; | |
1959 $output .= $data; | |
1960 $output .= '</div>'; | |
1961 } | |
1962 $output .= '</div>'; | |
1963 | |
1964 return $output; | |
1965 } | |
1966 | |
1967 /** | |
1968 * Theme requirements status report. | |
1969 * | |
1970 * @param $requirements | |
1971 * An array of requirements. | |
1972 * @ingroup themeable | |
1973 */ | |
1974 function theme_status_report(&$requirements) { | |
1975 $i = 0; | |
1976 $output = '<table class="system-status-report">'; | |
1977 foreach ($requirements as $requirement) { | |
1978 if (empty($requirement['#type'])) { | |
1979 $class = ++$i % 2 == 0 ? 'even' : 'odd'; | |
1980 | |
1981 $classes = array( | |
1982 REQUIREMENT_INFO => 'info', | |
1983 REQUIREMENT_OK => 'ok', | |
1984 REQUIREMENT_WARNING => 'warning', | |
1985 REQUIREMENT_ERROR => 'error', | |
1986 ); | |
1987 $class = $classes[isset($requirement['severity']) ? (int)$requirement['severity'] : 0] .' '. $class; | |
1988 | |
1989 // Output table row(s) | |
1990 if (!empty($requirement['description'])) { | |
1991 $output .= '<tr class="'. $class .' merge-down"><th>'. $requirement['title'] .'</th><td>'. $requirement['value'] .'</td></tr>'; | |
1992 $output .= '<tr class="'. $class .' merge-up"><td colspan="2">'. $requirement['description'] .'</td></tr>'; | |
1993 } | |
1994 else { | |
1995 $output .= '<tr class="'. $class .'"><th>'. $requirement['title'] .'</th><td>'. $requirement['value'] .'</td></tr>'; | |
1996 } | |
1997 } | |
1998 } | |
1999 | |
2000 $output .= '</table>'; | |
2001 return $output; | |
2002 } | |
2003 | |
2004 /** | |
2005 * Theme callback for the modules form. | |
2006 * | |
2007 * @param $form | |
2008 * An associative array containing the structure of the form. | |
2009 * @ingroup themeable | |
2010 */ | |
2011 function theme_system_modules($form) { | |
2012 if (isset($form['confirm'])) { | |
2013 return drupal_render($form); | |
2014 } | |
2015 | |
2016 // Individual table headers. | |
2017 $header = array(); | |
2018 $header[] = array('data' => t('Enabled'), 'class' => 'checkbox'); | |
2019 if (module_exists('throttle')) { | |
2020 $header[] = array('data' => t('Throttle'), 'class' => 'checkbox'); | |
2021 } | |
2022 $header[] = t('Name'); | |
2023 $header[] = t('Version'); | |
2024 $header[] = t('Description'); | |
2025 | |
2026 // Pull package information from module list and start grouping modules. | |
2027 $modules = $form['validation_modules']['#value']; | |
2028 foreach ($modules as $module) { | |
2029 if (!isset($module->info['package']) || !$module->info['package']) { | |
2030 $module->info['package'] = t('Other'); | |
2031 } | |
2032 $packages[$module->info['package']][$module->name] = $module->info; | |
2033 } | |
2034 ksort($packages); | |
2035 | |
2036 // Display packages. | |
2037 $output = ''; | |
2038 foreach ($packages as $package => $modules) { | |
2039 $rows = array(); | |
2040 foreach ($modules as $key => $module) { | |
2041 $row = array(); | |
2042 $description = drupal_render($form['description'][$key]); | |
2043 if (isset($form['status']['#incompatible_modules_core'][$key])) { | |
2044 unset($form['status'][$key]); | |
2045 $status = theme('image', 'misc/watchdog-error.png', t('incompatible'), t('Incompatible with this version of Drupal core')); | |
2046 $description .= '<div class="incompatible">'. t('This version is incompatible with the !core_version version of Drupal core.', array('!core_version' => VERSION)) .'</div>'; | |
2047 } | |
2048 elseif (isset($form['status']['#incompatible_modules_php'][$key])) { | |
2049 unset($form['status'][$key]); | |
2050 $status = theme('image', 'misc/watchdog-error.png', t('incompatible'), t('Incompatible with this version of PHP')); | |
2051 $php_required = $form['status']['#incompatible_modules_php'][$key]; | |
2052 if (substr_count($php_required, '.') < 2) { | |
2053 $php_required .= '.*'; | |
2054 } | |
2055 $description .= '<div class="incompatible">'. t('This module requires PHP version @php_required and is incompatible with PHP version !php_version.', array('@php_required' => $php_required, '!php_version' => phpversion())) .'</div>'; | |
2056 } | |
2057 else { | |
2058 $status = drupal_render($form['status'][$key]); | |
2059 } | |
2060 $row[] = array('data' => $status, 'class' => 'checkbox'); | |
2061 if (module_exists('throttle')) { | |
2062 $row[] = array('data' => drupal_render($form['throttle'][$key]), 'class' => 'checkbox'); | |
2063 } | |
2064 | |
2065 // Add labels only when there is also a checkbox. | |
2066 if (isset($form['status'][$key])) { | |
2067 $row[] = '<strong><label for="'. $form['status'][$key]['#id'] .'">'. drupal_render($form['name'][$key]) .'</label></strong>'; | |
2068 } | |
2069 else { | |
2070 $row[] = '<strong>'. drupal_render($form['name'][$key]) .'</strong>'; | |
2071 } | |
2072 | |
2073 $row[] = drupal_render($form['version'][$key]); | |
2074 $row[] = array('data' => $description, 'class' => 'description'); | |
2075 $rows[] = $row; | |
2076 } | |
2077 $fieldset = array( | |
2078 '#title' => t($package), | |
2079 '#collapsible' => TRUE, | |
2080 '#collapsed' => ($package == 'Core - required'), | |
2081 '#value' => theme('table', $header, $rows, array('class' => 'package')), | |
2082 ); | |
2083 $output .= theme('fieldset', $fieldset); | |
2084 } | |
2085 | |
2086 $output .= drupal_render($form); | |
2087 return $output; | |
2088 } | |
2089 | |
2090 /** | |
2091 * Themes a table of currently disabled modules. | |
2092 * | |
2093 * @ingroup themeable | |
2094 * @param $form | |
2095 * The form array representing the currently disabled modules. | |
2096 * @return | |
2097 * An HTML string representing the table. | |
2098 */ | |
2099 function theme_system_modules_uninstall($form) { | |
2100 // No theming for the confirm form. | |
2101 if (isset($form['confirm'])) { | |
2102 return drupal_render($form); | |
2103 } | |
2104 | |
2105 // Table headers. | |
2106 $header = array(t('Uninstall'), | |
2107 t('Name'), | |
2108 t('Description'), | |
2109 ); | |
2110 | |
2111 // Display table. | |
2112 $rows = array(); | |
2113 foreach (element_children($form['modules']) as $module) { | |
2114 $rows[] = array( | |
2115 array('data' => drupal_render($form['uninstall'][$module]), 'align' => 'center'), | |
2116 '<strong>'. drupal_render($form['modules'][$module]['name']) .'</strong>', | |
2117 array('data' => drupal_render($form['modules'][$module]['description']), 'class' => 'description'), | |
2118 ); | |
2119 } | |
2120 | |
2121 // Only display table if there are modules that can be uninstalled. | |
2122 if (empty($rows)) { | |
2123 $rows[] = array(array('data' => t('No modules are available to uninstall.'), 'colspan' => '3', 'align' => 'center', 'class' => 'message')); | |
2124 } | |
2125 | |
2126 $output = theme('table', $header, $rows); | |
2127 $output .= drupal_render($form); | |
2128 | |
2129 return $output; | |
2130 } | |
2131 | |
2132 /** | |
2133 * Theme the theme select form. | |
2134 * @param $form | |
2135 * An associative array containing the structure of the form. | |
2136 * @ingroup themeable | |
2137 */ | |
2138 function theme_system_theme_select_form($form) { | |
2139 foreach (element_children($form) as $key) { | |
2140 $row = array(); | |
2141 if (isset($form[$key]['description']) && is_array($form[$key]['description'])) { | |
2142 $row[] = drupal_render($form[$key]['screenshot']); | |
2143 $row[] = drupal_render($form[$key]['description']); | |
2144 $row[] = drupal_render($form['theme'][$key]); | |
2145 } | |
2146 $rows[] = $row; | |
2147 } | |
2148 | |
2149 $header = array(t('Screenshot'), t('Name'), t('Selected')); | |
2150 $output = theme('table', $header, $rows); | |
2151 return $output; | |
2152 } | |
2153 | |
2154 /** | |
2155 * Theme function for the system themes form. | |
2156 * | |
2157 * @param $form | |
2158 * An associative array containing the structure of the form. | |
2159 * @ingroup themeable | |
2160 */ | |
2161 function theme_system_themes_form($form) { | |
2162 foreach (element_children($form) as $key) { | |
2163 // Only look for themes | |
2164 if (!isset($form[$key]['info'])) { | |
2165 continue; | |
2166 } | |
2167 | |
2168 // Fetch info | |
2169 $info = $form[$key]['info']['#value']; | |
2170 // Localize theme description. | |
2171 $description = t($info['description']); | |
2172 // Make sure it is compatible and render the checkbox if so. | |
2173 if (isset($form['status']['#incompatible_themes_core'][$key])) { | |
2174 unset($form['status'][$key]); | |
2175 $status = theme('image', 'misc/watchdog-error.png', t('incompatible'), t('Incompatible with this version of Drupal core')); | |
2176 $description .= '<div class="incompatible">'. t('This version is incompatible with the !core_version version of Drupal core.', array('!core_version' => VERSION)) .'</div>'; | |
2177 } | |
2178 elseif (isset($form['status']['#incompatible_themes_php'][$key])) { | |
2179 unset($form['status'][$key]); | |
2180 $status = theme('image', 'misc/watchdog-error.png', t('incompatible'), t('Incompatible with this version of PHP')); | |
2181 $php_required = $form['status']['#incompatible_themes_php'][$key]; | |
2182 if (substr_count($php_required, '.') < 2) { | |
2183 $php_required .= '.*'; | |
2184 } | |
2185 $description .= '<div class="incompatible">'. t('This theme requires PHP version @php_required and is incompatible with PHP version !php_version.', array('@php_required' => $php_required, '!php_version' => phpversion())) .'</div>'; | |
2186 } | |
2187 else { | |
2188 $status = drupal_render($form['status'][$key]); | |
2189 } | |
2190 | |
2191 // Style theme info | |
2192 $theme = '<div class="theme-info"><h2>'. $info['name'] .'</h2><div class="description">'. $description .'</div></div>'; | |
2193 | |
2194 // Build rows | |
2195 $row = array(); | |
2196 $row[] = drupal_render($form[$key]['screenshot']); | |
2197 $row[] = $theme; | |
2198 $row[] = isset($info['version']) ? $info['version'] : ''; | |
2199 $row[] = array('data' => $status, 'align' => 'center'); | |
2200 if ($form['theme_default']) { | |
2201 $row[] = array('data' => drupal_render($form['theme_default'][$key]), 'align' => 'center'); | |
2202 $row[] = array('data' => drupal_render($form[$key]['operations']), 'align' => 'center'); | |
2203 } | |
2204 $rows[] = $row; | |
2205 } | |
2206 | |
2207 $header = array(t('Screenshot'), t('Name'), t('Version'), t('Enabled'), t('Default'), t('Operations')); | |
2208 $output = theme('table', $header, $rows); | |
2209 $output .= drupal_render($form); | |
2210 return $output; | |
2211 } |