system.module 75.9 KB
Newer Older
Dries Buytaert's avatar
 
Dries Buytaert committed
1
<?php
2
// $Id$
Dries Buytaert's avatar
 
Dries Buytaert committed
3

Dries Buytaert's avatar
   
Dries Buytaert committed
4
5
6
7
8
/**
 * @file
 * Configuration system that lets administrators modify the workings of the site.
 */

9
10
11
/**
 * The current system version.
 */
12
define('VERSION', '7.0-dev');
13
14
15
16

/**
 * Core API compatibility.
 */
17
define('DRUPAL_CORE_COMPATIBILITY', '7.x');
18

19
20
21
/**
 * Minimum supported version of PHP.
 */
22
define('DRUPAL_MINIMUM_PHP',    '5.2.0');
23

24
25
26
27
28
/**
 * Minimum recommended value of PHP memory_limit.
 */
define('DRUPAL_MINIMUM_PHP_MEMORY_LIMIT',    '16M');

29
30
31
/**
 * Minimum supported version of MySQL, if it is used.
 */
32
define('DRUPAL_MINIMUM_MYSQL',  '5.0');
33
34
35
36

/**
 * Minimum supported version of PostgreSQL, if it is used.
 */
37
define('DRUPAL_MINIMUM_PGSQL',  '8.1');
38
39
40
41

/**
 * Maximum age of temporary files in seconds.
 */
42
43
define('DRUPAL_MAXIMUM_TEMP_FILE_AGE', 1440);

Dries Buytaert's avatar
   
Dries Buytaert committed
44
45
46
/**
 * Implementation of hook_help().
 */
