diff --git a/browscap.admin.inc b/browscap.admin.inc index 627ff22..942381e 100644 --- a/browscap.admin.inc +++ b/browscap.admin.inc @@ -16,23 +16,40 @@ function browscap_settings_form($form, &$form_state) { $version = t('Never fetched'); } - $form['browscap_data_status'] = array( + $form['data'] = array( + '#type' => 'fieldset', + '#title' => t('User agent detection settings'), + ); + $form['data']['browscap_data_version'] = array( '#markup' => '

' . t('Current browscap data version: %fileversion.', array('%fileversion' => $version)) . '

', ); - $form['browscap_update_interval'] = array( - '#type' => 'textfield', - '#title' => t('Update interval'), - '#default_value' => variable_get('browscap_update_interval', 7), - '#description' => t('Control how often Browscap checks for new browser information. Enter 0 to disable updating.'), - '#field_suffix' => t('days'), - '#size' => 3, - '#maxlength' => 3, + $form['data']['browscap_enable_automatic_updates'] = array( + '#type' => 'checkbox', + '#title' => t('Enable automatic updates'), + '#default_value' => variable_get('browscap_enable_automatic_updates', TRUE), + '#description' => t('Automatically update the user agent detection information.'), + ); + $form['data']['browscap_automatic_updates_timer'] = array( + '#type' => 'select', + '#title' => t('Check for new user agent detection information every'), + '#default_value' => variable_get('browscap_automatic_updates_timer', 604800), + '#options' => drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'), + '#description' => t('Newer user agent detection information will be automatically downloaded and installed. (Requires a correctly configured cron maintenance task.)', array('@cron' => url('admin/reports/status'))), + '#states' => array( + 'visible' => array( + ':input[name="browscap_enable_automatic_updates"]' => array('checked' => TRUE), + ), + ), ); - $form['browscap_monitor'] = array( + $form['user_agent_log'] = array( + '#type' => 'fieldset', + '#title' => t('User agent log settings'), + ); + $form['user_agent_log']['browscap_enable_user_agent_log'] = array( '#type' => 'checkbox', - '#title' => t('Monitor browsers'), - '#default_value' => variable_get('browscap_monitor', FALSE), - '#description' => t('Monitor all user agents visiting the site. View the reports in the Browscap reports area.', array('!reports' => url('admin/reports/browscap'))), + '#title' => t('Enable user agent log'), + '#default_value' => variable_get('browscap_enable_user_agent_log', FALSE), + '#description' => t('Increment a counter each time content is viewed by a user agent.'), ); $form['actions']['browscap_refresh'] = array( '#type' => 'submit', @@ -44,24 +61,6 @@ function browscap_settings_form($form, &$form_state) { return system_settings_form($form); } - /** - * Validate the settings form. - */ -function browscap_settings_form_validate($form, &$form_state) { - // Check the update interval - $update_interval = $form_state['values']['browscap_update_interval']; - - // Ensure that the update interval is a number - if (!is_numeric($update_interval)) { - form_set_error('browscap_update_interval', t('The update interval must be a number.')); - } - - // Ensure that the update interval is a non-negative number - if ($update_interval < 0) { - form_set_error('browscap_update_interval', t('The update interval must be non-negative.')); - } -} - /** * Submit handler for the refresh browscap button. */ diff --git a/browscap.install b/browscap.install index 30013cb..69ae722 100644 --- a/browscap.install +++ b/browscap.install @@ -100,9 +100,10 @@ function browscap_install() { */ function browscap_uninstall() { variable_del('browscap_imported'); - variable_del('browscap_monitor'); - variable_del('browscap_update_interval'); variable_del('browscap_version'); + variable_del('browscap_enable_automatic_updates'); + variable_del('browscap_automatic_updates_timer'); + variable_del('browscap_enable_user_agent_log'); } /** @@ -113,3 +114,23 @@ function browscap_update_7000() { return $return; } + +/** + * Port and remove old variables. + */ +function browscap_update_7001() { + // Port and remove browscap_update_interval + $browscap_update_interval = variable_get('browscap_update_interval', 7); + + if ($browscap_update_interval == 0) { + variable_set('browscap_enable_automatic_updates', FALSE); + } + else { + $browscap_update_interval = $browscap_update_interval * 7 * 24 * 60 * 60; + variable_set('browscap_automatic_updates_timer', $browscap_update_interval); + } + + // Port and remove browscap_monitor + $browscap_monitor = variable_get('browscap_monitor', FALSE); + variable_set('browscap_enable_user_agent_log', $browscap_monitor); +} diff --git a/browscap.module b/browscap.module index 27b2990..e055616 100644 --- a/browscap.module +++ b/browscap.module @@ -80,11 +80,8 @@ function browscap_menu() { * Implements hook_exit(). */ function browscap_exit() { - // Check the status of user agent monitoring - $monitoring = variable_get('browscap_monitor', FALSE); - // Record the current user agent if monitoring is enabled - if ($monitoring == TRUE) { + if (variable_get('browscap_enable_user_agent_log', FALSE) == TRUE) { // Get browscap data about the current user agent $user_agent = browscap_get_browser(); @@ -122,23 +119,22 @@ function browscap_exit() { * Implements hook_cron(). */ function browscap_cron() { - // Check the current update interval - $update_interval = variable_get('browscap_update_interval', 7); - - // Convert the update interval from days to seconds - $update_interval = $update_interval * 7 * 24 * 60 * 60; + if (variable_get('browscap_enable_automatic_updates', TRUE) == TRUE) { + // Check the current update timer + $automatic_update_timer = variable_get('browscap_automatic_updates_timer', 604800); - // Check when the last update occurred - $last_imported = variable_get('browscap_imported', REQUEST_TIME); + // Check when the last update occurred + $last_imported = variable_get('browscap_imported', REQUEST_TIME); - // Update the browscap data if the amount of time specified by the update - // interval has passed - if (($last_imported + $update_interval) < REQUEST_TIME) { - // Update the browscap information - _browscap_import(); + // Update the browscap data if the amount of time specified by the update + // timer has passed + if (($last_imported + $automatic_update_timer) < REQUEST_TIME) { + // Update the browscap information + _browscap_import(); - // Record when the browscap information was updated - variable_set('browscap_imported', REQUEST_TIME); + // Record when the browscap information was updated + variable_set('browscap_imported', REQUEST_TIME); + } } }