Projet

Général

Profil

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

root / drupal7 / modules / system / system.module @ 26e8440b

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
  $types['scripts'] = array(
327
    '#items' => array(),
328
    '#pre_render' => array('drupal_pre_render_scripts'),
329
  );
330

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

    
474
  // Form structure.
475
  $types['item'] = array(
476
    '#markup' => '',
477
    '#pre_render' => array('drupal_pre_render_markup'),
478
    '#theme_wrappers' => array('form_element'),
479
  );
480
  $types['hidden'] = array(
481
    '#input' => TRUE,
482
    '#process' => array('ajax_process_form'),
483
    '#theme' => 'hidden',
484
  );
485
  $types['value'] = array(
486
    '#input' => TRUE,
487
  );
488
  $types['markup'] = array(
489
    '#markup' => '',
490
    '#pre_render' => array('drupal_pre_render_markup'),
491
  );
492
  $types['link'] = array(
493
    '#pre_render' => array('drupal_pre_render_link', 'drupal_pre_render_markup'),
494
  );
495
  $types['fieldset'] = array(
496
    '#collapsible' => FALSE,
497
    '#collapsed' => FALSE,
498
    '#value' => NULL,
499
    '#process' => array('form_process_fieldset', 'ajax_process_form'),
500
    '#pre_render' => array('form_pre_render_fieldset'),
501
    '#theme_wrappers' => array('fieldset'),
502
  );
503
  $types['vertical_tabs'] = array(
504
    '#theme_wrappers' => array('vertical_tabs'),
505
    '#default_tab' => '',
506
    '#process' => array('form_process_vertical_tabs'),
507
  );
508

    
509
  $types['container'] = array(
510
    '#theme_wrappers' => array('container'),
511
    '#process' => array('form_process_container'),
512
  );
513
  $types['actions'] = array(
514
    '#theme_wrappers' => array('container'),
515
    '#process' => array('form_process_actions', 'form_process_container'),
516
    '#weight' => 100,
517
  );
518

    
519
  $types['token'] = array(
520
    '#input' => TRUE,
521
    '#theme' => 'hidden',
522
  );
523

    
524
  return $types;
525
}
526

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

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

    
656
  foreach (list_themes() as $theme) {
657
    $items['admin/appearance/settings/' . $theme->name] = array(
658
      'title' => $theme->info['name'],
659
      'page arguments' => array('system_theme_settings', $theme->name),
660
      'type' => MENU_LOCAL_TASK,
661
      'access callback' => '_system_themes_access',
662
      'access arguments' => array($theme),
663
      'file' => 'system.admin.inc',
664
    );
665
  }
666

    
667
  // Modules.
668
  $items['admin/modules'] = array(
669
    'title' => 'Modules',
670
    'description' => 'Extend site functionality.',
671
    'page callback' => 'drupal_get_form',
672
    'page arguments' => array('system_modules'),
673
    'access arguments' => array('administer modules'),
674
    'file' => 'system.admin.inc',
675
    'weight' => -2,
676
  );
677
  $items['admin/modules/list'] = array(
678
    'title' => 'List',
679
    'type' => MENU_DEFAULT_LOCAL_TASK,
680
  );
681
  $items['admin/modules/list/confirm'] = array(
682
    'title' => 'List',
683
    'access arguments' => array('administer modules'),
684
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
685
  );
686
  $items['admin/modules/uninstall'] = array(
687
    'title' => 'Uninstall',
688
    'page arguments' => array('system_modules_uninstall'),
689
    'access arguments' => array('administer modules'),
690
    'type' => MENU_LOCAL_TASK,
691
    'file' => 'system.admin.inc',
692
    'weight' => 20,
693
  );
694
  $items['admin/modules/uninstall/confirm'] = array(
695
    'title' => 'Uninstall',
696
    'access arguments' => array('administer modules'),
697
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
698
    'file' => 'system.admin.inc',
699
  );
700

    
701
  // Configuration.
702
  $items['admin/config'] = array(
703
    'title' => 'Configuration',
704
    'description' => 'Administer settings.',
705
    'page callback' => 'system_admin_config_page',
706
    'access arguments' => array('access administration pages'),
707
    'file' => 'system.admin.inc',
708
  );
709

    
710
  // IP address blocking.
711
  $items['admin/config/people/ip-blocking'] = array(
712
    'title' => 'IP address blocking',
713
    'description' => 'Manage blocked IP addresses.',
714
    'page callback' => 'system_ip_blocking',
715
    'access arguments' => array('block IP addresses'),
716
    'file' => 'system.admin.inc',
717
    'weight' => 10,
718
  );
719
  $items['admin/config/people/ip-blocking/delete/%blocked_ip'] = array(
720
    'title' => 'Delete IP address',
721
    'page callback' => 'drupal_get_form',
722
    'page arguments' => array('system_ip_blocking_delete', 5),
723
    'access arguments' => array('block IP addresses'),
724
    'file' => 'system.admin.inc',
725
  );
726

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

    
756
  // Service settings.
757
  $items['admin/config/services'] = array(
758
    'title' => 'Web services',
759
    'description' => 'Tools related to web services.',
760
    'position' => 'right',
761
    'weight' => 0,
762
    'page callback' => 'system_admin_menu_block_page',
763
    'access arguments' => array('access administration pages'),
764
    'file' => 'system.admin.inc',
765
  );
766
  $items['admin/config/services/rss-publishing'] = array(
767
    'title' => 'RSS publishing',
768
    'description' => 'Configure the site description, the number of items per feed and whether feeds should be titles/teasers/full-text.',
769
    'page callback' => 'drupal_get_form',
770
    'page arguments' => array('system_rss_feeds_settings'),
771
    'access arguments' => array('administer site configuration'),
772
    'file' => 'system.admin.inc',
773
  );
774

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

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

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

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

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

    
1068
  // Default page for batch operations.
1069
  $items['batch'] = array(
1070
    'page callback' => 'system_batch_page',
1071
    'access callback' => TRUE,
1072
    'theme callback' => '_system_batch_theme',
1073
    'type' => MENU_CALLBACK,
1074
    'file' => 'system.admin.inc',
1075
  );
1076
  return $items;
1077
}
1078

    
1079
/**
1080
 * Theme callback for the default batch page.
1081
 */
1082
function _system_batch_theme() {
1083
  // Retrieve the current state of the batch.
1084
  $batch = &batch_get();
1085
  if (!$batch && isset($_REQUEST['id'])) {
1086
    require_once DRUPAL_ROOT . '/includes/batch.inc';
1087
    $batch = batch_load($_REQUEST['id']);
1088
  }
1089
  // Use the same theme as the page that started the batch.
1090
  if (!empty($batch['theme'])) {
1091
    return $batch['theme'];
1092
  }
1093
}
1094

    
1095
/**
1096
 * Implements hook_library().
1097
 */
1098
function system_library() {
1099
  // Drupal's Ajax framework.
1100
  $libraries['drupal.ajax'] = array(
1101
    'title' => 'Drupal AJAX',
1102
    'website' => 'http://api.drupal.org/api/drupal/includes--ajax.inc/group/ajax/7',
1103
    'version' => VERSION,
1104
    'js' => array(
1105
      'misc/ajax.js' => array('group' => JS_LIBRARY, 'weight' => 2),
1106
    ),
1107
    'dependencies' => array(
1108
      array('system', 'drupal.progress'),
1109
    ),
1110
  );
1111

    
1112
  // Drupal's batch API.
1113
  $libraries['drupal.batch'] = array(
1114
    'title' => 'Drupal batch API',
1115
    'version' => VERSION,
1116
    'js' => array(
1117
      'misc/batch.js' => array('group' => JS_DEFAULT, 'cache' => FALSE),
1118
    ),
1119
    'dependencies' => array(
1120
      array('system', 'drupal.progress'),
1121
    ),
1122
  );
1123

    
1124
  // Drupal's progress indicator.
1125
  $libraries['drupal.progress'] = array(
1126
    'title' => 'Drupal progress indicator',
1127
    'version' => VERSION,
1128
    'js' => array(
1129
      'misc/progress.js' => array('group' => JS_DEFAULT),
1130
    ),
1131
  );
1132

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

    
1142
  // Drupal's states library.
1143
  $libraries['drupal.states'] = array(
1144
    'title' => 'Drupal states',
1145
    'version' => VERSION,
1146
    'js' => array(
1147
      'misc/states.js' => array('group' => JS_LIBRARY, 'weight' => 1),
1148
    ),
1149
  );
1150

    
1151
  // Drupal's collapsible fieldset.
1152
  $libraries['drupal.collapse'] = array(
1153
    'title' => 'Drupal collapsible fieldset',
1154
    'version' => VERSION,
1155
    'js' => array(
1156
      'misc/collapse.js' => array('group' => JS_DEFAULT),
1157
    ),
1158
    'dependencies' => array(
1159
      // collapse.js relies on drupalGetSummary in form.js
1160
      array('system', 'drupal.form'),
1161
    ),
1162
  );
1163

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

    
1173
  // Drupal's autocomplete widget.
1174
  $libraries['drupal.autocomplete'] = array(
1175
    'title' => 'Drupal autocomplete',
1176
    'version' => VERSION,
1177
    'js' => array(
1178
      'misc/autocomplete.js' => array('group' => JS_DEFAULT),
1179
    ),
1180
  );
1181

    
1182
  // jQuery.
1183
  $libraries['jquery'] = array(
1184
    'title' => 'jQuery',
1185
    'website' => 'http://jquery.com',
1186
    'version' => '1.4.4',
1187
    'js' => array(
1188
      'misc/jquery.js' => array('group' => JS_LIBRARY, 'weight' => -20),
1189
      // These include security fixes, so assign a weight that makes them load
1190
      // as soon after jquery.js is loaded as possible.
1191
      'misc/jquery-extend-3.4.0.js' => array('group' => JS_LIBRARY, 'weight' => -19),
1192
      'misc/jquery-html-prefilter-3.5.0-backport.js' => array('group' => JS_LIBRARY, 'weight' => -19),
1193
    ),
1194
  );
1195

    
1196
  // jQuery Once.
1197
  $libraries['jquery.once'] = array(
1198
    'title' => 'jQuery Once',
1199
    'website' => 'http://plugins.jquery.com/project/once',
1200
    'version' => '1.2',
1201
    'js' => array(
1202
      'misc/jquery.once.js' => array('group' => JS_LIBRARY, 'weight' => -19),
1203
    ),
1204
  );
1205

    
1206
  // jQuery Form Plugin.
1207
  $libraries['jquery.form'] = array(
1208
    'title' => 'jQuery Form Plugin',
1209
    'website' => 'http://malsup.com/jquery/form/',
1210
    'version' => '2.52',
1211
    'js' => array(
1212
      'misc/jquery.form.js' => array(),
1213
    ),
1214
    'dependencies' => array(
1215
      array('system', 'jquery.cookie'),
1216
    ),
1217
  );
1218

    
1219
  // jQuery BBQ plugin.
1220
  $libraries['jquery.bbq'] = array(
1221
    'title' => 'jQuery BBQ',
1222
    'website' => 'http://benalman.com/projects/jquery-bbq-plugin/',
1223
    'version' => '1.2.1',
1224
    'js' => array(
1225
      'misc/jquery.ba-bbq.js' => array(),
1226
    ),
1227
  );
1228

    
1229
  // Vertical Tabs.
1230
  $libraries['drupal.vertical-tabs'] = array(
1231
    'title' => 'Vertical Tabs',
1232
    'website' => 'http://drupal.org/node/323112',
1233
    'version' => '1.0',
1234
    'js' => array(
1235
      'misc/vertical-tabs.js' => array(),
1236
    ),
1237
    'css' => array(
1238
      'misc/vertical-tabs.css' => array(),
1239
    ),
1240
    'dependencies' => array(
1241
      // Vertical tabs relies on drupalGetSummary in form.js
1242
      array('system', 'drupal.form'),
1243
    ),
1244
  );
1245

    
1246
  // Farbtastic.
1247
  $libraries['farbtastic'] = array(
1248
    'title' => 'Farbtastic',
1249
    'website' => 'http://code.google.com/p/farbtastic/',
1250
    'version' => '1.2',
1251
    'js' => array(
1252
      'misc/farbtastic/farbtastic.js' => array(),
1253
    ),
1254
    'css' => array(
1255
      'misc/farbtastic/farbtastic.css' => array(),
1256
    ),
1257
  );
1258

    
1259
  // Cookie.
1260
  $libraries['jquery.cookie'] = array(
1261
    'title' => 'Cookie',
1262
    'website' => 'http://plugins.jquery.com/project/cookie',
1263
    'version' => '1.0',
1264
    'js' => array(
1265
      'misc/jquery.cookie.js' => array(),
1266
    ),
1267
  );
1268

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

    
1650
  // These library names are deprecated. Earlier versions of Drupal 7 didn't
1651
  // consistently namespace their libraries, so these names are included for
1652
  // backwards compatibility with those versions.
1653
  $libraries['once'] = &$libraries['jquery.once'];
1654
  $libraries['form'] = &$libraries['jquery.form'];
1655
  $libraries['jquery-bbq'] = &$libraries['jquery.bbq'];
1656
  $libraries['vertical-tabs'] = &$libraries['drupal.vertical-tabs'];
1657
  $libraries['cookie'] = &$libraries['jquery.cookie'];
1658

    
1659
  return $libraries;
1660
}
1661

    
1662
/**
1663
 * Implements hook_stream_wrappers().
1664
 */
