Projet

Général

Profil

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

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

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
    ),
246
    'block IP addresses' => array(
247
      'title' => t('Block IP addresses'),
248
    ),
249
  );
250
}
251

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

    
269
  return $hooks;
270
}
271

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

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

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

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

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

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

    
513
  return $types;
514
}
515

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1644
  return $libraries;
1645
}
1646

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

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

    
1676
  return $wrappers;
1677
}
1678

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1994
/**
1995
 * Implements hook_user_login().
1996
 */
1997
function system_user_login(&$edit, $account) {
1998
  // If the user has a NULL time zone, notify them to set a time zone.
1999
  if (!$account->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) {
2000
    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')))));
2001
  }
2002
}
2003

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2203
  return $form_element;
2204
}
2205

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

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

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

    
2247
      $updated_fields = array();
2248

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2401
    // Merge in defaults and save.
2402
    $modules[$key]->info = $module->info + $defaults;
2403

    
2404
    // Prefix stylesheets and scripts with module path.
2405
    $path = dirname($module->uri);
2406
    if (isset($module->info['stylesheets'])) {
2407
      $module->info['stylesheets'] = _system_info_add_path($module->info['stylesheets'], $path);
2408
    }
2409
    if (isset($module->info['scripts'])) {
2410
      $module->info['scripts'] = _system_info_add_path($module->info['scripts'], $path);
2411
    }
2412

    
2413
    // Installation profiles are hidden by default, unless explicitly specified
2414
    // otherwise in the .info file.
2415
    if ($key == $profile && !isset($modules[$key]->info['hidden'])) {
2416
      $modules[$key]->info['hidden'] = TRUE;
2417
    }
2418

    
2419
    // Invoke hook_system_info_alter() to give installed modules a chance to
2420
    // modify the data in the .info files if necessary.
2421
    $type = 'module';
2422
    drupal_alter('system_info', $modules[$key]->info, $modules[$key], $type);
2423
  }
2424

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

    
2435
  return $modules;
2436
}
2437

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

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

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

    
2508
  // Find theme engines
2509
  $engines = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.engine$/', 'themes/engines');
2510

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

    
2533
  $sub_themes = array();
2534
  // Read info files for each theme
2535
  foreach ($themes as $key => $theme) {
2536
    $themes[$key]->filename = $theme->uri;
2537
    $themes[$key]->info = drupal_parse_info_file($theme->uri) + $defaults;
2538

    
2539
    // Invoke hook_system_info_alter() to give installed modules a chance to
2540
    // modify the data in the .info files if necessary.
2541
    $type = 'theme';
2542
    drupal_alter('system_info', $themes[$key]->info, $themes[$key], $type);
2543

    
2544
    if (!empty($themes[$key]->info['base theme'])) {
2545
      $sub_themes[] = $key;
2546
    }
2547
    if ($themes[$key]->info['engine'] == 'theme') {
2548
      $filename = dirname($themes[$key]->uri) . '/' . $themes[$key]->name . '.theme';
2549
      if (file_exists($filename)) {
2550
        $themes[$key]->owner = $filename;
2551
        $themes[$key]->prefix = $key;
2552
      }
2553
    }
2554
    else {
2555
      $engine = $themes[$key]->info['engine'];
2556
      if (isset($engines[$engine])) {
2557
        $themes[$key]->owner = $engines[$engine]->uri;
2558
        $themes[$key]->prefix = $engines[$engine]->name;
2559
        $themes[$key]->template = TRUE;
2560
      }
2561
    }
2562

    
2563
    // Prefix stylesheets and scripts with module path.
2564
    $path = dirname($theme->uri);
2565
    $theme->info['stylesheets'] = _system_info_add_path($theme->info['stylesheets'], $path);
2566
    $theme->info['scripts'] = _system_info_add_path($theme->info['scripts'], $path);
2567

    
2568
    // Give the screenshot proper path information.
2569
    if (!empty($themes[$key]->info['screenshot'])) {
2570
      $themes[$key]->info['screenshot'] = $path . '/' . $themes[$key]->info['screenshot'];
2571
    }
2572
  }
2573

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

    
2600
  return $themes;
2601
}
2602

    
2603
/**
2604
 * Rebuild, save, and return data about all currently available themes.
2605
 *
2606
 * @return
2607
 *   Array of all available themes and their data.
2608
 */
2609
function system_rebuild_theme_data() {
2610
  $themes = _system_rebuild_theme_data();
2611
  ksort($themes);
2612
  system_get_files_database($themes, 'theme');
2613
  system_update_files_database($themes, 'theme');
2614
  return $themes;
2615
}
2616

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

    
2652
/**
2653
 * Returns an array of default theme features.
2654
 */
2655
function _system_default_theme_features() {
2656
  return array(
2657
    'logo',
2658
    'favicon',
2659
    'name',
2660
    'slogan',
2661
    'node_user_picture',
2662
    'comment_user_picture',
2663
    'comment_user_verification',
2664
    'main_menu',
2665
    'secondary_menu',
2666
  );
2667
}
2668

    
2669
/**
2670
 * Find all the base themes for the specified theme.
2671
 *
2672
 * This function has been deprecated in favor of drupal_find_base_themes().
2673
 */
