You are here

function cleaner_cleaner_settings in Cleaner 5

Same name and namespace in other branches
  1. 6 cleaner.module \cleaner_cleaner_settings()
  2. 7 cleaner.module \cleaner_cleaner_settings()

Implementation of hook_cleaner_settings().

File

./cleaner.module, line 78
Allows the admin to set a schedule for clearing caches and other stuff.

Code

function cleaner_cleaner_settings() {
  drupal_add_css(drupal_get_path('module', 'cleaner') . '/cleaner.css');
  $form = $ret = array();
  $yesno = array(
    t('No'),
    t('Yes'),
  );

  // Time intervals.
  $min = 60;
  $hour = 3600;
  $day = 86400;
  $interval = array(
    0 => t('Every time'),
  );
  $interval += drupal_map_assoc(array(
    15 * $min,
    30 * $min,
    $hour,
    2 * $hour,
    4 * $hour,
    6 * $hour,
    12 * $hour,
    $day,
    2 * $day,
    3 * $day,
    7 * $day,
  ), 'format_interval');
  $form['cleaner_cron'] = array(
    '#type' => 'radios',
    '#title' => t('Run interval'),
    '#options' => $interval,
    '#default_value' => variable_get('cleaner_cron', $hour),
    '#description' => t('This is how often the options below will occur. The actions will occur on the next Cron run after this interval expires. "Every time" means on every Cron run.'),
  );
  $list = array();
  $result = db_query("SHOW TABLES LIKE 'cache\\_%'");
  while ($table = db_result($result)) {
    $list[] = $table;
  }
  $form['cleaner_clear_cache'] = array(
    '#type' => 'radios',
    '#options' => $yesno,
    '#title' => t('Clear cache'),
    '#default_value' => variable_get('cleaner_clear_cache', FALSE),
    '#description' => t('The current cache tables are: @list.', array(
      '@list' => implode(', ', $list),
    )),
  );
  $form['cleaner_empty_watchdog'] = array(
    '#type' => 'radios',
    '#options' => $yesno,
    '#title' => t('Empty Watchdog'),
    '#default_value' => variable_get('cleaner_empty_watchdog', FALSE),
    '#description' => t('There is a standard setting for controlling Watchdog contents. This is more useful for test sites.'),
  );
  $lifetime = session_get_cookie_params();
  $lifetime = $lifetime['lifetime'];
  $start = (isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time()) - $lifetime;
  $count = db_result(db_query("SELECT COUNT(sid) FROM {sessions} WHERE timestamp < %d", $start));
  $form['cleaner_clean_sessions'] = array(
    '#type' => 'radios',
    '#options' => $yesno,
    '#title' => t('Clean up Sessions table'),
    '#default_value' => variable_get('cleaner_clean_sessions', FALSE),
    '#description' => t('The sessions table can quickly become full with old, abandoned sessions. This will delete all sessions older than @interval (as set by your site administrator). There are currently @count such sessions.', array(
      '@interval' => format_interval($lifetime),
      '@count' => $count,
    )),
  );
  $ret['cleaner'] = $form;
  return $ret;
}