system.module

  1. drupal
    1. 4.6 modules/system.module
    2. 4.7 modules/system.module
    3. 5 modules/system/system.module
    4. 6 modules/system/system.module
    5. 7 modules/system/system.module
    6. 8 core/modules/system/system.module

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

Functions & methods

NameDescription
confirm_form
system_check_directoryChecks the existence of the directory specified in $form_element. This function is called from the system_view_general form to check both the file_directory_path and file_directory_temp directories. If validation fails, the form element is flagged…
system_cron_settingsReturn the cron status and errors for admin/settings.
system_default_regionGet the name of the default region for a given theme.
system_elementsImplementation of hook_elements().
system_get_files_databaseRetrieves the current status of an array of files in the system table.
system_helpImplementation of hook_help().
system_initialize_theme_blocksAssign an initial, default set of blocks for a theme.
system_listingReturns an array of files objects of the given type from both the site-wide directory (i.e. modules/) and site-specific directory (i.e. sites/somesite/modules/). The returned array will be keyed using the key specified (name, basename, filename). …
system_menuImplementation of hook_menu().
system_modulesMenu callback; displays a listing of all modules.
system_modules_submit
system_permImplementation of hook_perm().
system_region_listGet a list of available regions from a specified theme.
system_settings_form
system_settings_form_submitExecute the system_settings_form.
system_site_settingsMenu callback; displays a module's settings page.
system_themesMenu callback; displays a listing of all themes.
system_themes_submit
system_theme_dataCollect data about all currently available themes
system_theme_select_formReturns a fieldset containing the theme select form.
system_theme_settingsMenu callback; display theme configuration for entire site and individual themes.
system_theme_settings_submit
system_userImplementation of hook_user().
system_view_general
theme_system_modules
theme_system_themes
theme_system_theme_select_form
_system_zonelist

Constants

NameDescription
VERSION

File

