Projet

Général

Profil

Paste
Télécharger (4,68 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / update / update.settings.inc @ db2d93dd

1
<?php
2

    
3
/**
4
 * @file
5
 * Code required only for the update status settings form.
6
 */
7

    
8
/**
9
 * Form constructor for the update settings form.
10
 *
11
 * @see update_settings_validate()
12
 * @see update_settings_submit()
13
 * @ingroup forms
14
 */
15
function update_settings($form) {
16
  $form['update_check_frequency'] = array(
17
    '#type' => 'radios',
18
    '#title' => t('Check for updates'),
19
    '#default_value' => variable_get('update_check_frequency', 1),
20
    '#options' => array(
21
      '1' => t('Daily'),
22
      '7' => t('Weekly'),
23
    ),
24
    '#description' => t('Select how frequently you want to automatically check for new releases of your currently installed modules and themes.'),
25
  );
26

    
27
  $form['update_check_disabled'] = array(
28
    '#type' => 'checkbox',
29
    '#title' => t('Check for updates of disabled modules and themes'),
30
    '#default_value' => variable_get('update_check_disabled', FALSE),
31
  );
32

    
33
  $notify_emails = variable_get('update_notify_emails', array());
34
  $form['update_notify_emails'] = array(
35
    '#type' => 'textarea',
36
    '#title' => t('E-mail addresses to notify when updates are available'),
37
    '#rows' => 4,
38
    '#default_value' => implode("\n", $notify_emails),
39
    '#description' => t('Whenever your site checks for available updates and finds new releases, it can notify a list of users via e-mail. Put each address on a separate line. If blank, no e-mails will be sent.'),
40
  );
41

    
42
  $form['update_notification_threshold'] = array(
43
    '#type' => 'radios',
44
    '#title' => t('E-mail notification threshold'),
45
    '#default_value' => variable_get('update_notification_threshold', 'all'),
46
    '#options' => array(
47
      'all' => t('All newer versions'),
48
      'security' => t('Only security updates'),
49
    ),
50
    '#description' => t('You can choose to send e-mail only if a security update is available, or to be notified about all newer versions. If there are updates available of Drupal core or any of your installed modules and themes, your site will always print a message on the <a href="@status_report">status report</a> page, and will also display an error message on administration pages if there is a security update.', array('@status_report' => url('admin/reports/status')))
51
  );
52

    
53
  $form = system_settings_form($form);
54
  // Custom validation callback for the email notification setting.
55
  $form['#validate'][] = 'update_settings_validate';
56
  // We need to call our own submit callback first, not the one from
57
  // system_settings_form(), so that we can process and save the emails.
58
  unset($form['#submit']);
59

    
60
  return $form;
61
}
62

    
63
/**
64
 * Form validation handler for update_settings().
65
 *
66
 * Validates the e-mail addresses and ensures the field is formatted correctly.
67
 *
68
 * @see update_settings_submit()
69
 */
70
function update_settings_validate($form, &$form_state) {
71
  if (!empty($form_state['values']['update_notify_emails'])) {
72
    $valid = array();
73
    $invalid = array();
74
    foreach (explode("\n", trim($form_state['values']['update_notify_emails'])) as $email) {
75
      $email = trim($email);
76
      if (!empty($email)) {
77
        if (valid_email_address($email)) {
78
          $valid[] = $email;
79
        }
80
        else {
81
          $invalid[] = $email;
82
        }
83
      }
84
    }
85
    if (empty($invalid)) {
86
      $form_state['notify_emails'] = $valid;
87
    }
88
    elseif (count($invalid) == 1) {
89
      form_set_error('update_notify_emails', t('%email is not a valid e-mail address.', array('%email' => reset($invalid))));
90
    }
91
    else {
92
      form_set_error('update_notify_emails', t('%emails are not valid e-mail addresses.', array('%emails' => implode(', ', $invalid))));
93
    }
94
  }
95
}
96

    
97
/**
98
 * Form submission handler for update_settings().
99
 *
100
 * Also invalidates the cache of available updates if the "Check for updates of
101
 * disabled modules and themes" setting is being changed. The available updates
102
 * report needs to refetch available update data after this setting changes or
103
 * it would show misleading things (e.g., listing the disabled projects on the
104
 * site with the "No available releases found" warning).
105
 *
106
 * @see update_settings_validate()
107
 */
108
function update_settings_submit($form, $form_state) {
109
  $op = $form_state['values']['op'];
110

    
111
  if (empty($form_state['notify_emails'])) {
112
    variable_del('update_notify_emails');
113
  }
114
  else {
115
    variable_set('update_notify_emails', $form_state['notify_emails']);
116
  }
117
  unset($form_state['notify_emails']);
118
  unset($form_state['values']['update_notify_emails']);
119

    
120
  // See if the update_check_disabled setting is being changed, and if so,
121
  // invalidate all cached update status data.
122
  $check_disabled = variable_get('update_check_disabled', FALSE);
123
  if ($form_state['values']['update_check_disabled'] != $check_disabled) {
124
    _update_cache_clear();
125
  }
126

    
127
  system_settings_form_submit($form, $form_state);
128
}