Projet

Général

Profil

Paste
Télécharger (138 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / system / system.module @ b4adf10d

1
<?php
2

    
3
/**
4
 * @file
5
 * Configuration system that lets administrators modify the workings of the site.
6
 */
7

    
8
/**
9
 * Maximum age of temporary files in seconds.
10
 */
11
define('DRUPAL_MAXIMUM_TEMP_FILE_AGE', 21600);
12

    
13
/**
14
 * Default interval for automatic cron executions in seconds.
15
 */
16
define('DRUPAL_CRON_DEFAULT_THRESHOLD', 10800);
17

    
18
/**
19
 * New users will be set to the default time zone at registration.
20
 */
21
define('DRUPAL_USER_TIMEZONE_DEFAULT', 0);
22

    
23
/**
24
 * New users will get an empty time zone at registration.
25
 */
26
define('DRUPAL_USER_TIMEZONE_EMPTY', 1);
27

    
28
/**
29
 * New users will select their own timezone at registration.
30
 */
31
define('DRUPAL_USER_TIMEZONE_SELECT', 2);
32

    
33
 /**
34
 * Disabled option on forms and settings
35
 */
36
define('DRUPAL_DISABLED', 0);
37

    
38
/**
39
 * Optional option on forms and settings
40
 */
41
define('DRUPAL_OPTIONAL', 1);
42

    
43
/**
44
 * Required option on forms and settings
45
 */
46
define('DRUPAL_REQUIRED', 2);
47

    
48
/**
49
 * Maximum number of values in a weight select element.
50
 *
51
 * If the number of values is over the maximum, a text field is used instead.
52
 */
53
define('DRUPAL_WEIGHT_SELECT_MAX', 100);
54

    
55
/**
56
 * Return only visible regions.
57
 *
58
 * @see system_region_list()
59
 */
60
define('REGIONS_VISIBLE', 'visible');
61

    
62
/**
63
 * Return all regions.
64
 *
65
 * @see system_region_list()
66
 */
67
define('REGIONS_ALL', 'all');
68

    
69
/**
70
 * Implements hook_help().
71
 */
72
function system_help($path, $arg) {
73
  global $base_url;
74

    
75
  switch ($path) {
76
    case 'admin/help#system':
77
      $output = '';
78
      $output .= '<h3>' . t('About') . '</h3>';
79
      $output .= '<p>' . t('The System module is integral to the site, 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 and disabling 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. For more information, see the online handbook entry for <a href="@system">System module</a>.', array('@system' => 'http://drupal.org/documentation/modules/system')) . '</p>';
80
      $output .= '<h3>' . t('Uses') . '</h3>';
81
      $output .= '<dl>';
82
      $output .= '<dt>' . t('Managing modules') . '</dt>';
83
      $output .= '<dd>' . t('The System module allows users with the appropriate permissions to enable and disable modules on the <a href="@modules">Modules administration page</a>. Drupal comes with a number of core modules, and each module provides a discrete set of features and may be enabled or disabled depending on the needs of the site. Many 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/modules'), '@drupal-modules' => 'http://drupal.org/project/modules')) . '</dd>';
84
      $output .= '<dt>' . t('Managing themes') . '</dt>';
85
      $output .= '<dd>' . t('The System module allows users with the appropriate permissions to enable and disable themes on the <a href="@themes">Appearance administration page</a>. Themes 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/appearance'), '@drupal-themes' => 'http://drupal.org/project/themes')) . '</dd>';
86
      $output .= '<dt>' . t('Managing caching') . '</dt>';
87
      $output .= '<dd>' . t("The System module allows users with the appropriate permissions to manage caching on the <a href='@cache-settings'>Performance settings page</a>. Drupal has a robust caching system that allows the efficient re-use of previously-constructed web pages and web page components. Pages requested by anonymous users are stored in a compressed format; depending on your site configuration and the amount of your web traffic tied to anonymous visitors, the caching system may significantly increase the speed of your site.", array('@cache-settings' => url('admin/config/development/performance'))) . '</dd>';
88
      $output .= '<dt>' . t('Performing system maintenance') . '</dt>';
89
      $output .= '<dd>' . t('In order for the site and its modules to continue to operate well, a set of routine administrative operations must run on a regular basis. The System module manages this task by making use of a system cron job. You can verify the status of cron tasks by visiting the <a href="@status">Status report page</a>. For more information, see the online handbook entry for <a href="@handbook">configuring cron jobs</a>. You can set up cron job by visiting <a href="@cron">Cron configuration</a> page', array('@status' => url('admin/reports/status'), '@handbook' => 'http://drupal.org/cron', '@cron' => url('admin/config/system/cron'))) . '</dd>';
90
      $output .= '<dt>' . t('Configuring basic site settings') . '</dt>';
91
      $output .= '<dd>' . t('The System module also handles basic configuration options for your site, including <a href="@date-time-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="@maintenance-mode">Maintenance mode</a> for taking your site temporarily offline.', array('@date-time-settings' => url('admin/config/regional/date-time'), '@file-system' => url('admin/config/media/file-system'), '@clean-url' => url('admin/config/search/clean-urls'), '@site-info' => url('admin/config/system/site-information'), '@maintenance-mode' => url('admin/config/development/maintenance'))) . '</dd>';
92
      $output .= '<dt>' . t('Configuring actions') . '</dt>';
93
      $output .= '<dd>' . 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 <a href="@trigger-help">Trigger module</a>, 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. Visit the <a href="@actions">Actions page</a> to configure actions.', array('@trigger-help' => url('admin/help/trigger'), '@actions' => url('admin/config/system/actions'))) . '</dd>';
94
      $output .= '</dl>';
95
      return $output;
96
    case 'admin/index':
97
      return '<p>' . t('This page shows you all available administration tasks for each module.') . '</p>';
98
    case 'admin/appearance':
99
      $output = '<p>' . t('Set and configure the default theme for your website.  Alternative <a href="@themes">themes</a> are available.', array('@themes' => 'http://drupal.org/project/themes')) . '</p>';
100
      return $output;
101
    case 'admin/appearance/settings/' . $arg[3]:
102
      $theme_list = list_themes();
103
      $theme = $theme_list[$arg[3]];
104
      return '<p>' . t('These options control the display settings for the %name theme. When your site is displayed using this theme, these settings will be used.', array('%name' => $theme->info['name'])) . '</p>';
105
    case 'admin/appearance/settings':
106
      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>';
107
    case 'admin/modules':
108
      $output = '<p>' . t('Download additional <a href="@modules">contributed modules</a> to extend Drupal\'s functionality.', array('@modules' => 'http://drupal.org/project/modules')) . '</p>';
109
      if (module_exists('update')) {
110
        if (update_manager_access()) {
111
          $output .= '<p>' . t('Regularly review and install <a href="@updates">available updates</a> to maintain a secure and current site. Always run the <a href="@update-php">update script</a> each time a module is updated.', array('@update-php' => $base_url . '/update.php', '@updates' => url('admin/reports/updates'))) . '</p>';
112
        }
113
        else {
114
          $output .= '<p>' . t('Regularly review <a href="@updates">available updates</a> to maintain a secure and current site. Always run the <a href="@update-php">update script</a> each time a module is updated.', array('@update-php' => $base_url . '/update.php', '@updates' => url('admin/reports/updates'))) . '</p>';
115
        }
116
      }
117
      else {
118
        $output .= '<p>' . t('Regularly review available updates to maintain a secure and current site. Always run the <a href="@update-php">update script</a> each time a module is updated. Enable the Update manager module to update and install modules and themes.', array('@update-php' => $base_url . '/update.php')) . '</p>';
119
      }
120
      return $output;
121
    case 'admin/modules/uninstall':
122
      return '<p>' . t('The uninstall process removes all data related to a module. To uninstall a module, you must first disable it on the main <a href="@modules">Modules page</a>.', array('@modules' => url('admin/modules'))) . '</p>';
123
    case 'admin/structure/block/manage':
124
      if ($arg[4] == 'system' && $arg[5] == 'powered-by') {
125
        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>';
126
      }
127
      break;
128
    case 'admin/config/development/maintenance':
129
      global $user;
130
      if ($user->uid == 1) {
131
        return '<p>' . t('If you are upgrading to a newer version of Drupal or upgrading contributed modules or themes, you may need to run the <a href="@update-php">update script</a>.', array('@update-php' => $base_url . '/update.php')) . '</p>';
132
      }
133
      break;
134
    case 'admin/config/system/actions':
135
    case 'admin/config/system/actions/manage':
136
      $output = '';
137
      $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 need to be created and configured before they can be used, because they have options that need to be specified; for example, sending an e-mail to a specified address, or unpublishing content containing certain words. To create an advanced action, select the action from the drop-down list in the advanced action section below and click the <em>Create</em> button.') . '</p>';
138
      if (module_exists('trigger')) {
139
        $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/structure/trigger'))) . '</p>';
140
      }
141
      return $output;
142
    case 'admin/config/system/actions/configure':
143
      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").');
144
    case 'admin/config/people/ip-blocking':
145
      return '<p>' . t('IP addresses listed here are blocked from your site. Blocked addresses are completely forbidden from accessing the site and instead see a brief message explaining the situation.') . '</p>';
146
    case 'admin/reports/status':
147
      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>';
148
  }
149
}
150

    
151
/**
152
 * Implements hook_theme().
153
 */
154
function system_theme() {
155
  return array_merge(drupal_common_theme(), array(
156
    'system_themes_page' => array(
157
      'variables' => array('theme_groups' => NULL),
158
      'file' => 'system.admin.inc',
159
    ),
160
    'system_settings_form' => array(
161
      'render element' => 'form',
162
    ),
163
    'confirm_form' => array(
164
      'render element' => 'form',
165
    ),
166
    'system_modules_fieldset' => array(
167
      'render element' => 'form',
168
      'file' => 'system.admin.inc',
169
    ),
170
    'system_modules_incompatible' => array(
171
      'variables' => array('message' => NULL),
172
      'file' => 'system.admin.inc',
173
    ),
174
    'system_modules_uninstall' => array(
175
      'render element' => 'form',
176
      'file' => 'system.admin.inc',
177
    ),
178
    'status_report' => array(
179
      'render element' => 'requirements',
180
      'file' => 'system.admin.inc',
181
    ),
182
    'admin_page' => array(
183
      'variables' => array('blocks' => NULL),
184
      'file' => 'system.admin.inc',
185
    ),
186
    'admin_block' => array(
187
      'variables' => array('block' => NULL),
188
      'file' => 'system.admin.inc',
189
    ),
190
    'admin_block_content' => array(
191
      'variables' => array('content' => NULL),
192
      'file' => 'system.admin.inc',
193
    ),
194
    'system_admin_index' => array(
195
      'variables' => array('menu_items' => NULL),
196
      'file' => 'system.admin.inc',
197
    ),
198
    'system_powered_by' => array(
199
      'variables' => array(),
200
    ),
201
    'system_compact_link' => array(
202
      'variables' => array(),
203
    ),
204
    'system_date_time_settings' => array(
205
      'render element' => 'form',
206
      'file' => 'system.admin.inc',
207
    ),
208
  ));
209
}
210

    
211
/**
212
 * Implements hook_permission().
213
 */
214
function system_permission() {
215
  return array(
216
    'administer modules' => array(
217
      'title' => t('Administer modules'),
218
    ),
219
    'administer site configuration' => array(
220
      'title' => t('Administer site configuration'),
221
      'restrict access' => TRUE,
222
    ),
223
    'administer themes' => array(
224
      'title' => t('Administer themes'),
225
    ),
226
    'administer software updates' => array(
227
      'title' => t('Administer software updates'),
228
      'restrict access' => TRUE,
229
    ),
230
    'administer actions' => array(
231
      'title' => t('Administer actions'),
232
    ),
233
    'access administration pages' => array(
234
      'title' => t('Use the administration pages and help'),
235
    ),
236
    'access site in maintenance mode' => array(
237
      'title' => t('Use the site in maintenance mode'),
238
    ),
239
    'view the administration theme' => array(
240
      'title' => t('View the administration theme'),
241
      'description' => variable_get('admin_theme') ? '' : t('This is only used when the site is configured to use a separate administration theme on the <a href="@appearance-url">Appearance</a> page.', array('@appearance-url' => url('admin/appearance'))),
242
    ),
243
    'access site reports' => array(
244
      'title' => t('View site reports'),
245
      'restrict access' => TRUE,
246
    ),
247
    'block IP addresses' => array(
248
      'title' => t('Block IP addresses'),
249
    ),
250
  );
251
}
252

    
253
/**
254
 * Implements hook_hook_info().
255
 */
256
function system_hook_info() {
257
  $hooks['token_info'] = array(
258
    'group' => 'tokens',
259
  );
260
  $hooks['token_info_alter'] = array(
261
    'group' => 'tokens',
262
  );
263
  $hooks['tokens'] = array(
264
    'group' => 'tokens',
265
  );
266
  $hooks['tokens_alter'] = array(
267
    'group' => 'tokens',
268
  );
269

    
270
  return $hooks;
271
}
272

    
273
/**
274
 * Implements hook_entity_info().
275
 */
276
function system_entity_info() {
277
  return array(
278
    'file' => array(
279
      'label' => t('File'),
280
      'base table' => 'file_managed',
281
      'entity keys' => array(
282
        'id' => 'fid',
283
        'label' => 'filename',
284
      ),
285
      'static cache' => FALSE,
286
    ),
287
  );
288
}
289

    
290
/**
291
 * Implements hook_element_info().
292
 */
293
function system_element_info() {
294
  // Top level elements.
295
  $types['form'] = array(
296
    '#method' => 'post',
297
    '#action' => request_uri(),
298
    '#theme_wrappers' => array('form'),
299
  );
300
  $types['page'] = array(
301
    '#show_messages' => TRUE,
302
    '#theme' => 'page',
303
    '#theme_wrappers' => array('html'),
304
  );
305
  // By default, we don't want Ajax commands being rendered in the context of an
306
  // HTML page, so we don't provide defaults for #theme or #theme_wrappers.
307
  // However, modules can set these properties (for example, to provide an HTML
308
  // debugging page that displays rather than executes Ajax commands).
309
  $types['ajax'] = array(
310
    '#header' => TRUE,
311
    '#commands' => array(),
312
    '#error' => NULL,
313
  );
314
  $types['html_tag'] = array(
315
    '#theme' => 'html_tag',
316
    '#pre_render' => array('drupal_pre_render_conditional_comments'),
317
    '#attributes' => array(),
318
    '#value' => NULL,
319
  );
320
  $types['styles'] = array(
321
    '#items' => array(),
322
    '#pre_render' => array('drupal_pre_render_styles'),
323
    '#group_callback' => 'drupal_group_css',
324
    '#aggregate_callback' => 'drupal_aggregate_css',
325
  );
326

    
327
  // Input elements.
328
  $types['submit'] = array(
329
    '#input' => TRUE,
330
    '#name' => 'op',
331
    '#button_type' => 'submit',
332
    '#executes_submit_callback' => TRUE,
333
    '#limit_validation_errors' => FALSE,
334
    '#process' => array('ajax_process_form'),
335
    '#theme_wrappers' => array('button'),
336
  );
337
  $types['button'] = array(
338
    '#input' => TRUE,
339
    '#name' => 'op',
340
    '#button_type' => 'submit',
341
    '#executes_submit_callback' => FALSE,
342
    '#limit_validation_errors' => FALSE,
343
    '#process' => array('ajax_process_form'),
344
    '#theme_wrappers' => array('button'),
345
  );
346
  $types['image_button'] = array(
347
    '#input' => TRUE,
348
    '#button_type' => 'submit',
349
    '#executes_submit_callback' => TRUE,
350
    '#limit_validation_errors' => FALSE,
351
    '#process' => array('ajax_process_form'),
352
    '#return_value' => TRUE,
353
    '#has_garbage_value' => TRUE,
354
    '#src' => NULL,
355
    '#theme_wrappers' => array('image_button'),
356
  );
357
  $types['textfield'] = array(
358
    '#input' => TRUE,
359
    '#size' => 60,
360
    '#maxlength' => 128,
361
    '#autocomplete_path' => FALSE,
362
    '#process' => array('ajax_process_form'),
363
    '#theme' => 'textfield',
364
    '#theme_wrappers' => array('form_element'),
365
  );
366
  $types['machine_name'] = array(
367
    '#input' => TRUE,
368
    '#default_value' => NULL,
369
    '#required' => TRUE,
370
    '#maxlength' => 64,
371
    '#size' => 60,
372
    '#autocomplete_path' => FALSE,
373
    '#process' => array('form_process_machine_name', 'ajax_process_form'),
374
    '#element_validate' => array('form_validate_machine_name'),
375
    '#theme' => 'textfield',
376
    '#theme_wrappers' => array('form_element'),
377
  );
378
  $types['password'] = array(
379
    '#input' => TRUE,
380
    '#size' => 60,
381
    '#maxlength' => 128,
382
    '#process' => array('ajax_process_form'),
383
    '#theme' => 'password',
384
    '#theme_wrappers' => array('form_element'),
385
  );
386
  $types['password_confirm'] = array(
387
    '#input' => TRUE,
388
    '#process' => array('form_process_password_confirm', 'user_form_process_password_confirm'),
389
    '#theme_wrappers' => array('form_element'),
390
  );
391
  $types['textarea'] = array(
392
    '#input' => TRUE,
393
    '#cols' => 60,
394
    '#rows' => 5,
395
    '#resizable' => TRUE,
396
    '#process' => array('ajax_process_form'),
397
    '#theme' => 'textarea',
398
    '#theme_wrappers' => array('form_element'),
399
  );
400
  $types['radios'] = array(
401
    '#input' => TRUE,
402
    '#process' => array('form_process_radios'),
403
    '#theme_wrappers' => array('radios'),
404
    '#pre_render' => array('form_pre_render_conditional_form_element'),
405
  );
406
  $types['radio'] = array(
407
    '#input' => TRUE,
408
    '#default_value' => NULL,
409
    '#process' => array('ajax_process_form'),
410
    '#theme' => 'radio',
411
    '#theme_wrappers' => array('form_element'),
412
    '#title_display' => 'after',
413
  );
414
  $types['checkboxes'] = array(
415
    '#input' => TRUE,
416
    '#process' => array('form_process_checkboxes'),
417
    '#theme_wrappers' => array('checkboxes'),
418
    '#pre_render' => array('form_pre_render_conditional_form_element'),
419
  );
420
  $types['checkbox'] = array(
421
    '#input' => TRUE,
422
    '#return_value' => 1,
423
    '#theme' => 'checkbox',
424
    '#process' => array('form_process_checkbox', 'ajax_process_form'),
425
    '#theme_wrappers' => array('form_element'),
426
    '#title_display' => 'after',
427
  );
428
  $types['select'] = array(
429
    '#input' => TRUE,
430
    '#multiple' => FALSE,
431
    '#process' => array('form_process_select', 'ajax_process_form'),
432
    '#theme' => 'select',
433
    '#theme_wrappers' => array('form_element'),
434
  );
435
  $types['weight'] = array(
436
    '#input' => TRUE,
437
    '#delta' => 10,
438
    '#default_value' => 0,
439
    '#process' => array('form_process_weight', 'ajax_process_form'),
440
  );
441
  $types['date'] = array(
442
    '#input' => TRUE,
443
    '#element_validate' => array('date_validate'),
444
    '#process' => array('form_process_date'),
445
    '#theme' => 'date',
446
    '#theme_wrappers' => array('form_element'),
447
  );
448
  $types['file'] = array(
449
    '#input' => TRUE,
450
    '#size' => 60,
451
    '#theme' => 'file',
452
    '#theme_wrappers' => array('form_element'),
453
  );
454
  $types['tableselect'] = array(
455
    '#input' => TRUE,
456
    '#js_select' => TRUE,
457
    '#multiple' => TRUE,
458
    '#process' => array('form_process_tableselect'),
459
    '#options' => array(),
460
    '#empty' => '',
461
    '#theme' => 'tableselect',
462
  );
463

    
464
  // Form structure.
465
  $types['item'] = array(
466
    '#markup' => '',
467
    '#pre_render' => array('drupal_pre_render_markup'),
468
    '#theme_wrappers' => array('form_element'),
469
  );
470
  $types['hidden'] = array(
471
    '#input' => TRUE,
472
    '#process' => array('ajax_process_form'),
473
    '#theme' => 'hidden',
474
  );
475
  $types['value'] = array(
476
    '#input' => TRUE,
477
  );
478
  $types['markup'] = array(
479
    '#markup' => '',
480
    '#pre_render' => array('drupal_pre_render_markup'),
481
  );
482
  $types['link'] = array(
483
    '#pre_render' => array('drupal_pre_render_link', 'drupal_pre_render_markup'),
484
  );
485
  $types['fieldset'] = array(
486
    '#collapsible' => FALSE,
487
    '#collapsed' => FALSE,
488
    '#value' => NULL,
489
    '#process' => array('form_process_fieldset', 'ajax_process_form'),
490
    '#pre_render' => array('form_pre_render_fieldset'),
491
    '#theme_wrappers' => array('fieldset'),
492
  );
493
  $types['vertical_tabs'] = array(
494
    '#theme_wrappers' => array('vertical_tabs'),
495
    '#default_tab' => '',
496
    '#process' => array('form_process_vertical_tabs'),
497
  );
498

    
499
  $types['container'] = array(
500
    '#theme_wrappers' => array('container'),
501
    '#process' => array('form_process_container'),
502
  );
503
  $types['actions'] = array(
504
    '#theme_wrappers' => array('container'),
505
    '#process' => array('form_process_actions', 'form_process_container'),
506
    '#weight' => 100,
507
  );
508

    
509
  $types['token'] = array(
510
    '#input' => TRUE,
511
    '#theme' => 'hidden',
512
  );
513

    
514
  return $types;
515
}
516

    
517
/**
518
 * Implements hook_menu().
519
 */
