diff --git a/3.0/modules/movie_tools/controllers/admin_movie_tools.php b/3.0/modules/movie_tools/controllers/admin_movie_tools.php new file mode 100644 index 00000000..18d28753 --- /dev/null +++ b/3.0/modules/movie_tools/controllers/admin_movie_tools.php @@ -0,0 +1,99 @@ +_get_admin_form(); + $this->_print_view($form); + } + + public function save() { + access::verify_csrf(); + $form = $this->_get_admin_form(); + if ($form->validate()) { + $formats = movie_tools::get_formats(); + foreach ($formats as $id => $data) { + module::set_var("movie_tools", "allow_$id", ($form->formats->{$id}->value == 1)); + } + module::set_var("movie_tools", "custom_formats", + movie_tools::formats_string_to_json($form->formats->custom_formats->value)); + module::set_var("gallery", "movie_extract_frame_time", + $form->thumbs->extract_frame_time->value); + // All done - redirect with message. + message::success(t("Movie tools settings updated successfully")); + url::redirect("admin/movie_tools"); + } + // Something went wrong - print view from existing form. + $this->_print_view($form); + } + + private function _print_view($form) { + $view = new Admin_View("admin.html"); + $view->page_title = t("Movie tools"); + $view->content = new View("admin_movie_tools.html"); + $view->content->form = $this->_get_admin_form(); + $view->content->formats = + array_merge(movie_tools::get_default_formats(), movie_tools::get_formats()); + print $view; + } + + private function _get_admin_form() { + $form = new Forge("admin/movie_tools/save", "", "post", array("id" => "g-movie-tools-admin-form")); + + $formats = movie_tools::get_formats(); + $settings_formats = $form->group("formats")->label(t("Movie format supported")); + foreach ($formats as $id => $data) { + $settings_formats->checkbox($id) + ->label($data["name"]) + ->checked(module::get_var("movie_tools", "allow_$id", false)); + } + $settings_formats->input("custom_formats") + ->label(t("Additional movie formats (enter using the same formatting as the table above)")) + ->callback(array($this, "_validate_custom_formats")) + ->error_messages("valid_custom_formats", t("You must enter valid formats like the examples in the table")) + ->value(movie_tools::formats_json_to_string(module::get_var("movie_tools", "custom_formats", ""))); + + $settings_thumbs = $form->group("thumbs")->label(t("Movie thumbnails")); + $settings_thumbs->input("extract_frame_time") + ->label(t("Seconds from start of movie at which thumbnails are extracted (default: 3)")) + ->rules("required|valid_numeric") + ->callback(array($this, "_validate_extract_frame_time")) + ->error_messages("required", t("You must enter a number")) + ->error_messages("valid_numeric", t("You must enter a number")) + ->error_messages("valid_min", t("The value cannot be negative")) + ->value(module::get_var("gallery", "movie_extract_frame_time", 3)); + + $form->submit("save")->value(t("Save")); + return $form; + } + + function _validate_extract_frame_time($input) { + if ($input->value < 0) { + $input->add_error("valid_min", true); + } + } + + function _validate_custom_formats($input) { + if ($input->value && !movie_tools::formats_string_to_array($input->value)) { + // Input isn't empty, but doesn't parse correctly - it's invalid. + $input->add_error("valid_custom_formats", true); + } + } +} diff --git a/3.0/modules/movie_tools/helpers/movie_tools.php b/3.0/modules/movie_tools/helpers/movie_tools.php new file mode 100644 index 00000000..dc07258b --- /dev/null +++ b/3.0/modules/movie_tools/helpers/movie_tools.php @@ -0,0 +1,141 @@ + t("Supported by Flowplayer 3"), + "desc" => t("Formats that should be viewable with Gallery's standard movie player"), + "types" => array("mov" => "video/quicktime", + "f4v" => "video/x-m4v")); + $data["html5"] = array("name" => t("HTML5 video"), + "desc" => t("Along with MP4, generally considered 'HTML5-compatible' formats"), + "types" => array("webm" => "video/webm", + "ogv" => "video/ogg")); + $data["mts"] = array("name" => t("MPEG transport stream"), + "desc" => t("Not a standard web format, but still supported by FFMpeg"), + "types" => array("ts" => "video/mp2t", + "mts" => "video/mp2t", + "m2ts" => "video/mp2t")); + $data["mpeg"] = array("name" => t("MPEG-1 and MPEG-2"), + "desc" => t("Not a standard web format, but still supported by FFMpeg"), + "types" => array("mpe" => "video/mpeg", + "mpeg" => "video/mpeg", + "mpg" => "video/mpeg", + "m1v" => "video/mpeg", + "m2v" => "video/mpeg")); + $data["mpeg4"] = array("name" => t("Additional MPEG-4"), + "desc" => t("Not a standard web format, but still supported by FFMpeg"), + "types" => array("mp4v" => "video/mp4", + "mpg4" => "video/mp4")); + $data["msapple"] = array("name" => t("Microsoft and Apple"), + "desc" => t("Not a standard web format, but still supported by FFMpeg"), + "types" => array("qt" => "video/quicktime", + "wmv" => "video/x-ms-wmv", + "avi" => "video/x-msvideo", + "asf" => "video/x-ms-asf")); + $data["3gphone"] = array("name" => t("3G mobile phone video"), + "desc" => t("Not a standard web format, but still supported by FFMpeg"), + "types" => array("3gp" => "video/3gpp", + "3g2" => "video/3gpp2")); + return $data; + } + + /** + * Return data similar to that of the above function but for the default Gallery formats. + * These formats are not available as options; they're just used for display purposes. + */ + static function get_default_formats() { + $data = array(); + $data["default"] = array("name" => t("Gallery's defaults"), + "desc" => t("Enabled by default on all Gallery installations"), + "types" => array("mp4" => "video/mp4", + "flv" => "video/x-flv", + "m4v" => "video/x-m4v")); + return $data; + } + + /** + * Return formats string converted to array, e.g. convert "mp4 (video/mp4), webm (video/webm)" to + * array("mp4" => "video/mp4", "webm" => "video/webm") if the string is formatted correctly; + * return null if not. + */ + static function formats_string_to_array($input) { + $format_strings = explode(",", $input); + $formats = array(); + + foreach ($format_strings as $format_string) { + $format_string = strtolower(trim($format_string)); + if (!$format_string) { + // It's blank - skip it. + continue; + } + if (preg_match("|([0-9a-z]+)\s*\(([0-9a-z]+/[0-9a-z-]+)\)|", $format_string, $matches)) { + // It's valid - include it. + $formats[$matches[1]] = $matches[2]; + } else { + // It's invalid - break out of function and return null. + return null; + } + } + + return $formats; + } + + /** + * Return formats array as string, i.e. the inverse of the function above. + */ + static function formats_array_to_string($input) { + $formats = array(); + if (!$input) { + return array(); + } + foreach ($input as $extension => $mime_type) { + $formats[] = "$extension ($mime_type)"; + } + return implode(", ", $formats); + } + + /** + * Wrapper around formats_string_to_array() to convert straight to json and handle empty inputs. + */ + static function formats_string_to_json($input) { + $array = movie_tools::formats_string_to_array($input); + if ($array) { + return json_encode($array); + } else { + return ""; + } + } + + /** + * Wrapper around formats_array_to_string() to convert straight from json and handle empty inputs. + */ + static function formats_json_to_string($input) { + if ($input) { + return movie_tools::formats_array_to_string(json_decode($input, true)); + } else { + return ""; + } + } +} diff --git a/3.0/modules/movie_tools/helpers/movie_tools_event.php b/3.0/modules/movie_tools/helpers/movie_tools_event.php new file mode 100644 index 00000000..23eeb2b9 --- /dev/null +++ b/3.0/modules/movie_tools/helpers/movie_tools_event.php @@ -0,0 +1,42 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("movie_tools") + ->label(t("Movie tools")) + ->url(url::site("admin/movie_tools"))); + } + + static function movie_types_by_extension($types_by_extension_wrapper) { + $formats = movie_tools::get_formats(); + foreach ($formats as $id => $data) { + if (module::get_var("movie_tools", "allow_$id", false)) { + $types_by_extension_wrapper->types_by_extension = array_merge_recursive( + $types_by_extension_wrapper->types_by_extension, $data["types"]); + } + } + if ($custom_formats = module::get_var("movie_tools", "custom_formats", "")) { + $types_by_extension_wrapper->types_by_extension = array_merge_recursive( + $types_by_extension_wrapper->types_by_extension, json_decode($custom_formats, true)); + } + } +} diff --git a/3.0/modules/movie_tools/helpers/movie_tools_installer.php b/3.0/modules/movie_tools/helpers/movie_tools_installer.php new file mode 100644 index 00000000..4edb0c8e --- /dev/null +++ b/3.0/modules/movie_tools/helpers/movie_tools_installer.php @@ -0,0 +1,39 @@ + $data) { + module::set_var("movie_tools", "allow_$id", 0); + } + } + + static function can_activate() { + $messages = array(); + if (module::get_version("gallery") < 56) { + $messages["warn"][] = t("Movie Tools requires Gallery v3.0.5 or newer."); + } + return $messages; + } + + static function uninstall() { + module::clear_all_vars("movie_tools"); + } +} diff --git a/3.0/modules/movie_tools/module.info b/3.0/modules/movie_tools/module.info new file mode 100644 index 00000000..4974a381 --- /dev/null +++ b/3.0/modules/movie_tools/module.info @@ -0,0 +1,7 @@ +name = "Movie Tools" +description = "Add support for custom movie thumbs and additional movie formats" +version = 1 +author_name = "Shad Laws" +author_url = "" +info_url = "http://codex.galleryproject.org/Gallery3:Modules:movie_tools" +discuss_url = "" diff --git a/3.0/modules/movie_tools/views/admin_movie_tools.html.php b/3.0/modules/movie_tools/views/admin_movie_tools.html.php new file mode 100644 index 00000000..5e9e8d1d --- /dev/null +++ b/3.0/modules/movie_tools/views/admin_movie_tools.html.php @@ -0,0 +1,37 @@ + +
+

+

+ +

+

+ + + + +

+

+ + + + +

+

+ + + + + + + $data): ?> + + + + + + +
CategoryDescriptionFormats
+

+ + +