Projet

Général

Profil

Paste
Télécharger (7,19 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / user_stats / user_stats.admin.inc @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * @file
5
 * Commonly requested user statistics for themers administration interface.
6
 */
7

    
8
/**
9
 * Implements hook_settings().
10
 */
11
function user_stats_admin_settings($form, &$form_state) {
12
  $form['post_count_options'] = array(
13
    '#type' => 'fieldset',
14
    '#title' => t('Post count options'),
15
    '#collapsible' => TRUE,
16
    '#collapsed' => (variable_get('user_stats_count_posts', TRUE) || variable_get('user_stats_count_comments', TRUE) ? FALSE : TRUE),
17
  );
18

    
19
  $form['post_count_options']['user_stats_count_posts'] = array(
20
    '#type' => 'checkbox',
21
    '#title' => t('Count posts'),
22
    '#description' => t('If checked user post counts will be calculated.'),
23
    '#default_value' => variable_get('user_stats_count_posts', TRUE),
24
  );
25

    
26
  $form['post_count_options']['user_stats_count_comments'] = array(
27
    '#type' => 'checkbox',
28
    '#title' => t('Count comments'),
29
    '#description' => t('If checked user comments counts will be included in the total user post count.'),
30
    '#default_value' => variable_get('user_stats_count_comments', TRUE),
31
  );
32

    
33
  foreach (node_type_get_types() as $types) {
34
    $options[$types->type] = $types->name;
35
  }
36

    
37
  $form['post_count_options']['user_stats_included_content_types'] = array(
38
    '#type' => 'select',
39
    '#title' => t('Content types to include in post count'),
40
    '#description' => t('Select the content types to include in the user post count (hold ctrl or shift to select multiple types). Both nodes and comments will be included in the post count. If you do not select any content types, then all types will be counted.'),
41
    '#options' => $options,
42
    '#default_value' => variable_get('user_stats_included_content_types', array()),
43
    '#multiple' => TRUE,
44
    '#size' => 10,
45
  );
46

    
47
  $form['post_count_options']['user_stats_user_per_cron'] = array(
48
    '#type' => 'select',
49
    '#title' => t('Number of users to update per cron run'),
50
    '#options' => array(
51
      '10' => '10',
52
      '25' => '25',
53
      '50' => '50',
54
      '100' => '100',
55
      '200' => '200',
56
    ),
57
    '#default_value' => variable_get('user_stats_user_per_cron', array('25')),
58
  );
59

    
60
  $form['post_count_options']['post_count_reset'] = array(
61
    '#type' => 'fieldset',
62
    '#title' => t('Post count reset'),
63
    '#collapsible' => TRUE,
64
    '#collapsed' => TRUE,
65
  );
66

    
67
  $form['post_count_options']['post_count_reset']['user_stats_reset_post_count'] = array(
68
    '#type' => 'submit',
69
    '#value' => t('Reset all post counts'),
70
  );
71

    
72
  $form['login_count_options'] = array(
73
    '#type' => 'fieldset',
74
    '#title' => t('Login count options'),
75
    '#collapsible' => TRUE,
76
    '#collapsed' => (variable_get('user_stats_count_logins', TRUE) ? FALSE : TRUE),
77
  );
78

    
79
  $form['login_count_options']['user_stats_count_logins'] = array(
80
    '#type' => 'checkbox',
81
    '#title' => t('Count logins'),
82
    '#description' => t('If checked user login counts will be calculated.'),
83
    '#default_value' => variable_get('user_stats_count_logins', TRUE),
84
  );
85

    
86
  $form['login_count_options']['login_count_reset'] = array(
87
    '#type' => 'fieldset',
88
    '#title' => t('Login count reset'),
89
    '#collapsible' => TRUE,
90
    '#collapsed' => TRUE,
91
  );
92

    
93
  $form['login_count_options']['login_count_reset']['user_stats_reset_login_count'] = array(
94
    '#type' => 'submit',
95
    '#value' => t('Reset all login counts'),
96
  );
97

    
98
  $form['ip_tracking_options'] = array(
99
    '#type' => 'fieldset',
100
    '#title' => t('IP address tracking'),
101
    '#collapsible' => TRUE,
102
    '#collapsed' => (variable_get('user_stats_track_ips', TRUE) ? FALSE : TRUE),
103
  );
104

    
105
  $form['ip_tracking_options']['user_stats_track_ips'] = array(
106
    '#type' => 'checkbox',
107
    '#title' => t('Track IP addresses'),
108
    '#description' => t('If checked the IP addresses of users will be logged. This may be a privacy issue for some people, but is very useful for discovering spammers on community sites.'),
109
    '#default_value' => variable_get('user_stats_track_ips', TRUE),
110
  );
111

    
112
  $period = drupal_map_assoc(array(604800, 4838400, 15724800, 31536000, 157680000, 315360000), 'format_interval');
113
  $form['ip_tracking_options']['user_stats_flush_ips_timer'] = array(
114
    '#type' => 'select',
115
    '#title' => t('Discard IP logs older than'),
116
    '#description' => t('Older IP log entries will be automatically discarded. (Requires a correctly configured <a href="@cron">cron maintenance task</a>.)', array('@cron' => url('admin/reports/status'))),
117
    '#options' => $period,
118
    '#default_value' => variable_get('user_stats_flush_ips_timer', 31536000),
119
  );
120

    
121
  $form['online_user_options'] = array(
122
    '#type' => 'fieldset',
123
    '#title' => t('Online users'),
124
    '#collapsible' => TRUE,
125
    '#collapsed' => FALSE,
126
  );
127

    
128
  // Following blatantly nicked from /modules/user/user.module and should be updated if that changes.
129
  $period = drupal_map_assoc(array(30, 60, 120, 180, 300, 600, 900, 1800, 2700, 3600, 5400, 7200, 10800, 21600, 43200, 86400), 'format_interval');
130
  $form['online_user_options']['user_block_seconds_online'] = array(
131
    '#type' => 'select',
132
    '#title' => t('User activity'),
133
    '#default_value' => variable_get('user_block_seconds_online', 900),
134
    '#options' => $period,
135
    '#description' => t('A user is considered online for this long after they have last viewed a page.'),
136
  );
137

    
138
  $form['#submit'][] = 'user_stats_settings_change';
139

    
140
  return system_settings_form($form);
141
}
142

    
143
/**
144
 * Settings change callback.
145
 * TODO: make this check a setting has been changed before resetting counts.
146
 */
147
function user_stats_settings_change($form, &$form_state) {
148
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
149

    
150
  // Give user feedback that post counts have been reset as requested.
151
  if ($op == t('Reset all post counts')) {
152
    drupal_goto('admin/config/people/user_stats/reset_post_count');
153
  }
154
  else if ($op == t('Reset all login counts')) {
155
    drupal_goto('admin/config/people/user_stats/reset_login_count');
156
  }
157

    
158
  // If the user has decided not to track IPs, we delete all the logged entries.
159
  if (!$form_state['values']['user_stats_track_ips'] &&
160
      variable_get('user_stats_track_ips', TRUE) &&
161
      db_query("SELECT COUNT(*) FROM {user_stats_ips}")->fetchField()) {
162

    
163
    db_query("TRUNCATE TABLE {user_stats_ips}");
164
  }
165
  // We also need to rebuild the menus, as some Views we provide in the
166
  // Reports section rely on IP address tracking.
167
  if ($form_state['values']['user_stats_track_ips'] != variable_get('user_stats_track_ips', TRUE)) {
168
    // We have to save the form value for user_stats_track_ips before the menus
169
    // are rebuilt.
170
    variable_set('user_stats_track_ips', $form_state['values']['user_stats_track_ips']);
171
    menu_rebuild();
172
  }
173

    
174
  // Rebuild post count stats when settings change.
175
  variable_set('user_stats_rebuild_stats', TRUE);
176
  user_stats_reset_counts('post_count');
177
}
178

    
179
/**
180
 * Reset post count handler.
181
 */
182
function user_stats_reset_post_count() {
183
  variable_set('user_stats_rebuild_stats', TRUE);
184
  user_stats_reset_counts('post_count');
185
  drupal_set_message(t('Post counts have been reset.'));
186
  drupal_goto('admin/config/people/user_stats');
187
}
188

    
189
/**
190
 * Reset login count handler.
191
 */
192
function user_stats_reset_login_count() {
193
  user_stats_reset_counts('login_count');
194
  drupal_set_message(t('User login counts have been reset.'));
195
  drupal_goto('admin/config/people/user_stats');
196
}