Projet

Général

Profil

Paste
Télécharger (16 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / variable / includes / system.variable.inc @ 13755f8d

1
<?php
2
/**
3
 * @file
4
 * Variable API module. Definition for Drupal core variables
5
 */
6

    
7
/**
8
 * Implements hook_variable_info().
9
 */
10
function system_variable_info($options) {
11
  // Site configuration, site information
12
  $variables['site_name'] = array(
13
    'type' => 'string',
14
    'title' => t('Site name', array(), $options),
15
    'default' => 'Drupal',
16
    'description' => t('The name of this website.', array(), $options),
17
    'required' => TRUE,
18
    'group' => 'site_information',
19
  );
20
  $variables['site_mail'] = array(
21
    'type' => 'mail_address',
22
    'title' => t('Site email address', array(), $options),
23
    'default' => ini_get('sendmail_from'),
24
    '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),
25
    'required' => TRUE,
26
    'group' => 'site_information',
27
  );
28
  $variables['site_slogan'] = array(
29
    'type' => 'text',
30
    'title' => t('Site slogan', array(), $options),
31
    'default' => '',
32
    'description' => t("Your site's motto, tag line, or catchphrase (often displayed alongside the title of the site).", array(), $options),
33
    'group' => 'site_information',
34
  );
35
  $variables['anonymous'] = array(
36
    'type' => 'string',
37
    'title' => t('Anonymous user', array(), $options),
38
    'default' => t('Anonymous', array(), $options),
39
    'description' => t('The name used to indicate anonymous users.', array(), $options),
40
    'required' => TRUE,
41
    'group' => 'site_information',
42
  );
43
  $variables['site_frontpage'] = array(
44
    'type' => 'drupal_path',
45
    'title' => t('Default front page', array(), $options),
46
    'default' => 'node',
47
    'description' => t('The home page displays content from this relative URL. If unsure, specify "node".', array(), $options),
48
    'required' => TRUE,
49
    'group' => 'site_information',
50
  );
51
  $variables['default_nodes_main'] = array(
52
    'type' => 'select_number',
53
    'title' => t('Number of posts on main page', array(), $options),
54
    'default' => 10,
55
    'options' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30),
56
    'description' => t('The maximum number of posts displayed on overview pages such as the front page.', array(), $options),
57
    'group' => 'site_information',
58
  );
59

    
60
  $variables['site_403'] = array(
61
    'type' => 'drupal_path',
62
    'title' => t('Default 403 (access denied) page', array(), $options),
63
    'default' => '',
64
    '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),
65
    'group' => 'site_information',
66
  );
67
  $variables['site_404'] = array(
68
    'type' => 'drupal_path',
69
    'title' => t('Default 404 (not found) page', array(), $options),
70
    'default' => '',
71
    '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),
72
    'group' => 'site_information',
73
  );
74

    
75
  // Feed settings. Group 'feed_settings'.
76
  $variables['feed_description'] = array(
77
    'type' => 'text',
78
    'title' => t('Feed description'),
79
    'default' => '',
80
    'description' => t('Description of your site, included in each feed.', array(), $options),
81
    'group' => 'feed_settings',
82
  );
83
  $variables['feed_default_items'] = array(
84
    'type' => 'select_number',
85
    'title' => t('Number of items in each feed'),
86
    'default' => 10,
87
    'options' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30),
88
    'description' => t('Default number of items to include in each feed.', array(), $options),
89
    'group' => 'feed_settings',
90
  );
91
  $variables['feed_item_length'] = array(
92
    'type' => 'select',
93
    'title' => t('Feed content'),
94
    'default' => 'fulltext',
95
    'options' => array(
96
      'title' => t('Titles only', array(), $options),
97
      'teaser' => t('Titles plus teaser', array(), $options),
98
      'fulltext' => t('Full text', array(), $options)
99
    ),
100
    'description' => t('Global setting for the default display of content items in each feed.', array(), $options),
101
    'group' => 'feed_settings',
102
  );
103

    
104
  // Regional settings. Group 'regional_settings'.
105
  $variables['site_default_country'] = array(
106
    'type' => 'select',
107
    'options' => 'country',
108
    'title' => t('Default country', array(), $options),
109
    'element' => array('#type' => 'select', '#attributes' => array('class' => array('country-detect'))),
110
    'group' => 'regional_settings',
111
  );
