browscap.admin.inc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @file
  4. * Generate configuration form.
  5. */
  6. /**
  7. * Implements hook_form().
  8. */
  9. function browscap_settings_form($form, &$form_state) {
  10. // Check the local browscap data version number.
  11. $version = variable_get('browscap_version', 0);
  12. // If the version number is 0 then browscap data has never been fetched.
  13. if ($version == 0) {
  14. $version = t('Never fetched');
  15. }
  16. $form['browscap_data_version'] = array(
  17. '#markup' => '<p>' . t('Current browscap data version: %fileversion.', array('%fileversion' => $version)) . '</p>',
  18. );
  19. $form['browscap_enable_automatic_updates'] = array(
  20. '#type' => 'checkbox',
  21. '#title' => t('Enable automatic updates'),
  22. '#default_value' => variable_get('browscap_enable_automatic_updates', TRUE),
  23. '#description' => t('Automatically update the user agent detection information.'),
  24. );
  25. $form['browscap_automatic_updates_timer'] = array(
  26. '#type' => 'select',
  27. '#title' => t('Check for new user agent detection information every'),
  28. '#default_value' => variable_get('browscap_automatic_updates_timer', 604800),
  29. '#options' => drupal_map_assoc(array(
  30. 3600, 10800, 21600, 32400, 43200, 86400, 172800,
  31. 259200, 604800, 1209600, 2419200, 4838400, 9676800),
  32. 'format_interval'),
  33. '#description' => t('Newer user agent detection information will be automatically downloaded and installed. (Requires a correctly configured <a href="@cron">cron maintenance task</a>.)', array('@cron' => url('admin/reports/status'))),
  34. '#states' => array(
  35. 'visible' => array(
  36. ':input[name="browscap_enable_automatic_updates"]' => array('checked' => TRUE),
  37. ),
  38. ),
  39. );
  40. $form['actions']['browscap_refresh'] = array(
  41. '#type' => 'submit',
  42. '#value' => t('Refresh browscap data'),
  43. '#submit' => array('browscap_refresh_submit'),
  44. '#weight' => 10,
  45. );
  46. return system_settings_form($form);
  47. }
  48. /**
  49. * Submit handler for the refresh browscap button.
  50. */
  51. function browscap_refresh_submit($form, &$form_state) {
  52. // Update the browscap information.
  53. _browscap_import(FALSE);
  54. // Record when the browscap information was updated.
  55. variable_set('browscap_imported', REQUEST_TIME);
  56. }