520
function system_menu() {
521
  $items['system/files'] = array(
522
    'title' => 'File download',
523
    'page callback' => 'file_download',
524
    'page arguments' => array('private'),
525
    'access callback' => TRUE,
526
    'type' => MENU_CALLBACK,
527
  );
528
  $items['system/temporary'] = array(
529
    'title' => 'Temporary files',
530
    'page callback' => 'file_download',
531
    'page arguments' => array('temporary'),
532
    'access callback' => TRUE,
533
    'type' => MENU_CALLBACK,
534
  );
535
  $items['system/ajax'] = array(
536
    'title' => 'AHAH callback',
537
    'page callback' => 'ajax_form_callback',
538
    'delivery callback' => 'ajax_deliver',
539
    'access callback' => TRUE,
540
    'theme callback' => 'ajax_base_page_theme',
541
    'type' => MENU_CALLBACK,
542
    'file path' => 'includes',
543
    'file' => 'form.inc',
544
  );
545
  $items['system/timezone'] = array(
546
    'title' => 'Time zone',
547
    'page callback' => 'system_timezone',
548
    'access callback' => TRUE,
549
    'type' => MENU_CALLBACK,
550
    'file' => 'system.admin.inc',
551
  );
552
  $items['admin'] = array(
553
    'title' => 'Administration',
554
    'access arguments' => array('access administration pages'),
555
    'page callback' => 'system_admin_menu_block_page',
556
    'weight' => 9,
557
    'menu_name' => 'management',
558
    'file' => 'system.admin.inc',
559
  );
560
  $items['admin/compact'] = array(
561
    'title' => 'Compact mode',
562
    'page callback' => 'system_admin_compact_page',
563
    'access arguments' => array('access administration pages'),
564
    'type' => MENU_CALLBACK,
565
    'file' => 'system.admin.inc',
566
  );
567
  $items['admin/tasks'] = array(
568
    'title' => 'Tasks',
569
    'type' => MENU_DEFAULT_LOCAL_TASK,
570
    'weight' => -20,
571
  );
572
  $items['admin/index'] = array(
573
    'title' => 'Index',
574
    'page callback' => 'system_admin_index',
575
    'access arguments' => array('access administration pages'),
576
    'type' => MENU_LOCAL_TASK,
577
    'weight' => -18,
578
    'file' => 'system.admin.inc',
579
  );
580

    
581
  // Menu items that are basically just menu blocks.
582
  $items['admin/structure'] = array(
583
    'title' => 'Structure',
584
    'description' => 'Administer blocks, content types, menus, etc.',
585
    'position' => 'right',
586
    'weight' => -8,
587
    'page callback' => 'system_admin_menu_block_page',
588
    'access arguments' => array('access administration pages'),
589
    'file' => 'system.admin.inc',
590
  );
591
  // Appearance.
592
  $items['admin/appearance'] = array(
593
    'title' => 'Appearance',
594
    'description' => 'Select and configure your themes.',
595
    'page callback' => 'system_themes_page',
596
    'access arguments' => array('administer themes'),
597
    'position' => 'left',
598
    'weight' => -6,
599
    'file' => 'system.admin.inc',
600
  );
601
  $items['admin/appearance/list'] = array(
602
    'title' => 'List',
603
    'description' => 'Select and configure your theme',
604
    'type' => MENU_DEFAULT_LOCAL_TASK,
605
    'weight' => -1,
606
    'file' => 'system.admin.inc',
607
  );
608
  $items['admin/appearance/enable'] = array(
609
    'title' => 'Enable theme',
610
    'page callback' => 'system_theme_enable',
611
    'access arguments' => array('administer themes'),
612
    'type' => MENU_CALLBACK,
613
    'file' => 'system.admin.inc',
614
  );
615
  $items['admin/appearance/disable'] = array(
616
    'title' => 'Disable theme',
617
    'page callback' => 'system_theme_disable',
618
    'access arguments' => array('administer themes'),
619
    'type' => MENU_CALLBACK,
620
    'file' => 'system.admin.inc',
621
  );
622
  $items['admin/appearance/default'] = array(
623
    'title' => 'Set default theme',
624
    'page callback' => 'system_theme_default',
625
    'access arguments' => array('administer themes'),
626
    'type' => MENU_CALLBACK,
627
    'file' => 'system.admin.inc',
628
  );
629
  $items['admin/appearance/settings'] = array(
630
    'title' => 'Settings',
631
    'description' => 'Configure default and theme specific settings.',
632
    'page callback' => 'drupal_get_form',
633
    'page arguments' => array('system_theme_settings'),
634
    'access arguments' => array('administer themes'),
635
    'type' => MENU_LOCAL_TASK,
636
    'file' => 'system.admin.inc',
637
    'weight' => 20,
638
  );
639
  // Theme configuration subtabs.
640
  $items['admin/appearance/settings/global'] = array(
641
    'title' => 'Global settings',
642
    'type' => MENU_DEFAULT_LOCAL_TASK,
643
    'weight' => -1,
644
  );
645

    
646
  foreach (list_themes() as $theme) {
647
    $items['admin/appearance/settings/' . $theme->name] = array(
648
      'title' => $theme->info['name'],
649
      'page arguments' => array('system_theme_settings', $theme->name),
650
      'type' => MENU_LOCAL_TASK,
651
      'access callback' => '_system_themes_access',
652
      'access arguments' => array($theme),
653
      'file' => 'system.admin.inc',
654
    );
655
  }
656

    
657
  // Modules.
658
  $items['admin/modules'] = array(
659
    'title' => 'Modules',
660
    'description' => 'Extend site functionality.',
661
    'page callback' => 'drupal_get_form',
662
    'page arguments' => array('system_modules'),
663
    'access arguments' => array('administer modules'),
664
    'file' => 'system.admin.inc',
665
    'weight' => -2,
666
  );
667
  $items['admin/modules/list'] = array(
668
    'title' => 'List',
669
    'type' => MENU_DEFAULT_LOCAL_TASK,
670
  );
671
  $items['admin/modules/list/confirm'] = array(
672
    'title' => 'List',
673
    'access arguments' => array('administer modules'),
674
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
675
  );
676
  $items['admin/modules/uninstall'] = array(
677
    'title' => 'Uninstall',
678
    'page arguments' => array('system_modules_uninstall'),
679
    'access arguments' => array('administer modules'),
680
    'type' => MENU_LOCAL_TASK,
681
    'file' => 'system.admin.inc',
682
    'weight' => 20,
683
  );
684
  $items['admin/modules/uninstall/confirm'] = array(
685
    'title' => 'Uninstall',
686
    'access arguments' => array('administer modules'),
687
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
688
    'file' => 'system.admin.inc',
689
  );
690

    
691
  // Configuration.
692
  $items['admin/config'] = array(
693
    'title' => 'Configuration',
694
    'description' => 'Administer settings.',
695
    'page callback' => 'system_admin_config_page',
696
    'access arguments' => array('access administration pages'),
697
    'file' => 'system.admin.inc',
698
  );
699

    
700
  // IP address blocking.
701
  $items['admin/config/people/ip-blocking'] = array(
702
    'title' => 'IP address blocking',
703
    'description' => 'Manage blocked IP addresses.',
704
    'page callback' => 'system_ip_blocking',
705
    'access arguments' => array('block IP addresses'),
706
    'file' => 'system.admin.inc',
707
    'weight' => 10,
708
  );
709
  $items['admin/config/people/ip-blocking/delete/%blocked_ip'] = array(
710
    'title' => 'Delete IP address',
711
    'page callback' => 'drupal_get_form',
712
    'page arguments' => array('system_ip_blocking_delete', 5),
713
    'access arguments' => array('block IP addresses'),
714
    'file' => 'system.admin.inc',
715
  );
716

    
717
  // Media settings.
718
  $items['admin/config/media'] = array(
719
    'title' => 'Media',
720
    'description' => 'Media tools.',
721
    'position' => 'left',
722
    'weight' => -10,
723
    'page callback' => 'system_admin_menu_block_page',
724
    'access arguments' => array('access administration pages'),
725
    'file' => 'system.admin.inc',
726
  );
727
  $items['admin/config/media/file-system'] = array(
728
    'title' => 'File system',
729
    'description' => 'Tell Drupal where to store uploaded files and how they are accessed.',
730
    'page callback' => 'drupal_get_form',
731
    'page arguments' => array('system_file_system_settings'),
732
    'access arguments' => array('administer site configuration'),
733
    'weight' => -10,
734
    'file' => 'system.admin.inc',
735
  );
736
  $items['admin/config/media/image-toolkit'] = array(
737
    'title' => 'Image toolkit',
738
    'description' => 'Choose which image toolkit to use if you have installed optional toolkits.',
739
    'page callback' => 'drupal_get_form',
740
    'page arguments' => array('system_image_toolkit_settings'),
741
    'access arguments' => array('administer site configuration'),
742
    'weight' => 20,
743
    'file' => 'system.admin.inc',
744
  );
745

    
746
  // Service settings.
747
  $items['admin/config/services'] = array(
748
    'title' => 'Web services',
749
    'description' => 'Tools related to web services.',
750
    'position' => 'right',
751
    'weight' => 0,
752
    'page callback' => 'system_admin_menu_block_page',
753
    'access arguments' => array('access administration pages'),
754
    'file' => 'system.admin.inc',
755
  );
756
  $items['admin/config/services/rss-publishing'] = array(
757
    'title' => 'RSS publishing',
758
    'description' => 'Configure the site description, the number of items per feed and whether feeds should be titles/teasers/full-text.',
759
    'page callback' => 'drupal_get_form',
760
    'page arguments' => array('system_rss_feeds_settings'),
761
    'access arguments' => array('administer site configuration'),
762
    'file' => 'system.admin.inc',
763
  );
764

    
765
  // Development settings.
766
  $items['admin/config/development'] = array(
767
    'title' => 'Development',
768
    'description' => 'Development tools.',
769
    'position' => 'right',
770
    'weight' => -10,
771
    'page callback' => 'system_admin_menu_block_page',
772
    'access arguments' => array('access administration pages'),
773
    'file' => 'system.admin.inc',
774
  );
775
  $items['admin/config/development/maintenance'] = array(
776
    'title' => 'Maintenance mode',
777
    'description' => 'Take the site offline for maintenance or bring it back online.',
778
    'page callback' => 'drupal_get_form',
779
    'page arguments' => array('system_site_maintenance_mode'),
780
    'access arguments' => array('administer site configuration'),
781
    'file' => 'system.admin.inc',
782
    'weight' => -10,
783
  );
784
  $items['admin/config/development/performance'] = array(
785
    'title' => 'Performance',
786
    'description' => 'Enable or disable page caching for anonymous users and set CSS and JS bandwidth optimization options.',
787
    'page callback' => 'drupal_get_form',
788
    'page arguments' => array('system_performance_settings'),
789
    'access arguments' => array('administer site configuration'),
790
    'file' => 'system.admin.inc',
791
    'weight' => -20,
792
  );
793
  $items['admin/config/development/logging'] = array(
794
    'title' => 'Logging and errors',
795
    'description' => "Settings for logging and alerts modules. Various modules can route Drupal's system events to different destinations, such as syslog, database, email, etc.",
796
    'page callback' => 'drupal_get_form',
797
    'page arguments' => array('system_logging_settings'),
798
    'access arguments' => array('administer site configuration'),
799
    'file' => 'system.admin.inc',
800
    'weight' => -15,
801
  );
802

    
803
  // Regional and date settings.
804
  $items['admin/config/regional'] = array(
805
    'title' => 'Regional and language',
806
    'description' => 'Regional settings, localization and translation.',
807
    'position' => 'left',
808
    'weight' => -5,
809
    'page callback' => 'system_admin_menu_block_page',
810
    'access arguments' => array('access administration pages'),
811
    'file' => 'system.admin.inc',
812
  );
813
  $items['admin/config/regional/settings'] = array(
814
    'title' => 'Regional settings',
815
    'description' => "Settings for the site's default time zone and country.",
816
    'page callback' => 'drupal_get_form',
817
    'page arguments' => array('system_regional_settings'),
818
    'access arguments' => array('administer site configuration'),
819
    'weight' => -20,
820
    'file' => 'system.admin.inc',
821
  );
822
  $items['admin/config/regional/date-time'] = array(
823
    'title' => 'Date and time',
824
    'description' => 'Configure display formats for date and time.',
825
    'page callback' => 'drupal_get_form',
826
    'page arguments' => array('system_date_time_settings'),
827
    'access arguments' => array('administer site configuration'),
828
    'weight' => -15,
829
    'file' => 'system.admin.inc',
830
  );
831
  $items['admin/config/regional/date-time/types'] = array(
832
    'title' => 'Types',
833
    'description' => 'Configure display formats for date and time.',
834
    'page callback' => 'drupal_get_form',
835
    'page arguments' => array('system_date_time_settings'),
836
    'access arguments' => array('administer site configuration'),
837
    'type' => MENU_DEFAULT_LOCAL_TASK,
838
    'weight' => -10,
839
    'file' => 'system.admin.inc',
840
  );
841
  $items['admin/config/regional/date-time/types/add'] = array(
842
    'title' => 'Add date type',
843
    'description' => 'Add new date type.',
844
    'page callback' => 'drupal_get_form',
845
    'page arguments' => array('system_add_date_format_type_form'),
846
    'access arguments' => array('administer site configuration'),
847
    'type' => MENU_LOCAL_ACTION,
848
    'weight' => -10,
849
    'file' => 'system.admin.inc',
850
  );
851
  $items['admin/config/regional/date-time/types/%/delete'] = array(
852
    'title' => 'Delete date type',
853
    'description' => 'Allow users to delete a configured date type.',
854
    'page callback' => 'drupal_get_form',
855
    'page arguments' => array('system_delete_date_format_type_form', 5),
856
    'access arguments' => array('administer site configuration'),
857
    'file' => 'system.admin.inc',
858
  );
859
  $items['admin/config/regional/date-time/formats'] = array(
860
    'title' => 'Formats',
861
    'description' => 'Configure display format strings for date and time.',
862
    'page callback' => 'system_date_time_formats',
863
    'access arguments' => array('administer site configuration'),
864
    'type' => MENU_LOCAL_TASK,
865
    'weight' => -9,
866
    'file' => 'system.admin.inc',
867
  );
868
  $items['admin/config/regional/date-time/formats/add'] = array(
869
    'title' => 'Add format',
870
    'description' => 'Allow users to add additional date formats.',
871
    'type' => MENU_LOCAL_ACTION,
872
    'page callback' => 'drupal_get_form',
873
    'page arguments' => array('system_configure_date_formats_form'),
874
    'access arguments' => array('administer site configuration'),
875
    'weight' => -10,
876
    'file' => 'system.admin.inc',
877
  );
878
  $items['admin/config/regional/date-time/formats/%/edit'] = array(
879
    'title' => 'Edit date format',
880
    'description' => 'Allow users to edit a configured date format.',
881
    'page callback' => 'drupal_get_form',
882
    'page arguments' => array('system_configure_date_formats_form', 5),
883
    'access arguments' => array('administer site configuration'),
884
    'file' => 'system.admin.inc',
885
  );
886
  $items['admin/config/regional/date-time/formats/%/delete'] = array(
887
    'title' => 'Delete date format',
888
    'description' => 'Allow users to delete a configured date format.',
889
    'page callback' => 'drupal_get_form',
890
    'page arguments' => array('system_date_delete_format_form', 5),
891
    'access arguments' => array('administer site configuration'),
892
    'file' => 'system.admin.inc',
893
  );
894
  $items['admin/config/regional/date-time/formats/lookup'] = array(
895
    'title' => 'Date and time lookup',
896
    'page callback' => 'system_date_time_lookup',
897
    'access arguments' => array('administer site configuration'),
898
    'type' => MENU_CALLBACK,
899
    'file' => 'system.admin.inc',
900
  );
901

    
902
  // Search settings.
903
  $items['admin/config/search'] = array(
904
    'title' => 'Search and metadata',
905
    'description' => 'Local site search, metadata and SEO.',
906
    'position' => 'left',
907
    'weight' => -10,
908
    'page callback' => 'system_admin_menu_block_page',
909
    'access arguments' => array('access administration pages'),
910
    'file' => 'system.admin.inc',
911
  );
912
  $items['admin/config/search/clean-urls'] = array(
913
    'title' => 'Clean URLs',
914
    'description' => 'Enable or disable clean URLs for your site.',
915
    'page callback' => 'drupal_get_form',
916
    'page arguments' => array('system_clean_url_settings'),
917
    'access arguments' => array('administer site configuration'),
918
    'file' => 'system.admin.inc',
919
    'weight' => 5,
920
  );
921
  $items['admin/config/search/clean-urls/check'] = array(
922
    'title' => 'Clean URL check',
923
    'page callback' => 'drupal_json_output',
924
    'page arguments' => array(array('status' => TRUE)),
925
    'access callback' => TRUE,
926
    'type' => MENU_CALLBACK,
927
    'file' => 'system.admin.inc',
928
  );
929

    
930
  // System settings.
931
  $items['admin/config/system'] = array(
932
    'title' => 'System',
933
    'description' => 'General system related configuration.',
934
    'position' => 'right',
935
    'weight' => -20,
936
    'page callback' => 'system_admin_menu_block_page',
937
    'access arguments' => array('access administration pages'),
938
    'file' => 'system.admin.inc',
939
  );
940
  $items['admin/config/system/actions'] = array(
941
    'title' => 'Actions',
942
    'description' => 'Manage the actions defined for your site.',
943
    'access arguments' => array('administer actions'),
944
    'page callback' => 'system_actions_manage',
945
    'file' => 'system.admin.inc',
946
  );
947
  $items['admin/config/system/actions/manage'] = array(
948
    'title' => 'Manage actions',
949
    'description' => 'Manage the actions defined for your site.',
950
    'page callback' => 'system_actions_manage',
951
    'type' => MENU_DEFAULT_LOCAL_TASK,
952
    'weight' => -2,
953
    'file' => 'system.admin.inc',
954
  );
955
  $items['admin/config/system/actions/configure'] = array(
956
    'title' => 'Configure an advanced action',
957
    'page callback' => 'drupal_get_form',
958
    'page arguments' => array('system_actions_configure'),
959
    'access arguments' => array('administer actions'),
960
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
961
    'file' => 'system.admin.inc',
962
  );
963
  $items['admin/config/system/actions/delete/%actions'] = array(
964
    'title' => 'Delete action',
965
    'description' => 'Delete an action.',
966
    'page callback' => 'drupal_get_form',
967
    'page arguments' => array('system_actions_delete_form', 5),
968
    'access arguments' => array('administer actions'),
969
    'file' => 'system.admin.inc',
970
  );
971
  $items['admin/config/system/actions/orphan'] = array(
972
    'title' => 'Remove orphans',
973
    'page callback' => 'system_actions_remove_orphans',
974
    'access arguments' => array('administer actions'),
975
    'type' => MENU_CALLBACK,
976
    'file' => 'system.admin.inc',
977
  );
978
  $items['admin/config/system/site-information'] = array(
979
    'title' => 'Site information',
980
    'description' => 'Change site name, e-mail address, slogan, default front page, and number of posts per page, error pages.',
981
    'page callback' => 'drupal_get_form',
982
    'page arguments' => array('system_site_information_settings'),
983
    'access arguments' => array('administer site configuration'),
984
    'file' => 'system.admin.inc',
985
    'weight' => -20,
986
  );
987
  $items['admin/config/system/cron'] = array(
988
    'title' => 'Cron',
989
    'description' => 'Manage automatic site maintenance tasks.',
990
    'page callback' => 'drupal_get_form',
991
    'page arguments' => array('system_cron_settings'),
992
    'access arguments' => array('administer site configuration'),
993
    'file' => 'system.admin.inc',
994
    'weight' => 20,
995
  );
996
  // Additional categories
997
  $items['admin/config/user-interface'] = array(
998
    'title' => 'User interface',
999
    'description' => 'Tools that enhance the user interface.',
1000
    'position' => 'right',
1001
    'page callback' => 'system_admin_menu_block_page',
1002
    'access arguments' => array('access administration pages'),
1003
    'file' => 'system.admin.inc',
1004
    'weight' => -15,
1005
  );
1006
  $items['admin/config/workflow'] = array(
1007
    'title' => 'Workflow',
1008
    'description' => 'Content workflow, editorial workflow tools.',
1009
    'position' => 'right',
1010
    'weight' => 5,
1011
    'page callback' => 'system_admin_menu_block_page',
1012
    'access arguments' => array('access administration pages'),
1013
    'file' => 'system.admin.inc',
1014
  );
1015
  $items['admin/config/content'] = array(
1016
    'title' => 'Content authoring',
1017
    'description' => 'Settings related to formatting and authoring content.',
1018
    'position' => 'left',
1019
    'weight' => -15,
1020
    'page callback' => 'system_admin_menu_block_page',
1021
    'access arguments' => array('access administration pages'),
1022
    'file' => 'system.admin.inc',
1023
  );
1024

    
1025
  // Reports.
1026
  $items['admin/reports'] = array(
1027
    'title' => 'Reports',
1028
    'description' => 'View reports, updates, and errors.',
1029
    'page callback' => 'system_admin_menu_block_page',
1030
    'access arguments' => array('access site reports'),
1031
    'weight' => 5,
1032
    'position' => 'left',
1033
    'file' => 'system.admin.inc',
1034
  );
1035
  $items['admin/reports/status'] = array(
1036
    'title' => 'Status report',
1037
    'description' => "Get a status report about your site's operation and any detected problems.",
1038
    'page callback' => 'system_status',
1039
    'weight' => -60,
1040
    'access arguments' => array('administer site configuration'),
1041
    'file' => 'system.admin.inc',
1042
  );
1043
  $items['admin/reports/status/run-cron'] = array(
1044
    'title' => 'Run cron',
1045
    'page callback' => 'system_run_cron',
1046
    'access arguments' => array('administer site configuration'),
1047
    'type' => MENU_CALLBACK,
1048
    'file' => 'system.admin.inc',
1049
  );
1050
  $items['admin/reports/status/php'] = array(
1051
    'title' => 'PHP',
1052
    'page callback' => 'system_php',
1053
    'access arguments' => array('administer site configuration'),
1054
    'type' => MENU_CALLBACK,
1055
    'file' => 'system.admin.inc',
1056
  );
1057

    
1058
  // Default page for batch operations.
1059
  $items['batch'] = array(
1060
    'page callback' => 'system_batch_page',
1061
    'access callback' => TRUE,
1062
    'theme callback' => '_system_batch_theme',
1063
    'type' => MENU_CALLBACK,
1064
    'file' => 'system.admin.inc',
1065
  );
1066
  return $items;
1067
}
1068

    
1069
/**
1070
 * Theme callback for the default batch page.
1071
 */