112
  $variables['date_first_day'] = array(
113
    'type' => 'select',
114
    'options' => 'weekday',
115
    'title' => t('First day of week', array(), $options),
116
    'default' => 0,
117
    'localize' => TRUE,
118
    'group' => 'regional_settings',
119
  );
120
  $variables['date_default_timezone'] = array(
121
    'type' => 'select',
122
    'options' => 'timezone',
123
    'title' => t('Default time zone', array(), $options),
124
    'default callback' => 'date_default_timezone_get',
125
    'group' => 'regional_settings',
126
  );
127
  $variables['configurable_timezones'] = array(
128
    'type' => 'boolean',
129
    'title' => t('Users may set their own time zone.', array(), $options),
130
    'default' => 1,
131
    'group' => 'regional_settings',
132
  );
133
  $variables['empty_timezone_message'] = array(
134
    'type' => 'boolean',
135
    'title' => t('Remind users at login if their time zone is not set.', array(), $options),
136
    'default' => 0,
137
    'description' => t('Only applied if users may set their own time zone.', array(), $options),
138
    'group' => 'regional_settings',
139
  );
140
  $variables['user_default_timezone'] = array(
141
    'type' => 'select',
142
    'title' => t('Time zone for new users'),
143
    'default' => DRUPAL_USER_TIMEZONE_DEFAULT,
144
    'options' => array(
145
      DRUPAL_USER_TIMEZONE_DEFAULT => t('Default time zone.', array(), $options),
146
      DRUPAL_USER_TIMEZONE_EMPTY   => t('Empty time zone.', array(), $options),
147
      DRUPAL_USER_TIMEZONE_SELECT  => t('Users may set their own time zone at registration.', array(), $options),
148
    ),
149
    'description' => t('Only applied if users may set their own time zone.', array(), $options),
150
    'localize' => TRUE,
151
    'group' => 'regional_settings',
152
  );
153
  $variables['date_format_[date_type]'] = array(
154
    'type' => 'multiple',
155
    'title' => t('Date format'),
156
    'repeat' => array(
157
      'type' => 'select',
158
      'options' => 'date_format',
159
    ),
160
    'group' => 'regional_settings',
161
  );
162
  // Maintenance mode. Group 'site_information'
163
  $variables['maintenance_mode'] = array(
164
    'type' => 'boolean',
165
    'title' => t('Put site into maintenance mode', array(), $options),
166
    'default' => 0,
167
    '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),
168
    'group' => 'site_information'
169
  );
170
  $variables['maintenance_mode_message'] = array(
171
    'type' => 'text',
172
    'title' => t('Maintenance mode message', array(), $options),
173
    '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),
174
    'description' => t('Message to show visitors when the site is in maintenance mode.', array(), $options),
175
    'group' => 'site_information'
176
  );
177
  // Theme settings, we may want to localize the logo. Group 'theme_settings'
178
  $variables['theme_settings'] = array(
179
    'type' => 'properties',
180
    'title' => t('Global theme settings.', array(), $options),
181
    'group' => 'theme_settings',
182
    'default callback' => 'system_variable_theme_defaults',
183
    'localize' => TRUE,
184
    'group' => 'theme_settings',
185
  );
186
  $variables['theme_[theme]_settings'] = array(
187
    'type' => 'multiple',
188
    'multiple' => 'theme',
189
    'title' => t('Theme settings', array(), $options),
190
    'description' => t('Logo, icons and other specific theme settings.', array(), $options),
191
    'repeat' => array(
192
      'type' => 'properties',
193
      'default callback' => 'system_variable_theme_defaults',
194
    ),
195
    'group' => 'theme_settings',
196
    'localize' => TRUE,
197
  );
198
  // Performance options, changing them may need some extra cache refresh.
199
  $variables['cache'] = array(
200
    'type' => 'boolean',
201
    'title' => t('Cache pages for anonymous users', array(), $options),
202
    'default' => 0,
203
    'group' => 'system_performance',
204
  );
205
  // This one belongs to a different module, block, but it won't do any harm having it here.