1665
function system_stream_wrappers() {
1666
  $wrappers = array(
1667
    'public' => array(
1668
      'name' => t('Public files'),
1669
      'class' => 'DrupalPublicStreamWrapper',
1670
      'description' => t('Public local files served by the webserver.'),
1671
      'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
1672
    ),
1673
    'temporary' => array(
1674
      'name' => t('Temporary files'),
1675
      'class' => 'DrupalTemporaryStreamWrapper',
1676
      'description' => t('Temporary local files for upload and previews.'),
1677
      'type' => STREAM_WRAPPERS_LOCAL_HIDDEN,
1678
    ),
1679
  );
1680

    
1681
  // Only register the private file stream wrapper if a file path has been set.
1682
  if (variable_get('file_private_path', FALSE)) {
1683
    $wrappers['private'] = array(
1684
      'name' => t('Private files'),
1685
      'class' => 'DrupalPrivateStreamWrapper',
1686
      'description' => t('Private local files served by Drupal.'),
1687
      'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
1688
    );
1689
  }
1690

    
1691
  return $wrappers;
1692
}
1693

    
1694
/**
1695
 * Retrieve a blocked IP address from the database.
1696
 *
1697
 * @param $iid integer
1698
 *   The ID of the blocked IP address to retrieve.
1699
 *
1700
 * @return
1701
 *   The blocked IP address from the database as an array.
1702
 */
1703
function blocked_ip_load($iid) {
1704
  return db_query("SELECT * FROM {blocked_ips} WHERE iid = :iid", array(':iid' => $iid))->fetchAssoc();
1705
}
1706

    
1707
/**
1708
 * Menu item access callback - only admin or enabled themes can be accessed.
1709
 */
1710
function _system_themes_access($theme) {
1711
  return user_access('administer themes') && drupal_theme_access($theme);
1712
}
1713

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

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

    
1796
  // Now, define the callback to invoke.
1797
  $_SESSION['authorize_operation'] = array(
1798
    'callback' => $callback,
1799
    'file' => $file,
1800
    'arguments' => $arguments,
1801
  );
1802

    
1803
  if (isset($page_title)) {
1804
    $_SESSION['authorize_operation']['page_title'] = $page_title;
1805
  }
1806
}
1807

    
1808
/**
1809
 * Return the URL for the authorize.php script.
1810
 *
1811
 * @param array $options
1812
 *   Optional array of options to pass to url().
1813
 * @return
1814
 *   The full URL to authorize.php, using HTTPS if available.
1815
 *
1816
 * @see system_authorized_init()
1817
 */
1818
function system_authorized_get_url(array $options = array()) {
1819
  global $base_url;
1820
  // Force HTTPS if available, regardless of what the caller specifies.
1821
  $options['https'] = TRUE;
1822
  // We prefix with $base_url so we get a full path even if clean URLs are
1823
  // disabled.
1824
  return url($base_url . '/authorize.php', $options);
1825
}
1826

    
1827
/**
1828
 * Returns the URL for the authorize.php script when it is processing a batch.
1829
 */
1830
function system_authorized_batch_processing_url() {
1831
  return system_authorized_get_url(array('query' => array('batch' => '1')));
1832
}
1833

    
1834
/**
1835
 * Setup and invoke an operation using authorize.php.
1836
 *
1837
 * @see system_authorized_init()
1838
 */
1839
function system_authorized_run($callback, $file, $arguments = array(), $page_title = NULL) {
1840
  system_authorized_init($callback, $file, $arguments, $page_title);
1841
  drupal_goto(system_authorized_get_url());
1842
}
1843

    
1844
/**
1845
 * Use authorize.php to run batch_process().
1846
 *
1847
 * @see batch_process()
1848
 */
1849
function system_authorized_batch_process() {
1850
  $finish_url = system_authorized_get_url();
1851
  $process_url = system_authorized_batch_processing_url();
1852
  batch_process($finish_url, $process_url);
1853
}
1854

    
1855
/**
1856
 * @} End of "defgroup authorize".
1857
 */
1858

    
1859
/**
1860
 * Implements hook_updater_info().
1861
 */
1862
function system_updater_info() {
1863
  return array(
1864
    'module' => array(
1865
      'class' => 'ModuleUpdater',
1866
      'name' => t('Update modules'),
1867
      'weight' => 0,
1868
    ),
1869
    'theme' => array(
1870
      'class' => 'ThemeUpdater',
1871
      'name' => t('Update themes'),
1872
      'weight' => 0,
1873
    ),
1874
  );
1875
}
1876

    
1877
/**
1878
 * Implements hook_filetransfer_info().
1879
 */
1880
function system_filetransfer_info() {
1881
  $backends = array();
1882

    
1883
  // This is the default, will be available on most systems.
1884
  if (function_exists('ftp_connect')) {
1885
    $backends['ftp'] = array(
1886
      'title' => t('FTP'),
1887
      'class' => 'FileTransferFTP',
1888
      'file' => 'ftp.inc',
1889
      'file path' => 'includes/filetransfer',
1890
      'weight' => 0,
1891
    );
1892
  }
1893

    
1894
  // SSH2 lib connection is only available if the proper PHP extension is
1895
  // installed.
1896
  if (function_exists('ssh2_connect')) {
1897
    $backends['ssh'] = array(
1898
      'title' => t('SSH'),
1899
      'class' => 'FileTransferSSH',
1900
      'file' => 'ssh.inc',
1901
      'file path' => 'includes/filetransfer',
1902
      'weight' => 20,
1903
    );
1904
  }
1905
  return $backends;
1906
}
1907

    
1908
/**
1909
 * Implements hook_init().
1910
 */
1911
function system_init() {
1912
  $path = drupal_get_path('module', 'system');
1913
  // Add the CSS for this module. These aren't in system.info, because they
1914
  // need to be in the CSS_SYSTEM group rather than the CSS_DEFAULT group.
1915
  drupal_add_css($path . '/system.base.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
1916
  if (path_is_admin(current_path())) {
1917
    drupal_add_css($path . '/system.admin.css', array('group' => CSS_SYSTEM));
1918
  }
1919
  drupal_add_css($path . '/system.menus.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
1920
  drupal_add_css($path . '/system.messages.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
1921
  drupal_add_css($path . '/system.theme.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
1922

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

    
1946
  // Add CSS/JS files from module .info files.
1947
  system_add_module_assets();
1948
}
1949

    
1950
/**
1951
 * Adds CSS and JavaScript files declared in module .info files.
1952
 */
1953
function system_add_module_assets() {
1954
  foreach (system_get_info('module') as $module => $info) {
1955
    if (!empty($info['stylesheets'])) {
1956
      foreach ($info['stylesheets'] as $media => $stylesheets) {
1957
        foreach ($stylesheets as $stylesheet) {
1958
          drupal_add_css($stylesheet, array('every_page' => TRUE, 'media' => $media));
1959
        }
1960
      }
1961
    }
1962
    if (!empty($info['scripts'])) {
1963
      foreach ($info['scripts'] as $script) {
1964
        drupal_add_js($script, array('every_page' => TRUE));
1965
      }
1966
    }
1967
  }
1968
}
1969

    
1970
/**
1971
 * Implements hook_custom_theme().
1972
 */
1973
function system_custom_theme() {
1974
  if (user_access('view the administration theme') && path_is_admin(current_path())) {
1975
    return variable_get('admin_theme');
1976
  }
1977
}
1978

    
1979
/**
1980
 * Implements hook_form_FORM_ID_alter().
1981
 */
1982
function system_form_user_profile_form_alter(&$form, &$form_state) {
1983
  if ($form['#user_category'] == 'account') {
1984
    if (variable_get('configurable_timezones', 1)) {
1985
      system_user_timezone($form, $form_state);
1986
    }
1987
    return $form;
1988
  }
1989
}
1990

    
1991
/**
1992
 * Implements hook_form_FORM_ID_alter().
1993
 */
1994
function system_form_user_register_form_alter(&$form, &$form_state) {
1995
  if (variable_get('configurable_timezones', 1)) {
1996
    if (variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT) == DRUPAL_USER_TIMEZONE_SELECT) {
1997
      system_user_timezone($form, $form_state);
1998
    }
1999
    else {
2000
      $form['account']['timezone'] = array(
2001
        '#type' => 'hidden',
2002
        '#value' => variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT) ? '' : variable_get('date_default_timezone', ''),
2003
      );
2004
    }
2005
    return $form;
2006
  }
2007
}
2008

    
2009
/**
2010
 * Implements hook_user_login().
2011
 */
2012
function system_user_login(&$edit, $account) {
2013
  // If the user has a NULL time zone, notify them to set a time zone.
2014
  if (!$account->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) {
2015
    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')))));
2016
  }
2017
}
2018

    
2019
/**
2020
 * Add the time zone field to the user edit and register forms.
2021
 */
2022
function system_user_timezone(&$form, &$form_state) {
2023
  global $user;
2024

    
2025
  $account = $form['#user'];
2026

    
2027
  $form['timezone'] = array(
2028
    '#type' => 'fieldset',
2029
    '#title' => t('Locale settings'),
2030
    '#weight' => 6,
2031
    '#collapsible' => TRUE,
2032
  );
2033
  $form['timezone']['timezone'] = array(
2034
    '#type' => 'select',
2035
    '#title' => t('Time zone'),
2036
    '#default_value' => isset($account->timezone) ? $account->timezone : ($account->uid == $user->uid ? variable_get('date_default_timezone', '') : ''),
2037
    '#options' => system_time_zones($account->uid != $user->uid),
2038
    '#description' => t('Select the desired local time and time zone. Dates and times throughout this site will be displayed using this time zone.'),
2039
  );
2040
  if (!isset($account->timezone) && $account->uid == $user->uid && empty($form_state['input']['timezone'])) {
2041
    $form['timezone']['timezone']['#attributes'] = array('class' => array('timezone-detect'));
2042
    drupal_add_js('misc/timezone.js');
2043
  }
2044
}
2045

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

    
2082
/**
2083
 * Implements hook_block_view().
2084
 *
2085
 * Generate a block with a promotional link to Drupal.org and
2086
 * all system menu blocks.
2087
 */
2088
function system_block_view($delta = '') {
2089
  $block = array();
2090
  switch ($delta) {
2091
    case 'main':
2092
      $block['subject'] = NULL;
2093
      $block['content'] = drupal_set_page_content();
2094
      return $block;
2095
    case 'powered-by':
2096
      $block['subject'] = NULL;
2097
      $block['content'] = theme('system_powered_by');
2098
      return $block;
2099
    case 'help':
2100
      $block['subject'] = NULL;
2101
      $block['content'] = menu_get_active_help();
2102
      return $block;
2103
    default:
2104
      // All system menu blocks.
2105
      $system_menus = menu_list_system_menus();
2106
      if (isset($system_menus[$delta])) {
2107
        $block['subject'] = t($system_menus[$delta]);
2108
        $block['content'] = menu_tree($delta);
2109
        return $block;
2110
      }
2111
      break;
2112
  }
2113
}
2114

    
2115
/**
2116
 * Implements hook_preprocess_block().
2117
 */
2118
function system_preprocess_block(&$variables) {
2119
  // System menu blocks should get the same class as menu module blocks.
2120
  if ($variables['block']->module == 'system' && in_array($variables['block']->delta, array_keys(menu_list_system_menus()))) {
2121
    $variables['classes_array'][] = 'block-menu';
2122
  }
2123
}
2124

    
2125
/**
2126
 * Provide a single block on the administration overview page.
2127
 *
2128
 * @param $item
2129
 *   The menu item to be displayed.
2130
 */
2131
function system_admin_menu_block($item) {
2132
  $cache = &drupal_static(__FUNCTION__, array());
2133
  // If we are calling this function for a menu item that corresponds to a
2134
  // local task (for example, admin/tasks), then we want to retrieve the
2135
  // parent item's child links, not this item's (since this item won't have
2136
  // any).
2137
  if ($item['tab_root'] != $item['path']) {
2138
    $item = menu_get_item($item['tab_root_href']);
2139
  }
2140

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

    
2145
  if (isset($cache[$item['mlid']])) {
2146
    return $cache[$item['mlid']];
2147
  }
2148

    
2149
  $content = array();
2150
  $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));
2151
  $query->join('menu_router', 'm', 'm.path = ml.router_path');
2152
  $query
2153
    ->fields('ml')
2154
    // Weight should be taken from {menu_links}, not {menu_router}.
2155
    ->fields('m', array_diff(drupal_schema_fields_sql('menu_router'), array('weight')))
2156
    ->condition('ml.plid', $item['mlid'])
2157
    ->condition('ml.menu_name', $item['menu_name'])
2158
    ->condition('ml.hidden', 0);
2159

    
2160
  foreach ($query->execute() as $link) {
2161
    _menu_link_translate($link);
2162
    if ($link['access']) {
2163
      // The link description, either derived from 'description' in
2164
      // hook_menu() or customized via menu module is used as title attribute.
2165
      if (!empty($link['localized_options']['attributes']['title'])) {
2166
        $link['description'] = $link['localized_options']['attributes']['title'];
2167
        unset($link['localized_options']['attributes']['title']);
2168
      }
2169
      // Prepare for sorting as in function _menu_tree_check_access().
2170
      // The weight is offset so it is always positive, with a uniform 5-digits.
2171
      $key = (50000 + $link['weight']) . ' ' . drupal_strtolower($link['title']) . ' ' . $link['mlid'];
2172
      $content[$key] = $link;
2173
    }
2174
  }
2175
  ksort($content);
2176
  $cache[$item['mlid']] = $content;
2177
  return $content;
2178
}
2179

    
2180
/**
2181
 * Checks the existence of the directory specified in $form_element.
2182
 *
2183
 * This function is called from the system_settings form to check all core
2184
 * file directories (file_public_path, file_private_path, file_temporary_path).
2185
 *
2186
 * @param $form_element
2187
 *   The form element containing the name of the directory to check.
2188
 */
