Projet

Général

Profil

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

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

1
<?php
2

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

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

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

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

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

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

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

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

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

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

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

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

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

    
75
  switch ($path) {
76
    case 'admin/help#system':
77
      $output = '';
78
      $output .= '<h3>' . t('About') . '</h3>';
79
      $output .= '<p>' . t('The System module is integral to the site, and provides basic but extensible functionality for use by other modules and themes. Some integral elements of Drupal are contained in and managed by the System module, including caching, enabling and disabling modules and themes, preparing and displaying the administrative page, and configuring fundamental site settings. A number of key system maintenance operations are also part of the System module. For more information, see the online handbook entry for <a href="@system">System module</a>.', array('@system' => 'http://drupal.org/documentation/modules/system')) . '</p>';
80
      $output .= '<h3>' . t('Uses') . '</h3>';
81
      $output .= '<dl>';
82
      $output .= '<dt>' . t('Managing modules') . '</dt>';
83
      $output .= '<dd>' . t('The System module allows users with the appropriate permissions to enable and disable modules on the <a href="@modules">Modules administration page</a>. Drupal comes with a number of core modules, and each module provides a discrete set of features and may be enabled or disabled depending on the needs of the site. Many additional modules contributed by members of the Drupal community are available for download at the <a href="@drupal-modules">Drupal.org module page</a>.', array('@modules' => url('admin/modules'), '@drupal-modules' => 'http://drupal.org/project/modules')) . '</dd>';
84
      $output .= '<dt>' . t('Managing themes') . '</dt>';
85
      $output .= '<dd>' . t('The System module allows users with the appropriate permissions to enable and disable themes on the <a href="@themes">Appearance administration page</a>. Themes determine the design and presentation of your site. Drupal comes packaged with several core themes, and additional contributed themes are available at the <a href="@drupal-themes">Drupal.org theme page</a>.', array('@themes' => url('admin/appearance'), '@drupal-themes' => 'http://drupal.org/project/themes')) . '</dd>';
86
      $output .= '<dt>' . t('Managing caching') . '</dt>';
87
      $output .= '<dd>' . t("The System module allows users with the appropriate permissions to manage caching on the <a href='@cache-settings'>Performance settings page</a>. Drupal has a robust caching system that allows the efficient re-use of previously-constructed web pages and web page components. Pages requested by anonymous users are stored in a compressed format; depending on your site configuration and the amount of your web traffic tied to anonymous visitors, the caching system may significantly increase the speed of your site.", array('@cache-settings' => url('admin/config/development/performance'))) . '</dd>';
88
      $output .= '<dt>' . t('Performing system maintenance') . '</dt>';
89
      $output .= '<dd>' . t('In order for the site and its modules to continue to operate well, a set of routine administrative operations must run on a regular basis. The System module manages this task by making use of a system cron job. You can verify the status of cron tasks by visiting the <a href="@status">Status report page</a>. For more information, see the online handbook entry for <a href="@handbook">configuring cron jobs</a>. You can set up cron job by visiting <a href="@cron">Cron configuration</a> page', array('@status' => url('admin/reports/status'), '@handbook' => 'http://drupal.org/cron', '@cron' => url('admin/config/system/cron'))) . '</dd>';
90
      $output .= '<dt>' . t('Configuring basic site settings') . '</dt>';
91
      $output .= '<dd>' . t('The System module also handles basic configuration options for your site, including <a href="@date-time-settings">Date and time settings</a>, <a href="@file-system">File system settings</a>, <a href="@clean-url">Clean URL support</a>, <a href="@site-info">Site name and other information</a>, and a <a href="@maintenance-mode">Maintenance mode</a> for taking your site temporarily offline.', array('@date-time-settings' => url('admin/config/regional/date-time'), '@file-system' => url('admin/config/media/file-system'), '@clean-url' => url('admin/config/search/clean-urls'), '@site-info' => url('admin/config/system/site-information'), '@maintenance-mode' => url('admin/config/development/maintenance'))) . '</dd>';
92
      $output .= '<dt>' . t('Configuring actions') . '</dt>';
93
      $output .= '<dd>' . t('Actions are individual tasks that the system can do, such as unpublishing a piece of content or banning a user. Modules, such as the <a href="@trigger-help">Trigger module</a>, can fire these actions when certain system events happen; for example, when a new post is added or when a user logs in. Modules may also provide additional actions. Visit the <a href="@actions">Actions page</a> to configure actions.', array('@trigger-help' => url('admin/help/trigger'), '@actions' => url('admin/config/system/actions'))) . '</dd>';
94
      $output .= '</dl>';
95
      return $output;
96
    case 'admin/index':
97
      return '<p>' . t('This page shows you all available administration tasks for each module.') . '</p>';
98
    case 'admin/appearance':
99
      $output = '<p>' . t('Set and configure the default theme for your website.  Alternative <a href="@themes">themes</a> are available.', array('@themes' => 'http://drupal.org/project/themes')) . '</p>';
100
      return $output;
101
    case 'admin/appearance/settings/' . $arg[3]:
102
      $theme_list = list_themes();
103
      $theme = $theme_list[$arg[3]];
104
      return '<p>' . t('These options control the display settings for the %name theme. When your site is displayed using this theme, these settings will be used.', array('%name' => $theme->info['name'])) . '</p>';
105
    case 'admin/appearance/settings':
106
      return '<p>' . t('These options control the default display settings for your entire site, across all themes. Unless they have been overridden by a specific theme, these settings will be used.') . '</p>';
107
    case 'admin/modules':
108
      $output = '<p>' . t('Download additional <a href="@modules">contributed modules</a> to extend Drupal\'s functionality.', array('@modules' => 'http://drupal.org/project/modules')) . '</p>';
109
      if (module_exists('update')) {
110
        if (update_manager_access()) {
111
          $output .= '<p>' . t('Regularly review and install <a href="@updates">available updates</a> to maintain a secure and current site. Always run the <a href="@update-php">update script</a> each time a module is updated.', array('@update-php' => $base_url . '/update.php', '@updates' => url('admin/reports/updates'))) . '</p>';
112
        }
113
        else {
114
          $output .= '<p>' . t('Regularly review <a href="@updates">available updates</a> to maintain a secure and current site. Always run the <a href="@update-php">update script</a> each time a module is updated.', array('@update-php' => $base_url . '/update.php', '@updates' => url('admin/reports/updates'))) . '</p>';
115
        }
116
      }
117
      else {
118
        $output .= '<p>' . t('Regularly review available updates to maintain a secure and current site. Always run the <a href="@update-php">update script</a> each time a module is updated. Enable the Update manager module to update and install modules and themes.', array('@update-php' => $base_url . '/update.php')) . '</p>';
119
      }
120
      return $output;
121
    case 'admin/modules/uninstall':
122
      return '<p>' . t('The uninstall process removes all data related to a module. To uninstall a module, you must first disable it on the main <a href="@modules">Modules page</a>.', array('@modules' => url('admin/modules'))) . '</p>';
123
    case 'admin/structure/block/manage':
124
      if ($arg[4] == 'system' && $arg[5] == 'powered-by') {
125
        return '<p>' . t('The <em>Powered by Drupal</em> block is an optional link to the home page of the Drupal project. While there is absolutely no requirement that sites feature this link, it may be used to show support for Drupal.') . '</p>';
126
      }
127
      break;
128
    case 'admin/config/development/maintenance':
129
      global $user;
130
      if ($user->uid == 1) {
131
        return '<p>' . t('If you are upgrading to a newer version of Drupal or upgrading contributed modules or themes, you may need to run the <a href="@update-php">update script</a>.', array('@update-php' => $base_url . '/update.php')) . '</p>';
132
      }
133
      break;
134
    case 'admin/config/system/actions':
135
    case 'admin/config/system/actions/manage':
136
      $output = '';
137
      $output .= '<p>' . t('There are two types of actions: simple and advanced. Simple actions do not require any additional configuration, and are listed here automatically. Advanced actions need to be created and configured before they can be used, because they have options that need to be specified; for example, sending an e-mail to a specified address, or unpublishing content containing certain words. To create an advanced action, select the action from the drop-down list in the advanced action section below and click the <em>Create</em> button.') . '</p>';
138
      if (module_exists('trigger')) {
139
        $output .= '<p>' . t('You may proceed to the <a href="@url">Triggers</a> page to assign these actions to system events.', array('@url' => url('admin/structure/trigger'))) . '</p>';
140
      }
141
      return $output;
142
    case 'admin/config/system/actions/configure':
143
      return t('An advanced action offers additional configuration options which may be filled out below. Changing the <em>Description</em> field is recommended, in order to better identify the precise action taking place. This description will be displayed in modules such as the Trigger module when assigning actions to system events, so it is best if it is as descriptive as possible (for example, "Send e-mail to Moderation Team" rather than simply "Send e-mail").');
144
    case 'admin/config/people/ip-blocking':
145
      return '<p>' . t('IP addresses listed here are blocked from your site. Blocked addresses are completely forbidden from accessing the site and instead see a brief message explaining the situation.') . '</p>';
146
    case 'admin/reports/status':
147
      return '<p>' . t("Here you can find a short overview of your site's parameters as well as any problems detected with your installation. It may be useful to copy and paste this information into support requests filed on drupal.org's support forums and project issue queues.") . '</p>';
148
  }
