Index: node_gallery.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_gallery/node_gallery.pages.inc,v
retrieving revision 1.11.4.21
diff -u -r1.11.4.21 node_gallery.pages.inc
--- node_gallery.pages.inc	28 Oct 2009 01:36:48 -0000	1.11.4.21
+++ node_gallery.pages.inc	28 Oct 2009 04:48:18 -0000
@@ -7,6 +7,34 @@
  *
  */
 
+/**
+ * Validate filesystem paths
+ * 
+ * Take in a string; if transliteration is available use it, otherwise use a simple preg replace to generate a filesystem-friendly path.
+ *
+ * @param string $path
+ * @return string 
+ */
+function node_gallery_validate_filesystem_path($path = NULL) {
+  
+  if (! $path) {
+    return NULL;
+  }
+  // If transliteration is available, let it do the heavy lifting
+  if (module_exists('transliteration')) {
+    module_load_include('inc', 'transliteration');
+    $dest_array = array_filter(explode('/', $path));
+    foreach ($dest_array as $key => $dir) {
+      $dest_array[$key] = transliteration_clean_filename($dir);
+    }
+    $validated_path = implode('/', $dest_array);
+  }
+  else {
+    $validated_path = preg_replace('/[^a-zA-Z0-9._]/', '', str_replace(' ', '_', $path));
+  }
+  return $validated_path;
+}
+
 function node_gallery_list($account = NULL, $gallery_config = NULL) {
   $uid = isset($account->uid) ? $account->uid : 0;
   $gallery_type = empty($gallery_config) ? '' : $gallery_config['gallery_type'];
@@ -194,9 +222,7 @@
     foreach ($_FILES['files']['name'] as $id => $name) {
       if (!empty($name)) {
         // An additional check to strip all invalid characters
-        // Bug report - http://drupal.org/node/484502
-        $_FILES['files']['name'][$id] = str_replace(' ', '_', $_FILES['files']['name'][$id]);
-        $_FILES['files']['name'][$id] = preg_replace('/[^a-zA-Z0-9._]/', '', $_FILES['files']['name'][$id]);
+        $_FILES['files']['name'][$id] = node_gallery_validate_filesystem_path($_FILES['files']['name'][$id]);
         
         // Make sure we have a filename after scripting bad characters
         if (strlen($_FILES['files']['name'][$id]) < 5) {
@@ -232,7 +258,10 @@
 function node_gallery_check_directory($gallery) {
   global $user;
   $gallery_directory = strtr($gallery->config['gallery_directory'], 
-     array('%uid' => $user->uid, '%username' => $user->name, '%gid' => $gallery->nid, '%gallery_name' => preg_replace('/[^a-zA-Z0-9._]/', '', str_replace(' ', '_', $gallery->title))));
+     array('%uid' => $user->uid, '%username' => $user->name, '%gid' => $gallery->nid, '%gallery_name' => $gallery->title));
+     
+  $gallery_directory = node_gallery_validate_filesystem_path($gallery_directory);
+  
   $directory = rtrim(file_directory_path() .'/'. $gallery_directory, '/\\');
   //recursive mkdir;
   if (!is_dir($directory)) {