1072
function _system_batch_theme() {
1073
  // Retrieve the current state of the batch.
1074
  $batch = &batch_get();
1075
  if (!$batch && isset($_REQUEST['id'])) {
1076
    require_once DRUPAL_ROOT . '/includes/batch.inc';
1077
    $batch = batch_load($_REQUEST['id']);
1078
  }
1079
  // Use the same theme as the page that started the batch.
1080
  if (!empty($batch['theme'])) {
1081
    return $batch['theme'];
1082
  }
1083
}
1084

    
1085
/**
1086
 * Implements hook_library().
1087
 */
1088
function system_library() {
1089
  // Drupal's Ajax framework.
1090
  $libraries['drupal.ajax'] = array(
1091
    'title' => 'Drupal AJAX',
1092
    'website' => 'http://api.drupal.org/api/drupal/includes--ajax.inc/group/ajax/7',
1093
    'version' => VERSION,
1094
    'js' => array(
1095
      'misc/ajax.js' => array('group' => JS_LIBRARY, 'weight' => 2),
1096
    ),
1097
    'dependencies' => array(
1098
      array('system', 'drupal.progress'),
1099
    ),
1100
  );
1101

    
1102
  // Drupal's batch API.
1103
  $libraries['drupal.batch'] = array(
1104
    'title' => 'Drupal batch API',
1105
    'version' => VERSION,
1106
    'js' => array(
1107
      'misc/batch.js' => array('group' => JS_DEFAULT, 'cache' => FALSE),
1108
    ),
1109
    'dependencies' => array(
1110
      array('system', 'drupal.progress'),
1111
    ),
1112
  );
1113

    
1114
  // Drupal's progress indicator.
1115
  $libraries['drupal.progress'] = array(
1116
    'title' => 'Drupal progress indicator',
1117
    'version' => VERSION,
1118
    'js' => array(
1119
      'misc/progress.js' => array('group' => JS_DEFAULT),
1120
    ),
1121
  );
1122

    
1123
  // Drupal's form library.
1124
  $libraries['drupal.form'] = array(
1125
    'title' => 'Drupal form library',
1126
    'version' => VERSION,
1127
    'js' => array(
1128
      'misc/form.js' => array('group' => JS_LIBRARY, 'weight' => 1),
1129
    ),
1130
  );
1131

    
1132
  // Drupal's states library.
1133
  $libraries['drupal.states'] = array(
1134
    'title' => 'Drupal states',
1135
    'version' => VERSION,
1136
    'js' => array(
1137
      'misc/states.js' => array('group' => JS_LIBRARY, 'weight' => 1),
1138
    ),
1139
  );
1140

    
1141
  // Drupal's collapsible fieldset.
1142
  $libraries['drupal.collapse'] = array(
1143
    'title' => 'Drupal collapsible fieldset',
1144
    'version' => VERSION,
1145
    'js' => array(
1146
      'misc/collapse.js' => array('group' => JS_DEFAULT),
1147
    ),
1148
    'dependencies' => array(
1149
      // collapse.js relies on drupalGetSummary in form.js
1150
      array('system', 'drupal.form'),
1151
    ),
1152
  );
1153

    
1154
  // Drupal's resizable textarea.
1155
  $libraries['drupal.textarea'] = array(
1156
    'title' => 'Drupal resizable textarea',
1157
    'version' => VERSION,
1158
    'js' => array(
1159
      'misc/textarea.js' => array('group' => JS_DEFAULT),
1160
    ),
1161
  );
1162

    
1163
  // Drupal's autocomplete widget.
1164
  $libraries['drupal.autocomplete'] = array(
1165
    'title' => 'Drupal autocomplete',
1166
    'version' => VERSION,
1167
    'js' => array(
1168
      'misc/autocomplete.js' => array('group' => JS_DEFAULT),
1169
    ),
1170
  );
1171

    
1172
  // jQuery.
1173
  $libraries['jquery'] = array(
1174
    'title' => 'jQuery',
1175
    'website' => 'http://jquery.com',
1176
    'version' => '1.4.4',
1177
    'js' => array(
1178
      'misc/jquery.js' => array('group' => JS_LIBRARY, 'weight' => -20),
1179
    ),
1180
  );
1181

    
1182
  // jQuery Once.
1183
  $libraries['jquery.once'] = array(
1184
    'title' => 'jQuery Once',
1185
    'website' => 'http://plugins.jquery.com/project/once',
1186
    'version' => '1.2',
1187
    'js' => array(
1188
      'misc/jquery.once.js' => array('group' => JS_LIBRARY, 'weight' => -19),
1189
    ),
1190
  );
1191

    
1192
  // jQuery Form Plugin.
1193
  $libraries['jquery.form'] = array(
1194
    'title' => 'jQuery Form Plugin',
1195
    'website' => 'http://malsup.com/jquery/form/',
1196
    'version' => '2.52',
1197
    'js' => array(
1198
      'misc/jquery.form.js' => array(),
1199
    ),
1200
    'dependencies' => array(
1201
      array('system', 'jquery.cookie'),
1202
    ),
1203
  );
1204

    
1205
  // jQuery BBQ plugin.
1206
  $libraries['jquery.bbq'] = array(
1207
    'title' => 'jQuery BBQ',
1208
    'website' => 'http://benalman.com/projects/jquery-bbq-plugin/',
1209
    'version' => '1.2.1',
1210
    'js' => array(
1211
      'misc/jquery.ba-bbq.js' => array(),
1212
    ),
1213
  );
1214

    
1215
  // Vertical Tabs.
1216
  $libraries['drupal.vertical-tabs'] = array(
1217
    'title' => 'Vertical Tabs',
1218
    'website' => 'http://drupal.org/node/323112',
1219
    'version' => '1.0',
1220
    'js' => array(
1221
      'misc/vertical-tabs.js' => array(),
1222
    ),
1223
    'css' => array(
1224
      'misc/vertical-tabs.css' => array(),
1225
    ),
1226
    'dependencies' => array(
1227
      // Vertical tabs relies on drupalGetSummary in form.js
1228
      array('system', 'drupal.form'),
1229
    ),
1230
  );
1231

    
1232
  // Farbtastic.
1233
  $libraries['farbtastic'] = array(
1234
    'title' => 'Farbtastic',
1235
    'website' => 'http://code.google.com/p/farbtastic/',
1236
    'version' => '1.2',
1237
    'js' => array(
1238
      'misc/farbtastic/farbtastic.js' => array(),
1239
    ),
1240
    'css' => array(
1241
      'misc/farbtastic/farbtastic.css' => array(),
1242
    ),
1243
  );
1244

    
1245
  // Cookie.
1246
  $libraries['jquery.cookie'] = array(
1247
    'title' => 'Cookie',
1248
    'website' => 'http://plugins.jquery.com/project/cookie',
1249
    'version' => '1.0',
1250
    'js' => array(
1251
      'misc/jquery.cookie.js' => array(),
1252
    ),
1253
  );
1254

    
1255
  // jQuery UI.
1256
  $libraries['ui'] = array(
1257
    'title' => 'jQuery UI: Core',
1258
    'website' => 'http://jqueryui.com',
1259
    'version' => '1.8.7',
1260
    'js' => array(
1261
      'misc/ui/jquery.ui.core.min.js' => array('group' => JS_LIBRARY, 'weight' => -11),
1262
    ),
1263
    'css' => array(
1264
      'misc/ui/jquery.ui.core.css' => array(),
1265
      'misc/ui/jquery.ui.theme.css' => array(),
1266
    ),
1267
  );
1268
  $libraries['ui.accordion'] = array(
1269
    'title' => 'jQuery UI: Accordion',
1270
    'website' => 'http://jqueryui.com/demos/accordion/',
1271
    'version' => '1.8.7',
1272
    'js' => array(
1273
      'misc/ui/jquery.ui.accordion.min.js' => array(),
1274
    ),
1275
    'css' => array(
1276
      'misc/ui/jquery.ui.accordion.css' => array(),
1277
    ),
1278
    'dependencies' => array(
1279
      array('system', 'ui.widget'),
1280
    ),
1281
  );
1282
  $libraries['ui.autocomplete'] = array(
1283
    'title' => 'jQuery UI: Autocomplete',
1284
    'website' => 'http://jqueryui.com/demos/autocomplete/',
1285
    'version' => '1.8.7',
1286
    'js' => array(
1287
      'misc/ui/jquery.ui.autocomplete.min.js' => array(),
1288
    ),
1289
    'css' => array(
1290
      'misc/ui/jquery.ui.autocomplete.css' => array(),
1291
    ),
1292
    'dependencies' => array(
1293
      array('system', 'ui.widget'),
1294
      array('system', 'ui.position'),
1295
    ),
1296
  );
1297
  $libraries['ui.button'] = array(
1298
    'title' => 'jQuery UI: Button',
1299
    'website' => 'http://jqueryui.com/demos/button/',
1300
    'version' => '1.8.7',
1301
    'js' => array(
1302
      'misc/ui/jquery.ui.button.min.js' => array(),
1303
    ),
1304
    'css' => array(
1305
      'misc/ui/jquery.ui.button.css' => array(),
1306
    ),
1307
    'dependencies' => array(
1308
      array('system', 'ui.widget'),
1309
    ),
1310
  );
1311
  $libraries['ui.datepicker'] = array(
1312
    'title' => 'jQuery UI: Date Picker',
1313
    'website' => 'http://jqueryui.com/demos/datepicker/',
1314
    'version' => '1.8.7',
1315
    'js' => array(
1316
      'misc/ui/jquery.ui.datepicker.min.js' => array(),
1317
    ),
1318
    'css' => array(
1319
      'misc/ui/jquery.ui.datepicker.css' => array(),
1320
    ),
1321
    'dependencies' => array(
1322
      array('system', 'ui'),
1323
    ),
1324
  );
1325
  $libraries['ui.dialog'] = array(
1326
    'title' => 'jQuery UI: Dialog',
1327
    'website' => 'http://jqueryui.com/demos/dialog/',
1328
    'version' => '1.8.7',
1329
    'js' => array(
1330
      'misc/ui/jquery.ui.dialog.min.js' => array(),
1331
    ),
1332
    'css' => array(
1333
      'misc/ui/jquery.ui.dialog.css' => array(),
1334
    ),
1335
    'dependencies' => array(
1336
      array('system', 'ui.widget'),
1337
      array('system', 'ui.button'),
1338
      array('system', 'ui.draggable'),
1339
      array('system', 'ui.mouse'),
1340
      array('system', 'ui.position'),
1341
      array('system', 'ui.resizable'),
1342
    ),
1343
  );
1344
  $libraries['ui.draggable'] = array(
1345
    'title' => 'jQuery UI: Draggable',
1346
    'website' => 'http://jqueryui.com/demos/draggable/',
1347
    'version' => '1.8.7',
1348
    'js' => array(
1349
      'misc/ui/jquery.ui.draggable.min.js' => array(),
1350
    ),
1351
    'dependencies' => array(
1352
      array('system', 'ui.widget'),
1353
      array('system', 'ui.mouse'),
1354
    ),
1355
  );
1356
  $libraries['ui.droppable'] = array(
1357
    'title' => 'jQuery UI: Droppable',
1358
    'website' => 'http://jqueryui.com/demos/droppable/',
1359
    'version' => '1.8.7',
1360
    'js' => array(
1361
      'misc/ui/jquery.ui.droppable.min.js' => array(),
1362
    ),
1363
    'dependencies' => array(
1364
      array('system', 'ui.widget'),
1365
      array('system', 'ui.mouse'),
1366
      array('system', 'ui.draggable'),
1367
    ),
1368
  );
1369
  $libraries['ui.mouse'] = array(
1370
    'title' => 'jQuery UI: Mouse',
1371
    'website' => 'http://docs.jquery.com/UI/Mouse',
1372
    'version' => '1.8.7',
1373
    'js' => array(
1374
      'misc/ui/jquery.ui.mouse.min.js' => array(),
1375
    ),
1376
    'dependencies' => array(
1377
      array('system', 'ui.widget'),
1378
    ),
1379
  );
1380
  $libraries['ui.position'] = array(
1381
    'title' => 'jQuery UI: Position',
1382
    'website' => 'http://jqueryui.com/demos/position/',
1383
    'version' => '1.8.7',
1384
    'js' => array(
1385
      'misc/ui/jquery.ui.position.min.js' => array(),
1386
    ),
1387
  );
1388
  $libraries['ui.progressbar'] = array(
1389
    'title' => 'jQuery UI: Progress Bar',
1390
    'website' => 'http://jqueryui.com/demos/progressbar/',
1391
    'version' => '1.8.7',
1392
    'js' => array(
1393
      'misc/ui/jquery.ui.progressbar.min.js' => array(),
1394
    ),
1395
    'css' => array(
1396
      'misc/ui/jquery.ui.progressbar.css' => array(),
1397
    ),
1398
    'dependencies' => array(
1399
      array('system', 'ui.widget'),
1400
    ),
1401
  );
1402
  $libraries['ui.resizable'] = array(
1403
    'title' => 'jQuery UI: Resizable',
1404
    'website' => 'http://jqueryui.com/demos/resizable/',
1405
    'version' => '1.8.7',
1406
    'js' => array(
1407
      'misc/ui/jquery.ui.resizable.min.js' => array(),
1408
    ),
1409
    'css' => array(
1410
      'misc/ui/jquery.ui.resizable.css' => array(),
1411
    ),
1412
    'dependencies' => array(
1413
      array('system', 'ui.widget'),
1414
      array('system', 'ui.mouse'),
1415
    ),
1416
  );
1417
  $libraries['ui.selectable'] = array(
1418
    'title' => 'jQuery UI: Selectable',
1419
    'website' => 'http://jqueryui.com/demos/selectable/',
1420
    'version' => '1.8.7',
1421
    'js' => array(
1422
      'misc/ui/jquery.ui.selectable.min.js' => array(),
1423
    ),
1424
    'css' => array(
1425
      'misc/ui/jquery.ui.selectable.css' => array(),
1426
    ),
1427
    'dependencies' => array(
1428
      array('system', 'ui.widget'),
1429
      array('system', 'ui.mouse'),
1430
    ),
1431
  );
1432
  $libraries['ui.slider'] = array(
1433
    'title' => 'jQuery UI: Slider',
1434
    'website' => 'http://jqueryui.com/demos/slider/',
1435
    'version' => '1.8.7',
1436
    'js' => array(
1437
      'misc/ui/jquery.ui.slider.min.js' => array(),
1438
    ),
1439
    'css' => array(
1440
      'misc/ui/jquery.ui.slider.css' => array(),
1441
    ),
1442
    'dependencies' => array(
1443
      array('system', 'ui.widget'),
1444
      array('system', 'ui.mouse'),
1445
    ),
1446
  );
1447
  $libraries['ui.sortable'] = array(
1448
    'title' => 'jQuery UI: Sortable',
1449
    'website' => 'http://jqueryui.com/demos/sortable/',
1450
    'version' => '1.8.7',
1451
    'js' => array(
1452
      'misc/ui/jquery.ui.sortable.min.js' => array(),
1453
    ),
1454
    'dependencies' => array(
1455
      array('system', 'ui.widget'),
1456
      array('system', 'ui.mouse'),
1457
    ),
1458
  );
1459
  $libraries['ui.tabs'] = array(
1460
    'title' => 'jQuery UI: Tabs',
1461
    'website' => 'http://jqueryui.com/demos/tabs/',
1462
    'version' => '1.8.7',
1463
    'js' => array(
1464
      'misc/ui/jquery.ui.tabs.min.js' => array(),
1465
    ),
1466
    'css' => array(
1467
      'misc/ui/jquery.ui.tabs.css' => array(),
1468
    ),
1469
    'dependencies' => array(
1470
      array('system', 'ui.widget'),
1471
    ),
1472
  );
1473
  $libraries['ui.widget'] = array(
1474
    'title' => 'jQuery UI: Widget',
1475
    'website' => 'http://docs.jquery.com/UI/Widget',
1476
    'version' => '1.8.7',
1477
    'js' => array(
1478
      'misc/ui/jquery.ui.widget.min.js' => array('group' => JS_LIBRARY, 'weight' => -10),
1479
    ),
1480
    'dependencies' => array(
1481
      array('system', 'ui'),
1482
    ),
1483
  );
1484
  $libraries['effects'] = array(
1485
    'title' => 'jQuery UI: Effects',
1486
    'website' => 'http://jqueryui.com/demos/effect/',
1487
    'version' => '1.8.7',
1488
    'js' => array(
1489
      'misc/ui/jquery.effects.core.min.js' => array('group' => JS_LIBRARY, 'weight' => -9),
1490
    ),
1491
  );
1492
  $libraries['effects.blind'] = array(
1493
    'title' => 'jQuery UI: Effects Blind',
1494
    'website' => 'http://jqueryui.com/demos/effect/',
1495
    'version' => '1.8.7',
1496
    'js' => array(
1497
      'misc/ui/jquery.effects.blind.min.js' => array(),
1498
    ),
1499
    'dependencies' => array(
1500
      array('system', 'effects'),
1501
    ),
1502
  );
1503
  $libraries['effects.bounce'] = array(
1504
    'title' => 'jQuery UI: Effects Bounce',
1505
    'website' => 'http://jqueryui.com/demos/effect/',
1506
    'version' => '1.8.7',
1507
    'js' => array(
1508
      'misc/ui/jquery.effects.bounce.min.js' => array(),
1509
    ),
1510
    'dependencies' => array(
1511
      array('system', 'effects'),
1512
    ),
1513
  );
1514
  $libraries['effects.clip'] = array(
1515
    'title' => 'jQuery UI: Effects Clip',
1516
    'website' => 'http://jqueryui.com/demos/effect/',
1517
    'version' => '1.8.7',
1518
    'js' => array(
1519
      'misc/ui/jquery.effects.clip.min.js' => array(),
1520
    ),
1521
    'dependencies' => array(
1522
      array('system', 'effects'),
1523
    ),
1524
  );
1525
  $libraries['effects.drop'] = array(
1526
    'title' => 'jQuery UI: Effects Drop',
1527
    'website' => 'http://jqueryui.com/demos/effect/',
1528
    'version' => '1.8.7',
1529
    'js' => array(
1530
      'misc/ui/jquery.effects.drop.min.js' => array(),
1531
    ),
1532
    'dependencies' => array(
1533
      array('system', 'effects'),
1534
    ),
1535
  );
1536
  $libraries['effects.explode'] = array(
1537
    'title' => 'jQuery UI: Effects Explode',
1538
    'website' => 'http://jqueryui.com/demos/effect/',
1539
    'version' => '1.8.7',
1540
    'js' => array(
1541
      'misc/ui/jquery.effects.explode.min.js' => array(),
1542
    ),
1543
    'dependencies' => array(
1544
      array('system', 'effects'),
1545
    ),
1546
  );
1547
  $libraries['effects.fade'] = array(
1548
    'title' => 'jQuery UI: Effects Fade',
1549
    'website' => 'http://jqueryui.com/demos/effect/',
1550
    'version' => '1.8.7',
1551
    'js' => array(
1552
      'misc/ui/jquery.effects.fade.min.js' => array(),
1553
    ),
1554
    'dependencies' => array(
1555
      array('system', 'effects'),
1556
    ),
1557
  );
1558
  $libraries['effects.fold'] = array(
1559
    'title' => 'jQuery UI: Effects Fold',
1560
    'website' => 'http://jqueryui.com/demos/effect/',
1561
    'version' => '1.8.7',
1562
    'js' => array(
1563
      'misc/ui/jquery.effects.fold.min.js' => array(),
1564
    ),
1565
    'dependencies' => array(
1566
      array('system', 'effects'),
1567
    ),
1568
  );
1569
  $libraries['effects.highlight'] = array(
1570
    'title' => 'jQuery UI: Effects Highlight',
1571
    'website' => 'http://jqueryui.com/demos/effect/',
1572
    'version' => '1.8.7',
1573
    'js' => array(
1574
      'misc/ui/jquery.effects.highlight.min.js' => array(),
1575
    ),
1576
    'dependencies' => array(
1577
      array('system', 'effects'),
1578
    ),
1579
  );
1580
  $libraries['effects.pulsate'] = array(
1581
    'title' => 'jQuery UI: Effects Pulsate',
1582
    'website' => 'http://jqueryui.com/demos/effect/',
1583
    'version' => '1.8.7',
1584
    'js' => array(
1585
      'misc/ui/jquery.effects.pulsate.min.js' => array(),
1586
    ),
1587
    'dependencies' => array(
1588
      array('system', 'effects'),
1589
    ),
1590
  );
1591
  $libraries['effects.scale'] = array(
1592
    'title' => 'jQuery UI: Effects Scale',
1593
    'website' => 'http://jqueryui.com/demos/effect/',
1594
    'version' => '1.8.7',
1595
    'js' => array(
1596
      'misc/ui/jquery.effects.scale.min.js' => array(),
1597
    ),
1598
    'dependencies' => array(
1599
      array('system', 'effects'),
1600
    ),
1601
  );
1602
  $libraries['effects.shake'] = array(
1603
    'title' => 'jQuery UI: Effects Shake',
1604
    'website' => 'http://jqueryui.com/demos/effect/',
1605
    'version' => '1.8.7',
1606
    'js' => array(
1607
      'misc/ui/jquery.effects.shake.min.js' => array(),
1608
    ),
1609
    'dependencies' => array(
1610
      array('system', 'effects'),
1611
    ),
1612
  );
1613
  $libraries['effects.slide'] = array(
1614
    'title' => 'jQuery UI: Effects Slide',
1615
    'website' => 'http://jqueryui.com/demos/effect/',
1616
    'version' => '1.8.7',
1617
    'js' => array(
1618
      'misc/ui/jquery.effects.slide.min.js' => array(),
1619
    ),
1620
    'dependencies' => array(
1621
      array('system', 'effects'),
1622
    ),
1623
  );
1624
  $libraries['effects.transfer'] = array(
1625
    'title' => 'jQuery UI: Effects Transfer',
1626
    'website' => 'http://jqueryui.com/demos/effect/',
1627
    'version' => '1.8.7',
1628
    'js' => array(
1629
      'misc/ui/jquery.effects.transfer.min.js' => array(),
1630
    ),
1631
    'dependencies' => array(
1632
      array('system', 'effects'),
1633
    ),
1634
  );
1635

    
1636
  // These library names are deprecated. Earlier versions of Drupal 7 didn't
1637
  // consistently namespace their libraries, so these names are included for
1638
  // backwards compatibility with those versions.
1639
  $libraries['once'] = &$libraries['jquery.once'];
1640
  $libraries['form'] = &$libraries['jquery.form'];
1641
  $libraries['jquery-bbq'] = &$libraries['jquery.bbq'];
1642
  $libraries['vertical-tabs'] = &$libraries['drupal.vertical-tabs'];
1643
  $libraries['cookie'] = &$libraries['jquery.cookie'];
1644

    
1645
  return $libraries;
1646
}
1647

    
1648
/**
1649
 * Implements hook_stream_wrappers().
1650
 */