2189
function system_check_directory($form_element) {
2190
  $directory = $form_element['#value'];
2191
  if (strlen($directory) == 0) {
2192
    return $form_element;
2193
  }
2194

    
2195
  if (!is_dir($directory) && !drupal_mkdir($directory, NULL, TRUE)) {
2196
    // If the directory does not exists and cannot be created.
2197
    form_set_error($form_element['#parents'][0], t('The directory %directory does not exist and could not be created.', array('%directory' => $directory)));
2198
    watchdog('file system', 'The directory %directory does not exist and could not be created.', array('%directory' => $directory), WATCHDOG_ERROR);
2199
  }
2200

    
2201
  if (is_dir($directory) && !is_writable($directory) && !drupal_chmod($directory)) {
2202
    // If the directory is not writable and cannot be made so.
2203
    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)));
2204
    watchdog('file system', 'The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory), WATCHDOG_ERROR);
2205
  }
2206
  elseif (is_dir($directory)) {
2207
    if ($form_element['#name'] == 'file_public_path') {
2208
      // Create public .htaccess file.
2209
      file_create_htaccess($directory, FALSE);
2210
    }
2211
    else {
2212
      // Create private .htaccess file.
2213
      file_create_htaccess($directory);
2214
    }
2215
  }
2216

    
2217
  return $form_element;
2218
}
2219

    
2220
/**
2221
 * Retrieves the current status of an array of files in the system table.
2222
 *
2223
 * @param $files
2224
 *   An array of files to check.
2225
 * @param $type
2226
 *   The type of the files.
2227
 */
2228
function system_get_files_database(&$files, $type) {
2229
  // Extract current files from database.
2230
  $result = db_query("SELECT filename, name, type, status, schema_version, weight FROM {system} WHERE type = :type", array(':type' => $type));
2231
  foreach ($result as $file) {
2232
    if (isset($files[$file->name]) && is_object($files[$file->name])) {
2233
      $file->uri = $file->filename;
2234
      foreach ($file as $key => $value) {
2235
        if (!isset($files[$file->name]->$key)) {
2236
          $files[$file->name]->$key = $value;
2237
        }
2238
      }
2239
    }
2240
  }
2241
}
2242

    
2243
/**
2244
 * Updates the records in the system table based on the files array.
2245
 *
2246
 * @param $files
2247
 *   An array of files.
2248
 * @param $type
2249
 *   The type of the files.
2250
 */
2251
function system_update_files_database(&$files, $type) {
2252
  $result = db_query("SELECT * FROM {system} WHERE type = :type", array(':type' => $type));
2253

    
2254
  // Add all files that need to be deleted to a DatabaseCondition.
2255
  $delete = db_or();
2256
  foreach ($result as $file) {
2257
    if (isset($files[$file->name]) && is_object($files[$file->name])) {
2258
      // Keep the old filename from the database in case the file has moved.
2259
      $old_filename = $file->filename;
2260

    
2261
      $updated_fields = array();
2262

    
2263
      // Handle info specially, compare the serialized value.
2264
      $serialized_info = serialize($files[$file->name]->info);
2265
      if ($serialized_info != $file->info) {
2266
        $updated_fields['info'] = $serialized_info;
2267
      }
2268
      unset($file->info);
2269

    
2270
      // Scan remaining fields to find only the updated values.
2271
      foreach ($file as $key => $value) {
2272
        if (isset($files[$file->name]->$key) && $files[$file->name]->$key != $value) {
2273
          $updated_fields[$key] = $files[$file->name]->$key;
2274
        }
2275
      }
2276

    
2277
      // Update the record.
2278
      if (count($updated_fields)) {
2279
        db_update('system')
2280
          ->fields($updated_fields)
2281
          ->condition('filename', $old_filename)
2282
          ->execute();
2283
      }
2284

    
2285
      // Indicate that the file exists already.
2286
      $files[$file->name]->exists = TRUE;
2287
    }
2288
    else {
2289
      // File is not found in file system, so delete record from the system table.
2290
      $delete->condition('filename', $file->filename);
2291
    }
2292
  }
2293

    
2294
  if (count($delete) > 0) {
2295
    // Delete all missing files from the system table, but only if the plugin
2296
    // has never been installed.
2297
    db_delete('system')
2298
      ->condition($delete)
2299
      ->condition('schema_version', -1)
2300
      ->execute();
2301
  }
2302

    
2303
  // All remaining files are not in the system table, so we need to add them.
2304
  $query = db_insert('system')->fields(array('filename', 'name', 'type', 'owner', 'info'));
2305
  foreach ($files as &$file) {
2306
    if (isset($file->exists)) {
2307
      unset($file->exists);
2308
    }
2309
    else {
2310
      $query->values(array(
2311
        'filename' => $file->uri,
2312
        'name' => $file->name,
2313
        'type' => $type,
2314
        'owner' => isset($file->owner) ? $file->owner : '',
2315
        'info' => serialize($file->info),
2316
      ));
2317
      $file->type = $type;
2318
      $file->status = 0;
2319
      $file->schema_version = -1;
2320
    }
2321
  }
2322
  $query->execute();
2323

    
2324
  // If any module or theme was moved to a new location, we need to reset the
2325
  // system_list() cache or we will continue to load the old copy, look for
2326
  // schema updates in the wrong place, etc.
2327
  system_list_reset();
2328
}
2329

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

    
2369
/**
2370
 * Helper function to scan and collect module .info data.
2371
 *
2372
 * @return
2373
 *   An associative array of module information.
2374
 */
2375
function _system_rebuild_module_data() {
2376
  // Find modules
2377
  $modules = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.module$/', 'modules', 'name', 0);
2378

    
2379
  // Include the installation profile in modules that are loaded.
2380
  $profile = drupal_get_profile();
2381
  $modules[$profile] = new stdClass();
2382
  $modules[$profile]->name = $profile;
2383
  $modules[$profile]->uri = 'profiles/' . $profile . '/' . $profile . '.profile';
2384
  $modules[$profile]->filename = $profile . '.profile';
2385

    
2386
  // Installation profile hooks are always executed last.
2387
  $modules[$profile]->weight = 1000;
2388

    
2389
  // Set defaults for module info.
2390
  $defaults = array(
2391
    'dependencies' => array(),
2392
    'description' => '',
2393
    'package' => 'Other',
2394
    'version' => NULL,
2395
    'php' => DRUPAL_MINIMUM_PHP,
2396
    'files' => array(),
2397
    'bootstrap' => 0,
2398
  );
2399

    
2400
  // Read info files for each module.
2401
  foreach ($modules as $key => $module) {
2402
    // The module system uses the key 'filename' instead of 'uri' so copy the
2403
    // value so it will be used by the modules system.
2404
    $modules[$key]->filename = $module->uri;
2405

    
2406
    // Look for the info file.
2407
    $module->info = drupal_parse_info_file(dirname($module->uri) . '/' . $module->name . '.info');
2408

    
2409
    // Skip modules that don't provide info.
2410
    if (empty($module->info)) {
2411
      unset($modules[$key]);
2412
      continue;
2413
    }
2414

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

    
2419
    // Merge in defaults and save.
2420
    $modules[$key]->info = $module->info + $defaults;
2421

    
2422
    // The "name" key is required, but to avoid a fatal error in the menu system
2423
    // we set a reasonable default if it is not provided.
2424
    $modules[$key]->info += array('name' => $key);
2425

    
2426
    // Prefix stylesheets and scripts with module path.
2427
    $path = dirname($module->uri);
2428
    if (isset($module->info['stylesheets'])) {
2429
      $module->info['stylesheets'] = _system_info_add_path($module->info['stylesheets'], $path);
2430
    }
2431
    if (isset($module->info['scripts'])) {
2432
      $module->info['scripts'] = _system_info_add_path($module->info['scripts'], $path);
2433
    }
2434

    
2435
    // Installation profiles are hidden by default, unless explicitly specified
2436
    // otherwise in the .info file.
2437
    if ($key == $profile && !isset($modules[$key]->info['hidden'])) {
2438
      $modules[$key]->info['hidden'] = TRUE;
2439
    }
2440

    
2441
    // Invoke hook_system_info_alter() to give installed modules a chance to
2442
    // modify the data in the .info files if necessary.
2443
    $type = 'module';
2444
    drupal_alter('system_info', $modules[$key]->info, $modules[$key], $type);
2445
  }
2446

    
2447
  if (isset($modules[$profile])) {
2448
    // The installation profile is required, if it's a valid module.
2449
    $modules[$profile]->info['required'] = TRUE;
2450
    // Add a default distribution name if the profile did not provide one. This
2451
    // matches the default value used in install_profile_info().
2452
    if (!isset($modules[$profile]->info['distribution_name'])) {
2453
      $modules[$profile]->info['distribution_name'] = 'Drupal';
2454
    }
2455
  }
2456

    
2457
  return $modules;
2458
}
2459

    
2460
/**
2461
 * Rebuild, save, and return data about all currently available modules.
2462
 *
2463
 * @return
2464
 *   Array of all available modules and their data.
2465
 */
