| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Admin page callbacks for the incoming module.
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Form builder; Configure the incoming system.
|
| 10 |
*
|
| 11 |
* @ingroup forms
|
| 12 |
* @see system_settings_form()
|
| 13 |
* @see incoming_admin_settings_validate()
|
| 14 |
*/
|
| 15 |
function incoming_admin_settings() {
|
| 16 |
$probabilities = array(0 => '100%', 1 => '50%', 2 => '33.3%', 3 => '25%', 4 => '20%', 5 => '16.6%', 7 => '12.5%', 9 => '10%', 19 => '5%', 99 => '1%', 199 => '.5%', 399 => '.25%', 989 => '.1%');
|
| 17 |
$timespan = drupal_map_assoc(array(120, 180, 240, 300, 600, 900, 1800, 3600), 'format_interval');
|
| 18 |
$suppression = drupal_map_assoc(array(180, 600, 3600, 7200, 18000, 36000, 72000, 86400), 'format_interval');
|
| 19 |
|
| 20 |
$form['incoming_alert_threshold'] = array(
|
| 21 |
'#type' => 'textfield',
|
| 22 |
'#title' => t('Alert threshold'),
|
| 23 |
'#default_value' => variable_get('incoming_alert_threshold', 10),
|
| 24 |
'#size' => 5,
|
| 25 |
'#maxlength' => 6,
|
| 26 |
'#description' => t(' The amount of new visitors to your site in the specified timespan needed to trigger an alert. Be warned, if you set the number too high your server may crash under heavy load before the alert can be sent.')
|
| 27 |
);
|
| 28 |
$form['incoming_time_period'] = array(
|
| 29 |
'#type' => 'select',
|
| 30 |
'#title' => t('Timespan'),
|
| 31 |
'#default_value' => variable_get('incoming_time_period', 600),
|
| 32 |
'#options' => $timespan,
|
| 33 |
'#description' => t('The timespan sample to compare the level of visitors to your site against. As an example, 10 minutes will compare the number of visitors to your site over the last 10 minutes to the number of visitors to the site in the previous 10 minutes. If this number is higher than the alert threshold you have set above, an alert will be sent.')
|
| 34 |
);
|
| 35 |
$form['incoming_alert_suppression'] = array(
|
| 36 |
'#type' => 'select',
|
| 37 |
'#title' => t('Alert suppression'),
|
| 38 |
'#default_value' => variable_get('incoming_alert_suppression', 7200),
|
| 39 |
'#options' => $suppression,
|
| 40 |
'#description' => t('The amount of time after receiving an alert until you are alerted again to changes in the traffic status of your site.')
|
| 41 |
);
|
| 42 |
$form['incoming_probability_limiter'] = array(
|
| 43 |
'#type' => 'select',
|
| 44 |
'#title' => t('Probability limiter'),
|
| 45 |
'#default_value' => variable_get('incoming_probability_limiter', 9),
|
| 46 |
'#options' => $probabilities,
|
| 47 |
'#description' => t('The probability limiter is an efficiency mechanism to statistically reduce the overhead of the incoming module. The limiter is expressed as a percentage of page views, so for example if set to the default of 10% we only perform the extra database queries to check the number of new visitors on the site 1 out of every 10 page views. The busier your site, the lower you should set the limiter value. This functionality is based on the Drupal core throttle module.')
|
| 48 |
);
|
| 49 |
$form['incoming_alert_mail'] = array(
|
| 50 |
'#type' => 'textfield',
|
| 51 |
'#title' => t("E-mail"),
|
| 52 |
'#default_value' => variable_get('incoming_alert_mail', NULL),
|
| 53 |
'#description' => t('Alerts will be e-mailed to this address. Leave blank for none. Multiple e-mail addresses may be separated by commas.'),
|
| 54 |
);
|
| 55 |
|
| 56 |
|
| 57 |
$form['#validate'] = array('incoming_admin_settings_validate');
|
| 58 |
|
| 59 |
return system_settings_form($form);
|
| 60 |
}
|
| 61 |
|
| 62 |
function incoming_admin_settings_validate($form, &$form_state) {
|
| 63 |
if (!is_numeric($form_state['values']['incoming_alert_threshold']) || $form_state['values']['incoming_alert_threshold'] < 0) {
|
| 64 |
form_set_error('incoming_alert_threshold', t("%value is not a valid setting. Please enter a positive numeric value.", array('%value' => $form_state['values']['incoming_alert_threshold'])));
|
| 65 |
}
|
| 66 |
$recipients = explode(',', $form_state['values']['incoming_alert_mail']);
|
| 67 |
foreach ($recipients as $recipient) {
|
| 68 |
if (!valid_email_address(trim($recipient))) {
|
| 69 |
form_set_error('incoming_alert_mail', t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient)));
|
| 70 |
}
|
| 71 |
}
|
| 72 |
}
|