diff options
| author | shadlaws <shad@shadlaws.com> | 2012-12-16 18:11:01 +0100 |
|---|---|---|
| committer | shadlaws <shad@shadlaws.com> | 2012-12-16 18:11:01 +0100 |
| commit | 94b26e506c339f50b8d094057bffc1877a79afa9 (patch) | |
| tree | 6926ba85de8269983e09b8ea906aceb0c241087f /modules/gallery/helpers/legal_file.php | |
| parent | 7c62c67d56e854f69a411dd56c48ef066f951c48 (diff) | |
[#1924, #1925, #1927 - enhance compatibility with movies (movie helper) and file types (legal_file helper)]
bug fix: modify movie.php helper to take DAR (display aspect ratio) into account in get_file_metadata
bug fix / enhancement: add duration to get_file_metadata output
bug fix: modify movie.php helper to use correct resolution and duration from get_file_metadata in extract_frame
bug fix: modify movie.php helper to be more robust against ffmpeg failures and limitations, including adding "-threads 1" argument if needed
enhancement: modified to include ordered maps of extensions to MIME types (get_photo_types_by_extension and get_movie_types_by_extension functions), modified get_file_metadata in movie and photo helpers to use them
gallery_installer, module.info, install.sql: updated to v52 with m4v mime correction code (was video/mp4)
Diffstat (limited to 'modules/gallery/helpers/legal_file.php')
| -rw-r--r-- | modules/gallery/helpers/legal_file.php | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php index bd48d7b7..b3622764 100644 --- a/modules/gallery/helpers/legal_file.php +++ b/modules/gallery/helpers/legal_file.php @@ -19,11 +19,53 @@ */ class legal_file_Core { /** + * Create a default list of allowed photo MIME types paired with their extensions and then let + * modules modify it. This is an ordered map, mapping extensions to their MIME types. + * Extensions cannot be duplicated, but MIMEs can (e.g. jpeg and jpg both map to image/jpeg). + * + * @param string $extension (opt.) - return MIME of extension; if not given, return complete array + */ + static function get_photo_types_by_extension($extension=NULL) { + $types_by_extension_wrapper = new stdClass(); + $types_by_extension_wrapper->types_by_extension = array( + "jpg" => "image/jpeg", "jpeg" => "image/jpeg", "gif" => "image/gif", "png" => "image/png"); + module::event("photo_types_by_extension", $types_by_extension_wrapper); + if ($extension) { + // return matching MIME type + return $types_by_extension_wrapper->types_by_extension[$extension]; + } else { + // return complete array + return $types_by_extension_wrapper->types_by_extension; + } + } + + /** + * Create a default list of allowed movie MIME types paired with their extensions and then let + * modules modify it. This is an ordered map, mapping extensions to their MIME types. + * Extensions cannot be duplicated, but MIMEs can (e.g. jpeg and jpg both map to image/jpeg). + * + * @param string $extension (opt.) - return MIME of extension; if not given, return complete array + */ + static function get_movie_types_by_extension($extension=NULL) { + $types_by_extension_wrapper = new stdClass(); + $types_by_extension_wrapper->types_by_extension = array( + "flv" => "video/x-flv", "mp4" => "video/mp4", "m4v" => "video/x-m4v"); + module::event("movie_types_by_extension", $types_by_extension_wrapper); + if ($extension) { + // return matching MIME type + return $types_by_extension_wrapper->types_by_extension[$extension]; + } else { + // return complete array + return $types_by_extension_wrapper->types_by_extension; + } + } + + /** * Create a default list of allowed photo extensions and then let modules modify it. */ static function get_photo_extensions() { $extensions_wrapper = new stdClass(); - $extensions_wrapper->extensions = array("gif", "jpg", "jpeg", "png"); + $extensions_wrapper->extensions = array_keys(legal_file::get_photo_types_by_extension()); module::event("legal_photo_extensions", $extensions_wrapper); return $extensions_wrapper->extensions; } @@ -33,7 +75,7 @@ class legal_file_Core { */ static function get_movie_extensions() { $extensions_wrapper = new stdClass(); - $extensions_wrapper->extensions = array("flv", "mp4", "m4v"); + $extensions_wrapper->extensions = array_keys(legal_file::get_movie_types_by_extension()); module::event("legal_movie_extensions", $extensions_wrapper); return $extensions_wrapper->extensions; } @@ -63,20 +105,25 @@ class legal_file_Core { /** * Create a default list of allowed photo MIME types and then let modules modify it. + * Can be used to add legal alternatives for default MIME types. + * (e.g. flv maps to video/x-flv by default, but video/flv is still legal). */ static function get_photo_types() { $types_wrapper = new stdClass(); - $types_wrapper->types = array("image/jpeg", "image/gif", "image/png"); + $types_wrapper->types = array_values(legal_file::get_photo_types_by_extension()); module::event("legal_photo_types", $types_wrapper); return $types_wrapper->types; } /** * Create a default list of allowed movie MIME types and then let modules modify it. + * Can be used to add legal alternatives for default MIME types. + * (e.g. flv maps to video/x-flv by default, but video/flv is still legal). */ static function get_movie_types() { $types_wrapper = new stdClass(); - $types_wrapper->types = array("video/flv", "video/x-flv", "video/mp4"); + $types_wrapper->types = array_values(legal_file::get_movie_types_by_extension()); + $types_wrapper->types[] = "video/flv"; module::event("legal_movie_types", $types_wrapper); return $types_wrapper->types; } |
