function cleaner_cleaner_settings in Cleaner 6
Same name and namespace in other branches
- 5 cleaner.module \cleaner_cleaner_settings()
- 7 cleaner.module \cleaner_cleaner_settings()
Implementation of hook_cleaner_settings().
File
- ./
cleaner.module, line 77 - 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');
global $db_type;
$form = $ret = array();
$yesno = array(
t('No'),
t('Yes'),
);
$inline = array(
'class' => 'container-inline',
);
// 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.'),
'#attributes' => $inline,
);
$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', 0),
'#description' => t('The current cache tables are: @list.', array(
'@list' => implode(', ', $list),
)),
'#attributes' => $inline,
);
$form['cleaner_empty_watchdog'] = array(
'#type' => 'radios',
'#options' => $yesno,
'#title' => t('Empty Watchdog'),
'#default_value' => variable_get('cleaner_empty_watchdog', 0),
'#description' => t('There is a standard setting for controlling Watchdog contents. This is more useful for test sites.'),
'#attributes' => $inline,
);
$cookie = session_get_cookie_params();
$lifetime = $cookie['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', 0),
'#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,
)),
'#attributes' => $inline,
);
$form['cleaner_clean_cssdir'] = array(
'#type' => 'radios',
'#options' => $yesno,
'#title' => t('Clean up CSS files'),
'#default_value' => variable_get('cleaner_clean_cssdir', 0),
'#description' => t('The CSS directory can become full with stale and outdated cache files. This will delete all CSS cache files but the latest.'),
'#attributes' => $inline,
);
$form['cleaner_clean_jsdir'] = array(
'#type' => 'radios',
'#options' => $yesno,
'#title' => t('Clean up JS files'),
'#default_value' => variable_get('cleaner_clean_jsdir', 0),
'#description' => t('The JS directory can become full with stale and outdated cache files. This will delete all JS cache files but the latest.'),
'#attributes' => $inline,
);
// We can only offer OPTIMIZE to MySQL users.
$dbtype = drupal_strtolower(drupal_substr($db_type, 0, 5));
if ($dbtype == 'mysql') {
$form['cleaner_optimize_db'] = array(
'#type' => 'radios',
'#options' => $yesno + array(
'2' => 'Local only',
),
'#title' => t('Optimize tables with "overhead" space'),
'#default_value' => variable_get('cleaner_optimize_db', 0),
'#description' => t('The module will compress (optimize) all database tables with unused space. <strong>NOTE</strong>: During an optimization, the table will locked against any other activity; on a high vloume site, this may be undesirable. "Local only" means do not replicate the optimization (if it is being done).'),
'#attributes' => $inline,
);
}
else {
// If not MySql, delete (reset) the variable.
variable_del('cleaner_optimize_db');
}
$ret['cleaner'] = $form;
return $ret;
}