Newer
Older
// $Id$
/**
* @file
* Configuration system that lets administrators modify the workings of the site.
*/
Gábor Hojtsy
committed
define('VERSION', '6.0-beta1');
Dries Buytaert
committed
define('DRUPAL_CORE_COMPATIBILITY', '6.x');
Dries Buytaert
committed
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
// Maximum age of temporary files in seconds.
define('DRUPAL_MAXIMUM_TEMP_FILE_AGE', 1440);
Gábor Hojtsy
committed
function system_help($path, $arg) {
Gábor Hojtsy
committed
switch ($path) {
Dries Buytaert
committed
case 'admin/help#system':
Gábor Hojtsy
committed
$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>';
Dries Buytaert
committed
$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>';
$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>';
$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>';
Dries Buytaert
committed
return $output;
Dries Buytaert
committed
case 'admin':
return '<p>'. t('Welcome to the administration section. Here you may control how your site functions.') .'</p>';
Steven Wittens
committed
case 'admin/by-module':
return '<p>'. t('This page shows you all available administration tasks for each module.') .'</p>';
Dries Buytaert
committed
case 'admin/build/themes':
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>';
Gábor Hojtsy
committed
case 'admin/build/themes/settings/'. $arg[4]:
$reference = explode('.', $arg[4], 2);
$theme = array_pop($reference);
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>';
Gábor Hojtsy
committed
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>';
Steven Wittens
committed
case 'admin/build/modules':
Dries Buytaert
committed
$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;
Dries Buytaert
committed
case 'admin/build/modules/uninstall':
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>';
Gábor Hojtsy
committed
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>';
}
Gábor Hojtsy
committed
return $output;
Gábor Hojtsy
committed
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").');
Steven Wittens
committed
case 'admin/logs/status':
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>';
Dries Buytaert
committed
}
Dries Buytaert
committed
function system_theme() {
return array_merge(drupal_common_themes(), array(
'system_theme_select_form' => array(
'arguments' => array('form' => NULL),
'file' => 'system.admin.inc',
Dries Buytaert
committed
),
'system_themes_form' => array(
'arguments' => array('form' => NULL),
'file' => 'system.admin.inc',
Dries Buytaert
committed
),
'system_modules' => array(
'arguments' => array('form' => NULL),
'file' => 'system.admin.inc',
Dries Buytaert
committed
),
'system_modules_uninstall' => array(
'arguments' => array('form' => NULL),
'file' => 'system.admin.inc',
Dries Buytaert
committed
),
'status_report' => array(
'arguments' => array('requirements' => NULL),
'file' => 'system.admin.inc',
Dries Buytaert
committed
),
'admin_page' => array(
'arguments' => array('blocks' => NULL),
'file' => 'system.admin.inc',
Dries Buytaert
committed
),
'admin_block' => array(
'arguments' => array('block' => NULL),
'file' => 'system.admin.inc',
Dries Buytaert
committed
),
'admin_block_content' => array(
'arguments' => array('content' => NULL),
'file' => 'system.admin.inc',
Dries Buytaert
committed
),
'system_admin_by_module' => array(
'arguments' => array('menu_items' => NULL),
'file' => 'system.admin.inc',
Dries Buytaert
committed
),
));
}
Gábor Hojtsy
committed
return array('administer site configuration', 'access administration pages', 'administer actions', 'select different theme', 'administer files');
/**
* Implementation of hook_elements().
*/
function system_elements() {
// Top level form
Gerhard Killesreiter
committed
$type['form'] = array('#method' => 'post', '#action' => request_uri());
Dries Buytaert
committed
$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'));
$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);
$type['textfield'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE);
Dries Buytaert
committed
$type['password'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128);
Dries Buytaert
committed
$type['password_confirm'] = array('#input' => TRUE, '#process' => array('expand_password_confirm'));
Dries Buytaert
committed
$type['textarea'] = array('#input' => TRUE, '#cols' => 60, '#rows' => 5, '#resizable' => TRUE);
Dries Buytaert
committed
$type['radios'] = array('#input' => TRUE, '#process' => array('expand_radios'));
Dries Buytaert
committed
$type['radio'] = array('#input' => TRUE, '#default_value' => NULL);
Dries Buytaert
committed
$type['checkboxes'] = array('#input' => TRUE, '#process' => array('expand_checkboxes'), '#tree' => TRUE);
Dries Buytaert
committed
$type['checkbox'] = array('#input' => TRUE, '#return_value' => 1);
Dries Buytaert
committed
$type['select'] = array('#input' => TRUE, '#size' => 0, '#multiple' => FALSE);
Dries Buytaert
committed
$type['weight'] = array('#input' => TRUE, '#delta' => 10, '#default_value' => 0, '#process' => array('process_weight'));
$type['date'] = array('#input' => TRUE, '#process' => array('expand_date'), '#element_validate' => array('date_validate'));
Dries Buytaert
committed
$type['file'] = array('#input' => TRUE, '#size' => 60);
Dries Buytaert
committed
$type['item'] = array('#value' => '');
Dries Buytaert
committed
$type['hidden'] = array('#input' => TRUE);
$type['value'] = array('#input' => TRUE);
$type['markup'] = array('#prefix' => '', '#suffix' => '');
Dries Buytaert
committed
$type['fieldset'] = array('#collapsible' => FALSE, '#collapsed' => FALSE, '#value' => NULL);
Dries Buytaert
committed
function system_menu() {
$items['system/files'] = array(
'title' => 'File download',
Dries Buytaert
committed
'page callback' => 'file_download',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['admin'] = array(
'title' => 'Administer',
Dries Buytaert
committed
'access arguments' => array('access administration pages'),
'page callback' => 'system_main_admin_page',
'weight' => 9,
Dries Buytaert
committed
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/compact'] = array(
'title' => 'Compact mode',
Dries Buytaert
committed
'page callback' => 'system_admin_compact_page',
'type' => MENU_CALLBACK,
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/by-task'] = array(
'title' => 'By task',
Dries Buytaert
committed
'page callback' => 'system_main_admin_page',
Dries Buytaert
committed
'file' => 'system.admin.inc',
Dries Buytaert
committed
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/by-module'] = array(
'title' => 'By module',
Dries Buytaert
committed
'page callback' => 'system_admin_by_module',
'file' => 'system.admin.inc',
Dries Buytaert
committed
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
// menu items that are basically just menu blocks
$items['admin/settings'] = array(
'title' => 'Site configuration',
'description' => 'Adjust basic site configuration options.',
Dries Buytaert
committed
'position' => 'right',
'weight' => -5,
'page callback' => 'system_settings_overview',
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/build'] = array(
'title' => 'Site building',
'description' => 'Control how your site looks and feels.',
Dries Buytaert
committed
'position' => 'right',
'weight' => -10,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer site configuration'),
Dries Buytaert
committed
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/settings/admin'] = array(
'title' => 'Administration theme',
'description' => 'Settings for how your administrative pages should look.',
Dries Buytaert
committed
'position' => 'left',
'page callback' => 'drupal_get_form',
'page arguments' => array('system_admin_theme_settings'),
'block callback' => 'system_admin_theme_settings',
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
// Themes:
$items['admin/build/themes'] = array(
'title' => 'Themes',
'description' => 'Change which theme your site uses or allows users to set.',
Dries Buytaert
committed
'page callback' => 'drupal_get_form',
Gábor Hojtsy
committed
'page arguments' => array('system_themes_form', NULL),
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/build/themes/select'] = array(
'title' => 'List',
'description' => 'Select the default theme.',
Dries Buytaert
committed
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
);
$items['admin/build/themes/settings'] = array(
'title' => 'Configure',
Gábor Hojtsy
committed
'page arguments' => array('system_theme_settings'),
Dries Buytaert
committed
'type' => MENU_LOCAL_TASK,
);
// Theme configuration subtabs
$items['admin/build/themes/settings/global'] = array(
'title' => 'Global settings',
Dries Buytaert
committed
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
);
Dries Buytaert
committed
foreach (list_themes() as $theme) {
if ($theme->status) {
$items['admin/build/themes/settings/'. $theme->name] = array(
'title' => $theme->info['name'],
Dries Buytaert
committed
'page arguments' => array('system_theme_settings', $theme->name),
'type' => MENU_LOCAL_TASK,
);
Dries Buytaert
committed
// Modules:
$items['admin/build/modules'] = array(
'title' => 'Modules',
'description' => 'Enable or disable add-on modules for your site.',
Dries Buytaert
committed
'page callback' => 'drupal_get_form',
'page arguments' => array('system_modules'),
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/build/modules/list'] = array(
'title' => 'List',
Dries Buytaert
committed
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/build/modules/list/confirm'] = array(
'title' => 'List',
Dries Buytaert
committed
'type' => MENU_CALLBACK,
);
$items['admin/build/modules/uninstall'] = array(
'title' => 'Uninstall',
Dries Buytaert
committed
'page arguments' => array('system_modules_uninstall'),
'type' => MENU_LOCAL_TASK,
);
$items['admin/build/modules/uninstall/confirm'] = array(
'title' => 'Uninstall',
Dries Buytaert
committed
'type' => MENU_CALLBACK,
);
Gábor Hojtsy
committed
// Actions:
Gábor Hojtsy
committed
$items['admin/settings/actions'] = array(
Gábor Hojtsy
committed
'title' => 'Actions',
'description' => 'Manage the actions defined for your site.',
'access arguments' => array('administer actions'),
'page callback' => 'system_actions_manage'
);
Gábor Hojtsy
committed
$items['admin/settings/actions/manage'] = array(
Gábor Hojtsy
committed
'title' => 'Manage actions',
'description' => 'Manage the actions defined for your site.',
'page callback' => 'system_actions_manage',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -2,
);
Gábor Hojtsy
committed
$items['admin/settings/actions/configure'] = array(
'title' => 'Configure an advanced action',
Gábor Hojtsy
committed
'page callback' => 'drupal_get_form',
'page arguments' => array('system_actions_configure'),
'type' => MENU_CALLBACK,
);
Gábor Hojtsy
committed
$items['admin/settings/actions/delete/%actions'] = array(
Gábor Hojtsy
committed
'title' => 'Delete action',
'description' => 'Delete an action.',
'page callback' => 'drupal_get_form',
'page arguments' => array('system_actions_delete_form', 4),
'type' => MENU_CALLBACK,
);
Gábor Hojtsy
committed
$items['admin/settings/actions/orphan'] = array(
Gábor Hojtsy
committed
'title' => 'Remove orphans',
'page callback' => 'system_actions_remove_orphans',
'type' => MENU_CALLBACK,
);
Dries Buytaert
committed
// Settings:
$items['admin/settings/site-information'] = array(
'title' => 'Site information',
'description' => 'Change basic site information, such as the site name, slogan, e-mail address, mission, front page and more.',
Dries Buytaert
committed
'page callback' => 'drupal_get_form',
'page arguments' => array('system_site_information_settings'),
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/settings/error-reporting'] = array(
'title' => 'Error reporting',
'description' => 'Control how Drupal deals with errors including 403/404 errors as well as PHP error reporting.',
Dries Buytaert
committed
'page callback' => 'drupal_get_form',
'page arguments' => array('system_error_reporting_settings'),
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
Dries Buytaert
committed
$items['admin/settings/logging'] = array(
'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.",
Dries Buytaert
committed
'page callback' => 'system_logging_overview',
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
Dries Buytaert
committed
$items['admin/settings/performance'] = array(
'title' => 'Performance',
'description' => 'Enable or disable page caching for anonymous users and set CSS and JS bandwidth optimization options.',
Dries Buytaert
committed
'page callback' => 'drupal_get_form',
'page arguments' => array('system_performance_settings'),
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/settings/file-system'] = array(
'title' => 'File system',
'description' => 'Tell Drupal where to store uploaded files and how they are accessed.',
Dries Buytaert
committed
'page callback' => 'drupal_get_form',
'page arguments' => array('system_file_system_settings'),
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/settings/image-toolkit'] = array(
'title' => 'Image toolkit',
'description' => 'Choose which image toolkit to use if you have installed optional toolkits.',
Dries Buytaert
committed
'page callback' => 'drupal_get_form',
'page arguments' => array('system_image_toolkit_settings'),
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/content/rss-publishing'] = array(
'title' => 'RSS publishing',
'description' => 'Configure the number of items per feed and whether feeds should be titles/teasers/full-text.',
Dries Buytaert
committed
'page callback' => 'drupal_get_form',
'page arguments' => array('system_rss_feeds_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/settings/date-time'] = array(
'title' => 'Date and time',
'description' => "Settings for how Drupal displays date and time, as well as the system's default timezone.",
Dries Buytaert
committed
'page callback' => 'drupal_get_form',
'page arguments' => array('system_date_time_settings'),
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/settings/date-time/lookup'] = array(
'title' => t('Date and time lookup'),
'type' => MENU_CALLBACK,
'page callback' => 'system_date_time_lookup',
'file' => 'system.admin.inc',
Dries Buytaert
committed
$items['admin/settings/site-maintenance'] = array(
'title' => 'Site maintenance',
'description' => 'Take the site off-line for maintenance or bring it back online.',
Dries Buytaert
committed
'page callback' => 'drupal_get_form',
'page arguments' => array('system_site_maintenance_settings'),
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/settings/clean-urls'] = array(
'title' => 'Clean URLs',
'description' => 'Enable or disable clean URLs for your site.',
Dries Buytaert
committed
'page callback' => 'drupal_get_form',
'page arguments' => array('system_clean_url_settings'),
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
// Logs:
$items['admin/logs'] = array(
'title' => 'Logs',
'description' => 'View system logs and other status information.',
Dries Buytaert
committed
'page callback' => 'system_admin_menu_block_page',
'weight' => 5,
'position' => 'left',
Dries Buytaert
committed
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/logs/status'] = array(
'title' => 'Status report',
'description' => "Get a status report about your site's operation and any detected problems.",
Dries Buytaert
committed
'page callback' => 'system_status',
'weight' => 10,
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/logs/status/run-cron'] = array(
'title' => 'Run cron',
Dries Buytaert
committed
'page callback' => 'system_run_cron',
'type' => MENU_CALLBACK,
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/logs/status/php'] = array(
'title' => 'PHP',
Dries Buytaert
committed
'page callback' => 'system_php',
'type' => MENU_CALLBACK,
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
$items['admin/logs/status/sql'] = array(
'title' => 'SQL',
Dries Buytaert
committed
'page callback' => 'system_sql',
'type' => MENU_CALLBACK,
'file' => 'system.admin.inc',
Dries Buytaert
committed
);
// Default page for batch operations
$items['batch'] = array(
'page callback' => 'system_batch_page',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
'file' => 'system.admin.inc',
);
Dries Buytaert
committed
function system_init() {
// Use the administrative theme if the user is looking at a page in the admin/* path.
Dries Buytaert
committed
if (arg(0) == 'admin' || (variable_get('node_admin_theme', '0') && arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit'))) {
Dries Buytaert
committed
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');
}
/**
* Implementation of hook_user().
*
* Allows users to individually set their theme and time zone.
*/
function system_user($type, $edit, &$user, $category = NULL) {
if ($type == 'form' && $category == 'account') {
Dries Buytaert
committed
$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);
if (variable_get('configurable_timezones', 1)) {
$form['timezone'] = array(
Dries Buytaert
committed
'#type' => 'fieldset',
'#title' => t('Locale settings'),
'#weight' => 6,
'#collapsible' => TRUE,
);
$form['timezone']['timezone'] = array(
'#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.'),
Dries Buytaert
committed
/**
* Provide a single block on the administration overview page.
*/
function system_admin_menu_block($item) {
Dries Buytaert
committed
$content = array();
Dries Buytaert
committed
if (!isset($item['mlid'])) {
Gábor Hojtsy
committed
$item += db_fetch_array(db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = '%s' AND module = 'system'", $item['path']));
Dries Buytaert
committed
$result = db_query("
Gábor Hojtsy
committed
SELECT m.*, ml.*
Dries Buytaert
committed
FROM {menu_links} ml
INNER JOIN {menu_router} m ON ml.router_path = m.path
Gábor Hojtsy
committed
WHERE ml.plid = %d AND ml.menu_name = '%s' AND hidden = 0", $item['mlid'], $item['menu_name']);
Dries Buytaert
committed
while ($item = db_fetch_array($result)) {
_menu_link_translate($item);
Dries Buytaert
committed
if (!$item['access']) {
continue;
Dries Buytaert
committed
}
Gábor Hojtsy
committed
// 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;
Dries Buytaert
committed
}
Gábor Hojtsy
committed
ksort($content);
Dries Buytaert
committed
return $content;
}
Dries Buytaert
committed
function system_admin_theme_submit($form, &$form_state) {
Dries Buytaert
committed
// If we're changing themes, make sure the theme has its blocks initialized.
Dries Buytaert
committed
if ($form_state['values']['admin_theme'] != variable_get('admin_theme', '0')) {
Dries Buytaert
committed
$result = db_result(db_query("SELECT COUNT(*) FROM {blocks} WHERE theme = '%s'", $form_state['values']['admin_theme']));
if (!$result) {
Dries Buytaert
committed
system_initialize_theme_blocks($form_state['values']['admin_theme']);
Dries Buytaert
committed
}
}
}
/**
* 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
*/
Dries Buytaert
committed
function system_theme_select_form(&$form_state, $description = '', $default_value = '', $weight = 0) {
if (user_access('select different theme')) {
Steven Wittens
committed
$enabled = array();
Dries Buytaert
committed
$themes = list_themes();
foreach ($themes as $theme) {
if ($theme->status) {
$enabled[] = $theme;
}
}
if (count($enabled) > 1) {
ksort($enabled);
$form['themes'] = array(
'#type' => 'fieldset',
'#title' => t('Theme configuration'),
'#description' => $description,
'#collapsible' => TRUE,
'#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.
Dries Buytaert
committed
$info->key = $info->name == variable_get('theme_default', 'garland') ? '' : $info->name;
Dries Buytaert
committed
$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');
$form['themes'][$info->key]['screenshot'] = array('#value' => $screenshot);
$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>' : ''));
$options[$info->key] = '';
}
$form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $default_value ? $default_value : '');
$form['#weight'] = $weight;
return $form;
}
}
}
Dries Buytaert
committed
/**
* Checks the existence of the directory specified in $form_element. This
* function is called from the system_settings form to check both the
Dries Buytaert
committed
* 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.
*/
function system_check_directory($form_element) {
Dries Buytaert
committed
file_check_directory($form_element['#value'], FILE_CREATE_DIRECTORY, $form_element['#parents'][0]);
return $form_element;
}
/**
* Retrieves the current status of an array of files in the system table.
*/
function system_get_files_database(&$files, $type) {
Gerhard Killesreiter
committed
$result = db_query("SELECT filename, name, type, status, throttle, schema_version FROM {system} WHERE type = '%s'", $type);
if (isset($files[$file->name]) && is_object($files[$file->name])) {
Gerhard Killesreiter
committed
$file->old_filename = $file->filename;
if (!isset($files[$file->name]) || !isset($files[$file->name]->$key)) {
$files[$file->name]->$key = $value;
}
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',
Gábor Hojtsy
committed
'slogan',
'primary_links',
'secondary_links',
Gábor Hojtsy
committed
'stylesheets' => array(
'all' => array('style.css')
),
'scripts' => array('script.js'),
Dries Buytaert
committed
'screenshot' => 'screenshot.png',
Gábor Hojtsy
committed
'php' => DRUPAL_MINIMUM_PHP,
);
}
function system_theme_data() {
// Find themes
Dries Buytaert
committed
$themes = drupal_system_listing('\.info$', 'themes');
Dries Buytaert
committed
$engines = drupal_system_listing('\.engine$', 'themes/engines');
// Remove all theme engines from the system table
Gábor Hojtsy
committed
db_query("DELETE FROM {system} WHERE type = '%s'", 'theme_engine');
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);
Dries Buytaert
committed
}
Dries Buytaert
committed
$defaults = system_theme_default();
Dries Buytaert
committed
$sub_themes = array();
// Read info files for each theme
foreach ($themes as $key => $theme) {
$themes[$key]->info = drupal_parse_info_file($theme->filename) + $defaults;
Gábor Hojtsy
committed
// 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]);
Dries Buytaert
committed
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;
Dries Buytaert
committed
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;
}
}
Gábor Hojtsy
committed
// 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;
}
Dries Buytaert
committed
}
Gábor Hojtsy
committed
$themes[$key]->info['stylesheets'] = $pathed_stylesheets;
Gábor Hojtsy
committed
// Give the scripts proper path information.
$scripts = array();
foreach ($themes[$key]->info['scripts'] as $script) {
$scripts[$script] = dirname($themes[$key]->filename) .'/'. $script;
Gábor Hojtsy
committed
}
Gábor Hojtsy
committed
$themes[$key]->info['scripts'] = $scripts;
Dries Buytaert
committed
// Give the screenshot proper path information.
if (!empty($themes[$key]->info['screenshot'])) {
$themes[$key]->info['screenshot'] = dirname($themes[$key]->filename) .'/'. $themes[$key]->info['screenshot'];
}
Dries Buytaert
committed
// 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;
Gábor Hojtsy
committed
// Add any stylesheets from the base theme, unless the names match in which case
// the sub-theme wins. Note that we slip the base theme's stylesheets in at the
Gábor Hojtsy
committed
// 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
// the sub-theme wins. Note that we slip the base theme's scripts in at the
Gábor Hojtsy
committed
// 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'];
}
}
system_get_files_database($themes, 'theme');
db_query("DELETE FROM {system} WHERE type = 'theme'");
Dries Buytaert
committed
if (!isset($theme->owner)) {
$theme->owner = '';
}
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);
}
return $themes;
}
Dries Buytaert
committed
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
/**
* 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;
}
/**
* Get a list of available regions from a specified theme.
*
Dries Buytaert
committed
* @param $theme_key
* The name of a theme.
* @return
* An array of regions in the form $region['name'] = 'description'.
*/
Dries Buytaert
committed
function system_region_list($theme_key) {
static $list = array();
if (!array_key_exists($theme_key, $list)) {
$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']);
Dries Buytaert
committed
return $list[$theme_key];
}
/**
* 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));
Steven Wittens
committed
return isset($regions[0]) ? $regions[0] : '';
* Assign an initial, default set of blocks for a theme.
*
* This function is called the first time a new theme is enabled. The new theme
* 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.
Dries Buytaert
committed
if (!(db_result(db_query("SELECT COUNT(*) FROM {blocks} WHERE theme = '%s'", $theme)))) {
Dries Buytaert
committed
$default_theme = variable_get('theme_default', 'garland');
$regions = system_region_list($theme);
$result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
while ($block = db_fetch_array($result)) {
// 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);
}
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']);
Dries Buytaert
committed
/**
* Add default buttons to a form and set its prefix
*/
function system_settings_form($form) {
Dries Buytaert
committed
$form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
$form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
if (!empty($_POST) && form_get_errors()) {
Dries Buytaert
committed
drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
Dries Buytaert
committed
$form['#submit'][] = 'system_settings_form_submit';
$form['#validate'][] = 'system_settings_form_validate';
Dries Buytaert
committed
$form['#theme'] = 'system_settings_form';
Dries Buytaert
committed
return $form;
/**
* Execute the system_settings_form.
*
* If you want node type configure style handling of your checkboxes,
* add an array_filter value to your form.
*
Dries Buytaert
committed
function system_settings_form_submit($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
// Exclude unnecessary elements.
Dries Buytaert
committed
unset($form_state['values']['submit'], $form_state['values']['reset'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token']);
Dries Buytaert
committed
foreach ($form_state['values'] as $key => $value) {
if ($op == t('Reset to defaults')) {
variable_del($key);
}
else {
Dries Buytaert
committed
if (is_array($value) && isset($form_state['values']['array_filter'])) {
$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.'));
drupal_set_message(t('The configuration options have been saved.'));
}
Steven Wittens
committed
Dries Buytaert
committed
drupal_rebuild_theme_registry();
* Helper function to sort requirements.
function _system_sort_requirements($a, $b) {
if (!isset($a['weight'])) {
if (!isset($b['weight'])) {
return strcmp($a['title'], $b['title']);
return -$b['weight'];
return isset($b['weight']) ? $a['weight'] - $b['weight'] : $a['weight'];
/**
* 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;
Gábor Hojtsy
committed
$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);
Neil Drumm
committed
}
}
}
/**
* Output a confirmation form
*
Dries Buytaert
committed
* This function returns a complete form for confirming an action. A link is
* offered to go back to the item that is being changed in case the user changes
* his/her mind.
*
* You can check for the existence of $_POST[$name] (where $name
Dries Buytaert
committed
* is usually 'confirm') to check if the confirmation was successful or
* use the regular submit model.
*
* @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>?").
* @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.
Dries Buytaert
committed
* The form.
function confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm') {
$description = isset($description) ? $description : t('This action cannot be undone.');
// Prepare cancel link
$query = $fragment = NULL;
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;
Steven Wittens
committed
}
$cancel = l($no ? $no : t('Cancel'), $path, array('query' => $query, 'fragment' => $fragment));
drupal_set_title($question);
// Confirm form fails duplication check, as the form values rarely change -- so skip it.
$form['#skip_duplicate_check'] = TRUE;
Dries Buytaert
committed
$form['#attributes'] = array('class' => 'confirmation');
$form['description'] = array('#value' => $description);
$form[$name] = array('#type' => 'hidden', '#value' => 1);
Dries Buytaert
committed
$form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $yes ? $yes : t('Confirm'));
$form['actions']['cancel'] = array('#value' => $cancel);
Dries Buytaert
committed
$form['#theme'] = 'confirm_form';