149
}
150

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

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

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

    
270
  return $hooks;
271
}
272

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

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

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

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

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

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

    
514
  return $types;
515
}
516

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1645
  return $libraries;
1646
}
1647

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

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

    
1677
  return $wrappers;
1678
}
1679

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2204
  return $form_element;
2205
}
2206

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

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

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

    
2248
      $updated_fields = array();
2249

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2436
  return $modules;
2437
}
2438

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

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

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

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

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

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

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

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

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

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

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

    
2601
  return $themes;
2602
}
2603

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

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

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

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

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

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

    
2705
  return $list;
2706
}
2707

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

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

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

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

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

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

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

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

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

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

    
2862
  drupal_set_title($question, PASS_THROUGH);
2863

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

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

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

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

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

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

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

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

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

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

    
3003
  return $admin_tasks;
3004
}
3005

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3280
/**
3281
 * Settings form for system_goto_action().
3282
 */
3283
function system_goto_action_form($context) {
3284
  $form['url'] = array(
3285
    '#type' => 'textfield',
3286
    '#title' => t('URL'),
3287
    '#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.'),
3288
    '#default_value' => isset($context['url']) ? $context['url'] : '',
3289
    '#required' => TRUE,
3290
  );
3291
  return $form;
3292
}
3293

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

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

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

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

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

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

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

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

    
3407
  return $output;
