Code coverage for /20080809/modules/system/system.module

Line #Times calledCode
1
<?php
2
// $Id: system.module,v 1.612 2008/08/02 19:01:02 dries Exp $
3
4
/**
5
 * @file
6
 * Configuration system that lets administrators modify the workings of the
site.
7
 */
8
9
/**
10
 * The current system version.
11
 */
122027
define('VERSION', '7.0-dev');
13
14
/**
15
 * Core API compatibility.
16
 */
172027
define('DRUPAL_CORE_COMPATIBILITY', '7.x');
18
19
/**
20
 * Minimum supported version of PHP.
21
 */
222027
define('DRUPAL_MINIMUM_PHP',    '5.2.0');
23
24
/**
25
 * Minimum recommended value of PHP memory_limit.
26
 */
272027
define('DRUPAL_MINIMUM_PHP_MEMORY_LIMIT',    '16M');
28
29
/**
30
 * Minimum supported version of MySQL, if it is used.
31
 */
322027
define('DRUPAL_MINIMUM_MYSQL',  '5.0');
33
34
/**
35
 * Minimum supported version of PostgreSQL, if it is used.
36
 */
372027
define('DRUPAL_MINIMUM_PGSQL',  '8.1');
38
39
/**
40
 * Maximum age of temporary files in seconds.
41
 */
422027
define('DRUPAL_MAXIMUM_TEMP_FILE_AGE', 1440);
43
44
/**
45
 * Implementation of hook_help().
46
 */
472027
function system_help($path, $arg) {
481491
  global $base_url;
49
50
  switch ($path) {
511491
    case 'admin/help#system':
5211
      $output = '<p>' . t('The system module is at the foundation of your
Drupal website, 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 or disabling
of 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.') . '</p>';
5311
      $output .= '<p>' . t('The system module provides:') . '</p>';
5411
      $output .= '<ul><li>' . t('support for enabling and disabling <a
href="@modules">modules</a>. Drupal comes packaged with a number of core
modules; each module provides a discrete set of features and may be enabled
depending on the needs of your site. A wide array of 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/build/modules'), '@drupal-modules' =>
'http://drupal.org/project/modules')) . '</li>';
5511
      $output .= '<li>' . t('support for enabling and disabling <a
href="@themes">themes</a>, which 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/build/themes'),
'@drupal-themes' => 'http://drupal.org/project/themes')) . '</li>';
5611
      $output .= '<li>' . t('a robust <a href="@cache-settings">caching
system</a> that allows the efficient re-use of previously-constructed web
pages and web page components. Drupal stores the pages requested by
anonymous users in a compressed format; depending on your site
configuration and the amount of your web traffic tied to anonymous
visitors, Drupal\'s caching system may significantly increase the speed of
your site.', array('@cache-settings' => url('admin/settings/performance')))
. '</li>';
5711
      $output .= '<li>' . t('a set of routine administrative operations
that rely on a correctly-configured <a href="@cron">cron maintenance
task</a> to run automatically. A number of other modules, including the
feed aggregator, and search also rely on <a href="@cron">cron maintenance
tasks</a>. For more information, see the online handbook entry for <a
href="@handbook">configuring cron jobs</a>.', array('@cron' =>
url('admin/reports/status'), '@handbook' => 'http://drupal.org/cron')) .
'</li>';
5811
      $output .= '<li>' . t('basic configuration options for your site,
including <a href="@date-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="@site-maintenance">site maintenance</a> function for taking
your site temporarily offline.', array('@date-settings' =>
url('admin/settings/date-time'), '@file-system' =>
url('admin/settings/file-system'), '@clean-url' =>
url('admin/settings/clean-urls'), '@site-info' =>
url('admin/settings/site-information'), '@site-maintenance' =>
url('admin/settings/site-maintenance'))) . '</li></ul>';
5911
      $output .= '<p>' . t('For more information, see the online handbook
entry for <a href="@system">System module</a>.', array('@system' =>
'http://drupal.org/handbook/modules/system/')) . '</p>';
6011
      return $output;
611489
    case 'admin':