modules/system.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Configuration system that lets administrators modify the workings of the site.
  5. */
  6. define('VERSION', '4.7.12-dev');
  7. /**
  8. * Implementation of hook_help().
  9. */
  10. function system_help($section) {
  11. global $base_url;
  12. switch ($section) {
  13. case 'admin/help#system':
  14. $output = '<p>'. t('The system module provides system-wide defaults such as running jobs at a particular time, and storing web pages to improve efficiency. The ability to run scheduled jobs makes administering the web site more usable, as administrators do not have to manually start jobs. The storing of web pages, or caching, allows the site to efficiently re-use web pages and improve web site performance. The settings module provides control over preferences, behaviours including visual and operational settings.') .'</p>';
  15. $output .= '<p>'. t('Some modules require regularly scheduled actions, such as cleaning up logfiles. Cron, which stands for chronograph, is a periodic command scheduler executing commands at intervals specified in seconds. It can be used to control the execution of daily, weekly and monthly jobs (or anything with a period measured in seconds). The aggregator module periodically updates feeds using cron. Ping periodically notifies services of new content on your site. Search periodically indexes the content on your site. Automating tasks is one of the best ways to keep a system running smoothly, and if most of your administration does not require your direct involvement, cron is an ideal solution.') .'</p>';
  16. $output .= '<p>'. t('There is a caching mechanism which stores dynamically generated web pages in a database. By caching a web page, the system module does not have to create the page each time someone wants to view it, instead it takes only one SQL query to display it, reducing response time and the server\'s load. Only pages requested by <em>anonymous</em> users are cached. In order to reduce server load and save bandwidth, the system module stores and sends cached pages compressed.') .'</p>';
  17. $output .= t('<p>You can</p>
  18. <ul>
  19. <li>activate your cron job on the cron page <a href="%file-cron">cron.php</a>.</li>
  20. <li>read how to <a href="%external-http-drupal-org-cron">configure cron jobs</a>.</li>
  21. <li>administer cache settings in <a href="%admin-settings">administer &gt;&gt; settings</a>.</li>
  22. </ul>
  23. ', array('%file-cron' => 'cron.php', '%external-http-drupal-org-cron' => 'http://drupal.org/cron', '%admin-settings' => url('admin/settings')));
  24. $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%system">System page</a>.', array('%system' => 'http://drupal.org/handbook/modules/system/')) .'</p>';
  25. return $output;
  26. case 'admin/modules#description':
  27. return t('Handles general site configuration for administrators.');
  28. case 'admin':
  29. return t('<p>Welcome to the administration section. Below are the most recent system events.</p>');
  30. case 'admin/settings':
  31. return t('<p>General configuration options for your site. Set up the name of the site, e-mail address used in mail-outs, clean URL options, caching, etc.</p>');
  32. case 'admin/themes':
  33. return t('<p>Select which themes are available to your users and specify the default theme. To configure site-wide display settings, click the "configure" task above. Alternately, to override these settings in a specific theme, click the "configure" link for the corresponding theme. Note that different themes may have different regions available for rendering content like blocks. If you want consistency in what your users see, you may wish to enable only one theme.</p>');
  34. case 'admin/themes/settings':
  35. return t('<p>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>');
  36. case 'admin/themes/settings/'. arg(3):
  37. $reference = explode('.', arg(3), 2);
  38. $theme = array_pop($reference);
  39. return t('<p>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.</p>', array('%template' => check_plain($theme), '%global' => url('admin/themes/settings')));
  40. case 'admin/modules':
  41. return t('<p>Modules are plugins for Drupal that extend its core functionality. Here you can select which modules are enabled. Click on the name of the module in the navigation menu for their individual configuration pages. Once a module is enabled, new <a href="%permissions">permissions</a> might be made available. Modules can automatically be temporarily disabled to reduce server load when your site becomes extremely busy by enabling the throttle.module and checking throttle. The auto-throttle functionality must be enabled on the <a href="%throttle">throttle configuration page</a> after having enabled the throttle module.</p>
  42. <p>It is important that <a href="%update-php">update.php</a> is run every time a module is updated to a newer version.</p>', array('%permissions' => url('admin/access/permissions'), '%throttle' => url('admin/settings/throttle'), '%update-php' => $base_url .'/update.php'));
  43. }
  44. }
  45. /**
  46. * Implementation of hook_perm().
  47. */
  48. function system_perm() {
  49. return array('administer site configuration', 'access administration pages', 'select different theme');
  50. }
  51. /**
  52. * Implementation of hook_elements().
  53. */
  54. function system_elements() {
  55. // Top level form
  56. $type['form'] = array('#method' => 'post', '#action' => request_uri());
  57. // Inputs
  58. $type['checkbox'] = array('#input' => TRUE, '#return_value' => 1);
  59. $type['submit'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => TRUE);
  60. $type['button'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => FALSE);
  61. $type['textfield'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE);
  62. $type['password'] = array('#input' => TRUE, '#size' => 30);
  63. $type['password_confirm'] = array('#input' => TRUE, '#process' => array('expand_password_confirm' => array()));
  64. $type['textarea'] = array('#input' => TRUE, '#cols' => 60, '#rows' => 5);
  65. $type['radios'] = array('#input' => TRUE, '#process' => array('expand_radios' => array()));
  66. $type['radio'] = array('#input' => TRUE);
  67. $type['checkboxes'] = array('#input' => TRUE, '#process' => array('expand_checkboxes' => array()), '#tree' => TRUE);
  68. $type['select'] = array('#input' => TRUE);
  69. $type['weight'] = array('#input' => TRUE, '#delta' => 10, '#default_value' => 0);
  70. $type['date'] = array('#input' => TRUE, '#process' => array('expand_date' => array()), '#validate' => array('date_validate' => array()));
  71. $type['file'] = array('#input' => TRUE, '#size' => 60);
  72. // Form structure
  73. $type['item'] = array();
  74. $type['hidden'] = array('#input' => TRUE);
  75. $type['value'] = array('#input' => TRUE);
  76. $type['markup'] = array('#prefix' => '', '#suffix' => '');
  77. $type['fieldset'] = array('#collapsible' => FALSE, '#collapsed' => FALSE);
  78. $type['token'] = array('#input'=> TRUE);
  79. return $type;
  80. }
  81. /**
  82. * Implementation of hook_menu().
  83. */
  84. function system_menu($may_cache) {
  85. $items = array();
  86. if ($may_cache) {
  87. $items[] = array('path' => 'system/files', 'title' => t('file download'),
  88. 'callback' => 'file_download',
  89. 'access' => TRUE,
  90. 'type' => MENU_CALLBACK);
  91. $access = user_access('administer site configuration');
  92. $items[] = array('path' => 'admin', 'title' => t('administer'),
  93. 'access' => user_access('access administration pages'),
  94. 'callback' => 'watchdog_overview',
  95. 'weight' => 9);
  96. // Themes:
  97. $items[] = array('path' => 'admin/themes', 'title' => t('themes'),
  98. 'callback' => 'system_themes', 'access' => $access);
  99. $items[] = array('path' => 'admin/themes/select', 'title' => t('list'),
  100. 'callback' => 'system_themes', 'access' => $access,
  101. 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -1);
  102. $items[] = array('path' => 'admin/themes/settings', 'title' => t('configure'),
  103. 'callback' => 'system_theme_settings', 'access' => $access,
  104. 'type' => MENU_LOCAL_TASK);
  105. // Theme configuration subtabs
  106. $items[] = array('path' => 'admin/themes/settings/global', 'title' => t('global settings'),
  107. 'callback' => 'system_theme_settings', 'access' => $access,
  108. 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -1);
  109. foreach (list_themes() as $theme) {
  110. if ($theme->status) {
  111. $items[] = array('path' => 'admin/themes/settings/'. $theme->name, 'title' => $theme->name,
  112. 'callback' => 'system_theme_settings', 'callback arguments' => array($theme->name), 'access' => $access,
  113. 'type' => MENU_LOCAL_TASK);
  114. }
  115. }
  116. // Modules:
  117. $items[] = array('path' => 'admin/settings', 'title' => t('settings'),
  118. 'callback' => 'system_site_settings', 'access' => $access);
  119. foreach (module_list() as $name) {
  120. if (module_hook($name, 'settings')) {
  121. $items[] = array('path' => 'admin/settings/'. $name, 'title' => t($name));
  122. }
  123. }
  124. $items[] = array('path' => 'admin/modules', 'title' => t('modules'),
  125. 'callback' => 'system_modules', 'access' => $access);
  126. }
  127. return $items;
  128. }
  129. /**
  130. * Implementation of hook_user().
  131. *
  132. * Allows users to individually set their theme and time zone.
  133. */
  134. function system_user($type, $edit, &$user, $category = NULL) {
  135. if ($type == 'form' && $category == 'account') {
  136. $form['theme_select'] = system_theme_select_form(t('Selecting a different theme will change the look and feel of the site.'), $edit['theme'], 2);
  137. if (variable_get('configurable_timezones', 1)) {
  138. $zones = _system_zonelist();
  139. $form['timezone'] = array('#type'=>'fieldset', '#title' => t('Locale settings'), '#weight' => 6);
  140. $form['timezone']['timezone'] = array(
  141. '#type' => 'select', '#title' => t('Time zone'), '#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
  142. '#options' => $zones, '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')
  143. );
  144. }
  145. return $form;
  146. }
  147. }
  148. /**
  149. * Returns a fieldset containing the theme select form.
  150. *
  151. * @param $description
  152. * description of the fieldset
  153. * @param $default_value
  154. * default value of theme radios
  155. * @param $weight
  156. * weight of the fieldset
  157. * @return
  158. * a form array
  159. */
  160. function system_theme_select_form($description = '', $default_value = '', $weight = 0) {
  161. if (user_access('select different theme')) {
  162. foreach (list_themes() as $theme) {
  163. if ($theme->status) {
  164. $enabled[] = $theme;
  165. }
  166. }
  167. if (count($enabled) > 1) {
  168. ksort($enabled);
  169. $form['themes'] = array(
  170. '#type' => 'fieldset',
  171. '#title' => t('Theme configuration'),
  172. '#description' => $description,
  173. '#collapsible' => TRUE,
  174. '#theme' => 'system_theme_select_form'
  175. );
  176. foreach ($enabled as $info) {
  177. // For the default theme, revert to an empty string so the user's theme updates when the site theme is changed.
  178. $info->key = $info->name == variable_get('theme_default', 'bluemarine') ? '' : $info->name;
  179. $info->screenshot = dirname($info->filename) . '/screenshot.png';
  180. $screenshot = file_exists($info->screenshot) ? theme('image', $info->screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), false) : t('no screenshot');
  181. $form['themes'][$info->key]['screenshot'] = array('#type' => 'markup', '#value' => $screenshot);
  182. $form['themes'][$info->key]['description'] = array('#type' => 'item', '#title' => $info->name, '#value' => dirname($info->filename) . ($info->name == variable_get('theme_default', 'bluemarine') ? t('<br /> <em>(site default theme)</em>') : ''));
  183. $options[$info->key] = '';
  184. }
  185. $form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $default_value ? $default_value : '');
  186. $form['#weight'] = $weight;
  187. return $form;
  188. }
  189. }
  190. }
  191. function theme_system_theme_select_form($form) {
  192. foreach (element_children($form) as $key) {
  193. $row = array();
  194. if (is_array($form[$key]['description'])) {
  195. $row[] = form_render($form[$key]['screenshot']);
  196. $row[] = form_render($form[$key]['description']);
  197. $row[] = form_render($form['theme'][$key]);
  198. }
  199. $rows[] = $row;
  200. }
  201. $header = array(t('Screenshot'), t('Name'), t('Selected'));
  202. $output = theme('table', $header, $rows);
  203. return $output;
  204. }
  205. function _system_zonelist() {
  206. $timestamp = time();
  207. $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);
  208. $zones = array();
  209. foreach ($zonelist as $offset) {
  210. $zone = $offset * 3600;
  211. $zones[$zone] = format_date($timestamp, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') . ' O', $zone);
  212. }
  213. return $zones;
  214. }
  215. function system_view_general() {
  216. // General settings:
  217. $form['general'] = array(
  218. '#type' => 'fieldset', '#title' => t('General settings'),
  219. '#collapsible' => TRUE, '#collapsed' => TRUE
  220. );
  221. $form['general']['site_name'] = array(
  222. '#type' => 'textfield', '#title' => t('Name'), '#default_value' => variable_get('site_name', 'drupal'),
  223. '#description' => t('The name of this web site.'), '#required' => TRUE
  224. );
  225. $form['general']['site_mail'] = array(
  226. '#type' => 'textfield', '#title' => t('E-mail address'), '#default_value' => variable_get('site_mail', ini_get('sendmail_from')),
  227. '#description' => t('A valid e-mail address for this website, used by the auto-mailer during registration, new password requests, notifications, etc.')
  228. );
  229. $form['general']['site_slogan'] = array(
  230. '#type' => 'textfield', '#title' => t('Slogan'), '#default_value' => variable_get('site_slogan', ''),
  231. '#description' => t('The slogan of this website. Some themes display a slogan when available.')
  232. );
  233. $form['general']['site_mission'] = array(
  234. '#type' => 'textarea', '#title' => t('Mission'), '#default_value' => variable_get('site_mission', ''),
  235. '#description' => t('Your site\'s mission statement or focus.')
  236. );
  237. $form['general']['site_footer'] = array(
  238. '#type' => 'textarea', '#title' => t('Footer message'), '#default_value' => variable_get('site_footer', ''),
  239. '#description' => t('This text will be displayed at the bottom of each page. Useful for adding a copyright notice to your pages.')
  240. );
  241. $form['general']['anonymous'] = array(
  242. '#type' => 'textfield', '#title' => t('Anonymous user'), '#default_value' => variable_get('anonymous', 'Anonymous'),
  243. '#description' => t('The name used to indicate anonymous users.')
  244. );
  245. $form['general']['site_frontpage'] = array(
  246. '#type' => 'textfield', '#title' => t('Default front page'), '#default_value' => variable_get('site_frontpage', 'node'),
  247. '#description' => t('The home page displays content from this relative URL. Use an existing system path, for example: node/28, forum/1, taxonomy/term/1+2. If unsure, specify "node".')
  248. );
  249. // We check for clean URL support using an image on the client side.
  250. $form['general']['clean_url'] = array(
  251. '#type' => 'radios',
  252. '#title' => t('Clean URLs'),
  253. '#default_value' => variable_get('clean_url', 0),
  254. '#options' => array(t('Disabled'), t('Enabled')),
  255. '#description' => t('This option makes Drupal emit "clean" URLs (i.e. without <code>?q=</code> in the URL.)'),
  256. );
  257. if (!variable_get('clean_url', 0)) {
  258. if (strpos(request_uri(), '?q=') !== FALSE) {
  259. $form['general']['clean_url']['#description'] .= t(' Before enabling clean URLs, you must perform a test to determine if your server is properly configured. If you are able to see this page again after clicking the "Run the clean URL test" link, the test has succeeded and the radio buttons above will be available. If instead you are directed to a "Page not found" error, you will need to change the configuration of your server. The <a href="%handbook">handbook page on Clean URLs</a> has additional troubleshooting information. %run-test', array('%handbook' => 'http://drupal.org/node/15365', '%run-test' => '<a href ="'. base_path() . 'admin/settings">'. t('Run the clean URL test') .'</a>'));
  260. $form['general']['clean_url']['#attributes'] = array('disabled' => 'disabled');
  261. }
  262. else {
  263. $form['general']['clean_url']['#description'] .= t(' You have successfully demonstrated that clean URLs work on your server. You are welcome to enable/disable them as you wish.');
  264. $form['general']['#collapsed'] = FALSE;
  265. }
  266. }
  267. // Error handling:
  268. $form['errors'] = array( '#type' => 'fieldset', '#title' =>t('Error handling'), '#collapsible' => TRUE, '#collapsed' => TRUE );
  269. $form['errors']['site_403'] = array(
  270. '#type' => 'textfield', '#title' => t('Default 403 (access denied) page'), '#default_value' => variable_get('site_403', ''),
  271. '#description' => t('This page is displayed when the requested document is denied to the current user. Use an existing system path, for example: node/28, forum/1, taxonomy/term/1+2. If unsure, specify nothing.')
  272. );
  273. $form['errors']['site_404'] = array(
  274. '#type' => 'textfield', '#title' => t('Default 404 (not found) page'), '#default_value' => variable_get('site_404', ''),
  275. '#description' => t('This page is displayed when no other content matches the requested document. Use an existing system path, for example: node/28, forum/1, taxonomy/term/1+2. If unsure, specify nothing.')
  276. );
  277. $form['errors']['error_level'] = array(
  278. '#type' => 'select', '#title' => t('Error reporting'), '#default_value' => variable_get('error_level', 1),
  279. '#options' => array(t('Write errors to the log'), t('Write errors to the log and to the screen')),
  280. '#description' => t('Where Drupal, PHP and SQL errors are logged. On a production server it is recommended that errors are only written to the error log. On a test server it can be helpful to write logs to the screen.')
  281. );
  282. $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval');
  283. $period['1000000000'] = t('Never');
  284. $form['errors']['watchdog_clear'] = array(
  285. '#type' => 'select', '#title' => t('Discard log entries older than'), '#default_value' => variable_get('watchdog_clear', 604800), '#options' => $period,
  286. '#description' => t('The time log entries should be kept. Older entries will be automatically discarded. Requires crontab.')
  287. );
  288. // Caching:
  289. $form['cache'] = array('#type' => 'fieldset', '#title' => t('Cache settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
  290. $form['cache']['cache'] = array(
  291. '#type' => 'radios', '#title' => t('Page cache'), '#default_value' => variable_get('cache', CACHE_DISABLED),
  292. '#options' => array(CACHE_DISABLED => t('Disabled'), CACHE_ENABLED => t('Enabled')),
  293. '#description' => t("Drupal has a caching mechanism which stores dynamically generated web pages in a database. By caching a web page, Drupal does not have to create the page each time someone wants to view it, instead it takes only one SQL query to display it, reducing response time and the server's load. Only pages requested by \"anonymous\" users are cached. In order to reduce server load and save bandwidth, Drupal stores and sends compressed cached pages.")
  294. );
  295. $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval');
  296. $period[0] = t('none');
  297. $form['cache']['cache_lifetime'] = array(
  298. '#type' => 'select', '#title' => t('Minimum cache lifetime'), '#default_value' => variable_get('cache_lifetime', 0), '#options' => $period,
  299. '#description' => t('Enabling the cache will offer a sufficient performance boost for most low-traffic and medium-traffic sites. On high-traffic sites it can become necessary to enforce a minimum cache lifetime. The minimum cache lifetime is the minimum amount of time that will go by before the cache is emptied and recreated. A larger minimum cache lifetime offers better performance, but users will not see new content for a longer period of time.')
  300. );
  301. // File system:
  302. $form['files'] = array('#type' => 'fieldset', '#title' => t('File system settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
  303. $form['files']['file_directory_path'] = array(
  304. '#type' => 'textfield',
  305. '#title' => t('File system path'),
  306. '#default_value' => file_directory_path(),
  307. '#maxlength' => 255,
  308. '#description' => t('A file system path where the files will be stored. This directory has to exist and be writable by Drupal. If the download method is set to public this directory has to be relative to Drupal installation directory, and be accessible over the web. When download method is set to private this directory should not be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.'),
  309. '#after_build' => array('system_check_directory'),
  310. );
  311. $form['files']['file_directory_temp'] = array(
  312. '#type' => 'textfield',
  313. '#title' => t('Temporary directory'),
  314. '#default_value' => file_directory_temp(),
  315. '#maxlength' => 255,
  316. '#description' => t('Location where uploaded files will be kept during previews. Relative paths will be resolved relative to the Drupal installation directory.'),
  317. '#after_build' => array('system_check_directory'),
  318. );
  319. $form['files']['file_downloads'] = array(
  320. '#type' => 'radios', '#title' => t('Download method'), '#default_value' => variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC),
  321. '#options' => array(FILE_DOWNLOADS_PUBLIC => t('Public - files are available using http directly.'), FILE_DOWNLOADS_PRIVATE => t('Private - files are transferred by Drupal.')),
  322. '#description' => t('If you want any sort of access control on the downloading of files, this needs to be set to <em>private</em>. You can change this at any time, however all download URLs will change and there may be unexpected problems so it is not recommended.')
  323. );
  324. // Image handling:
  325. $toolkits_available = image_get_available_toolkits();
  326. if (count($toolkits_available) > 1) {
  327. $form['image'] = array('#type' => 'fieldset', '#title' => t('Image handling'), '#collapsible' => TRUE, '#collapsed' => true);
  328. $form['image']['image_toolkit'] = array(
  329. '#type' => 'radios', '#title' => t('Select an image processing toolkit'),
  330. '#default_value' => variable_get('image_toolkit', image_get_toolkit()), '#options' => $toolkits_available,
  331. '#validate' => array('image_toolkit_validate' => array('image_toolkit', 'image_toolkit')),
  332. );
  333. $form['image']['settings'] = image_toolkit_invoke('settings');
  334. }
  335. // Feed settings
  336. $form['feed'] = array('#type' => 'fieldset', '#title' => t('RSS feed settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
  337. $form['feed']['feed_default_items'] = array(
  338. '#type' => 'select', '#title' => t('Number of items per feed'), '#default_value' => variable_get('feed_default_items', 10),
  339. '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
  340. '#description' => t('The default number of items to include in a feed.')
  341. );
  342. $form['feed']['feed_item_length'] = array(
  343. '#type' => 'select', '#title' => t('Display of XML feed items'), '#default_value' => variable_get('feed_item_length','teaser'),
  344. '#options' => array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')),
  345. '#description' => t('Global setting for the length of XML feed items that are output by default.')
  346. );
  347. // Date settings:
  348. $zones = _system_zonelist();
  349. // Date settings: possible date formats
  350. $dateshort = array('Y-m-d H:i','m/d/Y - H:i', 'd/m/Y - H:i', 'Y/m/d - H:i',
  351. 'd.m.Y - H:i', 'm/d/Y - g:ia', 'd/m/Y - g:ia', 'Y/m/d - g:ia',
  352. 'M j Y - H:i', 'j M Y - H:i', 'Y M j - H:i',
  353. 'M j Y - g:ia', 'j M Y - g:ia', 'Y M j - g:ia');
  354. $datemedium = array('D, Y-m-d H:i', 'D, m/d/Y - H:i', 'D, d/m/Y - H:i',
  355. 'D, Y/m/d - H:i', 'F j, Y - H:i', 'j F, Y - H:i', 'Y, F j - H:i',
  356. 'D, m/d/Y - g:ia', 'D, d/m/Y - g:ia', 'D, Y/m/d - g:ia',
  357. 'F j, Y - g:ia', 'j F Y - g:ia', 'Y, F j - g:ia', 'j. F Y - G:i');
  358. $datelong = array('l, F j, Y - H:i', 'l, j F, Y - H:i', 'l, Y, F j - H:i',
  359. 'l, F j, Y - g:ia', 'l, j F Y - g:ia', 'l, Y, F j - g:ia', 'l, j. F Y - G:i');
  360. // Date settings: construct choices for user
  361. foreach ($dateshort as $f) {
  362. $dateshortchoices[$f] = format_date(time(), 'custom', $f);
  363. }
  364. foreach ($datemedium as $f) {
  365. $datemediumchoices[$f] = format_date(time(), 'custom', $f);
  366. }
  367. foreach ($datelong as $f) {
  368. $datelongchoices[$f] = format_date(time(), 'custom', $f);
  369. }
  370. $form['dates'] = array('#type' => 'fieldset', '#title' => t('Date settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
  371. $form['dates']['date_default_timezone'] = array(
  372. '#type' => 'select', '#title' => t('Default time zone'), '#default_value' => variable_get('date_default_timezone', 0),
  373. '#options' => $zones, '#description' => t('Select the default site time zone.')
  374. );
  375. $form['dates']['configurable_timezones'] = array(
  376. '#type' => 'radios', '#title' => t('Configurable time zones'), '#default_value' => variable_get('configurable_timezones', 1), '#options' => array(t('Disabled'), t('Enabled')),
  377. '#description' => t('Enable or disable user-configurable time zones. When enabled, users can set their own time zone and dates will be updated accordingly.')
  378. );
  379. $form['dates']['date_format_short'] = array(
  380. '#type' => 'select', '#title' => t('Short date format'), '#default_value' => variable_get('date_format_short', $dateshort[0]),
  381. '#options' => $dateshortchoices, '#description' => t('The short format of date display.')
  382. );
  383. $form['dates']['date_format_medium'] = array(
  384. '#type' => 'select', '#title' => t('Medium date format'), '#default_value' => variable_get('date_format_medium', $datemedium[0]),
  385. '#options' => $datemediumchoices, '#description' => t('The medium sized date display.')
  386. );
  387. $form['dates']['date_format_long'] = array(
  388. '#type' => 'select', '#title' => t('Long date format'), '#default_value' => variable_get('date_format_long', $datelong[0]),
  389. '#options' => $datelongchoices, '#description' => t('Longer date format used for detailed display.')
  390. );
  391. $form['dates']['date_first_day'] = array(
  392. '#type' => 'select', '#title' => t('First day of week'), '#default_value' => variable_get('date_first_day', 0),
  393. '#options' => array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')),
  394. '#description' => t('The first day of the week for calendar views.')
  395. );
  396. // Site off-line/maintenance settings
  397. $form['site_status'] = array(
  398. '#type' => 'fieldset',
  399. '#title' => t('Site maintenance'),
  400. '#collapsible' => TRUE,
  401. '#collapsed' => TRUE);
  402. $form['site_status']['site_offline'] = array(
  403. '#type' => 'radios',
  404. '#title' => t('Site status'),
  405. '#default_value' => variable_get('site_offline', 0),
  406. '#options' => array(t('Online'), t('Off-line')),
  407. '#description' => t('When set to "Online", all visitors will be able to browse your site normally. When set to "Off-line", only users with the "administer site configuration" permission will be able to access your site to perform maintenance; all other visitors will see the site off-line message configured below. Authorized users can log in during "Off-line" mode directly via the <a href="%user-login">user login</a> page.', array('%user-login' => url('user'))),
  408. );
  409. $form['site_status']['site_offline_message'] = array(
  410. '#type' => 'textarea',
  411. '#title' => t('Site off-line message'),
  412. '#default_value' => variable_get('site_offline_message', t('%site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('%site' => variable_get('site_name', t('This Drupal site'))))),
  413. '#description' => t('Message to show visitors when the site is in off-line mode.')
  414. );
  415. // String handling: report status and errors.
  416. $form['strings'] = array('#type' => 'fieldset', '#title' => t('String handling'), '#collapsible' => TRUE, '#collapsed' => TRUE);
  417. $form['strings'] = array_merge($form['strings'], unicode_settings());
  418. // Cron: report status and errors.
  419. $form['cron'] = array('#type' => 'fieldset', '#title' => t('Cron jobs'), '#collapsible' => TRUE, '#collapsed' => TRUE);
  420. $form['cron'] = array_merge($form['cron'], system_cron_settings());
  421. // Check database setup if necessary
  422. if (function_exists('db_check_setup') && empty($_POST)) {
  423. db_check_setup();
  424. }
  425. return $form;
  426. }
  427. /**
  428. * Checks the existence of the directory specified in $form_element. This
  429. * function is called from the system_view_general form to check both the
  430. * file_directory_path and file_directory_temp directories. If validation
  431. * fails, the form element is flagged with an error from within the
  432. * file_check_directory function.
  433. *
  434. * @param $form_element
  435. * The form element containing the name of the directory to check.
  436. */
  437. function system_check_directory($form_element) {
  438. file_check_directory($form_element['#value'], FILE_CREATE_DIRECTORY, $form_element['#parents'][0]);
  439. return $form_element;
  440. }
  441. /**
  442. * Return the cron status and errors for admin/settings.
  443. */
  444. function system_cron_settings() {
  445. $cron_last = variable_get('cron_last', NULL);
  446. if (is_numeric($cron_last)) {
  447. $status = t('Cron is running. The last cron job ran %time ago.', array('%time' => format_interval(time() - $cron_last)));
  448. }
  449. else {
  450. $status = t('Cron has not run. It appears cron jobs have not been setup on your system. Please check the help pages for <a href="%url">configuring cron jobs</a>.', array('%url' => 'http://drupal.org/cron'));
  451. }
  452. $form['settings'] = array('#type' => 'item', '#value' => $status);
  453. return $form;
  454. }
  455. /**
  456. * Retrieves the current status of an array of files in the system table.
  457. */
  458. function system_get_files_database(&$files, $type) {
  459. // Extract current files from database.
  460. $result = db_query("SELECT filename, name, type, status, throttle, schema_version FROM {system} WHERE type = '%s'", $type);
  461. while ($file = db_fetch_object($result)) {
  462. if (isset($files[$file->name]) && is_object($files[$file->name])) {
  463. $file->old_filename = $file->filename;
  464. foreach ($file as $key => $value) {
  465. if (!isset($files[$file->name]) || !isset($files[$file->name]->$key)) {
  466. $files[$file->name]->$key = $value;
  467. }
  468. }
  469. }
  470. }
  471. }
  472. /**
  473. * Collect data about all currently available themes
  474. */
  475. function system_theme_data() {
  476. // Find themes
  477. $themes = system_listing('\.theme$', 'themes');
  478. // Find theme engines
  479. $engines = system_listing('\.engine$', 'themes/engines');
  480. // can't iterate over array itself as it uses a copy of the array items
  481. foreach (array_keys($themes) as $key) {
  482. drupal_get_filename('theme', $themes[$key]->name, $themes[$key]->filename);
  483. drupal_load('theme', $themes[$key]->name);
  484. $themes[$key]->owner = $themes[$key]->filename;
  485. $themes[$key]->prefix = $key;
  486. }
  487. // Remove all theme engines from the system table
  488. db_query("DELETE FROM {system} WHERE type = 'theme_engine'");
  489. foreach ($engines as $engine) {
  490. // Insert theme engine into system table
  491. drupal_get_filename('theme_engine', $engine->name, $engine->filename);
  492. drupal_load('theme_engine', $engine->name);
  493. db_query("INSERT INTO {system} (name, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', %d, %d, %d)", $engine->name, 'theme_engine', $engine->filename, 1, 0, 0);
  494. // Add templates to the site listing
  495. foreach (call_user_func($engine->name . '_templates') as $template) {
  496. // Do not double-insert templates with theme files in their directory,
  497. // but do register their engine data.
  498. if (array_key_exists($template->name, $themes)) {
  499. $themes[$template->name]->template = TRUE;
  500. $themes[$template->name]->owner = $engine->filename;
  501. $themes[$template->name]->prefix = $engine->name;
  502. }
  503. else {
  504. $template->template = TRUE;
  505. $template->name = basename(dirname($template->filename));
  506. $template->owner = $engine->filename;
  507. $template->prefix = $engine->name;
  508. $themes[$template->name] = $template;
  509. }
  510. }
  511. }
  512. // Find styles in each theme's directory.
  513. foreach ($themes as $theme) {
  514. foreach (file_scan_directory(dirname($theme->filename), 'style.css$') as $style) {
  515. $style->style = TRUE;
  516. $style->template = isset($theme->template) ? $theme->template : FALSE;
  517. $style->name = basename(dirname($style->filename));
  518. $style->owner = $theme->filename;
  519. $style->prefix = $theme->template ? $theme->prefix : $theme->name;
  520. // do not double-insert styles with theme files in their directory
  521. if (array_key_exists($style->name, $themes)) {
  522. continue;
  523. }
  524. $themes[$style->name] = $style;
  525. }
  526. }
  527. // Extract current files from database.
  528. system_get_files_database($themes, 'theme');
  529. db_query("DELETE FROM {system} WHERE type = 'theme'");
  530. foreach ($themes as $theme) {
  531. db_query("INSERT INTO {system} (name, description, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $theme->name, $theme->owner, 'theme', $theme->filename, $theme->status, 0, 0);
  532. }
  533. return $themes;
  534. }
  535. /**
  536. * Get a list of available regions from a specified theme.
  537. *
  538. * @param $theme_key
  539. * The name of a theme.
  540. * @return
  541. * An array of regions in the form $region['name'] = 'description'.
  542. */
  543. function system_region_list($theme_key) {
  544. static $list = array();
  545. if (!array_key_exists($theme_key, $list)) {
  546. $theme = db_fetch_object(db_query("SELECT * FROM {system} WHERE type = 'theme' AND name = '%s'", $theme_key));
  547. // Stylesheets can't have regions; use its theme.
  548. if (strpos($theme->filename, '.css')) {
  549. return system_region_list(basename(dirname($theme->description)));
  550. }
  551. // If this is a custom theme, load it in before moving on.
  552. if (file_exists($file = dirname($theme->filename) .'/' . $theme_key . '.theme')) {
  553. include_once "./$file";
  554. }
  555. $regions = array();
  556. // This theme has defined its own regions.
  557. if (function_exists($theme_key . '_regions')) {
  558. $regions = call_user_func($theme_key . '_regions');
  559. }
  560. // File is an engine; include its regions.
  561. else if (strpos($theme->description, '.engine')) {
  562. include_once './' . $theme->description;
  563. $theme_engine = basename($theme->description, '.engine');
  564. $regions = function_exists($theme_engine . '_regions') ? call_user_func($theme_engine . '_regions') : array();
  565. }
  566. $list[$theme_key] = $regions;
  567. }
  568. return $list[$theme_key];
  569. }
  570. /**
  571. * Get the name of the default region for a given theme.
  572. *
  573. * @param $theme
  574. * The name of a theme.
  575. * @return
  576. * A string that is the region name.
  577. */
  578. function system_default_region($theme) {
  579. $regions = array_keys(system_region_list($theme));
  580. return $regions[0];
  581. }
  582. /**
  583. * Returns an array of files objects of the given type from both the
  584. * site-wide directory (i.e. modules/) and site-specific directory
  585. * (i.e. sites/somesite/modules/). The returned array will be keyed
  586. * using the key specified (name, basename, filename). Using name or
  587. * basename will cause site-specific files to shadow files in the
  588. * default directories. That is, if a file with the same name appears
  589. * in both location, only the site-specific version will be included.
  590. *
  591. * @param $mask
  592. * The regular expression of the files to find.
  593. * @param $directory
  594. * The subdirectory name in which the files are found. For example,
  595. * 'modules' will search in both modules/ and
  596. * sites/somesite/modules/.
  597. * @param $key
  598. * The key to be passed to file_scan_directory().
  599. * @param $min_depth
  600. * Minimum depth of directories to return files from.
  601. *
  602. * @return
  603. * An array of file objects of the specified type.
  604. */
  605. function system_listing($mask, $directory, $key = 'name', $min_depth = 1) {
  606. $config = conf_path();
  607. $searchdir = array($directory);
  608. $files = array();
  609. if (file_exists("$config/$directory")) {
  610. $searchdir[] = "$config/$directory";
  611. }
  612. // Get current list of items
  613. foreach ($searchdir as $dir) {
  614. $files = array_merge($files, file_scan_directory($dir, $mask, array('.', '..', 'CVS'), 0, TRUE, $key, $min_depth));
  615. }
  616. return $files;
  617. }
  618. /**
  619. * Assign an initial, default set of blocks for a theme.
  620. *
  621. * This function is called the first time a new theme is enabled. The new theme
  622. * gets a copy of the default theme's blocks, with the difference that if a
  623. * particular region isn't available in the new theme, the block is assigned
  624. * to the new theme's default region.
  625. *
  626. * @param $theme
  627. * The name of a theme.
  628. */
  629. function system_initialize_theme_blocks($theme) {
  630. // Initialize theme's blocks if none already registered.
  631. if (!(db_num_rows(db_query("SELECT module FROM {blocks} WHERE theme = '%s'", $theme)))) {
  632. $default_theme = variable_get('theme_default', 'bluemarine');
  633. $regions = system_region_list($theme);
  634. $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
  635. while($block = db_fetch_array($result)) {
  636. // If the region isn't supported by the theme, assign the block to the theme's default region.
  637. if (!array_key_exists($block['region'], $regions)) {
  638. $block['region'] = system_default_region($theme);
  639. }
  640. db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d)",
  641. $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']);
  642. }
  643. }
  644. }
  645. // Add the submit / reset buttons and run drupal_get_form()
  646. function system_settings_form($form_id, $form) {
  647. $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
  648. $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
  649. if (!empty($_POST) && form_get_errors()) {
  650. drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
  651. }
  652. return drupal_get_form($form_id, $form, 'system_settings_form');
  653. }
  654. function system_theme_settings_submit($form_id, $values) {
  655. $op = isset($_POST['op']) ? $_POST['op'] : '';
  656. $key = $values['var'];
  657. // Exclude unnecessary elements.
  658. unset($values['var'], $values['submit'], $values['reset'], $values['form_id'], $values['op'], $values['form_token']);
  659. if ($op == t('Reset to defaults')) {
  660. variable_del($key);
  661. drupal_set_message(t('The configuration options have been reset to their default values.'));
  662. }
  663. else {
  664. variable_set($key, $values);
  665. drupal_set_message(t('The configuration options have been saved.'));
  666. }
  667. }
  668. /**
  669. * Execute the system_settings_form.
  670. *
  671. * If you want node type configure style handling of your checkboxes,
  672. * add an array_filter value to your form.
  673. *
  674. */
  675. function system_settings_form_submit($form_id, $values) {
  676. $op = isset($_POST['op']) ? $_POST['op'] : '';
  677. // Exclude unnecessary elements.
  678. unset($values['submit'], $values['reset'], $values['form_id'], $values['form_token']);
  679. foreach ($values as $key => $value) {
  680. if ($op == t('Reset to defaults')) {
  681. variable_del($key);
  682. }
  683. else {
  684. if (is_array($value) && isset($values['array_filter'])) {
  685. $value = array_keys(array_filter($value));
  686. }
  687. variable_set($key, $value);
  688. }
  689. }
  690. if ($op == t('Reset to defaults')) {
  691. drupal_set_message(t('The configuration options have been reset to their default values.'));
  692. }
  693. else {
  694. drupal_set_message(t('The configuration options have been saved.'));
  695. }
  696. menu_rebuild();
  697. }
  698. /**
  699. * Menu callback; displays a listing of all themes.
  700. */
  701. function system_themes() {
  702. $themes = system_theme_data();
  703. ksort($themes);
  704. foreach ($themes as $info) {
  705. $info->screenshot = dirname($info->filename) . '/screenshot.png';
  706. $screenshot = file_exists($info->screenshot) ? theme('image', $info->screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), false) : t('no screenshot');
  707. $form[$info->name]['screenshot'] = array('#type' => 'markup', '#value' => $screenshot);
  708. $form[$info->name]['description'] = array('#type' => 'item', '#title' => $info->name, '#value' => dirname($info->filename));
  709. $options[$info->name] = '';
  710. if ($info->status) {
  711. $status[] = $info->name;
  712. }
  713. if ($info->status && (function_exists($info->prefix . '_settings') || function_exists($info->prefix . '_features'))) {
  714. $form[$info->name]['operations'] = array('#type' => 'markup', '#value' => l(t('configure'), 'admin/themes/settings/' . $info->name) );
  715. }
  716. else {
  717. // Dummy element for form_render. Cleaner than adding a check in the theme function.
  718. $form[$info->name]['operations'] = array();
  719. }
  720. }
  721. $form['status'] = array('#type' => 'checkboxes', '#options' => $options, '#default_value' => $status);
  722. $form['theme_default'] = array('#type' => 'radios', '#options' => $options, '#default_value' => variable_get('theme_default', 'bluemarine'));
  723. $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
  724. $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
  725. return drupal_get_form('system_themes', $form);
  726. }
  727. function theme_system_themes($form) {
  728. foreach (element_children($form) as $key) {
  729. $row = array();
  730. if (is_array($form[$key]['description'])) {
  731. $row[] = form_render($form[$key]['screenshot']);
  732. $row[] = form_render($form[$key]['description']);
  733. $row[] = array('data' => form_render($form['status'][$key]), 'align' => 'center');
  734. if ($form['theme_default']) {
  735. $row[] = array('data' => form_render($form['theme_default'][$key]), 'align' => 'center');
  736. $row[] = array('data' => form_render($form[$key]['operations']), 'align' => 'center');
  737. }
  738. }
  739. $rows[] = $row;
  740. }
  741. $header = array(t('Screenshot'), t('Name'), t('Enabled'), t('Default'), t('Operations'));
  742. $output = theme('table', $header, $rows);
  743. $output .= form_render($form);
  744. return $output;
  745. }
  746. function system_themes_submit($form_id, $values) {
  747. db_query("UPDATE {system} SET status = 0 WHERE type = 'theme'");
  748. if ($_POST['op'] == t('Save configuration')) {
  749. if (is_array($values['status'])) {
  750. foreach ($values['status'] as $key => $choice) {
  751. // Always enable the default theme, despite its status checkbox being checked:
  752. if ($choice || $values['theme_default'] == $key) {
  753. // If theme status is being set to 1 from 0, initialize block data for this theme if necessary.
  754. if (db_num_rows(db_query("SELECT status FROM {system} WHERE type = 'theme' AND name = '%s' AND status = 0", $key))) {
  755. system_initialize_theme_blocks($key);
  756. }
  757. db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' and name = '%s'", $key);
  758. }
  759. }
  760. }
  761. variable_set('theme_default', $values['theme_default']);
  762. }
  763. else {
  764. variable_del('theme_default');
  765. db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' AND name = 'bluemarine'");
  766. }
  767. menu_rebuild();
  768. drupal_set_message(t('The configuration options have been saved.'));
  769. return 'admin/themes';
  770. }
  771. /**
  772. * Menu callback; displays a listing of all modules.
  773. */
  774. function system_modules() {
  775. // Get current list of modules
  776. $files = system_listing('\.module$', 'modules', 'name', 0);
  777. // Extract current files from database.
  778. system_get_files_database($files, 'module');
  779. ksort($files);
  780. foreach ($files as $filename => $file) {
  781. drupal_get_filename('module', $file->name, $file->filename);
  782. drupal_load('module', $file->name);
  783. $file->description = module_invoke($file->name, 'help', 'admin/modules#description');
  784. $form['name'][$file->name] = array('#value' => $file->name);
  785. $form['description'][$file->name] = array('#value' => $file->description);
  786. $options[$file->name] = '';
  787. if ($file->status) {
  788. $status[] = $file->name;
  789. }
  790. if ($file->throttle) {
  791. $throttle[] = $file->name;
  792. }
  793. // log the critical hooks implemented by this module
  794. $bootstrap = 0;
  795. foreach (bootstrap_hooks() as $hook) {
  796. if (module_hook($file->name, $hook)) {
  797. $bootstrap = 1;
  798. break;
  799. }
  800. }
  801. // Update the contents of the system table:
  802. if (isset($file->status) || (isset($file->old_filename) && $file->old_filename != $file->filename)) {
  803. db_query("UPDATE {system} SET description = '%s', name = '%s', bootstrap = %d, filename = '%s' WHERE filename = '%s'", $file->description, $file->name, $bootstrap, $file->filename, $file->old_filename);
  804. }
  805. else {
  806. // This is a new module.
  807. db_query("INSERT INTO {system} (name, description, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $file->name, $file->description, 'module', $file->filename, $file->status, $file->throttle, $bootstrap);
  808. }
  809. }
  810. // Handle status checkboxes, including overriding the generated
  811. // checkboxes for required modules.
  812. $form['status'] = array('#type' => 'checkboxes', '#default_value' => $status, '#options' => $options);
  813. $required = array('block', 'filter', 'node', 'system', 'user', 'watchdog');
  814. foreach ($required as $require) {
  815. $form['status'][$require] = array('#type' => 'hidden', '#value' => 1, '#suffix' => t('required'));
  816. }
  817. /**
  818. * Handle throttle checkboxes, including overriding the generated checkboxes for required modules.
  819. */
  820. if (module_exist('throttle')) {
  821. $form['throttle'] = array('#type' => 'checkboxes', '#default_value' => $throttle, '#options' => $options);
  822. $throttle_required = array_merge($required, array('throttle'));
  823. foreach ($throttle_required as $require) {
  824. $form['throttle'][$require] = array('#type' => 'hidden', '#value' => 0, '#suffix' => t('required'));
  825. }
  826. }
  827. $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
  828. return drupal_get_form('system_modules', $form);
  829. }
  830. function theme_system_modules($form) {
  831. foreach (element_children($form['name']) as $key) {
  832. $row = array();
  833. $row[] = form_render($form['name'][$key]);
  834. $row[] = form_render($form['description'][$key]);
  835. $row[] = array('data' => form_render($form['status'][$key]), 'align' => 'center');
  836. if (module_exist('throttle')) {
  837. $row[] = array('data' => form_render($form['throttle'][$key]), 'align' => 'center');
  838. }
  839. $rows[] = $row;
  840. }
  841. $header = array(t('Name'), t('Description'), t('Enabled'));
  842. if (module_exist('throttle')) {
  843. $header[] = t('Throttle');
  844. }
  845. $output = theme('table', $header, $rows);
  846. $output .= form_render($form);
  847. return $output;
  848. }
  849. function system_modules_submit($form_id, $edit) {
  850. db_query("UPDATE {system} SET status = 0, throttle = 0 WHERE type = 'module'");
  851. $new_modules = array();
  852. foreach ($edit['status'] as $key => $choice) {
  853. if ($choice) {
  854. db_query("UPDATE {system} SET status = 1 WHERE type = 'module' AND name = '%s'", $key);
  855. if (!module_exist($key)) {
  856. $new_modules[] = $key;
  857. }
  858. }
  859. }
  860. if (is_array($edit['throttle'])) {
  861. foreach ($edit['throttle'] as $key => $choice) {
  862. if ($choice) {
  863. db_query("UPDATE {system} SET throttle = 1 WHERE type = 'module' and name = '%s'", $key);
  864. }
  865. }
  866. }
  867. module_list(TRUE, FALSE);
  868. include_once './includes/install.inc';
  869. foreach ($new_modules as $module) {
  870. // Set the installed schema version for newly-enabled modules
  871. $versions = drupal_get_schema_versions($module);
  872. if (drupal_get_installed_schema_version($module) == SCHEMA_UNINSTALLED) {
  873. drupal_set_installed_schema_version($module, $versions ? max($versions) : SCHEMA_INSTALLED);
  874. module_invoke($module, 'install');
  875. }
  876. }
  877. menu_rebuild();
  878. drupal_set_message(t('The configuration options have been saved.'));
  879. return 'admin/modules';
  880. }
  881. /**
  882. * Menu callback; displays a module's settings page.
  883. */
  884. function system_site_settings($module = NULL) {
  885. if ($module) {
  886. $form = module_invoke($module, 'settings');
  887. }
  888. else {
  889. $form = system_view_general();
  890. $module = 'system';
  891. }
  892. return system_settings_form($module . '_settings_form', $form);
  893. }
  894. /**
  895. * Menu callback; display theme configuration for entire site and individual themes.
  896. */
  897. function system_theme_settings($key = '') {
  898. $directory_path = file_directory_path();
  899. file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
  900. // Default settings are defined in theme_get_settings() in includes/theme.inc
  901. if ($key) {
  902. $settings = theme_get_settings($key);
  903. $var = str_replace('/', '_', 'theme_'. $key .'_settings');
  904. $themes = system_theme_data();
  905. $features = function_exists($themes[$key]->prefix . '_features') ? call_user_func($themes[$key]->prefix . '_features') : array();
  906. }
  907. else {
  908. $settings = theme_get_settings('');
  909. $var = 'theme_settings';
  910. }
  911. $form['var'] = array('#type' => 'hidden', '#value' => $var);
  912. // Check for a new uploaded logo, and use that instead.
  913. if ($file = file_check_upload('logo_upload')) {
  914. if ($info = image_get_info($file->filepath)) {
  915. $parts = pathinfo($file->filename);
  916. $filename = ($key) ? str_replace('/', '_', $key) . '_logo.' . $parts['extension'] : 'logo.' . $parts['extension'];
  917. if ($file = file_save_upload('logo_upload', $filename, 1)) {
  918. $_POST['edit']['default_logo'] = 0;
  919. $_POST['edit']['logo_path'] = $file->filepath;
  920. $_POST['edit']['toggle_logo'] = 1;
  921. }
  922. }
  923. else {
  924. form_set_error('file_upload', t('Only JPEG, PNG and GIF images are allowed to be used as logos.'));
  925. }
  926. }
  927. // Check for a new uploaded favicon, and use that instead.
  928. if ($file = file_check_upload('favicon_upload')) {
  929. $parts = pathinfo($file->filename);
  930. $filename = ($key) ? str_replace('/', '_', $key) . '_favicon.' . $parts['extension'] : 'favicon.' . $parts['extension'];
  931. if ($file = file_save_upload('favicon_upload', $filename, 1)) {
  932. $_POST['edit']['default_favicon'] = 0;
  933. $_POST['edit']['favicon_path'] = $file->filepath;
  934. $_POST['edit']['toggle_favicon'] = 1;
  935. }
  936. }
  937. // Toggle settings
  938. $toggles = array(
  939. 'toggle_logo' => t('Logo'),
  940. 'toggle_name' => t('Site name'),
  941. 'toggle_slogan' => t('Site slogan'),
  942. 'toggle_mission' => t('Mission statement'),
  943. 'toggle_node_user_picture' => t('User pictures in posts'),
  944. 'toggle_comment_user_picture' => t('User pictures in comments'),
  945. 'toggle_search' => t('Search box'),
  946. 'toggle_favicon' => t('Shortcut icon')
  947. );
  948. // Some features are not always available
  949. $disabled = array();
  950. if (!variable_get('user_pictures', 0)) {
  951. $disabled['toggle_node_user_picture'] = true;
  952. $disabled['toggle_comment_user_picture'] = true;
  953. }
  954. if (!module_exist('search')) {
  955. $disabled['toggle_search'] = true;
  956. }
  957. $form['theme_settings'] = array(
  958. '#type' => 'fieldset',
  959. '#title' => t('Toggle display'),
  960. '#description' => t('Enable or disable the display of certain page elements.'),
  961. );
  962. foreach ($toggles as $name => $title) {
  963. if ((!$key) || in_array($name, $features)) {
  964. // disable search box if search.module is disabled
  965. $form['theme_settings'][$name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $settings[$name]);
  966. if (isset($disabled[$name])) {
  967. $form['theme_settings'][$name]['#attributes'] = array('disabled' => 'disabled');
  968. }
  969. }
  970. }
  971. // System wide only settings.
  972. if (!$key) {
  973. // Create neat 2-column layout for the toggles
  974. $form['theme_settings'] += array(
  975. '#prefix' => '<div class="theme-settings-left">',
  976. '#suffix' => '</div>',
  977. );
  978. // Toggle node display.
  979. $node_types = module_invoke('node', 'get_types');
  980. if ($node_types) {
  981. $form['node_info'] = array(
  982. '#type' => 'fieldset',
  983. '#title' => t('Display post information on'),
  984. '#description' => t('Enable or disable the <em>submitted by Username on date</em> text when displaying posts of the following type.'),
  985. '#prefix' => '<div class="theme-settings-right">',
  986. '#suffix' => '</div>',
  987. );
  988. foreach ($node_types as $type => $name) {
  989. $form['node_info']["toggle_node_info_$type"] = array('#type' => 'checkbox', '#title' => $name, '#default_value' => $settings["toggle_node_info_$type"]);
  990. }
  991. }
  992. }
  993. // Logo settings
  994. if ((!$key) || in_array('toggle_logo', $features)) {
  995. $form['logo'] = array(
  996. '#type' => 'fieldset',
  997. '#title' => t('Logo image settings'),
  998. '#description' => t('If toggled on, the following logo will be displayed.'),
  999. '#attributes' => array('class' => 'theme-settings-bottom'),
  1000. );
  1001. $form['logo']["default_logo"] = array(
  1002. '#type' => 'checkbox',
  1003. '#title' => t('Use the default logo'),
  1004. '#default_value' => $settings['default_logo'],
  1005. '#tree' => FALSE,
  1006. '#description' => t('Check here if you want the theme to use the logo supplied with it.')
  1007. );
  1008. $form['logo']['logo_path'] = array(
  1009. '#type' => 'textfield',
  1010. '#title' => t('Path to custom logo'),
  1011. '#default_value' => $settings['logo_path'],
  1012. '#description' => t('The path to the file you would like to use as your logo file instead of the default logo.'));
  1013. $form['logo']['logo_upload'] = array(
  1014. '#type' => 'file',
  1015. '#title' => t('Upload logo image'),
  1016. '#maxlength' => 40,
  1017. '#description' => t("If you don't have direct file access to the server, use this field to upload your logo.")
  1018. );
  1019. }
  1020. // Icon settings
  1021. if ((!$key) || in_array('toggle_favicon', $features)) {
  1022. $form['favicon'] = array('#type' => 'fieldset', '#title' => t('Shortcut icon settings'));
  1023. $form['favicon']['text'] = array('#value' => t('Your shortcut icon or \'favicon\' is displayed in the address bar and bookmarks of most browsers.'));
  1024. $form['favicon']['default_favicon'] = array(
  1025. '#type' => 'checkbox',
  1026. '#title' => t('Use the default shortcut icon.'),
  1027. '#default_value' => $settings['default_favicon'],
  1028. '#description' => t('Check here if you want the theme to use the default shortcut icon.')
  1029. );
  1030. $form['favicon']['favicon_path'] = array(
  1031. '#type' => 'textfield',
  1032. '#title' => t('Path to custom icon'),
  1033. '#default_value' => $settings['favicon_path'],
  1034. '#description' => t('The path to the image file you would like to use as your custom shortcut icon.')
  1035. );
  1036. $form['favicon']['favicon_upload'] = array(
  1037. '#type' => 'file',
  1038. '#title' => t('Upload icon image'),
  1039. '#description' => t("If you don't have direct file access to the server, use this field to upload your shortcut icon.")
  1040. );
  1041. }
  1042. if ($key) {
  1043. // Template-specific settings
  1044. $function = $themes[$key]->prefix .'_settings';
  1045. if (function_exists($function)) {
  1046. if ($themes[$key]->template) {
  1047. // file is a template or a style of a template
  1048. $form['specific'] = array('#type' => 'fieldset', '#title' => t('Engine-specific settings'), '#description' => t('These settings only exist for all the templates and styles based on the %engine theme engine.', array('%engine' => $themes[$key]->prefix)));
  1049. }
  1050. else {
  1051. // file is a theme or a style of a theme
  1052. $form['specific'] = array('#type' => 'fieldset', '#title' => t('Theme-specific settings'), '#description' => t('These settings only exist for the %theme theme and all the styles based on it.', array('%theme' => $themes[$key]->prefix)));
  1053. }
  1054. $group = $function();
  1055. $form['specific'] = array_merge($form['specific'], (is_array($group) ? $group : array()));
  1056. }
  1057. }
  1058. $form['#attributes'] = array('enctype' => 'multipart/form-data');
  1059. return system_settings_form('system_theme_settings', $form);
  1060. }
  1061. /**
  1062. * Output a confirmation form
  1063. *
  1064. * This function outputs a complete form for confirming an action. A link is
  1065. * offered to go back to the item that is being changed in case the user changes
  1066. * his/her mind.
  1067. *
  1068. * If the submit handler for this form is invoked, the user successfully
  1069. * confirmed the action. You should never directly inspect $_POST to see if an
  1070. * action was confirmed.
  1071. *
  1072. * @param $form_id
  1073. * The unique form identifier. Used by the form API to construct the theme.
  1074. * @param $form
  1075. * Additional elements to inject into the form, for example hidden elements.
  1076. * @param $question
  1077. * The question to ask the user (e.g. "Are you sure you want to delete the
  1078. * block <em>foo</em>?").
  1079. * @param $path
  1080. * The page to go to if the user denies the action.
  1081. * @param $description
  1082. * Additional text to display (defaults to "This action cannot be undone.").
  1083. * @param $yes
  1084. * A caption for the button which confirms the action (e.g. "Delete",
  1085. * "Replace", ...).
  1086. * @param $no
  1087. * A caption for the link which denies the action (e.g. "Cancel").
  1088. * @param $name
  1089. * The internal name used to refer to the confirmation item.
  1090. * @return
  1091. * A themed HTML string representing the form.
  1092. */
  1093. function confirm_form($form_id, $form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm') {
  1094. $description = ($description) ? $description : t('This action cannot be undone.');
  1095. drupal_set_title($question);
  1096. $form['#attributes'] = array('class' => 'confirmation');
  1097. $form['description'] = array('#value' => $description);
  1098. $form[$name] = array('#type' => 'hidden', '#value' => 1);
  1099. $form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
  1100. $form['actions']['submit'] = array('#type' => 'submit', '#value' => $yes ? $yes : t('Confirm'));
  1101. $form['actions']['cancel'] = array('#value' => l($no ? $no : t('Cancel'), $path));
  1102. return drupal_get_form($form_id, $form, 'confirm_form');
  1103. }
Login or register to post comments