206
  $variables['block_cache'] = array(
207
    'type' => 'boolean',
208
    'title' => t('Cache blocks'),
209
    'default' => FALSE,
210
    'description' => t('Block caching is inactive if you have enabled modules defining content access restrictions.', array(), $options),
211
    'group' => 'system_performance',
212
  );
213
  $interval = array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400);
214
  $variables['cache_lifetime'] = array(
215
    'type' => 'time_interval',
216
    'title' => t('Minimum cache lifetime', array(), $options),
217
    'default' => 0,
218
    'interval values' => $interval,
219
    'description' => t('Cached pages will not be re-created until at least this much time has elapsed.', array(), $options),
220
    'group' => 'system_performance',
221
  );
222
  $variables['page_cache_maximum_age'] = array(
223
    'type' => 'time_interval',
224
    'title' => t('Expiration of cached pages', array(), $options),
225
    'default' =>  0,
226
    'interval values' => $interval,
227
    'description' => t('The maximum time an external cache can use an old version of a page.', array(), $options),
228
    'group' => 'system_performance',
229
  );
230

    
231
  $description = t('External resources can be optimized automatically, which can reduce both the size and number of requests made to your website.', array(), $options);
232
  $variables['page_compression'] = array(
233
    'type' => 'enable',
234
    'title' => t('Compress cached pages.', array(), $options),
235
    'description' => $description,
236
    'default' => TRUE,
237
    'group' => 'system_performance',
238
  );
239
  $variables['preprocess_css'] = array(
240
    'type' => 'boolean',
241
    'title' => t('Aggregate and compress CSS files.'),
242
    'description' => $description,
243
    'default' => 0,
244
    'group' => 'system_performance',
245
  );
246
  $variables['preprocess_js'] = array(
247
    'type' => 'boolean',
248
    'title' => t('Aggregate JavaScript files.'),
249
    'description' => $description,
250
    'default' => 0,
251
    'group' => 'system_performance',
252
  );
253
  return $variables;
254
}
255

    
256
/**
257
 * Implements hook_variable_group_info().
258
 */
259
function system_variable_group_info() {
260
  $groups['site_information'] = array(
261
    'title' => t('Site information'),
262
    'description' => t('Site information and maintenance mode'),
263
    'access' => 'administer site configuration',
264
    'path' => array('admin/config/system/site-information', 'admin/config/development/maintenance'),
265
  );
266
  $groups['feed_settings'] = array(
267
    'title' => t('Feed settings'),
268
    'description' => t('Feed settings'),
269
    'access' => 'administer site configuration',
270
  );
271
  $groups['regional_settings'] = array(
272
    'title' => t('Regional settings'),
273
    'description' => t('Regional settings'),
274
    'access' => 'administer site configuration',
275
  );
276
  $groups['theme_settings'] = array(
277
    'title' => t('Theme settings'),
278
    'description' => t('Theme settings'),
279
    'access' => 'administer site configuration',
280
  );
281
  $groups['system_performance'] = array(
282
    'title' => t('System performance'),
283
    'description' => t('Options related with cache, file compression and bandwidth optimization.'),
284
    'access' => 'administer site configuration',
285
    'path' => 'admin/config/development/performance',
286
  );
287
  return $groups;
288
}
289

    
290
/**
291
 * Implements hook_variable_type_info().
292
 */
