function brilliant_gallery_admin_validate in Brilliant Gallery 7
Same name and namespace in other branches
- 6.4 brilliant_gallery.module \brilliant_gallery_admin_validate()
- 7.2 brilliant_gallery_config.inc \brilliant_gallery_admin_validate()
@todo Please document this function.
See also
File
- ./
brilliant_gallery.module, line 358
Code
function brilliant_gallery_admin_validate($form, &$form_state) {
$brilliant_gallery_folder = $form_state['values']['brilliant_gallery_folder'];
if (substr($brilliant_gallery_folder, 0, 1) == "/" or substr($brilliant_gallery_folder, -1, 1) == "/") {
form_set_error('brilliant_gallery_folder', 'The path should not start or end with a slash.');
}
$dir = realpath(FILE_DIRECTORY_PATH) . '/' . $brilliant_gallery_folder;
if (!file_exists($dir) or !is_dir($dir)) {
// If the dir does not exist, attempt to create it or throw an error.
if (!mkdir($dir)) {
form_set_error('brilliant_gallery_folder', 'Directory ' . $brilliant_gallery_folder . ' does not exist in ' . FILE_DIRECTORY_PATH . '/ and it was not possible to create it automatically.');
}
}
$brilliant_gallery_pcache = $form_state['values']['brilliant_gallery_pcache'];
if (trim($brilliant_gallery_pcache) == '') {
$brilliant_gallery_pcache = BRILLIANT_GALLERY_DEFAULT_CACHE_DIR;
}
if (substr($brilliant_gallery_pcache, 0, 1) == "/" or substr($brilliant_gallery_pcache, -1, 1) == "/") {
form_set_error('brilliant_gallery_pcache', 'The path should not start or end with a slash.');
}
else {
// The directory either exists or we attempt to create it now.
$path = FILE_DIRECTORY_PATH . "/" . $brilliant_gallery_pcache;
if (file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
// All OK, the directory exists or was just created.
$form_state['values']['brilliant_gallery_pcache'] = $brilliant_gallery_pcache;
// Why not set it as well.
}
else {
form_set_error('brilliant_gallery_pcache', "Directory " . $brilliant_gallery_pcache . " in your /files folder either could not be created or is not writable.");
}
}
}