2674
function system_find_base_themes($themes, $key, $used_keys = array()) {
2675
  return drupal_find_base_themes($themes, $key, $used_keys);
2676
}
2677

    
2678
/**
2679
 * Get a list of available regions from a specified theme.
2680
 *
2681
 * @param $theme_key
2682
 *   The name of a theme.
2683
 * @param $show
2684
 *   Possible values: REGIONS_ALL or REGIONS_VISIBLE. Visible excludes hidden
2685
 *   regions.
2686
 * @return
2687
 *   An array of regions in the form $region['name'] = 'description'.
2688
 */
2689
function system_region_list($theme_key, $show = REGIONS_ALL) {
2690
  $themes = list_themes();
2691
  if (!isset($themes[$theme_key])) {
2692
    return array();
2693
  }
2694

    
2695
  $list = array();
2696
  $info = $themes[$theme_key]->info;
2697
  // If requested, suppress hidden regions. See block_admin_display_form().
2698
  foreach ($info['regions'] as $name => $label) {
2699
    if ($show == REGIONS_ALL || !isset($info['regions_hidden']) || !in_array($name, $info['regions_hidden'])) {
2700
      $list[$name] = t($label);
2701
    }
2702
  }
2703

    
2704
  return $list;
2705
}
2706

    
2707
/**
2708
 * Implements hook_system_info_alter().
2709
 */
2710
function system_system_info_alter(&$info, $file, $type) {
2711
  // Remove page-top and page-bottom from the blocks UI since they are reserved for
2712
  // modules to populate from outside the blocks system.
2713
  if ($type == 'theme') {
2714
    $info['regions_hidden'][] = 'page_top';
2715
    $info['regions_hidden'][] = 'page_bottom';
2716
  }
2717
}
2718

    
2719
/**
2720
 * Get the name of the default region for a given theme.
2721
 *
2722
 * @param $theme
2723
 *   The name of a theme.
2724
 * @return
2725
 *   A string that is the region name.
2726
 */
2727
function system_default_region($theme) {
2728
  $regions = array_keys(system_region_list($theme, REGIONS_VISIBLE));
2729
  return isset($regions[0]) ? $regions[0] : '';
2730
}
2731

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

    
2759
  if (!empty($_POST) && form_get_errors()) {
2760
    drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
2761
  }
2762
  $form['#submit'][] = 'system_settings_form_submit';
2763
  // By default, render the form using theme_system_settings_form().
2764
  if (!isset($form['#theme'])) {
2765
    $form['#theme'] = 'system_settings_form';
2766
  }
2767
  return $form;
2768
}
2769

    
2770
/**
2771
 * Form submission handler for system_settings_form().
2772
 *
2773
 * If you want node type configure style handling of your checkboxes,
2774
 * add an array_filter value to your form.
2775
 */
2776
function system_settings_form_submit($form, &$form_state) {
2777
  // Exclude unnecessary elements.
2778
  form_state_values_clean($form_state);
2779

    
2780
  foreach ($form_state['values'] as $key => $value) {
2781
    if (is_array($value) && isset($form_state['values']['array_filter'])) {
2782
      $value = array_keys(array_filter($value));
2783
    }
2784
    variable_set($key, $value);
2785
  }
2786

    
2787
  drupal_set_message(t('The configuration options have been saved.'));
2788
}
2789

    
2790
/**
2791
 * Helper function to sort requirements.
2792
 */
2793
function _system_sort_requirements($a, $b) {
2794
  if (!isset($a['weight'])) {
2795
    if (!isset($b['weight'])) {
2796
      return strcmp($a['title'], $b['title']);
2797
    }
2798
    return -$b['weight'];
2799
  }
2800
  return isset($b['weight']) ? $a['weight'] - $b['weight'] : $a['weight'];
2801
}
2802

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

    
2850
  // Prepare cancel link.
2851
  if (isset($_GET['destination'])) {
2852
    $options = drupal_parse_url(urldecode($_GET['destination']));
2853
  }
2854
  elseif (is_array($path)) {
2855
    $options = $path;
2856
  }
2857
  else {
2858
    $options = array('path' => $path);
2859
  }
2860

    
2861
  drupal_set_title($question, PASS_THROUGH);
2862

    
2863
  $form['#attributes']['class'][] = 'confirmation';
2864
  $form['description'] = array('#markup' => $description);
2865
  $form[$name] = array('#type' => 'hidden', '#value' => 1);
2866

    
2867
  $form['actions'] = array('#type' => 'actions');
2868
  $form['actions']['submit'] = array(
2869
    '#type' => 'submit',
2870
    '#value' => $yes ? $yes : t('Confirm'),
2871
  );
2872
  $form['actions']['cancel'] = array(
2873
    '#type' => 'link',
2874
    '#title' => $no ? $no : t('Cancel'),
2875
    '#href' => $options['path'],
2876
    '#options' => $options,
2877
  );
2878
  // By default, render the form using theme_confirm_form().
2879
  if (!isset($form['#theme'])) {
2880
    $form['#theme'] = 'confirm_form';
2881
  }
2882
  return $form;
2883
}
2884

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

    
2908
/**
2909
 * Menu callback; Sets whether the admin menu is in compact mode or not.
2910
 *
2911
 * @param $mode
2912
 *   Valid values are 'on' and 'off'.
2913
 */
2914
function system_admin_compact_page($mode = 'off') {
2915
  user_cookie_save(array('admin_compact_mode' => ($mode == 'on')));
2916
  drupal_goto();
2917
}
2918

    
2919
/**
2920
 * Generate a list of tasks offered by a specified module.
2921
 *
2922
 * @param $module
2923
 *   Module name.
2924
 * @param $info
2925
 *   The module's information, as provided by system_get_info().
2926
 *
2927
 * @return
2928
 *   An array of task links.
2929
 */
