Projet

Général

Profil

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

root / drupal7 / modules / update / update.settings.inc @ 6d8023f2

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 and uninstalled 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 and uninstalled modules and themes" setting is being changed. The
102
 * available updates report needs to refetch available update data after this
103
 * setting changes or it would show misleading things (e.g., listing the
104
 * disabled projects on the site with the "No available releases found"
105
 * warning).
106
 *
107
 * @see update_settings_validate()
108
 */
109
function update_settings_submit($form, $form_state) {
110
  $op = $form_state['values']['op'];
111

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

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

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