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. 8.3.x core/modules/system/system.module
  5. 4.6.x modules/system.module
  6. 4.7.x modules/system.module
  7. 5.x modules/system/system.module
  8. 6.x modules/system/system.module
  9. 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. define('VERSION', '5.24-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 system 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. Cron can, if necessary, also be run manually.') .'</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 .= '<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>';
  18. return $output;
  19. case 'admin':
  20. return '<p>'. t('Welcome to the administration section. Here you may control how your site functions.') .'</p>';
  21. case 'admin/by-module':
  22. return '<p>'. t('This page shows you all available administration tasks for each module.') .'</p>';
  23. case 'admin/build/themes':
  24. return '<p>'. t('Select which themes are available to your users and specify the default theme. To configure site-wide display settings, click the "configure" task above. Alternately, to override these settings in a specific theme, click the "configure" link for the corresponding theme. Note that different themes may have different regions available for rendering content like blocks. If you want consistency in what your users see, you may wish to enable only one theme.') .'</p>';
  25. case 'admin/build/themes/settings':
  26. 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>';
  27. case 'admin/build/themes/settings/'. arg(4):
  28. $reference = explode('.', arg(4), 2);
  29. $theme = array_pop($reference);
  30. 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>';
  31. case 'admin/build/modules':
  32. 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>
  33. <p>It is important that <a href="@update-php">update.php</a> is run every time a module is updated to a newer version.</p><p>You can find all administration tasks belonging to a particular module on the <a href="@by-module">administration by module page</a>.</p>', array('@permissions' => url('admin/user/access'), '@throttle' => url('admin/settings/throttle'), '@update-php' => $base_url .'/update.php', '@by-module' => url('admin/by-module')));
  34. case 'admin/build/modules/uninstall':
  35. 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>';
  36. case 'admin/logs/status':
  37. return '<p>'. t("Here you can find a short overview of your Drupal site's parameters as well as any problems detected with your installation. It is useful to copy/paste this information when you need support.") .'</p>';
  38. }
  39. }
  40. /**
  41. * Implementation of hook_perm().
  42. */
  43. function system_perm() {
  44. return array('administer site configuration', 'access administration pages', 'select different theme');
  45. }
  46. /**
  47. * Implementation of hook_elements().
  48. */
  49. function system_elements() {
  50. // Top level form
  51. $type['form'] = array('#method' => 'post', '#action' => request_uri());
  52. // Inputs
  53. $type['checkbox'] = array('#input' => TRUE, '#return_value' => 1);
  54. $type['submit'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => TRUE);
  55. $type['button'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => FALSE);
  56. $type['textfield'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE);
  57. $type['password'] = array('#input' => TRUE, '#size' => 60);
  58. $type['password_confirm'] = array('#input' => TRUE, '#process' => array('expand_password_confirm' => array()));
  59. $type['textarea'] = array('#input' => TRUE, '#cols' => 60, '#rows' => 5);
  60. $type['radios'] = array('#input' => TRUE, '#process' => array('expand_radios' => array()));
  61. $type['radio'] = array('#input' => TRUE);
  62. $type['checkboxes'] = array('#input' => TRUE, '#process' => array('expand_checkboxes' => array()), '#tree' => TRUE);
  63. $type['select'] = array('#input' => TRUE);
  64. $type['weight'] = array('#input' => TRUE, '#delta' => 10, '#default_value' => 0, '#process' => array('process_weight' => array()));
  65. $type['date'] = array('#input' => TRUE, '#process' => array('expand_date' => array()), '#validate' => array('date_validate' => array()));
  66. $type['file'] = array('#input' => TRUE, '#size' => 60);
  67. // Form structure
  68. $type['item'] = array();
  69. $type['hidden'] = array('#input' => TRUE);
  70. $type['value'] = array('#input' => TRUE);
  71. $type['markup'] = array('#prefix' => '', '#suffix' => '');
  72. $type['fieldset'] = array('#collapsible' => FALSE, '#collapsed' => FALSE);
  73. $type['token'] = array('#input' => TRUE);
  74. return $type;
  75. }
  76. /**
  77. * Implementation of hook_menu().
  78. */
  79. function system_menu($may_cache) {
  80. $items = array();
  81. if ($may_cache) {
  82. $items[] = array('path' => 'system/files', 'title' => t('File download'),
  83. 'callback' => 'file_download',
  84. 'access' => TRUE,
  85. 'type' => MENU_CALLBACK);
  86. $access = user_access('administer site configuration');
  87. $items[] = array('path' => 'admin', 'title' => t('Administer'),
  88. 'access' => user_access('access administration pages'),
  89. 'callback' => 'system_main_admin_page',
  90. 'weight' => 9);
  91. $items[] = array('path' => 'admin/compact', 'title' => t('Compact mode'),
  92. 'access' => user_access('access administration pages'),
  93. 'callback' => 'system_admin_compact_page',
  94. 'type' => MENU_CALLBACK);
  95. $items[] = array('path' => 'admin/by-task', 'title' => t('By task'),
  96. 'callback' => 'system_main_admin_page',
  97. 'type' => MENU_DEFAULT_LOCAL_TASK);
  98. $items[] = array('path' => 'admin/by-module', 'title' => t('By module'),
  99. 'callback' => 'system_admin_by_module',
  100. 'type' => MENU_LOCAL_TASK,
  101. 'weight' => 2);
  102. // menu items that are basically just menu blocks
  103. $items[] = array(
  104. 'path' => 'admin/settings',
  105. 'title' => t('Site configuration'),
  106. 'description' => t('Adjust basic site configuration options.'),
  107. 'position' => 'right',
  108. 'weight' => -5,
  109. 'callback' => 'system_settings_overview',
  110. 'access' => $access);
  111. $items[] = array('path' => 'admin/build',
  112. 'title' => t('Site building'),
  113. 'description' => t('Control how your site looks and feels.'),
  114. 'position' => 'right',
  115. 'weight' => -10,
  116. 'callback' => 'system_admin_menu_block_page',
  117. 'access' => $access);
  118. $items[] = array(
  119. 'path' => 'admin/settings/admin',
  120. 'title' => t('Administration theme'),
  121. 'description' => t('Settings for how your administrative pages should look.'),
  122. 'position' => 'left',
  123. 'callback' => 'drupal_get_form',
  124. 'callback arguments' => array('system_admin_theme_settings'),
  125. 'block callback' => 'system_admin_theme_settings',
  126. 'access' => $access);
  127. // Themes:
  128. $items[] = array(
  129. 'path' => 'admin/build/themes',
  130. 'title' => t('Themes'),
  131. 'description' => t('Change which theme your site uses or allows users to set.'),
  132. 'callback' => 'drupal_get_form',
  133. 'callback arguments' => array('system_themes'),
  134. 'access' => $access);
  135. $items[] = array(
  136. 'path' => 'admin/build/themes/select',
  137. 'title' => t('List'),
  138. 'description' => t('Select the default theme.'),
  139. 'callback' => 'drupal_get_form',
  140. 'callback arguments' => array('system_themes'),
  141. 'access' => $access,
  142. 'type' => MENU_DEFAULT_LOCAL_TASK,
  143. 'weight' => -1);
  144. $items[] = array('path' => 'admin/build/themes/settings',
  145. 'title' => t('Configure'),
  146. 'callback' => 'drupal_get_form',
  147. 'callback arguments' => array('system_theme_settings'),
  148. 'access' => $access,
  149. 'type' => MENU_LOCAL_TASK);
  150. // Theme configuration subtabs
  151. $items[] = array('path' => 'admin/build/themes/settings/global', 'title' => t('Global settings'),
  152. 'callback' => 'drupal_get_form',
  153. 'callback arguments' => array('system_theme_settings'),
  154. 'access' => $access,
  155. 'type' => MENU_DEFAULT_LOCAL_TASK,
  156. 'weight' => -1);
  157. foreach (list_themes() as $theme) {
  158. if ($theme->status) {
  159. $items[] = array('path' => 'admin/build/themes/settings/'. $theme->name, 'title' => $theme->name,
  160. 'callback' => 'drupal_get_form', 'callback arguments' => array('system_theme_settings', $theme->name),
  161. 'access' => $access, 'type' => MENU_LOCAL_TASK);
  162. }
  163. }
  164. // Modules:
  165. $items[] = array('path' => 'admin/build/modules',
  166. 'title' => t('Modules'),
  167. 'description' => t('Enable or disable add-on modules for your site.'),
  168. 'callback' => 'drupal_get_form',
  169. 'callback arguments' => array('system_modules'),
  170. 'access' => $access);
  171. $items[] = array('path' => 'admin/build/modules/list',
  172. 'title' => t('List'),
  173. 'type' => MENU_DEFAULT_LOCAL_TASK,
  174. 'access' => $access);
  175. $items[] = array('path' => 'admin/build/modules/list/confirm',
  176. 'title' => t('List'),
  177. 'callback' => 'drupal_get_form',
  178. 'callback arguments' => array('system_modules'),
  179. 'type' => MENU_CALLBACK,
  180. 'access' => $access);
  181. $items[] = array('path' => 'admin/build/modules/uninstall',
  182. 'title' => t('Uninstall'),
  183. 'callback' => 'drupal_get_form',
  184. 'callback arguments' => array('system_modules_uninstall'),
  185. 'type' => MENU_LOCAL_TASK,
  186. 'access' => $access);
  187. $items[] = array('path' => 'admin/build/modules/uninstall/confirm',
  188. 'title' => t('Uninstall'),
  189. 'callback' => 'drupal_get_form',
  190. 'callback arguments' => array('system_modules_uninstall'),
  191. 'type' => MENU_CALLBACK,
  192. 'access' => $access);
  193. // Settings:
  194. $items[] = array(
  195. 'path' => 'admin/settings/site-information',
  196. 'title' => t('Site information'),
  197. 'description' => t('Change basic site information, such as the site name, slogan, e-mail address, mission, front page and more.'),
  198. 'callback' => 'drupal_get_form',
  199. 'callback arguments' => array('system_site_information_settings'));
  200. $items[] = array(
  201. 'path' => 'admin/settings/error-reporting',
  202. 'title' => t('Error reporting'),
  203. 'description' => t('Control how Drupal deals with errors including 403/404 errors as well as PHP error reporting.'),
  204. 'callback' => 'drupal_get_form',
  205. 'callback arguments' => array('system_error_reporting_settings'));
  206. $items[] = array(
  207. 'path' => 'admin/settings/performance',
  208. 'title' => t('Performance'),
  209. 'description' => t('Enable or disable page caching for anonymous users, and enable or disable CSS preprocessor.'),
  210. 'callback' => 'drupal_get_form',
  211. 'callback arguments' => array('system_performance_settings'));
  212. $items[] = array(
  213. 'path' => 'admin/settings/file-system',
  214. 'title' => t('File system'),
  215. 'description' => t('Tell Drupal where to store uploaded files and how they are accessed.'),
  216. 'callback' => 'drupal_get_form',
  217. 'callback arguments' => array('system_file_system_settings'));
  218. $items[] = array(
  219. 'path' => 'admin/settings/image-toolkit',
  220. 'title' => t('Image toolkit'),
  221. 'description' => t('Choose which image toolkit to use if you have installed optional toolkits.'),
  222. 'callback' => 'drupal_get_form',
  223. 'callback arguments' => array('system_image_toolkit_settings'));
  224. $items[] = array(
  225. 'path' => 'admin/content/rss-publishing',
  226. 'title' => t('RSS publishing'),
  227. 'description' => t('Configure the number of items per feed and whether feeds should be titles/teasers/full-text.'),
  228. 'callback' => 'drupal_get_form',
  229. 'callback arguments' => array('system_rss_feeds_settings'));
  230. $items[] = array(
  231. 'path' => 'admin/settings/date-time',
  232. 'title' => t('Date and time'),
  233. 'description' => t("Settings for how Drupal displays date and time, as well as the system's default timezone."),
  234. 'callback' => 'drupal_get_form',
  235. 'callback arguments' => array('system_date_time_settings'));
  236. $items[] = array(
  237. 'path' => 'admin/settings/site-maintenance',
  238. 'title' => t('Site maintenance'),
  239. 'description' => t('Take the site off-line for maintenance or bring it back online.'),
  240. 'callback' => 'drupal_get_form',
  241. 'callback arguments' => array('system_site_maintenance_settings'));
  242. $items[] = array(
  243. 'path' => 'admin/settings/clean-urls',
  244. 'title' => t('Clean URLs'),
  245. 'description' => t('Enable or disable clean URLs for your site.'),
  246. 'callback' => 'drupal_get_form',
  247. 'callback arguments' => array('system_clean_url_settings'));
  248. // Logs:
  249. $items[] = array(
  250. 'path' => 'admin/logs',
  251. 'title' => t('Logs'),
  252. 'description' => t('View system logs and other status information.'),
  253. 'callback' => 'system_admin_menu_block_page',
  254. 'weight' => 5,
  255. 'position' => 'left');
  256. $items[] = array(
  257. 'path' => 'admin/logs/status',
  258. 'title' => t('Status report'),
  259. 'description' => t("Get a status report about your site's operation and any detected problems."),
  260. 'callback' => 'system_status',
  261. 'weight' => 10,
  262. 'access' => $access);
  263. $items[] = array(
  264. 'path' => 'admin/logs/status/run-cron',
  265. 'title' => t('Run cron'),
  266. 'callback' => 'system_run_cron',
  267. 'type' => MENU_CALLBACK);
  268. $items[] = array(
  269. 'path' => 'admin/logs/status/php',
  270. 'title' => t('PHP'),
  271. 'callback' => 'system_php',
  272. 'type' => MENU_CALLBACK);
  273. $items[] = array(
  274. 'path' => 'admin/logs/status/sql',
  275. 'title' => t('SQL'),
  276. 'callback' => 'system_sql',
  277. 'type' => MENU_CALLBACK);
  278. }
  279. else {
  280. /**
  281. * Use the administrative theme if the user is looking at a page in the admin/* path.
  282. */
  283. if (arg(0) == 'admin') {
  284. global $custom_theme;
  285. $custom_theme = variable_get('admin_theme', '0');
  286. drupal_add_css(drupal_get_path('module', 'system') .'/admin.css', 'module');
  287. }
  288. // Add the CSS for this module. We put this in !$may_cache so it is only
  289. // added once per request.
  290. drupal_add_css(drupal_get_path('module', 'system') .'/defaults.css', 'module');
  291. drupal_add_css(drupal_get_path('module', 'system') .'/system.css', 'module');
  292. }
  293. return $items;
  294. }
  295. /**
  296. * Implementation of hook_user().
  297. *
  298. * Allows users to individually set their theme and time zone.
  299. */
  300. function system_user($type, $edit, &$user, $category = NULL) {
  301. if ($type == 'form' && $category == 'account') {
  302. $form['theme_select'] = system_theme_select_form(t('Selecting a different theme will change the look and feel of the site.'), $edit['theme'], 2);
  303. if (variable_get('configurable_timezones', 1)) {
  304. $zones = _system_zonelist();
  305. $form['timezone'] = array(
  306. '#type'=>'fieldset',
  307. '#title' => t('Locale settings'),
  308. '#weight' => 6,
  309. '#collapsible' => TRUE,
  310. );
  311. $form['timezone']['timezone'] = array(
  312. '#type' => 'select',
  313. '#title' => t('Time zone'),
  314. '#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
  315. '#options' => $zones,
  316. '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.'),
  317. );
  318. }
  319. return $form;
  320. }
  321. }
  322. /**
  323. * Provide the administration overview page.
  324. */
  325. function system_main_admin_page($arg = NULL) {
  326. // If we received an argument, they probably meant some other page.
  327. // Let's 404 them since the menu system cannot be told we do not
  328. // accept arguments.
  329. if (isset($arg) && substr($arg, 0, 3) != 'by-') {
  330. return drupal_not_found();
  331. }
  332. // Check for status report errors.
  333. if (system_status(TRUE)) {
  334. drupal_set_message(t('One or more problems were detected with your Drupal installation. Check the <a href="@status">status report</a> for more information.', array('@status' => url('admin/logs/status'))), 'error');
  335. }
  336. $menu = menu_get_item(NULL, 'admin');
  337. usort($menu['children'], '_menu_sort');
  338. foreach ($menu['children'] as $mid) {
  339. $block = menu_get_item($mid);
  340. if ($block['block callback'] && function_exists($block['block callback'])) {
  341. $arguments = isset($block['block arguments']) ? $block['block arguments'] : array();
  342. $block['content'] .= call_user_func_array($block['block callback'], $arguments);
  343. }
  344. $block['content'] .= theme('admin_block_content', system_admin_menu_block($block));
  345. $blocks[] = $block;
  346. }
  347. return theme('admin_page', $blocks);
  348. }
  349. /**
  350. * Provide a single block on the administration overview page.
  351. */
  352. function system_admin_menu_block($block) {
  353. $content = array();
  354. if (is_array($block['children'])) {
  355. usort($block['children'], '_menu_sort');
  356. foreach ($block['children'] as $mid) {
  357. $item = menu_get_item($mid);
  358. if (($item['type'] & MENU_VISIBLE_IN_TREE) && _menu_item_is_accessible($mid)) {
  359. $content[] = $item;
  360. }
  361. }
  362. }
  363. return $content;
  364. }
  365. /**
  366. * Provide a single block from the administration menu as a page.
  367. * This function is often a destination for these blocks.
  368. * For example, 'admin/content/types' needs to have a destination to be valid
  369. * in the Drupal menu system, but too much information there might be
  370. * hidden, so we supply the contents of the block.
  371. */
  372. function system_admin_menu_block_page() {
  373. $menu = menu_get_item(NULL, $_GET['q']);
  374. $content = system_admin_menu_block($menu);
  375. $output = theme('admin_block_content', $content);
  376. return $output;
  377. }
  378. function system_admin_compact_page($mode = 'off') {
  379. global $user;
  380. user_save($user, array('admin_compact_mode' => ($mode == 'on')));
  381. drupal_goto('admin');
  382. }
  383. /**
  384. * This function allows selection of the theme to show in administration sections.
  385. */
  386. function system_admin_theme_settings() {
  387. $themes = system_theme_data();
  388. ksort($themes);
  389. $options[0] = t('System default');
  390. foreach ($themes as $theme) {
  391. $options[$theme->name] = $theme->name;
  392. }
  393. $form['admin_theme'] = array(
  394. '#type' => 'select',
  395. '#options' => $options,
  396. '#title' => t('Administration theme'),
  397. '#description' => t('Choose which theme the administration pages should display in. If you choose "System default" the administration pages will use the same theme as the rest of the site.'),
  398. '#default_value' => variable_get('admin_theme', '0'),
  399. );
  400. // In order to give it our own submit, we have to give it the default submit
  401. // too because the presence of a #submit will prevent the default #submit
  402. // from being used. Also we want ours first.
  403. $form['#submit']['system_admin_theme_submit'] = array();
  404. $form['#submit']['system_settings_form_submit'] = array();
  405. return system_settings_form($form);
  406. }
  407. function system_admin_theme_submit($form_id, $form_values) {
  408. // If we're changing themes, make sure the theme has its blocks initialized.
  409. if ($form_values['admin_theme'] != variable_get('admin_theme', '0')) {
  410. $result = db_query("SELECT status FROM {blocks} WHERE theme = '%s'", $form_values['admin_theme']);
  411. if (!db_num_rows($result)) {
  412. system_initialize_theme_blocks($form_values['admin_theme']);
  413. }
  414. }
  415. }
  416. /**
  417. * Returns a fieldset containing the theme select form.
  418. *
  419. * @param $description
  420. * description of the fieldset
  421. * @param $default_value
  422. * default value of theme radios
  423. * @param $weight
  424. * weight of the fieldset
  425. * @return
  426. * a form array
  427. */
  428. function system_theme_select_form($description = '', $default_value = '', $weight = 0) {
  429. if (user_access('select different theme')) {
  430. foreach (list_themes() as $theme) {
  431. if ($theme->status) {
  432. $enabled[] = $theme;
  433. }
  434. }
  435. if (count($enabled) > 1) {
  436. ksort($enabled);
  437. $form['themes'] = array(
  438. '#type' => 'fieldset',
  439. '#title' => t('Theme configuration'),
  440. '#description' => $description,
  441. '#collapsible' => TRUE,
  442. '#theme' => 'system_theme_select_form'
  443. );
  444. foreach ($enabled as $info) {
  445. // For the default theme, revert to an empty string so the user's theme updates when the site theme is changed.
  446. $info->key = $info->name == variable_get('theme_default', 'garland') ? '' : $info->name;
  447. $info->screenshot = dirname($info->filename) .'/screenshot.png';
  448. $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');
  449. $form['themes'][$info->key]['screenshot'] = array('#value' => $screenshot);
  450. $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>' : ''));
  451. $options[$info->key] = '';
  452. }
  453. $form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $default_value ? $default_value : '');
  454. $form['#weight'] = $weight;
  455. return $form;
  456. }
  457. }
  458. }
  459. function theme_system_theme_select_form($form) {
  460. foreach (element_children($form) as $key) {
  461. $row = array();
  462. if (is_array($form[$key]['description'])) {
  463. $row[] = drupal_render($form[$key]['screenshot']);
  464. $row[] = drupal_render($form[$key]['description']);
  465. $row[] = drupal_render($form['theme'][$key]);
  466. }
  467. $rows[] = $row;
  468. }
  469. $header = array(t('Screenshot'), t('Name'), t('Selected'));
  470. $output = theme('table', $header, $rows);
  471. return $output;
  472. }
  473. function _system_zonelist() {
  474. $timestamp = time();
  475. $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);
  476. $zones = array();
  477. foreach ($zonelist as $offset) {
  478. $zone = $offset * 3600;
  479. $zones[$zone] = format_date($timestamp, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') .' O', $zone);
  480. }
  481. return $zones;
  482. }
  483. function system_site_information_settings() {
  484. $form['site_name'] = array(
  485. '#type' => 'textfield',
  486. '#title' => t('Name'),
  487. '#default_value' => variable_get('site_name', 'Drupal'),
  488. '#description' => t('The name of this web site.'),
  489. '#required' => TRUE
  490. );
  491. $form['site_mail'] = array(
  492. '#type' => 'textfield',
  493. '#title' => t('E-mail address'),
  494. '#default_value' => variable_get('site_mail', ini_get('sendmail_from')),
  495. '#description' => t('A valid e-mail address to be used as the "From" address by the auto-mailer during registration, new password requests, notifications, etc. To lessen the likelihood of e-mail being marked as spam, this e-mail address should use the same domain as the website.'),
  496. '#required' => TRUE,
  497. );
  498. $form['site_slogan'] = array(
  499. '#type' => 'textfield',
  500. '#title' => t('Slogan'),
  501. '#default_value' => variable_get('site_slogan', ''),
  502. '#description' => t('The slogan of this website. Some themes display a slogan when available.')
  503. );
  504. $form['site_mission'] = array(
  505. '#type' => 'textarea',
  506. '#title' => t('Mission'),
  507. '#default_value' => variable_get('site_mission', ''),
  508. '#description' => t('Your site\'s mission statement or focus.')
  509. );
  510. $form['site_footer'] = array(
  511. '#type' => 'textarea',
  512. '#title' => t('Footer message'),
  513. '#default_value' => variable_get('site_footer', ''),
  514. '#description' => t('This text will be displayed at the bottom of each page. Useful for adding a copyright notice to your pages.')
  515. );
  516. $form['anonymous'] = array(
  517. '#type' => 'textfield',
  518. '#title' => t('Anonymous user'),
  519. '#default_value' => variable_get('anonymous', t('Anonymous')),
  520. '#description' => t('The name used to indicate anonymous users.')
  521. );
  522. $form['site_frontpage'] = array(
  523. '#type' => 'textfield',
  524. '#title' => t('Default front page'),
  525. '#default_value' => variable_get('site_frontpage', 'node'),
  526. '#size' => 40,
  527. '#description' => t('The home page displays content from this relative URL. If unsure, specify "node".'),
  528. '#field_prefix' => url(NULL, NULL, NULL, TRUE) . (variable_get('clean_url', 0) ? '' : '?q=')
  529. );
  530. return system_settings_form($form);
  531. }
  532. function system_clean_url_settings() {
  533. // We check for clean URL support using an image on the client side.
  534. $form['clean_url'] = array(
  535. '#type' => 'radios',
  536. '#title' => t('Clean URLs'),
  537. '#default_value' => variable_get('clean_url', 0),
  538. '#options' => array(t('Disabled'), t('Enabled')),
  539. '#description' => t('This option makes Drupal emit "clean" URLs (i.e. without <code>?q=</code> in the URL.)'),
  540. );
  541. if (!variable_get('clean_url', 0)) {
  542. if (strpos(request_uri(), '?q=') !== FALSE) {
  543. $form['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/clean-urls">'. t('Run the clean URL test') .'</a>'));
  544. $form['clean_url']['#disabled'] = TRUE;
  545. }
  546. else {
  547. $form['clean_url']['#description'] .= t(' You have successfully demonstrated that clean URLs work on your server. You may enable/disable them as you wish.');
  548. $form['#collapsed'] = FALSE;
  549. }
  550. }
  551. return system_settings_form($form);
  552. }
  553. function system_error_reporting_settings() {
  554. $form['site_403'] = array(
  555. '#type' => 'textfield',
  556. '#title' => t('Default 403 (access denied) page'),
  557. '#default_value' => variable_get('site_403', ''),
  558. '#size' => 40,
  559. '#description' => t('This page is displayed when the requested document is denied to the current user. If unsure, specify nothing.'),
  560. '#field_prefix' => url(NULL, NULL, NULL, TRUE) . (variable_get('clean_url', 0) ? '' : '?q=')
  561. );
  562. $form['site_404'] = array(
  563. '#type' => 'textfield',
  564. '#title' => t('Default 404 (not found) page'),
  565. '#default_value' => variable_get('site_404', ''),
  566. '#size' => 40,
  567. '#description' => t('This page is displayed when no other content matches the requested document. If unsure, specify nothing.'),
  568. '#field_prefix' => url(NULL, NULL, NULL, TRUE) . (variable_get('clean_url', 0) ? '' : '?q=')
  569. );
  570. $form['error_level'] = array(
  571. '#type' => 'select', '#title' => t('Error reporting'), '#default_value' => variable_get('error_level', 1),
  572. '#options' => array(t('Write errors to the log'), t('Write errors to the log and to the screen')),
  573. '#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.')
  574. );
  575. $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval');
  576. $period['1000000000'] = t('Never');
  577. $form['watchdog_clear'] = array(
  578. '#type' => 'select',
  579. '#title' => t('Discard log entries older than'),
  580. '#default_value' => variable_get('watchdog_clear', 604800),
  581. '#options' => $period,
  582. '#description' => t('The time log entries should be kept. Older entries will be automatically discarded. Requires crontab.')
  583. );
  584. return system_settings_form($form);
  585. }
  586. function system_performance_settings() {
  587. $description = '<p>'. t("The normal cache mode is suitable for most sites and does not cause any side effects. The aggressive cache mode causes Drupal to skip the loading (init) and unloading (exit) of enabled modules when serving a cached page. This results in an additional performance boost but can cause unwanted side effects.") .'</p>';
  588. $problem_modules = array_unique(array_merge(module_implements('init'), module_implements('exit')));
  589. sort($problem_modules);
  590. if (count($problem_modules) > 0) {
  591. $description .= '<p>'. t('<strong class="error">The following enabled modules are incompatible with aggressive mode caching and might not function properly: %modules</strong>', array('%modules' => implode(', ', $problem_modules))) .'.</p>';
  592. }
  593. else {
  594. $description .= '<p>'. t('<strong class="ok">Currently, all enabled modules are compatible with the aggressive caching policy.</strong> Please note, if you use aggressive caching and enable new modules, you will need to check this page again to ensure compatibility.') .'</p>';
  595. }
  596. $form['page_cache'] = array(
  597. '#type' => 'fieldset',
  598. '#title' => t('Page cache'),
  599. '#description' => t('Enabling the cache will offer a significant performance boost. Drupal can store and send compressed cached pages requested by <em>anonymous</em> users. By caching a web page, Drupal does not have to construct the page each time someone wants to view it.'),
  600. );
  601. $form['page_cache']['cache'] = array(
  602. '#type' => 'radios',
  603. '#title' => t('Caching mode'),
  604. '#default_value' => variable_get('cache', CACHE_DISABLED),
  605. '#options' => array(CACHE_DISABLED => t('Disabled'), CACHE_NORMAL => t('Normal (recommended, no side effects)'), CACHE_AGGRESSIVE => t('Aggressive (experts only, possible side effects)')),
  606. '#description' => $description
  607. );
  608. $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval');
  609. $period[0] = t('none');
  610. $form['page_cache']['cache_lifetime'] = array(
  611. '#type' => 'select',
  612. '#title' => t('Minimum cache lifetime'),
  613. '#default_value' => variable_get('cache_lifetime', 0),
  614. '#options' => $period,
  615. '#description' => t('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.')
  616. );
  617. $form['bandwidth_optimizations'] = array(
  618. '#type' => 'fieldset',
  619. '#title' => t('Bandwidth optimizations'),
  620. '#description' => t('These options can help reduce both the size and number of requests made to your website. This can reduce the server load, the bandwidth used, and the average page loading time for your visitors.')
  621. );
  622. $directory = file_directory_path();
  623. $is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC);
  624. $form['bandwidth_optimizations']['preprocess_css'] = array(
  625. '#type' => 'radios',
  626. '#title' => t('Aggregate and compress CSS files'),
  627. '#default_value' => intval(variable_get('preprocess_css', FALSE) && $is_writable),
  628. '#disabled' => !$is_writable,
  629. '#options' => array(t('Disabled'), t('Enabled')),
  630. '#description' => t("Some Drupal modules include their own CSS files. When these modules are enabled, each module's CSS file adds an additional HTTP request to the page, which can increase the load time of each page. These HTTP requests can also slightly increase server load. It is recommended to only turn this option on when your site is in production, as it can interfere with theme development. This option is disabled if you have not set up your files directory, or if your download method is set to private."),
  631. );
  632. $form['#submit']['system_settings_form_submit'] = array();
  633. $form['#submit']['drupal_clear_css_cache'] = array();
  634. return system_settings_form($form);
  635. }
  636. function system_file_system_settings() {
  637. $form['file_directory_path'] = array(
  638. '#type' => 'textfield',
  639. '#title' => t('File system path'),
  640. '#default_value' => file_directory_path(),
  641. '#maxlength' => 255,
  642. '#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 the 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.'),
  643. '#after_build' => array('system_check_directory'),
  644. );
  645. $form['file_directory_temp'] = array(
  646. '#type' => 'textfield',
  647. '#title' => t('Temporary directory'),
  648. '#default_value' => file_directory_temp(),
  649. '#maxlength' => 255,
  650. '#description' => t('Location where uploaded files will be kept during previews. Relative paths will be resolved relative to the Drupal installation directory.'),
  651. '#after_build' => array('system_check_directory'),
  652. );
  653. $form['file_downloads'] = array(
  654. '#type' => 'radios',
  655. '#title' => t('Download method'),
  656. '#default_value' => variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC),
  657. '#options' => array(FILE_DOWNLOADS_PUBLIC => t('Public - files are available using HTTP directly.'), FILE_DOWNLOADS_PRIVATE => t('Private - files are transferred by Drupal.')),
  658. '#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.')
  659. );
  660. return system_settings_form($form);
  661. }
  662. function system_image_toolkit_settings() {
  663. $toolkits_available = image_get_available_toolkits();
  664. if (count($toolkits_available) > 1) {
  665. $form['image_toolkit'] = array(
  666. '#type' => 'radios',
  667. '#title' => t('Select an image processing toolkit'),
  668. '#default_value' => variable_get('image_toolkit', image_get_toolkit()),
  669. '#options' => $toolkits_available
  670. );
  671. }
  672. else {
  673. $form['image_toolkit'] = array('#value' => '<p>'. t("No image toolkits found. Drupal will use PHP's built-in GD library for image handling.") .'</p>');
  674. }
  675. $form['image_toolkit_settings'] = image_toolkit_invoke('settings');
  676. return system_settings_form($form);
  677. }
  678. function system_rss_feeds_settings() {
  679. $form['feed_default_items'] = array(
  680. '#type' => 'select',
  681. '#title' => t('Number of items per feed'),
  682. '#default_value' => variable_get('feed_default_items', 10),
  683. '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
  684. '#description' => t('The default number of items to include in a feed.')
  685. );
  686. $form['feed_item_length'] = array(
  687. '#type' => 'select',
  688. '#title' => t('Display of XML feed items'),
  689. '#default_value' => variable_get('feed_item_length', 'teaser'),
  690. '#options' => array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')),
  691. '#description' => t('Global setting for the length of XML feed items that are output by default.')
  692. );
  693. return system_settings_form($form);
  694. }
  695. function system_date_time_settings() {
  696. // Date settings:
  697. $zones = _system_zonelist();
  698. // Date settings: possible date formats
  699. $dateshort = array('Y-m-d H:i', 'm/d/Y - H:i', 'd/m/Y - H:i', 'Y/m/d - H:i',
  700. 'd.m.Y - H:i', 'm/d/Y - g:ia', 'd/m/Y - g:ia', 'Y/m/d - g:ia',
  701. 'M j Y - H:i', 'j M Y - H:i', 'Y M j - H:i',
  702. 'M j Y - g:ia', 'j M Y - g:ia', 'Y M j - g:ia');
  703. $datemedium = array('D, Y-m-d H:i', 'D, m/d/Y - H:i', 'D, d/m/Y - H:i',
  704. 'D, Y/m/d - H:i', 'F j, Y - H:i', 'j F, Y - H:i', 'Y, F j - H:i',
  705. 'D, m/d/Y - g:ia', 'D, d/m/Y - g:ia', 'D, Y/m/d - g:ia',
  706. 'F j, Y - g:ia', 'j F Y - g:ia', 'Y, F j - g:ia', 'j. F Y - G:i');
  707. $datelong = array('l, F j, Y - H:i', 'l, j F, Y - H:i', 'l, Y, F j - H:i',
  708. 'l, F j, Y - g:ia', 'l, j F Y - g:ia', 'l, Y, F j - g:ia', 'l, j. F Y - G:i');
  709. // Date settings: construct choices for user
  710. foreach ($dateshort as $f) {
  711. $dateshortchoices[$f] = format_date(time(), 'custom', $f);
  712. }
  713. foreach ($datemedium as $f) {
  714. $datemediumchoices[$f] = format_date(time(), 'custom', $f);
  715. }
  716. foreach ($datelong as $f) {
  717. $datelongchoices[$f] = format_date(time(), 'custom', $f);
  718. }
  719. $form['date_default_timezone'] = array(
  720. '#type' => 'select',
  721. '#title' => t('Default time zone'),
  722. '#default_value' => variable_get('date_default_timezone', 0),
  723. '#options' => $zones,
  724. '#description' => t('Select the default site time zone.')
  725. );
  726. $form['configurable_timezones'] = array(
  727. '#type' => 'radios',
  728. '#title' => t('Configurable time zones'),
  729. '#default_value' => variable_get('configurable_timezones', 1),
  730. '#options' => array(t('Disabled'), t('Enabled')),
  731. '#description' => t('Enable or disable user-configurable time zones. When enabled, users can set their own time zone and dates will be updated accordingly.')
  732. );
  733. $form['date_format_short'] = array(
  734. '#type' => 'select',
  735. '#title' => t('Short date format'),
  736. '#default_value' => variable_get('date_format_short', $dateshort[1]),
  737. '#options' => $dateshortchoices,
  738. '#description' => t('The short format of date display.')
  739. );
  740. $form['date_format_medium'] = array(
  741. '#type' => 'select',
  742. '#title' => t('Medium date format'),
  743. '#default_value' => variable_get('date_format_medium', $datemedium[1]),
  744. '#options' => $datemediumchoices,
  745. '#description' => t('The medium sized date display.')
  746. );
  747. $form['date_format_long'] = array(
  748. '#type' => 'select',
  749. '#title' => t('Long date format'),
  750. '#default_value' => variable_get('date_format_long', $datelong[0]),
  751. '#options' => $datelongchoices,
  752. '#description' => t('Longer date format used for detailed display.')
  753. );
  754. $form['date_first_day'] = array(
  755. '#type' => 'select',
  756. '#title' => t('First day of week'),
  757. '#default_value' => variable_get('date_first_day', 0),
  758. '#options' => array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')),
  759. '#description' => t('The first day of the week for calendar views.')
  760. );
  761. return system_settings_form($form);
  762. }
  763. function system_site_maintenance_settings() {
  764. $form['site_offline'] = array(
  765. '#type' => 'radios',
  766. '#title' => t('Site status'),
  767. '#default_value' => variable_get('site_offline', 0),
  768. '#options' => array(t('Online'), t('Off-line')),
  769. '#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'))),
  770. );
  771. $form['site_offline_message'] = array(
  772. '#type' => 'textarea',
  773. '#title' => t('Site off-line message'),
  774. '#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', 'Drupal')))),
  775. '#description' => t('Message to show visitors when the site is in off-line mode.')
  776. );
  777. return system_settings_form($form);
  778. }
  779. /**
  780. * Checks the existence of the directory specified in $form_element. This
  781. * function is called from the system_settings form to check both the
  782. * file_directory_path and file_directory_temp directories. If validation
  783. * fails, the form element is flagged with an error from within the
  784. * file_check_directory function.
  785. *
  786. * @param $form_element
  787. * The form element containing the name of the directory to check.
  788. */
  789. function system_check_directory($form_element) {
  790. file_check_directory($form_element['#value'], FILE_CREATE_DIRECTORY, $form_element['#parents'][0]);
  791. return $form_element;
  792. }
  793. /**
  794. * Retrieves the current status of an array of files in the system table.
  795. */
  796. function system_get_files_database(&$files, $type) {
  797. // Extract current files from database.
  798. $result = db_query("SELECT filename, name, type, status, throttle, schema_version FROM {system} WHERE type = '%s'", $type);
  799. while ($file = db_fetch_object($result)) {
  800. if (isset($files[$file->name]) && is_object($files[$file->name])) {
  801. $file->old_filename = $file->filename;
  802. foreach ($file as $key => $value) {
  803. if (!isset($files[$file->name]) || !isset($files[$file->name]->$key)) {
  804. $files[$file->name]->$key = $value;
  805. }
  806. }
  807. }
  808. }
  809. }
  810. /**
  811. * Collect data about all currently available themes
  812. */
  813. function system_theme_data() {
  814. include_once './includes/install.inc';
  815. // Find themes
  816. $themes = drupal_system_listing('\.theme$', 'themes');
  817. // Find theme engines
  818. $engines = drupal_system_listing('\.engine$', 'themes/engines');
  819. // can't iterate over array itself as it uses a copy of the array items
  820. foreach (array_keys($themes) as $key) {
  821. drupal_get_filename('theme', $themes[$key]->name, $themes[$key]->filename);
  822. drupal_load('theme', $themes[$key]->name);
  823. $themes[$key]->owner = $themes[$key]->filename;
  824. $themes[$key]->prefix = $key;
  825. }
  826. // Remove all theme engines from the system table
  827. db_query("DELETE FROM {system} WHERE type = 'theme_engine'");
  828. foreach ($engines as $engine) {
  829. // Insert theme engine into system table
  830. drupal_get_filename('theme_engine', $engine->name, $engine->filename);
  831. drupal_load('theme_engine', $engine->name);
  832. 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);
  833. // Add templates to the site listing
  834. foreach (call_user_func($engine->name .'_templates') as $template) {
  835. // Do not double-insert templates with theme files in their directory,
  836. // but do register their engine data.
  837. if (array_key_exists($template->name, $themes)) {
  838. $themes[$template->name]->template = TRUE;
  839. $themes[$template->name]->owner = $engine->filename;
  840. $themes[$template->name]->prefix = $engine->name;
  841. }
  842. else {
  843. $template->template = TRUE;
  844. $template->name = basename(dirname($template->filename));
  845. $template->owner = $engine->filename;
  846. $template->prefix = $engine->name;
  847. $themes[$template->name] = $template;
  848. }
  849. }
  850. }
  851. // Find styles in each theme's directory.
  852. foreach ($themes as $theme) {
  853. foreach (file_scan_directory(dirname($theme->filename), 'style.css$') as $style) {
  854. $style->style = TRUE;
  855. $style->template = isset($theme->template) ? $theme->template : FALSE;
  856. $style->name = basename(dirname($style->filename));
  857. $style->owner = $theme->filename;
  858. $style->prefix = $theme->template ? $theme->prefix : $theme->name;
  859. // do not double-insert styles with theme files in their directory
  860. if (array_key_exists($style->name, $themes)) {
  861. continue;
  862. }
  863. $themes[$style->name] = $style;
  864. }
  865. }
  866. // Extract current files from database.
  867. system_get_files_database($themes, 'theme');
  868. db_query("DELETE FROM {system} WHERE type = 'theme'");
  869. foreach ($themes as $theme) {
  870. 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);
  871. }
  872. return $themes;
  873. }
  874. /**
  875. * Get a list of available regions from a specified theme.
  876. *
  877. * @param $theme_key
  878. * The name of a theme.
  879. * @return
  880. * An array of regions in the form $region['name'] = 'description'.
  881. */
  882. function system_region_list($theme_key) {
  883. static $list = array();
  884. if (!array_key_exists($theme_key, $list)) {
  885. $theme = db_fetch_object(db_query("SELECT * FROM {system} WHERE type = 'theme' AND name = '%s'", $theme_key));
  886. // Stylesheets can't have regions; use its theme.
  887. if (strpos($theme->filename, '.css')) {
  888. return system_region_list(basename(dirname($theme->description)));
  889. }
  890. // If this is a custom theme, load it in before moving on.
  891. if (file_exists($file = dirname($theme->filename) .'/'. $theme_key .'.theme')) {
  892. include_once "./$file";
  893. }
  894. $regions = array();
  895. // This theme has defined its own regions.
  896. if (function_exists($theme_key .'_regions')) {
  897. $regions = call_user_func($theme_key .'_regions');
  898. }
  899. // File is an engine; include its regions.
  900. else if (strpos($theme->description, '.engine')) {
  901. include_once './'. $theme->description;
  902. $theme_engine = basename($theme->description, '.engine');
  903. $regions = function_exists($theme_engine .'_regions') ? call_user_func($theme_engine .'_regions') : array();
  904. }
  905. $list[$theme_key] = $regions;
  906. }
  907. return $list[$theme_key];
  908. }
  909. /**
  910. * Get the name of the default region for a given theme.
  911. *
  912. * @param $theme
  913. * The name of a theme.
  914. * @return
  915. * A string that is the region name.
  916. */
  917. function system_default_region($theme) {
  918. $regions = array_keys(system_region_list($theme));
  919. return $regions[0];
  920. }
  921. /**
  922. * Assign an initial, default set of blocks for a theme.
  923. *
  924. * This function is called the first time a new theme is enabled. The new theme
  925. * gets a copy of the default theme's blocks, with the difference that if a
  926. * particular region isn't available in the new theme, the block is assigned
  927. * to the new theme's default region.
  928. *
  929. * @param $theme
  930. * The name of a theme.
  931. */
  932. function system_initialize_theme_blocks($theme) {
  933. // Initialize theme's blocks if none already registered.
  934. if (!(db_num_rows(db_query("SELECT module FROM {blocks} WHERE theme = '%s'", $theme)))) {
  935. $default_theme = variable_get('theme_default', 'garland');
  936. $regions = system_region_list($theme);
  937. $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
  938. while ($block = db_fetch_array($result)) {
  939. // If the region isn't supported by the theme, assign the block to the theme's default region.
  940. if (!array_key_exists($block['region'], $regions)) {
  941. $block['region'] = system_default_region($theme);
  942. }
  943. 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)",
  944. $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']);
  945. }
  946. }
  947. }
  948. /**
  949. * Add default buttons to a form and set its prefix
  950. */
  951. function system_settings_form($form) {
  952. $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
  953. $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
  954. if (!empty($_POST) && form_get_errors()) {
  955. drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
  956. }
  957. $form['#base'] = 'system_settings_form';
  958. return $form;
  959. }
  960. function system_theme_settings_submit($form_id, $form_values) {
  961. $op = isset($_POST['op']) ? $_POST['op'] : '';
  962. $key = $form_values['var'];
  963. // Exclude unnecessary elements.
  964. unset($form_values['var'], $form_values['submit'], $form_values['reset'], $form_values['form_id']);
  965. if ($op == t('Reset to defaults')) {
  966. variable_del($key);
  967. drupal_set_message(t('The configuration options have been reset to their default values.'));
  968. }
  969. else {
  970. variable_set($key, $form_values);
  971. drupal_set_message(t('The configuration options have been saved.'));
  972. }
  973. cache_clear_all();
  974. }
  975. /**
  976. * Execute the system_settings_form.
  977. *
  978. * If you want node type configure style handling of your checkboxes,
  979. * add an array_filter value to your form.
  980. *
  981. */
  982. function system_settings_form_submit($form_id, $form_values) {
  983. $op = isset($form_values['op']) ? $form_values['op'] : '';
  984. // Exclude unnecessary elements.
  985. unset($form_values['submit'], $form_values['reset'], $form_values['form_id'], $form_values['op'], $form_values['form_token']);
  986. foreach ($form_values as $key => $value) {
  987. if ($op == t('Reset to defaults')) {
  988. variable_del($key);
  989. }
  990. else {
  991. if (is_array($value) && isset($form_values['array_filter'])) {
  992. $value = array_keys(array_filter($value));
  993. }
  994. variable_set($key, $value);
  995. }
  996. }
  997. if ($op == t('Reset to defaults')) {
  998. drupal_set_message(t('The configuration options have been reset to their default values.'));
  999. }
  1000. else {
  1001. drupal_set_message(t('The configuration options have been saved.'));
  1002. }
  1003. menu_rebuild();
  1004. }
  1005. /**
  1006. * Menu callback; displays a listing of all themes.
  1007. */
  1008. function system_themes() {
  1009. drupal_clear_css_cache();
  1010. $themes = system_theme_data();
  1011. ksort($themes);
  1012. foreach ($themes as $info) {
  1013. $info->screenshot = dirname($info->filename) .'/screenshot.png';
  1014. $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');
  1015. $form[$info->name]['screenshot'] = array('#value' => $screenshot);
  1016. $form[$info->name]['description'] = array('#type' => 'item', '#title' => $info->name, '#value' => dirname($info->filename));
  1017. $options[$info->name] = '';
  1018. if ($info->status) {
  1019. $status[] = $info->name;
  1020. }
  1021. if ($info->status && (function_exists($info->prefix .'_settings') || function_exists($info->prefix .'_features'))) {
  1022. $form[$info->name]['operations'] = array('#value' => l(t('configure'), 'admin/build/themes/settings/'. $info->name) );
  1023. }
  1024. else {
  1025. // Dummy element for drupal_render. Cleaner than adding a check in the theme function.
  1026. $form[$info->name]['operations'] = array();
  1027. }
  1028. }
  1029. $form['status'] = array('#type' => 'checkboxes', '#options' => $options, '#default_value' => $status);
  1030. $form['theme_default'] = array('#type' => 'radios', '#options' => $options, '#default_value' => variable_get('theme_default', 'garland'));
  1031. $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
  1032. $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
  1033. return $form;
  1034. }
  1035. function theme_system_themes($form) {
  1036. foreach (element_children($form) as $key) {
  1037. $row = array();
  1038. if (is_array($form[$key]['description'])) {
  1039. $row[] = drupal_render($form[$key]['screenshot']);
  1040. $row[] = drupal_render($form[$key]['description']);
  1041. $row[] = array('data' => drupal_render($form['status'][$key]), 'align' => 'center');
  1042. if ($form['theme_default']) {
  1043. $row[] = array('data' => drupal_render($form['theme_default'][$key]), 'align' => 'center');
  1044. $row[] = array('data' => drupal_render($form[$key]['operations']), 'align' => 'center');
  1045. }
  1046. }
  1047. $rows[] = $row;
  1048. }
  1049. $header = array(t('Screenshot'), t('Name'), t('Enabled'), t('Default'), t('Operations'));
  1050. $output = theme('table', $header, $rows);
  1051. $output .= drupal_render($form);
  1052. return $output;
  1053. }
  1054. function system_themes_submit($form_id, $form_values) {
  1055. db_query("UPDATE {system} SET status = 0 WHERE type = 'theme'");
  1056. if ($form_values['op'] == t('Save configuration')) {
  1057. if (is_array($form_values['status'])) {
  1058. foreach ($form_values['status'] as $key => $choice) {
  1059. // Always enable the default theme, despite its status checkbox being checked:
  1060. if ($choice || $form_values['theme_default'] == $key) {
  1061. system_initialize_theme_blocks($key);
  1062. db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' and name = '%s'", $key);
  1063. }
  1064. }
  1065. }
  1066. if (($admin_theme = variable_get('admin_theme', '0')) != '0' && $admin_theme != $form_values['theme_default']) {
  1067. drupal_set_message(t('Please note that the <a href="!admin_theme_page">administration theme</a> is still set to the %admin_theme theme; consequently, the theme on this page remains unchanged. All non-administrative sections of the site, however, will show the selected %selected_theme theme by default.', array(
  1068. '!admin_theme_page' => url('admin/settings/admin'),
  1069. '%admin_theme' => $admin_theme,
  1070. '%selected_theme' => $form_values['theme_default'],
  1071. )));
  1072. }
  1073. variable_set('theme_default', $form_values['theme_default']);
  1074. }
  1075. else {
  1076. variable_del('theme_default');
  1077. db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' AND name = 'garland'");
  1078. }
  1079. menu_rebuild();
  1080. drupal_set_message(t('The configuration options have been saved.'));
  1081. return 'admin/build/themes';
  1082. }
  1083. /**
  1084. * Menu callback; provides module enable/disable interface.
  1085. *
  1086. * Modules can be enabled or disabled and set for throttling if the throttle module is enabled.
  1087. * The list of modules gets populated by module.info files, which contain each module's name,
  1088. * description and dependencies.
  1089. * @see _module_parse_info_file for information on module.info descriptors.
  1090. *
  1091. * Dependency checking is performed to ensure that a module cannot be enabled if the module has
  1092. * disabled dependencies and also to ensure that the module cannot be disabled if the module has
  1093. * enabled dependents.
  1094. *
  1095. * @return
  1096. * The form array.
  1097. */
  1098. function system_modules($form_values = NULL) {
  1099. // Get current list of modules.
  1100. $files = module_rebuild_cache();
  1101. uasort($files, 'system_sort_modules_by_info_name');
  1102. if ($confirm_form = system_modules_confirm_form($files, $form_values)) {
  1103. return $confirm_form;
  1104. }
  1105. // Store module list for validation callback.
  1106. $form['validation_modules'] = array('#type' => 'value', '#value' => $files);
  1107. // Create storage for disabled modules as browser will disable checkboxes.
  1108. $form['disabled_modules'] = array('#type' => 'value', '#value' => array());
  1109. // Array for disabling checkboxes in callback system_module_disable.
  1110. $disabled = array();
  1111. // Traverse the files retrieved and build the form.
  1112. foreach ($files as $filename => $file) {
  1113. $form['name'][$filename] = array('#value' => $file->info['name']);
  1114. $form['version'][$filename] = array('#value' => $file->info['version']);
  1115. $form['description'][$filename] = array('#value' => t($file->info['description']));
  1116. $options[$filename] = '';
  1117. if ($file->status) {
  1118. $status[] = $file->name;
  1119. }
  1120. if ($file->throttle) {
  1121. $throttle[] = $file->name;
  1122. }
  1123. $dependencies = array();
  1124. // Check for missing dependencies.
  1125. if (is_array($file->info['dependencies'])) {
  1126. foreach ($file->info['dependencies'] as $dependency) {
  1127. if (!isset($files[$dependency]) || !$files[$dependency]->status) {
  1128. if (isset($files[$dependency])) {
  1129. $dependencies[] = $files[$dependency]->info['name'] . t(' (<span class="admin-disabled">disabled</span>)');
  1130. }
  1131. else {
  1132. $dependencies[] = drupal_ucfirst($dependency) . t(' (<span class="admin-missing">missing</span>)');
  1133. $disabled[] = $filename;
  1134. $form['disabled_modules']['#value'][$filename] = FALSE;
  1135. }
  1136. }
  1137. else {
  1138. $dependencies[] = $files[$dependency]->info['name'] . t(' (<span class="admin-enabled">enabled</span>)');
  1139. }
  1140. }
  1141. // Add text for dependencies.
  1142. if (!empty($dependencies)) {
  1143. $form['description'][$filename]['dependencies'] = array(
  1144. '#value' => t('Depends on: !dependencies', array('!dependencies' => implode(', ', $dependencies))),
  1145. '#prefix' => '<div class="admin-dependencies">',
  1146. '#suffix' => '</div>',
  1147. );
  1148. }
  1149. }
  1150. // Mark dependents disabled so user can not remove modules being depended on.
  1151. $dependents = array();
  1152. if (is_array($file->info['dependents'])) {
  1153. foreach ($file->info['dependents'] as $dependent) {
  1154. if ($files[$dependent]->status == 1) {
  1155. $dependents[] = $files[$dependent]->info['name'] . t(' (<span class="admin-enabled">enabled</span>)');
  1156. $disabled[] = $filename;
  1157. $form['disabled_modules']['#value'][$filename] = TRUE;
  1158. }
  1159. else {
  1160. $dependents[] = $files[$dependent]->info['name'] . t(' (<span class="admin-disabled">disabled</span>)');
  1161. }
  1162. }
  1163. }
  1164. // Add text for enabled dependents.
  1165. if (!empty($dependents)) {
  1166. $form['description'][$filename]['required'] = array(
  1167. '#value' => t('Required by: !required', array('!required' => implode(', ', $dependents))),
  1168. '#prefix' => '<div class="admin-required">',
  1169. '#suffix' => '</div>',
  1170. );
  1171. }
  1172. }
  1173. // Merge in required modules.
  1174. $modules_required = array('block', 'filter', 'node', 'system', 'user', 'watchdog');
  1175. foreach ($modules_required as $required) {
  1176. $disabled[] = $required;
  1177. $form['disabled_modules']['#value'][$required] = TRUE;
  1178. }
  1179. // Handle status checkboxes, including overriding
  1180. // the generated checkboxes for required modules.
  1181. $form['status'] = array(
  1182. '#type' => 'checkboxes',
  1183. '#default_value' => $status,
  1184. '#options' => $options,
  1185. '#process' => array(
  1186. 'expand_checkboxes' => array(),
  1187. 'system_modules_disable' => array($disabled),
  1188. ),
  1189. );
  1190. // Handle throttle checkboxes, including overriding the
  1191. // generated checkboxes for required modules.
  1192. if (module_exists('throttle')) {
  1193. $form['throttle'] = array(
  1194. '#type' => 'checkboxes',
  1195. '#default_value' => $throttle,
  1196. '#options' => $options,
  1197. '#process' => array(
  1198. 'expand_checkboxes' => array(),
  1199. 'system_modules_disable' => array(array_merge($modules_required, array('throttle'))),
  1200. ),
  1201. );
  1202. }
  1203. $form['buttons']['submit'] = array(
  1204. '#type' => 'submit',
  1205. '#value' => t('Save configuration'),
  1206. );
  1207. $form['#multistep'] = TRUE;
  1208. $form['#action'] = url('admin/build/modules/list/confirm');
  1209. return $form;
  1210. }
  1211. function system_sort_modules_by_info_name($a, $b) {
  1212. return strcasecmp($a->info['name'], $b->info['name']);
  1213. }
  1214. /**
  1215. * Form process callback function to disable check boxes.
  1216. */
  1217. function system_modules_disable($form, $edit, $disabled) {
  1218. foreach ($disabled as $key) {
  1219. $form[$key]['#attributes']['disabled'] = 'disabled';
  1220. }
  1221. return $form;
  1222. }
  1223. function system_modules_confirm_form($modules, $form_values = array()) {
  1224. $form = array();
  1225. $items = array();
  1226. // Check values for submitted dependency errors.
  1227. if ($dependencies = system_module_build_dependencies($modules, $form_values)) {
  1228. // preserve the already switched on modules
  1229. foreach ($modules as $name => $module) {
  1230. if ($module->status) {
  1231. $form['status'][$name] = array('#type' => 'hidden', '#value' => 1);
  1232. }
  1233. }
  1234. $form['validation_modules'] = array('#type' => 'value', '#value' => $modules);
  1235. $form['status']['#tree'] = TRUE;
  1236. foreach ($dependencies as $name => $missing_dependencies) {
  1237. $form['status'][$name] = array('#type' => 'hidden', '#value' => 1);
  1238. foreach ($missing_dependencies as $k => $dependency) {
  1239. $form['status'][$dependency] = array('#type' => 'hidden', '#value' => 1);
  1240. $info = $modules[$dependency]->info;
  1241. $missing_dependencies[$k] = $info['name'] ? $info['name'] : drupal_ucfirst($dependency);
  1242. }
  1243. $t_argument = array(
  1244. '%module' => $modules[$name]->info['name'],
  1245. '%dependencies' => implode(', ', $missing_dependencies),
  1246. );
  1247. $items[] = strtr(format_plural(count($missing_dependencies), 'You must enable the %dependencies module to install %module.', 'You must enable the %dependencies modules to install %module.'), $t_argument);
  1248. }
  1249. $form['text'] = array('#value' => theme('item_list', $items));
  1250. }
  1251. if ($form) {
  1252. // Set some default form values
  1253. $form = confirm_form(
  1254. $form,
  1255. t('Some required modules must be enabled'),
  1256. 'admin/build/modules',
  1257. t('Would you like to continue with enabling the above?'),
  1258. t('Continue'),
  1259. t('Cancel'));
  1260. return $form;
  1261. }
  1262. }
  1263. function system_module_build_dependencies($modules, $form_values) {
  1264. static $dependencies;
  1265. if (!isset($dependencies) && isset($form_values) && is_array($form_values)) {
  1266. $dependencies = array();
  1267. foreach ($modules as $name => $module) {
  1268. // If the module is disabled, will be switched on and it has dependencies.
  1269. if (!$module->status && isset($form_values['status'][$name]) && $form_values['status'][$name] && isset($module->info['dependencies'])) {
  1270. foreach ($module->info['dependencies'] as $dependency) {
  1271. if (!$form_values['status'][$dependency] && isset($modules[$dependency])) {
  1272. if (!isset($dependencies[$name])) {
  1273. $dependencies[$name] = array();
  1274. }
  1275. $dependencies[$name][] = $dependency;
  1276. }
  1277. }
  1278. }
  1279. }
  1280. }
  1281. return $dependencies;
  1282. }
  1283. /**
  1284. * Submit callback; handles modules form submission.
  1285. */
  1286. function system_modules_submit($form_id, $form_values) {
  1287. include_once './includes/install.inc';
  1288. $new_modules = array();
  1289. // Merge in disabled active modules since they should be enabled.
  1290. // They don't appear because disabled checkboxes are not submitted
  1291. // by browsers.
  1292. $form_values['status'] = array_merge($form_values['status'], $form_values['disabled_modules']);
  1293. // Check values for dependency that we can't install.
  1294. if ($dependencies = system_module_build_dependencies($form_values['validation_modules'], $form_values)) {
  1295. // These are the modules that depend on existing modules.
  1296. foreach (array_keys($dependencies) as $name) {
  1297. $form_values['status'][$name] = 0;
  1298. }
  1299. }
  1300. $enable_modules = array();
  1301. $disable_modules = array();
  1302. foreach ($form_values['status'] as $key => $choice) {
  1303. if ($choice) {
  1304. if (drupal_get_installed_schema_version($key) == SCHEMA_UNINSTALLED) {
  1305. $new_modules[] = $key;
  1306. }
  1307. else {
  1308. $enable_modules[] = $key;
  1309. }
  1310. }
  1311. else {
  1312. $disable_modules[] = $key;
  1313. }
  1314. }
  1315. $old_module_list = module_list();
  1316. if (!empty($enable_modules)) {
  1317. module_enable($enable_modules);
  1318. }
  1319. if (!empty($disable_modules)) {
  1320. module_disable($disable_modules);
  1321. }
  1322. // Install new modules.
  1323. foreach ($new_modules as $key => $module) {
  1324. if (!drupal_check_module($module)) {
  1325. unset($new_modules[$key]);
  1326. }
  1327. }
  1328. drupal_install_modules($new_modules);
  1329. $current_module_list = module_list(TRUE, FALSE);
  1330. if (is_array($form_values['throttle'])) {
  1331. foreach ($form_values['throttle'] as $key => $choice) {
  1332. db_query("UPDATE {system} SET throttle = %d WHERE type = 'module' and name = '%s'", $choice ? 1 : 0, $key);
  1333. }
  1334. }
  1335. if ($old_module_list != $current_module_list) {
  1336. menu_rebuild();
  1337. node_types_rebuild();
  1338. drupal_set_message(t('The configuration options have been saved.'));
  1339. }
  1340. // If there where unmet dependencies and they haven't confirmed don't redirect.
  1341. if ($dependencies && !isset($form_values['confirm'])) {
  1342. return FALSE;
  1343. }
  1344. drupal_clear_css_cache();
  1345. return 'admin/build/modules';
  1346. }
  1347. /**
  1348. * Theme call back for the modules form.
  1349. */
  1350. function theme_system_modules($form) {
  1351. if (isset($form['confirm'])) {
  1352. return drupal_render($form);
  1353. }
  1354. // Individual table headers.
  1355. $header = array(t('Enabled'));
  1356. if (module_exists('throttle')) {
  1357. $header[] = t('Throttle');
  1358. }
  1359. $header[] = t('Name');
  1360. $header[] = t('Version');
  1361. $header[] = t('Description');
  1362. // Pull package information from module list and start grouping modules.
  1363. $modules = $form['validation_modules']['#value'];
  1364. foreach ($modules as $module) {
  1365. if (!isset($module->info['package']) || !$module->info['package']) {
  1366. $module->info['package'] = t('Other');
  1367. }
  1368. $packages[$module->info['package']][$module->name] = $module->info;
  1369. }
  1370. ksort($packages);
  1371. // Display packages.
  1372. $output = '';
  1373. foreach ($packages as $package => $modules) {
  1374. $rows = array();
  1375. foreach ($modules as $key => $module) {
  1376. $row = array();
  1377. $row[] = array('data' => drupal_render($form['status'][$key]), 'align' => 'center');
  1378. if (module_exists('throttle')) {
  1379. $row[] = array('data' => drupal_render($form['throttle'][$key]), 'align' => 'center');
  1380. }
  1381. $row[] = '<strong>'. drupal_render($form['name'][$key]) .'</strong>';
  1382. $row[] = drupal_render($form['version'][$key]);
  1383. $row[] = array('data' => drupal_render($form['description'][$key]), 'class' => 'description');
  1384. $rows[] = $row;
  1385. }
  1386. $fieldset = array(
  1387. '#title' => t($package),
  1388. '#collapsible' => TRUE,
  1389. '#collapsed' => ($package == 'Core - required'),
  1390. '#value' => theme('table', $header, $rows, array('class' => 'package')),
  1391. );
  1392. $output .= theme('fieldset', $fieldset);
  1393. }
  1394. $output .= drupal_render($form);
  1395. return $output;
  1396. }
  1397. /**
  1398. * Uninstall functions
  1399. */
  1400. /**
  1401. * Builds a form of currently disabled modules.
  1402. *
  1403. * @param
  1404. * $form_values Submitted form values.
  1405. * @return
  1406. * A form array representing the currently disabled modules.
  1407. */
  1408. function system_modules_uninstall($form_values = NULL) {
  1409. // Make sure the install API is available.
  1410. include_once './includes/install.inc';
  1411. // Display the confirm form if any modules have been submitted.
  1412. if ($confirm_form = system_modules_uninstall_confirm_form($form_values)) {
  1413. return $confirm_form;
  1414. }
  1415. $form = array();
  1416. // Pull all disabled modules from the system table.
  1417. $disabled_modules = db_query("SELECT name, filename FROM {system} WHERE type = 'module' AND status = 0 AND schema_version > %d ORDER BY name", SCHEMA_UNINSTALLED);
  1418. while ($module = db_fetch_object($disabled_modules)) {
  1419. // Grab the .info file and set name and description.
  1420. $info = _module_parse_info_file(dirname($module->filename) .'/'. $module->name .'.info');
  1421. // Load the .install file, and check for an uninstall hook.
  1422. // If the hook exists, the module can be uninstalled.
  1423. module_load_install($module->name);
  1424. if (module_hook($module->name, 'uninstall')) {
  1425. $form['modules'][$module->name]['name'] = array('#value' => $info['name'] ? $info['name'] : $module->name);
  1426. $form['modules'][$module->name]['description'] = array('#value' => t($info['description']));
  1427. $options[$module->name] = '';
  1428. }
  1429. }
  1430. // Only build the rest of the form if there are any modules available to uninstall.
  1431. if (count($options)) {
  1432. $form['uninstall'] = array(
  1433. '#type' => 'checkboxes',
  1434. '#options' => $options,
  1435. );
  1436. $form['buttons']['submit'] = array(
  1437. '#type' => 'button',
  1438. '#value' => t('Uninstall'),
  1439. );
  1440. $form['#multistep'] = TRUE;
  1441. $form['#action'] = url('admin/build/modules/uninstall/confirm');
  1442. }
  1443. return $form;
  1444. }
  1445. /**
  1446. * Confirm uninstall of selected modules.
  1447. *
  1448. * @param
  1449. * $form_values Submitted form values.
  1450. * @return
  1451. * A form array representing modules to confirm.
  1452. */
  1453. function system_modules_uninstall_confirm_form($form_values) {
  1454. // Nothing to build.
  1455. if (!isset($form_values)) {
  1456. return;
  1457. }
  1458. // Construct the hidden form elements and list items.
  1459. foreach (array_filter($form_values['uninstall']) as $module => $value) {
  1460. $info = _module_parse_info_file(dirname(drupal_get_filename('module', $module)) .'/'. $module .'.info');
  1461. $uninstall[] = $info['name'];
  1462. $form['uninstall'][$module] = array('#type' => 'hidden',
  1463. '#value' => 1,
  1464. );
  1465. }
  1466. // Display a confirm form if modules have been selected.
  1467. if (isset($uninstall)) {
  1468. $form['uninstall']['#tree'] = TRUE;
  1469. $form['#multistep'] = TRUE;
  1470. $form['modules'] = array('#value' => '<p>'. t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') .'</p>'. theme('item_list', $uninstall));
  1471. $form = confirm_form(
  1472. $form,
  1473. t('Confirm uninstall'),
  1474. 'admin/build/modules/uninstall',
  1475. t('Would you like to continue with uninstalling the above?'),
  1476. t('Uninstall'),
  1477. t('Cancel'));
  1478. return $form;
  1479. }
  1480. }
  1481. /**
  1482. * Themes a table of currently disabled modules.
  1483. *
  1484. * @param
  1485. * $form The form array representing the currently disabled modules.
  1486. * @return
  1487. * An HTML string representing the table.
  1488. */
  1489. function theme_system_modules_uninstall($form) {
  1490. // No theming for the confirm form.
  1491. if (isset($form['confirm'])) {
  1492. return drupal_render($form);
  1493. }
  1494. // Table headers.
  1495. $header = array(t('Uninstall'),
  1496. t('Name'),
  1497. t('Description'),
  1498. );
  1499. // Display table.
  1500. $rows = array();
  1501. foreach (element_children($form['modules']) as $module) {
  1502. $rows[] = array(
  1503. array('data' => drupal_render($form['uninstall'][$module]), 'align' => 'center'),
  1504. '<strong>'. drupal_render($form['modules'][$module]['name']) .'</strong>',
  1505. array('data' => drupal_render($form['modules'][$module]['description']), 'class' => 'description'),
  1506. );
  1507. }
  1508. // Only display table if there are modules that can be uninstalled.
  1509. if (!count($rows)) {
  1510. $rows[] = array(array('data' => t('No modules are available to uninstall.'), 'colspan' => '3', 'align' => 'center', 'class' => 'message'));
  1511. }
  1512. $output = theme('table', $header, $rows);
  1513. $output .= drupal_render($form);
  1514. return $output;
  1515. }
  1516. /**
  1517. * Validates the submitted uninstall form.
  1518. *
  1519. * @param
  1520. * $form_id The form ID.
  1521. * @param
  1522. * $form_values Submitted form values.
  1523. */
  1524. function system_modules_uninstall_validate($form_id, $form_values) {
  1525. // Form submitted, but no modules selected.
  1526. if (!count(array_filter($form_values['uninstall']))) {
  1527. drupal_set_message(t('No modules selected.'), 'error');
  1528. drupal_goto('admin/build/modules/uninstall');
  1529. }
  1530. }
  1531. /**
  1532. * Processes the submitted uninstall form.
  1533. *
  1534. * @param
  1535. * $form_id The form ID.
  1536. * @param
  1537. * $form_values Submitted form values.
  1538. */
  1539. function system_modules_uninstall_submit($form_id, $form_values) {
  1540. // Make sure the install API is available.
  1541. include_once './includes/install.inc';
  1542. // Call the uninstall routine for each selected module.
  1543. foreach (array_filter($form_values['uninstall']) as $module => $value) {
  1544. drupal_uninstall_module($module);
  1545. }
  1546. drupal_set_message(t('The selected modules have been uninstalled.'));
  1547. drupal_goto('admin/build/modules/uninstall');
  1548. }
  1549. /**
  1550. * Menu callback: run cron manually.
  1551. */
  1552. function system_run_cron() {
  1553. // Run cron manually
  1554. if (drupal_cron_run()) {
  1555. drupal_set_message(t('Cron ran successfully'));
  1556. }
  1557. else {
  1558. drupal_set_message(t('Cron run failed'));
  1559. }
  1560. drupal_goto('admin/logs/status');
  1561. }
  1562. /**
  1563. * Menu callback: return information about PHP.
  1564. */
  1565. function system_php() {
  1566. phpinfo(INFO_GENERAL | INFO_CONFIGURATION);
  1567. exit();
  1568. }
  1569. function _system_sql($data, $keys) {
  1570. $rows = array();
  1571. foreach ($keys as $key => $explanation) {
  1572. if (isset($data[$key])) {
  1573. $rows[] = array(check_plain($key), check_plain($data[$key]), $explanation);
  1574. }
  1575. }
  1576. return theme('table', array(t('Variable'), t('Value'), t('Description')), $rows);
  1577. }
  1578. /**
  1579. * Menu callback: return information about PHP.
  1580. */
  1581. function system_sql() {
  1582. $result = db_query("SHOW STATUS");
  1583. while ($entry = db_fetch_object($result)) {
  1584. $data[$entry->Variable_name] = $entry->Value;
  1585. }
  1586. $output = '<h2>'. t('Command counters') .'</h2>';
  1587. $output .= _system_sql($data, array(
  1588. 'Com_select' => t('The number of <code>SELECT</code>-statements.'),
  1589. 'Com_insert' => t('The number of <code>INSERT</code>-statements.'),
  1590. 'Com_update' => t('The number of <code>UPDATE</code>-statements.'),
  1591. 'Com_delete' => t('The number of <code>DELETE</code>-statements.'),
  1592. 'Com_lock_tables' => t('The number of table locks.'),
  1593. 'Com_unlock_tables' => t('The number of table unlocks.')
  1594. ));
  1595. $output .= '<h2>'. t('Query performance') .'</h2>';
  1596. $output .= _system_sql($data, array(
  1597. 'Select_full_join' => t('The number of joins without an index; should be zero.'),
  1598. 'Select_range_check' => t('The number of joins without an index; should be zero.'),
  1599. 'Sort_scan' => t('The number of sorts done without using an index; should be zero.'),
  1600. 'Table_locks_immediate' => t('The number of times a lock could be acquired immediately.'),
  1601. 'Table_locks_waited' => t('The number of times the server had to wait for a lock.')
  1602. ));
  1603. $output .= '<h2>'. t('Query cache information') .'</h2>';
  1604. $output .= '<p>'. t('The MySQL query cache can improve performance of your site by storing the result of queries. Then, if an identical query is received later, the MySQL server retrieves the result from the query cache rather than parsing and executing the statement again.') .'</p>';
  1605. $output .= _system_sql($data, array(
  1606. 'Qcache_queries_in_cache' => t('The number of queries in the query cache.'),
  1607. 'Qcache_hits' => t('The number of times that MySQL found previous results in the cache.'),
  1608. 'Qcache_inserts' => t('The number of times that MySQL added a query to the cache (misses).'),
  1609. 'Qcache_lowmem_prunes' => t('The number of times that MySQL had to remove queries from the cache because it ran out of memory. Ideally should be zero.')
  1610. ));
  1611. return $output;
  1612. }
  1613. /**
  1614. * Menu callback: displays the site status report. Can also be used as a pure check.
  1615. *
  1616. * @param $check
  1617. * If true, only returns a boolean whether there are system status errors.
  1618. */
  1619. function system_status($check = FALSE) {
  1620. // Load .install files
  1621. include_once './includes/install.inc';
  1622. drupal_load_updates();
  1623. // Check run-time requirements and status information
  1624. $requirements = module_invoke_all('requirements', 'runtime');
  1625. usort($requirements, '_system_sort_requirements');
  1626. if ($check) {
  1627. return drupal_requirements_severity($requirements) == REQUIREMENT_ERROR;
  1628. }
  1629. return theme('status_report', $requirements);
  1630. }
  1631. /**
  1632. * Helper function to sort requirements.
  1633. */
  1634. function _system_sort_requirements($a, $b) {
  1635. return (isset($a['weight']) || isset($b['weight'])) ? $a['weight'] - $b['weight'] : strcmp($a['title'], $b['title']);
  1636. }
  1637. /**
  1638. * Theme status report
  1639. */
  1640. function theme_status_report(&$requirements) {
  1641. $i = 0;
  1642. $output = '<table class="system-status-report">';
  1643. foreach ($requirements as $requirement) {
  1644. if ($requirement['#type'] == '') {
  1645. $class = ++$i % 2 == 0 ? 'even' : 'odd';
  1646. $classes = array(
  1647. REQUIREMENT_INFO => 'info',
  1648. REQUIREMENT_OK => 'ok',
  1649. REQUIREMENT_WARNING => 'warning',
  1650. REQUIREMENT_ERROR => 'error',
  1651. );
  1652. $class = $classes[(int)$requirement['severity']] .' '. $class;
  1653. // Output table row(s)
  1654. if ($requirement['description']) {
  1655. $output .= '<tr class="'. $class .' merge-down"><th>'. $requirement['title'] .'</th><td>'. $requirement['value'] .'</td></tr>';
  1656. $output .= '<tr class="'. $class .' merge-up"><td colspan="2">'. $requirement['description'] .'</td></tr>';
  1657. }
  1658. else {
  1659. $output .= '<tr class="'. $class .'"><th>'. $requirement['title'] .'</th><td>'. $requirement['value'] .'</td></tr>';
  1660. }
  1661. }
  1662. }
  1663. $output .= '</table>';
  1664. return $output;
  1665. }
  1666. /**
  1667. * Menu callback; displays a module's settings page.
  1668. */
  1669. function system_settings_overview() {
  1670. // Check database setup if necessary
  1671. if (function_exists('db_check_setup') && empty($_POST)) {
  1672. db_check_setup();
  1673. }
  1674. $menu = menu_get_item(NULL, 'admin/settings');
  1675. $content = system_admin_menu_block($menu);
  1676. $output = theme('admin_block_content', $content);
  1677. return $output;
  1678. }
  1679. /**
  1680. * Menu callback; display theme configuration for entire site and individual themes.
  1681. */
  1682. function system_theme_settings($key = '') {
  1683. $directory_path = file_directory_path();
  1684. file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
  1685. // Default settings are defined in theme_get_settings() in includes/theme.inc
  1686. if ($key) {
  1687. $settings = theme_get_settings($key);
  1688. $var = str_replace('/', '_', 'theme_'. $key .'_settings');
  1689. $themes = system_theme_data();
  1690. $features = function_exists($themes[$key]->prefix .'_features') ? call_user_func($themes[$key]->prefix .'_features') : array();
  1691. }
  1692. else {
  1693. $settings = theme_get_settings('');
  1694. $var = 'theme_settings';
  1695. }
  1696. $form['var'] = array('#type' => 'hidden', '#value' => $var);
  1697. // Check for a new uploaded logo, and use that instead.
  1698. if ($file = file_check_upload('logo_upload')) {
  1699. if ($info = image_get_info($file->filepath)) {
  1700. $parts = pathinfo($file->filename);
  1701. $filename = ($key) ? str_replace('/', '_', $key) .'_logo.'. $parts['extension'] : 'logo.'. $parts['extension'];
  1702. if ($file = file_save_upload('logo_upload', $filename, 1)) {
  1703. $_POST['default_logo'] = 0;
  1704. $_POST['logo_path'] = $file->filepath;
  1705. $_POST['toggle_logo'] = 1;
  1706. }
  1707. }
  1708. else {
  1709. form_set_error('file_upload', t('Only JPEG, PNG and GIF images are allowed to be used as logos.'));
  1710. }
  1711. }
  1712. // Check for a new uploaded favicon, and use that instead.
  1713. if ($file = file_check_upload('favicon_upload')) {
  1714. $parts = pathinfo($file->filename);
  1715. $filename = ($key) ? str_replace('/', '_', $key) .'_favicon.'. $parts['extension'] : 'favicon.'. $parts['extension'];
  1716. if ($file = file_save_upload('favicon_upload', $filename, 1)) {
  1717. $_POST['default_favicon'] = 0;
  1718. $_POST['favicon_path'] = $file->filepath;
  1719. $_POST['toggle_favicon'] = 1;
  1720. }
  1721. }
  1722. // Toggle settings
  1723. $toggles = array(
  1724. 'toggle_logo' => t('Logo'),
  1725. 'toggle_name' => t('Site name'),
  1726. 'toggle_slogan' => t('Site slogan'),
  1727. 'toggle_mission' => t('Mission statement'),
  1728. 'toggle_node_user_picture' => t('User pictures in posts'),
  1729. 'toggle_comment_user_picture' => t('User pictures in comments'),
  1730. 'toggle_search' => t('Search box'),
  1731. 'toggle_favicon' => t('Shortcut icon')
  1732. );
  1733. // Some features are not always available
  1734. $disabled = array();
  1735. if (!variable_get('user_pictures', 0)) {
  1736. $disabled['toggle_node_user_picture'] = TRUE;
  1737. $disabled['toggle_comment_user_picture'] = TRUE;
  1738. }
  1739. if (!module_exists('search')) {
  1740. $disabled['toggle_search'] = TRUE;
  1741. }
  1742. $form['theme_settings'] = array(
  1743. '#type' => 'fieldset',
  1744. '#title' => t('Toggle display'),
  1745. '#description' => t('Enable or disable the display of certain page elements.'),
  1746. );
  1747. foreach ($toggles as $name => $title) {
  1748. if ((!$key) || in_array($name, $features)) {
  1749. // disable search box if search.module is disabled
  1750. $form['theme_settings'][$name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $settings[$name]);
  1751. if (isset($disabled[$name])) {
  1752. $form['theme_settings'][$name]['#disabled'] = TRUE;
  1753. }
  1754. }
  1755. }
  1756. // System wide only settings.
  1757. if (!$key) {
  1758. // Create neat 2-column layout for the toggles
  1759. $form['theme_settings'] += array(
  1760. '#prefix' => '<div class="theme-settings-left">',
  1761. '#suffix' => '</div>',
  1762. );
  1763. // Toggle node display.
  1764. $node_types = node_get_types('names');
  1765. if ($node_types) {
  1766. $form['node_info'] = array(
  1767. '#type' => 'fieldset',
  1768. '#title' => t('Display post information on'),
  1769. '#description' => t('Enable or disable the <em>submitted by Username on date</em> text when displaying posts of the following type.'),
  1770. '#prefix' => '<div class="theme-settings-right">',
  1771. '#suffix' => '</div>',
  1772. );
  1773. foreach ($node_types as $type => $name) {
  1774. $form['node_info']["toggle_node_info_$type"] = array('#type' => 'checkbox', '#title' => check_plain($name), '#default_value' => $settings["toggle_node_info_$type"]);
  1775. }
  1776. }
  1777. }
  1778. // Logo settings
  1779. if ((!$key) || in_array('toggle_logo', $features)) {
  1780. $form['logo'] = array(
  1781. '#type' => 'fieldset',
  1782. '#title' => t('Logo image settings'),
  1783. '#description' => t('If toggled on, the following logo will be displayed.'),
  1784. '#attributes' => array('class' => 'theme-settings-bottom'),
  1785. );
  1786. $form['logo']["default_logo"] = array(
  1787. '#type' => 'checkbox',
  1788. '#title' => t('Use the default logo'),
  1789. '#default_value' => $settings['default_logo'],
  1790. '#tree' => FALSE,
  1791. '#description' => t('Check here if you want the theme to use the logo supplied with it.')
  1792. );
  1793. $form['logo']['logo_path'] = array(
  1794. '#type' => 'textfield',
  1795. '#title' => t('Path to custom logo'),
  1796. '#default_value' => $settings['logo_path'],
  1797. '#description' => t('The path to the file you would like to use as your logo file instead of the default logo.'));
  1798. $form['logo']['logo_upload'] = array(
  1799. '#type' => 'file',
  1800. '#title' => t('Upload logo image'),
  1801. '#maxlength' => 40,
  1802. '#description' => t("If you don't have direct file access to the server, use this field to upload your logo.")
  1803. );
  1804. }
  1805. // Icon settings
  1806. if ((!$key) || in_array('toggle_favicon', $features)) {
  1807. $form['favicon'] = array(
  1808. '#type' => 'fieldset',
  1809. '#title' => t('Shortcut icon settings'),
  1810. '#description' => t("Your shortcut icon or 'favicon' is displayed in the address bar and bookmarks of most browsers.")
  1811. );
  1812. $form['favicon']['default_favicon'] = array(
  1813. '#type' => 'checkbox',
  1814. '#title' => t('Use the default shortcut icon.'),
  1815. '#default_value' => $settings['default_favicon'],
  1816. '#description' => t('Check here if you want the theme to use the default shortcut icon.')
  1817. );
  1818. $form['favicon']['favicon_path'] = array(
  1819. '#type' => 'textfield',
  1820. '#title' => t('Path to custom icon'),
  1821. '#default_value' => $settings['favicon_path'],
  1822. '#description' => t('The path to the image file you would like to use as your custom shortcut icon.')
  1823. );
  1824. $form['favicon']['favicon_upload'] = array(
  1825. '#type' => 'file',
  1826. '#title' => t('Upload icon image'),
  1827. '#description' => t("If you don't have direct file access to the server, use this field to upload your shortcut icon.")
  1828. );
  1829. }
  1830. if ($key) {
  1831. // Template-specific settings
  1832. $function = $themes[$key]->prefix .'_settings';
  1833. if (function_exists($function)) {
  1834. if ($themes[$key]->template) {
  1835. // file is a template or a style of a template
  1836. $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)));
  1837. }
  1838. else {
  1839. // file is a theme or a style of a theme
  1840. $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)));
  1841. }
  1842. $group = $function();
  1843. $form['specific'] = array_merge($form['specific'], (is_array($group) ? $group : array()));
  1844. }
  1845. }
  1846. $form['#attributes'] = array('enctype' => 'multipart/form-data');
  1847. return system_settings_form($form);
  1848. }
  1849. /**
  1850. * Implementation of hook_node_type().
  1851. *
  1852. * Updates theme settings after a node type change.
  1853. */
  1854. function system_node_type($op, $info) {
  1855. if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) {
  1856. $old = 'toggle_node_info_'. $info->old_type;
  1857. $new = 'toggle_node_info_'. $info->type;
  1858. $theme_settings = variable_get('theme_settings', array());
  1859. if (isset($theme_settings[$old])) {
  1860. $theme_settings[$new] = $theme_settings[$old];
  1861. unset($theme_settings[$old]);
  1862. variable_set('theme_settings', $theme_settings);
  1863. }
  1864. }
  1865. }
  1866. /**
  1867. * Output a confirmation form
  1868. *
  1869. * This function returns a complete form for confirming an action. A link is
  1870. * offered to go back to the item that is being changed in case the user
  1871. * changes his/her mind.
  1872. *
  1873. * If the submit handler for this form is invoked, the user successfully
  1874. * confirmed the action. You should never directly inspect $_POST to see if an
  1875. * action was confirmed.
  1876. *
  1877. * @param $form
  1878. * Additional elements to inject into the form, for example hidden elements.
  1879. * @param $question
  1880. * The question to ask the user (e.g. "Are you sure you want to delete the
  1881. * block <em>foo</em>?").
  1882. * @param $path
  1883. * The page to go to if the user denies the action.
  1884. * Can be either a drupal path, or an array with the keys 'path', 'query', 'fragment'.
  1885. * @param $description
  1886. * Additional text to display (defaults to "This action cannot be undone.").
  1887. * @param $yes
  1888. * A caption for the button which confirms the action (e.g. "Delete",
  1889. * "Replace", ...).
  1890. * @param $no
  1891. * A caption for the link which denies the action (e.g. "Cancel").
  1892. * @param $name
  1893. * The internal name used to refer to the confirmation item.
  1894. * @return
  1895. * The form.
  1896. */
  1897. function confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm') {
  1898. $description = isset($description) ? $description : t('This action cannot be undone.');
  1899. // Prepare cancel link
  1900. $query = $fragment = NULL;
  1901. if (is_array($path)) {
  1902. $query = isset($path['query']) ? $path['query'] : NULL;
  1903. $fragment = isset($path['fragment']) ? $path['fragment'] : NULL;
  1904. $path = isset($path['path']) ? $path['path'] : NULL;
  1905. }
  1906. $cancel = l($no ? $no : t('Cancel'), $path, array(), $query, $fragment);
  1907. drupal_set_title($question);
  1908. $form['#attributes'] = array('class' => 'confirmation');
  1909. $form['description'] = array('#value' => $description);
  1910. $form[$name] = array('#type' => 'hidden', '#value' => 1);
  1911. $form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
  1912. $form['actions']['submit'] = array('#type' => 'submit', '#value' => $yes ? $yes : t('Confirm'));
  1913. $form['actions']['cancel'] = array('#value' => $cancel);
  1914. $form['#base'] = 'confirm_form';
  1915. return $form;
  1916. }
  1917. /**
  1918. * Determine if a user is in compact mode.
  1919. */
  1920. function system_admin_compact_mode() {
  1921. global $user;
  1922. return (isset($user->admin_compact_mode)) ? $user->admin_compact_mode : variable_get('admin_compact_mode', FALSE);
  1923. }
  1924. /**
  1925. * This function formats an administrative page for viewing.
  1926. *
  1927. * @param $blocks
  1928. * An array of blocks to display. Each array should include a
  1929. * 'title', a 'description', a formatted 'content' and a
  1930. * 'position' which will control which container it will be
  1931. * in. This is usually 'left' or 'right'.
  1932. * @themeable
  1933. */
  1934. function theme_admin_page($blocks) {
  1935. $stripe = 0;
  1936. $container = array();
  1937. foreach ($blocks as $block) {
  1938. if ($block_output = theme('admin_block', $block)) {
  1939. if (!$block['position']) {
  1940. // perform automatic striping.
  1941. $block['position'] = $stripe++ % 2 ? 'left' : 'right';
  1942. }
  1943. $container[$block['position']] .= $block_output;
  1944. }
  1945. }
  1946. $output = '<div class="admin clear-block">';
  1947. $output .= '<div class="compact-link">';
  1948. if (system_admin_compact_mode()) {
  1949. $output .= l(t('Show descriptions'), 'admin/compact/off', array('title' => t('Produce a less compact layout that includes descriptions.')));
  1950. }
  1951. else {
  1952. $output .= l(t('Hide descriptions'), 'admin/compact/on', array('title' => t("Produce a more compact layout that doesn't include descriptions.")));
  1953. }
  1954. $output .= '</div>';
  1955. foreach ($container as $id => $data) {
  1956. $output .= '<div class="'. $id .' clear-block">';
  1957. $output .= $data;
  1958. $output .= '</div>';
  1959. }
  1960. $output .= '</div>';
  1961. return $output;
  1962. }
  1963. /**
  1964. * This function formats an administrative block for display.
  1965. *
  1966. * @param $block
  1967. * An array containing information about the block. It should
  1968. * include a 'title', a 'description' and a formatted 'content'.
  1969. * @themeable
  1970. */
  1971. function theme_admin_block($block) {
  1972. // Don't display the block if it has no content to display.
  1973. if (!$block['content']) {
  1974. return '';
  1975. }
  1976. $output = <<< EOT
  1977. <div class="admin-panel">
  1978. <h3>
  1979. $block[title]
  1980. </h3>
  1981. <div class="body">
  1982. <p class="description">
  1983. $block[description]
  1984. </p>
  1985. $block[content]
  1986. </div>
  1987. </div>
  1988. EOT;
  1989. return $output;
  1990. }
  1991. /**
  1992. * This function formats the content of an administrative block.
  1993. *
  1994. * @param $block
  1995. * An array containing information about the block. It should
  1996. * include a 'title', a 'description' and a formatted 'content'.
  1997. * @themeable
  1998. */
  1999. function theme_admin_block_content($content) {
  2000. if (!$content) {
  2001. return '';
  2002. }
  2003. if (system_admin_compact_mode()) {
  2004. $output = '<ul class="menu">';
  2005. foreach ($content as $item) {
  2006. $output .= '<li class="leaf">'. l($item['title'], $item['path'], array('title' => $item['description'])) .'</li>';
  2007. }
  2008. $output .= '</ul>';
  2009. }
  2010. else {
  2011. $output = '<dl class="admin-list">';
  2012. foreach ($content as $item) {
  2013. $output .= '<dt>'. l($item['title'], $item['path']) .'</dt>';
  2014. $output .= '<dd>'. $item['description'] .'</dd>';
  2015. }
  2016. $output .= '</dl>';
  2017. }
  2018. return $output;
  2019. }
  2020. /**
  2021. * Menu callback; prints a listing of admin tasks for each installed module.
  2022. */
  2023. function system_admin_by_module() {
  2024. $modules = module_rebuild_cache();
  2025. $menu_items = array();
  2026. foreach ($modules as $file) {
  2027. $module = $file->name;
  2028. if ($module == 'help') {
  2029. continue;
  2030. }
  2031. $admin_tasks = system_get_module_admin_tasks($module);
  2032. // Only display a section if there are any available tasks.
  2033. if (count($admin_tasks)) {
  2034. // Check for help links.
  2035. if (module_invoke($module, 'help', "admin/help#$module")) {
  2036. $admin_tasks[100] = l(t('Get help'), "admin/help/$module");
  2037. }
  2038. // Sort.
  2039. ksort($admin_tasks);
  2040. $menu_items[$file->info['name']] = array($file->info['description'], $admin_tasks);
  2041. }
  2042. }
  2043. return theme('system_admin_by_module', $menu_items);
  2044. }
  2045. function system_get_module_admin_tasks($module) {
  2046. $admin_access = user_access('administer access control');
  2047. $menu = menu_get_menu();
  2048. $admin_tasks = array();
  2049. // Check for permissions.
  2050. if (module_hook($module, 'perm') && $admin_access) {
  2051. $admin_tasks[-1] = l(t('Configure permissions'), 'admin/user/access', NULL, NULL, 'module-'. $module);
  2052. }
  2053. // Check for menu items that are admin links.
  2054. if ($items = module_invoke($module, 'menu', TRUE)) {
  2055. foreach ($items as $item) {
  2056. $parts = explode('/', $item['path']);
  2057. $n = count($parts);
  2058. if ((!isset($item['type']) || ($item['type'] & MENU_VISIBLE_IN_TREE)) && ($parts[0] == 'admin') && ($n >= 3) && _menu_item_is_accessible($menu['path index'][$item['path']])) {
  2059. $admin_tasks[$item['title']] = l($item['title'], $item['path']);
  2060. }
  2061. }
  2062. }
  2063. return $admin_tasks;
  2064. }
  2065. /**
  2066. * Theme output of the dashboard page.
  2067. */
  2068. function theme_system_admin_by_module($menu_items) {
  2069. $stripe = 0;
  2070. $output = '';
  2071. $container = array();
  2072. // Iterate over all modules
  2073. foreach ($menu_items as $module => $block) {
  2074. list($description, $items) = $block;
  2075. // Output links
  2076. if (count($items)) {
  2077. $block = array();
  2078. $block['title'] = $module;
  2079. $block['content'] = theme('item_list', $items);
  2080. $block['description'] = t($description);
  2081. if ($block_output = theme('admin_block', $block)) {
  2082. if (!$block['position']) {
  2083. // Perform automatic striping.
  2084. $block['position'] = ++$stripe % 2 ? 'left' : 'right';
  2085. }
  2086. $container[$block['position']] .= $block_output;
  2087. }
  2088. }
  2089. }
  2090. $output = '<div class="admin clear-block">';
  2091. foreach ($container as $id => $data) {
  2092. $output .= '<div class="'. $id .' clear-block">';
  2093. $output .= $data;
  2094. $output .= '</div>';
  2095. }
  2096. $output .= '</div>';
  2097. return $output;
  2098. }