2930
function system_get_module_admin_tasks($module, $info) {
2931
  $links = &drupal_static(__FUNCTION__);
2932

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

    
2954
  $admin_tasks = array();
2955
  $titles = array();
2956
  if ($menu = module_invoke($module, 'menu')) {
2957
    foreach ($menu as $path => $item) {
2958
      if (isset($links[$path])) {
2959
        $task = $links[$path];
2960
        // The link description, either derived from 'description' in
2961
        // hook_menu() or customized via menu module is used as title attribute.
2962
        if (!empty($task['localized_options']['attributes']['title'])) {
2963
          $task['description'] = $task['localized_options']['attributes']['title'];
2964
          unset($task['localized_options']['attributes']['title']);
2965
        }
2966

    
2967
        // Check the admin tasks for duplicate names. If one is found,
2968
        // append the parent menu item's title to differentiate.
2969
        $duplicate_path = array_search($task['title'], $titles);
2970
        if ($duplicate_path !== FALSE) {
2971
          if ($parent = menu_link_load($task['plid'])) {
2972
            // Append the parent item's title to this task's title.
2973
            $task['title'] = t('@original_title (@parent_title)', array('@original_title' => $task['title'], '@parent_title' => $parent['title']));
2974
          }
2975
          if ($parent = menu_link_load($admin_tasks[$duplicate_path]['plid'])) {
2976
            // Append the parent item's title to the duplicated task's title.
2977
            // We use $links[$duplicate_path] in case there are triplicates.
2978
            $admin_tasks[$duplicate_path]['title'] = t('@original_title (@parent_title)', array('@original_title' => $links[$duplicate_path]['title'], '@parent_title' => $parent['title']));
2979
          }
2980
        }
2981
        else {
2982
          $titles[$path] = $task['title'];
2983
        }
2984

    
2985
        $admin_tasks[$path] = $task;
2986
      }
2987
    }
2988
  }
2989

    
2990
  // Append link for permissions.
2991
  if (module_hook($module, 'permission')) {
2992
    $item = menu_get_item('admin/people/permissions');
2993
    if (!empty($item['access'])) {
2994
      $item['link_path'] = $item['href'];
2995
      $item['title'] = t('Configure @module permissions', array('@module' => $info['name']));
2996
      unset($item['description']);
2997
      $item['localized_options']['fragment'] = 'module-' . $module;
2998
      $admin_tasks["admin/people/permissions#module-$module"] = $item;
2999
    }
3000
  }
3001

    
3002
  return $admin_tasks;
3003
}
3004

    
3005
/**
3006
 * Implements hook_cron().
3007
 *
3008
 * Remove older rows from flood and batch table. Remove old temporary files.
3009
 */
3010
function system_cron() {
3011
  // Cleanup the flood.
3012
  db_delete('flood')
3013
    ->condition('expiration', REQUEST_TIME, '<')
3014
    ->execute();
3015

    
3016
  // Remove temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
3017
  // Use separate placeholders for the status to avoid a bug in some versions
3018
  // of PHP. See http://drupal.org/node/352956.
3019
  $result = db_query('SELECT fid FROM {file_managed} WHERE status <> :permanent AND timestamp < :timestamp', array(
3020
    ':permanent' => FILE_STATUS_PERMANENT,
3021
    ':timestamp' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE
3022
  ));
3023
  foreach ($result as $row) {
3024
    if ($file = file_load($row->fid)) {
3025
      $references = file_usage_list($file);
3026
      if (empty($references)) {
3027
        if (!file_delete($file)) {
3028
          watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' => $file->uri), WATCHDOG_ERROR);
3029
        }
3030
      }
3031
      else {
3032
        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);
3033
      }
3034
    }
3035
  }
3036

    
3037
  $core = array('cache', 'cache_path', 'cache_filter', 'cache_page', 'cache_form', 'cache_menu');
3038
  $cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
3039
  foreach ($cache_tables as $table) {
3040
    cache_clear_all(NULL, $table);
3041
  }
3042

    
3043
  // Cleanup the batch table and the queue for failed batches.
3044
  db_delete('batch')
3045
    ->condition('timestamp', REQUEST_TIME - 864000, '<')
3046
    ->execute();
3047
  db_delete('queue')
3048
    ->condition('created', REQUEST_TIME - 864000, '<')
3049
    ->condition('name', 'drupal_batch:%', 'LIKE')
3050
    ->execute();
3051

    
3052
  // Reset expired items in the default queue implementation table. If that's
3053
  // not used, this will simply be a no-op.
3054
  db_update('queue')
3055
    ->fields(array(
3056
      'expire' => 0,
3057
    ))
3058
    ->condition('expire', 0, '<>')
3059
    ->condition('expire', REQUEST_TIME, '<')
3060
    ->execute();
3061
}
3062

    
3063
/**
3064
 * Implements hook_flush_caches().
3065
 */
3066
function system_flush_caches() {
3067
  // Rebuild list of date formats.
3068
  system_date_formats_rebuild();
3069
  // Reset the menu static caches.
3070
  menu_reset_static_cache();
3071
}
3072

    
3073
/**
3074
 * Implements hook_action_info().
3075
 */
