system.variable.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <?php
  2. /**
  3. * @file
  4. * Variable API module. Definition for Drupal core variables
  5. */
  6. /**
  7. * Implements hook_variable_info().
  8. */
  9. function system_variable_info($options) {
  10. // Site configuration, site information
  11. $variables['site_name'] = array(
  12. 'type' => 'string',
  13. 'title' => t('Site name', array(), $options),
  14. 'default' => 'Drupal',
  15. 'description' => t('The name of this website.', array(), $options),
  16. 'required' => TRUE,
  17. 'group' => 'site_information',
  18. );
  19. $variables['site_mail'] = array(
  20. 'type' => 'mail_address',
  21. 'title' => t('Site email address', array(), $options),
  22. 'default' => ini_get('sendmail_from'),
  23. 'description' => t("The <em>From</em> address in automated e-mails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this e-mail being flagged as spam.)", array(), $options),
  24. 'required' => TRUE,
  25. 'group' => 'site_information',
  26. );
  27. $variables['site_slogan'] = array(
  28. 'type' => 'text',
  29. 'title' => t('Site slogan', array(), $options),
  30. 'default' => '',
  31. 'description' => t("Your site's motto, tag line, or catchphrase (often displayed alongside the title of the site).", array(), $options),
  32. 'group' => 'site_information',
  33. );
  34. $variables['anonymous'] = array(
  35. 'type' => 'string',
  36. 'title' => t('Anonymous user', array(), $options),
  37. 'default' => t('Anonymous', array(), $options),
  38. 'description' => t('The name used to indicate anonymous users.', array(), $options),
  39. 'required' => TRUE,
  40. 'group' => 'site_information',
  41. );
  42. $variables['site_frontpage'] = array(
  43. 'type' => 'drupal_path',
  44. 'title' => t('Default front page', array(), $options),
  45. 'default' => 'node',
  46. 'description' => t('The home page displays content from this relative URL. If unsure, specify "node".', array(), $options),
  47. 'required' => TRUE,
  48. 'group' => 'site_information',
  49. );
  50. $variables['default_nodes_main'] = array(
  51. 'type' => 'select_number',
  52. 'title' => t('Number of posts on main page', array(), $options),
  53. 'default' => 10,
  54. 'options' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30),
  55. 'description' => t('The maximum number of posts displayed on overview pages such as the front page.', array(), $options),
  56. 'group' => 'site_information',
  57. );
  58. $variables['site_403'] = array(
  59. 'type' => 'drupal_path',
  60. 'title' => t('Default 403 (access denied) page', array(), $options),
  61. 'default' => '',
  62. 'description' => t('This page is displayed when the requested document is denied to the current user. Leave blank to display a generic "access denied" page.', array(), $options),
  63. 'group' => 'site_information',
  64. );
  65. $variables['site_404'] = array(
  66. 'type' => 'drupal_path',
  67. 'title' => t('Default 404 (not found) page', array(), $options),
  68. 'default' => '',
  69. 'description' => t('This page is displayed when no other content matches the requested document. Leave blank to display a generic "page not found" page.', array(), $options),
  70. 'group' => 'site_information',
  71. );
  72. // Feed settings. Group 'feed_settings'.
  73. $variables['feed_description'] = array(
  74. 'type' => 'text',
  75. 'title' => t('Feed description'),
  76. 'default' => '',
  77. 'description' => t('Description of your site, included in each feed.', array(), $options),
  78. 'group' => 'feed_settings',
  79. );
  80. $variables['feed_default_items'] = array(
  81. 'type' => 'select_number',
  82. 'title' => t('Number of items in each feed'),
  83. 'default' => 10,
  84. 'options' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30),
  85. 'description' => t('Default number of items to include in each feed.', array(), $options),
  86. 'group' => 'feed_settings',
  87. );
  88. $variables['feed_item_length'] = array(
  89. 'type' => 'select',
  90. 'title' => t('Feed content'),
  91. 'default' => 'fulltext',
  92. 'options' => array(
  93. 'title' => t('Titles only', array(), $options),
  94. 'teaser' => t('Titles plus teaser', array(), $options),
  95. 'fulltext' => t('Full text', array(), $options)
  96. ),
  97. 'description' => t('Global setting for the default display of content items in each feed.', array(), $options),
  98. 'group' => 'feed_settings',
  99. );
  100. // Regional settings. Group 'regional_settings'.
  101. $variables['site_default_country'] = array(
  102. 'type' => 'select',
  103. 'options' => 'country',
  104. 'title' => t('Default country', array(), $options),
  105. 'element' => array('#type' => 'select', '#attributes' => array('class' => array('country-detect'))),
  106. 'group' => 'regional_settings',
  107. );
  108. $variables['date_first_day'] = array(
  109. 'type' => 'select',
  110. 'options' => 'weekday',
  111. 'title' => t('First day of week', array(), $options),
  112. 'default' => 0,
  113. 'localize' => TRUE,
  114. 'group' => 'regional_settings',
  115. );
  116. $variables['date_default_timezone'] = array(
  117. 'type' => 'select',
  118. 'options' => 'timezone',
  119. 'title' => t('Default time zone', array(), $options),
  120. 'default callback' => 'date_default_timezone_get',
  121. 'group' => 'regional_settings',
  122. );
  123. $variables['configurable_timezones'] = array(
  124. 'type' => 'boolean',
  125. 'title' => t('Users may set their own time zone.', array(), $options),
  126. 'default' => 1,
  127. 'group' => 'regional_settings',
  128. );
  129. $variables['empty_timezone_message'] = array(
  130. 'type' => 'boolean',
  131. 'title' => t('Remind users at login if their time zone is not set.', array(), $options),
  132. 'default' => 0,
  133. 'description' => t('Only applied if users may set their own time zone.', array(), $options),
  134. 'group' => 'regional_settings',
  135. );
  136. $variables['user_default_timezone'] = array(
  137. 'type' => 'select',
  138. 'title' => t('Time zone for new users'),
  139. 'default' => DRUPAL_USER_TIMEZONE_DEFAULT,
  140. 'options' => array(
  141. DRUPAL_USER_TIMEZONE_DEFAULT => t('Default time zone.', array(), $options),
  142. DRUPAL_USER_TIMEZONE_EMPTY => t('Empty time zone.', array(), $options),
  143. DRUPAL_USER_TIMEZONE_SELECT => t('Users may set their own time zone at registration.', array(), $options),
  144. ),
  145. 'description' => t('Only applied if users may set their own time zone.', array(), $options),
  146. 'localize' => TRUE,
  147. 'group' => 'regional_settings',
  148. );
  149. $variables['date_format_[date_type]'] = array(
  150. 'type' => 'multiple',
  151. 'title' => t('Date format'),
  152. 'repeat' => array(
  153. 'type' => 'select',
  154. 'options' => 'date_format',
  155. ),
  156. 'group' => 'regional_settings',
  157. );
  158. // Maintenance mode. Group 'site_information'
  159. $variables['maintenance_mode'] = array(
  160. 'type' => 'boolean',
  161. 'title' => t('Put site into maintenance mode', array(), $options),
  162. 'default' => 0,
  163. 'description' => t('When enabled, only users with the "Use the site in maintenance mode" <a href="@permissions-url">permission</a> are able to access your site to perform maintenance; all other visitors see the maintenance mode message configured below. Authorized users can log in directly via the <a href="@user-login">user login</a> page.', array('@permissions-url' => url('admin/people/permissions'), '@user-login' => url('user')), $options),
  164. 'group' => 'site_information'
  165. );
  166. $variables['maintenance_mode_message'] = array(
  167. 'type' => 'text',
  168. 'title' => t('Maintenance mode message', array(), $options),
  169. 'default' => t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')), $options),
  170. 'description' => t('Message to show visitors when the site is in maintenance mode.', array(), $options),
  171. 'group' => 'site_information'
  172. );
  173. // Theme settings, we may want to localize the logo. Group 'theme_settings'
  174. $variables['theme_settings'] = array(
  175. 'type' => 'properties',
  176. 'title' => t('Global theme settings.', array(), $options),
  177. 'group' => 'theme_settings',
  178. 'default callback' => 'system_variable_theme_defaults',
  179. 'localize' => TRUE,
  180. 'group' => 'theme_settings',
  181. );
  182. $variables['theme_[theme]_settings'] = array(
  183. 'type' => 'multiple',
  184. 'multiple' => 'theme',
  185. 'title' => t('Theme settings', array(), $options),
  186. 'description' => t('Logo, icons and other specific theme settings.', array(), $options),
  187. 'repeat' => array(
  188. 'type' => 'properties',
  189. 'default callback' => 'system_variable_theme_defaults',
  190. ),
  191. 'group' => 'theme_settings',
  192. 'localize' => TRUE,
  193. );
  194. // Performance options, changing them may need some extra cache refresh.
  195. $variables['cache'] = array(
  196. 'type' => 'boolean',
  197. 'title' => t('Cache pages for anonymous users', array(), $options),
  198. 'default' => 0,
  199. 'group' => 'system_performance',
  200. );
  201. // This one belongs to a different module, block, but it won't do any harm having it here.
  202. $variables['block_cache'] = array(
  203. 'type' => 'boolean',
  204. 'title' => t('Cache blocks'),
  205. 'default' => FALSE,
  206. 'description' => t('Block caching is inactive if you have enabled modules defining content access restrictions.', array(), $options),
  207. 'group' => 'system_performance',
  208. );
  209. $interval = array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400);
  210. $variables['cache_lifetime'] = array(
  211. 'type' => 'time_interval',
  212. 'title' => t('Minimum cache lifetime', array(), $options),
  213. 'default' => 0,
  214. 'interval values' => $interval,
  215. 'description' => t('Cached pages will not be re-created until at least this much time has elapsed.', array(), $options),
  216. 'group' => 'system_performance',
  217. );
  218. $variables['page_cache_maximum_age'] = array(
  219. 'type' => 'time_interval',
  220. 'title' => t('Expiration of cached pages', array(), $options),
  221. 'default' => 0,
  222. 'interval values' => $interval,
  223. 'description' => t('The maximum time an external cache can use an old version of a page.', array(), $options),
  224. 'group' => 'system_performance',
  225. );
  226. $description = t('External resources can be optimized automatically, which can reduce both the size and number of requests made to your website.', array(), $options);
  227. $variables['page_compression'] = array(
  228. 'type' => 'enable',
  229. 'title' => t('Compress cached pages.', array(), $options),
  230. 'description' => $description,
  231. 'default' => TRUE,
  232. 'group' => 'system_performance',
  233. );
  234. $variables['preprocess_css'] = array(
  235. 'type' => 'boolean',
  236. 'title' => t('Aggregate and compress CSS files.'),
  237. 'description' => $description,
  238. 'default' => 0,
  239. 'group' => 'system_performance',
  240. );
  241. $variables['preprocess_js'] = array(
  242. 'type' => 'boolean',
  243. 'title' => t('Aggregate JavaScript files.'),
  244. 'description' => $description,
  245. 'default' => 0,
  246. 'group' => 'system_performance',
  247. );
  248. return $variables;
  249. }
  250. /**
  251. * Implements hook_variable_group_info().
  252. */
  253. function system_variable_group_info() {
  254. $groups['site_information'] = array(
  255. 'title' => t('Site information'),
  256. 'description' => t('Site information and maintenance mode'),
  257. 'access' => 'administer site configuration',
  258. 'path' => array('admin/config/system/site-information', 'admin/config/development/maintenance'),
  259. );
  260. $groups['feed_settings'] = array(
  261. 'title' => t('Feed settings'),
  262. 'description' => t('Feed settings'),
  263. 'access' => 'administer site configuration',
  264. );
  265. $groups['regional_settings'] = array(
  266. 'title' => t('Regional settings'),
  267. 'description' => t('Regional settings'),
  268. 'access' => 'administer site configuration',
  269. );
  270. $groups['theme_settings'] = array(
  271. 'title' => t('Theme settings'),
  272. 'description' => t('Theme settings'),
  273. 'access' => 'administer site configuration',
  274. );
  275. $groups['system_performance'] = array(
  276. 'title' => t('System performance'),
  277. 'description' => t('Options related with cache, file compression and bandwidth optimization.'),
  278. 'access' => 'administer site configuration',
  279. 'path' => 'admin/config/development/performance',
  280. );
  281. return $groups;
  282. }
  283. /**
  284. * Implements hook_variable_type_info().
  285. */
  286. function system_variable_type_info() {
  287. // Internal Drupal path as used by menu items.
  288. $type['drupal_path'] = array(
  289. 'title' => t('Drupal path'),
  290. 'element callback' => 'system_variable_path_element',
  291. 'localize' => TRUE,
  292. );
  293. // File system path, relative to Drupal installation.
  294. $type['file_path'] = array(
  295. 'title' => t('File path'),
  296. 'default' => conf_path() . '/files',
  297. 'element' => array('#type' => 'textfield', '#maxlength' => 255, '#after_build' => array('system_check_directory')),
  298. );
  299. // These are just for option lists though they can be used as variable type to have a selectable value.
  300. $type['weekday'] = array(
  301. 'title' => t('Day of week'),
  302. 'type' => 'select',
  303. 'options callback' => 'system_variable_option_weekday',
  304. );
  305. $type['theme'] = array(
  306. 'title' => t('Theme'),
  307. 'type' => 'select',
  308. 'options callback' => 'system_variable_option_theme',
  309. 'cache' => TRUE,
  310. );
  311. $type['country'] = array(
  312. 'title' => t('Country'),
  313. 'type' => 'select',
  314. 'options callback' => 'system_variable_option_country',
  315. 'cache' => TRUE,
  316. );
  317. $type['timezone'] = array(
  318. 'title' => t('Time zone'),
  319. 'type' => 'select',
  320. 'options callback' => 'system_time_zones',
  321. 'cache' => TRUE,
  322. );
  323. $type['date_type'] = array(
  324. 'title' => t('Date type'),
  325. 'type' => 'select',
  326. 'options callback' => 'system_variable_option_date_type',
  327. );
  328. $type['date_format'] = array(
  329. 'title' => t('Date format'),
  330. 'type' => 'select',
  331. 'options callback' => 'system_variable_option_date_format',
  332. );
  333. $type['time_interval'] = array(
  334. 'title' => t('Time interval'),
  335. 'type' => 'select',
  336. 'options callback' => 'system_variable_option_time_interval',
  337. );
  338. return $type;
  339. }
  340. /**
  341. * Callback for theme options
  342. */
  343. function system_variable_option_theme($variable, $options) {
  344. $list = array();
  345. foreach (list_themes() as $theme) {
  346. $list[$theme->name] = $theme->info['name'];
  347. }
  348. return $list;
  349. }
  350. /**
  351. * Callback for weekday options
  352. */
  353. function system_variable_option_weekday($variable, $options) {
  354. return array(
  355. 0 => t('Sunday', array(), $options),
  356. 1 => t('Monday', array(), $options),
  357. 2 => t('Tuesday', array(), $options),
  358. 3 => t('Wednesday', array(), $options),
  359. 4 => t('Thursday', array(), $options),
  360. 5 => t('Friday', array(), $options),
  361. 6 => t('Saturday', array(), $options)
  362. );
  363. }
  364. /**
  365. * Callback for date types
  366. */
  367. function system_variable_option_date_type($variable, $options) {
  368. $list = array();
  369. foreach (system_get_date_types() as $type => $info) {
  370. $list[$type] = check_plain($info['title']);
  371. }
  372. return $list;
  373. }
  374. /**
  375. * Callback for date types
  376. *
  377. * @todo These should be different for some variables
  378. */
  379. function system_variable_option_date_format($variable, $options) {
  380. // Get list of all available date formats.
  381. $all_formats = array();
  382. foreach (system_get_date_formats() as $type => $format_info) {
  383. $all_formats = array_merge($all_formats, $format_info);
  384. }
  385. if ($custom_formats = system_get_date_formats('custom')) {
  386. $all_formats = array_merge($all_formats, $custom_formats);
  387. }
  388. foreach ($all_formats as $f => $format) {
  389. $list[$f] = format_date(REQUEST_TIME, 'custom', $f);
  390. }
  391. return $list;
  392. }
  393. /**
  394. * Callback for country options
  395. */
  396. function system_variable_option_country($variable, $options) {
  397. include_once DRUPAL_ROOT . '/includes/locale.inc';
  398. return country_get_list();
  399. }
  400. /**
  401. * Callback for time interval options
  402. */
  403. function system_variable_option_time_interval($variable, $options) {
  404. $period = drupal_map_assoc($variable['interval values'], 'format_interval');
  405. if (isset($period[0])) {
  406. $period[0] = '<' . t('none') . '>';
  407. }
  408. return $period;
  409. }
  410. /**
  411. * Callback for default theme settings
  412. */
  413. function system_variable_theme_defaults($variable, $options) {
  414. return array(
  415. 'default_logo' => 1,
  416. 'logo_path' => '',
  417. 'default_favicon' => 1,
  418. 'favicon_path' => '',
  419. 'favicon_mimetype' => 'image/vnd.microsoft.icon',
  420. );
  421. }
  422. /**
  423. * Callback for path variable element
  424. */
  425. function system_variable_path_element($variable, $options) {
  426. $element = variable_form_element_default($variable, $options) +array(
  427. '#type' => 'textfield',
  428. '#size' => 40,
  429. '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
  430. );
  431. return $element;
  432. }