3408
}
3409

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

    
3423
/**
3424
 * Attempts to get a file using drupal_http_request and to store it locally.
3425
 *
3426
 * @param string $url
3427
 *   The URL of the file to grab.
3428
 * @param string $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
 * @param bool $managed
3436
 *   If this is set to TRUE, the file API hooks will be invoked and the file is
3437
 *   registered in the database.
3438
 * @param int $replace
3439
 *   Replace behavior when the destination file already exists:
3440
 *   - FILE_EXISTS_REPLACE: Replace the existing file.
3441
 *   - FILE_EXISTS_RENAME: Append _{incrementing number} until the filename is
3442
 *     unique.
3443
 *   - FILE_EXISTS_ERROR: Do nothing and return FALSE.
3444
 *
3445
 * @return mixed
3446
 *   One of these possibilities:
3447
 *   - If it succeeds and $managed is FALSE, the location where the file was
3448
 *     saved.
3449
 *   - If it succeeds and $managed is TRUE, a \Drupal\file\FileInterface
3450
 *     object which describes the file.
3451
 *   - If it fails, FALSE.
3452
 */
3453
function system_retrieve_file($url, $destination = NULL, $managed = FALSE, $replace = FILE_EXISTS_RENAME) {
3454
  $parsed_url = parse_url($url);
3455
  if (!isset($destination)) {
3456
    $path = file_build_uri(drupal_basename($parsed_url['path']));
3457
  }
3458
  else {
3459
    if (is_dir(drupal_realpath($destination))) {
3460
      // Prevent URIs with triple slashes when glueing parts together.
3461
      $path = str_replace('///', '//', "$destination/") . drupal_basename($parsed_url['path']);
3462
    }
3463
    else {
3464
      $path = $destination;
3465
    }
3466
  }
3467
  $result = drupal_http_request($url);
3468
  if ($result->code != 200) {
3469
    drupal_set_message(t('HTTP error @errorcode occurred when trying to fetch @remote.', array('@errorcode' => $result->code, '@remote' => $url)), 'error');
3470
    return FALSE;
3471
  }
3472
  $local = $managed ? file_save_data($result->data, $path, $replace) : file_unmanaged_save_data($result->data, $path, $replace);
3473
  if (!$local) {
3474
    drupal_set_message(t('@remote could not be saved to @path.', array('@remote' => $url, '@path' => $path)), 'error');
3475
  }
3476

    
3477
  return $local;
3478
}
3479

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

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

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

    
3534
  if (!isset($types)) {
3535
    $types = _system_date_format_types_build();
3536
  }
