Spike PHPCoverage Details: system.module

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