3076
function system_action_info() {
3077
  return array(
3078
    'system_message_action' => array(
3079
      'type' => 'system',
3080
      'label' => t('Display a message to the user'),
3081
      'configurable' => TRUE,
3082
      'triggers' => array('any'),
3083
    ),
3084
    'system_send_email_action' => array(
3085
      'type' => 'system',
3086
      'label' => t('Send e-mail'),
3087
      'configurable' => TRUE,
3088
      'triggers' => array('any'),
3089
    ),
3090
    'system_block_ip_action' => array(
3091
      'type' => 'user',
3092
      'label' => t('Ban IP address of current user'),
3093
      'configurable' => FALSE,
3094
      'triggers' => array('any'),
3095
    ),
3096
    'system_goto_action' => array(
3097
      'type' => 'system',
3098
      'label' => t('Redirect to URL'),
3099
      'configurable' => TRUE,
3100
      'triggers' => array('any'),
3101
    ),
3102
  );
3103
}
3104

    
3105
/**
3106
 * Return a form definition so the Send email action can be configured.
3107
 *
3108
 * @param $context
3109
 *   Default values (if we are editing an existing action instance).
3110
 *
3111
 * @return
3112
 *   Form definition.
3113
 *
3114
 * @see system_send_email_action_validate()
3115
 * @see system_send_email_action_submit()
3116
 */
3117
function system_send_email_action_form($context) {
3118
  // Set default values for form.
3119
  if (!isset($context['recipient'])) {
3120
    $context['recipient'] = '';
3121
  }
3122
  if (!isset($context['subject'])) {
3123
    $context['subject'] = '';
3124
  }
3125
  if (!isset($context['message'])) {
3126
    $context['message'] = '';
3127
  }
3128

    
3129
  $form['recipient'] = array(
3130
    '#type' => 'textfield',
3131
    '#title' => t('Recipient'),
3132
    '#default_value' => $context['recipient'],
3133
    '#maxlength' => '254',
3134
    '#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.'),
3135
  );
3136
  $form['subject'] = array(
3137
    '#type' => 'textfield',
3138
    '#title' => t('Subject'),
3139
    '#default_value' => $context['subject'],
3140
    '#maxlength' => '254',
3141
    '#description' => t('The subject of the message.'),
3142
  );
3143
  $form['message'] = array(
3144
    '#type' => 'textarea',
3145
    '#title' => t('Message'),
3146
    '#default_value' => $context['message'],
3147
    '#cols' => '80',
3148
    '#rows' => '20',
3149
    '#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.'),
3150
  );
3151
  return $form;
3152
}
3153

    
3154
/**
3155
 * Validate system_send_email_action form submissions.
3156
 */
3157
function system_send_email_action_validate($form, $form_state) {
3158
  $form_values = $form_state['values'];
3159
  // Validate the configuration form.
3160
  if (!valid_email_address($form_values['recipient']) && strpos($form_values['recipient'], ':mail') === FALSE) {
3161
    // We want the literal %author placeholder to be emphasized in the error message.
3162
    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]')));
3163
  }
3164
}
3165

    
3166
/**
3167
 * Process system_send_email_action form submissions.
3168
 */
3169
function system_send_email_action_submit($form, $form_state) {
3170
  $form_values = $form_state['values'];
3171
  // Process the HTML form to store configuration. The keyed array that
3172
  // we return will be serialized to the database.
3173
  $params = array(
3174
    'recipient' => $form_values['recipient'],
3175
    'subject'   => $form_values['subject'],
3176
    'message'   => $form_values['message'],
3177
  );
3178
  return $params;
3179
}
3180

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

    
3204
  $recipient = token_replace($context['recipient'], $context);
3205

    
3206
  // If the recipient is a registered user with a language preference, use
3207
  // the recipient's preferred language. Otherwise, use the system default
3208
  // language.
3209
  $recipient_account = user_load_by_mail($recipient);
3210
  if ($recipient_account) {
3211
    $language = user_preferred_language($recipient_account);
3212
  }
3213
  else {
3214
    $language = language_default();
3215
  }
3216
  $params = array('context' => $context);
3217

    
3218
  if (drupal_mail('system', 'action_send_email', $recipient, $language, $params)) {
3219
    watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient));
3220
  }
3221
  else {
3222
    watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient));
3223
  }
3224
}
3225

    
3226
/**
3227
 * Implements hook_mail().
3228
 */
3229
function system_mail($key, &$message, $params) {
3230
  $context = $params['context'];
3231

    
3232
  $subject = token_replace($context['subject'], $context);
3233
  $body = token_replace($context['message'], $context);
3234

    
3235
  $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
3236
  $message['body'][] = $body;
3237
}
3238

    
3239
function system_message_action_form($context) {
3240
  $form['message'] = array(
3241
    '#type' => 'textarea',
3242
    '#title' => t('Message'),
3243
    '#default_value' => isset($context['message']) ? $context['message'] : '',
3244
    '#required' => TRUE,
3245
    '#rows' => '8',
3246
    '#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.'),
3247
  );
3248
  return $form;
3249
}
3250

    
3251
function system_message_action_submit($form, $form_state) {
3252
  return array('message' => $form_state['values']['message']);
3253
}
3254

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

    
3275
  $context['message'] = token_replace(filter_xss_admin($context['message']), $context);
3276
  drupal_set_message($context['message']);
3277
}
3278

    
3279
/**
3280
 * Settings form for system_goto_action().
3281
 */