1651
function system_stream_wrappers() {
1652
  $wrappers = array(
1653
    'public' => array(
1654
      'name' => t('Public files'),
1655
      'class' => 'DrupalPublicStreamWrapper',
1656
      'description' => t('Public local files served by the webserver.'),
1657
      'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
1658
    ),
1659
    'temporary' => array(
1660
      'name' => t('Temporary files'),
1661
      'class' => 'DrupalTemporaryStreamWrapper',
1662
      'description' => t('Temporary local files for upload and previews.'),
1663
      'type' => STREAM_WRAPPERS_LOCAL_HIDDEN,
1664
    ),
1665
  );
1666

    
1667
  // Only register the private file stream wrapper if a file path has been set.
1668
  if (variable_get('file_private_path', FALSE)) {
1669
    $wrappers['private'] = array(
1670
      'name' => t('Private files'),
1671
      'class' => 'DrupalPrivateStreamWrapper',
1672
      'description' => t('Private local files served by Drupal.'),
1673
      'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
1674
    );
1675
  }
1676

    
1677
  return $wrappers;
1678
}
1679

    
1680
/**
1681
 * Retrieve a blocked IP address from the database.
1682
 *
1683
 * @param $iid integer
1684
 *   The ID of the blocked IP address to retrieve.
1685
 *
1686
 * @return
1687
 *   The blocked IP address from the database as an array.
1688
 */
1689
function blocked_ip_load($iid) {
1690
  return db_query("SELECT * FROM {blocked_ips} WHERE iid = :iid", array(':iid' => $iid))->fetchAssoc();
1691
}
1692

    
1693
/**
1694
 * Menu item access callback - only admin or enabled themes can be accessed.
1695
 */
1696
function _system_themes_access($theme) {
1697
  return user_access('administer themes') && drupal_theme_access($theme);
1698
}
1699

    
1700
/**
1701
 * @defgroup authorize Authorized operations
1702
 * @{
1703
 * Functions to run operations with elevated privileges via authorize.php.
1704
 *
1705
 * Because of the Update manager functionality included in Drupal core, there
1706
 * is a mechanism for running operations with elevated file system privileges,
1707
 * the top-level authorize.php script. This script runs at a reduced Drupal
1708
 * bootstrap level so that it is not reliant on the entire site being
1709
 * functional. The operations use a FileTransfer class to manipulate code
1710
 * installed on the system as the user that owns the files, not the user that
1711
 * the httpd is running as.
1712
 *
1713
 * The first setup is to define a callback function that should be authorized
1714
 * to run with the elevated privileges. This callback should take a
1715
 * FileTransfer as its first argument, although you can define an array of
1716
 * other arguments it should be invoked with. The callback should be placed in
1717
 * a separate .inc file that will be included by authorize.php.
1718
 *
1719
 * To run the operation, certain data must be saved into the SESSION, and then
1720
 * the flow of control should be redirected to the authorize.php script. There
1721
 * are two ways to do this, either to call system_authorized_run() directly,
1722
 * or to call system_authorized_init() and then redirect to authorize.php,
1723
 * using the URL from system_authorized_get_url(). Redirecting yourself is
1724
 * necessary when your authorized operation is being triggered by a form
1725
 * submit handler, since calling drupal_goto() in a submit handler is a bad
1726
 * idea, and you should instead set $form_state['redirect'].
1727
 *
1728
 * Once the SESSION is setup for the operation and the user is redirected to
1729
 * authorize.php, they will be prompted for their connection credentials (core
1730
 * provides FTP and SSH by default, although other connection classes can be
1731
 * added via contributed modules). With valid credentials, authorize.php will
1732
 * instantiate the appropriate FileTransfer object, and then invoke the
1733
 * desired operation passing in that object. The authorize.php script can act
1734
 * as a Batch API processing page, if the operation requires a batch.
1735
 *
1736
 * @see authorize.php
1737
 * @see FileTransfer
1738
 * @see hook_filetransfer_info()
1739
 */
1740

    
1741
/**
1742
 * Setup a given callback to run via authorize.php with elevated privileges.
1743
 *
1744
 * To use authorize.php, certain variables must be stashed into $_SESSION. This
1745
 * function sets up all the necessary $_SESSION variables. The calling function
1746
 * should then redirect to authorize.php, using the full path returned by
1747
 * system_authorized_get_url(). That initiates the workflow that will eventually
1748
 * lead to the callback being invoked. The callback will be invoked at a low
1749
 * bootstrap level, without all modules being invoked, so it needs to be careful
1750
 * not to assume any code exists. Example (system_authorized_run()):
1751
 * @code
1752
 *   system_authorized_init($callback, $file, $arguments, $page_title);
1753
 *   drupal_goto(system_authorized_get_url());
1754
 * @endcode
1755
 * Example (update_manager_install_form_submit()):
1756
 * @code
1757
 *  system_authorized_init('update_authorize_run_install',
1758
 *    drupal_get_path('module', 'update') . '/update.authorize.inc',
1759
 *    $arguments, t('Update manager'));
1760
 *  $form_state['redirect'] = system_authorized_get_url();
1761
 * @endcode
1762
 *
1763
 * @param $callback
1764
 *   The name of the function to invoke once the user authorizes the operation.
1765
 * @param $file
1766
 *   The full path to the file where the callback function is implemented.
1767
 * @param $arguments
1768
 *   Optional array of arguments to pass into the callback when it is invoked.
1769
 *   Note that the first argument to the callback is always the FileTransfer
1770
 *   object created by authorize.php when the user authorizes the operation.
1771
 * @param $page_title
1772
 *   Optional string to use as the page title once redirected to authorize.php.
1773
 * @return
1774
 *   Nothing, this function just initializes variables in the user's session.
1775
 */
1776
function system_authorized_init($callback, $file, $arguments = array(), $page_title = NULL) {
1777
  // First, figure out what file transfer backends the site supports, and put
1778
  // all of those in the SESSION so that authorize.php has access to all of
1779
  // them via the class autoloader, even without a full bootstrap.
1780
  $_SESSION['authorize_filetransfer_info'] = drupal_get_filetransfer_info();
1781

    
1782
  // Now, define the callback to invoke.
1783
  $_SESSION['authorize_operation'] = array(
1784
    'callback' => $callback,
1785
    'file' => $file,
1786
    'arguments' => $arguments,
1787
  );
1788

    
1789
  if (isset($page_title)) {
1790
    $_SESSION['authorize_operation']['page_title'] = $page_title;
1791
  }
1792
}
1793

    
1794
/**
1795
 * Return the URL for the authorize.php script.
1796
 *
1797
 * @param array $options
1798
 *   Optional array of options to pass to url().
1799
 * @return
1800
 *   The full URL to authorize.php, using HTTPS if available.
1801
 *
1802
 * @see system_authorized_init()
1803
 */
1804
function system_authorized_get_url(array $options = array()) {
1805
  global $base_url;
1806
  // Force HTTPS if available, regardless of what the caller specifies.
1807
  $options['https'] = TRUE;
1808
  // We prefix with $base_url so we get a full path even if clean URLs are
1809
  // disabled.
1810
  return url($base_url . '/authorize.php', $options);
1811
}
1812

    
1813
/**
1814
 * Returns the URL for the authorize.php script when it is processing a batch.
1815
 */
1816
function system_authorized_batch_processing_url() {
1817
  return system_authorized_get_url(array('query' => array('batch' => '1')));
1818
}
1819

    
1820
/**
1821
 * Setup and invoke an operation using authorize.php.
1822
 *
1823
 * @see system_authorized_init()
1824
 */
1825
function system_authorized_run($callback, $file, $arguments = array(), $page_title = NULL) {
1826
  system_authorized_init($callback, $file, $arguments, $page_title);
1827
  drupal_goto(system_authorized_get_url());
1828
}
1829

    
1830
/**
1831
 * Use authorize.php to run batch_process().
1832
 *
1833
 * @see batch_process()
1834
 */
1835
function system_authorized_batch_process() {
1836
  $finish_url = system_authorized_get_url();
1837
  $process_url = system_authorized_batch_processing_url();
1838
  batch_process($finish_url, $process_url);
1839
}
1840

    
1841
/**
1842
 * @} End of "defgroup authorize".
1843
 */
1844

    
1845
/**
1846
 * Implements hook_updater_info().
1847
 */
1848
function system_updater_info() {
1849
  return array(
1850
    'module' => array(
1851
      'class' => 'ModuleUpdater',
1852
      'name' => t('Update modules'),
1853
      'weight' => 0,
1854
    ),
1855
    'theme' => array(
1856
      'class' => 'ThemeUpdater',
1857
      'name' => t('Update themes'),
1858
      'weight' => 0,
1859
    ),
1860
  );
1861
}
1862

    
1863
/**
1864
 * Implements hook_filetransfer_info().
1865
 */
1866
function system_filetransfer_info() {
1867
  $backends = array();
1868

    
1869
  // This is the default, will be available on most systems.
1870
  if (function_exists('ftp_connect')) {
1871
    $backends['ftp'] = array(
1872
      'title' => t('FTP'),
1873
      'class' => 'FileTransferFTP',
1874
      'file' => 'ftp.inc',
1875
      'file path' => 'includes/filetransfer',
1876
      'weight' => 0,
1877
    );
1878
  }
1879

    
1880
  // SSH2 lib connection is only available if the proper PHP extension is
1881
  // installed.
1882
  if (function_exists('ssh2_connect')) {
1883
    $backends['ssh'] = array(
1884
      'title' => t('SSH'),
1885
      'class' => 'FileTransferSSH',
1886
      'file' => 'ssh.inc',
1887
      'file path' => 'includes/filetransfer',
1888
      'weight' => 20,
1889
    );
1890
  }
1891
  return $backends;
1892
}
1893

    
1894
/**
1895
 * Implements hook_init().
1896
 */
1897
function system_init() {
1898
  $path = drupal_get_path('module', 'system');
1899
  // Add the CSS for this module. These aren't in system.info, because they
1900
  // need to be in the CSS_SYSTEM group rather than the CSS_DEFAULT group.
1901
  drupal_add_css($path . '/system.base.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
1902
  if (path_is_admin(current_path())) {
1903
    drupal_add_css($path . '/system.admin.css', array('group' => CSS_SYSTEM));
1904
  }
1905
  drupal_add_css($path . '/system.menus.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
1906
  drupal_add_css($path . '/system.messages.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
1907
  drupal_add_css($path . '/system.theme.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
1908

    
1909
  // Ignore slave database servers for this request.
1910
  //
1911
  // In Drupal's distributed database structure, new data is written to the
1912
  // master and then propagated to the slave servers.  This means there is a
1913
  // lag between when data is written to the master and when it is available on
1914
  // the slave. At these times, we will want to avoid using a slave server
1915
  // temporarily. For example, if a user posts a new node then we want to
1916
  // disable the slave server for that user temporarily to allow the slave
1917
  // server to catch up. That way, that user will see their changes immediately
1918
  // while for other users we still get the benefits of having a slave server,
1919
  // just with slightly stale data.  Code that wants to disable the slave
1920
  // server should use the db_ignore_slave() function to set
1921
  // $_SESSION['ignore_slave_server'] to the timestamp after which the slave
1922
  // can be re-enabled.
1923
  if (isset($_SESSION['ignore_slave_server'])) {
1924
    if ($_SESSION['ignore_slave_server'] >= REQUEST_TIME) {
1925
      Database::ignoreTarget('default', 'slave');
1926
    }
1927
    else {
1928
      unset($_SESSION['ignore_slave_server']);
1929
    }
1930
  }
1931

    
1932
  // Add CSS/JS files from module .info files.
1933
  system_add_module_assets();
1934
}
1935

    
1936
/**
1937
 * Adds CSS and JavaScript files declared in module .info files.
1938
 */
1939
function system_add_module_assets() {
1940
  foreach (system_get_info('module') as $module => $info) {
1941
    if (!empty($info['stylesheets'])) {
1942
      foreach ($info['stylesheets'] as $media => $stylesheets) {
1943
        foreach ($stylesheets as $stylesheet) {
1944
          drupal_add_css($stylesheet, array('every_page' => TRUE, 'media' => $media));
1945
        }
1946
      }
1947
    }
1948
    if (!empty($info['scripts'])) {
1949
      foreach ($info['scripts'] as $script) {
1950
        drupal_add_js($script, array('every_page' => TRUE));
1951
      }
1952
    }
1953
  }
1954
}
1955

    
1956
/**
1957
 * Implements hook_custom_theme().
1958
 */
1959
function system_custom_theme() {
1960
  if (user_access('view the administration theme') && path_is_admin(current_path())) {
1961
    return variable_get('admin_theme');
1962
  }
1963
}
1964

    
1965
/**
1966
 * Implements hook_form_FORM_ID_alter().
1967
 */
1968
function system_form_user_profile_form_alter(&$form, &$form_state) {
1969
  if ($form['#user_category'] == 'account') {
1970
    if (variable_get('configurable_timezones', 1)) {
1971
      system_user_timezone($form, $form_state);
1972
    }
1973
    return $form;
1974
  }
1975
}
1976

    
1977
/**
1978
 * Implements hook_form_FORM_ID_alter().
1979
 */
1980
function system_form_user_register_form_alter(&$form, &$form_state) {
1981
  if (variable_get('configurable_timezones', 1)) {
1982
    if (variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT) == DRUPAL_USER_TIMEZONE_SELECT) {
1983
      system_user_timezone($form, $form_state);
1984
    }
1985
    else {
1986
      $form['account']['timezone'] = array(
1987
        '#type' => 'hidden',
1988
        '#value' => variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT) ? '' : variable_get('date_default_timezone', ''),
1989
      );
1990
    }
1991
    return $form;
1992
  }
1993
}
1994

    
1995
/**
1996
 * Implements hook_user_login().
1997
 */
1998
function system_user_login(&$edit, $account) {
1999
  // If the user has a NULL time zone, notify them to set a time zone.
2000
  if (!$account->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) {
2001
    drupal_set_message(t('Configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => url("user/$account->uid/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone')))));
2002
  }