2466
function system_rebuild_module_data() {
2467
  $modules_cache = &drupal_static(__FUNCTION__);
2468
  // Only rebuild once per request. $modules and $modules_cache cannot be
2469
  // combined into one variable, because the $modules_cache variable is reset by
2470
  // reference from system_list_reset() during the rebuild.
2471
  if (!isset($modules_cache)) {
2472
    $modules = _system_rebuild_module_data();
2473
    ksort($modules);
2474
    system_get_files_database($modules, 'module');
2475
    system_update_files_database($modules, 'module');
2476
    $modules = _module_build_dependencies($modules);
2477
    $modules_cache = $modules;
2478
  }
2479
  return $modules_cache;
2480
}
2481

    
2482
/**
2483
 * Refresh bootstrap column in the system table.
2484
 *
2485
 * This is called internally by module_enable/disable() to flag modules that
2486
 * implement hooks used during bootstrap, such as hook_boot(). These modules
2487
 * are loaded earlier to invoke the hooks.
2488
 */
2489
function _system_update_bootstrap_status() {
2490
  $bootstrap_modules = array();
2491
  foreach (bootstrap_hooks() as $hook) {
2492
    foreach (module_implements($hook) as $module) {
2493
      $bootstrap_modules[] = $module;
2494
    }
2495
  }
2496
  $query = db_update('system')->fields(array('bootstrap' => 0));
2497
  if ($bootstrap_modules) {
2498
    db_update('system')
2499
      ->fields(array('bootstrap' => 1))
2500
      ->condition('name', $bootstrap_modules, 'IN')
2501
      ->execute();
2502
    $query->condition('name', $bootstrap_modules, 'NOT IN');
2503
  }
2504
  $query->execute();
2505
  // Reset the cached list of bootstrap modules.
2506
  system_list_reset();
2507
}
2508

    
2509
/**
2510
 * Helper function to scan and collect theme .info data and their engines.
2511
 *
2512
 * @return
2513
 *   An associative array of themes information.
2514
 */
2515
function _system_rebuild_theme_data() {
2516
  // Find themes
2517
  $themes = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.info$/', 'themes');
2518
  // Allow modules to add further themes.
2519
  if ($module_themes = module_invoke_all('system_theme_info')) {
2520
    foreach ($module_themes as $name => $uri) {
2521
      // @see file_scan_directory()
2522
      $themes[$name] = (object) array(
2523
        'uri' => $uri,
2524
        'filename' => pathinfo($uri, PATHINFO_FILENAME),
2525
        'name' => $name,
2526
      );
2527
    }
2528
  }
2529

    
2530
  // Find theme engines
2531
  $engines = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.engine$/', 'themes/engines');
2532
  // Allow modules to add further theme engines.
2533
  if ($module_engines = module_invoke_all('system_theme_engine_info')) {
2534
    foreach ($module_engines as $name => $theme_engine_path) {
2535
      $engines[$name] = (object) array(
2536
        'uri' => $theme_engine_path,
2537
        'filename' => basename($theme_engine_path),
2538
        'name' => $name,
2539
      );
2540
    }
2541
  }
2542

    
2543
  // Set defaults for theme info.
2544
  $defaults = array(
2545
    'engine' => 'phptemplate',
2546
    'regions' => array(
2547
      'sidebar_first' => 'Left sidebar',
2548
      'sidebar_second' => 'Right sidebar',
2549
      'content' => 'Content',
2550
      'header' => 'Header',
2551
      'footer' => 'Footer',
2552
      'highlighted' => 'Highlighted',
2553
      'help' => 'Help',
2554
      'page_top' => 'Page top',
2555
      'page_bottom' => 'Page bottom',
2556
    ),
2557
    'description' => '',
2558
    'features' => _system_default_theme_features(),
2559
    'screenshot' => 'screenshot.png',
2560
    'php' => DRUPAL_MINIMUM_PHP,
2561
    'stylesheets' => array(),
2562
    'scripts' => array(),
2563
  );
2564

    
2565
  $sub_themes = array();
2566
  // Read info files for each theme
2567
  foreach ($themes as $key => $theme) {
2568
    $themes[$key]->filename = $theme->uri;
2569
    $themes[$key]->info = drupal_parse_info_file($theme->uri) + $defaults;
2570

    
2571
    // The "name" key is required, but to avoid a fatal error in the menu system
2572
    // we set a reasonable default if it is not provided.
2573
    $themes[$key]->info += array('name' => $key);
2574

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

    
2579
    // Invoke hook_system_info_alter() to give installed modules a chance to
2580
    // modify the data in the .info files if necessary.
2581
    $type = 'theme';
2582
    drupal_alter('system_info', $themes[$key]->info, $themes[$key], $type);
2583

    
2584
    if (!empty($themes[$key]->info['base theme'])) {
2585
      $sub_themes[] = $key;
2586
    }
2587
    if ($themes[$key]->info['engine'] == 'theme') {
2588
      $filename = dirname($themes[$key]->uri) . '/' . $themes[$key]->name . '.theme';
2589
      if (file_exists($filename)) {
2590
        $themes[$key]->owner = $filename;
2591
        $themes[$key]->prefix = $key;
2592
      }
2593
    }
2594
    else {
2595
      $engine = $themes[$key]->info['engine'];
2596
      if (isset($engines[$engine])) {
2597
        $themes[$key]->owner = $engines[$engine]->uri;
2598
        $themes[$key]->prefix = $engines[$engine]->name;
2599
        $themes[$key]->template = TRUE;
2600
      }
2601
    }
2602

    
2603
    // Prefix stylesheets and scripts with module path.
2604
    $path = dirname($theme->uri);
2605
    $theme->info['stylesheets'] = _system_info_add_path($theme->info['stylesheets'], $path);
2606
    $theme->info['scripts'] = _system_info_add_path($theme->info['scripts'], $path);
2607

    
2608
    // Give the screenshot proper path information.
2609
    if (!empty($themes[$key]->info['screenshot'])) {
2610
      $themes[$key]->info['screenshot'] = $path . '/' . $themes[$key]->info['screenshot'];
2611
    }
2612
  }
2613

    
2614
  // Now that we've established all our master themes, go back and fill in data
2615
  // for subthemes.
2616
  foreach ($sub_themes as $key) {
2617
    $themes[$key]->base_themes = drupal_find_base_themes($themes, $key);
2618
    // Don't proceed if there was a problem with the root base theme.
2619
    if (!current($themes[$key]->base_themes)) {
2620
      continue;
2621
    }
2622
    $base_key = key($themes[$key]->base_themes);
2623
    foreach (array_keys($themes[$key]->base_themes) as $base_theme) {
2624
      $themes[$base_theme]->sub_themes[$key] = $themes[$key]->info['name'];
2625
    }
2626
    // Copy the 'owner' and 'engine' over if the top level theme uses a theme
2627
    // engine.
2628
    if (isset($themes[$base_key]->owner)) {
2629
      if (isset($themes[$base_key]->info['engine'])) {
2630
        $themes[$key]->info['engine'] = $themes[$base_key]->info['engine'];
2631
        $themes[$key]->owner = $themes[$base_key]->owner;
2632
        $themes[$key]->prefix = $themes[$base_key]->prefix;
2633
      }
2634
      else {
2635
        $themes[$key]->prefix = $key;
2636
      }
2637
    }
2638
  }
2639

    
2640
  return $themes;
2641
}
2642

    
2643
/**
2644
 * Rebuild, save, and return data about all currently available themes.
2645
 *
2646
 * @return
2647
 *   Array of all available themes and their data.
2648
 */
2649
function system_rebuild_theme_data() {
2650
  $themes = _system_rebuild_theme_data();
2651
  ksort($themes);
2652
  system_get_files_database($themes, 'theme');
2653
  system_update_files_database($themes, 'theme');
2654
  return $themes;
2655
}
2656

    
2657
/**
2658
 * Prefixes all values in an .info file array with a given path.
2659
 *
2660
 * This helper function is mainly used to prefix all array values of an .info
2661
 * file property with a single given path (to the module or theme); e.g., to
2662
 * prefix all values of the 'stylesheets' or 'scripts' properties with the file
2663
 * path to the defining module/theme.
2664
 *
2665
 * @param $info
2666
 *   A nested array of data of an .info file to be processed.
2667
 * @param $path
2668
 *   A file path to prepend to each value in $info.
2669
 *
2670
 * @return
2671
 *   The $info array with prefixed values.
2672
 *
2673
 * @see _system_rebuild_module_data()
2674
 * @see _system_rebuild_theme_data()
2675
 */
2676
function _system_info_add_path($info, $path) {
2677
  foreach ($info as $key => $value) {
2678
    // Recurse into nested values until we reach the deepest level.
2679
    if (is_array($value)) {
2680
      $info[$key] = _system_info_add_path($info[$key], $path);
2681
    }
2682
    // Unset the original value's key and set the new value with prefix, using
2683
    // the original value as key, so original values can still be looked up.
2684
    else {
2685
      unset($info[$key]);
2686
      $info[$value] = $path . '/' . $value;
2687
    }
2688
  }
2689
  return $info;
2690
}
2691

    
2692
/**
2693
 * Returns an array of default theme features.
2694
 */
2695
function _system_default_theme_features() {
2696
  return array(
2697
    'logo',
2698
    'favicon',
2699
    'name',
2700
    'slogan',
2701
    'node_user_picture',
2702
    'comment_user_picture',
2703
    'comment_user_verification',
2704
    'main_menu',
2705
    'secondary_menu',
2706
  );
2707
}
2708

    
2709
/**
2710
 * Find all the base themes for the specified theme.
2711
 *
2712
 * This function has been deprecated in favor of drupal_find_base_themes().
2713
 */
2714
function system_find_base_themes($themes, $key, $used_keys = array()) {
2715
  return drupal_find_base_themes($themes, $key, $used_keys);
2716
}
2717

    
2718
/**
2719
 * Get a list of available regions from a specified theme.
2720
 *
2721
 * @param $theme_key
2722
 *   The name of a theme.
2723
 * @param $show
2724
 *   Possible values: REGIONS_ALL or REGIONS_VISIBLE. Visible excludes hidden
2725
 *   regions.
2726
 * @param bool $labels
2727
 *   (optional) Boolean to specify whether the human readable machine names
2728
 *   should be returned or not. Defaults to TRUE, but calling code can set
2729
 *   this to FALSE for better performance, if it only needs machine names.
2730
 *
2731
 * @return array
2732
 *   An associative array of regions in the form $region['name'] = 'description'
2733
 *   if $labels is set to TRUE, or $region['name'] = 'name', if $labels is set
2734
 *   to FALSE.
2735
 */
2736
function system_region_list($theme_key, $show = REGIONS_ALL, $labels = TRUE) {
2737
  $themes = list_themes();
2738
  if (!isset($themes[$theme_key])) {
2739
    return array();
2740
  }
2741

    
2742
  $list = array();
2743
  $info = $themes[$theme_key]->info;
2744
  // If requested, suppress hidden regions. See block_admin_display_form().
2745
  foreach ($info['regions'] as $name => $label) {
2746
    if ($show == REGIONS_ALL || !isset($info['regions_hidden']) || !in_array($name, $info['regions_hidden'])) {
2747
      if ($labels) {
2748
        $list[$name] = t($label);
2749
      }
2750
      else {
2751
        $list[$name] = $name;
2752
      }
2753
    }
2754
  }
2755
  return $list;
2756
}
2757

    
2758
/**
2759
 * Implements hook_system_info_alter().
2760
 */
2761
function system_system_info_alter(&$info, $file, $type) {
2762
  // Remove page-top and page-bottom from the blocks UI since they are reserved for
2763
  // modules to populate from outside the blocks system.
2764
  if ($type == 'theme') {
2765
    $info['regions_hidden'][] = 'page_top';
2766
    $info['regions_hidden'][] = 'page_bottom';
2767
  }
2768
}
2769

    
2770
/**
2771
 * Get the name of the default region for a given theme.
2772
 *
2773
 * @param $theme
2774
 *   The name of a theme.
2775
 *
2776
 * @return
2777
 *   A string that is the region name.
2778
 */
2779
function system_default_region($theme) {
2780
  $regions = system_region_list($theme, REGIONS_VISIBLE, FALSE);
2781
  return $regions ? reset($regions) : '';
2782
}
2783

    
2784
/**
2785
 * Sets up a form to save information automatically.
2786
 *
2787
 * This function adds a submit handler and a submit button to a form array. The
2788
 * submit function saves all the data in the form, using variable_set(), to
2789
 * variables named the same as the keys in the form array. Note that this means
2790
 * you should normally prefix your form array keys with your module name, so
2791
 * that they are unique when passed into variable_set().
2792
 *
2793
 * If you need to manipulate the data in a custom manner, you can either put
2794
 * your own submission handler in the form array before calling this function,
2795
 * or just use your own submission handler instead of calling this function.
2796
 *
2797
 * @param $form
2798
 *   An associative array containing the structure of the form.
2799
 *
2800
 * @return
2801
 *   The form structure.
2802
 *
2803
 * @see system_settings_form_submit()
2804
 *
2805
 * @ingroup forms
2806
 */
