2001-06-23 11:09:40 +00:00
<?php
2001-10-20 18:57:09 +00:00
// $Id$
2001-06-23 11:09:40 +00:00
2004-08-21 06:42:38 +00:00
/**
* @file
* Configuration system that lets administrators modify the workings of the site.
*/
2007-09-15 07:33:46 +00:00
define('VERSION', '6.0-dev');
2007-06-08 05:50:58 +00:00
define('DRUPAL_CORE_COMPATIBILITY', '6.x');
2006-06-05 08:53:05 +00:00
2007-03-26 06:26:45 +00:00
define('DRUPAL_MINIMUM_PHP', '4.3.3');
define('DRUPAL_MINIMUM_MYSQL', '4.1.0'); // If using MySQL
define('DRUPAL_MINIMUM_PGSQL', '7.4'); // If using PostgreSQL
define('DRUPAL_MINIMUM_APACHE', '1.3'); // If using Apache
2007-05-30 08:08:59 +00:00
// Maximum age of temporary files in seconds.
define('DRUPAL_MAXIMUM_TEMP_FILE_AGE', 1440);
2004-06-18 15:04:37 +00:00
/**
* Implementation of hook_help().
*/
2007-06-30 19:46:58 +00:00
function system_help($path, $arg) {
2006-04-23 06:07:59 +00:00
global $base_url;
2007-06-30 19:46:58 +00:00
switch ($path) {
2005-11-01 10:17:34 +00:00
case 'admin/help#system':
2007-08-18 11:51:48 +00:00
$output = '<p>'. t('The system module provides system-wide defaults such as running jobs at a particular time, and storing web pages to improve efficiency. The ability to run scheduled jobs makes administering the website more usable, as administrators do not have to manually start jobs. The storing of web pages, or caching, allows the site to efficiently re-use web pages and improve website performance. The system module provides control over preferences, behaviours including visual and operational settings.') .'</p>';
2006-08-09 07:42:55 +00:00
$output .= '<p>'. t('Some modules require regularly scheduled actions, such as cleaning up logfiles. Cron, which stands for chronograph, is a periodic command scheduler executing commands at intervals specified in seconds. It can be used to control the execution of daily, weekly and monthly jobs (or anything with a period measured in seconds). The aggregator module periodically updates feeds using cron. Ping periodically notifies services of new content on your site. Search periodically indexes the content on your site. Automating tasks is one of the best ways to keep a system running smoothly, and if most of your administration does not require your direct involvement, cron is an ideal solution. Cron can, if necessary, also be run manually.') .'</p>';
2006-11-24 10:18:24 +00:00
$output .= '<p>'. t("There is a caching mechanism which stores dynamically generated web pages in a database. By caching a web page, the system module does not have to create the page each time someone wants to view it, instead it takes only one SQL query to display it, reducing response time and the server's load. Only pages requested by <em>anonymous</em> users are cached. In order to reduce server load and save bandwidth, the system module stores and sends cached pages compressed.") .'</p>';
2006-08-18 12:17:00 +00:00
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="@system">System page</a>.', array('@system' => 'http://drupal.org/handbook/modules/system/')) .'</p>';
2005-11-01 10:17:34 +00:00
return $output;
2005-01-14 15:21:39 +00:00
case 'admin':
2006-11-26 23:10:29 +00:00
return '<p>'. t('Welcome to the administration section. Here you may control how your site functions.') .'</p>';
2006-10-03 20:38:07 +00:00
case 'admin/by-module':
2006-11-26 23:10:29 +00:00
return '<p>'. t('This page shows you all available administration tasks for each module.') .'</p>';
2006-07-31 11:25:55 +00:00
case 'admin/build/themes':
2006-11-26 23:10:29 +00:00
return '<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. Alternately, to override these settings in a specific theme, click the "configure" link for the corresponding theme. Note that different themes may have different regions available for rendering content like blocks. If you want consistency in what your users see, you may wish to enable only one theme.') .'</p>';
2007-06-30 19:46:58 +00:00
case 'admin/build/themes/settings/'. $arg[4]:
$reference = explode('.', $arg[4], 2);
2005-09-08 19:46:05 +00:00
$theme = array_pop($reference);
2006-11-26 23:10:29 +00:00
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>';
2007-06-30 19:46:58 +00:00
case 'admin/build/themes/settings':
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>';
2006-10-03 20:38:07 +00:00
case 'admin/build/modules':
2007-07-03 19:11:14 +00:00
$output = '<p>'. t('Modules are plugins for Drupal that extend its core functionality. Here you can select which modules are enabled. Once a module is enabled, new <a href="@permissions">permissions</a> might be made available. Modules can automatically be temporarily disabled to reduce server load when your site becomes extremely busy by enabling the throttle.module and checking throttle.', array('@permissions' => url('admin/user/access')));
if (module_exists('throttle')) {
$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')));
}
$output .= '</p>';
$output .= t('<p>It is important that <a href="@update-php">update.php</a> is run every time a module is updated to a newer version.</p><p>You can find all administration tasks belonging to a particular module on the <a href="@by-module">administration by module page</a>.</p>', array('@update-php' => $base_url .'/update.php', '@by-module' => url('admin/by-module')));
return $output;
2006-10-24 15:56:22 +00:00
case 'admin/build/modules/uninstall':
2006-11-26 23:10:29 +00:00
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>';
2007-09-11 14:50:05 +00:00
case 'admin/settings/actions':
case 'admin/settings/actions/manage':
$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>';
$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>';
if (module_exists('trigger')) {
$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>';
}
2007-08-29 14:57:50 +00:00
return $output;
2007-09-11 14:50:05 +00:00
case 'admin/settings/actions/configure':
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").');
2006-09-01 08:44:53 +00:00
case 'admin/logs/status':
2006-11-26 23:10:29 +00:00
return '<p>'. t("Here you can find a short overview of your Drupal site's parameters as well as any problems detected with your installation. It is useful to copy/paste this information when you need support.") .'</p>';
2003-08-21 18:13:28 +00:00
}
2002-02-07 19:59:37 +00:00
}
2007-04-06 13:27:23 +00:00
function system_theme() {
return array_merge(drupal_common_themes(), array(
'system_theme_select_form' => array(
'arguments' => array('form' => NULL),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-04-06 13:27:23 +00:00
),
'system_themes_form' => array(
'arguments' => array('form' => NULL),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-04-06 13:27:23 +00:00
),
'system_modules' => array(
'arguments' => array('form' => NULL),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-04-06 13:27:23 +00:00
),
'system_modules_uninstall' => array(
'arguments' => array('form' => NULL),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-04-06 13:27:23 +00:00
),
'status_report' => array(
'arguments' => array('requirements' => NULL),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-04-06 13:27:23 +00:00
),
'admin_page' => array(
'arguments' => array('blocks' => NULL),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-04-06 13:27:23 +00:00
),
'admin_block' => array(
'arguments' => array('block' => NULL),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-04-06 13:27:23 +00:00
),
'admin_block_content' => array(
'arguments' => array('content' => NULL),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-04-06 13:27:23 +00:00
),
'system_admin_by_module' => array(
'arguments' => array('menu_items' => NULL),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-04-06 13:27:23 +00:00
),
));
}
2004-06-18 15:04:37 +00:00
/**
* Implementation of hook_perm().
*/
2001-06-23 11:09:40 +00:00
function system_perm() {
2007-08-29 14:57:50 +00:00
return array('administer site configuration', 'access administration pages', 'administer actions', 'select different theme', 'administer files');
2001-06-29 22:08:57 +00:00
}
2005-10-07 06:11:12 +00:00
/**
* Implementation of hook_elements().
*/
function system_elements() {
// Top level form
2006-03-28 01:45:41 +00:00
$type['form'] = array('#method' => 'post', '#action' => request_uri());
2005-10-07 06:11:12 +00:00
// Inputs
2007-07-04 15:42:38 +00:00
$type['submit'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => TRUE, '#ahah_event' => 'submit', '#process' => array('form_expand_ahah'));
$type['button'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => FALSE, '#ahah_event' => 'submit', '#process' => array('form_expand_ahah'));
2007-09-05 08:42:02 +00:00
$type['image_button'] = array('#input' => TRUE, '#button_type' => 'submit', '#executes_submit_callback' => TRUE, '#ahah_event' => 'submit', '#process' => array('form_expand_ahah'), '#return_value' => TRUE, '#has_garbage_value' => TRUE, '#src' => NULL);
2005-11-12 11:26:16 +00:00
$type['textfield'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE);
2007-01-31 15:49:26 +00:00
$type['password'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128);
2007-05-14 13:43:38 +00:00
$type['password_confirm'] = array('#input' => TRUE, '#process' => array('expand_password_confirm'));
2007-01-31 15:49:26 +00:00
$type['textarea'] = array('#input' => TRUE, '#cols' => 60, '#rows' => 5, '#resizable' => TRUE);
2007-05-14 13:43:38 +00:00
$type['radios'] = array('#input' => TRUE, '#process' => array('expand_radios'));
2007-01-31 15:49:26 +00:00
$type['radio'] = array('#input' => TRUE, '#default_value' => NULL);
2007-05-14 13:43:38 +00:00
$type['checkboxes'] = array('#input' => TRUE, '#process' => array('expand_checkboxes'), '#tree' => TRUE);
2007-07-04 15:42:38 +00:00
$type['checkbox'] = array('#input' => TRUE, '#return_value' => 1);
2007-01-31 15:49:26 +00:00
$type['select'] = array('#input' => TRUE, '#size' => 0, '#multiple' => FALSE);
2007-05-14 13:43:38 +00:00
$type['weight'] = array('#input' => TRUE, '#delta' => 10, '#default_value' => 0, '#process' => array('process_weight'));
2007-07-16 06:33:44 +00:00
$type['date'] = array('#input' => TRUE, '#process' => array('expand_date'), '#element_validate' => array('date_validate'));
2005-10-11 19:44:35 +00:00
$type['file'] = array('#input' => TRUE, '#size' => 60);
2005-10-07 06:11:12 +00:00
// Form structure
2007-01-31 15:49:26 +00:00
$type['item'] = array('#value' => '');
2005-10-11 19:44:35 +00:00
$type['hidden'] = array('#input' => TRUE);
$type['value'] = array('#input' => TRUE);
$type['markup'] = array('#prefix' => '', '#suffix' => '');
2007-01-31 15:49:26 +00:00
$type['fieldset'] = array('#collapsible' => FALSE, '#collapsed' => FALSE, '#value' => NULL);
2007-01-24 07:51:53 +00:00
$type['token'] = array('#input' => TRUE);
2005-10-07 06:11:12 +00:00
return $type;
}
2004-04-21 13:56:38 +00:00
/**
2004-06-18 15:04:37 +00:00
* Implementation of hook_menu().
2004-04-21 13:56:38 +00:00
*/
2007-01-24 14:48:36 +00:00
function system_menu() {
$items['system/files'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'File download',
2007-01-24 14:48:36 +00:00
'page callback' => 'file_download',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['admin'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Administer',
2007-01-24 14:48:36 +00:00
'access arguments' => array('access administration pages'),
'page callback' => 'system_main_admin_page',
'weight' => 9,
2007-05-22 05:52:17 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/compact'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Compact mode',
2007-01-24 14:48:36 +00:00
'page callback' => 'system_admin_compact_page',
'type' => MENU_CALLBACK,
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/by-task'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'By task',
2007-01-24 14:48:36 +00:00
'page callback' => 'system_main_admin_page',
2007-05-27 20:31:13 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/by-module'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'By module',
2007-01-24 14:48:36 +00:00
'page callback' => 'system_admin_by_module',
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
// menu items that are basically just menu blocks
$items['admin/settings'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Site configuration',
'description' => 'Adjust basic site configuration options.',
2007-01-24 14:48:36 +00:00
'position' => 'right',
'weight' => -5,
'page callback' => 'system_settings_overview',
'access arguments' => array('administer site configuration'),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/build'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Site building',
'description' => 'Control how your site looks and feels.',
2007-01-24 14:48:36 +00:00
'position' => 'right',
'weight' => -10,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer site configuration'),
2007-05-22 05:52:17 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/settings/admin'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Administration theme',
'description' => 'Settings for how your administrative pages should look.',
2007-01-24 14:48:36 +00:00
'position' => 'left',
'page callback' => 'drupal_get_form',
'page arguments' => array('system_admin_theme_settings'),
'block callback' => 'system_admin_theme_settings',
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
// Themes:
$items['admin/build/themes'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Themes',
'description' => 'Change which theme your site uses or allows users to set.',
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
2007-06-30 19:46:58 +00:00
'page arguments' => array('system_themes_form', NULL),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/build/themes/select'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'List',
'description' => 'Select the default theme.',
2007-01-24 14:48:36 +00:00
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
);
$items['admin/build/themes/settings'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Configure',
2007-08-11 19:17:17 +00:00
'page arguments' => array('system_theme_settings'),
2007-01-24 14:48:36 +00:00
'type' => MENU_LOCAL_TASK,
);
// Theme configuration subtabs
$items['admin/build/themes/settings/global'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Global settings',
2007-01-24 14:48:36 +00:00
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
);
2004-09-16 07:17:56 +00:00
2007-01-24 14:48:36 +00:00
foreach (list_themes() as $theme) {
if ($theme->status) {
$items['admin/build/themes/settings/'. $theme->name] = array(
2007-04-17 07:19:39 +00:00
'title' => $theme->info['name'],
2007-01-24 14:48:36 +00:00
'page arguments' => array('system_theme_settings', $theme->name),
'type' => MENU_LOCAL_TASK,
);
2004-09-16 07:17:56 +00:00
}
2001-06-29 22:08:57 +00:00
}
2006-08-14 07:17:37 +00:00
2007-01-24 14:48:36 +00:00
// Modules:
$items['admin/build/modules'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Modules',
'description' => 'Enable or disable add-on modules for your site.',
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('system_modules'),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/build/modules/list'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'List',
2007-01-24 14:48:36 +00:00
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/build/modules/list/confirm'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'List',
2007-01-24 14:48:36 +00:00
'type' => MENU_CALLBACK,
);
$items['admin/build/modules/uninstall'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Uninstall',
2007-01-24 14:48:36 +00:00
'page arguments' => array('system_modules_uninstall'),
'type' => MENU_LOCAL_TASK,
);
$items['admin/build/modules/uninstall/confirm'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Uninstall',
2007-01-24 14:48:36 +00:00
'type' => MENU_CALLBACK,
);
2004-06-18 15:04:37 +00:00
2007-08-29 14:57:50 +00:00
// Actions:
2007-09-11 14:50:05 +00:00
$items['admin/settings/actions'] = array(
2007-08-29 14:57:50 +00:00
'title' => 'Actions',
'description' => 'Manage the actions defined for your site.',
'access arguments' => array('administer actions'),
'page callback' => 'system_actions_manage'
);
2007-09-11 14:50:05 +00:00
$items['admin/settings/actions/manage'] = array(
2007-08-29 14:57:50 +00:00
'title' => 'Manage actions',
'description' => 'Manage the actions defined for your site.',
'page callback' => 'system_actions_manage',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -2,
);
2007-09-11 14:50:05 +00:00
$items['admin/settings/actions/configure'] = array(
'title' => 'Configure an advanced action',
2007-08-29 14:57:50 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('system_actions_configure'),
'type' => MENU_CALLBACK,
);
2007-09-11 14:50:05 +00:00
$items['admin/settings/actions/delete/%actions'] = array(
2007-08-29 14:57:50 +00:00
'title' => 'Delete action',
'description' => 'Delete an action.',
'page callback' => 'drupal_get_form',
'page arguments' => array('system_actions_delete_form', 4),
'type' => MENU_CALLBACK,
);
2007-09-11 14:50:05 +00:00
$items['admin/settings/actions/orphan'] = array(
2007-08-29 14:57:50 +00:00
'title' => 'Remove orphans',
'page callback' => 'system_actions_remove_orphans',
'type' => MENU_CALLBACK,
);
2007-01-24 14:48:36 +00:00
// Settings:
$items['admin/settings/site-information'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Site information',
'description' => 'Change basic site information, such as the site name, slogan, e-mail address, mission, front page and more.',
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('system_site_information_settings'),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/settings/error-reporting'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Error reporting',
'description' => 'Control how Drupal deals with errors including 403/404 errors as well as PHP error reporting.',
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('system_error_reporting_settings'),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
2007-04-10 10:10:27 +00:00
$items['admin/settings/logging'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Logging and alerts',
'description' => "Settings for logging and alerts modules. Various modules can route Drupal's system events to different destination, such as syslog, database, email, ...etc.",
2007-04-10 10:10:27 +00:00
'page callback' => 'system_logging_overview',
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-04-10 10:10:27 +00:00
);
2007-01-24 14:48:36 +00:00
$items['admin/settings/performance'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Performance',
2007-06-01 09:05:45 +00:00
'description' => 'Enable or disable page caching for anonymous users and set CSS and JS bandwidth optimization options.',
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('system_performance_settings'),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/settings/file-system'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'File system',
'description' => 'Tell Drupal where to store uploaded files and how they are accessed.',
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('system_file_system_settings'),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/settings/image-toolkit'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Image toolkit',
'description' => 'Choose which image toolkit to use if you have installed optional toolkits.',
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('system_image_toolkit_settings'),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/content/rss-publishing'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'RSS publishing',
'description' => 'Configure the number of items per feed and whether feeds should be titles/teasers/full-text.',
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('system_rss_feeds_settings'),
2007-06-28 00:48:26 +00:00
'access arguments' => array('administer site configuration'),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/settings/date-time'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Date and time',
'description' => "Settings for how Drupal displays date and time, as well as the system's default timezone.",
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('system_date_time_settings'),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
2007-05-14 16:22:26 +00:00
$items['admin/settings/date-time/lookup'] = array(
'title' => t('Date and time lookup'),
'type' => MENU_CALLBACK,
'page callback' => 'system_date_time_lookup',
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-05-14 16:22:26 +00:00
);
2007-01-24 14:48:36 +00:00
$items['admin/settings/site-maintenance'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Site maintenance',
'description' => 'Take the site off-line for maintenance or bring it back online.',
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('system_site_maintenance_settings'),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/settings/clean-urls'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Clean URLs',
'description' => 'Enable or disable clean URLs for your site.',
2007-01-24 14:48:36 +00:00
'page callback' => 'drupal_get_form',
'page arguments' => array('system_clean_url_settings'),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
// Logs:
$items['admin/logs'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Logs',
'description' => 'View system logs and other status information.',
2007-01-24 14:48:36 +00:00
'page callback' => 'system_admin_menu_block_page',
'weight' => 5,
'position' => 'left',
2007-05-22 05:52:17 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/logs/status'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Status report',
'description' => "Get a status report about your site's operation and any detected problems.",
2007-01-24 14:48:36 +00:00
'page callback' => 'system_status',
'weight' => 10,
'access arguments' => array('administer site configuration'),
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/logs/status/run-cron'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'Run cron',
2007-01-24 14:48:36 +00:00
'page callback' => 'system_run_cron',
'type' => MENU_CALLBACK,
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/logs/status/php'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'PHP',
2007-01-24 14:48:36 +00:00
'page callback' => 'system_php',
'type' => MENU_CALLBACK,
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
$items['admin/logs/status/sql'] = array(
2007-04-30 17:03:29 +00:00
'title' => 'SQL',
2007-01-24 14:48:36 +00:00
'page callback' => 'system_sql',
'type' => MENU_CALLBACK,
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-01-24 14:48:36 +00:00
);
2007-05-04 09:41:37 +00:00
// Default page for batch operations
$items['batch'] = array(
'page callback' => 'system_batch_page',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
2007-08-26 16:41:02 +00:00
'file' => 'system.admin.inc',
2007-05-04 09:41:37 +00:00
);
2004-06-18 15:04:37 +00:00
return $items;
2001-06-23 11:09:40 +00:00
}
2007-01-24 14:48:36 +00:00
function system_init() {
// Use the administrative theme if the user is looking at a page in the admin/* path.
2007-06-04 07:22:23 +00:00
if (arg(0) == 'admin' || (variable_get('node_admin_theme', '0') && arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit'))) {
2007-01-24 14:48:36 +00:00
global $custom_theme;
$custom_theme = variable_get('admin_theme', '0');
drupal_add_css(drupal_get_path('module', 'system') .'/admin.css', 'module');
}
// Add the CSS for this module.
drupal_add_css(drupal_get_path('module', 'system') .'/defaults.css', 'module');
drupal_add_css(drupal_get_path('module', 'system') .'/system.css', 'module');
}
2004-06-18 15:04:37 +00:00
/**
* Implementation of hook_user().
*
* Allows users to individually set their theme and time zone.
*/
2004-06-27 19:10:52 +00:00
function system_user($type, $edit, &$user, $category = NULL) {
2006-04-17 20:48:26 +00:00
if ($type == 'form' && $category == 'account') {
2007-01-31 15:49:26 +00:00
$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);
2006-04-17 20:48:26 +00:00
2004-07-09 00:25:10 +00:00
if (variable_get('configurable_timezones', 1)) {
2004-07-22 02:13:13 +00:00
$zones = _system_zonelist();
2007-01-11 03:32:56 +00:00
$form['timezone'] = array(
2007-04-13 08:56:59 +00:00
'#type' => 'fieldset',
2007-01-11 03:32:56 +00:00
'#title' => t('Locale settings'),
'#weight' => 6,
'#collapsible' => TRUE,
);
2006-01-17 17:35:47 +00:00
$form['timezone']['timezone'] = array(
2007-01-11 03:32:56 +00:00
'#type' => 'select',
'#title' => t('Time zone'),
'#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
'#options' => $zones,
'#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.'),
2005-10-07 06:11:12 +00:00
);
2003-10-30 19:16:44 +00:00
}
2006-04-17 20:48:26 +00:00
2005-10-07 06:11:12 +00:00
return $form;
2004-02-07 16:59:34 +00:00
}
2003-09-30 21:48:32 +00:00
}
2006-07-31 11:25:55 +00:00
/**
* Provide a single block on the administration overview page.
*/
2007-03-12 13:01:10 +00:00
function system_admin_menu_block($item) {
2006-07-31 11:25:55 +00:00
$content = array();
2007-05-27 20:31:13 +00:00
if (!isset($item['mlid'])) {
2007-09-01 14:41:21 +00:00
$item += db_fetch_array(db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = '%s' AND module = 'system'", $item['path']));
2007-05-16 13:45:17 +00:00
}
2007-05-27 20:31:13 +00:00
$result = db_query("
2007-09-01 14:41:21 +00:00
SELECT m.*, ml.*
2007-05-27 20:31:13 +00:00
FROM {menu_links} ml
INNER JOIN {menu_router} m ON ml.router_path = m.path
2007-09-01 14:41:21 +00:00
WHERE ml.plid = %d AND ml.menu_name = '%s' AND hidden = 0", $item['mlid'], $item['menu_name']);
2007-05-27 20:31:13 +00:00
while ($item = db_fetch_array($result)) {
2007-05-16 13:45:17 +00:00
_menu_link_translate($item);
2007-05-27 20:31:13 +00:00
if (!$item['access']) {
2007-03-12 13:01:10 +00:00
continue;
2006-07-31 11:25:55 +00:00
}
2007-09-01 14:41:21 +00:00
// The link 'description' either derived from the hook_menu 'description' or
// entered by the user via menu module is saved as the title attribute.
if (!empty($item['options']['attributes']['title'])) {
$item['description'] = $item['options']['attributes']['title'];
}
// Prepare for sorting as in function _menu_tree_check_access().
// The weight is offset so it is always positive, with a uniform 5-digits.
$content[(50000 + $item['weight']) .' '. $item['title'] .' '. $item['mlid']] = $item;
2006-07-31 11:25:55 +00:00
}
2007-09-01 14:41:21 +00:00
ksort($content);
2006-07-31 11:25:55 +00:00
return $content;
}
2007-06-04 07:22:23 +00:00
function system_admin_theme_submit($form, &$form_state) {
2006-07-31 11:25:55 +00:00
// If we're changing themes, make sure the theme has its blocks initialized.
2007-06-04 07:22:23 +00:00
if ($form_state['values']['admin_theme'] != variable_get('admin_theme', '0')) {
2007-08-12 15:55:36 +00:00
$result = db_result(db_query("SELECT COUNT(*) FROM {blocks} WHERE theme = '%s'", $form_state['values']['admin_theme']));
if (!$result) {
2007-06-04 07:22:23 +00:00
system_initialize_theme_blocks($form_state['values']['admin_theme']);
2006-07-31 11:25:55 +00:00
}
}
}
2007-06-05 09:15:02 +00:00
/**
2006-04-14 20:30:08 +00:00
* Returns a fieldset containing the theme select form.
*
* @param $description
* description of the fieldset
* @param $default_value
* default value of theme radios
* @param $weight
* weight of the fieldset
* @return
* a form array
*/
2007-09-17 08:06:52 +00:00
function system_theme_select_form($description = '', $default_value = '', $weight = 0) {
2006-04-14 20:30:08 +00:00
if (user_access('select different theme')) {
2007-03-27 05:13:55 +00:00
$enabled = array();
2007-05-06 05:47:52 +00:00
$themes = list_themes();
foreach ($themes as $theme) {
2006-04-14 20:30:08 +00:00
if ($theme->status) {
$enabled[] = $theme;
}
}
if (count($enabled) > 1) {
ksort($enabled);
$form['themes'] = array(
2006-04-17 20:48:26 +00:00
'#type' => 'fieldset',
'#title' => t('Theme configuration'),
'#description' => $description,
'#collapsible' => TRUE,
2006-04-14 20:30:08 +00:00
'#theme' => 'system_theme_select_form'
);
foreach ($enabled as $info) {
// For the default theme, revert to an empty string so the user's theme updates when the site theme is changed.
2006-11-08 19:24:11 +00:00
$info->key = $info->name == variable_get('theme_default', 'garland') ? '' : $info->name;
2006-04-14 20:30:08 +00:00
2007-05-06 05:47:52 +00:00
$screenshot = NULL;
$theme_key = $info->name;
while ($theme_key) {
if (file_exists($themes[$theme_key]->info['screenshot'])) {
$screenshot = $themes[$theme_key]->info['screenshot'];
break;
}
$theme_key = isset($themes[$theme_key]->info['base theme']) ? $themes[$theme_key]->info['base theme'] : NULL;
}
$screenshot = $screenshot ? theme('image', $screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), FALSE) : t('no screenshot');
2006-04-14 20:30:08 +00:00
2006-10-26 05:31:14 +00:00
$form['themes'][$info->key]['screenshot'] = array('#value' => $screenshot);
2006-11-26 02:20:01 +00:00
$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>' : ''));
2006-04-14 20:30:08 +00:00
$options[$info->key] = '';
}
$form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $default_value ? $default_value : '');
$form['#weight'] = $weight;
return $form;
}
}
}
2005-11-13 07:57:11 +00:00
/**
* Checks the existence of the directory specified in $form_element. This
2006-07-10 19:27:52 +00:00
* function is called from the system_settings form to check both the
2005-11-13 07:57:11 +00:00
* file_directory_path and file_directory_temp directories. If validation
* fails, the form element is flagged with an error from within the
* file_check_directory function.
*
* @param $form_element
* The form element containing the name of the directory to check.
*/
2005-11-21 18:10:26 +00:00
function system_check_directory($form_element) {
2005-11-13 07:57:11 +00:00
file_check_directory($form_element['#value'], FILE_CREATE_DIRECTORY, $form_element['#parents'][0]);
return $form_element;
}
2004-08-20 07:51:27 +00:00
/**
* Retrieves the current status of an array of files in the system table.
*/
function system_get_files_database(&$files, $type) {
2002-11-08 13:19:12 +00:00
// Extract current files from database.
2006-02-27 14:32:38 +00:00
$result = db_query("SELECT filename, name, type, status, throttle, schema_version FROM {system} WHERE type = '%s'", $type);
2002-11-08 13:19:12 +00:00
while ($file = db_fetch_object($result)) {
2005-05-21 11:33:03 +00:00
if (isset($files[$file->name]) && is_object($files[$file->name])) {
2006-02-27 14:32:38 +00:00
$file->old_filename = $file->filename;
2002-11-08 13:19:12 +00:00
foreach ($file as $key => $value) {
2005-05-21 11:33:03 +00:00
if (!isset($files[$file->name]) || !isset($files[$file->name]->$key)) {
2004-11-24 22:44:01 +00:00
$files[$file->name]->$key = $value;
}
2002-11-08 13:19:12 +00:00
}
2002-04-14 19:34:04 +00:00
}
2001-06-23 11:09:40 +00:00
}
2004-08-20 07:51:27 +00:00
}
2001-06-23 11:09:40 +00:00
2007-04-17 07:19:39 +00:00
function system_theme_default() {
// Prepare defaults for themes.
return array(
'regions' => array(
'left' => 'Left sidebar',
'right' => 'Right sidebar',
'content' => 'Content',
'header' => 'Header',
'footer' => 'Footer',
),
'description' => '',
'features' => array(
'comment_user_picture',
'favicon',
'mission',
'logo',
'name',
'node_user_picture',
'search',
2007-08-20 18:26:41 +00:00
'slogan',
'primary_links',
'secondary_links',
2007-04-17 07:19:39 +00:00
),
2007-07-01 23:27:32 +00:00
'stylesheets' => array(
'all' => array('style.css')
),
'scripts' => array('script.js'),
2007-05-06 05:47:52 +00:00
'screenshot' => 'screenshot.png',
2007-06-27 17:54:49 +00:00
'php' => DRUPAL_MINIMUM_PHP,
2007-04-17 07:19:39 +00:00
);
}
2004-08-20 07:51:27 +00:00
/**
* Collect data about all currently available themes
*/
2004-11-24 22:44:01 +00:00
function system_theme_data() {
// Find themes
2007-05-06 05:47:52 +00:00
$themes = drupal_system_listing('\.info$', 'themes');
2004-11-24 22:44:01 +00:00
2004-08-20 07:51:27 +00:00
// Find theme engines
2006-10-23 06:45:17 +00:00
$engines = drupal_system_listing('\.engine$', 'themes/engines');
2004-11-24 22:44:01 +00:00
// Remove all theme engines from the system table
2007-08-22 08:36:34 +00:00
db_query("DELETE FROM {system} WHERE type = '%s'", 'theme_engine');
2004-08-20 07:51:27 +00:00
foreach ($engines as $engine) {
2004-11-25 06:17:03 +00:00
// Insert theme engine into system table
2004-11-24 22:44:01 +00:00
drupal_get_filename('theme_engine', $engine->name, $engine->filename);
drupal_load('theme_engine', $engine->name);
db_query("INSERT INTO {system} (name, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', %d, %d, %d)", $engine->name, 'theme_engine', $engine->filename, 1, 0, 0);
2007-05-06 05:47:52 +00:00
}
2004-11-24 22:44:01 +00:00
2007-05-06 05:47:52 +00:00
$defaults = system_theme_default();
2005-08-16 18:06:18 +00:00
2007-05-06 05:47:52 +00:00
$sub_themes = array();
// Read info files for each theme
foreach ($themes as $key => $theme) {
$themes[$key]->info = drupal_parse_info_file($theme->filename) + $defaults;
2007-06-27 21:59:33 +00:00
// Invoke hook_system_info_alter() to give installed modules a chance to
// modify the data in the .info files if necessary.
drupal_alter('system_info', $themes[$key]->info, $themes[$key]);
2007-05-06 05:47:52 +00:00
if (!empty($themes[$key]->info['base theme'])) {
$sub_themes[] = $key;
}
if (empty($themes[$key]->info['engine'])) {
$filename = dirname($themes[$key]->filename) .'/'. $themes[$key]->name .'.theme';
if (file_exists($filename)) {
$themes[$key]->owner = $filename;
$themes[$key]->prefix = $key;
2004-11-25 06:17:03 +00:00
}
2004-08-20 07:51:27 +00:00
}
2007-05-06 05:47:52 +00:00
else {
$engine = $themes[$key]->info['engine'];
if (isset($engines[$engine])) {
$themes[$key]->owner = $engines[$engine]->filename;
$themes[$key]->prefix = $engines[$engine]->name;
$themes[$key]->template = TRUE;
}
}
2007-07-01 23:27:32 +00:00
// Give the stylesheets proper path information.
$pathed_stylesheets = array();
foreach ($themes[$key]->info['stylesheets'] as $media => $stylesheets) {
foreach ($stylesheets as $stylesheet) {
$pathed_stylesheets[$media][$stylesheet] = dirname($themes[$key]->filename) .'/'. $stylesheet;
}
2007-05-06 05:47:52 +00:00
}
2007-07-01 23:27:32 +00:00
$themes[$key]->info['stylesheets'] = $pathed_stylesheets;
2007-07-02 14:41:37 +00:00
2007-07-01 23:27:32 +00:00
// Give the scripts proper path information.
$scripts = array();
foreach ($themes[$key]->info['scripts'] as $script) {
$scripts[$script] = dirname($themes[$key]->filename) .'/'. $script;
2007-06-08 12:51:59 +00:00
}
2007-07-01 23:27:32 +00:00
$themes[$key]->info['scripts'] = $scripts;
2007-05-06 05:47:52 +00:00
// Give the screenshot proper path information.
if (!empty($themes[$key]->info['screenshot'])) {
$themes[$key]->info['screenshot'] = dirname($themes[$key]->filename) .'/'. $themes[$key]->info['screenshot'];
}
2004-08-20 07:51:27 +00:00
}
2007-05-06 05:47:52 +00:00
// Now that we've established all our master themes, go back and fill in
// data for subthemes.
foreach ($sub_themes as $key) {
$base_key = system_find_base_theme($themes, $key);
if (!$base_key) {
continue;
}
// Copy the 'owner' and 'engine' over if the top level theme uses a
// theme engine.
if (isset($themes[$base_key]->owner)) {
if (isset($themes[$base_key]->info['engine'])) {
$themes[$key]->info['engine'] = $themes[$base_key]->info['engine'];
$themes[$key]->owner = $themes[$base_key]->owner;
$themes[$key]->prefix = $themes[$base_key]->prefix;
}
else {
$themes[$key]->prefix = $key;
2004-08-20 07:51:27 +00:00
}
}
2007-07-01 23:27:32 +00:00
// Add any stylesheets from the base theme, unless the names match in which case
2007-07-02 14:41:37 +00:00
// the sub-theme wins. Note that we slip the base theme's stylesheets in at the
2007-07-01 23:27:32 +00:00
// beginning of the array so that they get added to the page in the correct order.
foreach ($themes[$base_key]->info['stylesheets'] as $media => $stylesheets) {
foreach ($stylesheets as $stylesheet => $path) {
if (!isset($themes[$key]->info['stylesheets'][$media][$stylesheet])) {
// We need to ensure the media array exists, or the array addition below doesn't work.
if (!isset($themes[$key]->info['stylesheets'][$media])) {
$themes[$key]->info['stylesheets'][$media] = array();
}
$themes[$key]->info['stylesheets'][$media] = array($stylesheet => $path) + $themes[$key]->info['stylesheets'][$media];
}
}
}
// Add any scripts from the base theme, unless the names match in which case
2007-07-02 14:41:37 +00:00
// the sub-theme wins. Note that we slip the base theme's scripts in at the
2007-07-01 23:27:32 +00:00
// beginning of the array so that they get added to the page in the correct order.
foreach ($themes[$base_key]->info['scripts'] as $script => $path) {
if (!isset($themes[$key]->info['scripts'][$script])) {
$themes[$key]->info['scripts'] = array($script => $path) + $themes[$key]->info['scripts'];
}
}
2003-11-20 22:10:42 +00:00
}
2004-08-20 07:51:27 +00:00
// Extract current files from database.
2004-11-24 22:44:01 +00:00
system_get_files_database($themes, 'theme');
db_query("DELETE FROM {system} WHERE type = 'theme'");
2004-08-20 07:51:27 +00:00
2004-11-24 22:44:01 +00:00
foreach ($themes as $theme) {
2007-05-06 05:47:52 +00:00
if (!isset($theme->owner)) {
$theme->owner = '';
}
2007-04-17 07:19:39 +00:00
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);
2004-11-24 22:44:01 +00:00
}
return $themes;
}
2007-05-06 05:47:52 +00:00
/**
* Recursive function to find the top level base theme. Themes can inherit
* templates and function implementations from earlier themes; this function
* finds the top level parent that has no ancestor, or returns NULL if there
* isn't a valid parent.
*/
function system_find_base_theme($themes, $key, $used_keys = array()) {
$base_key = $themes[$key]->info['base theme'];
// Does the base theme exist?
if (!isset($themes[$base_key])) {
return NULL;
}
// Is the base theme itself a child of another theme?
if (isset($themes[$base_key]->info['base theme'])) {
// Prevent loops.
if ($used_keys[$base_key]) {
return NULL;
}
$used_keys[$base_key] = TRUE;
return system_find_base_theme($themes, $base_key, $used_keys);
}
// If we get here, then this is our parent theme.
return $base_key;
}
2005-08-16 18:06:18 +00:00
/**
* Get a list of available regions from a specified theme.
*
2005-08-28 18:17:47 +00:00
* @param $theme_key
2005-08-16 18:06:18 +00:00
* The name of a theme.
* @return
* An array of regions in the form $region['name'] = 'description'.
*/
2005-08-28 18:17:47 +00:00
function system_region_list($theme_key) {
2005-08-16 18:06:18 +00:00
static $list = array();
2005-10-22 15:14:46 +00:00
if (!array_key_exists($theme_key, $list)) {
2007-04-17 07:19:39 +00:00
$info = unserialize(db_result(db_query("SELECT info FROM {system} WHERE type = 'theme' AND name = '%s'", $theme_key)));
$list[$theme_key] = array_map('t', $info['regions']);
2005-08-16 18:06:18 +00:00
}
2005-08-28 18:17:47 +00:00
return $list[$theme_key];
2005-08-16 18:06:18 +00:00
}
/**
* Get the name of the default region for a given theme.
*
* @param $theme
* The name of a theme.
* @return
* A string that is the region name.
*/
function system_default_region($theme) {
$regions = array_keys(system_region_list($theme));
2007-03-27 05:13:55 +00:00
return isset($regions[0]) ? $regions[0] : '';
2005-08-16 18:06:18 +00:00
}
2004-08-20 07:51:27 +00:00
/**
2005-10-07 06:11:12 +00:00
* Assign an initial, default set of blocks for a theme.
*
2006-05-07 00:08:36 +00:00
* This function is called the first time a new theme is enabled. The new theme
2005-10-07 06:11:12 +00:00
* gets a copy of the default theme's blocks, with the difference that if a
* particular region isn't available in the new theme, the block is assigned
* to the new theme's default region.
*
* @param $theme
* The name of a theme.
*/
function system_initialize_theme_blocks($theme) {
// Initialize theme's blocks if none already registered.
2007-08-12 15:55:36 +00:00
if (!(db_result(db_query("SELECT COUNT(*) FROM {blocks} WHERE theme = '%s'", $theme)))) {
2006-11-08 19:24:11 +00:00
$default_theme = variable_get('theme_default', 'garland');
2005-10-07 06:11:12 +00:00
$regions = system_region_list($theme);
$result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
2007-01-02 05:05:38 +00:00
while ($block = db_fetch_array($result)) {
2005-10-07 06:11:12 +00:00
// If the region isn't supported by the theme, assign the block to the theme's default region.
if (!array_key_exists($block['region'], $regions)) {
$block['region'] = system_default_region($theme);
}
2007-08-19 08:08:45 +00:00
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)",
$block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle'], $block['cache']);
2005-10-07 06:11:12 +00:00
}
}
}
2006-08-18 18:58:47 +00:00
/**
* Add default buttons to a form and set its prefix
*/
function system_settings_form($form) {
2005-10-11 19:44:35 +00:00
$form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
$form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
2005-10-07 06:11:12 +00:00
2005-10-08 12:21:47 +00:00
if (!empty($_POST) && form_get_errors()) {
2005-10-08 12:38:20 +00:00
drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
2005-10-08 12:21:47 +00:00
}
2007-05-14 13:43:38 +00:00
$form['#submit'][] = 'system_settings_form_submit';
$form['#validate'][] = 'system_settings_form_validate';
2007-03-17 18:30:14 +00:00
$form['#theme'] = 'system_settings_form';
2006-08-18 18:58:47 +00:00
return $form;
2005-10-07 06:11:12 +00:00
}
2006-11-10 09:22:07 +00:00
2005-10-26 01:24:09 +00:00
2005-10-07 06:11:12 +00:00
/**
* Execute the system_settings_form.
*
2005-10-13 10:02:31 +00:00
* If you want node type configure style handling of your checkboxes,
* add an array_filter value to your form.
*
2005-10-07 06:11:12 +00:00
*/
2007-06-04 07:22:23 +00:00
function system_settings_form_submit($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
2005-10-07 06:11:12 +00:00
2006-04-25 10:00:57 +00:00
// Exclude unnecessary elements.
2007-06-04 07:22:23 +00:00
unset($form_state['values']['submit'], $form_state['values']['reset'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token']);
2006-04-25 10:00:57 +00:00
2007-06-04 07:22:23 +00:00
foreach ($form_state['values'] as $key => $value) {
2005-10-07 06:11:12 +00:00
if ($op == t('Reset to defaults')) {
variable_del($key);
}
else {
2007-06-04 07:22:23 +00:00
if (is_array($value) && isset($form_state['values']['array_filter'])) {
2005-10-07 06:11:12 +00:00
$value = array_keys(array_filter($value));
}
variable_set($key, $value);
}
}
if ($op == t('Reset to defaults')) {
drupal_set_message(t('The configuration options have been reset to their default values.'));
2005-10-22 15:14:46 +00:00
}
else {
2005-10-07 06:11:12 +00:00
drupal_set_message(t('The configuration options have been saved.'));
}
2006-12-10 09:54:35 +00:00
2007-04-06 13:27:23 +00:00
drupal_rebuild_theme_registry();
2005-10-07 06:11:12 +00:00
}
/**
2007-08-26 16:41:02 +00:00
* Helper function to sort requirements.
2005-10-07 06:11:12 +00:00
*/
2007-08-26 16:41:02 +00:00
function _system_sort_requirements($a, $b) {
if (!isset($a['weight'])) {
if (!isset($b['weight'])) {
return strcmp($a['title'], $b['title']);
2005-10-07 06:11:12 +00:00
}
2007-08-26 16:41:02 +00:00
return -$b['weight'];
2005-10-07 06:11:12 +00:00
}
2007-08-26 16:41:02 +00:00
return isset($b['weight']) ? $a['weight'] - $b['weight'] : $a['weight'];
2005-10-07 06:11:12 +00:00
}
2007-08-26 16:41:02 +00:00
/**
* Implementation of hook_node_type().
*
* Updates theme settings after a node type change.
*/
function system_node_type($op, $info) {
if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) {
$old = 'toggle_node_info_'. $info->old_type;
$new = 'toggle_node_info_'. $info->type;
2007-06-27 17:54:49 +00:00
2007-08-26 16:41:02 +00:00
$theme_settings = variable_get('theme_settings', array());
if (isset($theme_settings[$old])) {
$theme_settings[$new] = $theme_settings[$old];
unset($theme_settings[$old]);
variable_set('theme_settings', $theme_settings);
2006-11-27 01:55:45 +00:00
}
}
}
2005-10-07 06:11:12 +00:00
/**
* Output a confirmation form
*
2006-08-18 18:58:47 +00:00
* This function returns a complete form for confirming an action. A link is
2005-10-07 06:11:12 +00:00
* offered to go back to the item that is being changed in case the user changes
* his/her mind.
*
2006-08-29 09:12:03 +00:00
* You can check for the existence of $_POST[$name] (where $name
2006-08-18 18:58:47 +00:00
* is usually 'confirm') to check if the confirmation was successful or
* use the regular submit model.
2005-10-07 06:11:12 +00:00
*
* @param $form
* Additional elements to inject into the form, for example hidden elements.
* @param $question
* The question to ask the user (e.g. "Are you sure you want to delete the
* block <em>foo</em>?").
2007-07-01 17:41:16 +00:00
* @param $path
* The page to go to if the user denies the action.
* Can be either a drupal path, or an array with the keys 'path', 'query', 'fragment'.
* @param $description
* Additional text to display (defaults to "This action cannot be undone.").
* @param $yes
* A caption for the button which confirms the action (e.g. "Delete",
* "Replace", ...).
* @param $no
* A caption for the link which denies the action (e.g. "Cancel").
* @param $name
* The internal name used to refer to the confirmation item.
2005-10-07 06:11:12 +00:00
* @return
2006-08-18 18:58:47 +00:00
* The form.
2005-10-07 06:11:12 +00:00
*/
2007-07-01 17:41:16 +00:00
function confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm') {
$description = isset($description) ? $description : t('This action cannot be undone.');
2006-12-12 09:48:47 +00:00
// Prepare cancel link
$query = $fragment = NULL;
2007-07-01 17:41:16 +00:00
if (is_array($path)) {
$query = isset($path['query']) ? $path['query'] : NULL;
$fragment = isset($path['fragment']) ? $path['fragment'] : NULL;
$path = isset($path['path']) ? $path['path'] : NULL;
2007-06-24 10:09:53 +00:00
}
2007-07-01 17:41:16 +00:00
$cancel = l($no ? $no : t('Cancel'), $path, array('query' => $query, 'fragment' => $fragment));
2006-12-12 09:48:47 +00:00
2005-10-07 06:11:12 +00:00
drupal_set_title($question);
2007-03-13 13:41:39 +00:00
2007-07-01 17:41:16 +00:00
// Confirm form fails duplication check, as the form values rarely change -- so skip it.
$form['#skip_duplicate_check'] = TRUE;
2005-10-11 19:44:35 +00:00
$form['#attributes'] = array('class' => 'confirmation');
$form['description'] = array('#value' => $description);
$form[$name] = array('#type' => 'hidden', '#value' => 1);
2005-10-07 06:11:12 +00:00
2005-10-11 19:44:35 +00:00
$form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
2007-07-01 17:41:16 +00:00
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $yes ? $yes : t('Confirm'));
$form['actions']['cancel'] = array('#value' => $cancel);
2007-03-17 18:30:14 +00:00
$form['#theme'] = 'confirm_form';
2006-08-18 18:58:47 +00:00
return $form;
2005-10-07 06:11:12 +00:00
}
2006-07-31 11:25:55 +00:00
/**
* Determine if a user is in compact mode.
*/
function system_admin_compact_mode() {
global $user;
return (isset($user->admin_compact_mode)) ? $user->admin_compact_mode : variable_get('admin_compact_mode', FALSE);
}
2006-11-21 20:14:19 +00:00
function system_get_module_admin_tasks($module) {
2007-08-09 20:05:49 +00:00
static $items;
2006-11-21 20:14:19 +00:00
$admin_access = user_access('administer access control');
$admin_tasks = array();
2007-08-09 20:05:49 +00:00
if (!isset($items)) {
$result = db_query("
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.*
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");
$items = array();
while ($item = db_fetch_array($result)) {
_menu_link_translate($item);
if ($item['access']) {
$items[$item['router_path']] = $item;
}
}
}
$admin_tasks = array();
$admin_task_count = 0;
2006-11-21 20:14:19 +00:00
// Check for permissions.
if (module_hook($module, 'perm') && $admin_access) {
2007-02-15 11:40:19 +00:00
$admin_tasks[-1] = l(t('Configure permissions'), 'admin/user/access', array('fragment' => 'module-'. $module));
2006-11-21 20:14:19 +00:00
}
// Check for menu items that are admin links.
2007-08-09 20:05:49 +00:00
if ($menu = module_invoke($module, 'menu')) {
foreach (array_keys($menu) as $path) {
if (isset($items[$path])) {
$admin_tasks[$items[$path]['title'] . $admin_task_count ++] = l($items[$path]['title'], $path);
2006-11-21 20:14:19 +00:00
}
}
}
return $admin_tasks;
}
2007-04-10 10:10:27 +00:00
/**
* Implementation of hook_cron().
*
2007-05-30 08:08:59 +00:00
* Remove older rows from flood and batch table. Remove old temporary files.
2007-04-10 10:10:27 +00:00
*/
function system_cron() {
2007-05-30 08:08:59 +00:00
// Cleanup the flood.
2007-04-10 10:10:27 +00:00
db_query('DELETE FROM {flood} WHERE timestamp < %d', time() - 3600);
2007-05-30 08:08:59 +00:00
// Cleanup the batch table.
2007-05-04 09:41:37 +00:00
db_query('DELETE FROM {batch} WHERE timestamp < %d', time() - 864000);
2007-05-30 08:08:59 +00:00
// Remove temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
$result = db_query('SELECT * FROM {files} WHERE status = %s and timestamp < %d', FILE_STATUS_TEMPORARY, time() - DRUPAL_MAXIMUM_TEMP_FILE_AGE);
while ($file = db_fetch_object($result)) {
if (file_exists($file->filepath)) {
// If files that exist cannot be deleted, continue so the database remains
2007-07-02 14:41:37 +00:00
// consistent.
2007-05-30 08:08:59 +00:00
if (!file_delete($file->filepath)) {
watchdog('file system', t('Could not delete temporary file "%path" during garbage collection', array('%path' => $file->filepath)), 'error');
continue;
}
}
db_query('DELETE FROM {files} WHERE fid = %d', $file->fid);
}
2007-04-10 10:10:27 +00:00
}
2007-06-29 18:06:51 +00:00
/**
* Implementation of hook_hook_info().
*/
function system_hook_info() {
return array(
'system' => array(
'cron' => array(
'run' => array(
'runs when' => t('When cron runs'),
),
),
),
);
}
/**
* Implementation of hook_action_info().
*/
function system_action_info() {
return array(
'system_message_action' => array(
'type' => 'system',
'description' => t('Display a message to the user'),
'configurable' => TRUE,
'hooks' => array(
'nodeapi' => array('view', 'insert', 'update', 'delete'),
'comment' => array('view', 'insert', 'update', 'delete'),
'user' => array('view', 'insert', 'update', 'delete', 'login'),
'taxonomy' => array('insert', 'update', 'delete'),
),
),
'system_send_email_action' => array(
'description' => t('Send e-mail'),
'type' => 'system',
'configurable' => TRUE,
'hooks' => array(
'nodeapi' => array('view', 'insert', 'update', 'delete'),
'comment' => array('view', 'insert', 'update', 'delete'),
'user' => array('view', 'insert', 'update', 'delete', 'login'),
'taxonomy' => array('insert', 'update', 'delete'),
)
),
'system_goto_action' => array(
'description' => t('Redirect to URL'),
'type' => 'system',
'configurable' => TRUE,
'hooks' => array(
'nodeapi' => array('view', 'insert', 'update', 'delete'),
'comment' => array('view', 'insert', 'update', 'delete'),
'user' => array('view', 'insert', 'update', 'delete', 'login'),
)
)
);
}
2007-08-29 14:57:50 +00:00
/**
* Menu callback. Display an overview of available and configured actions.
*/
function system_actions_manage() {
$output = '';
$actions = actions_list();
actions_synchronize($actions);
$actions_map = actions_actions_map($actions);
$options = array(t('Choose an advanced action'));
$unconfigurable = array();
foreach ($actions_map as $key => $array) {
if ($array['configurable']) {
$options[$key] = $array['description'] .'...';
}
else {
$unconfigurable[] = $array;
}
}
$row = array();
$instances_present = db_fetch_object(db_query("SELECT aid FROM {actions} WHERE parameters != ''"));
$header = array(
2007-09-11 14:50:05 +00:00
array('data' => t('Action type'), 'field' => 'type'),
2007-08-29 14:57:50 +00:00
array('data' => t('Description'), 'field' => 'description'),
array('data' => $instances_present ? t('Operations') : '', 'colspan' => '2')
);
$sql = 'SELECT * FROM {actions}';
$result = pager_query($sql . tablesort_sql($header), 50);
while ($action = db_fetch_object($result)) {
$row[] = array(
array('data' => $action->type),
array('data' => $action->description),
2007-09-11 14:50:05 +00:00
array('data' => $action->parameters ? l(t('configure'), "admin/settings/actions/configure/$action->aid") : ''),
array('data' => $action->parameters ? l(t('delete'), "admin/settings/actions/delete/$action->aid") : '')
2007-08-29 14:57:50 +00:00
);
}
if ($row) {
$pager = theme('pager', NULL, 50, 0);
if (!empty($pager)) {
$row[] = array(array('data' => $pager, 'colspan' => '3'));
}
$output .= '<h3>'. t('Actions available to Drupal:') .'</h3>';
$output .= theme('table', $header, $row);
}
if ($actions_map) {
$output .= '<p>'. drupal_get_form('system_actions_manage_form', $options) .'</p>';
}
return $output;
}
/**
* Define the form for the actions overview page.
*
* @param $options
* An array of configurable actions.
* @return
* Form definition.
*/
function system_actions_manage_form($form_state, $options = array()) {
$form['parent'] = array(
'#type' => 'fieldset',
'#title' => t('Make a new advanced action available'),
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
);
$form['parent']['action'] = array(
'#type' => 'select',
'#default_value' => '',
'#options' => $options,
'#description' => '',
);
$form['parent']['buttons']['submit'] = array(
'#type' => 'submit',
2007-09-11 14:50:05 +00:00
'#value' => t('Create'),
2007-08-29 14:57:50 +00:00
);
return $form;
}
function system_actions_manage_form_submit($form, &$form_state) {
if ($form_state['values']['action']) {
2007-09-11 14:50:05 +00:00
$form_state['redirect'] = 'admin/settings/actions/configure/'. $form_state['values']['action'];
2007-08-29 14:57:50 +00:00
}
}
/**
* Menu callback. Create the form for configuration of a single action.
*
* We provide the "Description" field. The rest of the form
* is provided by the action. We then provide the Save button.
* Because we are combining unknown form elements with the action
* configuration form, we use actions_ prefix on our elements.
*
* @param $action
* md5 hash of action ID or an integer. If it's an md5 hash, we
* are creating a new instance. If it's an integer, we're editing
* an existing instance.
* @return
* Form definition.
*/
function system_actions_configure($form_state, $action = NULL) {
if ($action === NULL) {
2007-09-11 14:50:05 +00:00
drupal_goto('admin/settings/actions');
2007-08-29 14:57:50 +00:00
}
$actions_map = actions_actions_map(actions_list());
$edit = array();
// Numeric action denotes saved instance of a configurable action;
// else we are creating a new action instance.
if (is_numeric($action)) {
$aid = $action;
// Load stored parameter values from database.
$data = db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = %d", intval($aid)));
$edit['actions_description'] = $data->description;
$edit['actions_type'] = $data->type;
$function = $data->callback;
$action = md5($data->callback);
$params = unserialize($data->parameters);
if ($params) {
foreach ($params as $name => $val) {
$edit[$name] = $val;
}
}
}
else {
$function = $actions_map[$action]['callback'];
$edit['actions_description'] = $actions_map[$action]['description'];
$edit['actions_type'] = $actions_map[$action]['type'];
}
$form['actions_description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#default_value' => $edit['actions_description'],
'#maxlength' => '255',
2007-09-11 14:50:05 +00:00
'#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.'),
2007-08-29 14:57:50 +00:00
'#weight' => -10
);
$action_form = $function .'_form';
$form = array_merge($form, $action_form($edit));
$form['actions_type'] = array(
'#type' => 'value',
'#value' => $edit['actions_type'],
);
$form['actions_action'] = array(
'#type' => 'hidden',
'#value' => $action,
);
// $aid is set when configuring an existing action instance.
if (isset($aid)) {
$form['actions_aid'] = array(
'#type' => 'hidden',
'#value' => $aid,
);
}
$form['actions_configured'] = array(
'#type' => 'hidden',
'#value' => '1',
);
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 13
);
return $form;
}
function system_actions_configure_validate($form, $form_state) {
$function = actions_function_lookup($form_state['values']['actions_action']) .'_validate';
// Hand off validation to the action.
if (function_exists($function)) {
$function($form, $form_state);
}
}
function system_actions_configure_submit($form, &$form_state) {
$function = actions_function_lookup($form_state['values']['actions_action']);
$submit_function = $function .'_submit';
// Action will return keyed array of values to store.
$params = $submit_function($form, $form_state);
$aid = isset($form_state['values']['actions_aid']) ? $form_state['values']['actions_aid'] : NULL;
actions_save($function, $form_state['values']['actions_type'], $params, $form_state['values']['actions_description'], $aid);
drupal_set_message(t('The action has been successfully saved.'));
2007-09-11 14:50:05 +00:00
$form_state['redirect'] = 'admin/settings/actions/manage';
2007-08-29 14:57:50 +00:00
}
/**
* Create the form for confirmation of deleting an action.
*
* @param $aid
* The action ID.
*/
function system_actions_delete_form($form_state, $action) {
$form['aid'] = array(
'#type' => 'hidden',
'#value' => $action->aid,
);
return confirm_form($form,
t('Are you sure you want to delete the action %action?', array('%action' => $action->description)),
2007-09-11 14:50:05 +00:00
'admin/settings/actions/manage',
2007-08-29 14:57:50 +00:00
t('This cannot be undone.'),
t('Delete'), t('Cancel')
);
}
/**
* Post-deletion operations for action deletion.
*/
function system_actions_delete_form_submit($form, &$form_state) {
$aid = $form_state['values']['aid'];
$action = actions_load($aid);
actions_delete($aid);
$description = check_plain($action->description);
watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $aid, '%action' => $description));
drupal_set_message(t('Action %action was deleted', array('%action' => $description)));
2007-09-11 14:50:05 +00:00
$form_state['redirect'] = 'admin/settings/actions/manage';
2007-08-29 14:57:50 +00:00
}
/**
* Post-deletion operations for deleting action orphans.
*/
function system_action_delete_orphans_post($orphaned) {
foreach ($orphaned as $callback) {
drupal_set_message(t("Deleted orphaned action (%action).", array('%action' => $callback)));
}
}
/**
* Remove actions that are in the database but not supported by any enabled module.
*
*/
function system_actions_remove_orphans() {
actions_synchronize(actions_list(), TRUE);
2007-09-11 14:50:05 +00:00
drupal_goto('admin/settings/actions/manage');
2007-08-29 14:57:50 +00:00
}
2007-06-29 18:06:51 +00:00
/**
* Return a form definition so the Send email action can be configured.
*
* @param $context
* Default values (if we are editing an existing action instance).
* @return
* Form definition.
*/
function system_send_email_action_form($context) {
// Set default values for form.
if (!isset($context['recipient'])) {
$context['recipient'] = '';
}
if (!isset($context['subject'])) {
$context['subject'] = '';
}
if (!isset($context['message'])) {
$context['message'] = '';
}
$form['recipient'] = array(
'#type' => 'textfield',
'#title' => t('Recipient'),
'#default_value' => $context['recipient'],
'#maxlength' => '254',
2007-09-11 14:50:05 +00:00
'#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')),
2007-06-29 18:06:51 +00:00
);
$form['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#default_value' => $context['subject'],
'#maxlength' => '254',
'#description' => t('The subject of the message.'),
);
$form['message'] = array(
'#type' => 'textarea',
'#title' => t('Message'),
'#default_value' => $context['message'],
'#cols' => '80',
'#rows' => '20',
'#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.'),
);
return $form;
}
function system_send_email_action_validate($form, $form_state) {
$form_values = $form_state['values'];
// Validate the configuration form.
if (!valid_email_address($form_values['recipient']) && $form_values['recipient'] != '%author') {
// We want the literal %author placeholder to be emphasized in the error message.
form_set_error('recipient', t('Please enter a valid email address or %author.', array('%author' => '%author')));
}
}
function system_send_email_action_submit($form, $form_state) {
$form_values = $form_state['values'];
// Process the HTML form to store configuration. The keyed array that
// we return will be serialized to the database.
$params = array(
'recipient' => $form_values['recipient'],
'subject' => $form_values['subject'],
'message' => $form_values['message'],
);
return $params;
}
/**
2007-08-29 14:57:50 +00:00
* Implementation of a configurable Drupal action. Sends an email.
2007-06-29 18:06:51 +00:00
*/
function system_send_email_action($object, $context) {
global $user;
switch ($context['hook']) {
case 'nodeapi':
// Because this is not an action of type 'node' the node
// will not be passed as $object, but it will still be available
// in $context.
$node = $context['node'];
break;
// The comment hook provides nid, in $context.
case 'comment':
$comment = $context['comment'];
$node = node_load($comment->nid);
case 'user':
// Because this is not an action of type 'user' the user
// object is not passed as $object, but it will still be available
// in $context.
$account = $context['account'];
if (isset($context['node'])) {
$node = $context['node'];
}
elseif ($context['recipient'] == '%author') {
// If we don't have a node, we don't have a node author.
watchdog('error', 'Cannot use %author token in this context.');
return;
}
break;
default:
// We are being called directly.
$node = $object;
}
$recipient = $context['recipient'];
if (isset($node)) {
if (!isset($account)) {
$account = user_load(array('uid' => $node->uid));
}
if ($recipient == '%author') {
$recipient = $account->mail;
}
}
2007-09-10 09:28:28 +00:00
if (!isset($account)) {
$account = $user;
2007-06-29 18:06:51 +00:00
2007-09-10 09:28:28 +00:00
}
$language = user_preferred_language($account);
$params = array('account' => $account, 'object' => $object, 'context' => $context);
if (isset($node)) {
$params['node'] = $node;
2007-06-29 18:06:51 +00:00
}
2007-09-10 09:28:28 +00:00
if (drupal_mail('system', 'action_send_email', $recipient, $language, $params)) {
2007-06-29 18:06:51 +00:00
watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient));
}
else {
watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient));
}
}
2007-09-10 09:28:28 +00:00
/**
* Implementation of hook_mail().
*/
function system_mail($key, &$message, $params) {
$account = $params['account'];
$context = $params['context'];
$variables = array(
'%site_name' => variable_get('site_name', 'Drupal'),
'%username' => $account->name,
);
if ($context['hook'] == 'taxonomy') {
$object = $params['object'];
$vocabulary = taxonomy_vocabulary_load($object->vid);
$variables += array(
'%term_name' => $object->name,
'%term_description' => $object->description,
'%term_id' => $object->tid,
'%vocabulary_name' => $vocabulary->name,
'%vocabulary_description' => $vocabulary->description,
'%vocabulary_id' => $vocabulary->vid,
);
}
// Node-based variable translation is only available if we have a node.
if (isset($params['node'])) {
$node = $params['node'];
$variables += array(
'%uid' => $node->uid,
'%node_url' => url('node/'. $node->nid, array('absolute' => TRUE)),
'%node_type' => node_get_types('name', $node),
'%title' => $node->title,
'%teaser' => $node->teaser,
'%body' => $node->body,
);
}
$subject = strtr($context['subject'], $variables);
$body = strtr($context['message'], $variables);
$message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
$message['body'][] = drupal_html_to_text($body);
}
2007-06-29 18:06:51 +00:00
function system_message_action_form($context) {
$form['message'] = array(
'#type' => 'textarea',
'#title' => t('Message'),
'#default_value' => isset($context['message']) ? $context['message'] : '',
'#required' => TRUE,
'#rows' => '8',
'#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.'),
);
return $form;
}
function system_message_action_submit($form, $form_state) {
return array('message' => $form_state['values']['message']);
}
/**
2007-08-29 14:57:50 +00:00
* A configurable Drupal action. Sends a message to the current user's screen.
2007-06-29 18:06:51 +00:00
*/
function system_message_action(&$object, $context = array()) {
global $user;
$variables = array(
'%site_name' => variable_get('site_name', 'Drupal'),
'%username' => $user->name ? $user->name : variable_get('anonymous', t('Anonymous')),
2007-07-05 08:48:58 +00:00
);
2007-06-29 18:06:51 +00:00
// This action can be called in any context, but if placeholders
// are used a node object must be present to be the source
// of substituted text.
switch ($context['hook']) {
case 'nodeapi':
// Because this is not an action of type 'node' the node
// will not be passed as $object, but it will still be available
// in $context.
$node = $context['node'];
break;
// The comment hook also provides the node, in context.
case 'comment':
$comment = $context['comment'];
$node = node_load($comment->nid);
break;
case 'taxonomy':
$vocabulary = taxonomy_vocabulary_load($object->vid);
$variables = array_merge($variables, array(
'%term_name' => $object->name,
'%term_description' => $object->description,
'%term_id' => $object->tid,
'%vocabulary_name' => $vocabulary->name,
'%vocabulary_description' => $vocabulary->description,
'%vocabulary_id' => $vocabulary->vid,
)
);
break;
default:
// We are being called directly.
$node = $object;
}
if (isset($node) && is_object($node)) {
$variables = array_merge($variables, array(
'%uid' => $node->uid,
'%node_url' => url('node/'. $node->nid, array('absolute' => TRUE)),
'%node_type' => check_plain(node_get_types('name', $node)),
'%title' => filter_xss($node->title),
'%teaser' => filter_xss($node->teaser),
'%body' => filter_xss($node->body),
)
);
}
$context['message'] = strtr($context['message'], $variables);
drupal_set_message($context['message']);
}
/**
2007-08-29 14:57:50 +00:00
* Implementation of a configurable Drupal action. Redirect user to a URL.
2007-06-29 18:06:51 +00:00
*/
function system_goto_action_form($context) {
$form['url'] = array(
'#type' => 'textfield',
'#title' => t('URL'),
'#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.'),
'#default_value' => isset($context['url']) ? $context['url'] : '',
'#required' => TRUE,
);
return $form;
}
function system_goto_action_submit($form, $form_state) {
return array(
'url' => $form_state['values']['url']
);
}
function system_goto_action($object, $context) {
drupal_goto($context['url']);
2007-07-29 17:28:23 +00:00
}
2007-08-26 16:41:02 +00:00
function _system_zonelist() {
$timestamp = time();
$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);
$zones = array();
foreach ($zonelist as $offset) {
$zone = $offset * 3600;
$zones[$zone] = format_date($timestamp, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') .' O', $zone);
}
return $zones;
}