1. 8.2.x core/modules/system/system.module
  2. 8.0.x core/modules/system/system.module
  3. 8.1.x core/modules/system/system.module
  4. 4.6.x modules/system.module
  5. 4.7.x modules/system.module
  6. 5.x modules/system/system.module
  7. 6.x modules/system/system.module
  8. 7.x modules/system/system.module

Configuration system that lets administrators modify the workings of the site.

File

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

Functions

Namesort descending Description
confirm_form Generates a form array for a confirmation form.
system_actions_configure Menu callback. Create the form for configuration of a single action.
system_actions_configure_submit Process system_actions_configure form submissions.
system_actions_configure_validate Validate system_actions_configure form submissions.
system_actions_delete_form Create the form for confirmation of deleting an action.
system_actions_delete_form_submit Process system_actions_delete form submissions.
system_actions_manage Menu callback. Display an overview of available and configured actions.
system_actions_manage_form Define the form for the actions overview page.
system_actions_manage_form_submit Process system_actions_manage form submissions.
system_actions_remove_orphans Remove actions that are in the database but not supported by any enabled module.
system_action_delete_orphans_post Post-deletion operations for deleting action orphans.
system_action_info Implementation of hook_action_info().
system_admin_compact_mode Determine if a user is in compact mode.
system_admin_menu_block Provide a single block on the administration overview page.
system_admin_theme_submit Process admin theme form submissions.
system_block Implementation of hook_block().
system_check_directory Checks the existence of the directory specified in $form_element. This function is called from the system_settings form to check both the file_directory_path and file_directory_temp directories. If validation fails, the form element is flagged with an…
system_check_http_request Checks whether the server is capable of issuing HTTP requests.
system_cron Implementation of hook_cron().
system_default_region Get the name of the default region for a given theme.
system_elements Implementation of hook_elements().
system_find_base_theme This function has been deprecated in favor of system_find_base_themes().
system_find_base_themes Find all the base themes for the specified theme.
system_get_files_database Retrieves the current status of an array of files in the system table.
system_get_module_admin_tasks Generate a list of tasks offered by a specified module.
system_goto_action
system_goto_action_form Implementation of a configurable Drupal action. Redirect user to a URL.
system_goto_action_submit
system_help Implementation of hook_help().
system_hook_info Implementation of hook_hook_info().
system_init Implementation of hook_init().
system_initialize_theme_blocks Assign an initial, default set of blocks for a theme.
system_mail Implementation of hook_mail().
system_menu Implementation of hook_menu().
system_message_action A configurable Drupal action. Sends a message to the current user's screen.
system_message_action_form
system_message_action_submit
system_node_type Implementation of hook_node_type().
system_perm Implementation of hook_perm().
system_region_list Get a list of available regions from a specified theme.
system_send_email_action Implementation of a configurable Drupal action. Sends an email.
system_send_email_action_form Return a form definition so the Send email action can be configured.
system_send_email_action_submit Process system_send_email_action form submissions.
system_send_email_action_validate Validate system_send_email_action form submissions.
system_settings_form Add default buttons to a form and set its prefix.
system_settings_form_submit Execute the system_settings_form.
system_theme Implementation of hook_theme().
system_theme_data Collect data about all currently available themes.
system_theme_default Prepare defaults for themes.
system_theme_select_form Returns a fieldset containing the theme select form.
system_user Implementation of hook_user().
theme_system_powered_by Format the Powered by Drupal text.
_system_sort_requirements Helper function to sort requirements.
_system_themes_access Menu item access callback - only admin or enabled themes can be accessed.
_system_theme_data Helper function to scan and collect theme .info data and their engines.
_system_zonelist Generate an array of time zones and their local time&date.

Constants

Namesort descending Description
DRUPAL_CORE_COMPATIBILITY Core API compatibility.
DRUPAL_MAXIMUM_TEMP_FILE_AGE Maximum age of temporary files in seconds.
DRUPAL_MINIMUM_MYSQL Minimum supported version of MySQL, if it is used.
DRUPAL_MINIMUM_PGSQL Minimum supported version of PostgreSQL, if it is used.
DRUPAL_MINIMUM_PHP Minimum supported version of PHP.
DRUPAL_MINIMUM_PHP_MEMORY_LIMIT Minimum recommended value of PHP memory_limit.
VERSION The current system version.