2807
function system_settings_form($form) {
2808
  $form['actions']['#type'] = 'actions';
2809
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
2810

    
2811
  if (!empty($_POST) && form_get_errors()) {
2812
    drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
2813
  }
2814
  $form['#submit'][] = 'system_settings_form_submit';
2815
  // By default, render the form using theme_system_settings_form().
2816
  if (!isset($form['#theme'])) {
2817
    $form['#theme'] = 'system_settings_form';
2818
  }
2819
  return $form;
2820
}
2821

    
2822
/**
2823
 * Form submission handler for system_settings_form().
2824
 *
2825
 * If you want node type configure style handling of your checkboxes,
2826
 * add an array_filter value to your form.
2827
 */
2828
function system_settings_form_submit($form, &$form_state) {
2829
  // Exclude unnecessary elements.
2830
  form_state_values_clean($form_state);
2831

    
2832
  foreach ($form_state['values'] as $key => $value) {
2833
    if (is_array($value) && isset($form_state['values']['array_filter'])) {
2834
      $value = array_keys(array_filter($value));
2835
    }
2836
    variable_set($key, $value);
2837
  }
2838

    
2839
  drupal_set_message(t('The configuration options have been saved.'));
2840
}
2841

    
2842
/**
2843
 * Helper function to sort requirements.
2844
 */
2845
function _system_sort_requirements($a, $b) {
2846
  if (!isset($a['weight'])) {
2847
    if (!isset($b['weight'])) {
2848
      return strcasecmp($a['title'], $b['title']);
2849
    }
2850
    return -$b['weight'];
2851
  }
2852
  return isset($b['weight']) ? $a['weight'] - $b['weight'] : $a['weight'];
2853
}
2854

    
2855
/**
2856
 * Generates a form array for a confirmation form.
2857
 *
2858
 * This function returns a complete form array for confirming an action. The
2859
 * form contains a confirm button as well as a cancellation link that allows a
2860
 * user to abort the action.
2861
 *
2862
 * If the submit handler for a form that implements confirm_form() is invoked,
2863
 * the user successfully confirmed the action. You should never directly
2864
 * inspect $_POST to see if an action was confirmed.
2865
 *
2866
 * Note - if the parameters $question, $description, $yes, or $no could contain
2867
 * any user input (such as node titles or taxonomy terms), it is the
2868
 * responsibility of the code calling confirm_form() to sanitize them first with
2869
 * a function like check_plain() or filter_xss().
2870
 *
2871
 * @param $form
2872
 *   Additional elements to add to the form. These can be regular form elements,
2873
 *   #value elements, etc., and their values will be available to the submit
2874
 *   handler.
2875
 * @param $question
2876
 *   The question to ask the user (e.g. "Are you sure you want to delete the
2877
 *   block <em>foo</em>?"). The page title will be set to this value.
2878
 * @param $path
2879
 *   The page to go to if the user cancels the action. This can be either:
2880
 *   - A string containing a Drupal path.
2881
 *   - An associative array with a 'path' key. Additional array values are
2882
 *     passed as the $options parameter to l().
2883
 *   If the 'destination' query parameter is set in the URL when viewing a
2884
 *   confirmation form, that value will be used instead of $path.
2885
 * @param $description
2886
 *   Additional text to display. Defaults to t('This action cannot be undone.').
2887
 * @param $yes
2888
 *   A caption for the button that confirms the action (e.g. "Delete",
2889
 *   "Replace", ...). Defaults to t('Confirm').
2890
 * @param $no
2891
 *   A caption for the link which cancels the action (e.g. "Cancel"). Defaults
2892
 *   to t('Cancel').
2893
 * @param $name
2894
 *   The internal name used to refer to the confirmation item.
2895
 *
2896
 * @return
2897
 *   The form array.
2898
 */
2899
function confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm') {
2900
  $description = isset($description) ? $description : t('This action cannot be undone.');
2901

    
2902
  // Prepare cancel link.
2903
  if (isset($_GET['destination'])) {
2904
    $options = drupal_parse_url($_GET['destination']);
2905
  }
2906
  elseif (is_array($path)) {
2907
    $options = $path;
2908
  }
2909
  else {
2910
    $options = array('path' => $path);
2911
  }
2912

    
2913
  drupal_set_title($question, PASS_THROUGH);
2914

    
2915
  $form['#attributes']['class'][] = 'confirmation';
2916
  $form['description'] = array('#markup' => $description);
2917
  $form[$name] = array('#type' => 'hidden', '#value' => 1);
2918

    
2919
  $form['actions'] = array('#type' => 'actions');
2920
  $form['actions']['submit'] = array(
2921
    '#type' => 'submit',
2922
    '#value' => $yes ? $yes : t('Confirm'),
2923
  );
2924
  $form['actions']['cancel'] = array(
2925
    '#type' => 'link',
2926
    '#title' => $no ? $no : t('Cancel'),
2927
    '#href' => $options['path'],
2928
    '#options' => $options,
2929
  );
2930
  // By default, render the form using theme_confirm_form().
2931
  if (!isset($form['#theme'])) {
2932
    $form['#theme'] = 'confirm_form';
2933
  }
2934
  return $form;
2935
}
2936

    
2937
/**
2938
 * Determines whether the current user is in compact mode.
2939
 *
2940
 * Compact mode shows certain administration pages with less description text,
2941
 * such as the configuration page and the permissions page.
2942
 *
2943
 * Whether the user is in compact mode is determined by a cookie, which is set
2944
 * for the user by system_admin_compact_page().
2945
 *
2946
 * If the user does not have the cookie, the default value is given by the
2947
 * system variable 'admin_compact_mode', which itself defaults to FALSE. This
2948
 * does not have a user interface to set it: it is a hidden variable which can
2949
 * be set in the settings.php file.
2950
 *
2951
 * @return
2952
 *   TRUE when in compact mode, FALSE when in expanded mode.
2953
 */
2954
function system_admin_compact_mode() {
2955
  // PHP converts dots into underscores in cookie names to avoid problems with
2956
  // its parser, so we use a converted cookie name.
2957
  return isset($_COOKIE['Drupal_visitor_admin_compact_mode']) ? $_COOKIE['Drupal_visitor_admin_compact_mode'] : variable_get('admin_compact_mode', FALSE);
2958
}
2959

    
2960
/**
2961
 * Menu callback; Sets whether the admin menu is in compact mode or not.
2962
 *
2963
 * @param $mode
2964
 *   Valid values are 'on' and 'off'.
2965
 */
2966
function system_admin_compact_page($mode = 'off') {
2967
  user_cookie_save(array('admin_compact_mode' => ($mode == 'on')));
2968
  drupal_goto();
2969
}
2970

    
2971
/**
2972
 * Generate a list of tasks offered by a specified module.
2973
 *
2974
 * @param $module
2975
 *   Module name.
2976
 * @param $info
2977
 *   The module's information, as provided by system_get_info().
2978
 *
2979
 * @return
2980
 *   An array of task links.
2981
 */
2982
function system_get_module_admin_tasks($module, $info) {
2983
  $links = &drupal_static(__FUNCTION__);
2984

    
2985
  if (!isset($links)) {
2986
    $links = array();
2987
    $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));
2988
    $query->join('menu_router', 'm', 'm.path = ml.router_path');
2989
    $query
2990
      ->fields('ml')
2991
      // Weight should be taken from {menu_links}, not {menu_router}.
2992
      ->fields('m', array_diff(drupal_schema_fields_sql('menu_router'), array('weight')))
2993
      ->condition('ml.link_path', 'admin/%', 'LIKE')
2994
      ->condition('ml.hidden', 0, '>=')
2995
      ->condition('ml.module', 'system')
2996
      ->condition('m.number_parts', 1, '>')
2997
      ->condition('m.page_callback', 'system_admin_menu_block_page', '<>');
2998
    foreach ($query->execute() as $link) {
2999
      _menu_link_translate($link);
3000
      if ($link['access']) {
3001
        $links[$link['router_path']] = $link;
3002
      }
3003
    }
3004
  }
3005

    
3006
  $admin_tasks = array();
3007
  $titles = array();
3008
  if ($menu = module_invoke($module, 'menu')) {
3009
    foreach ($menu as $path => $item) {
3010
      if (isset($links[$path])) {
3011
        $task = $links[$path];
3012
        // The link description, either derived from 'description' in
3013
        // hook_menu() or customized via menu module is used as title attribute.
3014
        if (!empty($task['localized_options']['attributes']['title'])) {
3015
          $task['description'] = $task['localized_options']['attributes']['title'];
3016
          unset($task['localized_options']['attributes']['title']);
3017
        }
3018

    
3019
        // Check the admin tasks for duplicate names. If one is found,
3020
        // append the parent menu item's title to differentiate.
3021
        $duplicate_path = array_search($task['title'], $titles);
3022
        if ($duplicate_path !== FALSE) {
3023
          if ($parent = menu_link_load($task['plid'])) {
3024
            // Append the parent item's title to this task's title.
3025
            $task['title'] = t('@original_title (@parent_title)', array('@original_title' => $task['title'], '@parent_title' => $parent['title']));
3026
          }
3027
          if ($parent = menu_link_load($admin_tasks[$duplicate_path]['plid'])) {
3028
            // Append the parent item's title to the duplicated task's title.
3029
            // We use $links[$duplicate_path] in case there are triplicates.
3030
            $admin_tasks[$duplicate_path]['title'] = t('@original_title (@parent_title)', array('@original_title' => $links[$duplicate_path]['title'], '@parent_title' => $parent['title']));
3031
          }
3032
        }
3033
        else {
3034
          $titles[$path] = $task['title'];
3035
        }
3036

    
3037
        $admin_tasks[$path] = $task;
3038
      }
3039
    }
3040
  }
3041

    
3042
  // Append link for permissions.
3043
  if (module_hook($module, 'permission')) {
3044
    $item = menu_get_item('admin/people/permissions');
3045
    if (!empty($item['access'])) {
3046
      $item['link_path'] = $item['href'];
3047
      $item['title'] = t('Configure @module permissions', array('@module' => $info['name']));
3048
      unset($item['description']);
3049
      $item['localized_options']['fragment'] = 'module-' . $module;
3050
      $admin_tasks["admin/people/permissions#module-$module"] = $item;
3051
    }
3052
  }
3053

    
3054
  return $admin_tasks;
3055
}
3056

    
3057
/**
3058
 * Implements hook_cron().
3059
 *
3060
 * Remove older rows from flood and batch table. Remove old temporary files.
3061
 */
3062
function system_cron() {
3063
  // Cleanup the flood.
3064
  db_delete('flood')
3065
    ->condition('expiration', REQUEST_TIME, '<')
3066
    ->execute();
3067

    
3068
  // Remove temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
3069
  // Use separate placeholders for the status to avoid a bug in some versions
3070
  // of PHP. See http://drupal.org/node/352956.
3071
  $result = db_query('SELECT fid FROM {file_managed} WHERE status <> :permanent AND timestamp < :timestamp', array(
3072
    ':permanent' => FILE_STATUS_PERMANENT,
3073
    ':timestamp' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE
3074
  ));
3075
  foreach ($result as $row) {
3076
    if ($file = file_load($row->fid)) {
3077
      $references = file_usage_list($file);
3078
      if (empty($references)) {
3079
        if (!file_delete($file)) {
3080
          watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' => $file->uri), WATCHDOG_ERROR);
3081
        }
3082
      }
3083
      else {
3084
        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);
3085
      }
3086
    }
3087
  }
3088

    
3089
  // Delete expired cache entries.
3090
  // Avoid invoking hook_flush_cashes() on every cron run because some modules
3091
  // use this hook to perform expensive rebuilding operations (which are only
3092
  // designed to happen on full cache clears), rather than just returning a
3093
  // list of cache tables to be cleared.
3094
  $cache_object = cache_get('system_cache_tables');
