Validate form values. Used to unset variables before they get saved.
File
-
includes/
admin.inc, line 440
Code
function advagg_admin_settings_form_validate($form, &$form_state) {
global $conf;
// Custom directory handling.
if (!empty($form_state['values']['advagg_custom_files_dir'])) {
$form_state['values']['advagg_custom_files_dir'] = trim($form_state['values']['advagg_custom_files_dir']);
$files_dir = $form_state['values']['advagg_custom_files_dir'];
if (!empty($files_dir) && $files_dir != $conf['advagg_custom_files_dir']) {
// Try to create dir structure.
$cumulative = '';
$path_array = explode('/', $files_dir);
foreach ($path_array as $dir) {
if (empty($cumulative)) {
$cumulative = $dir;
}
else {
$cumulative .= '/' . $dir;
}
// If dir creation fails, bail out of loop.
if (!file_prepare_directory($cumulative, FILE_CREATE_DIRECTORY)) {
break;
}
}
// See if dir exists and is writable.
if (file_prepare_directory($files_dir) == TRUE) {
// Remove old files.
list($css_path, $js_path) = advagg_get_root_files_dir();
file_scan_directory($css_path, '/.*/', array(
'callback' => 'file_unmanaged_delete',
));
@unlink($css_path);
file_scan_directory($js_path, '/.*/', array(
'callback' => 'file_unmanaged_delete',
));
@unlink($js_path);
// Set new path.
$conf['advagg_custom_files_dir'] = $files_dir;
advagg_get_root_files_dir(TRUE);
menu_rebuild();
}
else {
form_set_error('advagg_custom_files_dir', t('%dir is not a directory or is not writable by the web server.', array(
'%dir' => $files_dir,
)));
}
}
}
// If the IP field is not blank, check that its a valid address.
if (!empty($form_state['values']['advagg_server_addr']) && $form_state['values']['advagg_server_addr'] != -1 && ip2long($form_state['values']['advagg_server_addr']) === FALSE) {
form_set_error('advagg_server_addr', t('Must be a valid IP address.'));
}
// Remove non variable form info.
unset($form_state['values']['advagg_flush']);
unset($form_state['values']['advagg_rebuild']);
unset($form_state['values']['advagg_forced_build']);
unset($form_state['values']['advagg_recreate_htaccess']);
unset($form_state['values']['advagg_reset']);
}