3282
function system_goto_action_form($context) {
3283
  $form['url'] = array(
3284
    '#type' => 'textfield',
3285
    '#title' => t('URL'),
3286
    '#description' => t('The URL to which the user should be redirected. This can be an internal URL like node/1234 or an external URL like http://drupal.org.'),
3287
    '#default_value' => isset($context['url']) ? $context['url'] : '',
3288
    '#required' => TRUE,
3289
  );
3290
  return $form;
3291
}
3292

    
3293
function system_goto_action_submit($form, $form_state) {
3294
  return array(
3295
    'url' => $form_state['values']['url']
3296
  );
3297
}
3298

    
3299
/**
3300
 * Redirects to a different URL.
3301
 *
3302
 * @param $entity
3303
 *   Ignored.
3304
 * @param array $context
3305
 *   Array with the following elements:
3306
 *   - 'url': URL to redirect to. This will be passed through
3307
 *     token_replace().
3308
 *   - Other elements will be used as the data for token replacement.
3309
 *
3310
 * @ingroup actions
3311
 */
3312
function system_goto_action($entity, $context) {
3313
  drupal_goto(token_replace($context['url'], $context));
3314
}
3315

    
3316
/**
3317
 * Blocks the current user's IP address.
3318
 *
3319
 * @ingroup actions
3320
 */
3321
function system_block_ip_action() {
3322
  $ip = ip_address();
3323
  db_insert('blocked_ips')
3324
    ->fields(array('ip' => $ip))
3325
    ->execute();
3326
  watchdog('action', 'Banned IP address %ip', array('%ip' => $ip));
3327
}
3328

    
3329
/**
3330
 * Generate an array of time zones and their local time&date.
3331
 *
3332
 * @param $blank
3333
 *   If evaluates true, prepend an empty time zone option to the array.
3334
 */
3335
function system_time_zones($blank = NULL) {
3336
  $zonelist = timezone_identifiers_list();
3337
  $zones = $blank ? array('' => t('- None selected -')) : array();
3338
  foreach ($zonelist as $zone) {
3339
    // Because many time zones exist in PHP only for backward compatibility
3340
    // reasons and should not be used, the list is filtered by a regular
3341
    // expression.
3342
    if (preg_match('!^((Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)/|UTC$)!', $zone)) {
3343
      $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)));
3344
    }
3345
  }
3346
  // Sort the translated time zones alphabetically.
3347
  asort($zones);
3348
  return $zones;
3349
}
3350

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

    
3371
/**
3372
 * Menu callback; Retrieve a JSON object containing a suggested time zone name.
3373
 */
3374
function system_timezone($abbreviation = '', $offset = -1, $is_daylight_saving_time = NULL) {
3375
  // An abbreviation of "0" passed in the callback arguments should be
3376
  // interpreted as the empty string.
3377
  $abbreviation = $abbreviation ? $abbreviation : '';
3378
  $timezone = timezone_name_from_abbr($abbreviation, intval($offset), $is_daylight_saving_time);
3379
  drupal_json_output($timezone);
3380
}
3381

    
3382
/**
3383
 * Returns HTML for the Powered by Drupal text.
3384
 *
3385
 * @ingroup themeable
3386
 */
3387
function theme_system_powered_by() {
3388
  return '<span>' . t('Powered by <a href="@poweredby">Drupal</a>', array('@poweredby' => 'http://drupal.org')) . '</span>';
3389
}
3390

    
3391
/**
3392
 * Returns HTML for a link to show or hide inline help descriptions.
3393
 *
3394
 * @ingroup themeable
3395
 */
3396
function theme_system_compact_link() {
3397
  $output = '<div class="compact-link">';
3398
  if (system_admin_compact_mode()) {
3399
    $output .= l(t('Show descriptions'), 'admin/compact/off', array('attributes' => array('title' => t('Expand layout to include descriptions.')), 'query' => drupal_get_destination()));
3400
  }
3401
  else {
3402
    $output .= l(t('Hide descriptions'), 'admin/compact/on', array('attributes' => array('title' => t('Compress layout by hiding descriptions.')), 'query' => drupal_get_destination()));
3403
  }
3404
  $output .= '</div>';
3405

    
3406
  return $output;
3407
}
3408

    
3409
/**
3410
 * Implements hook_image_toolkits().
3411
 */
3412
function system_image_toolkits() {
3413
  include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'system') . '/' . 'image.gd.inc';
3414
  return array(
3415
    'gd' => array(
3416
      'title' => t('GD2 image manipulation toolkit'),
3417
      'available' => function_exists('image_gd_check_settings') && image_gd_check_settings(),
3418
    ),
3419
  );
3420
}
3421

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

    
3474
  return $local;
3475
}
3476

    
3477
/**
3478
 * Implements hook_page_alter().
3479
 */
3480
function system_page_alter(&$page) {
3481
  // Find all non-empty page regions, and add a theme wrapper function that
3482
  // allows them to be consistently themed.
3483
  $regions = system_region_list($GLOBALS['theme']);
3484
  foreach (array_keys($regions) as $region) {
3485
    if (!empty($page[$region])) {
3486
      $page[$region]['#theme_wrappers'][] = 'region';
3487
      $page[$region]['#region'] = $region;
3488
    }
3489
  }
3490
}
3491

    
3492
/**
3493
 * Run the automated cron if enabled.
3494
 */
3495
function system_run_automated_cron() {
3496
  // If the site is not fully installed, suppress the automated cron run.
3497
  // Otherwise it could be triggered prematurely by Ajax requests during
3498
  // installation.
3499
  if (($threshold = variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD)) > 0 && variable_get('install_task') == 'done') {
3500
    $cron_last = variable_get('cron_last', NULL);
3501
    if (!isset($cron_last) || (REQUEST_TIME - $cron_last > $threshold)) {
3502
      drupal_cron_run();
3503
    }
3504
  }
