diff options
Diffstat (limited to 'modules/server_add')
| -rw-r--r-- | modules/server_add/controllers/admin_server_add.php | 97 | ||||
| -rw-r--r-- | modules/server_add/controllers/server_add.php | 315 | ||||
| -rw-r--r-- | modules/server_add/css/server_add.css | 38 | ||||
| -rw-r--r-- | modules/server_add/helpers/server_add.php | 49 | ||||
| -rw-r--r-- | modules/server_add/helpers/server_add_event.php | 42 | ||||
| -rw-r--r-- | modules/server_add/helpers/server_add_installer.php | 73 | ||||
| -rw-r--r-- | modules/server_add/helpers/server_add_theme.php | 27 | ||||
| -rw-r--r-- | modules/server_add/js/server_add.js | 125 | ||||
| -rw-r--r-- | modules/server_add/models/server_add_entry.php | 21 | ||||
| -rw-r--r-- | modules/server_add/module.info | 7 | ||||
| -rw-r--r-- | modules/server_add/views/admin_server_add.html.php | 40 | ||||
| -rw-r--r-- | modules/server_add/views/server_add_tree.html.php | 37 | ||||
| -rw-r--r-- | modules/server_add/views/server_add_tree_dialog.html.php | 52 |
13 files changed, 923 insertions, 0 deletions
diff --git a/modules/server_add/controllers/admin_server_add.php b/modules/server_add/controllers/admin_server_add.php new file mode 100644 index 0000000..ba2b9b3 --- /dev/null +++ b/modules/server_add/controllers/admin_server_add.php @@ -0,0 +1,97 @@ +<?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_Server_Add_Controller extends Admin_Controller { + public function index() { + $view = new Admin_View("admin.html"); + $view->page_title = t("Add from server"); + $view->content = new View("admin_server_add.html"); + $view->content->form = $this->_get_admin_form(); + $paths = unserialize(module::get_var("server_add", "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("server_add", "authorized_paths", "a:0:{}")); + if ($form->validate()) { + $path = html_entity_decode($form->add_path->path->value); + if (is_link($path)) { + $form->add_path->path->add_error("is_symlink", 1); + } else if (!is_readable($path)) { + $form->add_path->path->add_error("not_readable", 1); + } else { + $paths[$path] = 1; + module::set_var("server_add", "authorized_paths", serialize($paths)); + message::success(t("Added path %path", array("path" => $path))); + server_add::check_config($paths); + url::redirect("admin/server_add"); + } + } + + $view = new Admin_View("admin.html"); + $view->content = new View("admin_server_add.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("server_add", "authorized_paths")); + if (isset($paths[$path])) { + unset($paths[$path]); + message::success(t("Removed path %path", array("path" => $path))); + module::set_var("server_add", "authorized_paths", serialize($paths)); + server_add::check_config($paths); + } + url::redirect("admin/server_add"); + } + + 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[] = html::clean($file); + } + } + + ajax::response(implode("\n", $directories)); + } + + private function _get_admin_form() { + $form = new Forge("admin/server_add/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; + } +} diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php new file mode 100644 index 0000000..f6e0a94 --- /dev/null +++ b/modules/server_add/controllers/server_add.php @@ -0,0 +1,315 @@ +<?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 Server_Add_Controller extends Admin_Controller { + public function browse($id) { + $paths = unserialize(module::get_var("server_add", "authorized_paths")); + foreach (array_keys($paths) as $path) { + $files[] = $path; + } + + // Clean leftover task rows. There really should be support for this in the task framework + db::build() + ->where("task_id", "NOT IN", db::build()->select("id")->from("tasks")) + ->delete("server_add_entries") + ->execute(); + + $item = ORM::factory("item", $id); + $view = new View("server_add_tree_dialog.html"); + $view->item = $item; + $view->tree = new View("server_add_tree.html"); + $view->tree->files = $files; + $view->tree->parents = array(); + print $view; + } + + public function children() { + $path = Input::instance()->get("path"); + + $tree = new View("server_add_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 (server_add::is_valid_path($path)) { + $tree->parents[] = $path; + while (server_add::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 (!legal_file::get_extensions($ext)) { + continue; + } + } + + $tree->files[] = $file; + } + } else { + // Missing or invalid path; print out the list of authorized path + $paths = unserialize(module::get_var("server_add", "authorized_paths")); + foreach (array_keys($paths) as $path) { + $tree->files[] = $path; + } + } + print $tree; + } + + /** + * Begin the task of adding photos. + */ + public function start() { + access::verify_csrf(); + $item = ORM::factory("item", Input::instance()->get("item_id")); + + $task_def = Task_Definition::factory() + ->callback("Server_Add_Controller::add") + ->description(t("Add photos or movies from the local server")) + ->name(t("Add from server")); + $task = task::create($task_def, array("item_id" => $item->id)); + + foreach (Input::instance()->post("paths") as $path) { + if (server_add::is_valid_path($path)) { + $entry = ORM::factory("server_add_entry"); + $entry->path = $path; + $entry->is_directory = intval(is_dir($path)); + $entry->parent_id = null; + $entry->task_id = $task->id; + $entry->save(); + } + } + + json::reply( + array("result" => "started", + "status" => (string)$task->status, + "url" => url::site("server_add/run/$task->id?csrf=" . access::csrf_token()))); + } + + /** + * Run the task of adding photos + */ + 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_Entry_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->set("dirs_scanned", 0); + $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. + $paths = unserialize(module::get_var("server_add", "authorized_paths")); + $dirs_scanned = $task->get("dirs_scanned"); + while (microtime(true) - $start < 0.5) { + // Process every directory that doesn't yet have a parent id, these are the + // paths that we're importing. + $entry = ORM::factory("server_add_entry") + ->where("task_id", "=", $task->id) + ->where("is_directory", "=", 1) + ->where("checked", "=", 0) + ->order_by("id", "ASC") + ->find(); + + if ($entry->loaded()) { + $child_paths = glob(preg_quote($entry->path) . "/*"); + if (!$child_paths) { + $child_paths = glob("{$entry->path}/*"); + } + foreach ($child_paths as $child_path) { + if (!is_dir($child_path)) { + $ext = strtolower(pathinfo($child_path, PATHINFO_EXTENSION)); + if (!legal_file::get_extensions($ext) || !filesize($child_path)) { + // Not importable, skip it. + continue; + } + } + + $child_entry = ORM::factory("server_add_entry"); + $child_entry->task_id = $task->id; + $child_entry->path = $child_path; + $child_entry->parent_id = $entry->id; // null if the parent was a staging dir + $child_entry->is_directory = is_dir($child_path); + $child_entry->save(); + } + + // We've processed this entry, mark it as done. + $entry->checked = 1; + $entry->save(); + $dirs_scanned++; + } + } + + // 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("dirs_scanned", $dirs_scanned); + $task->percent_complete = min($task->percent_complete + 0.1, 10); + $task->status = t2("Scanned one directory", "Scanned %count directories", $dirs_scanned); + + if (!$entry->loaded()) { + $task->set("mode", "add-files"); + $task->set( + "total_files", + ORM::factory("server_add_entry")->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("server_add_entry") + ->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("server_add_entry", $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->path); + $title = item::convert_filename_to_title($name); + if ($entry->is_directory) { + $album = ORM::factory("item"); + $album->type = "album"; + $album->parent_id = $parent->id; + $album->name = $name; + $album->title = $title; + $album->owner_id = $owner_id; + $album->sort_order = $parent->sort_order; + $album->sort_column = $parent->sort_column; + $album->save(); + $entry->item_id = $album->id; + } else { + try { + $extension = strtolower(pathinfo($name, PATHINFO_EXTENSION)); + if (legal_file::get_photo_extensions($extension)) { + $photo = ORM::factory("item"); + $photo->type = "photo"; + $photo->parent_id = $parent->id; + $photo->set_data_file($entry->path); + $photo->name = $name; + $photo->title = $title; + $photo->owner_id = $owner_id; + $photo->save(); + $entry->item_id = $photo->id; + } else if (legal_file::get_movie_extensions($extension)) { + $movie = ORM::factory("item"); + $movie->type = "movie"; + $movie->parent_id = $parent->id; + $movie->set_data_file($entry->path); + $movie->name = $name; + $movie->title = $title; + $movie->owner_id = $owner_id; + $movie->save(); + $entry->item_id = $movie->id; + } 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->path}"); + } + } 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->path}"); + } + } + + $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; + ORM::factory("server_add_entry") + ->where("task_id", "=", $task->id) + ->delete_all(); + message::info(t2("Successfully added one photo / album", + "Successfully added %count photos / albums", + $task->get("completed_files"))); + } + } +} diff --git a/modules/server_add/css/server_add.css b/modules/server_add/css/server_add.css new file mode 100644 index 0000000..36746ab --- /dev/null +++ b/modules/server_add/css/server_add.css @@ -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; +} diff --git a/modules/server_add/helpers/server_add.php b/modules/server_add/helpers/server_add.php new file mode 100644 index 0000000..5cf08ce --- /dev/null +++ b/modules/server_add/helpers/server_add.php @@ -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-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 server_add_Core { + static function check_config($paths=null) { + if ($paths === null) { + $paths = unserialize(module::get_var("server_add", "authorized_paths")); + } + if (empty($paths)) { + site_status::warning( + t("Server Add needs configuration. <a href=\"%url\">Configure it now!</a>", + array("url" => html::mark_clean(url::site("admin/server_add")))), + "server_add_configuration"); + } else { + site_status::clear("server_add_configuration"); + } + } + + static function is_valid_path($path) { + if (!is_readable($path) || is_link($path)) { + return false; + } + + $authorized_paths = unserialize(module::get_var("server_add", "authorized_paths")); + foreach (array_keys($authorized_paths) as $valid_path) { + if (strpos($path, $valid_path) === 0) { + return true; + } + } + + return false; + } +} diff --git a/modules/server_add/helpers/server_add_event.php b/modules/server_add/helpers/server_add_event.php new file mode 100644 index 0000000..a718e2f --- /dev/null +++ b/modules/server_add/helpers/server_add_event.php @@ -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 server_add_event_Core { + static function admin_menu($menu, $theme) { + $menu->get("settings_menu") + ->append(Menu::factory("link") + ->id("server_add") + ->label(t("Server add")) + ->url(url::site("admin/server_add"))); + } + + static function site_menu($menu, $theme) { + $item = $theme->item(); + $paths = unserialize(module::get_var("server_add", "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("server_add") + ->label(t("Server add")) + ->url(url::site("server_add/browse/$item->id"))); + } + } +} diff --git a/modules/server_add/helpers/server_add_installer.php b/modules/server_add/helpers/server_add_installer.php new file mode 100644 index 0000000..b62bbcf --- /dev/null +++ b/modules/server_add/helpers/server_add_installer.php @@ -0,0 +1,73 @@ +<?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 server_add_installer { + static function install() { + $db = Database::instance(); + $db->query("CREATE TABLE {server_add_entries} ( + `id` int(9) NOT NULL auto_increment, + `checked` boolean default 0, + `is_directory` boolean default 0, + `item_id` int(9), + `parent_id` int(9), + `path` varchar(255) NOT NULL, + `task_id` int(9) NOT NULL, + PRIMARY KEY (`id`)) + DEFAULT CHARSET=utf8;"); + server_add::check_config(); + } + + static function upgrade($version) { + $db = Database::instance(); + if ($version == 1) { + $db->query("CREATE TABLE {server_add_files} ( + `id` int(9) NOT NULL auto_increment, + `task_id` int(9) NOT NULL, + `file` varchar(255) NOT NULL, + PRIMARY KEY (`id`)) + DEFAULT CHARSET=utf8;"); + module::set_version("server_add", $version = 2); + } + + if ($version == 2) { + $db->query("ALTER TABLE {server_add_files} ADD COLUMN `item_id` int(9)"); + $db->query("ALTER TABLE {server_add_files} ADD COLUMN `parent_id` int(9)"); + module::set_version("server_add", $version = 3); + } + + if ($version == 3) { + $db->query("DROP TABLE {server_add_files}"); + $db->query("CREATE TABLE {server_add_entries} ( + `id` int(9) NOT NULL auto_increment, + `checked` boolean default 0, + `is_directory` boolean default 0, + `item_id` int(9), + `parent_id` int(9), + `path` varchar(255) NOT NULL, + `task_id` int(9) NOT NULL, + PRIMARY KEY (`id`)) + DEFAULT CHARSET=utf8;"); + module::set_version("server_add", $version = 4); + } + } + + static function deactivate() { + site_status::clear("server_add_configuration"); + } +} diff --git a/modules/server_add/helpers/server_add_theme.php b/modules/server_add/helpers/server_add_theme.php new file mode 100644 index 0000000..7dfe658 --- /dev/null +++ b/modules/server_add/helpers/server_add_theme.php @@ -0,0 +1,27 @@ +<?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 server_add_theme_Core { + static function head($theme) { + if (identity::active_user()->admin) { + return $theme->css("server_add.css") + . $theme->script("server_add.js"); + } + } +}
\ No newline at end of file diff --git a/modules/server_add/js/server_add.js b/modules/server_add/js/server_add.js new file mode 100644 index 0000000..02dda4c --- /dev/null +++ b/modules/server_add/js/server_add.js @@ -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); diff --git a/modules/server_add/models/server_add_entry.php b/modules/server_add/models/server_add_entry.php new file mode 100644 index 0000000..572ebcb --- /dev/null +++ b/modules/server_add/models/server_add_entry.php @@ -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-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 Server_Add_Entry_Model_Core extends ORM { +} diff --git a/modules/server_add/module.info b/modules/server_add/module.info new file mode 100644 index 0000000..dc455c7 --- /dev/null +++ b/modules/server_add/module.info @@ -0,0 +1,7 @@ +name = "Server Add" +description = "Allows authorized users to load images directly from your web server" +version = 4 +author_name = "Gallery Team" +author_url = "http://codex.galleryproject.org/Gallery:Team" +info_url = "http://codex.galleryproject.org/Gallery3:Modules:server_add" +discuss_url = "http://galleryproject.org/forum_module_server_add" diff --git a/modules/server_add/views/admin_server_add.html.php b/modules/server_add/views/admin_server_add.html.php new file mode 100644 index 0000000..f59e327 --- /dev/null +++ b/modules/server_add/views/admin_server_add.html.php @@ -0,0 +1,40 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<?= $theme->css("server_add.css") ?> +<?= $theme->css("jquery.autocomplete.css") ?> +<?= $theme->script("jquery.autocomplete.js") ?> +<script type="text/javascript"> +$("document").ready(function() { + $("#g-path").gallery_autocomplete( + "<?= url::site("__ARGS__") ?>".replace("__ARGS__", "admin/server_add/autocomplete"), + { + max: 256, + loadingClass: "g-loading-small", + }); +}); +</script> + +<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/server_add/remove_path?path=" . urlencode($path) . "&csrf=" . access::csrf_token()) ?>" + 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> diff --git a/modules/server_add/views/server_add_tree.html.php b/modules/server_add/views/server_add_tree.html.php new file mode 100644 index 0000000..9135432 --- /dev/null +++ b/modules/server_add/views/server_add_tree.html.php @@ -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> diff --git a/modules/server_add/views/server_add_tree_dialog.html.php b/modules/server_add/views/server_add_tree_dialog.html.php new file mode 100644 index 0000000..824a86a --- /dev/null +++ b/modules/server_add/views/server_add_tree_dialog.html.php @@ -0,0 +1,52 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<script type="text/javascript"> + var GET_CHILDREN_URL = "<?= url::site("server_add/children?path=__PATH__") ?>"; + var START_URL = "<?= url::site("server_add/start?item_id={$item->id}&csrf=$csrf") ?>"; +</script> + +<div id="g-server-add"> + <h1 style="display: none;"><?= t("Add Photos to '%title'", array("title" => html::purify($item->title))) ?></h1> + + <p id="g-description"><?= t("Photos 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> |
