diff options
author | Bharat Mediratta <bharat@menalto.com> | 2012-05-05 19:34:01 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2012-05-05 19:34:01 -0700 |
commit | ef4dbd18af218a3c68a776122108af4b0d0191a4 (patch) | |
tree | bc7d4909608a6d1a2a673e5ae7f352ec9baf0623 /modules/gallery/helpers | |
parent | 4e3bcf52162d83a06c5e6f932fefea4f29b5135d (diff) |
Fix extension-swapping code for files that have extensions that are
not 3 characters long. Fixes #1845.
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r-- | modules/gallery/helpers/graphics.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/legal_file.php | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 7e0bbbea..27ee124a 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -156,7 +156,7 @@ class graphics_Core { foreach ($ops as $target => $output_file) { if ($input_item->is_movie()) { // Convert the movie to a JPG first - $output_file = preg_replace("/...$/", "jpg", $output_file); + $output_file = legal_file::change_extension($output_file, "jpg"); try { movie::extract_frame($input_file, $output_file); } catch (Exception $e) { diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php index 6ec65e97..af6472ca 100644 --- a/modules/gallery/helpers/legal_file.php +++ b/modules/gallery/helpers/legal_file.php @@ -80,4 +80,16 @@ class legal_file_Core { module::event("legal_movie_types", $types_wrapper); return $types_wrapper->types; } + + /** + * Convert the extension of a filename. If the original filename has no + * extension, add the new one to the end. + */ + static function change_extension($filename, $new_ext) { + if (strpos($filename, ".") === false) { + return "{$filename}.{$new_ext}"; + } else { + return preg_replace("/\..*?$/", ".{$new_ext}", $filename); + } + } } |