web/drupal/modules/system/system.module
branchdrupal
changeset 74 0ff3ba646492
equal deleted inserted replaced
73:fcf75e232c5b 74:0ff3ba646492
       
     1 <?php
       
     2 // $Id: system.module,v 1.585.2.38 2009/07/01 20:51:56 goba 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  */
       
    12 define('VERSION', '6.13');
       
    13 
       
    14 /**
       
    15  * Core API compatibility.
       
    16  */
       
    17 define('DRUPAL_CORE_COMPATIBILITY', '6.x');
       
    18 
       
    19 /**
       
    20  * Minimum supported version of PHP.
       
    21  */
       
    22 define('DRUPAL_MINIMUM_PHP',    '4.3.5');
       
    23 
       
    24 /**
       
    25  * Minimum recommended value of PHP memory_limit.
       
    26  */
       
    27 define('DRUPAL_MINIMUM_PHP_MEMORY_LIMIT',    '16M');
       
    28 
       
    29 /**
       
    30  * Minimum supported version of MySQL, if it is used.
       
    31  */
       
    32 define('DRUPAL_MINIMUM_MYSQL',  '4.1.1');
       
    33 
       
    34 /**
       
    35  * Minimum supported version of PostgreSQL, if it is used.
       
    36  */
       
    37 define('DRUPAL_MINIMUM_PGSQL',  '7.4');
       
    38 
       
    39 /**
       
    40  * Maximum age of temporary files in seconds.
       
    41  */
       
    42 define('DRUPAL_MAXIMUM_TEMP_FILE_AGE', 21600);
       
    43 
       
    44 /**
       
    45  * Implementation of hook_help().
       
    46  */
       
    47 function system_help($path, $arg) {
       
    48   global $base_url;
       
    49 
       
    50   switch ($path) {
       
    51     case 'admin/help#system':
       
    52       $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>';
       
    53       $output .= '<p>'. t('The system module provides:') .'</p>';
       
    54       $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>';
       
    55       $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>';
       
    56       $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>';
       
    57       $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, ping module 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>';
       
    58       $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 off-line.', 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>';
       
    59       $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>';
       
    60       return $output;
       
    61     case 'admin':
       
    62       return '<p>'. t('Welcome to the administration section. Here you may control how your site functions.') .'</p>';
       
    63     case 'admin/by-module':
       
    64       return '<p>'. t('This page shows you all available administration tasks for each module.') .'</p>';
       
    65     case 'admin/build/themes':
       
    66       $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>';
       
    67       $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>';
       
    68       return $output;
       
    69     case 'admin/build/themes/settings/'. $arg[4]:
       
    70       $reference = explode('.', $arg[4], 2);
       
    71       $theme = array_pop($reference);
       
    72       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>';
       
    73     case 'admin/build/themes/settings':
       
    74       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>';
       
    75     case 'admin/build/modules':
       
    76       $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. To reduce server load, modules with their <em>Throttle</em> checkbox selected are temporarily disabled when your site becomes extremely busy. (Note that the <em>Throttle</em> checkbox is only available if the Throttle module is enabled.)', array('@permissions' => url('admin/user/permissions')));
       
    77       if (module_exists('throttle')) {
       
    78         $output .= ' '. t('The auto-throttle functionality must be enabled on the <a href="@throttle">throttle configuration page</a> after having enabled the throttle module.', array('@throttle' => url('admin/settings/throttle')));
       
    79       }
       
    80       $output .= '</p>';
       
    81       $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>';
       
    82       $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>';
       
    83       $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>';
       
    84       return $output;
       
    85     case 'admin/build/modules/uninstall':
       
    86       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>';
       
    87     case 'admin/build/block/configure':
       
    88       if ($arg[4] == 'system' && $arg[5] == 0) {
       
    89         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>';
       
    90       }
       
    91       break;
       
    92     case 'admin/settings/actions':
       
    93     case 'admin/settings/actions/manage':
       
    94       $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>';
       
    95       $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>';
       
    96       if (module_exists('trigger')) {
       
    97         $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>';
       
    98       }
       
    99       return $output;
       
   100     case 'admin/settings/actions/configure':
       
   101       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").');
       
   102     case 'admin/reports/status':
       
   103       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>';
       
   104   }
       
   105 }
       
   106 
       
   107 /**
       
   108  * Implementation of hook_theme().
       
   109  */
       
   110 function system_theme() {
       
   111   return array_merge(drupal_common_theme(), array(
       
   112     'system_theme_select_form' => array(
       
   113       'arguments' => array('form' => NULL),
       
   114       'file' => 'system.admin.inc',
       
   115     ),
       
   116     'system_themes_form' => array(
       
   117       'arguments' => array('form' => NULL),
       
   118       'file' => 'system.admin.inc',
       
   119     ),
       
   120     'system_modules' => array(
       
   121       'arguments' => array('form' => NULL),
       
   122       'file' => 'system.admin.inc',
       
   123     ),
       
   124     'system_modules_uninstall' => array(
       
   125       'arguments' => array('form' => NULL),
       
   126       'file' => 'system.admin.inc',
       
   127     ),
       
   128     'status_report' => array(
       
   129       'arguments' => array('requirements' => NULL),
       
   130       'file' => 'system.admin.inc',
       
   131     ),
       
   132     'admin_page' => array(
       
   133       'arguments' => array('blocks' => NULL),
       
   134       'file' => 'system.admin.inc',
       
   135     ),
       
   136     'admin_block' => array(
       
   137       'arguments' => array('block' => NULL),
       
   138       'file' => 'system.admin.inc',
       
   139     ),
       
   140     'admin_block_content' => array(
       
   141       'arguments' => array('content' => NULL),
       
   142       'file' => 'system.admin.inc',
       
   143     ),
       
   144     'system_admin_by_module' => array(
       
   145       'arguments' => array('menu_items' => NULL),
       
   146       'file' => 'system.admin.inc',
       
   147     ),
       
   148     'system_powered_by' => array(
       
   149       'arguments' => array('image_path' => NULL),
       
   150     ),
       
   151   ));
       
   152 }
       
   153 
       
   154 /**
       
   155  * Implementation of hook_perm().
       
   156  */
       
   157 function system_perm() {
       
   158   return array('administer site configuration', 'access administration pages', 'administer actions', 'access site reports', 'select different theme', 'administer files');
       
   159 }
       
   160 
       
   161 /**
       
   162  * Implementation of hook_elements().
       
   163  */
       
   164 function system_elements() {
       
   165   // Top level form
       
   166   $type['form'] = array('#method' => 'post', '#action' => request_uri());
       
   167 
       
   168   // Inputs
       
   169   $type['submit'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => TRUE, '#process' => array('form_expand_ahah'));
       
   170   $type['button'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => FALSE, '#process' => array('form_expand_ahah'));
       
   171   $type['image_button'] = array('#input' => TRUE, '#button_type' => 'submit', '#executes_submit_callback' => TRUE, '#process' => array('form_expand_ahah'), '#return_value' => TRUE, '#has_garbage_value' => TRUE, '#src' => NULL);
       
   172   $type['textfield'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE, '#process' => array('form_expand_ahah'));
       
   173   $type['password'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#process' => array('form_expand_ahah'));
       
   174   $type['password_confirm'] = array('#input' => TRUE, '#process' => array('expand_password_confirm'));
       
   175   $type['textarea'] = array('#input' => TRUE, '#cols' => 60, '#rows' => 5, '#resizable' => TRUE, '#process' => array('form_expand_ahah'));
       
   176   $type['radios'] = array('#input' => TRUE, '#process' => array('expand_radios'));
       
   177   $type['radio'] = array('#input' => TRUE, '#default_value' => NULL, '#process' => array('form_expand_ahah'));
       
   178   $type['checkboxes'] = array('#input' => TRUE, '#process' => array('expand_checkboxes'), '#tree' => TRUE);
       
   179   $type['checkbox'] = array('#input' => TRUE, '#return_value' => 1, '#process' => array('form_expand_ahah'));
       
   180   $type['select'] = array('#input' => TRUE, '#size' => 0, '#multiple' => FALSE, '#process' => array('form_expand_ahah'));
       
   181   $type['weight'] = array('#input' => TRUE, '#delta' => 10, '#default_value' => 0, '#process' => array('process_weight', 'form_expand_ahah'));
       
   182   $type['date'] = array('#input' => TRUE, '#process' => array('expand_date'), '#element_validate' => array('date_validate'));
       
   183   $type['file'] = array('#input' => TRUE, '#size' => 60);
       
   184 
       
   185   // Form structure
       
   186   $type['item'] = array('#value' => '');
       
   187   $type['hidden'] = array('#input' => TRUE, '#process' => array('form_expand_ahah'));
       
   188   $type['value'] = array('#input' => TRUE);
       
   189   $type['markup'] = array('#prefix' => '', '#suffix' => '');
       
   190   $type['fieldset'] = array('#collapsible' => FALSE, '#collapsed' => FALSE, '#value' => NULL, '#process' => array('form_expand_ahah'));
       
   191   $type['token'] = array('#input' => TRUE);
       
   192   return $type;
       
   193 }
       
   194 
       
   195 /**
       
   196  * Implementation of hook_menu().
       
   197  */
       
   198 function system_menu() {
       
   199   $items['system/files'] = array(
       
   200     'title' => 'File download',
       
   201     'page callback' => 'file_download',
       
   202     'access callback' => TRUE,
       
   203     'type' => MENU_CALLBACK,
       
   204   );
       
   205   $items['admin'] = array(
       
   206     'title' => 'Administer',
       
   207     'access arguments' => array('access administration pages'),
       
   208     'page callback' => 'system_main_admin_page',
       
   209     'weight' => 9,
       
   210     'file' => 'system.admin.inc',
       
   211   );
       
   212   $items['admin/compact'] = array(
       
   213     'title' => 'Compact mode',
       
   214     'page callback' => 'system_admin_compact_page',
       
   215     'access arguments' => array('access administration pages'),
       
   216     'type' => MENU_CALLBACK,
       
   217     'file' => 'system.admin.inc',
       
   218   );
       
   219   $items['admin/by-task'] = array(
       
   220     'title' => 'By task',
       
   221     'page callback' => 'system_main_admin_page',
       
   222     'access arguments' => array('access administration pages'),
       
   223     'file' => 'system.admin.inc',
       
   224     'type' => MENU_DEFAULT_LOCAL_TASK,
       
   225   );
       
   226   $items['admin/by-module'] = array(
       
   227     'title' => 'By module',
       
   228     'page callback' => 'system_admin_by_module',
       
   229     'access arguments' => array('access administration pages'),
       
   230     'file' => 'system.admin.inc',
       
   231     'type' => MENU_LOCAL_TASK,
       
   232     'weight' => 2,
       
   233   );
       
   234   $items['admin/content'] = array(
       
   235     'title' => 'Content management',
       
   236     'description' => "Manage your site's content.",
       
   237     'position' => 'left',
       
   238     'weight' => -10,
       
   239     'page callback' => 'system_admin_menu_block_page',
       
   240     'access arguments' => array('access administration pages'),
       
   241     'file' => 'system.admin.inc',
       
   242   );
       
   243 
       
   244   // menu items that are basically just menu blocks
       
   245   $items['admin/settings'] = array(
       
   246     'title' => 'Site configuration',
       
   247     'description' => 'Adjust basic site configuration options.',
       
   248     'position' => 'right',
       
   249     'weight' => -5,
       
   250     'page callback' => 'system_settings_overview',
       
   251     'access arguments' => array('access administration pages'),
       
   252     'file' => 'system.admin.inc',
       
   253   );
       
   254   $items['admin/build'] = array(
       
   255     'title' => 'Site building',
       
   256     'description' => 'Control how your site looks and feels.',
       
   257     'position' => 'right',
       
   258     'weight' => -10,
       
   259     'page callback' => 'system_admin_menu_block_page',
       
   260     'access arguments' => array('access administration pages'),
       
   261     'file' => 'system.admin.inc',
       
   262   );
       
   263   $items['admin/settings/admin'] = array(
       
   264     'title' => 'Administration theme',
       
   265     'description' => 'Settings for how your administrative pages should look.',
       
   266     'position' => 'left',
       
   267     'page callback' => 'drupal_get_form',
       
   268     'page arguments' => array('system_admin_theme_settings'),
       
   269     'access arguments' => array('administer site configuration'),
       
   270     'block callback' => 'system_admin_theme_settings',
       
   271     'file' => 'system.admin.inc',
       
   272   );
       
   273   // Themes:
       
   274   $items['admin/build/themes'] = array(
       
   275     'title' => 'Themes',
       
   276     'description' => 'Change which theme your site uses or allows users to set.',
       
   277     'page callback' => 'drupal_get_form',
       
   278     'page arguments' => array('system_themes_form', NULL),
       
   279     'access arguments' => array('administer site configuration'),
       
   280     'file' => 'system.admin.inc',
       
   281   );
       
   282   $items['admin/build/themes/select'] = array(
       
   283     'title' => 'List',
       
   284     'description' => 'Select the default theme.',
       
   285     'type' => MENU_DEFAULT_LOCAL_TASK,
       
   286     'weight' => -1,
       
   287   );
       
   288   $items['admin/build/themes/settings'] = array(
       
   289     'title' => 'Configure',
       
   290     'page arguments' => array('system_theme_settings'),
       
   291     'access arguments' => array('administer site configuration'),
       
   292     'type' => MENU_LOCAL_TASK,
       
   293   );
       
   294   // Theme configuration subtabs
       
   295   $items['admin/build/themes/settings/global'] = array(
       
   296     'title' => 'Global settings',
       
   297     'type' => MENU_DEFAULT_LOCAL_TASK,
       
   298     'weight' => -1,
       
   299   );
       
   300 
       
   301   foreach (list_themes() as $theme) {
       
   302     $items['admin/build/themes/settings/'. $theme->name] = array(
       
   303       'title' => $theme->info['name'],
       
   304       'page arguments' => array('system_theme_settings', $theme->name),
       
   305       'type' => MENU_LOCAL_TASK,
       
   306       'access callback' => '_system_themes_access',
       
   307       'access arguments' => array($theme),
       
   308     );
       
   309   }
       
   310 
       
   311   // Modules:
       
   312   $items['admin/build/modules'] = array(
       
   313     'title' => 'Modules',
       
   314     'description' => 'Enable or disable add-on modules for your site.',
       
   315     'page callback' => 'drupal_get_form',
       
   316     'page arguments' => array('system_modules'),
       
   317     'access arguments' => array('administer site configuration'),
       
   318     'file' => 'system.admin.inc',
       
   319   );
       
   320   $items['admin/build/modules/list'] = array(
       
   321     'title' => 'List',
       
   322     'type' => MENU_DEFAULT_LOCAL_TASK,
       
   323   );
       
   324   $items['admin/build/modules/list/confirm'] = array(
       
   325     'title' => 'List',
       
   326     'access arguments' => array('administer site configuration'),
       
   327     'type' => MENU_CALLBACK,
       
   328   );
       
   329   $items['admin/build/modules/uninstall'] = array(
       
   330     'title' => 'Uninstall',
       
   331     'page arguments' => array('system_modules_uninstall'),
       
   332     'access arguments' => array('administer site configuration'),
       
   333     'type' => MENU_LOCAL_TASK,
       
   334   );
       
   335   $items['admin/build/modules/uninstall/confirm'] = array(
       
   336     'title' => 'Uninstall',
       
   337     'access arguments' => array('administer site configuration'),
       
   338     'type' => MENU_CALLBACK,
       
   339   );
       
   340 
       
   341   // Actions:
       
   342   $items['admin/settings/actions'] = array(
       
   343     'title' => 'Actions',
       
   344     'description' => 'Manage the actions defined for your site.',
       
   345     'access arguments' => array('administer actions'),
       
   346     'page callback' => 'system_actions_manage'
       
   347   );
       
   348   $items['admin/settings/actions/manage'] = array(
       
   349     'title' => 'Manage actions',
       
   350     'description' => 'Manage the actions defined for your site.',
       
   351     'page callback' => 'system_actions_manage',
       
   352     'type' => MENU_DEFAULT_LOCAL_TASK,
       
   353     'weight' => -2,
       
   354   );
       
   355   $items['admin/settings/actions/configure'] = array(
       
   356     'title' => 'Configure an advanced action',
       
   357     'page callback' => 'drupal_get_form',
       
   358     'page arguments' => array('system_actions_configure'),
       
   359     'access arguments' => array('administer actions'),
       
   360     'type' => MENU_CALLBACK,
       
   361   );
       
   362   $items['admin/settings/actions/delete/%actions'] = array(
       
   363     'title' => 'Delete action',
       
   364     'description' => 'Delete an action.',
       
   365     'page callback' => 'drupal_get_form',
       
   366     'page arguments' => array('system_actions_delete_form', 4),
       
   367     'access arguments' => array('administer actions'),
       
   368     'type' => MENU_CALLBACK,
       
   369   );
       
   370   $items['admin/settings/actions/orphan'] = array(
       
   371     'title' => 'Remove orphans',
       
   372     'page callback' => 'system_actions_remove_orphans',
       
   373     'access arguments' => array('administer actions'),
       
   374     'type' => MENU_CALLBACK,
       
   375   );
       
   376 
       
   377   // Settings:
       
   378   $items['admin/settings/site-information'] = array(
       
   379     'title' => 'Site information',
       
   380     'description' => 'Change basic site information, such as the site name, slogan, e-mail address, mission, front page and more.',
       
   381     'page callback' => 'drupal_get_form',
       
   382     'page arguments' => array('system_site_information_settings'),
       
   383     'access arguments' => array('administer site configuration'),
       
   384     'file' => 'system.admin.inc',
       
   385   );
       
   386   $items['admin/settings/error-reporting'] = array(
       
   387     'title' => 'Error reporting',
       
   388     'description' => 'Control how Drupal deals with errors including 403/404 errors as well as PHP error reporting.',
       
   389     'page callback' => 'drupal_get_form',
       
   390     'page arguments' => array('system_error_reporting_settings'),
       
   391     'access arguments' => array('administer site configuration'),
       
   392     'file' => 'system.admin.inc',
       
   393   );
       
   394   $items['admin/settings/logging'] = array(
       
   395     'title' => 'Logging and alerts',
       
   396     'description' => "Settings for logging and alerts modules. Various modules can route Drupal's system events to different destination, such as syslog, database, email, ...etc.",
       
   397     'page callback' => 'system_logging_overview',
       
   398     'access arguments' => array('administer site configuration'),
       
   399     'file' => 'system.admin.inc',
       
   400   );
       
   401   $items['admin/settings/performance'] = array(
       
   402     'title' => 'Performance',
       
   403     'description' => 'Enable or disable page caching for anonymous users and set CSS and JS bandwidth optimization options.',
       
   404     'page callback' => 'drupal_get_form',
       
   405     'page arguments' => array('system_performance_settings'),
       
   406     'access arguments' => array('administer site configuration'),
       
   407     'file' => 'system.admin.inc',
       
   408   );
       
   409   $items['admin/settings/file-system'] = array(
       
   410     'title' => 'File system',
       
   411     'description' => 'Tell Drupal where to store uploaded files and how they are accessed.',
       
   412     'page callback' => 'drupal_get_form',
       
   413     'page arguments' => array('system_file_system_settings'),
       
   414     'access arguments' => array('administer site configuration'),
       
   415     'file' => 'system.admin.inc',
       
   416   );
       
   417   $items['admin/settings/image-toolkit'] = array(
       
   418     'title' => 'Image toolkit',
       
   419     'description' => 'Choose which image toolkit to use if you have installed optional toolkits.',
       
   420     'page callback' => 'drupal_get_form',
       
   421     'page arguments' => array('system_image_toolkit_settings'),
       
   422     'access arguments' => array('administer site configuration'),
       
   423     'file' => 'system.admin.inc',
       
   424   );
       
   425   $items['admin/content/rss-publishing'] = array(
       
   426     'title' => 'RSS publishing',
       
   427     'description' => 'Configure the number of items per feed and whether feeds should be titles/teasers/full-text.',
       
   428     'page callback' => 'drupal_get_form',
       
   429     'page arguments' => array('system_rss_feeds_settings'),
       
   430     'access arguments' => array('administer site configuration'),
       
   431     'file' => 'system.admin.inc',
       
   432   );
       
   433   $items['admin/settings/date-time'] = array(
       
   434     'title' => 'Date and time',
       
   435     'description' => "Settings for how Drupal displays date and time, as well as the system's default timezone.",
       
   436     'page callback' => 'drupal_get_form',
       
   437     'page arguments' => array('system_date_time_settings'),
       
   438     'access arguments' => array('administer site configuration'),
       
   439     'file' => 'system.admin.inc',
       
   440   );
       
   441   $items['admin/settings/date-time/lookup'] = array(
       
   442     'title' => 'Date and time lookup',
       
   443     'type' => MENU_CALLBACK,
       
   444     'page callback' => 'system_date_time_lookup',
       
   445     'access arguments' => array('administer site configuration'),
       
   446     'file' => 'system.admin.inc',
       
   447   );
       
   448   $items['admin/settings/site-maintenance'] = array(
       
   449     'title' => 'Site maintenance',
       
   450     'description' => 'Take the site off-line for maintenance or bring it back online.',
       
   451     'page callback' => 'drupal_get_form',
       
   452     'page arguments' => array('system_site_maintenance_settings'),
       
   453     'access arguments' => array('administer site configuration'),
       
   454     'file' => 'system.admin.inc',
       
   455   );
       
   456   $items['admin/settings/clean-urls'] = array(
       
   457     'title' => 'Clean URLs',
       
   458     'description' => 'Enable or disable clean URLs for your site.',
       
   459     'page callback' => 'drupal_get_form',
       
   460     'page arguments' => array('system_clean_url_settings'),
       
   461     'access arguments' => array('administer site configuration'),
       
   462     'file' => 'system.admin.inc',
       
   463   );
       
   464   $items['admin/settings/clean-urls/check'] = array(
       
   465     'title' => 'Clean URL check',
       
   466     'page callback' => 'drupal_json',
       
   467     'page arguments' => array(array('status' => TRUE)),
       
   468     'access callback' => TRUE,
       
   469     'type' => MENU_CALLBACK,
       
   470   );
       
   471 
       
   472   // Reports:
       
   473   $items['admin/reports'] = array(
       
   474     'title' => 'Reports',
       
   475     'description' => 'View reports from system logs and other status information.',
       
   476     'page callback' => 'system_admin_menu_block_page',
       
   477     'access arguments' => array('access site reports'),
       
   478     'weight' => 5,
       
   479     'position' => 'left',
       
   480     'file' => 'system.admin.inc',
       
   481   );
       
   482   $items['admin/reports/status'] = array(
       
   483     'title' => 'Status report',
       
   484     'description' => "Get a status report about your site's operation and any detected problems.",
       
   485     'page callback' => 'system_status',
       
   486     'weight' => 10,
       
   487     'access arguments' => array('administer site configuration'),
       
   488     'file' => 'system.admin.inc',
       
   489   );
       
   490   $items['admin/reports/status/run-cron'] = array(
       
   491     'title' => 'Run cron',
       
   492     'page callback' => 'system_run_cron',
       
   493     'access arguments' => array('administer site configuration'),
       
   494     'type' => MENU_CALLBACK,
       
   495     'file' => 'system.admin.inc',
       
   496   );
       
   497   $items['admin/reports/status/php'] = array(
       
   498     'title' => 'PHP',
       
   499     'page callback' => 'system_php',
       
   500     'access arguments' => array('administer site configuration'),
       
   501     'type' => MENU_CALLBACK,
       
   502     'file' => 'system.admin.inc',
       
   503   );
       
   504   $items['admin/reports/status/sql'] = array(
       
   505     'title' => 'SQL',
       
   506     'page callback' => 'system_sql',
       
   507     'access arguments' => array('administer site configuration'),
       
   508     'type' => MENU_CALLBACK,
       
   509     'file' => 'system.admin.inc',
       
   510   );
       
   511   // Default page for batch operations
       
   512   $items['batch'] = array(
       
   513     'page callback' => 'system_batch_page',
       
   514     'access callback' => TRUE,
       
   515     'type' => MENU_CALLBACK,
       
   516     'file' => 'system.admin.inc',
       
   517   );
       
   518   return $items;
       
   519 }
       
   520 
       
   521 /**
       
   522  * Menu item access callback - only admin or enabled themes can be accessed.
       
   523  */
       
   524 function _system_themes_access($theme) {
       
   525   return user_access('administer site configuration') && ($theme->status || $theme->name == variable_get('admin_theme', '0'));
       
   526 }
       
   527 
       
   528 /**
       
   529  * Implementation of hook_init().
       
   530  */
       
   531 function system_init() {
       
   532   // Use the administrative theme if the user is looking at a page in the admin/* path.
       
   533   if (arg(0) == 'admin' || (variable_get('node_admin_theme', '0') && arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit'))) {
       
   534     global $custom_theme;
       
   535     $custom_theme = variable_get('admin_theme', '0');
       
   536     drupal_add_css(drupal_get_path('module', 'system') .'/admin.css', 'module');
       
   537   }
       
   538 
       
   539   // Add the CSS for this module.
       
   540   drupal_add_css(drupal_get_path('module', 'system') .'/defaults.css', 'module');
       
   541   drupal_add_css(drupal_get_path('module', 'system') .'/system.css', 'module');
       
   542   drupal_add_css(drupal_get_path('module', 'system') .'/system-menus.css', 'module');
       
   543 }
       
   544 
       
   545 /**
       
   546  * Implementation of hook_user().
       
   547  *
       
   548  * Allows users to individually set their theme and time zone.
       
   549  */
       
   550 function system_user($type, $edit, &$user, $category = NULL) {
       
   551   if ($type == 'form' && $category == 'account') {
       
   552     $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);
       
   553 
       
   554     if (variable_get('configurable_timezones', 1)) {
       
   555       $zones = _system_zonelist();
       
   556       $form['timezone'] = array(
       
   557         '#type' => 'fieldset',
       
   558         '#title' => t('Locale settings'),
       
   559         '#weight' => 6,
       
   560         '#collapsible' => TRUE,
       
   561       );
       
   562       $form['timezone']['timezone'] = array(
       
   563         '#type' => 'select',
       
   564         '#title' => t('Time zone'),
       
   565         '#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
       
   566         '#options' => $zones,
       
   567         '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.'),
       
   568       );
       
   569     }
       
   570 
       
   571     return $form;
       
   572   }
       
   573 }
       
   574 
       
   575 /**
       
   576  * Implementation of hook_block().
       
   577  *
       
   578  * Generate a block with a promotional link to Drupal.org.
       
   579  */
       
   580 function system_block($op = 'list', $delta = 0, $edit = NULL) {
       
   581   switch ($op) {
       
   582     case 'list':
       
   583       $blocks[0] = array(
       
   584         'info' => t('Powered by Drupal'),
       
   585         'weight' => '10',
       
   586          // Not worth caching.
       
   587         'cache' => BLOCK_NO_CACHE,
       
   588       );
       
   589       return $blocks;
       
   590     case 'configure':
       
   591       // Compile a list of fields to show
       
   592       $form['wrapper']['color'] = array(
       
   593         '#type' => 'select',
       
   594         '#title' => t('Badge color'),
       
   595         '#default_value' => variable_get('drupal_badge_color', 'powered-blue'),
       
   596         '#options' => array('powered-black' => t('Black'), 'powered-blue' => t('Blue'), 'powered-gray' => t('Gray')),
       
   597       );
       
   598       $form['wrapper']['size'] = array(
       
   599         '#type' => 'select',
       
   600         '#title' => t('Badge size'),
       
   601         '#default_value' => variable_get('drupal_badge_size', '80x15'),
       
   602         '#options' => array('80x15' => t('Small'), '88x31' => t('Medium'), '135x42' => t('Large')),
       
   603       );
       
   604       return $form;
       
   605     case 'save':
       
   606       variable_set('drupal_badge_color', $edit['color']);
       
   607       variable_set('drupal_badge_size', $edit['size']);
       
   608       break;
       
   609     case 'view':
       
   610       $image_path = 'misc/'. variable_get('drupal_badge_color', 'powered-blue') .'-'. variable_get('drupal_badge_size', '80x15') .'.png';
       
   611       $block['subject'] = NULL; // Don't display a title
       
   612       $block['content'] = theme('system_powered_by', $image_path);
       
   613       return $block;
       
   614   }
       
   615 }
       
   616 
       
   617 /**
       
   618  * Provide a single block on the administration overview page.
       
   619  *
       
   620  * @param $item
       
   621  *   The menu item to be displayed.
       
   622  */
       
   623 function system_admin_menu_block($item) {
       
   624   $content = array();
       
   625   if (!isset($item['mlid'])) {
       
   626     $item += db_fetch_array(db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = '%s' AND module = 'system'", $item['path']));
       
   627   }
       
   628   $result = db_query("
       
   629     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.*
       
   630     FROM {menu_links} ml
       
   631     LEFT JOIN {menu_router} m ON ml.router_path = m.path
       
   632     WHERE ml.plid = %d AND ml.menu_name = '%s' AND hidden = 0", $item['mlid'], $item['menu_name']);
       
   633   while ($item = db_fetch_array($result)) {
       
   634     _menu_link_translate($item);
       
   635     if (!$item['access']) {
       
   636       continue;
       
   637     }
       
   638     // The link 'description' either derived from the hook_menu 'description' or
       
   639     // entered by the user via menu module is saved as the title attribute.
       
   640     if (!empty($item['localized_options']['attributes']['title'])) {
       
   641       $item['description'] = $item['localized_options']['attributes']['title'];
       
   642     }
       
   643     // Prepare for sorting as in function _menu_tree_check_access().
       
   644     // The weight is offset so it is always positive, with a uniform 5-digits.
       
   645     $content[(50000 + $item['weight']) .' '. $item['title'] .' '. $item['mlid']] = $item;
       
   646   }
       
   647   ksort($content);
       
   648   return $content;
       
   649 }
       
   650 
       
   651 /**
       
   652  * Process admin theme form submissions.
       
   653  */
       
   654 function system_admin_theme_submit($form, &$form_state) {
       
   655   // If we're changing themes, make sure the theme has its blocks initialized.
       
   656   if ($form_state['values']['admin_theme'] && $form_state['values']['admin_theme'] != variable_get('admin_theme', '0')) {
       
   657     $result = db_result(db_query("SELECT COUNT(*) FROM {blocks} WHERE theme = '%s'", $form_state['values']['admin_theme']));
       
   658     if (!$result) {
       
   659       system_initialize_theme_blocks($form_state['values']['admin_theme']);
       
   660     }
       
   661   }
       
   662 }
       
   663 
       
   664 /**
       
   665  * Returns a fieldset containing the theme select form.
       
   666  *
       
   667  * @param $description
       
   668  *    description of the fieldset
       
   669  * @param $default_value
       
   670  *    default value of theme radios
       
   671  * @param $weight
       
   672  *    weight of the fieldset
       
   673  * @return
       
   674  *    a form array
       
   675  */
       
   676 function system_theme_select_form($description = '', $default_value = '', $weight = 0) {
       
   677   if (user_access('select different theme')) {
       
   678     $enabled = array();
       
   679     $themes = list_themes();
       
   680 
       
   681     foreach ($themes as $theme) {
       
   682       if ($theme->status) {
       
   683         $enabled[] = $theme;
       
   684       }
       
   685     }
       
   686 
       
   687     if (count($enabled) > 1) {
       
   688       ksort($enabled);
       
   689 
       
   690       $form['themes'] = array(
       
   691         '#type' => 'fieldset',
       
   692         '#title' => t('Theme configuration'),
       
   693         '#description' => $description,
       
   694         '#collapsible' => TRUE,
       
   695         '#theme' => 'system_theme_select_form'
       
   696       );
       
   697 
       
   698       foreach ($enabled as $info) {
       
   699         // For the default theme, revert to an empty string so the user's theme updates when the site theme is changed.
       
   700         $info->key = $info->name == variable_get('theme_default', 'garland') ? '' : $info->name;
       
   701 
       
   702         $screenshot = NULL;
       
   703         $theme_key = $info->name;
       
   704         while ($theme_key) {
       
   705           if (file_exists($themes[$theme_key]->info['screenshot'])) {
       
   706             $screenshot = $themes[$theme_key]->info['screenshot'];
       
   707             break;
       
   708           }
       
   709           $theme_key = isset($themes[$theme_key]->info['base theme']) ? $themes[$theme_key]->info['base theme'] : NULL;
       
   710         }
       
   711 
       
   712         $screenshot = $screenshot ? theme('image', $screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), FALSE) : t('no screenshot');
       
   713 
       
   714         $form['themes'][$info->key]['screenshot'] = array('#value' => $screenshot);
       
   715         $form['themes'][$info->key]['description'] = array('#type' => 'item', '#title' => $info->name, '#value' => dirname($info->filename) . ($info->name == variable_get('theme_default', 'garland') ? '<br /> <em>'. t('(site default theme)') .'</em>' : ''));
       
   716         $options[$info->key] = '';
       
   717       }
       
   718 
       
   719       $form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $default_value ? $default_value : '');
       
   720       $form['#weight'] = $weight;
       
   721       return $form;
       
   722     }
       
   723   }
       
   724 }
       
   725 
       
   726 /**
       
   727  * Checks the existence of the directory specified in $form_element. This
       
   728  * function is called from the system_settings form to check both the
       
   729  * file_directory_path and file_directory_temp directories. If validation
       
   730  * fails, the form element is flagged with an error from within the
       
   731  * file_check_directory function.
       
   732  *
       
   733  * @param $form_element
       
   734  *   The form element containing the name of the directory to check.
       
   735  */
       
   736 function system_check_directory($form_element) {
       
   737   file_check_directory($form_element['#value'], FILE_CREATE_DIRECTORY, $form_element['#parents'][0]);
       
   738   return $form_element;
       
   739 }
       
   740 
       
   741 /**
       
   742  * Retrieves the current status of an array of files in the system table.
       
   743  *
       
   744  * @param $files
       
   745  *   An array of files to check.
       
   746  * @param $type
       
   747  *   The type of the files.
       
   748  */
       
   749 function system_get_files_database(&$files, $type) {
       
   750   // Extract current files from database.
       
   751   $result = db_query("SELECT filename, name, type, status, throttle, schema_version FROM {system} WHERE type = '%s'", $type);
       
   752   while ($file = db_fetch_object($result)) {
       
   753     if (isset($files[$file->name]) && is_object($files[$file->name])) {
       
   754       $file->old_filename = $file->filename;
       
   755       foreach ($file as $key => $value) {
       
   756         if (!isset($files[$file->name]) || !isset($files[$file->name]->$key)) {
       
   757           $files[$file->name]->$key = $value;
       
   758         }
       
   759       }
       
   760     }
       
   761   }
       
   762 }
       
   763 
       
   764 /**
       
   765  * Prepare defaults for themes.
       
   766  *
       
   767  * @return
       
   768  *   An array of default themes settings.
       
   769  */
       
   770 function system_theme_default() {
       
   771   return array(
       
   772     'regions' => array(
       
   773       'left' => 'Left sidebar',
       
   774       'right' => 'Right sidebar',
       
   775       'content' => 'Content',
       
   776       'header' => 'Header',
       
   777       'footer' => 'Footer',
       
   778     ),
       
   779     'description' => '',
       
   780     'features' => array(
       
   781       'comment_user_picture',
       
   782       'favicon',
       
   783       'mission',
       
   784       'logo',
       
   785       'name',
       
   786       'node_user_picture',
       
   787       'search',
       
   788       'slogan',
       
   789       'primary_links',
       
   790       'secondary_links',
       
   791     ),
       
   792     'stylesheets' => array(
       
   793       'all' => array('style.css')
       
   794     ),
       
   795     'scripts' => array('script.js'),
       
   796     'screenshot' => 'screenshot.png',
       
   797     'php' => DRUPAL_MINIMUM_PHP,
       
   798   );
       
   799 }
       
   800 
       
   801 /**
       
   802  * Collect data about all currently available themes.
       
   803  *
       
   804  * @return
       
   805  *   Array of all available themes and their data.
       
   806  */
       
   807 function system_theme_data() {
       
   808   // Scan the installation theme .info files and their engines.
       
   809   $themes = _system_theme_data();
       
   810 
       
   811   // Extract current files from database.
       
   812   system_get_files_database($themes, 'theme');
       
   813 
       
   814   db_query("DELETE FROM {system} WHERE type = 'theme'");
       
   815 
       
   816   foreach ($themes as $theme) {
       
   817     if (!isset($theme->owner)) {
       
   818       $theme->owner = '';
       
   819     }
       
   820 
       
   821     db_query("INSERT INTO {system} (name, owner, info, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d)", $theme->name, $theme->owner, serialize($theme->info), 'theme', $theme->filename, isset($theme->status) ? $theme->status : 0, 0, 0);
       
   822   }
       
   823 
       
   824   return $themes;
       
   825 }
       
   826 
       
   827 /**
       
   828  * Helper function to scan and collect theme .info data and their engines.
       
   829  *
       
   830  * @return
       
   831  *   An associative array of themes information.
       
   832  */
       
   833 function _system_theme_data() {
       
   834   static $themes_info = array();
       
   835 
       
   836   if (empty($themes_info)) {
       
   837     // Find themes
       
   838     $themes = drupal_system_listing('\.info$', 'themes');
       
   839     // Find theme engines
       
   840     $engines = drupal_system_listing('\.engine$', 'themes/engines');
       
   841 
       
   842     $defaults = system_theme_default();
       
   843 
       
   844     $sub_themes = array();
       
   845     // Read info files for each theme
       
   846     foreach ($themes as $key => $theme) {
       
   847       $themes[$key]->info = drupal_parse_info_file($theme->filename) + $defaults;
       
   848 
       
   849       // Invoke hook_system_info_alter() to give installed modules a chance to
       
   850       // modify the data in the .info files if necessary.
       
   851       drupal_alter('system_info', $themes[$key]->info, $themes[$key]);
       
   852 
       
   853       if (!empty($themes[$key]->info['base theme'])) {
       
   854         $sub_themes[] = $key;
       
   855       }
       
   856       if (empty($themes[$key]->info['engine'])) {
       
   857         $filename = dirname($themes[$key]->filename) .'/'. $themes[$key]->name .'.theme';
       
   858         if (file_exists($filename)) {
       
   859           $themes[$key]->owner = $filename;
       
   860           $themes[$key]->prefix = $key;
       
   861         }
       
   862       }
       
   863       else {
       
   864         $engine = $themes[$key]->info['engine'];
       
   865         if (isset($engines[$engine])) {
       
   866           $themes[$key]->owner = $engines[$engine]->filename;
       
   867           $themes[$key]->prefix = $engines[$engine]->name;
       
   868           $themes[$key]->template = TRUE;
       
   869         }
       
   870       }
       
   871 
       
   872       // Give the stylesheets proper path information.
       
   873       $pathed_stylesheets = array();
       
   874       foreach ($themes[$key]->info['stylesheets'] as $media => $stylesheets) {
       
   875         foreach ($stylesheets as $stylesheet) {
       
   876           $pathed_stylesheets[$media][$stylesheet] = dirname($themes[$key]->filename) .'/'. $stylesheet;
       
   877         }
       
   878       }
       
   879       $themes[$key]->info['stylesheets'] = $pathed_stylesheets;
       
   880 
       
   881       // Give the scripts proper path information.
       
   882       $scripts = array();
       
   883       foreach ($themes[$key]->info['scripts'] as $script) {
       
   884         $scripts[$script] = dirname($themes[$key]->filename) .'/'. $script;
       
   885       }
       
   886       $themes[$key]->info['scripts'] = $scripts;
       
   887       // Give the screenshot proper path information.
       
   888       if (!empty($themes[$key]->info['screenshot'])) {
       
   889         $themes[$key]->info['screenshot'] = dirname($themes[$key]->filename) .'/'. $themes[$key]->info['screenshot'];
       
   890       }
       
   891     }
       
   892 
       
   893     // Now that we've established all our master themes, go back and fill in
       
   894     // data for subthemes.
       
   895     foreach ($sub_themes as $key) {
       
   896       $base_key = system_find_base_theme($themes, $key);
       
   897       if (!$base_key) {
       
   898         continue;
       
   899       }
       
   900       // Copy the 'owner' and 'engine' over if the top level theme uses a
       
   901       // theme engine.
       
   902       if (isset($themes[$base_key]->owner)) {
       
   903         if (isset($themes[$base_key]->info['engine'])) {
       
   904           $themes[$key]->info['engine'] = $themes[$base_key]->info['engine'];
       
   905           $themes[$key]->owner = $themes[$base_key]->owner;
       
   906           $themes[$key]->prefix = $themes[$base_key]->prefix;
       
   907         }
       
   908         else {
       
   909           $themes[$key]->prefix = $key;
       
   910         }
       
   911       }
       
   912     }
       
   913 
       
   914     $themes_info = $themes;
       
   915   }
       
   916 
       
   917   return $themes_info;
       
   918 }
       
   919 
       
   920 /**
       
   921  * Recursive function to find the top level base theme. Themes can inherit
       
   922  * templates and function implementations from earlier themes.
       
   923  *
       
   924  * @param $themes
       
   925  *   An array of available themes.
       
   926  * @param $key
       
   927  *   The name of the theme whose base we are looking for.
       
   928  * @param $used_keys
       
   929  *   A recursion parameter preventing endless loops.
       
   930  * @return
       
   931  *   Returns the top level parent that has no ancestor or returns NULL if there isn't a valid parent.
       
   932  */
       
   933 function system_find_base_theme($themes, $key, $used_keys = array()) {
       
   934   $base_key = $themes[$key]->info['base theme'];
       
   935   // Does the base theme exist?
       
   936   if (!isset($themes[$base_key])) {
       
   937     return NULL;
       
   938   }
       
   939 
       
   940   // Is the base theme itself a child of another theme?
       
   941   if (isset($themes[$base_key]->info['base theme'])) {
       
   942     // Prevent loops.
       
   943     if (!empty($used_keys[$base_key])) {
       
   944       return NULL;
       
   945     }
       
   946     $used_keys[$base_key] = TRUE;
       
   947     return system_find_base_theme($themes, $base_key, $used_keys);
       
   948   }
       
   949   // If we get here, then this is our parent theme.
       
   950   return $base_key;
       
   951 }
       
   952 
       
   953 /**
       
   954  * Get a list of available regions from a specified theme.
       
   955  *
       
   956  * @param $theme_key
       
   957  *   The name of a theme.
       
   958  * @return
       
   959  *   An array of regions in the form $region['name'] = 'description'.
       
   960  */
       
   961 function system_region_list($theme_key) {
       
   962   static $list = array();
       
   963 
       
   964   if (!array_key_exists($theme_key, $list)) {
       
   965     $info = unserialize(db_result(db_query("SELECT info FROM {system} WHERE type = 'theme' AND name = '%s'", $theme_key)));
       
   966     $list[$theme_key] = array_map('t', $info['regions']);
       
   967   }
       
   968 
       
   969   return $list[$theme_key];
       
   970 }
       
   971 
       
   972 /**
       
   973  * Get the name of the default region for a given theme.
       
   974  *
       
   975  * @param $theme
       
   976  *   The name of a theme.
       
   977  * @return
       
   978  *   A string that is the region name.
       
   979  */
       
   980 function system_default_region($theme) {
       
   981   $regions = array_keys(system_region_list($theme));
       
   982   return isset($regions[0]) ? $regions[0] : '';
       
   983 }
       
   984 
       
   985 /**
       
   986  * Assign an initial, default set of blocks for a theme.
       
   987  *
       
   988  * This function is called the first time a new theme is enabled. The new theme
       
   989  * gets a copy of the default theme's blocks, with the difference that if a
       
   990  * particular region isn't available in the new theme, the block is assigned
       
   991  * to the new theme's default region.
       
   992  *
       
   993  * @param $theme
       
   994  *   The name of a theme.
       
   995  */
       
   996 function system_initialize_theme_blocks($theme) {
       
   997   // Initialize theme's blocks if none already registered.
       
   998   if (!(db_result(db_query("SELECT COUNT(*) FROM {blocks} WHERE theme = '%s'", $theme)))) {
       
   999     $default_theme = variable_get('theme_default', 'garland');
       
  1000     $regions = system_region_list($theme);
       
  1001     $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
       
  1002     while ($block = db_fetch_array($result)) {
       
  1003       // If the region isn't supported by the theme, assign the block to the theme's default region.
       
  1004       if (!array_key_exists($block['region'], $regions)) {
       
  1005         $block['region'] = system_default_region($theme);
       
  1006       }
       
  1007       db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d, %d)",
       
  1008           $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle'], $block['cache']);
       
  1009     }
       
  1010   }
       
  1011 }
       
  1012 
       
  1013 /**
       
  1014  * Add default buttons to a form and set its prefix.
       
  1015  *
       
  1016  * @ingroup forms
       
  1017  * @see system_settings_form_submit()
       
  1018  * @param $form
       
  1019  *   An associative array containing the structure of the form.
       
  1020  * @return
       
  1021  *   The form structure.
       
  1022  */
       
  1023 function system_settings_form($form) {
       
  1024   $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
       
  1025   $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
       
  1026 
       
  1027   if (!empty($_POST) && form_get_errors()) {
       
  1028     drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
       
  1029   }
       
  1030   $form['#submit'][] = 'system_settings_form_submit';
       
  1031   $form['#theme'] = 'system_settings_form';
       
  1032   return $form;
       
  1033 }
       
  1034 
       
  1035 /**
       
  1036  * Execute the system_settings_form.
       
  1037  *
       
  1038  * If you want node type configure style handling of your checkboxes,
       
  1039  * add an array_filter value to your form.
       
  1040  */
       
  1041 function system_settings_form_submit($form, &$form_state) {
       
  1042   $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
       
  1043 
       
  1044   // Exclude unnecessary elements.
       
  1045   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']);
       
  1046 
       
  1047   foreach ($form_state['values'] as $key => $value) {
       
  1048     if ($op == t('Reset to defaults')) {
       
  1049       variable_del($key);
       
  1050     }
       
  1051     else {
       
  1052       if (is_array($value) && isset($form_state['values']['array_filter'])) {
       
  1053         $value = array_keys(array_filter($value));
       
  1054       }
       
  1055       variable_set($key, $value);
       
  1056     }
       
  1057   }
       
  1058   if ($op == t('Reset to defaults')) {
       
  1059     drupal_set_message(t('The configuration options have been reset to their default values.'));
       
  1060   }
       
  1061   else {
       
  1062     drupal_set_message(t('The configuration options have been saved.'));
       
  1063   }
       
  1064 
       
  1065   cache_clear_all();
       
  1066   drupal_rebuild_theme_registry();
       
  1067 }
       
  1068 
       
  1069 /**
       
  1070  * Helper function to sort requirements.
       
  1071  */
       
  1072 function _system_sort_requirements($a, $b) {
       
  1073   if (!isset($a['weight'])) {
       
  1074     if (!isset($b['weight'])) {
       
  1075       return strcmp($a['title'], $b['title']);
       
  1076     }
       
  1077     return -$b['weight'];
       
  1078   }
       
  1079   return isset($b['weight']) ? $a['weight'] - $b['weight'] : $a['weight'];
       
  1080 }
       
  1081 
       
  1082 /**
       
  1083  * Implementation of hook_node_type().
       
  1084  *
       
  1085  * Updates theme settings after a node type change.
       
  1086  */
       
  1087 function system_node_type($op, $info) {
       
  1088   if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) {
       
  1089     $old = 'toggle_node_info_'. $info->old_type;
       
  1090     $new = 'toggle_node_info_'. $info->type;
       
  1091 
       
  1092     $theme_settings = variable_get('theme_settings', array());
       
  1093     if (isset($theme_settings[$old])) {
       
  1094       $theme_settings[$new] = $theme_settings[$old];
       
  1095       unset($theme_settings[$old]);
       
  1096       variable_set('theme_settings', $theme_settings);
       
  1097     }
       
  1098   }
       
  1099 }
       
  1100 
       
  1101 /**
       
  1102  * Output a confirmation form
       
  1103  *
       
  1104  * This function returns a complete form for confirming an action. A link is
       
  1105  * offered to go back to the item that is being changed in case the user changes
       
  1106  * his/her mind.
       
  1107  *
       
  1108  * If the submit handler for this form is invoked, the user successfully
       
  1109  * confirmed the action. You should never directly inspect $_POST to see if an
       
  1110  * action was confirmed.
       
  1111  *
       
  1112  * @ingroup forms
       
  1113  * @param $form
       
  1114  *   Additional elements to inject into the form, for example hidden elements.
       
  1115  * @param $question
       
  1116  *   The question to ask the user (e.g. "Are you sure you want to delete the
       
  1117  *   block <em>foo</em>?").
       
  1118  * @param $path
       
  1119  *   The page to go to if the user denies the action.
       
  1120  *   Can be either a drupal path, or an array with the keys 'path', 'query', 'fragment'.
       
  1121  * @param $description
       
  1122  *   Additional text to display (defaults to "This action cannot be undone.").
       
  1123  * @param $yes
       
  1124  *   A caption for the button which confirms the action (e.g. "Delete",
       
  1125  *   "Replace", ...).
       
  1126  * @param $no
       
  1127  *   A caption for the link which denies the action (e.g. "Cancel").
       
  1128  * @param $name
       
  1129  *   The internal name used to refer to the confirmation item.
       
  1130  * @return
       
  1131  *   The form.
       
  1132  */
       
  1133 function confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm') {
       
  1134   $description = isset($description) ? $description : t('This action cannot be undone.');
       
  1135 
       
  1136   // Prepare cancel link
       
  1137   $query = $fragment = NULL;
       
  1138   if (is_array($path)) {
       
  1139     $query = isset($path['query']) ? $path['query'] : NULL;
       
  1140     $fragment = isset($path['fragment']) ? $path['fragment'] : NULL;
       
  1141     $path = isset($path['path']) ? $path['path'] : NULL;
       
  1142   }
       
  1143   $cancel = l($no ? $no : t('Cancel'), $path, array('query' => $query, 'fragment' => $fragment));
       
  1144 
       
  1145   drupal_set_title($question);
       
  1146 
       
  1147   // Confirm form fails duplication check, as the form values rarely change -- so skip it.
       
  1148   $form['#skip_duplicate_check'] = TRUE;
       
  1149 
       
  1150   $form['#attributes'] = array('class' => 'confirmation');
       
  1151   $form['description'] = array('#value' => $description);
       
  1152   $form[$name] = array('#type' => 'hidden', '#value' => 1);
       
  1153 
       
  1154   $form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
       
  1155   $form['actions']['submit'] = array('#type' => 'submit', '#value' => $yes ? $yes : t('Confirm'));
       
  1156   $form['actions']['cancel'] = array('#value' => $cancel);
       
  1157   $form['#theme'] = 'confirm_form';
       
  1158   return $form;
       
  1159 }
       
  1160 
       
  1161 /**
       
  1162  * Determine if a user is in compact mode.
       
  1163  */
       
  1164 function system_admin_compact_mode() {
       
  1165   global $user;
       
  1166   return (isset($user->admin_compact_mode)) ? $user->admin_compact_mode : variable_get('admin_compact_mode', FALSE);
       
  1167 }
       
  1168 
       
  1169 /**
       
  1170  * Generate a list of tasks offered by a specified module.
       
  1171  *
       
  1172  * @param $module
       
  1173  *   Module name.
       
  1174  * @return
       
  1175  *   An array of task links.
       
  1176  */
       
  1177 function system_get_module_admin_tasks($module) {
       
  1178   static $items;
       
  1179 
       
  1180   $admin_access = user_access('administer permissions');
       
  1181   $admin_tasks = array();
       
  1182 
       
  1183   if (!isset($items)) {
       
  1184     $result = db_query("
       
  1185        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.*
       
  1186        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");
       
  1187     $items = array();
       
  1188     while ($item = db_fetch_array($result)) {
       
  1189       _menu_link_translate($item);
       
  1190       if ($item['access']) {
       
  1191         $items[$item['router_path']] = $item;
       
  1192       }
       
  1193     }
       
  1194   }
       
  1195   $admin_tasks = array();
       
  1196   $admin_task_count = 0;
       
  1197   // Check for permissions.
       
  1198   if (module_hook($module, 'perm') && $admin_access) {
       
  1199     $admin_tasks[-1] = l(t('Configure permissions'), 'admin/user/permissions', array('fragment' => 'module-'. $module));
       
  1200   }
       
  1201 
       
  1202   // Check for menu items that are admin links.
       
  1203   if ($menu = module_invoke($module, 'menu')) {
       
  1204     foreach (array_keys($menu) as $path) {
       
  1205       if (isset($items[$path])) {
       
  1206         $admin_tasks[$items[$path]['title'] . $admin_task_count ++] = l($items[$path]['title'], $path);
       
  1207       }
       
  1208     }
       
  1209   }
       
  1210 
       
  1211   return $admin_tasks;
       
  1212 }
       
  1213 
       
  1214 /**
       
  1215  * Implementation of hook_cron().
       
  1216  *
       
  1217  * Remove older rows from flood and batch table. Remove old temporary files.
       
  1218  */
       
  1219 function system_cron() {
       
  1220   // Cleanup the flood.
       
  1221   db_query('DELETE FROM {flood} WHERE timestamp < %d', time() - 3600);
       
  1222   // Cleanup the batch table.
       
  1223   db_query('DELETE FROM {batch} WHERE timestamp < %d', time() - 864000);
       
  1224 
       
  1225   // Remove temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
       
  1226   $result = db_query('SELECT * FROM {files} WHERE status = %d and timestamp < %d', FILE_STATUS_TEMPORARY, time() - DRUPAL_MAXIMUM_TEMP_FILE_AGE);
       
  1227   while ($file = db_fetch_object($result)) {
       
  1228     if (file_exists($file->filepath)) {
       
  1229       // If files that exist cannot be deleted, continue so the database remains
       
  1230       // consistent.
       
  1231       if (!file_delete($file->filepath)) {
       
  1232         watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' => $file->filepath), 'error');
       
  1233         continue;
       
  1234       }
       
  1235     }
       
  1236     db_query('DELETE FROM {files} WHERE fid = %d', $file->fid);
       
  1237   }
       
  1238   $core = array('cache', 'cache_block', 'cache_filter', 'cache_page', 'cache_form', 'cache_menu');
       
  1239   $cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
       
  1240   foreach ($cache_tables as $table) {
       
  1241     cache_clear_all(NULL, $table);
       
  1242   }
       
  1243 }
       
  1244 
       
  1245 /**
       
  1246  * Implementation of hook_hook_info().
       
  1247  */
       
  1248 function system_hook_info() {
       
  1249   return array(
       
  1250     'system' => array(
       
  1251       'cron' => array(
       
  1252         'run' => array(
       
  1253           'runs when' => t('When cron runs'),
       
  1254         ),
       
  1255       ),
       
  1256     ),
       
  1257   );
       
  1258 }
       
  1259 
       
  1260 /**
       
  1261  * Implementation of hook_action_info().
       
  1262  */
       
  1263 function system_action_info() {
       
  1264   return array(
       
  1265     'system_message_action' => array(
       
  1266       'type' => 'system',
       
  1267       'description' => t('Display a message to the user'),
       
  1268       'configurable' => TRUE,
       
  1269       'hooks' => array(
       
  1270         'nodeapi' => array('view', 'insert', 'update', 'delete'),
       
  1271         'comment' => array('view', 'insert', 'update', 'delete'),
       
  1272         'user' => array('view', 'insert', 'update', 'delete', 'login'),
       
  1273         'taxonomy' => array('insert', 'update', 'delete'),
       
  1274       ),
       
  1275     ),
       
  1276     'system_send_email_action' => array(
       
  1277       'description' => t('Send e-mail'),
       
  1278       'type' => 'system',
       
  1279       'configurable' => TRUE,
       
  1280       'hooks' => array(
       
  1281         'nodeapi' => array('view', 'insert', 'update', 'delete'),
       
  1282         'comment' => array('view', 'insert', 'update', 'delete'),
       
  1283         'user' => array('view', 'insert', 'update', 'delete', 'login'),
       
  1284         'taxonomy' => array('insert', 'update', 'delete'),
       
  1285       )
       
  1286     ),
       
  1287     'system_goto_action' => array(
       
  1288       'description' => t('Redirect to URL'),
       
  1289       'type' => 'system',
       
  1290       'configurable' => TRUE,
       
  1291       'hooks' => array(
       
  1292         'nodeapi' => array('view', 'insert', 'update', 'delete'),
       
  1293         'comment' => array('view', 'insert', 'update', 'delete'),
       
  1294         'user' => array('view', 'insert', 'update', 'delete', 'login'),
       
  1295       )
       
  1296     )
       
  1297   );
       
  1298 }
       
  1299 
       
  1300 /**
       
  1301  * Menu callback. Display an overview of available and configured actions.
       
  1302  */
       
  1303 function system_actions_manage() {
       
  1304   $output = '';
       
  1305   $actions = actions_list();
       
  1306   actions_synchronize($actions);
       
  1307   $actions_map = actions_actions_map($actions);
       
  1308   $options = array(t('Choose an advanced action'));
       
  1309   $unconfigurable = array();
       
  1310 
       
  1311   foreach ($actions_map as $key => $array) {
       
  1312     if ($array['configurable']) {
       
  1313       $options[$key] = $array['description'] .'...';
       
  1314     }
       
  1315     else {
       
  1316       $unconfigurable[] = $array;
       
  1317     }
       
  1318   }
       
  1319 
       
  1320   $row = array();
       
  1321   $instances_present = db_fetch_object(db_query("SELECT aid FROM {actions} WHERE parameters <> ''"));
       
  1322   $header = array(
       
  1323     array('data' => t('Action type'), 'field' => 'type'),
       
  1324     array('data' => t('Description'), 'field' => 'description'),
       
  1325     array('data' => $instances_present ? t('Operations') : '', 'colspan' => '2')
       
  1326   );
       
  1327   $sql = 'SELECT * FROM {actions}';
       
  1328   $result = pager_query($sql . tablesort_sql($header), 50);
       
  1329   while ($action = db_fetch_object($result)) {
       
  1330     $row[] = array(
       
  1331       array('data' => $action->type),
       
  1332       array('data' => $action->description),
       
  1333       array('data' => $action->parameters ? l(t('configure'), "admin/settings/actions/configure/$action->aid") : ''),
       
  1334       array('data' => $action->parameters ? l(t('delete'), "admin/settings/actions/delete/$action->aid") : '')
       
  1335     );
       
  1336   }
       
  1337 
       
  1338   if ($row) {
       
  1339     $pager = theme('pager', NULL, 50, 0);
       
  1340     if (!empty($pager)) {
       
  1341       $row[] = array(array('data' => $pager, 'colspan' => '3'));
       
  1342     }
       
  1343     $output .= '<h3>'. t('Actions available to Drupal:') .'</h3>';
       
  1344     $output .= theme('table', $header, $row);
       
  1345   }
       
  1346 
       
  1347   if ($actions_map) {
       
  1348     $output .= drupal_get_form('system_actions_manage_form', $options);
       
  1349   }
       
  1350 
       
  1351   return $output;
       
  1352 }
       
  1353 
       
  1354 /**
       
  1355  * Define the form for the actions overview page.
       
  1356  *
       
  1357  * @see system_actions_manage_form_submit()
       
  1358  * @ingroup forms
       
  1359  * @param $form_state
       
  1360  *   An associative array containing the current state of the form; not used.
       
  1361  * @param $options
       
  1362  *   An array of configurable actions.
       
  1363  * @return
       
  1364  *   Form definition.
       
  1365  */
       
  1366 function system_actions_manage_form($form_state, $options = array()) {
       
  1367   $form['parent'] = array(
       
  1368     '#type' => 'fieldset',
       
  1369     '#title' => t('Make a new advanced action available'),
       
  1370     '#prefix' => '<div class="container-inline">',
       
  1371     '#suffix' => '</div>',
       
  1372   );
       
  1373   $form['parent']['action'] = array(
       
  1374     '#type' => 'select',
       
  1375     '#default_value' => '',
       
  1376     '#options' => $options,
       
  1377     '#description' => '',
       
  1378   );
       
  1379   $form['parent']['buttons']['submit'] = array(
       
  1380     '#type' => 'submit',
       
  1381     '#value' => t('Create'),
       
  1382   );
       
  1383   return $form;
       
  1384 }
       
  1385 
       
  1386 /**
       
  1387  * Process system_actions_manage form submissions.
       
  1388  */
       
  1389 function system_actions_manage_form_submit($form, &$form_state) {
       
  1390   if ($form_state['values']['action']) {
       
  1391     $form_state['redirect'] = 'admin/settings/actions/configure/'. $form_state['values']['action'];
       
  1392   }
       
  1393 }
       
  1394 
       
  1395 /**
       
  1396  * Menu callback. Create the form for configuration of a single action.
       
  1397  *
       
  1398  * We provide the "Description" field. The rest of the form
       
  1399  * is provided by the action. We then provide the Save button.
       
  1400  * Because we are combining unknown form elements with the action
       
  1401  * configuration form, we use actions_ prefix on our elements.
       
  1402  *
       
  1403  * @see system_actions_configure_validate()
       
  1404  * @see system_actions_configure_submit()
       
  1405  * @param $action
       
  1406  *   md5 hash of action ID or an integer. If it's an md5 hash, we
       
  1407  *   are creating a new instance. If it's an integer, we're editing
       
  1408  *   an existing instance.
       
  1409  * @return
       
  1410  *   Form definition.
       
  1411  */
       
  1412 function system_actions_configure($form_state, $action = NULL) {
       
  1413   if ($action === NULL) {
       
  1414     drupal_goto('admin/settings/actions');
       
  1415   }
       
  1416 
       
  1417   $actions_map = actions_actions_map(actions_list());
       
  1418   $edit = array();
       
  1419 
       
  1420   // Numeric action denotes saved instance of a configurable action;
       
  1421   // else we are creating a new action instance.
       
  1422   if (is_numeric($action)) {
       
  1423     $aid = $action;
       
  1424     // Load stored parameter values from database.
       
  1425     $data = db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = '%s'", $aid));
       
  1426     $edit['actions_description'] = $data->description;
       
  1427     $edit['actions_type'] = $data->type;
       
  1428     $function = $data->callback;
       
  1429     $action = md5($data->callback);
       
  1430     $params = unserialize($data->parameters);
       
  1431     if ($params) {
       
  1432       foreach ($params as $name => $val) {
       
  1433         $edit[$name] = $val;
       
  1434       }
       
  1435     }
       
  1436   }
       
  1437   else {
       
  1438     $function = $actions_map[$action]['callback'];
       
  1439     $edit['actions_description'] = $actions_map[$action]['description'];
       
  1440     $edit['actions_type'] = $actions_map[$action]['type'];
       
  1441   }
       
  1442 
       
  1443   $form['actions_description'] = array(
       
  1444     '#type' => 'textfield',
       
  1445     '#title' => t('Description'),
       
  1446     '#default_value' => $edit['actions_description'],
       
  1447     '#maxlength' => '255',
       
  1448     '#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.'),
       
  1449     '#weight' => -10
       
  1450   );
       
  1451   $action_form = $function .'_form';
       
  1452   $form = array_merge($form, $action_form($edit));
       
  1453   $form['actions_type'] = array(
       
  1454     '#type' => 'value',
       
  1455     '#value' => $edit['actions_type'],
       
  1456   );
       
  1457   $form['actions_action'] = array(
       
  1458     '#type' => 'hidden',
       
  1459     '#value' => $action,
       
  1460   );
       
  1461   // $aid is set when configuring an existing action instance.
       
  1462   if (isset($aid)) {
       
  1463     $form['actions_aid'] = array(
       
  1464       '#type' => 'hidden',
       
  1465       '#value' => $aid,
       
  1466     );
       
  1467   }
       
  1468   $form['actions_configured'] = array(
       
  1469     '#type' => 'hidden',
       
  1470     '#value' => '1',
       
  1471   );
       
  1472   $form['buttons']['submit'] = array(
       
  1473     '#type' => 'submit',
       
  1474     '#value' => t('Save'),
       
  1475     '#weight' => 13
       
  1476   );
       
  1477 
       
  1478   return $form;
       
  1479 }
       
  1480 
       
  1481 /**
       
  1482  * Validate system_actions_configure form submissions.
       
  1483  */
       
  1484 function system_actions_configure_validate($form, $form_state) {
       
  1485   $function = actions_function_lookup($form_state['values']['actions_action']) .'_validate';
       
  1486   // Hand off validation to the action.
       
  1487   if (function_exists($function)) {
       
  1488     $function($form, $form_state);
       
  1489   }
       
  1490 }
       
  1491 
       
  1492 /**
       
  1493  * Process system_actions_configure form submissions.
       
  1494  */
       
  1495 function system_actions_configure_submit($form, &$form_state) {
       
  1496   $function = actions_function_lookup($form_state['values']['actions_action']);
       
  1497   $submit_function = $function .'_submit';
       
  1498 
       
  1499   // Action will return keyed array of values to store.
       
  1500   $params = $submit_function($form, $form_state);
       
  1501   $aid = isset($form_state['values']['actions_aid']) ? $form_state['values']['actions_aid'] : NULL;
       
  1502 
       
  1503   actions_save($function, $form_state['values']['actions_type'], $params, $form_state['values']['actions_description'], $aid);
       
  1504   drupal_set_message(t('The action has been successfully saved.'));
       
  1505 
       
  1506   $form_state['redirect'] = 'admin/settings/actions/manage';
       
  1507 }
       
  1508 
       
  1509 /**
       
  1510  * Create the form for confirmation of deleting an action.
       
  1511  *
       
  1512  * @ingroup forms
       
  1513  * @see system_actions_delete_form_submit()
       
  1514  */
       
  1515 function system_actions_delete_form($form_state, $action) {
       
  1516 
       
  1517   $form['aid'] = array(
       
  1518     '#type' => 'hidden',
       
  1519     '#value' => $action->aid,
       
  1520   );
       
  1521   return confirm_form($form,
       
  1522     t('Are you sure you want to delete the action %action?', array('%action' => $action->description)),
       
  1523     'admin/settings/actions/manage',
       
  1524     t('This cannot be undone.'),
       
  1525     t('Delete'), t('Cancel')
       
  1526   );
       
  1527 }
       
  1528 
       
  1529 /**
       
  1530  * Process system_actions_delete form submissions.
       
  1531  *
       
  1532  * Post-deletion operations for action deletion.
       
  1533  */
       
  1534 function system_actions_delete_form_submit($form, &$form_state) {
       
  1535   $aid = $form_state['values']['aid'];
       
  1536   $action = actions_load($aid);
       
  1537   actions_delete($aid);
       
  1538   $description = check_plain($action->description);
       
  1539   watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $aid, '%action' => $description));
       
  1540   drupal_set_message(t('Action %action was deleted', array('%action' => $description)));
       
  1541   $form_state['redirect'] = 'admin/settings/actions/manage';
       
  1542 }
       
  1543 
       
  1544 /**
       
  1545  * Post-deletion operations for deleting action orphans.
       
  1546  *
       
  1547  * @param $orphaned
       
  1548  *   An array of orphaned actions.
       
  1549  */
       
  1550 function system_action_delete_orphans_post($orphaned) {
       
  1551   foreach ($orphaned as $callback) {
       
  1552     drupal_set_message(t("Deleted orphaned action (%action).", array('%action' => $callback)));
       
  1553   }
       
  1554 }
       
  1555 
       
  1556 /**
       
  1557  * Remove actions that are in the database but not supported by any enabled module.
       
  1558  */
       
  1559 function system_actions_remove_orphans() {
       
  1560   actions_synchronize(actions_list(), TRUE);
       
  1561   drupal_goto('admin/settings/actions/manage');
       
  1562 }
       
  1563 
       
  1564 /**
       
  1565  * Return a form definition so the Send email action can be configured.
       
  1566  *
       
  1567  * @see system_send_email_action_validate()
       
  1568  * @see system_send_email_action_submit()
       
  1569  * @param $context
       
  1570  *   Default values (if we are editing an existing action instance).
       
  1571  * @return
       
  1572  *   Form definition.
       
  1573  */
       
  1574 function system_send_email_action_form($context) {
       
  1575   // Set default values for form.
       
  1576   if (!isset($context['recipient'])) {
       
  1577     $context['recipient'] = '';
       
  1578   }
       
  1579   if (!isset($context['subject'])) {
       
  1580     $context['subject'] = '';
       
  1581   }
       
  1582   if (!isset($context['message'])) {
       
  1583     $context['message'] = '';
       
  1584   }
       
  1585 
       
  1586   $form['recipient'] = array(
       
  1587     '#type' => 'textfield',
       
  1588     '#title' => t('Recipient'),
       
  1589     '#default_value' => $context['recipient'],
       
  1590     '#maxlength' => '254',
       
  1591     '#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')),
       
  1592   );
       
  1593   $form['subject'] = array(
       
  1594     '#type' => 'textfield',
       
  1595     '#title' => t('Subject'),
       
  1596     '#default_value' => $context['subject'],
       
  1597     '#maxlength' => '254',
       
  1598     '#description' => t('The subject of the message.'),
       
  1599   );
       
  1600   $form['message'] = array(
       
  1601     '#type' => 'textarea',
       
  1602     '#title' => t('Message'),
       
  1603     '#default_value' => $context['message'],
       
  1604     '#cols' => '80',
       
  1605     '#rows' => '20',
       
  1606     '#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.'),
       
  1607   );
       
  1608   return $form;
       
  1609 }
       
  1610 
       
  1611 /**
       
  1612  * Validate system_send_email_action form submissions.
       
  1613  */
       
  1614 function system_send_email_action_validate($form, $form_state) {
       
  1615   $form_values = $form_state['values'];
       
  1616   // Validate the configuration form.
       
  1617   if (!valid_email_address($form_values['recipient']) && $form_values['recipient'] != '%author') {
       
  1618     // We want the literal %author placeholder to be emphasized in the error message.
       
  1619     form_set_error('recipient', t('Please enter a valid email address or %author.', array('%author' => '%author')));
       
  1620   }
       
  1621 }
       
  1622 
       
  1623 /**
       
  1624  * Process system_send_email_action form submissions.
       
  1625  */
       
  1626 function system_send_email_action_submit($form, $form_state) {
       
  1627   $form_values = $form_state['values'];
       
  1628   // Process the HTML form to store configuration. The keyed array that
       
  1629   // we return will be serialized to the database.
       
  1630   $params = array(
       
  1631     'recipient' => $form_values['recipient'],
       
  1632     'subject'   => $form_values['subject'],
       
  1633     'message'   => $form_values['message'],
       
  1634   );
       
  1635   return $params;
       
  1636 }
       
  1637 
       
  1638 /**
       
  1639  * Implementation of a configurable Drupal action. Sends an email.
       
  1640  */
       
  1641 function system_send_email_action($object, $context) {
       
  1642   global $user;
       
  1643 
       
  1644   switch ($context['hook']) {
       
  1645     case 'nodeapi':
       
  1646       // Because this is not an action of type 'node' the node
       
  1647       // will not be passed as $object, but it will still be available
       
  1648       // in $context.
       
  1649       $node = $context['node'];
       
  1650       break;
       
  1651     // The comment hook provides nid, in $context.
       
  1652     case 'comment':
       
  1653       $comment = $context['comment'];
       
  1654       $node = node_load($comment->nid);
       
  1655       break;
       
  1656     case 'user':
       
  1657       // Because this is not an action of type 'user' the user
       
  1658       // object is not passed as $object, but it will still be available
       
  1659       // in $context.
       
  1660       $account = $context['account'];
       
  1661       if (isset($context['node'])) {
       
  1662         $node = $context['node'];
       
  1663       }
       
  1664       elseif ($context['recipient'] == '%author') {
       
  1665         // If we don't have a node, we don't have a node author.
       
  1666         watchdog('error', 'Cannot use %author token in this context.');
       
  1667         return;
       
  1668       }
       
  1669       break;
       
  1670     default:
       
  1671       // We are being called directly.
       
  1672       $node = $object;
       
  1673   }
       
  1674 
       
  1675   $recipient = $context['recipient'];
       
  1676 
       
  1677   if (isset($node)) {
       
  1678     if (!isset($account)) {
       
  1679       $account = user_load(array('uid' => $node->uid));
       
  1680     }
       
  1681     if ($recipient == '%author') {
       
  1682       $recipient = $account->mail;
       
  1683     }
       
  1684   }
       
  1685 
       
  1686   if (!isset($account)) {
       
  1687     $account = $user;
       
  1688 
       
  1689   }
       
  1690   $language = user_preferred_language($account);
       
  1691   $params = array('account' => $account, 'object' => $object, 'context' => $context);
       
  1692   if (isset($node)) {
       
  1693     $params['node'] = $node;
       
  1694   }
       
  1695 
       
  1696   if (drupal_mail('system', 'action_send_email', $recipient, $language, $params)) {
       
  1697     watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient));
       
  1698   }
       
  1699   else {
       
  1700     watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient));
       
  1701   }
       
  1702 }
       
  1703 
       
  1704 /**
       
  1705  * Implementation of hook_mail().
       
  1706  */
       
  1707 function system_mail($key, &$message, $params) {
       
  1708   $account = $params['account'];
       
  1709   $context = $params['context'];
       
  1710   $variables = array(
       
  1711     '%site_name' => variable_get('site_name', 'Drupal'),
       
  1712     '%username' => $account->name,
       
  1713   );
       
  1714   if ($context['hook'] == 'taxonomy') {
       
  1715     $object = $params['object'];
       
  1716     $vocabulary = taxonomy_vocabulary_load($object->vid);
       
  1717     $variables += array(
       
  1718       '%term_name' => $object->name,
       
  1719       '%term_description' => $object->description,
       
  1720       '%term_id' => $object->tid,
       
  1721       '%vocabulary_name' => $vocabulary->name,
       
  1722       '%vocabulary_description' => $vocabulary->description,
       
  1723       '%vocabulary_id' => $vocabulary->vid,
       
  1724     );
       
  1725   }
       
  1726 
       
  1727   // Node-based variable translation is only available if we have a node.
       
  1728   if (isset($params['node'])) {
       
  1729     $node = $params['node'];
       
  1730     $variables += array(
       
  1731       '%uid' => $node->uid,
       
  1732       '%node_url' => url('node/'. $node->nid, array('absolute' => TRUE)),
       
  1733       '%node_type' => node_get_types('name', $node),
       
  1734       '%title' => $node->title,
       
  1735       '%teaser' => $node->teaser,
       
  1736       '%body' => $node->body,
       
  1737     );
       
  1738   }
       
  1739   $subject = strtr($context['subject'], $variables);
       
  1740   $body = strtr($context['message'], $variables);
       
  1741   $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
       
  1742   $message['body'][] = drupal_html_to_text($body);
       
  1743 }
       
  1744 
       
  1745 function system_message_action_form($context) {
       
  1746   $form['message'] = array(
       
  1747     '#type' => 'textarea',
       
  1748     '#title' => t('Message'),
       
  1749     '#default_value' => isset($context['message']) ? $context['message'] : '',
       
  1750     '#required' => TRUE,
       
  1751     '#rows' => '8',
       
  1752     '#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.'),
       
  1753   );
       
  1754   return $form;
       
  1755 }
       
  1756 
       
  1757 function system_message_action_submit($form, $form_state) {
       
  1758   return array('message' => $form_state['values']['message']);
       
  1759 }
       
  1760 
       
  1761 /**
       
  1762  * A configurable Drupal action. Sends a message to the current user's screen.
       
  1763  */
       
  1764 function system_message_action(&$object, $context = array()) {
       
  1765   global $user;
       
  1766   $variables = array(
       
  1767     '%site_name' => variable_get('site_name', 'Drupal'),
       
  1768     '%username' => $user->name ? $user->name : variable_get('anonymous', t('Anonymous')),
       
  1769   );
       
  1770 
       
  1771   // This action can be called in any context, but if placeholders
       
  1772   // are used a node object must be present to be the source
       
  1773   // of substituted text.
       
  1774   switch ($context['hook']) {
       
  1775     case 'nodeapi':
       
  1776       // Because this is not an action of type 'node' the node
       
  1777       // will not be passed as $object, but it will still be available
       
  1778       // in $context.
       
  1779       $node = $context['node'];
       
  1780       break;
       
  1781     // The comment hook also provides the node, in context.
       
  1782     case 'comment':
       
  1783       $comment = $context['comment'];
       
  1784       $node = node_load($comment->nid);
       
  1785       break;
       
  1786     case 'taxonomy':
       
  1787       $vocabulary = taxonomy_vocabulary_load($object->vid);
       
  1788       $variables = array_merge($variables, array(
       
  1789         '%term_name' => $object->name,
       
  1790         '%term_description' => $object->description,
       
  1791         '%term_id' => $object->tid,
       
  1792         '%vocabulary_name' => $vocabulary->name,
       
  1793         '%vocabulary_description' => $vocabulary->description,
       
  1794         '%vocabulary_id' => $vocabulary->vid,
       
  1795         )
       
  1796       );
       
  1797       break;
       
  1798     default:
       
  1799       // We are being called directly.
       
  1800       $node = $object;
       
  1801   }
       
  1802 
       
  1803   if (isset($node) && is_object($node)) {
       
  1804     $variables = array_merge($variables, array(
       
  1805       '%uid' => $node->uid,
       
  1806       '%node_url' => url('node/'. $node->nid, array('absolute' => TRUE)),
       
  1807       '%node_type' => check_plain(node_get_types('name', $node)),
       
  1808       '%title' => filter_xss($node->title),
       
  1809       '%teaser' => filter_xss($node->teaser),
       
  1810       '%body' => filter_xss($node->body),
       
  1811       )
       
  1812     );
       
  1813   }
       
  1814   $context['message'] = strtr($context['message'], $variables);
       
  1815   drupal_set_message($context['message']);
       
  1816 }
       
  1817 
       
  1818 /**
       
  1819  * Implementation of a configurable Drupal action. Redirect user to a URL.
       
  1820  */
       
  1821 function system_goto_action_form($context) {
       
  1822   $form['url'] = array(
       
  1823     '#type' => 'textfield',
       
  1824     '#title' => t('URL'),
       
  1825     '#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.'),
       
  1826     '#default_value' => isset($context['url']) ? $context['url'] : '',
       
  1827     '#required' => TRUE,
       
  1828   );
       
  1829   return $form;
       
  1830 }
       
  1831 
       
  1832 function system_goto_action_submit($form, $form_state) {
       
  1833   return array(
       
  1834     'url' => $form_state['values']['url']
       
  1835   );
       
  1836 }
       
  1837 
       
  1838 function system_goto_action($object, $context) {
       
  1839   drupal_goto($context['url']);
       
  1840 }
       
  1841 
       
  1842 /**
       
  1843  * Generate an array of time zones and their local time&date.
       
  1844  */
       
  1845 function _system_zonelist() {
       
  1846   $timestamp = time();
       
  1847   $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);
       
  1848   $zones = array();
       
  1849   foreach ($zonelist as $offset) {
       
  1850     $zone = $offset * 3600;
       
  1851     $zones[$zone] = format_date($timestamp, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') .' O', $zone);
       
  1852   }
       
  1853   return $zones;
       
  1854 }
       
  1855 
       
  1856 /**
       
  1857  * Checks whether the server is capable of issuing HTTP requests.
       
  1858  *
       
  1859  * The function sets the drupal_http_request_fail system variable to TRUE if
       
  1860  * drupal_http_request() does not work and then the system status report page
       
  1861  * will contain an error.
       
  1862  *
       
  1863  * @return
       
  1864  *  TRUE if this installation can issue HTTP requests.
       
  1865  */
       
  1866 function system_check_http_request() {
       
  1867   // Try to get the content of the front page via drupal_http_request().
       
  1868   $result = drupal_http_request(url('', array('absolute' => TRUE)));
       
  1869   // We only care that we get a http response - this means that Drupal
       
  1870   // can make a http request.
       
  1871   $works = isset($result->code) && ($result->code >= 100) && ($result->code < 600);
       
  1872   variable_set('drupal_http_request_fails', !$works);
       
  1873   return $works;
       
  1874 }
       
  1875 
       
  1876 /**
       
  1877  * Format the Powered by Drupal text.
       
  1878  *
       
  1879  * @ingroup themeable
       
  1880  */
       
  1881 function theme_system_powered_by($image_path) {
       
  1882   $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'));
       
  1883   return l($image, 'http://drupal.org', array('html' => TRUE, 'absolute' => TRUE, 'external' => TRUE));
       
  1884 }