622
      return '<p>' . t('Welcome to the administration section. Here you may
control how your site functions.') . '</p>';
631489
    case 'admin/by-module':
642
      return '<p>' . t('This page shows you all available administration
tasks for each module.') . '</p>';
651489
    case 'admin/build/themes':
660
      $output = '<p>' . t('Select which themes are available to your users
and specify the default theme. To configure site-wide display settings,
click the "configure" task above. Alternatively, to override these settings
in a specific theme, click the "configure" link for that theme. Note that
different themes may have different regions available for displaying
content; for consistency in presentation, you may wish to enable only one
theme.') . '</p>';
670
      $output .= '<p>' . t('To change the appearance of your site, a number
of <a href="@themes">contributed themes</a> are available.',
array('@themes' => 'http://drupal.org/project/themes')) . '</p>';
680
      return $output;
691489
    case 'admin/build/themes/settings/' . $arg[4]:
700
      $reference = explode('.', $arg[4], 2);
710
      $theme = array_pop($reference);
720
      return '<p>' . t('These options control the display settings for the
<code>%template</code> theme. When your site is displayed using this theme,
these settings will be used. By clicking "Reset to defaults," you can
choose to use the <a href="@global">global settings</a> for this theme.',
array('%template' => $theme, '@global' =>
url('admin/build/themes/settings'))) . '</p>';
731489
    case 'admin/build/themes/settings':
740
      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>';
751489
    case 'admin/build/modules':
766
      $output = '<p>' . t('Modules are plugins that extend Drupal\'s core
functionality. Enable modules by selecting the <em>Enabled</em> checkboxes
below and clicking the <em>Save configuration</em> button. Once a module is
enabled, new <a href="@permissions">permissions</a> may be available.)',
array('@permissions' => url('admin/user/permissions'))) . '</p>';
776
      $output .= '<p>' . t('It is important that <a
href="@update-php">update.php</a> is run every time a module is updated to
a newer version.', array('@update-php' => $base_url . '/update.php')) .
'</p>';
786
      $output .= '<p>' . t('You can find all administration tasks belonging
to a particular module on the <a href="@by-module">administration by module
page</a>.', array('@by-module' => url('admin/by-module'))) . '</p>';
796
      $output .= '<p>' . t('To extend the functionality of your site, a
number of <a href="@modules">contributed modules</a> are available.',
array('@modules' => 'http://drupal.org/project/modules')) . '</p>';
806
      return $output;
811489
    case 'admin/build/modules/uninstall':
822
      return '<p>' . t('The uninstall process removes all data related to a
module. To uninstall a module, you must first disable it. Not all modules
support this feature.') . '</p>';
831489
    case 'admin/build/block/configure':
842
      if ($arg[4] == 'system' && $arg[5] == 0) {
850
        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>';
860
      }
872
      break;
881489
    case 'admin/settings/actions':
891489
    case 'admin/settings/actions/manage':
900
      $output = '<p>' . 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 trigger module, 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.') . '</p>';
910
      $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 can do more than simple
actions; for example, send an e-mail to a specified address, or check for
certain words within a piece of content. These actions need to be created
and configured first before they may be used. To create an advanced action,
select the action from the drop-down below and click the <em>Create</em>
button.') . '</p>';
920
      if (module_exists('trigger')) {
930
        $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/build/trigger'))) . '</p>';
940
      }
950
      return $output;
961489
    case 'admin/settings/actions/configure':
970
      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").');
981489
    case 'admin/settings/ip-blocking':
9914
      return '<p>' . t('IP addresses listed here are blocked from your site
before any modules are loaded. You may add IP addresses to the list, or
delete existing entries.') . '</p>';
1001489
    case 'admin/reports/status':
1011
      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>';
1020
  }
1031489
}
104
105
/**
106
 * Implementation of hook_theme().
107
 */
1082027
function system_theme() {
10991
  return array_merge(drupal_common_theme(), array(
110
    'system_theme_select_form' => array(
11191
      'arguments' => array('form' => NULL),
11291
      'file' => 'system.admin.inc',
11391
    ),
114
    'system_themes_form' => array(
11591
      'arguments' => array('form' => NULL),
11691
      'file' => 'system.admin.inc',
11791
    ),
118
    'system_modules_fieldset' => array(
11991
      'arguments' => array('form' => NULL),
12091
      'file' => 'system.admin.inc',
12191
    ),
122
    'system_modules_incompatible' => array(
12391
      'arguments' => array('message' => NULL),
12491
      'file' => 'system.admin.inc',
12591
    ),
126
    'system_modules_uninstall' => array(
12791
      'arguments' => array('form' => NULL),
12891
      'file' => 'system.admin.inc',
12991
    ),
130
    'status_report' => array(
13191
      'arguments' => array('requirements' => NULL),
13291
      'file' => 'system.admin.inc',
13391
    ),
134
    'admin_page' => array(
13591
      'arguments' => array('blocks' => NULL),
13691
      'file' => 'system.admin.inc',
13791
    ),
138
    'admin_block' => array(
13991
      'arguments' => array('block' => NULL),
14091
      'file' => 'system.admin.inc',
14191
    ),
142
    'admin_block_content' => array(
14391
      'arguments' => array('content' => NULL),
14491
      'file' => 'system.admin.inc',
14591
    ),
146
    'system_admin_by_module' => array(
14791
      'arguments' => array('menu_items' => NULL),
14891
      'file' => 'system.admin.inc',
14991
    ),
150
    'system_powered_by' => array(
15191
      'arguments' => array('image_path' => NULL),
15291
    ),
153
    'meta_generator_html' => array(
15491
      'arguments' => array('version' => NULL),
15591
    ),
156
    'meta_generator_header' => array(
15791
      'arguments' => array('version' => NULL),
15891
    ),
15991
    'system_compact_link' => array(),
16091
  ));
1610
}
162
163
/**
164
 * Implementation of hook_perm().
165
 */
1662027
function system_perm() {
167
  return array(
16887
    'administer site configuration' => t('Configure site-wide settings such
as module or theme administration settings.'),
16987
    'access administration pages' => t('View the administration panel and
browse the help system.'),
17087
    'administer actions' => t('Manage the actions defined for your
site.'),
17187
    'access site reports' => t('View reports from system logs and other
status information.'),
17287
    'select different theme' => t('Select a theme other than the default
theme set by the site administrator.'),
17387
    'administer files' => t('Manage user-uploaded files.'),
17487
    'block IP addresses' => t('Block IP addresses from accessing your
site.'),
17587
  );
1760
}
177
178
/**
179
 * Implementation of hook_elements().
180
 */
1812027
function system_elements() {
182
  // Top level form
1831570
  $type['form'] = array(
1841570
    '#method' => 'post',
1851570
    '#action' => request_uri(),
186
  );
187
188
  /**
189
   * Input elements.
190
   */
1911570
  $type['submit'] = array(
1921570
    '#input' => TRUE,
1931570
    '#name' => 'op',
1941570
    '#button_type' => 'submit',
1951570
    '#executes_submit_callback' => TRUE,
1961570
    '#process' => array('form_process_ahah'),
197
  );
198
1991570
  $type['button'] = array(
2001570
    '#input' => TRUE,
2011570
    '#name' => 'op',
2021570
    '#button_type' => 'submit',
2031570
    '#executes_submit_callback' => FALSE,
2041570
    '#process' => array('form_process_ahah'),
205
  );
206
2071570
  $type['image_button'] = array(
2081570
    '#input' => TRUE,
2091570
    '#button_type' => 'submit',
2101570
    '#executes_submit_callback' => TRUE,
2111570
    '#process' => array('form_process_ahah'),
2121570
    '#return_value' => TRUE,
2131570
    '#has_garbage_value' => TRUE,
2141570
    '#src' => NULL,
215
  );
216
2171570
  $type['textfield'] = array(
2181570
    '#input' => TRUE,
2191570
    '#size' => 60,
2201570
    '#maxlength' => 128,
2211570
    '#autocomplete_path' => FALSE,
2221570
    '#process' => array('form_process_ahah'),
223
  );
224
2251570
  $type['password'] = array(
2261570
    '#input' => TRUE,
2271570
    '#size' => 60,
2281570
    '#maxlength' => 128,
2291570
    '#process' => array('form_process_ahah'),
230
  );
231
2321570
  $type['password_confirm'] = array(
2331570
    '#input' => TRUE,
2341570
    '#process' => array('form_process_password_confirm'),
235
  );
236
2371570
  $type['textarea'] = array(
2381570
    '#input' => TRUE,
2391570
    '#cols' => 60,
2401570
    '#rows' => 5,
2411570
    '#resizable' => TRUE,
2421570
    '#process' => array('form_process_ahah'),
243
  );
244
2451570
  $type['radios'] = array(
2461570
    '#input' => TRUE,
2471570
    '#process' => array('form_process_radios'),
248
  );
249
2501570
  $type['radio'] = array(
2511570
    '#input' => TRUE,
2521570
    '#default_value' => NULL,
2531570
    '#process' => array('form_process_ahah'),
254
  );
255
2561570
  $type['checkboxes'] = array(
2571570
    '#input' => TRUE,
2581570
    '#tree' => TRUE,
2591570
    '#process' => array('form_process_checkboxes'),
260
  );
261
2621570
  $type['checkbox'] = array(
2631570
    '#input' => TRUE,
2641570
    '#return_value' => 1,
2651570
    '#process' => array('form_process_ahah'),
266
  );
267
2681570
  $type['select'] = array(
2691570
    '#input' => TRUE,
2701570
    '#size' => 0,
2711570
    '#multiple' => FALSE,
2721570
    '#process' => array('form_process_ahah'),
273
  );
274
2751570
  $type['weight'] = array(
2761570
    '#input' => TRUE,
2771570
    '#delta' => 10,
2781570
    '#default_value' => 0,
2791570
    '#process' => array('form_process_weight', 'form_process_ahah'),
280
  );
281
2821570
  $type['date'] = array(
2831570
    '#input' => TRUE,
2841570
    '#element_validate' => array('date_validate'),
2851570
    '#process' => array('form_process_date'),
286
  );
287
2881570
  $type['file'] = array(
2891570
    '#input' => TRUE,
2901570
    '#size' => 60,
291
  );
292
293
294
  /**
295
   * Form structure.
296
   */
2971570
  $type['item'] = array(
2981570
    '#markup' => '',
299
  );
300
3011570
  $type['hidden'] = array(
3021570
    '#input' => TRUE,
3031570
    '#process' => array('form_process_ahah'),
304
  );
305
3061570
  $type['value'] = array(
3071570
    '#input' => TRUE,
308
  );
309
3101570
  $type['markup'] = array(
3111570
    '#prefix' => '',
3121570
    '#suffix' => '',
313
  );
314
3151570
  $type['fieldset'] = array(
3161570
    '#collapsible' => FALSE,
3171570
    '#collapsed' => FALSE,
3181570
    '#value' => NULL,
3191570
    '#process' => array('form_process_ahah'),
320
  );
321
3221570
  $type['token'] = array(
3231570
    '#input' => TRUE,
324
  );
325
3261570
  return $type;
3270
}
328
329
/**
330
 * Implementation of hook_menu().
331
 */
3322027
function system_menu() {
33385
  $items['system/files'] = array(
33485
    'title' => 'File download',
33585
    'page callback' => 'file_download',
33685
    'access callback' => TRUE,
33785
    'type' => MENU_CALLBACK,
338
  );
33985
  $items['admin'] = array(
34085
    'title' => 'Administer',
34185
    'access arguments' => array('access administration pages'),
34285
    'page callback' => 'system_main_admin_page',
34385
    'weight' => 9,
344
  );
34585
  $items['admin/compact'] = array(
34685
    'title' => 'Compact mode',
34785
    'page callback' => 'system_admin_compact_page',
34885
    'access arguments' => array('access administration pages'),
34985
    'type' => MENU_CALLBACK,
350
  );
35185
  $items['admin/by-task'] = array(
35285
    'title' => 'By task',
35385
    'page callback' => 'system_main_admin_page',
35485
    'access arguments' => array('access administration pages'),
35585
    'type' => MENU_DEFAULT_LOCAL_TASK,
356
  );
35785
  $items['admin/by-module'] = array(
35885
    'title' => 'By module',
35985
    'page callback' => 'system_admin_by_module',
36085
    'access arguments' => array('access administration pages'),
36185
    'type' => MENU_LOCAL_TASK,
36285
    'weight' => 2,
363
  );
36485
  $items['admin/content'] = array(
36585
    'title' => 'Content management',
36685
    'description' => "Manage your site's content.",
36785
    'position' => 'left',
36885
    'weight' => -10,
36985
    'page callback' => 'system_admin_menu_block_page',
37085
    'access arguments' => array('access administration pages'),
371
  );
372
373
  // menu items that are basically just menu blocks
37485
  $items['admin/settings'] = array(
37585
    'title' => 'Site configuration',
37685
    'description' => 'Adjust basic site configuration options.',
37785
    'position' => 'right',
37885
    'weight' => -5,
37985
    'page callback' => 'system_settings_overview',
38085
    'access arguments' => array('access administration pages'),
381
  );
38285
  $items['admin/build'] = array(
38385
    'title' => 'Site building',
38485
    'description' => 'Control how your site looks and feels.',
38585
    'position' => 'right',
38685
    'weight' => -10,
38785
    'page callback' => 'system_admin_menu_block_page',
38885
    'access arguments' => array('access administration pages'),
389
  );
39085
  $items['admin/settings/admin'] = array(
39185
    'title' => 'Administration theme',
39285
    'description' => 'Settings for how your administrative pages should
look.',
39385
    'position' => 'left',
39485
    'page callback' => 'drupal_get_form',
39585
    'page arguments' => array('system_admin_theme_settings'),
39685
    'access arguments' => array('administer site configuration'),
39785
    'block callback' => 'system_admin_theme_settings',
398
  );
399
  // Themes:
40085
  $items['admin/build/themes'] = array(
40185
    'title' => 'Themes',
40285
    'description' => 'Change which theme your site uses or allows users to
set.',
40385
    'page callback' => 'drupal_get_form',
40485
    'page arguments' => array('system_themes_form', NULL),
40585
    'access arguments' => array('administer site configuration'),
406
  );
40785
  $items['admin/build/themes/select'] = array(
40885
    'title' => 'List',
40985
    'description' => 'Select the default theme.',
41085
    'type' => MENU_DEFAULT_LOCAL_TASK,
41185
    'weight' => -1,
412
  );
41385
  $items['admin/build/themes/settings'] = array(
41485
    'title' => 'Configure',
41585
    'page arguments' => array('system_theme_settings'),
41685
    'access arguments' => array('administer site configuration'),
41785
    'type' => MENU_LOCAL_TASK,
418
  );
419
  // Theme configuration subtabs
42085
  $items['admin/build/themes/settings/global'] = array(
42185
    'title' => 'Global settings',
42285
    'type' => MENU_DEFAULT_LOCAL_TASK,
42385
    'weight' => -1,
424
  );
425
42685
  foreach (list_themes() as $theme) {
42785
    $items['admin/build/themes/settings/' . $theme->name] = array(
42885
      'title' => $theme->info['name'],
42985
      'page arguments' => array('system_theme_settings', $theme->name),
43085
      'type' => MENU_LOCAL_TASK,
43185
      'access callback' => '_system_themes_access',
43285
      'access arguments' => array($theme),
433
    );
43485
  }
435
436
  // Modules:
43785
  $items['admin/build/modules'] = array(
43885
    'title' => 'Modules',
43985
    'description' => 'Enable or disable add-on modules for your site.',
44085
    'page callback' => 'drupal_get_form',
44185
    'page arguments' => array('system_modules'),
44285
    'access arguments' => array('administer site configuration'),
443
  );
44485
  $items['admin/build/modules/list'] = array(
44585
    'title' => 'List',
44685
    'type' => MENU_DEFAULT_LOCAL_TASK,
447
  );
44885
  $items['admin/build/modules/list/confirm'] = array(
44985
    'title' => 'List',
45085
    'access arguments' => array('administer site configuration'),
45185
    'type' => MENU_CALLBACK,
452
  );
45385
  $items['admin/build/modules/uninstall'] = array(
45485
    'title' => 'Uninstall',
45585
    'page arguments' => array('system_modules_uninstall'),
45685
    'access arguments' => array('administer site configuration'),
45785
    'type' => MENU_LOCAL_TASK,
458
  );
45985
  $items['admin/build/modules/uninstall/confirm'] = array(
46085
    'title' => 'Uninstall',
46185
    'access arguments' => array('administer site configuration'),
46285
    'type' => MENU_CALLBACK,
463
  );
464
465
  // Actions:
46685
  $items['admin/settings/actions'] = array(
46785
    'title' => 'Actions',
46885
    'description' => 'Manage the actions defined for your site.',
46985
    'access arguments' => array('administer actions'),
470
    'page callback' => 'system_actions_manage'
47185
  );
47285
  $items['admin/settings/actions/manage'] = array(
47385
    'title' => 'Manage actions',
47485
    'description' => 'Manage the actions defined for your site.',
47585
    'page callback' => 'system_actions_manage',
47685
    'type' => MENU_DEFAULT_LOCAL_TASK,
47785
    'weight' => -2,
478
  );
47985
  $items['admin/settings/actions/configure'] = array(
48085
    'title' => 'Configure an advanced action',
48185
    'page callback' => 'drupal_get_form',
48285
    'page arguments' => array('system_actions_configure'),
48385
    'access arguments' => array('administer actions'),
48485
    'type' => MENU_CALLBACK,
485
  );
48685
  $items['admin/settings/actions/delete/%actions'] = array(
48785
    'title' => 'Delete action',
48885
    'description' => 'Delete an action.',
48985
    'page callback' => 'drupal_get_form',
49085
    'page arguments' => array('system_actions_delete_form', 4),
49185
    'access arguments' => array('administer actions'),
49285
    'type' => MENU_CALLBACK,
493
  );
49485
  $items['admin/settings/actions/orphan'] = array(
49585
    'title' => 'Remove orphans',
49685
    'page callback' => 'system_actions_remove_orphans',
49785
    'access arguments' => array('administer actions'),
49885
    'type' => MENU_CALLBACK,
499
  );
500
501
  // IP address blocking.
50285
  $items['admin/settings/ip-blocking'] = array(
50385
    'title' => 'IP address blocking',
50485
    'description' => 'Manage blocked IP addresses.',
50585
    'page callback' => 'system_ip_blocking',
50685
    'access arguments' => array('block IP addresses'),
507
  );
50885
  $items['admin/settings/ip-blocking/%'] = array(
50985
    'title' => 'IP address blocking',
51085
    'description' => 'Manage blocked IP addresses.',
51185
    'page callback' => 'system_ip_blocking',
51285
    'access arguments' => array('block IP addresses'),
51385
    'type' => MENU_CALLBACK,
514
  );
51585
  $items['admin/settings/ip-blocking/delete/%blocked_ip'] = array(
51685
    'title' => 'Delete IP address',
51785
    'page callback' => 'drupal_get_form',
51885
    'page arguments' => array('system_ip_blocking_delete', 4),
51985
    'access arguments' => array('block IP addresses'),
52085
    'type' => MENU_CALLBACK,
521
  );
522
523
  // Settings:
52485
  $items['admin/settings/site-information'] = array(
52585
    'title' => 'Site information',
52685
    'description' => 'Change basic site information, such as the site name,
slogan, e-mail address, mission, front page and more.',
52785
    'page callback' => 'drupal_get_form',
52885
    'page arguments' => array('system_site_information_settings'),
52985
    'access arguments' => array('administer site configuration'),
530
  );
53185
  $items['admin/settings/error-reporting'] = array(
53285
    'title' => 'Error reporting',
53385
    'description' => 'Control how Drupal deals with errors including
403/404 errors as well as PHP error reporting.',
53485
    'page callback' => 'drupal_get_form',
53585
    'page arguments' => array('system_error_reporting_settings'),
53685
    'access arguments' => array('administer site configuration'),
537
  );
53885
  $items['admin/settings/logging'] = array(
53985
    'title' => 'Logging and alerts',
54085
    'description' => "Settings for logging and alerts modules. Various
modules can route Drupal's system events to different destination, such as
syslog, database, email, ...etc.",
54185
    'page callback' => 'system_logging_overview',
54285
    'access arguments' => array('administer site configuration'),
543
  );
54485
  $items['admin/settings/performance'] = array(
54585
    'title' => 'Performance',
54685
    'description' => 'Enable or disable page caching for anonymous users
and set CSS and JS bandwidth optimization options.',
54785
    'page callback' => 'drupal_get_form',
54885
    'page arguments' => array('system_performance_settings'),
54985
    'access arguments' => array('administer site configuration'),
550
  );
55185
  $items['admin/settings/file-system'] = array(
55285
    'title' => 'File system',
55385
    'description' => 'Tell Drupal where to store uploaded files and how
they are accessed.',
55485
    'page callback' => 'drupal_get_form',
55585
    'page arguments' => array('system_file_system_settings'),
55685
    'access arguments' => array('administer site configuration'),
557
  );
55885
  $items['admin/settings/image-toolkit'] = array(
55985
    'title' => 'Image toolkit',
56085
    'description' => 'Choose which image toolkit to use if you have
installed optional toolkits.',
56185
    'page callback' => 'drupal_get_form',
56285
    'page arguments' => array('system_image_toolkit_settings'),
56385
    'access arguments' => array('administer site configuration'),
564
  );
56585
  $items['admin/content/rss-publishing'] = array(
56685
    'title' => 'RSS publishing',
56785
    'description' => 'Configure the number of items per feed and whether
feeds should be titles/teasers/full-text.',
56885
    'page callback' => 'drupal_get_form',
56985
    'page arguments' => array('system_rss_feeds_settings'),
57085
    'access arguments' => array('administer site configuration'),
571
  );
57285
  $items['admin/settings/date-time'] = array(
57385
    'title' => 'Date and time',
57485
    'description' => "Settings for how Drupal displays date and time, as
well as the system's default timezone.",
57585
    'page callback' => 'drupal_get_form',
57685
    'page arguments' => array('system_date_time_settings'),
57785
    'access arguments' => array('administer site configuration'),
578
  );
57985
  $items['admin/settings/date-time/lookup'] = array(
58085
    'title' => 'Date and time lookup',
58185
    'type' => MENU_CALLBACK,
58285
    'page callback' => 'system_date_time_lookup',
58385
    'access arguments' => array('administer site configuration'),
584
  );
58585
  $items['admin/settings/site-maintenance'] = array(
58685
    'title' => 'Site maintenance',
58785
    'description' => 'Take the site offline for maintenance or bring it
back online.',
58885
    'page callback' => 'drupal_get_form',
58985
    'page arguments' => array('system_site_maintenance_settings'),
59085
    'access arguments' => array('administer site configuration'),
591
  );
59285
  $items['admin/settings/clean-urls'] = array(
59385
    'title' => 'Clean URLs',
59485
    'description' => 'Enable or disable clean URLs for your site.',
59585
    'page callback' => 'drupal_get_form',
59685
    'page arguments' => array('system_clean_url_settings'),
59785
    'access arguments' => array('administer site configuration'),
598
  );
59985
  $items['admin/settings/clean-urls/check'] = array(
60085
    'title' => 'Clean URL check',
60185
    'page callback' => 'drupal_json',
60285
    'page arguments' => array(array('status' => TRUE)),
60385
    'access callback' => TRUE,
60485
    'type' => MENU_CALLBACK,
605
  );
606
  // Menu handler to test that drupal_http_request() works locally.
607
  // @see system_check_http_request()
60885
  $items['admin/reports/request-test'] = array(
60985
    'title' => 'Request test',
61085
    'page callback' => 'printf',
61185
    'page arguments' => array('request test'),
61285
    'access callback' => TRUE,
61385
    'type' => MENU_CALLBACK,
614
  );
615
616
  // Reports:
61785
  $items['admin/reports'] = array(
61885
    'title' => 'Reports',
61985
    'description' => 'View reports from system logs and other status
information.',
62085
    'page callback' => 'system_admin_menu_block_page',
62185
    'access arguments' => array('access site reports'),
62285
    'weight' => 5,
62385
    'position' => 'left',
624
  );
62585
  $items['admin/reports/status'] = array(
62685
    'title' => 'Status report',
62785
    'description' => "Get a status report about your site's operation and
any detected problems.",
62885
    'page callback' => 'system_status',
62985
    'weight' => 10,
63085
    'access arguments' => array('administer site configuration'),
631
  );
63285
  $items['admin/reports/status/run-cron'] = array(
63385
    'title' => 'Run cron',
63485
    'page callback' => 'system_run_cron',
63585
    'access arguments' => array('administer site configuration'),
63685
    'type' => MENU_CALLBACK,
637
  );
63885
  $items['admin/reports/status/php'] = array(
63985
    'title' => 'PHP',
64085
    'page callback' => 'system_php',
64185
    'access arguments' => array('administer site configuration'),
64285
    'type' => MENU_CALLBACK,
643
  );
64485
  $items['admin/reports/status/sql'] = array(
64585
    'title' => 'SQL',
64685
    'page callback' => 'system_sql',
64785
    'access arguments' => array('administer site configuration'),
64885
    'type' => MENU_CALLBACK,
649
  );
650
  // Default page for batch operations
65185
  $items['batch'] = array(
65285
    'page callback' => 'system_batch_page',
65385
    'access callback' => TRUE,
65485
    'type' => MENU_CALLBACK,
655
  );
65685
  return $items;
6570
}
658
659
/**
660
 * Retrieve a blocked IP address from the database.
661
 *
662
 * @param $iid integer
663
 *   The ID of the blocked IP address to retrieve.
664
 *
665
 * @return
666
 *   The blocked IP address from the database as an array.
667
 */
6682027
function blocked_ip_load($iid) {
6693
  $blocked_ip = db_fetch_array(db_query("SELECT * FROM {blocked_ips} WHERE
iid = %d", $iid));
6703
  return $blocked_ip;
6710
}
672
673
/**
674
 * Menu item access callback - only admin or enabled themes can be
accessed.
675
 */
6762027
function _system_themes_access($theme) {
6770
  return user_access('administer site configuration') && ($theme->status ||
$theme->name == variable_get('admin_theme', '0'));
6780
}
679
680
/**
681
 * Implementation of hook_init().
682
 */
6832027
function system_init() {
684
  // Use the administrative theme if the user is looking at a page in the
admin/* path.
6852027
  if (arg(0) == 'admin' || (variable_get('node_admin_theme', '0') && arg(0)
== 'node' && (arg(1) == 'add' || arg(2) == 'edit'))) {
686628
    global $custom_theme;
687628
    $custom_theme = variable_get('admin_theme', '0');
688628
    drupal_add_css(drupal_get_path('module', 'system') . '/admin.css',
'module');
689628
  }
690
691
  // Add the CSS for this module.
6922027
  drupal_add_css(drupal_get_path('module', 'system') . '/defaults.css',
'module');
6932027
  drupal_add_css(drupal_get_path('module', 'system') . '/system.css',
'module');
6942027
  drupal_add_css(drupal_get_path('module', 'system') . '/system-menus.css',
'module');
695
696
  // Get the major version
6972027
  list($version,) = explode('.', VERSION);
698
699
  // Emit the META tag in the HTML HEAD section
7002027
  theme('meta_generator_html', $version);
701
702
  // Emit the HTTP Header too
7032027
  theme('meta_generator_header', $version);
7042027
}
705
706
/**
707
 * Implementation of hook_user().
708
 *
709
 * Allows users to individually set their theme and time zone.
710
 */
7112027
function system_user($type, $edit, &$user, $category = NULL) {
7121848
  if ($type == 'form' && $category == 'account') {
71316
    $form['theme_select'] = system_theme_select_form(t('Selecting a
different theme will change the look and feel of the site.'),
isset($edit['theme']) ? $edit['theme'] : NULL, 2);
714
71516
    if (variable_get('configurable_timezones', 1)) {
71616
      $zones = _system_zonelist();
71716
      $form['timezone'] = array(
71816
        '#type' => 'fieldset',
71916
        '#title' => t('Locale settings'),
72016
        '#weight' => 6,
72116
        '#collapsible' => TRUE,
722
      );
72316
      $form['timezone']['timezone'] = array(
72416
        '#type' => 'select',
72516
        '#title' => t('Time zone'),
72616
        '#default_value' => strlen($edit['timezone']) ? $edit['timezone'] :
variable_get('date_default_timezone', 0),
72716
        '#options' => $zones,
72816
        '#description' => t('Select your current local time. Dates and
times throughout this site will be displayed using this time zone.'),
729
      );
73016
    }
731
73216
    return $form;
7330
  }
7341848
}
735
736
/**
737
 * Implementation of hook_block().
738
 *
739
 * Generate a block with a promotional link to Drupal.org.
740
 */
7412027
function system_block($op = 'list', $delta = '', $edit = NULL) {
742
  switch ($op) {
7431497
    case 'list':
74428
      $blocks['powered-by'] = array(
74528
        'info' => t('Powered by Drupal'),
74628
        'weight' => '10',
747
         // Not worth caching.
74828
        'cache' => BLOCK_NO_CACHE,
749
      );
75028
      return $blocks;
7511489
    case 'configure':
752
      // Compile a list of fields to show
7530
      $form['wrapper']['color'] = array(
7540
        '#type' => 'select',
7550
        '#title' => t('Badge color'),
7560
        '#default_value' => variable_get('drupal_badge_color',
'powered-blue'),
7570
        '#options' => array('powered-black' => t('Black'), 'powered-blue'
=> t('Blue'), 'powered-gray' => t('Gray')),
758
      );
7590
      $form['wrapper']['size'] = array(
7600
        '#type' => 'select',
7610
        '#title' => t('Badge size'),
7620
        '#default_value' => variable_get('drupal_badge_size', '80x15'),
7630
        '#options' => array('80x15' => t('Small'), '88x31' => t('Medium'),
'135x42' => t('Large')),
764
      );
7650
      return $form;
7661489
    case 'save':
7670
      variable_set('drupal_badge_color', $edit['color']);
7680
      variable_set('drupal_badge_size', $edit['size']);
7690
      break;
7701489
    case 'view':
7711489
      $image_path = 'misc/' . variable_get('drupal_badge_color',
'powered-blue') . '-' . variable_get('drupal_badge_size', '80x15') .
'.png';
7721489
      $block['subject'] = NULL; // Don't display a title
7731489
      $block['content'] = theme('system_powered_by', $image_path);
7741489
      return $block;
7750
  }
7760
}
777
778
/**
779
 * Provide a single block on the administration overview page.
780
 *
781
 * @param $item
782
 *   The menu item to be displayed.
783
 */
7842027
function system_admin_menu_block($item) {
7852
  $content = array();
7862
  if (!isset($item['mlid'])) {
7870
    $item += db_fetch_array(db_query("SELECT mlid, menu_name FROM
{menu_links} ml WHERE ml.router_path = '%s' AND module = 'system'",
$item['path']));
7880
  }
7892
  $result = db_query("
790
    SELECT m.load_functions, m.to_arg_functions, m.access_callback,
m.access_arguments, m.page_callback, m.page_arguments, m.title,
m.title_callback, m.title_arguments, m.type, m.description, ml.*
791
    FROM {menu_links} ml
792
    LEFT JOIN {menu_router} m ON ml.router_path = m.path
7932
    WHERE ml.plid = %d AND ml.menu_name = '%s' AND hidden = 0",
$item['mlid'], $item['menu_name']);
7942
  while ($item = db_fetch_array($result)) {
7952
    _menu_link_translate($item);
7962
    if (!$item['access']) {
7972
      continue;
7980
    }
799
    // The link 'description' either derived from the hook_menu
'description' or
800
    // entered by the user via menu module is saved as the title
attribute.
8011
    if (!empty($item['localized_options']['attributes']['title'])) {
8021
      $item['description'] =
$item['localized_options']['attributes']['title'];
8031
    }
804
    // Prepare for sorting as in function _menu_tree_check_access().
805
    // The weight is offset so it is always positive, with a uniform
5-digits.
8061
    $content[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' .
$item['mlid']] = $item;
8071
  }
8082
  ksort($content);
8092
  return $content;
8100
}
811
812
/**
813
 * Process admin theme form submissions.
814
 */
8152027
function system_admin_theme_submit($form, &$form_state) {
816
  // If we're changing themes, make sure the theme has its blocks
initialized.
8170
  if ($form_state['values']['admin_theme'] &&
$form_state['values']['admin_theme'] != variable_get('admin_theme', '0'))
{
8180
    $result = db_result(db_query("SELECT COUNT(*) FROM {blocks} WHERE theme
= '%s'", $form_state['values']['admin_theme']));
8190
    if (!$result) {
8200
     
system_initialize_theme_blocks($form_state['values']['admin_theme']);
8210
    }
8220
  }
8230
}
824
825
/**
826
 * Returns a fieldset containing the theme select form.
827
 *
828
 * @param $description
829
 *    description of the fieldset
830
 * @param $default_value
831
 *    default value of theme radios
832
 * @param $weight
833
 *    weight of the fieldset
834
 * @return
835
 *    a form array
836
 */
8372027
function system_theme_select_form($description = '', $default_value = '',
$weight = 0) {
83816
  if (user_access('select different theme')) {
8390
    $enabled = array();
8400
    $themes = list_themes();
841
8420
    foreach ($themes as $theme) {
8430
      if ($theme->status) {
8440
        $enabled[] = $theme;
8450
      }
8460
    }
847
8480
    if (count($enabled) > 1) {
8490
      ksort($enabled);
850
8510
      $form['themes'] = array(
8520
        '#type' => 'fieldset',
8530
        '#title' => t('Theme configuration'),
8540
        '#description' => $description,
8550
        '#collapsible' => TRUE,
856
        '#theme' => 'system_theme_select_form'
8570
      );
858
8590
      foreach ($enabled as $info) {
860
        // For the default theme, revert to an empty string so the user's
theme updates when the site theme is changed.
8610
        $info->key = $info->name == variable_get('theme_default',
'garland') ? '' : $info->name;
862
8630
        $screenshot = NULL;
8640
        $theme_key = $info->name;
8650
        while ($theme_key) {
8660
          if (file_exists($themes[$theme_key]->info['screenshot'])) {
8670
            $screenshot = $themes[$theme_key]->info['screenshot'];
8680
            break;
8690
          }
8700
          $theme_key = isset($themes[$theme_key]->info['base theme']) ?
$themes[$theme_key]->info['base theme'] : NULL;
8710
        }
872
8730
        $screenshot = $screenshot ? theme('image', $screenshot,
t('Screenshot for %theme theme', array('%theme' => $info->name)), '',
array('class' => 'screenshot'), FALSE) : t('no screenshot');
874
8750
        $form['themes'][$info->key]['screenshot'] = array('#markup' =>
$screenshot);
8760
        $form['themes'][$info->key]['description'] = array('#type' =>
'item', '#title' => $info->name, '#markup' => dirname($info->filename) .
($info->name == variable_get('theme_default', 'garland') ? '<br /> <em>' .
t('(site default theme)') . '</em>' : ''));
8770
        $options[$info->key] = '';
8780
      }
879
8800
      $form['themes']['theme'] = array('#type' => 'radios', '#options' =>
$options, '#default_value' => $default_value ? $default_value : '');
8810
      $form['#weight'] = $weight;
8820
      return $form;
8830
    }
8840
  }
88516
}
886
887
/**
888
 * Checks the existence of the directory specified in $form_element. This
889
 * function is called from the system_settings form to check both the
890
 * file_directory_path and file_directory_temp directories. If validation
891
 * fails, the form element is flagged with an error from within the
892
 * file_check_directory function.
893
 *
894
 * @param $form_element
895
 *   The form element containing the name of the directory to check.
896
 */
8972027
function system_check_directory($form_element) {
8980
  file_check_directory($form_element['#value'], FILE_CREATE_DIRECTORY,
$form_element['#parents'][0]);
8990
  return $form_element;
9000
}
901
902
/**
903
 * Retrieves the current status of an array of files in the system table.
904
 *
905
 * @param $files
906
 *   An array of files to check.
907
 * @param $type
908
 *   The type of the files.
909
 */
9102027
function system_get_files_database(&$files, $type) {
911
  // Extract current files from database.
91276
  $result = db_query("SELECT filename, name, type, status, schema_version
FROM {system} WHERE type = '%s'", $type);
91376
  while ($file = db_fetch_object($result)) {
91476
    if (isset($files[$file->name]) && is_object($files[$file->name])) {
91576
      $file->old_filename = $file->filename;
91676
      foreach ($file as $key => $value) {
91776
        if (!isset($files[$file->name]) ||
!isset($files[$file->name]->$key)) {
91876
          $files[$file->name]->$key = $value;
91976
        }
92076
      }
92176
    }
92276
  }
92376
}
924
925
/**
926
 * Prepare defaults for themes.
927
 *
928
 * @return
929
 *   An array of default themes settings.
930
 */
9312027
function system_theme_default() {
932
  return array(
933
    'regions' => array(
93462
      'left' => 'Left sidebar',
93562
      'right' => 'Right sidebar',
93662
      'content' => 'Content',
93762
      'header' => 'Header',
93862
      'footer' => 'Footer',
93962
    ),
94062
    'description' => '',
941
    'features' => array(
94262
      'comment_user_picture',
94362
      'favicon',
94462
      'mission',
94562
      'logo',
94662
      'name',
94762
      'node_user_picture',
94862
      'search',
94962
      'slogan',
95062
      'main_menu',
95162
      'secondary_menu',
95262
    ),
953
    'stylesheets' => array(
95462
      'all' => array('style.css')
95562
    ),
95662
    'scripts' => array('script.js'),
95762
    'screenshot' => 'screenshot.png',
95862
    'php' => DRUPAL_MINIMUM_PHP,
95962
  );
9600
}
961
962
/**
963
 * Collect data about all currently available themes.
964
 *
965
 * @return
966
 *   Array of all available themes and their data.
967
 */
9682027
function system_theme_data() {
969
  // Scan the installation theme .info files and their engines.
97062
  $themes = _system_theme_data();
971
972
  // Extract current files from database.
97362
  system_get_files_database($themes, 'theme');
974
97562
  db_query("DELETE FROM {system} WHERE type = 'theme'");
976
97762
  foreach ($themes as $theme) {
97862
    if (!isset($theme->owner)) {
97962
      $theme->owner = '';
98062
    }
981
98262
    db_query("INSERT INTO {system} (name, owner, info, type, filename,
status, bootstrap) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d)",
$theme->name, $theme->owner, serialize($theme->info), 'theme',
$theme->filename, isset($theme->status) ? $theme->status : 0, 0);
98362
  }
984
98562
  return $themes;
9860
}
987
988
/**
989
 * Helper function to scan and collect theme .info data and their engines.
990
 *
991
 * @return
992
 *   An associative array of themes information.
993
 */
9942027
function _system_theme_data() {
99562
  static $themes_info = array();
996
99762
  if (empty($themes_info)) {
998
    // Find themes
99962
    $themes = drupal_system_listing('\.info$', 'themes');
1000
    // Find theme engines
100162
    $engines = drupal_system_listing('\.engine$', 'themes/engines');
1002
100362
    $defaults = system_theme_default();
1004
100562
    $sub_themes = array();
1006
    // Read info files for each theme
100762
    foreach ($themes as $key => $theme) {
100862
      $themes[$key]->info = drupal_parse_info_file($theme->filename) +
$defaults;
1009
1010
      // Invoke hook_system_info_alter() to give installed modules a chance
to
1011
      // modify the data in the .info files if necessary.
101262
      drupal_alter('system_info', $themes[$key]->info, $themes[$key]);
1013
101462
      if (!empty($themes[$key]->info['base theme'])) {
101562
        $sub_themes[] = $key;
101662
      }
101762
      if (empty($themes[$key]->info['engine'])) {
101862
        $filename = dirname($themes[$key]->filename) . '/' .
$themes[$key]->name . '.theme';
101962
        if (file_exists($filename)) {
102062
          $themes[$key]->owner = $filename;
102162
          $themes[$key]->prefix = $key;
102262
        }
102362
      }
1024
      else {
102562
        $engine = $themes[$key]->info['engine'];
102662
        if (isset($engines[$engine])) {
102762
          $themes[$key]->owner = $engines[$engine]->filename;
102862
          $themes[$key]->prefix = $engines[$engine]->name;
102962
          $themes[$key]->template = TRUE;
103062
        }
1031
      }
1032
1033
      // Give the stylesheets proper path information.
103462
      $pathed_stylesheets = array();
103562
      foreach ($themes[$key]->info['stylesheets'] as $media =>
$stylesheets) {
103662
        foreach ($stylesheets as $stylesheet) {
103762
          $pathed_stylesheets[$media][$stylesheet] =
dirname($themes[$key]->filename) . '/' . $stylesheet;
103862
        }
103962
      }
104062
      $themes[$key]->info['stylesheets'] = $pathed_stylesheets;
1041
1042
      // Give the scripts proper path information.
104362
      $scripts = array();
104462
      foreach ($themes[$key]->info['scripts'] as $script) {
104562
        $scripts[$script] = dirname($themes[$key]->filename) . '/' .
$script;
104662
      }
104762
      $themes[$key]->info['scripts'] = $scripts;
1048
      // Give the screenshot proper path information.
104962
      if (!empty($themes[$key]->info['screenshot'])) {
105062
        $themes[$key]->info['screenshot'] =
dirname($themes[$key]->filename) . '/' .
$themes[$key]->info['screenshot'];
105162
      }
105262
    }
1053
1054
    // Now that we've established all our master themes, go back and fill
in
1055
    // data for subthemes.
105662
    foreach ($sub_themes as $key) {
105762
      $base_key = system_find_base_theme($themes, $key);
105862
      if (!$base_key) {
10590
        continue;
10600
      }
1061
      // Copy the 'owner' and 'engine' over if the top level theme uses a
1062
      // theme engine.
106362
      if (isset($themes[$base_key]->owner)) {
106462
        if (isset($themes[$base_key]->info['engine'])) {
106562
          $themes[$key]->info['engine'] =
$themes[$base_key]->info['engine'];
106662
          $themes[$key]->owner = $themes[$base_key]->owner;
106762
          $themes[$key]->prefix = $themes[$base_key]->prefix;
106862
        }
1069
        else {
107062
          $themes[$key]->prefix = $key;
1071
        }
107262
      }
107362
    }
1074
107562
    $themes_info = $themes;
107662
  }
1077
107862
  return $themes_info;
10790
}
1080
1081
/**
1082
 * Recursive function to find the top level base theme. Themes can inherit
1083
 * templates and function implementations from earlier themes.
1084
 *
1085
 * @param $themes
1086
 *   An array of available themes.
1087
 * @param $key
1088
 *   The name of the theme whose base we are looking for.
1089
 * @param $used_keys
1090
 *   A recursion parameter preventing endless loops.
1091
 * @return
1092
 *   Returns the top level parent that has no ancestor or returns NULL if
there isn't a valid parent.
1093
 */
10942027
function system_find_base_theme($themes, $key, $used_keys = array()) {
109562
  $base_key = $themes[$key]->info['base theme'];
1096
  // Does the base theme exist?
109762
  if (!isset($themes[$base_key])) {
10980
    return NULL;
10990
  }
1100
1101
  // Is the base theme itself a child of another theme?
110262
  if (isset($themes[$base_key]->info['base theme'])) {
1103
    // Prevent loops.
11040
    if (!empty($used_keys[$base_key])) {
11050
      return NULL;
11060
    }
11070
    $used_keys[$base_key] = TRUE;
11080
    return system_find_base_theme($themes, $base_key, $used_keys);
11090
  }
1110
  // If we get here, then this is our parent theme.
111162
  return $base_key;
11120
}
1113
1114
/**
1115
 * Get a list of available regions from a specified theme.
1116
 *
1117
 * @param $theme_key
1118
 *   The name of a theme.
1119
 * @return
1120
 *   An array of regions in the form $region['name'] = 'description'.
1121
 */
11222027
function system_region_list($theme_key) {
11231497
  static $list = array();
1124
11251497
  if (!array_key_exists($theme_key, $list)) {
11261497
    $info = unserialize(db_result(db_query("SELECT info FROM {system} WHERE
type = 'theme' AND name = '%s'", $theme_key)));
11271497
    $list[$theme_key] = array_map('t', $info['regions']);
11281497
  }
1129
11301497
  return $list[$theme_key];
11310
}
1132
1133
/**
1134
 * Get the name of the default region for a given theme.
1135
 *
1136
 * @param $theme
1137
 *   The name of a theme.
1138
 * @return
1139
 *   A string that is the region name.
1140
 */
11412027
function system_default_region($theme) {
11420
  $regions = array_keys(system_region_list($theme));
11430
  return isset($regions[0]) ? $regions[0] : '';
11440
}
1145
1146
/**
1147
 * Assign an initial, default set of blocks for a theme.
1148
 *
1149
 * This function is called the first time a new theme is enabled. The new
theme
1150
 * gets a copy of the default theme's blocks, with the difference that if
a
1151
 * particular region isn't available in the new theme, the block is
assigned
1152
 * to the new theme's default region.
1153
 *
1154
 * @param $theme
1155
 *   The name of a theme.
1156
 */
11572027
function system_initialize_theme_blocks($theme) {
1158
  // Initialize theme's blocks if none already registered.
11590
  if (!(db_result(db_query("SELECT COUNT(*) FROM {blocks} WHERE theme =
'%s'", $theme)))) {
11600
    $default_theme = variable_get('theme_default', 'garland');
11610
    $regions = system_region_list($theme);
11620
    $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'",
$default_theme);
11630
    while ($block = db_fetch_array($result)) {
1164
      // If the region isn't supported by the theme, assign the block to
the theme's default region.
11650
      if (!array_key_exists($block['region'], $regions)) {
11660
        $block['region'] = system_default_region($theme);
11670
      }
11680
      db_query("INSERT INTO {blocks} (module, delta, theme, status, weight,
region, visibility, pages, custom, cache) VALUES ('%s', '%s', '%s', %d, %d,
'%s', %d, '%s', %d, %d)",
11690
          $block['module'], $block['delta'], $theme, $block['status'],
$block['weight'], $block['region'], $block['visibility'], $block['pages'],
$block['custom'], $block['cache']);
11700
    }
11710
  }
11720
}
1173
1174
/**
1175
 * Add default buttons to a form and set its prefix.
1176
 *
1177
 * @ingroup forms
1178
 * @see system_settings_form_submit()
1179
 * @param $form
1180
 *   An associative array containing the structure of the form.
1181
 * @return
1182
 *   The form structure.
1183
 */
11842027
function system_settings_form($form) {
118531
  $form['buttons']['submit'] = array('#type' => 'submit', '#value' =>
t('Save configuration') );
118631
  $form['buttons']['reset'] = array('#type' => 'submit', '#value' =>
t('Reset to defaults') );
1187
118831
  if (!empty($_POST) && form_get_errors()) {
11890
    drupal_set_message(t('The settings have not been saved because of the
errors.'), 'error');
11900
  }
119131
  $form['#submit'][] = 'system_settings_form_submit';
119231
  $form['#theme'] = 'system_settings_form';
119331
  return $form;
11940
}
1195
1196
/**
1197
 * Execute the system_settings_form.
1198
 *
1199
 * If you want node type configure style handling of your checkboxes,
1200
 * add an array_filter value to your form.
1201
 */
12022027
function system_settings_form_submit($form, &$form_state) {
120310
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] :
'';
1204
1205
  // Exclude unnecessary elements.
120610
  unset($form_state['values']['submit'], $form_state['values']['reset'],
$form_state['values']['form_id'], $form_state['values']['op'],
$form_state['values']['form_token'],
$form_state['values']['form_build_id']);
1207
120810
  foreach ($form_state['values'] as $key => $value) {
120910
    if ($op == t('Reset to defaults')) {
12100
      variable_del($key);
12110
    }
1212
    else {
121310
      if (is_array($value) && isset($form_state['values']['array_filter']))
{
12140
        $value = array_keys(array_filter($value));
12150
      }
121610
      variable_set($key, $value);
1217
    }
121810
  }
121910
  if ($op == t('Reset to defaults')) {
12200
    drupal_set_message(t('The configuration options have been reset to
their default values.'));
12210
  }
1222
  else {
122310
    drupal_set_message(t('The configuration options have been saved.'));
1224
  }
1225
122610
  cache_clear_all();
122710
  drupal_theme_rebuild();
122810
}
1229
1230
/**
1231
 * Helper function to sort requirements.
1232
 */
12332027
function _system_sort_requirements($a, $b) {
12343
  if (!isset($a['weight'])) {
12353
    if (!isset($b['weight'])) {
12363
      return strcmp($a['title'], $b['title']);
12370
    }
12383
    return -$b['weight'];
12390
  }
12403
  return isset($b['weight']) ? $a['weight'] - $b['weight'] : $a['weight'];
12410
}
1242
1243
/**
1244
 * Implementation of hook_node_type().
1245
 *
1246
 * Updates theme settings after a node type change.
1247
 */
12482027
function system_node_type($op, $info) {
124963
  if ($op == 'update' && !empty($info->old_type) && $info->type !=
$info->old_type) {
12500
    $old = 'toggle_node_info_' . $info->old_type;
12510
    $new = 'toggle_node_info_' . $info->type;
1252
12530
    $theme_settings = variable_get('theme_settings', array());
12540
    if (isset($theme_settings[$old])) {
12550
      $theme_settings[$new] = $theme_settings[$old];
12560
      unset($theme_settings[$old]);
12570
      variable_set('theme_settings', $theme_settings);
12580
    }
12590
  }
126063
}
1261
1262
/**
1263
 * Output a confirmation form
1264
 *
1265
 * This function returns a complete form for confirming an action. A link
is
1266
 * offered to go back to the item that is being changed in case the user
changes
1267
 * his/her mind.
1268
 *
1269
 * If the submit handler for this form is invoked, the user successfully
1270
 * confirmed the action. You should never directly inspect $_POST to see if
an
1271
 * action was confirmed.
1272
 *
1273
 * @ingroup forms
1274
 * @param $form
1275
 *   Additional elements to inject into the form, for example hidden
elements.
1276
 * @param $question
1277
 *   The question to ask the user (e.g. "Are you sure you want to delete
the
1278
 *   block <em>foo</em>?").
1279
 * @param $path
1280
 *   The page to go to if the user denies the action.
1281
 *   Can be either a drupal path, or an array with the keys 'path',
'query', 'fragment'.
1282
 * @param $description
1283
 *   Additional text to display (defaults to "This action cannot be
undone.").
1284
 * @param $yes
1285
 *   A caption for the button which confirms the action (e.g. "Delete",
1286
 *   "Replace", ...).
1287
 * @param $no
1288
 *   A caption for the link which denies the action (e.g. "Cancel").
1289
 * @param $name
1290
 *   The internal name used to refer to the confirmation item.
1291
 * @return
1292
 *   The form.
1293
 */
12942027
function confirm_form($form, $question, $path, $description = NULL, $yes =
NULL, $no = NULL, $name = 'confirm') {
129599
  $description = isset($description) ? $description : t('This action cannot
be undone.');
1296
1297
  // Prepare cancel link
129899
  $query = $fragment = NULL;
129999
  if (is_array($path)) {
13000
    $query = isset($path['query']) ? $path['query'] : NULL;
13010
    $fragment = isset($path['fragment']) ? $path['fragment'] : NULL;
13020
    $path = isset($path['path']) ? $path['path'] : NULL;
13030
  }
130499
  $cancel = l($no ? $no : t('Cancel'), $path, array('query' => $query,
'fragment' => $fragment));
1305
130699
  drupal_set_title($question);
1307
1308
  // Confirm form fails duplication check, as the form values rarely change
-- so skip it.
130999
  $form['#skip_duplicate_check'] = TRUE;
1310
131199
  $form['#attributes'] = array('class' => 'confirmation');
131299
  $form['description'] = array('#markup' => $description);
131399
  $form[$name] = array('#type' => 'hidden', '#value' => 1);
1314
131599
  $form['actions'] = array('#prefix' => '<div class="container-inline">',
'#suffix' => '</div>');
131699
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => $yes
? $yes : t('Confirm'));
131799
  $form['actions']['cancel'] = array('#markup' => $cancel);
131899
  $form['#theme'] = 'confirm_form';
131999
  return $form;
13200
}
1321
1322
/**
1323
 * Determine if a user is in compact mode.
1324
 */
13252027
function system_admin_compact_mode() {
132628
  global $user;
132728
  return (isset($user->admin_compact_mode)) ? $user->admin_compact_mode :
variable_get('admin_compact_mode', FALSE);
13280
}
1329
1330
/**
1331
 * Menu callback; Sets whether the admin menu is in compact mode or not.
1332
 *
1333
 * @param $mode
1334
 *   Valid values are 'on' and 'off'.
1335
 */
13362027
function system_admin_compact_page($mode = 'off') {
13370
  global $user;
13380
  user_save($user, array('admin_compact_mode' => ($mode == 'on')));
13390
  drupal_goto(drupal_get_destination());
13400
}
1341
1342
/**
1343
 * Generate a list of tasks offered by a specified module.
1344
 *
1345
 * @param $module
1346
 *   Module name.
1347
 * @return
1348
 *   An array of task links.
1349
 */
13502027
function system_get_module_admin_tasks($module) {
135118
  static $items;
1352
135318
  $admin_access = user_access('administer permissions');
135418
  $admin_tasks = array();
1355
135618
  if (!isset($items)) {
135718
    $result = db_query("
1358
       SELECT m.load_functions, m.to_arg_functions, m.access_callback,
m.access_arguments, m.page_callback, m.page_arguments, m.title,
m.title_callback, m.title_arguments, m.type, ml.*
135918
       FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.router_path =
m.path WHERE ml.link_path LIKE 'admin/%' AND hidden >= 0 AND module =
'system' AND m.number_parts > 2");
136018
    $items = array();
136118
    while ($item = db_fetch_array($result)) {
136218
      _menu_link_translate($item);
136318
      if ($item['access']) {
13642
        $items[$item['router_path']] = $item;
13652
      }
136618
    }
136718
  }
136818
  $admin_tasks = array();
136918
  $admin_task_count = 0;
1370
  // Check for permissions.
137118
  if (module_hook($module, 'perm') && $admin_access) {
13720
    $admin_tasks[-1] = l(t('Configure permissions'),
'admin/user/permissions', array('fragment' => 'module-' . $module));
13730
  }
1374
1375
  // Check for menu items that are admin links.
137618
  if ($menu = module_invoke($module, 'menu')) {
137717
    foreach (array_keys($menu) as $path) {
137817
      if (isset($items[$path])) {
13792
        $admin_tasks[$items[$path]['title'] . $admin_task_count ++] =
l($items[$path]['title'], $path);
13802
      }
138117
    }
138217
  }
1383
138418
  return $admin_tasks;
13850
}
1386
1387
/**
1388
 * Implementation of hook_cron().
1389
 *
1390
 * Remove older rows from flood and batch table. Remove old temporary
files.
1391
 */
13922027
function system_cron() {
1393
  // Cleanup the flood.
13942
  db_query('DELETE FROM {flood} WHERE timestamp < %d', time() - 3600);
1395
  // Cleanup the batch table.
13962
  db_query('DELETE FROM {batch} WHERE timestamp < %d', time() - 864000);
1397
1398
  // Remove temporary files that are older than
DRUPAL_MAXIMUM_TEMP_FILE_AGE.
13992
  $result = db_query('SELECT * FROM {files} WHERE status = %d and timestamp
< %d', FILE_STATUS_TEMPORARY, time() - DRUPAL_MAXIMUM_TEMP_FILE_AGE);
14002
  while ($file = db_fetch_object($result)) {
14010
    if (file_exists($file->filepath)) {
1402
      // If files that exist cannot be deleted, continue so the database
remains
1403
      // consistent.
14040
      if (!file_delete($file->filepath)) {
14050
        watchdog('file system', 'Could not delete temporary file "%path"
during garbage collection', array('%path' => $file->filepath), 'error');
14060
        continue;
14070
      }
14080
    }
14090
    db_query('DELETE FROM {files} WHERE fid = %d', $file->fid);
14100
  }
14112
}
1412
1413
/**
1414
 * Implementation of hook_hook_info().
1415
 */
14162027
function system_hook_info() {
1417
  return array(
1418
    'system' => array(
1419
      'cron' => array(
1420
        'run' => array(
142155
          'runs when' => t('When cron runs'),
142255
        ),
142355
      ),
142455
    ),
142555
  );
14260
}
1427
1428
/**
1429
 * Implementation of hook_action_info().
1430
 */
14312027
function system_action_info() {
1432
  return array(
1433
    'system_message_action' => array(
1434131
      'type' => 'system',
1435131
      'description' => t('Display a message to the user'),
1436131
      'configurable' => TRUE,
1437
      'hooks' => array(
1438131
        'nodeapi' => array('view', 'insert', 'update', 'delete'),
1439131
        'comment' => array('view', 'insert', 'update', 'delete'),
1440131
        'user' => array('view', 'insert', 'update', 'delete', 'login'),
1441131
        'taxonomy' => array('insert', 'update', 'delete'),
1442131
      ),
1443131
    ),
1444
    'system_send_email_action' => array(
1445131
      'description' => t('Send e-mail'),
1446131
      'type' => 'system',
1447131
      'configurable' => TRUE,
1448
      'hooks' => array(
1449131
        'nodeapi' => array('view', 'insert', 'update', 'delete'),
1450131
        'comment' => array('view', 'insert', 'update', 'delete'),
1451131
        'user' => array('view', 'insert', 'update', 'delete', 'login'),
1452131
        'taxonomy' => array('insert', 'update', 'delete'),
1453
      )
1454131
    ),
1455
    'system_block_ip_action' => array(
1456131
      'description' => t('Ban IP address of current user'),
1457131
      'type' => 'user',
1458131
      'configurable' => FALSE,
1459131
      'hooks' => array(),
1460131
    ),
1461
    'system_goto_action' => array(
1462131
      'description' => t('Redirect to URL'),
1463131
      'type' => 'system',
1464131
      'configurable' => TRUE,
1465
      'hooks' => array(
1466131
        'nodeapi' => array('view', 'insert', 'update', 'delete'),
1467131
        'comment' => array('view', 'insert', 'update', 'delete'),
1468131
        'user' => array('view', 'insert', 'update', 'delete', 'login'),
1469
      )
1470131
    )
1471131
  );
14720
}
1473
1474
/**
1475
 * Menu callback. Display an overview of available and configured actions.
1476
 */
14772027
function system_actions_manage() {
14780
  $output = '';
14790
  $actions = actions_list();
14800
  actions_synchronize($actions);
14810
  $actions_map = actions_actions_map($actions);
14820
  $options = array(t('Choose an advanced action'));
14830
  $unconfigurable = array();
1484
14850
  foreach ($actions_map as $key => $array) {
14860
    if ($array['configurable']) {
14870
      $options[$key] = $array['description'] . '...';
14880
    }
1489
    else {
14900
      $unconfigurable[] = $array;
1491
    }
14920
  }
1493
14940
  $row = array();
14950
  $instances_present = db_fetch_object(db_query("SELECT aid FROM {actions}
WHERE parameters != ''"));
1496
  $header = array(
14970
    array('data' => t('Action type'), 'field' => 'type'),
14980
    array('data' => t('Description'), 'field' => 'description'),
14990
    array('data' => $instances_present ? t('Operations') : '', 'colspan' =>
'2')
15000
  );
15010
  $sql = 'SELECT * FROM {actions}';
15020
  $result = pager_query($sql . tablesort_sql($header), 50);
15030
  while ($action = db_fetch_object($result)) {
15040
    $row[] = array(
15050
      array('data' => $action->type),
15060
      array('data' => $action->description),
15070
      array('data' => $action->parameters ? l(t('configure'),
"admin/settings/actions/configure/$action->aid") : ''),
15080
      array('data' => $action->parameters ? l(t('delete'),
"admin/settings/actions/delete/$action->aid") : '')
15090
    );
15100
  }
1511
15120
  if ($row) {
15130
    $pager = theme('pager', NULL, 50, 0);
15140
    if (!empty($pager)) {
15150
      $row[] = array(array('data' => $pager, 'colspan' => '3'));
15160
    }
15170
    $output .= '<h3>' . t('Actions available to Drupal:') . '</h3>';
15180
    $output .= theme('table', $header, $row);
15190
  }
1520
15210
  if ($actions_map) {
15220
    $output .= drupal_get_form('system_actions_manage_form', $options);
15230
  }
1524
15250
  return $output;
15260
}
1527
1528
/**
1529
 * Define the form for the actions overview page.
1530
 *
1531
 * @see system_actions_manage_form_submit()
1532
 * @ingroup forms
1533
 * @param $form_state
1534
 *   An associative array containing the current state of the form; not
used.
1535
 * @param $options
1536
 *   An array of configurable actions.
1537
 * @return
1538
 *   Form definition.
1539
 */
15402027
function system_actions_manage_form($form_state, $options = array()) {
15410
  $form['parent'] = array(
15420
    '#type' => 'fieldset',
15430
    '#title' => t('Make a new advanced action available'),
15440
    '#prefix' => '<div class="container-inline">',
15450
    '#suffix' => '</div>',
1546
  );
15470
  $form['parent']['action'] = array(
15480
    '#type' => 'select',
15490
    '#default_value' => '',
15500
    '#options' => $options,
15510
    '#description' => '',
1552
  );
15530
  $form['parent']['buttons']['submit'] = array(
15540
    '#type' => 'submit',
15550
    '#value' => t('Create'),
1556
  );
15570
  return $form;
15580
}
1559
1560
/**
1561
 * Process system_actions_manage form submissions.
1562
 */
15632027
function system_actions_manage_form_submit($form, &$form_state) {
15640
  if ($form_state['values']['action']) {
15650
    $form_state['redirect'] = 'admin/settings/actions/configure/' .
$form_state['values']['action'];
15660
  }
15670
}
1568
1569
/**
1570
 * Menu callback. Create the form for configuration of a single action.
1571
 *
1572
 * We provide the "Description" field. The rest of the form
1573
 * is provided by the action. We then provide the Save button.
1574
 * Because we are combining unknown form elements with the action
1575
 * configuration form, we use actions_ prefix on our elements.
1576
 *
1577
 * @see system_actions_configure_validate()
1578
 * @see system_actions_configure_submit()
1579
 * @param $action
1580
 *   md5 hash of action ID or an integer. If it's an md5 hash, we
1581
 *   are creating a new instance. If it's an integer, we're editing
1582
 *   an existing instance.
1583
 * @return
1584
 *   Form definition.
1585
 */
15862027
function system_actions_configure($form_state, $action = NULL) {
15870
  if ($action === NULL) {
15880
    drupal_goto('admin/settings/actions');
15890
  }
1590
15910
  $actions_map = actions_actions_map(actions_list());
15920
  $edit = array();
1593
1594
  // Numeric action denotes saved instance of a configurable action;
1595
  // else we are creating a new action instance.
15960
  if (is_numeric($action)) {
15970
    $aid = $action;
1598
    // Load stored parameter values from database.
15990
    $data = db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid =
%d", intval($aid)));
16000
    $edit['actions_description'] = $data->description;
16010
    $edit['actions_type'] = $data->type;
16020
    $function = $data->callback;
16030
    $action = md5($data->callback);
16040
    $params = unserialize($data->parameters);
16050
    if ($params) {
16060
      foreach ($params as $name => $val) {
16070
        $edit[$name] = $val;
16080
      }
16090
    }
16100
  }
1611
  else {
16120
    $function = $actions_map[$action]['callback'];
16130
    $edit['actions_description'] = $actions_map[$action]['description'];
16140
    $edit['actions_type'] = $actions_map[$action]['type'];
1615
  }
1616
16170
  $form['actions_description'] = array(
16180
    '#type' => 'textfield',
16190
    '#title' => t('Description'),
16200
    '#default_value' => $edit['actions_description'],
16210
    '#maxlength' => '255',
16220
    '#description' => t('A unique description for this advanced action.
This description will be displayed in the interface of modules that
integrate with actions, such as Trigger module.'),
16230
    '#weight' => -10
16240
  );
16250
  $action_form = $function . '_form';
16260
  $form = array_merge($form, $action_form($edit));
16270
  $form['actions_type'] = array(
16280
    '#type' => 'value',
16290
    '#value' => $edit['actions_type'],
1630
  );
16310
  $form['actions_action'] = array(
16320
    '#type' => 'hidden',
16330
    '#value' => $action,
1634
  );
1635
  // $aid is set when configuring an existing action instance.
16360
  if (isset($aid)) {
16370
    $form['actions_aid'] = array(
16380
      '#type' => 'hidden',
16390
      '#value' => $aid,
1640
    );
16410
  }
16420
  $form['actions_configured'] = array(
16430
    '#type' => 'hidden',
16440
    '#value' => '1',
1645
  );
16460
  $form['buttons']['submit'] = array(
16470
    '#type' => 'submit',
16480
    '#value' => t('Save'),
1649
    '#weight' => 13
16500
  );
1651
16520
  return $form;
16530
}
1654
1655
/**
1656
 * Validate system_actions_configure form submissions.
1657
 */
16582027
function system_actions_configure_validate($form, $form_state) {
16590
  $function =
actions_function_lookup($form_state['values']['actions_action']) .
'_validate';
1660
  // Hand off validation to the action.
16610
  if (function_exists($function)) {
16620
    $function($form, $form_state);
16630
  }
16640
}
1665
1666
/**
1667
 * Process system_actions_configure form submissions.
1668
 */
16692027
function system_actions_configure_submit($form, &$form_state) {
16700
  $function =
actions_function_lookup($form_state['values']['actions_action']);
16710
  $submit_function = $function . '_submit';
1672
1673
  // Action will return keyed array of values to store.
16740
  $params = $submit_function($form, $form_state);
16750
  $aid = isset($form_state['values']['actions_aid']) ?
$form_state['values']['actions_aid'] : NULL;
1676
16770
  actions_save($function, $form_state['values']['actions_type'], $params,
$form_state['values']['actions_description'], $aid);
16780
  drupal_set_message(t('The action has been successfully saved.'));
1679
16800
  $form_state['redirect'] = 'admin/settings/actions/manage';
16810
}
1682
1683
/**
1684
 * Create the form for confirmation of deleting an action.
1685
 *
1686
 * @ingroup forms
1687
 * @see system_actions_delete_form_submit()
1688
 */
16892027
function system_actions_delete_form($form_state, $action) {
1690
16910
  $form['aid'] = array(
16920
    '#type' => 'hidden',
16930
    '#value' => $action->aid,
1694
  );
16950
  return confirm_form($form,
16960
    t('Are you sure you want to delete the action %action?',
array('%action' => $action->description)),
16970
    'admin/settings/actions/manage',
16980
    t('This cannot be undone.'),
16990
    t('Delete'), t('Cancel')
17000
  );
17010
}
1702
1703
/**
1704
 * Process system_actions_delete form submissions.
1705
 *
1706
 * Post-deletion operations for action deletion.
1707
 */
17082027
function system_actions_delete_form_submit($form, &$form_state) {
17090
  $aid = $form_state['values']['aid'];
17100
  $action = actions_load($aid);
17110
  actions_delete($aid);
17120
  $description = check_plain($action->description);
17130
  watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $aid,
'%action' => $description));
17140
  drupal_set_message(t('Action %action was deleted', array('%action' =>
$description)));
17150
  $form_state['redirect'] = 'admin/settings/actions/manage';
17160
}
1717
1718
/**
1719
 * Post-deletion operations for deleting action orphans.
1720
 *
1721
 * @param $orphaned
1722
 *   An array of orphaned actions.
1723
 */
17242027
function system_action_delete_orphans_post($orphaned) {
17250
  foreach ($orphaned as $callback) {
17260
    drupal_set_message(t("Deleted orphaned action (%action).",
array('%action' => $callback)));
17270
  }
17280
}
1729
1730
/**
1731
 * Remove actions that are in the database but not supported by any enabled
module.
1732
 */
17332027
function system_actions_remove_orphans() {
17340
  actions_synchronize(actions_list(), TRUE);
17350
  drupal_goto('admin/settings/actions/manage');
17360
}
1737
1738
/**
1739
 * Return a form definition so the Send email action can be configured.
1740
 *
1741
 * @see system_send_email_action_validate()
1742
 * @see system_send_email_action_submit()
1743
 * @param $context
1744
 *   Default values (if we are editing an existing action instance).
1745
 * @return
1746
 *   Form definition.
1747
 */
17482027
function system_send_email_action_form($context) {
1749
  // Set default values for form.
17500
  if (!isset($context['recipient'])) {
17510
    $context['recipient'] = '';
17520
  }
17530
  if (!isset($context['subject'])) {
17540
    $context['subject'] = '';
17550
  }
17560
  if (!isset($context['message'])) {
17570
    $context['message'] = '';
17580
  }
1759
17600
  $form['recipient'] = array(
17610
    '#type' => 'textfield',
17620
    '#title' => t('Recipient'),
17630
    '#default_value' => $context['recipient'],
17640
    '#maxlength' => '254',
17650
    '#description' => t('The email address to which the message should be
sent OR enter %author if you would like to send an e-mail to the author of
the original post.', array('%author' => '%author')),
1766
  );
17670
  $form['subject'] = array(
17680
    '#type' => 'textfield',
17690
    '#title' => t('Subject'),
17700
    '#default_value' => $context['subject'],
17710
    '#maxlength' => '254',
17720
    '#description' => t('The subject of the message.'),
1773
  );
17740
  $form['message'] = array(
17750
    '#type' => 'textarea',
17760
    '#title' => t('Message'),
17770
    '#default_value' => $context['message'],
17780
    '#cols' => '80',
17790
    '#rows' => '20',
17800
    '#description' => t('The message that should be sent. You may include
the following variables: %site_name, %username, %node_url, %node_type,
%title, %teaser, %body. Not all variables will be available in all
contexts.'),
1781
  );
17820
  return $form;
17830
}
1784
1785
/**
1786
 * Validate system_send_email_action form submissions.
1787
 */
17882027
function system_send_email_action_validate($form, $form_state) {
17890
  $form_values = $form_state['values'];
1790
  // Validate the configuration form.
17910
  if (!valid_email_address($form_values['recipient']) &&
$form_values['recipient'] != '%author') {
1792
    // We want the literal %author placeholder to be emphasized in the
error message.
17930
    form_set_error('recipient', t('Please enter a valid email address or
%author.', array('%author' => '%author')));
17940
  }
17950
}
1796
1797
/**
1798
 * Process system_send_email_action form submissions.
1799
 */
18002027
function system_send_email_action_submit($form, $form_state) {
18010
  $form_values = $form_state['values'];
1802
  // Process the HTML form to store configuration. The keyed array that
1803
  // we return will be serialized to the database.
1804
  $params = array(
18050
    'recipient' => $form_values['recipient'],
18060
    'subject'   => $form_values['subject'],
18070
    'message'   => $form_values['message'],
18080
  );
18090
  return $params;
18100
}
1811
1812
/**
1813
 * Implementation of a configurable Drupal action. Sends an email.
1814
 */
18152027
function system_send_email_action($object, $context) {
18160
  global $user;
1817
18180
  switch ($context['hook']) {
18190
    case 'nodeapi':
1820
      // Because this is not an action of type 'node' the node
1821
      // will not be passed as $object, but it will still be available
1822
      // in $context.
18230
      $node = $context['node'];
18240
      break;
1825
    // The comment hook provides nid, in $context.
18260
    case 'comment':
18270
      $comment = $context['comment'];
18280
      $node = node_load($comment->nid);
18290
      break;
18300
    case 'user':
1831
      // Because this is not an action of type 'user' the user
1832
      // object is not passed as $object, but it will still be available
1833
      // in $context.
18340
      $account = $context['account'];
18350
      if (isset($context['node'])) {
18360
        $node = $context['node'];
18370
      }
18380
      elseif ($context['recipient'] == '%author') {
1839
        // If we don't have a node, we don't have a node author.
18400
        watchdog('error', 'Cannot use %author token in this context.');
18410
        return;
18420
      }
18430
      break;
18440
    default:
1845
      // We are being called directly.
18460
      $node = $object;
18470
  }
1848
18490
  $recipient = $context['recipient'];
1850
18510
  if (isset($node)) {
18520
    if (!isset($account)) {
18530
      $account = user_load(array('uid' => $node->uid));
18540
    }
18550
    if ($recipient == '%author') {
18560
      $recipient = $account->mail;
18570
    }
18580
  }
1859
18600
  if (!isset($account)) {
18610
    $account = $user;
1862
18630
  }
18640
  $language = user_preferred_language($account);
18650
  $params = array('account' => $account, 'object' => $object, 'context' =>
$context);
18660
  if (isset($node)) {
18670
    $params['node'] = $node;
18680
  }
1869
18700
  if (drupal_mail('system', 'action_send_email', $recipient, $language,
$params)) {
18710
    watchdog('action', 'Sent email to %recipient', array('%recipient' =>
$recipient));
18720
  }
1873
  else {
18740
    watchdog('error', 'Unable to send email to %recipient',
array('%recipient' => $recipient));
1875
  }
18760
}
1877
1878
/**
1879
 * Implementation of hook_mail().
1880
 */
18812027
function system_mail($key, &$message, $params) {
18820
  $account = $params['account'];
18830
  $context = $params['context'];
1884
  $variables = array(
18850
    '%site_name' => variable_get('site_name', 'Drupal'),
18860
    '%username' => $account->name,
18870
  );
18880
  if ($context['hook'] == 'taxonomy') {
18890
    $object = $params['object'];
18900
    $vocabulary = taxonomy_vocabulary_load($object->vid);
1891
    $variables += array(
18920
      '%term_name' => $object->name,
18930
      '%term_description' => $object->description,
18940
      '%term_id' => $object->tid,
18950
      '%vocabulary_name' => $vocabulary->name,
18960
      '%vocabulary_description' => $vocabulary->description,
18970
      '%vocabulary_id' => $vocabulary->vid,
18980
    );
18990
  }
1900
1901
  // Node-based variable translation is only available if we have a node.
19020
  if (isset($params['node'])) {
19030
    $node = $params['node'];
1904
    $variables += array(
19050
      '%uid' => $node->uid,
19060
      '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
19070
      '%node_type' => node_get_types('name', $node),
19080
      '%title' => $node->title,
19090
      '%teaser' => $node->teaser,
19100
      '%body' => $node->body,
19110
    );
19120
  }
19130
  $subject = strtr($context['subject'], $variables);
19140
  $body = strtr($context['message'], $variables);
19150
  $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
19160
  $message['body'][] = drupal_html_to_text($body);
19170
}
1918
19192027
function system_message_action_form($context) {
19200
  $form['message'] = array(
19210
    '#type' => 'textarea',
19220
    '#title' => t('Message'),
19230
    '#default_value' => isset($context['message']) ? $context['message'] :
'',
19240
    '#required' => TRUE,
19250
    '#rows' => '8',
19260
    '#description' => t('The message to be displayed to the current user.
You may include the following variables: %site_name, %username, %node_url,
%node_type, %title, %teaser, %body. Not all variables will be available in
all contexts.'),
1927
  );
19280
  return $form;
19290
}
1930
19312027
function system_message_action_submit($form, $form_state) {
19320
  return array('message' => $form_state['values']['message']);
19330
}
1934
1935
/**
1936
 * A configurable Drupal action. Sends a message to the current user's
screen.
1937
 */
19382027
function system_message_action(&$object, $context = array()) {
19390
  global $user;
1940
  $variables = array(
19410
    '%site_name' => variable_get('site_name', 'Drupal'),
19420
    '%username' => $user->name ? $user->name : variable_get('anonymous',
t('Anonymous')),
19430
  );
1944
1945
  // This action can be called in any context, but if placeholders
1946
  // are used a node object must be present to be the source
1947
  // of substituted text.
19480
  switch ($context['hook']) {
19490
    case 'nodeapi':
1950
      // Because this is not an action of type 'node' the node
1951
      // will not be passed as $object, but it will still be available
1952
      // in $context.
19530
      $node = $context['node'];
19540
      break;
1955
    // The comment hook also provides the node, in context.
19560
    case 'comment':
19570
      $comment = $context['comment'];
19580
      $node = node_load($comment->nid);
19590
      break;
19600
    case 'taxonomy':
19610
      $vocabulary = taxonomy_vocabulary_load($object->vid);
19620
      $variables = array_merge($variables, array(
19630
        '%term_name' => $object->name,
19640
        '%term_description' => $object->description,
19650
        '%term_id' => $object->tid,
19660
        '%vocabulary_name' => $vocabulary->name,
19670
        '%vocabulary_description' => $vocabulary->description,
19680
        '%vocabulary_id' => $vocabulary->vid,
1969
        )
19700
      );
19710
      break;
19720
    default:
1973
      // We are being called directly.
19740
      $node = $object;
19750
  }
1976
19770
  if (isset($node) && is_object($node)) {
19780
    $variables = array_merge($variables, array(
19790
      '%uid' => $node->uid,
19800
      '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
19810
      '%node_type' => check_plain(node_get_types('name', $node)),
19820
      '%title' => filter_xss($node->title),
19830
      '%teaser' => filter_xss($node->teaser),
19840
      '%body' => filter_xss($node->body),
1985
      )
19860
    );
19870
  }
19880
  $context['message'] = strtr($context['message'], $variables);
19890
  drupal_set_message($context['message']);
19900
}
1991
1992
/**
1993
 * Implementation of a configurable Drupal action. Redirect user to a URL.
1994
 */
19952027
function system_goto_action_form($context) {
19960
  $form['url'] = array(
19970
    '#type' => 'textfield',
19980
    '#title' => t('URL'),
19990
    '#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.'),
20000
    '#default_value' => isset($context['url']) ? $context['url'] : '',
20010
    '#required' => TRUE,
2002
  );
20030
  return $form;
20040
}
2005
20062027
function system_goto_action_submit($form, $form_state) {
2007
  return array(
20080
    'url' => $form_state['values']['url']
20090
  );
20100
}
2011
20122027
function system_goto_action($object, $context) {
20130
  drupal_goto($context['url']);
20140
}
2015
2016
/**
2017
 * Implementation of a Drupal action.
2018
 * Blocks the user's IP address.
2019
 */
20202027
function system_block_ip_action() {
20210
  $ip = ip_address();
20220
  db_query("INSERT INTO {blocked_ips} (ip) VALUES ('%s')", $ip);;
20230
  watchdog('action', 'Banned IP address %ip', array('%ip' => $ip));
20240
}
2025
2026
/**
2027
 * Generate an array of time zones and their local time&date.
2028
 */
20292027
function _system_zonelist() {
203016
  $timestamp = time();
203116
  $zonelist = array(-11, -10, -9.5, -9, -8, -7, -6, -5, -4, -3.5, -3, -2,
-1, 0, 1, 2, 3, 3.5, 4, 5, 5.5, 5.75, 6, 6.5, 7, 8, 9, 9.5, 10, 10.5, 11,
11.5, 12, 12.75, 13, 14);
203216
  $zones = array();
203316
  foreach ($zonelist as $offset) {
203416
    $zone = $offset * 3600;
203516
    $zones[$zone] = format_date($timestamp, 'custom',
variable_get('date_format_long', 'l, F j, Y - H:i') . ' O', $zone);
203616
  }
203716
  return $zones;
20380
}
2039
2040
/**
2041
 * Checks whether the server is capable of issuing HTTP requests.
2042
 *
2043
 * The function sets the drupal_http_request_fail system variable to TRUE
if
2044
 * drupal_http_request() does not work and then the system status report
page
2045
 * will contain an error.
2046
 *
2047
 * @return
2048
 *  Whether the admin/reports/request-test page can be requested via HTTP
2049
 *  and contains the same output as if called via the menu system.
2050
 */
20512027
function system_check_http_request() {
2052
  // Check whether we can do any request at all. First get the results for
2053
  // a very simple page which has access TRUE set via the menu system.
Then,
2054
  // try to drupal_http_request() the same page and compare.
20550
  ob_start();
20560
  $path = 'admin/reports/request-test';
20570
  menu_execute_active_handler($path);
20580
  $nothing = ob_get_contents();
20590
  ob_end_clean();
20600
  $result = drupal_http_request(url($path, array('absolute' => TRUE)));
20610
  $works = isset($result->data) && $result->data == $nothing;
20620
  variable_set('drupal_http_request_fails', !$works);
20630
  return $works;
20640
}
2065
2066
/**
2067
 * Format the Powered by Drupal text.
2068
 *
2069
 * @ingroup themeable
2070
 */
20712027
function theme_system_powered_by($image_path) {
20721489
  $image = theme('image', $image_path, t('Powered by Drupal, an open source
content management system'), t('Powered by Drupal, an open source content
management system'));
20731489
  return l($image, 'http://drupal.org', array('html' => TRUE, 'absolute' =>
TRUE, 'external' => TRUE));
20740
}
2075
2076
/**
2077
 * Display the link to show or hide inline help descriptions.
2078
 *
2079
 * @ingroup themeable
2080
 */
20812027
function theme_system_compact_link() {
208218
  $output = '<div class="compact-link">';
208318
  if (system_admin_compact_mode()) {
20840
    $output .= l(t('Show descriptions'), 'admin/compact/off',
array('attributes' => array('title' => t('Expand layout to include
descriptions.')), 'query' => drupal_get_destination()));
20850
  }
2086
  else {
208718
    $output .= l(t('Hide descriptions'), 'admin/compact/on',
array('attributes' => array('title' => t('Compress layout by hiding
descriptions.')), 'query' => drupal_get_destination()));
2088
  }
208918
  $output .= '</div>';
2090
209118
  return $output;
20920
}
2093
2094
2095
/**
2096
 * Send Drupal and the major version number in the META GENERATOR HTML.
2097
 *
2098
 * @ingroup themeable
2099
 */
21002027
function theme_meta_generator_html($version = VERSION) {
21012027
  drupal_set_html_head('<meta name="Generator" content="Drupal ' . $version
. ' (http://drupal.org)" />');
21022027
}
2103
2104
/**
2105
 * Send Drupal and the major version number in the HTTP headers.
2106
 *
2107
 * @ingroup themeable
2108
 */
21092027
function theme_meta_generator_header($version = VERSION) {
21102027
  drupal_set_header('X-Generator: Drupal ' . $version . '
(http://drupal.org)');
21112027
}
2112
2113
/**
2114
 * Implementation of hook_image_toolkits().
2115
 */
21162027
function system_image_toolkits() {
21170
  return array('gd');
21180
}
21192027