3095
  if (empty($cache_object)) {
3096
    $core = array('cache', 'cache_path', 'cache_filter', 'cache_page', 'cache_form', 'cache_menu');
3097
    $cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
3098
    cache_set('system_cache_tables', $cache_tables);
3099
  }
3100
  else {
3101
    $cache_tables = $cache_object->data;
3102
  }
3103
  foreach ($cache_tables as $table) {
3104
    cache_clear_all(NULL, $table);
3105
  }
3106

    
3107
  // Cleanup the batch table and the queue for failed batches.
3108
  db_delete('batch')
3109
    ->condition('timestamp', REQUEST_TIME - 864000, '<')
3110
    ->execute();
3111
  db_delete('queue')
3112
    ->condition('created', REQUEST_TIME - 864000, '<')
3113
    ->condition('name', 'drupal_batch:%', 'LIKE')
3114
    ->execute();
3115

    
3116
  // Reset expired items in the default queue implementation table. If that's
3117
  // not used, this will simply be a no-op.
3118
  db_update('queue')
3119
    ->fields(array(
3120
      'expire' => 0,
3121
    ))
3122
    ->condition('expire', 0, '<>')
3123
    ->condition('expire', REQUEST_TIME, '<')
3124
    ->execute();
3125
}
3126

    
3127
/**
3128
 * Implements hook_flush_caches().
3129
 */
3130
function system_flush_caches() {
3131
  // Rebuild list of date formats.
3132
  system_date_formats_rebuild();
3133
  // Reset the menu static caches.
3134
  menu_reset_static_cache();
3135
}
3136

    
3137
/**
3138
 * Implements hook_action_info().
3139
 */
3140
function system_action_info() {
3141
  return array(
3142
    'system_message_action' => array(
3143
      'type' => 'system',
3144
      'label' => t('Display a message to the user'),
3145
      'configurable' => TRUE,
3146
      'triggers' => array('any'),
3147
    ),
3148
    'system_send_email_action' => array(
3149
      'type' => 'system',
3150
      'label' => t('Send e-mail'),
3151
      'configurable' => TRUE,
3152
      'triggers' => array('any'),
3153
    ),
3154
    'system_block_ip_action' => array(
3155
      'type' => 'user',
3156
      'label' => t('Ban IP address of current user'),
3157
      'configurable' => FALSE,
3158
      'triggers' => array('any'),
3159
    ),
3160
    'system_goto_action' => array(
3161
      'type' => 'system',
3162
      'label' => t('Redirect to URL'),
3163
      'configurable' => TRUE,
3164
      'triggers' => array('any'),
3165
    ),
3166
  );
3167
}
3168

    
3169
/**
3170
 * Return a form definition so the Send email action can be configured.
3171
 *
3172
 * @param $context
3173
 *   Default values (if we are editing an existing action instance).
3174
 *
3175
 * @return
3176
 *   Form definition.
3177
 *
3178
 * @see system_send_email_action_validate()
3179
 * @see system_send_email_action_submit()
3180
 */
3181
function system_send_email_action_form($context) {
3182
  // Set default values for form.
3183
  if (!isset($context['recipient'])) {
3184
    $context['recipient'] = '';
3185
  }
3186
  if (!isset($context['subject'])) {
3187
    $context['subject'] = '';
3188
  }
3189
  if (!isset($context['message'])) {
3190
    $context['message'] = '';
3191
  }
3192

    
3193
  $form['recipient'] = array(
3194
    '#type' => 'textfield',
3195
    '#title' => t('Recipient'),
3196
    '#default_value' => $context['recipient'],
3197
    '#maxlength' => '254',
3198
    '#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.'),
3199
  );
3200
  $form['subject'] = array(
3201
    '#type' => 'textfield',
3202
    '#title' => t('Subject'),
3203
    '#default_value' => $context['subject'],
3204
    '#maxlength' => '254',
3205
    '#description' => t('The subject of the message.'),
3206
  );
3207
  $form['message'] = array(
3208
    '#type' => 'textarea',
3209
    '#title' => t('Message'),
3210
    '#default_value' => $context['message'],
3211
    '#cols' => '80',
3212
    '#rows' => '20',
3213
    '#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.'),
3214
  );
3215
  return $form;
3216
}
3217

    
3218
/**
3219
 * Validate system_send_email_action form submissions.
3220
 */
3221
function system_send_email_action_validate($form, $form_state) {
3222
  $form_values = $form_state['values'];
3223
  // Validate the configuration form.
3224
  if (!valid_email_address($form_values['recipient']) && strpos($form_values['recipient'], ':mail') === FALSE) {
3225
    // We want the literal %author placeholder to be emphasized in the error message.
3226
    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]')));
3227
  }
3228
}
3229

    
3230
/**
3231
 * Process system_send_email_action form submissions.
3232
 */
3233
function system_send_email_action_submit($form, $form_state) {
3234
  $form_values = $form_state['values'];
3235
  // Process the HTML form to store configuration. The keyed array that
3236
  // we return will be serialized to the database.
3237
  $params = array(
3238
    'recipient' => $form_values['recipient'],
3239
    'subject'   => $form_values['subject'],
3240
    'message'   => $form_values['message'],
3241
  );
3242
  return $params;
3243
}
3244

    
3245
/**
3246
 * Sends an e-mail message.
3247
 *
3248
 * @param object $entity
3249
 *   An optional node object, which will be added as $context['node'] if
3250
 *   provided.
3251
 * @param array $context
3252
 *   Array with the following elements:
3253
 *   - 'recipient': E-mail message recipient. This will be passed through
3254
 *     token_replace().
3255
 *   - 'subject': The subject of the message. This will be passed through
3256
 *     token_replace().
3257
 *   - 'message': The message to send. This will be passed through
3258
 *     token_replace().
3259
 *   - Other elements will be used as the data for token replacement.
3260
 *
3261
 * @ingroup actions
3262
 */
3263
function system_send_email_action($entity, $context) {
3264
  if (empty($context['node'])) {
3265
    $context['node'] = $entity;
3266
  }
3267

    
3268
  $recipient = token_replace($context['recipient'], $context);
3269

    
3270
  // If the recipient is a registered user with a language preference, use
3271
  // the recipient's preferred language. Otherwise, use the system default
3272
  // language.
3273
  $recipient_account = user_load_by_mail($recipient);
3274
  if ($recipient_account) {
3275
    $language = user_preferred_language($recipient_account);
3276
  }
3277
  else {
3278
    $language = language_default();
3279
  }
3280
  $params = array('context' => $context);
3281

    
3282
  if (drupal_mail('system', 'action_send_email', $recipient, $language, $params)) {
3283
    watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient));
3284
  }
3285
  else {
3286
    watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient));
3287
  }
3288
}
3289

    
3290
/**
3291
 * Implements hook_mail().
3292
 */
3293
function system_mail($key, &$message, $params) {
3294
  $context = $params['context'];
3295

    
3296
  $subject = token_replace($context['subject'], $context);
3297
  $body = token_replace($context['message'], $context);
3298

    
3299
  $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
3300
  $message['body'][] = $body;
3301
}
3302

    
3303
function system_message_action_form($context) {
3304
  $form['message'] = array(
3305
    '#type' => 'textarea',
3306
    '#title' => t('Message'),
3307
    '#default_value' => isset($context['message']) ? $context['message'] : '',
3308
    '#required' => TRUE,
3309
    '#rows' => '8',
3310
    '#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.'),
3311
  );
3312
  return $form;
3313
}
3314

    
3315
function system_message_action_submit($form, $form_state) {
3316
  return array('message' => $form_state['values']['message']);
3317
}
3318

    
3319
/**
3320
 * Sends a message to the current user's screen.
3321
 *
3322
 * @param object $entity
3323
 *   An optional node object, which will be added as $context['node'] if
3324
 *   provided.
3325
 * @param array $context
3326
 *   Array with the following elements:
3327
 *   - 'message': The message to send. This will be passed through
3328
 *     token_replace().
3329
 *   - Other elements will be used as the data for token replacement in
3330
 *     the message.
3331
 *
3332
 * @ingroup actions
3333
 */
3334
function system_message_action(&$entity, $context = array()) {
3335
  if (empty($context['node'])) {
3336
    $context['node'] = $entity;
3337
  }
3338

    
3339
  $context['message'] = token_replace(filter_xss_admin($context['message']), $context);
3340
  drupal_set_message($context['message']);
3341
}
3342

    
3343
/**
3344
 * Settings form for system_goto_action().
3345
 */
3346
function system_goto_action_form($context) {
3347
  $form['url'] = array(
3348
    '#type' => 'textfield',
3349
    '#title' => t('URL'),
3350
    '#description' => t('The URL to which the user should be redirected. This can be an internal path like node/1234 or an external URL like http://example.com.'),
3351
    '#default_value' => isset($context['url']) ? $context['url'] : '',
3352
    '#required' => TRUE,
3353
  );
3354
  return $form;
3355
}
3356

    
3357
function system_goto_action_submit($form, $form_state) {
3358
  return array(
3359
    'url' => $form_state['values']['url']
3360
  );
3361
}
3362

    
3363
/**
3364
 * Redirects to a different URL.
3365
 *
3366
 * @param $entity
3367
 *   Ignored.
3368
 * @param array $context
3369
 *   Array with the following elements:
3370
 *   - 'url': URL to redirect to. This will be passed through
3371
 *     token_replace().
3372
 *   - Other elements will be used as the data for token replacement.
3373
 *
3374
 * @ingroup actions
3375
 */
3376
function system_goto_action($entity, $context) {
3377
  drupal_goto(token_replace($context['url'], $context));
3378
}
3379

    
3380
/**
3381
 * Blocks the current user's IP address.
3382
 *
3383
 * @ingroup actions
3384
 */
3385
function system_block_ip_action() {
3386
  $ip = ip_address();
3387
  db_merge('blocked_ips')
3388
    ->key(array('ip' => $ip))
3389
    ->fields(array('ip' => $ip))
3390
    ->execute();
3391
  watchdog('action', 'Banned IP address %ip', array('%ip' => $ip));
3392
}
3393

    
3394
/**
3395
 * Generate an array of time zones and their local time&date.
3396
 *
3397
 * @param $blank
3398
 *   If evaluates true, prepend an empty time zone option to the array.
3399
 */
3400
function system_time_zones($blank = NULL) {
3401
  $zonelist = timezone_identifiers_list();
3402
  $zones = $blank ? array('' => t('- None selected -')) : array();
3403
  foreach ($zonelist as $zone) {
3404
    // Because many time zones exist in PHP only for backward compatibility
3405
    // reasons and should not be used, the list is filtered by a regular
3406
    // expression.
3407
    if (preg_match('!^((Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)/|UTC$)!', $zone)) {
3408
      $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)));
3409
    }
3410
  }
3411
  // Sort the translated time zones alphabetically.
3412
  asort($zones);
3413
  return $zones;
3414
}
3415

    
3416
/**
3417
 * Checks whether the server is capable of issuing HTTP requests.
3418
 *
3419
 * The function sets the drupal_http_request_fail system variable to TRUE if
3420
 * drupal_http_request() does not work and then the system status report page
3421
 * will contain an error.
3422
 *
3423
 * @return
3424
 *  TRUE if this installation can issue HTTP requests.
3425
 */
3426
function system_check_http_request() {
3427
  // Try to get the content of the front page via drupal_http_request().
3428
  $result = drupal_http_request(url('', array('absolute' => TRUE)), array('max_redirects' => 0));
3429
  // We only care that we get a http response - this means that Drupal
3430
  // can make a http request.
3431
  $works = isset($result->code) && ($result->code >= 100) && ($result->code < 600);
3432
  variable_set('drupal_http_request_fails', !$works);
3433
  return $works;
3434
}
3435

    
3436
/**
3437
 * Menu callback; Retrieve a JSON object containing a suggested time zone name.
3438
 */
3439
function system_timezone($abbreviation = '', $offset = -1, $is_daylight_saving_time = NULL) {
3440
  // An abbreviation of "0" passed in the callback arguments should be
3441
  // interpreted as the empty string.
3442
  $abbreviation = $abbreviation ? $abbreviation : '';
3443
  $timezone = timezone_name_from_abbr($abbreviation, intval($offset), $is_daylight_saving_time);
3444
  drupal_json_output($timezone);
3445
}
3446

    
3447
/**
3448
 * Returns HTML for the Powered by Drupal text.
3449
 *
3450
 * @ingroup themeable
3451
 */
