You are here

function node_gallery_validate_filesystem_path in Node Gallery 6.2

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.

Parameters

string $path:

Return value

string

2 calls to node_gallery_validate_filesystem_path()
node_gallery_check_directory in ./node_gallery.pages.inc
node_gallery_upload_images in ./node_gallery.pages.inc

File

./node_gallery.pages.inc, line 17
Node gallery pages.

Code

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;
}