annotate modules/system/system.module @ 3:165d43f946a8 6.1

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