Permalink
Browse files

BackwardsCompatibilityBreak - Renamed fFilesystem::createUniqueName()…

… to fFilesystem::makeUniqueName()
  • Loading branch information...
wbond committed Oct 1, 2008
1 parent 6329fae commit 5291446aa67ab7f9eb2843b21035fe1e7f23dd5f
Showing with 44 additions and 44 deletions.
  1. +1 −1 classes/fDirectory.php
  2. +2 −2 classes/fFile.php
  3. +38 −38 classes/fFilesystem.php
  4. +1 −1 classes/fImage.php
  5. +1 −1 classes/fORMFile.php
  6. +1 −1 classes/fUpload.php
View
@@ -338,7 +338,7 @@ public function rename($new_dirname, $overwrite)
);
}
if (!$overwrite) {
$new_dirname = fFilesystem::createUniqueName($new_dirname);
$new_dirname = fFilesystem::makeUniqueName($new_dirname);
}
} else {
$parent_dir = new fDirectory($info['dirname']);
View
@@ -233,7 +233,7 @@ public function duplicate($new_directory=NULL, $overwrite=NULL)
);
}
if (!$overwrite) {
$new_filename = fFilesystem::createUniqueName($new_filename);
$new_filename = fFilesystem::makeUniqueName($new_filename);
$check_dir_permissions = TRUE;
}
} else {
@@ -421,7 +421,7 @@ public function rename($new_filename, $overwrite)
);
}
if (!$overwrite) {
$new_filename = fFilesystem::createUniqueName($new_filename);
$new_filename = fFilesystem::makeUniqueName($new_filename);
}
} else {
$new_dir = new fDirectory($info['dirname']);
View
@@ -165,44 +165,6 @@ static public function convertToBytes($size)
}
/**
* Returns a unique name for a file
*
* @param string $file The filename to check
* @param string $new_extension The new extension for the filename, do not include .
* @return string The unique file name
*/
static public function createUniqueName($file, $new_extension=NULL)
{
$info = self::getPathInfo($file);
// Change the file extension
if ($new_extension !== NULL) {
$new_extension = ($new_extension) ? '.' . $new_extension : $new_extension;
$file = $info['dirname'] . $info['filename'] . $new_extension;
$info = self::getPathInfo($file);
}
// If there is an extension, be sure to add . before it
$extension = (!empty($info['extension'])) ? '.' . $info['extension'] : '';
// Remove _copy# from the filename to start
$file = preg_replace('#_copy(\d+)' . preg_quote($extension, '#') . '$#', $extension, $file);
// Look for a unique name by adding _copy# to the end of the file
while (file_exists($file)) {
$info = self::getPathInfo($file);
if (preg_match('#_copy(\d+)' . preg_quote($extension, '#') . '$#', $file, $match)) {
$file = preg_replace('#_copy(\d+)' . preg_quote($extension, '#') . '$#', '_copy' . ($match[1]+1) . $extension, $file);
} else {
$file = $info['dirname'] . $info['filename'] . '_copy1' . $extension;
}
}
return $file;
}
/**
* Takes the size of a file in bytes and returns a friendly size in b/kb/mb/gb/tb
*
@@ -313,6 +275,44 @@ static public function isInsideTransaction()
}
/**
* Returns a unique name for a file
*
* @param string $file The filename to check
* @param string $new_extension The new extension for the filename, do not include .
* @return string The unique file name
*/
static public function makeUniqueName($file, $new_extension=NULL)
{
$info = self::getPathInfo($file);
// Change the file extension
if ($new_extension !== NULL) {
$new_extension = ($new_extension) ? '.' . $new_extension : $new_extension;
$file = $info['dirname'] . $info['filename'] . $new_extension;
$info = self::getPathInfo($file);
}
// If there is an extension, be sure to add . before it
$extension = (!empty($info['extension'])) ? '.' . $info['extension'] : '';
// Remove _copy# from the filename to start
$file = preg_replace('#_copy(\d+)' . preg_quote($extension, '#') . '$#', $extension, $file);
// Look for a unique name by adding _copy# to the end of the file
while (file_exists($file)) {
$info = self::getPathInfo($file);
if (preg_match('#_copy(\d+)' . preg_quote($extension, '#') . '$#', $file, $match)) {
$file = preg_replace('#_copy(\d+)' . preg_quote($extension, '#') . '$#', '_copy' . ($match[1]+1) . $extension, $file);
} else {
$file = $info['dirname'] . $info['filename'] . '_copy1' . $extension;
}
}
return $file;
}
/**
* Saves an object to the identity map
*
View
@@ -949,7 +949,7 @@ public function saveChanges($new_image_type=NULL)
}
if ($new_image_type) {
$output_file = fFilesystem::createUniqueName($this->file, $new_image_type);
$output_file = fFilesystem::makeUniqueName($this->file, $new_image_type);
} else {
$output_file = $this->file;
}
View
@@ -509,7 +509,7 @@ static public function moveFromTemp($object, &$values, &$old_values, &$related_r
// If the file is in a temp dir, move it out
if (stripos($value->getDirectory()->getPath(), self::TEMP_DIRECTORY) !== FALSE) {
$new_filename = str_replace(self::TEMP_DIRECTORY, '', $value->getPath());
$new_filename = fFilesystem::createUniqueName($new_filename);
$new_filename = fFilesystem::makeUniqueName($new_filename);
$value->rename($new_filename, FALSE);
}
}
View
@@ -282,7 +282,7 @@ static public function upload($directory, $field, $index=NULL)
$file_name = strtolower($file_array['name']);
$file_name = preg_replace('#\s+#', '_', $file_name);
$file_name = preg_replace('#[^a-z0-9_\.-]#', '', $file_name);
$file_name = fFilesystem::createUniqueName($directory->getPath() . $file_name);
$file_name = fFilesystem::makeUniqueName($directory->getPath() . $file_name);
if (!@move_uploaded_file($file_array['tmp_name'], $file_name)) {
fCore::toss(

0 comments on commit 5291446

Please sign in to comment.