3452
function theme_system_powered_by() {
3453
  return '<span>' . t('Powered by <a href="@poweredby">Drupal</a>', array('@poweredby' => 'https://www.drupal.org')) . '</span>';
3454
}
3455

    
3456
/**
3457
 * Returns HTML for a link to show or hide inline help descriptions.
3458
 *
3459
 * @ingroup themeable
3460
 */
3461
function theme_system_compact_link() {
3462
  $output = '<div class="compact-link">';
3463
  if (system_admin_compact_mode()) {
3464
    $output .= l(t('Show descriptions'), 'admin/compact/off', array('attributes' => array('title' => t('Expand layout to include descriptions.')), 'query' => drupal_get_destination()));
3465
  }
3466
  else {
3467
    $output .= l(t('Hide descriptions'), 'admin/compact/on', array('attributes' => array('title' => t('Compress layout by hiding descriptions.')), 'query' => drupal_get_destination()));
3468
  }
3469
  $output .= '</div>';
3470

    
3471
  return $output;
3472
}
3473

    
3474
/**
3475
 * Implements hook_image_toolkits().
3476
 */
3477
function system_image_toolkits() {
3478
  include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'system') . '/' . 'image.gd.inc';
3479
  return array(
3480
    'gd' => array(
3481
      'title' => t('GD2 image manipulation toolkit'),
3482
      'available' => function_exists('image_gd_check_settings') && image_gd_check_settings(),
3483
    ),
3484
  );
3485
}
3486

    
3487
/**
3488
 * Attempts to get a file using drupal_http_request and to store it locally.
3489
 *
3490
 * @param string $url
3491
 *   The URL of the file to grab.
3492
 * @param string $destination
3493
 *   Stream wrapper URI specifying where the file should be placed. If a
3494
 *   directory path is provided, the file is saved into that directory under
3495
 *   its original name. If the path contains a filename as well, that one will
3496
 *   be used instead.
3497
 *   If this value is omitted, the site's default files scheme will be used,
3498
 *   usually "public://".
3499
 * @param bool $managed
3500
 *   If this is set to TRUE, the file API hooks will be invoked and the file is
3501
 *   registered in the database.
3502
 * @param int $replace
3503
 *   Replace behavior when the destination file already exists:
3504
 *   - FILE_EXISTS_REPLACE: Replace the existing file.
3505
 *   - FILE_EXISTS_RENAME: Append _{incrementing number} until the filename is
3506
 *     unique.
3507
 *   - FILE_EXISTS_ERROR: Do nothing and return FALSE.
3508
 *
3509
 * @return mixed
3510
 *   One of these possibilities:
3511
 *   - If it succeeds and $managed is FALSE, the location where the file was
3512
 *     saved.
3513
 *   - If it succeeds and $managed is TRUE, a \Drupal\file\FileInterface
3514
 *     object which describes the file.
3515
 *   - If it fails, FALSE.
3516
 */
3517
function system_retrieve_file($url, $destination = NULL, $managed = FALSE, $replace = FILE_EXISTS_RENAME) {
3518
  $parsed_url = parse_url($url);
3519
  if (!isset($destination)) {
3520
    $path = file_build_uri(drupal_basename($parsed_url['path']));
3521
  }
3522
  else {
3523
    if (is_dir(drupal_realpath($destination))) {
3524
      // Prevent URIs with triple slashes when glueing parts together.
3525
      $path = str_replace('///', '//', "$destination/") . drupal_basename($parsed_url['path']);
3526
    }
3527
    else {
3528
      $path = $destination;
3529
    }
3530
  }
3531
  $result = drupal_http_request($url);
3532
  if ($result->code != 200) {
3533
    drupal_set_message(t('HTTP error @errorcode occurred when trying to fetch @remote.', array('@errorcode' => $result->code, '@remote' => $url)), 'error');
3534
    return FALSE;
3535
  }
3536
  $local = $managed ? file_save_data($result->data, $path, $replace) : file_unmanaged_save_data($result->data, $path, $replace);
3537
  if (!$local) {
3538
    drupal_set_message(t('@remote could not be saved to @path.', array('@remote' => $url, '@path' => $path)), 'error');
3539
  }
3540

    
3541
  return $local;
3542
}
3543

    
3544
/**
3545
 * Implements hook_page_alter().
3546
 */
3547
function system_page_alter(&$page) {
3548
  // Find all non-empty page regions, and add a theme wrapper function that
3549
  // allows them to be consistently themed.
3550
  foreach (system_region_list($GLOBALS['theme'], REGIONS_ALL, FALSE) as $region) {
3551
    if (!empty($page[$region])) {
3552
      $page[$region]['#theme_wrappers'][] = 'region';
3553
      $page[$region]['#region'] = $region;
3554
    }
3555
  }
3556
}
3557

    
3558
/**
3559
 * Run the automated cron if enabled.
3560
 */
3561
function system_run_automated_cron() {
3562
  // If the site is not fully installed, suppress the automated cron run.
3563
  // Otherwise it could be triggered prematurely by Ajax requests during
3564
  // installation.
3565
  if (($threshold = variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD)) > 0 && variable_get('install_task') == 'done') {
3566
    $cron_last = variable_get('cron_last', NULL);
3567
    if (!isset($cron_last) || (REQUEST_TIME - $cron_last > $threshold)) {
3568
      drupal_cron_run();
3569
    }
3570
  }
3571
}
3572

    
3573
/**
3574
 * Gets the list of available date types and attributes.
3575
 *
3576
 * @param $type
3577
 *   (optional) The date type name.
3578
 *
3579
 * @return
3580
 *   An associative array of date type information keyed by the date type name.
3581
 *   Each date type information array has the following elements:
3582
 *   - type: The machine-readable name of the date type.
3583
 *   - title: The human-readable name of the date type.
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 type in its
3587
 *     hook_date_format_types(). An empty string if the date type was
3588
 *     user-defined.
3589
 *   - is_new: A boolean indicating whether or not this date type is as of yet
3590
 *     unsaved in the database.
3591
 *   If $type was defined, only a single associative array with the above
3592
 *   elements is returned.
3593
 */
3594
function system_get_date_types($type = NULL) {
3595
  $types = &drupal_static(__FUNCTION__);
3596

    
3597
  if (!isset($types)) {
3598
    $types = _system_date_format_types_build();
3599
  }
3600

    
3601
  return $type ? (isset($types[$type]) ? $types[$type] : FALSE) : $types;
3602
}
3603

    
3604
/**
3605
 * Implements hook_date_format_types().
3606
 */
3607
function system_date_format_types() {
3608
  return array(
3609
    'long' => t('Long'),
3610
    'medium' => t('Medium'),
3611
    'short' => t('Short'),
3612
  );
3613
}
3614

    
3615
/**
3616
 * Implements hook_date_formats().
3617
 */
3618
function system_date_formats() {
3619
  include_once DRUPAL_ROOT . '/includes/date.inc';
3620
  return system_default_date_formats();
3621
}
3622

    
3623
/**
3624
 * Gets the list of defined date formats and attributes.
3625
 *
3626
 * @param $type
3627
 *   (optional) The date type name.
3628
 *
3629
 * @return
3630
 *   An associative array of date formats. The top-level keys are the names of
3631
 *   the date types that the date formats belong to. The values are in turn
3632
 *   associative arrays keyed by the format string, with the following keys:
3633
 *   - dfid: The date format ID.
3634
 *   - format: The format string.
3635
 *   - type: The machine-readable name of the date type.
3636
 *   - locales: An array of language codes. This can include both 2 character
3637
 *     language codes like 'en and 'fr' and 5 character language codes like
3638
 *     'en-gb' and 'en-us'.
3639
 *   - locked: A boolean indicating whether or not this date type should be
3640
 *     configurable from the user interface.
3641
 *   - module: The name of the module that defined this date format in its
3642
 *     hook_date_formats(). An empty string if the format was user-defined.
3643
 *   - is_new: A boolean indicating whether or not this date type is as of yet
3644
 *     unsaved in the database.
3645
 *   If $type was defined, only the date formats associated with the given date
3646
 *   type are returned, in a single associative array keyed by format string.
3647
 */
3648
function system_get_date_formats($type = NULL) {
3649
  $date_formats = &drupal_static(__FUNCTION__);
3650

    
3651
  if (!isset($date_formats)) {
3652
    $date_formats = _system_date_formats_build();
3653
  }
3654

    
3655
  return $type ? (isset($date_formats[$type]) ? $date_formats[$type] : FALSE) : $date_formats;
3656
}
3657

    
3658
/**
3659
 * Gets the format details for a particular format ID.
3660
 *
3661
 * @param $dfid
3662
 *   A date format ID.
3663
 *
3664
 * @return
3665
 *   A date format object with the following properties:
3666
 *   - dfid: The date format ID.
3667
 *   - format: The date format string.
3668
 *   - type: The name of the date type.
3669
 *   - locked: Whether the date format can be changed or not.
3670
 */
3671
function system_get_date_format($dfid) {
3672
  return db_query('SELECT df.dfid, df.format, df.type, df.locked FROM {date_formats} df WHERE df.dfid = :dfid', array(':dfid' => $dfid))->fetch();
3673
}
3674

    
3675
/**
3676
 * Resets the database cache of date formats and saves all new date formats.
3677
 */
3678
function system_date_formats_rebuild() {
3679
  drupal_static_reset('system_get_date_formats');
3680
  $date_formats = system_get_date_formats(NULL);
3681

    
3682
  foreach ($date_formats as $type => $formats) {
3683
    foreach ($formats as $format => $info) {
3684
      system_date_format_save($info);
3685
    }
3686
  }
3687

    
3688
  // Rebuild configured date formats locale list.
3689
  drupal_static_reset('system_date_format_locale');
3690
  system_date_format_locale();
3691

    
3692
  _system_date_formats_build();
3693
}
3694

    
3695
/**
3696
 * Gets the appropriate date format string for a date type and locale.
3697
 *
3698
 * @param $langcode
3699
 *   (optional) Language code for the current locale. This can be a 2 character
3700
 *   language code like 'en' and 'fr' or a 5 character language code like
3701
 *   'en-gb' and 'en-us'.
3702
 * @param $type
3703
 *   (optional) The date type name.
3704
 *
3705
 * @return
3706
 *   If $type and $langcode are specified, returns the corresponding date format
3707
 *   string. If only $langcode is specified, returns an array of all date
3708
 *   format strings for that locale, keyed by the date type. If neither is
3709
 *   specified, or if no matching formats are found, returns FALSE.
3710
 */
3711
function system_date_format_locale($langcode = NULL, $type = NULL) {
3712
  $formats = &drupal_static(__FUNCTION__);
3713

    
3714
  if (empty($formats)) {
3715
    $formats = array();
3716
    $result = db_query("SELECT format, type, language FROM {date_format_locale}");
3717
    foreach ($result as $record) {
3718
      if (!isset($formats[$record->language])) {
3719
        $formats[$record->language] = array();
3720
      }
3721
      $formats[$record->language][$record->type] = $record->format;
3722
    }
3723
  }
3724

    
3725
  if ($type && $langcode && !empty($formats[$langcode][$type])) {
3726
    return $formats[$langcode][$type];
3727
  }
3728
  elseif ($langcode && !empty($formats[$langcode])) {
3729
    return $formats[$langcode];
3730
  }
3731

    
3732
  return FALSE;
3733
}
3734

    
3735
/**
3736
 * Builds and returns information about available date types.
3737
 *
3738
 * @return
3739
 *   An associative array of date type information keyed by name. Each date type
3740
 *   information array has the following elements:
3741
 *   - type: The machine-readable name of the date type.
3742
 *   - title: The human-readable name of the date type.
3743
 *   - locked: A boolean indicating whether or not this date type should be
3744
 *     configurable from the user interface.
3745
 *   - module: The name of the module that defined this format in its
3746
 *     hook_date_format_types(). An empty string if the format was user-defined.
3747
 *   - is_new: A boolean indicating whether or not this date type is as of yet
3748
 *     unsaved in the database.
3749
 */