3537

    
3538
  return $type ? (isset($types[$type]) ? $types[$type] : FALSE) : $types;
3539
}
3540

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

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

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

    
3588
  if (!isset($date_formats)) {
3589
    $date_formats = _system_date_formats_build();
3590
  }
3591

    
3592
  return $type ? (isset($date_formats[$type]) ? $date_formats[$type] : FALSE) : $date_formats;
3593
}
3594

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

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

    
3619
  foreach ($date_formats as $type => $formats) {
3620
    foreach ($formats as $format => $info) {
3621
      system_date_format_save($info);
3622
    }
3623
  }
3624

    
3625
  // Rebuild configured date formats locale list.
3626
  drupal_static_reset('system_date_format_locale');
3627
  system_date_format_locale();
3628

    
3629
  _system_date_formats_build();
3630
}
3631

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

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

    
3662
  if ($type && $langcode && !empty($formats[$langcode][$type])) {
3663
    return $formats[$langcode][$type];
3664
  }
3665
  elseif ($langcode && !empty($formats[$langcode])) {
3666
    return $formats[$langcode];
3667
  }
3668

    
3669
  return FALSE;
3670
}
3671

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

    
3690
  // Get list of modules that implement hook_date_format_types().
3691
  $modules = module_implements('date_format_types');
3692

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

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

    
3726
  // Allow other modules to modify these date types.
3727
  drupal_alter('date_format_types', $types);
3728

    
3729
  return $types;
3730
}
3731

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

    
3755
  // First handle hook_date_format_types().
3756
  $types = _system_date_format_types_build();
3757
  foreach ($types as $type => $info) {
3758
    system_date_format_type_save($info);
3759
  }
3760

    
3761
  // Get formats supplied by various contrib modules.
3762
  $module_formats = module_invoke_all('date_formats');
3763

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

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

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

    
3813
  // Allow other modules to modify these formats.
3814
  drupal_alter('date_formats', $date_formats);
3815

    
3816
  return $date_formats;
3817
}
3818

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

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

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

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

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

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

    
3902
  $locale_format = array();
3903
  $locale_format['type'] = $date_format['type'];
3904
  $locale_format['format'] = $date_format['format'];
3905

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

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

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

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

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

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

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

    
4006
  $output .= drupal_render_children($form);
4007

    
4008
  return '<div class="exposed-filters">' . $output . '</div>';
4009
}
4010

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