3505
}
3506

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

    
3531
  if (!isset($types)) {
3532
    $types = _system_date_format_types_build();
3533
  }
3534

    
3535
  return $type ? (isset($types[$type]) ? $types[$type] : FALSE) : $types;
3536
}
3537

    
3538
/**
3539
 * Implements hook_date_format_types().
3540
 */
3541
function system_date_format_types() {
3542
  return array(
3543
    'long' => t('Long'),
3544
    'medium' => t('Medium'),
3545
    'short' => t('Short'),
3546
  );
3547
}
3548

    
3549
/**
3550
 * Implements hook_date_formats().
3551
 */
3552
function system_date_formats() {
3553
  include_once DRUPAL_ROOT . '/includes/date.inc';
3554
  return system_default_date_formats();
3555
}
3556

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

    
3585
  if (!isset($date_formats)) {
3586
    $date_formats = _system_date_formats_build();
3587
  }
3588

    
3589
  return $type ? (isset($date_formats[$type]) ? $date_formats[$type] : FALSE) : $date_formats;
3590
}
3591

    
3592
/**
3593
 * Gets the format details for a particular format ID.
3594
 *
3595
 * @param $dfid
3596
 *   A date format ID.
3597
 *
3598
 * @return
3599
 *   A date format object with the following properties:
3600
 *   - dfid: The date format ID.
3601
 *   - format: The date format string.
3602
 *   - type: The name of the date type.
3603
 *   - locked: Whether the date format can be changed or not.
3604
 */
3605
function system_get_date_format($dfid) {
3606
  return db_query('SELECT df.dfid, df.format, df.type, df.locked FROM {date_formats} df WHERE df.dfid = :dfid', array(':dfid' => $dfid))->fetch();
3607
}
3608

    
3609
/**
3610
 * Resets the database cache of date formats and saves all new date formats.
3611
 */
3612
function system_date_formats_rebuild() {
3613
  drupal_static_reset('system_get_date_formats');
3614
  $date_formats = system_get_date_formats(NULL);
3615

    
3616
  foreach ($date_formats as $type => $formats) {
3617
    foreach ($formats as $format => $info) {
3618
      system_date_format_save($info);
3619
    }
3620
  }
3621

    
3622
  // Rebuild configured date formats locale list.
3623
  drupal_static_reset('system_date_format_locale');
3624
  system_date_format_locale();
3625

    
3626
  _system_date_formats_build();
3627
}
3628

    
3629
/**
3630
 * Gets the appropriate date format string for a date type and locale.
3631
 *
3632
 * @param $langcode
3633
 *   (optional) Language code for the current locale. This can be a 2 character
3634
 *   language code like 'en' and 'fr' or a 5 character language code like
3635
 *   'en-gb' and 'en-us'.
3636
 * @param $type
3637
 *   (optional) The date type name.
3638
 *
3639
 * @return
3640
 *   If $type and $langcode are specified, returns the corresponding date format
3641
 *   string. If only $langcode is specified, returns an array of all date
3642
 *   format strings for that locale, keyed by the date type. If neither is
3643
 *   specified, or if no matching formats are found, returns FALSE.
3644
 */
3645
function system_date_format_locale($langcode = NULL, $type = NULL) {
3646
  $formats = &drupal_static(__FUNCTION__);
3647

    
3648
  if (empty($formats)) {
3649
    $formats = array();
3650
    $result = db_query("SELECT format, type, language FROM {date_format_locale}");
3651
    foreach ($result as $record) {
3652
      if (!isset($formats[$record->language])) {
3653
        $formats[$record->language] = array();
3654
      }
3655
      $formats[$record->language][$record->type] = $record->format;
3656
    }
3657
  }
3658

    
3659
  if ($type && $langcode && !empty($formats[$langcode][$type])) {
3660
    return $formats[$langcode][$type];
3661
  }
3662
  elseif ($langcode && !empty($formats[$langcode])) {
3663
    return $formats[$langcode];
3664
  }
3665

    
3666
  return FALSE;
3667
}
3668

    
3669
/**
3670
 * Builds and returns information about available date types.
3671
 *
3672
 * @return
3673
 *   An associative array of date type information keyed by name. Each date type
3674
 *   information array has the following elements:
3675
 *   - type: The machine-readable name of the date type.
3676
 *   - title: The human-readable name of the date type.
3677
 *   - locked: A boolean indicating whether or not this date type should be
3678
 *     configurable from the user interface.
3679
 *   - module: The name of the module that defined this format in its
3680
 *     hook_date_format_types(). An empty string if the format was user-defined.
3681
 *   - is_new: A boolean indicating whether or not this date type is as of yet
3682
 *     unsaved in the database.
3683
 */