Functions

Namesort descending Description
confirm_form Output a confirmation form
system_admin_by_module Menu callback; prints a listing of admin tasks for each installed module.
system_admin_compact_mode Determine if a user is in compact mode.
system_admin_compact_page
system_admin_menu_block Provide a single block on the administration overview page.
system_admin_menu_block_page Provide a single block from the administration menu as a page. This function is often a destination for these blocks. For example, 'admin/content/types' needs to have a destination to be valid in the Drupal menu system, but too much…
system_admin_theme_settings This function allows selection of the theme to show in administration sections.
system_admin_theme_submit
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_clean_url_settings
system_date_time_settings
system_default_region Get the name of the default region for a given theme.
system_elements Implementation of hook_elements().
system_error_reporting_settings
system_file_system_settings
system_get_files_database Retrieves the current status of an array of files in the system table.
system_get_module_admin_tasks
system_help Implementation of hook_help().
system_image_toolkit_settings
system_initialize_theme_blocks Assign an initial, default set of blocks for a theme.
system_main_admin_page Provide the administration overview page.
system_menu Implementation of hook_menu().
system_modules Menu callback; provides module enable/disable interface.
system_modules_confirm_form
system_modules_disable Form process callback function to disable check boxes.
system_modules_submit Submit callback; handles modules form submission.
system_modules_uninstall Builds a form of currently disabled modules.
system_modules_uninstall_confirm_form Confirm uninstall of selected modules.
system_modules_uninstall_submit Processes the submitted uninstall form.
system_modules_uninstall_validate Validates the submitted uninstall form.
system_module_build_dependencies
system_node_type Implementation of hook_node_type().
system_performance_settings
system_perm Implementation of hook_perm().
system_php Menu callback: return information about PHP.
system_region_list Get a list of available regions from a specified theme.
system_rss_feeds_settings
system_run_cron Menu callback: run cron manually.
system_settings_form Add default buttons to a form and set its prefix
system_settings_form_submit Execute the system_settings_form.
system_settings_overview Menu callback; displays a module's settings page.
system_site_information_settings
system_site_maintenance_settings
system_sort_modules_by_info_name
system_sql Menu callback: return information about PHP.
system_status Menu callback: displays the site status report. Can also be used as a pure check.
system_themes Menu callback; displays a listing of all themes.
system_themes_submit
system_theme_data Collect data about all currently available themes
system_theme_select_form Returns a fieldset containing the theme select form.
system_theme_settings Menu callback; display theme configuration for entire site and individual themes.
system_theme_settings_submit
system_user Implementation of hook_user().
theme_admin_block This function formats an administrative block for display.
theme_admin_block_content This function formats the content of an administrative block.
theme_admin_page This function formats an administrative page for viewing.
theme_status_report Theme status report
theme_system_admin_by_module Theme output of the dashboard page.
theme_system_modules Theme call back for the modules form.
theme_system_modules_uninstall Themes a table of currently disabled modules.
theme_system_themes
theme_system_theme_select_form
_system_sort_requirements Helper function to sort requirements.
_system_sql
_system_zonelist

Constants

Namesort descending Description
VERSION