1
0

Add new Movie Tools module. Requires Gallery v3.0.5 or greater (v56+).

@todo: update discuss_url in module.info once there is one.
This commit is contained in:
shadlaws 2013-02-22 20:01:11 +01:00
parent daf1f63616
commit 1edde80222
6 changed files with 365 additions and 0 deletions

View File

@ -0,0 +1,99 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2013 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Admin_Movie_Tools_Controller extends Admin_Controller {
public function index() {
// Print screen from new form.
$form = $this->_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);
}
}
}

View File

@ -0,0 +1,141 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2013 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class movie_tools_Core {
/**
* Return an array containing all of the data for the optional movie formats. This is used
* many other places in the module.
*/
static function get_formats() {
$data = array();
$data["fp3"] = array("name" => 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 "";
}
}
}

View File

@ -0,0 +1,42 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2013 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class movie_tools_event_Core {
static function admin_menu($menu, $theme) {
$menu->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));
}
}
}

View File

@ -0,0 +1,39 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2013 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class movie_tools_installer {
static function install() {
$formats = movie_tools::get_formats();
foreach ($formats as $id => $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");
}
}

View File

@ -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 = ""

View File

@ -0,0 +1,37 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div id="g-movie-tools-admin" class="g-block ui-helper-clearfix">
<h1> <?= t("Movie tools settings") ?> </h1>
<p>
<?= t("Movie tools allows you to add support for additional movie formats and customize when movie thumbnails are extracted.") ?>
</p>
<p>
<?= t("A table of common movie formats is given below, all of which can be enabled as desired.") ?>
<?= t("In addition, you can specify additional movie formats not on the table.") ?>
<?= t("If Gallery is unable to extract a thumbnail from a new movie type, it will use a placeholder.") ?>
<?= t("If Gallery is unable to play a movie, a download link will be provided to the user instead.") ?>
</p>
<p>
<b><?= t("Technical details:")?></b>
<?= t("If the movie is shorter than the time specified, the thumbnail will be taken from the start of the movie.") ?>
<?= t("Also, if you want to disable a previously-supported movie type, it's recommended to first delete any movies if that type.") ?>
<?= t("Otherwise, Gallery could act strangely with the now-unsupported movies.") ?>
</p>
<p>
<table>
<tr>
<td><b>Category</b></td>
<td><b>Description</b></td>
<td><b>Formats</b></td>
</tr>
<? foreach ($formats as $id => $data): ?>
<tr>
<td><?= $data["name"] ?></td>
<td><?= $data["desc"] ?></td>
<td><?= movie_tools::formats_array_to_string($data["types"]) ?></td>
</tr>
<? endforeach; ?>
</table>
</p>
<?= $form ?>
</div>