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