Initial commit of videos module.
This commit is contained in:
parent
250ed88738
commit
85fbf87b55
96
modules/videos/controllers/admin_videos.php
Normal file
96
modules/videos/controllers/admin_videos.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 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_Videos_Controller extends Admin_Controller {
|
||||
public function index() {
|
||||
$view = new Admin_View("admin.html");
|
||||
$view->page_title = t("Add videos from server");
|
||||
$view->content = new View("admin_videos.html");
|
||||
$view->content->form = $this->_get_admin_form();
|
||||
$paths = unserialize(module::get_var("videos", "authorized_paths", "a:0:{}"));
|
||||
$view->content->paths = array_keys($paths);
|
||||
|
||||
print $view;
|
||||
}
|
||||
|
||||
public function add_path() {
|
||||
access::verify_csrf();
|
||||
|
||||
$form = $this->_get_admin_form();
|
||||
$paths = unserialize(module::get_var("videos", "authorized_paths", "a:0:{}"));
|
||||
if ($form->validate()) {
|
||||
if (is_link($form->add_path->path->value)) {
|
||||
$form->add_path->path->add_error("is_symlink", 1);
|
||||
} else if (!is_readable($form->add_path->path->value)) {
|
||||
$form->add_path->path->add_error("not_readable", 1);
|
||||
} else {
|
||||
$path = $form->add_path->path->value;
|
||||
$paths[$path] = 1;
|
||||
module::set_var("videos", "authorized_paths", serialize($paths));
|
||||
message::success(t("Added path %path", array("path" => $path)));
|
||||
videos::check_config($paths);
|
||||
url::redirect("admin/videos");
|
||||
}
|
||||
}
|
||||
|
||||
$view = new Admin_View("admin.html");
|
||||
$view->content = new View("admin_videos.html");
|
||||
$view->content->form = $form;
|
||||
$view->content->paths = array_keys($paths);
|
||||
print $view;
|
||||
}
|
||||
|
||||
public function remove_path() {
|
||||
access::verify_csrf();
|
||||
|
||||
$path = Input::instance()->get("path");
|
||||
$paths = unserialize(module::get_var("videos", "authorized_paths"));
|
||||
if (isset($paths[$path])) {
|
||||
unset($paths[$path]);
|
||||
message::success(t("Removed path %path", array("path" => $path)));
|
||||
module::set_var("videos", "authorized_paths", serialize($paths));
|
||||
videos::check_config($paths);
|
||||
}
|
||||
url::redirect("admin/videos");
|
||||
}
|
||||
|
||||
public function autocomplete() {
|
||||
$directories = array();
|
||||
$path_prefix = Input::instance()->get("q");
|
||||
foreach (glob("{$path_prefix}*") as $file) {
|
||||
if (is_dir($file) && !is_link($file)) {
|
||||
$directories[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
print implode("\n", $directories);
|
||||
}
|
||||
|
||||
private function _get_admin_form() {
|
||||
$form = new Forge("admin/videos/add_path", "", "post",
|
||||
array("id" => "g-server-add-admin-form", "class" => "g-short-form"));
|
||||
$add_path = $form->group("add_path");
|
||||
$add_path->input("path")->label(t("Path"))->rules("required")->id("g-path")
|
||||
->error_messages("not_readable", t("This directory is not readable by the webserver"))
|
||||
->error_messages("is_symlink", t("Symbolic links are not allowed"));
|
||||
$add_path->submit("add")->value(t("Add Path"));
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
298
modules/videos/controllers/videos.php
Normal file
298
modules/videos/controllers/videos.php
Normal file
@ -0,0 +1,298 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 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 Videos_Controller extends Admin_Controller {
|
||||
public function browse($id) {
|
||||
$paths = unserialize(module::get_var("videos", "authorized_paths"));
|
||||
foreach (array_keys($paths) as $path) {
|
||||
$files[] = $path;
|
||||
}
|
||||
|
||||
$item = ORM::factory("item", $id);
|
||||
$view = new View("videos_tree_dialog.html");
|
||||
$view->item = $item;
|
||||
$view->tree = new View("videos_tree.html");
|
||||
$view->tree->files = $files;
|
||||
$view->tree->parents = array();
|
||||
print $view;
|
||||
}
|
||||
|
||||
public function children() {
|
||||
$path = Input::instance()->get("path");
|
||||
|
||||
$tree = new View("videos_tree.html");
|
||||
$tree->files = array();
|
||||
$tree->parents = array();
|
||||
|
||||
// Make a tree with the parents back up to the authorized path, and all the children under the
|
||||
// current path.
|
||||
if (videos::is_valid_path($path)) {
|
||||
$tree->parents[] = $path;
|
||||
while (videos::is_valid_path(dirname($tree->parents[0]))) {
|
||||
array_unshift($tree->parents, dirname($tree->parents[0]));
|
||||
}
|
||||
|
||||
$glob_path = str_replace(array("{", "}", "[", "]"), array("\{", "\}", "\[", "\]"), $path);
|
||||
foreach (glob("$glob_path/*") as $file) {
|
||||
if (!is_readable($file)) {
|
||||
continue;
|
||||
}
|
||||
if (!is_dir($file)) {
|
||||
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
|
||||
//if (!in_array($ext, array("gif", "jpeg", "jpg", "png", "flv", "mp4", "m4v"))) {
|
||||
if (!in_array($ext, unserialize(module::get_var("videos", "allowed_extensions")))) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$tree->files[] = $file;
|
||||
}
|
||||
} else {
|
||||
// Missing or invalid path; print out the list of authorized path
|
||||
$paths = unserialize(module::get_var("videos", "authorized_paths"));
|
||||
foreach (array_keys($paths) as $path) {
|
||||
$tree->files[] = $path;
|
||||
}
|
||||
}
|
||||
print $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin the task of adding files.
|
||||
*/
|
||||
public function start() {
|
||||
access::verify_csrf();
|
||||
$item = ORM::factory("item", Input::instance()->get("item_id"));
|
||||
|
||||
foreach (Input::instance()->post("paths") as $path) {
|
||||
if (videos::is_valid_path($path)) {
|
||||
$paths[] = array($path, null);
|
||||
}
|
||||
}
|
||||
|
||||
$task_def = Task_Definition::factory()
|
||||
->callback("Videos_Controller::add")
|
||||
->description(t("Add videos from the local server"))
|
||||
->name(t("Add from server"));
|
||||
$task = task::create($task_def, array("item_id" => $item->id, "queue" => $paths));
|
||||
|
||||
json::reply(
|
||||
array("result" => "started",
|
||||
"status" => (string)$task->status,
|
||||
"url" => url::site("videos/run/$task->id?csrf=" . access::csrf_token())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the task of adding files
|
||||
*/
|
||||
function run($task_id) {
|
||||
access::verify_csrf();
|
||||
|
||||
$task = ORM::factory("task", $task_id);
|
||||
if (!$task->loaded() || $task->owner_id != identity::active_user()->id) {
|
||||
access::forbidden();
|
||||
}
|
||||
|
||||
$task = task::run($task_id);
|
||||
// Prevent the JavaScript code from breaking by forcing a period as
|
||||
// decimal separator for all locales with sprintf("%F", $value).
|
||||
json::reply(array("done" => (bool)$task->done,
|
||||
"status" => (string)$task->status,
|
||||
"percent_complete" => sprintf("%F", $task->percent_complete)));
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the task code that adds photos and albums. It first examines all the target files
|
||||
* and creates a set of Server_Add_File_Models, then runs through the list of models and adds
|
||||
* them one at a time.
|
||||
*/
|
||||
static function add($task) {
|
||||
$mode = $task->get("mode", "init");
|
||||
$start = microtime(true);
|
||||
|
||||
switch ($mode) {
|
||||
case "init":
|
||||
$task->set("mode", "build-file-list");
|
||||
$task->percent_complete = 0;
|
||||
$task->status = t("Starting up");
|
||||
batch::start();
|
||||
break;
|
||||
|
||||
case "build-file-list": // 0% to 10%
|
||||
// We can't fit an arbitrary number of paths in a task, so store them in a separate table.
|
||||
// Don't use an iterator here because we can't get enough control over it when we're dealing
|
||||
// with a deep hierarchy and we don't want to go over our time quota. The queue is in the
|
||||
// form [path, parent_id] where the parent_id refers to another Server_Add_File_Model. We
|
||||
// have this extra level of abstraction because we don't know its Item_Model id yet.
|
||||
$queue = $task->get("queue");
|
||||
$paths = unserialize(module::get_var("videos", "authorized_paths"));
|
||||
|
||||
while ($queue && microtime(true) - $start < 0.5) {
|
||||
list($file, $parent_entry_id) = array_shift($queue);
|
||||
// Ignore the staging directories as directories to be imported.
|
||||
if (empty($paths[$file])) {
|
||||
$entry = ORM::factory("videos_file");
|
||||
$entry->task_id = $task->id;
|
||||
$entry->file = $file;
|
||||
$entry->parent_id = $parent_entry_id;
|
||||
$entry->save();
|
||||
$entry_id = $entry->id;
|
||||
} else {
|
||||
$entry_id = null;
|
||||
}
|
||||
|
||||
$file = preg_quote($file);
|
||||
foreach (glob("$file/*") as $child) {
|
||||
if (is_dir($child)) {
|
||||
$queue[] = array($child, $entry_id);
|
||||
} else {
|
||||
$ext = strtolower(pathinfo($child, PATHINFO_EXTENSION));
|
||||
//if (in_array($ext, array("gif", "jpeg", "jpg", "png", "flv", "mp4", "m4v")) &&
|
||||
if (in_array($ext, unserialize(module::get_var("videos", "allowed_extensions"))) &&
|
||||
filesize($child) > 0) {
|
||||
$child_entry = ORM::factory("videos_file");
|
||||
$child_entry->task_id = $task->id;
|
||||
$child_entry->file = $child;
|
||||
$child_entry->parent_id = $entry_id;
|
||||
$child_entry->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We have no idea how long this can take because we have no idea how deep the tree
|
||||
// hierarchy rabbit hole goes. Leave ourselves room here for 100 iterations and don't go
|
||||
// over 10% in percent_complete.
|
||||
$task->set("queue", $queue);
|
||||
$task->percent_complete = min($task->percent_complete + 0.1, 10);
|
||||
$task->status = t2(
|
||||
"Found one file", "Found %count files",
|
||||
ORM::factory("videos_file")->where("task_id", "=", $task->id)->count_all());
|
||||
|
||||
if (!$queue) {
|
||||
$task->set("mode", "add-files");
|
||||
$task->set(
|
||||
"total_files",
|
||||
ORM::factory("videos_file")->where("task_id", "=", $task->id)->count_all());
|
||||
$task->percent_complete = 10;
|
||||
}
|
||||
break;
|
||||
|
||||
case "add-files": // 10% to 100%
|
||||
$completed_files = $task->get("completed_files", 0);
|
||||
$total_files = $task->get("total_files");
|
||||
|
||||
// Ordering by id ensures that we add them in the order that we created the entries, which
|
||||
// will create albums first. Ignore entries which already have an Item_Model attached,
|
||||
// they're done.
|
||||
$entries = ORM::factory("videos_file")
|
||||
->where("task_id", "=", $task->id)
|
||||
->where("item_id", "IS", null)
|
||||
->order_by("id", "ASC")
|
||||
->limit(10)
|
||||
->find_all();
|
||||
if ($entries->count() == 0) {
|
||||
// Out of entries, we're done.
|
||||
$task->set("mode", "done");
|
||||
}
|
||||
|
||||
$owner_id = identity::active_user()->id;
|
||||
foreach ($entries as $entry) {
|
||||
if (microtime(true) - $start > 0.5) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Look up the parent item for this entry. By now it should exist, but if none was
|
||||
// specified, then this belongs as a child of the current item.
|
||||
$parent_entry = ORM::factory("videos_file", $entry->parent_id);
|
||||
if (!$parent_entry->loaded()) {
|
||||
$parent = ORM::factory("item", $task->get("item_id"));
|
||||
} else {
|
||||
$parent = ORM::factory("item", $parent_entry->item_id);
|
||||
}
|
||||
|
||||
$name = basename($entry->file);
|
||||
$title = item::convert_filename_to_title($name);
|
||||
if (is_dir($entry->file)) {
|
||||
$album = ORM::factory("item");
|
||||
$album->type = "album";
|
||||
$album->parent_id = $parent->id;
|
||||
$album->name = $name;
|
||||
$album->title = $title;
|
||||
$album->owner_id = $owner_id;
|
||||
$album->save();
|
||||
$entry->item_id = $album->id;
|
||||
} else {
|
||||
try {
|
||||
$extension = strtolower(pathinfo($name, PATHINFO_EXTENSION));
|
||||
if (in_array($extension, unserialize(module::get_var("videos", "allowed_extensions")))) {
|
||||
$movie = ORM::factory("item");
|
||||
$movie->type = "movie";
|
||||
$movie->parent_id = $parent->id;
|
||||
$movie->set_data_file($entry->file);
|
||||
$movie->name = $name;
|
||||
$movie->title = $title;
|
||||
$movie->owner_id = $owner_id;
|
||||
$movie->save();
|
||||
$entry->item_id = $movie->id;
|
||||
$items_video = ORM::factory("items_video");
|
||||
$items_video->item_id = $movie->id;
|
||||
$items_video->save();
|
||||
if (file_exists($entry->file . ".flv")) {
|
||||
copy($entry->file . ".flv", $movie->resize_path() . ".flv");
|
||||
}
|
||||
} else {
|
||||
// This should never happen, because we don't add stuff to the list that we can't
|
||||
// process. But just in, case.. set this to a non-null value so that we skip this
|
||||
// entry.
|
||||
$entry->item_id = 0;
|
||||
$task->log("Skipping unknown file type: $entry->file");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// This can happen if a photo file is invalid, like a BMP masquerading as a .jpg
|
||||
$entry->item_id = 0;
|
||||
$task->log("Skipping invalid file: $entry->file");
|
||||
}
|
||||
}
|
||||
|
||||
$completed_files++;
|
||||
$entry->save();
|
||||
}
|
||||
$task->set("completed_files", $completed_files);
|
||||
$task->status = t("Adding photos / albums (%completed of %total)",
|
||||
array("completed" => $completed_files,
|
||||
"total" => $total_files));
|
||||
$task->percent_complete = $total_files ? 10 + 100 * ($completed_files / $total_files) : 100;
|
||||
break;
|
||||
|
||||
case "done":
|
||||
batch::stop();
|
||||
$task->done = true;
|
||||
$task->state = "success";
|
||||
$task->percent_complete = 100;
|
||||
db::build()
|
||||
->delete("videos_files")
|
||||
->where("task_id", "=", $task->id)
|
||||
->execute();
|
||||
message::info(t2("Successfully added one file",
|
||||
"Successfully added %count files",
|
||||
$task->get("completed_files")));
|
||||
}
|
||||
}
|
||||
}
|
38
modules/videos/css/videos.css
Normal file
38
modules/videos/css/videos.css
Normal file
@ -0,0 +1,38 @@
|
||||
#g-server-add button {
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
|
||||
#g-server-add-tree {
|
||||
cursor: pointer;
|
||||
padding-left: 4px;
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
#g-server-add-tree li {
|
||||
padding: 0;
|
||||
float: none;
|
||||
}
|
||||
|
||||
#g-server-add-tree span.selected {
|
||||
background: #ddd;
|
||||
}
|
||||
|
||||
#g-server-add-tree {
|
||||
border: 1px solid #ccc;
|
||||
height: 20em;
|
||||
overflow: auto;
|
||||
margin-bottom: .5em;
|
||||
padding: .5em;
|
||||
}
|
||||
|
||||
#g-server-add ul ul li {
|
||||
padding-left: 1.2em;
|
||||
}
|
||||
|
||||
#g-server-add-paths li .ui-icon {
|
||||
margin-top: .4em;
|
||||
}
|
||||
|
||||
#g-server-add-admin-form .textbox {
|
||||
width: 400px;
|
||||
}
|
49
modules/videos/helpers/videos.php
Normal file
49
modules/videos/helpers/videos.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 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 videos_Core {
|
||||
static function check_config($paths=null) {
|
||||
if ($paths === null) {
|
||||
$paths = unserialize(module::get_var("videos", "authorized_paths"));
|
||||
}
|
||||
if (empty($paths)) {
|
||||
site_status::warning(
|
||||
t("Videos needs configuration. <a href=\"%url\">Configure it now!</a>",
|
||||
array("url" => html::mark_clean(url::site("admin/videos")))),
|
||||
"videos_configuration");
|
||||
} else {
|
||||
site_status::clear("videos_configuration");
|
||||
}
|
||||
}
|
||||
|
||||
static function is_valid_path($path) {
|
||||
if (!is_readable($path) || is_link($path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$authorized_paths = unserialize(module::get_var("videos", "authorized_paths"));
|
||||
foreach (array_keys($authorized_paths) as $valid_path) {
|
||||
if (strpos($path, $valid_path) === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
84
modules/videos/helpers/videos_event.php
Normal file
84
modules/videos/helpers/videos_event.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 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 videos_event_Core {
|
||||
static function admin_menu($menu, $theme) {
|
||||
$menu->get("settings_menu")
|
||||
->append(Menu::factory("link")
|
||||
->id("videos")
|
||||
->label(t("Videos"))
|
||||
->url(url::site("admin/videos")));
|
||||
}
|
||||
|
||||
static function site_menu($menu, $theme) {
|
||||
$item = $theme->item();
|
||||
$paths = unserialize(module::get_var("videos", "authorized_paths"));
|
||||
|
||||
if ($item && identity::active_user()->admin && $item->is_album() && !empty($paths) &&
|
||||
is_writable($item->is_album() ? $item->file_path() : $item->parent()->file_path())) {
|
||||
$menu->get("add_menu")
|
||||
->append(Menu::factory("dialog")
|
||||
->id("videos")
|
||||
->label(t("Add videos"))
|
||||
->url(url::site("videos/browse/$item->id")));
|
||||
}
|
||||
}
|
||||
|
||||
static function item_before_delete($item) {
|
||||
// If deleting a video, make sure the resize is deleted as well, if it exists.
|
||||
if ($item->is_movie()) {
|
||||
$items_video = ORM::factory("items_video")
|
||||
->where("item_id", "=", $item->id)
|
||||
->find();
|
||||
if ($items_video->loaded() && file_exists($item->resize_path() . ".flv")) {
|
||||
@unlink($item->resize_path() . ".flv");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static function item_updated($old, $new) {
|
||||
// When updating a video, check and see if the file name is being changed.
|
||||
// If so, check for and modify any corresponding resized video
|
||||
|
||||
if ($old->is_movie()) {
|
||||
if ($old->file_path() != $new->file_path()) {
|
||||
$items_video = ORM::factory("items_video")
|
||||
->where("item_id", "=", $old->id)
|
||||
->find();
|
||||
if ($items_video->loaded() && file_exists($old->resize_path() . ".flv")) {
|
||||
@rename($old->resize_path() . ".flv", $new->resize_path() . ".flv");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static function item_moved($item, $old_parent) {
|
||||
// When moving an video, also move the flash resize, if it exists.
|
||||
|
||||
if ($item->is_movie()) {
|
||||
$items_video = ORM::factory("items_video")
|
||||
->where("item_id", "=", $item->id)
|
||||
->find();
|
||||
$old_resize_path = $old_parent->resize_path() . "/" . $item->name . ".flv";
|
||||
if ($items_video->loaded() && file_exists($old_resize_path)) {
|
||||
@rename($old_resize_path, $item->resize_path() . ".flv");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
52
modules/videos/helpers/videos_installer.php
Normal file
52
modules/videos/helpers/videos_installer.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 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 videos_installer {
|
||||
static function install() {
|
||||
$db = Database::instance();
|
||||
$db->query("CREATE TABLE {videos_files} (
|
||||
`id` int(9) NOT NULL auto_increment,
|
||||
`file` varchar(255) NOT NULL,
|
||||
`item_id` int(9),
|
||||
`parent_id` int(9),
|
||||
`task_id` int(9) NOT NULL,
|
||||
PRIMARY KEY (`id`))
|
||||
DEFAULT CHARSET=utf8;");
|
||||
$db->query("CREATE TABLE {items_videos} (
|
||||
`id` int(9) NOT NULL auto_increment,
|
||||
`item_id` int(9) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY (`item_id`, `id`))
|
||||
DEFAULT CHARSET=utf8;");
|
||||
module::set_var("videos", "allowed_extensions", serialize(array("avi", "mpg", "mpeg", "mov", "wmv", "asf", "mts")));
|
||||
module::set_version("videos", 1);
|
||||
videos::check_config();
|
||||
}
|
||||
|
||||
static function deactivate() {
|
||||
site_status::clear("videos_configuration");
|
||||
}
|
||||
|
||||
static function uninstall() {
|
||||
$db = Database::instance();
|
||||
$db->query("DROP TABLE IF EXISTS {videos_files};");
|
||||
$db->query("DROP TABLE IF EXISTS {items_videos};");
|
||||
module::delete("videos");
|
||||
}
|
||||
}
|
55
modules/videos/helpers/videos_theme.php
Normal file
55
modules/videos/helpers/videos_theme.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 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 videos_theme_Core {
|
||||
static function head($theme) {
|
||||
if (identity::active_user()->admin) {
|
||||
$theme->css("videos.css");
|
||||
$theme->script("videos.js");
|
||||
}
|
||||
|
||||
$item = $theme->item();
|
||||
if ($item && $item->is_movie()) {
|
||||
$items_video = ORM::factory("items_video")
|
||||
->where("item_id", "=", $item->id)
|
||||
->find();
|
||||
if ($items_video->loaded()) {
|
||||
$view = new View("videos_display_js.html");
|
||||
//$view->embed_code = addslashes($embedded_video->embed_code);
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static function admin_head($theme) {
|
||||
$head = array();
|
||||
if (strpos(Router::$current_uri, "admin/videos") !== false) {
|
||||
$theme->css("videos.css");
|
||||
$theme->css("jquery.autocomplete.css");
|
||||
$base = url::site("__ARGS__");
|
||||
$csrf = access::csrf_token();
|
||||
$head[] = "<script type=\"text/javascript\"> var base_url = \"$base\"; var csrf = \"$csrf\";</script>";
|
||||
|
||||
$theme->script("jquery.autocomplete.js");
|
||||
$theme->script("admin_videos.js");
|
||||
}
|
||||
|
||||
return implode("\n", $head);
|
||||
}
|
||||
}
|
8
modules/videos/js/admin_videos.js
Normal file
8
modules/videos/js/admin_videos.js
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Set up autocomplete on the server path list
|
||||
*
|
||||
*/
|
||||
$("document").ready(function() {
|
||||
$("#g-path").autocomplete(
|
||||
base_url.replace("__ARGS__", "admin/videos/autocomplete"), {max: 256});
|
||||
});
|
125
modules/videos/js/videos.js
Normal file
125
modules/videos/js/videos.js
Normal file
@ -0,0 +1,125 @@
|
||||
(function($) {
|
||||
$.widget("ui.gallery_server_add", {
|
||||
_init: function() {
|
||||
var self = this;
|
||||
$("#g-server-add-add-button", this.element).click(function(event) {
|
||||
event.preventDefault();
|
||||
$(".g-progress-bar", this.element).
|
||||
progressbar().
|
||||
progressbar("value", 0);
|
||||
$("#g-server-add-progress", this.element).slideDown("fast", function() { self.start_add(); });
|
||||
});
|
||||
$("#g-server-add-pause-button", this.element).click(function(event) {
|
||||
self.pause = true;
|
||||
$("#g-server-add-pause-button", this.element).hide();
|
||||
$("#g-server-add-continue-button", this.element).show();
|
||||
});
|
||||
$("#g-server-add-continue-button", this.element).click(function(event) {
|
||||
self.pause = false;
|
||||
$("#g-server-add-pause-button", this.element).show();
|
||||
$("#g-server-add-continue-button", this.element).hide();
|
||||
self.run_add();
|
||||
});
|
||||
$("#g-server-add-close-button", this.element).click(function(event) {
|
||||
$("#g-dialog").dialog("close");
|
||||
window.location.reload();
|
||||
});
|
||||
$("#g-server-add-tree span.g-directory", this.element).dblclick(function(event) {
|
||||
self.open_dir(event);
|
||||
});
|
||||
$("#g-server-add-tree span.g-file, #g-server-add-tree span.g-directory", this.element).click(function(event) {
|
||||
self.select_file(event);
|
||||
});
|
||||
$("#g-server-add-tree span.g-directory", this.element).dblclick(function(event) {
|
||||
self.open_dir(event);
|
||||
});
|
||||
$("#g-dialog").bind("dialogclose", function(event, ui) {
|
||||
window.location.reload();
|
||||
});
|
||||
},
|
||||
|
||||
taskURL: null,
|
||||
pause: false,
|
||||
|
||||
start_add: function() {
|
||||
var self = this;
|
||||
var paths = [];
|
||||
$.each($("span.selected", self.element), function () {
|
||||
paths.push($(this).attr("ref"));
|
||||
});
|
||||
|
||||
$("#g-server-add-add-button", this.element).hide();
|
||||
$("#g-server-add-pause-button", this.element).show();
|
||||
|
||||
$.ajax({
|
||||
url: START_URL,
|
||||
type: "POST",
|
||||
async: false,
|
||||
data: { "paths[]": paths },
|
||||
dataType: "json",
|
||||
success: function(data, textStatus) {
|
||||
$("#g-status").html(data.status);
|
||||
$(".g-progress-bar", self.element).progressbar("value", data.percent_complete);
|
||||
self.taskURL = data.url;
|
||||
setTimeout(function() { self.run_add(); }, 25);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
},
|
||||
|
||||
run_add: function () {
|
||||
var self = this;
|
||||
$.ajax({
|
||||
url: self.taskURL,
|
||||
async: false,
|
||||
dataType: "json",
|
||||
success: function(data, textStatus) {
|
||||
$("#g-status").html(data.status);
|
||||
$(".g-progress-bar", self.element).progressbar("value", data.percent_complete);
|
||||
if (data.done) {
|
||||
$("#g-server-add-progress", this.element).slideUp();
|
||||
$("#g-server-add-add-button", this.element).show();
|
||||
$("#g-server-add-pause-button", this.element).hide();
|
||||
$("#g-server-add-continue-button", this.element).hide();
|
||||
} else {
|
||||
if (!self.pause) {
|
||||
setTimeout(function() { self.run_add(); }, 25);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Load a new directory
|
||||
*/
|
||||
open_dir: function(event) {
|
||||
var self = this;
|
||||
var path = $(event.target).attr("ref");
|
||||
$.ajax({
|
||||
url: GET_CHILDREN_URL.replace("__PATH__", path),
|
||||
success: function(data, textStatus) {
|
||||
$("#g-server-add-tree", self.element).html(data);
|
||||
$("#g-server-add-tree span.g-directory", self.element).dblclick(function(event) {
|
||||
self.open_dir(event);
|
||||
});
|
||||
$("#g-server-add-tree span.g-file, #g-server-add-tree span.g-directory", this.element).click(function(event) {
|
||||
self.select_file(event);
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Manage file selection state.
|
||||
*/
|
||||
select_file: function (event) {
|
||||
$(event.target).toggleClass("selected");
|
||||
if ($("#g-server-add span.selected").length) {
|
||||
$("#g-server-add-add-button").enable(true).removeClass("ui-state-disabled");
|
||||
} else {
|
||||
$("#g-server-add-add-button").enable(false).addClass("ui-state-disabled");
|
||||
}
|
||||
}
|
||||
});
|
||||
})(jQuery);
|
22
modules/videos/models/items_video.php
Normal file
22
modules/videos/models/items_video.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 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 Items_video_Model extends ORM {
|
||||
}
|
21
modules/videos/models/videos_file.php
Normal file
21
modules/videos/models/videos_file.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 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 Videos_File_Model extends ORM {
|
||||
}
|
3
modules/videos/module.info
Normal file
3
modules/videos/module.info
Normal file
@ -0,0 +1,3 @@
|
||||
name = "Videos"
|
||||
description = "Allows authorized users to load videos directly from your web server"
|
||||
version = 1
|
21
modules/videos/views/admin_videos.html.php
Normal file
21
modules/videos/views/admin_videos.html.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
<div class="g-block">
|
||||
<h1> <?= t("Add from server administration") ?> </h1>
|
||||
<div class="g-block-content">
|
||||
<?= $form ?>
|
||||
<h2><?= t("Authorized paths") ?></h2>
|
||||
<ul id="g-server-add-paths">
|
||||
<? if (empty($paths)): ?>
|
||||
<li class="g-module-status g-info"><?= t("No authorized image source paths defined yet") ?></li>
|
||||
<? endif ?>
|
||||
<? foreach ($paths as $id => $path): ?>
|
||||
<li>
|
||||
<?= html::clean($path) ?>
|
||||
<a href="<?= url::site("admin/videos/remove_path?path=" . urlencode($path) . "&csrf=$csrf") ?>"
|
||||
id="icon_<?= $id ?>"
|
||||
class="g-remove-dir g-button"><span class="ui-icon ui-icon-trash"><?= t("delete") ?></span></a>
|
||||
</li>
|
||||
<? endforeach ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
33
modules/videos/views/movieplayer.html.php
Normal file
33
modules/videos/views/movieplayer.html.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
<?
|
||||
$items_video = ORM::factory("items_video")
|
||||
->where("item_id", "=", $item->id)
|
||||
->find();
|
||||
if ($items_video->loaded() && file_exists($item->resize_path() . ".flv")) {
|
||||
print html::anchor(str_replace("?m=", ".flv?m=", $item->resize_url(true)), "", $attrs);
|
||||
} else {
|
||||
print html::anchor($item->file_url(true), "", $attrs);
|
||||
}
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
flowplayer(
|
||||
"<?= $attrs["id"] ?>",
|
||||
{
|
||||
src: "<?= url::abs_file("lib/flowplayer.swf") ?>",
|
||||
wmode: "transparent",
|
||||
provider: "pseudostreaming"
|
||||
},
|
||||
{
|
||||
plugins: {
|
||||
pseudostreaming: {
|
||||
url: "<?= url::abs_file("lib/flowplayer.pseudostreaming.swf") ?>"
|
||||
},
|
||||
controls: {
|
||||
autoHide: 'always',
|
||||
hideDelay: 2000
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
</script>
|
28
modules/videos/views/videos_display_js.html.php
Normal file
28
modules/videos/views/videos_display_js.html.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.")
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 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.
|
||||
*/
|
||||
?>
|
||||
|
||||
<? if (!file_exists($item->resize_path() . ".flv")) { ?>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("#g-movie").replaceWith("<center><a href=\"<?= $item->file_url(true) ?>\">Click Here to Download Video.</a></center>");
|
||||
});
|
||||
</script>
|
||||
<? } ?>
|
37
modules/videos/views/videos_tree.html.php
Normal file
37
modules/videos/views/videos_tree.html.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
<li class="ui-icon-left">
|
||||
<span class="ui-icon ui-icon-folder-open"></span>
|
||||
<span class="g-directory" ref="">
|
||||
<?= t("All") ?>
|
||||
</span>
|
||||
<ul>
|
||||
|
||||
<? foreach ($parents as $dir): ?>
|
||||
<li class="ui-icon-left">
|
||||
<span class="ui-icon ui-icon-folder-open"></span>
|
||||
<span class="g-directory" ref="<?= html::clean_attribute($dir) ?>">
|
||||
<?= html::clean(basename($dir)) ?>
|
||||
</span>
|
||||
<ul>
|
||||
<? endforeach ?>
|
||||
|
||||
<? foreach ($files as $file): ?>
|
||||
<li class="ui-icon-left">
|
||||
<span class="ui-icon <?= is_dir($file) ? "ui-icon-folder-collapsed" : "ui-icon-document" ?>"></span>
|
||||
<span class="<?= is_dir($file) ? "g-directory" : "g-file" ?>"
|
||||
ref="<?= html::clean_attribute($file) ?>" >
|
||||
<?= html::clean(basename($file)) ?>
|
||||
</span>
|
||||
</li>
|
||||
<? endforeach ?>
|
||||
<? if (!$files): ?>
|
||||
<li> <i> <?= t("empty") ?> </i> </li>
|
||||
<? endif ?>
|
||||
|
||||
<? foreach ($parents as $dir): ?>
|
||||
</ul>
|
||||
</li>
|
||||
<? endforeach ?>
|
||||
|
||||
</ul>
|
||||
</li>
|
52
modules/videos/views/videos_tree_dialog.html.php
Normal file
52
modules/videos/views/videos_tree_dialog.html.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
<script type="text/javascript">
|
||||
var GET_CHILDREN_URL = "<?= url::site("videos/children?path=__PATH__") ?>";
|
||||
var START_URL = "<?= url::site("videos/start?item_id={$item->id}&csrf=$csrf") ?>";
|
||||
</script>
|
||||
|
||||
<div id="g-server-add">
|
||||
<h1 style="display: none;"><?= t("Add Videos to '%title'", array("title" => html::purify($item->title))) ?></h1>
|
||||
|
||||
<p id="g-description"><?= t("Videos will be added to album:") ?></p>
|
||||
<ul class="g-breadcrumbs">
|
||||
<? $i = 0 ?>
|
||||
<? foreach ($item->parents() as $parent): ?>
|
||||
<li<? if ($i == 0) print " class=\"g-first\"" ?>> <?= html::purify($parent->title) ?> </li>
|
||||
<? $i++ ?>
|
||||
<? endforeach ?>
|
||||
<li class="g-active"> <?= html::purify($item->title) ?> </li>
|
||||
</ul>
|
||||
|
||||
<ul id="g-server-add-tree" class="g-checkbox-tree">
|
||||
<?= $tree ?>
|
||||
</ul>
|
||||
|
||||
<div id="g-server-add-progress" style="display: none">
|
||||
<div class="g-progress-bar"></div>
|
||||
<div id="g-status"></div>
|
||||
</div>
|
||||
|
||||
<span>
|
||||
<button id="g-server-add-add-button" class="ui-state-default ui-state-disabled ui-corner-all"
|
||||
disabled="disabled">
|
||||
<?= t("Add") ?>
|
||||
</button>
|
||||
<button id="g-server-add-pause-button" class="ui-state-default ui-corner-all" style="display:none">
|
||||
<?= t("Pause") ?>
|
||||
</button>
|
||||
<button id="g-server-add-continue-button" class="ui-state-default ui-corner-all" style="display:none">
|
||||
<?= t("Continue") ?>
|
||||
</button>
|
||||
|
||||
<button id="g-server-add-close-button" class="ui-state-default ui-corner-all">
|
||||
<?= t("Close") ?>
|
||||
</button>
|
||||
</span>
|
||||
|
||||
<script type="text/javascript">
|
||||
$("#g-server-add").ready(function() {
|
||||
$("#g-server-add").gallery_server_add();
|
||||
});
|
||||
</script>
|
||||
|
||||
</div>
|
Reference in New Issue
Block a user