3684
function _system_date_format_types_build() {
3685
  $types = array();
3686

    
3687
  // Get list of modules that implement hook_date_format_types().
3688
  $modules = module_implements('date_format_types');
3689

    
3690
  foreach ($modules as $module) {
3691
    $module_types = module_invoke($module, 'date_format_types');
3692
    foreach ($module_types as $module_type => $type_title) {
3693
      $type = array();
3694
      $type['module'] = $module;
3695
      $type['type'] = $module_type;
3696
      $type['title'] = $type_title;
3697
      $type['locked'] = 1;
3698
      // Will be over-ridden later if in the db.
3699
      $type['is_new'] = TRUE;
3700
      $types[$module_type] = $type;
3701
    }
3702
  }
3703

    
3704
  // Get custom formats added to the database by the end user.
3705
  $result = db_query('SELECT dft.type, dft.title, dft.locked FROM {date_format_type} dft ORDER BY dft.title');
3706
  foreach ($result as $record) {
3707
    if (!isset($types[$record->type])) {
3708
      $type = array();
3709
      $type['is_new'] = FALSE;
3710
      $type['module'] = '';
3711
      $type['type'] = $record->type;
3712
      $type['title'] = $record->title;
3713
      $type['locked'] = $record->locked;
3714
      $types[$record->type] = $type;
3715
    }
3716
    else {
3717
      $type = array();
3718
      $type['is_new'] = FALSE;  // Over-riding previous setting.
3719
      $types[$record->type] = array_merge($types[$record->type], $type);
3720
    }
3721
  }
3722

    
3723
  // Allow other modules to modify these date types.
3724
  drupal_alter('date_format_types', $types);
3725

    
3726
  return $types;
3727
}
3728

    
3729
/**
3730
 * Builds and returns information about available date formats.
3731
 *
3732
 * @return
3733
 *   An associative array of date formats. The top-level keys are the names of
3734
 *   the date types that the date formats belong to. The values are in turn
3735
 *   associative arrays keyed by format with the following keys:
3736
 *   - dfid: The date format ID.
3737
 *   - format: The PHP date format string.
3738
 *   - type: The machine-readable name of the date type the format belongs to.
3739
 *   - locales: An array of language codes. This can include both 2 character
3740
 *     language codes like 'en and 'fr' and 5 character language codes like
3741
 *     'en-gb' and 'en-us'.
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_formats(). 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_formats_build() {
3750
  $date_formats = array();
3751

    
3752
  // First handle hook_date_format_types().
3753
  $types = _system_date_format_types_build();
3754
  foreach ($types as $type => $info) {
3755
    system_date_format_type_save($info);
3756
  }
3757

    
3758
  // Get formats supplied by various contrib modules.
3759
  $module_formats = module_invoke_all('date_formats');
3760

    
3761
  foreach ($module_formats as $module_format) {
3762
    // System types are locked.
3763
    $module_format['locked'] = 1;
3764
    // If no date type is specified, assign 'custom'.
3765
    if (!isset($module_format['type'])) {
3766
      $module_format['type'] = 'custom';
3767
    }
3768
    if (!in_array($module_format['type'], array_keys($types))) {
3769
      continue;
3770
    }
3771
    if (!isset($date_formats[$module_format['type']])) {
3772
      $date_formats[$module_format['type']] = array();
3773
    }
3774

    
3775
    // If another module already set this format, merge in the new settings.
3776
    if (isset($date_formats[$module_format['type']][$module_format['format']])) {
3777
      $date_formats[$module_format['type']][$module_format['format']] = array_merge_recursive($date_formats[$module_format['type']][$module_format['format']], $module_format);
3778
    }
3779
    else {
3780
      // This setting will be overridden later if it already exists in the db.
3781
      $module_format['is_new'] = TRUE;
3782
      $date_formats[$module_format['type']][$module_format['format']] = $module_format;
3783
    }
3784
  }
3785

    
3786
  // Get custom formats added to the database by the end user.
3787
  $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');
3788
  foreach ($result as $record) {
3789
    // If this date type isn't set, initialise the array.
3790
    if (!isset($date_formats[$record->type])) {
3791
      $date_formats[$record->type] = array();
3792
    }
3793
    $format = (array) $record;
3794
    $format['is_new'] = FALSE; // It's in the db, so override this setting.
3795
    // If this format not already present, add it to the array.
3796
    if (!isset($date_formats[$record->type][$record->format])) {
3797
      $format['module'] = '';
3798
      $format['locales'] = array($record->language);
3799
      $date_formats[$record->type][$record->format] = $format;
3800
    }
3801
    // Format already present, so merge in settings.
3802
    else {
3803
      if (!empty($record->language)) {
3804
        $format['locales'] = array_merge($date_formats[$record->type][$record->format]['locales'], array($record->language));
3805
      }
3806
      $date_formats[$record->type][$record->format] = array_merge($date_formats[$record->type][$record->format], $format);
3807
    }
3808
  }
3809

    
3810
  // Allow other modules to modify these formats.
3811
  drupal_alter('date_formats', $date_formats);
3812

    
3813
  return $date_formats;
3814
}
3815

    
3816
/**
3817
 * Saves a date type to the database.
3818
 *
3819
 * @param $type
3820
 *   A date type array containing the following keys:
3821
 *   - type: The machine-readable name of the date type.
3822
 *   - title: The human-readable name of the date type.
3823
 *   - locked: A boolean indicating whether or not this date type should be
3824
 *     configurable from the user interface.
3825
 *   - is_new: A boolean indicating whether or not this date type is as of yet
3826
 *     unsaved in the database.
3827
 */
3828
function system_date_format_type_save($type) {
3829
  $info = array();
3830
  $info['type'] = $type['type'];
3831
  $info['title'] = $type['title'];
3832
  $info['locked'] = $type['locked'];
3833

    
3834
  // Update date_format table.
3835
  if (!empty($type['is_new'])) {
3836
    drupal_write_record('date_format_type', $info);
3837
  }
3838
  else {
3839
    drupal_write_record('date_format_type', $info, 'type');
3840
  }
3841
}
3842

    
3843
/**
3844
 * Deletes a date type from the database.
3845
 *
3846
 * @param $type
3847
 *   The machine-readable name of the date type.
3848
 */