2003
}
2004

    
2005
/**
2006
 * Add the time zone field to the user edit and register forms.
2007
 */
2008
function system_user_timezone(&$form, &$form_state) {
2009
  global $user;
2010

    
2011
  $account = $form['#user'];
2012

    
2013
  $form['timezone'] = array(
2014
    '#type' => 'fieldset',
2015
    '#title' => t('Locale settings'),
2016
    '#weight' => 6,
2017
    '#collapsible' => TRUE,
2018
  );
2019
  $form['timezone']['timezone'] = array(
2020
    '#type' => 'select',
2021
    '#title' => t('Time zone'),
2022
    '#default_value' => isset($account->timezone) ? $account->timezone : ($account->uid == $user->uid ? variable_get('date_default_timezone', '') : ''),
2023
    '#options' => system_time_zones($account->uid != $user->uid),
2024
    '#description' => t('Select the desired local time and time zone. Dates and times throughout this site will be displayed using this time zone.'),
2025
  );
2026
  if (!isset($account->timezone) && $account->uid == $user->uid && empty($form_state['input']['timezone'])) {
2027
    $form['timezone']['#description'] = t('Your time zone setting will be automatically detected if possible. Confirm the selection and click save.');
2028
    $form['timezone']['timezone']['#attributes'] = array('class' => array('timezone-detect'));
2029
    drupal_add_js('misc/timezone.js');
2030
  }
2031
}
2032

    
2033
/**
2034
 * Implements hook_block_info().
2035
 */
2036
function system_block_info() {
2037
  $blocks['main'] = array(
2038
    'info' => t('Main page content'),
2039
     // Cached elsewhere.
2040
    'cache' => DRUPAL_NO_CACHE,
2041
    // Auto-enable in 'content' region by default, which always exists.
2042
    // @see system_themes_page(), drupal_render_page()
2043
    'status' => 1,
2044
    'region' => 'content',
2045
  );
2046
  $blocks['powered-by'] = array(
2047
    'info' => t('Powered by Drupal'),
2048
    'weight' => '10',
2049
    'cache' => DRUPAL_NO_CACHE,
2050
  );
2051
  $blocks['help'] = array(
2052
    'info' => t('System help'),
2053
    'weight' => '5',
2054
    'cache' => DRUPAL_NO_CACHE,
2055
    // Auto-enable in 'help' region by default, if the theme defines one.
2056
    'status' => 1,
2057
    'region' => 'help',
2058
  );
2059
  // System-defined menu blocks.
2060
  foreach (menu_list_system_menus() as $menu_name => $title) {
2061
    $blocks[$menu_name]['info'] = t($title);
2062
    // Menu blocks can't be cached because each menu item can have
2063
    // a custom access callback. menu.inc manages its own caching.
2064
    $blocks[$menu_name]['cache'] = DRUPAL_NO_CACHE;
2065
  }
2066
  return $blocks;
2067
}
2068

    
2069
/**
2070
 * Implements hook_block_view().
2071
 *
2072
 * Generate a block with a promotional link to Drupal.org and
2073
 * all system menu blocks.
2074
 */
2075
function system_block_view($delta = '') {
2076
  $block = array();
2077
  switch ($delta) {
2078
    case 'main':
2079
      $block['subject'] = NULL;
2080
      $block['content'] = drupal_set_page_content();
2081
      return $block;
2082
    case 'powered-by':
2083
      $block['subject'] = NULL;
2084
      $block['content'] = theme('system_powered_by');
2085
      return $block;
2086
    case 'help':
2087
      $block['subject'] = NULL;
2088
      $block['content'] = menu_get_active_help();
2089
      return $block;
2090
    default:
2091
      // All system menu blocks.
2092
      $system_menus = menu_list_system_menus();
2093
      if (isset($system_menus[$delta])) {
2094
        $block['subject'] = t($system_menus[$delta]);
2095
        $block['content'] = menu_tree($delta);
2096
        return $block;
2097
      }
2098
      break;
2099
  }
2100
}
2101

    
2102
/**
2103
 * Implements hook_preprocess_block().
2104
 */
2105
function system_preprocess_block(&$variables) {
2106
  // System menu blocks should get the same class as menu module blocks.
2107
  if ($variables['block']->module == 'system' && in_array($variables['block']->delta, array_keys(menu_list_system_menus()))) {
2108
    $variables['classes_array'][] = 'block-menu';
2109
  }
2110
}
2111

    
2112
/**
2113
 * Provide a single block on the administration overview page.
2114
 *
2115
 * @param $item
2116
 *   The menu item to be displayed.
2117
 */
2118
function system_admin_menu_block($item) {
2119
  $cache = &drupal_static(__FUNCTION__, array());
2120
  // If we are calling this function for a menu item that corresponds to a
2121
  // local task (for example, admin/tasks), then we want to retrieve the
2122
  // parent item's child links, not this item's (since this item won't have
2123
  // any).
2124
  if ($item['tab_root'] != $item['path']) {
2125
    $item = menu_get_item($item['tab_root_href']);
2126
  }
2127

    
2128
  if (!isset($item['mlid'])) {
2129
    $item += db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = :path AND module = 'system'", array(':path' => $item['path']))->fetchAssoc();
2130
  }
2131

    
2132
  if (isset($cache[$item['mlid']])) {
2133
    return $cache[$item['mlid']];
2134
  }
2135

    
2136
  $content = array();
2137
  $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));
2138
  $query->join('menu_router', 'm', 'm.path = ml.router_path');
2139
  $query
2140
    ->fields('ml')
2141
    // Weight should be taken from {menu_links}, not {menu_router}.
2142
    ->fields('m', array_diff(drupal_schema_fields_sql('menu_router'), array('weight')))
2143
    ->condition('ml.plid', $item['mlid'])
2144
    ->condition('ml.menu_name', $item['menu_name'])
2145
    ->condition('ml.hidden', 0);
2146

    
2147
  foreach ($query->execute() as $link) {
2148
    _menu_link_translate($link);
2149
    if ($link['access']) {
2150
      // The link description, either derived from 'description' in
2151
      // hook_menu() or customized via menu module is used as title attribute.
2152
      if (!empty($link['localized_options']['attributes']['title'])) {
2153
        $link['description'] = $link['localized_options']['attributes']['title'];
2154
        unset($link['localized_options']['attributes']['title']);
2155
      }
2156
      // Prepare for sorting as in function _menu_tree_check_access().
2157
      // The weight is offset so it is always positive, with a uniform 5-digits.
2158
      $key = (50000 + $link['weight']) . ' ' . drupal_strtolower($link['title']) . ' ' . $link['mlid'];
2159
      $content[$key] = $link;
2160
    }
2161
  }
2162
  ksort($content);
2163
  $cache[$item['mlid']] = $content;
2164
  return $content;
2165
}
2166

    
2167
/**
2168
 * Checks the existence of the directory specified in $form_element.
2169
 *
2170
 * This function is called from the system_settings form to check all core
2171
 * file directories (file_public_path, file_private_path, file_temporary_path).
2172
 *
2173
 * @param $form_element
2174
 *   The form element containing the name of the directory to check.
2175
 */