3750
function _system_date_format_types_build() {
3751
  $types = array();
3752

    
3753
  // Get list of modules that implement hook_date_format_types().
3754
  $modules = module_implements('date_format_types');
3755

    
3756
  foreach ($modules as $module) {
3757
    $module_types = module_invoke($module, 'date_format_types');
3758
    foreach ($module_types as $module_type => $type_title) {
3759
      $type = array();
3760
      $type['module'] = $module;
3761
      $type['type'] = $module_type;
3762
      $type['title'] = $type_title;
3763
      $type['locked'] = 1;
3764
      // Will be over-ridden later if in the db.
3765
      $type['is_new'] = TRUE;
3766
      $types[$module_type] = $type;
3767
    }
3768
  }
3769

    
3770
  // Get custom formats added to the database by the end user.
3771
  $result = db_query('SELECT dft.type, dft.title, dft.locked FROM {date_format_type} dft ORDER BY dft.title');
3772
  foreach ($result as $record) {
3773
    if (!isset($types[$record->type])) {
3774
      $type = array();
3775
      $type['is_new'] = FALSE;
3776
      $type['module'] = '';
3777
      $type['type'] = $record->type;
3778
      $type['title'] = $record->title;
3779
      $type['locked'] = $record->locked;
3780
      $types[$record->type] = $type;
3781
    }
3782
    else {
3783
      $type = array();
3784
      $type['is_new'] = FALSE;  // Over-riding previous setting.
3785
      $types[$record->type] = array_merge($types[$record->type], $type);
3786
    }
3787
  }
3788

    
3789
  // Allow other modules to modify these date types.
3790
  drupal_alter('date_format_types', $types);
3791

    
3792
  return $types;
3793
}
3794

    
3795
/**
3796
 * Builds and returns information about available date formats.
3797
 *
3798
 * @return
3799
 *   An associative array of date formats. The top-level keys are the names of
3800
 *   the date types that the date formats belong to. The values are in turn
3801
 *   associative arrays keyed by format with the following keys:
3802
 *   - dfid: The date format ID.
3803
 *   - format: The PHP date format string.
3804
 *   - type: The machine-readable name of the date type the format belongs to.
3805
 *   - locales: An array of language codes. This can include both 2 character
3806
 *     language codes like 'en and 'fr' and 5 character language codes like
3807
 *     'en-gb' and 'en-us'.
3808
 *   - locked: A boolean indicating whether or not this date type should be
3809
 *     configurable from the user interface.
3810
 *   - module: The name of the module that defined this format in its
3811
 *     hook_date_formats(). An empty string if the format was user-defined.
3812
 *   - is_new: A boolean indicating whether or not this date type is as of yet
3813
 *     unsaved in the database.
3814
 */
3815
function _system_date_formats_build() {
3816
  $date_formats = array();
3817

    
3818
  // First handle hook_date_format_types().
3819
  $types = _system_date_format_types_build();
3820
  foreach ($types as $type => $info) {
3821
    system_date_format_type_save($info);
3822
  }
3823

    
3824
  // Get formats supplied by various contrib modules.
3825
  $module_formats = module_invoke_all('date_formats');
3826

    
3827
  foreach ($module_formats as $module_format) {
3828
    // System types are locked.
3829
    $module_format['locked'] = 1;
3830
    // If no date type is specified, assign 'custom'.
3831
    if (!isset($module_format['type'])) {
3832
      $module_format['type'] = 'custom';
3833
    }
3834
    if (!in_array($module_format['type'], array_keys($types))) {
3835
      continue;
3836
    }
3837
    if (!isset($date_formats[$module_format['type']])) {
3838
      $date_formats[$module_format['type']] = array();
3839
    }
3840

    
3841
    // If another module already set this format, merge in the new settings.
3842
    if (isset($date_formats[$module_format['type']][$module_format['format']])) {
3843
      $date_formats[$module_format['type']][$module_format['format']] = array_merge_recursive($date_formats[$module_format['type']][$module_format['format']], $module_format);
3844
    }
3845
    else {
3846
      // This setting will be overridden later if it already exists in the db.
3847
      $module_format['is_new'] = TRUE;
3848
      $date_formats[$module_format['type']][$module_format['format']] = $module_format;
3849
    }
3850
  }
3851

    
3852
  // Get custom formats added to the database by the end user.
3853
  $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');
3854
  foreach ($result as $record) {
3855
    // If this date type isn't set, initialise the array.
3856
    if (!isset($date_formats[$record->type])) {
3857
      $date_formats[$record->type] = array();
3858
    }
3859
    $format = (array) $record;
3860
    $format['is_new'] = FALSE; // It's in the db, so override this setting.
3861
    // If this format not already present, add it to the array.
3862
    if (!isset($date_formats[$record->type][$record->format])) {
3863
      $format['module'] = '';
3864
      $format['locales'] = array($record->language);
3865
      $date_formats[$record->type][$record->format] = $format;
3866
    }
3867
    // Format already present, so merge in settings.
3868
    else {
3869
      if (!empty($record->language)) {
3870
        $format['locales'] = array_merge($date_formats[$record->type][$record->format]['locales'], array($record->language));
3871
      }
3872
      $date_formats[$record->type][$record->format] = array_merge($date_formats[$record->type][$record->format], $format);
3873
    }
3874
  }
3875

    
3876
  // Allow other modules to modify these formats.
3877
  drupal_alter('date_formats', $date_formats);
3878

    
3879
  return $date_formats;
3880
}
3881

    
3882
/**
3883
 * Saves a date type to the database.
3884
 *
3885
 * @param $type
3886
 *   A date type array containing the following keys:
3887
 *   - type: The machine-readable name of the date type.
3888
 *   - title: The human-readable name of the date type.
3889
 *   - locked: A boolean indicating whether or not this date type should be
3890
 *     configurable from the user interface.
3891
 *   - is_new: A boolean indicating whether or not this date type is as of yet
3892
 *     unsaved in the database.
3893
 */
3894
function system_date_format_type_save($type) {
3895
  $info = array();
3896
  $info['type'] = $type['type'];
3897
  $info['title'] = $type['title'];
3898
  $info['locked'] = $type['locked'];
3899

    
3900
  // Update date_format table.
3901
  if (!empty($type['is_new'])) {
3902
    drupal_write_record('date_format_type', $info);
3903
  }
3904
  else {
3905
    drupal_write_record('date_format_type', $info, 'type');
3906
  }
3907
}
3908

    
3909
/**
3910
 * Deletes a date type from the database.
3911
 *
3912
 * @param $type
3913
 *   The machine-readable name of the date type.
3914
 */
3915
function system_date_format_type_delete($type) {
3916
  db_delete('date_formats')
3917
    ->condition('type', $type)
3918
    ->execute();
3919
  db_delete('date_format_type')
3920
    ->condition('type', $type)
3921
    ->execute();
3922
  db_delete('date_format_locale')
3923
    ->condition('type', $type)
3924
    ->execute();
3925
}
3926

    
3927
/**
3928
 * Saves a date format to the database.
3929
 *
3930
 * @param $date_format
3931
 *   A date format array containing the following keys:
3932
 *   - type: The name of the date type this format is associated with.
3933
 *   - format: The PHP date format string.
3934
 *   - locked: A boolean indicating whether or not this format should be
3935
 *     configurable from the user interface.
3936
 * @param $dfid
3937
 *   If set, replace the existing date format having this ID with the
3938
 *   information specified in $date_format.
3939
 *
3940
 * @see system_get_date_types()
3941
 * @see http://php.net/date
3942
 */
3943
function system_date_format_save($date_format, $dfid = 0) {
3944
  $info = array();
3945
  $info['dfid'] = $dfid;
3946
  $info['type'] = $date_format['type'];
3947
  $info['format'] = $date_format['format'];
3948
  $info['locked'] = $date_format['locked'];
3949

    
3950
  // Update date_format table.
3951
  if (!empty($date_format['is_new'])) {
3952
    drupal_write_record('date_formats', $info);
3953
  }
3954
  else {
3955
    $keys = ($dfid ? array('dfid') : array('format', 'type'));
3956
    drupal_write_record('date_formats', $info, $keys);
3957
  }
3958

    
3959
  // Retrieve an array of language objects for enabled languages.
3960
  $languages = language_list('enabled');
3961
  // This list is keyed off the value of $language->enabled; we want the ones
3962
  // that are enabled (value of 1).
3963
  $languages = $languages[1];
3964

    
3965
  $locale_format = array();
3966
  $locale_format['type'] = $date_format['type'];
3967
  $locale_format['format'] = $date_format['format'];
3968

    
3969
  // Check if the suggested language codes are configured and enabled.
3970
  if (!empty($date_format['locales'])) {
3971
    foreach ($date_format['locales'] as $langcode) {
3972
      // Only proceed if language is enabled.
3973
      if (isset($languages[$langcode])) {
3974
        $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();
3975
        if (!$is_existing) {
3976
          $locale_format['language'] = $langcode;
3977
          drupal_write_record('date_format_locale', $locale_format);
3978
        }
3979
      }
3980
    }
3981
  }
3982
}
3983

    
3984
/**
3985
 * Deletes a date format from the database.
3986
 *
3987
 * @param $dfid
3988
 *   The date format ID.
3989
 */
3990
function system_date_format_delete($dfid) {
3991
  db_delete('date_formats')
3992
    ->condition('dfid', $dfid)
3993
    ->execute();
3994
}
3995

    
3996
/**
3997
 * Implements hook_archiver_info().
3998
 */
3999
function system_archiver_info() {
4000
  $archivers['tar'] = array(
4001
    'class' => 'ArchiverTar',
4002
    'extensions' => array('tar', 'tgz', 'tar.gz', 'tar.bz2'),
4003
  );
4004
  if (function_exists('zip_open')) {
4005
    $archivers['zip'] = array(
4006
      'class' => 'ArchiverZip',
4007
      'extensions' => array('zip'),
4008
    );
4009
  }
4010
  return $archivers;
4011
}
4012

    
4013
/**
4014
 * Returns HTML for a confirmation form.
4015
 *
4016
 * By default this does not alter the appearance of a form at all,
4017
 * but is provided as a convenience for themers.
4018
 *
4019
 * @param $variables
4020
 *   An associative array containing:
4021
 *   - form: A render element representing the form.
4022
 *
4023
 * @ingroup themeable
4024
 */
4025
function theme_confirm_form($variables) {
4026
  return drupal_render_children($variables['form']);
4027
}
4028

    
4029
/**
4030
 * Returns HTML for a system settings form.
4031
 *
4032
 * By default this does not alter the appearance of a form at all,
4033
 * but is provided as a convenience for themers.
4034
 *
4035
 * @param $variables
4036
 *   An associative array containing:
4037
 *   - form: A render element representing the form.
4038
 *
4039
 * @ingroup themeable
4040
 */
4041
function theme_system_settings_form($variables) {
4042
  return drupal_render_children($variables['form']);
4043
}
4044

    
4045
/**
4046
 * Returns HTML for an exposed filter form.
4047
 *
4048
 * @param $variables
4049
 *   An associative array containing:
4050
 *   - form: An associative array containing the structure of the form.
4051
 *
4052
 * @return
4053
 *   A string containing an HTML-formatted form.
4054
 *
4055
 * @ingroup themeable
4056
 */
4057
function theme_exposed_filters($variables) {
4058
  $form = $variables['form'];
4059
  $output = '';
4060

    
4061
  if (isset($form['current'])) {
4062
    $items = array();
4063
    foreach (element_children($form['current']) as $key) {
4064
      $items[] = drupal_render($form['current'][$key]);
4065
    }
4066
    $output .= theme('item_list', array('items' => $items, 'attributes' => array('class' => array('clearfix', 'current-filters'))));
4067
  }
4068

    
4069
  $output .= drupal_render_children($form);
4070

    
4071
  return '<div class="exposed-filters">' . $output . '</div>';
4072
}
4073

    
4074
/**
4075
 * Implements hook_admin_paths().
4076
 */
4077
function system_admin_paths() {
4078
  $paths = array(
4079
    'admin' => TRUE,
4080
    'admin/*' => TRUE,
4081
    'batch' => TRUE,
4082
    // This page should not be treated as administrative since it outputs its
4083
    // own content (outside of any administration theme).
4084
    'admin/reports/status/php' => FALSE,
4085
  );
4086
  return $paths;
4087
}