293
function system_variable_type_info() {
294
  // Internal Drupal path as used by menu items.
295
  $type['drupal_path'] = array(
296
    'title' => t('Drupal path'),
297
    'element callback' => 'system_variable_path_element',
298
    'localize' => TRUE,
299
  );
300
  // File system path, relative to Drupal installation.
301
  $type['file_path'] = array(
302
    'title' => t('File path'),
303
    'default' => conf_path() . '/files',
304
    'element' => array('#type' => 'textfield', '#maxlength' => 255, '#after_build' => array('system_check_directory')),
305
  );
306
  // These are just for option lists though they can be used as variable type to have a selectable value.
307
  $type['weekday'] = array(
308
    'title' => t('Day of week'),
309
    'type' => 'select',
310
    'options callback' => 'system_variable_option_weekday',
311
  );
312
  $type['theme'] = array(
313
    'title' => t('Theme'),
314
    'type' => 'select',
315
    'options callback' => 'system_variable_option_theme',
316
    'cache' => TRUE,
317
  );
318
  $type['country'] = array(
319
    'title' => t('Country'),
320
    'type' => 'select',
321
    'options callback' => 'system_variable_option_country',
322
    'cache' => TRUE,
323
  );
324
  $type['timezone'] = array(
325
    'title' => t('Time zone'),
326
    'type' => 'select',
327
    'options callback' => 'system_time_zones',
328
    'cache' => TRUE,
329
  );
330
  $type['date_type'] = array(
331
    'title' => t('Date type'),
332
    'type' => 'select',
333
    'options callback' => 'system_variable_option_date_type',
334
  );
335
  $type['date_format'] = array(
336
    'title' => t('Date format'),
337
    'type' => 'select',
338
    'options callback' => 'system_variable_option_date_format',
339
  );
340
  $type['time_interval'] = array(
341
    'title' => t('Time interval'),
342
    'type' => 'select',
343
    'options callback' => 'system_variable_option_time_interval',
344
  );
345
  return $type;
346
}
347

    
348
/**
349
 * Callback for theme options
350
 */
351
function system_variable_option_theme($variable, $options) {
352
  $list = array();
353
  foreach (list_themes() as $theme) {
354
    $list[$theme->name] = $theme->info['name'];
355
  }
356
  return $list;
357
}
358

    
359
/**
360
 * Callback for weekday options
361
 */
362
function system_variable_option_weekday($variable, $options) {
363
  return array(
364
    0 => t('Sunday', array(), $options),
365
    1 => t('Monday', array(), $options),
366
    2 => t('Tuesday', array(), $options),
367
    3 => t('Wednesday', array(), $options),
368
    4 => t('Thursday', array(), $options),
369
    5 => t('Friday', array(), $options),
370
    6 => t('Saturday', array(), $options)
371
  );
372
}
373

    
374
/**
375
 * Callback for date types
376
 */
377
function system_variable_option_date_type($variable, $options) {
378
  $list = array();
379
  foreach (system_get_date_types() as $type => $info) {
380
    $list[$type] = check_plain($info['title']);
381
  }
382
  return $list;
383
}
384

    
385
/**
386
 * Callback for date types
387
 *
388
 * @todo These should be different for some variables
389
 */
390
function system_variable_option_date_format($variable, $options) {
391
  // Get list of all available date formats.
392
  $all_formats = array();
393
  foreach (system_get_date_formats() as $type => $format_info) {
394
    $all_formats = array_merge($all_formats, $format_info);
395
  }
396
  if ($custom_formats = system_get_date_formats('custom')) {
397
    $all_formats = array_merge($all_formats, $custom_formats);
398
  }
399
  foreach ($all_formats as $f => $format) {
400
    $list[$f] = format_date(REQUEST_TIME, 'custom', $f);
401
  }
402
  return $list;
403
}
404

    
405
/**
406
 * Callback for country options
407
 */
408
function system_variable_option_country($variable, $options) {
409
  include_once DRUPAL_ROOT . '/includes/locale.inc';
410
  return country_get_list();
411
}
412

    
413
/**
414
 * Callback for time interval options
415
 */
416
function system_variable_option_time_interval($variable, $options) {
417
  $period = drupal_map_assoc($variable['interval values'], 'format_interval');
418
  if (isset($period[0])) {
419
    $period[0] = '<' . t('none') . '>';
420
  }
421
  return $period;
422
}
423

    
424
/**
425
 * Callback for default theme settings
426
 */
427
function system_variable_theme_defaults($variable, $options) {
428
  return array(
429
    'default_logo' => 1,
430
    'logo_path' => '',
431
    'default_favicon' => 1,
432
    'favicon_path' => '',
433
    'favicon_mimetype' => 'image/vnd.microsoft.icon',
434
  );
435
}
436

    
437
/**
438
 * Callback for path variable element
439
 */
440
function system_variable_path_element($variable, $options) {
441
  $element = variable_form_element_default($variable, $options) +array(
442
    '#type' => 'textfield',
443
    '#size' => 40,
444
    '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
445
  );
446
  return $element;
447
}