2176
function system_check_directory($form_element) {
2177
  $directory = $form_element['#value'];
2178
  if (strlen($directory) == 0) {
2179
    return $form_element;
2180
  }
2181

    
2182
  if (!is_dir($directory) && !drupal_mkdir($directory, NULL, TRUE)) {
2183
    // If the directory does not exists and cannot be created.
2184
    form_set_error($form_element['#parents'][0], t('The directory %directory does not exist and could not be created.', array('%directory' => $directory)));
2185
    watchdog('file system', 'The directory %directory does not exist and could not be created.', array('%directory' => $directory), WATCHDOG_ERROR);
2186
  }
2187

    
2188
  if (is_dir($directory) && !is_writable($directory) && !drupal_chmod($directory)) {
2189
    // If the directory is not writable and cannot be made so.
2190
    form_set_error($form_element['#parents'][0], t('The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory)));
2191
    watchdog('file system', 'The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory), WATCHDOG_ERROR);
2192
  }
2193
  elseif (is_dir($directory)) {
2194
    if ($form_element['#name'] == 'file_public_path') {
2195
      // Create public .htaccess file.
2196
      file_create_htaccess($directory, FALSE);
2197
    }
2198
    else {
2199
      // Create private .htaccess file.
2200
      file_create_htaccess($directory);
2201
    }
2202
  }
2203

    
2204
  return $form_element;
2205
}
2206

    
2207
/**
2208
 * Retrieves the current status of an array of files in the system table.
2209
 *
2210
 * @param $files
2211
 *   An array of files to check.
2212
 * @param $type
2213
 *   The type of the files.
2214
 */
2215
function system_get_files_database(&$files, $type) {
2216
  // Extract current files from database.
2217
  $result = db_query("SELECT filename, name, type, status, schema_version, weight FROM {system} WHERE type = :type", array(':type' => $type));
2218
  foreach ($result as $file) {
2219
    if (isset($files[$file->name]) && is_object($files[$file->name])) {
2220
      $file->uri = $file->filename;
2221
      foreach ($file as $key => $value) {
2222
        if (!isset($files[$file->name]->$key)) {
2223
          $files[$file->name]->$key = $value;
2224
        }
2225
      }
2226
    }
2227
  }
2228
}
2229

    
2230
/**
2231
 * Updates the records in the system table based on the files array.
2232
 *
2233
 * @param $files
2234
 *   An array of files.
2235
 * @param $type
2236
 *   The type of the files.
2237
 */
2238
function system_update_files_database(&$files, $type) {
2239
  $result = db_query("SELECT * FROM {system} WHERE type = :type", array(':type' => $type));
2240

    
2241
  // Add all files that need to be deleted to a DatabaseCondition.
2242
  $delete = db_or();
2243
  foreach ($result as $file) {
2244
    if (isset($files[$file->name]) && is_object($files[$file->name])) {
2245
      // Keep the old filename from the database in case the file has moved.
2246
      $old_filename = $file->filename;
2247

    
2248
      $updated_fields = array();
2249

    
2250
      // Handle info specially, compare the serialized value.
2251
      $serialized_info = serialize($files[$file->name]->info);
2252
      if ($serialized_info != $file->info) {
2253
        $updated_fields['info'] = $serialized_info;
2254
      }
2255
      unset($file->info);
2256

    
2257
      // Scan remaining fields to find only the updated values.
2258
      foreach ($file as $key => $value) {
2259
        if (isset($files[$file->name]->$key) && $files[$file->name]->$key != $value) {
2260
          $updated_fields[$key] = $files[$file->name]->$key;
2261
        }
2262
      }
2263

    
2264
      // Update the record.
2265
      if (count($updated_fields)) {
2266
        db_update('system')
2267
          ->fields($updated_fields)
2268
          ->condition('filename', $old_filename)
2269
          ->execute();
2270
      }
2271

    
2272
      // Indicate that the file exists already.
2273
      $files[$file->name]->exists = TRUE;
2274
    }
2275
    else {
2276
      // File is not found in file system, so delete record from the system table.
2277
      $delete->condition('filename', $file->filename);
2278
    }
2279
  }
2280

    
2281
  if (count($delete) > 0) {
2282
    // Delete all missing files from the system table, but only if the plugin
2283
    // has never been installed.
2284
    db_delete('system')
2285
      ->condition($delete)
2286
      ->condition('schema_version', -1)
2287
      ->execute();
2288
  }
2289

    
2290
  // All remaining files are not in the system table, so we need to add them.
2291
  $query = db_insert('system')->fields(array('filename', 'name', 'type', 'owner', 'info'));
2292
  foreach ($files as &$file) {
2293
    if (isset($file->exists)) {
2294
      unset($file->exists);
2295
    }
2296
    else {
2297
      $query->values(array(
2298
        'filename' => $file->uri,
2299
        'name' => $file->name,
2300
        'type' => $type,
2301
        'owner' => isset($file->owner) ? $file->owner : '',
2302
        'info' => serialize($file->info),
2303
      ));
2304
      $file->type = $type;
2305
      $file->status = 0;
2306
      $file->schema_version = -1;
2307
    }
2308
  }
2309
  $query->execute();
2310

    
2311
  // If any module or theme was moved to a new location, we need to reset the
2312
  // system_list() cache or we will continue to load the old copy, look for
2313
  // schema updates in the wrong place, etc.
2314
  system_list_reset();
2315
}
2316

    
2317
/**
2318
 * Returns an array of information about enabled modules or themes.
2319
 *
2320
 * This function returns the information from the {system} table corresponding
2321
 * to the cached contents of the .info file for each active module or theme.
2322
 *
2323
 * @param $type
2324
 *   Either 'module' or 'theme'.
2325
 * @param $name
2326
 *   (optional) The name of a module or theme whose information shall be
2327
 *   returned. If omitted, all records for the provided $type will be returned.
2328
 *   If $name does not exist in the provided $type or is not enabled, an empty
2329
 *   array will be returned.
2330
 *
2331
 * @return
2332
 *   An associative array of module or theme information keyed by name, or only
2333
 *   information for $name, if given. If no records are available, an empty
2334
 *   array is returned.
2335
 *
2336
 * @see system_rebuild_module_data()
2337
 * @see system_rebuild_theme_data()
2338
 */
2339
function system_get_info($type, $name = NULL) {
2340
  $info = array();
2341
  if ($type == 'module') {
2342
    $type = 'module_enabled';
2343
  }
2344
  $list = system_list($type);
2345
  foreach ($list as $shortname => $item) {
2346
    if (!empty($item->status)) {
2347
      $info[$shortname] = $item->info;
2348
    }
2349
  }
2350
  if (isset($name)) {
2351
    return isset($info[$name]) ? $info[$name] : array();
2352
  }
2353
  return $info;
2354
}
2355

    
2356
/**
2357
 * Helper function to scan and collect module .info data.
2358
 *
2359
 * @return
2360
 *   An associative array of module information.
2361
 */
2362
function _system_rebuild_module_data() {
2363
  // Find modules
2364
  $modules = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.module$/', 'modules', 'name', 0);
2365

    
2366
  // Include the installation profile in modules that are loaded.
2367
  $profile = drupal_get_profile();
2368
  $modules[$profile] = new stdClass();
2369
  $modules[$profile]->name = $profile;
2370
  $modules[$profile]->uri = 'profiles/' . $profile . '/' . $profile . '.profile';
2371
  $modules[$profile]->filename = $profile . '.profile';
2372

    
2373
  // Installation profile hooks are always executed last.
2374
  $modules[$profile]->weight = 1000;
2375

    
2376
  // Set defaults for module info.
2377
  $defaults = array(
2378
    'dependencies' => array(),
2379
    'description' => '',
2380
    'package' => 'Other',
2381
    'version' => NULL,
2382
    'php' => DRUPAL_MINIMUM_PHP,
2383
    'files' => array(),
2384
    'bootstrap' => 0,
2385
  );
2386

    
2387
  // Read info files for each module.
2388
  foreach ($modules as $key => $module) {
2389
    // The module system uses the key 'filename' instead of 'uri' so copy the
2390
    // value so it will be used by the modules system.
2391
    $modules[$key]->filename = $module->uri;
2392

    
2393
    // Look for the info file.
2394
    $module->info = drupal_parse_info_file(dirname($module->uri) . '/' . $module->name . '.info');
2395

    
2396
    // Skip modules that don't provide info.
2397
    if (empty($module->info)) {
2398
      unset($modules[$key]);
2399
      continue;
2400
    }
2401

    
2402
    // Add the info file modification time, so it becomes available for
2403
    // contributed modules to use for ordering module lists.
2404
    $module->info['mtime'] = filemtime(dirname($module->uri) . '/' . $module->name . '.info');
2405

    
2406
    // Merge in defaults and save.
2407
    $modules[$key]->info = $module->info + $defaults;
2408

    
2409
    // Prefix stylesheets and scripts with module path.
2410
    $path = dirname($module->uri);
2411
    if (isset($module->info['stylesheets'])) {
2412
      $module->info['stylesheets'] = _system_info_add_path($module->info['stylesheets'], $path);
2413
    }
2414
    if (isset($module->info['scripts'])) {
2415
      $module->info['scripts'] = _system_info_add_path($module->info['scripts'], $path);
2416
    }
2417

    
2418
    // Installation profiles are hidden by default, unless explicitly specified
2419
    // otherwise in the .info file.
2420
    if ($key == $profile && !isset($modules[$key]->info['hidden'])) {
2421
      $modules[$key]->info['hidden'] = TRUE;
2422
    }
2423

    
2424
    // Invoke hook_system_info_alter() to give installed modules a chance to
2425
    // modify the data in the .info files if necessary.
2426
    $type = 'module';
2427
    drupal_alter('system_info', $modules[$key]->info, $modules[$key], $type);
2428
  }
2429

    
2430
  if (isset($modules[$profile])) {
2431
    // The installation profile is required, if it's a valid module.
2432
    $modules[$profile]->info['required'] = TRUE;
2433
    // Add a default distribution name if the profile did not provide one. This
2434
    // matches the default value used in install_profile_info().
2435
    if (!isset($modules[$profile]->info['distribution_name'])) {
2436
      $modules[$profile]->info['distribution_name'] = 'Drupal';
2437
    }
2438
  }
2439

    
2440
  return $modules;
2441
}
2442

    
2443
/**
2444
 * Rebuild, save, and return data about all currently available modules.
2445
 *
2446
 * @return
2447
 *   Array of all available modules and their data.
2448
 */
2449
function system_rebuild_module_data() {
2450
  $modules_cache = &drupal_static(__FUNCTION__);
2451
  // Only rebuild once per request. $modules and $modules_cache cannot be
2452
  // combined into one variable, because the $modules_cache variable is reset by
2453
  // reference from system_list_reset() during the rebuild.
2454
  if (!isset($modules_cache)) {
2455
    $modules = _system_rebuild_module_data();
2456
    ksort($modules);
2457
    system_get_files_database($modules, 'module');
2458
    system_update_files_database($modules, 'module');
2459
    $modules = _module_build_dependencies($modules);
2460
    $modules_cache = $modules;
2461
  }
2462
  return $modules_cache;
2463
}
2464

    
2465
/**
2466
 * Refresh bootstrap column in the system table.
2467
 *
2468
 * This is called internally by module_enable/disable() to flag modules that
2469
 * implement hooks used during bootstrap, such as hook_boot(). These modules
2470
 * are loaded earlier to invoke the hooks.
2471
 */
2472
function _system_update_bootstrap_status() {
2473
  $bootstrap_modules = array();
2474
  foreach (bootstrap_hooks() as $hook) {
2475
    foreach (module_implements($hook) as $module) {
2476
      $bootstrap_modules[] = $module;
2477
    }
2478
  }
2479
  $query = db_update('system')->fields(array('bootstrap' => 0));
2480
  if ($bootstrap_modules) {
2481
    db_update('system')
2482
      ->fields(array('bootstrap' => 1))
2483
      ->condition('name', $bootstrap_modules, 'IN')
2484
      ->execute();
2485
    $query->condition('name', $bootstrap_modules, 'NOT IN');
2486
  }
2487
  $query->execute();
2488
  // Reset the cached list of bootstrap modules.
2489
  system_list_reset();
2490
}
2491

    
2492
/**
2493
 * Helper function to scan and collect theme .info data and their engines.
2494
 *
2495
 * @return
2496
 *   An associative array of themes information.
2497
 */
2498
function _system_rebuild_theme_data() {
2499
  // Find themes
2500
  $themes = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.info$/', 'themes');
2501
  // Allow modules to add further themes.
2502
  if ($module_themes = module_invoke_all('system_theme_info')) {
2503
    foreach ($module_themes as $name => $uri) {
2504
      // @see file_scan_directory()
2505
      $themes[$name] = (object) array(
2506
        'uri' => $uri,
2507
        'filename' => pathinfo($uri, PATHINFO_FILENAME),
2508
        'name' => $name,
2509
      );
2510
    }
2511
  }
2512

    
2513
  // Find theme engines
2514
  $engines = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.engine$/', 'themes/engines');
2515

    
2516
  // Set defaults for theme info.
2517
  $defaults = array(
2518
    'engine' => 'phptemplate',
2519
    'regions' => array(
2520
      'sidebar_first' => 'Left sidebar',
2521
      'sidebar_second' => 'Right sidebar',
2522
      'content' => 'Content',
2523
      'header' => 'Header',
2524
      'footer' => 'Footer',
2525
      'highlighted' => 'Highlighted',
2526
      'help' => 'Help',
2527
      'page_top' => 'Page top',
2528
      'page_bottom' => 'Page bottom',
2529
    ),
2530
    'description' => '',
2531
    'features' => _system_default_theme_features(),
2532
    'screenshot' => 'screenshot.png',
2533
    'php' => DRUPAL_MINIMUM_PHP,
2534
    'stylesheets' => array(),
2535
    'scripts' => array(),
2536
  );
2537

    
2538
  $sub_themes = array();
2539
  // Read info files for each theme
2540
  foreach ($themes as $key => $theme) {
2541
    $themes[$key]->filename = $theme->uri;
2542
    $themes[$key]->info = drupal_parse_info_file($theme->uri) + $defaults;
2543

    
2544
    // Add the info file modification time, so it becomes available for
2545
    // contributed modules to use for ordering theme lists.
2546
    $themes[$key]->info['mtime'] = filemtime($theme->uri);
2547

    
2548
    // Invoke hook_system_info_alter() to give installed modules a chance to
2549
    // modify the data in the .info files if necessary.
2550
    $type = 'theme';
2551
    drupal_alter('system_info', $themes[$key]->info, $themes[$key], $type);
2552

    
2553
    if (!empty($themes[$key]->info['base theme'])) {
2554
      $sub_themes[] = $key;
2555
    }
2556
    if ($themes[$key]->info['engine'] == 'theme') {
2557
      $filename = dirname($themes[$key]->uri) . '/' . $themes[$key]->name . '.theme';
2558
      if (file_exists($filename)) {
2559
        $themes[$key]->owner = $filename;
2560
        $themes[$key]->prefix = $key;
2561
      }
2562
    }
2563
    else {
2564
      $engine = $themes[$key]->info['engine'];
2565
      if (isset($engines[$engine])) {
2566
        $themes[$key]->owner = $engines[$engine]->uri;
2567
        $themes[$key]->prefix = $engines[$engine]->name;
2568
        $themes[$key]->template = TRUE;
2569
      }
2570
    }
2571

    
2572
    // Prefix stylesheets and scripts with module path.
2573
    $path = dirname($theme->uri);
2574
    $theme->info['stylesheets'] = _system_info_add_path($theme->info['stylesheets'], $path);
2575
    $theme->info['scripts'] = _system_info_add_path($theme->info['scripts'], $path);
2576

    
2577
    // Give the screenshot proper path information.
2578
    if (!empty($themes[$key]->info['screenshot'])) {
2579
      $themes[$key]->info['screenshot'] = $path . '/' . $themes[$key]->info['screenshot'];
2580
    }
2581
  }
2582

    
2583
  // Now that we've established all our master themes, go back and fill in data
2584
  // for subthemes.
2585
  foreach ($sub_themes as $key) {
2586
    $themes[$key]->base_themes = drupal_find_base_themes($themes, $key);
2587
    // Don't proceed if there was a problem with the root base theme.
2588
    if (!current($themes[$key]->base_themes)) {
2589
      continue;
2590
    }
2591
    $base_key = key($themes[$key]->base_themes);
2592
    foreach (array_keys($themes[$key]->base_themes) as $base_theme) {
2593
      $themes[$base_theme]->sub_themes[$key] = $themes[$key]->info['name'];
2594
    }
2595
    // Copy the 'owner' and 'engine' over if the top level theme uses a theme
2596
    // engine.
2597
    if (isset($themes[$base_key]->owner)) {
2598
      if (isset($themes[$base_key]->info['engine'])) {
2599
        $themes[$key]->info['engine'] = $themes[$base_key]->info['engine'];
2600
        $themes[$key]->owner = $themes[$base_key]->owner;
2601
        $themes[$key]->prefix = $themes[$base_key]->prefix;
2602
      }
2603
      else {
2604
        $themes[$key]->prefix = $key;
2605
      }
2606
    }
2607
  }
2608

    
2609
  return $themes;
2610
}
2611

    
2612
/**
2613
 * Rebuild, save, and return data about all currently available themes.
2614
 *
2615
 * @return
2616
 *   Array of all available themes and their data.
2617
 */
2618
function system_rebuild_theme_data() {
2619
  $themes = _system_rebuild_theme_data();
2620
  ksort($themes);
2621
  system_get_files_database($themes, 'theme');
2622
  system_update_files_database($themes, 'theme');
2623
  return $themes;
2624
}
2625

    
2626
/**
2627
 * Prefixes all values in an .info file array with a given path.
2628
 *
2629
 * This helper function is mainly used to prefix all array values of an .info
2630
 * file property with a single given path (to the module or theme); e.g., to
2631
 * prefix all values of the 'stylesheets' or 'scripts' properties with the file
2632
 * path to the defining module/theme.
2633
 *
2634
 * @param $info
2635
 *   A nested array of data of an .info file to be processed.
2636
 * @param $path
2637
 *   A file path to prepend to each value in $info.
2638
 *
2639
 * @return
2640
 *   The $info array with prefixed values.
2641
 *
2642
 * @see _system_rebuild_module_data()
2643
 * @see _system_rebuild_theme_data()
2644
 */
2645
function _system_info_add_path($info, $path) {
2646
  foreach ($info as $key => $value) {
2647
    // Recurse into nested values until we reach the deepest level.
2648
    if (is_array($value)) {
2649
      $info[$key] = _system_info_add_path($info[$key], $path);
2650
    }
2651
    // Unset the original value's key and set the new value with prefix, using
2652
    // the original value as key, so original values can still be looked up.
2653
    else {
2654
      unset($info[$key]);
2655
      $info[$value] = $path . '/' . $value;
2656
    }
2657
  }
2658
  return $info;
2659
}
2660

    
2661
/**
2662
 * Returns an array of default theme features.
2663
 */
2664
function _system_default_theme_features() {
2665
  return array(
2666
    'logo',
2667
    'favicon',
2668
    'name',
2669
    'slogan',
2670
    'node_user_picture',
2671
    'comment_user_picture',
2672
    'comment_user_verification',
2673
    'main_menu',
2674
    'secondary_menu',
2675
  );
2676
}
2677

    
2678
/**
2679
 * Find all the base themes for the specified theme.
2680
 *
2681
 * This function has been deprecated in favor of drupal_find_base_themes().
2682
 */
2683
function system_find_base_themes($themes, $key, $used_keys = array()) {
2684
  return drupal_find_base_themes($themes, $key, $used_keys);
2685
}
2686

    
2687
/**
2688
 * Get a list of available regions from a specified theme.
2689
 *
2690
 * @param $theme_key
2691
 *   The name of a theme.
2692
 * @param $show
2693
 *   Possible values: REGIONS_ALL or REGIONS_VISIBLE. Visible excludes hidden
2694
 *   regions.
2695
 * @return
2696
 *   An array of regions in the form $region['name'] = 'description'.
2697
 */
2698
function system_region_list($theme_key, $show = REGIONS_ALL) {
2699
  $themes = list_themes();
2700
  if (!isset($themes[$theme_key])) {
2701
    return array();
2702
  }
2703

    
2704
  $list = array();
2705
  $info = $themes[$theme_key]->info;
2706
  // If requested, suppress hidden regions. See block_admin_display_form().
2707
  foreach ($info['regions'] as $name => $label) {
2708
    if ($show == REGIONS_ALL || !isset($info['regions_hidden']) || !in_array($name, $info['regions_hidden'])) {
2709
      $list[$name] = t($label);
2710
    }
2711
  }
2712

    
2713
  return $list;
2714
}
2715

    
2716
/**
2717
 * Implements hook_system_info_alter().
2718
 */
2719
function system_system_info_alter(&$info, $file, $type) {
2720
  // Remove page-top and page-bottom from the blocks UI since they are reserved for
2721
  // modules to populate from outside the blocks system.
2722
  if ($type == 'theme') {
2723
    $info['regions_hidden'][] = 'page_top';
2724
    $info['regions_hidden'][] = 'page_bottom';
2725
  }
2726
}
2727

    
2728
/**
2729
 * Get the name of the default region for a given theme.
2730
 *
2731
 * @param $theme
2732
 *   The name of a theme.
2733
 * @return
2734
 *   A string that is the region name.
2735
 */
2736
function system_default_region($theme) {
2737
  $regions = array_keys(system_region_list($theme, REGIONS_VISIBLE));
2738
  return isset($regions[0]) ? $regions[0] : '';
2739
}
2740

    
2741
/**
2742
 * Sets up a form to save information automatically.
2743
 *
2744
 * This function adds a submit handler and a submit button to a form array. The
2745
 * submit function saves all the data in the form, using variable_set(), to
2746
 * variables named the same as the keys in the form array. Note that this means
2747
 * you should normally prefix your form array keys with your module name, so
2748
 * that they are unique when passed into variable_set().
2749
 *
2750
 * If you need to manipulate the data in a custom manner, you can either put
2751
 * your own submission handler in the form array before calling this function,
2752
 * or just use your own submission handler instead of calling this function.
2753
 *
2754
 * @param $form
2755
 *   An associative array containing the structure of the form.
2756
 *
2757
 * @return
2758
 *   The form structure.
2759
 *
2760
 * @see system_settings_form_submit()
2761
 *
2762
 * @ingroup forms
2763
 */
2764
function system_settings_form($form) {
2765
  $form['actions']['#type'] = 'actions';
2766
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
2767

    
2768
  if (!empty($_POST) && form_get_errors()) {
2769
    drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
2770
  }
2771
  $form['#submit'][] = 'system_settings_form_submit';
2772
  // By default, render the form using theme_system_settings_form().
2773
  if (!isset($form['#theme'])) {
2774
    $form['#theme'] = 'system_settings_form';
2775
  }
2776
  return $form;
2777
}
2778

    
2779
/**
2780
 * Form submission handler for system_settings_form().
2781
 *
2782
 * If you want node type configure style handling of your checkboxes,
2783
 * add an array_filter value to your form.
2784
 */
2785
function system_settings_form_submit($form, &$form_state) {
2786
  // Exclude unnecessary elements.
2787
  form_state_values_clean($form_state);
2788

    
2789
  foreach ($form_state['values'] as $key => $value) {
2790
    if (is_array($value) && isset($form_state['values']['array_filter'])) {
2791
      $value = array_keys(array_filter($value));
2792
    }
2793
    variable_set($key, $value);
2794
  }
2795

    
2796
  drupal_set_message(t('The configuration options have been saved.'));
2797
}
2798

    
2799
/**
2800
 * Helper function to sort requirements.
2801
 */
2802
function _system_sort_requirements($a, $b) {
2803
  if (!isset($a['weight'])) {
2804
    if (!isset($b['weight'])) {
2805
      return strcmp($a['title'], $b['title']);
2806
    }
2807
    return -$b['weight'];
2808
  }
2809
  return isset($b['weight']) ? $a['weight'] - $b['weight'] : $a['weight'];
2810
}
2811

    
2812
/**
2813
 * Generates a form array for a confirmation form.
2814
 *
2815
 * This function returns a complete form array for confirming an action. The
2816
 * form contains a confirm button as well as a cancellation link that allows a
2817
 * user to abort the action.
2818
 *
2819
 * If the submit handler for a form that implements confirm_form() is invoked,
2820
 * the user successfully confirmed the action. You should never directly
2821
 * inspect $_POST to see if an action was confirmed.
2822
 *
2823
 * Note - if the parameters $question, $description, $yes, or $no could contain
2824
 * any user input (such as node titles or taxonomy terms), it is the
2825
 * responsibility of the code calling confirm_form() to sanitize them first with
2826
 * a function like check_plain() or filter_xss().
2827
 *
2828
 * @param $form
2829
 *   Additional elements to add to the form. These can be regular form elements,
2830
 *   #value elements, etc., and their values will be available to the submit
2831
 *   handler.
2832
 * @param $question
2833
 *   The question to ask the user (e.g. "Are you sure you want to delete the
2834
 *   block <em>foo</em>?"). The page title will be set to this value.
2835
 * @param $path
2836
 *   The page to go to if the user cancels the action. This can be either:
2837
 *   - A string containing a Drupal path.
2838
 *   - An associative array with a 'path' key. Additional array values are
2839
 *     passed as the $options parameter to l().
2840
 *   If the 'destination' query parameter is set in the URL when viewing a
2841
 *   confirmation form, that value will be used instead of $path.
2842
 * @param $description
2843
 *   Additional text to display. Defaults to t('This action cannot be undone.').
2844
 * @param $yes
2845
 *   A caption for the button that confirms the action (e.g. "Delete",
2846
 *   "Replace", ...). Defaults to t('Confirm').
2847
 * @param $no
2848
 *   A caption for the link which cancels the action (e.g. "Cancel"). Defaults
2849
 *   to t('Cancel').
2850
 * @param $name
2851
 *   The internal name used to refer to the confirmation item.
2852
 *
2853
 * @return
2854
 *   The form array.
2855
 */
2856
function confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm') {
2857
  $description = isset($description) ? $description : t('This action cannot be undone.');
2858

    
2859
  // Prepare cancel link.
2860
  if (isset($_GET['destination'])) {
2861
    $options = drupal_parse_url(urldecode($_GET['destination']));
2862
  }
2863
  elseif (is_array($path)) {
2864
    $options = $path;
2865
  }
2866
  else {
2867
    $options = array('path' => $path);
2868
  }
2869

    
2870
  drupal_set_title($question, PASS_THROUGH);
2871

    
2872
  $form['#attributes']['class'][] = 'confirmation';
2873
  $form['description'] = array('#markup' => $description);
2874
  $form[$name] = array('#type' => 'hidden', '#value' => 1);
2875

    
2876
  $form['actions'] = array('#type' => 'actions');
2877
  $form['actions']['submit'] = array(
2878
    '#type' => 'submit',
2879
    '#value' => $yes ? $yes : t('Confirm'),
2880
  );
2881
  $form['actions']['cancel'] = array(
2882
    '#type' => 'link',
2883
    '#title' => $no ? $no : t('Cancel'),
2884
    '#href' => $options['path'],
2885
    '#options' => $options,
2886
  );
2887
  // By default, render the form using theme_confirm_form().
2888
  if (!isset($form['#theme'])) {
2889
    $form['#theme'] = 'confirm_form';
2890
  }
2891
  return $form;
2892
}
2893

    
2894
/**
2895
 * Determines whether the current user is in compact mode.
2896
 *
2897
 * Compact mode shows certain administration pages with less description text,
2898
 * such as the configuration page and the permissions page.
2899
 *
2900
 * Whether the user is in compact mode is determined by a cookie, which is set
2901
 * for the user by system_admin_compact_page().
2902
 *
2903
 * If the user does not have the cookie, the default value is given by the
2904
 * system variable 'admin_compact_mode', which itself defaults to FALSE. This
2905
 * does not have a user interface to set it: it is a hidden variable which can
2906
 * be set in the settings.php file.
2907
 *
2908
 * @return
2909
 *   TRUE when in compact mode, FALSE when in expanded mode.
2910
 */
2911
function system_admin_compact_mode() {
2912
  // PHP converts dots into underscores in cookie names to avoid problems with
2913
  // its parser, so we use a converted cookie name.
2914
  return isset($_COOKIE['Drupal_visitor_admin_compact_mode']) ? $_COOKIE['Drupal_visitor_admin_compact_mode'] : variable_get('admin_compact_mode', FALSE);
2915
}
2916

    
2917
/**
2918
 * Menu callback; Sets whether the admin menu is in compact mode or not.
2919
 *
2920
 * @param $mode
2921
 *   Valid values are 'on' and 'off'.
2922
 */
2923
function system_admin_compact_page($mode = 'off') {
2924
  user_cookie_save(array('admin_compact_mode' => ($mode == 'on')));
2925
  drupal_goto();
2926
}
2927

    
2928
/**
2929
 * Generate a list of tasks offered by a specified module.
2930
 *
2931
 * @param $module
2932
 *   Module name.
2933
 * @param $info
2934
 *   The module's information, as provided by system_get_info().
2935
 *
2936
 * @return
2937
 *   An array of task links.
2938
 */
2939
function system_get_module_admin_tasks($module, $info) {
2940
  $links = &drupal_static(__FUNCTION__);
2941

    
2942
  if (!isset($links)) {
2943
    $links = array();
2944
    $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));
2945
    $query->join('menu_router', 'm', 'm.path = ml.router_path');
2946
    $query
2947
      ->fields('ml')
2948
      // Weight should be taken from {menu_links}, not {menu_router}.
2949
      ->fields('m', array_diff(drupal_schema_fields_sql('menu_router'), array('weight')))
2950
      ->condition('ml.link_path', 'admin/%', 'LIKE')
2951
      ->condition('ml.hidden', 0, '>=')
2952
      ->condition('ml.module', 'system')
2953
      ->condition('m.number_parts', 1, '>')
2954
      ->condition('m.page_callback', 'system_admin_menu_block_page', '<>');
2955
    foreach ($query->execute() as $link) {
2956
      _menu_link_translate($link);
2957
      if ($link['access']) {
2958
        $links[$link['router_path']] = $link;
2959
      }
2960
    }
2961
  }
2962

    
2963
  $admin_tasks = array();
2964
  $titles = array();
2965
  if ($menu = module_invoke($module, 'menu')) {
2966
    foreach ($menu as $path => $item) {
2967
      if (isset($links[$path])) {
2968
        $task = $links[$path];
2969
        // The link description, either derived from 'description' in
2970
        // hook_menu() or customized via menu module is used as title attribute.
2971
        if (!empty($task['localized_options']['attributes']['title'])) {
2972
          $task['description'] = $task['localized_options']['attributes']['title'];
2973
          unset($task['localized_options']['attributes']['title']);
2974
        }
2975

    
2976
        // Check the admin tasks for duplicate names. If one is found,
2977
        // append the parent menu item's title to differentiate.
2978
        $duplicate_path = array_search($task['title'], $titles);
2979
        if ($duplicate_path !== FALSE) {
2980
          if ($parent = menu_link_load($task['plid'])) {
2981
            // Append the parent item's title to this task's title.
2982
            $task['title'] = t('@original_title (@parent_title)', array('@original_title' => $task['title'], '@parent_title' => $parent['title']));
2983
          }
2984
          if ($parent = menu_link_load($admin_tasks[$duplicate_path]['plid'])) {
2985
            // Append the parent item's title to the duplicated task's title.
2986
            // We use $links[$duplicate_path] in case there are triplicates.
2987
            $admin_tasks[$duplicate_path]['title'] = t('@original_title (@parent_title)', array('@original_title' => $links[$duplicate_path]['title'], '@parent_title' => $parent['title']));
2988
          }
2989
        }
2990
        else {
2991
          $titles[$path] = $task['title'];
2992
        }
2993

    
2994
        $admin_tasks[$path] = $task;
2995
      }
2996
    }
2997
  }
2998

    
2999
  // Append link for permissions.
3000
  if (module_hook($module, 'permission')) {
3001
    $item = menu_get_item('admin/people/permissions');
3002
    if (!empty($item['access'])) {
3003
      $item['link_path'] = $item['href'];
3004
      $item['title'] = t('Configure @module permissions', array('@module' => $info['name']));
3005
      unset($item['description']);
3006
      $item['localized_options']['fragment'] = 'module-' . $module;
3007
      $admin_tasks["admin/people/permissions#module-$module"] = $item;
3008
    }
3009
  }
3010

    
3011
  return $admin_tasks;
3012
}
3013

    
3014
/**
3015
 * Implements hook_cron().
3016
 *
3017
 * Remove older rows from flood and batch table. Remove old temporary files.
3018
 */