3849
function system_date_format_type_delete($type) {
3850
  db_delete('date_formats')
3851
    ->condition('type', $type)
3852
    ->execute();
3853
  db_delete('date_format_type')
3854
    ->condition('type', $type)
3855
    ->execute();
3856
  db_delete('date_format_locale')
3857
    ->condition('type', $type)
3858
    ->execute();
3859
}
3860

    
3861
/**
3862
 * Saves a date format to the database.
3863
 *
3864
 * @param $date_format
3865
 *   A date format array containing the following keys:
3866
 *   - type: The name of the date type this format is associated with.
3867
 *   - format: The PHP date format string.
3868
 *   - locked: A boolean indicating whether or not this format should be
3869
 *     configurable from the user interface.
3870
 * @param $dfid
3871
 *   If set, replace the existing date format having this ID with the
3872
 *   information specified in $date_format.
3873
 *
3874
 * @see system_get_date_types()
3875
 * @see http://php.net/date
3876
 */
3877
function system_date_format_save($date_format, $dfid = 0) {
3878
  $info = array();
3879
  $info['dfid'] = $dfid;
3880
  $info['type'] = $date_format['type'];
3881
  $info['format'] = $date_format['format'];
3882
  $info['locked'] = $date_format['locked'];
3883

    
3884
  // Update date_format table.
3885
  if (!empty($date_format['is_new'])) {
3886
    drupal_write_record('date_formats', $info);
3887
  }
3888
  else {
3889
    $keys = ($dfid ? array('dfid') : array('format', 'type'));
3890
    drupal_write_record('date_formats', $info, $keys);
3891
  }
3892

    
3893
  // Retrieve an array of language objects for enabled languages.
3894
  $languages = language_list('enabled');
3895
  // This list is keyed off the value of $language->enabled; we want the ones
3896
  // that are enabled (value of 1).
3897
  $languages = $languages[1];
3898

    
3899
  $locale_format = array();
3900
  $locale_format['type'] = $date_format['type'];
3901
  $locale_format['format'] = $date_format['format'];
3902

    
3903
  // Check if the suggested language codes are configured and enabled.
3904
  if (!empty($date_format['locales'])) {
3905
    foreach ($date_format['locales'] as $langcode) {
3906
      // Only proceed if language is enabled.
3907
      if (isset($languages[$langcode])) {
3908
        $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();
3909
        if (!$is_existing) {
3910
          $locale_format['language'] = $langcode;
3911
          drupal_write_record('date_format_locale', $locale_format);
3912
        }
3913
      }
3914
    }
3915
  }
3916
}
3917

    
3918
/**
3919
 * Deletes a date format from the database.
3920
 *
3921
 * @param $dfid
3922
 *   The date format ID.
3923
 */
3924
function system_date_format_delete($dfid) {
3925
  db_delete('date_formats')
3926
    ->condition('dfid', $dfid)
3927
    ->execute();
3928
}
3929

    
3930
/**
3931
 * Implements hook_archiver_info().
3932
 */
3933
function system_archiver_info() {
3934
  $archivers['tar'] = array(
3935
    'class' => 'ArchiverTar',
3936
    'extensions' => array('tar', 'tgz', 'tar.gz', 'tar.bz2'),
3937
  );
3938
  if (function_exists('zip_open')) {
3939
    $archivers['zip'] = array(
3940
      'class' => 'ArchiverZip',
3941
      'extensions' => array('zip'),
3942
    );
3943
  }
3944
  return $archivers;
3945
}
3946

    
3947
/**
3948
 * Returns HTML for a confirmation form.
3949
 *
3950
 * By default this does not alter the appearance of a form at all,
3951
 * but is provided as a convenience for themers.
3952
 *
3953
 * @param $variables
3954
 *   An associative array containing:
3955
 *   - form: A render element representing the form.
3956
 *
3957
 * @ingroup themeable
3958
 */
3959
function theme_confirm_form($variables) {
3960
  return drupal_render_children($variables['form']);
3961
}
3962

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

    
3979
/**
3980
 * Returns HTML for an exposed filter form.
3981
 *
3982
 * @param $variables
3983
 *   An associative array containing:
3984
 *   - form: An associative array containing the structure of the form.
3985
 *
3986
 * @return
3987
 *   A string containing an HTML-formatted form.
3988
 *
3989
 * @ingroup themeable
3990
 */
3991
function theme_exposed_filters($variables) {
3992
  $form = $variables['form'];
3993
  $output = '';
3994

    
3995
  if (isset($form['current'])) {
3996
    $items = array();
3997
    foreach (element_children($form['current']) as $key) {
3998
      $items[] = drupal_render($form['current'][$key]);
3999
    }
4000
    $output .= theme('item_list', array('items' => $items, 'attributes' => array('class' => array('clearfix', 'current-filters'))));
4001
  }
4002

    
4003
  $output .= drupal_render_children($form);
4004

    
4005
  return '<div class="exposed-filters">' . $output . '</div>';
4006
}
4007

    
4008
/**
4009
 * Implements hook_admin_paths().
4010
 */
4011
function system_admin_paths() {
4012
  $paths = array(
4013
    'admin' => TRUE,
4014
    'admin/*' => TRUE,
4015
    'batch' => TRUE,
4016
    // This page should not be treated as administrative since it outputs its
4017
    // own content (outside of any administration theme).
4018
    'admin/reports/status/php' => FALSE,
4019
  );
4020
  return $paths;
4021
}