47
function system_help($path, $arg) {
48
49
  global $base_url;

50
  switch ($path) {
51
    case 'admin/help#system':
52
53
54
55
56
57
      $output = '<p>' . t('The system module is at the foundation of your Drupal website, and provides basic but extensible functionality for use by other modules and themes. Some integral elements of Drupal are contained in and managed by the system module, including caching, enabling or disabling of modules and themes, preparing and displaying the administrative page, and configuring fundamental site settings. A number of key system maintenance operations are also part of the system module.') . '</p>';
      $output .= '<p>' . t('The system module provides:') . '</p>';
      $output .= '<ul><li>' . t('support for enabling and disabling <a href="@modules">modules</a>. Drupal comes packaged with a number of core modules; each module provides a discrete set of features and may be enabled depending on the needs of your site. A wide array of additional modules contributed by members of the Drupal community are available for download at the <a href="@drupal-modules">Drupal.org module page</a>.', array('@modules' => url('admin/build/modules'), '@drupal-modules' => 'http://drupal.org/project/modules')) . '</li>';
      $output .= '<li>' . t('support for enabling and disabling <a href="@themes">themes</a>, which determine the design and presentation of your site. Drupal comes packaged with several core themes and additional contributed themes are available at the <a href="@drupal-themes">Drupal.org theme page</a>.', array('@themes' => url('admin/build/themes'), '@drupal-themes' => 'http://drupal.org/project/themes')) . '</li>';
      $output .= '<li>' . t('a robust <a href="@cache-settings">caching system</a> that allows the efficient re-use of previously-constructed web pages and web page components. Drupal stores the pages requested by anonymous users in a compressed format; depending on your site configuration and the amount of your web traffic tied to anonymous visitors, Drupal\'s caching system may significantly increase the speed of your site.', array('@cache-settings' => url('admin/settings/performance'))) . '</li>';
      $output .= '<li>' . t('a set of routine administrative operations that rely on a correctly-configured <a href="@cron">cron maintenance task</a> to run automatically. A number of other modules, including the feed aggregator, and search also rely on <a href="@cron">cron maintenance tasks</a>. For more information, see the online handbook entry for <a href="@handbook">configuring cron jobs</a>.', array('@cron' => url('admin/reports/status'), '@handbook' => 'http://drupal.org/cron')) . '</li>';
58
      $output .= '<li>' . t('basic configuration options for your site, including <a href="@date-settings">date and time settings</a>, <a href="@file-system">file system settings</a>, <a href="@clean-url">clean URL support</a>, <a href="@site-info">site name and other information</a>, and a <a href="@site-maintenance">site maintenance</a> function for taking your site temporarily offline.', array('@date-settings' => url('admin/settings/date-time'), '@file-system' => url('admin/settings/file-system'), '@clean-url' => url('admin/settings/clean-urls'), '@site-info' => url('admin/settings/site-information'), '@site-maintenance' => url('admin/settings/site-maintenance'))) . '</li></ul>';
59
      $output .= '<p>' . t('For more information, see the online handbook entry for <a href="@system">System module</a>.', array('@system' => 'http://drupal.org/handbook/modules/system/')) . '</p>';
60
      return $output;
61
    case 'admin':
62
      return '<p>' . t('Welcome to the administration section. Here you may control how your site functions.') . '</p>';
63
    case 'admin/by-module':
64
      return '<p>' . t('This page shows you all available administration tasks for each module.') . '</p>';
65
    case 'admin/build/themes':
66
67
      $output = '<p>' . t('Select which themes are available to your users and specify the default theme. To configure site-wide display settings, click the "configure" task above. Alternatively, to override these settings in a specific theme, click the "configure" link for that theme. Note that different themes may have different regions available for displaying content; for consistency in presentation, you may wish to enable only one theme.') . '</p>';
      $output .= '<p>' . t('To change the appearance of your site, a number of <a href="@themes">contributed themes</a> are available.', array('@themes' => 'http://drupal.org/project/themes')) . '</p>';
68
      return $output;
69
    case 'admin/build/themes/settings/' . $arg[4]:
70
      $reference = explode('.', $arg[4], 2);
71
      $theme = array_pop($reference);
72
      return '<p>' . t('These options control the display settings for the <code>%template</code> theme. When your site is displayed using this theme, these settings will be used. By clicking "Reset to defaults," you can choose to use the <a href="@global">global settings</a> for this theme.', array('%template' => $theme, '@global' => url('admin/build/themes/settings'))) . '</p>';
73
    case 'admin/build/themes/settings':
74
      return '<p>' . t('These options control the default display settings for your entire site, across all themes. Unless they have been overridden by a specific theme, these settings will be used.') . '</p>';
75
    case 'admin/build/modules':
76
      $output = '<p>' . t('Modules are plugins that extend Drupal\'s core functionality. Enable modules by selecting the <em>Enabled</em> checkboxes below and clicking the <em>Save configuration</em> button. Once a module is enabled, new <a href="@permissions">permissions</a> may be available.)', array('@permissions' => url('admin/user/permissions'))) . '</p>';
77
78
79
      $output .= '<p>' . t('It is important that <a href="@update-php">update.php</a> is run every time a module is updated to a newer version.', array('@update-php' => $base_url . '/update.php')) . '</p>';
      $output .= '<p>' . t('You can find all administration tasks belonging to a particular module on the <a href="@by-module">administration by module page</a>.', array('@by-module' => url('admin/by-module'))) . '</p>';
      $output .= '<p>' . t('To extend the functionality of your site, a number of <a href="@modules">contributed modules</a> are available.', array('@modules' => 'http://drupal.org/project/modules')) . '</p>';
80
      return $output;
81
    case 'admin/build/modules/uninstall':
82
      return '<p>' . t('The uninstall process removes all data related to a module. To uninstall a module, you must first disable it. Not all modules support this feature.') . '</p>';
83
84
    case 'admin/build/block/configure':
      if ($arg[4] == 'system' && $arg[5] == 0) {
85
        return '<p>' . t('The <em>Powered by Drupal</em> block is an optional link to the home page of the Drupal project. While there is absolutely no requirement that sites feature this link, it may be used to show support for Drupal.') . '</p>';
86
      }
87
      break;
88
89
    case 'admin/settings/actions':
    case 'admin/settings/actions/manage':
90
91
      $output = '<p>' . t('Actions are individual tasks that the system can do, such as unpublishing a piece of content or banning a user. Modules, such as the trigger module, can fire these actions when certain system events happen; for example, when a new post is added or when a user logs in. Modules may also provide additional actions.') . '</p>';
      $output .= '<p>' . t('There are two types of actions: simple and advanced. Simple actions do not require any additional configuration, and are listed here automatically. Advanced actions can do more than simple actions; for example, send an e-mail to a specified address, or check for certain words within a piece of content. These actions need to be created and configured first before they may be used. To create an advanced action, select the action from the drop-down below and click the <em>Create</em> button.') . '</p>';
92
      if (module_exists('trigger')) {
93
        $output .= '<p>' . t('You may proceed to the <a href="@url">Triggers</a> page to assign these actions to system events.', array('@url' => url('admin/build/trigger'))) . '</p>';
94
      }
95
      return $output;
96
97
    case 'admin/settings/actions/configure':
      return t('An advanced action offers additional configuration options which may be filled out below. Changing the <em>Description</em> field is recommended, in order to better identify the precise action taking place. This description will be displayed in modules such as the trigger module when assigning actions to system events, so it is best if it is as descriptive as possible (for example, "Send e-mail to Moderation Team" rather than simply "Send e-mail").');
98
    case 'admin/settings/ip-blocking':
99
      return '<p>' . t('IP addresses listed here are blocked from your site before any modules are loaded. You may add IP addresses to the list, or delete existing entries.') . '</p>';
100
    case 'admin/reports/status':
101
      return '<p>' . t("Here you can find a short overview of your site's parameters as well as any problems detected with your installation. It may be useful to copy and paste this information into support requests filed on drupal.org's support forums and project issue queues.") . '</p>';
102
  }
Dries Buytaert's avatar
   
Dries Buytaert committed
103
104
}

105
106
107
/**
 * Implementation of hook_theme().
 */