3019
function system_cron() {
3020
  // Cleanup the flood.
3021
  db_delete('flood')
3022
    ->condition('expiration', REQUEST_TIME, '<')
3023
    ->execute();
3024

    
3025
  // Remove temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
3026
  // Use separate placeholders for the status to avoid a bug in some versions
3027
  // of PHP. See http://drupal.org/node/352956.
3028
  $result = db_query('SELECT fid FROM {file_managed} WHERE status <> :permanent AND timestamp < :timestamp', array(
3029
    ':permanent' => FILE_STATUS_PERMANENT,
3030
    ':timestamp' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE
3031
  ));
3032
  foreach ($result as $row) {
3033
    if ($file = file_load($row->fid)) {
3034
      $references = file_usage_list($file);
3035
      if (empty($references)) {
3036
        if (!file_delete($file)) {
3037
          watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' => $file->uri), WATCHDOG_ERROR);
3038
        }
3039
      }
3040
      else {
3041
        watchdog('file system', 'Did not delete temporary file "%path" during garbage collection, because it is in use by the following modules: %modules.', array('%path' => $file->uri, '%modules' => implode(', ', array_keys($references))), WATCHDOG_INFO);
3042
      }
3043
    }
3044
  }
3045

    
3046
  $core = array('cache', 'cache_path', 'cache_filter', 'cache_page', 'cache_form', 'cache_menu');
3047
  $cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
3048
  foreach ($cache_tables as $table) {
3049
    cache_clear_all(NULL, $table);
3050
  }
3051

    
3052
  // Cleanup the batch table and the queue for failed batches.
3053
  db_delete('batch')
3054
    ->condition('timestamp', REQUEST_TIME - 864000, '<')
3055
    ->execute();
3056
  db_delete('queue')
3057
    ->condition('created', REQUEST_TIME - 864000, '<')
3058
    ->condition('name', 'drupal_batch:%', 'LIKE')
3059
    ->execute();
3060

    
3061
  // Reset expired items in the default queue implementation table. If that's
3062
  // not used, this will simply be a no-op.
3063
  db_update('queue')
3064
    ->fields(array(
3065
      'expire' => 0,
3066
    ))
3067
    ->condition('expire', 0, '<>')
3068
    ->condition('expire', REQUEST_TIME, '<')
3069
    ->execute();
3070
}
3071

    
3072
/**
3073
 * Implements hook_flush_caches().
3074
 */
3075
function system_flush_caches() {
3076
  // Rebuild list of date formats.
3077
  system_date_formats_rebuild();
3078
  // Reset the menu static caches.
3079
  menu_reset_static_cache();
3080
}
3081

    
3082
/**
3083
 * Implements hook_action_info().
3084
 */
3085
function system_action_info() {
3086
  return array(
3087
    'system_message_action' => array(
3088
      'type' => 'system',
3089
      'label' => t('Display a message to the user'),
3090
      'configurable' => TRUE,
3091
      'triggers' => array('any'),
3092
    ),
3093
    'system_send_email_action' => array(
3094
      'type' => 'system',
3095
      'label' => t('Send e-mail'),
3096
      'configurable' => TRUE,
3097
      'triggers' => array('any'),
3098
    ),
3099
    'system_block_ip_action' => array(
3100
      'type' => 'user',
3101
      'label' => t('Ban IP address of current user'),
3102
      'configurable' => FALSE,
3103
      'triggers' => array('any'),
3104
    ),
3105
    'system_goto_action' => array(
3106
      'type' => 'system',
3107
      'label' => t('Redirect to URL'),
3108
      'configurable' => TRUE,
3109
      'triggers' => array('any'),
3110
    ),
3111
  );
3112
}
3113

    
3114
/**
3115
 * Return a form definition so the Send email action can be configured.
3116
 *
3117
 * @param $context
3118
 *   Default values (if we are editing an existing action instance).
3119
 *
3120
 * @return
3121
 *   Form definition.
3122
 *
3123
 * @see system_send_email_action_validate()
3124
 * @see system_send_email_action_submit()
3125
 */
3126
function system_send_email_action_form($context) {
3127
  // Set default values for form.
3128
  if (!isset($context['recipient'])) {
3129
    $context['recipient'] = '';
3130
  }
3131
  if (!isset($context['subject'])) {
3132
    $context['subject'] = '';
3133
  }
3134
  if (!isset($context['message'])) {
3135
    $context['message'] = '';
3136
  }
3137

    
3138
  $form['recipient'] = array(
3139
    '#type' => 'textfield',
3140
    '#title' => t('Recipient'),
3141
    '#default_value' => $context['recipient'],
3142
    '#maxlength' => '254',
3143
    '#description' => t('The email address to which the message should be sent OR enter [node:author:mail], [comment:author:mail], etc. if you would like to send an e-mail to the author of the original post.'),
3144
  );
3145
  $form['subject'] = array(
3146
    '#type' => 'textfield',
3147
    '#title' => t('Subject'),
3148
    '#default_value' => $context['subject'],
3149
    '#maxlength' => '254',
3150
    '#description' => t('The subject of the message.'),
3151
  );
3152
  $form['message'] = array(
3153
    '#type' => 'textarea',
3154
    '#title' => t('Message'),
3155
    '#default_value' => $context['message'],
3156
    '#cols' => '80',
3157
    '#rows' => '20',
3158
    '#description' => t('The message that should be sent. You may include placeholders like [node:title], [user:name], and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'),
3159
  );
3160
  return $form;
3161
}
3162

    
3163
/**
3164
 * Validate system_send_email_action form submissions.
3165
 */
3166
function system_send_email_action_validate($form, $form_state) {
3167
  $form_values = $form_state['values'];
3168
  // Validate the configuration form.
3169
  if (!valid_email_address($form_values['recipient']) && strpos($form_values['recipient'], ':mail') === FALSE) {
3170
    // We want the literal %author placeholder to be emphasized in the error message.
3171
    form_set_error('recipient', t('Enter a valid email address or use a token e-mail address such as %author.', array('%author' => '[node:author:mail]')));
3172
  }
3173
}
3174

    
3175
/**
3176
 * Process system_send_email_action form submissions.
3177
 */
3178
function system_send_email_action_submit($form, $form_state) {
3179
  $form_values = $form_state['values'];
3180
  // Process the HTML form to store configuration. The keyed array that
3181
  // we return will be serialized to the database.
3182
  $params = array(
3183
    'recipient' => $form_values['recipient'],
3184
    'subject'   => $form_values['subject'],
3185
    'message'   => $form_values['message'],
3186
  );
3187
  return $params;
3188
}
3189

    
3190
/**
3191
 * Sends an e-mail message.
3192
 *
3193
 * @param object $entity
3194
 *   An optional node object, which will be added as $context['node'] if
3195
 *   provided.
3196
 * @param array $context
3197
 *   Array with the following elements:
3198
 *   - 'recipient': E-mail message recipient. This will be passed through
3199
 *     token_replace().
3200
 *   - 'subject': The subject of the message. This will be passed through
3201
 *     token_replace().
3202
 *   - 'message': The message to send. This will be passed through
3203
 *     token_replace().
3204
 *   - Other elements will be used as the data for token replacement.
3205
 *
3206
 * @ingroup actions
3207
 */
3208
function system_send_email_action($entity, $context) {
3209
  if (empty($context['node'])) {
3210
    $context['node'] = $entity;
3211
  }
3212

    
3213
  $recipient = token_replace($context['recipient'], $context);
3214

    
3215
  // If the recipient is a registered user with a language preference, use
3216
  // the recipient's preferred language. Otherwise, use the system default
3217
  // language.
3218
  $recipient_account = user_load_by_mail($recipient);
3219
  if ($recipient_account) {
3220
    $language = user_preferred_language($recipient_account);
3221
  }
3222
  else {
3223
    $language = language_default();
3224
  }
3225
  $params = array('context' => $context);
3226

    
3227
  if (drupal_mail('system', 'action_send_email', $recipient, $language, $params)) {
3228
    watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient));
3229
  }
3230
  else {
3231
    watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient));
3232
  }
3233
}
3234

    
3235
/**
3236
 * Implements hook_mail().
3237
 */
3238
function system_mail($key, &$message, $params) {
3239
  $context = $params['context'];
3240

    
3241
  $subject = token_replace($context['subject'], $context);
3242
  $body = token_replace($context['message'], $context);
3243

    
3244
  $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
3245
  $message['body'][] = $body;
3246
}
3247

    
3248
function system_message_action_form($context) {
3249
  $form['message'] = array(
3250
    '#type' => 'textarea',
3251
    '#title' => t('Message'),
3252
    '#default_value' => isset($context['message']) ? $context['message'] : '',
3253
    '#required' => TRUE,
3254
    '#rows' => '8',
3255
    '#description' => t('The message to be displayed to the current user. You may include placeholders like [node:title], [user:name], and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'),
3256
  );
3257
  return $form;
3258
}
3259

    
3260
function system_message_action_submit($form, $form_state) {
3261
  return array('message' => $form_state['values']['message']);
3262
}
3263

    
3264
/**
3265
 * Sends a message to the current user's screen.
3266
 *
3267
 * @param object $entity
3268
 *   An optional node object, which will be added as $context['node'] if
3269
 *   provided.
3270
 * @param array $context
3271
 *   Array with the following elements:
3272
 *   - 'message': The message to send. This will be passed through
3273
 *     token_replace().
3274
 *   - Other elements will be used as the data for token replacement in
3275
 *     the message.
3276
 *
3277
 * @ingroup actions
3278
 */
3279
function system_message_action(&$entity, $context = array()) {
3280
  if (empty($context['node'])) {
3281
    $context['node'] = $entity;
3282
  }
3283

    
3284
  $context['message'] = token_replace(filter_xss_admin($context['message']), $context);
3285
  drupal_set_message($context['message']);
3286
}
3287

    
3288
/**
3289
 * Settings form for system_goto_action().
3290
 */
3291
function system_goto_action_form($context) {
3292
  $form['url'] = array(
3293
    '#type' => 'textfield',
3294
    '#title' => t('URL'),
3295
    '#description' => t('The URL to which the user should be redirected. This can be an internal URL like node/1234 or an external URL like http://drupal.org.'),
3296
    '#default_value' => isset($context['url']) ? $context['url'] : '',
3297
    '#required' => TRUE,
3298
  );
3299
  return $form;
3300
}
3301

    
3302
function system_goto_action_submit($form, $form_state) {
3303
  return array(
3304
    'url' => $form_state['values']['url']
3305
  );
3306
}
3307

    
3308
/**
3309
 * Redirects to a different URL.
3310
 *
3311
 * @param $entity
3312
 *   Ignored.
3313
 * @param array $context
3314
 *   Array with the following elements:
3315
 *   - 'url': URL to redirect to. This will be passed through
3316
 *     token_replace().
3317
 *   - Other elements will be used as the data for token replacement.
3318
 *
3319
 * @ingroup actions
3320
 */
3321
function system_goto_action($entity, $context) {
3322
  drupal_goto(token_replace($context['url'], $context));
3323
}
3324

    
3325
/**
3326
 * Blocks the current user's IP address.
3327
 *
3328
 * @ingroup actions
3329
 */
3330
function system_block_ip_action() {
3331
  $ip = ip_address();
3332
  db_insert('blocked_ips')
3333
    ->fields(array('ip' => $ip))
3334
    ->execute();
3335
  watchdog('action', 'Banned IP address %ip', array('%ip' => $ip));
3336
}
3337

    
3338
/**
3339
 * Generate an array of time zones and their local time&date.
3340
 *
3341
 * @param $blank
3342
 *   If evaluates true, prepend an empty time zone option to the array.
3343
 */
