Projet

Général

Profil

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

root / drupal7 / modules / system / system.module @ 27e02aed

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
      // This includes a security fix, so assign a weight that makes this 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
    ),
1193
  );
1194

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

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

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

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

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

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

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

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

    
1658
  return $libraries;
1659
}
1660

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

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

    
1690
  return $wrappers;
1691
}
1692

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2216
  return $form_element;
2217
}
2218

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

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

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

    
2260
      $updated_fields = array();
2261

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2456
  return $modules;
2457
}
2458

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2639
  return $themes;
2640
}
2641

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2912
  drupal_set_title($question, PASS_THROUGH);
2913

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

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

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

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

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

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

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

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

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

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

    
3053
  return $admin_tasks;
3054
}
3055

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3342
/**
3343
 * Settings form for system_goto_action().
3344
 */
3345
function system_goto_action_form($context) {
3346
  $form['url'] = array(
3347
    '#type' => 'textfield',
3348
    '#title' => t('URL'),
3349
    '#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.'),
3350
    '#default_value' => isset($context['url']) ? $context['url'] : '',
3351
    '#required' => TRUE,
3352
  );
3353
  return $form;
3354
}
3355

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

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

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

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

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

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

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

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

    
3470
  return $output;
3471
}
3472

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

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

    
3540
  return $local;
3541
}
3542

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3691
  _system_date_formats_build();
3692
}
3693

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

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

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

    
3731
  return FALSE;
3732
}
3733

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

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

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

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

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

    
3791
  return $types;
3792
}
3793

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

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

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

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

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

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

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

    
3878
  return $date_formats;
3879
}
3880

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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