108
function system_theme() {
109
  return array_merge(drupal_common_theme(), array(
110
111
    'system_theme_select_form' => array(
      'arguments' => array('form' => NULL),
112
      'file' => 'system.admin.inc',
113
114
115
    ),
    'system_themes_form' => array(
      'arguments' => array('form' => NULL),
116
      'file' => 'system.admin.inc',
117
    ),
118
    'system_modules_fieldset' => array(
119
      'arguments' => array('form' => NULL),
120
      'file' => 'system.admin.inc',
121
    ),
122
123
124
125
    'system_modules_incompatible' => array(
      'arguments' => array('message' => NULL),
      'file' => 'system.admin.inc',
    ),
126
127
    'system_modules_uninstall' => array(
      'arguments' => array('form' => NULL),
128
      'file' => 'system.admin.inc',
129
130
131
    ),
    'status_report' => array(
      'arguments' => array('requirements' => NULL),
132
      'file' => 'system.admin.inc',
133
134
135
    ),
    'admin_page' => array(
      'arguments' => array('blocks' => NULL),
136
      'file' => 'system.admin.inc',
137
138
139
    ),
    'admin_block' => array(
      'arguments' => array('block' => NULL),
140
      'file' => 'system.admin.inc',
141
142
143
    ),
    'admin_block_content' => array(
      'arguments' => array('content' => NULL),
144
      'file' => 'system.admin.inc',
145
146
147
    ),
    'system_admin_by_module' => array(
      'arguments' => array('menu_items' => NULL),
148
      'file' => 'system.admin.inc',
149
    ),
150
151
152
    'system_powered_by' => array(
      'arguments' => array('image_path' => NULL),
    ),
153
154
155
156
157
158
    'meta_generator_html' => array(
      'arguments' => array('version' => NULL),
    ),
    'meta_generator_header' => array(
      'arguments' => array('version' => NULL),
    ),
159
    'system_compact_link' => array(),
160
161
  ));
}
162

Dries Buytaert's avatar
   
Dries Buytaert committed
163
164
165
/**
 * Implementation of hook_perm().
 */
Dries Buytaert's avatar
 
Dries Buytaert committed
166
function system_perm() {
167
168
169
170
171
172
173
  return array(
    'administer site configuration' => t('Configure site-wide settings such as module or theme administration settings.'),
    'access administration pages' => t('View the administration panel and browse the help system.'),
    'administer actions' => t('Manage the actions defined for your site.'),
    'access site reports' => t('View reports from system logs and other status information.'),
    'select different theme' => t('Select a theme other than the default theme set by the site administrator.'),
    'administer files' => t('Manage user-uploaded files.'),
174
    'block IP addresses' => t('Block IP addresses from accessing your site.'),
175
  );
Dries Buytaert's avatar
   
Dries Buytaert committed
176
177
}

178
179
180
181
182
/**
 * Implementation of hook_elements().
 */
function system_elements() {
  // Top level form
183
184
185
186
187
188
189
190
191
192
193
194
195
  $type['form'] = array(
    '#method' => 'post',
    '#action' => request_uri(),
  );

  /**
   * Input elements.
   */
  $type['submit'] = array(
    '#input' => TRUE,
    '#name' => 'op',
    '#button_type' => 'submit',
    '#executes_submit_callback' => TRUE,
196
    '#process' => array('form_process_ahah'),
197
198
199
200
201
202
203
  );

  $type['button'] = array(
    '#input' => TRUE,
    '#name' => 'op',
    '#button_type' => 'submit',
    '#executes_submit_callback' => FALSE,
204
    '#process' => array('form_process_ahah'),
205
206
207
208
209
210
  );

  $type['image_button'] = array(
    '#input' => TRUE,
    '#button_type' => 'submit',
    '#executes_submit_callback' => TRUE,
211
    '#process' => array('form_process_ahah'),
212
213
214
215
216
217
218
219
220
221
    '#return_value' => TRUE,
    '#has_garbage_value' => TRUE,
    '#src' => NULL,
  );

  $type['textfield'] = array(
    '#input' => TRUE,
    '#size' => 60,
    '#maxlength' => 128,
    '#autocomplete_path' => FALSE,
222
    '#process' => array('form_process_ahah'),
223
224
225
226
227
228
  );

  $type['password'] = array(
    '#input' => TRUE,
    '#size' => 60,
    '#maxlength' => 128,
229
    '#process' => array('form_process_ahah'),
230
231
232
233
  );

  $type['password_confirm'] = array(
    '#input' => TRUE,
234
    '#process' => array('form_process_password_confirm'),
235
236
237
238
239
240
241
  );

  $type['textarea'] = array(
    '#input' => TRUE,
    '#cols' => 60,
    '#rows' => 5,
    '#resizable' => TRUE,
242
    '#process' => array('form_process_ahah'),
243
244
245
246
  );

  $type['radios'] = array(
    '#input' => TRUE,
247
    '#process' => array('form_process_radios'),
248
249
250
251
252
  );

  $type['radio'] = array(
    '#input' => TRUE,
    '#default_value' => NULL,
253
    '#process' => array('form_process_ahah'),
254
255
256
257
258
  );

  $type['checkboxes'] = array(
    '#input' => TRUE,
    '#tree' => TRUE,
259
    '#process' => array('form_process_checkboxes'),
260
261
262
263
264
  );

  $type['checkbox'] = array(
    '#input' => TRUE,
    '#return_value' => 1,
265
    '#process' => array('form_process_ahah'),
266
267
268
269
270
271
  );

  $type['select'] = array(
    '#input' => TRUE,
    '#size' => 0,
    '#multiple' => FALSE,
272
    '#process' => array('form_process_ahah'),
273
274
275
276
277
278
  );

  $type['weight'] = array(
    '#input' => TRUE,
    '#delta' => 10,
    '#default_value' => 0,
279
    '#process' => array('form_process_weight', 'form_process_ahah'),
280
281
282
283
284
  );

  $type['date'] = array(
    '#input' => TRUE,
    '#element_validate' => array('date_validate'),
285
    '#process' => array('form_process_date'),
286
287
288
289
290
291
292
293
294
295
296
297
  );

  $type['file'] = array(
    '#input' => TRUE,
    '#size' => 60,
  );


  /**
   * Form structure.
   */
  $type['item'] = array(
298
    '#markup' => '',
299
300
301
302
  );

  $type['hidden'] = array(
    '#input' => TRUE,
303
    '#process' => array('form_process_ahah'),
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
  );

  $type['value'] = array(
    '#input' => TRUE,
  );

  $type['markup'] = array(
    '#prefix' => '',
    '#suffix' => '',
  );

  $type['fieldset'] = array(
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#value' => NULL,
319
    '#process' => array('form_process_ahah'),
320
321
322
323
324
325
  );

  $type['token'] = array(
    '#input' => TRUE,
  );

326
327
328
  return $type;
}