3344
function system_time_zones($blank = NULL) {
3345
  $zonelist = timezone_identifiers_list();
3346
  $zones = $blank ? array('' => t('- None selected -')) : array();
3347
  foreach ($zonelist as $zone) {
3348
    // Because many time zones exist in PHP only for backward compatibility
3349
    // reasons and should not be used, the list is filtered by a regular
3350
    // expression.
3351
    if (preg_match('!^((Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)/|UTC$)!', $zone)) {
3352
      $zones[$zone] = t('@zone: @date', array('@zone' => t(str_replace('_', ' ', $zone)), '@date' => format_date(REQUEST_TIME, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') . ' O', $zone)));
3353
    }
3354
  }
3355
  // Sort the translated time zones alphabetically.
3356
  asort($zones);
3357
  return $zones;
3358
}
3359

    
3360
/**
3361
 * Checks whether the server is capable of issuing HTTP requests.
3362
 *
3363
 * The function sets the drupal_http_request_fail system variable to TRUE if
3364
 * drupal_http_request() does not work and then the system status report page
3365
 * will contain an error.
3366
 *
3367
 * @return
3368
 *  TRUE if this installation can issue HTTP requests.
3369
 */
3370
function system_check_http_request() {
3371
  // Try to get the content of the front page via drupal_http_request().
3372
  $result = drupal_http_request(url('', array('absolute' => TRUE)), array('max_redirects' => 0));
3373
  // We only care that we get a http response - this means that Drupal
3374
  // can make a http request.
3375
  $works = isset($result->code) && ($result->code >= 100) && ($result->code < 600);
3376
  variable_set('drupal_http_request_fails', !$works);
3377
  return $works;
3378
}
3379

    
3380
/**
3381
 * Menu callback; Retrieve a JSON object containing a suggested time zone name.
3382
 */
3383
function system_timezone($abbreviation = '', $offset = -1, $is_daylight_saving_time = NULL) {
3384
  // An abbreviation of "0" passed in the callback arguments should be
3385
  // interpreted as the empty string.
3386
  $abbreviation = $abbreviation ? $abbreviation : '';
3387
  $timezone = timezone_name_from_abbr($abbreviation, intval($offset), $is_daylight_saving_time);
3388
  drupal_json_output($timezone);
3389
}
3390

    
3391
/**
3392
 * Returns HTML for the Powered by Drupal text.
3393
 *
3394
 * @ingroup themeable
3395
 */
3396
function theme_system_powered_by() {
3397
  return '<span>' . t('Powered by <a href="@poweredby">Drupal</a>', array('@poweredby' => 'https://www.drupal.org')) . '</span>';
3398
}
3399

    
3400
/**
3401
 * Returns HTML for a link to show or hide inline help descriptions.
3402
 *
3403
 * @ingroup themeable
3404
 */
3405
function theme_system_compact_link() {
3406
  $output = '<div class="compact-link">';
3407
  if (system_admin_compact_mode()) {
3408
    $output .= l(t('Show descriptions'), 'admin/compact/off', array('attributes' => array('title' => t('Expand layout to include descriptions.')), 'query' => drupal_get_destination()));
3409
  }
3410
  else {
3411
    $output .= l(t('Hide descriptions'), 'admin/compact/on', array('attributes' => array('title' => t('Compress layout by hiding descriptions.')), 'query' => drupal_get_destination()));
3412
  }
3413
  $output .= '</div>';
3414

    
3415
  return $output;
3416
}
3417

    
3418
/**
3419
 * Implements hook_image_toolkits().
3420
 */
3421
function system_image_toolkits() {
3422
  include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'system') . '/' . 'image.gd.inc';
3423
  return array(
3424
    'gd' => array(
3425
      'title' => t('GD2 image manipulation toolkit'),
3426
      'available' => function_exists('image_gd_check_settings') && image_gd_check_settings(),
3427
    ),
3428
  );
3429
}
3430

    
3431
/**
3432
 * Attempts to get a file using drupal_http_request and to store it locally.
3433
 *
3434
 * @param string $url
3435
 *   The URL of the file to grab.
3436
 * @param string $destination
3437
 *   Stream wrapper URI specifying where the file should be placed. If a
3438
 *   directory path is provided, the file is saved into that directory under
3439
 *   its original name. If the path contains a filename as well, that one will
3440
 *   be used instead.
3441
 *   If this value is omitted, the site's default files scheme will be used,
3442
 *   usually "public://".
3443
 * @param bool $managed
3444
 *   If this is set to TRUE, the file API hooks will be invoked and the file is
3445
 *   registered in the database.
3446
 * @param int $replace
3447
 *   Replace behavior when the destination file already exists:
3448
 *   - FILE_EXISTS_REPLACE: Replace the existing file.
3449
 *   - FILE_EXISTS_RENAME: Append _{incrementing number} until the filename is
3450
 *     unique.
3451
 *   - FILE_EXISTS_ERROR: Do nothing and return FALSE.
3452
 *
3453
 * @return mixed
3454
 *   One of these possibilities:
3455
 *   - If it succeeds and $managed is FALSE, the location where the file was
3456
 *     saved.
3457
 *   - If it succeeds and $managed is TRUE, a \Drupal\file\FileInterface
3458
 *     object which describes the file.
3459
 *   - If it fails, FALSE.
3460
 */
3461
function system_retrieve_file($url, $destination = NULL, $managed = FALSE, $replace = FILE_EXISTS_RENAME) {
3462
  $parsed_url = parse_url($url);
3463
  if (!isset($destination)) {
3464
    $path = file_build_uri(drupal_basename($parsed_url['path']));
3465
  }
3466
  else {
3467
    if (is_dir(drupal_realpath($destination))) {
3468
      // Prevent URIs with triple slashes when glueing parts together.
3469
      $path = str_replace('///', '//', "$destination/") . drupal_basename($parsed_url['path']);
3470
    }
3471
    else {
3472
      $path = $destination;
3473
    }
3474
  }
3475
  $result = drupal_http_request($url);
3476
  if ($result->code != 200) {
3477
    drupal_set_message(t('HTTP error @errorcode occurred when trying to fetch @remote.', array('@errorcode' => $result->code, '@remote' => $url)), 'error');
3478
    return FALSE;
3479
  }
3480
  $local = $managed ? file_save_data($result->data, $path, $replace) : file_unmanaged_save_data($result->data, $path, $replace);
3481
  if (!$local) {
3482
    drupal_set_message(t('@remote could not be saved to @path.', array('@remote' => $url, '@path' => $path)), 'error');
3483
  }
3484

    
3485
  return $local;
3486
}
3487

    
3488
/**
3489
 * Implements hook_page_alter().
3490
 */
3491
function system_page_alter(&$page) {
3492
  // Find all non-empty page regions, and add a theme wrapper function that
3493
  // allows them to be consistently themed.
3494
  $regions = system_region_list($GLOBALS['theme']);
3495
  foreach (array_keys($regions) as $region) {
3496
    if (!empty($page[$region])) {
3497
      $page[$region]['#theme_wrappers'][] = 'region';
3498
      $page[$region]['#region'] = $region;
3499
    }
3500
  }
3501
}
3502

    
3503
/**
3504
 * Run the automated cron if enabled.
3505
 */
3506
function system_run_automated_cron() {
3507
  // If the site is not fully installed, suppress the automated cron run.
3508
  // Otherwise it could be triggered prematurely by Ajax requests during
3509
  // installation.
3510
  if (($threshold = variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD)) > 0 && variable_get('install_task') == 'done') {
3511
    $cron_last = variable_get('cron_last', NULL);
3512
    if (!isset($cron_last) || (REQUEST_TIME - $cron_last > $threshold)) {
3513
      drupal_cron_run();
3514
    }
3515
  }
3516
}
3517

    
3518
/**
3519
 * Gets the list of available date types and attributes.
3520
 *
3521
 * @param $type
3522
 *   (optional) The date type name.
3523
 *
3524
 * @return
3525
 *   An associative array of date type information keyed by the date type name.
3526
 *   Each date type information array has the following elements:
3527
 *   - type: The machine-readable name of the date type.
3528
 *   - title: The human-readable name of the date type.
3529
 *   - locked: A boolean indicating whether or not this date type should be
3530
 *     configurable from the user interface.
3531
 *   - module: The name of the module that defined this date type in its
3532
 *     hook_date_format_types(). An empty string if the date type was
3533
 *     user-defined.
3534
 *   - is_new: A boolean indicating whether or not this date type is as of yet
3535
 *     unsaved in the database.
3536
 *   If $type was defined, only a single associative array with the above
3537
 *   elements is returned.
3538
 */
3539
function system_get_date_types($type = NULL) {
3540
  $types = &drupal_static(__FUNCTION__);
3541

    
3542
  if (!isset($types)) {
3543
    $types = _system_date_format_types_build();
3544
  }
3545

    
3546
  return $type ? (isset($types[$type]) ? $types[$type] : FALSE) : $types;
3547
}
3548

    
3549
/**
3550
 * Implements hook_date_format_types().
3551
 */
3552
function system_date_format_types() {
3553
  return array(
3554
    'long' => t('Long'),
3555
    'medium' => t('Medium'),
3556
    'short' => t('Short'),
3557
  );
3558
}
3559

    
3560
/**
3561
 * Implements hook_date_formats().
3562
 */
3563
function system_date_formats() {
3564
  include_once DRUPAL_ROOT . '/includes/date.inc';
3565
  return system_default_date_formats();
3566
}
3567

    
3568
/**
3569
 * Gets the list of defined date formats and attributes.
3570
 *
3571
 * @param $type
3572
 *   (optional) The date type name.
3573
 *
3574
 * @return
3575
 *   An associative array of date formats. The top-level keys are the names of
3576
 *   the date types that the date formats belong to. The values are in turn
3577
 *   associative arrays keyed by the format string, with the following keys:
3578
 *   - dfid: The date format ID.
3579
 *   - format: The format string.
3580
 *   - type: The machine-readable name of the date type.
3581
 *   - locales: An array of language codes. This can include both 2 character
3582
 *     language codes like 'en and 'fr' and 5 character language codes like
3583
 *     'en-gb' and 'en-us'.
3584
 *   - locked: A boolean indicating whether or not this date type should be
3585
 *     configurable from the user interface.
3586
 *   - module: The name of the module that defined this date format in its
3587
 *     hook_date_formats(). An empty string if the format was user-defined.
3588
 *   - is_new: A boolean indicating whether or not this date type is as of yet
3589
 *     unsaved in the database.
3590
 *   If $type was defined, only the date formats associated with the given date
3591
 *   type are returned, in a single associative array keyed by format string.
3592
 */
3593
function system_get_date_formats($type = NULL) {
3594
  $date_formats = &drupal_static(__FUNCTION__);
3595

    
3596
  if (!isset($date_formats)) {
3597
    $date_formats = _system_date_formats_build();
3598
  }
3599

    
3600
  return $type ? (isset($date_formats[$type]) ? $date_formats[$type] : FALSE) : $date_formats;
3601
}
3602

    
3603
/**
3604
 * Gets the format details for a particular format ID.
3605
 *
3606
 * @param $dfid
3607
 *   A date format ID.
3608
 *
3609
 * @return
3610
 *   A date format object with the following properties:
3611
 *   - dfid: The date format ID.
3612
 *   - format: The date format string.
3613
 *   - type: The name of the date type.
3614
 *   - locked: Whether the date format can be changed or not.
3615
 */
3616
function system_get_date_format($dfid) {
3617
  return db_query('SELECT df.dfid, df.format, df.type, df.locked FROM {date_formats} df WHERE df.dfid = :dfid', array(':dfid' => $dfid))->fetch();
3618
}
3619

    
3620
/**
3621
 * Resets the database cache of date formats and saves all new date formats.
3622
 */
3623
function system_date_formats_rebuild() {
3624
  drupal_static_reset('system_get_date_formats');
3625
  $date_formats = system_get_date_formats(NULL);
3626

    
3627
  foreach ($date_formats as $type => $formats) {
3628
    foreach ($formats as $format => $info) {
3629
      system_date_format_save($info);
3630
    }
3631
  }
3632

    
3633
  // Rebuild configured date formats locale list.
3634
  drupal_static_reset('system_date_format_locale');
3635
  system_date_format_locale();
3636

    
3637
  _system_date_formats_build();
3638
}
3639

    
3640
/**
3641
 * Gets the appropriate date format string for a date type and locale.
3642
 *
3643
 * @param $langcode
3644
 *   (optional) Language code for the current locale. This can be a 2 character
3645
 *   language code like 'en' and 'fr' or a 5 character language code like
3646
 *   'en-gb' and 'en-us'.
3647
 * @param $type
3648
 *   (optional) The date type name.
3649
 *
3650
 * @return
3651
 *   If $type and $langcode are specified, returns the corresponding date format
3652
 *   string. If only $langcode is specified, returns an array of all date
3653
 *   format strings for that locale, keyed by the date type. If neither is
3654
 *   specified, or if no matching formats are found, returns FALSE.
3655
 */
3656
function system_date_format_locale($langcode = NULL, $type = NULL) {
3657
  $formats = &drupal_static(__FUNCTION__);
3658

    
3659
  if (empty($formats)) {
3660
    $formats = array();
3661
    $result = db_query("SELECT format, type, language FROM {date_format_locale}");
3662
    foreach ($result as $record) {
3663
      if (!isset($formats[$record->language])) {
3664
        $formats[$record->language] = array();
3665
      }
3666
      $formats[$record->language][$record->type] = $record->format;
3667
    }
3668
  }
3669

    
3670
  if ($type && $langcode && !empty($formats[$langcode][$type])) {
3671
    return $formats[$langcode][$type];
3672
  }
3673
  elseif ($langcode && !empty($formats[$langcode])) {
3674
    return $formats[$langcode];
3675
  }
3676

    
3677
  return FALSE;
3678
}
3679

    
3680
/**
3681
 * Builds and returns information about available date types.
3682
 *
3683
 * @return
3684
 *   An associative array of date type information keyed by name. Each date type
3685
 *   information array has the following elements:
3686
 *   - type: The machine-readable name of the date type.
3687
 *   - title: The human-readable name of the date type.
3688
 *   - locked: A boolean indicating whether or not this date type should be
3689
 *     configurable from the user interface.
3690
 *   - module: The name of the module that defined this format in its
3691
 *     hook_date_format_types(). An empty string if the format was user-defined.
3692
 *   - is_new: A boolean indicating whether or not this date type is as of yet
3693
 *     unsaved in the database.
3694
 */
3695
function _system_date_format_types_build() {
3696
  $types = array();
3697

    
3698
  // Get list of modules that implement hook_date_format_types().
3699
  $modules = module_implements('date_format_types');
3700

    
3701
  foreach ($modules as $module) {
3702
    $module_types = module_invoke($module, 'date_format_types');
3703
    foreach ($module_types as $module_type => $type_title) {
3704
      $type = array();
3705
      $type['module'] = $module;
3706
      $type['type'] = $module_type;
3707
      $type['title'] = $type_title;
3708
      $type['locked'] = 1;
3709
      // Will be over-ridden later if in the db.
3710
      $type['is_new'] = TRUE;
3711
      $types[$module_type] = $type;
3712
    }
3713
  }
3714

    
3715
  // Get custom formats added to the database by the end user.
3716
  $result = db_query('SELECT dft.type, dft.title, dft.locked FROM {date_format_type} dft ORDER BY dft.title');
3717
  foreach ($result as $record) {
3718
    if (!isset($types[$record->type])) {
3719
      $type = array();
3720
      $type['is_new'] = FALSE;
3721
      $type['module'] = '';
3722
      $type['type'] = $record->type;
3723
      $type['title'] = $record->title;
3724
      $type['locked'] = $record->locked;
3725
      $types[$record->type] = $type;
3726
    }
3727
    else {
3728
      $type = array();
3729
      $type['is_new'] = FALSE;  // Over-riding previous setting.
3730
      $types[$record->type] = array_merge($types[$record->type], $type);
3731
    }
3732
  }
3733

    
3734
  // Allow other modules to modify these date types.
3735
  drupal_alter('date_format_types', $types);
3736

    
3737
  return $types;
3738
}
3739

    
3740
/**
3741
 * Builds and returns information about available date formats.
3742
 *
3743
 * @return
3744
 *   An associative array of date formats. The top-level keys are the names of
3745
 *   the date types that the date formats belong to. The values are in turn
3746
 *   associative arrays keyed by format with the following keys:
3747
 *   - dfid: The date format ID.
3748
 *   - format: The PHP date format string.
3749
 *   - type: The machine-readable name of the date type the format belongs to.
3750
 *   - locales: An array of language codes. This can include both 2 character
3751
 *     language codes like 'en and 'fr' and 5 character language codes like
3752
 *     'en-gb' and 'en-us'.
3753
 *   - locked: A boolean indicating whether or not this date type should be
3754
 *     configurable from the user interface.
3755
 *   - module: The name of the module that defined this format in its
3756
 *     hook_date_formats(). An empty string if the format was user-defined.
3757
 *   - is_new: A boolean indicating whether or not this date type is as of yet
3758
 *     unsaved in the database.
3759
 */
3760
function _system_date_formats_build() {
3761
  $date_formats = array();
3762

    
3763
  // First handle hook_date_format_types().
3764
  $types = _system_date_format_types_build();
3765
  foreach ($types as $type => $info) {
3766
    system_date_format_type_save($info);
3767
  }
3768

    
3769
  // Get formats supplied by various contrib modules.
3770
  $module_formats = module_invoke_all('date_formats');
3771

    
3772
  foreach ($module_formats as $module_format) {
3773
    // System types are locked.
3774
    $module_format['locked'] = 1;
3775
    // If no date type is specified, assign 'custom'.
3776
    if (!isset($module_format['type'])) {
3777
      $module_format['type'] = 'custom';
3778
    }
3779
    if (!in_array($module_format['type'], array_keys($types))) {
3780
      continue;
3781
    }
3782
    if (!isset($date_formats[$module_format['type']])) {
3783
      $date_formats[$module_format['type']] = array();
3784
    }
3785

    
3786
    // If another module already set this format, merge in the new settings.
3787
    if (isset($date_formats[$module_format['type']][$module_format['format']])) {
3788
      $date_formats[$module_format['type']][$module_format['format']] = array_merge_recursive($date_formats[$module_format['type']][$module_format['format']], $module_format);
3789
    }
3790
    else {
3791
      // This setting will be overridden later if it already exists in the db.
3792
      $module_format['is_new'] = TRUE;
3793
      $date_formats[$module_format['type']][$module_format['format']] = $module_format;
3794
    }
3795
  }
3796

    
3797
  // Get custom formats added to the database by the end user.
3798
  $result = db_query('SELECT df.dfid, df.format, df.type, df.locked, dfl.language FROM {date_formats} df LEFT JOIN {date_format_locale} dfl ON df.format = dfl.format AND df.type = dfl.type ORDER BY df.type, df.format');
3799
  foreach ($result as $record) {
3800
    // If this date type isn't set, initialise the array.
3801
    if (!isset($date_formats[$record->type])) {
3802
      $date_formats[$record->type] = array();
3803
    }
3804
    $format = (array) $record;
3805
    $format['is_new'] = FALSE; // It's in the db, so override this setting.
3806
    // If this format not already present, add it to the array.
3807
    if (!isset($date_formats[$record->type][$record->format])) {
3808
      $format['module'] = '';
3809
      $format['locales'] = array($record->language);
3810
      $date_formats[$record->type][$record->format] = $format;
3811
    }
3812
    // Format already present, so merge in settings.
3813
    else {
3814
      if (!empty($record->language)) {
3815
        $format['locales'] = array_merge($date_formats[$record->type][$record->format]['locales'], array($record->language));
3816
      }
3817
      $date_formats[$record->type][$record->format] = array_merge($date_formats[$record->type][$record->format], $format);
3818
    }
3819
  }
3820

    
3821
  // Allow other modules to modify these formats.
3822
  drupal_alter('date_formats', $date_formats);
3823

    
3824
  return $date_formats;
3825
}
3826

    
3827
/**
3828
 * Saves a date type to the database.
3829
 *
3830
 * @param $type
3831
 *   A date type array containing the following keys:
3832
 *   - type: The machine-readable name of the date type.
3833
 *   - title: The human-readable name of the date type.
3834
 *   - locked: A boolean indicating whether or not this date type should be
3835
 *     configurable from the user interface.
3836
 *   - is_new: A boolean indicating whether or not this date type is as of yet
3837
 *     unsaved in the database.
3838
 */
3839
function system_date_format_type_save($type) {
3840
  $info = array();
3841
  $info['type'] = $type['type'];
3842
  $info['title'] = $type['title'];
3843
  $info['locked'] = $type['locked'];
3844

    
3845
  // Update date_format table.
3846
  if (!empty($type['is_new'])) {
3847
    drupal_write_record('date_format_type', $info);
3848
  }
3849
  else {
3850
    drupal_write_record('date_format_type', $info, 'type');
3851
  }
3852
}
3853

    
3854
/**
3855
 * Deletes a date type from the database.
3856
 *
3857
 * @param $type
3858
 *   The machine-readable name of the date type.
3859
 */
3860
function system_date_format_type_delete($type) {
3861
  db_delete('date_formats')
3862
    ->condition('type', $type)
3863
    ->execute();
3864
  db_delete('date_format_type')
3865
    ->condition('type', $type)
3866
    ->execute();
3867
  db_delete('date_format_locale')
3868
    ->condition('type', $type)
3869
    ->execute();
3870
}
3871

    
3872
/**
3873
 * Saves a date format to the database.
3874
 *
3875
 * @param $date_format
3876
 *   A date format array containing the following keys:
3877
 *   - type: The name of the date type this format is associated with.
3878
 *   - format: The PHP date format string.
3879
 *   - locked: A boolean indicating whether or not this format should be
3880
 *     configurable from the user interface.
3881
 * @param $dfid
3882
 *   If set, replace the existing date format having this ID with the
3883
 *   information specified in $date_format.
3884
 *
3885
 * @see system_get_date_types()
3886
 * @see http://php.net/date
3887
 */
3888
function system_date_format_save($date_format, $dfid = 0) {
3889
  $info = array();
3890
  $info['dfid'] = $dfid;
3891
  $info['type'] = $date_format['type'];
3892
  $info['format'] = $date_format['format'];
3893
  $info['locked'] = $date_format['locked'];
3894

    
3895
  // Update date_format table.
3896
  if (!empty($date_format['is_new'])) {
3897
    drupal_write_record('date_formats', $info);
3898
  }
3899
  else {
3900
    $keys = ($dfid ? array('dfid') : array('format', 'type'));
3901
    drupal_write_record('date_formats', $info, $keys);
3902
  }
3903

    
3904
  // Retrieve an array of language objects for enabled languages.
3905
  $languages = language_list('enabled');
3906
  // This list is keyed off the value of $language->enabled; we want the ones
3907
  // that are enabled (value of 1).
3908
  $languages = $languages[1];
3909

    
3910
  $locale_format = array();
3911
  $locale_format['type'] = $date_format['type'];
3912
  $locale_format['format'] = $date_format['format'];
3913

    
3914
  // Check if the suggested language codes are configured and enabled.
3915
  if (!empty($date_format['locales'])) {
3916
    foreach ($date_format['locales'] as $langcode) {
3917
      // Only proceed if language is enabled.
3918
      if (isset($languages[$langcode])) {
3919
        $is_existing = (bool) db_query_range('SELECT 1 FROM {date_format_locale} WHERE type = :type AND language = :language', 0, 1, array(':type' => $date_format['type'], ':language' => $langcode))->fetchField();
3920
        if (!$is_existing) {
3921
          $locale_format['language'] = $langcode;
3922
          drupal_write_record('date_format_locale', $locale_format);
3923
        }
3924
      }
3925
    }
3926
  }
3927
}
3928

    
3929
/**
3930
 * Deletes a date format from the database.
3931
 *
3932
 * @param $dfid
3933
 *   The date format ID.
3934
 */
3935
function system_date_format_delete($dfid) {
3936
  db_delete('date_formats')
3937
    ->condition('dfid', $dfid)
3938
    ->execute();
3939
}
3940

    
3941
/**
3942
 * Implements hook_archiver_info().
3943
 */
3944
function system_archiver_info() {
3945
  $archivers['tar'] = array(
3946
    'class' => 'ArchiverTar',
3947
    'extensions' => array('tar', 'tgz', 'tar.gz', 'tar.bz2'),
3948
  );
3949
  if (function_exists('zip_open')) {
3950
    $archivers['zip'] = array(
3951
      'class' => 'ArchiverZip',
3952
      'extensions' => array('zip'),
3953
    );
3954
  }
3955
  return $archivers;
3956
}
3957

    
3958
/**
3959
 * Returns HTML for a confirmation form.
3960
 *
3961
 * By default this does not alter the appearance of a form at all,
3962
 * but is provided as a convenience for themers.
3963
 *
3964
 * @param $variables
3965
 *   An associative array containing:
3966
 *   - form: A render element representing the form.
3967
 *
3968
 * @ingroup themeable
3969
 */
3970
function theme_confirm_form($variables) {
3971
  return drupal_render_children($variables['form']);
3972
}
3973

    
3974
/**
3975
 * Returns HTML for a system settings form.
3976
 *
3977
 * By default this does not alter the appearance of a form at all,
3978
 * but is provided as a convenience for themers.
3979
 *
3980
 * @param $variables
3981
 *   An associative array containing:
3982
 *   - form: A render element representing the form.
3983
 *
3984
 * @ingroup themeable
3985
 */
3986
function theme_system_settings_form($variables) {
3987
  return drupal_render_children($variables['form']);
3988
}
3989

    
3990
/**
3991
 * Returns HTML for an exposed filter form.
3992
 *
3993
 * @param $variables
3994
 *   An associative array containing:
3995
 *   - form: An associative array containing the structure of the form.
3996
 *
3997
 * @return
3998
 *   A string containing an HTML-formatted form.
3999
 *
4000
 * @ingroup themeable
4001
 */
4002
function theme_exposed_filters($variables) {
4003
  $form = $variables['form'];
4004
  $output = '';
4005

    
4006
  if (isset($form['current'])) {
4007
    $items = array();
4008
    foreach (element_children($form['current']) as $key) {
4009
      $items[] = drupal_render($form['current'][$key]);
4010
    }
4011
    $output .= theme('item_list', array('items' => $items, 'attributes' => array('class' => array('clearfix', 'current-filters'))));
4012
  }
4013

    
4014
  $output .= drupal_render_children($form);
4015

    
4016
  return '<div class="exposed-filters">' . $output . '</div>';
4017
}
4018

    
4019
/**
4020
 * Implements hook_admin_paths().
4021
 */
4022
function system_admin_paths() {
4023
  $paths = array(
4024
    'admin' => TRUE,
4025
    'admin/*' => TRUE,
4026
    'batch' => TRUE,
4027
    // This page should not be treated as administrative since it outputs its
4028
    // own content (outside of any administration theme).
4029
    'admin/reports/status/php' => FALSE,
4030
  );
4031
  return $paths;
4032
}