summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reid2013-07-21 19:35:08 (GMT)
committer Dave Reid2013-07-21 19:35:08 (GMT)
commitd460ba965b7da2c965f734b5560e843b883ca2e6 (patch)
tree75972c40c3041c5448bc3a836c59bedeb373bb00
parenta01d976d0935453cc01e0f72e7e81936fd366611 (diff)
Improved the UX of the import files admin form.
-rw-r--r--includes/media.admin.inc24
1 files changed, 19 insertions, 5 deletions
diff --git a/includes/media.admin.inc b/includes/media.admin.inc
index 88b88b9..f344bff 100644
--- a/includes/media.admin.inc
+++ b/includes/media.admin.inc
@@ -20,13 +20,16 @@ function media_import($form, &$form_state) {
$form['directory'] = array(
'#type' => 'textfield',
'#title' => t('Directory'),
+ '#description' => t('Enter the absolute directory on the web server to look for files. Subdirectories inside this directory will not be scanned.'),
'#required' => TRUE,
);
$form['pattern'] = array(
- '#type' => 'textfield',
+ '#type' => 'textarea',
'#title' => t('Pattern'),
- '#description' => 'Only files matching this pattern will be imported. For example, to import all jpg and gif files, the pattern would be <em>*.jpg|*.gif</em>.',
+ '#description' => t("Only files matching these patterns will be imported. Enter one pattern per line. The '*' character is a wildcard. Example patterns are %png_example to import all PNG files.", array('%png_example' => '*.png')),
+ '#default_value' => '*',
+ '#required' => TRUE,
);
$form['actions'] = array('#type' => 'actions');
@@ -61,10 +64,21 @@ function media_import_validate($form, &$form_state) {
if (!is_dir($directory)) {
form_set_error('directory', t('The provided directory does not exist.'));
}
- $pattern = !empty($pattern) ? $pattern : '*';
- $files = glob("$directory/$pattern");
+ if (!is_readable($directory)) {
+ form_set_error('directory', t('The provided directory is not readable.'));
+ }
+
+ $pattern_quoted = preg_quote($pattern, '/');
+ $pattern_quoted = preg_replace('/(\r\n?|\n)/', '|', $pattern_quoted);
+ $pattern_quoted = strtr($pattern_quoted, array(
+ '\\|' => '|',
+ '\\*' => '.*',
+ '\\?' => '.?',
+ ));
+ $files = file_scan_directory($directory, '/^(' . $pattern_quoted . ')$/', array('recurse' => FALSE));
+ $files = array_keys($files);
if (empty($files)) {
- form_set_error('pattern', t('No files were found in %directory matching %pattern', array('%directory' => $directory, '%pattern' => $pattern)));
+ form_set_error('pattern', t('No files were found in %directory matching the regular expression %pattern', array('%directory' => $directory, '%pattern' => $pattern_quoted)));
}
$form_state['storage']['files'] = $files;
}