Dries Buytaert's avatar
   
Dries Buytaert committed
329
/**
Dries Buytaert's avatar
   
Dries Buytaert committed
330
 * Implementation of hook_menu().
Dries Buytaert's avatar
   
Dries Buytaert committed
331
 */
332
333
function system_menu() {
  $items['system/files'] = array(
334
    'title' => 'File download',
335
336
337
338
339
    'page callback' => 'file_download',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  $items['admin'] = array(
340
    'title' => 'Administer',
341
342
343
344
345
    'access arguments' => array('access administration pages'),
    'page callback' => 'system_main_admin_page',
    'weight' => 9,
  );
  $items['admin/compact'] = array(
346
    'title' => 'Compact mode',
347
    'page callback' => 'system_admin_compact_page',
348
    'access arguments' => array('access administration pages'),
349
350
351
    'type' => MENU_CALLBACK,
  );
  $items['admin/by-task'] = array(
352
    'title' => 'By task',
353
    'page callback' => 'system_main_admin_page',
354
    'access arguments' => array('access administration pages'),
355
356
357
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );
  $items['admin/by-module'] = array(
358
    'title' => 'By module',
359
    'page callback' => 'system_admin_by_module',
360
    'access arguments' => array('access administration pages'),
361
362
363
    'type' => MENU_LOCAL_TASK,
    'weight' => 2,
  );
364
365
366
367
368
369
  $items['admin/content'] = array(
    'title' => 'Content management',
    'description' => "Manage your site's content.",
    'position' => 'left',
    'weight' => -10,
    'page callback' => 'system_admin_menu_block_page',
370
    'access arguments' => array('access administration pages'),
371
372
  );

373
374
  // menu items that are basically just menu blocks
  $items['admin/settings'] = array(
375
376
    'title' => 'Site configuration',
    'description' => 'Adjust basic site configuration options.',
377
378
379
    'position' => 'right',
    'weight' => -5,
    'page callback' => 'system_settings_overview',
380
    'access arguments' => array('access administration pages'),
381
382
  );
  $items['admin/build'] = array(
383
384
    'title' => 'Site building',
    'description' => 'Control how your site looks and feels.',
385
386
387
    'position' => 'right',
    'weight' => -10,
    'page callback' => 'system_admin_menu_block_page',
388
    'access arguments' => array('access administration pages'),
389
390
  );
  $items['admin/settings/admin'] = array(
391
392
    'title' => 'Administration theme',
    'description' => 'Settings for how your administrative pages should look.',
393
394
395
    'position' => 'left',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_admin_theme_settings'),
396
    'access arguments' => array('administer site configuration'),
397
398
399
400
    'block callback' => 'system_admin_theme_settings',
  );
  // Themes:
  $items['admin/build/themes'] = array(
401
402
    'title' => 'Themes',
    'description' => 'Change which theme your site uses or allows users to set.',
403
    'page callback' => 'drupal_get_form',
404
    'page arguments' => array('system_themes_form', NULL),
405
    'access arguments' => array('administer site configuration'),
406
407
  );
  $items['admin/build/themes/select'] = array(
408
409
    'title' => 'List',
    'description' => 'Select the default theme.',
410
411
412
413
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -1,
  );
  $items['admin/build/themes/settings'] = array(
414
    'title' => 'Configure',
415
    'page arguments' => array('system_theme_settings'),
416
    'access arguments' => array('administer site configuration'),
417
418
419
420
    'type' => MENU_LOCAL_TASK,
  );
  // Theme configuration subtabs
  $items['admin/build/themes/settings/global'] = array(
421
    'title' => 'Global settings',
422
423
424
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -1,
  );
Dries Buytaert's avatar
   
Dries Buytaert committed
425

426
  foreach (list_themes() as $theme) {
427
    $items['admin/build/themes/settings/' . $theme->name] = array(
428
429
430
431
432
433
      'title' => $theme->info['name'],
      'page arguments' => array('system_theme_settings', $theme->name),
      'type' => MENU_LOCAL_TASK,
      'access callback' => '_system_themes_access',
      'access arguments' => array($theme),
    );
Dries Buytaert's avatar
   
Dries Buytaert committed
434
  }
435

436
437
  // Modules:
  $items['admin/build/modules'] = array(
438
439
    'title' => 'Modules',
    'description' => 'Enable or disable add-on modules for your site.',
440
441
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_modules'),
442
    'access arguments' => array('administer site configuration'),
443
444
  );
  $items['admin/build/modules/list'] = array(
445
    'title' => 'List',
446
447
448
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );
  $items['admin/build/modules/list/confirm'] = array(
449
    'title' => 'List',
450
    'access arguments' => array('administer site configuration'),
451
452
453
    'type' => MENU_CALLBACK,
  );
  $items['admin/build/modules/uninstall'] = array(
454
    'title' => 'Uninstall',
455
    'page arguments' => array('system_modules_uninstall'),
456
    'access arguments' => array('administer site configuration'),
457
458
459
    'type' => MENU_LOCAL_TASK,
  );
  $items['admin/build/modules/uninstall/confirm'] = array(
460
    'title' => 'Uninstall',
461
    'access arguments' => array('administer site configuration'),
462
463
    'type' => MENU_CALLBACK,
  );
Dries Buytaert's avatar
   
Dries Buytaert committed
464

465
  // Actions:
466
  $items['admin/settings/actions'] = array(
467
468
469
470
471
    'title' => 'Actions',
    'description' => 'Manage the actions defined for your site.',
    'access arguments' => array('administer actions'),
    'page callback' => 'system_actions_manage'
  );
472
  $items['admin/settings/actions/manage'] = array(
473
474
475
476
477
478
    'title' => 'Manage actions',
    'description' => 'Manage the actions defined for your site.',
    'page callback' => 'system_actions_manage',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -2,
  );
479
480
  $items['admin/settings/actions/configure'] = array(
    'title' => 'Configure an advanced action',
481
482
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_actions_configure'),
483
    'access arguments' => array('administer actions'),
484
485
    'type' => MENU_CALLBACK,
  );
486
  $items['admin/settings/actions/delete/%actions'] = array(
487
488
489
490
    'title' => 'Delete action',
    'description' => 'Delete an action.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_actions_delete_form', 4),
491
    'access arguments' => array('administer actions'),
492
493
    'type' => MENU_CALLBACK,
  );
494
  $items['admin/settings/actions/orphan'] = array(
495
496
    'title' => 'Remove orphans',
    'page callback' => 'system_actions_remove_orphans',
497
    'access arguments' => array('administer actions'),
498
499
500
    'type' => MENU_CALLBACK,
  );

501
502
503
504
505
506
507
  // IP address blocking.
  $items['admin/settings/ip-blocking'] = array(
    'title' => 'IP address blocking',
    'description' => 'Manage blocked IP addresses.',
    'page callback' => 'system_ip_blocking',
    'access arguments' => array('block IP addresses'),
  );
508
509
510
511
512
513
514
  $items['admin/settings/ip-blocking/%'] = array(
    'title' => 'IP address blocking',
    'description' => 'Manage blocked IP addresses.',
    'page callback' => 'system_ip_blocking',
    'access arguments' => array('block IP addresses'),
    'type' => MENU_CALLBACK,
  );
515
516
517
518
519
520
521
522
  $items['admin/settings/ip-blocking/delete/%blocked_ip'] = array(
    'title' => 'Delete IP address',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_ip_blocking_delete', 4),
    'access arguments' => array('block IP addresses'),
    'type' => MENU_CALLBACK,
  );

523
524
  // Settings:
  $items['admin/settings/site-information'] = array(
525
526
    'title' => 'Site information',
    'description' => 'Change basic site information, such as the site name, slogan, e-mail address, mission, front page and more.',
527
528
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_site_information_settings'),
529
    'access arguments' => array('administer site configuration'),
530
531
  );
  $items['admin/settings/error-reporting'] = array(
532
533
    'title' => 'Error reporting',
    'description' => 'Control how Drupal deals with errors including 403/404 errors as well as PHP error reporting.',
534
535
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_error_reporting_settings'),
536
    'access arguments' => array('administer site configuration'),
537
  );
538
  $items['admin/settings/logging'] = array(
539
540
    'title' => 'Logging and alerts',
    'description' => "Settings for logging and alerts modules. Various modules can route Drupal's system events to different destination, such as syslog, database, email, ...etc.",
541
    'page callback' => 'system_logging_overview',
542
    'access arguments' => array('administer site configuration'),
543
  );
544
  $items['admin/settings/performance'] = array(
545
    'title' => 'Performance',
546
    'description' => 'Enable or disable page caching for anonymous users and set CSS and JS bandwidth optimization options.',
547
548
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_performance_settings'),
549
    'access arguments' => array('administer site configuration'),
550
551
  );
  $items['admin/settings/file-system'] = array(
552
553
    'title' => 'File system',
    'description' => 'Tell Drupal where to store uploaded files and how they are accessed.',
554
555
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_file_system_settings'),
556
    'access arguments' => array('administer site configuration'),
557
558
  );
  $items['admin/settings/image-toolkit'] = array(
559
560
    'title' => 'Image toolkit',
    'description' => 'Choose which image toolkit to use if you have installed optional toolkits.',
561
562
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_image_toolkit_settings'),
563
    'access arguments' => array('administer site configuration'),
564
565
  );
  $items['admin/content/rss-publishing'] = array(
566
567
    'title' => 'RSS publishing',
    'description' => 'Configure the number of items per feed and whether feeds should be titles/teasers/full-text.',
568
569
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_rss_feeds_settings'),
570
    'access arguments' => array('administer site configuration'),
571
572
  );
  $items['admin/settings/date-time'] = array(
573
574
    'title' => 'Date and time',
    'description' => "Settings for how Drupal displays date and time, as well as the system's default timezone.",
575
576
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_date_time_settings'),
577
    'access arguments' => array('administer site configuration'),
578
  );
579
  $items['admin/settings/date-time/lookup'] = array(
580
    'title' => 'Date and time lookup',
581
582
    'type' => MENU_CALLBACK,
    'page callback' => 'system_date_time_lookup',
583
    'access arguments' => array('administer site configuration'),
584
  );
585
  $items['admin/settings/site-maintenance'] = array(
586
    'title' => 'Site maintenance',
587
    'description' => 'Take the site offline for maintenance or bring it back online.',
588
589
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_site_maintenance_settings'),
590
    'access arguments' => array('administer site configuration'),
591
592
  );
  $items['admin/settings/clean-urls'] = array(
593
594
    'title' => 'Clean URLs',
    'description' => 'Enable or disable clean URLs for your site.',
595
596
    'page callback' => 'drupal_get_form',
    'page arguments' => array('system_clean_url_settings'),
597
    'access arguments' => array('administer site configuration'),
598
  );
599
600
601
602
603
604
605
  $items['admin/settings/clean-urls/check'] = array(
    'title' => 'Clean URL check',
    'page callback' => 'drupal_json',
    'page arguments' => array(array('status' => TRUE)),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
606
  // Menu handler to test that drupal_http_request() works locally.
607
  // @see system_check_http_request()
608
609
610
611
612
613
614
  $items['admin/reports/request-test'] = array(
    'title' => 'Request test',
    'page callback' => 'printf',
    'page arguments' => array('request test'),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
615

616
617
618
619
  // Reports:
  $items['admin/reports'] = array(
    'title' => 'Reports',
    'description' => 'View reports from system logs and other status information.',
620
    'page callback' => 'system_admin_menu_block_page',
621
    'access arguments' => array('access site reports'),
622
623
624
    'weight' => 5,
    'position' => 'left',
  );
625
  $items['admin/reports/status'] = array(
626
627
    'title' => 'Status report',
    'description' => "Get a status report about your site's operation and any detected problems.",
628
629
630
631
    'page callback' => 'system_status',
    'weight' => 10,
    'access arguments' => array('administer site configuration'),
  );
632
  $items['admin/reports/status/run-cron'] = array(
633
    'title' => 'Run cron',
634
    'page callback' => 'system_run_cron',
635
    'access arguments' => array('administer site configuration'),
636
637
    'type' => MENU_CALLBACK,
  );
638
  $items['admin/reports/status/php'] = array(
639
    'title' => 'PHP',
640
    'page callback' => 'system_php',
641
    'access arguments' => array('administer site configuration'),
642
643
    'type' => MENU_CALLBACK,
  );
644
  $items['admin/reports/status/sql'] = array(
645
    'title' => 'SQL',
646
    'page callback' => 'system_sql',
647
    'access arguments' => array('administer site configuration'),
648
649
    'type' => MENU_CALLBACK,
  );
650
651
652
653
654
655
  // Default page for batch operations
  $items['batch'] = array(
    'page callback' => 'system_batch_page',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
Dries Buytaert's avatar
   
Dries Buytaert committed
656
  return $items;
Dries Buytaert's avatar
 
Dries Buytaert committed
657
658
}

659
660
661
662
663
664
665
666
667
668
669
670
671
672
/**
 * Retrieve a blocked IP address from the database.
 *
 * @param $iid integer
 *   The ID of the blocked IP address to retrieve.
 *
 * @return
 *   The blocked IP address from the database as an array.
 */
function blocked_ip_load($iid) {
  $blocked_ip = db_fetch_array(db_query("SELECT * FROM {blocked_ips} WHERE iid = %d", $iid));
  return $blocked_ip;
}

673
674
675
676
/**
 * Menu item access callback - only admin or enabled themes can be accessed.
 */
function _system_themes_access($theme) {
677
  return user_access('administer site configuration') && ($theme->status || $theme->name == variable_get('admin_theme', '0'));
678
679
}

680
681
682
/**
 * Implementation of hook_init().
 */
683
684
function system_init() {
  // Use the administrative theme if the user is looking at a page in the admin/* path.
685
  if (arg(0) == 'admin' || (variable_get('node_admin_theme', '0') && arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit'))) {
686
687
    global $custom_theme;
    $custom_theme = variable_get('admin_theme', '0');
688
    drupal_add_css(drupal_get_path('module', 'system') . '/admin.css', 'module');
689
690
691
  }

  // Add the CSS for this module.
692
693
694
  drupal_add_css(drupal_get_path('module', 'system') . '/defaults.css', 'module');
  drupal_add_css(drupal_get_path('module', 'system') . '/system.css', 'module');
  drupal_add_css(drupal_get_path('module', 'system') . '/system-menus.css', 'module');
695
696
697
698
699
700
701
702
703

  // Get the major version
  list($version,) = explode('.', VERSION);

  // Emit the META tag in the HTML HEAD section
  theme('meta_generator_html', $version);

  // Emit the HTTP Header too
  theme('meta_generator_header', $version);
704
705
}

Dries Buytaert's avatar
   
Dries Buytaert committed
706
707
708
709
710
/**
 * Implementation of hook_user().
 *
 * Allows users to individually set their theme and time zone.
 */
711
function system_user($type, $edit, &$user, $category = NULL) {
712
  if ($type == 'form' && $category == 'account') {
713
    $form['theme_select'] = system_theme_select_form(t('Selecting a different theme will change the look and feel of the site.'), isset($edit['theme']) ? $edit['theme'] : NULL, 2);
714

715
    if (variable_get('configurable_timezones', 1)) {
Steven Wittens's avatar
Steven Wittens committed
716
      $zones = _system_zonelist();
717
      $form['timezone'] = array(
718
        '#type' => 'fieldset',
719
720
721
722
        '#title' => t('Locale settings'),
        '#weight' => 6,
        '#collapsible' => TRUE,
      );
723
      $form['timezone']['timezone'] = array(
724
725
726
727
728
        '#type' => 'select',
        '#title' => t('Time zone'),
        '#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
        '#options' => $zones,
        '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.'),
729
      );
Dries Buytaert's avatar
   
Dries Buytaert committed
730
    }
731

732
    return $form;
Dries Buytaert's avatar
   
Dries Buytaert committed
733
  }
Dries Buytaert's avatar
   
Dries Buytaert committed
734
735
}

736
/**
737
738
 * Implementation of hook_block().
 *
739
740
 * Generate a block with a promotional link to Drupal.org.
 */
741
function system_block($op = 'list', $delta = '', $edit = NULL) {
742
  switch ($op) {
743
    case 'list':
744
      $blocks['powered-by'] = array(
745
746
        'info' => t('Powered by Drupal'),
        'weight' => '10',
747
748
         // Not worth caching.
        'cache' => BLOCK_NO_CACHE,
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
      );
      return $blocks;
    case 'configure':
      // Compile a list of fields to show
      $form['wrapper']['color'] = array(
        '#type' => 'select',
        '#title' => t('Badge color'),
        '#default_value' => variable_get('drupal_badge_color', 'powered-blue'),
        '#options' => array('powered-black' => t('Black'), 'powered-blue' => t('Blue'), 'powered-gray' => t('Gray')),
      );
      $form['wrapper']['size'] = array(
        '#type' => 'select',
        '#title' => t('Badge size'),
        '#default_value' => variable_get('drupal_badge_size', '80x15'),
        '#options' => array('80x15' => t('Small'), '88x31' => t('Medium'), '135x42' => t('Large')),
      );
      return $form;
    case 'save':
      variable_set('drupal_badge_color', $edit['color']);
      variable_set('drupal_badge_size', $edit['size']);
      break;
    case 'view':
771
      $image_path = 'misc/' . variable_get('drupal_badge_color', 'powered-blue') . '-' . variable_get('drupal_badge_size', '80x15') . '.png';
772
773
774
775
776
777
      $block['subject'] = NULL; // Don't display a title
      $block['content'] = theme('system_powered_by', $image_path);
      return $block;
  }
}

778
779
/**
 * Provide a single block on the administration overview page.
780
781
782
 *
 * @param $item
 *   The menu item to be displayed.
783
 */
784
function system_admin_menu_block($item) {
785
  $content = array();
786
  if (!isset($item['mlid'])) {
787
    $item += db_fetch_array(db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = '%s' AND module = 'system'", $item['path']));
788
  }
789
  $result = db_query("
790
    SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
791
    FROM {menu_links} ml
792
    LEFT JOIN {menu_router} m ON ml.router_path = m.path
793
    WHERE ml.plid = %d AND ml.menu_name = '%s' AND hidden = 0", $item['mlid'], $item['menu_name']);
794
  while ($item = db_fetch_array($result)) {
795
    _menu_link_translate($item);
796
    if (!$item['access']) {
797
      continue;
798
    }
799
800
    // The link 'description' either derived from the hook_menu 'description' or
    // entered by the user via menu module is saved as the title attribute.
801
802
    if (!empty($item['localized_options']['attributes']['title'])) {
      $item['description'] = $item['localized_options']['attributes']['title'];
803
804
805
    }
    // Prepare for sorting as in function _menu_tree_check_access().
    // The weight is offset so it is always positive, with a uniform 5-digits.
806
    $content[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $item;
807
  }
808
  ksort($content);
809
810
811
  return $content;
}

812
813
814
/**
 * Process admin theme form submissions.
 */
815
function system_admin_theme_submit($form, &$form_state) {
816
  // If we're changing themes, make sure the theme has its blocks initialized.
817
  if ($form_state['values']['admin_theme'] && $form_state['values']['admin_theme'] != variable_get('admin_theme', '0')) {
818
819
    $result = db_result(db_query("SELECT COUNT(*) FROM {blocks} WHERE theme = '%s'", $form_state['values']['admin_theme']));
    if (!$result) {
820
      system_initialize_theme_blocks($form_state['values']['admin_theme']);
821
822
823
824
    }
  }
}

825
/**
826
827
828
829
830
831
832
833
834
835
836
 * Returns a fieldset containing the theme select form.
 *
 * @param $description
 *    description of the fieldset
 * @param $default_value
 *    default value of theme radios
 * @param $weight
 *    weight of the fieldset
 * @return
 *    a form array
 */
837
function system_theme_select_form($description = '', $default_value = '', $weight = 0) {
838
  if (user_access('select different theme')) {
839
    $enabled = array();
840
841
842
    $themes = list_themes();

    foreach ($themes as $theme) {
843
844
845
846
847
848
849
850
851
      if ($theme->status) {
        $enabled[] = $theme;
      }
    }

    if (count($enabled) > 1) {
      ksort($enabled);

      $form['themes'] = array(
852
853
854
855
        '#type' => 'fieldset',
        '#title' => t('Theme configuration'),
        '#description' => $description,
        '#collapsible' => TRUE,
856
857
858
859
860
        '#theme' => 'system_theme_select_form'
      );

      foreach ($enabled as $info) {
        // For the default theme, revert to an empty string so the user's theme updates when the site theme is changed.
861
        $info->key = $info->name == variable_get('theme_default', 'garland') ? '' : $info->name;
862

863
864
865
866
867
868
869
870
871
872
873
        $screenshot = NULL;
        $theme_key = $info->name;
        while ($theme_key) {
          if (file_exists($themes[$theme_key]->info['screenshot'])) {
            $screenshot = $themes[$theme_key]->info['screenshot'];
            break;
          }
          $theme_key = isset($themes[$theme_key]->info['base theme']) ? $themes[$theme_key]->info['base theme'] : NULL;
        }

        $screenshot = $screenshot ? theme('image', $screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), FALSE) : t('no screenshot');
874

875
876
        $form['themes'][$info->key]['screenshot'] = array('#markup' => $screenshot);
        $form['themes'][$info->key]['description'] = array('#type' => 'item', '#title' => $info->name, '#markup' => dirname($info->filename) . ($info->name == variable_get('theme_default', 'garland') ? '<br /> <em>' . t('(site default theme)') . '</em>' : ''));
877
878
879
880
881
882
883
884
885
886
        $options[$info->key] = '';
      }

      $form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $default_value ? $default_value : '');
      $form['#weight'] = $weight;
      return $form;
    }
  }
}

887
888
/**
 * Checks the existence of the directory specified in $form_element. This
Dries Buytaert's avatar
Dries Buytaert committed
889
 * function is called from the system_settings form to check both the
890
891
892
893
894
895
896
 * file_directory_path and file_directory_temp directories. If validation
 * fails, the form element is flagged with an error from within the
 * file_check_directory function.
 *
 * @param $form_element
 *   The form element containing the name of the directory to check.
 */
897
function system_check_directory($form_element) {
898
899
900
901
  file_check_directory($form_element['#value'], FILE_CREATE_DIRECTORY, $form_element['#parents'][0]);
  return $form_element;
}

Dries Buytaert's avatar
   
Dries Buytaert committed
902
903
/**
 * Retrieves the current status of an array of files in the system table.
904
905
906
907
908
 *
 * @param $files
 *   An array of files to check.
 * @param $type
 *   The type of the files.
Dries Buytaert's avatar
   
Dries Buytaert committed
909
910
 */
function system_get_files_database(&$files, $type) {
Dries Buytaert's avatar
   
Dries Buytaert committed
911
  // Extract current files from database.
912
  $result = db_query("SELECT filename, name, type, status, schema_version FROM {system} WHERE type = '%s'", $type);
Dries Buytaert's avatar
   
Dries Buytaert committed
913
  while ($file = db_fetch_object($result)) {
914
    if (isset($files[$file->name]) && is_object($files[$file->name])) {
915
      $file->old_filename = $file->filename;
Dries Buytaert's avatar
   
Dries Buytaert committed
916
      foreach ($file as $key => $value) {
917
        if (!isset($files[$file->name]) || !isset($files[$file->name]->$key)) {
918
919
          $files[$file->name]->$key = $value;
        }
Dries Buytaert's avatar
   
Dries Buytaert committed
920
      }
921
    }
Dries Buytaert's avatar
 
Dries Buytaert committed
922
  }
Dries Buytaert's avatar
   
Dries Buytaert committed
923
}
Dries Buytaert's avatar
 
Dries Buytaert committed
924

925
926
927
928
929
930
/**
 * Prepare defaults for themes.
 *
 * @return
 *   An array of default themes settings.
 */
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
function system_theme_default() {
  return array(
    'regions' => array(
      'left' => 'Left sidebar',
      'right' => 'Right sidebar',
      'content' => 'Content',
      'header' => 'Header',
      'footer' => 'Footer',
    )